gianfar_ethtool.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819
  1. /*
  2. * drivers/net/ethernet/freescale/gianfar_ethtool.c
  3. *
  4. * Gianfar Ethernet Driver
  5. * Ethtool support for Gianfar Enet
  6. * Based on e1000 ethtool support
  7. *
  8. * Author: Andy Fleming
  9. * Maintainer: Kumar Gala
  10. * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
  11. *
  12. * Copyright 2003-2006, 2008-2009, 2011 Freescale Semiconductor, Inc.
  13. *
  14. * This software may be used and distributed according to
  15. * the terms of the GNU Public License, Version 2, incorporated herein
  16. * by reference.
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/kernel.h>
  20. #include <linux/string.h>
  21. #include <linux/errno.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/net_tstamp.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/mm.h>
  31. #include <asm/io.h>
  32. #include <asm/irq.h>
  33. #include <asm/uaccess.h>
  34. #include <linux/module.h>
  35. #include <linux/crc32.h>
  36. #include <asm/types.h>
  37. #include <linux/ethtool.h>
  38. #include <linux/mii.h>
  39. #include <linux/phy.h>
  40. #include <linux/sort.h>
  41. #include <linux/if_vlan.h>
  42. #include "gianfar.h"
  43. extern void gfar_start(struct net_device *dev);
  44. extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue,
  45. int rx_work_limit);
  46. #define GFAR_MAX_COAL_USECS 0xffff
  47. #define GFAR_MAX_COAL_FRAMES 0xff
  48. static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
  49. u64 *buf);
  50. static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
  51. static int gfar_gcoalesce(struct net_device *dev,
  52. struct ethtool_coalesce *cvals);
  53. static int gfar_scoalesce(struct net_device *dev,
  54. struct ethtool_coalesce *cvals);
  55. static void gfar_gringparam(struct net_device *dev,
  56. struct ethtool_ringparam *rvals);
  57. static int gfar_sringparam(struct net_device *dev,
  58. struct ethtool_ringparam *rvals);
  59. static void gfar_gdrvinfo(struct net_device *dev,
  60. struct ethtool_drvinfo *drvinfo);
  61. static const char stat_gstrings[][ETH_GSTRING_LEN] = {
  62. "rx-large-frame-errors",
  63. "rx-short-frame-errors",
  64. "rx-non-octet-errors",
  65. "rx-crc-errors",
  66. "rx-overrun-errors",
  67. "rx-busy-errors",
  68. "rx-babbling-errors",
  69. "rx-truncated-frames",
  70. "ethernet-bus-error",
  71. "tx-babbling-errors",
  72. "tx-underrun-errors",
  73. "rx-skb-missing-errors",
  74. "tx-timeout-errors",
  75. "tx-rx-64-frames",
  76. "tx-rx-65-127-frames",
  77. "tx-rx-128-255-frames",
  78. "tx-rx-256-511-frames",
  79. "tx-rx-512-1023-frames",
  80. "tx-rx-1024-1518-frames",
  81. "tx-rx-1519-1522-good-vlan",
  82. "rx-bytes",
  83. "rx-packets",
  84. "rx-fcs-errors",
  85. "receive-multicast-packet",
  86. "receive-broadcast-packet",
  87. "rx-control-frame-packets",
  88. "rx-pause-frame-packets",
  89. "rx-unknown-op-code",
  90. "rx-alignment-error",
  91. "rx-frame-length-error",
  92. "rx-code-error",
  93. "rx-carrier-sense-error",
  94. "rx-undersize-packets",
  95. "rx-oversize-packets",
  96. "rx-fragmented-frames",
  97. "rx-jabber-frames",
  98. "rx-dropped-frames",
  99. "tx-byte-counter",
  100. "tx-packets",
  101. "tx-multicast-packets",
  102. "tx-broadcast-packets",
  103. "tx-pause-control-frames",
  104. "tx-deferral-packets",
  105. "tx-excessive-deferral-packets",
  106. "tx-single-collision-packets",
  107. "tx-multiple-collision-packets",
  108. "tx-late-collision-packets",
  109. "tx-excessive-collision-packets",
  110. "tx-total-collision",
  111. "reserved",
  112. "tx-dropped-frames",
  113. "tx-jabber-frames",
  114. "tx-fcs-errors",
  115. "tx-control-frames",
  116. "tx-oversize-frames",
  117. "tx-undersize-frames",
  118. "tx-fragmented-frames",
  119. };
  120. /* Fill in a buffer with the strings which correspond to the
  121. * stats */
  122. static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
  123. {
  124. struct gfar_private *priv = netdev_priv(dev);
  125. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
  126. memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
  127. else
  128. memcpy(buf, stat_gstrings,
  129. GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
  130. }
  131. /* Fill in an array of 64-bit statistics from various sources.
  132. * This array will be appended to the end of the ethtool_stats
  133. * structure, and returned to user space
  134. */
  135. static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
  136. u64 *buf)
  137. {
  138. int i;
  139. struct gfar_private *priv = netdev_priv(dev);
  140. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  141. atomic64_t *extra = (atomic64_t *)&priv->extra_stats;
  142. for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
  143. buf[i] = atomic64_read(&extra[i]);
  144. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
  145. u32 __iomem *rmon = (u32 __iomem *) &regs->rmon;
  146. for (; i < GFAR_STATS_LEN; i++, rmon++)
  147. buf[i] = (u64) gfar_read(rmon);
  148. }
  149. }
  150. static int gfar_sset_count(struct net_device *dev, int sset)
  151. {
  152. struct gfar_private *priv = netdev_priv(dev);
  153. switch (sset) {
  154. case ETH_SS_STATS:
  155. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
  156. return GFAR_STATS_LEN;
  157. else
  158. return GFAR_EXTRA_STATS_LEN;
  159. default:
  160. return -EOPNOTSUPP;
  161. }
  162. }
  163. /* Fills in the drvinfo structure with some basic info */
  164. static void gfar_gdrvinfo(struct net_device *dev,
  165. struct ethtool_drvinfo *drvinfo)
  166. {
  167. strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
  168. strlcpy(drvinfo->version, gfar_driver_version,
  169. sizeof(drvinfo->version));
  170. strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
  171. strlcpy(drvinfo->bus_info, "N/A", sizeof(drvinfo->bus_info));
  172. drvinfo->regdump_len = 0;
  173. drvinfo->eedump_len = 0;
  174. }
  175. static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
  176. {
  177. struct gfar_private *priv = netdev_priv(dev);
  178. struct phy_device *phydev = priv->phydev;
  179. if (NULL == phydev)
  180. return -ENODEV;
  181. return phy_ethtool_sset(phydev, cmd);
  182. }
  183. /* Return the current settings in the ethtool_cmd structure */
  184. static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  185. {
  186. struct gfar_private *priv = netdev_priv(dev);
  187. struct phy_device *phydev = priv->phydev;
  188. struct gfar_priv_rx_q *rx_queue = NULL;
  189. struct gfar_priv_tx_q *tx_queue = NULL;
  190. if (NULL == phydev)
  191. return -ENODEV;
  192. tx_queue = priv->tx_queue[0];
  193. rx_queue = priv->rx_queue[0];
  194. /* etsec-1.7 and older versions have only one txic
  195. * and rxic regs although they support multiple queues */
  196. cmd->maxtxpkt = get_icft_value(tx_queue->txic);
  197. cmd->maxrxpkt = get_icft_value(rx_queue->rxic);
  198. return phy_ethtool_gset(phydev, cmd);
  199. }
  200. /* Return the length of the register structure */
  201. static int gfar_reglen(struct net_device *dev)
  202. {
  203. return sizeof (struct gfar);
  204. }
  205. /* Return a dump of the GFAR register space */
  206. static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs,
  207. void *regbuf)
  208. {
  209. int i;
  210. struct gfar_private *priv = netdev_priv(dev);
  211. u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs;
  212. u32 *buf = (u32 *) regbuf;
  213. for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
  214. buf[i] = gfar_read(&theregs[i]);
  215. }
  216. /* Convert microseconds to ethernet clock ticks, which changes
  217. * depending on what speed the controller is running at */
  218. static unsigned int gfar_usecs2ticks(struct gfar_private *priv,
  219. unsigned int usecs)
  220. {
  221. unsigned int count;
  222. /* The timer is different, depending on the interface speed */
  223. switch (priv->phydev->speed) {
  224. case SPEED_1000:
  225. count = GFAR_GBIT_TIME;
  226. break;
  227. case SPEED_100:
  228. count = GFAR_100_TIME;
  229. break;
  230. case SPEED_10:
  231. default:
  232. count = GFAR_10_TIME;
  233. break;
  234. }
  235. /* Make sure we return a number greater than 0
  236. * if usecs > 0 */
  237. return (usecs * 1000 + count - 1) / count;
  238. }
  239. /* Convert ethernet clock ticks to microseconds */
  240. static unsigned int gfar_ticks2usecs(struct gfar_private *priv,
  241. unsigned int ticks)
  242. {
  243. unsigned int count;
  244. /* The timer is different, depending on the interface speed */
  245. switch (priv->phydev->speed) {
  246. case SPEED_1000:
  247. count = GFAR_GBIT_TIME;
  248. break;
  249. case SPEED_100:
  250. count = GFAR_100_TIME;
  251. break;
  252. case SPEED_10:
  253. default:
  254. count = GFAR_10_TIME;
  255. break;
  256. }
  257. /* Make sure we return a number greater than 0 */
  258. /* if ticks is > 0 */
  259. return (ticks * count) / 1000;
  260. }
  261. /* Get the coalescing parameters, and put them in the cvals
  262. * structure. */
  263. static int gfar_gcoalesce(struct net_device *dev,
  264. struct ethtool_coalesce *cvals)
  265. {
  266. struct gfar_private *priv = netdev_priv(dev);
  267. struct gfar_priv_rx_q *rx_queue = NULL;
  268. struct gfar_priv_tx_q *tx_queue = NULL;
  269. unsigned long rxtime;
  270. unsigned long rxcount;
  271. unsigned long txtime;
  272. unsigned long txcount;
  273. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
  274. return -EOPNOTSUPP;
  275. if (NULL == priv->phydev)
  276. return -ENODEV;
  277. rx_queue = priv->rx_queue[0];
  278. tx_queue = priv->tx_queue[0];
  279. rxtime = get_ictt_value(rx_queue->rxic);
  280. rxcount = get_icft_value(rx_queue->rxic);
  281. txtime = get_ictt_value(tx_queue->txic);
  282. txcount = get_icft_value(tx_queue->txic);
  283. cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime);
  284. cvals->rx_max_coalesced_frames = rxcount;
  285. cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime);
  286. cvals->tx_max_coalesced_frames = txcount;
  287. cvals->use_adaptive_rx_coalesce = 0;
  288. cvals->use_adaptive_tx_coalesce = 0;
  289. cvals->pkt_rate_low = 0;
  290. cvals->rx_coalesce_usecs_low = 0;
  291. cvals->rx_max_coalesced_frames_low = 0;
  292. cvals->tx_coalesce_usecs_low = 0;
  293. cvals->tx_max_coalesced_frames_low = 0;
  294. /* When the packet rate is below pkt_rate_high but above
  295. * pkt_rate_low (both measured in packets per second) the
  296. * normal {rx,tx}_* coalescing parameters are used.
  297. */
  298. /* When the packet rate is (measured in packets per second)
  299. * is above pkt_rate_high, the {rx,tx}_*_high parameters are
  300. * used.
  301. */
  302. cvals->pkt_rate_high = 0;
  303. cvals->rx_coalesce_usecs_high = 0;
  304. cvals->rx_max_coalesced_frames_high = 0;
  305. cvals->tx_coalesce_usecs_high = 0;
  306. cvals->tx_max_coalesced_frames_high = 0;
  307. /* How often to do adaptive coalescing packet rate sampling,
  308. * measured in seconds. Must not be zero.
  309. */
  310. cvals->rate_sample_interval = 0;
  311. return 0;
  312. }
  313. /* Change the coalescing values.
  314. * Both cvals->*_usecs and cvals->*_frames have to be > 0
  315. * in order for coalescing to be active
  316. */
  317. static int gfar_scoalesce(struct net_device *dev,
  318. struct ethtool_coalesce *cvals)
  319. {
  320. struct gfar_private *priv = netdev_priv(dev);
  321. int i = 0;
  322. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
  323. return -EOPNOTSUPP;
  324. /* Set up rx coalescing */
  325. /* As of now, we will enable/disable coalescing for all
  326. * queues together in case of eTSEC2, this will be modified
  327. * along with the ethtool interface
  328. */
  329. if ((cvals->rx_coalesce_usecs == 0) ||
  330. (cvals->rx_max_coalesced_frames == 0)) {
  331. for (i = 0; i < priv->num_rx_queues; i++)
  332. priv->rx_queue[i]->rxcoalescing = 0;
  333. } else {
  334. for (i = 0; i < priv->num_rx_queues; i++)
  335. priv->rx_queue[i]->rxcoalescing = 1;
  336. }
  337. if (NULL == priv->phydev)
  338. return -ENODEV;
  339. /* Check the bounds of the values */
  340. if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
  341. pr_info("Coalescing is limited to %d microseconds\n",
  342. GFAR_MAX_COAL_USECS);
  343. return -EINVAL;
  344. }
  345. if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
  346. pr_info("Coalescing is limited to %d frames\n",
  347. GFAR_MAX_COAL_FRAMES);
  348. return -EINVAL;
  349. }
  350. for (i = 0; i < priv->num_rx_queues; i++) {
  351. priv->rx_queue[i]->rxic = mk_ic_value(
  352. cvals->rx_max_coalesced_frames,
  353. gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
  354. }
  355. /* Set up tx coalescing */
  356. if ((cvals->tx_coalesce_usecs == 0) ||
  357. (cvals->tx_max_coalesced_frames == 0)) {
  358. for (i = 0; i < priv->num_tx_queues; i++)
  359. priv->tx_queue[i]->txcoalescing = 0;
  360. } else {
  361. for (i = 0; i < priv->num_tx_queues; i++)
  362. priv->tx_queue[i]->txcoalescing = 1;
  363. }
  364. /* Check the bounds of the values */
  365. if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
  366. pr_info("Coalescing is limited to %d microseconds\n",
  367. GFAR_MAX_COAL_USECS);
  368. return -EINVAL;
  369. }
  370. if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
  371. pr_info("Coalescing is limited to %d frames\n",
  372. GFAR_MAX_COAL_FRAMES);
  373. return -EINVAL;
  374. }
  375. for (i = 0; i < priv->num_tx_queues; i++) {
  376. priv->tx_queue[i]->txic = mk_ic_value(
  377. cvals->tx_max_coalesced_frames,
  378. gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
  379. }
  380. gfar_configure_coalescing_all(priv);
  381. return 0;
  382. }
  383. /* Fills in rvals with the current ring parameters. Currently,
  384. * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
  385. * jumbo are ignored by the driver */
  386. static void gfar_gringparam(struct net_device *dev,
  387. struct ethtool_ringparam *rvals)
  388. {
  389. struct gfar_private *priv = netdev_priv(dev);
  390. struct gfar_priv_tx_q *tx_queue = NULL;
  391. struct gfar_priv_rx_q *rx_queue = NULL;
  392. tx_queue = priv->tx_queue[0];
  393. rx_queue = priv->rx_queue[0];
  394. rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
  395. rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
  396. rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
  397. rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;
  398. /* Values changeable by the user. The valid values are
  399. * in the range 1 to the "*_max_pending" counterpart above.
  400. */
  401. rvals->rx_pending = rx_queue->rx_ring_size;
  402. rvals->rx_mini_pending = rx_queue->rx_ring_size;
  403. rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
  404. rvals->tx_pending = tx_queue->tx_ring_size;
  405. }
  406. /* Change the current ring parameters, stopping the controller if
  407. * necessary so that we don't mess things up while we're in
  408. * motion. We wait for the ring to be clean before reallocating
  409. * the rings.
  410. */
  411. static int gfar_sringparam(struct net_device *dev,
  412. struct ethtool_ringparam *rvals)
  413. {
  414. struct gfar_private *priv = netdev_priv(dev);
  415. int err = 0, i = 0;
  416. if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
  417. return -EINVAL;
  418. if (!is_power_of_2(rvals->rx_pending)) {
  419. netdev_err(dev, "Ring sizes must be a power of 2\n");
  420. return -EINVAL;
  421. }
  422. if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
  423. return -EINVAL;
  424. if (!is_power_of_2(rvals->tx_pending)) {
  425. netdev_err(dev, "Ring sizes must be a power of 2\n");
  426. return -EINVAL;
  427. }
  428. if (dev->flags & IFF_UP) {
  429. unsigned long flags;
  430. /* Halt TX and RX, and process the frames which
  431. * have already been received
  432. */
  433. local_irq_save(flags);
  434. lock_tx_qs(priv);
  435. lock_rx_qs(priv);
  436. gfar_halt(dev);
  437. unlock_rx_qs(priv);
  438. unlock_tx_qs(priv);
  439. local_irq_restore(flags);
  440. for (i = 0; i < priv->num_rx_queues; i++)
  441. gfar_clean_rx_ring(priv->rx_queue[i],
  442. priv->rx_queue[i]->rx_ring_size);
  443. /* Now we take down the rings to rebuild them */
  444. stop_gfar(dev);
  445. }
  446. /* Change the size */
  447. for (i = 0; i < priv->num_rx_queues; i++) {
  448. priv->rx_queue[i]->rx_ring_size = rvals->rx_pending;
  449. priv->tx_queue[i]->tx_ring_size = rvals->tx_pending;
  450. priv->tx_queue[i]->num_txbdfree =
  451. priv->tx_queue[i]->tx_ring_size;
  452. }
  453. /* Rebuild the rings with the new size */
  454. if (dev->flags & IFF_UP) {
  455. err = startup_gfar(dev);
  456. netif_tx_wake_all_queues(dev);
  457. }
  458. return err;
  459. }
  460. int gfar_set_features(struct net_device *dev, netdev_features_t features)
  461. {
  462. struct gfar_private *priv = netdev_priv(dev);
  463. unsigned long flags;
  464. int err = 0, i = 0;
  465. netdev_features_t changed = dev->features ^ features;
  466. if (changed & (NETIF_F_HW_VLAN_TX|NETIF_F_HW_VLAN_RX))
  467. gfar_vlan_mode(dev, features);
  468. if (!(changed & NETIF_F_RXCSUM))
  469. return 0;
  470. if (dev->flags & IFF_UP) {
  471. /* Halt TX and RX, and process the frames which
  472. * have already been received
  473. */
  474. local_irq_save(flags);
  475. lock_tx_qs(priv);
  476. lock_rx_qs(priv);
  477. gfar_halt(dev);
  478. unlock_tx_qs(priv);
  479. unlock_rx_qs(priv);
  480. local_irq_restore(flags);
  481. for (i = 0; i < priv->num_rx_queues; i++)
  482. gfar_clean_rx_ring(priv->rx_queue[i],
  483. priv->rx_queue[i]->rx_ring_size);
  484. /* Now we take down the rings to rebuild them */
  485. stop_gfar(dev);
  486. dev->features = features;
  487. err = startup_gfar(dev);
  488. netif_tx_wake_all_queues(dev);
  489. }
  490. return err;
  491. }
  492. static uint32_t gfar_get_msglevel(struct net_device *dev)
  493. {
  494. struct gfar_private *priv = netdev_priv(dev);
  495. return priv->msg_enable;
  496. }
  497. static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
  498. {
  499. struct gfar_private *priv = netdev_priv(dev);
  500. priv->msg_enable = data;
  501. }
  502. #ifdef CONFIG_PM
  503. static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  504. {
  505. struct gfar_private *priv = netdev_priv(dev);
  506. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
  507. wol->supported = WAKE_MAGIC;
  508. wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
  509. } else {
  510. wol->supported = wol->wolopts = 0;
  511. }
  512. }
  513. static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  514. {
  515. struct gfar_private *priv = netdev_priv(dev);
  516. unsigned long flags;
  517. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  518. wol->wolopts != 0)
  519. return -EINVAL;
  520. if (wol->wolopts & ~WAKE_MAGIC)
  521. return -EINVAL;
  522. device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC);
  523. spin_lock_irqsave(&priv->bflock, flags);
  524. priv->wol_en = !!device_may_wakeup(&dev->dev);
  525. spin_unlock_irqrestore(&priv->bflock, flags);
  526. return 0;
  527. }
  528. #endif
  529. static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)
  530. {
  531. u32 fcr = 0x0, fpr = FPR_FILER_MASK;
  532. if (ethflow & RXH_L2DA) {
  533. fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH |
  534. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  535. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  536. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  537. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  538. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  539. fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH |
  540. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  541. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  542. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  543. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  544. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  545. }
  546. if (ethflow & RXH_VLAN) {
  547. fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  548. RQFCR_AND | RQFCR_HASHTBL_0;
  549. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  550. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  551. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  552. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  553. }
  554. if (ethflow & RXH_IP_SRC) {
  555. fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  556. RQFCR_AND | RQFCR_HASHTBL_0;
  557. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  558. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  559. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  560. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  561. }
  562. if (ethflow & (RXH_IP_DST)) {
  563. fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  564. RQFCR_AND | RQFCR_HASHTBL_0;
  565. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  566. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  567. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  568. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  569. }
  570. if (ethflow & RXH_L3_PROTO) {
  571. fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  572. RQFCR_AND | RQFCR_HASHTBL_0;
  573. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  574. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  575. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  576. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  577. }
  578. if (ethflow & RXH_L4_B_0_1) {
  579. fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  580. RQFCR_AND | RQFCR_HASHTBL_0;
  581. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  582. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  583. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  584. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  585. }
  586. if (ethflow & RXH_L4_B_2_3) {
  587. fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  588. RQFCR_AND | RQFCR_HASHTBL_0;
  589. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  590. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  591. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  592. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  593. }
  594. }
  595. static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow,
  596. u64 class)
  597. {
  598. unsigned int last_rule_idx = priv->cur_filer_idx;
  599. unsigned int cmp_rqfpr;
  600. unsigned int *local_rqfpr;
  601. unsigned int *local_rqfcr;
  602. int i = 0x0, k = 0x0;
  603. int j = MAX_FILER_IDX, l = 0x0;
  604. int ret = 1;
  605. local_rqfpr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int),
  606. GFP_KERNEL);
  607. local_rqfcr = kmalloc_array(MAX_FILER_IDX + 1, sizeof(unsigned int),
  608. GFP_KERNEL);
  609. if (!local_rqfpr || !local_rqfcr) {
  610. ret = 0;
  611. goto err;
  612. }
  613. switch (class) {
  614. case TCP_V4_FLOW:
  615. cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP;
  616. break;
  617. case UDP_V4_FLOW:
  618. cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP;
  619. break;
  620. case TCP_V6_FLOW:
  621. cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP;
  622. break;
  623. case UDP_V6_FLOW:
  624. cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP;
  625. break;
  626. default:
  627. pr_err("Right now this class is not supported\n");
  628. ret = 0;
  629. goto err;
  630. }
  631. for (i = 0; i < MAX_FILER_IDX + 1; i++) {
  632. local_rqfpr[j] = priv->ftp_rqfpr[i];
  633. local_rqfcr[j] = priv->ftp_rqfcr[i];
  634. j--;
  635. if ((priv->ftp_rqfcr[i] ==
  636. (RQFCR_PID_PARSE | RQFCR_CLE | RQFCR_AND)) &&
  637. (priv->ftp_rqfpr[i] == cmp_rqfpr))
  638. break;
  639. }
  640. if (i == MAX_FILER_IDX + 1) {
  641. pr_err("No parse rule found, can't create hash rules\n");
  642. ret = 0;
  643. goto err;
  644. }
  645. /* If a match was found, then it begins the starting of a cluster rule
  646. * if it was already programmed, we need to overwrite these rules
  647. */
  648. for (l = i+1; l < MAX_FILER_IDX; l++) {
  649. if ((priv->ftp_rqfcr[l] & RQFCR_CLE) &&
  650. !(priv->ftp_rqfcr[l] & RQFCR_AND)) {
  651. priv->ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
  652. RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
  653. priv->ftp_rqfpr[l] = FPR_FILER_MASK;
  654. gfar_write_filer(priv, l, priv->ftp_rqfcr[l],
  655. priv->ftp_rqfpr[l]);
  656. break;
  657. }
  658. if (!(priv->ftp_rqfcr[l] & RQFCR_CLE) &&
  659. (priv->ftp_rqfcr[l] & RQFCR_AND))
  660. continue;
  661. else {
  662. local_rqfpr[j] = priv->ftp_rqfpr[l];
  663. local_rqfcr[j] = priv->ftp_rqfcr[l];
  664. j--;
  665. }
  666. }
  667. priv->cur_filer_idx = l - 1;
  668. last_rule_idx = l;
  669. /* hash rules */
  670. ethflow_to_filer_rules(priv, ethflow);
  671. /* Write back the popped out rules again */
  672. for (k = j+1; k < MAX_FILER_IDX; k++) {
  673. priv->ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k];
  674. priv->ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k];
  675. gfar_write_filer(priv, priv->cur_filer_idx,
  676. local_rqfcr[k], local_rqfpr[k]);
  677. if (!priv->cur_filer_idx)
  678. break;
  679. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  680. }
  681. err:
  682. kfree(local_rqfcr);
  683. kfree(local_rqfpr);
  684. return ret;
  685. }
  686. static int gfar_set_hash_opts(struct gfar_private *priv,
  687. struct ethtool_rxnfc *cmd)
  688. {
  689. /* write the filer rules here */
  690. if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type))
  691. return -EINVAL;
  692. return 0;
  693. }
  694. static int gfar_check_filer_hardware(struct gfar_private *priv)
  695. {
  696. struct gfar __iomem *regs = NULL;
  697. u32 i;
  698. regs = priv->gfargrp[0].regs;
  699. /* Check if we are in FIFO mode */
  700. i = gfar_read(&regs->ecntrl);
  701. i &= ECNTRL_FIFM;
  702. if (i == ECNTRL_FIFM) {
  703. netdev_notice(priv->ndev, "Interface in FIFO mode\n");
  704. i = gfar_read(&regs->rctrl);
  705. i &= RCTRL_PRSDEP_MASK | RCTRL_PRSFM;
  706. if (i == (RCTRL_PRSDEP_MASK | RCTRL_PRSFM)) {
  707. netdev_info(priv->ndev,
  708. "Receive Queue Filtering enabled\n");
  709. } else {
  710. netdev_warn(priv->ndev,
  711. "Receive Queue Filtering disabled\n");
  712. return -EOPNOTSUPP;
  713. }
  714. }
  715. /* Or in standard mode */
  716. else {
  717. i = gfar_read(&regs->rctrl);
  718. i &= RCTRL_PRSDEP_MASK;
  719. if (i == RCTRL_PRSDEP_MASK) {
  720. netdev_info(priv->ndev,
  721. "Receive Queue Filtering enabled\n");
  722. } else {
  723. netdev_warn(priv->ndev,
  724. "Receive Queue Filtering disabled\n");
  725. return -EOPNOTSUPP;
  726. }
  727. }
  728. /* Sets the properties for arbitrary filer rule
  729. * to the first 4 Layer 4 Bytes
  730. */
  731. regs->rbifx = 0xC0C1C2C3;
  732. return 0;
  733. }
  734. static int gfar_comp_asc(const void *a, const void *b)
  735. {
  736. return memcmp(a, b, 4);
  737. }
  738. static int gfar_comp_desc(const void *a, const void *b)
  739. {
  740. return -memcmp(a, b, 4);
  741. }
  742. static void gfar_swap(void *a, void *b, int size)
  743. {
  744. u32 *_a = a;
  745. u32 *_b = b;
  746. swap(_a[0], _b[0]);
  747. swap(_a[1], _b[1]);
  748. swap(_a[2], _b[2]);
  749. swap(_a[3], _b[3]);
  750. }
  751. /* Write a mask to filer cache */
  752. static void gfar_set_mask(u32 mask, struct filer_table *tab)
  753. {
  754. tab->fe[tab->index].ctrl = RQFCR_AND | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
  755. tab->fe[tab->index].prop = mask;
  756. tab->index++;
  757. }
  758. /* Sets parse bits (e.g. IP or TCP) */
  759. static void gfar_set_parse_bits(u32 value, u32 mask, struct filer_table *tab)
  760. {
  761. gfar_set_mask(mask, tab);
  762. tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_PID_PARSE |
  763. RQFCR_AND;
  764. tab->fe[tab->index].prop = value;
  765. tab->index++;
  766. }
  767. static void gfar_set_general_attribute(u32 value, u32 mask, u32 flag,
  768. struct filer_table *tab)
  769. {
  770. gfar_set_mask(mask, tab);
  771. tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_AND | flag;
  772. tab->fe[tab->index].prop = value;
  773. tab->index++;
  774. }
  775. /* For setting a tuple of value and mask of type flag
  776. * Example:
  777. * IP-Src = 10.0.0.0/255.0.0.0
  778. * value: 0x0A000000 mask: FF000000 flag: RQFPR_IPV4
  779. *
  780. * Ethtool gives us a value=0 and mask=~0 for don't care a tuple
  781. * For a don't care mask it gives us a 0
  782. *
  783. * The check if don't care and the mask adjustment if mask=0 is done for VLAN
  784. * and MAC stuff on an upper level (due to missing information on this level).
  785. * For these guys we can discard them if they are value=0 and mask=0.
  786. *
  787. * Further the all masks are one-padded for better hardware efficiency.
  788. */
  789. static void gfar_set_attribute(u32 value, u32 mask, u32 flag,
  790. struct filer_table *tab)
  791. {
  792. switch (flag) {
  793. /* 3bit */
  794. case RQFCR_PID_PRI:
  795. if (!(value | mask))
  796. return;
  797. mask |= RQFCR_PID_PRI_MASK;
  798. break;
  799. /* 8bit */
  800. case RQFCR_PID_L4P:
  801. case RQFCR_PID_TOS:
  802. if (!~(mask | RQFCR_PID_L4P_MASK))
  803. return;
  804. if (!mask)
  805. mask = ~0;
  806. else
  807. mask |= RQFCR_PID_L4P_MASK;
  808. break;
  809. /* 12bit */
  810. case RQFCR_PID_VID:
  811. if (!(value | mask))
  812. return;
  813. mask |= RQFCR_PID_VID_MASK;
  814. break;
  815. /* 16bit */
  816. case RQFCR_PID_DPT:
  817. case RQFCR_PID_SPT:
  818. case RQFCR_PID_ETY:
  819. if (!~(mask | RQFCR_PID_PORT_MASK))
  820. return;
  821. if (!mask)
  822. mask = ~0;
  823. else
  824. mask |= RQFCR_PID_PORT_MASK;
  825. break;
  826. /* 24bit */
  827. case RQFCR_PID_DAH:
  828. case RQFCR_PID_DAL:
  829. case RQFCR_PID_SAH:
  830. case RQFCR_PID_SAL:
  831. if (!(value | mask))
  832. return;
  833. mask |= RQFCR_PID_MAC_MASK;
  834. break;
  835. /* for all real 32bit masks */
  836. default:
  837. if (!~mask)
  838. return;
  839. if (!mask)
  840. mask = ~0;
  841. break;
  842. }
  843. gfar_set_general_attribute(value, mask, flag, tab);
  844. }
  845. /* Translates value and mask for UDP, TCP or SCTP */
  846. static void gfar_set_basic_ip(struct ethtool_tcpip4_spec *value,
  847. struct ethtool_tcpip4_spec *mask,
  848. struct filer_table *tab)
  849. {
  850. gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab);
  851. gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab);
  852. gfar_set_attribute(value->pdst, mask->pdst, RQFCR_PID_DPT, tab);
  853. gfar_set_attribute(value->psrc, mask->psrc, RQFCR_PID_SPT, tab);
  854. gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab);
  855. }
  856. /* Translates value and mask for RAW-IP4 */
  857. static void gfar_set_user_ip(struct ethtool_usrip4_spec *value,
  858. struct ethtool_usrip4_spec *mask,
  859. struct filer_table *tab)
  860. {
  861. gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab);
  862. gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab);
  863. gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab);
  864. gfar_set_attribute(value->proto, mask->proto, RQFCR_PID_L4P, tab);
  865. gfar_set_attribute(value->l4_4_bytes, mask->l4_4_bytes, RQFCR_PID_ARB,
  866. tab);
  867. }
  868. /* Translates value and mask for ETHER spec */
  869. static void gfar_set_ether(struct ethhdr *value, struct ethhdr *mask,
  870. struct filer_table *tab)
  871. {
  872. u32 upper_temp_mask = 0;
  873. u32 lower_temp_mask = 0;
  874. /* Source address */
  875. if (!is_broadcast_ether_addr(mask->h_source)) {
  876. if (is_zero_ether_addr(mask->h_source)) {
  877. upper_temp_mask = 0xFFFFFFFF;
  878. lower_temp_mask = 0xFFFFFFFF;
  879. } else {
  880. upper_temp_mask = mask->h_source[0] << 16 |
  881. mask->h_source[1] << 8 |
  882. mask->h_source[2];
  883. lower_temp_mask = mask->h_source[3] << 16 |
  884. mask->h_source[4] << 8 |
  885. mask->h_source[5];
  886. }
  887. /* Upper 24bit */
  888. gfar_set_attribute(value->h_source[0] << 16 |
  889. value->h_source[1] << 8 |
  890. value->h_source[2],
  891. upper_temp_mask, RQFCR_PID_SAH, tab);
  892. /* And the same for the lower part */
  893. gfar_set_attribute(value->h_source[3] << 16 |
  894. value->h_source[4] << 8 |
  895. value->h_source[5],
  896. lower_temp_mask, RQFCR_PID_SAL, tab);
  897. }
  898. /* Destination address */
  899. if (!is_broadcast_ether_addr(mask->h_dest)) {
  900. /* Special for destination is limited broadcast */
  901. if ((is_broadcast_ether_addr(value->h_dest) &&
  902. is_zero_ether_addr(mask->h_dest))) {
  903. gfar_set_parse_bits(RQFPR_EBC, RQFPR_EBC, tab);
  904. } else {
  905. if (is_zero_ether_addr(mask->h_dest)) {
  906. upper_temp_mask = 0xFFFFFFFF;
  907. lower_temp_mask = 0xFFFFFFFF;
  908. } else {
  909. upper_temp_mask = mask->h_dest[0] << 16 |
  910. mask->h_dest[1] << 8 |
  911. mask->h_dest[2];
  912. lower_temp_mask = mask->h_dest[3] << 16 |
  913. mask->h_dest[4] << 8 |
  914. mask->h_dest[5];
  915. }
  916. /* Upper 24bit */
  917. gfar_set_attribute(value->h_dest[0] << 16 |
  918. value->h_dest[1] << 8 |
  919. value->h_dest[2],
  920. upper_temp_mask, RQFCR_PID_DAH, tab);
  921. /* And the same for the lower part */
  922. gfar_set_attribute(value->h_dest[3] << 16 |
  923. value->h_dest[4] << 8 |
  924. value->h_dest[5],
  925. lower_temp_mask, RQFCR_PID_DAL, tab);
  926. }
  927. }
  928. gfar_set_attribute(value->h_proto, mask->h_proto, RQFCR_PID_ETY, tab);
  929. }
  930. /* Convert a rule to binary filter format of gianfar */
  931. static int gfar_convert_to_filer(struct ethtool_rx_flow_spec *rule,
  932. struct filer_table *tab)
  933. {
  934. u32 vlan = 0, vlan_mask = 0;
  935. u32 id = 0, id_mask = 0;
  936. u32 cfi = 0, cfi_mask = 0;
  937. u32 prio = 0, prio_mask = 0;
  938. u32 old_index = tab->index;
  939. /* Check if vlan is wanted */
  940. if ((rule->flow_type & FLOW_EXT) && (rule->m_ext.vlan_tci != 0xFFFF)) {
  941. if (!rule->m_ext.vlan_tci)
  942. rule->m_ext.vlan_tci = 0xFFFF;
  943. vlan = RQFPR_VLN;
  944. vlan_mask = RQFPR_VLN;
  945. /* Separate the fields */
  946. id = rule->h_ext.vlan_tci & VLAN_VID_MASK;
  947. id_mask = rule->m_ext.vlan_tci & VLAN_VID_MASK;
  948. cfi = rule->h_ext.vlan_tci & VLAN_CFI_MASK;
  949. cfi_mask = rule->m_ext.vlan_tci & VLAN_CFI_MASK;
  950. prio = (rule->h_ext.vlan_tci & VLAN_PRIO_MASK) >>
  951. VLAN_PRIO_SHIFT;
  952. prio_mask = (rule->m_ext.vlan_tci & VLAN_PRIO_MASK) >>
  953. VLAN_PRIO_SHIFT;
  954. if (cfi == VLAN_TAG_PRESENT && cfi_mask == VLAN_TAG_PRESENT) {
  955. vlan |= RQFPR_CFI;
  956. vlan_mask |= RQFPR_CFI;
  957. } else if (cfi != VLAN_TAG_PRESENT &&
  958. cfi_mask == VLAN_TAG_PRESENT) {
  959. vlan_mask |= RQFPR_CFI;
  960. }
  961. }
  962. switch (rule->flow_type & ~FLOW_EXT) {
  963. case TCP_V4_FLOW:
  964. gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_TCP | vlan,
  965. RQFPR_IPV4 | RQFPR_TCP | vlan_mask, tab);
  966. gfar_set_basic_ip(&rule->h_u.tcp_ip4_spec,
  967. &rule->m_u.tcp_ip4_spec, tab);
  968. break;
  969. case UDP_V4_FLOW:
  970. gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_UDP | vlan,
  971. RQFPR_IPV4 | RQFPR_UDP | vlan_mask, tab);
  972. gfar_set_basic_ip(&rule->h_u.udp_ip4_spec,
  973. &rule->m_u.udp_ip4_spec, tab);
  974. break;
  975. case SCTP_V4_FLOW:
  976. gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask,
  977. tab);
  978. gfar_set_attribute(132, 0, RQFCR_PID_L4P, tab);
  979. gfar_set_basic_ip((struct ethtool_tcpip4_spec *)&rule->h_u,
  980. (struct ethtool_tcpip4_spec *)&rule->m_u,
  981. tab);
  982. break;
  983. case IP_USER_FLOW:
  984. gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask,
  985. tab);
  986. gfar_set_user_ip((struct ethtool_usrip4_spec *) &rule->h_u,
  987. (struct ethtool_usrip4_spec *) &rule->m_u,
  988. tab);
  989. break;
  990. case ETHER_FLOW:
  991. if (vlan)
  992. gfar_set_parse_bits(vlan, vlan_mask, tab);
  993. gfar_set_ether((struct ethhdr *) &rule->h_u,
  994. (struct ethhdr *) &rule->m_u, tab);
  995. break;
  996. default:
  997. return -1;
  998. }
  999. /* Set the vlan attributes in the end */
  1000. if (vlan) {
  1001. gfar_set_attribute(id, id_mask, RQFCR_PID_VID, tab);
  1002. gfar_set_attribute(prio, prio_mask, RQFCR_PID_PRI, tab);
  1003. }
  1004. /* If there has been nothing written till now, it must be a default */
  1005. if (tab->index == old_index) {
  1006. gfar_set_mask(0xFFFFFFFF, tab);
  1007. tab->fe[tab->index].ctrl = 0x20;
  1008. tab->fe[tab->index].prop = 0x0;
  1009. tab->index++;
  1010. }
  1011. /* Remove last AND */
  1012. tab->fe[tab->index - 1].ctrl &= (~RQFCR_AND);
  1013. /* Specify which queue to use or to drop */
  1014. if (rule->ring_cookie == RX_CLS_FLOW_DISC)
  1015. tab->fe[tab->index - 1].ctrl |= RQFCR_RJE;
  1016. else
  1017. tab->fe[tab->index - 1].ctrl |= (rule->ring_cookie << 10);
  1018. /* Only big enough entries can be clustered */
  1019. if (tab->index > (old_index + 2)) {
  1020. tab->fe[old_index + 1].ctrl |= RQFCR_CLE;
  1021. tab->fe[tab->index - 1].ctrl |= RQFCR_CLE;
  1022. }
  1023. /* In rare cases the cache can be full while there is
  1024. * free space in hw
  1025. */
  1026. if (tab->index > MAX_FILER_CACHE_IDX - 1)
  1027. return -EBUSY;
  1028. return 0;
  1029. }
  1030. /* Copy size filer entries */
  1031. static void gfar_copy_filer_entries(struct gfar_filer_entry dst[0],
  1032. struct gfar_filer_entry src[0], s32 size)
  1033. {
  1034. while (size > 0) {
  1035. size--;
  1036. dst[size].ctrl = src[size].ctrl;
  1037. dst[size].prop = src[size].prop;
  1038. }
  1039. }
  1040. /* Delete the contents of the filer-table between start and end
  1041. * and collapse them
  1042. */
  1043. static int gfar_trim_filer_entries(u32 begin, u32 end, struct filer_table *tab)
  1044. {
  1045. int length;
  1046. if (end > MAX_FILER_CACHE_IDX || end < begin)
  1047. return -EINVAL;
  1048. end++;
  1049. length = end - begin;
  1050. /* Copy */
  1051. while (end < tab->index) {
  1052. tab->fe[begin].ctrl = tab->fe[end].ctrl;
  1053. tab->fe[begin++].prop = tab->fe[end++].prop;
  1054. }
  1055. /* Fill up with don't cares */
  1056. while (begin < tab->index) {
  1057. tab->fe[begin].ctrl = 0x60;
  1058. tab->fe[begin].prop = 0xFFFFFFFF;
  1059. begin++;
  1060. }
  1061. tab->index -= length;
  1062. return 0;
  1063. }
  1064. /* Make space on the wanted location */
  1065. static int gfar_expand_filer_entries(u32 begin, u32 length,
  1066. struct filer_table *tab)
  1067. {
  1068. if (length == 0 || length + tab->index > MAX_FILER_CACHE_IDX ||
  1069. begin > MAX_FILER_CACHE_IDX)
  1070. return -EINVAL;
  1071. gfar_copy_filer_entries(&(tab->fe[begin + length]), &(tab->fe[begin]),
  1072. tab->index - length + 1);
  1073. tab->index += length;
  1074. return 0;
  1075. }
  1076. static int gfar_get_next_cluster_start(int start, struct filer_table *tab)
  1077. {
  1078. for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1);
  1079. start++) {
  1080. if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) ==
  1081. (RQFCR_AND | RQFCR_CLE))
  1082. return start;
  1083. }
  1084. return -1;
  1085. }
  1086. static int gfar_get_next_cluster_end(int start, struct filer_table *tab)
  1087. {
  1088. for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1);
  1089. start++) {
  1090. if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE)) ==
  1091. (RQFCR_CLE))
  1092. return start;
  1093. }
  1094. return -1;
  1095. }
  1096. /* Uses hardwares clustering option to reduce
  1097. * the number of filer table entries
  1098. */
  1099. static void gfar_cluster_filer(struct filer_table *tab)
  1100. {
  1101. s32 i = -1, j, iend, jend;
  1102. while ((i = gfar_get_next_cluster_start(++i, tab)) != -1) {
  1103. j = i;
  1104. while ((j = gfar_get_next_cluster_start(++j, tab)) != -1) {
  1105. /* The cluster entries self and the previous one
  1106. * (a mask) must be identical!
  1107. */
  1108. if (tab->fe[i].ctrl != tab->fe[j].ctrl)
  1109. break;
  1110. if (tab->fe[i].prop != tab->fe[j].prop)
  1111. break;
  1112. if (tab->fe[i - 1].ctrl != tab->fe[j - 1].ctrl)
  1113. break;
  1114. if (tab->fe[i - 1].prop != tab->fe[j - 1].prop)
  1115. break;
  1116. iend = gfar_get_next_cluster_end(i, tab);
  1117. jend = gfar_get_next_cluster_end(j, tab);
  1118. if (jend == -1 || iend == -1)
  1119. break;
  1120. /* First we make some free space, where our cluster
  1121. * element should be. Then we copy it there and finally
  1122. * delete in from its old location.
  1123. */
  1124. if (gfar_expand_filer_entries(iend, (jend - j), tab) ==
  1125. -EINVAL)
  1126. break;
  1127. gfar_copy_filer_entries(&(tab->fe[iend + 1]),
  1128. &(tab->fe[jend + 1]), jend - j);
  1129. if (gfar_trim_filer_entries(jend - 1,
  1130. jend + (jend - j),
  1131. tab) == -EINVAL)
  1132. return;
  1133. /* Mask out cluster bit */
  1134. tab->fe[iend].ctrl &= ~(RQFCR_CLE);
  1135. }
  1136. }
  1137. }
  1138. /* Swaps the masked bits of a1<>a2 and b1<>b2 */
  1139. static void gfar_swap_bits(struct gfar_filer_entry *a1,
  1140. struct gfar_filer_entry *a2,
  1141. struct gfar_filer_entry *b1,
  1142. struct gfar_filer_entry *b2, u32 mask)
  1143. {
  1144. u32 temp[4];
  1145. temp[0] = a1->ctrl & mask;
  1146. temp[1] = a2->ctrl & mask;
  1147. temp[2] = b1->ctrl & mask;
  1148. temp[3] = b2->ctrl & mask;
  1149. a1->ctrl &= ~mask;
  1150. a2->ctrl &= ~mask;
  1151. b1->ctrl &= ~mask;
  1152. b2->ctrl &= ~mask;
  1153. a1->ctrl |= temp[1];
  1154. a2->ctrl |= temp[0];
  1155. b1->ctrl |= temp[3];
  1156. b2->ctrl |= temp[2];
  1157. }
  1158. /* Generate a list consisting of masks values with their start and
  1159. * end of validity and block as indicator for parts belonging
  1160. * together (glued by ANDs) in mask_table
  1161. */
  1162. static u32 gfar_generate_mask_table(struct gfar_mask_entry *mask_table,
  1163. struct filer_table *tab)
  1164. {
  1165. u32 i, and_index = 0, block_index = 1;
  1166. for (i = 0; i < tab->index; i++) {
  1167. /* LSByte of control = 0 sets a mask */
  1168. if (!(tab->fe[i].ctrl & 0xF)) {
  1169. mask_table[and_index].mask = tab->fe[i].prop;
  1170. mask_table[and_index].start = i;
  1171. mask_table[and_index].block = block_index;
  1172. if (and_index >= 1)
  1173. mask_table[and_index - 1].end = i - 1;
  1174. and_index++;
  1175. }
  1176. /* cluster starts and ends will be separated because they should
  1177. * hold their position
  1178. */
  1179. if (tab->fe[i].ctrl & RQFCR_CLE)
  1180. block_index++;
  1181. /* A not set AND indicates the end of a depended block */
  1182. if (!(tab->fe[i].ctrl & RQFCR_AND))
  1183. block_index++;
  1184. }
  1185. mask_table[and_index - 1].end = i - 1;
  1186. return and_index;
  1187. }
  1188. /* Sorts the entries of mask_table by the values of the masks.
  1189. * Important: The 0xFF80 flags of the first and last entry of a
  1190. * block must hold their position (which queue, CLusterEnable, ReJEct,
  1191. * AND)
  1192. */
  1193. static void gfar_sort_mask_table(struct gfar_mask_entry *mask_table,
  1194. struct filer_table *temp_table, u32 and_index)
  1195. {
  1196. /* Pointer to compare function (_asc or _desc) */
  1197. int (*gfar_comp)(const void *, const void *);
  1198. u32 i, size = 0, start = 0, prev = 1;
  1199. u32 old_first, old_last, new_first, new_last;
  1200. gfar_comp = &gfar_comp_desc;
  1201. for (i = 0; i < and_index; i++) {
  1202. if (prev != mask_table[i].block) {
  1203. old_first = mask_table[start].start + 1;
  1204. old_last = mask_table[i - 1].end;
  1205. sort(mask_table + start, size,
  1206. sizeof(struct gfar_mask_entry),
  1207. gfar_comp, &gfar_swap);
  1208. /* Toggle order for every block. This makes the
  1209. * thing more efficient!
  1210. */
  1211. if (gfar_comp == gfar_comp_desc)
  1212. gfar_comp = &gfar_comp_asc;
  1213. else
  1214. gfar_comp = &gfar_comp_desc;
  1215. new_first = mask_table[start].start + 1;
  1216. new_last = mask_table[i - 1].end;
  1217. gfar_swap_bits(&temp_table->fe[new_first],
  1218. &temp_table->fe[old_first],
  1219. &temp_table->fe[new_last],
  1220. &temp_table->fe[old_last],
  1221. RQFCR_QUEUE | RQFCR_CLE |
  1222. RQFCR_RJE | RQFCR_AND);
  1223. start = i;
  1224. size = 0;
  1225. }
  1226. size++;
  1227. prev = mask_table[i].block;
  1228. }
  1229. }
  1230. /* Reduces the number of masks needed in the filer table to save entries
  1231. * This is done by sorting the masks of a depended block. A depended block is
  1232. * identified by gluing ANDs or CLE. The sorting order toggles after every
  1233. * block. Of course entries in scope of a mask must change their location with
  1234. * it.
  1235. */
  1236. static int gfar_optimize_filer_masks(struct filer_table *tab)
  1237. {
  1238. struct filer_table *temp_table;
  1239. struct gfar_mask_entry *mask_table;
  1240. u32 and_index = 0, previous_mask = 0, i = 0, j = 0, size = 0;
  1241. s32 ret = 0;
  1242. /* We need a copy of the filer table because
  1243. * we want to change its order
  1244. */
  1245. temp_table = kmemdup(tab, sizeof(*temp_table), GFP_KERNEL);
  1246. if (temp_table == NULL)
  1247. return -ENOMEM;
  1248. mask_table = kcalloc(MAX_FILER_CACHE_IDX / 2 + 1,
  1249. sizeof(struct gfar_mask_entry), GFP_KERNEL);
  1250. if (mask_table == NULL) {
  1251. ret = -ENOMEM;
  1252. goto end;
  1253. }
  1254. and_index = gfar_generate_mask_table(mask_table, tab);
  1255. gfar_sort_mask_table(mask_table, temp_table, and_index);
  1256. /* Now we can copy the data from our duplicated filer table to
  1257. * the real one in the order the mask table says
  1258. */
  1259. for (i = 0; i < and_index; i++) {
  1260. size = mask_table[i].end - mask_table[i].start + 1;
  1261. gfar_copy_filer_entries(&(tab->fe[j]),
  1262. &(temp_table->fe[mask_table[i].start]), size);
  1263. j += size;
  1264. }
  1265. /* And finally we just have to check for duplicated masks and drop the
  1266. * second ones
  1267. */
  1268. for (i = 0; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) {
  1269. if (tab->fe[i].ctrl == 0x80) {
  1270. previous_mask = i++;
  1271. break;
  1272. }
  1273. }
  1274. for (; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) {
  1275. if (tab->fe[i].ctrl == 0x80) {
  1276. if (tab->fe[i].prop == tab->fe[previous_mask].prop) {
  1277. /* Two identical ones found!
  1278. * So drop the second one!
  1279. */
  1280. gfar_trim_filer_entries(i, i, tab);
  1281. } else
  1282. /* Not identical! */
  1283. previous_mask = i;
  1284. }
  1285. }
  1286. kfree(mask_table);
  1287. end: kfree(temp_table);
  1288. return ret;
  1289. }
  1290. /* Write the bit-pattern from software's buffer to hardware registers */
  1291. static int gfar_write_filer_table(struct gfar_private *priv,
  1292. struct filer_table *tab)
  1293. {
  1294. u32 i = 0;
  1295. if (tab->index > MAX_FILER_IDX - 1)
  1296. return -EBUSY;
  1297. /* Avoid inconsistent filer table to be processed */
  1298. lock_rx_qs(priv);
  1299. /* Fill regular entries */
  1300. for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl);
  1301. i++)
  1302. gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
  1303. /* Fill the rest with fall-troughs */
  1304. for (; i < MAX_FILER_IDX - 1; i++)
  1305. gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF);
  1306. /* Last entry must be default accept
  1307. * because that's what people expect
  1308. */
  1309. gfar_write_filer(priv, i, 0x20, 0x0);
  1310. unlock_rx_qs(priv);
  1311. return 0;
  1312. }
  1313. static int gfar_check_capability(struct ethtool_rx_flow_spec *flow,
  1314. struct gfar_private *priv)
  1315. {
  1316. if (flow->flow_type & FLOW_EXT) {
  1317. if (~flow->m_ext.data[0] || ~flow->m_ext.data[1])
  1318. netdev_warn(priv->ndev,
  1319. "User-specific data not supported!\n");
  1320. if (~flow->m_ext.vlan_etype)
  1321. netdev_warn(priv->ndev,
  1322. "VLAN-etype not supported!\n");
  1323. }
  1324. if (flow->flow_type == IP_USER_FLOW)
  1325. if (flow->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4)
  1326. netdev_warn(priv->ndev,
  1327. "IP-Version differing from IPv4 not supported!\n");
  1328. return 0;
  1329. }
  1330. static int gfar_process_filer_changes(struct gfar_private *priv)
  1331. {
  1332. struct ethtool_flow_spec_container *j;
  1333. struct filer_table *tab;
  1334. s32 i = 0;
  1335. s32 ret = 0;
  1336. /* So index is set to zero, too! */
  1337. tab = kzalloc(sizeof(*tab), GFP_KERNEL);
  1338. if (tab == NULL)
  1339. return -ENOMEM;
  1340. /* Now convert the existing filer data from flow_spec into
  1341. * filer tables binary format
  1342. */
  1343. list_for_each_entry(j, &priv->rx_list.list, list) {
  1344. ret = gfar_convert_to_filer(&j->fs, tab);
  1345. if (ret == -EBUSY) {
  1346. netdev_err(priv->ndev,
  1347. "Rule not added: No free space!\n");
  1348. goto end;
  1349. }
  1350. if (ret == -1) {
  1351. netdev_err(priv->ndev,
  1352. "Rule not added: Unsupported Flow-type!\n");
  1353. goto end;
  1354. }
  1355. }
  1356. i = tab->index;
  1357. /* Optimizations to save entries */
  1358. gfar_cluster_filer(tab);
  1359. gfar_optimize_filer_masks(tab);
  1360. pr_debug("\n\tSummary:\n"
  1361. "\tData on hardware: %d\n"
  1362. "\tCompression rate: %d%%\n",
  1363. tab->index, 100 - (100 * tab->index) / i);
  1364. /* Write everything to hardware */
  1365. ret = gfar_write_filer_table(priv, tab);
  1366. if (ret == -EBUSY) {
  1367. netdev_err(priv->ndev, "Rule not added: No free space!\n");
  1368. goto end;
  1369. }
  1370. end:
  1371. kfree(tab);
  1372. return ret;
  1373. }
  1374. static void gfar_invert_masks(struct ethtool_rx_flow_spec *flow)
  1375. {
  1376. u32 i = 0;
  1377. for (i = 0; i < sizeof(flow->m_u); i++)
  1378. flow->m_u.hdata[i] ^= 0xFF;
  1379. flow->m_ext.vlan_etype ^= 0xFFFF;
  1380. flow->m_ext.vlan_tci ^= 0xFFFF;
  1381. flow->m_ext.data[0] ^= ~0;
  1382. flow->m_ext.data[1] ^= ~0;
  1383. }
  1384. static int gfar_add_cls(struct gfar_private *priv,
  1385. struct ethtool_rx_flow_spec *flow)
  1386. {
  1387. struct ethtool_flow_spec_container *temp, *comp;
  1388. int ret = 0;
  1389. temp = kmalloc(sizeof(*temp), GFP_KERNEL);
  1390. if (temp == NULL)
  1391. return -ENOMEM;
  1392. memcpy(&temp->fs, flow, sizeof(temp->fs));
  1393. gfar_invert_masks(&temp->fs);
  1394. ret = gfar_check_capability(&temp->fs, priv);
  1395. if (ret)
  1396. goto clean_mem;
  1397. /* Link in the new element at the right @location */
  1398. if (list_empty(&priv->rx_list.list)) {
  1399. ret = gfar_check_filer_hardware(priv);
  1400. if (ret != 0)
  1401. goto clean_mem;
  1402. list_add(&temp->list, &priv->rx_list.list);
  1403. goto process;
  1404. } else {
  1405. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1406. if (comp->fs.location > flow->location) {
  1407. list_add_tail(&temp->list, &comp->list);
  1408. goto process;
  1409. }
  1410. if (comp->fs.location == flow->location) {
  1411. netdev_err(priv->ndev,
  1412. "Rule not added: ID %d not free!\n",
  1413. flow->location);
  1414. ret = -EBUSY;
  1415. goto clean_mem;
  1416. }
  1417. }
  1418. list_add_tail(&temp->list, &priv->rx_list.list);
  1419. }
  1420. process:
  1421. ret = gfar_process_filer_changes(priv);
  1422. if (ret)
  1423. goto clean_list;
  1424. priv->rx_list.count++;
  1425. return ret;
  1426. clean_list:
  1427. list_del(&temp->list);
  1428. clean_mem:
  1429. kfree(temp);
  1430. return ret;
  1431. }
  1432. static int gfar_del_cls(struct gfar_private *priv, u32 loc)
  1433. {
  1434. struct ethtool_flow_spec_container *comp;
  1435. u32 ret = -EINVAL;
  1436. if (list_empty(&priv->rx_list.list))
  1437. return ret;
  1438. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1439. if (comp->fs.location == loc) {
  1440. list_del(&comp->list);
  1441. kfree(comp);
  1442. priv->rx_list.count--;
  1443. gfar_process_filer_changes(priv);
  1444. ret = 0;
  1445. break;
  1446. }
  1447. }
  1448. return ret;
  1449. }
  1450. static int gfar_get_cls(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
  1451. {
  1452. struct ethtool_flow_spec_container *comp;
  1453. u32 ret = -EINVAL;
  1454. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1455. if (comp->fs.location == cmd->fs.location) {
  1456. memcpy(&cmd->fs, &comp->fs, sizeof(cmd->fs));
  1457. gfar_invert_masks(&cmd->fs);
  1458. ret = 0;
  1459. break;
  1460. }
  1461. }
  1462. return ret;
  1463. }
  1464. static int gfar_get_cls_all(struct gfar_private *priv,
  1465. struct ethtool_rxnfc *cmd, u32 *rule_locs)
  1466. {
  1467. struct ethtool_flow_spec_container *comp;
  1468. u32 i = 0;
  1469. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1470. if (i == cmd->rule_cnt)
  1471. return -EMSGSIZE;
  1472. rule_locs[i] = comp->fs.location;
  1473. i++;
  1474. }
  1475. cmd->data = MAX_FILER_IDX;
  1476. cmd->rule_cnt = i;
  1477. return 0;
  1478. }
  1479. static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  1480. {
  1481. struct gfar_private *priv = netdev_priv(dev);
  1482. int ret = 0;
  1483. mutex_lock(&priv->rx_queue_access);
  1484. switch (cmd->cmd) {
  1485. case ETHTOOL_SRXFH:
  1486. ret = gfar_set_hash_opts(priv, cmd);
  1487. break;
  1488. case ETHTOOL_SRXCLSRLINS:
  1489. if ((cmd->fs.ring_cookie != RX_CLS_FLOW_DISC &&
  1490. cmd->fs.ring_cookie >= priv->num_rx_queues) ||
  1491. cmd->fs.location >= MAX_FILER_IDX) {
  1492. ret = -EINVAL;
  1493. break;
  1494. }
  1495. ret = gfar_add_cls(priv, &cmd->fs);
  1496. break;
  1497. case ETHTOOL_SRXCLSRLDEL:
  1498. ret = gfar_del_cls(priv, cmd->fs.location);
  1499. break;
  1500. default:
  1501. ret = -EINVAL;
  1502. }
  1503. mutex_unlock(&priv->rx_queue_access);
  1504. return ret;
  1505. }
  1506. static int gfar_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  1507. u32 *rule_locs)
  1508. {
  1509. struct gfar_private *priv = netdev_priv(dev);
  1510. int ret = 0;
  1511. switch (cmd->cmd) {
  1512. case ETHTOOL_GRXRINGS:
  1513. cmd->data = priv->num_rx_queues;
  1514. break;
  1515. case ETHTOOL_GRXCLSRLCNT:
  1516. cmd->rule_cnt = priv->rx_list.count;
  1517. break;
  1518. case ETHTOOL_GRXCLSRULE:
  1519. ret = gfar_get_cls(priv, cmd);
  1520. break;
  1521. case ETHTOOL_GRXCLSRLALL:
  1522. ret = gfar_get_cls_all(priv, cmd, rule_locs);
  1523. break;
  1524. default:
  1525. ret = -EINVAL;
  1526. break;
  1527. }
  1528. return ret;
  1529. }
  1530. int gfar_phc_index = -1;
  1531. EXPORT_SYMBOL(gfar_phc_index);
  1532. static int gfar_get_ts_info(struct net_device *dev,
  1533. struct ethtool_ts_info *info)
  1534. {
  1535. struct gfar_private *priv = netdev_priv(dev);
  1536. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_TIMER)) {
  1537. info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
  1538. SOF_TIMESTAMPING_SOFTWARE;
  1539. info->phc_index = -1;
  1540. return 0;
  1541. }
  1542. info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
  1543. SOF_TIMESTAMPING_RX_HARDWARE |
  1544. SOF_TIMESTAMPING_RAW_HARDWARE;
  1545. info->phc_index = gfar_phc_index;
  1546. info->tx_types = (1 << HWTSTAMP_TX_OFF) |
  1547. (1 << HWTSTAMP_TX_ON);
  1548. info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  1549. (1 << HWTSTAMP_FILTER_ALL);
  1550. return 0;
  1551. }
  1552. const struct ethtool_ops gfar_ethtool_ops = {
  1553. .get_settings = gfar_gsettings,
  1554. .set_settings = gfar_ssettings,
  1555. .get_drvinfo = gfar_gdrvinfo,
  1556. .get_regs_len = gfar_reglen,
  1557. .get_regs = gfar_get_regs,
  1558. .get_link = ethtool_op_get_link,
  1559. .get_coalesce = gfar_gcoalesce,
  1560. .set_coalesce = gfar_scoalesce,
  1561. .get_ringparam = gfar_gringparam,
  1562. .set_ringparam = gfar_sringparam,
  1563. .get_strings = gfar_gstrings,
  1564. .get_sset_count = gfar_sset_count,
  1565. .get_ethtool_stats = gfar_fill_stats,
  1566. .get_msglevel = gfar_get_msglevel,
  1567. .set_msglevel = gfar_set_msglevel,
  1568. #ifdef CONFIG_PM
  1569. .get_wol = gfar_get_wol,
  1570. .set_wol = gfar_set_wol,
  1571. #endif
  1572. .set_rxnfc = gfar_set_nfc,
  1573. .get_rxnfc = gfar_get_nfc,
  1574. .get_ts_info = gfar_get_ts_info,
  1575. };