gianfar_ethtool.c 45 KB

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