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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <byteswap.h>
  10. #include <gpxe/pci.h>
  11. #include "dhcp.h"
  12. typedef enum {
  13. DISABLE = 0,
  14. ENABLE,
  15. FORCE
  16. } irq_action_t;
  17. typedef enum duplex {
  18. HALF_DUPLEX = 1,
  19. FULL_DUPLEX
  20. } duplex_t;
  21. /*
  22. * Structure returned from eth_probe and passed to other driver
  23. * functions.
  24. */
  25. struct nic {
  26. struct nic_operations *nic_op;
  27. int flags; /* driver specific flags */
  28. unsigned char *node_addr;
  29. unsigned char *packet;
  30. unsigned int packetlen;
  31. unsigned int ioaddr;
  32. unsigned char irqno;
  33. unsigned int mbps;
  34. duplex_t duplex;
  35. struct dhcp_dev_id dhcp_dev_id;
  36. void *priv_data; /* driver private data */
  37. };
  38. struct nic_operations {
  39. int ( *connect ) ( struct nic * );
  40. int ( *poll ) ( struct nic *, int retrieve );
  41. void ( *transmit ) ( struct nic *, const char *,
  42. unsigned int, unsigned int, const char * );
  43. void ( *irq ) ( struct nic *, irq_action_t );
  44. };
  45. extern struct nic nic;
  46. static inline int eth_poll ( int retrieve ) {
  47. return nic.nic_op->poll ( &nic, retrieve );
  48. }
  49. static inline void eth_transmit ( const char *dest, unsigned int type,
  50. unsigned int size, const void *packet ) {
  51. nic.nic_op->transmit ( &nic, dest, type, size, packet );
  52. }
  53. /*
  54. * Function prototypes
  55. *
  56. */
  57. extern int dummy_connect ( struct nic *nic );
  58. extern void dummy_irq ( struct nic *nic, irq_action_t irq_action );
  59. extern int legacy_probe ( struct pci_device *pci,
  60. const struct pci_device_id *id,
  61. int ( * probe ) ( struct nic *nic,
  62. struct pci_device *pci ),
  63. void ( * disable ) ( struct nic *nic ) );
  64. extern void legacy_remove ( struct pci_device *pci,
  65. void ( * disable ) ( struct nic *nic ) );
  66. extern void pci_fill_nic ( struct nic *nic, struct pci_device *pci );
  67. #define PCI_DRIVER(_name,_ids,_class) \
  68. static int _name ## _legacy_probe ( struct pci_device *pci, \
  69. const struct pci_device_id *id ); \
  70. static void _name ## _legacy_remove ( struct pci_device *pci ); \
  71. struct pci_driver _name __pci_driver = { \
  72. .ids = _ids, \
  73. .id_count = sizeof ( _ids ) / sizeof ( _ids[0] ), \
  74. .probe = _name ## _legacy_probe, \
  75. .remove = _name ## _legacy_remove, \
  76. };
  77. #undef DRIVER
  78. #define DRIVER(_unused1,_unused2,_unused3,_name,_probe,_disable) \
  79. static int _name ## _legacy_probe ( struct pci_device *pci, \
  80. const struct pci_device_id *id ) {\
  81. return legacy_probe ( pci, id, _probe, _disable ); \
  82. } \
  83. static void _name ## _legacy_remove ( struct pci_device *pci ) {\
  84. return legacy_remove ( pci, _disable ); \
  85. }
  86. #endif /* NIC_H */