2 * aQuantia Corporation Network Driver
3 * Copyright (C) 2014-2017 aQuantia Corporation. All rights reserved
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
10 /* File aq_ethtool.c: Definition of ethertool related functions. */
12 #include "aq_ethtool.h"
15 static void aq_ethtool_get_regs(struct net_device
*ndev
,
16 struct ethtool_regs
*regs
, void *p
)
18 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
19 u32 regs_count
= aq_nic_get_regs_count(aq_nic
);
21 memset(p
, 0, regs_count
* sizeof(u32
));
22 aq_nic_get_regs(aq_nic
, regs
, p
);
25 static int aq_ethtool_get_regs_len(struct net_device
*ndev
)
27 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
28 u32 regs_count
= aq_nic_get_regs_count(aq_nic
);
30 return regs_count
* sizeof(u32
);
33 static u32
aq_ethtool_get_link(struct net_device
*ndev
)
35 return ethtool_op_get_link(ndev
);
38 static int aq_ethtool_get_link_ksettings(struct net_device
*ndev
,
39 struct ethtool_link_ksettings
*cmd
)
41 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
43 aq_nic_get_link_ksettings(aq_nic
, cmd
);
44 cmd
->base
.speed
= netif_carrier_ok(ndev
) ?
45 aq_nic_get_link_speed(aq_nic
) : 0U;
51 aq_ethtool_set_link_ksettings(struct net_device
*ndev
,
52 const struct ethtool_link_ksettings
*cmd
)
54 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
56 return aq_nic_set_link_ksettings(aq_nic
, cmd
);
59 static const char aq_ethtool_stat_names
[][ETH_GSTRING_LEN
] = {
84 static const char aq_ethtool_queue_stat_names
[][ETH_GSTRING_LEN
] = {
85 "Queue[%d] InPackets",
86 "Queue[%d] OutPackets",
88 "Queue[%d] InJumboPackets",
89 "Queue[%d] InLroPackets",
93 static void aq_ethtool_stats(struct net_device
*ndev
,
94 struct ethtool_stats
*stats
, u64
*data
)
96 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
97 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
99 memset(data
, 0, (ARRAY_SIZE(aq_ethtool_stat_names
) +
100 ARRAY_SIZE(aq_ethtool_queue_stat_names
) *
101 cfg
->vecs
) * sizeof(u64
));
102 aq_nic_get_stats(aq_nic
, data
);
105 static void aq_ethtool_get_drvinfo(struct net_device
*ndev
,
106 struct ethtool_drvinfo
*drvinfo
)
108 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
109 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
110 struct pci_dev
*pdev
= to_pci_dev(ndev
->dev
.parent
);
111 u32 firmware_version
= aq_nic_get_fw_version(aq_nic
);
112 u32 regs_count
= aq_nic_get_regs_count(aq_nic
);
114 strlcat(drvinfo
->driver
, AQ_CFG_DRV_NAME
, sizeof(drvinfo
->driver
));
115 strlcat(drvinfo
->version
, AQ_CFG_DRV_VERSION
, sizeof(drvinfo
->version
));
117 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
118 "%u.%u.%u", firmware_version
>> 24,
119 (firmware_version
>> 16) & 0xFFU
, firmware_version
& 0xFFFFU
);
121 strlcpy(drvinfo
->bus_info
, pdev
? pci_name(pdev
) : "",
122 sizeof(drvinfo
->bus_info
));
123 drvinfo
->n_stats
= ARRAY_SIZE(aq_ethtool_stat_names
) +
124 cfg
->vecs
* ARRAY_SIZE(aq_ethtool_queue_stat_names
);
125 drvinfo
->testinfo_len
= 0;
126 drvinfo
->regdump_len
= regs_count
;
127 drvinfo
->eedump_len
= 0;
130 static void aq_ethtool_get_strings(struct net_device
*ndev
,
131 u32 stringset
, u8
*data
)
134 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
135 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
138 if (stringset
== ETH_SS_STATS
) {
139 memcpy(p
, *aq_ethtool_stat_names
,
140 sizeof(aq_ethtool_stat_names
));
141 p
= p
+ sizeof(aq_ethtool_stat_names
);
142 for (i
= 0; i
< cfg
->vecs
; i
++) {
144 si
< ARRAY_SIZE(aq_ethtool_queue_stat_names
);
146 snprintf(p
, ETH_GSTRING_LEN
,
147 aq_ethtool_queue_stat_names
[si
], i
);
148 p
+= ETH_GSTRING_LEN
;
154 static int aq_ethtool_get_sset_count(struct net_device
*ndev
, int stringset
)
157 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
158 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
162 ret
= ARRAY_SIZE(aq_ethtool_stat_names
) +
163 cfg
->vecs
* ARRAY_SIZE(aq_ethtool_queue_stat_names
);
171 static u32
aq_ethtool_get_rss_indir_size(struct net_device
*ndev
)
173 return AQ_CFG_RSS_INDIRECTION_TABLE_MAX
;
176 static u32
aq_ethtool_get_rss_key_size(struct net_device
*ndev
)
178 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
179 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
181 return sizeof(cfg
->aq_rss
.hash_secret_key
);
184 static int aq_ethtool_get_rss(struct net_device
*ndev
, u32
*indir
, u8
*key
,
187 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
188 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
192 *hfunc
= ETH_RSS_HASH_TOP
; /* Toeplitz */
194 for (i
= 0; i
< AQ_CFG_RSS_INDIRECTION_TABLE_MAX
; i
++)
195 indir
[i
] = cfg
->aq_rss
.indirection_table
[i
];
198 memcpy(key
, cfg
->aq_rss
.hash_secret_key
,
199 sizeof(cfg
->aq_rss
.hash_secret_key
));
203 static int aq_ethtool_get_rxnfc(struct net_device
*ndev
,
204 struct ethtool_rxnfc
*cmd
,
207 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
208 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
212 case ETHTOOL_GRXRINGS
:
213 cmd
->data
= cfg
->vecs
;
224 static int aq_ethtool_get_coalesce(struct net_device
*ndev
,
225 struct ethtool_coalesce
*coal
)
227 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
228 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
230 if (cfg
->itr
== AQ_CFG_INTERRUPT_MODERATION_ON
||
231 cfg
->itr
== AQ_CFG_INTERRUPT_MODERATION_AUTO
) {
232 coal
->rx_coalesce_usecs
= cfg
->rx_itr
;
233 coal
->tx_coalesce_usecs
= cfg
->tx_itr
;
234 coal
->rx_max_coalesced_frames
= 0;
235 coal
->tx_max_coalesced_frames
= 0;
237 coal
->rx_coalesce_usecs
= 0;
238 coal
->tx_coalesce_usecs
= 0;
239 coal
->rx_max_coalesced_frames
= 1;
240 coal
->tx_max_coalesced_frames
= 1;
245 static int aq_ethtool_set_coalesce(struct net_device
*ndev
,
246 struct ethtool_coalesce
*coal
)
248 struct aq_nic_s
*aq_nic
= netdev_priv(ndev
);
249 struct aq_nic_cfg_s
*cfg
= aq_nic_get_cfg(aq_nic
);
251 /* This is not yet supported
253 if (coal
->use_adaptive_rx_coalesce
|| coal
->use_adaptive_tx_coalesce
)
256 /* Atlantic only supports timing based coalescing
258 if (coal
->rx_max_coalesced_frames
> 1 ||
259 coal
->rx_coalesce_usecs_irq
||
260 coal
->rx_max_coalesced_frames_irq
)
263 if (coal
->tx_max_coalesced_frames
> 1 ||
264 coal
->tx_coalesce_usecs_irq
||
265 coal
->tx_max_coalesced_frames_irq
)
268 /* We do not support frame counting. Check this
270 if (!(coal
->rx_max_coalesced_frames
== !coal
->rx_coalesce_usecs
))
272 if (!(coal
->tx_max_coalesced_frames
== !coal
->tx_coalesce_usecs
))
275 if (coal
->rx_coalesce_usecs
> AQ_CFG_INTERRUPT_MODERATION_USEC_MAX
||
276 coal
->tx_coalesce_usecs
> AQ_CFG_INTERRUPT_MODERATION_USEC_MAX
)
279 cfg
->itr
= AQ_CFG_INTERRUPT_MODERATION_ON
;
281 cfg
->rx_itr
= coal
->rx_coalesce_usecs
;
282 cfg
->tx_itr
= coal
->tx_coalesce_usecs
;
284 return aq_nic_update_interrupt_moderation_settings(aq_nic
);
287 const struct ethtool_ops aq_ethtool_ops
= {
288 .get_link
= aq_ethtool_get_link
,
289 .get_regs_len
= aq_ethtool_get_regs_len
,
290 .get_regs
= aq_ethtool_get_regs
,
291 .get_drvinfo
= aq_ethtool_get_drvinfo
,
292 .get_strings
= aq_ethtool_get_strings
,
293 .get_rxfh_indir_size
= aq_ethtool_get_rss_indir_size
,
294 .get_rxfh_key_size
= aq_ethtool_get_rss_key_size
,
295 .get_rxfh
= aq_ethtool_get_rss
,
296 .get_rxnfc
= aq_ethtool_get_rxnfc
,
297 .get_sset_count
= aq_ethtool_get_sset_count
,
298 .get_ethtool_stats
= aq_ethtool_stats
,
299 .get_link_ksettings
= aq_ethtool_get_link_ksettings
,
300 .set_link_ksettings
= aq_ethtool_set_link_ksettings
,
301 .get_coalesce
= aq_ethtool_get_coalesce
,
302 .set_coalesce
= aq_ethtool_set_coalesce
,