The Pedigree Project 0.1
3Com90x.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 NIC_3C90X_H
21#define NIC_3C90X_H
22
23#include "pedigree/kernel/machine/IrqHandler.h"
24#include "pedigree/kernel/machine/Network.h"
25#include "pedigree/kernel/machine/types.h"
26#include "pedigree/kernel/process/Mutex.h"
27#include "pedigree/kernel/process/Semaphore.h"
28#include "pedigree/kernel/processor/MemoryRegion.h"
29#include "pedigree/kernel/processor/state_forward.h"
30#include "pedigree/kernel/processor/types.h"
31#include "pedigree/kernel/utilities/String.h"
32
33#include "3Com90xConstants.h"
34
35class IoBase;
36
38class Nic3C90x : public Network, public IrqHandler {
39 public:
40 Nic3C90x(Network* pDev);
41 ~Nic3C90x();
42
43 virtual void getName(String& str) {
44 str.assign("3C90x", 6);
45 }
46
47 virtual bool send(size_t nBytes, uintptr_t buffer);
48
49 virtual bool setStationInfo(const StationInfo& info);
50
51 virtual const StationInfo& getStationInfo();
52
53 bool isInitialised() const {
54 return m_Initialised;
55 }
56
57 // IRQ handler callback.
58 virtual IrqDisposition irq(irq_id_t number);
59
60 IoBase* m_pBase;
61
62 private:
63 static constexpr size_t ReceiveSlotSize = 1536;
64
65 bool issueCommand(int cmd, int param);
66
67 int setWindow(int window);
68
69 bool waitForEepromReady();
70 bool readEeprom(int address, uint16_t& value);
71
72 int writeEepromWord(int address, uint16_t value);
73 int writeEeprom(int address, uint16_t value);
74
75 bool reset();
76 bool quiesce();
77 bool stopDeviceLocked();
78
80 uint8_t m_isBrev;
81 uint8_t m_CurrentWindow;
82
83 uint8_t* m_pRxBuffVirt;
84 uint8_t* m_pTxBuffVirt;
85 uintptr_t m_pRxBuffPhys;
86 uintptr_t m_pTxBuffPhys;
87 MemoryRegion m_RxBuffMR;
88 MemoryRegion m_TxBuffMR;
89
90 uintptr_t m_pDPD;
91 MemoryRegion m_DPDMR;
92
93 uintptr_t m_pUPD;
94 MemoryRegion m_UPDMR;
95
97 struct TXD {
98 uint32_t DnNextPtr;
99 uint32_t FrameStartHeader;
100 // uint32_t HdrAddr;
101 // uint32_t HdrLength;
102 uint32_t DataAddr;
103 uint32_t DataLength;
104 } __attribute__((aligned(8)));
105
107 struct RXD {
108 uint32_t UpNextPtr;
109 volatile uint32_t UpPktStatus;
110 uint32_t DataAddr;
111 uint32_t DataLength;
112 } __attribute__((aligned(8)));
113
114 TXD* m_TransmitDPD;
115 RXD* m_ReceiveUPD;
116
117 // The threaded IRQ worker is serialized for this line, so one device-owned
118 // batch can carry packets across the device-lock boundary without invoking
119 // the allocator while that lock is held.
120 uint8_t m_ReceiveStaging[NUM_UPDS * ReceiveSlotSize];
121
122 Nic3C90x(const Nic3C90x&);
123 void operator=(const Nic3C90x&);
124
125 Semaphore m_TxMutex;
126
127 Mutex m_DeviceLock;
128 Mutex m_SendLock;
129
130 size_t m_RxConsumerIndex;
131 irq_id_t m_IrqId;
132 bool m_Active;
133 bool m_Stopping;
134 bool m_TxSuccessful;
135 bool m_Initialised;
136};
137
138#endif
Abstrace base class for hardware I/O capabilities.
Definition IoBase.h:32
Special memory entity in the kernel's virtual address space.
Definition Mutex.h:56
virtual const StationInfo & getStationInfo()
Definition 3Com90x.cc:974
int writeEepromWord(int address, uint16_t value)
Definition 3Com90x.cc:176
bool reset()
Definition 3Com90x.cc:242
int setWindow(int window)
Definition 3Com90x.cc:132
uint8_t m_isBrev
Definition 3Com90x.h:80
virtual IrqDisposition irq(irq_id_t number)
Definition 3Com90x.cc:786
virtual bool send(size_t nBytes, uintptr_t buffer)
Definition 3Com90x.cc:347
virtual void getName(String &str)
Definition 3Com90x.h:43
int writeEeprom(int address, uint16_t value)
Definition 3Com90x.cc:209
virtual bool setStationInfo(const StationInfo &info)
Definition 3Com90x.cc:947
bool readEeprom(int address, uint16_t &value)
Definition 3Com90x.cc:158
bool issueCommand(int cmd, int param)
Definition 3Com90x.cc:95
IrqDisposition
Definition IrqHandler.h:31
Definition cmd.h:30