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