gianfar_ethtool.c 47 KB

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