xgbe-ethtool.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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. #define XGMAC_EXT_STAT(_string, _var) \
  132. { _string, \
  133. FIELD_SIZEOF(struct xgbe_ext_stats, _var), \
  134. offsetof(struct xgbe_prv_data, ext_stats._var), \
  135. }
  136. static const struct xgbe_stats xgbe_gstring_stats[] = {
  137. XGMAC_MMC_STAT("tx_bytes", txoctetcount_gb),
  138. XGMAC_MMC_STAT("tx_packets", txframecount_gb),
  139. XGMAC_MMC_STAT("tx_unicast_packets", txunicastframes_gb),
  140. XGMAC_MMC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
  141. XGMAC_MMC_STAT("tx_multicast_packets", txmulticastframes_gb),
  142. XGMAC_MMC_STAT("tx_vlan_packets", txvlanframes_g),
  143. XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
  144. XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
  145. XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
  146. XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
  147. XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
  148. XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
  149. XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
  150. XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
  151. XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
  152. XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
  153. XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
  154. XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
  155. XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
  156. XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
  157. XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
  158. XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
  159. XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
  160. XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
  161. XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
  162. XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
  163. XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
  164. XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
  165. XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
  166. XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
  167. XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
  168. XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
  169. XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
  170. XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
  171. XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
  172. XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
  173. XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
  174. XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
  175. XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
  176. };
  177. #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
  178. static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  179. {
  180. int i;
  181. switch (stringset) {
  182. case ETH_SS_STATS:
  183. for (i = 0; i < XGBE_STATS_COUNT; i++) {
  184. memcpy(data, xgbe_gstring_stats[i].stat_string,
  185. ETH_GSTRING_LEN);
  186. data += ETH_GSTRING_LEN;
  187. }
  188. break;
  189. }
  190. }
  191. static void xgbe_get_ethtool_stats(struct net_device *netdev,
  192. struct ethtool_stats *stats, u64 *data)
  193. {
  194. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  195. u8 *stat;
  196. int i;
  197. pdata->hw_if.read_mmc_stats(pdata);
  198. for (i = 0; i < XGBE_STATS_COUNT; i++) {
  199. stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
  200. *data++ = *(u64 *)stat;
  201. }
  202. }
  203. static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
  204. {
  205. int ret;
  206. switch (stringset) {
  207. case ETH_SS_STATS:
  208. ret = XGBE_STATS_COUNT;
  209. break;
  210. default:
  211. ret = -EOPNOTSUPP;
  212. }
  213. return ret;
  214. }
  215. static void xgbe_get_pauseparam(struct net_device *netdev,
  216. struct ethtool_pauseparam *pause)
  217. {
  218. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  219. pause->autoneg = pdata->phy.pause_autoneg;
  220. pause->tx_pause = pdata->phy.tx_pause;
  221. pause->rx_pause = pdata->phy.rx_pause;
  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. int ret = 0;
  228. if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
  229. netdev_err(netdev,
  230. "autoneg disabled, pause autoneg not avialable\n");
  231. return -EINVAL;
  232. }
  233. pdata->phy.pause_autoneg = pause->autoneg;
  234. pdata->phy.tx_pause = pause->tx_pause;
  235. pdata->phy.rx_pause = pause->rx_pause;
  236. pdata->phy.advertising &= ~ADVERTISED_Pause;
  237. pdata->phy.advertising &= ~ADVERTISED_Asym_Pause;
  238. if (pause->rx_pause) {
  239. pdata->phy.advertising |= ADVERTISED_Pause;
  240. pdata->phy.advertising |= ADVERTISED_Asym_Pause;
  241. }
  242. if (pause->tx_pause)
  243. pdata->phy.advertising ^= ADVERTISED_Asym_Pause;
  244. if (netif_running(netdev))
  245. ret = pdata->phy_if.phy_config_aneg(pdata);
  246. return ret;
  247. }
  248. static int xgbe_get_settings(struct net_device *netdev,
  249. struct ethtool_cmd *cmd)
  250. {
  251. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  252. cmd->phy_address = pdata->phy.address;
  253. cmd->supported = pdata->phy.supported;
  254. cmd->advertising = pdata->phy.advertising;
  255. cmd->lp_advertising = pdata->phy.lp_advertising;
  256. cmd->autoneg = pdata->phy.autoneg;
  257. ethtool_cmd_speed_set(cmd, pdata->phy.speed);
  258. cmd->duplex = pdata->phy.duplex;
  259. cmd->port = PORT_NONE;
  260. cmd->transceiver = XCVR_INTERNAL;
  261. return 0;
  262. }
  263. static int xgbe_set_settings(struct net_device *netdev,
  264. struct ethtool_cmd *cmd)
  265. {
  266. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  267. u32 speed;
  268. int ret;
  269. speed = ethtool_cmd_speed(cmd);
  270. if (cmd->phy_address != pdata->phy.address) {
  271. netdev_err(netdev, "invalid phy address %hhu\n",
  272. cmd->phy_address);
  273. return -EINVAL;
  274. }
  275. if ((cmd->autoneg != AUTONEG_ENABLE) &&
  276. (cmd->autoneg != AUTONEG_DISABLE)) {
  277. netdev_err(netdev, "unsupported autoneg %hhu\n",
  278. cmd->autoneg);
  279. return -EINVAL;
  280. }
  281. if (cmd->autoneg == AUTONEG_DISABLE) {
  282. switch (speed) {
  283. case SPEED_10000:
  284. case SPEED_2500:
  285. case SPEED_1000:
  286. break;
  287. default:
  288. netdev_err(netdev, "unsupported speed %u\n", speed);
  289. return -EINVAL;
  290. }
  291. if (cmd->duplex != DUPLEX_FULL) {
  292. netdev_err(netdev, "unsupported duplex %hhu\n",
  293. cmd->duplex);
  294. return -EINVAL;
  295. }
  296. }
  297. netif_dbg(pdata, link, netdev,
  298. "requested advertisement %#x, phy supported %#x\n",
  299. cmd->advertising, pdata->phy.supported);
  300. cmd->advertising &= pdata->phy.supported;
  301. if ((cmd->autoneg == AUTONEG_ENABLE) && !cmd->advertising) {
  302. netdev_err(netdev,
  303. "unsupported requested advertisement\n");
  304. return -EINVAL;
  305. }
  306. ret = 0;
  307. pdata->phy.autoneg = cmd->autoneg;
  308. pdata->phy.speed = speed;
  309. pdata->phy.duplex = cmd->duplex;
  310. pdata->phy.advertising = cmd->advertising;
  311. if (cmd->autoneg == AUTONEG_ENABLE)
  312. pdata->phy.advertising |= ADVERTISED_Autoneg;
  313. else
  314. pdata->phy.advertising &= ~ADVERTISED_Autoneg;
  315. if (netif_running(netdev))
  316. ret = pdata->phy_if.phy_config_aneg(pdata);
  317. return ret;
  318. }
  319. static void xgbe_get_drvinfo(struct net_device *netdev,
  320. struct ethtool_drvinfo *drvinfo)
  321. {
  322. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  323. struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
  324. strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
  325. strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
  326. strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
  327. sizeof(drvinfo->bus_info));
  328. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
  329. XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
  330. XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
  331. XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
  332. }
  333. static u32 xgbe_get_msglevel(struct net_device *netdev)
  334. {
  335. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  336. return pdata->msg_enable;
  337. }
  338. static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
  339. {
  340. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  341. pdata->msg_enable = msglevel;
  342. }
  343. static int xgbe_get_coalesce(struct net_device *netdev,
  344. struct ethtool_coalesce *ec)
  345. {
  346. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  347. memset(ec, 0, sizeof(struct ethtool_coalesce));
  348. ec->rx_coalesce_usecs = pdata->rx_usecs;
  349. ec->rx_max_coalesced_frames = pdata->rx_frames;
  350. ec->tx_max_coalesced_frames = pdata->tx_frames;
  351. return 0;
  352. }
  353. static int xgbe_set_coalesce(struct net_device *netdev,
  354. struct ethtool_coalesce *ec)
  355. {
  356. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  357. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  358. unsigned int rx_frames, rx_riwt, rx_usecs;
  359. unsigned int tx_frames;
  360. /* Check for not supported parameters */
  361. if ((ec->rx_coalesce_usecs_irq) ||
  362. (ec->rx_max_coalesced_frames_irq) ||
  363. (ec->tx_coalesce_usecs) ||
  364. (ec->tx_coalesce_usecs_irq) ||
  365. (ec->tx_max_coalesced_frames_irq) ||
  366. (ec->stats_block_coalesce_usecs) ||
  367. (ec->use_adaptive_rx_coalesce) ||
  368. (ec->use_adaptive_tx_coalesce) ||
  369. (ec->pkt_rate_low) ||
  370. (ec->rx_coalesce_usecs_low) ||
  371. (ec->rx_max_coalesced_frames_low) ||
  372. (ec->tx_coalesce_usecs_low) ||
  373. (ec->tx_max_coalesced_frames_low) ||
  374. (ec->pkt_rate_high) ||
  375. (ec->rx_coalesce_usecs_high) ||
  376. (ec->rx_max_coalesced_frames_high) ||
  377. (ec->tx_coalesce_usecs_high) ||
  378. (ec->tx_max_coalesced_frames_high) ||
  379. (ec->rate_sample_interval)) {
  380. netdev_err(netdev, "unsupported coalescing parameter\n");
  381. return -EOPNOTSUPP;
  382. }
  383. rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
  384. rx_usecs = ec->rx_coalesce_usecs;
  385. rx_frames = ec->rx_max_coalesced_frames;
  386. /* Use smallest possible value if conversion resulted in zero */
  387. if (rx_usecs && !rx_riwt)
  388. rx_riwt = 1;
  389. /* Check the bounds of values for Rx */
  390. if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
  391. netdev_err(netdev, "rx-usec is limited to %d usecs\n",
  392. hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
  393. return -EINVAL;
  394. }
  395. if (rx_frames > pdata->rx_desc_count) {
  396. netdev_err(netdev, "rx-frames is limited to %d frames\n",
  397. pdata->rx_desc_count);
  398. return -EINVAL;
  399. }
  400. tx_frames = ec->tx_max_coalesced_frames;
  401. /* Check the bounds of values for Tx */
  402. if (tx_frames > pdata->tx_desc_count) {
  403. netdev_err(netdev, "tx-frames is limited to %d frames\n",
  404. pdata->tx_desc_count);
  405. return -EINVAL;
  406. }
  407. pdata->rx_riwt = rx_riwt;
  408. pdata->rx_usecs = rx_usecs;
  409. pdata->rx_frames = rx_frames;
  410. hw_if->config_rx_coalesce(pdata);
  411. pdata->tx_frames = tx_frames;
  412. hw_if->config_tx_coalesce(pdata);
  413. return 0;
  414. }
  415. static int xgbe_get_rxnfc(struct net_device *netdev,
  416. struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
  417. {
  418. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  419. switch (rxnfc->cmd) {
  420. case ETHTOOL_GRXRINGS:
  421. rxnfc->data = pdata->rx_ring_count;
  422. break;
  423. default:
  424. return -EOPNOTSUPP;
  425. }
  426. return 0;
  427. }
  428. static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
  429. {
  430. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  431. return sizeof(pdata->rss_key);
  432. }
  433. static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
  434. {
  435. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  436. return ARRAY_SIZE(pdata->rss_table);
  437. }
  438. static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  439. u8 *hfunc)
  440. {
  441. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  442. unsigned int i;
  443. if (indir) {
  444. for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
  445. indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
  446. MAC_RSSDR, DMCH);
  447. }
  448. if (key)
  449. memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
  450. if (hfunc)
  451. *hfunc = ETH_RSS_HASH_TOP;
  452. return 0;
  453. }
  454. static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
  455. const u8 *key, const u8 hfunc)
  456. {
  457. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  458. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  459. unsigned int ret;
  460. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
  461. netdev_err(netdev, "unsupported hash function\n");
  462. return -EOPNOTSUPP;
  463. }
  464. if (indir) {
  465. ret = hw_if->set_rss_lookup_table(pdata, indir);
  466. if (ret)
  467. return ret;
  468. }
  469. if (key) {
  470. ret = hw_if->set_rss_hash_key(pdata, key);
  471. if (ret)
  472. return ret;
  473. }
  474. return 0;
  475. }
  476. static int xgbe_get_ts_info(struct net_device *netdev,
  477. struct ethtool_ts_info *ts_info)
  478. {
  479. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  480. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  481. SOF_TIMESTAMPING_RX_SOFTWARE |
  482. SOF_TIMESTAMPING_SOFTWARE |
  483. SOF_TIMESTAMPING_TX_HARDWARE |
  484. SOF_TIMESTAMPING_RX_HARDWARE |
  485. SOF_TIMESTAMPING_RAW_HARDWARE;
  486. if (pdata->ptp_clock)
  487. ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
  488. else
  489. ts_info->phc_index = -1;
  490. ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  491. ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  492. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  493. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  494. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  495. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  496. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  497. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
  498. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  499. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  500. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  501. (1 << HWTSTAMP_FILTER_ALL);
  502. return 0;
  503. }
  504. static const struct ethtool_ops xgbe_ethtool_ops = {
  505. .get_settings = xgbe_get_settings,
  506. .set_settings = xgbe_set_settings,
  507. .get_drvinfo = xgbe_get_drvinfo,
  508. .get_msglevel = xgbe_get_msglevel,
  509. .set_msglevel = xgbe_set_msglevel,
  510. .get_link = ethtool_op_get_link,
  511. .get_coalesce = xgbe_get_coalesce,
  512. .set_coalesce = xgbe_set_coalesce,
  513. .get_pauseparam = xgbe_get_pauseparam,
  514. .set_pauseparam = xgbe_set_pauseparam,
  515. .get_strings = xgbe_get_strings,
  516. .get_ethtool_stats = xgbe_get_ethtool_stats,
  517. .get_sset_count = xgbe_get_sset_count,
  518. .get_rxnfc = xgbe_get_rxnfc,
  519. .get_rxfh_key_size = xgbe_get_rxfh_key_size,
  520. .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
  521. .get_rxfh = xgbe_get_rxfh,
  522. .set_rxfh = xgbe_set_rxfh,
  523. .get_ts_info = xgbe_get_ts_info,
  524. };
  525. struct ethtool_ops *xgbe_get_ethtool_ops(void)
  526. {
  527. return (struct ethtool_ops *)&xgbe_ethtool_ops;
  528. }