RTEMS  5.0.0
rtemscompat1.h
1 #ifndef RTEMS_COMPAT1_BSD_NET_H
2 #define RTEMS_COMPAT1_BSD_NET_H
3 
4 /* BSD -> RTEMS conversion wrappers; stuff that must be defined
5  * after most BSD headers are included.
6  */
7 
8 #include <netinet/in.h>
9 #include <netinet/if_ether.h>
10 
11 /* Copyright: Till Straumann <strauman@slac.stanford.edu>, 2005;
12  * License: see LICENSE file.
13  */
14 
15 typedef struct device {
16  struct NET_SOFTC d_softc; /* MUST BE FIRST FIELD */
17  char *d_name;
18  char *d_desc;
19  int d_unit;
20  int flags;
21  /* pointer to ifconfig only valid during excution of
22  * the n_attach/n_detach methods (see below)
23  */
24  struct rtems_bsdnet_ifconfig *d_ifconfig;
25 } netdev_t;
26 
27 #define THEDEVS NET_EMBEMB(the_,NETDRIVER_PREFIX,_devs)
28 #define NETDEV_DECL netdev_t THEDEVS[NETDRIVER_SLOTS]
29 
30 extern NETDEV_DECL;
31 
32 typedef struct _net_drv_tbl {
33  int (*n_probe)(device_t);
34  int (*n_attach)(device_t);
35  int (*n_detach)(device_t);
36  void (*n_intr)(void *);
38 
39 static inline netdev_t *
40 net_dev_get(struct rtems_bsdnet_ifconfig *config)
41 {
42  int unitNo;
43  char *unitName;
44 
45  unitNo = rtems_bsdnet_parse_driver_name(config, &unitName);
46  if ( unitNo < 0 )
47  return 0;
48 
49  if ( unitNo <=0 || unitNo > NETDRIVER_SLOTS ) {
50  device_printf(dev, "Bad "NETDRIVER" unit number.\n");
51  return 0;
52  }
53 
54  if ( THEDEVS[unitNo-1].d_unit && THEDEVS[unitNo-1].d_unit != unitNo ) {
55  device_printf(dev, "Unit # mismatch !!??\n");
56  return 0;
57  }
58 
59  THEDEVS[unitNo-1].d_unit = unitNo;
60  THEDEVS[unitNo-1].d_name = unitName;
61  THEDEVS[unitNo-1].d_ifconfig = config;
62 
63  return &THEDEVS[unitNo - 1];
64 }
65 
66 /* kludge; that's why softc needs to be first */
67 static inline netdev_t *
68 softc_get_device(struct NET_SOFTC *sc)
69 {
70  return (netdev_t *)sc;
71 }
72 
73 static inline struct NET_SOFTC *
74 device_get_softc(netdev_t *dev)
75 { return &dev->d_softc; }
76 
77 static inline int
78 device_get_unit(netdev_t *dev)
79 { return dev->d_unit; }
80 
81 static inline char *
82 device_get_name(netdev_t *dev)
83 { return dev->d_name; }
84 
85 static inline void
86 if_initname(struct ifnet *ifp, char *name, int unit)
87 {
88  ifp->if_name = name;
89  ifp->if_unit = unit;
90 }
91 
92 static inline void
93 device_set_desc(netdev_t *dev, char *str)
94 {
95  dev->d_desc = str;
96 }
97 
98 static inline void
99 device_set_desc_copy(netdev_t *dev, char *str)
100 {
101  dev->d_desc = strdup(str);
102 }
103 
104 
105 static inline int
106 device_is_attached(netdev_t *dev)
107 {
108  return dev->d_softc.arpcom.ac_if.if_addrlist && dev->d_softc.arpcom.ac_if.if_init;
109 }
110 
111 #ifdef NETDRIVER_PCI
112 #include NETDRIVER_PCI
113 #include "pcireg.h"
114 
115 static inline unsigned
116 pci_read_config(device_t dev, unsigned addr, unsigned width)
117 {
118 rtemscompat_32_t d;
119 unsigned short s;
120 unsigned char b;
121 struct NET_SOFTC *sc = device_get_softc(dev);
122  switch (width) {
123  case 1: pci_read_config_byte(sc->b, sc->d, sc->f, addr, &b);
124  return b;
125  case 2: pci_read_config_word(sc->b, sc->d, sc->f, addr, &s);
126  return s;
127  case 4: pci_read_config_dword(sc->b, sc->d, sc->f, addr, &d);
128  return d;
129  default:
130  break;
131  }
132  return 0xdeadbeef;
133 }
134 
135 static inline void
136 pci_write_config(device_t dev, unsigned addr, unsigned width, unsigned val)
137 {
138 struct NET_SOFTC *sc = device_get_softc(dev);
139  switch (width) {
140  case 1: pci_write_config_byte(sc->b, sc->d, sc->f, addr, val);
141  return ;
142  case 2: pci_write_config_word(sc->b, sc->d, sc->f, addr, val);
143  return ;
144  case 4: pci_write_config_dword(sc->b, sc->d, sc->f, addr, val);
145  return ;
146  default:
147  break;
148  }
149 }
150 
151 
152 static inline unsigned short
153 pci_get_vendor(device_t dev)
154 {
155  return pci_read_config(dev, PCIR_VENDOR, 2);
156 }
157 
158 static inline unsigned short
159 pci_get_device(device_t dev)
160 {
161  return pci_read_config(dev, PCIR_DEVICE, 2);
162 }
163 
164 static inline unsigned short
165 pci_get_subvendor(device_t dev)
166 {
167  return pci_read_config(dev, PCIR_SUBVEND_0, 2);
168 }
169 
170 static inline unsigned short
171 pci_get_subdevice(device_t dev)
172 {
173  return pci_read_config(dev, PCIR_SUBDEV_0, 2);
174 }
175 
176 
177 static inline void
178 pci_enable_busmaster(device_t dev)
179 {
180  pci_write_config(
181  dev,
182  PCIR_COMMAND,
183  2,
184  pci_read_config(dev, PCIR_COMMAND, 2)
185  | PCIM_CMD_BUSMASTEREN);
186 }
187 
188 #define mtx_init(a,b,c,d) do {} while(0)
189 #define mtx_initialized(ma) (1)
190 #define mtx_destroy(ma) do {} while(0)
191 #define mtx_lock(a) do {} while(0)
192 #define mtx_unlock(a) do {} while(0)
193 #define mtx_assert(a,b) do {} while(0)
194 
195 #define callout_handle_init(x) do {} while (0)
196 #define untimeout(a...) do {} while (0)
197 
198 #if !ISMINVERSION(4,6,99)
199 #define pci_bus_count BusCountPCI
200 #endif
201 
202 #endif
203 
204 /* Ugly hack to allow unloading/reloading the driver core.
205  * Needed because rtems' bsdnet release doesn't implement
206  * if_detach(). Therefore, we bring the interface down but
207  * keep the device record alive...
208  */
209 static inline void
210 __ether_ifdetach(struct ifnet *ifp)
211 {
212  ifp->if_flags = 0;
213  ifp->if_ioctl = 0;
214  ifp->if_start = 0;
215  ifp->if_watchdog = 0;
216  ifp->if_init = 0;
217 }
218 
219 #endif
Definition: deflate.c:115
Definition: rtemscompat1.h:15
struct rtems_bsdnet_ifconfig * config
Network driver configuration.
Definition: rtemscompat1.h:32