162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * This software is available to you under a choice of one of two
562306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
662306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
762306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
862306a36Sopenharmony_ci * OpenIB.org BSD license below:
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1162306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1262306a36Sopenharmony_ci *     conditions are met:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1562306a36Sopenharmony_ci *	  copyright notice, this list of conditions and the following
1662306a36Sopenharmony_ci *	  disclaimer.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
1962306a36Sopenharmony_ci *	  copyright notice, this list of conditions and the following
2062306a36Sopenharmony_ci *	  disclaimer in the documentation and/or other materials
2162306a36Sopenharmony_ci *	  provided with the distribution.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2462306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2562306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2662306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2762306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2862306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2962306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3062306a36Sopenharmony_ci * SOFTWARE.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#ifndef __LIBCXGB_CM_H__
3462306a36Sopenharmony_ci#define __LIBCXGB_CM_H__
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#include <net/tcp.h>
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#include <cxgb4.h>
4062306a36Sopenharmony_ci#include <t4_msg.h>
4162306a36Sopenharmony_ci#include <l2t.h>
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_civoid
4462306a36Sopenharmony_cicxgb_get_4tuple(struct cpl_pass_accept_req *, enum chip_type,
4562306a36Sopenharmony_ci		int *, __u8 *, __u8 *, __be16 *, __be16 *);
4662306a36Sopenharmony_cistruct dst_entry *
4762306a36Sopenharmony_cicxgb_find_route(struct cxgb4_lld_info *,
4862306a36Sopenharmony_ci		struct net_device *(*)(struct net_device *),
4962306a36Sopenharmony_ci		__be32, __be32, __be16,	__be16, u8);
5062306a36Sopenharmony_cistruct dst_entry *
5162306a36Sopenharmony_cicxgb_find_route6(struct cxgb4_lld_info *,
5262306a36Sopenharmony_ci		 struct net_device *(*)(struct net_device *),
5362306a36Sopenharmony_ci		 __u8 *, __u8 *, __be16, __be16, u8, __u32);
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* Returns whether a CPL status conveys negative advice.
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_cistatic inline bool cxgb_is_neg_adv(unsigned int status)
5862306a36Sopenharmony_ci{
5962306a36Sopenharmony_ci	return status == CPL_ERR_RTX_NEG_ADVICE ||
6062306a36Sopenharmony_ci	       status == CPL_ERR_PERSIST_NEG_ADVICE ||
6162306a36Sopenharmony_ci	       status == CPL_ERR_KEEPALV_NEG_ADVICE;
6262306a36Sopenharmony_ci}
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_cistatic inline void
6562306a36Sopenharmony_cicxgb_best_mtu(const unsigned short *mtus, unsigned short mtu,
6662306a36Sopenharmony_ci	      unsigned int *idx, int use_ts, int ipv6)
6762306a36Sopenharmony_ci{
6862306a36Sopenharmony_ci	unsigned short hdr_size = (ipv6 ?
6962306a36Sopenharmony_ci				   sizeof(struct ipv6hdr) :
7062306a36Sopenharmony_ci				   sizeof(struct iphdr)) +
7162306a36Sopenharmony_ci				  sizeof(struct tcphdr) +
7262306a36Sopenharmony_ci				  (use_ts ?
7362306a36Sopenharmony_ci				   round_up(TCPOLEN_TIMESTAMP, 4) : 0);
7462306a36Sopenharmony_ci	unsigned short data_size = mtu - hdr_size;
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
7762306a36Sopenharmony_ci}
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistatic inline u32 cxgb_compute_wscale(u32 win)
8062306a36Sopenharmony_ci{
8162306a36Sopenharmony_ci	u32 wscale = 0;
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci	while (wscale < 14 && (65535 << wscale) < win)
8462306a36Sopenharmony_ci		wscale++;
8562306a36Sopenharmony_ci	return wscale;
8662306a36Sopenharmony_ci}
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_cistatic inline void
8962306a36Sopenharmony_cicxgb_mk_tid_release(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
9062306a36Sopenharmony_ci{
9162306a36Sopenharmony_ci	struct cpl_tid_release *req;
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci	req = __skb_put_zero(skb, len);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	INIT_TP_WR(req, tid);
9662306a36Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
9762306a36Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
9862306a36Sopenharmony_ci}
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_cistatic inline void
10162306a36Sopenharmony_cicxgb_mk_close_con_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
10262306a36Sopenharmony_ci		      void *handle, arp_err_handler_t handler)
10362306a36Sopenharmony_ci{
10462306a36Sopenharmony_ci	struct cpl_close_con_req *req;
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci	req = __skb_put_zero(skb, len);
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	INIT_TP_WR(req, tid);
10962306a36Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
11062306a36Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
11162306a36Sopenharmony_ci	t4_set_arp_err_handler(skb, handle, handler);
11262306a36Sopenharmony_ci}
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_cistatic inline void
11562306a36Sopenharmony_cicxgb_mk_abort_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
11662306a36Sopenharmony_ci		  void *handle, arp_err_handler_t handler)
11762306a36Sopenharmony_ci{
11862306a36Sopenharmony_ci	struct cpl_abort_req *req;
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	req = __skb_put_zero(skb, len);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	INIT_TP_WR(req, tid);
12362306a36Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
12462306a36Sopenharmony_ci	req->cmd = CPL_ABORT_SEND_RST;
12562306a36Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
12662306a36Sopenharmony_ci	t4_set_arp_err_handler(skb, handle, handler);
12762306a36Sopenharmony_ci}
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_cistatic inline void
13062306a36Sopenharmony_cicxgb_mk_abort_rpl(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
13162306a36Sopenharmony_ci{
13262306a36Sopenharmony_ci	struct cpl_abort_rpl *rpl;
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci	rpl = __skb_put_zero(skb, len);
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	INIT_TP_WR(rpl, tid);
13762306a36Sopenharmony_ci	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
13862306a36Sopenharmony_ci	rpl->cmd = CPL_ABORT_NO_RST;
13962306a36Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
14062306a36Sopenharmony_ci}
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_cistatic inline void
14362306a36Sopenharmony_cicxgb_mk_rx_data_ack(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
14462306a36Sopenharmony_ci		    u32 credit_dack)
14562306a36Sopenharmony_ci{
14662306a36Sopenharmony_ci	struct cpl_rx_data_ack *req;
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci	req = __skb_put_zero(skb, len);
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci	INIT_TP_WR(req, tid);
15162306a36Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, tid));
15262306a36Sopenharmony_ci	req->credit_dack = cpu_to_be32(credit_dack);
15362306a36Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_ACK, chan);
15462306a36Sopenharmony_ci}
15562306a36Sopenharmony_ci#endif
156