gianfar_ethtool.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*
  2. * drivers/net/gianfar_ethtool.c
  3. *
  4. * Gianfar Ethernet Driver
  5. * Ethtool support for Gianfar Enet
  6. * Based on e1000 ethtool support
  7. *
  8. * Author: Andy Fleming
  9. * Maintainer: Kumar Gala
  10. * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
  11. *
  12. * Copyright 2003-2006, 2008-2009 Freescale Semiconductor, Inc.
  13. *
  14. * This software may be used and distributed according to
  15. * the terms of the GNU Public License, Version 2, incorporated herein
  16. * by reference.
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/kernel.h>
  20. #include <linux/string.h>
  21. #include <linux/errno.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/init.h>
  24. #include <linux/delay.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/skbuff.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/mm.h>
  30. #include <asm/io.h>
  31. #include <asm/irq.h>
  32. #include <asm/uaccess.h>
  33. #include <linux/module.h>
  34. #include <linux/crc32.h>
  35. #include <asm/types.h>
  36. #include <linux/ethtool.h>
  37. #include <linux/mii.h>
  38. #include <linux/phy.h>
  39. #include "gianfar.h"
  40. extern void gfar_start(struct net_device *dev);
  41. extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit);
  42. #define GFAR_MAX_COAL_USECS 0xffff
  43. #define GFAR_MAX_COAL_FRAMES 0xff
  44. static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy,
  45. u64 * buf);
  46. static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf);
  47. static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
  48. static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals);
  49. static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
  50. static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals);
  51. static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo);
  52. static char stat_gstrings[][ETH_GSTRING_LEN] = {
  53. "rx-dropped-by-kernel",
  54. "rx-large-frame-errors",
  55. "rx-short-frame-errors",
  56. "rx-non-octet-errors",
  57. "rx-crc-errors",
  58. "rx-overrun-errors",
  59. "rx-busy-errors",
  60. "rx-babbling-errors",
  61. "rx-truncated-frames",
  62. "ethernet-bus-error",
  63. "tx-babbling-errors",
  64. "tx-underrun-errors",
  65. "rx-skb-missing-errors",
  66. "tx-timeout-errors",
  67. "tx-rx-64-frames",
  68. "tx-rx-65-127-frames",
  69. "tx-rx-128-255-frames",
  70. "tx-rx-256-511-frames",
  71. "tx-rx-512-1023-frames",
  72. "tx-rx-1024-1518-frames",
  73. "tx-rx-1519-1522-good-vlan",
  74. "rx-bytes",
  75. "rx-packets",
  76. "rx-fcs-errors",
  77. "receive-multicast-packet",
  78. "receive-broadcast-packet",
  79. "rx-control-frame-packets",
  80. "rx-pause-frame-packets",
  81. "rx-unknown-op-code",
  82. "rx-alignment-error",
  83. "rx-frame-length-error",
  84. "rx-code-error",
  85. "rx-carrier-sense-error",
  86. "rx-undersize-packets",
  87. "rx-oversize-packets",
  88. "rx-fragmented-frames",
  89. "rx-jabber-frames",
  90. "rx-dropped-frames",
  91. "tx-byte-counter",
  92. "tx-packets",
  93. "tx-multicast-packets",
  94. "tx-broadcast-packets",
  95. "tx-pause-control-frames",
  96. "tx-deferral-packets",
  97. "tx-excessive-deferral-packets",
  98. "tx-single-collision-packets",
  99. "tx-multiple-collision-packets",
  100. "tx-late-collision-packets",
  101. "tx-excessive-collision-packets",
  102. "tx-total-collision",
  103. "reserved",
  104. "tx-dropped-frames",
  105. "tx-jabber-frames",
  106. "tx-fcs-errors",
  107. "tx-control-frames",
  108. "tx-oversize-frames",
  109. "tx-undersize-frames",
  110. "tx-fragmented-frames",
  111. };
  112. /* Fill in a buffer with the strings which correspond to the
  113. * stats */
  114. static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf)
  115. {
  116. struct gfar_private *priv = netdev_priv(dev);
  117. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
  118. memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN);
  119. else
  120. memcpy(buf, stat_gstrings,
  121. GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN);
  122. }
  123. /* Fill in an array of 64-bit statistics from various sources.
  124. * This array will be appended to the end of the ethtool_stats
  125. * structure, and returned to user space
  126. */
  127. static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf)
  128. {
  129. int i;
  130. struct gfar_private *priv = netdev_priv(dev);
  131. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  132. u64 *extra = (u64 *) & priv->extra_stats;
  133. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) {
  134. u32 __iomem *rmon = (u32 __iomem *) &regs->rmon;
  135. struct gfar_stats *stats = (struct gfar_stats *) buf;
  136. for (i = 0; i < GFAR_RMON_LEN; i++)
  137. stats->rmon[i] = (u64) gfar_read(&rmon[i]);
  138. for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
  139. stats->extra[i] = extra[i];
  140. } else
  141. for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++)
  142. buf[i] = extra[i];
  143. }
  144. static int gfar_sset_count(struct net_device *dev, int sset)
  145. {
  146. struct gfar_private *priv = netdev_priv(dev);
  147. switch (sset) {
  148. case ETH_SS_STATS:
  149. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON)
  150. return GFAR_STATS_LEN;
  151. else
  152. return GFAR_EXTRA_STATS_LEN;
  153. default:
  154. return -EOPNOTSUPP;
  155. }
  156. }
  157. /* Fills in the drvinfo structure with some basic info */
  158. static void gfar_gdrvinfo(struct net_device *dev, struct
  159. ethtool_drvinfo *drvinfo)
  160. {
  161. strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN);
  162. strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN);
  163. strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN);
  164. strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN);
  165. drvinfo->regdump_len = 0;
  166. drvinfo->eedump_len = 0;
  167. }
  168. static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd)
  169. {
  170. struct gfar_private *priv = netdev_priv(dev);
  171. struct phy_device *phydev = priv->phydev;
  172. if (NULL == phydev)
  173. return -ENODEV;
  174. return phy_ethtool_sset(phydev, cmd);
  175. }
  176. /* Return the current settings in the ethtool_cmd structure */
  177. static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd)
  178. {
  179. struct gfar_private *priv = netdev_priv(dev);
  180. struct phy_device *phydev = priv->phydev;
  181. struct gfar_priv_rx_q *rx_queue = NULL;
  182. struct gfar_priv_tx_q *tx_queue = NULL;
  183. if (NULL == phydev)
  184. return -ENODEV;
  185. tx_queue = priv->tx_queue[0];
  186. rx_queue = priv->rx_queue[0];
  187. /* etsec-1.7 and older versions have only one txic
  188. * and rxic regs although they support multiple queues */
  189. cmd->maxtxpkt = get_icft_value(tx_queue->txic);
  190. cmd->maxrxpkt = get_icft_value(rx_queue->rxic);
  191. return phy_ethtool_gset(phydev, cmd);
  192. }
  193. /* Return the length of the register structure */
  194. static int gfar_reglen(struct net_device *dev)
  195. {
  196. return sizeof (struct gfar);
  197. }
  198. /* Return a dump of the GFAR register space */
  199. static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
  200. {
  201. int i;
  202. struct gfar_private *priv = netdev_priv(dev);
  203. u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp[0].regs;
  204. u32 *buf = (u32 *) regbuf;
  205. for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++)
  206. buf[i] = gfar_read(&theregs[i]);
  207. }
  208. /* Convert microseconds to ethernet clock ticks, which changes
  209. * depending on what speed the controller is running at */
  210. static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs)
  211. {
  212. unsigned int count;
  213. /* The timer is different, depending on the interface speed */
  214. switch (priv->phydev->speed) {
  215. case SPEED_1000:
  216. count = GFAR_GBIT_TIME;
  217. break;
  218. case SPEED_100:
  219. count = GFAR_100_TIME;
  220. break;
  221. case SPEED_10:
  222. default:
  223. count = GFAR_10_TIME;
  224. break;
  225. }
  226. /* Make sure we return a number greater than 0
  227. * if usecs > 0 */
  228. return (usecs * 1000 + count - 1) / count;
  229. }
  230. /* Convert ethernet clock ticks to microseconds */
  231. static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks)
  232. {
  233. unsigned int count;
  234. /* The timer is different, depending on the interface speed */
  235. switch (priv->phydev->speed) {
  236. case SPEED_1000:
  237. count = GFAR_GBIT_TIME;
  238. break;
  239. case SPEED_100:
  240. count = GFAR_100_TIME;
  241. break;
  242. case SPEED_10:
  243. default:
  244. count = GFAR_10_TIME;
  245. break;
  246. }
  247. /* Make sure we return a number greater than 0 */
  248. /* if ticks is > 0 */
  249. return (ticks * count) / 1000;
  250. }
  251. /* Get the coalescing parameters, and put them in the cvals
  252. * structure. */
  253. static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
  254. {
  255. struct gfar_private *priv = netdev_priv(dev);
  256. struct gfar_priv_rx_q *rx_queue = NULL;
  257. struct gfar_priv_tx_q *tx_queue = NULL;
  258. unsigned long rxtime;
  259. unsigned long rxcount;
  260. unsigned long txtime;
  261. unsigned long txcount;
  262. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
  263. return -EOPNOTSUPP;
  264. if (NULL == priv->phydev)
  265. return -ENODEV;
  266. rx_queue = priv->rx_queue[0];
  267. tx_queue = priv->tx_queue[0];
  268. rxtime = get_ictt_value(rx_queue->rxic);
  269. rxcount = get_icft_value(rx_queue->rxic);
  270. txtime = get_ictt_value(tx_queue->txic);
  271. txcount = get_icft_value(tx_queue->txic);
  272. cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime);
  273. cvals->rx_max_coalesced_frames = rxcount;
  274. cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime);
  275. cvals->tx_max_coalesced_frames = txcount;
  276. cvals->use_adaptive_rx_coalesce = 0;
  277. cvals->use_adaptive_tx_coalesce = 0;
  278. cvals->pkt_rate_low = 0;
  279. cvals->rx_coalesce_usecs_low = 0;
  280. cvals->rx_max_coalesced_frames_low = 0;
  281. cvals->tx_coalesce_usecs_low = 0;
  282. cvals->tx_max_coalesced_frames_low = 0;
  283. /* When the packet rate is below pkt_rate_high but above
  284. * pkt_rate_low (both measured in packets per second) the
  285. * normal {rx,tx}_* coalescing parameters are used.
  286. */
  287. /* When the packet rate is (measured in packets per second)
  288. * is above pkt_rate_high, the {rx,tx}_*_high parameters are
  289. * used.
  290. */
  291. cvals->pkt_rate_high = 0;
  292. cvals->rx_coalesce_usecs_high = 0;
  293. cvals->rx_max_coalesced_frames_high = 0;
  294. cvals->tx_coalesce_usecs_high = 0;
  295. cvals->tx_max_coalesced_frames_high = 0;
  296. /* How often to do adaptive coalescing packet rate sampling,
  297. * measured in seconds. Must not be zero.
  298. */
  299. cvals->rate_sample_interval = 0;
  300. return 0;
  301. }
  302. /* Change the coalescing values.
  303. * Both cvals->*_usecs and cvals->*_frames have to be > 0
  304. * in order for coalescing to be active
  305. */
  306. static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals)
  307. {
  308. struct gfar_private *priv = netdev_priv(dev);
  309. int i = 0;
  310. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE))
  311. return -EOPNOTSUPP;
  312. /* Set up rx coalescing */
  313. /* As of now, we will enable/disable coalescing for all
  314. * queues together in case of eTSEC2, this will be modified
  315. * along with the ethtool interface */
  316. if ((cvals->rx_coalesce_usecs == 0) ||
  317. (cvals->rx_max_coalesced_frames == 0)) {
  318. for (i = 0; i < priv->num_rx_queues; i++)
  319. priv->rx_queue[i]->rxcoalescing = 0;
  320. } else {
  321. for (i = 0; i < priv->num_rx_queues; i++)
  322. priv->rx_queue[i]->rxcoalescing = 1;
  323. }
  324. if (NULL == priv->phydev)
  325. return -ENODEV;
  326. /* Check the bounds of the values */
  327. if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
  328. pr_info("Coalescing is limited to %d microseconds\n",
  329. GFAR_MAX_COAL_USECS);
  330. return -EINVAL;
  331. }
  332. if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
  333. pr_info("Coalescing is limited to %d frames\n",
  334. GFAR_MAX_COAL_FRAMES);
  335. return -EINVAL;
  336. }
  337. for (i = 0; i < priv->num_rx_queues; i++) {
  338. priv->rx_queue[i]->rxic = mk_ic_value(
  339. cvals->rx_max_coalesced_frames,
  340. gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs));
  341. }
  342. /* Set up tx coalescing */
  343. if ((cvals->tx_coalesce_usecs == 0) ||
  344. (cvals->tx_max_coalesced_frames == 0)) {
  345. for (i = 0; i < priv->num_tx_queues; i++)
  346. priv->tx_queue[i]->txcoalescing = 0;
  347. } else {
  348. for (i = 0; i < priv->num_tx_queues; i++)
  349. priv->tx_queue[i]->txcoalescing = 1;
  350. }
  351. /* Check the bounds of the values */
  352. if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) {
  353. pr_info("Coalescing is limited to %d microseconds\n",
  354. GFAR_MAX_COAL_USECS);
  355. return -EINVAL;
  356. }
  357. if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) {
  358. pr_info("Coalescing is limited to %d frames\n",
  359. GFAR_MAX_COAL_FRAMES);
  360. return -EINVAL;
  361. }
  362. for (i = 0; i < priv->num_tx_queues; i++) {
  363. priv->tx_queue[i]->txic = mk_ic_value(
  364. cvals->tx_max_coalesced_frames,
  365. gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs));
  366. }
  367. gfar_configure_coalescing(priv, 0xFF, 0xFF);
  368. return 0;
  369. }
  370. /* Fills in rvals with the current ring parameters. Currently,
  371. * rx, rx_mini, and rx_jumbo rings are the same size, as mini and
  372. * jumbo are ignored by the driver */
  373. static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
  374. {
  375. struct gfar_private *priv = netdev_priv(dev);
  376. struct gfar_priv_tx_q *tx_queue = NULL;
  377. struct gfar_priv_rx_q *rx_queue = NULL;
  378. tx_queue = priv->tx_queue[0];
  379. rx_queue = priv->rx_queue[0];
  380. rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE;
  381. rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE;
  382. rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE;
  383. rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE;
  384. /* Values changeable by the user. The valid values are
  385. * in the range 1 to the "*_max_pending" counterpart above.
  386. */
  387. rvals->rx_pending = rx_queue->rx_ring_size;
  388. rvals->rx_mini_pending = rx_queue->rx_ring_size;
  389. rvals->rx_jumbo_pending = rx_queue->rx_ring_size;
  390. rvals->tx_pending = tx_queue->tx_ring_size;
  391. }
  392. /* Change the current ring parameters, stopping the controller if
  393. * necessary so that we don't mess things up while we're in
  394. * motion. We wait for the ring to be clean before reallocating
  395. * the rings. */
  396. static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals)
  397. {
  398. struct gfar_private *priv = netdev_priv(dev);
  399. int err = 0, i = 0;
  400. if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE)
  401. return -EINVAL;
  402. if (!is_power_of_2(rvals->rx_pending)) {
  403. netdev_err(dev, "Ring sizes must be a power of 2\n");
  404. return -EINVAL;
  405. }
  406. if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
  407. return -EINVAL;
  408. if (!is_power_of_2(rvals->tx_pending)) {
  409. netdev_err(dev, "Ring sizes must be a power of 2\n");
  410. return -EINVAL;
  411. }
  412. if (dev->flags & IFF_UP) {
  413. unsigned long flags;
  414. /* Halt TX and RX, and process the frames which
  415. * have already been received */
  416. local_irq_save(flags);
  417. lock_tx_qs(priv);
  418. lock_rx_qs(priv);
  419. gfar_halt(dev);
  420. unlock_rx_qs(priv);
  421. unlock_tx_qs(priv);
  422. local_irq_restore(flags);
  423. for (i = 0; i < priv->num_rx_queues; i++)
  424. gfar_clean_rx_ring(priv->rx_queue[i],
  425. priv->rx_queue[i]->rx_ring_size);
  426. /* Now we take down the rings to rebuild them */
  427. stop_gfar(dev);
  428. }
  429. /* Change the size */
  430. for (i = 0; i < priv->num_rx_queues; i++) {
  431. priv->rx_queue[i]->rx_ring_size = rvals->rx_pending;
  432. priv->tx_queue[i]->tx_ring_size = rvals->tx_pending;
  433. priv->tx_queue[i]->num_txbdfree = priv->tx_queue[i]->tx_ring_size;
  434. }
  435. /* Rebuild the rings with the new size */
  436. if (dev->flags & IFF_UP) {
  437. err = startup_gfar(dev);
  438. netif_tx_wake_all_queues(dev);
  439. }
  440. return err;
  441. }
  442. int gfar_set_features(struct net_device *dev, u32 features)
  443. {
  444. struct gfar_private *priv = netdev_priv(dev);
  445. unsigned long flags;
  446. int err = 0, i = 0;
  447. u32 changed = dev->features ^ features;
  448. if (!(changed & NETIF_F_RXCSUM))
  449. return 0;
  450. if (dev->flags & IFF_UP) {
  451. /* Halt TX and RX, and process the frames which
  452. * have already been received */
  453. local_irq_save(flags);
  454. lock_tx_qs(priv);
  455. lock_rx_qs(priv);
  456. gfar_halt(dev);
  457. unlock_tx_qs(priv);
  458. unlock_rx_qs(priv);
  459. local_irq_restore(flags);
  460. for (i = 0; i < priv->num_rx_queues; i++)
  461. gfar_clean_rx_ring(priv->rx_queue[i],
  462. priv->rx_queue[i]->rx_ring_size);
  463. /* Now we take down the rings to rebuild them */
  464. stop_gfar(dev);
  465. dev->features = features;
  466. err = startup_gfar(dev);
  467. netif_tx_wake_all_queues(dev);
  468. }
  469. return err;
  470. }
  471. static uint32_t gfar_get_msglevel(struct net_device *dev)
  472. {
  473. struct gfar_private *priv = netdev_priv(dev);
  474. return priv->msg_enable;
  475. }
  476. static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
  477. {
  478. struct gfar_private *priv = netdev_priv(dev);
  479. priv->msg_enable = data;
  480. }
  481. #ifdef CONFIG_PM
  482. static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  483. {
  484. struct gfar_private *priv = netdev_priv(dev);
  485. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
  486. wol->supported = WAKE_MAGIC;
  487. wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
  488. } else {
  489. wol->supported = wol->wolopts = 0;
  490. }
  491. }
  492. static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  493. {
  494. struct gfar_private *priv = netdev_priv(dev);
  495. unsigned long flags;
  496. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  497. wol->wolopts != 0)
  498. return -EINVAL;
  499. if (wol->wolopts & ~WAKE_MAGIC)
  500. return -EINVAL;
  501. device_set_wakeup_enable(&dev->dev, wol->wolopts & WAKE_MAGIC);
  502. spin_lock_irqsave(&priv->bflock, flags);
  503. priv->wol_en = !!device_may_wakeup(&dev->dev);
  504. spin_unlock_irqrestore(&priv->bflock, flags);
  505. return 0;
  506. }
  507. #endif
  508. static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)
  509. {
  510. u32 fcr = 0x0, fpr = FPR_FILER_MASK;
  511. if (ethflow & RXH_L2DA) {
  512. fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH |
  513. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  514. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  515. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  516. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  517. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  518. fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH |
  519. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  520. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  521. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  522. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  523. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  524. }
  525. if (ethflow & RXH_VLAN) {
  526. fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  527. RQFCR_AND | RQFCR_HASHTBL_0;
  528. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  529. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  530. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  531. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  532. }
  533. if (ethflow & RXH_IP_SRC) {
  534. fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  535. RQFCR_AND | RQFCR_HASHTBL_0;
  536. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  537. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  538. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  539. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  540. }
  541. if (ethflow & (RXH_IP_DST)) {
  542. fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  543. RQFCR_AND | RQFCR_HASHTBL_0;
  544. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  545. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  546. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  547. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  548. }
  549. if (ethflow & RXH_L3_PROTO) {
  550. fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  551. RQFCR_AND | RQFCR_HASHTBL_0;
  552. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  553. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  554. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  555. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  556. }
  557. if (ethflow & RXH_L4_B_0_1) {
  558. fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  559. RQFCR_AND | RQFCR_HASHTBL_0;
  560. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  561. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  562. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  563. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  564. }
  565. if (ethflow & RXH_L4_B_2_3) {
  566. fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  567. RQFCR_AND | RQFCR_HASHTBL_0;
  568. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  569. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  570. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  571. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  572. }
  573. }
  574. static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u64 class)
  575. {
  576. unsigned int last_rule_idx = priv->cur_filer_idx;
  577. unsigned int cmp_rqfpr;
  578. unsigned int local_rqfpr[MAX_FILER_IDX + 1];
  579. unsigned int local_rqfcr[MAX_FILER_IDX + 1];
  580. int i = 0x0, k = 0x0;
  581. int j = MAX_FILER_IDX, l = 0x0;
  582. switch (class) {
  583. case TCP_V4_FLOW:
  584. cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP;
  585. break;
  586. case UDP_V4_FLOW:
  587. cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP;
  588. break;
  589. case TCP_V6_FLOW:
  590. cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP;
  591. break;
  592. case UDP_V6_FLOW:
  593. cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP;
  594. break;
  595. default:
  596. pr_err("Right now this class is not supported\n");
  597. return 0;
  598. }
  599. for (i = 0; i < MAX_FILER_IDX + 1; i++) {
  600. local_rqfpr[j] = ftp_rqfpr[i];
  601. local_rqfcr[j] = ftp_rqfcr[i];
  602. j--;
  603. if ((ftp_rqfcr[i] == (RQFCR_PID_PARSE |
  604. RQFCR_CLE |RQFCR_AND)) &&
  605. (ftp_rqfpr[i] == cmp_rqfpr))
  606. break;
  607. }
  608. if (i == MAX_FILER_IDX + 1) {
  609. pr_err("No parse rule found, can't create hash rules\n");
  610. return 0;
  611. }
  612. /* If a match was found, then it begins the starting of a cluster rule
  613. * if it was already programmed, we need to overwrite these rules
  614. */
  615. for (l = i+1; l < MAX_FILER_IDX; l++) {
  616. if ((ftp_rqfcr[l] & RQFCR_CLE) &&
  617. !(ftp_rqfcr[l] & RQFCR_AND)) {
  618. ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
  619. RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
  620. ftp_rqfpr[l] = FPR_FILER_MASK;
  621. gfar_write_filer(priv, l, ftp_rqfcr[l], ftp_rqfpr[l]);
  622. break;
  623. }
  624. if (!(ftp_rqfcr[l] & RQFCR_CLE) && (ftp_rqfcr[l] & RQFCR_AND))
  625. continue;
  626. else {
  627. local_rqfpr[j] = ftp_rqfpr[l];
  628. local_rqfcr[j] = ftp_rqfcr[l];
  629. j--;
  630. }
  631. }
  632. priv->cur_filer_idx = l - 1;
  633. last_rule_idx = l;
  634. /* hash rules */
  635. ethflow_to_filer_rules(priv, ethflow);
  636. /* Write back the popped out rules again */
  637. for (k = j+1; k < MAX_FILER_IDX; k++) {
  638. ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k];
  639. ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k];
  640. gfar_write_filer(priv, priv->cur_filer_idx,
  641. local_rqfcr[k], local_rqfpr[k]);
  642. if (!priv->cur_filer_idx)
  643. break;
  644. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  645. }
  646. return 1;
  647. }
  648. static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
  649. {
  650. /* write the filer rules here */
  651. if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type))
  652. return -EINVAL;
  653. return 0;
  654. }
  655. static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  656. {
  657. struct gfar_private *priv = netdev_priv(dev);
  658. int ret = 0;
  659. switch(cmd->cmd) {
  660. case ETHTOOL_SRXFH:
  661. ret = gfar_set_hash_opts(priv, cmd);
  662. break;
  663. default:
  664. ret = -EINVAL;
  665. }
  666. return ret;
  667. }
  668. const struct ethtool_ops gfar_ethtool_ops = {
  669. .get_settings = gfar_gsettings,
  670. .set_settings = gfar_ssettings,
  671. .get_drvinfo = gfar_gdrvinfo,
  672. .get_regs_len = gfar_reglen,
  673. .get_regs = gfar_get_regs,
  674. .get_link = ethtool_op_get_link,
  675. .get_coalesce = gfar_gcoalesce,
  676. .set_coalesce = gfar_scoalesce,
  677. .get_ringparam = gfar_gringparam,
  678. .set_ringparam = gfar_sringparam,
  679. .get_strings = gfar_gstrings,
  680. .get_sset_count = gfar_sset_count,
  681. .get_ethtool_stats = gfar_fill_stats,
  682. .get_msglevel = gfar_get_msglevel,
  683. .set_msglevel = gfar_set_msglevel,
  684. #ifdef CONFIG_PM
  685. .get_wol = gfar_get_wol,
  686. .set_wol = gfar_set_wol,
  687. #endif
  688. .set_rxnfc = gfar_set_nfc,
  689. };