[legacy] Remove long-obsolete old dhcp.h file
[people/oremanj/gpxe.git] / src / include / nic.h
1  /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License as
4  * published by the Free Software Foundation; either version 2, or (at
5  * your option) any later version.
6  */
7
8 #ifndef NIC_H
9 #define NIC_H
10
11 #include <stdint.h>
12 #include <string.h>
13 #include <stdio.h>
14 #include <byteswap.h>
15 #include <gpxe/pci.h>
16 #include <gpxe/isapnp.h>
17 #include <gpxe/isa.h>
18 #include <gpxe/eisa.h>
19 #include <gpxe/mca.h>
20 #include <gpxe/io.h>
21
22 typedef enum {
23         DISABLE = 0,
24         ENABLE,
25         FORCE
26 } irq_action_t;
27
28 typedef enum duplex {
29         HALF_DUPLEX = 1,
30         FULL_DUPLEX
31 } duplex_t;
32
33 /*
34  *      Structure returned from eth_probe and passed to other driver
35  *      functions.
36  */
37 struct nic {
38         struct nic_operations   *nic_op;
39         int                     flags;  /* driver specific flags */
40         unsigned char           *node_addr;
41         unsigned char           *packet;
42         unsigned int            packetlen;
43         unsigned int            ioaddr;
44         unsigned char           irqno;
45         unsigned int            mbps;
46         duplex_t                duplex;
47         void                    *priv_data;     /* driver private data */
48 };
49
50 struct nic_operations {
51         int ( *connect ) ( struct nic * );
52         int ( *poll ) ( struct nic *, int retrieve );
53         void ( *transmit ) ( struct nic *, const char *,
54                              unsigned int, unsigned int, const char * );
55         void ( *irq ) ( struct nic *, irq_action_t );
56 };
57
58 extern struct nic nic;
59
60 static inline int eth_poll ( int retrieve ) {
61         return nic.nic_op->poll ( &nic, retrieve );
62 }
63
64 static inline void eth_transmit ( const char *dest, unsigned int type,
65                                   unsigned int size, const void *packet ) {
66         nic.nic_op->transmit ( &nic, dest, type, size, packet );
67 }
68
69 /*
70  * Function prototypes
71  *
72  */
73 extern int dummy_connect ( struct nic *nic );
74 extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
75 extern int legacy_probe ( void *hwdev,
76                           void ( * set_drvdata ) ( void *hwdev, void *priv ),
77                           struct device *dev,
78                           int ( * probe ) ( struct nic *nic, void *hwdev ),
79                           void ( * disable ) ( struct nic *nic, void *hwdev ));
80 void legacy_remove ( void *hwdev,
81                      void * ( * get_drvdata ) ( void *hwdev ),
82                      void ( * disable ) ( struct nic *nic, void *hwdev ) );
83
84 #define PCI_DRIVER(_name,_ids,_class)                                     \
85         static inline int                                                 \
86         _name ## _pci_legacy_probe ( struct pci_device *pci,              \
87                                      const struct pci_device_id *id );    \
88         static inline void                                                \
89         _name ## _pci_legacy_remove ( struct pci_device *pci );           \
90         struct pci_driver _name __pci_driver = {                          \
91                 .ids = _ids,                                              \
92                 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),         \
93                 .probe = _name ## _pci_legacy_probe,                      \
94                 .remove = _name ## _pci_legacy_remove,                    \
95         };                                                                \
96         REQUIRE_OBJECT ( pci );
97
98 static inline void legacy_pci_set_drvdata ( void *hwdev, void *priv ) {
99         pci_set_drvdata ( hwdev, priv );
100 }
101 static inline void * legacy_pci_get_drvdata ( void *hwdev ) {
102         return pci_get_drvdata ( hwdev );
103 }
104
105 #define ISAPNP_DRIVER(_name,_ids)                                         \
106         static inline int                                                 \
107         _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp,     \
108                                         const struct isapnp_device_id *id ); \
109         static inline void                                                \
110         _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp );  \
111         struct isapnp_driver _name __isapnp_driver = {                    \
112                 .ids = _ids,                                              \
113                 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),         \
114                 .probe = _name ## _isapnp_legacy_probe,                   \
115                 .remove = _name ## _isapnp_legacy_remove,                 \
116         };                                                                \
117         REQUIRE_OBJECT ( isapnp );
118
119 static inline void legacy_isapnp_set_drvdata ( void *hwdev, void *priv ) {
120         isapnp_set_drvdata ( hwdev, priv );
121 }
122 static inline void * legacy_isapnp_get_drvdata ( void *hwdev ) {
123         return isapnp_get_drvdata ( hwdev );
124 }
125
126 #define EISA_DRIVER(_name,_ids)                                           \
127         static inline int                                                 \
128         _name ## _eisa_legacy_probe ( struct eisa_device *eisa,           \
129                                       const struct eisa_device_id *id );  \
130         static inline void                                                \
131         _name ## _eisa_legacy_remove ( struct eisa_device *eisa );        \
132         struct eisa_driver _name __eisa_driver = {                        \
133                 .ids = _ids,                                              \
134                 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),         \
135                 .probe = _name ## _eisa_legacy_probe,                     \
136                 .remove = _name ## _eisa_legacy_remove,                   \
137         };                                                                \
138         REQUIRE_OBJECT ( eisa );
139
140 static inline void legacy_eisa_set_drvdata ( void *hwdev, void *priv ) {
141         eisa_set_drvdata ( hwdev, priv );
142 }
143 static inline void * legacy_eisa_get_drvdata ( void *hwdev ) {
144         return eisa_get_drvdata ( hwdev );
145 }
146
147 #define MCA_DRIVER(_name,_ids)                                            \
148         static inline int                                                 \
149         _name ## _mca_legacy_probe ( struct mca_device *mca,              \
150                                      const struct mca_device_id *id );    \
151         static inline void                                                \
152         _name ## _mca_legacy_remove ( struct mca_device *mca );           \
153         struct mca_driver _name __mca_driver = {                          \
154                 .ids = _ids,                                              \
155                 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ),         \
156                 .probe = _name ## _mca_legacy_probe,                      \
157                 .remove = _name ## _mca_legacy_remove,                    \
158         };                                                                \
159         REQUIRE_OBJECT ( mca );
160
161 static inline void legacy_mca_set_drvdata ( void *hwdev, void *priv ) {
162         mca_set_drvdata ( hwdev, priv );
163 }
164 static inline void * legacy_mca_get_drvdata ( void *hwdev ) {
165         return mca_get_drvdata ( hwdev );
166 }
167
168 #define ISA_DRIVER(_name,_probe_addrs,_probe_addr,_vendor_id,_prod_id)    \
169         static inline int                                                 \
170         _name ## _isa_legacy_probe ( struct isa_device *isa );            \
171         static inline int                                                 \
172         _name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) {   \
173                 if ( ! _probe_addr ( isa->ioaddr ) )                      \
174                         return -ENODEV;                                   \
175                 return _name ## _isa_legacy_probe ( isa );                \
176         }                                                                 \
177         static inline void                                                \
178         _name ## _isa_legacy_remove ( struct isa_device *isa );           \
179         static const char _name ## _text[];                               \
180         struct isa_driver _name __isa_driver = {                          \
181                 .name = _name ## _text,                                   \
182                 .probe_addrs = _probe_addrs,                              \
183                 .addr_count = ( sizeof ( _probe_addrs ) /                 \
184                                 sizeof ( _probe_addrs[0] ) ),             \
185                 .vendor_id = _vendor_id,                                  \
186                 .prod_id = _prod_id,                                      \
187                 .probe = _name ## _isa_legacy_probe_at_addr,              \
188                 .remove = _name ## _isa_legacy_remove,                    \
189         };                                                                \
190         REQUIRE_OBJECT ( isa );
191
192 static inline void legacy_isa_set_drvdata ( void *hwdev, void *priv ) {
193         isa_set_drvdata ( hwdev, priv );
194 }
195 static inline void * legacy_isa_get_drvdata ( void *hwdev ) {
196         return isa_get_drvdata ( hwdev );
197 }
198
199 #undef DRIVER
200 #define DRIVER(_name_text,_unused2,_unused3,_name,_probe,_disable)        \
201         static const char _name ## _text[] = _name_text;                  \
202         static inline int                                                 \
203         _name ## _probe ( struct nic *nic, void *hwdev ) {                \
204                 return _probe ( nic, hwdev );                             \
205         }                                                                 \
206         static inline void                                                \
207         _name ## _disable ( struct nic *nic, void *hwdev ) {              \
208                 void ( * _unsafe_disable ) () = _disable;                 \
209                 _unsafe_disable ( nic, hwdev );                           \
210         }                                                                 \
211         static inline int                                                 \
212         _name ## _pci_legacy_probe ( struct pci_device *pci,              \
213                             const struct pci_device_id *id __unused ) {   \
214                 return legacy_probe ( pci, legacy_pci_set_drvdata,        \
215                                       &pci->dev, _name ## _probe,         \
216                                       _name ## _disable );                \
217         }                                                                 \
218         static inline void                                                \
219         _name ## _pci_legacy_remove ( struct pci_device *pci ) {          \
220                 return legacy_remove ( pci, legacy_pci_get_drvdata,       \
221                                        _name ## _disable );               \
222         }                                                                 \
223         static inline int                                                 \
224         _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp,     \
225                          const struct isapnp_device_id *id __unused ) {   \
226                 return legacy_probe ( isapnp, legacy_isapnp_set_drvdata,  \
227                                       &isapnp->dev, _name ## _probe,      \
228                                       _name ## _disable );                \
229         }                                                                 \
230         static inline void                                                \
231         _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
232                 return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
233                                        _name ## _disable );               \
234         }                                                                 \
235         static inline int                                                 \
236         _name ## _eisa_legacy_probe ( struct eisa_device *eisa,           \
237                              const struct eisa_device_id *id __unused ) { \
238                 return legacy_probe ( eisa, legacy_eisa_set_drvdata,      \
239                                       &eisa->dev, _name ## _probe,        \
240                                       _name ## _disable );                \
241         }                                                                 \
242         static inline void                                                \
243         _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) {       \
244                 return legacy_remove ( eisa, legacy_eisa_get_drvdata,     \
245                                        _name ## _disable );               \
246         }                                                                 \
247         static inline int                                                 \
248         _name ## _mca_legacy_probe ( struct mca_device *mca,              \
249                               const struct mca_device_id *id __unused ) { \
250                 return legacy_probe ( mca, legacy_mca_set_drvdata,        \
251                                       &mca->dev, _name ## _probe,         \
252                                       _name ## _disable );                \
253         }                                                                 \
254         static inline void                                                \
255         _name ## _mca_legacy_remove ( struct mca_device *mca ) {          \
256                 return legacy_remove ( mca, legacy_mca_get_drvdata,       \
257                                        _name ## _disable );               \
258         }                                                                 \
259         static inline int                                                 \
260         _name ## _isa_legacy_probe ( struct isa_device *isa ) {           \
261                 return legacy_probe ( isa, legacy_isa_set_drvdata,        \
262                                       &isa->dev, _name ## _probe,         \
263                                       _name ## _disable );                \
264         }                                                                 \
265         static inline void                                                \
266         _name ## _isa_legacy_remove ( struct isa_device *isa ) {          \
267                 return legacy_remove ( isa, legacy_isa_get_drvdata,       \
268                                        _name ## _disable );               \
269         }
270
271 #endif  /* NIC_H */