xgbe.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391
  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. #include <linux/completion.h>
  129. #include <linux/cpumask.h>
  130. #include <linux/interrupt.h>
  131. #include <linux/dcache.h>
  132. #include <linux/ethtool.h>
  133. #include <linux/list.h>
  134. #define XGBE_DRV_NAME "amd-xgbe"
  135. #define XGBE_DRV_DESC "AMD 10 Gigabit Ethernet Driver"
  136. /* Descriptor related defines */
  137. #define XGBE_TX_DESC_CNT 512
  138. #define XGBE_TX_DESC_MIN_FREE (XGBE_TX_DESC_CNT >> 3)
  139. #define XGBE_TX_DESC_MAX_PROC (XGBE_TX_DESC_CNT >> 1)
  140. #define XGBE_RX_DESC_CNT 512
  141. #define XGBE_TX_DESC_CNT_MIN 64
  142. #define XGBE_TX_DESC_CNT_MAX 4096
  143. #define XGBE_RX_DESC_CNT_MIN 64
  144. #define XGBE_RX_DESC_CNT_MAX 4096
  145. #define XGBE_TX_MAX_BUF_SIZE (0x3fff & ~(64 - 1))
  146. /* Descriptors required for maximum contiguous TSO/GSO packet */
  147. #define XGBE_TX_MAX_SPLIT \
  148. ((GSO_LEGACY_MAX_SIZE / XGBE_TX_MAX_BUF_SIZE) + 1)
  149. /* Maximum possible descriptors needed for an SKB:
  150. * - Maximum number of SKB frags
  151. * - Maximum descriptors for contiguous TSO/GSO packet
  152. * - Possible context descriptor
  153. * - Possible TSO header descriptor
  154. */
  155. #define XGBE_TX_MAX_DESCS (MAX_SKB_FRAGS + XGBE_TX_MAX_SPLIT + 2)
  156. #define XGBE_RX_MIN_BUF_SIZE (ETH_FRAME_LEN + ETH_FCS_LEN + VLAN_HLEN)
  157. #define XGBE_RX_BUF_ALIGN 64
  158. #define XGBE_SKB_ALLOC_SIZE 256
  159. #define XGBE_SPH_HDSMS_SIZE 2 /* Keep in sync with SKB_ALLOC_SIZE */
  160. #define XGBE_MAX_DMA_CHANNELS 16
  161. #define XGBE_MAX_QUEUES 16
  162. #define XGBE_PRIORITY_QUEUES 8
  163. #define XGBE_DMA_STOP_TIMEOUT 1
  164. /* DMA cache settings - Outer sharable, write-back, write-allocate */
  165. #define XGBE_DMA_OS_ARCR 0x002b2b2b
  166. #define XGBE_DMA_OS_AWCR 0x2f2f2f2f
  167. /* DMA cache settings - System, no caches used */
  168. #define XGBE_DMA_SYS_ARCR 0x00303030
  169. #define XGBE_DMA_SYS_AWCR 0x30303030
  170. /* DMA cache settings - PCI device */
  171. #define XGBE_DMA_PCI_ARCR 0x000f0f0f
  172. #define XGBE_DMA_PCI_AWCR 0x0f0f0f0f
  173. #define XGBE_DMA_PCI_AWARCR 0x00000f0f
  174. /* DMA channel interrupt modes */
  175. #define XGBE_IRQ_MODE_EDGE 0
  176. #define XGBE_IRQ_MODE_LEVEL 1
  177. #define XGMAC_MIN_PACKET 60
  178. #define XGMAC_STD_PACKET_MTU 1500
  179. #define XGMAC_MAX_STD_PACKET 1518
  180. #define XGMAC_JUMBO_PACKET_MTU 9000
  181. #define XGMAC_MAX_JUMBO_PACKET 9018
  182. #define XGMAC_ETH_PREAMBLE (12 + 8) /* Inter-frame gap + preamble */
  183. #define XGMAC_PFC_DATA_LEN 46
  184. #define XGMAC_PFC_DELAYS 14000
  185. #define XGMAC_PRIO_QUEUES(_cnt) \
  186. min_t(unsigned int, IEEE_8021QAZ_MAX_TCS, (_cnt))
  187. /* Common property names */
  188. #define XGBE_MAC_ADDR_PROPERTY "mac-address"
  189. #define XGBE_PHY_MODE_PROPERTY "phy-mode"
  190. #define XGBE_DMA_IRQS_PROPERTY "amd,per-channel-interrupt"
  191. #define XGBE_SPEEDSET_PROPERTY "amd,speed-set"
  192. /* Device-tree clock names */
  193. #define XGBE_DMA_CLOCK "dma_clk"
  194. #define XGBE_PTP_CLOCK "ptp_clk"
  195. /* ACPI property names */
  196. #define XGBE_ACPI_DMA_FREQ "amd,dma-freq"
  197. #define XGBE_ACPI_PTP_FREQ "amd,ptp-freq"
  198. /* PCI BAR mapping */
  199. #define XGBE_XGMAC_BAR 0
  200. #define XGBE_XPCS_BAR 1
  201. #define XGBE_MAC_PROP_OFFSET 0x1d000
  202. #define XGBE_I2C_CTRL_OFFSET 0x1e000
  203. /* PCI MSI/MSIx support */
  204. #define XGBE_MSI_BASE_COUNT 4
  205. #define XGBE_MSI_MIN_COUNT (XGBE_MSI_BASE_COUNT + 1)
  206. /* PCI clock frequencies */
  207. #define XGBE_V2_DMA_CLOCK_FREQ 500000000 /* 500 MHz */
  208. #define XGBE_V2_PTP_CLOCK_FREQ 125000000 /* 125 MHz */
  209. /* Timestamp support - values based on 50MHz PTP clock
  210. * 50MHz => 20 nsec
  211. */
  212. #define XGBE_TSTAMP_SSINC 20
  213. #define XGBE_TSTAMP_SNSINC 0
  214. /* Driver PMT macros */
  215. #define XGMAC_DRIVER_CONTEXT 1
  216. #define XGMAC_IOCTL_CONTEXT 2
  217. #define XGMAC_FIFO_MIN_ALLOC 2048
  218. #define XGMAC_FIFO_UNIT 256
  219. #define XGMAC_FIFO_ALIGN(_x) \
  220. (((_x) + XGMAC_FIFO_UNIT - 1) & ~(XGMAC_FIFO_UNIT - 1))
  221. #define XGMAC_FIFO_FC_OFF 2048
  222. #define XGMAC_FIFO_FC_MIN 4096
  223. #define XGBE_TC_MIN_QUANTUM 10
  224. /* Helper macro for descriptor handling
  225. * Always use XGBE_GET_DESC_DATA to access the descriptor data
  226. * since the index is free-running and needs to be and-ed
  227. * with the descriptor count value of the ring to index to
  228. * the proper descriptor data.
  229. */
  230. #define XGBE_GET_DESC_DATA(_ring, _idx) \
  231. ((_ring)->rdata + \
  232. ((_idx) & ((_ring)->rdesc_count - 1)))
  233. /* Default coalescing parameters */
  234. #define XGMAC_INIT_DMA_TX_USECS 1000
  235. #define XGMAC_INIT_DMA_TX_FRAMES 25
  236. #define XGMAC_MAX_DMA_RIWT 0xff
  237. #define XGMAC_INIT_DMA_RX_USECS 30
  238. #define XGMAC_INIT_DMA_RX_FRAMES 25
  239. /* Flow control queue count */
  240. #define XGMAC_MAX_FLOW_CONTROL_QUEUES 8
  241. /* Flow control threshold units */
  242. #define XGMAC_FLOW_CONTROL_UNIT 512
  243. #define XGMAC_FLOW_CONTROL_ALIGN(_x) \
  244. (((_x) + XGMAC_FLOW_CONTROL_UNIT - 1) & ~(XGMAC_FLOW_CONTROL_UNIT - 1))
  245. #define XGMAC_FLOW_CONTROL_VALUE(_x) \
  246. (((_x) < 1024) ? 0 : ((_x) / XGMAC_FLOW_CONTROL_UNIT) - 2)
  247. #define XGMAC_FLOW_CONTROL_MAX 33280
  248. /* Maximum MAC address hash table size (256 bits = 8 bytes) */
  249. #define XGBE_MAC_HASH_TABLE_SIZE 8
  250. /* Receive Side Scaling */
  251. #define XGBE_RSS_HASH_KEY_SIZE 40
  252. #define XGBE_RSS_MAX_TABLE_SIZE 256
  253. #define XGBE_RSS_LOOKUP_TABLE_TYPE 0
  254. #define XGBE_RSS_HASH_KEY_TYPE 1
  255. /* Auto-negotiation */
  256. #define XGBE_AN_MS_TIMEOUT 500
  257. #define XGBE_LINK_TIMEOUT 5
  258. #define XGBE_KR_TRAINING_WAIT_ITER 50
  259. #define XGBE_SGMII_AN_LINK_STATUS BIT(1)
  260. #define XGBE_SGMII_AN_LINK_SPEED (BIT(2) | BIT(3))
  261. #define XGBE_SGMII_AN_LINK_SPEED_100 0x04
  262. #define XGBE_SGMII_AN_LINK_SPEED_1000 0x08
  263. #define XGBE_SGMII_AN_LINK_DUPLEX BIT(4)
  264. /* ECC correctable error notification window (seconds) */
  265. #define XGBE_ECC_LIMIT 60
  266. /* MDIO port types */
  267. #define XGMAC_MAX_C22_PORT 3
  268. /* Link mode bit operations */
  269. #define XGBE_ZERO_SUP(_ls) \
  270. ethtool_link_ksettings_zero_link_mode((_ls), supported)
  271. #define XGBE_SET_SUP(_ls, _mode) \
  272. ethtool_link_ksettings_add_link_mode((_ls), supported, _mode)
  273. #define XGBE_CLR_SUP(_ls, _mode) \
  274. ethtool_link_ksettings_del_link_mode((_ls), supported, _mode)
  275. #define XGBE_IS_SUP(_ls, _mode) \
  276. ethtool_link_ksettings_test_link_mode((_ls), supported, _mode)
  277. #define XGBE_ZERO_ADV(_ls) \
  278. ethtool_link_ksettings_zero_link_mode((_ls), advertising)
  279. #define XGBE_SET_ADV(_ls, _mode) \
  280. ethtool_link_ksettings_add_link_mode((_ls), advertising, _mode)
  281. #define XGBE_CLR_ADV(_ls, _mode) \
  282. ethtool_link_ksettings_del_link_mode((_ls), advertising, _mode)
  283. #define XGBE_ADV(_ls, _mode) \
  284. ethtool_link_ksettings_test_link_mode((_ls), advertising, _mode)
  285. #define XGBE_ZERO_LP_ADV(_ls) \
  286. ethtool_link_ksettings_zero_link_mode((_ls), lp_advertising)
  287. #define XGBE_SET_LP_ADV(_ls, _mode) \
  288. ethtool_link_ksettings_add_link_mode((_ls), lp_advertising, _mode)
  289. #define XGBE_CLR_LP_ADV(_ls, _mode) \
  290. ethtool_link_ksettings_del_link_mode((_ls), lp_advertising, _mode)
  291. #define XGBE_LP_ADV(_ls, _mode) \
  292. ethtool_link_ksettings_test_link_mode((_ls), lp_advertising, _mode)
  293. #define XGBE_LM_COPY(_dst, _dname, _src, _sname) \
  294. bitmap_copy((_dst)->link_modes._dname, \
  295. (_src)->link_modes._sname, \
  296. __ETHTOOL_LINK_MODE_MASK_NBITS)
  297. struct xgbe_prv_data;
  298. struct xgbe_packet_data {
  299. struct sk_buff *skb;
  300. unsigned int attributes;
  301. unsigned int errors;
  302. unsigned int rdesc_count;
  303. unsigned int length;
  304. unsigned int header_len;
  305. unsigned int tcp_header_len;
  306. unsigned int tcp_payload_len;
  307. unsigned short mss;
  308. unsigned short vlan_ctag;
  309. u64 rx_tstamp;
  310. u32 rss_hash;
  311. enum pkt_hash_types rss_hash_type;
  312. unsigned int tx_packets;
  313. unsigned int tx_bytes;
  314. };
  315. /* Common Rx and Tx descriptor mapping */
  316. struct xgbe_ring_desc {
  317. __le32 desc0;
  318. __le32 desc1;
  319. __le32 desc2;
  320. __le32 desc3;
  321. };
  322. /* Page allocation related values */
  323. struct xgbe_page_alloc {
  324. struct page *pages;
  325. unsigned int pages_len;
  326. unsigned int pages_offset;
  327. dma_addr_t pages_dma;
  328. };
  329. /* Ring entry buffer data */
  330. struct xgbe_buffer_data {
  331. struct xgbe_page_alloc pa;
  332. struct xgbe_page_alloc pa_unmap;
  333. dma_addr_t dma_base;
  334. unsigned long dma_off;
  335. unsigned int dma_len;
  336. };
  337. /* Tx-related ring data */
  338. struct xgbe_tx_ring_data {
  339. unsigned int packets; /* BQL packet count */
  340. unsigned int bytes; /* BQL byte count */
  341. };
  342. /* Rx-related ring data */
  343. struct xgbe_rx_ring_data {
  344. struct xgbe_buffer_data hdr; /* Header locations */
  345. struct xgbe_buffer_data buf; /* Payload locations */
  346. unsigned short hdr_len; /* Length of received header */
  347. unsigned short len; /* Length of received packet */
  348. };
  349. /* Structure used to hold information related to the descriptor
  350. * and the packet associated with the descriptor (always use
  351. * the XGBE_GET_DESC_DATA macro to access this data from the ring)
  352. */
  353. struct xgbe_ring_data {
  354. struct xgbe_ring_desc *rdesc; /* Virtual address of descriptor */
  355. dma_addr_t rdesc_dma; /* DMA address of descriptor */
  356. struct sk_buff *skb; /* Virtual address of SKB */
  357. dma_addr_t skb_dma; /* DMA address of SKB data */
  358. unsigned int skb_dma_len; /* Length of SKB DMA area */
  359. struct xgbe_tx_ring_data tx; /* Tx-related data */
  360. struct xgbe_rx_ring_data rx; /* Rx-related data */
  361. unsigned int mapped_as_page;
  362. /* Incomplete receive save location. If the budget is exhausted
  363. * or the last descriptor (last normal descriptor or a following
  364. * context descriptor) has not been DMA'd yet the current state
  365. * of the receive processing needs to be saved.
  366. */
  367. unsigned int state_saved;
  368. struct {
  369. struct sk_buff *skb;
  370. unsigned int len;
  371. unsigned int error;
  372. } state;
  373. };
  374. struct xgbe_ring {
  375. /* Ring lock - used just for TX rings at the moment */
  376. spinlock_t lock;
  377. /* Per packet related information */
  378. struct xgbe_packet_data packet_data;
  379. /* Virtual/DMA addresses and count of allocated descriptor memory */
  380. struct xgbe_ring_desc *rdesc;
  381. dma_addr_t rdesc_dma;
  382. unsigned int rdesc_count;
  383. /* Array of descriptor data corresponding the descriptor memory
  384. * (always use the XGBE_GET_DESC_DATA macro to access this data)
  385. */
  386. struct xgbe_ring_data *rdata;
  387. /* Page allocation for RX buffers */
  388. struct xgbe_page_alloc rx_hdr_pa;
  389. struct xgbe_page_alloc rx_buf_pa;
  390. int node;
  391. /* Ring index values
  392. * cur - Tx: index of descriptor to be used for current transfer
  393. * Rx: index of descriptor to check for packet availability
  394. * dirty - Tx: index of descriptor to check for transfer complete
  395. * Rx: index of descriptor to check for buffer reallocation
  396. */
  397. unsigned int cur;
  398. unsigned int dirty;
  399. /* Coalesce frame count used for interrupt bit setting */
  400. unsigned int coalesce_count;
  401. union {
  402. struct {
  403. unsigned int queue_stopped;
  404. unsigned int xmit_more;
  405. unsigned short cur_mss;
  406. unsigned short cur_vlan_ctag;
  407. } tx;
  408. };
  409. } ____cacheline_aligned;
  410. /* Structure used to describe the descriptor rings associated with
  411. * a DMA channel.
  412. */
  413. struct xgbe_channel {
  414. char name[16];
  415. /* Address of private data area for device */
  416. struct xgbe_prv_data *pdata;
  417. /* Queue index and base address of queue's DMA registers */
  418. unsigned int queue_index;
  419. void __iomem *dma_regs;
  420. /* Per channel interrupt irq number */
  421. int dma_irq;
  422. char dma_irq_name[IFNAMSIZ + 32];
  423. /* Netdev related settings */
  424. struct napi_struct napi;
  425. /* Per channel interrupt enablement tracker */
  426. unsigned int curr_ier;
  427. unsigned int saved_ier;
  428. unsigned int tx_timer_active;
  429. struct timer_list tx_timer;
  430. struct xgbe_ring *tx_ring;
  431. struct xgbe_ring *rx_ring;
  432. int node;
  433. cpumask_t affinity_mask;
  434. } ____cacheline_aligned;
  435. enum xgbe_state {
  436. XGBE_DOWN,
  437. XGBE_LINK_INIT,
  438. XGBE_LINK_ERR,
  439. XGBE_STOPPED,
  440. };
  441. enum xgbe_int {
  442. XGMAC_INT_DMA_CH_SR_TI,
  443. XGMAC_INT_DMA_CH_SR_TPS,
  444. XGMAC_INT_DMA_CH_SR_TBU,
  445. XGMAC_INT_DMA_CH_SR_RI,
  446. XGMAC_INT_DMA_CH_SR_RBU,
  447. XGMAC_INT_DMA_CH_SR_RPS,
  448. XGMAC_INT_DMA_CH_SR_TI_RI,
  449. XGMAC_INT_DMA_CH_SR_FBE,
  450. XGMAC_INT_DMA_ALL,
  451. };
  452. enum xgbe_int_state {
  453. XGMAC_INT_STATE_SAVE,
  454. XGMAC_INT_STATE_RESTORE,
  455. };
  456. enum xgbe_ecc_sec {
  457. XGBE_ECC_SEC_TX,
  458. XGBE_ECC_SEC_RX,
  459. XGBE_ECC_SEC_DESC,
  460. };
  461. enum xgbe_speed {
  462. XGBE_SPEED_1000 = 0,
  463. XGBE_SPEED_2500,
  464. XGBE_SPEED_10000,
  465. XGBE_SPEEDS,
  466. };
  467. enum xgbe_xpcs_access {
  468. XGBE_XPCS_ACCESS_V1 = 0,
  469. XGBE_XPCS_ACCESS_V2,
  470. };
  471. enum xgbe_an_mode {
  472. XGBE_AN_MODE_CL73 = 0,
  473. XGBE_AN_MODE_CL73_REDRV,
  474. XGBE_AN_MODE_CL37,
  475. XGBE_AN_MODE_CL37_SGMII,
  476. XGBE_AN_MODE_NONE,
  477. };
  478. enum xgbe_an {
  479. XGBE_AN_READY = 0,
  480. XGBE_AN_PAGE_RECEIVED,
  481. XGBE_AN_INCOMPAT_LINK,
  482. XGBE_AN_COMPLETE,
  483. XGBE_AN_NO_LINK,
  484. XGBE_AN_ERROR,
  485. };
  486. enum xgbe_rx {
  487. XGBE_RX_BPA = 0,
  488. XGBE_RX_XNP,
  489. XGBE_RX_COMPLETE,
  490. XGBE_RX_ERROR,
  491. };
  492. enum xgbe_mode {
  493. XGBE_MODE_KX_1000 = 0,
  494. XGBE_MODE_KX_2500,
  495. XGBE_MODE_KR,
  496. XGBE_MODE_X,
  497. XGBE_MODE_SGMII_100,
  498. XGBE_MODE_SGMII_1000,
  499. XGBE_MODE_SFI,
  500. XGBE_MODE_UNKNOWN,
  501. };
  502. enum xgbe_speedset {
  503. XGBE_SPEEDSET_1000_10000 = 0,
  504. XGBE_SPEEDSET_2500_10000,
  505. };
  506. enum xgbe_mdio_mode {
  507. XGBE_MDIO_MODE_NONE = 0,
  508. XGBE_MDIO_MODE_CL22,
  509. XGBE_MDIO_MODE_CL45,
  510. };
  511. enum xgbe_mb_cmd {
  512. XGBE_MB_CMD_POWER_OFF = 0,
  513. XGBE_MB_CMD_SET_1G,
  514. XGBE_MB_CMD_SET_2_5G,
  515. XGBE_MB_CMD_SET_10G_SFI,
  516. XGBE_MB_CMD_SET_10G_KR,
  517. XGBE_MB_CMD_RRC
  518. };
  519. enum xgbe_mb_subcmd {
  520. XGBE_MB_SUBCMD_NONE = 0,
  521. /* 10GbE SFP subcommands */
  522. XGBE_MB_SUBCMD_ACTIVE = 0,
  523. XGBE_MB_SUBCMD_PASSIVE_1M,
  524. XGBE_MB_SUBCMD_PASSIVE_3M,
  525. XGBE_MB_SUBCMD_PASSIVE_OTHER,
  526. /* 1GbE Mode subcommands */
  527. XGBE_MB_SUBCMD_10MBITS = 0,
  528. XGBE_MB_SUBCMD_100MBITS,
  529. XGBE_MB_SUBCMD_1G_SGMII,
  530. XGBE_MB_SUBCMD_1G_KX
  531. };
  532. struct xgbe_phy {
  533. struct ethtool_link_ksettings lks;
  534. int address;
  535. int autoneg;
  536. int speed;
  537. int duplex;
  538. int link;
  539. int pause_autoneg;
  540. int tx_pause;
  541. int rx_pause;
  542. };
  543. enum xgbe_i2c_cmd {
  544. XGBE_I2C_CMD_READ = 0,
  545. XGBE_I2C_CMD_WRITE,
  546. };
  547. struct xgbe_i2c_op {
  548. enum xgbe_i2c_cmd cmd;
  549. unsigned int target;
  550. void *buf;
  551. unsigned int len;
  552. };
  553. struct xgbe_i2c_op_state {
  554. struct xgbe_i2c_op *op;
  555. unsigned int tx_len;
  556. unsigned char *tx_buf;
  557. unsigned int rx_len;
  558. unsigned char *rx_buf;
  559. unsigned int tx_abort_source;
  560. int ret;
  561. };
  562. struct xgbe_i2c {
  563. unsigned int started;
  564. unsigned int max_speed_mode;
  565. unsigned int rx_fifo_size;
  566. unsigned int tx_fifo_size;
  567. struct xgbe_i2c_op_state op_state;
  568. };
  569. struct xgbe_mmc_stats {
  570. /* Tx Stats */
  571. u64 txoctetcount_gb;
  572. u64 txframecount_gb;
  573. u64 txbroadcastframes_g;
  574. u64 txmulticastframes_g;
  575. u64 tx64octets_gb;
  576. u64 tx65to127octets_gb;
  577. u64 tx128to255octets_gb;
  578. u64 tx256to511octets_gb;
  579. u64 tx512to1023octets_gb;
  580. u64 tx1024tomaxoctets_gb;
  581. u64 txunicastframes_gb;
  582. u64 txmulticastframes_gb;
  583. u64 txbroadcastframes_gb;
  584. u64 txunderflowerror;
  585. u64 txoctetcount_g;
  586. u64 txframecount_g;
  587. u64 txpauseframes;
  588. u64 txvlanframes_g;
  589. /* Rx Stats */
  590. u64 rxframecount_gb;
  591. u64 rxoctetcount_gb;
  592. u64 rxoctetcount_g;
  593. u64 rxbroadcastframes_g;
  594. u64 rxmulticastframes_g;
  595. u64 rxcrcerror;
  596. u64 rxrunterror;
  597. u64 rxjabbererror;
  598. u64 rxundersize_g;
  599. u64 rxoversize_g;
  600. u64 rx64octets_gb;
  601. u64 rx65to127octets_gb;
  602. u64 rx128to255octets_gb;
  603. u64 rx256to511octets_gb;
  604. u64 rx512to1023octets_gb;
  605. u64 rx1024tomaxoctets_gb;
  606. u64 rxunicastframes_g;
  607. u64 rxlengtherror;
  608. u64 rxoutofrangetype;
  609. u64 rxpauseframes;
  610. u64 rxfifooverflow;
  611. u64 rxvlanframes_gb;
  612. u64 rxwatchdogerror;
  613. };
  614. struct xgbe_ext_stats {
  615. u64 tx_tso_packets;
  616. u64 rx_split_header_packets;
  617. u64 rx_buffer_unavailable;
  618. u64 txq_packets[XGBE_MAX_DMA_CHANNELS];
  619. u64 txq_bytes[XGBE_MAX_DMA_CHANNELS];
  620. u64 rxq_packets[XGBE_MAX_DMA_CHANNELS];
  621. u64 rxq_bytes[XGBE_MAX_DMA_CHANNELS];
  622. u64 tx_vxlan_packets;
  623. u64 rx_vxlan_packets;
  624. u64 rx_csum_errors;
  625. u64 rx_vxlan_csum_errors;
  626. };
  627. struct xgbe_hw_if {
  628. int (*tx_complete)(struct xgbe_ring_desc *);
  629. int (*set_mac_address)(struct xgbe_prv_data *, const u8 *addr);
  630. int (*config_rx_mode)(struct xgbe_prv_data *);
  631. int (*enable_rx_csum)(struct xgbe_prv_data *);
  632. int (*disable_rx_csum)(struct xgbe_prv_data *);
  633. int (*enable_rx_vlan_stripping)(struct xgbe_prv_data *);
  634. int (*disable_rx_vlan_stripping)(struct xgbe_prv_data *);
  635. int (*enable_rx_vlan_filtering)(struct xgbe_prv_data *);
  636. int (*disable_rx_vlan_filtering)(struct xgbe_prv_data *);
  637. int (*update_vlan_hash_table)(struct xgbe_prv_data *);
  638. int (*read_mmd_regs)(struct xgbe_prv_data *, int, int);
  639. void (*write_mmd_regs)(struct xgbe_prv_data *, int, int, int);
  640. int (*set_speed)(struct xgbe_prv_data *, int);
  641. int (*set_ext_mii_mode)(struct xgbe_prv_data *, unsigned int,
  642. enum xgbe_mdio_mode);
  643. int (*read_ext_mii_regs)(struct xgbe_prv_data *, int, int);
  644. int (*write_ext_mii_regs)(struct xgbe_prv_data *, int, int, u16);
  645. int (*set_gpio)(struct xgbe_prv_data *, unsigned int);
  646. int (*clr_gpio)(struct xgbe_prv_data *, unsigned int);
  647. void (*enable_tx)(struct xgbe_prv_data *);
  648. void (*disable_tx)(struct xgbe_prv_data *);
  649. void (*enable_rx)(struct xgbe_prv_data *);
  650. void (*disable_rx)(struct xgbe_prv_data *);
  651. void (*powerup_tx)(struct xgbe_prv_data *);
  652. void (*powerdown_tx)(struct xgbe_prv_data *);
  653. void (*powerup_rx)(struct xgbe_prv_data *);
  654. void (*powerdown_rx)(struct xgbe_prv_data *);
  655. int (*init)(struct xgbe_prv_data *);
  656. int (*exit)(struct xgbe_prv_data *);
  657. int (*enable_int)(struct xgbe_channel *, enum xgbe_int);
  658. int (*disable_int)(struct xgbe_channel *, enum xgbe_int);
  659. void (*dev_xmit)(struct xgbe_channel *);
  660. int (*dev_read)(struct xgbe_channel *);
  661. void (*tx_desc_init)(struct xgbe_channel *);
  662. void (*rx_desc_init)(struct xgbe_channel *);
  663. void (*tx_desc_reset)(struct xgbe_ring_data *);
  664. void (*rx_desc_reset)(struct xgbe_prv_data *, struct xgbe_ring_data *,
  665. unsigned int);
  666. int (*is_last_desc)(struct xgbe_ring_desc *);
  667. int (*is_context_desc)(struct xgbe_ring_desc *);
  668. void (*tx_start_xmit)(struct xgbe_channel *, struct xgbe_ring *);
  669. /* For FLOW ctrl */
  670. int (*config_tx_flow_control)(struct xgbe_prv_data *);
  671. int (*config_rx_flow_control)(struct xgbe_prv_data *);
  672. /* For RX coalescing */
  673. int (*config_rx_coalesce)(struct xgbe_prv_data *);
  674. int (*config_tx_coalesce)(struct xgbe_prv_data *);
  675. unsigned int (*usec_to_riwt)(struct xgbe_prv_data *, unsigned int);
  676. unsigned int (*riwt_to_usec)(struct xgbe_prv_data *, unsigned int);
  677. /* For RX and TX threshold config */
  678. int (*config_rx_threshold)(struct xgbe_prv_data *, unsigned int);
  679. int (*config_tx_threshold)(struct xgbe_prv_data *, unsigned int);
  680. /* For RX and TX Store and Forward Mode config */
  681. int (*config_rsf_mode)(struct xgbe_prv_data *, unsigned int);
  682. int (*config_tsf_mode)(struct xgbe_prv_data *, unsigned int);
  683. /* For TX DMA Operate on Second Frame config */
  684. int (*config_osp_mode)(struct xgbe_prv_data *);
  685. /* For MMC statistics */
  686. void (*rx_mmc_int)(struct xgbe_prv_data *);
  687. void (*tx_mmc_int)(struct xgbe_prv_data *);
  688. void (*read_mmc_stats)(struct xgbe_prv_data *);
  689. /* For Timestamp config */
  690. int (*config_tstamp)(struct xgbe_prv_data *, unsigned int);
  691. void (*update_tstamp_addend)(struct xgbe_prv_data *, unsigned int);
  692. void (*set_tstamp_time)(struct xgbe_prv_data *, unsigned int sec,
  693. unsigned int nsec);
  694. u64 (*get_tstamp_time)(struct xgbe_prv_data *);
  695. u64 (*get_tx_tstamp)(struct xgbe_prv_data *);
  696. /* For Data Center Bridging config */
  697. void (*config_tc)(struct xgbe_prv_data *);
  698. void (*config_dcb_tc)(struct xgbe_prv_data *);
  699. void (*config_dcb_pfc)(struct xgbe_prv_data *);
  700. /* For Receive Side Scaling */
  701. int (*enable_rss)(struct xgbe_prv_data *);
  702. int (*disable_rss)(struct xgbe_prv_data *);
  703. int (*set_rss_hash_key)(struct xgbe_prv_data *, const u8 *);
  704. int (*set_rss_lookup_table)(struct xgbe_prv_data *, const u32 *);
  705. /* For ECC */
  706. void (*disable_ecc_ded)(struct xgbe_prv_data *);
  707. void (*disable_ecc_sec)(struct xgbe_prv_data *, enum xgbe_ecc_sec);
  708. /* For VXLAN */
  709. void (*enable_vxlan)(struct xgbe_prv_data *);
  710. void (*disable_vxlan)(struct xgbe_prv_data *);
  711. void (*set_vxlan_id)(struct xgbe_prv_data *);
  712. };
  713. /* This structure represents implementation specific routines for an
  714. * implementation of a PHY. All routines are required unless noted below.
  715. * Optional routines:
  716. * an_pre, an_post
  717. * kr_training_pre, kr_training_post
  718. * module_info, module_eeprom
  719. */
  720. struct xgbe_phy_impl_if {
  721. /* Perform Setup/teardown actions */
  722. int (*init)(struct xgbe_prv_data *);
  723. void (*exit)(struct xgbe_prv_data *);
  724. /* Perform start/stop specific actions */
  725. int (*reset)(struct xgbe_prv_data *);
  726. int (*start)(struct xgbe_prv_data *);
  727. void (*stop)(struct xgbe_prv_data *);
  728. /* Return the link status */
  729. int (*link_status)(struct xgbe_prv_data *, int *);
  730. /* Indicate if a particular speed is valid */
  731. bool (*valid_speed)(struct xgbe_prv_data *, int);
  732. /* Check if the specified mode can/should be used */
  733. bool (*use_mode)(struct xgbe_prv_data *, enum xgbe_mode);
  734. /* Switch the PHY into various modes */
  735. void (*set_mode)(struct xgbe_prv_data *, enum xgbe_mode);
  736. /* Retrieve mode needed for a specific speed */
  737. enum xgbe_mode (*get_mode)(struct xgbe_prv_data *, int);
  738. /* Retrieve new/next mode when trying to auto-negotiate */
  739. enum xgbe_mode (*switch_mode)(struct xgbe_prv_data *);
  740. /* Retrieve current mode */
  741. enum xgbe_mode (*cur_mode)(struct xgbe_prv_data *);
  742. /* Retrieve current auto-negotiation mode */
  743. enum xgbe_an_mode (*an_mode)(struct xgbe_prv_data *);
  744. /* Configure auto-negotiation settings */
  745. int (*an_config)(struct xgbe_prv_data *);
  746. /* Set/override auto-negotiation advertisement settings */
  747. void (*an_advertising)(struct xgbe_prv_data *,
  748. struct ethtool_link_ksettings *);
  749. /* Process results of auto-negotiation */
  750. enum xgbe_mode (*an_outcome)(struct xgbe_prv_data *);
  751. /* Pre/Post auto-negotiation support */
  752. void (*an_pre)(struct xgbe_prv_data *);
  753. void (*an_post)(struct xgbe_prv_data *);
  754. /* Pre/Post KR training enablement support */
  755. void (*kr_training_pre)(struct xgbe_prv_data *);
  756. void (*kr_training_post)(struct xgbe_prv_data *);
  757. /* SFP module related info */
  758. int (*module_info)(struct xgbe_prv_data *pdata,
  759. struct ethtool_modinfo *modinfo);
  760. int (*module_eeprom)(struct xgbe_prv_data *pdata,
  761. struct ethtool_eeprom *eeprom, u8 *data);
  762. };
  763. struct xgbe_phy_if {
  764. /* For PHY setup/teardown */
  765. int (*phy_init)(struct xgbe_prv_data *);
  766. void (*phy_exit)(struct xgbe_prv_data *);
  767. /* For PHY support when setting device up/down */
  768. int (*phy_reset)(struct xgbe_prv_data *);
  769. int (*phy_start)(struct xgbe_prv_data *);
  770. void (*phy_stop)(struct xgbe_prv_data *);
  771. /* For PHY support while device is up */
  772. void (*phy_status)(struct xgbe_prv_data *);
  773. int (*phy_config_aneg)(struct xgbe_prv_data *);
  774. /* For PHY settings validation */
  775. bool (*phy_valid_speed)(struct xgbe_prv_data *, int);
  776. /* For single interrupt support */
  777. irqreturn_t (*an_isr)(struct xgbe_prv_data *);
  778. /* For ethtool PHY support */
  779. int (*module_info)(struct xgbe_prv_data *pdata,
  780. struct ethtool_modinfo *modinfo);
  781. int (*module_eeprom)(struct xgbe_prv_data *pdata,
  782. struct ethtool_eeprom *eeprom, u8 *data);
  783. /* PHY implementation specific services */
  784. struct xgbe_phy_impl_if phy_impl;
  785. };
  786. struct xgbe_i2c_if {
  787. /* For initial I2C setup */
  788. int (*i2c_init)(struct xgbe_prv_data *);
  789. /* For I2C support when setting device up/down */
  790. int (*i2c_start)(struct xgbe_prv_data *);
  791. void (*i2c_stop)(struct xgbe_prv_data *);
  792. /* For performing I2C operations */
  793. int (*i2c_xfer)(struct xgbe_prv_data *, struct xgbe_i2c_op *);
  794. /* For single interrupt support */
  795. irqreturn_t (*i2c_isr)(struct xgbe_prv_data *);
  796. };
  797. struct xgbe_desc_if {
  798. int (*alloc_ring_resources)(struct xgbe_prv_data *);
  799. void (*free_ring_resources)(struct xgbe_prv_data *);
  800. int (*map_tx_skb)(struct xgbe_channel *, struct sk_buff *);
  801. int (*map_rx_buffer)(struct xgbe_prv_data *, struct xgbe_ring *,
  802. struct xgbe_ring_data *);
  803. void (*unmap_rdata)(struct xgbe_prv_data *, struct xgbe_ring_data *);
  804. void (*wrapper_tx_desc_init)(struct xgbe_prv_data *);
  805. void (*wrapper_rx_desc_init)(struct xgbe_prv_data *);
  806. };
  807. /* This structure contains flags that indicate what hardware features
  808. * or configurations are present in the device.
  809. */
  810. struct xgbe_hw_features {
  811. /* HW Version */
  812. unsigned int version;
  813. /* HW Feature Register0 */
  814. unsigned int gmii; /* 1000 Mbps support */
  815. unsigned int vlhash; /* VLAN Hash Filter */
  816. unsigned int sma; /* SMA(MDIO) Interface */
  817. unsigned int rwk; /* PMT remote wake-up packet */
  818. unsigned int mgk; /* PMT magic packet */
  819. unsigned int mmc; /* RMON module */
  820. unsigned int aoe; /* ARP Offload */
  821. unsigned int ts; /* IEEE 1588-2008 Advanced Timestamp */
  822. unsigned int eee; /* Energy Efficient Ethernet */
  823. unsigned int tx_coe; /* Tx Checksum Offload */
  824. unsigned int rx_coe; /* Rx Checksum Offload */
  825. unsigned int addn_mac; /* Additional MAC Addresses */
  826. unsigned int ts_src; /* Timestamp Source */
  827. unsigned int sa_vlan_ins; /* Source Address or VLAN Insertion */
  828. unsigned int vxn; /* VXLAN/NVGRE */
  829. /* HW Feature Register1 */
  830. unsigned int rx_fifo_size; /* MTL Receive FIFO Size */
  831. unsigned int tx_fifo_size; /* MTL Transmit FIFO Size */
  832. unsigned int adv_ts_hi; /* Advance Timestamping High Word */
  833. unsigned int dma_width; /* DMA width */
  834. unsigned int dcb; /* DCB Feature */
  835. unsigned int sph; /* Split Header Feature */
  836. unsigned int tso; /* TCP Segmentation Offload */
  837. unsigned int dma_debug; /* DMA Debug Registers */
  838. unsigned int rss; /* Receive Side Scaling */
  839. unsigned int tc_cnt; /* Number of Traffic Classes */
  840. unsigned int hash_table_size; /* Hash Table Size */
  841. unsigned int l3l4_filter_num; /* Number of L3-L4 Filters */
  842. /* HW Feature Register2 */
  843. unsigned int rx_q_cnt; /* Number of MTL Receive Queues */
  844. unsigned int tx_q_cnt; /* Number of MTL Transmit Queues */
  845. unsigned int rx_ch_cnt; /* Number of DMA Receive Channels */
  846. unsigned int tx_ch_cnt; /* Number of DMA Transmit Channels */
  847. unsigned int pps_out_num; /* Number of PPS outputs */
  848. unsigned int aux_snap_num; /* Number of Aux snapshot inputs */
  849. };
  850. struct xgbe_version_data {
  851. void (*init_function_ptrs_phy_impl)(struct xgbe_phy_if *);
  852. enum xgbe_xpcs_access xpcs_access;
  853. unsigned int mmc_64bit;
  854. unsigned int tx_max_fifo_size;
  855. unsigned int rx_max_fifo_size;
  856. unsigned int tx_tstamp_workaround;
  857. unsigned int ecc_support;
  858. unsigned int i2c_support;
  859. unsigned int irq_reissue_support;
  860. unsigned int tx_desc_prefetch;
  861. unsigned int rx_desc_prefetch;
  862. unsigned int an_cdr_workaround;
  863. unsigned int enable_rrc;
  864. };
  865. struct xgbe_prv_data {
  866. struct net_device *netdev;
  867. struct pci_dev *pcidev;
  868. struct platform_device *platdev;
  869. struct acpi_device *adev;
  870. struct device *dev;
  871. struct platform_device *phy_platdev;
  872. struct device *phy_dev;
  873. /* Version related data */
  874. struct xgbe_version_data *vdata;
  875. /* ACPI or DT flag */
  876. unsigned int use_acpi;
  877. /* XGMAC/XPCS related mmio registers */
  878. void __iomem *xgmac_regs; /* XGMAC CSRs */
  879. void __iomem *xpcs_regs; /* XPCS MMD registers */
  880. void __iomem *rxtx_regs; /* SerDes Rx/Tx CSRs */
  881. void __iomem *sir0_regs; /* SerDes integration registers (1/2) */
  882. void __iomem *sir1_regs; /* SerDes integration registers (2/2) */
  883. void __iomem *xprop_regs; /* XGBE property registers */
  884. void __iomem *xi2c_regs; /* XGBE I2C CSRs */
  885. /* Port property registers */
  886. unsigned int pp0;
  887. unsigned int pp1;
  888. unsigned int pp2;
  889. unsigned int pp3;
  890. unsigned int pp4;
  891. /* Overall device lock */
  892. spinlock_t lock;
  893. /* XPCS indirect addressing lock */
  894. spinlock_t xpcs_lock;
  895. unsigned int xpcs_window_def_reg;
  896. unsigned int xpcs_window_sel_reg;
  897. unsigned int xpcs_window;
  898. unsigned int xpcs_window_size;
  899. unsigned int xpcs_window_mask;
  900. /* RSS addressing mutex */
  901. struct mutex rss_mutex;
  902. /* Flags representing xgbe_state */
  903. unsigned long dev_state;
  904. /* ECC support */
  905. unsigned long tx_sec_period;
  906. unsigned long tx_ded_period;
  907. unsigned long rx_sec_period;
  908. unsigned long rx_ded_period;
  909. unsigned long desc_sec_period;
  910. unsigned long desc_ded_period;
  911. unsigned int tx_sec_count;
  912. unsigned int tx_ded_count;
  913. unsigned int rx_sec_count;
  914. unsigned int rx_ded_count;
  915. unsigned int desc_ded_count;
  916. unsigned int desc_sec_count;
  917. int dev_irq;
  918. int ecc_irq;
  919. int i2c_irq;
  920. int channel_irq[XGBE_MAX_DMA_CHANNELS];
  921. unsigned int per_channel_irq;
  922. unsigned int irq_count;
  923. unsigned int channel_irq_count;
  924. unsigned int channel_irq_mode;
  925. char ecc_name[IFNAMSIZ + 32];
  926. struct xgbe_hw_if hw_if;
  927. struct xgbe_phy_if phy_if;
  928. struct xgbe_desc_if desc_if;
  929. struct xgbe_i2c_if i2c_if;
  930. /* AXI DMA settings */
  931. unsigned int coherent;
  932. unsigned int arcr;
  933. unsigned int awcr;
  934. unsigned int awarcr;
  935. /* Service routine support */
  936. struct workqueue_struct *dev_workqueue;
  937. struct work_struct service_work;
  938. struct timer_list service_timer;
  939. /* Rings for Tx/Rx on a DMA channel */
  940. struct xgbe_channel *channel[XGBE_MAX_DMA_CHANNELS];
  941. unsigned int tx_max_channel_count;
  942. unsigned int rx_max_channel_count;
  943. unsigned int channel_count;
  944. unsigned int tx_ring_count;
  945. unsigned int tx_desc_count;
  946. unsigned int rx_ring_count;
  947. unsigned int rx_desc_count;
  948. unsigned int new_tx_ring_count;
  949. unsigned int new_rx_ring_count;
  950. unsigned int tx_max_q_count;
  951. unsigned int rx_max_q_count;
  952. unsigned int tx_q_count;
  953. unsigned int rx_q_count;
  954. /* Tx/Rx common settings */
  955. unsigned int blen;
  956. unsigned int pbl;
  957. unsigned int aal;
  958. unsigned int rd_osr_limit;
  959. unsigned int wr_osr_limit;
  960. /* Tx settings */
  961. unsigned int tx_sf_mode;
  962. unsigned int tx_threshold;
  963. unsigned int tx_osp_mode;
  964. unsigned int tx_max_fifo_size;
  965. /* Rx settings */
  966. unsigned int rx_sf_mode;
  967. unsigned int rx_threshold;
  968. unsigned int rx_max_fifo_size;
  969. /* Tx coalescing settings */
  970. unsigned int tx_usecs;
  971. unsigned int tx_frames;
  972. /* Rx coalescing settings */
  973. unsigned int rx_riwt;
  974. unsigned int rx_usecs;
  975. unsigned int rx_frames;
  976. /* Current Rx buffer size */
  977. unsigned int rx_buf_size;
  978. /* Flow control settings */
  979. unsigned int pause_autoneg;
  980. unsigned int tx_pause;
  981. unsigned int rx_pause;
  982. unsigned int rx_rfa[XGBE_MAX_QUEUES];
  983. unsigned int rx_rfd[XGBE_MAX_QUEUES];
  984. /* Receive Side Scaling settings */
  985. u8 rss_key[XGBE_RSS_HASH_KEY_SIZE];
  986. u32 rss_table[XGBE_RSS_MAX_TABLE_SIZE];
  987. u32 rss_options;
  988. /* VXLAN settings */
  989. u16 vxlan_port;
  990. /* Netdev related settings */
  991. unsigned char mac_addr[ETH_ALEN];
  992. netdev_features_t netdev_features;
  993. struct napi_struct napi;
  994. struct xgbe_mmc_stats mmc_stats;
  995. struct xgbe_ext_stats ext_stats;
  996. /* Filtering support */
  997. unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
  998. /* Device clocks */
  999. struct clk *sysclk;
  1000. unsigned long sysclk_rate;
  1001. struct clk *ptpclk;
  1002. unsigned long ptpclk_rate;
  1003. /* Timestamp support */
  1004. spinlock_t tstamp_lock;
  1005. struct ptp_clock_info ptp_clock_info;
  1006. struct ptp_clock *ptp_clock;
  1007. struct hwtstamp_config tstamp_config;
  1008. struct cyclecounter tstamp_cc;
  1009. struct timecounter tstamp_tc;
  1010. unsigned int tstamp_addend;
  1011. struct work_struct tx_tstamp_work;
  1012. struct sk_buff *tx_tstamp_skb;
  1013. u64 tx_tstamp;
  1014. /* DCB support */
  1015. struct ieee_ets *ets;
  1016. struct ieee_pfc *pfc;
  1017. unsigned int q2tc_map[XGBE_MAX_QUEUES];
  1018. unsigned int prio2q_map[IEEE_8021QAZ_MAX_TCS];
  1019. unsigned int pfcq[XGBE_MAX_QUEUES];
  1020. unsigned int pfc_rfa;
  1021. u8 num_tcs;
  1022. /* Hardware features of the device */
  1023. struct xgbe_hw_features hw_feat;
  1024. /* Device work structures */
  1025. struct work_struct restart_work;
  1026. struct work_struct stopdev_work;
  1027. /* Keeps track of power mode */
  1028. unsigned int power_down;
  1029. /* Network interface message level setting */
  1030. u32 msg_enable;
  1031. /* Current PHY settings */
  1032. phy_interface_t phy_mode;
  1033. int phy_link;
  1034. int phy_speed;
  1035. /* MDIO/PHY related settings */
  1036. unsigned int phy_started;
  1037. void *phy_data;
  1038. struct xgbe_phy phy;
  1039. int mdio_mmd;
  1040. unsigned long link_check;
  1041. struct completion mdio_complete;
  1042. unsigned int kr_redrv;
  1043. char an_name[IFNAMSIZ + 32];
  1044. struct workqueue_struct *an_workqueue;
  1045. int an_irq;
  1046. struct work_struct an_irq_work;
  1047. /* Auto-negotiation state machine support */
  1048. unsigned int an_int;
  1049. unsigned int an_status;
  1050. struct mutex an_mutex;
  1051. enum xgbe_an an_result;
  1052. enum xgbe_an an_state;
  1053. enum xgbe_rx kr_state;
  1054. enum xgbe_rx kx_state;
  1055. struct work_struct an_work;
  1056. unsigned int an_again;
  1057. unsigned int an_supported;
  1058. unsigned int parallel_detect;
  1059. unsigned int fec_ability;
  1060. unsigned long an_start;
  1061. unsigned long kr_start_time;
  1062. enum xgbe_an_mode an_mode;
  1063. /* I2C support */
  1064. struct xgbe_i2c i2c;
  1065. struct mutex i2c_mutex;
  1066. struct completion i2c_complete;
  1067. char i2c_name[IFNAMSIZ + 32];
  1068. unsigned int lpm_ctrl; /* CTRL1 for resume */
  1069. unsigned int isr_as_tasklet;
  1070. struct tasklet_struct tasklet_dev;
  1071. struct tasklet_struct tasklet_ecc;
  1072. struct tasklet_struct tasklet_i2c;
  1073. struct tasklet_struct tasklet_an;
  1074. struct dentry *xgbe_debugfs;
  1075. unsigned int debugfs_xgmac_reg;
  1076. unsigned int debugfs_xpcs_mmd;
  1077. unsigned int debugfs_xpcs_reg;
  1078. unsigned int debugfs_xprop_reg;
  1079. unsigned int debugfs_xi2c_reg;
  1080. bool debugfs_an_cdr_workaround;
  1081. bool debugfs_an_cdr_track_early;
  1082. };
  1083. /* Function prototypes*/
  1084. struct xgbe_prv_data *xgbe_alloc_pdata(struct device *);
  1085. void xgbe_free_pdata(struct xgbe_prv_data *);
  1086. void xgbe_set_counts(struct xgbe_prv_data *);
  1087. int xgbe_config_netdev(struct xgbe_prv_data *);
  1088. void xgbe_deconfig_netdev(struct xgbe_prv_data *);
  1089. int xgbe_platform_init(void);
  1090. void xgbe_platform_exit(void);
  1091. #ifdef CONFIG_PCI
  1092. int xgbe_pci_init(void);
  1093. void xgbe_pci_exit(void);
  1094. #else
  1095. static inline int xgbe_pci_init(void) { return 0; }
  1096. static inline void xgbe_pci_exit(void) { }
  1097. #endif
  1098. void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
  1099. void xgbe_init_function_ptrs_phy(struct xgbe_phy_if *);
  1100. void xgbe_init_function_ptrs_phy_v1(struct xgbe_phy_if *);
  1101. void xgbe_init_function_ptrs_phy_v2(struct xgbe_phy_if *);
  1102. void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *);
  1103. void xgbe_init_function_ptrs_i2c(struct xgbe_i2c_if *);
  1104. const struct net_device_ops *xgbe_get_netdev_ops(void);
  1105. const struct ethtool_ops *xgbe_get_ethtool_ops(void);
  1106. const struct udp_tunnel_nic_info *xgbe_get_udp_tunnel_info(void);
  1107. #ifdef CONFIG_AMD_XGBE_DCB
  1108. const struct dcbnl_rtnl_ops *xgbe_get_dcbnl_ops(void);
  1109. #endif
  1110. void xgbe_ptp_register(struct xgbe_prv_data *);
  1111. void xgbe_ptp_unregister(struct xgbe_prv_data *);
  1112. void xgbe_dump_tx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  1113. unsigned int, unsigned int, unsigned int);
  1114. void xgbe_dump_rx_desc(struct xgbe_prv_data *, struct xgbe_ring *,
  1115. unsigned int);
  1116. void xgbe_print_pkt(struct net_device *, struct sk_buff *, bool);
  1117. void xgbe_get_all_hw_features(struct xgbe_prv_data *);
  1118. int xgbe_powerup(struct net_device *, unsigned int);
  1119. int xgbe_powerdown(struct net_device *, unsigned int);
  1120. void xgbe_init_rx_coalesce(struct xgbe_prv_data *);
  1121. void xgbe_init_tx_coalesce(struct xgbe_prv_data *);
  1122. void xgbe_restart_dev(struct xgbe_prv_data *pdata);
  1123. void xgbe_full_restart_dev(struct xgbe_prv_data *pdata);
  1124. #ifdef CONFIG_DEBUG_FS
  1125. void xgbe_debugfs_init(struct xgbe_prv_data *);
  1126. void xgbe_debugfs_exit(struct xgbe_prv_data *);
  1127. void xgbe_debugfs_rename(struct xgbe_prv_data *pdata);
  1128. #else
  1129. static inline void xgbe_debugfs_init(struct xgbe_prv_data *pdata) {}
  1130. static inline void xgbe_debugfs_exit(struct xgbe_prv_data *pdata) {}
  1131. static inline void xgbe_debugfs_rename(struct xgbe_prv_data *pdata) {}
  1132. #endif /* CONFIG_DEBUG_FS */
  1133. /* NOTE: Uncomment for function trace log messages in KERNEL LOG */
  1134. #if 0
  1135. #define YDEBUG
  1136. #define YDEBUG_MDIO
  1137. #endif
  1138. /* For debug prints */
  1139. #ifdef YDEBUG
  1140. #define DBGPR(x...) pr_alert(x)
  1141. #else
  1142. #define DBGPR(x...) do { } while (0)
  1143. #endif
  1144. #ifdef YDEBUG_MDIO
  1145. #define DBGPR_MDIO(x...) pr_alert(x)
  1146. #else
  1147. #define DBGPR_MDIO(x...) do { } while (0)
  1148. #endif
  1149. #endif