common.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*******************************************************************************
  2. STMMAC Common Header File
  3. Copyright (C) 2007-2009 STMicroelectronics Ltd
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  17. *******************************************************************************/
  18. #ifndef __COMMON_H__
  19. #define __COMMON_H__
  20. #include <linux/etherdevice.h>
  21. #include <linux/netdevice.h>
  22. #include <linux/phy.h>
  23. #include <linux/module.h>
  24. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  25. #define STMMAC_VLAN_TAG_USED
  26. #include <linux/if_vlan.h>
  27. #endif
  28. #include "descs.h"
  29. #include "mmc.h"
  30. /* Synopsys Core versions */
  31. #define DWMAC_CORE_3_40 0x34
  32. #define DWMAC_CORE_3_50 0x35
  33. #undef FRAME_FILTER_DEBUG
  34. /* #define FRAME_FILTER_DEBUG */
  35. /* Extra statistic and debug information exposed by ethtool */
  36. struct stmmac_extra_stats {
  37. /* Transmit errors */
  38. unsigned long tx_underflow ____cacheline_aligned;
  39. unsigned long tx_carrier;
  40. unsigned long tx_losscarrier;
  41. unsigned long vlan_tag;
  42. unsigned long tx_deferred;
  43. unsigned long tx_vlan;
  44. unsigned long tx_jabber;
  45. unsigned long tx_frame_flushed;
  46. unsigned long tx_payload_error;
  47. unsigned long tx_ip_header_error;
  48. /* Receive errors */
  49. unsigned long rx_desc;
  50. unsigned long sa_filter_fail;
  51. unsigned long overflow_error;
  52. unsigned long ipc_csum_error;
  53. unsigned long rx_collision;
  54. unsigned long rx_crc;
  55. unsigned long dribbling_bit;
  56. unsigned long rx_length;
  57. unsigned long rx_mii;
  58. unsigned long rx_multicast;
  59. unsigned long rx_gmac_overflow;
  60. unsigned long rx_watchdog;
  61. unsigned long da_rx_filter_fail;
  62. unsigned long sa_rx_filter_fail;
  63. unsigned long rx_missed_cntr;
  64. unsigned long rx_overflow_cntr;
  65. unsigned long rx_vlan;
  66. /* Tx/Rx IRQ error info */
  67. unsigned long tx_undeflow_irq;
  68. unsigned long tx_process_stopped_irq;
  69. unsigned long tx_jabber_irq;
  70. unsigned long rx_overflow_irq;
  71. unsigned long rx_buf_unav_irq;
  72. unsigned long rx_process_stopped_irq;
  73. unsigned long rx_watchdog_irq;
  74. unsigned long tx_early_irq;
  75. unsigned long fatal_bus_error_irq;
  76. /* Tx/Rx IRQ Events */
  77. unsigned long rx_early_irq;
  78. unsigned long threshold;
  79. unsigned long tx_pkt_n;
  80. unsigned long rx_pkt_n;
  81. unsigned long normal_irq_n;
  82. unsigned long rx_normal_irq_n;
  83. unsigned long napi_poll;
  84. unsigned long tx_normal_irq_n;
  85. unsigned long tx_clean;
  86. unsigned long tx_reset_ic_bit;
  87. unsigned long irq_receive_pmt_irq_n;
  88. /* MMC info */
  89. unsigned long mmc_tx_irq_n;
  90. unsigned long mmc_rx_irq_n;
  91. unsigned long mmc_rx_csum_offload_irq_n;
  92. /* EEE */
  93. unsigned long irq_tx_path_in_lpi_mode_n;
  94. unsigned long irq_tx_path_exit_lpi_mode_n;
  95. unsigned long irq_rx_path_in_lpi_mode_n;
  96. unsigned long irq_rx_path_exit_lpi_mode_n;
  97. unsigned long phy_eee_wakeup_error_n;
  98. /* Extended RDES status */
  99. unsigned long ip_hdr_err;
  100. unsigned long ip_payload_err;
  101. unsigned long ip_csum_bypassed;
  102. unsigned long ipv4_pkt_rcvd;
  103. unsigned long ipv6_pkt_rcvd;
  104. unsigned long rx_msg_type_ext_no_ptp;
  105. unsigned long rx_msg_type_sync;
  106. unsigned long rx_msg_type_follow_up;
  107. unsigned long rx_msg_type_delay_req;
  108. unsigned long rx_msg_type_delay_resp;
  109. unsigned long rx_msg_type_pdelay_req;
  110. unsigned long rx_msg_type_pdelay_resp;
  111. unsigned long rx_msg_type_pdelay_follow_up;
  112. unsigned long ptp_frame_type;
  113. unsigned long ptp_ver;
  114. unsigned long timestamp_dropped;
  115. unsigned long av_pkt_rcvd;
  116. unsigned long av_tagged_pkt_rcvd;
  117. unsigned long vlan_tag_priority_val;
  118. unsigned long l3_filter_match;
  119. unsigned long l4_filter_match;
  120. unsigned long l3_l4_filter_no_match;
  121. /* PCS */
  122. unsigned long irq_pcs_ane_n;
  123. unsigned long irq_pcs_link_n;
  124. unsigned long irq_rgmii_n;
  125. unsigned long pcs_link;
  126. unsigned long pcs_duplex;
  127. unsigned long pcs_speed;
  128. };
  129. /* CSR Frequency Access Defines*/
  130. #define CSR_F_35M 35000000
  131. #define CSR_F_60M 60000000
  132. #define CSR_F_100M 100000000
  133. #define CSR_F_150M 150000000
  134. #define CSR_F_250M 250000000
  135. #define CSR_F_300M 300000000
  136. #define MAC_CSR_H_FRQ_MASK 0x20
  137. #define HASH_TABLE_SIZE 64
  138. #define PAUSE_TIME 0xffff
  139. /* Flow Control defines */
  140. #define FLOW_OFF 0
  141. #define FLOW_RX 1
  142. #define FLOW_TX 2
  143. #define FLOW_AUTO (FLOW_TX | FLOW_RX)
  144. /* PCS defines */
  145. #define STMMAC_PCS_RGMII (1 << 0)
  146. #define STMMAC_PCS_SGMII (1 << 1)
  147. #define STMMAC_PCS_TBI (1 << 2)
  148. #define STMMAC_PCS_RTBI (1 << 3)
  149. #define SF_DMA_MODE 1 /* DMA STORE-AND-FORWARD Operation Mode */
  150. /* DAM HW feature register fields */
  151. #define DMA_HW_FEAT_MIISEL 0x00000001 /* 10/100 Mbps Support */
  152. #define DMA_HW_FEAT_GMIISEL 0x00000002 /* 1000 Mbps Support */
  153. #define DMA_HW_FEAT_HDSEL 0x00000004 /* Half-Duplex Support */
  154. #define DMA_HW_FEAT_EXTHASHEN 0x00000008 /* Expanded DA Hash Filter */
  155. #define DMA_HW_FEAT_HASHSEL 0x00000010 /* HASH Filter */
  156. #define DMA_HW_FEAT_ADDMAC 0x00000020 /* Multiple MAC Addr Reg */
  157. #define DMA_HW_FEAT_PCSSEL 0x00000040 /* PCS registers */
  158. #define DMA_HW_FEAT_L3L4FLTREN 0x00000080 /* Layer 3 & Layer 4 Feature */
  159. #define DMA_HW_FEAT_SMASEL 0x00000100 /* SMA(MDIO) Interface */
  160. #define DMA_HW_FEAT_RWKSEL 0x00000200 /* PMT Remote Wakeup */
  161. #define DMA_HW_FEAT_MGKSEL 0x00000400 /* PMT Magic Packet */
  162. #define DMA_HW_FEAT_MMCSEL 0x00000800 /* RMON Module */
  163. #define DMA_HW_FEAT_TSVER1SEL 0x00001000 /* Only IEEE 1588-2002 */
  164. #define DMA_HW_FEAT_TSVER2SEL 0x00002000 /* IEEE 1588-2008 PTPv2 */
  165. #define DMA_HW_FEAT_EEESEL 0x00004000 /* Energy Efficient Ethernet */
  166. #define DMA_HW_FEAT_AVSEL 0x00008000 /* AV Feature */
  167. #define DMA_HW_FEAT_TXCOESEL 0x00010000 /* Checksum Offload in Tx */
  168. #define DMA_HW_FEAT_RXTYP1COE 0x00020000 /* IP COE (Type 1) in Rx */
  169. #define DMA_HW_FEAT_RXTYP2COE 0x00040000 /* IP COE (Type 2) in Rx */
  170. #define DMA_HW_FEAT_RXFIFOSIZE 0x00080000 /* Rx FIFO > 2048 Bytes */
  171. #define DMA_HW_FEAT_RXCHCNT 0x00300000 /* No. additional Rx Channels */
  172. #define DMA_HW_FEAT_TXCHCNT 0x00c00000 /* No. additional Tx Channels */
  173. #define DMA_HW_FEAT_ENHDESSEL 0x01000000 /* Alternate Descriptor */
  174. /* Timestamping with Internal System Time */
  175. #define DMA_HW_FEAT_INTTSEN 0x02000000
  176. #define DMA_HW_FEAT_FLEXIPPSEN 0x04000000 /* Flexible PPS Output */
  177. #define DMA_HW_FEAT_SAVLANINS 0x08000000 /* Source Addr or VLAN */
  178. #define DMA_HW_FEAT_ACTPHYIF 0x70000000 /* Active/selected PHY iface */
  179. #define DEFAULT_DMA_PBL 8
  180. /* Max/Min RI Watchdog Timer count value */
  181. #define MAX_DMA_RIWT 0xff
  182. #define MIN_DMA_RIWT 0x20
  183. /* Tx coalesce parameters */
  184. #define STMMAC_COAL_TX_TIMER 40000
  185. #define STMMAC_MAX_COAL_TX_TICK 100000
  186. #define STMMAC_TX_MAX_FRAMES 256
  187. #define STMMAC_TX_FRAMES 64
  188. /* Rx IPC status */
  189. enum rx_frame_status {
  190. good_frame = 0,
  191. discard_frame = 1,
  192. csum_none = 2,
  193. llc_snap = 4,
  194. };
  195. enum dma_irq_status {
  196. tx_hard_error = 0x1,
  197. tx_hard_error_bump_tc = 0x2,
  198. handle_rx = 0x4,
  199. handle_tx = 0x8,
  200. };
  201. /* EEE and LPI defines */
  202. #define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 0)
  203. #define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 1)
  204. #define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 2)
  205. #define CORE_IRQ_RX_PATH_EXIT_LPI_MODE (1 << 3)
  206. #define CORE_PCS_ANE_COMPLETE (1 << 5)
  207. #define CORE_PCS_LINK_STATUS (1 << 6)
  208. #define CORE_RGMII_IRQ (1 << 7)
  209. /* Physical Coding Sublayer */
  210. struct rgmii_adv {
  211. unsigned int pause;
  212. unsigned int duplex;
  213. unsigned int lp_pause;
  214. unsigned int lp_duplex;
  215. };
  216. #define STMMAC_PCS_PAUSE 1
  217. #define STMMAC_PCS_ASYM_PAUSE 2
  218. /* DMA HW capabilities */
  219. struct dma_features {
  220. unsigned int mbps_10_100;
  221. unsigned int mbps_1000;
  222. unsigned int half_duplex;
  223. unsigned int hash_filter;
  224. unsigned int multi_addr;
  225. unsigned int pcs;
  226. unsigned int sma_mdio;
  227. unsigned int pmt_remote_wake_up;
  228. unsigned int pmt_magic_frame;
  229. unsigned int rmon;
  230. /* IEEE 1588-2002 */
  231. unsigned int time_stamp;
  232. /* IEEE 1588-2008 */
  233. unsigned int atime_stamp;
  234. /* 802.3az - Energy-Efficient Ethernet (EEE) */
  235. unsigned int eee;
  236. unsigned int av;
  237. /* TX and RX csum */
  238. unsigned int tx_coe;
  239. unsigned int rx_coe_type1;
  240. unsigned int rx_coe_type2;
  241. unsigned int rxfifo_over_2048;
  242. /* TX and RX number of channels */
  243. unsigned int number_rx_channel;
  244. unsigned int number_tx_channel;
  245. /* Alternate (enhanced) DESC mode */
  246. unsigned int enh_desc;
  247. };
  248. /* GMAC TX FIFO is 8K, Rx FIFO is 16K */
  249. #define BUF_SIZE_16KiB 16384
  250. #define BUF_SIZE_8KiB 8192
  251. #define BUF_SIZE_4KiB 4096
  252. #define BUF_SIZE_2KiB 2048
  253. /* Power Down and WOL */
  254. #define PMT_NOT_SUPPORTED 0
  255. #define PMT_SUPPORTED 1
  256. /* Common MAC defines */
  257. #define MAC_CTRL_REG 0x00000000 /* MAC Control */
  258. #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */
  259. #define MAC_RNABLE_RX 0x00000004 /* Receiver Enable */
  260. /* Default LPI timers */
  261. #define STMMAC_DEFAULT_LIT_LS 0x3E8
  262. #define STMMAC_DEFAULT_TWT_LS 0x1E
  263. #define STMMAC_CHAIN_MODE 0x1
  264. #define STMMAC_RING_MODE 0x2
  265. #define JUMBO_LEN 9000
  266. /* Descriptors helpers */
  267. struct stmmac_desc_ops {
  268. /* DMA RX descriptor ring initialization */
  269. void (*init_rx_desc) (struct dma_desc *p, int disable_rx_ic, int mode,
  270. int end);
  271. /* DMA TX descriptor ring initialization */
  272. void (*init_tx_desc) (struct dma_desc *p, int mode, int end);
  273. /* Invoked by the xmit function to prepare the tx descriptor */
  274. void (*prepare_tx_desc) (struct dma_desc *p, int is_fs, int len,
  275. int csum_flag, int mode);
  276. /* Set/get the owner of the descriptor */
  277. void (*set_tx_owner) (struct dma_desc *p);
  278. int (*get_tx_owner) (struct dma_desc *p);
  279. /* Invoked by the xmit function to close the tx descriptor */
  280. void (*close_tx_desc) (struct dma_desc *p);
  281. /* Clean the tx descriptor as soon as the tx irq is received */
  282. void (*release_tx_desc) (struct dma_desc *p, int mode);
  283. /* Clear interrupt on tx frame completion. When this bit is
  284. * set an interrupt happens as soon as the frame is transmitted */
  285. void (*clear_tx_ic) (struct dma_desc *p);
  286. /* Last tx segment reports the transmit status */
  287. int (*get_tx_ls) (struct dma_desc *p);
  288. /* Return the transmit status looking at the TDES1 */
  289. int (*tx_status) (void *data, struct stmmac_extra_stats *x,
  290. struct dma_desc *p, void __iomem *ioaddr);
  291. /* Get the buffer size from the descriptor */
  292. int (*get_tx_len) (struct dma_desc *p);
  293. /* Handle extra events on specific interrupts hw dependent */
  294. int (*get_rx_owner) (struct dma_desc *p);
  295. void (*set_rx_owner) (struct dma_desc *p);
  296. /* Get the receive frame size */
  297. int (*get_rx_frame_len) (struct dma_desc *p, int rx_coe_type);
  298. /* Return the reception status looking at the RDES1 */
  299. int (*rx_status) (void *data, struct stmmac_extra_stats *x,
  300. struct dma_desc *p);
  301. void (*rx_extended_status) (void *data, struct stmmac_extra_stats *x,
  302. struct dma_extended_desc *p);
  303. /* Set tx timestamp enable bit */
  304. void (*enable_tx_timestamp) (struct dma_desc *p);
  305. /* get tx timestamp status */
  306. int (*get_tx_timestamp_status) (struct dma_desc *p);
  307. /* get timestamp value */
  308. u64(*get_timestamp) (void *desc, u32 ats);
  309. /* get rx timestamp status */
  310. int (*get_rx_timestamp_status) (void *desc, u32 ats);
  311. };
  312. extern const struct stmmac_desc_ops enh_desc_ops;
  313. extern const struct stmmac_desc_ops ndesc_ops;
  314. /* Specific DMA helpers */
  315. struct stmmac_dma_ops {
  316. /* DMA core initialization */
  317. int (*init) (void __iomem *ioaddr, int pbl, int fb, int mb,
  318. int burst_len, u32 dma_tx, u32 dma_rx, int atds);
  319. /* Dump DMA registers */
  320. void (*dump_regs) (void __iomem *ioaddr);
  321. /* Set tx/rx threshold in the csr6 register
  322. * An invalid value enables the store-and-forward mode */
  323. void (*dma_mode)(void __iomem *ioaddr, int txmode, int rxmode,
  324. int rxfifosz);
  325. /* To track extra statistic (if supported) */
  326. void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
  327. void __iomem *ioaddr);
  328. void (*enable_dma_transmission) (void __iomem *ioaddr);
  329. void (*enable_dma_irq) (void __iomem *ioaddr);
  330. void (*disable_dma_irq) (void __iomem *ioaddr);
  331. void (*start_tx) (void __iomem *ioaddr);
  332. void (*stop_tx) (void __iomem *ioaddr);
  333. void (*start_rx) (void __iomem *ioaddr);
  334. void (*stop_rx) (void __iomem *ioaddr);
  335. int (*dma_interrupt) (void __iomem *ioaddr,
  336. struct stmmac_extra_stats *x);
  337. /* If supported then get the optional core features */
  338. unsigned int (*get_hw_feature) (void __iomem *ioaddr);
  339. /* Program the HW RX Watchdog */
  340. void (*rx_watchdog) (void __iomem *ioaddr, u32 riwt);
  341. };
  342. struct mac_device_info;
  343. /* Helpers to program the MAC core */
  344. struct stmmac_ops {
  345. /* MAC core initialization */
  346. void (*core_init)(struct mac_device_info *hw, int mtu);
  347. /* Enable and verify that the IPC module is supported */
  348. int (*rx_ipc)(struct mac_device_info *hw);
  349. /* Dump MAC registers */
  350. void (*dump_regs)(struct mac_device_info *hw);
  351. /* Handle extra events on specific interrupts hw dependent */
  352. int (*host_irq_status)(struct mac_device_info *hw,
  353. struct stmmac_extra_stats *x);
  354. /* Multicast filter setting */
  355. void (*set_filter)(struct mac_device_info *hw, struct net_device *dev);
  356. /* Flow control setting */
  357. void (*flow_ctrl)(struct mac_device_info *hw, unsigned int duplex,
  358. unsigned int fc, unsigned int pause_time);
  359. /* Set power management mode (e.g. magic frame) */
  360. void (*pmt)(struct mac_device_info *hw, unsigned long mode);
  361. /* Set/Get Unicast MAC addresses */
  362. void (*set_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
  363. unsigned int reg_n);
  364. void (*get_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
  365. unsigned int reg_n);
  366. void (*set_eee_mode)(struct mac_device_info *hw);
  367. void (*reset_eee_mode)(struct mac_device_info *hw);
  368. void (*set_eee_timer)(struct mac_device_info *hw, int ls, int tw);
  369. void (*set_eee_pls)(struct mac_device_info *hw, int link);
  370. void (*ctrl_ane)(struct mac_device_info *hw, bool restart);
  371. void (*get_adv)(struct mac_device_info *hw, struct rgmii_adv *adv);
  372. };
  373. /* PTP and HW Timer helpers */
  374. struct stmmac_hwtimestamp {
  375. void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
  376. void (*config_sub_second_increment) (void __iomem *ioaddr);
  377. int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
  378. int (*config_addend) (void __iomem *ioaddr, u32 addend);
  379. int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
  380. int add_sub);
  381. u64(*get_systime) (void __iomem *ioaddr);
  382. };
  383. extern const struct stmmac_hwtimestamp stmmac_ptp;
  384. struct mac_link {
  385. int port;
  386. int duplex;
  387. int speed;
  388. };
  389. struct mii_regs {
  390. unsigned int addr; /* MII Address */
  391. unsigned int data; /* MII Data */
  392. };
  393. /* Helpers to manage the descriptors for chain and ring modes */
  394. struct stmmac_mode_ops {
  395. void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
  396. unsigned int extend_desc);
  397. unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
  398. int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
  399. int (*set_16kib_bfsize)(int mtu);
  400. void (*init_desc3)(struct dma_desc *p);
  401. void (*refill_desc3) (void *priv, struct dma_desc *p);
  402. void (*clean_desc3) (void *priv, struct dma_desc *p);
  403. };
  404. struct mac_device_info {
  405. const struct stmmac_ops *mac;
  406. const struct stmmac_desc_ops *desc;
  407. const struct stmmac_dma_ops *dma;
  408. const struct stmmac_mode_ops *mode;
  409. const struct stmmac_hwtimestamp *ptp;
  410. struct mii_regs mii; /* MII register Addresses */
  411. struct mac_link link;
  412. unsigned int synopsys_uid;
  413. void __iomem *pcsr; /* vpointer to device CSRs */
  414. int multicast_filter_bins;
  415. int unicast_filter_entries;
  416. int mcast_bits_log2;
  417. unsigned int rx_csum;
  418. };
  419. struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
  420. int perfect_uc_entries);
  421. struct mac_device_info *dwmac100_setup(void __iomem *ioaddr);
  422. void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
  423. unsigned int high, unsigned int low);
  424. void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
  425. unsigned int high, unsigned int low);
  426. void stmmac_set_mac(void __iomem *ioaddr, bool enable);
  427. void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
  428. extern const struct stmmac_mode_ops ring_mode_ops;
  429. extern const struct stmmac_mode_ops chain_mode_ops;
  430. #endif /* __COMMON_H__ */