120 lines · c
1/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */2/* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */3 4#ifndef __MLX5_VNET_H__5#define __MLX5_VNET_H__6 7#include "mlx5_vdpa.h"8 9#define to_mlx5_vdpa_ndev(__mvdev) \10 container_of(__mvdev, struct mlx5_vdpa_net, mvdev)11#define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)12 13struct mlx5_vdpa_net_resources {14 u32 tisn;15 u32 tdn;16 u32 tirn;17 u32 rqtn;18 bool valid;19 struct dentry *tirn_dent;20};21 22#define MLX5V_MACVLAN_SIZE 25623 24static inline u16 key2vid(u64 key)25{26 return (u16)(key >> 48) & 0xfff;27}28 29#define MLX5_VDPA_IRQ_NAME_LEN 3230 31struct mlx5_vdpa_irq_pool_entry {32 struct msi_map map;33 bool used;34 char name[MLX5_VDPA_IRQ_NAME_LEN];35 void *dev_id;36};37 38struct mlx5_vdpa_irq_pool {39 int num_ent;40 struct mlx5_vdpa_irq_pool_entry *entries;41};42 43struct mlx5_vdpa_net {44 struct mlx5_vdpa_dev mvdev;45 struct mlx5_vdpa_net_resources res;46 struct virtio_net_config config;47 struct mlx5_vdpa_virtqueue *vqs;48 struct vdpa_callback *event_cbs;49 50 /* Serialize vq resources creation and destruction. This is required51 * since memory map might change and we need to destroy and create52 * resources while driver in operational.53 */54 struct rw_semaphore reslock;55 struct mlx5_flow_table *rxft;56 struct dentry *rx_dent;57 struct dentry *rx_table_dent;58 bool setup;59 bool needs_teardown;60 u32 cur_num_vqs;61 u32 rqt_size;62 bool nb_registered;63 struct notifier_block nb;64 struct vdpa_callback config_cb;65 struct mlx5_vdpa_wq_ent cvq_ent;66 struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];67 struct mlx5_vdpa_irq_pool irqp;68 struct dentry *debugfs;69 70 u32 umem_1_buffer_param_a;71 u32 umem_1_buffer_param_b;72 73 u32 umem_2_buffer_param_a;74 u32 umem_2_buffer_param_b;75 76 u32 umem_3_buffer_param_a;77 u32 umem_3_buffer_param_b;78};79 80struct mlx5_vdpa_counter {81 struct mlx5_fc *counter;82 struct dentry *dent;83 struct mlx5_core_dev *mdev;84};85 86struct macvlan_node {87 struct hlist_node hlist;88 struct mlx5_flow_handle *ucast_rule;89 struct mlx5_flow_handle *mcast_rule;90 u64 macvlan;91 struct mlx5_vdpa_net *ndev;92 bool tagged;93#if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)94 struct dentry *dent;95 struct mlx5_vdpa_counter ucast_counter;96 struct mlx5_vdpa_counter mcast_counter;97#endif98};99 100void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);101void mlx5_vdpa_remove_debugfs(struct mlx5_vdpa_net *ndev);102void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);103void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);104void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);105void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev);106#if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)107void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,108 struct macvlan_node *node);109void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,110 struct macvlan_node *node);111#else112static inline void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,113 struct macvlan_node *node) {}114static inline void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,115 struct macvlan_node *node) {}116#endif117 118 119#endif /* __MLX5_VNET_H__ */120