0815866986b00406927ed94a39768cf20c23b4fd
[pandora-kernel.git] / drivers / net / ethernet / apm / xgene / xgene_enet_main.h
1 /* Applied Micro X-Gene SoC Ethernet Driver
2  *
3  * Copyright (c) 2014, Applied Micro Circuits Corporation
4  * Authors: Iyappan Subramanian <isubramanian@apm.com>
5  *          Ravi Patel <rapatel@apm.com>
6  *          Keyur Chudgar <kchudgar@apm.com>
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef __XGENE_ENET_MAIN_H__
23 #define __XGENE_ENET_MAIN_H__
24
25 #include <linux/clk.h>
26 #include <linux/of_platform.h>
27 #include <linux/of_net.h>
28 #include <linux/of_mdio.h>
29 #include <linux/module.h>
30 #include <net/ip.h>
31 #include <linux/prefetch.h>
32 #include <linux/if_vlan.h>
33 #include <linux/phy.h>
34 #include "xgene_enet_hw.h"
35
36 #define XGENE_DRV_VERSION       "v1.0"
37 #define XGENE_ENET_MAX_MTU      1536
38 #define SKB_BUFFER_SIZE         (XGENE_ENET_MAX_MTU - NET_IP_ALIGN)
39 #define NUM_PKT_BUF     64
40 #define NUM_BUFPOOL     32
41
42 /* software context of a descriptor ring */
43 struct xgene_enet_desc_ring {
44         struct net_device *ndev;
45         u16 id;
46         u16 num;
47         u16 head;
48         u16 tail;
49         u16 slots;
50         u16 irq;
51         u32 size;
52         u32 state[NUM_RING_CONFIG];
53         void __iomem *cmd_base;
54         void __iomem *cmd;
55         dma_addr_t dma;
56         u16 dst_ring_num;
57         u8 nbufpool;
58         struct sk_buff *(*rx_skb);
59         struct sk_buff *(*cp_skb);
60         enum xgene_enet_ring_cfgsize cfgsize;
61         struct xgene_enet_desc_ring *cp_ring;
62         struct xgene_enet_desc_ring *buf_pool;
63         struct napi_struct napi;
64         union {
65                 void *desc_addr;
66                 struct xgene_enet_raw_desc *raw_desc;
67                 struct xgene_enet_raw_desc16 *raw_desc16;
68         };
69 };
70
71 /* ethernet private data */
72 struct xgene_enet_pdata {
73         struct net_device *ndev;
74         struct mii_bus *mdio_bus;
75         struct phy_device *phy_dev;
76         int phy_speed;
77         struct clk *clk;
78         struct platform_device *pdev;
79         struct xgene_enet_desc_ring *tx_ring;
80         struct xgene_enet_desc_ring *rx_ring;
81         char *dev_name;
82         u32 rx_buff_cnt;
83         u32 tx_qcnt_hi;
84         u32 cp_qcnt_hi;
85         u32 cp_qcnt_low;
86         u32 rx_irq;
87         void __iomem *eth_csr_addr;
88         void __iomem *eth_ring_if_addr;
89         void __iomem *eth_diag_csr_addr;
90         void __iomem *mcx_mac_addr;
91         void __iomem *mcx_stats_addr;
92         void __iomem *mcx_mac_csr_addr;
93         void __iomem *base_addr;
94         void __iomem *ring_csr_addr;
95         void __iomem *ring_cmd_addr;
96         u32 phy_addr;
97         int phy_mode;
98         u32 speed;
99         u16 rm;
100         struct rtnl_link_stats64 stats;
101 };
102
103 /* Set the specified value into a bit-field defined by its starting position
104  * and length within a single u64.
105  */
106 static inline u64 xgene_enet_set_field_value(int pos, int len, u64 val)
107 {
108         return (val & ((1ULL << len) - 1)) << pos;
109 }
110
111 #define SET_VAL(field, val) \
112                 xgene_enet_set_field_value(field ## _POS, field ## _LEN, val)
113
114 #define SET_BIT(field) \
115                 xgene_enet_set_field_value(field ## _POS, 1, 1)
116
117 /* Get the value from a bit-field defined by its starting position
118  * and length within the specified u64.
119  */
120 static inline u64 xgene_enet_get_field_value(int pos, int len, u64 src)
121 {
122         return (src >> pos) & ((1ULL << len) - 1);
123 }
124
125 #define GET_VAL(field, src) \
126                 xgene_enet_get_field_value(field ## _POS, field ## _LEN, src)
127
128 static inline struct device *ndev_to_dev(struct net_device *ndev)
129 {
130         return ndev->dev.parent;
131 }
132
133 void xgene_enet_set_ethtool_ops(struct net_device *netdev);
134
135 #endif /* __XGENE_ENET_MAIN_H__ */