mv643xx_eth.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236
  1. /*
  2. * drivers/net/mv643xx_eth.c - Driver for MV643XX ethernet ports
  3. * Copyright (C) 2002 Matthew Dharm <mdharm@momenco.com>
  4. *
  5. * Based on the 64360 driver from:
  6. * Copyright (C) 2002 rabeeh@galileo.co.il
  7. *
  8. * Copyright (C) 2003 PMC-Sierra, Inc.,
  9. * written by Manish Lachwani
  10. *
  11. * Copyright (C) 2003 Ralf Baechle <ralf@linux-mips.org>
  12. *
  13. * Copyright (C) 2004-2005 MontaVista Software, Inc.
  14. * Dale Farnsworth <dale@farnsworth.org>
  15. *
  16. * Copyright (C) 2004 Steven J. Hill <sjhill1@rockwellcollins.com>
  17. * <sjhill@realitydiluted.com>
  18. *
  19. * This program is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU General Public License
  21. * as published by the Free Software Foundation; either version 2
  22. * of the License, or (at your option) any later version.
  23. *
  24. * This program is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. * GNU General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU General Public License
  30. * along with this program; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32. */
  33. #include <linux/init.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/tcp.h>
  36. #include <linux/udp.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/in.h>
  39. #include <linux/ip.h>
  40. #include <linux/bitops.h>
  41. #include <linux/delay.h>
  42. #include <linux/ethtool.h>
  43. #include <linux/platform_device.h>
  44. #include <asm/io.h>
  45. #include <asm/types.h>
  46. #include <asm/pgtable.h>
  47. #include <asm/system.h>
  48. #include <asm/delay.h>
  49. #include "mv643xx_eth.h"
  50. /*
  51. * The first part is the high level driver of the gigE ethernet ports.
  52. */
  53. /* Constants */
  54. #define VLAN_HLEN 4
  55. #define FCS_LEN 4
  56. #define DMA_ALIGN 8 /* hw requires 8-byte alignment */
  57. #define HW_IP_ALIGN 2 /* hw aligns IP header */
  58. #define WRAP HW_IP_ALIGN + ETH_HLEN + VLAN_HLEN + FCS_LEN
  59. #define RX_SKB_SIZE ((dev->mtu + WRAP + 7) & ~0x7)
  60. #define INT_CAUSE_UNMASK_ALL 0x0007ffff
  61. #define INT_CAUSE_UNMASK_ALL_EXT 0x0011ffff
  62. #define INT_CAUSE_MASK_ALL 0x00000000
  63. #define INT_CAUSE_MASK_ALL_EXT 0x00000000
  64. #define INT_CAUSE_CHECK_BITS INT_CAUSE_UNMASK_ALL
  65. #define INT_CAUSE_CHECK_BITS_EXT INT_CAUSE_UNMASK_ALL_EXT
  66. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  67. #define MAX_DESCS_PER_SKB (MAX_SKB_FRAGS + 1)
  68. #else
  69. #define MAX_DESCS_PER_SKB 1
  70. #endif
  71. #define PHY_WAIT_ITERATIONS 1000 /* 1000 iterations * 10uS = 10mS max */
  72. #define PHY_WAIT_MICRO_SECONDS 10
  73. /* Static function declarations */
  74. static int eth_port_link_is_up(unsigned int eth_port_num);
  75. static void eth_port_uc_addr_get(struct net_device *dev,
  76. unsigned char *MacAddr);
  77. static void eth_port_set_multicast_list(struct net_device *);
  78. static int mv643xx_eth_real_open(struct net_device *);
  79. static int mv643xx_eth_real_stop(struct net_device *);
  80. static int mv643xx_eth_change_mtu(struct net_device *, int);
  81. static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *);
  82. static void eth_port_init_mac_tables(unsigned int eth_port_num);
  83. #ifdef MV643XX_NAPI
  84. static int mv643xx_poll(struct net_device *dev, int *budget);
  85. #endif
  86. static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr);
  87. static int ethernet_phy_detect(unsigned int eth_port_num);
  88. static struct ethtool_ops mv643xx_ethtool_ops;
  89. static char mv643xx_driver_name[] = "mv643xx_eth";
  90. static char mv643xx_driver_version[] = "1.0";
  91. static void __iomem *mv643xx_eth_shared_base;
  92. /* used to protect MV643XX_ETH_SMI_REG, which is shared across ports */
  93. static DEFINE_SPINLOCK(mv643xx_eth_phy_lock);
  94. static inline u32 mv_read(int offset)
  95. {
  96. void __iomem *reg_base;
  97. reg_base = mv643xx_eth_shared_base - MV643XX_ETH_SHARED_REGS;
  98. return readl(reg_base + offset);
  99. }
  100. static inline void mv_write(int offset, u32 data)
  101. {
  102. void __iomem *reg_base;
  103. reg_base = mv643xx_eth_shared_base - MV643XX_ETH_SHARED_REGS;
  104. writel(data, reg_base + offset);
  105. }
  106. /*
  107. * Changes MTU (maximum transfer unit) of the gigabit ethenret port
  108. *
  109. * Input : pointer to ethernet interface network device structure
  110. * new mtu size
  111. * Output : 0 upon success, -EINVAL upon failure
  112. */
  113. static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu)
  114. {
  115. if ((new_mtu > 9500) || (new_mtu < 64))
  116. return -EINVAL;
  117. dev->mtu = new_mtu;
  118. /*
  119. * Stop then re-open the interface. This will allocate RX skb's with
  120. * the new MTU.
  121. * There is a possible danger that the open will not successed, due
  122. * to memory is full, which might fail the open function.
  123. */
  124. if (netif_running(dev)) {
  125. if (mv643xx_eth_real_stop(dev))
  126. printk(KERN_ERR
  127. "%s: Fatal error on stopping device\n",
  128. dev->name);
  129. if (mv643xx_eth_real_open(dev))
  130. printk(KERN_ERR
  131. "%s: Fatal error on opening device\n",
  132. dev->name);
  133. }
  134. return 0;
  135. }
  136. /*
  137. * mv643xx_eth_rx_task
  138. *
  139. * Fills / refills RX queue on a certain gigabit ethernet port
  140. *
  141. * Input : pointer to ethernet interface network device structure
  142. * Output : N/A
  143. */
  144. static void mv643xx_eth_rx_task(void *data)
  145. {
  146. struct net_device *dev = (struct net_device *)data;
  147. struct mv643xx_private *mp = netdev_priv(dev);
  148. struct pkt_info pkt_info;
  149. struct sk_buff *skb;
  150. int unaligned;
  151. if (test_and_set_bit(0, &mp->rx_task_busy))
  152. panic("%s: Error in test_set_bit / clear_bit", dev->name);
  153. while (mp->rx_ring_skbs < (mp->rx_ring_size - 5)) {
  154. skb = dev_alloc_skb(RX_SKB_SIZE + DMA_ALIGN);
  155. if (!skb)
  156. break;
  157. mp->rx_ring_skbs++;
  158. unaligned = (u32)skb->data & (DMA_ALIGN - 1);
  159. if (unaligned)
  160. skb_reserve(skb, DMA_ALIGN - unaligned);
  161. pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT;
  162. pkt_info.byte_cnt = RX_SKB_SIZE;
  163. pkt_info.buf_ptr = dma_map_single(NULL, skb->data, RX_SKB_SIZE,
  164. DMA_FROM_DEVICE);
  165. pkt_info.return_info = skb;
  166. if (eth_rx_return_buff(mp, &pkt_info) != ETH_OK) {
  167. printk(KERN_ERR
  168. "%s: Error allocating RX Ring\n", dev->name);
  169. break;
  170. }
  171. skb_reserve(skb, HW_IP_ALIGN);
  172. }
  173. clear_bit(0, &mp->rx_task_busy);
  174. /*
  175. * If RX ring is empty of SKB, set a timer to try allocating
  176. * again in a later time .
  177. */
  178. if ((mp->rx_ring_skbs == 0) && (mp->rx_timer_flag == 0)) {
  179. printk(KERN_INFO "%s: Rx ring is empty\n", dev->name);
  180. /* After 100mSec */
  181. mp->timeout.expires = jiffies + (HZ / 10);
  182. add_timer(&mp->timeout);
  183. mp->rx_timer_flag = 1;
  184. }
  185. #ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
  186. else {
  187. /* Return interrupts */
  188. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(mp->port_num),
  189. INT_CAUSE_UNMASK_ALL);
  190. }
  191. #endif
  192. }
  193. /*
  194. * mv643xx_eth_rx_task_timer_wrapper
  195. *
  196. * Timer routine to wake up RX queue filling task. This function is
  197. * used only in case the RX queue is empty, and all alloc_skb has
  198. * failed (due to out of memory event).
  199. *
  200. * Input : pointer to ethernet interface network device structure
  201. * Output : N/A
  202. */
  203. static void mv643xx_eth_rx_task_timer_wrapper(unsigned long data)
  204. {
  205. struct net_device *dev = (struct net_device *)data;
  206. struct mv643xx_private *mp = netdev_priv(dev);
  207. mp->rx_timer_flag = 0;
  208. mv643xx_eth_rx_task((void *)data);
  209. }
  210. /*
  211. * mv643xx_eth_update_mac_address
  212. *
  213. * Update the MAC address of the port in the address table
  214. *
  215. * Input : pointer to ethernet interface network device structure
  216. * Output : N/A
  217. */
  218. static void mv643xx_eth_update_mac_address(struct net_device *dev)
  219. {
  220. struct mv643xx_private *mp = netdev_priv(dev);
  221. unsigned int port_num = mp->port_num;
  222. eth_port_init_mac_tables(port_num);
  223. memcpy(mp->port_mac_addr, dev->dev_addr, 6);
  224. eth_port_uc_addr_set(port_num, mp->port_mac_addr);
  225. }
  226. /*
  227. * mv643xx_eth_set_rx_mode
  228. *
  229. * Change from promiscuos to regular rx mode
  230. *
  231. * Input : pointer to ethernet interface network device structure
  232. * Output : N/A
  233. */
  234. static void mv643xx_eth_set_rx_mode(struct net_device *dev)
  235. {
  236. struct mv643xx_private *mp = netdev_priv(dev);
  237. if (dev->flags & IFF_PROMISC)
  238. mp->port_config |= (u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE;
  239. else
  240. mp->port_config &= ~(u32) MV643XX_ETH_UNICAST_PROMISCUOUS_MODE;
  241. mv_write(MV643XX_ETH_PORT_CONFIG_REG(mp->port_num), mp->port_config);
  242. eth_port_set_multicast_list(dev);
  243. }
  244. /*
  245. * mv643xx_eth_set_mac_address
  246. *
  247. * Change the interface's mac address.
  248. * No special hardware thing should be done because interface is always
  249. * put in promiscuous mode.
  250. *
  251. * Input : pointer to ethernet interface network device structure and
  252. * a pointer to the designated entry to be added to the cache.
  253. * Output : zero upon success, negative upon failure
  254. */
  255. static int mv643xx_eth_set_mac_address(struct net_device *dev, void *addr)
  256. {
  257. int i;
  258. for (i = 0; i < 6; i++)
  259. /* +2 is for the offset of the HW addr type */
  260. dev->dev_addr[i] = ((unsigned char *)addr)[i + 2];
  261. mv643xx_eth_update_mac_address(dev);
  262. return 0;
  263. }
  264. /*
  265. * mv643xx_eth_tx_timeout
  266. *
  267. * Called upon a timeout on transmitting a packet
  268. *
  269. * Input : pointer to ethernet interface network device structure.
  270. * Output : N/A
  271. */
  272. static void mv643xx_eth_tx_timeout(struct net_device *dev)
  273. {
  274. struct mv643xx_private *mp = netdev_priv(dev);
  275. printk(KERN_INFO "%s: TX timeout ", dev->name);
  276. /* Do the reset outside of interrupt context */
  277. schedule_work(&mp->tx_timeout_task);
  278. }
  279. /*
  280. * mv643xx_eth_tx_timeout_task
  281. *
  282. * Actual routine to reset the adapter when a timeout on Tx has occurred
  283. */
  284. static void mv643xx_eth_tx_timeout_task(struct net_device *dev)
  285. {
  286. struct mv643xx_private *mp = netdev_priv(dev);
  287. netif_device_detach(dev);
  288. eth_port_reset(mp->port_num);
  289. eth_port_start(mp);
  290. netif_device_attach(dev);
  291. }
  292. /*
  293. * mv643xx_eth_free_tx_queue
  294. *
  295. * Input : dev - a pointer to the required interface
  296. *
  297. * Output : 0 if was able to release skb , nonzero otherwise
  298. */
  299. static int mv643xx_eth_free_tx_queue(struct net_device *dev,
  300. unsigned int eth_int_cause_ext)
  301. {
  302. struct mv643xx_private *mp = netdev_priv(dev);
  303. struct net_device_stats *stats = &mp->stats;
  304. struct pkt_info pkt_info;
  305. int released = 1;
  306. if (!(eth_int_cause_ext & (BIT0 | BIT8)))
  307. return released;
  308. /* Check only queue 0 */
  309. while (eth_tx_return_desc(mp, &pkt_info) == ETH_OK) {
  310. if (pkt_info.cmd_sts & BIT0) {
  311. printk("%s: Error in TX\n", dev->name);
  312. stats->tx_errors++;
  313. }
  314. if (pkt_info.cmd_sts & ETH_TX_FIRST_DESC)
  315. dma_unmap_single(NULL, pkt_info.buf_ptr,
  316. pkt_info.byte_cnt,
  317. DMA_TO_DEVICE);
  318. else
  319. dma_unmap_page(NULL, pkt_info.buf_ptr,
  320. pkt_info.byte_cnt,
  321. DMA_TO_DEVICE);
  322. if (pkt_info.return_info) {
  323. dev_kfree_skb_irq(pkt_info.return_info);
  324. released = 0;
  325. }
  326. }
  327. return released;
  328. }
  329. /*
  330. * mv643xx_eth_receive
  331. *
  332. * This function is forward packets that are received from the port's
  333. * queues toward kernel core or FastRoute them to another interface.
  334. *
  335. * Input : dev - a pointer to the required interface
  336. * max - maximum number to receive (0 means unlimted)
  337. *
  338. * Output : number of served packets
  339. */
  340. #ifdef MV643XX_NAPI
  341. static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
  342. #else
  343. static int mv643xx_eth_receive_queue(struct net_device *dev)
  344. #endif
  345. {
  346. struct mv643xx_private *mp = netdev_priv(dev);
  347. struct net_device_stats *stats = &mp->stats;
  348. unsigned int received_packets = 0;
  349. struct sk_buff *skb;
  350. struct pkt_info pkt_info;
  351. #ifdef MV643XX_NAPI
  352. while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) {
  353. #else
  354. while (eth_port_receive(mp, &pkt_info) == ETH_OK) {
  355. #endif
  356. mp->rx_ring_skbs--;
  357. received_packets++;
  358. /* Update statistics. Note byte count includes 4 byte CRC count */
  359. stats->rx_packets++;
  360. stats->rx_bytes += pkt_info.byte_cnt;
  361. skb = pkt_info.return_info;
  362. /*
  363. * In case received a packet without first / last bits on OR
  364. * the error summary bit is on, the packets needs to be dropeed.
  365. */
  366. if (((pkt_info.cmd_sts
  367. & (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) !=
  368. (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC))
  369. || (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)) {
  370. stats->rx_dropped++;
  371. if ((pkt_info.cmd_sts & (ETH_RX_FIRST_DESC |
  372. ETH_RX_LAST_DESC)) !=
  373. (ETH_RX_FIRST_DESC | ETH_RX_LAST_DESC)) {
  374. if (net_ratelimit())
  375. printk(KERN_ERR
  376. "%s: Received packet spread "
  377. "on multiple descriptors\n",
  378. dev->name);
  379. }
  380. if (pkt_info.cmd_sts & ETH_ERROR_SUMMARY)
  381. stats->rx_errors++;
  382. dev_kfree_skb_irq(skb);
  383. } else {
  384. /*
  385. * The -4 is for the CRC in the trailer of the
  386. * received packet
  387. */
  388. skb_put(skb, pkt_info.byte_cnt - 4);
  389. skb->dev = dev;
  390. if (pkt_info.cmd_sts & ETH_LAYER_4_CHECKSUM_OK) {
  391. skb->ip_summed = CHECKSUM_UNNECESSARY;
  392. skb->csum = htons(
  393. (pkt_info.cmd_sts & 0x0007fff8) >> 3);
  394. }
  395. skb->protocol = eth_type_trans(skb, dev);
  396. #ifdef MV643XX_NAPI
  397. netif_receive_skb(skb);
  398. #else
  399. netif_rx(skb);
  400. #endif
  401. }
  402. }
  403. return received_packets;
  404. }
  405. /*
  406. * mv643xx_eth_int_handler
  407. *
  408. * Main interrupt handler for the gigbit ethernet ports
  409. *
  410. * Input : irq - irq number (not used)
  411. * dev_id - a pointer to the required interface's data structure
  412. * regs - not used
  413. * Output : N/A
  414. */
  415. static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id,
  416. struct pt_regs *regs)
  417. {
  418. struct net_device *dev = (struct net_device *)dev_id;
  419. struct mv643xx_private *mp = netdev_priv(dev);
  420. u32 eth_int_cause, eth_int_cause_ext = 0;
  421. unsigned int port_num = mp->port_num;
  422. /* Read interrupt cause registers */
  423. eth_int_cause = mv_read(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num)) &
  424. INT_CAUSE_UNMASK_ALL;
  425. if (eth_int_cause & BIT1)
  426. eth_int_cause_ext = mv_read(
  427. MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num)) &
  428. INT_CAUSE_UNMASK_ALL_EXT;
  429. #ifdef MV643XX_NAPI
  430. if (!(eth_int_cause & 0x0007fffd)) {
  431. /* Dont ack the Rx interrupt */
  432. #endif
  433. /*
  434. * Clear specific ethernet port intrerrupt registers by
  435. * acknowleding relevant bits.
  436. */
  437. mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num),
  438. ~eth_int_cause);
  439. if (eth_int_cause_ext != 0x0)
  440. mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG
  441. (port_num), ~eth_int_cause_ext);
  442. /* UDP change : We may need this */
  443. if ((eth_int_cause_ext & 0x0000ffff) &&
  444. (mv643xx_eth_free_tx_queue(dev, eth_int_cause_ext) == 0) &&
  445. (mp->tx_ring_size > mp->tx_ring_skbs + MAX_DESCS_PER_SKB))
  446. netif_wake_queue(dev);
  447. #ifdef MV643XX_NAPI
  448. } else {
  449. if (netif_rx_schedule_prep(dev)) {
  450. /* Mask all the interrupts */
  451. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num), 0);
  452. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG
  453. (port_num), 0);
  454. /* ensure previous writes have taken effect */
  455. mv_read(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num));
  456. __netif_rx_schedule(dev);
  457. }
  458. #else
  459. if (eth_int_cause & (BIT2 | BIT11))
  460. mv643xx_eth_receive_queue(dev, 0);
  461. /*
  462. * After forwarded received packets to upper layer, add a task
  463. * in an interrupts enabled context that refills the RX ring
  464. * with skb's.
  465. */
  466. #ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
  467. /* Unmask all interrupts on ethernet port */
  468. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  469. INT_CAUSE_MASK_ALL);
  470. /* wait for previous write to take effect */
  471. mv_read(MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
  472. queue_task(&mp->rx_task, &tq_immediate);
  473. mark_bh(IMMEDIATE_BH);
  474. #else
  475. mp->rx_task.func(dev);
  476. #endif
  477. #endif
  478. }
  479. /* PHY status changed */
  480. if (eth_int_cause_ext & (BIT16 | BIT20)) {
  481. if (eth_port_link_is_up(port_num)) {
  482. netif_carrier_on(dev);
  483. netif_wake_queue(dev);
  484. /* Start TX queue */
  485. mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG
  486. (port_num), 1);
  487. } else {
  488. netif_carrier_off(dev);
  489. netif_stop_queue(dev);
  490. }
  491. }
  492. /*
  493. * If no real interrupt occured, exit.
  494. * This can happen when using gigE interrupt coalescing mechanism.
  495. */
  496. if ((eth_int_cause == 0x0) && (eth_int_cause_ext == 0x0))
  497. return IRQ_NONE;
  498. return IRQ_HANDLED;
  499. }
  500. #ifdef MV643XX_COAL
  501. /*
  502. * eth_port_set_rx_coal - Sets coalescing interrupt mechanism on RX path
  503. *
  504. * DESCRIPTION:
  505. * This routine sets the RX coalescing interrupt mechanism parameter.
  506. * This parameter is a timeout counter, that counts in 64 t_clk
  507. * chunks ; that when timeout event occurs a maskable interrupt
  508. * occurs.
  509. * The parameter is calculated using the tClk of the MV-643xx chip
  510. * , and the required delay of the interrupt in usec.
  511. *
  512. * INPUT:
  513. * unsigned int eth_port_num Ethernet port number
  514. * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
  515. * unsigned int delay Delay in usec
  516. *
  517. * OUTPUT:
  518. * Interrupt coalescing mechanism value is set in MV-643xx chip.
  519. *
  520. * RETURN:
  521. * The interrupt coalescing value set in the gigE port.
  522. *
  523. */
  524. static unsigned int eth_port_set_rx_coal(unsigned int eth_port_num,
  525. unsigned int t_clk, unsigned int delay)
  526. {
  527. unsigned int coal = ((t_clk / 1000000) * delay) / 64;
  528. /* Set RX Coalescing mechanism */
  529. mv_write(MV643XX_ETH_SDMA_CONFIG_REG(eth_port_num),
  530. ((coal & 0x3fff) << 8) |
  531. (mv_read(MV643XX_ETH_SDMA_CONFIG_REG(eth_port_num))
  532. & 0xffc000ff));
  533. return coal;
  534. }
  535. #endif
  536. /*
  537. * eth_port_set_tx_coal - Sets coalescing interrupt mechanism on TX path
  538. *
  539. * DESCRIPTION:
  540. * This routine sets the TX coalescing interrupt mechanism parameter.
  541. * This parameter is a timeout counter, that counts in 64 t_clk
  542. * chunks ; that when timeout event occurs a maskable interrupt
  543. * occurs.
  544. * The parameter is calculated using the t_cLK frequency of the
  545. * MV-643xx chip and the required delay in the interrupt in uSec
  546. *
  547. * INPUT:
  548. * unsigned int eth_port_num Ethernet port number
  549. * unsigned int t_clk t_clk of the MV-643xx chip in HZ units
  550. * unsigned int delay Delay in uSeconds
  551. *
  552. * OUTPUT:
  553. * Interrupt coalescing mechanism value is set in MV-643xx chip.
  554. *
  555. * RETURN:
  556. * The interrupt coalescing value set in the gigE port.
  557. *
  558. */
  559. static unsigned int eth_port_set_tx_coal(unsigned int eth_port_num,
  560. unsigned int t_clk, unsigned int delay)
  561. {
  562. unsigned int coal;
  563. coal = ((t_clk / 1000000) * delay) / 64;
  564. /* Set TX Coalescing mechanism */
  565. mv_write(MV643XX_ETH_TX_FIFO_URGENT_THRESHOLD_REG(eth_port_num),
  566. coal << 4);
  567. return coal;
  568. }
  569. /*
  570. * mv643xx_eth_open
  571. *
  572. * This function is called when openning the network device. The function
  573. * should initialize all the hardware, initialize cyclic Rx/Tx
  574. * descriptors chain and buffers and allocate an IRQ to the network
  575. * device.
  576. *
  577. * Input : a pointer to the network device structure
  578. *
  579. * Output : zero of success , nonzero if fails.
  580. */
  581. static int mv643xx_eth_open(struct net_device *dev)
  582. {
  583. struct mv643xx_private *mp = netdev_priv(dev);
  584. unsigned int port_num = mp->port_num;
  585. int err;
  586. err = request_irq(dev->irq, mv643xx_eth_int_handler,
  587. SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
  588. if (err) {
  589. printk(KERN_ERR "Can not assign IRQ number to MV643XX_eth%d\n",
  590. port_num);
  591. return -EAGAIN;
  592. }
  593. if (mv643xx_eth_real_open(dev)) {
  594. printk("%s: Error opening interface\n", dev->name);
  595. free_irq(dev->irq, dev);
  596. err = -EBUSY;
  597. }
  598. return err;
  599. }
  600. /*
  601. * ether_init_rx_desc_ring - Curve a Rx chain desc list and buffer in memory.
  602. *
  603. * DESCRIPTION:
  604. * This function prepares a Rx chained list of descriptors and packet
  605. * buffers in a form of a ring. The routine must be called after port
  606. * initialization routine and before port start routine.
  607. * The Ethernet SDMA engine uses CPU bus addresses to access the various
  608. * devices in the system (i.e. DRAM). This function uses the ethernet
  609. * struct 'virtual to physical' routine (set by the user) to set the ring
  610. * with physical addresses.
  611. *
  612. * INPUT:
  613. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  614. *
  615. * OUTPUT:
  616. * The routine updates the Ethernet port control struct with information
  617. * regarding the Rx descriptors and buffers.
  618. *
  619. * RETURN:
  620. * None.
  621. */
  622. static void ether_init_rx_desc_ring(struct mv643xx_private *mp)
  623. {
  624. volatile struct eth_rx_desc *p_rx_desc;
  625. int rx_desc_num = mp->rx_ring_size;
  626. int i;
  627. /* initialize the next_desc_ptr links in the Rx descriptors ring */
  628. p_rx_desc = (struct eth_rx_desc *)mp->p_rx_desc_area;
  629. for (i = 0; i < rx_desc_num; i++) {
  630. p_rx_desc[i].next_desc_ptr = mp->rx_desc_dma +
  631. ((i + 1) % rx_desc_num) * sizeof(struct eth_rx_desc);
  632. }
  633. /* Save Rx desc pointer to driver struct. */
  634. mp->rx_curr_desc_q = 0;
  635. mp->rx_used_desc_q = 0;
  636. mp->rx_desc_area_size = rx_desc_num * sizeof(struct eth_rx_desc);
  637. /* Add the queue to the list of RX queues of this port */
  638. mp->port_rx_queue_command |= 1;
  639. }
  640. /*
  641. * ether_init_tx_desc_ring - Curve a Tx chain desc list and buffer in memory.
  642. *
  643. * DESCRIPTION:
  644. * This function prepares a Tx chained list of descriptors and packet
  645. * buffers in a form of a ring. The routine must be called after port
  646. * initialization routine and before port start routine.
  647. * The Ethernet SDMA engine uses CPU bus addresses to access the various
  648. * devices in the system (i.e. DRAM). This function uses the ethernet
  649. * struct 'virtual to physical' routine (set by the user) to set the ring
  650. * with physical addresses.
  651. *
  652. * INPUT:
  653. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  654. *
  655. * OUTPUT:
  656. * The routine updates the Ethernet port control struct with information
  657. * regarding the Tx descriptors and buffers.
  658. *
  659. * RETURN:
  660. * None.
  661. */
  662. static void ether_init_tx_desc_ring(struct mv643xx_private *mp)
  663. {
  664. int tx_desc_num = mp->tx_ring_size;
  665. struct eth_tx_desc *p_tx_desc;
  666. int i;
  667. /* Initialize the next_desc_ptr links in the Tx descriptors ring */
  668. p_tx_desc = (struct eth_tx_desc *)mp->p_tx_desc_area;
  669. for (i = 0; i < tx_desc_num; i++) {
  670. p_tx_desc[i].next_desc_ptr = mp->tx_desc_dma +
  671. ((i + 1) % tx_desc_num) * sizeof(struct eth_tx_desc);
  672. }
  673. mp->tx_curr_desc_q = 0;
  674. mp->tx_used_desc_q = 0;
  675. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  676. mp->tx_first_desc_q = 0;
  677. #endif
  678. mp->tx_desc_area_size = tx_desc_num * sizeof(struct eth_tx_desc);
  679. /* Add the queue to the list of Tx queues of this port */
  680. mp->port_tx_queue_command |= 1;
  681. }
  682. /* Helper function for mv643xx_eth_open */
  683. static int mv643xx_eth_real_open(struct net_device *dev)
  684. {
  685. struct mv643xx_private *mp = netdev_priv(dev);
  686. unsigned int port_num = mp->port_num;
  687. unsigned int size;
  688. /* Stop RX Queues */
  689. mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num), 0x0000ff00);
  690. /* Set the MAC Address */
  691. memcpy(mp->port_mac_addr, dev->dev_addr, 6);
  692. eth_port_init(mp);
  693. INIT_WORK(&mp->rx_task, (void (*)(void *))mv643xx_eth_rx_task, dev);
  694. memset(&mp->timeout, 0, sizeof(struct timer_list));
  695. mp->timeout.function = mv643xx_eth_rx_task_timer_wrapper;
  696. mp->timeout.data = (unsigned long)dev;
  697. mp->rx_task_busy = 0;
  698. mp->rx_timer_flag = 0;
  699. /* Allocate RX and TX skb rings */
  700. mp->rx_skb = kmalloc(sizeof(*mp->rx_skb) * mp->rx_ring_size,
  701. GFP_KERNEL);
  702. if (!mp->rx_skb) {
  703. printk(KERN_ERR "%s: Cannot allocate Rx skb ring\n", dev->name);
  704. return -ENOMEM;
  705. }
  706. mp->tx_skb = kmalloc(sizeof(*mp->tx_skb) * mp->tx_ring_size,
  707. GFP_KERNEL);
  708. if (!mp->tx_skb) {
  709. printk(KERN_ERR "%s: Cannot allocate Tx skb ring\n", dev->name);
  710. kfree(mp->rx_skb);
  711. return -ENOMEM;
  712. }
  713. /* Allocate TX ring */
  714. mp->tx_ring_skbs = 0;
  715. size = mp->tx_ring_size * sizeof(struct eth_tx_desc);
  716. mp->tx_desc_area_size = size;
  717. if (mp->tx_sram_size) {
  718. mp->p_tx_desc_area = ioremap(mp->tx_sram_addr,
  719. mp->tx_sram_size);
  720. mp->tx_desc_dma = mp->tx_sram_addr;
  721. } else
  722. mp->p_tx_desc_area = dma_alloc_coherent(NULL, size,
  723. &mp->tx_desc_dma,
  724. GFP_KERNEL);
  725. if (!mp->p_tx_desc_area) {
  726. printk(KERN_ERR "%s: Cannot allocate Tx Ring (size %d bytes)\n",
  727. dev->name, size);
  728. kfree(mp->rx_skb);
  729. kfree(mp->tx_skb);
  730. return -ENOMEM;
  731. }
  732. BUG_ON((u32) mp->p_tx_desc_area & 0xf); /* check 16-byte alignment */
  733. memset((void *)mp->p_tx_desc_area, 0, mp->tx_desc_area_size);
  734. ether_init_tx_desc_ring(mp);
  735. /* Allocate RX ring */
  736. mp->rx_ring_skbs = 0;
  737. size = mp->rx_ring_size * sizeof(struct eth_rx_desc);
  738. mp->rx_desc_area_size = size;
  739. if (mp->rx_sram_size) {
  740. mp->p_rx_desc_area = ioremap(mp->rx_sram_addr,
  741. mp->rx_sram_size);
  742. mp->rx_desc_dma = mp->rx_sram_addr;
  743. } else
  744. mp->p_rx_desc_area = dma_alloc_coherent(NULL, size,
  745. &mp->rx_desc_dma,
  746. GFP_KERNEL);
  747. if (!mp->p_rx_desc_area) {
  748. printk(KERN_ERR "%s: Cannot allocate Rx ring (size %d bytes)\n",
  749. dev->name, size);
  750. printk(KERN_ERR "%s: Freeing previously allocated TX queues...",
  751. dev->name);
  752. if (mp->rx_sram_size)
  753. iounmap(mp->p_tx_desc_area);
  754. else
  755. dma_free_coherent(NULL, mp->tx_desc_area_size,
  756. mp->p_tx_desc_area, mp->tx_desc_dma);
  757. kfree(mp->rx_skb);
  758. kfree(mp->tx_skb);
  759. return -ENOMEM;
  760. }
  761. memset((void *)mp->p_rx_desc_area, 0, size);
  762. ether_init_rx_desc_ring(mp);
  763. mv643xx_eth_rx_task(dev); /* Fill RX ring with skb's */
  764. eth_port_start(mp);
  765. /* Interrupt Coalescing */
  766. #ifdef MV643XX_COAL
  767. mp->rx_int_coal =
  768. eth_port_set_rx_coal(port_num, 133000000, MV643XX_RX_COAL);
  769. #endif
  770. mp->tx_int_coal =
  771. eth_port_set_tx_coal(port_num, 133000000, MV643XX_TX_COAL);
  772. /* Clear any pending ethernet port interrupts */
  773. mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
  774. mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
  775. /* Unmask phy and link status changes interrupts */
  776. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
  777. INT_CAUSE_UNMASK_ALL_EXT);
  778. /* Unmask RX buffer and TX end interrupt */
  779. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  780. INT_CAUSE_UNMASK_ALL);
  781. return 0;
  782. }
  783. static void mv643xx_eth_free_tx_rings(struct net_device *dev)
  784. {
  785. struct mv643xx_private *mp = netdev_priv(dev);
  786. unsigned int port_num = mp->port_num;
  787. unsigned int curr;
  788. /* Stop Tx Queues */
  789. mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num), 0x0000ff00);
  790. /* Free outstanding skb's on TX rings */
  791. for (curr = 0; mp->tx_ring_skbs && curr < mp->tx_ring_size; curr++) {
  792. if (mp->tx_skb[curr]) {
  793. dev_kfree_skb(mp->tx_skb[curr]);
  794. mp->tx_ring_skbs--;
  795. }
  796. }
  797. if (mp->tx_ring_skbs)
  798. printk("%s: Error on Tx descriptor free - could not free %d"
  799. " descriptors\n", dev->name, mp->tx_ring_skbs);
  800. /* Free TX ring */
  801. if (mp->tx_sram_size)
  802. iounmap(mp->p_tx_desc_area);
  803. else
  804. dma_free_coherent(NULL, mp->tx_desc_area_size,
  805. mp->p_tx_desc_area, mp->tx_desc_dma);
  806. }
  807. static void mv643xx_eth_free_rx_rings(struct net_device *dev)
  808. {
  809. struct mv643xx_private *mp = netdev_priv(dev);
  810. unsigned int port_num = mp->port_num;
  811. int curr;
  812. /* Stop RX Queues */
  813. mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num), 0x0000ff00);
  814. /* Free preallocated skb's on RX rings */
  815. for (curr = 0; mp->rx_ring_skbs && curr < mp->rx_ring_size; curr++) {
  816. if (mp->rx_skb[curr]) {
  817. dev_kfree_skb(mp->rx_skb[curr]);
  818. mp->rx_ring_skbs--;
  819. }
  820. }
  821. if (mp->rx_ring_skbs)
  822. printk(KERN_ERR
  823. "%s: Error in freeing Rx Ring. %d skb's still"
  824. " stuck in RX Ring - ignoring them\n", dev->name,
  825. mp->rx_ring_skbs);
  826. /* Free RX ring */
  827. if (mp->rx_sram_size)
  828. iounmap(mp->p_rx_desc_area);
  829. else
  830. dma_free_coherent(NULL, mp->rx_desc_area_size,
  831. mp->p_rx_desc_area, mp->rx_desc_dma);
  832. }
  833. /*
  834. * mv643xx_eth_stop
  835. *
  836. * This function is used when closing the network device.
  837. * It updates the hardware,
  838. * release all memory that holds buffers and descriptors and release the IRQ.
  839. * Input : a pointer to the device structure
  840. * Output : zero if success , nonzero if fails
  841. */
  842. /* Helper function for mv643xx_eth_stop */
  843. static int mv643xx_eth_real_stop(struct net_device *dev)
  844. {
  845. struct mv643xx_private *mp = netdev_priv(dev);
  846. unsigned int port_num = mp->port_num;
  847. /* Mask RX buffer and TX end interrupt */
  848. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num), 0);
  849. /* Mask phy and link status changes interrupts */
  850. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num), 0);
  851. /* ensure previous writes have taken effect */
  852. mv_read(MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
  853. #ifdef MV643XX_NAPI
  854. netif_poll_disable(dev);
  855. #endif
  856. netif_carrier_off(dev);
  857. netif_stop_queue(dev);
  858. eth_port_reset(mp->port_num);
  859. mv643xx_eth_free_tx_rings(dev);
  860. mv643xx_eth_free_rx_rings(dev);
  861. #ifdef MV643XX_NAPI
  862. netif_poll_enable(dev);
  863. #endif
  864. return 0;
  865. }
  866. static int mv643xx_eth_stop(struct net_device *dev)
  867. {
  868. mv643xx_eth_real_stop(dev);
  869. free_irq(dev->irq, dev);
  870. return 0;
  871. }
  872. #ifdef MV643XX_NAPI
  873. static void mv643xx_tx(struct net_device *dev)
  874. {
  875. struct mv643xx_private *mp = netdev_priv(dev);
  876. struct pkt_info pkt_info;
  877. while (eth_tx_return_desc(mp, &pkt_info) == ETH_OK) {
  878. if (pkt_info.cmd_sts & ETH_TX_FIRST_DESC)
  879. dma_unmap_single(NULL, pkt_info.buf_ptr,
  880. pkt_info.byte_cnt,
  881. DMA_TO_DEVICE);
  882. else
  883. dma_unmap_page(NULL, pkt_info.buf_ptr,
  884. pkt_info.byte_cnt,
  885. DMA_TO_DEVICE);
  886. if (pkt_info.return_info)
  887. dev_kfree_skb_irq(pkt_info.return_info);
  888. }
  889. if (netif_queue_stopped(dev) &&
  890. mp->tx_ring_size > mp->tx_ring_skbs + MAX_DESCS_PER_SKB)
  891. netif_wake_queue(dev);
  892. }
  893. /*
  894. * mv643xx_poll
  895. *
  896. * This function is used in case of NAPI
  897. */
  898. static int mv643xx_poll(struct net_device *dev, int *budget)
  899. {
  900. struct mv643xx_private *mp = netdev_priv(dev);
  901. int done = 1, orig_budget, work_done;
  902. unsigned int port_num = mp->port_num;
  903. #ifdef MV643XX_TX_FAST_REFILL
  904. if (++mp->tx_clean_threshold > 5) {
  905. mv643xx_tx(dev);
  906. mp->tx_clean_threshold = 0;
  907. }
  908. #endif
  909. if ((mv_read(MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_0(port_num)))
  910. != (u32) mp->rx_used_desc_q) {
  911. orig_budget = *budget;
  912. if (orig_budget > dev->quota)
  913. orig_budget = dev->quota;
  914. work_done = mv643xx_eth_receive_queue(dev, orig_budget);
  915. mp->rx_task.func(dev);
  916. *budget -= work_done;
  917. dev->quota -= work_done;
  918. if (work_done >= orig_budget)
  919. done = 0;
  920. }
  921. if (done) {
  922. netif_rx_complete(dev);
  923. mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
  924. mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
  925. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  926. INT_CAUSE_UNMASK_ALL);
  927. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
  928. INT_CAUSE_UNMASK_ALL_EXT);
  929. }
  930. return done ? 0 : 1;
  931. }
  932. #endif
  933. /* Hardware can't handle unaligned fragments smaller than 9 bytes.
  934. * This helper function detects that case.
  935. */
  936. static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb)
  937. {
  938. unsigned int frag;
  939. skb_frag_t *fragp;
  940. for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
  941. fragp = &skb_shinfo(skb)->frags[frag];
  942. if (fragp->size <= 8 && fragp->page_offset & 0x7)
  943. return 1;
  944. }
  945. return 0;
  946. }
  947. /*
  948. * mv643xx_eth_start_xmit
  949. *
  950. * This function is queues a packet in the Tx descriptor for
  951. * required port.
  952. *
  953. * Input : skb - a pointer to socket buffer
  954. * dev - a pointer to the required port
  955. *
  956. * Output : zero upon success
  957. */
  958. static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)
  959. {
  960. struct mv643xx_private *mp = netdev_priv(dev);
  961. struct net_device_stats *stats = &mp->stats;
  962. ETH_FUNC_RET_STATUS status;
  963. unsigned long flags;
  964. struct pkt_info pkt_info;
  965. if (netif_queue_stopped(dev)) {
  966. printk(KERN_ERR
  967. "%s: Tried sending packet when interface is stopped\n",
  968. dev->name);
  969. return 1;
  970. }
  971. /* This is a hard error, log it. */
  972. if ((mp->tx_ring_size - mp->tx_ring_skbs) <=
  973. (skb_shinfo(skb)->nr_frags + 1)) {
  974. netif_stop_queue(dev);
  975. printk(KERN_ERR
  976. "%s: Bug in mv643xx_eth - Trying to transmit when"
  977. " queue full !\n", dev->name);
  978. return 1;
  979. }
  980. /* Paranoid check - this shouldn't happen */
  981. if (skb == NULL) {
  982. stats->tx_dropped++;
  983. printk(KERN_ERR "mv64320_eth paranoid check failed\n");
  984. return 1;
  985. }
  986. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  987. if (has_tiny_unaligned_frags(skb)) {
  988. if ((skb_linearize(skb, GFP_ATOMIC) != 0)) {
  989. stats->tx_dropped++;
  990. printk(KERN_DEBUG "%s: failed to linearize tiny "
  991. "unaligned fragment\n", dev->name);
  992. return 1;
  993. }
  994. }
  995. spin_lock_irqsave(&mp->lock, flags);
  996. if (!skb_shinfo(skb)->nr_frags) {
  997. if (skb->ip_summed != CHECKSUM_HW) {
  998. /* Errata BTS #50, IHL must be 5 if no HW checksum */
  999. pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT |
  1000. ETH_TX_FIRST_DESC |
  1001. ETH_TX_LAST_DESC |
  1002. 5 << ETH_TX_IHL_SHIFT;
  1003. pkt_info.l4i_chk = 0;
  1004. } else {
  1005. pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT |
  1006. ETH_TX_FIRST_DESC |
  1007. ETH_TX_LAST_DESC |
  1008. ETH_GEN_TCP_UDP_CHECKSUM |
  1009. ETH_GEN_IP_V_4_CHECKSUM |
  1010. skb->nh.iph->ihl << ETH_TX_IHL_SHIFT;
  1011. /* CPU already calculated pseudo header checksum. */
  1012. if (skb->nh.iph->protocol == IPPROTO_UDP) {
  1013. pkt_info.cmd_sts |= ETH_UDP_FRAME;
  1014. pkt_info.l4i_chk = skb->h.uh->check;
  1015. } else if (skb->nh.iph->protocol == IPPROTO_TCP)
  1016. pkt_info.l4i_chk = skb->h.th->check;
  1017. else {
  1018. printk(KERN_ERR
  1019. "%s: chksum proto != TCP or UDP\n",
  1020. dev->name);
  1021. spin_unlock_irqrestore(&mp->lock, flags);
  1022. return 1;
  1023. }
  1024. }
  1025. pkt_info.byte_cnt = skb->len;
  1026. pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
  1027. DMA_TO_DEVICE);
  1028. pkt_info.return_info = skb;
  1029. status = eth_port_send(mp, &pkt_info);
  1030. if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
  1031. printk(KERN_ERR "%s: Error on transmitting packet\n",
  1032. dev->name);
  1033. stats->tx_bytes += pkt_info.byte_cnt;
  1034. } else {
  1035. unsigned int frag;
  1036. /* first frag which is skb header */
  1037. pkt_info.byte_cnt = skb_headlen(skb);
  1038. pkt_info.buf_ptr = dma_map_single(NULL, skb->data,
  1039. skb_headlen(skb),
  1040. DMA_TO_DEVICE);
  1041. pkt_info.l4i_chk = 0;
  1042. pkt_info.return_info = 0;
  1043. if (skb->ip_summed != CHECKSUM_HW)
  1044. /* Errata BTS #50, IHL must be 5 if no HW checksum */
  1045. pkt_info.cmd_sts = ETH_TX_FIRST_DESC |
  1046. 5 << ETH_TX_IHL_SHIFT;
  1047. else {
  1048. pkt_info.cmd_sts = ETH_TX_FIRST_DESC |
  1049. ETH_GEN_TCP_UDP_CHECKSUM |
  1050. ETH_GEN_IP_V_4_CHECKSUM |
  1051. skb->nh.iph->ihl << ETH_TX_IHL_SHIFT;
  1052. /* CPU already calculated pseudo header checksum. */
  1053. if (skb->nh.iph->protocol == IPPROTO_UDP) {
  1054. pkt_info.cmd_sts |= ETH_UDP_FRAME;
  1055. pkt_info.l4i_chk = skb->h.uh->check;
  1056. } else if (skb->nh.iph->protocol == IPPROTO_TCP)
  1057. pkt_info.l4i_chk = skb->h.th->check;
  1058. else {
  1059. printk(KERN_ERR
  1060. "%s: chksum proto != TCP or UDP\n",
  1061. dev->name);
  1062. spin_unlock_irqrestore(&mp->lock, flags);
  1063. return 1;
  1064. }
  1065. }
  1066. status = eth_port_send(mp, &pkt_info);
  1067. if (status != ETH_OK) {
  1068. if ((status == ETH_ERROR))
  1069. printk(KERN_ERR
  1070. "%s: Error on transmitting packet\n",
  1071. dev->name);
  1072. if (status == ETH_QUEUE_FULL)
  1073. printk("Error on Queue Full \n");
  1074. if (status == ETH_QUEUE_LAST_RESOURCE)
  1075. printk("Tx resource error \n");
  1076. }
  1077. stats->tx_bytes += pkt_info.byte_cnt;
  1078. /* Check for the remaining frags */
  1079. for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
  1080. skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag];
  1081. pkt_info.l4i_chk = 0x0000;
  1082. pkt_info.cmd_sts = 0x00000000;
  1083. /* Last Frag enables interrupt and frees the skb */
  1084. if (frag == (skb_shinfo(skb)->nr_frags - 1)) {
  1085. pkt_info.cmd_sts |= ETH_TX_ENABLE_INTERRUPT |
  1086. ETH_TX_LAST_DESC;
  1087. pkt_info.return_info = skb;
  1088. } else {
  1089. pkt_info.return_info = 0;
  1090. }
  1091. pkt_info.l4i_chk = 0;
  1092. pkt_info.byte_cnt = this_frag->size;
  1093. pkt_info.buf_ptr = dma_map_page(NULL, this_frag->page,
  1094. this_frag->page_offset,
  1095. this_frag->size,
  1096. DMA_TO_DEVICE);
  1097. status = eth_port_send(mp, &pkt_info);
  1098. if (status != ETH_OK) {
  1099. if ((status == ETH_ERROR))
  1100. printk(KERN_ERR "%s: Error on "
  1101. "transmitting packet\n",
  1102. dev->name);
  1103. if (status == ETH_QUEUE_LAST_RESOURCE)
  1104. printk("Tx resource error \n");
  1105. if (status == ETH_QUEUE_FULL)
  1106. printk("Queue is full \n");
  1107. }
  1108. stats->tx_bytes += pkt_info.byte_cnt;
  1109. }
  1110. }
  1111. #else
  1112. spin_lock_irqsave(&mp->lock, flags);
  1113. pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT | ETH_TX_FIRST_DESC |
  1114. ETH_TX_LAST_DESC;
  1115. pkt_info.l4i_chk = 0;
  1116. pkt_info.byte_cnt = skb->len;
  1117. pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
  1118. DMA_TO_DEVICE);
  1119. pkt_info.return_info = skb;
  1120. status = eth_port_send(mp, &pkt_info);
  1121. if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
  1122. printk(KERN_ERR "%s: Error on transmitting packet\n",
  1123. dev->name);
  1124. stats->tx_bytes += pkt_info.byte_cnt;
  1125. #endif
  1126. /* Check if TX queue can handle another skb. If not, then
  1127. * signal higher layers to stop requesting TX
  1128. */
  1129. if (mp->tx_ring_size <= (mp->tx_ring_skbs + MAX_DESCS_PER_SKB))
  1130. /*
  1131. * Stop getting skb's from upper layers.
  1132. * Getting skb's from upper layers will be enabled again after
  1133. * packets are released.
  1134. */
  1135. netif_stop_queue(dev);
  1136. /* Update statistics and start of transmittion time */
  1137. stats->tx_packets++;
  1138. dev->trans_start = jiffies;
  1139. spin_unlock_irqrestore(&mp->lock, flags);
  1140. return 0; /* success */
  1141. }
  1142. /*
  1143. * mv643xx_eth_get_stats
  1144. *
  1145. * Returns a pointer to the interface statistics.
  1146. *
  1147. * Input : dev - a pointer to the required interface
  1148. *
  1149. * Output : a pointer to the interface's statistics
  1150. */
  1151. static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *dev)
  1152. {
  1153. struct mv643xx_private *mp = netdev_priv(dev);
  1154. return &mp->stats;
  1155. }
  1156. #ifdef CONFIG_NET_POLL_CONTROLLER
  1157. static inline void mv643xx_enable_irq(struct mv643xx_private *mp)
  1158. {
  1159. int port_num = mp->port_num;
  1160. unsigned long flags;
  1161. spin_lock_irqsave(&mp->lock, flags);
  1162. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  1163. INT_CAUSE_UNMASK_ALL);
  1164. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
  1165. INT_CAUSE_UNMASK_ALL_EXT);
  1166. spin_unlock_irqrestore(&mp->lock, flags);
  1167. }
  1168. static inline void mv643xx_disable_irq(struct mv643xx_private *mp)
  1169. {
  1170. int port_num = mp->port_num;
  1171. unsigned long flags;
  1172. spin_lock_irqsave(&mp->lock, flags);
  1173. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  1174. INT_CAUSE_MASK_ALL);
  1175. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
  1176. INT_CAUSE_MASK_ALL_EXT);
  1177. spin_unlock_irqrestore(&mp->lock, flags);
  1178. }
  1179. static void mv643xx_netpoll(struct net_device *netdev)
  1180. {
  1181. struct mv643xx_private *mp = netdev_priv(netdev);
  1182. mv643xx_disable_irq(mp);
  1183. mv643xx_eth_int_handler(netdev->irq, netdev, NULL);
  1184. mv643xx_enable_irq(mp);
  1185. }
  1186. #endif
  1187. /*/
  1188. * mv643xx_eth_probe
  1189. *
  1190. * First function called after registering the network device.
  1191. * It's purpose is to initialize the device as an ethernet device,
  1192. * fill the ethernet device structure with pointers * to functions,
  1193. * and set the MAC address of the interface
  1194. *
  1195. * Input : struct device *
  1196. * Output : -ENOMEM if failed , 0 if success
  1197. */
  1198. static int mv643xx_eth_probe(struct platform_device *pdev)
  1199. {
  1200. struct mv643xx_eth_platform_data *pd;
  1201. int port_num = pdev->id;
  1202. struct mv643xx_private *mp;
  1203. struct net_device *dev;
  1204. u8 *p;
  1205. struct resource *res;
  1206. int err;
  1207. dev = alloc_etherdev(sizeof(struct mv643xx_private));
  1208. if (!dev)
  1209. return -ENOMEM;
  1210. platform_set_drvdata(pdev, dev);
  1211. mp = netdev_priv(dev);
  1212. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1213. BUG_ON(!res);
  1214. dev->irq = res->start;
  1215. mp->port_num = port_num;
  1216. dev->open = mv643xx_eth_open;
  1217. dev->stop = mv643xx_eth_stop;
  1218. dev->hard_start_xmit = mv643xx_eth_start_xmit;
  1219. dev->get_stats = mv643xx_eth_get_stats;
  1220. dev->set_mac_address = mv643xx_eth_set_mac_address;
  1221. dev->set_multicast_list = mv643xx_eth_set_rx_mode;
  1222. /* No need to Tx Timeout */
  1223. dev->tx_timeout = mv643xx_eth_tx_timeout;
  1224. #ifdef MV643XX_NAPI
  1225. dev->poll = mv643xx_poll;
  1226. dev->weight = 64;
  1227. #endif
  1228. #ifdef CONFIG_NET_POLL_CONTROLLER
  1229. dev->poll_controller = mv643xx_netpoll;
  1230. #endif
  1231. dev->watchdog_timeo = 2 * HZ;
  1232. dev->tx_queue_len = mp->tx_ring_size;
  1233. dev->base_addr = 0;
  1234. dev->change_mtu = mv643xx_eth_change_mtu;
  1235. SET_ETHTOOL_OPS(dev, &mv643xx_ethtool_ops);
  1236. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  1237. #ifdef MAX_SKB_FRAGS
  1238. /*
  1239. * Zero copy can only work if we use Discovery II memory. Else, we will
  1240. * have to map the buffers to ISA memory which is only 16 MB
  1241. */
  1242. dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_HW_CSUM;
  1243. #endif
  1244. #endif
  1245. /* Configure the timeout task */
  1246. INIT_WORK(&mp->tx_timeout_task,
  1247. (void (*)(void *))mv643xx_eth_tx_timeout_task, dev);
  1248. spin_lock_init(&mp->lock);
  1249. /* set default config values */
  1250. eth_port_uc_addr_get(dev, dev->dev_addr);
  1251. mp->port_config = MV643XX_ETH_PORT_CONFIG_DEFAULT_VALUE;
  1252. mp->port_config_extend = MV643XX_ETH_PORT_CONFIG_EXTEND_DEFAULT_VALUE;
  1253. mp->port_sdma_config = MV643XX_ETH_PORT_SDMA_CONFIG_DEFAULT_VALUE;
  1254. mp->port_serial_control = MV643XX_ETH_PORT_SERIAL_CONTROL_DEFAULT_VALUE;
  1255. mp->rx_ring_size = MV643XX_ETH_PORT_DEFAULT_RECEIVE_QUEUE_SIZE;
  1256. mp->tx_ring_size = MV643XX_ETH_PORT_DEFAULT_TRANSMIT_QUEUE_SIZE;
  1257. pd = pdev->dev.platform_data;
  1258. if (pd) {
  1259. if (pd->mac_addr != NULL)
  1260. memcpy(dev->dev_addr, pd->mac_addr, 6);
  1261. if (pd->phy_addr || pd->force_phy_addr)
  1262. ethernet_phy_set(port_num, pd->phy_addr);
  1263. if (pd->port_config || pd->force_port_config)
  1264. mp->port_config = pd->port_config;
  1265. if (pd->port_config_extend || pd->force_port_config_extend)
  1266. mp->port_config_extend = pd->port_config_extend;
  1267. if (pd->port_sdma_config || pd->force_port_sdma_config)
  1268. mp->port_sdma_config = pd->port_sdma_config;
  1269. if (pd->port_serial_control || pd->force_port_serial_control)
  1270. mp->port_serial_control = pd->port_serial_control;
  1271. if (pd->rx_queue_size)
  1272. mp->rx_ring_size = pd->rx_queue_size;
  1273. if (pd->tx_queue_size)
  1274. mp->tx_ring_size = pd->tx_queue_size;
  1275. if (pd->tx_sram_size) {
  1276. mp->tx_sram_size = pd->tx_sram_size;
  1277. mp->tx_sram_addr = pd->tx_sram_addr;
  1278. }
  1279. if (pd->rx_sram_size) {
  1280. mp->rx_sram_size = pd->rx_sram_size;
  1281. mp->rx_sram_addr = pd->rx_sram_addr;
  1282. }
  1283. }
  1284. err = ethernet_phy_detect(port_num);
  1285. if (err) {
  1286. pr_debug("MV643xx ethernet port %d: "
  1287. "No PHY detected at addr %d\n",
  1288. port_num, ethernet_phy_get(port_num));
  1289. return err;
  1290. }
  1291. err = register_netdev(dev);
  1292. if (err)
  1293. goto out;
  1294. p = dev->dev_addr;
  1295. printk(KERN_NOTICE
  1296. "%s: port %d with MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
  1297. dev->name, port_num, p[0], p[1], p[2], p[3], p[4], p[5]);
  1298. if (dev->features & NETIF_F_SG)
  1299. printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name);
  1300. if (dev->features & NETIF_F_IP_CSUM)
  1301. printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n",
  1302. dev->name);
  1303. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  1304. printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name);
  1305. #endif
  1306. #ifdef MV643XX_COAL
  1307. printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n",
  1308. dev->name);
  1309. #endif
  1310. #ifdef MV643XX_NAPI
  1311. printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name);
  1312. #endif
  1313. if (mp->tx_sram_size > 0)
  1314. printk(KERN_NOTICE "%s: Using SRAM\n", dev->name);
  1315. return 0;
  1316. out:
  1317. free_netdev(dev);
  1318. return err;
  1319. }
  1320. static int mv643xx_eth_remove(struct platform_device *pdev)
  1321. {
  1322. struct net_device *dev = platform_get_drvdata(pdev);
  1323. unregister_netdev(dev);
  1324. flush_scheduled_work();
  1325. free_netdev(dev);
  1326. platform_set_drvdata(pdev, NULL);
  1327. return 0;
  1328. }
  1329. static int mv643xx_eth_shared_probe(struct platform_device *pdev)
  1330. {
  1331. struct resource *res;
  1332. printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n");
  1333. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1334. if (res == NULL)
  1335. return -ENODEV;
  1336. mv643xx_eth_shared_base = ioremap(res->start,
  1337. MV643XX_ETH_SHARED_REGS_SIZE);
  1338. if (mv643xx_eth_shared_base == NULL)
  1339. return -ENOMEM;
  1340. return 0;
  1341. }
  1342. static int mv643xx_eth_shared_remove(struct platform_device *pdev)
  1343. {
  1344. iounmap(mv643xx_eth_shared_base);
  1345. mv643xx_eth_shared_base = NULL;
  1346. return 0;
  1347. }
  1348. static struct platform_driver mv643xx_eth_driver = {
  1349. .probe = mv643xx_eth_probe,
  1350. .remove = mv643xx_eth_remove,
  1351. .driver = {
  1352. .name = MV643XX_ETH_NAME,
  1353. },
  1354. };
  1355. static struct platform_driver mv643xx_eth_shared_driver = {
  1356. .probe = mv643xx_eth_shared_probe,
  1357. .remove = mv643xx_eth_shared_remove,
  1358. .driver = {
  1359. .name = MV643XX_ETH_SHARED_NAME,
  1360. },
  1361. };
  1362. /*
  1363. * mv643xx_init_module
  1364. *
  1365. * Registers the network drivers into the Linux kernel
  1366. *
  1367. * Input : N/A
  1368. *
  1369. * Output : N/A
  1370. */
  1371. static int __init mv643xx_init_module(void)
  1372. {
  1373. int rc;
  1374. rc = platform_driver_register(&mv643xx_eth_shared_driver);
  1375. if (!rc) {
  1376. rc = platform_driver_register(&mv643xx_eth_driver);
  1377. if (rc)
  1378. platform_driver_unregister(&mv643xx_eth_shared_driver);
  1379. }
  1380. return rc;
  1381. }
  1382. /*
  1383. * mv643xx_cleanup_module
  1384. *
  1385. * Registers the network drivers into the Linux kernel
  1386. *
  1387. * Input : N/A
  1388. *
  1389. * Output : N/A
  1390. */
  1391. static void __exit mv643xx_cleanup_module(void)
  1392. {
  1393. platform_driver_unregister(&mv643xx_eth_driver);
  1394. platform_driver_unregister(&mv643xx_eth_shared_driver);
  1395. }
  1396. module_init(mv643xx_init_module);
  1397. module_exit(mv643xx_cleanup_module);
  1398. MODULE_LICENSE("GPL");
  1399. MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani"
  1400. " and Dale Farnsworth");
  1401. MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
  1402. /*
  1403. * The second part is the low level driver of the gigE ethernet ports.
  1404. */
  1405. /*
  1406. * Marvell's Gigabit Ethernet controller low level driver
  1407. *
  1408. * DESCRIPTION:
  1409. * This file introduce low level API to Marvell's Gigabit Ethernet
  1410. * controller. This Gigabit Ethernet Controller driver API controls
  1411. * 1) Operations (i.e. port init, start, reset etc').
  1412. * 2) Data flow (i.e. port send, receive etc').
  1413. * Each Gigabit Ethernet port is controlled via
  1414. * struct mv643xx_private.
  1415. * This struct includes user configuration information as well as
  1416. * driver internal data needed for its operations.
  1417. *
  1418. * Supported Features:
  1419. * - This low level driver is OS independent. Allocating memory for
  1420. * the descriptor rings and buffers are not within the scope of
  1421. * this driver.
  1422. * - The user is free from Rx/Tx queue managing.
  1423. * - This low level driver introduce functionality API that enable
  1424. * the to operate Marvell's Gigabit Ethernet Controller in a
  1425. * convenient way.
  1426. * - Simple Gigabit Ethernet port operation API.
  1427. * - Simple Gigabit Ethernet port data flow API.
  1428. * - Data flow and operation API support per queue functionality.
  1429. * - Support cached descriptors for better performance.
  1430. * - Enable access to all four DRAM banks and internal SRAM memory
  1431. * spaces.
  1432. * - PHY access and control API.
  1433. * - Port control register configuration API.
  1434. * - Full control over Unicast and Multicast MAC configurations.
  1435. *
  1436. * Operation flow:
  1437. *
  1438. * Initialization phase
  1439. * This phase complete the initialization of the the
  1440. * mv643xx_private struct.
  1441. * User information regarding port configuration has to be set
  1442. * prior to calling the port initialization routine.
  1443. *
  1444. * In this phase any port Tx/Rx activity is halted, MIB counters
  1445. * are cleared, PHY address is set according to user parameter and
  1446. * access to DRAM and internal SRAM memory spaces.
  1447. *
  1448. * Driver ring initialization
  1449. * Allocating memory for the descriptor rings and buffers is not
  1450. * within the scope of this driver. Thus, the user is required to
  1451. * allocate memory for the descriptors ring and buffers. Those
  1452. * memory parameters are used by the Rx and Tx ring initialization
  1453. * routines in order to curve the descriptor linked list in a form
  1454. * of a ring.
  1455. * Note: Pay special attention to alignment issues when using
  1456. * cached descriptors/buffers. In this phase the driver store
  1457. * information in the mv643xx_private struct regarding each queue
  1458. * ring.
  1459. *
  1460. * Driver start
  1461. * This phase prepares the Ethernet port for Rx and Tx activity.
  1462. * It uses the information stored in the mv643xx_private struct to
  1463. * initialize the various port registers.
  1464. *
  1465. * Data flow:
  1466. * All packet references to/from the driver are done using
  1467. * struct pkt_info.
  1468. * This struct is a unified struct used with Rx and Tx operations.
  1469. * This way the user is not required to be familiar with neither
  1470. * Tx nor Rx descriptors structures.
  1471. * The driver's descriptors rings are management by indexes.
  1472. * Those indexes controls the ring resources and used to indicate
  1473. * a SW resource error:
  1474. * 'current'
  1475. * This index points to the current available resource for use. For
  1476. * example in Rx process this index will point to the descriptor
  1477. * that will be passed to the user upon calling the receive
  1478. * routine. In Tx process, this index will point to the descriptor
  1479. * that will be assigned with the user packet info and transmitted.
  1480. * 'used'
  1481. * This index points to the descriptor that need to restore its
  1482. * resources. For example in Rx process, using the Rx buffer return
  1483. * API will attach the buffer returned in packet info to the
  1484. * descriptor pointed by 'used'. In Tx process, using the Tx
  1485. * descriptor return will merely return the user packet info with
  1486. * the command status of the transmitted buffer pointed by the
  1487. * 'used' index. Nevertheless, it is essential to use this routine
  1488. * to update the 'used' index.
  1489. * 'first'
  1490. * This index supports Tx Scatter-Gather. It points to the first
  1491. * descriptor of a packet assembled of multiple buffers. For
  1492. * example when in middle of Such packet we have a Tx resource
  1493. * error the 'curr' index get the value of 'first' to indicate
  1494. * that the ring returned to its state before trying to transmit
  1495. * this packet.
  1496. *
  1497. * Receive operation:
  1498. * The eth_port_receive API set the packet information struct,
  1499. * passed by the caller, with received information from the
  1500. * 'current' SDMA descriptor.
  1501. * It is the user responsibility to return this resource back
  1502. * to the Rx descriptor ring to enable the reuse of this source.
  1503. * Return Rx resource is done using the eth_rx_return_buff API.
  1504. *
  1505. * Transmit operation:
  1506. * The eth_port_send API supports Scatter-Gather which enables to
  1507. * send a packet spanned over multiple buffers. This means that
  1508. * for each packet info structure given by the user and put into
  1509. * the Tx descriptors ring, will be transmitted only if the 'LAST'
  1510. * bit will be set in the packet info command status field. This
  1511. * API also consider restriction regarding buffer alignments and
  1512. * sizes.
  1513. * The user must return a Tx resource after ensuring the buffer
  1514. * has been transmitted to enable the Tx ring indexes to update.
  1515. *
  1516. * BOARD LAYOUT
  1517. * This device is on-board. No jumper diagram is necessary.
  1518. *
  1519. * EXTERNAL INTERFACE
  1520. *
  1521. * Prior to calling the initialization routine eth_port_init() the user
  1522. * must set the following fields under mv643xx_private struct:
  1523. * port_num User Ethernet port number.
  1524. * port_mac_addr[6] User defined port MAC address.
  1525. * port_config User port configuration value.
  1526. * port_config_extend User port config extend value.
  1527. * port_sdma_config User port SDMA config value.
  1528. * port_serial_control User port serial control value.
  1529. *
  1530. * This driver data flow is done using the struct pkt_info which
  1531. * is a unified struct for Rx and Tx operations:
  1532. *
  1533. * byte_cnt Tx/Rx descriptor buffer byte count.
  1534. * l4i_chk CPU provided TCP Checksum. For Tx operation
  1535. * only.
  1536. * cmd_sts Tx/Rx descriptor command status.
  1537. * buf_ptr Tx/Rx descriptor buffer pointer.
  1538. * return_info Tx/Rx user resource return information.
  1539. */
  1540. /* defines */
  1541. /* SDMA command macros */
  1542. #define ETH_ENABLE_TX_QUEUE(eth_port) \
  1543. mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), 1)
  1544. /* locals */
  1545. /* PHY routines */
  1546. static int ethernet_phy_get(unsigned int eth_port_num);
  1547. static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr);
  1548. /* Ethernet Port routines */
  1549. static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
  1550. int option);
  1551. /*
  1552. * eth_port_init - Initialize the Ethernet port driver
  1553. *
  1554. * DESCRIPTION:
  1555. * This function prepares the ethernet port to start its activity:
  1556. * 1) Completes the ethernet port driver struct initialization toward port
  1557. * start routine.
  1558. * 2) Resets the device to a quiescent state in case of warm reboot.
  1559. * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
  1560. * 4) Clean MAC tables. The reset status of those tables is unknown.
  1561. * 5) Set PHY address.
  1562. * Note: Call this routine prior to eth_port_start routine and after
  1563. * setting user values in the user fields of Ethernet port control
  1564. * struct.
  1565. *
  1566. * INPUT:
  1567. * struct mv643xx_private *mp Ethernet port control struct
  1568. *
  1569. * OUTPUT:
  1570. * See description.
  1571. *
  1572. * RETURN:
  1573. * None.
  1574. */
  1575. static void eth_port_init(struct mv643xx_private *mp)
  1576. {
  1577. mp->port_rx_queue_command = 0;
  1578. mp->port_tx_queue_command = 0;
  1579. mp->rx_resource_err = 0;
  1580. mp->tx_resource_err = 0;
  1581. eth_port_reset(mp->port_num);
  1582. eth_port_init_mac_tables(mp->port_num);
  1583. ethernet_phy_reset(mp->port_num);
  1584. }
  1585. /*
  1586. * eth_port_start - Start the Ethernet port activity.
  1587. *
  1588. * DESCRIPTION:
  1589. * This routine prepares the Ethernet port for Rx and Tx activity:
  1590. * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
  1591. * has been initialized a descriptor's ring (using
  1592. * ether_init_tx_desc_ring for Tx and ether_init_rx_desc_ring for Rx)
  1593. * 2. Initialize and enable the Ethernet configuration port by writing to
  1594. * the port's configuration and command registers.
  1595. * 3. Initialize and enable the SDMA by writing to the SDMA's
  1596. * configuration and command registers. After completing these steps,
  1597. * the ethernet port SDMA can starts to perform Rx and Tx activities.
  1598. *
  1599. * Note: Each Rx and Tx queue descriptor's list must be initialized prior
  1600. * to calling this function (use ether_init_tx_desc_ring for Tx queues
  1601. * and ether_init_rx_desc_ring for Rx queues).
  1602. *
  1603. * INPUT:
  1604. * struct mv643xx_private *mp Ethernet port control struct
  1605. *
  1606. * OUTPUT:
  1607. * Ethernet port is ready to receive and transmit.
  1608. *
  1609. * RETURN:
  1610. * None.
  1611. */
  1612. static void eth_port_start(struct mv643xx_private *mp)
  1613. {
  1614. unsigned int port_num = mp->port_num;
  1615. int tx_curr_desc, rx_curr_desc;
  1616. /* Assignment of Tx CTRP of given queue */
  1617. tx_curr_desc = mp->tx_curr_desc_q;
  1618. mv_write(MV643XX_ETH_TX_CURRENT_QUEUE_DESC_PTR_0(port_num),
  1619. (u32)((struct eth_tx_desc *)mp->tx_desc_dma + tx_curr_desc));
  1620. /* Assignment of Rx CRDP of given queue */
  1621. rx_curr_desc = mp->rx_curr_desc_q;
  1622. mv_write(MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_0(port_num),
  1623. (u32)((struct eth_rx_desc *)mp->rx_desc_dma + rx_curr_desc));
  1624. /* Add the assigned Ethernet address to the port's address table */
  1625. eth_port_uc_addr_set(port_num, mp->port_mac_addr);
  1626. /* Assign port configuration and command. */
  1627. mv_write(MV643XX_ETH_PORT_CONFIG_REG(port_num), mp->port_config);
  1628. mv_write(MV643XX_ETH_PORT_CONFIG_EXTEND_REG(port_num),
  1629. mp->port_config_extend);
  1630. /* Increase the Rx side buffer size if supporting GigE */
  1631. if (mp->port_serial_control & MV643XX_ETH_SET_GMII_SPEED_TO_1000)
  1632. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
  1633. (mp->port_serial_control & 0xfff1ffff) | (0x5 << 17));
  1634. else
  1635. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
  1636. mp->port_serial_control);
  1637. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
  1638. mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num)) |
  1639. MV643XX_ETH_SERIAL_PORT_ENABLE);
  1640. /* Assign port SDMA configuration */
  1641. mv_write(MV643XX_ETH_SDMA_CONFIG_REG(port_num),
  1642. mp->port_sdma_config);
  1643. /* Enable port Rx. */
  1644. mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
  1645. mp->port_rx_queue_command);
  1646. /* Disable port bandwidth limits by clearing MTU register */
  1647. mv_write(MV643XX_ETH_MAXIMUM_TRANSMIT_UNIT(port_num), 0);
  1648. }
  1649. /*
  1650. * eth_port_uc_addr_set - This function Set the port Unicast address.
  1651. *
  1652. * DESCRIPTION:
  1653. * This function Set the port Ethernet MAC address.
  1654. *
  1655. * INPUT:
  1656. * unsigned int eth_port_num Port number.
  1657. * char * p_addr Address to be set
  1658. *
  1659. * OUTPUT:
  1660. * Set MAC address low and high registers. also calls eth_port_uc_addr()
  1661. * To set the unicast table with the proper information.
  1662. *
  1663. * RETURN:
  1664. * N/A.
  1665. *
  1666. */
  1667. static void eth_port_uc_addr_set(unsigned int eth_port_num,
  1668. unsigned char *p_addr)
  1669. {
  1670. unsigned int mac_h;
  1671. unsigned int mac_l;
  1672. mac_l = (p_addr[4] << 8) | (p_addr[5]);
  1673. mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
  1674. (p_addr[3] << 0);
  1675. mv_write(MV643XX_ETH_MAC_ADDR_LOW(eth_port_num), mac_l);
  1676. mv_write(MV643XX_ETH_MAC_ADDR_HIGH(eth_port_num), mac_h);
  1677. /* Accept frames of this address */
  1678. eth_port_uc_addr(eth_port_num, p_addr[5], ACCEPT_MAC_ADDR);
  1679. return;
  1680. }
  1681. /*
  1682. * eth_port_uc_addr_get - This function retrieves the port Unicast address
  1683. * (MAC address) from the ethernet hw registers.
  1684. *
  1685. * DESCRIPTION:
  1686. * This function retrieves the port Ethernet MAC address.
  1687. *
  1688. * INPUT:
  1689. * unsigned int eth_port_num Port number.
  1690. * char *MacAddr pointer where the MAC address is stored
  1691. *
  1692. * OUTPUT:
  1693. * Copy the MAC address to the location pointed to by MacAddr
  1694. *
  1695. * RETURN:
  1696. * N/A.
  1697. *
  1698. */
  1699. static void eth_port_uc_addr_get(struct net_device *dev, unsigned char *p_addr)
  1700. {
  1701. struct mv643xx_private *mp = netdev_priv(dev);
  1702. unsigned int mac_h;
  1703. unsigned int mac_l;
  1704. mac_h = mv_read(MV643XX_ETH_MAC_ADDR_HIGH(mp->port_num));
  1705. mac_l = mv_read(MV643XX_ETH_MAC_ADDR_LOW(mp->port_num));
  1706. p_addr[0] = (mac_h >> 24) & 0xff;
  1707. p_addr[1] = (mac_h >> 16) & 0xff;
  1708. p_addr[2] = (mac_h >> 8) & 0xff;
  1709. p_addr[3] = mac_h & 0xff;
  1710. p_addr[4] = (mac_l >> 8) & 0xff;
  1711. p_addr[5] = mac_l & 0xff;
  1712. }
  1713. /*
  1714. * eth_port_uc_addr - This function Set the port unicast address table
  1715. *
  1716. * DESCRIPTION:
  1717. * This function locates the proper entry in the Unicast table for the
  1718. * specified MAC nibble and sets its properties according to function
  1719. * parameters.
  1720. *
  1721. * INPUT:
  1722. * unsigned int eth_port_num Port number.
  1723. * unsigned char uc_nibble Unicast MAC Address last nibble.
  1724. * int option 0 = Add, 1 = remove address.
  1725. *
  1726. * OUTPUT:
  1727. * This function add/removes MAC addresses from the port unicast address
  1728. * table.
  1729. *
  1730. * RETURN:
  1731. * true is output succeeded.
  1732. * false if option parameter is invalid.
  1733. *
  1734. */
  1735. static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
  1736. int option)
  1737. {
  1738. unsigned int unicast_reg;
  1739. unsigned int tbl_offset;
  1740. unsigned int reg_offset;
  1741. /* Locate the Unicast table entry */
  1742. uc_nibble = (0xf & uc_nibble);
  1743. tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
  1744. reg_offset = uc_nibble % 4; /* Entry offset within the above register */
  1745. switch (option) {
  1746. case REJECT_MAC_ADDR:
  1747. /* Clear accepts frame bit at given unicast DA table entry */
  1748. unicast_reg = mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1749. (eth_port_num) + tbl_offset));
  1750. unicast_reg &= (0x0E << (8 * reg_offset));
  1751. mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1752. (eth_port_num) + tbl_offset), unicast_reg);
  1753. break;
  1754. case ACCEPT_MAC_ADDR:
  1755. /* Set accepts frame bit at unicast DA filter table entry */
  1756. unicast_reg =
  1757. mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1758. (eth_port_num) + tbl_offset));
  1759. unicast_reg |= (0x01 << (8 * reg_offset));
  1760. mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1761. (eth_port_num) + tbl_offset), unicast_reg);
  1762. break;
  1763. default:
  1764. return 0;
  1765. }
  1766. return 1;
  1767. }
  1768. /*
  1769. * The entries in each table are indexed by a hash of a packet's MAC
  1770. * address. One bit in each entry determines whether the packet is
  1771. * accepted. There are 4 entries (each 8 bits wide) in each register
  1772. * of the table. The bits in each entry are defined as follows:
  1773. * 0 Accept=1, Drop=0
  1774. * 3-1 Queue (ETH_Q0=0)
  1775. * 7-4 Reserved = 0;
  1776. */
  1777. static void eth_port_set_filter_table_entry(int table, unsigned char entry)
  1778. {
  1779. unsigned int table_reg;
  1780. unsigned int tbl_offset;
  1781. unsigned int reg_offset;
  1782. tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */
  1783. reg_offset = entry % 4; /* Entry offset within the register */
  1784. /* Set "accepts frame bit" at specified table entry */
  1785. table_reg = mv_read(table + tbl_offset);
  1786. table_reg |= 0x01 << (8 * reg_offset);
  1787. mv_write(table + tbl_offset, table_reg);
  1788. }
  1789. /*
  1790. * eth_port_mc_addr - Multicast address settings.
  1791. *
  1792. * The MV device supports multicast using two tables:
  1793. * 1) Special Multicast Table for MAC addresses of the form
  1794. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_FF).
  1795. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  1796. * Table entries in the DA-Filter table.
  1797. * 2) Other Multicast Table for multicast of another type. A CRC-8bit
  1798. * is used as an index to the Other Multicast Table entries in the
  1799. * DA-Filter table. This function calculates the CRC-8bit value.
  1800. * In either case, eth_port_set_filter_table_entry() is then called
  1801. * to set to set the actual table entry.
  1802. */
  1803. static void eth_port_mc_addr(unsigned int eth_port_num, unsigned char *p_addr)
  1804. {
  1805. unsigned int mac_h;
  1806. unsigned int mac_l;
  1807. unsigned char crc_result = 0;
  1808. int table;
  1809. int mac_array[48];
  1810. int crc[8];
  1811. int i;
  1812. if ((p_addr[0] == 0x01) && (p_addr[1] == 0x00) &&
  1813. (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) {
  1814. table = MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
  1815. (eth_port_num);
  1816. eth_port_set_filter_table_entry(table, p_addr[5]);
  1817. return;
  1818. }
  1819. /* Calculate CRC-8 out of the given address */
  1820. mac_h = (p_addr[0] << 8) | (p_addr[1]);
  1821. mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
  1822. (p_addr[4] << 8) | (p_addr[5] << 0);
  1823. for (i = 0; i < 32; i++)
  1824. mac_array[i] = (mac_l >> i) & 0x1;
  1825. for (i = 32; i < 48; i++)
  1826. mac_array[i] = (mac_h >> (i - 32)) & 0x1;
  1827. crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^
  1828. mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^
  1829. mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
  1830. mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^
  1831. mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0];
  1832. crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
  1833. mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^
  1834. mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
  1835. mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^
  1836. mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^
  1837. mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
  1838. mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0];
  1839. crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^
  1840. mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^
  1841. mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
  1842. mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^
  1843. mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^
  1844. mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0];
  1845. crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
  1846. mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^
  1847. mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
  1848. mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
  1849. mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^
  1850. mac_array[3] ^ mac_array[2] ^ mac_array[1];
  1851. crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^
  1852. mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^
  1853. mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
  1854. mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^
  1855. mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^
  1856. mac_array[3] ^ mac_array[2];
  1857. crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^
  1858. mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^
  1859. mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
  1860. mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^
  1861. mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^
  1862. mac_array[4] ^ mac_array[3];
  1863. crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^
  1864. mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^
  1865. mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
  1866. mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^
  1867. mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^
  1868. mac_array[4];
  1869. crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^
  1870. mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^
  1871. mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
  1872. mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^
  1873. mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5];
  1874. for (i = 0; i < 8; i++)
  1875. crc_result = crc_result | (crc[i] << i);
  1876. table = MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num);
  1877. eth_port_set_filter_table_entry(table, crc_result);
  1878. }
  1879. /*
  1880. * Set the entire multicast list based on dev->mc_list.
  1881. */
  1882. static void eth_port_set_multicast_list(struct net_device *dev)
  1883. {
  1884. struct dev_mc_list *mc_list;
  1885. int i;
  1886. int table_index;
  1887. struct mv643xx_private *mp = netdev_priv(dev);
  1888. unsigned int eth_port_num = mp->port_num;
  1889. /* If the device is in promiscuous mode or in all multicast mode,
  1890. * we will fully populate both multicast tables with accept.
  1891. * This is guaranteed to yield a match on all multicast addresses...
  1892. */
  1893. if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) {
  1894. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1895. /* Set all entries in DA filter special multicast
  1896. * table (Ex_dFSMT)
  1897. * Set for ETH_Q0 for now
  1898. * Bits
  1899. * 0 Accept=1, Drop=0
  1900. * 3-1 Queue ETH_Q0=0
  1901. * 7-4 Reserved = 0;
  1902. */
  1903. mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101);
  1904. /* Set all entries in DA filter other multicast
  1905. * table (Ex_dFOMT)
  1906. * Set for ETH_Q0 for now
  1907. * Bits
  1908. * 0 Accept=1, Drop=0
  1909. * 3-1 Queue ETH_Q0=0
  1910. * 7-4 Reserved = 0;
  1911. */
  1912. mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101);
  1913. }
  1914. return;
  1915. }
  1916. /* We will clear out multicast tables every time we get the list.
  1917. * Then add the entire new list...
  1918. */
  1919. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1920. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1921. mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
  1922. (eth_port_num) + table_index, 0);
  1923. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1924. mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE
  1925. (eth_port_num) + table_index, 0);
  1926. }
  1927. /* Get pointer to net_device multicast list and add each one... */
  1928. for (i = 0, mc_list = dev->mc_list;
  1929. (i < 256) && (mc_list != NULL) && (i < dev->mc_count);
  1930. i++, mc_list = mc_list->next)
  1931. if (mc_list->dmi_addrlen == 6)
  1932. eth_port_mc_addr(eth_port_num, mc_list->dmi_addr);
  1933. }
  1934. /*
  1935. * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
  1936. *
  1937. * DESCRIPTION:
  1938. * Go through all the DA filter tables (Unicast, Special Multicast &
  1939. * Other Multicast) and set each entry to 0.
  1940. *
  1941. * INPUT:
  1942. * unsigned int eth_port_num Ethernet Port number.
  1943. *
  1944. * OUTPUT:
  1945. * Multicast and Unicast packets are rejected.
  1946. *
  1947. * RETURN:
  1948. * None.
  1949. */
  1950. static void eth_port_init_mac_tables(unsigned int eth_port_num)
  1951. {
  1952. int table_index;
  1953. /* Clear DA filter unicast table (Ex_dFUT) */
  1954. for (table_index = 0; table_index <= 0xC; table_index += 4)
  1955. mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1956. (eth_port_num) + table_index), 0);
  1957. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1958. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1959. mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
  1960. (eth_port_num) + table_index, 0);
  1961. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1962. mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE
  1963. (eth_port_num) + table_index, 0);
  1964. }
  1965. }
  1966. /*
  1967. * eth_clear_mib_counters - Clear all MIB counters
  1968. *
  1969. * DESCRIPTION:
  1970. * This function clears all MIB counters of a specific ethernet port.
  1971. * A read from the MIB counter will reset the counter.
  1972. *
  1973. * INPUT:
  1974. * unsigned int eth_port_num Ethernet Port number.
  1975. *
  1976. * OUTPUT:
  1977. * After reading all MIB counters, the counters resets.
  1978. *
  1979. * RETURN:
  1980. * MIB counter value.
  1981. *
  1982. */
  1983. static void eth_clear_mib_counters(unsigned int eth_port_num)
  1984. {
  1985. int i;
  1986. /* Perform dummy reads from MIB counters */
  1987. for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
  1988. i += 4)
  1989. mv_read(MV643XX_ETH_MIB_COUNTERS_BASE(eth_port_num) + i);
  1990. }
  1991. static inline u32 read_mib(struct mv643xx_private *mp, int offset)
  1992. {
  1993. return mv_read(MV643XX_ETH_MIB_COUNTERS_BASE(mp->port_num) + offset);
  1994. }
  1995. static void eth_update_mib_counters(struct mv643xx_private *mp)
  1996. {
  1997. struct mv643xx_mib_counters *p = &mp->mib_counters;
  1998. int offset;
  1999. p->good_octets_received +=
  2000. read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
  2001. p->good_octets_received +=
  2002. (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32;
  2003. for (offset = ETH_MIB_BAD_OCTETS_RECEIVED;
  2004. offset <= ETH_MIB_FRAMES_1024_TO_MAX_OCTETS;
  2005. offset += 4)
  2006. *(u32 *)((char *)p + offset) = read_mib(mp, offset);
  2007. p->good_octets_sent += read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_LOW);
  2008. p->good_octets_sent +=
  2009. (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_HIGH) << 32;
  2010. for (offset = ETH_MIB_GOOD_FRAMES_SENT;
  2011. offset <= ETH_MIB_LATE_COLLISION;
  2012. offset += 4)
  2013. *(u32 *)((char *)p + offset) = read_mib(mp, offset);
  2014. }
  2015. /*
  2016. * ethernet_phy_detect - Detect whether a phy is present
  2017. *
  2018. * DESCRIPTION:
  2019. * This function tests whether there is a PHY present on
  2020. * the specified port.
  2021. *
  2022. * INPUT:
  2023. * unsigned int eth_port_num Ethernet Port number.
  2024. *
  2025. * OUTPUT:
  2026. * None
  2027. *
  2028. * RETURN:
  2029. * 0 on success
  2030. * -ENODEV on failure
  2031. *
  2032. */
  2033. static int ethernet_phy_detect(unsigned int port_num)
  2034. {
  2035. unsigned int phy_reg_data0;
  2036. int auto_neg;
  2037. eth_port_read_smi_reg(port_num, 0, &phy_reg_data0);
  2038. auto_neg = phy_reg_data0 & 0x1000;
  2039. phy_reg_data0 ^= 0x1000; /* invert auto_neg */
  2040. eth_port_write_smi_reg(port_num, 0, phy_reg_data0);
  2041. eth_port_read_smi_reg(port_num, 0, &phy_reg_data0);
  2042. if ((phy_reg_data0 & 0x1000) == auto_neg)
  2043. return -ENODEV; /* change didn't take */
  2044. phy_reg_data0 ^= 0x1000;
  2045. eth_port_write_smi_reg(port_num, 0, phy_reg_data0);
  2046. return 0;
  2047. }
  2048. /*
  2049. * ethernet_phy_get - Get the ethernet port PHY address.
  2050. *
  2051. * DESCRIPTION:
  2052. * This routine returns the given ethernet port PHY address.
  2053. *
  2054. * INPUT:
  2055. * unsigned int eth_port_num Ethernet Port number.
  2056. *
  2057. * OUTPUT:
  2058. * None.
  2059. *
  2060. * RETURN:
  2061. * PHY address.
  2062. *
  2063. */
  2064. static int ethernet_phy_get(unsigned int eth_port_num)
  2065. {
  2066. unsigned int reg_data;
  2067. reg_data = mv_read(MV643XX_ETH_PHY_ADDR_REG);
  2068. return ((reg_data >> (5 * eth_port_num)) & 0x1f);
  2069. }
  2070. /*
  2071. * ethernet_phy_set - Set the ethernet port PHY address.
  2072. *
  2073. * DESCRIPTION:
  2074. * This routine sets the given ethernet port PHY address.
  2075. *
  2076. * INPUT:
  2077. * unsigned int eth_port_num Ethernet Port number.
  2078. * int phy_addr PHY address.
  2079. *
  2080. * OUTPUT:
  2081. * None.
  2082. *
  2083. * RETURN:
  2084. * None.
  2085. *
  2086. */
  2087. static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr)
  2088. {
  2089. u32 reg_data;
  2090. int addr_shift = 5 * eth_port_num;
  2091. reg_data = mv_read(MV643XX_ETH_PHY_ADDR_REG);
  2092. reg_data &= ~(0x1f << addr_shift);
  2093. reg_data |= (phy_addr & 0x1f) << addr_shift;
  2094. mv_write(MV643XX_ETH_PHY_ADDR_REG, reg_data);
  2095. }
  2096. /*
  2097. * ethernet_phy_reset - Reset Ethernet port PHY.
  2098. *
  2099. * DESCRIPTION:
  2100. * This routine utilizes the SMI interface to reset the ethernet port PHY.
  2101. *
  2102. * INPUT:
  2103. * unsigned int eth_port_num Ethernet Port number.
  2104. *
  2105. * OUTPUT:
  2106. * The PHY is reset.
  2107. *
  2108. * RETURN:
  2109. * None.
  2110. *
  2111. */
  2112. static void ethernet_phy_reset(unsigned int eth_port_num)
  2113. {
  2114. unsigned int phy_reg_data;
  2115. /* Reset the PHY */
  2116. eth_port_read_smi_reg(eth_port_num, 0, &phy_reg_data);
  2117. phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
  2118. eth_port_write_smi_reg(eth_port_num, 0, phy_reg_data);
  2119. }
  2120. /*
  2121. * eth_port_reset - Reset Ethernet port
  2122. *
  2123. * DESCRIPTION:
  2124. * This routine resets the chip by aborting any SDMA engine activity and
  2125. * clearing the MIB counters. The Receiver and the Transmit unit are in
  2126. * idle state after this command is performed and the port is disabled.
  2127. *
  2128. * INPUT:
  2129. * unsigned int eth_port_num Ethernet Port number.
  2130. *
  2131. * OUTPUT:
  2132. * Channel activity is halted.
  2133. *
  2134. * RETURN:
  2135. * None.
  2136. *
  2137. */
  2138. static void eth_port_reset(unsigned int port_num)
  2139. {
  2140. unsigned int reg_data;
  2141. /* Stop Tx port activity. Check port Tx activity. */
  2142. reg_data = mv_read(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num));
  2143. if (reg_data & 0xFF) {
  2144. /* Issue stop command for active channels only */
  2145. mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num),
  2146. (reg_data << 8));
  2147. /* Wait for all Tx activity to terminate. */
  2148. /* Check port cause register that all Tx queues are stopped */
  2149. while (mv_read(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num))
  2150. & 0xFF)
  2151. udelay(10);
  2152. }
  2153. /* Stop Rx port activity. Check port Rx activity. */
  2154. reg_data = mv_read(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num));
  2155. if (reg_data & 0xFF) {
  2156. /* Issue stop command for active channels only */
  2157. mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
  2158. (reg_data << 8));
  2159. /* Wait for all Rx activity to terminate. */
  2160. /* Check port cause register that all Rx queues are stopped */
  2161. while (mv_read(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num))
  2162. & 0xFF)
  2163. udelay(10);
  2164. }
  2165. /* Clear all MIB counters */
  2166. eth_clear_mib_counters(port_num);
  2167. /* Reset the Enable bit in the Configuration Register */
  2168. reg_data = mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num));
  2169. reg_data &= ~MV643XX_ETH_SERIAL_PORT_ENABLE;
  2170. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num), reg_data);
  2171. }
  2172. static int eth_port_autoneg_supported(unsigned int eth_port_num)
  2173. {
  2174. unsigned int phy_reg_data0;
  2175. eth_port_read_smi_reg(eth_port_num, 0, &phy_reg_data0);
  2176. return phy_reg_data0 & 0x1000;
  2177. }
  2178. static int eth_port_link_is_up(unsigned int eth_port_num)
  2179. {
  2180. unsigned int phy_reg_data1;
  2181. eth_port_read_smi_reg(eth_port_num, 1, &phy_reg_data1);
  2182. if (eth_port_autoneg_supported(eth_port_num)) {
  2183. if (phy_reg_data1 & 0x20) /* auto-neg complete */
  2184. return 1;
  2185. } else if (phy_reg_data1 & 0x4) /* link up */
  2186. return 1;
  2187. return 0;
  2188. }
  2189. /*
  2190. * eth_port_read_smi_reg - Read PHY registers
  2191. *
  2192. * DESCRIPTION:
  2193. * This routine utilize the SMI interface to interact with the PHY in
  2194. * order to perform PHY register read.
  2195. *
  2196. * INPUT:
  2197. * unsigned int port_num Ethernet Port number.
  2198. * unsigned int phy_reg PHY register address offset.
  2199. * unsigned int *value Register value buffer.
  2200. *
  2201. * OUTPUT:
  2202. * Write the value of a specified PHY register into given buffer.
  2203. *
  2204. * RETURN:
  2205. * false if the PHY is busy or read data is not in valid state.
  2206. * true otherwise.
  2207. *
  2208. */
  2209. static void eth_port_read_smi_reg(unsigned int port_num,
  2210. unsigned int phy_reg, unsigned int *value)
  2211. {
  2212. int phy_addr = ethernet_phy_get(port_num);
  2213. unsigned long flags;
  2214. int i;
  2215. /* the SMI register is a shared resource */
  2216. spin_lock_irqsave(&mv643xx_eth_phy_lock, flags);
  2217. /* wait for the SMI register to become available */
  2218. for (i = 0; mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_BUSY; i++) {
  2219. if (i == PHY_WAIT_ITERATIONS) {
  2220. printk("mv643xx PHY busy timeout, port %d\n", port_num);
  2221. goto out;
  2222. }
  2223. udelay(PHY_WAIT_MICRO_SECONDS);
  2224. }
  2225. mv_write(MV643XX_ETH_SMI_REG,
  2226. (phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ);
  2227. /* now wait for the data to be valid */
  2228. for (i = 0; !(mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_READ_VALID); i++) {
  2229. if (i == PHY_WAIT_ITERATIONS) {
  2230. printk("mv643xx PHY read timeout, port %d\n", port_num);
  2231. goto out;
  2232. }
  2233. udelay(PHY_WAIT_MICRO_SECONDS);
  2234. }
  2235. *value = mv_read(MV643XX_ETH_SMI_REG) & 0xffff;
  2236. out:
  2237. spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags);
  2238. }
  2239. /*
  2240. * eth_port_write_smi_reg - Write to PHY registers
  2241. *
  2242. * DESCRIPTION:
  2243. * This routine utilize the SMI interface to interact with the PHY in
  2244. * order to perform writes to PHY registers.
  2245. *
  2246. * INPUT:
  2247. * unsigned int eth_port_num Ethernet Port number.
  2248. * unsigned int phy_reg PHY register address offset.
  2249. * unsigned int value Register value.
  2250. *
  2251. * OUTPUT:
  2252. * Write the given value to the specified PHY register.
  2253. *
  2254. * RETURN:
  2255. * false if the PHY is busy.
  2256. * true otherwise.
  2257. *
  2258. */
  2259. static void eth_port_write_smi_reg(unsigned int eth_port_num,
  2260. unsigned int phy_reg, unsigned int value)
  2261. {
  2262. int phy_addr;
  2263. int i;
  2264. unsigned long flags;
  2265. phy_addr = ethernet_phy_get(eth_port_num);
  2266. /* the SMI register is a shared resource */
  2267. spin_lock_irqsave(&mv643xx_eth_phy_lock, flags);
  2268. /* wait for the SMI register to become available */
  2269. for (i = 0; mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_BUSY; i++) {
  2270. if (i == PHY_WAIT_ITERATIONS) {
  2271. printk("mv643xx PHY busy timeout, port %d\n",
  2272. eth_port_num);
  2273. goto out;
  2274. }
  2275. udelay(PHY_WAIT_MICRO_SECONDS);
  2276. }
  2277. mv_write(MV643XX_ETH_SMI_REG, (phy_addr << 16) | (phy_reg << 21) |
  2278. ETH_SMI_OPCODE_WRITE | (value & 0xffff));
  2279. out:
  2280. spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags);
  2281. }
  2282. /*
  2283. * eth_port_send - Send an Ethernet packet
  2284. *
  2285. * DESCRIPTION:
  2286. * This routine send a given packet described by p_pktinfo parameter. It
  2287. * supports transmitting of a packet spaned over multiple buffers. The
  2288. * routine updates 'curr' and 'first' indexes according to the packet
  2289. * segment passed to the routine. In case the packet segment is first,
  2290. * the 'first' index is update. In any case, the 'curr' index is updated.
  2291. * If the routine get into Tx resource error it assigns 'curr' index as
  2292. * 'first'. This way the function can abort Tx process of multiple
  2293. * descriptors per packet.
  2294. *
  2295. * INPUT:
  2296. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2297. * struct pkt_info *p_pkt_info User packet buffer.
  2298. *
  2299. * OUTPUT:
  2300. * Tx ring 'curr' and 'first' indexes are updated.
  2301. *
  2302. * RETURN:
  2303. * ETH_QUEUE_FULL in case of Tx resource error.
  2304. * ETH_ERROR in case the routine can not access Tx desc ring.
  2305. * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource.
  2306. * ETH_OK otherwise.
  2307. *
  2308. */
  2309. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  2310. /*
  2311. * Modified to include the first descriptor pointer in case of SG
  2312. */
  2313. static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
  2314. struct pkt_info *p_pkt_info)
  2315. {
  2316. int tx_desc_curr, tx_desc_used, tx_first_desc, tx_next_desc;
  2317. struct eth_tx_desc *current_descriptor;
  2318. struct eth_tx_desc *first_descriptor;
  2319. u32 command;
  2320. unsigned long flags;
  2321. /* Do not process Tx ring in case of Tx ring resource error */
  2322. if (mp->tx_resource_err)
  2323. return ETH_QUEUE_FULL;
  2324. /*
  2325. * The hardware requires that each buffer that is <= 8 bytes
  2326. * in length must be aligned on an 8 byte boundary.
  2327. */
  2328. if (p_pkt_info->byte_cnt <= 8 && p_pkt_info->buf_ptr & 0x7) {
  2329. printk(KERN_ERR
  2330. "mv643xx_eth port %d: packet size <= 8 problem\n",
  2331. mp->port_num);
  2332. return ETH_ERROR;
  2333. }
  2334. spin_lock_irqsave(&mp->lock, flags);
  2335. mp->tx_ring_skbs++;
  2336. BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
  2337. /* Get the Tx Desc ring indexes */
  2338. tx_desc_curr = mp->tx_curr_desc_q;
  2339. tx_desc_used = mp->tx_used_desc_q;
  2340. current_descriptor = &mp->p_tx_desc_area[tx_desc_curr];
  2341. tx_next_desc = (tx_desc_curr + 1) % mp->tx_ring_size;
  2342. current_descriptor->buf_ptr = p_pkt_info->buf_ptr;
  2343. current_descriptor->byte_cnt = p_pkt_info->byte_cnt;
  2344. current_descriptor->l4i_chk = p_pkt_info->l4i_chk;
  2345. mp->tx_skb[tx_desc_curr] = p_pkt_info->return_info;
  2346. command = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC |
  2347. ETH_BUFFER_OWNED_BY_DMA;
  2348. if (command & ETH_TX_FIRST_DESC) {
  2349. tx_first_desc = tx_desc_curr;
  2350. mp->tx_first_desc_q = tx_first_desc;
  2351. first_descriptor = current_descriptor;
  2352. mp->tx_first_command = command;
  2353. } else {
  2354. tx_first_desc = mp->tx_first_desc_q;
  2355. first_descriptor = &mp->p_tx_desc_area[tx_first_desc];
  2356. BUG_ON(first_descriptor == NULL);
  2357. current_descriptor->cmd_sts = command;
  2358. }
  2359. if (command & ETH_TX_LAST_DESC) {
  2360. wmb();
  2361. first_descriptor->cmd_sts = mp->tx_first_command;
  2362. wmb();
  2363. ETH_ENABLE_TX_QUEUE(mp->port_num);
  2364. /*
  2365. * Finish Tx packet. Update first desc in case of Tx resource
  2366. * error */
  2367. tx_first_desc = tx_next_desc;
  2368. mp->tx_first_desc_q = tx_first_desc;
  2369. }
  2370. /* Check for ring index overlap in the Tx desc ring */
  2371. if (tx_next_desc == tx_desc_used) {
  2372. mp->tx_resource_err = 1;
  2373. mp->tx_curr_desc_q = tx_first_desc;
  2374. spin_unlock_irqrestore(&mp->lock, flags);
  2375. return ETH_QUEUE_LAST_RESOURCE;
  2376. }
  2377. mp->tx_curr_desc_q = tx_next_desc;
  2378. spin_unlock_irqrestore(&mp->lock, flags);
  2379. return ETH_OK;
  2380. }
  2381. #else
  2382. static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
  2383. struct pkt_info *p_pkt_info)
  2384. {
  2385. int tx_desc_curr;
  2386. int tx_desc_used;
  2387. struct eth_tx_desc *current_descriptor;
  2388. unsigned int command_status;
  2389. unsigned long flags;
  2390. /* Do not process Tx ring in case of Tx ring resource error */
  2391. if (mp->tx_resource_err)
  2392. return ETH_QUEUE_FULL;
  2393. spin_lock_irqsave(&mp->lock, flags);
  2394. mp->tx_ring_skbs++;
  2395. BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
  2396. /* Get the Tx Desc ring indexes */
  2397. tx_desc_curr = mp->tx_curr_desc_q;
  2398. tx_desc_used = mp->tx_used_desc_q;
  2399. current_descriptor = &mp->p_tx_desc_area[tx_desc_curr];
  2400. command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC;
  2401. current_descriptor->buf_ptr = p_pkt_info->buf_ptr;
  2402. current_descriptor->byte_cnt = p_pkt_info->byte_cnt;
  2403. mp->tx_skb[tx_desc_curr] = p_pkt_info->return_info;
  2404. /* Set last desc with DMA ownership and interrupt enable. */
  2405. wmb();
  2406. current_descriptor->cmd_sts = command_status |
  2407. ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT;
  2408. wmb();
  2409. ETH_ENABLE_TX_QUEUE(mp->port_num);
  2410. /* Finish Tx packet. Update first desc in case of Tx resource error */
  2411. tx_desc_curr = (tx_desc_curr + 1) % mp->tx_ring_size;
  2412. /* Update the current descriptor */
  2413. mp->tx_curr_desc_q = tx_desc_curr;
  2414. /* Check for ring index overlap in the Tx desc ring */
  2415. if (tx_desc_curr == tx_desc_used) {
  2416. mp->tx_resource_err = 1;
  2417. spin_unlock_irqrestore(&mp->lock, flags);
  2418. return ETH_QUEUE_LAST_RESOURCE;
  2419. }
  2420. spin_unlock_irqrestore(&mp->lock, flags);
  2421. return ETH_OK;
  2422. }
  2423. #endif
  2424. /*
  2425. * eth_tx_return_desc - Free all used Tx descriptors
  2426. *
  2427. * DESCRIPTION:
  2428. * This routine returns the transmitted packet information to the caller.
  2429. * It uses the 'first' index to support Tx desc return in case a transmit
  2430. * of a packet spanned over multiple buffer still in process.
  2431. * In case the Tx queue was in "resource error" condition, where there are
  2432. * no available Tx resources, the function resets the resource error flag.
  2433. *
  2434. * INPUT:
  2435. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2436. * struct pkt_info *p_pkt_info User packet buffer.
  2437. *
  2438. * OUTPUT:
  2439. * Tx ring 'first' and 'used' indexes are updated.
  2440. *
  2441. * RETURN:
  2442. * ETH_OK on success
  2443. * ETH_ERROR otherwise.
  2444. *
  2445. */
  2446. static ETH_FUNC_RET_STATUS eth_tx_return_desc(struct mv643xx_private *mp,
  2447. struct pkt_info *p_pkt_info)
  2448. {
  2449. int tx_desc_used;
  2450. int tx_busy_desc;
  2451. struct eth_tx_desc *p_tx_desc_used;
  2452. unsigned int command_status;
  2453. unsigned long flags;
  2454. int err = ETH_OK;
  2455. spin_lock_irqsave(&mp->lock, flags);
  2456. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  2457. tx_busy_desc = mp->tx_first_desc_q;
  2458. #else
  2459. tx_busy_desc = mp->tx_curr_desc_q;
  2460. #endif
  2461. /* Get the Tx Desc ring indexes */
  2462. tx_desc_used = mp->tx_used_desc_q;
  2463. p_tx_desc_used = &mp->p_tx_desc_area[tx_desc_used];
  2464. /* Sanity check */
  2465. if (p_tx_desc_used == NULL) {
  2466. err = ETH_ERROR;
  2467. goto out;
  2468. }
  2469. /* Stop release. About to overlap the current available Tx descriptor */
  2470. if (tx_desc_used == tx_busy_desc && !mp->tx_resource_err) {
  2471. err = ETH_ERROR;
  2472. goto out;
  2473. }
  2474. command_status = p_tx_desc_used->cmd_sts;
  2475. /* Still transmitting... */
  2476. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  2477. err = ETH_ERROR;
  2478. goto out;
  2479. }
  2480. /* Pass the packet information to the caller */
  2481. p_pkt_info->cmd_sts = command_status;
  2482. p_pkt_info->return_info = mp->tx_skb[tx_desc_used];
  2483. p_pkt_info->buf_ptr = p_tx_desc_used->buf_ptr;
  2484. p_pkt_info->byte_cnt = p_tx_desc_used->byte_cnt;
  2485. mp->tx_skb[tx_desc_used] = NULL;
  2486. /* Update the next descriptor to release. */
  2487. mp->tx_used_desc_q = (tx_desc_used + 1) % mp->tx_ring_size;
  2488. /* Any Tx return cancels the Tx resource error status */
  2489. mp->tx_resource_err = 0;
  2490. BUG_ON(mp->tx_ring_skbs == 0);
  2491. mp->tx_ring_skbs--;
  2492. out:
  2493. spin_unlock_irqrestore(&mp->lock, flags);
  2494. return err;
  2495. }
  2496. /*
  2497. * eth_port_receive - Get received information from Rx ring.
  2498. *
  2499. * DESCRIPTION:
  2500. * This routine returns the received data to the caller. There is no
  2501. * data copying during routine operation. All information is returned
  2502. * using pointer to packet information struct passed from the caller.
  2503. * If the routine exhausts Rx ring resources then the resource error flag
  2504. * is set.
  2505. *
  2506. * INPUT:
  2507. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2508. * struct pkt_info *p_pkt_info User packet buffer.
  2509. *
  2510. * OUTPUT:
  2511. * Rx ring current and used indexes are updated.
  2512. *
  2513. * RETURN:
  2514. * ETH_ERROR in case the routine can not access Rx desc ring.
  2515. * ETH_QUEUE_FULL if Rx ring resources are exhausted.
  2516. * ETH_END_OF_JOB if there is no received data.
  2517. * ETH_OK otherwise.
  2518. */
  2519. static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp,
  2520. struct pkt_info *p_pkt_info)
  2521. {
  2522. int rx_next_curr_desc, rx_curr_desc, rx_used_desc;
  2523. volatile struct eth_rx_desc *p_rx_desc;
  2524. unsigned int command_status;
  2525. unsigned long flags;
  2526. /* Do not process Rx ring in case of Rx ring resource error */
  2527. if (mp->rx_resource_err)
  2528. return ETH_QUEUE_FULL;
  2529. spin_lock_irqsave(&mp->lock, flags);
  2530. /* Get the Rx Desc ring 'curr and 'used' indexes */
  2531. rx_curr_desc = mp->rx_curr_desc_q;
  2532. rx_used_desc = mp->rx_used_desc_q;
  2533. p_rx_desc = &mp->p_rx_desc_area[rx_curr_desc];
  2534. /* The following parameters are used to save readings from memory */
  2535. command_status = p_rx_desc->cmd_sts;
  2536. rmb();
  2537. /* Nothing to receive... */
  2538. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  2539. spin_unlock_irqrestore(&mp->lock, flags);
  2540. return ETH_END_OF_JOB;
  2541. }
  2542. p_pkt_info->byte_cnt = (p_rx_desc->byte_cnt) - RX_BUF_OFFSET;
  2543. p_pkt_info->cmd_sts = command_status;
  2544. p_pkt_info->buf_ptr = (p_rx_desc->buf_ptr) + RX_BUF_OFFSET;
  2545. p_pkt_info->return_info = mp->rx_skb[rx_curr_desc];
  2546. p_pkt_info->l4i_chk = p_rx_desc->buf_size;
  2547. /* Clean the return info field to indicate that the packet has been */
  2548. /* moved to the upper layers */
  2549. mp->rx_skb[rx_curr_desc] = NULL;
  2550. /* Update current index in data structure */
  2551. rx_next_curr_desc = (rx_curr_desc + 1) % mp->rx_ring_size;
  2552. mp->rx_curr_desc_q = rx_next_curr_desc;
  2553. /* Rx descriptors exhausted. Set the Rx ring resource error flag */
  2554. if (rx_next_curr_desc == rx_used_desc)
  2555. mp->rx_resource_err = 1;
  2556. spin_unlock_irqrestore(&mp->lock, flags);
  2557. return ETH_OK;
  2558. }
  2559. /*
  2560. * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
  2561. *
  2562. * DESCRIPTION:
  2563. * This routine returns a Rx buffer back to the Rx ring. It retrieves the
  2564. * next 'used' descriptor and attached the returned buffer to it.
  2565. * In case the Rx ring was in "resource error" condition, where there are
  2566. * no available Rx resources, the function resets the resource error flag.
  2567. *
  2568. * INPUT:
  2569. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2570. * struct pkt_info *p_pkt_info Information on returned buffer.
  2571. *
  2572. * OUTPUT:
  2573. * New available Rx resource in Rx descriptor ring.
  2574. *
  2575. * RETURN:
  2576. * ETH_ERROR in case the routine can not access Rx desc ring.
  2577. * ETH_OK otherwise.
  2578. */
  2579. static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp,
  2580. struct pkt_info *p_pkt_info)
  2581. {
  2582. int used_rx_desc; /* Where to return Rx resource */
  2583. volatile struct eth_rx_desc *p_used_rx_desc;
  2584. unsigned long flags;
  2585. spin_lock_irqsave(&mp->lock, flags);
  2586. /* Get 'used' Rx descriptor */
  2587. used_rx_desc = mp->rx_used_desc_q;
  2588. p_used_rx_desc = &mp->p_rx_desc_area[used_rx_desc];
  2589. p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
  2590. p_used_rx_desc->buf_size = p_pkt_info->byte_cnt;
  2591. mp->rx_skb[used_rx_desc] = p_pkt_info->return_info;
  2592. /* Flush the write pipe */
  2593. /* Return the descriptor to DMA ownership */
  2594. wmb();
  2595. p_used_rx_desc->cmd_sts =
  2596. ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
  2597. wmb();
  2598. /* Move the used descriptor pointer to the next descriptor */
  2599. mp->rx_used_desc_q = (used_rx_desc + 1) % mp->rx_ring_size;
  2600. /* Any Rx return cancels the Rx resource error status */
  2601. mp->rx_resource_err = 0;
  2602. spin_unlock_irqrestore(&mp->lock, flags);
  2603. return ETH_OK;
  2604. }
  2605. /************* Begin ethtool support *************************/
  2606. struct mv643xx_stats {
  2607. char stat_string[ETH_GSTRING_LEN];
  2608. int sizeof_stat;
  2609. int stat_offset;
  2610. };
  2611. #define MV643XX_STAT(m) sizeof(((struct mv643xx_private *)0)->m), \
  2612. offsetof(struct mv643xx_private, m)
  2613. static const struct mv643xx_stats mv643xx_gstrings_stats[] = {
  2614. { "rx_packets", MV643XX_STAT(stats.rx_packets) },
  2615. { "tx_packets", MV643XX_STAT(stats.tx_packets) },
  2616. { "rx_bytes", MV643XX_STAT(stats.rx_bytes) },
  2617. { "tx_bytes", MV643XX_STAT(stats.tx_bytes) },
  2618. { "rx_errors", MV643XX_STAT(stats.rx_errors) },
  2619. { "tx_errors", MV643XX_STAT(stats.tx_errors) },
  2620. { "rx_dropped", MV643XX_STAT(stats.rx_dropped) },
  2621. { "tx_dropped", MV643XX_STAT(stats.tx_dropped) },
  2622. { "good_octets_received", MV643XX_STAT(mib_counters.good_octets_received) },
  2623. { "bad_octets_received", MV643XX_STAT(mib_counters.bad_octets_received) },
  2624. { "internal_mac_transmit_err", MV643XX_STAT(mib_counters.internal_mac_transmit_err) },
  2625. { "good_frames_received", MV643XX_STAT(mib_counters.good_frames_received) },
  2626. { "bad_frames_received", MV643XX_STAT(mib_counters.bad_frames_received) },
  2627. { "broadcast_frames_received", MV643XX_STAT(mib_counters.broadcast_frames_received) },
  2628. { "multicast_frames_received", MV643XX_STAT(mib_counters.multicast_frames_received) },
  2629. { "frames_64_octets", MV643XX_STAT(mib_counters.frames_64_octets) },
  2630. { "frames_65_to_127_octets", MV643XX_STAT(mib_counters.frames_65_to_127_octets) },
  2631. { "frames_128_to_255_octets", MV643XX_STAT(mib_counters.frames_128_to_255_octets) },
  2632. { "frames_256_to_511_octets", MV643XX_STAT(mib_counters.frames_256_to_511_octets) },
  2633. { "frames_512_to_1023_octets", MV643XX_STAT(mib_counters.frames_512_to_1023_octets) },
  2634. { "frames_1024_to_max_octets", MV643XX_STAT(mib_counters.frames_1024_to_max_octets) },
  2635. { "good_octets_sent", MV643XX_STAT(mib_counters.good_octets_sent) },
  2636. { "good_frames_sent", MV643XX_STAT(mib_counters.good_frames_sent) },
  2637. { "excessive_collision", MV643XX_STAT(mib_counters.excessive_collision) },
  2638. { "multicast_frames_sent", MV643XX_STAT(mib_counters.multicast_frames_sent) },
  2639. { "broadcast_frames_sent", MV643XX_STAT(mib_counters.broadcast_frames_sent) },
  2640. { "unrec_mac_control_received", MV643XX_STAT(mib_counters.unrec_mac_control_received) },
  2641. { "fc_sent", MV643XX_STAT(mib_counters.fc_sent) },
  2642. { "good_fc_received", MV643XX_STAT(mib_counters.good_fc_received) },
  2643. { "bad_fc_received", MV643XX_STAT(mib_counters.bad_fc_received) },
  2644. { "undersize_received", MV643XX_STAT(mib_counters.undersize_received) },
  2645. { "fragments_received", MV643XX_STAT(mib_counters.fragments_received) },
  2646. { "oversize_received", MV643XX_STAT(mib_counters.oversize_received) },
  2647. { "jabber_received", MV643XX_STAT(mib_counters.jabber_received) },
  2648. { "mac_receive_error", MV643XX_STAT(mib_counters.mac_receive_error) },
  2649. { "bad_crc_event", MV643XX_STAT(mib_counters.bad_crc_event) },
  2650. { "collision", MV643XX_STAT(mib_counters.collision) },
  2651. { "late_collision", MV643XX_STAT(mib_counters.late_collision) },
  2652. };
  2653. #define MV643XX_STATS_LEN \
  2654. sizeof(mv643xx_gstrings_stats) / sizeof(struct mv643xx_stats)
  2655. static int
  2656. mv643xx_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  2657. {
  2658. struct mv643xx_private *mp = netdev->priv;
  2659. int port_num = mp->port_num;
  2660. int autoneg = eth_port_autoneg_supported(port_num);
  2661. int mode_10_bit;
  2662. int auto_duplex;
  2663. int half_duplex = 0;
  2664. int full_duplex = 0;
  2665. int auto_speed;
  2666. int speed_10 = 0;
  2667. int speed_100 = 0;
  2668. int speed_1000 = 0;
  2669. u32 pcs = mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num));
  2670. u32 psr = mv_read(MV643XX_ETH_PORT_STATUS_REG(port_num));
  2671. mode_10_bit = psr & MV643XX_ETH_PORT_STATUS_MODE_10_BIT;
  2672. if (mode_10_bit) {
  2673. ecmd->supported = SUPPORTED_10baseT_Half;
  2674. } else {
  2675. ecmd->supported = (SUPPORTED_10baseT_Half |
  2676. SUPPORTED_10baseT_Full |
  2677. SUPPORTED_100baseT_Half |
  2678. SUPPORTED_100baseT_Full |
  2679. SUPPORTED_1000baseT_Full |
  2680. (autoneg ? SUPPORTED_Autoneg : 0) |
  2681. SUPPORTED_TP);
  2682. auto_duplex = !(pcs & MV643XX_ETH_DISABLE_AUTO_NEG_FOR_DUPLX);
  2683. auto_speed = !(pcs & MV643XX_ETH_DISABLE_AUTO_NEG_SPEED_GMII);
  2684. ecmd->advertising = ADVERTISED_TP;
  2685. if (autoneg) {
  2686. ecmd->advertising |= ADVERTISED_Autoneg;
  2687. if (auto_duplex) {
  2688. half_duplex = 1;
  2689. full_duplex = 1;
  2690. } else {
  2691. if (pcs & MV643XX_ETH_SET_FULL_DUPLEX_MODE)
  2692. full_duplex = 1;
  2693. else
  2694. half_duplex = 1;
  2695. }
  2696. if (auto_speed) {
  2697. speed_10 = 1;
  2698. speed_100 = 1;
  2699. speed_1000 = 1;
  2700. } else {
  2701. if (pcs & MV643XX_ETH_SET_GMII_SPEED_TO_1000)
  2702. speed_1000 = 1;
  2703. else if (pcs & MV643XX_ETH_SET_MII_SPEED_TO_100)
  2704. speed_100 = 1;
  2705. else
  2706. speed_10 = 1;
  2707. }
  2708. if (speed_10 & half_duplex)
  2709. ecmd->advertising |= ADVERTISED_10baseT_Half;
  2710. if (speed_10 & full_duplex)
  2711. ecmd->advertising |= ADVERTISED_10baseT_Full;
  2712. if (speed_100 & half_duplex)
  2713. ecmd->advertising |= ADVERTISED_100baseT_Half;
  2714. if (speed_100 & full_duplex)
  2715. ecmd->advertising |= ADVERTISED_100baseT_Full;
  2716. if (speed_1000)
  2717. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  2718. }
  2719. }
  2720. ecmd->port = PORT_TP;
  2721. ecmd->phy_address = ethernet_phy_get(port_num);
  2722. ecmd->transceiver = XCVR_EXTERNAL;
  2723. if (netif_carrier_ok(netdev)) {
  2724. if (mode_10_bit)
  2725. ecmd->speed = SPEED_10;
  2726. else {
  2727. if (psr & MV643XX_ETH_PORT_STATUS_GMII_1000)
  2728. ecmd->speed = SPEED_1000;
  2729. else if (psr & MV643XX_ETH_PORT_STATUS_MII_100)
  2730. ecmd->speed = SPEED_100;
  2731. else
  2732. ecmd->speed = SPEED_10;
  2733. }
  2734. if (psr & MV643XX_ETH_PORT_STATUS_FULL_DUPLEX)
  2735. ecmd->duplex = DUPLEX_FULL;
  2736. else
  2737. ecmd->duplex = DUPLEX_HALF;
  2738. } else {
  2739. ecmd->speed = -1;
  2740. ecmd->duplex = -1;
  2741. }
  2742. ecmd->autoneg = autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  2743. return 0;
  2744. }
  2745. static void
  2746. mv643xx_get_drvinfo(struct net_device *netdev,
  2747. struct ethtool_drvinfo *drvinfo)
  2748. {
  2749. strncpy(drvinfo->driver, mv643xx_driver_name, 32);
  2750. strncpy(drvinfo->version, mv643xx_driver_version, 32);
  2751. strncpy(drvinfo->fw_version, "N/A", 32);
  2752. strncpy(drvinfo->bus_info, "mv643xx", 32);
  2753. drvinfo->n_stats = MV643XX_STATS_LEN;
  2754. }
  2755. static int
  2756. mv643xx_get_stats_count(struct net_device *netdev)
  2757. {
  2758. return MV643XX_STATS_LEN;
  2759. }
  2760. static void
  2761. mv643xx_get_ethtool_stats(struct net_device *netdev,
  2762. struct ethtool_stats *stats, uint64_t *data)
  2763. {
  2764. struct mv643xx_private *mp = netdev->priv;
  2765. int i;
  2766. eth_update_mib_counters(mp);
  2767. for(i = 0; i < MV643XX_STATS_LEN; i++) {
  2768. char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset;
  2769. data[i] = (mv643xx_gstrings_stats[i].sizeof_stat ==
  2770. sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
  2771. }
  2772. }
  2773. static void
  2774. mv643xx_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
  2775. {
  2776. int i;
  2777. switch(stringset) {
  2778. case ETH_SS_STATS:
  2779. for (i=0; i < MV643XX_STATS_LEN; i++) {
  2780. memcpy(data + i * ETH_GSTRING_LEN,
  2781. mv643xx_gstrings_stats[i].stat_string,
  2782. ETH_GSTRING_LEN);
  2783. }
  2784. break;
  2785. }
  2786. }
  2787. static struct ethtool_ops mv643xx_ethtool_ops = {
  2788. .get_settings = mv643xx_get_settings,
  2789. .get_drvinfo = mv643xx_get_drvinfo,
  2790. .get_link = ethtool_op_get_link,
  2791. .get_sg = ethtool_op_get_sg,
  2792. .set_sg = ethtool_op_set_sg,
  2793. .get_strings = mv643xx_get_strings,
  2794. .get_stats_count = mv643xx_get_stats_count,
  2795. .get_ethtool_stats = mv643xx_get_ethtool_stats,
  2796. };
  2797. /************* End ethtool support *************************/