]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/apm/xgene/xgene_enet_main.h
a44f4a3e938824090fdb8612c980d0564d17ee3b
[karo-tx-linux.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/acpi.h>
26 #include <linux/clk.h>
27 #include <linux/efi.h>
28 #include <linux/io.h>
29 #include <linux/of_platform.h>
30 #include <linux/of_net.h>
31 #include <linux/of_mdio.h>
32 #include <linux/module.h>
33 #include <net/ip.h>
34 #include <linux/prefetch.h>
35 #include <linux/if_vlan.h>
36 #include <linux/phy.h>
37 #include "xgene_enet_hw.h"
38
39 #define XGENE_DRV_VERSION       "v1.0"
40 #define XGENE_ENET_MAX_MTU      1536
41 #define SKB_BUFFER_SIZE         (XGENE_ENET_MAX_MTU - NET_IP_ALIGN)
42 #define NUM_PKT_BUF     64
43 #define NUM_BUFPOOL     32
44
45 #define START_CPU_BUFNUM_0      0
46 #define START_ETH_BUFNUM_0      2
47 #define START_BP_BUFNUM_0       0x22
48 #define START_RING_NUM_0        8
49 #define START_CPU_BUFNUM_1      12
50 #define START_ETH_BUFNUM_1      10
51 #define START_BP_BUFNUM_1       0x2A
52 #define START_RING_NUM_1        264
53
54 #define IRQ_ID_SIZE             16
55 #define XGENE_MAX_TXC_RINGS     1
56
57 #define PHY_POLL_LINK_ON        (10 * HZ)
58 #define PHY_POLL_LINK_OFF       (PHY_POLL_LINK_ON / 5)
59
60 /* software context of a descriptor ring */
61 struct xgene_enet_desc_ring {
62         struct net_device *ndev;
63         u16 id;
64         u16 num;
65         u16 head;
66         u16 tail;
67         u16 slots;
68         u16 irq;
69         char irq_name[IRQ_ID_SIZE];
70         u32 size;
71         u32 state[NUM_RING_CONFIG];
72         void __iomem *cmd_base;
73         void __iomem *cmd;
74         dma_addr_t dma;
75         dma_addr_t irq_mbox_dma;
76         void *irq_mbox_addr;
77         u16 dst_ring_num;
78         u8 nbufpool;
79         struct sk_buff *(*rx_skb);
80         struct sk_buff *(*cp_skb);
81         enum xgene_enet_ring_cfgsize cfgsize;
82         struct xgene_enet_desc_ring *cp_ring;
83         struct xgene_enet_desc_ring *buf_pool;
84         struct napi_struct napi;
85         union {
86                 void *desc_addr;
87                 struct xgene_enet_raw_desc *raw_desc;
88                 struct xgene_enet_raw_desc16 *raw_desc16;
89         };
90 };
91
92 struct xgene_mac_ops {
93         void (*init)(struct xgene_enet_pdata *pdata);
94         void (*reset)(struct xgene_enet_pdata *pdata);
95         void (*tx_enable)(struct xgene_enet_pdata *pdata);
96         void (*rx_enable)(struct xgene_enet_pdata *pdata);
97         void (*tx_disable)(struct xgene_enet_pdata *pdata);
98         void (*rx_disable)(struct xgene_enet_pdata *pdata);
99         void (*set_mac_addr)(struct xgene_enet_pdata *pdata);
100         void (*link_state)(struct work_struct *work);
101 };
102
103 struct xgene_port_ops {
104         int (*reset)(struct xgene_enet_pdata *pdata);
105         void (*cle_bypass)(struct xgene_enet_pdata *pdata,
106                            u32 dst_ring_num, u16 bufpool_id);
107         void (*shutdown)(struct xgene_enet_pdata *pdata);
108 };
109
110 struct xgene_ring_ops {
111         u8 num_ring_config;
112         u8 num_ring_id_shift;
113         struct xgene_enet_desc_ring * (*setup)(struct xgene_enet_desc_ring *);
114         void (*clear)(struct xgene_enet_desc_ring *);
115         void (*wr_cmd)(struct xgene_enet_desc_ring *, int);
116         u32 (*len)(struct xgene_enet_desc_ring *);
117 };
118
119 /* ethernet private data */
120 struct xgene_enet_pdata {
121         struct net_device *ndev;
122         struct mii_bus *mdio_bus;
123         struct phy_device *phy_dev;
124         int phy_speed;
125         struct clk *clk;
126         struct platform_device *pdev;
127         struct xgene_enet_desc_ring *tx_ring;
128         struct xgene_enet_desc_ring *rx_ring;
129         char *dev_name;
130         u32 rx_buff_cnt;
131         u32 tx_qcnt_hi;
132         u32 cp_qcnt_hi;
133         u32 cp_qcnt_low;
134         u32 rx_irq;
135         u32 txc_irq;
136         u8 cq_cnt;
137         void __iomem *eth_csr_addr;
138         void __iomem *eth_ring_if_addr;
139         void __iomem *eth_diag_csr_addr;
140         void __iomem *mcx_mac_addr;
141         void __iomem *mcx_mac_csr_addr;
142         void __iomem *base_addr;
143         void __iomem *ring_csr_addr;
144         void __iomem *ring_cmd_addr;
145         int phy_mode;
146         enum xgene_enet_rm rm;
147         struct rtnl_link_stats64 stats;
148         struct xgene_mac_ops *mac_ops;
149         struct xgene_port_ops *port_ops;
150         struct xgene_ring_ops *ring_ops;
151         struct delayed_work link_work;
152         u32 port_id;
153         u8 cpu_bufnum;
154         u8 eth_bufnum;
155         u8 bp_bufnum;
156         u16 ring_num;
157 };
158
159 struct xgene_indirect_ctl {
160         void __iomem *addr;
161         void __iomem *ctl;
162         void __iomem *cmd;
163         void __iomem *cmd_done;
164 };
165
166 /* Set the specified value into a bit-field defined by its starting position
167  * and length within a single u64.
168  */
169 static inline u64 xgene_enet_set_field_value(int pos, int len, u64 val)
170 {
171         return (val & ((1ULL << len) - 1)) << pos;
172 }
173
174 #define SET_VAL(field, val) \
175                 xgene_enet_set_field_value(field ## _POS, field ## _LEN, val)
176
177 #define SET_BIT(field) \
178                 xgene_enet_set_field_value(field ## _POS, 1, 1)
179
180 /* Get the value from a bit-field defined by its starting position
181  * and length within the specified u64.
182  */
183 static inline u64 xgene_enet_get_field_value(int pos, int len, u64 src)
184 {
185         return (src >> pos) & ((1ULL << len) - 1);
186 }
187
188 #define GET_VAL(field, src) \
189                 xgene_enet_get_field_value(field ## _POS, field ## _LEN, src)
190
191 static inline struct device *ndev_to_dev(struct net_device *ndev)
192 {
193         return ndev->dev.parent;
194 }
195
196 void xgene_enet_set_ethtool_ops(struct net_device *netdev);
197
198 #endif /* __XGENE_ENET_MAIN_H__ */