1: /*
2:
3: File: GTDriver.h
4: Program: GTDriver
5: Author: Michael Roßberg
6: mick@binaervarianz.de
7: Description: GTDriver is a free driver for PrismGT based cards under OS X.
8:
9: This file is part of GTDriver.
10:
11: GTDriver is free software; you can redistribute it and/or modify
12: it under the terms of the GNU General Public License as published by
13: the Free Software Foundation; either version 2 of the License, or
14: (at your option) any later version.
15:
16: GTDriver is distributed in the hope that it will be useful,
17: but WITHOUT ANY WARRANTY; without even the implied warranty of
18: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: GNU General Public License for more details.
20:
21: You should have received a copy of the GNU General Public License
22: along with GTDriver; if not, write to the Free Software
23: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: */
25: #include "WiFiControllerPCI.h"
26: #include "GTIDs.h"
27:
28: typedef struct {
29: gt_control_block *cb;
30: pageBlock_t page;
31: IOPhysicalAddress dmaAddress;
32: } controlBlock;
33:
34: typedef struct __mutex__ mutex_t;
35:
36: class GTDriver : public WiFiControllerPCI {
37: OSDeclareDefaultStructors(GTDriver)
38:
39: public:
40: virtual const OSString * newModelString() const;
41:
42: virtual bool startHardware();
43: virtual bool initHardware();
44: virtual bool freeHardware();
45: virtual bool enableHardware();
46: virtual bool disableHardware();
47: virtual bool handleEjectionHardware();
48: virtual bool getReadyForSleep();
49:
50: virtual bool handleInterrupt();
51: virtual bool handleTimer();
52:
53: virtual IOReturn outputPacketHardware(mbuf_t m);
54: virtual IOReturn setHardwareAddressHardware(UInt8 *addr);
55:
56: virtual UInt32 getLinkSpeed();
57: virtual bool setSSID(UInt32 length, UInt8* ssid);
58: virtual bool setKey(UInt32 length, UInt8* key);
59: virtual bool setMode(wirelessMode mode);
60: virtual bool setFrequency(UInt32 frequency);
61: virtual UInt32 getFrequency();
62:
63: protected:
64: bool _uploadFirmware();
65: bool _initHW();
66: bool _updateMACAddress();
67:
68: //memory managment
69: bool _allocPacketForFragment(mbuf_t *packet, volatile gt_fragment *f);
70: bool _allocQueues();
71: bool _freePacketForFragment(mbuf_t *packet, volatile gt_fragment *f);
72: bool _freeTransmitQueues();
73: bool _freeQueues();
74:
75: //frame transport
76: UInt32 _freeFragmentsInQueue(int queue);
77: bool _fillFragment(volatile gt_fragment *f, mbuf_t packet, UInt16 flags = 0);
78: IOReturn _transmitInQueue(mbuf_t m, int queue);
79: int _inQueue(int queue);
80:
81: //PIMFOR handling
82: bool _setStruc(UInt32 oid, void* data, UInt32 len, bool waitForResponse = false);
83: bool _setValue(UInt32 oid, UInt32 value, bool waitForResponse = false);
84: bool _getValue(UInt32 oid, UInt32 len = 4, bool waitForResponse = false);
85: void _fillPIMFOR(UInt32 operation, UInt32 oid, UInt32 length, pimforHeader *h);
86: bool _transmitPIM(UInt32 operation, UInt32 oid, UInt32 length, void* data, bool waitForResponse = false);
87: bool _parsePIMFOR(mbuf_t m);
88:
89:
90: inline UInt32 getRegister(int r, bool littleEndian = true) {
91: if (_cardGone) return 0xFFFFFFFF;
92: if (littleEndian)
93: return OSReadLittleInt32((void*)_ioBase, r);
94: else
95: return OSReadBigInt32((void*)_ioBase, r);
96: }
97:
98: inline void setRegister(int r, UInt32 v,
99: bool littleEndian = true, bool flush = true) {
100: if (_cardGone) return;
101: if (littleEndian)
102: OSWriteLittleInt32((void*)_ioBase, r, v);
103: else
104: OSWriteBigInt32((void*)_ioBase, r, v);
105:
106: //for flushing?!
107: if (flush) getRegister(GT_INT_EN_REG);
108: OSSynchronizeIO();
109: }
110:
111: mutex_t *_mgmtMutex, *_dataMutex;
112: controlBlock _controlBlock;
113: bool _initialized;
114: bool _dozing;
115: bool _doAsyncIO;
116: bool _interruptBusy;
117: bool _stalled;
118: wirelessMode _mode;
119:
120: UInt32 _txDataLowPos, _txDataHighPos, _txDataMgmtPos;
121:
122: mbuf_t _rxDataLow[CB_RX_QSIZE], _txDataLow[CB_TX_QSIZE],
123: _rxDataHigh[CB_RX_QSIZE], _txDataHigh[CB_TX_QSIZE],
124: _rxDataMgmt[CB_MGMT_QSIZE],_txDataMgmt[CB_MGMT_QSIZE];
125:
126: UInt32 _allocated, _freed, _rxAllocated, _rxFreed;
127: volatile int _interruptPoint, _lastIndex;
128: };
129: