cxgb_l2t.h revision 1.1 1 1.1 jklos /**************************************************************************
2 1.1 jklos
3 1.1 jklos Copyright (c) 2007, Chelsio Inc.
4 1.1 jklos All rights reserved.
5 1.1 jklos
6 1.1 jklos Redistribution and use in source and binary forms, with or without
7 1.1 jklos modification, are permitted provided that the following conditions are met:
8 1.1 jklos
9 1.1 jklos 1. Redistributions of source code must retain the above copyright notice,
10 1.1 jklos this list of conditions and the following disclaimer.
11 1.1 jklos
12 1.1 jklos 2. Neither the name of the Chelsio Corporation nor the names of its
13 1.1 jklos contributors may be used to endorse or promote products derived from
14 1.1 jklos this software without specific prior written permission.
15 1.1 jklos
16 1.1 jklos THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 1.1 jklos AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 1.1 jklos IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 1.1 jklos ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 1.1 jklos LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 jklos CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 jklos SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 jklos INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 jklos CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.1 jklos ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 jklos POSSIBILITY OF SUCH DAMAGE.
27 1.1 jklos
28 1.1 jklos ***************************************************************************/
29 1.1 jklos #ifndef _CHELSIO_L2T_H
30 1.1 jklos #define _CHELSIO_L2T_H
31 1.1 jklos
32 1.1 jklos #include <sys/lock.h>
33 1.1 jklos
34 1.1 jklos #define rwlock mtx
35 1.1 jklos #define rw_wlock(x) mtx_lock((x))
36 1.1 jklos #define rw_wunlock(x) mtx_unlock((x))
37 1.1 jklos #define rw_rlock(x) mtx_lock((x))
38 1.1 jklos #define rw_runlock(x) mtx_unlock((x))
39 1.1 jklos #define rw_init(x, str) mtx_init((x), (str), NULL, MTX_DEF)
40 1.1 jklos #define rw_destroy(x) mtx_destroy((x))
41 1.1 jklos
42 1.1 jklos enum {
43 1.1 jklos L2T_STATE_VALID, /* entry is up to date */
44 1.1 jklos L2T_STATE_STALE, /* entry may be used but needs revalidation */
45 1.1 jklos L2T_STATE_RESOLVING, /* entry needs address resolution */
46 1.1 jklos L2T_STATE_UNUSED /* entry not in use */
47 1.1 jklos };
48 1.1 jklos
49 1.1 jklos /*
50 1.1 jklos * Each L2T entry plays multiple roles. First of all, it keeps state for the
51 1.1 jklos * corresponding entry of the HW L2 table and maintains a queue of offload
52 1.1 jklos * packets awaiting address resolution. Second, it is a node of a hash table
53 1.1 jklos * chain, where the nodes of the chain are linked together through their next
54 1.1 jklos * pointer. Finally, each node is a bucket of a hash table, pointing to the
55 1.1 jklos * first element in its chain through its first pointer.
56 1.1 jklos */
57 1.1 jklos struct l2t_entry {
58 1.1 jklos uint16_t state; /* entry state */
59 1.1 jklos uint16_t idx; /* entry index */
60 1.1 jklos uint32_t addr; /* dest IP address */
61 1.1 jklos int ifindex; /* neighbor's net_device's ifindex */
62 1.1 jklos uint16_t smt_idx; /* SMT index */
63 1.1 jklos uint16_t vlan; /* VLAN TCI (id: bits 0-11, prio: 13-15 */
64 1.1 jklos struct rtentry *neigh; /* associated neighbour */
65 1.1 jklos struct l2t_entry *first; /* start of hash chain */
66 1.1 jklos struct l2t_entry *next; /* next l2t_entry on chain */
67 1.1 jklos struct mbuf *arpq_head; /* queue of packets awaiting resolution */
68 1.1 jklos struct mbuf *arpq_tail;
69 1.1 jklos struct mtx lock;
70 1.1 jklos volatile uint32_t refcnt; /* entry reference count */
71 1.1 jklos uint8_t dmac[6]; /* neighbour's MAC address */
72 1.1 jklos #ifndef NETEVENT
73 1.1 jklos #ifdef CONFIG_CHELSIO_T3_MODULE
74 1.1 jklos struct timer_list update_timer;
75 1.1 jklos #endif
76 1.1 jklos #endif
77 1.1 jklos };
78 1.1 jklos
79 1.1 jklos struct l2t_data {
80 1.1 jklos unsigned int nentries; /* number of entries */
81 1.1 jklos struct l2t_entry *rover; /* starting point for next allocation */
82 1.1 jklos volatile uint32_t nfree; /* number of free entries */
83 1.1 jklos struct rwlock lock;
84 1.1 jklos struct l2t_entry l2tab[0];
85 1.1 jklos };
86 1.1 jklos
87 1.1 jklos typedef void (*arp_failure_handler_func)(struct toedev *dev,
88 1.1 jklos struct mbuf *m);
89 1.1 jklos
90 1.1 jklos /*
91 1.1 jklos * Callback stored in an skb to handle address resolution failure.
92 1.1 jklos */
93 1.1 jklos struct l2t_mbuf_cb {
94 1.1 jklos arp_failure_handler_func arp_failure_handler;
95 1.1 jklos };
96 1.1 jklos
97 1.1 jklos /*
98 1.1 jklos * XXX
99 1.1 jklos */
100 1.1 jklos #define L2T_MBUF_CB(skb) ((struct l2t_mbuf_cb *)(skb)->cb)
101 1.1 jklos
102 1.1 jklos
103 1.1 jklos static __inline void set_arp_failure_handler(struct mbuf *m,
104 1.1 jklos arp_failure_handler_func hnd)
105 1.1 jklos {
106 1.1 jklos #if 0
107 1.1 jklos L2T_SKB_CB(skb)->arp_failure_handler = hnd;
108 1.1 jklos #endif
109 1.1 jklos panic("implement me");
110 1.1 jklos }
111 1.1 jklos
112 1.1 jklos /*
113 1.1 jklos * Getting to the L2 data from an offload device.
114 1.1 jklos */
115 1.1 jklos #define L2DATA(dev) ((dev)->l2opt)
116 1.1 jklos
117 1.1 jklos void t3_l2e_free(struct l2t_data *d, struct l2t_entry *e);
118 1.1 jklos void t3_l2t_update(struct toedev *dev, struct rtentry *ifp);
119 1.1 jklos struct l2t_entry *t3_l2t_get(struct toedev *dev, struct rtentry *neigh,
120 1.1 jklos unsigned int smt_idx);
121 1.1 jklos int t3_l2t_send_slow(struct toedev *dev, struct mbuf *m,
122 1.1 jklos struct l2t_entry *e);
123 1.1 jklos void t3_l2t_send_event(struct toedev *dev, struct l2t_entry *e);
124 1.1 jklos struct l2t_data *t3_init_l2t(unsigned int l2t_capacity);
125 1.1 jklos void t3_free_l2t(struct l2t_data *d);
126 1.1 jklos
127 1.1 jklos #ifdef CONFIG_PROC_FS
128 1.1 jklos int t3_l2t_proc_setup(struct proc_dir_entry *dir, struct l2t_data *d);
129 1.1 jklos void t3_l2t_proc_free(struct proc_dir_entry *dir);
130 1.1 jklos #else
131 1.1 jklos #define l2t_proc_setup(dir, d) 0
132 1.1 jklos #define l2t_proc_free(dir)
133 1.1 jklos #endif
134 1.1 jklos
135 1.1 jklos int cxgb_ofld_send(struct toedev *dev, struct mbuf *m);
136 1.1 jklos
137 1.1 jklos static inline int l2t_send(struct toedev *dev, struct mbuf *m,
138 1.1 jklos struct l2t_entry *e)
139 1.1 jklos {
140 1.1 jklos if (__predict_true(e->state == L2T_STATE_VALID))
141 1.1 jklos return cxgb_ofld_send(dev, m);
142 1.1 jklos return t3_l2t_send_slow(dev, m, e);
143 1.1 jklos }
144 1.1 jklos
145 1.1 jklos static inline void l2t_release(struct l2t_data *d, struct l2t_entry *e)
146 1.1 jklos {
147 1.1 jklos if (atomic_fetchadd_int(&e->refcnt, -1) == 1)
148 1.1 jklos t3_l2e_free(d, e);
149 1.1 jklos }
150 1.1 jklos
151 1.1 jklos static inline void l2t_hold(struct l2t_data *d, struct l2t_entry *e)
152 1.1 jklos {
153 1.1 jklos if (atomic_fetchadd_int(&e->refcnt, 1) == 1) /* 0 -> 1 transition */
154 1.1 jklos atomic_add_int(&d->nfree, 1);
155 1.1 jklos }
156 1.1 jklos
157 1.1 jklos #endif
158