gianfar_ethtool.c 47 KB

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