18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This software is available to you under a choice of one of two
58c2ecf20Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
68c2ecf20Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
78c2ecf20Sopenharmony_ci * COPYING in the main directory of this source tree, or the
88c2ecf20Sopenharmony_ci * OpenIB.org BSD license below:
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
118c2ecf20Sopenharmony_ci *     without modification, are permitted provided that the following
128c2ecf20Sopenharmony_ci *     conditions are met:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci *      - Redistributions of source code must retain the above
158c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
168c2ecf20Sopenharmony_ci *        disclaimer.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
198c2ecf20Sopenharmony_ci *        copyright notice, this list of conditions and the following
208c2ecf20Sopenharmony_ci *        disclaimer in the documentation and/or other materials
218c2ecf20Sopenharmony_ci *        provided with the distribution.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
248c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
258c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
268c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
278c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
288c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
298c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
308c2ecf20Sopenharmony_ci * SOFTWARE.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#ifndef _CHELSIO_DEFS_H
338c2ecf20Sopenharmony_ci#define _CHELSIO_DEFS_H
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <linux/skbuff.h>
368c2ecf20Sopenharmony_ci#include <net/tcp.h>
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#include "t3cdev.h"
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#include "cxgb3_offload.h"
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci#define VALIDATE_TID 1
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/*
458c2ecf20Sopenharmony_ci * Map an ATID or STID to their entries in the corresponding TID tables.
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_cistatic inline union active_open_entry *atid2entry(const struct tid_info *t,
488c2ecf20Sopenharmony_ci						  unsigned int atid)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci	return &t->atid_tab[atid - t->atid_base];
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic inline union listen_entry *stid2entry(const struct tid_info *t,
548c2ecf20Sopenharmony_ci					     unsigned int stid)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	return &t->stid_tab[stid - t->stid_base];
578c2ecf20Sopenharmony_ci}
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci/*
608c2ecf20Sopenharmony_ci * Find the connection corresponding to a TID.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistatic inline struct t3c_tid_entry *lookup_tid(const struct tid_info *t,
638c2ecf20Sopenharmony_ci					       unsigned int tid)
648c2ecf20Sopenharmony_ci{
658c2ecf20Sopenharmony_ci	struct t3c_tid_entry *t3c_tid = tid < t->ntids ?
668c2ecf20Sopenharmony_ci	    &(t->tid_tab[tid]) : NULL;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	return (t3c_tid && t3c_tid->client) ? t3c_tid : NULL;
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci/*
728c2ecf20Sopenharmony_ci * Find the connection corresponding to a server TID.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_cistatic inline struct t3c_tid_entry *lookup_stid(const struct tid_info *t,
758c2ecf20Sopenharmony_ci						unsigned int tid)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	union listen_entry *e;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
808c2ecf20Sopenharmony_ci		return NULL;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	e = stid2entry(t, tid);
838c2ecf20Sopenharmony_ci	if ((void *)e->next >= (void *)t->tid_tab &&
848c2ecf20Sopenharmony_ci	    (void *)e->next < (void *)&t->atid_tab[t->natids])
858c2ecf20Sopenharmony_ci		return NULL;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	return &e->t3c_tid;
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/*
918c2ecf20Sopenharmony_ci * Find the connection corresponding to an active-open TID.
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistatic inline struct t3c_tid_entry *lookup_atid(const struct tid_info *t,
948c2ecf20Sopenharmony_ci						unsigned int tid)
958c2ecf20Sopenharmony_ci{
968c2ecf20Sopenharmony_ci	union active_open_entry *e;
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	if (tid < t->atid_base || tid >= t->atid_base + t->natids)
998c2ecf20Sopenharmony_ci		return NULL;
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	e = atid2entry(t, tid);
1028c2ecf20Sopenharmony_ci	if ((void *)e->next >= (void *)t->tid_tab &&
1038c2ecf20Sopenharmony_ci	    (void *)e->next < (void *)&t->atid_tab[t->natids])
1048c2ecf20Sopenharmony_ci		return NULL;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	return &e->t3c_tid;
1078c2ecf20Sopenharmony_ci}
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciint attach_t3cdev(struct t3cdev *dev);
1108c2ecf20Sopenharmony_civoid detach_t3cdev(struct t3cdev *dev);
1118c2ecf20Sopenharmony_ci#endif
112