-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathb44lmqnx.c
287 lines (241 loc) · 8.97 KB
/
b44lmqnx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "b44mm.h"
LM_STATUS b44_MM_ReadConfig16(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT16 *pValue16)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK )pDevice;
pci_read_config16(pUmDevice->pciinfo.BusNumber,pUmDevice->pciinfo.DevFunc,Offset,1,pValue16);
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_WriteConfig16(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT16 Value16)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK )pDevice;
pci_write_config16(pUmDevice->pciinfo.BusNumber,pUmDevice->pciinfo.DevFunc,Offset,1,&Value16);
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_ReadConfig32(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 *pValue32)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK )pDevice;
pci_read_config32(pUmDevice->pciinfo.BusNumber,pUmDevice->pciinfo.DevFunc,Offset,1,pValue32);
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_WriteConfig32(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 Value32)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK )pDevice;
pci_write_config32(pUmDevice->pciinfo.BusNumber,pUmDevice->pciinfo.DevFunc,Offset,1,&Value32);
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_MapMemBase(PLM_DEVICE_BLOCK pDevice)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
pDevice->pMappedMemBase = (void *)mmap_device_memory(0,sizeof(bcmenetregs_t) + 128,PROT_READ|PROT_WRITE|PROT_NOCACHE,0,PCI_MEM_ADDR(pUmDevice->pciinfo.CpuBaseAddress[0]));
if(pDevice->pMappedMemBase == MAP_FAILED)
{
DbgPrint("mmap_device_memory failed: %s\n",strerror(errno));
}
pUmDevice->nic->cfg.NumMemWindows=1;
pUmDevice->nic->cfg.MemBase[0] = (ulong_t)pDevice->pMappedMemBase;
pUmDevice->nic->cfg.MemLength[0] = sizeof(bcmenetregs_t)+128;
// pUmDevice->cfg.MemAttrib[0] = ATTR_MEM_SHARED; //??
return LM_STATUS_SUCCESS;
}
/********/
LM_STATUS b44_MM_IndicateRxPackets(PLM_DEVICE_BLOCK pDevice)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
PLM_PACKET pPacket;
PUM_PACKET pUmPacket;
int size;
npkt_t * npkt;
net_buf_t *nb;
net_iov_t *iov;
while(1) {
pPacket = (PLM_PACKET)QQ_PopHead(&pDevice->RxPacketReceivedQ.Container);
if(pPacket == 0) {
break;
}
pUmPacket = (PUM_PACKET)pPacket;
if((pPacket->PacketStatus != LM_STATUS_SUCCESS) || ((size = pPacket->PacketSize) > MAX_ETHERNET_PACKET_SIZE_NO_CRC)) { //error.. but reuse the packet.
DbgPrint("packet is failure :c");
QQ_PushTail(&pDevice->RxPacketFreeQ.Container,pPacket);
pUmDevice->nic->nstats.gstats.rcv_error++;
continue;
}
npkt = pUmPacket->npkt;
nb = (net_buf_t *)TAILQ_FIRST(&npkt->buffers);
iov = nb->net_iov;
iov->iov_phys += pDevice->rxoffset;
iov->iov_base += pDevice->rxoffset;
//Reset the packet into a working condition
npkt->next = NULL;
npkt->num_complete=1;
npkt->req_complete=0;
npkt->ref_cnt = 1;
npkt->flags = _NPKT_UP | _NPKT_NOT_TXED;
npkt->tot_iov = 1;
iov->iov_len = size;
npkt->framelen = size;
npkt->cell = pUmDevice->cell;
npkt->iface = 0;
npkt->endpoint = pUmDevice->nic->lan;
pUmPacket->npkt = 0;
QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container,pPacket); //once this packet is processed, it'll be put back onto the Receivequeue...
pUmDevice->bytecount.rx_bytes+=size;
pUmDevice->nic->nstats.gstats.rcv_ok++;
if(pUmDevice->options.nic.drvr.verbose>4) {
DbgPrint("Received a package of %d bytes",npkt->framelen);
}
if( pUmDevice->ion->tx_up_start(pUmDevice->reg_hdlp,npkt,0,0,pUmDevice->cell,pUmDevice->nic->lan,0, pUmDevice->nic) != 0) {
DbgPrint("GAwww, couldn't send package to io-net!!");
pUmDevice->ion->tx_done(pUmDevice->reg_hdlp,npkt);
}
}
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_IndicateTxPackets(PLM_DEVICE_BLOCK pDevice)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
PLM_PACKET pPacket;
PUM_PACKET pUmPacket;
npkt_t *npkt;
while(1){
pPacket = (PLM_PACKET)QQ_PopHead(&pDevice->TxPacketXmittedQ.Container);
if(pPacket == 0)
break;
pUmPacket = (PUM_PACKET)pPacket;
npkt = pUmPacket->npkt;
if(npkt)
pUmDevice->ion->tx_done(pUmDevice->reg_hdlp,npkt);
pUmPacket->npkt = NULL;
QQ_PushTail(&pDevice->TxPacketFreeQ.Container,pPacket);
}
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_AllocateMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize, PLM_VOID *pMemoryBlockVirt)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
PLM_VOID pvirt;
pvirt = malloc(BlockSize);
pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
pUmDevice->dma_list[pUmDevice->mem_list_num] = 0;
pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = 0;
/* mem_size_list[i] == 0 indicates that the memory should be freed */
memset(pvirt,0,BlockSize);
*pMemoryBlockVirt = pvirt;
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize, PLM_VOID *pMemoryBlockVirt, PLM_PHYSICAL_ADDRESS pMemoryBlockPhy)
{
PLM_VOID pvirt;
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
pvirt = pUmDevice->ion->alloc(BlockSize,0);
pUmDevice->mem_list[pUmDevice->mem_list_num] = pvirt;
pUmDevice->dma_list[pUmDevice->mem_list_num] = pUmDevice->ion->mphys(pvirt);
pUmDevice->mem_size_list[pUmDevice->mem_list_num++] = BlockSize;
*pMemoryBlockVirt = (PLM_VOID)pvirt;
*pMemoryBlockPhy = (LM_PHYSICAL_ADDRESS)pUmDevice->ion->mphys(pvirt);
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_GetConfig(PLM_DEVICE_BLOCK pDevice)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
if(pUmDevice->options.nic.speed != 0)
pDevice->DisableAutoNeg = TRUE;
else
pDevice->DisableAutoNeg = FALSE;
if(pUmDevice->options.nic.speed == 10)
pDevice->RequestedLineSpeed = LM_LINE_SPEED_10MBPS;
else if(pUmDevice->options.nic.speed == 100)
pDevice->RequestedLineSpeed = LM_LINE_SPEED_100MBPS;
else
pDevice->RequestedLineSpeed = LM_LINE_SPEED_AUTO;
if(pUmDevice->options.nic.fullduplex == 1)
pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_HALF;
else if(pUmDevice->options.nic.fullduplex == 2)
pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_FULL;
else
pDevice->RequestedDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
pDevice->FlowControlCap = 0;
pUmDevice->timer_interval = 1000000; //0.1 seconds polling time..
pUmDevice->link_interval = 10; //every 10th time, update stats etc.
if(pUmDevice->options.nic.transmit != 0 && pUmDevice->options.nic.transmit < MAX_TX_PACKET_DESC_COUNT) {
pDevice->TxPacketDescCnt = pUmDevice->options.nic.transmit;
} else
pDevice->TxPacketDescCnt = DEFAULT_TX_PACKET_DESC_COUNT;
if(pUmDevice->options.nic.receive != 0 && pUmDevice->options.nic.receive < MAX_RX_PACKET_DESC_COUNT) {
pDevice->RxPacketDescCnt = pUmDevice->options.nic.receive;
} else
pDevice->RxPacketDescCnt = DEFAULT_RX_PACKET_DESC_COUNT;
if(memcmp(pUmDevice->options.nic.mac,"\0\0\0\0\0\0",6)!= 0){
b44_LM_SetMacAddress(pDevice,pUmDevice->options.nic.mac);
}
if(pUmDevice->options.nic.nomulticast != -1)
b44_LM_SetReceiveMask(pDevice,pDevice->ReceiveMask & ~LM_ACCEPT_MULTICAST);
else
b44_LM_SetReceiveMask(pDevice,pDevice->ReceiveMask & LM_ACCEPT_MULTICAST);
if(pUmDevice->options.nic.promiscuous != -1)
b44_LM_SetReceiveMask(pDevice,pDevice->ReceiveMask & LM_PROMISCUOUS_MODE);
else
b44_LM_SetReceiveMask(pDevice,pDevice->ReceiveMask & ~LM_PROMISCUOUS_MODE);
//Add support for flowcontrol
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status)
{
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
if(!pUmDevice->opened)
return LM_STATUS_SUCCESS;
if(pUmDevice->delayed_link_ind > 0)
return LM_STATUS_SUCCESS;
else {
if(Status == LM_STATUS_LINK_DOWN) {
pUmDevice->line_speed = 0;
}
else if(Status == LM_STATUS_LINK_ACTIVE) {
//netif_carrier_on.
}
}
if(Status == LM_STATUS_LINK_ACTIVE) {
if(pDevice->LineSpeed == LM_LINE_SPEED_100MBPS)
pUmDevice->line_speed = 100000;
else if(pDevice->LineSpeed == LM_LINE_SPEED_10MBPS)
pUmDevice->line_speed = 10000;
}
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_InitializeUmPackets(PLM_DEVICE_BLOCK pDevice){
int i;
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK) pDevice;
PUM_PACKET pUmPacket;
PLM_PACKET pPacket;
for (i = 0; i < pDevice->RxPacketDescCnt; i++) {
pPacket = QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
pUmPacket = (PUM_PACKET) pPacket;
if (pPacket == 0) {
DbgPrint("Bad RxPacketFreeQ\n");
}
if(pUmPacket->npkt) {
ASSERT(0);
}
if(bcm4400_allocatenpkt(pUmDevice,pUmPacket) == -1) {
QQ_PushTail(&pUmDevice->rx_out_of_buf_q.Container,pPacket);
continue;
}
QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
}
pUmDevice->rx_buf_repl_thresh = pDevice->RxPacketDescCnt / 4;
pUmDevice->rx_buf_repl_panic_thresh = pDevice->RxPacketDescCnt * 3 / 4;
return LM_STATUS_SUCCESS;
}
LM_STATUS b44_MM_FreeRxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
{
PUM_PACKET pUmPacket;
PUM_DEVICE_BLOCK pUmDevice = (PUM_DEVICE_BLOCK)pDevice;
npkt_t *npkt;
if(pPacket == NULL)
return LM_STATUS_SUCCESS;
pUmPacket = (PUM_PACKET)pPacket;
if((npkt = pUmPacket->npkt))
pUmDevice->ion->free(npkt->org_data);
pUmDevice->ion->free(npkt);
pUmPacket->npkt = 0;
return LM_STATUS_SUCCESS;
}