1414#include <linux/workqueue.h>
1515#include <net/sch_generic.h>
1616#include "gve.h"
17+ #include "gve_dqo.h"
1718#include "gve_adminq.h"
1819#include "gve_register.h"
1920
2627const char gve_version_str [] = GVE_VERSION ;
2728static const char gve_version_prefix [] = GVE_VERSION_PREFIX ;
2829
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+
2940static void gve_get_stats (struct net_device * dev , struct rtnl_link_stats64 * s )
3041{
3142 struct gve_priv * priv = netdev_priv (dev );
@@ -155,6 +166,15 @@ static irqreturn_t gve_intr(int irq, void *arg)
155166 return IRQ_HANDLED ;
156167}
157168
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+
158178static int gve_napi_poll (struct napi_struct * napi , int budget )
159179{
160180 struct gve_notify_block * block ;
@@ -191,6 +211,54 @@ static int gve_napi_poll(struct napi_struct *napi, int budget)
191211 return 0 ;
192212}
193213
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+
194262static int gve_alloc_notify_blocks (struct gve_priv * priv )
195263{
196264 int num_vecs_requested = priv -> num_ntfy_blks + 1 ;
@@ -264,7 +332,8 @@ static int gve_alloc_notify_blocks(struct gve_priv *priv)
264332 name , i );
265333 block -> priv = priv ;
266334 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 );
268337 if (err ) {
269338 dev_err (& priv -> pdev -> dev ,
270339 "Failed to receive msix vector %d\n" , i );
@@ -417,11 +486,12 @@ static void gve_teardown_device_resources(struct gve_priv *priv)
417486 gve_clear_device_resources_ok (priv );
418487}
419488
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 ))
421491{
422492 struct gve_notify_block * block = & priv -> ntfy_blocks [ntfy_idx ];
423493
424- netif_napi_add (priv -> dev , & block -> napi , gve_napi_poll ,
494+ netif_napi_add (priv -> dev , & block -> napi , gve_poll ,
425495 NAPI_POLL_WEIGHT );
426496}
427497
@@ -512,11 +582,33 @@ static int gve_create_rings(struct gve_priv *priv)
512582 return 0 ;
513583}
514584
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+
515609static int gve_alloc_rings (struct gve_priv * priv )
516610{
517- int ntfy_idx ;
518611 int err ;
519- int i ;
520612
521613 /* Setup tx rings */
522614 priv -> tx = kvzalloc (priv -> tx_cfg .num_queues * sizeof (* priv -> tx ),
@@ -536,18 +628,11 @@ static int gve_alloc_rings(struct gve_priv *priv)
536628 err = gve_rx_alloc_rings (priv );
537629 if (err )
538630 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 );
551636
552637 return 0 ;
553638
@@ -798,9 +883,17 @@ static int gve_open(struct net_device *dev)
798883 err = gve_register_qpls (priv );
799884 if (err )
800885 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+ }
801893 err = gve_create_rings (priv );
802894 if (err )
803895 goto reset ;
896+
804897 gve_set_device_rings_ok (priv );
805898
806899 if (gve_get_report_stats (priv ))
@@ -970,12 +1063,49 @@ static void gve_tx_timeout(struct net_device *dev, unsigned int txqueue)
9701063 priv -> tx_timeo_cnt ++ ;
9711064}
9721065
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+
9731102static const struct net_device_ops gve_netdev_ops = {
974- .ndo_start_xmit = gve_tx ,
1103+ .ndo_start_xmit = gve_start_xmit ,
9751104 .ndo_open = gve_open ,
9761105 .ndo_stop = gve_close ,
9771106 .ndo_get_stats64 = gve_get_stats ,
9781107 .ndo_tx_timeout = gve_tx_timeout ,
1108+ .ndo_set_features = gve_set_features ,
9791109};
9801110
9811111static void gve_handle_status (struct gve_priv * priv , u32 status )
@@ -1019,6 +1149,15 @@ void gve_handle_report_stats(struct gve_priv *priv)
10191149 /* tx stats */
10201150 if (priv -> tx ) {
10211151 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+
10221161 do {
10231162 start = u64_stats_fetch_begin (& priv -> tx [idx ].statss );
10241163 tx_bytes = priv -> tx [idx ].bytes_done ;
@@ -1035,7 +1174,7 @@ void gve_handle_report_stats(struct gve_priv *priv)
10351174 };
10361175 stats [stats_idx ++ ] = (struct stats ) {
10371176 .stat_name = cpu_to_be32 (TX_FRAMES_SENT ),
1038- .value = cpu_to_be64 (priv -> tx [ idx ]. req ),
1177+ .value = cpu_to_be64 (tx_frames ),
10391178 .queue_id = cpu_to_be32 (idx ),
10401179 };
10411180 stats [stats_idx ++ ] = (struct stats ) {
@@ -1045,7 +1184,7 @@ void gve_handle_report_stats(struct gve_priv *priv)
10451184 };
10461185 stats [stats_idx ++ ] = (struct stats ) {
10471186 .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 ),
10491188 .queue_id = cpu_to_be32 (idx ),
10501189 };
10511190 }
@@ -1121,7 +1260,7 @@ static int gve_init_priv(struct gve_priv *priv, bool skip_describe_device)
11211260 "Could not get device information: err=%d\n" , err );
11221261 goto err ;
11231262 }
1124- if (priv -> dev -> max_mtu > PAGE_SIZE ) {
1263+ if (gve_is_gqi ( priv ) && priv -> dev -> max_mtu > PAGE_SIZE ) {
11251264 priv -> dev -> max_mtu = PAGE_SIZE ;
11261265 err = gve_adminq_set_mtu (priv , priv -> dev -> mtu );
11271266 if (err ) {
@@ -1332,7 +1471,12 @@ static int gve_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
13321471 pci_set_drvdata (pdev , dev );
13331472 dev -> ethtool_ops = & gve_ethtool_ops ;
13341473 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+ */
13361480 dev -> hw_features = NETIF_F_HIGHDMA ;
13371481 dev -> hw_features |= NETIF_F_SG ;
13381482 dev -> hw_features |= NETIF_F_HW_CSUM ;
0 commit comments