gianfar.c 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427
  1. /* drivers/net/ethernet/freescale/gianfar.c
  2. *
  3. * Gianfar Ethernet Driver
  4. * This driver is designed for the non-CPM ethernet controllers
  5. * on the 85xx and 83xx family of integrated processors
  6. * Based on 8260_io/fcc_enet.c
  7. *
  8. * Author: Andy Fleming
  9. * Maintainer: Kumar Gala
  10. * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
  11. *
  12. * Copyright 2002-2009, 2011 Freescale Semiconductor, Inc.
  13. * Copyright 2007 MontaVista Software, Inc.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. *
  20. * Gianfar: AKA Lambda Draconis, "Dragon"
  21. * RA 11 31 24.2
  22. * Dec +69 19 52
  23. * V 3.84
  24. * B-V +1.62
  25. *
  26. * Theory of operation
  27. *
  28. * The driver is initialized through of_device. Configuration information
  29. * is therefore conveyed through an OF-style device tree.
  30. *
  31. * The Gianfar Ethernet Controller uses a ring of buffer
  32. * descriptors. The beginning is indicated by a register
  33. * pointing to the physical address of the start of the ring.
  34. * The end is determined by a "wrap" bit being set in the
  35. * last descriptor of the ring.
  36. *
  37. * When a packet is received, the RXF bit in the
  38. * IEVENT register is set, triggering an interrupt when the
  39. * corresponding bit in the IMASK register is also set (if
  40. * interrupt coalescing is active, then the interrupt may not
  41. * happen immediately, but will wait until either a set number
  42. * of frames or amount of time have passed). In NAPI, the
  43. * interrupt handler will signal there is work to be done, and
  44. * exit. This method will start at the last known empty
  45. * descriptor, and process every subsequent descriptor until there
  46. * are none left with data (NAPI will stop after a set number of
  47. * packets to give time to other tasks, but will eventually
  48. * process all the packets). The data arrives inside a
  49. * pre-allocated skb, and so after the skb is passed up to the
  50. * stack, a new skb must be allocated, and the address field in
  51. * the buffer descriptor must be updated to indicate this new
  52. * skb.
  53. *
  54. * When the kernel requests that a packet be transmitted, the
  55. * driver starts where it left off last time, and points the
  56. * descriptor at the buffer which was passed in. The driver
  57. * then informs the DMA engine that there are packets ready to
  58. * be transmitted. Once the controller is finished transmitting
  59. * the packet, an interrupt may be triggered (under the same
  60. * conditions as for reception, but depending on the TXF bit).
  61. * The driver then cleans up the buffer.
  62. */
  63. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  64. #define DEBUG
  65. #include <linux/kernel.h>
  66. #include <linux/string.h>
  67. #include <linux/errno.h>
  68. #include <linux/unistd.h>
  69. #include <linux/slab.h>
  70. #include <linux/interrupt.h>
  71. #include <linux/init.h>
  72. #include <linux/delay.h>
  73. #include <linux/netdevice.h>
  74. #include <linux/etherdevice.h>
  75. #include <linux/skbuff.h>
  76. #include <linux/if_vlan.h>
  77. #include <linux/spinlock.h>
  78. #include <linux/mm.h>
  79. #include <linux/of_mdio.h>
  80. #include <linux/of_platform.h>
  81. #include <linux/ip.h>
  82. #include <linux/tcp.h>
  83. #include <linux/udp.h>
  84. #include <linux/in.h>
  85. #include <linux/net_tstamp.h>
  86. #include <asm/io.h>
  87. #include <asm/reg.h>
  88. #include <asm/irq.h>
  89. #include <asm/uaccess.h>
  90. #include <linux/module.h>
  91. #include <linux/dma-mapping.h>
  92. #include <linux/crc32.h>
  93. #include <linux/mii.h>
  94. #include <linux/phy.h>
  95. #include <linux/phy_fixed.h>
  96. #include <linux/of.h>
  97. #include <linux/of_net.h>
  98. #include "gianfar.h"
  99. #define TX_TIMEOUT (1*HZ)
  100. const char gfar_driver_version[] = "1.3";
  101. static int gfar_enet_open(struct net_device *dev);
  102. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
  103. static void gfar_reset_task(struct work_struct *work);
  104. static void gfar_timeout(struct net_device *dev);
  105. static int gfar_close(struct net_device *dev);
  106. struct sk_buff *gfar_new_skb(struct net_device *dev);
  107. static void gfar_new_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp,
  108. struct sk_buff *skb);
  109. static int gfar_set_mac_address(struct net_device *dev);
  110. static int gfar_change_mtu(struct net_device *dev, int new_mtu);
  111. static irqreturn_t gfar_error(int irq, void *dev_id);
  112. static irqreturn_t gfar_transmit(int irq, void *dev_id);
  113. static irqreturn_t gfar_interrupt(int irq, void *dev_id);
  114. static void adjust_link(struct net_device *dev);
  115. static void init_registers(struct net_device *dev);
  116. static int init_phy(struct net_device *dev);
  117. static int gfar_probe(struct platform_device *ofdev);
  118. static int gfar_remove(struct platform_device *ofdev);
  119. static void free_skb_resources(struct gfar_private *priv);
  120. static void gfar_set_multi(struct net_device *dev);
  121. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr);
  122. static void gfar_configure_serdes(struct net_device *dev);
  123. static int gfar_poll(struct napi_struct *napi, int budget);
  124. static int gfar_poll_sq(struct napi_struct *napi, int budget);
  125. #ifdef CONFIG_NET_POLL_CONTROLLER
  126. static void gfar_netpoll(struct net_device *dev);
  127. #endif
  128. int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit);
  129. static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue);
  130. static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  131. int amount_pull, struct napi_struct *napi);
  132. void gfar_halt(struct net_device *dev);
  133. static void gfar_halt_nodisable(struct net_device *dev);
  134. void gfar_start(struct net_device *dev);
  135. static void gfar_clear_exact_match(struct net_device *dev);
  136. static void gfar_set_mac_for_addr(struct net_device *dev, int num,
  137. const u8 *addr);
  138. static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  139. MODULE_AUTHOR("Freescale Semiconductor, Inc");
  140. MODULE_DESCRIPTION("Gianfar Ethernet Driver");
  141. MODULE_LICENSE("GPL");
  142. static void gfar_init_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp,
  143. dma_addr_t buf)
  144. {
  145. u32 lstatus;
  146. bdp->bufPtr = buf;
  147. lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
  148. if (bdp == rx_queue->rx_bd_base + rx_queue->rx_ring_size - 1)
  149. lstatus |= BD_LFLAG(RXBD_WRAP);
  150. eieio();
  151. bdp->lstatus = lstatus;
  152. }
  153. static int gfar_init_bds(struct net_device *ndev)
  154. {
  155. struct gfar_private *priv = netdev_priv(ndev);
  156. struct gfar_priv_tx_q *tx_queue = NULL;
  157. struct gfar_priv_rx_q *rx_queue = NULL;
  158. struct txbd8 *txbdp;
  159. struct rxbd8 *rxbdp;
  160. int i, j;
  161. for (i = 0; i < priv->num_tx_queues; i++) {
  162. tx_queue = priv->tx_queue[i];
  163. /* Initialize some variables in our dev structure */
  164. tx_queue->num_txbdfree = tx_queue->tx_ring_size;
  165. tx_queue->dirty_tx = tx_queue->tx_bd_base;
  166. tx_queue->cur_tx = tx_queue->tx_bd_base;
  167. tx_queue->skb_curtx = 0;
  168. tx_queue->skb_dirtytx = 0;
  169. /* Initialize Transmit Descriptor Ring */
  170. txbdp = tx_queue->tx_bd_base;
  171. for (j = 0; j < tx_queue->tx_ring_size; j++) {
  172. txbdp->lstatus = 0;
  173. txbdp->bufPtr = 0;
  174. txbdp++;
  175. }
  176. /* Set the last descriptor in the ring to indicate wrap */
  177. txbdp--;
  178. txbdp->status |= TXBD_WRAP;
  179. }
  180. for (i = 0; i < priv->num_rx_queues; i++) {
  181. rx_queue = priv->rx_queue[i];
  182. rx_queue->cur_rx = rx_queue->rx_bd_base;
  183. rx_queue->skb_currx = 0;
  184. rxbdp = rx_queue->rx_bd_base;
  185. for (j = 0; j < rx_queue->rx_ring_size; j++) {
  186. struct sk_buff *skb = rx_queue->rx_skbuff[j];
  187. if (skb) {
  188. gfar_init_rxbdp(rx_queue, rxbdp,
  189. rxbdp->bufPtr);
  190. } else {
  191. skb = gfar_new_skb(ndev);
  192. if (!skb) {
  193. netdev_err(ndev, "Can't allocate RX buffers\n");
  194. return -ENOMEM;
  195. }
  196. rx_queue->rx_skbuff[j] = skb;
  197. gfar_new_rxbdp(rx_queue, rxbdp, skb);
  198. }
  199. rxbdp++;
  200. }
  201. }
  202. return 0;
  203. }
  204. static int gfar_alloc_skb_resources(struct net_device *ndev)
  205. {
  206. void *vaddr;
  207. dma_addr_t addr;
  208. int i, j, k;
  209. struct gfar_private *priv = netdev_priv(ndev);
  210. struct device *dev = priv->dev;
  211. struct gfar_priv_tx_q *tx_queue = NULL;
  212. struct gfar_priv_rx_q *rx_queue = NULL;
  213. priv->total_tx_ring_size = 0;
  214. for (i = 0; i < priv->num_tx_queues; i++)
  215. priv->total_tx_ring_size += priv->tx_queue[i]->tx_ring_size;
  216. priv->total_rx_ring_size = 0;
  217. for (i = 0; i < priv->num_rx_queues; i++)
  218. priv->total_rx_ring_size += priv->rx_queue[i]->rx_ring_size;
  219. /* Allocate memory for the buffer descriptors */
  220. vaddr = dma_alloc_coherent(dev,
  221. (priv->total_tx_ring_size *
  222. sizeof(struct txbd8)) +
  223. (priv->total_rx_ring_size *
  224. sizeof(struct rxbd8)),
  225. &addr, GFP_KERNEL);
  226. if (!vaddr)
  227. return -ENOMEM;
  228. for (i = 0; i < priv->num_tx_queues; i++) {
  229. tx_queue = priv->tx_queue[i];
  230. tx_queue->tx_bd_base = vaddr;
  231. tx_queue->tx_bd_dma_base = addr;
  232. tx_queue->dev = ndev;
  233. /* enet DMA only understands physical addresses */
  234. addr += sizeof(struct txbd8) * tx_queue->tx_ring_size;
  235. vaddr += sizeof(struct txbd8) * tx_queue->tx_ring_size;
  236. }
  237. /* Start the rx descriptor ring where the tx ring leaves off */
  238. for (i = 0; i < priv->num_rx_queues; i++) {
  239. rx_queue = priv->rx_queue[i];
  240. rx_queue->rx_bd_base = vaddr;
  241. rx_queue->rx_bd_dma_base = addr;
  242. rx_queue->dev = ndev;
  243. addr += sizeof(struct rxbd8) * rx_queue->rx_ring_size;
  244. vaddr += sizeof(struct rxbd8) * rx_queue->rx_ring_size;
  245. }
  246. /* Setup the skbuff rings */
  247. for (i = 0; i < priv->num_tx_queues; i++) {
  248. tx_queue = priv->tx_queue[i];
  249. tx_queue->tx_skbuff =
  250. kmalloc_array(tx_queue->tx_ring_size,
  251. sizeof(*tx_queue->tx_skbuff),
  252. GFP_KERNEL);
  253. if (!tx_queue->tx_skbuff)
  254. goto cleanup;
  255. for (k = 0; k < tx_queue->tx_ring_size; k++)
  256. tx_queue->tx_skbuff[k] = NULL;
  257. }
  258. for (i = 0; i < priv->num_rx_queues; i++) {
  259. rx_queue = priv->rx_queue[i];
  260. rx_queue->rx_skbuff =
  261. kmalloc_array(rx_queue->rx_ring_size,
  262. sizeof(*rx_queue->rx_skbuff),
  263. GFP_KERNEL);
  264. if (!rx_queue->rx_skbuff)
  265. goto cleanup;
  266. for (j = 0; j < rx_queue->rx_ring_size; j++)
  267. rx_queue->rx_skbuff[j] = NULL;
  268. }
  269. if (gfar_init_bds(ndev))
  270. goto cleanup;
  271. return 0;
  272. cleanup:
  273. free_skb_resources(priv);
  274. return -ENOMEM;
  275. }
  276. static void gfar_init_tx_rx_base(struct gfar_private *priv)
  277. {
  278. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  279. u32 __iomem *baddr;
  280. int i;
  281. baddr = &regs->tbase0;
  282. for (i = 0; i < priv->num_tx_queues; i++) {
  283. gfar_write(baddr, priv->tx_queue[i]->tx_bd_dma_base);
  284. baddr += 2;
  285. }
  286. baddr = &regs->rbase0;
  287. for (i = 0; i < priv->num_rx_queues; i++) {
  288. gfar_write(baddr, priv->rx_queue[i]->rx_bd_dma_base);
  289. baddr += 2;
  290. }
  291. }
  292. static void gfar_init_mac(struct net_device *ndev)
  293. {
  294. struct gfar_private *priv = netdev_priv(ndev);
  295. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  296. u32 rctrl = 0;
  297. u32 tctrl = 0;
  298. u32 attrs = 0;
  299. /* write the tx/rx base registers */
  300. gfar_init_tx_rx_base(priv);
  301. /* Configure the coalescing support */
  302. gfar_configure_coalescing_all(priv);
  303. /* set this when rx hw offload (TOE) functions are being used */
  304. priv->uses_rxfcb = 0;
  305. if (priv->rx_filer_enable) {
  306. rctrl |= RCTRL_FILREN;
  307. /* Program the RIR0 reg with the required distribution */
  308. gfar_write(&regs->rir0, DEFAULT_RIR0);
  309. }
  310. /* Restore PROMISC mode */
  311. if (ndev->flags & IFF_PROMISC)
  312. rctrl |= RCTRL_PROM;
  313. if (ndev->features & NETIF_F_RXCSUM) {
  314. rctrl |= RCTRL_CHECKSUMMING;
  315. priv->uses_rxfcb = 1;
  316. }
  317. if (priv->extended_hash) {
  318. rctrl |= RCTRL_EXTHASH;
  319. gfar_clear_exact_match(ndev);
  320. rctrl |= RCTRL_EMEN;
  321. }
  322. if (priv->padding) {
  323. rctrl &= ~RCTRL_PAL_MASK;
  324. rctrl |= RCTRL_PADDING(priv->padding);
  325. }
  326. /* Insert receive time stamps into padding alignment bytes */
  327. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER) {
  328. rctrl &= ~RCTRL_PAL_MASK;
  329. rctrl |= RCTRL_PADDING(8);
  330. priv->padding = 8;
  331. }
  332. /* Enable HW time stamping if requested from user space */
  333. if (priv->hwts_rx_en) {
  334. rctrl |= RCTRL_PRSDEP_INIT | RCTRL_TS_ENABLE;
  335. priv->uses_rxfcb = 1;
  336. }
  337. if (ndev->features & NETIF_F_HW_VLAN_CTAG_RX) {
  338. rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT;
  339. priv->uses_rxfcb = 1;
  340. }
  341. /* Init rctrl based on our settings */
  342. gfar_write(&regs->rctrl, rctrl);
  343. if (ndev->features & NETIF_F_IP_CSUM)
  344. tctrl |= TCTRL_INIT_CSUM;
  345. if (priv->prio_sched_en)
  346. tctrl |= TCTRL_TXSCHED_PRIO;
  347. else {
  348. tctrl |= TCTRL_TXSCHED_WRRS;
  349. gfar_write(&regs->tr03wt, DEFAULT_WRRS_WEIGHT);
  350. gfar_write(&regs->tr47wt, DEFAULT_WRRS_WEIGHT);
  351. }
  352. gfar_write(&regs->tctrl, tctrl);
  353. /* Set the extraction length and index */
  354. attrs = ATTRELI_EL(priv->rx_stash_size) |
  355. ATTRELI_EI(priv->rx_stash_index);
  356. gfar_write(&regs->attreli, attrs);
  357. /* Start with defaults, and add stashing or locking
  358. * depending on the approprate variables
  359. */
  360. attrs = ATTR_INIT_SETTINGS;
  361. if (priv->bd_stash_en)
  362. attrs |= ATTR_BDSTASH;
  363. if (priv->rx_stash_size != 0)
  364. attrs |= ATTR_BUFSTASH;
  365. gfar_write(&regs->attr, attrs);
  366. gfar_write(&regs->fifo_tx_thr, priv->fifo_threshold);
  367. gfar_write(&regs->fifo_tx_starve, priv->fifo_starve);
  368. gfar_write(&regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
  369. }
  370. static struct net_device_stats *gfar_get_stats(struct net_device *dev)
  371. {
  372. struct gfar_private *priv = netdev_priv(dev);
  373. unsigned long rx_packets = 0, rx_bytes = 0, rx_dropped = 0;
  374. unsigned long tx_packets = 0, tx_bytes = 0;
  375. int i;
  376. for (i = 0; i < priv->num_rx_queues; i++) {
  377. rx_packets += priv->rx_queue[i]->stats.rx_packets;
  378. rx_bytes += priv->rx_queue[i]->stats.rx_bytes;
  379. rx_dropped += priv->rx_queue[i]->stats.rx_dropped;
  380. }
  381. dev->stats.rx_packets = rx_packets;
  382. dev->stats.rx_bytes = rx_bytes;
  383. dev->stats.rx_dropped = rx_dropped;
  384. for (i = 0; i < priv->num_tx_queues; i++) {
  385. tx_bytes += priv->tx_queue[i]->stats.tx_bytes;
  386. tx_packets += priv->tx_queue[i]->stats.tx_packets;
  387. }
  388. dev->stats.tx_bytes = tx_bytes;
  389. dev->stats.tx_packets = tx_packets;
  390. return &dev->stats;
  391. }
  392. static const struct net_device_ops gfar_netdev_ops = {
  393. .ndo_open = gfar_enet_open,
  394. .ndo_start_xmit = gfar_start_xmit,
  395. .ndo_stop = gfar_close,
  396. .ndo_change_mtu = gfar_change_mtu,
  397. .ndo_set_features = gfar_set_features,
  398. .ndo_set_rx_mode = gfar_set_multi,
  399. .ndo_tx_timeout = gfar_timeout,
  400. .ndo_do_ioctl = gfar_ioctl,
  401. .ndo_get_stats = gfar_get_stats,
  402. .ndo_set_mac_address = eth_mac_addr,
  403. .ndo_validate_addr = eth_validate_addr,
  404. #ifdef CONFIG_NET_POLL_CONTROLLER
  405. .ndo_poll_controller = gfar_netpoll,
  406. #endif
  407. };
  408. void lock_rx_qs(struct gfar_private *priv)
  409. {
  410. int i;
  411. for (i = 0; i < priv->num_rx_queues; i++)
  412. spin_lock(&priv->rx_queue[i]->rxlock);
  413. }
  414. void lock_tx_qs(struct gfar_private *priv)
  415. {
  416. int i;
  417. for (i = 0; i < priv->num_tx_queues; i++)
  418. spin_lock(&priv->tx_queue[i]->txlock);
  419. }
  420. void unlock_rx_qs(struct gfar_private *priv)
  421. {
  422. int i;
  423. for (i = 0; i < priv->num_rx_queues; i++)
  424. spin_unlock(&priv->rx_queue[i]->rxlock);
  425. }
  426. void unlock_tx_qs(struct gfar_private *priv)
  427. {
  428. int i;
  429. for (i = 0; i < priv->num_tx_queues; i++)
  430. spin_unlock(&priv->tx_queue[i]->txlock);
  431. }
  432. static void free_tx_pointers(struct gfar_private *priv)
  433. {
  434. int i;
  435. for (i = 0; i < priv->num_tx_queues; i++)
  436. kfree(priv->tx_queue[i]);
  437. }
  438. static void free_rx_pointers(struct gfar_private *priv)
  439. {
  440. int i;
  441. for (i = 0; i < priv->num_rx_queues; i++)
  442. kfree(priv->rx_queue[i]);
  443. }
  444. static void unmap_group_regs(struct gfar_private *priv)
  445. {
  446. int i;
  447. for (i = 0; i < MAXGROUPS; i++)
  448. if (priv->gfargrp[i].regs)
  449. iounmap(priv->gfargrp[i].regs);
  450. }
  451. static void free_gfar_dev(struct gfar_private *priv)
  452. {
  453. int i, j;
  454. for (i = 0; i < priv->num_grps; i++)
  455. for (j = 0; j < GFAR_NUM_IRQS; j++) {
  456. kfree(priv->gfargrp[i].irqinfo[j]);
  457. priv->gfargrp[i].irqinfo[j] = NULL;
  458. }
  459. free_netdev(priv->ndev);
  460. }
  461. static void disable_napi(struct gfar_private *priv)
  462. {
  463. int i;
  464. for (i = 0; i < priv->num_grps; i++)
  465. napi_disable(&priv->gfargrp[i].napi);
  466. }
  467. static void enable_napi(struct gfar_private *priv)
  468. {
  469. int i;
  470. for (i = 0; i < priv->num_grps; i++)
  471. napi_enable(&priv->gfargrp[i].napi);
  472. }
  473. static int gfar_parse_group(struct device_node *np,
  474. struct gfar_private *priv, const char *model)
  475. {
  476. struct gfar_priv_grp *grp = &priv->gfargrp[priv->num_grps];
  477. u32 *queue_mask;
  478. int i;
  479. for (i = 0; i < GFAR_NUM_IRQS; i++) {
  480. grp->irqinfo[i] = kzalloc(sizeof(struct gfar_irqinfo),
  481. GFP_KERNEL);
  482. if (!grp->irqinfo[i])
  483. return -ENOMEM;
  484. }
  485. grp->regs = of_iomap(np, 0);
  486. if (!grp->regs)
  487. return -ENOMEM;
  488. gfar_irq(grp, TX)->irq = irq_of_parse_and_map(np, 0);
  489. /* If we aren't the FEC we have multiple interrupts */
  490. if (model && strcasecmp(model, "FEC")) {
  491. gfar_irq(grp, RX)->irq = irq_of_parse_and_map(np, 1);
  492. gfar_irq(grp, ER)->irq = irq_of_parse_and_map(np, 2);
  493. if (gfar_irq(grp, TX)->irq == NO_IRQ ||
  494. gfar_irq(grp, RX)->irq == NO_IRQ ||
  495. gfar_irq(grp, ER)->irq == NO_IRQ)
  496. return -EINVAL;
  497. }
  498. grp->priv = priv;
  499. spin_lock_init(&grp->grplock);
  500. if (priv->mode == MQ_MG_MODE) {
  501. queue_mask = (u32 *)of_get_property(np, "fsl,rx-bit-map", NULL);
  502. grp->rx_bit_map = queue_mask ?
  503. *queue_mask : (DEFAULT_MAPPING >> priv->num_grps);
  504. queue_mask = (u32 *)of_get_property(np, "fsl,tx-bit-map", NULL);
  505. grp->tx_bit_map = queue_mask ?
  506. *queue_mask : (DEFAULT_MAPPING >> priv->num_grps);
  507. } else {
  508. grp->rx_bit_map = 0xFF;
  509. grp->tx_bit_map = 0xFF;
  510. }
  511. priv->num_grps++;
  512. return 0;
  513. }
  514. static int gfar_of_init(struct platform_device *ofdev, struct net_device **pdev)
  515. {
  516. const char *model;
  517. const char *ctype;
  518. const void *mac_addr;
  519. int err = 0, i;
  520. struct net_device *dev = NULL;
  521. struct gfar_private *priv = NULL;
  522. struct device_node *np = ofdev->dev.of_node;
  523. struct device_node *child = NULL;
  524. const u32 *stash;
  525. const u32 *stash_len;
  526. const u32 *stash_idx;
  527. unsigned int num_tx_qs, num_rx_qs;
  528. u32 *tx_queues, *rx_queues;
  529. if (!np || !of_device_is_available(np))
  530. return -ENODEV;
  531. /* parse the num of tx and rx queues */
  532. tx_queues = (u32 *)of_get_property(np, "fsl,num_tx_queues", NULL);
  533. num_tx_qs = tx_queues ? *tx_queues : 1;
  534. if (num_tx_qs > MAX_TX_QS) {
  535. pr_err("num_tx_qs(=%d) greater than MAX_TX_QS(=%d)\n",
  536. num_tx_qs, MAX_TX_QS);
  537. pr_err("Cannot do alloc_etherdev, aborting\n");
  538. return -EINVAL;
  539. }
  540. rx_queues = (u32 *)of_get_property(np, "fsl,num_rx_queues", NULL);
  541. num_rx_qs = rx_queues ? *rx_queues : 1;
  542. if (num_rx_qs > MAX_RX_QS) {
  543. pr_err("num_rx_qs(=%d) greater than MAX_RX_QS(=%d)\n",
  544. num_rx_qs, MAX_RX_QS);
  545. pr_err("Cannot do alloc_etherdev, aborting\n");
  546. return -EINVAL;
  547. }
  548. *pdev = alloc_etherdev_mq(sizeof(*priv), num_tx_qs);
  549. dev = *pdev;
  550. if (NULL == dev)
  551. return -ENOMEM;
  552. priv = netdev_priv(dev);
  553. priv->ndev = dev;
  554. priv->num_tx_queues = num_tx_qs;
  555. netif_set_real_num_rx_queues(dev, num_rx_qs);
  556. priv->num_rx_queues = num_rx_qs;
  557. priv->num_grps = 0x0;
  558. /* Init Rx queue filer rule set linked list */
  559. INIT_LIST_HEAD(&priv->rx_list.list);
  560. priv->rx_list.count = 0;
  561. mutex_init(&priv->rx_queue_access);
  562. model = of_get_property(np, "model", NULL);
  563. for (i = 0; i < MAXGROUPS; i++)
  564. priv->gfargrp[i].regs = NULL;
  565. /* Parse and initialize group specific information */
  566. if (of_device_is_compatible(np, "fsl,etsec2")) {
  567. priv->mode = MQ_MG_MODE;
  568. for_each_child_of_node(np, child) {
  569. err = gfar_parse_group(child, priv, model);
  570. if (err)
  571. goto err_grp_init;
  572. }
  573. } else {
  574. priv->mode = SQ_SG_MODE;
  575. err = gfar_parse_group(np, priv, model);
  576. if (err)
  577. goto err_grp_init;
  578. }
  579. for (i = 0; i < priv->num_tx_queues; i++)
  580. priv->tx_queue[i] = NULL;
  581. for (i = 0; i < priv->num_rx_queues; i++)
  582. priv->rx_queue[i] = NULL;
  583. for (i = 0; i < priv->num_tx_queues; i++) {
  584. priv->tx_queue[i] = kzalloc(sizeof(struct gfar_priv_tx_q),
  585. GFP_KERNEL);
  586. if (!priv->tx_queue[i]) {
  587. err = -ENOMEM;
  588. goto tx_alloc_failed;
  589. }
  590. priv->tx_queue[i]->tx_skbuff = NULL;
  591. priv->tx_queue[i]->qindex = i;
  592. priv->tx_queue[i]->dev = dev;
  593. spin_lock_init(&(priv->tx_queue[i]->txlock));
  594. }
  595. for (i = 0; i < priv->num_rx_queues; i++) {
  596. priv->rx_queue[i] = kzalloc(sizeof(struct gfar_priv_rx_q),
  597. GFP_KERNEL);
  598. if (!priv->rx_queue[i]) {
  599. err = -ENOMEM;
  600. goto rx_alloc_failed;
  601. }
  602. priv->rx_queue[i]->rx_skbuff = NULL;
  603. priv->rx_queue[i]->qindex = i;
  604. priv->rx_queue[i]->dev = dev;
  605. spin_lock_init(&(priv->rx_queue[i]->rxlock));
  606. }
  607. stash = of_get_property(np, "bd-stash", NULL);
  608. if (stash) {
  609. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
  610. priv->bd_stash_en = 1;
  611. }
  612. stash_len = of_get_property(np, "rx-stash-len", NULL);
  613. if (stash_len)
  614. priv->rx_stash_size = *stash_len;
  615. stash_idx = of_get_property(np, "rx-stash-idx", NULL);
  616. if (stash_idx)
  617. priv->rx_stash_index = *stash_idx;
  618. if (stash_len || stash_idx)
  619. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
  620. mac_addr = of_get_mac_address(np);
  621. if (mac_addr)
  622. memcpy(dev->dev_addr, mac_addr, ETH_ALEN);
  623. if (model && !strcasecmp(model, "TSEC"))
  624. priv->device_flags = FSL_GIANFAR_DEV_HAS_GIGABIT |
  625. FSL_GIANFAR_DEV_HAS_COALESCE |
  626. FSL_GIANFAR_DEV_HAS_RMON |
  627. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  628. if (model && !strcasecmp(model, "eTSEC"))
  629. priv->device_flags = FSL_GIANFAR_DEV_HAS_GIGABIT |
  630. FSL_GIANFAR_DEV_HAS_COALESCE |
  631. FSL_GIANFAR_DEV_HAS_RMON |
  632. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  633. FSL_GIANFAR_DEV_HAS_PADDING |
  634. FSL_GIANFAR_DEV_HAS_CSUM |
  635. FSL_GIANFAR_DEV_HAS_VLAN |
  636. FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
  637. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH |
  638. FSL_GIANFAR_DEV_HAS_TIMER;
  639. ctype = of_get_property(np, "phy-connection-type", NULL);
  640. /* We only care about rgmii-id. The rest are autodetected */
  641. if (ctype && !strcmp(ctype, "rgmii-id"))
  642. priv->interface = PHY_INTERFACE_MODE_RGMII_ID;
  643. else
  644. priv->interface = PHY_INTERFACE_MODE_MII;
  645. if (of_get_property(np, "fsl,magic-packet", NULL))
  646. priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
  647. priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
  648. /* Find the TBI PHY. If it's not there, we don't support SGMII */
  649. priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
  650. return 0;
  651. rx_alloc_failed:
  652. free_rx_pointers(priv);
  653. tx_alloc_failed:
  654. free_tx_pointers(priv);
  655. err_grp_init:
  656. unmap_group_regs(priv);
  657. free_gfar_dev(priv);
  658. return err;
  659. }
  660. static int gfar_hwtstamp_ioctl(struct net_device *netdev,
  661. struct ifreq *ifr, int cmd)
  662. {
  663. struct hwtstamp_config config;
  664. struct gfar_private *priv = netdev_priv(netdev);
  665. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  666. return -EFAULT;
  667. /* reserved for future extensions */
  668. if (config.flags)
  669. return -EINVAL;
  670. switch (config.tx_type) {
  671. case HWTSTAMP_TX_OFF:
  672. priv->hwts_tx_en = 0;
  673. break;
  674. case HWTSTAMP_TX_ON:
  675. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
  676. return -ERANGE;
  677. priv->hwts_tx_en = 1;
  678. break;
  679. default:
  680. return -ERANGE;
  681. }
  682. switch (config.rx_filter) {
  683. case HWTSTAMP_FILTER_NONE:
  684. if (priv->hwts_rx_en) {
  685. stop_gfar(netdev);
  686. priv->hwts_rx_en = 0;
  687. startup_gfar(netdev);
  688. }
  689. break;
  690. default:
  691. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER))
  692. return -ERANGE;
  693. if (!priv->hwts_rx_en) {
  694. stop_gfar(netdev);
  695. priv->hwts_rx_en = 1;
  696. startup_gfar(netdev);
  697. }
  698. config.rx_filter = HWTSTAMP_FILTER_ALL;
  699. break;
  700. }
  701. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  702. -EFAULT : 0;
  703. }
  704. /* Ioctl MII Interface */
  705. static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  706. {
  707. struct gfar_private *priv = netdev_priv(dev);
  708. if (!netif_running(dev))
  709. return -EINVAL;
  710. if (cmd == SIOCSHWTSTAMP)
  711. return gfar_hwtstamp_ioctl(dev, rq, cmd);
  712. if (!priv->phydev)
  713. return -ENODEV;
  714. return phy_mii_ioctl(priv->phydev, rq, cmd);
  715. }
  716. static unsigned int reverse_bitmap(unsigned int bit_map, unsigned int max_qs)
  717. {
  718. unsigned int new_bit_map = 0x0;
  719. int mask = 0x1 << (max_qs - 1), i;
  720. for (i = 0; i < max_qs; i++) {
  721. if (bit_map & mask)
  722. new_bit_map = new_bit_map + (1 << i);
  723. mask = mask >> 0x1;
  724. }
  725. return new_bit_map;
  726. }
  727. static u32 cluster_entry_per_class(struct gfar_private *priv, u32 rqfar,
  728. u32 class)
  729. {
  730. u32 rqfpr = FPR_FILER_MASK;
  731. u32 rqfcr = 0x0;
  732. rqfar--;
  733. rqfcr = RQFCR_CLE | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
  734. priv->ftp_rqfpr[rqfar] = rqfpr;
  735. priv->ftp_rqfcr[rqfar] = rqfcr;
  736. gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
  737. rqfar--;
  738. rqfcr = RQFCR_CMP_NOMATCH;
  739. priv->ftp_rqfpr[rqfar] = rqfpr;
  740. priv->ftp_rqfcr[rqfar] = rqfcr;
  741. gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
  742. rqfar--;
  743. rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND;
  744. rqfpr = class;
  745. priv->ftp_rqfcr[rqfar] = rqfcr;
  746. priv->ftp_rqfpr[rqfar] = rqfpr;
  747. gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
  748. rqfar--;
  749. rqfcr = RQFCR_CMP_EXACT | RQFCR_PID_MASK | RQFCR_AND;
  750. rqfpr = class;
  751. priv->ftp_rqfcr[rqfar] = rqfcr;
  752. priv->ftp_rqfpr[rqfar] = rqfpr;
  753. gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
  754. return rqfar;
  755. }
  756. static void gfar_init_filer_table(struct gfar_private *priv)
  757. {
  758. int i = 0x0;
  759. u32 rqfar = MAX_FILER_IDX;
  760. u32 rqfcr = 0x0;
  761. u32 rqfpr = FPR_FILER_MASK;
  762. /* Default rule */
  763. rqfcr = RQFCR_CMP_MATCH;
  764. priv->ftp_rqfcr[rqfar] = rqfcr;
  765. priv->ftp_rqfpr[rqfar] = rqfpr;
  766. gfar_write_filer(priv, rqfar, rqfcr, rqfpr);
  767. rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6);
  768. rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_UDP);
  769. rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV6 | RQFPR_TCP);
  770. rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4);
  771. rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_UDP);
  772. rqfar = cluster_entry_per_class(priv, rqfar, RQFPR_IPV4 | RQFPR_TCP);
  773. /* cur_filer_idx indicated the first non-masked rule */
  774. priv->cur_filer_idx = rqfar;
  775. /* Rest are masked rules */
  776. rqfcr = RQFCR_CMP_NOMATCH;
  777. for (i = 0; i < rqfar; i++) {
  778. priv->ftp_rqfcr[i] = rqfcr;
  779. priv->ftp_rqfpr[i] = rqfpr;
  780. gfar_write_filer(priv, i, rqfcr, rqfpr);
  781. }
  782. }
  783. static void gfar_detect_errata(struct gfar_private *priv)
  784. {
  785. struct device *dev = &priv->ofdev->dev;
  786. unsigned int pvr = mfspr(SPRN_PVR);
  787. unsigned int svr = mfspr(SPRN_SVR);
  788. unsigned int mod = (svr >> 16) & 0xfff6; /* w/o E suffix */
  789. unsigned int rev = svr & 0xffff;
  790. /* MPC8313 Rev 2.0 and higher; All MPC837x */
  791. if ((pvr == 0x80850010 && mod == 0x80b0 && rev >= 0x0020) ||
  792. (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
  793. priv->errata |= GFAR_ERRATA_74;
  794. /* MPC8313 and MPC837x all rev */
  795. if ((pvr == 0x80850010 && mod == 0x80b0) ||
  796. (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
  797. priv->errata |= GFAR_ERRATA_76;
  798. /* MPC8313 and MPC837x all rev */
  799. if ((pvr == 0x80850010 && mod == 0x80b0) ||
  800. (pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
  801. priv->errata |= GFAR_ERRATA_A002;
  802. /* MPC8313 Rev < 2.0, MPC8548 rev 2.0 */
  803. if ((pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020) ||
  804. (pvr == 0x80210020 && mod == 0x8030 && rev == 0x0020))
  805. priv->errata |= GFAR_ERRATA_12;
  806. if (priv->errata)
  807. dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
  808. priv->errata);
  809. }
  810. /* Set up the ethernet device structure, private data,
  811. * and anything else we need before we start
  812. */
  813. static int gfar_probe(struct platform_device *ofdev)
  814. {
  815. u32 tempval;
  816. struct net_device *dev = NULL;
  817. struct gfar_private *priv = NULL;
  818. struct gfar __iomem *regs = NULL;
  819. int err = 0, i, grp_idx = 0;
  820. u32 rstat = 0, tstat = 0, rqueue = 0, tqueue = 0;
  821. u32 isrg = 0;
  822. u32 __iomem *baddr;
  823. err = gfar_of_init(ofdev, &dev);
  824. if (err)
  825. return err;
  826. priv = netdev_priv(dev);
  827. priv->ndev = dev;
  828. priv->ofdev = ofdev;
  829. priv->dev = &ofdev->dev;
  830. SET_NETDEV_DEV(dev, &ofdev->dev);
  831. spin_lock_init(&priv->bflock);
  832. INIT_WORK(&priv->reset_task, gfar_reset_task);
  833. platform_set_drvdata(ofdev, priv);
  834. regs = priv->gfargrp[0].regs;
  835. gfar_detect_errata(priv);
  836. /* Stop the DMA engine now, in case it was running before
  837. * (The firmware could have used it, and left it running).
  838. */
  839. gfar_halt(dev);
  840. /* Reset MAC layer */
  841. gfar_write(&regs->maccfg1, MACCFG1_SOFT_RESET);
  842. /* We need to delay at least 3 TX clocks */
  843. udelay(2);
  844. tempval = 0;
  845. if (!priv->pause_aneg_en && priv->tx_pause_en)
  846. tempval |= MACCFG1_TX_FLOW;
  847. if (!priv->pause_aneg_en && priv->rx_pause_en)
  848. tempval |= MACCFG1_RX_FLOW;
  849. /* the soft reset bit is not self-resetting, so we need to
  850. * clear it before resuming normal operation
  851. */
  852. gfar_write(&regs->maccfg1, tempval);
  853. /* Initialize MACCFG2. */
  854. tempval = MACCFG2_INIT_SETTINGS;
  855. if (gfar_has_errata(priv, GFAR_ERRATA_74))
  856. tempval |= MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK;
  857. gfar_write(&regs->maccfg2, tempval);
  858. /* Initialize ECNTRL */
  859. gfar_write(&regs->ecntrl, ECNTRL_INIT_SETTINGS);
  860. /* Set the dev->base_addr to the gfar reg region */
  861. dev->base_addr = (unsigned long) regs;
  862. /* Fill in the dev structure */
  863. dev->watchdog_timeo = TX_TIMEOUT;
  864. dev->mtu = 1500;
  865. dev->netdev_ops = &gfar_netdev_ops;
  866. dev->ethtool_ops = &gfar_ethtool_ops;
  867. /* Register for napi ...We are registering NAPI for each grp */
  868. if (priv->mode == SQ_SG_MODE)
  869. netif_napi_add(dev, &priv->gfargrp[0].napi, gfar_poll_sq,
  870. GFAR_DEV_WEIGHT);
  871. else
  872. for (i = 0; i < priv->num_grps; i++)
  873. netif_napi_add(dev, &priv->gfargrp[i].napi, gfar_poll,
  874. GFAR_DEV_WEIGHT);
  875. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
  876. dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG |
  877. NETIF_F_RXCSUM;
  878. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG |
  879. NETIF_F_RXCSUM | NETIF_F_HIGHDMA;
  880. }
  881. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN) {
  882. dev->hw_features |= NETIF_F_HW_VLAN_CTAG_TX |
  883. NETIF_F_HW_VLAN_CTAG_RX;
  884. dev->features |= NETIF_F_HW_VLAN_CTAG_RX;
  885. }
  886. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
  887. priv->extended_hash = 1;
  888. priv->hash_width = 9;
  889. priv->hash_regs[0] = &regs->igaddr0;
  890. priv->hash_regs[1] = &regs->igaddr1;
  891. priv->hash_regs[2] = &regs->igaddr2;
  892. priv->hash_regs[3] = &regs->igaddr3;
  893. priv->hash_regs[4] = &regs->igaddr4;
  894. priv->hash_regs[5] = &regs->igaddr5;
  895. priv->hash_regs[6] = &regs->igaddr6;
  896. priv->hash_regs[7] = &regs->igaddr7;
  897. priv->hash_regs[8] = &regs->gaddr0;
  898. priv->hash_regs[9] = &regs->gaddr1;
  899. priv->hash_regs[10] = &regs->gaddr2;
  900. priv->hash_regs[11] = &regs->gaddr3;
  901. priv->hash_regs[12] = &regs->gaddr4;
  902. priv->hash_regs[13] = &regs->gaddr5;
  903. priv->hash_regs[14] = &regs->gaddr6;
  904. priv->hash_regs[15] = &regs->gaddr7;
  905. } else {
  906. priv->extended_hash = 0;
  907. priv->hash_width = 8;
  908. priv->hash_regs[0] = &regs->gaddr0;
  909. priv->hash_regs[1] = &regs->gaddr1;
  910. priv->hash_regs[2] = &regs->gaddr2;
  911. priv->hash_regs[3] = &regs->gaddr3;
  912. priv->hash_regs[4] = &regs->gaddr4;
  913. priv->hash_regs[5] = &regs->gaddr5;
  914. priv->hash_regs[6] = &regs->gaddr6;
  915. priv->hash_regs[7] = &regs->gaddr7;
  916. }
  917. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_PADDING)
  918. priv->padding = DEFAULT_PADDING;
  919. else
  920. priv->padding = 0;
  921. if (dev->features & NETIF_F_IP_CSUM ||
  922. priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)
  923. dev->needed_headroom = GMAC_FCB_LEN;
  924. /* Program the isrg regs only if number of grps > 1 */
  925. if (priv->num_grps > 1) {
  926. baddr = &regs->isrg0;
  927. for (i = 0; i < priv->num_grps; i++) {
  928. isrg |= (priv->gfargrp[i].rx_bit_map << ISRG_SHIFT_RX);
  929. isrg |= (priv->gfargrp[i].tx_bit_map << ISRG_SHIFT_TX);
  930. gfar_write(baddr, isrg);
  931. baddr++;
  932. isrg = 0x0;
  933. }
  934. }
  935. /* Need to reverse the bit maps as bit_map's MSB is q0
  936. * but, for_each_set_bit parses from right to left, which
  937. * basically reverses the queue numbers
  938. */
  939. for (i = 0; i< priv->num_grps; i++) {
  940. priv->gfargrp[i].tx_bit_map =
  941. reverse_bitmap(priv->gfargrp[i].tx_bit_map, MAX_TX_QS);
  942. priv->gfargrp[i].rx_bit_map =
  943. reverse_bitmap(priv->gfargrp[i].rx_bit_map, MAX_RX_QS);
  944. }
  945. /* Calculate RSTAT, TSTAT, RQUEUE and TQUEUE values,
  946. * also assign queues to groups
  947. */
  948. for (grp_idx = 0; grp_idx < priv->num_grps; grp_idx++) {
  949. priv->gfargrp[grp_idx].num_rx_queues = 0x0;
  950. for_each_set_bit(i, &priv->gfargrp[grp_idx].rx_bit_map,
  951. priv->num_rx_queues) {
  952. priv->gfargrp[grp_idx].num_rx_queues++;
  953. priv->rx_queue[i]->grp = &priv->gfargrp[grp_idx];
  954. rstat = rstat | (RSTAT_CLEAR_RHALT >> i);
  955. rqueue = rqueue | ((RQUEUE_EN0 | RQUEUE_EX0) >> i);
  956. }
  957. priv->gfargrp[grp_idx].num_tx_queues = 0x0;
  958. for_each_set_bit(i, &priv->gfargrp[grp_idx].tx_bit_map,
  959. priv->num_tx_queues) {
  960. priv->gfargrp[grp_idx].num_tx_queues++;
  961. priv->tx_queue[i]->grp = &priv->gfargrp[grp_idx];
  962. tstat = tstat | (TSTAT_CLEAR_THALT >> i);
  963. tqueue = tqueue | (TQUEUE_EN0 >> i);
  964. }
  965. priv->gfargrp[grp_idx].rstat = rstat;
  966. priv->gfargrp[grp_idx].tstat = tstat;
  967. rstat = tstat =0;
  968. }
  969. gfar_write(&regs->rqueue, rqueue);
  970. gfar_write(&regs->tqueue, tqueue);
  971. priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
  972. /* Initializing some of the rx/tx queue level parameters */
  973. for (i = 0; i < priv->num_tx_queues; i++) {
  974. priv->tx_queue[i]->tx_ring_size = DEFAULT_TX_RING_SIZE;
  975. priv->tx_queue[i]->num_txbdfree = DEFAULT_TX_RING_SIZE;
  976. priv->tx_queue[i]->txcoalescing = DEFAULT_TX_COALESCE;
  977. priv->tx_queue[i]->txic = DEFAULT_TXIC;
  978. }
  979. for (i = 0; i < priv->num_rx_queues; i++) {
  980. priv->rx_queue[i]->rx_ring_size = DEFAULT_RX_RING_SIZE;
  981. priv->rx_queue[i]->rxcoalescing = DEFAULT_RX_COALESCE;
  982. priv->rx_queue[i]->rxic = DEFAULT_RXIC;
  983. }
  984. /* always enable rx filer */
  985. priv->rx_filer_enable = 1;
  986. /* Enable most messages by default */
  987. priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
  988. /* use pritority h/w tx queue scheduling for single queue devices */
  989. if (priv->num_tx_queues == 1)
  990. priv->prio_sched_en = 1;
  991. /* Carrier starts down, phylib will bring it up */
  992. netif_carrier_off(dev);
  993. err = register_netdev(dev);
  994. if (err) {
  995. pr_err("%s: Cannot register net device, aborting\n", dev->name);
  996. goto register_fail;
  997. }
  998. device_init_wakeup(&dev->dev,
  999. priv->device_flags &
  1000. FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  1001. /* fill out IRQ number and name fields */
  1002. for (i = 0; i < priv->num_grps; i++) {
  1003. struct gfar_priv_grp *grp = &priv->gfargrp[i];
  1004. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  1005. sprintf(gfar_irq(grp, TX)->name, "%s%s%c%s",
  1006. dev->name, "_g", '0' + i, "_tx");
  1007. sprintf(gfar_irq(grp, RX)->name, "%s%s%c%s",
  1008. dev->name, "_g", '0' + i, "_rx");
  1009. sprintf(gfar_irq(grp, ER)->name, "%s%s%c%s",
  1010. dev->name, "_g", '0' + i, "_er");
  1011. } else
  1012. strcpy(gfar_irq(grp, TX)->name, dev->name);
  1013. }
  1014. /* Initialize the filer table */
  1015. gfar_init_filer_table(priv);
  1016. /* Create all the sysfs files */
  1017. gfar_init_sysfs(dev);
  1018. /* Print out the device info */
  1019. netdev_info(dev, "mac: %pM\n", dev->dev_addr);
  1020. /* Even more device info helps when determining which kernel
  1021. * provided which set of benchmarks.
  1022. */
  1023. netdev_info(dev, "Running with NAPI enabled\n");
  1024. for (i = 0; i < priv->num_rx_queues; i++)
  1025. netdev_info(dev, "RX BD ring size for Q[%d]: %d\n",
  1026. i, priv->rx_queue[i]->rx_ring_size);
  1027. for (i = 0; i < priv->num_tx_queues; i++)
  1028. netdev_info(dev, "TX BD ring size for Q[%d]: %d\n",
  1029. i, priv->tx_queue[i]->tx_ring_size);
  1030. return 0;
  1031. register_fail:
  1032. unmap_group_regs(priv);
  1033. free_tx_pointers(priv);
  1034. free_rx_pointers(priv);
  1035. if (priv->phy_node)
  1036. of_node_put(priv->phy_node);
  1037. if (priv->tbi_node)
  1038. of_node_put(priv->tbi_node);
  1039. free_gfar_dev(priv);
  1040. return err;
  1041. }
  1042. static int gfar_remove(struct platform_device *ofdev)
  1043. {
  1044. struct gfar_private *priv = platform_get_drvdata(ofdev);
  1045. if (priv->phy_node)
  1046. of_node_put(priv->phy_node);
  1047. if (priv->tbi_node)
  1048. of_node_put(priv->tbi_node);
  1049. unregister_netdev(priv->ndev);
  1050. unmap_group_regs(priv);
  1051. free_gfar_dev(priv);
  1052. return 0;
  1053. }
  1054. #ifdef CONFIG_PM
  1055. static int gfar_suspend(struct device *dev)
  1056. {
  1057. struct gfar_private *priv = dev_get_drvdata(dev);
  1058. struct net_device *ndev = priv->ndev;
  1059. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1060. unsigned long flags;
  1061. u32 tempval;
  1062. int magic_packet = priv->wol_en &&
  1063. (priv->device_flags &
  1064. FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  1065. netif_device_detach(ndev);
  1066. if (netif_running(ndev)) {
  1067. local_irq_save(flags);
  1068. lock_tx_qs(priv);
  1069. lock_rx_qs(priv);
  1070. gfar_halt_nodisable(ndev);
  1071. /* Disable Tx, and Rx if wake-on-LAN is disabled. */
  1072. tempval = gfar_read(&regs->maccfg1);
  1073. tempval &= ~MACCFG1_TX_EN;
  1074. if (!magic_packet)
  1075. tempval &= ~MACCFG1_RX_EN;
  1076. gfar_write(&regs->maccfg1, tempval);
  1077. unlock_rx_qs(priv);
  1078. unlock_tx_qs(priv);
  1079. local_irq_restore(flags);
  1080. disable_napi(priv);
  1081. if (magic_packet) {
  1082. /* Enable interrupt on Magic Packet */
  1083. gfar_write(&regs->imask, IMASK_MAG);
  1084. /* Enable Magic Packet mode */
  1085. tempval = gfar_read(&regs->maccfg2);
  1086. tempval |= MACCFG2_MPEN;
  1087. gfar_write(&regs->maccfg2, tempval);
  1088. } else {
  1089. phy_stop(priv->phydev);
  1090. }
  1091. }
  1092. return 0;
  1093. }
  1094. static int gfar_resume(struct device *dev)
  1095. {
  1096. struct gfar_private *priv = dev_get_drvdata(dev);
  1097. struct net_device *ndev = priv->ndev;
  1098. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1099. unsigned long flags;
  1100. u32 tempval;
  1101. int magic_packet = priv->wol_en &&
  1102. (priv->device_flags &
  1103. FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  1104. if (!netif_running(ndev)) {
  1105. netif_device_attach(ndev);
  1106. return 0;
  1107. }
  1108. if (!magic_packet && priv->phydev)
  1109. phy_start(priv->phydev);
  1110. /* Disable Magic Packet mode, in case something
  1111. * else woke us up.
  1112. */
  1113. local_irq_save(flags);
  1114. lock_tx_qs(priv);
  1115. lock_rx_qs(priv);
  1116. tempval = gfar_read(&regs->maccfg2);
  1117. tempval &= ~MACCFG2_MPEN;
  1118. gfar_write(&regs->maccfg2, tempval);
  1119. gfar_start(ndev);
  1120. unlock_rx_qs(priv);
  1121. unlock_tx_qs(priv);
  1122. local_irq_restore(flags);
  1123. netif_device_attach(ndev);
  1124. enable_napi(priv);
  1125. return 0;
  1126. }
  1127. static int gfar_restore(struct device *dev)
  1128. {
  1129. struct gfar_private *priv = dev_get_drvdata(dev);
  1130. struct net_device *ndev = priv->ndev;
  1131. if (!netif_running(ndev)) {
  1132. netif_device_attach(ndev);
  1133. return 0;
  1134. }
  1135. if (gfar_init_bds(ndev)) {
  1136. free_skb_resources(priv);
  1137. return -ENOMEM;
  1138. }
  1139. init_registers(ndev);
  1140. gfar_set_mac_address(ndev);
  1141. gfar_init_mac(ndev);
  1142. gfar_start(ndev);
  1143. priv->oldlink = 0;
  1144. priv->oldspeed = 0;
  1145. priv->oldduplex = -1;
  1146. if (priv->phydev)
  1147. phy_start(priv->phydev);
  1148. netif_device_attach(ndev);
  1149. enable_napi(priv);
  1150. return 0;
  1151. }
  1152. static struct dev_pm_ops gfar_pm_ops = {
  1153. .suspend = gfar_suspend,
  1154. .resume = gfar_resume,
  1155. .freeze = gfar_suspend,
  1156. .thaw = gfar_resume,
  1157. .restore = gfar_restore,
  1158. };
  1159. #define GFAR_PM_OPS (&gfar_pm_ops)
  1160. #else
  1161. #define GFAR_PM_OPS NULL
  1162. #endif
  1163. /* Reads the controller's registers to determine what interface
  1164. * connects it to the PHY.
  1165. */
  1166. static phy_interface_t gfar_get_interface(struct net_device *dev)
  1167. {
  1168. struct gfar_private *priv = netdev_priv(dev);
  1169. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1170. u32 ecntrl;
  1171. ecntrl = gfar_read(&regs->ecntrl);
  1172. if (ecntrl & ECNTRL_SGMII_MODE)
  1173. return PHY_INTERFACE_MODE_SGMII;
  1174. if (ecntrl & ECNTRL_TBI_MODE) {
  1175. if (ecntrl & ECNTRL_REDUCED_MODE)
  1176. return PHY_INTERFACE_MODE_RTBI;
  1177. else
  1178. return PHY_INTERFACE_MODE_TBI;
  1179. }
  1180. if (ecntrl & ECNTRL_REDUCED_MODE) {
  1181. if (ecntrl & ECNTRL_REDUCED_MII_MODE) {
  1182. return PHY_INTERFACE_MODE_RMII;
  1183. }
  1184. else {
  1185. phy_interface_t interface = priv->interface;
  1186. /* This isn't autodetected right now, so it must
  1187. * be set by the device tree or platform code.
  1188. */
  1189. if (interface == PHY_INTERFACE_MODE_RGMII_ID)
  1190. return PHY_INTERFACE_MODE_RGMII_ID;
  1191. return PHY_INTERFACE_MODE_RGMII;
  1192. }
  1193. }
  1194. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
  1195. return PHY_INTERFACE_MODE_GMII;
  1196. return PHY_INTERFACE_MODE_MII;
  1197. }
  1198. /* Initializes driver's PHY state, and attaches to the PHY.
  1199. * Returns 0 on success.
  1200. */
  1201. static int init_phy(struct net_device *dev)
  1202. {
  1203. struct gfar_private *priv = netdev_priv(dev);
  1204. uint gigabit_support =
  1205. priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
  1206. GFAR_SUPPORTED_GBIT : 0;
  1207. phy_interface_t interface;
  1208. priv->oldlink = 0;
  1209. priv->oldspeed = 0;
  1210. priv->oldduplex = -1;
  1211. interface = gfar_get_interface(dev);
  1212. priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
  1213. interface);
  1214. if (!priv->phydev)
  1215. priv->phydev = of_phy_connect_fixed_link(dev, &adjust_link,
  1216. interface);
  1217. if (!priv->phydev) {
  1218. dev_err(&dev->dev, "could not attach to PHY\n");
  1219. return -ENODEV;
  1220. }
  1221. if (interface == PHY_INTERFACE_MODE_SGMII)
  1222. gfar_configure_serdes(dev);
  1223. /* Remove any features not supported by the controller */
  1224. priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
  1225. priv->phydev->advertising = priv->phydev->supported;
  1226. return 0;
  1227. }
  1228. /* Initialize TBI PHY interface for communicating with the
  1229. * SERDES lynx PHY on the chip. We communicate with this PHY
  1230. * through the MDIO bus on each controller, treating it as a
  1231. * "normal" PHY at the address found in the TBIPA register. We assume
  1232. * that the TBIPA register is valid. Either the MDIO bus code will set
  1233. * it to a value that doesn't conflict with other PHYs on the bus, or the
  1234. * value doesn't matter, as there are no other PHYs on the bus.
  1235. */
  1236. static void gfar_configure_serdes(struct net_device *dev)
  1237. {
  1238. struct gfar_private *priv = netdev_priv(dev);
  1239. struct phy_device *tbiphy;
  1240. if (!priv->tbi_node) {
  1241. dev_warn(&dev->dev, "error: SGMII mode requires that the "
  1242. "device tree specify a tbi-handle\n");
  1243. return;
  1244. }
  1245. tbiphy = of_phy_find_device(priv->tbi_node);
  1246. if (!tbiphy) {
  1247. dev_err(&dev->dev, "error: Could not get TBI device\n");
  1248. return;
  1249. }
  1250. /* If the link is already up, we must already be ok, and don't need to
  1251. * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
  1252. * everything for us? Resetting it takes the link down and requires
  1253. * several seconds for it to come back.
  1254. */
  1255. if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
  1256. return;
  1257. /* Single clk mode, mii mode off(for serdes communication) */
  1258. phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
  1259. phy_write(tbiphy, MII_ADVERTISE,
  1260. ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
  1261. ADVERTISE_1000XPSE_ASYM);
  1262. phy_write(tbiphy, MII_BMCR,
  1263. BMCR_ANENABLE | BMCR_ANRESTART | BMCR_FULLDPLX |
  1264. BMCR_SPEED1000);
  1265. }
  1266. static void init_registers(struct net_device *dev)
  1267. {
  1268. struct gfar_private *priv = netdev_priv(dev);
  1269. struct gfar __iomem *regs = NULL;
  1270. int i;
  1271. for (i = 0; i < priv->num_grps; i++) {
  1272. regs = priv->gfargrp[i].regs;
  1273. /* Clear IEVENT */
  1274. gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
  1275. /* Initialize IMASK */
  1276. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  1277. }
  1278. regs = priv->gfargrp[0].regs;
  1279. /* Init hash registers to zero */
  1280. gfar_write(&regs->igaddr0, 0);
  1281. gfar_write(&regs->igaddr1, 0);
  1282. gfar_write(&regs->igaddr2, 0);
  1283. gfar_write(&regs->igaddr3, 0);
  1284. gfar_write(&regs->igaddr4, 0);
  1285. gfar_write(&regs->igaddr5, 0);
  1286. gfar_write(&regs->igaddr6, 0);
  1287. gfar_write(&regs->igaddr7, 0);
  1288. gfar_write(&regs->gaddr0, 0);
  1289. gfar_write(&regs->gaddr1, 0);
  1290. gfar_write(&regs->gaddr2, 0);
  1291. gfar_write(&regs->gaddr3, 0);
  1292. gfar_write(&regs->gaddr4, 0);
  1293. gfar_write(&regs->gaddr5, 0);
  1294. gfar_write(&regs->gaddr6, 0);
  1295. gfar_write(&regs->gaddr7, 0);
  1296. /* Zero out the rmon mib registers if it has them */
  1297. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
  1298. memset_io(&(regs->rmon), 0, sizeof (struct rmon_mib));
  1299. /* Mask off the CAM interrupts */
  1300. gfar_write(&regs->rmon.cam1, 0xffffffff);
  1301. gfar_write(&regs->rmon.cam2, 0xffffffff);
  1302. }
  1303. /* Initialize the max receive buffer length */
  1304. gfar_write(&regs->mrblr, priv->rx_buffer_size);
  1305. /* Initialize the Minimum Frame Length Register */
  1306. gfar_write(&regs->minflr, MINFLR_INIT_SETTINGS);
  1307. }
  1308. static int __gfar_is_rx_idle(struct gfar_private *priv)
  1309. {
  1310. u32 res;
  1311. /* Normaly TSEC should not hang on GRS commands, so we should
  1312. * actually wait for IEVENT_GRSC flag.
  1313. */
  1314. if (likely(!gfar_has_errata(priv, GFAR_ERRATA_A002)))
  1315. return 0;
  1316. /* Read the eTSEC register at offset 0xD1C. If bits 7-14 are
  1317. * the same as bits 23-30, the eTSEC Rx is assumed to be idle
  1318. * and the Rx can be safely reset.
  1319. */
  1320. res = gfar_read((void __iomem *)priv->gfargrp[0].regs + 0xd1c);
  1321. res &= 0x7f807f80;
  1322. if ((res & 0xffff) == (res >> 16))
  1323. return 1;
  1324. return 0;
  1325. }
  1326. /* Halt the receive and transmit queues */
  1327. static void gfar_halt_nodisable(struct net_device *dev)
  1328. {
  1329. struct gfar_private *priv = netdev_priv(dev);
  1330. struct gfar __iomem *regs = NULL;
  1331. u32 tempval;
  1332. int i;
  1333. for (i = 0; i < priv->num_grps; i++) {
  1334. regs = priv->gfargrp[i].regs;
  1335. /* Mask all interrupts */
  1336. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  1337. /* Clear all interrupts */
  1338. gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
  1339. }
  1340. regs = priv->gfargrp[0].regs;
  1341. /* Stop the DMA, and wait for it to stop */
  1342. tempval = gfar_read(&regs->dmactrl);
  1343. if ((tempval & (DMACTRL_GRS | DMACTRL_GTS)) !=
  1344. (DMACTRL_GRS | DMACTRL_GTS)) {
  1345. int ret;
  1346. tempval |= (DMACTRL_GRS | DMACTRL_GTS);
  1347. gfar_write(&regs->dmactrl, tempval);
  1348. do {
  1349. ret = spin_event_timeout(((gfar_read(&regs->ievent) &
  1350. (IEVENT_GRSC | IEVENT_GTSC)) ==
  1351. (IEVENT_GRSC | IEVENT_GTSC)), 1000000, 0);
  1352. if (!ret && !(gfar_read(&regs->ievent) & IEVENT_GRSC))
  1353. ret = __gfar_is_rx_idle(priv);
  1354. } while (!ret);
  1355. }
  1356. }
  1357. /* Halt the receive and transmit queues */
  1358. void gfar_halt(struct net_device *dev)
  1359. {
  1360. struct gfar_private *priv = netdev_priv(dev);
  1361. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1362. u32 tempval;
  1363. gfar_halt_nodisable(dev);
  1364. /* Disable Rx and Tx */
  1365. tempval = gfar_read(&regs->maccfg1);
  1366. tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
  1367. gfar_write(&regs->maccfg1, tempval);
  1368. }
  1369. static void free_grp_irqs(struct gfar_priv_grp *grp)
  1370. {
  1371. free_irq(gfar_irq(grp, TX)->irq, grp);
  1372. free_irq(gfar_irq(grp, RX)->irq, grp);
  1373. free_irq(gfar_irq(grp, ER)->irq, grp);
  1374. }
  1375. void stop_gfar(struct net_device *dev)
  1376. {
  1377. struct gfar_private *priv = netdev_priv(dev);
  1378. unsigned long flags;
  1379. int i;
  1380. phy_stop(priv->phydev);
  1381. /* Lock it down */
  1382. local_irq_save(flags);
  1383. lock_tx_qs(priv);
  1384. lock_rx_qs(priv);
  1385. gfar_halt(dev);
  1386. unlock_rx_qs(priv);
  1387. unlock_tx_qs(priv);
  1388. local_irq_restore(flags);
  1389. /* Free the IRQs */
  1390. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  1391. for (i = 0; i < priv->num_grps; i++)
  1392. free_grp_irqs(&priv->gfargrp[i]);
  1393. } else {
  1394. for (i = 0; i < priv->num_grps; i++)
  1395. free_irq(gfar_irq(&priv->gfargrp[i], TX)->irq,
  1396. &priv->gfargrp[i]);
  1397. }
  1398. free_skb_resources(priv);
  1399. }
  1400. static void free_skb_tx_queue(struct gfar_priv_tx_q *tx_queue)
  1401. {
  1402. struct txbd8 *txbdp;
  1403. struct gfar_private *priv = netdev_priv(tx_queue->dev);
  1404. int i, j;
  1405. txbdp = tx_queue->tx_bd_base;
  1406. for (i = 0; i < tx_queue->tx_ring_size; i++) {
  1407. if (!tx_queue->tx_skbuff[i])
  1408. continue;
  1409. dma_unmap_single(priv->dev, txbdp->bufPtr,
  1410. txbdp->length, DMA_TO_DEVICE);
  1411. txbdp->lstatus = 0;
  1412. for (j = 0; j < skb_shinfo(tx_queue->tx_skbuff[i])->nr_frags;
  1413. j++) {
  1414. txbdp++;
  1415. dma_unmap_page(priv->dev, txbdp->bufPtr,
  1416. txbdp->length, DMA_TO_DEVICE);
  1417. }
  1418. txbdp++;
  1419. dev_kfree_skb_any(tx_queue->tx_skbuff[i]);
  1420. tx_queue->tx_skbuff[i] = NULL;
  1421. }
  1422. kfree(tx_queue->tx_skbuff);
  1423. tx_queue->tx_skbuff = NULL;
  1424. }
  1425. static void free_skb_rx_queue(struct gfar_priv_rx_q *rx_queue)
  1426. {
  1427. struct rxbd8 *rxbdp;
  1428. struct gfar_private *priv = netdev_priv(rx_queue->dev);
  1429. int i;
  1430. rxbdp = rx_queue->rx_bd_base;
  1431. for (i = 0; i < rx_queue->rx_ring_size; i++) {
  1432. if (rx_queue->rx_skbuff[i]) {
  1433. dma_unmap_single(priv->dev, rxbdp->bufPtr,
  1434. priv->rx_buffer_size,
  1435. DMA_FROM_DEVICE);
  1436. dev_kfree_skb_any(rx_queue->rx_skbuff[i]);
  1437. rx_queue->rx_skbuff[i] = NULL;
  1438. }
  1439. rxbdp->lstatus = 0;
  1440. rxbdp->bufPtr = 0;
  1441. rxbdp++;
  1442. }
  1443. kfree(rx_queue->rx_skbuff);
  1444. rx_queue->rx_skbuff = NULL;
  1445. }
  1446. /* If there are any tx skbs or rx skbs still around, free them.
  1447. * Then free tx_skbuff and rx_skbuff
  1448. */
  1449. static void free_skb_resources(struct gfar_private *priv)
  1450. {
  1451. struct gfar_priv_tx_q *tx_queue = NULL;
  1452. struct gfar_priv_rx_q *rx_queue = NULL;
  1453. int i;
  1454. /* Go through all the buffer descriptors and free their data buffers */
  1455. for (i = 0; i < priv->num_tx_queues; i++) {
  1456. struct netdev_queue *txq;
  1457. tx_queue = priv->tx_queue[i];
  1458. txq = netdev_get_tx_queue(tx_queue->dev, tx_queue->qindex);
  1459. if (tx_queue->tx_skbuff)
  1460. free_skb_tx_queue(tx_queue);
  1461. netdev_tx_reset_queue(txq);
  1462. }
  1463. for (i = 0; i < priv->num_rx_queues; i++) {
  1464. rx_queue = priv->rx_queue[i];
  1465. if (rx_queue->rx_skbuff)
  1466. free_skb_rx_queue(rx_queue);
  1467. }
  1468. dma_free_coherent(priv->dev,
  1469. sizeof(struct txbd8) * priv->total_tx_ring_size +
  1470. sizeof(struct rxbd8) * priv->total_rx_ring_size,
  1471. priv->tx_queue[0]->tx_bd_base,
  1472. priv->tx_queue[0]->tx_bd_dma_base);
  1473. }
  1474. void gfar_start(struct net_device *dev)
  1475. {
  1476. struct gfar_private *priv = netdev_priv(dev);
  1477. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1478. u32 tempval;
  1479. int i = 0;
  1480. /* Enable Rx and Tx in MACCFG1 */
  1481. tempval = gfar_read(&regs->maccfg1);
  1482. tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  1483. gfar_write(&regs->maccfg1, tempval);
  1484. /* Initialize DMACTRL to have WWR and WOP */
  1485. tempval = gfar_read(&regs->dmactrl);
  1486. tempval |= DMACTRL_INIT_SETTINGS;
  1487. gfar_write(&regs->dmactrl, tempval);
  1488. /* Make sure we aren't stopped */
  1489. tempval = gfar_read(&regs->dmactrl);
  1490. tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
  1491. gfar_write(&regs->dmactrl, tempval);
  1492. for (i = 0; i < priv->num_grps; i++) {
  1493. regs = priv->gfargrp[i].regs;
  1494. /* Clear THLT/RHLT, so that the DMA starts polling now */
  1495. gfar_write(&regs->tstat, priv->gfargrp[i].tstat);
  1496. gfar_write(&regs->rstat, priv->gfargrp[i].rstat);
  1497. /* Unmask the interrupts we look for */
  1498. gfar_write(&regs->imask, IMASK_DEFAULT);
  1499. }
  1500. dev->trans_start = jiffies; /* prevent tx timeout */
  1501. }
  1502. static void gfar_configure_coalescing(struct gfar_private *priv,
  1503. unsigned long tx_mask, unsigned long rx_mask)
  1504. {
  1505. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1506. u32 __iomem *baddr;
  1507. if (priv->mode == MQ_MG_MODE) {
  1508. int i = 0;
  1509. baddr = &regs->txic0;
  1510. for_each_set_bit(i, &tx_mask, priv->num_tx_queues) {
  1511. gfar_write(baddr + i, 0);
  1512. if (likely(priv->tx_queue[i]->txcoalescing))
  1513. gfar_write(baddr + i, priv->tx_queue[i]->txic);
  1514. }
  1515. baddr = &regs->rxic0;
  1516. for_each_set_bit(i, &rx_mask, priv->num_rx_queues) {
  1517. gfar_write(baddr + i, 0);
  1518. if (likely(priv->rx_queue[i]->rxcoalescing))
  1519. gfar_write(baddr + i, priv->rx_queue[i]->rxic);
  1520. }
  1521. } else {
  1522. /* Backward compatible case -- even if we enable
  1523. * multiple queues, there's only single reg to program
  1524. */
  1525. gfar_write(&regs->txic, 0);
  1526. if (likely(priv->tx_queue[0]->txcoalescing))
  1527. gfar_write(&regs->txic, priv->tx_queue[0]->txic);
  1528. gfar_write(&regs->rxic, 0);
  1529. if (unlikely(priv->rx_queue[0]->rxcoalescing))
  1530. gfar_write(&regs->rxic, priv->rx_queue[0]->rxic);
  1531. }
  1532. }
  1533. void gfar_configure_coalescing_all(struct gfar_private *priv)
  1534. {
  1535. gfar_configure_coalescing(priv, 0xFF, 0xFF);
  1536. }
  1537. static int register_grp_irqs(struct gfar_priv_grp *grp)
  1538. {
  1539. struct gfar_private *priv = grp->priv;
  1540. struct net_device *dev = priv->ndev;
  1541. int err;
  1542. /* If the device has multiple interrupts, register for
  1543. * them. Otherwise, only register for the one
  1544. */
  1545. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  1546. /* Install our interrupt handlers for Error,
  1547. * Transmit, and Receive
  1548. */
  1549. err = request_irq(gfar_irq(grp, ER)->irq, gfar_error, 0,
  1550. gfar_irq(grp, ER)->name, grp);
  1551. if (err < 0) {
  1552. netif_err(priv, intr, dev, "Can't get IRQ %d\n",
  1553. gfar_irq(grp, ER)->irq);
  1554. goto err_irq_fail;
  1555. }
  1556. err = request_irq(gfar_irq(grp, TX)->irq, gfar_transmit, 0,
  1557. gfar_irq(grp, TX)->name, grp);
  1558. if (err < 0) {
  1559. netif_err(priv, intr, dev, "Can't get IRQ %d\n",
  1560. gfar_irq(grp, TX)->irq);
  1561. goto tx_irq_fail;
  1562. }
  1563. err = request_irq(gfar_irq(grp, RX)->irq, gfar_receive, 0,
  1564. gfar_irq(grp, RX)->name, grp);
  1565. if (err < 0) {
  1566. netif_err(priv, intr, dev, "Can't get IRQ %d\n",
  1567. gfar_irq(grp, RX)->irq);
  1568. goto rx_irq_fail;
  1569. }
  1570. } else {
  1571. err = request_irq(gfar_irq(grp, TX)->irq, gfar_interrupt, 0,
  1572. gfar_irq(grp, TX)->name, grp);
  1573. if (err < 0) {
  1574. netif_err(priv, intr, dev, "Can't get IRQ %d\n",
  1575. gfar_irq(grp, TX)->irq);
  1576. goto err_irq_fail;
  1577. }
  1578. }
  1579. return 0;
  1580. rx_irq_fail:
  1581. free_irq(gfar_irq(grp, TX)->irq, grp);
  1582. tx_irq_fail:
  1583. free_irq(gfar_irq(grp, ER)->irq, grp);
  1584. err_irq_fail:
  1585. return err;
  1586. }
  1587. /* Bring the controller up and running */
  1588. int startup_gfar(struct net_device *ndev)
  1589. {
  1590. struct gfar_private *priv = netdev_priv(ndev);
  1591. struct gfar __iomem *regs = NULL;
  1592. int err, i, j;
  1593. for (i = 0; i < priv->num_grps; i++) {
  1594. regs= priv->gfargrp[i].regs;
  1595. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  1596. }
  1597. regs= priv->gfargrp[0].regs;
  1598. err = gfar_alloc_skb_resources(ndev);
  1599. if (err)
  1600. return err;
  1601. gfar_init_mac(ndev);
  1602. for (i = 0; i < priv->num_grps; i++) {
  1603. err = register_grp_irqs(&priv->gfargrp[i]);
  1604. if (err) {
  1605. for (j = 0; j < i; j++)
  1606. free_grp_irqs(&priv->gfargrp[j]);
  1607. goto irq_fail;
  1608. }
  1609. }
  1610. /* Start the controller */
  1611. gfar_start(ndev);
  1612. phy_start(priv->phydev);
  1613. gfar_configure_coalescing_all(priv);
  1614. return 0;
  1615. irq_fail:
  1616. free_skb_resources(priv);
  1617. return err;
  1618. }
  1619. /* Called when something needs to use the ethernet device
  1620. * Returns 0 for success.
  1621. */
  1622. static int gfar_enet_open(struct net_device *dev)
  1623. {
  1624. struct gfar_private *priv = netdev_priv(dev);
  1625. int err;
  1626. enable_napi(priv);
  1627. /* Initialize a bunch of registers */
  1628. init_registers(dev);
  1629. gfar_set_mac_address(dev);
  1630. err = init_phy(dev);
  1631. if (err) {
  1632. disable_napi(priv);
  1633. return err;
  1634. }
  1635. err = startup_gfar(dev);
  1636. if (err) {
  1637. disable_napi(priv);
  1638. return err;
  1639. }
  1640. netif_tx_start_all_queues(dev);
  1641. device_set_wakeup_enable(&dev->dev, priv->wol_en);
  1642. return err;
  1643. }
  1644. static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
  1645. {
  1646. struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
  1647. memset(fcb, 0, GMAC_FCB_LEN);
  1648. return fcb;
  1649. }
  1650. static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb,
  1651. int fcb_length)
  1652. {
  1653. /* If we're here, it's a IP packet with a TCP or UDP
  1654. * payload. We set it to checksum, using a pseudo-header
  1655. * we provide
  1656. */
  1657. u8 flags = TXFCB_DEFAULT;
  1658. /* Tell the controller what the protocol is
  1659. * And provide the already calculated phcs
  1660. */
  1661. if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
  1662. flags |= TXFCB_UDP;
  1663. fcb->phcs = udp_hdr(skb)->check;
  1664. } else
  1665. fcb->phcs = tcp_hdr(skb)->check;
  1666. /* l3os is the distance between the start of the
  1667. * frame (skb->data) and the start of the IP hdr.
  1668. * l4os is the distance between the start of the
  1669. * l3 hdr and the l4 hdr
  1670. */
  1671. fcb->l3os = (u16)(skb_network_offset(skb) - fcb_length);
  1672. fcb->l4os = skb_network_header_len(skb);
  1673. fcb->flags = flags;
  1674. }
  1675. void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
  1676. {
  1677. fcb->flags |= TXFCB_VLN;
  1678. fcb->vlctl = vlan_tx_tag_get(skb);
  1679. }
  1680. static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
  1681. struct txbd8 *base, int ring_size)
  1682. {
  1683. struct txbd8 *new_bd = bdp + stride;
  1684. return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
  1685. }
  1686. static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
  1687. int ring_size)
  1688. {
  1689. return skip_txbd(bdp, 1, base, ring_size);
  1690. }
  1691. /* eTSEC12: csum generation not supported for some fcb offsets */
  1692. static inline bool gfar_csum_errata_12(struct gfar_private *priv,
  1693. unsigned long fcb_addr)
  1694. {
  1695. return (gfar_has_errata(priv, GFAR_ERRATA_12) &&
  1696. (fcb_addr % 0x20) > 0x18);
  1697. }
  1698. /* eTSEC76: csum generation for frames larger than 2500 may
  1699. * cause excess delays before start of transmission
  1700. */
  1701. static inline bool gfar_csum_errata_76(struct gfar_private *priv,
  1702. unsigned int len)
  1703. {
  1704. return (gfar_has_errata(priv, GFAR_ERRATA_76) &&
  1705. (len > 2500));
  1706. }
  1707. /* This is called by the kernel when a frame is ready for transmission.
  1708. * It is pointed to by the dev->hard_start_xmit function pointer
  1709. */
  1710. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1711. {
  1712. struct gfar_private *priv = netdev_priv(dev);
  1713. struct gfar_priv_tx_q *tx_queue = NULL;
  1714. struct netdev_queue *txq;
  1715. struct gfar __iomem *regs = NULL;
  1716. struct txfcb *fcb = NULL;
  1717. struct txbd8 *txbdp, *txbdp_start, *base, *txbdp_tstamp = NULL;
  1718. u32 lstatus;
  1719. int i, rq = 0;
  1720. int do_tstamp, do_csum, do_vlan;
  1721. u32 bufaddr;
  1722. unsigned long flags;
  1723. unsigned int nr_frags, nr_txbds, length, fcb_len = 0;
  1724. rq = skb->queue_mapping;
  1725. tx_queue = priv->tx_queue[rq];
  1726. txq = netdev_get_tx_queue(dev, rq);
  1727. base = tx_queue->tx_bd_base;
  1728. regs = tx_queue->grp->regs;
  1729. do_csum = (CHECKSUM_PARTIAL == skb->ip_summed);
  1730. do_vlan = vlan_tx_tag_present(skb);
  1731. do_tstamp = (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) &&
  1732. priv->hwts_tx_en;
  1733. if (do_csum || do_vlan)
  1734. fcb_len = GMAC_FCB_LEN;
  1735. /* check if time stamp should be generated */
  1736. if (unlikely(do_tstamp))
  1737. fcb_len = GMAC_FCB_LEN + GMAC_TXPAL_LEN;
  1738. /* make space for additional header when fcb is needed */
  1739. if (fcb_len && unlikely(skb_headroom(skb) < fcb_len)) {
  1740. struct sk_buff *skb_new;
  1741. skb_new = skb_realloc_headroom(skb, fcb_len);
  1742. if (!skb_new) {
  1743. dev->stats.tx_errors++;
  1744. kfree_skb(skb);
  1745. return NETDEV_TX_OK;
  1746. }
  1747. if (skb->sk)
  1748. skb_set_owner_w(skb_new, skb->sk);
  1749. consume_skb(skb);
  1750. skb = skb_new;
  1751. }
  1752. /* total number of fragments in the SKB */
  1753. nr_frags = skb_shinfo(skb)->nr_frags;
  1754. /* calculate the required number of TxBDs for this skb */
  1755. if (unlikely(do_tstamp))
  1756. nr_txbds = nr_frags + 2;
  1757. else
  1758. nr_txbds = nr_frags + 1;
  1759. /* check if there is space to queue this packet */
  1760. if (nr_txbds > tx_queue->num_txbdfree) {
  1761. /* no space, stop the queue */
  1762. netif_tx_stop_queue(txq);
  1763. dev->stats.tx_fifo_errors++;
  1764. return NETDEV_TX_BUSY;
  1765. }
  1766. /* Update transmit stats */
  1767. tx_queue->stats.tx_bytes += skb->len;
  1768. tx_queue->stats.tx_packets++;
  1769. txbdp = txbdp_start = tx_queue->cur_tx;
  1770. lstatus = txbdp->lstatus;
  1771. /* Time stamp insertion requires one additional TxBD */
  1772. if (unlikely(do_tstamp))
  1773. txbdp_tstamp = txbdp = next_txbd(txbdp, base,
  1774. tx_queue->tx_ring_size);
  1775. if (nr_frags == 0) {
  1776. if (unlikely(do_tstamp))
  1777. txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_LAST |
  1778. TXBD_INTERRUPT);
  1779. else
  1780. lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1781. } else {
  1782. /* Place the fragment addresses and lengths into the TxBDs */
  1783. for (i = 0; i < nr_frags; i++) {
  1784. /* Point at the next BD, wrapping as needed */
  1785. txbdp = next_txbd(txbdp, base, tx_queue->tx_ring_size);
  1786. length = skb_shinfo(skb)->frags[i].size;
  1787. lstatus = txbdp->lstatus | length |
  1788. BD_LFLAG(TXBD_READY);
  1789. /* Handle the last BD specially */
  1790. if (i == nr_frags - 1)
  1791. lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1792. bufaddr = skb_frag_dma_map(priv->dev,
  1793. &skb_shinfo(skb)->frags[i],
  1794. 0,
  1795. length,
  1796. DMA_TO_DEVICE);
  1797. /* set the TxBD length and buffer pointer */
  1798. txbdp->bufPtr = bufaddr;
  1799. txbdp->lstatus = lstatus;
  1800. }
  1801. lstatus = txbdp_start->lstatus;
  1802. }
  1803. /* Add TxPAL between FCB and frame if required */
  1804. if (unlikely(do_tstamp)) {
  1805. skb_push(skb, GMAC_TXPAL_LEN);
  1806. memset(skb->data, 0, GMAC_TXPAL_LEN);
  1807. }
  1808. /* Add TxFCB if required */
  1809. if (fcb_len) {
  1810. fcb = gfar_add_fcb(skb);
  1811. lstatus |= BD_LFLAG(TXBD_TOE);
  1812. }
  1813. /* Set up checksumming */
  1814. if (do_csum) {
  1815. gfar_tx_checksum(skb, fcb, fcb_len);
  1816. if (unlikely(gfar_csum_errata_12(priv, (unsigned long)fcb)) ||
  1817. unlikely(gfar_csum_errata_76(priv, skb->len))) {
  1818. __skb_pull(skb, GMAC_FCB_LEN);
  1819. skb_checksum_help(skb);
  1820. if (do_vlan || do_tstamp) {
  1821. /* put back a new fcb for vlan/tstamp TOE */
  1822. fcb = gfar_add_fcb(skb);
  1823. } else {
  1824. /* Tx TOE not used */
  1825. lstatus &= ~(BD_LFLAG(TXBD_TOE));
  1826. fcb = NULL;
  1827. }
  1828. }
  1829. }
  1830. if (do_vlan)
  1831. gfar_tx_vlan(skb, fcb);
  1832. /* Setup tx hardware time stamping if requested */
  1833. if (unlikely(do_tstamp)) {
  1834. skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
  1835. fcb->ptp = 1;
  1836. }
  1837. txbdp_start->bufPtr = dma_map_single(priv->dev, skb->data,
  1838. skb_headlen(skb), DMA_TO_DEVICE);
  1839. /* If time stamping is requested one additional TxBD must be set up. The
  1840. * first TxBD points to the FCB and must have a data length of
  1841. * GMAC_FCB_LEN. The second TxBD points to the actual frame data with
  1842. * the full frame length.
  1843. */
  1844. if (unlikely(do_tstamp)) {
  1845. txbdp_tstamp->bufPtr = txbdp_start->bufPtr + fcb_len;
  1846. txbdp_tstamp->lstatus |= BD_LFLAG(TXBD_READY) |
  1847. (skb_headlen(skb) - fcb_len);
  1848. lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | GMAC_FCB_LEN;
  1849. } else {
  1850. lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
  1851. }
  1852. netdev_tx_sent_queue(txq, skb->len);
  1853. /* We can work in parallel with gfar_clean_tx_ring(), except
  1854. * when modifying num_txbdfree. Note that we didn't grab the lock
  1855. * when we were reading the num_txbdfree and checking for available
  1856. * space, that's because outside of this function it can only grow,
  1857. * and once we've got needed space, it cannot suddenly disappear.
  1858. *
  1859. * The lock also protects us from gfar_error(), which can modify
  1860. * regs->tstat and thus retrigger the transfers, which is why we
  1861. * also must grab the lock before setting ready bit for the first
  1862. * to be transmitted BD.
  1863. */
  1864. spin_lock_irqsave(&tx_queue->txlock, flags);
  1865. /* The powerpc-specific eieio() is used, as wmb() has too strong
  1866. * semantics (it requires synchronization between cacheable and
  1867. * uncacheable mappings, which eieio doesn't provide and which we
  1868. * don't need), thus requiring a more expensive sync instruction. At
  1869. * some point, the set of architecture-independent barrier functions
  1870. * should be expanded to include weaker barriers.
  1871. */
  1872. eieio();
  1873. txbdp_start->lstatus = lstatus;
  1874. eieio(); /* force lstatus write before tx_skbuff */
  1875. tx_queue->tx_skbuff[tx_queue->skb_curtx] = skb;
  1876. /* Update the current skb pointer to the next entry we will use
  1877. * (wrapping if necessary)
  1878. */
  1879. tx_queue->skb_curtx = (tx_queue->skb_curtx + 1) &
  1880. TX_RING_MOD_MASK(tx_queue->tx_ring_size);
  1881. tx_queue->cur_tx = next_txbd(txbdp, base, tx_queue->tx_ring_size);
  1882. /* reduce TxBD free count */
  1883. tx_queue->num_txbdfree -= (nr_txbds);
  1884. /* If the next BD still needs to be cleaned up, then the bds
  1885. * are full. We need to tell the kernel to stop sending us stuff.
  1886. */
  1887. if (!tx_queue->num_txbdfree) {
  1888. netif_tx_stop_queue(txq);
  1889. dev->stats.tx_fifo_errors++;
  1890. }
  1891. /* Tell the DMA to go go go */
  1892. gfar_write(&regs->tstat, TSTAT_CLEAR_THALT >> tx_queue->qindex);
  1893. /* Unlock priv */
  1894. spin_unlock_irqrestore(&tx_queue->txlock, flags);
  1895. return NETDEV_TX_OK;
  1896. }
  1897. /* Stops the kernel queue, and halts the controller */
  1898. static int gfar_close(struct net_device *dev)
  1899. {
  1900. struct gfar_private *priv = netdev_priv(dev);
  1901. disable_napi(priv);
  1902. cancel_work_sync(&priv->reset_task);
  1903. stop_gfar(dev);
  1904. /* Disconnect from the PHY */
  1905. phy_disconnect(priv->phydev);
  1906. priv->phydev = NULL;
  1907. netif_tx_stop_all_queues(dev);
  1908. return 0;
  1909. }
  1910. /* Changes the mac address if the controller is not running. */
  1911. static int gfar_set_mac_address(struct net_device *dev)
  1912. {
  1913. gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
  1914. return 0;
  1915. }
  1916. /* Check if rx parser should be activated */
  1917. void gfar_check_rx_parser_mode(struct gfar_private *priv)
  1918. {
  1919. struct gfar __iomem *regs;
  1920. u32 tempval;
  1921. regs = priv->gfargrp[0].regs;
  1922. tempval = gfar_read(&regs->rctrl);
  1923. /* If parse is no longer required, then disable parser */
  1924. if (tempval & RCTRL_REQ_PARSER) {
  1925. tempval |= RCTRL_PRSDEP_INIT;
  1926. priv->uses_rxfcb = 1;
  1927. } else {
  1928. tempval &= ~RCTRL_PRSDEP_INIT;
  1929. priv->uses_rxfcb = 0;
  1930. }
  1931. gfar_write(&regs->rctrl, tempval);
  1932. }
  1933. /* Enables and disables VLAN insertion/extraction */
  1934. void gfar_vlan_mode(struct net_device *dev, netdev_features_t features)
  1935. {
  1936. struct gfar_private *priv = netdev_priv(dev);
  1937. struct gfar __iomem *regs = NULL;
  1938. unsigned long flags;
  1939. u32 tempval;
  1940. regs = priv->gfargrp[0].regs;
  1941. local_irq_save(flags);
  1942. lock_rx_qs(priv);
  1943. if (features & NETIF_F_HW_VLAN_CTAG_TX) {
  1944. /* Enable VLAN tag insertion */
  1945. tempval = gfar_read(&regs->tctrl);
  1946. tempval |= TCTRL_VLINS;
  1947. gfar_write(&regs->tctrl, tempval);
  1948. } else {
  1949. /* Disable VLAN tag insertion */
  1950. tempval = gfar_read(&regs->tctrl);
  1951. tempval &= ~TCTRL_VLINS;
  1952. gfar_write(&regs->tctrl, tempval);
  1953. }
  1954. if (features & NETIF_F_HW_VLAN_CTAG_RX) {
  1955. /* Enable VLAN tag extraction */
  1956. tempval = gfar_read(&regs->rctrl);
  1957. tempval |= (RCTRL_VLEX | RCTRL_PRSDEP_INIT);
  1958. gfar_write(&regs->rctrl, tempval);
  1959. priv->uses_rxfcb = 1;
  1960. } else {
  1961. /* Disable VLAN tag extraction */
  1962. tempval = gfar_read(&regs->rctrl);
  1963. tempval &= ~RCTRL_VLEX;
  1964. gfar_write(&regs->rctrl, tempval);
  1965. gfar_check_rx_parser_mode(priv);
  1966. }
  1967. gfar_change_mtu(dev, dev->mtu);
  1968. unlock_rx_qs(priv);
  1969. local_irq_restore(flags);
  1970. }
  1971. static int gfar_change_mtu(struct net_device *dev, int new_mtu)
  1972. {
  1973. int tempsize, tempval;
  1974. struct gfar_private *priv = netdev_priv(dev);
  1975. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  1976. int oldsize = priv->rx_buffer_size;
  1977. int frame_size = new_mtu + ETH_HLEN;
  1978. if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
  1979. netif_err(priv, drv, dev, "Invalid MTU setting\n");
  1980. return -EINVAL;
  1981. }
  1982. if (priv->uses_rxfcb)
  1983. frame_size += GMAC_FCB_LEN;
  1984. frame_size += priv->padding;
  1985. tempsize = (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
  1986. INCREMENTAL_BUFFER_SIZE;
  1987. /* Only stop and start the controller if it isn't already
  1988. * stopped, and we changed something
  1989. */
  1990. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1991. stop_gfar(dev);
  1992. priv->rx_buffer_size = tempsize;
  1993. dev->mtu = new_mtu;
  1994. gfar_write(&regs->mrblr, priv->rx_buffer_size);
  1995. gfar_write(&regs->maxfrm, priv->rx_buffer_size);
  1996. /* If the mtu is larger than the max size for standard
  1997. * ethernet frames (ie, a jumbo frame), then set maccfg2
  1998. * to allow huge frames, and to check the length
  1999. */
  2000. tempval = gfar_read(&regs->maccfg2);
  2001. if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE ||
  2002. gfar_has_errata(priv, GFAR_ERRATA_74))
  2003. tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  2004. else
  2005. tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  2006. gfar_write(&regs->maccfg2, tempval);
  2007. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  2008. startup_gfar(dev);
  2009. return 0;
  2010. }
  2011. /* gfar_reset_task gets scheduled when a packet has not been
  2012. * transmitted after a set amount of time.
  2013. * For now, assume that clearing out all the structures, and
  2014. * starting over will fix the problem.
  2015. */
  2016. static void gfar_reset_task(struct work_struct *work)
  2017. {
  2018. struct gfar_private *priv = container_of(work, struct gfar_private,
  2019. reset_task);
  2020. struct net_device *dev = priv->ndev;
  2021. if (dev->flags & IFF_UP) {
  2022. netif_tx_stop_all_queues(dev);
  2023. stop_gfar(dev);
  2024. startup_gfar(dev);
  2025. netif_tx_start_all_queues(dev);
  2026. }
  2027. netif_tx_schedule_all(dev);
  2028. }
  2029. static void gfar_timeout(struct net_device *dev)
  2030. {
  2031. struct gfar_private *priv = netdev_priv(dev);
  2032. dev->stats.tx_errors++;
  2033. schedule_work(&priv->reset_task);
  2034. }
  2035. static void gfar_align_skb(struct sk_buff *skb)
  2036. {
  2037. /* We need the data buffer to be aligned properly. We will reserve
  2038. * as many bytes as needed to align the data properly
  2039. */
  2040. skb_reserve(skb, RXBUF_ALIGNMENT -
  2041. (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1)));
  2042. }
  2043. /* Interrupt Handler for Transmit complete */
  2044. static void gfar_clean_tx_ring(struct gfar_priv_tx_q *tx_queue)
  2045. {
  2046. struct net_device *dev = tx_queue->dev;
  2047. struct netdev_queue *txq;
  2048. struct gfar_private *priv = netdev_priv(dev);
  2049. struct txbd8 *bdp, *next = NULL;
  2050. struct txbd8 *lbdp = NULL;
  2051. struct txbd8 *base = tx_queue->tx_bd_base;
  2052. struct sk_buff *skb;
  2053. int skb_dirtytx;
  2054. int tx_ring_size = tx_queue->tx_ring_size;
  2055. int frags = 0, nr_txbds = 0;
  2056. int i;
  2057. int howmany = 0;
  2058. int tqi = tx_queue->qindex;
  2059. unsigned int bytes_sent = 0;
  2060. u32 lstatus;
  2061. size_t buflen;
  2062. txq = netdev_get_tx_queue(dev, tqi);
  2063. bdp = tx_queue->dirty_tx;
  2064. skb_dirtytx = tx_queue->skb_dirtytx;
  2065. while ((skb = tx_queue->tx_skbuff[skb_dirtytx])) {
  2066. unsigned long flags;
  2067. frags = skb_shinfo(skb)->nr_frags;
  2068. /* When time stamping, one additional TxBD must be freed.
  2069. * Also, we need to dma_unmap_single() the TxPAL.
  2070. */
  2071. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))
  2072. nr_txbds = frags + 2;
  2073. else
  2074. nr_txbds = frags + 1;
  2075. lbdp = skip_txbd(bdp, nr_txbds - 1, base, tx_ring_size);
  2076. lstatus = lbdp->lstatus;
  2077. /* Only clean completed frames */
  2078. if ((lstatus & BD_LFLAG(TXBD_READY)) &&
  2079. (lstatus & BD_LENGTH_MASK))
  2080. break;
  2081. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
  2082. next = next_txbd(bdp, base, tx_ring_size);
  2083. buflen = next->length + GMAC_FCB_LEN + GMAC_TXPAL_LEN;
  2084. } else
  2085. buflen = bdp->length;
  2086. dma_unmap_single(priv->dev, bdp->bufPtr,
  2087. buflen, DMA_TO_DEVICE);
  2088. if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
  2089. struct skb_shared_hwtstamps shhwtstamps;
  2090. u64 *ns = (u64*) (((u32)skb->data + 0x10) & ~0x7);
  2091. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  2092. shhwtstamps.hwtstamp = ns_to_ktime(*ns);
  2093. skb_pull(skb, GMAC_FCB_LEN + GMAC_TXPAL_LEN);
  2094. skb_tstamp_tx(skb, &shhwtstamps);
  2095. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  2096. bdp = next;
  2097. }
  2098. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  2099. bdp = next_txbd(bdp, base, tx_ring_size);
  2100. for (i = 0; i < frags; i++) {
  2101. dma_unmap_page(priv->dev, bdp->bufPtr,
  2102. bdp->length, DMA_TO_DEVICE);
  2103. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  2104. bdp = next_txbd(bdp, base, tx_ring_size);
  2105. }
  2106. bytes_sent += skb->len;
  2107. dev_kfree_skb_any(skb);
  2108. tx_queue->tx_skbuff[skb_dirtytx] = NULL;
  2109. skb_dirtytx = (skb_dirtytx + 1) &
  2110. TX_RING_MOD_MASK(tx_ring_size);
  2111. howmany++;
  2112. spin_lock_irqsave(&tx_queue->txlock, flags);
  2113. tx_queue->num_txbdfree += nr_txbds;
  2114. spin_unlock_irqrestore(&tx_queue->txlock, flags);
  2115. }
  2116. /* If we freed a buffer, we can restart transmission, if necessary */
  2117. if (netif_tx_queue_stopped(txq) && tx_queue->num_txbdfree)
  2118. netif_wake_subqueue(dev, tqi);
  2119. /* Update dirty indicators */
  2120. tx_queue->skb_dirtytx = skb_dirtytx;
  2121. tx_queue->dirty_tx = bdp;
  2122. netdev_tx_completed_queue(txq, howmany, bytes_sent);
  2123. }
  2124. static void gfar_schedule_cleanup(struct gfar_priv_grp *gfargrp)
  2125. {
  2126. unsigned long flags;
  2127. spin_lock_irqsave(&gfargrp->grplock, flags);
  2128. if (napi_schedule_prep(&gfargrp->napi)) {
  2129. gfar_write(&gfargrp->regs->imask, IMASK_RTX_DISABLED);
  2130. __napi_schedule(&gfargrp->napi);
  2131. } else {
  2132. /* Clear IEVENT, so interrupts aren't called again
  2133. * because of the packets that have already arrived.
  2134. */
  2135. gfar_write(&gfargrp->regs->ievent, IEVENT_RTX_MASK);
  2136. }
  2137. spin_unlock_irqrestore(&gfargrp->grplock, flags);
  2138. }
  2139. /* Interrupt Handler for Transmit complete */
  2140. static irqreturn_t gfar_transmit(int irq, void *grp_id)
  2141. {
  2142. gfar_schedule_cleanup((struct gfar_priv_grp *)grp_id);
  2143. return IRQ_HANDLED;
  2144. }
  2145. static void gfar_new_rxbdp(struct gfar_priv_rx_q *rx_queue, struct rxbd8 *bdp,
  2146. struct sk_buff *skb)
  2147. {
  2148. struct net_device *dev = rx_queue->dev;
  2149. struct gfar_private *priv = netdev_priv(dev);
  2150. dma_addr_t buf;
  2151. buf = dma_map_single(priv->dev, skb->data,
  2152. priv->rx_buffer_size, DMA_FROM_DEVICE);
  2153. gfar_init_rxbdp(rx_queue, bdp, buf);
  2154. }
  2155. static struct sk_buff *gfar_alloc_skb(struct net_device *dev)
  2156. {
  2157. struct gfar_private *priv = netdev_priv(dev);
  2158. struct sk_buff *skb;
  2159. skb = netdev_alloc_skb(dev, priv->rx_buffer_size + RXBUF_ALIGNMENT);
  2160. if (!skb)
  2161. return NULL;
  2162. gfar_align_skb(skb);
  2163. return skb;
  2164. }
  2165. struct sk_buff *gfar_new_skb(struct net_device *dev)
  2166. {
  2167. return gfar_alloc_skb(dev);
  2168. }
  2169. static inline void count_errors(unsigned short status, struct net_device *dev)
  2170. {
  2171. struct gfar_private *priv = netdev_priv(dev);
  2172. struct net_device_stats *stats = &dev->stats;
  2173. struct gfar_extra_stats *estats = &priv->extra_stats;
  2174. /* If the packet was truncated, none of the other errors matter */
  2175. if (status & RXBD_TRUNCATED) {
  2176. stats->rx_length_errors++;
  2177. atomic64_inc(&estats->rx_trunc);
  2178. return;
  2179. }
  2180. /* Count the errors, if there were any */
  2181. if (status & (RXBD_LARGE | RXBD_SHORT)) {
  2182. stats->rx_length_errors++;
  2183. if (status & RXBD_LARGE)
  2184. atomic64_inc(&estats->rx_large);
  2185. else
  2186. atomic64_inc(&estats->rx_short);
  2187. }
  2188. if (status & RXBD_NONOCTET) {
  2189. stats->rx_frame_errors++;
  2190. atomic64_inc(&estats->rx_nonoctet);
  2191. }
  2192. if (status & RXBD_CRCERR) {
  2193. atomic64_inc(&estats->rx_crcerr);
  2194. stats->rx_crc_errors++;
  2195. }
  2196. if (status & RXBD_OVERRUN) {
  2197. atomic64_inc(&estats->rx_overrun);
  2198. stats->rx_crc_errors++;
  2199. }
  2200. }
  2201. irqreturn_t gfar_receive(int irq, void *grp_id)
  2202. {
  2203. gfar_schedule_cleanup((struct gfar_priv_grp *)grp_id);
  2204. return IRQ_HANDLED;
  2205. }
  2206. static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
  2207. {
  2208. /* If valid headers were found, and valid sums
  2209. * were verified, then we tell the kernel that no
  2210. * checksumming is necessary. Otherwise, it is [FIXME]
  2211. */
  2212. if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU))
  2213. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2214. else
  2215. skb_checksum_none_assert(skb);
  2216. }
  2217. /* gfar_process_frame() -- handle one incoming packet if skb isn't NULL. */
  2218. static void gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  2219. int amount_pull, struct napi_struct *napi)
  2220. {
  2221. struct gfar_private *priv = netdev_priv(dev);
  2222. struct rxfcb *fcb = NULL;
  2223. /* fcb is at the beginning if exists */
  2224. fcb = (struct rxfcb *)skb->data;
  2225. /* Remove the FCB from the skb
  2226. * Remove the padded bytes, if there are any
  2227. */
  2228. if (amount_pull) {
  2229. skb_record_rx_queue(skb, fcb->rq);
  2230. skb_pull(skb, amount_pull);
  2231. }
  2232. /* Get receive timestamp from the skb */
  2233. if (priv->hwts_rx_en) {
  2234. struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
  2235. u64 *ns = (u64 *) skb->data;
  2236. memset(shhwtstamps, 0, sizeof(*shhwtstamps));
  2237. shhwtstamps->hwtstamp = ns_to_ktime(*ns);
  2238. }
  2239. if (priv->padding)
  2240. skb_pull(skb, priv->padding);
  2241. if (dev->features & NETIF_F_RXCSUM)
  2242. gfar_rx_checksum(skb, fcb);
  2243. /* Tell the skb what kind of packet this is */
  2244. skb->protocol = eth_type_trans(skb, dev);
  2245. /* There's need to check for NETIF_F_HW_VLAN_CTAG_RX here.
  2246. * Even if vlan rx accel is disabled, on some chips
  2247. * RXFCB_VLN is pseudo randomly set.
  2248. */
  2249. if (dev->features & NETIF_F_HW_VLAN_CTAG_RX &&
  2250. fcb->flags & RXFCB_VLN)
  2251. __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), fcb->vlctl);
  2252. /* Send the packet up the stack */
  2253. napi_gro_receive(napi, skb);
  2254. }
  2255. /* gfar_clean_rx_ring() -- Processes each frame in the rx ring
  2256. * until the budget/quota has been reached. Returns the number
  2257. * of frames handled
  2258. */
  2259. int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit)
  2260. {
  2261. struct net_device *dev = rx_queue->dev;
  2262. struct rxbd8 *bdp, *base;
  2263. struct sk_buff *skb;
  2264. int pkt_len;
  2265. int amount_pull;
  2266. int howmany = 0;
  2267. struct gfar_private *priv = netdev_priv(dev);
  2268. /* Get the first full descriptor */
  2269. bdp = rx_queue->cur_rx;
  2270. base = rx_queue->rx_bd_base;
  2271. amount_pull = priv->uses_rxfcb ? GMAC_FCB_LEN : 0;
  2272. while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
  2273. struct sk_buff *newskb;
  2274. rmb();
  2275. /* Add another skb for the future */
  2276. newskb = gfar_new_skb(dev);
  2277. skb = rx_queue->rx_skbuff[rx_queue->skb_currx];
  2278. dma_unmap_single(priv->dev, bdp->bufPtr,
  2279. priv->rx_buffer_size, DMA_FROM_DEVICE);
  2280. if (unlikely(!(bdp->status & RXBD_ERR) &&
  2281. bdp->length > priv->rx_buffer_size))
  2282. bdp->status = RXBD_LARGE;
  2283. /* We drop the frame if we failed to allocate a new buffer */
  2284. if (unlikely(!newskb || !(bdp->status & RXBD_LAST) ||
  2285. bdp->status & RXBD_ERR)) {
  2286. count_errors(bdp->status, dev);
  2287. if (unlikely(!newskb))
  2288. newskb = skb;
  2289. else if (skb)
  2290. dev_kfree_skb(skb);
  2291. } else {
  2292. /* Increment the number of packets */
  2293. rx_queue->stats.rx_packets++;
  2294. howmany++;
  2295. if (likely(skb)) {
  2296. pkt_len = bdp->length - ETH_FCS_LEN;
  2297. /* Remove the FCS from the packet length */
  2298. skb_put(skb, pkt_len);
  2299. rx_queue->stats.rx_bytes += pkt_len;
  2300. skb_record_rx_queue(skb, rx_queue->qindex);
  2301. gfar_process_frame(dev, skb, amount_pull,
  2302. &rx_queue->grp->napi);
  2303. } else {
  2304. netif_warn(priv, rx_err, dev, "Missing skb!\n");
  2305. rx_queue->stats.rx_dropped++;
  2306. atomic64_inc(&priv->extra_stats.rx_skbmissing);
  2307. }
  2308. }
  2309. rx_queue->rx_skbuff[rx_queue->skb_currx] = newskb;
  2310. /* Setup the new bdp */
  2311. gfar_new_rxbdp(rx_queue, bdp, newskb);
  2312. /* Update to the next pointer */
  2313. bdp = next_bd(bdp, base, rx_queue->rx_ring_size);
  2314. /* update to point at the next skb */
  2315. rx_queue->skb_currx = (rx_queue->skb_currx + 1) &
  2316. RX_RING_MOD_MASK(rx_queue->rx_ring_size);
  2317. }
  2318. /* Update the current rxbd pointer to be the next one */
  2319. rx_queue->cur_rx = bdp;
  2320. return howmany;
  2321. }
  2322. static int gfar_poll_sq(struct napi_struct *napi, int budget)
  2323. {
  2324. struct gfar_priv_grp *gfargrp =
  2325. container_of(napi, struct gfar_priv_grp, napi);
  2326. struct gfar __iomem *regs = gfargrp->regs;
  2327. struct gfar_priv_tx_q *tx_queue = gfargrp->priv->tx_queue[0];
  2328. struct gfar_priv_rx_q *rx_queue = gfargrp->priv->rx_queue[0];
  2329. int work_done = 0;
  2330. /* Clear IEVENT, so interrupts aren't called again
  2331. * because of the packets that have already arrived
  2332. */
  2333. gfar_write(&regs->ievent, IEVENT_RTX_MASK);
  2334. /* run Tx cleanup to completion */
  2335. if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx])
  2336. gfar_clean_tx_ring(tx_queue);
  2337. work_done = gfar_clean_rx_ring(rx_queue, budget);
  2338. if (work_done < budget) {
  2339. napi_complete(napi);
  2340. /* Clear the halt bit in RSTAT */
  2341. gfar_write(&regs->rstat, gfargrp->rstat);
  2342. gfar_write(&regs->imask, IMASK_DEFAULT);
  2343. /* If we are coalescing interrupts, update the timer
  2344. * Otherwise, clear it
  2345. */
  2346. gfar_write(&regs->txic, 0);
  2347. if (likely(tx_queue->txcoalescing))
  2348. gfar_write(&regs->txic, tx_queue->txic);
  2349. gfar_write(&regs->rxic, 0);
  2350. if (unlikely(rx_queue->rxcoalescing))
  2351. gfar_write(&regs->rxic, rx_queue->rxic);
  2352. }
  2353. return work_done;
  2354. }
  2355. static int gfar_poll(struct napi_struct *napi, int budget)
  2356. {
  2357. struct gfar_priv_grp *gfargrp =
  2358. container_of(napi, struct gfar_priv_grp, napi);
  2359. struct gfar_private *priv = gfargrp->priv;
  2360. struct gfar __iomem *regs = gfargrp->regs;
  2361. struct gfar_priv_tx_q *tx_queue = NULL;
  2362. struct gfar_priv_rx_q *rx_queue = NULL;
  2363. int work_done = 0, work_done_per_q = 0;
  2364. int i, budget_per_q = 0;
  2365. int has_tx_work;
  2366. unsigned long rstat_rxf;
  2367. int num_act_queues;
  2368. /* Clear IEVENT, so interrupts aren't called again
  2369. * because of the packets that have already arrived
  2370. */
  2371. gfar_write(&regs->ievent, IEVENT_RTX_MASK);
  2372. rstat_rxf = gfar_read(&regs->rstat) & RSTAT_RXF_MASK;
  2373. num_act_queues = bitmap_weight(&rstat_rxf, MAX_RX_QS);
  2374. if (num_act_queues)
  2375. budget_per_q = budget/num_act_queues;
  2376. while (1) {
  2377. has_tx_work = 0;
  2378. for_each_set_bit(i, &gfargrp->tx_bit_map, priv->num_tx_queues) {
  2379. tx_queue = priv->tx_queue[i];
  2380. /* run Tx cleanup to completion */
  2381. if (tx_queue->tx_skbuff[tx_queue->skb_dirtytx]) {
  2382. gfar_clean_tx_ring(tx_queue);
  2383. has_tx_work = 1;
  2384. }
  2385. }
  2386. for_each_set_bit(i, &gfargrp->rx_bit_map, priv->num_rx_queues) {
  2387. /* skip queue if not active */
  2388. if (!(rstat_rxf & (RSTAT_CLEAR_RXF0 >> i)))
  2389. continue;
  2390. rx_queue = priv->rx_queue[i];
  2391. work_done_per_q =
  2392. gfar_clean_rx_ring(rx_queue, budget_per_q);
  2393. work_done += work_done_per_q;
  2394. /* finished processing this queue */
  2395. if (work_done_per_q < budget_per_q) {
  2396. /* clear active queue hw indication */
  2397. gfar_write(&regs->rstat,
  2398. RSTAT_CLEAR_RXF0 >> i);
  2399. rstat_rxf &= ~(RSTAT_CLEAR_RXF0 >> i);
  2400. num_act_queues--;
  2401. if (!num_act_queues)
  2402. break;
  2403. /* recompute budget per Rx queue */
  2404. budget_per_q =
  2405. (budget - work_done) / num_act_queues;
  2406. }
  2407. }
  2408. if (work_done >= budget)
  2409. break;
  2410. if (!num_act_queues && !has_tx_work) {
  2411. napi_complete(napi);
  2412. /* Clear the halt bit in RSTAT */
  2413. gfar_write(&regs->rstat, gfargrp->rstat);
  2414. gfar_write(&regs->imask, IMASK_DEFAULT);
  2415. /* If we are coalescing interrupts, update the timer
  2416. * Otherwise, clear it
  2417. */
  2418. gfar_configure_coalescing(priv, gfargrp->rx_bit_map,
  2419. gfargrp->tx_bit_map);
  2420. break;
  2421. }
  2422. }
  2423. return work_done;
  2424. }
  2425. #ifdef CONFIG_NET_POLL_CONTROLLER
  2426. /* Polling 'interrupt' - used by things like netconsole to send skbs
  2427. * without having to re-enable interrupts. It's not called while
  2428. * the interrupt routine is executing.
  2429. */
  2430. static void gfar_netpoll(struct net_device *dev)
  2431. {
  2432. struct gfar_private *priv = netdev_priv(dev);
  2433. int i;
  2434. /* If the device has multiple interrupts, run tx/rx */
  2435. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  2436. for (i = 0; i < priv->num_grps; i++) {
  2437. struct gfar_priv_grp *grp = &priv->gfargrp[i];
  2438. disable_irq(gfar_irq(grp, TX)->irq);
  2439. disable_irq(gfar_irq(grp, RX)->irq);
  2440. disable_irq(gfar_irq(grp, ER)->irq);
  2441. gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
  2442. enable_irq(gfar_irq(grp, ER)->irq);
  2443. enable_irq(gfar_irq(grp, RX)->irq);
  2444. enable_irq(gfar_irq(grp, TX)->irq);
  2445. }
  2446. } else {
  2447. for (i = 0; i < priv->num_grps; i++) {
  2448. struct gfar_priv_grp *grp = &priv->gfargrp[i];
  2449. disable_irq(gfar_irq(grp, TX)->irq);
  2450. gfar_interrupt(gfar_irq(grp, TX)->irq, grp);
  2451. enable_irq(gfar_irq(grp, TX)->irq);
  2452. }
  2453. }
  2454. }
  2455. #endif
  2456. /* The interrupt handler for devices with one interrupt */
  2457. static irqreturn_t gfar_interrupt(int irq, void *grp_id)
  2458. {
  2459. struct gfar_priv_grp *gfargrp = grp_id;
  2460. /* Save ievent for future reference */
  2461. u32 events = gfar_read(&gfargrp->regs->ievent);
  2462. /* Check for reception */
  2463. if (events & IEVENT_RX_MASK)
  2464. gfar_receive(irq, grp_id);
  2465. /* Check for transmit completion */
  2466. if (events & IEVENT_TX_MASK)
  2467. gfar_transmit(irq, grp_id);
  2468. /* Check for errors */
  2469. if (events & IEVENT_ERR_MASK)
  2470. gfar_error(irq, grp_id);
  2471. return IRQ_HANDLED;
  2472. }
  2473. static u32 gfar_get_flowctrl_cfg(struct gfar_private *priv)
  2474. {
  2475. struct phy_device *phydev = priv->phydev;
  2476. u32 val = 0;
  2477. if (!phydev->duplex)
  2478. return val;
  2479. if (!priv->pause_aneg_en) {
  2480. if (priv->tx_pause_en)
  2481. val |= MACCFG1_TX_FLOW;
  2482. if (priv->rx_pause_en)
  2483. val |= MACCFG1_RX_FLOW;
  2484. } else {
  2485. u16 lcl_adv, rmt_adv;
  2486. u8 flowctrl;
  2487. /* get link partner capabilities */
  2488. rmt_adv = 0;
  2489. if (phydev->pause)
  2490. rmt_adv = LPA_PAUSE_CAP;
  2491. if (phydev->asym_pause)
  2492. rmt_adv |= LPA_PAUSE_ASYM;
  2493. lcl_adv = mii_advertise_flowctrl(phydev->advertising);
  2494. flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
  2495. if (flowctrl & FLOW_CTRL_TX)
  2496. val |= MACCFG1_TX_FLOW;
  2497. if (flowctrl & FLOW_CTRL_RX)
  2498. val |= MACCFG1_RX_FLOW;
  2499. }
  2500. return val;
  2501. }
  2502. /* Called every time the controller might need to be made
  2503. * aware of new link state. The PHY code conveys this
  2504. * information through variables in the phydev structure, and this
  2505. * function converts those variables into the appropriate
  2506. * register values, and can bring down the device if needed.
  2507. */
  2508. static void adjust_link(struct net_device *dev)
  2509. {
  2510. struct gfar_private *priv = netdev_priv(dev);
  2511. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  2512. unsigned long flags;
  2513. struct phy_device *phydev = priv->phydev;
  2514. int new_state = 0;
  2515. local_irq_save(flags);
  2516. lock_tx_qs(priv);
  2517. if (phydev->link) {
  2518. u32 tempval1 = gfar_read(&regs->maccfg1);
  2519. u32 tempval = gfar_read(&regs->maccfg2);
  2520. u32 ecntrl = gfar_read(&regs->ecntrl);
  2521. /* Now we make sure that we can be in full duplex mode.
  2522. * If not, we operate in half-duplex mode.
  2523. */
  2524. if (phydev->duplex != priv->oldduplex) {
  2525. new_state = 1;
  2526. if (!(phydev->duplex))
  2527. tempval &= ~(MACCFG2_FULL_DUPLEX);
  2528. else
  2529. tempval |= MACCFG2_FULL_DUPLEX;
  2530. priv->oldduplex = phydev->duplex;
  2531. }
  2532. if (phydev->speed != priv->oldspeed) {
  2533. new_state = 1;
  2534. switch (phydev->speed) {
  2535. case 1000:
  2536. tempval =
  2537. ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
  2538. ecntrl &= ~(ECNTRL_R100);
  2539. break;
  2540. case 100:
  2541. case 10:
  2542. tempval =
  2543. ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
  2544. /* Reduced mode distinguishes
  2545. * between 10 and 100
  2546. */
  2547. if (phydev->speed == SPEED_100)
  2548. ecntrl |= ECNTRL_R100;
  2549. else
  2550. ecntrl &= ~(ECNTRL_R100);
  2551. break;
  2552. default:
  2553. netif_warn(priv, link, dev,
  2554. "Ack! Speed (%d) is not 10/100/1000!\n",
  2555. phydev->speed);
  2556. break;
  2557. }
  2558. priv->oldspeed = phydev->speed;
  2559. }
  2560. tempval1 &= ~(MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
  2561. tempval1 |= gfar_get_flowctrl_cfg(priv);
  2562. gfar_write(&regs->maccfg1, tempval1);
  2563. gfar_write(&regs->maccfg2, tempval);
  2564. gfar_write(&regs->ecntrl, ecntrl);
  2565. if (!priv->oldlink) {
  2566. new_state = 1;
  2567. priv->oldlink = 1;
  2568. }
  2569. } else if (priv->oldlink) {
  2570. new_state = 1;
  2571. priv->oldlink = 0;
  2572. priv->oldspeed = 0;
  2573. priv->oldduplex = -1;
  2574. }
  2575. if (new_state && netif_msg_link(priv))
  2576. phy_print_status(phydev);
  2577. unlock_tx_qs(priv);
  2578. local_irq_restore(flags);
  2579. }
  2580. /* Update the hash table based on the current list of multicast
  2581. * addresses we subscribe to. Also, change the promiscuity of
  2582. * the device based on the flags (this function is called
  2583. * whenever dev->flags is changed
  2584. */
  2585. static void gfar_set_multi(struct net_device *dev)
  2586. {
  2587. struct netdev_hw_addr *ha;
  2588. struct gfar_private *priv = netdev_priv(dev);
  2589. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  2590. u32 tempval;
  2591. if (dev->flags & IFF_PROMISC) {
  2592. /* Set RCTRL to PROM */
  2593. tempval = gfar_read(&regs->rctrl);
  2594. tempval |= RCTRL_PROM;
  2595. gfar_write(&regs->rctrl, tempval);
  2596. } else {
  2597. /* Set RCTRL to not PROM */
  2598. tempval = gfar_read(&regs->rctrl);
  2599. tempval &= ~(RCTRL_PROM);
  2600. gfar_write(&regs->rctrl, tempval);
  2601. }
  2602. if (dev->flags & IFF_ALLMULTI) {
  2603. /* Set the hash to rx all multicast frames */
  2604. gfar_write(&regs->igaddr0, 0xffffffff);
  2605. gfar_write(&regs->igaddr1, 0xffffffff);
  2606. gfar_write(&regs->igaddr2, 0xffffffff);
  2607. gfar_write(&regs->igaddr3, 0xffffffff);
  2608. gfar_write(&regs->igaddr4, 0xffffffff);
  2609. gfar_write(&regs->igaddr5, 0xffffffff);
  2610. gfar_write(&regs->igaddr6, 0xffffffff);
  2611. gfar_write(&regs->igaddr7, 0xffffffff);
  2612. gfar_write(&regs->gaddr0, 0xffffffff);
  2613. gfar_write(&regs->gaddr1, 0xffffffff);
  2614. gfar_write(&regs->gaddr2, 0xffffffff);
  2615. gfar_write(&regs->gaddr3, 0xffffffff);
  2616. gfar_write(&regs->gaddr4, 0xffffffff);
  2617. gfar_write(&regs->gaddr5, 0xffffffff);
  2618. gfar_write(&regs->gaddr6, 0xffffffff);
  2619. gfar_write(&regs->gaddr7, 0xffffffff);
  2620. } else {
  2621. int em_num;
  2622. int idx;
  2623. /* zero out the hash */
  2624. gfar_write(&regs->igaddr0, 0x0);
  2625. gfar_write(&regs->igaddr1, 0x0);
  2626. gfar_write(&regs->igaddr2, 0x0);
  2627. gfar_write(&regs->igaddr3, 0x0);
  2628. gfar_write(&regs->igaddr4, 0x0);
  2629. gfar_write(&regs->igaddr5, 0x0);
  2630. gfar_write(&regs->igaddr6, 0x0);
  2631. gfar_write(&regs->igaddr7, 0x0);
  2632. gfar_write(&regs->gaddr0, 0x0);
  2633. gfar_write(&regs->gaddr1, 0x0);
  2634. gfar_write(&regs->gaddr2, 0x0);
  2635. gfar_write(&regs->gaddr3, 0x0);
  2636. gfar_write(&regs->gaddr4, 0x0);
  2637. gfar_write(&regs->gaddr5, 0x0);
  2638. gfar_write(&regs->gaddr6, 0x0);
  2639. gfar_write(&regs->gaddr7, 0x0);
  2640. /* If we have extended hash tables, we need to
  2641. * clear the exact match registers to prepare for
  2642. * setting them
  2643. */
  2644. if (priv->extended_hash) {
  2645. em_num = GFAR_EM_NUM + 1;
  2646. gfar_clear_exact_match(dev);
  2647. idx = 1;
  2648. } else {
  2649. idx = 0;
  2650. em_num = 0;
  2651. }
  2652. if (netdev_mc_empty(dev))
  2653. return;
  2654. /* Parse the list, and set the appropriate bits */
  2655. netdev_for_each_mc_addr(ha, dev) {
  2656. if (idx < em_num) {
  2657. gfar_set_mac_for_addr(dev, idx, ha->addr);
  2658. idx++;
  2659. } else
  2660. gfar_set_hash_for_addr(dev, ha->addr);
  2661. }
  2662. }
  2663. }
  2664. /* Clears each of the exact match registers to zero, so they
  2665. * don't interfere with normal reception
  2666. */
  2667. static void gfar_clear_exact_match(struct net_device *dev)
  2668. {
  2669. int idx;
  2670. static const u8 zero_arr[ETH_ALEN] = {0, 0, 0, 0, 0, 0};
  2671. for (idx = 1; idx < GFAR_EM_NUM + 1; idx++)
  2672. gfar_set_mac_for_addr(dev, idx, zero_arr);
  2673. }
  2674. /* Set the appropriate hash bit for the given addr */
  2675. /* The algorithm works like so:
  2676. * 1) Take the Destination Address (ie the multicast address), and
  2677. * do a CRC on it (little endian), and reverse the bits of the
  2678. * result.
  2679. * 2) Use the 8 most significant bits as a hash into a 256-entry
  2680. * table. The table is controlled through 8 32-bit registers:
  2681. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  2682. * gaddr7. This means that the 3 most significant bits in the
  2683. * hash index which gaddr register to use, and the 5 other bits
  2684. * indicate which bit (assuming an IBM numbering scheme, which
  2685. * for PowerPC (tm) is usually the case) in the register holds
  2686. * the entry.
  2687. */
  2688. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
  2689. {
  2690. u32 tempval;
  2691. struct gfar_private *priv = netdev_priv(dev);
  2692. u32 result = ether_crc(ETH_ALEN, addr);
  2693. int width = priv->hash_width;
  2694. u8 whichbit = (result >> (32 - width)) & 0x1f;
  2695. u8 whichreg = result >> (32 - width + 5);
  2696. u32 value = (1 << (31-whichbit));
  2697. tempval = gfar_read(priv->hash_regs[whichreg]);
  2698. tempval |= value;
  2699. gfar_write(priv->hash_regs[whichreg], tempval);
  2700. }
  2701. /* There are multiple MAC Address register pairs on some controllers
  2702. * This function sets the numth pair to a given address
  2703. */
  2704. static void gfar_set_mac_for_addr(struct net_device *dev, int num,
  2705. const u8 *addr)
  2706. {
  2707. struct gfar_private *priv = netdev_priv(dev);
  2708. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  2709. int idx;
  2710. char tmpbuf[ETH_ALEN];
  2711. u32 tempval;
  2712. u32 __iomem *macptr = &regs->macstnaddr1;
  2713. macptr += num*2;
  2714. /* Now copy it into the mac registers backwards, cuz
  2715. * little endian is silly
  2716. */
  2717. for (idx = 0; idx < ETH_ALEN; idx++)
  2718. tmpbuf[ETH_ALEN - 1 - idx] = addr[idx];
  2719. gfar_write(macptr, *((u32 *) (tmpbuf)));
  2720. tempval = *((u32 *) (tmpbuf + 4));
  2721. gfar_write(macptr+1, tempval);
  2722. }
  2723. /* GFAR error interrupt handler */
  2724. static irqreturn_t gfar_error(int irq, void *grp_id)
  2725. {
  2726. struct gfar_priv_grp *gfargrp = grp_id;
  2727. struct gfar __iomem *regs = gfargrp->regs;
  2728. struct gfar_private *priv= gfargrp->priv;
  2729. struct net_device *dev = priv->ndev;
  2730. /* Save ievent for future reference */
  2731. u32 events = gfar_read(&regs->ievent);
  2732. /* Clear IEVENT */
  2733. gfar_write(&regs->ievent, events & IEVENT_ERR_MASK);
  2734. /* Magic Packet is not an error. */
  2735. if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  2736. (events & IEVENT_MAG))
  2737. events &= ~IEVENT_MAG;
  2738. /* Hmm... */
  2739. if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
  2740. netdev_dbg(dev,
  2741. "error interrupt (ievent=0x%08x imask=0x%08x)\n",
  2742. events, gfar_read(&regs->imask));
  2743. /* Update the error counters */
  2744. if (events & IEVENT_TXE) {
  2745. dev->stats.tx_errors++;
  2746. if (events & IEVENT_LC)
  2747. dev->stats.tx_window_errors++;
  2748. if (events & IEVENT_CRL)
  2749. dev->stats.tx_aborted_errors++;
  2750. if (events & IEVENT_XFUN) {
  2751. unsigned long flags;
  2752. netif_dbg(priv, tx_err, dev,
  2753. "TX FIFO underrun, packet dropped\n");
  2754. dev->stats.tx_dropped++;
  2755. atomic64_inc(&priv->extra_stats.tx_underrun);
  2756. local_irq_save(flags);
  2757. lock_tx_qs(priv);
  2758. /* Reactivate the Tx Queues */
  2759. gfar_write(&regs->tstat, gfargrp->tstat);
  2760. unlock_tx_qs(priv);
  2761. local_irq_restore(flags);
  2762. }
  2763. netif_dbg(priv, tx_err, dev, "Transmit Error\n");
  2764. }
  2765. if (events & IEVENT_BSY) {
  2766. dev->stats.rx_errors++;
  2767. atomic64_inc(&priv->extra_stats.rx_bsy);
  2768. gfar_receive(irq, grp_id);
  2769. netif_dbg(priv, rx_err, dev, "busy error (rstat: %x)\n",
  2770. gfar_read(&regs->rstat));
  2771. }
  2772. if (events & IEVENT_BABR) {
  2773. dev->stats.rx_errors++;
  2774. atomic64_inc(&priv->extra_stats.rx_babr);
  2775. netif_dbg(priv, rx_err, dev, "babbling RX error\n");
  2776. }
  2777. if (events & IEVENT_EBERR) {
  2778. atomic64_inc(&priv->extra_stats.eberr);
  2779. netif_dbg(priv, rx_err, dev, "bus error\n");
  2780. }
  2781. if (events & IEVENT_RXC)
  2782. netif_dbg(priv, rx_status, dev, "control frame\n");
  2783. if (events & IEVENT_BABT) {
  2784. atomic64_inc(&priv->extra_stats.tx_babt);
  2785. netif_dbg(priv, tx_err, dev, "babbling TX error\n");
  2786. }
  2787. return IRQ_HANDLED;
  2788. }
  2789. static struct of_device_id gfar_match[] =
  2790. {
  2791. {
  2792. .type = "network",
  2793. .compatible = "gianfar",
  2794. },
  2795. {
  2796. .compatible = "fsl,etsec2",
  2797. },
  2798. {},
  2799. };
  2800. MODULE_DEVICE_TABLE(of, gfar_match);
  2801. /* Structure for a device driver */
  2802. static struct platform_driver gfar_driver = {
  2803. .driver = {
  2804. .name = "fsl-gianfar",
  2805. .owner = THIS_MODULE,
  2806. .pm = GFAR_PM_OPS,
  2807. .of_match_table = gfar_match,
  2808. },
  2809. .probe = gfar_probe,
  2810. .remove = gfar_remove,
  2811. };
  2812. module_platform_driver(gfar_driver);