blob: b023131277807f4d343cf3b59eaf9f8c19855331 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Heiko Carstense018ba12006-02-01 03:06:31 -08002 * linux/drivers/s390/net/qeth_eddp.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Enhanced Device Driver Packing (EDDP) support for the qeth driver.
5 *
6 * Copyright 2004 IBM Corporation
7 *
8 * Author(s): Thomas Spatzier <tspat@de.ibm.com>
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11#include <linux/config.h>
12#include <linux/errno.h>
13#include <linux/ip.h>
14#include <linux/inetdevice.h>
15#include <linux/netdevice.h>
16#include <linux/kernel.h>
17#include <linux/tcp.h>
18#include <net/tcp.h>
19#include <linux/skbuff.h>
20
21#include <net/ip.h>
22
23#include "qeth.h"
24#include "qeth_mpc.h"
25#include "qeth_eddp.h"
26
27int
28qeth_eddp_check_buffers_for_context(struct qeth_qdio_out_q *queue,
29 struct qeth_eddp_context *ctx)
30{
31 int index = queue->next_buf_to_fill;
32 int elements_needed = ctx->num_elements;
33 int elements_in_buffer;
34 int skbs_in_buffer;
35 int buffers_needed = 0;
36
37 QETH_DBF_TEXT(trace, 5, "eddpcbfc");
38 while(elements_needed > 0) {
39 buffers_needed++;
40 if (atomic_read(&queue->bufs[index].state) !=
41 QETH_QDIO_BUF_EMPTY)
42 return -EBUSY;
43
44 elements_in_buffer = QETH_MAX_BUFFER_ELEMENTS(queue->card) -
45 queue->bufs[index].next_element_to_fill;
46 skbs_in_buffer = elements_in_buffer / ctx->elements_per_skb;
47 elements_needed -= skbs_in_buffer * ctx->elements_per_skb;
48 index = (index + 1) % QDIO_MAX_BUFFERS_PER_Q;
49 }
50 return buffers_needed;
51}
52
53static inline void
54qeth_eddp_free_context(struct qeth_eddp_context *ctx)
55{
56 int i;
57
58 QETH_DBF_TEXT(trace, 5, "eddpfctx");
59 for (i = 0; i < ctx->num_pages; ++i)
60 free_page((unsigned long)ctx->pages[i]);
61 kfree(ctx->pages);
Frank Pavlic4965e972005-12-13 08:22:30 +010062 if (ctx->elements != NULL)
63 kfree(ctx->elements);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 kfree(ctx);
65}
66
67
68static inline void
69qeth_eddp_get_context(struct qeth_eddp_context *ctx)
70{
71 atomic_inc(&ctx->refcnt);
72}
73
74void
75qeth_eddp_put_context(struct qeth_eddp_context *ctx)
76{
77 if (atomic_dec_return(&ctx->refcnt) == 0)
78 qeth_eddp_free_context(ctx);
79}
80
81void
82qeth_eddp_buf_release_contexts(struct qeth_qdio_out_buffer *buf)
83{
84 struct qeth_eddp_context_reference *ref;
Frank Pavlic05e08a22005-05-12 20:39:09 +020085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 QETH_DBF_TEXT(trace, 6, "eddprctx");
87 while (!list_empty(&buf->ctx_list)){
88 ref = list_entry(buf->ctx_list.next,
89 struct qeth_eddp_context_reference, list);
90 qeth_eddp_put_context(ref->ctx);
91 list_del(&ref->list);
92 kfree(ref);
93 }
94}
95
96static inline int
97qeth_eddp_buf_ref_context(struct qeth_qdio_out_buffer *buf,
98 struct qeth_eddp_context *ctx)
99{
100 struct qeth_eddp_context_reference *ref;
101
102 QETH_DBF_TEXT(trace, 6, "eddprfcx");
103 ref = kmalloc(sizeof(struct qeth_eddp_context_reference), GFP_ATOMIC);
104 if (ref == NULL)
105 return -ENOMEM;
106 qeth_eddp_get_context(ctx);
107 ref->ctx = ctx;
108 list_add_tail(&ref->list, &buf->ctx_list);
109 return 0;
110}
111
112int
113qeth_eddp_fill_buffer(struct qeth_qdio_out_q *queue,
114 struct qeth_eddp_context *ctx,
115 int index)
116{
117 struct qeth_qdio_out_buffer *buf = NULL;
118 struct qdio_buffer *buffer;
119 int elements = ctx->num_elements;
120 int element = 0;
121 int flush_cnt = 0;
122 int must_refcnt = 1;
123 int i;
124
125 QETH_DBF_TEXT(trace, 5, "eddpfibu");
126 while (elements > 0) {
127 buf = &queue->bufs[index];
128 if (atomic_read(&buf->state) != QETH_QDIO_BUF_EMPTY){
129 /* normally this should not happen since we checked for
130 * available elements in qeth_check_elements_for_context
131 */
132 if (element == 0)
133 return -EBUSY;
134 else {
135 PRINT_WARN("could only partially fill eddp "
136 "buffer!\n");
137 goto out;
138 }
Frank Pavlic05e08a22005-05-12 20:39:09 +0200139 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 /* check if the whole next skb fits into current buffer */
141 if ((QETH_MAX_BUFFER_ELEMENTS(queue->card) -
142 buf->next_element_to_fill)
143 < ctx->elements_per_skb){
144 /* no -> go to next buffer */
145 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
146 index = (index + 1) % QDIO_MAX_BUFFERS_PER_Q;
147 flush_cnt++;
148 /* new buffer, so we have to add ctx to buffer'ctx_list
149 * and increment ctx's refcnt */
150 must_refcnt = 1;
151 continue;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200152 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 if (must_refcnt){
154 must_refcnt = 0;
155 if (qeth_eddp_buf_ref_context(buf, ctx)){
156 PRINT_WARN("no memory to create eddp context "
157 "reference\n");
158 goto out_check;
159 }
160 }
161 buffer = buf->buffer;
162 /* fill one skb into buffer */
163 for (i = 0; i < ctx->elements_per_skb; ++i){
164 buffer->element[buf->next_element_to_fill].addr =
165 ctx->elements[element].addr;
166 buffer->element[buf->next_element_to_fill].length =
167 ctx->elements[element].length;
168 buffer->element[buf->next_element_to_fill].flags =
169 ctx->elements[element].flags;
170 buf->next_element_to_fill++;
171 element++;
172 elements--;
173 }
174 }
175out_check:
176 if (!queue->do_pack) {
177 QETH_DBF_TEXT(trace, 6, "fillbfnp");
178 /* set state to PRIMED -> will be flushed */
179 if (buf->next_element_to_fill > 0){
180 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
181 flush_cnt++;
182 }
183 } else {
184#ifdef CONFIG_QETH_PERF_STATS
185 queue->card->perf_stats.skbs_sent_pack++;
186#endif
187 QETH_DBF_TEXT(trace, 6, "fillbfpa");
188 if (buf->next_element_to_fill >=
189 QETH_MAX_BUFFER_ELEMENTS(queue->card)) {
190 /*
191 * packed buffer if full -> set state PRIMED
192 * -> will be flushed
193 */
194 atomic_set(&buf->state, QETH_QDIO_BUF_PRIMED);
195 flush_cnt++;
196 }
197 }
198out:
199 return flush_cnt;
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static inline void
203qeth_eddp_create_segment_hdrs(struct qeth_eddp_context *ctx,
Frank Pavlic05e08a22005-05-12 20:39:09 +0200204 struct qeth_eddp_data *eddp, int data_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 u8 *page;
207 int page_remainder;
208 int page_offset;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200209 int pkt_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 struct qeth_eddp_element *element;
211
212 QETH_DBF_TEXT(trace, 5, "eddpcrsh");
213 page = ctx->pages[ctx->offset >> PAGE_SHIFT];
214 page_offset = ctx->offset % PAGE_SIZE;
215 element = &ctx->elements[ctx->num_elements];
Frank Pavlic05e08a22005-05-12 20:39:09 +0200216 pkt_len = eddp->nhl + eddp->thl + data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 /* FIXME: layer2 and VLAN !!! */
218 if (eddp->qh.hdr.l2.id == QETH_HEADER_TYPE_LAYER2)
Frank Pavlic05e08a22005-05-12 20:39:09 +0200219 pkt_len += ETH_HLEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 if (eddp->mac.h_proto == __constant_htons(ETH_P_8021Q))
Frank Pavlic05e08a22005-05-12 20:39:09 +0200221 pkt_len += VLAN_HLEN;
222 /* does complete packet fit in current page ? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 page_remainder = PAGE_SIZE - page_offset;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200224 if (page_remainder < (sizeof(struct qeth_hdr) + pkt_len)){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* no -> go to start of next page */
226 ctx->offset += page_remainder;
227 page = ctx->pages[ctx->offset >> PAGE_SHIFT];
228 page_offset = 0;
229 }
230 memcpy(page + page_offset, &eddp->qh, sizeof(struct qeth_hdr));
231 element->addr = page + page_offset;
232 element->length = sizeof(struct qeth_hdr);
233 ctx->offset += sizeof(struct qeth_hdr);
234 page_offset += sizeof(struct qeth_hdr);
235 /* add mac header (?) */
236 if (eddp->qh.hdr.l2.id == QETH_HEADER_TYPE_LAYER2){
237 memcpy(page + page_offset, &eddp->mac, ETH_HLEN);
238 element->length += ETH_HLEN;
239 ctx->offset += ETH_HLEN;
240 page_offset += ETH_HLEN;
241 }
242 /* add VLAN tag */
243 if (eddp->mac.h_proto == __constant_htons(ETH_P_8021Q)){
244 memcpy(page + page_offset, &eddp->vlan, VLAN_HLEN);
245 element->length += VLAN_HLEN;
246 ctx->offset += VLAN_HLEN;
247 page_offset += VLAN_HLEN;
248 }
249 /* add network header */
250 memcpy(page + page_offset, (u8 *)&eddp->nh, eddp->nhl);
251 element->length += eddp->nhl;
252 eddp->nh_in_ctx = page + page_offset;
253 ctx->offset += eddp->nhl;
254 page_offset += eddp->nhl;
255 /* add transport header */
256 memcpy(page + page_offset, (u8 *)&eddp->th, eddp->thl);
257 element->length += eddp->thl;
258 eddp->th_in_ctx = page + page_offset;
259 ctx->offset += eddp->thl;
260}
261
262static inline void
263qeth_eddp_copy_data_tcp(char *dst, struct qeth_eddp_data *eddp, int len,
264 u32 *hcsum)
265{
266 struct skb_frag_struct *frag;
267 int left_in_frag;
268 int copy_len;
269 u8 *src;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 QETH_DBF_TEXT(trace, 5, "eddpcdtc");
272 if (skb_shinfo(eddp->skb)->nr_frags == 0) {
273 memcpy(dst, eddp->skb->data + eddp->skb_offset, len);
274 *hcsum = csum_partial(eddp->skb->data + eddp->skb_offset, len,
275 *hcsum);
276 eddp->skb_offset += len;
277 } else {
278 while (len > 0) {
279 if (eddp->frag < 0) {
280 /* we're in skb->data */
Frank Pavlic05e08a22005-05-12 20:39:09 +0200281 left_in_frag = (eddp->skb->len - eddp->skb->data_len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 - eddp->skb_offset;
283 src = eddp->skb->data + eddp->skb_offset;
284 } else {
285 frag = &skb_shinfo(eddp->skb)->
286 frags[eddp->frag];
287 left_in_frag = frag->size - eddp->frag_offset;
288 src = (u8 *)(
289 (page_to_pfn(frag->page) << PAGE_SHIFT)+
290 frag->page_offset + eddp->frag_offset);
291 }
292 if (left_in_frag <= 0) {
293 eddp->frag++;
294 eddp->frag_offset = 0;
295 continue;
296 }
297 copy_len = min(left_in_frag, len);
298 memcpy(dst, src, copy_len);
299 *hcsum = csum_partial(src, copy_len, *hcsum);
300 dst += copy_len;
301 eddp->frag_offset += copy_len;
302 eddp->skb_offset += copy_len;
303 len -= copy_len;
304 }
305 }
306}
307
308static inline void
309qeth_eddp_create_segment_data_tcp(struct qeth_eddp_context *ctx,
310 struct qeth_eddp_data *eddp, int data_len,
311 u32 hcsum)
312{
313 u8 *page;
314 int page_remainder;
315 int page_offset;
316 struct qeth_eddp_element *element;
317 int first_lap = 1;
318
319 QETH_DBF_TEXT(trace, 5, "eddpcsdt");
320 page = ctx->pages[ctx->offset >> PAGE_SHIFT];
321 page_offset = ctx->offset % PAGE_SIZE;
322 element = &ctx->elements[ctx->num_elements];
323 while (data_len){
324 page_remainder = PAGE_SIZE - page_offset;
325 if (page_remainder < data_len){
326 qeth_eddp_copy_data_tcp(page + page_offset, eddp,
327 page_remainder, &hcsum);
328 element->length += page_remainder;
329 if (first_lap)
330 element->flags = SBAL_FLAGS_FIRST_FRAG;
331 else
332 element->flags = SBAL_FLAGS_MIDDLE_FRAG;
333 ctx->num_elements++;
334 element++;
335 data_len -= page_remainder;
336 ctx->offset += page_remainder;
337 page = ctx->pages[ctx->offset >> PAGE_SHIFT];
338 page_offset = 0;
339 element->addr = page + page_offset;
340 } else {
341 qeth_eddp_copy_data_tcp(page + page_offset, eddp,
342 data_len, &hcsum);
343 element->length += data_len;
344 if (!first_lap)
345 element->flags = SBAL_FLAGS_LAST_FRAG;
346 ctx->num_elements++;
347 ctx->offset += data_len;
348 data_len = 0;
349 }
350 first_lap = 0;
351 }
352 ((struct tcphdr *)eddp->th_in_ctx)->check = csum_fold(hcsum);
353}
354
355static inline u32
356qeth_eddp_check_tcp4_hdr(struct qeth_eddp_data *eddp, int data_len)
357{
358 u32 phcsum; /* pseudo header checksum */
359
360 QETH_DBF_TEXT(trace, 5, "eddpckt4");
361 eddp->th.tcp.h.check = 0;
362 /* compute pseudo header checksum */
363 phcsum = csum_tcpudp_nofold(eddp->nh.ip4.h.saddr, eddp->nh.ip4.h.daddr,
364 eddp->thl + data_len, IPPROTO_TCP, 0);
365 /* compute checksum of tcp header */
366 return csum_partial((u8 *)&eddp->th, eddp->thl, phcsum);
367}
368
369static inline u32
370qeth_eddp_check_tcp6_hdr(struct qeth_eddp_data *eddp, int data_len)
371{
372 u32 proto;
373 u32 phcsum; /* pseudo header checksum */
374
375 QETH_DBF_TEXT(trace, 5, "eddpckt6");
376 eddp->th.tcp.h.check = 0;
377 /* compute pseudo header checksum */
378 phcsum = csum_partial((u8 *)&eddp->nh.ip6.h.saddr,
379 sizeof(struct in6_addr), 0);
380 phcsum = csum_partial((u8 *)&eddp->nh.ip6.h.daddr,
381 sizeof(struct in6_addr), phcsum);
382 proto = htonl(IPPROTO_TCP);
383 phcsum = csum_partial((u8 *)&proto, sizeof(u32), phcsum);
384 return phcsum;
385}
386
387static inline struct qeth_eddp_data *
388qeth_eddp_create_eddp_data(struct qeth_hdr *qh, u8 *nh, u8 nhl, u8 *th, u8 thl)
389{
390 struct qeth_eddp_data *eddp;
391
392 QETH_DBF_TEXT(trace, 5, "eddpcrda");
393 eddp = kmalloc(sizeof(struct qeth_eddp_data), GFP_ATOMIC);
394 if (eddp){
395 memset(eddp, 0, sizeof(struct qeth_eddp_data));
396 eddp->nhl = nhl;
397 eddp->thl = thl;
398 memcpy(&eddp->qh, qh, sizeof(struct qeth_hdr));
399 memcpy(&eddp->nh, nh, nhl);
400 memcpy(&eddp->th, th, thl);
401 eddp->frag = -1; /* initially we're in skb->data */
402 }
403 return eddp;
404}
405
406static inline void
407__qeth_eddp_fill_context_tcp(struct qeth_eddp_context *ctx,
408 struct qeth_eddp_data *eddp)
409{
410 struct tcphdr *tcph;
411 int data_len;
412 u32 hcsum;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 QETH_DBF_TEXT(trace, 5, "eddpftcp");
415 eddp->skb_offset = sizeof(struct qeth_hdr) + eddp->nhl + eddp->thl;
416 tcph = eddp->skb->h.th;
417 while (eddp->skb_offset < eddp->skb->len) {
418 data_len = min((int)skb_shinfo(eddp->skb)->tso_size,
419 (int)(eddp->skb->len - eddp->skb_offset));
420 /* prepare qdio hdr */
421 if (eddp->qh.hdr.l2.id == QETH_HEADER_TYPE_LAYER2){
422 eddp->qh.hdr.l2.pkt_length = data_len + ETH_HLEN +
423 eddp->nhl + eddp->thl -
424 sizeof(struct qeth_hdr);
425#ifdef CONFIG_QETH_VLAN
426 if (eddp->mac.h_proto == __constant_htons(ETH_P_8021Q))
427 eddp->qh.hdr.l2.pkt_length += VLAN_HLEN;
428#endif /* CONFIG_QETH_VLAN */
429 } else
430 eddp->qh.hdr.l3.length = data_len + eddp->nhl +
431 eddp->thl;
432 /* prepare ip hdr */
433 if (eddp->skb->protocol == ETH_P_IP){
434 eddp->nh.ip4.h.tot_len = data_len + eddp->nhl +
435 eddp->thl;
436 eddp->nh.ip4.h.check = 0;
437 eddp->nh.ip4.h.check =
438 ip_fast_csum((u8 *)&eddp->nh.ip4.h,
439 eddp->nh.ip4.h.ihl);
440 } else
441 eddp->nh.ip6.h.payload_len = data_len + eddp->thl;
442 /* prepare tcp hdr */
443 if (data_len == (eddp->skb->len - eddp->skb_offset)){
444 /* last segment -> set FIN and PSH flags */
445 eddp->th.tcp.h.fin = tcph->fin;
446 eddp->th.tcp.h.psh = tcph->psh;
447 }
448 if (eddp->skb->protocol == ETH_P_IP)
449 hcsum = qeth_eddp_check_tcp4_hdr(eddp, data_len);
450 else
451 hcsum = qeth_eddp_check_tcp6_hdr(eddp, data_len);
452 /* fill the next segment into the context */
Frank Pavlic05e08a22005-05-12 20:39:09 +0200453 qeth_eddp_create_segment_hdrs(ctx, eddp, data_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 qeth_eddp_create_segment_data_tcp(ctx, eddp, data_len, hcsum);
455 if (eddp->skb_offset >= eddp->skb->len)
456 break;
457 /* prepare headers for next round */
458 if (eddp->skb->protocol == ETH_P_IP)
459 eddp->nh.ip4.h.id++;
460 eddp->th.tcp.h.seq += data_len;
461 }
462}
Frank Pavlic05e08a22005-05-12 20:39:09 +0200463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464static inline int
465qeth_eddp_fill_context_tcp(struct qeth_eddp_context *ctx,
466 struct sk_buff *skb, struct qeth_hdr *qhdr)
467{
468 struct qeth_eddp_data *eddp = NULL;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 QETH_DBF_TEXT(trace, 5, "eddpficx");
471 /* create our segmentation headers and copy original headers */
472 if (skb->protocol == ETH_P_IP)
473 eddp = qeth_eddp_create_eddp_data(qhdr, (u8 *)skb->nh.iph,
474 skb->nh.iph->ihl*4,
475 (u8 *)skb->h.th, skb->h.th->doff*4);
476 else
477 eddp = qeth_eddp_create_eddp_data(qhdr, (u8 *)skb->nh.ipv6h,
478 sizeof(struct ipv6hdr),
479 (u8 *)skb->h.th, skb->h.th->doff*4);
480
481 if (eddp == NULL) {
482 QETH_DBF_TEXT(trace, 2, "eddpfcnm");
483 return -ENOMEM;
484 }
485 if (qhdr->hdr.l2.id == QETH_HEADER_TYPE_LAYER2) {
486 memcpy(&eddp->mac, eth_hdr(skb), ETH_HLEN);
487#ifdef CONFIG_QETH_VLAN
488 if (eddp->mac.h_proto == __constant_htons(ETH_P_8021Q)) {
489 eddp->vlan[0] = __constant_htons(skb->protocol);
490 eddp->vlan[1] = htons(vlan_tx_tag_get(skb));
491 }
492#endif /* CONFIG_QETH_VLAN */
493 }
494 /* the next flags will only be set on the last segment */
495 eddp->th.tcp.h.fin = 0;
496 eddp->th.tcp.h.psh = 0;
497 eddp->skb = skb;
498 /* begin segmentation and fill context */
499 __qeth_eddp_fill_context_tcp(ctx, eddp);
500 kfree(eddp);
501 return 0;
502}
503
504static inline void
505qeth_eddp_calc_num_pages(struct qeth_eddp_context *ctx, struct sk_buff *skb,
506 int hdr_len)
507{
508 int skbs_per_page;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 QETH_DBF_TEXT(trace, 5, "eddpcanp");
511 /* can we put multiple skbs in one page? */
512 skbs_per_page = PAGE_SIZE / (skb_shinfo(skb)->tso_size + hdr_len);
513 if (skbs_per_page > 1){
514 ctx->num_pages = (skb_shinfo(skb)->tso_segs + 1) /
515 skbs_per_page + 1;
516 ctx->elements_per_skb = 1;
517 } else {
518 /* no -> how many elements per skb? */
519 ctx->elements_per_skb = (skb_shinfo(skb)->tso_size + hdr_len +
520 PAGE_SIZE) >> PAGE_SHIFT;
521 ctx->num_pages = ctx->elements_per_skb *
522 (skb_shinfo(skb)->tso_segs + 1);
523 }
524 ctx->num_elements = ctx->elements_per_skb *
525 (skb_shinfo(skb)->tso_segs + 1);
526}
527
528static inline struct qeth_eddp_context *
529qeth_eddp_create_context_generic(struct qeth_card *card, struct sk_buff *skb,
530 int hdr_len)
531{
532 struct qeth_eddp_context *ctx = NULL;
533 u8 *addr;
534 int i;
535
536 QETH_DBF_TEXT(trace, 5, "creddpcg");
537 /* create the context and allocate pages */
538 ctx = kmalloc(sizeof(struct qeth_eddp_context), GFP_ATOMIC);
539 if (ctx == NULL){
540 QETH_DBF_TEXT(trace, 2, "ceddpcn1");
541 return NULL;
542 }
543 memset(ctx, 0, sizeof(struct qeth_eddp_context));
544 ctx->type = QETH_LARGE_SEND_EDDP;
545 qeth_eddp_calc_num_pages(ctx, skb, hdr_len);
546 if (ctx->elements_per_skb > QETH_MAX_BUFFER_ELEMENTS(card)){
547 QETH_DBF_TEXT(trace, 2, "ceddpcis");
548 kfree(ctx);
549 return NULL;
550 }
551 ctx->pages = kmalloc(ctx->num_pages * sizeof(u8 *), GFP_ATOMIC);
552 if (ctx->pages == NULL){
553 QETH_DBF_TEXT(trace, 2, "ceddpcn2");
554 kfree(ctx);
555 return NULL;
556 }
557 memset(ctx->pages, 0, ctx->num_pages * sizeof(u8 *));
558 for (i = 0; i < ctx->num_pages; ++i){
559 addr = (u8 *)__get_free_page(GFP_ATOMIC);
560 if (addr == NULL){
561 QETH_DBF_TEXT(trace, 2, "ceddpcn3");
562 ctx->num_pages = i;
563 qeth_eddp_free_context(ctx);
564 return NULL;
565 }
566 memset(addr, 0, PAGE_SIZE);
567 ctx->pages[i] = addr;
568 }
569 ctx->elements = kmalloc(ctx->num_elements *
570 sizeof(struct qeth_eddp_element), GFP_ATOMIC);
571 if (ctx->elements == NULL){
572 QETH_DBF_TEXT(trace, 2, "ceddpcn4");
573 qeth_eddp_free_context(ctx);
574 return NULL;
575 }
576 memset(ctx->elements, 0,
577 ctx->num_elements * sizeof(struct qeth_eddp_element));
578 /* reset num_elements; will be incremented again in fill_buffer to
579 * reflect number of actually used elements */
580 ctx->num_elements = 0;
581 return ctx;
582}
583
584static inline struct qeth_eddp_context *
585qeth_eddp_create_context_tcp(struct qeth_card *card, struct sk_buff *skb,
586 struct qeth_hdr *qhdr)
587{
588 struct qeth_eddp_context *ctx = NULL;
Frank Pavlic05e08a22005-05-12 20:39:09 +0200589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 QETH_DBF_TEXT(trace, 5, "creddpct");
591 if (skb->protocol == ETH_P_IP)
592 ctx = qeth_eddp_create_context_generic(card, skb,
593 sizeof(struct qeth_hdr) + skb->nh.iph->ihl*4 +
594 skb->h.th->doff*4);
595 else if (skb->protocol == ETH_P_IPV6)
596 ctx = qeth_eddp_create_context_generic(card, skb,
597 sizeof(struct qeth_hdr) + sizeof(struct ipv6hdr) +
598 skb->h.th->doff*4);
599 else
600 QETH_DBF_TEXT(trace, 2, "cetcpinv");
601
602 if (ctx == NULL) {
603 QETH_DBF_TEXT(trace, 2, "creddpnl");
604 return NULL;
605 }
606 if (qeth_eddp_fill_context_tcp(ctx, skb, qhdr)){
607 QETH_DBF_TEXT(trace, 2, "ceddptfe");
608 qeth_eddp_free_context(ctx);
609 return NULL;
610 }
611 atomic_set(&ctx->refcnt, 1);
612 return ctx;
613}
614
615struct qeth_eddp_context *
616qeth_eddp_create_context(struct qeth_card *card, struct sk_buff *skb,
617 struct qeth_hdr *qhdr)
618{
619 QETH_DBF_TEXT(trace, 5, "creddpc");
620 switch (skb->sk->sk_protocol){
621 case IPPROTO_TCP:
622 return qeth_eddp_create_context_tcp(card, skb, qhdr);
623 default:
624 QETH_DBF_TEXT(trace, 2, "eddpinvp");
625 }
626 return NULL;
627}
628
629