atl1.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. /*
  2. * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
  3. * Copyright(c) 2006 - 2007 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/compiler.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/if_vlan.h>
  28. #include <linux/mii.h>
  29. #include <linux/module.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/timer.h>
  33. #include <linux/types.h>
  34. #include <linux/workqueue.h>
  35. #include "atlx.h"
  36. #define ATLX_DRIVER_NAME "atl1"
  37. MODULE_DESCRIPTION("Atheros L1 Gigabit Ethernet Driver");
  38. #define atlx_adapter atl1_adapter
  39. #define atlx_check_for_link atl1_check_for_link
  40. #define atlx_check_link atl1_check_link
  41. #define atlx_hash_mc_addr atl1_hash_mc_addr
  42. #define atlx_hash_set atl1_hash_set
  43. #define atlx_hw atl1_hw
  44. #define atlx_mii_ioctl atl1_mii_ioctl
  45. #define atlx_read_phy_reg atl1_read_phy_reg
  46. #define atlx_set_mac atl1_set_mac
  47. #define atlx_set_mac_addr atl1_set_mac_addr
  48. struct atl1_adapter;
  49. struct atl1_hw;
  50. /* function prototypes needed by multiple files */
  51. s32 atl1_phy_setup_autoneg_adv(struct atl1_hw *hw);
  52. s32 atl1_write_phy_reg(struct atl1_hw *hw, u32 reg_addr, u16 phy_data);
  53. s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex);
  54. s32 atl1_read_mac_addr(struct atl1_hw *hw);
  55. s32 atl1_init_hw(struct atl1_hw *hw);
  56. s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex);
  57. s32 atl1_set_speed_and_duplex(struct atl1_hw *hw, u16 speed, u16 duplex);
  58. u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
  59. void atl1_hash_set(struct atl1_hw *hw, u32 hash_value);
  60. s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data);
  61. void atl1_set_mac_addr(struct atl1_hw *hw);
  62. s32 atl1_phy_enter_power_saving(struct atl1_hw *hw);
  63. s32 atl1_reset_hw(struct atl1_hw *hw);
  64. void atl1_check_options(struct atl1_adapter *adapter);
  65. static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  66. int cmd);
  67. static u32 atl1_check_link(struct atl1_adapter *adapter);
  68. s32 atl1_up(struct atl1_adapter *adapter);
  69. void atl1_down(struct atl1_adapter *adapter);
  70. int atl1_reset(struct atl1_adapter *adapter);
  71. extern const struct ethtool_ops atl1_ethtool_ops;
  72. /* hardware definitions specific to L1 */
  73. /* Block IDLE Status Register */
  74. #define IDLE_STATUS_RXMAC 0x1
  75. #define IDLE_STATUS_TXMAC 0x2
  76. #define IDLE_STATUS_RXQ 0x4
  77. #define IDLE_STATUS_TXQ 0x8
  78. #define IDLE_STATUS_DMAR 0x10
  79. #define IDLE_STATUS_DMAW 0x20
  80. #define IDLE_STATUS_SMB 0x40
  81. #define IDLE_STATUS_CMB 0x80
  82. /* MDIO Control Register */
  83. #define MDIO_WAIT_TIMES 30
  84. /* MAC Control Register */
  85. #define MAC_CTRL_TX_PAUSE 0x10000
  86. #define MAC_CTRL_SCNT 0x20000
  87. #define MAC_CTRL_SRST_TX 0x40000
  88. #define MAC_CTRL_TX_SIMURST 0x80000
  89. #define MAC_CTRL_SPEED_SHIFT 20
  90. #define MAC_CTRL_SPEED_MASK 0x300000
  91. #define MAC_CTRL_SPEED_1000 0x2
  92. #define MAC_CTRL_SPEED_10_100 0x1
  93. #define MAC_CTRL_DBG_TX_BKPRESURE 0x400000
  94. #define MAC_CTRL_TX_HUGE 0x800000
  95. #define MAC_CTRL_RX_CHKSUM_EN 0x1000000
  96. #define MAC_CTRL_DBG 0x8000000
  97. /* Wake-On-Lan control register */
  98. #define WOL_CLK_SWITCH_EN 0x8000
  99. #define WOL_PT5_EN 0x200000
  100. #define WOL_PT6_EN 0x400000
  101. #define WOL_PT5_MATCH 0x8000000
  102. #define WOL_PT6_MATCH 0x10000000
  103. /* WOL Length ( 2 DWORD ) */
  104. #define REG_WOL_PATTERN_LEN 0x14A4
  105. #define WOL_PT_LEN_MASK 0x7F
  106. #define WOL_PT0_LEN_SHIFT 0
  107. #define WOL_PT1_LEN_SHIFT 8
  108. #define WOL_PT2_LEN_SHIFT 16
  109. #define WOL_PT3_LEN_SHIFT 24
  110. #define WOL_PT4_LEN_SHIFT 0
  111. #define WOL_PT5_LEN_SHIFT 8
  112. #define WOL_PT6_LEN_SHIFT 16
  113. /* Internal SRAM Partition Registers, low 32 bits */
  114. #define REG_SRAM_RFD_LEN 0x1504
  115. #define REG_SRAM_RRD_ADDR 0x1508
  116. #define REG_SRAM_RRD_LEN 0x150C
  117. #define REG_SRAM_TPD_ADDR 0x1510
  118. #define REG_SRAM_TPD_LEN 0x1514
  119. #define REG_SRAM_TRD_ADDR 0x1518
  120. #define REG_SRAM_TRD_LEN 0x151C
  121. #define REG_SRAM_RXF_ADDR 0x1520
  122. #define REG_SRAM_RXF_LEN 0x1524
  123. #define REG_SRAM_TXF_ADDR 0x1528
  124. #define REG_SRAM_TXF_LEN 0x152C
  125. #define REG_SRAM_TCPH_PATH_ADDR 0x1530
  126. #define SRAM_TCPH_ADDR_MASK 0xFFF
  127. #define SRAM_TCPH_ADDR_SHIFT 0
  128. #define SRAM_PATH_ADDR_MASK 0xFFF
  129. #define SRAM_PATH_ADDR_SHIFT 16
  130. /* Load Ptr Register */
  131. #define REG_LOAD_PTR 0x1534
  132. /* Descriptor Control registers, low 32 bits */
  133. #define REG_DESC_RFD_ADDR_LO 0x1544
  134. #define REG_DESC_RRD_ADDR_LO 0x1548
  135. #define REG_DESC_TPD_ADDR_LO 0x154C
  136. #define REG_DESC_CMB_ADDR_LO 0x1550
  137. #define REG_DESC_SMB_ADDR_LO 0x1554
  138. #define REG_DESC_RFD_RRD_RING_SIZE 0x1558
  139. #define DESC_RFD_RING_SIZE_MASK 0x7FF
  140. #define DESC_RFD_RING_SIZE_SHIFT 0
  141. #define DESC_RRD_RING_SIZE_MASK 0x7FF
  142. #define DESC_RRD_RING_SIZE_SHIFT 16
  143. #define REG_DESC_TPD_RING_SIZE 0x155C
  144. #define DESC_TPD_RING_SIZE_MASK 0x3FF
  145. #define DESC_TPD_RING_SIZE_SHIFT 0
  146. /* TXQ Control Register */
  147. #define REG_TXQ_CTRL 0x1580
  148. #define TXQ_CTRL_TPD_BURST_NUM_SHIFT 0
  149. #define TXQ_CTRL_TPD_BURST_NUM_MASK 0x1F
  150. #define TXQ_CTRL_EN 0x20
  151. #define TXQ_CTRL_ENH_MODE 0x40
  152. #define TXQ_CTRL_TPD_FETCH_TH_SHIFT 8
  153. #define TXQ_CTRL_TPD_FETCH_TH_MASK 0x3F
  154. #define TXQ_CTRL_TXF_BURST_NUM_SHIFT 16
  155. #define TXQ_CTRL_TXF_BURST_NUM_MASK 0xFFFF
  156. /* Jumbo packet Threshold for task offload */
  157. #define REG_TX_JUMBO_TASK_TH_TPD_IPG 0x1584
  158. #define TX_JUMBO_TASK_TH_MASK 0x7FF
  159. #define TX_JUMBO_TASK_TH_SHIFT 0
  160. #define TX_TPD_MIN_IPG_MASK 0x1F
  161. #define TX_TPD_MIN_IPG_SHIFT 16
  162. /* RXQ Control Register */
  163. #define REG_RXQ_CTRL 0x15A0
  164. #define RXQ_CTRL_RFD_BURST_NUM_SHIFT 0
  165. #define RXQ_CTRL_RFD_BURST_NUM_MASK 0xFF
  166. #define RXQ_CTRL_RRD_BURST_THRESH_SHIFT 8
  167. #define RXQ_CTRL_RRD_BURST_THRESH_MASK 0xFF
  168. #define RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT 16
  169. #define RXQ_CTRL_RFD_PREF_MIN_IPG_MASK 0x1F
  170. #define RXQ_CTRL_CUT_THRU_EN 0x40000000
  171. #define RXQ_CTRL_EN 0x80000000
  172. /* Rx jumbo packet threshold and rrd retirement timer */
  173. #define REG_RXQ_JMBOSZ_RRDTIM 0x15A4
  174. #define RXQ_JMBOSZ_TH_MASK 0x7FF
  175. #define RXQ_JMBOSZ_TH_SHIFT 0
  176. #define RXQ_JMBO_LKAH_MASK 0xF
  177. #define RXQ_JMBO_LKAH_SHIFT 11
  178. #define RXQ_RRD_TIMER_MASK 0xFFFF
  179. #define RXQ_RRD_TIMER_SHIFT 16
  180. /* RFD flow control register */
  181. #define REG_RXQ_RXF_PAUSE_THRESH 0x15A8
  182. #define RXQ_RXF_PAUSE_TH_HI_SHIFT 16
  183. #define RXQ_RXF_PAUSE_TH_HI_MASK 0xFFF
  184. #define RXQ_RXF_PAUSE_TH_LO_SHIFT 0
  185. #define RXQ_RXF_PAUSE_TH_LO_MASK 0xFFF
  186. /* RRD flow control register */
  187. #define REG_RXQ_RRD_PAUSE_THRESH 0x15AC
  188. #define RXQ_RRD_PAUSE_TH_HI_SHIFT 0
  189. #define RXQ_RRD_PAUSE_TH_HI_MASK 0xFFF
  190. #define RXQ_RRD_PAUSE_TH_LO_SHIFT 16
  191. #define RXQ_RRD_PAUSE_TH_LO_MASK 0xFFF
  192. /* DMA Engine Control Register */
  193. #define REG_DMA_CTRL 0x15C0
  194. #define DMA_CTRL_DMAR_IN_ORDER 0x1
  195. #define DMA_CTRL_DMAR_ENH_ORDER 0x2
  196. #define DMA_CTRL_DMAR_OUT_ORDER 0x4
  197. #define DMA_CTRL_RCB_VALUE 0x8
  198. #define DMA_CTRL_DMAR_BURST_LEN_SHIFT 4
  199. #define DMA_CTRL_DMAR_BURST_LEN_MASK 7
  200. #define DMA_CTRL_DMAW_BURST_LEN_SHIFT 7
  201. #define DMA_CTRL_DMAW_BURST_LEN_MASK 7
  202. #define DMA_CTRL_DMAR_EN 0x400
  203. #define DMA_CTRL_DMAW_EN 0x800
  204. /* CMB/SMB Control Register */
  205. #define REG_CSMB_CTRL 0x15D0
  206. #define CSMB_CTRL_CMB_NOW 1
  207. #define CSMB_CTRL_SMB_NOW 2
  208. #define CSMB_CTRL_CMB_EN 4
  209. #define CSMB_CTRL_SMB_EN 8
  210. /* CMB DMA Write Threshold Register */
  211. #define REG_CMB_WRITE_TH 0x15D4
  212. #define CMB_RRD_TH_SHIFT 0
  213. #define CMB_RRD_TH_MASK 0x7FF
  214. #define CMB_TPD_TH_SHIFT 16
  215. #define CMB_TPD_TH_MASK 0x7FF
  216. /* RX/TX count-down timer to trigger CMB-write. 2us resolution. */
  217. #define REG_CMB_WRITE_TIMER 0x15D8
  218. #define CMB_RX_TM_SHIFT 0
  219. #define CMB_RX_TM_MASK 0xFFFF
  220. #define CMB_TX_TM_SHIFT 16
  221. #define CMB_TX_TM_MASK 0xFFFF
  222. /* Number of packet received since last CMB write */
  223. #define REG_CMB_RX_PKT_CNT 0x15DC
  224. /* Number of packet transmitted since last CMB write */
  225. #define REG_CMB_TX_PKT_CNT 0x15E0
  226. /* SMB auto DMA timer register */
  227. #define REG_SMB_TIMER 0x15E4
  228. /* Mailbox Register */
  229. #define REG_MAILBOX 0x15F0
  230. #define MB_RFD_PROD_INDX_SHIFT 0
  231. #define MB_RFD_PROD_INDX_MASK 0x7FF
  232. #define MB_RRD_CONS_INDX_SHIFT 11
  233. #define MB_RRD_CONS_INDX_MASK 0x7FF
  234. #define MB_TPD_PROD_INDX_SHIFT 22
  235. #define MB_TPD_PROD_INDX_MASK 0x3FF
  236. /* Interrupt Status Register */
  237. #define ISR_SMB 0x1
  238. #define ISR_TIMER 0x2
  239. #define ISR_MANUAL 0x4
  240. #define ISR_RXF_OV 0x8
  241. #define ISR_RFD_UNRUN 0x10
  242. #define ISR_RRD_OV 0x20
  243. #define ISR_TXF_UNRUN 0x40
  244. #define ISR_LINK 0x80
  245. #define ISR_HOST_RFD_UNRUN 0x100
  246. #define ISR_HOST_RRD_OV 0x200
  247. #define ISR_DMAR_TO_RST 0x400
  248. #define ISR_DMAW_TO_RST 0x800
  249. #define ISR_GPHY 0x1000
  250. #define ISR_RX_PKT 0x10000
  251. #define ISR_TX_PKT 0x20000
  252. #define ISR_TX_DMA 0x40000
  253. #define ISR_RX_DMA 0x80000
  254. #define ISR_CMB_RX 0x100000
  255. #define ISR_CMB_TX 0x200000
  256. #define ISR_MAC_RX 0x400000
  257. #define ISR_MAC_TX 0x800000
  258. #define ISR_DIS_SMB 0x20000000
  259. #define ISR_DIS_DMA 0x40000000
  260. /* Normal Interrupt mask */
  261. #define IMR_NORMAL_MASK (\
  262. ISR_SMB |\
  263. ISR_GPHY |\
  264. ISR_PHY_LINKDOWN|\
  265. ISR_DMAR_TO_RST |\
  266. ISR_DMAW_TO_RST |\
  267. ISR_CMB_TX |\
  268. ISR_CMB_RX)
  269. /* Debug Interrupt Mask (enable all interrupt) */
  270. #define IMR_DEBUG_MASK (\
  271. ISR_SMB |\
  272. ISR_TIMER |\
  273. ISR_MANUAL |\
  274. ISR_RXF_OV |\
  275. ISR_RFD_UNRUN |\
  276. ISR_RRD_OV |\
  277. ISR_TXF_UNRUN |\
  278. ISR_LINK |\
  279. ISR_CMB_TX |\
  280. ISR_CMB_RX |\
  281. ISR_RX_PKT |\
  282. ISR_TX_PKT |\
  283. ISR_MAC_RX |\
  284. ISR_MAC_TX)
  285. #define MEDIA_TYPE_1000M_FULL 1
  286. #define MEDIA_TYPE_100M_FULL 2
  287. #define MEDIA_TYPE_100M_HALF 3
  288. #define MEDIA_TYPE_10M_FULL 4
  289. #define MEDIA_TYPE_10M_HALF 5
  290. #define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x002F /* All but 1000-Half */
  291. #define MAX_JUMBO_FRAME_SIZE 10240
  292. #define ATL1_EEDUMP_LEN 48
  293. /* Statistics counters collected by the MAC */
  294. struct stats_msg_block {
  295. /* rx */
  296. u32 rx_ok; /* good RX packets */
  297. u32 rx_bcast; /* good RX broadcast packets */
  298. u32 rx_mcast; /* good RX multicast packets */
  299. u32 rx_pause; /* RX pause frames */
  300. u32 rx_ctrl; /* RX control packets other than pause frames */
  301. u32 rx_fcs_err; /* RX packets with bad FCS */
  302. u32 rx_len_err; /* RX packets with length != actual size */
  303. u32 rx_byte_cnt; /* good bytes received. FCS is NOT included */
  304. u32 rx_runt; /* RX packets < 64 bytes with good FCS */
  305. u32 rx_frag; /* RX packets < 64 bytes with bad FCS */
  306. u32 rx_sz_64; /* 64 byte RX packets */
  307. u32 rx_sz_65_127;
  308. u32 rx_sz_128_255;
  309. u32 rx_sz_256_511;
  310. u32 rx_sz_512_1023;
  311. u32 rx_sz_1024_1518;
  312. u32 rx_sz_1519_max; /* 1519 byte to MTU RX packets */
  313. u32 rx_sz_ov; /* truncated RX packets > MTU */
  314. u32 rx_rxf_ov; /* frames dropped due to RX FIFO overflow */
  315. u32 rx_rrd_ov; /* frames dropped due to RRD overflow */
  316. u32 rx_align_err; /* alignment errors */
  317. u32 rx_bcast_byte_cnt; /* RX broadcast bytes, excluding FCS */
  318. u32 rx_mcast_byte_cnt; /* RX multicast bytes, excluding FCS */
  319. u32 rx_err_addr; /* packets dropped due to address filtering */
  320. /* tx */
  321. u32 tx_ok; /* good TX packets */
  322. u32 tx_bcast; /* good TX broadcast packets */
  323. u32 tx_mcast; /* good TX multicast packets */
  324. u32 tx_pause; /* TX pause frames */
  325. u32 tx_exc_defer; /* TX packets deferred excessively */
  326. u32 tx_ctrl; /* TX control frames, excluding pause frames */
  327. u32 tx_defer; /* TX packets deferred */
  328. u32 tx_byte_cnt; /* bytes transmitted, FCS is NOT included */
  329. u32 tx_sz_64; /* 64 byte TX packets */
  330. u32 tx_sz_65_127;
  331. u32 tx_sz_128_255;
  332. u32 tx_sz_256_511;
  333. u32 tx_sz_512_1023;
  334. u32 tx_sz_1024_1518;
  335. u32 tx_sz_1519_max; /* 1519 byte to MTU TX packets */
  336. u32 tx_1_col; /* packets TX after a single collision */
  337. u32 tx_2_col; /* packets TX after multiple collisions */
  338. u32 tx_late_col; /* TX packets with late collisions */
  339. u32 tx_abort_col; /* TX packets aborted w/excessive collisions */
  340. u32 tx_underrun; /* TX packets aborted due to TX FIFO underrun
  341. * or TRD FIFO underrun */
  342. u32 tx_rd_eop; /* reads beyond the EOP into the next frame
  343. * when TRD was not written timely */
  344. u32 tx_len_err; /* TX packets where length != actual size */
  345. u32 tx_trunc; /* TX packets truncated due to size > MTU */
  346. u32 tx_bcast_byte; /* broadcast bytes transmitted, excluding FCS */
  347. u32 tx_mcast_byte; /* multicast bytes transmitted, excluding FCS */
  348. u32 smb_updated; /* 1: SMB Updated. This is used by software to
  349. * indicate the statistics update. Software
  350. * should clear this bit after retrieving the
  351. * statistics information. */
  352. };
  353. /* Coalescing Message Block */
  354. struct coals_msg_block {
  355. u32 int_stats; /* interrupt status */
  356. u16 rrd_prod_idx; /* TRD Producer Index. */
  357. u16 rfd_cons_idx; /* RFD Consumer Index. */
  358. u16 update; /* Selene sets this bit every time it DMAs the
  359. * CMB to host memory. Software should clear
  360. * this bit when CMB info is processed. */
  361. u16 tpd_cons_idx; /* TPD Consumer Index. */
  362. };
  363. /* RRD descriptor */
  364. struct rx_return_desc {
  365. u8 num_buf; /* Number of RFD buffers used by the received packet */
  366. u8 resved;
  367. u16 buf_indx; /* RFD Index of the first buffer */
  368. union {
  369. u32 valid;
  370. struct {
  371. u16 rx_chksum;
  372. u16 pkt_size;
  373. } xsum_sz;
  374. } xsz;
  375. u16 pkt_flg; /* Packet flags */
  376. u16 err_flg; /* Error flags */
  377. u16 resved2;
  378. u16 vlan_tag; /* VLAN TAG */
  379. };
  380. #define PACKET_FLAG_ETH_TYPE 0x0080
  381. #define PACKET_FLAG_VLAN_INS 0x0100
  382. #define PACKET_FLAG_ERR 0x0200
  383. #define PACKET_FLAG_IPV4 0x0400
  384. #define PACKET_FLAG_UDP 0x0800
  385. #define PACKET_FLAG_TCP 0x1000
  386. #define PACKET_FLAG_BCAST 0x2000
  387. #define PACKET_FLAG_MCAST 0x4000
  388. #define PACKET_FLAG_PAUSE 0x8000
  389. #define ERR_FLAG_CRC 0x0001
  390. #define ERR_FLAG_CODE 0x0002
  391. #define ERR_FLAG_DRIBBLE 0x0004
  392. #define ERR_FLAG_RUNT 0x0008
  393. #define ERR_FLAG_OV 0x0010
  394. #define ERR_FLAG_TRUNC 0x0020
  395. #define ERR_FLAG_IP_CHKSUM 0x0040
  396. #define ERR_FLAG_L4_CHKSUM 0x0080
  397. #define ERR_FLAG_LEN 0x0100
  398. #define ERR_FLAG_DES_ADDR 0x0200
  399. /* RFD descriptor */
  400. struct rx_free_desc {
  401. __le64 buffer_addr; /* Address of the descriptor's data buffer */
  402. __le16 buf_len; /* Size of the receive buffer in host memory */
  403. u16 coalese; /* Update consumer index to host after the
  404. * reception of this frame */
  405. /* __attribute__ ((packed)) is required */
  406. } __attribute__ ((packed));
  407. /* tsopu defines */
  408. #define TSO_PARAM_BUFLEN_MASK 0x3FFF
  409. #define TSO_PARAM_BUFLEN_SHIFT 0
  410. #define TSO_PARAM_DMAINT_MASK 0x0001
  411. #define TSO_PARAM_DMAINT_SHIFT 14
  412. #define TSO_PARAM_PKTNT_MASK 0x0001
  413. #define TSO_PARAM_PKTINT_SHIFT 15
  414. #define TSO_PARAM_VLANTAG_MASK 0xFFFF
  415. #define TSO_PARAM_VLAN_SHIFT 16
  416. /* tsopl defines */
  417. #define TSO_PARAM_EOP_MASK 0x0001
  418. #define TSO_PARAM_EOP_SHIFT 0
  419. #define TSO_PARAM_COALESCE_MASK 0x0001
  420. #define TSO_PARAM_COALESCE_SHIFT 1
  421. #define TSO_PARAM_INSVLAG_MASK 0x0001
  422. #define TSO_PARAM_INSVLAG_SHIFT 2
  423. #define TSO_PARAM_CUSTOMCKSUM_MASK 0x0001
  424. #define TSO_PARAM_CUSTOMCKSUM_SHIFT 3
  425. #define TSO_PARAM_SEGMENT_MASK 0x0001
  426. #define TSO_PARAM_SEGMENT_SHIFT 4
  427. #define TSO_PARAM_IPCKSUM_MASK 0x0001
  428. #define TSO_PARAM_IPCKSUM_SHIFT 5
  429. #define TSO_PARAM_TCPCKSUM_MASK 0x0001
  430. #define TSO_PARAM_TCPCKSUM_SHIFT 6
  431. #define TSO_PARAM_UDPCKSUM_MASK 0x0001
  432. #define TSO_PARAM_UDPCKSUM_SHIFT 7
  433. #define TSO_PARAM_VLANTAGGED_MASK 0x0001
  434. #define TSO_PARAM_VLANTAGGED_SHIFT 8
  435. #define TSO_PARAM_ETHTYPE_MASK 0x0001
  436. #define TSO_PARAM_ETHTYPE_SHIFT 9
  437. #define TSO_PARAM_IPHL_MASK 0x000F
  438. #define TSO_PARAM_IPHL_SHIFT 10
  439. #define TSO_PARAM_TCPHDRLEN_MASK 0x000F
  440. #define TSO_PARAM_TCPHDRLEN_SHIFT 14
  441. #define TSO_PARAM_HDRFLAG_MASK 0x0001
  442. #define TSO_PARAM_HDRFLAG_SHIFT 18
  443. #define TSO_PARAM_MSS_MASK 0x1FFF
  444. #define TSO_PARAM_MSS_SHIFT 19
  445. /* csumpu defines */
  446. #define CSUM_PARAM_BUFLEN_MASK 0x3FFF
  447. #define CSUM_PARAM_BUFLEN_SHIFT 0
  448. #define CSUM_PARAM_DMAINT_MASK 0x0001
  449. #define CSUM_PARAM_DMAINT_SHIFT 14
  450. #define CSUM_PARAM_PKTINT_MASK 0x0001
  451. #define CSUM_PARAM_PKTINT_SHIFT 15
  452. #define CSUM_PARAM_VALANTAG_MASK 0xFFFF
  453. #define CSUM_PARAM_VALAN_SHIFT 16
  454. /* csumpl defines*/
  455. #define CSUM_PARAM_EOP_MASK 0x0001
  456. #define CSUM_PARAM_EOP_SHIFT 0
  457. #define CSUM_PARAM_COALESCE_MASK 0x0001
  458. #define CSUM_PARAM_COALESCE_SHIFT 1
  459. #define CSUM_PARAM_INSVLAG_MASK 0x0001
  460. #define CSUM_PARAM_INSVLAG_SHIFT 2
  461. #define CSUM_PARAM_CUSTOMCKSUM_MASK 0x0001
  462. #define CSUM_PARAM_CUSTOMCKSUM_SHIFT 3
  463. #define CSUM_PARAM_SEGMENT_MASK 0x0001
  464. #define CSUM_PARAM_SEGMENT_SHIFT 4
  465. #define CSUM_PARAM_IPCKSUM_MASK 0x0001
  466. #define CSUM_PARAM_IPCKSUM_SHIFT 5
  467. #define CSUM_PARAM_TCPCKSUM_MASK 0x0001
  468. #define CSUM_PARAM_TCPCKSUM_SHIFT 6
  469. #define CSUM_PARAM_UDPCKSUM_MASK 0x0001
  470. #define CSUM_PARAM_UDPCKSUM_SHIFT 7
  471. #define CSUM_PARAM_VLANTAGGED_MASK 0x0001
  472. #define CSUM_PARAM_VLANTAGGED_SHIFT 8
  473. #define CSUM_PARAM_ETHTYPE_MASK 0x0001
  474. #define CSUM_PARAM_ETHTYPE_SHIFT 9
  475. #define CSUM_PARAM_IPHL_MASK 0x000F
  476. #define CSUM_PARAM_IPHL_SHIFT 10
  477. #define CSUM_PARAM_PLOADOFFSET_MASK 0x00FF
  478. #define CSUM_PARAM_PLOADOFFSET_SHIFT 16
  479. #define CSUM_PARAM_XSUMOFFSET_MASK 0x00FF
  480. #define CSUM_PARAM_XSUMOFFSET_SHIFT 24
  481. /* TPD descriptor */
  482. struct tso_param {
  483. /* The order of these declarations is important -- don't change it */
  484. u32 tsopu; /* tso_param upper word */
  485. u32 tsopl; /* tso_param lower word */
  486. };
  487. struct csum_param {
  488. /* The order of these declarations is important -- don't change it */
  489. u32 csumpu; /* csum_param upper word */
  490. u32 csumpl; /* csum_param lower word */
  491. };
  492. union tpd_descr {
  493. u64 data;
  494. struct csum_param csum;
  495. struct tso_param tso;
  496. };
  497. struct tx_packet_desc {
  498. __le64 buffer_addr;
  499. union tpd_descr desc;
  500. };
  501. /* DMA Order Settings */
  502. enum atl1_dma_order {
  503. atl1_dma_ord_in = 1,
  504. atl1_dma_ord_enh = 2,
  505. atl1_dma_ord_out = 4
  506. };
  507. enum atl1_dma_rcb {
  508. atl1_rcb_64 = 0,
  509. atl1_rcb_128 = 1
  510. };
  511. enum atl1_dma_req_block {
  512. atl1_dma_req_128 = 0,
  513. atl1_dma_req_256 = 1,
  514. atl1_dma_req_512 = 2,
  515. atl1_dma_req_1024 = 3,
  516. atl1_dma_req_2048 = 4,
  517. atl1_dma_req_4096 = 5
  518. };
  519. #define ATL1_MAX_INTR 3
  520. #define ATL1_MAX_TX_BUF_LEN 0x3000 /* 12288 bytes */
  521. #define ATL1_DEFAULT_TPD 256
  522. #define ATL1_MAX_TPD 1024
  523. #define ATL1_MIN_TPD 64
  524. #define ATL1_DEFAULT_RFD 512
  525. #define ATL1_MIN_RFD 128
  526. #define ATL1_MAX_RFD 2048
  527. #define ATL1_GET_DESC(R, i, type) (&(((type *)((R)->desc))[i]))
  528. #define ATL1_RFD_DESC(R, i) ATL1_GET_DESC(R, i, struct rx_free_desc)
  529. #define ATL1_TPD_DESC(R, i) ATL1_GET_DESC(R, i, struct tx_packet_desc)
  530. #define ATL1_RRD_DESC(R, i) ATL1_GET_DESC(R, i, struct rx_return_desc)
  531. /*
  532. * atl1_ring_header represents a single, contiguous block of DMA space
  533. * mapped for the three descriptor rings (tpd, rfd, rrd) and the two
  534. * message blocks (cmb, smb) described below
  535. */
  536. struct atl1_ring_header {
  537. void *desc; /* virtual address */
  538. dma_addr_t dma; /* physical address*/
  539. unsigned int size; /* length in bytes */
  540. };
  541. /*
  542. * atl1_buffer is wrapper around a pointer to a socket buffer
  543. * so a DMA handle can be stored along with the skb
  544. */
  545. struct atl1_buffer {
  546. struct sk_buff *skb; /* socket buffer */
  547. u16 length; /* rx buffer length */
  548. u16 alloced; /* 1 if skb allocated */
  549. dma_addr_t dma;
  550. };
  551. /* transmit packet descriptor (tpd) ring */
  552. struct atl1_tpd_ring {
  553. void *desc; /* descriptor ring virtual address */
  554. dma_addr_t dma; /* descriptor ring physical address */
  555. u16 size; /* descriptor ring length in bytes */
  556. u16 count; /* number of descriptors in the ring */
  557. u16 hw_idx; /* hardware index */
  558. atomic_t next_to_clean;
  559. atomic_t next_to_use;
  560. struct atl1_buffer *buffer_info;
  561. };
  562. /* receive free descriptor (rfd) ring */
  563. struct atl1_rfd_ring {
  564. void *desc; /* descriptor ring virtual address */
  565. dma_addr_t dma; /* descriptor ring physical address */
  566. u16 size; /* descriptor ring length in bytes */
  567. u16 count; /* number of descriptors in the ring */
  568. atomic_t next_to_use;
  569. u16 next_to_clean;
  570. struct atl1_buffer *buffer_info;
  571. };
  572. /* receive return descriptor (rrd) ring */
  573. struct atl1_rrd_ring {
  574. void *desc; /* descriptor ring virtual address */
  575. dma_addr_t dma; /* descriptor ring physical address */
  576. unsigned int size; /* descriptor ring length in bytes */
  577. u16 count; /* number of descriptors in the ring */
  578. u16 next_to_use;
  579. atomic_t next_to_clean;
  580. };
  581. /* coalescing message block (cmb) */
  582. struct atl1_cmb {
  583. struct coals_msg_block *cmb;
  584. dma_addr_t dma;
  585. };
  586. /* statistics message block (smb) */
  587. struct atl1_smb {
  588. struct stats_msg_block *smb;
  589. dma_addr_t dma;
  590. };
  591. /* Statistics counters */
  592. struct atl1_sft_stats {
  593. u64 rx_packets;
  594. u64 tx_packets;
  595. u64 rx_bytes;
  596. u64 tx_bytes;
  597. u64 multicast;
  598. u64 collisions;
  599. u64 rx_errors;
  600. u64 rx_length_errors;
  601. u64 rx_crc_errors;
  602. u64 rx_frame_errors;
  603. u64 rx_fifo_errors;
  604. u64 rx_missed_errors;
  605. u64 tx_errors;
  606. u64 tx_fifo_errors;
  607. u64 tx_aborted_errors;
  608. u64 tx_window_errors;
  609. u64 tx_carrier_errors;
  610. u64 tx_pause; /* TX pause frames */
  611. u64 excecol; /* TX packets w/ excessive collisions */
  612. u64 deffer; /* TX packets deferred */
  613. u64 scc; /* packets TX after a single collision */
  614. u64 mcc; /* packets TX after multiple collisions */
  615. u64 latecol; /* TX packets w/ late collisions */
  616. u64 tx_underun; /* TX packets aborted due to TX FIFO underrun
  617. * or TRD FIFO underrun */
  618. u64 tx_trunc; /* TX packets truncated due to size > MTU */
  619. u64 rx_pause; /* num Pause packets received. */
  620. u64 rx_rrd_ov;
  621. u64 rx_trunc;
  622. };
  623. /* hardware structure */
  624. struct atl1_hw {
  625. u8 __iomem *hw_addr;
  626. struct atl1_adapter *back;
  627. enum atl1_dma_order dma_ord;
  628. enum atl1_dma_rcb rcb_value;
  629. enum atl1_dma_req_block dmar_block;
  630. enum atl1_dma_req_block dmaw_block;
  631. u8 preamble_len;
  632. u8 max_retry;
  633. u8 jam_ipg; /* IPG to start JAM for collision based flow
  634. * control in half-duplex mode. In units of
  635. * 8-bit time */
  636. u8 ipgt; /* Desired back to back inter-packet gap.
  637. * The default is 96-bit time */
  638. u8 min_ifg; /* Minimum number of IFG to enforce in between
  639. * receive frames. Frame gap below such IFP
  640. * is dropped */
  641. u8 ipgr1; /* 64bit Carrier-Sense window */
  642. u8 ipgr2; /* 96-bit IPG window */
  643. u8 tpd_burst; /* Number of TPD to prefetch in cache-aligned
  644. * burst. Each TPD is 16 bytes long */
  645. u8 rfd_burst; /* Number of RFD to prefetch in cache-aligned
  646. * burst. Each RFD is 12 bytes long */
  647. u8 rfd_fetch_gap;
  648. u8 rrd_burst; /* Threshold number of RRDs that can be retired
  649. * in a burst. Each RRD is 16 bytes long */
  650. u8 tpd_fetch_th;
  651. u8 tpd_fetch_gap;
  652. u16 tx_jumbo_task_th;
  653. u16 txf_burst; /* Number of data bytes to read in a cache-
  654. * aligned burst. Each SRAM entry is 8 bytes */
  655. u16 rx_jumbo_th; /* Jumbo packet size for non-VLAN packet. VLAN
  656. * packets should add 4 bytes */
  657. u16 rx_jumbo_lkah;
  658. u16 rrd_ret_timer; /* RRD retirement timer. Decrement by 1 after
  659. * every 512ns passes. */
  660. u16 lcol; /* Collision Window */
  661. u16 cmb_tpd;
  662. u16 cmb_rrd;
  663. u16 cmb_rx_timer;
  664. u16 cmb_tx_timer;
  665. u32 smb_timer;
  666. u16 media_type;
  667. u16 autoneg_advertised;
  668. u16 mii_autoneg_adv_reg;
  669. u16 mii_1000t_ctrl_reg;
  670. u32 max_frame_size;
  671. u32 min_frame_size;
  672. u16 dev_rev;
  673. /* spi flash */
  674. u8 flash_vendor;
  675. u8 mac_addr[ETH_ALEN];
  676. u8 perm_mac_addr[ETH_ALEN];
  677. bool phy_configured;
  678. };
  679. struct atl1_adapter {
  680. struct net_device *netdev;
  681. struct pci_dev *pdev;
  682. struct net_device_stats net_stats;
  683. struct atl1_sft_stats soft_stats;
  684. struct vlan_group *vlgrp;
  685. u32 rx_buffer_len;
  686. u32 wol;
  687. u16 link_speed;
  688. u16 link_duplex;
  689. spinlock_t lock;
  690. struct work_struct tx_timeout_task;
  691. struct work_struct link_chg_task;
  692. struct work_struct pcie_dma_to_rst_task;
  693. struct timer_list watchdog_timer;
  694. struct timer_list phy_config_timer;
  695. bool phy_timer_pending;
  696. /* all descriptor rings' memory */
  697. struct atl1_ring_header ring_header;
  698. /* TX */
  699. struct atl1_tpd_ring tpd_ring;
  700. spinlock_t mb_lock;
  701. /* RX */
  702. struct atl1_rfd_ring rfd_ring;
  703. struct atl1_rrd_ring rrd_ring;
  704. u64 hw_csum_err;
  705. u64 hw_csum_good;
  706. u16 imt; /* interrupt moderator timer (2us resolution) */
  707. u16 ict; /* interrupt clear timer (2us resolution */
  708. struct mii_if_info mii; /* MII interface info */
  709. u32 bd_number; /* board number */
  710. bool pci_using_64;
  711. struct atl1_hw hw;
  712. struct atl1_smb smb;
  713. struct atl1_cmb cmb;
  714. };
  715. #endif /* ATL1_H */