mv643xx_eth.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162
  1. /*
  2. * Driver for Marvell Discovery (MV643XX) and Marvell Orion ethernet ports
  3. * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com>
  4. *
  5. * Based on the 64360 driver from:
  6. * Copyright (C) 2002 Rabeeh Khoury <rabeeh@galileo.co.il>
  7. * Rabeeh Khoury <rabeeh@marvell.com>
  8. *
  9. * Copyright (C) 2003 PMC-Sierra, Inc.,
  10. * written by Manish Lachwani
  11. *
  12. * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org>
  13. *
  14. * Copyright (C) 2004-2006 MontaVista Software, Inc.
  15. * Dale Farnsworth <dale@farnsworth.org>
  16. *
  17. * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com>
  18. * <sjhill@realitydiluted.com>
  19. *
  20. * Copyright (C) 2007-2008 Marvell Semiconductor
  21. * Lennert Buytenhek <buytenh@marvell.com>
  22. *
  23. * This program is free software; you can redistribute it and/or
  24. * modify it under the terms of the GNU General Public License
  25. * as published by the Free Software Foundation; either version 2
  26. * of the License, or (at your option) any later version.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. * GNU General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public License
  34. * along with this program; if not, write to the Free Software
  35. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  36. */
  37. #include <linux/init.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/in.h>
  40. #include <linux/tcp.h>
  41. #include <linux/udp.h>
  42. #include <linux/etherdevice.h>
  43. #include <linux/delay.h>
  44. #include <linux/ethtool.h>
  45. #include <linux/platform_device.h>
  46. #include <linux/module.h>
  47. #include <linux/kernel.h>
  48. #include <linux/spinlock.h>
  49. #include <linux/workqueue.h>
  50. #include <linux/mii.h>
  51. #include <linux/mv643xx_eth.h>
  52. #include <asm/io.h>
  53. #include <asm/types.h>
  54. #include <asm/system.h>
  55. static char mv643xx_driver_name[] = "mv643xx_eth";
  56. static char mv643xx_driver_version[] = "1.0";
  57. #define MV643XX_CHECKSUM_OFFLOAD_TX
  58. #define MV643XX_NAPI
  59. #define MV643XX_TX_FAST_REFILL
  60. #undef MV643XX_COAL
  61. #define MV643XX_TX_COAL 100
  62. #ifdef MV643XX_COAL
  63. #define MV643XX_RX_COAL 100
  64. #endif
  65. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  66. #define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1)
  67. #else
  68. #define MAX_DESCS_PER_SKB 1
  69. #endif
  70. #define ETH_VLAN_HLEN 4
  71. #define ETH_FCS_LEN 4
  72. #define ETH_HW_IP_ALIGN 2 /* hw aligns IP header */
  73. #define ETH_WRAPPER_LEN (ETH_HW_IP_ALIGN + ETH_HLEN + \
  74. ETH_VLAN_HLEN + ETH_FCS_LEN)
  75. #define ETH_RX_SKB_SIZE (dev->mtu + ETH_WRAPPER_LEN + \
  76. dma_get_cache_alignment())
  77. /*
  78. * Registers shared between all ports.
  79. */
  80. #define PHY_ADDR 0x0000
  81. #define SMI_REG 0x0004
  82. #define WINDOW_BASE(w) (0x0200 + ((w) << 3))
  83. #define WINDOW_SIZE(w) (0x0204 + ((w) << 3))
  84. #define WINDOW_REMAP_HIGH(w) (0x0280 + ((w) << 2))
  85. #define WINDOW_BAR_ENABLE 0x0290
  86. #define WINDOW_PROTECT(w) (0x0294 + ((w) << 4))
  87. /*
  88. * Per-port registers.
  89. */
  90. #define PORT_CONFIG(p) (0x0400 + ((p) << 10))
  91. #define UNICAST_PROMISCUOUS_MODE 0x00000001
  92. #define PORT_CONFIG_EXT(p) (0x0404 + ((p) << 10))
  93. #define MAC_ADDR_LOW(p) (0x0414 + ((p) << 10))
  94. #define MAC_ADDR_HIGH(p) (0x0418 + ((p) << 10))
  95. #define SDMA_CONFIG(p) (0x041c + ((p) << 10))
  96. #define PORT_SERIAL_CONTROL(p) (0x043c + ((p) << 10))
  97. #define PORT_STATUS(p) (0x0444 + ((p) << 10))
  98. #define TXQ_COMMAND(p) (0x0448 + ((p) << 10))
  99. #define TX_BW_MTU(p) (0x0458 + ((p) << 10))
  100. #define INT_CAUSE(p) (0x0460 + ((p) << 10))
  101. #define INT_CAUSE_EXT(p) (0x0464 + ((p) << 10))
  102. #define INT_MASK(p) (0x0468 + ((p) << 10))
  103. #define INT_MASK_EXT(p) (0x046c + ((p) << 10))
  104. #define TX_FIFO_URGENT_THRESHOLD(p) (0x0474 + ((p) << 10))
  105. #define RXQ_CURRENT_DESC_PTR(p) (0x060c + ((p) << 10))
  106. #define RXQ_COMMAND(p) (0x0680 + ((p) << 10))
  107. #define TXQ_CURRENT_DESC_PTR(p) (0x06c0 + ((p) << 10))
  108. #define MIB_COUNTERS(p) (0x1000 + ((p) << 7))
  109. #define SPECIAL_MCAST_TABLE(p) (0x1400 + ((p) << 10))
  110. #define OTHER_MCAST_TABLE(p) (0x1500 + ((p) << 10))
  111. #define UNICAST_TABLE(p) (0x1600 + ((p) << 10))
  112. /* These macros describe Ethernet Port Sdma configuration reg (SDCR) bits */
  113. #define RIFB (1 << 0)
  114. #define RX_BURST_SIZE_1_64BIT (0 << 1)
  115. #define RX_BURST_SIZE_2_64BIT (1 << 1)
  116. #define RX_BURST_SIZE_4_64BIT (2 << 1)
  117. #define RX_BURST_SIZE_8_64BIT (3 << 1)
  118. #define RX_BURST_SIZE_16_64BIT (4 << 1)
  119. #define BLM_RX_NO_SWAP (1 << 4)
  120. #define BLM_RX_BYTE_SWAP (0 << 4)
  121. #define BLM_TX_NO_SWAP (1 << 5)
  122. #define BLM_TX_BYTE_SWAP (0 << 5)
  123. #define DESCRIPTORS_BYTE_SWAP (1 << 6)
  124. #define DESCRIPTORS_NO_SWAP (0 << 6)
  125. #define IPG_INT_RX(value) (((value) & 0x3fff) << 8)
  126. #define TX_BURST_SIZE_1_64BIT (0 << 22)
  127. #define TX_BURST_SIZE_2_64BIT (1 << 22)
  128. #define TX_BURST_SIZE_4_64BIT (2 << 22)
  129. #define TX_BURST_SIZE_8_64BIT (3 << 22)
  130. #define TX_BURST_SIZE_16_64BIT (4 << 22)
  131. #if defined(__BIG_ENDIAN)
  132. #define PORT_SDMA_CONFIG_DEFAULT_VALUE \
  133. RX_BURST_SIZE_4_64BIT | \
  134. IPG_INT_RX(0) | \
  135. TX_BURST_SIZE_4_64BIT
  136. #elif defined(__LITTLE_ENDIAN)
  137. #define PORT_SDMA_CONFIG_DEFAULT_VALUE \
  138. RX_BURST_SIZE_4_64BIT | \
  139. BLM_RX_NO_SWAP | \
  140. BLM_TX_NO_SWAP | \
  141. IPG_INT_RX(0) | \
  142. TX_BURST_SIZE_4_64BIT
  143. #else
  144. #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined
  145. #endif
  146. /* These macros describe Ethernet Port serial control reg (PSCR) bits */
  147. #define SERIAL_PORT_DISABLE (0 << 0)
  148. #define SERIAL_PORT_ENABLE (1 << 0)
  149. #define DO_NOT_FORCE_LINK_PASS (0 << 1)
  150. #define FORCE_LINK_PASS (1 << 1)
  151. #define ENABLE_AUTO_NEG_FOR_DUPLX (0 << 2)
  152. #define DISABLE_AUTO_NEG_FOR_DUPLX (1 << 2)
  153. #define ENABLE_AUTO_NEG_FOR_FLOW_CTRL (0 << 3)
  154. #define DISABLE_AUTO_NEG_FOR_FLOW_CTRL (1 << 3)
  155. #define ADV_NO_FLOW_CTRL (0 << 4)
  156. #define ADV_SYMMETRIC_FLOW_CTRL (1 << 4)
  157. #define FORCE_FC_MODE_NO_PAUSE_DIS_TX (0 << 5)
  158. #define FORCE_FC_MODE_TX_PAUSE_DIS (1 << 5)
  159. #define FORCE_BP_MODE_NO_JAM (0 << 7)
  160. #define FORCE_BP_MODE_JAM_TX (1 << 7)
  161. #define FORCE_BP_MODE_JAM_TX_ON_RX_ERR (2 << 7)
  162. #define SERIAL_PORT_CONTROL_RESERVED (1 << 9)
  163. #define FORCE_LINK_FAIL (0 << 10)
  164. #define DO_NOT_FORCE_LINK_FAIL (1 << 10)
  165. #define RETRANSMIT_16_ATTEMPTS (0 << 11)
  166. #define RETRANSMIT_FOREVER (1 << 11)
  167. #define ENABLE_AUTO_NEG_SPEED_GMII (0 << 13)
  168. #define DISABLE_AUTO_NEG_SPEED_GMII (1 << 13)
  169. #define DTE_ADV_0 (0 << 14)
  170. #define DTE_ADV_1 (1 << 14)
  171. #define DISABLE_AUTO_NEG_BYPASS (0 << 15)
  172. #define ENABLE_AUTO_NEG_BYPASS (1 << 15)
  173. #define AUTO_NEG_NO_CHANGE (0 << 16)
  174. #define RESTART_AUTO_NEG (1 << 16)
  175. #define MAX_RX_PACKET_1518BYTE (0 << 17)
  176. #define MAX_RX_PACKET_1522BYTE (1 << 17)
  177. #define MAX_RX_PACKET_1552BYTE (2 << 17)
  178. #define MAX_RX_PACKET_9022BYTE (3 << 17)
  179. #define MAX_RX_PACKET_9192BYTE (4 << 17)
  180. #define MAX_RX_PACKET_9700BYTE (5 << 17)
  181. #define MAX_RX_PACKET_MASK (7 << 17)
  182. #define CLR_EXT_LOOPBACK (0 << 20)
  183. #define SET_EXT_LOOPBACK (1 << 20)
  184. #define SET_HALF_DUPLEX_MODE (0 << 21)
  185. #define SET_FULL_DUPLEX_MODE (1 << 21)
  186. #define DISABLE_FLOW_CTRL_TX_RX_IN_FULL_DUPLEX (0 << 22)
  187. #define ENABLE_FLOW_CTRL_TX_RX_IN_FULL_DUPLEX (1 << 22)
  188. #define SET_GMII_SPEED_TO_10_100 (0 << 23)
  189. #define SET_GMII_SPEED_TO_1000 (1 << 23)
  190. #define SET_MII_SPEED_TO_10 (0 << 24)
  191. #define SET_MII_SPEED_TO_100 (1 << 24)
  192. #define PORT_SERIAL_CONTROL_DEFAULT_VALUE \
  193. DO_NOT_FORCE_LINK_PASS | \
  194. ENABLE_AUTO_NEG_FOR_DUPLX | \
  195. DISABLE_AUTO_NEG_FOR_FLOW_CTRL | \
  196. ADV_SYMMETRIC_FLOW_CTRL | \
  197. FORCE_FC_MODE_NO_PAUSE_DIS_TX | \
  198. FORCE_BP_MODE_NO_JAM | \
  199. (1 << 9) /* reserved */ | \
  200. DO_NOT_FORCE_LINK_FAIL | \
  201. RETRANSMIT_16_ATTEMPTS | \
  202. ENABLE_AUTO_NEG_SPEED_GMII | \
  203. DTE_ADV_0 | \
  204. DISABLE_AUTO_NEG_BYPASS | \
  205. AUTO_NEG_NO_CHANGE | \
  206. MAX_RX_PACKET_9700BYTE | \
  207. CLR_EXT_LOOPBACK | \
  208. SET_FULL_DUPLEX_MODE | \
  209. ENABLE_FLOW_CTRL_TX_RX_IN_FULL_DUPLEX
  210. /* These macros describe Ethernet Serial Status reg (PSR) bits */
  211. #define PORT_STATUS_MODE_10_BIT (1 << 0)
  212. #define PORT_STATUS_LINK_UP (1 << 1)
  213. #define PORT_STATUS_FULL_DUPLEX (1 << 2)
  214. #define PORT_STATUS_FLOW_CONTROL (1 << 3)
  215. #define PORT_STATUS_GMII_1000 (1 << 4)
  216. #define PORT_STATUS_MII_100 (1 << 5)
  217. /* PSR bit 6 is undocumented */
  218. #define PORT_STATUS_TX_IN_PROGRESS (1 << 7)
  219. #define PORT_STATUS_AUTONEG_BYPASSED (1 << 8)
  220. #define PORT_STATUS_PARTITION (1 << 9)
  221. #define PORT_STATUS_TX_FIFO_EMPTY (1 << 10)
  222. /* PSR bits 11-31 are reserved */
  223. #define PORT_DEFAULT_TRANSMIT_QUEUE_SIZE 800
  224. #define PORT_DEFAULT_RECEIVE_QUEUE_SIZE 400
  225. #define DESC_SIZE 64
  226. #define ETH_RX_QUEUES_ENABLED (1 << 0) /* use only Q0 for receive */
  227. #define ETH_TX_QUEUES_ENABLED (1 << 0) /* use only Q0 for transmit */
  228. #define ETH_INT_CAUSE_RX_DONE (ETH_RX_QUEUES_ENABLED << 2)
  229. #define ETH_INT_CAUSE_RX_ERROR (ETH_RX_QUEUES_ENABLED << 9)
  230. #define ETH_INT_CAUSE_RX (ETH_INT_CAUSE_RX_DONE | ETH_INT_CAUSE_RX_ERROR)
  231. #define ETH_INT_CAUSE_EXT 0x00000002
  232. #define ETH_INT_UNMASK_ALL (ETH_INT_CAUSE_RX | ETH_INT_CAUSE_EXT)
  233. #define ETH_INT_CAUSE_TX_DONE (ETH_TX_QUEUES_ENABLED << 0)
  234. #define ETH_INT_CAUSE_TX_ERROR (ETH_TX_QUEUES_ENABLED << 8)
  235. #define ETH_INT_CAUSE_TX (ETH_INT_CAUSE_TX_DONE | ETH_INT_CAUSE_TX_ERROR)
  236. #define ETH_INT_CAUSE_PHY 0x00010000
  237. #define ETH_INT_CAUSE_STATE 0x00100000
  238. #define ETH_INT_UNMASK_ALL_EXT (ETH_INT_CAUSE_TX | ETH_INT_CAUSE_PHY | \
  239. ETH_INT_CAUSE_STATE)
  240. #define ETH_INT_MASK_ALL 0x00000000
  241. #define ETH_INT_MASK_ALL_EXT 0x00000000
  242. #define PHY_WAIT_ITERATIONS 1000 /* 1000 iterations * 10uS = 10mS max */
  243. #define PHY_WAIT_MICRO_SECONDS 10
  244. /* Buffer offset from buffer pointer */
  245. #define RX_BUF_OFFSET 0x2
  246. /* Gigabit Ethernet Unit Global Registers */
  247. /* MIB Counters register definitions */
  248. #define ETH_MIB_GOOD_OCTETS_RECEIVED_LOW 0x0
  249. #define ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH 0x4
  250. #define ETH_MIB_BAD_OCTETS_RECEIVED 0x8
  251. #define ETH_MIB_INTERNAL_MAC_TRANSMIT_ERR 0xc
  252. #define ETH_MIB_GOOD_FRAMES_RECEIVED 0x10
  253. #define ETH_MIB_BAD_FRAMES_RECEIVED 0x14
  254. #define ETH_MIB_BROADCAST_FRAMES_RECEIVED 0x18
  255. #define ETH_MIB_MULTICAST_FRAMES_RECEIVED 0x1c
  256. #define ETH_MIB_FRAMES_64_OCTETS 0x20
  257. #define ETH_MIB_FRAMES_65_TO_127_OCTETS 0x24
  258. #define ETH_MIB_FRAMES_128_TO_255_OCTETS 0x28
  259. #define ETH_MIB_FRAMES_256_TO_511_OCTETS 0x2c
  260. #define ETH_MIB_FRAMES_512_TO_1023_OCTETS 0x30
  261. #define ETH_MIB_FRAMES_1024_TO_MAX_OCTETS 0x34
  262. #define ETH_MIB_GOOD_OCTETS_SENT_LOW 0x38
  263. #define ETH_MIB_GOOD_OCTETS_SENT_HIGH 0x3c
  264. #define ETH_MIB_GOOD_FRAMES_SENT 0x40
  265. #define ETH_MIB_EXCESSIVE_COLLISION 0x44
  266. #define ETH_MIB_MULTICAST_FRAMES_SENT 0x48
  267. #define ETH_MIB_BROADCAST_FRAMES_SENT 0x4c
  268. #define ETH_MIB_UNREC_MAC_CONTROL_RECEIVED 0x50
  269. #define ETH_MIB_FC_SENT 0x54
  270. #define ETH_MIB_GOOD_FC_RECEIVED 0x58
  271. #define ETH_MIB_BAD_FC_RECEIVED 0x5c
  272. #define ETH_MIB_UNDERSIZE_RECEIVED 0x60
  273. #define ETH_MIB_FRAGMENTS_RECEIVED 0x64
  274. #define ETH_MIB_OVERSIZE_RECEIVED 0x68
  275. #define ETH_MIB_JABBER_RECEIVED 0x6c
  276. #define ETH_MIB_MAC_RECEIVE_ERROR 0x70
  277. #define ETH_MIB_BAD_CRC_EVENT 0x74
  278. #define ETH_MIB_COLLISION 0x78
  279. #define ETH_MIB_LATE_COLLISION 0x7c
  280. /* Port serial status reg (PSR) */
  281. #define ETH_INTERFACE_PCM 0x00000001
  282. #define ETH_LINK_IS_UP 0x00000002
  283. #define ETH_PORT_AT_FULL_DUPLEX 0x00000004
  284. #define ETH_RX_FLOW_CTRL_ENABLED 0x00000008
  285. #define ETH_GMII_SPEED_1000 0x00000010
  286. #define ETH_MII_SPEED_100 0x00000020
  287. #define ETH_TX_IN_PROGRESS 0x00000080
  288. #define ETH_BYPASS_ACTIVE 0x00000100
  289. #define ETH_PORT_AT_PARTITION_STATE 0x00000200
  290. #define ETH_PORT_TX_FIFO_EMPTY 0x00000400
  291. /* SMI reg */
  292. #define ETH_SMI_BUSY 0x10000000 /* 0 - Write, 1 - Read */
  293. #define ETH_SMI_READ_VALID 0x08000000 /* 0 - Write, 1 - Read */
  294. #define ETH_SMI_OPCODE_WRITE 0 /* Completion of Read */
  295. #define ETH_SMI_OPCODE_READ 0x04000000 /* Operation is in progress */
  296. /* Interrupt Cause Register Bit Definitions */
  297. /* SDMA command status fields macros */
  298. /* Tx & Rx descriptors status */
  299. #define ETH_ERROR_SUMMARY 0x00000001
  300. /* Tx & Rx descriptors command */
  301. #define ETH_BUFFER_OWNED_BY_DMA 0x80000000
  302. /* Tx descriptors status */
  303. #define ETH_LC_ERROR 0
  304. #define ETH_UR_ERROR 0x00000002
  305. #define ETH_RL_ERROR 0x00000004
  306. #define ETH_LLC_SNAP_FORMAT 0x00000200
  307. /* Rx descriptors status */
  308. #define ETH_OVERRUN_ERROR 0x00000002
  309. #define ETH_MAX_FRAME_LENGTH_ERROR 0x00000004
  310. #define ETH_RESOURCE_ERROR 0x00000006
  311. #define ETH_VLAN_TAGGED 0x00080000
  312. #define ETH_BPDU_FRAME 0x00100000
  313. #define ETH_UDP_FRAME_OVER_IP_V_4 0x00200000
  314. #define ETH_OTHER_FRAME_TYPE 0x00400000
  315. #define ETH_LAYER_2_IS_ETH_V_2 0x00800000
  316. #define ETH_FRAME_TYPE_IP_V_4 0x01000000
  317. #define ETH_FRAME_HEADER_OK 0x02000000
  318. #define ETH_RX_LAST_DESC 0x04000000
  319. #define ETH_RX_FIRST_DESC 0x08000000
  320. #define ETH_UNKNOWN_DESTINATION_ADDR 0x10000000
  321. #define ETH_RX_ENABLE_INTERRUPT 0x20000000
  322. #define ETH_LAYER_4_CHECKSUM_OK 0x40000000
  323. /* Rx descriptors byte count */
  324. #define ETH_FRAME_FRAGMENTED 0x00000004
  325. /* Tx descriptors command */
  326. #define ETH_LAYER_4_CHECKSUM_FIRST_DESC 0x00000400
  327. #define ETH_FRAME_SET_TO_VLAN 0x00008000
  328. #define ETH_UDP_FRAME 0x00010000
  329. #define ETH_GEN_TCP_UDP_CHECKSUM 0x00020000
  330. #define ETH_GEN_IP_V_4_CHECKSUM 0x00040000
  331. #define ETH_ZERO_PADDING 0x00080000
  332. #define ETH_TX_LAST_DESC 0x00100000
  333. #define ETH_TX_FIRST_DESC 0x00200000
  334. #define ETH_GEN_CRC 0x00400000
  335. #define ETH_TX_ENABLE_INTERRUPT 0x00800000
  336. #define ETH_AUTO_MODE 0x40000000
  337. #define ETH_TX_IHL_SHIFT 11
  338. /* typedefs */
  339. typedef enum _eth_func_ret_status {
  340. ETH_OK, /* Returned as expected. */
  341. ETH_ERROR, /* Fundamental error. */
  342. ETH_RETRY, /* Could not process request. Try later.*/
  343. ETH_END_OF_JOB, /* Ring has nothing to process. */
  344. ETH_QUEUE_FULL, /* Ring resource error. */
  345. ETH_QUEUE_LAST_RESOURCE /* Ring resources about to exhaust. */
  346. } ETH_FUNC_RET_STATUS;
  347. /* These are for big-endian machines. Little endian needs different
  348. * definitions.
  349. */
  350. #if defined(__BIG_ENDIAN)
  351. struct eth_rx_desc {
  352. u16 byte_cnt; /* Descriptor buffer byte count */
  353. u16 buf_size; /* Buffer size */
  354. u32 cmd_sts; /* Descriptor command status */
  355. u32 next_desc_ptr; /* Next descriptor pointer */
  356. u32 buf_ptr; /* Descriptor buffer pointer */
  357. };
  358. struct eth_tx_desc {
  359. u16 byte_cnt; /* buffer byte count */
  360. u16 l4i_chk; /* CPU provided TCP checksum */
  361. u32 cmd_sts; /* Command/status field */
  362. u32 next_desc_ptr; /* Pointer to next descriptor */
  363. u32 buf_ptr; /* pointer to buffer for this descriptor*/
  364. };
  365. #elif defined(__LITTLE_ENDIAN)
  366. struct eth_rx_desc {
  367. u32 cmd_sts; /* Descriptor command status */
  368. u16 buf_size; /* Buffer size */
  369. u16 byte_cnt; /* Descriptor buffer byte count */
  370. u32 buf_ptr; /* Descriptor buffer pointer */
  371. u32 next_desc_ptr; /* Next descriptor pointer */
  372. };
  373. struct eth_tx_desc {
  374. u32 cmd_sts; /* Command/status field */
  375. u16 l4i_chk; /* CPU provided TCP checksum */
  376. u16 byte_cnt; /* buffer byte count */
  377. u32 buf_ptr; /* pointer to buffer for this descriptor*/
  378. u32 next_desc_ptr; /* Pointer to next descriptor */
  379. };
  380. #else
  381. #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined
  382. #endif
  383. /* Unified struct for Rx and Tx operations. The user is not required to */
  384. /* be familier with neither Tx nor Rx descriptors. */
  385. struct pkt_info {
  386. unsigned short byte_cnt; /* Descriptor buffer byte count */
  387. unsigned short l4i_chk; /* Tx CPU provided TCP Checksum */
  388. unsigned int cmd_sts; /* Descriptor command status */
  389. dma_addr_t buf_ptr; /* Descriptor buffer pointer */
  390. struct sk_buff *return_info; /* User resource return information */
  391. };
  392. /* global *******************************************************************/
  393. struct mv643xx_shared_private {
  394. void __iomem *eth_base;
  395. /* used to protect SMI_REG, which is shared across ports */
  396. spinlock_t phy_lock;
  397. u32 win_protect;
  398. unsigned int t_clk;
  399. };
  400. /* per-port *****************************************************************/
  401. struct mv643xx_mib_counters {
  402. u64 good_octets_received;
  403. u32 bad_octets_received;
  404. u32 internal_mac_transmit_err;
  405. u32 good_frames_received;
  406. u32 bad_frames_received;
  407. u32 broadcast_frames_received;
  408. u32 multicast_frames_received;
  409. u32 frames_64_octets;
  410. u32 frames_65_to_127_octets;
  411. u32 frames_128_to_255_octets;
  412. u32 frames_256_to_511_octets;
  413. u32 frames_512_to_1023_octets;
  414. u32 frames_1024_to_max_octets;
  415. u64 good_octets_sent;
  416. u32 good_frames_sent;
  417. u32 excessive_collision;
  418. u32 multicast_frames_sent;
  419. u32 broadcast_frames_sent;
  420. u32 unrec_mac_control_received;
  421. u32 fc_sent;
  422. u32 good_fc_received;
  423. u32 bad_fc_received;
  424. u32 undersize_received;
  425. u32 fragments_received;
  426. u32 oversize_received;
  427. u32 jabber_received;
  428. u32 mac_receive_error;
  429. u32 bad_crc_event;
  430. u32 collision;
  431. u32 late_collision;
  432. };
  433. struct mv643xx_private {
  434. struct mv643xx_shared_private *shared;
  435. int port_num; /* User Ethernet port number */
  436. struct mv643xx_shared_private *shared_smi;
  437. u32 rx_sram_addr; /* Base address of rx sram area */
  438. u32 rx_sram_size; /* Size of rx sram area */
  439. u32 tx_sram_addr; /* Base address of tx sram area */
  440. u32 tx_sram_size; /* Size of tx sram area */
  441. int rx_resource_err; /* Rx ring resource error flag */
  442. /* Tx/Rx rings managment indexes fields. For driver use */
  443. /* Next available and first returning Rx resource */
  444. int rx_curr_desc_q, rx_used_desc_q;
  445. /* Next available and first returning Tx resource */
  446. int tx_curr_desc_q, tx_used_desc_q;
  447. #ifdef MV643XX_TX_FAST_REFILL
  448. u32 tx_clean_threshold;
  449. #endif
  450. struct eth_rx_desc *p_rx_desc_area;
  451. dma_addr_t rx_desc_dma;
  452. int rx_desc_area_size;
  453. struct sk_buff **rx_skb;
  454. struct eth_tx_desc *p_tx_desc_area;
  455. dma_addr_t tx_desc_dma;
  456. int tx_desc_area_size;
  457. struct sk_buff **tx_skb;
  458. struct work_struct tx_timeout_task;
  459. struct net_device *dev;
  460. struct napi_struct napi;
  461. struct net_device_stats stats;
  462. struct mv643xx_mib_counters mib_counters;
  463. spinlock_t lock;
  464. /* Size of Tx Ring per queue */
  465. int tx_ring_size;
  466. /* Number of tx descriptors in use */
  467. int tx_desc_count;
  468. /* Size of Rx Ring per queue */
  469. int rx_ring_size;
  470. /* Number of rx descriptors in use */
  471. int rx_desc_count;
  472. /*
  473. * Used in case RX Ring is empty, which can be caused when
  474. * system does not have resources (skb's)
  475. */
  476. struct timer_list timeout;
  477. u32 rx_int_coal;
  478. u32 tx_int_coal;
  479. struct mii_if_info mii;
  480. };
  481. /* port register accessors **************************************************/
  482. static inline u32 rdl(struct mv643xx_private *mp, int offset)
  483. {
  484. return readl(mp->shared->eth_base + offset);
  485. }
  486. static inline void wrl(struct mv643xx_private *mp, int offset, u32 data)
  487. {
  488. writel(data, mp->shared->eth_base + offset);
  489. }
  490. /* rxq/txq helper functions *************************************************/
  491. static void mv643xx_eth_port_enable_rx(struct mv643xx_private *mp,
  492. unsigned int queues)
  493. {
  494. wrl(mp, RXQ_COMMAND(mp->port_num), queues);
  495. }
  496. static unsigned int mv643xx_eth_port_disable_rx(struct mv643xx_private *mp)
  497. {
  498. unsigned int port_num = mp->port_num;
  499. u32 queues;
  500. /* Stop Rx port activity. Check port Rx activity. */
  501. queues = rdl(mp, RXQ_COMMAND(port_num)) & 0xFF;
  502. if (queues) {
  503. /* Issue stop command for active queues only */
  504. wrl(mp, RXQ_COMMAND(port_num), (queues << 8));
  505. /* Wait for all Rx activity to terminate. */
  506. /* Check port cause register that all Rx queues are stopped */
  507. while (rdl(mp, RXQ_COMMAND(port_num)) & 0xFF)
  508. udelay(PHY_WAIT_MICRO_SECONDS);
  509. }
  510. return queues;
  511. }
  512. static void mv643xx_eth_port_enable_tx(struct mv643xx_private *mp,
  513. unsigned int queues)
  514. {
  515. wrl(mp, TXQ_COMMAND(mp->port_num), queues);
  516. }
  517. static unsigned int mv643xx_eth_port_disable_tx(struct mv643xx_private *mp)
  518. {
  519. unsigned int port_num = mp->port_num;
  520. u32 queues;
  521. /* Stop Tx port activity. Check port Tx activity. */
  522. queues = rdl(mp, TXQ_COMMAND(port_num)) & 0xFF;
  523. if (queues) {
  524. /* Issue stop command for active queues only */
  525. wrl(mp, TXQ_COMMAND(port_num), (queues << 8));
  526. /* Wait for all Tx activity to terminate. */
  527. /* Check port cause register that all Tx queues are stopped */
  528. while (rdl(mp, TXQ_COMMAND(port_num)) & 0xFF)
  529. udelay(PHY_WAIT_MICRO_SECONDS);
  530. /* Wait for Tx FIFO to empty */
  531. while (rdl(mp, PORT_STATUS(port_num)) & ETH_PORT_TX_FIFO_EMPTY)
  532. udelay(PHY_WAIT_MICRO_SECONDS);
  533. }
  534. return queues;
  535. }
  536. /* rx ***********************************************************************/
  537. static void mv643xx_eth_free_completed_tx_descs(struct net_device *dev);
  538. /*
  539. * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
  540. *
  541. * DESCRIPTION:
  542. * This routine returns a Rx buffer back to the Rx ring. It retrieves the
  543. * next 'used' descriptor and attached the returned buffer to it.
  544. * In case the Rx ring was in "resource error" condition, where there are
  545. * no available Rx resources, the function resets the resource error flag.
  546. *
  547. * INPUT:
  548. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  549. * struct pkt_info *p_pkt_info Information on returned buffer.
  550. *
  551. * OUTPUT:
  552. * New available Rx resource in Rx descriptor ring.
  553. *
  554. * RETURN:
  555. * ETH_ERROR in case the routine can not access Rx desc ring.
  556. * ETH_OK otherwise.
  557. */
  558. static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp,
  559. struct pkt_info *p_pkt_info)
  560. {
  561. int used_rx_desc; /* Where to return Rx resource */
  562. volatile struct eth_rx_desc *p_used_rx_desc;
  563. unsigned long flags;
  564. spin_lock_irqsave(&mp->lock, flags);
  565. /* Get 'used' Rx descriptor */
  566. used_rx_desc = mp->rx_used_desc_q;
  567. p_used_rx_desc = &mp->p_rx_desc_area[used_rx_desc];
  568. p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
  569. p_used_rx_desc->buf_size = p_pkt_info->byte_cnt;
  570. mp->rx_skb[used_rx_desc] = p_pkt_info->return_info;
  571. /* Flush the write pipe */
  572. /* Return the descriptor to DMA ownership */
  573. wmb();
  574. p_used_rx_desc->cmd_sts =
  575. ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
  576. wmb();
  577. /* Move the used descriptor pointer to the next descriptor */
  578. mp->rx_used_desc_q = (used_rx_desc + 1) % mp->rx_ring_size;
  579. /* Any Rx return cancels the Rx resource error status */
  580. mp->rx_resource_err = 0;
  581. spin_unlock_irqrestore(&mp->lock, flags);
  582. return ETH_OK;
  583. }
  584. /*
  585. * mv643xx_eth_rx_refill_descs
  586. *
  587. * Fills / refills RX queue on a certain gigabit ethernet port
  588. *
  589. * Input : pointer to ethernet interface network device structure
  590. * Output : N/A
  591. */
  592. static void mv643xx_eth_rx_refill_descs(struct net_device *dev)
  593. {
  594. struct mv643xx_private *mp = netdev_priv(dev);
  595. struct pkt_info pkt_info;
  596. struct sk_buff *skb;
  597. int unaligned;
  598. while (mp->rx_desc_count < mp->rx_ring_size) {
  599. skb = dev_alloc_skb(ETH_RX_SKB_SIZE + dma_get_cache_alignment());
  600. if (!skb)
  601. break;
  602. mp->rx_desc_count++;
  603. unaligned = (u32)skb->data & (dma_get_cache_alignment() - 1);
  604. if (unaligned)
  605. skb_reserve(skb, dma_get_cache_alignment() - unaligned);
  606. pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT;
  607. pkt_info.byte_cnt = ETH_RX_SKB_SIZE;
  608. pkt_info.buf_ptr = dma_map_single(NULL, skb->data,
  609. ETH_RX_SKB_SIZE, DMA_FROM_DEVICE);
  610. pkt_info.return_info = skb;
  611. if (eth_rx_return_buff(mp, &pkt_info) != ETH_OK) {
  612. printk(KERN_ERR
  613. "%s: Error allocating RX Ring\n", dev->name);
  614. break;
  615. }
  616. skb_reserve(skb, ETH_HW_IP_ALIGN);
  617. }
  618. /*
  619. * If RX ring is empty of SKB, set a timer to try allocating
  620. * again at a later time.
  621. */
  622. if (mp->rx_desc_count == 0) {
  623. printk(KERN_INFO "%s: Rx ring is empty\n", dev->name);
  624. mp->timeout.expires = jiffies + (HZ / 10); /* 100 mSec */
  625. add_timer(&mp->timeout);
  626. }
  627. }
  628. /*
  629. * mv643xx_eth_rx_refill_descs_timer_wrapper
  630. *
  631. * Timer routine to wake up RX queue filling task. This function is
  632. * used only in case the RX queue is empty, and all alloc_skb has
  633. * failed (due to out of memory event).
  634. *
  635. * Input : pointer to ethernet interface network device structure
  636. * Output : N/A
  637. */
  638. static inline void mv643xx_eth_rx_refill_descs_timer_wrapper(unsigned long data)
  639. {
  640. mv643xx_eth_rx_refill_descs((struct net_device *)data);
  641. }
  642. /*
  643. * eth_port_receive - Get received information from Rx ring.
  644. *
  645. * DESCRIPTION:
  646. * This routine returns the received data to the caller. There is no
  647. * data copying during routine operation. All information is returned
  648. * using pointer to packet information struct passed from the caller.
  649. * If the routine exhausts Rx ring resources then the resource error flag
  650. * is set.
  651. *
  652. * INPUT:
  653. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  654. * struct pkt_info *p_pkt_info User packet buffer.
  655. *
  656. * OUTPUT:
  657. * Rx ring current and used indexes are updated.
  658. *
  659. * RETURN:
  660. * ETH_ERROR in case the routine can not access Rx desc ring.
  661. * ETH_QUEUE_FULL if Rx ring resources are exhausted.
  662. * ETH_END_OF_JOB if there is no received data.
  663. * ETH_OK otherwise.
  664. */
  665. static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp,
  666. struct pkt_info *p_pkt_info)
  667. {
  668. int rx_next_curr_desc, rx_curr_desc, rx_used_desc;
  669. volatile struct eth_rx_desc *p_rx_desc;
  670. unsigned int command_status;
  671. unsigned long flags;
  672. /* Do not process Rx ring in case of Rx ring resource error */
  673. if (mp->rx_resource_err)
  674. return ETH_QUEUE_FULL;
  675. spin_lock_irqsave(&mp->lock, flags);
  676. /* Get the Rx Desc ring 'curr and 'used' indexes */
  677. rx_curr_desc = mp->rx_curr_desc_q;
  678. rx_used_desc = mp->rx_used_desc_q;
  679. p_rx_desc = &mp->p_rx_desc_area[rx_curr_desc];
  680. /* The following parameters are used to save readings from memory */
  681. command_status = p_rx_desc->cmd_sts;
  682. rmb();
  683. /* Nothing to receive... */
  684. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  685. spin_unlock_irqrestore(&mp->lock, flags);
  686. return ETH_END_OF_JOB;
  687. }
  688. p_pkt_info->byte_cnt = (p_rx_desc->byte_cnt) - RX_BUF_OFFSET;
  689. p_pkt_info->cmd_sts = command_status;
  690. p_pkt_info->buf_ptr = (p_rx_desc->buf_ptr) + RX_BUF_OFFSET;
  691. p_pkt_info->return_info = mp->rx_skb[rx_curr_desc];
  692. p_pkt_info->l4i_chk = p_rx_desc->buf_size;
  693. /*
  694. * Clean the return info field to indicate that the
  695. * packet has been moved to the upper layers
  696. */
  697. mp->rx_skb[rx_curr_desc] = NULL;
  698. /* Update current index in data structure */
  699. rx_next_curr_desc = (rx_curr_desc + 1) % mp->rx_ring_size;
  700. mp->rx_curr_desc_q = rx_next_curr_desc;
  701. /* Rx descriptors exhausted. Set the Rx ring resource error flag */
  702. if (rx_next_curr_desc == rx_used_desc)
  703. mp->rx_resource_err = 1;
  704. spin_unlock_irqrestore(&mp->lock, flags);
  705. return ETH_OK;
  706. }
  707. /*
  708. * mv643xx_eth_receive
  709. *
  710. * This function is forward packets that are received from the port's
  711. * queues toward kernel core or FastRoute them to another interface.
  712. *
  713. * Input : dev - a pointer to the required interface
  714. * max - maximum number to receive (0 means unlimted)
  715. *
  716. * Output : number of served packets
  717. */
  718. static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
  719. {
  720. struct mv643xx_private *mp = netdev_priv(dev);
  721. struct net_device_stats *stats = &dev->stats;
  722. unsigned int received_packets = 0;
  723. struct sk_buff *skb;
  724. struct pkt_info pkt_info;
  725. while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) {
  726. dma_unmap_single(NULL, pkt_info.buf_ptr, ETH_RX_SKB_SIZE,
  727. DMA_FROM_DEVICE);
  728. mp->rx_desc_count--;
  729. received_packets++;
  730. /*
  731. * Update statistics.
  732. * Note byte count includes 4 byte CRC count
  733. */
  734. stats->rx_packets++;
  735. stats->rx_bytes += pkt_info.byte_cnt;
  736. skb = pkt_info.return_info;
  737. /*
  738. * In case received a packet without first / last bits on OR
  739. * the error summary bit is on, the packets needs to be dropeed.
  740. */
  741. if (((pkt_info.cmd_sts
  742. & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) !=
  743. (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC))
  744. || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) {
  745. stats->rx_dropped++;
  746. if ((pkt_info.cmd_sts & (ETH_RX_FIRST_DESC |
  747. ETH_RX_LAST_DESC)) !=
  748. (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) {
  749. if (net_ratelimit())
  750. printk(KERN_ERR
  751. "%s: Received packet spread "
  752. "on multiple descriptors\n",
  753. dev->name);
  754. }
  755. if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)
  756. stats->rx_errors++;
  757. dev_kfree_skb_irq(skb);
  758. } else {
  759. /*
  760. * The -4 is for the CRC in the trailer of the
  761. * received packet
  762. */
  763. skb_put(skb, pkt_info.byte_cnt - 4);
  764. if (pkt_info.cmd_sts & ETH_LAYER_4_CHECKSUM_OK) {
  765. skb->ip_summed = CHECKSUM_UNNECESSARY;
  766. skb->csum = htons(
  767. (pkt_info.cmd_sts & 0x0007fff8) >> 3);
  768. }
  769. skb->protocol = eth_type_trans(skb, dev);
  770. #ifdef MV643XX_NAPI
  771. netif_receive_skb(skb);
  772. #else
  773. netif_rx(skb);
  774. #endif
  775. }
  776. dev->last_rx = jiffies;
  777. }
  778. mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */
  779. return received_packets;
  780. }
  781. #ifdef MV643XX_NAPI
  782. /*
  783. * mv643xx_poll
  784. *
  785. * This function is used in case of NAPI
  786. */
  787. static int mv643xx_poll(struct napi_struct *napi, int budget)
  788. {
  789. struct mv643xx_private *mp = container_of(napi, struct mv643xx_private, napi);
  790. struct net_device *dev = mp->dev;
  791. unsigned int port_num = mp->port_num;
  792. int work_done;
  793. #ifdef MV643XX_TX_FAST_REFILL
  794. if (++mp->tx_clean_threshold > 5) {
  795. mv643xx_eth_free_completed_tx_descs(dev);
  796. mp->tx_clean_threshold = 0;
  797. }
  798. #endif
  799. work_done = 0;
  800. if ((rdl(mp, RXQ_CURRENT_DESC_PTR(port_num)))
  801. != (u32) mp->rx_used_desc_q)
  802. work_done = mv643xx_eth_receive_queue(dev, budget);
  803. if (work_done < budget) {
  804. netif_rx_complete(dev, napi);
  805. wrl(mp, INT_CAUSE(port_num), 0);
  806. wrl(mp, INT_CAUSE_EXT(port_num), 0);
  807. wrl(mp, INT_MASK(port_num), ETH_INT_UNMASK_ALL);
  808. }
  809. return work_done;
  810. }
  811. #endif
  812. /* tx ***********************************************************************/
  813. /**
  814. * has_tiny_unaligned_frags - check if skb has any small, unaligned fragments
  815. *
  816. * Hardware can't handle unaligned fragments smaller than 9 bytes.
  817. * This helper function detects that case.
  818. */
  819. static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb)
  820. {
  821. unsigned int frag;
  822. skb_frag_t *fragp;
  823. for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
  824. fragp = &skb_shinfo(skb)->frags[frag];
  825. if (fragp->size <= 8 && fragp->page_offset & 0x7)
  826. return 1;
  827. }
  828. return 0;
  829. }
  830. /**
  831. * eth_alloc_tx_desc_index - return the index of the next available tx desc
  832. */
  833. static int eth_alloc_tx_desc_index(struct mv643xx_private *mp)
  834. {
  835. int tx_desc_curr;
  836. BUG_ON(mp->tx_desc_count >= mp->tx_ring_size);
  837. tx_desc_curr = mp->tx_curr_desc_q;
  838. mp->tx_curr_desc_q = (tx_desc_curr + 1) % mp->tx_ring_size;
  839. BUG_ON(mp->tx_curr_desc_q == mp->tx_used_desc_q);
  840. return tx_desc_curr;
  841. }
  842. /**
  843. * eth_tx_fill_frag_descs - fill tx hw descriptors for an skb's fragments.
  844. *
  845. * Ensure the data for each fragment to be transmitted is mapped properly,
  846. * then fill in descriptors in the tx hw queue.
  847. */
  848. static void eth_tx_fill_frag_descs(struct mv643xx_private *mp,
  849. struct sk_buff *skb)
  850. {
  851. int frag;
  852. int tx_index;
  853. struct eth_tx_desc *desc;
  854. for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
  855. skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag];
  856. tx_index = eth_alloc_tx_desc_index(mp);
  857. desc = &mp->p_tx_desc_area[tx_index];
  858. desc->cmd_sts = ETH_BUFFER_OWNED_BY_DMA;
  859. /* Last Frag enables interrupt and frees the skb */
  860. if (frag == (skb_shinfo(skb)->nr_frags - 1)) {
  861. desc->cmd_sts |= ETH_ZERO_PADDING |
  862. ETH_TX_LAST_DESC |
  863. ETH_TX_ENABLE_INTERRUPT;
  864. mp->tx_skb[tx_index] = skb;
  865. } else
  866. mp->tx_skb[tx_index] = NULL;
  867. desc = &mp->p_tx_desc_area[tx_index];
  868. desc->l4i_chk = 0;
  869. desc->byte_cnt = this_frag->size;
  870. desc->buf_ptr = dma_map_page(NULL, this_frag->page,
  871. this_frag->page_offset,
  872. this_frag->size,
  873. DMA_TO_DEVICE);
  874. }
  875. }
  876. static inline __be16 sum16_as_be(__sum16 sum)
  877. {
  878. return (__force __be16)sum;
  879. }
  880. /**
  881. * eth_tx_submit_descs_for_skb - submit data from an skb to the tx hw
  882. *
  883. * Ensure the data for an skb to be transmitted is mapped properly,
  884. * then fill in descriptors in the tx hw queue and start the hardware.
  885. */
  886. static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
  887. struct sk_buff *skb)
  888. {
  889. int tx_index;
  890. struct eth_tx_desc *desc;
  891. u32 cmd_sts;
  892. int length;
  893. int nr_frags = skb_shinfo(skb)->nr_frags;
  894. cmd_sts = ETH_TX_FIRST_DESC | ETH_GEN_CRC | ETH_BUFFER_OWNED_BY_DMA;
  895. tx_index = eth_alloc_tx_desc_index(mp);
  896. desc = &mp->p_tx_desc_area[tx_index];
  897. if (nr_frags) {
  898. eth_tx_fill_frag_descs(mp, skb);
  899. length = skb_headlen(skb);
  900. mp->tx_skb[tx_index] = NULL;
  901. } else {
  902. cmd_sts |= ETH_ZERO_PADDING |
  903. ETH_TX_LAST_DESC |
  904. ETH_TX_ENABLE_INTERRUPT;
  905. length = skb->len;
  906. mp->tx_skb[tx_index] = skb;
  907. }
  908. desc->byte_cnt = length;
  909. desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
  910. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  911. BUG_ON(skb->protocol != htons(ETH_P_IP));
  912. cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
  913. ETH_GEN_IP_V_4_CHECKSUM |
  914. ip_hdr(skb)->ihl << ETH_TX_IHL_SHIFT;
  915. switch (ip_hdr(skb)->protocol) {
  916. case IPPROTO_UDP:
  917. cmd_sts |= ETH_UDP_FRAME;
  918. desc->l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check));
  919. break;
  920. case IPPROTO_TCP:
  921. desc->l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check));
  922. break;
  923. default:
  924. BUG();
  925. }
  926. } else {
  927. /* Errata BTS #50, IHL must be 5 if no HW checksum */
  928. cmd_sts |= 5 << ETH_TX_IHL_SHIFT;
  929. desc->l4i_chk = 0;
  930. }
  931. /* ensure all other descriptors are written before first cmd_sts */
  932. wmb();
  933. desc->cmd_sts = cmd_sts;
  934. /* ensure all descriptors are written before poking hardware */
  935. wmb();
  936. mv643xx_eth_port_enable_tx(mp, ETH_TX_QUEUES_ENABLED);
  937. mp->tx_desc_count += nr_frags + 1;
  938. }
  939. /**
  940. * mv643xx_eth_start_xmit - queue an skb to the hardware for transmission
  941. *
  942. */
  943. static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)
  944. {
  945. struct mv643xx_private *mp = netdev_priv(dev);
  946. struct net_device_stats *stats = &dev->stats;
  947. unsigned long flags;
  948. BUG_ON(netif_queue_stopped(dev));
  949. if (has_tiny_unaligned_frags(skb) && __skb_linearize(skb)) {
  950. stats->tx_dropped++;
  951. printk(KERN_DEBUG "%s: failed to linearize tiny "
  952. "unaligned fragment\n", dev->name);
  953. return NETDEV_TX_BUSY;
  954. }
  955. spin_lock_irqsave(&mp->lock, flags);
  956. if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) {
  957. printk(KERN_ERR "%s: transmit with queue full\n", dev->name);
  958. netif_stop_queue(dev);
  959. spin_unlock_irqrestore(&mp->lock, flags);
  960. return NETDEV_TX_BUSY;
  961. }
  962. eth_tx_submit_descs_for_skb(mp, skb);
  963. stats->tx_bytes += skb->len;
  964. stats->tx_packets++;
  965. dev->trans_start = jiffies;
  966. if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB)
  967. netif_stop_queue(dev);
  968. spin_unlock_irqrestore(&mp->lock, flags);
  969. return NETDEV_TX_OK;
  970. }
  971. /* mii management interface *************************************************/
  972. static int ethernet_phy_get(struct mv643xx_private *mp);
  973. /*
  974. * eth_port_read_smi_reg - Read PHY registers
  975. *
  976. * DESCRIPTION:
  977. * This routine utilize the SMI interface to interact with the PHY in
  978. * order to perform PHY register read.
  979. *
  980. * INPUT:
  981. * struct mv643xx_private *mp Ethernet Port.
  982. * unsigned int phy_reg PHY register address offset.
  983. * unsigned int *value Register value buffer.
  984. *
  985. * OUTPUT:
  986. * Write the value of a specified PHY register into given buffer.
  987. *
  988. * RETURN:
  989. * false if the PHY is busy or read data is not in valid state.
  990. * true otherwise.
  991. *
  992. */
  993. static void eth_port_read_smi_reg(struct mv643xx_private *mp,
  994. unsigned int phy_reg, unsigned int *value)
  995. {
  996. void __iomem *smi_reg = mp->shared_smi->eth_base + SMI_REG;
  997. int phy_addr = ethernet_phy_get(mp);
  998. unsigned long flags;
  999. int i;
  1000. /* the SMI register is a shared resource */
  1001. spin_lock_irqsave(&mp->shared_smi->phy_lock, flags);
  1002. /* wait for the SMI register to become available */
  1003. for (i = 0; readl(smi_reg) & ETH_SMI_BUSY; i++) {
  1004. if (i == PHY_WAIT_ITERATIONS) {
  1005. printk("%s: PHY busy timeout\n", mp->dev->name);
  1006. goto out;
  1007. }
  1008. udelay(PHY_WAIT_MICRO_SECONDS);
  1009. }
  1010. writel((phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ,
  1011. smi_reg);
  1012. /* now wait for the data to be valid */
  1013. for (i = 0; !(readl(smi_reg) & ETH_SMI_READ_VALID); i++) {
  1014. if (i == PHY_WAIT_ITERATIONS) {
  1015. printk("%s: PHY read timeout\n", mp->dev->name);
  1016. goto out;
  1017. }
  1018. udelay(PHY_WAIT_MICRO_SECONDS);
  1019. }
  1020. *value = readl(smi_reg) & 0xffff;
  1021. out:
  1022. spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags);
  1023. }
  1024. /*
  1025. * eth_port_write_smi_reg - Write to PHY registers
  1026. *
  1027. * DESCRIPTION:
  1028. * This routine utilize the SMI interface to interact with the PHY in
  1029. * order to perform writes to PHY registers.
  1030. *
  1031. * INPUT:
  1032. * struct mv643xx_private *mp Ethernet Port.
  1033. * unsigned int phy_reg PHY register address offset.
  1034. * unsigned int value Register value.
  1035. *
  1036. * OUTPUT:
  1037. * Write the given value to the specified PHY register.
  1038. *
  1039. * RETURN:
  1040. * false if the PHY is busy.
  1041. * true otherwise.
  1042. *
  1043. */
  1044. static void eth_port_write_smi_reg(struct mv643xx_private *mp,
  1045. unsigned int phy_reg, unsigned int value)
  1046. {
  1047. void __iomem *smi_reg = mp->shared_smi->eth_base + SMI_REG;
  1048. int phy_addr = ethernet_phy_get(mp);
  1049. unsigned long flags;
  1050. int i;
  1051. /* the SMI register is a shared resource */
  1052. spin_lock_irqsave(&mp->shared_smi->phy_lock, flags);
  1053. /* wait for the SMI register to become available */
  1054. for (i = 0; readl(smi_reg) & ETH_SMI_BUSY; i++) {
  1055. if (i == PHY_WAIT_ITERATIONS) {
  1056. printk("%s: PHY busy timeout\n", mp->dev->name);
  1057. goto out;
  1058. }
  1059. udelay(PHY_WAIT_MICRO_SECONDS);
  1060. }
  1061. writel((phy_addr << 16) | (phy_reg << 21) |
  1062. ETH_SMI_OPCODE_WRITE | (value & 0xffff), smi_reg);
  1063. out:
  1064. spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags);
  1065. }
  1066. /* mib counters *************************************************************/
  1067. /*
  1068. * eth_clear_mib_counters - Clear all MIB counters
  1069. *
  1070. * DESCRIPTION:
  1071. * This function clears all MIB counters of a specific ethernet port.
  1072. * A read from the MIB counter will reset the counter.
  1073. *
  1074. * INPUT:
  1075. * struct mv643xx_private *mp Ethernet Port.
  1076. *
  1077. * OUTPUT:
  1078. * After reading all MIB counters, the counters resets.
  1079. *
  1080. * RETURN:
  1081. * MIB counter value.
  1082. *
  1083. */
  1084. static void eth_clear_mib_counters(struct mv643xx_private *mp)
  1085. {
  1086. unsigned int port_num = mp->port_num;
  1087. int i;
  1088. /* Perform dummy reads from MIB counters */
  1089. for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
  1090. i += 4)
  1091. rdl(mp, MIB_COUNTERS(port_num) + i);
  1092. }
  1093. static inline u32 read_mib(struct mv643xx_private *mp, int offset)
  1094. {
  1095. return rdl(mp, MIB_COUNTERS(mp->port_num) + offset);
  1096. }
  1097. static void eth_update_mib_counters(struct mv643xx_private *mp)
  1098. {
  1099. struct mv643xx_mib_counters *p = &mp->mib_counters;
  1100. int offset;
  1101. p->good_octets_received +=
  1102. read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
  1103. p->good_octets_received +=
  1104. (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32;
  1105. for (offset = ETH_MIB_BAD_OCTETS_RECEIVED;
  1106. offset <= ETH_MIB_FRAMES_1024_TO_MAX_OCTETS;
  1107. offset += 4)
  1108. *(u32 *)((char *)p + offset) += read_mib(mp, offset);
  1109. p->good_octets_sent += read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_LOW);
  1110. p->good_octets_sent +=
  1111. (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_HIGH) << 32;
  1112. for (offset = ETH_MIB_GOOD_FRAMES_SENT;
  1113. offset <= ETH_MIB_LATE_COLLISION;
  1114. offset += 4)
  1115. *(u32 *)((char *)p + offset) += read_mib(mp, offset);
  1116. }
  1117. /* ethtool ******************************************************************/
  1118. struct mv643xx_stats {
  1119. char stat_string[ETH_GSTRING_LEN];
  1120. int sizeof_stat;
  1121. int stat_offset;
  1122. };
  1123. #define MV643XX_STAT(m) FIELD_SIZEOF(struct mv643xx_private, m), \
  1124. offsetof(struct mv643xx_private, m)
  1125. static const struct mv643xx_stats mv643xx_gstrings_stats[] = {
  1126. { "rx_packets", MV643XX_STAT(stats.rx_packets) },
  1127. { "tx_packets", MV643XX_STAT(stats.tx_packets) },
  1128. { "rx_bytes", MV643XX_STAT(stats.rx_bytes) },
  1129. { "tx_bytes", MV643XX_STAT(stats.tx_bytes) },
  1130. { "rx_errors", MV643XX_STAT(stats.rx_errors) },
  1131. { "tx_errors", MV643XX_STAT(stats.tx_errors) },
  1132. { "rx_dropped", MV643XX_STAT(stats.rx_dropped) },
  1133. { "tx_dropped", MV643XX_STAT(stats.tx_dropped) },
  1134. { "good_octets_received", MV643XX_STAT(mib_counters.good_octets_received) },
  1135. { "bad_octets_received", MV643XX_STAT(mib_counters.bad_octets_received) },
  1136. { "internal_mac_transmit_err", MV643XX_STAT(mib_counters.internal_mac_transmit_err) },
  1137. { "good_frames_received", MV643XX_STAT(mib_counters.good_frames_received) },
  1138. { "bad_frames_received", MV643XX_STAT(mib_counters.bad_frames_received) },
  1139. { "broadcast_frames_received", MV643XX_STAT(mib_counters.broadcast_frames_received) },
  1140. { "multicast_frames_received", MV643XX_STAT(mib_counters.multicast_frames_received) },
  1141. { "frames_64_octets", MV643XX_STAT(mib_counters.frames_64_octets) },
  1142. { "frames_65_to_127_octets", MV643XX_STAT(mib_counters.frames_65_to_127_octets) },
  1143. { "frames_128_to_255_octets", MV643XX_STAT(mib_counters.frames_128_to_255_octets) },
  1144. { "frames_256_to_511_octets", MV643XX_STAT(mib_counters.frames_256_to_511_octets) },
  1145. { "frames_512_to_1023_octets", MV643XX_STAT(mib_counters.frames_512_to_1023_octets) },
  1146. { "frames_1024_to_max_octets", MV643XX_STAT(mib_counters.frames_1024_to_max_octets) },
  1147. { "good_octets_sent", MV643XX_STAT(mib_counters.good_octets_sent) },
  1148. { "good_frames_sent", MV643XX_STAT(mib_counters.good_frames_sent) },
  1149. { "excessive_collision", MV643XX_STAT(mib_counters.excessive_collision) },
  1150. { "multicast_frames_sent", MV643XX_STAT(mib_counters.multicast_frames_sent) },
  1151. { "broadcast_frames_sent", MV643XX_STAT(mib_counters.broadcast_frames_sent) },
  1152. { "unrec_mac_control_received", MV643XX_STAT(mib_counters.unrec_mac_control_received) },
  1153. { "fc_sent", MV643XX_STAT(mib_counters.fc_sent) },
  1154. { "good_fc_received", MV643XX_STAT(mib_counters.good_fc_received) },
  1155. { "bad_fc_received", MV643XX_STAT(mib_counters.bad_fc_received) },
  1156. { "undersize_received", MV643XX_STAT(mib_counters.undersize_received) },
  1157. { "fragments_received", MV643XX_STAT(mib_counters.fragments_received) },
  1158. { "oversize_received", MV643XX_STAT(mib_counters.oversize_received) },
  1159. { "jabber_received", MV643XX_STAT(mib_counters.jabber_received) },
  1160. { "mac_receive_error", MV643XX_STAT(mib_counters.mac_receive_error) },
  1161. { "bad_crc_event", MV643XX_STAT(mib_counters.bad_crc_event) },
  1162. { "collision", MV643XX_STAT(mib_counters.collision) },
  1163. { "late_collision", MV643XX_STAT(mib_counters.late_collision) },
  1164. };
  1165. #define MV643XX_STATS_LEN ARRAY_SIZE(mv643xx_gstrings_stats)
  1166. static int mv643xx_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1167. {
  1168. struct mv643xx_private *mp = netdev_priv(dev);
  1169. int err;
  1170. spin_lock_irq(&mp->lock);
  1171. err = mii_ethtool_gset(&mp->mii, cmd);
  1172. spin_unlock_irq(&mp->lock);
  1173. /* The PHY may support 1000baseT_Half, but the mv643xx does not */
  1174. cmd->supported &= ~SUPPORTED_1000baseT_Half;
  1175. cmd->advertising &= ~ADVERTISED_1000baseT_Half;
  1176. return err;
  1177. }
  1178. static int mv643xx_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1179. {
  1180. struct mv643xx_private *mp = netdev_priv(dev);
  1181. int err;
  1182. spin_lock_irq(&mp->lock);
  1183. err = mii_ethtool_sset(&mp->mii, cmd);
  1184. spin_unlock_irq(&mp->lock);
  1185. return err;
  1186. }
  1187. static void mv643xx_get_drvinfo(struct net_device *netdev,
  1188. struct ethtool_drvinfo *drvinfo)
  1189. {
  1190. strncpy(drvinfo->driver, mv643xx_driver_name, 32);
  1191. strncpy(drvinfo->version, mv643xx_driver_version, 32);
  1192. strncpy(drvinfo->fw_version, "N/A", 32);
  1193. strncpy(drvinfo->bus_info, "mv643xx", 32);
  1194. drvinfo->n_stats = MV643XX_STATS_LEN;
  1195. }
  1196. static int mv643xx_eth_nway_restart(struct net_device *dev)
  1197. {
  1198. struct mv643xx_private *mp = netdev_priv(dev);
  1199. return mii_nway_restart(&mp->mii);
  1200. }
  1201. static u32 mv643xx_eth_get_link(struct net_device *dev)
  1202. {
  1203. struct mv643xx_private *mp = netdev_priv(dev);
  1204. return mii_link_ok(&mp->mii);
  1205. }
  1206. static void mv643xx_get_strings(struct net_device *netdev, uint32_t stringset,
  1207. uint8_t *data)
  1208. {
  1209. int i;
  1210. switch(stringset) {
  1211. case ETH_SS_STATS:
  1212. for (i=0; i < MV643XX_STATS_LEN; i++) {
  1213. memcpy(data + i * ETH_GSTRING_LEN,
  1214. mv643xx_gstrings_stats[i].stat_string,
  1215. ETH_GSTRING_LEN);
  1216. }
  1217. break;
  1218. }
  1219. }
  1220. static void mv643xx_get_ethtool_stats(struct net_device *netdev,
  1221. struct ethtool_stats *stats, uint64_t *data)
  1222. {
  1223. struct mv643xx_private *mp = netdev->priv;
  1224. int i;
  1225. eth_update_mib_counters(mp);
  1226. for (i = 0; i < MV643XX_STATS_LEN; i++) {
  1227. char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset;
  1228. data[i] = (mv643xx_gstrings_stats[i].sizeof_stat ==
  1229. sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
  1230. }
  1231. }
  1232. static int mv643xx_get_sset_count(struct net_device *netdev, int sset)
  1233. {
  1234. switch (sset) {
  1235. case ETH_SS_STATS:
  1236. return MV643XX_STATS_LEN;
  1237. default:
  1238. return -EOPNOTSUPP;
  1239. }
  1240. }
  1241. static const struct ethtool_ops mv643xx_ethtool_ops = {
  1242. .get_settings = mv643xx_get_settings,
  1243. .set_settings = mv643xx_set_settings,
  1244. .get_drvinfo = mv643xx_get_drvinfo,
  1245. .get_link = mv643xx_eth_get_link,
  1246. .set_sg = ethtool_op_set_sg,
  1247. .get_sset_count = mv643xx_get_sset_count,
  1248. .get_ethtool_stats = mv643xx_get_ethtool_stats,
  1249. .get_strings = mv643xx_get_strings,
  1250. .nway_reset = mv643xx_eth_nway_restart,
  1251. };
  1252. /* address handling *********************************************************/
  1253. /*
  1254. * eth_port_uc_addr_get - Read the MAC address from the port's hw registers
  1255. */
  1256. static void eth_port_uc_addr_get(struct mv643xx_private *mp,
  1257. unsigned char *p_addr)
  1258. {
  1259. unsigned int port_num = mp->port_num;
  1260. unsigned int mac_h;
  1261. unsigned int mac_l;
  1262. mac_h = rdl(mp, MAC_ADDR_HIGH(port_num));
  1263. mac_l = rdl(mp, MAC_ADDR_LOW(port_num));
  1264. p_addr[0] = (mac_h >> 24) & 0xff;
  1265. p_addr[1] = (mac_h >> 16) & 0xff;
  1266. p_addr[2] = (mac_h >> 8) & 0xff;
  1267. p_addr[3] = mac_h & 0xff;
  1268. p_addr[4] = (mac_l >> 8) & 0xff;
  1269. p_addr[5] = mac_l & 0xff;
  1270. }
  1271. /*
  1272. * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
  1273. *
  1274. * DESCRIPTION:
  1275. * Go through all the DA filter tables (Unicast, Special Multicast &
  1276. * Other Multicast) and set each entry to 0.
  1277. *
  1278. * INPUT:
  1279. * struct mv643xx_private *mp Ethernet Port.
  1280. *
  1281. * OUTPUT:
  1282. * Multicast and Unicast packets are rejected.
  1283. *
  1284. * RETURN:
  1285. * None.
  1286. */
  1287. static void eth_port_init_mac_tables(struct mv643xx_private *mp)
  1288. {
  1289. unsigned int port_num = mp->port_num;
  1290. int table_index;
  1291. /* Clear DA filter unicast table (Ex_dFUT) */
  1292. for (table_index = 0; table_index <= 0xC; table_index += 4)
  1293. wrl(mp, UNICAST_TABLE(port_num) + table_index, 0);
  1294. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1295. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1296. wrl(mp, SPECIAL_MCAST_TABLE(port_num) + table_index, 0);
  1297. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1298. wrl(mp, OTHER_MCAST_TABLE(port_num) + table_index, 0);
  1299. }
  1300. }
  1301. /*
  1302. * The entries in each table are indexed by a hash of a packet's MAC
  1303. * address. One bit in each entry determines whether the packet is
  1304. * accepted. There are 4 entries (each 8 bits wide) in each register
  1305. * of the table. The bits in each entry are defined as follows:
  1306. * 0 Accept=1, Drop=0
  1307. * 3-1 Queue (ETH_Q0=0)
  1308. * 7-4 Reserved = 0;
  1309. */
  1310. static void eth_port_set_filter_table_entry(struct mv643xx_private *mp,
  1311. int table, unsigned char entry)
  1312. {
  1313. unsigned int table_reg;
  1314. unsigned int tbl_offset;
  1315. unsigned int reg_offset;
  1316. tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */
  1317. reg_offset = entry % 4; /* Entry offset within the register */
  1318. /* Set "accepts frame bit" at specified table entry */
  1319. table_reg = rdl(mp, table + tbl_offset);
  1320. table_reg |= 0x01 << (8 * reg_offset);
  1321. wrl(mp, table + tbl_offset, table_reg);
  1322. }
  1323. /*
  1324. * eth_port_uc_addr_set - Write a MAC address into the port's hw registers
  1325. */
  1326. static void eth_port_uc_addr_set(struct mv643xx_private *mp,
  1327. unsigned char *p_addr)
  1328. {
  1329. unsigned int port_num = mp->port_num;
  1330. unsigned int mac_h;
  1331. unsigned int mac_l;
  1332. int table;
  1333. mac_l = (p_addr[4] << 8) | (p_addr[5]);
  1334. mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
  1335. (p_addr[3] << 0);
  1336. wrl(mp, MAC_ADDR_LOW(port_num), mac_l);
  1337. wrl(mp, MAC_ADDR_HIGH(port_num), mac_h);
  1338. /* Accept frames with this address */
  1339. table = UNICAST_TABLE(port_num);
  1340. eth_port_set_filter_table_entry(mp, table, p_addr[5] & 0x0f);
  1341. }
  1342. /*
  1343. * mv643xx_eth_update_mac_address
  1344. *
  1345. * Update the MAC address of the port in the address table
  1346. *
  1347. * Input : pointer to ethernet interface network device structure
  1348. * Output : N/A
  1349. */
  1350. static void mv643xx_eth_update_mac_address(struct net_device *dev)
  1351. {
  1352. struct mv643xx_private *mp = netdev_priv(dev);
  1353. eth_port_init_mac_tables(mp);
  1354. eth_port_uc_addr_set(mp, dev->dev_addr);
  1355. }
  1356. /*
  1357. * mv643xx_eth_set_mac_address
  1358. *
  1359. * Change the interface's mac address.
  1360. * No special hardware thing should be done because interface is always
  1361. * put in promiscuous mode.
  1362. *
  1363. * Input : pointer to ethernet interface network device structure and
  1364. * a pointer to the designated entry to be added to the cache.
  1365. * Output : zero upon success, negative upon failure
  1366. */
  1367. static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr)
  1368. {
  1369. int i;
  1370. for (i = 0; i < 6; i++)
  1371. /* +2 is for the offset of the HW addr type */
  1372. dev->dev_addr[i] = ((unsigned char *)addr)[i + 2];
  1373. mv643xx_eth_update_mac_address(dev);
  1374. return 0;
  1375. }
  1376. /*
  1377. * eth_port_mc_addr - Multicast address settings.
  1378. *
  1379. * The MV device supports multicast using two tables:
  1380. * 1) Special Multicast Table for MAC addresses of the form
  1381. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_FF).
  1382. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  1383. * Table entries in the DA-Filter table.
  1384. * 2) Other Multicast Table for multicast of another type. A CRC-8bit
  1385. * is used as an index to the Other Multicast Table entries in the
  1386. * DA-Filter table. This function calculates the CRC-8bit value.
  1387. * In either case, eth_port_set_filter_table_entry() is then called
  1388. * to set to set the actual table entry.
  1389. */
  1390. static void eth_port_mc_addr(struct mv643xx_private *mp, unsigned char *p_addr)
  1391. {
  1392. unsigned int port_num = mp->port_num;
  1393. unsigned int mac_h;
  1394. unsigned int mac_l;
  1395. unsigned char crc_result = 0;
  1396. int table;
  1397. int mac_array[48];
  1398. int crc[8];
  1399. int i;
  1400. if ((p_addr[0] == 0x01) && (p_addr[1] == 0x00) &&
  1401. (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) {
  1402. table = SPECIAL_MCAST_TABLE(port_num);
  1403. eth_port_set_filter_table_entry(mp, table, p_addr[5]);
  1404. return;
  1405. }
  1406. /* Calculate CRC-8 out of the given address */
  1407. mac_h = (p_addr[0] << 8) | (p_addr[1]);
  1408. mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
  1409. (p_addr[4] << 8) | (p_addr[5] << 0);
  1410. for (i = 0; i < 32; i++)
  1411. mac_array[i] = (mac_l >> i) & 0x1;
  1412. for (i = 32; i < 48; i++)
  1413. mac_array[i] = (mac_h >> (i - 32)) & 0x1;
  1414. crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^
  1415. mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^
  1416. mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
  1417. mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^
  1418. mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0];
  1419. crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
  1420. mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^
  1421. mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
  1422. mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^
  1423. mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^
  1424. mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
  1425. mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0];
  1426. crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^
  1427. mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^
  1428. mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
  1429. mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^
  1430. mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^
  1431. mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0];
  1432. crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
  1433. mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^
  1434. mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
  1435. mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
  1436. mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^
  1437. mac_array[3] ^ mac_array[2] ^ mac_array[1];
  1438. crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^
  1439. mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^
  1440. mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
  1441. mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^
  1442. mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^
  1443. mac_array[3] ^ mac_array[2];
  1444. crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^
  1445. mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^
  1446. mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
  1447. mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^
  1448. mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^
  1449. mac_array[4] ^ mac_array[3];
  1450. crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^
  1451. mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^
  1452. mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
  1453. mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^
  1454. mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^
  1455. mac_array[4];
  1456. crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^
  1457. mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^
  1458. mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
  1459. mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^
  1460. mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5];
  1461. for (i = 0; i < 8; i++)
  1462. crc_result = crc_result | (crc[i] << i);
  1463. table = OTHER_MCAST_TABLE(port_num);
  1464. eth_port_set_filter_table_entry(mp, table, crc_result);
  1465. }
  1466. /*
  1467. * Set the entire multicast list based on dev->mc_list.
  1468. */
  1469. static void eth_port_set_multicast_list(struct net_device *dev)
  1470. {
  1471. struct dev_mc_list *mc_list;
  1472. int i;
  1473. int table_index;
  1474. struct mv643xx_private *mp = netdev_priv(dev);
  1475. unsigned int eth_port_num = mp->port_num;
  1476. /* If the device is in promiscuous mode or in all multicast mode,
  1477. * we will fully populate both multicast tables with accept.
  1478. * This is guaranteed to yield a match on all multicast addresses...
  1479. */
  1480. if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) {
  1481. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1482. /* Set all entries in DA filter special multicast
  1483. * table (Ex_dFSMT)
  1484. * Set for ETH_Q0 for now
  1485. * Bits
  1486. * 0 Accept=1, Drop=0
  1487. * 3-1 Queue ETH_Q0=0
  1488. * 7-4 Reserved = 0;
  1489. */
  1490. wrl(mp, SPECIAL_MCAST_TABLE(eth_port_num) + table_index, 0x01010101);
  1491. /* Set all entries in DA filter other multicast
  1492. * table (Ex_dFOMT)
  1493. * Set for ETH_Q0 for now
  1494. * Bits
  1495. * 0 Accept=1, Drop=0
  1496. * 3-1 Queue ETH_Q0=0
  1497. * 7-4 Reserved = 0;
  1498. */
  1499. wrl(mp, OTHER_MCAST_TABLE(eth_port_num) + table_index, 0x01010101);
  1500. }
  1501. return;
  1502. }
  1503. /* We will clear out multicast tables every time we get the list.
  1504. * Then add the entire new list...
  1505. */
  1506. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1507. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1508. wrl(mp, SPECIAL_MCAST_TABLE(eth_port_num) + table_index, 0);
  1509. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1510. wrl(mp, OTHER_MCAST_TABLE(eth_port_num) + table_index, 0);
  1511. }
  1512. /* Get pointer to net_device multicast list and add each one... */
  1513. for (i = 0, mc_list = dev->mc_list;
  1514. (i < 256) && (mc_list != NULL) && (i < dev->mc_count);
  1515. i++, mc_list = mc_list->next)
  1516. if (mc_list->dmi_addrlen == 6)
  1517. eth_port_mc_addr(mp, mc_list->dmi_addr);
  1518. }
  1519. /*
  1520. * mv643xx_eth_set_rx_mode
  1521. *
  1522. * Change from promiscuos to regular rx mode
  1523. *
  1524. * Input : pointer to ethernet interface network device structure
  1525. * Output : N/A
  1526. */
  1527. static void mv643xx_eth_set_rx_mode(struct net_device *dev)
  1528. {
  1529. struct mv643xx_private *mp = netdev_priv(dev);
  1530. u32 config_reg;
  1531. config_reg = rdl(mp, PORT_CONFIG(mp->port_num));
  1532. if (dev->flags & IFF_PROMISC)
  1533. config_reg |= UNICAST_PROMISCUOUS_MODE;
  1534. else
  1535. config_reg &= ~UNICAST_PROMISCUOUS_MODE;
  1536. wrl(mp, PORT_CONFIG(mp->port_num), config_reg);
  1537. eth_port_set_multicast_list(dev);
  1538. }
  1539. /* rx/tx queue initialisation ***********************************************/
  1540. /*
  1541. * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
  1542. *
  1543. * DESCRIPTION:
  1544. * This function prepares a Rx chained list of descriptors and packet
  1545. * buffers in a form of a ring. The routine must be called after port
  1546. * initialization routine and before port start routine.
  1547. * The Ethernet SDMA engine uses CPU bus addresses to access the various
  1548. * devices in the system (i.e. DRAM). This function uses the ethernet
  1549. * struct 'virtual to physical' routine (set by the user) to set the ring
  1550. * with physical addresses.
  1551. *
  1552. * INPUT:
  1553. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  1554. *
  1555. * OUTPUT:
  1556. * The routine updates the Ethernet port control struct with information
  1557. * regarding the Rx descriptors and buffers.
  1558. *
  1559. * RETURN:
  1560. * None.
  1561. */
  1562. static void ether_init_rx_desc_ring(struct mv643xx_private *mp)
  1563. {
  1564. volatile struct eth_rx_desc *p_rx_desc;
  1565. int rx_desc_num = mp->rx_ring_size;
  1566. int i;
  1567. /* initialize the next_desc_ptr links in the Rx descriptors ring */
  1568. p_rx_desc = (struct eth_rx_desc *)mp->p_rx_desc_area;
  1569. for (i = 0; i < rx_desc_num; i++) {
  1570. p_rx_desc[i].next_desc_ptr = mp->rx_desc_dma +
  1571. ((i + 1) % rx_desc_num) * sizeof(struct eth_rx_desc);
  1572. }
  1573. /* Save Rx desc pointer to driver struct. */
  1574. mp->rx_curr_desc_q = 0;
  1575. mp->rx_used_desc_q = 0;
  1576. mp->rx_desc_area_size = rx_desc_num * sizeof(struct eth_rx_desc);
  1577. }
  1578. static void mv643xx_eth_free_rx_rings(struct net_device *dev)
  1579. {
  1580. struct mv643xx_private *mp = netdev_priv(dev);
  1581. int curr;
  1582. /* Stop RX Queues */
  1583. mv643xx_eth_port_disable_rx(mp);
  1584. /* Free preallocated skb's on RX rings */
  1585. for (curr = 0; mp->rx_desc_count && curr < mp->rx_ring_size; curr++) {
  1586. if (mp->rx_skb[curr]) {
  1587. dev_kfree_skb(mp->rx_skb[curr]);
  1588. mp->rx_desc_count--;
  1589. }
  1590. }
  1591. if (mp->rx_desc_count)
  1592. printk(KERN_ERR
  1593. "%s: Error in freeing Rx Ring. %d skb's still"
  1594. " stuck in RX Ring - ignoring them\n", dev->name,
  1595. mp->rx_desc_count);
  1596. /* Free RX ring */
  1597. if (mp->rx_sram_size)
  1598. iounmap(mp->p_rx_desc_area);
  1599. else
  1600. dma_free_coherent(NULL, mp->rx_desc_area_size,
  1601. mp->p_rx_desc_area, mp->rx_desc_dma);
  1602. }
  1603. /*
  1604. * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory.
  1605. *
  1606. * DESCRIPTION:
  1607. * This function prepares a Tx chained list of descriptors and packet
  1608. * buffers in a form of a ring. The routine must be called after port
  1609. * initialization routine and before port start routine.
  1610. * The Ethernet SDMA engine uses CPU bus addresses to access the various
  1611. * devices in the system (i.e. DRAM). This function uses the ethernet
  1612. * struct 'virtual to physical' routine (set by the user) to set the ring
  1613. * with physical addresses.
  1614. *
  1615. * INPUT:
  1616. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  1617. *
  1618. * OUTPUT:
  1619. * The routine updates the Ethernet port control struct with information
  1620. * regarding the Tx descriptors and buffers.
  1621. *
  1622. * RETURN:
  1623. * None.
  1624. */
  1625. static void ether_init_tx_desc_ring(struct mv643xx_private *mp)
  1626. {
  1627. int tx_desc_num = mp->tx_ring_size;
  1628. struct eth_tx_desc *p_tx_desc;
  1629. int i;
  1630. /* Initialize the next_desc_ptr links in the Tx descriptors ring */
  1631. p_tx_desc = (struct eth_tx_desc *)mp->p_tx_desc_area;
  1632. for (i = 0; i < tx_desc_num; i++) {
  1633. p_tx_desc[i].next_desc_ptr = mp->tx_desc_dma +
  1634. ((i + 1) % tx_desc_num) * sizeof(struct eth_tx_desc);
  1635. }
  1636. mp->tx_curr_desc_q = 0;
  1637. mp->tx_used_desc_q = 0;
  1638. mp->tx_desc_area_size = tx_desc_num * sizeof(struct eth_tx_desc);
  1639. }
  1640. /**
  1641. * mv643xx_eth_free_tx_descs - Free the tx desc data for completed descriptors
  1642. *
  1643. * If force is non-zero, frees uncompleted descriptors as well
  1644. */
  1645. static int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
  1646. {
  1647. struct mv643xx_private *mp = netdev_priv(dev);
  1648. struct eth_tx_desc *desc;
  1649. u32 cmd_sts;
  1650. struct sk_buff *skb;
  1651. unsigned long flags;
  1652. int tx_index;
  1653. dma_addr_t addr;
  1654. int count;
  1655. int released = 0;
  1656. while (mp->tx_desc_count > 0) {
  1657. spin_lock_irqsave(&mp->lock, flags);
  1658. /* tx_desc_count might have changed before acquiring the lock */
  1659. if (mp->tx_desc_count <= 0) {
  1660. spin_unlock_irqrestore(&mp->lock, flags);
  1661. return released;
  1662. }
  1663. tx_index = mp->tx_used_desc_q;
  1664. desc = &mp->p_tx_desc_area[tx_index];
  1665. cmd_sts = desc->cmd_sts;
  1666. if (!force && (cmd_sts & ETH_BUFFER_OWNED_BY_DMA)) {
  1667. spin_unlock_irqrestore(&mp->lock, flags);
  1668. return released;
  1669. }
  1670. mp->tx_used_desc_q = (tx_index + 1) % mp->tx_ring_size;
  1671. mp->tx_desc_count--;
  1672. addr = desc->buf_ptr;
  1673. count = desc->byte_cnt;
  1674. skb = mp->tx_skb[tx_index];
  1675. if (skb)
  1676. mp->tx_skb[tx_index] = NULL;
  1677. if (cmd_sts & ETH_ERROR_SUMMARY) {
  1678. printk("%s: Error in TX\n", dev->name);
  1679. dev->stats.tx_errors++;
  1680. }
  1681. spin_unlock_irqrestore(&mp->lock, flags);
  1682. if (cmd_sts & ETH_TX_FIRST_DESC)
  1683. dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
  1684. else
  1685. dma_unmap_page(NULL, addr, count, DMA_TO_DEVICE);
  1686. if (skb)
  1687. dev_kfree_skb_irq(skb);
  1688. released = 1;
  1689. }
  1690. return released;
  1691. }
  1692. static void mv643xx_eth_free_completed_tx_descs(struct net_device *dev)
  1693. {
  1694. struct mv643xx_private *mp = netdev_priv(dev);
  1695. if (mv643xx_eth_free_tx_descs(dev, 0) &&
  1696. mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB)
  1697. netif_wake_queue(dev);
  1698. }
  1699. static void mv643xx_eth_free_all_tx_descs(struct net_device *dev)
  1700. {
  1701. mv643xx_eth_free_tx_descs(dev, 1);
  1702. }
  1703. static void mv643xx_eth_free_tx_rings(struct net_device *dev)
  1704. {
  1705. struct mv643xx_private *mp = netdev_priv(dev);
  1706. /* Stop Tx Queues */
  1707. mv643xx_eth_port_disable_tx(mp);
  1708. /* Free outstanding skb's on TX ring */
  1709. mv643xx_eth_free_all_tx_descs(dev);
  1710. BUG_ON(mp->tx_used_desc_q != mp->tx_curr_desc_q);
  1711. /* Free TX ring */
  1712. if (mp->tx_sram_size)
  1713. iounmap(mp->p_tx_desc_area);
  1714. else
  1715. dma_free_coherent(NULL, mp->tx_desc_area_size,
  1716. mp->p_tx_desc_area, mp->tx_desc_dma);
  1717. }
  1718. /* netdev ops and related ***************************************************/
  1719. static void eth_port_reset(struct mv643xx_private *mp);
  1720. /* Set the mv643xx port configuration register for the speed/duplex mode. */
  1721. static void mv643xx_eth_update_pscr(struct net_device *dev,
  1722. struct ethtool_cmd *ecmd)
  1723. {
  1724. struct mv643xx_private *mp = netdev_priv(dev);
  1725. int port_num = mp->port_num;
  1726. u32 o_pscr, n_pscr;
  1727. unsigned int queues;
  1728. o_pscr = rdl(mp, PORT_SERIAL_CONTROL(port_num));
  1729. n_pscr = o_pscr;
  1730. /* clear speed, duplex and rx buffer size fields */
  1731. n_pscr &= ~(SET_MII_SPEED_TO_100 |
  1732. SET_GMII_SPEED_TO_1000 |
  1733. SET_FULL_DUPLEX_MODE |
  1734. MAX_RX_PACKET_MASK);
  1735. if (ecmd->duplex == DUPLEX_FULL)
  1736. n_pscr |= SET_FULL_DUPLEX_MODE;
  1737. if (ecmd->speed == SPEED_1000)
  1738. n_pscr |= SET_GMII_SPEED_TO_1000 |
  1739. MAX_RX_PACKET_9700BYTE;
  1740. else {
  1741. if (ecmd->speed == SPEED_100)
  1742. n_pscr |= SET_MII_SPEED_TO_100;
  1743. n_pscr |= MAX_RX_PACKET_1522BYTE;
  1744. }
  1745. if (n_pscr != o_pscr) {
  1746. if ((o_pscr & SERIAL_PORT_ENABLE) == 0)
  1747. wrl(mp, PORT_SERIAL_CONTROL(port_num), n_pscr);
  1748. else {
  1749. queues = mv643xx_eth_port_disable_tx(mp);
  1750. o_pscr &= ~SERIAL_PORT_ENABLE;
  1751. wrl(mp, PORT_SERIAL_CONTROL(port_num), o_pscr);
  1752. wrl(mp, PORT_SERIAL_CONTROL(port_num), n_pscr);
  1753. wrl(mp, PORT_SERIAL_CONTROL(port_num), n_pscr);
  1754. if (queues)
  1755. mv643xx_eth_port_enable_tx(mp, queues);
  1756. }
  1757. }
  1758. }
  1759. /*
  1760. * mv643xx_eth_int_handler
  1761. *
  1762. * Main interrupt handler for the gigbit ethernet ports
  1763. *
  1764. * Input : irq - irq number (not used)
  1765. * dev_id - a pointer to the required interface's data structure
  1766. * regs - not used
  1767. * Output : N/A
  1768. */
  1769. static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id)
  1770. {
  1771. struct net_device *dev = (struct net_device *)dev_id;
  1772. struct mv643xx_private *mp = netdev_priv(dev);
  1773. u32 eth_int_cause, eth_int_cause_ext = 0;
  1774. unsigned int port_num = mp->port_num;
  1775. /* Read interrupt cause registers */
  1776. eth_int_cause = rdl(mp, INT_CAUSE(port_num)) & ETH_INT_UNMASK_ALL;
  1777. if (eth_int_cause & ETH_INT_CAUSE_EXT) {
  1778. eth_int_cause_ext = rdl(mp, INT_CAUSE_EXT(port_num))
  1779. & ETH_INT_UNMASK_ALL_EXT;
  1780. wrl(mp, INT_CAUSE_EXT(port_num), ~eth_int_cause_ext);
  1781. }
  1782. /* PHY status changed */
  1783. if (eth_int_cause_ext & (ETH_INT_CAUSE_PHY | ETH_INT_CAUSE_STATE)) {
  1784. struct ethtool_cmd cmd;
  1785. if (mii_link_ok(&mp->mii)) {
  1786. mii_ethtool_gset(&mp->mii, &cmd);
  1787. mv643xx_eth_update_pscr(dev, &cmd);
  1788. mv643xx_eth_port_enable_tx(mp, ETH_TX_QUEUES_ENABLED);
  1789. if (!netif_carrier_ok(dev)) {
  1790. netif_carrier_on(dev);
  1791. if (mp->tx_ring_size - mp->tx_desc_count >=
  1792. MAX_DESCS_PER_SKB)
  1793. netif_wake_queue(dev);
  1794. }
  1795. } else if (netif_carrier_ok(dev)) {
  1796. netif_stop_queue(dev);
  1797. netif_carrier_off(dev);
  1798. }
  1799. }
  1800. #ifdef MV643XX_NAPI
  1801. if (eth_int_cause & ETH_INT_CAUSE_RX) {
  1802. /* schedule the NAPI poll routine to maintain port */
  1803. wrl(mp, INT_MASK(port_num), ETH_INT_MASK_ALL);
  1804. /* wait for previous write to complete */
  1805. rdl(mp, INT_MASK(port_num));
  1806. netif_rx_schedule(dev, &mp->napi);
  1807. }
  1808. #else
  1809. if (eth_int_cause & ETH_INT_CAUSE_RX)
  1810. mv643xx_eth_receive_queue(dev, INT_MAX);
  1811. #endif
  1812. if (eth_int_cause_ext & ETH_INT_CAUSE_TX)
  1813. mv643xx_eth_free_completed_tx_descs(dev);
  1814. /*
  1815. * If no real interrupt occured, exit.
  1816. * This can happen when using gigE interrupt coalescing mechanism.
  1817. */
  1818. if ((eth_int_cause == 0x0) && (eth_int_cause_ext == 0x0))
  1819. return IRQ_NONE;
  1820. return IRQ_HANDLED;
  1821. }
  1822. /*
  1823. * ethernet_phy_reset - Reset Ethernet port PHY.
  1824. *
  1825. * DESCRIPTION:
  1826. * This routine utilizes the SMI interface to reset the ethernet port PHY.
  1827. *
  1828. * INPUT:
  1829. * struct mv643xx_private *mp Ethernet Port.
  1830. *
  1831. * OUTPUT:
  1832. * The PHY is reset.
  1833. *
  1834. * RETURN:
  1835. * None.
  1836. *
  1837. */
  1838. static void ethernet_phy_reset(struct mv643xx_private *mp)
  1839. {
  1840. unsigned int phy_reg_data;
  1841. /* Reset the PHY */
  1842. eth_port_read_smi_reg(mp, 0, &phy_reg_data);
  1843. phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
  1844. eth_port_write_smi_reg(mp, 0, phy_reg_data);
  1845. /* wait for PHY to come out of reset */
  1846. do {
  1847. udelay(1);
  1848. eth_port_read_smi_reg(mp, 0, &phy_reg_data);
  1849. } while (phy_reg_data & 0x8000);
  1850. }
  1851. /*
  1852. * eth_port_start - Start the Ethernet port activity.
  1853. *
  1854. * DESCRIPTION:
  1855. * This routine prepares the Ethernet port for Rx and Tx activity:
  1856. * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
  1857. * has been initialized a descriptor's ring (using
  1858. * ether_init_tx_desc_ring for Tx and ether_init_rx_desc_ring for Rx)
  1859. * 2. Initialize and enable the Ethernet configuration port by writing to
  1860. * the port's configuration and command registers.
  1861. * 3. Initialize and enable the SDMA by writing to the SDMA's
  1862. * configuration and command registers. After completing these steps,
  1863. * the ethernet port SDMA can starts to perform Rx and Tx activities.
  1864. *
  1865. * Note: Each Rx and Tx queue descriptor's list must be initialized prior
  1866. * to calling this function (use ether_init_tx_desc_ring for Tx queues
  1867. * and ether_init_rx_desc_ring for Rx queues).
  1868. *
  1869. * INPUT:
  1870. * dev - a pointer to the required interface
  1871. *
  1872. * OUTPUT:
  1873. * Ethernet port is ready to receive and transmit.
  1874. *
  1875. * RETURN:
  1876. * None.
  1877. */
  1878. static void eth_port_start(struct net_device *dev)
  1879. {
  1880. struct mv643xx_private *mp = netdev_priv(dev);
  1881. unsigned int port_num = mp->port_num;
  1882. int tx_curr_desc, rx_curr_desc;
  1883. u32 pscr;
  1884. struct ethtool_cmd ethtool_cmd;
  1885. /* Assignment of Tx CTRP of given queue */
  1886. tx_curr_desc = mp->tx_curr_desc_q;
  1887. wrl(mp, TXQ_CURRENT_DESC_PTR(port_num),
  1888. (u32)((struct eth_tx_desc *)mp->tx_desc_dma + tx_curr_desc));
  1889. /* Assignment of Rx CRDP of given queue */
  1890. rx_curr_desc = mp->rx_curr_desc_q;
  1891. wrl(mp, RXQ_CURRENT_DESC_PTR(port_num),
  1892. (u32)((struct eth_rx_desc *)mp->rx_desc_dma + rx_curr_desc));
  1893. /* Add the assigned Ethernet address to the port's address table */
  1894. eth_port_uc_addr_set(mp, dev->dev_addr);
  1895. /*
  1896. * Receive all unmatched unicast, TCP, UDP, BPDU and broadcast
  1897. * frames to RX queue #0.
  1898. */
  1899. wrl(mp, PORT_CONFIG(port_num), 0x00000000);
  1900. /*
  1901. * Treat BPDUs as normal multicasts, and disable partition mode.
  1902. */
  1903. wrl(mp, PORT_CONFIG_EXT(port_num), 0x00000000);
  1904. pscr = rdl(mp, PORT_SERIAL_CONTROL(port_num));
  1905. pscr &= ~(SERIAL_PORT_ENABLE | FORCE_LINK_PASS);
  1906. wrl(mp, PORT_SERIAL_CONTROL(port_num), pscr);
  1907. pscr |= DISABLE_AUTO_NEG_FOR_FLOW_CTRL |
  1908. DISABLE_AUTO_NEG_SPEED_GMII |
  1909. DISABLE_AUTO_NEG_FOR_DUPLX |
  1910. DO_NOT_FORCE_LINK_FAIL |
  1911. SERIAL_PORT_CONTROL_RESERVED;
  1912. wrl(mp, PORT_SERIAL_CONTROL(port_num), pscr);
  1913. pscr |= SERIAL_PORT_ENABLE;
  1914. wrl(mp, PORT_SERIAL_CONTROL(port_num), pscr);
  1915. /* Assign port SDMA configuration */
  1916. wrl(mp, SDMA_CONFIG(port_num), PORT_SDMA_CONFIG_DEFAULT_VALUE);
  1917. /* Enable port Rx. */
  1918. mv643xx_eth_port_enable_rx(mp, ETH_RX_QUEUES_ENABLED);
  1919. /* Disable port bandwidth limits by clearing MTU register */
  1920. wrl(mp, TX_BW_MTU(port_num), 0);
  1921. /* save phy settings across reset */
  1922. mv643xx_get_settings(dev, &ethtool_cmd);
  1923. ethernet_phy_reset(mp);
  1924. mv643xx_set_settings(dev, &ethtool_cmd);
  1925. }
  1926. #ifdef MV643XX_COAL
  1927. /*
  1928. * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path
  1929. *
  1930. * DESCRIPTION:
  1931. * This routine sets the RX coalescing interrupt mechanism parameter.
  1932. * This parameter is a timeout counter, that counts in 64 t_clk
  1933. * chunks ; that when timeout event occurs a maskable interrupt
  1934. * occurs.
  1935. * The parameter is calculated using the tClk of the MV-643xx chip
  1936. * , and the required delay of the interrupt in usec.
  1937. *
  1938. * INPUT:
  1939. * struct mv643xx_private *mp Ethernet port
  1940. * unsigned int delay Delay in usec
  1941. *
  1942. * OUTPUT:
  1943. * Interrupt coalescing mechanism value is set in MV-643xx chip.
  1944. *
  1945. * RETURN:
  1946. * The interrupt coalescing value set in the gigE port.
  1947. *
  1948. */
  1949. static unsigned int eth_port_set_rx_coal(struct mv643xx_private *mp,
  1950. unsigned int delay)
  1951. {
  1952. unsigned int port_num = mp->port_num;
  1953. unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64;
  1954. /* Set RX Coalescing mechanism */
  1955. wrl(mp, SDMA_CONFIG(port_num),
  1956. ((coal & 0x3fff) << 8) |
  1957. (rdl(mp, SDMA_CONFIG(port_num))
  1958. & 0xffc000ff));
  1959. return coal;
  1960. }
  1961. #endif
  1962. /*
  1963. * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path
  1964. *
  1965. * DESCRIPTION:
  1966. * This routine sets the TX coalescing interrupt mechanism parameter.
  1967. * This parameter is a timeout counter, that counts in 64 t_clk
  1968. * chunks ; that when timeout event occurs a maskable interrupt
  1969. * occurs.
  1970. * The parameter is calculated using the t_cLK frequency of the
  1971. * MV-643xx chip and the required delay in the interrupt in uSec
  1972. *
  1973. * INPUT:
  1974. * struct mv643xx_private *mp Ethernet port
  1975. * unsigned int delay Delay in uSeconds
  1976. *
  1977. * OUTPUT:
  1978. * Interrupt coalescing mechanism value is set in MV-643xx chip.
  1979. *
  1980. * RETURN:
  1981. * The interrupt coalescing value set in the gigE port.
  1982. *
  1983. */
  1984. static unsigned int eth_port_set_tx_coal(struct mv643xx_private *mp,
  1985. unsigned int delay)
  1986. {
  1987. unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64;
  1988. /* Set TX Coalescing mechanism */
  1989. wrl(mp, TX_FIFO_URGENT_THRESHOLD(mp->port_num), coal << 4);
  1990. return coal;
  1991. }
  1992. /*
  1993. * eth_port_init - Initialize the Ethernet port driver
  1994. *
  1995. * DESCRIPTION:
  1996. * This function prepares the ethernet port to start its activity:
  1997. * 1) Completes the ethernet port driver struct initialization toward port
  1998. * start routine.
  1999. * 2) Resets the device to a quiescent state in case of warm reboot.
  2000. * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
  2001. * 4) Clean MAC tables. The reset status of those tables is unknown.
  2002. * 5) Set PHY address.
  2003. * Note: Call this routine prior to eth_port_start routine and after
  2004. * setting user values in the user fields of Ethernet port control
  2005. * struct.
  2006. *
  2007. * INPUT:
  2008. * struct mv643xx_private *mp Ethernet port control struct
  2009. *
  2010. * OUTPUT:
  2011. * See description.
  2012. *
  2013. * RETURN:
  2014. * None.
  2015. */
  2016. static void eth_port_init(struct mv643xx_private *mp)
  2017. {
  2018. mp->rx_resource_err = 0;
  2019. eth_port_reset(mp);
  2020. eth_port_init_mac_tables(mp);
  2021. }
  2022. /*
  2023. * mv643xx_eth_open
  2024. *
  2025. * This function is called when openning the network device. The function
  2026. * should initialize all the hardware, initialize cyclic Rx/Tx
  2027. * descriptors chain and buffers and allocate an IRQ to the network
  2028. * device.
  2029. *
  2030. * Input : a pointer to the network device structure
  2031. *
  2032. * Output : zero of success , nonzero if fails.
  2033. */
  2034. static int mv643xx_eth_open(struct net_device *dev)
  2035. {
  2036. struct mv643xx_private *mp = netdev_priv(dev);
  2037. unsigned int port_num = mp->port_num;
  2038. unsigned int size;
  2039. int err;
  2040. /* Clear any pending ethernet port interrupts */
  2041. wrl(mp, INT_CAUSE(port_num), 0);
  2042. wrl(mp, INT_CAUSE_EXT(port_num), 0);
  2043. /* wait for previous write to complete */
  2044. rdl(mp, INT_CAUSE_EXT(port_num));
  2045. err = request_irq(dev->irq, mv643xx_eth_int_handler,
  2046. IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
  2047. if (err) {
  2048. printk(KERN_ERR "%s: Can not assign IRQ\n", dev->name);
  2049. return -EAGAIN;
  2050. }
  2051. eth_port_init(mp);
  2052. memset(&mp->timeout, 0, sizeof(struct timer_list));
  2053. mp->timeout.function = mv643xx_eth_rx_refill_descs_timer_wrapper;
  2054. mp->timeout.data = (unsigned long)dev;
  2055. /* Allocate RX and TX skb rings */
  2056. mp->rx_skb = kmalloc(sizeof(*mp->rx_skb) * mp->rx_ring_size,
  2057. GFP_KERNEL);
  2058. if (!mp->rx_skb) {
  2059. printk(KERN_ERR "%s: Cannot allocate Rx skb ring\n", dev->name);
  2060. err = -ENOMEM;
  2061. goto out_free_irq;
  2062. }
  2063. mp->tx_skb = kmalloc(sizeof(*mp->tx_skb) * mp->tx_ring_size,
  2064. GFP_KERNEL);
  2065. if (!mp->tx_skb) {
  2066. printk(KERN_ERR "%s: Cannot allocate Tx skb ring\n", dev->name);
  2067. err = -ENOMEM;
  2068. goto out_free_rx_skb;
  2069. }
  2070. /* Allocate TX ring */
  2071. mp->tx_desc_count = 0;
  2072. size = mp->tx_ring_size * sizeof(struct eth_tx_desc);
  2073. mp->tx_desc_area_size = size;
  2074. if (mp->tx_sram_size) {
  2075. mp->p_tx_desc_area = ioremap(mp->tx_sram_addr,
  2076. mp->tx_sram_size);
  2077. mp->tx_desc_dma = mp->tx_sram_addr;
  2078. } else
  2079. mp->p_tx_desc_area = dma_alloc_coherent(NULL, size,
  2080. &mp->tx_desc_dma,
  2081. GFP_KERNEL);
  2082. if (!mp->p_tx_desc_area) {
  2083. printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n",
  2084. dev->name, size);
  2085. err = -ENOMEM;
  2086. goto out_free_tx_skb;
  2087. }
  2088. BUG_ON((u32) mp->p_tx_desc_area & 0xf); /* check 16-byte alignment */
  2089. memset((void *)mp->p_tx_desc_area, 0, mp->tx_desc_area_size);
  2090. ether_init_tx_desc_ring(mp);
  2091. /* Allocate RX ring */
  2092. mp->rx_desc_count = 0;
  2093. size = mp->rx_ring_size * sizeof(struct eth_rx_desc);
  2094. mp->rx_desc_area_size = size;
  2095. if (mp->rx_sram_size) {
  2096. mp->p_rx_desc_area = ioremap(mp->rx_sram_addr,
  2097. mp->rx_sram_size);
  2098. mp->rx_desc_dma = mp->rx_sram_addr;
  2099. } else
  2100. mp->p_rx_desc_area = dma_alloc_coherent(NULL, size,
  2101. &mp->rx_desc_dma,
  2102. GFP_KERNEL);
  2103. if (!mp->p_rx_desc_area) {
  2104. printk(KERN_ERR "%s: Cannot allocate Rx ring (size %d bytes)\n",
  2105. dev->name, size);
  2106. printk(KERN_ERR "%s: Freeing previously allocated TX queues...",
  2107. dev->name);
  2108. if (mp->rx_sram_size)
  2109. iounmap(mp->p_tx_desc_area);
  2110. else
  2111. dma_free_coherent(NULL, mp->tx_desc_area_size,
  2112. mp->p_tx_desc_area, mp->tx_desc_dma);
  2113. err = -ENOMEM;
  2114. goto out_free_tx_skb;
  2115. }
  2116. memset((void *)mp->p_rx_desc_area, 0, size);
  2117. ether_init_rx_desc_ring(mp);
  2118. mv643xx_eth_rx_refill_descs(dev); /* Fill RX ring with skb's */
  2119. #ifdef MV643XX_NAPI
  2120. napi_enable(&mp->napi);
  2121. #endif
  2122. eth_port_start(dev);
  2123. /* Interrupt Coalescing */
  2124. #ifdef MV643XX_COAL
  2125. mp->rx_int_coal =
  2126. eth_port_set_rx_coal(mp, MV643XX_RX_COAL);
  2127. #endif
  2128. mp->tx_int_coal =
  2129. eth_port_set_tx_coal(mp, MV643XX_TX_COAL);
  2130. /* Unmask phy and link status changes interrupts */
  2131. wrl(mp, INT_MASK_EXT(port_num), ETH_INT_UNMASK_ALL_EXT);
  2132. /* Unmask RX buffer and TX end interrupt */
  2133. wrl(mp, INT_MASK(port_num), ETH_INT_UNMASK_ALL);
  2134. return 0;
  2135. out_free_tx_skb:
  2136. kfree(mp->tx_skb);
  2137. out_free_rx_skb:
  2138. kfree(mp->rx_skb);
  2139. out_free_irq:
  2140. free_irq(dev->irq, dev);
  2141. return err;
  2142. }
  2143. /*
  2144. * eth_port_reset - Reset Ethernet port
  2145. *
  2146. * DESCRIPTION:
  2147. * This routine resets the chip by aborting any SDMA engine activity and
  2148. * clearing the MIB counters. The Receiver and the Transmit unit are in
  2149. * idle state after this command is performed and the port is disabled.
  2150. *
  2151. * INPUT:
  2152. * struct mv643xx_private *mp Ethernet Port.
  2153. *
  2154. * OUTPUT:
  2155. * Channel activity is halted.
  2156. *
  2157. * RETURN:
  2158. * None.
  2159. *
  2160. */
  2161. static void eth_port_reset(struct mv643xx_private *mp)
  2162. {
  2163. unsigned int port_num = mp->port_num;
  2164. unsigned int reg_data;
  2165. mv643xx_eth_port_disable_tx(mp);
  2166. mv643xx_eth_port_disable_rx(mp);
  2167. /* Clear all MIB counters */
  2168. eth_clear_mib_counters(mp);
  2169. /* Reset the Enable bit in the Configuration Register */
  2170. reg_data = rdl(mp, PORT_SERIAL_CONTROL(port_num));
  2171. reg_data &= ~(SERIAL_PORT_ENABLE |
  2172. DO_NOT_FORCE_LINK_FAIL |
  2173. FORCE_LINK_PASS);
  2174. wrl(mp, PORT_SERIAL_CONTROL(port_num), reg_data);
  2175. }
  2176. /*
  2177. * mv643xx_eth_stop
  2178. *
  2179. * This function is used when closing the network device.
  2180. * It updates the hardware,
  2181. * release all memory that holds buffers and descriptors and release the IRQ.
  2182. * Input : a pointer to the device structure
  2183. * Output : zero if success , nonzero if fails
  2184. */
  2185. static int mv643xx_eth_stop(struct net_device *dev)
  2186. {
  2187. struct mv643xx_private *mp = netdev_priv(dev);
  2188. unsigned int port_num = mp->port_num;
  2189. /* Mask all interrupts on ethernet port */
  2190. wrl(mp, INT_MASK(port_num), ETH_INT_MASK_ALL);
  2191. /* wait for previous write to complete */
  2192. rdl(mp, INT_MASK(port_num));
  2193. #ifdef MV643XX_NAPI
  2194. napi_disable(&mp->napi);
  2195. #endif
  2196. netif_carrier_off(dev);
  2197. netif_stop_queue(dev);
  2198. eth_port_reset(mp);
  2199. mv643xx_eth_free_tx_rings(dev);
  2200. mv643xx_eth_free_rx_rings(dev);
  2201. free_irq(dev->irq, dev);
  2202. return 0;
  2203. }
  2204. static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  2205. {
  2206. struct mv643xx_private *mp = netdev_priv(dev);
  2207. return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL);
  2208. }
  2209. /*
  2210. * Changes MTU (maximum transfer unit) of the gigabit ethenret port
  2211. *
  2212. * Input : pointer to ethernet interface network device structure
  2213. * new mtu size
  2214. * Output : 0 upon success, -EINVAL upon failure
  2215. */
  2216. static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu)
  2217. {
  2218. if ((new_mtu > 9500) || (new_mtu < 64))
  2219. return -EINVAL;
  2220. dev->mtu = new_mtu;
  2221. if (!netif_running(dev))
  2222. return 0;
  2223. /*
  2224. * Stop and then re-open the interface. This will allocate RX
  2225. * skbs of the new MTU.
  2226. * There is a possible danger that the open will not succeed,
  2227. * due to memory being full, which might fail the open function.
  2228. */
  2229. mv643xx_eth_stop(dev);
  2230. if (mv643xx_eth_open(dev)) {
  2231. printk(KERN_ERR "%s: Fatal error on opening device\n",
  2232. dev->name);
  2233. }
  2234. return 0;
  2235. }
  2236. /*
  2237. * mv643xx_eth_tx_timeout_task
  2238. *
  2239. * Actual routine to reset the adapter when a timeout on Tx has occurred
  2240. */
  2241. static void mv643xx_eth_tx_timeout_task(struct work_struct *ugly)
  2242. {
  2243. struct mv643xx_private *mp = container_of(ugly, struct mv643xx_private,
  2244. tx_timeout_task);
  2245. struct net_device *dev = mp->dev;
  2246. if (!netif_running(dev))
  2247. return;
  2248. netif_stop_queue(dev);
  2249. eth_port_reset(mp);
  2250. eth_port_start(dev);
  2251. if (mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB)
  2252. netif_wake_queue(dev);
  2253. }
  2254. /*
  2255. * mv643xx_eth_tx_timeout
  2256. *
  2257. * Called upon a timeout on transmitting a packet
  2258. *
  2259. * Input : pointer to ethernet interface network device structure.
  2260. * Output : N/A
  2261. */
  2262. static void mv643xx_eth_tx_timeout(struct net_device *dev)
  2263. {
  2264. struct mv643xx_private *mp = netdev_priv(dev);
  2265. printk(KERN_INFO "%s: TX timeout ", dev->name);
  2266. /* Do the reset outside of interrupt context */
  2267. schedule_work(&mp->tx_timeout_task);
  2268. }
  2269. #ifdef CONFIG_NET_POLL_CONTROLLER
  2270. static void mv643xx_netpoll(struct net_device *netdev)
  2271. {
  2272. struct mv643xx_private *mp = netdev_priv(netdev);
  2273. int port_num = mp->port_num;
  2274. wrl(mp, INT_MASK(port_num), ETH_INT_MASK_ALL);
  2275. /* wait for previous write to complete */
  2276. rdl(mp, INT_MASK(port_num));
  2277. mv643xx_eth_int_handler(netdev->irq, netdev);
  2278. wrl(mp, INT_MASK(port_num), ETH_INT_UNMASK_ALL);
  2279. }
  2280. #endif
  2281. /*
  2282. * Wrappers for MII support library.
  2283. */
  2284. static int mv643xx_mdio_read(struct net_device *dev, int phy_id, int location)
  2285. {
  2286. struct mv643xx_private *mp = netdev_priv(dev);
  2287. int val;
  2288. eth_port_read_smi_reg(mp, location, &val);
  2289. return val;
  2290. }
  2291. static void mv643xx_mdio_write(struct net_device *dev, int phy_id, int location, int val)
  2292. {
  2293. struct mv643xx_private *mp = netdev_priv(dev);
  2294. eth_port_write_smi_reg(mp, location, val);
  2295. }
  2296. /* platform glue ************************************************************/
  2297. static void mv643xx_eth_conf_mbus_windows(struct mv643xx_shared_private *msp,
  2298. struct mbus_dram_target_info *dram)
  2299. {
  2300. void __iomem *base = msp->eth_base;
  2301. u32 win_enable;
  2302. u32 win_protect;
  2303. int i;
  2304. for (i = 0; i < 6; i++) {
  2305. writel(0, base + WINDOW_BASE(i));
  2306. writel(0, base + WINDOW_SIZE(i));
  2307. if (i < 4)
  2308. writel(0, base + WINDOW_REMAP_HIGH(i));
  2309. }
  2310. win_enable = 0x3f;
  2311. win_protect = 0;
  2312. for (i = 0; i < dram->num_cs; i++) {
  2313. struct mbus_dram_window *cs = dram->cs + i;
  2314. writel((cs->base & 0xffff0000) |
  2315. (cs->mbus_attr << 8) |
  2316. dram->mbus_dram_target_id, base + WINDOW_BASE(i));
  2317. writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i));
  2318. win_enable &= ~(1 << i);
  2319. win_protect |= 3 << (2 * i);
  2320. }
  2321. writel(win_enable, base + WINDOW_BAR_ENABLE);
  2322. msp->win_protect = win_protect;
  2323. }
  2324. static int mv643xx_eth_shared_probe(struct platform_device *pdev)
  2325. {
  2326. static int mv643xx_version_printed = 0;
  2327. struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data;
  2328. struct mv643xx_shared_private *msp;
  2329. struct resource *res;
  2330. int ret;
  2331. if (!mv643xx_version_printed++)
  2332. printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n");
  2333. ret = -EINVAL;
  2334. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2335. if (res == NULL)
  2336. goto out;
  2337. ret = -ENOMEM;
  2338. msp = kmalloc(sizeof(*msp), GFP_KERNEL);
  2339. if (msp == NULL)
  2340. goto out;
  2341. memset(msp, 0, sizeof(*msp));
  2342. msp->eth_base = ioremap(res->start, res->end - res->start + 1);
  2343. if (msp->eth_base == NULL)
  2344. goto out_free;
  2345. spin_lock_init(&msp->phy_lock);
  2346. msp->t_clk = (pd != NULL && pd->t_clk != 0) ? pd->t_clk : 133000000;
  2347. platform_set_drvdata(pdev, msp);
  2348. /*
  2349. * (Re-)program MBUS remapping windows if we are asked to.
  2350. */
  2351. if (pd != NULL && pd->dram != NULL)
  2352. mv643xx_eth_conf_mbus_windows(msp, pd->dram);
  2353. return 0;
  2354. out_free:
  2355. kfree(msp);
  2356. out:
  2357. return ret;
  2358. }
  2359. static int mv643xx_eth_shared_remove(struct platform_device *pdev)
  2360. {
  2361. struct mv643xx_shared_private *msp = platform_get_drvdata(pdev);
  2362. iounmap(msp->eth_base);
  2363. kfree(msp);
  2364. return 0;
  2365. }
  2366. static struct platform_driver mv643xx_eth_shared_driver = {
  2367. .probe = mv643xx_eth_shared_probe,
  2368. .remove = mv643xx_eth_shared_remove,
  2369. .driver = {
  2370. .name = MV643XX_ETH_SHARED_NAME,
  2371. .owner = THIS_MODULE,
  2372. },
  2373. };
  2374. /*
  2375. * ethernet_phy_set - Set the ethernet port PHY address.
  2376. *
  2377. * DESCRIPTION:
  2378. * This routine sets the given ethernet port PHY address.
  2379. *
  2380. * INPUT:
  2381. * struct mv643xx_private *mp Ethernet Port.
  2382. * int phy_addr PHY address.
  2383. *
  2384. * OUTPUT:
  2385. * None.
  2386. *
  2387. * RETURN:
  2388. * None.
  2389. *
  2390. */
  2391. static void ethernet_phy_set(struct mv643xx_private *mp, int phy_addr)
  2392. {
  2393. u32 reg_data;
  2394. int addr_shift = 5 * mp->port_num;
  2395. reg_data = rdl(mp, PHY_ADDR);
  2396. reg_data &= ~(0x1f << addr_shift);
  2397. reg_data |= (phy_addr & 0x1f) << addr_shift;
  2398. wrl(mp, PHY_ADDR, reg_data);
  2399. }
  2400. /*
  2401. * ethernet_phy_get - Get the ethernet port PHY address.
  2402. *
  2403. * DESCRIPTION:
  2404. * This routine returns the given ethernet port PHY address.
  2405. *
  2406. * INPUT:
  2407. * struct mv643xx_private *mp Ethernet Port.
  2408. *
  2409. * OUTPUT:
  2410. * None.
  2411. *
  2412. * RETURN:
  2413. * PHY address.
  2414. *
  2415. */
  2416. static int ethernet_phy_get(struct mv643xx_private *mp)
  2417. {
  2418. unsigned int reg_data;
  2419. reg_data = rdl(mp, PHY_ADDR);
  2420. return ((reg_data >> (5 * mp->port_num)) & 0x1f);
  2421. }
  2422. /*
  2423. * ethernet_phy_detect - Detect whether a phy is present
  2424. *
  2425. * DESCRIPTION:
  2426. * This function tests whether there is a PHY present on
  2427. * the specified port.
  2428. *
  2429. * INPUT:
  2430. * struct mv643xx_private *mp Ethernet Port.
  2431. *
  2432. * OUTPUT:
  2433. * None
  2434. *
  2435. * RETURN:
  2436. * 0 on success
  2437. * -ENODEV on failure
  2438. *
  2439. */
  2440. static int ethernet_phy_detect(struct mv643xx_private *mp)
  2441. {
  2442. unsigned int phy_reg_data0;
  2443. int auto_neg;
  2444. eth_port_read_smi_reg(mp, 0, &phy_reg_data0);
  2445. auto_neg = phy_reg_data0 & 0x1000;
  2446. phy_reg_data0 ^= 0x1000; /* invert auto_neg */
  2447. eth_port_write_smi_reg(mp, 0, phy_reg_data0);
  2448. eth_port_read_smi_reg(mp, 0, &phy_reg_data0);
  2449. if ((phy_reg_data0 & 0x1000) == auto_neg)
  2450. return -ENODEV; /* change didn't take */
  2451. phy_reg_data0 ^= 0x1000;
  2452. eth_port_write_smi_reg(mp, 0, phy_reg_data0);
  2453. return 0;
  2454. }
  2455. static void mv643xx_init_ethtool_cmd(struct net_device *dev, int phy_address,
  2456. int speed, int duplex,
  2457. struct ethtool_cmd *cmd)
  2458. {
  2459. struct mv643xx_private *mp = netdev_priv(dev);
  2460. memset(cmd, 0, sizeof(*cmd));
  2461. cmd->port = PORT_MII;
  2462. cmd->transceiver = XCVR_INTERNAL;
  2463. cmd->phy_address = phy_address;
  2464. if (speed == 0) {
  2465. cmd->autoneg = AUTONEG_ENABLE;
  2466. /* mii lib checks, but doesn't use speed on AUTONEG_ENABLE */
  2467. cmd->speed = SPEED_100;
  2468. cmd->advertising = ADVERTISED_10baseT_Half |
  2469. ADVERTISED_10baseT_Full |
  2470. ADVERTISED_100baseT_Half |
  2471. ADVERTISED_100baseT_Full;
  2472. if (mp->mii.supports_gmii)
  2473. cmd->advertising |= ADVERTISED_1000baseT_Full;
  2474. } else {
  2475. cmd->autoneg = AUTONEG_DISABLE;
  2476. cmd->speed = speed;
  2477. cmd->duplex = duplex;
  2478. }
  2479. }
  2480. /*/
  2481. * mv643xx_eth_probe
  2482. *
  2483. * First function called after registering the network device.
  2484. * It's purpose is to initialize the device as an ethernet device,
  2485. * fill the ethernet device structure with pointers * to functions,
  2486. * and set the MAC address of the interface
  2487. *
  2488. * Input : struct device *
  2489. * Output : -ENOMEM if failed , 0 if success
  2490. */
  2491. static int mv643xx_eth_probe(struct platform_device *pdev)
  2492. {
  2493. struct mv643xx_eth_platform_data *pd;
  2494. int port_num;
  2495. struct mv643xx_private *mp;
  2496. struct net_device *dev;
  2497. u8 *p;
  2498. struct resource *res;
  2499. int err;
  2500. struct ethtool_cmd cmd;
  2501. int duplex = DUPLEX_HALF;
  2502. int speed = 0; /* default to auto-negotiation */
  2503. DECLARE_MAC_BUF(mac);
  2504. pd = pdev->dev.platform_data;
  2505. if (pd == NULL) {
  2506. printk(KERN_ERR "No mv643xx_eth_platform_data\n");
  2507. return -ENODEV;
  2508. }
  2509. if (pd->shared == NULL) {
  2510. printk(KERN_ERR "No mv643xx_eth_platform_data->shared\n");
  2511. return -ENODEV;
  2512. }
  2513. dev = alloc_etherdev(sizeof(struct mv643xx_private));
  2514. if (!dev)
  2515. return -ENOMEM;
  2516. platform_set_drvdata(pdev, dev);
  2517. mp = netdev_priv(dev);
  2518. mp->dev = dev;
  2519. #ifdef MV643XX_NAPI
  2520. netif_napi_add(dev, &mp->napi, mv643xx_poll, 64);
  2521. #endif
  2522. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  2523. BUG_ON(!res);
  2524. dev->irq = res->start;
  2525. dev->open = mv643xx_eth_open;
  2526. dev->stop = mv643xx_eth_stop;
  2527. dev->hard_start_xmit = mv643xx_eth_start_xmit;
  2528. dev->set_mac_address = mv643xx_eth_set_mac_address;
  2529. dev->set_multicast_list = mv643xx_eth_set_rx_mode;
  2530. /* No need to Tx Timeout */
  2531. dev->tx_timeout = mv643xx_eth_tx_timeout;
  2532. #ifdef CONFIG_NET_POLL_CONTROLLER
  2533. dev->poll_controller = mv643xx_netpoll;
  2534. #endif
  2535. dev->watchdog_timeo = 2 * HZ;
  2536. dev->base_addr = 0;
  2537. dev->change_mtu = mv643xx_eth_change_mtu;
  2538. dev->do_ioctl = mv643xx_eth_do_ioctl;
  2539. SET_ETHTOOL_OPS(dev, &mv643xx_ethtool_ops);
  2540. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  2541. #ifdef MAX_SKB_FRAGS
  2542. /*
  2543. * Zero copy can only work if we use Discovery II memory. Else, we will
  2544. * have to map the buffers to ISA memory which is only 16 MB
  2545. */
  2546. dev->features = NETIF_F_SG | NETIF_F_IP_CSUM;
  2547. #endif
  2548. #endif
  2549. /* Configure the timeout task */
  2550. INIT_WORK(&mp->tx_timeout_task, mv643xx_eth_tx_timeout_task);
  2551. spin_lock_init(&mp->lock);
  2552. mp->shared = platform_get_drvdata(pd->shared);
  2553. port_num = mp->port_num = pd->port_number;
  2554. if (mp->shared->win_protect)
  2555. wrl(mp, WINDOW_PROTECT(port_num), mp->shared->win_protect);
  2556. mp->shared_smi = mp->shared;
  2557. if (pd->shared_smi != NULL)
  2558. mp->shared_smi = platform_get_drvdata(pd->shared_smi);
  2559. /* set default config values */
  2560. eth_port_uc_addr_get(mp, dev->dev_addr);
  2561. mp->rx_ring_size = PORT_DEFAULT_RECEIVE_QUEUE_SIZE;
  2562. mp->tx_ring_size = PORT_DEFAULT_TRANSMIT_QUEUE_SIZE;
  2563. if (is_valid_ether_addr(pd->mac_addr))
  2564. memcpy(dev->dev_addr, pd->mac_addr, 6);
  2565. if (pd->phy_addr || pd->force_phy_addr)
  2566. ethernet_phy_set(mp, pd->phy_addr);
  2567. if (pd->rx_queue_size)
  2568. mp->rx_ring_size = pd->rx_queue_size;
  2569. if (pd->tx_queue_size)
  2570. mp->tx_ring_size = pd->tx_queue_size;
  2571. if (pd->tx_sram_size) {
  2572. mp->tx_sram_size = pd->tx_sram_size;
  2573. mp->tx_sram_addr = pd->tx_sram_addr;
  2574. }
  2575. if (pd->rx_sram_size) {
  2576. mp->rx_sram_size = pd->rx_sram_size;
  2577. mp->rx_sram_addr = pd->rx_sram_addr;
  2578. }
  2579. duplex = pd->duplex;
  2580. speed = pd->speed;
  2581. /* Hook up MII support for ethtool */
  2582. mp->mii.dev = dev;
  2583. mp->mii.mdio_read = mv643xx_mdio_read;
  2584. mp->mii.mdio_write = mv643xx_mdio_write;
  2585. mp->mii.phy_id = ethernet_phy_get(mp);
  2586. mp->mii.phy_id_mask = 0x3f;
  2587. mp->mii.reg_num_mask = 0x1f;
  2588. err = ethernet_phy_detect(mp);
  2589. if (err) {
  2590. pr_debug("%s: No PHY detected at addr %d\n",
  2591. dev->name, ethernet_phy_get(mp));
  2592. goto out;
  2593. }
  2594. ethernet_phy_reset(mp);
  2595. mp->mii.supports_gmii = mii_check_gmii_support(&mp->mii);
  2596. mv643xx_init_ethtool_cmd(dev, mp->mii.phy_id, speed, duplex, &cmd);
  2597. mv643xx_eth_update_pscr(dev, &cmd);
  2598. mv643xx_set_settings(dev, &cmd);
  2599. SET_NETDEV_DEV(dev, &pdev->dev);
  2600. err = register_netdev(dev);
  2601. if (err)
  2602. goto out;
  2603. p = dev->dev_addr;
  2604. printk(KERN_NOTICE
  2605. "%s: port %d with MAC address %s\n",
  2606. dev->name, port_num, print_mac(mac, p));
  2607. if (dev->features & NETIF_F_SG)
  2608. printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name);
  2609. if (dev->features & NETIF_F_IP_CSUM)
  2610. printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n",
  2611. dev->name);
  2612. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  2613. printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name);
  2614. #endif
  2615. #ifdef MV643XX_COAL
  2616. printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n",
  2617. dev->name);
  2618. #endif
  2619. #ifdef MV643XX_NAPI
  2620. printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name);
  2621. #endif
  2622. if (mp->tx_sram_size > 0)
  2623. printk(KERN_NOTICE "%s: Using SRAM\n", dev->name);
  2624. return 0;
  2625. out:
  2626. free_netdev(dev);
  2627. return err;
  2628. }
  2629. static int mv643xx_eth_remove(struct platform_device *pdev)
  2630. {
  2631. struct net_device *dev = platform_get_drvdata(pdev);
  2632. unregister_netdev(dev);
  2633. flush_scheduled_work();
  2634. free_netdev(dev);
  2635. platform_set_drvdata(pdev, NULL);
  2636. return 0;
  2637. }
  2638. static void mv643xx_eth_shutdown(struct platform_device *pdev)
  2639. {
  2640. struct net_device *dev = platform_get_drvdata(pdev);
  2641. struct mv643xx_private *mp = netdev_priv(dev);
  2642. unsigned int port_num = mp->port_num;
  2643. /* Mask all interrupts on ethernet port */
  2644. wrl(mp, INT_MASK(port_num), 0);
  2645. rdl(mp, INT_MASK(port_num));
  2646. eth_port_reset(mp);
  2647. }
  2648. static struct platform_driver mv643xx_eth_driver = {
  2649. .probe = mv643xx_eth_probe,
  2650. .remove = mv643xx_eth_remove,
  2651. .shutdown = mv643xx_eth_shutdown,
  2652. .driver = {
  2653. .name = MV643XX_ETH_NAME,
  2654. .owner = THIS_MODULE,
  2655. },
  2656. };
  2657. /*
  2658. * mv643xx_init_module
  2659. *
  2660. * Registers the network drivers into the Linux kernel
  2661. *
  2662. * Input : N/A
  2663. *
  2664. * Output : N/A
  2665. */
  2666. static int __init mv643xx_init_module(void)
  2667. {
  2668. int rc;
  2669. rc = platform_driver_register(&mv643xx_eth_shared_driver);
  2670. if (!rc) {
  2671. rc = platform_driver_register(&mv643xx_eth_driver);
  2672. if (rc)
  2673. platform_driver_unregister(&mv643xx_eth_shared_driver);
  2674. }
  2675. return rc;
  2676. }
  2677. /*
  2678. * mv643xx_cleanup_module
  2679. *
  2680. * Registers the network drivers into the Linux kernel
  2681. *
  2682. * Input : N/A
  2683. *
  2684. * Output : N/A
  2685. */
  2686. static void __exit mv643xx_cleanup_module(void)
  2687. {
  2688. platform_driver_unregister(&mv643xx_eth_driver);
  2689. platform_driver_unregister(&mv643xx_eth_shared_driver);
  2690. }
  2691. module_init(mv643xx_init_module);
  2692. module_exit(mv643xx_cleanup_module);
  2693. MODULE_LICENSE("GPL");
  2694. MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani"
  2695. " and Dale Farnsworth");
  2696. MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
  2697. MODULE_ALIAS("platform:" MV643XX_ETH_NAME);
  2698. MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME);