2 * cxgb3i_offload.h: Chelsio S3xx iscsi offloaded tcp connection management
4 * Copyright (C) 2003-2008 Chelsio Communications. All rights reserved.
6 * This program is distributed in the hope that it will be useful, but WITHOUT
7 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8 * FITNESS FOR A PARTICULAR PURPOSE. See the LICENSE file included in this
9 * release for licensing terms and conditions.
11 * Written by: Dimitris Michailidis (dm@chelsio.com)
12 * Karen Xie (kxie@chelsio.com)
15 #ifndef _CXGB3I_OFFLOAD_H
16 #define _CXGB3I_OFFLOAD_H
18 #include <linux/skbuff.h>
24 #include "cxgb3_offload.h"
26 #define cxgb3i_log_error(fmt...) printk(KERN_ERR "cxgb3i: ERR! " fmt)
27 #define cxgb3i_log_warn(fmt...) printk(KERN_WARNING "cxgb3i: WARN! " fmt)
28 #define cxgb3i_log_info(fmt...) printk(KERN_INFO "cxgb3i: " fmt)
29 #define cxgb3i_log_debug(fmt, args...) \
30 printk(KERN_INFO "cxgb3i: %s - " fmt, __func__ , ## args)
33 * struct s3_conn - an iscsi tcp connection structure
35 * @dev: net device of with connection
36 * @cdev: adapter t3cdev for net device
37 * @flags: see c3cn_flags below
38 * @tid: connection id assigned by the h/w
39 * @qset: queue set used by connection
40 * @mss_idx: Maximum Segment Size table index
41 * @l2t: ARP resolution entry for offload packets
42 * @wr_max: maximum in-flight writes
43 * @wr_avail: number of writes available
44 * @wr_unacked: writes since last request for completion notification
45 * @wr_pending_head: head of pending write queue
46 * @wr_pending_tail: tail of pending write queue
47 * @cpl_close: skb for cpl_close_req
48 * @cpl_abort_req: skb for cpl_abort_req
49 * @cpl_abort_rpl: skb for cpl_abort_rpl
50 * @lock: connection status lock
51 * @refcnt: reference count on connection
52 * @state: connection state
53 * @saddr: source ip/port address
54 * @daddr: destination ip/port address
55 * @dst_cache: reference to destination route
56 * @receive_queue: received PDUs
57 * @write_queue: un-pushed pending writes
58 * @retry_timer: retry timer for various operations
59 * @err: connection error status
60 * @callback_lock: lock for opaque user context
61 * @user_data: opaque user context
62 * @rcv_nxt: next receive seq. #
63 * @copied_seq: head of yet unread data
64 * @rcv_wup: rcv_nxt on last window update sent
65 * @snd_nxt: next sequence we send
66 * @snd_una: first byte we want an ack for
67 * @write_seq: tail+1 of data held in send buffer
70 struct net_device
*dev
;
76 struct l2t_entry
*l2t
;
80 struct sk_buff
*wr_pending_head
;
81 struct sk_buff
*wr_pending_tail
;
82 struct sk_buff
*cpl_close
;
83 struct sk_buff
*cpl_abort_req
;
84 struct sk_buff
*cpl_abort_rpl
;
87 volatile unsigned int state
;
88 struct sockaddr_in saddr
;
89 struct sockaddr_in daddr
;
90 struct dst_entry
*dst_cache
;
91 struct sk_buff_head receive_queue
;
92 struct sk_buff_head write_queue
;
93 struct timer_list retry_timer
;
95 rwlock_t callback_lock
;
110 C3CN_STATE_CONNECTING
= 1,
111 C3CN_STATE_ESTABLISHED
,
112 C3CN_STATE_ACTIVE_CLOSE
,
113 C3CN_STATE_PASSIVE_CLOSE
,
114 C3CN_STATE_CLOSE_WAIT_1
,
115 C3CN_STATE_CLOSE_WAIT_2
,
120 static inline unsigned int c3cn_is_closing(const struct s3_conn
*c3cn
)
122 return c3cn
->state
>= C3CN_STATE_ACTIVE_CLOSE
;
124 static inline unsigned int c3cn_is_established(const struct s3_conn
*c3cn
)
126 return c3cn
->state
== C3CN_STATE_ESTABLISHED
;
130 * Connection flags -- many to track some close related events.
133 C3CN_ABORT_RPL_RCVD
, /* received one ABORT_RPL_RSS message */
134 C3CN_ABORT_REQ_RCVD
, /* received one ABORT_REQ_RSS message */
135 C3CN_ABORT_RPL_PENDING
, /* expecting an abort reply */
136 C3CN_TX_DATA_SENT
, /* already sent a TX_DATA WR */
137 C3CN_ACTIVE_CLOSE_NEEDED
, /* need to be closed */
138 C3CN_OFFLOAD_DOWN
/* offload function off */
142 * cxgb3i_sdev_data - Per adapter data.
143 * Linked off of each Ethernet device port on the adapter.
144 * Also available via the t3cdev structure since we have pointers to our port
145 * net_device's there ...
147 * @list: list head to link elements
148 * @cdev: t3cdev adapter
149 * @client: CPL client pointer
150 * @ports: array of adapter ports
151 * @sport_next: next port
152 * @sport_conn: source port connection
154 struct cxgb3i_sdev_data
{
155 struct list_head list
;
157 struct cxgb3_client
*client
;
158 struct adap_ports ports
;
160 unsigned int sport_next
;
161 struct s3_conn
*sport_conn
[0];
163 #define NDEV2CDATA(ndev) (*(struct cxgb3i_sdev_data **)&(ndev)->ec_ptr)
164 #define CXGB3_SDEV_DATA(cdev) NDEV2CDATA((cdev)->lldev)
166 void cxgb3i_sdev_cleanup(void);
167 int cxgb3i_sdev_init(cxgb3_cpl_handler_func
*);
168 void cxgb3i_sdev_add(struct t3cdev
*, struct cxgb3_client
*);
169 void cxgb3i_sdev_remove(struct t3cdev
*);
171 struct s3_conn
*cxgb3i_c3cn_create(void);
172 int cxgb3i_c3cn_connect(struct net_device
*, struct s3_conn
*,
173 struct sockaddr_in
*);
174 void cxgb3i_c3cn_rx_credits(struct s3_conn
*, int);
175 int cxgb3i_c3cn_send_pdus(struct s3_conn
*, struct sk_buff
*);
176 void cxgb3i_c3cn_release(struct s3_conn
*);
179 * cxgb3_skb_cb - control block for received pdu state and ULP mode management.
181 * @flag: see C3CB_FLAG_* below
182 * @ulp_mode: ULP mode/submode of sk_buff
183 * @seq: tcp sequence number
185 struct cxgb3_skb_rx_cb
{
186 __u32 ddigest
; /* data digest */
187 __u32 pdulen
; /* recovered pdu length */
190 struct cxgb3_skb_tx_cb
{
191 struct sk_buff
*wr_next
; /* next wr */
194 struct cxgb3_skb_cb
{
199 struct cxgb3_skb_rx_cb rx
;
200 struct cxgb3_skb_tx_cb tx
;
204 #define CXGB3_SKB_CB(skb) ((struct cxgb3_skb_cb *)&((skb)->cb[0]))
205 #define skb_flags(skb) (CXGB3_SKB_CB(skb)->flags)
206 #define skb_ulp_mode(skb) (CXGB3_SKB_CB(skb)->ulp_mode)
207 #define skb_tcp_seq(skb) (CXGB3_SKB_CB(skb)->seq)
208 #define skb_rx_ddigest(skb) (CXGB3_SKB_CB(skb)->rx.ddigest)
209 #define skb_rx_pdulen(skb) (CXGB3_SKB_CB(skb)->rx.pdulen)
210 #define skb_tx_wr_next(skb) (CXGB3_SKB_CB(skb)->tx.wr_next)
213 C3CB_FLAG_NEED_HDR
= 1 << 0, /* packet needs a TX_DATA_WR header */
214 C3CB_FLAG_NO_APPEND
= 1 << 1, /* don't grow this skb */
215 C3CB_FLAG_COMPL
= 1 << 2, /* request WR completion */
220 * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
221 * and for which we must reserve space.
223 struct sge_opaque_hdr
{
225 dma_addr_t addr
[MAX_SKB_FRAGS
+ 1];
228 /* for TX: a skb must have a headroom of at least TX_HEADER_LEN bytes */
229 #define TX_HEADER_LEN \
230 (sizeof(struct tx_data_wr) + sizeof(struct sge_opaque_hdr))
231 #define SKB_TX_HEADROOM SKB_MAX_HEAD(TX_HEADER_LEN)
234 * get and set private ip for iscsi traffic
236 #define cxgb3i_get_private_ipv4addr(ndev) \
237 (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr)
238 #define cxgb3i_set_private_ipv4addr(ndev, addr) \
239 (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) = addr
241 /* max. connections per adapter */
242 #define CXGB3I_MAX_CONN 16384
243 #endif /* _CXGB3_OFFLOAD_H */