]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/cxgb/ulp/tom/cxgb_t3_ddp.h
This commit was generated by cvs2svn to compensate for changes in r174993,
[FreeBSD/FreeBSD.git] / sys / dev / cxgb / ulp / tom / cxgb_t3_ddp.h
1
2 /**************************************************************************
3
4 Copyright (c) 2007, Chelsio Inc.
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10  1. Redistributions of source code must retain the above copyright notice,
11     this list of conditions and the following disclaimer.
12
13  2. Neither the name of the Chelsio Corporation nor the names of its
14     contributors may be used to endorse or promote products derived from
15     this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28
29
30 $FreeBSD$
31
32 ***************************************************************************/
33
34 #ifndef T3_DDP_H
35 #define T3_DDP_H
36
37 /* Should be 1 or 2 indicating single or double kernel buffers. */
38 #define NUM_DDP_KBUF 2
39
40 /* min receive window for a connection to be considered for DDP */
41 #define MIN_DDP_RCV_WIN (48 << 10)
42
43 /* amount of Rx window not available to DDP to avoid window exhaustion */
44 #define DDP_RSVD_WIN (16 << 10)
45
46 /* # of sentinel invalid page pods at the end of a group of valid page pods */
47 #define NUM_SENTINEL_PPODS 0
48
49 /* # of pages a pagepod can hold without needing another pagepod */
50 #define PPOD_PAGES 4
51
52 /* page pods are allocated in groups of this size (must be power of 2) */
53 #define PPOD_CLUSTER_SIZE 16
54
55 /* for each TID we reserve this many page pods up front */
56 #define RSVD_PPODS_PER_TID 1
57
58 struct pagepod {
59         uint32_t pp_vld_tid;
60         uint32_t pp_pgsz_tag_color;
61         uint32_t pp_max_offset;
62         uint32_t pp_page_offset;
63         uint64_t pp_rsvd;
64         uint64_t pp_addr[5];
65 };
66
67 #define PPOD_SIZE sizeof(struct pagepod)
68
69 #define S_PPOD_TID    0
70 #define M_PPOD_TID    0xFFFFFF
71 #define V_PPOD_TID(x) ((x) << S_PPOD_TID)
72
73 #define S_PPOD_VALID    24
74 #define V_PPOD_VALID(x) ((x) << S_PPOD_VALID)
75 #define F_PPOD_VALID    V_PPOD_VALID(1U)
76
77 #define S_PPOD_COLOR    0
78 #define M_PPOD_COLOR    0x3F
79 #define V_PPOD_COLOR(x) ((x) << S_PPOD_COLOR)
80
81 #define S_PPOD_TAG    6
82 #define M_PPOD_TAG    0xFFFFFF
83 #define V_PPOD_TAG(x) ((x) << S_PPOD_TAG)
84
85 #define S_PPOD_PGSZ    30
86 #define M_PPOD_PGSZ    0x3
87 #define V_PPOD_PGSZ(x) ((x) << S_PPOD_PGSZ)
88
89 struct pci_dev;
90 #include <vm/vm.h>
91 #include <vm/vm_page.h>
92 #include <machine/bus.h>
93
94 /* DDP gather lists can specify an offset only for the first page. */
95 struct ddp_gather_list {
96         unsigned int    dgl_length;
97         unsigned int    dgl_offset;
98         unsigned int    dgl_nelem;
99         vm_page_t       *dgl_pages;
100         bus_addr_t      dgl_phys_addr[0];
101 };
102
103 struct ddp_buf_state {
104         unsigned int cur_offset;     /* offset of latest DDP notification */
105         unsigned int flags;
106         struct ddp_gather_list *gl;
107 };
108
109 struct ddp_state {
110         struct pci_dev *pdev;
111         struct ddp_buf_state buf_state[2];   /* per buffer state */
112         int cur_buf;
113         unsigned short kbuf_noinval;
114         unsigned short kbuf_idx;        /* which HW buffer is used for kbuf */
115         struct ddp_gather_list *ubuf;
116         unsigned int ubuf_nppods;       /* # of page pods for buffer 1 */
117         unsigned int ubuf_tag;
118         unsigned int ubuf_ddp_ready;
119         int get_tcb_count;
120         unsigned int kbuf_posted;
121         int cancel_ubuf;
122         unsigned int kbuf_nppods[NUM_DDP_KBUF];
123         unsigned int kbuf_tag[NUM_DDP_KBUF];
124         struct ddp_gather_list *kbuf[NUM_DDP_KBUF]; /* kernel buffer for DDP prefetch */
125 };
126
127 /* buf_state flags */
128 enum {
129         DDP_BF_NOINVAL = 1 << 0,   /* buffer is set to NO_INVALIDATE */
130         DDP_BF_NOCOPY  = 1 << 1,   /* DDP to final dest, no copy needed */
131         DDP_BF_NOFLIP  = 1 << 2,   /* buffer flips after GET_TCB_RPL */
132         DDP_BF_PSH     = 1 << 3,   /* set in skb->flags if the a DDP was 
133                                       completed with a segment having the
134                                       PSH flag set */
135 };
136
137 #ifdef notyet
138 /*
139  * Returns 1 if a UBUF DMA buffer might be active.
140  */
141 static inline int t3_ddp_ubuf_pending(struct sock *so)
142 {
143         struct tcp_sock *tp = tcp_sk(sk);
144         struct ddp_state *p = DDP_STATE(tp);
145
146         /* When the TOM_TUNABLE(ddp) is enabled, we're always in ULP_MODE DDP,
147          * but DDP_STATE() is only valid if the connection actually enabled
148          * DDP.
149          */
150         if (!p)
151                 return 0;
152
153         return (p->buf_state[0].flags & (DDP_BF_NOFLIP | DDP_BF_NOCOPY)) || 
154                (p->buf_state[1].flags & (DDP_BF_NOFLIP | DDP_BF_NOCOPY));
155 }
156 #endif
157
158 int t3_setup_ppods(struct socket *so, const struct ddp_gather_list *gl,
159                    unsigned int nppods, unsigned int tag, unsigned int maxoff,
160                    unsigned int pg_off, unsigned int color);
161 int t3_alloc_ppods(struct tom_data *td, unsigned int n);
162 void t3_free_ppods(struct tom_data *td, unsigned int tag, unsigned int n);
163 void t3_free_ddp_gl(struct pci_dev *pdev, struct ddp_gather_list *gl);
164 int t3_pin_pages(struct pci_dev *pdev, unsigned long uaddr, size_t len,
165                  struct ddp_gather_list **newgl,
166                  const struct ddp_gather_list *gl);
167 int t3_ddp_copy(const struct mbuf *skb, int offset, struct iovec *to,
168                 int len);
169 //void t3_repost_kbuf(struct socket *so, int modulate, int activate);
170 void t3_post_kbuf(struct socket *so, int modulate);
171 int t3_post_ubuf(struct socket *so, const struct iovec *iov, int nonblock,
172                  int rcv_flags, int modulate, int post_kbuf);
173 void t3_cancel_ubuf(struct socket *so);
174 int t3_overlay_ubuf(struct socket *so, const struct iovec *iov, int nonblock,
175                     int rcv_flags, int modulate, int post_kbuf);
176 int t3_enter_ddp(struct socket *so, unsigned int kbuf_size, unsigned int waitall);
177 void t3_cleanup_ddp(struct socket *so);
178 void t3_release_ddp_resources(struct toepcb *toep);
179 void t3_cancel_ddpbuf(struct socket *so, unsigned int bufidx);
180 void t3_overlay_ddpbuf(struct socket *so, unsigned int bufidx, unsigned int tag0,
181                        unsigned int tag1, unsigned int len);
182 void t3_setup_ddpbufs(struct socket *so, unsigned int len0, unsigned int offset0,
183                       unsigned int len1, unsigned int offset1,
184                       uint64_t ddp_flags, uint64_t flag_mask, int modulate);
185 #endif  /* T3_DDP_H */