mv643xx_eth.c 93 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239
  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->protocol == ETH_P_IP) &&
  1013. (skb->nh.iph->protocol == IPPROTO_UDP) ) {
  1014. pkt_info.cmd_sts |= ETH_UDP_FRAME;
  1015. pkt_info.l4i_chk = skb->h.uh->check;
  1016. } else if ((skb->protocol == ETH_P_IP) &&
  1017. (skb->nh.iph->protocol == IPPROTO_TCP))
  1018. pkt_info.l4i_chk = skb->h.th->check;
  1019. else {
  1020. printk(KERN_ERR
  1021. "%s: chksum proto != IPv4 TCP or UDP\n",
  1022. dev->name);
  1023. spin_unlock_irqrestore(&mp->lock, flags);
  1024. return 1;
  1025. }
  1026. }
  1027. pkt_info.byte_cnt = skb->len;
  1028. pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
  1029. DMA_TO_DEVICE);
  1030. pkt_info.return_info = skb;
  1031. status = eth_port_send(mp, &pkt_info);
  1032. if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
  1033. printk(KERN_ERR "%s: Error on transmitting packet\n",
  1034. dev->name);
  1035. stats->tx_bytes += pkt_info.byte_cnt;
  1036. } else {
  1037. unsigned int frag;
  1038. /* first frag which is skb header */
  1039. pkt_info.byte_cnt = skb_headlen(skb);
  1040. pkt_info.buf_ptr = dma_map_single(NULL, skb->data,
  1041. skb_headlen(skb),
  1042. DMA_TO_DEVICE);
  1043. pkt_info.l4i_chk = 0;
  1044. pkt_info.return_info = 0;
  1045. if (skb->ip_summed != CHECKSUM_HW)
  1046. /* Errata BTS #50, IHL must be 5 if no HW checksum */
  1047. pkt_info.cmd_sts = ETH_TX_FIRST_DESC |
  1048. 5 << ETH_TX_IHL_SHIFT;
  1049. else {
  1050. pkt_info.cmd_sts = ETH_TX_FIRST_DESC |
  1051. ETH_GEN_TCP_UDP_CHECKSUM |
  1052. ETH_GEN_IP_V_4_CHECKSUM |
  1053. skb->nh.iph->ihl << ETH_TX_IHL_SHIFT;
  1054. /* CPU already calculated pseudo header checksum. */
  1055. if ((skb->protocol == ETH_P_IP) &&
  1056. (skb->nh.iph->protocol == IPPROTO_UDP)) {
  1057. pkt_info.cmd_sts |= ETH_UDP_FRAME;
  1058. pkt_info.l4i_chk = skb->h.uh->check;
  1059. } else if ((skb->protocol == ETH_P_IP) &&
  1060. (skb->nh.iph->protocol == IPPROTO_TCP))
  1061. pkt_info.l4i_chk = skb->h.th->check;
  1062. else {
  1063. printk(KERN_ERR
  1064. "%s: chksum proto != IPv4 TCP or UDP\n",
  1065. dev->name);
  1066. spin_unlock_irqrestore(&mp->lock, flags);
  1067. return 1;
  1068. }
  1069. }
  1070. status = eth_port_send(mp, &pkt_info);
  1071. if (status != ETH_OK) {
  1072. if ((status == ETH_ERROR))
  1073. printk(KERN_ERR
  1074. "%s: Error on transmitting packet\n",
  1075. dev->name);
  1076. if (status == ETH_QUEUE_FULL)
  1077. printk("Error on Queue Full \n");
  1078. if (status == ETH_QUEUE_LAST_RESOURCE)
  1079. printk("Tx resource error \n");
  1080. }
  1081. stats->tx_bytes += pkt_info.byte_cnt;
  1082. /* Check for the remaining frags */
  1083. for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
  1084. skb_frag_t *this_frag = &skb_shinfo(skb)->frags[frag];
  1085. pkt_info.l4i_chk = 0x0000;
  1086. pkt_info.cmd_sts = 0x00000000;
  1087. /* Last Frag enables interrupt and frees the skb */
  1088. if (frag == (skb_shinfo(skb)->nr_frags - 1)) {
  1089. pkt_info.cmd_sts |= ETH_TX_ENABLE_INTERRUPT |
  1090. ETH_TX_LAST_DESC;
  1091. pkt_info.return_info = skb;
  1092. } else {
  1093. pkt_info.return_info = 0;
  1094. }
  1095. pkt_info.l4i_chk = 0;
  1096. pkt_info.byte_cnt = this_frag->size;
  1097. pkt_info.buf_ptr = dma_map_page(NULL, this_frag->page,
  1098. this_frag->page_offset,
  1099. this_frag->size,
  1100. DMA_TO_DEVICE);
  1101. status = eth_port_send(mp, &pkt_info);
  1102. if (status != ETH_OK) {
  1103. if ((status == ETH_ERROR))
  1104. printk(KERN_ERR "%s: Error on "
  1105. "transmitting packet\n",
  1106. dev->name);
  1107. if (status == ETH_QUEUE_LAST_RESOURCE)
  1108. printk("Tx resource error \n");
  1109. if (status == ETH_QUEUE_FULL)
  1110. printk("Queue is full \n");
  1111. }
  1112. stats->tx_bytes += pkt_info.byte_cnt;
  1113. }
  1114. }
  1115. #else
  1116. spin_lock_irqsave(&mp->lock, flags);
  1117. pkt_info.cmd_sts = ETH_TX_ENABLE_INTERRUPT | ETH_TX_FIRST_DESC |
  1118. ETH_TX_LAST_DESC;
  1119. pkt_info.l4i_chk = 0;
  1120. pkt_info.byte_cnt = skb->len;
  1121. pkt_info.buf_ptr = dma_map_single(NULL, skb->data, skb->len,
  1122. DMA_TO_DEVICE);
  1123. pkt_info.return_info = skb;
  1124. status = eth_port_send(mp, &pkt_info);
  1125. if ((status == ETH_ERROR) || (status == ETH_QUEUE_FULL))
  1126. printk(KERN_ERR "%s: Error on transmitting packet\n",
  1127. dev->name);
  1128. stats->tx_bytes += pkt_info.byte_cnt;
  1129. #endif
  1130. /* Check if TX queue can handle another skb. If not, then
  1131. * signal higher layers to stop requesting TX
  1132. */
  1133. if (mp->tx_ring_size <= (mp->tx_ring_skbs + MAX_DESCS_PER_SKB))
  1134. /*
  1135. * Stop getting skb's from upper layers.
  1136. * Getting skb's from upper layers will be enabled again after
  1137. * packets are released.
  1138. */
  1139. netif_stop_queue(dev);
  1140. /* Update statistics and start of transmittion time */
  1141. stats->tx_packets++;
  1142. dev->trans_start = jiffies;
  1143. spin_unlock_irqrestore(&mp->lock, flags);
  1144. return 0; /* success */
  1145. }
  1146. /*
  1147. * mv643xx_eth_get_stats
  1148. *
  1149. * Returns a pointer to the interface statistics.
  1150. *
  1151. * Input : dev - a pointer to the required interface
  1152. *
  1153. * Output : a pointer to the interface's statistics
  1154. */
  1155. static struct net_device_stats *mv643xx_eth_get_stats(struct net_device *dev)
  1156. {
  1157. struct mv643xx_private *mp = netdev_priv(dev);
  1158. return &mp->stats;
  1159. }
  1160. #ifdef CONFIG_NET_POLL_CONTROLLER
  1161. static inline void mv643xx_enable_irq(struct mv643xx_private *mp)
  1162. {
  1163. int port_num = mp->port_num;
  1164. unsigned long flags;
  1165. spin_lock_irqsave(&mp->lock, flags);
  1166. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  1167. INT_CAUSE_UNMASK_ALL);
  1168. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
  1169. INT_CAUSE_UNMASK_ALL_EXT);
  1170. spin_unlock_irqrestore(&mp->lock, flags);
  1171. }
  1172. static inline void mv643xx_disable_irq(struct mv643xx_private *mp)
  1173. {
  1174. int port_num = mp->port_num;
  1175. unsigned long flags;
  1176. spin_lock_irqsave(&mp->lock, flags);
  1177. mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
  1178. INT_CAUSE_MASK_ALL);
  1179. mv_write(MV643XX_ETH_INTERRUPT_EXTEND_MASK_REG(port_num),
  1180. INT_CAUSE_MASK_ALL_EXT);
  1181. spin_unlock_irqrestore(&mp->lock, flags);
  1182. }
  1183. static void mv643xx_netpoll(struct net_device *netdev)
  1184. {
  1185. struct mv643xx_private *mp = netdev_priv(netdev);
  1186. mv643xx_disable_irq(mp);
  1187. mv643xx_eth_int_handler(netdev->irq, netdev, NULL);
  1188. mv643xx_enable_irq(mp);
  1189. }
  1190. #endif
  1191. /*/
  1192. * mv643xx_eth_probe
  1193. *
  1194. * First function called after registering the network device.
  1195. * It's purpose is to initialize the device as an ethernet device,
  1196. * fill the ethernet device structure with pointers * to functions,
  1197. * and set the MAC address of the interface
  1198. *
  1199. * Input : struct device *
  1200. * Output : -ENOMEM if failed , 0 if success
  1201. */
  1202. static int mv643xx_eth_probe(struct platform_device *pdev)
  1203. {
  1204. struct mv643xx_eth_platform_data *pd;
  1205. int port_num = pdev->id;
  1206. struct mv643xx_private *mp;
  1207. struct net_device *dev;
  1208. u8 *p;
  1209. struct resource *res;
  1210. int err;
  1211. dev = alloc_etherdev(sizeof(struct mv643xx_private));
  1212. if (!dev)
  1213. return -ENOMEM;
  1214. platform_set_drvdata(pdev, dev);
  1215. mp = netdev_priv(dev);
  1216. res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  1217. BUG_ON(!res);
  1218. dev->irq = res->start;
  1219. mp->port_num = port_num;
  1220. dev->open = mv643xx_eth_open;
  1221. dev->stop = mv643xx_eth_stop;
  1222. dev->hard_start_xmit = mv643xx_eth_start_xmit;
  1223. dev->get_stats = mv643xx_eth_get_stats;
  1224. dev->set_mac_address = mv643xx_eth_set_mac_address;
  1225. dev->set_multicast_list = mv643xx_eth_set_rx_mode;
  1226. /* No need to Tx Timeout */
  1227. dev->tx_timeout = mv643xx_eth_tx_timeout;
  1228. #ifdef MV643XX_NAPI
  1229. dev->poll = mv643xx_poll;
  1230. dev->weight = 64;
  1231. #endif
  1232. #ifdef CONFIG_NET_POLL_CONTROLLER
  1233. dev->poll_controller = mv643xx_netpoll;
  1234. #endif
  1235. dev->watchdog_timeo = 2 * HZ;
  1236. dev->tx_queue_len = mp->tx_ring_size;
  1237. dev->base_addr = 0;
  1238. dev->change_mtu = mv643xx_eth_change_mtu;
  1239. SET_ETHTOOL_OPS(dev, &mv643xx_ethtool_ops);
  1240. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  1241. #ifdef MAX_SKB_FRAGS
  1242. /*
  1243. * Zero copy can only work if we use Discovery II memory. Else, we will
  1244. * have to map the buffers to ISA memory which is only 16 MB
  1245. */
  1246. dev->features = NETIF_F_SG | NETIF_F_IP_CSUM;
  1247. #endif
  1248. #endif
  1249. /* Configure the timeout task */
  1250. INIT_WORK(&mp->tx_timeout_task,
  1251. (void (*)(void *))mv643xx_eth_tx_timeout_task, dev);
  1252. spin_lock_init(&mp->lock);
  1253. /* set default config values */
  1254. eth_port_uc_addr_get(dev, dev->dev_addr);
  1255. mp->port_config = MV643XX_ETH_PORT_CONFIG_DEFAULT_VALUE;
  1256. mp->port_config_extend = MV643XX_ETH_PORT_CONFIG_EXTEND_DEFAULT_VALUE;
  1257. mp->port_sdma_config = MV643XX_ETH_PORT_SDMA_CONFIG_DEFAULT_VALUE;
  1258. mp->port_serial_control = MV643XX_ETH_PORT_SERIAL_CONTROL_DEFAULT_VALUE;
  1259. mp->rx_ring_size = MV643XX_ETH_PORT_DEFAULT_RECEIVE_QUEUE_SIZE;
  1260. mp->tx_ring_size = MV643XX_ETH_PORT_DEFAULT_TRANSMIT_QUEUE_SIZE;
  1261. pd = pdev->dev.platform_data;
  1262. if (pd) {
  1263. if (pd->mac_addr != NULL)
  1264. memcpy(dev->dev_addr, pd->mac_addr, 6);
  1265. if (pd->phy_addr || pd->force_phy_addr)
  1266. ethernet_phy_set(port_num, pd->phy_addr);
  1267. if (pd->port_config || pd->force_port_config)
  1268. mp->port_config = pd->port_config;
  1269. if (pd->port_config_extend || pd->force_port_config_extend)
  1270. mp->port_config_extend = pd->port_config_extend;
  1271. if (pd->port_sdma_config || pd->force_port_sdma_config)
  1272. mp->port_sdma_config = pd->port_sdma_config;
  1273. if (pd->port_serial_control || pd->force_port_serial_control)
  1274. mp->port_serial_control = pd->port_serial_control;
  1275. if (pd->rx_queue_size)
  1276. mp->rx_ring_size = pd->rx_queue_size;
  1277. if (pd->tx_queue_size)
  1278. mp->tx_ring_size = pd->tx_queue_size;
  1279. if (pd->tx_sram_size) {
  1280. mp->tx_sram_size = pd->tx_sram_size;
  1281. mp->tx_sram_addr = pd->tx_sram_addr;
  1282. }
  1283. if (pd->rx_sram_size) {
  1284. mp->rx_sram_size = pd->rx_sram_size;
  1285. mp->rx_sram_addr = pd->rx_sram_addr;
  1286. }
  1287. }
  1288. err = ethernet_phy_detect(port_num);
  1289. if (err) {
  1290. pr_debug("MV643xx ethernet port %d: "
  1291. "No PHY detected at addr %d\n",
  1292. port_num, ethernet_phy_get(port_num));
  1293. return err;
  1294. }
  1295. err = register_netdev(dev);
  1296. if (err)
  1297. goto out;
  1298. p = dev->dev_addr;
  1299. printk(KERN_NOTICE
  1300. "%s: port %d with MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
  1301. dev->name, port_num, p[0], p[1], p[2], p[3], p[4], p[5]);
  1302. if (dev->features & NETIF_F_SG)
  1303. printk(KERN_NOTICE "%s: Scatter Gather Enabled\n", dev->name);
  1304. if (dev->features & NETIF_F_IP_CSUM)
  1305. printk(KERN_NOTICE "%s: TX TCP/IP Checksumming Supported\n",
  1306. dev->name);
  1307. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  1308. printk(KERN_NOTICE "%s: RX TCP/UDP Checksum Offload ON \n", dev->name);
  1309. #endif
  1310. #ifdef MV643XX_COAL
  1311. printk(KERN_NOTICE "%s: TX and RX Interrupt Coalescing ON \n",
  1312. dev->name);
  1313. #endif
  1314. #ifdef MV643XX_NAPI
  1315. printk(KERN_NOTICE "%s: RX NAPI Enabled \n", dev->name);
  1316. #endif
  1317. if (mp->tx_sram_size > 0)
  1318. printk(KERN_NOTICE "%s: Using SRAM\n", dev->name);
  1319. return 0;
  1320. out:
  1321. free_netdev(dev);
  1322. return err;
  1323. }
  1324. static int mv643xx_eth_remove(struct platform_device *pdev)
  1325. {
  1326. struct net_device *dev = platform_get_drvdata(pdev);
  1327. unregister_netdev(dev);
  1328. flush_scheduled_work();
  1329. free_netdev(dev);
  1330. platform_set_drvdata(pdev, NULL);
  1331. return 0;
  1332. }
  1333. static int mv643xx_eth_shared_probe(struct platform_device *pdev)
  1334. {
  1335. struct resource *res;
  1336. printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n");
  1337. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1338. if (res == NULL)
  1339. return -ENODEV;
  1340. mv643xx_eth_shared_base = ioremap(res->start,
  1341. MV643XX_ETH_SHARED_REGS_SIZE);
  1342. if (mv643xx_eth_shared_base == NULL)
  1343. return -ENOMEM;
  1344. return 0;
  1345. }
  1346. static int mv643xx_eth_shared_remove(struct platform_device *pdev)
  1347. {
  1348. iounmap(mv643xx_eth_shared_base);
  1349. mv643xx_eth_shared_base = NULL;
  1350. return 0;
  1351. }
  1352. static struct platform_driver mv643xx_eth_driver = {
  1353. .probe = mv643xx_eth_probe,
  1354. .remove = mv643xx_eth_remove,
  1355. .driver = {
  1356. .name = MV643XX_ETH_NAME,
  1357. },
  1358. };
  1359. static struct platform_driver mv643xx_eth_shared_driver = {
  1360. .probe = mv643xx_eth_shared_probe,
  1361. .remove = mv643xx_eth_shared_remove,
  1362. .driver = {
  1363. .name = MV643XX_ETH_SHARED_NAME,
  1364. },
  1365. };
  1366. /*
  1367. * mv643xx_init_module
  1368. *
  1369. * Registers the network drivers into the Linux kernel
  1370. *
  1371. * Input : N/A
  1372. *
  1373. * Output : N/A
  1374. */
  1375. static int __init mv643xx_init_module(void)
  1376. {
  1377. int rc;
  1378. rc = platform_driver_register(&mv643xx_eth_shared_driver);
  1379. if (!rc) {
  1380. rc = platform_driver_register(&mv643xx_eth_driver);
  1381. if (rc)
  1382. platform_driver_unregister(&mv643xx_eth_shared_driver);
  1383. }
  1384. return rc;
  1385. }
  1386. /*
  1387. * mv643xx_cleanup_module
  1388. *
  1389. * Registers the network drivers into the Linux kernel
  1390. *
  1391. * Input : N/A
  1392. *
  1393. * Output : N/A
  1394. */
  1395. static void __exit mv643xx_cleanup_module(void)
  1396. {
  1397. platform_driver_unregister(&mv643xx_eth_driver);
  1398. platform_driver_unregister(&mv643xx_eth_shared_driver);
  1399. }
  1400. module_init(mv643xx_init_module);
  1401. module_exit(mv643xx_cleanup_module);
  1402. MODULE_LICENSE("GPL");
  1403. MODULE_AUTHOR( "Rabeeh Khoury, Assaf Hoffman, Matthew Dharm, Manish Lachwani"
  1404. " and Dale Farnsworth");
  1405. MODULE_DESCRIPTION("Ethernet driver for Marvell MV643XX");
  1406. /*
  1407. * The second part is the low level driver of the gigE ethernet ports.
  1408. */
  1409. /*
  1410. * Marvell's Gigabit Ethernet controller low level driver
  1411. *
  1412. * DESCRIPTION:
  1413. * This file introduce low level API to Marvell's Gigabit Ethernet
  1414. * controller. This Gigabit Ethernet Controller driver API controls
  1415. * 1) Operations (i.e. port init, start, reset etc').
  1416. * 2) Data flow (i.e. port send, receive etc').
  1417. * Each Gigabit Ethernet port is controlled via
  1418. * struct mv643xx_private.
  1419. * This struct includes user configuration information as well as
  1420. * driver internal data needed for its operations.
  1421. *
  1422. * Supported Features:
  1423. * - This low level driver is OS independent. Allocating memory for
  1424. * the descriptor rings and buffers are not within the scope of
  1425. * this driver.
  1426. * - The user is free from Rx/Tx queue managing.
  1427. * - This low level driver introduce functionality API that enable
  1428. * the to operate Marvell's Gigabit Ethernet Controller in a
  1429. * convenient way.
  1430. * - Simple Gigabit Ethernet port operation API.
  1431. * - Simple Gigabit Ethernet port data flow API.
  1432. * - Data flow and operation API support per queue functionality.
  1433. * - Support cached descriptors for better performance.
  1434. * - Enable access to all four DRAM banks and internal SRAM memory
  1435. * spaces.
  1436. * - PHY access and control API.
  1437. * - Port control register configuration API.
  1438. * - Full control over Unicast and Multicast MAC configurations.
  1439. *
  1440. * Operation flow:
  1441. *
  1442. * Initialization phase
  1443. * This phase complete the initialization of the the
  1444. * mv643xx_private struct.
  1445. * User information regarding port configuration has to be set
  1446. * prior to calling the port initialization routine.
  1447. *
  1448. * In this phase any port Tx/Rx activity is halted, MIB counters
  1449. * are cleared, PHY address is set according to user parameter and
  1450. * access to DRAM and internal SRAM memory spaces.
  1451. *
  1452. * Driver ring initialization
  1453. * Allocating memory for the descriptor rings and buffers is not
  1454. * within the scope of this driver. Thus, the user is required to
  1455. * allocate memory for the descriptors ring and buffers. Those
  1456. * memory parameters are used by the Rx and Tx ring initialization
  1457. * routines in order to curve the descriptor linked list in a form
  1458. * of a ring.
  1459. * Note: Pay special attention to alignment issues when using
  1460. * cached descriptors/buffers. In this phase the driver store
  1461. * information in the mv643xx_private struct regarding each queue
  1462. * ring.
  1463. *
  1464. * Driver start
  1465. * This phase prepares the Ethernet port for Rx and Tx activity.
  1466. * It uses the information stored in the mv643xx_private struct to
  1467. * initialize the various port registers.
  1468. *
  1469. * Data flow:
  1470. * All packet references to/from the driver are done using
  1471. * struct pkt_info.
  1472. * This struct is a unified struct used with Rx and Tx operations.
  1473. * This way the user is not required to be familiar with neither
  1474. * Tx nor Rx descriptors structures.
  1475. * The driver's descriptors rings are management by indexes.
  1476. * Those indexes controls the ring resources and used to indicate
  1477. * a SW resource error:
  1478. * 'current'
  1479. * This index points to the current available resource for use. For
  1480. * example in Rx process this index will point to the descriptor
  1481. * that will be passed to the user upon calling the receive
  1482. * routine. In Tx process, this index will point to the descriptor
  1483. * that will be assigned with the user packet info and transmitted.
  1484. * 'used'
  1485. * This index points to the descriptor that need to restore its
  1486. * resources. For example in Rx process, using the Rx buffer return
  1487. * API will attach the buffer returned in packet info to the
  1488. * descriptor pointed by 'used'. In Tx process, using the Tx
  1489. * descriptor return will merely return the user packet info with
  1490. * the command status of the transmitted buffer pointed by the
  1491. * 'used' index. Nevertheless, it is essential to use this routine
  1492. * to update the 'used' index.
  1493. * 'first'
  1494. * This index supports Tx Scatter-Gather. It points to the first
  1495. * descriptor of a packet assembled of multiple buffers. For
  1496. * example when in middle of Such packet we have a Tx resource
  1497. * error the 'curr' index get the value of 'first' to indicate
  1498. * that the ring returned to its state before trying to transmit
  1499. * this packet.
  1500. *
  1501. * Receive operation:
  1502. * The eth_port_receive API set the packet information struct,
  1503. * passed by the caller, with received information from the
  1504. * 'current' SDMA descriptor.
  1505. * It is the user responsibility to return this resource back
  1506. * to the Rx descriptor ring to enable the reuse of this source.
  1507. * Return Rx resource is done using the eth_rx_return_buff API.
  1508. *
  1509. * Transmit operation:
  1510. * The eth_port_send API supports Scatter-Gather which enables to
  1511. * send a packet spanned over multiple buffers. This means that
  1512. * for each packet info structure given by the user and put into
  1513. * the Tx descriptors ring, will be transmitted only if the 'LAST'
  1514. * bit will be set in the packet info command status field. This
  1515. * API also consider restriction regarding buffer alignments and
  1516. * sizes.
  1517. * The user must return a Tx resource after ensuring the buffer
  1518. * has been transmitted to enable the Tx ring indexes to update.
  1519. *
  1520. * BOARD LAYOUT
  1521. * This device is on-board. No jumper diagram is necessary.
  1522. *
  1523. * EXTERNAL INTERFACE
  1524. *
  1525. * Prior to calling the initialization routine eth_port_init() the user
  1526. * must set the following fields under mv643xx_private struct:
  1527. * port_num User Ethernet port number.
  1528. * port_mac_addr[6] User defined port MAC address.
  1529. * port_config User port configuration value.
  1530. * port_config_extend User port config extend value.
  1531. * port_sdma_config User port SDMA config value.
  1532. * port_serial_control User port serial control value.
  1533. *
  1534. * This driver data flow is done using the struct pkt_info which
  1535. * is a unified struct for Rx and Tx operations:
  1536. *
  1537. * byte_cnt Tx/Rx descriptor buffer byte count.
  1538. * l4i_chk CPU provided TCP Checksum. For Tx operation
  1539. * only.
  1540. * cmd_sts Tx/Rx descriptor command status.
  1541. * buf_ptr Tx/Rx descriptor buffer pointer.
  1542. * return_info Tx/Rx user resource return information.
  1543. */
  1544. /* defines */
  1545. /* SDMA command macros */
  1546. #define ETH_ENABLE_TX_QUEUE(eth_port) \
  1547. mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(eth_port), 1)
  1548. /* locals */
  1549. /* PHY routines */
  1550. static int ethernet_phy_get(unsigned int eth_port_num);
  1551. static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr);
  1552. /* Ethernet Port routines */
  1553. static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
  1554. int option);
  1555. /*
  1556. * eth_port_init - Initialize the Ethernet port driver
  1557. *
  1558. * DESCRIPTION:
  1559. * This function prepares the ethernet port to start its activity:
  1560. * 1) Completes the ethernet port driver struct initialization toward port
  1561. * start routine.
  1562. * 2) Resets the device to a quiescent state in case of warm reboot.
  1563. * 3) Enable SDMA access to all four DRAM banks as well as internal SRAM.
  1564. * 4) Clean MAC tables. The reset status of those tables is unknown.
  1565. * 5) Set PHY address.
  1566. * Note: Call this routine prior to eth_port_start routine and after
  1567. * setting user values in the user fields of Ethernet port control
  1568. * struct.
  1569. *
  1570. * INPUT:
  1571. * struct mv643xx_private *mp Ethernet port control struct
  1572. *
  1573. * OUTPUT:
  1574. * See description.
  1575. *
  1576. * RETURN:
  1577. * None.
  1578. */
  1579. static void eth_port_init(struct mv643xx_private *mp)
  1580. {
  1581. mp->port_rx_queue_command = 0;
  1582. mp->port_tx_queue_command = 0;
  1583. mp->rx_resource_err = 0;
  1584. mp->tx_resource_err = 0;
  1585. eth_port_reset(mp->port_num);
  1586. eth_port_init_mac_tables(mp->port_num);
  1587. ethernet_phy_reset(mp->port_num);
  1588. }
  1589. /*
  1590. * eth_port_start - Start the Ethernet port activity.
  1591. *
  1592. * DESCRIPTION:
  1593. * This routine prepares the Ethernet port for Rx and Tx activity:
  1594. * 1. Initialize Tx and Rx Current Descriptor Pointer for each queue that
  1595. * has been initialized a descriptor's ring (using
  1596. * ether_init_tx_desc_ring for Tx and ether_init_rx_desc_ring for Rx)
  1597. * 2. Initialize and enable the Ethernet configuration port by writing to
  1598. * the port's configuration and command registers.
  1599. * 3. Initialize and enable the SDMA by writing to the SDMA's
  1600. * configuration and command registers. After completing these steps,
  1601. * the ethernet port SDMA can starts to perform Rx and Tx activities.
  1602. *
  1603. * Note: Each Rx and Tx queue descriptor's list must be initialized prior
  1604. * to calling this function (use ether_init_tx_desc_ring for Tx queues
  1605. * and ether_init_rx_desc_ring for Rx queues).
  1606. *
  1607. * INPUT:
  1608. * struct mv643xx_private *mp Ethernet port control struct
  1609. *
  1610. * OUTPUT:
  1611. * Ethernet port is ready to receive and transmit.
  1612. *
  1613. * RETURN:
  1614. * None.
  1615. */
  1616. static void eth_port_start(struct mv643xx_private *mp)
  1617. {
  1618. unsigned int port_num = mp->port_num;
  1619. int tx_curr_desc, rx_curr_desc;
  1620. /* Assignment of Tx CTRP of given queue */
  1621. tx_curr_desc = mp->tx_curr_desc_q;
  1622. mv_write(MV643XX_ETH_TX_CURRENT_QUEUE_DESC_PTR_0(port_num),
  1623. (u32)((struct eth_tx_desc *)mp->tx_desc_dma + tx_curr_desc));
  1624. /* Assignment of Rx CRDP of given queue */
  1625. rx_curr_desc = mp->rx_curr_desc_q;
  1626. mv_write(MV643XX_ETH_RX_CURRENT_QUEUE_DESC_PTR_0(port_num),
  1627. (u32)((struct eth_rx_desc *)mp->rx_desc_dma + rx_curr_desc));
  1628. /* Add the assigned Ethernet address to the port's address table */
  1629. eth_port_uc_addr_set(port_num, mp->port_mac_addr);
  1630. /* Assign port configuration and command. */
  1631. mv_write(MV643XX_ETH_PORT_CONFIG_REG(port_num), mp->port_config);
  1632. mv_write(MV643XX_ETH_PORT_CONFIG_EXTEND_REG(port_num),
  1633. mp->port_config_extend);
  1634. /* Increase the Rx side buffer size if supporting GigE */
  1635. if (mp->port_serial_control & MV643XX_ETH_SET_GMII_SPEED_TO_1000)
  1636. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
  1637. (mp->port_serial_control & 0xfff1ffff) | (0x5 << 17));
  1638. else
  1639. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
  1640. mp->port_serial_control);
  1641. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num),
  1642. mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num)) |
  1643. MV643XX_ETH_SERIAL_PORT_ENABLE);
  1644. /* Assign port SDMA configuration */
  1645. mv_write(MV643XX_ETH_SDMA_CONFIG_REG(port_num),
  1646. mp->port_sdma_config);
  1647. /* Enable port Rx. */
  1648. mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
  1649. mp->port_rx_queue_command);
  1650. /* Disable port bandwidth limits by clearing MTU register */
  1651. mv_write(MV643XX_ETH_MAXIMUM_TRANSMIT_UNIT(port_num), 0);
  1652. }
  1653. /*
  1654. * eth_port_uc_addr_set - This function Set the port Unicast address.
  1655. *
  1656. * DESCRIPTION:
  1657. * This function Set the port Ethernet MAC address.
  1658. *
  1659. * INPUT:
  1660. * unsigned int eth_port_num Port number.
  1661. * char * p_addr Address to be set
  1662. *
  1663. * OUTPUT:
  1664. * Set MAC address low and high registers. also calls eth_port_uc_addr()
  1665. * To set the unicast table with the proper information.
  1666. *
  1667. * RETURN:
  1668. * N/A.
  1669. *
  1670. */
  1671. static void eth_port_uc_addr_set(unsigned int eth_port_num,
  1672. unsigned char *p_addr)
  1673. {
  1674. unsigned int mac_h;
  1675. unsigned int mac_l;
  1676. mac_l = (p_addr[4] << 8) | (p_addr[5]);
  1677. mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
  1678. (p_addr[3] << 0);
  1679. mv_write(MV643XX_ETH_MAC_ADDR_LOW(eth_port_num), mac_l);
  1680. mv_write(MV643XX_ETH_MAC_ADDR_HIGH(eth_port_num), mac_h);
  1681. /* Accept frames of this address */
  1682. eth_port_uc_addr(eth_port_num, p_addr[5], ACCEPT_MAC_ADDR);
  1683. return;
  1684. }
  1685. /*
  1686. * eth_port_uc_addr_get - This function retrieves the port Unicast address
  1687. * (MAC address) from the ethernet hw registers.
  1688. *
  1689. * DESCRIPTION:
  1690. * This function retrieves the port Ethernet MAC address.
  1691. *
  1692. * INPUT:
  1693. * unsigned int eth_port_num Port number.
  1694. * char *MacAddr pointer where the MAC address is stored
  1695. *
  1696. * OUTPUT:
  1697. * Copy the MAC address to the location pointed to by MacAddr
  1698. *
  1699. * RETURN:
  1700. * N/A.
  1701. *
  1702. */
  1703. static void eth_port_uc_addr_get(struct net_device *dev, unsigned char *p_addr)
  1704. {
  1705. struct mv643xx_private *mp = netdev_priv(dev);
  1706. unsigned int mac_h;
  1707. unsigned int mac_l;
  1708. mac_h = mv_read(MV643XX_ETH_MAC_ADDR_HIGH(mp->port_num));
  1709. mac_l = mv_read(MV643XX_ETH_MAC_ADDR_LOW(mp->port_num));
  1710. p_addr[0] = (mac_h >> 24) & 0xff;
  1711. p_addr[1] = (mac_h >> 16) & 0xff;
  1712. p_addr[2] = (mac_h >> 8) & 0xff;
  1713. p_addr[3] = mac_h & 0xff;
  1714. p_addr[4] = (mac_l >> 8) & 0xff;
  1715. p_addr[5] = mac_l & 0xff;
  1716. }
  1717. /*
  1718. * eth_port_uc_addr - This function Set the port unicast address table
  1719. *
  1720. * DESCRIPTION:
  1721. * This function locates the proper entry in the Unicast table for the
  1722. * specified MAC nibble and sets its properties according to function
  1723. * parameters.
  1724. *
  1725. * INPUT:
  1726. * unsigned int eth_port_num Port number.
  1727. * unsigned char uc_nibble Unicast MAC Address last nibble.
  1728. * int option 0 = Add, 1 = remove address.
  1729. *
  1730. * OUTPUT:
  1731. * This function add/removes MAC addresses from the port unicast address
  1732. * table.
  1733. *
  1734. * RETURN:
  1735. * true is output succeeded.
  1736. * false if option parameter is invalid.
  1737. *
  1738. */
  1739. static int eth_port_uc_addr(unsigned int eth_port_num, unsigned char uc_nibble,
  1740. int option)
  1741. {
  1742. unsigned int unicast_reg;
  1743. unsigned int tbl_offset;
  1744. unsigned int reg_offset;
  1745. /* Locate the Unicast table entry */
  1746. uc_nibble = (0xf & uc_nibble);
  1747. tbl_offset = (uc_nibble / 4) * 4; /* Register offset from unicast table base */
  1748. reg_offset = uc_nibble % 4; /* Entry offset within the above register */
  1749. switch (option) {
  1750. case REJECT_MAC_ADDR:
  1751. /* Clear accepts frame bit at given unicast DA table entry */
  1752. unicast_reg = mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1753. (eth_port_num) + tbl_offset));
  1754. unicast_reg &= (0x0E << (8 * reg_offset));
  1755. mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1756. (eth_port_num) + tbl_offset), unicast_reg);
  1757. break;
  1758. case ACCEPT_MAC_ADDR:
  1759. /* Set accepts frame bit at unicast DA filter table entry */
  1760. unicast_reg =
  1761. mv_read((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1762. (eth_port_num) + tbl_offset));
  1763. unicast_reg |= (0x01 << (8 * reg_offset));
  1764. mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1765. (eth_port_num) + tbl_offset), unicast_reg);
  1766. break;
  1767. default:
  1768. return 0;
  1769. }
  1770. return 1;
  1771. }
  1772. /*
  1773. * The entries in each table are indexed by a hash of a packet's MAC
  1774. * address. One bit in each entry determines whether the packet is
  1775. * accepted. There are 4 entries (each 8 bits wide) in each register
  1776. * of the table. The bits in each entry are defined as follows:
  1777. * 0 Accept=1, Drop=0
  1778. * 3-1 Queue (ETH_Q0=0)
  1779. * 7-4 Reserved = 0;
  1780. */
  1781. static void eth_port_set_filter_table_entry(int table, unsigned char entry)
  1782. {
  1783. unsigned int table_reg;
  1784. unsigned int tbl_offset;
  1785. unsigned int reg_offset;
  1786. tbl_offset = (entry / 4) * 4; /* Register offset of DA table entry */
  1787. reg_offset = entry % 4; /* Entry offset within the register */
  1788. /* Set "accepts frame bit" at specified table entry */
  1789. table_reg = mv_read(table + tbl_offset);
  1790. table_reg |= 0x01 << (8 * reg_offset);
  1791. mv_write(table + tbl_offset, table_reg);
  1792. }
  1793. /*
  1794. * eth_port_mc_addr - Multicast address settings.
  1795. *
  1796. * The MV device supports multicast using two tables:
  1797. * 1) Special Multicast Table for MAC addresses of the form
  1798. * 0x01-00-5E-00-00-XX (where XX is between 0x00 and 0x_FF).
  1799. * The MAC DA[7:0] bits are used as a pointer to the Special Multicast
  1800. * Table entries in the DA-Filter table.
  1801. * 2) Other Multicast Table for multicast of another type. A CRC-8bit
  1802. * is used as an index to the Other Multicast Table entries in the
  1803. * DA-Filter table. This function calculates the CRC-8bit value.
  1804. * In either case, eth_port_set_filter_table_entry() is then called
  1805. * to set to set the actual table entry.
  1806. */
  1807. static void eth_port_mc_addr(unsigned int eth_port_num, unsigned char *p_addr)
  1808. {
  1809. unsigned int mac_h;
  1810. unsigned int mac_l;
  1811. unsigned char crc_result = 0;
  1812. int table;
  1813. int mac_array[48];
  1814. int crc[8];
  1815. int i;
  1816. if ((p_addr[0] == 0x01) && (p_addr[1] == 0x00) &&
  1817. (p_addr[2] == 0x5E) && (p_addr[3] == 0x00) && (p_addr[4] == 0x00)) {
  1818. table = MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
  1819. (eth_port_num);
  1820. eth_port_set_filter_table_entry(table, p_addr[5]);
  1821. return;
  1822. }
  1823. /* Calculate CRC-8 out of the given address */
  1824. mac_h = (p_addr[0] << 8) | (p_addr[1]);
  1825. mac_l = (p_addr[2] << 24) | (p_addr[3] << 16) |
  1826. (p_addr[4] << 8) | (p_addr[5] << 0);
  1827. for (i = 0; i < 32; i++)
  1828. mac_array[i] = (mac_l >> i) & 0x1;
  1829. for (i = 32; i < 48; i++)
  1830. mac_array[i] = (mac_h >> (i - 32)) & 0x1;
  1831. crc[0] = mac_array[45] ^ mac_array[43] ^ mac_array[40] ^ mac_array[39] ^
  1832. mac_array[35] ^ mac_array[34] ^ mac_array[31] ^ mac_array[30] ^
  1833. mac_array[28] ^ mac_array[23] ^ mac_array[21] ^ mac_array[19] ^
  1834. mac_array[18] ^ mac_array[16] ^ mac_array[14] ^ mac_array[12] ^
  1835. mac_array[8] ^ mac_array[7] ^ mac_array[6] ^ mac_array[0];
  1836. crc[1] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
  1837. mac_array[41] ^ mac_array[39] ^ mac_array[36] ^ mac_array[34] ^
  1838. mac_array[32] ^ mac_array[30] ^ mac_array[29] ^ mac_array[28] ^
  1839. mac_array[24] ^ mac_array[23] ^ mac_array[22] ^ mac_array[21] ^
  1840. mac_array[20] ^ mac_array[18] ^ mac_array[17] ^ mac_array[16] ^
  1841. mac_array[15] ^ mac_array[14] ^ mac_array[13] ^ mac_array[12] ^
  1842. mac_array[9] ^ mac_array[6] ^ mac_array[1] ^ mac_array[0];
  1843. crc[2] = mac_array[47] ^ mac_array[46] ^ mac_array[44] ^ mac_array[43] ^
  1844. mac_array[42] ^ mac_array[39] ^ mac_array[37] ^ mac_array[34] ^
  1845. mac_array[33] ^ mac_array[29] ^ mac_array[28] ^ mac_array[25] ^
  1846. mac_array[24] ^ mac_array[22] ^ mac_array[17] ^ mac_array[15] ^
  1847. mac_array[13] ^ mac_array[12] ^ mac_array[10] ^ mac_array[8] ^
  1848. mac_array[6] ^ mac_array[2] ^ mac_array[1] ^ mac_array[0];
  1849. crc[3] = mac_array[47] ^ mac_array[45] ^ mac_array[44] ^ mac_array[43] ^
  1850. mac_array[40] ^ mac_array[38] ^ mac_array[35] ^ mac_array[34] ^
  1851. mac_array[30] ^ mac_array[29] ^ mac_array[26] ^ mac_array[25] ^
  1852. mac_array[23] ^ mac_array[18] ^ mac_array[16] ^ mac_array[14] ^
  1853. mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[7] ^
  1854. mac_array[3] ^ mac_array[2] ^ mac_array[1];
  1855. crc[4] = mac_array[46] ^ mac_array[45] ^ mac_array[44] ^ mac_array[41] ^
  1856. mac_array[39] ^ mac_array[36] ^ mac_array[35] ^ mac_array[31] ^
  1857. mac_array[30] ^ mac_array[27] ^ mac_array[26] ^ mac_array[24] ^
  1858. mac_array[19] ^ mac_array[17] ^ mac_array[15] ^ mac_array[14] ^
  1859. mac_array[12] ^ mac_array[10] ^ mac_array[8] ^ mac_array[4] ^
  1860. mac_array[3] ^ mac_array[2];
  1861. crc[5] = mac_array[47] ^ mac_array[46] ^ mac_array[45] ^ mac_array[42] ^
  1862. mac_array[40] ^ mac_array[37] ^ mac_array[36] ^ mac_array[32] ^
  1863. mac_array[31] ^ mac_array[28] ^ mac_array[27] ^ mac_array[25] ^
  1864. mac_array[20] ^ mac_array[18] ^ mac_array[16] ^ mac_array[15] ^
  1865. mac_array[13] ^ mac_array[11] ^ mac_array[9] ^ mac_array[5] ^
  1866. mac_array[4] ^ mac_array[3];
  1867. crc[6] = mac_array[47] ^ mac_array[46] ^ mac_array[43] ^ mac_array[41] ^
  1868. mac_array[38] ^ mac_array[37] ^ mac_array[33] ^ mac_array[32] ^
  1869. mac_array[29] ^ mac_array[28] ^ mac_array[26] ^ mac_array[21] ^
  1870. mac_array[19] ^ mac_array[17] ^ mac_array[16] ^ mac_array[14] ^
  1871. mac_array[12] ^ mac_array[10] ^ mac_array[6] ^ mac_array[5] ^
  1872. mac_array[4];
  1873. crc[7] = mac_array[47] ^ mac_array[44] ^ mac_array[42] ^ mac_array[39] ^
  1874. mac_array[38] ^ mac_array[34] ^ mac_array[33] ^ mac_array[30] ^
  1875. mac_array[29] ^ mac_array[27] ^ mac_array[22] ^ mac_array[20] ^
  1876. mac_array[18] ^ mac_array[17] ^ mac_array[15] ^ mac_array[13] ^
  1877. mac_array[11] ^ mac_array[7] ^ mac_array[6] ^ mac_array[5];
  1878. for (i = 0; i < 8; i++)
  1879. crc_result = crc_result | (crc[i] << i);
  1880. table = MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num);
  1881. eth_port_set_filter_table_entry(table, crc_result);
  1882. }
  1883. /*
  1884. * Set the entire multicast list based on dev->mc_list.
  1885. */
  1886. static void eth_port_set_multicast_list(struct net_device *dev)
  1887. {
  1888. struct dev_mc_list *mc_list;
  1889. int i;
  1890. int table_index;
  1891. struct mv643xx_private *mp = netdev_priv(dev);
  1892. unsigned int eth_port_num = mp->port_num;
  1893. /* If the device is in promiscuous mode or in all multicast mode,
  1894. * we will fully populate both multicast tables with accept.
  1895. * This is guaranteed to yield a match on all multicast addresses...
  1896. */
  1897. if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) {
  1898. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1899. /* Set all entries in DA filter special multicast
  1900. * table (Ex_dFSMT)
  1901. * Set for ETH_Q0 for now
  1902. * Bits
  1903. * 0 Accept=1, Drop=0
  1904. * 3-1 Queue ETH_Q0=0
  1905. * 7-4 Reserved = 0;
  1906. */
  1907. mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101);
  1908. /* Set all entries in DA filter other multicast
  1909. * table (Ex_dFOMT)
  1910. * Set for ETH_Q0 for now
  1911. * Bits
  1912. * 0 Accept=1, Drop=0
  1913. * 3-1 Queue ETH_Q0=0
  1914. * 7-4 Reserved = 0;
  1915. */
  1916. mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE(eth_port_num) + table_index, 0x01010101);
  1917. }
  1918. return;
  1919. }
  1920. /* We will clear out multicast tables every time we get the list.
  1921. * Then add the entire new list...
  1922. */
  1923. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1924. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1925. mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
  1926. (eth_port_num) + table_index, 0);
  1927. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1928. mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE
  1929. (eth_port_num) + table_index, 0);
  1930. }
  1931. /* Get pointer to net_device multicast list and add each one... */
  1932. for (i = 0, mc_list = dev->mc_list;
  1933. (i < 256) && (mc_list != NULL) && (i < dev->mc_count);
  1934. i++, mc_list = mc_list->next)
  1935. if (mc_list->dmi_addrlen == 6)
  1936. eth_port_mc_addr(eth_port_num, mc_list->dmi_addr);
  1937. }
  1938. /*
  1939. * eth_port_init_mac_tables - Clear all entrance in the UC, SMC and OMC tables
  1940. *
  1941. * DESCRIPTION:
  1942. * Go through all the DA filter tables (Unicast, Special Multicast &
  1943. * Other Multicast) and set each entry to 0.
  1944. *
  1945. * INPUT:
  1946. * unsigned int eth_port_num Ethernet Port number.
  1947. *
  1948. * OUTPUT:
  1949. * Multicast and Unicast packets are rejected.
  1950. *
  1951. * RETURN:
  1952. * None.
  1953. */
  1954. static void eth_port_init_mac_tables(unsigned int eth_port_num)
  1955. {
  1956. int table_index;
  1957. /* Clear DA filter unicast table (Ex_dFUT) */
  1958. for (table_index = 0; table_index <= 0xC; table_index += 4)
  1959. mv_write((MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE
  1960. (eth_port_num) + table_index), 0);
  1961. for (table_index = 0; table_index <= 0xFC; table_index += 4) {
  1962. /* Clear DA filter special multicast table (Ex_dFSMT) */
  1963. mv_write(MV643XX_ETH_DA_FILTER_SPECIAL_MULTICAST_TABLE_BASE
  1964. (eth_port_num) + table_index, 0);
  1965. /* Clear DA filter other multicast table (Ex_dFOMT) */
  1966. mv_write(MV643XX_ETH_DA_FILTER_OTHER_MULTICAST_TABLE_BASE
  1967. (eth_port_num) + table_index, 0);
  1968. }
  1969. }
  1970. /*
  1971. * eth_clear_mib_counters - Clear all MIB counters
  1972. *
  1973. * DESCRIPTION:
  1974. * This function clears all MIB counters of a specific ethernet port.
  1975. * A read from the MIB counter will reset the counter.
  1976. *
  1977. * INPUT:
  1978. * unsigned int eth_port_num Ethernet Port number.
  1979. *
  1980. * OUTPUT:
  1981. * After reading all MIB counters, the counters resets.
  1982. *
  1983. * RETURN:
  1984. * MIB counter value.
  1985. *
  1986. */
  1987. static void eth_clear_mib_counters(unsigned int eth_port_num)
  1988. {
  1989. int i;
  1990. /* Perform dummy reads from MIB counters */
  1991. for (i = ETH_MIB_GOOD_OCTETS_RECEIVED_LOW; i < ETH_MIB_LATE_COLLISION;
  1992. i += 4)
  1993. mv_read(MV643XX_ETH_MIB_COUNTERS_BASE(eth_port_num) + i);
  1994. }
  1995. static inline u32 read_mib(struct mv643xx_private *mp, int offset)
  1996. {
  1997. return mv_read(MV643XX_ETH_MIB_COUNTERS_BASE(mp->port_num) + offset);
  1998. }
  1999. static void eth_update_mib_counters(struct mv643xx_private *mp)
  2000. {
  2001. struct mv643xx_mib_counters *p = &mp->mib_counters;
  2002. int offset;
  2003. p->good_octets_received +=
  2004. read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_LOW);
  2005. p->good_octets_received +=
  2006. (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_RECEIVED_HIGH) << 32;
  2007. for (offset = ETH_MIB_BAD_OCTETS_RECEIVED;
  2008. offset <= ETH_MIB_FRAMES_1024_TO_MAX_OCTETS;
  2009. offset += 4)
  2010. *(u32 *)((char *)p + offset) = read_mib(mp, offset);
  2011. p->good_octets_sent += read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_LOW);
  2012. p->good_octets_sent +=
  2013. (u64)read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_HIGH) << 32;
  2014. for (offset = ETH_MIB_GOOD_FRAMES_SENT;
  2015. offset <= ETH_MIB_LATE_COLLISION;
  2016. offset += 4)
  2017. *(u32 *)((char *)p + offset) = read_mib(mp, offset);
  2018. }
  2019. /*
  2020. * ethernet_phy_detect - Detect whether a phy is present
  2021. *
  2022. * DESCRIPTION:
  2023. * This function tests whether there is a PHY present on
  2024. * the specified port.
  2025. *
  2026. * INPUT:
  2027. * unsigned int eth_port_num Ethernet Port number.
  2028. *
  2029. * OUTPUT:
  2030. * None
  2031. *
  2032. * RETURN:
  2033. * 0 on success
  2034. * -ENODEV on failure
  2035. *
  2036. */
  2037. static int ethernet_phy_detect(unsigned int port_num)
  2038. {
  2039. unsigned int phy_reg_data0;
  2040. int auto_neg;
  2041. eth_port_read_smi_reg(port_num, 0, &phy_reg_data0);
  2042. auto_neg = phy_reg_data0 & 0x1000;
  2043. phy_reg_data0 ^= 0x1000; /* invert auto_neg */
  2044. eth_port_write_smi_reg(port_num, 0, phy_reg_data0);
  2045. eth_port_read_smi_reg(port_num, 0, &phy_reg_data0);
  2046. if ((phy_reg_data0 & 0x1000) == auto_neg)
  2047. return -ENODEV; /* change didn't take */
  2048. phy_reg_data0 ^= 0x1000;
  2049. eth_port_write_smi_reg(port_num, 0, phy_reg_data0);
  2050. return 0;
  2051. }
  2052. /*
  2053. * ethernet_phy_get - Get the ethernet port PHY address.
  2054. *
  2055. * DESCRIPTION:
  2056. * This routine returns the given ethernet port PHY address.
  2057. *
  2058. * INPUT:
  2059. * unsigned int eth_port_num Ethernet Port number.
  2060. *
  2061. * OUTPUT:
  2062. * None.
  2063. *
  2064. * RETURN:
  2065. * PHY address.
  2066. *
  2067. */
  2068. static int ethernet_phy_get(unsigned int eth_port_num)
  2069. {
  2070. unsigned int reg_data;
  2071. reg_data = mv_read(MV643XX_ETH_PHY_ADDR_REG);
  2072. return ((reg_data >> (5 * eth_port_num)) & 0x1f);
  2073. }
  2074. /*
  2075. * ethernet_phy_set - Set the ethernet port PHY address.
  2076. *
  2077. * DESCRIPTION:
  2078. * This routine sets the given ethernet port PHY address.
  2079. *
  2080. * INPUT:
  2081. * unsigned int eth_port_num Ethernet Port number.
  2082. * int phy_addr PHY address.
  2083. *
  2084. * OUTPUT:
  2085. * None.
  2086. *
  2087. * RETURN:
  2088. * None.
  2089. *
  2090. */
  2091. static void ethernet_phy_set(unsigned int eth_port_num, int phy_addr)
  2092. {
  2093. u32 reg_data;
  2094. int addr_shift = 5 * eth_port_num;
  2095. reg_data = mv_read(MV643XX_ETH_PHY_ADDR_REG);
  2096. reg_data &= ~(0x1f << addr_shift);
  2097. reg_data |= (phy_addr & 0x1f) << addr_shift;
  2098. mv_write(MV643XX_ETH_PHY_ADDR_REG, reg_data);
  2099. }
  2100. /*
  2101. * ethernet_phy_reset - Reset Ethernet port PHY.
  2102. *
  2103. * DESCRIPTION:
  2104. * This routine utilizes the SMI interface to reset the ethernet port PHY.
  2105. *
  2106. * INPUT:
  2107. * unsigned int eth_port_num Ethernet Port number.
  2108. *
  2109. * OUTPUT:
  2110. * The PHY is reset.
  2111. *
  2112. * RETURN:
  2113. * None.
  2114. *
  2115. */
  2116. static void ethernet_phy_reset(unsigned int eth_port_num)
  2117. {
  2118. unsigned int phy_reg_data;
  2119. /* Reset the PHY */
  2120. eth_port_read_smi_reg(eth_port_num, 0, &phy_reg_data);
  2121. phy_reg_data |= 0x8000; /* Set bit 15 to reset the PHY */
  2122. eth_port_write_smi_reg(eth_port_num, 0, phy_reg_data);
  2123. }
  2124. /*
  2125. * eth_port_reset - Reset Ethernet port
  2126. *
  2127. * DESCRIPTION:
  2128. * This routine resets the chip by aborting any SDMA engine activity and
  2129. * clearing the MIB counters. The Receiver and the Transmit unit are in
  2130. * idle state after this command is performed and the port is disabled.
  2131. *
  2132. * INPUT:
  2133. * unsigned int eth_port_num Ethernet Port number.
  2134. *
  2135. * OUTPUT:
  2136. * Channel activity is halted.
  2137. *
  2138. * RETURN:
  2139. * None.
  2140. *
  2141. */
  2142. static void eth_port_reset(unsigned int port_num)
  2143. {
  2144. unsigned int reg_data;
  2145. /* Stop Tx port activity. Check port Tx activity. */
  2146. reg_data = mv_read(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num));
  2147. if (reg_data & 0xFF) {
  2148. /* Issue stop command for active channels only */
  2149. mv_write(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num),
  2150. (reg_data << 8));
  2151. /* Wait for all Tx activity to terminate. */
  2152. /* Check port cause register that all Tx queues are stopped */
  2153. while (mv_read(MV643XX_ETH_TRANSMIT_QUEUE_COMMAND_REG(port_num))
  2154. & 0xFF)
  2155. udelay(10);
  2156. }
  2157. /* Stop Rx port activity. Check port Rx activity. */
  2158. reg_data = mv_read(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num));
  2159. if (reg_data & 0xFF) {
  2160. /* Issue stop command for active channels only */
  2161. mv_write(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num),
  2162. (reg_data << 8));
  2163. /* Wait for all Rx activity to terminate. */
  2164. /* Check port cause register that all Rx queues are stopped */
  2165. while (mv_read(MV643XX_ETH_RECEIVE_QUEUE_COMMAND_REG(port_num))
  2166. & 0xFF)
  2167. udelay(10);
  2168. }
  2169. /* Clear all MIB counters */
  2170. eth_clear_mib_counters(port_num);
  2171. /* Reset the Enable bit in the Configuration Register */
  2172. reg_data = mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num));
  2173. reg_data &= ~MV643XX_ETH_SERIAL_PORT_ENABLE;
  2174. mv_write(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num), reg_data);
  2175. }
  2176. static int eth_port_autoneg_supported(unsigned int eth_port_num)
  2177. {
  2178. unsigned int phy_reg_data0;
  2179. eth_port_read_smi_reg(eth_port_num, 0, &phy_reg_data0);
  2180. return phy_reg_data0 & 0x1000;
  2181. }
  2182. static int eth_port_link_is_up(unsigned int eth_port_num)
  2183. {
  2184. unsigned int phy_reg_data1;
  2185. eth_port_read_smi_reg(eth_port_num, 1, &phy_reg_data1);
  2186. if (eth_port_autoneg_supported(eth_port_num)) {
  2187. if (phy_reg_data1 & 0x20) /* auto-neg complete */
  2188. return 1;
  2189. } else if (phy_reg_data1 & 0x4) /* link up */
  2190. return 1;
  2191. return 0;
  2192. }
  2193. /*
  2194. * eth_port_read_smi_reg - Read PHY registers
  2195. *
  2196. * DESCRIPTION:
  2197. * This routine utilize the SMI interface to interact with the PHY in
  2198. * order to perform PHY register read.
  2199. *
  2200. * INPUT:
  2201. * unsigned int port_num Ethernet Port number.
  2202. * unsigned int phy_reg PHY register address offset.
  2203. * unsigned int *value Register value buffer.
  2204. *
  2205. * OUTPUT:
  2206. * Write the value of a specified PHY register into given buffer.
  2207. *
  2208. * RETURN:
  2209. * false if the PHY is busy or read data is not in valid state.
  2210. * true otherwise.
  2211. *
  2212. */
  2213. static void eth_port_read_smi_reg(unsigned int port_num,
  2214. unsigned int phy_reg, unsigned int *value)
  2215. {
  2216. int phy_addr = ethernet_phy_get(port_num);
  2217. unsigned long flags;
  2218. int i;
  2219. /* the SMI register is a shared resource */
  2220. spin_lock_irqsave(&mv643xx_eth_phy_lock, flags);
  2221. /* wait for the SMI register to become available */
  2222. for (i = 0; mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_BUSY; i++) {
  2223. if (i == PHY_WAIT_ITERATIONS) {
  2224. printk("mv643xx PHY busy timeout, port %d\n", port_num);
  2225. goto out;
  2226. }
  2227. udelay(PHY_WAIT_MICRO_SECONDS);
  2228. }
  2229. mv_write(MV643XX_ETH_SMI_REG,
  2230. (phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ);
  2231. /* now wait for the data to be valid */
  2232. for (i = 0; !(mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_READ_VALID); i++) {
  2233. if (i == PHY_WAIT_ITERATIONS) {
  2234. printk("mv643xx PHY read timeout, port %d\n", port_num);
  2235. goto out;
  2236. }
  2237. udelay(PHY_WAIT_MICRO_SECONDS);
  2238. }
  2239. *value = mv_read(MV643XX_ETH_SMI_REG) & 0xffff;
  2240. out:
  2241. spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags);
  2242. }
  2243. /*
  2244. * eth_port_write_smi_reg - Write to PHY registers
  2245. *
  2246. * DESCRIPTION:
  2247. * This routine utilize the SMI interface to interact with the PHY in
  2248. * order to perform writes to PHY registers.
  2249. *
  2250. * INPUT:
  2251. * unsigned int eth_port_num Ethernet Port number.
  2252. * unsigned int phy_reg PHY register address offset.
  2253. * unsigned int value Register value.
  2254. *
  2255. * OUTPUT:
  2256. * Write the given value to the specified PHY register.
  2257. *
  2258. * RETURN:
  2259. * false if the PHY is busy.
  2260. * true otherwise.
  2261. *
  2262. */
  2263. static void eth_port_write_smi_reg(unsigned int eth_port_num,
  2264. unsigned int phy_reg, unsigned int value)
  2265. {
  2266. int phy_addr;
  2267. int i;
  2268. unsigned long flags;
  2269. phy_addr = ethernet_phy_get(eth_port_num);
  2270. /* the SMI register is a shared resource */
  2271. spin_lock_irqsave(&mv643xx_eth_phy_lock, flags);
  2272. /* wait for the SMI register to become available */
  2273. for (i = 0; mv_read(MV643XX_ETH_SMI_REG) & ETH_SMI_BUSY; i++) {
  2274. if (i == PHY_WAIT_ITERATIONS) {
  2275. printk("mv643xx PHY busy timeout, port %d\n",
  2276. eth_port_num);
  2277. goto out;
  2278. }
  2279. udelay(PHY_WAIT_MICRO_SECONDS);
  2280. }
  2281. mv_write(MV643XX_ETH_SMI_REG, (phy_addr << 16) | (phy_reg << 21) |
  2282. ETH_SMI_OPCODE_WRITE | (value & 0xffff));
  2283. out:
  2284. spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags);
  2285. }
  2286. /*
  2287. * eth_port_send - Send an Ethernet packet
  2288. *
  2289. * DESCRIPTION:
  2290. * This routine send a given packet described by p_pktinfo parameter. It
  2291. * supports transmitting of a packet spaned over multiple buffers. The
  2292. * routine updates 'curr' and 'first' indexes according to the packet
  2293. * segment passed to the routine. In case the packet segment is first,
  2294. * the 'first' index is update. In any case, the 'curr' index is updated.
  2295. * If the routine get into Tx resource error it assigns 'curr' index as
  2296. * 'first'. This way the function can abort Tx process of multiple
  2297. * descriptors per packet.
  2298. *
  2299. * INPUT:
  2300. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2301. * struct pkt_info *p_pkt_info User packet buffer.
  2302. *
  2303. * OUTPUT:
  2304. * Tx ring 'curr' and 'first' indexes are updated.
  2305. *
  2306. * RETURN:
  2307. * ETH_QUEUE_FULL in case of Tx resource error.
  2308. * ETH_ERROR in case the routine can not access Tx desc ring.
  2309. * ETH_QUEUE_LAST_RESOURCE if the routine uses the last Tx resource.
  2310. * ETH_OK otherwise.
  2311. *
  2312. */
  2313. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  2314. /*
  2315. * Modified to include the first descriptor pointer in case of SG
  2316. */
  2317. static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
  2318. struct pkt_info *p_pkt_info)
  2319. {
  2320. int tx_desc_curr, tx_desc_used, tx_first_desc, tx_next_desc;
  2321. struct eth_tx_desc *current_descriptor;
  2322. struct eth_tx_desc *first_descriptor;
  2323. u32 command;
  2324. unsigned long flags;
  2325. /* Do not process Tx ring in case of Tx ring resource error */
  2326. if (mp->tx_resource_err)
  2327. return ETH_QUEUE_FULL;
  2328. /*
  2329. * The hardware requires that each buffer that is <= 8 bytes
  2330. * in length must be aligned on an 8 byte boundary.
  2331. */
  2332. if (p_pkt_info->byte_cnt <= 8 && p_pkt_info->buf_ptr & 0x7) {
  2333. printk(KERN_ERR
  2334. "mv643xx_eth port %d: packet size <= 8 problem\n",
  2335. mp->port_num);
  2336. return ETH_ERROR;
  2337. }
  2338. spin_lock_irqsave(&mp->lock, flags);
  2339. mp->tx_ring_skbs++;
  2340. BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
  2341. /* Get the Tx Desc ring indexes */
  2342. tx_desc_curr = mp->tx_curr_desc_q;
  2343. tx_desc_used = mp->tx_used_desc_q;
  2344. current_descriptor = &mp->p_tx_desc_area[tx_desc_curr];
  2345. tx_next_desc = (tx_desc_curr + 1) % mp->tx_ring_size;
  2346. current_descriptor->buf_ptr = p_pkt_info->buf_ptr;
  2347. current_descriptor->byte_cnt = p_pkt_info->byte_cnt;
  2348. current_descriptor->l4i_chk = p_pkt_info->l4i_chk;
  2349. mp->tx_skb[tx_desc_curr] = p_pkt_info->return_info;
  2350. command = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC |
  2351. ETH_BUFFER_OWNED_BY_DMA;
  2352. if (command & ETH_TX_FIRST_DESC) {
  2353. tx_first_desc = tx_desc_curr;
  2354. mp->tx_first_desc_q = tx_first_desc;
  2355. first_descriptor = current_descriptor;
  2356. mp->tx_first_command = command;
  2357. } else {
  2358. tx_first_desc = mp->tx_first_desc_q;
  2359. first_descriptor = &mp->p_tx_desc_area[tx_first_desc];
  2360. BUG_ON(first_descriptor == NULL);
  2361. current_descriptor->cmd_sts = command;
  2362. }
  2363. if (command & ETH_TX_LAST_DESC) {
  2364. wmb();
  2365. first_descriptor->cmd_sts = mp->tx_first_command;
  2366. wmb();
  2367. ETH_ENABLE_TX_QUEUE(mp->port_num);
  2368. /*
  2369. * Finish Tx packet. Update first desc in case of Tx resource
  2370. * error */
  2371. tx_first_desc = tx_next_desc;
  2372. mp->tx_first_desc_q = tx_first_desc;
  2373. }
  2374. /* Check for ring index overlap in the Tx desc ring */
  2375. if (tx_next_desc == tx_desc_used) {
  2376. mp->tx_resource_err = 1;
  2377. mp->tx_curr_desc_q = tx_first_desc;
  2378. spin_unlock_irqrestore(&mp->lock, flags);
  2379. return ETH_QUEUE_LAST_RESOURCE;
  2380. }
  2381. mp->tx_curr_desc_q = tx_next_desc;
  2382. spin_unlock_irqrestore(&mp->lock, flags);
  2383. return ETH_OK;
  2384. }
  2385. #else
  2386. static ETH_FUNC_RET_STATUS eth_port_send(struct mv643xx_private *mp,
  2387. struct pkt_info *p_pkt_info)
  2388. {
  2389. int tx_desc_curr;
  2390. int tx_desc_used;
  2391. struct eth_tx_desc *current_descriptor;
  2392. unsigned int command_status;
  2393. unsigned long flags;
  2394. /* Do not process Tx ring in case of Tx ring resource error */
  2395. if (mp->tx_resource_err)
  2396. return ETH_QUEUE_FULL;
  2397. spin_lock_irqsave(&mp->lock, flags);
  2398. mp->tx_ring_skbs++;
  2399. BUG_ON(mp->tx_ring_skbs > mp->tx_ring_size);
  2400. /* Get the Tx Desc ring indexes */
  2401. tx_desc_curr = mp->tx_curr_desc_q;
  2402. tx_desc_used = mp->tx_used_desc_q;
  2403. current_descriptor = &mp->p_tx_desc_area[tx_desc_curr];
  2404. command_status = p_pkt_info->cmd_sts | ETH_ZERO_PADDING | ETH_GEN_CRC;
  2405. current_descriptor->buf_ptr = p_pkt_info->buf_ptr;
  2406. current_descriptor->byte_cnt = p_pkt_info->byte_cnt;
  2407. mp->tx_skb[tx_desc_curr] = p_pkt_info->return_info;
  2408. /* Set last desc with DMA ownership and interrupt enable. */
  2409. wmb();
  2410. current_descriptor->cmd_sts = command_status |
  2411. ETH_BUFFER_OWNED_BY_DMA | ETH_TX_ENABLE_INTERRUPT;
  2412. wmb();
  2413. ETH_ENABLE_TX_QUEUE(mp->port_num);
  2414. /* Finish Tx packet. Update first desc in case of Tx resource error */
  2415. tx_desc_curr = (tx_desc_curr + 1) % mp->tx_ring_size;
  2416. /* Update the current descriptor */
  2417. mp->tx_curr_desc_q = tx_desc_curr;
  2418. /* Check for ring index overlap in the Tx desc ring */
  2419. if (tx_desc_curr == tx_desc_used) {
  2420. mp->tx_resource_err = 1;
  2421. spin_unlock_irqrestore(&mp->lock, flags);
  2422. return ETH_QUEUE_LAST_RESOURCE;
  2423. }
  2424. spin_unlock_irqrestore(&mp->lock, flags);
  2425. return ETH_OK;
  2426. }
  2427. #endif
  2428. /*
  2429. * eth_tx_return_desc - Free all used Tx descriptors
  2430. *
  2431. * DESCRIPTION:
  2432. * This routine returns the transmitted packet information to the caller.
  2433. * It uses the 'first' index to support Tx desc return in case a transmit
  2434. * of a packet spanned over multiple buffer still in process.
  2435. * In case the Tx queue was in "resource error" condition, where there are
  2436. * no available Tx resources, the function resets the resource error flag.
  2437. *
  2438. * INPUT:
  2439. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2440. * struct pkt_info *p_pkt_info User packet buffer.
  2441. *
  2442. * OUTPUT:
  2443. * Tx ring 'first' and 'used' indexes are updated.
  2444. *
  2445. * RETURN:
  2446. * ETH_OK on success
  2447. * ETH_ERROR otherwise.
  2448. *
  2449. */
  2450. static ETH_FUNC_RET_STATUS eth_tx_return_desc(struct mv643xx_private *mp,
  2451. struct pkt_info *p_pkt_info)
  2452. {
  2453. int tx_desc_used;
  2454. int tx_busy_desc;
  2455. struct eth_tx_desc *p_tx_desc_used;
  2456. unsigned int command_status;
  2457. unsigned long flags;
  2458. int err = ETH_OK;
  2459. spin_lock_irqsave(&mp->lock, flags);
  2460. #ifdef MV643XX_CHECKSUM_OFFLOAD_TX
  2461. tx_busy_desc = mp->tx_first_desc_q;
  2462. #else
  2463. tx_busy_desc = mp->tx_curr_desc_q;
  2464. #endif
  2465. /* Get the Tx Desc ring indexes */
  2466. tx_desc_used = mp->tx_used_desc_q;
  2467. p_tx_desc_used = &mp->p_tx_desc_area[tx_desc_used];
  2468. /* Sanity check */
  2469. if (p_tx_desc_used == NULL) {
  2470. err = ETH_ERROR;
  2471. goto out;
  2472. }
  2473. /* Stop release. About to overlap the current available Tx descriptor */
  2474. if (tx_desc_used == tx_busy_desc && !mp->tx_resource_err) {
  2475. err = ETH_ERROR;
  2476. goto out;
  2477. }
  2478. command_status = p_tx_desc_used->cmd_sts;
  2479. /* Still transmitting... */
  2480. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  2481. err = ETH_ERROR;
  2482. goto out;
  2483. }
  2484. /* Pass the packet information to the caller */
  2485. p_pkt_info->cmd_sts = command_status;
  2486. p_pkt_info->return_info = mp->tx_skb[tx_desc_used];
  2487. p_pkt_info->buf_ptr = p_tx_desc_used->buf_ptr;
  2488. p_pkt_info->byte_cnt = p_tx_desc_used->byte_cnt;
  2489. mp->tx_skb[tx_desc_used] = NULL;
  2490. /* Update the next descriptor to release. */
  2491. mp->tx_used_desc_q = (tx_desc_used + 1) % mp->tx_ring_size;
  2492. /* Any Tx return cancels the Tx resource error status */
  2493. mp->tx_resource_err = 0;
  2494. BUG_ON(mp->tx_ring_skbs == 0);
  2495. mp->tx_ring_skbs--;
  2496. out:
  2497. spin_unlock_irqrestore(&mp->lock, flags);
  2498. return err;
  2499. }
  2500. /*
  2501. * eth_port_receive - Get received information from Rx ring.
  2502. *
  2503. * DESCRIPTION:
  2504. * This routine returns the received data to the caller. There is no
  2505. * data copying during routine operation. All information is returned
  2506. * using pointer to packet information struct passed from the caller.
  2507. * If the routine exhausts Rx ring resources then the resource error flag
  2508. * is set.
  2509. *
  2510. * INPUT:
  2511. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2512. * struct pkt_info *p_pkt_info User packet buffer.
  2513. *
  2514. * OUTPUT:
  2515. * Rx ring current and used indexes are updated.
  2516. *
  2517. * RETURN:
  2518. * ETH_ERROR in case the routine can not access Rx desc ring.
  2519. * ETH_QUEUE_FULL if Rx ring resources are exhausted.
  2520. * ETH_END_OF_JOB if there is no received data.
  2521. * ETH_OK otherwise.
  2522. */
  2523. static ETH_FUNC_RET_STATUS eth_port_receive(struct mv643xx_private *mp,
  2524. struct pkt_info *p_pkt_info)
  2525. {
  2526. int rx_next_curr_desc, rx_curr_desc, rx_used_desc;
  2527. volatile struct eth_rx_desc *p_rx_desc;
  2528. unsigned int command_status;
  2529. unsigned long flags;
  2530. /* Do not process Rx ring in case of Rx ring resource error */
  2531. if (mp->rx_resource_err)
  2532. return ETH_QUEUE_FULL;
  2533. spin_lock_irqsave(&mp->lock, flags);
  2534. /* Get the Rx Desc ring 'curr and 'used' indexes */
  2535. rx_curr_desc = mp->rx_curr_desc_q;
  2536. rx_used_desc = mp->rx_used_desc_q;
  2537. p_rx_desc = &mp->p_rx_desc_area[rx_curr_desc];
  2538. /* The following parameters are used to save readings from memory */
  2539. command_status = p_rx_desc->cmd_sts;
  2540. rmb();
  2541. /* Nothing to receive... */
  2542. if (command_status & (ETH_BUFFER_OWNED_BY_DMA)) {
  2543. spin_unlock_irqrestore(&mp->lock, flags);
  2544. return ETH_END_OF_JOB;
  2545. }
  2546. p_pkt_info->byte_cnt = (p_rx_desc->byte_cnt) - RX_BUF_OFFSET;
  2547. p_pkt_info->cmd_sts = command_status;
  2548. p_pkt_info->buf_ptr = (p_rx_desc->buf_ptr) + RX_BUF_OFFSET;
  2549. p_pkt_info->return_info = mp->rx_skb[rx_curr_desc];
  2550. p_pkt_info->l4i_chk = p_rx_desc->buf_size;
  2551. /* Clean the return info field to indicate that the packet has been */
  2552. /* moved to the upper layers */
  2553. mp->rx_skb[rx_curr_desc] = NULL;
  2554. /* Update current index in data structure */
  2555. rx_next_curr_desc = (rx_curr_desc + 1) % mp->rx_ring_size;
  2556. mp->rx_curr_desc_q = rx_next_curr_desc;
  2557. /* Rx descriptors exhausted. Set the Rx ring resource error flag */
  2558. if (rx_next_curr_desc == rx_used_desc)
  2559. mp->rx_resource_err = 1;
  2560. spin_unlock_irqrestore(&mp->lock, flags);
  2561. return ETH_OK;
  2562. }
  2563. /*
  2564. * eth_rx_return_buff - Returns a Rx buffer back to the Rx ring.
  2565. *
  2566. * DESCRIPTION:
  2567. * This routine returns a Rx buffer back to the Rx ring. It retrieves the
  2568. * next 'used' descriptor and attached the returned buffer to it.
  2569. * In case the Rx ring was in "resource error" condition, where there are
  2570. * no available Rx resources, the function resets the resource error flag.
  2571. *
  2572. * INPUT:
  2573. * struct mv643xx_private *mp Ethernet Port Control srtuct.
  2574. * struct pkt_info *p_pkt_info Information on returned buffer.
  2575. *
  2576. * OUTPUT:
  2577. * New available Rx resource in Rx descriptor ring.
  2578. *
  2579. * RETURN:
  2580. * ETH_ERROR in case the routine can not access Rx desc ring.
  2581. * ETH_OK otherwise.
  2582. */
  2583. static ETH_FUNC_RET_STATUS eth_rx_return_buff(struct mv643xx_private *mp,
  2584. struct pkt_info *p_pkt_info)
  2585. {
  2586. int used_rx_desc; /* Where to return Rx resource */
  2587. volatile struct eth_rx_desc *p_used_rx_desc;
  2588. unsigned long flags;
  2589. spin_lock_irqsave(&mp->lock, flags);
  2590. /* Get 'used' Rx descriptor */
  2591. used_rx_desc = mp->rx_used_desc_q;
  2592. p_used_rx_desc = &mp->p_rx_desc_area[used_rx_desc];
  2593. p_used_rx_desc->buf_ptr = p_pkt_info->buf_ptr;
  2594. p_used_rx_desc->buf_size = p_pkt_info->byte_cnt;
  2595. mp->rx_skb[used_rx_desc] = p_pkt_info->return_info;
  2596. /* Flush the write pipe */
  2597. /* Return the descriptor to DMA ownership */
  2598. wmb();
  2599. p_used_rx_desc->cmd_sts =
  2600. ETH_BUFFER_OWNED_BY_DMA | ETH_RX_ENABLE_INTERRUPT;
  2601. wmb();
  2602. /* Move the used descriptor pointer to the next descriptor */
  2603. mp->rx_used_desc_q = (used_rx_desc + 1) % mp->rx_ring_size;
  2604. /* Any Rx return cancels the Rx resource error status */
  2605. mp->rx_resource_err = 0;
  2606. spin_unlock_irqrestore(&mp->lock, flags);
  2607. return ETH_OK;
  2608. }
  2609. /************* Begin ethtool support *************************/
  2610. struct mv643xx_stats {
  2611. char stat_string[ETH_GSTRING_LEN];
  2612. int sizeof_stat;
  2613. int stat_offset;
  2614. };
  2615. #define MV643XX_STAT(m) sizeof(((struct mv643xx_private *)0)->m), \
  2616. offsetof(struct mv643xx_private, m)
  2617. static const struct mv643xx_stats mv643xx_gstrings_stats[] = {
  2618. { "rx_packets", MV643XX_STAT(stats.rx_packets) },
  2619. { "tx_packets", MV643XX_STAT(stats.tx_packets) },
  2620. { "rx_bytes", MV643XX_STAT(stats.rx_bytes) },
  2621. { "tx_bytes", MV643XX_STAT(stats.tx_bytes) },
  2622. { "rx_errors", MV643XX_STAT(stats.rx_errors) },
  2623. { "tx_errors", MV643XX_STAT(stats.tx_errors) },
  2624. { "rx_dropped", MV643XX_STAT(stats.rx_dropped) },
  2625. { "tx_dropped", MV643XX_STAT(stats.tx_dropped) },
  2626. { "good_octets_received", MV643XX_STAT(mib_counters.good_octets_received) },
  2627. { "bad_octets_received", MV643XX_STAT(mib_counters.bad_octets_received) },
  2628. { "internal_mac_transmit_err", MV643XX_STAT(mib_counters.internal_mac_transmit_err) },
  2629. { "good_frames_received", MV643XX_STAT(mib_counters.good_frames_received) },
  2630. { "bad_frames_received", MV643XX_STAT(mib_counters.bad_frames_received) },
  2631. { "broadcast_frames_received", MV643XX_STAT(mib_counters.broadcast_frames_received) },
  2632. { "multicast_frames_received", MV643XX_STAT(mib_counters.multicast_frames_received) },
  2633. { "frames_64_octets", MV643XX_STAT(mib_counters.frames_64_octets) },
  2634. { "frames_65_to_127_octets", MV643XX_STAT(mib_counters.frames_65_to_127_octets) },
  2635. { "frames_128_to_255_octets", MV643XX_STAT(mib_counters.frames_128_to_255_octets) },
  2636. { "frames_256_to_511_octets", MV643XX_STAT(mib_counters.frames_256_to_511_octets) },
  2637. { "frames_512_to_1023_octets", MV643XX_STAT(mib_counters.frames_512_to_1023_octets) },
  2638. { "frames_1024_to_max_octets", MV643XX_STAT(mib_counters.frames_1024_to_max_octets) },
  2639. { "good_octets_sent", MV643XX_STAT(mib_counters.good_octets_sent) },
  2640. { "good_frames_sent", MV643XX_STAT(mib_counters.good_frames_sent) },
  2641. { "excessive_collision", MV643XX_STAT(mib_counters.excessive_collision) },
  2642. { "multicast_frames_sent", MV643XX_STAT(mib_counters.multicast_frames_sent) },
  2643. { "broadcast_frames_sent", MV643XX_STAT(mib_counters.broadcast_frames_sent) },
  2644. { "unrec_mac_control_received", MV643XX_STAT(mib_counters.unrec_mac_control_received) },
  2645. { "fc_sent", MV643XX_STAT(mib_counters.fc_sent) },
  2646. { "good_fc_received", MV643XX_STAT(mib_counters.good_fc_received) },
  2647. { "bad_fc_received", MV643XX_STAT(mib_counters.bad_fc_received) },
  2648. { "undersize_received", MV643XX_STAT(mib_counters.undersize_received) },
  2649. { "fragments_received", MV643XX_STAT(mib_counters.fragments_received) },
  2650. { "oversize_received", MV643XX_STAT(mib_counters.oversize_received) },
  2651. { "jabber_received", MV643XX_STAT(mib_counters.jabber_received) },
  2652. { "mac_receive_error", MV643XX_STAT(mib_counters.mac_receive_error) },
  2653. { "bad_crc_event", MV643XX_STAT(mib_counters.bad_crc_event) },
  2654. { "collision", MV643XX_STAT(mib_counters.collision) },
  2655. { "late_collision", MV643XX_STAT(mib_counters.late_collision) },
  2656. };
  2657. #define MV643XX_STATS_LEN \
  2658. sizeof(mv643xx_gstrings_stats) / sizeof(struct mv643xx_stats)
  2659. static int
  2660. mv643xx_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  2661. {
  2662. struct mv643xx_private *mp = netdev->priv;
  2663. int port_num = mp->port_num;
  2664. int autoneg = eth_port_autoneg_supported(port_num);
  2665. int mode_10_bit;
  2666. int auto_duplex;
  2667. int half_duplex = 0;
  2668. int full_duplex = 0;
  2669. int auto_speed;
  2670. int speed_10 = 0;
  2671. int speed_100 = 0;
  2672. int speed_1000 = 0;
  2673. u32 pcs = mv_read(MV643XX_ETH_PORT_SERIAL_CONTROL_REG(port_num));
  2674. u32 psr = mv_read(MV643XX_ETH_PORT_STATUS_REG(port_num));
  2675. mode_10_bit = psr & MV643XX_ETH_PORT_STATUS_MODE_10_BIT;
  2676. if (mode_10_bit) {
  2677. ecmd->supported = SUPPORTED_10baseT_Half;
  2678. } else {
  2679. ecmd->supported = (SUPPORTED_10baseT_Half |
  2680. SUPPORTED_10baseT_Full |
  2681. SUPPORTED_100baseT_Half |
  2682. SUPPORTED_100baseT_Full |
  2683. SUPPORTED_1000baseT_Full |
  2684. (autoneg ? SUPPORTED_Autoneg : 0) |
  2685. SUPPORTED_TP);
  2686. auto_duplex = !(pcs & MV643XX_ETH_DISABLE_AUTO_NEG_FOR_DUPLX);
  2687. auto_speed = !(pcs & MV643XX_ETH_DISABLE_AUTO_NEG_SPEED_GMII);
  2688. ecmd->advertising = ADVERTISED_TP;
  2689. if (autoneg) {
  2690. ecmd->advertising |= ADVERTISED_Autoneg;
  2691. if (auto_duplex) {
  2692. half_duplex = 1;
  2693. full_duplex = 1;
  2694. } else {
  2695. if (pcs & MV643XX_ETH_SET_FULL_DUPLEX_MODE)
  2696. full_duplex = 1;
  2697. else
  2698. half_duplex = 1;
  2699. }
  2700. if (auto_speed) {
  2701. speed_10 = 1;
  2702. speed_100 = 1;
  2703. speed_1000 = 1;
  2704. } else {
  2705. if (pcs & MV643XX_ETH_SET_GMII_SPEED_TO_1000)
  2706. speed_1000 = 1;
  2707. else if (pcs & MV643XX_ETH_SET_MII_SPEED_TO_100)
  2708. speed_100 = 1;
  2709. else
  2710. speed_10 = 1;
  2711. }
  2712. if (speed_10 & half_duplex)
  2713. ecmd->advertising |= ADVERTISED_10baseT_Half;
  2714. if (speed_10 & full_duplex)
  2715. ecmd->advertising |= ADVERTISED_10baseT_Full;
  2716. if (speed_100 & half_duplex)
  2717. ecmd->advertising |= ADVERTISED_100baseT_Half;
  2718. if (speed_100 & full_duplex)
  2719. ecmd->advertising |= ADVERTISED_100baseT_Full;
  2720. if (speed_1000)
  2721. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  2722. }
  2723. }
  2724. ecmd->port = PORT_TP;
  2725. ecmd->phy_address = ethernet_phy_get(port_num);
  2726. ecmd->transceiver = XCVR_EXTERNAL;
  2727. if (netif_carrier_ok(netdev)) {
  2728. if (mode_10_bit)
  2729. ecmd->speed = SPEED_10;
  2730. else {
  2731. if (psr & MV643XX_ETH_PORT_STATUS_GMII_1000)
  2732. ecmd->speed = SPEED_1000;
  2733. else if (psr & MV643XX_ETH_PORT_STATUS_MII_100)
  2734. ecmd->speed = SPEED_100;
  2735. else
  2736. ecmd->speed = SPEED_10;
  2737. }
  2738. if (psr & MV643XX_ETH_PORT_STATUS_FULL_DUPLEX)
  2739. ecmd->duplex = DUPLEX_FULL;
  2740. else
  2741. ecmd->duplex = DUPLEX_HALF;
  2742. } else {
  2743. ecmd->speed = -1;
  2744. ecmd->duplex = -1;
  2745. }
  2746. ecmd->autoneg = autoneg ? AUTONEG_ENABLE : AUTONEG_DISABLE;
  2747. return 0;
  2748. }
  2749. static void
  2750. mv643xx_get_drvinfo(struct net_device *netdev,
  2751. struct ethtool_drvinfo *drvinfo)
  2752. {
  2753. strncpy(drvinfo->driver, mv643xx_driver_name, 32);
  2754. strncpy(drvinfo->version, mv643xx_driver_version, 32);
  2755. strncpy(drvinfo->fw_version, "N/A", 32);
  2756. strncpy(drvinfo->bus_info, "mv643xx", 32);
  2757. drvinfo->n_stats = MV643XX_STATS_LEN;
  2758. }
  2759. static int
  2760. mv643xx_get_stats_count(struct net_device *netdev)
  2761. {
  2762. return MV643XX_STATS_LEN;
  2763. }
  2764. static void
  2765. mv643xx_get_ethtool_stats(struct net_device *netdev,
  2766. struct ethtool_stats *stats, uint64_t *data)
  2767. {
  2768. struct mv643xx_private *mp = netdev->priv;
  2769. int i;
  2770. eth_update_mib_counters(mp);
  2771. for(i = 0; i < MV643XX_STATS_LEN; i++) {
  2772. char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset;
  2773. data[i] = (mv643xx_gstrings_stats[i].sizeof_stat ==
  2774. sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
  2775. }
  2776. }
  2777. static void
  2778. mv643xx_get_strings(struct net_device *netdev, uint32_t stringset, uint8_t *data)
  2779. {
  2780. int i;
  2781. switch(stringset) {
  2782. case ETH_SS_STATS:
  2783. for (i=0; i < MV643XX_STATS_LEN; i++) {
  2784. memcpy(data + i * ETH_GSTRING_LEN,
  2785. mv643xx_gstrings_stats[i].stat_string,
  2786. ETH_GSTRING_LEN);
  2787. }
  2788. break;
  2789. }
  2790. }
  2791. static struct ethtool_ops mv643xx_ethtool_ops = {
  2792. .get_settings = mv643xx_get_settings,
  2793. .get_drvinfo = mv643xx_get_drvinfo,
  2794. .get_link = ethtool_op_get_link,
  2795. .get_sg = ethtool_op_get_sg,
  2796. .set_sg = ethtool_op_set_sg,
  2797. .get_strings = mv643xx_get_strings,
  2798. .get_stats_count = mv643xx_get_stats_count,
  2799. .get_ethtool_stats = mv643xx_get_ethtool_stats,
  2800. };
  2801. /************* End ethtool support *************************/