2 * Copyright (c) 2016 Chelsio Communications, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
12 #include <linux/mutex.h>
13 #include <linux/list.h>
14 #include <linux/spinlock.h>
15 #include <linux/idr.h>
16 #include <linux/completion.h>
17 #include <linux/netdevice.h>
18 #include <linux/sched.h>
19 #include <linux/pci.h>
20 #include <linux/dma-mapping.h>
21 #include <linux/inet.h>
22 #include <linux/wait.h>
23 #include <linux/kref.h>
24 #include <linux/timer.h>
27 #include <asm/byteorder.h>
29 #include <net/net_namespace.h>
31 #include <target/iscsi/iscsi_transport.h>
32 #include <iscsi_target_parameters.h>
33 #include <iscsi_target_login.h>
38 #include "cxgb4_uld.h"
40 #include "libcxgb_ppm.h"
41 #include "cxgbit_lro.h"
43 extern struct mutex cdev_list_lock
;
44 extern struct list_head cdev_list_head
;
50 struct scatterlist sg
;
51 struct cxgbi_task_tag_info ttinfo
;
56 #define CXGBIT_MAX_ISO_PAYLOAD \
57 min_t(u32, MAX_SKB_FRAGS * PAGE_SIZE, 65535)
59 struct cxgbit_iso_info
{
66 enum cxgbit_skcb_flags
{
67 SKCBF_TX_NEED_HDR
= (1 << 0), /* packet needs a header */
68 SKCBF_TX_FLAG_COMPL
= (1 << 1), /* wr completion flag */
69 SKCBF_TX_ISO
= (1 << 2), /* iso cpl in tx skb */
70 SKCBF_RX_LRO
= (1 << 3), /* lro skb */
73 struct cxgbit_skb_rx_cb
{
76 void (*backlog_fn
)(struct cxgbit_sock
*, struct sk_buff
*);
79 struct cxgbit_skb_tx_cb
{
88 struct cxgbit_skb_tx_cb tx
;
89 struct cxgbit_skb_rx_cb rx
;
94 /* This member must be first. */
95 struct l2t_skb_cb l2t
;
96 struct sk_buff
*wr_next
;
100 #define CXGBIT_SKB_CB(skb) ((union cxgbit_skb_cb *)&((skb)->cb[0]))
101 #define cxgbit_skcb_flags(skb) (CXGBIT_SKB_CB(skb)->flags)
102 #define cxgbit_skcb_submode(skb) (CXGBIT_SKB_CB(skb)->tx.submode)
103 #define cxgbit_skcb_tx_wr_next(skb) (CXGBIT_SKB_CB(skb)->wr_next)
104 #define cxgbit_skcb_tx_extralen(skb) (CXGBIT_SKB_CB(skb)->tx.extra_len)
105 #define cxgbit_skcb_rx_opcode(skb) (CXGBIT_SKB_CB(skb)->rx.opcode)
106 #define cxgbit_skcb_rx_backlog_fn(skb) (CXGBIT_SKB_CB(skb)->rx.backlog_fn)
107 #define cxgbit_rx_pdu_cb(skb) (CXGBIT_SKB_CB(skb)->rx.pdu_cb)
109 static inline void *cplhdr(struct sk_buff
*skb
)
114 enum cxgbit_cdev_flags
{
120 #define NP_INFO_HASH_SIZE 32
123 struct np_info
*next
;
124 struct cxgbit_np
*cnp
;
128 struct cxgbit_list_head
{
129 struct list_head list
;
134 struct cxgbit_device
{
135 struct list_head list
;
136 struct cxgb4_lld_info lldi
;
137 struct np_info
*np_hash_tab
[NP_INFO_HASH_SIZE
];
140 u8 selectq
[MAX_NPORTS
][2];
141 struct cxgbit_list_head cskq
;
147 struct cxgbit_wr_wait
{
148 struct completion completion
;
152 enum cxgbit_csk_state
{
155 CSK_STATE_CONNECTING
,
156 CSK_STATE_ESTABLISHED
,
163 enum cxgbit_csk_flags
{
164 CSK_TX_DATA_SENT
= 0,
170 struct cxgbit_sock_common
{
171 struct cxgbit_device
*cdev
;
172 struct sockaddr_storage local_addr
;
173 struct sockaddr_storage remote_addr
;
174 struct cxgbit_wr_wait wr_wait
;
175 enum cxgbit_csk_state state
;
180 struct cxgbit_sock_common com
;
181 wait_queue_head_t accept_wait
;
183 struct completion accept_comp
;
184 struct list_head np_accept_list
;
186 spinlock_t np_accept_lock
;
192 struct cxgbit_sock_common com
;
193 struct cxgbit_np
*cnp
;
194 struct iscsi_conn
*conn
;
195 struct l2t_entry
*l2t
;
196 struct dst_entry
*dst
;
197 struct list_head list
;
198 struct sk_buff_head rxq
;
199 struct sk_buff_head txq
;
200 struct sk_buff_head ppodq
;
201 struct sk_buff_head backlogq
;
202 struct sk_buff_head skbq
;
203 struct sk_buff
*wr_pending_head
;
204 struct sk_buff
*wr_pending_tail
;
206 struct sk_buff
*lro_skb
;
207 struct sk_buff
*lro_hskb
;
208 struct list_head accept_node
;
211 wait_queue_head_t waitq
;
212 wait_queue_head_t ack_waitq
;
238 #define CXGBIT_SUBMODE_HCRC 0x1
239 #define CXGBIT_SUBMODE_DCRC 0x2
241 #ifdef CONFIG_CHELSIO_T4_DCB
247 void _cxgbit_free_cdev(struct kref
*kref
);
248 void _cxgbit_free_csk(struct kref
*kref
);
249 void _cxgbit_free_cnp(struct kref
*kref
);
251 static inline void cxgbit_get_cdev(struct cxgbit_device
*cdev
)
253 kref_get(&cdev
->kref
);
256 static inline void cxgbit_put_cdev(struct cxgbit_device
*cdev
)
258 kref_put(&cdev
->kref
, _cxgbit_free_cdev
);
261 static inline void cxgbit_get_csk(struct cxgbit_sock
*csk
)
263 kref_get(&csk
->kref
);
266 static inline void cxgbit_put_csk(struct cxgbit_sock
*csk
)
268 kref_put(&csk
->kref
, _cxgbit_free_csk
);
271 static inline void cxgbit_get_cnp(struct cxgbit_np
*cnp
)
273 kref_get(&cnp
->kref
);
276 static inline void cxgbit_put_cnp(struct cxgbit_np
*cnp
)
278 kref_put(&cnp
->kref
, _cxgbit_free_cnp
);
281 static inline void cxgbit_sock_reset_wr_list(struct cxgbit_sock
*csk
)
283 csk
->wr_pending_tail
= NULL
;
284 csk
->wr_pending_head
= NULL
;
287 static inline struct sk_buff
*cxgbit_sock_peek_wr(const struct cxgbit_sock
*csk
)
289 return csk
->wr_pending_head
;
293 cxgbit_sock_enqueue_wr(struct cxgbit_sock
*csk
, struct sk_buff
*skb
)
295 cxgbit_skcb_tx_wr_next(skb
) = NULL
;
299 if (!csk
->wr_pending_head
)
300 csk
->wr_pending_head
= skb
;
302 cxgbit_skcb_tx_wr_next(csk
->wr_pending_tail
) = skb
;
303 csk
->wr_pending_tail
= skb
;
306 static inline struct sk_buff
*cxgbit_sock_dequeue_wr(struct cxgbit_sock
*csk
)
308 struct sk_buff
*skb
= csk
->wr_pending_head
;
311 csk
->wr_pending_head
= cxgbit_skcb_tx_wr_next(skb
);
312 cxgbit_skcb_tx_wr_next(skb
) = NULL
;
317 typedef void (*cxgbit_cplhandler_func
)(struct cxgbit_device
*,
320 int cxgbit_setup_np(struct iscsi_np
*, struct sockaddr_storage
*);
321 int cxgbit_setup_conn_digest(struct cxgbit_sock
*);
322 int cxgbit_accept_np(struct iscsi_np
*, struct iscsi_conn
*);
323 void cxgbit_free_np(struct iscsi_np
*);
324 void cxgbit_free_conn(struct iscsi_conn
*);
325 extern cxgbit_cplhandler_func cxgbit_cplhandlers
[NUM_CPL_CMDS
];
326 int cxgbit_get_login_rx(struct iscsi_conn
*, struct iscsi_login
*);
327 int cxgbit_rx_data_ack(struct cxgbit_sock
*);
328 int cxgbit_l2t_send(struct cxgbit_device
*, struct sk_buff
*,
330 void cxgbit_push_tx_frames(struct cxgbit_sock
*);
331 int cxgbit_put_login_tx(struct iscsi_conn
*, struct iscsi_login
*, u32
);
332 int cxgbit_xmit_pdu(struct iscsi_conn
*, struct iscsi_cmd
*,
333 struct iscsi_datain_req
*, const void *, u32
);
334 void cxgbit_get_r2t_ttt(struct iscsi_conn
*, struct iscsi_cmd
*,
336 u32
cxgbit_send_tx_flowc_wr(struct cxgbit_sock
*);
337 int cxgbit_ofld_send(struct cxgbit_device
*, struct sk_buff
*);
338 void cxgbit_get_rx_pdu(struct iscsi_conn
*);
339 int cxgbit_validate_params(struct iscsi_conn
*);
340 struct cxgbit_device
*cxgbit_find_device(struct net_device
*, u8
*);
343 int cxgbit_ddp_init(struct cxgbit_device
*);
344 int cxgbit_setup_conn_pgidx(struct cxgbit_sock
*, u32
);
345 int cxgbit_reserve_ttt(struct cxgbit_sock
*, struct iscsi_cmd
*);
346 void cxgbit_release_cmd(struct iscsi_conn
*, struct iscsi_cmd
*);
349 struct cxgbi_ppm
*cdev2ppm(struct cxgbit_device
*cdev
)
351 return (struct cxgbi_ppm
*)(*cdev
->lldi
.iscsi_ppm
);
353 #endif /* __CXGBIT_H__ */