]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/ethernet/hisilicon/hns/hns_dsaf_main.c
Merge remote-tracking branches 'regmap/topic/mmio', 'regmap/topic/rbtree' and 'regmap...
[mirror_ubuntu-artful-kernel.git] / drivers / net / ethernet / hisilicon / hns / hns_dsaf_main.c
1 /*
2 * Copyright (c) 2014-2015 Hisilicon Limited.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 */
9
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/netdevice.h>
15 #include <linux/platform_device.h>
16 #include <linux/of.h>
17 #include <linux/of_address.h>
18 #include <linux/of_irq.h>
19 #include <linux/device.h>
20 #include <linux/vmalloc.h>
21
22 #include "hns_dsaf_main.h"
23 #include "hns_dsaf_rcb.h"
24 #include "hns_dsaf_ppe.h"
25 #include "hns_dsaf_mac.h"
26
27 const char *g_dsaf_mode_match[DSAF_MODE_MAX] = {
28 [DSAF_MODE_DISABLE_2PORT_64VM] = "2port-64vf",
29 [DSAF_MODE_DISABLE_6PORT_0VM] = "6port-16rss",
30 [DSAF_MODE_DISABLE_6PORT_16VM] = "6port-16vf",
31 };
32
33 int hns_dsaf_get_cfg(struct dsaf_device *dsaf_dev)
34 {
35 int ret, i;
36 u32 desc_num;
37 u32 buf_size;
38 const char *name, *mode_str;
39 struct device_node *np = dsaf_dev->dev->of_node;
40
41 if (of_device_is_compatible(np, "hisilicon,hns-dsaf-v2"))
42 dsaf_dev->dsaf_ver = AE_VERSION_2;
43 else
44 dsaf_dev->dsaf_ver = AE_VERSION_1;
45
46 ret = of_property_read_string(np, "dsa_name", &name);
47 if (ret) {
48 dev_err(dsaf_dev->dev, "get dsaf name fail, ret=%d!\n", ret);
49 return ret;
50 }
51 strncpy(dsaf_dev->ae_dev.name, name, AE_NAME_SIZE);
52 dsaf_dev->ae_dev.name[AE_NAME_SIZE - 1] = '\0';
53
54 ret = of_property_read_string(np, "mode", &mode_str);
55 if (ret) {
56 dev_err(dsaf_dev->dev, "get dsaf mode fail, ret=%d!\n", ret);
57 return ret;
58 }
59 for (i = 0; i < DSAF_MODE_MAX; i++) {
60 if (g_dsaf_mode_match[i] &&
61 !strcmp(mode_str, g_dsaf_mode_match[i]))
62 break;
63 }
64 if (i >= DSAF_MODE_MAX ||
65 i == DSAF_MODE_INVALID || i == DSAF_MODE_ENABLE) {
66 dev_err(dsaf_dev->dev,
67 "%s prs mode str fail!\n", dsaf_dev->ae_dev.name);
68 return -EINVAL;
69 }
70 dsaf_dev->dsaf_mode = (enum dsaf_mode)i;
71
72 if (dsaf_dev->dsaf_mode > DSAF_MODE_ENABLE)
73 dsaf_dev->dsaf_en = HRD_DSAF_NO_DSAF_MODE;
74 else
75 dsaf_dev->dsaf_en = HRD_DSAF_MODE;
76
77 if ((i == DSAF_MODE_ENABLE_16VM) ||
78 (i == DSAF_MODE_DISABLE_2PORT_8VM) ||
79 (i == DSAF_MODE_DISABLE_6PORT_2VM))
80 dsaf_dev->dsaf_tc_mode = HRD_DSAF_8TC_MODE;
81 else
82 dsaf_dev->dsaf_tc_mode = HRD_DSAF_4TC_MODE;
83
84 dsaf_dev->sc_base = of_iomap(np, 0);
85 if (!dsaf_dev->sc_base) {
86 dev_err(dsaf_dev->dev,
87 "%s of_iomap 0 fail!\n", dsaf_dev->ae_dev.name);
88 ret = -ENOMEM;
89 goto unmap_base_addr;
90 }
91
92 dsaf_dev->sds_base = of_iomap(np, 1);
93 if (!dsaf_dev->sds_base) {
94 dev_err(dsaf_dev->dev,
95 "%s of_iomap 1 fail!\n", dsaf_dev->ae_dev.name);
96 ret = -ENOMEM;
97 goto unmap_base_addr;
98 }
99
100 dsaf_dev->ppe_base = of_iomap(np, 2);
101 if (!dsaf_dev->ppe_base) {
102 dev_err(dsaf_dev->dev,
103 "%s of_iomap 2 fail!\n", dsaf_dev->ae_dev.name);
104 ret = -ENOMEM;
105 goto unmap_base_addr;
106 }
107
108 dsaf_dev->io_base = of_iomap(np, 3);
109 if (!dsaf_dev->io_base) {
110 dev_err(dsaf_dev->dev,
111 "%s of_iomap 3 fail!\n", dsaf_dev->ae_dev.name);
112 ret = -ENOMEM;
113 goto unmap_base_addr;
114 }
115
116 dsaf_dev->cpld_base = of_iomap(np, 4);
117 if (!dsaf_dev->cpld_base)
118 dev_dbg(dsaf_dev->dev, "NO CPLD ADDR");
119
120 ret = of_property_read_u32(np, "desc-num", &desc_num);
121 if (ret < 0 || desc_num < HNS_DSAF_MIN_DESC_CNT ||
122 desc_num > HNS_DSAF_MAX_DESC_CNT) {
123 dev_err(dsaf_dev->dev, "get desc-num(%d) fail, ret=%d!\n",
124 desc_num, ret);
125 goto unmap_base_addr;
126 }
127 dsaf_dev->desc_num = desc_num;
128
129 ret = of_property_read_u32(np, "buf-size", &buf_size);
130 if (ret < 0) {
131 dev_err(dsaf_dev->dev,
132 "get buf-size fail, ret=%d!\r\n", ret);
133 goto unmap_base_addr;
134 }
135 dsaf_dev->buf_size = buf_size;
136
137 dsaf_dev->buf_size_type = hns_rcb_buf_size2type(buf_size);
138 if (dsaf_dev->buf_size_type < 0) {
139 dev_err(dsaf_dev->dev,
140 "buf_size(%d) is wrong!\n", buf_size);
141 goto unmap_base_addr;
142 }
143
144 if (!dma_set_mask_and_coherent(dsaf_dev->dev, DMA_BIT_MASK(64ULL)))
145 dev_dbg(dsaf_dev->dev, "set mask to 64bit\n");
146 else
147 dev_err(dsaf_dev->dev, "set mask to 64bit fail!\n");
148
149 return 0;
150
151 unmap_base_addr:
152 if (dsaf_dev->io_base)
153 iounmap(dsaf_dev->io_base);
154 if (dsaf_dev->ppe_base)
155 iounmap(dsaf_dev->ppe_base);
156 if (dsaf_dev->sds_base)
157 iounmap(dsaf_dev->sds_base);
158 if (dsaf_dev->sc_base)
159 iounmap(dsaf_dev->sc_base);
160 if (dsaf_dev->cpld_base)
161 iounmap(dsaf_dev->cpld_base);
162 return ret;
163 }
164
165 static void hns_dsaf_free_cfg(struct dsaf_device *dsaf_dev)
166 {
167 if (dsaf_dev->io_base)
168 iounmap(dsaf_dev->io_base);
169
170 if (dsaf_dev->ppe_base)
171 iounmap(dsaf_dev->ppe_base);
172
173 if (dsaf_dev->sds_base)
174 iounmap(dsaf_dev->sds_base);
175
176 if (dsaf_dev->sc_base)
177 iounmap(dsaf_dev->sc_base);
178
179 if (dsaf_dev->cpld_base)
180 iounmap(dsaf_dev->cpld_base);
181 }
182
183 /**
184 * hns_dsaf_sbm_link_sram_init_en - config dsaf_sbm_init_en
185 * @dsaf_id: dsa fabric id
186 */
187 static void hns_dsaf_sbm_link_sram_init_en(struct dsaf_device *dsaf_dev)
188 {
189 dsaf_set_dev_bit(dsaf_dev, DSAF_CFG_0_REG, DSAF_CFG_SBM_INIT_S, 1);
190 }
191
192 /**
193 * hns_dsaf_reg_cnt_clr_ce - config hns_dsaf_reg_cnt_clr_ce
194 * @dsaf_id: dsa fabric id
195 * @hns_dsaf_reg_cnt_clr_ce: config value
196 */
197 static void
198 hns_dsaf_reg_cnt_clr_ce(struct dsaf_device *dsaf_dev, u32 reg_cnt_clr_ce)
199 {
200 dsaf_set_dev_bit(dsaf_dev, DSAF_DSA_REG_CNT_CLR_CE_REG,
201 DSAF_CNT_CLR_CE_S, reg_cnt_clr_ce);
202 }
203
204 /**
205 * hns_ppe_qid_cfg - config ppe qid
206 * @dsaf_id: dsa fabric id
207 * @pppe_qid_cfg: value array
208 */
209 static void
210 hns_dsaf_ppe_qid_cfg(struct dsaf_device *dsaf_dev, u32 qid_cfg)
211 {
212 u32 i;
213
214 for (i = 0; i < DSAF_COMM_CHN; i++) {
215 dsaf_set_dev_field(dsaf_dev,
216 DSAF_PPE_QID_CFG_0_REG + 0x0004 * i,
217 DSAF_PPE_QID_CFG_M, DSAF_PPE_QID_CFG_S,
218 qid_cfg);
219 }
220 }
221
222 static void hns_dsaf_mix_def_qid_cfg(struct dsaf_device *dsaf_dev)
223 {
224 u16 max_q_per_vf, max_vfn;
225 u32 q_id, q_num_per_port;
226 u32 i;
227
228 hns_rcb_get_queue_mode(dsaf_dev->dsaf_mode,
229 HNS_DSAF_COMM_SERVICE_NW_IDX,
230 &max_vfn, &max_q_per_vf);
231 q_num_per_port = max_vfn * max_q_per_vf;
232
233 for (i = 0, q_id = 0; i < DSAF_SERVICE_NW_NUM; i++) {
234 dsaf_set_dev_field(dsaf_dev,
235 DSAF_MIX_DEF_QID_0_REG + 0x0004 * i,
236 0xff, 0, q_id);
237 q_id += q_num_per_port;
238 }
239 }
240
241 /**
242 * hns_dsaf_sw_port_type_cfg - cfg sw type
243 * @dsaf_id: dsa fabric id
244 * @psw_port_type: array
245 */
246 static void hns_dsaf_sw_port_type_cfg(struct dsaf_device *dsaf_dev,
247 enum dsaf_sw_port_type port_type)
248 {
249 u32 i;
250
251 for (i = 0; i < DSAF_SW_PORT_NUM; i++) {
252 dsaf_set_dev_field(dsaf_dev,
253 DSAF_SW_PORT_TYPE_0_REG + 0x0004 * i,
254 DSAF_SW_PORT_TYPE_M, DSAF_SW_PORT_TYPE_S,
255 port_type);
256 }
257 }
258
259 /**
260 * hns_dsaf_stp_port_type_cfg - cfg stp type
261 * @dsaf_id: dsa fabric id
262 * @pstp_port_type: array
263 */
264 static void hns_dsaf_stp_port_type_cfg(struct dsaf_device *dsaf_dev,
265 enum dsaf_stp_port_type port_type)
266 {
267 u32 i;
268
269 for (i = 0; i < DSAF_COMM_CHN; i++) {
270 dsaf_set_dev_field(dsaf_dev,
271 DSAF_STP_PORT_TYPE_0_REG + 0x0004 * i,
272 DSAF_STP_PORT_TYPE_M, DSAF_STP_PORT_TYPE_S,
273 port_type);
274 }
275 }
276
277 /**
278 * hns_dsaf_sbm_cfg - config sbm
279 * @dsaf_id: dsa fabric id
280 */
281 static void hns_dsaf_sbm_cfg(struct dsaf_device *dsaf_dev)
282 {
283 u32 o_sbm_cfg;
284 u32 i;
285
286 for (i = 0; i < DSAF_SBM_NUM; i++) {
287 o_sbm_cfg = dsaf_read_dev(dsaf_dev,
288 DSAF_SBM_CFG_REG_0_REG + 0x80 * i);
289 dsaf_set_bit(o_sbm_cfg, DSAF_SBM_CFG_EN_S, 1);
290 dsaf_set_bit(o_sbm_cfg, DSAF_SBM_CFG_SHCUT_EN_S, 0);
291 dsaf_write_dev(dsaf_dev,
292 DSAF_SBM_CFG_REG_0_REG + 0x80 * i, o_sbm_cfg);
293 }
294 }
295
296 /**
297 * hns_dsaf_sbm_cfg_mib_en - config sbm
298 * @dsaf_id: dsa fabric id
299 */
300 static int hns_dsaf_sbm_cfg_mib_en(struct dsaf_device *dsaf_dev)
301 {
302 u32 sbm_cfg_mib_en;
303 u32 i;
304 u32 reg;
305 u32 read_cnt;
306
307 for (i = 0; i < DSAF_SBM_NUM; i++) {
308 reg = DSAF_SBM_CFG_REG_0_REG + 0x80 * i;
309 dsaf_set_dev_bit(dsaf_dev, reg, DSAF_SBM_CFG_MIB_EN_S, 1);
310 }
311
312 /* waitint for all sbm enable finished */
313 for (i = 0; i < DSAF_SBM_NUM; i++) {
314 read_cnt = 0;
315 reg = DSAF_SBM_CFG_REG_0_REG + 0x80 * i;
316 do {
317 udelay(1);
318 sbm_cfg_mib_en = dsaf_get_dev_bit(
319 dsaf_dev, reg, DSAF_SBM_CFG_MIB_EN_S);
320 read_cnt++;
321 } while (sbm_cfg_mib_en == 0 &&
322 read_cnt < DSAF_CFG_READ_CNT);
323
324 if (sbm_cfg_mib_en == 0) {
325 dev_err(dsaf_dev->dev,
326 "sbm_cfg_mib_en fail,%s,sbm_num=%d\n",
327 dsaf_dev->ae_dev.name, i);
328 return -ENODEV;
329 }
330 }
331
332 return 0;
333 }
334
335 /**
336 * hns_dsaf_sbm_bp_wl_cfg - config sbm
337 * @dsaf_id: dsa fabric id
338 */
339 static void hns_dsaf_sbm_bp_wl_cfg(struct dsaf_device *dsaf_dev)
340 {
341 u32 o_sbm_bp_cfg0;
342 u32 o_sbm_bp_cfg1;
343 u32 o_sbm_bp_cfg2;
344 u32 o_sbm_bp_cfg3;
345 u32 reg;
346 u32 i;
347
348 /* XGE */
349 for (i = 0; i < DSAF_XGE_NUM; i++) {
350 reg = DSAF_SBM_BP_CFG_0_XGE_REG_0_REG + 0x80 * i;
351 o_sbm_bp_cfg0 = dsaf_read_dev(dsaf_dev, reg);
352 dsaf_set_field(o_sbm_bp_cfg0, DSAF_SBM_CFG0_COM_MAX_BUF_NUM_M,
353 DSAF_SBM_CFG0_COM_MAX_BUF_NUM_S, 512);
354 dsaf_set_field(o_sbm_bp_cfg0, DSAF_SBM_CFG0_VC0_MAX_BUF_NUM_M,
355 DSAF_SBM_CFG0_VC0_MAX_BUF_NUM_S, 0);
356 dsaf_set_field(o_sbm_bp_cfg0, DSAF_SBM_CFG0_VC1_MAX_BUF_NUM_M,
357 DSAF_SBM_CFG0_VC1_MAX_BUF_NUM_S, 0);
358 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg0);
359
360 reg = DSAF_SBM_BP_CFG_1_REG_0_REG + 0x80 * i;
361 o_sbm_bp_cfg1 = dsaf_read_dev(dsaf_dev, reg);
362 dsaf_set_field(o_sbm_bp_cfg1, DSAF_SBM_CFG1_TC4_MAX_BUF_NUM_M,
363 DSAF_SBM_CFG1_TC4_MAX_BUF_NUM_S, 0);
364 dsaf_set_field(o_sbm_bp_cfg1, DSAF_SBM_CFG1_TC0_MAX_BUF_NUM_M,
365 DSAF_SBM_CFG1_TC0_MAX_BUF_NUM_S, 0);
366 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg1);
367
368 reg = DSAF_SBM_BP_CFG_2_XGE_REG_0_REG + 0x80 * i;
369 o_sbm_bp_cfg2 = dsaf_read_dev(dsaf_dev, reg);
370 dsaf_set_field(o_sbm_bp_cfg2, DSAF_SBM_CFG2_SET_BUF_NUM_M,
371 DSAF_SBM_CFG2_SET_BUF_NUM_S, 104);
372 dsaf_set_field(o_sbm_bp_cfg2, DSAF_SBM_CFG2_RESET_BUF_NUM_M,
373 DSAF_SBM_CFG2_RESET_BUF_NUM_S, 128);
374 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg2);
375
376 reg = DSAF_SBM_BP_CFG_3_REG_0_REG + 0x80 * i;
377 o_sbm_bp_cfg3 = dsaf_read_dev(dsaf_dev, reg);
378 dsaf_set_field(o_sbm_bp_cfg3,
379 DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_M,
380 DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 110);
381 dsaf_set_field(o_sbm_bp_cfg3,
382 DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_M,
383 DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 160);
384 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg3);
385
386 /* for no enable pfc mode */
387 reg = DSAF_SBM_BP_CFG_4_REG_0_REG + 0x80 * i;
388 o_sbm_bp_cfg3 = dsaf_read_dev(dsaf_dev, reg);
389 dsaf_set_field(o_sbm_bp_cfg3,
390 DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_M,
391 DSAF_SBM_CFG3_SET_BUF_NUM_NO_PFC_S, 128);
392 dsaf_set_field(o_sbm_bp_cfg3,
393 DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_M,
394 DSAF_SBM_CFG3_RESET_BUF_NUM_NO_PFC_S, 192);
395 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg3);
396 }
397
398 /* PPE */
399 for (i = 0; i < DSAF_COMM_CHN; i++) {
400 reg = DSAF_SBM_BP_CFG_2_PPE_REG_0_REG + 0x80 * i;
401 o_sbm_bp_cfg2 = dsaf_read_dev(dsaf_dev, reg);
402 dsaf_set_field(o_sbm_bp_cfg2, DSAF_SBM_CFG2_SET_BUF_NUM_M,
403 DSAF_SBM_CFG2_SET_BUF_NUM_S, 10);
404 dsaf_set_field(o_sbm_bp_cfg2, DSAF_SBM_CFG2_RESET_BUF_NUM_M,
405 DSAF_SBM_CFG2_RESET_BUF_NUM_S, 12);
406 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg2);
407 }
408
409 /* RoCEE */
410 for (i = 0; i < DSAF_COMM_CHN; i++) {
411 reg = DSAF_SBM_BP_CFG_2_ROCEE_REG_0_REG + 0x80 * i;
412 o_sbm_bp_cfg2 = dsaf_read_dev(dsaf_dev, reg);
413 dsaf_set_field(o_sbm_bp_cfg2, DSAF_SBM_CFG2_SET_BUF_NUM_M,
414 DSAF_SBM_CFG2_SET_BUF_NUM_S, 2);
415 dsaf_set_field(o_sbm_bp_cfg2, DSAF_SBM_CFG2_RESET_BUF_NUM_M,
416 DSAF_SBM_CFG2_RESET_BUF_NUM_S, 4);
417 dsaf_write_dev(dsaf_dev, reg, o_sbm_bp_cfg2);
418 }
419 }
420
421 /**
422 * hns_dsaf_voq_bp_all_thrd_cfg - voq
423 * @dsaf_id: dsa fabric id
424 */
425 static void hns_dsaf_voq_bp_all_thrd_cfg(struct dsaf_device *dsaf_dev)
426 {
427 u32 voq_bp_all_thrd;
428 u32 i;
429
430 for (i = 0; i < DSAF_VOQ_NUM; i++) {
431 voq_bp_all_thrd = dsaf_read_dev(
432 dsaf_dev, DSAF_VOQ_BP_ALL_THRD_0_REG + 0x40 * i);
433 if (i < DSAF_XGE_NUM) {
434 dsaf_set_field(voq_bp_all_thrd,
435 DSAF_VOQ_BP_ALL_DOWNTHRD_M,
436 DSAF_VOQ_BP_ALL_DOWNTHRD_S, 930);
437 dsaf_set_field(voq_bp_all_thrd,
438 DSAF_VOQ_BP_ALL_UPTHRD_M,
439 DSAF_VOQ_BP_ALL_UPTHRD_S, 950);
440 } else {
441 dsaf_set_field(voq_bp_all_thrd,
442 DSAF_VOQ_BP_ALL_DOWNTHRD_M,
443 DSAF_VOQ_BP_ALL_DOWNTHRD_S, 220);
444 dsaf_set_field(voq_bp_all_thrd,
445 DSAF_VOQ_BP_ALL_UPTHRD_M,
446 DSAF_VOQ_BP_ALL_UPTHRD_S, 230);
447 }
448 dsaf_write_dev(
449 dsaf_dev, DSAF_VOQ_BP_ALL_THRD_0_REG + 0x40 * i,
450 voq_bp_all_thrd);
451 }
452 }
453
454 /**
455 * hns_dsaf_tbl_tcam_data_cfg - tbl
456 * @dsaf_id: dsa fabric id
457 * @ptbl_tcam_data: addr
458 */
459 static void hns_dsaf_tbl_tcam_data_cfg(
460 struct dsaf_device *dsaf_dev,
461 struct dsaf_tbl_tcam_data *ptbl_tcam_data)
462 {
463 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_LOW_0_REG,
464 ptbl_tcam_data->tbl_tcam_data_low);
465 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_HIGH_0_REG,
466 ptbl_tcam_data->tbl_tcam_data_high);
467 }
468
469 /**
470 * dsaf_tbl_tcam_mcast_cfg - tbl
471 * @dsaf_id: dsa fabric id
472 * @ptbl_tcam_mcast: addr
473 */
474 static void hns_dsaf_tbl_tcam_mcast_cfg(
475 struct dsaf_device *dsaf_dev,
476 struct dsaf_tbl_tcam_mcast_cfg *mcast)
477 {
478 u32 mcast_cfg4;
479
480 mcast_cfg4 = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG);
481 dsaf_set_bit(mcast_cfg4, DSAF_TBL_MCAST_CFG4_ITEM_VLD_S,
482 mcast->tbl_mcast_item_vld);
483 dsaf_set_bit(mcast_cfg4, DSAF_TBL_MCAST_CFG4_OLD_EN_S,
484 mcast->tbl_mcast_old_en);
485 dsaf_set_field(mcast_cfg4, DSAF_TBL_MCAST_CFG4_VM128_112_M,
486 DSAF_TBL_MCAST_CFG4_VM128_112_S,
487 mcast->tbl_mcast_port_msk[4]);
488 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG, mcast_cfg4);
489
490 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_3_0_REG,
491 mcast->tbl_mcast_port_msk[3]);
492
493 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_2_0_REG,
494 mcast->tbl_mcast_port_msk[2]);
495
496 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_1_0_REG,
497 mcast->tbl_mcast_port_msk[1]);
498
499 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_0_0_REG,
500 mcast->tbl_mcast_port_msk[0]);
501 }
502
503 /**
504 * hns_dsaf_tbl_tcam_ucast_cfg - tbl
505 * @dsaf_id: dsa fabric id
506 * @ptbl_tcam_ucast: addr
507 */
508 static void hns_dsaf_tbl_tcam_ucast_cfg(
509 struct dsaf_device *dsaf_dev,
510 struct dsaf_tbl_tcam_ucast_cfg *tbl_tcam_ucast)
511 {
512 u32 ucast_cfg1;
513
514 ucast_cfg1 = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_UCAST_CFG_0_REG);
515 dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_MAC_DISCARD_S,
516 tbl_tcam_ucast->tbl_ucast_mac_discard);
517 dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_ITEM_VLD_S,
518 tbl_tcam_ucast->tbl_ucast_item_vld);
519 dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_OLD_EN_S,
520 tbl_tcam_ucast->tbl_ucast_old_en);
521 dsaf_set_bit(ucast_cfg1, DSAF_TBL_UCAST_CFG1_DVC_S,
522 tbl_tcam_ucast->tbl_ucast_dvc);
523 dsaf_set_field(ucast_cfg1, DSAF_TBL_UCAST_CFG1_OUT_PORT_M,
524 DSAF_TBL_UCAST_CFG1_OUT_PORT_S,
525 tbl_tcam_ucast->tbl_ucast_out_port);
526 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_UCAST_CFG_0_REG, ucast_cfg1);
527 }
528
529 /**
530 * hns_dsaf_tbl_line_cfg - tbl
531 * @dsaf_id: dsa fabric id
532 * @ptbl_lin: addr
533 */
534 static void hns_dsaf_tbl_line_cfg(struct dsaf_device *dsaf_dev,
535 struct dsaf_tbl_line_cfg *tbl_lin)
536 {
537 u32 tbl_line;
538
539 tbl_line = dsaf_read_dev(dsaf_dev, DSAF_TBL_LIN_CFG_0_REG);
540 dsaf_set_bit(tbl_line, DSAF_TBL_LINE_CFG_MAC_DISCARD_S,
541 tbl_lin->tbl_line_mac_discard);
542 dsaf_set_bit(tbl_line, DSAF_TBL_LINE_CFG_DVC_S,
543 tbl_lin->tbl_line_dvc);
544 dsaf_set_field(tbl_line, DSAF_TBL_LINE_CFG_OUT_PORT_M,
545 DSAF_TBL_LINE_CFG_OUT_PORT_S,
546 tbl_lin->tbl_line_out_port);
547 dsaf_write_dev(dsaf_dev, DSAF_TBL_LIN_CFG_0_REG, tbl_line);
548 }
549
550 /**
551 * hns_dsaf_tbl_tcam_mcast_pul - tbl
552 * @dsaf_id: dsa fabric id
553 */
554 static void hns_dsaf_tbl_tcam_mcast_pul(struct dsaf_device *dsaf_dev)
555 {
556 u32 o_tbl_pul;
557
558 o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
559 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 1);
560 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
561 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 0);
562 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
563 }
564
565 /**
566 * hns_dsaf_tbl_line_pul - tbl
567 * @dsaf_id: dsa fabric id
568 */
569 static void hns_dsaf_tbl_line_pul(struct dsaf_device *dsaf_dev)
570 {
571 u32 tbl_pul;
572
573 tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
574 dsaf_set_bit(tbl_pul, DSAF_TBL_PUL_LINE_VLD_S, 1);
575 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, tbl_pul);
576 dsaf_set_bit(tbl_pul, DSAF_TBL_PUL_LINE_VLD_S, 0);
577 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, tbl_pul);
578 }
579
580 /**
581 * hns_dsaf_tbl_tcam_data_mcast_pul - tbl
582 * @dsaf_id: dsa fabric id
583 */
584 static void hns_dsaf_tbl_tcam_data_mcast_pul(
585 struct dsaf_device *dsaf_dev)
586 {
587 u32 o_tbl_pul;
588
589 o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
590 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 1);
591 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 1);
592 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
593 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 0);
594 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_MCAST_VLD_S, 0);
595 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
596 }
597
598 /**
599 * hns_dsaf_tbl_tcam_data_ucast_pul - tbl
600 * @dsaf_id: dsa fabric id
601 */
602 static void hns_dsaf_tbl_tcam_data_ucast_pul(
603 struct dsaf_device *dsaf_dev)
604 {
605 u32 o_tbl_pul;
606
607 o_tbl_pul = dsaf_read_dev(dsaf_dev, DSAF_TBL_PUL_0_REG);
608 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 1);
609 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_UCAST_VLD_S, 1);
610 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
611 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_TCAM_DATA_VLD_S, 0);
612 dsaf_set_bit(o_tbl_pul, DSAF_TBL_PUL_UCAST_VLD_S, 0);
613 dsaf_write_dev(dsaf_dev, DSAF_TBL_PUL_0_REG, o_tbl_pul);
614 }
615
616 void hns_dsaf_set_promisc_mode(struct dsaf_device *dsaf_dev, u32 en)
617 {
618 dsaf_set_dev_bit(dsaf_dev, DSAF_CFG_0_REG, DSAF_CFG_MIX_MODE_S, !!en);
619 }
620
621 /**
622 * hns_dsaf_tbl_stat_en - tbl
623 * @dsaf_id: dsa fabric id
624 * @ptbl_stat_en: addr
625 */
626 static void hns_dsaf_tbl_stat_en(struct dsaf_device *dsaf_dev)
627 {
628 u32 o_tbl_ctrl;
629
630 o_tbl_ctrl = dsaf_read_dev(dsaf_dev, DSAF_TBL_DFX_CTRL_0_REG);
631 dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_LINE_LKUP_NUM_EN_S, 1);
632 dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_UC_LKUP_NUM_EN_S, 1);
633 dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_MC_LKUP_NUM_EN_S, 1);
634 dsaf_set_bit(o_tbl_ctrl, DSAF_TBL_DFX_BC_LKUP_NUM_EN_S, 1);
635 dsaf_write_dev(dsaf_dev, DSAF_TBL_DFX_CTRL_0_REG, o_tbl_ctrl);
636 }
637
638 /**
639 * hns_dsaf_rocee_bp_en - rocee back press enable
640 * @dsaf_id: dsa fabric id
641 */
642 static void hns_dsaf_rocee_bp_en(struct dsaf_device *dsaf_dev)
643 {
644 dsaf_set_dev_bit(dsaf_dev, DSAF_XGE_CTRL_SIG_CFG_0_REG,
645 DSAF_FC_XGE_TX_PAUSE_S, 1);
646 }
647
648 /* set msk for dsaf exception irq*/
649 static void hns_dsaf_int_xge_msk_set(struct dsaf_device *dsaf_dev,
650 u32 chnn_num, u32 mask_set)
651 {
652 dsaf_write_dev(dsaf_dev,
653 DSAF_XGE_INT_MSK_0_REG + 0x4 * chnn_num, mask_set);
654 }
655
656 static void hns_dsaf_int_ppe_msk_set(struct dsaf_device *dsaf_dev,
657 u32 chnn_num, u32 msk_set)
658 {
659 dsaf_write_dev(dsaf_dev,
660 DSAF_PPE_INT_MSK_0_REG + 0x4 * chnn_num, msk_set);
661 }
662
663 static void hns_dsaf_int_rocee_msk_set(struct dsaf_device *dsaf_dev,
664 u32 chnn, u32 msk_set)
665 {
666 dsaf_write_dev(dsaf_dev,
667 DSAF_ROCEE_INT_MSK_0_REG + 0x4 * chnn, msk_set);
668 }
669
670 static void
671 hns_dsaf_int_tbl_msk_set(struct dsaf_device *dsaf_dev, u32 msk_set)
672 {
673 dsaf_write_dev(dsaf_dev, DSAF_TBL_INT_MSK_0_REG, msk_set);
674 }
675
676 /* clr dsaf exception irq*/
677 static void hns_dsaf_int_xge_src_clr(struct dsaf_device *dsaf_dev,
678 u32 chnn_num, u32 int_src)
679 {
680 dsaf_write_dev(dsaf_dev,
681 DSAF_XGE_INT_SRC_0_REG + 0x4 * chnn_num, int_src);
682 }
683
684 static void hns_dsaf_int_ppe_src_clr(struct dsaf_device *dsaf_dev,
685 u32 chnn, u32 int_src)
686 {
687 dsaf_write_dev(dsaf_dev,
688 DSAF_PPE_INT_SRC_0_REG + 0x4 * chnn, int_src);
689 }
690
691 static void hns_dsaf_int_rocee_src_clr(struct dsaf_device *dsaf_dev,
692 u32 chnn, u32 int_src)
693 {
694 dsaf_write_dev(dsaf_dev,
695 DSAF_ROCEE_INT_SRC_0_REG + 0x4 * chnn, int_src);
696 }
697
698 static void hns_dsaf_int_tbl_src_clr(struct dsaf_device *dsaf_dev,
699 u32 int_src)
700 {
701 dsaf_write_dev(dsaf_dev, DSAF_TBL_INT_SRC_0_REG, int_src);
702 }
703
704 /**
705 * hns_dsaf_single_line_tbl_cfg - INT
706 * @dsaf_id: dsa fabric id
707 * @address:
708 * @ptbl_line:
709 */
710 static void hns_dsaf_single_line_tbl_cfg(
711 struct dsaf_device *dsaf_dev,
712 u32 address, struct dsaf_tbl_line_cfg *ptbl_line)
713 {
714 /*Write Addr*/
715 hns_dsaf_tbl_line_addr_cfg(dsaf_dev, address);
716
717 /*Write Line*/
718 hns_dsaf_tbl_line_cfg(dsaf_dev, ptbl_line);
719
720 /*Write Plus*/
721 hns_dsaf_tbl_line_pul(dsaf_dev);
722 }
723
724 /**
725 * hns_dsaf_tcam_uc_cfg - INT
726 * @dsaf_id: dsa fabric id
727 * @address,
728 * @ptbl_tcam_data,
729 */
730 static void hns_dsaf_tcam_uc_cfg(
731 struct dsaf_device *dsaf_dev, u32 address,
732 struct dsaf_tbl_tcam_data *ptbl_tcam_data,
733 struct dsaf_tbl_tcam_ucast_cfg *ptbl_tcam_ucast)
734 {
735 /*Write Addr*/
736 hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
737 /*Write Tcam Data*/
738 hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, ptbl_tcam_data);
739 /*Write Tcam Ucast*/
740 hns_dsaf_tbl_tcam_ucast_cfg(dsaf_dev, ptbl_tcam_ucast);
741 /*Write Plus*/
742 hns_dsaf_tbl_tcam_data_ucast_pul(dsaf_dev);
743 }
744
745 /**
746 * hns_dsaf_tcam_mc_cfg - INT
747 * @dsaf_id: dsa fabric id
748 * @address,
749 * @ptbl_tcam_data,
750 * @ptbl_tcam_mcast,
751 */
752 static void hns_dsaf_tcam_mc_cfg(
753 struct dsaf_device *dsaf_dev, u32 address,
754 struct dsaf_tbl_tcam_data *ptbl_tcam_data,
755 struct dsaf_tbl_tcam_mcast_cfg *ptbl_tcam_mcast)
756 {
757 /*Write Addr*/
758 hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
759 /*Write Tcam Data*/
760 hns_dsaf_tbl_tcam_data_cfg(dsaf_dev, ptbl_tcam_data);
761 /*Write Tcam Mcast*/
762 hns_dsaf_tbl_tcam_mcast_cfg(dsaf_dev, ptbl_tcam_mcast);
763 /*Write Plus*/
764 hns_dsaf_tbl_tcam_data_mcast_pul(dsaf_dev);
765 }
766
767 /**
768 * hns_dsaf_tcam_mc_invld - INT
769 * @dsaf_id: dsa fabric id
770 * @address
771 */
772 static void hns_dsaf_tcam_mc_invld(struct dsaf_device *dsaf_dev, u32 address)
773 {
774 /*Write Addr*/
775 hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
776
777 /*write tcam mcast*/
778 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_0_0_REG, 0);
779 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_1_0_REG, 0);
780 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_2_0_REG, 0);
781 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_3_0_REG, 0);
782 dsaf_write_dev(dsaf_dev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG, 0);
783
784 /*Write Plus*/
785 hns_dsaf_tbl_tcam_mcast_pul(dsaf_dev);
786 }
787
788 /**
789 * hns_dsaf_tcam_uc_get - INT
790 * @dsaf_id: dsa fabric id
791 * @address
792 * @ptbl_tcam_data
793 * @ptbl_tcam_ucast
794 */
795 static void hns_dsaf_tcam_uc_get(
796 struct dsaf_device *dsaf_dev, u32 address,
797 struct dsaf_tbl_tcam_data *ptbl_tcam_data,
798 struct dsaf_tbl_tcam_ucast_cfg *ptbl_tcam_ucast)
799 {
800 u32 tcam_read_data0;
801 u32 tcam_read_data4;
802
803 /*Write Addr*/
804 hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
805
806 /*read tcam item puls*/
807 hns_dsaf_tbl_tcam_load_pul(dsaf_dev);
808
809 /*read tcam data*/
810 ptbl_tcam_data->tbl_tcam_data_high
811 = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
812 ptbl_tcam_data->tbl_tcam_data_low
813 = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
814
815 /*read tcam mcast*/
816 tcam_read_data0 = dsaf_read_dev(dsaf_dev,
817 DSAF_TBL_TCAM_RAM_RDATA0_0_REG);
818 tcam_read_data4 = dsaf_read_dev(dsaf_dev,
819 DSAF_TBL_TCAM_RAM_RDATA4_0_REG);
820
821 ptbl_tcam_ucast->tbl_ucast_item_vld
822 = dsaf_get_bit(tcam_read_data4,
823 DSAF_TBL_MCAST_CFG4_ITEM_VLD_S);
824 ptbl_tcam_ucast->tbl_ucast_old_en
825 = dsaf_get_bit(tcam_read_data4, DSAF_TBL_MCAST_CFG4_OLD_EN_S);
826 ptbl_tcam_ucast->tbl_ucast_mac_discard
827 = dsaf_get_bit(tcam_read_data0,
828 DSAF_TBL_UCAST_CFG1_MAC_DISCARD_S);
829 ptbl_tcam_ucast->tbl_ucast_out_port
830 = dsaf_get_field(tcam_read_data0,
831 DSAF_TBL_UCAST_CFG1_OUT_PORT_M,
832 DSAF_TBL_UCAST_CFG1_OUT_PORT_S);
833 ptbl_tcam_ucast->tbl_ucast_dvc
834 = dsaf_get_bit(tcam_read_data0, DSAF_TBL_UCAST_CFG1_DVC_S);
835 }
836
837 /**
838 * hns_dsaf_tcam_mc_get - INT
839 * @dsaf_id: dsa fabric id
840 * @address
841 * @ptbl_tcam_data
842 * @ptbl_tcam_ucast
843 */
844 static void hns_dsaf_tcam_mc_get(
845 struct dsaf_device *dsaf_dev, u32 address,
846 struct dsaf_tbl_tcam_data *ptbl_tcam_data,
847 struct dsaf_tbl_tcam_mcast_cfg *ptbl_tcam_mcast)
848 {
849 u32 data_tmp;
850
851 /*Write Addr*/
852 hns_dsaf_tbl_tcam_addr_cfg(dsaf_dev, address);
853
854 /*read tcam item puls*/
855 hns_dsaf_tbl_tcam_load_pul(dsaf_dev);
856
857 /*read tcam data*/
858 ptbl_tcam_data->tbl_tcam_data_high =
859 dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
860 ptbl_tcam_data->tbl_tcam_data_low =
861 dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
862
863 /*read tcam mcast*/
864 ptbl_tcam_mcast->tbl_mcast_port_msk[0] =
865 dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA0_0_REG);
866 ptbl_tcam_mcast->tbl_mcast_port_msk[1] =
867 dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA1_0_REG);
868 ptbl_tcam_mcast->tbl_mcast_port_msk[2] =
869 dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA2_0_REG);
870 ptbl_tcam_mcast->tbl_mcast_port_msk[3] =
871 dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA3_0_REG);
872
873 data_tmp = dsaf_read_dev(dsaf_dev, DSAF_TBL_TCAM_RAM_RDATA4_0_REG);
874 ptbl_tcam_mcast->tbl_mcast_item_vld =
875 dsaf_get_bit(data_tmp, DSAF_TBL_MCAST_CFG4_ITEM_VLD_S);
876 ptbl_tcam_mcast->tbl_mcast_old_en =
877 dsaf_get_bit(data_tmp, DSAF_TBL_MCAST_CFG4_OLD_EN_S);
878 ptbl_tcam_mcast->tbl_mcast_port_msk[4] =
879 dsaf_get_field(data_tmp, DSAF_TBL_MCAST_CFG4_VM128_112_M,
880 DSAF_TBL_MCAST_CFG4_VM128_112_S);
881 }
882
883 /**
884 * hns_dsaf_tbl_line_init - INT
885 * @dsaf_id: dsa fabric id
886 */
887 static void hns_dsaf_tbl_line_init(struct dsaf_device *dsaf_dev)
888 {
889 u32 i;
890 /* defaultly set all lineal mac table entry resulting discard */
891 struct dsaf_tbl_line_cfg tbl_line[] = {{1, 0, 0} };
892
893 for (i = 0; i < DSAF_LINE_SUM; i++)
894 hns_dsaf_single_line_tbl_cfg(dsaf_dev, i, tbl_line);
895 }
896
897 /**
898 * hns_dsaf_tbl_tcam_init - INT
899 * @dsaf_id: dsa fabric id
900 */
901 static void hns_dsaf_tbl_tcam_init(struct dsaf_device *dsaf_dev)
902 {
903 u32 i;
904 struct dsaf_tbl_tcam_data tcam_data[] = {{0, 0} };
905 struct dsaf_tbl_tcam_ucast_cfg tcam_ucast[] = {{0, 0, 0, 0, 0} };
906
907 /*tcam tbl*/
908 for (i = 0; i < DSAF_TCAM_SUM; i++)
909 hns_dsaf_tcam_uc_cfg(dsaf_dev, i, tcam_data, tcam_ucast);
910 }
911
912 /**
913 * hns_dsaf_pfc_en_cfg - dsaf pfc pause cfg
914 * @mac_cb: mac contrl block
915 */
916 static void hns_dsaf_pfc_en_cfg(struct dsaf_device *dsaf_dev,
917 int mac_id, int en)
918 {
919 if (!en)
920 dsaf_write_dev(dsaf_dev, DSAF_PFC_EN_0_REG + mac_id * 4, 0);
921 else
922 dsaf_write_dev(dsaf_dev, DSAF_PFC_EN_0_REG + mac_id * 4, 0xff);
923 }
924
925 /**
926 * hns_dsaf_tbl_tcam_init - INT
927 * @dsaf_id: dsa fabric id
928 * @dsaf_mode
929 */
930 static void hns_dsaf_comm_init(struct dsaf_device *dsaf_dev)
931 {
932 u32 i;
933 u32 o_dsaf_cfg;
934
935 o_dsaf_cfg = dsaf_read_dev(dsaf_dev, DSAF_CFG_0_REG);
936 dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_EN_S, dsaf_dev->dsaf_en);
937 dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_TC_MODE_S, dsaf_dev->dsaf_tc_mode);
938 dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_CRC_EN_S, 0);
939 dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_MIX_MODE_S, 0);
940 dsaf_set_bit(o_dsaf_cfg, DSAF_CFG_LOCA_ADDR_EN_S, 0);
941 dsaf_write_dev(dsaf_dev, DSAF_CFG_0_REG, o_dsaf_cfg);
942
943 hns_dsaf_reg_cnt_clr_ce(dsaf_dev, 1);
944 hns_dsaf_stp_port_type_cfg(dsaf_dev, DSAF_STP_PORT_TYPE_FORWARD);
945
946 /* set 22 queue per tx ppe engine, only used in switch mode */
947 hns_dsaf_ppe_qid_cfg(dsaf_dev, DSAF_DEFAUTL_QUEUE_NUM_PER_PPE);
948
949 /* set promisc def queue id */
950 hns_dsaf_mix_def_qid_cfg(dsaf_dev);
951
952 /* in non switch mode, set all port to access mode */
953 hns_dsaf_sw_port_type_cfg(dsaf_dev, DSAF_SW_PORT_TYPE_NON_VLAN);
954
955 /*set dsaf pfc to 0 for parseing rx pause*/
956 for (i = 0; i < DSAF_COMM_CHN; i++)
957 hns_dsaf_pfc_en_cfg(dsaf_dev, i, 0);
958
959 /*msk and clr exception irqs */
960 for (i = 0; i < DSAF_COMM_CHN; i++) {
961 hns_dsaf_int_xge_src_clr(dsaf_dev, i, 0xfffffffful);
962 hns_dsaf_int_ppe_src_clr(dsaf_dev, i, 0xfffffffful);
963 hns_dsaf_int_rocee_src_clr(dsaf_dev, i, 0xfffffffful);
964
965 hns_dsaf_int_xge_msk_set(dsaf_dev, i, 0xfffffffful);
966 hns_dsaf_int_ppe_msk_set(dsaf_dev, i, 0xfffffffful);
967 hns_dsaf_int_rocee_msk_set(dsaf_dev, i, 0xfffffffful);
968 }
969 hns_dsaf_int_tbl_src_clr(dsaf_dev, 0xfffffffful);
970 hns_dsaf_int_tbl_msk_set(dsaf_dev, 0xfffffffful);
971 }
972
973 /**
974 * hns_dsaf_inode_init - INT
975 * @dsaf_id: dsa fabric id
976 */
977 static void hns_dsaf_inode_init(struct dsaf_device *dsaf_dev)
978 {
979 u32 reg;
980 u32 tc_cfg;
981 u32 i;
982
983 if (dsaf_dev->dsaf_tc_mode == HRD_DSAF_4TC_MODE)
984 tc_cfg = HNS_DSAF_I4TC_CFG;
985 else
986 tc_cfg = HNS_DSAF_I8TC_CFG;
987
988 for (i = 0; i < DSAF_INODE_NUM; i++) {
989 reg = DSAF_INODE_IN_PORT_NUM_0_REG + 0x80 * i;
990 dsaf_set_dev_field(dsaf_dev, reg, DSAF_INODE_IN_PORT_NUM_M,
991 DSAF_INODE_IN_PORT_NUM_S, i % DSAF_XGE_NUM);
992
993 reg = DSAF_INODE_PRI_TC_CFG_0_REG + 0x80 * i;
994 dsaf_write_dev(dsaf_dev, reg, tc_cfg);
995 }
996 }
997
998 /**
999 * hns_dsaf_sbm_init - INT
1000 * @dsaf_id: dsa fabric id
1001 */
1002 static int hns_dsaf_sbm_init(struct dsaf_device *dsaf_dev)
1003 {
1004 u32 flag;
1005 u32 cnt = 0;
1006 int ret;
1007
1008 hns_dsaf_sbm_bp_wl_cfg(dsaf_dev);
1009
1010 /* enable sbm chanel, disable sbm chanel shcut function*/
1011 hns_dsaf_sbm_cfg(dsaf_dev);
1012
1013 /* enable sbm mib */
1014 ret = hns_dsaf_sbm_cfg_mib_en(dsaf_dev);
1015 if (ret) {
1016 dev_err(dsaf_dev->dev,
1017 "hns_dsaf_sbm_cfg_mib_en fail,%s, ret=%d\n",
1018 dsaf_dev->ae_dev.name, ret);
1019 return ret;
1020 }
1021
1022 /* enable sbm initial link sram */
1023 hns_dsaf_sbm_link_sram_init_en(dsaf_dev);
1024
1025 do {
1026 usleep_range(200, 210);/*udelay(200);*/
1027 flag = dsaf_read_dev(dsaf_dev, DSAF_SRAM_INIT_OVER_0_REG);
1028 cnt++;
1029 } while (flag != DSAF_SRAM_INIT_FINISH_FLAG && cnt < DSAF_CFG_READ_CNT);
1030
1031 if (flag != DSAF_SRAM_INIT_FINISH_FLAG) {
1032 dev_err(dsaf_dev->dev,
1033 "hns_dsaf_sbm_init fail %s, flag=%d, cnt=%d\n",
1034 dsaf_dev->ae_dev.name, flag, cnt);
1035 return -ENODEV;
1036 }
1037
1038 hns_dsaf_rocee_bp_en(dsaf_dev);
1039
1040 return 0;
1041 }
1042
1043 /**
1044 * hns_dsaf_tbl_init - INT
1045 * @dsaf_id: dsa fabric id
1046 */
1047 static void hns_dsaf_tbl_init(struct dsaf_device *dsaf_dev)
1048 {
1049 hns_dsaf_tbl_stat_en(dsaf_dev);
1050
1051 hns_dsaf_tbl_tcam_init(dsaf_dev);
1052 hns_dsaf_tbl_line_init(dsaf_dev);
1053 }
1054
1055 /**
1056 * hns_dsaf_voq_init - INT
1057 * @dsaf_id: dsa fabric id
1058 */
1059 static void hns_dsaf_voq_init(struct dsaf_device *dsaf_dev)
1060 {
1061 hns_dsaf_voq_bp_all_thrd_cfg(dsaf_dev);
1062 }
1063
1064 /**
1065 * hns_dsaf_init_hw - init dsa fabric hardware
1066 * @dsaf_dev: dsa fabric device struct pointer
1067 */
1068 static int hns_dsaf_init_hw(struct dsaf_device *dsaf_dev)
1069 {
1070 int ret;
1071
1072 dev_dbg(dsaf_dev->dev,
1073 "hns_dsaf_init_hw begin %s !\n", dsaf_dev->ae_dev.name);
1074
1075 hns_dsaf_rst(dsaf_dev, 0);
1076 mdelay(10);
1077 hns_dsaf_rst(dsaf_dev, 1);
1078
1079 hns_dsaf_comm_init(dsaf_dev);
1080
1081 /*init XBAR_INODE*/
1082 hns_dsaf_inode_init(dsaf_dev);
1083
1084 /*init SBM*/
1085 ret = hns_dsaf_sbm_init(dsaf_dev);
1086 if (ret)
1087 return ret;
1088
1089 /*init TBL*/
1090 hns_dsaf_tbl_init(dsaf_dev);
1091
1092 /*init VOQ*/
1093 hns_dsaf_voq_init(dsaf_dev);
1094
1095 return 0;
1096 }
1097
1098 /**
1099 * hns_dsaf_remove_hw - uninit dsa fabric hardware
1100 * @dsaf_dev: dsa fabric device struct pointer
1101 */
1102 static void hns_dsaf_remove_hw(struct dsaf_device *dsaf_dev)
1103 {
1104 /*reset*/
1105 hns_dsaf_rst(dsaf_dev, 0);
1106 }
1107
1108 /**
1109 * hns_dsaf_init - init dsa fabric
1110 * @dsaf_dev: dsa fabric device struct pointer
1111 * retuen 0 - success , negative --fail
1112 */
1113 static int hns_dsaf_init(struct dsaf_device *dsaf_dev)
1114 {
1115 struct dsaf_drv_priv *priv =
1116 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1117 u32 i;
1118 int ret;
1119
1120 ret = hns_dsaf_init_hw(dsaf_dev);
1121 if (ret)
1122 return ret;
1123
1124 /* malloc mem for tcam mac key(vlan+mac) */
1125 priv->soft_mac_tbl = vzalloc(sizeof(*priv->soft_mac_tbl)
1126 * DSAF_TCAM_SUM);
1127 if (!priv->soft_mac_tbl) {
1128 ret = -ENOMEM;
1129 goto remove_hw;
1130 }
1131
1132 /*all entry invall */
1133 for (i = 0; i < DSAF_TCAM_SUM; i++)
1134 (priv->soft_mac_tbl + i)->index = DSAF_INVALID_ENTRY_IDX;
1135
1136 return 0;
1137
1138 remove_hw:
1139 hns_dsaf_remove_hw(dsaf_dev);
1140 return ret;
1141 }
1142
1143 /**
1144 * hns_dsaf_free - free dsa fabric
1145 * @dsaf_dev: dsa fabric device struct pointer
1146 */
1147 static void hns_dsaf_free(struct dsaf_device *dsaf_dev)
1148 {
1149 struct dsaf_drv_priv *priv =
1150 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1151
1152 hns_dsaf_remove_hw(dsaf_dev);
1153
1154 /* free all mac mem */
1155 vfree(priv->soft_mac_tbl);
1156 priv->soft_mac_tbl = NULL;
1157 }
1158
1159 /**
1160 * hns_dsaf_find_soft_mac_entry - find dsa fabric soft entry
1161 * @dsaf_dev: dsa fabric device struct pointer
1162 * @mac_key: mac entry struct pointer
1163 */
1164 static u16 hns_dsaf_find_soft_mac_entry(
1165 struct dsaf_device *dsaf_dev,
1166 struct dsaf_drv_tbl_tcam_key *mac_key)
1167 {
1168 struct dsaf_drv_priv *priv =
1169 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1170 struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
1171 u32 i;
1172
1173 soft_mac_entry = priv->soft_mac_tbl;
1174 for (i = 0; i < DSAF_TCAM_SUM; i++) {
1175 /* invall tab entry */
1176 if ((soft_mac_entry->index != DSAF_INVALID_ENTRY_IDX) &&
1177 (soft_mac_entry->tcam_key.high.val == mac_key->high.val) &&
1178 (soft_mac_entry->tcam_key.low.val == mac_key->low.val))
1179 /* return find result --soft index */
1180 return soft_mac_entry->index;
1181
1182 soft_mac_entry++;
1183 }
1184 return DSAF_INVALID_ENTRY_IDX;
1185 }
1186
1187 /**
1188 * hns_dsaf_find_empty_mac_entry - search dsa fabric soft empty-entry
1189 * @dsaf_dev: dsa fabric device struct pointer
1190 */
1191 static u16 hns_dsaf_find_empty_mac_entry(struct dsaf_device *dsaf_dev)
1192 {
1193 struct dsaf_drv_priv *priv =
1194 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1195 struct dsaf_drv_soft_mac_tbl *soft_mac_entry;
1196 u32 i;
1197
1198 soft_mac_entry = priv->soft_mac_tbl;
1199 for (i = 0; i < DSAF_TCAM_SUM; i++) {
1200 /* inv all entry */
1201 if (soft_mac_entry->index == DSAF_INVALID_ENTRY_IDX)
1202 /* return find result --soft index */
1203 return i;
1204
1205 soft_mac_entry++;
1206 }
1207 return DSAF_INVALID_ENTRY_IDX;
1208 }
1209
1210 /**
1211 * hns_dsaf_set_mac_key - set mac key
1212 * @dsaf_dev: dsa fabric device struct pointer
1213 * @mac_key: tcam key pointer
1214 * @vlan_id: vlan id
1215 * @in_port_num: input port num
1216 * @addr: mac addr
1217 */
1218 static void hns_dsaf_set_mac_key(
1219 struct dsaf_device *dsaf_dev,
1220 struct dsaf_drv_tbl_tcam_key *mac_key, u16 vlan_id, u8 in_port_num,
1221 u8 *addr)
1222 {
1223 u8 port;
1224
1225 if (dsaf_dev->dsaf_mode <= DSAF_MODE_ENABLE)
1226 /*DSAF mode : in port id fixed 0*/
1227 port = 0;
1228 else
1229 /*non-dsaf mode*/
1230 port = in_port_num;
1231
1232 mac_key->high.bits.mac_0 = addr[0];
1233 mac_key->high.bits.mac_1 = addr[1];
1234 mac_key->high.bits.mac_2 = addr[2];
1235 mac_key->high.bits.mac_3 = addr[3];
1236 mac_key->low.bits.mac_4 = addr[4];
1237 mac_key->low.bits.mac_5 = addr[5];
1238 mac_key->low.bits.vlan = vlan_id;
1239 mac_key->low.bits.port = port;
1240 }
1241
1242 /**
1243 * hns_dsaf_set_mac_uc_entry - set mac uc-entry
1244 * @dsaf_dev: dsa fabric device struct pointer
1245 * @mac_entry: uc-mac entry
1246 */
1247 int hns_dsaf_set_mac_uc_entry(
1248 struct dsaf_device *dsaf_dev,
1249 struct dsaf_drv_mac_single_dest_entry *mac_entry)
1250 {
1251 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1252 struct dsaf_drv_tbl_tcam_key mac_key;
1253 struct dsaf_tbl_tcam_ucast_cfg mac_data;
1254 struct dsaf_drv_priv *priv =
1255 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1256 struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
1257
1258 /* mac addr check */
1259 if (MAC_IS_ALL_ZEROS(mac_entry->addr) ||
1260 MAC_IS_BROADCAST(mac_entry->addr) ||
1261 MAC_IS_MULTICAST(mac_entry->addr)) {
1262 dev_err(dsaf_dev->dev, "set_uc %s Mac %pM err!\n",
1263 dsaf_dev->ae_dev.name, mac_entry->addr);
1264 return -EINVAL;
1265 }
1266
1267 /* config key */
1268 hns_dsaf_set_mac_key(dsaf_dev, &mac_key, mac_entry->in_vlan_id,
1269 mac_entry->in_port_num, mac_entry->addr);
1270
1271 /* entry ie exist? */
1272 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1273 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1274 /*if has not inv entry,find a empty entry */
1275 entry_index = hns_dsaf_find_empty_mac_entry(dsaf_dev);
1276 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1277 /* has not empty,return error */
1278 dev_err(dsaf_dev->dev,
1279 "set_uc_entry failed, %s Mac key(%#x:%#x)\n",
1280 dsaf_dev->ae_dev.name,
1281 mac_key.high.val, mac_key.low.val);
1282 return -EINVAL;
1283 }
1284 }
1285
1286 dev_dbg(dsaf_dev->dev,
1287 "set_uc_entry, %s Mac key(%#x:%#x) entry_index%d\n",
1288 dsaf_dev->ae_dev.name, mac_key.high.val,
1289 mac_key.low.val, entry_index);
1290
1291 /* config hardware entry */
1292 mac_data.tbl_ucast_item_vld = 1;
1293 mac_data.tbl_ucast_mac_discard = 0;
1294 mac_data.tbl_ucast_old_en = 0;
1295 /* default config dvc to 0 */
1296 mac_data.tbl_ucast_dvc = 0;
1297 mac_data.tbl_ucast_out_port = mac_entry->port_num;
1298 hns_dsaf_tcam_uc_cfg(
1299 dsaf_dev, entry_index,
1300 (struct dsaf_tbl_tcam_data *)(&mac_key), &mac_data);
1301
1302 /* config software entry */
1303 soft_mac_entry += entry_index;
1304 soft_mac_entry->index = entry_index;
1305 soft_mac_entry->tcam_key.high.val = mac_key.high.val;
1306 soft_mac_entry->tcam_key.low.val = mac_key.low.val;
1307
1308 return 0;
1309 }
1310
1311 /**
1312 * hns_dsaf_set_mac_mc_entry - set mac mc-entry
1313 * @dsaf_dev: dsa fabric device struct pointer
1314 * @mac_entry: mc-mac entry
1315 */
1316 int hns_dsaf_set_mac_mc_entry(
1317 struct dsaf_device *dsaf_dev,
1318 struct dsaf_drv_mac_multi_dest_entry *mac_entry)
1319 {
1320 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1321 struct dsaf_drv_tbl_tcam_key mac_key;
1322 struct dsaf_tbl_tcam_mcast_cfg mac_data;
1323 struct dsaf_drv_priv *priv =
1324 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1325 struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
1326 struct dsaf_drv_tbl_tcam_key tmp_mac_key;
1327
1328 /* mac addr check */
1329 if (MAC_IS_ALL_ZEROS(mac_entry->addr)) {
1330 dev_err(dsaf_dev->dev, "set uc %s Mac %pM err!\n",
1331 dsaf_dev->ae_dev.name, mac_entry->addr);
1332 return -EINVAL;
1333 }
1334
1335 /*config key */
1336 hns_dsaf_set_mac_key(dsaf_dev, &mac_key,
1337 mac_entry->in_vlan_id,
1338 mac_entry->in_port_num, mac_entry->addr);
1339
1340 /* entry ie exist? */
1341 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1342 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1343 /*if hasnot, find enpty entry*/
1344 entry_index = hns_dsaf_find_empty_mac_entry(dsaf_dev);
1345 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1346 /*if hasnot empty, error*/
1347 dev_err(dsaf_dev->dev,
1348 "set_uc_entry failed, %s Mac key(%#x:%#x)\n",
1349 dsaf_dev->ae_dev.name,
1350 mac_key.high.val, mac_key.low.val);
1351 return -EINVAL;
1352 }
1353
1354 /* config hardware entry */
1355 memset(mac_data.tbl_mcast_port_msk,
1356 0, sizeof(mac_data.tbl_mcast_port_msk));
1357 } else {
1358 /* config hardware entry */
1359 hns_dsaf_tcam_mc_get(
1360 dsaf_dev, entry_index,
1361 (struct dsaf_tbl_tcam_data *)(&tmp_mac_key), &mac_data);
1362 }
1363 mac_data.tbl_mcast_old_en = 0;
1364 mac_data.tbl_mcast_item_vld = 1;
1365 dsaf_set_field(mac_data.tbl_mcast_port_msk[0],
1366 0x3F, 0, mac_entry->port_mask[0]);
1367
1368 dev_dbg(dsaf_dev->dev,
1369 "set_uc_entry, %s key(%#x:%#x) entry_index%d\n",
1370 dsaf_dev->ae_dev.name, mac_key.high.val,
1371 mac_key.low.val, entry_index);
1372
1373 hns_dsaf_tcam_mc_cfg(
1374 dsaf_dev, entry_index,
1375 (struct dsaf_tbl_tcam_data *)(&mac_key), &mac_data);
1376
1377 /* config software entry */
1378 soft_mac_entry += entry_index;
1379 soft_mac_entry->index = entry_index;
1380 soft_mac_entry->tcam_key.high.val = mac_key.high.val;
1381 soft_mac_entry->tcam_key.low.val = mac_key.low.val;
1382
1383 return 0;
1384 }
1385
1386 /**
1387 * hns_dsaf_add_mac_mc_port - add mac mc-port
1388 * @dsaf_dev: dsa fabric device struct pointer
1389 * @mac_entry: mc-mac entry
1390 */
1391 int hns_dsaf_add_mac_mc_port(struct dsaf_device *dsaf_dev,
1392 struct dsaf_drv_mac_single_dest_entry *mac_entry)
1393 {
1394 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1395 struct dsaf_drv_tbl_tcam_key mac_key;
1396 struct dsaf_tbl_tcam_mcast_cfg mac_data;
1397 struct dsaf_drv_priv *priv =
1398 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1399 struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
1400 struct dsaf_drv_tbl_tcam_key tmp_mac_key;
1401 int mskid;
1402
1403 /*chechk mac addr */
1404 if (MAC_IS_ALL_ZEROS(mac_entry->addr)) {
1405 dev_err(dsaf_dev->dev, "set_entry failed,addr %pM!\n",
1406 mac_entry->addr);
1407 return -EINVAL;
1408 }
1409
1410 /*config key */
1411 hns_dsaf_set_mac_key(
1412 dsaf_dev, &mac_key, mac_entry->in_vlan_id,
1413 mac_entry->in_port_num, mac_entry->addr);
1414
1415 memset(&mac_data, 0, sizeof(struct dsaf_tbl_tcam_mcast_cfg));
1416
1417 /*check exist? */
1418 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1419 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1420 /*if hasnot , find a empty*/
1421 entry_index = hns_dsaf_find_empty_mac_entry(dsaf_dev);
1422 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1423 /*if hasnot empty, error*/
1424 dev_err(dsaf_dev->dev,
1425 "set_uc_entry failed, %s Mac key(%#x:%#x)\n",
1426 dsaf_dev->ae_dev.name, mac_key.high.val,
1427 mac_key.low.val);
1428 return -EINVAL;
1429 }
1430 } else {
1431 /*if exist, add in */
1432 hns_dsaf_tcam_mc_get(
1433 dsaf_dev, entry_index,
1434 (struct dsaf_tbl_tcam_data *)(&tmp_mac_key), &mac_data);
1435 }
1436 /* config hardware entry */
1437 if (mac_entry->port_num < DSAF_SERVICE_NW_NUM) {
1438 mskid = mac_entry->port_num;
1439 } else if (mac_entry->port_num >= DSAF_BASE_INNER_PORT_NUM) {
1440 mskid = mac_entry->port_num -
1441 DSAF_BASE_INNER_PORT_NUM + DSAF_SERVICE_NW_NUM;
1442 } else {
1443 dev_err(dsaf_dev->dev,
1444 "%s,pnum(%d)error,key(%#x:%#x)\n",
1445 dsaf_dev->ae_dev.name, mac_entry->port_num,
1446 mac_key.high.val, mac_key.low.val);
1447 return -EINVAL;
1448 }
1449 dsaf_set_bit(mac_data.tbl_mcast_port_msk[mskid / 32], mskid % 32, 1);
1450 mac_data.tbl_mcast_old_en = 0;
1451 mac_data.tbl_mcast_item_vld = 1;
1452
1453 dev_dbg(dsaf_dev->dev,
1454 "set_uc_entry, %s Mac key(%#x:%#x) entry_index%d\n",
1455 dsaf_dev->ae_dev.name, mac_key.high.val,
1456 mac_key.low.val, entry_index);
1457
1458 hns_dsaf_tcam_mc_cfg(
1459 dsaf_dev, entry_index,
1460 (struct dsaf_tbl_tcam_data *)(&mac_key), &mac_data);
1461
1462 /*config software entry */
1463 soft_mac_entry += entry_index;
1464 soft_mac_entry->index = entry_index;
1465 soft_mac_entry->tcam_key.high.val = mac_key.high.val;
1466 soft_mac_entry->tcam_key.low.val = mac_key.low.val;
1467
1468 return 0;
1469 }
1470
1471 /**
1472 * hns_dsaf_del_mac_entry - del mac mc-port
1473 * @dsaf_dev: dsa fabric device struct pointer
1474 * @vlan_id: vlian id
1475 * @in_port_num: input port num
1476 * @addr : mac addr
1477 */
1478 int hns_dsaf_del_mac_entry(struct dsaf_device *dsaf_dev, u16 vlan_id,
1479 u8 in_port_num, u8 *addr)
1480 {
1481 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1482 struct dsaf_drv_tbl_tcam_key mac_key;
1483 struct dsaf_drv_priv *priv =
1484 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1485 struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
1486
1487 /*check mac addr */
1488 if (MAC_IS_ALL_ZEROS(addr) || MAC_IS_BROADCAST(addr)) {
1489 dev_err(dsaf_dev->dev, "del_entry failed,addr %pM!\n",
1490 addr);
1491 return -EINVAL;
1492 }
1493
1494 /*config key */
1495 hns_dsaf_set_mac_key(dsaf_dev, &mac_key, vlan_id, in_port_num, addr);
1496
1497 /*exist ?*/
1498 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1499 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1500 /*not exist, error */
1501 dev_err(dsaf_dev->dev,
1502 "del_mac_entry failed, %s Mac key(%#x:%#x)\n",
1503 dsaf_dev->ae_dev.name,
1504 mac_key.high.val, mac_key.low.val);
1505 return -EINVAL;
1506 }
1507 dev_dbg(dsaf_dev->dev,
1508 "del_mac_entry, %s Mac key(%#x:%#x) entry_index%d\n",
1509 dsaf_dev->ae_dev.name, mac_key.high.val,
1510 mac_key.low.val, entry_index);
1511
1512 /*do del opt*/
1513 hns_dsaf_tcam_mc_invld(dsaf_dev, entry_index);
1514
1515 /*del soft emtry */
1516 soft_mac_entry += entry_index;
1517 soft_mac_entry->index = DSAF_INVALID_ENTRY_IDX;
1518
1519 return 0;
1520 }
1521
1522 /**
1523 * hns_dsaf_del_mac_mc_port - del mac mc- port
1524 * @dsaf_dev: dsa fabric device struct pointer
1525 * @mac_entry: mac entry
1526 */
1527 int hns_dsaf_del_mac_mc_port(struct dsaf_device *dsaf_dev,
1528 struct dsaf_drv_mac_single_dest_entry *mac_entry)
1529 {
1530 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1531 struct dsaf_drv_tbl_tcam_key mac_key;
1532 struct dsaf_drv_priv *priv =
1533 (struct dsaf_drv_priv *)hns_dsaf_dev_priv(dsaf_dev);
1534 struct dsaf_drv_soft_mac_tbl *soft_mac_entry = priv->soft_mac_tbl;
1535 u16 vlan_id;
1536 u8 in_port_num;
1537 struct dsaf_tbl_tcam_mcast_cfg mac_data;
1538 struct dsaf_drv_tbl_tcam_key tmp_mac_key;
1539 int mskid;
1540 const u8 empty_msk[sizeof(mac_data.tbl_mcast_port_msk)] = {0};
1541
1542 if (!(void *)mac_entry) {
1543 dev_err(dsaf_dev->dev,
1544 "hns_dsaf_del_mac_mc_port mac_entry is NULL\n");
1545 return -EINVAL;
1546 }
1547
1548 /*get key info*/
1549 vlan_id = mac_entry->in_vlan_id;
1550 in_port_num = mac_entry->in_port_num;
1551
1552 /*check mac addr */
1553 if (MAC_IS_ALL_ZEROS(mac_entry->addr)) {
1554 dev_err(dsaf_dev->dev, "del_port failed, addr %pM!\n",
1555 mac_entry->addr);
1556 return -EINVAL;
1557 }
1558
1559 /*config key */
1560 hns_dsaf_set_mac_key(dsaf_dev, &mac_key, vlan_id, in_port_num,
1561 mac_entry->addr);
1562
1563 /*check is exist? */
1564 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1565 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1566 /*find none */
1567 dev_err(dsaf_dev->dev,
1568 "find_soft_mac_entry failed, %s Mac key(%#x:%#x)\n",
1569 dsaf_dev->ae_dev.name,
1570 mac_key.high.val, mac_key.low.val);
1571 return -EINVAL;
1572 }
1573
1574 dev_dbg(dsaf_dev->dev,
1575 "del_mac_mc_port, %s key(%#x:%#x) index%d\n",
1576 dsaf_dev->ae_dev.name, mac_key.high.val,
1577 mac_key.low.val, entry_index);
1578
1579 /*read entry*/
1580 hns_dsaf_tcam_mc_get(
1581 dsaf_dev, entry_index,
1582 (struct dsaf_tbl_tcam_data *)(&tmp_mac_key), &mac_data);
1583
1584 /*del the port*/
1585 if (mac_entry->port_num < DSAF_SERVICE_NW_NUM) {
1586 mskid = mac_entry->port_num;
1587 } else if (mac_entry->port_num >= DSAF_BASE_INNER_PORT_NUM) {
1588 mskid = mac_entry->port_num -
1589 DSAF_BASE_INNER_PORT_NUM + DSAF_SERVICE_NW_NUM;
1590 } else {
1591 dev_err(dsaf_dev->dev,
1592 "%s,pnum(%d)error,key(%#x:%#x)\n",
1593 dsaf_dev->ae_dev.name, mac_entry->port_num,
1594 mac_key.high.val, mac_key.low.val);
1595 return -EINVAL;
1596 }
1597 dsaf_set_bit(mac_data.tbl_mcast_port_msk[mskid / 32], mskid % 32, 0);
1598
1599 /*check non port, do del entry */
1600 if (!memcmp(mac_data.tbl_mcast_port_msk, empty_msk,
1601 sizeof(mac_data.tbl_mcast_port_msk))) {
1602 hns_dsaf_tcam_mc_invld(dsaf_dev, entry_index);
1603
1604 /* del soft entry */
1605 soft_mac_entry += entry_index;
1606 soft_mac_entry->index = DSAF_INVALID_ENTRY_IDX;
1607 } else { /* not zer, just del port, updata*/
1608 hns_dsaf_tcam_mc_cfg(
1609 dsaf_dev, entry_index,
1610 (struct dsaf_tbl_tcam_data *)(&mac_key), &mac_data);
1611 }
1612
1613 return 0;
1614 }
1615
1616 /**
1617 * hns_dsaf_get_mac_uc_entry - get mac uc entry
1618 * @dsaf_dev: dsa fabric device struct pointer
1619 * @mac_entry: mac entry
1620 */
1621 int hns_dsaf_get_mac_uc_entry(struct dsaf_device *dsaf_dev,
1622 struct dsaf_drv_mac_single_dest_entry *mac_entry)
1623 {
1624 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1625 struct dsaf_drv_tbl_tcam_key mac_key;
1626
1627 struct dsaf_tbl_tcam_ucast_cfg mac_data;
1628
1629 /* check macaddr */
1630 if (MAC_IS_ALL_ZEROS(mac_entry->addr) ||
1631 MAC_IS_BROADCAST(mac_entry->addr)) {
1632 dev_err(dsaf_dev->dev, "get_entry failed,addr %pM\n",
1633 mac_entry->addr);
1634 return -EINVAL;
1635 }
1636
1637 /*config key */
1638 hns_dsaf_set_mac_key(dsaf_dev, &mac_key, mac_entry->in_vlan_id,
1639 mac_entry->in_port_num, mac_entry->addr);
1640
1641 /*check exist? */
1642 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1643 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1644 /*find none, error */
1645 dev_err(dsaf_dev->dev,
1646 "get_uc_entry failed, %s Mac key(%#x:%#x)\n",
1647 dsaf_dev->ae_dev.name,
1648 mac_key.high.val, mac_key.low.val);
1649 return -EINVAL;
1650 }
1651 dev_dbg(dsaf_dev->dev,
1652 "get_uc_entry, %s Mac key(%#x:%#x) entry_index%d\n",
1653 dsaf_dev->ae_dev.name, mac_key.high.val,
1654 mac_key.low.val, entry_index);
1655
1656 /*read entry*/
1657 hns_dsaf_tcam_uc_get(dsaf_dev, entry_index,
1658 (struct dsaf_tbl_tcam_data *)&mac_key, &mac_data);
1659 mac_entry->port_num = mac_data.tbl_ucast_out_port;
1660
1661 return 0;
1662 }
1663
1664 /**
1665 * hns_dsaf_get_mac_mc_entry - get mac mc entry
1666 * @dsaf_dev: dsa fabric device struct pointer
1667 * @mac_entry: mac entry
1668 */
1669 int hns_dsaf_get_mac_mc_entry(struct dsaf_device *dsaf_dev,
1670 struct dsaf_drv_mac_multi_dest_entry *mac_entry)
1671 {
1672 u16 entry_index = DSAF_INVALID_ENTRY_IDX;
1673 struct dsaf_drv_tbl_tcam_key mac_key;
1674
1675 struct dsaf_tbl_tcam_mcast_cfg mac_data;
1676
1677 /*check mac addr */
1678 if (MAC_IS_ALL_ZEROS(mac_entry->addr) ||
1679 MAC_IS_BROADCAST(mac_entry->addr)) {
1680 dev_err(dsaf_dev->dev, "get_entry failed,addr %pM\n",
1681 mac_entry->addr);
1682 return -EINVAL;
1683 }
1684
1685 /*config key */
1686 hns_dsaf_set_mac_key(dsaf_dev, &mac_key, mac_entry->in_vlan_id,
1687 mac_entry->in_port_num, mac_entry->addr);
1688
1689 /*check exist? */
1690 entry_index = hns_dsaf_find_soft_mac_entry(dsaf_dev, &mac_key);
1691 if (entry_index == DSAF_INVALID_ENTRY_IDX) {
1692 /* find none, error */
1693 dev_err(dsaf_dev->dev,
1694 "get_mac_uc_entry failed, %s Mac key(%#x:%#x)\n",
1695 dsaf_dev->ae_dev.name, mac_key.high.val,
1696 mac_key.low.val);
1697 return -EINVAL;
1698 }
1699 dev_dbg(dsaf_dev->dev,
1700 "get_mac_uc_entry, %s Mac key(%#x:%#x) entry_index%d\n",
1701 dsaf_dev->ae_dev.name, mac_key.high.val,
1702 mac_key.low.val, entry_index);
1703
1704 /*read entry */
1705 hns_dsaf_tcam_mc_get(dsaf_dev, entry_index,
1706 (struct dsaf_tbl_tcam_data *)&mac_key, &mac_data);
1707
1708 mac_entry->port_mask[0] = mac_data.tbl_mcast_port_msk[0] & 0x3F;
1709 return 0;
1710 }
1711
1712 /**
1713 * hns_dsaf_get_mac_entry_by_index - get mac entry by tab index
1714 * @dsaf_dev: dsa fabric device struct pointer
1715 * @entry_index: tab entry index
1716 * @mac_entry: mac entry
1717 */
1718 int hns_dsaf_get_mac_entry_by_index(
1719 struct dsaf_device *dsaf_dev,
1720 u16 entry_index, struct dsaf_drv_mac_multi_dest_entry *mac_entry)
1721 {
1722 struct dsaf_drv_tbl_tcam_key mac_key;
1723
1724 struct dsaf_tbl_tcam_mcast_cfg mac_data;
1725 struct dsaf_tbl_tcam_ucast_cfg mac_uc_data;
1726 char mac_addr[MAC_NUM_OCTETS_PER_ADDR] = {0};
1727
1728 if (entry_index >= DSAF_TCAM_SUM) {
1729 /* find none, del error */
1730 dev_err(dsaf_dev->dev, "get_uc_entry failed, %s\n",
1731 dsaf_dev->ae_dev.name);
1732 return -EINVAL;
1733 }
1734
1735 /* mc entry, do read opt */
1736 hns_dsaf_tcam_mc_get(dsaf_dev, entry_index,
1737 (struct dsaf_tbl_tcam_data *)&mac_key, &mac_data);
1738
1739 mac_entry->port_mask[0] = mac_data.tbl_mcast_port_msk[0] & 0x3F;
1740
1741 /***get mac addr*/
1742 mac_addr[0] = mac_key.high.bits.mac_0;
1743 mac_addr[1] = mac_key.high.bits.mac_1;
1744 mac_addr[2] = mac_key.high.bits.mac_2;
1745 mac_addr[3] = mac_key.high.bits.mac_3;
1746 mac_addr[4] = mac_key.low.bits.mac_4;
1747 mac_addr[5] = mac_key.low.bits.mac_5;
1748 /**is mc or uc*/
1749 if (MAC_IS_MULTICAST((u8 *)mac_addr) ||
1750 MAC_IS_L3_MULTICAST((u8 *)mac_addr)) {
1751 /**mc donot do*/
1752 } else {
1753 /*is not mc, just uc... */
1754 hns_dsaf_tcam_uc_get(dsaf_dev, entry_index,
1755 (struct dsaf_tbl_tcam_data *)&mac_key,
1756 &mac_uc_data);
1757 mac_entry->port_mask[0] = (1 << mac_uc_data.tbl_ucast_out_port);
1758 }
1759
1760 return 0;
1761 }
1762
1763 static struct dsaf_device *hns_dsaf_alloc_dev(struct device *dev,
1764 size_t sizeof_priv)
1765 {
1766 struct dsaf_device *dsaf_dev;
1767
1768 dsaf_dev = devm_kzalloc(dev,
1769 sizeof(*dsaf_dev) + sizeof_priv, GFP_KERNEL);
1770 if (unlikely(!dsaf_dev)) {
1771 dsaf_dev = ERR_PTR(-ENOMEM);
1772 } else {
1773 dsaf_dev->dev = dev;
1774 dev_set_drvdata(dev, dsaf_dev);
1775 }
1776
1777 return dsaf_dev;
1778 }
1779
1780 /**
1781 * hns_dsaf_free_dev - free dev mem
1782 * @dev: struct device pointer
1783 */
1784 static void hns_dsaf_free_dev(struct dsaf_device *dsaf_dev)
1785 {
1786 (void)dev_set_drvdata(dsaf_dev->dev, NULL);
1787 }
1788
1789 /**
1790 * dsaf_pfc_unit_cnt - set pfc unit count
1791 * @dsaf_id: dsa fabric id
1792 * @pport_rate: value array
1793 * @pdsaf_pfc_unit_cnt: value array
1794 */
1795 static void hns_dsaf_pfc_unit_cnt(struct dsaf_device *dsaf_dev, int mac_id,
1796 enum dsaf_port_rate_mode rate)
1797 {
1798 u32 unit_cnt;
1799
1800 switch (rate) {
1801 case DSAF_PORT_RATE_10000:
1802 unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_XGE;
1803 break;
1804 case DSAF_PORT_RATE_1000:
1805 unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_GE_1000;
1806 break;
1807 case DSAF_PORT_RATE_2500:
1808 unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_GE_1000;
1809 break;
1810 default:
1811 unit_cnt = HNS_DSAF_PFC_UNIT_CNT_FOR_XGE;
1812 }
1813
1814 dsaf_set_dev_field(dsaf_dev,
1815 (DSAF_PFC_UNIT_CNT_0_REG + 0x4 * (u64)mac_id),
1816 DSAF_PFC_UNINT_CNT_M, DSAF_PFC_UNINT_CNT_S,
1817 unit_cnt);
1818 }
1819
1820 /**
1821 * dsaf_port_work_rate_cfg - fifo
1822 * @dsaf_id: dsa fabric id
1823 * @xge_ge_work_mode
1824 */
1825 void hns_dsaf_port_work_rate_cfg(struct dsaf_device *dsaf_dev, int mac_id,
1826 enum dsaf_port_rate_mode rate_mode)
1827 {
1828 u32 port_work_mode;
1829
1830 port_work_mode = dsaf_read_dev(
1831 dsaf_dev, DSAF_XGE_GE_WORK_MODE_0_REG + 0x4 * (u64)mac_id);
1832
1833 if (rate_mode == DSAF_PORT_RATE_10000)
1834 dsaf_set_bit(port_work_mode, DSAF_XGE_GE_WORK_MODE_S, 1);
1835 else
1836 dsaf_set_bit(port_work_mode, DSAF_XGE_GE_WORK_MODE_S, 0);
1837
1838 dsaf_write_dev(dsaf_dev,
1839 DSAF_XGE_GE_WORK_MODE_0_REG + 0x4 * (u64)mac_id,
1840 port_work_mode);
1841
1842 hns_dsaf_pfc_unit_cnt(dsaf_dev, mac_id, rate_mode);
1843 }
1844
1845 /**
1846 * hns_dsaf_fix_mac_mode - dsaf modify mac mode
1847 * @mac_cb: mac contrl block
1848 */
1849 void hns_dsaf_fix_mac_mode(struct hns_mac_cb *mac_cb)
1850 {
1851 enum dsaf_port_rate_mode mode;
1852 struct dsaf_device *dsaf_dev = mac_cb->dsaf_dev;
1853 int mac_id = mac_cb->mac_id;
1854
1855 if (mac_cb->mac_type != HNAE_PORT_SERVICE)
1856 return;
1857 if (mac_cb->phy_if == PHY_INTERFACE_MODE_XGMII)
1858 mode = DSAF_PORT_RATE_10000;
1859 else
1860 mode = DSAF_PORT_RATE_1000;
1861
1862 hns_dsaf_port_work_rate_cfg(dsaf_dev, mac_id, mode);
1863 }
1864
1865 void hns_dsaf_update_stats(struct dsaf_device *dsaf_dev, u32 node_num)
1866 {
1867 struct dsaf_hw_stats *hw_stats
1868 = &dsaf_dev->hw_stats[node_num];
1869
1870 hw_stats->pad_drop += dsaf_read_dev(dsaf_dev,
1871 DSAF_INODE_PAD_DISCARD_NUM_0_REG + 0x80 * (u64)node_num);
1872 hw_stats->man_pkts += dsaf_read_dev(dsaf_dev,
1873 DSAF_INODE_FINAL_IN_MAN_NUM_0_REG + 0x80 * (u64)node_num);
1874 hw_stats->rx_pkts += dsaf_read_dev(dsaf_dev,
1875 DSAF_INODE_FINAL_IN_PKT_NUM_0_REG + 0x80 * (u64)node_num);
1876 hw_stats->rx_pkt_id += dsaf_read_dev(dsaf_dev,
1877 DSAF_INODE_SBM_PID_NUM_0_REG + 0x80 * (u64)node_num);
1878 hw_stats->rx_pause_frame += dsaf_read_dev(dsaf_dev,
1879 DSAF_INODE_FINAL_IN_PAUSE_NUM_0_REG + 0x80 * (u64)node_num);
1880 hw_stats->release_buf_num += dsaf_read_dev(dsaf_dev,
1881 DSAF_INODE_SBM_RELS_NUM_0_REG + 0x80 * (u64)node_num);
1882 hw_stats->sbm_drop += dsaf_read_dev(dsaf_dev,
1883 DSAF_INODE_SBM_DROP_NUM_0_REG + 0x80 * (u64)node_num);
1884 hw_stats->crc_false += dsaf_read_dev(dsaf_dev,
1885 DSAF_INODE_CRC_FALSE_NUM_0_REG + 0x80 * (u64)node_num);
1886 hw_stats->bp_drop += dsaf_read_dev(dsaf_dev,
1887 DSAF_INODE_BP_DISCARD_NUM_0_REG + 0x80 * (u64)node_num);
1888 hw_stats->rslt_drop += dsaf_read_dev(dsaf_dev,
1889 DSAF_INODE_RSLT_DISCARD_NUM_0_REG + 0x80 * (u64)node_num);
1890 hw_stats->local_addr_false += dsaf_read_dev(dsaf_dev,
1891 DSAF_INODE_LOCAL_ADDR_FALSE_NUM_0_REG + 0x80 * (u64)node_num);
1892
1893 hw_stats->vlan_drop += dsaf_read_dev(dsaf_dev,
1894 DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + 0x80 * (u64)node_num);
1895 hw_stats->stp_drop += dsaf_read_dev(dsaf_dev,
1896 DSAF_INODE_IN_DATA_STP_DISC_0_REG + 0x80 * (u64)node_num);
1897
1898 hw_stats->tx_pkts += dsaf_read_dev(dsaf_dev,
1899 DSAF_XOD_RCVPKT_CNT_0_REG + 0x90 * (u64)node_num);
1900 }
1901
1902 /**
1903 *hns_dsaf_get_regs - dump dsaf regs
1904 *@dsaf_dev: dsaf device
1905 *@data:data for value of regs
1906 */
1907 void hns_dsaf_get_regs(struct dsaf_device *ddev, u32 port, void *data)
1908 {
1909 u32 i = 0;
1910 u32 j;
1911 u32 *p = data;
1912
1913 /* dsaf common registers */
1914 p[0] = dsaf_read_dev(ddev, DSAF_SRAM_INIT_OVER_0_REG);
1915 p[1] = dsaf_read_dev(ddev, DSAF_CFG_0_REG);
1916 p[2] = dsaf_read_dev(ddev, DSAF_ECC_ERR_INVERT_0_REG);
1917 p[3] = dsaf_read_dev(ddev, DSAF_ABNORMAL_TIMEOUT_0_REG);
1918 p[4] = dsaf_read_dev(ddev, DSAF_FSM_TIMEOUT_0_REG);
1919 p[5] = dsaf_read_dev(ddev, DSAF_DSA_REG_CNT_CLR_CE_REG);
1920 p[6] = dsaf_read_dev(ddev, DSAF_DSA_SBM_INF_FIFO_THRD_REG);
1921 p[7] = dsaf_read_dev(ddev, DSAF_DSA_SRAM_1BIT_ECC_SEL_REG);
1922 p[8] = dsaf_read_dev(ddev, DSAF_DSA_SRAM_1BIT_ECC_CNT_REG);
1923
1924 p[9] = dsaf_read_dev(ddev, DSAF_PFC_EN_0_REG + port * 4);
1925 p[10] = dsaf_read_dev(ddev, DSAF_PFC_UNIT_CNT_0_REG + port * 4);
1926 p[11] = dsaf_read_dev(ddev, DSAF_XGE_INT_MSK_0_REG + port * 4);
1927 p[12] = dsaf_read_dev(ddev, DSAF_XGE_INT_SRC_0_REG + port * 4);
1928 p[13] = dsaf_read_dev(ddev, DSAF_XGE_INT_STS_0_REG + port * 4);
1929 p[14] = dsaf_read_dev(ddev, DSAF_XGE_INT_MSK_0_REG + port * 4);
1930 p[15] = dsaf_read_dev(ddev, DSAF_PPE_INT_MSK_0_REG + port * 4);
1931 p[16] = dsaf_read_dev(ddev, DSAF_ROCEE_INT_MSK_0_REG + port * 4);
1932 p[17] = dsaf_read_dev(ddev, DSAF_XGE_INT_SRC_0_REG + port * 4);
1933 p[18] = dsaf_read_dev(ddev, DSAF_PPE_INT_SRC_0_REG + port * 4);
1934 p[19] = dsaf_read_dev(ddev, DSAF_ROCEE_INT_SRC_0_REG + port * 4);
1935 p[20] = dsaf_read_dev(ddev, DSAF_XGE_INT_STS_0_REG + port * 4);
1936 p[21] = dsaf_read_dev(ddev, DSAF_PPE_INT_STS_0_REG + port * 4);
1937 p[22] = dsaf_read_dev(ddev, DSAF_ROCEE_INT_STS_0_REG + port * 4);
1938 p[23] = dsaf_read_dev(ddev, DSAF_PPE_QID_CFG_0_REG + port * 4);
1939
1940 for (i = 0; i < DSAF_SW_PORT_NUM; i++)
1941 p[24 + i] = dsaf_read_dev(ddev,
1942 DSAF_SW_PORT_TYPE_0_REG + i * 4);
1943
1944 p[32] = dsaf_read_dev(ddev, DSAF_MIX_DEF_QID_0_REG + port * 4);
1945
1946 for (i = 0; i < DSAF_SW_PORT_NUM; i++)
1947 p[33 + i] = dsaf_read_dev(ddev,
1948 DSAF_PORT_DEF_VLAN_0_REG + i * 4);
1949
1950 for (i = 0; i < DSAF_TOTAL_QUEUE_NUM; i++)
1951 p[41 + i] = dsaf_read_dev(ddev,
1952 DSAF_VM_DEF_VLAN_0_REG + i * 4);
1953
1954 /* dsaf inode registers */
1955 p[170] = dsaf_read_dev(ddev, DSAF_INODE_CUT_THROUGH_CFG_0_REG);
1956
1957 p[171] = dsaf_read_dev(ddev,
1958 DSAF_INODE_ECC_ERR_ADDR_0_REG + port * 0x80);
1959
1960 for (i = 0; i < DSAF_INODE_NUM / DSAF_COMM_CHN; i++) {
1961 j = i * DSAF_COMM_CHN + port;
1962 p[172 + i] = dsaf_read_dev(ddev,
1963 DSAF_INODE_IN_PORT_NUM_0_REG + j * 0x80);
1964 p[175 + i] = dsaf_read_dev(ddev,
1965 DSAF_INODE_PRI_TC_CFG_0_REG + j * 0x80);
1966 p[178 + i] = dsaf_read_dev(ddev,
1967 DSAF_INODE_BP_STATUS_0_REG + j * 0x80);
1968 p[181 + i] = dsaf_read_dev(ddev,
1969 DSAF_INODE_PAD_DISCARD_NUM_0_REG + j * 0x80);
1970 p[184 + i] = dsaf_read_dev(ddev,
1971 DSAF_INODE_FINAL_IN_MAN_NUM_0_REG + j * 0x80);
1972 p[187 + i] = dsaf_read_dev(ddev,
1973 DSAF_INODE_FINAL_IN_PKT_NUM_0_REG + j * 0x80);
1974 p[190 + i] = dsaf_read_dev(ddev,
1975 DSAF_INODE_SBM_PID_NUM_0_REG + j * 0x80);
1976 p[193 + i] = dsaf_read_dev(ddev,
1977 DSAF_INODE_FINAL_IN_PAUSE_NUM_0_REG + j * 0x80);
1978 p[196 + i] = dsaf_read_dev(ddev,
1979 DSAF_INODE_SBM_RELS_NUM_0_REG + j * 0x80);
1980 p[199 + i] = dsaf_read_dev(ddev,
1981 DSAF_INODE_SBM_DROP_NUM_0_REG + j * 0x80);
1982 p[202 + i] = dsaf_read_dev(ddev,
1983 DSAF_INODE_CRC_FALSE_NUM_0_REG + j * 0x80);
1984 p[205 + i] = dsaf_read_dev(ddev,
1985 DSAF_INODE_BP_DISCARD_NUM_0_REG + j * 0x80);
1986 p[208 + i] = dsaf_read_dev(ddev,
1987 DSAF_INODE_RSLT_DISCARD_NUM_0_REG + j * 0x80);
1988 p[211 + i] = dsaf_read_dev(ddev,
1989 DSAF_INODE_LOCAL_ADDR_FALSE_NUM_0_REG + j * 0x80);
1990 p[214 + i] = dsaf_read_dev(ddev,
1991 DSAF_INODE_VOQ_OVER_NUM_0_REG + j * 0x80);
1992 p[217 + i] = dsaf_read_dev(ddev,
1993 DSAF_INODE_BD_SAVE_STATUS_0_REG + j * 4);
1994 p[220 + i] = dsaf_read_dev(ddev,
1995 DSAF_INODE_BD_ORDER_STATUS_0_REG + j * 4);
1996 p[223 + i] = dsaf_read_dev(ddev,
1997 DSAF_INODE_SW_VLAN_TAG_DISC_0_REG + j * 4);
1998 p[224 + i] = dsaf_read_dev(ddev,
1999 DSAF_INODE_IN_DATA_STP_DISC_0_REG + j * 4);
2000 }
2001
2002 p[227] = dsaf_read_dev(ddev, DSAF_INODE_GE_FC_EN_0_REG + port * 4);
2003
2004 for (i = 0; i < DSAF_INODE_NUM / DSAF_COMM_CHN; i++) {
2005 j = i * DSAF_COMM_CHN + port;
2006 p[228 + i] = dsaf_read_dev(ddev,
2007 DSAF_INODE_VC0_IN_PKT_NUM_0_REG + j * 4);
2008 }
2009
2010 p[231] = dsaf_read_dev(ddev,
2011 DSAF_INODE_VC1_IN_PKT_NUM_0_REG + port * 4);
2012
2013 /* dsaf inode registers */
2014 for (i = 0; i < DSAF_SBM_NUM / DSAF_COMM_CHN; i++) {
2015 j = i * DSAF_COMM_CHN + port;
2016 p[232 + i] = dsaf_read_dev(ddev,
2017 DSAF_SBM_CFG_REG_0_REG + j * 0x80);
2018 p[235 + i] = dsaf_read_dev(ddev,
2019 DSAF_SBM_BP_CFG_0_XGE_REG_0_REG + j * 0x80);
2020 p[238 + i] = dsaf_read_dev(ddev,
2021 DSAF_SBM_BP_CFG_1_REG_0_REG + j * 0x80);
2022 p[241 + i] = dsaf_read_dev(ddev,
2023 DSAF_SBM_BP_CFG_2_XGE_REG_0_REG + j * 0x80);
2024 p[244 + i] = dsaf_read_dev(ddev,
2025 DSAF_SBM_FREE_CNT_0_0_REG + j * 0x80);
2026 p[245 + i] = dsaf_read_dev(ddev,
2027 DSAF_SBM_FREE_CNT_1_0_REG + j * 0x80);
2028 p[248 + i] = dsaf_read_dev(ddev,
2029 DSAF_SBM_BP_CNT_0_0_REG + j * 0x80);
2030 p[251 + i] = dsaf_read_dev(ddev,
2031 DSAF_SBM_BP_CNT_1_0_REG + j * 0x80);
2032 p[254 + i] = dsaf_read_dev(ddev,
2033 DSAF_SBM_BP_CNT_2_0_REG + j * 0x80);
2034 p[257 + i] = dsaf_read_dev(ddev,
2035 DSAF_SBM_BP_CNT_3_0_REG + j * 0x80);
2036 p[260 + i] = dsaf_read_dev(ddev,
2037 DSAF_SBM_INER_ST_0_REG + j * 0x80);
2038 p[263 + i] = dsaf_read_dev(ddev,
2039 DSAF_SBM_MIB_REQ_FAILED_TC_0_REG + j * 0x80);
2040 p[266 + i] = dsaf_read_dev(ddev,
2041 DSAF_SBM_LNK_INPORT_CNT_0_REG + j * 0x80);
2042 p[269 + i] = dsaf_read_dev(ddev,
2043 DSAF_SBM_LNK_DROP_CNT_0_REG + j * 0x80);
2044 p[272 + i] = dsaf_read_dev(ddev,
2045 DSAF_SBM_INF_OUTPORT_CNT_0_REG + j * 0x80);
2046 p[275 + i] = dsaf_read_dev(ddev,
2047 DSAF_SBM_LNK_INPORT_TC0_CNT_0_REG + j * 0x80);
2048 p[278 + i] = dsaf_read_dev(ddev,
2049 DSAF_SBM_LNK_INPORT_TC1_CNT_0_REG + j * 0x80);
2050 p[281 + i] = dsaf_read_dev(ddev,
2051 DSAF_SBM_LNK_INPORT_TC2_CNT_0_REG + j * 0x80);
2052 p[284 + i] = dsaf_read_dev(ddev,
2053 DSAF_SBM_LNK_INPORT_TC3_CNT_0_REG + j * 0x80);
2054 p[287 + i] = dsaf_read_dev(ddev,
2055 DSAF_SBM_LNK_INPORT_TC4_CNT_0_REG + j * 0x80);
2056 p[290 + i] = dsaf_read_dev(ddev,
2057 DSAF_SBM_LNK_INPORT_TC5_CNT_0_REG + j * 0x80);
2058 p[293 + i] = dsaf_read_dev(ddev,
2059 DSAF_SBM_LNK_INPORT_TC6_CNT_0_REG + j * 0x80);
2060 p[296 + i] = dsaf_read_dev(ddev,
2061 DSAF_SBM_LNK_INPORT_TC7_CNT_0_REG + j * 0x80);
2062 p[299 + i] = dsaf_read_dev(ddev,
2063 DSAF_SBM_LNK_REQ_CNT_0_REG + j * 0x80);
2064 p[302 + i] = dsaf_read_dev(ddev,
2065 DSAF_SBM_LNK_RELS_CNT_0_REG + j * 0x80);
2066 p[305 + i] = dsaf_read_dev(ddev,
2067 DSAF_SBM_BP_CFG_3_REG_0_REG + j * 0x80);
2068 p[308 + i] = dsaf_read_dev(ddev,
2069 DSAF_SBM_BP_CFG_4_REG_0_REG + j * 0x80);
2070 }
2071
2072 /* dsaf onode registers */
2073 for (i = 0; i < DSAF_XOD_NUM; i++) {
2074 p[311 + i] = dsaf_read_dev(ddev,
2075 DSAF_XOD_ETS_TSA_TC0_TC3_CFG_0_REG + j * 0x90);
2076 p[319 + i] = dsaf_read_dev(ddev,
2077 DSAF_XOD_ETS_TSA_TC4_TC7_CFG_0_REG + j * 0x90);
2078 p[327 + i] = dsaf_read_dev(ddev,
2079 DSAF_XOD_ETS_BW_TC0_TC3_CFG_0_REG + j * 0x90);
2080 p[335 + i] = dsaf_read_dev(ddev,
2081 DSAF_XOD_ETS_BW_TC4_TC7_CFG_0_REG + j * 0x90);
2082 p[343 + i] = dsaf_read_dev(ddev,
2083 DSAF_XOD_ETS_BW_OFFSET_CFG_0_REG + j * 0x90);
2084 p[351 + i] = dsaf_read_dev(ddev,
2085 DSAF_XOD_ETS_TOKEN_CFG_0_REG + j * 0x90);
2086 }
2087
2088 p[359] = dsaf_read_dev(ddev, DSAF_XOD_PFS_CFG_0_0_REG + port * 0x90);
2089 p[360] = dsaf_read_dev(ddev, DSAF_XOD_PFS_CFG_1_0_REG + port * 0x90);
2090 p[361] = dsaf_read_dev(ddev, DSAF_XOD_PFS_CFG_2_0_REG + port * 0x90);
2091
2092 for (i = 0; i < DSAF_XOD_BIG_NUM / DSAF_COMM_CHN; i++) {
2093 j = i * DSAF_COMM_CHN + port;
2094 p[362 + i] = dsaf_read_dev(ddev,
2095 DSAF_XOD_GNT_L_0_REG + j * 0x90);
2096 p[365 + i] = dsaf_read_dev(ddev,
2097 DSAF_XOD_GNT_H_0_REG + j * 0x90);
2098 p[368 + i] = dsaf_read_dev(ddev,
2099 DSAF_XOD_CONNECT_STATE_0_REG + j * 0x90);
2100 p[371 + i] = dsaf_read_dev(ddev,
2101 DSAF_XOD_RCVPKT_CNT_0_REG + j * 0x90);
2102 p[374 + i] = dsaf_read_dev(ddev,
2103 DSAF_XOD_RCVTC0_CNT_0_REG + j * 0x90);
2104 p[377 + i] = dsaf_read_dev(ddev,
2105 DSAF_XOD_RCVTC1_CNT_0_REG + j * 0x90);
2106 p[380 + i] = dsaf_read_dev(ddev,
2107 DSAF_XOD_RCVTC2_CNT_0_REG + j * 0x90);
2108 p[383 + i] = dsaf_read_dev(ddev,
2109 DSAF_XOD_RCVTC3_CNT_0_REG + j * 0x90);
2110 p[386 + i] = dsaf_read_dev(ddev,
2111 DSAF_XOD_RCVVC0_CNT_0_REG + j * 0x90);
2112 p[389 + i] = dsaf_read_dev(ddev,
2113 DSAF_XOD_RCVVC1_CNT_0_REG + j * 0x90);
2114 }
2115
2116 p[392] = dsaf_read_dev(ddev,
2117 DSAF_XOD_XGE_RCVIN0_CNT_0_REG + port * 0x90);
2118 p[393] = dsaf_read_dev(ddev,
2119 DSAF_XOD_XGE_RCVIN1_CNT_0_REG + port * 0x90);
2120 p[394] = dsaf_read_dev(ddev,
2121 DSAF_XOD_XGE_RCVIN2_CNT_0_REG + port * 0x90);
2122 p[395] = dsaf_read_dev(ddev,
2123 DSAF_XOD_XGE_RCVIN3_CNT_0_REG + port * 0x90);
2124 p[396] = dsaf_read_dev(ddev,
2125 DSAF_XOD_XGE_RCVIN4_CNT_0_REG + port * 0x90);
2126 p[397] = dsaf_read_dev(ddev,
2127 DSAF_XOD_XGE_RCVIN5_CNT_0_REG + port * 0x90);
2128 p[398] = dsaf_read_dev(ddev,
2129 DSAF_XOD_XGE_RCVIN6_CNT_0_REG + port * 0x90);
2130 p[399] = dsaf_read_dev(ddev,
2131 DSAF_XOD_XGE_RCVIN7_CNT_0_REG + port * 0x90);
2132 p[400] = dsaf_read_dev(ddev,
2133 DSAF_XOD_PPE_RCVIN0_CNT_0_REG + port * 0x90);
2134 p[401] = dsaf_read_dev(ddev,
2135 DSAF_XOD_PPE_RCVIN1_CNT_0_REG + port * 0x90);
2136 p[402] = dsaf_read_dev(ddev,
2137 DSAF_XOD_ROCEE_RCVIN0_CNT_0_REG + port * 0x90);
2138 p[403] = dsaf_read_dev(ddev,
2139 DSAF_XOD_ROCEE_RCVIN1_CNT_0_REG + port * 0x90);
2140 p[404] = dsaf_read_dev(ddev,
2141 DSAF_XOD_FIFO_STATUS_0_REG + port * 0x90);
2142
2143 /* dsaf voq registers */
2144 for (i = 0; i < DSAF_VOQ_NUM / DSAF_COMM_CHN; i++) {
2145 j = (i * DSAF_COMM_CHN + port) * 0x90;
2146 p[405 + i] = dsaf_read_dev(ddev,
2147 DSAF_VOQ_ECC_INVERT_EN_0_REG + j);
2148 p[408 + i] = dsaf_read_dev(ddev,
2149 DSAF_VOQ_SRAM_PKT_NUM_0_REG + j);
2150 p[411 + i] = dsaf_read_dev(ddev, DSAF_VOQ_IN_PKT_NUM_0_REG + j);
2151 p[414 + i] = dsaf_read_dev(ddev,
2152 DSAF_VOQ_OUT_PKT_NUM_0_REG + j);
2153 p[417 + i] = dsaf_read_dev(ddev,
2154 DSAF_VOQ_ECC_ERR_ADDR_0_REG + j);
2155 p[420 + i] = dsaf_read_dev(ddev, DSAF_VOQ_BP_STATUS_0_REG + j);
2156 p[423 + i] = dsaf_read_dev(ddev, DSAF_VOQ_SPUP_IDLE_0_REG + j);
2157 p[426 + i] = dsaf_read_dev(ddev,
2158 DSAF_VOQ_XGE_XOD_REQ_0_0_REG + j);
2159 p[429 + i] = dsaf_read_dev(ddev,
2160 DSAF_VOQ_XGE_XOD_REQ_1_0_REG + j);
2161 p[432 + i] = dsaf_read_dev(ddev,
2162 DSAF_VOQ_PPE_XOD_REQ_0_REG + j);
2163 p[435 + i] = dsaf_read_dev(ddev,
2164 DSAF_VOQ_ROCEE_XOD_REQ_0_REG + j);
2165 p[438 + i] = dsaf_read_dev(ddev,
2166 DSAF_VOQ_BP_ALL_THRD_0_REG + j);
2167 }
2168
2169 /* dsaf tbl registers */
2170 p[441] = dsaf_read_dev(ddev, DSAF_TBL_CTRL_0_REG);
2171 p[442] = dsaf_read_dev(ddev, DSAF_TBL_INT_MSK_0_REG);
2172 p[443] = dsaf_read_dev(ddev, DSAF_TBL_INT_SRC_0_REG);
2173 p[444] = dsaf_read_dev(ddev, DSAF_TBL_INT_STS_0_REG);
2174 p[445] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_ADDR_0_REG);
2175 p[446] = dsaf_read_dev(ddev, DSAF_TBL_LINE_ADDR_0_REG);
2176 p[447] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_HIGH_0_REG);
2177 p[448] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_LOW_0_REG);
2178 p[449] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_4_0_REG);
2179 p[450] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_3_0_REG);
2180 p[451] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_2_0_REG);
2181 p[452] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_1_0_REG);
2182 p[453] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_MCAST_CFG_0_0_REG);
2183 p[454] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_UCAST_CFG_0_REG);
2184 p[455] = dsaf_read_dev(ddev, DSAF_TBL_LIN_CFG_0_REG);
2185 p[456] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RDATA_HIGH_0_REG);
2186 p[457] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RDATA_LOW_0_REG);
2187 p[458] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA4_0_REG);
2188 p[459] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA3_0_REG);
2189 p[460] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA2_0_REG);
2190 p[461] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA1_0_REG);
2191 p[462] = dsaf_read_dev(ddev, DSAF_TBL_TCAM_RAM_RDATA0_0_REG);
2192 p[463] = dsaf_read_dev(ddev, DSAF_TBL_LIN_RDATA_0_REG);
2193
2194 for (i = 0; i < DSAF_SW_PORT_NUM; i++) {
2195 j = i * 0x8;
2196 p[464 + 2 * i] = dsaf_read_dev(ddev,
2197 DSAF_TBL_DA0_MIS_INFO1_0_REG + j);
2198 p[465 + 2 * i] = dsaf_read_dev(ddev,
2199 DSAF_TBL_DA0_MIS_INFO0_0_REG + j);
2200 }
2201
2202 p[480] = dsaf_read_dev(ddev, DSAF_TBL_SA_MIS_INFO2_0_REG);
2203 p[481] = dsaf_read_dev(ddev, DSAF_TBL_SA_MIS_INFO1_0_REG);
2204 p[482] = dsaf_read_dev(ddev, DSAF_TBL_SA_MIS_INFO0_0_REG);
2205 p[483] = dsaf_read_dev(ddev, DSAF_TBL_PUL_0_REG);
2206 p[484] = dsaf_read_dev(ddev, DSAF_TBL_OLD_RSLT_0_REG);
2207 p[485] = dsaf_read_dev(ddev, DSAF_TBL_OLD_SCAN_VAL_0_REG);
2208 p[486] = dsaf_read_dev(ddev, DSAF_TBL_DFX_CTRL_0_REG);
2209 p[487] = dsaf_read_dev(ddev, DSAF_TBL_DFX_STAT_0_REG);
2210 p[488] = dsaf_read_dev(ddev, DSAF_TBL_DFX_STAT_2_0_REG);
2211 p[489] = dsaf_read_dev(ddev, DSAF_TBL_LKUP_NUM_I_0_REG);
2212 p[490] = dsaf_read_dev(ddev, DSAF_TBL_LKUP_NUM_O_0_REG);
2213 p[491] = dsaf_read_dev(ddev, DSAF_TBL_UCAST_BCAST_MIS_INFO_0_0_REG);
2214
2215 /* dsaf other registers */
2216 p[492] = dsaf_read_dev(ddev, DSAF_INODE_FIFO_WL_0_REG + port * 0x4);
2217 p[493] = dsaf_read_dev(ddev, DSAF_ONODE_FIFO_WL_0_REG + port * 0x4);
2218 p[494] = dsaf_read_dev(ddev, DSAF_XGE_GE_WORK_MODE_0_REG + port * 0x4);
2219 p[495] = dsaf_read_dev(ddev,
2220 DSAF_XGE_APP_RX_LINK_UP_0_REG + port * 0x4);
2221 p[496] = dsaf_read_dev(ddev, DSAF_NETPORT_CTRL_SIG_0_REG + port * 0x4);
2222 p[497] = dsaf_read_dev(ddev, DSAF_XGE_CTRL_SIG_CFG_0_REG + port * 0x4);
2223
2224 /* mark end of dsaf regs */
2225 for (i = 498; i < 504; i++)
2226 p[i] = 0xdddddddd;
2227 }
2228
2229 static char *hns_dsaf_get_node_stats_strings(char *data, int node)
2230 {
2231 char *buff = data;
2232
2233 snprintf(buff, ETH_GSTRING_LEN, "innod%d_pad_drop_pkts", node);
2234 buff = buff + ETH_GSTRING_LEN;
2235 snprintf(buff, ETH_GSTRING_LEN, "innod%d_manage_pkts", node);
2236 buff = buff + ETH_GSTRING_LEN;
2237 snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkts", node);
2238 buff = buff + ETH_GSTRING_LEN;
2239 snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pkt_id", node);
2240 buff = buff + ETH_GSTRING_LEN;
2241 snprintf(buff, ETH_GSTRING_LEN, "innod%d_rx_pause_frame", node);
2242 buff = buff + ETH_GSTRING_LEN;
2243 snprintf(buff, ETH_GSTRING_LEN, "innod%d_release_buf_num", node);
2244 buff = buff + ETH_GSTRING_LEN;
2245 snprintf(buff, ETH_GSTRING_LEN, "innod%d_sbm_drop_pkts", node);
2246 buff = buff + ETH_GSTRING_LEN;
2247 snprintf(buff, ETH_GSTRING_LEN, "innod%d_crc_false_pkts", node);
2248 buff = buff + ETH_GSTRING_LEN;
2249 snprintf(buff, ETH_GSTRING_LEN, "innod%d_bp_drop_pkts", node);
2250 buff = buff + ETH_GSTRING_LEN;
2251 snprintf(buff, ETH_GSTRING_LEN, "innod%d_lookup_rslt_drop_pkts", node);
2252 buff = buff + ETH_GSTRING_LEN;
2253 snprintf(buff, ETH_GSTRING_LEN, "innod%d_local_rslt_fail_pkts", node);
2254 buff = buff + ETH_GSTRING_LEN;
2255 snprintf(buff, ETH_GSTRING_LEN, "innod%d_vlan_drop_pkts", node);
2256 buff = buff + ETH_GSTRING_LEN;
2257 snprintf(buff, ETH_GSTRING_LEN, "innod%d_stp_drop_pkts", node);
2258 buff = buff + ETH_GSTRING_LEN;
2259 snprintf(buff, ETH_GSTRING_LEN, "onnod%d_tx_pkts", node);
2260 buff = buff + ETH_GSTRING_LEN;
2261
2262 return buff;
2263 }
2264
2265 static u64 *hns_dsaf_get_node_stats(struct dsaf_device *ddev, u64 *data,
2266 int node_num)
2267 {
2268 u64 *p = data;
2269 struct dsaf_hw_stats *hw_stats = &ddev->hw_stats[node_num];
2270
2271 p[0] = hw_stats->pad_drop;
2272 p[1] = hw_stats->man_pkts;
2273 p[2] = hw_stats->rx_pkts;
2274 p[3] = hw_stats->rx_pkt_id;
2275 p[4] = hw_stats->rx_pause_frame;
2276 p[5] = hw_stats->release_buf_num;
2277 p[6] = hw_stats->sbm_drop;
2278 p[7] = hw_stats->crc_false;
2279 p[8] = hw_stats->bp_drop;
2280 p[9] = hw_stats->rslt_drop;
2281 p[10] = hw_stats->local_addr_false;
2282 p[11] = hw_stats->vlan_drop;
2283 p[12] = hw_stats->stp_drop;
2284 p[13] = hw_stats->tx_pkts;
2285
2286 return &p[14];
2287 }
2288
2289 /**
2290 *hns_dsaf_get_stats - get dsaf statistic
2291 *@ddev: dsaf device
2292 *@data:statistic value
2293 *@port: port num
2294 */
2295 void hns_dsaf_get_stats(struct dsaf_device *ddev, u64 *data, int port)
2296 {
2297 u64 *p = data;
2298 int node_num = port;
2299
2300 /* for ge/xge node info */
2301 p = hns_dsaf_get_node_stats(ddev, p, node_num);
2302
2303 /* for ppe node info */
2304 node_num = port + DSAF_PPE_INODE_BASE;
2305 (void)hns_dsaf_get_node_stats(ddev, p, node_num);
2306 }
2307
2308 /**
2309 *hns_dsaf_get_sset_count - get dsaf string set count
2310 *@stringset: type of values in data
2311 *return dsaf string name count
2312 */
2313 int hns_dsaf_get_sset_count(int stringset)
2314 {
2315 if (stringset == ETH_SS_STATS)
2316 return DSAF_STATIC_NUM;
2317
2318 return 0;
2319 }
2320
2321 /**
2322 *hns_dsaf_get_strings - get dsaf string set
2323 *@stringset:srting set index
2324 *@data:strings name value
2325 *@port:port index
2326 */
2327 void hns_dsaf_get_strings(int stringset, u8 *data, int port)
2328 {
2329 char *buff = (char *)data;
2330 int node = port;
2331
2332 if (stringset != ETH_SS_STATS)
2333 return;
2334
2335 /* for ge/xge node info */
2336 buff = hns_dsaf_get_node_stats_strings(buff, node);
2337
2338 /* for ppe node info */
2339 node = port + DSAF_PPE_INODE_BASE;
2340 (void)hns_dsaf_get_node_stats_strings(buff, node);
2341 }
2342
2343 /**
2344 *hns_dsaf_get_sset_count - get dsaf regs count
2345 *return dsaf regs count
2346 */
2347 int hns_dsaf_get_regs_count(void)
2348 {
2349 return DSAF_DUMP_REGS_NUM;
2350 }
2351
2352 /**
2353 * dsaf_probe - probo dsaf dev
2354 * @pdev: dasf platform device
2355 * retuen 0 - success , negative --fail
2356 */
2357 static int hns_dsaf_probe(struct platform_device *pdev)
2358 {
2359 struct dsaf_device *dsaf_dev;
2360 int ret;
2361
2362 dsaf_dev = hns_dsaf_alloc_dev(&pdev->dev, sizeof(struct dsaf_drv_priv));
2363 if (IS_ERR(dsaf_dev)) {
2364 ret = PTR_ERR(dsaf_dev);
2365 dev_err(&pdev->dev,
2366 "dsaf_probe dsaf_alloc_dev failed, ret = %#x!\n", ret);
2367 return ret;
2368 }
2369
2370 ret = hns_dsaf_get_cfg(dsaf_dev);
2371 if (ret)
2372 goto free_dev;
2373
2374 ret = hns_dsaf_init(dsaf_dev);
2375 if (ret)
2376 goto free_cfg;
2377
2378 ret = hns_mac_init(dsaf_dev);
2379 if (ret)
2380 goto uninit_dsaf;
2381
2382 ret = hns_ppe_init(dsaf_dev);
2383 if (ret)
2384 goto uninit_mac;
2385
2386 ret = hns_dsaf_ae_init(dsaf_dev);
2387 if (ret)
2388 goto uninit_ppe;
2389
2390 return 0;
2391
2392 uninit_ppe:
2393 hns_ppe_uninit(dsaf_dev);
2394
2395 uninit_mac:
2396 hns_mac_uninit(dsaf_dev);
2397
2398 uninit_dsaf:
2399 hns_dsaf_free(dsaf_dev);
2400
2401 free_cfg:
2402 hns_dsaf_free_cfg(dsaf_dev);
2403
2404 free_dev:
2405 hns_dsaf_free_dev(dsaf_dev);
2406
2407 return ret;
2408 }
2409
2410 /**
2411 * dsaf_remove - remove dsaf dev
2412 * @pdev: dasf platform device
2413 */
2414 static int hns_dsaf_remove(struct platform_device *pdev)
2415 {
2416 struct dsaf_device *dsaf_dev = dev_get_drvdata(&pdev->dev);
2417
2418 hns_dsaf_ae_uninit(dsaf_dev);
2419
2420 hns_ppe_uninit(dsaf_dev);
2421
2422 hns_mac_uninit(dsaf_dev);
2423
2424 hns_dsaf_free(dsaf_dev);
2425
2426 hns_dsaf_free_cfg(dsaf_dev);
2427
2428 hns_dsaf_free_dev(dsaf_dev);
2429
2430 return 0;
2431 }
2432
2433 static const struct of_device_id g_dsaf_match[] = {
2434 {.compatible = "hisilicon,hns-dsaf-v1"},
2435 {.compatible = "hisilicon,hns-dsaf-v2"},
2436 {}
2437 };
2438
2439 static struct platform_driver g_dsaf_driver = {
2440 .probe = hns_dsaf_probe,
2441 .remove = hns_dsaf_remove,
2442 .driver = {
2443 .name = DSAF_DRV_NAME,
2444 .of_match_table = g_dsaf_match,
2445 },
2446 };
2447
2448 module_platform_driver(g_dsaf_driver);
2449
2450 MODULE_LICENSE("GPL");
2451 MODULE_AUTHOR("Huawei Tech. Co., Ltd.");
2452 MODULE_DESCRIPTION("HNS DSAF driver");
2453 MODULE_VERSION(DSAF_MOD_VERSION);