162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * This software is available to you under a choice of one of two 562306a36Sopenharmony_ci * licenses. You may choose to be licensed under the terms of the GNU 662306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file 762306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the 862306a36Sopenharmony_ci * BSD license below: 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or 1162306a36Sopenharmony_ci * without modification, are permitted provided that the following 1262306a36Sopenharmony_ci * conditions are met: 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * - Redistributions of source code must retain the above 1562306a36Sopenharmony_ci * copyright notice, this list of conditions and the following 1662306a36Sopenharmony_ci * disclaimer. 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * - Redistributions in binary form must reproduce the above 1962306a36Sopenharmony_ci * copyright notice, this list of conditions and the following 2062306a36Sopenharmony_ci * disclaimer in the documentation and/or other materials 2162306a36Sopenharmony_ci * provided with the distribution. 2262306a36Sopenharmony_ci * 2362306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 2462306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2562306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 2662306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 2762306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 2862306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2962306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 3062306a36Sopenharmony_ci * SOFTWARE. 3162306a36Sopenharmony_ci * 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#ifndef USNIC_FWD_H_ 3562306a36Sopenharmony_ci#define USNIC_FWD_H_ 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#include <linux/if.h> 3862306a36Sopenharmony_ci#include <linux/netdevice.h> 3962306a36Sopenharmony_ci#include <linux/if_ether.h> 4062306a36Sopenharmony_ci#include <linux/pci.h> 4162306a36Sopenharmony_ci#include <linux/in.h> 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#include "usnic_abi.h" 4462306a36Sopenharmony_ci#include "usnic_common_pkt_hdr.h" 4562306a36Sopenharmony_ci#include "vnic_devcmd.h" 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_cistruct usnic_fwd_dev { 4862306a36Sopenharmony_ci struct pci_dev *pdev; 4962306a36Sopenharmony_ci struct net_device *netdev; 5062306a36Sopenharmony_ci spinlock_t lock; 5162306a36Sopenharmony_ci /* 5262306a36Sopenharmony_ci * The following fields can be read directly off the device. 5362306a36Sopenharmony_ci * However, they should be set by a accessor function, except name, 5462306a36Sopenharmony_ci * which cannot be changed. 5562306a36Sopenharmony_ci */ 5662306a36Sopenharmony_ci bool link_up; 5762306a36Sopenharmony_ci char mac[ETH_ALEN]; 5862306a36Sopenharmony_ci unsigned int mtu; 5962306a36Sopenharmony_ci __be32 inaddr; 6062306a36Sopenharmony_ci char name[IFNAMSIZ]; 6162306a36Sopenharmony_ci}; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistruct usnic_fwd_flow { 6462306a36Sopenharmony_ci uint32_t flow_id; 6562306a36Sopenharmony_ci struct usnic_fwd_dev *ufdev; 6662306a36Sopenharmony_ci unsigned int vnic_idx; 6762306a36Sopenharmony_ci}; 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistruct usnic_filter_action { 7062306a36Sopenharmony_ci int vnic_idx; 7162306a36Sopenharmony_ci struct filter_action action; 7262306a36Sopenharmony_ci}; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_cistruct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev); 7562306a36Sopenharmony_civoid usnic_fwd_dev_free(struct usnic_fwd_dev *ufdev); 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_civoid usnic_fwd_set_mac(struct usnic_fwd_dev *ufdev, const char mac[ETH_ALEN]); 7862306a36Sopenharmony_civoid usnic_fwd_add_ipaddr(struct usnic_fwd_dev *ufdev, __be32 inaddr); 7962306a36Sopenharmony_civoid usnic_fwd_del_ipaddr(struct usnic_fwd_dev *ufdev); 8062306a36Sopenharmony_civoid usnic_fwd_carrier_up(struct usnic_fwd_dev *ufdev); 8162306a36Sopenharmony_civoid usnic_fwd_carrier_down(struct usnic_fwd_dev *ufdev); 8262306a36Sopenharmony_civoid usnic_fwd_set_mtu(struct usnic_fwd_dev *ufdev, unsigned int mtu); 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci/* 8562306a36Sopenharmony_ci * Allocate a flow on this forwarding device. Whoever calls this function, 8662306a36Sopenharmony_ci * must monitor netdev events on ufdev's netdevice. If NETDEV_REBOOT or 8762306a36Sopenharmony_ci * NETDEV_DOWN is seen, flow will no longer function and must be 8862306a36Sopenharmony_ci * immediately freed by calling usnic_dealloc_flow. 8962306a36Sopenharmony_ci */ 9062306a36Sopenharmony_cistruct usnic_fwd_flow* 9162306a36Sopenharmony_ciusnic_fwd_alloc_flow(struct usnic_fwd_dev *ufdev, struct filter *filter, 9262306a36Sopenharmony_ci struct usnic_filter_action *action); 9362306a36Sopenharmony_ciint usnic_fwd_dealloc_flow(struct usnic_fwd_flow *flow); 9462306a36Sopenharmony_ciint usnic_fwd_enable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx); 9562306a36Sopenharmony_ciint usnic_fwd_disable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx); 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_cistatic inline void usnic_fwd_init_usnic_filter(struct filter *filter, 9862306a36Sopenharmony_ci uint32_t usnic_id) 9962306a36Sopenharmony_ci{ 10062306a36Sopenharmony_ci filter->type = FILTER_USNIC_ID; 10162306a36Sopenharmony_ci filter->u.usnic.ethtype = ETH_P_IBOE; 10262306a36Sopenharmony_ci filter->u.usnic.flags = FILTER_FIELD_USNIC_ETHTYPE | 10362306a36Sopenharmony_ci FILTER_FIELD_USNIC_ID | 10462306a36Sopenharmony_ci FILTER_FIELD_USNIC_PROTO; 10562306a36Sopenharmony_ci filter->u.usnic.proto_version = (USNIC_ROCE_GRH_VER << 10662306a36Sopenharmony_ci USNIC_ROCE_GRH_VER_SHIFT) | 10762306a36Sopenharmony_ci USNIC_PROTO_VER; 10862306a36Sopenharmony_ci filter->u.usnic.usnic_id = usnic_id; 10962306a36Sopenharmony_ci} 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_cistatic inline void usnic_fwd_init_udp_filter(struct filter *filter, 11262306a36Sopenharmony_ci uint32_t daddr, uint16_t dport) 11362306a36Sopenharmony_ci{ 11462306a36Sopenharmony_ci filter->type = FILTER_IPV4_5TUPLE; 11562306a36Sopenharmony_ci filter->u.ipv4.flags = FILTER_FIELD_5TUP_PROTO; 11662306a36Sopenharmony_ci filter->u.ipv4.protocol = PROTO_UDP; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci if (daddr) { 11962306a36Sopenharmony_ci filter->u.ipv4.flags |= FILTER_FIELD_5TUP_DST_AD; 12062306a36Sopenharmony_ci filter->u.ipv4.dst_addr = daddr; 12162306a36Sopenharmony_ci } 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci if (dport) { 12462306a36Sopenharmony_ci filter->u.ipv4.flags |= FILTER_FIELD_5TUP_DST_PT; 12562306a36Sopenharmony_ci filter->u.ipv4.dst_port = dport; 12662306a36Sopenharmony_ci } 12762306a36Sopenharmony_ci} 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci#endif /* !USNIC_FWD_H_ */ 130