gianfar_ethtool.c 46 KB

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