Commit | Line | Data |
---|---|---|
4d22de3e | 1 | /* |
1d68e93d | 2 | * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. |
4d22de3e DLR |
3 | * |
4 | * This software is available to you under a choice of one of two | |
5 | * licenses. You may choose to be licensed under the terms of the GNU | |
6 | * General Public License (GPL) Version 2, available from the file | |
7 | * COPYING in the main directory of this source tree, or the | |
8 | * OpenIB.org BSD license below: | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or | |
11 | * without modification, are permitted provided that the following | |
12 | * conditions are met: | |
13 | * | |
14 | * - Redistributions of source code must retain the above | |
15 | * copyright notice, this list of conditions and the following | |
16 | * disclaimer. | |
17 | * | |
18 | * - Redistributions in binary form must reproduce the above | |
19 | * copyright notice, this list of conditions and the following | |
20 | * disclaimer in the documentation and/or other materials | |
21 | * provided with the distribution. | |
22 | * | |
23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | |
27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | |
28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
30 | * SOFTWARE. | |
31 | */ | |
32 | ||
33 | #include <linux/list.h> | |
34 | #include <net/neighbour.h> | |
35 | #include <linux/notifier.h> | |
36 | #include <asm/atomic.h> | |
37 | #include <linux/proc_fs.h> | |
38 | #include <linux/if_vlan.h> | |
39 | #include <net/netevent.h> | |
40 | #include <linux/highmem.h> | |
41 | #include <linux/vmalloc.h> | |
42 | ||
43 | #include "common.h" | |
44 | #include "regs.h" | |
45 | #include "cxgb3_ioctl.h" | |
46 | #include "cxgb3_ctl_defs.h" | |
47 | #include "cxgb3_defs.h" | |
48 | #include "l2t.h" | |
49 | #include "firmware_exports.h" | |
50 | #include "cxgb3_offload.h" | |
51 | ||
52 | static LIST_HEAD(client_list); | |
53 | static LIST_HEAD(ofld_dev_list); | |
54 | static DEFINE_MUTEX(cxgb3_db_lock); | |
55 | ||
56 | static DEFINE_RWLOCK(adapter_list_lock); | |
57 | static LIST_HEAD(adapter_list); | |
58 | ||
59 | static const unsigned int MAX_ATIDS = 64 * 1024; | |
c9a6ce50 | 60 | static const unsigned int ATID_BASE = 0x10000; |
4d22de3e DLR |
61 | |
62 | static inline int offload_activated(struct t3cdev *tdev) | |
63 | { | |
64 | const struct adapter *adapter = tdev2adap(tdev); | |
65 | ||
66 | return (test_bit(OFFLOAD_DEVMAP_BIT, &adapter->open_device_map)); | |
67 | } | |
68 | ||
69 | /** | |
70 | * cxgb3_register_client - register an offload client | |
71 | * @client: the client | |
72 | * | |
73 | * Add the client to the client list, | |
74 | * and call backs the client for each activated offload device | |
75 | */ | |
76 | void cxgb3_register_client(struct cxgb3_client *client) | |
77 | { | |
78 | struct t3cdev *tdev; | |
79 | ||
80 | mutex_lock(&cxgb3_db_lock); | |
81 | list_add_tail(&client->client_list, &client_list); | |
82 | ||
83 | if (client->add) { | |
84 | list_for_each_entry(tdev, &ofld_dev_list, ofld_dev_list) { | |
85 | if (offload_activated(tdev)) | |
86 | client->add(tdev); | |
87 | } | |
88 | } | |
89 | mutex_unlock(&cxgb3_db_lock); | |
90 | } | |
91 | ||
92 | EXPORT_SYMBOL(cxgb3_register_client); | |
93 | ||
94 | /** | |
95 | * cxgb3_unregister_client - unregister an offload client | |
96 | * @client: the client | |
97 | * | |
98 | * Remove the client to the client list, | |
99 | * and call backs the client for each activated offload device. | |
100 | */ | |
101 | void cxgb3_unregister_client(struct cxgb3_client *client) | |
102 | { | |
103 | struct t3cdev *tdev; | |
104 | ||
105 | mutex_lock(&cxgb3_db_lock); | |
106 | list_del(&client->client_list); | |
107 | ||
108 | if (client->remove) { | |
109 | list_for_each_entry(tdev, &ofld_dev_list, ofld_dev_list) { | |
110 | if (offload_activated(tdev)) | |
111 | client->remove(tdev); | |
112 | } | |
113 | } | |
114 | mutex_unlock(&cxgb3_db_lock); | |
115 | } | |
116 | ||
117 | EXPORT_SYMBOL(cxgb3_unregister_client); | |
118 | ||
119 | /** | |
120 | * cxgb3_add_clients - activate registered clients for an offload device | |
121 | * @tdev: the offload device | |
122 | * | |
123 | * Call backs all registered clients once a offload device is activated | |
124 | */ | |
125 | void cxgb3_add_clients(struct t3cdev *tdev) | |
126 | { | |
127 | struct cxgb3_client *client; | |
128 | ||
129 | mutex_lock(&cxgb3_db_lock); | |
130 | list_for_each_entry(client, &client_list, client_list) { | |
131 | if (client->add) | |
132 | client->add(tdev); | |
133 | } | |
134 | mutex_unlock(&cxgb3_db_lock); | |
135 | } | |
136 | ||
137 | /** | |
138 | * cxgb3_remove_clients - deactivates registered clients | |
139 | * for an offload device | |
140 | * @tdev: the offload device | |
141 | * | |
142 | * Call backs all registered clients once a offload device is deactivated | |
143 | */ | |
144 | void cxgb3_remove_clients(struct t3cdev *tdev) | |
145 | { | |
146 | struct cxgb3_client *client; | |
147 | ||
148 | mutex_lock(&cxgb3_db_lock); | |
149 | list_for_each_entry(client, &client_list, client_list) { | |
150 | if (client->remove) | |
151 | client->remove(tdev); | |
152 | } | |
153 | mutex_unlock(&cxgb3_db_lock); | |
154 | } | |
155 | ||
156 | static struct net_device *get_iff_from_mac(struct adapter *adapter, | |
157 | const unsigned char *mac, | |
158 | unsigned int vlan) | |
159 | { | |
160 | int i; | |
161 | ||
162 | for_each_port(adapter, i) { | |
5c15bdec | 163 | struct vlan_group *grp; |
4d22de3e DLR |
164 | struct net_device *dev = adapter->port[i]; |
165 | const struct port_info *p = netdev_priv(dev); | |
166 | ||
167 | if (!memcmp(dev->dev_addr, mac, ETH_ALEN)) { | |
168 | if (vlan && vlan != VLAN_VID_MASK) { | |
169 | grp = p->vlan_grp; | |
5c15bdec DA |
170 | dev = NULL; |
171 | if (grp) | |
172 | dev = vlan_group_get_device(grp, vlan); | |
4d22de3e DLR |
173 | } else |
174 | while (dev->master) | |
175 | dev = dev->master; | |
176 | return dev; | |
177 | } | |
178 | } | |
179 | return NULL; | |
180 | } | |
181 | ||
182 | static int cxgb_ulp_iscsi_ctl(struct adapter *adapter, unsigned int req, | |
183 | void *data) | |
184 | { | |
185 | int ret = 0; | |
186 | struct ulp_iscsi_info *uiip = data; | |
187 | ||
188 | switch (req) { | |
189 | case ULP_ISCSI_GET_PARAMS: | |
190 | uiip->pdev = adapter->pdev; | |
191 | uiip->llimit = t3_read_reg(adapter, A_ULPRX_ISCSI_LLIMIT); | |
192 | uiip->ulimit = t3_read_reg(adapter, A_ULPRX_ISCSI_ULIMIT); | |
193 | uiip->tagmask = t3_read_reg(adapter, A_ULPRX_ISCSI_TAGMASK); | |
194 | /* | |
195 | * On tx, the iscsi pdu has to be <= tx page size and has to | |
196 | * fit into the Tx PM FIFO. | |
197 | */ | |
198 | uiip->max_txsz = min(adapter->params.tp.tx_pg_size, | |
199 | t3_read_reg(adapter, A_PM1_TX_CFG) >> 17); | |
200 | /* on rx, the iscsi pdu has to be < rx page size and the | |
201 | whole pdu + cpl headers has to fit into one sge buffer */ | |
202 | uiip->max_rxsz = min_t(unsigned int, | |
203 | adapter->params.tp.rx_pg_size, | |
204 | (adapter->sge.qs[0].fl[1].buf_size - | |
205 | sizeof(struct cpl_rx_data) * 2 - | |
206 | sizeof(struct cpl_rx_data_ddp))); | |
207 | break; | |
208 | case ULP_ISCSI_SET_PARAMS: | |
209 | t3_write_reg(adapter, A_ULPRX_ISCSI_TAGMASK, uiip->tagmask); | |
210 | break; | |
211 | default: | |
212 | ret = -EOPNOTSUPP; | |
213 | } | |
214 | return ret; | |
215 | } | |
216 | ||
217 | /* Response queue used for RDMA events. */ | |
218 | #define ASYNC_NOTIF_RSPQ 0 | |
219 | ||
220 | static int cxgb_rdma_ctl(struct adapter *adapter, unsigned int req, void *data) | |
221 | { | |
222 | int ret = 0; | |
223 | ||
224 | switch (req) { | |
9265fabf SH |
225 | case RDMA_GET_PARAMS: { |
226 | struct rdma_info *rdma = data; | |
4d22de3e DLR |
227 | struct pci_dev *pdev = adapter->pdev; |
228 | ||
9265fabf SH |
229 | rdma->udbell_physbase = pci_resource_start(pdev, 2); |
230 | rdma->udbell_len = pci_resource_len(pdev, 2); | |
231 | rdma->tpt_base = | |
4d22de3e | 232 | t3_read_reg(adapter, A_ULPTX_TPT_LLIMIT); |
9265fabf SH |
233 | rdma->tpt_top = t3_read_reg(adapter, A_ULPTX_TPT_ULIMIT); |
234 | rdma->pbl_base = | |
4d22de3e | 235 | t3_read_reg(adapter, A_ULPTX_PBL_LLIMIT); |
9265fabf SH |
236 | rdma->pbl_top = t3_read_reg(adapter, A_ULPTX_PBL_ULIMIT); |
237 | rdma->rqt_base = t3_read_reg(adapter, A_ULPRX_RQ_LLIMIT); | |
238 | rdma->rqt_top = t3_read_reg(adapter, A_ULPRX_RQ_ULIMIT); | |
239 | rdma->kdb_addr = adapter->regs + A_SG_KDOORBELL; | |
240 | rdma->pdev = pdev; | |
4d22de3e DLR |
241 | break; |
242 | } | |
243 | case RDMA_CQ_OP:{ | |
244 | unsigned long flags; | |
9265fabf | 245 | struct rdma_cq_op *rdma = data; |
4d22de3e DLR |
246 | |
247 | /* may be called in any context */ | |
248 | spin_lock_irqsave(&adapter->sge.reg_lock, flags); | |
9265fabf SH |
249 | ret = t3_sge_cqcntxt_op(adapter, rdma->id, rdma->op, |
250 | rdma->credits); | |
4d22de3e DLR |
251 | spin_unlock_irqrestore(&adapter->sge.reg_lock, flags); |
252 | break; | |
253 | } | |
254 | case RDMA_GET_MEM:{ | |
255 | struct ch_mem_range *t = data; | |
256 | struct mc7 *mem; | |
257 | ||
258 | if ((t->addr & 7) || (t->len & 7)) | |
259 | return -EINVAL; | |
260 | if (t->mem_id == MEM_CM) | |
261 | mem = &adapter->cm; | |
262 | else if (t->mem_id == MEM_PMRX) | |
263 | mem = &adapter->pmrx; | |
264 | else if (t->mem_id == MEM_PMTX) | |
265 | mem = &adapter->pmtx; | |
266 | else | |
267 | return -EINVAL; | |
268 | ||
269 | ret = | |
270 | t3_mc7_bd_read(mem, t->addr / 8, t->len / 8, | |
271 | (u64 *) t->buf); | |
272 | if (ret) | |
273 | return ret; | |
274 | break; | |
275 | } | |
276 | case RDMA_CQ_SETUP:{ | |
9265fabf | 277 | struct rdma_cq_setup *rdma = data; |
4d22de3e DLR |
278 | |
279 | spin_lock_irq(&adapter->sge.reg_lock); | |
280 | ret = | |
9265fabf SH |
281 | t3_sge_init_cqcntxt(adapter, rdma->id, |
282 | rdma->base_addr, rdma->size, | |
4d22de3e | 283 | ASYNC_NOTIF_RSPQ, |
9265fabf SH |
284 | rdma->ovfl_mode, rdma->credits, |
285 | rdma->credit_thres); | |
4d22de3e DLR |
286 | spin_unlock_irq(&adapter->sge.reg_lock); |
287 | break; | |
288 | } | |
289 | case RDMA_CQ_DISABLE: | |
290 | spin_lock_irq(&adapter->sge.reg_lock); | |
291 | ret = t3_sge_disable_cqcntxt(adapter, *(unsigned int *)data); | |
292 | spin_unlock_irq(&adapter->sge.reg_lock); | |
293 | break; | |
294 | case RDMA_CTRL_QP_SETUP:{ | |
9265fabf | 295 | struct rdma_ctrlqp_setup *rdma = data; |
4d22de3e DLR |
296 | |
297 | spin_lock_irq(&adapter->sge.reg_lock); | |
298 | ret = t3_sge_init_ecntxt(adapter, FW_RI_SGEEC_START, 0, | |
299 | SGE_CNTXT_RDMA, | |
300 | ASYNC_NOTIF_RSPQ, | |
9265fabf | 301 | rdma->base_addr, rdma->size, |
4d22de3e DLR |
302 | FW_RI_TID_START, 1, 0); |
303 | spin_unlock_irq(&adapter->sge.reg_lock); | |
304 | break; | |
305 | } | |
306 | default: | |
307 | ret = -EOPNOTSUPP; | |
308 | } | |
309 | return ret; | |
310 | } | |
311 | ||
312 | static int cxgb_offload_ctl(struct t3cdev *tdev, unsigned int req, void *data) | |
313 | { | |
314 | struct adapter *adapter = tdev2adap(tdev); | |
315 | struct tid_range *tid; | |
316 | struct mtutab *mtup; | |
317 | struct iff_mac *iffmacp; | |
318 | struct ddp_params *ddpp; | |
319 | struct adap_ports *ports; | |
e22bb45d DLR |
320 | struct ofld_page_info *rx_page_info; |
321 | struct tp_params *tp = &adapter->params.tp; | |
4d22de3e DLR |
322 | int i; |
323 | ||
324 | switch (req) { | |
325 | case GET_MAX_OUTSTANDING_WR: | |
326 | *(unsigned int *)data = FW_WR_NUM; | |
327 | break; | |
328 | case GET_WR_LEN: | |
329 | *(unsigned int *)data = WR_FLITS; | |
330 | break; | |
331 | case GET_TX_MAX_CHUNK: | |
332 | *(unsigned int *)data = 1 << 20; /* 1MB */ | |
333 | break; | |
334 | case GET_TID_RANGE: | |
335 | tid = data; | |
336 | tid->num = t3_mc5_size(&adapter->mc5) - | |
337 | adapter->params.mc5.nroutes - | |
338 | adapter->params.mc5.nfilters - adapter->params.mc5.nservers; | |
339 | tid->base = 0; | |
340 | break; | |
341 | case GET_STID_RANGE: | |
342 | tid = data; | |
343 | tid->num = adapter->params.mc5.nservers; | |
344 | tid->base = t3_mc5_size(&adapter->mc5) - tid->num - | |
345 | adapter->params.mc5.nfilters - adapter->params.mc5.nroutes; | |
346 | break; | |
347 | case GET_L2T_CAPACITY: | |
348 | *(unsigned int *)data = 2048; | |
349 | break; | |
350 | case GET_MTUS: | |
351 | mtup = data; | |
352 | mtup->size = NMTUS; | |
353 | mtup->mtus = adapter->params.mtus; | |
354 | break; | |
355 | case GET_IFF_FROM_MAC: | |
356 | iffmacp = data; | |
357 | iffmacp->dev = get_iff_from_mac(adapter, iffmacp->mac_addr, | |
358 | iffmacp->vlan_tag & | |
359 | VLAN_VID_MASK); | |
360 | break; | |
361 | case GET_DDP_PARAMS: | |
362 | ddpp = data; | |
363 | ddpp->llimit = t3_read_reg(adapter, A_ULPRX_TDDP_LLIMIT); | |
364 | ddpp->ulimit = t3_read_reg(adapter, A_ULPRX_TDDP_ULIMIT); | |
365 | ddpp->tag_mask = t3_read_reg(adapter, A_ULPRX_TDDP_TAGMASK); | |
366 | break; | |
367 | case GET_PORTS: | |
368 | ports = data; | |
369 | ports->nports = adapter->params.nports; | |
370 | for_each_port(adapter, i) | |
371 | ports->lldevs[i] = adapter->port[i]; | |
372 | break; | |
373 | case ULP_ISCSI_GET_PARAMS: | |
374 | case ULP_ISCSI_SET_PARAMS: | |
375 | if (!offload_running(adapter)) | |
376 | return -EAGAIN; | |
377 | return cxgb_ulp_iscsi_ctl(adapter, req, data); | |
378 | case RDMA_GET_PARAMS: | |
379 | case RDMA_CQ_OP: | |
380 | case RDMA_CQ_SETUP: | |
381 | case RDMA_CQ_DISABLE: | |
382 | case RDMA_CTRL_QP_SETUP: | |
383 | case RDMA_GET_MEM: | |
384 | if (!offload_running(adapter)) | |
385 | return -EAGAIN; | |
386 | return cxgb_rdma_ctl(adapter, req, data); | |
e22bb45d DLR |
387 | case GET_RX_PAGE_INFO: |
388 | rx_page_info = data; | |
389 | rx_page_info->page_size = tp->rx_pg_size; | |
390 | rx_page_info->num = tp->rx_num_pgs; | |
391 | break; | |
4d22de3e DLR |
392 | default: |
393 | return -EOPNOTSUPP; | |
394 | } | |
395 | return 0; | |
396 | } | |
397 | ||
398 | /* | |
399 | * Dummy handler for Rx offload packets in case we get an offload packet before | |
400 | * proper processing is setup. This complains and drops the packet as it isn't | |
401 | * normal to get offload packets at this stage. | |
402 | */ | |
403 | static int rx_offload_blackhole(struct t3cdev *dev, struct sk_buff **skbs, | |
404 | int n) | |
405 | { | |
4d22de3e DLR |
406 | while (n--) |
407 | dev_kfree_skb_any(skbs[n]); | |
408 | return 0; | |
409 | } | |
410 | ||
411 | static void dummy_neigh_update(struct t3cdev *dev, struct neighbour *neigh) | |
412 | { | |
413 | } | |
414 | ||
415 | void cxgb3_set_dummy_ops(struct t3cdev *dev) | |
416 | { | |
417 | dev->recv = rx_offload_blackhole; | |
418 | dev->neigh_update = dummy_neigh_update; | |
419 | } | |
420 | ||
421 | /* | |
422 | * Free an active-open TID. | |
423 | */ | |
424 | void *cxgb3_free_atid(struct t3cdev *tdev, int atid) | |
425 | { | |
426 | struct tid_info *t = &(T3C_DATA(tdev))->tid_maps; | |
427 | union active_open_entry *p = atid2entry(t, atid); | |
428 | void *ctx = p->t3c_tid.ctx; | |
429 | ||
430 | spin_lock_bh(&t->atid_lock); | |
431 | p->next = t->afree; | |
432 | t->afree = p; | |
433 | t->atids_in_use--; | |
434 | spin_unlock_bh(&t->atid_lock); | |
435 | ||
436 | return ctx; | |
437 | } | |
438 | ||
439 | EXPORT_SYMBOL(cxgb3_free_atid); | |
440 | ||
441 | /* | |
442 | * Free a server TID and return it to the free pool. | |
443 | */ | |
444 | void cxgb3_free_stid(struct t3cdev *tdev, int stid) | |
445 | { | |
446 | struct tid_info *t = &(T3C_DATA(tdev))->tid_maps; | |
447 | union listen_entry *p = stid2entry(t, stid); | |
448 | ||
449 | spin_lock_bh(&t->stid_lock); | |
450 | p->next = t->sfree; | |
451 | t->sfree = p; | |
452 | t->stids_in_use--; | |
453 | spin_unlock_bh(&t->stid_lock); | |
454 | } | |
455 | ||
456 | EXPORT_SYMBOL(cxgb3_free_stid); | |
457 | ||
458 | void cxgb3_insert_tid(struct t3cdev *tdev, struct cxgb3_client *client, | |
459 | void *ctx, unsigned int tid) | |
460 | { | |
461 | struct tid_info *t = &(T3C_DATA(tdev))->tid_maps; | |
462 | ||
463 | t->tid_tab[tid].client = client; | |
464 | t->tid_tab[tid].ctx = ctx; | |
465 | atomic_inc(&t->tids_in_use); | |
466 | } | |
467 | ||
468 | EXPORT_SYMBOL(cxgb3_insert_tid); | |
469 | ||
470 | /* | |
471 | * Populate a TID_RELEASE WR. The skb must be already propely sized. | |
472 | */ | |
473 | static inline void mk_tid_release(struct sk_buff *skb, unsigned int tid) | |
474 | { | |
475 | struct cpl_tid_release *req; | |
476 | ||
477 | skb->priority = CPL_PRIORITY_SETUP; | |
478 | req = (struct cpl_tid_release *)__skb_put(skb, sizeof(*req)); | |
479 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
480 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid)); | |
481 | } | |
482 | ||
483 | static void t3_process_tid_release_list(struct work_struct *work) | |
484 | { | |
485 | struct t3c_data *td = container_of(work, struct t3c_data, | |
486 | tid_release_task); | |
487 | struct sk_buff *skb; | |
488 | struct t3cdev *tdev = td->dev; | |
2eab17ab | 489 | |
4d22de3e DLR |
490 | |
491 | spin_lock_bh(&td->tid_release_lock); | |
492 | while (td->tid_release_list) { | |
493 | struct t3c_tid_entry *p = td->tid_release_list; | |
494 | ||
495 | td->tid_release_list = (struct t3c_tid_entry *)p->ctx; | |
496 | spin_unlock_bh(&td->tid_release_lock); | |
497 | ||
498 | skb = alloc_skb(sizeof(struct cpl_tid_release), | |
499 | GFP_KERNEL | __GFP_NOFAIL); | |
500 | mk_tid_release(skb, p - td->tid_maps.tid_tab); | |
501 | cxgb3_ofld_send(tdev, skb); | |
502 | p->ctx = NULL; | |
503 | spin_lock_bh(&td->tid_release_lock); | |
504 | } | |
505 | spin_unlock_bh(&td->tid_release_lock); | |
506 | } | |
507 | ||
508 | /* use ctx as a next pointer in the tid release list */ | |
509 | void cxgb3_queue_tid_release(struct t3cdev *tdev, unsigned int tid) | |
510 | { | |
511 | struct t3c_data *td = T3C_DATA(tdev); | |
512 | struct t3c_tid_entry *p = &td->tid_maps.tid_tab[tid]; | |
513 | ||
514 | spin_lock_bh(&td->tid_release_lock); | |
515 | p->ctx = (void *)td->tid_release_list; | |
606fcd0b | 516 | p->client = NULL; |
4d22de3e DLR |
517 | td->tid_release_list = p; |
518 | if (!p->ctx) | |
519 | schedule_work(&td->tid_release_task); | |
520 | spin_unlock_bh(&td->tid_release_lock); | |
521 | } | |
522 | ||
523 | EXPORT_SYMBOL(cxgb3_queue_tid_release); | |
524 | ||
525 | /* | |
526 | * Remove a tid from the TID table. A client may defer processing its last | |
527 | * CPL message if it is locked at the time it arrives, and while the message | |
528 | * sits in the client's backlog the TID may be reused for another connection. | |
529 | * To handle this we atomically switch the TID association if it still points | |
530 | * to the original client context. | |
531 | */ | |
532 | void cxgb3_remove_tid(struct t3cdev *tdev, void *ctx, unsigned int tid) | |
533 | { | |
534 | struct tid_info *t = &(T3C_DATA(tdev))->tid_maps; | |
535 | ||
536 | BUG_ON(tid >= t->ntids); | |
537 | if (tdev->type == T3A) | |
538 | (void)cmpxchg(&t->tid_tab[tid].ctx, ctx, NULL); | |
539 | else { | |
540 | struct sk_buff *skb; | |
541 | ||
542 | skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC); | |
543 | if (likely(skb)) { | |
544 | mk_tid_release(skb, tid); | |
545 | cxgb3_ofld_send(tdev, skb); | |
546 | t->tid_tab[tid].ctx = NULL; | |
547 | } else | |
548 | cxgb3_queue_tid_release(tdev, tid); | |
549 | } | |
550 | atomic_dec(&t->tids_in_use); | |
551 | } | |
552 | ||
553 | EXPORT_SYMBOL(cxgb3_remove_tid); | |
554 | ||
555 | int cxgb3_alloc_atid(struct t3cdev *tdev, struct cxgb3_client *client, | |
556 | void *ctx) | |
557 | { | |
558 | int atid = -1; | |
559 | struct tid_info *t = &(T3C_DATA(tdev))->tid_maps; | |
560 | ||
561 | spin_lock_bh(&t->atid_lock); | |
9f238486 DLR |
562 | if (t->afree && |
563 | t->atids_in_use + atomic_read(&t->tids_in_use) + MC5_MIN_TIDS <= | |
564 | t->ntids) { | |
4d22de3e DLR |
565 | union active_open_entry *p = t->afree; |
566 | ||
567 | atid = (p - t->atid_tab) + t->atid_base; | |
568 | t->afree = p->next; | |
569 | p->t3c_tid.ctx = ctx; | |
570 | p->t3c_tid.client = client; | |
571 | t->atids_in_use++; | |
572 | } | |
573 | spin_unlock_bh(&t->atid_lock); | |
574 | return atid; | |
575 | } | |
576 | ||
577 | EXPORT_SYMBOL(cxgb3_alloc_atid); | |
578 | ||
579 | int cxgb3_alloc_stid(struct t3cdev *tdev, struct cxgb3_client *client, | |
580 | void *ctx) | |
581 | { | |
582 | int stid = -1; | |
583 | struct tid_info *t = &(T3C_DATA(tdev))->tid_maps; | |
584 | ||
585 | spin_lock_bh(&t->stid_lock); | |
586 | if (t->sfree) { | |
587 | union listen_entry *p = t->sfree; | |
588 | ||
589 | stid = (p - t->stid_tab) + t->stid_base; | |
590 | t->sfree = p->next; | |
591 | p->t3c_tid.ctx = ctx; | |
592 | p->t3c_tid.client = client; | |
593 | t->stids_in_use++; | |
594 | } | |
595 | spin_unlock_bh(&t->stid_lock); | |
596 | return stid; | |
597 | } | |
598 | ||
599 | EXPORT_SYMBOL(cxgb3_alloc_stid); | |
600 | ||
5fbf816f DLR |
601 | /* Get the t3cdev associated with a net_device */ |
602 | struct t3cdev *dev2t3cdev(struct net_device *dev) | |
603 | { | |
604 | const struct port_info *pi = netdev_priv(dev); | |
605 | ||
606 | return (struct t3cdev *)pi->adapter; | |
607 | } | |
608 | ||
609 | EXPORT_SYMBOL(dev2t3cdev); | |
610 | ||
4d22de3e DLR |
611 | static int do_smt_write_rpl(struct t3cdev *dev, struct sk_buff *skb) |
612 | { | |
613 | struct cpl_smt_write_rpl *rpl = cplhdr(skb); | |
614 | ||
615 | if (rpl->status != CPL_ERR_NONE) | |
616 | printk(KERN_ERR | |
617 | "Unexpected SMT_WRITE_RPL status %u for entry %u\n", | |
618 | rpl->status, GET_TID(rpl)); | |
619 | ||
620 | return CPL_RET_BUF_DONE; | |
621 | } | |
622 | ||
623 | static int do_l2t_write_rpl(struct t3cdev *dev, struct sk_buff *skb) | |
624 | { | |
625 | struct cpl_l2t_write_rpl *rpl = cplhdr(skb); | |
626 | ||
627 | if (rpl->status != CPL_ERR_NONE) | |
628 | printk(KERN_ERR | |
629 | "Unexpected L2T_WRITE_RPL status %u for entry %u\n", | |
630 | rpl->status, GET_TID(rpl)); | |
631 | ||
632 | return CPL_RET_BUF_DONE; | |
633 | } | |
634 | ||
b881955b DLR |
635 | static int do_rte_write_rpl(struct t3cdev *dev, struct sk_buff *skb) |
636 | { | |
637 | struct cpl_rte_write_rpl *rpl = cplhdr(skb); | |
638 | ||
639 | if (rpl->status != CPL_ERR_NONE) | |
640 | printk(KERN_ERR | |
641 | "Unexpected RTE_WRITE_RPL status %u for entry %u\n", | |
642 | rpl->status, GET_TID(rpl)); | |
643 | ||
644 | return CPL_RET_BUF_DONE; | |
645 | } | |
646 | ||
4d22de3e DLR |
647 | static int do_act_open_rpl(struct t3cdev *dev, struct sk_buff *skb) |
648 | { | |
649 | struct cpl_act_open_rpl *rpl = cplhdr(skb); | |
650 | unsigned int atid = G_TID(ntohl(rpl->atid)); | |
651 | struct t3c_tid_entry *t3c_tid; | |
652 | ||
653 | t3c_tid = lookup_atid(&(T3C_DATA(dev))->tid_maps, atid); | |
606fcd0b DLR |
654 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client && |
655 | t3c_tid->client->handlers && | |
4d22de3e DLR |
656 | t3c_tid->client->handlers[CPL_ACT_OPEN_RPL]) { |
657 | return t3c_tid->client->handlers[CPL_ACT_OPEN_RPL] (dev, skb, | |
658 | t3c_tid-> | |
659 | ctx); | |
660 | } else { | |
661 | printk(KERN_ERR "%s: received clientless CPL command 0x%x\n", | |
662 | dev->name, CPL_ACT_OPEN_RPL); | |
663 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; | |
664 | } | |
665 | } | |
666 | ||
667 | static int do_stid_rpl(struct t3cdev *dev, struct sk_buff *skb) | |
668 | { | |
669 | union opcode_tid *p = cplhdr(skb); | |
670 | unsigned int stid = G_TID(ntohl(p->opcode_tid)); | |
671 | struct t3c_tid_entry *t3c_tid; | |
672 | ||
673 | t3c_tid = lookup_stid(&(T3C_DATA(dev))->tid_maps, stid); | |
606fcd0b | 674 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client->handlers && |
4d22de3e DLR |
675 | t3c_tid->client->handlers[p->opcode]) { |
676 | return t3c_tid->client->handlers[p->opcode] (dev, skb, | |
677 | t3c_tid->ctx); | |
678 | } else { | |
679 | printk(KERN_ERR "%s: received clientless CPL command 0x%x\n", | |
680 | dev->name, p->opcode); | |
681 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; | |
682 | } | |
683 | } | |
684 | ||
685 | static int do_hwtid_rpl(struct t3cdev *dev, struct sk_buff *skb) | |
686 | { | |
687 | union opcode_tid *p = cplhdr(skb); | |
688 | unsigned int hwtid = G_TID(ntohl(p->opcode_tid)); | |
689 | struct t3c_tid_entry *t3c_tid; | |
690 | ||
691 | t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid); | |
606fcd0b | 692 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client->handlers && |
4d22de3e DLR |
693 | t3c_tid->client->handlers[p->opcode]) { |
694 | return t3c_tid->client->handlers[p->opcode] | |
695 | (dev, skb, t3c_tid->ctx); | |
696 | } else { | |
697 | printk(KERN_ERR "%s: received clientless CPL command 0x%x\n", | |
698 | dev->name, p->opcode); | |
699 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; | |
700 | } | |
701 | } | |
702 | ||
703 | static int do_cr(struct t3cdev *dev, struct sk_buff *skb) | |
704 | { | |
705 | struct cpl_pass_accept_req *req = cplhdr(skb); | |
706 | unsigned int stid = G_PASS_OPEN_TID(ntohl(req->tos_tid)); | |
c9a6ce50 | 707 | struct tid_info *t = &(T3C_DATA(dev))->tid_maps; |
4d22de3e | 708 | struct t3c_tid_entry *t3c_tid; |
c9a6ce50 | 709 | unsigned int tid = GET_TID(req); |
4d22de3e | 710 | |
c9a6ce50 DLR |
711 | if (unlikely(tid >= t->ntids)) { |
712 | printk("%s: passive open TID %u too large\n", | |
713 | dev->name, tid); | |
714 | t3_fatal_err(tdev2adap(dev)); | |
715 | return CPL_RET_BUF_DONE; | |
716 | } | |
717 | ||
718 | t3c_tid = lookup_stid(t, stid); | |
719 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client->handlers && | |
4d22de3e DLR |
720 | t3c_tid->client->handlers[CPL_PASS_ACCEPT_REQ]) { |
721 | return t3c_tid->client->handlers[CPL_PASS_ACCEPT_REQ] | |
722 | (dev, skb, t3c_tid->ctx); | |
723 | } else { | |
724 | printk(KERN_ERR "%s: received clientless CPL command 0x%x\n", | |
725 | dev->name, CPL_PASS_ACCEPT_REQ); | |
726 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; | |
727 | } | |
728 | } | |
729 | ||
606fcd0b DLR |
730 | /* |
731 | * Returns an sk_buff for a reply CPL message of size len. If the input | |
732 | * sk_buff has no other users it is trimmed and reused, otherwise a new buffer | |
733 | * is allocated. The input skb must be of size at least len. Note that this | |
734 | * operation does not destroy the original skb data even if it decides to reuse | |
735 | * the buffer. | |
736 | */ | |
737 | static struct sk_buff *cxgb3_get_cpl_reply_skb(struct sk_buff *skb, size_t len, | |
1f41bb3a | 738 | gfp_t gfp) |
606fcd0b DLR |
739 | { |
740 | if (likely(!skb_cloned(skb))) { | |
741 | BUG_ON(skb->len < len); | |
742 | __skb_trim(skb, len); | |
743 | skb_get(skb); | |
744 | } else { | |
745 | skb = alloc_skb(len, gfp); | |
746 | if (skb) | |
747 | __skb_put(skb, len); | |
748 | } | |
749 | return skb; | |
750 | } | |
751 | ||
4d22de3e DLR |
752 | static int do_abort_req_rss(struct t3cdev *dev, struct sk_buff *skb) |
753 | { | |
754 | union opcode_tid *p = cplhdr(skb); | |
755 | unsigned int hwtid = G_TID(ntohl(p->opcode_tid)); | |
756 | struct t3c_tid_entry *t3c_tid; | |
757 | ||
758 | t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid); | |
606fcd0b | 759 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client->handlers && |
4d22de3e DLR |
760 | t3c_tid->client->handlers[p->opcode]) { |
761 | return t3c_tid->client->handlers[p->opcode] | |
762 | (dev, skb, t3c_tid->ctx); | |
763 | } else { | |
764 | struct cpl_abort_req_rss *req = cplhdr(skb); | |
765 | struct cpl_abort_rpl *rpl; | |
606fcd0b DLR |
766 | struct sk_buff *reply_skb; |
767 | unsigned int tid = GET_TID(req); | |
768 | u8 cmd = req->status; | |
769 | ||
770 | if (req->status == CPL_ERR_RTX_NEG_ADVICE || | |
771 | req->status == CPL_ERR_PERSIST_NEG_ADVICE) | |
772 | goto out; | |
4d22de3e | 773 | |
606fcd0b DLR |
774 | reply_skb = cxgb3_get_cpl_reply_skb(skb, |
775 | sizeof(struct | |
776 | cpl_abort_rpl), | |
777 | GFP_ATOMIC); | |
778 | ||
779 | if (!reply_skb) { | |
4d22de3e DLR |
780 | printk("do_abort_req_rss: couldn't get skb!\n"); |
781 | goto out; | |
782 | } | |
606fcd0b DLR |
783 | reply_skb->priority = CPL_PRIORITY_DATA; |
784 | __skb_put(reply_skb, sizeof(struct cpl_abort_rpl)); | |
785 | rpl = cplhdr(reply_skb); | |
4d22de3e DLR |
786 | rpl->wr.wr_hi = |
787 | htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL)); | |
606fcd0b DLR |
788 | rpl->wr.wr_lo = htonl(V_WR_TID(tid)); |
789 | OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, tid)); | |
790 | rpl->cmd = cmd; | |
791 | cxgb3_ofld_send(dev, reply_skb); | |
4d22de3e DLR |
792 | out: |
793 | return CPL_RET_BUF_DONE; | |
794 | } | |
795 | } | |
796 | ||
797 | static int do_act_establish(struct t3cdev *dev, struct sk_buff *skb) | |
798 | { | |
799 | struct cpl_act_establish *req = cplhdr(skb); | |
800 | unsigned int atid = G_PASS_OPEN_TID(ntohl(req->tos_tid)); | |
c9a6ce50 | 801 | struct tid_info *t = &(T3C_DATA(dev))->tid_maps; |
4d22de3e | 802 | struct t3c_tid_entry *t3c_tid; |
c9a6ce50 | 803 | unsigned int tid = GET_TID(req); |
4d22de3e | 804 | |
c9a6ce50 DLR |
805 | if (unlikely(tid >= t->ntids)) { |
806 | printk("%s: active establish TID %u too large\n", | |
807 | dev->name, tid); | |
808 | t3_fatal_err(tdev2adap(dev)); | |
809 | return CPL_RET_BUF_DONE; | |
810 | } | |
811 | ||
812 | t3c_tid = lookup_atid(t, atid); | |
606fcd0b | 813 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client->handlers && |
4d22de3e DLR |
814 | t3c_tid->client->handlers[CPL_ACT_ESTABLISH]) { |
815 | return t3c_tid->client->handlers[CPL_ACT_ESTABLISH] | |
816 | (dev, skb, t3c_tid->ctx); | |
817 | } else { | |
818 | printk(KERN_ERR "%s: received clientless CPL command 0x%x\n", | |
c9a6ce50 | 819 | dev->name, CPL_ACT_ESTABLISH); |
4d22de3e DLR |
820 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; |
821 | } | |
822 | } | |
823 | ||
4d22de3e DLR |
824 | static int do_trace(struct t3cdev *dev, struct sk_buff *skb) |
825 | { | |
826 | struct cpl_trace_pkt *p = cplhdr(skb); | |
827 | ||
b5344972 | 828 | skb->protocol = htons(0xffff); |
4d22de3e DLR |
829 | skb->dev = dev->lldev; |
830 | skb_pull(skb, sizeof(*p)); | |
459a98ed | 831 | skb_reset_mac_header(skb); |
4d22de3e DLR |
832 | netif_receive_skb(skb); |
833 | return 0; | |
834 | } | |
835 | ||
fa3a6cb4 AV |
836 | /* |
837 | * That skb would better have come from process_responses() where we abuse | |
838 | * ->priority and ->csum to carry our data. NB: if we get to per-arch | |
839 | * ->csum, the things might get really interesting here. | |
840 | */ | |
841 | ||
842 | static inline u32 get_hwtid(struct sk_buff *skb) | |
843 | { | |
844 | return ntohl((__force __be32)skb->priority) >> 8 & 0xfffff; | |
845 | } | |
846 | ||
847 | static inline u32 get_opcode(struct sk_buff *skb) | |
848 | { | |
849 | return G_OPCODE(ntohl((__force __be32)skb->csum)); | |
850 | } | |
851 | ||
4d22de3e DLR |
852 | static int do_term(struct t3cdev *dev, struct sk_buff *skb) |
853 | { | |
fa3a6cb4 AV |
854 | unsigned int hwtid = get_hwtid(skb); |
855 | unsigned int opcode = get_opcode(skb); | |
4d22de3e DLR |
856 | struct t3c_tid_entry *t3c_tid; |
857 | ||
858 | t3c_tid = lookup_tid(&(T3C_DATA(dev))->tid_maps, hwtid); | |
606fcd0b | 859 | if (t3c_tid && t3c_tid->ctx && t3c_tid->client->handlers && |
4d22de3e DLR |
860 | t3c_tid->client->handlers[opcode]) { |
861 | return t3c_tid->client->handlers[opcode] (dev, skb, | |
862 | t3c_tid->ctx); | |
863 | } else { | |
864 | printk(KERN_ERR "%s: received clientless CPL command 0x%x\n", | |
865 | dev->name, opcode); | |
866 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; | |
867 | } | |
868 | } | |
869 | ||
870 | static int nb_callback(struct notifier_block *self, unsigned long event, | |
871 | void *ctx) | |
872 | { | |
873 | switch (event) { | |
874 | case (NETEVENT_NEIGH_UPDATE):{ | |
875 | cxgb_neigh_update((struct neighbour *)ctx); | |
876 | break; | |
877 | } | |
878 | case (NETEVENT_PMTU_UPDATE): | |
879 | break; | |
880 | case (NETEVENT_REDIRECT):{ | |
881 | struct netevent_redirect *nr = ctx; | |
882 | cxgb_redirect(nr->old, nr->new); | |
883 | cxgb_neigh_update(nr->new->neighbour); | |
884 | break; | |
885 | } | |
886 | default: | |
887 | break; | |
888 | } | |
889 | return 0; | |
890 | } | |
891 | ||
892 | static struct notifier_block nb = { | |
893 | .notifier_call = nb_callback | |
894 | }; | |
895 | ||
896 | /* | |
897 | * Process a received packet with an unknown/unexpected CPL opcode. | |
898 | */ | |
899 | static int do_bad_cpl(struct t3cdev *dev, struct sk_buff *skb) | |
900 | { | |
901 | printk(KERN_ERR "%s: received bad CPL command 0x%x\n", dev->name, | |
902 | *skb->data); | |
903 | return CPL_RET_BUF_DONE | CPL_RET_BAD_MSG; | |
904 | } | |
905 | ||
906 | /* | |
907 | * Handlers for each CPL opcode | |
908 | */ | |
909 | static cpl_handler_func cpl_handlers[NUM_CPL_CMDS]; | |
910 | ||
911 | /* | |
912 | * Add a new handler to the CPL dispatch table. A NULL handler may be supplied | |
913 | * to unregister an existing handler. | |
914 | */ | |
915 | void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h) | |
916 | { | |
917 | if (opcode < NUM_CPL_CMDS) | |
918 | cpl_handlers[opcode] = h ? h : do_bad_cpl; | |
919 | else | |
920 | printk(KERN_ERR "T3C: handler registration for " | |
921 | "opcode %x failed\n", opcode); | |
922 | } | |
923 | ||
924 | EXPORT_SYMBOL(t3_register_cpl_handler); | |
925 | ||
926 | /* | |
927 | * T3CDEV's receive method. | |
928 | */ | |
929 | int process_rx(struct t3cdev *dev, struct sk_buff **skbs, int n) | |
930 | { | |
931 | while (n--) { | |
932 | struct sk_buff *skb = *skbs++; | |
fa3a6cb4 | 933 | unsigned int opcode = get_opcode(skb); |
4d22de3e DLR |
934 | int ret = cpl_handlers[opcode] (dev, skb); |
935 | ||
936 | #if VALIDATE_TID | |
937 | if (ret & CPL_RET_UNKNOWN_TID) { | |
938 | union opcode_tid *p = cplhdr(skb); | |
939 | ||
940 | printk(KERN_ERR "%s: CPL message (opcode %u) had " | |
941 | "unknown TID %u\n", dev->name, opcode, | |
942 | G_TID(ntohl(p->opcode_tid))); | |
943 | } | |
944 | #endif | |
945 | if (ret & CPL_RET_BUF_DONE) | |
946 | kfree_skb(skb); | |
947 | } | |
948 | return 0; | |
949 | } | |
950 | ||
951 | /* | |
952 | * Sends an sk_buff to a T3C driver after dealing with any active network taps. | |
953 | */ | |
954 | int cxgb3_ofld_send(struct t3cdev *dev, struct sk_buff *skb) | |
955 | { | |
956 | int r; | |
957 | ||
958 | local_bh_disable(); | |
959 | r = dev->send(dev, skb); | |
960 | local_bh_enable(); | |
961 | return r; | |
962 | } | |
963 | ||
964 | EXPORT_SYMBOL(cxgb3_ofld_send); | |
965 | ||
966 | static int is_offloading(struct net_device *dev) | |
967 | { | |
968 | struct adapter *adapter; | |
969 | int i; | |
970 | ||
971 | read_lock_bh(&adapter_list_lock); | |
972 | list_for_each_entry(adapter, &adapter_list, adapter_list) { | |
973 | for_each_port(adapter, i) { | |
974 | if (dev == adapter->port[i]) { | |
975 | read_unlock_bh(&adapter_list_lock); | |
976 | return 1; | |
977 | } | |
978 | } | |
979 | } | |
980 | read_unlock_bh(&adapter_list_lock); | |
981 | return 0; | |
982 | } | |
983 | ||
984 | void cxgb_neigh_update(struct neighbour *neigh) | |
985 | { | |
986 | struct net_device *dev = neigh->dev; | |
987 | ||
988 | if (dev && (is_offloading(dev))) { | |
5fbf816f | 989 | struct t3cdev *tdev = dev2t3cdev(dev); |
4d22de3e DLR |
990 | |
991 | BUG_ON(!tdev); | |
992 | t3_l2t_update(tdev, neigh); | |
993 | } | |
994 | } | |
995 | ||
996 | static void set_l2t_ix(struct t3cdev *tdev, u32 tid, struct l2t_entry *e) | |
997 | { | |
998 | struct sk_buff *skb; | |
999 | struct cpl_set_tcb_field *req; | |
1000 | ||
1001 | skb = alloc_skb(sizeof(*req), GFP_ATOMIC); | |
1002 | if (!skb) { | |
1003 | printk(KERN_ERR "%s: cannot allocate skb!\n", __FUNCTION__); | |
1004 | return; | |
1005 | } | |
1006 | skb->priority = CPL_PRIORITY_CONTROL; | |
1007 | req = (struct cpl_set_tcb_field *)skb_put(skb, sizeof(*req)); | |
1008 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
1009 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, tid)); | |
1010 | req->reply = 0; | |
1011 | req->cpu_idx = 0; | |
1012 | req->word = htons(W_TCB_L2T_IX); | |
1013 | req->mask = cpu_to_be64(V_TCB_L2T_IX(M_TCB_L2T_IX)); | |
1014 | req->val = cpu_to_be64(V_TCB_L2T_IX(e->idx)); | |
1015 | tdev->send(tdev, skb); | |
1016 | } | |
1017 | ||
1018 | void cxgb_redirect(struct dst_entry *old, struct dst_entry *new) | |
1019 | { | |
1020 | struct net_device *olddev, *newdev; | |
1021 | struct tid_info *ti; | |
1022 | struct t3cdev *tdev; | |
1023 | u32 tid; | |
1024 | int update_tcb; | |
1025 | struct l2t_entry *e; | |
1026 | struct t3c_tid_entry *te; | |
1027 | ||
1028 | olddev = old->neighbour->dev; | |
1029 | newdev = new->neighbour->dev; | |
1030 | if (!is_offloading(olddev)) | |
1031 | return; | |
1032 | if (!is_offloading(newdev)) { | |
f07b2e40 | 1033 | printk(KERN_WARNING "%s: Redirect to non-offload " |
4d22de3e DLR |
1034 | "device ignored.\n", __FUNCTION__); |
1035 | return; | |
1036 | } | |
5fbf816f | 1037 | tdev = dev2t3cdev(olddev); |
4d22de3e | 1038 | BUG_ON(!tdev); |
5fbf816f | 1039 | if (tdev != dev2t3cdev(newdev)) { |
4d22de3e DLR |
1040 | printk(KERN_WARNING "%s: Redirect to different " |
1041 | "offload device ignored.\n", __FUNCTION__); | |
1042 | return; | |
1043 | } | |
1044 | ||
1045 | /* Add new L2T entry */ | |
1046 | e = t3_l2t_get(tdev, new->neighbour, newdev); | |
1047 | if (!e) { | |
1048 | printk(KERN_ERR "%s: couldn't allocate new l2t entry!\n", | |
1049 | __FUNCTION__); | |
1050 | return; | |
1051 | } | |
1052 | ||
1053 | /* Walk tid table and notify clients of dst change. */ | |
1054 | ti = &(T3C_DATA(tdev))->tid_maps; | |
1055 | for (tid = 0; tid < ti->ntids; tid++) { | |
1056 | te = lookup_tid(ti, tid); | |
1057 | BUG_ON(!te); | |
606fcd0b | 1058 | if (te && te->ctx && te->client && te->client->redirect) { |
4d22de3e DLR |
1059 | update_tcb = te->client->redirect(te->ctx, old, new, e); |
1060 | if (update_tcb) { | |
1061 | l2t_hold(L2DATA(tdev), e); | |
1062 | set_l2t_ix(tdev, tid, e); | |
1063 | } | |
1064 | } | |
1065 | } | |
1066 | l2t_release(L2DATA(tdev), e); | |
1067 | } | |
1068 | ||
1069 | /* | |
1070 | * Allocate a chunk of memory using kmalloc or, if that fails, vmalloc. | |
1071 | * The allocated memory is cleared. | |
1072 | */ | |
1073 | void *cxgb_alloc_mem(unsigned long size) | |
1074 | { | |
1075 | void *p = kmalloc(size, GFP_KERNEL); | |
1076 | ||
1077 | if (!p) | |
1078 | p = vmalloc(size); | |
1079 | if (p) | |
1080 | memset(p, 0, size); | |
1081 | return p; | |
1082 | } | |
1083 | ||
1084 | /* | |
1085 | * Free memory allocated through t3_alloc_mem(). | |
1086 | */ | |
1087 | void cxgb_free_mem(void *addr) | |
1088 | { | |
9e2779fa | 1089 | if (is_vmalloc_addr(addr)) |
4d22de3e DLR |
1090 | vfree(addr); |
1091 | else | |
1092 | kfree(addr); | |
1093 | } | |
1094 | ||
1095 | /* | |
1096 | * Allocate and initialize the TID tables. Returns 0 on success. | |
1097 | */ | |
1098 | static int init_tid_tabs(struct tid_info *t, unsigned int ntids, | |
1099 | unsigned int natids, unsigned int nstids, | |
1100 | unsigned int atid_base, unsigned int stid_base) | |
1101 | { | |
1102 | unsigned long size = ntids * sizeof(*t->tid_tab) + | |
1103 | natids * sizeof(*t->atid_tab) + nstids * sizeof(*t->stid_tab); | |
1104 | ||
1105 | t->tid_tab = cxgb_alloc_mem(size); | |
1106 | if (!t->tid_tab) | |
1107 | return -ENOMEM; | |
1108 | ||
1109 | t->stid_tab = (union listen_entry *)&t->tid_tab[ntids]; | |
1110 | t->atid_tab = (union active_open_entry *)&t->stid_tab[nstids]; | |
1111 | t->ntids = ntids; | |
1112 | t->nstids = nstids; | |
1113 | t->stid_base = stid_base; | |
1114 | t->sfree = NULL; | |
1115 | t->natids = natids; | |
1116 | t->atid_base = atid_base; | |
1117 | t->afree = NULL; | |
1118 | t->stids_in_use = t->atids_in_use = 0; | |
1119 | atomic_set(&t->tids_in_use, 0); | |
1120 | spin_lock_init(&t->stid_lock); | |
1121 | spin_lock_init(&t->atid_lock); | |
1122 | ||
1123 | /* | |
1124 | * Setup the free lists for stid_tab and atid_tab. | |
1125 | */ | |
1126 | if (nstids) { | |
1127 | while (--nstids) | |
1128 | t->stid_tab[nstids - 1].next = &t->stid_tab[nstids]; | |
1129 | t->sfree = t->stid_tab; | |
1130 | } | |
1131 | if (natids) { | |
1132 | while (--natids) | |
1133 | t->atid_tab[natids - 1].next = &t->atid_tab[natids]; | |
1134 | t->afree = t->atid_tab; | |
1135 | } | |
1136 | return 0; | |
1137 | } | |
1138 | ||
1139 | static void free_tid_maps(struct tid_info *t) | |
1140 | { | |
1141 | cxgb_free_mem(t->tid_tab); | |
1142 | } | |
1143 | ||
1144 | static inline void add_adapter(struct adapter *adap) | |
1145 | { | |
1146 | write_lock_bh(&adapter_list_lock); | |
1147 | list_add_tail(&adap->adapter_list, &adapter_list); | |
1148 | write_unlock_bh(&adapter_list_lock); | |
1149 | } | |
1150 | ||
1151 | static inline void remove_adapter(struct adapter *adap) | |
1152 | { | |
1153 | write_lock_bh(&adapter_list_lock); | |
1154 | list_del(&adap->adapter_list); | |
1155 | write_unlock_bh(&adapter_list_lock); | |
1156 | } | |
1157 | ||
1158 | int cxgb3_offload_activate(struct adapter *adapter) | |
1159 | { | |
1160 | struct t3cdev *dev = &adapter->tdev; | |
1161 | int natids, err; | |
1162 | struct t3c_data *t; | |
1163 | struct tid_range stid_range, tid_range; | |
1164 | struct mtutab mtutab; | |
1165 | unsigned int l2t_capacity; | |
1166 | ||
1167 | t = kcalloc(1, sizeof(*t), GFP_KERNEL); | |
1168 | if (!t) | |
1169 | return -ENOMEM; | |
1170 | ||
1171 | err = -EOPNOTSUPP; | |
1172 | if (dev->ctl(dev, GET_TX_MAX_CHUNK, &t->tx_max_chunk) < 0 || | |
1173 | dev->ctl(dev, GET_MAX_OUTSTANDING_WR, &t->max_wrs) < 0 || | |
1174 | dev->ctl(dev, GET_L2T_CAPACITY, &l2t_capacity) < 0 || | |
1175 | dev->ctl(dev, GET_MTUS, &mtutab) < 0 || | |
1176 | dev->ctl(dev, GET_TID_RANGE, &tid_range) < 0 || | |
1177 | dev->ctl(dev, GET_STID_RANGE, &stid_range) < 0) | |
1178 | goto out_free; | |
1179 | ||
1180 | err = -ENOMEM; | |
1181 | L2DATA(dev) = t3_init_l2t(l2t_capacity); | |
1182 | if (!L2DATA(dev)) | |
1183 | goto out_free; | |
1184 | ||
1185 | natids = min(tid_range.num / 2, MAX_ATIDS); | |
1186 | err = init_tid_tabs(&t->tid_maps, tid_range.num, natids, | |
1187 | stid_range.num, ATID_BASE, stid_range.base); | |
1188 | if (err) | |
1189 | goto out_free_l2t; | |
1190 | ||
1191 | t->mtus = mtutab.mtus; | |
1192 | t->nmtus = mtutab.size; | |
1193 | ||
1194 | INIT_WORK(&t->tid_release_task, t3_process_tid_release_list); | |
1195 | spin_lock_init(&t->tid_release_lock); | |
1196 | INIT_LIST_HEAD(&t->list_node); | |
1197 | t->dev = dev; | |
1198 | ||
1199 | T3C_DATA(dev) = t; | |
1200 | dev->recv = process_rx; | |
1201 | dev->neigh_update = t3_l2t_update; | |
1202 | ||
1203 | /* Register netevent handler once */ | |
1204 | if (list_empty(&adapter_list)) | |
1205 | register_netevent_notifier(&nb); | |
1206 | ||
1207 | add_adapter(adapter); | |
1208 | return 0; | |
1209 | ||
1210 | out_free_l2t: | |
1211 | t3_free_l2t(L2DATA(dev)); | |
1212 | L2DATA(dev) = NULL; | |
1213 | out_free: | |
1214 | kfree(t); | |
1215 | return err; | |
1216 | } | |
1217 | ||
1218 | void cxgb3_offload_deactivate(struct adapter *adapter) | |
1219 | { | |
1220 | struct t3cdev *tdev = &adapter->tdev; | |
1221 | struct t3c_data *t = T3C_DATA(tdev); | |
1222 | ||
1223 | remove_adapter(adapter); | |
1224 | if (list_empty(&adapter_list)) | |
1225 | unregister_netevent_notifier(&nb); | |
1226 | ||
1227 | free_tid_maps(&t->tid_maps); | |
1228 | T3C_DATA(tdev) = NULL; | |
1229 | t3_free_l2t(L2DATA(tdev)); | |
1230 | L2DATA(tdev) = NULL; | |
1231 | kfree(t); | |
1232 | } | |
1233 | ||
1234 | static inline void register_tdev(struct t3cdev *tdev) | |
1235 | { | |
1236 | static int unit; | |
1237 | ||
1238 | mutex_lock(&cxgb3_db_lock); | |
1239 | snprintf(tdev->name, sizeof(tdev->name), "ofld_dev%d", unit++); | |
1240 | list_add_tail(&tdev->ofld_dev_list, &ofld_dev_list); | |
1241 | mutex_unlock(&cxgb3_db_lock); | |
1242 | } | |
1243 | ||
1244 | static inline void unregister_tdev(struct t3cdev *tdev) | |
1245 | { | |
1246 | mutex_lock(&cxgb3_db_lock); | |
1247 | list_del(&tdev->ofld_dev_list); | |
1248 | mutex_unlock(&cxgb3_db_lock); | |
1249 | } | |
1250 | ||
1251 | void __devinit cxgb3_adapter_ofld(struct adapter *adapter) | |
1252 | { | |
1253 | struct t3cdev *tdev = &adapter->tdev; | |
1254 | ||
1255 | INIT_LIST_HEAD(&tdev->ofld_dev_list); | |
1256 | ||
1257 | cxgb3_set_dummy_ops(tdev); | |
1258 | tdev->send = t3_offload_tx; | |
1259 | tdev->ctl = cxgb_offload_ctl; | |
1260 | tdev->type = adapter->params.rev == 0 ? T3A : T3B; | |
1261 | ||
1262 | register_tdev(tdev); | |
1263 | } | |
1264 | ||
1265 | void __devexit cxgb3_adapter_unofld(struct adapter *adapter) | |
1266 | { | |
1267 | struct t3cdev *tdev = &adapter->tdev; | |
1268 | ||
1269 | tdev->recv = NULL; | |
1270 | tdev->neigh_update = NULL; | |
1271 | ||
1272 | unregister_tdev(tdev); | |
1273 | } | |
1274 | ||
1275 | void __init cxgb3_offload_init(void) | |
1276 | { | |
1277 | int i; | |
1278 | ||
1279 | for (i = 0; i < NUM_CPL_CMDS; ++i) | |
1280 | cpl_handlers[i] = do_bad_cpl; | |
1281 | ||
1282 | t3_register_cpl_handler(CPL_SMT_WRITE_RPL, do_smt_write_rpl); | |
1283 | t3_register_cpl_handler(CPL_L2T_WRITE_RPL, do_l2t_write_rpl); | |
b881955b | 1284 | t3_register_cpl_handler(CPL_RTE_WRITE_RPL, do_rte_write_rpl); |
4d22de3e DLR |
1285 | t3_register_cpl_handler(CPL_PASS_OPEN_RPL, do_stid_rpl); |
1286 | t3_register_cpl_handler(CPL_CLOSE_LISTSRV_RPL, do_stid_rpl); | |
1287 | t3_register_cpl_handler(CPL_PASS_ACCEPT_REQ, do_cr); | |
1288 | t3_register_cpl_handler(CPL_PASS_ESTABLISH, do_hwtid_rpl); | |
1289 | t3_register_cpl_handler(CPL_ABORT_RPL_RSS, do_hwtid_rpl); | |
1290 | t3_register_cpl_handler(CPL_ABORT_RPL, do_hwtid_rpl); | |
1291 | t3_register_cpl_handler(CPL_RX_URG_NOTIFY, do_hwtid_rpl); | |
1292 | t3_register_cpl_handler(CPL_RX_DATA, do_hwtid_rpl); | |
1293 | t3_register_cpl_handler(CPL_TX_DATA_ACK, do_hwtid_rpl); | |
1294 | t3_register_cpl_handler(CPL_TX_DMA_ACK, do_hwtid_rpl); | |
1295 | t3_register_cpl_handler(CPL_ACT_OPEN_RPL, do_act_open_rpl); | |
1296 | t3_register_cpl_handler(CPL_PEER_CLOSE, do_hwtid_rpl); | |
1297 | t3_register_cpl_handler(CPL_CLOSE_CON_RPL, do_hwtid_rpl); | |
1298 | t3_register_cpl_handler(CPL_ABORT_REQ_RSS, do_abort_req_rss); | |
1299 | t3_register_cpl_handler(CPL_ACT_ESTABLISH, do_act_establish); | |
6cdbd77e DLR |
1300 | t3_register_cpl_handler(CPL_SET_TCB_RPL, do_hwtid_rpl); |
1301 | t3_register_cpl_handler(CPL_GET_TCB_RPL, do_hwtid_rpl); | |
4d22de3e DLR |
1302 | t3_register_cpl_handler(CPL_RDMA_TERMINATE, do_term); |
1303 | t3_register_cpl_handler(CPL_RDMA_EC_STATUS, do_hwtid_rpl); | |
1304 | t3_register_cpl_handler(CPL_TRACE_PKT, do_trace); | |
1305 | t3_register_cpl_handler(CPL_RX_DATA_DDP, do_hwtid_rpl); | |
1306 | t3_register_cpl_handler(CPL_RX_DDP_COMPLETE, do_hwtid_rpl); | |
1307 | t3_register_cpl_handler(CPL_ISCSI_HDR, do_hwtid_rpl); | |
1308 | } |