qeth_eddp.c 17 KB

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