The Pedigree Project  0.1
Ne2k.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef NE2K_H
21 #define NE2K_H
22 
23 #include "pedigree/kernel/Spinlock.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/machine/IrqHandler.h"
26 #include "pedigree/kernel/machine/Network.h"
27 #include "pedigree/kernel/machine/types.h"
28 #include "pedigree/kernel/process/Semaphore.h"
29 #include "pedigree/kernel/processor/state_forward.h"
30 #include "pedigree/kernel/processor/types.h"
31 #include "pedigree/kernel/utilities/List.h"
32 #include "pedigree/kernel/utilities/String.h"
33 #include "pedigree/kernel/utilities/new"
34 
35 class IoBase;
36 
37 #define NE2K_VENDOR_ID 0x10ec
38 #define NE2K_DEVICE_ID 0x8029
39 
41 class Ne2k : public Network, public IrqHandler
42 {
43  public:
44  Ne2k(Network *pDev);
45  virtual ~Ne2k();
46 
47  virtual void getName(String &str)
48  {
49  str = "ne2k";
50  }
51 
52  virtual bool send(size_t nBytes, uintptr_t buffer);
53 
54  virtual bool setStationInfo(const StationInfo &info);
55 
56  virtual const StationInfo &getStationInfo();
57 
58  // IRQ handler callback.
59  virtual bool irq(irq_id_t number, InterruptState &state);
60 
61  IoBase *m_pBase;
62 
63  bool isConnected();
64 
65  private:
66  void recv();
67 
68  static int trampoline(void *p) NORETURN;
69 
70  void receiveThread() NORETURN;
71 
72  struct packet
73  {
74  uintptr_t ptr;
75  size_t len;
76  };
77  uint8_t m_NextPacket;
78 
79  Semaphore m_PacketQueueSize;
80  List<packet *> m_PacketQueue;
81 
82  Spinlock m_PacketQueueLock;
83 
84  Ne2k(const Ne2k &);
85  void operator=(const Ne2k &);
86 };
87 
88 #endif
Ne2k(Network *pDev)
Definition: Ne2k.cc:41
Definition: String.h:49
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
Definition: Ne2k.h:41
virtual const StationInfo & getStationInfo()
Definition: Ne2k.cc:374
Definition: List.h:64
virtual bool setStationInfo(const StationInfo &info)
Definition: Ne2k.cc:338
virtual void getName(String &str)
Definition: Ne2k.h:47
virtual bool irq(irq_id_t number, InterruptState &state)
Definition: Ne2k.cc:379
bool isConnected()
Definition: Ne2k.cc:418
virtual bool send(size_t nBytes, uintptr_t buffer)
Definition: Ne2k.cc:150