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_priv {
38 	/* Frequently used values are kept adjacent for cache effect */
39 	struct dma_extended_desc *dma_etx ____cacheline_aligned_in_smp;
40 	struct dma_desc *dma_tx;
41 	struct sk_buff **tx_skbuff;
42 	unsigned int cur_tx;
43 	unsigned int dirty_tx;
44 	unsigned int dma_tx_size;
45 	u32 tx_count_frames;
46 	u32 tx_coal_frames;
47 	u32 tx_coal_timer;
48 	dma_addr_t *tx_skbuff_dma;
49 	dma_addr_t dma_tx_phy;
50 	int tx_coalesce;
51 	int hwts_tx_en;
52 	spinlock_t tx_lock;
53 	bool tx_path_in_lpi_mode;
54 	struct timer_list txtimer;
55 
56 	struct dma_desc *dma_rx	____cacheline_aligned_in_smp;
57 	struct dma_extended_desc *dma_erx;
58 	struct sk_buff **rx_skbuff;
59 	unsigned int cur_rx;
60 	unsigned int dirty_rx;
61 	unsigned int dma_rx_size;
62 	unsigned int dma_buf_sz;
63 	u32 rx_riwt;
64 	int hwts_rx_en;
65 	dma_addr_t *rx_skbuff_dma;
66 	dma_addr_t dma_rx_phy;
67 
68 	struct napi_struct napi ____cacheline_aligned_in_smp;
69 
70 	void __iomem *ioaddr;
71 	struct net_device *dev;
72 	struct device *device;
73 	struct mac_device_info *hw;
74 	spinlock_t lock;
75 
76 	struct phy_device *phydev ____cacheline_aligned_in_smp;
77 	int oldlink;
78 	int speed;
79 	int oldduplex;
80 	unsigned int flow_ctrl;
81 	unsigned int pause;
82 	struct mii_bus *mii;
83 	int mii_irq[PHY_MAX_ADDR];
84 
85 	struct stmmac_extra_stats xstats ____cacheline_aligned_in_smp;
86 	struct plat_stmmacenet_data *plat;
87 	struct dma_features dma_cap;
88 	struct stmmac_counters mmc;
89 	int hw_cap_support;
90 	int synopsys_id;
91 	u32 msg_enable;
92 	int wolopts;
93 	int wol_irq;
94 	struct clk *stmmac_clk;
95 	struct reset_control *stmmac_rst;
96 	int clk_csr;
97 	struct timer_list eee_ctrl_timer;
98 	int lpi_irq;
99 	int eee_enabled;
100 	int eee_active;
101 	int tx_lpi_timer;
102 	int pcs;
103 	unsigned int mode;
104 	int extend_desc;
105 	struct ptp_clock *ptp_clock;
106 	struct ptp_clock_info ptp_clock_ops;
107 	unsigned int default_addend;
108 	u32 adv_ts;
109 	int use_riwt;
110 	int irq_wake;
111 	spinlock_t ptp_lock;
112 };
113 
114 int stmmac_mdio_unregister(struct net_device *ndev);
115 int stmmac_mdio_register(struct net_device *ndev);
116 int stmmac_mdio_reset(struct mii_bus *mii);
117 void stmmac_set_ethtool_ops(struct net_device *netdev);
118 extern const struct stmmac_desc_ops enh_desc_ops;
119 extern const struct stmmac_desc_ops ndesc_ops;
120 extern const struct stmmac_hwtimestamp stmmac_ptp;
121 int stmmac_ptp_register(struct stmmac_priv *priv);
122 void stmmac_ptp_unregister(struct stmmac_priv *priv);
123 int stmmac_resume(struct net_device *ndev);
124 int stmmac_suspend(struct net_device *ndev);
125 int stmmac_dvr_remove(struct net_device *ndev);
126 struct stmmac_priv *stmmac_dvr_probe(struct device *device,
127 				     struct plat_stmmacenet_data *plat_dat,
128 				     void __iomem *addr);
129 void stmmac_disable_eee_mode(struct stmmac_priv *priv);
130 bool stmmac_eee_init(struct stmmac_priv *priv);
131 
132 #ifdef CONFIG_STMMAC_PLATFORM
133 #ifdef CONFIG_DWMAC_SUNXI
134 extern const struct stmmac_of_data sun7i_gmac_data;
135 #endif
136 extern struct platform_driver stmmac_pltfr_driver;
137 static inline int stmmac_register_platform(void)
138 {
139 	int err;
140 
141 	err = platform_driver_register(&stmmac_pltfr_driver);
142 	if (err)
143 		pr_err("stmmac: failed to register the platform driver\n");
144 
145 	return err;
146 }
147 
148 static inline void stmmac_unregister_platform(void)
149 {
150 	platform_driver_unregister(&stmmac_pltfr_driver);
151 }
152 #else
153 static inline int stmmac_register_platform(void)
154 {
155 	pr_debug("stmmac: do not register the platf driver\n");
156 
157 	return 0;
158 }
159 
160 static inline void stmmac_unregister_platform(void)
161 {
162 }
163 #endif /* CONFIG_STMMAC_PLATFORM */
164 
165 #ifdef CONFIG_STMMAC_PCI
166 extern struct pci_driver stmmac_pci_driver;
167 static inline int stmmac_register_pci(void)
168 {
169 	int err;
170 
171 	err = pci_register_driver(&stmmac_pci_driver);
172 	if (err)
173 		pr_err("stmmac: failed to register the PCI driver\n");
174 
175 	return err;
176 }
177 
178 static inline void stmmac_unregister_pci(void)
179 {
180 	pci_unregister_driver(&stmmac_pci_driver);
181 }
182 #else
183 static inline int stmmac_register_pci(void)
184 {
185 	pr_debug("stmmac: do not register the PCI driver\n");
186 
187 	return 0;
188 }
189 
190 static inline void stmmac_unregister_pci(void)
191 {
192 }
193 #endif /* CONFIG_STMMAC_PCI */
194 
195 #endif /* __STMMAC_H__ */
196