blob: b146eb97d82c51dd87157bf08ccd9df453aa87c3 [file] [log] [blame]
Upinder Malhie3cf00d2013-09-10 03:38:16 +00001/*
2 * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
3 *
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.
7 *
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
15 * SOFTWARE.
16 *
17 */
18
19#ifndef USNIC_FWD_H_
20#define USNIC_FWD_H_
21
22#include <linux/if.h>
Upinder Malhi2183b992014-01-09 14:48:07 -080023#include <linux/netdevice.h>
Upinder Malhie3cf00d2013-09-10 03:38:16 +000024#include <linux/pci.h>
Upinder Malhi2183b992014-01-09 14:48:07 -080025#include <linux/in.h>
Upinder Malhie3cf00d2013-09-10 03:38:16 +000026
27#include "usnic_abi.h"
Upinder Malhi2183b992014-01-09 14:48:07 -080028#include "usnic_common_pkt_hdr.h"
Upinder Malhie3cf00d2013-09-10 03:38:16 +000029#include "vnic_devcmd.h"
30
31struct usnic_fwd_dev {
32 struct pci_dev *pdev;
33 struct net_device *netdev;
34 spinlock_t lock;
Upinder Malhi2183b992014-01-09 14:48:07 -080035 /*
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.
39 */
40 bool link_up;
41 char mac[ETH_ALEN];
42 unsigned int mtu;
43 char name[IFNAMSIZ+1];
Upinder Malhie3cf00d2013-09-10 03:38:16 +000044};
45
Upinder Malhi2183b992014-01-09 14:48:07 -080046struct usnic_fwd_flow {
47 uint32_t flow_id;
Upinder Malhie3cf00d2013-09-10 03:38:16 +000048 struct usnic_fwd_dev *ufdev;
Upinder Malhi2183b992014-01-09 14:48:07 -080049 unsigned int vnic_idx;
50};
51
52struct usnic_filter_action {
53 int vnic_idx;
54 struct filter_action action;
Upinder Malhie3cf00d2013-09-10 03:38:16 +000055};
56
57struct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev);
58void usnic_fwd_dev_free(struct usnic_fwd_dev *ufdev);
Upinder Malhi2183b992014-01-09 14:48:07 -080059
60void usnic_fwd_set_mac(struct usnic_fwd_dev *ufdev, char mac[ETH_ALEN]);
61void usnic_fwd_carrier_up(struct usnic_fwd_dev *ufdev);
62void usnic_fwd_carrier_down(struct usnic_fwd_dev *ufdev);
63void usnic_fwd_set_mtu(struct usnic_fwd_dev *ufdev, unsigned int mtu);
64
65/*
66 * Allocate a flow on this forwarding device. Whoever calls this function,
67 * must monitor netdev events on ufdev's netdevice. If NETDEV_REBOOT or
68 * NETDEV_DOWN is seen, flow will no longer function and must be
69 * immediately freed by calling usnic_dealloc_flow.
70 */
71struct usnic_fwd_flow*
72usnic_fwd_alloc_flow(struct usnic_fwd_dev *ufdev, struct filter *filter,
73 struct usnic_filter_action *action);
74int usnic_fwd_dealloc_flow(struct usnic_fwd_flow *flow);
75int usnic_fwd_enable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx);
76int usnic_fwd_disable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx);
77
78static inline void usnic_fwd_init_usnic_filter(struct filter *filter,
79 uint32_t usnic_id)
80{
81 filter->type = FILTER_USNIC_ID;
82 filter->u.usnic.ethtype = USNIC_ROCE_ETHERTYPE;
83 filter->u.usnic.flags = FILTER_FIELD_USNIC_ETHTYPE |
84 FILTER_FIELD_USNIC_ID |
85 FILTER_FIELD_USNIC_PROTO;
86 filter->u.usnic.proto_version = (USNIC_ROCE_GRH_VER <<
87 USNIC_ROCE_GRH_VER_SHIFT) |
88 USNIC_PROTO_VER;
89 filter->u.usnic.usnic_id = usnic_id;
90}
Upinder Malhie3cf00d2013-09-10 03:38:16 +000091
92#endif /* !USNIC_FWD_H_ */