blob: 515b94ff9080406caf9a0e1d327ca6d5f0160c85 [file] [log] [blame]
Varun Prakash85e42b02016-09-13 21:23:56 +05301/*
2 * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved.
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#ifndef __LIBCXGB_CM_H__
34#define __LIBCXGB_CM_H__
35
Varun Prakash44c6d062016-09-13 21:24:00 +053036
37#include <net/tcp.h>
38
Varun Prakash85e42b02016-09-13 21:23:56 +053039#include <cxgb4.h>
40#include <t4_msg.h>
Varun Prakash29fb6f42016-09-13 21:24:03 +053041#include <l2t.h>
Varun Prakash85e42b02016-09-13 21:23:56 +053042
43void
44cxgb_get_4tuple(struct cpl_pass_accept_req *, enum chip_type,
45 int *, __u8 *, __u8 *, __be16 *, __be16 *);
Varun Prakash804c2f32016-09-13 21:23:57 +053046struct dst_entry *
47cxgb_find_route(struct cxgb4_lld_info *,
48 struct net_device *(*)(struct net_device *),
49 __be32, __be32, __be16, __be16, u8);
Varun Prakash95554762016-09-13 21:23:58 +053050struct dst_entry *
51cxgb_find_route6(struct cxgb4_lld_info *,
52 struct net_device *(*)(struct net_device *),
53 __u8 *, __u8 *, __be16, __be16, u8, __u32);
Varun Prakashb65eef02016-09-13 21:23:59 +053054
55/* Returns whether a CPL status conveys negative advice.
56 */
57static inline bool cxgb_is_neg_adv(unsigned int status)
58{
59 return status == CPL_ERR_RTX_NEG_ADVICE ||
60 status == CPL_ERR_PERSIST_NEG_ADVICE ||
61 status == CPL_ERR_KEEPALV_NEG_ADVICE;
62}
Varun Prakash44c6d062016-09-13 21:24:00 +053063
64static inline void
65cxgb_best_mtu(const unsigned short *mtus, unsigned short mtu,
66 unsigned int *idx, int use_ts, int ipv6)
67{
68 unsigned short hdr_size = (ipv6 ?
69 sizeof(struct ipv6hdr) :
70 sizeof(struct iphdr)) +
71 sizeof(struct tcphdr) +
72 (use_ts ?
73 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
74 unsigned short data_size = mtu - hdr_size;
75
76 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
77}
Varun Prakashcc516702016-09-13 21:24:01 +053078
79static inline u32 cxgb_compute_wscale(u32 win)
80{
81 u32 wscale = 0;
82
83 while (wscale < 14 && (65535 << wscale) < win)
84 wscale++;
85 return wscale;
86}
Varun Prakasha1a23452016-09-13 21:24:02 +053087
88static inline void
89cxgb_mk_tid_release(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
90{
91 struct cpl_tid_release *req;
92
93 req = (struct cpl_tid_release *)__skb_put(skb, len);
94 memset(req, 0, len);
95
96 INIT_TP_WR(req, tid);
97 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
98 set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
99}
Varun Prakash29fb6f42016-09-13 21:24:03 +0530100
101static inline void
102cxgb_mk_close_con_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
103 void *handle, arp_err_handler_t handler)
104{
105 struct cpl_close_con_req *req;
106
107 req = (struct cpl_close_con_req *)__skb_put(skb, len);
108 memset(req, 0, len);
109
110 INIT_TP_WR(req, tid);
111 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
112 set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
113 t4_set_arp_err_handler(skb, handle, handler);
114}
Varun Prakasha7e1a972016-09-13 21:24:04 +0530115
116static inline void
117cxgb_mk_abort_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
118 void *handle, arp_err_handler_t handler)
119{
120 struct cpl_abort_req *req;
121
122 req = (struct cpl_abort_req *)__skb_put(skb, len);
123 memset(req, 0, len);
124
125 INIT_TP_WR(req, tid);
126 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
127 req->cmd = CPL_ABORT_SEND_RST;
128 set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
129 t4_set_arp_err_handler(skb, handle, handler);
130}
Varun Prakash052f4732016-09-13 21:24:05 +0530131
132static inline void
133cxgb_mk_abort_rpl(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
134{
135 struct cpl_abort_rpl *rpl;
136
137 rpl = (struct cpl_abort_rpl *)__skb_put(skb, len);
138 memset(rpl, 0, len);
139
140 INIT_TP_WR(rpl, tid);
141 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
142 rpl->cmd = CPL_ABORT_NO_RST;
143 set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
144}
Varun Prakash6e3b6fc2016-09-13 21:24:06 +0530145
146static inline void
147cxgb_mk_rx_data_ack(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
148 u32 credit_dack)
149{
150 struct cpl_rx_data_ack *req;
151
152 req = (struct cpl_rx_data_ack *)__skb_put(skb, len);
153 memset(req, 0, len);
154
155 INIT_TP_WR(req, tid);
156 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, tid));
157 req->credit_dack = cpu_to_be32(credit_dack);
158 set_wr_txq(skb, CPL_PRIORITY_ACK, chan);
159}
Varun Prakash85e42b02016-09-13 21:23:56 +0530160#endif