mv643xx_eth.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  38. #include <linux/init.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/in.h>
  41. #include <linux/ip.h>
  42. #include <linux/tcp.h>
  43. #include <linux/udp.h>
  44. #include <linux/etherdevice.h>
  45. #include <linux/delay.h>
  46. #include <linux/ethtool.h>
  47. #include <linux/platform_device.h>
  48. #include <linux/module.h>
  49. #include <linux/kernel.h>
  50. #include <linux/spinlock.h>
  51. #include <linux/workqueue.h>
  52. #include <linux/phy.h>
  53. #include <linux/mv643xx_eth.h>
  54. #include <linux/io.h>
  55. #include <linux/types.h>
  56. #include <linux/inet_lro.h>
  57. #include <linux/slab.h>
  58. #include <asm/system.h>
  59. static char mv643xx_eth_driver_name[] = "mv643xx_eth";
  60. static char mv643xx_eth_driver_version[] = "1.4";
  61. /*
  62. * Registers shared between all ports.
  63. */
  64. #define PHY_ADDR 0x0000
  65. #define SMI_REG 0x0004
  66. #define SMI_BUSY 0x10000000
  67. #define SMI_READ_VALID 0x08000000
  68. #define SMI_OPCODE_READ 0x04000000
  69. #define SMI_OPCODE_WRITE 0x00000000
  70. #define ERR_INT_CAUSE 0x0080
  71. #define ERR_INT_SMI_DONE 0x00000010
  72. #define ERR_INT_MASK 0x0084
  73. #define WINDOW_BASE(w) (0x0200 + ((w) << 3))
  74. #define WINDOW_SIZE(w) (0x0204 + ((w) << 3))
  75. #define WINDOW_REMAP_HIGH(w) (0x0280 + ((w) << 2))
  76. #define WINDOW_BAR_ENABLE 0x0290
  77. #define WINDOW_PROTECT(w) (0x0294 + ((w) << 4))
  78. /*
  79. * Main per-port registers. These live at offset 0x0400 for
  80. * port #0, 0x0800 for port #1, and 0x0c00 for port #2.
  81. */
  82. #define PORT_CONFIG 0x0000
  83. #define UNICAST_PROMISCUOUS_MODE 0x00000001
  84. #define PORT_CONFIG_EXT 0x0004
  85. #define MAC_ADDR_LOW 0x0014
  86. #define MAC_ADDR_HIGH 0x0018
  87. #define SDMA_CONFIG 0x001c
  88. #define TX_BURST_SIZE_16_64BIT 0x01000000
  89. #define TX_BURST_SIZE_4_64BIT 0x00800000
  90. #define BLM_TX_NO_SWAP 0x00000020
  91. #define BLM_RX_NO_SWAP 0x00000010
  92. #define RX_BURST_SIZE_16_64BIT 0x00000008
  93. #define RX_BURST_SIZE_4_64BIT 0x00000004
  94. #define PORT_SERIAL_CONTROL 0x003c
  95. #define SET_MII_SPEED_TO_100 0x01000000
  96. #define SET_GMII_SPEED_TO_1000 0x00800000
  97. #define SET_FULL_DUPLEX_MODE 0x00200000
  98. #define MAX_RX_PACKET_9700BYTE 0x000a0000
  99. #define DISABLE_AUTO_NEG_SPEED_GMII 0x00002000
  100. #define DO_NOT_FORCE_LINK_FAIL 0x00000400
  101. #define SERIAL_PORT_CONTROL_RESERVED 0x00000200
  102. #define DISABLE_AUTO_NEG_FOR_FLOW_CTRL 0x00000008
  103. #define DISABLE_AUTO_NEG_FOR_DUPLEX 0x00000004
  104. #define FORCE_LINK_PASS 0x00000002
  105. #define SERIAL_PORT_ENABLE 0x00000001
  106. #define PORT_STATUS 0x0044
  107. #define TX_FIFO_EMPTY 0x00000400
  108. #define TX_IN_PROGRESS 0x00000080
  109. #define PORT_SPEED_MASK 0x00000030
  110. #define PORT_SPEED_1000 0x00000010
  111. #define PORT_SPEED_100 0x00000020
  112. #define PORT_SPEED_10 0x00000000
  113. #define FLOW_CONTROL_ENABLED 0x00000008
  114. #define FULL_DUPLEX 0x00000004
  115. #define LINK_UP 0x00000002
  116. #define TXQ_COMMAND 0x0048
  117. #define TXQ_FIX_PRIO_CONF 0x004c
  118. #define TX_BW_RATE 0x0050
  119. #define TX_BW_MTU 0x0058
  120. #define TX_BW_BURST 0x005c
  121. #define INT_CAUSE 0x0060
  122. #define INT_TX_END 0x07f80000
  123. #define INT_TX_END_0 0x00080000
  124. #define INT_RX 0x000003fc
  125. #define INT_RX_0 0x00000004
  126. #define INT_EXT 0x00000002
  127. #define INT_CAUSE_EXT 0x0064
  128. #define INT_EXT_LINK_PHY 0x00110000
  129. #define INT_EXT_TX 0x000000ff
  130. #define INT_MASK 0x0068
  131. #define INT_MASK_EXT 0x006c
  132. #define TX_FIFO_URGENT_THRESHOLD 0x0074
  133. #define RX_DISCARD_FRAME_CNT 0x0084
  134. #define RX_OVERRUN_FRAME_CNT 0x0088
  135. #define TXQ_FIX_PRIO_CONF_MOVED 0x00dc
  136. #define TX_BW_RATE_MOVED 0x00e0
  137. #define TX_BW_MTU_MOVED 0x00e8
  138. #define TX_BW_BURST_MOVED 0x00ec
  139. #define RXQ_CURRENT_DESC_PTR(q) (0x020c + ((q) << 4))
  140. #define RXQ_COMMAND 0x0280
  141. #define TXQ_CURRENT_DESC_PTR(q) (0x02c0 + ((q) << 2))
  142. #define TXQ_BW_TOKENS(q) (0x0300 + ((q) << 4))
  143. #define TXQ_BW_CONF(q) (0x0304 + ((q) << 4))
  144. #define TXQ_BW_WRR_CONF(q) (0x0308 + ((q) << 4))
  145. /*
  146. * Misc per-port registers.
  147. */
  148. #define MIB_COUNTERS(p) (0x1000 + ((p) << 7))
  149. #define SPECIAL_MCAST_TABLE(p) (0x1400 + ((p) << 10))
  150. #define OTHER_MCAST_TABLE(p) (0x1500 + ((p) << 10))
  151. #define UNICAST_TABLE(p) (0x1600 + ((p) << 10))
  152. /*
  153. * SDMA configuration register default value.
  154. */
  155. #if defined(__BIG_ENDIAN)
  156. #define PORT_SDMA_CONFIG_DEFAULT_VALUE \
  157. (RX_BURST_SIZE_4_64BIT | \
  158. TX_BURST_SIZE_4_64BIT)
  159. #elif defined(__LITTLE_ENDIAN)
  160. #define PORT_SDMA_CONFIG_DEFAULT_VALUE \
  161. (RX_BURST_SIZE_4_64BIT | \
  162. BLM_RX_NO_SWAP | \
  163. BLM_TX_NO_SWAP | \
  164. TX_BURST_SIZE_4_64BIT)
  165. #else
  166. #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined
  167. #endif
  168. /*
  169. * Misc definitions.
  170. */
  171. #define DEFAULT_RX_QUEUE_SIZE 128
  172. #define DEFAULT_TX_QUEUE_SIZE 256
  173. #define SKB_DMA_REALIGN ((PAGE_SIZE - NET_SKB_PAD) % SMP_CACHE_BYTES)
  174. /*
  175. * RX/TX descriptors.
  176. */
  177. #if defined(__BIG_ENDIAN)
  178. struct rx_desc {
  179. u16 byte_cnt; /* Descriptor buffer byte count */
  180. u16 buf_size; /* Buffer size */
  181. u32 cmd_sts; /* Descriptor command status */
  182. u32 next_desc_ptr; /* Next descriptor pointer */
  183. u32 buf_ptr; /* Descriptor buffer pointer */
  184. };
  185. struct tx_desc {
  186. u16 byte_cnt; /* buffer byte count */
  187. u16 l4i_chk; /* CPU provided TCP checksum */
  188. u32 cmd_sts; /* Command/status field */
  189. u32 next_desc_ptr; /* Pointer to next descriptor */
  190. u32 buf_ptr; /* pointer to buffer for this descriptor*/
  191. };
  192. #elif defined(__LITTLE_ENDIAN)
  193. struct rx_desc {
  194. u32 cmd_sts; /* Descriptor command status */
  195. u16 buf_size; /* Buffer size */
  196. u16 byte_cnt; /* Descriptor buffer byte count */
  197. u32 buf_ptr; /* Descriptor buffer pointer */
  198. u32 next_desc_ptr; /* Next descriptor pointer */
  199. };
  200. struct tx_desc {
  201. u32 cmd_sts; /* Command/status field */
  202. u16 l4i_chk; /* CPU provided TCP checksum */
  203. u16 byte_cnt; /* buffer byte count */
  204. u32 buf_ptr; /* pointer to buffer for this descriptor*/
  205. u32 next_desc_ptr; /* Pointer to next descriptor */
  206. };
  207. #else
  208. #error One of __BIG_ENDIAN or __LITTLE_ENDIAN must be defined
  209. #endif
  210. /* RX & TX descriptor command */
  211. #define BUFFER_OWNED_BY_DMA 0x80000000
  212. /* RX & TX descriptor status */
  213. #define ERROR_SUMMARY 0x00000001
  214. /* RX descriptor status */
  215. #define LAYER_4_CHECKSUM_OK 0x40000000
  216. #define RX_ENABLE_INTERRUPT 0x20000000
  217. #define RX_FIRST_DESC 0x08000000
  218. #define RX_LAST_DESC 0x04000000
  219. #define RX_IP_HDR_OK 0x02000000
  220. #define RX_PKT_IS_IPV4 0x01000000
  221. #define RX_PKT_IS_ETHERNETV2 0x00800000
  222. #define RX_PKT_LAYER4_TYPE_MASK 0x00600000
  223. #define RX_PKT_LAYER4_TYPE_TCP_IPV4 0x00000000
  224. #define RX_PKT_IS_VLAN_TAGGED 0x00080000
  225. /* TX descriptor command */
  226. #define TX_ENABLE_INTERRUPT 0x00800000
  227. #define GEN_CRC 0x00400000
  228. #define TX_FIRST_DESC 0x00200000
  229. #define TX_LAST_DESC 0x00100000
  230. #define ZERO_PADDING 0x00080000
  231. #define GEN_IP_V4_CHECKSUM 0x00040000
  232. #define GEN_TCP_UDP_CHECKSUM 0x00020000
  233. #define UDP_FRAME 0x00010000
  234. #define MAC_HDR_EXTRA_4_BYTES 0x00008000
  235. #define MAC_HDR_EXTRA_8_BYTES 0x00000200
  236. #define TX_IHL_SHIFT 11
  237. /* global *******************************************************************/
  238. struct mv643xx_eth_shared_private {
  239. /*
  240. * Ethernet controller base address.
  241. */
  242. void __iomem *base;
  243. /*
  244. * Points at the right SMI instance to use.
  245. */
  246. struct mv643xx_eth_shared_private *smi;
  247. /*
  248. * Provides access to local SMI interface.
  249. */
  250. struct mii_bus *smi_bus;
  251. /*
  252. * If we have access to the error interrupt pin (which is
  253. * somewhat misnamed as it not only reflects internal errors
  254. * but also reflects SMI completion), use that to wait for
  255. * SMI access completion instead of polling the SMI busy bit.
  256. */
  257. int err_interrupt;
  258. wait_queue_head_t smi_busy_wait;
  259. /*
  260. * Per-port MBUS window access register value.
  261. */
  262. u32 win_protect;
  263. /*
  264. * Hardware-specific parameters.
  265. */
  266. unsigned int t_clk;
  267. int extended_rx_coal_limit;
  268. int tx_bw_control;
  269. int tx_csum_limit;
  270. };
  271. #define TX_BW_CONTROL_ABSENT 0
  272. #define TX_BW_CONTROL_OLD_LAYOUT 1
  273. #define TX_BW_CONTROL_NEW_LAYOUT 2
  274. static int mv643xx_eth_open(struct net_device *dev);
  275. static int mv643xx_eth_stop(struct net_device *dev);
  276. /* per-port *****************************************************************/
  277. struct mib_counters {
  278. u64 good_octets_received;
  279. u32 bad_octets_received;
  280. u32 internal_mac_transmit_err;
  281. u32 good_frames_received;
  282. u32 bad_frames_received;
  283. u32 broadcast_frames_received;
  284. u32 multicast_frames_received;
  285. u32 frames_64_octets;
  286. u32 frames_65_to_127_octets;
  287. u32 frames_128_to_255_octets;
  288. u32 frames_256_to_511_octets;
  289. u32 frames_512_to_1023_octets;
  290. u32 frames_1024_to_max_octets;
  291. u64 good_octets_sent;
  292. u32 good_frames_sent;
  293. u32 excessive_collision;
  294. u32 multicast_frames_sent;
  295. u32 broadcast_frames_sent;
  296. u32 unrec_mac_control_received;
  297. u32 fc_sent;
  298. u32 good_fc_received;
  299. u32 bad_fc_received;
  300. u32 undersize_received;
  301. u32 fragments_received;
  302. u32 oversize_received;
  303. u32 jabber_received;
  304. u32 mac_receive_error;
  305. u32 bad_crc_event;
  306. u32 collision;
  307. u32 late_collision;
  308. /* Non MIB hardware counters */
  309. u32 rx_discard;
  310. u32 rx_overrun;
  311. };
  312. struct lro_counters {
  313. u32 lro_aggregated;
  314. u32 lro_flushed;
  315. u32 lro_no_desc;
  316. };
  317. struct rx_queue {
  318. int index;
  319. int rx_ring_size;
  320. int rx_desc_count;
  321. int rx_curr_desc;
  322. int rx_used_desc;
  323. struct rx_desc *rx_desc_area;
  324. dma_addr_t rx_desc_dma;
  325. int rx_desc_area_size;
  326. struct sk_buff **rx_skb;
  327. struct net_lro_mgr lro_mgr;
  328. struct net_lro_desc lro_arr[8];
  329. };
  330. struct tx_queue {
  331. int index;
  332. int tx_ring_size;
  333. int tx_desc_count;
  334. int tx_curr_desc;
  335. int tx_used_desc;
  336. struct tx_desc *tx_desc_area;
  337. dma_addr_t tx_desc_dma;
  338. int tx_desc_area_size;
  339. struct sk_buff_head tx_skb;
  340. unsigned long tx_packets;
  341. unsigned long tx_bytes;
  342. unsigned long tx_dropped;
  343. };
  344. struct mv643xx_eth_private {
  345. struct mv643xx_eth_shared_private *shared;
  346. void __iomem *base;
  347. int port_num;
  348. struct net_device *dev;
  349. struct phy_device *phy;
  350. struct timer_list mib_counters_timer;
  351. spinlock_t mib_counters_lock;
  352. struct mib_counters mib_counters;
  353. struct lro_counters lro_counters;
  354. struct work_struct tx_timeout_task;
  355. struct napi_struct napi;
  356. u32 int_mask;
  357. u8 oom;
  358. u8 work_link;
  359. u8 work_tx;
  360. u8 work_tx_end;
  361. u8 work_rx;
  362. u8 work_rx_refill;
  363. int skb_size;
  364. struct sk_buff_head rx_recycle;
  365. /*
  366. * RX state.
  367. */
  368. int rx_ring_size;
  369. unsigned long rx_desc_sram_addr;
  370. int rx_desc_sram_size;
  371. int rxq_count;
  372. struct timer_list rx_oom;
  373. struct rx_queue rxq[8];
  374. /*
  375. * TX state.
  376. */
  377. int tx_ring_size;
  378. unsigned long tx_desc_sram_addr;
  379. int tx_desc_sram_size;
  380. int txq_count;
  381. struct tx_queue txq[8];
  382. };
  383. /* port register accessors **************************************************/
  384. static inline u32 rdl(struct mv643xx_eth_private *mp, int offset)
  385. {
  386. return readl(mp->shared->base + offset);
  387. }
  388. static inline u32 rdlp(struct mv643xx_eth_private *mp, int offset)
  389. {
  390. return readl(mp->base + offset);
  391. }
  392. static inline void wrl(struct mv643xx_eth_private *mp, int offset, u32 data)
  393. {
  394. writel(data, mp->shared->base + offset);
  395. }
  396. static inline void wrlp(struct mv643xx_eth_private *mp, int offset, u32 data)
  397. {
  398. writel(data, mp->base + offset);
  399. }
  400. /* rxq/txq helper functions *************************************************/
  401. static struct mv643xx_eth_private *rxq_to_mp(struct rx_queue *rxq)
  402. {
  403. return container_of(rxq, struct mv643xx_eth_private, rxq[rxq->index]);
  404. }
  405. static struct mv643xx_eth_private *txq_to_mp(struct tx_queue *txq)
  406. {
  407. return container_of(txq, struct mv643xx_eth_private, txq[txq->index]);
  408. }
  409. static void rxq_enable(struct rx_queue *rxq)
  410. {
  411. struct mv643xx_eth_private *mp = rxq_to_mp(rxq);
  412. wrlp(mp, RXQ_COMMAND, 1 << rxq->index);
  413. }
  414. static void rxq_disable(struct rx_queue *rxq)
  415. {
  416. struct mv643xx_eth_private *mp = rxq_to_mp(rxq);
  417. u8 mask = 1 << rxq->index;
  418. wrlp(mp, RXQ_COMMAND, mask << 8);
  419. while (rdlp(mp, RXQ_COMMAND) & mask)
  420. udelay(10);
  421. }
  422. static void txq_reset_hw_ptr(struct tx_queue *txq)
  423. {
  424. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  425. u32 addr;
  426. addr = (u32)txq->tx_desc_dma;
  427. addr += txq->tx_curr_desc * sizeof(struct tx_desc);
  428. wrlp(mp, TXQ_CURRENT_DESC_PTR(txq->index), addr);
  429. }
  430. static void txq_enable(struct tx_queue *txq)
  431. {
  432. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  433. wrlp(mp, TXQ_COMMAND, 1 << txq->index);
  434. }
  435. static void txq_disable(struct tx_queue *txq)
  436. {
  437. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  438. u8 mask = 1 << txq->index;
  439. wrlp(mp, TXQ_COMMAND, mask << 8);
  440. while (rdlp(mp, TXQ_COMMAND) & mask)
  441. udelay(10);
  442. }
  443. static void txq_maybe_wake(struct tx_queue *txq)
  444. {
  445. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  446. struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index);
  447. if (netif_tx_queue_stopped(nq)) {
  448. __netif_tx_lock(nq, smp_processor_id());
  449. if (txq->tx_ring_size - txq->tx_desc_count >= MAX_SKB_FRAGS + 1)
  450. netif_tx_wake_queue(nq);
  451. __netif_tx_unlock(nq);
  452. }
  453. }
  454. /* rx napi ******************************************************************/
  455. static int
  456. mv643xx_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph,
  457. u64 *hdr_flags, void *priv)
  458. {
  459. unsigned long cmd_sts = (unsigned long)priv;
  460. /*
  461. * Make sure that this packet is Ethernet II, is not VLAN
  462. * tagged, is IPv4, has a valid IP header, and is TCP.
  463. */
  464. if ((cmd_sts & (RX_IP_HDR_OK | RX_PKT_IS_IPV4 |
  465. RX_PKT_IS_ETHERNETV2 | RX_PKT_LAYER4_TYPE_MASK |
  466. RX_PKT_IS_VLAN_TAGGED)) !=
  467. (RX_IP_HDR_OK | RX_PKT_IS_IPV4 |
  468. RX_PKT_IS_ETHERNETV2 | RX_PKT_LAYER4_TYPE_TCP_IPV4))
  469. return -1;
  470. skb_reset_network_header(skb);
  471. skb_set_transport_header(skb, ip_hdrlen(skb));
  472. *iphdr = ip_hdr(skb);
  473. *tcph = tcp_hdr(skb);
  474. *hdr_flags = LRO_IPV4 | LRO_TCP;
  475. return 0;
  476. }
  477. static int rxq_process(struct rx_queue *rxq, int budget)
  478. {
  479. struct mv643xx_eth_private *mp = rxq_to_mp(rxq);
  480. struct net_device_stats *stats = &mp->dev->stats;
  481. int lro_flush_needed;
  482. int rx;
  483. lro_flush_needed = 0;
  484. rx = 0;
  485. while (rx < budget && rxq->rx_desc_count) {
  486. struct rx_desc *rx_desc;
  487. unsigned int cmd_sts;
  488. struct sk_buff *skb;
  489. u16 byte_cnt;
  490. rx_desc = &rxq->rx_desc_area[rxq->rx_curr_desc];
  491. cmd_sts = rx_desc->cmd_sts;
  492. if (cmd_sts & BUFFER_OWNED_BY_DMA)
  493. break;
  494. rmb();
  495. skb = rxq->rx_skb[rxq->rx_curr_desc];
  496. rxq->rx_skb[rxq->rx_curr_desc] = NULL;
  497. rxq->rx_curr_desc++;
  498. if (rxq->rx_curr_desc == rxq->rx_ring_size)
  499. rxq->rx_curr_desc = 0;
  500. dma_unmap_single(mp->dev->dev.parent, rx_desc->buf_ptr,
  501. rx_desc->buf_size, DMA_FROM_DEVICE);
  502. rxq->rx_desc_count--;
  503. rx++;
  504. mp->work_rx_refill |= 1 << rxq->index;
  505. byte_cnt = rx_desc->byte_cnt;
  506. /*
  507. * Update statistics.
  508. *
  509. * Note that the descriptor byte count includes 2 dummy
  510. * bytes automatically inserted by the hardware at the
  511. * start of the packet (which we don't count), and a 4
  512. * byte CRC at the end of the packet (which we do count).
  513. */
  514. stats->rx_packets++;
  515. stats->rx_bytes += byte_cnt - 2;
  516. /*
  517. * In case we received a packet without first / last bits
  518. * on, or the error summary bit is set, the packet needs
  519. * to be dropped.
  520. */
  521. if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC | ERROR_SUMMARY))
  522. != (RX_FIRST_DESC | RX_LAST_DESC))
  523. goto err;
  524. /*
  525. * The -4 is for the CRC in the trailer of the
  526. * received packet
  527. */
  528. skb_put(skb, byte_cnt - 2 - 4);
  529. if (cmd_sts & LAYER_4_CHECKSUM_OK)
  530. skb->ip_summed = CHECKSUM_UNNECESSARY;
  531. skb->protocol = eth_type_trans(skb, mp->dev);
  532. if (skb->dev->features & NETIF_F_LRO &&
  533. skb->ip_summed == CHECKSUM_UNNECESSARY) {
  534. lro_receive_skb(&rxq->lro_mgr, skb, (void *)cmd_sts);
  535. lro_flush_needed = 1;
  536. } else
  537. netif_receive_skb(skb);
  538. continue;
  539. err:
  540. stats->rx_dropped++;
  541. if ((cmd_sts & (RX_FIRST_DESC | RX_LAST_DESC)) !=
  542. (RX_FIRST_DESC | RX_LAST_DESC)) {
  543. if (net_ratelimit())
  544. netdev_err(mp->dev,
  545. "received packet spanning multiple descriptors\n");
  546. }
  547. if (cmd_sts & ERROR_SUMMARY)
  548. stats->rx_errors++;
  549. dev_kfree_skb(skb);
  550. }
  551. if (lro_flush_needed)
  552. lro_flush_all(&rxq->lro_mgr);
  553. if (rx < budget)
  554. mp->work_rx &= ~(1 << rxq->index);
  555. return rx;
  556. }
  557. static int rxq_refill(struct rx_queue *rxq, int budget)
  558. {
  559. struct mv643xx_eth_private *mp = rxq_to_mp(rxq);
  560. int refilled;
  561. refilled = 0;
  562. while (refilled < budget && rxq->rx_desc_count < rxq->rx_ring_size) {
  563. struct sk_buff *skb;
  564. int rx;
  565. struct rx_desc *rx_desc;
  566. int size;
  567. skb = __skb_dequeue(&mp->rx_recycle);
  568. if (skb == NULL)
  569. skb = netdev_alloc_skb(mp->dev, mp->skb_size);
  570. if (skb == NULL) {
  571. mp->oom = 1;
  572. goto oom;
  573. }
  574. if (SKB_DMA_REALIGN)
  575. skb_reserve(skb, SKB_DMA_REALIGN);
  576. refilled++;
  577. rxq->rx_desc_count++;
  578. rx = rxq->rx_used_desc++;
  579. if (rxq->rx_used_desc == rxq->rx_ring_size)
  580. rxq->rx_used_desc = 0;
  581. rx_desc = rxq->rx_desc_area + rx;
  582. size = skb->end - skb->data;
  583. rx_desc->buf_ptr = dma_map_single(mp->dev->dev.parent,
  584. skb->data, size,
  585. DMA_FROM_DEVICE);
  586. rx_desc->buf_size = size;
  587. rxq->rx_skb[rx] = skb;
  588. wmb();
  589. rx_desc->cmd_sts = BUFFER_OWNED_BY_DMA | RX_ENABLE_INTERRUPT;
  590. wmb();
  591. /*
  592. * The hardware automatically prepends 2 bytes of
  593. * dummy data to each received packet, so that the
  594. * IP header ends up 16-byte aligned.
  595. */
  596. skb_reserve(skb, 2);
  597. }
  598. if (refilled < budget)
  599. mp->work_rx_refill &= ~(1 << rxq->index);
  600. oom:
  601. return refilled;
  602. }
  603. /* tx ***********************************************************************/
  604. static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb)
  605. {
  606. int frag;
  607. for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
  608. const skb_frag_t *fragp = &skb_shinfo(skb)->frags[frag];
  609. if (skb_frag_size(fragp) <= 8 && fragp->page_offset & 7)
  610. return 1;
  611. }
  612. return 0;
  613. }
  614. static void txq_submit_frag_skb(struct tx_queue *txq, struct sk_buff *skb)
  615. {
  616. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  617. int nr_frags = skb_shinfo(skb)->nr_frags;
  618. int frag;
  619. for (frag = 0; frag < nr_frags; frag++) {
  620. skb_frag_t *this_frag;
  621. int tx_index;
  622. struct tx_desc *desc;
  623. this_frag = &skb_shinfo(skb)->frags[frag];
  624. tx_index = txq->tx_curr_desc++;
  625. if (txq->tx_curr_desc == txq->tx_ring_size)
  626. txq->tx_curr_desc = 0;
  627. desc = &txq->tx_desc_area[tx_index];
  628. /*
  629. * The last fragment will generate an interrupt
  630. * which will free the skb on TX completion.
  631. */
  632. if (frag == nr_frags - 1) {
  633. desc->cmd_sts = BUFFER_OWNED_BY_DMA |
  634. ZERO_PADDING | TX_LAST_DESC |
  635. TX_ENABLE_INTERRUPT;
  636. } else {
  637. desc->cmd_sts = BUFFER_OWNED_BY_DMA;
  638. }
  639. desc->l4i_chk = 0;
  640. desc->byte_cnt = skb_frag_size(this_frag);
  641. desc->buf_ptr = skb_frag_dma_map(mp->dev->dev.parent,
  642. this_frag, 0,
  643. skb_frag_size(this_frag),
  644. DMA_TO_DEVICE);
  645. }
  646. }
  647. static inline __be16 sum16_as_be(__sum16 sum)
  648. {
  649. return (__force __be16)sum;
  650. }
  651. static int txq_submit_skb(struct tx_queue *txq, struct sk_buff *skb)
  652. {
  653. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  654. int nr_frags = skb_shinfo(skb)->nr_frags;
  655. int tx_index;
  656. struct tx_desc *desc;
  657. u32 cmd_sts;
  658. u16 l4i_chk;
  659. int length;
  660. cmd_sts = TX_FIRST_DESC | GEN_CRC | BUFFER_OWNED_BY_DMA;
  661. l4i_chk = 0;
  662. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  663. int hdr_len;
  664. int tag_bytes;
  665. BUG_ON(skb->protocol != htons(ETH_P_IP) &&
  666. skb->protocol != htons(ETH_P_8021Q));
  667. hdr_len = (void *)ip_hdr(skb) - (void *)skb->data;
  668. tag_bytes = hdr_len - ETH_HLEN;
  669. if (skb->len - hdr_len > mp->shared->tx_csum_limit ||
  670. unlikely(tag_bytes & ~12)) {
  671. if (skb_checksum_help(skb) == 0)
  672. goto no_csum;
  673. kfree_skb(skb);
  674. return 1;
  675. }
  676. if (tag_bytes & 4)
  677. cmd_sts |= MAC_HDR_EXTRA_4_BYTES;
  678. if (tag_bytes & 8)
  679. cmd_sts |= MAC_HDR_EXTRA_8_BYTES;
  680. cmd_sts |= GEN_TCP_UDP_CHECKSUM |
  681. GEN_IP_V4_CHECKSUM |
  682. ip_hdr(skb)->ihl << TX_IHL_SHIFT;
  683. switch (ip_hdr(skb)->protocol) {
  684. case IPPROTO_UDP:
  685. cmd_sts |= UDP_FRAME;
  686. l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check));
  687. break;
  688. case IPPROTO_TCP:
  689. l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check));
  690. break;
  691. default:
  692. BUG();
  693. }
  694. } else {
  695. no_csum:
  696. /* Errata BTS #50, IHL must be 5 if no HW checksum */
  697. cmd_sts |= 5 << TX_IHL_SHIFT;
  698. }
  699. tx_index = txq->tx_curr_desc++;
  700. if (txq->tx_curr_desc == txq->tx_ring_size)
  701. txq->tx_curr_desc = 0;
  702. desc = &txq->tx_desc_area[tx_index];
  703. if (nr_frags) {
  704. txq_submit_frag_skb(txq, skb);
  705. length = skb_headlen(skb);
  706. } else {
  707. cmd_sts |= ZERO_PADDING | TX_LAST_DESC | TX_ENABLE_INTERRUPT;
  708. length = skb->len;
  709. }
  710. desc->l4i_chk = l4i_chk;
  711. desc->byte_cnt = length;
  712. desc->buf_ptr = dma_map_single(mp->dev->dev.parent, skb->data,
  713. length, DMA_TO_DEVICE);
  714. __skb_queue_tail(&txq->tx_skb, skb);
  715. skb_tx_timestamp(skb);
  716. /* ensure all other descriptors are written before first cmd_sts */
  717. wmb();
  718. desc->cmd_sts = cmd_sts;
  719. /* clear TX_END status */
  720. mp->work_tx_end &= ~(1 << txq->index);
  721. /* ensure all descriptors are written before poking hardware */
  722. wmb();
  723. txq_enable(txq);
  724. txq->tx_desc_count += nr_frags + 1;
  725. return 0;
  726. }
  727. static netdev_tx_t mv643xx_eth_xmit(struct sk_buff *skb, struct net_device *dev)
  728. {
  729. struct mv643xx_eth_private *mp = netdev_priv(dev);
  730. int length, queue;
  731. struct tx_queue *txq;
  732. struct netdev_queue *nq;
  733. queue = skb_get_queue_mapping(skb);
  734. txq = mp->txq + queue;
  735. nq = netdev_get_tx_queue(dev, queue);
  736. if (has_tiny_unaligned_frags(skb) && __skb_linearize(skb)) {
  737. txq->tx_dropped++;
  738. netdev_printk(KERN_DEBUG, dev,
  739. "failed to linearize skb with tiny unaligned fragment\n");
  740. return NETDEV_TX_BUSY;
  741. }
  742. if (txq->tx_ring_size - txq->tx_desc_count < MAX_SKB_FRAGS + 1) {
  743. if (net_ratelimit())
  744. netdev_err(dev, "tx queue full?!\n");
  745. kfree_skb(skb);
  746. return NETDEV_TX_OK;
  747. }
  748. length = skb->len;
  749. if (!txq_submit_skb(txq, skb)) {
  750. int entries_left;
  751. txq->tx_bytes += length;
  752. txq->tx_packets++;
  753. entries_left = txq->tx_ring_size - txq->tx_desc_count;
  754. if (entries_left < MAX_SKB_FRAGS + 1)
  755. netif_tx_stop_queue(nq);
  756. }
  757. return NETDEV_TX_OK;
  758. }
  759. /* tx napi ******************************************************************/
  760. static void txq_kick(struct tx_queue *txq)
  761. {
  762. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  763. struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index);
  764. u32 hw_desc_ptr;
  765. u32 expected_ptr;
  766. __netif_tx_lock(nq, smp_processor_id());
  767. if (rdlp(mp, TXQ_COMMAND) & (1 << txq->index))
  768. goto out;
  769. hw_desc_ptr = rdlp(mp, TXQ_CURRENT_DESC_PTR(txq->index));
  770. expected_ptr = (u32)txq->tx_desc_dma +
  771. txq->tx_curr_desc * sizeof(struct tx_desc);
  772. if (hw_desc_ptr != expected_ptr)
  773. txq_enable(txq);
  774. out:
  775. __netif_tx_unlock(nq);
  776. mp->work_tx_end &= ~(1 << txq->index);
  777. }
  778. static int txq_reclaim(struct tx_queue *txq, int budget, int force)
  779. {
  780. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  781. struct netdev_queue *nq = netdev_get_tx_queue(mp->dev, txq->index);
  782. int reclaimed;
  783. __netif_tx_lock(nq, smp_processor_id());
  784. reclaimed = 0;
  785. while (reclaimed < budget && txq->tx_desc_count > 0) {
  786. int tx_index;
  787. struct tx_desc *desc;
  788. u32 cmd_sts;
  789. struct sk_buff *skb;
  790. tx_index = txq->tx_used_desc;
  791. desc = &txq->tx_desc_area[tx_index];
  792. cmd_sts = desc->cmd_sts;
  793. if (cmd_sts & BUFFER_OWNED_BY_DMA) {
  794. if (!force)
  795. break;
  796. desc->cmd_sts = cmd_sts & ~BUFFER_OWNED_BY_DMA;
  797. }
  798. txq->tx_used_desc = tx_index + 1;
  799. if (txq->tx_used_desc == txq->tx_ring_size)
  800. txq->tx_used_desc = 0;
  801. reclaimed++;
  802. txq->tx_desc_count--;
  803. skb = NULL;
  804. if (cmd_sts & TX_LAST_DESC)
  805. skb = __skb_dequeue(&txq->tx_skb);
  806. if (cmd_sts & ERROR_SUMMARY) {
  807. netdev_info(mp->dev, "tx error\n");
  808. mp->dev->stats.tx_errors++;
  809. }
  810. if (cmd_sts & TX_FIRST_DESC) {
  811. dma_unmap_single(mp->dev->dev.parent, desc->buf_ptr,
  812. desc->byte_cnt, DMA_TO_DEVICE);
  813. } else {
  814. dma_unmap_page(mp->dev->dev.parent, desc->buf_ptr,
  815. desc->byte_cnt, DMA_TO_DEVICE);
  816. }
  817. if (skb != NULL) {
  818. if (skb_queue_len(&mp->rx_recycle) <
  819. mp->rx_ring_size &&
  820. skb_recycle_check(skb, mp->skb_size))
  821. __skb_queue_head(&mp->rx_recycle, skb);
  822. else
  823. dev_kfree_skb(skb);
  824. }
  825. }
  826. __netif_tx_unlock(nq);
  827. if (reclaimed < budget)
  828. mp->work_tx &= ~(1 << txq->index);
  829. return reclaimed;
  830. }
  831. /* tx rate control **********************************************************/
  832. /*
  833. * Set total maximum TX rate (shared by all TX queues for this port)
  834. * to 'rate' bits per second, with a maximum burst of 'burst' bytes.
  835. */
  836. static void tx_set_rate(struct mv643xx_eth_private *mp, int rate, int burst)
  837. {
  838. int token_rate;
  839. int mtu;
  840. int bucket_size;
  841. token_rate = ((rate / 1000) * 64) / (mp->shared->t_clk / 1000);
  842. if (token_rate > 1023)
  843. token_rate = 1023;
  844. mtu = (mp->dev->mtu + 255) >> 8;
  845. if (mtu > 63)
  846. mtu = 63;
  847. bucket_size = (burst + 255) >> 8;
  848. if (bucket_size > 65535)
  849. bucket_size = 65535;
  850. switch (mp->shared->tx_bw_control) {
  851. case TX_BW_CONTROL_OLD_LAYOUT:
  852. wrlp(mp, TX_BW_RATE, token_rate);
  853. wrlp(mp, TX_BW_MTU, mtu);
  854. wrlp(mp, TX_BW_BURST, bucket_size);
  855. break;
  856. case TX_BW_CONTROL_NEW_LAYOUT:
  857. wrlp(mp, TX_BW_RATE_MOVED, token_rate);
  858. wrlp(mp, TX_BW_MTU_MOVED, mtu);
  859. wrlp(mp, TX_BW_BURST_MOVED, bucket_size);
  860. break;
  861. }
  862. }
  863. static void txq_set_rate(struct tx_queue *txq, int rate, int burst)
  864. {
  865. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  866. int token_rate;
  867. int bucket_size;
  868. token_rate = ((rate / 1000) * 64) / (mp->shared->t_clk / 1000);
  869. if (token_rate > 1023)
  870. token_rate = 1023;
  871. bucket_size = (burst + 255) >> 8;
  872. if (bucket_size > 65535)
  873. bucket_size = 65535;
  874. wrlp(mp, TXQ_BW_TOKENS(txq->index), token_rate << 14);
  875. wrlp(mp, TXQ_BW_CONF(txq->index), (bucket_size << 10) | token_rate);
  876. }
  877. static void txq_set_fixed_prio_mode(struct tx_queue *txq)
  878. {
  879. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  880. int off;
  881. u32 val;
  882. /*
  883. * Turn on fixed priority mode.
  884. */
  885. off = 0;
  886. switch (mp->shared->tx_bw_control) {
  887. case TX_BW_CONTROL_OLD_LAYOUT:
  888. off = TXQ_FIX_PRIO_CONF;
  889. break;
  890. case TX_BW_CONTROL_NEW_LAYOUT:
  891. off = TXQ_FIX_PRIO_CONF_MOVED;
  892. break;
  893. }
  894. if (off) {
  895. val = rdlp(mp, off);
  896. val |= 1 << txq->index;
  897. wrlp(mp, off, val);
  898. }
  899. }
  900. /* mii management interface *************************************************/
  901. static irqreturn_t mv643xx_eth_err_irq(int irq, void *dev_id)
  902. {
  903. struct mv643xx_eth_shared_private *msp = dev_id;
  904. if (readl(msp->base + ERR_INT_CAUSE) & ERR_INT_SMI_DONE) {
  905. writel(~ERR_INT_SMI_DONE, msp->base + ERR_INT_CAUSE);
  906. wake_up(&msp->smi_busy_wait);
  907. return IRQ_HANDLED;
  908. }
  909. return IRQ_NONE;
  910. }
  911. static int smi_is_done(struct mv643xx_eth_shared_private *msp)
  912. {
  913. return !(readl(msp->base + SMI_REG) & SMI_BUSY);
  914. }
  915. static int smi_wait_ready(struct mv643xx_eth_shared_private *msp)
  916. {
  917. if (msp->err_interrupt == NO_IRQ) {
  918. int i;
  919. for (i = 0; !smi_is_done(msp); i++) {
  920. if (i == 10)
  921. return -ETIMEDOUT;
  922. msleep(10);
  923. }
  924. return 0;
  925. }
  926. if (!smi_is_done(msp)) {
  927. wait_event_timeout(msp->smi_busy_wait, smi_is_done(msp),
  928. msecs_to_jiffies(100));
  929. if (!smi_is_done(msp))
  930. return -ETIMEDOUT;
  931. }
  932. return 0;
  933. }
  934. static int smi_bus_read(struct mii_bus *bus, int addr, int reg)
  935. {
  936. struct mv643xx_eth_shared_private *msp = bus->priv;
  937. void __iomem *smi_reg = msp->base + SMI_REG;
  938. int ret;
  939. if (smi_wait_ready(msp)) {
  940. pr_warn("SMI bus busy timeout\n");
  941. return -ETIMEDOUT;
  942. }
  943. writel(SMI_OPCODE_READ | (reg << 21) | (addr << 16), smi_reg);
  944. if (smi_wait_ready(msp)) {
  945. pr_warn("SMI bus busy timeout\n");
  946. return -ETIMEDOUT;
  947. }
  948. ret = readl(smi_reg);
  949. if (!(ret & SMI_READ_VALID)) {
  950. pr_warn("SMI bus read not valid\n");
  951. return -ENODEV;
  952. }
  953. return ret & 0xffff;
  954. }
  955. static int smi_bus_write(struct mii_bus *bus, int addr, int reg, u16 val)
  956. {
  957. struct mv643xx_eth_shared_private *msp = bus->priv;
  958. void __iomem *smi_reg = msp->base + SMI_REG;
  959. if (smi_wait_ready(msp)) {
  960. pr_warn("SMI bus busy timeout\n");
  961. return -ETIMEDOUT;
  962. }
  963. writel(SMI_OPCODE_WRITE | (reg << 21) |
  964. (addr << 16) | (val & 0xffff), smi_reg);
  965. if (smi_wait_ready(msp)) {
  966. pr_warn("SMI bus busy timeout\n");
  967. return -ETIMEDOUT;
  968. }
  969. return 0;
  970. }
  971. /* statistics ***************************************************************/
  972. static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *dev)
  973. {
  974. struct mv643xx_eth_private *mp = netdev_priv(dev);
  975. struct net_device_stats *stats = &dev->stats;
  976. unsigned long tx_packets = 0;
  977. unsigned long tx_bytes = 0;
  978. unsigned long tx_dropped = 0;
  979. int i;
  980. for (i = 0; i < mp->txq_count; i++) {
  981. struct tx_queue *txq = mp->txq + i;
  982. tx_packets += txq->tx_packets;
  983. tx_bytes += txq->tx_bytes;
  984. tx_dropped += txq->tx_dropped;
  985. }
  986. stats->tx_packets = tx_packets;
  987. stats->tx_bytes = tx_bytes;
  988. stats->tx_dropped = tx_dropped;
  989. return stats;
  990. }
  991. static void mv643xx_eth_grab_lro_stats(struct mv643xx_eth_private *mp)
  992. {
  993. u32 lro_aggregated = 0;
  994. u32 lro_flushed = 0;
  995. u32 lro_no_desc = 0;
  996. int i;
  997. for (i = 0; i < mp->rxq_count; i++) {
  998. struct rx_queue *rxq = mp->rxq + i;
  999. lro_aggregated += rxq->lro_mgr.stats.aggregated;
  1000. lro_flushed += rxq->lro_mgr.stats.flushed;
  1001. lro_no_desc += rxq->lro_mgr.stats.no_desc;
  1002. }
  1003. mp->lro_counters.lro_aggregated = lro_aggregated;
  1004. mp->lro_counters.lro_flushed = lro_flushed;
  1005. mp->lro_counters.lro_no_desc = lro_no_desc;
  1006. }
  1007. static inline u32 mib_read(struct mv643xx_eth_private *mp, int offset)
  1008. {
  1009. return rdl(mp, MIB_COUNTERS(mp->port_num) + offset);
  1010. }
  1011. static void mib_counters_clear(struct mv643xx_eth_private *mp)
  1012. {
  1013. int i;
  1014. for (i = 0; i < 0x80; i += 4)
  1015. mib_read(mp, i);
  1016. /* Clear non MIB hw counters also */
  1017. rdlp(mp, RX_DISCARD_FRAME_CNT);
  1018. rdlp(mp, RX_OVERRUN_FRAME_CNT);
  1019. }
  1020. static void mib_counters_update(struct mv643xx_eth_private *mp)
  1021. {
  1022. struct mib_counters *p = &mp->mib_counters;
  1023. spin_lock_bh(&mp->mib_counters_lock);
  1024. p->good_octets_received += mib_read(mp, 0x00);
  1025. p->bad_octets_received += mib_read(mp, 0x08);
  1026. p->internal_mac_transmit_err += mib_read(mp, 0x0c);
  1027. p->good_frames_received += mib_read(mp, 0x10);
  1028. p->bad_frames_received += mib_read(mp, 0x14);
  1029. p->broadcast_frames_received += mib_read(mp, 0x18);
  1030. p->multicast_frames_received += mib_read(mp, 0x1c);
  1031. p->frames_64_octets += mib_read(mp, 0x20);
  1032. p->frames_65_to_127_octets += mib_read(mp, 0x24);
  1033. p->frames_128_to_255_octets += mib_read(mp, 0x28);
  1034. p->frames_256_to_511_octets += mib_read(mp, 0x2c);
  1035. p->frames_512_to_1023_octets += mib_read(mp, 0x30);
  1036. p->frames_1024_to_max_octets += mib_read(mp, 0x34);
  1037. p->good_octets_sent += mib_read(mp, 0x38);
  1038. p->good_frames_sent += mib_read(mp, 0x40);
  1039. p->excessive_collision += mib_read(mp, 0x44);
  1040. p->multicast_frames_sent += mib_read(mp, 0x48);
  1041. p->broadcast_frames_sent += mib_read(mp, 0x4c);
  1042. p->unrec_mac_control_received += mib_read(mp, 0x50);
  1043. p->fc_sent += mib_read(mp, 0x54);
  1044. p->good_fc_received += mib_read(mp, 0x58);
  1045. p->bad_fc_received += mib_read(mp, 0x5c);
  1046. p->undersize_received += mib_read(mp, 0x60);
  1047. p->fragments_received += mib_read(mp, 0x64);
  1048. p->oversize_received += mib_read(mp, 0x68);
  1049. p->jabber_received += mib_read(mp, 0x6c);
  1050. p->mac_receive_error += mib_read(mp, 0x70);
  1051. p->bad_crc_event += mib_read(mp, 0x74);
  1052. p->collision += mib_read(mp, 0x78);
  1053. p->late_collision += mib_read(mp, 0x7c);
  1054. /* Non MIB hardware counters */
  1055. p->rx_discard += rdlp(mp, RX_DISCARD_FRAME_CNT);
  1056. p->rx_overrun += rdlp(mp, RX_OVERRUN_FRAME_CNT);
  1057. spin_unlock_bh(&mp->mib_counters_lock);
  1058. mod_timer(&mp->mib_counters_timer, jiffies + 30 * HZ);
  1059. }
  1060. static void mib_counters_timer_wrapper(unsigned long _mp)
  1061. {
  1062. struct mv643xx_eth_private *mp = (void *)_mp;
  1063. mib_counters_update(mp);
  1064. }
  1065. /* interrupt coalescing *****************************************************/
  1066. /*
  1067. * Hardware coalescing parameters are set in units of 64 t_clk
  1068. * cycles. I.e.:
  1069. *
  1070. * coal_delay_in_usec = 64000000 * register_value / t_clk_rate
  1071. *
  1072. * register_value = coal_delay_in_usec * t_clk_rate / 64000000
  1073. *
  1074. * In the ->set*() methods, we round the computed register value
  1075. * to the nearest integer.
  1076. */
  1077. static unsigned int get_rx_coal(struct mv643xx_eth_private *mp)
  1078. {
  1079. u32 val = rdlp(mp, SDMA_CONFIG);
  1080. u64 temp;
  1081. if (mp->shared->extended_rx_coal_limit)
  1082. temp = ((val & 0x02000000) >> 10) | ((val & 0x003fff80) >> 7);
  1083. else
  1084. temp = (val & 0x003fff00) >> 8;
  1085. temp *= 64000000;
  1086. do_div(temp, mp->shared->t_clk);
  1087. return (unsigned int)temp;
  1088. }
  1089. static void set_rx_coal(struct mv643xx_eth_private *mp, unsigned int usec)
  1090. {
  1091. u64 temp;
  1092. u32 val;
  1093. temp = (u64)usec * mp->shared->t_clk;
  1094. temp += 31999999;
  1095. do_div(temp, 64000000);
  1096. val = rdlp(mp, SDMA_CONFIG);
  1097. if (mp->shared->extended_rx_coal_limit) {
  1098. if (temp > 0xffff)
  1099. temp = 0xffff;
  1100. val &= ~0x023fff80;
  1101. val |= (temp & 0x8000) << 10;
  1102. val |= (temp & 0x7fff) << 7;
  1103. } else {
  1104. if (temp > 0x3fff)
  1105. temp = 0x3fff;
  1106. val &= ~0x003fff00;
  1107. val |= (temp & 0x3fff) << 8;
  1108. }
  1109. wrlp(mp, SDMA_CONFIG, val);
  1110. }
  1111. static unsigned int get_tx_coal(struct mv643xx_eth_private *mp)
  1112. {
  1113. u64 temp;
  1114. temp = (rdlp(mp, TX_FIFO_URGENT_THRESHOLD) & 0x3fff0) >> 4;
  1115. temp *= 64000000;
  1116. do_div(temp, mp->shared->t_clk);
  1117. return (unsigned int)temp;
  1118. }
  1119. static void set_tx_coal(struct mv643xx_eth_private *mp, unsigned int usec)
  1120. {
  1121. u64 temp;
  1122. temp = (u64)usec * mp->shared->t_clk;
  1123. temp += 31999999;
  1124. do_div(temp, 64000000);
  1125. if (temp > 0x3fff)
  1126. temp = 0x3fff;
  1127. wrlp(mp, TX_FIFO_URGENT_THRESHOLD, temp << 4);
  1128. }
  1129. /* ethtool ******************************************************************/
  1130. struct mv643xx_eth_stats {
  1131. char stat_string[ETH_GSTRING_LEN];
  1132. int sizeof_stat;
  1133. int netdev_off;
  1134. int mp_off;
  1135. };
  1136. #define SSTAT(m) \
  1137. { #m, FIELD_SIZEOF(struct net_device_stats, m), \
  1138. offsetof(struct net_device, stats.m), -1 }
  1139. #define MIBSTAT(m) \
  1140. { #m, FIELD_SIZEOF(struct mib_counters, m), \
  1141. -1, offsetof(struct mv643xx_eth_private, mib_counters.m) }
  1142. #define LROSTAT(m) \
  1143. { #m, FIELD_SIZEOF(struct lro_counters, m), \
  1144. -1, offsetof(struct mv643xx_eth_private, lro_counters.m) }
  1145. static const struct mv643xx_eth_stats mv643xx_eth_stats[] = {
  1146. SSTAT(rx_packets),
  1147. SSTAT(tx_packets),
  1148. SSTAT(rx_bytes),
  1149. SSTAT(tx_bytes),
  1150. SSTAT(rx_errors),
  1151. SSTAT(tx_errors),
  1152. SSTAT(rx_dropped),
  1153. SSTAT(tx_dropped),
  1154. MIBSTAT(good_octets_received),
  1155. MIBSTAT(bad_octets_received),
  1156. MIBSTAT(internal_mac_transmit_err),
  1157. MIBSTAT(good_frames_received),
  1158. MIBSTAT(bad_frames_received),
  1159. MIBSTAT(broadcast_frames_received),
  1160. MIBSTAT(multicast_frames_received),
  1161. MIBSTAT(frames_64_octets),
  1162. MIBSTAT(frames_65_to_127_octets),
  1163. MIBSTAT(frames_128_to_255_octets),
  1164. MIBSTAT(frames_256_to_511_octets),
  1165. MIBSTAT(frames_512_to_1023_octets),
  1166. MIBSTAT(frames_1024_to_max_octets),
  1167. MIBSTAT(good_octets_sent),
  1168. MIBSTAT(good_frames_sent),
  1169. MIBSTAT(excessive_collision),
  1170. MIBSTAT(multicast_frames_sent),
  1171. MIBSTAT(broadcast_frames_sent),
  1172. MIBSTAT(unrec_mac_control_received),
  1173. MIBSTAT(fc_sent),
  1174. MIBSTAT(good_fc_received),
  1175. MIBSTAT(bad_fc_received),
  1176. MIBSTAT(undersize_received),
  1177. MIBSTAT(fragments_received),
  1178. MIBSTAT(oversize_received),
  1179. MIBSTAT(jabber_received),
  1180. MIBSTAT(mac_receive_error),
  1181. MIBSTAT(bad_crc_event),
  1182. MIBSTAT(collision),
  1183. MIBSTAT(late_collision),
  1184. MIBSTAT(rx_discard),
  1185. MIBSTAT(rx_overrun),
  1186. LROSTAT(lro_aggregated),
  1187. LROSTAT(lro_flushed),
  1188. LROSTAT(lro_no_desc),
  1189. };
  1190. static int
  1191. mv643xx_eth_get_settings_phy(struct mv643xx_eth_private *mp,
  1192. struct ethtool_cmd *cmd)
  1193. {
  1194. int err;
  1195. err = phy_read_status(mp->phy);
  1196. if (err == 0)
  1197. err = phy_ethtool_gset(mp->phy, cmd);
  1198. /*
  1199. * The MAC does not support 1000baseT_Half.
  1200. */
  1201. cmd->supported &= ~SUPPORTED_1000baseT_Half;
  1202. cmd->advertising &= ~ADVERTISED_1000baseT_Half;
  1203. return err;
  1204. }
  1205. static int
  1206. mv643xx_eth_get_settings_phyless(struct mv643xx_eth_private *mp,
  1207. struct ethtool_cmd *cmd)
  1208. {
  1209. u32 port_status;
  1210. port_status = rdlp(mp, PORT_STATUS);
  1211. cmd->supported = SUPPORTED_MII;
  1212. cmd->advertising = ADVERTISED_MII;
  1213. switch (port_status & PORT_SPEED_MASK) {
  1214. case PORT_SPEED_10:
  1215. ethtool_cmd_speed_set(cmd, SPEED_10);
  1216. break;
  1217. case PORT_SPEED_100:
  1218. ethtool_cmd_speed_set(cmd, SPEED_100);
  1219. break;
  1220. case PORT_SPEED_1000:
  1221. ethtool_cmd_speed_set(cmd, SPEED_1000);
  1222. break;
  1223. default:
  1224. cmd->speed = -1;
  1225. break;
  1226. }
  1227. cmd->duplex = (port_status & FULL_DUPLEX) ? DUPLEX_FULL : DUPLEX_HALF;
  1228. cmd->port = PORT_MII;
  1229. cmd->phy_address = 0;
  1230. cmd->transceiver = XCVR_INTERNAL;
  1231. cmd->autoneg = AUTONEG_DISABLE;
  1232. cmd->maxtxpkt = 1;
  1233. cmd->maxrxpkt = 1;
  1234. return 0;
  1235. }
  1236. static int
  1237. mv643xx_eth_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1238. {
  1239. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1240. if (mp->phy != NULL)
  1241. return mv643xx_eth_get_settings_phy(mp, cmd);
  1242. else
  1243. return mv643xx_eth_get_settings_phyless(mp, cmd);
  1244. }
  1245. static int
  1246. mv643xx_eth_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  1247. {
  1248. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1249. if (mp->phy == NULL)
  1250. return -EINVAL;
  1251. /*
  1252. * The MAC does not support 1000baseT_Half.
  1253. */
  1254. cmd->advertising &= ~ADVERTISED_1000baseT_Half;
  1255. return phy_ethtool_sset(mp->phy, cmd);
  1256. }
  1257. static void mv643xx_eth_get_drvinfo(struct net_device *dev,
  1258. struct ethtool_drvinfo *drvinfo)
  1259. {
  1260. strlcpy(drvinfo->driver, mv643xx_eth_driver_name,
  1261. sizeof(drvinfo->driver));
  1262. strlcpy(drvinfo->version, mv643xx_eth_driver_version,
  1263. sizeof(drvinfo->version));
  1264. strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
  1265. strlcpy(drvinfo->bus_info, "platform", sizeof(drvinfo->bus_info));
  1266. drvinfo->n_stats = ARRAY_SIZE(mv643xx_eth_stats);
  1267. }
  1268. static int mv643xx_eth_nway_reset(struct net_device *dev)
  1269. {
  1270. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1271. if (mp->phy == NULL)
  1272. return -EINVAL;
  1273. return genphy_restart_aneg(mp->phy);
  1274. }
  1275. static int
  1276. mv643xx_eth_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  1277. {
  1278. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1279. ec->rx_coalesce_usecs = get_rx_coal(mp);
  1280. ec->tx_coalesce_usecs = get_tx_coal(mp);
  1281. return 0;
  1282. }
  1283. static int
  1284. mv643xx_eth_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec)
  1285. {
  1286. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1287. set_rx_coal(mp, ec->rx_coalesce_usecs);
  1288. set_tx_coal(mp, ec->tx_coalesce_usecs);
  1289. return 0;
  1290. }
  1291. static void
  1292. mv643xx_eth_get_ringparam(struct net_device *dev, struct ethtool_ringparam *er)
  1293. {
  1294. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1295. er->rx_max_pending = 4096;
  1296. er->tx_max_pending = 4096;
  1297. er->rx_pending = mp->rx_ring_size;
  1298. er->tx_pending = mp->tx_ring_size;
  1299. }
  1300. static int
  1301. mv643xx_eth_set_ringparam(struct net_device *dev, struct ethtool_ringparam *er)
  1302. {
  1303. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1304. if (er->rx_mini_pending || er->rx_jumbo_pending)
  1305. return -EINVAL;
  1306. mp->rx_ring_size = er->rx_pending < 4096 ? er->rx_pending : 4096;
  1307. mp->tx_ring_size = er->tx_pending < 4096 ? er->tx_pending : 4096;
  1308. if (netif_running(dev)) {
  1309. mv643xx_eth_stop(dev);
  1310. if (mv643xx_eth_open(dev)) {
  1311. netdev_err(dev,
  1312. "fatal error on re-opening device after ring param change\n");
  1313. return -ENOMEM;
  1314. }
  1315. }
  1316. return 0;
  1317. }
  1318. static int
  1319. mv643xx_eth_set_features(struct net_device *dev, netdev_features_t features)
  1320. {
  1321. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1322. bool rx_csum = features & NETIF_F_RXCSUM;
  1323. wrlp(mp, PORT_CONFIG, rx_csum ? 0x02000000 : 0x00000000);
  1324. return 0;
  1325. }
  1326. static void mv643xx_eth_get_strings(struct net_device *dev,
  1327. uint32_t stringset, uint8_t *data)
  1328. {
  1329. int i;
  1330. if (stringset == ETH_SS_STATS) {
  1331. for (i = 0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) {
  1332. memcpy(data + i * ETH_GSTRING_LEN,
  1333. mv643xx_eth_stats[i].stat_string,
  1334. ETH_GSTRING_LEN);
  1335. }
  1336. }
  1337. }
  1338. static void mv643xx_eth_get_ethtool_stats(struct net_device *dev,
  1339. struct ethtool_stats *stats,
  1340. uint64_t *data)
  1341. {
  1342. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1343. int i;
  1344. mv643xx_eth_get_stats(dev);
  1345. mib_counters_update(mp);
  1346. mv643xx_eth_grab_lro_stats(mp);
  1347. for (i = 0; i < ARRAY_SIZE(mv643xx_eth_stats); i++) {
  1348. const struct mv643xx_eth_stats *stat;
  1349. void *p;
  1350. stat = mv643xx_eth_stats + i;
  1351. if (stat->netdev_off >= 0)
  1352. p = ((void *)mp->dev) + stat->netdev_off;
  1353. else
  1354. p = ((void *)mp) + stat->mp_off;
  1355. data[i] = (stat->sizeof_stat == 8) ?
  1356. *(uint64_t *)p : *(uint32_t *)p;
  1357. }
  1358. }
  1359. static int mv643xx_eth_get_sset_count(struct net_device *dev, int sset)
  1360. {
  1361. if (sset == ETH_SS_STATS)
  1362. return ARRAY_SIZE(mv643xx_eth_stats);
  1363. return -EOPNOTSUPP;
  1364. }
  1365. static const struct ethtool_ops mv643xx_eth_ethtool_ops = {
  1366. .get_settings = mv643xx_eth_get_settings,
  1367. .set_settings = mv643xx_eth_set_settings,
  1368. .get_drvinfo = mv643xx_eth_get_drvinfo,
  1369. .nway_reset = mv643xx_eth_nway_reset,
  1370. .get_link = ethtool_op_get_link,
  1371. .get_coalesce = mv643xx_eth_get_coalesce,
  1372. .set_coalesce = mv643xx_eth_set_coalesce,
  1373. .get_ringparam = mv643xx_eth_get_ringparam,
  1374. .set_ringparam = mv643xx_eth_set_ringparam,
  1375. .get_strings = mv643xx_eth_get_strings,
  1376. .get_ethtool_stats = mv643xx_eth_get_ethtool_stats,
  1377. .get_sset_count = mv643xx_eth_get_sset_count,
  1378. };
  1379. /* address handling *********************************************************/
  1380. static void uc_addr_get(struct mv643xx_eth_private *mp, unsigned char *addr)
  1381. {
  1382. unsigned int mac_h = rdlp(mp, MAC_ADDR_HIGH);
  1383. unsigned int mac_l = rdlp(mp, MAC_ADDR_LOW);
  1384. addr[0] = (mac_h >> 24) & 0xff;
  1385. addr[1] = (mac_h >> 16) & 0xff;
  1386. addr[2] = (mac_h >> 8) & 0xff;
  1387. addr[3] = mac_h & 0xff;
  1388. addr[4] = (mac_l >> 8) & 0xff;
  1389. addr[5] = mac_l & 0xff;
  1390. }
  1391. static void uc_addr_set(struct mv643xx_eth_private *mp, unsigned char *addr)
  1392. {
  1393. wrlp(mp, MAC_ADDR_HIGH,
  1394. (addr[0] << 24) | (addr[1] << 16) | (addr[2] << 8) | addr[3]);
  1395. wrlp(mp, MAC_ADDR_LOW, (addr[4] << 8) | addr[5]);
  1396. }
  1397. static u32 uc_addr_filter_mask(struct net_device *dev)
  1398. {
  1399. struct netdev_hw_addr *ha;
  1400. u32 nibbles;
  1401. if (dev->flags & IFF_PROMISC)
  1402. return 0;
  1403. nibbles = 1 << (dev->dev_addr[5] & 0x0f);
  1404. netdev_for_each_uc_addr(ha, dev) {
  1405. if (memcmp(dev->dev_addr, ha->addr, 5))
  1406. return 0;
  1407. if ((dev->dev_addr[5] ^ ha->addr[5]) & 0xf0)
  1408. return 0;
  1409. nibbles |= 1 << (ha->addr[5] & 0x0f);
  1410. }
  1411. return nibbles;
  1412. }
  1413. static void mv643xx_eth_program_unicast_filter(struct net_device *dev)
  1414. {
  1415. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1416. u32 port_config;
  1417. u32 nibbles;
  1418. int i;
  1419. uc_addr_set(mp, dev->dev_addr);
  1420. port_config = rdlp(mp, PORT_CONFIG) & ~UNICAST_PROMISCUOUS_MODE;
  1421. nibbles = uc_addr_filter_mask(dev);
  1422. if (!nibbles) {
  1423. port_config |= UNICAST_PROMISCUOUS_MODE;
  1424. nibbles = 0xffff;
  1425. }
  1426. for (i = 0; i < 16; i += 4) {
  1427. int off = UNICAST_TABLE(mp->port_num) + i;
  1428. u32 v;
  1429. v = 0;
  1430. if (nibbles & 1)
  1431. v |= 0x00000001;
  1432. if (nibbles & 2)
  1433. v |= 0x00000100;
  1434. if (nibbles & 4)
  1435. v |= 0x00010000;
  1436. if (nibbles & 8)
  1437. v |= 0x01000000;
  1438. nibbles >>= 4;
  1439. wrl(mp, off, v);
  1440. }
  1441. wrlp(mp, PORT_CONFIG, port_config);
  1442. }
  1443. static int addr_crc(unsigned char *addr)
  1444. {
  1445. int crc = 0;
  1446. int i;
  1447. for (i = 0; i < 6; i++) {
  1448. int j;
  1449. crc = (crc ^ addr[i]) << 8;
  1450. for (j = 7; j >= 0; j--) {
  1451. if (crc & (0x100 << j))
  1452. crc ^= 0x107 << j;
  1453. }
  1454. }
  1455. return crc;
  1456. }
  1457. static void mv643xx_eth_program_multicast_filter(struct net_device *dev)
  1458. {
  1459. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1460. u32 *mc_spec;
  1461. u32 *mc_other;
  1462. struct netdev_hw_addr *ha;
  1463. int i;
  1464. if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
  1465. int port_num;
  1466. u32 accept;
  1467. oom:
  1468. port_num = mp->port_num;
  1469. accept = 0x01010101;
  1470. for (i = 0; i < 0x100; i += 4) {
  1471. wrl(mp, SPECIAL_MCAST_TABLE(port_num) + i, accept);
  1472. wrl(mp, OTHER_MCAST_TABLE(port_num) + i, accept);
  1473. }
  1474. return;
  1475. }
  1476. mc_spec = kmalloc(0x200, GFP_ATOMIC);
  1477. if (mc_spec == NULL)
  1478. goto oom;
  1479. mc_other = mc_spec + (0x100 >> 2);
  1480. memset(mc_spec, 0, 0x100);
  1481. memset(mc_other, 0, 0x100);
  1482. netdev_for_each_mc_addr(ha, dev) {
  1483. u8 *a = ha->addr;
  1484. u32 *table;
  1485. int entry;
  1486. if (memcmp(a, "\x01\x00\x5e\x00\x00", 5) == 0) {
  1487. table = mc_spec;
  1488. entry = a[5];
  1489. } else {
  1490. table = mc_other;
  1491. entry = addr_crc(a);
  1492. }
  1493. table[entry >> 2] |= 1 << (8 * (entry & 3));
  1494. }
  1495. for (i = 0; i < 0x100; i += 4) {
  1496. wrl(mp, SPECIAL_MCAST_TABLE(mp->port_num) + i, mc_spec[i >> 2]);
  1497. wrl(mp, OTHER_MCAST_TABLE(mp->port_num) + i, mc_other[i >> 2]);
  1498. }
  1499. kfree(mc_spec);
  1500. }
  1501. static void mv643xx_eth_set_rx_mode(struct net_device *dev)
  1502. {
  1503. mv643xx_eth_program_unicast_filter(dev);
  1504. mv643xx_eth_program_multicast_filter(dev);
  1505. }
  1506. static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr)
  1507. {
  1508. struct sockaddr *sa = addr;
  1509. if (!is_valid_ether_addr(sa->sa_data))
  1510. return -EADDRNOTAVAIL;
  1511. memcpy(dev->dev_addr, sa->sa_data, ETH_ALEN);
  1512. netif_addr_lock_bh(dev);
  1513. mv643xx_eth_program_unicast_filter(dev);
  1514. netif_addr_unlock_bh(dev);
  1515. return 0;
  1516. }
  1517. /* rx/tx queue initialisation ***********************************************/
  1518. static int rxq_init(struct mv643xx_eth_private *mp, int index)
  1519. {
  1520. struct rx_queue *rxq = mp->rxq + index;
  1521. struct rx_desc *rx_desc;
  1522. int size;
  1523. int i;
  1524. rxq->index = index;
  1525. rxq->rx_ring_size = mp->rx_ring_size;
  1526. rxq->rx_desc_count = 0;
  1527. rxq->rx_curr_desc = 0;
  1528. rxq->rx_used_desc = 0;
  1529. size = rxq->rx_ring_size * sizeof(struct rx_desc);
  1530. if (index == 0 && size <= mp->rx_desc_sram_size) {
  1531. rxq->rx_desc_area = ioremap(mp->rx_desc_sram_addr,
  1532. mp->rx_desc_sram_size);
  1533. rxq->rx_desc_dma = mp->rx_desc_sram_addr;
  1534. } else {
  1535. rxq->rx_desc_area = dma_alloc_coherent(mp->dev->dev.parent,
  1536. size, &rxq->rx_desc_dma,
  1537. GFP_KERNEL);
  1538. }
  1539. if (rxq->rx_desc_area == NULL) {
  1540. netdev_err(mp->dev,
  1541. "can't allocate rx ring (%d bytes)\n", size);
  1542. goto out;
  1543. }
  1544. memset(rxq->rx_desc_area, 0, size);
  1545. rxq->rx_desc_area_size = size;
  1546. rxq->rx_skb = kmalloc(rxq->rx_ring_size * sizeof(*rxq->rx_skb),
  1547. GFP_KERNEL);
  1548. if (rxq->rx_skb == NULL) {
  1549. netdev_err(mp->dev, "can't allocate rx skb ring\n");
  1550. goto out_free;
  1551. }
  1552. rx_desc = (struct rx_desc *)rxq->rx_desc_area;
  1553. for (i = 0; i < rxq->rx_ring_size; i++) {
  1554. int nexti;
  1555. nexti = i + 1;
  1556. if (nexti == rxq->rx_ring_size)
  1557. nexti = 0;
  1558. rx_desc[i].next_desc_ptr = rxq->rx_desc_dma +
  1559. nexti * sizeof(struct rx_desc);
  1560. }
  1561. rxq->lro_mgr.dev = mp->dev;
  1562. memset(&rxq->lro_mgr.stats, 0, sizeof(rxq->lro_mgr.stats));
  1563. rxq->lro_mgr.features = LRO_F_NAPI;
  1564. rxq->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
  1565. rxq->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
  1566. rxq->lro_mgr.max_desc = ARRAY_SIZE(rxq->lro_arr);
  1567. rxq->lro_mgr.max_aggr = 32;
  1568. rxq->lro_mgr.frag_align_pad = 0;
  1569. rxq->lro_mgr.lro_arr = rxq->lro_arr;
  1570. rxq->lro_mgr.get_skb_header = mv643xx_get_skb_header;
  1571. memset(&rxq->lro_arr, 0, sizeof(rxq->lro_arr));
  1572. return 0;
  1573. out_free:
  1574. if (index == 0 && size <= mp->rx_desc_sram_size)
  1575. iounmap(rxq->rx_desc_area);
  1576. else
  1577. dma_free_coherent(mp->dev->dev.parent, size,
  1578. rxq->rx_desc_area,
  1579. rxq->rx_desc_dma);
  1580. out:
  1581. return -ENOMEM;
  1582. }
  1583. static void rxq_deinit(struct rx_queue *rxq)
  1584. {
  1585. struct mv643xx_eth_private *mp = rxq_to_mp(rxq);
  1586. int i;
  1587. rxq_disable(rxq);
  1588. for (i = 0; i < rxq->rx_ring_size; i++) {
  1589. if (rxq->rx_skb[i]) {
  1590. dev_kfree_skb(rxq->rx_skb[i]);
  1591. rxq->rx_desc_count--;
  1592. }
  1593. }
  1594. if (rxq->rx_desc_count) {
  1595. netdev_err(mp->dev, "error freeing rx ring -- %d skbs stuck\n",
  1596. rxq->rx_desc_count);
  1597. }
  1598. if (rxq->index == 0 &&
  1599. rxq->rx_desc_area_size <= mp->rx_desc_sram_size)
  1600. iounmap(rxq->rx_desc_area);
  1601. else
  1602. dma_free_coherent(mp->dev->dev.parent, rxq->rx_desc_area_size,
  1603. rxq->rx_desc_area, rxq->rx_desc_dma);
  1604. kfree(rxq->rx_skb);
  1605. }
  1606. static int txq_init(struct mv643xx_eth_private *mp, int index)
  1607. {
  1608. struct tx_queue *txq = mp->txq + index;
  1609. struct tx_desc *tx_desc;
  1610. int size;
  1611. int i;
  1612. txq->index = index;
  1613. txq->tx_ring_size = mp->tx_ring_size;
  1614. txq->tx_desc_count = 0;
  1615. txq->tx_curr_desc = 0;
  1616. txq->tx_used_desc = 0;
  1617. size = txq->tx_ring_size * sizeof(struct tx_desc);
  1618. if (index == 0 && size <= mp->tx_desc_sram_size) {
  1619. txq->tx_desc_area = ioremap(mp->tx_desc_sram_addr,
  1620. mp->tx_desc_sram_size);
  1621. txq->tx_desc_dma = mp->tx_desc_sram_addr;
  1622. } else {
  1623. txq->tx_desc_area = dma_alloc_coherent(mp->dev->dev.parent,
  1624. size, &txq->tx_desc_dma,
  1625. GFP_KERNEL);
  1626. }
  1627. if (txq->tx_desc_area == NULL) {
  1628. netdev_err(mp->dev,
  1629. "can't allocate tx ring (%d bytes)\n", size);
  1630. return -ENOMEM;
  1631. }
  1632. memset(txq->tx_desc_area, 0, size);
  1633. txq->tx_desc_area_size = size;
  1634. tx_desc = (struct tx_desc *)txq->tx_desc_area;
  1635. for (i = 0; i < txq->tx_ring_size; i++) {
  1636. struct tx_desc *txd = tx_desc + i;
  1637. int nexti;
  1638. nexti = i + 1;
  1639. if (nexti == txq->tx_ring_size)
  1640. nexti = 0;
  1641. txd->cmd_sts = 0;
  1642. txd->next_desc_ptr = txq->tx_desc_dma +
  1643. nexti * sizeof(struct tx_desc);
  1644. }
  1645. skb_queue_head_init(&txq->tx_skb);
  1646. return 0;
  1647. }
  1648. static void txq_deinit(struct tx_queue *txq)
  1649. {
  1650. struct mv643xx_eth_private *mp = txq_to_mp(txq);
  1651. txq_disable(txq);
  1652. txq_reclaim(txq, txq->tx_ring_size, 1);
  1653. BUG_ON(txq->tx_used_desc != txq->tx_curr_desc);
  1654. if (txq->index == 0 &&
  1655. txq->tx_desc_area_size <= mp->tx_desc_sram_size)
  1656. iounmap(txq->tx_desc_area);
  1657. else
  1658. dma_free_coherent(mp->dev->dev.parent, txq->tx_desc_area_size,
  1659. txq->tx_desc_area, txq->tx_desc_dma);
  1660. }
  1661. /* netdev ops and related ***************************************************/
  1662. static int mv643xx_eth_collect_events(struct mv643xx_eth_private *mp)
  1663. {
  1664. u32 int_cause;
  1665. u32 int_cause_ext;
  1666. int_cause = rdlp(mp, INT_CAUSE) & mp->int_mask;
  1667. if (int_cause == 0)
  1668. return 0;
  1669. int_cause_ext = 0;
  1670. if (int_cause & INT_EXT) {
  1671. int_cause &= ~INT_EXT;
  1672. int_cause_ext = rdlp(mp, INT_CAUSE_EXT);
  1673. }
  1674. if (int_cause) {
  1675. wrlp(mp, INT_CAUSE, ~int_cause);
  1676. mp->work_tx_end |= ((int_cause & INT_TX_END) >> 19) &
  1677. ~(rdlp(mp, TXQ_COMMAND) & 0xff);
  1678. mp->work_rx |= (int_cause & INT_RX) >> 2;
  1679. }
  1680. int_cause_ext &= INT_EXT_LINK_PHY | INT_EXT_TX;
  1681. if (int_cause_ext) {
  1682. wrlp(mp, INT_CAUSE_EXT, ~int_cause_ext);
  1683. if (int_cause_ext & INT_EXT_LINK_PHY)
  1684. mp->work_link = 1;
  1685. mp->work_tx |= int_cause_ext & INT_EXT_TX;
  1686. }
  1687. return 1;
  1688. }
  1689. static irqreturn_t mv643xx_eth_irq(int irq, void *dev_id)
  1690. {
  1691. struct net_device *dev = (struct net_device *)dev_id;
  1692. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1693. if (unlikely(!mv643xx_eth_collect_events(mp)))
  1694. return IRQ_NONE;
  1695. wrlp(mp, INT_MASK, 0);
  1696. napi_schedule(&mp->napi);
  1697. return IRQ_HANDLED;
  1698. }
  1699. static void handle_link_event(struct mv643xx_eth_private *mp)
  1700. {
  1701. struct net_device *dev = mp->dev;
  1702. u32 port_status;
  1703. int speed;
  1704. int duplex;
  1705. int fc;
  1706. port_status = rdlp(mp, PORT_STATUS);
  1707. if (!(port_status & LINK_UP)) {
  1708. if (netif_carrier_ok(dev)) {
  1709. int i;
  1710. netdev_info(dev, "link down\n");
  1711. netif_carrier_off(dev);
  1712. for (i = 0; i < mp->txq_count; i++) {
  1713. struct tx_queue *txq = mp->txq + i;
  1714. txq_reclaim(txq, txq->tx_ring_size, 1);
  1715. txq_reset_hw_ptr(txq);
  1716. }
  1717. }
  1718. return;
  1719. }
  1720. switch (port_status & PORT_SPEED_MASK) {
  1721. case PORT_SPEED_10:
  1722. speed = 10;
  1723. break;
  1724. case PORT_SPEED_100:
  1725. speed = 100;
  1726. break;
  1727. case PORT_SPEED_1000:
  1728. speed = 1000;
  1729. break;
  1730. default:
  1731. speed = -1;
  1732. break;
  1733. }
  1734. duplex = (port_status & FULL_DUPLEX) ? 1 : 0;
  1735. fc = (port_status & FLOW_CONTROL_ENABLED) ? 1 : 0;
  1736. netdev_info(dev, "link up, %d Mb/s, %s duplex, flow control %sabled\n",
  1737. speed, duplex ? "full" : "half", fc ? "en" : "dis");
  1738. if (!netif_carrier_ok(dev))
  1739. netif_carrier_on(dev);
  1740. }
  1741. static int mv643xx_eth_poll(struct napi_struct *napi, int budget)
  1742. {
  1743. struct mv643xx_eth_private *mp;
  1744. int work_done;
  1745. mp = container_of(napi, struct mv643xx_eth_private, napi);
  1746. if (unlikely(mp->oom)) {
  1747. mp->oom = 0;
  1748. del_timer(&mp->rx_oom);
  1749. }
  1750. work_done = 0;
  1751. while (work_done < budget) {
  1752. u8 queue_mask;
  1753. int queue;
  1754. int work_tbd;
  1755. if (mp->work_link) {
  1756. mp->work_link = 0;
  1757. handle_link_event(mp);
  1758. work_done++;
  1759. continue;
  1760. }
  1761. queue_mask = mp->work_tx | mp->work_tx_end | mp->work_rx;
  1762. if (likely(!mp->oom))
  1763. queue_mask |= mp->work_rx_refill;
  1764. if (!queue_mask) {
  1765. if (mv643xx_eth_collect_events(mp))
  1766. continue;
  1767. break;
  1768. }
  1769. queue = fls(queue_mask) - 1;
  1770. queue_mask = 1 << queue;
  1771. work_tbd = budget - work_done;
  1772. if (work_tbd > 16)
  1773. work_tbd = 16;
  1774. if (mp->work_tx_end & queue_mask) {
  1775. txq_kick(mp->txq + queue);
  1776. } else if (mp->work_tx & queue_mask) {
  1777. work_done += txq_reclaim(mp->txq + queue, work_tbd, 0);
  1778. txq_maybe_wake(mp->txq + queue);
  1779. } else if (mp->work_rx & queue_mask) {
  1780. work_done += rxq_process(mp->rxq + queue, work_tbd);
  1781. } else if (!mp->oom && (mp->work_rx_refill & queue_mask)) {
  1782. work_done += rxq_refill(mp->rxq + queue, work_tbd);
  1783. } else {
  1784. BUG();
  1785. }
  1786. }
  1787. if (work_done < budget) {
  1788. if (mp->oom)
  1789. mod_timer(&mp->rx_oom, jiffies + (HZ / 10));
  1790. napi_complete(napi);
  1791. wrlp(mp, INT_MASK, mp->int_mask);
  1792. }
  1793. return work_done;
  1794. }
  1795. static inline void oom_timer_wrapper(unsigned long data)
  1796. {
  1797. struct mv643xx_eth_private *mp = (void *)data;
  1798. napi_schedule(&mp->napi);
  1799. }
  1800. static void phy_reset(struct mv643xx_eth_private *mp)
  1801. {
  1802. int data;
  1803. data = phy_read(mp->phy, MII_BMCR);
  1804. if (data < 0)
  1805. return;
  1806. data |= BMCR_RESET;
  1807. if (phy_write(mp->phy, MII_BMCR, data) < 0)
  1808. return;
  1809. do {
  1810. data = phy_read(mp->phy, MII_BMCR);
  1811. } while (data >= 0 && data & BMCR_RESET);
  1812. }
  1813. static void port_start(struct mv643xx_eth_private *mp)
  1814. {
  1815. u32 pscr;
  1816. int i;
  1817. /*
  1818. * Perform PHY reset, if there is a PHY.
  1819. */
  1820. if (mp->phy != NULL) {
  1821. struct ethtool_cmd cmd;
  1822. mv643xx_eth_get_settings(mp->dev, &cmd);
  1823. phy_reset(mp);
  1824. mv643xx_eth_set_settings(mp->dev, &cmd);
  1825. }
  1826. /*
  1827. * Configure basic link parameters.
  1828. */
  1829. pscr = rdlp(mp, PORT_SERIAL_CONTROL);
  1830. pscr |= SERIAL_PORT_ENABLE;
  1831. wrlp(mp, PORT_SERIAL_CONTROL, pscr);
  1832. pscr |= DO_NOT_FORCE_LINK_FAIL;
  1833. if (mp->phy == NULL)
  1834. pscr |= FORCE_LINK_PASS;
  1835. wrlp(mp, PORT_SERIAL_CONTROL, pscr);
  1836. /*
  1837. * Configure TX path and queues.
  1838. */
  1839. tx_set_rate(mp, 1000000000, 16777216);
  1840. for (i = 0; i < mp->txq_count; i++) {
  1841. struct tx_queue *txq = mp->txq + i;
  1842. txq_reset_hw_ptr(txq);
  1843. txq_set_rate(txq, 1000000000, 16777216);
  1844. txq_set_fixed_prio_mode(txq);
  1845. }
  1846. /*
  1847. * Receive all unmatched unicast, TCP, UDP, BPDU and broadcast
  1848. * frames to RX queue #0, and include the pseudo-header when
  1849. * calculating receive checksums.
  1850. */
  1851. mv643xx_eth_set_features(mp->dev, mp->dev->features);
  1852. /*
  1853. * Treat BPDUs as normal multicasts, and disable partition mode.
  1854. */
  1855. wrlp(mp, PORT_CONFIG_EXT, 0x00000000);
  1856. /*
  1857. * Add configured unicast addresses to address filter table.
  1858. */
  1859. mv643xx_eth_program_unicast_filter(mp->dev);
  1860. /*
  1861. * Enable the receive queues.
  1862. */
  1863. for (i = 0; i < mp->rxq_count; i++) {
  1864. struct rx_queue *rxq = mp->rxq + i;
  1865. u32 addr;
  1866. addr = (u32)rxq->rx_desc_dma;
  1867. addr += rxq->rx_curr_desc * sizeof(struct rx_desc);
  1868. wrlp(mp, RXQ_CURRENT_DESC_PTR(i), addr);
  1869. rxq_enable(rxq);
  1870. }
  1871. }
  1872. static void mv643xx_eth_recalc_skb_size(struct mv643xx_eth_private *mp)
  1873. {
  1874. int skb_size;
  1875. /*
  1876. * Reserve 2+14 bytes for an ethernet header (the hardware
  1877. * automatically prepends 2 bytes of dummy data to each
  1878. * received packet), 16 bytes for up to four VLAN tags, and
  1879. * 4 bytes for the trailing FCS -- 36 bytes total.
  1880. */
  1881. skb_size = mp->dev->mtu + 36;
  1882. /*
  1883. * Make sure that the skb size is a multiple of 8 bytes, as
  1884. * the lower three bits of the receive descriptor's buffer
  1885. * size field are ignored by the hardware.
  1886. */
  1887. mp->skb_size = (skb_size + 7) & ~7;
  1888. /*
  1889. * If NET_SKB_PAD is smaller than a cache line,
  1890. * netdev_alloc_skb() will cause skb->data to be misaligned
  1891. * to a cache line boundary. If this is the case, include
  1892. * some extra space to allow re-aligning the data area.
  1893. */
  1894. mp->skb_size += SKB_DMA_REALIGN;
  1895. }
  1896. static int mv643xx_eth_open(struct net_device *dev)
  1897. {
  1898. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1899. int err;
  1900. int i;
  1901. wrlp(mp, INT_CAUSE, 0);
  1902. wrlp(mp, INT_CAUSE_EXT, 0);
  1903. rdlp(mp, INT_CAUSE_EXT);
  1904. err = request_irq(dev->irq, mv643xx_eth_irq,
  1905. IRQF_SHARED, dev->name, dev);
  1906. if (err) {
  1907. netdev_err(dev, "can't assign irq\n");
  1908. return -EAGAIN;
  1909. }
  1910. mv643xx_eth_recalc_skb_size(mp);
  1911. napi_enable(&mp->napi);
  1912. skb_queue_head_init(&mp->rx_recycle);
  1913. mp->int_mask = INT_EXT;
  1914. for (i = 0; i < mp->rxq_count; i++) {
  1915. err = rxq_init(mp, i);
  1916. if (err) {
  1917. while (--i >= 0)
  1918. rxq_deinit(mp->rxq + i);
  1919. goto out;
  1920. }
  1921. rxq_refill(mp->rxq + i, INT_MAX);
  1922. mp->int_mask |= INT_RX_0 << i;
  1923. }
  1924. if (mp->oom) {
  1925. mp->rx_oom.expires = jiffies + (HZ / 10);
  1926. add_timer(&mp->rx_oom);
  1927. }
  1928. for (i = 0; i < mp->txq_count; i++) {
  1929. err = txq_init(mp, i);
  1930. if (err) {
  1931. while (--i >= 0)
  1932. txq_deinit(mp->txq + i);
  1933. goto out_free;
  1934. }
  1935. mp->int_mask |= INT_TX_END_0 << i;
  1936. }
  1937. port_start(mp);
  1938. wrlp(mp, INT_MASK_EXT, INT_EXT_LINK_PHY | INT_EXT_TX);
  1939. wrlp(mp, INT_MASK, mp->int_mask);
  1940. return 0;
  1941. out_free:
  1942. for (i = 0; i < mp->rxq_count; i++)
  1943. rxq_deinit(mp->rxq + i);
  1944. out:
  1945. free_irq(dev->irq, dev);
  1946. return err;
  1947. }
  1948. static void port_reset(struct mv643xx_eth_private *mp)
  1949. {
  1950. unsigned int data;
  1951. int i;
  1952. for (i = 0; i < mp->rxq_count; i++)
  1953. rxq_disable(mp->rxq + i);
  1954. for (i = 0; i < mp->txq_count; i++)
  1955. txq_disable(mp->txq + i);
  1956. while (1) {
  1957. u32 ps = rdlp(mp, PORT_STATUS);
  1958. if ((ps & (TX_IN_PROGRESS | TX_FIFO_EMPTY)) == TX_FIFO_EMPTY)
  1959. break;
  1960. udelay(10);
  1961. }
  1962. /* Reset the Enable bit in the Configuration Register */
  1963. data = rdlp(mp, PORT_SERIAL_CONTROL);
  1964. data &= ~(SERIAL_PORT_ENABLE |
  1965. DO_NOT_FORCE_LINK_FAIL |
  1966. FORCE_LINK_PASS);
  1967. wrlp(mp, PORT_SERIAL_CONTROL, data);
  1968. }
  1969. static int mv643xx_eth_stop(struct net_device *dev)
  1970. {
  1971. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1972. int i;
  1973. wrlp(mp, INT_MASK_EXT, 0x00000000);
  1974. wrlp(mp, INT_MASK, 0x00000000);
  1975. rdlp(mp, INT_MASK);
  1976. napi_disable(&mp->napi);
  1977. del_timer_sync(&mp->rx_oom);
  1978. netif_carrier_off(dev);
  1979. free_irq(dev->irq, dev);
  1980. port_reset(mp);
  1981. mv643xx_eth_get_stats(dev);
  1982. mib_counters_update(mp);
  1983. del_timer_sync(&mp->mib_counters_timer);
  1984. skb_queue_purge(&mp->rx_recycle);
  1985. for (i = 0; i < mp->rxq_count; i++)
  1986. rxq_deinit(mp->rxq + i);
  1987. for (i = 0; i < mp->txq_count; i++)
  1988. txq_deinit(mp->txq + i);
  1989. return 0;
  1990. }
  1991. static int mv643xx_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1992. {
  1993. struct mv643xx_eth_private *mp = netdev_priv(dev);
  1994. if (mp->phy != NULL)
  1995. return phy_mii_ioctl(mp->phy, ifr, cmd);
  1996. return -EOPNOTSUPP;
  1997. }
  1998. static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu)
  1999. {
  2000. struct mv643xx_eth_private *mp = netdev_priv(dev);
  2001. if (new_mtu < 64 || new_mtu > 9500)
  2002. return -EINVAL;
  2003. dev->mtu = new_mtu;
  2004. mv643xx_eth_recalc_skb_size(mp);
  2005. tx_set_rate(mp, 1000000000, 16777216);
  2006. if (!netif_running(dev))
  2007. return 0;
  2008. /*
  2009. * Stop and then re-open the interface. This will allocate RX
  2010. * skbs of the new MTU.
  2011. * There is a possible danger that the open will not succeed,
  2012. * due to memory being full.
  2013. */
  2014. mv643xx_eth_stop(dev);
  2015. if (mv643xx_eth_open(dev)) {
  2016. netdev_err(dev,
  2017. "fatal error on re-opening device after MTU change\n");
  2018. }
  2019. return 0;
  2020. }
  2021. static void tx_timeout_task(struct work_struct *ugly)
  2022. {
  2023. struct mv643xx_eth_private *mp;
  2024. mp = container_of(ugly, struct mv643xx_eth_private, tx_timeout_task);
  2025. if (netif_running(mp->dev)) {
  2026. netif_tx_stop_all_queues(mp->dev);
  2027. port_reset(mp);
  2028. port_start(mp);
  2029. netif_tx_wake_all_queues(mp->dev);
  2030. }
  2031. }
  2032. static void mv643xx_eth_tx_timeout(struct net_device *dev)
  2033. {
  2034. struct mv643xx_eth_private *mp = netdev_priv(dev);
  2035. netdev_info(dev, "tx timeout\n");
  2036. schedule_work(&mp->tx_timeout_task);
  2037. }
  2038. #ifdef CONFIG_NET_POLL_CONTROLLER
  2039. static void mv643xx_eth_netpoll(struct net_device *dev)
  2040. {
  2041. struct mv643xx_eth_private *mp = netdev_priv(dev);
  2042. wrlp(mp, INT_MASK, 0x00000000);
  2043. rdlp(mp, INT_MASK);
  2044. mv643xx_eth_irq(dev->irq, dev);
  2045. wrlp(mp, INT_MASK, mp->int_mask);
  2046. }
  2047. #endif
  2048. /* platform glue ************************************************************/
  2049. static void
  2050. mv643xx_eth_conf_mbus_windows(struct mv643xx_eth_shared_private *msp,
  2051. const struct mbus_dram_target_info *dram)
  2052. {
  2053. void __iomem *base = msp->base;
  2054. u32 win_enable;
  2055. u32 win_protect;
  2056. int i;
  2057. for (i = 0; i < 6; i++) {
  2058. writel(0, base + WINDOW_BASE(i));
  2059. writel(0, base + WINDOW_SIZE(i));
  2060. if (i < 4)
  2061. writel(0, base + WINDOW_REMAP_HIGH(i));
  2062. }
  2063. win_enable = 0x3f;
  2064. win_protect = 0;
  2065. for (i = 0; i < dram->num_cs; i++) {
  2066. const struct mbus_dram_window *cs = dram->cs + i;
  2067. writel((cs->base & 0xffff0000) |
  2068. (cs->mbus_attr << 8) |
  2069. dram->mbus_dram_target_id, base + WINDOW_BASE(i));
  2070. writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i));
  2071. win_enable &= ~(1 << i);
  2072. win_protect |= 3 << (2 * i);
  2073. }
  2074. writel(win_enable, base + WINDOW_BAR_ENABLE);
  2075. msp->win_protect = win_protect;
  2076. }
  2077. static void infer_hw_params(struct mv643xx_eth_shared_private *msp)
  2078. {
  2079. /*
  2080. * Check whether we have a 14-bit coal limit field in bits
  2081. * [21:8], or a 16-bit coal limit in bits [25,21:7] of the
  2082. * SDMA config register.
  2083. */
  2084. writel(0x02000000, msp->base + 0x0400 + SDMA_CONFIG);
  2085. if (readl(msp->base + 0x0400 + SDMA_CONFIG) & 0x02000000)
  2086. msp->extended_rx_coal_limit = 1;
  2087. else
  2088. msp->extended_rx_coal_limit = 0;
  2089. /*
  2090. * Check whether the MAC supports TX rate control, and if
  2091. * yes, whether its associated registers are in the old or
  2092. * the new place.
  2093. */
  2094. writel(1, msp->base + 0x0400 + TX_BW_MTU_MOVED);
  2095. if (readl(msp->base + 0x0400 + TX_BW_MTU_MOVED) & 1) {
  2096. msp->tx_bw_control = TX_BW_CONTROL_NEW_LAYOUT;
  2097. } else {
  2098. writel(7, msp->base + 0x0400 + TX_BW_RATE);
  2099. if (readl(msp->base + 0x0400 + TX_BW_RATE) & 7)
  2100. msp->tx_bw_control = TX_BW_CONTROL_OLD_LAYOUT;
  2101. else
  2102. msp->tx_bw_control = TX_BW_CONTROL_ABSENT;
  2103. }
  2104. }
  2105. static int mv643xx_eth_shared_probe(struct platform_device *pdev)
  2106. {
  2107. static int mv643xx_eth_version_printed;
  2108. struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data;
  2109. struct mv643xx_eth_shared_private *msp;
  2110. const struct mbus_dram_target_info *dram;
  2111. struct resource *res;
  2112. int ret;
  2113. if (!mv643xx_eth_version_printed++)
  2114. pr_notice("MV-643xx 10/100/1000 ethernet driver version %s\n",
  2115. mv643xx_eth_driver_version);
  2116. ret = -EINVAL;
  2117. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  2118. if (res == NULL)
  2119. goto out;
  2120. ret = -ENOMEM;
  2121. msp = kzalloc(sizeof(*msp), GFP_KERNEL);
  2122. if (msp == NULL)
  2123. goto out;
  2124. msp->base = ioremap(res->start, resource_size(res));
  2125. if (msp->base == NULL)
  2126. goto out_free;
  2127. /*
  2128. * Set up and register SMI bus.
  2129. */
  2130. if (pd == NULL || pd->shared_smi == NULL) {
  2131. msp->smi_bus = mdiobus_alloc();
  2132. if (msp->smi_bus == NULL)
  2133. goto out_unmap;
  2134. msp->smi_bus->priv = msp;
  2135. msp->smi_bus->name = "mv643xx_eth smi";
  2136. msp->smi_bus->read = smi_bus_read;
  2137. msp->smi_bus->write = smi_bus_write,
  2138. snprintf(msp->smi_bus->id, MII_BUS_ID_SIZE, "%s-%d",
  2139. pdev->name, pdev->id);
  2140. msp->smi_bus->parent = &pdev->dev;
  2141. msp->smi_bus->phy_mask = 0xffffffff;
  2142. if (mdiobus_register(msp->smi_bus) < 0)
  2143. goto out_free_mii_bus;
  2144. msp->smi = msp;
  2145. } else {
  2146. msp->smi = platform_get_drvdata(pd->shared_smi);
  2147. }
  2148. msp->err_interrupt = NO_IRQ;
  2149. init_waitqueue_head(&msp->smi_busy_wait);
  2150. /*
  2151. * Check whether the error interrupt is hooked up.
  2152. */
  2153. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  2154. if (res != NULL) {
  2155. int err;
  2156. err = request_irq(res->start, mv643xx_eth_err_irq,
  2157. IRQF_SHARED, "mv643xx_eth", msp);
  2158. if (!err) {
  2159. writel(ERR_INT_SMI_DONE, msp->base + ERR_INT_MASK);
  2160. msp->err_interrupt = res->start;
  2161. }
  2162. }
  2163. /*
  2164. * (Re-)program MBUS remapping windows if we are asked to.
  2165. */
  2166. dram = mv_mbus_dram_info();
  2167. if (dram)
  2168. mv643xx_eth_conf_mbus_windows(msp, dram);
  2169. /*
  2170. * Detect hardware parameters.
  2171. */
  2172. msp->t_clk = (pd != NULL && pd->t_clk != 0) ? pd->t_clk : 133000000;
  2173. msp->tx_csum_limit = (pd != NULL && pd->tx_csum_limit) ?
  2174. pd->tx_csum_limit : 9 * 1024;
  2175. infer_hw_params(msp);
  2176. platform_set_drvdata(pdev, msp);
  2177. return 0;
  2178. out_free_mii_bus:
  2179. mdiobus_free(msp->smi_bus);
  2180. out_unmap:
  2181. iounmap(msp->base);
  2182. out_free:
  2183. kfree(msp);
  2184. out:
  2185. return ret;
  2186. }
  2187. static int mv643xx_eth_shared_remove(struct platform_device *pdev)
  2188. {
  2189. struct mv643xx_eth_shared_private *msp = platform_get_drvdata(pdev);
  2190. struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data;
  2191. if (pd == NULL || pd->shared_smi == NULL) {
  2192. mdiobus_unregister(msp->smi_bus);
  2193. mdiobus_free(msp->smi_bus);
  2194. }
  2195. if (msp->err_interrupt != NO_IRQ)
  2196. free_irq(msp->err_interrupt, msp);
  2197. iounmap(msp->base);
  2198. kfree(msp);
  2199. return 0;
  2200. }
  2201. static struct platform_driver mv643xx_eth_shared_driver = {
  2202. .probe = mv643xx_eth_shared_probe,
  2203. .remove = mv643xx_eth_shared_remove,
  2204. .driver = {
  2205. .name = MV643XX_ETH_SHARED_NAME,
  2206. .owner = THIS_MODULE,
  2207. },
  2208. };
  2209. static void phy_addr_set(struct mv643xx_eth_private *mp, int phy_addr)
  2210. {
  2211. int addr_shift = 5 * mp->port_num;
  2212. u32 data;
  2213. data = rdl(mp, PHY_ADDR);
  2214. data &= ~(0x1f << addr_shift);
  2215. data |= (phy_addr & 0x1f) << addr_shift;
  2216. wrl(mp, PHY_ADDR, data);
  2217. }
  2218. static int phy_addr_get(struct mv643xx_eth_private *mp)
  2219. {
  2220. unsigned int data;
  2221. data = rdl(mp, PHY_ADDR);
  2222. return (data >> (5 * mp->port_num)) & 0x1f;
  2223. }
  2224. static void set_params(struct mv643xx_eth_private *mp,
  2225. struct mv643xx_eth_platform_data *pd)
  2226. {
  2227. struct net_device *dev = mp->dev;
  2228. if (is_valid_ether_addr(pd->mac_addr))
  2229. memcpy(dev->dev_addr, pd->mac_addr, 6);
  2230. else
  2231. uc_addr_get(mp, dev->dev_addr);
  2232. mp->rx_ring_size = DEFAULT_RX_QUEUE_SIZE;
  2233. if (pd->rx_queue_size)
  2234. mp->rx_ring_size = pd->rx_queue_size;
  2235. mp->rx_desc_sram_addr = pd->rx_sram_addr;
  2236. mp->rx_desc_sram_size = pd->rx_sram_size;
  2237. mp->rxq_count = pd->rx_queue_count ? : 1;
  2238. mp->tx_ring_size = DEFAULT_TX_QUEUE_SIZE;
  2239. if (pd->tx_queue_size)
  2240. mp->tx_ring_size = pd->tx_queue_size;
  2241. mp->tx_desc_sram_addr = pd->tx_sram_addr;
  2242. mp->tx_desc_sram_size = pd->tx_sram_size;
  2243. mp->txq_count = pd->tx_queue_count ? : 1;
  2244. }
  2245. static struct phy_device *phy_scan(struct mv643xx_eth_private *mp,
  2246. int phy_addr)
  2247. {
  2248. struct mii_bus *bus = mp->shared->smi->smi_bus;
  2249. struct phy_device *phydev;
  2250. int start;
  2251. int num;
  2252. int i;
  2253. if (phy_addr == MV643XX_ETH_PHY_ADDR_DEFAULT) {
  2254. start = phy_addr_get(mp) & 0x1f;
  2255. num = 32;
  2256. } else {
  2257. start = phy_addr & 0x1f;
  2258. num = 1;
  2259. }
  2260. phydev = NULL;
  2261. for (i = 0; i < num; i++) {
  2262. int addr = (start + i) & 0x1f;
  2263. if (bus->phy_map[addr] == NULL)
  2264. mdiobus_scan(bus, addr);
  2265. if (phydev == NULL) {
  2266. phydev = bus->phy_map[addr];
  2267. if (phydev != NULL)
  2268. phy_addr_set(mp, addr);
  2269. }
  2270. }
  2271. return phydev;
  2272. }
  2273. static void phy_init(struct mv643xx_eth_private *mp, int speed, int duplex)
  2274. {
  2275. struct phy_device *phy = mp->phy;
  2276. phy_reset(mp);
  2277. phy_attach(mp->dev, dev_name(&phy->dev), 0, PHY_INTERFACE_MODE_GMII);
  2278. if (speed == 0) {
  2279. phy->autoneg = AUTONEG_ENABLE;
  2280. phy->speed = 0;
  2281. phy->duplex = 0;
  2282. phy->advertising = phy->supported | ADVERTISED_Autoneg;
  2283. } else {
  2284. phy->autoneg = AUTONEG_DISABLE;
  2285. phy->advertising = 0;
  2286. phy->speed = speed;
  2287. phy->duplex = duplex;
  2288. }
  2289. phy_start_aneg(phy);
  2290. }
  2291. static void init_pscr(struct mv643xx_eth_private *mp, int speed, int duplex)
  2292. {
  2293. u32 pscr;
  2294. pscr = rdlp(mp, PORT_SERIAL_CONTROL);
  2295. if (pscr & SERIAL_PORT_ENABLE) {
  2296. pscr &= ~SERIAL_PORT_ENABLE;
  2297. wrlp(mp, PORT_SERIAL_CONTROL, pscr);
  2298. }
  2299. pscr = MAX_RX_PACKET_9700BYTE | SERIAL_PORT_CONTROL_RESERVED;
  2300. if (mp->phy == NULL) {
  2301. pscr |= DISABLE_AUTO_NEG_SPEED_GMII;
  2302. if (speed == SPEED_1000)
  2303. pscr |= SET_GMII_SPEED_TO_1000;
  2304. else if (speed == SPEED_100)
  2305. pscr |= SET_MII_SPEED_TO_100;
  2306. pscr |= DISABLE_AUTO_NEG_FOR_FLOW_CTRL;
  2307. pscr |= DISABLE_AUTO_NEG_FOR_DUPLEX;
  2308. if (duplex == DUPLEX_FULL)
  2309. pscr |= SET_FULL_DUPLEX_MODE;
  2310. }
  2311. wrlp(mp, PORT_SERIAL_CONTROL, pscr);
  2312. }
  2313. static const struct net_device_ops mv643xx_eth_netdev_ops = {
  2314. .ndo_open = mv643xx_eth_open,
  2315. .ndo_stop = mv643xx_eth_stop,
  2316. .ndo_start_xmit = mv643xx_eth_xmit,
  2317. .ndo_set_rx_mode = mv643xx_eth_set_rx_mode,
  2318. .ndo_set_mac_address = mv643xx_eth_set_mac_address,
  2319. .ndo_validate_addr = eth_validate_addr,
  2320. .ndo_do_ioctl = mv643xx_eth_ioctl,
  2321. .ndo_change_mtu = mv643xx_eth_change_mtu,
  2322. .ndo_set_features = mv643xx_eth_set_features,
  2323. .ndo_tx_timeout = mv643xx_eth_tx_timeout,
  2324. .ndo_get_stats = mv643xx_eth_get_stats,
  2325. #ifdef CONFIG_NET_POLL_CONTROLLER
  2326. .ndo_poll_controller = mv643xx_eth_netpoll,
  2327. #endif
  2328. };
  2329. static int mv643xx_eth_probe(struct platform_device *pdev)
  2330. {
  2331. struct mv643xx_eth_platform_data *pd;
  2332. struct mv643xx_eth_private *mp;
  2333. struct net_device *dev;
  2334. struct resource *res;
  2335. int err;
  2336. pd = pdev->dev.platform_data;
  2337. if (pd == NULL) {
  2338. dev_err(&pdev->dev, "no mv643xx_eth_platform_data\n");
  2339. return -ENODEV;
  2340. }
  2341. if (pd->shared == NULL) {
  2342. dev_err(&pdev->dev, "no mv643xx_eth_platform_data->shared\n");
  2343. return -ENODEV;
  2344. }
  2345. dev = alloc_etherdev_mq(sizeof(struct mv643xx_eth_private), 8);
  2346. if (!dev)
  2347. return -ENOMEM;
  2348. mp = netdev_priv(dev);
  2349. platform_set_drvdata(pdev, mp);
  2350. mp->shared = platform_get_drvdata(pd->shared);
  2351. mp->base = mp->shared->base + 0x0400 + (pd->port_number << 10);
  2352. mp->port_num = pd->port_number;
  2353. mp->dev = dev;
  2354. set_params(mp, pd);
  2355. netif_set_real_num_tx_queues(dev, mp->txq_count);
  2356. netif_set_real_num_rx_queues(dev, mp->rxq_count);
  2357. if (pd->phy_addr != MV643XX_ETH_PHY_NONE)
  2358. mp->phy = phy_scan(mp, pd->phy_addr);
  2359. if (mp->phy != NULL)
  2360. phy_init(mp, pd->speed, pd->duplex);
  2361. SET_ETHTOOL_OPS(dev, &mv643xx_eth_ethtool_ops);
  2362. init_pscr(mp, pd->speed, pd->duplex);
  2363. mib_counters_clear(mp);
  2364. init_timer(&mp->mib_counters_timer);
  2365. mp->mib_counters_timer.data = (unsigned long)mp;
  2366. mp->mib_counters_timer.function = mib_counters_timer_wrapper;
  2367. mp->mib_counters_timer.expires = jiffies + 30 * HZ;
  2368. add_timer(&mp->mib_counters_timer);
  2369. spin_lock_init(&mp->mib_counters_lock);
  2370. INIT_WORK(&mp->tx_timeout_task, tx_timeout_task);
  2371. netif_napi_add(dev, &mp->napi, mv643xx_eth_poll, 128);
  2372. init_timer(&mp->rx_oom);
  2373. mp->rx_oom.data = (unsigned long)mp;
  2374. mp->rx_oom.function = oom_timer_wrapper;
  2375. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  2376. BUG_ON(!res);
  2377. dev->irq = res->start;
  2378. dev->netdev_ops = &mv643xx_eth_netdev_ops;
  2379. dev->watchdog_timeo = 2 * HZ;
  2380. dev->base_addr = 0;
  2381. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
  2382. NETIF_F_RXCSUM | NETIF_F_LRO;
  2383. dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
  2384. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM;
  2385. dev->priv_flags |= IFF_UNICAST_FLT;
  2386. SET_NETDEV_DEV(dev, &pdev->dev);
  2387. if (mp->shared->win_protect)
  2388. wrl(mp, WINDOW_PROTECT(mp->port_num), mp->shared->win_protect);
  2389. netif_carrier_off(dev);
  2390. wrlp(mp, SDMA_CONFIG, PORT_SDMA_CONFIG_DEFAULT_VALUE);
  2391. set_rx_coal(mp, 250);
  2392. set_tx_coal(mp, 0);
  2393. err = register_netdev(dev);
  2394. if (err)
  2395. goto out;
  2396. netdev_notice(dev, "port %d with MAC address %pM\n",
  2397. mp->port_num, dev->dev_addr);
  2398. if (mp->tx_desc_sram_size > 0)
  2399. netdev_notice(dev, "configured with sram\n");
  2400. return 0;
  2401. out:
  2402. free_netdev(dev);
  2403. return err;
  2404. }
  2405. static int mv643xx_eth_remove(struct platform_device *pdev)
  2406. {
  2407. struct mv643xx_eth_private *mp = platform_get_drvdata(pdev);
  2408. unregister_netdev(mp->dev);
  2409. if (mp->phy != NULL)
  2410. phy_detach(mp->phy);
  2411. cancel_work_sync(&mp->tx_timeout_task);
  2412. free_netdev(mp->dev);
  2413. platform_set_drvdata(pdev, NULL);
  2414. return 0;
  2415. }
  2416. static void mv643xx_eth_shutdown(struct platform_device *pdev)
  2417. {
  2418. struct mv643xx_eth_private *mp = platform_get_drvdata(pdev);
  2419. /* Mask all interrupts on ethernet port */
  2420. wrlp(mp, INT_MASK, 0);
  2421. rdlp(mp, INT_MASK);
  2422. if (netif_running(mp->dev))
  2423. port_reset(mp);
  2424. }
  2425. static struct platform_driver mv643xx_eth_driver = {
  2426. .probe = mv643xx_eth_probe,
  2427. .remove = mv643xx_eth_remove,
  2428. .shutdown = mv643xx_eth_shutdown,
  2429. .driver = {
  2430. .name = MV643XX_ETH_NAME,
  2431. .owner = THIS_MODULE,
  2432. },
  2433. };
  2434. static int __init mv643xx_eth_init_module(void)
  2435. {
  2436. int rc;
  2437. rc = platform_driver_register(&mv643xx_eth_shared_driver);
  2438. if (!rc) {
  2439. rc = platform_driver_register(&mv643xx_eth_driver);
  2440. if (rc)
  2441. platform_driver_unregister(&mv643xx_eth_shared_driver);
  2442. }
  2443. return rc;
  2444. }
  2445. module_init(mv643xx_eth_init_module);
  2446. static void __exit mv643xx_eth_cleanup_module(void)
  2447. {
  2448. platform_driver_unregister(&mv643xx_eth_driver);
  2449. platform_driver_unregister(&mv643xx_eth_shared_driver);
  2450. }
  2451. module_exit(mv643xx_eth_cleanup_module);
  2452. MODULE_AUTHOR("Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, "
  2453. "Manish Lachwani, Dale Farnsworth and Lennert Buytenhek");
  2454. MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
  2455. MODULE_LICENSE("GPL");
  2456. MODULE_ALIAS("platform:" MV643XX_ETH_SHARED_NAME);
  2457. MODULE_ALIAS("platform:" MV643XX_ETH_NAME);