blob: 84b96af52655377fb8cf69f588e78b29e3ee5ca8 [file] [log] [blame]
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -07001/*
2 * libcxgbi.h: Chelsio common library for T3/T4 iSCSI driver.
3 *
Karen Xie1149a5e2015-04-10 13:57:15 -07004 * Copyright (c) 2010-2015 Chelsio Communications, Inc.
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation.
9 *
10 * Written by: Karen Xie (kxie@chelsio.com)
11 * Written by: Rakesh Ranjan (rranjan@chelsio.com)
12 */
13
14#ifndef __LIBCXGBI_H__
15#define __LIBCXGBI_H__
16
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/types.h>
20#include <linux/debugfs.h>
21#include <linux/list.h>
22#include <linux/netdevice.h>
23#include <linux/if_vlan.h>
24#include <linux/scatterlist.h>
25#include <linux/skbuff.h>
26#include <linux/vmalloc.h>
Varun Prakash71f7a002016-07-21 22:57:16 +053027#include <linux/version.h>
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -070028#include <scsi/scsi_device.h>
29#include <scsi/libiscsi_tcp.h>
30
Varun Prakash71f7a002016-07-21 22:57:16 +053031#include <libcxgb_ppm.h>
32
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -070033enum cxgbi_dbg_flag {
34 CXGBI_DBG_ISCSI,
35 CXGBI_DBG_DDP,
36 CXGBI_DBG_TOE,
37 CXGBI_DBG_SOCK,
38
39 CXGBI_DBG_PDU_TX,
40 CXGBI_DBG_PDU_RX,
41 CXGBI_DBG_DEV,
42};
43
44#define log_debug(level, fmt, ...) \
45 do { \
46 if (dbg_level & (level)) \
47 pr_info(fmt, ##__VA_ARGS__); \
48 } while (0)
49
Anish Bhattfc8d0592014-07-17 00:18:17 -070050#define pr_info_ipaddr(fmt_trail, \
51 addr1, addr2, args_trail...) \
52do { \
53 if (!((1 << CXGBI_DBG_SOCK) & dbg_level)) \
54 break; \
55 pr_info("%pISpc - %pISpc, " fmt_trail, \
56 addr1, addr2, args_trail); \
57} while (0)
58
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -070059/* max. connections per adapter */
60#define CXGBI_MAX_CONN 16384
61
62/* always allocate rooms for AHS */
63#define SKB_TX_ISCSI_PDU_HEADER_MAX \
64 (sizeof(struct iscsi_hdr) + ISCSI_MAX_AHS_SIZE)
65
66#define ISCSI_PDU_NONPAYLOAD_LEN 312 /* bhs(48) + ahs(256) + digest(8)*/
67
68/*
69 * align pdu size to multiple of 512 for better performance
70 */
71#define cxgbi_align_pdu_size(n) do { n = (n) & (~511); } while (0)
72
73#define ULP2_MODE_ISCSI 2
74
75#define ULP2_MAX_PKT_SIZE 16224
76#define ULP2_MAX_PDU_PAYLOAD \
77 (ULP2_MAX_PKT_SIZE - ISCSI_PDU_NONPAYLOAD_LEN)
78
79/*
80 * For iscsi connections HW may inserts digest bytes into the pdu. Those digest
81 * bytes are not sent by the host but are part of the TCP payload and therefore
82 * consume TCP sequence space.
83 */
84static const unsigned int ulp2_extra_len[] = { 0, 4, 4, 8 };
85static inline unsigned int cxgbi_ulp_extra_len(int submode)
86{
87 return ulp2_extra_len[submode & 3];
88}
89
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -070090#define CPL_RX_DDP_STATUS_DDP_SHIFT 16 /* ddp'able */
91#define CPL_RX_DDP_STATUS_PAD_SHIFT 19 /* pad error */
92#define CPL_RX_DDP_STATUS_HCRC_SHIFT 20 /* hcrc error */
93#define CPL_RX_DDP_STATUS_DCRC_SHIFT 21 /* dcrc error */
94
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -070095/*
96 * sge_opaque_hdr -
97 * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
98 * and for which we must reserve space.
99 */
100struct sge_opaque_hdr {
101 void *dev;
102 dma_addr_t addr[MAX_SKB_FRAGS + 1];
103};
104
105struct cxgbi_sock {
106 struct cxgbi_device *cdev;
107
108 int tid;
109 int atid;
110 unsigned long flags;
111 unsigned int mtu;
112 unsigned short rss_qid;
113 unsigned short txq_idx;
114 unsigned short advmss;
115 unsigned int tx_chan;
116 unsigned int rx_chan;
117 unsigned int mss_idx;
118 unsigned int smac_idx;
119 unsigned char port_id;
120 int wr_max_cred;
121 int wr_cred;
122 int wr_una_cred;
Varun Prakashb5a5fe42018-09-13 21:26:00 +0530123#ifdef CONFIG_CHELSIO_T4_DCB
124 u8 dcb_priority;
125#endif
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700126 unsigned char hcrc_len;
127 unsigned char dcrc_len;
128
129 void *l2t;
130 struct sk_buff *wr_pending_head;
131 struct sk_buff *wr_pending_tail;
132 struct sk_buff *cpl_close;
133 struct sk_buff *cpl_abort_req;
134 struct sk_buff *cpl_abort_rpl;
135 struct sk_buff *skb_ulp_lhdr;
136 spinlock_t lock;
137 struct kref refcnt;
138 unsigned int state;
Anish Bhattfc8d0592014-07-17 00:18:17 -0700139 unsigned int csk_family;
140 union {
141 struct sockaddr_in saddr;
142 struct sockaddr_in6 saddr6;
143 };
144 union {
145 struct sockaddr_in daddr;
146 struct sockaddr_in6 daddr6;
147 };
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700148 struct dst_entry *dst;
149 struct sk_buff_head receive_queue;
150 struct sk_buff_head write_queue;
151 struct timer_list retry_timer;
Varun Prakash9e8f1c72019-01-10 23:29:28 +0530152 struct completion cmpl;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700153 int err;
154 rwlock_t callback_lock;
155 void *user_data;
156
157 u32 rcv_nxt;
158 u32 copied_seq;
159 u32 rcv_wup;
160 u32 snd_nxt;
161 u32 snd_una;
162 u32 write_seq;
Karen Xie81daf102015-04-10 13:57:12 -0700163 u32 snd_win;
164 u32 rcv_win;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700165};
166
167/*
168 * connection states
169 */
170enum cxgbi_sock_states{
171 CTP_CLOSED,
172 CTP_CONNECTING,
173 CTP_ACTIVE_OPEN,
174 CTP_ESTABLISHED,
175 CTP_ACTIVE_CLOSE,
176 CTP_PASSIVE_CLOSE,
177 CTP_CLOSE_WAIT_1,
178 CTP_CLOSE_WAIT_2,
179 CTP_ABORTING,
180};
181
182/*
183 * Connection flags -- many to track some close related events.
184 */
185enum cxgbi_sock_flags {
186 CTPF_ABORT_RPL_RCVD, /*received one ABORT_RPL_RSS message */
187 CTPF_ABORT_REQ_RCVD, /*received one ABORT_REQ_RSS message */
188 CTPF_ABORT_RPL_PENDING, /* expecting an abort reply */
189 CTPF_TX_DATA_SENT, /* already sent a TX_DATA WR */
190 CTPF_ACTIVE_CLOSE_NEEDED,/* need to be closed */
191 CTPF_HAS_ATID, /* reserved atid */
192 CTPF_HAS_TID, /* reserved hw tid */
193 CTPF_OFFLOAD_DOWN, /* offload function off */
Varun Prakashe0f8e8c2017-05-27 20:22:51 +0530194 CTPF_LOGOUT_RSP_RCVD, /* received logout response */
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700195};
196
197struct cxgbi_skb_rx_cb {
198 __u32 ddigest;
199 __u32 pdulen;
200};
201
202struct cxgbi_skb_tx_cb {
Varun Prakash75b61252017-05-16 19:23:44 +0530203 void *handle;
204 void *arp_err_handler;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700205 struct sk_buff *wr_next;
206};
207
208enum cxgbi_skcb_flags {
209 SKCBF_TX_NEED_HDR, /* packet needs a header */
Varun Prakash71f7a002016-07-21 22:57:16 +0530210 SKCBF_TX_MEM_WRITE, /* memory write */
211 SKCBF_TX_FLAG_COMPL, /* wr completion flag */
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700212 SKCBF_RX_COALESCED, /* received whole pdu */
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300213 SKCBF_RX_HDR, /* received pdu header */
214 SKCBF_RX_DATA, /* received pdu payload */
215 SKCBF_RX_STATUS, /* received ddp status */
Varun Prakash44830d82016-12-01 20:28:29 +0530216 SKCBF_RX_ISCSI_COMPL, /* received iscsi completion */
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700217 SKCBF_RX_DATA_DDPD, /* pdu payload ddp'd */
218 SKCBF_RX_HCRC_ERR, /* header digest error */
219 SKCBF_RX_DCRC_ERR, /* data digest error */
220 SKCBF_RX_PAD_ERR, /* padding byte error */
221};
222
223struct cxgbi_skb_cb {
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700224 union {
225 struct cxgbi_skb_rx_cb rx;
226 struct cxgbi_skb_tx_cb tx;
227 };
Varun Prakash75b61252017-05-16 19:23:44 +0530228 unsigned char ulp_mode;
229 unsigned long flags;
230 unsigned int seq;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700231};
232
233#define CXGBI_SKB_CB(skb) ((struct cxgbi_skb_cb *)&((skb)->cb[0]))
234#define cxgbi_skcb_flags(skb) (CXGBI_SKB_CB(skb)->flags)
235#define cxgbi_skcb_ulp_mode(skb) (CXGBI_SKB_CB(skb)->ulp_mode)
236#define cxgbi_skcb_tcp_seq(skb) (CXGBI_SKB_CB(skb)->seq)
237#define cxgbi_skcb_rx_ddigest(skb) (CXGBI_SKB_CB(skb)->rx.ddigest)
238#define cxgbi_skcb_rx_pdulen(skb) (CXGBI_SKB_CB(skb)->rx.pdulen)
239#define cxgbi_skcb_tx_wr_next(skb) (CXGBI_SKB_CB(skb)->tx.wr_next)
240
241static inline void cxgbi_skcb_set_flag(struct sk_buff *skb,
242 enum cxgbi_skcb_flags flag)
243{
244 __set_bit(flag, &(cxgbi_skcb_flags(skb)));
245}
246
247static inline void cxgbi_skcb_clear_flag(struct sk_buff *skb,
248 enum cxgbi_skcb_flags flag)
249{
250 __clear_bit(flag, &(cxgbi_skcb_flags(skb)));
251}
252
Karen Xie84944d82014-12-11 19:13:29 -0800253static inline int cxgbi_skcb_test_flag(const struct sk_buff *skb,
254 enum cxgbi_skcb_flags flag)
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700255{
256 return test_bit(flag, &(cxgbi_skcb_flags(skb)));
257}
258
259static inline void cxgbi_sock_set_flag(struct cxgbi_sock *csk,
260 enum cxgbi_sock_flags flag)
261{
262 __set_bit(flag, &csk->flags);
263 log_debug(1 << CXGBI_DBG_SOCK,
264 "csk 0x%p,%u,0x%lx, bit %d.\n",
265 csk, csk->state, csk->flags, flag);
266}
267
268static inline void cxgbi_sock_clear_flag(struct cxgbi_sock *csk,
269 enum cxgbi_sock_flags flag)
270{
271 __clear_bit(flag, &csk->flags);
272 log_debug(1 << CXGBI_DBG_SOCK,
273 "csk 0x%p,%u,0x%lx, bit %d.\n",
274 csk, csk->state, csk->flags, flag);
275}
276
277static inline int cxgbi_sock_flag(struct cxgbi_sock *csk,
278 enum cxgbi_sock_flags flag)
279{
280 if (csk == NULL)
281 return 0;
282 return test_bit(flag, &csk->flags);
283}
284
285static inline void cxgbi_sock_set_state(struct cxgbi_sock *csk, int state)
286{
287 log_debug(1 << CXGBI_DBG_SOCK,
288 "csk 0x%p,%u,0x%lx, state -> %u.\n",
289 csk, csk->state, csk->flags, state);
290 csk->state = state;
291}
292
293static inline void cxgbi_sock_free(struct kref *kref)
294{
295 struct cxgbi_sock *csk = container_of(kref,
296 struct cxgbi_sock,
297 refcnt);
298 if (csk) {
299 log_debug(1 << CXGBI_DBG_SOCK,
300 "free csk 0x%p, state %u, flags 0x%lx\n",
301 csk, csk->state, csk->flags);
302 kfree(csk);
303 }
304}
305
306static inline void __cxgbi_sock_put(const char *fn, struct cxgbi_sock *csk)
307{
308 log_debug(1 << CXGBI_DBG_SOCK,
309 "%s, put csk 0x%p, ref %u-1.\n",
Peter Zijlstra2c935bc2016-11-14 17:29:48 +0100310 fn, csk, kref_read(&csk->refcnt));
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700311 kref_put(&csk->refcnt, cxgbi_sock_free);
312}
313#define cxgbi_sock_put(csk) __cxgbi_sock_put(__func__, csk)
314
315static inline void __cxgbi_sock_get(const char *fn, struct cxgbi_sock *csk)
316{
317 log_debug(1 << CXGBI_DBG_SOCK,
318 "%s, get csk 0x%p, ref %u+1.\n",
Peter Zijlstra2c935bc2016-11-14 17:29:48 +0100319 fn, csk, kref_read(&csk->refcnt));
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700320 kref_get(&csk->refcnt);
321}
322#define cxgbi_sock_get(csk) __cxgbi_sock_get(__func__, csk)
323
324static inline int cxgbi_sock_is_closing(struct cxgbi_sock *csk)
325{
326 return csk->state >= CTP_ACTIVE_CLOSE;
327}
328
329static inline int cxgbi_sock_is_established(struct cxgbi_sock *csk)
330{
331 return csk->state == CTP_ESTABLISHED;
332}
333
334static inline void cxgbi_sock_purge_write_queue(struct cxgbi_sock *csk)
335{
336 struct sk_buff *skb;
337
338 while ((skb = __skb_dequeue(&csk->write_queue)))
339 __kfree_skb(skb);
340}
341
342static inline unsigned int cxgbi_sock_compute_wscale(unsigned int win)
343{
344 unsigned int wscale = 0;
345
346 while (wscale < 14 && (65535 << wscale) < win)
347 wscale++;
348 return wscale;
349}
350
kxie@chelsio.com24d3f952010-09-23 16:43:23 -0700351static inline struct sk_buff *alloc_wr(int wrlen, int dlen, gfp_t gfp)
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700352{
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700353 struct sk_buff *skb = alloc_skb(wrlen + dlen, gfp);
354
355 if (skb) {
356 __skb_put(skb, wrlen);
357 memset(skb->head, 0, wrlen + dlen);
358 } else
kxie@chelsio.com24d3f952010-09-23 16:43:23 -0700359 pr_info("alloc cpl wr skb %u+%u, OOM.\n", wrlen, dlen);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700360 return skb;
361}
362
363
364/*
365 * The number of WRs needed for an skb depends on the number of fragments
366 * in the skb and whether it has any payload in its main body. This maps the
367 * length of the gather list represented by an skb into the # of necessary WRs.
368 * The extra two fragments are for iscsi bhs and payload padding.
369 */
370#define SKB_WR_LIST_SIZE (MAX_SKB_FRAGS + 2)
371
372static inline void cxgbi_sock_reset_wr_list(struct cxgbi_sock *csk)
373{
374 csk->wr_pending_head = csk->wr_pending_tail = NULL;
375}
376
377static inline void cxgbi_sock_enqueue_wr(struct cxgbi_sock *csk,
378 struct sk_buff *skb)
379{
380 cxgbi_skcb_tx_wr_next(skb) = NULL;
381 /*
382 * We want to take an extra reference since both us and the driver
Varun Prakash75b61252017-05-16 19:23:44 +0530383 * need to free the packet before it's really freed.
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700384 */
Varun Prakash75b61252017-05-16 19:23:44 +0530385 skb_get(skb);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700386
387 if (!csk->wr_pending_head)
388 csk->wr_pending_head = skb;
389 else
390 cxgbi_skcb_tx_wr_next(csk->wr_pending_tail) = skb;
391 csk->wr_pending_tail = skb;
392}
393
394static inline int cxgbi_sock_count_pending_wrs(const struct cxgbi_sock *csk)
395{
396 int n = 0;
397 const struct sk_buff *skb = csk->wr_pending_head;
398
399 while (skb) {
400 n += skb->csum;
401 skb = cxgbi_skcb_tx_wr_next(skb);
402 }
403 return n;
404}
405
406static inline struct sk_buff *cxgbi_sock_peek_wr(const struct cxgbi_sock *csk)
407{
408 return csk->wr_pending_head;
409}
410
411static inline struct sk_buff *cxgbi_sock_dequeue_wr(struct cxgbi_sock *csk)
412{
413 struct sk_buff *skb = csk->wr_pending_head;
414
415 if (likely(skb)) {
416 csk->wr_pending_head = cxgbi_skcb_tx_wr_next(skb);
417 cxgbi_skcb_tx_wr_next(skb) = NULL;
418 }
419 return skb;
420}
421
422void cxgbi_sock_check_wr_invariants(const struct cxgbi_sock *);
423void cxgbi_sock_purge_wr_queue(struct cxgbi_sock *);
424void cxgbi_sock_skb_entail(struct cxgbi_sock *, struct sk_buff *);
425void cxgbi_sock_fail_act_open(struct cxgbi_sock *, int);
426void cxgbi_sock_act_open_req_arp_failure(void *, struct sk_buff *);
427void cxgbi_sock_closed(struct cxgbi_sock *);
428void cxgbi_sock_established(struct cxgbi_sock *, unsigned int, unsigned int);
429void cxgbi_sock_rcv_abort_rpl(struct cxgbi_sock *);
430void cxgbi_sock_rcv_peer_close(struct cxgbi_sock *);
431void cxgbi_sock_rcv_close_conn_rpl(struct cxgbi_sock *, u32);
432void cxgbi_sock_rcv_wr_ack(struct cxgbi_sock *, unsigned int, unsigned int,
433 int);
434unsigned int cxgbi_sock_select_mss(struct cxgbi_sock *, unsigned int);
435void cxgbi_sock_free_cpl_skbs(struct cxgbi_sock *);
436
437struct cxgbi_hba {
438 struct net_device *ndev;
kxie@chelsio.com0b3d8942010-09-23 16:43:23 -0700439 struct net_device *vdev; /* vlan dev */
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700440 struct Scsi_Host *shost;
441 struct cxgbi_device *cdev;
442 __be32 ipv4addr;
443 unsigned char port_id;
444};
445
446struct cxgbi_ports_map {
447 unsigned int max_connect;
448 unsigned int used;
449 unsigned short sport_base;
450 spinlock_t lock;
451 unsigned int next;
452 struct cxgbi_sock **port_csk;
453};
454
455#define CXGBI_FLAG_DEV_T3 0x1
456#define CXGBI_FLAG_DEV_T4 0x2
457#define CXGBI_FLAG_ADAPTER_RESET 0x4
458#define CXGBI_FLAG_IPV4_SET 0x10
Varun Prakash71f7a002016-07-21 22:57:16 +0530459#define CXGBI_FLAG_USE_PPOD_OFLDQ 0x40
460#define CXGBI_FLAG_DDP_OFF 0x100
461
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700462struct cxgbi_device {
463 struct list_head list_head;
Anish Bhatt078efae2014-09-15 17:44:18 -0700464 struct list_head rcu_node;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700465 unsigned int flags;
466 struct net_device **ports;
467 void *lldev;
468 struct cxgbi_hba **hbas;
469 const unsigned short *mtus;
470 unsigned char nmtus;
471 unsigned char nports;
472 struct pci_dev *pdev;
473 struct dentry *debugfs_root;
474 struct iscsi_transport *itp;
Varun Prakash1fe1fdb2016-12-07 21:06:45 +0530475 struct module *owner;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700476
477 unsigned int pfvf;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700478 unsigned int rx_credit_thres;
479 unsigned int skb_tx_rsvd;
480 unsigned int skb_rx_extra; /* for msg coalesced mode */
481 unsigned int tx_max_size;
482 unsigned int rx_max_size;
Varun Prakash6c9e2772017-06-22 15:47:49 +0530483 unsigned int rxq_idx_cntr;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700484 struct cxgbi_ports_map pmap;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700485
486 void (*dev_ddp_cleanup)(struct cxgbi_device *);
Varun Prakash71f7a002016-07-21 22:57:16 +0530487 struct cxgbi_ppm* (*cdev2ppm)(struct cxgbi_device *);
488 int (*csk_ddp_set_map)(struct cxgbi_ppm *, struct cxgbi_sock *,
489 struct cxgbi_task_tag_info *);
490 void (*csk_ddp_clear_map)(struct cxgbi_device *cdev,
491 struct cxgbi_ppm *,
492 struct cxgbi_task_tag_info *);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700493 int (*csk_ddp_setup_digest)(struct cxgbi_sock *,
Varun Prakash9e8f1c72019-01-10 23:29:28 +0530494 unsigned int, int, int);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700495 int (*csk_ddp_setup_pgidx)(struct cxgbi_sock *,
Varun Prakash9e8f1c72019-01-10 23:29:28 +0530496 unsigned int, int);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700497
498 void (*csk_release_offload_resources)(struct cxgbi_sock *);
499 int (*csk_rx_pdu_ready)(struct cxgbi_sock *, struct sk_buff *);
500 u32 (*csk_send_rx_credits)(struct cxgbi_sock *, u32);
501 int (*csk_push_tx_frames)(struct cxgbi_sock *, int);
502 void (*csk_send_abort_req)(struct cxgbi_sock *);
503 void (*csk_send_close_req)(struct cxgbi_sock *);
504 int (*csk_alloc_cpls)(struct cxgbi_sock *);
505 int (*csk_init_act_open)(struct cxgbi_sock *);
506
507 void *dd_data;
508};
509#define cxgbi_cdev_priv(cdev) ((cdev)->dd_data)
510
511struct cxgbi_conn {
512 struct cxgbi_endpoint *cep;
513 struct iscsi_conn *iconn;
514 struct cxgbi_hba *chba;
515 u32 task_idx_bits;
Varun Prakash71f7a002016-07-21 22:57:16 +0530516 unsigned int ddp_full;
517 unsigned int ddp_tag_full;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700518};
519
520struct cxgbi_endpoint {
521 struct cxgbi_conn *cconn;
522 struct cxgbi_hba *chba;
523 struct cxgbi_sock *csk;
524};
525
526#define MAX_PDU_FRAGS ((ULP2_MAX_PDU_PAYLOAD + 512 - 1) / 512)
527struct cxgbi_task_data {
528 unsigned short nr_frags;
Ian Campbell6a39a162011-10-19 23:01:48 +0000529 struct page_frag frags[MAX_PDU_FRAGS];
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700530 struct sk_buff *skb;
Varun Prakash71f7a002016-07-21 22:57:16 +0530531 unsigned int dlen;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700532 unsigned int offset;
533 unsigned int count;
534 unsigned int sgoffset;
Varun Prakash71f7a002016-07-21 22:57:16 +0530535 struct cxgbi_task_tag_info ttinfo;
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700536};
kxie@chelsio.come3d2ad82010-09-23 16:43:23 -0700537#define iscsi_task_cxgbi_data(task) \
538 ((task)->dd_data + sizeof(struct iscsi_tcp_task))
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700539
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700540static inline void *cxgbi_alloc_big_mem(unsigned int size,
541 gfp_t gfp)
542{
Joe Perches8be04b92013-06-19 12:15:53 -0700543 void *p = kzalloc(size, gfp | __GFP_NOWARN);
544
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700545 if (!p)
Joe Perches8be04b92013-06-19 12:15:53 -0700546 p = vzalloc(size);
547
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700548 return p;
549}
550
551static inline void cxgbi_free_big_mem(void *addr)
552{
Pekka Enberg32a78fa2015-06-30 14:59:27 -0700553 kvfree(addr);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700554}
555
556static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr)
557{
558 if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET)
559 chba->ipv4addr = ipaddr;
560 else
561 pr_info("set iscsi ipv4 NOT supported, using %s ipv4.\n",
562 chba->ndev->name);
563}
564
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700565struct cxgbi_device *cxgbi_device_register(unsigned int, unsigned int);
566void cxgbi_device_unregister(struct cxgbi_device *);
567void cxgbi_device_unregister_all(unsigned int flag);
568struct cxgbi_device *cxgbi_device_find_by_lldev(void *);
Anish Bhattfc8d0592014-07-17 00:18:17 -0700569struct cxgbi_device *cxgbi_device_find_by_netdev(struct net_device *, int *);
Anish Bhatt078efae2014-09-15 17:44:18 -0700570struct cxgbi_device *cxgbi_device_find_by_netdev_rcu(struct net_device *,
571 int *);
Hannes Reinecke1abf6352014-06-25 15:27:38 +0200572int cxgbi_hbas_add(struct cxgbi_device *, u64, unsigned int,
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700573 struct scsi_host_template *,
574 struct scsi_transport_template *);
575void cxgbi_hbas_remove(struct cxgbi_device *);
576
577int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base,
578 unsigned int max_conn);
579void cxgbi_device_portmap_cleanup(struct cxgbi_device *cdev);
580
581void cxgbi_conn_tx_open(struct cxgbi_sock *);
582void cxgbi_conn_pdu_ready(struct cxgbi_sock *);
583int cxgbi_conn_alloc_pdu(struct iscsi_task *, u8);
584int cxgbi_conn_init_pdu(struct iscsi_task *, unsigned int , unsigned int);
585int cxgbi_conn_xmit_pdu(struct iscsi_task *);
586
587void cxgbi_cleanup_task(struct iscsi_task *task);
588
Al Viro587a1f12011-07-23 23:11:19 -0400589umode_t cxgbi_attr_is_visible(int param_type, int param);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700590void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *);
591int cxgbi_set_conn_param(struct iscsi_cls_conn *,
592 enum iscsi_param, char *, int);
Mike Christiec71b9b62011-02-16 15:04:38 -0600593int cxgbi_get_ep_param(struct iscsi_endpoint *ep, enum iscsi_param, char *);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700594struct iscsi_cls_conn *cxgbi_create_conn(struct iscsi_cls_session *, u32);
595int cxgbi_bind_conn(struct iscsi_cls_session *,
596 struct iscsi_cls_conn *, u64, int);
597void cxgbi_destroy_session(struct iscsi_cls_session *);
598struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *,
599 u16, u16, u32);
600int cxgbi_set_host_param(struct Scsi_Host *,
601 enum iscsi_host_param, char *, int);
602int cxgbi_get_host_param(struct Scsi_Host *, enum iscsi_host_param, char *);
603struct iscsi_endpoint *cxgbi_ep_connect(struct Scsi_Host *,
604 struct sockaddr *, int);
605int cxgbi_ep_poll(struct iscsi_endpoint *, int);
606void cxgbi_ep_disconnect(struct iscsi_endpoint *);
607
608int cxgbi_iscsi_init(struct iscsi_transport *,
609 struct scsi_transport_template **);
610void cxgbi_iscsi_cleanup(struct iscsi_transport *,
611 struct scsi_transport_template **);
612void cxgbi_parse_pdu_itt(struct iscsi_conn *, itt_t, int *, int *);
613int cxgbi_ddp_init(struct cxgbi_device *, unsigned int, unsigned int,
614 unsigned int, unsigned int);
615int cxgbi_ddp_cleanup(struct cxgbi_device *);
616void cxgbi_ddp_page_size_factor(int *);
Varun Prakash71f7a002016-07-21 22:57:16 +0530617void cxgbi_ddp_set_one_ppod(struct cxgbi_pagepod *,
618 struct cxgbi_task_tag_info *,
619 struct scatterlist **sg_pp, unsigned int *sg_off);
Varun Prakasha2483842019-06-10 18:36:34 +0530620int cxgbi_ddp_ppm_setup(void **ppm_pp, struct cxgbi_device *cdev,
621 struct cxgbi_tag_format *tformat,
622 unsigned int iscsi_size, unsigned int llimit,
623 unsigned int start, unsigned int rsvd_factor,
624 unsigned int edram_start, unsigned int edram_size);
kxie@chelsio.com9ba682f2010-08-16 20:55:53 -0700625#endif /*__LIBCXGBI_H__*/