1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 #include <linux/if_link.h>
5 
6 #include "sd-device.h"
7 
8 #include "conf-parser.h"
9 #include "ether-addr-util.h"
10 #include "hashmap.h"
11 
12 typedef enum SRIOVLinkState {
13         SR_IOV_LINK_STATE_AUTO = IFLA_VF_LINK_STATE_AUTO,
14         SR_IOV_LINK_STATE_ENABLE = IFLA_VF_LINK_STATE_ENABLE,
15         SR_IOV_LINK_STATE_DISABLE = IFLA_VF_LINK_STATE_DISABLE,
16         _SR_IOV_LINK_STATE_MAX,
17         _SR_IOV_LINK_STATE_INVALID = -EINVAL,
18 } SRIOVLinkState;
19 
20 typedef struct SRIOV {
21         ConfigSection *section;
22         OrderedHashmap *sr_iov_by_section;
23 
24         uint32_t vf;   /* 0 - 2147483646 */
25         uint32_t vlan; /* 0 - 4095, 0 disables VLAN filter */
26         uint32_t qos;
27         uint16_t vlan_proto; /* ETH_P_8021Q or ETH_P_8021AD */
28         int vf_spoof_check_setting;
29         int query_rss;
30         int trust;
31         SRIOVLinkState link_state;
32         struct ether_addr mac;
33 } SRIOV;
34 
35 SRIOV *sr_iov_free(SRIOV *sr_iov);
36 void sr_iov_hash_func(const SRIOV *sr_iov, struct siphash *state);
37 int sr_iov_compare_func(const SRIOV *s1, const SRIOV *s2);
38 int sr_iov_set_netlink_message(SRIOV *sr_iov, sd_netlink_message *req);
39 int sr_iov_get_num_vfs(sd_device *device, uint32_t *ret);
40 int sr_iov_set_num_vfs(sd_device *device, uint32_t num_vfs, OrderedHashmap *sr_iov_by_section);
41 int sr_iov_drop_invalid_sections(uint32_t num_vfs, OrderedHashmap *sr_iov_by_section);
42 
43 DEFINE_SECTION_CLEANUP_FUNCTIONS(SRIOV, sr_iov_free);
44 
45 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_uint32);
46 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_boolean);
47 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_link_state);
48 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_vlan_proto);
49 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_mac);
50 CONFIG_PARSER_PROTOTYPE(config_parse_sr_iov_num_vfs);
51