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