You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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