This source file includes following definitions.
- hns_mac_get_drv
1
2
3
4
5
6 #ifndef _HNS_DSAF_MAC_H
7 #define _HNS_DSAF_MAC_H
8
9 #include <linux/if_vlan.h>
10 #include <linux/kernel.h>
11 #include <linux/phy.h>
12 #include <linux/regmap.h>
13 #include "hns_dsaf_main.h"
14
15 struct dsaf_device;
16
17 #define MAC_GMAC_SUPPORTED \
18 (SUPPORTED_10baseT_Half \
19 | SUPPORTED_10baseT_Full \
20 | SUPPORTED_100baseT_Half \
21 | SUPPORTED_100baseT_Full \
22 | SUPPORTED_Autoneg)
23
24 #define MAC_DEFAULT_MTU (ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN + ETH_DATA_LEN)
25 #define MAC_MAX_MTU 9600
26 #define MAC_MAX_MTU_V2 9728
27 #define MAC_MIN_MTU 68
28 #define MAC_MAX_MTU_DBG MAC_DEFAULT_MTU
29
30 #define MAC_DEFAULT_PAUSE_TIME 0xffff
31
32 #define MAC_GMAC_IDX 0
33 #define MAC_XGMAC_IDX 1
34
35 #define ETH_STATIC_REG 1
36 #define ETH_DUMP_REG 5
37
38 #define MAC_IS_BROADCAST(p) ((*(p) == 0xff) && (*((p) + 1) == 0xff) && \
39 (*((p) + 2) == 0xff) && (*((p) + 3) == 0xff) && \
40 (*((p) + 4) == 0xff) && (*((p) + 5) == 0xff))
41
42
43 #define MAC_IS_L3_MULTICAST(p) ((*((p) + 0) == 0x01) && \
44 (*((p) + 1) == 0x00) && \
45 (*((p) + 2) == 0x5e))
46
47
48 #define MAC_IS_ALL_ZEROS(p) ((*(p) == 0) && (*((p) + 1) == 0) && \
49 (*((p) + 2) == 0) && (*((p) + 3) == 0) && \
50 (*((p) + 4) == 0) && (*((p) + 5) == 0))
51
52
53 #define MAC_IS_MULTICAST(p) ((*((u8 *)((p) + 0)) & 0x01) ? (1) : (0))
54
55 struct mac_priv {
56 void *mac;
57 };
58
59
60 enum mac_speed {
61 MAC_SPEED_10 = 10,
62 MAC_SPEED_100 = 100,
63 MAC_SPEED_1000 = 1000,
64 MAC_SPEED_10000 = 10000
65 };
66
67
68 enum mac_intf {
69 MAC_IF_NONE = 0x00000000,
70 MAC_IF_MII = 0x00010000,
71 MAC_IF_RMII = 0x00020000,
72 MAC_IF_SMII = 0x00030000,
73 MAC_IF_GMII = 0x00040000,
74 MAC_IF_RGMII = 0x00050000,
75 MAC_IF_TBI = 0x00060000,
76 MAC_IF_RTBI = 0x00070000,
77 MAC_IF_SGMII = 0x00080000,
78 MAC_IF_XGMII = 0x00090000,
79 MAC_IF_QSGMII = 0x000a0000
80 };
81
82
83 enum mac_mode {
84
85 MAC_MODE_INVALID = 0,
86
87 MAC_MODE_MII_10 = (MAC_IF_MII | MAC_SPEED_10),
88
89 MAC_MODE_MII_100 = (MAC_IF_MII | MAC_SPEED_100),
90
91 MAC_MODE_RMII_10 = (MAC_IF_RMII | MAC_SPEED_10),
92
93 MAC_MODE_RMII_100 = (MAC_IF_RMII | MAC_SPEED_100),
94
95 MAC_MODE_SMII_10 = (MAC_IF_SMII | MAC_SPEED_10),
96
97 MAC_MODE_SMII_100 = (MAC_IF_SMII | MAC_SPEED_100),
98
99 MAC_MODE_GMII_1000 = (MAC_IF_GMII | MAC_SPEED_1000),
100
101 MAC_MODE_RGMII_10 = (MAC_IF_RGMII | MAC_SPEED_10),
102
103 MAC_MODE_RGMII_100 = (MAC_IF_RGMII | MAC_SPEED_100),
104
105 MAC_MODE_RGMII_1000 = (MAC_IF_RGMII | MAC_SPEED_1000),
106
107 MAC_MODE_TBI_1000 = (MAC_IF_TBI | MAC_SPEED_1000),
108
109 MAC_MODE_RTBI_1000 = (MAC_IF_RTBI | MAC_SPEED_1000),
110
111 MAC_MODE_SGMII_10 = (MAC_IF_SGMII | MAC_SPEED_10),
112
113 MAC_MODE_SGMII_100 = (MAC_IF_SGMII | MAC_SPEED_100),
114
115 MAC_MODE_SGMII_1000 = (MAC_IF_SGMII | MAC_SPEED_1000),
116
117 MAC_MODE_XGMII_10000 = (MAC_IF_XGMII | MAC_SPEED_10000),
118
119 MAC_MODE_QSGMII_1000 = (MAC_IF_QSGMII | MAC_SPEED_1000)
120 };
121
122
123 enum mac_commom_mode {
124 MAC_COMM_MODE_NONE = 0,
125 MAC_COMM_MODE_RX = 1,
126 MAC_COMM_MODE_TX = 2,
127 MAC_COMM_MODE_RX_AND_TX = 3
128 };
129
130
131 struct mac_statistics {
132 u64 stat_pkts64;
133 u64 stat_pkts65to127;
134 u64 stat_pkts128to255;
135 u64 stat_pkts256to511;
136 u64 stat_pkts512to1023;
137 u64 stat_pkts1024to1518;
138 u64 stat_pkts1519to1522;
139
140
141 u64 stat_fragments;
142
143 u64 stat_jabbers;
144
145
146 u64 stat_drop_events;
147
148
149 u64 stat_crc_align_errors;
150
151
152 u64 stat_undersize_pkts;
153 u64 stat_oversize_pkts;
154
155 u64 stat_rx_pause;
156 u64 stat_tx_pause;
157
158 u64 in_octets;
159 u64 in_pkts;
160 u64 in_mcast_pkts;
161 u64 in_bcast_pkts;
162
163
164 u64 in_discards;
165 u64 in_errors;
166
167
168
169
170 u64 out_octets;
171 u64 out_pkts;
172 u64 out_mcast_pkts;
173 u64 out_bcast_pkts;
174
175
176 u64 out_discards;
177 u64 out_errors;
178
179
180
181 };
182
183
184 struct mac_params {
185 char addr[ETH_ALEN];
186 u8 __iomem *vaddr;
187 struct device *dev;
188 u8 mac_id;
189
190 enum mac_mode mac_mode;
191 };
192
193 struct mac_info {
194 u16 speed;
195
196
197
198 u8 duplex;
199 u8 auto_neg;
200 enum hnae_loop loop_mode;
201 u8 tx_pause_en;
202 u8 tx_pause_time;
203 u8 rx_pause_en;
204 u8 pad_and_crc_en;
205 u8 promiscuous_en;
206 u8 port_en;
207 };
208
209 struct mac_entry_idx {
210 u8 addr[ETH_ALEN];
211 u16 vlan_id:12;
212 u16 valid:1;
213 u16 qos:3;
214 };
215
216 struct mac_hw_stats {
217 u64 rx_good_pkts;
218 u64 rx_good_bytes;
219 u64 rx_total_pkts;
220 u64 rx_total_bytes;
221 u64 rx_bad_bytes;
222 u64 rx_uc_pkts;
223 u64 rx_mc_pkts;
224 u64 rx_bc_pkts;
225 u64 rx_fragment_err;
226 u64 rx_undersize;
227 u64 rx_under_min;
228 u64 rx_minto64;
229 u64 rx_64bytes;
230 u64 rx_65to127;
231 u64 rx_128to255;
232 u64 rx_256to511;
233 u64 rx_512to1023;
234 u64 rx_1024to1518;
235 u64 rx_1519tomax;
236 u64 rx_1519tomax_good;
237 u64 rx_oversize;
238 u64 rx_jabber_err;
239 u64 rx_fcs_err;
240 u64 rx_vlan_pkts;
241 u64 rx_data_err;
242 u64 rx_align_err;
243 u64 rx_long_err;
244 u64 rx_pfc_tc0;
245 u64 rx_pfc_tc1;
246 u64 rx_pfc_tc2;
247 u64 rx_pfc_tc3;
248 u64 rx_pfc_tc4;
249 u64 rx_pfc_tc5;
250 u64 rx_pfc_tc6;
251 u64 rx_pfc_tc7;
252 u64 rx_unknown_ctrl;
253 u64 rx_filter_pkts;
254 u64 rx_filter_bytes;
255 u64 rx_fifo_overrun_err;
256 u64 rx_len_err;
257 u64 rx_comma_err;
258 u64 rx_symbol_err;
259 u64 tx_good_to_sw;
260 u64 tx_bad_to_sw;
261 u64 rx_1731_pkts;
262
263 u64 tx_good_bytes;
264 u64 tx_good_pkts;
265 u64 tx_total_bytes;
266 u64 tx_total_pkts;
267 u64 tx_bad_bytes;
268 u64 tx_bad_pkts;
269 u64 tx_uc_pkts;
270 u64 tx_mc_pkts;
271 u64 tx_bc_pkts;
272 u64 tx_undersize;
273 u64 tx_fragment_err;
274 u64 tx_under_min_pkts;
275 u64 tx_64bytes;
276 u64 tx_65to127;
277 u64 tx_128to255;
278 u64 tx_256to511;
279 u64 tx_512to1023;
280 u64 tx_1024to1518;
281 u64 tx_1519tomax;
282 u64 tx_1519tomax_good;
283 u64 tx_oversize;
284 u64 tx_jabber_err;
285 u64 tx_underrun_err;
286 u64 tx_vlan;
287 u64 tx_crc_err;
288 u64 tx_pfc_tc0;
289 u64 tx_pfc_tc1;
290 u64 tx_pfc_tc2;
291 u64 tx_pfc_tc3;
292 u64 tx_pfc_tc4;
293 u64 tx_pfc_tc5;
294 u64 tx_pfc_tc6;
295 u64 tx_pfc_tc7;
296 u64 tx_ctrl;
297 u64 tx_1731_pkts;
298 u64 tx_1588_pkts;
299 u64 rx_good_from_sw;
300 u64 rx_bad_from_sw;
301 };
302
303 struct hns_mac_cb {
304 struct device *dev;
305 struct dsaf_device *dsaf_dev;
306 struct mac_priv priv;
307 struct fwnode_handle *fw_port;
308 u8 __iomem *vaddr;
309 u8 __iomem *sys_ctl_vaddr;
310 u8 __iomem *serdes_vaddr;
311 struct regmap *serdes_ctrl;
312 struct regmap *cpld_ctrl;
313 char mc_mask[ETH_ALEN];
314 u32 cpld_ctrl_reg;
315 u32 port_rst_off;
316 u32 port_mode_off;
317 struct mac_entry_idx addr_entry_idx[DSAF_MAX_VM_NUM];
318 u8 sfp_prsnt;
319 u8 cpld_led_value;
320 u8 mac_id;
321
322 u8 link;
323 u8 half_duplex;
324 u16 speed;
325 u16 max_speed;
326 u16 max_frm;
327 u16 tx_pause_frm_time;
328 u32 if_support;
329 u64 txpkt_for_led;
330 u64 rxpkt_for_led;
331 enum hnae_port_type mac_type;
332 enum hnae_media_type media_type;
333 phy_interface_t phy_if;
334 enum hnae_loop loop_mode;
335
336 struct phy_device *phy_dev;
337
338 struct mac_hw_stats hw_stats;
339 };
340
341 struct mac_driver {
342
343 void (*mac_init)(void *mac_drv);
344
345 void (*mac_free)(void *mac_drv);
346
347 void (*mac_enable)(void *mac_drv, enum mac_commom_mode mode);
348
349 void (*mac_disable)(void *mac_drv, enum mac_commom_mode mode);
350
351 void (*set_mac_addr)(void *mac_drv, char *mac_addr);
352
353 int (*adjust_link)(void *mac_drv, enum mac_speed speed,
354 u32 full_duplex);
355
356 bool (*need_adjust_link)(void *mac_drv, enum mac_speed speed,
357 int duplex);
358
359 void (*set_an_mode)(void *mac_drv, u8 enable);
360
361 int (*config_loopback)(void *mac_drv, enum hnae_loop loop_mode,
362 u8 enable);
363
364 void (*config_max_frame_length)(void *mac_drv, u16 newval);
365
366 void (*config_pad_and_crc)(void *mac_drv, u8 newval);
367
368 void (*config_half_duplex)(void *mac_drv, u8 newval);
369
370 void (*set_tx_auto_pause_frames)(void *mac_drv, u16 pause_time);
371
372 void (*set_rx_ignore_pause_frames)(void *mac_drv, u32 enable);
373
374 void (*set_promiscuous)(void *mac_drv, u8 enable);
375 void (*mac_pausefrm_cfg)(void *mac_drv, u32 rx_en, u32 tx_en);
376
377 void (*autoneg_stat)(void *mac_drv, u32 *enable);
378 int (*set_pause_enable)(void *mac_drv, u32 rx_en, u32 tx_en);
379 void (*get_pause_enable)(void *mac_drv, u32 *rx_en, u32 *tx_en);
380 void (*get_link_status)(void *mac_drv, u32 *link_stat);
381
382 void (*get_regs)(void *mac_drv, void *data);
383 int (*get_regs_count)(void);
384
385 void (*get_strings)(u32 stringset, u8 *data);
386
387 int (*get_sset_count)(int stringset);
388
389
390 void (*get_ethtool_stats)(void *mac_drv, u64 *data);
391
392
393 void (*get_info)(void *mac_drv, struct mac_info *mac_info);
394
395 void (*update_stats)(void *mac_drv);
396 int (*wait_fifo_clean)(void *mac_drv);
397
398 enum mac_mode mac_mode;
399 u8 mac_id;
400 struct hns_mac_cb *mac_cb;
401 u8 __iomem *io_base;
402 unsigned int mac_en_flg;
403 unsigned int virt_dev_num;
404 struct device *dev;
405 };
406
407 struct mac_stats_string {
408 const char desc[ETH_GSTRING_LEN];
409 unsigned long offset;
410 };
411
412 #define MAC_MAKE_MODE(interface, speed) (enum mac_mode)((interface) | (speed))
413 #define MAC_INTERFACE_FROM_MODE(mode) (enum mac_intf)((mode) & 0xFFFF0000)
414 #define MAC_SPEED_FROM_MODE(mode) (enum mac_speed)((mode) & 0x0000FFFF)
415 #define MAC_STATS_FIELD_OFF(field) (offsetof(struct mac_hw_stats, field))
416
417 static inline struct mac_driver *hns_mac_get_drv(
418 const struct hns_mac_cb *mac_cb)
419 {
420 return (struct mac_driver *)(mac_cb->priv.mac);
421 }
422
423 void *hns_gmac_config(struct hns_mac_cb *mac_cb,
424 struct mac_params *mac_param);
425 void *hns_xgmac_config(struct hns_mac_cb *mac_cb,
426 struct mac_params *mac_param);
427
428 int hns_mac_init(struct dsaf_device *dsaf_dev);
429 void mac_adjust_link(struct net_device *net_dev);
430 bool hns_mac_need_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex);
431 void hns_mac_get_link_status(struct hns_mac_cb *mac_cb, u32 *link_status);
432 int hns_mac_change_vf_addr(struct hns_mac_cb *mac_cb, u32 vmid, char *addr);
433 int hns_mac_set_multi(struct hns_mac_cb *mac_cb,
434 u32 port_num, char *addr, bool enable);
435 int hns_mac_vm_config_bc_en(struct hns_mac_cb *mac_cb, u32 vm, bool enable);
436 void hns_mac_start(struct hns_mac_cb *mac_cb);
437 void hns_mac_stop(struct hns_mac_cb *mac_cb);
438 void hns_mac_uninit(struct dsaf_device *dsaf_dev);
439 void hns_mac_adjust_link(struct hns_mac_cb *mac_cb, int speed, int duplex);
440 void hns_mac_reset(struct hns_mac_cb *mac_cb);
441 void hns_mac_get_autoneg(struct hns_mac_cb *mac_cb, u32 *auto_neg);
442 void hns_mac_get_pauseparam(struct hns_mac_cb *mac_cb, u32 *rx_en, u32 *tx_en);
443 int hns_mac_set_autoneg(struct hns_mac_cb *mac_cb, u8 enable);
444 int hns_mac_set_pauseparam(struct hns_mac_cb *mac_cb, u32 rx_en, u32 tx_en);
445 int hns_mac_set_mtu(struct hns_mac_cb *mac_cb, u32 new_mtu, u32 buf_size);
446 int hns_mac_get_port_info(struct hns_mac_cb *mac_cb,
447 u8 *auto_neg, u16 *speed, u8 *duplex);
448 int hns_mac_config_mac_loopback(struct hns_mac_cb *mac_cb,
449 enum hnae_loop loop, int en);
450 void hns_mac_update_stats(struct hns_mac_cb *mac_cb);
451 void hns_mac_get_stats(struct hns_mac_cb *mac_cb, u64 *data);
452 void hns_mac_get_strings(struct hns_mac_cb *mac_cb, int stringset, u8 *data);
453 int hns_mac_get_sset_count(struct hns_mac_cb *mac_cb, int stringset);
454 void hns_mac_get_regs(struct hns_mac_cb *mac_cb, void *data);
455 int hns_mac_get_regs_count(struct hns_mac_cb *mac_cb);
456 void hns_set_led_opt(struct hns_mac_cb *mac_cb);
457 int hns_cpld_led_set_id(struct hns_mac_cb *mac_cb,
458 enum hnae_led_state status);
459 void hns_mac_set_promisc(struct hns_mac_cb *mac_cb, u8 en);
460 int hns_mac_get_inner_port_num(struct hns_mac_cb *mac_cb,
461 u8 vmid, u8 *port_num);
462 int hns_mac_add_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
463 const unsigned char *addr);
464 int hns_mac_rm_uc_addr(struct hns_mac_cb *mac_cb, u8 vf_id,
465 const unsigned char *addr);
466 int hns_mac_clr_multicast(struct hns_mac_cb *mac_cb, int vfn);
467 void hns_mac_enable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode);
468 void hns_mac_disable(struct hns_mac_cb *mac_cb, enum mac_commom_mode mode);
469 int hns_mac_wait_fifo_clean(struct hns_mac_cb *mac_cb);
470
471 #endif