00001
00002
00003
00004
00005
00006
00007
00008 FILE_LICENCE ( GPL2_OR_LATER );
00009
00010 #ifndef NIC_H
00011 #define NIC_H
00012
00013 #include <stdint.h>
00014 #include <string.h>
00015 #include <stdio.h>
00016 #include <byteswap.h>
00017 #include <gpxe/pci.h>
00018 #include <gpxe/isapnp.h>
00019 #include <gpxe/isa.h>
00020 #include <gpxe/eisa.h>
00021 #include <gpxe/mca.h>
00022 #include <gpxe/io.h>
00023
00024 typedef enum {
00025 DISABLE = 0,
00026 ENABLE,
00027 FORCE
00028 } irq_action_t;
00029
00030 typedef enum duplex {
00031 HALF_DUPLEX = 1,
00032 FULL_DUPLEX
00033 } duplex_t;
00034
00035
00036
00037
00038
00039 struct nic {
00040 struct nic_operations *nic_op;
00041 int flags;
00042 unsigned char *node_addr;
00043 unsigned char *packet;
00044 unsigned int packetlen;
00045 unsigned int ioaddr;
00046 unsigned char irqno;
00047 unsigned int mbps;
00048 duplex_t duplex;
00049 void *priv_data;
00050 };
00051
00052 struct nic_operations {
00053 int ( *connect ) ( struct nic * );
00054 int ( *poll ) ( struct nic *, int retrieve );
00055 void ( *transmit ) ( struct nic *, const char *,
00056 unsigned int, unsigned int, const char * );
00057 void ( *irq ) ( struct nic *, irq_action_t );
00058 };
00059
00060 extern struct nic nic;
00061
00062 static inline int eth_poll ( int retrieve ) {
00063 return nic.nic_op->poll ( &nic, retrieve );
00064 }
00065
00066 static inline void eth_transmit ( const char *dest, unsigned int type,
00067 unsigned int size, const void *packet ) {
00068 nic.nic_op->transmit ( &nic, dest, type, size, packet );
00069 }
00070
00071
00072
00073
00074
00075 extern int dummy_connect ( struct nic *nic );
00076 extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
00077 extern int legacy_probe ( void *hwdev,
00078 void ( * set_drvdata ) ( void *hwdev, void *priv ),
00079 struct device *dev,
00080 int ( * probe ) ( struct nic *nic, void *hwdev ),
00081 void ( * disable ) ( struct nic *nic, void *hwdev ));
00082 void legacy_remove ( void *hwdev,
00083 void * ( * get_drvdata ) ( void *hwdev ),
00084 void ( * disable ) ( struct nic *nic, void *hwdev ) );
00085
00086 #define PCI_DRIVER(_name,_ids,_class) \
00087 static inline int \
00088 _name ## _pci_legacy_probe ( struct pci_device *pci, \
00089 const struct pci_device_id *id ); \
00090 static inline void \
00091 _name ## _pci_legacy_remove ( struct pci_device *pci ); \
00092 struct pci_driver _name __pci_driver = { \
00093 .ids = _ids, \
00094 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
00095 .probe = _name ## _pci_legacy_probe, \
00096 .remove = _name ## _pci_legacy_remove, \
00097 }; \
00098 REQUIRE_OBJECT ( pci );
00099
00100 static inline void legacy_pci_set_drvdata ( void *hwdev, void *priv ) {
00101 pci_set_drvdata ( hwdev, priv );
00102 }
00103 static inline void * legacy_pci_get_drvdata ( void *hwdev ) {
00104 return pci_get_drvdata ( hwdev );
00105 }
00106
00107 #define ISAPNP_DRIVER(_name,_ids) \
00108 static inline int \
00109 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
00110 const struct isapnp_device_id *id ); \
00111 static inline void \
00112 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ); \
00113 struct isapnp_driver _name __isapnp_driver = { \
00114 .ids = _ids, \
00115 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
00116 .probe = _name ## _isapnp_legacy_probe, \
00117 .remove = _name ## _isapnp_legacy_remove, \
00118 }; \
00119 REQUIRE_OBJECT ( isapnp );
00120
00121 static inline void legacy_isapnp_set_drvdata ( void *hwdev, void *priv ) {
00122 isapnp_set_drvdata ( hwdev, priv );
00123 }
00124 static inline void * legacy_isapnp_get_drvdata ( void *hwdev ) {
00125 return isapnp_get_drvdata ( hwdev );
00126 }
00127
00128 #define EISA_DRIVER(_name,_ids) \
00129 static inline int \
00130 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
00131 const struct eisa_device_id *id ); \
00132 static inline void \
00133 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ); \
00134 struct eisa_driver _name __eisa_driver = { \
00135 .ids = _ids, \
00136 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
00137 .probe = _name ## _eisa_legacy_probe, \
00138 .remove = _name ## _eisa_legacy_remove, \
00139 }; \
00140 REQUIRE_OBJECT ( eisa );
00141
00142 static inline void legacy_eisa_set_drvdata ( void *hwdev, void *priv ) {
00143 eisa_set_drvdata ( hwdev, priv );
00144 }
00145 static inline void * legacy_eisa_get_drvdata ( void *hwdev ) {
00146 return eisa_get_drvdata ( hwdev );
00147 }
00148
00149 #define MCA_DRIVER(_name,_ids) \
00150 static inline int \
00151 _name ## _mca_legacy_probe ( struct mca_device *mca, \
00152 const struct mca_device_id *id ); \
00153 static inline void \
00154 _name ## _mca_legacy_remove ( struct mca_device *mca ); \
00155 struct mca_driver _name __mca_driver = { \
00156 .ids = _ids, \
00157 .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
00158 .probe = _name ## _mca_legacy_probe, \
00159 .remove = _name ## _mca_legacy_remove, \
00160 }; \
00161 REQUIRE_OBJECT ( mca );
00162
00163 static inline void legacy_mca_set_drvdata ( void *hwdev, void *priv ) {
00164 mca_set_drvdata ( hwdev, priv );
00165 }
00166 static inline void * legacy_mca_get_drvdata ( void *hwdev ) {
00167 return mca_get_drvdata ( hwdev );
00168 }
00169
00170 #define ISA_DRIVER(_name,_probe_addrs,_probe_addr,_vendor_id,_prod_id) \
00171 static inline int \
00172 _name ## _isa_legacy_probe ( struct isa_device *isa ); \
00173 static inline int \
00174 _name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) { \
00175 if ( ! _probe_addr ( isa->ioaddr ) ) \
00176 return -ENODEV; \
00177 return _name ## _isa_legacy_probe ( isa ); \
00178 } \
00179 static inline void \
00180 _name ## _isa_legacy_remove ( struct isa_device *isa ); \
00181 static const char _name ## _text[]; \
00182 struct isa_driver _name __isa_driver = { \
00183 .name = _name ## _text, \
00184 .probe_addrs = _probe_addrs, \
00185 .addr_count = ( sizeof ( _probe_addrs ) / \
00186 sizeof ( _probe_addrs[0] ) ), \
00187 .vendor_id = _vendor_id, \
00188 .prod_id = _prod_id, \
00189 .probe = _name ## _isa_legacy_probe_at_addr, \
00190 .remove = _name ## _isa_legacy_remove, \
00191 }; \
00192 REQUIRE_OBJECT ( isa );
00193
00194 static inline void legacy_isa_set_drvdata ( void *hwdev, void *priv ) {
00195 isa_set_drvdata ( hwdev, priv );
00196 }
00197 static inline void * legacy_isa_get_drvdata ( void *hwdev ) {
00198 return isa_get_drvdata ( hwdev );
00199 }
00200
00201 #undef DRIVER
00202 #define DRIVER(_name_text,_unused2,_unused3,_name,_probe,_disable) \
00203 static const char _name ## _text[] = _name_text; \
00204 static inline int \
00205 _name ## _probe ( struct nic *nic, void *hwdev ) { \
00206 return _probe ( nic, hwdev ); \
00207 } \
00208 static inline void \
00209 _name ## _disable ( struct nic *nic, void *hwdev ) { \
00210 void ( * _unsafe_disable ) () = _disable; \
00211 _unsafe_disable ( nic, hwdev ); \
00212 } \
00213 static inline int \
00214 _name ## _pci_legacy_probe ( struct pci_device *pci, \
00215 const struct pci_device_id *id __unused ) { \
00216 return legacy_probe ( pci, legacy_pci_set_drvdata, \
00217 &pci->dev, _name ## _probe, \
00218 _name ## _disable ); \
00219 } \
00220 static inline void \
00221 _name ## _pci_legacy_remove ( struct pci_device *pci ) { \
00222 return legacy_remove ( pci, legacy_pci_get_drvdata, \
00223 _name ## _disable ); \
00224 } \
00225 static inline int \
00226 _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
00227 const struct isapnp_device_id *id __unused ) { \
00228 return legacy_probe ( isapnp, legacy_isapnp_set_drvdata, \
00229 &isapnp->dev, _name ## _probe, \
00230 _name ## _disable ); \
00231 } \
00232 static inline void \
00233 _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
00234 return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
00235 _name ## _disable ); \
00236 } \
00237 static inline int \
00238 _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
00239 const struct eisa_device_id *id __unused ) { \
00240 return legacy_probe ( eisa, legacy_eisa_set_drvdata, \
00241 &eisa->dev, _name ## _probe, \
00242 _name ## _disable ); \
00243 } \
00244 static inline void \
00245 _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) { \
00246 return legacy_remove ( eisa, legacy_eisa_get_drvdata, \
00247 _name ## _disable ); \
00248 } \
00249 static inline int \
00250 _name ## _mca_legacy_probe ( struct mca_device *mca, \
00251 const struct mca_device_id *id __unused ) { \
00252 return legacy_probe ( mca, legacy_mca_set_drvdata, \
00253 &mca->dev, _name ## _probe, \
00254 _name ## _disable ); \
00255 } \
00256 static inline void \
00257 _name ## _mca_legacy_remove ( struct mca_device *mca ) { \
00258 return legacy_remove ( mca, legacy_mca_get_drvdata, \
00259 _name ## _disable ); \
00260 } \
00261 static inline int \
00262 _name ## _isa_legacy_probe ( struct isa_device *isa ) { \
00263 return legacy_probe ( isa, legacy_isa_set_drvdata, \
00264 &isa->dev, _name ## _probe, \
00265 _name ## _disable ); \
00266 } \
00267 static inline void \
00268 _name ## _isa_legacy_remove ( struct isa_device *isa ) { \
00269 return legacy_remove ( isa, legacy_isa_get_drvdata, \
00270 _name ## _disable ); \
00271 }
00272
00273 #endif