1f7917c00SJeff Kirsher /*
2f7917c00SJeff Kirsher  * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
3f7917c00SJeff Kirsher  *
4f7917c00SJeff Kirsher  * This software is available to you under a choice of one of two
5f7917c00SJeff Kirsher  * licenses.  You may choose to be licensed under the terms of the GNU
6f7917c00SJeff Kirsher  * General Public License (GPL) Version 2, available from the file
7f7917c00SJeff Kirsher  * COPYING in the main directory of this source tree, or the
8f7917c00SJeff Kirsher  * OpenIB.org BSD license below:
9f7917c00SJeff Kirsher  *
10f7917c00SJeff Kirsher  *     Redistribution and use in source and binary forms, with or
11f7917c00SJeff Kirsher  *     without modification, are permitted provided that the following
12f7917c00SJeff Kirsher  *     conditions are met:
13f7917c00SJeff Kirsher  *
14f7917c00SJeff Kirsher  *      - Redistributions of source code must retain the above
15f7917c00SJeff Kirsher  *        copyright notice, this list of conditions and the following
16f7917c00SJeff Kirsher  *        disclaimer.
17f7917c00SJeff Kirsher  *
18f7917c00SJeff Kirsher  *      - Redistributions in binary form must reproduce the above
19f7917c00SJeff Kirsher  *        copyright notice, this list of conditions and the following
20f7917c00SJeff Kirsher  *        disclaimer in the documentation and/or other materials
21f7917c00SJeff Kirsher  *        provided with the distribution.
22f7917c00SJeff Kirsher  *
23f7917c00SJeff Kirsher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24f7917c00SJeff Kirsher  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25f7917c00SJeff Kirsher  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26f7917c00SJeff Kirsher  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27f7917c00SJeff Kirsher  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28f7917c00SJeff Kirsher  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29f7917c00SJeff Kirsher  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30f7917c00SJeff Kirsher  * SOFTWARE.
31f7917c00SJeff Kirsher  */
32f7917c00SJeff Kirsher #ifndef _CHELSIO_DEFS_H
33f7917c00SJeff Kirsher #define _CHELSIO_DEFS_H
34f7917c00SJeff Kirsher 
35f7917c00SJeff Kirsher #include <linux/skbuff.h>
36f7917c00SJeff Kirsher #include <net/tcp.h>
37f7917c00SJeff Kirsher 
38f7917c00SJeff Kirsher #include "t3cdev.h"
39f7917c00SJeff Kirsher 
40f7917c00SJeff Kirsher #include "cxgb3_offload.h"
41f7917c00SJeff Kirsher 
42f7917c00SJeff Kirsher #define VALIDATE_TID 1
43f7917c00SJeff Kirsher 
44f7917c00SJeff Kirsher /*
45f7917c00SJeff Kirsher  * Map an ATID or STID to their entries in the corresponding TID tables.
46f7917c00SJeff Kirsher  */
atid2entry(const struct tid_info * t,unsigned int atid)47f7917c00SJeff Kirsher static inline union active_open_entry *atid2entry(const struct tid_info *t,
48f7917c00SJeff Kirsher 						  unsigned int atid)
49f7917c00SJeff Kirsher {
50f7917c00SJeff Kirsher 	return &t->atid_tab[atid - t->atid_base];
51f7917c00SJeff Kirsher }
52f7917c00SJeff Kirsher 
stid2entry(const struct tid_info * t,unsigned int stid)53f7917c00SJeff Kirsher static inline union listen_entry *stid2entry(const struct tid_info *t,
54f7917c00SJeff Kirsher 					     unsigned int stid)
55f7917c00SJeff Kirsher {
56f7917c00SJeff Kirsher 	return &t->stid_tab[stid - t->stid_base];
57f7917c00SJeff Kirsher }
58f7917c00SJeff Kirsher 
59f7917c00SJeff Kirsher /*
60f7917c00SJeff Kirsher  * Find the connection corresponding to a TID.
61f7917c00SJeff Kirsher  */
lookup_tid(const struct tid_info * t,unsigned int tid)62f7917c00SJeff Kirsher static inline struct t3c_tid_entry *lookup_tid(const struct tid_info *t,
63f7917c00SJeff Kirsher 					       unsigned int tid)
64f7917c00SJeff Kirsher {
65f7917c00SJeff Kirsher 	struct t3c_tid_entry *t3c_tid = tid < t->ntids ?
66f7917c00SJeff Kirsher 	    &(t->tid_tab[tid]) : NULL;
67f7917c00SJeff Kirsher 
68f7917c00SJeff Kirsher 	return (t3c_tid && t3c_tid->client) ? t3c_tid : NULL;
69f7917c00SJeff Kirsher }
70f7917c00SJeff Kirsher 
71f7917c00SJeff Kirsher /*
72f7917c00SJeff Kirsher  * Find the connection corresponding to a server TID.
73f7917c00SJeff Kirsher  */
lookup_stid(const struct tid_info * t,unsigned int tid)74f7917c00SJeff Kirsher static inline struct t3c_tid_entry *lookup_stid(const struct tid_info *t,
75f7917c00SJeff Kirsher 						unsigned int tid)
76f7917c00SJeff Kirsher {
77f7917c00SJeff Kirsher 	union listen_entry *e;
78f7917c00SJeff Kirsher 
79f7917c00SJeff Kirsher 	if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
80f7917c00SJeff Kirsher 		return NULL;
81f7917c00SJeff Kirsher 
82f7917c00SJeff Kirsher 	e = stid2entry(t, tid);
83f7917c00SJeff Kirsher 	if ((void *)e->next >= (void *)t->tid_tab &&
84f7917c00SJeff Kirsher 	    (void *)e->next < (void *)&t->atid_tab[t->natids])
85f7917c00SJeff Kirsher 		return NULL;
86f7917c00SJeff Kirsher 
87f7917c00SJeff Kirsher 	return &e->t3c_tid;
88f7917c00SJeff Kirsher }
89f7917c00SJeff Kirsher 
90f7917c00SJeff Kirsher /*
91f7917c00SJeff Kirsher  * Find the connection corresponding to an active-open TID.
92f7917c00SJeff Kirsher  */
lookup_atid(const struct tid_info * t,unsigned int tid)93f7917c00SJeff Kirsher static inline struct t3c_tid_entry *lookup_atid(const struct tid_info *t,
94f7917c00SJeff Kirsher 						unsigned int tid)
95f7917c00SJeff Kirsher {
96f7917c00SJeff Kirsher 	union active_open_entry *e;
97f7917c00SJeff Kirsher 
98f7917c00SJeff Kirsher 	if (tid < t->atid_base || tid >= t->atid_base + t->natids)
99f7917c00SJeff Kirsher 		return NULL;
100f7917c00SJeff Kirsher 
101f7917c00SJeff Kirsher 	e = atid2entry(t, tid);
102f7917c00SJeff Kirsher 	if ((void *)e->next >= (void *)t->tid_tab &&
103f7917c00SJeff Kirsher 	    (void *)e->next < (void *)&t->atid_tab[t->natids])
104f7917c00SJeff Kirsher 		return NULL;
105f7917c00SJeff Kirsher 
106f7917c00SJeff Kirsher 	return &e->t3c_tid;
107f7917c00SJeff Kirsher }
108f7917c00SJeff Kirsher 
109f7917c00SJeff Kirsher int attach_t3cdev(struct t3cdev *dev);
110f7917c00SJeff Kirsher void detach_t3cdev(struct t3cdev *dev);
111f7917c00SJeff Kirsher #endif
112