This source file includes following definitions.
- t4_init_smt
- find_or_alloc_smte
- t4_smte_free
- cxgb4_smt_release
- do_smt_write_rpl
- write_smt_entry
- t4_smt_alloc_switching
- cxgb4_smt_alloc_switching
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include "cxgb4.h"
36 #include "smt.h"
37 #include "t4_msg.h"
38 #include "t4fw_api.h"
39 #include "t4_regs.h"
40 #include "t4_values.h"
41
42 struct smt_data *t4_init_smt(void)
43 {
44 unsigned int smt_size;
45 struct smt_data *s;
46 int i;
47
48 smt_size = SMT_SIZE;
49
50 s = kvzalloc(struct_size(s, smtab, smt_size), GFP_KERNEL);
51 if (!s)
52 return NULL;
53 s->smt_size = smt_size;
54 rwlock_init(&s->lock);
55 for (i = 0; i < s->smt_size; ++i) {
56 s->smtab[i].idx = i;
57 s->smtab[i].state = SMT_STATE_UNUSED;
58 memset(&s->smtab[i].src_mac, 0, ETH_ALEN);
59 spin_lock_init(&s->smtab[i].lock);
60 s->smtab[i].refcnt = 0;
61 }
62 return s;
63 }
64
65 static struct smt_entry *find_or_alloc_smte(struct smt_data *s, u8 *smac)
66 {
67 struct smt_entry *first_free = NULL;
68 struct smt_entry *e, *end;
69
70 for (e = &s->smtab[0], end = &s->smtab[s->smt_size]; e != end; ++e) {
71 if (e->refcnt == 0) {
72 if (!first_free)
73 first_free = e;
74 } else {
75 if (e->state == SMT_STATE_SWITCHING) {
76
77
78
79 if (memcmp(e->src_mac, smac, ETH_ALEN) == 0)
80 goto found_reuse;
81 }
82 }
83 }
84
85 if (first_free) {
86 e = first_free;
87 goto found;
88 }
89 return NULL;
90
91 found:
92 e->state = SMT_STATE_UNUSED;
93
94 found_reuse:
95 return e;
96 }
97
98 static void t4_smte_free(struct smt_entry *e)
99 {
100 if (e->refcnt == 0) {
101 e->state = SMT_STATE_UNUSED;
102 }
103 }
104
105
106
107
108
109
110 void cxgb4_smt_release(struct smt_entry *e)
111 {
112 spin_lock_bh(&e->lock);
113 if ((--e->refcnt) == 0)
114 t4_smte_free(e);
115 spin_unlock_bh(&e->lock);
116 }
117 EXPORT_SYMBOL(cxgb4_smt_release);
118
119 void do_smt_write_rpl(struct adapter *adap, const struct cpl_smt_write_rpl *rpl)
120 {
121 unsigned int smtidx = TID_TID_G(GET_TID(rpl));
122 struct smt_data *s = adap->smt;
123
124 if (unlikely(rpl->status != CPL_ERR_NONE)) {
125 struct smt_entry *e = &s->smtab[smtidx];
126
127 dev_err(adap->pdev_dev,
128 "Unexpected SMT_WRITE_RPL status %u for entry %u\n",
129 rpl->status, smtidx);
130 spin_lock(&e->lock);
131 e->state = SMT_STATE_ERROR;
132 spin_unlock(&e->lock);
133 return;
134 }
135 }
136
137 static int write_smt_entry(struct adapter *adapter, struct smt_entry *e)
138 {
139 struct cpl_t6_smt_write_req *t6req;
140 struct smt_data *s = adapter->smt;
141 struct cpl_smt_write_req *req;
142 struct sk_buff *skb;
143 int size;
144 u8 row;
145
146 if (CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) {
147 size = sizeof(*req);
148 skb = alloc_skb(size, GFP_ATOMIC);
149 if (!skb)
150 return -ENOMEM;
151
152
153
154 req = (struct cpl_smt_write_req *)__skb_put(skb, size);
155 INIT_TP_WR(req, 0);
156
157
158
159
160 row = (e->idx >> 1);
161 if (e->idx & 1) {
162 req->pfvf1 = 0x0;
163 memcpy(req->src_mac1, e->src_mac, ETH_ALEN);
164
165
166
167
168 req->pfvf0 = 0x0;
169 memcpy(req->src_mac0, s->smtab[e->idx - 1].src_mac,
170 ETH_ALEN);
171 } else {
172 req->pfvf0 = 0x0;
173 memcpy(req->src_mac0, e->src_mac, ETH_ALEN);
174
175
176
177
178 req->pfvf1 = 0x0;
179 memcpy(req->src_mac1, s->smtab[e->idx + 1].src_mac,
180 ETH_ALEN);
181 }
182 } else {
183 size = sizeof(*t6req);
184 skb = alloc_skb(size, GFP_ATOMIC);
185 if (!skb)
186 return -ENOMEM;
187
188 t6req = (struct cpl_t6_smt_write_req *)__skb_put(skb, size);
189 INIT_TP_WR(t6req, 0);
190 req = (struct cpl_smt_write_req *)t6req;
191
192
193 req->pfvf0 = 0x0;
194 memcpy(req->src_mac0, s->smtab[e->idx].src_mac, ETH_ALEN);
195 row = e->idx;
196 }
197
198 OPCODE_TID(req) =
199 htonl(MK_OPCODE_TID(CPL_SMT_WRITE_REQ, e->idx |
200 TID_QID_V(adapter->sge.fw_evtq.abs_id)));
201 req->params = htonl(SMTW_NORPL_V(0) |
202 SMTW_IDX_V(row) |
203 SMTW_OVLAN_IDX_V(0));
204 t4_mgmt_tx(adapter, skb);
205 return 0;
206 }
207
208 static struct smt_entry *t4_smt_alloc_switching(struct adapter *adap, u16 pfvf,
209 u8 *smac)
210 {
211 struct smt_data *s = adap->smt;
212 struct smt_entry *e;
213
214 write_lock_bh(&s->lock);
215 e = find_or_alloc_smte(s, smac);
216 if (e) {
217 spin_lock(&e->lock);
218 if (!e->refcnt) {
219 e->refcnt = 1;
220 e->state = SMT_STATE_SWITCHING;
221 e->pfvf = pfvf;
222 memcpy(e->src_mac, smac, ETH_ALEN);
223 write_smt_entry(adap, e);
224 } else {
225 ++e->refcnt;
226 }
227 spin_unlock(&e->lock);
228 }
229 write_unlock_bh(&s->lock);
230 return e;
231 }
232
233
234
235
236
237
238
239
240 struct smt_entry *cxgb4_smt_alloc_switching(struct net_device *dev, u8 *smac)
241 {
242 struct adapter *adap = netdev2adap(dev);
243
244 return t4_smt_alloc_switching(adap, 0x0, smac);
245 }
246 EXPORT_SYMBOL(cxgb4_smt_alloc_switching);