hc
2024-11-01 2f529f9b558ca1c1bd74be7437a84e4711743404
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
51
52
53
54
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***
 *
 *  rtmac/nomac/nomac_module.c
 *
 *  RTmac - real-time networking media access control subsystem
 *  Copyright (C) 2002       Marc Kleine-Budde <kleine-budde@gmx.de>,
 *                2003, 2004 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.
 *
 */
 
#include <linux/init.h>
#include <linux/module.h>
 
#include <rtdm/driver.h>
#include <rtmac/rtmac_vnic.h>
#include <rtmac/nomac/nomac.h>
#include <rtmac/nomac/nomac_dev.h>
#include <rtmac/nomac/nomac_ioctl.h>
#include <rtmac/nomac/nomac_proto.h>
 
#ifdef CONFIG_XENO_OPT_VFILE
LIST_HEAD(nomac_devices);
DEFINE_MUTEX(nomac_nrt_lock);
 
int nomac_proc_read(struct xnvfile_regular_iterator *it, void *data)
{
   struct nomac_priv *entry;
 
   mutex_lock(&nomac_nrt_lock);
 
   xnvfile_printf(it, "Interface       API Device      State\n");
 
   list_for_each_entry (entry, &nomac_devices, list_entry)
       xnvfile_printf(it, "%-15s %-15s Attached\n", entry->rtdev->name,
                  entry->api_device.name);
 
   mutex_unlock(&nomac_nrt_lock);
 
   return 0;
}
#endif /* CONFIG_XENO_OPT_VFILE */
 
int nomac_attach(struct rtnet_device *rtdev, void *priv)
{
   struct nomac_priv *nomac = (struct nomac_priv *)priv;
   int ret;
 
   nomac->magic = NOMAC_MAGIC;
   nomac->rtdev = rtdev;
 
   /* ... */
 
   ret = nomac_dev_init(rtdev, nomac);
   if (ret < 0)
       return ret;
 
#ifdef CONFIG_XENO_OPT_VFILE
   mutex_lock(&nomac_nrt_lock);
   list_add(&nomac->list_entry, &nomac_devices);
   mutex_unlock(&nomac_nrt_lock);
#endif /* CONFIG_XENO_OPT_VFILE */
 
   return 0;
}
 
int nomac_detach(struct rtnet_device *rtdev, void *priv)
{
   struct nomac_priv *nomac = (struct nomac_priv *)priv;
 
   nomac_dev_release(nomac);
 
   /* ... */
#ifdef CONFIG_XENO_OPT_VFILE
   mutex_lock(&nomac_nrt_lock);
   list_del(&nomac->list_entry);
   mutex_unlock(&nomac_nrt_lock);
#endif /* CONFIG_XENO_OPT_VFILE */
 
   return 0;
}
 
#ifdef CONFIG_XENO_OPT_VFILE
struct rtmac_proc_entry nomac_proc_entries[] = {
   { name: "nomac", handler: nomac_proc_read },
};
#endif /* CONFIG_XENO_OPT_VFILE */
 
struct rtmac_disc nomac_disc = {
   name: "NoMAC",
   priv_size: sizeof(struct nomac_priv),
   disc_type: __constant_htons(RTMAC_TYPE_NOMAC),
 
   packet_rx: nomac_packet_rx,
   rt_packet_tx: nomac_rt_packet_tx,
   nrt_packet_tx: nomac_nrt_packet_tx,
 
   get_mtu: NULL,
 
   vnic_xmit: RTMAC_DEFAULT_VNIC,
 
   attach: nomac_attach,
   detach: nomac_detach,
 
   ioctls: {
       service_name: "RTmac/NoMAC",
       ioctl_type: RTNET_IOC_TYPE_RTMAC_NOMAC,
       handler: nomac_ioctl
   },
 
#ifdef CONFIG_XENO_OPT_VFILE
   proc_entries: nomac_proc_entries,
   nr_proc_entries: ARRAY_SIZE(nomac_proc_entries),
#endif /* CONFIG_XENO_OPT_VFILE */
};
 
int __init nomac_init(void)
{
   int ret;
 
   printk("RTmac/NoMAC: init void media access control mechanism\n");
 
   ret = nomac_proto_init();
   if (ret < 0)
       return ret;
 
   ret = rtmac_disc_register(&nomac_disc);
   if (ret < 0) {
       nomac_proto_cleanup();
       return ret;
   }
 
   return 0;
}
 
void nomac_release(void)
{
   rtmac_disc_deregister(&nomac_disc);
   nomac_proto_cleanup();
 
   printk("RTmac/NoMAC: unloaded\n");
}
 
module_init(nomac_init);
module_exit(nomac_release);
 
MODULE_AUTHOR("Jan Kiszka");
MODULE_LICENSE("GPL");