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 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 const char _name ## _text[] = _name_text; \
  191. static inline int \
  192. _name ## _probe ( struct nic *nic, void *hwdev ) { \
  193. return _probe ( nic, hwdev ); \
  194. } \
  195. static inline void \
  196. _name ## _disable ( struct nic *nic, void *hwdev ) { \
  197. void ( * _unsafe_disable ) () = _disable; \
  198. _unsafe_disable ( nic, hwdev ); \
  199. } \
  200. static inline int \
  201. _name ## _pci_legacy_probe ( struct pci_device *pci ) { \
  202. return legacy_probe ( pci, legacy_pci_set_drvdata, \
  203. &pci->dev, _name ## _probe, \
  204. _name ## _disable ); \
  205. } \
  206. static inline void \
  207. _name ## _pci_legacy_remove ( struct pci_device *pci ) { \
  208. return legacy_remove ( pci, legacy_pci_get_drvdata, \
  209. _name ## _disable ); \
  210. } \
  211. static inline int \
  212. _name ## _isapnp_legacy_probe ( struct isapnp_device *isapnp, \
  213. const struct isapnp_device_id *id __unused ) { \
  214. return legacy_probe ( isapnp, legacy_isapnp_set_drvdata, \
  215. &isapnp->dev, _name ## _probe, \
  216. _name ## _disable ); \
  217. } \
  218. static inline void \
  219. _name ## _isapnp_legacy_remove ( struct isapnp_device *isapnp ) { \
  220. return legacy_remove ( isapnp, legacy_isapnp_get_drvdata, \
  221. _name ## _disable ); \
  222. } \
  223. static inline int \
  224. _name ## _eisa_legacy_probe ( struct eisa_device *eisa, \
  225. const struct eisa_device_id *id __unused ) { \
  226. return legacy_probe ( eisa, legacy_eisa_set_drvdata, \
  227. &eisa->dev, _name ## _probe, \
  228. _name ## _disable ); \
  229. } \
  230. static inline void \
  231. _name ## _eisa_legacy_remove ( struct eisa_device *eisa ) { \
  232. return legacy_remove ( eisa, legacy_eisa_get_drvdata, \
  233. _name ## _disable ); \
  234. } \
  235. static inline int \
  236. _name ## _mca_legacy_probe ( struct mca_device *mca, \
  237. const struct mca_device_id *id __unused ) { \
  238. return legacy_probe ( mca, legacy_mca_set_drvdata, \
  239. &mca->dev, _name ## _probe, \
  240. _name ## _disable ); \
  241. } \
  242. static inline void \
  243. _name ## _mca_legacy_remove ( struct mca_device *mca ) { \
  244. return legacy_remove ( mca, legacy_mca_get_drvdata, \
  245. _name ## _disable ); \
  246. } \
  247. static inline int \
  248. _name ## _isa_legacy_probe ( struct isa_device *isa ) { \
  249. return legacy_probe ( isa, legacy_isa_set_drvdata, \
  250. &isa->dev, _name ## _probe, \
  251. _name ## _disable ); \
  252. } \
  253. static inline void \
  254. _name ## _isa_legacy_remove ( struct isa_device *isa ) { \
  255. return legacy_remove ( isa, legacy_isa_get_drvdata, \
  256. _name ## _disable ); \
  257. } \
  258. PROVIDE_REQUIRING_SYMBOL()
  259. #endif /* NIC_H */