source: rtems/c/src/lib/libbsp/powerpc/beatnik/network/if_mve/mve_smallbuf_tst.c @ 6273201

4.115
Last change on this file since 6273201 was b7a6d23a, checked in by Till Straumann <strauman@…>, on 12/03/09 at 16:56:50
  • importing 'beatnik' BSP from SLAC repository.
  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include <rtems.h>
2#include <bsp.h>
3#include <bsp/if_mve_pub.h>
4#include <stdlib.h>
5#include <stdio.h>
6
7/* Demo for the mv64360 ethernet quirk:
8 *
9 * $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
10 * $$ buffer segments < 8 bytes must be aligned $$
11 * $$ to 8 bytes but larger segments are not    $$
12 * $$ sensitive to alignment.                   $$
13 * $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
14 *
15 * How to use:
16 *
17 *   Init MVE driver on (unused) unit 2:
18 *
19 *    mve = mvtst_init(2)
20 *
21 *    data = { 1,2,3,4,5,6,7,8,9,0xa,0xb, ... }
22 *
23 *   Alloc 2-element mbuf chain (1st holds an
24 *   ethernet header which is > 8bytes so we can't
25 *   test this with only 1 mbuf. The 2nd mbuf holds
26 *   a small fragment of data).
27 *
28 *     mb  = mvtst_getbuf(mve)
29 *
30 *   Copy data into aligned area inside 2nd mbuf,
31 *   (so that you can see if the chip starts using
32 *   the aligned area rather than the unaligned
33 *   buffer pointer). Point mbuf's data pointer
34 *   at 'off'set from the aligned area:
35 *
36 *     mvtst_putbuf(mb, data, len, offset)
37 *
38 *   Send chain off:
39 *
40 *    BSP_mve_send_buf(mve, mb, 0, 0)
41 *
42 *   Watch raw data:
43 *
44 *    tcpdump -XX -vv -s0 ether host <my-ether-addr>
45 *
46 *   E.g, if offset = 1, len = 2 then we would like
47 *   to see
48 * 
49 *   GOOD:
50 *           < 14 header bytes > 0x02, 0x03
51
52 *   but if the chip starts DMA at aligned address
53 *   we see instead
54 *   BAD:
55 *           < 14 header bytes > 0x01, 0x02
56 */
57
58static inline void *rmalloc(size_t l) { return malloc(l); }
59static inline void  rfree(void *p) { return free(p); }
60
61#define _KERNEL
62#include <sys/mbuf.h>
63
64static void
65cleanup_buf(void *u_b, void *closure, int error)
66{
67rtems_bsdnet_semaphore_obtain();
68        m_freem((struct mbuf*)u_b);
69rtems_bsdnet_semaphore_release();
70}
71
72struct mbuf *mvtst_getbuf(struct mveth_private *mp)
73{
74struct mbuf *m,*n;
75
76        if ( !mp ) {
77                printf("need driver ptr arg\n");
78                return 0;
79        }
80rtems_bsdnet_semaphore_obtain();
81        MGETHDR(m, M_DONTWAIT, MT_DATA);
82        MGET(n, M_DONTWAIT, MT_DATA);
83        m->m_next = n;
84rtems_bsdnet_semaphore_release();
85        /* Ethernet header */
86        memset( mtod(m, unsigned char*), 0xff, 6);
87        BSP_mve_read_eaddr(mp, mtod(m, unsigned char*) + 6);
88        /* Arbitrary; setting to IP but we don't bother
89         * to setup a real IP header. We just watch the
90         * raw packet contents...
91         */
92        mtod(m, unsigned char*)[12] = 0x08;
93        mtod(m, unsigned char*)[13] = 0x00;
94        m->m_pkthdr.len = m->m_len = 14;
95        n->m_len = 0;
96        return m;
97}
98
99int
100mvtst_putbuf(struct mbuf *m, void *data, int len, int off)
101{
102int i;
103        if ( m ) {
104                m->m_pkthdr.len += len;
105        if ( ( m= m->m_next ) ) {
106                m->m_len = len;
107                memcpy(mtod(m, void*), data, 32);
108                m->m_data += off;
109                printf("m.dat: 0x%08x, m.data: 0x%08x\n", m->m_dat, m->m_data);
110                for ( i=0; i< 16; i++ ) {
111                        printf(" %02x,",mtod(m, unsigned char*)[i]);
112                }
113                printf("\n");
114        }
115        }
116       
117        return 0;
118}
119
120static void *alloc_rxbuf(int *p_size, unsigned long *paddr)
121{
122        return *(void**)paddr = rmalloc((*p_size = 1800));
123}
124
125static void consume_buf(void *buf, void *closure, int len)
126{
127        rfree(buf);
128}
129
130void *
131mvtst_init(int unit)
132{
133struct mveth_private *mp;
134        mp = BSP_mve_setup(
135                unit, 0,
136                cleanup_buf, 0,
137                alloc_rxbuf,
138                consume_buf, 0,
139                10, 10,
140                0);
141        if ( mp )
142                BSP_mve_init_hw(mp, 0, 0);
143        return mp;
144}
Note: See TracBrowser for help on using the repository browser.