xgbe-ethtool.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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-2016 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-2016 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_vxlan_packets", tx_vxlan_packets),
  144. XGMAC_EXT_STAT("tx_tso_packets", tx_tso_packets),
  145. XGMAC_MMC_STAT("tx_64_byte_packets", tx64octets_gb),
  146. XGMAC_MMC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
  147. XGMAC_MMC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
  148. XGMAC_MMC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
  149. XGMAC_MMC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
  150. XGMAC_MMC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
  151. XGMAC_MMC_STAT("tx_underflow_errors", txunderflowerror),
  152. XGMAC_MMC_STAT("tx_pause_frames", txpauseframes),
  153. XGMAC_MMC_STAT("rx_bytes", rxoctetcount_gb),
  154. XGMAC_MMC_STAT("rx_packets", rxframecount_gb),
  155. XGMAC_MMC_STAT("rx_unicast_packets", rxunicastframes_g),
  156. XGMAC_MMC_STAT("rx_broadcast_packets", rxbroadcastframes_g),
  157. XGMAC_MMC_STAT("rx_multicast_packets", rxmulticastframes_g),
  158. XGMAC_MMC_STAT("rx_vlan_packets", rxvlanframes_gb),
  159. XGMAC_EXT_STAT("rx_vxlan_packets", rx_vxlan_packets),
  160. XGMAC_MMC_STAT("rx_64_byte_packets", rx64octets_gb),
  161. XGMAC_MMC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
  162. XGMAC_MMC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
  163. XGMAC_MMC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
  164. XGMAC_MMC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
  165. XGMAC_MMC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
  166. XGMAC_MMC_STAT("rx_undersize_packets", rxundersize_g),
  167. XGMAC_MMC_STAT("rx_oversize_packets", rxoversize_g),
  168. XGMAC_MMC_STAT("rx_crc_errors", rxcrcerror),
  169. XGMAC_MMC_STAT("rx_crc_errors_small_packets", rxrunterror),
  170. XGMAC_MMC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
  171. XGMAC_MMC_STAT("rx_length_errors", rxlengtherror),
  172. XGMAC_MMC_STAT("rx_out_of_range_errors", rxoutofrangetype),
  173. XGMAC_MMC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
  174. XGMAC_MMC_STAT("rx_watchdog_errors", rxwatchdogerror),
  175. XGMAC_EXT_STAT("rx_csum_errors", rx_csum_errors),
  176. XGMAC_EXT_STAT("rx_vxlan_csum_errors", rx_vxlan_csum_errors),
  177. XGMAC_MMC_STAT("rx_pause_frames", rxpauseframes),
  178. XGMAC_EXT_STAT("rx_split_header_packets", rx_split_header_packets),
  179. XGMAC_EXT_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
  180. };
  181. #define XGBE_STATS_COUNT ARRAY_SIZE(xgbe_gstring_stats)
  182. static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  183. {
  184. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  185. int i;
  186. switch (stringset) {
  187. case ETH_SS_STATS:
  188. for (i = 0; i < XGBE_STATS_COUNT; i++) {
  189. memcpy(data, xgbe_gstring_stats[i].stat_string,
  190. ETH_GSTRING_LEN);
  191. data += ETH_GSTRING_LEN;
  192. }
  193. for (i = 0; i < pdata->tx_ring_count; i++) {
  194. sprintf(data, "txq_%u_packets", i);
  195. data += ETH_GSTRING_LEN;
  196. sprintf(data, "txq_%u_bytes", i);
  197. data += ETH_GSTRING_LEN;
  198. }
  199. for (i = 0; i < pdata->rx_ring_count; i++) {
  200. sprintf(data, "rxq_%u_packets", i);
  201. data += ETH_GSTRING_LEN;
  202. sprintf(data, "rxq_%u_bytes", i);
  203. data += ETH_GSTRING_LEN;
  204. }
  205. break;
  206. }
  207. }
  208. static void xgbe_get_ethtool_stats(struct net_device *netdev,
  209. struct ethtool_stats *stats, u64 *data)
  210. {
  211. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  212. u8 *stat;
  213. int i;
  214. pdata->hw_if.read_mmc_stats(pdata);
  215. for (i = 0; i < XGBE_STATS_COUNT; i++) {
  216. stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
  217. *data++ = *(u64 *)stat;
  218. }
  219. for (i = 0; i < pdata->tx_ring_count; i++) {
  220. *data++ = pdata->ext_stats.txq_packets[i];
  221. *data++ = pdata->ext_stats.txq_bytes[i];
  222. }
  223. for (i = 0; i < pdata->rx_ring_count; i++) {
  224. *data++ = pdata->ext_stats.rxq_packets[i];
  225. *data++ = pdata->ext_stats.rxq_bytes[i];
  226. }
  227. }
  228. static int xgbe_get_sset_count(struct net_device *netdev, int stringset)
  229. {
  230. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  231. int ret;
  232. switch (stringset) {
  233. case ETH_SS_STATS:
  234. ret = XGBE_STATS_COUNT +
  235. (pdata->tx_ring_count * 2) +
  236. (pdata->rx_ring_count * 2);
  237. break;
  238. default:
  239. ret = -EOPNOTSUPP;
  240. }
  241. return ret;
  242. }
  243. static void xgbe_get_pauseparam(struct net_device *netdev,
  244. struct ethtool_pauseparam *pause)
  245. {
  246. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  247. pause->autoneg = pdata->phy.pause_autoneg;
  248. pause->tx_pause = pdata->phy.tx_pause;
  249. pause->rx_pause = pdata->phy.rx_pause;
  250. }
  251. static int xgbe_set_pauseparam(struct net_device *netdev,
  252. struct ethtool_pauseparam *pause)
  253. {
  254. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  255. struct ethtool_link_ksettings *lks = &pdata->phy.lks;
  256. int ret = 0;
  257. if (pause->autoneg && (pdata->phy.autoneg != AUTONEG_ENABLE)) {
  258. netdev_err(netdev,
  259. "autoneg disabled, pause autoneg not available\n");
  260. return -EINVAL;
  261. }
  262. pdata->phy.pause_autoneg = pause->autoneg;
  263. pdata->phy.tx_pause = pause->tx_pause;
  264. pdata->phy.rx_pause = pause->rx_pause;
  265. XGBE_CLR_ADV(lks, Pause);
  266. XGBE_CLR_ADV(lks, Asym_Pause);
  267. if (pause->rx_pause) {
  268. XGBE_SET_ADV(lks, Pause);
  269. XGBE_SET_ADV(lks, Asym_Pause);
  270. }
  271. if (pause->tx_pause) {
  272. /* Equivalent to XOR of Asym_Pause */
  273. if (XGBE_ADV(lks, Asym_Pause))
  274. XGBE_CLR_ADV(lks, Asym_Pause);
  275. else
  276. XGBE_SET_ADV(lks, Asym_Pause);
  277. }
  278. if (netif_running(netdev))
  279. ret = pdata->phy_if.phy_config_aneg(pdata);
  280. return ret;
  281. }
  282. static int xgbe_get_link_ksettings(struct net_device *netdev,
  283. struct ethtool_link_ksettings *cmd)
  284. {
  285. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  286. struct ethtool_link_ksettings *lks = &pdata->phy.lks;
  287. cmd->base.phy_address = pdata->phy.address;
  288. cmd->base.autoneg = pdata->phy.autoneg;
  289. cmd->base.speed = pdata->phy.speed;
  290. cmd->base.duplex = pdata->phy.duplex;
  291. cmd->base.port = PORT_NONE;
  292. XGBE_LM_COPY(cmd, supported, lks, supported);
  293. XGBE_LM_COPY(cmd, advertising, lks, advertising);
  294. XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising);
  295. return 0;
  296. }
  297. static int xgbe_set_link_ksettings(struct net_device *netdev,
  298. const struct ethtool_link_ksettings *cmd)
  299. {
  300. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  301. struct ethtool_link_ksettings *lks = &pdata->phy.lks;
  302. __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
  303. u32 speed;
  304. int ret;
  305. speed = cmd->base.speed;
  306. if (cmd->base.phy_address != pdata->phy.address) {
  307. netdev_err(netdev, "invalid phy address %hhu\n",
  308. cmd->base.phy_address);
  309. return -EINVAL;
  310. }
  311. if ((cmd->base.autoneg != AUTONEG_ENABLE) &&
  312. (cmd->base.autoneg != AUTONEG_DISABLE)) {
  313. netdev_err(netdev, "unsupported autoneg %hhu\n",
  314. cmd->base.autoneg);
  315. return -EINVAL;
  316. }
  317. if (cmd->base.autoneg == AUTONEG_DISABLE) {
  318. if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
  319. netdev_err(netdev, "unsupported speed %u\n", speed);
  320. return -EINVAL;
  321. }
  322. if (cmd->base.duplex != DUPLEX_FULL) {
  323. netdev_err(netdev, "unsupported duplex %hhu\n",
  324. cmd->base.duplex);
  325. return -EINVAL;
  326. }
  327. }
  328. netif_dbg(pdata, link, netdev,
  329. "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
  330. __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
  331. __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
  332. bitmap_and(advertising,
  333. cmd->link_modes.advertising, lks->link_modes.supported,
  334. __ETHTOOL_LINK_MODE_MASK_NBITS);
  335. if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
  336. bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
  337. netdev_err(netdev,
  338. "unsupported requested advertisement\n");
  339. return -EINVAL;
  340. }
  341. ret = 0;
  342. pdata->phy.autoneg = cmd->base.autoneg;
  343. pdata->phy.speed = speed;
  344. pdata->phy.duplex = cmd->base.duplex;
  345. bitmap_copy(lks->link_modes.advertising, advertising,
  346. __ETHTOOL_LINK_MODE_MASK_NBITS);
  347. if (cmd->base.autoneg == AUTONEG_ENABLE)
  348. XGBE_SET_ADV(lks, Autoneg);
  349. else
  350. XGBE_CLR_ADV(lks, Autoneg);
  351. if (netif_running(netdev))
  352. ret = pdata->phy_if.phy_config_aneg(pdata);
  353. return ret;
  354. }
  355. static void xgbe_get_drvinfo(struct net_device *netdev,
  356. struct ethtool_drvinfo *drvinfo)
  357. {
  358. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  359. struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
  360. strlcpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
  361. strlcpy(drvinfo->version, XGBE_DRV_VERSION, sizeof(drvinfo->version));
  362. strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
  363. sizeof(drvinfo->bus_info));
  364. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
  365. XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
  366. XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
  367. XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
  368. }
  369. static u32 xgbe_get_msglevel(struct net_device *netdev)
  370. {
  371. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  372. return pdata->msg_enable;
  373. }
  374. static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
  375. {
  376. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  377. pdata->msg_enable = msglevel;
  378. }
  379. static int xgbe_get_coalesce(struct net_device *netdev,
  380. struct ethtool_coalesce *ec)
  381. {
  382. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  383. memset(ec, 0, sizeof(struct ethtool_coalesce));
  384. ec->rx_coalesce_usecs = pdata->rx_usecs;
  385. ec->rx_max_coalesced_frames = pdata->rx_frames;
  386. ec->tx_max_coalesced_frames = pdata->tx_frames;
  387. return 0;
  388. }
  389. static int xgbe_set_coalesce(struct net_device *netdev,
  390. struct ethtool_coalesce *ec)
  391. {
  392. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  393. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  394. unsigned int rx_frames, rx_riwt, rx_usecs;
  395. unsigned int tx_frames;
  396. /* Check for not supported parameters */
  397. if ((ec->rx_coalesce_usecs_irq) ||
  398. (ec->rx_max_coalesced_frames_irq) ||
  399. (ec->tx_coalesce_usecs) ||
  400. (ec->tx_coalesce_usecs_irq) ||
  401. (ec->tx_max_coalesced_frames_irq) ||
  402. (ec->stats_block_coalesce_usecs) ||
  403. (ec->use_adaptive_rx_coalesce) ||
  404. (ec->use_adaptive_tx_coalesce) ||
  405. (ec->pkt_rate_low) ||
  406. (ec->rx_coalesce_usecs_low) ||
  407. (ec->rx_max_coalesced_frames_low) ||
  408. (ec->tx_coalesce_usecs_low) ||
  409. (ec->tx_max_coalesced_frames_low) ||
  410. (ec->pkt_rate_high) ||
  411. (ec->rx_coalesce_usecs_high) ||
  412. (ec->rx_max_coalesced_frames_high) ||
  413. (ec->tx_coalesce_usecs_high) ||
  414. (ec->tx_max_coalesced_frames_high) ||
  415. (ec->rate_sample_interval)) {
  416. netdev_err(netdev, "unsupported coalescing parameter\n");
  417. return -EOPNOTSUPP;
  418. }
  419. rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
  420. rx_usecs = ec->rx_coalesce_usecs;
  421. rx_frames = ec->rx_max_coalesced_frames;
  422. /* Use smallest possible value if conversion resulted in zero */
  423. if (rx_usecs && !rx_riwt)
  424. rx_riwt = 1;
  425. /* Check the bounds of values for Rx */
  426. if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
  427. netdev_err(netdev, "rx-usec is limited to %d usecs\n",
  428. hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
  429. return -EINVAL;
  430. }
  431. if (rx_frames > pdata->rx_desc_count) {
  432. netdev_err(netdev, "rx-frames is limited to %d frames\n",
  433. pdata->rx_desc_count);
  434. return -EINVAL;
  435. }
  436. tx_frames = ec->tx_max_coalesced_frames;
  437. /* Check the bounds of values for Tx */
  438. if (tx_frames > pdata->tx_desc_count) {
  439. netdev_err(netdev, "tx-frames is limited to %d frames\n",
  440. pdata->tx_desc_count);
  441. return -EINVAL;
  442. }
  443. pdata->rx_riwt = rx_riwt;
  444. pdata->rx_usecs = rx_usecs;
  445. pdata->rx_frames = rx_frames;
  446. hw_if->config_rx_coalesce(pdata);
  447. pdata->tx_frames = tx_frames;
  448. hw_if->config_tx_coalesce(pdata);
  449. return 0;
  450. }
  451. static int xgbe_get_rxnfc(struct net_device *netdev,
  452. struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
  453. {
  454. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  455. switch (rxnfc->cmd) {
  456. case ETHTOOL_GRXRINGS:
  457. rxnfc->data = pdata->rx_ring_count;
  458. break;
  459. default:
  460. return -EOPNOTSUPP;
  461. }
  462. return 0;
  463. }
  464. static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
  465. {
  466. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  467. return sizeof(pdata->rss_key);
  468. }
  469. static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
  470. {
  471. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  472. return ARRAY_SIZE(pdata->rss_table);
  473. }
  474. static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  475. u8 *hfunc)
  476. {
  477. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  478. unsigned int i;
  479. if (indir) {
  480. for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
  481. indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
  482. MAC_RSSDR, DMCH);
  483. }
  484. if (key)
  485. memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
  486. if (hfunc)
  487. *hfunc = ETH_RSS_HASH_TOP;
  488. return 0;
  489. }
  490. static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
  491. const u8 *key, const u8 hfunc)
  492. {
  493. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  494. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  495. unsigned int ret;
  496. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
  497. netdev_err(netdev, "unsupported hash function\n");
  498. return -EOPNOTSUPP;
  499. }
  500. if (indir) {
  501. ret = hw_if->set_rss_lookup_table(pdata, indir);
  502. if (ret)
  503. return ret;
  504. }
  505. if (key) {
  506. ret = hw_if->set_rss_hash_key(pdata, key);
  507. if (ret)
  508. return ret;
  509. }
  510. return 0;
  511. }
  512. static int xgbe_get_ts_info(struct net_device *netdev,
  513. struct ethtool_ts_info *ts_info)
  514. {
  515. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  516. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  517. SOF_TIMESTAMPING_RX_SOFTWARE |
  518. SOF_TIMESTAMPING_SOFTWARE |
  519. SOF_TIMESTAMPING_TX_HARDWARE |
  520. SOF_TIMESTAMPING_RX_HARDWARE |
  521. SOF_TIMESTAMPING_RAW_HARDWARE;
  522. if (pdata->ptp_clock)
  523. ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
  524. else
  525. ts_info->phc_index = -1;
  526. ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  527. ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  528. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  529. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  530. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  531. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  532. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  533. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
  534. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  535. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  536. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  537. (1 << HWTSTAMP_FILTER_ALL);
  538. return 0;
  539. }
  540. static int xgbe_get_module_info(struct net_device *netdev,
  541. struct ethtool_modinfo *modinfo)
  542. {
  543. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  544. return pdata->phy_if.module_info(pdata, modinfo);
  545. }
  546. static int xgbe_get_module_eeprom(struct net_device *netdev,
  547. struct ethtool_eeprom *eeprom, u8 *data)
  548. {
  549. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  550. return pdata->phy_if.module_eeprom(pdata, eeprom, data);
  551. }
  552. static void xgbe_get_ringparam(struct net_device *netdev,
  553. struct ethtool_ringparam *ringparam)
  554. {
  555. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  556. ringparam->rx_max_pending = XGBE_RX_DESC_CNT_MAX;
  557. ringparam->tx_max_pending = XGBE_TX_DESC_CNT_MAX;
  558. ringparam->rx_pending = pdata->rx_desc_count;
  559. ringparam->tx_pending = pdata->tx_desc_count;
  560. }
  561. static int xgbe_set_ringparam(struct net_device *netdev,
  562. struct ethtool_ringparam *ringparam)
  563. {
  564. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  565. unsigned int rx, tx;
  566. if (ringparam->rx_mini_pending || ringparam->rx_jumbo_pending) {
  567. netdev_err(netdev, "unsupported ring parameter\n");
  568. return -EINVAL;
  569. }
  570. if ((ringparam->rx_pending < XGBE_RX_DESC_CNT_MIN) ||
  571. (ringparam->rx_pending > XGBE_RX_DESC_CNT_MAX)) {
  572. netdev_err(netdev,
  573. "rx ring parameter must be between %u and %u\n",
  574. XGBE_RX_DESC_CNT_MIN, XGBE_RX_DESC_CNT_MAX);
  575. return -EINVAL;
  576. }
  577. if ((ringparam->tx_pending < XGBE_TX_DESC_CNT_MIN) ||
  578. (ringparam->tx_pending > XGBE_TX_DESC_CNT_MAX)) {
  579. netdev_err(netdev,
  580. "tx ring parameter must be between %u and %u\n",
  581. XGBE_TX_DESC_CNT_MIN, XGBE_TX_DESC_CNT_MAX);
  582. return -EINVAL;
  583. }
  584. rx = __rounddown_pow_of_two(ringparam->rx_pending);
  585. if (rx != ringparam->rx_pending)
  586. netdev_notice(netdev,
  587. "rx ring parameter rounded to power of two: %u\n",
  588. rx);
  589. tx = __rounddown_pow_of_two(ringparam->tx_pending);
  590. if (tx != ringparam->tx_pending)
  591. netdev_notice(netdev,
  592. "tx ring parameter rounded to power of two: %u\n",
  593. tx);
  594. if ((rx == pdata->rx_desc_count) &&
  595. (tx == pdata->tx_desc_count))
  596. goto out;
  597. pdata->rx_desc_count = rx;
  598. pdata->tx_desc_count = tx;
  599. xgbe_restart_dev(pdata);
  600. out:
  601. return 0;
  602. }
  603. static void xgbe_get_channels(struct net_device *netdev,
  604. struct ethtool_channels *channels)
  605. {
  606. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  607. unsigned int rx, tx, combined;
  608. /* Calculate maximums allowed:
  609. * - Take into account the number of available IRQs
  610. * - Do not take into account the number of online CPUs so that
  611. * the user can over-subscribe if desired
  612. * - Tx is additionally limited by the number of hardware queues
  613. */
  614. rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
  615. rx = min(rx, pdata->channel_irq_count);
  616. tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
  617. tx = min(tx, pdata->channel_irq_count);
  618. tx = min(tx, pdata->tx_max_q_count);
  619. combined = min(rx, tx);
  620. channels->max_combined = combined;
  621. channels->max_rx = rx ? rx - 1 : 0;
  622. channels->max_tx = tx ? tx - 1 : 0;
  623. /* Get current settings based on device state */
  624. rx = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
  625. tx = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
  626. combined = min(rx, tx);
  627. rx -= combined;
  628. tx -= combined;
  629. channels->combined_count = combined;
  630. channels->rx_count = rx;
  631. channels->tx_count = tx;
  632. }
  633. static void xgbe_print_set_channels_input(struct net_device *netdev,
  634. struct ethtool_channels *channels)
  635. {
  636. netdev_err(netdev, "channel inputs: combined=%u, rx-only=%u, tx-only=%u\n",
  637. channels->combined_count, channels->rx_count,
  638. channels->tx_count);
  639. }
  640. static int xgbe_set_channels(struct net_device *netdev,
  641. struct ethtool_channels *channels)
  642. {
  643. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  644. unsigned int rx, rx_curr, tx, tx_curr, combined;
  645. /* Calculate maximums allowed:
  646. * - Take into account the number of available IRQs
  647. * - Do not take into account the number of online CPUs so that
  648. * the user can over-subscribe if desired
  649. * - Tx is additionally limited by the number of hardware queues
  650. */
  651. rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
  652. rx = min(rx, pdata->channel_irq_count);
  653. tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
  654. tx = min(tx, pdata->tx_max_q_count);
  655. tx = min(tx, pdata->channel_irq_count);
  656. combined = min(rx, tx);
  657. /* Should not be setting other count */
  658. if (channels->other_count) {
  659. netdev_err(netdev,
  660. "other channel count must be zero\n");
  661. return -EINVAL;
  662. }
  663. /* Require at least one Combined (Rx and Tx) channel */
  664. if (!channels->combined_count) {
  665. netdev_err(netdev,
  666. "at least one combined Rx/Tx channel is required\n");
  667. xgbe_print_set_channels_input(netdev, channels);
  668. return -EINVAL;
  669. }
  670. /* Check combined channels */
  671. if (channels->combined_count > combined) {
  672. netdev_err(netdev,
  673. "combined channel count cannot exceed %u\n",
  674. combined);
  675. xgbe_print_set_channels_input(netdev, channels);
  676. return -EINVAL;
  677. }
  678. /* Can have some Rx-only or Tx-only channels, but not both */
  679. if (channels->rx_count && channels->tx_count) {
  680. netdev_err(netdev,
  681. "cannot specify both Rx-only and Tx-only channels\n");
  682. xgbe_print_set_channels_input(netdev, channels);
  683. return -EINVAL;
  684. }
  685. /* Check that we don't exceed the maximum number of channels */
  686. if ((channels->combined_count + channels->rx_count) > rx) {
  687. netdev_err(netdev,
  688. "total Rx channels (%u) requested exceeds maximum available (%u)\n",
  689. channels->combined_count + channels->rx_count, rx);
  690. xgbe_print_set_channels_input(netdev, channels);
  691. return -EINVAL;
  692. }
  693. if ((channels->combined_count + channels->tx_count) > tx) {
  694. netdev_err(netdev,
  695. "total Tx channels (%u) requested exceeds maximum available (%u)\n",
  696. channels->combined_count + channels->tx_count, tx);
  697. xgbe_print_set_channels_input(netdev, channels);
  698. return -EINVAL;
  699. }
  700. rx = channels->combined_count + channels->rx_count;
  701. tx = channels->combined_count + channels->tx_count;
  702. rx_curr = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
  703. tx_curr = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
  704. if ((rx == rx_curr) && (tx == tx_curr))
  705. goto out;
  706. pdata->new_rx_ring_count = rx;
  707. pdata->new_tx_ring_count = tx;
  708. xgbe_full_restart_dev(pdata);
  709. out:
  710. return 0;
  711. }
  712. static const struct ethtool_ops xgbe_ethtool_ops = {
  713. .get_drvinfo = xgbe_get_drvinfo,
  714. .get_msglevel = xgbe_get_msglevel,
  715. .set_msglevel = xgbe_set_msglevel,
  716. .get_link = ethtool_op_get_link,
  717. .get_coalesce = xgbe_get_coalesce,
  718. .set_coalesce = xgbe_set_coalesce,
  719. .get_pauseparam = xgbe_get_pauseparam,
  720. .set_pauseparam = xgbe_set_pauseparam,
  721. .get_strings = xgbe_get_strings,
  722. .get_ethtool_stats = xgbe_get_ethtool_stats,
  723. .get_sset_count = xgbe_get_sset_count,
  724. .get_rxnfc = xgbe_get_rxnfc,
  725. .get_rxfh_key_size = xgbe_get_rxfh_key_size,
  726. .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
  727. .get_rxfh = xgbe_get_rxfh,
  728. .set_rxfh = xgbe_set_rxfh,
  729. .get_ts_info = xgbe_get_ts_info,
  730. .get_link_ksettings = xgbe_get_link_ksettings,
  731. .set_link_ksettings = xgbe_set_link_ksettings,
  732. .get_module_info = xgbe_get_module_info,
  733. .get_module_eeprom = xgbe_get_module_eeprom,
  734. .get_ringparam = xgbe_get_ringparam,
  735. .set_ringparam = xgbe_set_ringparam,
  736. .get_channels = xgbe_get_channels,
  737. .set_channels = xgbe_set_channels,
  738. };
  739. const struct ethtool_ops *xgbe_get_ethtool_ops(void)
  740. {
  741. return &xgbe_ethtool_ops;
  742. }