gianfar_ethtool.c 24 KB

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