atl1.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
  3. * Copyright(c) 2006 Chris Snook <csnook@redhat.com>
  4. * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com>
  5. *
  6. * Derived from Intel e1000 driver
  7. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program; if not, write to the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #ifndef _ATL1_H_
  24. #define _ATL1_H_
  25. #include <linux/types.h>
  26. #include <linux/if_vlan.h>
  27. #include "atl1_hw.h"
  28. /* function prototypes needed by multiple files */
  29. s32 atl1_up(struct atl1_adapter *adapter);
  30. void atl1_down(struct atl1_adapter *adapter);
  31. int atl1_reset(struct atl1_adapter *adapter);
  32. s32 atl1_setup_ring_resources(struct atl1_adapter *adapter);
  33. void atl1_free_ring_resources(struct atl1_adapter *adapter);
  34. extern char atl1_driver_name[];
  35. extern char atl1_driver_version[];
  36. extern const struct ethtool_ops atl1_ethtool_ops;
  37. struct atl1_adapter;
  38. #define ATL1_MAX_INTR 3
  39. #define ATL1_MAX_TX_BUF_LEN 0x3000 /* 12288 bytes */
  40. #define ATL1_DEFAULT_TPD 256
  41. #define ATL1_MAX_TPD 1024
  42. #define ATL1_MIN_TPD 64
  43. #define ATL1_DEFAULT_RFD 512
  44. #define ATL1_MIN_RFD 128
  45. #define ATL1_MAX_RFD 2048
  46. #define ATL1_GET_DESC(R, i, type) (&(((type *)((R)->desc))[i]))
  47. #define ATL1_RFD_DESC(R, i) ATL1_GET_DESC(R, i, struct rx_free_desc)
  48. #define ATL1_TPD_DESC(R, i) ATL1_GET_DESC(R, i, struct tx_packet_desc)
  49. #define ATL1_RRD_DESC(R, i) ATL1_GET_DESC(R, i, struct rx_return_desc)
  50. /*
  51. * This detached comment is preserved for documentation purposes only.
  52. * It was originally attached to some code that got deleted, but seems
  53. * important enough to keep around...
  54. *
  55. * <begin detached comment>
  56. * Some workarounds require millisecond delays and are run during interrupt
  57. * context. Most notably, when establishing link, the phy may need tweaking
  58. * but cannot process phy register reads/writes faster than millisecond
  59. * intervals...and we establish link due to a "link status change" interrupt.
  60. * <end detached comment>
  61. */
  62. /*
  63. * atl1_ring_header represents a single, contiguous block of DMA space
  64. * mapped for the three descriptor rings (tpd, rfd, rrd) and the two
  65. * message blocks (cmb, smb) described below
  66. */
  67. struct atl1_ring_header {
  68. void *desc; /* virtual address */
  69. dma_addr_t dma; /* physical address*/
  70. unsigned int size; /* length in bytes */
  71. };
  72. /*
  73. * atl1_buffer is wrapper around a pointer to a socket buffer
  74. * so a DMA handle can be stored along with the skb
  75. */
  76. struct atl1_buffer {
  77. struct sk_buff *skb; /* socket buffer */
  78. u16 length; /* rx buffer length */
  79. u16 alloced; /* 1 if skb allocated */
  80. dma_addr_t dma;
  81. };
  82. /* transmit packet descriptor (tpd) ring */
  83. struct atl1_tpd_ring {
  84. void *desc; /* descriptor ring virtual address */
  85. dma_addr_t dma; /* descriptor ring physical address */
  86. u16 size; /* descriptor ring length in bytes */
  87. u16 count; /* number of descriptors in the ring */
  88. u16 hw_idx; /* hardware index */
  89. atomic_t next_to_clean;
  90. atomic_t next_to_use;
  91. struct atl1_buffer *buffer_info;
  92. };
  93. /* receive free descriptor (rfd) ring */
  94. struct atl1_rfd_ring {
  95. void *desc; /* descriptor ring virtual address */
  96. dma_addr_t dma; /* descriptor ring physical address */
  97. u16 size; /* descriptor ring length in bytes */
  98. u16 count; /* number of descriptors in the ring */
  99. atomic_t next_to_use;
  100. u16 next_to_clean;
  101. struct atl1_buffer *buffer_info;
  102. };
  103. /* receive return descriptor (rrd) ring */
  104. struct atl1_rrd_ring {
  105. void *desc; /* descriptor ring virtual address */
  106. dma_addr_t dma; /* descriptor ring physical address */
  107. unsigned int size; /* descriptor ring length in bytes */
  108. u16 count; /* number of descriptors in the ring */
  109. u16 next_to_use;
  110. atomic_t next_to_clean;
  111. };
  112. /* coalescing message block (cmb) */
  113. struct atl1_cmb {
  114. struct coals_msg_block *cmb;
  115. dma_addr_t dma;
  116. };
  117. /* statistics message block (smb) */
  118. struct atl1_smb {
  119. struct stats_msg_block *smb;
  120. dma_addr_t dma;
  121. };
  122. /* Statistics counters */
  123. struct atl1_sft_stats {
  124. u64 rx_packets;
  125. u64 tx_packets;
  126. u64 rx_bytes;
  127. u64 tx_bytes;
  128. u64 multicast;
  129. u64 collisions;
  130. u64 rx_errors;
  131. u64 rx_length_errors;
  132. u64 rx_crc_errors;
  133. u64 rx_frame_errors;
  134. u64 rx_fifo_errors;
  135. u64 rx_missed_errors;
  136. u64 tx_errors;
  137. u64 tx_fifo_errors;
  138. u64 tx_aborted_errors;
  139. u64 tx_window_errors;
  140. u64 tx_carrier_errors;
  141. u64 tx_pause; /* num pause packets transmitted. */
  142. u64 excecol; /* num tx packets w/ excessive collisions. */
  143. u64 deffer; /* num tx packets deferred */
  144. u64 scc; /* num packets subsequently transmitted
  145. * successfully w/ single prior collision. */
  146. u64 mcc; /* num packets subsequently transmitted
  147. * successfully w/ multiple prior collisions. */
  148. u64 latecol; /* num tx packets w/ late collisions. */
  149. u64 tx_underun; /* num tx packets aborted due to transmit
  150. * FIFO underrun, or TRD FIFO underrun */
  151. u64 tx_trunc; /* num tx packets truncated due to size
  152. * exceeding MTU, regardless whether truncated
  153. * by the chip or not. (The name doesn't really
  154. * reflect the meaning in this case.) */
  155. u64 rx_pause; /* num Pause packets received. */
  156. u64 rx_rrd_ov;
  157. u64 rx_trunc;
  158. };
  159. /* hardware structure */
  160. struct atl1_hw {
  161. u8 __iomem *hw_addr;
  162. struct atl1_adapter *back;
  163. enum atl1_dma_order dma_ord;
  164. enum atl1_dma_rcb rcb_value;
  165. enum atl1_dma_req_block dmar_block;
  166. enum atl1_dma_req_block dmaw_block;
  167. u8 preamble_len;
  168. u8 max_retry; /* Retransmission maximum, after which the
  169. * packet will be discarded */
  170. u8 jam_ipg; /* IPG to start JAM for collision based flow
  171. * control in half-duplex mode. In units of
  172. * 8-bit time */
  173. u8 ipgt; /* Desired back to back inter-packet gap.
  174. * The default is 96-bit time */
  175. u8 min_ifg; /* Minimum number of IFG to enforce in between
  176. * receive frames. Frame gap below such IFP
  177. * is dropped */
  178. u8 ipgr1; /* 64bit Carrier-Sense window */
  179. u8 ipgr2; /* 96-bit IPG window */
  180. u8 tpd_burst; /* Number of TPD to prefetch in cache-aligned
  181. * burst. Each TPD is 16 bytes long */
  182. u8 rfd_burst; /* Number of RFD to prefetch in cache-aligned
  183. * burst. Each RFD is 12 bytes long */
  184. u8 rfd_fetch_gap;
  185. u8 rrd_burst; /* Threshold number of RRDs that can be retired
  186. * in a burst. Each RRD is 16 bytes long */
  187. u8 tpd_fetch_th;
  188. u8 tpd_fetch_gap;
  189. u16 tx_jumbo_task_th;
  190. u16 txf_burst; /* Number of data bytes to read in a cache-
  191. * aligned burst. Each SRAM entry is 8 bytes */
  192. u16 rx_jumbo_th; /* Jumbo packet size for non-VLAN packet. VLAN
  193. * packets should add 4 bytes */
  194. u16 rx_jumbo_lkah;
  195. u16 rrd_ret_timer; /* RRD retirement timer. Decrement by 1 after
  196. * every 512ns passes. */
  197. u16 lcol; /* Collision Window */
  198. u16 cmb_tpd;
  199. u16 cmb_rrd;
  200. u16 cmb_rx_timer;
  201. u16 cmb_tx_timer;
  202. u32 smb_timer;
  203. u16 media_type;
  204. u16 autoneg_advertised;
  205. u16 mii_autoneg_adv_reg;
  206. u16 mii_1000t_ctrl_reg;
  207. u32 max_frame_size;
  208. u32 min_frame_size;
  209. u16 dev_rev;
  210. /* spi flash */
  211. u8 flash_vendor;
  212. u8 mac_addr[ETH_ALEN];
  213. u8 perm_mac_addr[ETH_ALEN];
  214. bool phy_configured;
  215. };
  216. struct atl1_adapter {
  217. struct net_device *netdev;
  218. struct pci_dev *pdev;
  219. struct net_device_stats net_stats;
  220. struct atl1_sft_stats soft_stats;
  221. struct vlan_group *vlgrp;
  222. u32 rx_buffer_len;
  223. u32 wol;
  224. u16 link_speed;
  225. u16 link_duplex;
  226. spinlock_t lock;
  227. struct work_struct tx_timeout_task;
  228. struct work_struct link_chg_task;
  229. struct work_struct pcie_dma_to_rst_task;
  230. struct timer_list watchdog_timer;
  231. struct timer_list phy_config_timer;
  232. bool phy_timer_pending;
  233. /* all descriptor rings' memory */
  234. struct atl1_ring_header ring_header;
  235. /* TX */
  236. struct atl1_tpd_ring tpd_ring;
  237. spinlock_t mb_lock;
  238. /* RX */
  239. struct atl1_rfd_ring rfd_ring;
  240. struct atl1_rrd_ring rrd_ring;
  241. u64 hw_csum_err;
  242. u64 hw_csum_good;
  243. u16 imt; /* interrupt moderator timer (2us resolution */
  244. u16 ict; /* interrupt clear timer (2us resolution */
  245. struct mii_if_info mii; /* MII interface info */
  246. /* structs defined in atl1_hw.h */
  247. u32 bd_number; /* board number */
  248. bool pci_using_64;
  249. struct atl1_hw hw;
  250. struct atl1_smb smb;
  251. struct atl1_cmb cmb;
  252. };
  253. #endif /* _ATL1_H_ */