atl1c.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright(c) 2008 - 2009 Atheros Corporation. All rights reserved.
  4. *
  5. * Derived from Intel e1000 driver
  6. * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
  7. */
  8. #ifndef _ATL1C_H_
  9. #define _ATL1C_H_
  10. #include <linux/interrupt.h>
  11. #include <linux/types.h>
  12. #include <linux/errno.h>
  13. #include <linux/module.h>
  14. #include <linux/pci.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/ioport.h>
  19. #include <linux/slab.h>
  20. #include <linux/list.h>
  21. #include <linux/delay.h>
  22. #include <linux/sched.h>
  23. #include <linux/in.h>
  24. #include <linux/ip.h>
  25. #include <linux/ipv6.h>
  26. #include <linux/udp.h>
  27. #include <linux/mii.h>
  28. #include <linux/io.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/pagemap.h>
  31. #include <linux/tcp.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/if_vlan.h>
  34. #include <linux/workqueue.h>
  35. #include <net/checksum.h>
  36. #include <net/ip6_checksum.h>
  37. #include "atl1c_hw.h"
  38. /* Wake Up Filter Control */
  39. #define AT_WUFC_LNKC 0x00000001 /* Link Status Change Wakeup Enable */
  40. #define AT_WUFC_MAG 0x00000002 /* Magic Packet Wakeup Enable */
  41. #define AT_WUFC_EX 0x00000004 /* Directed Exact Wakeup Enable */
  42. #define AT_WUFC_MC 0x00000008 /* Multicast Wakeup Enable */
  43. #define AT_WUFC_BC 0x00000010 /* Broadcast Wakeup Enable */
  44. #define AT_VLAN_TO_TAG(_vlan, _tag) \
  45. _tag = ((((_vlan) >> 8) & 0xFF) |\
  46. (((_vlan) & 0xFF) << 8))
  47. #define AT_TAG_TO_VLAN(_tag, _vlan) \
  48. _vlan = ((((_tag) >> 8) & 0xFF) |\
  49. (((_tag) & 0xFF) << 8))
  50. #define SPEED_0 0xffff
  51. #define HALF_DUPLEX 1
  52. #define FULL_DUPLEX 2
  53. #define AT_RX_BUF_SIZE (ETH_FRAME_LEN + VLAN_HLEN + ETH_FCS_LEN)
  54. #define MAX_JUMBO_FRAME_SIZE (6*1024)
  55. #define AT_MAX_RECEIVE_QUEUE 4
  56. #define AT_DEF_RECEIVE_QUEUE 1
  57. #define AT_MAX_TRANSMIT_QUEUE 4
  58. #define AT_DMA_HI_ADDR_MASK 0xffffffff00000000ULL
  59. #define AT_DMA_LO_ADDR_MASK 0x00000000ffffffffULL
  60. #define AT_TX_WATCHDOG (5 * HZ)
  61. #define AT_MAX_INT_WORK 5
  62. #define AT_TWSI_EEPROM_TIMEOUT 100
  63. #define AT_HW_MAX_IDLE_DELAY 10
  64. #define AT_SUSPEND_LINK_TIMEOUT 100
  65. #define AT_ASPM_L0S_TIMER 6
  66. #define AT_ASPM_L1_TIMER 12
  67. #define AT_LCKDET_TIMER 12
  68. #define ATL1C_PCIE_L0S_L1_DISABLE 0x01
  69. #define ATL1C_PCIE_PHY_RESET 0x02
  70. #define ATL1C_ASPM_L0s_ENABLE 0x0001
  71. #define ATL1C_ASPM_L1_ENABLE 0x0002
  72. #define AT_REGS_LEN (74 * sizeof(u32))
  73. #define AT_EEPROM_LEN 512
  74. #define ATL1C_GET_DESC(R, i, type) (&(((type *)((R)->desc))[i]))
  75. #define ATL1C_RFD_DESC(R, i) ATL1C_GET_DESC(R, i, struct atl1c_rx_free_desc)
  76. #define ATL1C_TPD_DESC(R, i) ATL1C_GET_DESC(R, i, struct atl1c_tpd_desc)
  77. #define ATL1C_RRD_DESC(R, i) ATL1C_GET_DESC(R, i, struct atl1c_recv_ret_status)
  78. /* tpd word 1 bit 0:7 General Checksum task offload */
  79. #define TPD_L4HDR_OFFSET_MASK 0x00FF
  80. #define TPD_L4HDR_OFFSET_SHIFT 0
  81. /* tpd word 1 bit 0:7 Large Send task offload (IPv4/IPV6) */
  82. #define TPD_TCPHDR_OFFSET_MASK 0x00FF
  83. #define TPD_TCPHDR_OFFSET_SHIFT 0
  84. /* tpd word 1 bit 0:7 Custom Checksum task offload */
  85. #define TPD_PLOADOFFSET_MASK 0x00FF
  86. #define TPD_PLOADOFFSET_SHIFT 0
  87. /* tpd word 1 bit 8:17 */
  88. #define TPD_CCSUM_EN_MASK 0x0001
  89. #define TPD_CCSUM_EN_SHIFT 8
  90. #define TPD_IP_CSUM_MASK 0x0001
  91. #define TPD_IP_CSUM_SHIFT 9
  92. #define TPD_TCP_CSUM_MASK 0x0001
  93. #define TPD_TCP_CSUM_SHIFT 10
  94. #define TPD_UDP_CSUM_MASK 0x0001
  95. #define TPD_UDP_CSUM_SHIFT 11
  96. #define TPD_LSO_EN_MASK 0x0001 /* TCP Large Send Offload */
  97. #define TPD_LSO_EN_SHIFT 12
  98. #define TPD_LSO_VER_MASK 0x0001
  99. #define TPD_LSO_VER_SHIFT 13 /* 0 : ipv4; 1 : ipv4/ipv6 */
  100. #define TPD_CON_VTAG_MASK 0x0001
  101. #define TPD_CON_VTAG_SHIFT 14
  102. #define TPD_INS_VTAG_MASK 0x0001
  103. #define TPD_INS_VTAG_SHIFT 15
  104. #define TPD_IPV4_PACKET_MASK 0x0001 /* valid when LSO VER is 1 */
  105. #define TPD_IPV4_PACKET_SHIFT 16
  106. #define TPD_ETH_TYPE_MASK 0x0001
  107. #define TPD_ETH_TYPE_SHIFT 17 /* 0 : 802.3 frame; 1 : Ethernet */
  108. /* tpd word 18:25 Custom Checksum task offload */
  109. #define TPD_CCSUM_OFFSET_MASK 0x00FF
  110. #define TPD_CCSUM_OFFSET_SHIFT 18
  111. #define TPD_CCSUM_EPAD_MASK 0x0001
  112. #define TPD_CCSUM_EPAD_SHIFT 30
  113. /* tpd word 18:30 Large Send task offload (IPv4/IPV6) */
  114. #define TPD_MSS_MASK 0x1FFF
  115. #define TPD_MSS_SHIFT 18
  116. #define TPD_EOP_MASK 0x0001
  117. #define TPD_EOP_SHIFT 31
  118. struct atl1c_tpd_desc {
  119. __le16 buffer_len; /* include 4-byte CRC */
  120. __le16 vlan_tag;
  121. __le32 word1;
  122. __le64 buffer_addr;
  123. };
  124. struct atl1c_tpd_ext_desc {
  125. u32 reservd_0;
  126. __le32 word1;
  127. __le32 pkt_len;
  128. u32 reservd_1;
  129. };
  130. /* rrs word 0 bit 0:31 */
  131. #define RRS_RX_CSUM_MASK 0xFFFF
  132. #define RRS_RX_CSUM_SHIFT 0
  133. #define RRS_RX_RFD_CNT_MASK 0x000F
  134. #define RRS_RX_RFD_CNT_SHIFT 16
  135. #define RRS_RX_RFD_INDEX_MASK 0x0FFF
  136. #define RRS_RX_RFD_INDEX_SHIFT 20
  137. /* rrs flag bit 0:16 */
  138. #define RRS_HEAD_LEN_MASK 0x00FF
  139. #define RRS_HEAD_LEN_SHIFT 0
  140. #define RRS_HDS_TYPE_MASK 0x0003
  141. #define RRS_HDS_TYPE_SHIFT 8
  142. #define RRS_CPU_NUM_MASK 0x0003
  143. #define RRS_CPU_NUM_SHIFT 10
  144. #define RRS_HASH_FLG_MASK 0x000F
  145. #define RRS_HASH_FLG_SHIFT 12
  146. #define RRS_HDS_TYPE_HEAD 1
  147. #define RRS_HDS_TYPE_DATA 2
  148. #define RRS_IS_NO_HDS_TYPE(flag) \
  149. ((((flag) >> (RRS_HDS_TYPE_SHIFT)) & RRS_HDS_TYPE_MASK) == 0)
  150. #define RRS_IS_HDS_HEAD(flag) \
  151. ((((flag) >> (RRS_HDS_TYPE_SHIFT)) & RRS_HDS_TYPE_MASK) == \
  152. RRS_HDS_TYPE_HEAD)
  153. #define RRS_IS_HDS_DATA(flag) \
  154. ((((flag) >> (RRS_HDS_TYPE_SHIFT)) & RRS_HDS_TYPE_MASK) == \
  155. RRS_HDS_TYPE_DATA)
  156. /* rrs word 3 bit 0:31 */
  157. #define RRS_PKT_SIZE_MASK 0x3FFF
  158. #define RRS_PKT_SIZE_SHIFT 0
  159. #define RRS_ERR_L4_CSUM_MASK 0x0001
  160. #define RRS_ERR_L4_CSUM_SHIFT 14
  161. #define RRS_ERR_IP_CSUM_MASK 0x0001
  162. #define RRS_ERR_IP_CSUM_SHIFT 15
  163. #define RRS_VLAN_INS_MASK 0x0001
  164. #define RRS_VLAN_INS_SHIFT 16
  165. #define RRS_PROT_ID_MASK 0x0007
  166. #define RRS_PROT_ID_SHIFT 17
  167. #define RRS_RX_ERR_SUM_MASK 0x0001
  168. #define RRS_RX_ERR_SUM_SHIFT 20
  169. #define RRS_RX_ERR_CRC_MASK 0x0001
  170. #define RRS_RX_ERR_CRC_SHIFT 21
  171. #define RRS_RX_ERR_FAE_MASK 0x0001
  172. #define RRS_RX_ERR_FAE_SHIFT 22
  173. #define RRS_RX_ERR_TRUNC_MASK 0x0001
  174. #define RRS_RX_ERR_TRUNC_SHIFT 23
  175. #define RRS_RX_ERR_RUNC_MASK 0x0001
  176. #define RRS_RX_ERR_RUNC_SHIFT 24
  177. #define RRS_RX_ERR_ICMP_MASK 0x0001
  178. #define RRS_RX_ERR_ICMP_SHIFT 25
  179. #define RRS_PACKET_BCAST_MASK 0x0001
  180. #define RRS_PACKET_BCAST_SHIFT 26
  181. #define RRS_PACKET_MCAST_MASK 0x0001
  182. #define RRS_PACKET_MCAST_SHIFT 27
  183. #define RRS_PACKET_TYPE_MASK 0x0001
  184. #define RRS_PACKET_TYPE_SHIFT 28
  185. #define RRS_FIFO_FULL_MASK 0x0001
  186. #define RRS_FIFO_FULL_SHIFT 29
  187. #define RRS_802_3_LEN_ERR_MASK 0x0001
  188. #define RRS_802_3_LEN_ERR_SHIFT 30
  189. #define RRS_RXD_UPDATED_MASK 0x0001
  190. #define RRS_RXD_UPDATED_SHIFT 31
  191. #define RRS_ERR_L4_CSUM 0x00004000
  192. #define RRS_ERR_IP_CSUM 0x00008000
  193. #define RRS_VLAN_INS 0x00010000
  194. #define RRS_RX_ERR_SUM 0x00100000
  195. #define RRS_RX_ERR_CRC 0x00200000
  196. #define RRS_802_3_LEN_ERR 0x40000000
  197. #define RRS_RXD_UPDATED 0x80000000
  198. #define RRS_PACKET_TYPE_802_3 1
  199. #define RRS_PACKET_TYPE_ETH 0
  200. #define RRS_PACKET_IS_ETH(word) \
  201. ((((word) >> RRS_PACKET_TYPE_SHIFT) & RRS_PACKET_TYPE_MASK) == \
  202. RRS_PACKET_TYPE_ETH)
  203. #define RRS_RXD_IS_VALID(word) \
  204. ((((word) >> RRS_RXD_UPDATED_SHIFT) & RRS_RXD_UPDATED_MASK) == 1)
  205. #define RRS_PACKET_PROT_IS_IPV4_ONLY(word) \
  206. ((((word) >> RRS_PROT_ID_SHIFT) & RRS_PROT_ID_MASK) == 1)
  207. #define RRS_PACKET_PROT_IS_IPV6_ONLY(word) \
  208. ((((word) >> RRS_PROT_ID_SHIFT) & RRS_PROT_ID_MASK) == 6)
  209. #define RRS_MT_PROT_ID_TCPUDP BIT(19)
  210. struct atl1c_recv_ret_status {
  211. __le32 word0;
  212. __le32 rss_hash;
  213. __le16 vlan_tag;
  214. __le16 flag;
  215. __le32 word3;
  216. };
  217. /* RFD descriptor */
  218. struct atl1c_rx_free_desc {
  219. __le64 buffer_addr;
  220. };
  221. /* DMA Order Settings */
  222. enum atl1c_dma_order {
  223. atl1c_dma_ord_in = 1,
  224. atl1c_dma_ord_enh = 2,
  225. atl1c_dma_ord_out = 4
  226. };
  227. enum atl1c_dma_rcb {
  228. atl1c_rcb_64 = 0,
  229. atl1c_rcb_128 = 1
  230. };
  231. enum atl1c_mac_speed {
  232. atl1c_mac_speed_0 = 0,
  233. atl1c_mac_speed_10_100 = 1,
  234. atl1c_mac_speed_1000 = 2
  235. };
  236. enum atl1c_dma_req_block {
  237. atl1c_dma_req_128 = 0,
  238. atl1c_dma_req_256 = 1,
  239. atl1c_dma_req_512 = 2,
  240. atl1c_dma_req_1024 = 3,
  241. atl1c_dma_req_2048 = 4,
  242. atl1c_dma_req_4096 = 5
  243. };
  244. enum atl1c_nic_type {
  245. athr_l1c = 0,
  246. athr_l2c = 1,
  247. athr_l2c_b,
  248. athr_l2c_b2,
  249. athr_l1d,
  250. athr_l1d_2,
  251. athr_mt,
  252. };
  253. struct atl1c_hw_stats {
  254. /* rx */
  255. unsigned long rx_ok; /* The number of good packet received. */
  256. unsigned long rx_bcast; /* The number of good broadcast packet received. */
  257. unsigned long rx_mcast; /* The number of good multicast packet received. */
  258. unsigned long rx_pause; /* The number of Pause packet received. */
  259. unsigned long rx_ctrl; /* The number of Control packet received other than Pause frame. */
  260. unsigned long rx_fcs_err; /* The number of packets with bad FCS. */
  261. unsigned long rx_len_err; /* The number of packets with mismatch of length field and actual size. */
  262. unsigned long rx_byte_cnt; /* The number of bytes of good packet received. FCS is NOT included. */
  263. unsigned long rx_runt; /* The number of packets received that are less than 64 byte long and with good FCS. */
  264. unsigned long rx_frag; /* The number of packets received that are less than 64 byte long and with bad FCS. */
  265. unsigned long rx_sz_64; /* The number of good and bad packets received that are 64 byte long. */
  266. unsigned long rx_sz_65_127; /* The number of good and bad packets received that are between 65 and 127-byte long. */
  267. unsigned long rx_sz_128_255; /* The number of good and bad packets received that are between 128 and 255-byte long. */
  268. unsigned long rx_sz_256_511; /* The number of good and bad packets received that are between 256 and 511-byte long. */
  269. unsigned long rx_sz_512_1023; /* The number of good and bad packets received that are between 512 and 1023-byte long. */
  270. unsigned long rx_sz_1024_1518; /* The number of good and bad packets received that are between 1024 and 1518-byte long. */
  271. unsigned long rx_sz_1519_max; /* The number of good and bad packets received that are between 1519-byte and MTU. */
  272. unsigned long rx_sz_ov; /* The number of good and bad packets received that are more than MTU size truncated by Selene. */
  273. unsigned long rx_rxf_ov; /* The number of frame dropped due to occurrence of RX FIFO overflow. */
  274. unsigned long rx_rrd_ov; /* The number of frame dropped due to occurrence of RRD overflow. */
  275. unsigned long rx_align_err; /* Alignment Error */
  276. unsigned long rx_bcast_byte_cnt; /* The byte count of broadcast packet received, excluding FCS. */
  277. unsigned long rx_mcast_byte_cnt; /* The byte count of multicast packet received, excluding FCS. */
  278. unsigned long rx_err_addr; /* The number of packets dropped due to address filtering. */
  279. /* tx */
  280. unsigned long tx_ok; /* The number of good packet transmitted. */
  281. unsigned long tx_bcast; /* The number of good broadcast packet transmitted. */
  282. unsigned long tx_mcast; /* The number of good multicast packet transmitted. */
  283. unsigned long tx_pause; /* The number of Pause packet transmitted. */
  284. unsigned long tx_exc_defer; /* The number of packets transmitted with excessive deferral. */
  285. unsigned long tx_ctrl; /* The number of packets transmitted is a control frame, excluding Pause frame. */
  286. unsigned long tx_defer; /* The number of packets transmitted that is deferred. */
  287. unsigned long tx_byte_cnt; /* The number of bytes of data transmitted. FCS is NOT included. */
  288. unsigned long tx_sz_64; /* The number of good and bad packets transmitted that are 64 byte long. */
  289. unsigned long tx_sz_65_127; /* The number of good and bad packets transmitted that are between 65 and 127-byte long. */
  290. unsigned long tx_sz_128_255; /* The number of good and bad packets transmitted that are between 128 and 255-byte long. */
  291. unsigned long tx_sz_256_511; /* The number of good and bad packets transmitted that are between 256 and 511-byte long. */
  292. unsigned long tx_sz_512_1023; /* The number of good and bad packets transmitted that are between 512 and 1023-byte long. */
  293. unsigned long tx_sz_1024_1518; /* The number of good and bad packets transmitted that are between 1024 and 1518-byte long. */
  294. unsigned long tx_sz_1519_max; /* The number of good and bad packets transmitted that are between 1519-byte and MTU. */
  295. unsigned long tx_1_col; /* The number of packets subsequently transmitted successfully with a single prior collision. */
  296. unsigned long tx_2_col; /* The number of packets subsequently transmitted successfully with multiple prior collisions. */
  297. unsigned long tx_late_col; /* The number of packets transmitted with late collisions. */
  298. unsigned long tx_abort_col; /* The number of transmit packets aborted due to excessive collisions. */
  299. unsigned long tx_underrun; /* The number of transmit packets aborted due to transmit FIFO underrun, or TRD FIFO underrun */
  300. unsigned long tx_rd_eop; /* The number of times that read beyond the EOP into the next frame area when TRD was not written timely */
  301. unsigned long tx_len_err; /* The number of transmit packets with length field does NOT match the actual frame size. */
  302. unsigned long tx_trunc; /* The number of transmit packets truncated due to size exceeding MTU. */
  303. unsigned long tx_bcast_byte; /* The byte count of broadcast packet transmitted, excluding FCS. */
  304. unsigned long tx_mcast_byte; /* The byte count of multicast packet transmitted, excluding FCS. */
  305. };
  306. struct atl1c_hw {
  307. u8 __iomem *hw_addr; /* inner register address */
  308. struct atl1c_adapter *adapter;
  309. enum atl1c_nic_type nic_type;
  310. enum atl1c_dma_order dma_order;
  311. enum atl1c_dma_rcb rcb_value;
  312. enum atl1c_dma_req_block dmar_block;
  313. u16 device_id;
  314. u16 vendor_id;
  315. u16 subsystem_id;
  316. u16 subsystem_vendor_id;
  317. u8 revision_id;
  318. u16 phy_id1;
  319. u16 phy_id2;
  320. spinlock_t intr_mask_lock; /* protect the intr_mask */
  321. u32 intr_mask;
  322. u8 preamble_len;
  323. u16 max_frame_size;
  324. u16 min_frame_size;
  325. enum atl1c_mac_speed mac_speed;
  326. bool mac_duplex;
  327. bool hibernate;
  328. u16 media_type;
  329. #define MEDIA_TYPE_AUTO_SENSOR 0
  330. #define MEDIA_TYPE_100M_FULL 1
  331. #define MEDIA_TYPE_100M_HALF 2
  332. #define MEDIA_TYPE_10M_FULL 3
  333. #define MEDIA_TYPE_10M_HALF 4
  334. u16 autoneg_advertised;
  335. u16 mii_autoneg_adv_reg;
  336. u16 mii_1000t_ctrl_reg;
  337. u16 tx_imt; /* TX Interrupt Moderator timer ( 2us resolution) */
  338. u16 rx_imt; /* RX Interrupt Moderator timer ( 2us resolution) */
  339. u16 ict; /* Interrupt Clear timer (2us resolution) */
  340. u16 ctrl_flags;
  341. #define ATL1C_INTR_CLEAR_ON_READ 0x0001
  342. #define ATL1C_INTR_MODRT_ENABLE 0x0002
  343. #define ATL1C_CMB_ENABLE 0x0004
  344. #define ATL1C_SMB_ENABLE 0x0010
  345. #define ATL1C_TXQ_MODE_ENHANCE 0x0020
  346. #define ATL1C_RX_IPV6_CHKSUM 0x0040
  347. #define ATL1C_ASPM_L0S_SUPPORT 0x0080
  348. #define ATL1C_ASPM_L1_SUPPORT 0x0100
  349. #define ATL1C_ASPM_CTRL_MON 0x0200
  350. #define ATL1C_HIB_DISABLE 0x0400
  351. #define ATL1C_APS_MODE_ENABLE 0x0800
  352. #define ATL1C_LINK_EXT_SYNC 0x1000
  353. #define ATL1C_CLK_GATING_EN 0x2000
  354. #define ATL1C_FPGA_VERSION 0x8000
  355. u16 link_cap_flags;
  356. #define ATL1C_LINK_CAP_1000M 0x0001
  357. u32 smb_timer;
  358. u16 rrd_thresh; /* Threshold of number of RRD produced to trigger
  359. interrupt request */
  360. u16 tpd_thresh;
  361. u8 tpd_burst; /* Number of TPD to prefetch in cache-aligned burst. */
  362. u8 rfd_burst;
  363. u32 base_cpu;
  364. u32 indirect_tab;
  365. u8 mac_addr[ETH_ALEN];
  366. u8 perm_mac_addr[ETH_ALEN];
  367. bool phy_configured;
  368. bool re_autoneg;
  369. bool emi_ca;
  370. bool msi_lnkpatch; /* link patch for specific platforms */
  371. };
  372. /*
  373. * atl1c_ring_header represents a single, contiguous block of DMA space
  374. * mapped for the three descriptor rings (tpd, rfd, rrd) described below
  375. */
  376. struct atl1c_ring_header {
  377. void *desc; /* virtual address */
  378. dma_addr_t dma; /* physical address*/
  379. unsigned int size; /* length in bytes */
  380. };
  381. /*
  382. * atl1c_buffer is wrapper around a pointer to a socket buffer
  383. * so a DMA handle can be stored along with the skb
  384. */
  385. struct atl1c_buffer {
  386. struct sk_buff *skb; /* socket buffer */
  387. u16 length; /* rx buffer length */
  388. u16 flags; /* information of buffer */
  389. #define ATL1C_BUFFER_FREE 0x0001
  390. #define ATL1C_BUFFER_BUSY 0x0002
  391. #define ATL1C_BUFFER_STATE_MASK 0x0003
  392. #define ATL1C_PCIMAP_SINGLE 0x0004
  393. #define ATL1C_PCIMAP_PAGE 0x0008
  394. #define ATL1C_PCIMAP_TYPE_MASK 0x000C
  395. #define ATL1C_PCIMAP_TODEVICE 0x0010
  396. #define ATL1C_PCIMAP_FROMDEVICE 0x0020
  397. #define ATL1C_PCIMAP_DIRECTION_MASK 0x0030
  398. dma_addr_t dma;
  399. };
  400. #define ATL1C_SET_BUFFER_STATE(buff, state) do { \
  401. ((buff)->flags) &= ~ATL1C_BUFFER_STATE_MASK; \
  402. ((buff)->flags) |= (state); \
  403. } while (0)
  404. #define ATL1C_SET_PCIMAP_TYPE(buff, type, direction) do { \
  405. ((buff)->flags) &= ~ATL1C_PCIMAP_TYPE_MASK; \
  406. ((buff)->flags) |= (type); \
  407. ((buff)->flags) &= ~ATL1C_PCIMAP_DIRECTION_MASK; \
  408. ((buff)->flags) |= (direction); \
  409. } while (0)
  410. /* transimit packet descriptor (tpd) ring */
  411. struct atl1c_tpd_ring {
  412. struct atl1c_adapter *adapter;
  413. void *desc; /* descriptor ring virtual address */
  414. dma_addr_t dma; /* descriptor ring physical address */
  415. u16 num;
  416. u16 size; /* descriptor ring length in bytes */
  417. u16 count; /* number of descriptors in the ring */
  418. u16 next_to_use;
  419. atomic_t next_to_clean;
  420. struct atl1c_buffer *buffer_info;
  421. struct napi_struct napi;
  422. };
  423. /* receive free descriptor (rfd) ring */
  424. struct atl1c_rfd_ring {
  425. void *desc; /* descriptor ring virtual address */
  426. dma_addr_t dma; /* descriptor ring physical address */
  427. u16 size; /* descriptor ring length in bytes */
  428. u16 count; /* number of descriptors in the ring */
  429. u16 next_to_use;
  430. u16 next_to_clean;
  431. struct atl1c_buffer *buffer_info;
  432. };
  433. /* receive return descriptor (rrd) ring */
  434. struct atl1c_rrd_ring {
  435. struct atl1c_adapter *adapter;
  436. void *desc; /* descriptor ring virtual address */
  437. dma_addr_t dma; /* descriptor ring physical address */
  438. u16 num;
  439. u16 size; /* descriptor ring length in bytes */
  440. u16 count; /* number of descriptors in the ring */
  441. u16 next_to_use;
  442. u16 next_to_clean;
  443. struct napi_struct napi;
  444. };
  445. /* board specific private data structure */
  446. struct atl1c_adapter {
  447. struct net_device *netdev;
  448. struct pci_dev *pdev;
  449. struct atl1c_hw hw;
  450. struct atl1c_hw_stats hw_stats;
  451. struct mii_if_info mii; /* MII interface info */
  452. u16 rx_buffer_len;
  453. unsigned int tx_queue_count;
  454. unsigned int rx_queue_count;
  455. unsigned long flags;
  456. #define __AT_TESTING 0x0001
  457. #define __AT_RESETTING 0x0002
  458. #define __AT_DOWN 0x0003
  459. unsigned long work_event;
  460. #define ATL1C_WORK_EVENT_RESET 0
  461. #define ATL1C_WORK_EVENT_LINK_CHANGE 1
  462. u32 msg_enable;
  463. bool have_msi;
  464. u32 wol;
  465. u16 link_speed;
  466. u16 link_duplex;
  467. spinlock_t mdio_lock;
  468. atomic_t irq_sem;
  469. struct work_struct common_task;
  470. struct timer_list watchdog_timer;
  471. struct timer_list phy_config_timer;
  472. /* All Descriptor memory */
  473. struct atl1c_ring_header ring_header;
  474. struct atl1c_tpd_ring tpd_ring[AT_MAX_TRANSMIT_QUEUE];
  475. struct atl1c_rfd_ring rfd_ring[AT_MAX_RECEIVE_QUEUE];
  476. struct atl1c_rrd_ring rrd_ring[AT_MAX_RECEIVE_QUEUE];
  477. u32 bd_number; /* board number;*/
  478. };
  479. #define AT_WRITE_REG(a, reg, value) ( \
  480. writel((value), ((a)->hw_addr + reg)))
  481. #define AT_WRITE_FLUSH(a) (\
  482. readl((a)->hw_addr))
  483. #define AT_READ_REG(a, reg, pdata) do { \
  484. if (unlikely((a)->hibernate)) { \
  485. readl((a)->hw_addr + reg); \
  486. *(u32 *)pdata = readl((a)->hw_addr + reg); \
  487. } else { \
  488. *(u32 *)pdata = readl((a)->hw_addr + reg); \
  489. } \
  490. } while (0)
  491. #define AT_WRITE_REGB(a, reg, value) (\
  492. writeb((value), ((a)->hw_addr + reg)))
  493. #define AT_READ_REGB(a, reg) (\
  494. readb((a)->hw_addr + reg))
  495. #define AT_WRITE_REGW(a, reg, value) (\
  496. writew((value), ((a)->hw_addr + reg)))
  497. #define AT_READ_REGW(a, reg, pdata) do { \
  498. if (unlikely((a)->hibernate)) { \
  499. readw((a)->hw_addr + reg); \
  500. *(u16 *)pdata = readw((a)->hw_addr + reg); \
  501. } else { \
  502. *(u16 *)pdata = readw((a)->hw_addr + reg); \
  503. } \
  504. } while (0)
  505. #define AT_WRITE_REG_ARRAY(a, reg, offset, value) ( \
  506. writel((value), (((a)->hw_addr + reg) + ((offset) << 2))))
  507. #define AT_READ_REG_ARRAY(a, reg, offset) ( \
  508. readl(((a)->hw_addr + reg) + ((offset) << 2)))
  509. extern char atl1c_driver_name[];
  510. void atl1c_reinit_locked(struct atl1c_adapter *adapter);
  511. s32 atl1c_reset_hw(struct atl1c_hw *hw);
  512. void atl1c_set_ethtool_ops(struct net_device *netdev);
  513. #endif /* _ATL1C_H_ */