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/Mutex.h"
29#include "pedigree/kernel/process/OwnedThread.h"
30#include "pedigree/kernel/process/Semaphore.h"
31#include "pedigree/kernel/processor/types.h"
32#include "pedigree/kernel/utilities/List.h"
33#include "pedigree/kernel/utilities/String.h"
34#include "pedigree/kernel/utilities/new"
35
36class IoBase;
37
38#define NE2K_VENDOR_ID 0x10ec
39#define NE2K_DEVICE_ID 0x8029
40
42class Ne2k : public Network, public IrqHandler {
43 public:
44 Ne2k(Network* pDev);
45 virtual ~Ne2k();
46
47 virtual void getName(String& str) {
48 str.assign("ne2k", 5);
49 }
50
51 virtual bool send(size_t nBytes, uintptr_t buffer);
52
53 virtual bool setStationInfo(const StationInfo& info);
54
55 virtual const StationInfo& getStationInfo();
56
57 // IRQ handler callback.
58 virtual IrqDisposition irq(irq_id_t number);
59
60 IoBase* m_pBase;
61
62 bool isConnected();
63 bool isValid() const {
64 return m_IrqId != 0 && m_NetworkRegistered;
65 }
66
67 private:
68 bool recv();
69 bool waitForRemoteDma();
70 bool resetController();
71 bool recoverReceiveOverflow(uint8_t irqStatus);
72 void advanceReceiveBoundary(uint8_t nextPacket);
73
74 static int trampoline(void* p);
75
76 void receiveThread();
77
78 struct packet {
79 uintptr_t ptr;
80 size_t len;
81 };
82 uint8_t m_NextPacket;
83
84 Semaphore m_PacketQueueSize;
85 List<packet*> m_PacketQueue;
86
87 Spinlock m_PacketQueueLock;
88 Mutex m_DmaLock;
89
90 irq_id_t m_IrqId;
91 bool m_Stopping;
92 bool m_NetworkRegistered;
93 OwnedThread m_ReceiveThread;
94
95 Ne2k(const Ne2k&);
96 void operator=(const Ne2k&);
97};
98
99#endif
Abstrace base class for hardware I/O capabilities.
Definition IoBase.h:32
Definition List.h:61
Definition Mutex.h:56
Definition Ne2k.h:42
virtual const StationInfo & getStationInfo()
Definition Ne2k.cc:615
virtual bool send(size_t nBytes, uintptr_t buffer)
Definition Ne2k.cc:223
virtual IrqDisposition irq(irq_id_t number)
Definition Ne2k.cc:619
virtual bool setStationInfo(const StationInfo &info)
Definition Ne2k.cc:585
bool isConnected()
Definition Ne2k.cc:663
virtual void getName(String &str)
Definition Ne2k.h:47
IrqDisposition
Definition IrqHandler.h:31