[package] crda: new package (thanks to Hauke Mehrtens <hauke@hauke-m.de>)
[openwrt.git] / package / broadcom-57xx / src / mm.h
1 /******************************************************************************/
2 /* */
3 /* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2000 - 2004 Broadcom */
4 /* Corporation. */
5 /* All rights reserved. */
6 /* */
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. */
10 /* */
11 /******************************************************************************/
12
13 /* $Id: mm.h,v 1.6 2006/09/26 05:22:21 michael Exp $ */
14
15 #ifndef MM_H
16 #define MM_H
17
18 #include <linux/config.h>
19
20 #if defined(CONFIG_SMP) && !defined(__SMP__)
21 #define __SMP__
22 #endif
23
24 #if defined(CONFIG_MODVERSIONS) && defined(MODULE) && !defined(MODVERSIONS)
25 #ifndef BCM_SMALL_DRV
26 #define MODVERSIONS
27 #endif
28 #endif
29
30 #ifndef B57UM
31 #define __NO_VERSION__
32 #endif
33 #include <linux/version.h>
34
35 #ifdef MODULE
36
37 #if defined(MODVERSIONS) && (LINUX_VERSION_CODE < 0x020500)
38 #ifndef BCM_SMALL_DRV
39 #include <linux/modversions.h>
40 #endif
41 #endif
42
43 #if (LINUX_VERSION_CODE < 0x020605)
44 #include <linux/module.h>
45 #else
46 #include <linux/moduleparam.h>
47 #endif
48
49 #else
50
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)
55 #endif
56
57
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>
74 #include <asm/io.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>
83 #endif
84 #include <linux/ethtool.h>
85 #endif
86 #ifdef CONFIG_PROC_FS
87 #include <linux/smp_lock.h>
88 #include <linux/proc_fs.h>
89 #define BCM_PROC_FS 1
90 #endif
91 #ifdef NETIF_F_HW_VLAN_TX
92 #include <linux/if_vlan.h>
93 #define BCM_VLAN 1
94 #endif
95 #ifdef NETIF_F_TSO
96 #define BCM_TSO 1
97 #define INCLUDE_TCP_SEG_SUPPORT 1
98 #include <net/ip.h>
99 #include <net/tcp.h>
100 #include <net/checksum.h>
101 #endif
102
103 #ifndef LINUX_KERNEL_VERSION
104 #define LINUX_KERNEL_VERSION 0
105 #endif
106
107 #ifndef MAX_SKB_FRAGS
108 #define MAX_SKB_FRAGS 0
109 #endif
110
111 #if (LINUX_VERSION_CODE >= 0x020400)
112 #ifndef ETHTOOL_GEEPROM
113
114 #define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
115 #define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data */
116
117 /* for passing EEPROM chunks */
118 struct ethtool_eeprom {
119 u32 cmd;
120 u32 magic;
121 u32 offset; /* in bytes */
122 u32 len; /* in bytes */
123 u8 data[0];
124 };
125 #define BCM_EEDUMP_LEN(info_p, size) *((u32 *) &((info_p)->reserved1[24]))=size
126
127 #else
128
129 #define BCM_EEDUMP_LEN(info_p, size) (info_p)->eedump_len=size
130
131 #endif
132 #endif
133
134 #define BCM_INT_COAL 1
135 #define BCM_NIC_SEND_BD 1
136 #define BCM_ASF 1
137 #define BCM_WOL 1
138 #define BCM_TASKLET 1
139
140 #if HAVE_NETIF_RECEIVE_SKB
141 #define BCM_NAPI_RXPOLL 1
142 #undef BCM_TASKLET
143 #endif
144
145 #if defined(CONFIG_PPC64)
146 #define BCM_DISCONNECT_AT_CACHELINE 1
147 #endif
148
149 #ifdef BCM_SMALL_DRV
150 #undef BCM_PROC_FS
151 #undef ETHTOOL_GEEPROM
152 #undef ETHTOOL_SEEPROM
153 #undef ETHTOOL_GREGS
154 #undef ETHTOOL_GPAUSEPARAM
155 #undef ETHTOOL_GRXCSUM
156 #undef ETHTOOL_TEST
157 #undef BCM_INT_COAL
158 #undef BCM_NIC_SEND_BD
159 #undef BCM_WOL
160 #undef BCM_TASKLET
161 #undef BCM_TSO
162 #endif
163
164 #ifdef __BIG_ENDIAN
165 #define BIG_ENDIAN_HOST 1
166 #endif
167
168 #define MM_SWAP_LE32(x) cpu_to_le32(x)
169 #define MM_SWAP_BE32(x) cpu_to_be32(x)
170
171 #if (LINUX_VERSION_CODE < 0x020327)
172 #define __raw_readl readl
173 #define __raw_writel writel
174 #endif
175
176 #define MM_MEMWRITEL(ptr, val) __raw_writel(val, ptr)
177 #define MM_MEMREADL(ptr) __raw_readl(ptr)
178
179 typedef atomic_t MM_ATOMIC_T;
180
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)
187
188
189 #ifndef mmiowb
190 #define mmiowb()
191 #endif
192
193
194 #define MM_MB() mb()
195 #define MM_WMB() wmb()
196 #define MM_RMB() rmb()
197 #define MM_MMIOWB() mmiowb()
198
199 #include "lm.h"
200 #include "queue.h"
201 #include "tigon3.h"
202
203 #if DBG
204 #define STATIC
205 #else
206 #define STATIC static
207 #endif
208
209 extern int MM_Packet_Desc_Size;
210
211 #define MM_PACKET_DESC_SIZE MM_Packet_Desc_Size
212
213 DECLARE_QUEUE_TYPE(UM_RX_PACKET_Q, MAX_RX_PACKET_DESC_COUNT+1);
214
215 #define MAX_MEM 16
216 #define MAX_MEM2 4
217
218 #if (LINUX_VERSION_CODE < 0x020211)
219 typedef u32 dma_addr_t;
220 #endif
221
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)
225 #endif
226
227 #if MAX_SKB_FRAGS
228 #if (LINUX_VERSION_CODE >= 0x02040d)
229
230 typedef dma_addr_t dmaaddr_high_t;
231
232 #else
233
234 #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && !defined(CONFIG_X86_64)
235
236 #if defined(CONFIG_HIGHMEM64G)
237 typedef unsigned long long dmaaddr_high_t;
238 #else
239 typedef dma_addr_t dmaaddr_high_t;
240 #endif
241
242 #ifndef pci_map_page
243 #define pci_map_page bcm_pci_map_page
244 #endif
245
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)
249 {
250 dmaaddr_high_t phys;
251
252 phys = (page-mem_map) * (dmaaddr_high_t) PAGE_SIZE + offset;
253
254 return phys;
255 }
256
257 #ifndef pci_unmap_page
258 #define pci_unmap_page(dev, map, size, dir)
259 #endif
260
261 #else /* #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && ! defined(CONFIG_X86_64)*/
262
263 typedef dma_addr_t dmaaddr_high_t;
264
265 /* Warning - This may not work for all architectures if HIGHMEM is defined */
266
267 #ifndef pci_map_page
268 #define pci_map_page(dev, page, offset, size, dir) \
269 pci_map_single(dev, page_address(page) + (offset), size, dir)
270 #endif
271 #ifndef pci_unmap_page
272 #define pci_unmap_page(dev, map, size, dir) \
273 pci_unmap_single(dev, map, size, dir)
274 #endif
275
276 #endif /* #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && ! defined(CONFIG_X86_64)*/
277
278 #endif /* #if (LINUX_VERSION_CODE >= 0x02040d)*/
279 #endif /* #if MAX_SKB_FRAGS*/
280
281 #if defined(CONFIG_X86) && !defined(CONFIG_X86_64)
282 #define NO_PCI_UNMAP 1
283 #endif
284
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;
289
290 #define pci_unmap_addr(PTR, ADDR_NAME) \
291 ((PTR)->ADDR_NAME)
292
293 #define pci_unmap_len(PTR, LEN_NAME) \
294 ((PTR)->LEN_NAME)
295
296 #define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \
297 (((PTR)->ADDR_NAME) = (VAL))
298
299 #define pci_unmap_len_set(PTR, LEN_NAME, VAL) \
300 (((PTR)->LEN_NAME) = (VAL))
301 #else
302 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
303 #define DECLARE_PCI_UNMAP_LEN(ADDR_NAME)
304
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)
309 #endif
310 #endif
311
312 #if (LINUX_VERSION_CODE < 0x02030e)
313 #define net_device device
314 #define netif_carrier_on(dev)
315 #define netif_carrier_off(dev)
316 #endif
317
318 #if (LINUX_VERSION_CODE < 0x02032b)
319 #define tasklet_struct tq_struct
320 #endif
321
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;
327 char *name;
328 #ifdef BCM_PROC_FS
329 struct proc_dir_entry *pfs_entry;
330 char pfs_name[32];
331 #endif
332 void *mem_list[MAX_MEM];
333 dma_addr_t dma_list[MAX_MEM];
334 int mem_size_list[MAX_MEM];
335 int mem_list_num;
336
337 int index;
338 int opened;
339 int suspended;
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. */
343 int timer_interval;
344 int statstimer_interval;
345 int adaptive_expiry;
346 int crc_counter_expiry;
347 int poll_tbi_interval;
348 int poll_tbi_expiry;
349 int asf_heartbeat;
350 int tx_full;
351 int tx_queued;
352 int line_speed; /* in Mbps, 0 if link is down */
353 UM_RX_PACKET_Q rx_out_of_buf_q;
354 int rx_out_of_buf;
355 int rx_buf_repl_thresh;
356 int rx_buf_repl_panic_thresh;
357 int rx_buf_repl_isr_limit;
358 int rx_buf_align;
359 struct timer_list timer;
360 struct timer_list statstimer;
361 int do_global_lock;
362 spinlock_t global_lock;
363 spinlock_t undi_lock;
364 spinlock_t phy_lock;
365 unsigned long undi_flags;
366 volatile unsigned long interrupt;
367 atomic_t intr_sem;
368 int tasklet_pending;
369 volatile unsigned long tasklet_busy;
370 struct tasklet_struct tasklet;
371 struct net_device_stats stats;
372 int intr_test;
373 int intr_test_result;
374 #ifdef NETIF_F_HW_VLAN_TX
375 struct vlan_group *vlgrp;
376 #endif
377 int vlan_tag_mode; /* Setting to allow ASF to work properly with */
378 /* VLANs */
379 #define VLAN_TAG_MODE_AUTO_STRIP 0
380 #define VLAN_TAG_MODE_NORMAL_STRIP 1
381 #define VLAN_TAG_MODE_FORCED_STRIP 2
382
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. */
387
388 int adaptive_coalesce;
389 uint rx_last_cnt;
390 uint tx_last_cnt;
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;
395 #if TIGON3_DEBUG
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;
400 #endif
401 unsigned long rx_bad_chksum_count;
402 #ifdef BCM_TSO
403 unsigned long tso_pkt_count;
404 #endif
405 unsigned long rx_misc_errors;
406 uint64_t phy_crc_count;
407 unsigned int spurious_int;
408
409 void *sbh;
410 unsigned long boardflags;
411 void *robo;
412 int qos;
413 } UM_DEVICE_BLOCK, *PUM_DEVICE_BLOCK;
414
415 typedef struct _UM_PACKET {
416 LM_PACKET lm_packet;
417 struct sk_buff *skbuff;
418 #if MAX_SKB_FRAGS
419 DECLARE_PCI_UNMAP_ADDR(map[MAX_SKB_FRAGS + 1])
420 DECLARE_PCI_UNMAP_LEN(map_len[MAX_SKB_FRAGS + 1])
421 #else
422 DECLARE_PCI_UNMAP_ADDR(map[1])
423 DECLARE_PCI_UNMAP_LEN(map_len[1])
424 #endif
425 } UM_PACKET, *PUM_PACKET;
426
427 static inline void MM_SetAddr(LM_PHYSICAL_ADDRESS *paddr, dma_addr_t addr)
428 {
429 #if BITS_PER_LONG == 64
430 paddr->High = ((unsigned long) addr) >> 32;
431 paddr->Low = ((unsigned long) addr) & 0xffffffff;
432 #else
433 paddr->High = 0;
434 paddr->Low = (unsigned long) addr;
435 #endif
436 }
437
438 static inline void MM_SetT3Addr(T3_64BIT_HOST_ADDR *paddr, dma_addr_t addr)
439 {
440 #if BITS_PER_LONG == 64
441 paddr->High = ((unsigned long) addr) >> 32;
442 paddr->Low = ((unsigned long) addr) & 0xffffffff;
443 #else
444 paddr->High = 0;
445 paddr->Low = (unsigned long) addr;
446 #endif
447 }
448
449 #if MAX_SKB_FRAGS
450 static inline void MM_SetT3AddrHigh(T3_64BIT_HOST_ADDR *paddr,
451 dmaaddr_high_t addr)
452 {
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);
456 #else
457 MM_SetT3Addr(paddr, (dma_addr_t) addr);
458 #endif
459 }
460 #endif
461
462 static inline void MM_MapRxDma(PLM_DEVICE_BLOCK pDevice,
463 struct _LM_PACKET *pPacket,
464 T3_64BIT_HOST_ADDR *paddr)
465 {
466 dma_addr_t map;
467 struct sk_buff *skb = ((struct _UM_PACKET *) pPacket)->skbuff;
468
469 map = pci_map_single(((struct _UM_DEVICE_BLOCK *)pDevice)->pdev,
470 skb->tail,
471 pPacket->u.Rx.RxBufferSize,
472 PCI_DMA_FROMDEVICE);
473 pci_unmap_addr_set(((struct _UM_PACKET *) pPacket), map[0], map);
474 MM_SetT3Addr(paddr, map);
475 }
476
477 static inline void MM_MapTxDma(PLM_DEVICE_BLOCK pDevice,
478 struct _LM_PACKET *pPacket,
479 T3_64BIT_HOST_ADDR *paddr,
480 LM_UINT32 *len,
481 int frag)
482 {
483 dma_addr_t map;
484 struct sk_buff *skb = ((struct _UM_PACKET *) pPacket)->skbuff;
485 unsigned int length;
486
487 if (frag == 0) {
488 #if MAX_SKB_FRAGS
489 if (skb_shinfo(skb)->nr_frags)
490 length = skb->len - skb->data_len;
491 else
492 #endif
493 length = skb->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],
499 length);
500 *len = length;
501 }
502 #if MAX_SKB_FRAGS
503 else {
504 skb_frag_t *sk_frag;
505 dmaaddr_high_t hi_map;
506
507 sk_frag = &skb_shinfo(skb)->frags[frag - 1];
508
509 hi_map = pci_map_page(
510 ((struct _UM_DEVICE_BLOCK *)pDevice)->pdev,
511 sk_frag->page,
512 sk_frag->page_offset,
513 sk_frag->size, PCI_DMA_TODEVICE);
514
515 MM_SetT3AddrHigh(paddr, hi_map);
516 pci_unmap_addr_set(((struct _UM_PACKET *) pPacket), map[frag],
517 hi_map);
518 pci_unmap_len_set(((struct _UM_PACKET *) pPacket),
519 map_len[frag], sk_frag->size);
520 *len = sk_frag->size;
521 }
522 #endif
523 }
524
525 #define BCM5700_PHY_LOCK(pUmDevice, flags) { \
526 spinlock_t *lock; \
527 if ((pUmDevice)->do_global_lock) { \
528 lock = &(pUmDevice)->global_lock; \
529 } \
530 else { \
531 lock = &(pUmDevice)->phy_lock; \
532 } \
533 spin_lock_irqsave(lock, flags); \
534 }
535
536 #define BCM5700_PHY_UNLOCK(pUmDevice, flags) { \
537 spinlock_t *lock; \
538 if ((pUmDevice)->do_global_lock) { \
539 lock = &(pUmDevice)->global_lock; \
540 } \
541 else { \
542 lock = &(pUmDevice)->phy_lock; \
543 } \
544 spin_unlock_irqrestore(lock, flags); \
545 }
546
547
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; \
553 }
554
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); \
559 }
560
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); \
564 }
565
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); \
569 }
570
571 #define MM_UINT_PTR(_ptr) ((unsigned long) (_ptr))
572
573 #define MM_GETSTATS64(_Ctr) \
574 (uint64_t) (_Ctr).Low + ((uint64_t) (_Ctr).High << 32)
575
576 #define MM_GETSTATS32(_Ctr) \
577 (uint32_t) (_Ctr).Low
578
579 #if BITS_PER_LONG == 64
580 #define MM_GETSTATS(_Ctr) (unsigned long) MM_GETSTATS64(_Ctr)
581 #else
582 #define MM_GETSTATS(_Ctr) (unsigned long) MM_GETSTATS32(_Ctr)
583 #endif
584
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)))
590 #else
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))
595 #endif
596
597 #ifndef printf
598 #define printf(fmt, args...) printk(KERN_WARNING fmt, ##args)
599 #endif
600
601 #define DbgPrint(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
602 #if defined(CONFIG_X86)
603 #define DbgBreakPoint() __asm__("int $129")
604 #else
605 #define DbgBreakPoint()
606 #endif
607 #define MM_Wait(time) udelay(time)
608
609 #endif
This page took 0.079596 seconds and 5 git commands to generate.