mv643xx_eth.c 93 KB

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