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 "modules/system/usb/UsbDevice.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/Semaphore.h"
29 #include "pedigree/kernel/processor/types.h"
30 #include "pedigree/kernel/utilities/List.h"
31 #include "pedigree/kernel/utilities/String.h"
32 #include "pedigree/kernel/utilities/new"
33 
34 class Dm9601 : public UsbDevice, public Network
35 {
36  public:
37  Dm9601(UsbDevice *pDev);
38 
39  virtual ~Dm9601();
40 
41  virtual void initialiseDriver();
42 
43  virtual void getName(String &str)
44  {
45  str = "DM9601";
46  }
47 
48  virtual bool send(size_t nBytes, uintptr_t buffer);
49 
50  virtual bool setStationInfo(const StationInfo &info);
51 
52  virtual const StationInfo &getStationInfo();
53 
54  private:
55  static int recvTrampoline(void *p) NORETURN;
56 
57  static int trampoline(void *p) NORETURN;
58 
59  void receiveThread() NORETURN;
60 
61  void receiveLoop() NORETURN;
62 
63  void doReceive();
64 
65  enum VendorRequests
66  {
67  ReadRegister = 0,
68  WriteRegister = 1,
69  ReadMemory = 2,
70  WriteRegister1 = 3,
71  WriteMemory = 5,
72  WriteMemory1 = 7,
73  };
74 
75  enum Registers
76  {
77  NetworkControl = 0,
78  NetworkStatus = 1,
79  TxControl = 2,
80  TxStatus1 = 3,
81  TxStatus2 = 4,
82  RxControl = 5,
83  RxStatus = 6,
84  RxOverflowCount = 7,
85  BackPressThreshold = 8,
86  FlowControl = 9,
87  RxFlowControl = 10,
88  PhyControl = 11,
89  PhyAddress = 12,
90  PhyLowByte = 13,
91  PhyHighByte = 14,
92  WakeUpControl = 15,
93  PhysicalAddress = 16,
94  MulticastAddress = 22,
95  GeneralPurposeCtl = 30,
96  GeneralPurpose = 31,
97  TxWriteAddressLo = 32,
98  TxWriteAddressHi = 33,
99  TxReadAddressLo = 34,
100  TxReadAddressHi = 35,
101  RxWriteAddressLo = 36,
102  RxWriteAddressHi = 37,
103  RxReadAddressLo = 38,
104  RxReadAddressHi = 39,
105  Vendor = 40,
106  Product = 42,
107  Chip = 44,
108 
109  UsbAddress = 0xF0,
110  RxCounter = 0xF1,
111  TxCount = 0xF2,
112  UsbStatus = 0xF2,
113  UsbControl = 0xF4
114  };
115 
117  {
118  uint8_t networkStatus;
119  uint8_t txStatus1;
120  uint8_t txStatus2;
121  uint8_t rxStatus;
122  uint8_t rxOverflowCounter;
123  uint8_t rxCounter;
124  uint8_t txCounter;
125  uint8_t gpRegister;
126  } PACKED;
127 
129  ssize_t readRegister(uint8_t reg, uintptr_t buffer, size_t nBytes);
130 
132  ssize_t writeRegister(uint8_t reg, uintptr_t buffer, size_t nBytes);
133 
135  ssize_t writeRegister(uint8_t reg, uint8_t data);
136 
138  ssize_t readMemory(uint16_t offset, uintptr_t buffer, size_t nBytes);
139 
141  ssize_t writeMemory(uint16_t offset, uintptr_t buffer, size_t nBytes);
142 
144  ssize_t writeMemory(uint16_t offset, uint8_t data);
145 
147  uint16_t readEeprom(uint8_t offset);
148 
150  void writeEeprom(uint8_t offset, uint16_t data);
151 
153  uint16_t readMii(uint8_t offset);
154 
156  void writeMii(uint8_t offset, uint16_t data);
157 
160 
163 
166 
169 
171  struct Packet
172  {
173  uintptr_t buffer;
174  size_t len;
175  uint32_t offset;
176  };
177  List<Packet *> m_RxPacketQueue;
178  Spinlock m_RxPacketQueueLock;
179 
181  size_t m_TxPacket;
182 
183  Dm9601(const Dm9601 &);
184  void operator=(const Dm9601 &);
185 };
186 
187 #endif
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.
Definition: Dm9601.cc:47
virtual void getName(String &str)
Definition: Dm9601.h:43
Definition: Dm9601.h:34
Semaphore m_IncomingPackets
Definition: Dm9601.h:168
Endpoint * m_pInEndpoint
Definition: Dm9601.h:159
ssize_t readMemory(uint16_t offset, uintptr_t buffer, size_t nBytes)
Reads data from device memory into a buffer.
Definition: Dm9601.cc:334
Mutex m_TxLock
Definition: Dm9601.h:165
Definition: Mutex.h:58
Definition: String.h:49
ssize_t writeRegister(uint8_t reg, uintptr_t buffer, size_t nBytes)
Writes data from a buffer to a register.
Definition: Dm9601.cc:318
void writeMii(uint8_t offset, uint16_t data)
Writes a 16-bit value to the external MII.
Definition: Dm9601.cc:405
uint16_t readMii(uint8_t offset)
Reads a 16-bit value from the external MII.
Definition: Dm9601.cc:389
Definition: List.h:64
ssize_t writeMemory(uint16_t offset, uintptr_t buffer, size_t nBytes)
Writes data from a buffer into device memory.
Definition: Dm9601.cc:343
virtual bool setStationInfo(const StationInfo &info)
Definition: Dm9601.cc:270
virtual const StationInfo & getStationInfo()
Definition: Dm9601.cc:304
void writeEeprom(uint8_t offset, uint16_t data)
Writes a 16-bit value to the device EEPROM.
Definition: Dm9601.cc:375
uint16_t readEeprom(uint8_t offset)
Reads a 16-bit value from the device EEPROM.
Definition: Dm9601.cc:359
ssize_t readRegister(uint8_t reg, uintptr_t buffer, size_t nBytes)
Reads data from a register into a buffer.
Definition: Dm9601.cc:309
size_t m_TxPacket
Definition: Dm9601.h:181
virtual bool send(size_t nBytes, uintptr_t buffer)
Definition: Dm9601.cc:182
Endpoint * m_pOutEndpoint
Definition: Dm9601.h:162