1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/crc32.h>
28#include <net/dsa.h>
29#include <asm/io.h>
30#include "stmmac.h"
31#include "dwmac100.h"
32
33static void dwmac100_core_init(struct mac_device_info *hw,
34 struct net_device *dev)
35{
36 void __iomem *ioaddr = hw->pcsr;
37 u32 value = readl(ioaddr + MAC_CONTROL);
38
39 value |= MAC_CORE_INIT;
40
41
42
43
44
45 if (netdev_uses_dsa(dev))
46 value &= ~MAC_CONTROL_ASTP;
47
48 writel(value, ioaddr + MAC_CONTROL);
49
50#ifdef STMMAC_VLAN_TAG_USED
51 writel(ETH_P_8021Q, ioaddr + MAC_VLAN1);
52#endif
53}
54
55static void dwmac100_dump_mac_regs(struct mac_device_info *hw, u32 *reg_space)
56{
57 void __iomem *ioaddr = hw->pcsr;
58
59 reg_space[MAC_CONTROL / 4] = readl(ioaddr + MAC_CONTROL);
60 reg_space[MAC_ADDR_HIGH / 4] = readl(ioaddr + MAC_ADDR_HIGH);
61 reg_space[MAC_ADDR_LOW / 4] = readl(ioaddr + MAC_ADDR_LOW);
62 reg_space[MAC_HASH_HIGH / 4] = readl(ioaddr + MAC_HASH_HIGH);
63 reg_space[MAC_HASH_LOW / 4] = readl(ioaddr + MAC_HASH_LOW);
64 reg_space[MAC_FLOW_CTRL / 4] = readl(ioaddr + MAC_FLOW_CTRL);
65 reg_space[MAC_VLAN1 / 4] = readl(ioaddr + MAC_VLAN1);
66 reg_space[MAC_VLAN2 / 4] = readl(ioaddr + MAC_VLAN2);
67}
68
69static int dwmac100_rx_ipc_enable(struct mac_device_info *hw)
70{
71 return 0;
72}
73
74static int dwmac100_irq_status(struct mac_device_info *hw,
75 struct stmmac_extra_stats *x)
76{
77 return 0;
78}
79
80static void dwmac100_set_umac_addr(struct mac_device_info *hw,
81 unsigned char *addr,
82 unsigned int reg_n)
83{
84 void __iomem *ioaddr = hw->pcsr;
85 stmmac_set_mac_addr(ioaddr, addr, MAC_ADDR_HIGH, MAC_ADDR_LOW);
86}
87
88static void dwmac100_get_umac_addr(struct mac_device_info *hw,
89 unsigned char *addr,
90 unsigned int reg_n)
91{
92 void __iomem *ioaddr = hw->pcsr;
93 stmmac_get_mac_addr(ioaddr, addr, MAC_ADDR_HIGH, MAC_ADDR_LOW);
94}
95
96static void dwmac100_set_filter(struct mac_device_info *hw,
97 struct net_device *dev)
98{
99 void __iomem *ioaddr = (void __iomem *)dev->base_addr;
100 u32 value = readl(ioaddr + MAC_CONTROL);
101
102 if (dev->flags & IFF_PROMISC) {
103 value |= MAC_CONTROL_PR;
104 value &= ~(MAC_CONTROL_PM | MAC_CONTROL_IF | MAC_CONTROL_HO |
105 MAC_CONTROL_HP);
106 } else if ((netdev_mc_count(dev) > HASH_TABLE_SIZE)
107 || (dev->flags & IFF_ALLMULTI)) {
108 value |= MAC_CONTROL_PM;
109 value &= ~(MAC_CONTROL_PR | MAC_CONTROL_IF | MAC_CONTROL_HO);
110 writel(0xffffffff, ioaddr + MAC_HASH_HIGH);
111 writel(0xffffffff, ioaddr + MAC_HASH_LOW);
112 } else if (netdev_mc_empty(dev)) {
113 value &= ~(MAC_CONTROL_PM | MAC_CONTROL_PR | MAC_CONTROL_IF |
114 MAC_CONTROL_HO | MAC_CONTROL_HP);
115 } else {
116 u32 mc_filter[2];
117 struct netdev_hw_addr *ha;
118
119
120
121
122 value |= MAC_CONTROL_HP;
123 value &= ~(MAC_CONTROL_PM | MAC_CONTROL_PR |
124 MAC_CONTROL_IF | MAC_CONTROL_HO);
125
126 memset(mc_filter, 0, sizeof(mc_filter));
127 netdev_for_each_mc_addr(ha, dev) {
128
129
130
131 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26;
132
133
134
135
136 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31);
137 }
138 writel(mc_filter[0], ioaddr + MAC_HASH_LOW);
139 writel(mc_filter[1], ioaddr + MAC_HASH_HIGH);
140 }
141
142 writel(value, ioaddr + MAC_CONTROL);
143}
144
145static void dwmac100_flow_ctrl(struct mac_device_info *hw, unsigned int duplex,
146 unsigned int fc, unsigned int pause_time,
147 u32 tx_cnt)
148{
149 void __iomem *ioaddr = hw->pcsr;
150 unsigned int flow = MAC_FLOW_CTRL_ENABLE;
151
152 if (duplex)
153 flow |= (pause_time << MAC_FLOW_CTRL_PT_SHIFT);
154 writel(flow, ioaddr + MAC_FLOW_CTRL);
155}
156
157
158static void dwmac100_pmt(struct mac_device_info *hw, unsigned long mode)
159{
160 return;
161}
162
163const struct stmmac_ops dwmac100_ops = {
164 .core_init = dwmac100_core_init,
165 .set_mac = stmmac_set_mac,
166 .rx_ipc = dwmac100_rx_ipc_enable,
167 .dump_regs = dwmac100_dump_mac_regs,
168 .host_irq_status = dwmac100_irq_status,
169 .set_filter = dwmac100_set_filter,
170 .flow_ctrl = dwmac100_flow_ctrl,
171 .pmt = dwmac100_pmt,
172 .set_umac_addr = dwmac100_set_umac_addr,
173 .get_umac_addr = dwmac100_get_umac_addr,
174};
175
176int dwmac100_setup(struct stmmac_priv *priv)
177{
178 struct mac_device_info *mac = priv->hw;
179
180 dev_info(priv->device, "\tDWMAC100\n");
181
182 mac->pcsr = priv->ioaddr;
183 mac->link.duplex = MAC_CONTROL_F;
184 mac->link.speed10 = 0;
185 mac->link.speed100 = 0;
186 mac->link.speed1000 = 0;
187 mac->link.speed_mask = MAC_CONTROL_PS;
188 mac->mii.addr = MAC_MII_ADDR;
189 mac->mii.data = MAC_MII_DATA;
190 mac->mii.addr_shift = 11;
191 mac->mii.addr_mask = 0x0000F800;
192 mac->mii.reg_shift = 6;
193 mac->mii.reg_mask = 0x000007C0;
194 mac->mii.clk_csr_shift = 2;
195 mac->mii.clk_csr_mask = GENMASK(5, 2);
196
197 return 0;
198}
199