xgbe.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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-2016 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-2016 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_tc)(struct xgbe_prv_data *);
  572. void (*config_dcb_tc)(struct xgbe_prv_data *);
  573. void (*config_dcb_pfc)(struct xgbe_prv_data *);
  574. /* For Receive Side Scaling */
  575. int (*enable_rss)(struct xgbe_prv_data *);
  576. int (*disable_rss)(struct xgbe_prv_data *);
  577. int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
  578. int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
  579. };
  580. struct xgbe_phy_if {
  581. /* For initial PHY setup */
  582. void (*phy_init)(struct xgbe_prv_data *);
  583. /* For PHY support when setting device up/down */
  584. int (*phy_reset)(struct xgbe_prv_data *);
  585. int (*phy_start)(struct xgbe_prv_data *);
  586. void (*phy_stop)(struct xgbe_prv_data *);
  587. /* For PHY support while device is up */
  588. void (*phy_status)(struct xgbe_prv_data *);
  589. int (*phy_config_aneg)(struct xgbe_prv_data *);
  590. };
  591. struct xgbe_desc_if {
  592. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  593. void (*free_ring_resources)(struct xgbe_prv_data *);
  594. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  595. int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
  596. struct xgbe_ring_data *);
  597. void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  598. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  599. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  600. };
  601. /* This structure contains flags that indicate what hardware features
  602. * or configurations are present in the device.
  603. */
  604. struct xgbe_hw_features {
  605. /* HW Version */
  606. unsigned int version;
  607. /* HW Feature Register0 */
  608. unsigned int gmii; /* 1000 Mbps support */
  609. unsigned int vlhash; /* VLAN Hash Filter */
  610. unsigned int sma; /* SMA(MDIO) Interface */
  611. unsigned int rwk; /* PMT remote wake-up packet */
  612. unsigned int mgk; /* PMT magic packet */
  613. unsigned int mmc; /* RMON module */
  614. unsigned int aoe; /* ARP Offload */
  615. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  616. unsigned int eee; /* Energy Efficient Ethernet */
  617. unsigned int tx_coe; /* Tx Checksum Offload */
  618. unsigned int rx_coe; /* Rx Checksum Offload */
  619. unsigned int addn_mac; /* Additional MAC Addresses */
  620. unsigned int ts_src; /* Timestamp Source */
  621. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  622. /* HW Feature Register1 */
  623. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  624. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  625. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  626. unsigned int dma_width; /* DMA width */
  627. unsigned int dcb; /* DCB Feature */
  628. unsigned int sph; /* Split Header Feature */
  629. unsigned int tso; /* TCP Segmentation Offload */
  630. unsigned int dma_debug; /* DMA Debug Registers */
  631. unsigned int rss; /* Receive Side Scaling */
  632. unsigned int tc_cnt; /* Number of Traffic Classes */
  633. unsigned int hash_table_size; /* Hash Table Size */
  634. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  635. /* HW Feature Register2 */
  636. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  637. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  638. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  639. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  640. unsigned int pps_out_num; /* Number of PPS outputs */
  641. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  642. };
  643. struct xgbe_prv_data {
  644. struct net_device *netdev;
  645. struct platform_device *pdev;
  646. struct acpi_device *adev;
  647. struct device *dev;
  648. /* ACPI or DT flag */
  649. unsigned int use_acpi;
  650. /* XGMAC/XPCS related mmio registers */
  651. void __iomem *xgmac_regs; /* XGMAC CSRs */
  652. void __iomem *xpcs_regs; /* XPCS MMD registers */
  653. void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
  654. void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
  655. void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
  656. /* Overall device lock */
  657. spinlock_t lock;
  658. /* XPCS indirect addressing lock */
  659. spinlock_t xpcs_lock;
  660. /* RSS addressing mutex */
  661. struct mutex rss_mutex;
  662. /* Flags representing xgbe_state */
  663. unsigned long dev_state;
  664. int dev_irq;
  665. unsigned int per_channel_irq;
  666. struct xgbe_hw_if hw_if;
  667. struct xgbe_phy_if phy_if;
  668. struct xgbe_desc_if desc_if;
  669. /* AXI DMA settings */
  670. unsigned int coherent;
  671. unsigned int axdomain;
  672. unsigned int arcache;
  673. unsigned int awcache;
  674. /* Service routine support */
  675. struct workqueue_struct *dev_workqueue;
  676. struct work_struct service_work;
  677. struct timer_list service_timer;
  678. /* Rings for Tx/Rx on a DMA channel */
  679. struct xgbe_channel *channel;
  680. unsigned int channel_count;
  681. unsigned int tx_ring_count;
  682. unsigned int tx_desc_count;
  683. unsigned int rx_ring_count;
  684. unsigned int rx_desc_count;
  685. unsigned int tx_q_count;
  686. unsigned int rx_q_count;
  687. /* Tx/Rx common settings */
  688. unsigned int pblx8;
  689. /* Tx settings */
  690. unsigned int tx_sf_mode;
  691. unsigned int tx_threshold;
  692. unsigned int tx_pbl;
  693. unsigned int tx_osp_mode;
  694. /* Rx settings */
  695. unsigned int rx_sf_mode;
  696. unsigned int rx_threshold;
  697. unsigned int rx_pbl;
  698. /* Tx coalescing settings */
  699. unsigned int tx_usecs;
  700. unsigned int tx_frames;
  701. /* Rx coalescing settings */
  702. unsigned int rx_riwt;
  703. unsigned int rx_usecs;
  704. unsigned int rx_frames;
  705. /* Current Rx buffer size */
  706. unsigned int rx_buf_size;
  707. /* Flow control settings */
  708. unsigned int pause_autoneg;
  709. unsigned int tx_pause;
  710. unsigned int rx_pause;
  711. /* Receive Side Scaling settings */
  712. u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
  713. u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
  714. u32 rss_options;
  715. /* Netdev related settings */
  716. unsigned char mac_addr[ETH_ALEN];
  717. netdev_features_t netdev_features;
  718. struct napi_struct napi;
  719. struct xgbe_mmc_stats mmc_stats;
  720. struct xgbe_ext_stats ext_stats;
  721. /* Filtering support */
  722. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  723. /* Device clocks */
  724. struct clk *sysclk;
  725. unsigned long sysclk_rate;
  726. struct clk *ptpclk;
  727. unsigned long ptpclk_rate;
  728. /* Timestamp support */
  729. spinlock_t tstamp_lock;
  730. struct ptp_clock_info ptp_clock_info;
  731. struct ptp_clock *ptp_clock;
  732. struct hwtstamp_config tstamp_config;
  733. struct cyclecounter tstamp_cc;
  734. struct timecounter tstamp_tc;
  735. unsigned int tstamp_addend;
  736. struct work_struct tx_tstamp_work;
  737. struct sk_buff *tx_tstamp_skb;
  738. u64 tx_tstamp;
  739. /* DCB support */
  740. struct ieee_ets *ets;
  741. struct ieee_pfc *pfc;
  742. unsigned int q2tc_map[XGBE_MAX_QUEUES];
  743. unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
  744. u8 num_tcs;
  745. /* Hardware features of the device */
  746. struct xgbe_hw_features hw_feat;
  747. /* Device restart work structure */
  748. struct work_struct restart_work;
  749. /* Keeps track of power mode */
  750. unsigned int power_down;
  751. /* Network interface message level setting */
  752. u32 msg_enable;
  753. /* Current PHY settings */
  754. phy_interface_t phy_mode;
  755. int phy_link;
  756. int phy_speed;
  757. /* MDIO/PHY related settings */
  758. struct xgbe_phy phy;
  759. int mdio_mmd;
  760. unsigned long link_check;
  761. char an_name[IFNAMSIZ + 32];
  762. struct workqueue_struct *an_workqueue;
  763. int an_irq;
  764. struct work_struct an_irq_work;
  765. unsigned int speed_set;
  766. /* SerDes UEFI configurable settings.
  767. * Switching between modes/speeds requires new values for some
  768. * SerDes settings. The values can be supplied as device
  769. * properties in array format. The first array entry is for
  770. * 1GbE, second for 2.5GbE and third for 10GbE
  771. */
  772. u32 serdes_blwc[XGBE_SPEEDS];
  773. u32 serdes_cdr_rate[XGBE_SPEEDS];
  774. u32 serdes_pq_skew[XGBE_SPEEDS];
  775. u32 serdes_tx_amp[XGBE_SPEEDS];
  776. u32 serdes_dfe_tap_cfg[XGBE_SPEEDS];
  777. u32 serdes_dfe_tap_ena[XGBE_SPEEDS];
  778. /* Auto-negotiation state machine support */
  779. unsigned int an_int;
  780. struct mutex an_mutex;
  781. enum xgbe_an an_result;
  782. enum xgbe_an an_state;
  783. enum xgbe_rx kr_state;
  784. enum xgbe_rx kx_state;
  785. struct work_struct an_work;
  786. unsigned int an_supported;
  787. unsigned int parallel_detect;
  788. unsigned int fec_ability;
  789. unsigned long an_start;
  790. unsigned int lpm_ctrl; /* CTRL1 for resume */
  791. #ifdef CONFIG_DEBUG_FS
  792. struct dentry *xgbe_debugfs;
  793. unsigned int debugfs_xgmac_reg;
  794. unsigned int debugfs_xpcs_mmd;
  795. unsigned int debugfs_xpcs_reg;
  796. #endif
  797. };
  798. /* Function prototypes*/
  799. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  800. void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
  801. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  802. const struct net_device_ops *xgbe_get_netdev_ops(void);
  803. const struct ethtool_ops *xgbe_get_ethtool_ops(void);
  804. #ifdef CONFIG_AMD_XGBE_DCB
  805. const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
  806. #endif
  807. void xgbe_ptp_register(struct xgbe_prv_data *);
  808. void xgbe_ptp_unregister(struct xgbe_prv_data *);
  809. void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  810. unsigned int, unsigned int, unsigned int);
  811. void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  812. unsigned int);
  813. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  814. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  815. int xgbe_powerup(struct net_device *, unsigned int);
  816. int xgbe_powerdown(struct net_device *, unsigned int);
  817. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  818. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  819. #ifdef CONFIG_DEBUG_FS
  820. void xgbe_debugfs_init(struct xgbe_prv_data *);
  821. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  822. #else
  823. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  824. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  825. #endif /* CONFIG_DEBUG_FS */
  826. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  827. #if 0
  828. #define YDEBUG
  829. #define YDEBUG_MDIO
  830. #endif
  831. /* For debug prints */
  832. #ifdef YDEBUG
  833. #define DBGPR(x...) pr_alert(x)
  834. #else
  835. #define DBGPR(x...) do { } while (0)
  836. #endif
  837. #ifdef YDEBUG_MDIO
  838. #define DBGPR_MDIO(x...) pr_alert(x)
  839. #else
  840. #define DBGPR_MDIO(x...) do { } while (0)
  841. #endif
  842. #endif