14
14
#include <linux/workqueue.h>
15
15
#include <net/sch_generic.h>
16
16
#include "gve.h"
17
+ #include "gve_dqo.h"
17
18
#include "gve_adminq.h"
18
19
#include "gve_register.h"
19
20
26
27
const char gve_version_str [] = GVE_VERSION ;
27
28
static const char gve_version_prefix [] = GVE_VERSION_PREFIX ;
28
29
30
+ static netdev_tx_t gve_start_xmit (struct sk_buff * skb , struct net_device * dev )
31
+ {
32
+ struct gve_priv * priv = netdev_priv (dev );
33
+
34
+ if (gve_is_gqi (priv ))
35
+ return gve_tx (skb , dev );
36
+ else
37
+ return gve_tx_dqo (skb , dev );
38
+ }
39
+
29
40
static void gve_get_stats (struct net_device * dev , struct rtnl_link_stats64 * s )
30
41
{
31
42
struct gve_priv * priv = netdev_priv (dev );
@@ -155,6 +166,15 @@ static irqreturn_t gve_intr(int irq, void *arg)
155
166
return IRQ_HANDLED ;
156
167
}
157
168
169
+ static irqreturn_t gve_intr_dqo (int irq , void * arg )
170
+ {
171
+ struct gve_notify_block * block = arg ;
172
+
173
+ /* Interrupts are automatically masked */
174
+ napi_schedule_irqoff (& block -> napi );
175
+ return IRQ_HANDLED ;
176
+ }
177
+
158
178
static int gve_napi_poll (struct napi_struct * napi , int budget )
159
179
{
160
180
struct gve_notify_block * block ;
@@ -191,6 +211,54 @@ static int gve_napi_poll(struct napi_struct *napi, int budget)
191
211
return 0 ;
192
212
}
193
213
214
+ static int gve_napi_poll_dqo (struct napi_struct * napi , int budget )
215
+ {
216
+ struct gve_notify_block * block =
217
+ container_of (napi , struct gve_notify_block , napi );
218
+ struct gve_priv * priv = block -> priv ;
219
+ bool reschedule = false;
220
+ int work_done = 0 ;
221
+
222
+ /* Clear PCI MSI-X Pending Bit Array (PBA)
223
+ *
224
+ * This bit is set if an interrupt event occurs while the vector is
225
+ * masked. If this bit is set and we reenable the interrupt, it will
226
+ * fire again. Since we're just about to poll the queue state, we don't
227
+ * need it to fire again.
228
+ *
229
+ * Under high softirq load, it's possible that the interrupt condition
230
+ * is triggered twice before we got the chance to process it.
231
+ */
232
+ gve_write_irq_doorbell_dqo (priv , block ,
233
+ GVE_ITR_NO_UPDATE_DQO | GVE_ITR_CLEAR_PBA_BIT_DQO );
234
+
235
+ if (block -> tx )
236
+ reschedule |= gve_tx_poll_dqo (block , /*do_clean=*/ true);
237
+
238
+ if (block -> rx ) {
239
+ work_done = gve_rx_poll_dqo (block , budget );
240
+ reschedule |= work_done == budget ;
241
+ }
242
+
243
+ if (reschedule )
244
+ return budget ;
245
+
246
+ if (likely (napi_complete_done (napi , work_done ))) {
247
+ /* Enable interrupts again.
248
+ *
249
+ * We don't need to repoll afterwards because HW supports the
250
+ * PCI MSI-X PBA feature.
251
+ *
252
+ * Another interrupt would be triggered if a new event came in
253
+ * since the last one.
254
+ */
255
+ gve_write_irq_doorbell_dqo (priv , block ,
256
+ GVE_ITR_NO_UPDATE_DQO | GVE_ITR_ENABLE_BIT_DQO );
257
+ }
258
+
259
+ return work_done ;
260
+ }
261
+
194
262
static int gve_alloc_notify_blocks (struct gve_priv * priv )
195
263
{
196
264
int num_vecs_requested = priv -> num_ntfy_blks + 1 ;
@@ -264,7 +332,8 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv)
264
332
name , i );
265
333
block -> priv = priv ;
266
334
err = request_irq (priv -> msix_vectors [msix_idx ].vector ,
267
- gve_intr , 0 , block -> name , block );
335
+ gve_is_gqi (priv ) ? gve_intr : gve_intr_dqo ,
336
+ 0 , block -> name , block );
268
337
if (err ) {
269
338
dev_err (& priv -> pdev -> dev ,
270
339
"Failed to receive msix vector %d\n" , i );
@@ -417,11 +486,12 @@ static void gve_teardown_device_resources(struct gve_priv *priv)
417
486
gve_clear_device_resources_ok (priv );
418
487
}
419
488
420
- static void gve_add_napi (struct gve_priv * priv , int ntfy_idx )
489
+ static void gve_add_napi (struct gve_priv * priv , int ntfy_idx ,
490
+ int (* gve_poll )(struct napi_struct * , int ))
421
491
{
422
492
struct gve_notify_block * block = & priv -> ntfy_blocks [ntfy_idx ];
423
493
424
- netif_napi_add (priv -> dev , & block -> napi , gve_napi_poll ,
494
+ netif_napi_add (priv -> dev , & block -> napi , gve_poll ,
425
495
NAPI_POLL_WEIGHT );
426
496
}
427
497
@@ -512,11 +582,33 @@ static int gve_create_rings(struct gve_priv *priv)
512
582
return 0 ;
513
583
}
514
584
585
+ static void add_napi_init_sync_stats (struct gve_priv * priv ,
586
+ int (* napi_poll )(struct napi_struct * napi ,
587
+ int budget ))
588
+ {
589
+ int i ;
590
+
591
+ /* Add tx napi & init sync stats*/
592
+ for (i = 0 ; i < priv -> tx_cfg .num_queues ; i ++ ) {
593
+ int ntfy_idx = gve_tx_idx_to_ntfy (priv , i );
594
+
595
+ u64_stats_init (& priv -> tx [i ].statss );
596
+ priv -> tx [i ].ntfy_id = ntfy_idx ;
597
+ gve_add_napi (priv , ntfy_idx , napi_poll );
598
+ }
599
+ /* Add rx napi & init sync stats*/
600
+ for (i = 0 ; i < priv -> rx_cfg .num_queues ; i ++ ) {
601
+ int ntfy_idx = gve_rx_idx_to_ntfy (priv , i );
602
+
603
+ u64_stats_init (& priv -> rx [i ].statss );
604
+ priv -> rx [i ].ntfy_id = ntfy_idx ;
605
+ gve_add_napi (priv , ntfy_idx , napi_poll );
606
+ }
607
+ }
608
+
515
609
static int gve_alloc_rings (struct gve_priv * priv )
516
610
{
517
- int ntfy_idx ;
518
611
int err ;
519
- int i ;
520
612
521
613
/* Setup tx rings */
522
614
priv -> tx = kvzalloc (priv -> tx_cfg .num_queues * sizeof (* priv -> tx ),
@@ -536,18 +628,11 @@ static int gve_alloc_rings(struct gve_priv *priv)
536
628
err = gve_rx_alloc_rings (priv );
537
629
if (err )
538
630
goto free_rx ;
539
- /* Add tx napi & init sync stats*/
540
- for (i = 0 ; i < priv -> tx_cfg .num_queues ; i ++ ) {
541
- u64_stats_init (& priv -> tx [i ].statss );
542
- ntfy_idx = gve_tx_idx_to_ntfy (priv , i );
543
- gve_add_napi (priv , ntfy_idx );
544
- }
545
- /* Add rx napi & init sync stats*/
546
- for (i = 0 ; i < priv -> rx_cfg .num_queues ; i ++ ) {
547
- u64_stats_init (& priv -> rx [i ].statss );
548
- ntfy_idx = gve_rx_idx_to_ntfy (priv , i );
549
- gve_add_napi (priv , ntfy_idx );
550
- }
631
+
632
+ if (gve_is_gqi (priv ))
633
+ add_napi_init_sync_stats (priv , gve_napi_poll );
634
+ else
635
+ add_napi_init_sync_stats (priv , gve_napi_poll_dqo );
551
636
552
637
return 0 ;
553
638
@@ -798,9 +883,17 @@ static int gve_open(struct net_device *dev)
798
883
err = gve_register_qpls (priv );
799
884
if (err )
800
885
goto reset ;
886
+
887
+ if (!gve_is_gqi (priv )) {
888
+ /* Hard code this for now. This may be tuned in the future for
889
+ * performance.
890
+ */
891
+ priv -> data_buffer_size_dqo = GVE_RX_BUFFER_SIZE_DQO ;
892
+ }
801
893
err = gve_create_rings (priv );
802
894
if (err )
803
895
goto reset ;
896
+
804
897
gve_set_device_rings_ok (priv );
805
898
806
899
if (gve_get_report_stats (priv ))
@@ -970,12 +1063,49 @@ static void gve_tx_timeout(struct net_device *dev, unsigned int txqueue)
970
1063
priv -> tx_timeo_cnt ++ ;
971
1064
}
972
1065
1066
+ static int gve_set_features (struct net_device * netdev ,
1067
+ netdev_features_t features )
1068
+ {
1069
+ const netdev_features_t orig_features = netdev -> features ;
1070
+ struct gve_priv * priv = netdev_priv (netdev );
1071
+ int err ;
1072
+
1073
+ if ((netdev -> features & NETIF_F_LRO ) != (features & NETIF_F_LRO )) {
1074
+ netdev -> features ^= NETIF_F_LRO ;
1075
+ if (netif_carrier_ok (netdev )) {
1076
+ /* To make this process as simple as possible we
1077
+ * teardown the device, set the new configuration,
1078
+ * and then bring the device up again.
1079
+ */
1080
+ err = gve_close (netdev );
1081
+ /* We have already tried to reset in close, just fail
1082
+ * at this point.
1083
+ */
1084
+ if (err )
1085
+ goto err ;
1086
+
1087
+ err = gve_open (netdev );
1088
+ if (err )
1089
+ goto err ;
1090
+ }
1091
+ }
1092
+
1093
+ return 0 ;
1094
+ err :
1095
+ /* Reverts the change on error. */
1096
+ netdev -> features = orig_features ;
1097
+ netif_err (priv , drv , netdev ,
1098
+ "Set features failed! !!! DISABLING ALL QUEUES !!!\n" );
1099
+ return err ;
1100
+ }
1101
+
973
1102
static const struct net_device_ops gve_netdev_ops = {
974
- .ndo_start_xmit = gve_tx ,
1103
+ .ndo_start_xmit = gve_start_xmit ,
975
1104
.ndo_open = gve_open ,
976
1105
.ndo_stop = gve_close ,
977
1106
.ndo_get_stats64 = gve_get_stats ,
978
1107
.ndo_tx_timeout = gve_tx_timeout ,
1108
+ .ndo_set_features = gve_set_features ,
979
1109
};
980
1110
981
1111
static void gve_handle_status (struct gve_priv * priv , u32 status )
@@ -1019,6 +1149,15 @@ void gve_handle_report_stats(struct gve_priv *priv)
1019
1149
/* tx stats */
1020
1150
if (priv -> tx ) {
1021
1151
for (idx = 0 ; idx < priv -> tx_cfg .num_queues ; idx ++ ) {
1152
+ u32 last_completion = 0 ;
1153
+ u32 tx_frames = 0 ;
1154
+
1155
+ /* DQO doesn't currently support these metrics. */
1156
+ if (gve_is_gqi (priv )) {
1157
+ last_completion = priv -> tx [idx ].done ;
1158
+ tx_frames = priv -> tx [idx ].req ;
1159
+ }
1160
+
1022
1161
do {
1023
1162
start = u64_stats_fetch_begin (& priv -> tx [idx ].statss );
1024
1163
tx_bytes = priv -> tx [idx ].bytes_done ;
@@ -1035,7 +1174,7 @@ void gve_handle_report_stats(struct gve_priv *priv)
1035
1174
};
1036
1175
stats [stats_idx ++ ] = (struct stats ) {
1037
1176
.stat_name = cpu_to_be32 (TX_FRAMES_SENT ),
1038
- .value = cpu_to_be64 (priv -> tx [ idx ]. req ),
1177
+ .value = cpu_to_be64 (tx_frames ),
1039
1178
.queue_id = cpu_to_be32 (idx ),
1040
1179
};
1041
1180
stats [stats_idx ++ ] = (struct stats ) {
@@ -1045,7 +1184,7 @@ void gve_handle_report_stats(struct gve_priv *priv)
1045
1184
};
1046
1185
stats [stats_idx ++ ] = (struct stats ) {
1047
1186
.stat_name = cpu_to_be32 (TX_LAST_COMPLETION_PROCESSED ),
1048
- .value = cpu_to_be64 (priv -> tx [ idx ]. done ),
1187
+ .value = cpu_to_be64 (last_completion ),
1049
1188
.queue_id = cpu_to_be32 (idx ),
1050
1189
};
1051
1190
}
@@ -1121,7 +1260,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
1121
1260
"Could not get device information: err=%d\n" , err );
1122
1261
goto err ;
1123
1262
}
1124
- if (priv -> dev -> max_mtu > PAGE_SIZE ) {
1263
+ if (gve_is_gqi ( priv ) && priv -> dev -> max_mtu > PAGE_SIZE ) {
1125
1264
priv -> dev -> max_mtu = PAGE_SIZE ;
1126
1265
err = gve_adminq_set_mtu (priv , priv -> dev -> mtu );
1127
1266
if (err ) {
@@ -1332,7 +1471,12 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1332
1471
pci_set_drvdata (pdev , dev );
1333
1472
dev -> ethtool_ops = & gve_ethtool_ops ;
1334
1473
dev -> netdev_ops = & gve_netdev_ops ;
1335
- /* advertise features */
1474
+
1475
+ /* Set default and supported features.
1476
+ *
1477
+ * Features might be set in other locations as well (such as
1478
+ * `gve_adminq_describe_device`).
1479
+ */
1336
1480
dev -> hw_features = NETIF_F_HIGHDMA ;
1337
1481
dev -> hw_features |= NETIF_F_SG ;
1338
1482
dev -> hw_features |= NETIF_F_HW_CSUM ;
0 commit comments