qeth_eddp.c 17 KB

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