gianfar_ethtool.c 41 KB

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