The Pedigree Project 0.1
Dm9601.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 DM9601_H
21#define DM9601_H
22
23#include "pedigree/kernel/Atomic.h"
24#include "pedigree/kernel/Spinlock.h"
25#include "pedigree/kernel/compiler.h"
26#include "pedigree/kernel/machine/Network.h"
27#include "pedigree/kernel/process/Mutex.h"
28#include "pedigree/kernel/process/OperationBarrier.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/String.h"
33#include "pedigree/kernel/utilities/new"
34
35#include "modules/system/usb/UsbDevice.h"
36
37class Dm9601 : public UsbDevice, public Network {
38 public:
39 Dm9601(UsbDevice* pDev);
40
41 virtual ~Dm9601();
42
43 virtual void initialiseDriver();
44
45 virtual void getName(String& str) {
46 str.assign("DM9601", 7);
47 }
48
49 virtual bool send(size_t nBytes, uintptr_t buffer);
50
51 virtual bool setStationInfo(const StationInfo& info);
52
53 virtual const StationInfo& getStationInfo();
54
55 private:
56 static int recvTrampoline(void* p);
57
58 static int trampoline(void* p);
59
60 void receiveThread();
61
62 void receiveLoop();
63
64 void doReceive();
65
66 enum VendorRequests {
67 ReadRegister = 0,
68 WriteRegister = 1,
69 ReadMemory = 2,
70 WriteRegister1 = 3,
71 WriteMemory = 5,
72 WriteMemory1 = 7,
73 };
74
75 enum Registers {
76 NetworkControl = 0,
77 NetworkStatus = 1,
78 TxControl = 2,
79 TxStatus1 = 3,
80 TxStatus2 = 4,
81 RxControl = 5,
82 RxStatus = 6,
83 RxOverflowCount = 7,
84 BackPressThreshold = 8,
85 FlowControl = 9,
86 RxFlowControl = 10,
87 PhyControl = 11,
88 PhyAddress = 12,
89 PhyLowByte = 13,
90 PhyHighByte = 14,
91 WakeUpControl = 15,
92 PhysicalAddress = 16,
93 MulticastAddress = 22,
94 GeneralPurposeCtl = 30,
95 GeneralPurpose = 31,
96 TxWriteAddressLo = 32,
97 TxWriteAddressHi = 33,
98 TxReadAddressLo = 34,
99 TxReadAddressHi = 35,
100 RxWriteAddressLo = 36,
101 RxWriteAddressHi = 37,
102 RxReadAddressLo = 38,
103 RxReadAddressHi = 39,
104 Vendor = 40,
105 Product = 42,
106 Chip = 44,
107
108 UsbAddress = 0xF0,
109 RxCounter = 0xF1,
110 TxCount = 0xF2,
111 UsbStatus = 0xF2,
112 UsbControl = 0xF4
113 };
114
116 uint8_t networkStatus;
117 uint8_t txStatus1;
118 uint8_t txStatus2;
119 uint8_t rxStatus;
120 uint8_t rxOverflowCounter;
121 uint8_t rxCounter;
122 uint8_t txCounter;
123 uint8_t gpRegister;
124 } PACKED;
125
127 bool readRegister(uint8_t reg, uintptr_t buffer, size_t nBytes);
128
130 bool writeRegister(uint8_t reg, uintptr_t buffer, size_t nBytes);
131
133 bool writeRegister(uint8_t reg, uint8_t data);
134
136 bool readMemory(uint16_t offset, uintptr_t buffer, size_t nBytes);
137
139 bool writeMemory(uint16_t offset, uintptr_t buffer, size_t nBytes);
140
142 bool writeMemory(uint16_t offset, uint8_t data);
143
145 bool readEeprom(uint8_t offset, uint16_t& value);
146
148 bool writeEeprom(uint8_t offset, uint16_t data);
149
151 bool readMii(uint8_t offset, uint16_t& value);
152
154 bool writeMii(uint8_t offset, uint16_t data);
155
156 bool readSharedWord(bool phy, uint8_t offset, uint16_t& value);
157 bool writeSharedWord(bool phy, uint8_t offset, uint16_t value);
158 bool waitForSharedOperation();
159 bool resetDevice();
160 bool waitForLink();
161 bool waitForTxReady();
162
165
168
171
174
177
179 struct Packet {
180 uintptr_t buffer;
181 size_t len;
182 uint32_t offset;
183 Packet* next;
184 };
185 Packet* m_RxQueueHead;
186 Packet* m_RxQueueTail;
187 Spinlock m_RxPacketQueueLock;
188
191
192 Atomic<bool> m_Running;
193 bool m_Registered;
194 OperationBarrier m_Operations;
195 OwnedThread m_PacketWorker;
196 OwnedThread m_ReceiveWorker;
197
198 Dm9601(const Dm9601&);
199 void operator=(const Dm9601&);
200};
201
202#endif
bool writeMemory(uint16_t offset, uintptr_t buffer, size_t nBytes)
Writes data from a buffer into device memory.
Definition Dm9601.cc:443
bool writeRegister(uint8_t reg, uintptr_t buffer, size_t nBytes)
Writes data from a buffer to a register.
Definition Dm9601.cc:421
bool writeMii(uint8_t offset, uint16_t data)
Writes a 16-bit value to the external MII.
Definition Dm9601.cc:469
Mutex m_SharedRegisterLock
Definition Dm9601.h:173
size_t m_TxPacket
Definition Dm9601.h:190
Endpoint * m_pOutEndpoint
Definition Dm9601.h:167
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.
Definition Dm9601.cc:116
virtual bool send(size_t nBytes, uintptr_t buffer)
Definition Dm9601.cc:249
bool writeEeprom(uint8_t offset, uint16_t data)
Writes a 16-bit value to the device EEPROM.
Definition Dm9601.cc:461
bool readRegister(uint8_t reg, uintptr_t buffer, size_t nBytes)
Reads data from a register into a buffer.
Definition Dm9601.cc:413
bool readMemory(uint16_t offset, uintptr_t buffer, size_t nBytes)
Reads data from device memory into a buffer.
Definition Dm9601.cc:435
bool readMii(uint8_t offset, uint16_t &value)
Reads a 16-bit value from the external MII.
Definition Dm9601.cc:465
Mutex m_TxLock
Definition Dm9601.h:170
Semaphore m_IncomingPackets
Definition Dm9601.h:176
virtual bool setStationInfo(const StationInfo &info)
Definition Dm9601.cc:382
virtual const StationInfo & getStationInfo()
Definition Dm9601.cc:409
virtual void getName(String &str)
Definition Dm9601.h:45
Endpoint * m_pInEndpoint
Definition Dm9601.h:164
bool readEeprom(uint8_t offset, uint16_t &value)
Reads a 16-bit value from the device EEPROM.
Definition Dm9601.cc:457
Definition Mutex.h:56