2 /******************************************************************************/
4 /* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2000 Broadcom */
6 /* All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify */
9 /* it under the terms of the GNU General Public License as published by */
10 /* the Free Software Foundation, located in the file LICENSE. */
13 /* 02/25/00 Hav Khauv Initial version. */
14 /******************************************************************************/
19 #include "bcm570x_queue.h"
20 #include "bcm570x_bits.h"
23 /******************************************************************************/
25 /******************************************************************************/
27 typedef char LM_CHAR, *PLM_CHAR;
28 typedef unsigned int LM_UINT, *PLM_UINT;
29 typedef unsigned char LM_UINT8, *PLM_UINT8;
30 typedef unsigned short LM_UINT16, *PLM_UINT16;
31 typedef unsigned int LM_UINT32, *PLM_UINT32;
32 typedef unsigned int LM_COUNTER, *PLM_COUNTER;
33 typedef void LM_VOID, *PLM_VOID;
34 typedef char LM_BOOL, *PLM_BOOL;
38 #ifdef BIG_ENDIAN_HOST
41 #else /* BIG_ENDIAN_HOST */
44 #endif /* !BIG_ENDIAN_HOST */
45 } LM_UINT64, *PLM_UINT64;
47 typedef LM_UINT64 LM_PHYSICAL_ADDRESS, *PLM_PHYSICAL_ADDRESS;
49 /* void LM_INC_PHYSICAL_ADDRESS(PLM_PHYSICAL_ADDRESS pAddr,LM_UINT32 IncSize) */
50 #define LM_INC_PHYSICAL_ADDRESS(pAddr, IncSize) \
54 OrgLow = (pAddr)->Low; \
55 (pAddr)->Low += IncSize; \
56 if((pAddr)->Low < OrgLow) { \
57 (pAddr)->High++; /* Wrap around. */ \
63 #define NULL ((void *) 0)
67 #define OFFSETOF(_s, _m) (MM_UINT_PTR(&(((_s *) 0)->_m)))
71 /******************************************************************************/
73 /******************************************************************************/
75 #define IS_ETH_BROADCAST(_pEthAddr) \
76 (((unsigned char *) (_pEthAddr))[0] == ((unsigned char) 0xff))
78 #define IS_ETH_MULTICAST(_pEthAddr) \
79 (((unsigned char *) (_pEthAddr))[0] & ((unsigned char) 0x01))
81 #define IS_ETH_ADDRESS_EQUAL(_pEtherAddr1, _pEtherAddr2) \
82 ((((unsigned char *) (_pEtherAddr1))[0] == \
83 ((unsigned char *) (_pEtherAddr2))[0]) && \
84 (((unsigned char *) (_pEtherAddr1))[1] == \
85 ((unsigned char *) (_pEtherAddr2))[1]) && \
86 (((unsigned char *) (_pEtherAddr1))[2] == \
87 ((unsigned char *) (_pEtherAddr2))[2]) && \
88 (((unsigned char *) (_pEtherAddr1))[3] == \
89 ((unsigned char *) (_pEtherAddr2))[3]) && \
90 (((unsigned char *) (_pEtherAddr1))[4] == \
91 ((unsigned char *) (_pEtherAddr2))[4]) && \
92 (((unsigned char *) (_pEtherAddr1))[5] == \
93 ((unsigned char *) (_pEtherAddr2))[5]))
95 #define COPY_ETH_ADDRESS(_Src, _Dst) \
96 ((unsigned char *) (_Dst))[0] = ((unsigned char *) (_Src))[0]; \
97 ((unsigned char *) (_Dst))[1] = ((unsigned char *) (_Src))[1]; \
98 ((unsigned char *) (_Dst))[2] = ((unsigned char *) (_Src))[2]; \
99 ((unsigned char *) (_Dst))[3] = ((unsigned char *) (_Src))[3]; \
100 ((unsigned char *) (_Dst))[4] = ((unsigned char *) (_Src))[4]; \
101 ((unsigned char *) (_Dst))[5] = ((unsigned char *) (_Src))[5];
104 /******************************************************************************/
106 /******************************************************************************/
108 #define ETHERNET_ADDRESS_SIZE 6
109 #define ETHERNET_PACKET_HEADER_SIZE 14
110 #define MIN_ETHERNET_PACKET_SIZE 64 /* with 4 byte crc. */
111 #define MAX_ETHERNET_PACKET_SIZE 1518 /* with 4 byte crc. */
112 #define MIN_ETHERNET_PACKET_SIZE_NO_CRC 60
113 #define MAX_ETHERNET_PACKET_SIZE_NO_CRC 1514
114 #define MAX_ETHERNET_PACKET_BUFFER_SIZE 1536 /* A nice even number. */
116 #ifndef LM_MAX_MC_TABLE_SIZE
117 #define LM_MAX_MC_TABLE_SIZE 32
118 #endif /* LM_MAX_MC_TABLE_SIZE */
119 #define LM_MC_ENTRY_SIZE (ETHERNET_ADDRESS_SIZE+1)
120 #define LM_MC_INSTANCE_COUNT_INDEX (LM_MC_ENTRY_SIZE-1)
123 /* Receive filter masks. */
124 #define LM_ACCEPT_UNICAST 0x0001
125 #define LM_ACCEPT_MULTICAST 0x0002
126 #define LM_ACCEPT_ALL_MULTICAST 0x0004
127 #define LM_ACCEPT_BROADCAST 0x0008
128 #define LM_ACCEPT_ERROR_PACKET 0x0010
130 #define LM_PROMISCUOUS_MODE 0x10000
133 /******************************************************************************/
135 /******************************************************************************/
137 #define PCI_VENDOR_ID_REG 0x00
138 #define PCI_DEVICE_ID_REG 0x02
140 #define PCI_COMMAND_REG 0x04
141 #define PCI_IO_SPACE_ENABLE 0x0001
142 #define PCI_MEM_SPACE_ENABLE 0x0002
143 #define PCI_BUSMASTER_ENABLE 0x0004
144 #define PCI_MEMORY_WRITE_INVALIDATE 0x0010
145 #define PCI_PARITY_ERROR_ENABLE 0x0040
146 #define PCI_SYSTEM_ERROR_ENABLE 0x0100
147 #define PCI_FAST_BACK_TO_BACK_ENABLE 0x0200
149 #define PCI_STATUS_REG 0x06
150 #define PCI_REV_ID_REG 0x08
152 #define PCI_CACHE_LINE_SIZE_REG 0x0c
154 #define PCI_IO_BASE_ADDR_REG 0x10
155 #define PCI_IO_BASE_ADDR_MASK 0xfffffff0
157 #define PCI_MEM_BASE_ADDR_LOW 0x10
158 #define PCI_MEM_BASE_ADDR_HIGH 0x14
160 #define PCI_SUBSYSTEM_VENDOR_ID_REG 0x2c
161 #define PCI_SUBSYSTEM_ID_REG 0x2e
162 #define PCI_INT_LINE_REG 0x3c
164 #define PCIX_CAP_REG 0x40
165 #define PCIX_ENABLE_RELAXED_ORDERING BIT_17
167 /******************************************************************************/
168 /* Fragment structure. */
169 /******************************************************************************/
173 LM_PHYSICAL_ADDRESS FragBuf;
174 } LM_FRAG, *PLM_FRAG;
177 /* FragCount is initialized for the caller to the maximum array size, on */
178 /* return FragCount is the number of the actual fragments in the array. */
181 /* Total buffer size. */
184 /* Fragment array buffer. */
185 LM_FRAG Fragments[1];
186 } LM_FRAG_LIST, *PLM_FRAG_LIST;
188 #define DECLARE_FRAG_LIST_BUFFER_TYPE(_FRAG_LIST_TYPE_NAME, _MAX_FRAG_COUNT) \
190 LM_FRAG_LIST FragList; \
191 LM_FRAG FragListBuffer[_MAX_FRAG_COUNT-1]; \
192 } _FRAG_LIST_TYPE_NAME, *P##_FRAG_LIST_TYPE_NAME
195 /******************************************************************************/
197 /******************************************************************************/
199 #define LM_STATUS_SUCCESS 0
200 #define LM_STATUS_FAILURE 1
202 #define LM_STATUS_INTERRUPT_ACTIVE 2
203 #define LM_STATUS_INTERRUPT_NOT_ACTIVE 3
205 #define LM_STATUS_LINK_ACTIVE 4
206 #define LM_STATUS_LINK_DOWN 5
207 #define LM_STATUS_LINK_SETTING_MISMATCH 6
209 #define LM_STATUS_TOO_MANY_FRAGMENTS 7
210 #define LM_STATUS_TRANSMIT_ABORTED 8
211 #define LM_STATUS_TRANSMIT_ERROR 9
212 #define LM_STATUS_RECEIVE_ABORTED 10
213 #define LM_STATUS_RECEIVE_ERROR 11
214 #define LM_STATUS_INVALID_PACKET_SIZE 12
215 #define LM_STATUS_OUT_OF_MAP_REGISTERS 13
216 #define LM_STATUS_UNKNOWN_ADAPTER 14
218 typedef LM_UINT LM_STATUS, *PLM_STATUS;
221 /******************************************************************************/
222 /* Requested media type. */
223 /******************************************************************************/
225 #define LM_REQUESTED_MEDIA_TYPE_AUTO 0
226 #define LM_REQUESTED_MEDIA_TYPE_BNC 1
227 #define LM_REQUESTED_MEDIA_TYPE_UTP_AUTO 2
228 #define LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS 3
229 #define LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX 4
230 #define LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS 5
231 #define LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX 6
232 #define LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS 7
233 #define LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX 8
234 #define LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS 9
235 #define LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS_FULL_DUPLEX 10
236 #define LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS 11
237 #define LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX 12
238 #define LM_REQUESTED_MEDIA_TYPE_MAC_LOOPBACK 0xfffe
239 #define LM_REQUESTED_MEDIA_TYPE_PHY_LOOPBACK 0xffff
241 typedef LM_UINT32 LM_REQUESTED_MEDIA_TYPE, *PLM_REQUESTED_MEDIA_TYPE;
244 /******************************************************************************/
246 /******************************************************************************/
248 #define LM_MEDIA_TYPE_UNKNOWN -1
249 #define LM_MEDIA_TYPE_AUTO 0
250 #define LM_MEDIA_TYPE_UTP 1
251 #define LM_MEDIA_TYPE_BNC 2
252 #define LM_MEDIA_TYPE_AUI 3
253 #define LM_MEDIA_TYPE_FIBER 4
255 typedef LM_UINT32 LM_MEDIA_TYPE, *PLM_MEDIA_TYPE;
258 /******************************************************************************/
260 /******************************************************************************/
262 #define LM_LINE_SPEED_UNKNOWN 0
263 #define LM_LINE_SPEED_10MBPS 1
264 #define LM_LINE_SPEED_100MBPS 2
265 #define LM_LINE_SPEED_1000MBPS 3
267 typedef LM_UINT32 LM_LINE_SPEED, *PLM_LINE_SPEED;
270 /******************************************************************************/
272 /******************************************************************************/
274 #define LM_DUPLEX_MODE_UNKNOWN 0
275 #define LM_DUPLEX_MODE_HALF 1
276 #define LM_DUPLEX_MODE_FULL 2
278 typedef LM_UINT32 LM_DUPLEX_MODE, *PLM_DUPLEX_MODE;
281 /******************************************************************************/
283 /******************************************************************************/
285 #define LM_POWER_STATE_D0 0
286 #define LM_POWER_STATE_D1 1
287 #define LM_POWER_STATE_D2 2
288 #define LM_POWER_STATE_D3 3
290 typedef LM_UINT32 LM_POWER_STATE, *PLM_POWER_STATE;
293 /******************************************************************************/
294 /* Task offloading. */
295 /******************************************************************************/
297 #define LM_TASK_OFFLOAD_NONE 0x0000
298 #define LM_TASK_OFFLOAD_TX_IP_CHECKSUM 0x0001
299 #define LM_TASK_OFFLOAD_RX_IP_CHECKSUM 0x0002
300 #define LM_TASK_OFFLOAD_TX_TCP_CHECKSUM 0x0004
301 #define LM_TASK_OFFLOAD_RX_TCP_CHECKSUM 0x0008
302 #define LM_TASK_OFFLOAD_TX_UDP_CHECKSUM 0x0010
303 #define LM_TASK_OFFLOAD_RX_UDP_CHECKSUM 0x0020
304 #define LM_TASK_OFFLOAD_TCP_SEGMENTATION 0x0040
306 typedef LM_UINT32 LM_TASK_OFFLOAD, *PLM_TASK_OFFLOAD;
309 /******************************************************************************/
311 /******************************************************************************/
313 #define LM_FLOW_CONTROL_NONE 0x00
314 #define LM_FLOW_CONTROL_RECEIVE_PAUSE 0x01
315 #define LM_FLOW_CONTROL_TRANSMIT_PAUSE 0x02
316 #define LM_FLOW_CONTROL_RX_TX_PAUSE (LM_FLOW_CONTROL_RECEIVE_PAUSE | \
317 LM_FLOW_CONTROL_TRANSMIT_PAUSE)
319 /* This value can be or-ed with RECEIVE_PAUSE and TRANSMIT_PAUSE. If the */
320 /* auto-negotiation is disabled and the RECEIVE_PAUSE and TRANSMIT_PAUSE */
321 /* bits are set, then flow control is enabled regardless of link partner's */
322 /* flow control capability. */
323 #define LM_FLOW_CONTROL_AUTO_PAUSE 0x80000000
325 typedef LM_UINT32 LM_FLOW_CONTROL, *PLM_FLOW_CONTROL;
328 /******************************************************************************/
330 /******************************************************************************/
332 #define LM_WAKE_UP_MODE_NONE 0
333 #define LM_WAKE_UP_MODE_MAGIC_PACKET 1
334 #define LM_WAKE_UP_MODE_NWUF 2
335 #define LM_WAKE_UP_MODE_LINK_CHANGE 4
337 typedef LM_UINT32 LM_WAKE_UP_MODE, *PLM_WAKE_UP_MODE;
340 /******************************************************************************/
342 /******************************************************************************/
344 #define LM_COUNTER_FRAMES_XMITTED_OK 0
345 #define LM_COUNTER_FRAMES_RECEIVED_OK 1
346 #define LM_COUNTER_ERRORED_TRANSMIT_COUNT 2
347 #define LM_COUNTER_ERRORED_RECEIVE_COUNT 3
348 #define LM_COUNTER_RCV_CRC_ERROR 4
349 #define LM_COUNTER_ALIGNMENT_ERROR 5
350 #define LM_COUNTER_SINGLE_COLLISION_FRAMES 6
351 #define LM_COUNTER_MULTIPLE_COLLISION_FRAMES 7
352 #define LM_COUNTER_FRAMES_DEFERRED 8
353 #define LM_COUNTER_MAX_COLLISIONS 9
354 #define LM_COUNTER_RCV_OVERRUN 10
355 #define LM_COUNTER_XMIT_UNDERRUN 11
356 #define LM_COUNTER_UNICAST_FRAMES_XMIT 12
357 #define LM_COUNTER_MULTICAST_FRAMES_XMIT 13
358 #define LM_COUNTER_BROADCAST_FRAMES_XMIT 14
359 #define LM_COUNTER_UNICAST_FRAMES_RCV 15
360 #define LM_COUNTER_MULTICAST_FRAMES_RCV 16
361 #define LM_COUNTER_BROADCAST_FRAMES_RCV 17
363 typedef LM_UINT32 LM_COUNTER_TYPE, *PLM_COUNTER_TYPE;
366 /******************************************************************************/
367 /* Forward definition. */
368 /******************************************************************************/
370 typedef struct _LM_DEVICE_BLOCK *PLM_DEVICE_BLOCK;
371 typedef struct _LM_PACKET *PLM_PACKET;
374 /******************************************************************************/
375 /* Function prototypes. */
376 /******************************************************************************/
378 LM_STATUS LM_GetAdapterInfo(PLM_DEVICE_BLOCK pDevice);
379 LM_STATUS LM_InitializeAdapter(PLM_DEVICE_BLOCK pDevice);
380 LM_STATUS LM_ResetAdapter(PLM_DEVICE_BLOCK pDevice);
381 LM_STATUS LM_DisableInterrupt(PLM_DEVICE_BLOCK pDevice);
382 LM_STATUS LM_EnableInterrupt(PLM_DEVICE_BLOCK pDevice);
383 LM_STATUS LM_SendPacket(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket);
384 LM_STATUS LM_ServiceInterrupts(PLM_DEVICE_BLOCK pDevice);
385 LM_STATUS LM_QueueRxPackets(PLM_DEVICE_BLOCK pDevice);
386 LM_STATUS LM_SetReceiveMask(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Mask);
387 LM_STATUS LM_Halt(PLM_DEVICE_BLOCK pDevice);
388 LM_STATUS LM_Abort(PLM_DEVICE_BLOCK pDevice);
389 LM_STATUS LM_MulticastAdd(PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress);
390 LM_STATUS LM_MulticastDel(PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress);
391 LM_STATUS LM_MulticastClear(PLM_DEVICE_BLOCK pDevice);
392 LM_STATUS LM_SetMacAddress(PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMacAddress);
393 LM_STATUS LM_LoopbackAddress(PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pAddress);
395 LM_UINT32 LM_GetCrcCounter(PLM_DEVICE_BLOCK pDevice);
397 LM_WAKE_UP_MODE LM_PMCapabilities(PLM_DEVICE_BLOCK pDevice);
398 LM_STATUS LM_NwufAdd(PLM_DEVICE_BLOCK pDevice, LM_UINT32 ByteMaskSize,
399 LM_UINT8 *pByteMask, LM_UINT8 *pPattern);
400 LM_STATUS LM_NwufRemove(PLM_DEVICE_BLOCK pDevice, LM_UINT32 ByteMaskSize,
401 LM_UINT8 *pByteMask, LM_UINT8 *pPattern);
402 LM_STATUS LM_SetPowerState(PLM_DEVICE_BLOCK pDevice, LM_POWER_STATE PowerLevel);
404 LM_VOID LM_ReadPhy(PLM_DEVICE_BLOCK pDevice, LM_UINT32 PhyReg,
406 LM_VOID LM_WritePhy(PLM_DEVICE_BLOCK pDevice, LM_UINT32 PhyReg,
409 LM_STATUS LM_ControlLoopBack(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Control);
410 LM_STATUS LM_SetupPhy(PLM_DEVICE_BLOCK pDevice);
411 int LM_BlinkLED(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlinkDuration);
414 /******************************************************************************/
415 /* These are the OS specific functions called by LMAC. */
416 /******************************************************************************/
418 LM_STATUS MM_ReadConfig16(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
419 LM_UINT16 *pValue16);
420 LM_STATUS MM_WriteConfig16(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
422 LM_STATUS MM_ReadConfig32(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
423 LM_UINT32 *pValue32);
424 LM_STATUS MM_WriteConfig32(PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset,
426 LM_STATUS MM_MapMemBase(PLM_DEVICE_BLOCK pDevice);
427 LM_STATUS MM_MapIoBase(PLM_DEVICE_BLOCK pDevice);
428 LM_STATUS MM_IndicateRxPackets(PLM_DEVICE_BLOCK pDevice);
429 LM_STATUS MM_IndicateTxPackets(PLM_DEVICE_BLOCK pDevice);
430 LM_STATUS MM_StartTxDma(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket);
431 LM_STATUS MM_CompleteTxDma(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket);
432 LM_STATUS MM_AllocateMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
433 PLM_VOID *pMemoryBlockVirt);
434 LM_STATUS MM_AllocateSharedMemory(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlockSize,
435 PLM_VOID *pMemoryBlockVirt, PLM_PHYSICAL_ADDRESS pMemoryBlockPhy,
437 LM_STATUS MM_GetConfig(PLM_DEVICE_BLOCK pDevice);
438 LM_STATUS MM_IndicateStatus(PLM_DEVICE_BLOCK pDevice, LM_STATUS Status);
439 LM_STATUS MM_InitializeUmPackets(PLM_DEVICE_BLOCK pDevice);
440 LM_STATUS MM_FreeRxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket);
441 LM_STATUS MM_CoalesceTxBuffer(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket);
442 LM_STATUS LM_MbufWorkAround(PLM_DEVICE_BLOCK pDevice);
443 LM_STATUS LM_SetLinkSpeed(PLM_DEVICE_BLOCK pDevice,
444 LM_REQUESTED_MEDIA_TYPE RequestedMediaType);
446 #if INCLUDE_5703_A0_FIX
447 LM_STATUS LM_Load5703DmaWFirmware(PLM_DEVICE_BLOCK pDevice);