|
@@ -11,6 +11,26 @@
|
11
|
11
|
#include <assert.h>
|
12
|
12
|
#include <gpxe/list.h>
|
13
|
13
|
|
|
14
|
+/**
|
|
15
|
+ * I/O buffer alignment
|
|
16
|
+ *
|
|
17
|
+ * I/O buffers allocated via alloc_iob() are guaranteed to be
|
|
18
|
+ * physically aligned to this boundary. Some cards cannot DMA across
|
|
19
|
+ * a 4kB boundary. With a standard Ethernet MTU, aligning to a 2kB
|
|
20
|
+ * boundary is sufficient to guarantee no 4kB boundary crossings. For
|
|
21
|
+ * a jumbo Ethernet MTU, a packet may be larger than 4kB anyway.
|
|
22
|
+ */
|
|
23
|
+#define IOB_ALIGN 2048
|
|
24
|
+
|
|
25
|
+/**
|
|
26
|
+ * Minimum I/O buffer length
|
|
27
|
+ *
|
|
28
|
+ * alloc_iob() will round up the allocated length to this size if
|
|
29
|
+ * necessary. This is used on behalf of hardware that is not capable
|
|
30
|
+ * of auto-padding.
|
|
31
|
+ */
|
|
32
|
+#define IOB_ZLEN 64
|
|
33
|
+
|
14
|
34
|
/**
|
15
|
35
|
* A persistent I/O buffer
|
16
|
36
|
*
|
|
@@ -40,109 +60,109 @@ struct io_buffer {
|
40
|
60
|
/**
|
41
|
61
|
* Reserve space at start of I/O buffer
|
42
|
62
|
*
|
43
|
|
- * @v iob I/O buffer
|
|
63
|
+ * @v iobuf I/O buffer
|
44
|
64
|
* @v len Length to reserve
|
45
|
65
|
* @ret data Pointer to new start of buffer
|
46
|
66
|
*/
|
47
|
|
-static inline void * iob_reserve ( struct io_buffer *iob, size_t len ) {
|
48
|
|
- iob->data += len;
|
49
|
|
- iob->tail += len;
|
50
|
|
- assert ( iob->tail <= iob->end );
|
51
|
|
- return iob->data;
|
|
67
|
+static inline void * iob_reserve ( struct io_buffer *iobuf, size_t len ) {
|
|
68
|
+ iobuf->data += len;
|
|
69
|
+ iobuf->tail += len;
|
|
70
|
+ assert ( iobuf->tail <= iobuf->end );
|
|
71
|
+ return iobuf->data;
|
52
|
72
|
}
|
53
|
73
|
|
54
|
74
|
/**
|
55
|
75
|
* Add data to start of I/O buffer
|
56
|
76
|
*
|
57
|
|
- * @v iob I/O buffer
|
|
77
|
+ * @v iobuf I/O buffer
|
58
|
78
|
* @v len Length to add
|
59
|
79
|
* @ret data Pointer to new start of buffer
|
60
|
80
|
*/
|
61
|
|
-static inline void * iob_push ( struct io_buffer *iob, size_t len ) {
|
62
|
|
- iob->data -= len;
|
63
|
|
- assert ( iob->data >= iob->head );
|
64
|
|
- return iob->data;
|
|
81
|
+static inline void * iob_push ( struct io_buffer *iobuf, size_t len ) {
|
|
82
|
+ iobuf->data -= len;
|
|
83
|
+ assert ( iobuf->data >= iobuf->head );
|
|
84
|
+ return iobuf->data;
|
65
|
85
|
}
|
66
|
86
|
|
67
|
87
|
/**
|
68
|
88
|
* Remove data from start of I/O buffer
|
69
|
89
|
*
|
70
|
|
- * @v iob I/O buffer
|
|
90
|
+ * @v iobuf I/O buffer
|
71
|
91
|
* @v len Length to remove
|
72
|
92
|
* @ret data Pointer to new start of buffer
|
73
|
93
|
*/
|
74
|
|
-static inline void * iob_pull ( struct io_buffer *iob, size_t len ) {
|
75
|
|
- iob->data += len;
|
76
|
|
- assert ( iob->data <= iob->tail );
|
77
|
|
- return iob->data;
|
|
94
|
+static inline void * iob_pull ( struct io_buffer *iobuf, size_t len ) {
|
|
95
|
+ iobuf->data += len;
|
|
96
|
+ assert ( iobuf->data <= iobuf->tail );
|
|
97
|
+ return iobuf->data;
|
78
|
98
|
}
|
79
|
99
|
|
80
|
100
|
/**
|
81
|
101
|
* Add data to end of I/O buffer
|
82
|
102
|
*
|
83
|
|
- * @v iob I/O buffer
|
|
103
|
+ * @v iobuf I/O buffer
|
84
|
104
|
* @v len Length to add
|
85
|
105
|
* @ret data Pointer to newly added space
|
86
|
106
|
*/
|
87
|
|
-static inline void * iob_put ( struct io_buffer *iob, size_t len ) {
|
88
|
|
- void *old_tail = iob->tail;
|
89
|
|
- iob->tail += len;
|
90
|
|
- assert ( iob->tail <= iob->end );
|
|
107
|
+static inline void * iob_put ( struct io_buffer *iobuf, size_t len ) {
|
|
108
|
+ void *old_tail = iobuf->tail;
|
|
109
|
+ iobuf->tail += len;
|
|
110
|
+ assert ( iobuf->tail <= iobuf->end );
|
91
|
111
|
return old_tail;
|
92
|
112
|
}
|
93
|
113
|
|
94
|
114
|
/**
|
95
|
115
|
* Remove data from end of I/O buffer
|
96
|
116
|
*
|
97
|
|
- * @v iob I/O buffer
|
|
117
|
+ * @v iobuf I/O buffer
|
98
|
118
|
* @v len Length to remove
|
99
|
119
|
*/
|
100
|
|
-static inline void iob_unput ( struct io_buffer *iob, size_t len ) {
|
101
|
|
- iob->tail -= len;
|
102
|
|
- assert ( iob->tail >= iob->data );
|
|
120
|
+static inline void iob_unput ( struct io_buffer *iobuf, size_t len ) {
|
|
121
|
+ iobuf->tail -= len;
|
|
122
|
+ assert ( iobuf->tail >= iobuf->data );
|
103
|
123
|
}
|
104
|
124
|
|
105
|
125
|
/**
|
106
|
126
|
* Empty an I/O buffer
|
107
|
127
|
*
|
108
|
|
- * @v iob I/O buffer
|
|
128
|
+ * @v iobuf I/O buffer
|
109
|
129
|
*/
|
110
|
|
-static inline void iob_empty ( struct io_buffer *iob ) {
|
111
|
|
- iob->tail = iob->data;
|
|
130
|
+static inline void iob_empty ( struct io_buffer *iobuf ) {
|
|
131
|
+ iobuf->tail = iobuf->data;
|
112
|
132
|
}
|
113
|
133
|
|
114
|
134
|
/**
|
115
|
135
|
* Calculate length of data in an I/O buffer
|
116
|
136
|
*
|
117
|
|
- * @v iob I/O buffer
|
|
137
|
+ * @v iobuf I/O buffer
|
118
|
138
|
* @ret len Length of data in buffer
|
119
|
139
|
*/
|
120
|
|
-static inline size_t iob_len ( struct io_buffer *iob ) {
|
121
|
|
- return ( iob->tail - iob->data );
|
|
140
|
+static inline size_t iob_len ( struct io_buffer *iobuf ) {
|
|
141
|
+ return ( iobuf->tail - iobuf->data );
|
122
|
142
|
}
|
123
|
143
|
|
124
|
144
|
/**
|
125
|
145
|
* Calculate available space at start of an I/O buffer
|
126
|
146
|
*
|
127
|
|
- * @v iob I/O buffer
|
|
147
|
+ * @v iobuf I/O buffer
|
128
|
148
|
* @ret len Length of data available at start of buffer
|
129
|
149
|
*/
|
130
|
|
-static inline size_t iob_headroom ( struct io_buffer *iob ) {
|
131
|
|
- return ( iob->data - iob->head );
|
|
150
|
+static inline size_t iob_headroom ( struct io_buffer *iobuf ) {
|
|
151
|
+ return ( iobuf->data - iobuf->head );
|
132
|
152
|
}
|
133
|
153
|
|
134
|
154
|
/**
|
135
|
155
|
* Calculate available space at end of an I/O buffer
|
136
|
156
|
*
|
137
|
|
- * @v iob I/O buffer
|
|
157
|
+ * @v iobuf I/O buffer
|
138
|
158
|
* @ret len Length of data available at end of buffer
|
139
|
159
|
*/
|
140
|
|
-static inline size_t iob_tailroom ( struct io_buffer *iob ) {
|
141
|
|
- return ( iob->end - iob->tail );
|
|
160
|
+static inline size_t iob_tailroom ( struct io_buffer *iobuf ) {
|
|
161
|
+ return ( iobuf->end - iobuf->tail );
|
142
|
162
|
}
|
143
|
163
|
|
144
|
164
|
extern struct io_buffer * alloc_iob ( size_t len );
|
145
|
|
-extern void free_iob ( struct io_buffer *iob );
|
146
|
|
-extern void iob_pad ( struct io_buffer *iob, size_t min_len );
|
|
165
|
+extern void free_iob ( struct io_buffer *iobuf );
|
|
166
|
+extern void iob_pad ( struct io_buffer *iobuf, size_t min_len );
|
147
|
167
|
|
148
|
168
|
#endif /* _GPXE_IOBUF_H */
|