blob: 0b2cc4e7970750d4e9fbfcbad6a26a307d3a1c0e [file] [log] [blame]
Upinder Malhie3cf00d2013-09-10 03:38:16 +00001/*
2 * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
3 *
Jeff Squyres3805ead2015-09-30 13:34:00 -07004 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
Upinder Malhie3cf00d2013-09-10 03:38:16 +000022 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 *
32 */
33
34#ifndef USNIC_FWD_H_
35#define USNIC_FWD_H_
36
37#include <linux/if.h>
Upinder Malhi2183b992014-01-09 14:48:07 -080038#include <linux/netdevice.h>
Selvin Xavier69ae5432016-12-19 11:28:46 -080039#include <linux/if_ether.h>
Upinder Malhie3cf00d2013-09-10 03:38:16 +000040#include <linux/pci.h>
Upinder Malhi2183b992014-01-09 14:48:07 -080041#include <linux/in.h>
Upinder Malhie3cf00d2013-09-10 03:38:16 +000042
43#include "usnic_abi.h"
Upinder Malhi2183b992014-01-09 14:48:07 -080044#include "usnic_common_pkt_hdr.h"
Upinder Malhie3cf00d2013-09-10 03:38:16 +000045#include "vnic_devcmd.h"
46
47struct usnic_fwd_dev {
48 struct pci_dev *pdev;
49 struct net_device *netdev;
50 spinlock_t lock;
Upinder Malhi2183b992014-01-09 14:48:07 -080051 /*
52 * The following fields can be read directly off the device.
53 * However, they should be set by a accessor function, except name,
54 * which cannot be changed.
55 */
56 bool link_up;
57 char mac[ETH_ALEN];
58 unsigned int mtu;
Upinder Malhi3f92bed2014-01-09 14:48:15 -080059 __be32 inaddr;
Upinder Malhi2183b992014-01-09 14:48:07 -080060 char name[IFNAMSIZ+1];
Upinder Malhie3cf00d2013-09-10 03:38:16 +000061};
62
Upinder Malhi2183b992014-01-09 14:48:07 -080063struct usnic_fwd_flow {
64 uint32_t flow_id;
Upinder Malhie3cf00d2013-09-10 03:38:16 +000065 struct usnic_fwd_dev *ufdev;
Upinder Malhi2183b992014-01-09 14:48:07 -080066 unsigned int vnic_idx;
67};
68
69struct usnic_filter_action {
70 int vnic_idx;
71 struct filter_action action;
Upinder Malhie3cf00d2013-09-10 03:38:16 +000072};
73
74struct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev);
75void usnic_fwd_dev_free(struct usnic_fwd_dev *ufdev);
Upinder Malhi2183b992014-01-09 14:48:07 -080076
77void usnic_fwd_set_mac(struct usnic_fwd_dev *ufdev, char mac[ETH_ALEN]);
Leon Romanovsky5d50f402017-08-17 15:50:41 +030078void usnic_fwd_add_ipaddr(struct usnic_fwd_dev *ufdev, __be32 inaddr);
Upinder Malhi3f92bed2014-01-09 14:48:15 -080079void usnic_fwd_del_ipaddr(struct usnic_fwd_dev *ufdev);
Upinder Malhi2183b992014-01-09 14:48:07 -080080void 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 * Allocate a flow on this forwarding device. Whoever calls this function,
86 * must monitor netdev events on ufdev's netdevice. If NETDEV_REBOOT or
87 * NETDEV_DOWN is seen, flow will no longer function and must be
88 * immediately freed by calling usnic_dealloc_flow.
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;
Selvin Xavier69ae5432016-12-19 11:28:46 -0800101 filter->u.usnic.ethtype = ETH_P_IBOE;
Upinder Malhi2183b992014-01-09 14:48:07 -0800102 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}
Upinder Malhie3cf00d2013-09-10 03:38:16 +0000110
Upinder Malhi3f92bed2014-01-09 14:48:15 -0800111static 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
Upinder Malhie3cf00d2013-09-10 03:38:16 +0000129#endif /* !USNIC_FWD_H_ */