gianfar.c 62 KB

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