xgbe-ethtool.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  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. sizeof_field(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. sizeof_field(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. if (netif_carrier_ok(netdev)) {
  289. cmd->base.speed = pdata->phy.speed;
  290. cmd->base.duplex = pdata->phy.duplex;
  291. } else {
  292. cmd->base.speed = SPEED_UNKNOWN;
  293. cmd->base.duplex = DUPLEX_UNKNOWN;
  294. }
  295. cmd->base.autoneg = pdata->phy.autoneg;
  296. cmd->base.port = PORT_NONE;
  297. XGBE_LM_COPY(cmd, supported, lks, supported);
  298. XGBE_LM_COPY(cmd, advertising, lks, advertising);
  299. XGBE_LM_COPY(cmd, lp_advertising, lks, lp_advertising);
  300. return 0;
  301. }
  302. static int xgbe_set_link_ksettings(struct net_device *netdev,
  303. const struct ethtool_link_ksettings *cmd)
  304. {
  305. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  306. struct ethtool_link_ksettings *lks = &pdata->phy.lks;
  307. __ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
  308. u32 speed;
  309. int ret;
  310. speed = cmd->base.speed;
  311. if (cmd->base.phy_address != pdata->phy.address) {
  312. netdev_err(netdev, "invalid phy address %hhu\n",
  313. cmd->base.phy_address);
  314. return -EINVAL;
  315. }
  316. if ((cmd->base.autoneg != AUTONEG_ENABLE) &&
  317. (cmd->base.autoneg != AUTONEG_DISABLE)) {
  318. netdev_err(netdev, "unsupported autoneg %hhu\n",
  319. cmd->base.autoneg);
  320. return -EINVAL;
  321. }
  322. if (cmd->base.autoneg == AUTONEG_DISABLE) {
  323. if (!pdata->phy_if.phy_valid_speed(pdata, speed)) {
  324. netdev_err(netdev, "unsupported speed %u\n", speed);
  325. return -EINVAL;
  326. }
  327. if (cmd->base.duplex != DUPLEX_FULL) {
  328. netdev_err(netdev, "unsupported duplex %hhu\n",
  329. cmd->base.duplex);
  330. return -EINVAL;
  331. }
  332. }
  333. netif_dbg(pdata, link, netdev,
  334. "requested advertisement 0x%*pb, phy supported 0x%*pb\n",
  335. __ETHTOOL_LINK_MODE_MASK_NBITS, cmd->link_modes.advertising,
  336. __ETHTOOL_LINK_MODE_MASK_NBITS, lks->link_modes.supported);
  337. linkmode_and(advertising, cmd->link_modes.advertising,
  338. lks->link_modes.supported);
  339. if ((cmd->base.autoneg == AUTONEG_ENABLE) &&
  340. bitmap_empty(advertising, __ETHTOOL_LINK_MODE_MASK_NBITS)) {
  341. netdev_err(netdev,
  342. "unsupported requested advertisement\n");
  343. return -EINVAL;
  344. }
  345. ret = 0;
  346. pdata->phy.autoneg = cmd->base.autoneg;
  347. pdata->phy.speed = speed;
  348. pdata->phy.duplex = cmd->base.duplex;
  349. linkmode_copy(lks->link_modes.advertising, advertising);
  350. if (cmd->base.autoneg == AUTONEG_ENABLE)
  351. XGBE_SET_ADV(lks, Autoneg);
  352. else
  353. XGBE_CLR_ADV(lks, Autoneg);
  354. if (netif_running(netdev))
  355. ret = pdata->phy_if.phy_config_aneg(pdata);
  356. return ret;
  357. }
  358. static void xgbe_get_drvinfo(struct net_device *netdev,
  359. struct ethtool_drvinfo *drvinfo)
  360. {
  361. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  362. struct xgbe_hw_features *hw_feat = &pdata->hw_feat;
  363. strscpy(drvinfo->driver, XGBE_DRV_NAME, sizeof(drvinfo->driver));
  364. strscpy(drvinfo->bus_info, dev_name(pdata->dev),
  365. sizeof(drvinfo->bus_info));
  366. snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d.%d.%d",
  367. XGMAC_GET_BITS(hw_feat->version, MAC_VR, USERVER),
  368. XGMAC_GET_BITS(hw_feat->version, MAC_VR, DEVID),
  369. XGMAC_GET_BITS(hw_feat->version, MAC_VR, SNPSVER));
  370. }
  371. static u32 xgbe_get_msglevel(struct net_device *netdev)
  372. {
  373. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  374. return pdata->msg_enable;
  375. }
  376. static void xgbe_set_msglevel(struct net_device *netdev, u32 msglevel)
  377. {
  378. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  379. pdata->msg_enable = msglevel;
  380. }
  381. static int xgbe_get_coalesce(struct net_device *netdev,
  382. struct ethtool_coalesce *ec,
  383. struct kernel_ethtool_coalesce *kernel_coal,
  384. struct netlink_ext_ack *extack)
  385. {
  386. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  387. memset(ec, 0, sizeof(struct ethtool_coalesce));
  388. ec->rx_coalesce_usecs = pdata->rx_usecs;
  389. ec->rx_max_coalesced_frames = pdata->rx_frames;
  390. ec->tx_max_coalesced_frames = pdata->tx_frames;
  391. return 0;
  392. }
  393. static int xgbe_set_coalesce(struct net_device *netdev,
  394. struct ethtool_coalesce *ec,
  395. struct kernel_ethtool_coalesce *kernel_coal,
  396. struct netlink_ext_ack *extack)
  397. {
  398. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  399. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  400. unsigned int rx_frames, rx_riwt, rx_usecs;
  401. unsigned int tx_frames;
  402. rx_riwt = hw_if->usec_to_riwt(pdata, ec->rx_coalesce_usecs);
  403. rx_usecs = ec->rx_coalesce_usecs;
  404. rx_frames = ec->rx_max_coalesced_frames;
  405. /* Use smallest possible value if conversion resulted in zero */
  406. if (rx_usecs && !rx_riwt)
  407. rx_riwt = 1;
  408. /* Check the bounds of values for Rx */
  409. if (rx_riwt > XGMAC_MAX_DMA_RIWT) {
  410. netdev_err(netdev, "rx-usec is limited to %d usecs\n",
  411. hw_if->riwt_to_usec(pdata, XGMAC_MAX_DMA_RIWT));
  412. return -EINVAL;
  413. }
  414. if (rx_frames > pdata->rx_desc_count) {
  415. netdev_err(netdev, "rx-frames is limited to %d frames\n",
  416. pdata->rx_desc_count);
  417. return -EINVAL;
  418. }
  419. tx_frames = ec->tx_max_coalesced_frames;
  420. /* Check the bounds of values for Tx */
  421. if (tx_frames > pdata->tx_desc_count) {
  422. netdev_err(netdev, "tx-frames is limited to %d frames\n",
  423. pdata->tx_desc_count);
  424. return -EINVAL;
  425. }
  426. pdata->rx_riwt = rx_riwt;
  427. pdata->rx_usecs = rx_usecs;
  428. pdata->rx_frames = rx_frames;
  429. hw_if->config_rx_coalesce(pdata);
  430. pdata->tx_frames = tx_frames;
  431. hw_if->config_tx_coalesce(pdata);
  432. return 0;
  433. }
  434. static int xgbe_get_rxnfc(struct net_device *netdev,
  435. struct ethtool_rxnfc *rxnfc, u32 *rule_locs)
  436. {
  437. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  438. switch (rxnfc->cmd) {
  439. case ETHTOOL_GRXRINGS:
  440. rxnfc->data = pdata->rx_ring_count;
  441. break;
  442. default:
  443. return -EOPNOTSUPP;
  444. }
  445. return 0;
  446. }
  447. static u32 xgbe_get_rxfh_key_size(struct net_device *netdev)
  448. {
  449. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  450. return sizeof(pdata->rss_key);
  451. }
  452. static u32 xgbe_get_rxfh_indir_size(struct net_device *netdev)
  453. {
  454. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  455. return ARRAY_SIZE(pdata->rss_table);
  456. }
  457. static int xgbe_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
  458. u8 *hfunc)
  459. {
  460. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  461. unsigned int i;
  462. if (indir) {
  463. for (i = 0; i < ARRAY_SIZE(pdata->rss_table); i++)
  464. indir[i] = XGMAC_GET_BITS(pdata->rss_table[i],
  465. MAC_RSSDR, DMCH);
  466. }
  467. if (key)
  468. memcpy(key, pdata->rss_key, sizeof(pdata->rss_key));
  469. if (hfunc)
  470. *hfunc = ETH_RSS_HASH_TOP;
  471. return 0;
  472. }
  473. static int xgbe_set_rxfh(struct net_device *netdev, const u32 *indir,
  474. const u8 *key, const u8 hfunc)
  475. {
  476. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  477. struct xgbe_hw_if *hw_if = &pdata->hw_if;
  478. unsigned int ret;
  479. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP) {
  480. netdev_err(netdev, "unsupported hash function\n");
  481. return -EOPNOTSUPP;
  482. }
  483. if (indir) {
  484. ret = hw_if->set_rss_lookup_table(pdata, indir);
  485. if (ret)
  486. return ret;
  487. }
  488. if (key) {
  489. ret = hw_if->set_rss_hash_key(pdata, key);
  490. if (ret)
  491. return ret;
  492. }
  493. return 0;
  494. }
  495. static int xgbe_get_ts_info(struct net_device *netdev,
  496. struct ethtool_ts_info *ts_info)
  497. {
  498. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  499. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  500. SOF_TIMESTAMPING_RX_SOFTWARE |
  501. SOF_TIMESTAMPING_SOFTWARE |
  502. SOF_TIMESTAMPING_TX_HARDWARE |
  503. SOF_TIMESTAMPING_RX_HARDWARE |
  504. SOF_TIMESTAMPING_RAW_HARDWARE;
  505. if (pdata->ptp_clock)
  506. ts_info->phc_index = ptp_clock_index(pdata->ptp_clock);
  507. else
  508. ts_info->phc_index = -1;
  509. ts_info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
  510. ts_info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
  511. (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
  512. (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
  513. (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
  514. (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
  515. (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
  516. (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
  517. (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
  518. (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
  519. (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
  520. (1 << HWTSTAMP_FILTER_ALL);
  521. return 0;
  522. }
  523. static int xgbe_get_module_info(struct net_device *netdev,
  524. struct ethtool_modinfo *modinfo)
  525. {
  526. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  527. return pdata->phy_if.module_info(pdata, modinfo);
  528. }
  529. static int xgbe_get_module_eeprom(struct net_device *netdev,
  530. struct ethtool_eeprom *eeprom, u8 *data)
  531. {
  532. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  533. return pdata->phy_if.module_eeprom(pdata, eeprom, data);
  534. }
  535. static void
  536. xgbe_get_ringparam(struct net_device *netdev,
  537. struct ethtool_ringparam *ringparam,
  538. struct kernel_ethtool_ringparam *kernel_ringparam,
  539. struct netlink_ext_ack *extack)
  540. {
  541. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  542. ringparam->rx_max_pending = XGBE_RX_DESC_CNT_MAX;
  543. ringparam->tx_max_pending = XGBE_TX_DESC_CNT_MAX;
  544. ringparam->rx_pending = pdata->rx_desc_count;
  545. ringparam->tx_pending = pdata->tx_desc_count;
  546. }
  547. static int xgbe_set_ringparam(struct net_device *netdev,
  548. struct ethtool_ringparam *ringparam,
  549. struct kernel_ethtool_ringparam *kernel_ringparam,
  550. struct netlink_ext_ack *extack)
  551. {
  552. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  553. unsigned int rx, tx;
  554. if (ringparam->rx_mini_pending || ringparam->rx_jumbo_pending) {
  555. netdev_err(netdev, "unsupported ring parameter\n");
  556. return -EINVAL;
  557. }
  558. if ((ringparam->rx_pending < XGBE_RX_DESC_CNT_MIN) ||
  559. (ringparam->rx_pending > XGBE_RX_DESC_CNT_MAX)) {
  560. netdev_err(netdev,
  561. "rx ring parameter must be between %u and %u\n",
  562. XGBE_RX_DESC_CNT_MIN, XGBE_RX_DESC_CNT_MAX);
  563. return -EINVAL;
  564. }
  565. if ((ringparam->tx_pending < XGBE_TX_DESC_CNT_MIN) ||
  566. (ringparam->tx_pending > XGBE_TX_DESC_CNT_MAX)) {
  567. netdev_err(netdev,
  568. "tx ring parameter must be between %u and %u\n",
  569. XGBE_TX_DESC_CNT_MIN, XGBE_TX_DESC_CNT_MAX);
  570. return -EINVAL;
  571. }
  572. rx = __rounddown_pow_of_two(ringparam->rx_pending);
  573. if (rx != ringparam->rx_pending)
  574. netdev_notice(netdev,
  575. "rx ring parameter rounded to power of two: %u\n",
  576. rx);
  577. tx = __rounddown_pow_of_two(ringparam->tx_pending);
  578. if (tx != ringparam->tx_pending)
  579. netdev_notice(netdev,
  580. "tx ring parameter rounded to power of two: %u\n",
  581. tx);
  582. if ((rx == pdata->rx_desc_count) &&
  583. (tx == pdata->tx_desc_count))
  584. goto out;
  585. pdata->rx_desc_count = rx;
  586. pdata->tx_desc_count = tx;
  587. xgbe_restart_dev(pdata);
  588. out:
  589. return 0;
  590. }
  591. static void xgbe_get_channels(struct net_device *netdev,
  592. struct ethtool_channels *channels)
  593. {
  594. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  595. unsigned int rx, tx, combined;
  596. /* Calculate maximums allowed:
  597. * - Take into account the number of available IRQs
  598. * - Do not take into account the number of online CPUs so that
  599. * the user can over-subscribe if desired
  600. * - Tx is additionally limited by the number of hardware queues
  601. */
  602. rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
  603. rx = min(rx, pdata->channel_irq_count);
  604. tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
  605. tx = min(tx, pdata->channel_irq_count);
  606. tx = min(tx, pdata->tx_max_q_count);
  607. combined = min(rx, tx);
  608. channels->max_combined = combined;
  609. channels->max_rx = rx ? rx - 1 : 0;
  610. channels->max_tx = tx ? tx - 1 : 0;
  611. /* Get current settings based on device state */
  612. rx = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
  613. tx = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
  614. combined = min(rx, tx);
  615. rx -= combined;
  616. tx -= combined;
  617. channels->combined_count = combined;
  618. channels->rx_count = rx;
  619. channels->tx_count = tx;
  620. }
  621. static void xgbe_print_set_channels_input(struct net_device *netdev,
  622. struct ethtool_channels *channels)
  623. {
  624. netdev_err(netdev, "channel inputs: combined=%u, rx-only=%u, tx-only=%u\n",
  625. channels->combined_count, channels->rx_count,
  626. channels->tx_count);
  627. }
  628. static int xgbe_set_channels(struct net_device *netdev,
  629. struct ethtool_channels *channels)
  630. {
  631. struct xgbe_prv_data *pdata = netdev_priv(netdev);
  632. unsigned int rx, rx_curr, tx, tx_curr, combined;
  633. /* Calculate maximums allowed:
  634. * - Take into account the number of available IRQs
  635. * - Do not take into account the number of online CPUs so that
  636. * the user can over-subscribe if desired
  637. * - Tx is additionally limited by the number of hardware queues
  638. */
  639. rx = min(pdata->hw_feat.rx_ch_cnt, pdata->rx_max_channel_count);
  640. rx = min(rx, pdata->channel_irq_count);
  641. tx = min(pdata->hw_feat.tx_ch_cnt, pdata->tx_max_channel_count);
  642. tx = min(tx, pdata->tx_max_q_count);
  643. tx = min(tx, pdata->channel_irq_count);
  644. combined = min(rx, tx);
  645. /* Should not be setting other count */
  646. if (channels->other_count) {
  647. netdev_err(netdev,
  648. "other channel count must be zero\n");
  649. return -EINVAL;
  650. }
  651. /* Require at least one Combined (Rx and Tx) channel */
  652. if (!channels->combined_count) {
  653. netdev_err(netdev,
  654. "at least one combined Rx/Tx channel is required\n");
  655. xgbe_print_set_channels_input(netdev, channels);
  656. return -EINVAL;
  657. }
  658. /* Check combined channels */
  659. if (channels->combined_count > combined) {
  660. netdev_err(netdev,
  661. "combined channel count cannot exceed %u\n",
  662. combined);
  663. xgbe_print_set_channels_input(netdev, channels);
  664. return -EINVAL;
  665. }
  666. /* Can have some Rx-only or Tx-only channels, but not both */
  667. if (channels->rx_count && channels->tx_count) {
  668. netdev_err(netdev,
  669. "cannot specify both Rx-only and Tx-only channels\n");
  670. xgbe_print_set_channels_input(netdev, channels);
  671. return -EINVAL;
  672. }
  673. /* Check that we don't exceed the maximum number of channels */
  674. if ((channels->combined_count + channels->rx_count) > rx) {
  675. netdev_err(netdev,
  676. "total Rx channels (%u) requested exceeds maximum available (%u)\n",
  677. channels->combined_count + channels->rx_count, rx);
  678. xgbe_print_set_channels_input(netdev, channels);
  679. return -EINVAL;
  680. }
  681. if ((channels->combined_count + channels->tx_count) > tx) {
  682. netdev_err(netdev,
  683. "total Tx channels (%u) requested exceeds maximum available (%u)\n",
  684. channels->combined_count + channels->tx_count, tx);
  685. xgbe_print_set_channels_input(netdev, channels);
  686. return -EINVAL;
  687. }
  688. rx = channels->combined_count + channels->rx_count;
  689. tx = channels->combined_count + channels->tx_count;
  690. rx_curr = pdata->new_rx_ring_count ? : pdata->rx_ring_count;
  691. tx_curr = pdata->new_tx_ring_count ? : pdata->tx_ring_count;
  692. if ((rx == rx_curr) && (tx == tx_curr))
  693. goto out;
  694. pdata->new_rx_ring_count = rx;
  695. pdata->new_tx_ring_count = tx;
  696. xgbe_full_restart_dev(pdata);
  697. out:
  698. return 0;
  699. }
  700. static const struct ethtool_ops xgbe_ethtool_ops = {
  701. .supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS |
  702. ETHTOOL_COALESCE_MAX_FRAMES,
  703. .get_drvinfo = xgbe_get_drvinfo,
  704. .get_msglevel = xgbe_get_msglevel,
  705. .set_msglevel = xgbe_set_msglevel,
  706. .get_link = ethtool_op_get_link,
  707. .get_coalesce = xgbe_get_coalesce,
  708. .set_coalesce = xgbe_set_coalesce,
  709. .get_pauseparam = xgbe_get_pauseparam,
  710. .set_pauseparam = xgbe_set_pauseparam,
  711. .get_strings = xgbe_get_strings,
  712. .get_ethtool_stats = xgbe_get_ethtool_stats,
  713. .get_sset_count = xgbe_get_sset_count,
  714. .get_rxnfc = xgbe_get_rxnfc,
  715. .get_rxfh_key_size = xgbe_get_rxfh_key_size,
  716. .get_rxfh_indir_size = xgbe_get_rxfh_indir_size,
  717. .get_rxfh = xgbe_get_rxfh,
  718. .set_rxfh = xgbe_set_rxfh,
  719. .get_ts_info = xgbe_get_ts_info,
  720. .get_link_ksettings = xgbe_get_link_ksettings,
  721. .set_link_ksettings = xgbe_set_link_ksettings,
  722. .get_module_info = xgbe_get_module_info,
  723. .get_module_eeprom = xgbe_get_module_eeprom,
  724. .get_ringparam = xgbe_get_ringparam,
  725. .set_ringparam = xgbe_set_ringparam,
  726. .get_channels = xgbe_get_channels,
  727. .set_channels = xgbe_set_channels,
  728. };
  729. const struct ethtool_ops *xgbe_get_ethtool_ops(void)
  730. {
  731. return &xgbe_ethtool_ops;
  732. }