atl1.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804
  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 - 2008 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. static u32 atl1_hash_mc_addr(struct atl1_hw *hw, u8 *mc_addr);
  52. static void atl1_hash_set(struct atl1_hw *hw, u32 hash_value);
  53. static void atl1_set_mac_addr(struct atl1_hw *hw);
  54. static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr,
  55. int cmd);
  56. static u32 atl1_check_link(struct atl1_adapter *adapter);
  57. /* hardware definitions specific to L1 */
  58. /* Block IDLE Status Register */
  59. #define IDLE_STATUS_RXMAC 0x1
  60. #define IDLE_STATUS_TXMAC 0x2
  61. #define IDLE_STATUS_RXQ 0x4
  62. #define IDLE_STATUS_TXQ 0x8
  63. #define IDLE_STATUS_DMAR 0x10
  64. #define IDLE_STATUS_DMAW 0x20
  65. #define IDLE_STATUS_SMB 0x40
  66. #define IDLE_STATUS_CMB 0x80
  67. /* MDIO Control Register */
  68. #define MDIO_WAIT_TIMES 30
  69. /* MAC Control Register */
  70. #define MAC_CTRL_TX_PAUSE 0x10000
  71. #define MAC_CTRL_SCNT 0x20000
  72. #define MAC_CTRL_SRST_TX 0x40000
  73. #define MAC_CTRL_TX_SIMURST 0x80000
  74. #define MAC_CTRL_SPEED_SHIFT 20
  75. #define MAC_CTRL_SPEED_MASK 0x300000
  76. #define MAC_CTRL_SPEED_1000 0x2
  77. #define MAC_CTRL_SPEED_10_100 0x1
  78. #define MAC_CTRL_DBG_TX_BKPRESURE 0x400000
  79. #define MAC_CTRL_TX_HUGE 0x800000
  80. #define MAC_CTRL_RX_CHKSUM_EN 0x1000000
  81. #define MAC_CTRL_DBG 0x8000000
  82. /* Wake-On-Lan control register */
  83. #define WOL_CLK_SWITCH_EN 0x8000
  84. #define WOL_PT5_EN 0x200000
  85. #define WOL_PT6_EN 0x400000
  86. #define WOL_PT5_MATCH 0x8000000
  87. #define WOL_PT6_MATCH 0x10000000
  88. /* WOL Length ( 2 DWORD ) */
  89. #define REG_WOL_PATTERN_LEN 0x14A4
  90. #define WOL_PT_LEN_MASK 0x7F
  91. #define WOL_PT0_LEN_SHIFT 0
  92. #define WOL_PT1_LEN_SHIFT 8
  93. #define WOL_PT2_LEN_SHIFT 16
  94. #define WOL_PT3_LEN_SHIFT 24
  95. #define WOL_PT4_LEN_SHIFT 0
  96. #define WOL_PT5_LEN_SHIFT 8
  97. #define WOL_PT6_LEN_SHIFT 16
  98. /* Internal SRAM Partition Registers, low 32 bits */
  99. #define REG_SRAM_RFD_LEN 0x1504
  100. #define REG_SRAM_RRD_ADDR 0x1508
  101. #define REG_SRAM_RRD_LEN 0x150C
  102. #define REG_SRAM_TPD_ADDR 0x1510
  103. #define REG_SRAM_TPD_LEN 0x1514
  104. #define REG_SRAM_TRD_ADDR 0x1518
  105. #define REG_SRAM_TRD_LEN 0x151C
  106. #define REG_SRAM_RXF_ADDR 0x1520
  107. #define REG_SRAM_RXF_LEN 0x1524
  108. #define REG_SRAM_TXF_ADDR 0x1528
  109. #define REG_SRAM_TXF_LEN 0x152C
  110. #define REG_SRAM_TCPH_PATH_ADDR 0x1530
  111. #define SRAM_TCPH_ADDR_MASK 0xFFF
  112. #define SRAM_TCPH_ADDR_SHIFT 0
  113. #define SRAM_PATH_ADDR_MASK 0xFFF
  114. #define SRAM_PATH_ADDR_SHIFT 16
  115. /* Load Ptr Register */
  116. #define REG_LOAD_PTR 0x1534
  117. /* Descriptor Control registers, low 32 bits */
  118. #define REG_DESC_RFD_ADDR_LO 0x1544
  119. #define REG_DESC_RRD_ADDR_LO 0x1548
  120. #define REG_DESC_TPD_ADDR_LO 0x154C
  121. #define REG_DESC_CMB_ADDR_LO 0x1550
  122. #define REG_DESC_SMB_ADDR_LO 0x1554
  123. #define REG_DESC_RFD_RRD_RING_SIZE 0x1558
  124. #define DESC_RFD_RING_SIZE_MASK 0x7FF
  125. #define DESC_RFD_RING_SIZE_SHIFT 0
  126. #define DESC_RRD_RING_SIZE_MASK 0x7FF
  127. #define DESC_RRD_RING_SIZE_SHIFT 16
  128. #define REG_DESC_TPD_RING_SIZE 0x155C
  129. #define DESC_TPD_RING_SIZE_MASK 0x3FF
  130. #define DESC_TPD_RING_SIZE_SHIFT 0
  131. /* TXQ Control Register */
  132. #define REG_TXQ_CTRL 0x1580
  133. #define TXQ_CTRL_TPD_BURST_NUM_SHIFT 0
  134. #define TXQ_CTRL_TPD_BURST_NUM_MASK 0x1F
  135. #define TXQ_CTRL_EN 0x20
  136. #define TXQ_CTRL_ENH_MODE 0x40
  137. #define TXQ_CTRL_TPD_FETCH_TH_SHIFT 8
  138. #define TXQ_CTRL_TPD_FETCH_TH_MASK 0x3F
  139. #define TXQ_CTRL_TXF_BURST_NUM_SHIFT 16
  140. #define TXQ_CTRL_TXF_BURST_NUM_MASK 0xFFFF
  141. /* Jumbo packet Threshold for task offload */
  142. #define REG_TX_JUMBO_TASK_TH_TPD_IPG 0x1584
  143. #define TX_JUMBO_TASK_TH_MASK 0x7FF
  144. #define TX_JUMBO_TASK_TH_SHIFT 0
  145. #define TX_TPD_MIN_IPG_MASK 0x1F
  146. #define TX_TPD_MIN_IPG_SHIFT 16
  147. /* RXQ Control Register */
  148. #define REG_RXQ_CTRL 0x15A0
  149. #define RXQ_CTRL_RFD_BURST_NUM_SHIFT 0
  150. #define RXQ_CTRL_RFD_BURST_NUM_MASK 0xFF
  151. #define RXQ_CTRL_RRD_BURST_THRESH_SHIFT 8
  152. #define RXQ_CTRL_RRD_BURST_THRESH_MASK 0xFF
  153. #define RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT 16
  154. #define RXQ_CTRL_RFD_PREF_MIN_IPG_MASK 0x1F
  155. #define RXQ_CTRL_CUT_THRU_EN 0x40000000
  156. #define RXQ_CTRL_EN 0x80000000
  157. /* Rx jumbo packet threshold and rrd retirement timer */
  158. #define REG_RXQ_JMBOSZ_RRDTIM 0x15A4
  159. #define RXQ_JMBOSZ_TH_MASK 0x7FF
  160. #define RXQ_JMBOSZ_TH_SHIFT 0
  161. #define RXQ_JMBO_LKAH_MASK 0xF
  162. #define RXQ_JMBO_LKAH_SHIFT 11
  163. #define RXQ_RRD_TIMER_MASK 0xFFFF
  164. #define RXQ_RRD_TIMER_SHIFT 16
  165. /* RFD flow control register */
  166. #define REG_RXQ_RXF_PAUSE_THRESH 0x15A8
  167. #define RXQ_RXF_PAUSE_TH_HI_SHIFT 16
  168. #define RXQ_RXF_PAUSE_TH_HI_MASK 0xFFF
  169. #define RXQ_RXF_PAUSE_TH_LO_SHIFT 0
  170. #define RXQ_RXF_PAUSE_TH_LO_MASK 0xFFF
  171. /* RRD flow control register */
  172. #define REG_RXQ_RRD_PAUSE_THRESH 0x15AC
  173. #define RXQ_RRD_PAUSE_TH_HI_SHIFT 0
  174. #define RXQ_RRD_PAUSE_TH_HI_MASK 0xFFF
  175. #define RXQ_RRD_PAUSE_TH_LO_SHIFT 16
  176. #define RXQ_RRD_PAUSE_TH_LO_MASK 0xFFF
  177. /* DMA Engine Control Register */
  178. #define REG_DMA_CTRL 0x15C0
  179. #define DMA_CTRL_DMAR_IN_ORDER 0x1
  180. #define DMA_CTRL_DMAR_ENH_ORDER 0x2
  181. #define DMA_CTRL_DMAR_OUT_ORDER 0x4
  182. #define DMA_CTRL_RCB_VALUE 0x8
  183. #define DMA_CTRL_DMAR_BURST_LEN_SHIFT 4
  184. #define DMA_CTRL_DMAR_BURST_LEN_MASK 7
  185. #define DMA_CTRL_DMAW_BURST_LEN_SHIFT 7
  186. #define DMA_CTRL_DMAW_BURST_LEN_MASK 7
  187. #define DMA_CTRL_DMAR_EN 0x400
  188. #define DMA_CTRL_DMAW_EN 0x800
  189. /* CMB/SMB Control Register */
  190. #define REG_CSMB_CTRL 0x15D0
  191. #define CSMB_CTRL_CMB_NOW 1
  192. #define CSMB_CTRL_SMB_NOW 2
  193. #define CSMB_CTRL_CMB_EN 4
  194. #define CSMB_CTRL_SMB_EN 8
  195. /* CMB DMA Write Threshold Register */
  196. #define REG_CMB_WRITE_TH 0x15D4
  197. #define CMB_RRD_TH_SHIFT 0
  198. #define CMB_RRD_TH_MASK 0x7FF
  199. #define CMB_TPD_TH_SHIFT 16
  200. #define CMB_TPD_TH_MASK 0x7FF
  201. /* RX/TX count-down timer to trigger CMB-write. 2us resolution. */
  202. #define REG_CMB_WRITE_TIMER 0x15D8
  203. #define CMB_RX_TM_SHIFT 0
  204. #define CMB_RX_TM_MASK 0xFFFF
  205. #define CMB_TX_TM_SHIFT 16
  206. #define CMB_TX_TM_MASK 0xFFFF
  207. /* Number of packet received since last CMB write */
  208. #define REG_CMB_RX_PKT_CNT 0x15DC
  209. /* Number of packet transmitted since last CMB write */
  210. #define REG_CMB_TX_PKT_CNT 0x15E0
  211. /* SMB auto DMA timer register */
  212. #define REG_SMB_TIMER 0x15E4
  213. /* Mailbox Register */
  214. #define REG_MAILBOX 0x15F0
  215. #define MB_RFD_PROD_INDX_SHIFT 0
  216. #define MB_RFD_PROD_INDX_MASK 0x7FF
  217. #define MB_RRD_CONS_INDX_SHIFT 11
  218. #define MB_RRD_CONS_INDX_MASK 0x7FF
  219. #define MB_TPD_PROD_INDX_SHIFT 22
  220. #define MB_TPD_PROD_INDX_MASK 0x3FF
  221. /* Interrupt Status Register */
  222. #define ISR_SMB 0x1
  223. #define ISR_TIMER 0x2
  224. #define ISR_MANUAL 0x4
  225. #define ISR_RXF_OV 0x8
  226. #define ISR_RFD_UNRUN 0x10
  227. #define ISR_RRD_OV 0x20
  228. #define ISR_TXF_UNRUN 0x40
  229. #define ISR_LINK 0x80
  230. #define ISR_HOST_RFD_UNRUN 0x100
  231. #define ISR_HOST_RRD_OV 0x200
  232. #define ISR_DMAR_TO_RST 0x400
  233. #define ISR_DMAW_TO_RST 0x800
  234. #define ISR_GPHY 0x1000
  235. #define ISR_RX_PKT 0x10000
  236. #define ISR_TX_PKT 0x20000
  237. #define ISR_TX_DMA 0x40000
  238. #define ISR_RX_DMA 0x80000
  239. #define ISR_CMB_RX 0x100000
  240. #define ISR_CMB_TX 0x200000
  241. #define ISR_MAC_RX 0x400000
  242. #define ISR_MAC_TX 0x800000
  243. #define ISR_DIS_SMB 0x20000000
  244. #define ISR_DIS_DMA 0x40000000
  245. /* Normal Interrupt mask without RX/TX enabled */
  246. #define IMR_NORXTX_MASK (\
  247. ISR_SMB |\
  248. ISR_GPHY |\
  249. ISR_PHY_LINKDOWN|\
  250. ISR_DMAR_TO_RST |\
  251. ISR_DMAW_TO_RST)
  252. /* Normal Interrupt mask */
  253. #define IMR_NORMAL_MASK (\
  254. IMR_NORXTX_MASK |\
  255. ISR_CMB_TX |\
  256. ISR_CMB_RX)
  257. /* Debug Interrupt Mask (enable all interrupt) */
  258. #define IMR_DEBUG_MASK (\
  259. ISR_SMB |\
  260. ISR_TIMER |\
  261. ISR_MANUAL |\
  262. ISR_RXF_OV |\
  263. ISR_RFD_UNRUN |\
  264. ISR_RRD_OV |\
  265. ISR_TXF_UNRUN |\
  266. ISR_LINK |\
  267. ISR_CMB_TX |\
  268. ISR_CMB_RX |\
  269. ISR_RX_PKT |\
  270. ISR_TX_PKT |\
  271. ISR_MAC_RX |\
  272. ISR_MAC_TX)
  273. #define MEDIA_TYPE_1000M_FULL 1
  274. #define MEDIA_TYPE_100M_FULL 2
  275. #define MEDIA_TYPE_100M_HALF 3
  276. #define MEDIA_TYPE_10M_FULL 4
  277. #define MEDIA_TYPE_10M_HALF 5
  278. #define AUTONEG_ADVERTISE_SPEED_DEFAULT 0x002F /* All but 1000-Half */
  279. #define MAX_JUMBO_FRAME_SIZE 10240
  280. #define ATL1_EEDUMP_LEN 48
  281. /* Statistics counters collected by the MAC */
  282. struct stats_msg_block {
  283. /* rx */
  284. u32 rx_ok; /* good RX packets */
  285. u32 rx_bcast; /* good RX broadcast packets */
  286. u32 rx_mcast; /* good RX multicast packets */
  287. u32 rx_pause; /* RX pause frames */
  288. u32 rx_ctrl; /* RX control packets other than pause frames */
  289. u32 rx_fcs_err; /* RX packets with bad FCS */
  290. u32 rx_len_err; /* RX packets with length != actual size */
  291. u32 rx_byte_cnt; /* good bytes received. FCS is NOT included */
  292. u32 rx_runt; /* RX packets < 64 bytes with good FCS */
  293. u32 rx_frag; /* RX packets < 64 bytes with bad FCS */
  294. u32 rx_sz_64; /* 64 byte RX packets */
  295. u32 rx_sz_65_127;
  296. u32 rx_sz_128_255;
  297. u32 rx_sz_256_511;
  298. u32 rx_sz_512_1023;
  299. u32 rx_sz_1024_1518;
  300. u32 rx_sz_1519_max; /* 1519 byte to MTU RX packets */
  301. u32 rx_sz_ov; /* truncated RX packets > MTU */
  302. u32 rx_rxf_ov; /* frames dropped due to RX FIFO overflow */
  303. u32 rx_rrd_ov; /* frames dropped due to RRD overflow */
  304. u32 rx_align_err; /* alignment errors */
  305. u32 rx_bcast_byte_cnt; /* RX broadcast bytes, excluding FCS */
  306. u32 rx_mcast_byte_cnt; /* RX multicast bytes, excluding FCS */
  307. u32 rx_err_addr; /* packets dropped due to address filtering */
  308. /* tx */
  309. u32 tx_ok; /* good TX packets */
  310. u32 tx_bcast; /* good TX broadcast packets */
  311. u32 tx_mcast; /* good TX multicast packets */
  312. u32 tx_pause; /* TX pause frames */
  313. u32 tx_exc_defer; /* TX packets deferred excessively */
  314. u32 tx_ctrl; /* TX control frames, excluding pause frames */
  315. u32 tx_defer; /* TX packets deferred */
  316. u32 tx_byte_cnt; /* bytes transmitted, FCS is NOT included */
  317. u32 tx_sz_64; /* 64 byte TX packets */
  318. u32 tx_sz_65_127;
  319. u32 tx_sz_128_255;
  320. u32 tx_sz_256_511;
  321. u32 tx_sz_512_1023;
  322. u32 tx_sz_1024_1518;
  323. u32 tx_sz_1519_max; /* 1519 byte to MTU TX packets */
  324. u32 tx_1_col; /* packets TX after a single collision */
  325. u32 tx_2_col; /* packets TX after multiple collisions */
  326. u32 tx_late_col; /* TX packets with late collisions */
  327. u32 tx_abort_col; /* TX packets aborted w/excessive collisions */
  328. u32 tx_underrun; /* TX packets aborted due to TX FIFO underrun
  329. * or TRD FIFO underrun */
  330. u32 tx_rd_eop; /* reads beyond the EOP into the next frame
  331. * when TRD was not written timely */
  332. u32 tx_len_err; /* TX packets where length != actual size */
  333. u32 tx_trunc; /* TX packets truncated due to size > MTU */
  334. u32 tx_bcast_byte; /* broadcast bytes transmitted, excluding FCS */
  335. u32 tx_mcast_byte; /* multicast bytes transmitted, excluding FCS */
  336. u32 smb_updated; /* 1: SMB Updated. This is used by software to
  337. * indicate the statistics update. Software
  338. * should clear this bit after retrieving the
  339. * statistics information. */
  340. };
  341. /* Coalescing Message Block */
  342. struct coals_msg_block {
  343. u32 int_stats; /* interrupt status */
  344. u16 rrd_prod_idx; /* TRD Producer Index. */
  345. u16 rfd_cons_idx; /* RFD Consumer Index. */
  346. u16 update; /* Selene sets this bit every time it DMAs the
  347. * CMB to host memory. Software should clear
  348. * this bit when CMB info is processed. */
  349. u16 tpd_cons_idx; /* TPD Consumer Index. */
  350. };
  351. /* RRD descriptor */
  352. struct rx_return_desc {
  353. u8 num_buf; /* Number of RFD buffers used by the received packet */
  354. u8 resved;
  355. u16 buf_indx; /* RFD Index of the first buffer */
  356. union {
  357. u32 valid;
  358. struct {
  359. u16 rx_chksum;
  360. u16 pkt_size;
  361. } xsum_sz;
  362. } xsz;
  363. u16 pkt_flg; /* Packet flags */
  364. u16 err_flg; /* Error flags */
  365. u16 resved2;
  366. u16 vlan_tag; /* VLAN TAG */
  367. };
  368. #define PACKET_FLAG_ETH_TYPE 0x0080
  369. #define PACKET_FLAG_VLAN_INS 0x0100
  370. #define PACKET_FLAG_ERR 0x0200
  371. #define PACKET_FLAG_IPV4 0x0400
  372. #define PACKET_FLAG_UDP 0x0800
  373. #define PACKET_FLAG_TCP 0x1000
  374. #define PACKET_FLAG_BCAST 0x2000
  375. #define PACKET_FLAG_MCAST 0x4000
  376. #define PACKET_FLAG_PAUSE 0x8000
  377. #define ERR_FLAG_CRC 0x0001
  378. #define ERR_FLAG_CODE 0x0002
  379. #define ERR_FLAG_DRIBBLE 0x0004
  380. #define ERR_FLAG_RUNT 0x0008
  381. #define ERR_FLAG_OV 0x0010
  382. #define ERR_FLAG_TRUNC 0x0020
  383. #define ERR_FLAG_IP_CHKSUM 0x0040
  384. #define ERR_FLAG_L4_CHKSUM 0x0080
  385. #define ERR_FLAG_LEN 0x0100
  386. #define ERR_FLAG_DES_ADDR 0x0200
  387. /* RFD descriptor */
  388. struct rx_free_desc {
  389. __le64 buffer_addr; /* Address of the descriptor's data buffer */
  390. __le16 buf_len; /* Size of the receive buffer in host memory */
  391. u16 coalese; /* Update consumer index to host after the
  392. * reception of this frame */
  393. /* __packed is required */
  394. } __packed;
  395. /*
  396. * The L1 transmit packet descriptor is comprised of four 32-bit words.
  397. *
  398. * 31 0
  399. * +---------------------------------------+
  400. * | Word 0: Buffer addr lo |
  401. * +---------------------------------------+
  402. * | Word 1: Buffer addr hi |
  403. * +---------------------------------------+
  404. * | Word 2 |
  405. * +---------------------------------------+
  406. * | Word 3 |
  407. * +---------------------------------------+
  408. *
  409. * Words 0 and 1 combine to form a 64-bit buffer address.
  410. *
  411. * Word 2 is self explanatory in the #define block below.
  412. *
  413. * Word 3 has two forms, depending upon the state of bits 3 and 4.
  414. * If bits 3 and 4 are both zero, then bits 14:31 are unused by the
  415. * hardware. Otherwise, if either bit 3 or 4 is set, the definition
  416. * of bits 14:31 vary according to the following depiction.
  417. *
  418. * 0 End of packet 0 End of packet
  419. * 1 Coalesce 1 Coalesce
  420. * 2 Insert VLAN tag 2 Insert VLAN tag
  421. * 3 Custom csum enable = 0 3 Custom csum enable = 1
  422. * 4 Segment enable = 1 4 Segment enable = 0
  423. * 5 Generate IP checksum 5 Generate IP checksum
  424. * 6 Generate TCP checksum 6 Generate TCP checksum
  425. * 7 Generate UDP checksum 7 Generate UDP checksum
  426. * 8 VLAN tagged 8 VLAN tagged
  427. * 9 Ethernet frame type 9 Ethernet frame type
  428. * 10-+ 10-+
  429. * 11 | IP hdr length (10:13) 11 | IP hdr length (10:13)
  430. * 12 | (num 32-bit words) 12 | (num 32-bit words)
  431. * 13-+ 13-+
  432. * 14-+ 14 Unused
  433. * 15 | TCP hdr length (14:17) 15 Unused
  434. * 16 | (num 32-bit words) 16-+
  435. * 17-+ 17 |
  436. * 18 Header TPD flag 18 |
  437. * 19-+ 19 | Payload offset
  438. * 20 | 20 | (16:23)
  439. * 21 | 21 |
  440. * 22 | 22 |
  441. * 23 | 23-+
  442. * 24 | 24-+
  443. * 25 | MSS (19:31) 25 |
  444. * 26 | 26 |
  445. * 27 | 27 | Custom csum offset
  446. * 28 | 28 | (24:31)
  447. * 29 | 29 |
  448. * 30 | 30 |
  449. * 31-+ 31-+
  450. */
  451. /* tpd word 2 */
  452. #define TPD_BUFLEN_MASK 0x3FFF
  453. #define TPD_BUFLEN_SHIFT 0
  454. #define TPD_DMAINT_MASK 0x0001
  455. #define TPD_DMAINT_SHIFT 14
  456. #define TPD_PKTNT_MASK 0x0001
  457. #define TPD_PKTINT_SHIFT 15
  458. #define TPD_VLANTAG_MASK 0xFFFF
  459. #define TPD_VLANTAG_SHIFT 16
  460. /* tpd word 3 bits 0:13 */
  461. #define TPD_EOP_MASK 0x0001
  462. #define TPD_EOP_SHIFT 0
  463. #define TPD_COALESCE_MASK 0x0001
  464. #define TPD_COALESCE_SHIFT 1
  465. #define TPD_INS_VL_TAG_MASK 0x0001
  466. #define TPD_INS_VL_TAG_SHIFT 2
  467. #define TPD_CUST_CSUM_EN_MASK 0x0001
  468. #define TPD_CUST_CSUM_EN_SHIFT 3
  469. #define TPD_SEGMENT_EN_MASK 0x0001
  470. #define TPD_SEGMENT_EN_SHIFT 4
  471. #define TPD_IP_CSUM_MASK 0x0001
  472. #define TPD_IP_CSUM_SHIFT 5
  473. #define TPD_TCP_CSUM_MASK 0x0001
  474. #define TPD_TCP_CSUM_SHIFT 6
  475. #define TPD_UDP_CSUM_MASK 0x0001
  476. #define TPD_UDP_CSUM_SHIFT 7
  477. #define TPD_VL_TAGGED_MASK 0x0001
  478. #define TPD_VL_TAGGED_SHIFT 8
  479. #define TPD_ETHTYPE_MASK 0x0001
  480. #define TPD_ETHTYPE_SHIFT 9
  481. #define TPD_IPHL_MASK 0x000F
  482. #define TPD_IPHL_SHIFT 10
  483. /* tpd word 3 bits 14:31 if segment enabled */
  484. #define TPD_TCPHDRLEN_MASK 0x000F
  485. #define TPD_TCPHDRLEN_SHIFT 14
  486. #define TPD_HDRFLAG_MASK 0x0001
  487. #define TPD_HDRFLAG_SHIFT 18
  488. #define TPD_MSS_MASK 0x1FFF
  489. #define TPD_MSS_SHIFT 19
  490. /* tpd word 3 bits 16:31 if custom csum enabled */
  491. #define TPD_PLOADOFFSET_MASK 0x00FF
  492. #define TPD_PLOADOFFSET_SHIFT 16
  493. #define TPD_CCSUMOFFSET_MASK 0x00FF
  494. #define TPD_CCSUMOFFSET_SHIFT 24
  495. struct tx_packet_desc {
  496. __le64 buffer_addr;
  497. __le32 word2;
  498. __le32 word3;
  499. };
  500. /* DMA Order Settings */
  501. enum atl1_dma_order {
  502. atl1_dma_ord_in = 1,
  503. atl1_dma_ord_enh = 2,
  504. atl1_dma_ord_out = 4
  505. };
  506. enum atl1_dma_rcb {
  507. atl1_rcb_64 = 0,
  508. atl1_rcb_128 = 1
  509. };
  510. enum atl1_dma_req_block {
  511. atl1_dma_req_128 = 0,
  512. atl1_dma_req_256 = 1,
  513. atl1_dma_req_512 = 2,
  514. atl1_dma_req_1024 = 3,
  515. atl1_dma_req_2048 = 4,
  516. atl1_dma_req_4096 = 5
  517. };
  518. #define ATL1_MAX_INTR 3
  519. #define ATL1_MAX_TX_BUF_LEN 0x3000 /* 12288 bytes */
  520. #define ATL1_DEFAULT_TPD 256
  521. #define ATL1_MAX_TPD 1024
  522. #define ATL1_MIN_TPD 64
  523. #define ATL1_DEFAULT_RFD 512
  524. #define ATL1_MIN_RFD 128
  525. #define ATL1_MAX_RFD 2048
  526. #define ATL1_REG_COUNT 1538
  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_dropped;
  603. u64 rx_frame_errors;
  604. u64 rx_fifo_errors;
  605. u64 rx_missed_errors;
  606. u64 tx_errors;
  607. u64 tx_fifo_errors;
  608. u64 tx_aborted_errors;
  609. u64 tx_window_errors;
  610. u64 tx_carrier_errors;
  611. u64 tx_pause; /* TX pause frames */
  612. u64 excecol; /* TX packets w/ excessive collisions */
  613. u64 deffer; /* TX packets deferred */
  614. u64 scc; /* packets TX after a single collision */
  615. u64 mcc; /* packets TX after multiple collisions */
  616. u64 latecol; /* TX packets w/ late collisions */
  617. u64 tx_underun; /* TX packets aborted due to TX FIFO underrun
  618. * or TRD FIFO underrun */
  619. u64 tx_trunc; /* TX packets truncated due to size > MTU */
  620. u64 rx_pause; /* num Pause packets received. */
  621. u64 rx_rrd_ov;
  622. u64 rx_trunc;
  623. };
  624. /* hardware structure */
  625. struct atl1_hw {
  626. u8 __iomem *hw_addr;
  627. struct atl1_adapter *back;
  628. enum atl1_dma_order dma_ord;
  629. enum atl1_dma_rcb rcb_value;
  630. enum atl1_dma_req_block dmar_block;
  631. enum atl1_dma_req_block dmaw_block;
  632. u8 preamble_len;
  633. u8 max_retry;
  634. u8 jam_ipg; /* IPG to start JAM for collision based flow
  635. * control in half-duplex mode. In units of
  636. * 8-bit time */
  637. u8 ipgt; /* Desired back to back inter-packet gap.
  638. * The default is 96-bit time */
  639. u8 min_ifg; /* Minimum number of IFG to enforce in between
  640. * receive frames. Frame gap below such IFP
  641. * is dropped */
  642. u8 ipgr1; /* 64bit Carrier-Sense window */
  643. u8 ipgr2; /* 96-bit IPG window */
  644. u8 tpd_burst; /* Number of TPD to prefetch in cache-aligned
  645. * burst. Each TPD is 16 bytes long */
  646. u8 rfd_burst; /* Number of RFD to prefetch in cache-aligned
  647. * burst. Each RFD is 12 bytes long */
  648. u8 rfd_fetch_gap;
  649. u8 rrd_burst; /* Threshold number of RRDs that can be retired
  650. * in a burst. Each RRD is 16 bytes long */
  651. u8 tpd_fetch_th;
  652. u8 tpd_fetch_gap;
  653. u16 tx_jumbo_task_th;
  654. u16 txf_burst; /* Number of data bytes to read in a cache-
  655. * aligned burst. Each SRAM entry is 8 bytes */
  656. u16 rx_jumbo_th; /* Jumbo packet size for non-VLAN packet. VLAN
  657. * packets should add 4 bytes */
  658. u16 rx_jumbo_lkah;
  659. u16 rrd_ret_timer; /* RRD retirement timer. Decrement by 1 after
  660. * every 512ns passes. */
  661. u16 lcol; /* Collision Window */
  662. u16 cmb_tpd;
  663. u16 cmb_rrd;
  664. u16 cmb_rx_timer;
  665. u16 cmb_tx_timer;
  666. u32 smb_timer;
  667. u16 media_type;
  668. u16 autoneg_advertised;
  669. u16 mii_autoneg_adv_reg;
  670. u16 mii_1000t_ctrl_reg;
  671. u32 max_frame_size;
  672. u32 min_frame_size;
  673. u16 dev_rev;
  674. /* spi flash */
  675. u8 flash_vendor;
  676. u8 mac_addr[ETH_ALEN];
  677. u8 perm_mac_addr[ETH_ALEN];
  678. bool phy_configured;
  679. };
  680. struct atl1_adapter {
  681. struct net_device *netdev;
  682. struct pci_dev *pdev;
  683. struct atl1_sft_stats soft_stats;
  684. u32 rx_buffer_len;
  685. u32 wol;
  686. u16 link_speed;
  687. u16 link_duplex;
  688. spinlock_t lock;
  689. struct napi_struct napi;
  690. struct work_struct reset_dev_task;
  691. struct work_struct link_chg_task;
  692. struct timer_list phy_config_timer;
  693. bool phy_timer_pending;
  694. /* all descriptor rings' memory */
  695. struct atl1_ring_header ring_header;
  696. /* TX */
  697. struct atl1_tpd_ring tpd_ring;
  698. spinlock_t mb_lock;
  699. /* RX */
  700. struct atl1_rfd_ring rfd_ring;
  701. struct atl1_rrd_ring rrd_ring;
  702. u64 hw_csum_err;
  703. u64 hw_csum_good;
  704. u32 msg_enable;
  705. u16 imt; /* interrupt moderator timer (2us resolution) */
  706. u16 ict; /* interrupt clear timer (2us resolution */
  707. struct mii_if_info mii; /* MII interface info */
  708. /*
  709. * Use this value to check is napi handler allowed to
  710. * enable ints or not
  711. */
  712. bool int_enabled;
  713. u32 bd_number; /* board number */
  714. bool pci_using_64;
  715. struct atl1_hw hw;
  716. struct atl1_smb smb;
  717. struct atl1_cmb cmb;
  718. };
  719. #endif /* ATL1_H */