Skip to content

Commit 0550890

Browse files
committed
Merge branch 'gve-add-rx-hw-timestamping-support'
Ziwei Xiao says: ==================== gve: Add Rx HW timestamping support This patch series add the support of Rx HW timestamping, which sends adminq commands periodically to the device for clock synchronization with the NIC. The ability to read the PHC from user space will be added in the future patch series when adding the actual PTP support. For this patch series, it's adding the initial ptp to utilize the ptp_schedule_worker to schedule the work of syncing the NIC clock. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 7768c5f + a471e7f commit 0550890

File tree

10 files changed

+396
-17
lines changed

10 files changed

+396
-17
lines changed

drivers/net/ethernet/google/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if NET_VENDOR_GOOGLE
1818
config GVE
1919
tristate "Google Virtual NIC (gVNIC) support"
2020
depends on (PCI_MSI && (X86 || CPU_LITTLE_ENDIAN))
21+
depends on PTP_1588_CLOCK_OPTIONAL
2122
select PAGE_POOL
2223
help
2324
This driver supports Google Virtual NIC (gVNIC)"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Makefile for the Google virtual Ethernet (gve) driver
22

33
obj-$(CONFIG_GVE) += gve.o
4-
gve-objs := gve_main.o gve_tx.o gve_tx_dqo.o gve_rx.o gve_rx_dqo.o gve_ethtool.o gve_adminq.o gve_utils.o gve_flow_rule.o \
4+
gve-y := gve_main.o gve_tx.o gve_tx_dqo.o gve_rx.o gve_rx_dqo.o gve_ethtool.o gve_adminq.o gve_utils.o gve_flow_rule.o \
55
gve_buffer_mgmt_dqo.o
6+
7+
gve-$(CONFIG_PTP_1588_CLOCK) += gve_ptp.o

drivers/net/ethernet/google/gve/gve.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
#include <linux/dmapool.h>
1212
#include <linux/ethtool_netlink.h>
1313
#include <linux/netdevice.h>
14+
#include <linux/net_tstamp.h>
1415
#include <linux/pci.h>
16+
#include <linux/ptp_clock_kernel.h>
1517
#include <linux/u64_stats_sync.h>
1618
#include <net/page_pool/helpers.h>
1719
#include <net/xdp.h>
@@ -750,6 +752,12 @@ struct gve_rss_config {
750752
u32 *hash_lut;
751753
};
752754

755+
struct gve_ptp {
756+
struct ptp_clock_info info;
757+
struct ptp_clock *clock;
758+
struct gve_priv *priv;
759+
};
760+
753761
struct gve_priv {
754762
struct net_device *dev;
755763
struct gve_tx_ring *tx; /* array of tx_cfg.num_queues */
@@ -813,6 +821,7 @@ struct gve_priv {
813821
u32 adminq_set_driver_parameter_cnt;
814822
u32 adminq_report_stats_cnt;
815823
u32 adminq_report_link_speed_cnt;
824+
u32 adminq_report_nic_timestamp_cnt;
816825
u32 adminq_get_ptype_map_cnt;
817826
u32 adminq_verify_driver_compatibility_cnt;
818827
u32 adminq_query_flow_rules_cnt;
@@ -870,6 +879,14 @@ struct gve_priv {
870879
u16 rss_lut_size;
871880
bool cache_rss_config;
872881
struct gve_rss_config rss_config;
882+
883+
/* True if the device supports reading the nic clock */
884+
bool nic_timestamp_supported;
885+
struct gve_ptp *ptp;
886+
struct kernel_hwtstamp_config ts_config;
887+
struct gve_nic_ts_report *nic_ts_report;
888+
dma_addr_t nic_ts_report_bus;
889+
u64 last_sync_nic_counter; /* Clock counter from last NIC TS report */
873890
};
874891

875892
enum gve_service_task_flags_bit {
@@ -1249,6 +1266,24 @@ int gve_del_flow_rule(struct gve_priv *priv, struct ethtool_rxnfc *cmd);
12491266
int gve_flow_rules_reset(struct gve_priv *priv);
12501267
/* RSS config */
12511268
int gve_init_rss_config(struct gve_priv *priv, u16 num_queues);
1269+
/* PTP and timestamping */
1270+
#if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
1271+
int gve_clock_nic_ts_read(struct gve_priv *priv);
1272+
int gve_init_clock(struct gve_priv *priv);
1273+
void gve_teardown_clock(struct gve_priv *priv);
1274+
#else /* CONFIG_PTP_1588_CLOCK */
1275+
static inline int gve_clock_nic_ts_read(struct gve_priv *priv)
1276+
{
1277+
return -EOPNOTSUPP;
1278+
}
1279+
1280+
static inline int gve_init_clock(struct gve_priv *priv)
1281+
{
1282+
return 0;
1283+
}
1284+
1285+
static inline void gve_teardown_clock(struct gve_priv *priv) { }
1286+
#endif /* CONFIG_PTP_1588_CLOCK */
12521287
/* report stats handling */
12531288
void gve_handle_report_stats(struct gve_priv *priv);
12541289
/* exported by ethtool.c */

drivers/net/ethernet/google/gve/gve_adminq.c

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void gve_parse_device_option(struct gve_priv *priv,
4646
struct gve_device_option_buffer_sizes **dev_op_buffer_sizes,
4747
struct gve_device_option_flow_steering **dev_op_flow_steering,
4848
struct gve_device_option_rss_config **dev_op_rss_config,
49+
struct gve_device_option_nic_timestamp **dev_op_nic_timestamp,
4950
struct gve_device_option_modify_ring **dev_op_modify_ring)
5051
{
5152
u32 req_feat_mask = be32_to_cpu(option->required_features_mask);
@@ -225,6 +226,23 @@ void gve_parse_device_option(struct gve_priv *priv,
225226
"RSS config");
226227
*dev_op_rss_config = (void *)(option + 1);
227228
break;
229+
case GVE_DEV_OPT_ID_NIC_TIMESTAMP:
230+
if (option_length < sizeof(**dev_op_nic_timestamp) ||
231+
req_feat_mask != GVE_DEV_OPT_REQ_FEAT_MASK_NIC_TIMESTAMP) {
232+
dev_warn(&priv->pdev->dev, GVE_DEVICE_OPTION_ERROR_FMT,
233+
"Nic Timestamp",
234+
(int)sizeof(**dev_op_nic_timestamp),
235+
GVE_DEV_OPT_REQ_FEAT_MASK_NIC_TIMESTAMP,
236+
option_length, req_feat_mask);
237+
break;
238+
}
239+
240+
if (option_length > sizeof(**dev_op_nic_timestamp))
241+
dev_warn(&priv->pdev->dev,
242+
GVE_DEVICE_OPTION_TOO_BIG_FMT,
243+
"Nic Timestamp");
244+
*dev_op_nic_timestamp = (void *)(option + 1);
245+
break;
228246
default:
229247
/* If we don't recognize the option just continue
230248
* without doing anything.
@@ -246,6 +264,7 @@ gve_process_device_options(struct gve_priv *priv,
246264
struct gve_device_option_buffer_sizes **dev_op_buffer_sizes,
247265
struct gve_device_option_flow_steering **dev_op_flow_steering,
248266
struct gve_device_option_rss_config **dev_op_rss_config,
267+
struct gve_device_option_nic_timestamp **dev_op_nic_timestamp,
249268
struct gve_device_option_modify_ring **dev_op_modify_ring)
250269
{
251270
const int num_options = be16_to_cpu(descriptor->num_device_options);
@@ -269,6 +288,7 @@ gve_process_device_options(struct gve_priv *priv,
269288
dev_op_dqo_rda, dev_op_jumbo_frames,
270289
dev_op_dqo_qpl, dev_op_buffer_sizes,
271290
dev_op_flow_steering, dev_op_rss_config,
291+
dev_op_nic_timestamp,
272292
dev_op_modify_ring);
273293
dev_opt = next_opt;
274294
}
@@ -306,6 +326,7 @@ int gve_adminq_alloc(struct device *dev, struct gve_priv *priv)
306326
priv->adminq_set_driver_parameter_cnt = 0;
307327
priv->adminq_report_stats_cnt = 0;
308328
priv->adminq_report_link_speed_cnt = 0;
329+
priv->adminq_report_nic_timestamp_cnt = 0;
309330
priv->adminq_get_ptype_map_cnt = 0;
310331
priv->adminq_query_flow_rules_cnt = 0;
311332
priv->adminq_cfg_flow_rule_cnt = 0;
@@ -442,6 +463,8 @@ static int gve_adminq_kick_and_wait(struct gve_priv *priv)
442463
int tail, head;
443464
int i;
444465

466+
lockdep_assert_held(&priv->adminq_lock);
467+
445468
tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
446469
head = priv->adminq_prod_cnt;
447470

@@ -467,16 +490,15 @@ static int gve_adminq_kick_and_wait(struct gve_priv *priv)
467490
return 0;
468491
}
469492

470-
/* This function is not threadsafe - the caller is responsible for any
471-
* necessary locks.
472-
*/
473493
static int gve_adminq_issue_cmd(struct gve_priv *priv,
474494
union gve_adminq_command *cmd_orig)
475495
{
476496
union gve_adminq_command *cmd;
477497
u32 opcode;
478498
u32 tail;
479499

500+
lockdep_assert_held(&priv->adminq_lock);
501+
480502
tail = ioread32be(&priv->reg_bar0->adminq_event_counter);
481503

482504
// Check if next command will overflow the buffer.
@@ -544,6 +566,9 @@ static int gve_adminq_issue_cmd(struct gve_priv *priv,
544566
case GVE_ADMINQ_REPORT_LINK_SPEED:
545567
priv->adminq_report_link_speed_cnt++;
546568
break;
569+
case GVE_ADMINQ_REPORT_NIC_TIMESTAMP:
570+
priv->adminq_report_nic_timestamp_cnt++;
571+
break;
547572
case GVE_ADMINQ_GET_PTYPE_MAP:
548573
priv->adminq_get_ptype_map_cnt++;
549574
break;
@@ -709,13 +734,19 @@ int gve_adminq_create_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_que
709734
int err;
710735
int i;
711736

737+
mutex_lock(&priv->adminq_lock);
738+
712739
for (i = start_id; i < start_id + num_queues; i++) {
713740
err = gve_adminq_create_tx_queue(priv, i);
714741
if (err)
715-
return err;
742+
goto out;
716743
}
717744

718-
return gve_adminq_kick_and_wait(priv);
745+
err = gve_adminq_kick_and_wait(priv);
746+
747+
out:
748+
mutex_unlock(&priv->adminq_lock);
749+
return err;
719750
}
720751

721752
static void gve_adminq_get_create_rx_queue_cmd(struct gve_priv *priv,
@@ -788,13 +819,19 @@ int gve_adminq_create_rx_queues(struct gve_priv *priv, u32 num_queues)
788819
int err;
789820
int i;
790821

822+
mutex_lock(&priv->adminq_lock);
823+
791824
for (i = 0; i < num_queues; i++) {
792825
err = gve_adminq_create_rx_queue(priv, i);
793826
if (err)
794-
return err;
827+
goto out;
795828
}
796829

797-
return gve_adminq_kick_and_wait(priv);
830+
err = gve_adminq_kick_and_wait(priv);
831+
832+
out:
833+
mutex_unlock(&priv->adminq_lock);
834+
return err;
798835
}
799836

800837
static int gve_adminq_destroy_tx_queue(struct gve_priv *priv, u32 queue_index)
@@ -820,13 +857,19 @@ int gve_adminq_destroy_tx_queues(struct gve_priv *priv, u32 start_id, u32 num_qu
820857
int err;
821858
int i;
822859

860+
mutex_lock(&priv->adminq_lock);
861+
823862
for (i = start_id; i < start_id + num_queues; i++) {
824863
err = gve_adminq_destroy_tx_queue(priv, i);
825864
if (err)
826-
return err;
865+
goto out;
827866
}
828867

829-
return gve_adminq_kick_and_wait(priv);
868+
err = gve_adminq_kick_and_wait(priv);
869+
870+
out:
871+
mutex_unlock(&priv->adminq_lock);
872+
return err;
830873
}
831874

832875
static void gve_adminq_make_destroy_rx_queue_cmd(union gve_adminq_command *cmd,
@@ -861,13 +904,19 @@ int gve_adminq_destroy_rx_queues(struct gve_priv *priv, u32 num_queues)
861904
int err;
862905
int i;
863906

907+
mutex_lock(&priv->adminq_lock);
908+
864909
for (i = 0; i < num_queues; i++) {
865910
err = gve_adminq_destroy_rx_queue(priv, i);
866911
if (err)
867-
return err;
912+
goto out;
868913
}
869914

870-
return gve_adminq_kick_and_wait(priv);
915+
err = gve_adminq_kick_and_wait(priv);
916+
917+
out:
918+
mutex_unlock(&priv->adminq_lock);
919+
return err;
871920
}
872921

873922
static void gve_set_default_desc_cnt(struct gve_priv *priv,
@@ -904,6 +953,8 @@ static void gve_enable_supported_features(struct gve_priv *priv,
904953
*dev_op_flow_steering,
905954
const struct gve_device_option_rss_config
906955
*dev_op_rss_config,
956+
const struct gve_device_option_nic_timestamp
957+
*dev_op_nic_timestamp,
907958
const struct gve_device_option_modify_ring
908959
*dev_op_modify_ring)
909960
{
@@ -980,10 +1031,15 @@ static void gve_enable_supported_features(struct gve_priv *priv,
9801031
"RSS device option enabled with key size of %u, lut size of %u.\n",
9811032
priv->rss_key_size, priv->rss_lut_size);
9821033
}
1034+
1035+
if (dev_op_nic_timestamp &&
1036+
(supported_features_mask & GVE_SUP_NIC_TIMESTAMP_MASK))
1037+
priv->nic_timestamp_supported = true;
9831038
}
9841039

9851040
int gve_adminq_describe_device(struct gve_priv *priv)
9861041
{
1042+
struct gve_device_option_nic_timestamp *dev_op_nic_timestamp = NULL;
9871043
struct gve_device_option_flow_steering *dev_op_flow_steering = NULL;
9881044
struct gve_device_option_buffer_sizes *dev_op_buffer_sizes = NULL;
9891045
struct gve_device_option_jumbo_frames *dev_op_jumbo_frames = NULL;
@@ -1024,6 +1080,7 @@ int gve_adminq_describe_device(struct gve_priv *priv)
10241080
&dev_op_buffer_sizes,
10251081
&dev_op_flow_steering,
10261082
&dev_op_rss_config,
1083+
&dev_op_nic_timestamp,
10271084
&dev_op_modify_ring);
10281085
if (err)
10291086
goto free_device_descriptor;
@@ -1088,7 +1145,8 @@ int gve_adminq_describe_device(struct gve_priv *priv)
10881145
gve_enable_supported_features(priv, supported_features_mask,
10891146
dev_op_jumbo_frames, dev_op_dqo_qpl,
10901147
dev_op_buffer_sizes, dev_op_flow_steering,
1091-
dev_op_rss_config, dev_op_modify_ring);
1148+
dev_op_rss_config, dev_op_nic_timestamp,
1149+
dev_op_modify_ring);
10921150

10931151
free_device_descriptor:
10941152
dma_pool_free(priv->adminq_pool, descriptor, descriptor_bus);
@@ -1200,6 +1258,22 @@ int gve_adminq_report_link_speed(struct gve_priv *priv)
12001258
return err;
12011259
}
12021260

1261+
int gve_adminq_report_nic_ts(struct gve_priv *priv,
1262+
dma_addr_t nic_ts_report_addr)
1263+
{
1264+
union gve_adminq_command cmd;
1265+
1266+
memset(&cmd, 0, sizeof(cmd));
1267+
cmd.opcode = cpu_to_be32(GVE_ADMINQ_REPORT_NIC_TIMESTAMP);
1268+
cmd.report_nic_ts = (struct gve_adminq_report_nic_ts) {
1269+
.nic_ts_report_len =
1270+
cpu_to_be64(sizeof(struct gve_nic_ts_report)),
1271+
.nic_ts_report_addr = cpu_to_be64(nic_ts_report_addr),
1272+
};
1273+
1274+
return gve_adminq_execute_cmd(priv, &cmd);
1275+
}
1276+
12031277
int gve_adminq_get_ptype_map_dqo(struct gve_priv *priv,
12041278
struct gve_ptype_lut *ptype_lut)
12051279
{

0 commit comments

Comments
 (0)