gve.h (1dfc2e46117e5c41037e27e859e75a7518881ee6) gve.h (f13697cc7a19225307d85b0a77ef1c15abe95a7d)
1/* SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 * Google virtual Ethernet (gve) driver
3 *
4 * Copyright (C) 2015-2021 Google, Inc.
5 */
6
7#ifndef _GVE_H_
8#define _GVE_H_

--- 952 unchanged lines hidden (view full) ---

961}
962
963static inline bool gve_is_qpl(struct gve_priv *priv)
964{
965 return priv->queue_format == GVE_GQI_QPL_FORMAT ||
966 priv->queue_format == GVE_DQO_QPL_FORMAT;
967}
968
1/* SPDX-License-Identifier: (GPL-2.0 OR MIT)
2 * Google virtual Ethernet (gve) driver
3 *
4 * Copyright (C) 2015-2021 Google, Inc.
5 */
6
7#ifndef _GVE_H_
8#define _GVE_H_

--- 952 unchanged lines hidden (view full) ---

961}
962
963static inline bool gve_is_qpl(struct gve_priv *priv)
964{
965 return priv->queue_format == GVE_GQI_QPL_FORMAT ||
966 priv->queue_format == GVE_DQO_QPL_FORMAT;
967}
968
969/* Returns the number of tx queue page lists
970 */
971static inline u32 gve_num_tx_qpls(struct gve_priv *priv)
969/* Returns the number of tx queue page lists */
970static inline u32 gve_num_tx_qpls(const struct gve_queue_config *tx_cfg,
971 int num_xdp_queues,
972 bool is_qpl)
972{
973{
973 if (!gve_is_qpl(priv))
974 if (!is_qpl)
974 return 0;
975 return 0;
975
976 return priv->tx_cfg.num_queues + priv->num_xdp_queues;
976 return tx_cfg->num_queues + num_xdp_queues;
977}
978
979/* Returns the number of XDP tx queue page lists
980 */
981static inline u32 gve_num_xdp_qpls(struct gve_priv *priv)
982{
983 if (priv->queue_format != GVE_GQI_QPL_FORMAT)
984 return 0;
985
986 return priv->num_xdp_queues;
987}
988
977}
978
979/* Returns the number of XDP tx queue page lists
980 */
981static inline u32 gve_num_xdp_qpls(struct gve_priv *priv)
982{
983 if (priv->queue_format != GVE_GQI_QPL_FORMAT)
984 return 0;
985
986 return priv->num_xdp_queues;
987}
988
989/* Returns the number of rx queue page lists
990 */
991static inline u32 gve_num_rx_qpls(struct gve_priv *priv)
989/* Returns the number of rx queue page lists */
990static inline u32 gve_num_rx_qpls(const struct gve_queue_config *rx_cfg,
991 bool is_qpl)
992{
992{
993 if (!gve_is_qpl(priv))
993 if (!is_qpl)
994 return 0;
994 return 0;
995
996 return priv->rx_cfg.num_queues;
995 return rx_cfg->num_queues;
997}
998
999static inline u32 gve_tx_qpl_id(struct gve_priv *priv, int tx_qid)
1000{
1001 return tx_qid;
1002}
1003
1004static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid)
1005{
1006 return priv->tx_cfg.max_queues + rx_qid;
1007}
1008
996}
997
998static inline u32 gve_tx_qpl_id(struct gve_priv *priv, int tx_qid)
999{
1000 return tx_qid;
1001}
1002
1003static inline u32 gve_rx_qpl_id(struct gve_priv *priv, int rx_qid)
1004{
1005 return priv->tx_cfg.max_queues + rx_qid;
1006}
1007
1008/* Returns the index into priv->qpls where a certain rx queue's QPL resides */
1009static inline u32 gve_get_rx_qpl_id(const struct gve_queue_config *tx_cfg, int rx_qid)
1010{
1011 return tx_cfg->max_queues + rx_qid;
1012}
1013
1009static inline u32 gve_tx_start_qpl_id(struct gve_priv *priv)
1010{
1011 return gve_tx_qpl_id(priv, 0);
1012}
1013
1014static inline u32 gve_tx_start_qpl_id(struct gve_priv *priv)
1015{
1016 return gve_tx_qpl_id(priv, 0);
1017}
1018
1014static inline u32 gve_rx_start_qpl_id(struct gve_priv *priv)
1019/* Returns the index into priv->qpls where the first rx queue's QPL resides */
1020static inline u32 gve_rx_start_qpl_id(const struct gve_queue_config *tx_cfg)
1015{
1021{
1016 return gve_rx_qpl_id(priv, 0);
1022 return gve_get_rx_qpl_id(tx_cfg, 0);
1017}
1018
1023}
1024
1019/* Returns a pointer to the next available tx qpl in the list of qpls
1020 */
1025/* Returns a pointer to the next available tx qpl in the list of qpls */
1021static inline
1026static inline
1022struct gve_queue_page_list *gve_assign_tx_qpl(struct gve_priv *priv, int tx_qid)
1027struct gve_queue_page_list *gve_assign_tx_qpl(struct gve_tx_alloc_rings_cfg *cfg,
1028 int tx_qid)
1023{
1029{
1024 int id = gve_tx_qpl_id(priv, tx_qid);
1025
1026 /* QPL already in use */
1030 /* QPL already in use */
1027 if (test_bit(id, priv->qpl_cfg.qpl_id_map))
1031 if (test_bit(tx_qid, cfg->qpl_cfg->qpl_id_map))
1028 return NULL;
1032 return NULL;
1029
1030 set_bit(id, priv->qpl_cfg.qpl_id_map);
1031 return &priv->qpls[id];
1033 set_bit(tx_qid, cfg->qpl_cfg->qpl_id_map);
1034 return &cfg->qpls[tx_qid];
1032}
1033
1035}
1036
1034/* Returns a pointer to the next available rx qpl in the list of qpls
1035 */
1037/* Returns a pointer to the next available rx qpl in the list of qpls */
1036static inline
1038static inline
1037struct gve_queue_page_list *gve_assign_rx_qpl(struct gve_priv *priv, int rx_qid)
1039struct gve_queue_page_list *gve_assign_rx_qpl(struct gve_rx_alloc_rings_cfg *cfg,
1040 int rx_qid)
1038{
1041{
1039 int id = gve_rx_qpl_id(priv, rx_qid);
1040
1042 int id = gve_get_rx_qpl_id(cfg->qcfg_tx, rx_qid);
1041 /* QPL already in use */
1043 /* QPL already in use */
1042 if (test_bit(id, priv->qpl_cfg.qpl_id_map))
1044 if (test_bit(id, cfg->qpl_cfg->qpl_id_map))
1043 return NULL;
1045 return NULL;
1044
1045 set_bit(id, priv->qpl_cfg.qpl_id_map);
1046 return &priv->qpls[id];
1046 set_bit(id, cfg->qpl_cfg->qpl_id_map);
1047 return &cfg->qpls[id];
1047}
1048
1048}
1049
1049/* Unassigns the qpl with the given id
1050 */
1051static inline void gve_unassign_qpl(struct gve_priv *priv, int id)
1050/* Unassigns the qpl with the given id */
1051static inline void gve_unassign_qpl(struct gve_qpl_config *qpl_cfg, int id)
1052{
1052{
1053 clear_bit(id, priv->qpl_cfg.qpl_id_map);
1053 clear_bit(id, qpl_cfg->qpl_id_map);
1054}
1055
1054}
1055
1056/* Returns the correct dma direction for tx and rx qpls
1057 */
1056/* Returns the correct dma direction for tx and rx qpls */
1058static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,
1059 int id)
1060{
1057static inline enum dma_data_direction gve_qpl_dma_dir(struct gve_priv *priv,
1058 int id)
1059{
1061 if (id < gve_rx_start_qpl_id(priv))
1060 if (id < gve_rx_start_qpl_id(&priv->tx_cfg))
1062 return DMA_TO_DEVICE;
1063 else
1064 return DMA_FROM_DEVICE;
1065}
1066
1067static inline bool gve_is_gqi(struct gve_priv *priv)
1068{
1069 return priv->queue_format == GVE_GQI_RDA_FORMAT ||

--- 28 unchanged lines hidden (view full) ---

1098netdev_tx_t gve_tx(struct sk_buff *skb, struct net_device *dev);
1099int gve_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
1100 u32 flags);
1101int gve_xdp_xmit_one(struct gve_priv *priv, struct gve_tx_ring *tx,
1102 void *data, int len, void *frame_p);
1103void gve_xdp_tx_flush(struct gve_priv *priv, u32 xdp_qid);
1104bool gve_tx_poll(struct gve_notify_block *block, int budget);
1105bool gve_xdp_poll(struct gve_notify_block *block, int budget);
1061 return DMA_TO_DEVICE;
1062 else
1063 return DMA_FROM_DEVICE;
1064}
1065
1066static inline bool gve_is_gqi(struct gve_priv *priv)
1067{
1068 return priv->queue_format == GVE_GQI_RDA_FORMAT ||

--- 28 unchanged lines hidden (view full) ---

1097netdev_tx_t gve_tx(struct sk_buff *skb, struct net_device *dev);
1098int gve_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **frames,
1099 u32 flags);
1100int gve_xdp_xmit_one(struct gve_priv *priv, struct gve_tx_ring *tx,
1101 void *data, int len, void *frame_p);
1102void gve_xdp_tx_flush(struct gve_priv *priv, u32 xdp_qid);
1103bool gve_tx_poll(struct gve_notify_block *block, int budget);
1104bool gve_xdp_poll(struct gve_notify_block *block, int budget);
1106int gve_tx_alloc_rings(struct gve_priv *priv, int start_id, int num_rings);
1107void gve_tx_free_rings_gqi(struct gve_priv *priv, int start_id, int num_rings);
1105int gve_tx_alloc_rings_gqi(struct gve_priv *priv,
1106 struct gve_tx_alloc_rings_cfg *cfg);
1107void gve_tx_free_rings_gqi(struct gve_priv *priv,
1108 struct gve_tx_alloc_rings_cfg *cfg);
1109void gve_tx_start_ring_gqi(struct gve_priv *priv, int idx);
1110void gve_tx_stop_ring_gqi(struct gve_priv *priv, int idx);
1108u32 gve_tx_load_event_counter(struct gve_priv *priv,
1109 struct gve_tx_ring *tx);
1110bool gve_tx_clean_pending(struct gve_priv *priv, struct gve_tx_ring *tx);
1111/* rx handling */
1112void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx);
1113int gve_rx_poll(struct gve_notify_block *block, int budget);
1114bool gve_rx_work_pending(struct gve_rx_ring *rx);
1115int gve_rx_alloc_rings(struct gve_priv *priv);
1111u32 gve_tx_load_event_counter(struct gve_priv *priv,
1112 struct gve_tx_ring *tx);
1113bool gve_tx_clean_pending(struct gve_priv *priv, struct gve_tx_ring *tx);
1114/* rx handling */
1115void gve_rx_write_doorbell(struct gve_priv *priv, struct gve_rx_ring *rx);
1116int gve_rx_poll(struct gve_notify_block *block, int budget);
1117bool gve_rx_work_pending(struct gve_rx_ring *rx);
1118int gve_rx_alloc_rings(struct gve_priv *priv);
1116void gve_rx_free_rings_gqi(struct gve_priv *priv);
1119int gve_rx_alloc_rings_gqi(struct gve_priv *priv,
1120 struct gve_rx_alloc_rings_cfg *cfg);
1121void gve_rx_free_rings_gqi(struct gve_priv *priv,
1122 struct gve_rx_alloc_rings_cfg *cfg);
1123void gve_rx_start_ring_gqi(struct gve_priv *priv, int idx);
1124void gve_rx_stop_ring_gqi(struct gve_priv *priv, int idx);
1117/* Reset */
1118void gve_schedule_reset(struct gve_priv *priv);
1119int gve_reset(struct gve_priv *priv, bool attempt_teardown);
1120int gve_adjust_queues(struct gve_priv *priv,
1121 struct gve_queue_config new_rx_config,
1122 struct gve_queue_config new_tx_config);
1123/* report stats handling */
1124void gve_handle_report_stats(struct gve_priv *priv);
1125/* exported by ethtool.c */
1126extern const struct ethtool_ops gve_ethtool_ops;
1127/* needed by ethtool */
1128extern char gve_driver_name[];
1129extern const char gve_version_str[];
1130#endif /* _GVE_H_ */
1125/* Reset */
1126void gve_schedule_reset(struct gve_priv *priv);
1127int gve_reset(struct gve_priv *priv, bool attempt_teardown);
1128int gve_adjust_queues(struct gve_priv *priv,
1129 struct gve_queue_config new_rx_config,
1130 struct gve_queue_config new_tx_config);
1131/* report stats handling */
1132void gve_handle_report_stats(struct gve_priv *priv);
1133/* exported by ethtool.c */
1134extern const struct ethtool_ops gve_ethtool_ops;
1135/* needed by ethtool */
1136extern char gve_driver_name[];
1137extern const char gve_version_str[];
1138#endif /* _GVE_H_ */