net/enic: add SR-IOV VF representor
Subsystems (2)
cover net/enic: add SR-IOV VF representor
This series adds VF representors to the driver. It enables single-queue representors and implements enough flow features to run OVS-DPDK offload for default vlan+mac based switching.
The flow API handlers and devcmd functions (firmware commands) are now aware of representors. Representors reserve PF Tx/Rx queues for their implicit paths to/from VFs. Packet forwarding rules for these implicit paths are set up using firmware's Flow Manager (flowman), which is also used for rte_flow API.
Thanks.
-Hyong
Hyong Youb Kim (5):
net/enic: extend vnic dev API for VF representors net/enic: add minimal VF representor
net/enic: add single-queue Tx and Rx to VF representor net/enic: extend flow handler to support VF representors net/enic: enable flow API for VF representor
doc/guides/rel_notes/release_20_11.rst | 4 + drivers/net/enic/base/vnic_dev.c | 112 +++- drivers/net/enic/base/vnic_dev.h | 4 + drivers/net/enic/enic.h | 116 ++++ drivers/net/enic/enic_ethdev.c | 107 +++- drivers/net/enic/enic_fm_flow.c | 487 +++++++++++++++-- drivers/net/enic/enic_main.c | 114 +++- drivers/net/enic/enic_vf_representor.c | 729 +++++++++++++++++++++++++ drivers/net/enic/meson.build | 1 + 9 files changed, 1602 insertions(+), 72 deletions(-) create mode 100644 drivers/net/enic/enic_vf_representor.c
Signature · 1 line
2.26.2
PATCH 1/5 net/enic: extend vnic dev API for VF representors
VF representors need to proxy devcmd through the PF vnic_dev instance. Extend vnic_dev to accommodate them as follows.
1. Add vnic_vf_rep_register()
A VF representor creates its own vnic_dev instance via this function and saves VF ID. When performing devcmd, vnic_dev uses the saved VF ID to proxy devcmd through the PF vnic_dev instance.
2. Add vnic_register_lock()
As PF and VF representors appear as independent ports to the application, its threads may invoke APIs on them simultaneously, leading to race conditions on the PF vnic_dev. For example, thread A can query stats on PF port, while thread B queries stats on a VF representor.
The PF port invokes this function to provide a lock to vnic_dev. This lock is used to serialize devcmd calls from PF and VF representors.
3. Add utility functions to assist VF representor settings vnic_dev_mtu() and vnic_dev_uif() retrieve vnic MTU and UIF number (uplink index), respectively.
--- drivers/net/enic/base/vnic_dev.c | 112 ++++++++++++++++++++++++++++++- drivers/net/enic/base/vnic_dev.h | 4 ++ 2 files changed, 113 insertions(+), 3 deletions(-)
drivers/net/enic/base/vnic_dev.c +109 -3
@@ -61,6 +61,16 @@ struct vnic_dev {void (*free_consistent)(void *priv,size_t size,void *vaddr,dma_addr_t dma_handle); +/* +* Used to serialize devcmd access, currently from PF and its +* VF representors. When there are no representors, lock is +* not used. +*/ +int locked; +void (*lock)(void *priv); +void (*unlock)(void *priv); +struct vnic_dev *pf_vdev; +int vf_id; };#define VNIC_MAX_RES_HDR_SIZE \
@@ -84,6 +94,14 @@ void vnic_register_cbacks(struct vnic_dev *vdev, vdev->free_consistent = free_consistent; } +void vnic_register_lock (struct vnic_dev *vdev,void (*lock)(void *priv), +void (*unlock)(void *priv)) +{ + vdev->lock = lock; + vdev->unlock = unlock; + vdev->locked =0 ; +} +static int vnic_dev_discover_res (struct vnic_dev *vdev,struct vnic_dev_bar *bar,unsigned int num_bars) {
@@ -410,12 +428,39 @@ static int vnic_dev_cmd_no_proxy(struct vnic_dev *vdev,return err; } +void vnic_dev_cmd_proxy_by_index_start (struct vnic_dev *vdev,uint16_t index) +{ + vdev->proxy =PROXY_BY_INDEX ; + vdev->proxy_index = index; +} + +void vnic_dev_cmd_proxy_end (struct vnic_dev *vdev) +{ + vdev->proxy =PROXY_NONE ; + vdev->proxy_index =0 ; +} +int vnic_dev_cmd (struct vnic_dev *vdev,enum vnic_devcmd_cmd cmd,uint64_t *a0,uint64_t *a1,int wait) {uint64_t args[2 ]; +bool vf_rep; +int vf_idx;int err; + vf_rep = false; +if (vdev->pf_vdev) { + vf_rep = true; + vf_idx = vdev->vf_id; +/* Everything below assumes PF vdev */ + vdev = vdev->pf_vdev; + } +if (vdev->lock) + vdev->lock (vdev->priv); +/* For VF representor, proxy devcmd to VF index */ +if (vf_rep) +vnic_dev_cmd_proxy_by_index_start (vdev, vf_idx); + args[0 ] = *a0; args[1 ] = *a1;memset (vdev->args,0 ,sizeof (vdev->args));
@@ -435,6 +480,10 @@ int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,break ; } +if (vf_rep) +vnic_dev_cmd_proxy_end (vdev); +if (vdev->unlock) + vdev->unlock (vdev->priv);if (err ==0 ) { *a0 = args[0 ]; *a1 = args[1 ];
@@ -446,17 +495,41 @@ int vnic_dev_cmd(struct vnic_dev *vdev, enum vnic_devcmd_cmd cmd,int vnic_dev_cmd_args (struct vnic_dev *vdev,enum vnic_devcmd_cmd cmd,uint64_t *args,int nargs,int wait) { +bool vf_rep; +int vf_idx; +int err; + + vf_rep = false; +if (vdev->pf_vdev) { + vf_rep = true; + vf_idx = vdev->vf_id; + vdev = vdev->pf_vdev; + } +if (vdev->lock) + vdev->lock (vdev->priv); +if (vf_rep) +vnic_dev_cmd_proxy_by_index_start (vdev, vf_idx); +switch (vdev->proxy) {case PROXY_BY_INDEX : -return vnic_dev_cmd_proxy (vdev,CMD_PROXY_BY_INDEX , cmd, + err =vnic_dev_cmd_proxy (vdev,CMD_PROXY_BY_INDEX , cmd, args, nargs, wait); +break ;case PROXY_BY_BDF : -return vnic_dev_cmd_proxy (vdev,CMD_PROXY_BY_BDF , cmd, + err =vnic_dev_cmd_proxy (vdev,CMD_PROXY_BY_BDF , cmd, args, nargs, wait); +break ;case PROXY_NONE :default : -return vnic_dev_cmd_no_proxy (vdev, cmd, args, nargs, wait); + err =vnic_dev_cmd_no_proxy (vdev, cmd, args, nargs, wait); +break ; } + +if (vf_rep) +vnic_dev_cmd_proxy_end (vdev); +if (vdev->unlock) + vdev->unlock (vdev->priv); +return err; } int vnic_dev_fw_info(struct vnic_dev *vdev,
@@ -1012,6 +1085,22 @@ uint32_t vnic_dev_port_speed(struct vnic_dev *vdev)return vdev->notify_copy.port_speed; } +uint32_t vnic_dev_mtu (struct vnic_dev *vdev) +{ +if (!vnic_dev_notify_ready (vdev)) +return 0 ; + +return vdev->notify_copy.mtu; +} + +uint32_t vnic_dev_uif (struct vnic_dev *vdev) +{ +if (!vnic_dev_notify_ready (vdev)) +return 0 ; + +return vdev->notify_copy.uif; +} +uint32_t vnic_dev_intr_coal_timer_usec_to_hw (struct vnic_dev *vdev,uint32_t usec) {
@@ -1100,6 +1189,23 @@ struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev,return NULL ; } +struct vnic_dev *vnic_vf_rep_register (void *priv,struct vnic_dev *pf_vdev, +int vf_id) +{ +struct vnic_dev *vdev; + + vdev = (struct vnic_dev *)rte_zmalloc ("enic-vf-rep-vdev" , +sizeof (struct vnic_dev ),RTE_CACHE_LINE_SIZE ); +if (!vdev) +return NULL ; + vdev->priv = priv; + vdev->pf_vdev = pf_vdev; + vdev->vf_id = vf_id; + vdev->alloc_consistent = pf_vdev->alloc_consistent; + vdev->free_consistent = pf_vdev->free_consistent; +return vdev; +} +/* * vnic_dev_classifier: Add/Delete classifier entries * @vdev: vdev of the device
drivers/net/enic/base/vnic_dev.h +4 -0
@@ -80,6 +80,8 @@ void vnic_register_cbacks(struct vnic_dev *vdev,void (*free_consistent)(void *priv,size_t size,void *vaddr, dma_addr_t dma_handle)); +void vnic_register_lock (struct vnic_dev *vdev,void (*lock)(void *priv), +void (*unlock)(void *priv));void __iomem *vnic_dev_get_res (struct vnic_dev *vdev,enum vnic_res_type type,unsigned int index); dma_addr_t vnic_dev_get_res_bus_addr(struct vnic_dev *vdev,
@@ -172,6 +174,8 @@ struct vnic_dev *vnic_dev_register(struct vnic_dev *vdev, void *priv, struct rte_pci_device *pdev, struct vnic_dev_bar *bar, unsigned int num_bars);struct rte_pci_device *vnic_dev_get_pdev (struct vnic_dev *vdev); +struct vnic_dev *vnic_vf_rep_register (void *priv,struct vnic_dev *pf_vdev, +int vf_id);int vnic_dev_alloc_stats_mem (struct vnic_dev *vdev);int vnic_dev_cmd_init (struct vnic_dev *vdev,int fallback);int vnic_dev_get_size (void );
Signature · 1 line
2.26.2
PATCH 2/5 net/enic: add minimal VF representor
In reply to Hyong Youb KimEnable the minimal VF representor without Tx/Rx and flow API support.
1. Enable the standard devarg 'representor'
When the devarg is specified, create VF representor ports.
2. Initialize flowman early during PF probe
Representors require the flowman API from the firmware. Initialize it before creating VF representors, so probe can detect the flowman support and fail if not available.
3. Add enic_fm_allocate_switch_domain() to allocate switch domain ID PFs and VFs on the same VIC adapter can forward packets to each other, so the switch domain is the physical adapter.
4. Create a vnic_dev lock to serialize concurrent devcmd calls PF and VF representor ports may invoke devcmd (e.g. dump stats) simultaneously. As they all share a single PF devcmd instance in the firmware, use a lock to serialize devcmd calls.
--- drivers/net/enic/enic.h | 34 ++ drivers/net/enic/enic_ethdev.c | 107 ++++++- drivers/net/enic/enic_fm_flow.c | 55 +++- drivers/net/enic/enic_main.c | 41 ++- drivers/net/enic/enic_vf_representor.c | 425 +++++++++++++++++++++++++ drivers/net/enic/meson.build | 1 + 6 files changed, 652 insertions(+), 11 deletions(-) create mode 100644 drivers/net/enic/enic_vf_representor.c
drivers/net/enic/enic.h +34 -0
@@ -210,8 +210,38 @@ struct enic {/* Flow manager API */ struct enic_flowman *fm; +/* switchdev */ +uint8_t switchdev_mode; +uint16_t switch_domain_id; +uint16_t max_vf_id; +/* +* Lock to serialize devcmds from PF, VF representors as they all share +* the same PF devcmd instance in firmware. +*/ +rte_spinlock_t devcmd_lock; +}; + +struct enic_vf_representor { +struct enic enic; +struct vnic_enet_config config; +struct rte_eth_dev *eth_dev; +struct rte_ether_addr mac_addr; +struct rte_pci_addr bdf; +struct enic *pf; +uint16_t switch_domain_id; +uint16_t vf_id; +int allmulti; +int promisc; }; +#define VF_ENIC_TO_VF_REP (vf_enic) \ + container_of(vf_enic, struct enic_vf_representor, enic) + +static inline int enic_is_vf_rep (struct enic *enic) +{ +return !!(enic->rte_dev->data->dev_flags &RTE_ETH_DEV_REPRESENTOR ); +} +/* Compute ethdev's max packet size from MTU */ static inline uint32_t enic_mtu_to_max_rx_pktlen (uint32_t mtu) {
@@ -364,6 +394,10 @@ void enic_pick_rx_handler(struct rte_eth_dev *eth_dev);void enic_pick_tx_handler (struct rte_eth_dev *eth_dev);void enic_fdir_info (struct enic *enic);void enic_fdir_info_get (struct enic *enic,struct rte_eth_fdir_info *stats); +int enic_vf_representor_init (struct rte_eth_dev *eth_dev,void *init_params); +int enic_vf_representor_uninit (struct rte_eth_dev *ethdev); +int enic_fm_allocate_switch_domain (struct enic *pf);extern const struct rte_flow_ops enic_flow_ops;extern const struct rte_flow_ops enic_fm_flow_ops; +#endif /* _ENIC_H_ */
drivers/net/enic/enic_ethdev.c +98 -9
146 lines not on this page · raw message
drivers/net/enic/enic_fm_flow.c +54 -1
67 lines not on this page · raw message
drivers/net/enic/enic_main.c +40 -1
75 lines not on this page · raw message
drivers/net/enic/enic_vf_representor.c new file +425 -0
425 lines not on this page · raw message
drivers/net/enic/meson.build +1 -0
@@ -14,6 +14,7 @@ sources = files( 'enic_main.c', 'enic_res.c', 'enic_rxtx.c', + 'enic_vf_representor.c', ) deps += ['hash'] includes += include_directories('base')
Signature · 1 line
2.26.2
PATCH 3/5 net/enic: add single-queue Tx and Rx to VF representor
In reply to Hyong Youb KimA VF representor allocates queues from PF's pool of queues and use them for its Tx and Rx. It supports 1 Tx queue and 1 Rx queue.
Implicit packet forwarding between representor queues and VF does not yet exist. It will be enabled in subsequent commits using flowman API.
--- drivers/net/enic/enic.h | 74 ++++++++++ drivers/net/enic/enic_main.c | 73 ++++++++-- drivers/net/enic/enic_vf_representor.c | 188 ++++++++++++++++++++++--- 3 files changed, 299 insertions(+), 36 deletions(-)
drivers/net/enic/enic.h +74 -0
@@ -214,6 +214,10 @@ struct enic {uint8_t switchdev_mode;uint16_t switch_domain_id;uint16_t max_vf_id; +/* Number of queues needed for VF representor paths */ +uint32_t vf_required_wq; +uint32_t vf_required_cq; +uint32_t vf_required_rq;/* * Lock to serialize devcmds from PF, VF representors as they all share * the same PF devcmd instance in firmware.
@@ -232,6 +236,11 @@ struct enic_vf_representor {uint16_t vf_id;int allmulti;int promisc; +/* Representor path uses PF queues. These are reserved during init */ +uint16_t pf_wq_idx;/* WQ dedicated to VF rep */ +uint16_t pf_wq_cq_idx;/* CQ for WQ */ +uint16_t pf_rq_sop_idx;/* SOP RQ dedicated to VF rep */ +uint16_t pf_rq_data_idx;/* Data RQ */ };#define VF_ENIC_TO_VF_REP (vf_enic) \
@@ -293,6 +302,67 @@ static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)return enic->rq_count + wq; } +/* +* WQ, RQ, CQ allocation scheme. Firmware gives the driver an array of +* WQs, an array of RQs, and an array of CQs. Fow now, these are +* statically allocated between PF app send/receive queues and VF +* representor app send/receive queues. VF representor supports only 1 +* send and 1 receive queue. The number of PF app queue is not known +* until the queue setup time. +* +* R = number of receive queues for PF app +* S = number of send queues for PF app +* V = number of VF representors +* +* wI = WQ for PF app send queue I +* rI = SOP RQ for PF app receive queue I +* dI = Data RQ for rI +* cwI = CQ for wI +* crI = CQ for rI +* vwI = WQ for VF representor send queue I +* vrI = SOP RQ for VF representor receive queue I +* vdI = Data RQ for vrI +* vcwI = CQ for vwI +* vcrI = CQ for vrI +* +* WQ array: | w0 |..| wS-1 |..| vwV-1 |..| vw0 | +* ^ ^ ^ ^ +* index 0 S-1 W-V W-1 W=len(WQ array) +* +* RQ array: | r0 |..| rR-1 |d0 |..|dR-1| ..|vdV-1 |..| vd0 |vrV-1 |..|vr0 | +* ^ ^ ^ ^ ^ ^ ^ ^ +* index 0 R-1 R 2R-1 X-2V X-(V+1) X-V X-1 +* X=len(RQ array) +* +* CQ array: | cr0 |..| crR-1 |cw0|..|cwS-1|..|vcwV-1|..| vcw0|vcrV-1|..|vcr0|.. +* ^ ^ ^ ^ ^ ^ ^ ^ +* index 0 R-1 R R+S-1 X-2V X-(V+1) X-V X-1 +* X is not a typo. It really is len(RQ array) to accommodate enic_cq_rq() used +* throughout RX handlers. The current scheme requires +* len(CQ array) >= len(RQ array). +*/ + +static inline unsigned int vf_wq_cq_idx (struct enic_vf_representor *vf) +{ +/* rq is not a typo. index(vcwI) coincides with index(vdI) */ +return vf->pf->conf_rq_count - (vf->pf->max_vf_id + vf->vf_id +2 ); +} + +static inline unsigned int vf_wq_idx (struct enic_vf_representor *vf) +{ +return vf->pf->conf_wq_count - vf->vf_id -1 ; +} + +static inline unsigned int vf_rq_sop_idx (struct enic_vf_representor *vf) +{ +return vf->pf->conf_rq_count - vf->vf_id -1 ; +} + +static inline unsigned int vf_rq_data_idx (struct enic_vf_representor *vf) +{ +return vf->pf->conf_rq_count - (vf->pf->max_vf_id + vf->vf_id +2 ); +} +static inline struct enic *pmd_priv (struct rte_eth_dev *eth_dev) {return eth_dev->data->dev_private;
@@ -397,6 +467,10 @@ void enic_fdir_info_get(struct enic *enic, struct rte_eth_fdir_info *stats);int enic_vf_representor_init (struct rte_eth_dev *eth_dev,void *init_params);int enic_vf_representor_uninit (struct rte_eth_dev *ethdev);int enic_fm_allocate_switch_domain (struct enic *pf); +int enic_alloc_rx_queue_mbufs (struct enic *enic,struct vnic_rq *rq); +void enic_rxmbuf_queue_release (struct enic *enic,struct vnic_rq *rq); +void enic_free_wq_buf (struct rte_mbuf **buf); +void enic_free_rq_buf (struct rte_mbuf **mbuf);extern const struct rte_flow_ops enic_flow_ops;extern const struct rte_flow_ops enic_fm_flow_ops;
drivers/net/enic/enic_main.c +59 -14
143 lines not on this page · raw message
drivers/net/enic/enic_vf_representor.c +166 -22
255 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 4/5 net/enic: extend flow handler to support VF representors
In reply to Hyong Youb KimVF representor ports can create flows on VFs through the PF flowman (Flow Manager) instance in the firmware. These flows match packets egressing from VFs and apply flowman actions.
1. Make flow handler aware of VF representors
When a representor port invokes flow APIs, use the PF port's flowman instance to perform flowman devcmd. If the port ID refers to a representor, use VF handle instead of PF handle.
2. Serialize flow API calls
Multiple application thread may invoke flow APIs through PF and VF representor ports simultaneously. This leads to races, as ports all share the same PF flowman instance. Use a lock to serialize API calls. Lock is used only when representors exist.
3. Add functions to create flows for implicit representor paths There is an implicit path between VF and its representor. The functions below create flow rules to implement that path.
- enic_fm_add_rep2vf_flow()
- enic_fm_add_vf2rep_flow()
The flows created for representor paths are marked as internal. These are not visible to application, and the flush API does not destroy them. They are automatically deleted when the representor port stops (enic_fm_destroy).
--- drivers/net/enic/enic.h | 8 + drivers/net/enic/enic_fm_flow.c | 432 ++++++++++++++++++++++++++++---- 2 files changed, 396 insertions(+), 44 deletions(-)
drivers/net/enic/enic.h +8 -0
@@ -101,6 +101,7 @@ struct rte_flow {struct filter_v2 enic_filter;/* Data for flow manager based flow (enic_fm_flow.c) */ struct enic_fm_flow *fm; +int internal; };/* Per-instance private data structure */
@@ -210,6 +211,8 @@ struct enic {/* Flow manager API */ struct enic_flowman *fm; +uint64_t fm_vnic_handle; +uint32_t fm_vnic_uif;/* switchdev */ uint8_t switchdev_mode;uint16_t switch_domain_id;
@@ -241,6 +244,9 @@ struct enic_vf_representor {uint16_t pf_wq_cq_idx;/* CQ for WQ */ uint16_t pf_rq_sop_idx;/* SOP RQ dedicated to VF rep */ uint16_t pf_rq_data_idx;/* Data RQ */ +/* Representor flows managed by flowman */ +struct rte_flow *vf2rep_flow[2 ]; +struct rte_flow *rep2vf_flow[2 ]; };#define VF_ENIC_TO_VF_REP (vf_enic) \
@@ -467,6 +473,8 @@ void enic_fdir_info_get(struct enic *enic, struct rte_eth_fdir_info *stats);int enic_vf_representor_init (struct rte_eth_dev *eth_dev,void *init_params);int enic_vf_representor_uninit (struct rte_eth_dev *ethdev);int enic_fm_allocate_switch_domain (struct enic *pf); +int enic_fm_add_rep2vf_flow (struct enic_vf_representor *vf); +int enic_fm_add_vf2rep_flow (struct enic_vf_representor *vf);int enic_alloc_rx_queue_mbufs (struct enic *enic,struct vnic_rq *rq);void enic_rxmbuf_queue_release (struct enic *enic,struct vnic_rq *rq);void enic_free_wq_buf (struct rte_mbuf **buf);
drivers/net/enic/enic_fm_flow.c +388 -44
742 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH 5/5 net/enic: enable flow API for VF representor
In reply to Hyong Youb KimUse Flow Manager (flowman) to support flow API for representors. Representor's flow handlers simply invoke PF handlers and pass the representor's flowman structure. The PF flowman handlers are aware of representors and perform appropriate devcmds to create flows on the NIC.
Also use flowman to create internal flows for implicit VF-representor path. With that, representor Tx/Rx is now functional.
--- doc/guides/rel_notes/release_20_11.rst | 4 + drivers/net/enic/enic_vf_representor.c | 160 +++++++++++++++++++++++++ 2 files changed, 164 insertions(+)
doc/guides/rel_notes/release_20_11.rst +4 -0
@@ -134,3 +134,7 @@ Tested Platforms This section is a comment. Do not overwrite or remove it. Also, make sure to start the actual text at the margin. ======================================================= + +* **Updated Cisco enic driver.** + + * Added support for VF representors with single-queue Tx/Rx and flow API
drivers/net/enic/enic_vf_representor.c +160 -0
190 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 13 lines · Hyong Youb Kim
This series adds VF representors to the driver. It enables single-queue representors and implements enough flow features to run OVS-DPDK offload for default vlan+mac based switching.
The flow API handlers and devcmd functions (firmware commands) are now aware of representors. Representors reserve PF Tx/Rx queues for their implicit paths to/from VFs. Packet forwarding rules for these implicit paths are set up using firmware's Flow Manager (flowman), which is also used for
rte_flowAPI.Thanks.
-Hyong
Quoted 7 lines
Hyong Youb Kim (5):
net/enic: extend vnic dev API for VF representors net/enic: add minimal VF representor
net/enic: add single-queue Tx and Rx to VF representor net/enic: extend flow handler to support VF representors net/enic: enable flow API for VF representor
Series applied to dpdk-next-net/main, thanks.