xref: /openbmc/linux/drivers/net/ethernet/chelsio/libcxgb/libcxgb_cm.h (revision 3eb66e91a25497065c5322b1268cbc3953642227)
185e42b04SVarun Prakash /*
285e42b04SVarun Prakash  * Copyright (c) 2016 Chelsio Communications, Inc. All rights reserved.
385e42b04SVarun Prakash  *
485e42b04SVarun Prakash  * This software is available to you under a choice of one of two
585e42b04SVarun Prakash  * licenses.  You may choose to be licensed under the terms of the GNU
685e42b04SVarun Prakash  * General Public License (GPL) Version 2, available from the file
785e42b04SVarun Prakash  * COPYING in the main directory of this source tree, or the
885e42b04SVarun Prakash  * OpenIB.org BSD license below:
985e42b04SVarun Prakash  *
1085e42b04SVarun Prakash  *     Redistribution and use in source and binary forms, with or
1185e42b04SVarun Prakash  *     without modification, are permitted provided that the following
1285e42b04SVarun Prakash  *     conditions are met:
1385e42b04SVarun Prakash  *
1485e42b04SVarun Prakash  *      - Redistributions of source code must retain the above
1585e42b04SVarun Prakash  *	  copyright notice, this list of conditions and the following
1685e42b04SVarun Prakash  *	  disclaimer.
1785e42b04SVarun Prakash  *
1885e42b04SVarun Prakash  *      - Redistributions in binary form must reproduce the above
1985e42b04SVarun Prakash  *	  copyright notice, this list of conditions and the following
2085e42b04SVarun Prakash  *	  disclaimer in the documentation and/or other materials
2185e42b04SVarun Prakash  *	  provided with the distribution.
2285e42b04SVarun Prakash  *
2385e42b04SVarun Prakash  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2485e42b04SVarun Prakash  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2585e42b04SVarun Prakash  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2685e42b04SVarun Prakash  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2785e42b04SVarun Prakash  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2885e42b04SVarun Prakash  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2985e42b04SVarun Prakash  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3085e42b04SVarun Prakash  * SOFTWARE.
3185e42b04SVarun Prakash  */
3285e42b04SVarun Prakash 
3385e42b04SVarun Prakash #ifndef __LIBCXGB_CM_H__
3485e42b04SVarun Prakash #define __LIBCXGB_CM_H__
3585e42b04SVarun Prakash 
3644c6d069SVarun Prakash 
3744c6d069SVarun Prakash #include <net/tcp.h>
3844c6d069SVarun Prakash 
3985e42b04SVarun Prakash #include <cxgb4.h>
4085e42b04SVarun Prakash #include <t4_msg.h>
4129fb6f42SVarun Prakash #include <l2t.h>
4285e42b04SVarun Prakash 
4385e42b04SVarun Prakash void
4485e42b04SVarun Prakash cxgb_get_4tuple(struct cpl_pass_accept_req *, enum chip_type,
4585e42b04SVarun Prakash 		int *, __u8 *, __u8 *, __be16 *, __be16 *);
46804c2f3eSVarun Prakash struct dst_entry *
47804c2f3eSVarun Prakash cxgb_find_route(struct cxgb4_lld_info *,
48804c2f3eSVarun Prakash 		struct net_device *(*)(struct net_device *),
49804c2f3eSVarun Prakash 		__be32, __be32, __be16,	__be16, u8);
5095554761SVarun Prakash struct dst_entry *
5195554761SVarun Prakash cxgb_find_route6(struct cxgb4_lld_info *,
5295554761SVarun Prakash 		 struct net_device *(*)(struct net_device *),
5395554761SVarun Prakash 		 __u8 *, __u8 *, __be16, __be16, u8, __u32);
54b65eef0aSVarun Prakash 
55b65eef0aSVarun Prakash /* Returns whether a CPL status conveys negative advice.
56b65eef0aSVarun Prakash  */
cxgb_is_neg_adv(unsigned int status)57b65eef0aSVarun Prakash static inline bool cxgb_is_neg_adv(unsigned int status)
58b65eef0aSVarun Prakash {
59b65eef0aSVarun Prakash 	return status == CPL_ERR_RTX_NEG_ADVICE ||
60b65eef0aSVarun Prakash 	       status == CPL_ERR_PERSIST_NEG_ADVICE ||
61b65eef0aSVarun Prakash 	       status == CPL_ERR_KEEPALV_NEG_ADVICE;
62b65eef0aSVarun Prakash }
6344c6d069SVarun Prakash 
6444c6d069SVarun Prakash static inline void
cxgb_best_mtu(const unsigned short * mtus,unsigned short mtu,unsigned int * idx,int use_ts,int ipv6)6544c6d069SVarun Prakash cxgb_best_mtu(const unsigned short *mtus, unsigned short mtu,
6644c6d069SVarun Prakash 	      unsigned int *idx, int use_ts, int ipv6)
6744c6d069SVarun Prakash {
6844c6d069SVarun Prakash 	unsigned short hdr_size = (ipv6 ?
6944c6d069SVarun Prakash 				   sizeof(struct ipv6hdr) :
7044c6d069SVarun Prakash 				   sizeof(struct iphdr)) +
7144c6d069SVarun Prakash 				  sizeof(struct tcphdr) +
7244c6d069SVarun Prakash 				  (use_ts ?
7344c6d069SVarun Prakash 				   round_up(TCPOLEN_TIMESTAMP, 4) : 0);
7444c6d069SVarun Prakash 	unsigned short data_size = mtu - hdr_size;
7544c6d069SVarun Prakash 
7644c6d069SVarun Prakash 	cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
7744c6d069SVarun Prakash }
78cc516700SVarun Prakash 
cxgb_compute_wscale(u32 win)79cc516700SVarun Prakash static inline u32 cxgb_compute_wscale(u32 win)
80cc516700SVarun Prakash {
81cc516700SVarun Prakash 	u32 wscale = 0;
82cc516700SVarun Prakash 
83cc516700SVarun Prakash 	while (wscale < 14 && (65535 << wscale) < win)
84cc516700SVarun Prakash 		wscale++;
85cc516700SVarun Prakash 	return wscale;
86cc516700SVarun Prakash }
87a1a23454SVarun Prakash 
88a1a23454SVarun Prakash static inline void
cxgb_mk_tid_release(struct sk_buff * skb,u32 len,u32 tid,u16 chan)89a1a23454SVarun Prakash cxgb_mk_tid_release(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
90a1a23454SVarun Prakash {
91a1a23454SVarun Prakash 	struct cpl_tid_release *req;
92a1a23454SVarun Prakash 
93*a6a188e4SYueHaibing 	req = __skb_put_zero(skb, len);
94a1a23454SVarun Prakash 
95a1a23454SVarun Prakash 	INIT_TP_WR(req, tid);
96a1a23454SVarun Prakash 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
97a1a23454SVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
98a1a23454SVarun Prakash }
9929fb6f42SVarun Prakash 
10029fb6f42SVarun Prakash static inline void
cxgb_mk_close_con_req(struct sk_buff * skb,u32 len,u32 tid,u16 chan,void * handle,arp_err_handler_t handler)10129fb6f42SVarun Prakash cxgb_mk_close_con_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
10229fb6f42SVarun Prakash 		      void *handle, arp_err_handler_t handler)
10329fb6f42SVarun Prakash {
10429fb6f42SVarun Prakash 	struct cpl_close_con_req *req;
10529fb6f42SVarun Prakash 
106*a6a188e4SYueHaibing 	req = __skb_put_zero(skb, len);
10729fb6f42SVarun Prakash 
10829fb6f42SVarun Prakash 	INIT_TP_WR(req, tid);
10929fb6f42SVarun Prakash 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, tid));
11029fb6f42SVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
11129fb6f42SVarun Prakash 	t4_set_arp_err_handler(skb, handle, handler);
11229fb6f42SVarun Prakash }
113a7e1a97fSVarun Prakash 
114a7e1a97fSVarun Prakash static inline void
cxgb_mk_abort_req(struct sk_buff * skb,u32 len,u32 tid,u16 chan,void * handle,arp_err_handler_t handler)115a7e1a97fSVarun Prakash cxgb_mk_abort_req(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
116a7e1a97fSVarun Prakash 		  void *handle, arp_err_handler_t handler)
117a7e1a97fSVarun Prakash {
118a7e1a97fSVarun Prakash 	struct cpl_abort_req *req;
119a7e1a97fSVarun Prakash 
120*a6a188e4SYueHaibing 	req = __skb_put_zero(skb, len);
121a7e1a97fSVarun Prakash 
122a7e1a97fSVarun Prakash 	INIT_TP_WR(req, tid);
123a7e1a97fSVarun Prakash 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, tid));
124a7e1a97fSVarun Prakash 	req->cmd = CPL_ABORT_SEND_RST;
125a7e1a97fSVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
126a7e1a97fSVarun Prakash 	t4_set_arp_err_handler(skb, handle, handler);
127a7e1a97fSVarun Prakash }
128052f4731SVarun Prakash 
129052f4731SVarun Prakash static inline void
cxgb_mk_abort_rpl(struct sk_buff * skb,u32 len,u32 tid,u16 chan)130052f4731SVarun Prakash cxgb_mk_abort_rpl(struct sk_buff *skb, u32 len, u32 tid, u16 chan)
131052f4731SVarun Prakash {
132052f4731SVarun Prakash 	struct cpl_abort_rpl *rpl;
133052f4731SVarun Prakash 
134*a6a188e4SYueHaibing 	rpl = __skb_put_zero(skb, len);
135052f4731SVarun Prakash 
136052f4731SVarun Prakash 	INIT_TP_WR(rpl, tid);
137052f4731SVarun Prakash 	OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, tid));
138052f4731SVarun Prakash 	rpl->cmd = CPL_ABORT_NO_RST;
139052f4731SVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_DATA, chan);
140052f4731SVarun Prakash }
1416e3b6fc2SVarun Prakash 
1426e3b6fc2SVarun Prakash static inline void
cxgb_mk_rx_data_ack(struct sk_buff * skb,u32 len,u32 tid,u16 chan,u32 credit_dack)1436e3b6fc2SVarun Prakash cxgb_mk_rx_data_ack(struct sk_buff *skb, u32 len, u32 tid, u16 chan,
1446e3b6fc2SVarun Prakash 		    u32 credit_dack)
1456e3b6fc2SVarun Prakash {
1466e3b6fc2SVarun Prakash 	struct cpl_rx_data_ack *req;
1476e3b6fc2SVarun Prakash 
148*a6a188e4SYueHaibing 	req = __skb_put_zero(skb, len);
1496e3b6fc2SVarun Prakash 
1506e3b6fc2SVarun Prakash 	INIT_TP_WR(req, tid);
1516e3b6fc2SVarun Prakash 	OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK, tid));
1526e3b6fc2SVarun Prakash 	req->credit_dack = cpu_to_be32(credit_dack);
1536e3b6fc2SVarun Prakash 	set_wr_txq(skb, CPL_PRIORITY_ACK, chan);
1546e3b6fc2SVarun Prakash }
15585e42b04SVarun Prakash #endif
156