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