gianfar_ethtool.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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. #include <linux/kernel.h>
  19. #include <linux/string.h>
  20. #include <linux/errno.h>
  21. #include <linux/slab.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. printk("%s: Ring sizes must be a power of 2\n",
  404. dev->name);
  405. return -EINVAL;
  406. }
  407. if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE)
  408. return -EINVAL;
  409. if (!is_power_of_2(rvals->tx_pending)) {
  410. printk("%s: Ring sizes must be a power of 2\n",
  411. dev->name);
  412. return -EINVAL;
  413. }
  414. if (dev->flags & IFF_UP) {
  415. unsigned long flags;
  416. /* Halt TX and RX, and process the frames which
  417. * have already been received */
  418. local_irq_save(flags);
  419. lock_tx_qs(priv);
  420. lock_rx_qs(priv);
  421. gfar_halt(dev);
  422. unlock_rx_qs(priv);
  423. unlock_tx_qs(priv);
  424. local_irq_restore(flags);
  425. for (i = 0; i < priv->num_rx_queues; i++)
  426. gfar_clean_rx_ring(priv->rx_queue[i],
  427. priv->rx_queue[i]->rx_ring_size);
  428. /* Now we take down the rings to rebuild them */
  429. stop_gfar(dev);
  430. }
  431. /* Change the size */
  432. for (i = 0; i < priv->num_rx_queues; i++) {
  433. priv->rx_queue[i]->rx_ring_size = rvals->rx_pending;
  434. priv->tx_queue[i]->tx_ring_size = rvals->tx_pending;
  435. priv->tx_queue[i]->num_txbdfree = priv->tx_queue[i]->tx_ring_size;
  436. }
  437. /* Rebuild the rings with the new size */
  438. if (dev->flags & IFF_UP) {
  439. err = startup_gfar(dev);
  440. netif_tx_wake_all_queues(dev);
  441. }
  442. return err;
  443. }
  444. static int gfar_set_rx_csum(struct net_device *dev, uint32_t data)
  445. {
  446. struct gfar_private *priv = netdev_priv(dev);
  447. unsigned long flags;
  448. int err = 0, i = 0;
  449. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
  450. return -EOPNOTSUPP;
  451. if (dev->flags & IFF_UP) {
  452. /* Halt TX and RX, and process the frames which
  453. * have already been received */
  454. local_irq_save(flags);
  455. lock_tx_qs(priv);
  456. lock_rx_qs(priv);
  457. gfar_halt(dev);
  458. unlock_tx_qs(priv);
  459. unlock_rx_qs(priv);
  460. local_irq_save(flags);
  461. for (i = 0; i < priv->num_rx_queues; i++)
  462. gfar_clean_rx_ring(priv->rx_queue[i],
  463. priv->rx_queue[i]->rx_ring_size);
  464. /* Now we take down the rings to rebuild them */
  465. stop_gfar(dev);
  466. }
  467. spin_lock_irqsave(&priv->bflock, flags);
  468. priv->rx_csum_enable = data;
  469. spin_unlock_irqrestore(&priv->bflock, flags);
  470. if (dev->flags & IFF_UP) {
  471. err = startup_gfar(dev);
  472. netif_tx_wake_all_queues(dev);
  473. }
  474. return err;
  475. }
  476. static uint32_t gfar_get_rx_csum(struct net_device *dev)
  477. {
  478. struct gfar_private *priv = netdev_priv(dev);
  479. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
  480. return 0;
  481. return priv->rx_csum_enable;
  482. }
  483. static int gfar_set_tx_csum(struct net_device *dev, uint32_t data)
  484. {
  485. struct gfar_private *priv = netdev_priv(dev);
  486. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
  487. return -EOPNOTSUPP;
  488. netif_tx_lock_bh(dev);
  489. if (data)
  490. dev->features |= NETIF_F_IP_CSUM;
  491. else
  492. dev->features &= ~NETIF_F_IP_CSUM;
  493. netif_tx_unlock_bh(dev);
  494. return 0;
  495. }
  496. static uint32_t gfar_get_tx_csum(struct net_device *dev)
  497. {
  498. struct gfar_private *priv = netdev_priv(dev);
  499. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM))
  500. return 0;
  501. return (dev->features & NETIF_F_IP_CSUM) != 0;
  502. }
  503. static uint32_t gfar_get_msglevel(struct net_device *dev)
  504. {
  505. struct gfar_private *priv = netdev_priv(dev);
  506. return priv->msg_enable;
  507. }
  508. static void gfar_set_msglevel(struct net_device *dev, uint32_t data)
  509. {
  510. struct gfar_private *priv = netdev_priv(dev);
  511. priv->msg_enable = data;
  512. }
  513. #ifdef CONFIG_PM
  514. static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  515. {
  516. struct gfar_private *priv = netdev_priv(dev);
  517. if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) {
  518. wol->supported = WAKE_MAGIC;
  519. wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0;
  520. } else {
  521. wol->supported = wol->wolopts = 0;
  522. }
  523. }
  524. static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  525. {
  526. struct gfar_private *priv = netdev_priv(dev);
  527. unsigned long flags;
  528. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) &&
  529. wol->wolopts != 0)
  530. return -EINVAL;
  531. if (wol->wolopts & ~WAKE_MAGIC)
  532. return -EINVAL;
  533. spin_lock_irqsave(&priv->bflock, flags);
  534. priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0;
  535. device_set_wakeup_enable(&dev->dev, priv->wol_en);
  536. spin_unlock_irqrestore(&priv->bflock, flags);
  537. return 0;
  538. }
  539. #endif
  540. static int gfar_ethflow_to_class(int flow_type, u64 *class)
  541. {
  542. switch (flow_type) {
  543. case TCP_V4_FLOW:
  544. *class = CLASS_CODE_TCP_IPV4;
  545. break;
  546. case UDP_V4_FLOW:
  547. *class = CLASS_CODE_UDP_IPV4;
  548. break;
  549. case AH_V4_FLOW:
  550. case ESP_V4_FLOW:
  551. *class = CLASS_CODE_AH_ESP_IPV4;
  552. break;
  553. case SCTP_V4_FLOW:
  554. *class = CLASS_CODE_SCTP_IPV4;
  555. break;
  556. case TCP_V6_FLOW:
  557. *class = CLASS_CODE_TCP_IPV6;
  558. break;
  559. case UDP_V6_FLOW:
  560. *class = CLASS_CODE_UDP_IPV6;
  561. break;
  562. case AH_V6_FLOW:
  563. case ESP_V6_FLOW:
  564. *class = CLASS_CODE_AH_ESP_IPV6;
  565. break;
  566. case SCTP_V6_FLOW:
  567. *class = CLASS_CODE_SCTP_IPV6;
  568. break;
  569. default:
  570. return 0;
  571. }
  572. return 1;
  573. }
  574. static void ethflow_to_filer_rules (struct gfar_private *priv, u64 ethflow)
  575. {
  576. u32 fcr = 0x0, fpr = FPR_FILER_MASK;
  577. if (ethflow & RXH_L2DA) {
  578. fcr = RQFCR_PID_DAH |RQFCR_CMP_NOMATCH |
  579. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  580. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  581. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  582. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  583. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  584. fcr = RQFCR_PID_DAL | RQFCR_AND | RQFCR_CMP_NOMATCH |
  585. RQFCR_HASH | RQFCR_AND | RQFCR_HASHTBL_0;
  586. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  587. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  588. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  589. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  590. }
  591. if (ethflow & RXH_VLAN) {
  592. fcr = RQFCR_PID_VID | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  593. RQFCR_AND | RQFCR_HASHTBL_0;
  594. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  595. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  596. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  597. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  598. }
  599. if (ethflow & RXH_IP_SRC) {
  600. fcr = RQFCR_PID_SIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  601. RQFCR_AND | RQFCR_HASHTBL_0;
  602. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  603. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  604. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  605. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  606. }
  607. if (ethflow & (RXH_IP_DST)) {
  608. fcr = RQFCR_PID_DIA | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  609. RQFCR_AND | RQFCR_HASHTBL_0;
  610. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  611. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  612. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  613. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  614. }
  615. if (ethflow & RXH_L3_PROTO) {
  616. fcr = RQFCR_PID_L4P | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  617. RQFCR_AND | RQFCR_HASHTBL_0;
  618. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  619. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  620. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  621. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  622. }
  623. if (ethflow & RXH_L4_B_0_1) {
  624. fcr = RQFCR_PID_SPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  625. RQFCR_AND | RQFCR_HASHTBL_0;
  626. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  627. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  628. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  629. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  630. }
  631. if (ethflow & RXH_L4_B_2_3) {
  632. fcr = RQFCR_PID_DPT | RQFCR_CMP_NOMATCH | RQFCR_HASH |
  633. RQFCR_AND | RQFCR_HASHTBL_0;
  634. ftp_rqfpr[priv->cur_filer_idx] = fpr;
  635. ftp_rqfcr[priv->cur_filer_idx] = fcr;
  636. gfar_write_filer(priv, priv->cur_filer_idx, fcr, fpr);
  637. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  638. }
  639. }
  640. static int gfar_ethflow_to_filer_table(struct gfar_private *priv, u64 ethflow, u64 class)
  641. {
  642. unsigned int last_rule_idx = priv->cur_filer_idx;
  643. unsigned int cmp_rqfpr;
  644. unsigned int local_rqfpr[MAX_FILER_IDX + 1];
  645. unsigned int local_rqfcr[MAX_FILER_IDX + 1];
  646. int i = 0x0, k = 0x0;
  647. int j = MAX_FILER_IDX, l = 0x0;
  648. switch (class) {
  649. case TCP_V4_FLOW:
  650. cmp_rqfpr = RQFPR_IPV4 |RQFPR_TCP;
  651. break;
  652. case UDP_V4_FLOW:
  653. cmp_rqfpr = RQFPR_IPV4 |RQFPR_UDP;
  654. break;
  655. case TCP_V6_FLOW:
  656. cmp_rqfpr = RQFPR_IPV6 |RQFPR_TCP;
  657. break;
  658. case UDP_V6_FLOW:
  659. cmp_rqfpr = RQFPR_IPV6 |RQFPR_UDP;
  660. break;
  661. case IPV4_FLOW:
  662. cmp_rqfpr = RQFPR_IPV4;
  663. case IPV6_FLOW:
  664. cmp_rqfpr = RQFPR_IPV6;
  665. break;
  666. default:
  667. printk(KERN_ERR "Right now this class is not supported\n");
  668. return 0;
  669. }
  670. for (i = 0; i < MAX_FILER_IDX + 1; i++) {
  671. local_rqfpr[j] = ftp_rqfpr[i];
  672. local_rqfcr[j] = ftp_rqfcr[i];
  673. j--;
  674. if ((ftp_rqfcr[i] == (RQFCR_PID_PARSE |
  675. RQFCR_CLE |RQFCR_AND)) &&
  676. (ftp_rqfpr[i] == cmp_rqfpr))
  677. break;
  678. }
  679. if (i == MAX_FILER_IDX + 1) {
  680. printk(KERN_ERR "No parse rule found, ");
  681. printk(KERN_ERR "can't create hash rules\n");
  682. return 0;
  683. }
  684. /* If a match was found, then it begins the starting of a cluster rule
  685. * if it was already programmed, we need to overwrite these rules
  686. */
  687. for (l = i+1; l < MAX_FILER_IDX; l++) {
  688. if ((ftp_rqfcr[l] & RQFCR_CLE) &&
  689. !(ftp_rqfcr[l] & RQFCR_AND)) {
  690. ftp_rqfcr[l] = RQFCR_CLE | RQFCR_CMP_EXACT |
  691. RQFCR_HASHTBL_0 | RQFCR_PID_MASK;
  692. ftp_rqfpr[l] = FPR_FILER_MASK;
  693. gfar_write_filer(priv, l, ftp_rqfcr[l], ftp_rqfpr[l]);
  694. break;
  695. }
  696. if (!(ftp_rqfcr[l] & RQFCR_CLE) && (ftp_rqfcr[l] & RQFCR_AND))
  697. continue;
  698. else {
  699. local_rqfpr[j] = ftp_rqfpr[l];
  700. local_rqfcr[j] = ftp_rqfcr[l];
  701. j--;
  702. }
  703. }
  704. priv->cur_filer_idx = l - 1;
  705. last_rule_idx = l;
  706. /* hash rules */
  707. ethflow_to_filer_rules(priv, ethflow);
  708. /* Write back the popped out rules again */
  709. for (k = j+1; k < MAX_FILER_IDX; k++) {
  710. ftp_rqfpr[priv->cur_filer_idx] = local_rqfpr[k];
  711. ftp_rqfcr[priv->cur_filer_idx] = local_rqfcr[k];
  712. gfar_write_filer(priv, priv->cur_filer_idx,
  713. local_rqfcr[k], local_rqfpr[k]);
  714. if (!priv->cur_filer_idx)
  715. break;
  716. priv->cur_filer_idx = priv->cur_filer_idx - 1;
  717. }
  718. return 1;
  719. }
  720. static int gfar_set_hash_opts(struct gfar_private *priv, struct ethtool_rxnfc *cmd)
  721. {
  722. u64 class;
  723. if (!gfar_ethflow_to_class(cmd->flow_type, &class))
  724. return -EINVAL;
  725. if (class < CLASS_CODE_USER_PROG1 ||
  726. class > CLASS_CODE_SCTP_IPV6)
  727. return -EINVAL;
  728. /* write the filer rules here */
  729. if (!gfar_ethflow_to_filer_table(priv, cmd->data, cmd->flow_type))
  730. return -1;
  731. return 0;
  732. }
  733. static int gfar_set_nfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
  734. {
  735. struct gfar_private *priv = netdev_priv(dev);
  736. int ret = 0;
  737. switch(cmd->cmd) {
  738. case ETHTOOL_SRXFH:
  739. ret = gfar_set_hash_opts(priv, cmd);
  740. break;
  741. default:
  742. ret = -EINVAL;
  743. }
  744. return ret;
  745. }
  746. const struct ethtool_ops gfar_ethtool_ops = {
  747. .get_settings = gfar_gsettings,
  748. .set_settings = gfar_ssettings,
  749. .get_drvinfo = gfar_gdrvinfo,
  750. .get_regs_len = gfar_reglen,
  751. .get_regs = gfar_get_regs,
  752. .get_link = ethtool_op_get_link,
  753. .get_coalesce = gfar_gcoalesce,
  754. .set_coalesce = gfar_scoalesce,
  755. .get_ringparam = gfar_gringparam,
  756. .set_ringparam = gfar_sringparam,
  757. .get_strings = gfar_gstrings,
  758. .get_sset_count = gfar_sset_count,
  759. .get_ethtool_stats = gfar_fill_stats,
  760. .get_rx_csum = gfar_get_rx_csum,
  761. .get_tx_csum = gfar_get_tx_csum,
  762. .set_rx_csum = gfar_set_rx_csum,
  763. .set_tx_csum = gfar_set_tx_csum,
  764. .set_sg = ethtool_op_set_sg,
  765. .get_msglevel = gfar_get_msglevel,
  766. .set_msglevel = gfar_set_msglevel,
  767. #ifdef CONFIG_PM
  768. .get_wol = gfar_get_wol,
  769. .set_wol = gfar_set_wol,
  770. #endif
  771. .set_rxnfc = gfar_set_nfc,
  772. };