netdev.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Network device interface: one struct per NIC driver, shared by the network
  2. * stack (net.c) and the net* shell commands (netcmd.c).
  3. *
  4. * Drivers are registered in the table in netdev.c (first match wins); add new
  5. * ones there. Everything here is polled, matching the rest of the kernel. */
  6. #ifndef NETDEV_H
  7. #define NETDEV_H
  8. struct netdev {
  9. const char *name; /* short driver name, e.g. "ne2000" */
  10. const char *chip; /* detected chip, e.g. "RTL8029AS" */
  11. int (*init)(void); /* probe + bring up: 0 = ready, -1 = not present */
  12. void (*get_mac)(unsigned char mac[6]);
  13. int (*rx)(unsigned char *buf, unsigned int maxlen); /* len, or -1 */
  14. int (*tx)(const unsigned char *buf, unsigned int len); /* 0, or -1 */
  15. void (*print_info)(void); /* status lines (MAC, link, ...) */
  16. void (*dump_regs)(void); /* register dump; may be NULL */
  17. int (*set_loopback)(int on); /* PHY loopback for self-test; may be NULL */
  18. void (*reset)(void); /* full NIC re-init (recover from a stall); may be NULL */
  19. int (*set_speed)(unsigned int mbps); /* 0 = auto, 100 = force 100M; may be NULL */
  20. void (*set_mac)(const unsigned char mac[6]); /* runtime MAC override; may be NULL */
  21. /* Address applied when this driver becomes active. The direct ASIX
  22. * link uses its own subnet so it can coexist with the e1000e link to
  23. * the router. NULL leaves the current address alone. */
  24. const unsigned char *default_ip;
  25. const unsigned char *default_mask;
  26. /* Short RX summary for the boot log (a full register dump can
  27. * overflow the netlog ring before the WM starts); may be NULL. */
  28. void (*dump_brief)(void);
  29. /* Stop DMA before a kexec jump; may be NULL. */
  30. void (*stop)(void);
  31. /* Link state for drivers whose link can be down for long (WiFi before
  32. * association): 0 = no link, so the boot DHCP is skipped. NULL means
  33. * "always up" (the wired drivers). */
  34. int (*link_up)(void);
  35. };
  36. /* First registered driver that probes successfully (probe result is cached);
  37. * NULL when no NIC is present. */
  38. const struct netdev *netdev_active(void);
  39. /* Driver table access for the ring-3 network menu: count and indexed entry.
  40. * The menu probes each driver's init() to build its "available" list. */
  41. unsigned int netdev_count(void);
  42. const struct netdev *netdev_at(unsigned int index);
  43. /* Whether the boot-time probe has run (netdev_active() is then a cached
  44. * lookup and can be called without releasing the BKL). */
  45. int netdev_probed(void);
  46. /* Effective link state of a driver (drivers without a link_up hook are
  47. * treated as always up). */
  48. int netdev_link(const struct netdev *nd);
  49. /* A USB network device appeared after boot (hotplug probe succeeded). Makes
  50. * it the active NIC when the boot probe found none; never overrides an
  51. * already-selected driver. */
  52. void netdev_hotplug(void);
  53. /* Management NIC for netlog/netkexec. Prefers the ASIX dongle so the
  54. * direct debug link survives `netdev e1000e`; falls back to the active
  55. * driver. */
  56. const struct netdev *netdev_mgmt(void);
  57. /* Quiesce the active and management NIC DMA before a kexec jump. */
  58. void netdev_shutdown(void);
  59. /* Select a NIC by short driver name ("e1000e", "r8168", "ne2000", "asix").
  60. * Returns 0 on success; leaves the current driver active on failure. */
  61. int netdev_select(const char *name);
  62. void program_netdev_main(const char *arg);
  63. /* Busy gate for commands that poll the NIC for a while (netrecv, ping,
  64. * netloop, netkexec): the background kexec watcher must not steal
  65. * frames while one of them owns the receiver. */
  66. void netdev_acquire(void);
  67. void netdev_release(void);
  68. int netdev_in_use(void);
  69. /* Process that currently owns the NIC (0 = free), and a hard reset used by
  70. * the reaper so a killed process cannot leave the receiver owned. */
  71. unsigned int netdev_owner(void);
  72. void netdev_release_all(void);
  73. /* Fill the active NIC's MAC; -1 (and a zero MAC) when there is no NIC. */
  74. int netdev_get_mac(unsigned char mac[6]);
  75. /* One shared frame-receive scratch buffer (1518 bytes) for protocol code that
  76. * just needs somewhere for nd->rx() to land. Only valid while the caller
  77. * owns the NIC, and only until the next rx(). Shared so the DNS/TCP/ARP
  78. * paths don't each carry their own frame buffer in the kernel's BSS. */
  79. unsigned char *netdev_rx_scratch(void);
  80. #define NETDEV_FRAME_MAX 1518
  81. #endif