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.

nic.h 9.0KB

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