rtdev.h 7.82 KB
Newer Older
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/***
 *
 *  rtdev.h
 *
 *  RTnet - real-time networking subsystem
 *  Copyright (C) 1999       Lineo, Inc
 *                1999, 2002 David A. Schleef <ds@schleef.org>
 *                2003-2005  Jan Kiszka <jan.kiszka@web.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#ifndef __RTDEV_H_
#define __RTDEV_H_

#define MAX_RT_DEVICES                  8


#ifdef __KERNEL__

#include <asm/atomic.h>
#include <linux/netdevice.h>

#include <rtskb.h>
#include <rtnet_internal.h>

#define RTDEV_VERS_2_0                  0x0200

#define PRIV_FLAG_UP                    0
#define PRIV_FLAG_ADDING_ROUTE          1

#ifndef NETIF_F_LLTX
#define NETIF_F_LLTX                    4096
#endif


enum rtnet_link_state {
51
52
53
54
        __RTNET_LINK_STATE_XOFF = 0,
        __RTNET_LINK_STATE_START,
        __RTNET_LINK_STATE_PRESENT,
        __RTNET_LINK_STATE_NOCARRIER,
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
};

/***
 *  rtnet_device
 */
struct rtnet_device {
    /* Many field are borrowed from struct net_device in
     * <linux/netdevice.h> - WY
     */
    unsigned int        vers;

    char                name[IFNAMSIZ];

    unsigned long       rmem_end;   /* shmem "recv" end     */
    unsigned long       rmem_start; /* shmem "recv" start   */
    unsigned long       mem_end;    /* shared mem end       */
    unsigned long       mem_start;  /* shared mem start     */
    unsigned long       base_addr;  /* device I/O address   */
    unsigned int        irq;        /* device IRQ number    */

    /*
     *  Some hardware also needs these fields, but they are not
     *  part of the usual set specified in Space.c.
     */
    unsigned char       if_port;    /* Selectable AUI, TP,..*/
    unsigned char       dma;        /* DMA channel          */
    __u16               __padding;

    unsigned long       link_state;
    int                 ifindex;
    atomic_t            refcount;

    struct module       *rt_owner;  /* like classic owner, but      *
                                     * forces correct macro usage   */

    unsigned int        flags;      /* interface flags (a la BSD)   */
    unsigned long       priv_flags; /* internal flags               */
    unsigned short      type;       /* interface hardware type      */
    unsigned short      hard_header_len;    /* hardware hdr length  */
    unsigned int        mtu;        /* eth = 1536, tr = 4...        */
    void                *priv;      /* pointer to private data      */
    int                 features;   /* [RT]NETIF_F_*                */

    /* Interface address info. */
    unsigned char       broadcast[MAX_ADDR_LEN];    /* hw bcast add */
    unsigned char       dev_addr[MAX_ADDR_LEN];     /* hw address   */
    unsigned char       addr_len;   /* hardware address length      */

    int                 promiscuity;
    int                 allmulti;

    __u32               local_ip;   /* IP address in network order  */
    __u32               broadcast_ip; /* broadcast IP in network order */

    rtdm_event_t        *stack_event;

    rtdm_mutex_t        xmit_mutex; /* protects xmit routine        */
    rtdm_lock_t         rtdev_lock; /* management lock              */
    struct mutex        nrt_lock;   /* non-real-time locking        */

    unsigned int        add_rtskbs; /* additionally allocated global rtskbs */

    /* RTmac related fields */
    struct rtmac_disc   *mac_disc;
    struct rtmac_priv   *mac_priv;
    int                 (*mac_detach)(struct rtnet_device *rtdev);

    /* Device operations */
    int                 (*open)(struct rtnet_device *rtdev);
    int                 (*stop)(struct rtnet_device *rtdev);
    int                 (*hard_header)(struct rtskb *, struct rtnet_device *,
                                       unsigned short type, void *daddr,
                                       void *saddr, unsigned int len);
    int                 (*rebuild_header)(struct rtskb *);
    int                 (*hard_start_xmit)(struct rtskb *skb,
                                           struct rtnet_device *dev);
    int                 (*hw_reset)(struct rtnet_device *rtdev);

    /* Transmission hook, managed by the stack core, RTcap, and RTmac
     *
     * If xmit_lock is used, start_xmit points either to rtdev_locked_xmit or
     * the RTmac discipline handler. If xmit_lock is not required, start_xmit
     * points to hard_start_xmit or the discipline handler.
     */
    int                 (*start_xmit)(struct rtskb *skb,
                                      struct rtnet_device *dev);

    /* MTU hook, managed by the stack core and RTmac */
    unsigned int        (*get_mtu)(struct rtnet_device *rtdev,
                                   unsigned int priority);

146
147
    int                 (*do_ioctl)(struct rtnet_device *rtdev,
                                    unsigned int request, void * cmd);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
    struct net_device_stats *(*get_stats)(struct rtnet_device *rtdev);

    /* DMA pre-mapping hooks */
    dma_addr_t          (*map_rtskb)(struct rtnet_device *rtdev,
                                     struct rtskb *skb);
    void                (*unmap_rtskb)(struct rtnet_device *rtdev,
                                       struct rtskb *skb);
};


struct rtnet_core_cmd;

struct rtdev_event_hook {
    struct list_head    entry;
    void                (*register_device)(struct rtnet_device *rtdev);
    void                (*unregister_device)(struct rtnet_device *rtdev);
    void                (*ifup)(struct rtnet_device *rtdev,
                                struct rtnet_core_cmd *up_cmd);
    void                (*ifdown)(struct rtnet_device *rtdev);
};

extern struct list_head event_hook_list;
extern struct mutex rtnet_devices_nrt_lock;
extern struct rtnet_device *rtnet_devices[];


struct rtnet_device *rt_alloc_etherdev(int sizeof_priv);
void rtdev_free(struct rtnet_device *rtdev);

int rt_register_rtnetdev(struct rtnet_device *rtdev);
int rt_unregister_rtnetdev(struct rtnet_device *rtdev);

void rtdev_add_event_hook(struct rtdev_event_hook *hook);
void rtdev_del_event_hook(struct rtdev_event_hook *hook);

void rtdev_alloc_name (struct rtnet_device *rtdev, const char *name_mask);

/**
 *  __rtdev_get_by_index - find a rtnet_device by its ifindex
 *  @ifindex: index of device
 *  @note: caller must hold rtnet_devices_nrt_lock
 */
static inline struct rtnet_device *__rtdev_get_by_index(int ifindex)
{
    return rtnet_devices[ifindex-1];
}

struct rtnet_device *rtdev_get_by_name(const char *if_name);
struct rtnet_device *rtdev_get_by_index(int ifindex);
struct rtnet_device *rtdev_get_by_hwaddr(unsigned short type,char *ha);
struct rtnet_device *rtdev_get_loopback(void);

static inline void rtdev_reference(struct rtnet_device *rtdev)
{
202
    smp_mb__before_atomic();
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
203
204
205
206
207
    atomic_inc(&rtdev->refcount);
}

static inline void rtdev_dereference(struct rtnet_device *rtdev)
{
208
    smp_mb__before_atomic();
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
    atomic_dec(&rtdev->refcount);
}

int rtdev_xmit(struct rtskb *skb);

#ifdef CONFIG_XENO_DRIVERS_NET_ADDON_PROXY
int rtdev_xmit_proxy(struct rtskb *skb);
#endif

unsigned int rt_hard_mtu(struct rtnet_device *rtdev, unsigned int priority);

int rtdev_open(struct rtnet_device *rtdev);
int rtdev_close(struct rtnet_device *rtdev);

int rtdev_map_rtskb(struct rtskb *skb);
void rtdev_unmap_rtskb(struct rtskb *skb);

#endif  /* __KERNEL__ */

#endif  /* __RTDEV_H_ */