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/etherdevice.h> 11 #include <linux/netdevice.h> 12 #include <linux/spinlock.h> 13 14 #include "hnae.h" 15 #include "hns_dsaf_mac.h" 16 #include "hns_dsaf_main.h" 17 #include "hns_dsaf_ppe.h" 18 #include "hns_dsaf_rcb.h" 19 20 #define AE_NAME_PORT_ID_IDX 6 21 #define ETH_STATIC_REG 1 22 #define ETH_DUMP_REG 5 23 #define ETH_GSTRING_LEN 32 24 25 static struct hns_mac_cb *hns_get_mac_cb(struct hnae_handle *handle) 26 { 27 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 28 29 return vf_cb->mac_cb; 30 } 31 32 /** 33 * hns_ae_map_eport_to_dport - translate enet port id to dsaf port id 34 * @port_id: enet port id 35 *: debug port 0-1, service port 2 -7 (dsaf mode only 2) 36 * return: dsaf port id 37 *: service ports 0 - 5, debug port 6-7 38 **/ 39 static int hns_ae_map_eport_to_dport(u32 port_id) 40 { 41 int port_index; 42 43 if (port_id < DSAF_DEBUG_NW_NUM) 44 port_index = port_id + DSAF_SERVICE_PORT_NUM_PER_DSAF; 45 else 46 port_index = port_id - DSAF_DEBUG_NW_NUM; 47 48 return port_index; 49 } 50 51 static struct dsaf_device *hns_ae_get_dsaf_dev(struct hnae_ae_dev *dev) 52 { 53 return container_of(dev, struct dsaf_device, ae_dev); 54 } 55 56 static struct hns_ppe_cb *hns_get_ppe_cb(struct hnae_handle *handle) 57 { 58 int ppe_index; 59 int ppe_common_index; 60 struct ppe_common_cb *ppe_comm; 61 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 62 63 if (vf_cb->port_index < DSAF_SERVICE_PORT_NUM_PER_DSAF) { 64 ppe_index = vf_cb->port_index; 65 ppe_common_index = 0; 66 } else { 67 ppe_index = 0; 68 ppe_common_index = 69 vf_cb->port_index - DSAF_SERVICE_PORT_NUM_PER_DSAF + 1; 70 } 71 ppe_comm = vf_cb->dsaf_dev->ppe_common[ppe_common_index]; 72 return &ppe_comm->ppe_cb[ppe_index]; 73 } 74 75 static int hns_ae_get_q_num_per_vf( 76 struct dsaf_device *dsaf_dev, int port) 77 { 78 int common_idx = hns_dsaf_get_comm_idx_by_port(port); 79 80 return dsaf_dev->rcb_common[common_idx]->max_q_per_vf; 81 } 82 83 static int hns_ae_get_vf_num_per_port( 84 struct dsaf_device *dsaf_dev, int port) 85 { 86 int common_idx = hns_dsaf_get_comm_idx_by_port(port); 87 88 return dsaf_dev->rcb_common[common_idx]->max_vfn; 89 } 90 91 static struct ring_pair_cb *hns_ae_get_base_ring_pair( 92 struct dsaf_device *dsaf_dev, int port) 93 { 94 int common_idx = hns_dsaf_get_comm_idx_by_port(port); 95 struct rcb_common_cb *rcb_comm = dsaf_dev->rcb_common[common_idx]; 96 int q_num = rcb_comm->max_q_per_vf; 97 int vf_num = rcb_comm->max_vfn; 98 99 if (common_idx == HNS_DSAF_COMM_SERVICE_NW_IDX) 100 return &rcb_comm->ring_pair_cb[port * q_num * vf_num]; 101 else 102 return &rcb_comm->ring_pair_cb[0]; 103 } 104 105 static struct ring_pair_cb *hns_ae_get_ring_pair(struct hnae_queue *q) 106 { 107 return container_of(q, struct ring_pair_cb, q); 108 } 109 110 struct hnae_handle *hns_ae_get_handle(struct hnae_ae_dev *dev, 111 u32 port_id) 112 { 113 int port_idx; 114 int vfnum_per_port; 115 int qnum_per_vf; 116 int i; 117 struct dsaf_device *dsaf_dev; 118 struct hnae_handle *ae_handle; 119 struct ring_pair_cb *ring_pair_cb; 120 struct hnae_vf_cb *vf_cb; 121 122 dsaf_dev = hns_ae_get_dsaf_dev(dev); 123 port_idx = hns_ae_map_eport_to_dport(port_id); 124 125 ring_pair_cb = hns_ae_get_base_ring_pair(dsaf_dev, port_idx); 126 vfnum_per_port = hns_ae_get_vf_num_per_port(dsaf_dev, port_idx); 127 qnum_per_vf = hns_ae_get_q_num_per_vf(dsaf_dev, port_idx); 128 129 vf_cb = kzalloc(sizeof(*vf_cb) + 130 qnum_per_vf * sizeof(struct hnae_queue *), GFP_KERNEL); 131 if (unlikely(!vf_cb)) { 132 dev_err(dsaf_dev->dev, "malloc vf_cb fail!\n"); 133 ae_handle = ERR_PTR(-ENOMEM); 134 goto handle_err; 135 } 136 ae_handle = &vf_cb->ae_handle; 137 /* ae_handle Init */ 138 ae_handle->owner_dev = dsaf_dev->dev; 139 ae_handle->dev = dev; 140 ae_handle->q_num = qnum_per_vf; 141 142 /* find ring pair, and set vf id*/ 143 for (ae_handle->vf_id = 0; 144 ae_handle->vf_id < vfnum_per_port; ae_handle->vf_id++) { 145 if (!ring_pair_cb->used_by_vf) 146 break; 147 ring_pair_cb += qnum_per_vf; 148 } 149 if (ae_handle->vf_id >= vfnum_per_port) { 150 dev_err(dsaf_dev->dev, "malloc queue fail!\n"); 151 ae_handle = ERR_PTR(-EINVAL); 152 goto vf_id_err; 153 } 154 155 ae_handle->qs = (struct hnae_queue **)(&ae_handle->qs + 1); 156 for (i = 0; i < qnum_per_vf; i++) { 157 ae_handle->qs[i] = &ring_pair_cb->q; 158 ae_handle->qs[i]->rx_ring.q = ae_handle->qs[i]; 159 ae_handle->qs[i]->tx_ring.q = ae_handle->qs[i]; 160 161 ring_pair_cb->used_by_vf = 1; 162 if (port_idx < DSAF_SERVICE_PORT_NUM_PER_DSAF) 163 ring_pair_cb->port_id_in_dsa = port_idx; 164 else 165 ring_pair_cb->port_id_in_dsa = 0; 166 167 ring_pair_cb++; 168 } 169 170 vf_cb->dsaf_dev = dsaf_dev; 171 vf_cb->port_index = port_idx; 172 vf_cb->mac_cb = &dsaf_dev->mac_cb[port_idx]; 173 174 ae_handle->phy_if = vf_cb->mac_cb->phy_if; 175 ae_handle->phy_node = vf_cb->mac_cb->phy_node; 176 ae_handle->if_support = vf_cb->mac_cb->if_support; 177 ae_handle->port_type = vf_cb->mac_cb->mac_type; 178 179 return ae_handle; 180 vf_id_err: 181 kfree(vf_cb); 182 handle_err: 183 return ae_handle; 184 } 185 186 static void hns_ae_put_handle(struct hnae_handle *handle) 187 { 188 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 189 int i; 190 191 vf_cb->mac_cb = NULL; 192 193 kfree(vf_cb); 194 195 for (i = 0; i < handle->q_num; i++) 196 hns_ae_get_ring_pair(handle->qs[i])->used_by_vf = 0; 197 } 198 199 static void hns_ae_ring_enable_all(struct hnae_handle *handle, int val) 200 { 201 int q_num = handle->q_num; 202 int i; 203 204 for (i = 0; i < q_num; i++) 205 hns_rcb_ring_enable_hw(handle->qs[i], val); 206 } 207 208 static void hns_ae_init_queue(struct hnae_queue *q) 209 { 210 struct ring_pair_cb *ring = 211 container_of(q, struct ring_pair_cb, q); 212 213 hns_rcb_init_hw(ring); 214 } 215 216 static void hns_ae_fini_queue(struct hnae_queue *q) 217 { 218 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(q->handle); 219 220 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE) 221 hns_rcb_reset_ring_hw(q); 222 } 223 224 static int hns_ae_set_mac_address(struct hnae_handle *handle, void *p) 225 { 226 int ret; 227 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 228 229 if (!p || !is_valid_ether_addr((const u8 *)p)) { 230 dev_err(handle->owner_dev, "is not valid ether addr !\n"); 231 return -EADDRNOTAVAIL; 232 } 233 234 ret = hns_mac_change_vf_addr(mac_cb, handle->vf_id, p); 235 if (ret != 0) { 236 dev_err(handle->owner_dev, 237 "set_mac_address fail, ret=%d!\n", ret); 238 return ret; 239 } 240 241 return 0; 242 } 243 244 static int hns_ae_set_multicast_one(struct hnae_handle *handle, void *addr) 245 { 246 int ret; 247 char *mac_addr = (char *)addr; 248 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 249 250 assert(mac_cb); 251 252 if (mac_cb->mac_type != HNAE_PORT_SERVICE) 253 return 0; 254 255 ret = hns_mac_set_multi(mac_cb, mac_cb->mac_id, mac_addr, ENABLE); 256 if (ret) { 257 dev_err(handle->owner_dev, 258 "mac add mul_mac:%pM port%d fail, ret = %#x!\n", 259 mac_addr, mac_cb->mac_id, ret); 260 return ret; 261 } 262 263 ret = hns_mac_set_multi(mac_cb, DSAF_BASE_INNER_PORT_NUM, 264 mac_addr, ENABLE); 265 if (ret) 266 dev_err(handle->owner_dev, 267 "mac add mul_mac:%pM port%d fail, ret = %#x!\n", 268 mac_addr, DSAF_BASE_INNER_PORT_NUM, ret); 269 270 return ret; 271 } 272 273 static int hns_ae_set_mtu(struct hnae_handle *handle, int new_mtu) 274 { 275 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 276 277 return hns_mac_set_mtu(mac_cb, new_mtu); 278 } 279 280 static int hns_ae_start(struct hnae_handle *handle) 281 { 282 int ret; 283 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 284 285 ret = hns_mac_vm_config_bc_en(mac_cb, 0, ENABLE); 286 if (ret) 287 return ret; 288 289 hns_ae_ring_enable_all(handle, 1); 290 msleep(100); 291 292 hns_mac_start(mac_cb); 293 294 return 0; 295 } 296 297 void hns_ae_stop(struct hnae_handle *handle) 298 { 299 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 300 301 /* just clean tx fbd, neednot rx fbd*/ 302 hns_rcb_wait_fbd_clean(handle->qs, handle->q_num, RCB_INT_FLAG_TX); 303 304 msleep(20); 305 306 hns_mac_stop(mac_cb); 307 308 usleep_range(10000, 20000); 309 310 hns_ae_ring_enable_all(handle, 0); 311 312 (void)hns_mac_vm_config_bc_en(mac_cb, 0, DISABLE); 313 } 314 315 static void hns_ae_reset(struct hnae_handle *handle) 316 { 317 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 318 319 if (vf_cb->mac_cb->mac_type == HNAE_PORT_DEBUG) { 320 u8 ppe_common_index = 321 vf_cb->port_index - DSAF_SERVICE_PORT_NUM_PER_DSAF + 1; 322 323 hns_mac_reset(vf_cb->mac_cb); 324 hns_ppe_reset_common(vf_cb->dsaf_dev, ppe_common_index); 325 } 326 } 327 328 void hns_ae_toggle_ring_irq(struct hnae_ring *ring, u32 mask) 329 { 330 u32 flag; 331 332 if (is_tx_ring(ring)) 333 flag = RCB_INT_FLAG_TX; 334 else 335 flag = RCB_INT_FLAG_RX; 336 337 hns_rcb_int_clr_hw(ring->q, flag); 338 hns_rcb_int_ctrl_hw(ring->q, flag, mask); 339 } 340 341 static void hns_ae_toggle_queue_status(struct hnae_queue *queue, u32 val) 342 { 343 hns_rcb_start(queue, val); 344 } 345 346 static int hns_ae_get_link_status(struct hnae_handle *handle) 347 { 348 u32 link_status; 349 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 350 351 hns_mac_get_link_status(mac_cb, &link_status); 352 353 return !!link_status; 354 } 355 356 static int hns_ae_get_mac_info(struct hnae_handle *handle, 357 u8 *auto_neg, u16 *speed, u8 *duplex) 358 { 359 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 360 361 return hns_mac_get_port_info(mac_cb, auto_neg, speed, duplex); 362 } 363 364 static void hns_ae_adjust_link(struct hnae_handle *handle, int speed, 365 int duplex) 366 { 367 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 368 369 hns_mac_adjust_link(mac_cb, speed, duplex); 370 } 371 372 static void hns_ae_get_ring_bdnum_limit(struct hnae_queue *queue, 373 u32 *uplimit) 374 { 375 *uplimit = HNS_RCB_RING_MAX_PENDING_BD; 376 } 377 378 static void hns_ae_get_pauseparam(struct hnae_handle *handle, 379 u32 *auto_neg, u32 *rx_en, u32 *tx_en) 380 { 381 assert(handle); 382 383 hns_mac_get_autoneg(hns_get_mac_cb(handle), auto_neg); 384 385 hns_mac_get_pauseparam(hns_get_mac_cb(handle), rx_en, tx_en); 386 } 387 388 static int hns_ae_set_autoneg(struct hnae_handle *handle, u8 enable) 389 { 390 assert(handle); 391 392 return hns_mac_set_autoneg(hns_get_mac_cb(handle), enable); 393 } 394 395 static int hns_ae_get_autoneg(struct hnae_handle *handle) 396 { 397 u32 auto_neg; 398 399 assert(handle); 400 401 hns_mac_get_autoneg(hns_get_mac_cb(handle), &auto_neg); 402 403 return auto_neg; 404 } 405 406 static int hns_ae_set_pauseparam(struct hnae_handle *handle, 407 u32 autoneg, u32 rx_en, u32 tx_en) 408 { 409 struct hns_mac_cb *mac_cb = hns_get_mac_cb(handle); 410 int ret; 411 412 ret = hns_mac_set_autoneg(mac_cb, autoneg); 413 if (ret) 414 return ret; 415 416 return hns_mac_set_pauseparam(mac_cb, rx_en, tx_en); 417 } 418 419 static void hns_ae_get_coalesce_usecs(struct hnae_handle *handle, 420 u32 *tx_usecs, u32 *rx_usecs) 421 { 422 int port; 423 424 port = hns_ae_map_eport_to_dport(handle->eport_id); 425 426 *tx_usecs = hns_rcb_get_coalesce_usecs( 427 hns_ae_get_dsaf_dev(handle->dev), 428 hns_dsaf_get_comm_idx_by_port(port)); 429 *rx_usecs = hns_rcb_get_coalesce_usecs( 430 hns_ae_get_dsaf_dev(handle->dev), 431 hns_dsaf_get_comm_idx_by_port(port)); 432 } 433 434 static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle *handle, 435 u32 *tx_frames, u32 *rx_frames) 436 { 437 int port; 438 439 assert(handle); 440 441 port = hns_ae_map_eport_to_dport(handle->eport_id); 442 443 *tx_frames = hns_rcb_get_coalesced_frames( 444 hns_ae_get_dsaf_dev(handle->dev), port); 445 *rx_frames = hns_rcb_get_coalesced_frames( 446 hns_ae_get_dsaf_dev(handle->dev), port); 447 } 448 449 static void hns_ae_set_coalesce_usecs(struct hnae_handle *handle, 450 u32 timeout) 451 { 452 int port; 453 454 assert(handle); 455 456 port = hns_ae_map_eport_to_dport(handle->eport_id); 457 458 hns_rcb_set_coalesce_usecs(hns_ae_get_dsaf_dev(handle->dev), 459 port, timeout); 460 } 461 462 static int hns_ae_set_coalesce_frames(struct hnae_handle *handle, 463 u32 coalesce_frames) 464 { 465 int port; 466 int ret; 467 468 assert(handle); 469 470 port = hns_ae_map_eport_to_dport(handle->eport_id); 471 472 ret = hns_rcb_set_coalesced_frames(hns_ae_get_dsaf_dev(handle->dev), 473 port, coalesce_frames); 474 return ret; 475 } 476 477 void hns_ae_update_stats(struct hnae_handle *handle, 478 struct net_device_stats *net_stats) 479 { 480 int port; 481 int idx; 482 struct dsaf_device *dsaf_dev; 483 struct hns_mac_cb *mac_cb; 484 struct hns_ppe_cb *ppe_cb; 485 struct hnae_queue *queue; 486 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 487 u64 tx_bytes = 0, rx_bytes = 0, tx_packets = 0, rx_packets = 0; 488 u64 rx_errors = 0, tx_errors = 0, tx_dropped = 0; 489 u64 rx_missed_errors = 0; 490 491 dsaf_dev = hns_ae_get_dsaf_dev(handle->dev); 492 if (!dsaf_dev) 493 return; 494 port = vf_cb->port_index; 495 ppe_cb = hns_get_ppe_cb(handle); 496 mac_cb = hns_get_mac_cb(handle); 497 498 for (idx = 0; idx < handle->q_num; idx++) { 499 queue = handle->qs[idx]; 500 hns_rcb_update_stats(queue); 501 502 tx_bytes += queue->tx_ring.stats.tx_bytes; 503 tx_packets += queue->tx_ring.stats.tx_pkts; 504 rx_bytes += queue->rx_ring.stats.rx_bytes; 505 rx_packets += queue->rx_ring.stats.rx_pkts; 506 507 rx_errors += queue->rx_ring.stats.err_pkt_len 508 + queue->rx_ring.stats.l2_err 509 + queue->rx_ring.stats.l3l4_csum_err; 510 } 511 512 hns_ppe_update_stats(ppe_cb); 513 rx_missed_errors = ppe_cb->hw_stats.rx_drop_no_buf; 514 tx_errors += ppe_cb->hw_stats.tx_err_checksum 515 + ppe_cb->hw_stats.tx_err_fifo_empty; 516 517 if (mac_cb->mac_type == HNAE_PORT_SERVICE) { 518 hns_dsaf_update_stats(dsaf_dev, port); 519 /* for port upline direction, i.e., rx. */ 520 rx_missed_errors += dsaf_dev->hw_stats[port].bp_drop; 521 rx_missed_errors += dsaf_dev->hw_stats[port].pad_drop; 522 rx_missed_errors += dsaf_dev->hw_stats[port].crc_false; 523 524 /* for port downline direction, i.e., tx. */ 525 port = port + DSAF_PPE_INODE_BASE; 526 hns_dsaf_update_stats(dsaf_dev, port); 527 tx_dropped += dsaf_dev->hw_stats[port].bp_drop; 528 tx_dropped += dsaf_dev->hw_stats[port].pad_drop; 529 tx_dropped += dsaf_dev->hw_stats[port].crc_false; 530 tx_dropped += dsaf_dev->hw_stats[port].rslt_drop; 531 tx_dropped += dsaf_dev->hw_stats[port].vlan_drop; 532 tx_dropped += dsaf_dev->hw_stats[port].stp_drop; 533 } 534 535 hns_mac_update_stats(mac_cb); 536 rx_errors += mac_cb->hw_stats.rx_fifo_overrun_err; 537 538 tx_errors += mac_cb->hw_stats.tx_bad_pkts 539 + mac_cb->hw_stats.tx_fragment_err 540 + mac_cb->hw_stats.tx_jabber_err 541 + mac_cb->hw_stats.tx_underrun_err 542 + mac_cb->hw_stats.tx_crc_err; 543 544 net_stats->tx_bytes = tx_bytes; 545 net_stats->tx_packets = tx_packets; 546 net_stats->rx_bytes = rx_bytes; 547 net_stats->rx_dropped = 0; 548 net_stats->rx_packets = rx_packets; 549 net_stats->rx_errors = rx_errors; 550 net_stats->tx_errors = tx_errors; 551 net_stats->tx_dropped = tx_dropped; 552 net_stats->rx_missed_errors = rx_missed_errors; 553 net_stats->rx_crc_errors = mac_cb->hw_stats.rx_fcs_err; 554 net_stats->rx_frame_errors = mac_cb->hw_stats.rx_align_err; 555 net_stats->rx_fifo_errors = mac_cb->hw_stats.rx_fifo_overrun_err; 556 net_stats->rx_length_errors = mac_cb->hw_stats.rx_len_err; 557 net_stats->multicast = mac_cb->hw_stats.rx_mc_pkts; 558 } 559 560 void hns_ae_get_stats(struct hnae_handle *handle, u64 *data) 561 { 562 int idx; 563 struct hns_mac_cb *mac_cb; 564 struct hns_ppe_cb *ppe_cb; 565 u64 *p = data; 566 struct hnae_vf_cb *vf_cb; 567 568 if (!handle || !data) { 569 pr_err("hns_ae_get_stats NULL handle or data pointer!\n"); 570 return; 571 } 572 573 vf_cb = hns_ae_get_vf_cb(handle); 574 mac_cb = hns_get_mac_cb(handle); 575 ppe_cb = hns_get_ppe_cb(handle); 576 577 for (idx = 0; idx < handle->q_num; idx++) { 578 hns_rcb_get_stats(handle->qs[idx], p); 579 p += hns_rcb_get_ring_sset_count((int)ETH_SS_STATS); 580 } 581 582 hns_ppe_get_stats(ppe_cb, p); 583 p += hns_ppe_get_sset_count((int)ETH_SS_STATS); 584 585 hns_mac_get_stats(mac_cb, p); 586 p += hns_mac_get_sset_count(mac_cb, (int)ETH_SS_STATS); 587 588 if (mac_cb->mac_type == HNAE_PORT_SERVICE) 589 hns_dsaf_get_stats(vf_cb->dsaf_dev, p, vf_cb->port_index); 590 } 591 592 void hns_ae_get_strings(struct hnae_handle *handle, 593 u32 stringset, u8 *data) 594 { 595 int port; 596 int idx; 597 struct hns_mac_cb *mac_cb; 598 struct hns_ppe_cb *ppe_cb; 599 u8 *p = data; 600 struct hnae_vf_cb *vf_cb; 601 602 assert(handle); 603 604 vf_cb = hns_ae_get_vf_cb(handle); 605 port = vf_cb->port_index; 606 mac_cb = hns_get_mac_cb(handle); 607 ppe_cb = hns_get_ppe_cb(handle); 608 609 for (idx = 0; idx < handle->q_num; idx++) { 610 hns_rcb_get_strings(stringset, p, idx); 611 p += ETH_GSTRING_LEN * hns_rcb_get_ring_sset_count(stringset); 612 } 613 614 hns_ppe_get_strings(ppe_cb, stringset, p); 615 p += ETH_GSTRING_LEN * hns_ppe_get_sset_count(stringset); 616 617 hns_mac_get_strings(mac_cb, stringset, p); 618 p += ETH_GSTRING_LEN * hns_mac_get_sset_count(mac_cb, stringset); 619 620 if (mac_cb->mac_type == HNAE_PORT_SERVICE) 621 hns_dsaf_get_strings(stringset, p, port); 622 } 623 624 int hns_ae_get_sset_count(struct hnae_handle *handle, int stringset) 625 { 626 u32 sset_count = 0; 627 struct hns_mac_cb *mac_cb; 628 629 assert(handle); 630 631 mac_cb = hns_get_mac_cb(handle); 632 633 sset_count += hns_rcb_get_ring_sset_count(stringset) * handle->q_num; 634 sset_count += hns_ppe_get_sset_count(stringset); 635 sset_count += hns_mac_get_sset_count(mac_cb, stringset); 636 637 if (mac_cb->mac_type == HNAE_PORT_SERVICE) 638 sset_count += hns_dsaf_get_sset_count(stringset); 639 640 return sset_count; 641 } 642 643 static int hns_ae_config_loopback(struct hnae_handle *handle, 644 enum hnae_loop loop, int en) 645 { 646 int ret; 647 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 648 649 switch (loop) { 650 case MAC_INTERNALLOOP_SERDES: 651 ret = hns_mac_config_sds_loopback(vf_cb->mac_cb, en); 652 break; 653 case MAC_INTERNALLOOP_MAC: 654 ret = hns_mac_config_mac_loopback(vf_cb->mac_cb, loop, en); 655 break; 656 default: 657 ret = -EINVAL; 658 } 659 return ret; 660 } 661 662 void hns_ae_update_led_status(struct hnae_handle *handle) 663 { 664 struct hns_mac_cb *mac_cb; 665 666 assert(handle); 667 mac_cb = hns_get_mac_cb(handle); 668 if (!mac_cb->cpld_vaddr) 669 return; 670 hns_set_led_opt(mac_cb); 671 } 672 673 int hns_ae_cpld_set_led_id(struct hnae_handle *handle, 674 enum hnae_led_state status) 675 { 676 struct hns_mac_cb *mac_cb; 677 678 assert(handle); 679 680 mac_cb = hns_get_mac_cb(handle); 681 682 return hns_cpld_led_set_id(mac_cb, status); 683 } 684 685 void hns_ae_get_regs(struct hnae_handle *handle, void *data) 686 { 687 u32 *p = data; 688 u32 rcb_com_idx; 689 int i; 690 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 691 struct hns_ppe_cb *ppe_cb = hns_get_ppe_cb(handle); 692 693 hns_ppe_get_regs(ppe_cb, p); 694 p += hns_ppe_get_regs_count(); 695 696 rcb_com_idx = hns_dsaf_get_comm_idx_by_port(vf_cb->port_index); 697 hns_rcb_get_common_regs(vf_cb->dsaf_dev->rcb_common[rcb_com_idx], p); 698 p += hns_rcb_get_common_regs_count(); 699 700 for (i = 0; i < handle->q_num; i++) { 701 hns_rcb_get_ring_regs(handle->qs[i], p); 702 p += hns_rcb_get_ring_regs_count(); 703 } 704 705 hns_mac_get_regs(vf_cb->mac_cb, p); 706 p += hns_mac_get_regs_count(vf_cb->mac_cb); 707 708 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE) 709 hns_dsaf_get_regs(vf_cb->dsaf_dev, vf_cb->port_index, p); 710 } 711 712 int hns_ae_get_regs_len(struct hnae_handle *handle) 713 { 714 u32 total_num; 715 struct hnae_vf_cb *vf_cb = hns_ae_get_vf_cb(handle); 716 717 total_num = hns_ppe_get_regs_count(); 718 total_num += hns_rcb_get_common_regs_count(); 719 total_num += hns_rcb_get_ring_regs_count() * handle->q_num; 720 total_num += hns_mac_get_regs_count(vf_cb->mac_cb); 721 722 if (vf_cb->mac_cb->mac_type == HNAE_PORT_SERVICE) 723 total_num += hns_dsaf_get_regs_count(); 724 725 return total_num; 726 } 727 728 static struct hnae_ae_ops hns_dsaf_ops = { 729 .get_handle = hns_ae_get_handle, 730 .put_handle = hns_ae_put_handle, 731 .init_queue = hns_ae_init_queue, 732 .fini_queue = hns_ae_fini_queue, 733 .start = hns_ae_start, 734 .stop = hns_ae_stop, 735 .reset = hns_ae_reset, 736 .toggle_ring_irq = hns_ae_toggle_ring_irq, 737 .toggle_queue_status = hns_ae_toggle_queue_status, 738 .get_status = hns_ae_get_link_status, 739 .get_info = hns_ae_get_mac_info, 740 .adjust_link = hns_ae_adjust_link, 741 .set_loopback = hns_ae_config_loopback, 742 .get_ring_bdnum_limit = hns_ae_get_ring_bdnum_limit, 743 .get_pauseparam = hns_ae_get_pauseparam, 744 .set_autoneg = hns_ae_set_autoneg, 745 .get_autoneg = hns_ae_get_autoneg, 746 .set_pauseparam = hns_ae_set_pauseparam, 747 .get_coalesce_usecs = hns_ae_get_coalesce_usecs, 748 .get_rx_max_coalesced_frames = hns_ae_get_rx_max_coalesced_frames, 749 .set_coalesce_usecs = hns_ae_set_coalesce_usecs, 750 .set_coalesce_frames = hns_ae_set_coalesce_frames, 751 .set_mac_addr = hns_ae_set_mac_address, 752 .set_mc_addr = hns_ae_set_multicast_one, 753 .set_mtu = hns_ae_set_mtu, 754 .update_stats = hns_ae_update_stats, 755 .get_stats = hns_ae_get_stats, 756 .get_strings = hns_ae_get_strings, 757 .get_sset_count = hns_ae_get_sset_count, 758 .update_led_status = hns_ae_update_led_status, 759 .set_led_id = hns_ae_cpld_set_led_id, 760 .get_regs = hns_ae_get_regs, 761 .get_regs_len = hns_ae_get_regs_len 762 }; 763 764 int hns_dsaf_ae_init(struct dsaf_device *dsaf_dev) 765 { 766 struct hnae_ae_dev *ae_dev = &dsaf_dev->ae_dev; 767 768 ae_dev->ops = &hns_dsaf_ops; 769 ae_dev->dev = dsaf_dev->dev; 770 771 return hnae_ae_register(ae_dev, THIS_MODULE); 772 } 773 774 void hns_dsaf_ae_uninit(struct dsaf_device *dsaf_dev) 775 { 776 hnae_ae_unregister(&dsaf_dev->ae_dev); 777 } 778