Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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