1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * This file is part of the Chelsio T4 Ethernet driver for Linux.
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * This software is available to you under a choice of one of two
7*4882a593Smuzhiyun * licenses. You may choose to be licensed under the terms of the GNU
8*4882a593Smuzhiyun * General Public License (GPL) Version 2, available from the file
9*4882a593Smuzhiyun * COPYING in the main directory of this source tree, or the
10*4882a593Smuzhiyun * OpenIB.org BSD license below:
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or
13*4882a593Smuzhiyun * without modification, are permitted provided that the following
14*4882a593Smuzhiyun * conditions are met:
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * - Redistributions of source code must retain the above
17*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
18*4882a593Smuzhiyun * disclaimer.
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * - Redistributions in binary form must reproduce the above
21*4882a593Smuzhiyun * copyright notice, this list of conditions and the following
22*4882a593Smuzhiyun * disclaimer in the documentation and/or other materials
23*4882a593Smuzhiyun * provided with the distribution.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26*4882a593Smuzhiyun * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27*4882a593Smuzhiyun * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28*4882a593Smuzhiyun * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29*4882a593Smuzhiyun * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30*4882a593Smuzhiyun * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31*4882a593Smuzhiyun * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32*4882a593Smuzhiyun * SOFTWARE.
33*4882a593Smuzhiyun */
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun #ifndef __CXGB4_L2T_H
36*4882a593Smuzhiyun #define __CXGB4_L2T_H
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun #include <linux/spinlock.h>
39*4882a593Smuzhiyun #include <linux/if_ether.h>
40*4882a593Smuzhiyun #include <linux/atomic.h>
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun #define VLAN_NONE 0xfff
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun enum { L2T_SIZE = 4096 }; /* # of L2T entries */
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun enum {
47*4882a593Smuzhiyun L2T_STATE_VALID, /* entry is up to date */
48*4882a593Smuzhiyun L2T_STATE_STALE, /* entry may be used but needs revalidation */
49*4882a593Smuzhiyun L2T_STATE_RESOLVING, /* entry needs address resolution */
50*4882a593Smuzhiyun L2T_STATE_SYNC_WRITE, /* synchronous write of entry underway */
51*4882a593Smuzhiyun L2T_STATE_NOARP, /* Netdev down or removed*/
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /* when state is one of the below the entry is not hashed */
54*4882a593Smuzhiyun L2T_STATE_SWITCHING, /* entry is being used by a switching filter */
55*4882a593Smuzhiyun L2T_STATE_UNUSED /* entry not in use */
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun struct adapter;
59*4882a593Smuzhiyun struct l2t_data;
60*4882a593Smuzhiyun struct neighbour;
61*4882a593Smuzhiyun struct net_device;
62*4882a593Smuzhiyun struct file_operations;
63*4882a593Smuzhiyun struct cpl_l2t_write_rpl;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /*
66*4882a593Smuzhiyun * Each L2T entry plays multiple roles. First of all, it keeps state for the
67*4882a593Smuzhiyun * corresponding entry of the HW L2 table and maintains a queue of offload
68*4882a593Smuzhiyun * packets awaiting address resolution. Second, it is a node of a hash table
69*4882a593Smuzhiyun * chain, where the nodes of the chain are linked together through their next
70*4882a593Smuzhiyun * pointer. Finally, each node is a bucket of a hash table, pointing to the
71*4882a593Smuzhiyun * first element in its chain through its first pointer.
72*4882a593Smuzhiyun */
73*4882a593Smuzhiyun struct l2t_entry {
74*4882a593Smuzhiyun u16 state; /* entry state */
75*4882a593Smuzhiyun u16 idx; /* entry index within in-memory table */
76*4882a593Smuzhiyun u32 addr[4]; /* next hop IP or IPv6 address */
77*4882a593Smuzhiyun int ifindex; /* neighbor's net_device's ifindex */
78*4882a593Smuzhiyun struct neighbour *neigh; /* associated neighbour */
79*4882a593Smuzhiyun struct l2t_entry *first; /* start of hash chain */
80*4882a593Smuzhiyun struct l2t_entry *next; /* next l2t_entry on chain */
81*4882a593Smuzhiyun struct sk_buff_head arpq; /* packet queue awaiting resolution */
82*4882a593Smuzhiyun spinlock_t lock;
83*4882a593Smuzhiyun atomic_t refcnt; /* entry reference count */
84*4882a593Smuzhiyun u16 hash; /* hash bucket the entry is on */
85*4882a593Smuzhiyun u16 vlan; /* VLAN TCI (id: bits 0-11, prio: 13-15 */
86*4882a593Smuzhiyun u8 v6; /* whether entry is for IPv6 */
87*4882a593Smuzhiyun u8 lport; /* associated offload logical interface */
88*4882a593Smuzhiyun u8 dmac[ETH_ALEN]; /* neighbour's MAC address */
89*4882a593Smuzhiyun };
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun typedef void (*arp_err_handler_t)(void *handle, struct sk_buff *skb);
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /*
94*4882a593Smuzhiyun * Callback stored in an skb to handle address resolution failure.
95*4882a593Smuzhiyun */
96*4882a593Smuzhiyun struct l2t_skb_cb {
97*4882a593Smuzhiyun void *handle;
98*4882a593Smuzhiyun arp_err_handler_t arp_err_handler;
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
102*4882a593Smuzhiyun
t4_set_arp_err_handler(struct sk_buff * skb,void * handle,arp_err_handler_t handler)103*4882a593Smuzhiyun static inline void t4_set_arp_err_handler(struct sk_buff *skb, void *handle,
104*4882a593Smuzhiyun arp_err_handler_t handler)
105*4882a593Smuzhiyun {
106*4882a593Smuzhiyun L2T_SKB_CB(skb)->handle = handle;
107*4882a593Smuzhiyun L2T_SKB_CB(skb)->arp_err_handler = handler;
108*4882a593Smuzhiyun }
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun void cxgb4_l2t_release(struct l2t_entry *e);
111*4882a593Smuzhiyun int cxgb4_l2t_send(struct net_device *dev, struct sk_buff *skb,
112*4882a593Smuzhiyun struct l2t_entry *e);
113*4882a593Smuzhiyun struct l2t_entry *cxgb4_l2t_get(struct l2t_data *d, struct neighbour *neigh,
114*4882a593Smuzhiyun const struct net_device *physdev,
115*4882a593Smuzhiyun unsigned int priority);
116*4882a593Smuzhiyun u64 cxgb4_select_ntuple(struct net_device *dev,
117*4882a593Smuzhiyun const struct l2t_entry *l2t);
118*4882a593Smuzhiyun struct l2t_entry *cxgb4_l2t_alloc_switching(struct net_device *dev, u16 vlan,
119*4882a593Smuzhiyun u8 port, u8 *dmac);
120*4882a593Smuzhiyun void t4_l2t_update(struct adapter *adap, struct neighbour *neigh);
121*4882a593Smuzhiyun struct l2t_entry *t4_l2t_alloc_switching(struct adapter *adap, u16 vlan,
122*4882a593Smuzhiyun u8 port, u8 *dmac);
123*4882a593Smuzhiyun struct l2t_data *t4_init_l2t(unsigned int l2t_start, unsigned int l2t_end);
124*4882a593Smuzhiyun void do_l2t_write_rpl(struct adapter *p, const struct cpl_l2t_write_rpl *rpl);
125*4882a593Smuzhiyun bool cxgb4_check_l2t_valid(struct l2t_entry *e);
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun extern const struct file_operations t4_l2t_fops;
128*4882a593Smuzhiyun #endif /* __CXGB4_L2T_H */
129