pch_gbe.h 23 KB

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