xgbe-ethtool.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * AMD 10Gb Ethernet driver
  3. *
  4. * This file is available to you under your choice of the following two
  5. * licenses:
  6. *
  7. * License 1: GPLv2
  8. *
  9. * Copyright (c) 2014 Advanced Micro Devices, Inc.
  10. *
  11. * This file is free software; you may copy, redistribute and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * This file incorporates work covered by the following copyright and
  25. * permission notice:
  26. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  27. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  28. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  29. * and you.
  30. *
  31. * The Software IS NOT an item of Licensed Software or Licensed Product
  32. * under any End User Software License Agreement or Agreement for Licensed
  33. * Product with Synopsys or any supplement thereto. Permission is hereby
  34. * granted, free of charge, to any person obtaining a copy of this software
  35. * annotated with this license and the Software, to deal in the Software
  36. * without restriction, including without limitation the rights to use,
  37. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  38. * of the Software, and to permit persons to whom the Software is furnished
  39. * to do so, subject to the following conditions:
  40. *
  41. * The above copyright notice and this permission notice shall be included
  42. * in all copies or substantial portions of the Software.
  43. *
  44. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  46. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  47. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  48. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  49. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  50. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  51. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  52. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  53. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  54. * THE POSSIBILITY OF SUCH DAMAGE.
  55. *
  56. *
  57. * License 2: Modified BSD
  58. *
  59. * Copyright (c) 2014 Advanced Micro Devices, Inc.
  60. * All rights reserved.
  61. *
  62. * Redistribution and use in source and binary forms, with or without
  63. * modification, are permitted provided that the following conditions are met:
  64. * * Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. * * Redistributions in binary form must reproduce the above copyright
  67. * notice, this list of conditions and the following disclaimer in the
  68. * documentation and/or other materials provided with the distribution.
  69. * * Neither the name of Advanced Micro Devices, Inc. nor the
  70. * names of its contributors may be used to endorse or promote products
  71. * derived from this software without specific prior written permission.
  72. *
  73. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  74. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76. * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  77. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  79. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  80. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  81. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  82. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  83. *
  84. * This file incorporates work covered by the following copyright and
  85. * permission notice:
  86. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  87. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  88. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  89. * and you.
  90. *
  91. * The Software IS NOT an item of Licensed Software or Licensed Product
  92. * under any End User Software License Agreement or Agreement for Licensed
  93. * Product with Synopsys or any supplement thereto. Permission is hereby
  94. * granted, free of charge, to any person obtaining a copy of this software
  95. * annotated with this license and the Software, to deal in the Software
  96. * without restriction, including without limitation the rights to use,
  97. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  98. * of the Software, and to permit persons to whom the Software is furnished
  99. * to do so, subject to the following conditions:
  100. *
  101. * The above copyright notice and this permission notice shall be included
  102. * in all copies or substantial portions of the Software.
  103. *
  104. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  105. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  106. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  107. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  108. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  109. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  110. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  111. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  112. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  113. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  114. * THE POSSIBILITY OF SUCH DAMAGE.
  115. */
  116. #include <linux/spinlock.h>
  117. #include <linux/phy.h>
  118. #include <linux/net_tstamp.h>
  119. #include "xgbe.h"
  120. #include "xgbe-common.h"
  121. struct xgbe_stats {
  122. char stat_string[ETH_GSTRING_LEN];
  123. int stat_size;
  124. int stat_offset;
  125. };
  126. #define XGMAC_MMC_STAT(_string, _var) \
  127. { _string, \
  128. FIELD_SIZEOF(struct xgbe_mmc_stats, _var), \
  129. offsetof(struct xgbe_prv_data, mmc_stats._var), \
  130. }
  131. static const struct xgbe_stats xgbe_gstring_stats[] = {
  132. XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
  133. XGMAC_MMC_STAT("tx_packets", txframecount_gb),
  134. XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
  135. XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
  136. XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
  137. XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
  138. XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
  139. XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
  140. XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
  141. XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
  142. XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
  143. XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
  144. XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
  145. XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
  146. XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
  147. XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
  148. XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
  149. XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
  150. XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
  151. XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
  152. XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
  153. XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
  154. XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
  155. XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
  156. XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
  157. XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
  158. XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
  159. XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
  160. XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
  161. XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
  162. XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
  163. XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
  164. XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
  165. XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
  166. XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
  167. XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
  168. };
  169. #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
  170. static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  171. {
  172. int i;
  173. DBGPR("-->%s\n", __func__);
  174. switch (stringset) {
  175. case ETH_SS_STATS:
  176. for (i = 0; i < XGBE_STATS_COUNT; i++) {
  177. memcpy(data, xgbe_gstring_stats[i].stat_string,
  178. ETH_GSTRING_LEN);
  179. data += ETH_GSTRING_LEN;
  180. }
  181. break;
  182. }
  183. DBGPR("<--%s\n", __func__);
  184. }
  185. static void xgbe_get_ethtool_stats(struct net_device *netdev,
  186. struct ethtool_stats *stats, u64 *data)
  187. {
  188. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  189. u8 *stat;
  190. int i;
  191. DBGPR("-->%s\n", __func__);
  192. pdata->hw_if.read_mmc_stats(pdata);
  193. for (i = 0; i < XGBE_STATS_COUNT; i++) {
  194. stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
  195. *data++ = *(u64 *)stat;
  196. }
  197. DBGPR("<--%s\n", __func__);
  198. }
  199. static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
  200. {
  201. int ret;
  202. DBGPR("-->%s\n", __func__);
  203. switch (stringset) {
  204. case ETH_SS_STATS:
  205. ret = XGBE_STATS_COUNT;
  206. break;
  207. default:
  208. ret = -EOPNOTSUPP;
  209. }
  210. DBGPR("<--%s\n", __func__);
  211. return ret;
  212. }
  213. static void xgbe_get_pauseparam(struct net_device *netdev,
  214. struct ethtool_pauseparam *pause)
  215. {
  216. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  217. DBGPR("-->xgbe_get_pauseparam\n");
  218. pause->autoneg = pdata->pause_autoneg;
  219. pause->tx_pause = pdata->tx_pause;
  220. pause->rx_pause = pdata->rx_pause;
  221. DBGPR("<--xgbe_get_pauseparam\n");
  222. }
  223. static int xgbe_set_pauseparam(struct net_device *netdev,
  224. struct ethtool_pauseparam *pause)
  225. {
  226. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  227. struct phy_device *phydev = pdata->phydev;
  228. int ret = 0;
  229. DBGPR("-->xgbe_set_pauseparam\n");
  230. DBGPR(" autoneg = %d, tx_pause = %d, rx_pause = %d\n",
  231. pause->autoneg, pause->tx_pause, pause->rx_pause);
  232. pdata->pause_autoneg = pause->autoneg;
  233. if (pause->autoneg) {
  234. phydev->advertising |= ADVERTISED_Pause;
  235. phydev->advertising |= ADVERTISED_Asym_Pause;
  236. } else {
  237. phydev->advertising &= ~ADVERTISED_Pause;
  238. phydev->advertising &= ~ADVERTISED_Asym_Pause;
  239. pdata->tx_pause = pause->tx_pause;
  240. pdata->rx_pause = pause->rx_pause;
  241. }
  242. if (netif_running(netdev))
  243. ret = phy_start_aneg(phydev);
  244. DBGPR("<--xgbe_set_pauseparam\n");
  245. return ret;
  246. }
  247. static int xgbe_get_settings(struct net_device *netdev,
  248. struct ethtool_cmd *cmd)
  249. {
  250. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  251. int ret;
  252. DBGPR("-->xgbe_get_settings\n");
  253. if (!pdata->phydev)
  254. return -ENODEV;
  255. ret = phy_ethtool_gset(pdata->phydev, cmd);
  256. DBGPR("<--xgbe_get_settings\n");
  257. return ret;
  258. }
  259. static int xgbe_set_settings(struct net_device *netdev,
  260. struct ethtool_cmd *cmd)
  261. {
  262. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  263. struct phy_device *phydev = pdata->phydev;
  264. u32 speed;
  265. int ret;
  266. DBGPR("-->xgbe_set_settings\n");
  267. if (!pdata->phydev)
  268. return -ENODEV;
  269. speed = ethtool_cmd_speed(cmd);
  270. if (cmd->phy_address != phydev->addr)
  271. return -EINVAL;
  272. if ((cmd->autoneg != AUTONEG_ENABLE) &&
  273. (cmd->autoneg != AUTONEG_DISABLE))
  274. return -EINVAL;
  275. if (cmd->autoneg == AUTONEG_DISABLE) {
  276. switch (speed) {
  277. case SPEED_10000:
  278. case SPEED_2500:
  279. case SPEED_1000:
  280. break;
  281. default:
  282. return -EINVAL;
  283. }
  284. if (cmd->duplex != DUPLEX_FULL)
  285. return -EINVAL;
  286. }
  287. cmd->advertising &= phydev->supported;
  288. if ((cmd->autoneg == AUTONEG_ENABLE) && !cmd->advertising)
  289. return -EINVAL;
  290. ret = 0;
  291. phydev->autoneg = cmd->autoneg;
  292. phydev->speed = speed;
  293. phydev->duplex = cmd->duplex;
  294. phydev->advertising = cmd->advertising;
  295. if (cmd->autoneg == AUTONEG_ENABLE)
  296. phydev->advertising |= ADVERTISED_Autoneg;
  297. else
  298. phydev->advertising &= ~ADVERTISED_Autoneg;
  299. if (netif_running(netdev))
  300. ret = phy_start_aneg(phydev);
  301. DBGPR("<--xgbe_set_settings\n");
  302. return ret;
  303. }
  304. static void xgbe_get_drvinfo(struct net_device *netdev,
  305. struct ethtool_drvinfo *drvinfo)
  306. {
  307. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  308. struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
  309. strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
  310. strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
  311. strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
  312. sizeof(drvinfo->bus_info));
  313. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
  314. XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
  315. XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
  316. XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
  317. drvinfo->n_stats = XGBE_STATS_COUNT;
  318. }
  319. static int xgbe_get_coalesce(struct net_device *netdev,
  320. struct ethtool_coalesce *ec)
  321. {
  322. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  323. DBGPR("-->xgbe_get_coalesce\n");
  324. memset(ec, 0, sizeof(struct ethtool_coalesce));
  325. ec->rx_coalesce_usecs = pdata->rx_usecs;
  326. ec->rx_max_coalesced_frames = pdata->rx_frames;
  327. ec->tx_max_coalesced_frames = pdata->tx_frames;
  328. DBGPR("<--xgbe_get_coalesce\n");
  329. return 0;
  330. }
  331. static int xgbe_set_coalesce(struct net_device *netdev,
  332. struct ethtool_coalesce *ec)
  333. {
  334. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  335. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  336. unsigned int rx_frames, rx_riwt, rx_usecs;
  337. unsigned int tx_frames;
  338. DBGPR("-->xgbe_set_coalesce\n");
  339. /* Check for not supported parameters */
  340. if ((ec->rx_coalesce_usecs_irq) ||
  341. (ec->rx_max_coalesced_frames_irq) ||
  342. (ec->tx_coalesce_usecs) ||
  343. (ec->tx_coalesce_usecs_irq) ||
  344. (ec->tx_max_coalesced_frames_irq) ||
  345. (ec->stats_block_coalesce_usecs) ||
  346. (ec->use_adaptive_rx_coalesce) ||
  347. (ec->use_adaptive_tx_coalesce) ||
  348. (ec->pkt_rate_low) ||
  349. (ec->rx_coalesce_usecs_low) ||
  350. (ec->rx_max_coalesced_frames_low) ||
  351. (ec->tx_coalesce_usecs_low) ||
  352. (ec->tx_max_coalesced_frames_low) ||
  353. (ec->pkt_rate_high) ||
  354. (ec->rx_coalesce_usecs_high) ||
  355. (ec->rx_max_coalesced_frames_high) ||
  356. (ec->tx_coalesce_usecs_high) ||
  357. (ec->tx_max_coalesced_frames_high) ||
  358. (ec->rate_sample_interval))
  359. return -EOPNOTSUPP;
  360. rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
  361. rx_usecs = ec->rx_coalesce_usecs;
  362. rx_frames = ec->rx_max_coalesced_frames;
  363. /* Use smallest possible value if conversion resulted in zero */
  364. if (rx_usecs && !rx_riwt)
  365. rx_riwt = 1;
  366. /* Check the bounds of values for Rx */
  367. if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
  368. netdev_alert(netdev, "rx-usec is limited to %d usecs\n",
  369. hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
  370. return -EINVAL;
  371. }
  372. if (rx_frames > pdata->rx_desc_count) {
  373. netdev_alert(netdev, "rx-frames is limited to %d frames\n",
  374. pdata->rx_desc_count);
  375. return -EINVAL;
  376. }
  377. tx_frames = ec->tx_max_coalesced_frames;
  378. /* Check the bounds of values for Tx */
  379. if (tx_frames > pdata->tx_desc_count) {
  380. netdev_alert(netdev, "tx-frames is limited to %d frames\n",
  381. pdata->tx_desc_count);
  382. return -EINVAL;
  383. }
  384. pdata->rx_riwt = rx_riwt;
  385. pdata->rx_usecs = rx_usecs;
  386. pdata->rx_frames = rx_frames;
  387. hw_if->config_rx_coalesce(pdata);
  388. pdata->tx_frames = tx_frames;
  389. hw_if->config_tx_coalesce(pdata);
  390. DBGPR("<--xgbe_set_coalesce\n");
  391. return 0;
  392. }
  393. static int xgbe_get_rxnfc(struct net_device *netdev,
  394. struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
  395. {
  396. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  397. switch (rxnfc->cmd) {
  398. case ETHTOOL_GRXRINGS:
  399. rxnfc->data = pdata->rx_ring_count;
  400. break;
  401. default:
  402. return -EOPNOTSUPP;
  403. }
  404. return 0;
  405. }
  406. static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
  407. {
  408. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  409. return sizeof(pdata->rss_key);
  410. }
  411. static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
  412. {
  413. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  414. return ARRAY_SIZE(pdata->rss_table);
  415. }
  416. static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  417. u8 *hfunc)
  418. {
  419. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  420. unsigned int i;
  421. if (indir) {
  422. for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
  423. indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
  424. MAC_RSSDR, DMCH);
  425. }
  426. if (key)
  427. memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
  428. if (hfunc)
  429. *hfunc = ETH_RSS_HASH_TOP;
  430. return 0;
  431. }
  432. static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
  433. const u8 *key, const u8 hfunc)
  434. {
  435. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  436. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  437. unsigned int ret;
  438. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  439. return -EOPNOTSUPP;
  440. if (indir) {
  441. ret = hw_if->set_rss_lookup_table(pdata, indir);
  442. if (ret)
  443. return ret;
  444. }
  445. if (key) {
  446. ret = hw_if->set_rss_hash_key(pdata, key);
  447. if (ret)
  448. return ret;
  449. }
  450. return 0;
  451. }
  452. static int xgbe_get_ts_info(struct net_device *netdev,
  453. struct ethtool_ts_info *ts_info)
  454. {
  455. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  456. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  457. SOF_TIMESTAMPING_RX_SOFTWARE |
  458. SOF_TIMESTAMPING_SOFTWARE |
  459. SOF_TIMESTAMPING_TX_HARDWARE |
  460. SOF_TIMESTAMPING_RX_HARDWARE |
  461. SOF_TIMESTAMPING_RAW_HARDWARE;
  462. if (pdata->ptp_clock)
  463. ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
  464. else
  465. ts_info->phc_index = -1;
  466. ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  467. ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  468. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  469. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  470. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  471. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  472. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  473. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
  474. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  475. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  476. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  477. (1 << HWTSTAMP_FILTER_ALL);
  478. return 0;
  479. }
  480. static const struct ethtool_ops xgbe_ethtool_ops = {
  481. .get_settings = xgbe_get_settings,
  482. .set_settings = xgbe_set_settings,
  483. .get_drvinfo = xgbe_get_drvinfo,
  484. .get_link = ethtool_op_get_link,
  485. .get_coalesce = xgbe_get_coalesce,
  486. .set_coalesce = xgbe_set_coalesce,
  487. .get_pauseparam = xgbe_get_pauseparam,
  488. .set_pauseparam = xgbe_set_pauseparam,
  489. .get_strings = xgbe_get_strings,
  490. .get_ethtool_stats = xgbe_get_ethtool_stats,
  491. .get_sset_count = xgbe_get_sset_count,
  492. .get_rxnfc = xgbe_get_rxnfc,
  493. .get_rxfh_key_size = xgbe_get_rxfh_key_size,
  494. .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
  495. .get_rxfh = xgbe_get_rxfh,
  496. .set_rxfh = xgbe_set_rxfh,
  497. .get_ts_info = xgbe_get_ts_info,
  498. };
  499. struct ethtool_ops *xgbe_get_ethtool_ops(void)
  500. {
  501. return (struct ethtool_ops *)&xgbe_ethtool_ops;
  502. }