gianfar.c 62 KB

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