1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34#ifndef USNIC_FWD_H_
35#define USNIC_FWD_H_
36
37#include <linux/if.h>
38#include <linux/netdevice.h>
39#include <linux/if_ether.h>
40#include <linux/pci.h>
41#include <linux/in.h>
42
43#include "usnic_abi.h"
44#include "usnic_common_pkt_hdr.h"
45#include "vnic_devcmd.h"
46
47struct usnic_fwd_dev {
48 struct pci_dev *pdev;
49 struct net_device *netdev;
50 spinlock_t lock;
51
52
53
54
55
56 bool link_up;
57 char mac[ETH_ALEN];
58 unsigned int mtu;
59 __be32 inaddr;
60 char name[IFNAMSIZ];
61};
62
63struct usnic_fwd_flow {
64 uint32_t flow_id;
65 struct usnic_fwd_dev *ufdev;
66 unsigned int vnic_idx;
67};
68
69struct usnic_filter_action {
70 int vnic_idx;
71 struct filter_action action;
72};
73
74struct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev);
75void usnic_fwd_dev_free(struct usnic_fwd_dev *ufdev);
76
77void usnic_fwd_set_mac(struct usnic_fwd_dev *ufdev, char mac[ETH_ALEN]);
78void usnic_fwd_add_ipaddr(struct usnic_fwd_dev *ufdev, __be32 inaddr);
79void usnic_fwd_del_ipaddr(struct usnic_fwd_dev *ufdev);
80void usnic_fwd_carrier_up(struct usnic_fwd_dev *ufdev);
81void usnic_fwd_carrier_down(struct usnic_fwd_dev *ufdev);
82void usnic_fwd_set_mtu(struct usnic_fwd_dev *ufdev, unsigned int mtu);
83
84
85
86
87
88
89
90struct usnic_fwd_flow*
91usnic_fwd_alloc_flow(struct usnic_fwd_dev *ufdev, struct filter *filter,
92 struct usnic_filter_action *action);
93int usnic_fwd_dealloc_flow(struct usnic_fwd_flow *flow);
94int usnic_fwd_enable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx);
95int usnic_fwd_disable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx);
96
97static inline void usnic_fwd_init_usnic_filter(struct filter *filter,
98 uint32_t usnic_id)
99{
100 filter->type = FILTER_USNIC_ID;
101 filter->u.usnic.ethtype = ETH_P_IBOE;
102 filter->u.usnic.flags = FILTER_FIELD_USNIC_ETHTYPE |
103 FILTER_FIELD_USNIC_ID |
104 FILTER_FIELD_USNIC_PROTO;
105 filter->u.usnic.proto_version = (USNIC_ROCE_GRH_VER <<
106 USNIC_ROCE_GRH_VER_SHIFT) |
107 USNIC_PROTO_VER;
108 filter->u.usnic.usnic_id = usnic_id;
109}
110
111static inline void usnic_fwd_init_udp_filter(struct filter *filter,
112 uint32_t daddr, uint16_t dport)
113{
114 filter->type = FILTER_IPV4_5TUPLE;
115 filter->u.ipv4.flags = FILTER_FIELD_5TUP_PROTO;
116 filter->u.ipv4.protocol = PROTO_UDP;
117
118 if (daddr) {
119 filter->u.ipv4.flags |= FILTER_FIELD_5TUP_DST_AD;
120 filter->u.ipv4.dst_addr = daddr;
121 }
122
123 if (dport) {
124 filter->u.ipv4.flags |= FILTER_FIELD_5TUP_DST_PT;
125 filter->u.ipv4.dst_port = dport;
126 }
127}
128
129#endif
130