am_net8218.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #ifndef __AM_NET_8218_H_
  2. #define __AM_NET_8218_H_
  3. #include <mach/am_regs.h>
  4. #include <mach/am_eth_reg.h>
  5. #include <linux/io.h>
  6. #include <plat/io.h>
  7. #include <linux/skbuff.h>
  8. /* */
  9. #define DMA_USE_SKB_BUF
  10. //#define DMA_USE_MALLOC_ADDR
  11. #define ETH_INTERRUPT (INT_ETHERNET)
  12. #define IO_WRITE32(val,addr) __raw_writel(val,addr)
  13. #define IO_READ32(addr) __raw_readl(addr)
  14. #define ETHBASE (IO_ETH_BASE)
  15. #define WRITE_PERIPHS_REG(v,addr) __raw_writel(v,addr)
  16. #define READ_PERIPHS_REG(addr) __raw_readl(addr)
  17. //#define USE_COHERENT_MEMORY
  18. #ifndef USE_COHERENT_MEMORY
  19. #define CACHE_WSYNC(addr,size) __dma_single_cpu_to_dev((const void *)addr,(size_t)size-1,DMA_TO_DEVICE)
  20. #define CACHE_RSYNC(addr,size) __dma_single_dev_to_cpu((const void *)addr,(size_t)size-1,DMA_FROM_DEVICE)
  21. #else
  22. #define CACHE_WSYNC(addr,size)
  23. #define CACHE_RSYNC(addr,size)
  24. #endif
  25. //ring buf must less than the MAX alloc length 131072
  26. //131072/1536~=85;
  27. #define TX_RING_SIZE 64
  28. #define RX_RING_SIZE 64
  29. #define CACHE_LINE 32
  30. #define IS_CACHE_ALIGNED(x) (!((unsigned long )x &(CACHE_LINE-1)))
  31. #define CACHE_HEAD_ALIGNED(x) ((x-CACHE_LINE) & (~(CACHE_LINE-1)))
  32. #define CACHE_END_ALIGNED(x) ((x+CACHE_LINE) & (~(CACHE_LINE-1)))
  33. #define EEPROM_SIZE 8
  34. #define MII_CNT 1
  35. #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
  36. #define TX_TIMEOUT (HZ * 200 / 1000)
  37. #define ANOR_INTR_EN 1<<15
  38. #define TX_STOP_EN 1<<1
  39. #define TX_JABBER_TIMEOUT 1<<3
  40. #define RX_FIFO_OVER 1<<4
  41. #define TX_UNDERFLOW 1<<5
  42. #define RX_BUF_UN 1<<7
  43. #define RX_STOP_EN 1<<8
  44. #define RX_WATCH_TIMEOUT 1<<9
  45. #define EARLY_TX_INTR_EN 1<<10
  46. #define FATAL_BUS_ERROR 1<<13
  47. #define NOR_INTR_EN 1<<16
  48. #define TX_INTR_EN 1<<0
  49. #define TX_BUF_UN_EN 1<<2
  50. #define RX_INTR_EN 1<<6
  51. #define EARLY_RX_INTR_EN 1<<14
  52. enum mii_reg_bits {
  53. MDIO_ShiftClk = 0x10000, MDIO_DataIn = 0x80000, MDIO_DataOut = 0x20000,
  54. MDIO_EnbOutput = 0x40000, MDIO_EnbIn = 0x00000,
  55. };
  56. enum DmaDescriptorLength { /* length word of DMA descriptor */
  57. DescTxIntEnable = 0x80000000, /* Tx - interrupt on completion */
  58. DescTxLast = 0x40000000, /* Tx - Last segment of the frame */
  59. DescTxFirst = 0x20000000, /* Tx - First segment of the frame */
  60. DescTxDisableCrc = 0x04000000, /* Tx - Add CRC disabled (first segment only) */
  61. DescEndOfRing = 0x02000000, /* End of descriptors ring */
  62. DescChain = 0x01000000, /* Second buffer address is chain address */
  63. DescTxDisablePadd = 0x00800000, /* disable padding, added by - reyaz */
  64. DescSize2Mask = 0x003FF800, /* Buffer 2 size */
  65. DescSize2Shift = 11, DescSize1Mask = 0x000007FF, /* Buffer 1 size */
  66. DescSize1Shift = 0,
  67. };
  68. enum DmaDescriptorStatus { /* status word of DMA descriptor */
  69. DescOwnByDma = 0x80000000, /* Descriptor is owned by DMA engine */
  70. // CHANGED: Added on 07/29
  71. DescDAFilterFail = 0x40000000, /* Rx - DA Filter Fail for the received frame E */
  72. DescFrameLengthMask = 0x3FFF0000, /* Receive descriptor frame length */
  73. DescFrameLengthShift = 16, DescError = 0x00008000, /* Error summary bit - OR of the following bits: v */
  74. DescRxTruncated = 0x00004000, /* Rx - no more descriptors for receive frame E */
  75. // CHANGED: Added on 07/29
  76. DescSAFilterFail = 0x00002000, /* Rx - SA Filter Fail for the received frame E */
  77. /* added by reyaz */
  78. DescRxLengthError = 0x00001000, /* Rx - frame size not matching with length field E */
  79. DescRxDamaged = 0x00000800, /* Rx - frame was damaged due to buffer overflow E */
  80. // CHANGED: Added on 07/29
  81. DescRxVLANTag = 0x00000400, /* Rx - received frame is a VLAN frame I */
  82. DescRxFirst = 0x00000200, /* Rx - first descriptor of the frame I */
  83. DescRxLast = 0x00000100, /* Rx - last descriptor of the frame I */
  84. DescRxLongFrame = 0x00000080, /* Rx - frame is longer than 1518 bytes E */
  85. DescRxIPChecksumErr = 0x00000080, // IPC Checksum Error/Giant Frame
  86. DescRxCollision = 0x00000040, /* Rx - late collision occurred during reception E */
  87. DescRxFrameEther = 0x00000020, /* Rx - Frame type - Ethernet, otherwise 802.3 */
  88. DescRxWatchdog = 0x00000010, /* Rx - watchdog timer expired during reception E */
  89. DescRxMiiError = 0x00000008, /* Rx - error reported by MII interface E */
  90. DescRxDribbling = 0x00000004, /* Rx - frame contains noninteger multiple of 8 bits */
  91. DescRxCrc = 0x00000002, /* Rx - CRC error E */
  92. DescRxTCPChecksumErr = 0x00000001, // Payload Checksum Error
  93. DescTxTimeout = 0x00004000, /* Tx - Transmit jabber timeout E */
  94. // CHANGED: Added on 07/29
  95. DescTxFrameFlushed = 0x00002000, /* Tx - DMA/MTL flushed the frame due to SW flush I */
  96. DescTxLostCarrier = 0x00000800, /* Tx - carrier lost during tramsmission E */
  97. DescTxNoCarrier = 0x00000400, /* Tx - no carrier signal from the tranceiver E */
  98. DescTxLateCollision = 0x00000200, /* Tx - transmission aborted due to collision E */
  99. DescTxExcCollisions = 0x00000100, /* Tx - transmission aborted after 16 collisions E */
  100. DescTxVLANFrame = 0x00000080, /* Tx - VLAN-type frame */
  101. DescTxCollMask = 0x00000078, /* Tx - Collision count */
  102. DescTxCollShift = 3, DescTxExcDeferral = 0x00000004, /* Tx - excessive deferral E */
  103. DescTxUnderflow = 0x00000002, /* Tx - late data arrival from the memory E */
  104. DescTxDeferred = 0x00000001, /* Tx - frame transmision deferred */
  105. };
  106. struct _tx_desc {
  107. unsigned long status;
  108. unsigned long count;
  109. dma_addr_t buf_dma;
  110. struct _tx_desc *next_dma;
  111. //-------------------------
  112. struct sk_buff *skb;
  113. unsigned long buf;
  114. struct _tx_desc *next;
  115. unsigned long reverse[1];
  116. };
  117. struct _rx_desc {
  118. unsigned long status;
  119. unsigned long count;
  120. dma_addr_t buf_dma;
  121. struct _rx_desc *next_dma;
  122. //-------------------------
  123. struct sk_buff *skb;
  124. unsigned long buf;
  125. struct _rx_desc *next;
  126. unsigned long reverse[1];
  127. };
  128. #define PHY_SMSC_8700 0x7c0c4
  129. #define PHY_SMSC_8720 0x7c0f1
  130. #define PHY_ATHEROS_8032 0x004dd023
  131. struct am_net_private {
  132. struct _rx_desc *rx_ring;
  133. struct _rx_desc *rx_ring_dma;
  134. struct _tx_desc *tx_ring;
  135. struct _tx_desc *tx_ring_dma;
  136. struct _rx_desc *last_rx;
  137. struct _tx_desc *last_tx;
  138. struct _tx_desc *start_tx;
  139. struct net_device *dev;
  140. struct net_device_stats stats;
  141. struct timer_list timer; /* Media monitoring timer. */
  142. struct tasklet_struct rx_tasklet;
  143. int int_rx_tx;
  144. unsigned int irq_mask;
  145. /* Frequently used values: keep some adjacent for cache effect. */
  146. spinlock_t lock;
  147. unsigned int rx_buf_sz; /* Based on MTU+slack. */
  148. unsigned int tx_full; /* The Tx queue is full. */
  149. int first_tx;
  150. /* MII transceiver section. */
  151. int mii_cnt; /* MII device addresses. */
  152. unsigned char phys[MII_CNT]; /* MII device addresses, but only the first is used */
  153. int phy_Identifier;
  154. u32 mii;
  155. int phy_set[MII_CNT]; //save the latest phy_set;
  156. struct mii_if_info mii_if;
  157. unsigned long base_addr;
  158. };
  159. #endif /* */