common.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  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/stmmac.h>
  23. #include <linux/phy.h>
  24. #include <linux/module.h>
  25. #if IS_ENABLED(CONFIG_VLAN_8021Q)
  26. #define STMMAC_VLAN_TAG_USED
  27. #include <linux/if_vlan.h>
  28. #endif
  29. #include "descs.h"
  30. #include "mmc.h"
  31. /* Synopsys Core versions */
  32. #define DWMAC_CORE_3_40 0x34
  33. #define DWMAC_CORE_3_50 0x35
  34. #define DWMAC_CORE_4_00 0x40
  35. #define STMMAC_CHAN0 0 /* Always supported and default for all chips */
  36. #define DMA_TX_SIZE 512
  37. #define DMA_RX_SIZE 512
  38. #define STMMAC_GET_ENTRY(x, size) ((x + 1) & (size - 1))
  39. #undef FRAME_FILTER_DEBUG
  40. /* #define FRAME_FILTER_DEBUG */
  41. /* Extra statistic and debug information exposed by ethtool */
  42. struct stmmac_extra_stats {
  43. /* Transmit errors */
  44. unsigned long tx_underflow ____cacheline_aligned;
  45. unsigned long tx_carrier;
  46. unsigned long tx_losscarrier;
  47. unsigned long vlan_tag;
  48. unsigned long tx_deferred;
  49. unsigned long tx_vlan;
  50. unsigned long tx_jabber;
  51. unsigned long tx_frame_flushed;
  52. unsigned long tx_payload_error;
  53. unsigned long tx_ip_header_error;
  54. /* Receive errors */
  55. unsigned long rx_desc;
  56. unsigned long sa_filter_fail;
  57. unsigned long overflow_error;
  58. unsigned long ipc_csum_error;
  59. unsigned long rx_collision;
  60. unsigned long rx_crc;
  61. unsigned long dribbling_bit;
  62. unsigned long rx_length;
  63. unsigned long rx_mii;
  64. unsigned long rx_multicast;
  65. unsigned long rx_gmac_overflow;
  66. unsigned long rx_watchdog;
  67. unsigned long da_rx_filter_fail;
  68. unsigned long sa_rx_filter_fail;
  69. unsigned long rx_missed_cntr;
  70. unsigned long rx_overflow_cntr;
  71. unsigned long rx_vlan;
  72. /* Tx/Rx IRQ error info */
  73. unsigned long tx_undeflow_irq;
  74. unsigned long tx_process_stopped_irq;
  75. unsigned long tx_jabber_irq;
  76. unsigned long rx_overflow_irq;
  77. unsigned long rx_buf_unav_irq;
  78. unsigned long rx_process_stopped_irq;
  79. unsigned long rx_watchdog_irq;
  80. unsigned long tx_early_irq;
  81. unsigned long fatal_bus_error_irq;
  82. /* Tx/Rx IRQ Events */
  83. unsigned long rx_early_irq;
  84. unsigned long threshold;
  85. unsigned long tx_pkt_n;
  86. unsigned long rx_pkt_n;
  87. unsigned long normal_irq_n;
  88. unsigned long rx_normal_irq_n;
  89. unsigned long napi_poll;
  90. unsigned long tx_normal_irq_n;
  91. unsigned long tx_clean;
  92. unsigned long tx_set_ic_bit;
  93. unsigned long irq_receive_pmt_irq_n;
  94. /* MMC info */
  95. unsigned long mmc_tx_irq_n;
  96. unsigned long mmc_rx_irq_n;
  97. unsigned long mmc_rx_csum_offload_irq_n;
  98. /* EEE */
  99. unsigned long irq_tx_path_in_lpi_mode_n;
  100. unsigned long irq_tx_path_exit_lpi_mode_n;
  101. unsigned long irq_rx_path_in_lpi_mode_n;
  102. unsigned long irq_rx_path_exit_lpi_mode_n;
  103. unsigned long phy_eee_wakeup_error_n;
  104. /* Extended RDES status */
  105. unsigned long ip_hdr_err;
  106. unsigned long ip_payload_err;
  107. unsigned long ip_csum_bypassed;
  108. unsigned long ipv4_pkt_rcvd;
  109. unsigned long ipv6_pkt_rcvd;
  110. unsigned long no_ptp_rx_msg_type_ext;
  111. unsigned long ptp_rx_msg_type_sync;
  112. unsigned long ptp_rx_msg_type_follow_up;
  113. unsigned long ptp_rx_msg_type_delay_req;
  114. unsigned long ptp_rx_msg_type_delay_resp;
  115. unsigned long ptp_rx_msg_type_pdelay_req;
  116. unsigned long ptp_rx_msg_type_pdelay_resp;
  117. unsigned long ptp_rx_msg_type_pdelay_follow_up;
  118. unsigned long ptp_rx_msg_type_announce;
  119. unsigned long ptp_rx_msg_type_management;
  120. unsigned long ptp_rx_msg_pkt_reserved_type;
  121. unsigned long ptp_frame_type;
  122. unsigned long ptp_ver;
  123. unsigned long timestamp_dropped;
  124. unsigned long av_pkt_rcvd;
  125. unsigned long av_tagged_pkt_rcvd;
  126. unsigned long vlan_tag_priority_val;
  127. unsigned long l3_filter_match;
  128. unsigned long l4_filter_match;
  129. unsigned long l3_l4_filter_no_match;
  130. /* PCS */
  131. unsigned long irq_pcs_ane_n;
  132. unsigned long irq_pcs_link_n;
  133. unsigned long irq_rgmii_n;
  134. unsigned long pcs_link;
  135. unsigned long pcs_duplex;
  136. unsigned long pcs_speed;
  137. /* debug register */
  138. unsigned long mtl_tx_status_fifo_full;
  139. unsigned long mtl_tx_fifo_not_empty;
  140. unsigned long mmtl_fifo_ctrl;
  141. unsigned long mtl_tx_fifo_read_ctrl_write;
  142. unsigned long mtl_tx_fifo_read_ctrl_wait;
  143. unsigned long mtl_tx_fifo_read_ctrl_read;
  144. unsigned long mtl_tx_fifo_read_ctrl_idle;
  145. unsigned long mac_tx_in_pause;
  146. unsigned long mac_tx_frame_ctrl_xfer;
  147. unsigned long mac_tx_frame_ctrl_idle;
  148. unsigned long mac_tx_frame_ctrl_wait;
  149. unsigned long mac_tx_frame_ctrl_pause;
  150. unsigned long mac_gmii_tx_proto_engine;
  151. unsigned long mtl_rx_fifo_fill_level_full;
  152. unsigned long mtl_rx_fifo_fill_above_thresh;
  153. unsigned long mtl_rx_fifo_fill_below_thresh;
  154. unsigned long mtl_rx_fifo_fill_level_empty;
  155. unsigned long mtl_rx_fifo_read_ctrl_flush;
  156. unsigned long mtl_rx_fifo_read_ctrl_read_data;
  157. unsigned long mtl_rx_fifo_read_ctrl_status;
  158. unsigned long mtl_rx_fifo_read_ctrl_idle;
  159. unsigned long mtl_rx_fifo_ctrl_active;
  160. unsigned long mac_rx_frame_ctrl_fifo;
  161. unsigned long mac_gmii_rx_proto_engine;
  162. /* TSO */
  163. unsigned long tx_tso_frames;
  164. unsigned long tx_tso_nfrags;
  165. };
  166. /* CSR Frequency Access Defines*/
  167. #define CSR_F_35M 35000000
  168. #define CSR_F_60M 60000000
  169. #define CSR_F_100M 100000000
  170. #define CSR_F_150M 150000000
  171. #define CSR_F_250M 250000000
  172. #define CSR_F_300M 300000000
  173. #define MAC_CSR_H_FRQ_MASK 0x20
  174. #define HASH_TABLE_SIZE 64
  175. #define PAUSE_TIME 0xffff
  176. /* Flow Control defines */
  177. #define FLOW_OFF 0
  178. #define FLOW_RX 1
  179. #define FLOW_TX 2
  180. #define FLOW_AUTO (FLOW_TX | FLOW_RX)
  181. /* PCS defines */
  182. #define STMMAC_PCS_RGMII (1 << 0)
  183. #define STMMAC_PCS_SGMII (1 << 1)
  184. #define STMMAC_PCS_TBI (1 << 2)
  185. #define STMMAC_PCS_RTBI (1 << 3)
  186. #define SF_DMA_MODE 1 /* DMA STORE-AND-FORWARD Operation Mode */
  187. /* DAM HW feature register fields */
  188. #define DMA_HW_FEAT_MIISEL 0x00000001 /* 10/100 Mbps Support */
  189. #define DMA_HW_FEAT_GMIISEL 0x00000002 /* 1000 Mbps Support */
  190. #define DMA_HW_FEAT_HDSEL 0x00000004 /* Half-Duplex Support */
  191. #define DMA_HW_FEAT_EXTHASHEN 0x00000008 /* Expanded DA Hash Filter */
  192. #define DMA_HW_FEAT_HASHSEL 0x00000010 /* HASH Filter */
  193. #define DMA_HW_FEAT_ADDMAC 0x00000020 /* Multiple MAC Addr Reg */
  194. #define DMA_HW_FEAT_PCSSEL 0x00000040 /* PCS registers */
  195. #define DMA_HW_FEAT_L3L4FLTREN 0x00000080 /* Layer 3 & Layer 4 Feature */
  196. #define DMA_HW_FEAT_SMASEL 0x00000100 /* SMA(MDIO) Interface */
  197. #define DMA_HW_FEAT_RWKSEL 0x00000200 /* PMT Remote Wakeup */
  198. #define DMA_HW_FEAT_MGKSEL 0x00000400 /* PMT Magic Packet */
  199. #define DMA_HW_FEAT_MMCSEL 0x00000800 /* RMON Module */
  200. #define DMA_HW_FEAT_TSVER1SEL 0x00001000 /* Only IEEE 1588-2002 */
  201. #define DMA_HW_FEAT_TSVER2SEL 0x00002000 /* IEEE 1588-2008 PTPv2 */
  202. #define DMA_HW_FEAT_EEESEL 0x00004000 /* Energy Efficient Ethernet */
  203. #define DMA_HW_FEAT_AVSEL 0x00008000 /* AV Feature */
  204. #define DMA_HW_FEAT_TXCOESEL 0x00010000 /* Checksum Offload in Tx */
  205. #define DMA_HW_FEAT_RXTYP1COE 0x00020000 /* IP COE (Type 1) in Rx */
  206. #define DMA_HW_FEAT_RXTYP2COE 0x00040000 /* IP COE (Type 2) in Rx */
  207. #define DMA_HW_FEAT_RXFIFOSIZE 0x00080000 /* Rx FIFO > 2048 Bytes */
  208. #define DMA_HW_FEAT_RXCHCNT 0x00300000 /* No. additional Rx Channels */
  209. #define DMA_HW_FEAT_TXCHCNT 0x00c00000 /* No. additional Tx Channels */
  210. #define DMA_HW_FEAT_ENHDESSEL 0x01000000 /* Alternate Descriptor */
  211. /* Timestamping with Internal System Time */
  212. #define DMA_HW_FEAT_INTTSEN 0x02000000
  213. #define DMA_HW_FEAT_FLEXIPPSEN 0x04000000 /* Flexible PPS Output */
  214. #define DMA_HW_FEAT_SAVLANINS 0x08000000 /* Source Addr or VLAN */
  215. #define DMA_HW_FEAT_ACTPHYIF 0x70000000 /* Active/selected PHY iface */
  216. #define DEFAULT_DMA_PBL 8
  217. /* PCS status and mask defines */
  218. #define PCS_ANE_IRQ BIT(2) /* PCS Auto-Negotiation */
  219. #define PCS_LINK_IRQ BIT(1) /* PCS Link */
  220. #define PCS_RGSMIIIS_IRQ BIT(0) /* RGMII or SMII Interrupt */
  221. /* Max/Min RI Watchdog Timer count value */
  222. #define MAX_DMA_RIWT 0xff
  223. #define MIN_DMA_RIWT 0x20
  224. /* Tx coalesce parameters */
  225. #define STMMAC_COAL_TX_TIMER 40000
  226. #define STMMAC_MAX_COAL_TX_TICK 100000
  227. #define STMMAC_TX_MAX_FRAMES 256
  228. #define STMMAC_TX_FRAMES 64
  229. /* Rx IPC status */
  230. enum rx_frame_status {
  231. good_frame = 0x0,
  232. discard_frame = 0x1,
  233. csum_none = 0x2,
  234. llc_snap = 0x4,
  235. dma_own = 0x8,
  236. rx_not_ls = 0x10,
  237. };
  238. /* Tx status */
  239. enum tx_frame_status {
  240. tx_done = 0x0,
  241. tx_not_ls = 0x1,
  242. tx_err = 0x2,
  243. tx_dma_own = 0x4,
  244. };
  245. enum dma_irq_status {
  246. tx_hard_error = 0x1,
  247. tx_hard_error_bump_tc = 0x2,
  248. handle_rx = 0x4,
  249. handle_tx = 0x8,
  250. };
  251. /* EEE and LPI defines */
  252. #define CORE_IRQ_TX_PATH_IN_LPI_MODE (1 << 0)
  253. #define CORE_IRQ_TX_PATH_EXIT_LPI_MODE (1 << 1)
  254. #define CORE_IRQ_RX_PATH_IN_LPI_MODE (1 << 2)
  255. #define CORE_IRQ_RX_PATH_EXIT_LPI_MODE (1 << 3)
  256. #define CORE_IRQ_MTL_RX_OVERFLOW BIT(8)
  257. /* Physical Coding Sublayer */
  258. struct rgmii_adv {
  259. unsigned int pause;
  260. unsigned int duplex;
  261. unsigned int lp_pause;
  262. unsigned int lp_duplex;
  263. };
  264. #define STMMAC_PCS_PAUSE 1
  265. #define STMMAC_PCS_ASYM_PAUSE 2
  266. /* DMA HW capabilities */
  267. struct dma_features {
  268. unsigned int mbps_10_100;
  269. unsigned int mbps_1000;
  270. unsigned int half_duplex;
  271. unsigned int hash_filter;
  272. unsigned int multi_addr;
  273. unsigned int pcs;
  274. unsigned int sma_mdio;
  275. unsigned int pmt_remote_wake_up;
  276. unsigned int pmt_magic_frame;
  277. unsigned int rmon;
  278. /* IEEE 1588-2002 */
  279. unsigned int time_stamp;
  280. /* IEEE 1588-2008 */
  281. unsigned int atime_stamp;
  282. /* 802.3az - Energy-Efficient Ethernet (EEE) */
  283. unsigned int eee;
  284. unsigned int av;
  285. unsigned int tsoen;
  286. /* TX and RX csum */
  287. unsigned int tx_coe;
  288. unsigned int rx_coe;
  289. unsigned int rx_coe_type1;
  290. unsigned int rx_coe_type2;
  291. unsigned int rxfifo_over_2048;
  292. /* TX and RX number of channels */
  293. unsigned int number_rx_channel;
  294. unsigned int number_tx_channel;
  295. /* Alternate (enhanced) DESC mode */
  296. unsigned int enh_desc;
  297. };
  298. /* GMAC TX FIFO is 8K, Rx FIFO is 16K */
  299. #define BUF_SIZE_16KiB 16384
  300. #define BUF_SIZE_8KiB 8192
  301. #define BUF_SIZE_4KiB 4096
  302. #define BUF_SIZE_2KiB 2048
  303. /* Power Down and WOL */
  304. #define PMT_NOT_SUPPORTED 0
  305. #define PMT_SUPPORTED 1
  306. /* Common MAC defines */
  307. #define MAC_CTRL_REG 0x00000000 /* MAC Control */
  308. #define MAC_ENABLE_TX 0x00000008 /* Transmitter Enable */
  309. #define MAC_RNABLE_RX 0x00000004 /* Receiver Enable */
  310. /* Default LPI timers */
  311. #define STMMAC_DEFAULT_LIT_LS 0x3E8
  312. #define STMMAC_DEFAULT_TWT_LS 0x1E
  313. #define STMMAC_CHAIN_MODE 0x1
  314. #define STMMAC_RING_MODE 0x2
  315. #define JUMBO_LEN 9000
  316. /* Descriptors helpers */
  317. struct stmmac_desc_ops {
  318. /* DMA RX descriptor ring initialization */
  319. void (*init_rx_desc) (struct dma_desc *p, int disable_rx_ic, int mode,
  320. int end);
  321. /* DMA TX descriptor ring initialization */
  322. void (*init_tx_desc) (struct dma_desc *p, int mode, int end);
  323. /* Invoked by the xmit function to prepare the tx descriptor */
  324. void (*prepare_tx_desc) (struct dma_desc *p, int is_fs, int len,
  325. bool csum_flag, int mode, bool tx_own,
  326. bool ls);
  327. void (*prepare_tso_tx_desc)(struct dma_desc *p, int is_fs, int len1,
  328. int len2, bool tx_own, bool ls,
  329. unsigned int tcphdrlen,
  330. unsigned int tcppayloadlen);
  331. /* Set/get the owner of the descriptor */
  332. void (*set_tx_owner) (struct dma_desc *p);
  333. int (*get_tx_owner) (struct dma_desc *p);
  334. /* Clean the tx descriptor as soon as the tx irq is received */
  335. void (*release_tx_desc) (struct dma_desc *p, int mode);
  336. /* Clear interrupt on tx frame completion. When this bit is
  337. * set an interrupt happens as soon as the frame is transmitted */
  338. void (*set_tx_ic)(struct dma_desc *p);
  339. /* Last tx segment reports the transmit status */
  340. int (*get_tx_ls) (struct dma_desc *p);
  341. /* Return the transmit status looking at the TDES1 */
  342. int (*tx_status) (void *data, struct stmmac_extra_stats *x,
  343. struct dma_desc *p, void __iomem *ioaddr);
  344. /* Get the buffer size from the descriptor */
  345. int (*get_tx_len) (struct dma_desc *p);
  346. /* Handle extra events on specific interrupts hw dependent */
  347. void (*set_rx_owner) (struct dma_desc *p);
  348. /* Get the receive frame size */
  349. int (*get_rx_frame_len) (struct dma_desc *p, int rx_coe_type);
  350. /* Return the reception status looking at the RDES1 */
  351. int (*rx_status) (void *data, struct stmmac_extra_stats *x,
  352. struct dma_desc *p);
  353. void (*rx_extended_status) (void *data, struct stmmac_extra_stats *x,
  354. struct dma_extended_desc *p);
  355. /* Set tx timestamp enable bit */
  356. void (*enable_tx_timestamp) (struct dma_desc *p);
  357. /* get tx timestamp status */
  358. int (*get_tx_timestamp_status) (struct dma_desc *p);
  359. /* get timestamp value */
  360. u64(*get_timestamp) (void *desc, u32 ats);
  361. /* get rx timestamp status */
  362. int (*get_rx_timestamp_status) (void *desc, u32 ats);
  363. /* Display ring */
  364. void (*display_ring)(void *head, unsigned int size, bool rx);
  365. /* set MSS via context descriptor */
  366. void (*set_mss)(struct dma_desc *p, unsigned int mss);
  367. };
  368. extern const struct stmmac_desc_ops enh_desc_ops;
  369. extern const struct stmmac_desc_ops ndesc_ops;
  370. /* Specific DMA helpers */
  371. struct stmmac_dma_ops {
  372. /* DMA core initialization */
  373. int (*reset)(void __iomem *ioaddr);
  374. void (*init)(void __iomem *ioaddr, int pbl, int fb, int mb,
  375. int aal, u32 dma_tx, u32 dma_rx, int atds);
  376. /* Configure the AXI Bus Mode Register */
  377. void (*axi)(void __iomem *ioaddr, struct stmmac_axi *axi);
  378. /* Dump DMA registers */
  379. void (*dump_regs) (void __iomem *ioaddr);
  380. /* Set tx/rx threshold in the csr6 register
  381. * An invalid value enables the store-and-forward mode */
  382. void (*dma_mode)(void __iomem *ioaddr, int txmode, int rxmode,
  383. int rxfifosz);
  384. /* To track extra statistic (if supported) */
  385. void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
  386. void __iomem *ioaddr);
  387. void (*enable_dma_transmission) (void __iomem *ioaddr);
  388. void (*enable_dma_irq) (void __iomem *ioaddr);
  389. void (*disable_dma_irq) (void __iomem *ioaddr);
  390. void (*start_tx) (void __iomem *ioaddr);
  391. void (*stop_tx) (void __iomem *ioaddr);
  392. void (*start_rx) (void __iomem *ioaddr);
  393. void (*stop_rx) (void __iomem *ioaddr);
  394. int (*dma_interrupt) (void __iomem *ioaddr,
  395. struct stmmac_extra_stats *x);
  396. /* If supported then get the optional core features */
  397. void (*get_hw_feature)(void __iomem *ioaddr,
  398. struct dma_features *dma_cap);
  399. /* Program the HW RX Watchdog */
  400. void (*rx_watchdog) (void __iomem *ioaddr, u32 riwt);
  401. void (*set_tx_ring_len)(void __iomem *ioaddr, u32 len);
  402. void (*set_rx_ring_len)(void __iomem *ioaddr, u32 len);
  403. void (*set_rx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
  404. void (*set_tx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
  405. void (*enable_tso)(void __iomem *ioaddr, bool en, u32 chan);
  406. };
  407. struct mac_device_info;
  408. /* Helpers to program the MAC core */
  409. struct stmmac_ops {
  410. /* MAC core initialization */
  411. void (*core_init)(struct mac_device_info *hw, int mtu);
  412. /* Enable and verify that the IPC module is supported */
  413. int (*rx_ipc)(struct mac_device_info *hw);
  414. /* Dump MAC registers */
  415. void (*dump_regs)(struct mac_device_info *hw);
  416. /* Handle extra events on specific interrupts hw dependent */
  417. int (*host_irq_status)(struct mac_device_info *hw,
  418. struct stmmac_extra_stats *x);
  419. /* Multicast filter setting */
  420. void (*set_filter)(struct mac_device_info *hw, struct net_device *dev);
  421. /* Flow control setting */
  422. void (*flow_ctrl)(struct mac_device_info *hw, unsigned int duplex,
  423. unsigned int fc, unsigned int pause_time);
  424. /* Set power management mode (e.g. magic frame) */
  425. void (*pmt)(struct mac_device_info *hw, unsigned long mode);
  426. /* Set/Get Unicast MAC addresses */
  427. void (*set_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
  428. unsigned int reg_n);
  429. void (*get_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
  430. unsigned int reg_n);
  431. void (*set_eee_mode)(struct mac_device_info *hw);
  432. void (*reset_eee_mode)(struct mac_device_info *hw);
  433. void (*set_eee_timer)(struct mac_device_info *hw, int ls, int tw);
  434. void (*set_eee_pls)(struct mac_device_info *hw, int link);
  435. void (*debug)(void __iomem *ioaddr, struct stmmac_extra_stats *x);
  436. /* PCS calls */
  437. void (*pcs_ctrl_ane)(void __iomem *ioaddr, bool ane, bool srgmi_ral,
  438. bool loopback);
  439. void (*pcs_rane)(void __iomem *ioaddr, bool restart);
  440. void (*pcs_get_adv_lp)(void __iomem *ioaddr, struct rgmii_adv *adv);
  441. };
  442. /* PTP and HW Timer helpers */
  443. struct stmmac_hwtimestamp {
  444. void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
  445. u32 (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
  446. int gmac4);
  447. int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
  448. int (*config_addend) (void __iomem *ioaddr, u32 addend);
  449. int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
  450. int add_sub, int gmac4);
  451. u64(*get_systime) (void __iomem *ioaddr);
  452. };
  453. extern const struct stmmac_hwtimestamp stmmac_ptp;
  454. extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
  455. struct mac_link {
  456. int port;
  457. int duplex;
  458. int speed;
  459. };
  460. struct mii_regs {
  461. unsigned int addr; /* MII Address */
  462. unsigned int data; /* MII Data */
  463. };
  464. /* Helpers to manage the descriptors for chain and ring modes */
  465. struct stmmac_mode_ops {
  466. void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
  467. unsigned int extend_desc);
  468. unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
  469. int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
  470. int (*set_16kib_bfsize)(int mtu);
  471. void (*init_desc3)(struct dma_desc *p);
  472. void (*refill_desc3) (void *priv, struct dma_desc *p);
  473. void (*clean_desc3) (void *priv, struct dma_desc *p);
  474. };
  475. struct mac_device_info {
  476. const struct stmmac_ops *mac;
  477. const struct stmmac_desc_ops *desc;
  478. const struct stmmac_dma_ops *dma;
  479. const struct stmmac_mode_ops *mode;
  480. const struct stmmac_hwtimestamp *ptp;
  481. struct mii_regs mii; /* MII register Addresses */
  482. struct mac_link link;
  483. void __iomem *pcsr; /* vpointer to device CSRs */
  484. int multicast_filter_bins;
  485. int unicast_filter_entries;
  486. int mcast_bits_log2;
  487. unsigned int rx_csum;
  488. unsigned int pcs;
  489. unsigned int pmt;
  490. unsigned int ps;
  491. };
  492. struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
  493. int perfect_uc_entries,
  494. int *synopsys_id);
  495. struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id);
  496. struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
  497. int perfect_uc_entries, int *synopsys_id);
  498. void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
  499. unsigned int high, unsigned int low);
  500. void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
  501. unsigned int high, unsigned int low);
  502. void stmmac_set_mac(void __iomem *ioaddr, bool enable);
  503. void stmmac_dwmac4_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
  504. unsigned int high, unsigned int low);
  505. void stmmac_dwmac4_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
  506. unsigned int high, unsigned int low);
  507. void stmmac_dwmac4_set_mac(void __iomem *ioaddr, bool enable);
  508. void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
  509. extern const struct stmmac_mode_ops ring_mode_ops;
  510. extern const struct stmmac_mode_ops chain_mode_ops;
  511. extern const struct stmmac_desc_ops dwmac4_desc_ops;
  512. /**
  513. * stmmac_get_synopsys_id - return the SYINID.
  514. * @priv: driver private structure
  515. * Description: this simple function is to decode and return the SYINID
  516. * starting from the HW core register.
  517. */
  518. static inline u32 stmmac_get_synopsys_id(u32 hwid)
  519. {
  520. /* Check Synopsys Id (not available on old chips) */
  521. if (likely(hwid)) {
  522. u32 uid = ((hwid & 0x0000ff00) >> 8);
  523. u32 synid = (hwid & 0x000000ff);
  524. pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
  525. uid, synid);
  526. return synid;
  527. }
  528. return 0;
  529. }
  530. #endif /* __COMMON_H__ */