rtdev.h 7.78 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
};

/***
 *  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      *
88
				     * forces correct macro usage   */
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
89
90
91
92
93
94
95

    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      */
96
    netdev_features_t   features;   /* [RT]NETIF_F_*                */
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

    /* 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 */

117
118
    struct rtskb_pool   rx_pool;

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
119
120
121
122
123
124
125
126
127
    /* 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 *,
128
129
				       unsigned short type, void *daddr,
				       void *saddr, unsigned int len);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
130
131
    int                 (*rebuild_header)(struct rtskb *);
    int                 (*hard_start_xmit)(struct rtskb *skb,
132
					   struct rtnet_device *dev);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
133
134
135
136
137
138
139
140
141
    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,
142
				      struct rtnet_device *dev);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
143
144
145

    /* MTU hook, managed by the stack core and RTmac */
    unsigned int        (*get_mtu)(struct rtnet_device *rtdev,
146
				   unsigned int priority);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
147

148
    int                 (*do_ioctl)(struct rtnet_device *rtdev,
149
				    unsigned int request, void * cmd);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
150
151
152
153
    struct net_device_stats *(*get_stats)(struct rtnet_device *rtdev);

    /* DMA pre-mapping hooks */
    dma_addr_t          (*map_rtskb)(struct rtnet_device *rtdev,
154
				     struct rtskb *skb);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
155
    void                (*unmap_rtskb)(struct rtnet_device *rtdev,
156
				       struct rtskb *skb);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
157
158
159
160
161
162
163
164
165
166
};


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,
167
				struct rtnet_core_cmd *up_cmd);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
168
169
170
171
172
173
174
175
    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[];


176
177
178
179
180
181
struct rtnet_device *__rt_alloc_etherdev(unsigned sizeof_priv,
					unsigned rx_pool_size,
					struct module *module);
#define rt_alloc_etherdev(priv_size, rx_size) \
    __rt_alloc_etherdev(priv_size, rx_size, THIS_MODULE)

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
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);

207
int rtdev_reference(struct rtnet_device *rtdev);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
208
209
210

static inline void rtdev_dereference(struct rtnet_device *rtdev)
{
211
    smp_mb__before_atomic();
212
213
    if (rtdev->rt_owner && atomic_dec_and_test(&rtdev->refcount))
	module_put(rtdev->rt_owner);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
214
215
216
217
}

int rtdev_xmit(struct rtskb *skb);

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
218
#if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_ADDON_PROXY)
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
219
220
221
222
223
224
225
226
227
228
229
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);

230
231
struct rtskb *rtnetdev_alloc_rtskb(struct rtnet_device *dev, unsigned int size);

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
232
233
234
#endif  /* __KERNEL__ */

#endif  /* __RTDEV_H_ */