18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2016 Chelsio Communications, 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
338c2ecf20Sopenharmony_ci#ifndef __LIBCXGB_CM_H__
348c2ecf20Sopenharmony_ci#define __LIBCXGB_CM_H__
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include <net/tcp.h>
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#include <cxgb4.h>
408c2ecf20Sopenharmony_ci#include <t4_msg.h>
418c2ecf20Sopenharmony_ci#include <l2t.h>
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_civoid
448c2ecf20Sopenharmony_cicxgb_get_4tuple(struct cpl_pass_accept_req *, enum chip_type,
458c2ecf20Sopenharmony_ci		int *, __u8 *, __u8 *, __be16 *, __be16 *);
468c2ecf20Sopenharmony_cistruct dst_entry *
478c2ecf20Sopenharmony_cicxgb_find_route(struct cxgb4_lld_info *,
488c2ecf20Sopenharmony_ci		struct net_device *(*)(struct net_device *),
498c2ecf20Sopenharmony_ci		__be32, __be32, __be16,	__be16, u8);
508c2ecf20Sopenharmony_cistruct dst_entry *
518c2ecf20Sopenharmony_cicxgb_find_route6(struct cxgb4_lld_info *,
528c2ecf20Sopenharmony_ci		 struct net_device *(*)(struct net_device *),
538c2ecf20Sopenharmony_ci		 __u8 *, __u8 *, __be16, __be16, u8, __u32);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* Returns whether a CPL status conveys negative advice.
568c2ecf20Sopenharmony_ci */
578c2ecf20Sopenharmony_cistatic inline bool cxgb_is_neg_adv(unsigned int status)
588c2ecf20Sopenharmony_ci{
598c2ecf20Sopenharmony_ci	return status == CPL_ERR_RTX_NEG_ADVICE ||
608c2ecf20Sopenharmony_ci	       status == CPL_ERR_PERSIST_NEG_ADVICE ||
618c2ecf20Sopenharmony_ci	       status == CPL_ERR_KEEPALV_NEG_ADVICE;
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic inline void
658c2ecf20Sopenharmony_cicxgb_best_mtu(const unsigned short *mtus, unsigned short mtu,
668c2ecf20Sopenharmony_ci	      unsigned int *idx, int use_ts, int ipv6)
678c2ecf20Sopenharmony_ci{
688c2ecf20Sopenharmony_ci	unsigned short hdr_size = (ipv6 ?
698c2ecf20Sopenharmony_ci				   sizeof(struct ipv6hdr) :
708c2ecf20Sopenharmony_ci				   sizeof(struct iphdr)) +
718c2ecf20Sopenharmony_ci				  sizeof(struct tcphdr) +
728c2ecf20Sopenharmony_ci				  (use_ts ?
738c2ecf20Sopenharmony_ci				   round_up(TCPOLEN_TIMESTAMP, 4) : 0);
748c2ecf20Sopenharmony_ci	unsigned short data_size = mtu - hdr_size;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline u32 cxgb_compute_wscale(u32 win)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	u32 wscale = 0;
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	while (wscale < 14 && (65535 << wscale) < win)
848c2ecf20Sopenharmony_ci		wscale++;
858c2ecf20Sopenharmony_ci	return wscale;
868c2ecf20Sopenharmony_ci}
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic inline void
898c2ecf20Sopenharmony_cicxgb_mk_tid_release(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
908c2ecf20Sopenharmony_ci{
918c2ecf20Sopenharmony_ci	struct cpl_tid_release *req;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	req = __skb_put_zero(skb, len);
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci	INIT_TP_WR(req, tid);
968c2ecf20Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
978c2ecf20Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic inline void
1018c2ecf20Sopenharmony_cicxgb_mk_close_con_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
1028c2ecf20Sopenharmony_ci		      void *handle, arp_err_handler_t handler)
1038c2ecf20Sopenharmony_ci{
1048c2ecf20Sopenharmony_ci	struct cpl_close_con_req *req;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	req = __skb_put_zero(skb, len);
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	INIT_TP_WR(req, tid);
1098c2ecf20Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
1108c2ecf20Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
1118c2ecf20Sopenharmony_ci	t4_set_arp_err_handler(skb, handle, handler);
1128c2ecf20Sopenharmony_ci}
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistatic inline void
1158c2ecf20Sopenharmony_cicxgb_mk_abort_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
1168c2ecf20Sopenharmony_ci		  void *handle, arp_err_handler_t handler)
1178c2ecf20Sopenharmony_ci{
1188c2ecf20Sopenharmony_ci	struct cpl_abort_req *req;
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci	req = __skb_put_zero(skb, len);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	INIT_TP_WR(req, tid);
1238c2ecf20Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
1248c2ecf20Sopenharmony_ci	req->cmd = CPL_ABORT_SEND_RST;
1258c2ecf20Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
1268c2ecf20Sopenharmony_ci	t4_set_arp_err_handler(skb, handle, handler);
1278c2ecf20Sopenharmony_ci}
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_cistatic inline void
1308c2ecf20Sopenharmony_cicxgb_mk_abort_rpl(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	struct cpl_abort_rpl *rpl;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	rpl = __skb_put_zero(skb, len);
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	INIT_TP_WR(rpl, tid);
1378c2ecf20Sopenharmony_ci	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
1388c2ecf20Sopenharmony_ci	rpl->cmd = CPL_ABORT_NO_RST;
1398c2ecf20Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
1408c2ecf20Sopenharmony_ci}
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistatic inline void
1438c2ecf20Sopenharmony_cicxgb_mk_rx_data_ack(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
1448c2ecf20Sopenharmony_ci		    u32 credit_dack)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	struct cpl_rx_data_ack *req;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	req = __skb_put_zero(skb, len);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci	INIT_TP_WR(req, tid);
1518c2ecf20Sopenharmony_ci	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, tid));
1528c2ecf20Sopenharmony_ci	req->credit_dack = cpu_to_be32(credit_dack);
1538c2ecf20Sopenharmony_ci	set_wr_txq(skb, CPL_PRIORITY_ACK, chan);
1548c2ecf20Sopenharmony_ci}
1558c2ecf20Sopenharmony_ci#endif
156