gianfar_ethtool.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  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_RXCSUM))
  451. return 0;
  452. if (dev->flags & IFF_UP) {
  453. /* Halt TX and RX, and process the frames which
  454. * have already been received */
  455. local_irq_save(flags);
  456. lock_tx_qs(priv);
  457. lock_rx_qs(priv);
  458. gfar_halt(dev);
  459. unlock_tx_qs(priv);
  460. unlock_rx_qs(priv);
  461. local_irq_restore(flags);
  462. for (i = 0; i < priv->num_rx_queues; i++)
  463. gfar_clean_rx_ring(priv->rx_queue[i],
  464. priv->rx_queue[i]->rx_ring_size);
  465. /* Now we take down the rings to rebuild them */
  466. stop_gfar(dev);
  467. dev->features = features;
  468. err = startup_gfar(dev);
  469. netif_tx_wake_all_queues(dev);
  470. }
  471. return err;
  472. }
  473. static uint32_t gfar_get_msglevel(struct net_device *dev)
  474. {
  475. struct gfar_private *priv = netdev_priv(dev);
  476. return priv->msg_enable;
  477. }
  478. static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
  479. {
  480. struct gfar_private *priv = netdev_priv(dev);
  481. priv->msg_enable = data;
  482. }
  483. #ifdef CONFIG_PM
  484. static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  485. {
  486. struct gfar_private *priv = netdev_priv(dev);
  487. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
  488. wol->supported = WAKE_MAGIC;
  489. wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
  490. } else {
  491. wol->supported = wol->wolopts = 0;
  492. }
  493. }
  494. static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  495. {
  496. struct gfar_private *priv = netdev_priv(dev);
  497. unsigned long flags;
  498. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  499. wol->wolopts != 0)
  500. return -EINVAL;
  501. if (wol->wolopts & ~WAKE_MAGIC)
  502. return -EINVAL;
  503. device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC);
  504. spin_lock_irqsave(&priv->bflock, flags);
  505. priv->wol_en = !!device_may_wakeup(&dev->dev);
  506. spin_unlock_irqrestore(&priv->bflock, flags);
  507. return 0;
  508. }
  509. #endif
  510. static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)
  511. {
  512. u32 fcr = 0x0, fpr = FPR_FILER_MASK;
  513. if (ethflow & RXH_L2DA) {
  514. fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH |
  515. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  516. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  517. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  518. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  519. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  520. fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH |
  521. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  522. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  523. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  524. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  525. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  526. }
  527. if (ethflow & RXH_VLAN) {
  528. fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  529. RQFCR_AND | RQFCR_HASHTBL_0;
  530. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  531. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  532. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  533. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  534. }
  535. if (ethflow & RXH_IP_SRC) {
  536. fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  537. RQFCR_AND | RQFCR_HASHTBL_0;
  538. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  539. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  540. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  541. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  542. }
  543. if (ethflow & (RXH_IP_DST)) {
  544. fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  545. RQFCR_AND | RQFCR_HASHTBL_0;
  546. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  547. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  548. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  549. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  550. }
  551. if (ethflow & RXH_L3_PROTO) {
  552. fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  553. RQFCR_AND | RQFCR_HASHTBL_0;
  554. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  555. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  556. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  557. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  558. }
  559. if (ethflow & RXH_L4_B_0_1) {
  560. fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  561. RQFCR_AND | RQFCR_HASHTBL_0;
  562. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  563. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  564. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  565. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  566. }
  567. if (ethflow & RXH_L4_B_2_3) {
  568. fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  569. RQFCR_AND | RQFCR_HASHTBL_0;
  570. priv->ftp_rqfpr[priv->cur_filer_idx] = fpr;
  571. priv->ftp_rqfcr[priv->cur_filer_idx] = fcr;
  572. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  573. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  574. }
  575. }
  576. static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u64 class)
  577. {
  578. unsigned int last_rule_idx = priv->cur_filer_idx;
  579. unsigned int cmp_rqfpr;
  580. unsigned int local_rqfpr[MAX_FILER_IDX + 1];
  581. unsigned int local_rqfcr[MAX_FILER_IDX + 1];
  582. int i = 0x0, k = 0x0;
  583. int j = MAX_FILER_IDX, l = 0x0;
  584. switch (class) {
  585. case TCP_V4_FLOW:
  586. cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP;
  587. break;
  588. case UDP_V4_FLOW:
  589. cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP;
  590. break;
  591. case TCP_V6_FLOW:
  592. cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP;
  593. break;
  594. case UDP_V6_FLOW:
  595. cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP;
  596. break;
  597. default:
  598. pr_err("Right now this class is not supported\n");
  599. return 0;
  600. }
  601. for (i = 0; i < MAX_FILER_IDX + 1; i++) {
  602. local_rqfpr[j] = priv->ftp_rqfpr[i];
  603. local_rqfcr[j] = priv->ftp_rqfcr[i];
  604. j--;
  605. if ((priv->ftp_rqfcr[i] == (RQFCR_PID_PARSE |
  606. RQFCR_CLE |RQFCR_AND)) &&
  607. (priv->ftp_rqfpr[i] == cmp_rqfpr))
  608. break;
  609. }
  610. if (i == MAX_FILER_IDX + 1) {
  611. pr_err("No parse rule found, can't create hash rules\n");
  612. return 0;
  613. }
  614. /* If a match was found, then it begins the starting of a cluster rule
  615. * if it was already programmed, we need to overwrite these rules
  616. */
  617. for (l = i+1; l < MAX_FILER_IDX; l++) {
  618. if ((priv->ftp_rqfcr[l] & RQFCR_CLE) &&
  619. !(priv->ftp_rqfcr[l] & RQFCR_AND)) {
  620. priv->ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
  621. RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
  622. priv->ftp_rqfpr[l] = FPR_FILER_MASK;
  623. gfar_write_filer(priv, l, priv->ftp_rqfcr[l],
  624. priv->ftp_rqfpr[l]);
  625. break;
  626. }
  627. if (!(priv->ftp_rqfcr[l] & RQFCR_CLE) &&
  628. (priv->ftp_rqfcr[l] & RQFCR_AND))
  629. continue;
  630. else {
  631. local_rqfpr[j] = priv->ftp_rqfpr[l];
  632. local_rqfcr[j] = priv->ftp_rqfcr[l];
  633. j--;
  634. }
  635. }
  636. priv->cur_filer_idx = l - 1;
  637. last_rule_idx = l;
  638. /* hash rules */
  639. ethflow_to_filer_rules(priv, ethflow);
  640. /* Write back the popped out rules again */
  641. for (k = j+1; k < MAX_FILER_IDX; k++) {
  642. priv->ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k];
  643. priv->ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k];
  644. gfar_write_filer(priv, priv->cur_filer_idx,
  645. local_rqfcr[k], local_rqfpr[k]);
  646. if (!priv->cur_filer_idx)
  647. break;
  648. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  649. }
  650. return 1;
  651. }
  652. static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
  653. {
  654. /* write the filer rules here */
  655. if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type))
  656. return -EINVAL;
  657. return 0;
  658. }
  659. static int gfar_check_filer_hardware(struct gfar_private *priv)
  660. {
  661. struct gfar __iomem *regs = NULL;
  662. u32 i;
  663. regs = priv->gfargrp[0].regs;
  664. /* Check if we are in FIFO mode */
  665. i = gfar_read(&regs->ecntrl);
  666. i &= ECNTRL_FIFM;
  667. if (i == ECNTRL_FIFM) {
  668. netdev_notice(priv->ndev, "Interface in FIFO mode\n");
  669. i = gfar_read(&regs->rctrl);
  670. i &= RCTRL_PRSDEP_MASK | RCTRL_PRSFM;
  671. if (i == (RCTRL_PRSDEP_MASK | RCTRL_PRSFM)) {
  672. netdev_info(priv->ndev,
  673. "Receive Queue Filtering enabled\n");
  674. } else {
  675. netdev_warn(priv->ndev,
  676. "Receive Queue Filtering disabled\n");
  677. return -EOPNOTSUPP;
  678. }
  679. }
  680. /* Or in standard mode */
  681. else {
  682. i = gfar_read(&regs->rctrl);
  683. i &= RCTRL_PRSDEP_MASK;
  684. if (i == RCTRL_PRSDEP_MASK) {
  685. netdev_info(priv->ndev,
  686. "Receive Queue Filtering enabled\n");
  687. } else {
  688. netdev_warn(priv->ndev,
  689. "Receive Queue Filtering disabled\n");
  690. return -EOPNOTSUPP;
  691. }
  692. }
  693. /* Sets the properties for arbitrary filer rule
  694. * to the first 4 Layer 4 Bytes */
  695. regs->rbifx = 0xC0C1C2C3;
  696. return 0;
  697. }
  698. static int gfar_comp_asc(const void *a, const void *b)
  699. {
  700. return memcmp(a, b, 4);
  701. }
  702. static int gfar_comp_desc(const void *a, const void *b)
  703. {
  704. return -memcmp(a, b, 4);
  705. }
  706. static void gfar_swap(void *a, void *b, int size)
  707. {
  708. u32 *_a = a;
  709. u32 *_b = b;
  710. swap(_a[0], _b[0]);
  711. swap(_a[1], _b[1]);
  712. swap(_a[2], _b[2]);
  713. swap(_a[3], _b[3]);
  714. }
  715. /* Write a mask to filer cache */
  716. static void gfar_set_mask(u32 mask, struct filer_table *tab)
  717. {
  718. tab->fe[tab->index].ctrl = RQFCR_AND | RQFCR_PID_MASK | RQFCR_CMP_EXACT;
  719. tab->fe[tab->index].prop = mask;
  720. tab->index++;
  721. }
  722. /* Sets parse bits (e.g. IP or TCP) */
  723. static void gfar_set_parse_bits(u32 value, u32 mask, struct filer_table *tab)
  724. {
  725. gfar_set_mask(mask, tab);
  726. tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_PID_PARSE
  727. | RQFCR_AND;
  728. tab->fe[tab->index].prop = value;
  729. tab->index++;
  730. }
  731. static void gfar_set_general_attribute(u32 value, u32 mask, u32 flag,
  732. struct filer_table *tab)
  733. {
  734. gfar_set_mask(mask, tab);
  735. tab->fe[tab->index].ctrl = RQFCR_CMP_EXACT | RQFCR_AND | flag;
  736. tab->fe[tab->index].prop = value;
  737. tab->index++;
  738. }
  739. /*
  740. * For setting a tuple of value and mask of type flag
  741. * Example:
  742. * IP-Src = 10.0.0.0/255.0.0.0
  743. * value: 0x0A000000 mask: FF000000 flag: RQFPR_IPV4
  744. *
  745. * Ethtool gives us a value=0 and mask=~0 for don't care a tuple
  746. * For a don't care mask it gives us a 0
  747. *
  748. * The check if don't care and the mask adjustment if mask=0 is done for VLAN
  749. * and MAC stuff on an upper level (due to missing information on this level).
  750. * For these guys we can discard them if they are value=0 and mask=0.
  751. *
  752. * Further the all masks are one-padded for better hardware efficiency.
  753. */
  754. static void gfar_set_attribute(u32 value, u32 mask, u32 flag,
  755. struct filer_table *tab)
  756. {
  757. switch (flag) {
  758. /* 3bit */
  759. case RQFCR_PID_PRI:
  760. if (!(value | mask))
  761. return;
  762. mask |= RQFCR_PID_PRI_MASK;
  763. break;
  764. /* 8bit */
  765. case RQFCR_PID_L4P:
  766. case RQFCR_PID_TOS:
  767. if (!~(mask | RQFCR_PID_L4P_MASK))
  768. return;
  769. if (!mask)
  770. mask = ~0;
  771. else
  772. mask |= RQFCR_PID_L4P_MASK;
  773. break;
  774. /* 12bit */
  775. case RQFCR_PID_VID:
  776. if (!(value | mask))
  777. return;
  778. mask |= RQFCR_PID_VID_MASK;
  779. break;
  780. /* 16bit */
  781. case RQFCR_PID_DPT:
  782. case RQFCR_PID_SPT:
  783. case RQFCR_PID_ETY:
  784. if (!~(mask | RQFCR_PID_PORT_MASK))
  785. return;
  786. if (!mask)
  787. mask = ~0;
  788. else
  789. mask |= RQFCR_PID_PORT_MASK;
  790. break;
  791. /* 24bit */
  792. case RQFCR_PID_DAH:
  793. case RQFCR_PID_DAL:
  794. case RQFCR_PID_SAH:
  795. case RQFCR_PID_SAL:
  796. if (!(value | mask))
  797. return;
  798. mask |= RQFCR_PID_MAC_MASK;
  799. break;
  800. /* for all real 32bit masks */
  801. default:
  802. if (!~mask)
  803. return;
  804. if (!mask)
  805. mask = ~0;
  806. break;
  807. }
  808. gfar_set_general_attribute(value, mask, flag, tab);
  809. }
  810. /* Translates value and mask for UDP, TCP or SCTP */
  811. static void gfar_set_basic_ip(struct ethtool_tcpip4_spec *value,
  812. struct ethtool_tcpip4_spec *mask, struct filer_table *tab)
  813. {
  814. gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab);
  815. gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab);
  816. gfar_set_attribute(value->pdst, mask->pdst, RQFCR_PID_DPT, tab);
  817. gfar_set_attribute(value->psrc, mask->psrc, RQFCR_PID_SPT, tab);
  818. gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab);
  819. }
  820. /* Translates value and mask for RAW-IP4 */
  821. static void gfar_set_user_ip(struct ethtool_usrip4_spec *value,
  822. struct ethtool_usrip4_spec *mask, struct filer_table *tab)
  823. {
  824. gfar_set_attribute(value->ip4src, mask->ip4src, RQFCR_PID_SIA, tab);
  825. gfar_set_attribute(value->ip4dst, mask->ip4dst, RQFCR_PID_DIA, tab);
  826. gfar_set_attribute(value->tos, mask->tos, RQFCR_PID_TOS, tab);
  827. gfar_set_attribute(value->proto, mask->proto, RQFCR_PID_L4P, tab);
  828. gfar_set_attribute(value->l4_4_bytes, mask->l4_4_bytes, RQFCR_PID_ARB,
  829. tab);
  830. }
  831. /* Translates value and mask for ETHER spec */
  832. static void gfar_set_ether(struct ethhdr *value, struct ethhdr *mask,
  833. struct filer_table *tab)
  834. {
  835. u32 upper_temp_mask = 0;
  836. u32 lower_temp_mask = 0;
  837. /* Source address */
  838. if (!is_broadcast_ether_addr(mask->h_source)) {
  839. if (is_zero_ether_addr(mask->h_source)) {
  840. upper_temp_mask = 0xFFFFFFFF;
  841. lower_temp_mask = 0xFFFFFFFF;
  842. } else {
  843. upper_temp_mask = mask->h_source[0] << 16
  844. | mask->h_source[1] << 8
  845. | mask->h_source[2];
  846. lower_temp_mask = mask->h_source[3] << 16
  847. | mask->h_source[4] << 8
  848. | mask->h_source[5];
  849. }
  850. /* Upper 24bit */
  851. gfar_set_attribute(
  852. value->h_source[0] << 16 | value->h_source[1]
  853. << 8 | value->h_source[2],
  854. upper_temp_mask, RQFCR_PID_SAH, tab);
  855. /* And the same for the lower part */
  856. gfar_set_attribute(
  857. value->h_source[3] << 16 | value->h_source[4]
  858. << 8 | value->h_source[5],
  859. lower_temp_mask, RQFCR_PID_SAL, tab);
  860. }
  861. /* Destination address */
  862. if (!is_broadcast_ether_addr(mask->h_dest)) {
  863. /* Special for destination is limited broadcast */
  864. if ((is_broadcast_ether_addr(value->h_dest)
  865. && is_zero_ether_addr(mask->h_dest))) {
  866. gfar_set_parse_bits(RQFPR_EBC, RQFPR_EBC, tab);
  867. } else {
  868. if (is_zero_ether_addr(mask->h_dest)) {
  869. upper_temp_mask = 0xFFFFFFFF;
  870. lower_temp_mask = 0xFFFFFFFF;
  871. } else {
  872. upper_temp_mask = mask->h_dest[0] << 16
  873. | mask->h_dest[1] << 8
  874. | mask->h_dest[2];
  875. lower_temp_mask = mask->h_dest[3] << 16
  876. | mask->h_dest[4] << 8
  877. | mask->h_dest[5];
  878. }
  879. /* Upper 24bit */
  880. gfar_set_attribute(
  881. value->h_dest[0] << 16
  882. | value->h_dest[1] << 8
  883. | value->h_dest[2],
  884. upper_temp_mask, RQFCR_PID_DAH, tab);
  885. /* And the same for the lower part */
  886. gfar_set_attribute(
  887. value->h_dest[3] << 16
  888. | value->h_dest[4] << 8
  889. | value->h_dest[5],
  890. lower_temp_mask, RQFCR_PID_DAL, tab);
  891. }
  892. }
  893. gfar_set_attribute(value->h_proto, mask->h_proto, RQFCR_PID_ETY, tab);
  894. }
  895. /* Convert a rule to binary filter format of gianfar */
  896. static int gfar_convert_to_filer(struct ethtool_rx_flow_spec *rule,
  897. struct filer_table *tab)
  898. {
  899. u32 vlan = 0, vlan_mask = 0;
  900. u32 id = 0, id_mask = 0;
  901. u32 cfi = 0, cfi_mask = 0;
  902. u32 prio = 0, prio_mask = 0;
  903. u32 old_index = tab->index;
  904. /* Check if vlan is wanted */
  905. if ((rule->flow_type & FLOW_EXT) && (rule->m_ext.vlan_tci != 0xFFFF)) {
  906. if (!rule->m_ext.vlan_tci)
  907. rule->m_ext.vlan_tci = 0xFFFF;
  908. vlan = RQFPR_VLN;
  909. vlan_mask = RQFPR_VLN;
  910. /* Separate the fields */
  911. id = rule->h_ext.vlan_tci & VLAN_VID_MASK;
  912. id_mask = rule->m_ext.vlan_tci & VLAN_VID_MASK;
  913. cfi = rule->h_ext.vlan_tci & VLAN_CFI_MASK;
  914. cfi_mask = rule->m_ext.vlan_tci & VLAN_CFI_MASK;
  915. prio = (rule->h_ext.vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  916. prio_mask = (rule->m_ext.vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  917. if (cfi == VLAN_TAG_PRESENT && cfi_mask == VLAN_TAG_PRESENT) {
  918. vlan |= RQFPR_CFI;
  919. vlan_mask |= RQFPR_CFI;
  920. } else if (cfi != VLAN_TAG_PRESENT && cfi_mask == VLAN_TAG_PRESENT) {
  921. vlan_mask |= RQFPR_CFI;
  922. }
  923. }
  924. switch (rule->flow_type & ~FLOW_EXT) {
  925. case TCP_V4_FLOW:
  926. gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_TCP | vlan,
  927. RQFPR_IPV4 | RQFPR_TCP | vlan_mask, tab);
  928. gfar_set_basic_ip(&rule->h_u.tcp_ip4_spec,
  929. &rule->m_u.tcp_ip4_spec, tab);
  930. break;
  931. case UDP_V4_FLOW:
  932. gfar_set_parse_bits(RQFPR_IPV4 | RQFPR_UDP | vlan,
  933. RQFPR_IPV4 | RQFPR_UDP | vlan_mask, tab);
  934. gfar_set_basic_ip(&rule->h_u.udp_ip4_spec,
  935. &rule->m_u.udp_ip4_spec, tab);
  936. break;
  937. case SCTP_V4_FLOW:
  938. gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask,
  939. tab);
  940. gfar_set_attribute(132, 0, RQFCR_PID_L4P, tab);
  941. gfar_set_basic_ip((struct ethtool_tcpip4_spec *) &rule->h_u,
  942. (struct ethtool_tcpip4_spec *) &rule->m_u, tab);
  943. break;
  944. case IP_USER_FLOW:
  945. gfar_set_parse_bits(RQFPR_IPV4 | vlan, RQFPR_IPV4 | vlan_mask,
  946. tab);
  947. gfar_set_user_ip((struct ethtool_usrip4_spec *) &rule->h_u,
  948. (struct ethtool_usrip4_spec *) &rule->m_u, tab);
  949. break;
  950. case ETHER_FLOW:
  951. if (vlan)
  952. gfar_set_parse_bits(vlan, vlan_mask, tab);
  953. gfar_set_ether((struct ethhdr *) &rule->h_u,
  954. (struct ethhdr *) &rule->m_u, tab);
  955. break;
  956. default:
  957. return -1;
  958. }
  959. /* Set the vlan attributes in the end */
  960. if (vlan) {
  961. gfar_set_attribute(id, id_mask, RQFCR_PID_VID, tab);
  962. gfar_set_attribute(prio, prio_mask, RQFCR_PID_PRI, tab);
  963. }
  964. /* If there has been nothing written till now, it must be a default */
  965. if (tab->index == old_index) {
  966. gfar_set_mask(0xFFFFFFFF, tab);
  967. tab->fe[tab->index].ctrl = 0x20;
  968. tab->fe[tab->index].prop = 0x0;
  969. tab->index++;
  970. }
  971. /* Remove last AND */
  972. tab->fe[tab->index - 1].ctrl &= (~RQFCR_AND);
  973. /* Specify which queue to use or to drop */
  974. if (rule->ring_cookie == RX_CLS_FLOW_DISC)
  975. tab->fe[tab->index - 1].ctrl |= RQFCR_RJE;
  976. else
  977. tab->fe[tab->index - 1].ctrl |= (rule->ring_cookie << 10);
  978. /* Only big enough entries can be clustered */
  979. if (tab->index > (old_index + 2)) {
  980. tab->fe[old_index + 1].ctrl |= RQFCR_CLE;
  981. tab->fe[tab->index - 1].ctrl |= RQFCR_CLE;
  982. }
  983. /* In rare cases the cache can be full while there is free space in hw */
  984. if (tab->index > MAX_FILER_CACHE_IDX - 1)
  985. return -EBUSY;
  986. return 0;
  987. }
  988. /* Copy size filer entries */
  989. static void gfar_copy_filer_entries(struct gfar_filer_entry dst[0],
  990. struct gfar_filer_entry src[0], s32 size)
  991. {
  992. while (size > 0) {
  993. size--;
  994. dst[size].ctrl = src[size].ctrl;
  995. dst[size].prop = src[size].prop;
  996. }
  997. }
  998. /* Delete the contents of the filer-table between start and end
  999. * and collapse them */
  1000. static int gfar_trim_filer_entries(u32 begin, u32 end, struct filer_table *tab)
  1001. {
  1002. int length;
  1003. if (end > MAX_FILER_CACHE_IDX || end < begin)
  1004. return -EINVAL;
  1005. end++;
  1006. length = end - begin;
  1007. /* Copy */
  1008. while (end < tab->index) {
  1009. tab->fe[begin].ctrl = tab->fe[end].ctrl;
  1010. tab->fe[begin++].prop = tab->fe[end++].prop;
  1011. }
  1012. /* Fill up with don't cares */
  1013. while (begin < tab->index) {
  1014. tab->fe[begin].ctrl = 0x60;
  1015. tab->fe[begin].prop = 0xFFFFFFFF;
  1016. begin++;
  1017. }
  1018. tab->index -= length;
  1019. return 0;
  1020. }
  1021. /* Make space on the wanted location */
  1022. static int gfar_expand_filer_entries(u32 begin, u32 length,
  1023. struct filer_table *tab)
  1024. {
  1025. if (length == 0 || length + tab->index > MAX_FILER_CACHE_IDX || begin
  1026. > MAX_FILER_CACHE_IDX)
  1027. return -EINVAL;
  1028. gfar_copy_filer_entries(&(tab->fe[begin + length]), &(tab->fe[begin]),
  1029. tab->index - length + 1);
  1030. tab->index += length;
  1031. return 0;
  1032. }
  1033. static int gfar_get_next_cluster_start(int start, struct filer_table *tab)
  1034. {
  1035. for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1); start++) {
  1036. if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE))
  1037. == (RQFCR_AND | RQFCR_CLE))
  1038. return start;
  1039. }
  1040. return -1;
  1041. }
  1042. static int gfar_get_next_cluster_end(int start, struct filer_table *tab)
  1043. {
  1044. for (; (start < tab->index) && (start < MAX_FILER_CACHE_IDX - 1); start++) {
  1045. if ((tab->fe[start].ctrl & (RQFCR_AND | RQFCR_CLE))
  1046. == (RQFCR_CLE))
  1047. return start;
  1048. }
  1049. return -1;
  1050. }
  1051. /*
  1052. * Uses hardwares clustering option to reduce
  1053. * the number of filer table entries
  1054. */
  1055. static void gfar_cluster_filer(struct filer_table *tab)
  1056. {
  1057. s32 i = -1, j, iend, jend;
  1058. while ((i = gfar_get_next_cluster_start(++i, tab)) != -1) {
  1059. j = i;
  1060. while ((j = gfar_get_next_cluster_start(++j, tab)) != -1) {
  1061. /*
  1062. * The cluster entries self and the previous one
  1063. * (a mask) must be identical!
  1064. */
  1065. if (tab->fe[i].ctrl != tab->fe[j].ctrl)
  1066. break;
  1067. if (tab->fe[i].prop != tab->fe[j].prop)
  1068. break;
  1069. if (tab->fe[i - 1].ctrl != tab->fe[j - 1].ctrl)
  1070. break;
  1071. if (tab->fe[i - 1].prop != tab->fe[j - 1].prop)
  1072. break;
  1073. iend = gfar_get_next_cluster_end(i, tab);
  1074. jend = gfar_get_next_cluster_end(j, tab);
  1075. if (jend == -1 || iend == -1)
  1076. break;
  1077. /*
  1078. * First we make some free space, where our cluster
  1079. * element should be. Then we copy it there and finally
  1080. * delete in from its old location.
  1081. */
  1082. if (gfar_expand_filer_entries(iend, (jend - j), tab)
  1083. == -EINVAL)
  1084. break;
  1085. gfar_copy_filer_entries(&(tab->fe[iend + 1]),
  1086. &(tab->fe[jend + 1]), jend - j);
  1087. if (gfar_trim_filer_entries(jend - 1,
  1088. jend + (jend - j), tab) == -EINVAL)
  1089. return;
  1090. /* Mask out cluster bit */
  1091. tab->fe[iend].ctrl &= ~(RQFCR_CLE);
  1092. }
  1093. }
  1094. }
  1095. /* Swaps the masked bits of a1<>a2 and b1<>b2 */
  1096. static void gfar_swap_bits(struct gfar_filer_entry *a1,
  1097. struct gfar_filer_entry *a2, struct gfar_filer_entry *b1,
  1098. struct gfar_filer_entry *b2, u32 mask)
  1099. {
  1100. u32 temp[4];
  1101. temp[0] = a1->ctrl & mask;
  1102. temp[1] = a2->ctrl & mask;
  1103. temp[2] = b1->ctrl & mask;
  1104. temp[3] = b2->ctrl & mask;
  1105. a1->ctrl &= ~mask;
  1106. a2->ctrl &= ~mask;
  1107. b1->ctrl &= ~mask;
  1108. b2->ctrl &= ~mask;
  1109. a1->ctrl |= temp[1];
  1110. a2->ctrl |= temp[0];
  1111. b1->ctrl |= temp[3];
  1112. b2->ctrl |= temp[2];
  1113. }
  1114. /*
  1115. * Generate a list consisting of masks values with their start and
  1116. * end of validity and block as indicator for parts belonging
  1117. * together (glued by ANDs) in mask_table
  1118. */
  1119. static u32 gfar_generate_mask_table(struct gfar_mask_entry *mask_table,
  1120. struct filer_table *tab)
  1121. {
  1122. u32 i, and_index = 0, block_index = 1;
  1123. for (i = 0; i < tab->index; i++) {
  1124. /* LSByte of control = 0 sets a mask */
  1125. if (!(tab->fe[i].ctrl & 0xF)) {
  1126. mask_table[and_index].mask = tab->fe[i].prop;
  1127. mask_table[and_index].start = i;
  1128. mask_table[and_index].block = block_index;
  1129. if (and_index >= 1)
  1130. mask_table[and_index - 1].end = i - 1;
  1131. and_index++;
  1132. }
  1133. /* cluster starts and ends will be separated because they should
  1134. * hold their position */
  1135. if (tab->fe[i].ctrl & RQFCR_CLE)
  1136. block_index++;
  1137. /* A not set AND indicates the end of a depended block */
  1138. if (!(tab->fe[i].ctrl & RQFCR_AND))
  1139. block_index++;
  1140. }
  1141. mask_table[and_index - 1].end = i - 1;
  1142. return and_index;
  1143. }
  1144. /*
  1145. * Sorts the entries of mask_table by the values of the masks.
  1146. * Important: The 0xFF80 flags of the first and last entry of a
  1147. * block must hold their position (which queue, CLusterEnable, ReJEct,
  1148. * AND)
  1149. */
  1150. static void gfar_sort_mask_table(struct gfar_mask_entry *mask_table,
  1151. struct filer_table *temp_table, u32 and_index)
  1152. {
  1153. /* Pointer to compare function (_asc or _desc) */
  1154. int (*gfar_comp)(const void *, const void *);
  1155. u32 i, size = 0, start = 0, prev = 1;
  1156. u32 old_first, old_last, new_first, new_last;
  1157. gfar_comp = &gfar_comp_desc;
  1158. for (i = 0; i < and_index; i++) {
  1159. if (prev != mask_table[i].block) {
  1160. old_first = mask_table[start].start + 1;
  1161. old_last = mask_table[i - 1].end;
  1162. sort(mask_table + start, size,
  1163. sizeof(struct gfar_mask_entry),
  1164. gfar_comp, &gfar_swap);
  1165. /* Toggle order for every block. This makes the
  1166. * thing more efficient! */
  1167. if (gfar_comp == gfar_comp_desc)
  1168. gfar_comp = &gfar_comp_asc;
  1169. else
  1170. gfar_comp = &gfar_comp_desc;
  1171. new_first = mask_table[start].start + 1;
  1172. new_last = mask_table[i - 1].end;
  1173. gfar_swap_bits(&temp_table->fe[new_first],
  1174. &temp_table->fe[old_first],
  1175. &temp_table->fe[new_last],
  1176. &temp_table->fe[old_last],
  1177. RQFCR_QUEUE | RQFCR_CLE |
  1178. RQFCR_RJE | RQFCR_AND
  1179. );
  1180. start = i;
  1181. size = 0;
  1182. }
  1183. size++;
  1184. prev = mask_table[i].block;
  1185. }
  1186. }
  1187. /*
  1188. * Reduces the number of masks needed in the filer table to save entries
  1189. * This is done by sorting the masks of a depended block. A depended block is
  1190. * identified by gluing ANDs or CLE. The sorting order toggles after every
  1191. * block. Of course entries in scope of a mask must change their location with
  1192. * it.
  1193. */
  1194. static int gfar_optimize_filer_masks(struct filer_table *tab)
  1195. {
  1196. struct filer_table *temp_table;
  1197. struct gfar_mask_entry *mask_table;
  1198. u32 and_index = 0, previous_mask = 0, i = 0, j = 0, size = 0;
  1199. s32 ret = 0;
  1200. /* We need a copy of the filer table because
  1201. * we want to change its order */
  1202. temp_table = kmalloc(sizeof(*temp_table), GFP_KERNEL);
  1203. if (temp_table == NULL)
  1204. return -ENOMEM;
  1205. memcpy(temp_table, tab, sizeof(*temp_table));
  1206. mask_table = kcalloc(MAX_FILER_CACHE_IDX / 2 + 1,
  1207. sizeof(struct gfar_mask_entry), GFP_KERNEL);
  1208. if (mask_table == NULL) {
  1209. ret = -ENOMEM;
  1210. goto end;
  1211. }
  1212. and_index = gfar_generate_mask_table(mask_table, tab);
  1213. gfar_sort_mask_table(mask_table, temp_table, and_index);
  1214. /* Now we can copy the data from our duplicated filer table to
  1215. * the real one in the order the mask table says */
  1216. for (i = 0; i < and_index; i++) {
  1217. size = mask_table[i].end - mask_table[i].start + 1;
  1218. gfar_copy_filer_entries(&(tab->fe[j]),
  1219. &(temp_table->fe[mask_table[i].start]), size);
  1220. j += size;
  1221. }
  1222. /* And finally we just have to check for duplicated masks and drop the
  1223. * second ones */
  1224. for (i = 0; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) {
  1225. if (tab->fe[i].ctrl == 0x80) {
  1226. previous_mask = i++;
  1227. break;
  1228. }
  1229. }
  1230. for (; i < tab->index && i < MAX_FILER_CACHE_IDX; i++) {
  1231. if (tab->fe[i].ctrl == 0x80) {
  1232. if (tab->fe[i].prop == tab->fe[previous_mask].prop) {
  1233. /* Two identical ones found!
  1234. * So drop the second one! */
  1235. gfar_trim_filer_entries(i, i, tab);
  1236. } else
  1237. /* Not identical! */
  1238. previous_mask = i;
  1239. }
  1240. }
  1241. kfree(mask_table);
  1242. end: kfree(temp_table);
  1243. return ret;
  1244. }
  1245. /* Write the bit-pattern from software's buffer to hardware registers */
  1246. static int gfar_write_filer_table(struct gfar_private *priv,
  1247. struct filer_table *tab)
  1248. {
  1249. u32 i = 0;
  1250. if (tab->index > MAX_FILER_IDX - 1)
  1251. return -EBUSY;
  1252. /* Avoid inconsistent filer table to be processed */
  1253. lock_rx_qs(priv);
  1254. /* Fill regular entries */
  1255. for (; i < MAX_FILER_IDX - 1 && (tab->fe[i].ctrl | tab->fe[i].ctrl); i++)
  1256. gfar_write_filer(priv, i, tab->fe[i].ctrl, tab->fe[i].prop);
  1257. /* Fill the rest with fall-troughs */
  1258. for (; i < MAX_FILER_IDX - 1; i++)
  1259. gfar_write_filer(priv, i, 0x60, 0xFFFFFFFF);
  1260. /* Last entry must be default accept
  1261. * because that's what people expect */
  1262. gfar_write_filer(priv, i, 0x20, 0x0);
  1263. unlock_rx_qs(priv);
  1264. return 0;
  1265. }
  1266. static int gfar_check_capability(struct ethtool_rx_flow_spec *flow,
  1267. struct gfar_private *priv)
  1268. {
  1269. if (flow->flow_type & FLOW_EXT) {
  1270. if (~flow->m_ext.data[0] || ~flow->m_ext.data[1])
  1271. netdev_warn(priv->ndev,
  1272. "User-specific data not supported!\n");
  1273. if (~flow->m_ext.vlan_etype)
  1274. netdev_warn(priv->ndev,
  1275. "VLAN-etype not supported!\n");
  1276. }
  1277. if (flow->flow_type == IP_USER_FLOW)
  1278. if (flow->h_u.usr_ip4_spec.ip_ver != ETH_RX_NFC_IP4)
  1279. netdev_warn(priv->ndev,
  1280. "IP-Version differing from IPv4 not supported!\n");
  1281. return 0;
  1282. }
  1283. static int gfar_process_filer_changes(struct gfar_private *priv)
  1284. {
  1285. struct ethtool_flow_spec_container *j;
  1286. struct filer_table *tab;
  1287. s32 i = 0;
  1288. s32 ret = 0;
  1289. /* So index is set to zero, too! */
  1290. tab = kzalloc(sizeof(*tab), GFP_KERNEL);
  1291. if (tab == NULL)
  1292. return -ENOMEM;
  1293. /* Now convert the existing filer data from flow_spec into
  1294. * filer tables binary format */
  1295. list_for_each_entry(j, &priv->rx_list.list, list) {
  1296. ret = gfar_convert_to_filer(&j->fs, tab);
  1297. if (ret == -EBUSY) {
  1298. netdev_err(priv->ndev, "Rule not added: No free space!\n");
  1299. goto end;
  1300. }
  1301. if (ret == -1) {
  1302. netdev_err(priv->ndev, "Rule not added: Unsupported Flow-type!\n");
  1303. goto end;
  1304. }
  1305. }
  1306. i = tab->index;
  1307. /* Optimizations to save entries */
  1308. gfar_cluster_filer(tab);
  1309. gfar_optimize_filer_masks(tab);
  1310. pr_debug("\n\tSummary:\n"
  1311. "\tData on hardware: %d\n"
  1312. "\tCompression rate: %d%%\n",
  1313. tab->index, 100 - (100 * tab->index) / i);
  1314. /* Write everything to hardware */
  1315. ret = gfar_write_filer_table(priv, tab);
  1316. if (ret == -EBUSY) {
  1317. netdev_err(priv->ndev, "Rule not added: No free space!\n");
  1318. goto end;
  1319. }
  1320. end: kfree(tab);
  1321. return ret;
  1322. }
  1323. static void gfar_invert_masks(struct ethtool_rx_flow_spec *flow)
  1324. {
  1325. u32 i = 0;
  1326. for (i = 0; i < sizeof(flow->m_u); i++)
  1327. flow->m_u.hdata[i] ^= 0xFF;
  1328. flow->m_ext.vlan_etype ^= 0xFFFF;
  1329. flow->m_ext.vlan_tci ^= 0xFFFF;
  1330. flow->m_ext.data[0] ^= ~0;
  1331. flow->m_ext.data[1] ^= ~0;
  1332. }
  1333. static int gfar_add_cls(struct gfar_private *priv,
  1334. struct ethtool_rx_flow_spec *flow)
  1335. {
  1336. struct ethtool_flow_spec_container *temp, *comp;
  1337. int ret = 0;
  1338. temp = kmalloc(sizeof(*temp), GFP_KERNEL);
  1339. if (temp == NULL)
  1340. return -ENOMEM;
  1341. memcpy(&temp->fs, flow, sizeof(temp->fs));
  1342. gfar_invert_masks(&temp->fs);
  1343. ret = gfar_check_capability(&temp->fs, priv);
  1344. if (ret)
  1345. goto clean_mem;
  1346. /* Link in the new element at the right @location */
  1347. if (list_empty(&priv->rx_list.list)) {
  1348. ret = gfar_check_filer_hardware(priv);
  1349. if (ret != 0)
  1350. goto clean_mem;
  1351. list_add(&temp->list, &priv->rx_list.list);
  1352. goto process;
  1353. } else {
  1354. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1355. if (comp->fs.location > flow->location) {
  1356. list_add_tail(&temp->list, &comp->list);
  1357. goto process;
  1358. }
  1359. if (comp->fs.location == flow->location) {
  1360. netdev_err(priv->ndev,
  1361. "Rule not added: ID %d not free!\n",
  1362. flow->location);
  1363. ret = -EBUSY;
  1364. goto clean_mem;
  1365. }
  1366. }
  1367. list_add_tail(&temp->list, &priv->rx_list.list);
  1368. }
  1369. process:
  1370. ret = gfar_process_filer_changes(priv);
  1371. if (ret)
  1372. goto clean_list;
  1373. priv->rx_list.count++;
  1374. return ret;
  1375. clean_list:
  1376. list_del(&temp->list);
  1377. clean_mem:
  1378. kfree(temp);
  1379. return ret;
  1380. }
  1381. static int gfar_del_cls(struct gfar_private *priv, u32 loc)
  1382. {
  1383. struct ethtool_flow_spec_container *comp;
  1384. u32 ret = -EINVAL;
  1385. if (list_empty(&priv->rx_list.list))
  1386. return ret;
  1387. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1388. if (comp->fs.location == loc) {
  1389. list_del(&comp->list);
  1390. kfree(comp);
  1391. priv->rx_list.count--;
  1392. gfar_process_filer_changes(priv);
  1393. ret = 0;
  1394. break;
  1395. }
  1396. }
  1397. return ret;
  1398. }
  1399. static int gfar_get_cls(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
  1400. {
  1401. struct ethtool_flow_spec_container *comp;
  1402. u32 ret = -EINVAL;
  1403. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1404. if (comp->fs.location == cmd->fs.location) {
  1405. memcpy(&cmd->fs, &comp->fs, sizeof(cmd->fs));
  1406. gfar_invert_masks(&cmd->fs);
  1407. ret = 0;
  1408. break;
  1409. }
  1410. }
  1411. return ret;
  1412. }
  1413. static int gfar_get_cls_all(struct gfar_private *priv,
  1414. struct ethtool_rxnfc *cmd, u32 *rule_locs)
  1415. {
  1416. struct ethtool_flow_spec_container *comp;
  1417. u32 i = 0;
  1418. list_for_each_entry(comp, &priv->rx_list.list, list) {
  1419. if (i <= cmd->rule_cnt) {
  1420. rule_locs[i] = comp->fs.location;
  1421. i++;
  1422. }
  1423. }
  1424. cmd->data = MAX_FILER_IDX;
  1425. return 0;
  1426. }
  1427. static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  1428. {
  1429. struct gfar_private *priv = netdev_priv(dev);
  1430. int ret = 0;
  1431. mutex_lock(&priv->rx_queue_access);
  1432. switch (cmd->cmd) {
  1433. case ETHTOOL_SRXFH:
  1434. ret = gfar_set_hash_opts(priv, cmd);
  1435. break;
  1436. case ETHTOOL_SRXCLSRLINS:
  1437. if (cmd->fs.ring_cookie != RX_CLS_FLOW_DISC &&
  1438. cmd->fs.ring_cookie >= priv->num_rx_queues) {
  1439. ret = -EINVAL;
  1440. break;
  1441. }
  1442. ret = gfar_add_cls(priv, &cmd->fs);
  1443. break;
  1444. case ETHTOOL_SRXCLSRLDEL:
  1445. ret = gfar_del_cls(priv, cmd->fs.location);
  1446. break;
  1447. default:
  1448. ret = -EINVAL;
  1449. }
  1450. mutex_unlock(&priv->rx_queue_access);
  1451. return ret;
  1452. }
  1453. static int gfar_get_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
  1454. void *rule_locs)
  1455. {
  1456. struct gfar_private *priv = netdev_priv(dev);
  1457. int ret = 0;
  1458. switch (cmd->cmd) {
  1459. case ETHTOOL_GRXRINGS:
  1460. cmd->data = priv->num_rx_queues;
  1461. break;
  1462. case ETHTOOL_GRXCLSRLCNT:
  1463. cmd->rule_cnt = priv->rx_list.count;
  1464. break;
  1465. case ETHTOOL_GRXCLSRULE:
  1466. ret = gfar_get_cls(priv, cmd);
  1467. break;
  1468. case ETHTOOL_GRXCLSRLALL:
  1469. ret = gfar_get_cls_all(priv, cmd, (u32 *) rule_locs);
  1470. break;
  1471. default:
  1472. ret = -EINVAL;
  1473. break;
  1474. }
  1475. return ret;
  1476. }
  1477. const struct ethtool_ops gfar_ethtool_ops = {
  1478. .get_settings = gfar_gsettings,
  1479. .set_settings = gfar_ssettings,
  1480. .get_drvinfo = gfar_gdrvinfo,
  1481. .get_regs_len = gfar_reglen,
  1482. .get_regs = gfar_get_regs,
  1483. .get_link = ethtool_op_get_link,
  1484. .get_coalesce = gfar_gcoalesce,
  1485. .set_coalesce = gfar_scoalesce,
  1486. .get_ringparam = gfar_gringparam,
  1487. .set_ringparam = gfar_sringparam,
  1488. .get_strings = gfar_gstrings,
  1489. .get_sset_count = gfar_sset_count,
  1490. .get_ethtool_stats = gfar_fill_stats,
  1491. .get_msglevel = gfar_get_msglevel,
  1492. .set_msglevel = gfar_set_msglevel,
  1493. #ifdef CONFIG_PM
  1494. .get_wol = gfar_get_wol,
  1495. .set_wol = gfar_set_wol,
  1496. #endif
  1497. .set_rxnfc = gfar_set_nfc,
  1498. .get_rxnfc = gfar_get_nfc,
  1499. };