]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/scsi/cxgb3i/cxgb3i_offload.h
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jbarnes...
[linux-2.6-omap-h63xx.git] / drivers / scsi / cxgb3i / cxgb3i_offload.h
1 /*
2  * cxgb3i_offload.h: Chelsio S3xx iscsi offloaded tcp connection management
3  *
4  * Copyright (C) 2003-2008 Chelsio Communications.  All rights reserved.
5  *
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.
10  *
11  * Written by:  Dimitris Michailidis (dm@chelsio.com)
12  *              Karen Xie (kxie@chelsio.com)
13  */
14
15 #ifndef _CXGB3I_OFFLOAD_H
16 #define _CXGB3I_OFFLOAD_H
17
18 #include <linux/skbuff.h>
19 #include <linux/in.h>
20
21 #include "common.h"
22 #include "adapter.h"
23 #include "t3cdev.h"
24 #include "cxgb3_offload.h"
25
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)
31
32 /**
33  * struct s3_conn - an iscsi tcp connection structure
34  *
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
68  */
69 struct s3_conn {
70         struct net_device *dev;
71         struct t3cdev *cdev;
72         unsigned long flags;
73         int tid;
74         int qset;
75         int mss_idx;
76         struct l2t_entry *l2t;
77         int wr_max;
78         int wr_avail;
79         int wr_unacked;
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;
85         spinlock_t lock;
86         atomic_t refcnt;
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;
94         int err;
95         rwlock_t callback_lock;
96         void *user_data;
97
98         u32 rcv_nxt;
99         u32 copied_seq;
100         u32 rcv_wup;
101         u32 snd_nxt;
102         u32 snd_una;
103         u32 write_seq;
104 };
105
106 /*
107  * connection state
108  */
109 enum conn_states {
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,
116         C3CN_STATE_ABORTING,
117         C3CN_STATE_CLOSED,
118 };
119
120 static inline unsigned int c3cn_is_closing(const struct s3_conn *c3cn)
121 {
122         return c3cn->state >= C3CN_STATE_ACTIVE_CLOSE;
123 }
124 static inline unsigned int c3cn_is_established(const struct s3_conn *c3cn)
125 {
126         return c3cn->state == C3CN_STATE_ESTABLISHED;
127 }
128
129 /*
130  * Connection flags -- many to track some close related events.
131  */
132 enum c3cn_flags {
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 */
139 };
140
141 /**
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 ...
146  *
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
153  */
154 struct cxgb3i_sdev_data {
155         struct list_head list;
156         struct t3cdev *cdev;
157         struct cxgb3_client *client;
158         struct adap_ports ports;
159         spinlock_t lock;
160         unsigned int sport_next;
161         struct s3_conn *sport_conn[0];
162 };
163 #define NDEV2CDATA(ndev) (*(struct cxgb3i_sdev_data **)&(ndev)->ec_ptr)
164 #define CXGB3_SDEV_DATA(cdev) NDEV2CDATA((cdev)->lldev)
165
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 *);
170
171 struct s3_conn *cxgb3i_c3cn_create(void);
172 int cxgb3i_c3cn_connect(struct s3_conn *, struct sockaddr_in *);
173 void cxgb3i_c3cn_rx_credits(struct s3_conn *, int);
174 int cxgb3i_c3cn_send_pdus(struct s3_conn *, struct sk_buff *);
175 void cxgb3i_c3cn_release(struct s3_conn *);
176
177 /**
178  * cxgb3_skb_cb - control block for received pdu state and ULP mode management.
179  *
180  * @flag:       see C3CB_FLAG_* below
181  * @ulp_mode:   ULP mode/submode of sk_buff
182  * @seq:        tcp sequence number
183  */
184 struct cxgb3_skb_rx_cb {
185         __u32 ddigest;                  /* data digest */
186         __u32 pdulen;                   /* recovered pdu length */
187 };
188
189 struct cxgb3_skb_tx_cb {
190         struct sk_buff *wr_next;        /* next wr */
191 };
192
193 struct cxgb3_skb_cb {
194         __u8 flags;
195         __u8 ulp_mode;
196         __u32 seq;
197         union {
198                 struct cxgb3_skb_rx_cb rx;
199                 struct cxgb3_skb_tx_cb tx;
200         };
201 };
202
203 #define CXGB3_SKB_CB(skb)       ((struct cxgb3_skb_cb *)&((skb)->cb[0]))
204 #define skb_flags(skb)          (CXGB3_SKB_CB(skb)->flags)
205 #define skb_ulp_mode(skb)       (CXGB3_SKB_CB(skb)->ulp_mode)
206 #define skb_tcp_seq(skb)        (CXGB3_SKB_CB(skb)->seq)
207 #define skb_rx_ddigest(skb)     (CXGB3_SKB_CB(skb)->rx.ddigest)
208 #define skb_rx_pdulen(skb)      (CXGB3_SKB_CB(skb)->rx.pdulen)
209 #define skb_tx_wr_next(skb)     (CXGB3_SKB_CB(skb)->tx.wr_next)
210
211 enum c3cb_flags {
212         C3CB_FLAG_NEED_HDR = 1 << 0,    /* packet needs a TX_DATA_WR header */
213         C3CB_FLAG_NO_APPEND = 1 << 1,   /* don't grow this skb */
214         C3CB_FLAG_COMPL = 1 << 2,       /* request WR completion */
215 };
216
217 /**
218  * sge_opaque_hdr -
219  * Opaque version of structure the SGE stores at skb->head of TX_DATA packets
220  * and for which we must reserve space.
221  */
222 struct sge_opaque_hdr {
223         void *dev;
224         dma_addr_t addr[MAX_SKB_FRAGS + 1];
225 };
226
227 /* for TX: a skb must have a headroom of at least TX_HEADER_LEN bytes */
228 #define TX_HEADER_LEN \
229                 (sizeof(struct tx_data_wr) + sizeof(struct sge_opaque_hdr))
230 #define SKB_TX_HEADROOM         SKB_MAX_HEAD(TX_HEADER_LEN)
231
232 /*
233  * get and set private ip for iscsi traffic
234  */
235 #define cxgb3i_get_private_ipv4addr(ndev) \
236         (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr)
237 #define cxgb3i_set_private_ipv4addr(ndev, addr) \
238         (((struct port_info *)(netdev_priv(ndev)))->iscsi_ipv4addr) = addr
239
240 /* max. connections per adapter */
241 #define CXGB3I_MAX_CONN         16384
242 #endif /* _CXGB3_OFFLOAD_H */