xgbe.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /*
  2. * AMD 10Gb Ethernet driver
  3. *
  4. * This file is available to you under your choice of the following two
  5. * licenses:
  6. *
  7. * License 1: GPLv2
  8. *
  9. * Copyright (c) 2014 Advanced Micro Devices, Inc.
  10. *
  11. * This file is free software; you may copy, redistribute and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 2 of the License, or (at
  14. * your option) any later version.
  15. *
  16. * This file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * This file incorporates work covered by the following copyright and
  25. * permission notice:
  26. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  27. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  28. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  29. * and you.
  30. *
  31. * The Software IS NOT an item of Licensed Software or Licensed Product
  32. * under any End User Software License Agreement or Agreement for Licensed
  33. * Product with Synopsys or any supplement thereto. Permission is hereby
  34. * granted, free of charge, to any person obtaining a copy of this software
  35. * annotated with this license and the Software, to deal in the Software
  36. * without restriction, including without limitation the rights to use,
  37. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  38. * of the Software, and to permit persons to whom the Software is furnished
  39. * to do so, subject to the following conditions:
  40. *
  41. * The above copyright notice and this permission notice shall be included
  42. * in all copies or substantial portions of the Software.
  43. *
  44. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  45. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  46. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  47. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  48. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  49. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  50. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  51. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  52. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  53. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  54. * THE POSSIBILITY OF SUCH DAMAGE.
  55. *
  56. *
  57. * License 2: Modified BSD
  58. *
  59. * Copyright (c) 2014 Advanced Micro Devices, Inc.
  60. * All rights reserved.
  61. *
  62. * Redistribution and use in source and binary forms, with or without
  63. * modification, are permitted provided that the following conditions are met:
  64. * * Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. * * Redistributions in binary form must reproduce the above copyright
  67. * notice, this list of conditions and the following disclaimer in the
  68. * documentation and/or other materials provided with the distribution.
  69. * * Neither the name of Advanced Micro Devices, Inc. nor the
  70. * names of its contributors may be used to endorse or promote products
  71. * derived from this software without specific prior written permission.
  72. *
  73. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  74. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76. * ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  77. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  79. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  80. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  81. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  82. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  83. *
  84. * This file incorporates work covered by the following copyright and
  85. * permission notice:
  86. * The Synopsys DWC ETHER XGMAC Software Driver and documentation
  87. * (hereinafter "Software") is an unsupported proprietary work of Synopsys,
  88. * Inc. unless otherwise expressly agreed to in writing between Synopsys
  89. * and you.
  90. *
  91. * The Software IS NOT an item of Licensed Software or Licensed Product
  92. * under any End User Software License Agreement or Agreement for Licensed
  93. * Product with Synopsys or any supplement thereto. Permission is hereby
  94. * granted, free of charge, to any person obtaining a copy of this software
  95. * annotated with this license and the Software, to deal in the Software
  96. * without restriction, including without limitation the rights to use,
  97. * copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  98. * of the Software, and to permit persons to whom the Software is furnished
  99. * to do so, subject to the following conditions:
  100. *
  101. * The above copyright notice and this permission notice shall be included
  102. * in all copies or substantial portions of the Software.
  103. *
  104. * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  105. * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  106. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  107. * PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS
  108. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  109. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  110. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  111. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  112. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  113. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  114. * THE POSSIBILITY OF SUCH DAMAGE.
  115. */
  116. #ifndef __XGBE_H__
  117. #define __XGBE_H__
  118. #include <linux/dma-mapping.h>
  119. #include <linux/netdevice.h>
  120. #include <linux/workqueue.h>
  121. #include <linux/phy.h>
  122. #include <linux/if_vlan.h>
  123. #include <linux/bitops.h>
  124. #include <linux/ptp_clock_kernel.h>
  125. #include <linux/timecounter.h>
  126. #include <linux/net_tstamp.h>
  127. #include <net/dcbnl.h>
  128. #define XGBE_DRV_NAME "amd-xgbe"
  129. #define XGBE_DRV_VERSION "1.0.2"
  130. #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
  131. /* Descriptor related defines */
  132. #define XGBE_TX_DESC_CNT 512
  133. #define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
  134. #define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
  135. #define XGBE_RX_DESC_CNT 512
  136. #define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
  137. /* Descriptors required for maximum contiguous TSO/GSO packet */
  138. #define XGBE_TX_MAX_SPLIT ((GSO_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
  139. /* Maximum possible descriptors needed for an SKB:
  140. * - Maximum number of SKB frags
  141. * - Maximum descriptors for contiguous TSO/GSO packet
  142. * - Possible context descriptor
  143. * - Possible TSO header descriptor
  144. */
  145. #define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
  146. #define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  147. #define XGBE_RX_BUF_ALIGN 64
  148. #define XGBE_SKB_ALLOC_SIZE 256
  149. #define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
  150. #define XGBE_MAX_DMA_CHANNELS 16
  151. #define XGBE_MAX_QUEUES 16
  152. #define XGBE_DMA_STOP_TIMEOUT 5
  153. /* DMA cache settings - Outer sharable, write-back, write-allocate */
  154. #define XGBE_DMA_OS_AXDOMAIN 0x2
  155. #define XGBE_DMA_OS_ARCACHE 0xb
  156. #define XGBE_DMA_OS_AWCACHE 0xf
  157. /* DMA cache settings - System, no caches used */
  158. #define XGBE_DMA_SYS_AXDOMAIN 0x3
  159. #define XGBE_DMA_SYS_ARCACHE 0x0
  160. #define XGBE_DMA_SYS_AWCACHE 0x0
  161. #define XGBE_DMA_INTERRUPT_MASK 0x31c7
  162. #define XGMAC_MIN_PACKET 60
  163. #define XGMAC_STD_PACKET_MTU 1500
  164. #define XGMAC_MAX_STD_PACKET 1518
  165. #define XGMAC_JUMBO_PACKET_MTU 9000
  166. #define XGMAC_MAX_JUMBO_PACKET 9018
  167. /* Common property names */
  168. #define XGBE_MAC_ADDR_PROPERTY "mac-address"
  169. #define XGBE_PHY_MODE_PROPERTY "phy-mode"
  170. #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
  171. #define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
  172. #define XGBE_BLWC_PROPERTY "amd,serdes-blwc"
  173. #define XGBE_CDR_RATE_PROPERTY "amd,serdes-cdr-rate"
  174. #define XGBE_PQ_SKEW_PROPERTY "amd,serdes-pq-skew"
  175. #define XGBE_TX_AMP_PROPERTY "amd,serdes-tx-amp"
  176. #define XGBE_DFE_CFG_PROPERTY "amd,serdes-dfe-tap-config"
  177. #define XGBE_DFE_ENA_PROPERTY "amd,serdes-dfe-tap-enable"
  178. /* Device-tree clock names */
  179. #define XGBE_DMA_CLOCK "dma_clk"
  180. #define XGBE_PTP_CLOCK "ptp_clk"
  181. /* ACPI property names */
  182. #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
  183. #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
  184. /* Timestamp support - values based on 50MHz PTP clock
  185. * 50MHz => 20 nsec
  186. */
  187. #define XGBE_TSTAMP_SSINC 20
  188. #define XGBE_TSTAMP_SNSINC 0
  189. /* Driver PMT macros */
  190. #define XGMAC_DRIVER_CONTEXT 1
  191. #define XGMAC_IOCTL_CONTEXT 2
  192. #define XGBE_FIFO_MAX 81920
  193. #define XGBE_TC_MIN_QUANTUM 10
  194. /* Helper macro for descriptor handling
  195. * Always use XGBE_GET_DESC_DATA to access the descriptor data
  196. * since the index is free-running and needs to be and-ed
  197. * with the descriptor count value of the ring to index to
  198. * the proper descriptor data.
  199. */
  200. #define XGBE_GET_DESC_DATA(_ring, _idx) \
  201. ((_ring)->rdata + \
  202. ((_idx) & ((_ring)->rdesc_count - 1)))
  203. /* Default coalescing parameters */
  204. #define XGMAC_INIT_DMA_TX_USECS 1000
  205. #define XGMAC_INIT_DMA_TX_FRAMES 25
  206. #define XGMAC_MAX_DMA_RIWT 0xff
  207. #define XGMAC_INIT_DMA_RX_USECS 30
  208. #define XGMAC_INIT_DMA_RX_FRAMES 25
  209. /* Flow control queue count */
  210. #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
  211. /* Maximum MAC address hash table size (256 bits = 8 bytes) */
  212. #define XGBE_MAC_HASH_TABLE_SIZE 8
  213. /* Receive Side Scaling */
  214. #define XGBE_RSS_HASH_KEY_SIZE 40
  215. #define XGBE_RSS_MAX_TABLE_SIZE 256
  216. #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
  217. #define XGBE_RSS_HASH_KEY_TYPE 1
  218. /* Auto-negotiation */
  219. #define XGBE_AN_MS_TIMEOUT 500
  220. #define XGBE_LINK_TIMEOUT 10
  221. #define XGBE_AN_INT_CMPLT 0x01
  222. #define XGBE_AN_INC_LINK 0x02
  223. #define XGBE_AN_PG_RCV 0x04
  224. #define XGBE_AN_INT_MASK 0x07
  225. /* Rate-change complete wait/retry count */
  226. #define XGBE_RATECHANGE_COUNT 500
  227. /* Default SerDes settings */
  228. #define XGBE_SPEED_10000_BLWC 0
  229. #define XGBE_SPEED_10000_CDR 0x7
  230. #define XGBE_SPEED_10000_PLL 0x1
  231. #define XGBE_SPEED_10000_PQ 0x12
  232. #define XGBE_SPEED_10000_RATE 0x0
  233. #define XGBE_SPEED_10000_TXAMP 0xa
  234. #define XGBE_SPEED_10000_WORD 0x7
  235. #define XGBE_SPEED_10000_DFE_TAP_CONFIG 0x1
  236. #define XGBE_SPEED_10000_DFE_TAP_ENABLE 0x7f
  237. #define XGBE_SPEED_2500_BLWC 1
  238. #define XGBE_SPEED_2500_CDR 0x2
  239. #define XGBE_SPEED_2500_PLL 0x0
  240. #define XGBE_SPEED_2500_PQ 0xa
  241. #define XGBE_SPEED_2500_RATE 0x1
  242. #define XGBE_SPEED_2500_TXAMP 0xf
  243. #define XGBE_SPEED_2500_WORD 0x1
  244. #define XGBE_SPEED_2500_DFE_TAP_CONFIG 0x3
  245. #define XGBE_SPEED_2500_DFE_TAP_ENABLE 0x0
  246. #define XGBE_SPEED_1000_BLWC 1
  247. #define XGBE_SPEED_1000_CDR 0x2
  248. #define XGBE_SPEED_1000_PLL 0x0
  249. #define XGBE_SPEED_1000_PQ 0xa
  250. #define XGBE_SPEED_1000_RATE 0x3
  251. #define XGBE_SPEED_1000_TXAMP 0xf
  252. #define XGBE_SPEED_1000_WORD 0x1
  253. #define XGBE_SPEED_1000_DFE_TAP_CONFIG 0x3
  254. #define XGBE_SPEED_1000_DFE_TAP_ENABLE 0x0
  255. struct xgbe_prv_data;
  256. struct xgbe_packet_data {
  257. struct sk_buff *skb;
  258. unsigned int attributes;
  259. unsigned int errors;
  260. unsigned int rdesc_count;
  261. unsigned int length;
  262. unsigned int header_len;
  263. unsigned int tcp_header_len;
  264. unsigned int tcp_payload_len;
  265. unsigned short mss;
  266. unsigned short vlan_ctag;
  267. u64 rx_tstamp;
  268. u32 rss_hash;
  269. enum pkt_hash_types rss_hash_type;
  270. unsigned int tx_packets;
  271. unsigned int tx_bytes;
  272. };
  273. /* Common Rx and Tx descriptor mapping */
  274. struct xgbe_ring_desc {
  275. __le32 desc0;
  276. __le32 desc1;
  277. __le32 desc2;
  278. __le32 desc3;
  279. };
  280. /* Page allocation related values */
  281. struct xgbe_page_alloc {
  282. struct page *pages;
  283. unsigned int pages_len;
  284. unsigned int pages_offset;
  285. dma_addr_t pages_dma;
  286. };
  287. /* Ring entry buffer data */
  288. struct xgbe_buffer_data {
  289. struct xgbe_page_alloc pa;
  290. struct xgbe_page_alloc pa_unmap;
  291. dma_addr_t dma_base;
  292. unsigned long dma_off;
  293. unsigned int dma_len;
  294. };
  295. /* Tx-related ring data */
  296. struct xgbe_tx_ring_data {
  297. unsigned int packets; /* BQL packet count */
  298. unsigned int bytes; /* BQL byte count */
  299. };
  300. /* Rx-related ring data */
  301. struct xgbe_rx_ring_data {
  302. struct xgbe_buffer_data hdr; /* Header locations */
  303. struct xgbe_buffer_data buf; /* Payload locations */
  304. unsigned short hdr_len; /* Length of received header */
  305. unsigned short len; /* Length of received packet */
  306. };
  307. /* Structure used to hold information related to the descriptor
  308. * and the packet associated with the descriptor (always use
  309. * use the XGBE_GET_DESC_DATA macro to access this data from the ring)
  310. */
  311. struct xgbe_ring_data {
  312. struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
  313. dma_addr_t rdesc_dma; /* DMA address of descriptor */
  314. struct sk_buff *skb; /* Virtual address of SKB */
  315. dma_addr_t skb_dma; /* DMA address of SKB data */
  316. unsigned int skb_dma_len; /* Length of SKB DMA area */
  317. struct xgbe_tx_ring_data tx; /* Tx-related data */
  318. struct xgbe_rx_ring_data rx; /* Rx-related data */
  319. unsigned int mapped_as_page;
  320. /* Incomplete receive save location. If the budget is exhausted
  321. * or the last descriptor (last normal descriptor or a following
  322. * context descriptor) has not been DMA'd yet the current state
  323. * of the receive processing needs to be saved.
  324. */
  325. unsigned int state_saved;
  326. struct {
  327. struct sk_buff *skb;
  328. unsigned int len;
  329. unsigned int error;
  330. } state;
  331. };
  332. struct xgbe_ring {
  333. /* Ring lock - used just for TX rings at the moment */
  334. spinlock_t lock;
  335. /* Per packet related information */
  336. struct xgbe_packet_data packet_data;
  337. /* Virtual/DMA addresses and count of allocated descriptor memory */
  338. struct xgbe_ring_desc *rdesc;
  339. dma_addr_t rdesc_dma;
  340. unsigned int rdesc_count;
  341. /* Array of descriptor data corresponding the descriptor memory
  342. * (always use the XGBE_GET_DESC_DATA macro to access this data)
  343. */
  344. struct xgbe_ring_data *rdata;
  345. /* Page allocation for RX buffers */
  346. struct xgbe_page_alloc rx_hdr_pa;
  347. struct xgbe_page_alloc rx_buf_pa;
  348. /* Ring index values
  349. * cur - Tx: index of descriptor to be used for current transfer
  350. * Rx: index of descriptor to check for packet availability
  351. * dirty - Tx: index of descriptor to check for transfer complete
  352. * Rx: index of descriptor to check for buffer reallocation
  353. */
  354. unsigned int cur;
  355. unsigned int dirty;
  356. /* Coalesce frame count used for interrupt bit setting */
  357. unsigned int coalesce_count;
  358. union {
  359. struct {
  360. unsigned int queue_stopped;
  361. unsigned int xmit_more;
  362. unsigned short cur_mss;
  363. unsigned short cur_vlan_ctag;
  364. } tx;
  365. };
  366. } ____cacheline_aligned;
  367. /* Structure used to describe the descriptor rings associated with
  368. * a DMA channel.
  369. */
  370. struct xgbe_channel {
  371. char name[16];
  372. /* Address of private data area for device */
  373. struct xgbe_prv_data *pdata;
  374. /* Queue index and base address of queue's DMA registers */
  375. unsigned int queue_index;
  376. void __iomem *dma_regs;
  377. /* Per channel interrupt irq number */
  378. int dma_irq;
  379. char dma_irq_name[IFNAMSIZ + 32];
  380. /* Netdev related settings */
  381. struct napi_struct napi;
  382. unsigned int saved_ier;
  383. unsigned int tx_timer_active;
  384. struct timer_list tx_timer;
  385. struct xgbe_ring *tx_ring;
  386. struct xgbe_ring *rx_ring;
  387. } ____cacheline_aligned;
  388. enum xgbe_state {
  389. XGBE_DOWN,
  390. XGBE_LINK_INIT,
  391. XGBE_LINK_ERR,
  392. };
  393. enum xgbe_int {
  394. XGMAC_INT_DMA_CH_SR_TI,
  395. XGMAC_INT_DMA_CH_SR_TPS,
  396. XGMAC_INT_DMA_CH_SR_TBU,
  397. XGMAC_INT_DMA_CH_SR_RI,
  398. XGMAC_INT_DMA_CH_SR_RBU,
  399. XGMAC_INT_DMA_CH_SR_RPS,
  400. XGMAC_INT_DMA_CH_SR_TI_RI,
  401. XGMAC_INT_DMA_CH_SR_FBE,
  402. XGMAC_INT_DMA_ALL,
  403. };
  404. enum xgbe_int_state {
  405. XGMAC_INT_STATE_SAVE,
  406. XGMAC_INT_STATE_RESTORE,
  407. };
  408. enum xgbe_speed {
  409. XGBE_SPEED_1000 = 0,
  410. XGBE_SPEED_2500,
  411. XGBE_SPEED_10000,
  412. XGBE_SPEEDS,
  413. };
  414. enum xgbe_an {
  415. XGBE_AN_READY = 0,
  416. XGBE_AN_PAGE_RECEIVED,
  417. XGBE_AN_INCOMPAT_LINK,
  418. XGBE_AN_COMPLETE,
  419. XGBE_AN_NO_LINK,
  420. XGBE_AN_ERROR,
  421. };
  422. enum xgbe_rx {
  423. XGBE_RX_BPA = 0,
  424. XGBE_RX_XNP,
  425. XGBE_RX_COMPLETE,
  426. XGBE_RX_ERROR,
  427. };
  428. enum xgbe_mode {
  429. XGBE_MODE_KR = 0,
  430. XGBE_MODE_KX,
  431. };
  432. enum xgbe_speedset {
  433. XGBE_SPEEDSET_1000_10000 = 0,
  434. XGBE_SPEEDSET_2500_10000,
  435. };
  436. struct xgbe_phy {
  437. u32 supported;
  438. u32 advertising;
  439. u32 lp_advertising;
  440. int address;
  441. int autoneg;
  442. int speed;
  443. int duplex;
  444. int link;
  445. int pause_autoneg;
  446. int tx_pause;
  447. int rx_pause;
  448. };
  449. struct xgbe_mmc_stats {
  450. /* Tx Stats */
  451. u64 txoctetcount_gb;
  452. u64 txframecount_gb;
  453. u64 txbroadcastframes_g;
  454. u64 txmulticastframes_g;
  455. u64 tx64octets_gb;
  456. u64 tx65to127octets_gb;
  457. u64 tx128to255octets_gb;
  458. u64 tx256to511octets_gb;
  459. u64 tx512to1023octets_gb;
  460. u64 tx1024tomaxoctets_gb;
  461. u64 txunicastframes_gb;
  462. u64 txmulticastframes_gb;
  463. u64 txbroadcastframes_gb;
  464. u64 txunderflowerror;
  465. u64 txoctetcount_g;
  466. u64 txframecount_g;
  467. u64 txpauseframes;
  468. u64 txvlanframes_g;
  469. /* Rx Stats */
  470. u64 rxframecount_gb;
  471. u64 rxoctetcount_gb;
  472. u64 rxoctetcount_g;
  473. u64 rxbroadcastframes_g;
  474. u64 rxmulticastframes_g;
  475. u64 rxcrcerror;
  476. u64 rxrunterror;
  477. u64 rxjabbererror;
  478. u64 rxundersize_g;
  479. u64 rxoversize_g;
  480. u64 rx64octets_gb;
  481. u64 rx65to127octets_gb;
  482. u64 rx128to255octets_gb;
  483. u64 rx256to511octets_gb;
  484. u64 rx512to1023octets_gb;
  485. u64 rx1024tomaxoctets_gb;
  486. u64 rxunicastframes_g;
  487. u64 rxlengtherror;
  488. u64 rxoutofrangetype;
  489. u64 rxpauseframes;
  490. u64 rxfifooverflow;
  491. u64 rxvlanframes_gb;
  492. u64 rxwatchdogerror;
  493. };
  494. struct xgbe_ext_stats {
  495. u64 tx_tso_packets;
  496. u64 rx_split_header_packets;
  497. u64 rx_buffer_unavailable;
  498. };
  499. struct xgbe_hw_if {
  500. int (*tx_complete)(struct xgbe_ring_desc *);
  501. int (*set_mac_address)(struct xgbe_prv_data *, u8 *addr);
  502. int (*config_rx_mode)(struct xgbe_prv_data *);
  503. int (*enable_rx_csum)(struct xgbe_prv_data *);
  504. int (*disable_rx_csum)(struct xgbe_prv_data *);
  505. int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
  506. int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
  507. int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
  508. int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
  509. int (*update_vlan_hash_table)(struct xgbe_prv_data *);
  510. int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
  511. void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
  512. int (*set_gmii_speed)(struct xgbe_prv_data *);
  513. int (*set_gmii_2500_speed)(struct xgbe_prv_data *);
  514. int (*set_xgmii_speed)(struct xgbe_prv_data *);
  515. void (*enable_tx)(struct xgbe_prv_data *);
  516. void (*disable_tx)(struct xgbe_prv_data *);
  517. void (*enable_rx)(struct xgbe_prv_data *);
  518. void (*disable_rx)(struct xgbe_prv_data *);
  519. void (*powerup_tx)(struct xgbe_prv_data *);
  520. void (*powerdown_tx)(struct xgbe_prv_data *);
  521. void (*powerup_rx)(struct xgbe_prv_data *);
  522. void (*powerdown_rx)(struct xgbe_prv_data *);
  523. int (*init)(struct xgbe_prv_data *);
  524. int (*exit)(struct xgbe_prv_data *);
  525. int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
  526. int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
  527. void (*dev_xmit)(struct xgbe_channel *);
  528. int (*dev_read)(struct xgbe_channel *);
  529. void (*tx_desc_init)(struct xgbe_channel *);
  530. void (*rx_desc_init)(struct xgbe_channel *);
  531. void (*tx_desc_reset)(struct xgbe_ring_data *);
  532. void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
  533. unsigned int);
  534. int (*is_last_desc)(struct xgbe_ring_desc *);
  535. int (*is_context_desc)(struct xgbe_ring_desc *);
  536. void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
  537. /* For FLOW ctrl */
  538. int (*config_tx_flow_control)(struct xgbe_prv_data *);
  539. int (*config_rx_flow_control)(struct xgbe_prv_data *);
  540. /* For RX coalescing */
  541. int (*config_rx_coalesce)(struct xgbe_prv_data *);
  542. int (*config_tx_coalesce)(struct xgbe_prv_data *);
  543. unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
  544. unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
  545. /* For RX and TX threshold config */
  546. int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
  547. int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
  548. /* For RX and TX Store and Forward Mode config */
  549. int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
  550. int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
  551. /* For TX DMA Operate on Second Frame config */
  552. int (*config_osp_mode)(struct xgbe_prv_data *);
  553. /* For RX and TX PBL config */
  554. int (*config_rx_pbl_val)(struct xgbe_prv_data *);
  555. int (*get_rx_pbl_val)(struct xgbe_prv_data *);
  556. int (*config_tx_pbl_val)(struct xgbe_prv_data *);
  557. int (*get_tx_pbl_val)(struct xgbe_prv_data *);
  558. int (*config_pblx8)(struct xgbe_prv_data *);
  559. /* For MMC statistics */
  560. void (*rx_mmc_int)(struct xgbe_prv_data *);
  561. void (*tx_mmc_int)(struct xgbe_prv_data *);
  562. void (*read_mmc_stats)(struct xgbe_prv_data *);
  563. /* For Timestamp config */
  564. int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
  565. void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
  566. void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
  567. unsigned int nsec);
  568. u64 (*get_tstamp_time)(struct xgbe_prv_data *);
  569. u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
  570. /* For Data Center Bridging config */
  571. void (*config_dcb_tc)(struct xgbe_prv_data *);
  572. void (*config_dcb_pfc)(struct xgbe_prv_data *);
  573. /* For Receive Side Scaling */
  574. int (*enable_rss)(struct xgbe_prv_data *);
  575. int (*disable_rss)(struct xgbe_prv_data *);
  576. int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
  577. int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
  578. };
  579. struct xgbe_phy_if {
  580. /* For initial PHY setup */
  581. void (*phy_init)(struct xgbe_prv_data *);
  582. /* For PHY support when setting device up/down */
  583. int (*phy_reset)(struct xgbe_prv_data *);
  584. int (*phy_start)(struct xgbe_prv_data *);
  585. void (*phy_stop)(struct xgbe_prv_data *);
  586. /* For PHY support while device is up */
  587. void (*phy_status)(struct xgbe_prv_data *);
  588. int (*phy_config_aneg)(struct xgbe_prv_data *);
  589. };
  590. struct xgbe_desc_if {
  591. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  592. void (*free_ring_resources)(struct xgbe_prv_data *);
  593. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  594. int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
  595. struct xgbe_ring_data *);
  596. void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  597. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  598. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  599. };
  600. /* This structure contains flags that indicate what hardware features
  601. * or configurations are present in the device.
  602. */
  603. struct xgbe_hw_features {
  604. /* HW Version */
  605. unsigned int version;
  606. /* HW Feature Register0 */
  607. unsigned int gmii; /* 1000 Mbps support */
  608. unsigned int vlhash; /* VLAN Hash Filter */
  609. unsigned int sma; /* SMA(MDIO) Interface */
  610. unsigned int rwk; /* PMT remote wake-up packet */
  611. unsigned int mgk; /* PMT magic packet */
  612. unsigned int mmc; /* RMON module */
  613. unsigned int aoe; /* ARP Offload */
  614. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  615. unsigned int eee; /* Energy Efficient Ethernet */
  616. unsigned int tx_coe; /* Tx Checksum Offload */
  617. unsigned int rx_coe; /* Rx Checksum Offload */
  618. unsigned int addn_mac; /* Additional MAC Addresses */
  619. unsigned int ts_src; /* Timestamp Source */
  620. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  621. /* HW Feature Register1 */
  622. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  623. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  624. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  625. unsigned int dma_width; /* DMA width */
  626. unsigned int dcb; /* DCB Feature */
  627. unsigned int sph; /* Split Header Feature */
  628. unsigned int tso; /* TCP Segmentation Offload */
  629. unsigned int dma_debug; /* DMA Debug Registers */
  630. unsigned int rss; /* Receive Side Scaling */
  631. unsigned int tc_cnt; /* Number of Traffic Classes */
  632. unsigned int hash_table_size; /* Hash Table Size */
  633. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  634. /* HW Feature Register2 */
  635. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  636. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  637. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  638. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  639. unsigned int pps_out_num; /* Number of PPS outputs */
  640. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  641. };
  642. struct xgbe_prv_data {
  643. struct net_device *netdev;
  644. struct platform_device *pdev;
  645. struct acpi_device *adev;
  646. struct device *dev;
  647. /* ACPI or DT flag */
  648. unsigned int use_acpi;
  649. /* XGMAC/XPCS related mmio registers */
  650. void __iomem *xgmac_regs; /* XGMAC CSRs */
  651. void __iomem *xpcs_regs; /* XPCS MMD registers */
  652. void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
  653. void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
  654. void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
  655. /* Overall device lock */
  656. spinlock_t lock;
  657. /* XPCS indirect addressing mutex */
  658. struct mutex xpcs_mutex;
  659. /* RSS addressing mutex */
  660. struct mutex rss_mutex;
  661. /* Flags representing xgbe_state */
  662. unsigned long dev_state;
  663. int dev_irq;
  664. unsigned int per_channel_irq;
  665. struct xgbe_hw_if hw_if;
  666. struct xgbe_phy_if phy_if;
  667. struct xgbe_desc_if desc_if;
  668. /* AXI DMA settings */
  669. unsigned int coherent;
  670. unsigned int axdomain;
  671. unsigned int arcache;
  672. unsigned int awcache;
  673. /* Service routine support */
  674. struct workqueue_struct *dev_workqueue;
  675. struct work_struct service_work;
  676. struct timer_list service_timer;
  677. /* Rings for Tx/Rx on a DMA channel */
  678. struct xgbe_channel *channel;
  679. unsigned int channel_count;
  680. unsigned int tx_ring_count;
  681. unsigned int tx_desc_count;
  682. unsigned int rx_ring_count;
  683. unsigned int rx_desc_count;
  684. unsigned int tx_q_count;
  685. unsigned int rx_q_count;
  686. /* Tx/Rx common settings */
  687. unsigned int pblx8;
  688. /* Tx settings */
  689. unsigned int tx_sf_mode;
  690. unsigned int tx_threshold;
  691. unsigned int tx_pbl;
  692. unsigned int tx_osp_mode;
  693. /* Rx settings */
  694. unsigned int rx_sf_mode;
  695. unsigned int rx_threshold;
  696. unsigned int rx_pbl;
  697. /* Tx coalescing settings */
  698. unsigned int tx_usecs;
  699. unsigned int tx_frames;
  700. /* Rx coalescing settings */
  701. unsigned int rx_riwt;
  702. unsigned int rx_usecs;
  703. unsigned int rx_frames;
  704. /* Current Rx buffer size */
  705. unsigned int rx_buf_size;
  706. /* Flow control settings */
  707. unsigned int pause_autoneg;
  708. unsigned int tx_pause;
  709. unsigned int rx_pause;
  710. /* Receive Side Scaling settings */
  711. u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
  712. u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
  713. u32 rss_options;
  714. /* Netdev related settings */
  715. unsigned char mac_addr[ETH_ALEN];
  716. netdev_features_t netdev_features;
  717. struct napi_struct napi;
  718. struct xgbe_mmc_stats mmc_stats;
  719. struct xgbe_ext_stats ext_stats;
  720. /* Filtering support */
  721. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  722. /* Device clocks */
  723. struct clk *sysclk;
  724. unsigned long sysclk_rate;
  725. struct clk *ptpclk;
  726. unsigned long ptpclk_rate;
  727. /* Timestamp support */
  728. spinlock_t tstamp_lock;
  729. struct ptp_clock_info ptp_clock_info;
  730. struct ptp_clock *ptp_clock;
  731. struct hwtstamp_config tstamp_config;
  732. struct cyclecounter tstamp_cc;
  733. struct timecounter tstamp_tc;
  734. unsigned int tstamp_addend;
  735. struct work_struct tx_tstamp_work;
  736. struct sk_buff *tx_tstamp_skb;
  737. u64 tx_tstamp;
  738. /* DCB support */
  739. struct ieee_ets *ets;
  740. struct ieee_pfc *pfc;
  741. unsigned int q2tc_map[XGBE_MAX_QUEUES];
  742. unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
  743. /* Hardware features of the device */
  744. struct xgbe_hw_features hw_feat;
  745. /* Device restart work structure */
  746. struct work_struct restart_work;
  747. /* Keeps track of power mode */
  748. unsigned int power_down;
  749. /* Network interface message level setting */
  750. u32 msg_enable;
  751. /* Current PHY settings */
  752. phy_interface_t phy_mode;
  753. int phy_link;
  754. int phy_speed;
  755. /* MDIO/PHY related settings */
  756. struct xgbe_phy phy;
  757. int mdio_mmd;
  758. unsigned long link_check;
  759. char an_name[IFNAMSIZ + 32];
  760. struct workqueue_struct *an_workqueue;
  761. int an_irq;
  762. struct work_struct an_irq_work;
  763. unsigned int speed_set;
  764. /* SerDes UEFI configurable settings.
  765. * Switching between modes/speeds requires new values for some
  766. * SerDes settings. The values can be supplied as device
  767. * properties in array format. The first array entry is for
  768. * 1GbE, second for 2.5GbE and third for 10GbE
  769. */
  770. u32 serdes_blwc[XGBE_SPEEDS];
  771. u32 serdes_cdr_rate[XGBE_SPEEDS];
  772. u32 serdes_pq_skew[XGBE_SPEEDS];
  773. u32 serdes_tx_amp[XGBE_SPEEDS];
  774. u32 serdes_dfe_tap_cfg[XGBE_SPEEDS];
  775. u32 serdes_dfe_tap_ena[XGBE_SPEEDS];
  776. /* Auto-negotiation state machine support */
  777. struct mutex an_mutex;
  778. enum xgbe_an an_result;
  779. enum xgbe_an an_state;
  780. enum xgbe_rx kr_state;
  781. enum xgbe_rx kx_state;
  782. struct work_struct an_work;
  783. unsigned int an_supported;
  784. unsigned int parallel_detect;
  785. unsigned int fec_ability;
  786. unsigned long an_start;
  787. unsigned int lpm_ctrl; /* CTRL1 for resume */
  788. #ifdef CONFIG_DEBUG_FS
  789. struct dentry *xgbe_debugfs;
  790. unsigned int debugfs_xgmac_reg;
  791. unsigned int debugfs_xpcs_mmd;
  792. unsigned int debugfs_xpcs_reg;
  793. #endif
  794. };
  795. /* Function prototypes*/
  796. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  797. void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
  798. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  799. struct net_device_ops *xgbe_get_netdev_ops(void);
  800. struct ethtool_ops *xgbe_get_ethtool_ops(void);
  801. #ifdef CONFIG_AMD_XGBE_DCB
  802. const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
  803. #endif
  804. void xgbe_ptp_register(struct xgbe_prv_data *);
  805. void xgbe_ptp_unregister(struct xgbe_prv_data *);
  806. void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  807. unsigned int, unsigned int, unsigned int);
  808. void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  809. unsigned int);
  810. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  811. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  812. int xgbe_powerup(struct net_device *, unsigned int);
  813. int xgbe_powerdown(struct net_device *, unsigned int);
  814. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  815. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  816. #ifdef CONFIG_DEBUG_FS
  817. void xgbe_debugfs_init(struct xgbe_prv_data *);
  818. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  819. #else
  820. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  821. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  822. #endif /* CONFIG_DEBUG_FS */
  823. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  824. #if 0
  825. #define YDEBUG
  826. #define YDEBUG_MDIO
  827. #endif
  828. /* For debug prints */
  829. #ifdef YDEBUG
  830. #define DBGPR(x...) pr_alert(x)
  831. #else
  832. #define DBGPR(x...) do { } while (0)
  833. #endif
  834. #ifdef YDEBUG_MDIO
  835. #define DBGPR_MDIO(x...) pr_alert(x)
  836. #else
  837. #define DBGPR_MDIO(x...) do { } while (0)
  838. #endif
  839. #endif