1 /*******************************************************************************
2   Copyright (C) 2007-2009  STMicroelectronics Ltd
3 
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 
8   This program is distributed in the hope it will be useful, but WITHOUT
9   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
11   more details.
12 
13   You should have received a copy of the GNU General Public License along with
14   this program; if not, write to the Free Software Foundation, Inc.,
15   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
16 
17   The full GNU General Public License is included in this distribution in
18   the file called "COPYING".
19 
20   Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
21 *******************************************************************************/
22 
23 #ifndef __STMMAC_H__
24 #define __STMMAC_H__
25 
26 #define STMMAC_RESOURCE_NAME   "stmmaceth"
27 #define DRV_MODULE_VERSION	"March_2013"
28 
29 #include <linux/clk.h>
30 #include <linux/stmmac.h>
31 #include <linux/phy.h>
32 #include <linux/pci.h>
33 #include "common.h"
34 #include <linux/ptp_clock_kernel.h>
35 #include <linux/reset.h>
36 
37 struct stmmac_tx_info {
38 	dma_addr_t buf;
39 	bool map_as_page;
40 };
41 
42 struct stmmac_priv {
43 	/* Frequently used values are kept adjacent for cache effect */
44 	struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
45 	struct dma_desc *dma_tx;
46 	struct sk_buff **tx_skbuff;
47 	unsigned int cur_tx;
48 	unsigned int dirty_tx;
49 	unsigned int dma_tx_size;
50 	u32 tx_count_frames;
51 	u32 tx_coal_frames;
52 	u32 tx_coal_timer;
53 	struct stmmac_tx_info *tx_skbuff_dma;
54 	dma_addr_t dma_tx_phy;
55 	int tx_coalesce;
56 	int hwts_tx_en;
57 	spinlock_t tx_lock;
58 	bool tx_path_in_lpi_mode;
59 	struct timer_list txtimer;
60 
61 	struct dma_desc *dma_rx	____cacheline_aligned_in_smp;
62 	struct dma_extended_desc *dma_erx;
63 	struct sk_buff **rx_skbuff;
64 	unsigned int cur_rx;
65 	unsigned int dirty_rx;
66 	unsigned int dma_rx_size;
67 	unsigned int dma_buf_sz;
68 	u32 rx_riwt;
69 	int hwts_rx_en;
70 	dma_addr_t *rx_skbuff_dma;
71 	dma_addr_t dma_rx_phy;
72 
73 	struct napi_struct napi ____cacheline_aligned_in_smp;
74 
75 	void __iomem *ioaddr;
76 	struct net_device *dev;
77 	struct device *device;
78 	struct mac_device_info *hw;
79 	spinlock_t lock;
80 
81 	struct phy_device *phydev ____cacheline_aligned_in_smp;
82 	int oldlink;
83 	int speed;
84 	int oldduplex;
85 	unsigned int flow_ctrl;
86 	unsigned int pause;
87 	struct mii_bus *mii;
88 	int mii_irq[PHY_MAX_ADDR];
89 
90 	struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
91 	struct plat_stmmacenet_data *plat;
92 	struct dma_features dma_cap;
93 	struct stmmac_counters mmc;
94 	int hw_cap_support;
95 	int synopsys_id;
96 	u32 msg_enable;
97 	int wolopts;
98 	int wol_irq;
99 	struct clk *stmmac_clk;
100 	struct reset_control *stmmac_rst;
101 	int clk_csr;
102 	struct timer_list eee_ctrl_timer;
103 	int lpi_irq;
104 	int eee_enabled;
105 	int eee_active;
106 	int tx_lpi_timer;
107 	int pcs;
108 	unsigned int mode;
109 	int extend_desc;
110 	struct ptp_clock *ptp_clock;
111 	struct ptp_clock_info ptp_clock_ops;
112 	unsigned int default_addend;
113 	struct clk *clk_ptp_ref;
114 	unsigned int clk_ptp_rate;
115 	u32 adv_ts;
116 	int use_riwt;
117 	int irq_wake;
118 	spinlock_t ptp_lock;
119 };
120 
121 int stmmac_mdio_unregister(struct net_device *ndev);
122 int stmmac_mdio_register(struct net_device *ndev);
123 int stmmac_mdio_reset(struct mii_bus *mii);
124 void stmmac_set_ethtool_ops(struct net_device *netdev);
125 extern const struct stmmac_desc_ops enh_desc_ops;
126 extern const struct stmmac_desc_ops ndesc_ops;
127 extern const struct stmmac_hwtimestamp stmmac_ptp;
128 int stmmac_ptp_register(struct stmmac_priv *priv);
129 void stmmac_ptp_unregister(struct stmmac_priv *priv);
130 int stmmac_resume(struct net_device *ndev);
131 int stmmac_suspend(struct net_device *ndev);
132 int stmmac_dvr_remove(struct net_device *ndev);
133 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
134 				     struct plat_stmmacenet_data *plat_dat,
135 				     void __iomem *addr);
136 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
137 bool stmmac_eee_init(struct stmmac_priv *priv);
138 
139 #ifdef CONFIG_STMMAC_PLATFORM
140 #ifdef CONFIG_DWMAC_MESON
141 extern const struct stmmac_of_data meson6_dwmac_data;
142 #endif
143 #ifdef CONFIG_DWMAC_SUNXI
144 extern const struct stmmac_of_data sun7i_gmac_data;
145 #endif
146 #ifdef CONFIG_DWMAC_STI
147 extern const struct stmmac_of_data stih4xx_dwmac_data;
148 extern const struct stmmac_of_data stid127_dwmac_data;
149 #endif
150 #ifdef CONFIG_DWMAC_SOCFPGA
151 extern const struct stmmac_of_data socfpga_gmac_data;
152 #endif
153 extern struct platform_driver stmmac_pltfr_driver;
154 static inline int stmmac_register_platform(void)
155 {
156 	int err;
157 
158 	err = platform_driver_register(&stmmac_pltfr_driver);
159 	if (err)
160 		pr_err("stmmac: failed to register the platform driver\n");
161 
162 	return err;
163 }
164 
165 static inline void stmmac_unregister_platform(void)
166 {
167 	platform_driver_unregister(&stmmac_pltfr_driver);
168 }
169 #else
170 static inline int stmmac_register_platform(void)
171 {
172 	pr_debug("stmmac: do not register the platf driver\n");
173 
174 	return 0;
175 }
176 
177 static inline void stmmac_unregister_platform(void)
178 {
179 }
180 #endif /* CONFIG_STMMAC_PLATFORM */
181 
182 #ifdef CONFIG_STMMAC_PCI
183 extern struct pci_driver stmmac_pci_driver;
184 static inline int stmmac_register_pci(void)
185 {
186 	int err;
187 
188 	err = pci_register_driver(&stmmac_pci_driver);
189 	if (err)
190 		pr_err("stmmac: failed to register the PCI driver\n");
191 
192 	return err;
193 }
194 
195 static inline void stmmac_unregister_pci(void)
196 {
197 	pci_unregister_driver(&stmmac_pci_driver);
198 }
199 #else
200 static inline int stmmac_register_pci(void)
201 {
202 	pr_debug("stmmac: do not register the PCI driver\n");
203 
204 	return 0;
205 }
206 
207 static inline void stmmac_unregister_pci(void)
208 {
209 }
210 #endif /* CONFIG_STMMAC_PCI */
211 
212 #endif /* __STMMAC_H__ */
213