2 * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
4 * This program is free software; you may redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
10 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
11 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
12 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
13 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include <linux/netdevice.h>
24 #include <linux/pci.h>
27 #include "usnic_abi.h"
28 #include "usnic_common_pkt_hdr.h"
29 #include "vnic_devcmd.h"
31 struct usnic_fwd_dev
{
33 struct net_device
*netdev
;
36 * The following fields can be read directly off the device.
37 * However, they should be set by a accessor function, except name,
38 * which cannot be changed.
44 char name
[IFNAMSIZ
+1];
47 struct usnic_fwd_flow
{
49 struct usnic_fwd_dev
*ufdev
;
50 unsigned int vnic_idx
;
53 struct usnic_filter_action
{
55 struct filter_action action
;
58 struct usnic_fwd_dev
*usnic_fwd_dev_alloc(struct pci_dev
*pdev
);
59 void usnic_fwd_dev_free(struct usnic_fwd_dev
*ufdev
);
61 void usnic_fwd_set_mac(struct usnic_fwd_dev
*ufdev
, char mac
[ETH_ALEN
]);
62 int usnic_fwd_add_ipaddr(struct usnic_fwd_dev
*ufdev
, __be32 inaddr
);
63 void usnic_fwd_del_ipaddr(struct usnic_fwd_dev
*ufdev
);
64 void usnic_fwd_carrier_up(struct usnic_fwd_dev
*ufdev
);
65 void usnic_fwd_carrier_down(struct usnic_fwd_dev
*ufdev
);
66 void usnic_fwd_set_mtu(struct usnic_fwd_dev
*ufdev
, unsigned int mtu
);
69 * Allocate a flow on this forwarding device. Whoever calls this function,
70 * must monitor netdev events on ufdev's netdevice. If NETDEV_REBOOT or
71 * NETDEV_DOWN is seen, flow will no longer function and must be
72 * immediately freed by calling usnic_dealloc_flow.
74 struct usnic_fwd_flow
*
75 usnic_fwd_alloc_flow(struct usnic_fwd_dev
*ufdev
, struct filter
*filter
,
76 struct usnic_filter_action
*action
);
77 int usnic_fwd_dealloc_flow(struct usnic_fwd_flow
*flow
);
78 int usnic_fwd_enable_qp(struct usnic_fwd_dev
*ufdev
, int vnic_idx
, int qp_idx
);
79 int usnic_fwd_disable_qp(struct usnic_fwd_dev
*ufdev
, int vnic_idx
, int qp_idx
);
81 static inline void usnic_fwd_init_usnic_filter(struct filter
*filter
,
84 filter
->type
= FILTER_USNIC_ID
;
85 filter
->u
.usnic
.ethtype
= USNIC_ROCE_ETHERTYPE
;
86 filter
->u
.usnic
.flags
= FILTER_FIELD_USNIC_ETHTYPE
|
87 FILTER_FIELD_USNIC_ID
|
88 FILTER_FIELD_USNIC_PROTO
;
89 filter
->u
.usnic
.proto_version
= (USNIC_ROCE_GRH_VER
<<
90 USNIC_ROCE_GRH_VER_SHIFT
) |
92 filter
->u
.usnic
.usnic_id
= usnic_id
;
95 static inline void usnic_fwd_init_udp_filter(struct filter
*filter
,
96 uint32_t daddr
, uint16_t dport
)
98 filter
->type
= FILTER_IPV4_5TUPLE
;
99 filter
->u
.ipv4
.flags
= FILTER_FIELD_5TUP_PROTO
;
100 filter
->u
.ipv4
.protocol
= PROTO_UDP
;
103 filter
->u
.ipv4
.flags
|= FILTER_FIELD_5TUP_DST_AD
;
104 filter
->u
.ipv4
.dst_addr
= daddr
;
108 filter
->u
.ipv4
.flags
|= FILTER_FIELD_5TUP_DST_PT
;
109 filter
->u
.ipv4
.dst_port
= dport
;
113 #endif /* !USNIC_FWD_H_ */