-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
160 lines (149 loc) · 4.63 KB
/
main.c
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
/**
*@mainpage TrustNode Ethernetdriver
*@author M.Ulbricht, G.Eschemann
*
*This is the documentation for the TrustNode Ethernet driver. The code is mainly structured in PCI and NetWork communication. You should start browsing the <a href="files.html">filelist</a> first.<br>Questions and bugs please report to <a href="mailto:[email protected]">[email protected]</a>
**/
/**
*@file
*@brief main driver Function
*M.Ulbricht 2015
**/
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include "INR.h"
//#include "INR-PCI.h"
#include "INR-NW.h"
//#include "INR-ctl.h"
volatile uint8_t probed=0;
static void remove (void);
/**
*@brief PCI-Device definition
*
*/
struct net_device *INR_NW;
/**
*@brief init nw-device
*
*/
int
INR_NWDEV_init (void)
{
uint8_t i = 0;
for (i = 0; i < INR_NW_devcount; i++) {
//INR_NW = alloc_netdev (sizeof (struct INR_NW_priv), "TN%d", NET_NAME_UNKNOWN, INR_NW_init);
INR_NW = alloc_netdev_mq (sizeof (struct INR_NW_priv), "TN%d", NET_NAME_UNKNOWN, INR_NW_init,TX_queue_count);
if (INR_NW == NULL) {
INR_LOG_debug (loglevel_err"Cant alloc NWDEV %i !\n", i);
return 1;
} else {
if (0 == register_netdev (INR_NW))
INR_LOG_debug (loglevel_info"NWDev %i registerd, flags:%llx ", i, INR_NW->hw_features);
INR_LOG_debug (loglevel_info"flags2:%llx\n", INR_NW->hw_features);
set_nwdev (i, INR_NW);
}
}
return 0;
}
//*****************************************************************************************************************
/**
*destroy nw-device
*/
void
INR_NWDEV_destroi (void)
{
uint8_t i = 0;
for (i = 0; i < INR_NW_devcount; i++) {
INR_LOG_debug (loglevel_info"destroy INRNWDEV %i\n",i);
unregister_netdev (get_nwdev(i));
free_netdev (get_nwdev(i));
}
}
//*****************************************************************************************************************
/**
*init driver function
*/
static int
probe(void)
{
printk (loglevel_info "moep!\n"); //this is one of the verry important things needed to run the driver :D
if (probed) {
INR_LOG_debug (loglevel_err"driver already loaded... exit\n");
return -1;
}
probed++; //prevent driver from loaded twice
INR_NW_zerovars(); //reset all global vars
//INR_PCI_zerovars();
//INR_zerovars();
int result;
//INR_LOG_timelog_init (); //safe timestamp
INR_LOG_debug (loglevel_info"Start load module\n");
/*if ((result = pci_enable_device (dev)) < 0) {
INR_LOG_debug (loglevel_err"device enable fail...\n");
return result;
} else {
INR_LOG_debug (loglevel_info"device enabled\n");
INR_STATUS_set (INR_STATUS_DEVICE);
}*/
if (0 == INR_NWDEV_init ()) {
INR_STATUS_set (INR_STATUS_NW_enabled);
}
//INR_init_drv (dev); //INIT pci and network
//INR_CTL_init_proc (dev); //init proc fs
//INR_STATUS_set (INR_STATUS_DRV_INIT_done);
return 0;
}
//*****************************************************************************************************************
/*static struct pci_driver pci_driver = {
.name = "INRTrustnode",
.id_table = ids,
.probe = probe,
.remove = remove,
};*/
//*****************************************************************************************************************
/**
*driver-end function, called by kernel
*@param *dev PCI-device
*/
static void
remove (void)
{
INR_NWDEV_destroi();
//INR_CTL_remove_proc (dev);
INR_LOG_debug (loglevel_info"remove Module\n");
INR_LOG_debug (loglevel_info"Reset Logic\n");
//INR_remove_drv (dev);
if(probed) {
probed--;
}
}
//*****************************************************************************************************************
static int __init
pci_skel_init (void)
{
//return pci_register_driver (&pci_driver);
probe();
}
//*****************************************************************************************************************
static void __exit
pci_skel_exit (void)
{
//pci_unregister_driver (&pci_driver);
remove();
}
//*****************************************************************************************************************
module_init (pci_skel_init);
module_exit (pci_skel_exit);
MODULE_LICENSE ("Dual BSD/GPL");
MODULE_AUTHOR ("M.Ulbricht");
MODULE_VERSION ("1.0");
MODULE_DESCRIPTION ("InnoRoute GTP dummy driver");
//MODULE_DEVICE_TABLE (pci, ids);