hw.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * Copyright (c) 2013 Johannes Berg <johannes@sipsolutions.net>
  3. *
  4. * This file is free software: you may copy, redistribute and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation, either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This file is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * This file incorporates work covered by the following copyright and
  18. * permission notice:
  19. *
  20. * Copyright (c) 2012 Qualcomm Atheros, Inc.
  21. *
  22. * Permission to use, copy, modify, and/or distribute this software for any
  23. * purpose with or without fee is hereby granted, provided that the above
  24. * copyright notice and this permission notice appear in all copies.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  27. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  29. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  30. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  31. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  32. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  33. */
  34. #ifndef ALX_HW_H_
  35. #define ALX_HW_H_
  36. #include <linux/types.h>
  37. #include <linux/mdio.h>
  38. #include <linux/pci.h>
  39. #include <linux/if_vlan.h>
  40. #include "reg.h"
  41. /* Transmit Packet Descriptor, contains 4 32-bit words.
  42. *
  43. * 31 16 0
  44. * +----------------+----------------+
  45. * | vlan-tag | buf length |
  46. * +----------------+----------------+
  47. * | Word 1 |
  48. * +----------------+----------------+
  49. * | Word 2: buf addr lo |
  50. * +----------------+----------------+
  51. * | Word 3: buf addr hi |
  52. * +----------------+----------------+
  53. *
  54. * Word 2 and 3 combine to form a 64-bit buffer address
  55. *
  56. * Word 1 has three forms, depending on the state of bit 8/12/13:
  57. * if bit8 =='1', the definition is just for custom checksum offload.
  58. * if bit8 == '0' && bit12 == '1' && bit13 == '1', the *FIRST* descriptor
  59. * for the skb is special for LSO V2, Word 2 become total skb length ,
  60. * Word 3 is meaningless.
  61. * other condition, the definition is for general skb or ip/tcp/udp
  62. * checksum or LSO(TSO) offload.
  63. *
  64. * Here is the depiction:
  65. *
  66. * 0-+ 0-+
  67. * 1 | 1 |
  68. * 2 | 2 |
  69. * 3 | Payload offset 3 | L4 header offset
  70. * 4 | (7:0) 4 | (7:0)
  71. * 5 | 5 |
  72. * 6 | 6 |
  73. * 7-+ 7-+
  74. * 8 Custom csum enable = 1 8 Custom csum enable = 0
  75. * 9 General IPv4 checksum 9 General IPv4 checksum
  76. * 10 General TCP checksum 10 General TCP checksum
  77. * 11 General UDP checksum 11 General UDP checksum
  78. * 12 Large Send Segment enable 12 Large Send Segment enable
  79. * 13 Large Send Segment type 13 Large Send Segment type
  80. * 14 VLAN tagged 14 VLAN tagged
  81. * 15 Insert VLAN tag 15 Insert VLAN tag
  82. * 16 IPv4 packet 16 IPv4 packet
  83. * 17 Ethernet frame type 17 Ethernet frame type
  84. * 18-+ 18-+
  85. * 19 | 19 |
  86. * 20 | 20 |
  87. * 21 | Custom csum offset 21 |
  88. * 22 | (25:18) 22 |
  89. * 23 | 23 | MSS (30:18)
  90. * 24 | 24 |
  91. * 25-+ 25 |
  92. * 26-+ 26 |
  93. * 27 | 27 |
  94. * 28 | Reserved 28 |
  95. * 29 | 29 |
  96. * 30-+ 30-+
  97. * 31 End of packet 31 End of packet
  98. */
  99. struct alx_txd {
  100. __le16 len;
  101. __le16 vlan_tag;
  102. __le32 word1;
  103. union {
  104. __le64 addr;
  105. struct {
  106. __le32 pkt_len;
  107. __le32 resvd;
  108. } l;
  109. } adrl;
  110. } __packed;
  111. /* tpd word 1 */
  112. #define TPD_CXSUMSTART_MASK 0x00FF
  113. #define TPD_CXSUMSTART_SHIFT 0
  114. #define TPD_L4HDROFFSET_MASK 0x00FF
  115. #define TPD_L4HDROFFSET_SHIFT 0
  116. #define TPD_CXSUM_EN_MASK 0x0001
  117. #define TPD_CXSUM_EN_SHIFT 8
  118. #define TPD_IP_XSUM_MASK 0x0001
  119. #define TPD_IP_XSUM_SHIFT 9
  120. #define TPD_TCP_XSUM_MASK 0x0001
  121. #define TPD_TCP_XSUM_SHIFT 10
  122. #define TPD_UDP_XSUM_MASK 0x0001
  123. #define TPD_UDP_XSUM_SHIFT 11
  124. #define TPD_LSO_EN_MASK 0x0001
  125. #define TPD_LSO_EN_SHIFT 12
  126. #define TPD_LSO_V2_MASK 0x0001
  127. #define TPD_LSO_V2_SHIFT 13
  128. #define TPD_VLTAGGED_MASK 0x0001
  129. #define TPD_VLTAGGED_SHIFT 14
  130. #define TPD_INS_VLTAG_MASK 0x0001
  131. #define TPD_INS_VLTAG_SHIFT 15
  132. #define TPD_IPV4_MASK 0x0001
  133. #define TPD_IPV4_SHIFT 16
  134. #define TPD_ETHTYPE_MASK 0x0001
  135. #define TPD_ETHTYPE_SHIFT 17
  136. #define TPD_CXSUMOFFSET_MASK 0x00FF
  137. #define TPD_CXSUMOFFSET_SHIFT 18
  138. #define TPD_MSS_MASK 0x1FFF
  139. #define TPD_MSS_SHIFT 18
  140. #define TPD_EOP_MASK 0x0001
  141. #define TPD_EOP_SHIFT 31
  142. #define DESC_GET(_x, _name) ((_x) >> _name##SHIFT & _name##MASK)
  143. /* Receive Free Descriptor */
  144. struct alx_rfd {
  145. __le64 addr; /* data buffer address, length is
  146. * declared in register --- every
  147. * buffer has the same size
  148. */
  149. } __packed;
  150. /* Receive Return Descriptor, contains 4 32-bit words.
  151. *
  152. * 31 16 0
  153. * +----------------+----------------+
  154. * | Word 0 |
  155. * +----------------+----------------+
  156. * | Word 1: RSS Hash value |
  157. * +----------------+----------------+
  158. * | Word 2 |
  159. * +----------------+----------------+
  160. * | Word 3 |
  161. * +----------------+----------------+
  162. *
  163. * Word 0 depiction & Word 2 depiction:
  164. *
  165. * 0--+ 0--+
  166. * 1 | 1 |
  167. * 2 | 2 |
  168. * 3 | 3 |
  169. * 4 | 4 |
  170. * 5 | 5 |
  171. * 6 | 6 |
  172. * 7 | IP payload checksum 7 | VLAN tag
  173. * 8 | (15:0) 8 | (15:0)
  174. * 9 | 9 |
  175. * 10 | 10 |
  176. * 11 | 11 |
  177. * 12 | 12 |
  178. * 13 | 13 |
  179. * 14 | 14 |
  180. * 15-+ 15-+
  181. * 16-+ 16-+
  182. * 17 | Number of RFDs 17 |
  183. * 18 | (19:16) 18 |
  184. * 19-+ 19 | Protocol ID
  185. * 20-+ 20 | (23:16)
  186. * 21 | 21 |
  187. * 22 | 22 |
  188. * 23 | 23-+
  189. * 24 | 24 | Reserved
  190. * 25 | Start index of RFD-ring 25-+
  191. * 26 | (31:20) 26 | RSS Q-num (27:25)
  192. * 27 | 27-+
  193. * 28 | 28-+
  194. * 29 | 29 | RSS Hash algorithm
  195. * 30 | 30 | (31:28)
  196. * 31-+ 31-+
  197. *
  198. * Word 3 depiction:
  199. *
  200. * 0--+
  201. * 1 |
  202. * 2 |
  203. * 3 |
  204. * 4 |
  205. * 5 |
  206. * 6 |
  207. * 7 | Packet length (include FCS)
  208. * 8 | (13:0)
  209. * 9 |
  210. * 10 |
  211. * 11 |
  212. * 12 |
  213. * 13-+
  214. * 14 L4 Header checksum error
  215. * 15 IPv4 checksum error
  216. * 16 VLAN tagged
  217. * 17-+
  218. * 18 | Protocol ID (19:17)
  219. * 19-+
  220. * 20 Receive error summary
  221. * 21 FCS(CRC) error
  222. * 22 Frame alignment error
  223. * 23 Truncated packet
  224. * 24 Runt packet
  225. * 25 Incomplete packet due to insufficient rx-desc
  226. * 26 Broadcast packet
  227. * 27 Multicast packet
  228. * 28 Ethernet type (EII or 802.3)
  229. * 29 FIFO overflow
  230. * 30 Length error (for 802.3, length field mismatch with actual len)
  231. * 31 Updated, indicate to driver that this RRD is refreshed.
  232. */
  233. struct alx_rrd {
  234. __le32 word0;
  235. __le32 rss_hash;
  236. __le32 word2;
  237. __le32 word3;
  238. } __packed;
  239. /* rrd word 0 */
  240. #define RRD_XSUM_MASK 0xFFFF
  241. #define RRD_XSUM_SHIFT 0
  242. #define RRD_NOR_MASK 0x000F
  243. #define RRD_NOR_SHIFT 16
  244. #define RRD_SI_MASK 0x0FFF
  245. #define RRD_SI_SHIFT 20
  246. /* rrd word 2 */
  247. #define RRD_VLTAG_MASK 0xFFFF
  248. #define RRD_VLTAG_SHIFT 0
  249. #define RRD_PID_MASK 0x00FF
  250. #define RRD_PID_SHIFT 16
  251. /* non-ip packet */
  252. #define RRD_PID_NONIP 0
  253. /* ipv4(only) */
  254. #define RRD_PID_IPV4 1
  255. /* tcp/ipv6 */
  256. #define RRD_PID_IPV6TCP 2
  257. /* tcp/ipv4 */
  258. #define RRD_PID_IPV4TCP 3
  259. /* udp/ipv6 */
  260. #define RRD_PID_IPV6UDP 4
  261. /* udp/ipv4 */
  262. #define RRD_PID_IPV4UDP 5
  263. /* ipv6(only) */
  264. #define RRD_PID_IPV6 6
  265. /* LLDP packet */
  266. #define RRD_PID_LLDP 7
  267. /* 1588 packet */
  268. #define RRD_PID_1588 8
  269. #define RRD_RSSQ_MASK 0x0007
  270. #define RRD_RSSQ_SHIFT 25
  271. #define RRD_RSSALG_MASK 0x000F
  272. #define RRD_RSSALG_SHIFT 28
  273. #define RRD_RSSALG_TCPV6 0x1
  274. #define RRD_RSSALG_IPV6 0x2
  275. #define RRD_RSSALG_TCPV4 0x4
  276. #define RRD_RSSALG_IPV4 0x8
  277. /* rrd word 3 */
  278. #define RRD_PKTLEN_MASK 0x3FFF
  279. #define RRD_PKTLEN_SHIFT 0
  280. #define RRD_ERR_L4_MASK 0x0001
  281. #define RRD_ERR_L4_SHIFT 14
  282. #define RRD_ERR_IPV4_MASK 0x0001
  283. #define RRD_ERR_IPV4_SHIFT 15
  284. #define RRD_VLTAGGED_MASK 0x0001
  285. #define RRD_VLTAGGED_SHIFT 16
  286. #define RRD_OLD_PID_MASK 0x0007
  287. #define RRD_OLD_PID_SHIFT 17
  288. #define RRD_ERR_RES_MASK 0x0001
  289. #define RRD_ERR_RES_SHIFT 20
  290. #define RRD_ERR_FCS_MASK 0x0001
  291. #define RRD_ERR_FCS_SHIFT 21
  292. #define RRD_ERR_FAE_MASK 0x0001
  293. #define RRD_ERR_FAE_SHIFT 22
  294. #define RRD_ERR_TRUNC_MASK 0x0001
  295. #define RRD_ERR_TRUNC_SHIFT 23
  296. #define RRD_ERR_RUNT_MASK 0x0001
  297. #define RRD_ERR_RUNT_SHIFT 24
  298. #define RRD_ERR_ICMP_MASK 0x0001
  299. #define RRD_ERR_ICMP_SHIFT 25
  300. #define RRD_BCAST_MASK 0x0001
  301. #define RRD_BCAST_SHIFT 26
  302. #define RRD_MCAST_MASK 0x0001
  303. #define RRD_MCAST_SHIFT 27
  304. #define RRD_ETHTYPE_MASK 0x0001
  305. #define RRD_ETHTYPE_SHIFT 28
  306. #define RRD_ERR_FIFOV_MASK 0x0001
  307. #define RRD_ERR_FIFOV_SHIFT 29
  308. #define RRD_ERR_LEN_MASK 0x0001
  309. #define RRD_ERR_LEN_SHIFT 30
  310. #define RRD_UPDATED_MASK 0x0001
  311. #define RRD_UPDATED_SHIFT 31
  312. #define ALX_MAX_SETUP_LNK_CYCLE 50
  313. /* for FlowControl */
  314. #define ALX_FC_RX 0x01
  315. #define ALX_FC_TX 0x02
  316. #define ALX_FC_ANEG 0x04
  317. /* for sleep control */
  318. #define ALX_SLEEP_WOL_PHY 0x00000001
  319. #define ALX_SLEEP_WOL_MAGIC 0x00000002
  320. #define ALX_SLEEP_CIFS 0x00000004
  321. #define ALX_SLEEP_ACTIVE (ALX_SLEEP_WOL_PHY | \
  322. ALX_SLEEP_WOL_MAGIC | \
  323. ALX_SLEEP_CIFS)
  324. /* for RSS hash type */
  325. #define ALX_RSS_HASH_TYPE_IPV4 0x1
  326. #define ALX_RSS_HASH_TYPE_IPV4_TCP 0x2
  327. #define ALX_RSS_HASH_TYPE_IPV6 0x4
  328. #define ALX_RSS_HASH_TYPE_IPV6_TCP 0x8
  329. #define ALX_RSS_HASH_TYPE_ALL (ALX_RSS_HASH_TYPE_IPV4 | \
  330. ALX_RSS_HASH_TYPE_IPV4_TCP | \
  331. ALX_RSS_HASH_TYPE_IPV6 | \
  332. ALX_RSS_HASH_TYPE_IPV6_TCP)
  333. #define ALX_FRAME_PAD 16
  334. #define ALX_RAW_MTU(_mtu) (_mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN)
  335. #define ALX_MAX_FRAME_LEN(_mtu) (ALIGN((ALX_RAW_MTU(_mtu) + ALX_FRAME_PAD), 8))
  336. #define ALX_DEF_RXBUF_SIZE ALX_MAX_FRAME_LEN(1500)
  337. #define ALX_MAX_JUMBO_PKT_SIZE (9*1024)
  338. #define ALX_MAX_TSO_PKT_SIZE (7*1024)
  339. #define ALX_MAX_FRAME_SIZE ALX_MAX_JUMBO_PKT_SIZE
  340. #define ALX_MAX_RX_QUEUES 8
  341. #define ALX_MAX_TX_QUEUES 4
  342. #define ALX_MAX_HANDLED_INTRS 5
  343. #define ALX_ISR_MISC (ALX_ISR_PCIE_LNKDOWN | \
  344. ALX_ISR_DMAW | \
  345. ALX_ISR_DMAR | \
  346. ALX_ISR_SMB | \
  347. ALX_ISR_MANU | \
  348. ALX_ISR_TIMER)
  349. #define ALX_ISR_FATAL (ALX_ISR_PCIE_LNKDOWN | \
  350. ALX_ISR_DMAW | ALX_ISR_DMAR)
  351. #define ALX_ISR_ALERT (ALX_ISR_RXF_OV | \
  352. ALX_ISR_TXF_UR | \
  353. ALX_ISR_RFD_UR)
  354. #define ALX_ISR_ALL_QUEUES (ALX_ISR_TX_Q0 | \
  355. ALX_ISR_TX_Q1 | \
  356. ALX_ISR_TX_Q2 | \
  357. ALX_ISR_TX_Q3 | \
  358. ALX_ISR_RX_Q0 | \
  359. ALX_ISR_RX_Q1 | \
  360. ALX_ISR_RX_Q2 | \
  361. ALX_ISR_RX_Q3 | \
  362. ALX_ISR_RX_Q4 | \
  363. ALX_ISR_RX_Q5 | \
  364. ALX_ISR_RX_Q6 | \
  365. ALX_ISR_RX_Q7)
  366. /* Statistics counters collected by the MAC
  367. *
  368. * The order of the fields must match the strings in alx_gstrings_stats
  369. * All stats fields should be u64
  370. * See ethtool.c
  371. */
  372. struct alx_hw_stats {
  373. /* rx */
  374. u64 rx_ok; /* good RX packets */
  375. u64 rx_bcast; /* good RX broadcast packets */
  376. u64 rx_mcast; /* good RX multicast packets */
  377. u64 rx_pause; /* RX pause frames */
  378. u64 rx_ctrl; /* RX control packets other than pause frames */
  379. u64 rx_fcs_err; /* RX packets with bad FCS */
  380. u64 rx_len_err; /* RX packets with length != actual size */
  381. u64 rx_byte_cnt; /* good bytes received. FCS is NOT included */
  382. u64 rx_runt; /* RX packets < 64 bytes with good FCS */
  383. u64 rx_frag; /* RX packets < 64 bytes with bad FCS */
  384. u64 rx_sz_64B; /* 64 byte RX packets */
  385. u64 rx_sz_127B; /* 65-127 byte RX packets */
  386. u64 rx_sz_255B; /* 128-255 byte RX packets */
  387. u64 rx_sz_511B; /* 256-511 byte RX packets */
  388. u64 rx_sz_1023B; /* 512-1023 byte RX packets */
  389. u64 rx_sz_1518B; /* 1024-1518 byte RX packets */
  390. u64 rx_sz_max; /* 1519 byte to MTU RX packets */
  391. u64 rx_ov_sz; /* truncated RX packets, size > MTU */
  392. u64 rx_ov_rxf; /* frames dropped due to RX FIFO overflow */
  393. u64 rx_ov_rrd; /* frames dropped due to RRD overflow */
  394. u64 rx_align_err; /* alignment errors */
  395. u64 rx_bc_byte_cnt; /* RX broadcast bytes, excluding FCS */
  396. u64 rx_mc_byte_cnt; /* RX multicast bytes, excluding FCS */
  397. u64 rx_err_addr; /* packets dropped due to address filtering */
  398. /* tx */
  399. u64 tx_ok; /* good TX packets */
  400. u64 tx_bcast; /* good TX broadcast packets */
  401. u64 tx_mcast; /* good TX multicast packets */
  402. u64 tx_pause; /* TX pause frames */
  403. u64 tx_exc_defer; /* TX packets deferred excessively */
  404. u64 tx_ctrl; /* TX control frames, excluding pause frames */
  405. u64 tx_defer; /* TX packets deferred */
  406. u64 tx_byte_cnt; /* bytes transmitted, FCS is NOT included */
  407. u64 tx_sz_64B; /* 64 byte TX packets */
  408. u64 tx_sz_127B; /* 65-127 byte TX packets */
  409. u64 tx_sz_255B; /* 128-255 byte TX packets */
  410. u64 tx_sz_511B; /* 256-511 byte TX packets */
  411. u64 tx_sz_1023B; /* 512-1023 byte TX packets */
  412. u64 tx_sz_1518B; /* 1024-1518 byte TX packets */
  413. u64 tx_sz_max; /* 1519 byte to MTU TX packets */
  414. u64 tx_single_col; /* packets TX after a single collision */
  415. u64 tx_multi_col; /* packets TX after multiple collisions */
  416. u64 tx_late_col; /* TX packets with late collisions */
  417. u64 tx_abort_col; /* TX packets aborted w/excessive collisions */
  418. u64 tx_underrun; /* TX packets aborted due to TX FIFO underrun
  419. * or TRD FIFO underrun
  420. */
  421. u64 tx_trd_eop; /* reads beyond the EOP into the next frame
  422. * when TRD was not written timely
  423. */
  424. u64 tx_len_err; /* TX packets where length != actual size */
  425. u64 tx_trunc; /* TX packets truncated due to size > MTU */
  426. u64 tx_bc_byte_cnt; /* broadcast bytes transmitted, excluding FCS */
  427. u64 tx_mc_byte_cnt; /* multicast bytes transmitted, excluding FCS */
  428. u64 update;
  429. };
  430. /* maximum interrupt vectors for msix */
  431. #define ALX_MAX_MSIX_INTRS 16
  432. #define ALX_GET_FIELD(_data, _field) \
  433. (((_data) >> _field ## _SHIFT) & _field ## _MASK)
  434. #define ALX_SET_FIELD(_data, _field, _value) do { \
  435. (_data) &= ~(_field ## _MASK << _field ## _SHIFT); \
  436. (_data) |= ((_value) & _field ## _MASK) << _field ## _SHIFT;\
  437. } while (0)
  438. struct alx_hw {
  439. struct pci_dev *pdev;
  440. u8 __iomem *hw_addr;
  441. /* current & permanent mac addr */
  442. u8 mac_addr[ETH_ALEN];
  443. u8 perm_addr[ETH_ALEN];
  444. u16 mtu;
  445. u16 imt;
  446. u8 dma_chnl;
  447. u8 max_dma_chnl;
  448. /* tpd threshold to trig INT */
  449. u32 ith_tpd;
  450. u32 rx_ctrl;
  451. u32 mc_hash[2];
  452. u32 smb_timer;
  453. /* SPEED_* + DUPLEX_*, SPEED_UNKNOWN if link is down */
  454. int link_speed;
  455. u8 duplex;
  456. /* auto-neg advertisement or force mode config */
  457. u8 flowctrl;
  458. u32 adv_cfg;
  459. spinlock_t mdio_lock;
  460. struct mdio_if_info mdio;
  461. u16 phy_id[2];
  462. /* PHY link patch flag */
  463. bool lnk_patch;
  464. /* cumulated stats from the hardware (registers are cleared on read) */
  465. struct alx_hw_stats stats;
  466. };
  467. static inline int alx_hw_revision(struct alx_hw *hw)
  468. {
  469. return hw->pdev->revision >> ALX_PCI_REVID_SHIFT;
  470. }
  471. static inline bool alx_hw_with_cr(struct alx_hw *hw)
  472. {
  473. return hw->pdev->revision & 1;
  474. }
  475. static inline bool alx_hw_giga(struct alx_hw *hw)
  476. {
  477. return hw->pdev->device & 1;
  478. }
  479. static inline void alx_write_mem8(struct alx_hw *hw, u32 reg, u8 val)
  480. {
  481. writeb(val, hw->hw_addr + reg);
  482. }
  483. static inline void alx_write_mem16(struct alx_hw *hw, u32 reg, u16 val)
  484. {
  485. writew(val, hw->hw_addr + reg);
  486. }
  487. static inline u16 alx_read_mem16(struct alx_hw *hw, u32 reg)
  488. {
  489. return readw(hw->hw_addr + reg);
  490. }
  491. static inline void alx_write_mem32(struct alx_hw *hw, u32 reg, u32 val)
  492. {
  493. writel(val, hw->hw_addr + reg);
  494. }
  495. static inline u32 alx_read_mem32(struct alx_hw *hw, u32 reg)
  496. {
  497. return readl(hw->hw_addr + reg);
  498. }
  499. static inline void alx_post_write(struct alx_hw *hw)
  500. {
  501. readl(hw->hw_addr);
  502. }
  503. int alx_get_perm_macaddr(struct alx_hw *hw, u8 *addr);
  504. void alx_reset_phy(struct alx_hw *hw);
  505. void alx_reset_pcie(struct alx_hw *hw);
  506. void alx_enable_aspm(struct alx_hw *hw, bool l0s_en, bool l1_en);
  507. int alx_setup_speed_duplex(struct alx_hw *hw, u32 ethadv, u8 flowctrl);
  508. void alx_post_phy_link(struct alx_hw *hw);
  509. int alx_read_phy_reg(struct alx_hw *hw, u16 reg, u16 *phy_data);
  510. int alx_write_phy_reg(struct alx_hw *hw, u16 reg, u16 phy_data);
  511. int alx_read_phy_ext(struct alx_hw *hw, u8 dev, u16 reg, u16 *pdata);
  512. int alx_write_phy_ext(struct alx_hw *hw, u8 dev, u16 reg, u16 data);
  513. int alx_read_phy_link(struct alx_hw *hw);
  514. int alx_clear_phy_intr(struct alx_hw *hw);
  515. void alx_cfg_mac_flowcontrol(struct alx_hw *hw, u8 fc);
  516. void alx_start_mac(struct alx_hw *hw);
  517. int alx_reset_mac(struct alx_hw *hw);
  518. void alx_set_macaddr(struct alx_hw *hw, const u8 *addr);
  519. bool alx_phy_configured(struct alx_hw *hw);
  520. void alx_configure_basic(struct alx_hw *hw);
  521. void alx_mask_msix(struct alx_hw *hw, int index, bool mask);
  522. void alx_disable_rss(struct alx_hw *hw);
  523. bool alx_get_phy_info(struct alx_hw *hw);
  524. void alx_update_hw_stats(struct alx_hw *hw);
  525. static inline u32 alx_speed_to_ethadv(int speed, u8 duplex)
  526. {
  527. if (speed == SPEED_1000 && duplex == DUPLEX_FULL)
  528. return ADVERTISED_1000baseT_Full;
  529. if (speed == SPEED_100 && duplex == DUPLEX_FULL)
  530. return ADVERTISED_100baseT_Full;
  531. if (speed == SPEED_100 && duplex== DUPLEX_HALF)
  532. return ADVERTISED_100baseT_Half;
  533. if (speed == SPEED_10 && duplex == DUPLEX_FULL)
  534. return ADVERTISED_10baseT_Full;
  535. if (speed == SPEED_10 && duplex == DUPLEX_HALF)
  536. return ADVERTISED_10baseT_Half;
  537. return 0;
  538. }
  539. #endif