9be87c016ed6fa0e21d2a62c598432c2ddfb913c
[dpdk.git] / drivers / net / mlx5 / mlx5_nl.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2019 Mellanox Technologies, Ltd
3  */
4
5 #ifndef RTE_PMD_MLX5_NL_H_
6 #define RTE_PMD_MLX5_NL_H_
7
8 #include <linux/netlink.h>
9
10
11 /* Recognized Infiniband device physical port name types. */
12 enum mlx5_nl_phys_port_name_type {
13         MLX5_PHYS_PORT_NAME_TYPE_NOTSET = 0, /* Not set. */
14         MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 */
15         MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >= 5.0 */
16         MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >= 5.0 */
17         MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */
18 };
19
20 /** Switch information returned by mlx5_nl_switch_info(). */
21 struct mlx5_switch_info {
22         uint32_t master:1; /**< Master device. */
23         uint32_t representor:1; /**< Representor device. */
24         enum mlx5_nl_phys_port_name_type name_type; /** < Port name type. */
25         int32_t pf_num; /**< PF number (valid for pfxvfx format only). */
26         int32_t port_name; /**< Representor port name. */
27         uint64_t switch_id; /**< Switch identifier. */
28 };
29
30 /* VLAN netdev for VLAN workaround. */
31 struct mlx5_nl_vlan_dev {
32         uint32_t refcnt;
33         uint32_t ifindex; /**< Own interface index. */
34 };
35
36 /*
37  * Array of VLAN devices created on the base of VF
38  * used for workaround in virtual environments.
39  */
40 struct mlx5_nl_vlan_vmwa_context {
41         int nl_socket;
42         uint32_t vf_ifindex;
43         struct mlx5_nl_vlan_dev vlan_dev[4096];
44 };
45
46
47 int mlx5_nl_init(int protocol);
48 int mlx5_nl_mac_addr_add(int nlsk_fd, unsigned int iface_idx, uint64_t *mac_own,
49                          struct rte_ether_addr *mac, uint32_t index);
50 int mlx5_nl_mac_addr_remove(int nlsk_fd, unsigned int iface_idx,
51                             uint64_t *mac_own, struct rte_ether_addr *mac,
52                             uint32_t index);
53 void mlx5_nl_mac_addr_sync(int nlsk_fd, unsigned int iface_idx,
54                            struct rte_ether_addr *mac_addrs, int n);
55 void mlx5_nl_mac_addr_flush(int nlsk_fd, unsigned int iface_idx,
56                             struct rte_ether_addr *mac_addrs, int n,
57                             uint64_t *mac_own);
58 int mlx5_nl_promisc(int nlsk_fd, unsigned int iface_idx, int enable);
59 int mlx5_nl_allmulti(int nlsk_fd, unsigned int iface_idx, int enable);
60 unsigned int mlx5_nl_portnum(int nl, const char *name);
61 unsigned int mlx5_nl_ifindex(int nl, const char *name, uint32_t pindex);
62 int mlx5_nl_vf_mac_addr_modify(int nlsk_fd, unsigned int iface_idx,
63                                struct rte_ether_addr *mac, int vf_index);
64 int mlx5_nl_switch_info(int nl, unsigned int ifindex,
65                         struct mlx5_switch_info *info);
66
67 void mlx5_nl_vlan_vmwa_delete(struct mlx5_nl_vlan_vmwa_context *vmwa,
68                               uint32_t ifindex);
69 uint32_t mlx5_nl_vlan_vmwa_create(struct mlx5_nl_vlan_vmwa_context *vmwa,
70                                   uint32_t ifindex, uint16_t tag);
71
72 #endif /* RTE_PMD_MLX5_NL_H_ */