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
/***
 *
 *  rtmac/nomac/nomac_proto.c
 *
 *  RTmac - real-time networking media access control subsystem
 *  Copyright (C) 2002      Marc Kleine-Budde <kleine-budde@gmx.de>,
 *                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.
 *
 */
 
#include <linux/init.h>
 
#include <rtdev.h>
#include <rtmac/rtmac_proto.h>
#include <rtmac/nomac/nomac.h>
 
static struct rtskb_queue nrt_rtskb_queue;
static rtdm_task_t wrapper_task;
static rtdm_event_t wakeup_sem;
 
int nomac_rt_packet_tx(struct rtskb *rtskb, struct rtnet_device *rtdev)
{
   /* unused here, just to demonstrate access to the discipline state
    struct nomac_priv   *nomac =
        (struct nomac_priv *)rtdev->mac_priv->disc_priv; */
   int ret;
 
   rtcap_mark_rtmac_enqueue(rtskb);
 
   /* no MAC: we simply transmit the packet under xmit_lock */
   rtdm_mutex_lock(&rtdev->xmit_mutex);
   ret = rtmac_xmit(rtskb);
   rtdm_mutex_unlock(&rtdev->xmit_mutex);
 
   return ret;
}
 
int nomac_nrt_packet_tx(struct rtskb *rtskb)
{
   struct rtnet_device *rtdev = rtskb->rtdev;
   /* unused here, just to demonstrate access to the discipline state
    struct nomac_priv   *nomac =
        (struct nomac_priv *)rtdev->mac_priv->disc_priv; */
   int ret;
 
   rtcap_mark_rtmac_enqueue(rtskb);
 
   /* note: this routine may be called both in rt and non-rt context
     *       => detect and wrap the context if necessary */
   if (!rtdm_in_rt_context()) {
       rtskb_queue_tail(&nrt_rtskb_queue, rtskb);
       rtdm_event_signal(&wakeup_sem);
       return 0;
   } else {
       /* no MAC: we simply transmit the packet under xmit_lock */
       rtdm_mutex_lock(&rtdev->xmit_mutex);
       ret = rtmac_xmit(rtskb);
       rtdm_mutex_unlock(&rtdev->xmit_mutex);
 
       return ret;
   }
}
 
void nrt_xmit_task(void *arg)
{
   struct rtskb *rtskb;
   struct rtnet_device *rtdev;
 
   while (!rtdm_task_should_stop()) {
       if (rtdm_event_wait(&wakeup_sem) < 0)
           break;
 
       while ((rtskb = rtskb_dequeue(&nrt_rtskb_queue))) {
           rtdev = rtskb->rtdev;
 
           /* no MAC: we simply transmit the packet under xmit_lock */
           rtdm_mutex_lock(&rtdev->xmit_mutex);
           rtmac_xmit(rtskb);
           rtdm_mutex_unlock(&rtdev->xmit_mutex);
       }
   }
}
 
int nomac_packet_rx(struct rtskb *rtskb)
{
   /* actually, NoMAC doesn't expect any control packet */
   kfree_rtskb(rtskb);
 
   return 0;
}
 
int __init nomac_proto_init(void)
{
   int ret;
 
   rtskb_queue_init(&nrt_rtskb_queue);
   rtdm_event_init(&wakeup_sem, 0);
 
   ret = rtdm_task_init(&wrapper_task, "rtnet-nomac", nrt_xmit_task, 0,
                RTDM_TASK_LOWEST_PRIORITY, 0);
   if (ret < 0) {
       rtdm_event_destroy(&wakeup_sem);
       return ret;
   }
 
   return 0;
}
 
void nomac_proto_cleanup(void)
{
   rtdm_event_destroy(&wakeup_sem);
   rtdm_task_destroy(&wrapper_task);
}