gianfar_ethtool.c 47 KB

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