source: rtems/bsps/powerpc/beatnik/net/if_mve/mve_smallbuf_tst.c @ 031df391

5
Last change on this file since 031df391 was 031df391, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 23, 2018 at 7:53:31 AM

bsps: Move legacy network drivers to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • 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/param.h>
63#include <sys/mbuf.h>
64
65static void
66cleanup_buf(void *u_b, void *closure, int error)
67{
68rtems_bsdnet_semaphore_obtain();
69        m_freem((struct mbuf*)u_b);
70rtems_bsdnet_semaphore_release();
71}
72
73struct mbuf *mvtst_getbuf(struct mveth_private *mp)
74{
75struct mbuf *m,*n;
76
77        if ( !mp ) {
78                printf("need driver ptr arg\n");
79                return 0;
80        }
81rtems_bsdnet_semaphore_obtain();
82        MGETHDR(m, M_DONTWAIT, MT_DATA);
83        MGET(n, M_DONTWAIT, MT_DATA);
84        m->m_next = n;
85rtems_bsdnet_semaphore_release();
86        /* Ethernet header */
87        memset( mtod(m, unsigned char*), 0xff, 6);
88        BSP_mve_read_eaddr(mp, mtod(m, unsigned char*) + 6);
89        /* Arbitrary; setting to IP but we don't bother
90         * to setup a real IP header. We just watch the
91         * raw packet contents...
92         */
93        mtod(m, unsigned char*)[12] = 0x08;
94        mtod(m, unsigned char*)[13] = 0x00;
95        m->m_pkthdr.len = m->m_len = 14;
96        n->m_len = 0;
97        return m;
98}
99
100int
101mvtst_putbuf(struct mbuf *m, void *data, int len, int off)
102{
103int i;
104        if ( m ) {
105                m->m_pkthdr.len += len;
106        if ( ( m= m->m_next ) ) {
107                m->m_len = len;
108                memcpy(mtod(m, void*), data, 32);
109                m->m_data += off;
110                printf("m.dat: 0x%08x, m.data: 0x%08x\n", m->m_dat, m->m_data);
111                for ( i=0; i< 16; i++ ) {
112                        printf(" %02x,",mtod(m, unsigned char*)[i]);
113                }
114                printf("\n");
115        }
116        }
117       
118        return 0;
119}
120
121static void *alloc_rxbuf(int *p_size, unsigned long *paddr)
122{
123        return *(void**)paddr = rmalloc((*p_size = 1800));
124}
125
126static void consume_buf(void *buf, void *closure, int len)
127{
128        rfree(buf);
129}
130
131void *
132mvtst_init(int unit)
133{
134struct mveth_private *mp;
135        mp = BSP_mve_setup(
136                unit, 0,
137                cleanup_buf, 0,
138                alloc_rxbuf,
139                consume_buf, 0,
140                10, 10,
141                0);
142        if ( mp )
143                BSP_mve_init_hw(mp, 0, 0);
144        return mp;
145}
Note: See TracBrowser for help on using the repository browser.