xref: /linux/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h (revision 62370a4f346dda9a7026445016db5f8eddd533a5)
1f7917c00SJeff Kirsher /*
2f7917c00SJeff Kirsher  * This file is part of the Chelsio T4 Ethernet driver for Linux.
3f7917c00SJeff Kirsher  *
4578b46b9SRahul Lakkireddy  * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
5f7917c00SJeff Kirsher  *
6f7917c00SJeff Kirsher  * This software is available to you under a choice of one of two
7f7917c00SJeff Kirsher  * licenses.  You may choose to be licensed under the terms of the GNU
8f7917c00SJeff Kirsher  * General Public License (GPL) Version 2, available from the file
9f7917c00SJeff Kirsher  * COPYING in the main directory of this source tree, or the
10f7917c00SJeff Kirsher  * OpenIB.org BSD license below:
11f7917c00SJeff Kirsher  *
12f7917c00SJeff Kirsher  *     Redistribution and use in source and binary forms, with or
13f7917c00SJeff Kirsher  *     without modification, are permitted provided that the following
14f7917c00SJeff Kirsher  *     conditions are met:
15f7917c00SJeff Kirsher  *
16f7917c00SJeff Kirsher  *      - Redistributions of source code must retain the above
17f7917c00SJeff Kirsher  *        copyright notice, this list of conditions and the following
18f7917c00SJeff Kirsher  *        disclaimer.
19f7917c00SJeff Kirsher  *
20f7917c00SJeff Kirsher  *      - Redistributions in binary form must reproduce the above
21f7917c00SJeff Kirsher  *        copyright notice, this list of conditions and the following
22f7917c00SJeff Kirsher  *        disclaimer in the documentation and/or other materials
23f7917c00SJeff Kirsher  *        provided with the distribution.
24f7917c00SJeff Kirsher  *
25f7917c00SJeff Kirsher  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26f7917c00SJeff Kirsher  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27f7917c00SJeff Kirsher  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28f7917c00SJeff Kirsher  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29f7917c00SJeff Kirsher  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30f7917c00SJeff Kirsher  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31f7917c00SJeff Kirsher  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32f7917c00SJeff Kirsher  * SOFTWARE.
33f7917c00SJeff Kirsher  */
34f7917c00SJeff Kirsher 
3594cdb8bbSHariprasad Shenai #ifndef __CXGB4_ULD_H
3694cdb8bbSHariprasad Shenai #define __CXGB4_ULD_H
37f7917c00SJeff Kirsher 
38f7917c00SJeff Kirsher #include <linux/cache.h>
39f7917c00SJeff Kirsher #include <linux/spinlock.h>
40f7917c00SJeff Kirsher #include <linux/skbuff.h>
41793dad94SVipul Pandya #include <linux/inetdevice.h>
42f7917c00SJeff Kirsher #include <linux/atomic.h>
4327999805SHariprasad S #include "cxgb4.h"
44f7917c00SJeff Kirsher 
450fbc81b3SHariprasad Shenai #define MAX_ULD_QSETS 16
460fbc81b3SHariprasad Shenai 
47f7917c00SJeff Kirsher /* CPL message priority levels */
48f7917c00SJeff Kirsher enum {
49f7917c00SJeff Kirsher 	CPL_PRIORITY_DATA     = 0,  /* data messages */
50f7917c00SJeff Kirsher 	CPL_PRIORITY_SETUP    = 1,  /* connection setup messages */
51f7917c00SJeff Kirsher 	CPL_PRIORITY_TEARDOWN = 0,  /* connection teardown messages */
52f7917c00SJeff Kirsher 	CPL_PRIORITY_LISTEN   = 1,  /* listen start/stop messages */
53f7917c00SJeff Kirsher 	CPL_PRIORITY_ACK      = 1,  /* RX ACK messages */
54f7917c00SJeff Kirsher 	CPL_PRIORITY_CONTROL  = 1   /* control messages */
55f7917c00SJeff Kirsher };
56f7917c00SJeff Kirsher 
57f7917c00SJeff Kirsher #define INIT_TP_WR(w, tid) do { \
58e2ac9628SHariprasad Shenai 	(w)->wr.wr_hi = htonl(FW_WR_OP_V(FW_TP_WR) | \
59e2ac9628SHariprasad Shenai 			      FW_WR_IMMDLEN_V(sizeof(*w) - sizeof(w->wr))); \
60e2ac9628SHariprasad Shenai 	(w)->wr.wr_mid = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*w), 16)) | \
61e2ac9628SHariprasad Shenai 			       FW_WR_FLOWID_V(tid)); \
62f7917c00SJeff Kirsher 	(w)->wr.wr_lo = cpu_to_be64(0); \
63f7917c00SJeff Kirsher } while (0)
64f7917c00SJeff Kirsher 
65f7917c00SJeff Kirsher #define INIT_TP_WR_CPL(w, cpl, tid) do { \
66f7917c00SJeff Kirsher 	INIT_TP_WR(w, tid); \
67f7917c00SJeff Kirsher 	OPCODE_TID(w) = htonl(MK_OPCODE_TID(cpl, tid)); \
68f7917c00SJeff Kirsher } while (0)
69f7917c00SJeff Kirsher 
70f7917c00SJeff Kirsher #define INIT_ULPTX_WR(w, wrlen, atomic, tid) do { \
71e2ac9628SHariprasad Shenai 	(w)->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) | \
72e2ac9628SHariprasad Shenai 			      FW_WR_ATOMIC_V(atomic)); \
73e2ac9628SHariprasad Shenai 	(w)->wr.wr_mid = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(wrlen, 16)) | \
74e2ac9628SHariprasad Shenai 			       FW_WR_FLOWID_V(tid)); \
75f7917c00SJeff Kirsher 	(w)->wr.wr_lo = cpu_to_be64(0); \
76f7917c00SJeff Kirsher } while (0)
77f7917c00SJeff Kirsher 
78f7917c00SJeff Kirsher /* Special asynchronous notification message */
79f7917c00SJeff Kirsher #define CXGB4_MSG_AN ((void *)1)
80ab677ff4SHariprasad Shenai #define TX_ULD(uld)(((uld) != CXGB4_ULD_CRYPTO) ? CXGB4_TX_OFLD :\
81ab677ff4SHariprasad Shenai 		      CXGB4_TX_CRYPTO)
82f7917c00SJeff Kirsher 
83f7917c00SJeff Kirsher struct serv_entry {
84f7917c00SJeff Kirsher 	void *data;
85f7917c00SJeff Kirsher };
86f7917c00SJeff Kirsher 
87f7917c00SJeff Kirsher union aopen_entry {
88f7917c00SJeff Kirsher 	void *data;
89f7917c00SJeff Kirsher 	union aopen_entry *next;
90f7917c00SJeff Kirsher };
91f7917c00SJeff Kirsher 
92ab0367eaSRahul Lakkireddy struct eotid_entry {
93ab0367eaSRahul Lakkireddy 	void *data;
94ab0367eaSRahul Lakkireddy };
95ab0367eaSRahul Lakkireddy 
96f7917c00SJeff Kirsher /*
97f7917c00SJeff Kirsher  * Holds the size, base address, free list start, etc of the TID, server TID,
98f7917c00SJeff Kirsher  * and active-open TID tables.  The tables themselves are allocated dynamically.
99f7917c00SJeff Kirsher  */
100f7917c00SJeff Kirsher struct tid_info {
101f7917c00SJeff Kirsher 	void **tid_tab;
10259437d78SShahjada Abul Husain 	unsigned int tid_base;
103f7917c00SJeff Kirsher 	unsigned int ntids;
104f7917c00SJeff Kirsher 
105f7917c00SJeff Kirsher 	struct serv_entry *stid_tab;
106f7917c00SJeff Kirsher 	unsigned long *stid_bmap;
107f7917c00SJeff Kirsher 	unsigned int nstids;
108f7917c00SJeff Kirsher 	unsigned int stid_base;
1099a1bb9f6SHariprasad Shenai 	unsigned int hash_base;
110f7917c00SJeff Kirsher 
111f7917c00SJeff Kirsher 	union aopen_entry *atid_tab;
112f7917c00SJeff Kirsher 	unsigned int natids;
113f2b7e78dSVipul Pandya 	unsigned int atid_base;
114f7917c00SJeff Kirsher 
115c2193999SShahjada Abul Husain 	struct filter_entry *hpftid_tab;
116c2193999SShahjada Abul Husain 	unsigned long *hpftid_bmap;
117c2193999SShahjada Abul Husain 	unsigned int nhpftids;
118c2193999SShahjada Abul Husain 	unsigned int hpftid_base;
119c2193999SShahjada Abul Husain 
120f2b7e78dSVipul Pandya 	struct filter_entry *ftid_tab;
121578b46b9SRahul Lakkireddy 	unsigned long *ftid_bmap;
122f7917c00SJeff Kirsher 	unsigned int nftids;
123f7917c00SJeff Kirsher 	unsigned int ftid_base;
124636f9d37SVipul Pandya 	unsigned int aftid_base;
125636f9d37SVipul Pandya 	unsigned int aftid_end;
1269a4da2cdSVipul Pandya 	/* Server filter region */
1279a4da2cdSVipul Pandya 	unsigned int sftid_base;
1289a4da2cdSVipul Pandya 	unsigned int nsftids;
129f7917c00SJeff Kirsher 
130f7917c00SJeff Kirsher 	spinlock_t atid_lock ____cacheline_aligned_in_smp;
131f7917c00SJeff Kirsher 	union aopen_entry *afree;
132f7917c00SJeff Kirsher 	unsigned int atids_in_use;
133f7917c00SJeff Kirsher 
134f7917c00SJeff Kirsher 	spinlock_t stid_lock;
135f7917c00SJeff Kirsher 	unsigned int stids_in_use;
1361dec4cecSGanesh Goudar 	unsigned int v6_stids_in_use;
1372248b293SHariprasad Shenai 	unsigned int sftids_in_use;
138f7917c00SJeff Kirsher 
139ab0367eaSRahul Lakkireddy 	/* ETHOFLD range */
140ab0367eaSRahul Lakkireddy 	struct eotid_entry *eotid_tab;
141ab0367eaSRahul Lakkireddy 	unsigned long *eotid_bmap;
142ab0367eaSRahul Lakkireddy 	unsigned int eotid_base;
143ab0367eaSRahul Lakkireddy 	unsigned int neotids;
144ab0367eaSRahul Lakkireddy 
1459a1bb9f6SHariprasad Shenai 	/* TIDs in the TCAM */
146f7917c00SJeff Kirsher 	atomic_t tids_in_use;
1479a1bb9f6SHariprasad Shenai 	/* TIDs in the HASH */
1489a1bb9f6SHariprasad Shenai 	atomic_t hash_tids_in_use;
1491dec4cecSGanesh Goudar 	atomic_t conns_in_use;
150578b46b9SRahul Lakkireddy 	/* lock for setting/clearing filter bitmap */
151578b46b9SRahul Lakkireddy 	spinlock_t ftid_lock;
152f7917c00SJeff Kirsher };
153f7917c00SJeff Kirsher 
154f7917c00SJeff Kirsher static inline void *lookup_tid(const struct tid_info *t, unsigned int tid)
155f7917c00SJeff Kirsher {
15659437d78SShahjada Abul Husain 	tid -= t->tid_base;
157f7917c00SJeff Kirsher 	return tid < t->ntids ? t->tid_tab[tid] : NULL;
158f7917c00SJeff Kirsher }
159f7917c00SJeff Kirsher 
16059437d78SShahjada Abul Husain static inline bool tid_out_of_range(const struct tid_info *t, unsigned int tid)
16159437d78SShahjada Abul Husain {
16259437d78SShahjada Abul Husain 	return ((tid - t->tid_base) >= t->ntids);
16359437d78SShahjada Abul Husain }
16459437d78SShahjada Abul Husain 
165f7917c00SJeff Kirsher static inline void *lookup_atid(const struct tid_info *t, unsigned int atid)
166f7917c00SJeff Kirsher {
167f7917c00SJeff Kirsher 	return atid < t->natids ? t->atid_tab[atid].data : NULL;
168f7917c00SJeff Kirsher }
169f7917c00SJeff Kirsher 
170f7917c00SJeff Kirsher static inline void *lookup_stid(const struct tid_info *t, unsigned int stid)
171f7917c00SJeff Kirsher {
172470c60c4SKumar Sanghvi 	/* Is it a server filter TID? */
173470c60c4SKumar Sanghvi 	if (t->nsftids && (stid >= t->sftid_base)) {
174470c60c4SKumar Sanghvi 		stid -= t->sftid_base;
175470c60c4SKumar Sanghvi 		stid += t->nstids;
176470c60c4SKumar Sanghvi 	} else {
177f7917c00SJeff Kirsher 		stid -= t->stid_base;
178470c60c4SKumar Sanghvi 	}
179470c60c4SKumar Sanghvi 
180dca4faebSVipul Pandya 	return stid < (t->nstids + t->nsftids) ? t->stid_tab[stid].data : NULL;
181f7917c00SJeff Kirsher }
182f7917c00SJeff Kirsher 
183f7917c00SJeff Kirsher static inline void cxgb4_insert_tid(struct tid_info *t, void *data,
1841dec4cecSGanesh Goudar 				    unsigned int tid, unsigned short family)
185f7917c00SJeff Kirsher {
18659437d78SShahjada Abul Husain 	t->tid_tab[tid - t->tid_base] = data;
1871dec4cecSGanesh Goudar 	if (t->hash_base && (tid >= t->hash_base)) {
1881dec4cecSGanesh Goudar 		if (family == AF_INET6)
1891dec4cecSGanesh Goudar 			atomic_add(2, &t->hash_tids_in_use);
1901dec4cecSGanesh Goudar 		else
1919a1bb9f6SHariprasad Shenai 			atomic_inc(&t->hash_tids_in_use);
1921dec4cecSGanesh Goudar 	} else {
1931dec4cecSGanesh Goudar 		if (family == AF_INET6)
1941dec4cecSGanesh Goudar 			atomic_add(2, &t->tids_in_use);
1959a1bb9f6SHariprasad Shenai 		else
196f7917c00SJeff Kirsher 			atomic_inc(&t->tids_in_use);
197f7917c00SJeff Kirsher 	}
1981dec4cecSGanesh Goudar 	atomic_inc(&t->conns_in_use);
1991dec4cecSGanesh Goudar }
200f7917c00SJeff Kirsher 
201b1396c2bSRahul Lakkireddy static inline struct eotid_entry *cxgb4_lookup_eotid(struct tid_info *t,
202b1396c2bSRahul Lakkireddy 						     u32 eotid)
203b1396c2bSRahul Lakkireddy {
204b1396c2bSRahul Lakkireddy 	return eotid < t->neotids ? &t->eotid_tab[eotid] : NULL;
205b1396c2bSRahul Lakkireddy }
206b1396c2bSRahul Lakkireddy 
207b1396c2bSRahul Lakkireddy static inline int cxgb4_get_free_eotid(struct tid_info *t)
208b1396c2bSRahul Lakkireddy {
209b1396c2bSRahul Lakkireddy 	int eotid;
210b1396c2bSRahul Lakkireddy 
211b1396c2bSRahul Lakkireddy 	eotid = find_first_zero_bit(t->eotid_bmap, t->neotids);
212b1396c2bSRahul Lakkireddy 	if (eotid >= t->neotids)
213b1396c2bSRahul Lakkireddy 		eotid = -1;
214b1396c2bSRahul Lakkireddy 
215b1396c2bSRahul Lakkireddy 	return eotid;
216b1396c2bSRahul Lakkireddy }
217b1396c2bSRahul Lakkireddy 
218b1396c2bSRahul Lakkireddy static inline void cxgb4_alloc_eotid(struct tid_info *t, u32 eotid, void *data)
219b1396c2bSRahul Lakkireddy {
220b1396c2bSRahul Lakkireddy 	set_bit(eotid, t->eotid_bmap);
221b1396c2bSRahul Lakkireddy 	t->eotid_tab[eotid].data = data;
222b1396c2bSRahul Lakkireddy }
223b1396c2bSRahul Lakkireddy 
224b1396c2bSRahul Lakkireddy static inline void cxgb4_free_eotid(struct tid_info *t, u32 eotid)
225b1396c2bSRahul Lakkireddy {
226b1396c2bSRahul Lakkireddy 	clear_bit(eotid, t->eotid_bmap);
227b1396c2bSRahul Lakkireddy 	t->eotid_tab[eotid].data = NULL;
228b1396c2bSRahul Lakkireddy }
229b1396c2bSRahul Lakkireddy 
230f7917c00SJeff Kirsher int cxgb4_alloc_atid(struct tid_info *t, void *data);
231f7917c00SJeff Kirsher int cxgb4_alloc_stid(struct tid_info *t, int family, void *data);
232dca4faebSVipul Pandya int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data);
233f7917c00SJeff Kirsher void cxgb4_free_atid(struct tid_info *t, unsigned int atid);
234f7917c00SJeff Kirsher void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family);
2351dec4cecSGanesh Goudar void cxgb4_remove_tid(struct tid_info *t, unsigned int qid, unsigned int tid,
2361dec4cecSGanesh Goudar 		      unsigned short family);
237f7917c00SJeff Kirsher struct in6_addr;
238f7917c00SJeff Kirsher 
239f7917c00SJeff Kirsher int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
240793dad94SVipul Pandya 			__be32 sip, __be16 sport, __be16 vlan,
241793dad94SVipul Pandya 			unsigned int queue);
24280f40c1fSVipul Pandya int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
24380f40c1fSVipul Pandya 			 const struct in6_addr *sip, __be16 sport,
24480f40c1fSVipul Pandya 			 unsigned int queue);
24580f40c1fSVipul Pandya int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
24680f40c1fSVipul Pandya 			unsigned int queue, bool ipv6);
247dca4faebSVipul Pandya int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
248793dad94SVipul Pandya 			       __be32 sip, __be16 sport, __be16 vlan,
249793dad94SVipul Pandya 			       unsigned int queue,
250793dad94SVipul Pandya 			       unsigned char port, unsigned char mask);
251dca4faebSVipul Pandya int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
252dca4faebSVipul Pandya 			       unsigned int queue, bool ipv6);
253a3e3b285SAnish Bhatt 
254578b46b9SRahul Lakkireddy /* Filter operation context to allow callers of cxgb4_set_filter() and
255578b46b9SRahul Lakkireddy  * cxgb4_del_filter() to wait for an asynchronous completion.
256578b46b9SRahul Lakkireddy  */
257578b46b9SRahul Lakkireddy struct filter_ctx {
258578b46b9SRahul Lakkireddy 	struct completion completion;	/* completion rendezvous */
259578b46b9SRahul Lakkireddy 	void *closure;			/* caller's opaque information */
260578b46b9SRahul Lakkireddy 	int result;			/* result of operation */
261578b46b9SRahul Lakkireddy 	u32 tid;			/* to store tid */
262578b46b9SRahul Lakkireddy };
263578b46b9SRahul Lakkireddy 
264578b46b9SRahul Lakkireddy struct ch_filter_specification;
265578b46b9SRahul Lakkireddy 
26662488e4bSKumar Sanghvi int cxgb4_get_free_ftid(struct net_device *dev, int family);
267578b46b9SRahul Lakkireddy int __cxgb4_set_filter(struct net_device *dev, int filter_id,
268578b46b9SRahul Lakkireddy 		       struct ch_filter_specification *fs,
269578b46b9SRahul Lakkireddy 		       struct filter_ctx *ctx);
270578b46b9SRahul Lakkireddy int __cxgb4_del_filter(struct net_device *dev, int filter_id,
2713b0b3beeSKumar Sanghvi 		       struct ch_filter_specification *fs,
272578b46b9SRahul Lakkireddy 		       struct filter_ctx *ctx);
273578b46b9SRahul Lakkireddy int cxgb4_set_filter(struct net_device *dev, int filter_id,
274578b46b9SRahul Lakkireddy 		     struct ch_filter_specification *fs);
2753b0b3beeSKumar Sanghvi int cxgb4_del_filter(struct net_device *dev, int filter_id,
2763b0b3beeSKumar Sanghvi 		     struct ch_filter_specification *fs);
277e0f911c8SKumar Sanghvi int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
2789d922d4bSKumar Sanghvi 			      u64 *hitcnt, u64 *bytecnt, bool hash);
279578b46b9SRahul Lakkireddy 
280f7917c00SJeff Kirsher static inline void set_wr_txq(struct sk_buff *skb, int prio, int queue)
281f7917c00SJeff Kirsher {
282f7917c00SJeff Kirsher 	skb_set_queue_mapping(skb, (queue << 1) | prio);
283f7917c00SJeff Kirsher }
284f7917c00SJeff Kirsher 
285f7917c00SJeff Kirsher enum cxgb4_uld {
2860fbc81b3SHariprasad Shenai 	CXGB4_ULD_INIT,
287f7917c00SJeff Kirsher 	CXGB4_ULD_RDMA,
288f7917c00SJeff Kirsher 	CXGB4_ULD_ISCSI,
2892fddfb81SVarun Prakash 	CXGB4_ULD_ISCSIT,
2900fbc81b3SHariprasad Shenai 	CXGB4_ULD_CRYPTO,
291e383f248SAtul Gupta 	CXGB4_ULD_TLS,
292f7917c00SJeff Kirsher 	CXGB4_ULD_MAX
293f7917c00SJeff Kirsher };
294f7917c00SJeff Kirsher 
295ab677ff4SHariprasad Shenai enum cxgb4_tx_uld {
296ab677ff4SHariprasad Shenai 	CXGB4_TX_OFLD,
297ab677ff4SHariprasad Shenai 	CXGB4_TX_CRYPTO,
298ab677ff4SHariprasad Shenai 	CXGB4_TX_MAX
299ab677ff4SHariprasad Shenai };
300ab677ff4SHariprasad Shenai 
301ab677ff4SHariprasad Shenai enum cxgb4_txq_type {
302ab677ff4SHariprasad Shenai 	CXGB4_TXQ_ETH,
303ab677ff4SHariprasad Shenai 	CXGB4_TXQ_ULD,
304ab677ff4SHariprasad Shenai 	CXGB4_TXQ_CTRL,
305ab677ff4SHariprasad Shenai 	CXGB4_TXQ_MAX
306ab677ff4SHariprasad Shenai };
307ab677ff4SHariprasad Shenai 
308f7917c00SJeff Kirsher enum cxgb4_state {
309f7917c00SJeff Kirsher 	CXGB4_STATE_UP,
310f7917c00SJeff Kirsher 	CXGB4_STATE_START_RECOVERY,
311f7917c00SJeff Kirsher 	CXGB4_STATE_DOWN,
3128b7372c1SGanesh Goudar 	CXGB4_STATE_DETACH,
3138b7372c1SGanesh Goudar 	CXGB4_STATE_FATAL_ERROR
314f7917c00SJeff Kirsher };
315f7917c00SJeff Kirsher 
316881806bcSVipul Pandya enum cxgb4_control {
317881806bcSVipul Pandya 	CXGB4_CONTROL_DB_FULL,
318881806bcSVipul Pandya 	CXGB4_CONTROL_DB_EMPTY,
319881806bcSVipul Pandya 	CXGB4_CONTROL_DB_DROP,
320881806bcSVipul Pandya };
321881806bcSVipul Pandya 
322f7917c00SJeff Kirsher struct pci_dev;
323f7917c00SJeff Kirsher struct l2t_data;
324f7917c00SJeff Kirsher struct net_device;
325f7917c00SJeff Kirsher struct pkt_gl;
326f7917c00SJeff Kirsher struct tp_tcp_stats;
3272337ba42SVarun Prakash struct t4_lro_mgr;
328f7917c00SJeff Kirsher 
329f7917c00SJeff Kirsher struct cxgb4_range {
330f7917c00SJeff Kirsher 	unsigned int start;
331f7917c00SJeff Kirsher 	unsigned int size;
332f7917c00SJeff Kirsher };
333f7917c00SJeff Kirsher 
334f7917c00SJeff Kirsher struct cxgb4_virt_res {                      /* virtualized HW resources */
335f7917c00SJeff Kirsher 	struct cxgb4_range ddp;
336f7917c00SJeff Kirsher 	struct cxgb4_range iscsi;
337f7917c00SJeff Kirsher 	struct cxgb4_range stag;
338f7917c00SJeff Kirsher 	struct cxgb4_range rq;
339c68644efSRaju Rangoju 	struct cxgb4_range srq;
340f7917c00SJeff Kirsher 	struct cxgb4_range pbl;
341f7917c00SJeff Kirsher 	struct cxgb4_range qp;
342f7917c00SJeff Kirsher 	struct cxgb4_range cq;
343f7917c00SJeff Kirsher 	struct cxgb4_range ocq;
344e383f248SAtul Gupta 	struct cxgb4_range key;
34572a56ca9SHarsh Jain 	unsigned int ncrypto_fc;
346a248384eSVarun Prakash 	struct cxgb4_range ppod_edram;
347f7917c00SJeff Kirsher };
348f7917c00SJeff Kirsher 
349ee0863baSHarsh Jain struct chcr_stats_debug {
350ee0863baSHarsh Jain 	atomic_t cipher_rqst;
351ee0863baSHarsh Jain 	atomic_t digest_rqst;
352ee0863baSHarsh Jain 	atomic_t aead_rqst;
353ee0863baSHarsh Jain 	atomic_t complete;
354ee0863baSHarsh Jain 	atomic_t error;
355ee0863baSHarsh Jain 	atomic_t fallback;
356a6ec572bSAtul Gupta 	atomic_t ipsec_cnt;
357e383f248SAtul Gupta 	atomic_t tls_pdu_tx;
358e383f248SAtul Gupta 	atomic_t tls_pdu_rx;
359e383f248SAtul Gupta 	atomic_t tls_key;
360*62370a4fSRohit Maheshwari #ifdef CONFIG_CHELSIO_TLS_DEVICE
361*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_connection_open;
362*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_connection_fail;
363*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_connection_close;
364*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_send_records;
365*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_end_pkts;
366*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_start_pkts;
367*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_middle_pkts;
368*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_retransmit_pkts;
369*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_complete_pkts;
370*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_trimmed_pkts;
371*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_encrypted_packets;
372*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_encrypted_bytes;
373*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_ctx;
374*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_ooo;
375*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_skip_no_sync_data;
376*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_drop_no_sync_data;
377*62370a4fSRohit Maheshwari 	atomic64_t ktls_tx_drop_bypass_req;
378*62370a4fSRohit Maheshwari 
379*62370a4fSRohit Maheshwari #endif
380ee0863baSHarsh Jain };
381ee0863baSHarsh Jain 
382f7917c00SJeff Kirsher #define OCQ_WIN_OFFSET(pdev, vres) \
383f7917c00SJeff Kirsher 	(pci_resource_len((pdev), 2) - roundup_pow_of_two((vres)->ocq.size))
384f7917c00SJeff Kirsher 
385f7917c00SJeff Kirsher /*
386f7917c00SJeff Kirsher  * Block of information the LLD provides to ULDs attaching to a device.
387f7917c00SJeff Kirsher  */
388f7917c00SJeff Kirsher struct cxgb4_lld_info {
389f7917c00SJeff Kirsher 	struct pci_dev *pdev;                /* associated PCI device */
390f7917c00SJeff Kirsher 	struct l2t_data *l2t;                /* L2 table */
391f7917c00SJeff Kirsher 	struct tid_info *tids;               /* TID table */
392f7917c00SJeff Kirsher 	struct net_device **ports;           /* device ports */
393f7917c00SJeff Kirsher 	const struct cxgb4_virt_res *vr;     /* assorted HW resources */
394f7917c00SJeff Kirsher 	const unsigned short *mtus;          /* MTU table */
395f7917c00SJeff Kirsher 	const unsigned short *rxq_ids;       /* the ULD's Rx queue ids */
396cf38be6dSHariprasad Shenai 	const unsigned short *ciq_ids;       /* the ULD's concentrator IQ ids */
397f7917c00SJeff Kirsher 	unsigned short nrxq;                 /* # of Rx queues */
398f7917c00SJeff Kirsher 	unsigned short ntxq;                 /* # of Tx queues */
399cf38be6dSHariprasad Shenai 	unsigned short nciq;		     /* # of concentrator IQ */
400f7917c00SJeff Kirsher 	unsigned char nchan:4;               /* # of channels */
401f7917c00SJeff Kirsher 	unsigned char nports:4;              /* # of ports */
402f7917c00SJeff Kirsher 	unsigned char wr_cred;               /* WR 16-byte credits */
403f7917c00SJeff Kirsher 	unsigned char adapter_type;          /* type of adapter */
404f7917c00SJeff Kirsher 	unsigned char fw_api_ver;            /* FW API version */
405a6ec572bSAtul Gupta 	unsigned char crypto;                /* crypto support */
406f7917c00SJeff Kirsher 	unsigned int fw_vers;                /* FW version */
407f7917c00SJeff Kirsher 	unsigned int iscsi_iolen;            /* iSCSI max I/O length */
4087730b4c7SHariprasad Shenai 	unsigned int cclk_ps;                /* Core clock period in psec */
409f7917c00SJeff Kirsher 	unsigned short udb_density;          /* # of user DB/page */
410f7917c00SJeff Kirsher 	unsigned short ucq_density;          /* # of user CQs/page */
411fc4144e7SRaju Rangoju 	unsigned int sge_host_page_size;     /* SGE host page size */
412dca4faebSVipul Pandya 	unsigned short filt_mode;            /* filter optional components */
413dca4faebSVipul Pandya 	unsigned short tx_modq[NCHAN];       /* maps each tx channel to a */
414dca4faebSVipul Pandya 					     /* scheduler queue */
415f7917c00SJeff Kirsher 	void __iomem *gts_reg;               /* address of GTS register */
416f7917c00SJeff Kirsher 	void __iomem *db_reg;                /* address of kernel doorbell */
4173069ee9bSVipul Pandya 	int dbfifo_int_thresh;		     /* doorbell fifo int threshold */
41804e10e21SHariprasad Shenai 	unsigned int sge_ingpadboundary;     /* SGE ingress padding boundary */
41904e10e21SHariprasad Shenai 	unsigned int sge_egrstatuspagesize;  /* SGE egress status page size */
420dca4faebSVipul Pandya 	unsigned int sge_pktshift;           /* Padding between CPL and */
421dca4faebSVipul Pandya 					     /*	packet data */
42235b1de55SHariprasad Shenai 	unsigned int pf;		     /* Physical Function we're using */
423dca4faebSVipul Pandya 	bool enable_fw_ofld_conn;            /* Enable connection through fw */
424dca4faebSVipul Pandya 					     /* WR */
4254c2c5763SHariprasad Shenai 	unsigned int max_ordird_qp;          /* Max ORD/IRD depth per RDMA QP */
4264c2c5763SHariprasad Shenai 	unsigned int max_ird_adapter;        /* Max IRD memory per adapter */
4271ac0f095SKumar Sanghvi 	bool ulptx_memwrite_dsgl;            /* use of T5 DSGL allowed */
4287714cb9eSVarun Prakash 	unsigned int iscsi_tagmask;	     /* iscsi ddp tag mask */
4297714cb9eSVarun Prakash 	unsigned int iscsi_pgsz_order;	     /* iscsi ddp page size orders */
4307714cb9eSVarun Prakash 	unsigned int iscsi_llimit;	     /* chip's iscsi region llimit */
43114c19b17SHarsh Jain 	unsigned int ulp_crypto;             /* crypto lookaside support */
4327714cb9eSVarun Prakash 	void **iscsi_ppm;		     /* iscsi page pod manager */
433982b81ebSHariprasad Shenai 	int nodeid;			     /* device numa node id */
434086de575SSteve Wise 	bool fr_nsmr_tpte_wr_support;	     /* FW supports FR_NSMR_TPTE_WR */
43543db9296SRaju Rangoju 	bool write_w_imm_support;         /* FW supports WRITE_WITH_IMMEDIATE */
436f3910c62SRaju Rangoju 	bool write_cmpl_support;             /* FW supports WRITE_CMPL WR */
437f7917c00SJeff Kirsher };
438f7917c00SJeff Kirsher 
439f7917c00SJeff Kirsher struct cxgb4_uld_info {
4401a91649fSArnd Bergmann 	char name[IFNAMSIZ];
44194cdb8bbSHariprasad Shenai 	void *handle;
44294cdb8bbSHariprasad Shenai 	unsigned int nrxq;
44394cdb8bbSHariprasad Shenai 	unsigned int rxq_size;
444ab677ff4SHariprasad Shenai 	unsigned int ntxq;
4450fbc81b3SHariprasad Shenai 	bool ciq;
4460fbc81b3SHariprasad Shenai 	bool lro;
44794cdb8bbSHariprasad Shenai 	void *(*add)(const struct cxgb4_lld_info *p);
44894cdb8bbSHariprasad Shenai 	int (*rx_handler)(void *handle, const __be64 *rsp,
44994cdb8bbSHariprasad Shenai 			  const struct pkt_gl *gl);
45094cdb8bbSHariprasad Shenai 	int (*state_change)(void *handle, enum cxgb4_state new_state);
45194cdb8bbSHariprasad Shenai 	int (*control)(void *handle, enum cxgb4_control control, ...);
45294cdb8bbSHariprasad Shenai 	int (*lro_rx_handler)(void *handle, const __be64 *rsp,
45394cdb8bbSHariprasad Shenai 			      const struct pkt_gl *gl,
45494cdb8bbSHariprasad Shenai 			      struct t4_lro_mgr *lro_mgr,
45594cdb8bbSHariprasad Shenai 			      struct napi_struct *napi);
45694cdb8bbSHariprasad Shenai 	void (*lro_flush)(struct t4_lro_mgr *);
457a6ec572bSAtul Gupta 	int (*tx_handler)(struct sk_buff *skb, struct net_device *dev);
45894cdb8bbSHariprasad Shenai };
45994cdb8bbSHariprasad Shenai 
46040b06553SGanesh Goudar void cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p);
461f7917c00SJeff Kirsher int cxgb4_unregister_uld(enum cxgb4_uld type);
462f7917c00SJeff Kirsher int cxgb4_ofld_send(struct net_device *dev, struct sk_buff *skb);
463e383f248SAtul Gupta int cxgb4_immdata_send(struct net_device *dev, unsigned int idx,
464e383f248SAtul Gupta 		       const void *src, unsigned int len);
465ab677ff4SHariprasad Shenai int cxgb4_crypto_send(struct net_device *dev, struct sk_buff *skb);
466881806bcSVipul Pandya unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo);
467f7917c00SJeff Kirsher unsigned int cxgb4_port_chan(const struct net_device *dev);
46874dd5aa1SVishal Kulkarni unsigned int cxgb4_port_e2cchan(const struct net_device *dev);
469f7917c00SJeff Kirsher unsigned int cxgb4_port_viid(const struct net_device *dev);
47027999805SHariprasad S unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid);
471f7917c00SJeff Kirsher unsigned int cxgb4_port_idx(const struct net_device *dev);
472f7917c00SJeff Kirsher unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
473f7917c00SJeff Kirsher 			    unsigned int *idx);
47492e7ae71SHariprasad Shenai unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
47592e7ae71SHariprasad Shenai 				    unsigned short header_size,
47692e7ae71SHariprasad Shenai 				    unsigned short data_size_max,
47792e7ae71SHariprasad Shenai 				    unsigned short data_size_align,
47892e7ae71SHariprasad Shenai 				    unsigned int *mtu_idxp);
479f7917c00SJeff Kirsher void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
480f7917c00SJeff Kirsher 			 struct tp_tcp_stats *v6);
481f7917c00SJeff Kirsher void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
482f7917c00SJeff Kirsher 		      const unsigned int *pgsz_order);
483f7917c00SJeff Kirsher struct sk_buff *cxgb4_pktgl_to_skb(const struct pkt_gl *gl,
484f7917c00SJeff Kirsher 				   unsigned int skb_len, unsigned int pull_len);
4853069ee9bSVipul Pandya int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx, u16 size);
4863069ee9bSVipul Pandya int cxgb4_flush_eq_cache(struct net_device *dev);
487031cf476SHariprasad Shenai int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte);
4887730b4c7SHariprasad Shenai u64 cxgb4_read_sge_timestamp(struct net_device *dev);
4893cbdb928SVipul Pandya 
490df64e4d3SHariprasad Shenai enum cxgb4_bar2_qtype { CXGB4_BAR2_QTYPE_EGRESS, CXGB4_BAR2_QTYPE_INGRESS };
491df64e4d3SHariprasad Shenai int cxgb4_bar2_sge_qregs(struct net_device *dev,
492df64e4d3SHariprasad Shenai 			 unsigned int qid,
493df64e4d3SHariprasad Shenai 			 enum cxgb4_bar2_qtype qtype,
49466cf188eSHariprasad S 			 int user,
495df64e4d3SHariprasad Shenai 			 u64 *pbar2_qoffset,
496df64e4d3SHariprasad Shenai 			 unsigned int *pbar2_qid);
497df64e4d3SHariprasad Shenai 
49894cdb8bbSHariprasad Shenai #endif  /* !__CXGB4_ULD_H */
499