gianfar.c 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359
  1. /*
  2. * drivers/net/gianfar.c
  3. *
  4. * Gianfar Ethernet Driver
  5. * This driver is designed for the non-CPM ethernet controllers
  6. * on the 85xx and 83xx family of integrated processors
  7. * Based on 8260_io/fcc_enet.c
  8. *
  9. * Author: Andy Fleming
  10. * Maintainer: Kumar Gala
  11. *
  12. * Copyright (c) 2002-2006 Freescale Semiconductor, Inc.
  13. * Copyright (c) 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. #include <linux/kernel.h>
  64. #include <linux/string.h>
  65. #include <linux/errno.h>
  66. #include <linux/unistd.h>
  67. #include <linux/slab.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/init.h>
  70. #include <linux/delay.h>
  71. #include <linux/netdevice.h>
  72. #include <linux/etherdevice.h>
  73. #include <linux/skbuff.h>
  74. #include <linux/if_vlan.h>
  75. #include <linux/spinlock.h>
  76. #include <linux/mm.h>
  77. #include <linux/of_mdio.h>
  78. #include <linux/of_platform.h>
  79. #include <linux/ip.h>
  80. #include <linux/tcp.h>
  81. #include <linux/udp.h>
  82. #include <linux/in.h>
  83. #include <asm/io.h>
  84. #include <asm/irq.h>
  85. #include <asm/uaccess.h>
  86. #include <linux/module.h>
  87. #include <linux/dma-mapping.h>
  88. #include <linux/crc32.h>
  89. #include <linux/mii.h>
  90. #include <linux/phy.h>
  91. #include <linux/phy_fixed.h>
  92. #include <linux/of.h>
  93. #include "gianfar.h"
  94. #include "fsl_pq_mdio.h"
  95. #define TX_TIMEOUT (1*HZ)
  96. #undef BRIEF_GFAR_ERRORS
  97. #undef VERBOSE_GFAR_ERRORS
  98. const char gfar_driver_name[] = "Gianfar Ethernet";
  99. const char gfar_driver_version[] = "1.3";
  100. static int gfar_enet_open(struct net_device *dev);
  101. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev);
  102. static void gfar_reset_task(struct work_struct *work);
  103. static void gfar_timeout(struct net_device *dev);
  104. static int gfar_close(struct net_device *dev);
  105. struct sk_buff *gfar_new_skb(struct net_device *dev);
  106. static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
  107. struct sk_buff *skb);
  108. static int gfar_set_mac_address(struct net_device *dev);
  109. static int gfar_change_mtu(struct net_device *dev, int new_mtu);
  110. static irqreturn_t gfar_error(int irq, void *dev_id);
  111. static irqreturn_t gfar_transmit(int irq, void *dev_id);
  112. static irqreturn_t gfar_interrupt(int irq, void *dev_id);
  113. static void adjust_link(struct net_device *dev);
  114. static void init_registers(struct net_device *dev);
  115. static int init_phy(struct net_device *dev);
  116. static int gfar_probe(struct of_device *ofdev,
  117. const struct of_device_id *match);
  118. static int gfar_remove(struct of_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. #ifdef CONFIG_NET_POLL_CONTROLLER
  125. static void gfar_netpoll(struct net_device *dev);
  126. #endif
  127. int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit);
  128. static int gfar_clean_tx_ring(struct net_device *dev);
  129. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  130. int amount_pull);
  131. static void gfar_vlan_rx_register(struct net_device *netdev,
  132. struct vlan_group *grp);
  133. void gfar_halt(struct net_device *dev);
  134. static void gfar_halt_nodisable(struct net_device *dev);
  135. void gfar_start(struct net_device *dev);
  136. static void gfar_clear_exact_match(struct net_device *dev);
  137. static void gfar_set_mac_for_addr(struct net_device *dev, int num, 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 int gfar_alloc_skb_resources(struct net_device *ndev)
  143. {
  144. struct txbd8 *txbdp;
  145. struct rxbd8 *rxbdp;
  146. dma_addr_t addr = 0;
  147. void *vaddr;
  148. int i;
  149. struct gfar_private *priv = netdev_priv(ndev);
  150. struct device *dev = &priv->ofdev->dev;
  151. struct gfar __iomem *regs = priv->regs;
  152. /* Allocate memory for the buffer descriptors */
  153. vaddr = dma_alloc_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size +
  154. sizeof(*rxbdp) * priv->rx_ring_size,
  155. &addr, GFP_KERNEL);
  156. if (!vaddr) {
  157. if (netif_msg_ifup(priv))
  158. pr_err("%s: Could not allocate buffer descriptors!\n",
  159. ndev->name);
  160. return -ENOMEM;
  161. }
  162. priv->tx_bd_base = vaddr;
  163. /* enet DMA only understands physical addresses */
  164. gfar_write(&regs->tbase0, addr);
  165. /* Start the rx descriptor ring where the tx ring leaves off */
  166. addr = addr + sizeof(*txbdp) * priv->tx_ring_size;
  167. vaddr = vaddr + sizeof(*txbdp) * priv->tx_ring_size;
  168. priv->rx_bd_base = vaddr;
  169. gfar_write(&regs->rbase0, addr);
  170. /* Setup the skbuff rings */
  171. priv->tx_skbuff = kmalloc(sizeof(*priv->tx_skbuff) *
  172. priv->tx_ring_size, GFP_KERNEL);
  173. if (!priv->tx_skbuff) {
  174. if (netif_msg_ifup(priv))
  175. pr_err("%s: Could not allocate tx_skbuff\n",
  176. ndev->name);
  177. goto cleanup;
  178. }
  179. for (i = 0; i < priv->tx_ring_size; i++)
  180. priv->tx_skbuff[i] = NULL;
  181. priv->rx_skbuff = kmalloc(sizeof(*priv->rx_skbuff) *
  182. priv->rx_ring_size, GFP_KERNEL);
  183. if (!priv->rx_skbuff) {
  184. if (netif_msg_ifup(priv))
  185. pr_err("%s: Could not allocate rx_skbuff\n",
  186. ndev->name);
  187. goto cleanup;
  188. }
  189. for (i = 0; i < priv->rx_ring_size; i++)
  190. priv->rx_skbuff[i] = NULL;
  191. /* Initialize some variables in our dev structure */
  192. priv->num_txbdfree = priv->tx_ring_size;
  193. priv->dirty_tx = priv->cur_tx = priv->tx_bd_base;
  194. priv->cur_rx = priv->rx_bd_base;
  195. priv->skb_curtx = priv->skb_dirtytx = 0;
  196. priv->skb_currx = 0;
  197. /* Initialize Transmit Descriptor Ring */
  198. txbdp = priv->tx_bd_base;
  199. for (i = 0; i < priv->tx_ring_size; i++) {
  200. txbdp->lstatus = 0;
  201. txbdp->bufPtr = 0;
  202. txbdp++;
  203. }
  204. /* Set the last descriptor in the ring to indicate wrap */
  205. txbdp--;
  206. txbdp->status |= TXBD_WRAP;
  207. rxbdp = priv->rx_bd_base;
  208. for (i = 0; i < priv->rx_ring_size; i++) {
  209. struct sk_buff *skb;
  210. skb = gfar_new_skb(ndev);
  211. if (!skb) {
  212. pr_err("%s: Can't allocate RX buffers\n", ndev->name);
  213. goto cleanup;
  214. }
  215. priv->rx_skbuff[i] = skb;
  216. gfar_new_rxbdp(ndev, rxbdp, skb);
  217. rxbdp++;
  218. }
  219. return 0;
  220. cleanup:
  221. free_skb_resources(priv);
  222. return -ENOMEM;
  223. }
  224. static void gfar_init_mac(struct net_device *ndev)
  225. {
  226. struct gfar_private *priv = netdev_priv(ndev);
  227. struct gfar __iomem *regs = priv->regs;
  228. u32 rctrl = 0;
  229. u32 tctrl = 0;
  230. u32 attrs = 0;
  231. /* Configure the coalescing support */
  232. gfar_write(&regs->txic, 0);
  233. if (priv->txcoalescing)
  234. gfar_write(&regs->txic, priv->txic);
  235. gfar_write(&regs->rxic, 0);
  236. if (priv->rxcoalescing)
  237. gfar_write(&regs->rxic, priv->rxic);
  238. if (priv->rx_csum_enable)
  239. rctrl |= RCTRL_CHECKSUMMING;
  240. if (priv->extended_hash) {
  241. rctrl |= RCTRL_EXTHASH;
  242. gfar_clear_exact_match(ndev);
  243. rctrl |= RCTRL_EMEN;
  244. }
  245. if (priv->padding) {
  246. rctrl &= ~RCTRL_PAL_MASK;
  247. rctrl |= RCTRL_PADDING(priv->padding);
  248. }
  249. /* keep vlan related bits if it's enabled */
  250. if (priv->vlgrp) {
  251. rctrl |= RCTRL_VLEX | RCTRL_PRSDEP_INIT;
  252. tctrl |= TCTRL_VLINS;
  253. }
  254. /* Init rctrl based on our settings */
  255. gfar_write(&regs->rctrl, rctrl);
  256. if (ndev->features & NETIF_F_IP_CSUM)
  257. tctrl |= TCTRL_INIT_CSUM;
  258. gfar_write(&regs->tctrl, tctrl);
  259. /* Set the extraction length and index */
  260. attrs = ATTRELI_EL(priv->rx_stash_size) |
  261. ATTRELI_EI(priv->rx_stash_index);
  262. gfar_write(&regs->attreli, attrs);
  263. /* Start with defaults, and add stashing or locking
  264. * depending on the approprate variables */
  265. attrs = ATTR_INIT_SETTINGS;
  266. if (priv->bd_stash_en)
  267. attrs |= ATTR_BDSTASH;
  268. if (priv->rx_stash_size != 0)
  269. attrs |= ATTR_BUFSTASH;
  270. gfar_write(&regs->attr, attrs);
  271. gfar_write(&regs->fifo_tx_thr, priv->fifo_threshold);
  272. gfar_write(&regs->fifo_tx_starve, priv->fifo_starve);
  273. gfar_write(&regs->fifo_tx_starve_shutoff, priv->fifo_starve_off);
  274. }
  275. static const struct net_device_ops gfar_netdev_ops = {
  276. .ndo_open = gfar_enet_open,
  277. .ndo_start_xmit = gfar_start_xmit,
  278. .ndo_stop = gfar_close,
  279. .ndo_change_mtu = gfar_change_mtu,
  280. .ndo_set_multicast_list = gfar_set_multi,
  281. .ndo_tx_timeout = gfar_timeout,
  282. .ndo_do_ioctl = gfar_ioctl,
  283. .ndo_vlan_rx_register = gfar_vlan_rx_register,
  284. .ndo_set_mac_address = eth_mac_addr,
  285. .ndo_validate_addr = eth_validate_addr,
  286. #ifdef CONFIG_NET_POLL_CONTROLLER
  287. .ndo_poll_controller = gfar_netpoll,
  288. #endif
  289. };
  290. /* Returns 1 if incoming frames use an FCB */
  291. static inline int gfar_uses_fcb(struct gfar_private *priv)
  292. {
  293. return priv->vlgrp || priv->rx_csum_enable;
  294. }
  295. static int gfar_of_init(struct net_device *dev)
  296. {
  297. const char *model;
  298. const char *ctype;
  299. const void *mac_addr;
  300. u64 addr, size;
  301. int err = 0;
  302. struct gfar_private *priv = netdev_priv(dev);
  303. struct device_node *np = priv->node;
  304. const u32 *stash;
  305. const u32 *stash_len;
  306. const u32 *stash_idx;
  307. if (!np || !of_device_is_available(np))
  308. return -ENODEV;
  309. /* get a pointer to the register memory */
  310. addr = of_translate_address(np, of_get_address(np, 0, &size, NULL));
  311. priv->regs = ioremap(addr, size);
  312. if (priv->regs == NULL)
  313. return -ENOMEM;
  314. priv->interruptTransmit = irq_of_parse_and_map(np, 0);
  315. model = of_get_property(np, "model", NULL);
  316. /* If we aren't the FEC we have multiple interrupts */
  317. if (model && strcasecmp(model, "FEC")) {
  318. priv->interruptReceive = irq_of_parse_and_map(np, 1);
  319. priv->interruptError = irq_of_parse_and_map(np, 2);
  320. if (priv->interruptTransmit < 0 ||
  321. priv->interruptReceive < 0 ||
  322. priv->interruptError < 0) {
  323. err = -EINVAL;
  324. goto err_out;
  325. }
  326. }
  327. stash = of_get_property(np, "bd-stash", NULL);
  328. if(stash) {
  329. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BD_STASHING;
  330. priv->bd_stash_en = 1;
  331. }
  332. stash_len = of_get_property(np, "rx-stash-len", NULL);
  333. if (stash_len)
  334. priv->rx_stash_size = *stash_len;
  335. stash_idx = of_get_property(np, "rx-stash-idx", NULL);
  336. if (stash_idx)
  337. priv->rx_stash_index = *stash_idx;
  338. if (stash_len || stash_idx)
  339. priv->device_flags |= FSL_GIANFAR_DEV_HAS_BUF_STASHING;
  340. mac_addr = of_get_mac_address(np);
  341. if (mac_addr)
  342. memcpy(dev->dev_addr, mac_addr, MAC_ADDR_LEN);
  343. if (model && !strcasecmp(model, "TSEC"))
  344. priv->device_flags =
  345. FSL_GIANFAR_DEV_HAS_GIGABIT |
  346. FSL_GIANFAR_DEV_HAS_COALESCE |
  347. FSL_GIANFAR_DEV_HAS_RMON |
  348. FSL_GIANFAR_DEV_HAS_MULTI_INTR;
  349. if (model && !strcasecmp(model, "eTSEC"))
  350. priv->device_flags =
  351. FSL_GIANFAR_DEV_HAS_GIGABIT |
  352. FSL_GIANFAR_DEV_HAS_COALESCE |
  353. FSL_GIANFAR_DEV_HAS_RMON |
  354. FSL_GIANFAR_DEV_HAS_MULTI_INTR |
  355. FSL_GIANFAR_DEV_HAS_PADDING |
  356. FSL_GIANFAR_DEV_HAS_CSUM |
  357. FSL_GIANFAR_DEV_HAS_VLAN |
  358. FSL_GIANFAR_DEV_HAS_MAGIC_PACKET |
  359. FSL_GIANFAR_DEV_HAS_EXTENDED_HASH;
  360. ctype = of_get_property(np, "phy-connection-type", NULL);
  361. /* We only care about rgmii-id. The rest are autodetected */
  362. if (ctype && !strcmp(ctype, "rgmii-id"))
  363. priv->interface = PHY_INTERFACE_MODE_RGMII_ID;
  364. else
  365. priv->interface = PHY_INTERFACE_MODE_MII;
  366. if (of_get_property(np, "fsl,magic-packet", NULL))
  367. priv->device_flags |= FSL_GIANFAR_DEV_HAS_MAGIC_PACKET;
  368. priv->phy_node = of_parse_phandle(np, "phy-handle", 0);
  369. /* Find the TBI PHY. If it's not there, we don't support SGMII */
  370. priv->tbi_node = of_parse_phandle(np, "tbi-handle", 0);
  371. return 0;
  372. err_out:
  373. iounmap(priv->regs);
  374. return err;
  375. }
  376. /* Ioctl MII Interface */
  377. static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  378. {
  379. struct gfar_private *priv = netdev_priv(dev);
  380. if (!netif_running(dev))
  381. return -EINVAL;
  382. if (!priv->phydev)
  383. return -ENODEV;
  384. return phy_mii_ioctl(priv->phydev, if_mii(rq), cmd);
  385. }
  386. /* Set up the ethernet device structure, private data,
  387. * and anything else we need before we start */
  388. static int gfar_probe(struct of_device *ofdev,
  389. const struct of_device_id *match)
  390. {
  391. u32 tempval;
  392. struct net_device *dev = NULL;
  393. struct gfar_private *priv = NULL;
  394. int err = 0;
  395. int len_devname;
  396. /* Create an ethernet device instance */
  397. dev = alloc_etherdev(sizeof (*priv));
  398. if (NULL == dev)
  399. return -ENOMEM;
  400. priv = netdev_priv(dev);
  401. priv->ndev = dev;
  402. priv->ofdev = ofdev;
  403. priv->node = ofdev->node;
  404. SET_NETDEV_DEV(dev, &ofdev->dev);
  405. err = gfar_of_init(dev);
  406. if (err)
  407. goto regs_fail;
  408. spin_lock_init(&priv->txlock);
  409. spin_lock_init(&priv->rxlock);
  410. spin_lock_init(&priv->bflock);
  411. INIT_WORK(&priv->reset_task, gfar_reset_task);
  412. dev_set_drvdata(&ofdev->dev, priv);
  413. /* Stop the DMA engine now, in case it was running before */
  414. /* (The firmware could have used it, and left it running). */
  415. gfar_halt(dev);
  416. /* Reset MAC layer */
  417. gfar_write(&priv->regs->maccfg1, MACCFG1_SOFT_RESET);
  418. /* We need to delay at least 3 TX clocks */
  419. udelay(2);
  420. tempval = (MACCFG1_TX_FLOW | MACCFG1_RX_FLOW);
  421. gfar_write(&priv->regs->maccfg1, tempval);
  422. /* Initialize MACCFG2. */
  423. gfar_write(&priv->regs->maccfg2, MACCFG2_INIT_SETTINGS);
  424. /* Initialize ECNTRL */
  425. gfar_write(&priv->regs->ecntrl, ECNTRL_INIT_SETTINGS);
  426. /* Set the dev->base_addr to the gfar reg region */
  427. dev->base_addr = (unsigned long) (priv->regs);
  428. SET_NETDEV_DEV(dev, &ofdev->dev);
  429. /* Fill in the dev structure */
  430. dev->watchdog_timeo = TX_TIMEOUT;
  431. netif_napi_add(dev, &priv->napi, gfar_poll, GFAR_DEV_WEIGHT);
  432. dev->mtu = 1500;
  433. dev->netdev_ops = &gfar_netdev_ops;
  434. dev->ethtool_ops = &gfar_ethtool_ops;
  435. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM) {
  436. priv->rx_csum_enable = 1;
  437. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA;
  438. } else
  439. priv->rx_csum_enable = 0;
  440. priv->vlgrp = NULL;
  441. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_VLAN)
  442. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  443. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_EXTENDED_HASH) {
  444. priv->extended_hash = 1;
  445. priv->hash_width = 9;
  446. priv->hash_regs[0] = &priv->regs->igaddr0;
  447. priv->hash_regs[1] = &priv->regs->igaddr1;
  448. priv->hash_regs[2] = &priv->regs->igaddr2;
  449. priv->hash_regs[3] = &priv->regs->igaddr3;
  450. priv->hash_regs[4] = &priv->regs->igaddr4;
  451. priv->hash_regs[5] = &priv->regs->igaddr5;
  452. priv->hash_regs[6] = &priv->regs->igaddr6;
  453. priv->hash_regs[7] = &priv->regs->igaddr7;
  454. priv->hash_regs[8] = &priv->regs->gaddr0;
  455. priv->hash_regs[9] = &priv->regs->gaddr1;
  456. priv->hash_regs[10] = &priv->regs->gaddr2;
  457. priv->hash_regs[11] = &priv->regs->gaddr3;
  458. priv->hash_regs[12] = &priv->regs->gaddr4;
  459. priv->hash_regs[13] = &priv->regs->gaddr5;
  460. priv->hash_regs[14] = &priv->regs->gaddr6;
  461. priv->hash_regs[15] = &priv->regs->gaddr7;
  462. } else {
  463. priv->extended_hash = 0;
  464. priv->hash_width = 8;
  465. priv->hash_regs[0] = &priv->regs->gaddr0;
  466. priv->hash_regs[1] = &priv->regs->gaddr1;
  467. priv->hash_regs[2] = &priv->regs->gaddr2;
  468. priv->hash_regs[3] = &priv->regs->gaddr3;
  469. priv->hash_regs[4] = &priv->regs->gaddr4;
  470. priv->hash_regs[5] = &priv->regs->gaddr5;
  471. priv->hash_regs[6] = &priv->regs->gaddr6;
  472. priv->hash_regs[7] = &priv->regs->gaddr7;
  473. }
  474. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_PADDING)
  475. priv->padding = DEFAULT_PADDING;
  476. else
  477. priv->padding = 0;
  478. if (dev->features & NETIF_F_IP_CSUM)
  479. dev->hard_header_len += GMAC_FCB_LEN;
  480. priv->rx_buffer_size = DEFAULT_RX_BUFFER_SIZE;
  481. priv->tx_ring_size = DEFAULT_TX_RING_SIZE;
  482. priv->rx_ring_size = DEFAULT_RX_RING_SIZE;
  483. priv->num_txbdfree = DEFAULT_TX_RING_SIZE;
  484. priv->txcoalescing = DEFAULT_TX_COALESCE;
  485. priv->txic = DEFAULT_TXIC;
  486. priv->rxcoalescing = DEFAULT_RX_COALESCE;
  487. priv->rxic = DEFAULT_RXIC;
  488. /* Enable most messages by default */
  489. priv->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
  490. /* Carrier starts down, phylib will bring it up */
  491. netif_carrier_off(dev);
  492. err = register_netdev(dev);
  493. if (err) {
  494. printk(KERN_ERR "%s: Cannot register net device, aborting.\n",
  495. dev->name);
  496. goto register_fail;
  497. }
  498. device_init_wakeup(&dev->dev,
  499. priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  500. /* fill out IRQ number and name fields */
  501. len_devname = strlen(dev->name);
  502. strncpy(&priv->int_name_tx[0], dev->name, len_devname);
  503. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  504. strncpy(&priv->int_name_tx[len_devname],
  505. "_tx", sizeof("_tx") + 1);
  506. strncpy(&priv->int_name_rx[0], dev->name, len_devname);
  507. strncpy(&priv->int_name_rx[len_devname],
  508. "_rx", sizeof("_rx") + 1);
  509. strncpy(&priv->int_name_er[0], dev->name, len_devname);
  510. strncpy(&priv->int_name_er[len_devname],
  511. "_er", sizeof("_er") + 1);
  512. } else
  513. priv->int_name_tx[len_devname] = '\0';
  514. /* Create all the sysfs files */
  515. gfar_init_sysfs(dev);
  516. /* Print out the device info */
  517. printk(KERN_INFO DEVICE_NAME "%pM\n", dev->name, dev->dev_addr);
  518. /* Even more device info helps when determining which kernel */
  519. /* provided which set of benchmarks. */
  520. printk(KERN_INFO "%s: Running with NAPI enabled\n", dev->name);
  521. printk(KERN_INFO "%s: %d/%d RX/TX BD ring size\n",
  522. dev->name, priv->rx_ring_size, priv->tx_ring_size);
  523. return 0;
  524. register_fail:
  525. iounmap(priv->regs);
  526. regs_fail:
  527. if (priv->phy_node)
  528. of_node_put(priv->phy_node);
  529. if (priv->tbi_node)
  530. of_node_put(priv->tbi_node);
  531. free_netdev(dev);
  532. return err;
  533. }
  534. static int gfar_remove(struct of_device *ofdev)
  535. {
  536. struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
  537. if (priv->phy_node)
  538. of_node_put(priv->phy_node);
  539. if (priv->tbi_node)
  540. of_node_put(priv->tbi_node);
  541. dev_set_drvdata(&ofdev->dev, NULL);
  542. unregister_netdev(priv->ndev);
  543. iounmap(priv->regs);
  544. free_netdev(priv->ndev);
  545. return 0;
  546. }
  547. #ifdef CONFIG_PM
  548. static int gfar_suspend(struct of_device *ofdev, pm_message_t state)
  549. {
  550. struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
  551. struct net_device *dev = priv->ndev;
  552. unsigned long flags;
  553. u32 tempval;
  554. int magic_packet = priv->wol_en &&
  555. (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  556. netif_device_detach(dev);
  557. if (netif_running(dev)) {
  558. spin_lock_irqsave(&priv->txlock, flags);
  559. spin_lock(&priv->rxlock);
  560. gfar_halt_nodisable(dev);
  561. /* Disable Tx, and Rx if wake-on-LAN is disabled. */
  562. tempval = gfar_read(&priv->regs->maccfg1);
  563. tempval &= ~MACCFG1_TX_EN;
  564. if (!magic_packet)
  565. tempval &= ~MACCFG1_RX_EN;
  566. gfar_write(&priv->regs->maccfg1, tempval);
  567. spin_unlock(&priv->rxlock);
  568. spin_unlock_irqrestore(&priv->txlock, flags);
  569. napi_disable(&priv->napi);
  570. if (magic_packet) {
  571. /* Enable interrupt on Magic Packet */
  572. gfar_write(&priv->regs->imask, IMASK_MAG);
  573. /* Enable Magic Packet mode */
  574. tempval = gfar_read(&priv->regs->maccfg2);
  575. tempval |= MACCFG2_MPEN;
  576. gfar_write(&priv->regs->maccfg2, tempval);
  577. } else {
  578. phy_stop(priv->phydev);
  579. }
  580. }
  581. return 0;
  582. }
  583. static int gfar_resume(struct of_device *ofdev)
  584. {
  585. struct gfar_private *priv = dev_get_drvdata(&ofdev->dev);
  586. struct net_device *dev = priv->ndev;
  587. unsigned long flags;
  588. u32 tempval;
  589. int magic_packet = priv->wol_en &&
  590. (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET);
  591. if (!netif_running(dev)) {
  592. netif_device_attach(dev);
  593. return 0;
  594. }
  595. if (!magic_packet && priv->phydev)
  596. phy_start(priv->phydev);
  597. /* Disable Magic Packet mode, in case something
  598. * else woke us up.
  599. */
  600. spin_lock_irqsave(&priv->txlock, flags);
  601. spin_lock(&priv->rxlock);
  602. tempval = gfar_read(&priv->regs->maccfg2);
  603. tempval &= ~MACCFG2_MPEN;
  604. gfar_write(&priv->regs->maccfg2, tempval);
  605. gfar_start(dev);
  606. spin_unlock(&priv->rxlock);
  607. spin_unlock_irqrestore(&priv->txlock, flags);
  608. netif_device_attach(dev);
  609. napi_enable(&priv->napi);
  610. return 0;
  611. }
  612. #else
  613. #define gfar_suspend NULL
  614. #define gfar_resume NULL
  615. #endif
  616. /* Reads the controller's registers to determine what interface
  617. * connects it to the PHY.
  618. */
  619. static phy_interface_t gfar_get_interface(struct net_device *dev)
  620. {
  621. struct gfar_private *priv = netdev_priv(dev);
  622. u32 ecntrl = gfar_read(&priv->regs->ecntrl);
  623. if (ecntrl & ECNTRL_SGMII_MODE)
  624. return PHY_INTERFACE_MODE_SGMII;
  625. if (ecntrl & ECNTRL_TBI_MODE) {
  626. if (ecntrl & ECNTRL_REDUCED_MODE)
  627. return PHY_INTERFACE_MODE_RTBI;
  628. else
  629. return PHY_INTERFACE_MODE_TBI;
  630. }
  631. if (ecntrl & ECNTRL_REDUCED_MODE) {
  632. if (ecntrl & ECNTRL_REDUCED_MII_MODE)
  633. return PHY_INTERFACE_MODE_RMII;
  634. else {
  635. phy_interface_t interface = priv->interface;
  636. /*
  637. * This isn't autodetected right now, so it must
  638. * be set by the device tree or platform code.
  639. */
  640. if (interface == PHY_INTERFACE_MODE_RGMII_ID)
  641. return PHY_INTERFACE_MODE_RGMII_ID;
  642. return PHY_INTERFACE_MODE_RGMII;
  643. }
  644. }
  645. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT)
  646. return PHY_INTERFACE_MODE_GMII;
  647. return PHY_INTERFACE_MODE_MII;
  648. }
  649. /* Initializes driver's PHY state, and attaches to the PHY.
  650. * Returns 0 on success.
  651. */
  652. static int init_phy(struct net_device *dev)
  653. {
  654. struct gfar_private *priv = netdev_priv(dev);
  655. uint gigabit_support =
  656. priv->device_flags & FSL_GIANFAR_DEV_HAS_GIGABIT ?
  657. SUPPORTED_1000baseT_Full : 0;
  658. phy_interface_t interface;
  659. priv->oldlink = 0;
  660. priv->oldspeed = 0;
  661. priv->oldduplex = -1;
  662. interface = gfar_get_interface(dev);
  663. priv->phydev = of_phy_connect(dev, priv->phy_node, &adjust_link, 0,
  664. interface);
  665. if (!priv->phydev)
  666. priv->phydev = of_phy_connect_fixed_link(dev, &adjust_link,
  667. interface);
  668. if (!priv->phydev) {
  669. dev_err(&dev->dev, "could not attach to PHY\n");
  670. return -ENODEV;
  671. }
  672. if (interface == PHY_INTERFACE_MODE_SGMII)
  673. gfar_configure_serdes(dev);
  674. /* Remove any features not supported by the controller */
  675. priv->phydev->supported &= (GFAR_SUPPORTED | gigabit_support);
  676. priv->phydev->advertising = priv->phydev->supported;
  677. return 0;
  678. }
  679. /*
  680. * Initialize TBI PHY interface for communicating with the
  681. * SERDES lynx PHY on the chip. We communicate with this PHY
  682. * through the MDIO bus on each controller, treating it as a
  683. * "normal" PHY at the address found in the TBIPA register. We assume
  684. * that the TBIPA register is valid. Either the MDIO bus code will set
  685. * it to a value that doesn't conflict with other PHYs on the bus, or the
  686. * value doesn't matter, as there are no other PHYs on the bus.
  687. */
  688. static void gfar_configure_serdes(struct net_device *dev)
  689. {
  690. struct gfar_private *priv = netdev_priv(dev);
  691. struct phy_device *tbiphy;
  692. if (!priv->tbi_node) {
  693. dev_warn(&dev->dev, "error: SGMII mode requires that the "
  694. "device tree specify a tbi-handle\n");
  695. return;
  696. }
  697. tbiphy = of_phy_find_device(priv->tbi_node);
  698. if (!tbiphy) {
  699. dev_err(&dev->dev, "error: Could not get TBI device\n");
  700. return;
  701. }
  702. /*
  703. * If the link is already up, we must already be ok, and don't need to
  704. * configure and reset the TBI<->SerDes link. Maybe U-Boot configured
  705. * everything for us? Resetting it takes the link down and requires
  706. * several seconds for it to come back.
  707. */
  708. if (phy_read(tbiphy, MII_BMSR) & BMSR_LSTATUS)
  709. return;
  710. /* Single clk mode, mii mode off(for serdes communication) */
  711. phy_write(tbiphy, MII_TBICON, TBICON_CLK_SELECT);
  712. phy_write(tbiphy, MII_ADVERTISE,
  713. ADVERTISE_1000XFULL | ADVERTISE_1000XPAUSE |
  714. ADVERTISE_1000XPSE_ASYM);
  715. phy_write(tbiphy, MII_BMCR, BMCR_ANENABLE |
  716. BMCR_ANRESTART | BMCR_FULLDPLX | BMCR_SPEED1000);
  717. }
  718. static void init_registers(struct net_device *dev)
  719. {
  720. struct gfar_private *priv = netdev_priv(dev);
  721. /* Clear IEVENT */
  722. gfar_write(&priv->regs->ievent, IEVENT_INIT_CLEAR);
  723. /* Initialize IMASK */
  724. gfar_write(&priv->regs->imask, IMASK_INIT_CLEAR);
  725. /* Init hash registers to zero */
  726. gfar_write(&priv->regs->igaddr0, 0);
  727. gfar_write(&priv->regs->igaddr1, 0);
  728. gfar_write(&priv->regs->igaddr2, 0);
  729. gfar_write(&priv->regs->igaddr3, 0);
  730. gfar_write(&priv->regs->igaddr4, 0);
  731. gfar_write(&priv->regs->igaddr5, 0);
  732. gfar_write(&priv->regs->igaddr6, 0);
  733. gfar_write(&priv->regs->igaddr7, 0);
  734. gfar_write(&priv->regs->gaddr0, 0);
  735. gfar_write(&priv->regs->gaddr1, 0);
  736. gfar_write(&priv->regs->gaddr2, 0);
  737. gfar_write(&priv->regs->gaddr3, 0);
  738. gfar_write(&priv->regs->gaddr4, 0);
  739. gfar_write(&priv->regs->gaddr5, 0);
  740. gfar_write(&priv->regs->gaddr6, 0);
  741. gfar_write(&priv->regs->gaddr7, 0);
  742. /* Zero out the rmon mib registers if it has them */
  743. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
  744. memset_io(&(priv->regs->rmon), 0, sizeof (struct rmon_mib));
  745. /* Mask off the CAM interrupts */
  746. gfar_write(&priv->regs->rmon.cam1, 0xffffffff);
  747. gfar_write(&priv->regs->rmon.cam2, 0xffffffff);
  748. }
  749. /* Initialize the max receive buffer length */
  750. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  751. /* Initialize the Minimum Frame Length Register */
  752. gfar_write(&priv->regs->minflr, MINFLR_INIT_SETTINGS);
  753. }
  754. /* Halt the receive and transmit queues */
  755. static void gfar_halt_nodisable(struct net_device *dev)
  756. {
  757. struct gfar_private *priv = netdev_priv(dev);
  758. struct gfar __iomem *regs = priv->regs;
  759. u32 tempval;
  760. /* Mask all interrupts */
  761. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  762. /* Clear all interrupts */
  763. gfar_write(&regs->ievent, IEVENT_INIT_CLEAR);
  764. /* Stop the DMA, and wait for it to stop */
  765. tempval = gfar_read(&priv->regs->dmactrl);
  766. if ((tempval & (DMACTRL_GRS | DMACTRL_GTS))
  767. != (DMACTRL_GRS | DMACTRL_GTS)) {
  768. tempval |= (DMACTRL_GRS | DMACTRL_GTS);
  769. gfar_write(&priv->regs->dmactrl, tempval);
  770. while (!(gfar_read(&priv->regs->ievent) &
  771. (IEVENT_GRSC | IEVENT_GTSC)))
  772. cpu_relax();
  773. }
  774. }
  775. /* Halt the receive and transmit queues */
  776. void gfar_halt(struct net_device *dev)
  777. {
  778. struct gfar_private *priv = netdev_priv(dev);
  779. struct gfar __iomem *regs = priv->regs;
  780. u32 tempval;
  781. gfar_halt_nodisable(dev);
  782. /* Disable Rx and Tx */
  783. tempval = gfar_read(&regs->maccfg1);
  784. tempval &= ~(MACCFG1_RX_EN | MACCFG1_TX_EN);
  785. gfar_write(&regs->maccfg1, tempval);
  786. }
  787. void stop_gfar(struct net_device *dev)
  788. {
  789. struct gfar_private *priv = netdev_priv(dev);
  790. unsigned long flags;
  791. phy_stop(priv->phydev);
  792. /* Lock it down */
  793. spin_lock_irqsave(&priv->txlock, flags);
  794. spin_lock(&priv->rxlock);
  795. gfar_halt(dev);
  796. spin_unlock(&priv->rxlock);
  797. spin_unlock_irqrestore(&priv->txlock, flags);
  798. /* Free the IRQs */
  799. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  800. free_irq(priv->interruptError, dev);
  801. free_irq(priv->interruptTransmit, dev);
  802. free_irq(priv->interruptReceive, dev);
  803. } else {
  804. free_irq(priv->interruptTransmit, dev);
  805. }
  806. free_skb_resources(priv);
  807. }
  808. /* If there are any tx skbs or rx skbs still around, free them.
  809. * Then free tx_skbuff and rx_skbuff */
  810. static void free_skb_resources(struct gfar_private *priv)
  811. {
  812. struct device *dev = &priv->ofdev->dev;
  813. struct rxbd8 *rxbdp;
  814. struct txbd8 *txbdp;
  815. int i, j;
  816. /* Go through all the buffer descriptors and free their data buffers */
  817. txbdp = priv->tx_bd_base;
  818. if (!priv->tx_skbuff)
  819. goto skip_tx_skbuff;
  820. for (i = 0; i < priv->tx_ring_size; i++) {
  821. if (!priv->tx_skbuff[i])
  822. continue;
  823. dma_unmap_single(&priv->ofdev->dev, txbdp->bufPtr,
  824. txbdp->length, DMA_TO_DEVICE);
  825. txbdp->lstatus = 0;
  826. for (j = 0; j < skb_shinfo(priv->tx_skbuff[i])->nr_frags; j++) {
  827. txbdp++;
  828. dma_unmap_page(&priv->ofdev->dev, txbdp->bufPtr,
  829. txbdp->length, DMA_TO_DEVICE);
  830. }
  831. txbdp++;
  832. dev_kfree_skb_any(priv->tx_skbuff[i]);
  833. priv->tx_skbuff[i] = NULL;
  834. }
  835. kfree(priv->tx_skbuff);
  836. skip_tx_skbuff:
  837. rxbdp = priv->rx_bd_base;
  838. if (!priv->rx_skbuff)
  839. goto skip_rx_skbuff;
  840. for (i = 0; i < priv->rx_ring_size; i++) {
  841. if (priv->rx_skbuff[i]) {
  842. dma_unmap_single(&priv->ofdev->dev, rxbdp->bufPtr,
  843. priv->rx_buffer_size,
  844. DMA_FROM_DEVICE);
  845. dev_kfree_skb_any(priv->rx_skbuff[i]);
  846. priv->rx_skbuff[i] = NULL;
  847. }
  848. rxbdp->lstatus = 0;
  849. rxbdp->bufPtr = 0;
  850. rxbdp++;
  851. }
  852. kfree(priv->rx_skbuff);
  853. skip_rx_skbuff:
  854. dma_free_coherent(dev, sizeof(*txbdp) * priv->tx_ring_size +
  855. sizeof(*rxbdp) * priv->rx_ring_size,
  856. priv->tx_bd_base, gfar_read(&priv->regs->tbase0));
  857. }
  858. void gfar_start(struct net_device *dev)
  859. {
  860. struct gfar_private *priv = netdev_priv(dev);
  861. struct gfar __iomem *regs = priv->regs;
  862. u32 tempval;
  863. /* Enable Rx and Tx in MACCFG1 */
  864. tempval = gfar_read(&regs->maccfg1);
  865. tempval |= (MACCFG1_RX_EN | MACCFG1_TX_EN);
  866. gfar_write(&regs->maccfg1, tempval);
  867. /* Initialize DMACTRL to have WWR and WOP */
  868. tempval = gfar_read(&priv->regs->dmactrl);
  869. tempval |= DMACTRL_INIT_SETTINGS;
  870. gfar_write(&priv->regs->dmactrl, tempval);
  871. /* Make sure we aren't stopped */
  872. tempval = gfar_read(&priv->regs->dmactrl);
  873. tempval &= ~(DMACTRL_GRS | DMACTRL_GTS);
  874. gfar_write(&priv->regs->dmactrl, tempval);
  875. /* Clear THLT/RHLT, so that the DMA starts polling now */
  876. gfar_write(&regs->tstat, TSTAT_CLEAR_THALT);
  877. gfar_write(&regs->rstat, RSTAT_CLEAR_RHALT);
  878. /* Unmask the interrupts we look for */
  879. gfar_write(&regs->imask, IMASK_DEFAULT);
  880. dev->trans_start = jiffies;
  881. }
  882. /* Bring the controller up and running */
  883. int startup_gfar(struct net_device *ndev)
  884. {
  885. struct gfar_private *priv = netdev_priv(ndev);
  886. struct gfar __iomem *regs = priv->regs;
  887. int err;
  888. gfar_write(&regs->imask, IMASK_INIT_CLEAR);
  889. err = gfar_alloc_skb_resources(ndev);
  890. if (err)
  891. return err;
  892. gfar_init_mac(ndev);
  893. /* If the device has multiple interrupts, register for
  894. * them. Otherwise, only register for the one */
  895. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  896. /* Install our interrupt handlers for Error,
  897. * Transmit, and Receive */
  898. err = request_irq(priv->interruptError, gfar_error, 0,
  899. priv->int_name_er, ndev);
  900. if (err) {
  901. if (netif_msg_intr(priv))
  902. pr_err("%s: Can't get IRQ %d\n", ndev->name,
  903. priv->interruptError);
  904. goto err_irq_fail;
  905. }
  906. err = request_irq(priv->interruptTransmit, gfar_transmit, 0,
  907. priv->int_name_tx, ndev);
  908. if (err) {
  909. if (netif_msg_intr(priv))
  910. pr_err("%s: Can't get IRQ %d\n", ndev->name,
  911. priv->interruptTransmit);
  912. goto tx_irq_fail;
  913. }
  914. err = request_irq(priv->interruptReceive, gfar_receive, 0,
  915. priv->int_name_rx, ndev);
  916. if (err) {
  917. if (netif_msg_intr(priv))
  918. pr_err("%s: Can't get IRQ %d (receive0)\n",
  919. ndev->name, priv->interruptReceive);
  920. goto rx_irq_fail;
  921. }
  922. } else {
  923. err = request_irq(priv->interruptTransmit, gfar_interrupt,
  924. 0, priv->int_name_tx, ndev);
  925. if (err) {
  926. if (netif_msg_intr(priv))
  927. pr_err("%s: Can't get IRQ %d\n", ndev->name,
  928. priv->interruptTransmit);
  929. goto err_irq_fail;
  930. }
  931. }
  932. /* Start the controller */
  933. gfar_start(ndev);
  934. phy_start(priv->phydev);
  935. return 0;
  936. rx_irq_fail:
  937. free_irq(priv->interruptTransmit, ndev);
  938. tx_irq_fail:
  939. free_irq(priv->interruptError, ndev);
  940. err_irq_fail:
  941. free_skb_resources(priv);
  942. return err;
  943. }
  944. /* Called when something needs to use the ethernet device */
  945. /* Returns 0 for success. */
  946. static int gfar_enet_open(struct net_device *dev)
  947. {
  948. struct gfar_private *priv = netdev_priv(dev);
  949. int err;
  950. napi_enable(&priv->napi);
  951. skb_queue_head_init(&priv->rx_recycle);
  952. /* Initialize a bunch of registers */
  953. init_registers(dev);
  954. gfar_set_mac_address(dev);
  955. err = init_phy(dev);
  956. if(err) {
  957. napi_disable(&priv->napi);
  958. return err;
  959. }
  960. err = startup_gfar(dev);
  961. if (err) {
  962. napi_disable(&priv->napi);
  963. return err;
  964. }
  965. netif_start_queue(dev);
  966. device_set_wakeup_enable(&dev->dev, priv->wol_en);
  967. return err;
  968. }
  969. static inline struct txfcb *gfar_add_fcb(struct sk_buff *skb)
  970. {
  971. struct txfcb *fcb = (struct txfcb *)skb_push(skb, GMAC_FCB_LEN);
  972. memset(fcb, 0, GMAC_FCB_LEN);
  973. return fcb;
  974. }
  975. static inline void gfar_tx_checksum(struct sk_buff *skb, struct txfcb *fcb)
  976. {
  977. u8 flags = 0;
  978. /* If we're here, it's a IP packet with a TCP or UDP
  979. * payload. We set it to checksum, using a pseudo-header
  980. * we provide
  981. */
  982. flags = TXFCB_DEFAULT;
  983. /* Tell the controller what the protocol is */
  984. /* And provide the already calculated phcs */
  985. if (ip_hdr(skb)->protocol == IPPROTO_UDP) {
  986. flags |= TXFCB_UDP;
  987. fcb->phcs = udp_hdr(skb)->check;
  988. } else
  989. fcb->phcs = tcp_hdr(skb)->check;
  990. /* l3os is the distance between the start of the
  991. * frame (skb->data) and the start of the IP hdr.
  992. * l4os is the distance between the start of the
  993. * l3 hdr and the l4 hdr */
  994. fcb->l3os = (u16)(skb_network_offset(skb) - GMAC_FCB_LEN);
  995. fcb->l4os = skb_network_header_len(skb);
  996. fcb->flags = flags;
  997. }
  998. void inline gfar_tx_vlan(struct sk_buff *skb, struct txfcb *fcb)
  999. {
  1000. fcb->flags |= TXFCB_VLN;
  1001. fcb->vlctl = vlan_tx_tag_get(skb);
  1002. }
  1003. static inline struct txbd8 *skip_txbd(struct txbd8 *bdp, int stride,
  1004. struct txbd8 *base, int ring_size)
  1005. {
  1006. struct txbd8 *new_bd = bdp + stride;
  1007. return (new_bd >= (base + ring_size)) ? (new_bd - ring_size) : new_bd;
  1008. }
  1009. static inline struct txbd8 *next_txbd(struct txbd8 *bdp, struct txbd8 *base,
  1010. int ring_size)
  1011. {
  1012. return skip_txbd(bdp, 1, base, ring_size);
  1013. }
  1014. /* This is called by the kernel when a frame is ready for transmission. */
  1015. /* It is pointed to by the dev->hard_start_xmit function pointer */
  1016. static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1017. {
  1018. struct gfar_private *priv = netdev_priv(dev);
  1019. struct txfcb *fcb = NULL;
  1020. struct txbd8 *txbdp, *txbdp_start, *base;
  1021. u32 lstatus;
  1022. int i;
  1023. u32 bufaddr;
  1024. unsigned long flags;
  1025. unsigned int nr_frags, length;
  1026. base = priv->tx_bd_base;
  1027. /* make space for additional header when fcb is needed */
  1028. if (((skb->ip_summed == CHECKSUM_PARTIAL) ||
  1029. (priv->vlgrp && vlan_tx_tag_present(skb))) &&
  1030. (skb_headroom(skb) < GMAC_FCB_LEN)) {
  1031. struct sk_buff *skb_new;
  1032. skb_new = skb_realloc_headroom(skb, GMAC_FCB_LEN);
  1033. if (!skb_new) {
  1034. dev->stats.tx_errors++;
  1035. kfree_skb(skb);
  1036. return NETDEV_TX_OK;
  1037. }
  1038. kfree_skb(skb);
  1039. skb = skb_new;
  1040. }
  1041. /* total number of fragments in the SKB */
  1042. nr_frags = skb_shinfo(skb)->nr_frags;
  1043. spin_lock_irqsave(&priv->txlock, flags);
  1044. /* check if there is space to queue this packet */
  1045. if ((nr_frags+1) > priv->num_txbdfree) {
  1046. /* no space, stop the queue */
  1047. netif_stop_queue(dev);
  1048. dev->stats.tx_fifo_errors++;
  1049. spin_unlock_irqrestore(&priv->txlock, flags);
  1050. return NETDEV_TX_BUSY;
  1051. }
  1052. /* Update transmit stats */
  1053. dev->stats.tx_bytes += skb->len;
  1054. txbdp = txbdp_start = priv->cur_tx;
  1055. if (nr_frags == 0) {
  1056. lstatus = txbdp->lstatus | BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1057. } else {
  1058. /* Place the fragment addresses and lengths into the TxBDs */
  1059. for (i = 0; i < nr_frags; i++) {
  1060. /* Point at the next BD, wrapping as needed */
  1061. txbdp = next_txbd(txbdp, base, priv->tx_ring_size);
  1062. length = skb_shinfo(skb)->frags[i].size;
  1063. lstatus = txbdp->lstatus | length |
  1064. BD_LFLAG(TXBD_READY);
  1065. /* Handle the last BD specially */
  1066. if (i == nr_frags - 1)
  1067. lstatus |= BD_LFLAG(TXBD_LAST | TXBD_INTERRUPT);
  1068. bufaddr = dma_map_page(&priv->ofdev->dev,
  1069. skb_shinfo(skb)->frags[i].page,
  1070. skb_shinfo(skb)->frags[i].page_offset,
  1071. length,
  1072. DMA_TO_DEVICE);
  1073. /* set the TxBD length and buffer pointer */
  1074. txbdp->bufPtr = bufaddr;
  1075. txbdp->lstatus = lstatus;
  1076. }
  1077. lstatus = txbdp_start->lstatus;
  1078. }
  1079. /* Set up checksumming */
  1080. if (CHECKSUM_PARTIAL == skb->ip_summed) {
  1081. fcb = gfar_add_fcb(skb);
  1082. lstatus |= BD_LFLAG(TXBD_TOE);
  1083. gfar_tx_checksum(skb, fcb);
  1084. }
  1085. if (priv->vlgrp && vlan_tx_tag_present(skb)) {
  1086. if (unlikely(NULL == fcb)) {
  1087. fcb = gfar_add_fcb(skb);
  1088. lstatus |= BD_LFLAG(TXBD_TOE);
  1089. }
  1090. gfar_tx_vlan(skb, fcb);
  1091. }
  1092. /* setup the TxBD length and buffer pointer for the first BD */
  1093. priv->tx_skbuff[priv->skb_curtx] = skb;
  1094. txbdp_start->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
  1095. skb_headlen(skb), DMA_TO_DEVICE);
  1096. lstatus |= BD_LFLAG(TXBD_CRC | TXBD_READY) | skb_headlen(skb);
  1097. /*
  1098. * The powerpc-specific eieio() is used, as wmb() has too strong
  1099. * semantics (it requires synchronization between cacheable and
  1100. * uncacheable mappings, which eieio doesn't provide and which we
  1101. * don't need), thus requiring a more expensive sync instruction. At
  1102. * some point, the set of architecture-independent barrier functions
  1103. * should be expanded to include weaker barriers.
  1104. */
  1105. eieio();
  1106. txbdp_start->lstatus = lstatus;
  1107. /* Update the current skb pointer to the next entry we will use
  1108. * (wrapping if necessary) */
  1109. priv->skb_curtx = (priv->skb_curtx + 1) &
  1110. TX_RING_MOD_MASK(priv->tx_ring_size);
  1111. priv->cur_tx = next_txbd(txbdp, base, priv->tx_ring_size);
  1112. /* reduce TxBD free count */
  1113. priv->num_txbdfree -= (nr_frags + 1);
  1114. dev->trans_start = jiffies;
  1115. /* If the next BD still needs to be cleaned up, then the bds
  1116. are full. We need to tell the kernel to stop sending us stuff. */
  1117. if (!priv->num_txbdfree) {
  1118. netif_stop_queue(dev);
  1119. dev->stats.tx_fifo_errors++;
  1120. }
  1121. /* Tell the DMA to go go go */
  1122. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1123. /* Unlock priv */
  1124. spin_unlock_irqrestore(&priv->txlock, flags);
  1125. return NETDEV_TX_OK;
  1126. }
  1127. /* Stops the kernel queue, and halts the controller */
  1128. static int gfar_close(struct net_device *dev)
  1129. {
  1130. struct gfar_private *priv = netdev_priv(dev);
  1131. napi_disable(&priv->napi);
  1132. skb_queue_purge(&priv->rx_recycle);
  1133. cancel_work_sync(&priv->reset_task);
  1134. stop_gfar(dev);
  1135. /* Disconnect from the PHY */
  1136. phy_disconnect(priv->phydev);
  1137. priv->phydev = NULL;
  1138. netif_stop_queue(dev);
  1139. return 0;
  1140. }
  1141. /* Changes the mac address if the controller is not running. */
  1142. static int gfar_set_mac_address(struct net_device *dev)
  1143. {
  1144. gfar_set_mac_for_addr(dev, 0, dev->dev_addr);
  1145. return 0;
  1146. }
  1147. /* Enables and disables VLAN insertion/extraction */
  1148. static void gfar_vlan_rx_register(struct net_device *dev,
  1149. struct vlan_group *grp)
  1150. {
  1151. struct gfar_private *priv = netdev_priv(dev);
  1152. unsigned long flags;
  1153. u32 tempval;
  1154. spin_lock_irqsave(&priv->rxlock, flags);
  1155. priv->vlgrp = grp;
  1156. if (grp) {
  1157. /* Enable VLAN tag insertion */
  1158. tempval = gfar_read(&priv->regs->tctrl);
  1159. tempval |= TCTRL_VLINS;
  1160. gfar_write(&priv->regs->tctrl, tempval);
  1161. /* Enable VLAN tag extraction */
  1162. tempval = gfar_read(&priv->regs->rctrl);
  1163. tempval |= (RCTRL_VLEX | RCTRL_PRSDEP_INIT);
  1164. gfar_write(&priv->regs->rctrl, tempval);
  1165. } else {
  1166. /* Disable VLAN tag insertion */
  1167. tempval = gfar_read(&priv->regs->tctrl);
  1168. tempval &= ~TCTRL_VLINS;
  1169. gfar_write(&priv->regs->tctrl, tempval);
  1170. /* Disable VLAN tag extraction */
  1171. tempval = gfar_read(&priv->regs->rctrl);
  1172. tempval &= ~RCTRL_VLEX;
  1173. /* If parse is no longer required, then disable parser */
  1174. if (tempval & RCTRL_REQ_PARSER)
  1175. tempval |= RCTRL_PRSDEP_INIT;
  1176. else
  1177. tempval &= ~RCTRL_PRSDEP_INIT;
  1178. gfar_write(&priv->regs->rctrl, tempval);
  1179. }
  1180. gfar_change_mtu(dev, dev->mtu);
  1181. spin_unlock_irqrestore(&priv->rxlock, flags);
  1182. }
  1183. static int gfar_change_mtu(struct net_device *dev, int new_mtu)
  1184. {
  1185. int tempsize, tempval;
  1186. struct gfar_private *priv = netdev_priv(dev);
  1187. int oldsize = priv->rx_buffer_size;
  1188. int frame_size = new_mtu + ETH_HLEN;
  1189. if (priv->vlgrp)
  1190. frame_size += VLAN_HLEN;
  1191. if ((frame_size < 64) || (frame_size > JUMBO_FRAME_SIZE)) {
  1192. if (netif_msg_drv(priv))
  1193. printk(KERN_ERR "%s: Invalid MTU setting\n",
  1194. dev->name);
  1195. return -EINVAL;
  1196. }
  1197. if (gfar_uses_fcb(priv))
  1198. frame_size += GMAC_FCB_LEN;
  1199. frame_size += priv->padding;
  1200. tempsize =
  1201. (frame_size & ~(INCREMENTAL_BUFFER_SIZE - 1)) +
  1202. INCREMENTAL_BUFFER_SIZE;
  1203. /* Only stop and start the controller if it isn't already
  1204. * stopped, and we changed something */
  1205. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1206. stop_gfar(dev);
  1207. priv->rx_buffer_size = tempsize;
  1208. dev->mtu = new_mtu;
  1209. gfar_write(&priv->regs->mrblr, priv->rx_buffer_size);
  1210. gfar_write(&priv->regs->maxfrm, priv->rx_buffer_size);
  1211. /* If the mtu is larger than the max size for standard
  1212. * ethernet frames (ie, a jumbo frame), then set maccfg2
  1213. * to allow huge frames, and to check the length */
  1214. tempval = gfar_read(&priv->regs->maccfg2);
  1215. if (priv->rx_buffer_size > DEFAULT_RX_BUFFER_SIZE)
  1216. tempval |= (MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  1217. else
  1218. tempval &= ~(MACCFG2_HUGEFRAME | MACCFG2_LENGTHCHECK);
  1219. gfar_write(&priv->regs->maccfg2, tempval);
  1220. if ((oldsize != tempsize) && (dev->flags & IFF_UP))
  1221. startup_gfar(dev);
  1222. return 0;
  1223. }
  1224. /* gfar_reset_task gets scheduled when a packet has not been
  1225. * transmitted after a set amount of time.
  1226. * For now, assume that clearing out all the structures, and
  1227. * starting over will fix the problem.
  1228. */
  1229. static void gfar_reset_task(struct work_struct *work)
  1230. {
  1231. struct gfar_private *priv = container_of(work, struct gfar_private,
  1232. reset_task);
  1233. struct net_device *dev = priv->ndev;
  1234. if (dev->flags & IFF_UP) {
  1235. netif_stop_queue(dev);
  1236. stop_gfar(dev);
  1237. startup_gfar(dev);
  1238. netif_start_queue(dev);
  1239. }
  1240. netif_tx_schedule_all(dev);
  1241. }
  1242. static void gfar_timeout(struct net_device *dev)
  1243. {
  1244. struct gfar_private *priv = netdev_priv(dev);
  1245. dev->stats.tx_errors++;
  1246. schedule_work(&priv->reset_task);
  1247. }
  1248. /* Interrupt Handler for Transmit complete */
  1249. static int gfar_clean_tx_ring(struct net_device *dev)
  1250. {
  1251. struct gfar_private *priv = netdev_priv(dev);
  1252. struct txbd8 *bdp;
  1253. struct txbd8 *lbdp = NULL;
  1254. struct txbd8 *base = priv->tx_bd_base;
  1255. struct sk_buff *skb;
  1256. int skb_dirtytx;
  1257. int tx_ring_size = priv->tx_ring_size;
  1258. int frags = 0;
  1259. int i;
  1260. int howmany = 0;
  1261. u32 lstatus;
  1262. bdp = priv->dirty_tx;
  1263. skb_dirtytx = priv->skb_dirtytx;
  1264. while ((skb = priv->tx_skbuff[skb_dirtytx])) {
  1265. frags = skb_shinfo(skb)->nr_frags;
  1266. lbdp = skip_txbd(bdp, frags, base, tx_ring_size);
  1267. lstatus = lbdp->lstatus;
  1268. /* Only clean completed frames */
  1269. if ((lstatus & BD_LFLAG(TXBD_READY)) &&
  1270. (lstatus & BD_LENGTH_MASK))
  1271. break;
  1272. dma_unmap_single(&priv->ofdev->dev,
  1273. bdp->bufPtr,
  1274. bdp->length,
  1275. DMA_TO_DEVICE);
  1276. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  1277. bdp = next_txbd(bdp, base, tx_ring_size);
  1278. for (i = 0; i < frags; i++) {
  1279. dma_unmap_page(&priv->ofdev->dev,
  1280. bdp->bufPtr,
  1281. bdp->length,
  1282. DMA_TO_DEVICE);
  1283. bdp->lstatus &= BD_LFLAG(TXBD_WRAP);
  1284. bdp = next_txbd(bdp, base, tx_ring_size);
  1285. }
  1286. /*
  1287. * If there's room in the queue (limit it to rx_buffer_size)
  1288. * we add this skb back into the pool, if it's the right size
  1289. */
  1290. if (skb_queue_len(&priv->rx_recycle) < priv->rx_ring_size &&
  1291. skb_recycle_check(skb, priv->rx_buffer_size +
  1292. RXBUF_ALIGNMENT))
  1293. __skb_queue_head(&priv->rx_recycle, skb);
  1294. else
  1295. dev_kfree_skb_any(skb);
  1296. priv->tx_skbuff[skb_dirtytx] = NULL;
  1297. skb_dirtytx = (skb_dirtytx + 1) &
  1298. TX_RING_MOD_MASK(tx_ring_size);
  1299. howmany++;
  1300. priv->num_txbdfree += frags + 1;
  1301. }
  1302. /* If we freed a buffer, we can restart transmission, if necessary */
  1303. if (netif_queue_stopped(dev) && priv->num_txbdfree)
  1304. netif_wake_queue(dev);
  1305. /* Update dirty indicators */
  1306. priv->skb_dirtytx = skb_dirtytx;
  1307. priv->dirty_tx = bdp;
  1308. dev->stats.tx_packets += howmany;
  1309. return howmany;
  1310. }
  1311. static void gfar_schedule_cleanup(struct net_device *dev)
  1312. {
  1313. struct gfar_private *priv = netdev_priv(dev);
  1314. unsigned long flags;
  1315. spin_lock_irqsave(&priv->txlock, flags);
  1316. spin_lock(&priv->rxlock);
  1317. if (napi_schedule_prep(&priv->napi)) {
  1318. gfar_write(&priv->regs->imask, IMASK_RTX_DISABLED);
  1319. __napi_schedule(&priv->napi);
  1320. } else {
  1321. /*
  1322. * Clear IEVENT, so interrupts aren't called again
  1323. * because of the packets that have already arrived.
  1324. */
  1325. gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
  1326. }
  1327. spin_unlock(&priv->rxlock);
  1328. spin_unlock_irqrestore(&priv->txlock, flags);
  1329. }
  1330. /* Interrupt Handler for Transmit complete */
  1331. static irqreturn_t gfar_transmit(int irq, void *dev_id)
  1332. {
  1333. gfar_schedule_cleanup((struct net_device *)dev_id);
  1334. return IRQ_HANDLED;
  1335. }
  1336. static void gfar_new_rxbdp(struct net_device *dev, struct rxbd8 *bdp,
  1337. struct sk_buff *skb)
  1338. {
  1339. struct gfar_private *priv = netdev_priv(dev);
  1340. u32 lstatus;
  1341. bdp->bufPtr = dma_map_single(&priv->ofdev->dev, skb->data,
  1342. priv->rx_buffer_size, DMA_FROM_DEVICE);
  1343. lstatus = BD_LFLAG(RXBD_EMPTY | RXBD_INTERRUPT);
  1344. if (bdp == priv->rx_bd_base + priv->rx_ring_size - 1)
  1345. lstatus |= BD_LFLAG(RXBD_WRAP);
  1346. eieio();
  1347. bdp->lstatus = lstatus;
  1348. }
  1349. struct sk_buff * gfar_new_skb(struct net_device *dev)
  1350. {
  1351. unsigned int alignamount;
  1352. struct gfar_private *priv = netdev_priv(dev);
  1353. struct sk_buff *skb = NULL;
  1354. skb = __skb_dequeue(&priv->rx_recycle);
  1355. if (!skb)
  1356. skb = netdev_alloc_skb(dev,
  1357. priv->rx_buffer_size + RXBUF_ALIGNMENT);
  1358. if (!skb)
  1359. return NULL;
  1360. alignamount = RXBUF_ALIGNMENT -
  1361. (((unsigned long) skb->data) & (RXBUF_ALIGNMENT - 1));
  1362. /* We need the data buffer to be aligned properly. We will reserve
  1363. * as many bytes as needed to align the data properly
  1364. */
  1365. skb_reserve(skb, alignamount);
  1366. return skb;
  1367. }
  1368. static inline void count_errors(unsigned short status, struct net_device *dev)
  1369. {
  1370. struct gfar_private *priv = netdev_priv(dev);
  1371. struct net_device_stats *stats = &dev->stats;
  1372. struct gfar_extra_stats *estats = &priv->extra_stats;
  1373. /* If the packet was truncated, none of the other errors
  1374. * matter */
  1375. if (status & RXBD_TRUNCATED) {
  1376. stats->rx_length_errors++;
  1377. estats->rx_trunc++;
  1378. return;
  1379. }
  1380. /* Count the errors, if there were any */
  1381. if (status & (RXBD_LARGE | RXBD_SHORT)) {
  1382. stats->rx_length_errors++;
  1383. if (status & RXBD_LARGE)
  1384. estats->rx_large++;
  1385. else
  1386. estats->rx_short++;
  1387. }
  1388. if (status & RXBD_NONOCTET) {
  1389. stats->rx_frame_errors++;
  1390. estats->rx_nonoctet++;
  1391. }
  1392. if (status & RXBD_CRCERR) {
  1393. estats->rx_crcerr++;
  1394. stats->rx_crc_errors++;
  1395. }
  1396. if (status & RXBD_OVERRUN) {
  1397. estats->rx_overrun++;
  1398. stats->rx_crc_errors++;
  1399. }
  1400. }
  1401. irqreturn_t gfar_receive(int irq, void *dev_id)
  1402. {
  1403. gfar_schedule_cleanup((struct net_device *)dev_id);
  1404. return IRQ_HANDLED;
  1405. }
  1406. static inline void gfar_rx_checksum(struct sk_buff *skb, struct rxfcb *fcb)
  1407. {
  1408. /* If valid headers were found, and valid sums
  1409. * were verified, then we tell the kernel that no
  1410. * checksumming is necessary. Otherwise, it is */
  1411. if ((fcb->flags & RXFCB_CSUM_MASK) == (RXFCB_CIP | RXFCB_CTU))
  1412. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1413. else
  1414. skb->ip_summed = CHECKSUM_NONE;
  1415. }
  1416. /* gfar_process_frame() -- handle one incoming packet if skb
  1417. * isn't NULL. */
  1418. static int gfar_process_frame(struct net_device *dev, struct sk_buff *skb,
  1419. int amount_pull)
  1420. {
  1421. struct gfar_private *priv = netdev_priv(dev);
  1422. struct rxfcb *fcb = NULL;
  1423. int ret;
  1424. /* fcb is at the beginning if exists */
  1425. fcb = (struct rxfcb *)skb->data;
  1426. /* Remove the FCB from the skb */
  1427. /* Remove the padded bytes, if there are any */
  1428. if (amount_pull)
  1429. skb_pull(skb, amount_pull);
  1430. if (priv->rx_csum_enable)
  1431. gfar_rx_checksum(skb, fcb);
  1432. /* Tell the skb what kind of packet this is */
  1433. skb->protocol = eth_type_trans(skb, dev);
  1434. /* Send the packet up the stack */
  1435. if (unlikely(priv->vlgrp && (fcb->flags & RXFCB_VLN)))
  1436. ret = vlan_hwaccel_receive_skb(skb, priv->vlgrp, fcb->vlctl);
  1437. else
  1438. ret = netif_receive_skb(skb);
  1439. if (NET_RX_DROP == ret)
  1440. priv->extra_stats.kernel_dropped++;
  1441. return 0;
  1442. }
  1443. /* gfar_clean_rx_ring() -- Processes each frame in the rx ring
  1444. * until the budget/quota has been reached. Returns the number
  1445. * of frames handled
  1446. */
  1447. int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
  1448. {
  1449. struct rxbd8 *bdp, *base;
  1450. struct sk_buff *skb;
  1451. int pkt_len;
  1452. int amount_pull;
  1453. int howmany = 0;
  1454. struct gfar_private *priv = netdev_priv(dev);
  1455. /* Get the first full descriptor */
  1456. bdp = priv->cur_rx;
  1457. base = priv->rx_bd_base;
  1458. amount_pull = (gfar_uses_fcb(priv) ? GMAC_FCB_LEN : 0) +
  1459. priv->padding;
  1460. while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
  1461. struct sk_buff *newskb;
  1462. rmb();
  1463. /* Add another skb for the future */
  1464. newskb = gfar_new_skb(dev);
  1465. skb = priv->rx_skbuff[priv->skb_currx];
  1466. dma_unmap_single(&priv->ofdev->dev, bdp->bufPtr,
  1467. priv->rx_buffer_size, DMA_FROM_DEVICE);
  1468. /* We drop the frame if we failed to allocate a new buffer */
  1469. if (unlikely(!newskb || !(bdp->status & RXBD_LAST) ||
  1470. bdp->status & RXBD_ERR)) {
  1471. count_errors(bdp->status, dev);
  1472. if (unlikely(!newskb))
  1473. newskb = skb;
  1474. else if (skb) {
  1475. /*
  1476. * We need to reset ->data to what it
  1477. * was before gfar_new_skb() re-aligned
  1478. * it to an RXBUF_ALIGNMENT boundary
  1479. * before we put the skb back on the
  1480. * recycle list.
  1481. */
  1482. skb->data = skb->head + NET_SKB_PAD;
  1483. __skb_queue_head(&priv->rx_recycle, skb);
  1484. }
  1485. } else {
  1486. /* Increment the number of packets */
  1487. dev->stats.rx_packets++;
  1488. howmany++;
  1489. if (likely(skb)) {
  1490. pkt_len = bdp->length - ETH_FCS_LEN;
  1491. /* Remove the FCS from the packet length */
  1492. skb_put(skb, pkt_len);
  1493. dev->stats.rx_bytes += pkt_len;
  1494. if (in_irq() || irqs_disabled())
  1495. printk("Interrupt problem!\n");
  1496. gfar_process_frame(dev, skb, amount_pull);
  1497. } else {
  1498. if (netif_msg_rx_err(priv))
  1499. printk(KERN_WARNING
  1500. "%s: Missing skb!\n", dev->name);
  1501. dev->stats.rx_dropped++;
  1502. priv->extra_stats.rx_skbmissing++;
  1503. }
  1504. }
  1505. priv->rx_skbuff[priv->skb_currx] = newskb;
  1506. /* Setup the new bdp */
  1507. gfar_new_rxbdp(dev, bdp, newskb);
  1508. /* Update to the next pointer */
  1509. bdp = next_bd(bdp, base, priv->rx_ring_size);
  1510. /* update to point at the next skb */
  1511. priv->skb_currx =
  1512. (priv->skb_currx + 1) &
  1513. RX_RING_MOD_MASK(priv->rx_ring_size);
  1514. }
  1515. /* Update the current rxbd pointer to be the next one */
  1516. priv->cur_rx = bdp;
  1517. return howmany;
  1518. }
  1519. static int gfar_poll(struct napi_struct *napi, int budget)
  1520. {
  1521. struct gfar_private *priv = container_of(napi, struct gfar_private, napi);
  1522. struct net_device *dev = priv->ndev;
  1523. int tx_cleaned = 0;
  1524. int rx_cleaned = 0;
  1525. unsigned long flags;
  1526. /* Clear IEVENT, so interrupts aren't called again
  1527. * because of the packets that have already arrived */
  1528. gfar_write(&priv->regs->ievent, IEVENT_RTX_MASK);
  1529. /* If we fail to get the lock, don't bother with the TX BDs */
  1530. if (spin_trylock_irqsave(&priv->txlock, flags)) {
  1531. tx_cleaned = gfar_clean_tx_ring(dev);
  1532. spin_unlock_irqrestore(&priv->txlock, flags);
  1533. }
  1534. rx_cleaned = gfar_clean_rx_ring(dev, budget);
  1535. if (tx_cleaned)
  1536. return budget;
  1537. if (rx_cleaned < budget) {
  1538. napi_complete(napi);
  1539. /* Clear the halt bit in RSTAT */
  1540. gfar_write(&priv->regs->rstat, RSTAT_CLEAR_RHALT);
  1541. gfar_write(&priv->regs->imask, IMASK_DEFAULT);
  1542. /* If we are coalescing interrupts, update the timer */
  1543. /* Otherwise, clear it */
  1544. if (likely(priv->rxcoalescing)) {
  1545. gfar_write(&priv->regs->rxic, 0);
  1546. gfar_write(&priv->regs->rxic, priv->rxic);
  1547. }
  1548. if (likely(priv->txcoalescing)) {
  1549. gfar_write(&priv->regs->txic, 0);
  1550. gfar_write(&priv->regs->txic, priv->txic);
  1551. }
  1552. }
  1553. return rx_cleaned;
  1554. }
  1555. #ifdef CONFIG_NET_POLL_CONTROLLER
  1556. /*
  1557. * Polling 'interrupt' - used by things like netconsole to send skbs
  1558. * without having to re-enable interrupts. It's not called while
  1559. * the interrupt routine is executing.
  1560. */
  1561. static void gfar_netpoll(struct net_device *dev)
  1562. {
  1563. struct gfar_private *priv = netdev_priv(dev);
  1564. /* If the device has multiple interrupts, run tx/rx */
  1565. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MULTI_INTR) {
  1566. disable_irq(priv->interruptTransmit);
  1567. disable_irq(priv->interruptReceive);
  1568. disable_irq(priv->interruptError);
  1569. gfar_interrupt(priv->interruptTransmit, dev);
  1570. enable_irq(priv->interruptError);
  1571. enable_irq(priv->interruptReceive);
  1572. enable_irq(priv->interruptTransmit);
  1573. } else {
  1574. disable_irq(priv->interruptTransmit);
  1575. gfar_interrupt(priv->interruptTransmit, dev);
  1576. enable_irq(priv->interruptTransmit);
  1577. }
  1578. }
  1579. #endif
  1580. /* The interrupt handler for devices with one interrupt */
  1581. static irqreturn_t gfar_interrupt(int irq, void *dev_id)
  1582. {
  1583. struct net_device *dev = dev_id;
  1584. struct gfar_private *priv = netdev_priv(dev);
  1585. /* Save ievent for future reference */
  1586. u32 events = gfar_read(&priv->regs->ievent);
  1587. /* Check for reception */
  1588. if (events & IEVENT_RX_MASK)
  1589. gfar_receive(irq, dev_id);
  1590. /* Check for transmit completion */
  1591. if (events & IEVENT_TX_MASK)
  1592. gfar_transmit(irq, dev_id);
  1593. /* Check for errors */
  1594. if (events & IEVENT_ERR_MASK)
  1595. gfar_error(irq, dev_id);
  1596. return IRQ_HANDLED;
  1597. }
  1598. /* Called every time the controller might need to be made
  1599. * aware of new link state. The PHY code conveys this
  1600. * information through variables in the phydev structure, and this
  1601. * function converts those variables into the appropriate
  1602. * register values, and can bring down the device if needed.
  1603. */
  1604. static void adjust_link(struct net_device *dev)
  1605. {
  1606. struct gfar_private *priv = netdev_priv(dev);
  1607. struct gfar __iomem *regs = priv->regs;
  1608. unsigned long flags;
  1609. struct phy_device *phydev = priv->phydev;
  1610. int new_state = 0;
  1611. spin_lock_irqsave(&priv->txlock, flags);
  1612. if (phydev->link) {
  1613. u32 tempval = gfar_read(&regs->maccfg2);
  1614. u32 ecntrl = gfar_read(&regs->ecntrl);
  1615. /* Now we make sure that we can be in full duplex mode.
  1616. * If not, we operate in half-duplex mode. */
  1617. if (phydev->duplex != priv->oldduplex) {
  1618. new_state = 1;
  1619. if (!(phydev->duplex))
  1620. tempval &= ~(MACCFG2_FULL_DUPLEX);
  1621. else
  1622. tempval |= MACCFG2_FULL_DUPLEX;
  1623. priv->oldduplex = phydev->duplex;
  1624. }
  1625. if (phydev->speed != priv->oldspeed) {
  1626. new_state = 1;
  1627. switch (phydev->speed) {
  1628. case 1000:
  1629. tempval =
  1630. ((tempval & ~(MACCFG2_IF)) | MACCFG2_GMII);
  1631. ecntrl &= ~(ECNTRL_R100);
  1632. break;
  1633. case 100:
  1634. case 10:
  1635. tempval =
  1636. ((tempval & ~(MACCFG2_IF)) | MACCFG2_MII);
  1637. /* Reduced mode distinguishes
  1638. * between 10 and 100 */
  1639. if (phydev->speed == SPEED_100)
  1640. ecntrl |= ECNTRL_R100;
  1641. else
  1642. ecntrl &= ~(ECNTRL_R100);
  1643. break;
  1644. default:
  1645. if (netif_msg_link(priv))
  1646. printk(KERN_WARNING
  1647. "%s: Ack! Speed (%d) is not 10/100/1000!\n",
  1648. dev->name, phydev->speed);
  1649. break;
  1650. }
  1651. priv->oldspeed = phydev->speed;
  1652. }
  1653. gfar_write(&regs->maccfg2, tempval);
  1654. gfar_write(&regs->ecntrl, ecntrl);
  1655. if (!priv->oldlink) {
  1656. new_state = 1;
  1657. priv->oldlink = 1;
  1658. }
  1659. } else if (priv->oldlink) {
  1660. new_state = 1;
  1661. priv->oldlink = 0;
  1662. priv->oldspeed = 0;
  1663. priv->oldduplex = -1;
  1664. }
  1665. if (new_state && netif_msg_link(priv))
  1666. phy_print_status(phydev);
  1667. spin_unlock_irqrestore(&priv->txlock, flags);
  1668. }
  1669. /* Update the hash table based on the current list of multicast
  1670. * addresses we subscribe to. Also, change the promiscuity of
  1671. * the device based on the flags (this function is called
  1672. * whenever dev->flags is changed */
  1673. static void gfar_set_multi(struct net_device *dev)
  1674. {
  1675. struct dev_mc_list *mc_ptr;
  1676. struct gfar_private *priv = netdev_priv(dev);
  1677. struct gfar __iomem *regs = priv->regs;
  1678. u32 tempval;
  1679. if(dev->flags & IFF_PROMISC) {
  1680. /* Set RCTRL to PROM */
  1681. tempval = gfar_read(&regs->rctrl);
  1682. tempval |= RCTRL_PROM;
  1683. gfar_write(&regs->rctrl, tempval);
  1684. } else {
  1685. /* Set RCTRL to not PROM */
  1686. tempval = gfar_read(&regs->rctrl);
  1687. tempval &= ~(RCTRL_PROM);
  1688. gfar_write(&regs->rctrl, tempval);
  1689. }
  1690. if(dev->flags & IFF_ALLMULTI) {
  1691. /* Set the hash to rx all multicast frames */
  1692. gfar_write(&regs->igaddr0, 0xffffffff);
  1693. gfar_write(&regs->igaddr1, 0xffffffff);
  1694. gfar_write(&regs->igaddr2, 0xffffffff);
  1695. gfar_write(&regs->igaddr3, 0xffffffff);
  1696. gfar_write(&regs->igaddr4, 0xffffffff);
  1697. gfar_write(&regs->igaddr5, 0xffffffff);
  1698. gfar_write(&regs->igaddr6, 0xffffffff);
  1699. gfar_write(&regs->igaddr7, 0xffffffff);
  1700. gfar_write(&regs->gaddr0, 0xffffffff);
  1701. gfar_write(&regs->gaddr1, 0xffffffff);
  1702. gfar_write(&regs->gaddr2, 0xffffffff);
  1703. gfar_write(&regs->gaddr3, 0xffffffff);
  1704. gfar_write(&regs->gaddr4, 0xffffffff);
  1705. gfar_write(&regs->gaddr5, 0xffffffff);
  1706. gfar_write(&regs->gaddr6, 0xffffffff);
  1707. gfar_write(&regs->gaddr7, 0xffffffff);
  1708. } else {
  1709. int em_num;
  1710. int idx;
  1711. /* zero out the hash */
  1712. gfar_write(&regs->igaddr0, 0x0);
  1713. gfar_write(&regs->igaddr1, 0x0);
  1714. gfar_write(&regs->igaddr2, 0x0);
  1715. gfar_write(&regs->igaddr3, 0x0);
  1716. gfar_write(&regs->igaddr4, 0x0);
  1717. gfar_write(&regs->igaddr5, 0x0);
  1718. gfar_write(&regs->igaddr6, 0x0);
  1719. gfar_write(&regs->igaddr7, 0x0);
  1720. gfar_write(&regs->gaddr0, 0x0);
  1721. gfar_write(&regs->gaddr1, 0x0);
  1722. gfar_write(&regs->gaddr2, 0x0);
  1723. gfar_write(&regs->gaddr3, 0x0);
  1724. gfar_write(&regs->gaddr4, 0x0);
  1725. gfar_write(&regs->gaddr5, 0x0);
  1726. gfar_write(&regs->gaddr6, 0x0);
  1727. gfar_write(&regs->gaddr7, 0x0);
  1728. /* If we have extended hash tables, we need to
  1729. * clear the exact match registers to prepare for
  1730. * setting them */
  1731. if (priv->extended_hash) {
  1732. em_num = GFAR_EM_NUM + 1;
  1733. gfar_clear_exact_match(dev);
  1734. idx = 1;
  1735. } else {
  1736. idx = 0;
  1737. em_num = 0;
  1738. }
  1739. if(dev->mc_count == 0)
  1740. return;
  1741. /* Parse the list, and set the appropriate bits */
  1742. for(mc_ptr = dev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
  1743. if (idx < em_num) {
  1744. gfar_set_mac_for_addr(dev, idx,
  1745. mc_ptr->dmi_addr);
  1746. idx++;
  1747. } else
  1748. gfar_set_hash_for_addr(dev, mc_ptr->dmi_addr);
  1749. }
  1750. }
  1751. return;
  1752. }
  1753. /* Clears each of the exact match registers to zero, so they
  1754. * don't interfere with normal reception */
  1755. static void gfar_clear_exact_match(struct net_device *dev)
  1756. {
  1757. int idx;
  1758. u8 zero_arr[MAC_ADDR_LEN] = {0,0,0,0,0,0};
  1759. for(idx = 1;idx < GFAR_EM_NUM + 1;idx++)
  1760. gfar_set_mac_for_addr(dev, idx, (u8 *)zero_arr);
  1761. }
  1762. /* Set the appropriate hash bit for the given addr */
  1763. /* The algorithm works like so:
  1764. * 1) Take the Destination Address (ie the multicast address), and
  1765. * do a CRC on it (little endian), and reverse the bits of the
  1766. * result.
  1767. * 2) Use the 8 most significant bits as a hash into a 256-entry
  1768. * table. The table is controlled through 8 32-bit registers:
  1769. * gaddr0-7. gaddr0's MSB is entry 0, and gaddr7's LSB is
  1770. * gaddr7. This means that the 3 most significant bits in the
  1771. * hash index which gaddr register to use, and the 5 other bits
  1772. * indicate which bit (assuming an IBM numbering scheme, which
  1773. * for PowerPC (tm) is usually the case) in the register holds
  1774. * the entry. */
  1775. static void gfar_set_hash_for_addr(struct net_device *dev, u8 *addr)
  1776. {
  1777. u32 tempval;
  1778. struct gfar_private *priv = netdev_priv(dev);
  1779. u32 result = ether_crc(MAC_ADDR_LEN, addr);
  1780. int width = priv->hash_width;
  1781. u8 whichbit = (result >> (32 - width)) & 0x1f;
  1782. u8 whichreg = result >> (32 - width + 5);
  1783. u32 value = (1 << (31-whichbit));
  1784. tempval = gfar_read(priv->hash_regs[whichreg]);
  1785. tempval |= value;
  1786. gfar_write(priv->hash_regs[whichreg], tempval);
  1787. return;
  1788. }
  1789. /* There are multiple MAC Address register pairs on some controllers
  1790. * This function sets the numth pair to a given address
  1791. */
  1792. static void gfar_set_mac_for_addr(struct net_device *dev, int num, u8 *addr)
  1793. {
  1794. struct gfar_private *priv = netdev_priv(dev);
  1795. int idx;
  1796. char tmpbuf[MAC_ADDR_LEN];
  1797. u32 tempval;
  1798. u32 __iomem *macptr = &priv->regs->macstnaddr1;
  1799. macptr += num*2;
  1800. /* Now copy it into the mac registers backwards, cuz */
  1801. /* little endian is silly */
  1802. for (idx = 0; idx < MAC_ADDR_LEN; idx++)
  1803. tmpbuf[MAC_ADDR_LEN - 1 - idx] = addr[idx];
  1804. gfar_write(macptr, *((u32 *) (tmpbuf)));
  1805. tempval = *((u32 *) (tmpbuf + 4));
  1806. gfar_write(macptr+1, tempval);
  1807. }
  1808. /* GFAR error interrupt handler */
  1809. static irqreturn_t gfar_error(int irq, void *dev_id)
  1810. {
  1811. struct net_device *dev = dev_id;
  1812. struct gfar_private *priv = netdev_priv(dev);
  1813. /* Save ievent for future reference */
  1814. u32 events = gfar_read(&priv->regs->ievent);
  1815. /* Clear IEVENT */
  1816. gfar_write(&priv->regs->ievent, events & IEVENT_ERR_MASK);
  1817. /* Magic Packet is not an error. */
  1818. if ((priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  1819. (events & IEVENT_MAG))
  1820. events &= ~IEVENT_MAG;
  1821. /* Hmm... */
  1822. if (netif_msg_rx_err(priv) || netif_msg_tx_err(priv))
  1823. printk(KERN_DEBUG "%s: error interrupt (ievent=0x%08x imask=0x%08x)\n",
  1824. dev->name, events, gfar_read(&priv->regs->imask));
  1825. /* Update the error counters */
  1826. if (events & IEVENT_TXE) {
  1827. dev->stats.tx_errors++;
  1828. if (events & IEVENT_LC)
  1829. dev->stats.tx_window_errors++;
  1830. if (events & IEVENT_CRL)
  1831. dev->stats.tx_aborted_errors++;
  1832. if (events & IEVENT_XFUN) {
  1833. if (netif_msg_tx_err(priv))
  1834. printk(KERN_DEBUG "%s: TX FIFO underrun, "
  1835. "packet dropped.\n", dev->name);
  1836. dev->stats.tx_dropped++;
  1837. priv->extra_stats.tx_underrun++;
  1838. /* Reactivate the Tx Queues */
  1839. gfar_write(&priv->regs->tstat, TSTAT_CLEAR_THALT);
  1840. }
  1841. if (netif_msg_tx_err(priv))
  1842. printk(KERN_DEBUG "%s: Transmit Error\n", dev->name);
  1843. }
  1844. if (events & IEVENT_BSY) {
  1845. dev->stats.rx_errors++;
  1846. priv->extra_stats.rx_bsy++;
  1847. gfar_receive(irq, dev_id);
  1848. if (netif_msg_rx_err(priv))
  1849. printk(KERN_DEBUG "%s: busy error (rstat: %x)\n",
  1850. dev->name, gfar_read(&priv->regs->rstat));
  1851. }
  1852. if (events & IEVENT_BABR) {
  1853. dev->stats.rx_errors++;
  1854. priv->extra_stats.rx_babr++;
  1855. if (netif_msg_rx_err(priv))
  1856. printk(KERN_DEBUG "%s: babbling RX error\n", dev->name);
  1857. }
  1858. if (events & IEVENT_EBERR) {
  1859. priv->extra_stats.eberr++;
  1860. if (netif_msg_rx_err(priv))
  1861. printk(KERN_DEBUG "%s: bus error\n", dev->name);
  1862. }
  1863. if ((events & IEVENT_RXC) && netif_msg_rx_status(priv))
  1864. printk(KERN_DEBUG "%s: control frame\n", dev->name);
  1865. if (events & IEVENT_BABT) {
  1866. priv->extra_stats.tx_babt++;
  1867. if (netif_msg_tx_err(priv))
  1868. printk(KERN_DEBUG "%s: babbling TX error\n", dev->name);
  1869. }
  1870. return IRQ_HANDLED;
  1871. }
  1872. /* work with hotplug and coldplug */
  1873. MODULE_ALIAS("platform:fsl-gianfar");
  1874. static struct of_device_id gfar_match[] =
  1875. {
  1876. {
  1877. .type = "network",
  1878. .compatible = "gianfar",
  1879. },
  1880. {},
  1881. };
  1882. /* Structure for a device driver */
  1883. static struct of_platform_driver gfar_driver = {
  1884. .name = "fsl-gianfar",
  1885. .match_table = gfar_match,
  1886. .probe = gfar_probe,
  1887. .remove = gfar_remove,
  1888. .suspend = gfar_suspend,
  1889. .resume = gfar_resume,
  1890. };
  1891. static int __init gfar_init(void)
  1892. {
  1893. return of_register_platform_driver(&gfar_driver);
  1894. }
  1895. static void __exit gfar_exit(void)
  1896. {
  1897. of_unregister_platform_driver(&gfar_driver);
  1898. }
  1899. module_init(gfar_init);
  1900. module_exit(gfar_exit);