gianfar_ethtool.c 46 KB

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