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