gianfar_ethtool.c 47 KB

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