xref: /openbmc/linux/drivers/net/ethernet/stmicro/stmmac/stmmac.h (revision d765955d2ae0b88781a0db3a5bacfe4241925e09)
17ac6653aSJeff Kirsher /*******************************************************************************
27ac6653aSJeff Kirsher   Copyright (C) 2007-2009  STMicroelectronics Ltd
37ac6653aSJeff Kirsher 
47ac6653aSJeff Kirsher   This program is free software; you can redistribute it and/or modify it
57ac6653aSJeff Kirsher   under the terms and conditions of the GNU General Public License,
67ac6653aSJeff Kirsher   version 2, as published by the Free Software Foundation.
77ac6653aSJeff Kirsher 
87ac6653aSJeff Kirsher   This program is distributed in the hope it will be useful, but WITHOUT
97ac6653aSJeff Kirsher   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
107ac6653aSJeff Kirsher   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
117ac6653aSJeff Kirsher   more details.
127ac6653aSJeff Kirsher 
137ac6653aSJeff Kirsher   You should have received a copy of the GNU General Public License along with
147ac6653aSJeff Kirsher   this program; if not, write to the Free Software Foundation, Inc.,
157ac6653aSJeff Kirsher   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
167ac6653aSJeff Kirsher 
177ac6653aSJeff Kirsher   The full GNU General Public License is included in this distribution in
187ac6653aSJeff Kirsher   the file called "COPYING".
197ac6653aSJeff Kirsher 
207ac6653aSJeff Kirsher   Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
217ac6653aSJeff Kirsher *******************************************************************************/
227ac6653aSJeff Kirsher 
23bfab27a1SGiuseppe CAVALLARO #define STMMAC_RESOURCE_NAME   "stmmaceth"
24bd856615SGiuseppe CAVALLARO #define DRV_MODULE_VERSION	"March_2012"
25ba1377ffSGiuseppe CAVALLARO 
26ba1377ffSGiuseppe CAVALLARO #include <linux/clk.h>
277ac6653aSJeff Kirsher #include <linux/stmmac.h>
28286a8372SGiuseppe CAVALLARO #include <linux/phy.h>
2933d5e332SGiuseppe CAVALLARO #include <linux/pci.h>
307ac6653aSJeff Kirsher #include "common.h"
317ac6653aSJeff Kirsher #ifdef CONFIG_STMMAC_TIMER
327ac6653aSJeff Kirsher #include "stmmac_timer.h"
337ac6653aSJeff Kirsher #endif
347ac6653aSJeff Kirsher 
357ac6653aSJeff Kirsher struct stmmac_priv {
367ac6653aSJeff Kirsher 	/* Frequently used values are kept adjacent for cache effect */
377ac6653aSJeff Kirsher 	struct dma_desc *dma_tx ____cacheline_aligned;
387ac6653aSJeff Kirsher 	dma_addr_t dma_tx_phy;
397ac6653aSJeff Kirsher 	struct sk_buff **tx_skbuff;
407ac6653aSJeff Kirsher 	unsigned int cur_tx;
417ac6653aSJeff Kirsher 	unsigned int dirty_tx;
427ac6653aSJeff Kirsher 	unsigned int dma_tx_size;
437ac6653aSJeff Kirsher 	int tx_coalesce;
447ac6653aSJeff Kirsher 
457ac6653aSJeff Kirsher 	struct dma_desc *dma_rx ;
467ac6653aSJeff Kirsher 	unsigned int cur_rx;
477ac6653aSJeff Kirsher 	unsigned int dirty_rx;
487ac6653aSJeff Kirsher 	struct sk_buff **rx_skbuff;
497ac6653aSJeff Kirsher 	dma_addr_t *rx_skbuff_dma;
507ac6653aSJeff Kirsher 	struct sk_buff_head rx_recycle;
517ac6653aSJeff Kirsher 
527ac6653aSJeff Kirsher 	struct net_device *dev;
537ac6653aSJeff Kirsher 	dma_addr_t dma_rx_phy;
547ac6653aSJeff Kirsher 	unsigned int dma_rx_size;
557ac6653aSJeff Kirsher 	unsigned int dma_buf_sz;
567ac6653aSJeff Kirsher 	struct device *device;
577ac6653aSJeff Kirsher 	struct mac_device_info *hw;
587ac6653aSJeff Kirsher 	void __iomem *ioaddr;
597ac6653aSJeff Kirsher 
607ac6653aSJeff Kirsher 	struct stmmac_extra_stats xstats;
617ac6653aSJeff Kirsher 	struct napi_struct napi;
627ac6653aSJeff Kirsher 	int no_csum_insertion;
637ac6653aSJeff Kirsher 
647ac6653aSJeff Kirsher 	struct phy_device *phydev;
657ac6653aSJeff Kirsher 	int oldlink;
667ac6653aSJeff Kirsher 	int speed;
677ac6653aSJeff Kirsher 	int oldduplex;
687ac6653aSJeff Kirsher 	unsigned int flow_ctrl;
697ac6653aSJeff Kirsher 	unsigned int pause;
707ac6653aSJeff Kirsher 	struct mii_bus *mii;
717ac6653aSJeff Kirsher 	int mii_irq[PHY_MAX_ADDR];
727ac6653aSJeff Kirsher 
737ac6653aSJeff Kirsher 	u32 msg_enable;
747ac6653aSJeff Kirsher 	spinlock_t lock;
75a9097a96SGiuseppe CAVALLARO 	spinlock_t tx_lock;
767ac6653aSJeff Kirsher 	int wolopts;
773172d3afSDeepak Sikri 	int wol_irq;
787ac6653aSJeff Kirsher #ifdef CONFIG_STMMAC_TIMER
797ac6653aSJeff Kirsher 	struct stmmac_timer *tm;
807ac6653aSJeff Kirsher #endif
817ac6653aSJeff Kirsher 	struct plat_stmmacenet_data *plat;
821c901a46SGiuseppe CAVALLARO 	struct stmmac_counters mmc;
83e7434821SGiuseppe CAVALLARO 	struct dma_features dma_cap;
8419e30c14SGiuseppe CAVALLARO 	int hw_cap_support;
85ba1377ffSGiuseppe CAVALLARO #ifdef CONFIG_HAVE_CLK
86ba1377ffSGiuseppe CAVALLARO 	struct clk *stmmac_clk;
87ba1377ffSGiuseppe CAVALLARO #endif
88cd7201f4SGiuseppe CAVALLARO 	int clk_csr;
89cffb13f4SGiuseppe CAVALLARO 	int synopsys_id;
90*d765955dSGiuseppe CAVALLARO 	struct timer_list eee_ctrl_timer;
91*d765955dSGiuseppe CAVALLARO 	bool tx_path_in_lpi_mode;
92*d765955dSGiuseppe CAVALLARO 	int lpi_irq;
93*d765955dSGiuseppe CAVALLARO 	int eee_enabled;
94*d765955dSGiuseppe CAVALLARO 	int eee_active;
95*d765955dSGiuseppe CAVALLARO 	int tx_lpi_timer;
967ac6653aSJeff Kirsher };
977ac6653aSJeff Kirsher 
98bfab27a1SGiuseppe CAVALLARO extern int phyaddr;
99bfab27a1SGiuseppe CAVALLARO 
1007ac6653aSJeff Kirsher extern int stmmac_mdio_unregister(struct net_device *ndev);
1017ac6653aSJeff Kirsher extern int stmmac_mdio_register(struct net_device *ndev);
1027ac6653aSJeff Kirsher extern void stmmac_set_ethtool_ops(struct net_device *netdev);
1037ac6653aSJeff Kirsher extern const struct stmmac_desc_ops enh_desc_ops;
1047ac6653aSJeff Kirsher extern const struct stmmac_desc_ops ndesc_ops;
105bfab27a1SGiuseppe CAVALLARO int stmmac_freeze(struct net_device *ndev);
106bfab27a1SGiuseppe CAVALLARO int stmmac_restore(struct net_device *ndev);
107bfab27a1SGiuseppe CAVALLARO int stmmac_resume(struct net_device *ndev);
108bfab27a1SGiuseppe CAVALLARO int stmmac_suspend(struct net_device *ndev);
109bfab27a1SGiuseppe CAVALLARO int stmmac_dvr_remove(struct net_device *ndev);
110bfab27a1SGiuseppe CAVALLARO struct stmmac_priv *stmmac_dvr_probe(struct device *device,
111cf3f047bSGiuseppe CAVALLARO 				     struct plat_stmmacenet_data *plat_dat,
112cf3f047bSGiuseppe CAVALLARO 				     void __iomem *addr);
113*d765955dSGiuseppe CAVALLARO void stmmac_disable_eee_mode(struct stmmac_priv *priv);
114*d765955dSGiuseppe CAVALLARO bool stmmac_eee_init(struct stmmac_priv *priv);
115ba1377ffSGiuseppe CAVALLARO 
116ba1377ffSGiuseppe CAVALLARO #ifdef CONFIG_HAVE_CLK
117ba1377ffSGiuseppe CAVALLARO static inline int stmmac_clk_enable(struct stmmac_priv *priv)
118ba1377ffSGiuseppe CAVALLARO {
11931ea38eeSGiuseppe CAVALLARO 	if (!IS_ERR(priv->stmmac_clk))
120883ffd6eSStefan Roese 		return clk_prepare_enable(priv->stmmac_clk);
121ba1377ffSGiuseppe CAVALLARO 
122ba1377ffSGiuseppe CAVALLARO 	return 0;
123ba1377ffSGiuseppe CAVALLARO }
124ba1377ffSGiuseppe CAVALLARO 
125ba1377ffSGiuseppe CAVALLARO static inline void stmmac_clk_disable(struct stmmac_priv *priv)
126ba1377ffSGiuseppe CAVALLARO {
12731ea38eeSGiuseppe CAVALLARO 	if (IS_ERR(priv->stmmac_clk))
12831ea38eeSGiuseppe CAVALLARO 		return;
12931ea38eeSGiuseppe CAVALLARO 
130883ffd6eSStefan Roese 	clk_disable_unprepare(priv->stmmac_clk);
131ba1377ffSGiuseppe CAVALLARO }
132ba1377ffSGiuseppe CAVALLARO static inline int stmmac_clk_get(struct stmmac_priv *priv)
133ba1377ffSGiuseppe CAVALLARO {
134ba1377ffSGiuseppe CAVALLARO 	priv->stmmac_clk = clk_get(priv->device, NULL);
135ba1377ffSGiuseppe CAVALLARO 
13631ea38eeSGiuseppe CAVALLARO 	if (IS_ERR(priv->stmmac_clk))
137ba1377ffSGiuseppe CAVALLARO 		return PTR_ERR(priv->stmmac_clk);
13831ea38eeSGiuseppe CAVALLARO 
139ba1377ffSGiuseppe CAVALLARO 	return 0;
140ba1377ffSGiuseppe CAVALLARO }
141ba1377ffSGiuseppe CAVALLARO #else
142ba1377ffSGiuseppe CAVALLARO static inline int stmmac_clk_enable(struct stmmac_priv *priv)
143ba1377ffSGiuseppe CAVALLARO {
144ba1377ffSGiuseppe CAVALLARO 	return 0;
145ba1377ffSGiuseppe CAVALLARO }
146ba1377ffSGiuseppe CAVALLARO static inline void stmmac_clk_disable(struct stmmac_priv *priv)
147ba1377ffSGiuseppe CAVALLARO {
148ba1377ffSGiuseppe CAVALLARO }
149ba1377ffSGiuseppe CAVALLARO static inline int stmmac_clk_get(struct stmmac_priv *priv)
150ba1377ffSGiuseppe CAVALLARO {
151ba1377ffSGiuseppe CAVALLARO 	return 0;
152ba1377ffSGiuseppe CAVALLARO }
153ba1377ffSGiuseppe CAVALLARO #endif /* CONFIG_HAVE_CLK */
15433d5e332SGiuseppe CAVALLARO 
15533d5e332SGiuseppe CAVALLARO 
15633d5e332SGiuseppe CAVALLARO #ifdef CONFIG_STMMAC_PLATFORM
15733d5e332SGiuseppe CAVALLARO extern struct platform_driver stmmac_pltfr_driver;
15833d5e332SGiuseppe CAVALLARO static inline int stmmac_register_platform(void)
15933d5e332SGiuseppe CAVALLARO {
16033d5e332SGiuseppe CAVALLARO 	int err;
16133d5e332SGiuseppe CAVALLARO 
16233d5e332SGiuseppe CAVALLARO 	err = platform_driver_register(&stmmac_pltfr_driver);
16333d5e332SGiuseppe CAVALLARO 	if (err)
16433d5e332SGiuseppe CAVALLARO 		pr_err("stmmac: failed to register the platform driver\n");
16533d5e332SGiuseppe CAVALLARO 
16633d5e332SGiuseppe CAVALLARO 	return err;
16733d5e332SGiuseppe CAVALLARO }
16833d5e332SGiuseppe CAVALLARO static inline void stmmac_unregister_platform(void)
16933d5e332SGiuseppe CAVALLARO {
17033d5e332SGiuseppe CAVALLARO 	platform_driver_register(&stmmac_pltfr_driver);
17133d5e332SGiuseppe CAVALLARO }
17233d5e332SGiuseppe CAVALLARO #else
17333d5e332SGiuseppe CAVALLARO static inline int stmmac_register_platform(void)
17433d5e332SGiuseppe CAVALLARO {
17533d5e332SGiuseppe CAVALLARO 	pr_debug("stmmac: do not register the platf driver\n");
17633d5e332SGiuseppe CAVALLARO 
17733d5e332SGiuseppe CAVALLARO 	return -EINVAL;
17833d5e332SGiuseppe CAVALLARO }
17933d5e332SGiuseppe CAVALLARO static inline void stmmac_unregister_platform(void)
18033d5e332SGiuseppe CAVALLARO {
18133d5e332SGiuseppe CAVALLARO }
18233d5e332SGiuseppe CAVALLARO #endif /* CONFIG_STMMAC_PLATFORM */
18333d5e332SGiuseppe CAVALLARO 
18433d5e332SGiuseppe CAVALLARO #ifdef CONFIG_STMMAC_PCI
18533d5e332SGiuseppe CAVALLARO extern struct pci_driver stmmac_pci_driver;
18633d5e332SGiuseppe CAVALLARO static inline int stmmac_register_pci(void)
18733d5e332SGiuseppe CAVALLARO {
18833d5e332SGiuseppe CAVALLARO 	int err;
18933d5e332SGiuseppe CAVALLARO 
19033d5e332SGiuseppe CAVALLARO 	err = pci_register_driver(&stmmac_pci_driver);
19133d5e332SGiuseppe CAVALLARO 	if (err)
19233d5e332SGiuseppe CAVALLARO 		pr_err("stmmac: failed to register the PCI driver\n");
19333d5e332SGiuseppe CAVALLARO 
19433d5e332SGiuseppe CAVALLARO 	return err;
19533d5e332SGiuseppe CAVALLARO }
19633d5e332SGiuseppe CAVALLARO static inline void stmmac_unregister_pci(void)
19733d5e332SGiuseppe CAVALLARO {
19833d5e332SGiuseppe CAVALLARO 	pci_unregister_driver(&stmmac_pci_driver);
19933d5e332SGiuseppe CAVALLARO }
20033d5e332SGiuseppe CAVALLARO #else
20133d5e332SGiuseppe CAVALLARO static inline int stmmac_register_pci(void)
20233d5e332SGiuseppe CAVALLARO {
20333d5e332SGiuseppe CAVALLARO 	pr_debug("stmmac: do not register the PCI driver\n");
20433d5e332SGiuseppe CAVALLARO 
20533d5e332SGiuseppe CAVALLARO 	return -EINVAL;
20633d5e332SGiuseppe CAVALLARO }
20733d5e332SGiuseppe CAVALLARO static inline void stmmac_unregister_pci(void)
20833d5e332SGiuseppe CAVALLARO {
20933d5e332SGiuseppe CAVALLARO }
21033d5e332SGiuseppe CAVALLARO #endif /* CONFIG_STMMAC_PCI */
211