Upinder Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 1 | /* |
| 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 Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 23 | #include <linux/netdevice.h> |
Upinder Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 24 | #include <linux/pci.h> |
Upinder Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 25 | #include <linux/in.h> |
Upinder Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 26 | |
| 27 | #include "usnic_abi.h" |
Upinder Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 28 | #include "usnic_common_pkt_hdr.h" |
Upinder Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 29 | #include "vnic_devcmd.h" |
| 30 | |
| 31 | struct usnic_fwd_dev { |
| 32 | struct pci_dev *pdev; |
| 33 | struct net_device *netdev; |
| 34 | spinlock_t lock; |
Upinder Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 35 | /* |
| 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 Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
Upinder Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 46 | struct usnic_fwd_flow { |
| 47 | uint32_t flow_id; |
Upinder Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 48 | struct usnic_fwd_dev *ufdev; |
Upinder Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 49 | unsigned int vnic_idx; |
| 50 | }; |
| 51 | |
| 52 | struct usnic_filter_action { |
| 53 | int vnic_idx; |
| 54 | struct filter_action action; |
Upinder Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | struct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev); |
| 58 | void usnic_fwd_dev_free(struct usnic_fwd_dev *ufdev); |
Upinder Malhi | 2183b99 | 2014-01-09 14:48:07 -0800 | [diff] [blame^] | 59 | |
| 60 | void usnic_fwd_set_mac(struct usnic_fwd_dev *ufdev, char mac[ETH_ALEN]); |
| 61 | void usnic_fwd_carrier_up(struct usnic_fwd_dev *ufdev); |
| 62 | void usnic_fwd_carrier_down(struct usnic_fwd_dev *ufdev); |
| 63 | void 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 | */ |
| 71 | struct usnic_fwd_flow* |
| 72 | usnic_fwd_alloc_flow(struct usnic_fwd_dev *ufdev, struct filter *filter, |
| 73 | struct usnic_filter_action *action); |
| 74 | int usnic_fwd_dealloc_flow(struct usnic_fwd_flow *flow); |
| 75 | int usnic_fwd_enable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx); |
| 76 | int usnic_fwd_disable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx); |
| 77 | |
| 78 | static 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 Malhi | e3cf00d | 2013-09-10 03:38:16 +0000 | [diff] [blame] | 91 | |
| 92 | #endif /* !USNIC_FWD_H_ */ |