rtdev.h 9.31 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
/***
 *
 *  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

49
50
#define RTDEV_TX_OK		0
#define RTDEV_TX_BUSY	1
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
51
52

enum rtnet_link_state {
53
54
55
56
	__RTNET_LINK_STATE_XOFF = 0,
	__RTNET_LINK_STATE_START,
	__RTNET_LINK_STATE_PRESENT,
	__RTNET_LINK_STATE_NOCARRIER,
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
57
};
58
59
60
61
#define RTNET_LINK_STATE_XOFF (1 << __RTNET_LINK_STATE_XOFF)
#define RTNET_LINK_STATE_START (1 << __RTNET_LINK_STATE_START)
#define RTNET_LINK_STATE_PRESENT (1 << __RTNET_LINK_STATE_PRESENT)
#define RTNET_LINK_STATE_NOCARRIER (1 << __RTNET_LINK_STATE_NOCARRIER)
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
62
63
64
65
66
67
68
69
70
71
72

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

    char                name[IFNAMSIZ];
73
    struct device	*sysbind;   /* device bound in sysfs (optional) */
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

    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;

94
    struct device	*sysdev;    /* node in driver model for sysfs */
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
95
    struct module       *rt_owner;  /* like classic owner, but      *
96
				     * forces correct macro usage   */
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
97
98
99
100
101
102
103

    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      */
104
    netdev_features_t   features;   /* [RT]NETIF_F_*                */
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124

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

125
    struct rtskb_pool   dev_pool;
126

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
127
128
129
130
131
132
133
134
135
    /* 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 *,
136
137
				       unsigned short type, void *daddr,
				       void *saddr, unsigned int len);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
138
139
    int                 (*rebuild_header)(struct rtskb *);
    int                 (*hard_start_xmit)(struct rtskb *skb,
140
					   struct rtnet_device *dev);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
141
142
143
144
145
146
147
148
149
    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,
150
				      struct rtnet_device *dev);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
151
152
153

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

156
    int                 (*do_ioctl)(struct rtnet_device *rtdev,
157
				    struct ifreq *ifr, int cmd);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
158
159
160
161
    struct net_device_stats *(*get_stats)(struct rtnet_device *rtdev);

    /* DMA pre-mapping hooks */
    dma_addr_t          (*map_rtskb)(struct rtnet_device *rtdev,
162
				     struct rtskb *skb);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
163
    void                (*unmap_rtskb)(struct rtnet_device *rtdev,
164
				       struct rtskb *skb);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
165
166
167
168
169
170
171
172
173
};

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,
174
				struct rtnet_core_cmd *up_cmd);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
175
176
177
178
179
180
181
182
    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[];


183
struct rtnet_device *__rt_alloc_etherdev(unsigned sizeof_priv,
184
					unsigned dev_pool_size,
185
186
187
188
					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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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);

214
int rtdev_reference(struct rtnet_device *rtdev);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
215
216
217

static inline void rtdev_dereference(struct rtnet_device *rtdev)
{
218
    smp_mb__before_atomic();
219
220
    if (rtdev->rt_owner && atomic_dec_and_test(&rtdev->refcount))
	module_put(rtdev->rt_owner);
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
221
222
223
224
}

int rtdev_xmit(struct rtskb *skb);

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
225
#if IS_ENABLED(CONFIG_XENO_DRIVERS_NET_ADDON_PROXY)
Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
226
227
228
229
230
231
232
233
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);

234
235
236
237
int rtdev_up(struct rtnet_device *rtdev,
	     struct rtnet_core_cmd *cmd);
int rtdev_down(struct rtnet_device *rtdev);

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
238
239
240
int rtdev_map_rtskb(struct rtskb *skb);
void rtdev_unmap_rtskb(struct rtskb *skb);

241
242
struct rtskb *rtnetdev_alloc_rtskb(struct rtnet_device *dev, unsigned int size);

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
#define rtnetdev_priv(dev) ((dev)->priv)

#define rtdev_emerg(__dev, format, args...) \
	pr_emerg("%s: " format, (__dev)->name, ##args)
#define rtdev_alert(__dev, format, args...) \
	pr_alert("%s: " format, (__dev)->name, ##args)
#define rtdev_crit(__dev, format, args...) \
	pr_crit("%s: " format, (__dev)->name, ##args)
#define rtdev_err(__dev, format, args...) \
	pr_err("%s: " format, (__dev)->name, ##args)
#define rtdev_warn(__dev, format, args...) \
	pr_warn("%s: " format, (__dev)->name, ##args)
#define rtdev_notice(__dev, format, args...) \
	pr_notice("%s: " format, (__dev)->name, ##args)
#define rtdev_info(__dev, format, args...) \
	pr_info("%s: " format, (__dev)->name, ##args)
#define rtdev_dbg(__dev, format, args...) \
	pr_debug("%s: " format, (__dev)->name, ##args)

#ifdef VERBOSE_DEBUG
#define rtdev_vdbg rtdev_dbg
#else
#define rtdev_vdbg(__dev, format, args...)			\
({								\
	if (0)							\
		pr_debug("%s: " format, (__dev)->name, ##args);	\
								\
	0;							\
})
#endif

Gilles Chanteperdrix's avatar
Gilles Chanteperdrix committed
274
275
276
#endif  /* __KERNEL__ */

#endif  /* __RTDEV_H_ */