netdev.hpp 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <defs.hpp>
  3. #include <functional>
  4. #include <stdint.h>
  5. #include <kernel/hw/pci.hpp>
  6. #include <net/ethernet.hpp>
  7. namespace net {
  8. constexpr unsigned long NETDEV_UP = 0x001;
  9. constexpr unsigned long NETDEV_DOWN = 0x002;
  10. constexpr unsigned long NETDEV_SPEED_MASK = 0x03c;
  11. constexpr unsigned long NETDEV_SPEED_UNKNOWN = 0x004;
  12. constexpr unsigned long NETDEV_SPEED_10M = 0x008;
  13. constexpr unsigned long NETDEV_SPEED_100M = 0x010;
  14. constexpr unsigned long NETDEV_SPEED_1000M = 0x020;
  15. class Netdev {
  16. protected:
  17. unsigned long status;
  18. MACAddress mac;
  19. Netdev(kernel::hw::pci::pci_device& device);
  20. public:
  21. kernel::hw::pci::pci_device& device;
  22. virtual ~Netdev() = default;
  23. int setLinkSpeed(unsigned long speedFlag);
  24. virtual int up() = 0;
  25. virtual isize send(const u8* data, usize len) = 0;
  26. };
  27. int registerNetdev(std::unique_ptr<Netdev> dev);
  28. } // namespace net