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>
43a8c16e8eSRohit Maheshwari #include <net/tls.h>
4427999805SHariprasad S #include "cxgb4.h"
45f7917c00SJeff Kirsher
460fbc81b3SHariprasad Shenai #define MAX_ULD_QSETS 16
473427e13eSRohit Maheshwari #define MAX_ULD_NPORTS 4
480fbc81b3SHariprasad Shenai
49*2355a677SAyush Sawal /* ulp_mem_io + ulptx_idata + payload + padding */
50*2355a677SAyush Sawal #define MAX_IMM_ULPTX_WR_LEN (32 + 8 + 256 + 8)
51*2355a677SAyush Sawal
52f7917c00SJeff Kirsher /* CPL message priority levels */
53f7917c00SJeff Kirsher enum {
54f7917c00SJeff Kirsher CPL_PRIORITY_DATA = 0, /* data messages */
55f7917c00SJeff Kirsher CPL_PRIORITY_SETUP = 1, /* connection setup messages */
56f7917c00SJeff Kirsher CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */
57f7917c00SJeff Kirsher CPL_PRIORITY_LISTEN = 1, /* listen start/stop messages */
58f7917c00SJeff Kirsher CPL_PRIORITY_ACK = 1, /* RX ACK messages */
59f7917c00SJeff Kirsher CPL_PRIORITY_CONTROL = 1 /* control messages */
60f7917c00SJeff Kirsher };
61f7917c00SJeff Kirsher
62f7917c00SJeff Kirsher #define INIT_TP_WR(w, tid) do { \
63e2ac9628SHariprasad Shenai (w)->wr.wr_hi = htonl(FW_WR_OP_V(FW_TP_WR) | \
64e2ac9628SHariprasad Shenai FW_WR_IMMDLEN_V(sizeof(*w) - sizeof(w->wr))); \
65e2ac9628SHariprasad Shenai (w)->wr.wr_mid = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*w), 16)) | \
66e2ac9628SHariprasad Shenai FW_WR_FLOWID_V(tid)); \
67f7917c00SJeff Kirsher (w)->wr.wr_lo = cpu_to_be64(0); \
68f7917c00SJeff Kirsher } while (0)
69f7917c00SJeff Kirsher
70f7917c00SJeff Kirsher #define INIT_TP_WR_CPL(w, cpl, tid) do { \
71f7917c00SJeff Kirsher INIT_TP_WR(w, tid); \
72f7917c00SJeff Kirsher OPCODE_TID(w) = htonl(MK_OPCODE_TID(cpl, tid)); \
73f7917c00SJeff Kirsher } while (0)
74f7917c00SJeff Kirsher
75f7917c00SJeff Kirsher #define INIT_ULPTX_WR(w, wrlen, atomic, tid) do { \
76e2ac9628SHariprasad Shenai (w)->wr.wr_hi = htonl(FW_WR_OP_V(FW_ULPTX_WR) | \
77e2ac9628SHariprasad Shenai FW_WR_ATOMIC_V(atomic)); \
78e2ac9628SHariprasad Shenai (w)->wr.wr_mid = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(wrlen, 16)) | \
79e2ac9628SHariprasad Shenai FW_WR_FLOWID_V(tid)); \
80f7917c00SJeff Kirsher (w)->wr.wr_lo = cpu_to_be64(0); \
81f7917c00SJeff Kirsher } while (0)
82f7917c00SJeff Kirsher
83f7917c00SJeff Kirsher /* Special asynchronous notification message */
84f7917c00SJeff Kirsher #define CXGB4_MSG_AN ((void *)1)
85ab677ff4SHariprasad Shenai #define TX_ULD(uld)(((uld) != CXGB4_ULD_CRYPTO) ? CXGB4_TX_OFLD :\
86ab677ff4SHariprasad Shenai CXGB4_TX_CRYPTO)
87f7917c00SJeff Kirsher
88f7917c00SJeff Kirsher struct serv_entry {
89f7917c00SJeff Kirsher void *data;
90f7917c00SJeff Kirsher };
91f7917c00SJeff Kirsher
92f7917c00SJeff Kirsher union aopen_entry {
93f7917c00SJeff Kirsher void *data;
94f7917c00SJeff Kirsher union aopen_entry *next;
95f7917c00SJeff Kirsher };
96f7917c00SJeff Kirsher
97ab0367eaSRahul Lakkireddy struct eotid_entry {
98ab0367eaSRahul Lakkireddy void *data;
99ab0367eaSRahul Lakkireddy };
100ab0367eaSRahul Lakkireddy
101f7917c00SJeff Kirsher /*
102f7917c00SJeff Kirsher * Holds the size, base address, free list start, etc of the TID, server TID,
103f7917c00SJeff Kirsher * and active-open TID tables. The tables themselves are allocated dynamically.
104f7917c00SJeff Kirsher */
105f7917c00SJeff Kirsher struct tid_info {
106f7917c00SJeff Kirsher void **tid_tab;
10759437d78SShahjada Abul Husain unsigned int tid_base;
108f7917c00SJeff Kirsher unsigned int ntids;
109f7917c00SJeff Kirsher
110f7917c00SJeff Kirsher struct serv_entry *stid_tab;
111f7917c00SJeff Kirsher unsigned long *stid_bmap;
112f7917c00SJeff Kirsher unsigned int nstids;
113f7917c00SJeff Kirsher unsigned int stid_base;
114d915c299SVishal Kulkarni
115d915c299SVishal Kulkarni unsigned int nhash;
1169a1bb9f6SHariprasad Shenai unsigned int hash_base;
117f7917c00SJeff Kirsher
118f7917c00SJeff Kirsher union aopen_entry *atid_tab;
119f7917c00SJeff Kirsher unsigned int natids;
120f2b7e78dSVipul Pandya unsigned int atid_base;
121f7917c00SJeff Kirsher
122c2193999SShahjada Abul Husain struct filter_entry *hpftid_tab;
123c2193999SShahjada Abul Husain unsigned long *hpftid_bmap;
124c2193999SShahjada Abul Husain unsigned int nhpftids;
125c2193999SShahjada Abul Husain unsigned int hpftid_base;
126c2193999SShahjada Abul Husain
127f2b7e78dSVipul Pandya struct filter_entry *ftid_tab;
128578b46b9SRahul Lakkireddy unsigned long *ftid_bmap;
129f7917c00SJeff Kirsher unsigned int nftids;
130f7917c00SJeff Kirsher unsigned int ftid_base;
131636f9d37SVipul Pandya unsigned int aftid_base;
132636f9d37SVipul Pandya unsigned int aftid_end;
1339a4da2cdSVipul Pandya /* Server filter region */
1349a4da2cdSVipul Pandya unsigned int sftid_base;
1359a4da2cdSVipul Pandya unsigned int nsftids;
136f7917c00SJeff Kirsher
137f7917c00SJeff Kirsher spinlock_t atid_lock ____cacheline_aligned_in_smp;
138f7917c00SJeff Kirsher union aopen_entry *afree;
139f7917c00SJeff Kirsher unsigned int atids_in_use;
140f7917c00SJeff Kirsher
141f7917c00SJeff Kirsher spinlock_t stid_lock;
142f7917c00SJeff Kirsher unsigned int stids_in_use;
1431dec4cecSGanesh Goudar unsigned int v6_stids_in_use;
1442248b293SHariprasad Shenai unsigned int sftids_in_use;
145f7917c00SJeff Kirsher
146ab0367eaSRahul Lakkireddy /* ETHOFLD range */
147ab0367eaSRahul Lakkireddy struct eotid_entry *eotid_tab;
148ab0367eaSRahul Lakkireddy unsigned long *eotid_bmap;
149ab0367eaSRahul Lakkireddy unsigned int eotid_base;
150ab0367eaSRahul Lakkireddy unsigned int neotids;
151ab0367eaSRahul Lakkireddy
1529a1bb9f6SHariprasad Shenai /* TIDs in the TCAM */
153f7917c00SJeff Kirsher atomic_t tids_in_use;
1549a1bb9f6SHariprasad Shenai /* TIDs in the HASH */
1559a1bb9f6SHariprasad Shenai atomic_t hash_tids_in_use;
1561dec4cecSGanesh Goudar atomic_t conns_in_use;
1575148e595SRahul Lakkireddy /* ETHOFLD TIDs used for rate limiting */
1585148e595SRahul Lakkireddy atomic_t eotids_in_use;
1595148e595SRahul Lakkireddy
160578b46b9SRahul Lakkireddy /* lock for setting/clearing filter bitmap */
161578b46b9SRahul Lakkireddy spinlock_t ftid_lock;
1628d174351SRahul Lakkireddy
1638d174351SRahul Lakkireddy unsigned int tc_hash_tids_max_prio;
164f7917c00SJeff Kirsher };
165f7917c00SJeff Kirsher
lookup_tid(const struct tid_info * t,unsigned int tid)166f7917c00SJeff Kirsher static inline void *lookup_tid(const struct tid_info *t, unsigned int tid)
167f7917c00SJeff Kirsher {
16859437d78SShahjada Abul Husain tid -= t->tid_base;
169f7917c00SJeff Kirsher return tid < t->ntids ? t->tid_tab[tid] : NULL;
170f7917c00SJeff Kirsher }
171f7917c00SJeff Kirsher
tid_out_of_range(const struct tid_info * t,unsigned int tid)17259437d78SShahjada Abul Husain static inline bool tid_out_of_range(const struct tid_info *t, unsigned int tid)
17359437d78SShahjada Abul Husain {
17459437d78SShahjada Abul Husain return ((tid - t->tid_base) >= t->ntids);
17559437d78SShahjada Abul Husain }
17659437d78SShahjada Abul Husain
lookup_atid(const struct tid_info * t,unsigned int atid)177f7917c00SJeff Kirsher static inline void *lookup_atid(const struct tid_info *t, unsigned int atid)
178f7917c00SJeff Kirsher {
179f7917c00SJeff Kirsher return atid < t->natids ? t->atid_tab[atid].data : NULL;
180f7917c00SJeff Kirsher }
181f7917c00SJeff Kirsher
lookup_stid(const struct tid_info * t,unsigned int stid)182f7917c00SJeff Kirsher static inline void *lookup_stid(const struct tid_info *t, unsigned int stid)
183f7917c00SJeff Kirsher {
184470c60c4SKumar Sanghvi /* Is it a server filter TID? */
185470c60c4SKumar Sanghvi if (t->nsftids && (stid >= t->sftid_base)) {
186470c60c4SKumar Sanghvi stid -= t->sftid_base;
187470c60c4SKumar Sanghvi stid += t->nstids;
188470c60c4SKumar Sanghvi } else {
189f7917c00SJeff Kirsher stid -= t->stid_base;
190470c60c4SKumar Sanghvi }
191470c60c4SKumar Sanghvi
192dca4faebSVipul Pandya return stid < (t->nstids + t->nsftids) ? t->stid_tab[stid].data : NULL;
193f7917c00SJeff Kirsher }
194f7917c00SJeff Kirsher
cxgb4_insert_tid(struct tid_info * t,void * data,unsigned int tid,unsigned short family)195f7917c00SJeff Kirsher static inline void cxgb4_insert_tid(struct tid_info *t, void *data,
1961dec4cecSGanesh Goudar unsigned int tid, unsigned short family)
197f7917c00SJeff Kirsher {
19859437d78SShahjada Abul Husain t->tid_tab[tid - t->tid_base] = data;
1991dec4cecSGanesh Goudar if (t->hash_base && (tid >= t->hash_base)) {
2001dec4cecSGanesh Goudar if (family == AF_INET6)
2011dec4cecSGanesh Goudar atomic_add(2, &t->hash_tids_in_use);
2021dec4cecSGanesh Goudar else
2039a1bb9f6SHariprasad Shenai atomic_inc(&t->hash_tids_in_use);
2041dec4cecSGanesh Goudar } else {
2051dec4cecSGanesh Goudar if (family == AF_INET6)
2061dec4cecSGanesh Goudar atomic_add(2, &t->tids_in_use);
2079a1bb9f6SHariprasad Shenai else
208f7917c00SJeff Kirsher atomic_inc(&t->tids_in_use);
209f7917c00SJeff Kirsher }
2101dec4cecSGanesh Goudar atomic_inc(&t->conns_in_use);
2111dec4cecSGanesh Goudar }
212f7917c00SJeff Kirsher
cxgb4_lookup_eotid(struct tid_info * t,u32 eotid)213b1396c2bSRahul Lakkireddy static inline struct eotid_entry *cxgb4_lookup_eotid(struct tid_info *t,
214b1396c2bSRahul Lakkireddy u32 eotid)
215b1396c2bSRahul Lakkireddy {
216b1396c2bSRahul Lakkireddy return eotid < t->neotids ? &t->eotid_tab[eotid] : NULL;
217b1396c2bSRahul Lakkireddy }
218b1396c2bSRahul Lakkireddy
cxgb4_get_free_eotid(struct tid_info * t)219b1396c2bSRahul Lakkireddy static inline int cxgb4_get_free_eotid(struct tid_info *t)
220b1396c2bSRahul Lakkireddy {
221b1396c2bSRahul Lakkireddy int eotid;
222b1396c2bSRahul Lakkireddy
223b1396c2bSRahul Lakkireddy eotid = find_first_zero_bit(t->eotid_bmap, t->neotids);
224b1396c2bSRahul Lakkireddy if (eotid >= t->neotids)
225b1396c2bSRahul Lakkireddy eotid = -1;
226b1396c2bSRahul Lakkireddy
227b1396c2bSRahul Lakkireddy return eotid;
228b1396c2bSRahul Lakkireddy }
229b1396c2bSRahul Lakkireddy
cxgb4_alloc_eotid(struct tid_info * t,u32 eotid,void * data)230b1396c2bSRahul Lakkireddy static inline void cxgb4_alloc_eotid(struct tid_info *t, u32 eotid, void *data)
231b1396c2bSRahul Lakkireddy {
232b1396c2bSRahul Lakkireddy set_bit(eotid, t->eotid_bmap);
233b1396c2bSRahul Lakkireddy t->eotid_tab[eotid].data = data;
2345148e595SRahul Lakkireddy atomic_inc(&t->eotids_in_use);
235b1396c2bSRahul Lakkireddy }
236b1396c2bSRahul Lakkireddy
cxgb4_free_eotid(struct tid_info * t,u32 eotid)237b1396c2bSRahul Lakkireddy static inline void cxgb4_free_eotid(struct tid_info *t, u32 eotid)
238b1396c2bSRahul Lakkireddy {
239b1396c2bSRahul Lakkireddy clear_bit(eotid, t->eotid_bmap);
240b1396c2bSRahul Lakkireddy t->eotid_tab[eotid].data = NULL;
2415148e595SRahul Lakkireddy atomic_dec(&t->eotids_in_use);
242b1396c2bSRahul Lakkireddy }
243b1396c2bSRahul Lakkireddy
244f7917c00SJeff Kirsher int cxgb4_alloc_atid(struct tid_info *t, void *data);
245f7917c00SJeff Kirsher int cxgb4_alloc_stid(struct tid_info *t, int family, void *data);
246dca4faebSVipul Pandya int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data);
247f7917c00SJeff Kirsher void cxgb4_free_atid(struct tid_info *t, unsigned int atid);
248f7917c00SJeff Kirsher void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family);
2491dec4cecSGanesh Goudar void cxgb4_remove_tid(struct tid_info *t, unsigned int qid, unsigned int tid,
2501dec4cecSGanesh Goudar unsigned short family);
251f7917c00SJeff Kirsher struct in6_addr;
252f7917c00SJeff Kirsher
253f7917c00SJeff Kirsher int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
254793dad94SVipul Pandya __be32 sip, __be16 sport, __be16 vlan,
255793dad94SVipul Pandya unsigned int queue);
25680f40c1fSVipul Pandya int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
25780f40c1fSVipul Pandya const struct in6_addr *sip, __be16 sport,
25880f40c1fSVipul Pandya unsigned int queue);
25980f40c1fSVipul Pandya int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
26080f40c1fSVipul Pandya unsigned int queue, bool ipv6);
261dca4faebSVipul Pandya int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
262793dad94SVipul Pandya __be32 sip, __be16 sport, __be16 vlan,
263793dad94SVipul Pandya unsigned int queue,
264793dad94SVipul Pandya unsigned char port, unsigned char mask);
265dca4faebSVipul Pandya int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
266dca4faebSVipul Pandya unsigned int queue, bool ipv6);
267a3e3b285SAnish Bhatt
268578b46b9SRahul Lakkireddy /* Filter operation context to allow callers of cxgb4_set_filter() and
269578b46b9SRahul Lakkireddy * cxgb4_del_filter() to wait for an asynchronous completion.
270578b46b9SRahul Lakkireddy */
271578b46b9SRahul Lakkireddy struct filter_ctx {
272578b46b9SRahul Lakkireddy struct completion completion; /* completion rendezvous */
273578b46b9SRahul Lakkireddy void *closure; /* caller's opaque information */
274578b46b9SRahul Lakkireddy int result; /* result of operation */
275578b46b9SRahul Lakkireddy u32 tid; /* to store tid */
276578b46b9SRahul Lakkireddy };
277578b46b9SRahul Lakkireddy
278a3ac249aSRohit Maheshwari struct chcr_ktls {
279a3ac249aSRohit Maheshwari refcount_t ktls_refcount;
280a3ac249aSRohit Maheshwari };
281a3ac249aSRohit Maheshwari
282578b46b9SRahul Lakkireddy struct ch_filter_specification;
283578b46b9SRahul Lakkireddy
2848d174351SRahul Lakkireddy int cxgb4_get_free_ftid(struct net_device *dev, u8 family, bool hash_en,
2858d174351SRahul Lakkireddy u32 tc_prio);
286578b46b9SRahul Lakkireddy int __cxgb4_set_filter(struct net_device *dev, int filter_id,
287578b46b9SRahul Lakkireddy struct ch_filter_specification *fs,
288578b46b9SRahul Lakkireddy struct filter_ctx *ctx);
289578b46b9SRahul Lakkireddy int __cxgb4_del_filter(struct net_device *dev, int filter_id,
2903b0b3beeSKumar Sanghvi struct ch_filter_specification *fs,
291578b46b9SRahul Lakkireddy struct filter_ctx *ctx);
292578b46b9SRahul Lakkireddy int cxgb4_set_filter(struct net_device *dev, int filter_id,
293578b46b9SRahul Lakkireddy struct ch_filter_specification *fs);
2943b0b3beeSKumar Sanghvi int cxgb4_del_filter(struct net_device *dev, int filter_id,
2953b0b3beeSKumar Sanghvi struct ch_filter_specification *fs);
296e0f911c8SKumar Sanghvi int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
2979d922d4bSKumar Sanghvi u64 *hitcnt, u64 *bytecnt, bool hash);
298578b46b9SRahul Lakkireddy
set_wr_txq(struct sk_buff * skb,int prio,int queue)299f7917c00SJeff Kirsher static inline void set_wr_txq(struct sk_buff *skb, int prio, int queue)
300f7917c00SJeff Kirsher {
301f7917c00SJeff Kirsher skb_set_queue_mapping(skb, (queue << 1) | prio);
302f7917c00SJeff Kirsher }
303f7917c00SJeff Kirsher
304f7917c00SJeff Kirsher enum cxgb4_uld {
3050fbc81b3SHariprasad Shenai CXGB4_ULD_INIT,
306f7917c00SJeff Kirsher CXGB4_ULD_RDMA,
307f7917c00SJeff Kirsher CXGB4_ULD_ISCSI,
3082fddfb81SVarun Prakash CXGB4_ULD_ISCSIT,
3090fbc81b3SHariprasad Shenai CXGB4_ULD_CRYPTO,
3101b77be46SVinay Kumar Yadav CXGB4_ULD_IPSEC,
311e383f248SAtul Gupta CXGB4_ULD_TLS,
312a8c16e8eSRohit Maheshwari CXGB4_ULD_KTLS,
313f7917c00SJeff Kirsher CXGB4_ULD_MAX
314f7917c00SJeff Kirsher };
315f7917c00SJeff Kirsher
316ab677ff4SHariprasad Shenai enum cxgb4_tx_uld {
317ab677ff4SHariprasad Shenai CXGB4_TX_OFLD,
318ab677ff4SHariprasad Shenai CXGB4_TX_CRYPTO,
319ab677ff4SHariprasad Shenai CXGB4_TX_MAX
320ab677ff4SHariprasad Shenai };
321ab677ff4SHariprasad Shenai
322ab677ff4SHariprasad Shenai enum cxgb4_txq_type {
323ab677ff4SHariprasad Shenai CXGB4_TXQ_ETH,
324ab677ff4SHariprasad Shenai CXGB4_TXQ_ULD,
325ab677ff4SHariprasad Shenai CXGB4_TXQ_CTRL,
326ab677ff4SHariprasad Shenai CXGB4_TXQ_MAX
327ab677ff4SHariprasad Shenai };
328ab677ff4SHariprasad Shenai
329f7917c00SJeff Kirsher enum cxgb4_state {
330f7917c00SJeff Kirsher CXGB4_STATE_UP,
331f7917c00SJeff Kirsher CXGB4_STATE_START_RECOVERY,
332f7917c00SJeff Kirsher CXGB4_STATE_DOWN,
3338b7372c1SGanesh Goudar CXGB4_STATE_DETACH,
3348b7372c1SGanesh Goudar CXGB4_STATE_FATAL_ERROR
335f7917c00SJeff Kirsher };
336f7917c00SJeff Kirsher
337881806bcSVipul Pandya enum cxgb4_control {
338881806bcSVipul Pandya CXGB4_CONTROL_DB_FULL,
339881806bcSVipul Pandya CXGB4_CONTROL_DB_EMPTY,
340881806bcSVipul Pandya CXGB4_CONTROL_DB_DROP,
341881806bcSVipul Pandya };
342881806bcSVipul Pandya
34393a09e74SPotnuri Bharat Teja struct adapter;
344f7917c00SJeff Kirsher struct pci_dev;
345f7917c00SJeff Kirsher struct l2t_data;
346f7917c00SJeff Kirsher struct net_device;
347f7917c00SJeff Kirsher struct pkt_gl;
348f7917c00SJeff Kirsher struct tp_tcp_stats;
3492337ba42SVarun Prakash struct t4_lro_mgr;
350f7917c00SJeff Kirsher
351f7917c00SJeff Kirsher struct cxgb4_range {
352f7917c00SJeff Kirsher unsigned int start;
353f7917c00SJeff Kirsher unsigned int size;
354f7917c00SJeff Kirsher };
355f7917c00SJeff Kirsher
356f7917c00SJeff Kirsher struct cxgb4_virt_res { /* virtualized HW resources */
357f7917c00SJeff Kirsher struct cxgb4_range ddp;
358f7917c00SJeff Kirsher struct cxgb4_range iscsi;
359f7917c00SJeff Kirsher struct cxgb4_range stag;
360f7917c00SJeff Kirsher struct cxgb4_range rq;
361c68644efSRaju Rangoju struct cxgb4_range srq;
362f7917c00SJeff Kirsher struct cxgb4_range pbl;
363f7917c00SJeff Kirsher struct cxgb4_range qp;
364f7917c00SJeff Kirsher struct cxgb4_range cq;
365f7917c00SJeff Kirsher struct cxgb4_range ocq;
366e383f248SAtul Gupta struct cxgb4_range key;
36772a56ca9SHarsh Jain unsigned int ncrypto_fc;
368a248384eSVarun Prakash struct cxgb4_range ppod_edram;
369f7917c00SJeff Kirsher };
370f7917c00SJeff Kirsher
371a8c16e8eSRohit Maheshwari #if IS_ENABLED(CONFIG_CHELSIO_TLS_DEVICE)
3723427e13eSRohit Maheshwari struct ch_ktls_port_stats_debug {
37362370a4fSRohit Maheshwari atomic64_t ktls_tx_connection_open;
37462370a4fSRohit Maheshwari atomic64_t ktls_tx_connection_fail;
37562370a4fSRohit Maheshwari atomic64_t ktls_tx_connection_close;
37662370a4fSRohit Maheshwari atomic64_t ktls_tx_encrypted_packets;
37762370a4fSRohit Maheshwari atomic64_t ktls_tx_encrypted_bytes;
37862370a4fSRohit Maheshwari atomic64_t ktls_tx_ctx;
37962370a4fSRohit Maheshwari atomic64_t ktls_tx_ooo;
38062370a4fSRohit Maheshwari atomic64_t ktls_tx_skip_no_sync_data;
38162370a4fSRohit Maheshwari atomic64_t ktls_tx_drop_no_sync_data;
38262370a4fSRohit Maheshwari atomic64_t ktls_tx_drop_bypass_req;
383a8c16e8eSRohit Maheshwari };
3843427e13eSRohit Maheshwari
3853427e13eSRohit Maheshwari struct ch_ktls_stats_debug {
3863427e13eSRohit Maheshwari struct ch_ktls_port_stats_debug ktls_port[MAX_ULD_NPORTS];
3873427e13eSRohit Maheshwari atomic64_t ktls_tx_send_records;
3883427e13eSRohit Maheshwari atomic64_t ktls_tx_end_pkts;
3893427e13eSRohit Maheshwari atomic64_t ktls_tx_start_pkts;
3903427e13eSRohit Maheshwari atomic64_t ktls_tx_middle_pkts;
3913427e13eSRohit Maheshwari atomic64_t ktls_tx_retransmit_pkts;
3923427e13eSRohit Maheshwari atomic64_t ktls_tx_complete_pkts;
3933427e13eSRohit Maheshwari atomic64_t ktls_tx_trimmed_pkts;
39421f82acbSRohit Maheshwari atomic64_t ktls_tx_fallback;
3953427e13eSRohit Maheshwari };
39662370a4fSRohit Maheshwari #endif
397a8c16e8eSRohit Maheshwari
398a8c16e8eSRohit Maheshwari struct chcr_stats_debug {
399a8c16e8eSRohit Maheshwari atomic_t cipher_rqst;
400a8c16e8eSRohit Maheshwari atomic_t digest_rqst;
401a8c16e8eSRohit Maheshwari atomic_t aead_rqst;
402a8c16e8eSRohit Maheshwari atomic_t complete;
403a8c16e8eSRohit Maheshwari atomic_t error;
404a8c16e8eSRohit Maheshwari atomic_t fallback;
405a8c16e8eSRohit Maheshwari atomic_t tls_pdu_tx;
406a8c16e8eSRohit Maheshwari atomic_t tls_pdu_rx;
407a8c16e8eSRohit Maheshwari atomic_t tls_key;
408ee0863baSHarsh Jain };
409ee0863baSHarsh Jain
4101b77be46SVinay Kumar Yadav #if IS_ENABLED(CONFIG_CHELSIO_IPSEC_INLINE)
4111b77be46SVinay Kumar Yadav struct ch_ipsec_stats_debug {
4121b77be46SVinay Kumar Yadav atomic_t ipsec_cnt;
4131b77be46SVinay Kumar Yadav };
4141b77be46SVinay Kumar Yadav #endif
4151b77be46SVinay Kumar Yadav
416f7917c00SJeff Kirsher #define OCQ_WIN_OFFSET(pdev, vres) \
417f7917c00SJeff Kirsher (pci_resource_len((pdev), 2) - roundup_pow_of_two((vres)->ocq.size))
418f7917c00SJeff Kirsher
419f7917c00SJeff Kirsher /*
420f7917c00SJeff Kirsher * Block of information the LLD provides to ULDs attaching to a device.
421f7917c00SJeff Kirsher */
422f7917c00SJeff Kirsher struct cxgb4_lld_info {
423f7917c00SJeff Kirsher struct pci_dev *pdev; /* associated PCI device */
424f7917c00SJeff Kirsher struct l2t_data *l2t; /* L2 table */
425f7917c00SJeff Kirsher struct tid_info *tids; /* TID table */
426f7917c00SJeff Kirsher struct net_device **ports; /* device ports */
427f7917c00SJeff Kirsher const struct cxgb4_virt_res *vr; /* assorted HW resources */
428f7917c00SJeff Kirsher const unsigned short *mtus; /* MTU table */
429f7917c00SJeff Kirsher const unsigned short *rxq_ids; /* the ULD's Rx queue ids */
430cf38be6dSHariprasad Shenai const unsigned short *ciq_ids; /* the ULD's concentrator IQ ids */
431f7917c00SJeff Kirsher unsigned short nrxq; /* # of Rx queues */
432f7917c00SJeff Kirsher unsigned short ntxq; /* # of Tx queues */
433cf38be6dSHariprasad Shenai unsigned short nciq; /* # of concentrator IQ */
434f7917c00SJeff Kirsher unsigned char nchan:4; /* # of channels */
435f7917c00SJeff Kirsher unsigned char nports:4; /* # of ports */
436f7917c00SJeff Kirsher unsigned char wr_cred; /* WR 16-byte credits */
437f7917c00SJeff Kirsher unsigned char adapter_type; /* type of adapter */
438f7917c00SJeff Kirsher unsigned char fw_api_ver; /* FW API version */
439a6ec572bSAtul Gupta unsigned char crypto; /* crypto support */
440f7917c00SJeff Kirsher unsigned int fw_vers; /* FW version */
441f7917c00SJeff Kirsher unsigned int iscsi_iolen; /* iSCSI max I/O length */
4427730b4c7SHariprasad Shenai unsigned int cclk_ps; /* Core clock period in psec */
443f7917c00SJeff Kirsher unsigned short udb_density; /* # of user DB/page */
444f7917c00SJeff Kirsher unsigned short ucq_density; /* # of user CQs/page */
445fc4144e7SRaju Rangoju unsigned int sge_host_page_size; /* SGE host page size */
446dca4faebSVipul Pandya unsigned short filt_mode; /* filter optional components */
447dca4faebSVipul Pandya unsigned short tx_modq[NCHAN]; /* maps each tx channel to a */
448dca4faebSVipul Pandya /* scheduler queue */
449f7917c00SJeff Kirsher void __iomem *gts_reg; /* address of GTS register */
450f7917c00SJeff Kirsher void __iomem *db_reg; /* address of kernel doorbell */
4513069ee9bSVipul Pandya int dbfifo_int_thresh; /* doorbell fifo int threshold */
45204e10e21SHariprasad Shenai unsigned int sge_ingpadboundary; /* SGE ingress padding boundary */
45304e10e21SHariprasad Shenai unsigned int sge_egrstatuspagesize; /* SGE egress status page size */
454dca4faebSVipul Pandya unsigned int sge_pktshift; /* Padding between CPL and */
455dca4faebSVipul Pandya /* packet data */
45635b1de55SHariprasad Shenai unsigned int pf; /* Physical Function we're using */
457dca4faebSVipul Pandya bool enable_fw_ofld_conn; /* Enable connection through fw */
458dca4faebSVipul Pandya /* WR */
4594c2c5763SHariprasad Shenai unsigned int max_ordird_qp; /* Max ORD/IRD depth per RDMA QP */
4604c2c5763SHariprasad Shenai unsigned int max_ird_adapter; /* Max IRD memory per adapter */
4611ac0f095SKumar Sanghvi bool ulptx_memwrite_dsgl; /* use of T5 DSGL allowed */
4627714cb9eSVarun Prakash unsigned int iscsi_tagmask; /* iscsi ddp tag mask */
4637714cb9eSVarun Prakash unsigned int iscsi_pgsz_order; /* iscsi ddp page size orders */
4647714cb9eSVarun Prakash unsigned int iscsi_llimit; /* chip's iscsi region llimit */
46514c19b17SHarsh Jain unsigned int ulp_crypto; /* crypto lookaside support */
4667714cb9eSVarun Prakash void **iscsi_ppm; /* iscsi page pod manager */
467982b81ebSHariprasad Shenai int nodeid; /* device numa node id */
468086de575SSteve Wise bool fr_nsmr_tpte_wr_support; /* FW supports FR_NSMR_TPTE_WR */
46943db9296SRaju Rangoju bool write_w_imm_support; /* FW supports WRITE_WITH_IMMEDIATE */
470f3910c62SRaju Rangoju bool write_cmpl_support; /* FW supports WRITE_CMPL WR */
471f7917c00SJeff Kirsher };
472f7917c00SJeff Kirsher
473f7917c00SJeff Kirsher struct cxgb4_uld_info {
4741a91649fSArnd Bergmann char name[IFNAMSIZ];
47594cdb8bbSHariprasad Shenai void *handle;
47694cdb8bbSHariprasad Shenai unsigned int nrxq;
47794cdb8bbSHariprasad Shenai unsigned int rxq_size;
478ab677ff4SHariprasad Shenai unsigned int ntxq;
4790fbc81b3SHariprasad Shenai bool ciq;
4800fbc81b3SHariprasad Shenai bool lro;
48194cdb8bbSHariprasad Shenai void *(*add)(const struct cxgb4_lld_info *p);
48294cdb8bbSHariprasad Shenai int (*rx_handler)(void *handle, const __be64 *rsp,
48394cdb8bbSHariprasad Shenai const struct pkt_gl *gl);
48494cdb8bbSHariprasad Shenai int (*state_change)(void *handle, enum cxgb4_state new_state);
48594cdb8bbSHariprasad Shenai int (*control)(void *handle, enum cxgb4_control control, ...);
48694cdb8bbSHariprasad Shenai int (*lro_rx_handler)(void *handle, const __be64 *rsp,
48794cdb8bbSHariprasad Shenai const struct pkt_gl *gl,
48894cdb8bbSHariprasad Shenai struct t4_lro_mgr *lro_mgr,
48994cdb8bbSHariprasad Shenai struct napi_struct *napi);
49094cdb8bbSHariprasad Shenai void (*lro_flush)(struct t4_lro_mgr *);
491a6ec572bSAtul Gupta int (*tx_handler)(struct sk_buff *skb, struct net_device *dev);
492a8c16e8eSRohit Maheshwari #if IS_ENABLED(CONFIG_CHELSIO_TLS_DEVICE)
493a3ac249aSRohit Maheshwari const struct tlsdev_ops *tlsdev_ops;
494a3ac249aSRohit Maheshwari #endif
49576f919ebSAyush Sawal #if IS_ENABLED(CONFIG_XFRM_OFFLOAD)
49676f919ebSAyush Sawal const struct xfrmdev_ops *xfrmdev_ops;
49776f919ebSAyush Sawal #endif
49894cdb8bbSHariprasad Shenai };
49994cdb8bbSHariprasad Shenai
50093a09e74SPotnuri Bharat Teja void cxgb4_uld_enable(struct adapter *adap);
50140b06553SGanesh Goudar void cxgb4_register_uld(enum cxgb4_uld type, const struct cxgb4_uld_info *p);
502f7917c00SJeff Kirsher int cxgb4_unregister_uld(enum cxgb4_uld type);
503f7917c00SJeff Kirsher int cxgb4_ofld_send(struct net_device *dev, struct sk_buff *skb);
504e383f248SAtul Gupta int cxgb4_immdata_send(struct net_device *dev, unsigned int idx,
505e383f248SAtul Gupta const void *src, unsigned int len);
506ab677ff4SHariprasad Shenai int cxgb4_crypto_send(struct net_device *dev, struct sk_buff *skb);
507881806bcSVipul Pandya unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo);
508f7917c00SJeff Kirsher unsigned int cxgb4_port_chan(const struct net_device *dev);
50974dd5aa1SVishal Kulkarni unsigned int cxgb4_port_e2cchan(const struct net_device *dev);
510f7917c00SJeff Kirsher unsigned int cxgb4_port_viid(const struct net_device *dev);
511f7917c00SJeff Kirsher unsigned int cxgb4_port_idx(const struct net_device *dev);
512f7917c00SJeff Kirsher unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
513f7917c00SJeff Kirsher unsigned int *idx);
51492e7ae71SHariprasad Shenai unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
51592e7ae71SHariprasad Shenai unsigned short header_size,
51692e7ae71SHariprasad Shenai unsigned short data_size_max,
51792e7ae71SHariprasad Shenai unsigned short data_size_align,
51892e7ae71SHariprasad Shenai unsigned int *mtu_idxp);
519f7917c00SJeff Kirsher void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
520f7917c00SJeff Kirsher struct tp_tcp_stats *v6);
521f7917c00SJeff Kirsher void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
522f7917c00SJeff Kirsher const unsigned int *pgsz_order);
523f7917c00SJeff Kirsher struct sk_buff *cxgb4_pktgl_to_skb(const struct pkt_gl *gl,
524f7917c00SJeff Kirsher unsigned int skb_len, unsigned int pull_len);
5253069ee9bSVipul Pandya int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx, u16 size);
5263069ee9bSVipul Pandya int cxgb4_flush_eq_cache(struct net_device *dev);
527031cf476SHariprasad Shenai int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte);
5287730b4c7SHariprasad Shenai u64 cxgb4_read_sge_timestamp(struct net_device *dev);
5293cbdb928SVipul Pandya
530df64e4d3SHariprasad Shenai enum cxgb4_bar2_qtype { CXGB4_BAR2_QTYPE_EGRESS, CXGB4_BAR2_QTYPE_INGRESS };
531df64e4d3SHariprasad Shenai int cxgb4_bar2_sge_qregs(struct net_device *dev,
532df64e4d3SHariprasad Shenai unsigned int qid,
533df64e4d3SHariprasad Shenai enum cxgb4_bar2_qtype qtype,
53466cf188eSHariprasad S int user,
535df64e4d3SHariprasad Shenai u64 *pbar2_qoffset,
536df64e4d3SHariprasad Shenai unsigned int *pbar2_qid);
537df64e4d3SHariprasad Shenai
53894cdb8bbSHariprasad Shenai #endif /* !__CXGB4_ULD_H */
539