pch_gbe.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * Copyright (C) 1999 - 2010 Intel Corporation.
  3. * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD.
  4. *
  5. * This code was derived from the Intel e1000e Linux driver.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _PCH_GBE_H_
  20. #define _PCH_GBE_H_
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/mii.h>
  23. #include <linux/delay.h>
  24. #include <linux/pci.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/ethtool.h>
  28. #include <linux/vmalloc.h>
  29. #include <net/ip.h>
  30. #include <net/tcp.h>
  31. #include <net/udp.h>
  32. /**
  33. * pch_gbe_regs_mac_adr - Structure holding values of mac address registers
  34. * @high Denotes the 1st to 4th byte from the initial of MAC address
  35. * @low Denotes the 5th to 6th byte from the initial of MAC address
  36. */
  37. struct pch_gbe_regs_mac_adr {
  38. u32 high;
  39. u32 low;
  40. };
  41. /**
  42. * pch_udc_regs - Structure holding values of MAC registers
  43. */
  44. struct pch_gbe_regs {
  45. u32 INT_ST;
  46. u32 INT_EN;
  47. u32 MODE;
  48. u32 RESET;
  49. u32 TCPIP_ACC;
  50. u32 EX_LIST;
  51. u32 INT_ST_HOLD;
  52. u32 PHY_INT_CTRL;
  53. u32 MAC_RX_EN;
  54. u32 RX_FCTRL;
  55. u32 PAUSE_REQ;
  56. u32 RX_MODE;
  57. u32 TX_MODE;
  58. u32 RX_FIFO_ST;
  59. u32 TX_FIFO_ST;
  60. u32 TX_FID;
  61. u32 TX_RESULT;
  62. u32 PAUSE_PKT1;
  63. u32 PAUSE_PKT2;
  64. u32 PAUSE_PKT3;
  65. u32 PAUSE_PKT4;
  66. u32 PAUSE_PKT5;
  67. u32 reserve[2];
  68. struct pch_gbe_regs_mac_adr mac_adr[16];
  69. u32 ADDR_MASK;
  70. u32 MIIM;
  71. u32 MAC_ADDR_LOAD;
  72. u32 RGMII_ST;
  73. u32 RGMII_CTRL;
  74. u32 reserve3[3];
  75. u32 DMA_CTRL;
  76. u32 reserve4[3];
  77. u32 RX_DSC_BASE;
  78. u32 RX_DSC_SIZE;
  79. u32 RX_DSC_HW_P;
  80. u32 RX_DSC_HW_P_HLD;
  81. u32 RX_DSC_SW_P;
  82. u32 reserve5[3];
  83. u32 TX_DSC_BASE;
  84. u32 TX_DSC_SIZE;
  85. u32 TX_DSC_HW_P;
  86. u32 TX_DSC_HW_P_HLD;
  87. u32 TX_DSC_SW_P;
  88. u32 reserve6[3];
  89. u32 RX_DMA_ST;
  90. u32 TX_DMA_ST;
  91. u32 reserve7[2];
  92. u32 WOL_ST;
  93. u32 WOL_CTRL;
  94. u32 WOL_ADDR_MASK;
  95. };
  96. /* Interrupt Status */
  97. /* Interrupt Status Hold */
  98. /* Interrupt Enable */
  99. #define PCH_GBE_INT_RX_DMA_CMPLT 0x00000001 /* Receive DMA Transfer Complete */
  100. #define PCH_GBE_INT_RX_VALID 0x00000002 /* MAC Normal Receive Complete */
  101. #define PCH_GBE_INT_RX_FRAME_ERR 0x00000004 /* Receive frame error */
  102. #define PCH_GBE_INT_RX_FIFO_ERR 0x00000008 /* Receive FIFO Overflow */
  103. #define PCH_GBE_INT_RX_DMA_ERR 0x00000010 /* Receive DMA Transfer Error */
  104. #define PCH_GBE_INT_RX_DSC_EMP 0x00000020 /* Receive Descriptor Empty */
  105. #define PCH_GBE_INT_TX_CMPLT 0x00000100 /* MAC Transmission Complete */
  106. #define PCH_GBE_INT_TX_DMA_CMPLT 0x00000200 /* DMA Transfer Complete */
  107. #define PCH_GBE_INT_TX_FIFO_ERR 0x00000400 /* Transmission FIFO underflow. */
  108. #define PCH_GBE_INT_TX_DMA_ERR 0x00000800 /* Transmission DMA Error */
  109. #define PCH_GBE_INT_PAUSE_CMPLT 0x00001000 /* Pause Transmission complete */
  110. #define PCH_GBE_INT_MIIM_CMPLT 0x00010000 /* MIIM I/F Read completion */
  111. #define PCH_GBE_INT_PHY_INT 0x00100000 /* Interruption from PHY */
  112. #define PCH_GBE_INT_WOL_DET 0x01000000 /* Wake On LAN Event detection. */
  113. #define PCH_GBE_INT_TCPIP_ERR 0x10000000 /* TCP/IP Accelerator Error */
  114. /* Mode */
  115. #define PCH_GBE_MODE_MII_ETHER 0x00000000 /* GIGA Ethernet Mode [MII] */
  116. #define PCH_GBE_MODE_GMII_ETHER 0x80000000 /* GIGA Ethernet Mode [GMII] */
  117. #define PCH_GBE_MODE_HALF_DUPLEX 0x00000000 /* Duplex Mode [half duplex] */
  118. #define PCH_GBE_MODE_FULL_DUPLEX 0x40000000 /* Duplex Mode [full duplex] */
  119. #define PCH_GBE_MODE_FR_BST 0x04000000 /* Frame bursting is done */
  120. /* Reset */
  121. #define PCH_GBE_ALL_RST 0x80000000 /* All reset */
  122. #define PCH_GBE_TX_RST 0x00008000 /* TX MAC, TX FIFO, TX DMA reset */
  123. #define PCH_GBE_RX_RST 0x00004000 /* RX MAC, RX FIFO, RX DMA reset */
  124. /* TCP/IP Accelerator Control */
  125. #define PCH_GBE_EX_LIST_EN 0x00000008 /* External List Enable */
  126. #define PCH_GBE_RX_TCPIPACC_OFF 0x00000004 /* RX TCP/IP ACC Disabled */
  127. #define PCH_GBE_TX_TCPIPACC_EN 0x00000002 /* TX TCP/IP ACC Enable */
  128. #define PCH_GBE_RX_TCPIPACC_EN 0x00000001 /* RX TCP/IP ACC Enable */
  129. /* MAC RX Enable */
  130. #define PCH_GBE_MRE_MAC_RX_EN 0x00000001 /* MAC Receive Enable */
  131. /* RX Flow Control */
  132. #define PCH_GBE_FL_CTRL_EN 0x80000000 /* Pause packet is enabled */
  133. /* Pause Packet Request */
  134. #define PCH_GBE_PS_PKT_RQ 0x80000000 /* Pause packet Request */
  135. /* RX Mode */
  136. #define PCH_GBE_ADD_FIL_EN 0x80000000 /* Address Filtering Enable */
  137. /* Multicast Filtering Enable */
  138. #define PCH_GBE_MLT_FIL_EN 0x40000000
  139. /* Receive Almost Empty Threshold */
  140. #define PCH_GBE_RH_ALM_EMP_4 0x00000000 /* 4 words */
  141. #define PCH_GBE_RH_ALM_EMP_8 0x00004000 /* 8 words */
  142. #define PCH_GBE_RH_ALM_EMP_16 0x00008000 /* 16 words */
  143. #define PCH_GBE_RH_ALM_EMP_32 0x0000C000 /* 32 words */
  144. /* Receive Almost Full Threshold */
  145. #define PCH_GBE_RH_ALM_FULL_4 0x00000000 /* 4 words */
  146. #define PCH_GBE_RH_ALM_FULL_8 0x00001000 /* 8 words */
  147. #define PCH_GBE_RH_ALM_FULL_16 0x00002000 /* 16 words */
  148. #define PCH_GBE_RH_ALM_FULL_32 0x00003000 /* 32 words */
  149. /* RX FIFO Read Triger Threshold */
  150. #define PCH_GBE_RH_RD_TRG_4 0x00000000 /* 4 words */
  151. #define PCH_GBE_RH_RD_TRG_8 0x00000200 /* 8 words */
  152. #define PCH_GBE_RH_RD_TRG_16 0x00000400 /* 16 words */
  153. #define PCH_GBE_RH_RD_TRG_32 0x00000600 /* 32 words */
  154. #define PCH_GBE_RH_RD_TRG_64 0x00000800 /* 64 words */
  155. #define PCH_GBE_RH_RD_TRG_128 0x00000A00 /* 128 words */
  156. #define PCH_GBE_RH_RD_TRG_256 0x00000C00 /* 256 words */
  157. #define PCH_GBE_RH_RD_TRG_512 0x00000E00 /* 512 words */
  158. /* Receive Descriptor bit definitions */
  159. #define PCH_GBE_RXD_ACC_STAT_BCAST 0x00000400
  160. #define PCH_GBE_RXD_ACC_STAT_MCAST 0x00000200
  161. #define PCH_GBE_RXD_ACC_STAT_UCAST 0x00000100
  162. #define PCH_GBE_RXD_ACC_STAT_TCPIPOK 0x000000C0
  163. #define PCH_GBE_RXD_ACC_STAT_IPOK 0x00000080
  164. #define PCH_GBE_RXD_ACC_STAT_TCPOK 0x00000040
  165. #define PCH_GBE_RXD_ACC_STAT_IP6ERR 0x00000020
  166. #define PCH_GBE_RXD_ACC_STAT_OFLIST 0x00000010
  167. #define PCH_GBE_RXD_ACC_STAT_TYPEIP 0x00000008
  168. #define PCH_GBE_RXD_ACC_STAT_MACL 0x00000004
  169. #define PCH_GBE_RXD_ACC_STAT_PPPOE 0x00000002
  170. #define PCH_GBE_RXD_ACC_STAT_VTAGT 0x00000001
  171. #define PCH_GBE_RXD_GMAC_STAT_PAUSE 0x0200
  172. #define PCH_GBE_RXD_GMAC_STAT_MARBR 0x0100
  173. #define PCH_GBE_RXD_GMAC_STAT_MARMLT 0x0080
  174. #define PCH_GBE_RXD_GMAC_STAT_MARIND 0x0040
  175. #define PCH_GBE_RXD_GMAC_STAT_MARNOTMT 0x0020
  176. #define PCH_GBE_RXD_GMAC_STAT_TLONG 0x0010
  177. #define PCH_GBE_RXD_GMAC_STAT_TSHRT 0x0008
  178. #define PCH_GBE_RXD_GMAC_STAT_NOTOCTAL 0x0004
  179. #define PCH_GBE_RXD_GMAC_STAT_NBLERR 0x0002
  180. #define PCH_GBE_RXD_GMAC_STAT_CRCERR 0x0001
  181. /* Transmit Descriptor bit definitions */
  182. #define PCH_GBE_TXD_CTRL_TCPIP_ACC_OFF 0x0008
  183. #define PCH_GBE_TXD_CTRL_ITAG 0x0004
  184. #define PCH_GBE_TXD_CTRL_ICRC 0x0002
  185. #define PCH_GBE_TXD_CTRL_APAD 0x0001
  186. #define PCH_GBE_TXD_WORDS_SHIFT 2
  187. #define PCH_GBE_TXD_GMAC_STAT_CMPLT 0x2000
  188. #define PCH_GBE_TXD_GMAC_STAT_ABT 0x1000
  189. #define PCH_GBE_TXD_GMAC_STAT_EXCOL 0x0800
  190. #define PCH_GBE_TXD_GMAC_STAT_SNGCOL 0x0400
  191. #define PCH_GBE_TXD_GMAC_STAT_MLTCOL 0x0200
  192. #define PCH_GBE_TXD_GMAC_STAT_CRSER 0x0100
  193. #define PCH_GBE_TXD_GMAC_STAT_TLNG 0x0080
  194. #define PCH_GBE_TXD_GMAC_STAT_TSHRT 0x0040
  195. #define PCH_GBE_TXD_GMAC_STAT_LTCOL 0x0020
  196. #define PCH_GBE_TXD_GMAC_STAT_TFUNDFLW 0x0010
  197. #define PCH_GBE_TXD_GMAC_STAT_RTYCNT_MASK 0x000F
  198. /* TX Mode */
  199. #define PCH_GBE_TM_NO_RTRY 0x80000000 /* No Retransmission */
  200. #define PCH_GBE_TM_LONG_PKT 0x40000000 /* Long Packt TX Enable */
  201. #define PCH_GBE_TM_ST_AND_FD 0x20000000 /* Stare and Forward */
  202. #define PCH_GBE_TM_SHORT_PKT 0x10000000 /* Short Packet TX Enable */
  203. #define PCH_GBE_TM_LTCOL_RETX 0x08000000 /* Retransmission at Late Collision */
  204. /* Frame Start Threshold */
  205. #define PCH_GBE_TM_TH_TX_STRT_4 0x00000000 /* 4 words */
  206. #define PCH_GBE_TM_TH_TX_STRT_8 0x00004000 /* 8 words */
  207. #define PCH_GBE_TM_TH_TX_STRT_16 0x00008000 /* 16 words */
  208. #define PCH_GBE_TM_TH_TX_STRT_32 0x0000C000 /* 32 words */
  209. /* Transmit Almost Empty Threshold */
  210. #define PCH_GBE_TM_TH_ALM_EMP_4 0x00000000 /* 4 words */
  211. #define PCH_GBE_TM_TH_ALM_EMP_8 0x00000800 /* 8 words */
  212. #define PCH_GBE_TM_TH_ALM_EMP_16 0x00001000 /* 16 words */
  213. #define PCH_GBE_TM_TH_ALM_EMP_32 0x00001800 /* 32 words */
  214. #define PCH_GBE_TM_TH_ALM_EMP_64 0x00002000 /* 64 words */
  215. #define PCH_GBE_TM_TH_ALM_EMP_128 0x00002800 /* 128 words */
  216. #define PCH_GBE_TM_TH_ALM_EMP_256 0x00003000 /* 256 words */
  217. #define PCH_GBE_TM_TH_ALM_EMP_512 0x00003800 /* 512 words */
  218. /* Transmit Almost Full Threshold */
  219. #define PCH_GBE_TM_TH_ALM_FULL_4 0x00000000 /* 4 words */
  220. #define PCH_GBE_TM_TH_ALM_FULL_8 0x00000200 /* 8 words */
  221. #define PCH_GBE_TM_TH_ALM_FULL_16 0x00000400 /* 16 words */
  222. #define PCH_GBE_TM_TH_ALM_FULL_32 0x00000600 /* 32 words */
  223. /* RX FIFO Status */
  224. #define PCH_GBE_RF_ALM_FULL 0x80000000 /* RX FIFO is almost full. */
  225. #define PCH_GBE_RF_ALM_EMP 0x40000000 /* RX FIFO is almost empty. */
  226. #define PCH_GBE_RF_RD_TRG 0x20000000 /* Become more than RH_RD_TRG. */
  227. #define PCH_GBE_RF_STRWD 0x1FFE0000 /* The word count of RX FIFO. */
  228. #define PCH_GBE_RF_RCVING 0x00010000 /* Stored in RX FIFO. */
  229. /* MAC Address Mask */
  230. #define PCH_GBE_BUSY 0x80000000
  231. /* MIIM */
  232. #define PCH_GBE_MIIM_OPER_WRITE 0x04000000
  233. #define PCH_GBE_MIIM_OPER_READ 0x00000000
  234. #define PCH_GBE_MIIM_OPER_READY 0x04000000
  235. #define PCH_GBE_MIIM_PHY_ADDR_SHIFT 21
  236. #define PCH_GBE_MIIM_REG_ADDR_SHIFT 16
  237. /* RGMII Status */
  238. #define PCH_GBE_LINK_UP 0x80000008
  239. #define PCH_GBE_RXC_SPEED_MSK 0x00000006
  240. #define PCH_GBE_RXC_SPEED_2_5M 0x00000000 /* 2.5MHz */
  241. #define PCH_GBE_RXC_SPEED_25M 0x00000002 /* 25MHz */
  242. #define PCH_GBE_RXC_SPEED_125M 0x00000004 /* 100MHz */
  243. #define PCH_GBE_DUPLEX_FULL 0x00000001
  244. /* RGMII Control */
  245. #define PCH_GBE_CRS_SEL 0x00000010
  246. #define PCH_GBE_RGMII_RATE_125M 0x00000000
  247. #define PCH_GBE_RGMII_RATE_25M 0x00000008
  248. #define PCH_GBE_RGMII_RATE_2_5M 0x0000000C
  249. #define PCH_GBE_RGMII_MODE_GMII 0x00000000
  250. #define PCH_GBE_RGMII_MODE_RGMII 0x00000002
  251. #define PCH_GBE_CHIP_TYPE_EXTERNAL 0x00000000
  252. #define PCH_GBE_CHIP_TYPE_INTERNAL 0x00000001
  253. /* DMA Control */
  254. #define PCH_GBE_RX_DMA_EN 0x00000002 /* Enables Receive DMA */
  255. #define PCH_GBE_TX_DMA_EN 0x00000001 /* Enables Transmission DMA */
  256. /* RX DMA STATUS */
  257. #define PCH_GBE_IDLE_CHECK 0xFFFFFFFE
  258. /* Wake On LAN Status */
  259. #define PCH_GBE_WLS_BR 0x00000008 /* Broadcas Address */
  260. #define PCH_GBE_WLS_MLT 0x00000004 /* Multicast Address */
  261. /* The Frame registered in Address Recognizer */
  262. #define PCH_GBE_WLS_IND 0x00000002
  263. #define PCH_GBE_WLS_MP 0x00000001 /* Magic packet Address */
  264. /* Wake On LAN Control */
  265. #define PCH_GBE_WLC_WOL_MODE 0x00010000
  266. #define PCH_GBE_WLC_IGN_TLONG 0x00000100
  267. #define PCH_GBE_WLC_IGN_TSHRT 0x00000080
  268. #define PCH_GBE_WLC_IGN_OCTER 0x00000040
  269. #define PCH_GBE_WLC_IGN_NBLER 0x00000020
  270. #define PCH_GBE_WLC_IGN_CRCER 0x00000010
  271. #define PCH_GBE_WLC_BR 0x00000008
  272. #define PCH_GBE_WLC_MLT 0x00000004
  273. #define PCH_GBE_WLC_IND 0x00000002
  274. #define PCH_GBE_WLC_MP 0x00000001
  275. /* Wake On LAN Address Mask */
  276. #define PCH_GBE_WLA_BUSY 0x80000000
  277. /* TX/RX descriptor defines */
  278. #define PCH_GBE_MAX_TXD 4096
  279. #define PCH_GBE_DEFAULT_TXD 256
  280. #define PCH_GBE_MIN_TXD 8
  281. #define PCH_GBE_MAX_RXD 4096
  282. #define PCH_GBE_DEFAULT_RXD 256
  283. #define PCH_GBE_MIN_RXD 8
  284. /* Number of Transmit and Receive Descriptors must be a multiple of 8 */
  285. #define PCH_GBE_TX_DESC_MULTIPLE 8
  286. #define PCH_GBE_RX_DESC_MULTIPLE 8
  287. /* Read/Write operation is done through MII Management IF */
  288. #define PCH_GBE_HAL_MIIM_READ ((u32)0x00000000)
  289. #define PCH_GBE_HAL_MIIM_WRITE ((u32)0x04000000)
  290. /* flow control values */
  291. #define PCH_GBE_FC_NONE 0
  292. #define PCH_GBE_FC_RX_PAUSE 1
  293. #define PCH_GBE_FC_TX_PAUSE 2
  294. #define PCH_GBE_FC_FULL 3
  295. #define PCH_GBE_FC_DEFAULT PCH_GBE_FC_FULL
  296. struct pch_gbe_hw;
  297. /**
  298. * struct pch_gbe_functions - HAL APi function pointer
  299. * @get_bus_info: for pch_gbe_hal_get_bus_info
  300. * @init_hw: for pch_gbe_hal_init_hw
  301. * @read_phy_reg: for pch_gbe_hal_read_phy_reg
  302. * @write_phy_reg: for pch_gbe_hal_write_phy_reg
  303. * @reset_phy: for pch_gbe_hal_phy_hw_reset
  304. * @sw_reset_phy: for pch_gbe_hal_phy_sw_reset
  305. * @power_up_phy: for pch_gbe_hal_power_up_phy
  306. * @power_down_phy: for pch_gbe_hal_power_down_phy
  307. * @read_mac_addr: for pch_gbe_hal_read_mac_addr
  308. */
  309. struct pch_gbe_functions {
  310. void (*get_bus_info) (struct pch_gbe_hw *);
  311. s32 (*init_hw) (struct pch_gbe_hw *);
  312. s32 (*read_phy_reg) (struct pch_gbe_hw *, u32, u16 *);
  313. s32 (*write_phy_reg) (struct pch_gbe_hw *, u32, u16);
  314. void (*reset_phy) (struct pch_gbe_hw *);
  315. void (*sw_reset_phy) (struct pch_gbe_hw *);
  316. void (*power_up_phy) (struct pch_gbe_hw *hw);
  317. void (*power_down_phy) (struct pch_gbe_hw *hw);
  318. s32 (*read_mac_addr) (struct pch_gbe_hw *);
  319. };
  320. /**
  321. * struct pch_gbe_mac_info - MAC information
  322. * @addr[6]: Store the MAC address
  323. * @fc: Mode of flow control
  324. * @fc_autoneg: Auto negotiation enable for flow control setting
  325. * @tx_fc_enable: Enable flag of Transmit flow control
  326. * @max_frame_size: Max transmit frame size
  327. * @min_frame_size: Min transmit frame size
  328. * @autoneg: Auto negotiation enable
  329. * @link_speed: Link speed
  330. * @link_duplex: Link duplex
  331. */
  332. struct pch_gbe_mac_info {
  333. u8 addr[6];
  334. u8 fc;
  335. u8 fc_autoneg;
  336. u8 tx_fc_enable;
  337. u32 max_frame_size;
  338. u32 min_frame_size;
  339. u8 autoneg;
  340. u16 link_speed;
  341. u16 link_duplex;
  342. };
  343. /**
  344. * struct pch_gbe_phy_info - PHY information
  345. * @addr: PHY address
  346. * @id: PHY's identifier
  347. * @revision: PHY's revision
  348. * @reset_delay_us: HW reset delay time[us]
  349. * @autoneg_advertised: Autoneg advertised
  350. */
  351. struct pch_gbe_phy_info {
  352. u32 addr;
  353. u32 id;
  354. u32 revision;
  355. u32 reset_delay_us;
  356. u16 autoneg_advertised;
  357. };
  358. /*!
  359. * @ingroup Gigabit Ether driver Layer
  360. * @struct pch_gbe_bus_info
  361. * @brief Bus information
  362. */
  363. struct pch_gbe_bus_info {
  364. u8 type;
  365. u8 speed;
  366. u8 width;
  367. };
  368. /*!
  369. * @ingroup Gigabit Ether driver Layer
  370. * @struct pch_gbe_hw
  371. * @brief Hardware information
  372. */
  373. struct pch_gbe_hw {
  374. void *back;
  375. struct pch_gbe_regs __iomem *reg;
  376. spinlock_t miim_lock;
  377. const struct pch_gbe_functions *func;
  378. struct pch_gbe_mac_info mac;
  379. struct pch_gbe_phy_info phy;
  380. struct pch_gbe_bus_info bus;
  381. };
  382. /**
  383. * struct pch_gbe_rx_desc - Receive Descriptor
  384. * @buffer_addr: RX Frame Buffer Address
  385. * @tcp_ip_status: TCP/IP Accelerator Status
  386. * @rx_words_eob: RX word count and Byte position
  387. * @gbec_status: GMAC Status
  388. * @dma_status: DMA Status
  389. * @reserved1: Reserved
  390. * @reserved2: Reserved
  391. */
  392. struct pch_gbe_rx_desc {
  393. u32 buffer_addr;
  394. u32 tcp_ip_status;
  395. u16 rx_words_eob;
  396. u16 gbec_status;
  397. u8 dma_status;
  398. u8 reserved1;
  399. u16 reserved2;
  400. };
  401. /**
  402. * struct pch_gbe_tx_desc - Transmit Descriptor
  403. * @buffer_addr: TX Frame Buffer Address
  404. * @length: Data buffer length
  405. * @reserved1: Reserved
  406. * @tx_words_eob: TX word count and Byte position
  407. * @tx_frame_ctrl: TX Frame Control
  408. * @dma_status: DMA Status
  409. * @reserved2: Reserved
  410. * @gbec_status: GMAC Status
  411. */
  412. struct pch_gbe_tx_desc {
  413. u32 buffer_addr;
  414. u16 length;
  415. u16 reserved1;
  416. u16 tx_words_eob;
  417. u16 tx_frame_ctrl;
  418. u8 dma_status;
  419. u8 reserved2;
  420. u16 gbec_status;
  421. };
  422. /**
  423. * struct pch_gbe_buffer - Buffer information
  424. * @skb: pointer to a socket buffer
  425. * @dma: DMA address
  426. * @time_stamp: time stamp
  427. * @length: data size
  428. */
  429. struct pch_gbe_buffer {
  430. struct sk_buff *skb;
  431. dma_addr_t dma;
  432. unsigned char *rx_buffer;
  433. unsigned long time_stamp;
  434. u16 length;
  435. bool mapped;
  436. };
  437. /**
  438. * struct pch_gbe_tx_ring - tx ring information
  439. * @tx_lock: spinlock structs
  440. * @desc: pointer to the descriptor ring memory
  441. * @dma: physical address of the descriptor ring
  442. * @size: length of descriptor ring in bytes
  443. * @count: number of descriptors in the ring
  444. * @next_to_use: next descriptor to associate a buffer with
  445. * @next_to_clean: next descriptor to check for DD status bit
  446. * @buffer_info: array of buffer information structs
  447. */
  448. struct pch_gbe_tx_ring {
  449. spinlock_t tx_lock;
  450. struct pch_gbe_tx_desc *desc;
  451. dma_addr_t dma;
  452. unsigned int size;
  453. unsigned int count;
  454. unsigned int next_to_use;
  455. unsigned int next_to_clean;
  456. struct pch_gbe_buffer *buffer_info;
  457. };
  458. /**
  459. * struct pch_gbe_rx_ring - rx ring information
  460. * @desc: pointer to the descriptor ring memory
  461. * @dma: physical address of the descriptor ring
  462. * @size: length of descriptor ring in bytes
  463. * @count: number of descriptors in the ring
  464. * @next_to_use: next descriptor to associate a buffer with
  465. * @next_to_clean: next descriptor to check for DD status bit
  466. * @buffer_info: array of buffer information structs
  467. */
  468. struct pch_gbe_rx_ring {
  469. struct pch_gbe_rx_desc *desc;
  470. dma_addr_t dma;
  471. unsigned char *rx_buff_pool;
  472. dma_addr_t rx_buff_pool_logic;
  473. unsigned int rx_buff_pool_size;
  474. unsigned int size;
  475. unsigned int count;
  476. unsigned int next_to_use;
  477. unsigned int next_to_clean;
  478. struct pch_gbe_buffer *buffer_info;
  479. };
  480. /**
  481. * struct pch_gbe_hw_stats - Statistics counters collected by the MAC
  482. * @rx_packets: total packets received
  483. * @tx_packets: total packets transmitted
  484. * @rx_bytes: total bytes received
  485. * @tx_bytes: total bytes transmitted
  486. * @rx_errors: bad packets received
  487. * @tx_errors: packet transmit problems
  488. * @rx_dropped: no space in Linux buffers
  489. * @tx_dropped: no space available in Linux
  490. * @multicast: multicast packets received
  491. * @collisions: collisions
  492. * @rx_crc_errors: received packet with crc error
  493. * @rx_frame_errors: received frame alignment error
  494. * @rx_alloc_buff_failed: allocate failure of a receive buffer
  495. * @tx_length_errors: transmit length error
  496. * @tx_aborted_errors: transmit aborted error
  497. * @tx_carrier_errors: transmit carrier error
  498. * @tx_timeout_count: Number of transmit timeout
  499. * @tx_restart_count: Number of transmit restert
  500. * @intr_rx_dsc_empty_count: Interrupt count of receive descriptor empty
  501. * @intr_rx_frame_err_count: Interrupt count of receive frame error
  502. * @intr_rx_fifo_err_count: Interrupt count of receive FIFO error
  503. * @intr_rx_dma_err_count: Interrupt count of receive DMA error
  504. * @intr_tx_fifo_err_count: Interrupt count of transmit FIFO error
  505. * @intr_tx_dma_err_count: Interrupt count of transmit DMA error
  506. * @intr_tcpip_err_count: Interrupt count of TCP/IP Accelerator
  507. */
  508. struct pch_gbe_hw_stats {
  509. u32 rx_packets;
  510. u32 tx_packets;
  511. u32 rx_bytes;
  512. u32 tx_bytes;
  513. u32 rx_errors;
  514. u32 tx_errors;
  515. u32 rx_dropped;
  516. u32 tx_dropped;
  517. u32 multicast;
  518. u32 collisions;
  519. u32 rx_crc_errors;
  520. u32 rx_frame_errors;
  521. u32 rx_alloc_buff_failed;
  522. u32 tx_length_errors;
  523. u32 tx_aborted_errors;
  524. u32 tx_carrier_errors;
  525. u32 tx_timeout_count;
  526. u32 tx_restart_count;
  527. u32 intr_rx_dsc_empty_count;
  528. u32 intr_rx_frame_err_count;
  529. u32 intr_rx_fifo_err_count;
  530. u32 intr_rx_dma_err_count;
  531. u32 intr_tx_fifo_err_count;
  532. u32 intr_tx_dma_err_count;
  533. u32 intr_tcpip_err_count;
  534. };
  535. /**
  536. * struct pch_gbe_privdata - PCI Device ID driver data
  537. * @phy_tx_clk_delay: Bool, configure the PHY TX delay in software
  538. * @phy_disable_hibernate: Bool, disable PHY hibernation
  539. * @platform_init: Platform initialization callback, called from
  540. * probe, prior to PHY initialization.
  541. */
  542. struct pch_gbe_privdata {
  543. bool phy_tx_clk_delay;
  544. bool phy_disable_hibernate;
  545. int (*platform_init)(struct pci_dev *pdev);
  546. };
  547. /**
  548. * struct pch_gbe_adapter - board specific private data structure
  549. * @stats_lock: Spinlock structure for status
  550. * @ethtool_lock: Spinlock structure for ethtool
  551. * @irq_sem: Semaphore for interrupt
  552. * @netdev: Pointer of network device structure
  553. * @pdev: Pointer of pci device structure
  554. * @polling_netdev: Pointer of polling network device structure
  555. * @napi: NAPI structure
  556. * @hw: Pointer of hardware structure
  557. * @stats: Hardware status
  558. * @reset_task: Reset task
  559. * @mii: MII information structure
  560. * @watchdog_timer: Watchdog timer list
  561. * @wake_up_evt: Wake up event
  562. * @config_space: Configuration space
  563. * @msg_enable: Driver message level
  564. * @led_status: LED status
  565. * @tx_ring: Pointer of Tx descriptor ring structure
  566. * @rx_ring: Pointer of Rx descriptor ring structure
  567. * @rx_buffer_len: Receive buffer length
  568. * @tx_queue_len: Transmit queue length
  569. * @have_msi: PCI MSI mode flag
  570. * @pch_gbe_privdata: PCI Device ID driver_data
  571. */
  572. struct pch_gbe_adapter {
  573. spinlock_t stats_lock;
  574. spinlock_t ethtool_lock;
  575. atomic_t irq_sem;
  576. struct net_device *netdev;
  577. struct pci_dev *pdev;
  578. struct net_device *polling_netdev;
  579. struct napi_struct napi;
  580. struct pch_gbe_hw hw;
  581. struct pch_gbe_hw_stats stats;
  582. struct work_struct reset_task;
  583. struct mii_if_info mii;
  584. struct timer_list watchdog_timer;
  585. u32 wake_up_evt;
  586. u32 *config_space;
  587. unsigned long led_status;
  588. struct pch_gbe_tx_ring *tx_ring;
  589. struct pch_gbe_rx_ring *rx_ring;
  590. unsigned long rx_buffer_len;
  591. unsigned long tx_queue_len;
  592. bool have_msi;
  593. bool rx_stop_flag;
  594. int hwts_tx_en;
  595. int hwts_rx_en;
  596. struct pci_dev *ptp_pdev;
  597. struct pch_gbe_privdata *pdata;
  598. };
  599. #define pch_gbe_hw_to_adapter(hw) container_of(hw, struct pch_gbe_adapter, hw)
  600. extern const char pch_driver_version[];
  601. /* pch_gbe_main.c */
  602. int pch_gbe_up(struct pch_gbe_adapter *adapter);
  603. void pch_gbe_down(struct pch_gbe_adapter *adapter);
  604. void pch_gbe_reinit_locked(struct pch_gbe_adapter *adapter);
  605. void pch_gbe_reset(struct pch_gbe_adapter *adapter);
  606. int pch_gbe_setup_tx_resources(struct pch_gbe_adapter *adapter,
  607. struct pch_gbe_tx_ring *txdr);
  608. int pch_gbe_setup_rx_resources(struct pch_gbe_adapter *adapter,
  609. struct pch_gbe_rx_ring *rxdr);
  610. void pch_gbe_free_tx_resources(struct pch_gbe_adapter *adapter,
  611. struct pch_gbe_tx_ring *tx_ring);
  612. void pch_gbe_free_rx_resources(struct pch_gbe_adapter *adapter,
  613. struct pch_gbe_rx_ring *rx_ring);
  614. void pch_gbe_update_stats(struct pch_gbe_adapter *adapter);
  615. u32 pch_ch_control_read(struct pci_dev *pdev);
  616. void pch_ch_control_write(struct pci_dev *pdev, u32 val);
  617. u32 pch_ch_event_read(struct pci_dev *pdev);
  618. void pch_ch_event_write(struct pci_dev *pdev, u32 val);
  619. u32 pch_src_uuid_lo_read(struct pci_dev *pdev);
  620. u32 pch_src_uuid_hi_read(struct pci_dev *pdev);
  621. u64 pch_rx_snap_read(struct pci_dev *pdev);
  622. u64 pch_tx_snap_read(struct pci_dev *pdev);
  623. int pch_set_station_address(u8 *addr, struct pci_dev *pdev);
  624. /* pch_gbe_param.c */
  625. void pch_gbe_check_options(struct pch_gbe_adapter *adapter);
  626. /* pch_gbe_ethtool.c */
  627. void pch_gbe_set_ethtool_ops(struct net_device *netdev);
  628. /* pch_gbe_mac.c */
  629. s32 pch_gbe_mac_force_mac_fc(struct pch_gbe_hw *hw);
  630. s32 pch_gbe_mac_read_mac_addr(struct pch_gbe_hw *hw);
  631. u16 pch_gbe_mac_ctrl_miim(struct pch_gbe_hw *hw, u32 addr, u32 dir, u32 reg,
  632. u16 data);
  633. #endif /* _PCH_GBE_H_ */