Skip to content

Commit fcea6f3

Browse files
refactormanJeff Kirsher
authored and
Jeff Kirsher
committed
ice: Add stats and ethtool support
This patch implements a watchdog task to get packet statistics from the device. This patch also adds support for the following ethtool operations: ethtool devname ethtool -s devname [msglvl N] [msglevel type on|off] ethtool -g|--show-ring devname ethtool -G|--set-ring devname [rx N] [tx N] ethtool -i|--driver devname ethtool -d|--register-dump devname [raw on|off] [hex on|off] [file name] ethtool -k|--show-features|--show-offload devname ethtool -K|--features|--offload devname feature on|off ethtool -P|--show-permaddr devname ethtool -S|--statistics devname ethtool -a|--show-pause devname ethtool -A|--pause devname [autoneg on|off] [rx on|off] [tx on|off] ethtool -r|--negotiate devname CC: Andrew Lunn <[email protected]> CC: Jakub Kicinski <[email protected]> CC: Stephen Hemminger <[email protected]> Signed-off-by: Anirudh Venkataramanan <[email protected]> Acked-by: Stephen Hemminger <[email protected]> Tested-by: Tony Brelinski <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent d76a60b commit fcea6f3

File tree

9 files changed

+1828
-5
lines changed

9 files changed

+1828
-5
lines changed

drivers/net/ethernet/intel/ice/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ ice-y := ice_main.o \
1313
ice_nvm.o \
1414
ice_switch.o \
1515
ice_sched.o \
16-
ice_txrx.o
16+
ice_txrx.o \
17+
ice_ethtool.o

drivers/net/ethernet/intel/ice/ice.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
#include <linux/etherdevice.h>
1414
#include <linux/skbuff.h>
1515
#include <linux/cpumask.h>
16+
#include <linux/rtnetlink.h>
1617
#include <linux/if_vlan.h>
1718
#include <linux/dma-mapping.h>
1819
#include <linux/pci.h>
1920
#include <linux/workqueue.h>
2021
#include <linux/aer.h>
2122
#include <linux/interrupt.h>
23+
#include <linux/ethtool.h>
2224
#include <linux/timer.h>
2325
#include <linux/delay.h>
2426
#include <linux/bitmap.h>
@@ -34,10 +36,14 @@
3436
#include "ice_common.h"
3537
#include "ice_sched.h"
3638

39+
extern const char ice_drv_ver[];
3740
#define ICE_BAR0 0
3841
#define ICE_DFLT_NUM_DESC 128
42+
#define ICE_MIN_NUM_DESC 8
43+
#define ICE_MAX_NUM_DESC 8160
3944
#define ICE_REQ_DESC_MULTIPLE 32
4045
#define ICE_INT_NAME_STR_LEN (IFNAMSIZ + 16)
46+
#define ICE_ETHTOOL_FWVER_LEN 32
4147
#define ICE_AQ_LEN 64
4248
#define ICE_MIN_MSIX 2
4349
#define ICE_NO_VSI 0xffff
@@ -56,6 +62,8 @@
5662
#define ICE_RES_MISC_VEC_ID (ICE_RES_VALID_BIT - 1)
5763
#define ICE_INVAL_Q_INDEX 0xffff
5864

65+
#define ICE_VSIQF_HKEY_ARRAY_SIZE ((VSIQF_HKEY_MAX_INDEX + 1) * 4)
66+
5967
#define ICE_DFLT_NETIF_M (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
6068

6169
#define ICE_MAX_MTU (ICE_AQ_SET_MAC_FRAME_SIZE_MAX - \
@@ -102,6 +110,7 @@ enum ice_state {
102110
__ICE_DOWN,
103111
__ICE_PFR_REQ, /* set by driver and peers */
104112
__ICE_ADMINQ_EVENT_PENDING,
113+
__ICE_CFG_BUSY,
105114
__ICE_SERVICE_SCHED,
106115
__ICE_STATE_NBITS /* must be last */
107116
};
@@ -118,8 +127,13 @@ struct ice_vsi {
118127

119128
irqreturn_t (*irq_handler)(int irq, void *data);
120129

130+
u64 tx_linearize;
121131
DECLARE_BITMAP(state, __ICE_STATE_NBITS);
122132
unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
133+
u32 tx_restart;
134+
u32 tx_busy;
135+
u32 rx_buf_failed;
136+
u32 rx_page_failed;
123137
int num_q_vectors;
124138
int base_vector;
125139
enum ice_vsi_type type;
@@ -141,8 +155,14 @@ struct ice_vsi {
141155

142156
struct ice_aqc_vsi_props info; /* VSI properties */
143157

158+
/* VSI stats */
159+
struct rtnl_link_stats64 net_stats;
160+
struct ice_eth_stats eth_stats;
161+
struct ice_eth_stats eth_stats_prev;
162+
144163
bool irqs_ready;
145164
bool current_isup; /* Sync 'link up' logging */
165+
bool stat_offsets_loaded;
146166

147167
/* queue information */
148168
u8 tx_mapping_mode; /* ICE_MAP_MODE_[CONTIG|SCATTER] */
@@ -205,8 +225,10 @@ struct ice_pf {
205225
u16 q_left_rx; /* remaining num rx queues left unclaimed */
206226
u16 next_vsi; /* Next free slot in pf->vsi[] - 0-based! */
207227
u16 num_alloc_vsi;
208-
228+
struct ice_hw_port_stats stats;
229+
struct ice_hw_port_stats stats_prev;
209230
struct ice_hw hw;
231+
bool stat_prev_loaded; /* has previous stats been loaded */
210232
char int_name[ICE_INT_NAME_STR_LEN];
211233
};
212234

@@ -239,8 +261,12 @@ static inline void ice_irq_dynamic_ena(struct ice_hw *hw, struct ice_vsi *vsi,
239261
wr32(hw, GLINT_DYN_CTL(vector), val);
240262
}
241263

264+
void ice_set_ethtool_ops(struct net_device *netdev);
265+
int ice_up(struct ice_vsi *vsi);
266+
int ice_down(struct ice_vsi *vsi);
242267
int ice_set_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
243268
int ice_get_rss(struct ice_vsi *vsi, u8 *seed, u8 *lut, u16 lut_size);
244269
void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size);
270+
void ice_print_link_msg(struct ice_vsi *vsi, bool isup);
245271

246272
#endif /* _ICE_H_ */

drivers/net/ethernet/intel/ice/ice_adminq_cmd.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,45 @@ struct ice_aqc_get_phy_caps_data {
859859
} qual_modules[ICE_AQC_QUAL_MOD_COUNT_MAX];
860860
};
861861

862+
/* Set PHY capabilities (direct 0x0601)
863+
* NOTE: This command must be followed by setup link and restart auto-neg
864+
*/
865+
struct ice_aqc_set_phy_cfg {
866+
u8 lport_num;
867+
u8 reserved[7];
868+
__le32 addr_high;
869+
__le32 addr_low;
870+
};
871+
872+
/* Set PHY config command data structure */
873+
struct ice_aqc_set_phy_cfg_data {
874+
__le64 phy_type_low; /* Use values from ICE_PHY_TYPE_LOW_* */
875+
__le64 rsvd0;
876+
u8 caps;
877+
#define ICE_AQ_PHY_ENA_TX_PAUSE_ABILITY BIT(0)
878+
#define ICE_AQ_PHY_ENA_RX_PAUSE_ABILITY BIT(1)
879+
#define ICE_AQ_PHY_ENA_LOW_POWER BIT(2)
880+
#define ICE_AQ_PHY_ENA_LINK BIT(3)
881+
#define ICE_AQ_PHY_ENA_ATOMIC_LINK BIT(5)
882+
u8 low_power_ctrl;
883+
__le16 eee_cap; /* Value from ice_aqc_get_phy_caps */
884+
__le16 eeer_value;
885+
u8 link_fec_opt; /* Use defines from ice_aqc_get_phy_caps */
886+
u8 rsvd1;
887+
};
888+
889+
/* Restart AN command data structure (direct 0x0605)
890+
* Also used for response, with only the lport_num field present.
891+
*/
892+
struct ice_aqc_restart_an {
893+
u8 lport_num;
894+
u8 reserved;
895+
u8 cmd_flags;
896+
#define ICE_AQC_RESTART_AN_LINK_RESTART BIT(1)
897+
#define ICE_AQC_RESTART_AN_LINK_ENABLE BIT(2)
898+
u8 reserved2[13];
899+
};
900+
862901
/* Get link status (indirect 0x0607), also used for Link Status Event */
863902
struct ice_aqc_get_link_status {
864903
u8 lport_num;
@@ -1137,6 +1176,8 @@ struct ice_aq_desc {
11371176
struct ice_aqc_clear_pxe clear_pxe;
11381177
struct ice_aqc_list_caps get_cap;
11391178
struct ice_aqc_get_phy_caps get_phy;
1179+
struct ice_aqc_set_phy_cfg set_phy;
1180+
struct ice_aqc_restart_an restart_an;
11401181
struct ice_aqc_get_sw_cfg get_sw_conf;
11411182
struct ice_aqc_sw_rules sw_rules;
11421183
struct ice_aqc_get_topo get_topo;
@@ -1222,6 +1263,8 @@ enum ice_adminq_opc {
12221263

12231264
/* PHY commands */
12241265
ice_aqc_opc_get_phy_caps = 0x0600,
1266+
ice_aqc_opc_set_phy_cfg = 0x0601,
1267+
ice_aqc_opc_restart_an = 0x0605,
12251268
ice_aqc_opc_get_link_status = 0x0607,
12261269

12271270
/* NVM commands */

drivers/net/ethernet/intel/ice/ice_common.c

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,201 @@ void ice_clear_pxe_mode(struct ice_hw *hw)
12611261
ice_aq_clear_pxe_mode(hw);
12621262
}
12631263

1264+
/**
1265+
* ice_aq_set_phy_cfg
1266+
* @hw: pointer to the hw struct
1267+
* @lport: logical port number
1268+
* @cfg: structure with PHY configuration data to be set
1269+
* @cd: pointer to command details structure or NULL
1270+
*
1271+
* Set the various PHY configuration parameters supported on the Port.
1272+
* One or more of the Set PHY config parameters may be ignored in an MFP
1273+
* mode as the PF may not have the privilege to set some of the PHY Config
1274+
* parameters. This status will be indicated by the command response (0x0601).
1275+
*/
1276+
static enum ice_status
1277+
ice_aq_set_phy_cfg(struct ice_hw *hw, u8 lport,
1278+
struct ice_aqc_set_phy_cfg_data *cfg, struct ice_sq_cd *cd)
1279+
{
1280+
struct ice_aqc_set_phy_cfg *cmd;
1281+
struct ice_aq_desc desc;
1282+
1283+
if (!cfg)
1284+
return ICE_ERR_PARAM;
1285+
1286+
cmd = &desc.params.set_phy;
1287+
ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_set_phy_cfg);
1288+
cmd->lport_num = lport;
1289+
1290+
return ice_aq_send_cmd(hw, &desc, cfg, sizeof(*cfg), cd);
1291+
}
1292+
1293+
/**
1294+
* ice_update_link_info - update status of the HW network link
1295+
* @pi: port info structure of the interested logical port
1296+
*/
1297+
static enum ice_status
1298+
ice_update_link_info(struct ice_port_info *pi)
1299+
{
1300+
struct ice_aqc_get_phy_caps_data *pcaps;
1301+
struct ice_phy_info *phy_info;
1302+
enum ice_status status;
1303+
struct ice_hw *hw;
1304+
1305+
if (!pi)
1306+
return ICE_ERR_PARAM;
1307+
1308+
hw = pi->hw;
1309+
1310+
pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
1311+
if (!pcaps)
1312+
return ICE_ERR_NO_MEMORY;
1313+
1314+
phy_info = &pi->phy;
1315+
status = ice_aq_get_link_info(pi, true, NULL, NULL);
1316+
if (status)
1317+
goto out;
1318+
1319+
if (phy_info->link_info.link_info & ICE_AQ_MEDIA_AVAILABLE) {
1320+
status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG,
1321+
pcaps, NULL);
1322+
if (status)
1323+
goto out;
1324+
1325+
memcpy(phy_info->link_info.module_type, &pcaps->module_type,
1326+
sizeof(phy_info->link_info.module_type));
1327+
}
1328+
out:
1329+
devm_kfree(ice_hw_to_dev(hw), pcaps);
1330+
return status;
1331+
}
1332+
1333+
/**
1334+
* ice_set_fc
1335+
* @pi: port information structure
1336+
* @aq_failures: pointer to status code, specific to ice_set_fc routine
1337+
* @atomic_restart: enable automatic link update
1338+
*
1339+
* Set the requested flow control mode.
1340+
*/
1341+
enum ice_status
1342+
ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool atomic_restart)
1343+
{
1344+
struct ice_aqc_set_phy_cfg_data cfg = { 0 };
1345+
struct ice_aqc_get_phy_caps_data *pcaps;
1346+
enum ice_status status;
1347+
u8 pause_mask = 0x0;
1348+
struct ice_hw *hw;
1349+
1350+
if (!pi)
1351+
return ICE_ERR_PARAM;
1352+
hw = pi->hw;
1353+
*aq_failures = ICE_SET_FC_AQ_FAIL_NONE;
1354+
1355+
switch (pi->fc.req_mode) {
1356+
case ICE_FC_FULL:
1357+
pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
1358+
pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
1359+
break;
1360+
case ICE_FC_RX_PAUSE:
1361+
pause_mask |= ICE_AQC_PHY_EN_RX_LINK_PAUSE;
1362+
break;
1363+
case ICE_FC_TX_PAUSE:
1364+
pause_mask |= ICE_AQC_PHY_EN_TX_LINK_PAUSE;
1365+
break;
1366+
default:
1367+
break;
1368+
}
1369+
1370+
pcaps = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*pcaps), GFP_KERNEL);
1371+
if (!pcaps)
1372+
return ICE_ERR_NO_MEMORY;
1373+
1374+
/* Get the current phy config */
1375+
status = ice_aq_get_phy_caps(pi, false, ICE_AQC_REPORT_SW_CFG, pcaps,
1376+
NULL);
1377+
if (status) {
1378+
*aq_failures = ICE_SET_FC_AQ_FAIL_GET;
1379+
goto out;
1380+
}
1381+
1382+
/* clear the old pause settings */
1383+
cfg.caps = pcaps->caps & ~(ICE_AQC_PHY_EN_TX_LINK_PAUSE |
1384+
ICE_AQC_PHY_EN_RX_LINK_PAUSE);
1385+
/* set the new capabilities */
1386+
cfg.caps |= pause_mask;
1387+
/* If the capabilities have changed, then set the new config */
1388+
if (cfg.caps != pcaps->caps) {
1389+
int retry_count, retry_max = 10;
1390+
1391+
/* Auto restart link so settings take effect */
1392+
if (atomic_restart)
1393+
cfg.caps |= ICE_AQ_PHY_ENA_ATOMIC_LINK;
1394+
/* Copy over all the old settings */
1395+
cfg.phy_type_low = pcaps->phy_type_low;
1396+
cfg.low_power_ctrl = pcaps->low_power_ctrl;
1397+
cfg.eee_cap = pcaps->eee_cap;
1398+
cfg.eeer_value = pcaps->eeer_value;
1399+
cfg.link_fec_opt = pcaps->link_fec_options;
1400+
1401+
status = ice_aq_set_phy_cfg(hw, pi->lport, &cfg, NULL);
1402+
if (status) {
1403+
*aq_failures = ICE_SET_FC_AQ_FAIL_SET;
1404+
goto out;
1405+
}
1406+
1407+
/* Update the link info
1408+
* It sometimes takes a really long time for link to
1409+
* come back from the atomic reset. Thus, we wait a
1410+
* little bit.
1411+
*/
1412+
for (retry_count = 0; retry_count < retry_max; retry_count++) {
1413+
status = ice_update_link_info(pi);
1414+
1415+
if (!status)
1416+
break;
1417+
1418+
mdelay(100);
1419+
}
1420+
1421+
if (status)
1422+
*aq_failures = ICE_SET_FC_AQ_FAIL_UPDATE;
1423+
}
1424+
1425+
out:
1426+
devm_kfree(ice_hw_to_dev(hw), pcaps);
1427+
return status;
1428+
}
1429+
1430+
/**
1431+
* ice_aq_set_link_restart_an
1432+
* @pi: pointer to the port information structure
1433+
* @ena_link: if true: enable link, if false: disable link
1434+
* @cd: pointer to command details structure or NULL
1435+
*
1436+
* Sets up the link and restarts the Auto-Negotiation over the link.
1437+
*/
1438+
enum ice_status
1439+
ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
1440+
struct ice_sq_cd *cd)
1441+
{
1442+
struct ice_aqc_restart_an *cmd;
1443+
struct ice_aq_desc desc;
1444+
1445+
cmd = &desc.params.restart_an;
1446+
1447+
ice_fill_dflt_direct_cmd_desc(&desc, ice_aqc_opc_restart_an);
1448+
1449+
cmd->cmd_flags = ICE_AQC_RESTART_AN_LINK_RESTART;
1450+
cmd->lport_num = pi->lport;
1451+
if (ena_link)
1452+
cmd->cmd_flags |= ICE_AQC_RESTART_AN_LINK_ENABLE;
1453+
else
1454+
cmd->cmd_flags &= ~ICE_AQC_RESTART_AN_LINK_ENABLE;
1455+
1456+
return ice_aq_send_cmd(pi->hw, &desc, NULL, 0, cd);
1457+
}
1458+
12641459
/**
12651460
* __ice_aq_get_set_rss_lut
12661461
* @hw: pointer to the hardware structure

drivers/net/ethernet/intel/ice/ice_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ ice_aq_send_cmd(struct ice_hw *hw, struct ice_aq_desc *desc,
5858
enum ice_status ice_aq_get_fw_ver(struct ice_hw *hw, struct ice_sq_cd *cd);
5959
enum ice_status ice_clear_pf_cfg(struct ice_hw *hw);
6060
enum ice_status
61+
ice_set_fc(struct ice_port_info *pi, u8 *aq_failures, bool atomic_restart);
62+
enum ice_status
63+
ice_aq_set_link_restart_an(struct ice_port_info *pi, bool ena_link,
64+
struct ice_sq_cd *cd);
65+
enum ice_status
6166
ice_aq_get_link_info(struct ice_port_info *pi, bool ena_lse,
6267
struct ice_link_status *link, struct ice_sq_cd *cd);
6368
enum ice_status

0 commit comments

Comments
 (0)