Commit | Line | Data |
---|---|---|
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" | |
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 | |
ca626454 KC |
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 | |
e6ad7673 | 53 | |
32f784b5 IS |
54 | #define PHY_POLL_LINK_ON (10 * HZ) |
55 | #define PHY_POLL_LINK_OFF (PHY_POLL_LINK_ON / 5) | |
56 | ||
e6ad7673 IS |
57 | /* software context of a descriptor ring */ |
58 | struct xgene_enet_desc_ring { | |
59 | struct net_device *ndev; | |
60 | u16 id; | |
61 | u16 num; | |
62 | u16 head; | |
63 | u16 tail; | |
64 | u16 slots; | |
65 | u16 irq; | |
66 | u32 size; | |
67 | u32 state[NUM_RING_CONFIG]; | |
68 | void __iomem *cmd_base; | |
69 | void __iomem *cmd; | |
70 | dma_addr_t dma; | |
71 | u16 dst_ring_num; | |
72 | u8 nbufpool; | |
73 | struct sk_buff *(*rx_skb); | |
74 | struct sk_buff *(*cp_skb); | |
75 | enum xgene_enet_ring_cfgsize cfgsize; | |
76 | struct xgene_enet_desc_ring *cp_ring; | |
77 | struct xgene_enet_desc_ring *buf_pool; | |
78 | struct napi_struct napi; | |
79 | union { | |
80 | void *desc_addr; | |
81 | struct xgene_enet_raw_desc *raw_desc; | |
82 | struct xgene_enet_raw_desc16 *raw_desc16; | |
83 | }; | |
84 | }; | |
85 | ||
d0eb7458 IS |
86 | struct xgene_mac_ops { |
87 | void (*init)(struct xgene_enet_pdata *pdata); | |
88 | void (*reset)(struct xgene_enet_pdata *pdata); | |
89 | void (*tx_enable)(struct xgene_enet_pdata *pdata); | |
90 | void (*rx_enable)(struct xgene_enet_pdata *pdata); | |
91 | void (*tx_disable)(struct xgene_enet_pdata *pdata); | |
92 | void (*rx_disable)(struct xgene_enet_pdata *pdata); | |
93 | void (*set_mac_addr)(struct xgene_enet_pdata *pdata); | |
dc8385f0 | 94 | void (*link_state)(struct work_struct *work); |
d0eb7458 IS |
95 | }; |
96 | ||
97 | struct xgene_port_ops { | |
c3f4465d | 98 | int (*reset)(struct xgene_enet_pdata *pdata); |
d0eb7458 IS |
99 | void (*cle_bypass)(struct xgene_enet_pdata *pdata, |
100 | u32 dst_ring_num, u16 bufpool_id); | |
101 | void (*shutdown)(struct xgene_enet_pdata *pdata); | |
102 | }; | |
103 | ||
e6ad7673 IS |
104 | /* ethernet private data */ |
105 | struct xgene_enet_pdata { | |
106 | struct net_device *ndev; | |
107 | struct mii_bus *mdio_bus; | |
108 | struct phy_device *phy_dev; | |
109 | int phy_speed; | |
110 | struct clk *clk; | |
111 | struct platform_device *pdev; | |
112 | struct xgene_enet_desc_ring *tx_ring; | |
113 | struct xgene_enet_desc_ring *rx_ring; | |
114 | char *dev_name; | |
115 | u32 rx_buff_cnt; | |
116 | u32 tx_qcnt_hi; | |
117 | u32 cp_qcnt_hi; | |
118 | u32 cp_qcnt_low; | |
119 | u32 rx_irq; | |
120 | void __iomem *eth_csr_addr; | |
121 | void __iomem *eth_ring_if_addr; | |
122 | void __iomem *eth_diag_csr_addr; | |
123 | void __iomem *mcx_mac_addr; | |
e6ad7673 IS |
124 | void __iomem *mcx_mac_csr_addr; |
125 | void __iomem *base_addr; | |
126 | void __iomem *ring_csr_addr; | |
127 | void __iomem *ring_cmd_addr; | |
e6ad7673 | 128 | int phy_mode; |
0148d38d | 129 | enum xgene_enet_rm rm; |
e6ad7673 | 130 | struct rtnl_link_stats64 stats; |
d0eb7458 IS |
131 | struct xgene_mac_ops *mac_ops; |
132 | struct xgene_port_ops *port_ops; | |
0148d38d | 133 | struct delayed_work link_work; |
ca626454 KC |
134 | u32 port_id; |
135 | u8 cpu_bufnum; | |
136 | u8 eth_bufnum; | |
137 | u8 bp_bufnum; | |
138 | u16 ring_num; | |
e6ad7673 IS |
139 | }; |
140 | ||
32f784b5 IS |
141 | struct xgene_indirect_ctl { |
142 | void __iomem *addr; | |
143 | void __iomem *ctl; | |
144 | void __iomem *cmd; | |
145 | void __iomem *cmd_done; | |
146 | }; | |
147 | ||
e6ad7673 IS |
148 | /* Set the specified value into a bit-field defined by its starting position |
149 | * and length within a single u64. | |
150 | */ | |
151 | static inline u64 xgene_enet_set_field_value(int pos, int len, u64 val) | |
152 | { | |
153 | return (val & ((1ULL << len) - 1)) << pos; | |
154 | } | |
155 | ||
156 | #define SET_VAL(field, val) \ | |
157 | xgene_enet_set_field_value(field ## _POS, field ## _LEN, val) | |
158 | ||
159 | #define SET_BIT(field) \ | |
160 | xgene_enet_set_field_value(field ## _POS, 1, 1) | |
161 | ||
162 | /* Get the value from a bit-field defined by its starting position | |
163 | * and length within the specified u64. | |
164 | */ | |
165 | static inline u64 xgene_enet_get_field_value(int pos, int len, u64 src) | |
166 | { | |
167 | return (src >> pos) & ((1ULL << len) - 1); | |
168 | } | |
169 | ||
170 | #define GET_VAL(field, src) \ | |
171 | xgene_enet_get_field_value(field ## _POS, field ## _LEN, src) | |
172 | ||
173 | static inline struct device *ndev_to_dev(struct net_device *ndev) | |
174 | { | |
175 | return ndev->dev.parent; | |
176 | } | |
177 | ||
178 | void xgene_enet_set_ethtool_ops(struct net_device *netdev); | |
179 | ||
180 | #endif /* __XGENE_ENET_MAIN_H__ */ |