2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
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:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
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.
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
35 #include <linux/inet.h>
36 #include <linux/wait.h>
37 #include <linux/spinlock.h>
38 #include <linux/kref.h>
40 #include <rdma/ib_verbs.h>
41 #include <rdma/iw_cm.h>
43 #include "cxgb3_offload.h"
44 #include "iwch_provider.h"
46 #define MPA_KEY_REQ "MPA ID Req Frame"
47 #define MPA_KEY_REP "MPA ID Rep Frame"
49 #define MPA_MAX_PRIVATE_DATA 256
50 #define MPA_REV 0 /* XXX - amso1100 uses rev 0 ! */
51 #define MPA_REJECT 0x20
53 #define MPA_MARKERS 0x80
54 #define MPA_FLAGS_MASK 0xE0
56 #define put_ep(ep) { \
57 PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \
58 ep, atomic_read(&((ep)->kref.refcount))); \
59 WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \
60 kref_put(&((ep)->kref), __free_ep); \
63 #define get_ep(ep) { \
64 PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \
65 ep, atomic_read(&((ep)->kref.refcount))); \
66 kref_get(&((ep)->kref)); \
73 __be16 private_data_size
;
77 struct terminate_message
{
84 #define TERM_MAX_LENGTH (sizeof(struct terminate_message) + 2 + 18 + 28)
86 enum iwch_layers_types
{
90 RDMAP_LOCAL_CATA
= 0x00,
91 RDMAP_REMOTE_PROT
= 0x01,
92 RDMAP_REMOTE_OP
= 0x02,
93 DDP_LOCAL_CATA
= 0x00,
94 DDP_TAGGED_ERR
= 0x01,
95 DDP_UNTAGGED_ERR
= 0x02,
99 enum iwch_rdma_ecodes
{
100 RDMAP_INV_STAG
= 0x00,
101 RDMAP_BASE_BOUNDS
= 0x01,
102 RDMAP_ACC_VIOL
= 0x02,
103 RDMAP_STAG_NOT_ASSOC
= 0x03,
104 RDMAP_TO_WRAP
= 0x04,
105 RDMAP_INV_VERS
= 0x05,
106 RDMAP_INV_OPCODE
= 0x06,
107 RDMAP_STREAM_CATA
= 0x07,
108 RDMAP_GLOBAL_CATA
= 0x08,
109 RDMAP_CANT_INV_STAG
= 0x09,
110 RDMAP_UNSPECIFIED
= 0xff
113 enum iwch_ddp_ecodes
{
114 DDPT_INV_STAG
= 0x00,
115 DDPT_BASE_BOUNDS
= 0x01,
116 DDPT_STAG_NOT_ASSOC
= 0x02,
118 DDPT_INV_VERS
= 0x04,
120 DDPU_INV_MSN_NOBUF
= 0x02,
121 DDPU_INV_MSN_RANGE
= 0x03,
123 DDPU_MSG_TOOBIG
= 0x05,
127 enum iwch_mpa_ecodes
{
129 MPA_MARKER_ERR
= 0x03
148 PEER_ABORT_IN_PROGRESS
= 0,
149 ABORT_REQ_IN_PROGRESS
= 1,
150 RELEASE_RESOURCES
= 2,
154 struct iwch_ep_common
{
155 struct iw_cm_id
*cm_id
;
158 enum iwch_ep_state state
;
161 struct sockaddr_in local_addr
;
162 struct sockaddr_in remote_addr
;
163 wait_queue_head_t waitq
;
169 struct iwch_listen_ep
{
170 struct iwch_ep_common com
;
176 struct iwch_ep_common com
;
177 struct iwch_ep
*parent_ep
;
178 struct timer_list timer
;
183 struct l2t_entry
*l2t
;
184 struct dst_entry
*dst
;
185 struct sk_buff
*mpa_skb
;
186 struct iwch_mpa_attributes mpa_attr
;
187 unsigned int mpa_pkt_len
;
188 u8 mpa_pkt
[sizeof(struct mpa_message
) + MPA_MAX_PRIVATE_DATA
];
196 static inline struct iwch_ep
*to_ep(struct iw_cm_id
*cm_id
)
198 return cm_id
->provider_data
;
201 static inline struct iwch_listen_ep
*to_listen_ep(struct iw_cm_id
*cm_id
)
203 return cm_id
->provider_data
;
206 static inline int compute_wscale(int win
)
210 while (wscale
< 14 && (65535<<wscale
) < win
)
217 int iwch_connect(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
);
218 int iwch_create_listen(struct iw_cm_id
*cm_id
, int backlog
);
219 int iwch_destroy_listen(struct iw_cm_id
*cm_id
);
220 int iwch_reject_cr(struct iw_cm_id
*cm_id
, const void *pdata
, u8 pdata_len
);
221 int iwch_accept_cr(struct iw_cm_id
*cm_id
, struct iw_cm_conn_param
*conn_param
);
222 int iwch_ep_disconnect(struct iwch_ep
*ep
, int abrupt
, gfp_t gfp
);
223 int iwch_quiesce_tid(struct iwch_ep
*ep
);
224 int iwch_resume_tid(struct iwch_ep
*ep
);
225 void __free_ep(struct kref
*kref
);
226 void iwch_rearp(struct iwch_ep
*ep
);
227 int iwch_ep_redirect(void *ctx
, struct dst_entry
*old
, struct dst_entry
*new, struct l2t_entry
*l2t
);
229 int __init
iwch_cm_init(void);
230 void __exit
iwch_cm_term(void);
231 extern int peer2peer
;
233 #endif /* _IWCH_CM_H_ */