xgbe.h 39 KB

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