diff options
author | kxie@chelsio.com <kxie@chelsio.com> | 2010-08-16 23:55:53 -0400 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2010-09-05 13:28:35 -0400 |
commit | 9ba682f01e2ffe47e6ea47fcc6cdfe39d7a71571 (patch) | |
tree | 6e46beeb7796e5ed61cf5b70334763d533197469 /drivers/scsi/cxgbi/libcxgbi.h | |
parent | ec21b3b0dbbaf5965f6b508cb6b48d9fe5bb6ab5 (diff) |
[SCSI] libcxgbi: common library for cxgb3i and cxgb4i
[PATCH v5 1/3] libcxgbi: common library for cxgb3i and cxgb4i
From: Karen Xie <kxie@chelsio.com>
Extracts common functions to libcxgbi.
Signed-off-by: Karen Xie <kxie@chelsio.com>
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/cxgbi/libcxgbi.h')
-rw-r--r-- | drivers/scsi/cxgbi/libcxgbi.h | 753 |
1 files changed, 753 insertions, 0 deletions
diff --git a/drivers/scsi/cxgbi/libcxgbi.h b/drivers/scsi/cxgbi/libcxgbi.h new file mode 100644 index 000000000000..40551f3be5dc --- /dev/null +++ b/drivers/scsi/cxgbi/libcxgbi.h | |||
@@ -0,0 +1,753 @@ | |||
1 | /* | ||
2 | * libcxgbi.h: Chelsio common library for T3/T4 iSCSI driver. | ||
3 | * | ||
4 | * Copyright (c) 2010 Chelsio Communications, Inc. | ||
5 | * | ||
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> | ||
27 | #include <scsi/scsi_device.h> | ||
28 | #include <scsi/libiscsi_tcp.h> | ||
29 | |||
30 | enum cxgbi_dbg_flag { | ||
31 | CXGBI_DBG_ISCSI, | ||
32 | CXGBI_DBG_DDP, | ||
33 | CXGBI_DBG_TOE, | ||
34 | CXGBI_DBG_SOCK, | ||
35 | |||
36 | CXGBI_DBG_PDU_TX, | ||
37 | CXGBI_DBG_PDU_RX, | ||
38 | CXGBI_DBG_DEV, | ||
39 | }; | ||
40 | |||
41 | #define log_debug(level, fmt, ...) \ | ||
42 | do { \ | ||
43 | if (dbg_level & (level)) \ | ||
44 | pr_info(fmt, ##__VA_ARGS__); \ | ||
45 | } while (0) | ||
46 | |||
47 | /* max. connections per adapter */ | ||
48 | #define CXGBI_MAX_CONN 16384 | ||
49 | |||
50 | /* always allocate rooms for AHS */ | ||
51 | #define SKB_TX_ISCSI_PDU_HEADER_MAX \ | ||
52 | (sizeof(struct iscsi_hdr) + ISCSI_MAX_AHS_SIZE) | ||
53 | |||
54 | #define ISCSI_PDU_NONPAYLOAD_LEN 312 /* bhs(48) + ahs(256) + digest(8)*/ | ||
55 | |||
56 | /* | ||
57 | * align pdu size to multiple of 512 for better performance | ||
58 | */ | ||
59 | #define cxgbi_align_pdu_size(n) do { n = (n) & (~511); } while (0) | ||
60 | |||
61 | #define ULP2_MODE_ISCSI 2 | ||
62 | |||
63 | #define ULP2_MAX_PKT_SIZE 16224 | ||
64 | #define ULP2_MAX_PDU_PAYLOAD \ | ||
65 | (ULP2_MAX_PKT_SIZE - ISCSI_PDU_NONPAYLOAD_LEN) | ||
66 | |||
67 | /* | ||
68 | * For iscsi connections HW may inserts digest bytes into the pdu. Those digest | ||
69 | * bytes are not sent by the host but are part of the TCP payload and therefore | ||
70 | * consume TCP sequence space. | ||
71 | */ | ||
72 | static const unsigned int ulp2_extra_len[] = { 0, 4, 4, 8 }; | ||
73 | static inline unsigned int cxgbi_ulp_extra_len(int submode) | ||
74 | { | ||
75 | return ulp2_extra_len[submode & 3]; | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | * struct pagepod_hdr, pagepod - pagepod format | ||
80 | */ | ||
81 | |||
82 | #define CPL_RX_DDP_STATUS_DDP_SHIFT 16 /* ddp'able */ | ||
83 | #define CPL_RX_DDP_STATUS_PAD_SHIFT 19 /* pad error */ | ||
84 | #define CPL_RX_DDP_STATUS_HCRC_SHIFT 20 /* hcrc error */ | ||
85 | #define CPL_RX_DDP_STATUS_DCRC_SHIFT 21 /* dcrc error */ | ||
86 | |||
87 | struct cxgbi_pagepod_hdr { | ||
88 | u32 vld_tid; | ||
89 | u32 pgsz_tag_clr; | ||
90 | u32 max_offset; | ||
91 | u32 page_offset; | ||
92 | u64 rsvd; | ||
93 | }; | ||
94 | |||
95 | #define PPOD_PAGES_MAX 4 | ||
96 | struct cxgbi_pagepod { | ||
97 | struct cxgbi_pagepod_hdr hdr; | ||
98 | u64 addr[PPOD_PAGES_MAX + 1]; | ||
99 | }; | ||
100 | |||
101 | struct cxgbi_tag_format { | ||
102 | unsigned char sw_bits; | ||
103 | unsigned char rsvd_bits; | ||
104 | unsigned char rsvd_shift; | ||
105 | unsigned char filler[1]; | ||
106 | u32 rsvd_mask; | ||
107 | }; | ||
108 | |||
109 | struct cxgbi_gather_list { | ||
110 | unsigned int tag; | ||
111 | unsigned int length; | ||
112 | unsigned int offset; | ||
113 | unsigned int nelem; | ||
114 | struct page **pages; | ||
115 | dma_addr_t phys_addr[0]; | ||
116 | }; | ||
117 | |||
118 | struct cxgbi_ddp_info { | ||
119 | struct kref refcnt; | ||
120 | struct cxgbi_device *cdev; | ||
121 | struct pci_dev *pdev; | ||
122 | unsigned int max_txsz; | ||
123 | unsigned int max_rxsz; | ||
124 | unsigned int llimit; | ||
125 | unsigned int ulimit; | ||
126 | unsigned int nppods; | ||
127 | unsigned int idx_last; | ||
128 | unsigned char idx_bits; | ||
129 | unsigned char filler[3]; | ||
130 | unsigned int idx_mask; | ||
131 | unsigned int rsvd_tag_mask; | ||
132 | spinlock_t map_lock; | ||
133 | struct cxgbi_gather_list **gl_map; | ||
134 | struct sk_buff **gl_skb; | ||
135 | }; | ||
136 | |||
137 | #define DDP_PGIDX_MAX 4 | ||
138 | #define DDP_THRESHOLD 2048 | ||
139 | |||
140 | #define PPOD_PAGES_SHIFT 2 /* 4 pages per pod */ | ||
141 | |||
142 | #define PPOD_SIZE sizeof(struct cxgbi_pagepod) /* 64 */ | ||
143 | #define PPOD_SIZE_SHIFT 6 | ||
144 | |||
145 | #define ULPMEM_DSGL_MAX_NPPODS 16 /* 1024/PPOD_SIZE */ | ||
146 | #define ULPMEM_IDATA_MAX_NPPODS 4 /* 256/PPOD_SIZE */ | ||
147 | #define PCIE_MEMWIN_MAX_NPPODS 16 /* 1024/PPOD_SIZE */ | ||
148 | |||
149 | #define PPOD_COLOR_SHIFT 0 | ||
150 | #define PPOD_COLOR(x) ((x) << PPOD_COLOR_SHIFT) | ||
151 | |||
152 | #define PPOD_IDX_SHIFT 6 | ||
153 | #define PPOD_IDX_MAX_SIZE 24 | ||
154 | |||
155 | #define PPOD_TID_SHIFT 0 | ||
156 | #define PPOD_TID(x) ((x) << PPOD_TID_SHIFT) | ||
157 | |||
158 | #define PPOD_TAG_SHIFT 6 | ||
159 | #define PPOD_TAG(x) ((x) << PPOD_TAG_SHIFT) | ||
160 | |||
161 | #define PPOD_VALID_SHIFT 24 | ||
162 | #define PPOD_VALID(x) ((x) << PPOD_VALID_SHIFT) | ||
163 | #define PPOD_VALID_FLAG PPOD_VALID(1U) | ||
164 | |||
165 | #define W_TCB_ULP_TYPE 0 | ||
166 | #define TCB_ULP_TYPE_SHIFT 0 | ||
167 | #define TCB_ULP_TYPE_MASK 0xfULL | ||
168 | #define TCB_ULP_TYPE(x) ((x) << TCB_ULP_TYPE_SHIFT) | ||
169 | |||
170 | #define W_TCB_ULP_RAW 0 | ||
171 | #define TCB_ULP_RAW_SHIFT 4 | ||
172 | #define TCB_ULP_RAW_MASK 0xffULL | ||
173 | #define TCB_ULP_RAW(x) ((x) << TCB_ULP_RAW_SHIFT) | ||
174 | |||
175 | /* | ||
176 | * sge_opaque_hdr - | ||
177 | * Opaque version of structure the SGE stores at skb->head of TX_DATA packets | ||
178 | * and for which we must reserve space. | ||
179 | */ | ||
180 | struct sge_opaque_hdr { | ||
181 | void *dev; | ||
182 | dma_addr_t addr[MAX_SKB_FRAGS + 1]; | ||
183 | }; | ||
184 | |||
185 | struct cxgbi_sock { | ||
186 | struct cxgbi_device *cdev; | ||
187 | |||
188 | int tid; | ||
189 | int atid; | ||
190 | unsigned long flags; | ||
191 | unsigned int mtu; | ||
192 | unsigned short rss_qid; | ||
193 | unsigned short txq_idx; | ||
194 | unsigned short advmss; | ||
195 | unsigned int tx_chan; | ||
196 | unsigned int rx_chan; | ||
197 | unsigned int mss_idx; | ||
198 | unsigned int smac_idx; | ||
199 | unsigned char port_id; | ||
200 | int wr_max_cred; | ||
201 | int wr_cred; | ||
202 | int wr_una_cred; | ||
203 | unsigned char hcrc_len; | ||
204 | unsigned char dcrc_len; | ||
205 | |||
206 | void *l2t; | ||
207 | struct sk_buff *wr_pending_head; | ||
208 | struct sk_buff *wr_pending_tail; | ||
209 | struct sk_buff *cpl_close; | ||
210 | struct sk_buff *cpl_abort_req; | ||
211 | struct sk_buff *cpl_abort_rpl; | ||
212 | struct sk_buff *skb_ulp_lhdr; | ||
213 | spinlock_t lock; | ||
214 | struct kref refcnt; | ||
215 | unsigned int state; | ||
216 | struct sockaddr_in saddr; | ||
217 | struct sockaddr_in daddr; | ||
218 | struct dst_entry *dst; | ||
219 | struct sk_buff_head receive_queue; | ||
220 | struct sk_buff_head write_queue; | ||
221 | struct timer_list retry_timer; | ||
222 | int err; | ||
223 | rwlock_t callback_lock; | ||
224 | void *user_data; | ||
225 | |||
226 | u32 rcv_nxt; | ||
227 | u32 copied_seq; | ||
228 | u32 rcv_wup; | ||
229 | u32 snd_nxt; | ||
230 | u32 snd_una; | ||
231 | u32 write_seq; | ||
232 | }; | ||
233 | |||
234 | /* | ||
235 | * connection states | ||
236 | */ | ||
237 | enum cxgbi_sock_states{ | ||
238 | CTP_CLOSED, | ||
239 | CTP_CONNECTING, | ||
240 | CTP_ACTIVE_OPEN, | ||
241 | CTP_ESTABLISHED, | ||
242 | CTP_ACTIVE_CLOSE, | ||
243 | CTP_PASSIVE_CLOSE, | ||
244 | CTP_CLOSE_WAIT_1, | ||
245 | CTP_CLOSE_WAIT_2, | ||
246 | CTP_ABORTING, | ||
247 | }; | ||
248 | |||
249 | /* | ||
250 | * Connection flags -- many to track some close related events. | ||
251 | */ | ||
252 | enum cxgbi_sock_flags { | ||
253 | CTPF_ABORT_RPL_RCVD, /*received one ABORT_RPL_RSS message */ | ||
254 | CTPF_ABORT_REQ_RCVD, /*received one ABORT_REQ_RSS message */ | ||
255 | CTPF_ABORT_RPL_PENDING, /* expecting an abort reply */ | ||
256 | CTPF_TX_DATA_SENT, /* already sent a TX_DATA WR */ | ||
257 | CTPF_ACTIVE_CLOSE_NEEDED,/* need to be closed */ | ||
258 | CTPF_HAS_ATID, /* reserved atid */ | ||
259 | CTPF_HAS_TID, /* reserved hw tid */ | ||
260 | CTPF_OFFLOAD_DOWN, /* offload function off */ | ||
261 | }; | ||
262 | |||
263 | struct cxgbi_skb_rx_cb { | ||
264 | __u32 ddigest; | ||
265 | __u32 pdulen; | ||
266 | }; | ||
267 | |||
268 | struct cxgbi_skb_tx_cb { | ||
269 | void *l2t; | ||
270 | struct sk_buff *wr_next; | ||
271 | }; | ||
272 | |||
273 | enum cxgbi_skcb_flags { | ||
274 | SKCBF_TX_NEED_HDR, /* packet needs a header */ | ||
275 | SKCBF_RX_COALESCED, /* received whole pdu */ | ||
276 | SKCBF_RX_HDR, /* recieved pdu header */ | ||
277 | SKCBF_RX_DATA, /* recieved pdu payload */ | ||
278 | SKCBF_RX_STATUS, /* recieved ddp status */ | ||
279 | SKCBF_RX_DATA_DDPD, /* pdu payload ddp'd */ | ||
280 | SKCBF_RX_HCRC_ERR, /* header digest error */ | ||
281 | SKCBF_RX_DCRC_ERR, /* data digest error */ | ||
282 | SKCBF_RX_PAD_ERR, /* padding byte error */ | ||
283 | }; | ||
284 | |||
285 | struct cxgbi_skb_cb { | ||
286 | unsigned char ulp_mode; | ||
287 | unsigned long flags; | ||
288 | unsigned int seq; | ||
289 | union { | ||
290 | struct cxgbi_skb_rx_cb rx; | ||
291 | struct cxgbi_skb_tx_cb tx; | ||
292 | }; | ||
293 | }; | ||
294 | |||
295 | #define CXGBI_SKB_CB(skb) ((struct cxgbi_skb_cb *)&((skb)->cb[0])) | ||
296 | #define cxgbi_skcb_flags(skb) (CXGBI_SKB_CB(skb)->flags) | ||
297 | #define cxgbi_skcb_ulp_mode(skb) (CXGBI_SKB_CB(skb)->ulp_mode) | ||
298 | #define cxgbi_skcb_tcp_seq(skb) (CXGBI_SKB_CB(skb)->seq) | ||
299 | #define cxgbi_skcb_rx_ddigest(skb) (CXGBI_SKB_CB(skb)->rx.ddigest) | ||
300 | #define cxgbi_skcb_rx_pdulen(skb) (CXGBI_SKB_CB(skb)->rx.pdulen) | ||
301 | #define cxgbi_skcb_tx_wr_next(skb) (CXGBI_SKB_CB(skb)->tx.wr_next) | ||
302 | |||
303 | static inline void cxgbi_skcb_set_flag(struct sk_buff *skb, | ||
304 | enum cxgbi_skcb_flags flag) | ||
305 | { | ||
306 | __set_bit(flag, &(cxgbi_skcb_flags(skb))); | ||
307 | } | ||
308 | |||
309 | static inline void cxgbi_skcb_clear_flag(struct sk_buff *skb, | ||
310 | enum cxgbi_skcb_flags flag) | ||
311 | { | ||
312 | __clear_bit(flag, &(cxgbi_skcb_flags(skb))); | ||
313 | } | ||
314 | |||
315 | static inline int cxgbi_skcb_test_flag(struct sk_buff *skb, | ||
316 | enum cxgbi_skcb_flags flag) | ||
317 | { | ||
318 | return test_bit(flag, &(cxgbi_skcb_flags(skb))); | ||
319 | } | ||
320 | |||
321 | static inline void cxgbi_sock_set_flag(struct cxgbi_sock *csk, | ||
322 | enum cxgbi_sock_flags flag) | ||
323 | { | ||
324 | __set_bit(flag, &csk->flags); | ||
325 | log_debug(1 << CXGBI_DBG_SOCK, | ||
326 | "csk 0x%p,%u,0x%lx, bit %d.\n", | ||
327 | csk, csk->state, csk->flags, flag); | ||
328 | } | ||
329 | |||
330 | static inline void cxgbi_sock_clear_flag(struct cxgbi_sock *csk, | ||
331 | enum cxgbi_sock_flags flag) | ||
332 | { | ||
333 | __clear_bit(flag, &csk->flags); | ||
334 | log_debug(1 << CXGBI_DBG_SOCK, | ||
335 | "csk 0x%p,%u,0x%lx, bit %d.\n", | ||
336 | csk, csk->state, csk->flags, flag); | ||
337 | } | ||
338 | |||
339 | static inline int cxgbi_sock_flag(struct cxgbi_sock *csk, | ||
340 | enum cxgbi_sock_flags flag) | ||
341 | { | ||
342 | if (csk == NULL) | ||
343 | return 0; | ||
344 | return test_bit(flag, &csk->flags); | ||
345 | } | ||
346 | |||
347 | static inline void cxgbi_sock_set_state(struct cxgbi_sock *csk, int state) | ||
348 | { | ||
349 | log_debug(1 << CXGBI_DBG_SOCK, | ||
350 | "csk 0x%p,%u,0x%lx, state -> %u.\n", | ||
351 | csk, csk->state, csk->flags, state); | ||
352 | csk->state = state; | ||
353 | } | ||
354 | |||
355 | static inline void cxgbi_sock_free(struct kref *kref) | ||
356 | { | ||
357 | struct cxgbi_sock *csk = container_of(kref, | ||
358 | struct cxgbi_sock, | ||
359 | refcnt); | ||
360 | if (csk) { | ||
361 | log_debug(1 << CXGBI_DBG_SOCK, | ||
362 | "free csk 0x%p, state %u, flags 0x%lx\n", | ||
363 | csk, csk->state, csk->flags); | ||
364 | kfree(csk); | ||
365 | } | ||
366 | } | ||
367 | |||
368 | static inline void __cxgbi_sock_put(const char *fn, struct cxgbi_sock *csk) | ||
369 | { | ||
370 | log_debug(1 << CXGBI_DBG_SOCK, | ||
371 | "%s, put csk 0x%p, ref %u-1.\n", | ||
372 | fn, csk, atomic_read(&csk->refcnt.refcount)); | ||
373 | kref_put(&csk->refcnt, cxgbi_sock_free); | ||
374 | } | ||
375 | #define cxgbi_sock_put(csk) __cxgbi_sock_put(__func__, csk) | ||
376 | |||
377 | static inline void __cxgbi_sock_get(const char *fn, struct cxgbi_sock *csk) | ||
378 | { | ||
379 | log_debug(1 << CXGBI_DBG_SOCK, | ||
380 | "%s, get csk 0x%p, ref %u+1.\n", | ||
381 | fn, csk, atomic_read(&csk->refcnt.refcount)); | ||
382 | kref_get(&csk->refcnt); | ||
383 | } | ||
384 | #define cxgbi_sock_get(csk) __cxgbi_sock_get(__func__, csk) | ||
385 | |||
386 | static inline int cxgbi_sock_is_closing(struct cxgbi_sock *csk) | ||
387 | { | ||
388 | return csk->state >= CTP_ACTIVE_CLOSE; | ||
389 | } | ||
390 | |||
391 | static inline int cxgbi_sock_is_established(struct cxgbi_sock *csk) | ||
392 | { | ||
393 | return csk->state == CTP_ESTABLISHED; | ||
394 | } | ||
395 | |||
396 | static inline void cxgbi_sock_purge_write_queue(struct cxgbi_sock *csk) | ||
397 | { | ||
398 | struct sk_buff *skb; | ||
399 | |||
400 | while ((skb = __skb_dequeue(&csk->write_queue))) | ||
401 | __kfree_skb(skb); | ||
402 | } | ||
403 | |||
404 | static inline unsigned int cxgbi_sock_compute_wscale(unsigned int win) | ||
405 | { | ||
406 | unsigned int wscale = 0; | ||
407 | |||
408 | while (wscale < 14 && (65535 << wscale) < win) | ||
409 | wscale++; | ||
410 | return wscale; | ||
411 | } | ||
412 | |||
413 | static inline struct sk_buff *alloc_cpl(int cpl_len, int dlen, gfp_t gfp) | ||
414 | { | ||
415 | int wrlen = roundup(cpl_len, 16); | ||
416 | struct sk_buff *skb = alloc_skb(wrlen + dlen, gfp); | ||
417 | |||
418 | if (skb) { | ||
419 | __skb_put(skb, wrlen); | ||
420 | memset(skb->head, 0, wrlen + dlen); | ||
421 | } else | ||
422 | pr_info("alloc cpl skb %u+%u, OOM.\n", cpl_len, dlen); | ||
423 | return skb; | ||
424 | } | ||
425 | |||
426 | |||
427 | /* | ||
428 | * The number of WRs needed for an skb depends on the number of fragments | ||
429 | * in the skb and whether it has any payload in its main body. This maps the | ||
430 | * length of the gather list represented by an skb into the # of necessary WRs. | ||
431 | * The extra two fragments are for iscsi bhs and payload padding. | ||
432 | */ | ||
433 | #define SKB_WR_LIST_SIZE (MAX_SKB_FRAGS + 2) | ||
434 | |||
435 | static inline void cxgbi_sock_reset_wr_list(struct cxgbi_sock *csk) | ||
436 | { | ||
437 | csk->wr_pending_head = csk->wr_pending_tail = NULL; | ||
438 | } | ||
439 | |||
440 | static inline void cxgbi_sock_enqueue_wr(struct cxgbi_sock *csk, | ||
441 | struct sk_buff *skb) | ||
442 | { | ||
443 | cxgbi_skcb_tx_wr_next(skb) = NULL; | ||
444 | /* | ||
445 | * We want to take an extra reference since both us and the driver | ||
446 | * need to free the packet before it's really freed. We know there's | ||
447 | * just one user currently so we use atomic_set rather than skb_get | ||
448 | * to avoid the atomic op. | ||
449 | */ | ||
450 | atomic_set(&skb->users, 2); | ||
451 | |||
452 | if (!csk->wr_pending_head) | ||
453 | csk->wr_pending_head = skb; | ||
454 | else | ||
455 | cxgbi_skcb_tx_wr_next(csk->wr_pending_tail) = skb; | ||
456 | csk->wr_pending_tail = skb; | ||
457 | } | ||
458 | |||
459 | static inline int cxgbi_sock_count_pending_wrs(const struct cxgbi_sock *csk) | ||
460 | { | ||
461 | int n = 0; | ||
462 | const struct sk_buff *skb = csk->wr_pending_head; | ||
463 | |||
464 | while (skb) { | ||
465 | n += skb->csum; | ||
466 | skb = cxgbi_skcb_tx_wr_next(skb); | ||
467 | } | ||
468 | return n; | ||
469 | } | ||
470 | |||
471 | static inline struct sk_buff *cxgbi_sock_peek_wr(const struct cxgbi_sock *csk) | ||
472 | { | ||
473 | return csk->wr_pending_head; | ||
474 | } | ||
475 | |||
476 | static inline struct sk_buff *cxgbi_sock_dequeue_wr(struct cxgbi_sock *csk) | ||
477 | { | ||
478 | struct sk_buff *skb = csk->wr_pending_head; | ||
479 | |||
480 | if (likely(skb)) { | ||
481 | csk->wr_pending_head = cxgbi_skcb_tx_wr_next(skb); | ||
482 | cxgbi_skcb_tx_wr_next(skb) = NULL; | ||
483 | } | ||
484 | return skb; | ||
485 | } | ||
486 | |||
487 | void cxgbi_sock_check_wr_invariants(const struct cxgbi_sock *); | ||
488 | void cxgbi_sock_purge_wr_queue(struct cxgbi_sock *); | ||
489 | void cxgbi_sock_skb_entail(struct cxgbi_sock *, struct sk_buff *); | ||
490 | void cxgbi_sock_fail_act_open(struct cxgbi_sock *, int); | ||
491 | void cxgbi_sock_act_open_req_arp_failure(void *, struct sk_buff *); | ||
492 | void cxgbi_sock_closed(struct cxgbi_sock *); | ||
493 | void cxgbi_sock_established(struct cxgbi_sock *, unsigned int, unsigned int); | ||
494 | void cxgbi_sock_rcv_abort_rpl(struct cxgbi_sock *); | ||
495 | void cxgbi_sock_rcv_peer_close(struct cxgbi_sock *); | ||
496 | void cxgbi_sock_rcv_close_conn_rpl(struct cxgbi_sock *, u32); | ||
497 | void cxgbi_sock_rcv_wr_ack(struct cxgbi_sock *, unsigned int, unsigned int, | ||
498 | int); | ||
499 | unsigned int cxgbi_sock_select_mss(struct cxgbi_sock *, unsigned int); | ||
500 | void cxgbi_sock_free_cpl_skbs(struct cxgbi_sock *); | ||
501 | |||
502 | struct cxgbi_hba { | ||
503 | struct net_device *ndev; | ||
504 | struct Scsi_Host *shost; | ||
505 | struct cxgbi_device *cdev; | ||
506 | __be32 ipv4addr; | ||
507 | unsigned char port_id; | ||
508 | }; | ||
509 | |||
510 | struct cxgbi_ports_map { | ||
511 | unsigned int max_connect; | ||
512 | unsigned int used; | ||
513 | unsigned short sport_base; | ||
514 | spinlock_t lock; | ||
515 | unsigned int next; | ||
516 | struct cxgbi_sock **port_csk; | ||
517 | }; | ||
518 | |||
519 | #define CXGBI_FLAG_DEV_T3 0x1 | ||
520 | #define CXGBI_FLAG_DEV_T4 0x2 | ||
521 | #define CXGBI_FLAG_ADAPTER_RESET 0x4 | ||
522 | #define CXGBI_FLAG_IPV4_SET 0x10 | ||
523 | struct cxgbi_device { | ||
524 | struct list_head list_head; | ||
525 | unsigned int flags; | ||
526 | struct net_device **ports; | ||
527 | void *lldev; | ||
528 | struct cxgbi_hba **hbas; | ||
529 | const unsigned short *mtus; | ||
530 | unsigned char nmtus; | ||
531 | unsigned char nports; | ||
532 | struct pci_dev *pdev; | ||
533 | struct dentry *debugfs_root; | ||
534 | struct iscsi_transport *itp; | ||
535 | |||
536 | unsigned int pfvf; | ||
537 | unsigned int snd_win; | ||
538 | unsigned int rcv_win; | ||
539 | unsigned int rx_credit_thres; | ||
540 | unsigned int skb_tx_rsvd; | ||
541 | unsigned int skb_rx_extra; /* for msg coalesced mode */ | ||
542 | unsigned int tx_max_size; | ||
543 | unsigned int rx_max_size; | ||
544 | struct cxgbi_ports_map pmap; | ||
545 | struct cxgbi_tag_format tag_format; | ||
546 | struct cxgbi_ddp_info *ddp; | ||
547 | |||
548 | void (*dev_ddp_cleanup)(struct cxgbi_device *); | ||
549 | void (*csk_ddp_free_gl_skb)(struct cxgbi_ddp_info *, int, int); | ||
550 | int (*csk_ddp_alloc_gl_skb)(struct cxgbi_ddp_info *, int, int, gfp_t); | ||
551 | int (*csk_ddp_set)(struct cxgbi_sock *, struct cxgbi_pagepod_hdr *, | ||
552 | unsigned int, unsigned int, | ||
553 | struct cxgbi_gather_list *); | ||
554 | void (*csk_ddp_clear)(struct cxgbi_hba *, | ||
555 | unsigned int, unsigned int, unsigned int); | ||
556 | int (*csk_ddp_setup_digest)(struct cxgbi_sock *, | ||
557 | unsigned int, int, int, int); | ||
558 | int (*csk_ddp_setup_pgidx)(struct cxgbi_sock *, | ||
559 | unsigned int, int, bool); | ||
560 | |||
561 | void (*csk_release_offload_resources)(struct cxgbi_sock *); | ||
562 | int (*csk_rx_pdu_ready)(struct cxgbi_sock *, struct sk_buff *); | ||
563 | u32 (*csk_send_rx_credits)(struct cxgbi_sock *, u32); | ||
564 | int (*csk_push_tx_frames)(struct cxgbi_sock *, int); | ||
565 | void (*csk_send_abort_req)(struct cxgbi_sock *); | ||
566 | void (*csk_send_close_req)(struct cxgbi_sock *); | ||
567 | int (*csk_alloc_cpls)(struct cxgbi_sock *); | ||
568 | int (*csk_init_act_open)(struct cxgbi_sock *); | ||
569 | |||
570 | void *dd_data; | ||
571 | }; | ||
572 | #define cxgbi_cdev_priv(cdev) ((cdev)->dd_data) | ||
573 | |||
574 | struct cxgbi_conn { | ||
575 | struct cxgbi_endpoint *cep; | ||
576 | struct iscsi_conn *iconn; | ||
577 | struct cxgbi_hba *chba; | ||
578 | u32 task_idx_bits; | ||
579 | }; | ||
580 | |||
581 | struct cxgbi_endpoint { | ||
582 | struct cxgbi_conn *cconn; | ||
583 | struct cxgbi_hba *chba; | ||
584 | struct cxgbi_sock *csk; | ||
585 | }; | ||
586 | |||
587 | #define MAX_PDU_FRAGS ((ULP2_MAX_PDU_PAYLOAD + 512 - 1) / 512) | ||
588 | struct cxgbi_task_data { | ||
589 | unsigned short nr_frags; | ||
590 | skb_frag_t frags[MAX_PDU_FRAGS]; | ||
591 | struct sk_buff *skb; | ||
592 | unsigned int offset; | ||
593 | unsigned int count; | ||
594 | unsigned int sgoffset; | ||
595 | }; | ||
596 | |||
597 | static inline int cxgbi_is_ddp_tag(struct cxgbi_tag_format *tformat, u32 tag) | ||
598 | { | ||
599 | return !(tag & (1 << (tformat->rsvd_bits + tformat->rsvd_shift - 1))); | ||
600 | } | ||
601 | |||
602 | static inline int cxgbi_sw_tag_usable(struct cxgbi_tag_format *tformat, | ||
603 | u32 sw_tag) | ||
604 | { | ||
605 | sw_tag >>= (32 - tformat->rsvd_bits); | ||
606 | return !sw_tag; | ||
607 | } | ||
608 | |||
609 | static inline u32 cxgbi_set_non_ddp_tag(struct cxgbi_tag_format *tformat, | ||
610 | u32 sw_tag) | ||
611 | { | ||
612 | unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1; | ||
613 | u32 mask = (1 << shift) - 1; | ||
614 | |||
615 | if (sw_tag && (sw_tag & ~mask)) { | ||
616 | u32 v1 = sw_tag & ((1 << shift) - 1); | ||
617 | u32 v2 = (sw_tag >> (shift - 1)) << shift; | ||
618 | |||
619 | return v2 | v1 | 1 << shift; | ||
620 | } | ||
621 | |||
622 | return sw_tag | 1 << shift; | ||
623 | } | ||
624 | |||
625 | static inline u32 cxgbi_ddp_tag_base(struct cxgbi_tag_format *tformat, | ||
626 | u32 sw_tag) | ||
627 | { | ||
628 | u32 mask = (1 << tformat->rsvd_shift) - 1; | ||
629 | |||
630 | if (sw_tag && (sw_tag & ~mask)) { | ||
631 | u32 v1 = sw_tag & mask; | ||
632 | u32 v2 = sw_tag >> tformat->rsvd_shift; | ||
633 | |||
634 | v2 <<= tformat->rsvd_bits + tformat->rsvd_shift; | ||
635 | |||
636 | return v2 | v1; | ||
637 | } | ||
638 | |||
639 | return sw_tag; | ||
640 | } | ||
641 | |||
642 | static inline u32 cxgbi_tag_rsvd_bits(struct cxgbi_tag_format *tformat, | ||
643 | u32 tag) | ||
644 | { | ||
645 | if (cxgbi_is_ddp_tag(tformat, tag)) | ||
646 | return (tag >> tformat->rsvd_shift) & tformat->rsvd_mask; | ||
647 | |||
648 | return 0; | ||
649 | } | ||
650 | |||
651 | static inline u32 cxgbi_tag_nonrsvd_bits(struct cxgbi_tag_format *tformat, | ||
652 | u32 tag) | ||
653 | { | ||
654 | unsigned char shift = tformat->rsvd_bits + tformat->rsvd_shift - 1; | ||
655 | u32 v1, v2; | ||
656 | |||
657 | if (cxgbi_is_ddp_tag(tformat, tag)) { | ||
658 | v1 = tag & ((1 << tformat->rsvd_shift) - 1); | ||
659 | v2 = (tag >> (shift + 1)) << tformat->rsvd_shift; | ||
660 | } else { | ||
661 | u32 mask = (1 << shift) - 1; | ||
662 | tag &= ~(1 << shift); | ||
663 | v1 = tag & mask; | ||
664 | v2 = (tag >> 1) & ~mask; | ||
665 | } | ||
666 | return v1 | v2; | ||
667 | } | ||
668 | |||
669 | static inline void *cxgbi_alloc_big_mem(unsigned int size, | ||
670 | gfp_t gfp) | ||
671 | { | ||
672 | void *p = kmalloc(size, gfp); | ||
673 | if (!p) | ||
674 | p = vmalloc(size); | ||
675 | if (p) | ||
676 | memset(p, 0, size); | ||
677 | return p; | ||
678 | } | ||
679 | |||
680 | static inline void cxgbi_free_big_mem(void *addr) | ||
681 | { | ||
682 | if (is_vmalloc_addr(addr)) | ||
683 | vfree(addr); | ||
684 | else | ||
685 | kfree(addr); | ||
686 | } | ||
687 | |||
688 | static inline void cxgbi_set_iscsi_ipv4(struct cxgbi_hba *chba, __be32 ipaddr) | ||
689 | { | ||
690 | if (chba->cdev->flags & CXGBI_FLAG_IPV4_SET) | ||
691 | chba->ipv4addr = ipaddr; | ||
692 | else | ||
693 | pr_info("set iscsi ipv4 NOT supported, using %s ipv4.\n", | ||
694 | chba->ndev->name); | ||
695 | } | ||
696 | |||
697 | static inline __be32 cxgbi_get_iscsi_ipv4(struct cxgbi_hba *chba) | ||
698 | { | ||
699 | return chba->ipv4addr; | ||
700 | } | ||
701 | |||
702 | struct cxgbi_device *cxgbi_device_register(unsigned int, unsigned int); | ||
703 | void cxgbi_device_unregister(struct cxgbi_device *); | ||
704 | void cxgbi_device_unregister_all(unsigned int flag); | ||
705 | struct cxgbi_device *cxgbi_device_find_by_lldev(void *); | ||
706 | int cxgbi_hbas_add(struct cxgbi_device *, unsigned int, unsigned int, | ||
707 | struct scsi_host_template *, | ||
708 | struct scsi_transport_template *); | ||
709 | void cxgbi_hbas_remove(struct cxgbi_device *); | ||
710 | |||
711 | int cxgbi_device_portmap_create(struct cxgbi_device *cdev, unsigned int base, | ||
712 | unsigned int max_conn); | ||
713 | void cxgbi_device_portmap_cleanup(struct cxgbi_device *cdev); | ||
714 | |||
715 | void cxgbi_conn_tx_open(struct cxgbi_sock *); | ||
716 | void cxgbi_conn_pdu_ready(struct cxgbi_sock *); | ||
717 | int cxgbi_conn_alloc_pdu(struct iscsi_task *, u8); | ||
718 | int cxgbi_conn_init_pdu(struct iscsi_task *, unsigned int , unsigned int); | ||
719 | int cxgbi_conn_xmit_pdu(struct iscsi_task *); | ||
720 | |||
721 | void cxgbi_cleanup_task(struct iscsi_task *task); | ||
722 | |||
723 | void cxgbi_get_conn_stats(struct iscsi_cls_conn *, struct iscsi_stats *); | ||
724 | int cxgbi_set_conn_param(struct iscsi_cls_conn *, | ||
725 | enum iscsi_param, char *, int); | ||
726 | int cxgbi_get_conn_param(struct iscsi_cls_conn *, enum iscsi_param, char *); | ||
727 | struct iscsi_cls_conn *cxgbi_create_conn(struct iscsi_cls_session *, u32); | ||
728 | int cxgbi_bind_conn(struct iscsi_cls_session *, | ||
729 | struct iscsi_cls_conn *, u64, int); | ||
730 | void cxgbi_destroy_session(struct iscsi_cls_session *); | ||
731 | struct iscsi_cls_session *cxgbi_create_session(struct iscsi_endpoint *, | ||
732 | u16, u16, u32); | ||
733 | int cxgbi_set_host_param(struct Scsi_Host *, | ||
734 | enum iscsi_host_param, char *, int); | ||
735 | int cxgbi_get_host_param(struct Scsi_Host *, enum iscsi_host_param, char *); | ||
736 | struct iscsi_endpoint *cxgbi_ep_connect(struct Scsi_Host *, | ||
737 | struct sockaddr *, int); | ||
738 | int cxgbi_ep_poll(struct iscsi_endpoint *, int); | ||
739 | void cxgbi_ep_disconnect(struct iscsi_endpoint *); | ||
740 | |||
741 | int cxgbi_iscsi_init(struct iscsi_transport *, | ||
742 | struct scsi_transport_template **); | ||
743 | void cxgbi_iscsi_cleanup(struct iscsi_transport *, | ||
744 | struct scsi_transport_template **); | ||
745 | void cxgbi_parse_pdu_itt(struct iscsi_conn *, itt_t, int *, int *); | ||
746 | int cxgbi_ddp_init(struct cxgbi_device *, unsigned int, unsigned int, | ||
747 | unsigned int, unsigned int); | ||
748 | int cxgbi_ddp_cleanup(struct cxgbi_device *); | ||
749 | void cxgbi_ddp_page_size_factor(int *); | ||
750 | void cxgbi_ddp_ppod_clear(struct cxgbi_pagepod *); | ||
751 | void cxgbi_ddp_ppod_set(struct cxgbi_pagepod *, struct cxgbi_pagepod_hdr *, | ||
752 | struct cxgbi_gather_list *, unsigned int); | ||
753 | #endif /*__LIBCXGBI_H__*/ | ||