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 241182 2011-02-17 21:50:03Z $ */ 14 15#ifndef MM_H 16#define MM_H 17 18#ifdef HNDCTF 19#include <ctf/hndctf.h> 20#endif /* HNDCTF */ 21 22#include <linux/config.h> 23 24#if defined(CONFIG_SMP) && !defined(__SMP__) 25#define __SMP__ 26#endif 27 28#if defined(CONFIG_MODVERSIONS) && defined(MODULE) && !defined(MODVERSIONS) 29#ifndef BCM_SMALL_DRV 30#define MODVERSIONS 31#endif 32#endif 33 34#ifndef B57UM 35#define __NO_VERSION__ 36#endif 37#include <linux/version.h> 38 39#ifdef MODULE 40 41#if defined(MODVERSIONS) && (LINUX_VERSION_CODE < 0x020500) 42#ifndef BCM_SMALL_DRV 43#include <linux/modversions.h> 44#endif 45#endif 46 47#if (LINUX_VERSION_CODE < 0x020605) 48#include <linux/module.h> 49#else 50#include <linux/moduleparam.h> 51#endif 52 53#else 54 55#define MOD_INC_USE_COUNT 56#define MOD_DEC_USE_COUNT 57#define SET_MODULE_OWNER(dev) 58#define MODULE_DEVICE_TABLE(pci, pci_tbl) 59#endif 60 61 62#include <linuxver.h> 63#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) 64#include <linux/utsrelease.h> 65#endif 66#include <linux/kernel.h> 67#include <linux/sched.h> 68#include <linux/string.h> 69#include <linux/timer.h> 70#include <linux/errno.h> 71#include <linux/ioport.h> 72#include <linux/slab.h> 73#include <linux/interrupt.h> 74#include <linux/pci.h> 75#include <linux/init.h> 76#include <linux/netdevice.h> 77#include <linux/etherdevice.h> 78#include <linux/skbuff.h> 79#include <linux/reboot.h> 80#include <asm/processor.h> /* Processor type for cache alignment. */ 81#include <asm/bitops.h> 82#include <asm/io.h> 83#include <asm/unaligned.h> 84#include <linux/delay.h> 85#include <asm/byteorder.h> 86#include <linux/time.h> 87#include <asm/uaccess.h> 88#if (LINUX_VERSION_CODE >= 0x020400) 89#if (LINUX_VERSION_CODE < 0x020500) 90#include <linux/wrapper.h> 91#endif 92#include <linux/ethtool.h> 93#endif 94#ifdef CONFIG_PROC_FS 95#include <linux/smp_lock.h> 96#include <linux/proc_fs.h> 97#define BCM_PROC_FS 1 98#endif 99#ifdef NETIF_F_HW_VLAN_TX 100#include <linux/if_vlan.h> 101#define BCM_VLAN 1 102#endif 103#ifdef NETIF_F_TSO 104#define BCM_TSO 1 105#define INCLUDE_TCP_SEG_SUPPORT 1 106#include <net/ip.h> 107#include <net/tcp.h> 108#include <net/checksum.h> 109#endif 110 111#ifndef LINUX_KERNEL_VERSION 112#define LINUX_KERNEL_VERSION 0 113#endif 114 115#ifndef MAX_SKB_FRAGS 116#define MAX_SKB_FRAGS 0 117#endif 118 119#if (LINUX_VERSION_CODE >= 0x020400) 120#ifndef ETHTOOL_GEEPROM 121 122#define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */ 123#define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data */ 124 125/* for passing EEPROM chunks */ 126struct ethtool_eeprom { 127 u32 cmd; 128 u32 magic; 129 u32 offset; /* in bytes */ 130 u32 len; /* in bytes */ 131 u8 data[0]; 132}; 133#define BCM_EEDUMP_LEN(info_p, size) *((u32 *) &((info_p)->reserved1[24]))=size 134 135#else 136 137#define BCM_EEDUMP_LEN(info_p, size) (info_p)->eedump_len=size 138 139#endif 140#endif 141 142#define BCM_INT_COAL 1 143#define BCM_NIC_SEND_BD 1 144#define BCM_ASF 1 145#define BCM_WOL 1 146#define BCM_TASKLET 1 147 148#if HAVE_NETIF_RECEIVE_SKB 149#define BCM_NAPI_RXPOLL 1 150#undef BCM_TASKLET 151#endif 152 153#if defined(CONFIG_PPC64) 154#define BCM_DISCONNECT_AT_CACHELINE 1 155#endif 156 157#ifdef BCM_SMALL_DRV 158#undef BCM_PROC_FS 159#undef ETHTOOL_GEEPROM 160#undef ETHTOOL_SEEPROM 161#undef ETHTOOL_GREGS 162#undef ETHTOOL_GPAUSEPARAM 163#undef ETHTOOL_GRXCSUM 164#undef ETHTOOL_TEST 165#undef BCM_INT_COAL 166#undef BCM_NIC_SEND_BD 167#undef BCM_WOL 168#undef NICE_SUPPORT 169#undef BCM_TASKLET 170#undef BCM_TSO 171#endif 172 173#ifdef __BIG_ENDIAN 174#define BIG_ENDIAN_HOST 1 175#endif 176 177#define MM_SWAP_LE32(x) cpu_to_le32(x) 178#define MM_SWAP_BE32(x) cpu_to_be32(x) 179 180#if (LINUX_VERSION_CODE < 0x020327) 181#define __raw_readl readl 182#define __raw_writel writel 183#endif 184 185#define MM_MEMWRITEL(ptr, val) __raw_writel(val, ptr) 186#define MM_MEMREADL(ptr) __raw_readl(ptr) 187 188typedef atomic_t MM_ATOMIC_T; 189 190#define MM_ATOMIC_SET(ptr, val) atomic_set(ptr, val) 191#define MM_ATOMIC_READ(ptr) atomic_read(ptr) 192#define MM_ATOMIC_INC(ptr) atomic_inc(ptr) 193#define MM_ATOMIC_ADD(ptr, val) atomic_add(val, ptr) 194#define MM_ATOMIC_DEC(ptr) atomic_dec(ptr) 195#define MM_ATOMIC_SUB(ptr, val) atomic_sub(val, ptr) 196 197 198#ifndef mmiowb 199#define mmiowb() 200#endif 201 202 203#define MM_MB() mb() 204#define MM_WMB() wmb() 205#define MM_RMB() rmb() 206#define MM_MMIOWB() mmiowb() 207 208#include "lm.h" 209#include "queue.h" 210#include "tigon3.h" 211 212#if DBG 213#define STATIC 214#else 215#define STATIC static 216#endif 217 218extern int MM_Packet_Desc_Size; 219 220#define MM_PACKET_DESC_SIZE MM_Packet_Desc_Size 221 222DECLARE_QUEUE_TYPE(UM_RX_PACKET_Q, MAX_RX_PACKET_DESC_COUNT+1); 223 224#define MAX_MEM 16 225#define MAX_MEM2 4 226 227#if (LINUX_VERSION_CODE < 0x020211) 228typedef u32 dma_addr_t; 229#endif 230 231#if (LINUX_VERSION_CODE < 0x02032a) 232#define pci_map_single(dev, address, size, dir) virt_to_bus(address) 233#define pci_unmap_single(dev, dma_addr, size, dir) 234#endif 235 236#if MAX_SKB_FRAGS 237#if (LINUX_VERSION_CODE >= 0x02040d) 238 239typedef dma_addr_t dmaaddr_high_t; 240 241#else 242 243#if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && !defined(CONFIG_X86_64) 244 245#if defined(CONFIG_HIGHMEM64G) 246typedef unsigned long long dmaaddr_high_t; 247#else 248typedef dma_addr_t dmaaddr_high_t; 249#endif 250 251#ifndef pci_map_page 252#define pci_map_page bcm_pci_map_page 253#endif 254 255static inline dmaaddr_high_t 256bcm_pci_map_page(struct pci_dev *dev, struct page *page, 257 int offset, size_t size, int dir) 258{ 259 dmaaddr_high_t phys; 260 261 phys = (page-mem_map) * (dmaaddr_high_t) PAGE_SIZE + offset; 262 263 return phys; 264} 265 266#ifndef pci_unmap_page 267#define pci_unmap_page(dev, map, size, dir) 268#endif 269 270#else /* #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && ! defined(CONFIG_X86_64)*/ 271 272typedef dma_addr_t dmaaddr_high_t; 273 274/* Warning - This may not work for all architectures if HIGHMEM is defined */ 275 276#ifndef pci_map_page 277#define pci_map_page(dev, page, offset, size, dir) \ 278 pci_map_single(dev, page_address(page) + (offset), size, dir) 279#endif 280#ifndef pci_unmap_page 281#define pci_unmap_page(dev, map, size, dir) \ 282 pci_unmap_single(dev, map, size, dir) 283#endif 284 285#endif /* #if defined(CONFIG_HIGHMEM) && defined(CONFIG_X86) && ! defined(CONFIG_X86_64)*/ 286 287#endif /* #if (LINUX_VERSION_CODE >= 0x02040d)*/ 288#endif /* #if MAX_SKB_FRAGS*/ 289 290#if defined(CONFIG_X86) && !defined(CONFIG_X86_64) 291#define NO_PCI_UNMAP 1 292#endif 293 294#if (LINUX_VERSION_CODE < 0x020412) 295#if !defined(NO_PCI_UNMAP) 296#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME; 297#define DECLARE_PCI_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME; 298 299#define pci_unmap_addr(PTR, ADDR_NAME) \ 300 ((PTR)->ADDR_NAME) 301 302#define pci_unmap_len(PTR, LEN_NAME) \ 303 ((PTR)->LEN_NAME) 304 305#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) \ 306 (((PTR)->ADDR_NAME) = (VAL)) 307 308#define pci_unmap_len_set(PTR, LEN_NAME, VAL) \ 309 (((PTR)->LEN_NAME) = (VAL)) 310#else 311#define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME) 312#define DECLARE_PCI_UNMAP_LEN(ADDR_NAME) 313 314#define pci_unmap_addr(PTR, ADDR_NAME) 0 315#define pci_unmap_len(PTR, LEN_NAME) 0 316#define pci_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0) 317#define pci_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) 318#endif 319#endif 320 321#if (LINUX_VERSION_CODE < 0x02030e) 322#define net_device device 323#define netif_carrier_on(dev) 324#define netif_carrier_off(dev) 325#endif 326 327#if (LINUX_VERSION_CODE < 0x02032b) 328#define tasklet_struct tq_struct 329#endif 330 331typedef struct _UM_DEVICE_BLOCK { 332 LM_DEVICE_BLOCK lm_dev; 333 struct net_device *dev; 334 struct pci_dev *pdev; 335 struct net_device *next_module; 336 char *name; 337#ifdef BCM_PROC_FS 338 struct proc_dir_entry *pfs_entry; 339 char pfs_name[32]; 340#endif 341 void *mem_list[MAX_MEM]; 342 dma_addr_t dma_list[MAX_MEM]; 343 int mem_size_list[MAX_MEM]; 344 int mem_list_num; 345 346#ifdef NICE_SUPPORT 347 void *mem_list2[MAX_MEM2]; /* for diagnostics ioctl */ 348 dma_addr_t dma_list2[MAX_MEM2]; 349 __u64 cpu_pa_list2[MAX_MEM2]; 350 int mem_size_list2[MAX_MEM2]; 351#endif 352 int index; 353 int opened; 354 int suspended; 355 int using_dac; /* dual address cycle */ 356 int delayed_link_ind; /* Delay link status during initial load */ 357 int adapter_just_inited; /* the first few seconds after init. */ 358 int timer_interval; 359 int statstimer_interval; 360 int adaptive_expiry; 361 int crc_counter_expiry; 362 int poll_tbi_interval; 363 int poll_tbi_expiry; 364 int asf_heartbeat; 365 int tx_full; 366 int tx_queued; 367 int line_speed; /* in Mbps, 0 if link is down */ 368 UM_RX_PACKET_Q rx_out_of_buf_q; 369 int rx_out_of_buf; 370 int rx_buf_repl_thresh; 371 int rx_buf_repl_panic_thresh; 372 int rx_buf_repl_isr_limit; 373 int rx_buf_align; 374 struct timer_list timer; 375 struct timer_list statstimer; 376 int do_global_lock; 377 spinlock_t global_lock; 378 spinlock_t undi_lock; 379 spinlock_t phy_lock; 380 unsigned long undi_flags; 381 volatile unsigned long interrupt; 382 atomic_t intr_sem; 383 int tasklet_pending; 384 volatile unsigned long tasklet_busy; 385 struct tasklet_struct tasklet; 386 struct net_device_stats stats; 387#ifdef NICE_SUPPORT 388 void (*nice_rx)( struct sk_buff*, void* ); 389 void* nice_ctx; 390#endif /* NICE_SUPPORT */ 391 int intr_test; 392 int intr_test_result; 393#ifdef NETIF_F_HW_VLAN_TX 394 struct vlan_group *vlgrp; 395#endif 396 int vlan_tag_mode; /* Setting to allow ASF to work properly with */ 397 /* VLANs */ 398 #define VLAN_TAG_MODE_AUTO_STRIP 0 399 #define VLAN_TAG_MODE_NORMAL_STRIP 1 400 #define VLAN_TAG_MODE_FORCED_STRIP 2 401 402 /* Auto mode - VLAN TAGs are always stripped if ASF is enabled, */ 403 /* If ASF is not enabled, it will be in normal mode. */ 404 /* Normal mode - VLAN TAGs are stripped when VLANs are registered */ 405 /* Forced mode - VLAN TAGs are always stripped. */ 406 407 int adaptive_coalesce; 408 uint rx_last_cnt; 409 uint tx_last_cnt; 410 uint rx_curr_coalesce_frames; 411 uint rx_curr_coalesce_frames_intr; 412 uint rx_curr_coalesce_ticks; 413 uint tx_curr_coalesce_frames; 414#if TIGON3_DEBUG 415 unsigned long tx_zc_count; 416 unsigned long tx_chksum_count; 417 unsigned long tx_himem_count; 418 unsigned long rx_good_chksum_count; 419#endif 420 unsigned long rx_bad_chksum_count; 421#ifdef BCM_TSO 422 unsigned long tso_pkt_count; 423#endif 424 unsigned long rx_misc_errors; 425 uint64_t phy_crc_count; 426 unsigned int spurious_int; 427 428 void *sih; 429 unsigned long boardflags; 430 void *robo; 431 int qos; 432#ifdef HNDCTF 433 ctf_t *cih; 434 void *osh; 435#endif /* HNDCTF */ 436} UM_DEVICE_BLOCK, *PUM_DEVICE_BLOCK; 437 438typedef struct _UM_PACKET { 439 LM_PACKET lm_packet; 440 struct sk_buff *skbuff; 441#if MAX_SKB_FRAGS 442 DECLARE_PCI_UNMAP_ADDR(map[MAX_SKB_FRAGS + 1]) 443 DECLARE_PCI_UNMAP_LEN(map_len[MAX_SKB_FRAGS + 1]) 444#else 445 DECLARE_PCI_UNMAP_ADDR(map[1]) 446 DECLARE_PCI_UNMAP_LEN(map_len[1]) 447#endif 448} UM_PACKET, *PUM_PACKET; 449 450static inline void MM_SetAddr(LM_PHYSICAL_ADDRESS *paddr, dma_addr_t addr) 451{ 452#if (BITS_PER_LONG == 64) 453 paddr->High = ((unsigned long) addr) >> 32; 454 paddr->Low = ((unsigned long) addr) & 0xffffffff; 455#else 456 paddr->High = 0; 457 paddr->Low = (unsigned long) addr; 458#endif 459} 460 461static inline void MM_SetT3Addr(T3_64BIT_HOST_ADDR *paddr, dma_addr_t addr) 462{ 463#if (BITS_PER_LONG == 64) 464 paddr->High = ((unsigned long) addr) >> 32; 465 paddr->Low = ((unsigned long) addr) & 0xffffffff; 466#else 467 paddr->High = 0; 468 paddr->Low = (unsigned long) addr; 469#endif 470} 471 472#if MAX_SKB_FRAGS 473static inline void MM_SetT3AddrHigh(T3_64BIT_HOST_ADDR *paddr, 474 dmaaddr_high_t addr) 475{ 476#if defined(CONFIG_HIGHMEM64G) && defined(CONFIG_X86) && !defined(CONFIG_X86_64) 477 paddr->High = (unsigned long) (addr >> 32); 478 paddr->Low = (unsigned long) (addr & 0xffffffff); 479#else 480 MM_SetT3Addr(paddr, (dma_addr_t) addr); 481#endif 482} 483#endif 484 485static inline void MM_MapRxDma(PLM_DEVICE_BLOCK pDevice, 486 struct _LM_PACKET *pPacket, 487 T3_64BIT_HOST_ADDR *paddr) 488{ 489 dma_addr_t map; 490 struct sk_buff *skb = ((struct _UM_PACKET *) pPacket)->skbuff; 491 492 map = pci_map_single(((struct _UM_DEVICE_BLOCK *)pDevice)->pdev, 493 skb->tail, 494 pPacket->u.Rx.RxBufferSize, 495 PCI_DMA_FROMDEVICE); 496 pci_unmap_addr_set(((struct _UM_PACKET *) pPacket), map[0], map); 497 MM_SetT3Addr(paddr, map); 498} 499 500static inline void MM_MapTxDma(PLM_DEVICE_BLOCK pDevice, 501 struct _LM_PACKET *pPacket, 502 T3_64BIT_HOST_ADDR *paddr, 503 LM_UINT32 *len, 504 int frag) 505{ 506 dma_addr_t map; 507 struct sk_buff *skb = ((struct _UM_PACKET *) pPacket)->skbuff; 508 unsigned int length; 509 510 if (frag == 0) { 511#if MAX_SKB_FRAGS 512 if (skb_shinfo(skb)->nr_frags) 513 length = skb->len - skb->data_len; 514 else 515#endif 516 length = skb->len; 517 map = pci_map_single(((struct _UM_DEVICE_BLOCK *)pDevice)->pdev, 518 skb->data, length, PCI_DMA_TODEVICE); 519 MM_SetT3Addr(paddr, map); 520 pci_unmap_addr_set(((struct _UM_PACKET *)pPacket), map[0], map); 521 pci_unmap_len_set(((struct _UM_PACKET *) pPacket), map_len[0], 522 length); 523 *len = length; 524 } 525#if MAX_SKB_FRAGS 526 else { 527 skb_frag_t *sk_frag; 528 dmaaddr_high_t hi_map; 529 530 sk_frag = &skb_shinfo(skb)->frags[frag - 1]; 531 532 hi_map = pci_map_page( 533 ((struct _UM_DEVICE_BLOCK *)pDevice)->pdev, 534 sk_frag->page, 535 sk_frag->page_offset, 536 sk_frag->size, PCI_DMA_TODEVICE); 537 538 MM_SetT3AddrHigh(paddr, hi_map); 539 pci_unmap_addr_set(((struct _UM_PACKET *) pPacket), map[frag], 540 hi_map); 541 pci_unmap_len_set(((struct _UM_PACKET *) pPacket), 542 map_len[frag], sk_frag->size); 543 *len = sk_frag->size; 544 } 545#endif 546} 547 548#define BCM5700_PHY_LOCK(pUmDevice, flags) { \ 549 spinlock_t *lock; \ 550 if ((pUmDevice)->do_global_lock) { \ 551 lock = &(pUmDevice)->global_lock; \ 552 } \ 553 else { \ 554 lock = &(pUmDevice)->phy_lock; \ 555 } \ 556 spin_lock_irqsave(lock, flags); \ 557} 558 559#define BCM5700_PHY_UNLOCK(pUmDevice, flags) { \ 560 spinlock_t *lock; \ 561 if ((pUmDevice)->do_global_lock) { \ 562 lock = &(pUmDevice)->global_lock; \ 563 } \ 564 else { \ 565 lock = &(pUmDevice)->phy_lock; \ 566 } \ 567 spin_unlock_irqrestore(lock, flags); \ 568} 569 570 571#define MM_ACQUIRE_UNDI_LOCK(_pDevice) \ 572 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \ 573 unsigned long flags; \ 574 spin_lock_irqsave(&((PUM_DEVICE_BLOCK)(_pDevice))->undi_lock, flags); \ 575 ((PUM_DEVICE_BLOCK)(_pDevice))->undi_flags = flags; \ 576 } 577 578#define MM_RELEASE_UNDI_LOCK(_pDevice) \ 579 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \ 580 unsigned long flags = ((PUM_DEVICE_BLOCK) (_pDevice))->undi_flags; \ 581 spin_unlock_irqrestore(&((PUM_DEVICE_BLOCK)(_pDevice))->undi_lock, flags); \ 582 } 583 584#define MM_ACQUIRE_PHY_LOCK_IN_IRQ(_pDevice) \ 585 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \ 586 spin_lock(&((PUM_DEVICE_BLOCK)(_pDevice))->phy_lock); \ 587 } 588 589#define MM_RELEASE_PHY_LOCK_IN_IRQ(_pDevice) \ 590 if (!(((PUM_DEVICE_BLOCK)(_pDevice))->do_global_lock)) { \ 591 spin_unlock(&((PUM_DEVICE_BLOCK)(_pDevice))->phy_lock); \ 592 } 593 594#define MM_UINT_PTR(_ptr) ((unsigned long) (_ptr)) 595 596#define MM_GETSTATS64(_Ctr) \ 597 (uint64_t) (_Ctr).Low + ((uint64_t) (_Ctr).High << 32) 598 599#define MM_GETSTATS32(_Ctr) \ 600 (uint32_t) (_Ctr).Low 601 602#if (BITS_PER_LONG == 64) 603#define MM_GETSTATS(_Ctr) (unsigned long) MM_GETSTATS64(_Ctr) 604#else 605#define MM_GETSTATS(_Ctr) (unsigned long) MM_GETSTATS32(_Ctr) 606#endif 607 608#if (LINUX_VERSION_CODE >= 0x020600) 609#define mm_copy_to_user( to, from, size ) \ 610 (in_atomic() ? (memcpy((to),(from),(size)), 0) : copy_to_user((to),(from),(size))) 611#define mm_copy_from_user( to, from, size ) \ 612 (in_atomic() ? (memcpy((to),(from),(size)), 0) : copy_from_user((to),(from),(size))) 613#else 614#define mm_copy_to_user( to, from, size ) \ 615 copy_to_user((to),(from),(size) ) 616#define mm_copy_from_user( to, from, size ) \ 617 copy_from_user((to),(from),(size)) 618#endif 619 620#ifndef printf 621#define printf(fmt, args...) printk(KERN_WARNING fmt, ##args) 622#endif 623 624#define DbgPrint(fmt, arg...) printk(KERN_DEBUG fmt, ##arg) 625#if defined(CONFIG_X86) 626#define DbgBreakPoint() __asm__("int $129") 627#else 628#define DbgBreakPoint() 629#endif 630#define MM_Wait(time) udelay(time) 631 632#endif 633