1 /******************************************************************************/
3 /* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2000 - 2004 Broadcom */
5 /* All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify */
8 /* it under the terms of the GNU General Public License as published by */
9 /* the Free Software Foundation, located in the file LICENSE. */
11 /******************************************************************************/
13 /* $Id: mm.h,v 1.6 2006/09/26 05:22:21 michael Exp $ */
18 #include <linux/config.h>
20 #if defined(CONFIG_SMP) && !defined(__SMP__)
24 #if defined(CONFIG_MODVERSIONS) && defined(MODULE) && !defined(MODVERSIONS)
31 #define __NO_VERSION__
33 #include <linux/version.h>
37 #if defined(MODVERSIONS) && (LINUX_VERSION_CODE < 0x020500)
39 #include <linux/modversions.h>
43 #if (LINUX_VERSION_CODE < 0x020605)
44 #include <linux/module.h>
46 #include <linux/moduleparam.h>
51 #define MOD_INC_USE_COUNT
52 #define MOD_DEC_USE_COUNT
53 #define SET_MODULE_OWNER(dev)
54 #define MODULE_DEVICE_TABLE(pci, pci_tbl)
58 #include <linux/kernel.h>
59 #include <linux/sched.h>
60 #include <linux/string.h>
61 #include <linux/timer.h>
62 #include <linux/errno.h>
63 #include <linux/ioport.h>
64 #include <linux/slab.h>
65 #include <linux/interrupt.h>
66 #include <linux/pci.h>
67 #include <linux/init.h>
68 #include <linux/netdevice.h>
69 #include <linux/etherdevice.h>
70 #include <linux/skbuff.h>
71 #include <linux/reboot.h>
72 #include <asm/processor.h> /* Processor type for cache alignment. */
73 #include <asm/bitops.h>
75 #include <asm/unaligned.h>
76 #include <linux/delay.h>
77 #include <asm/byteorder.h>
78 #include <linux/time.h>
79 #include <asm/uaccess.h>
80 #if (LINUX_VERSION_CODE >= 0x020400)
81 #if (LINUX_VERSION_CODE < 0x020500)
82 #include <linux/wrapper.h>
84 #include <linux/ethtool.h>
87 #include <linux/smp_lock.h>
88 #include <linux/proc_fs.h>
91 #ifdef NETIF_F_HW_VLAN_TX
92 #include <linux/if_vlan.h>
97 #define INCLUDE_TCP_SEG_SUPPORT 1
100 #include <net/checksum.h>
103 #ifndef LINUX_KERNEL_VERSION
104 #define LINUX_KERNEL_VERSION 0
107 #ifndef MAX_SKB_FRAGS
108 #define MAX_SKB_FRAGS 0
111 #if (LINUX_VERSION_CODE >= 0x020400)
112 #ifndef ETHTOOL_GEEPROM
114 #define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
115 #define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data */
117 /* for passing EEPROM chunks */
118 struct ethtool_eeprom
{
121 u32 offset
; /* in bytes */
122 u32 len
; /* in bytes */
125 #define BCM_EEDUMP_LEN(info_p, size) *((u32 *) &((info_p)->reserved1[24]))=size
129 #define BCM_EEDUMP_LEN(info_p, size) (info_p)->eedump_len=size
134 #define BCM_INT_COAL 1
135 #define BCM_NIC_SEND_BD 1
138 #define BCM_TASKLET 1
140 #if HAVE_NETIF_RECEIVE_SKB
141 #define BCM_NAPI_RXPOLL 1
145 #if defined(CONFIG_PPC64)
146 #define BCM_DISCONNECT_AT_CACHELINE 1
151 #undef ETHTOOL_GEEPROM
152 #undef ETHTOOL_SEEPROM
154 #undef ETHTOOL_GPAUSEPARAM
155 #undef ETHTOOL_GRXCSUM
158 #undef BCM_NIC_SEND_BD
165 #define BIG_ENDIAN_HOST 1
168 #define MM_SWAP_LE32(x) cpu_to_le32(x)
169 #define MM_SWAP_BE32(x) cpu_to_be32(x)
171 #if (LINUX_VERSION_CODE < 0x020327)
172 #define __raw_readl readl
173 #define __raw_writel writel
176 #define MM_MEMWRITEL(ptr, val) __raw_writel(val, ptr)
177 #define MM_MEMREADL(ptr) __raw_readl(ptr)
179 typedef atomic_t MM_ATOMIC_T
;
181 #define MM_ATOMIC_SET(ptr, val) atomic_set(ptr, val)
182 #define MM_ATOMIC_READ(ptr) atomic_read(ptr)
183 #define MM_ATOMIC_INC(ptr) atomic_inc(ptr)
184 #define MM_ATOMIC_ADD(ptr, val) atomic_add(val, ptr)
185 #define MM_ATOMIC_DEC(ptr) atomic_dec(ptr)
186 #define MM_ATOMIC_SUB(ptr, val) atomic_sub(val, ptr)
195 #define MM_WMB() wmb()
196 #define MM_RMB() rmb()
197 #define MM_MMIOWB() mmiowb()
206 #define STATIC static
209 extern int MM_Packet_Desc_Size
;
211 #define MM_PACKET_DESC_SIZE MM_Packet_Desc_Size
213 DECLARE_QUEUE_TYPE(UM_RX_PACKET_Q
, MAX_RX_PACKET_DESC_COUNT
+1);
218 #if (LINUX_VERSION_CODE < 0x020211)
219 typedef u32 dma_addr_t
;
222 #if (LINUX_VERSION_CODE < 0x02032a)
223 #define pci_map_single(dev, address, size, dir) virt_to_bus(address)
224 #define pci_unmap_single(dev, dma_addr, size, dir)
228 #if (LINUX_VERSION_CODE >= 0x02040d)
230 typedef dma_addr_t dmaaddr_high_t
;
234 #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && !defined(CONFIG_X86_64)
236 #if defined(CONFIG_HIGHMEM64G)
237 typedef unsigned long long dmaaddr_high_t
;
239 typedef dma_addr_t dmaaddr_high_t
;
243 #define pci_map_page bcm_pci_map_page
246 static inline dmaaddr_high_t
247 bcm_pci_map_page(struct pci_dev
*dev
, struct page
*page
,
248 int offset
, size_t size
, int dir
)
252 phys
= (page
-mem_map
) * (dmaaddr_high_t
) PAGE_SIZE
+ offset
;
257 #ifndef pci_unmap_page
258 #define pci_unmap_page(dev, map, size, dir)
261 #else /* #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && ! defined(CONFIG_X86_64)*/
263 typedef dma_addr_t dmaaddr_high_t
;
265 /* Warning - This may not work for all architectures if HIGHMEM is defined */
268 #define pci_map_page(dev, page, offset, size, dir) \
269 pci_map_single(dev, page_address(page) + (offset), size, dir)
271 #ifndef pci_unmap_page
272 #define pci_unmap_page(dev, map, size, dir) \
273 pci_unmap_single(dev, map, size, dir)
276 #endif /* #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && ! defined(CONFIG_X86_64)*/
278 #endif /* #if (LINUX_VERSION_CODE >= 0x02040d)*/
279 #endif /* #if MAX_SKB_FRAGS*/
281 #if defined(CONFIG_X86) && !defined(CONFIG_X86_64)
282 #define NO_PCI_UNMAP 1
285 #if (LINUX_VERSION_CODE < 0x020412)
286 #if !defined(NO_PCI_UNMAP)
287 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME;
288 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME;
290 #define pci_unmap_addr(PTR, ADDR_NAME) \
293 #define pci_unmap_len(PTR, LEN_NAME) \
296 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
297 (((PTR)->ADDR_NAME) = (VAL))
299 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
300 (((PTR)->LEN_NAME) = (VAL))
302 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
303 #define DECLARE_PCI_UNMAP_LEN(ADDR_NAME)
305 #define pci_unmap_addr(PTR, ADDR_NAME) 0
306 #define pci_unmap_len(PTR, LEN_NAME) 0
307 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
308 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
312 #if (LINUX_VERSION_CODE < 0x02030e)
313 #define net_device device
314 #define netif_carrier_on(dev)
315 #define netif_carrier_off(dev)
318 #if (LINUX_VERSION_CODE < 0x02032b)
319 #define tasklet_struct tq_struct
322 typedef struct _UM_DEVICE_BLOCK
{
323 LM_DEVICE_BLOCK lm_dev
;
324 struct net_device
*dev
;
325 struct pci_dev
*pdev
;
326 struct net_device
*next_module
;
329 struct proc_dir_entry
*pfs_entry
;
332 void *mem_list
[MAX_MEM
];
333 dma_addr_t dma_list
[MAX_MEM
];
334 int mem_size_list
[MAX_MEM
];
340 int using_dac
; /* dual address cycle */
341 int delayed_link_ind
; /* Delay link status during initial load */
342 int adapter_just_inited
; /* the first few seconds after init. */
344 int statstimer_interval
;
346 int crc_counter_expiry
;
347 int poll_tbi_interval
;
352 int line_speed
; /* in Mbps, 0 if link is down */
353 UM_RX_PACKET_Q rx_out_of_buf_q
;
355 int rx_buf_repl_thresh
;
356 int rx_buf_repl_panic_thresh
;
357 int rx_buf_repl_isr_limit
;
359 struct timer_list timer
;
360 struct timer_list statstimer
;
362 spinlock_t global_lock
;
363 spinlock_t undi_lock
;
365 unsigned long undi_flags
;
366 volatile unsigned long interrupt
;
369 volatile unsigned long tasklet_busy
;
370 struct tasklet_struct tasklet
;
371 struct net_device_stats stats
;
373 int intr_test_result
;
374 #ifdef NETIF_F_HW_VLAN_TX
375 struct vlan_group
*vlgrp
;
377 int vlan_tag_mode
; /* Setting to allow ASF to work properly with */
379 #define VLAN_TAG_MODE_AUTO_STRIP 0
380 #define VLAN_TAG_MODE_NORMAL_STRIP 1
381 #define VLAN_TAG_MODE_FORCED_STRIP 2
383 /* Auto mode - VLAN TAGs are always stripped if ASF is enabled, */
384 /* If ASF is not enabled, it will be in normal mode. */
385 /* Normal mode - VLAN TAGs are stripped when VLANs are registered */
386 /* Forced mode - VLAN TAGs are always stripped. */
388 int adaptive_coalesce
;
391 uint rx_curr_coalesce_frames
;
392 uint rx_curr_coalesce_frames_intr
;
393 uint rx_curr_coalesce_ticks
;
394 uint tx_curr_coalesce_frames
;
396 unsigned long tx_zc_count
;
397 unsigned long tx_chksum_count
;
398 unsigned long tx_himem_count
;
399 unsigned long rx_good_chksum_count
;
401 unsigned long rx_bad_chksum_count
;
403 unsigned long tso_pkt_count
;
405 unsigned long rx_misc_errors
;
406 uint64_t phy_crc_count
;
407 unsigned int spurious_int
;
410 unsigned long boardflags
;
413 } UM_DEVICE_BLOCK
, *PUM_DEVICE_BLOCK
;
415 typedef struct _UM_PACKET
{
417 struct sk_buff
*skbuff
;
419 DECLARE_PCI_UNMAP_ADDR(map
[MAX_SKB_FRAGS
+ 1])
420 DECLARE_PCI_UNMAP_LEN(map_len
[MAX_SKB_FRAGS
+ 1])
422 DECLARE_PCI_UNMAP_ADDR(map
[1])
423 DECLARE_PCI_UNMAP_LEN(map_len
[1])
425 } UM_PACKET
, *PUM_PACKET
;
427 static inline void MM_SetAddr(LM_PHYSICAL_ADDRESS
*paddr
, dma_addr_t addr
)
429 #if BITS_PER_LONG == 64
430 paddr
->High
= ((unsigned long) addr
) >> 32;
431 paddr
->Low
= ((unsigned long) addr
) & 0xffffffff;
434 paddr
->Low
= (unsigned long) addr
;
438 static inline void MM_SetT3Addr(T3_64BIT_HOST_ADDR
*paddr
, dma_addr_t addr
)
440 #if BITS_PER_LONG == 64
441 paddr
->High
= ((unsigned long) addr
) >> 32;
442 paddr
->Low
= ((unsigned long) addr
) & 0xffffffff;
445 paddr
->Low
= (unsigned long) addr
;
450 static inline void MM_SetT3AddrHigh(T3_64BIT_HOST_ADDR
*paddr
,
453 #if defined(CONFIG_HIGHMEM64G) && defined(CONFIG_X86) && !defined(CONFIG_X86_64)
454 paddr
->High
= (unsigned long) (addr
>> 32);
455 paddr
->Low
= (unsigned long) (addr
& 0xffffffff);
457 MM_SetT3Addr(paddr
, (dma_addr_t
) addr
);
462 static inline void MM_MapRxDma(PLM_DEVICE_BLOCK pDevice
,
463 struct _LM_PACKET
*pPacket
,
464 T3_64BIT_HOST_ADDR
*paddr
)
467 struct sk_buff
*skb
= ((struct _UM_PACKET
*) pPacket
)->skbuff
;
469 map
= pci_map_single(((struct _UM_DEVICE_BLOCK
*)pDevice
)->pdev
,
471 pPacket
->u
.Rx
.RxBufferSize
,
473 pci_unmap_addr_set(((struct _UM_PACKET
*) pPacket
), map
[0], map
);
474 MM_SetT3Addr(paddr
, map
);
477 static inline void MM_MapTxDma(PLM_DEVICE_BLOCK pDevice
,
478 struct _LM_PACKET
*pPacket
,
479 T3_64BIT_HOST_ADDR
*paddr
,
484 struct sk_buff
*skb
= ((struct _UM_PACKET
*) pPacket
)->skbuff
;
489 if (skb_shinfo(skb
)->nr_frags
)
490 length
= skb
->len
- skb
->data_len
;
494 map
= pci_map_single(((struct _UM_DEVICE_BLOCK
*)pDevice
)->pdev
,
495 skb
->data
, length
, PCI_DMA_TODEVICE
);
496 MM_SetT3Addr(paddr
, map
);
497 pci_unmap_addr_set(((struct _UM_PACKET
*)pPacket
), map
[0], map
);
498 pci_unmap_len_set(((struct _UM_PACKET
*) pPacket
), map_len
[0],
505 dmaaddr_high_t hi_map
;
507 sk_frag
= &skb_shinfo(skb
)->frags
[frag
- 1];
509 hi_map
= pci_map_page(
510 ((struct _UM_DEVICE_BLOCK
*)pDevice
)->pdev
,
512 sk_frag
->page_offset
,
513 sk_frag
->size
, PCI_DMA_TODEVICE
);
515 MM_SetT3AddrHigh(paddr
, hi_map
);
516 pci_unmap_addr_set(((struct _UM_PACKET
*) pPacket
), map
[frag
],
518 pci_unmap_len_set(((struct _UM_PACKET
*) pPacket
),
519 map_len
[frag
], sk_frag
->size
);
520 *len
= sk_frag
->size
;
525 #define BCM5700_PHY_LOCK(pUmDevice, flags) { \
527 if ((pUmDevice)->do_global_lock) { \
528 lock = &(pUmDevice)->global_lock; \
531 lock = &(pUmDevice)->phy_lock; \
533 spin_lock_irqsave(lock, flags); \
536 #define BCM5700_PHY_UNLOCK(pUmDevice, flags) { \
538 if ((pUmDevice)->do_global_lock) { \
539 lock = &(pUmDevice)->global_lock; \
542 lock = &(pUmDevice)->phy_lock; \
544 spin_unlock_irqrestore(lock, flags); \
548 #define MM_ACQUIRE_UNDI_LOCK(_pDevice) \
549 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \
550 unsigned long flags; \
551 spin_lock_irqsave(&((PUM_DEVICE_BLOCK)(_pDevice))->undi_lock, flags); \
552 ((PUM_DEVICE_BLOCK)(_pDevice))->undi_flags = flags; \
555 #define MM_RELEASE_UNDI_LOCK(_pDevice) \
556 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \
557 unsigned long flags = ((PUM_DEVICE_BLOCK) (_pDevice))->undi_flags; \
558 spin_unlock_irqrestore(&((PUM_DEVICE_BLOCK)(_pDevice))->undi_lock, flags); \
561 #define MM_ACQUIRE_PHY_LOCK_IN_IRQ(_pDevice) \
562 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \
563 spin_lock(&((PUM_DEVICE_BLOCK)(_pDevice))->phy_lock); \
566 #define MM_RELEASE_PHY_LOCK_IN_IRQ(_pDevice) \
567 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \
568 spin_unlock(&((PUM_DEVICE_BLOCK)(_pDevice))->phy_lock); \
571 #define MM_UINT_PTR(_ptr) ((unsigned long) (_ptr))
573 #define MM_GETSTATS64(_Ctr) \
574 (uint64_t) (_Ctr).Low + ((uint64_t) (_Ctr).High << 32)
576 #define MM_GETSTATS32(_Ctr) \
577 (uint32_t) (_Ctr).Low
579 #if BITS_PER_LONG == 64
580 #define MM_GETSTATS(_Ctr) (unsigned long) MM_GETSTATS64(_Ctr)
582 #define MM_GETSTATS(_Ctr) (unsigned long) MM_GETSTATS32(_Ctr)
585 #if (LINUX_VERSION_CODE >= 0x020600)
586 #define mm_copy_to_user( to, from, size ) \
587 (in_atomic() ? (memcpy((to),(from),(size)), 0) : copy_to_user((to),(from),(size)))
588 #define mm_copy_from_user( to, from, size ) \
589 (in_atomic() ? (memcpy((to),(from),(size)), 0) : copy_from_user((to),(from),(size)))
591 #define mm_copy_to_user( to, from, size ) \
592 copy_to_user((to),(from),(size) )
593 #define mm_copy_from_user( to, from, size ) \
594 copy_from_user((to),(from),(size))
598 #define printf(fmt, args...) printk(KERN_WARNING fmt, ##args)
601 #define DbgPrint(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
602 #if defined(CONFIG_X86)
603 #define DbgBreakPoint() __asm__("int $129")
605 #define DbgBreakPoint()
607 #define MM_Wait(time) udelay(time)