Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

nic.h 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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 <ipxe/pci.h>
  15. #include <ipxe/isapnp.h>
  16. #include <ipxe/isa.h>
  17. #include <ipxe/eisa.h>
  18. #include <ipxe/mca.h>
  19. #include <ipxe/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. static inline void \
  78. _name ## _pci_legacy_remove ( struct pci_device *pci ); \
  79. struct pci_driver _name __pci_driver = { \
  80. .ids = _ids, \
  81. .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
  82. .probe = _name ## _pci_legacy_probe, \
  83. .remove = _name ## _pci_legacy_remove, \
  84. }; \
  85. REQUIRE_OBJECT ( pci );
  86. static inline void legacy_pci_set_drvdata ( void *hwdev, void *priv ) {
  87. pci_set_drvdata ( hwdev, priv );
  88. }
  89. static inline void * legacy_pci_get_drvdata ( void *hwdev ) {
  90. return pci_get_drvdata ( hwdev );
  91. }
  92. #define ISAPNP_DRIVER(_name,_ids) \
  93. static inline int \
  94. _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
  95. const struct isapnp_device_id *id ); \
  96. static inline void \
  97. _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ); \
  98. struct isapnp_driver _name __isapnp_driver = { \
  99. .ids = _ids, \
  100. .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
  101. .probe = _name ## _isapnp_legacy_probe, \
  102. .remove = _name ## _isapnp_legacy_remove, \
  103. }; \
  104. REQUIRE_OBJECT ( isapnp );
  105. static inline void legacy_isapnp_set_drvdata ( void *hwdev, void *priv ) {
  106. isapnp_set_drvdata ( hwdev, priv );
  107. }
  108. static inline void * legacy_isapnp_get_drvdata ( void *hwdev ) {
  109. return isapnp_get_drvdata ( hwdev );
  110. }
  111. #define EISA_DRIVER(_name,_ids) \
  112. static inline int \
  113. _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
  114. const struct eisa_device_id *id ); \
  115. static inline void \
  116. _name ## _eisa_legacy_remove ( struct eisa_device *eisa ); \
  117. struct eisa_driver _name __eisa_driver = { \
  118. .ids = _ids, \
  119. .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
  120. .probe = _name ## _eisa_legacy_probe, \
  121. .remove = _name ## _eisa_legacy_remove, \
  122. }; \
  123. REQUIRE_OBJECT ( eisa );
  124. static inline void legacy_eisa_set_drvdata ( void *hwdev, void *priv ) {
  125. eisa_set_drvdata ( hwdev, priv );
  126. }
  127. static inline void * legacy_eisa_get_drvdata ( void *hwdev ) {
  128. return eisa_get_drvdata ( hwdev );
  129. }
  130. #define MCA_DRIVER(_name,_ids) \
  131. static inline int \
  132. _name ## _mca_legacy_probe ( struct mca_device *mca, \
  133. const struct mca_device_id *id ); \
  134. static inline void \
  135. _name ## _mca_legacy_remove ( struct mca_device *mca ); \
  136. struct mca_driver _name __mca_driver = { \
  137. .ids = _ids, \
  138. .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
  139. .probe = _name ## _mca_legacy_probe, \
  140. .remove = _name ## _mca_legacy_remove, \
  141. }; \
  142. REQUIRE_OBJECT ( mca );
  143. static inline void legacy_mca_set_drvdata ( void *hwdev, void *priv ) {
  144. mca_set_drvdata ( hwdev, priv );
  145. }
  146. static inline void * legacy_mca_get_drvdata ( void *hwdev ) {
  147. return mca_get_drvdata ( hwdev );
  148. }
  149. #define ISA_DRIVER(_name,_probe_addrs,_probe_addr,_vendor_id,_prod_id) \
  150. static inline int \
  151. _name ## _isa_legacy_probe ( struct isa_device *isa ); \
  152. static inline int \
  153. _name ## _isa_legacy_probe_at_addr ( struct isa_device *isa ) { \
  154. if ( ! _probe_addr ( isa->ioaddr ) ) \
  155. return -ENODEV; \
  156. return _name ## _isa_legacy_probe ( isa ); \
  157. } \
  158. static inline void \
  159. _name ## _isa_legacy_remove ( struct isa_device *isa ); \
  160. static const char _name ## _text[]; \
  161. struct isa_driver _name __isa_driver = { \
  162. .name = _name ## _text, \
  163. .probe_addrs = _probe_addrs, \
  164. .addr_count = ( sizeof ( _probe_addrs ) / \
  165. sizeof ( _probe_addrs[0] ) ), \
  166. .vendor_id = _vendor_id, \
  167. .prod_id = _prod_id, \
  168. .probe = _name ## _isa_legacy_probe_at_addr, \
  169. .remove = _name ## _isa_legacy_remove, \
  170. }; \
  171. REQUIRE_OBJECT ( isa );
  172. static inline void legacy_isa_set_drvdata ( void *hwdev, void *priv ) {
  173. isa_set_drvdata ( hwdev, priv );
  174. }
  175. static inline void * legacy_isa_get_drvdata ( void *hwdev ) {
  176. return isa_get_drvdata ( hwdev );
  177. }
  178. #undef DRIVER
  179. #define DRIVER(_name_text,_unused2,_unused3,_name,_probe,_disable) \
  180. static const char _name ## _text[] = _name_text; \
  181. static inline int \
  182. _name ## _probe ( struct nic *nic, void *hwdev ) { \
  183. return _probe ( nic, hwdev ); \
  184. } \
  185. static inline void \
  186. _name ## _disable ( struct nic *nic, void *hwdev ) { \
  187. void ( * _unsafe_disable ) () = _disable; \
  188. _unsafe_disable ( nic, hwdev ); \
  189. } \
  190. static inline int \
  191. _name ## _pci_legacy_probe ( struct pci_device *pci ) { \
  192. return legacy_probe ( pci, legacy_pci_set_drvdata, \
  193. &pci->dev, _name ## _probe, \
  194. _name ## _disable ); \
  195. } \
  196. static inline void \
  197. _name ## _pci_legacy_remove ( struct pci_device *pci ) { \
  198. return legacy_remove ( pci, legacy_pci_get_drvdata, \
  199. _name ## _disable ); \
  200. } \
  201. static inline int \
  202. _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
  203. const struct isapnp_device_id *id __unused ) { \
  204. return legacy_probe ( isapnp, legacy_isapnp_set_drvdata, \
  205. &isapnp->dev, _name ## _probe, \
  206. _name ## _disable ); \
  207. } \
  208. static inline void \
  209. _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
  210. return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
  211. _name ## _disable ); \
  212. } \
  213. static inline int \
  214. _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
  215. const struct eisa_device_id *id __unused ) { \
  216. return legacy_probe ( eisa, legacy_eisa_set_drvdata, \
  217. &eisa->dev, _name ## _probe, \
  218. _name ## _disable ); \
  219. } \
  220. static inline void \
  221. _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) { \
  222. return legacy_remove ( eisa, legacy_eisa_get_drvdata, \
  223. _name ## _disable ); \
  224. } \
  225. static inline int \
  226. _name ## _mca_legacy_probe ( struct mca_device *mca, \
  227. const struct mca_device_id *id __unused ) { \
  228. return legacy_probe ( mca, legacy_mca_set_drvdata, \
  229. &mca->dev, _name ## _probe, \
  230. _name ## _disable ); \
  231. } \
  232. static inline void \
  233. _name ## _mca_legacy_remove ( struct mca_device *mca ) { \
  234. return legacy_remove ( mca, legacy_mca_get_drvdata, \
  235. _name ## _disable ); \
  236. } \
  237. static inline int \
  238. _name ## _isa_legacy_probe ( struct isa_device *isa ) { \
  239. return legacy_probe ( isa, legacy_isa_set_drvdata, \
  240. &isa->dev, _name ## _probe, \
  241. _name ## _disable ); \
  242. } \
  243. static inline void \
  244. _name ## _isa_legacy_remove ( struct isa_device *isa ) { \
  245. return legacy_remove ( isa, legacy_isa_get_drvdata, \
  246. _name ## _disable ); \
  247. }
  248. #endif /* NIC_H */