7ad60fd757959d3bd1548a104f22a98def6b71bd
[openwrt.git] / package / ifxmips-atm / src / skb.c
1 #include <linux/skbuff.h>
2
3 #include "common.h"
4
5 void resize_skb_rx(struct sk_buff *skb, unsigned int size, int is_cell)
6 {
7 if((u32)skb < 0x80000000)
8 {
9 int key = 0;
10 printk("resize_skb_rx problem: skb = %08X, size = %d, is_cell = %d\n", (u32)skb, size, is_cell);
11 while(!key){}
12 }
13 skb->data = (unsigned char*)(((u32)skb->head + 16 + (DMA_ALIGNMENT - 1)) & ~(DMA_ALIGNMENT - 1));
14 skb->tail = skb->data;
15
16 /* Set up other state */
17 skb->len = 0;
18 skb->cloned = 0;
19 #if defined(CONFIG_IMQ) || defined (CONFIG_IMQ_MODULE)
20 skb->imq_flags = 0;
21 skb->nf_info = NULL;
22 #endif
23 skb->data_len = 0;
24 }
25
26 struct sk_buff* alloc_skb_rx(void)
27 {
28 struct sk_buff *skb;
29
30 /* allocate memroy including trailer and padding */
31 skb = dev_alloc_skb(ppe_dev.aal5.rx_buffer_size + DMA_ALIGNMENT);
32 if (skb)
33 {
34 /* must be burst length alignment */
35 if ( ((u32)skb->data & (DMA_ALIGNMENT - 1)) != 0 )
36 skb_reserve(skb, ~((u32)skb->data + (DMA_ALIGNMENT - 1)) & (DMA_ALIGNMENT - 1));
37 /* put skb in reserved area "skb->data - 4" */
38 *((u32*)skb->data - 1) = (u32)skb;
39 /* invalidate cache */
40 dma_cache_inv((unsigned long)skb->head, (u32)skb->end - (u32)skb->head);
41 }
42 return skb;
43 }
44
45 void atm_free_tx_skb_vcc(struct sk_buff *skb)
46 {
47 struct atm_vcc* vcc;
48
49 if ( (u32)skb <= 0x80000000 )
50 {
51 volatile int key = 0;
52 printk("atm_free_tx_skb_vcc: skb = %08X\n", (u32)skb);
53 for ( ; !key; );
54 }
55
56 vcc = ATM_SKB(skb)->vcc;
57 if ( vcc != NULL && vcc->pop != NULL )
58 {
59 if ( atomic_read(&skb->users) == 0 )
60 {
61 volatile int key = 0;
62 printk("atm_free_tx_skb_vcc(vcc->pop): skb->users == 0, skb = %08X\n", (u32)skb);
63 for ( ; !key; );
64 }
65 vcc->pop(vcc, skb);
66 }
67 else
68 {
69 if ( atomic_read(&skb->users) == 0 )
70 {
71 volatile int key = 0;
72 printk("atm_free_tx_skb_vcc(dev_kfree_skb_any): skb->users == 0, skb = %08X\n", (u32)skb);
73 for ( ; !key; );
74 }
75 dev_kfree_skb_any(skb);
76 }
77 }
78
79 struct sk_buff* alloc_skb_tx(unsigned int size)
80 {
81 struct sk_buff *skb;
82
83 /* allocate memory including header and padding */
84 size += TX_INBAND_HEADER_LENGTH + MAX_TX_PACKET_ALIGN_BYTES + MAX_TX_PACKET_PADDING_BYTES;
85 size &= ~(DMA_ALIGNMENT - 1);
86 skb = dev_alloc_skb(size + DMA_ALIGNMENT);
87 /* must be burst length alignment */
88 if ( skb )
89 skb_reserve(skb, (~((u32)skb->data + (DMA_ALIGNMENT - 1)) & (DMA_ALIGNMENT - 1)) + TX_INBAND_HEADER_LENGTH);
90 return skb;
91 }
92
93 struct sk_buff* atm_alloc_tx(struct atm_vcc *vcc, unsigned int size)
94 {
95 int conn;
96 struct sk_buff *skb;
97
98 /* oversize packet */
99 if ( ((size + TX_INBAND_HEADER_LENGTH + MAX_TX_PACKET_ALIGN_BYTES + MAX_TX_PACKET_PADDING_BYTES) & ~(DMA_ALIGNMENT - 1)) > ppe_dev.aal5.tx_max_packet_size )
100 {
101 printk("atm_alloc_tx: oversize packet\n");
102 return NULL;
103 }
104 /* send buffer overflow */
105 if ( atomic_read(&vcc->sk.sk_wmem_alloc) && !atm_may_send(vcc, size) )
106 {
107 printk("atm_alloc_tx: send buffer overflow\n");
108 return NULL;
109 }
110 conn = find_vcc(vcc);
111 if ( conn < 0 )
112 {
113 printk("atm_alloc_tx: unknown VCC\n");
114 return NULL;
115 }
116
117 skb = dev_alloc_skb(size);
118 if ( skb == NULL )
119 {
120 printk("atm_alloc_tx: sk buffer is used up\n");
121 return NULL;
122 }
123 #define ATM_PDU_OVHD 0
124 atomic_add(skb->truesize + ATM_PDU_OVHD, &vcc->sk.sk_wmem_alloc);
125
126 return skb;
127 }
128
This page took 0.058508 seconds and 3 git commands to generate.