2 * Copyright (c) 2014-2015 Hisilicon Limited.
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.
10 #include <linux/etherdevice.h>
11 #include <linux/netdevice.h>
12 #include <linux/spinlock.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"
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
25 static struct hns_mac_cb
*hns_get_mac_cb(struct hnae_handle
*handle
)
27 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
32 static struct dsaf_device
*hns_ae_get_dsaf_dev(struct hnae_ae_dev
*dev
)
34 return container_of(dev
, struct dsaf_device
, ae_dev
);
37 static struct hns_ppe_cb
*hns_get_ppe_cb(struct hnae_handle
*handle
)
40 struct ppe_common_cb
*ppe_comm
;
41 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
43 ppe_comm
= vf_cb
->dsaf_dev
->ppe_common
[0];
44 ppe_index
= vf_cb
->port_index
;
46 return &ppe_comm
->ppe_cb
[ppe_index
];
49 static int hns_ae_get_q_num_per_vf(
50 struct dsaf_device
*dsaf_dev
, int port
)
52 return dsaf_dev
->rcb_common
[0]->max_q_per_vf
;
55 static int hns_ae_get_vf_num_per_port(
56 struct dsaf_device
*dsaf_dev
, int port
)
58 return dsaf_dev
->rcb_common
[0]->max_vfn
;
61 static struct ring_pair_cb
*hns_ae_get_base_ring_pair(
62 struct dsaf_device
*dsaf_dev
, int port
)
64 struct rcb_common_cb
*rcb_comm
= dsaf_dev
->rcb_common
[0];
65 int q_num
= rcb_comm
->max_q_per_vf
;
66 int vf_num
= rcb_comm
->max_vfn
;
68 return &rcb_comm
->ring_pair_cb
[port
* q_num
* vf_num
];
71 static struct ring_pair_cb
*hns_ae_get_ring_pair(struct hnae_queue
*q
)
73 return container_of(q
, struct ring_pair_cb
, q
);
76 struct hnae_handle
*hns_ae_get_handle(struct hnae_ae_dev
*dev
,
82 struct dsaf_device
*dsaf_dev
;
83 struct hnae_handle
*ae_handle
;
84 struct ring_pair_cb
*ring_pair_cb
;
85 struct hnae_vf_cb
*vf_cb
;
87 dsaf_dev
= hns_ae_get_dsaf_dev(dev
);
89 ring_pair_cb
= hns_ae_get_base_ring_pair(dsaf_dev
, port_id
);
90 vfnum_per_port
= hns_ae_get_vf_num_per_port(dsaf_dev
, port_id
);
91 qnum_per_vf
= hns_ae_get_q_num_per_vf(dsaf_dev
, port_id
);
93 vf_cb
= kzalloc(sizeof(*vf_cb
) +
94 qnum_per_vf
* sizeof(struct hnae_queue
*), GFP_KERNEL
);
95 if (unlikely(!vf_cb
)) {
96 dev_err(dsaf_dev
->dev
, "malloc vf_cb fail!\n");
97 ae_handle
= ERR_PTR(-ENOMEM
);
100 ae_handle
= &vf_cb
->ae_handle
;
102 ae_handle
->owner_dev
= dsaf_dev
->dev
;
103 ae_handle
->dev
= dev
;
104 ae_handle
->q_num
= qnum_per_vf
;
106 /* find ring pair, and set vf id*/
107 for (ae_handle
->vf_id
= 0;
108 ae_handle
->vf_id
< vfnum_per_port
; ae_handle
->vf_id
++) {
109 if (!ring_pair_cb
->used_by_vf
)
111 ring_pair_cb
+= qnum_per_vf
;
113 if (ae_handle
->vf_id
>= vfnum_per_port
) {
114 dev_err(dsaf_dev
->dev
, "malloc queue fail!\n");
115 ae_handle
= ERR_PTR(-EINVAL
);
119 ae_handle
->qs
= (struct hnae_queue
**)(&ae_handle
->qs
+ 1);
120 for (i
= 0; i
< qnum_per_vf
; i
++) {
121 ae_handle
->qs
[i
] = &ring_pair_cb
->q
;
122 ae_handle
->qs
[i
]->rx_ring
.q
= ae_handle
->qs
[i
];
123 ae_handle
->qs
[i
]->tx_ring
.q
= ae_handle
->qs
[i
];
125 ring_pair_cb
->used_by_vf
= 1;
129 vf_cb
->dsaf_dev
= dsaf_dev
;
130 vf_cb
->port_index
= port_id
;
131 vf_cb
->mac_cb
= dsaf_dev
->mac_cb
[port_id
];
133 ae_handle
->phy_if
= vf_cb
->mac_cb
->phy_if
;
134 ae_handle
->phy_dev
= vf_cb
->mac_cb
->phy_dev
;
135 ae_handle
->if_support
= vf_cb
->mac_cb
->if_support
;
136 ae_handle
->port_type
= vf_cb
->mac_cb
->mac_type
;
137 ae_handle
->dport_id
= port_id
;
146 static void hns_ae_put_handle(struct hnae_handle
*handle
)
148 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
151 vf_cb
->mac_cb
= NULL
;
155 for (i
= 0; i
< handle
->q_num
; i
++)
156 hns_ae_get_ring_pair(handle
->qs
[i
])->used_by_vf
= 0;
159 static void hns_ae_ring_enable_all(struct hnae_handle
*handle
, int val
)
161 int q_num
= handle
->q_num
;
164 for (i
= 0; i
< q_num
; i
++)
165 hns_rcb_ring_enable_hw(handle
->qs
[i
], val
);
168 static void hns_ae_init_queue(struct hnae_queue
*q
)
170 struct ring_pair_cb
*ring
=
171 container_of(q
, struct ring_pair_cb
, q
);
173 hns_rcb_init_hw(ring
);
176 static void hns_ae_fini_queue(struct hnae_queue
*q
)
178 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(q
->handle
);
180 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
181 hns_rcb_reset_ring_hw(q
);
184 static int hns_ae_set_mac_address(struct hnae_handle
*handle
, void *p
)
187 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
189 if (!p
|| !is_valid_ether_addr((const u8
*)p
)) {
190 dev_err(handle
->owner_dev
, "is not valid ether addr !\n");
191 return -EADDRNOTAVAIL
;
194 ret
= hns_mac_change_vf_addr(mac_cb
, handle
->vf_id
, p
);
196 dev_err(handle
->owner_dev
,
197 "set_mac_address fail, ret=%d!\n", ret
);
204 static int hns_ae_set_multicast_one(struct hnae_handle
*handle
, void *addr
)
207 char *mac_addr
= (char *)addr
;
208 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
212 if (mac_cb
->mac_type
!= HNAE_PORT_SERVICE
)
215 ret
= hns_mac_set_multi(mac_cb
, mac_cb
->mac_id
, mac_addr
, true);
217 dev_err(handle
->owner_dev
,
218 "mac add mul_mac:%pM port%d fail, ret = %#x!\n",
219 mac_addr
, mac_cb
->mac_id
, ret
);
223 ret
= hns_mac_set_multi(mac_cb
, DSAF_BASE_INNER_PORT_NUM
,
226 dev_err(handle
->owner_dev
,
227 "mac add mul_mac:%pM port%d fail, ret = %#x!\n",
228 mac_addr
, DSAF_BASE_INNER_PORT_NUM
, ret
);
233 static int hns_ae_set_mtu(struct hnae_handle
*handle
, int new_mtu
)
235 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
237 return hns_mac_set_mtu(mac_cb
, new_mtu
);
240 static void hns_ae_set_tso_stats(struct hnae_handle
*handle
, int enable
)
242 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
244 hns_ppe_set_tso_enable(ppe_cb
, enable
);
247 static int hns_ae_start(struct hnae_handle
*handle
)
250 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
252 ret
= hns_mac_vm_config_bc_en(mac_cb
, 0, true);
256 hns_ae_ring_enable_all(handle
, 1);
259 hns_mac_start(mac_cb
);
264 void hns_ae_stop(struct hnae_handle
*handle
)
266 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
268 /* just clean tx fbd, neednot rx fbd*/
269 hns_rcb_wait_fbd_clean(handle
->qs
, handle
->q_num
, RCB_INT_FLAG_TX
);
273 hns_mac_stop(mac_cb
);
275 usleep_range(10000, 20000);
277 hns_ae_ring_enable_all(handle
, 0);
279 (void)hns_mac_vm_config_bc_en(mac_cb
, 0, false);
282 static void hns_ae_reset(struct hnae_handle
*handle
)
284 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
286 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_DEBUG
) {
287 hns_mac_reset(vf_cb
->mac_cb
);
288 hns_ppe_reset_common(vf_cb
->dsaf_dev
, 0);
292 void hns_ae_toggle_ring_irq(struct hnae_ring
*ring
, u32 mask
)
296 if (is_tx_ring(ring
))
297 flag
= RCB_INT_FLAG_TX
;
299 flag
= RCB_INT_FLAG_RX
;
301 hns_rcb_int_ctrl_hw(ring
->q
, flag
, mask
);
304 static void hns_aev2_toggle_ring_irq(struct hnae_ring
*ring
, u32 mask
)
308 if (is_tx_ring(ring
))
309 flag
= RCB_INT_FLAG_TX
;
311 flag
= RCB_INT_FLAG_RX
;
313 hns_rcbv2_int_ctrl_hw(ring
->q
, flag
, mask
);
316 static void hns_ae_toggle_queue_status(struct hnae_queue
*queue
, u32 val
)
318 struct dsaf_device
*dsaf_dev
= hns_ae_get_dsaf_dev(queue
->dev
);
320 if (AE_IS_VER1(dsaf_dev
->dsaf_ver
))
321 hns_rcb_int_clr_hw(queue
, RCB_INT_FLAG_TX
| RCB_INT_FLAG_RX
);
323 hns_rcbv2_int_clr_hw(queue
, RCB_INT_FLAG_TX
| RCB_INT_FLAG_RX
);
325 hns_rcb_start(queue
, val
);
328 static int hns_ae_get_link_status(struct hnae_handle
*handle
)
331 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
333 hns_mac_get_link_status(mac_cb
, &link_status
);
335 return !!link_status
;
338 static int hns_ae_get_mac_info(struct hnae_handle
*handle
,
339 u8
*auto_neg
, u16
*speed
, u8
*duplex
)
341 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
343 return hns_mac_get_port_info(mac_cb
, auto_neg
, speed
, duplex
);
346 static void hns_ae_adjust_link(struct hnae_handle
*handle
, int speed
,
349 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
351 hns_mac_adjust_link(mac_cb
, speed
, duplex
);
354 static void hns_ae_get_ring_bdnum_limit(struct hnae_queue
*queue
,
357 *uplimit
= HNS_RCB_RING_MAX_PENDING_BD
;
360 static void hns_ae_get_pauseparam(struct hnae_handle
*handle
,
361 u32
*auto_neg
, u32
*rx_en
, u32
*tx_en
)
363 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
364 struct dsaf_device
*dsaf_dev
= mac_cb
->dsaf_dev
;
366 hns_mac_get_autoneg(mac_cb
, auto_neg
);
368 hns_mac_get_pauseparam(mac_cb
, rx_en
, tx_en
);
370 /* Service port's pause feature is provided by DSAF, not mac */
371 if (handle
->port_type
== HNAE_PORT_SERVICE
)
372 hns_dsaf_get_rx_mac_pause_en(dsaf_dev
, mac_cb
->mac_id
, rx_en
);
375 static int hns_ae_set_autoneg(struct hnae_handle
*handle
, u8 enable
)
379 return hns_mac_set_autoneg(hns_get_mac_cb(handle
), enable
);
382 static void hns_ae_set_promisc_mode(struct hnae_handle
*handle
, u32 en
)
384 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
386 hns_dsaf_set_promisc_mode(hns_ae_get_dsaf_dev(handle
->dev
), en
);
387 hns_mac_set_promisc(mac_cb
, (u8
)!!en
);
390 static int hns_ae_get_autoneg(struct hnae_handle
*handle
)
396 hns_mac_get_autoneg(hns_get_mac_cb(handle
), &auto_neg
);
401 static int hns_ae_set_pauseparam(struct hnae_handle
*handle
,
402 u32 autoneg
, u32 rx_en
, u32 tx_en
)
404 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
405 struct dsaf_device
*dsaf_dev
= mac_cb
->dsaf_dev
;
408 ret
= hns_mac_set_autoneg(mac_cb
, autoneg
);
412 /* Service port's pause feature is provided by DSAF, not mac */
413 if (handle
->port_type
== HNAE_PORT_SERVICE
) {
414 ret
= hns_dsaf_set_rx_mac_pause_en(dsaf_dev
,
415 mac_cb
->mac_id
, rx_en
);
420 return hns_mac_set_pauseparam(mac_cb
, rx_en
, tx_en
);
423 static void hns_ae_get_coalesce_usecs(struct hnae_handle
*handle
,
424 u32
*tx_usecs
, u32
*rx_usecs
)
426 struct ring_pair_cb
*ring_pair
=
427 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
429 *tx_usecs
= hns_rcb_get_coalesce_usecs(ring_pair
->rcb_common
,
430 ring_pair
->port_id_in_comm
);
431 *rx_usecs
= hns_rcb_get_coalesce_usecs(ring_pair
->rcb_common
,
432 ring_pair
->port_id_in_comm
);
435 static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle
*handle
,
436 u32
*tx_frames
, u32
*rx_frames
)
438 struct ring_pair_cb
*ring_pair
=
439 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
441 *tx_frames
= hns_rcb_get_coalesced_frames(ring_pair
->rcb_common
,
442 ring_pair
->port_id_in_comm
);
443 *rx_frames
= hns_rcb_get_coalesced_frames(ring_pair
->rcb_common
,
444 ring_pair
->port_id_in_comm
);
447 static int hns_ae_set_coalesce_usecs(struct hnae_handle
*handle
,
450 struct ring_pair_cb
*ring_pair
=
451 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
453 return hns_rcb_set_coalesce_usecs(
454 ring_pair
->rcb_common
, ring_pair
->port_id_in_comm
, timeout
);
457 static int hns_ae_set_coalesce_frames(struct hnae_handle
*handle
,
460 struct ring_pair_cb
*ring_pair
=
461 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
463 return hns_rcb_set_coalesced_frames(
464 ring_pair
->rcb_common
,
465 ring_pair
->port_id_in_comm
, coalesce_frames
);
468 static void hns_ae_get_coalesce_range(struct hnae_handle
*handle
,
469 u32
*tx_frames_low
, u32
*rx_frames_low
,
470 u32
*tx_frames_high
, u32
*rx_frames_high
,
471 u32
*tx_usecs_low
, u32
*rx_usecs_low
,
472 u32
*tx_usecs_high
, u32
*rx_usecs_high
)
474 struct dsaf_device
*dsaf_dev
;
476 dsaf_dev
= hns_ae_get_dsaf_dev(handle
->dev
);
478 *tx_frames_low
= HNS_RCB_MIN_COALESCED_FRAMES
;
479 *rx_frames_low
= HNS_RCB_MIN_COALESCED_FRAMES
;
481 (dsaf_dev
->desc_num
- 1 > HNS_RCB_MAX_COALESCED_FRAMES
) ?
482 HNS_RCB_MAX_COALESCED_FRAMES
: dsaf_dev
->desc_num
- 1;
484 (dsaf_dev
->desc_num
- 1 > HNS_RCB_MAX_COALESCED_FRAMES
) ?
485 HNS_RCB_MAX_COALESCED_FRAMES
: dsaf_dev
->desc_num
- 1;
488 *tx_usecs_high
= HNS_RCB_MAX_COALESCED_USECS
;
489 *rx_usecs_high
= HNS_RCB_MAX_COALESCED_USECS
;
492 void hns_ae_update_stats(struct hnae_handle
*handle
,
493 struct net_device_stats
*net_stats
)
497 struct dsaf_device
*dsaf_dev
;
498 struct hns_mac_cb
*mac_cb
;
499 struct hns_ppe_cb
*ppe_cb
;
500 struct hnae_queue
*queue
;
501 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
502 u64 tx_bytes
= 0, rx_bytes
= 0, tx_packets
= 0, rx_packets
= 0;
503 u64 rx_errors
= 0, tx_errors
= 0, tx_dropped
= 0;
504 u64 rx_missed_errors
= 0;
506 dsaf_dev
= hns_ae_get_dsaf_dev(handle
->dev
);
509 port
= vf_cb
->port_index
;
510 ppe_cb
= hns_get_ppe_cb(handle
);
511 mac_cb
= hns_get_mac_cb(handle
);
513 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
514 queue
= handle
->qs
[idx
];
515 hns_rcb_update_stats(queue
);
517 tx_bytes
+= queue
->tx_ring
.stats
.tx_bytes
;
518 tx_packets
+= queue
->tx_ring
.stats
.tx_pkts
;
519 rx_bytes
+= queue
->rx_ring
.stats
.rx_bytes
;
520 rx_packets
+= queue
->rx_ring
.stats
.rx_pkts
;
522 rx_errors
+= queue
->rx_ring
.stats
.err_pkt_len
523 + queue
->rx_ring
.stats
.l2_err
524 + queue
->rx_ring
.stats
.l3l4_csum_err
;
527 hns_ppe_update_stats(ppe_cb
);
528 rx_missed_errors
= ppe_cb
->hw_stats
.rx_drop_no_buf
;
529 tx_errors
+= ppe_cb
->hw_stats
.tx_err_checksum
530 + ppe_cb
->hw_stats
.tx_err_fifo_empty
;
532 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
) {
533 hns_dsaf_update_stats(dsaf_dev
, port
);
534 /* for port upline direction, i.e., rx. */
535 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].bp_drop
;
536 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].pad_drop
;
537 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].crc_false
;
539 /* for port downline direction, i.e., tx. */
540 port
= port
+ DSAF_PPE_INODE_BASE
;
541 hns_dsaf_update_stats(dsaf_dev
, port
);
542 tx_dropped
+= dsaf_dev
->hw_stats
[port
].bp_drop
;
543 tx_dropped
+= dsaf_dev
->hw_stats
[port
].pad_drop
;
544 tx_dropped
+= dsaf_dev
->hw_stats
[port
].crc_false
;
545 tx_dropped
+= dsaf_dev
->hw_stats
[port
].rslt_drop
;
546 tx_dropped
+= dsaf_dev
->hw_stats
[port
].vlan_drop
;
547 tx_dropped
+= dsaf_dev
->hw_stats
[port
].stp_drop
;
550 hns_mac_update_stats(mac_cb
);
551 rx_errors
+= mac_cb
->hw_stats
.rx_fifo_overrun_err
;
553 tx_errors
+= mac_cb
->hw_stats
.tx_bad_pkts
554 + mac_cb
->hw_stats
.tx_fragment_err
555 + mac_cb
->hw_stats
.tx_jabber_err
556 + mac_cb
->hw_stats
.tx_underrun_err
557 + mac_cb
->hw_stats
.tx_crc_err
;
559 net_stats
->tx_bytes
= tx_bytes
;
560 net_stats
->tx_packets
= tx_packets
;
561 net_stats
->rx_bytes
= rx_bytes
;
562 net_stats
->rx_dropped
= 0;
563 net_stats
->rx_packets
= rx_packets
;
564 net_stats
->rx_errors
= rx_errors
;
565 net_stats
->tx_errors
= tx_errors
;
566 net_stats
->tx_dropped
= tx_dropped
;
567 net_stats
->rx_missed_errors
= rx_missed_errors
;
568 net_stats
->rx_crc_errors
= mac_cb
->hw_stats
.rx_fcs_err
;
569 net_stats
->rx_frame_errors
= mac_cb
->hw_stats
.rx_align_err
;
570 net_stats
->rx_fifo_errors
= mac_cb
->hw_stats
.rx_fifo_overrun_err
;
571 net_stats
->rx_length_errors
= mac_cb
->hw_stats
.rx_len_err
;
572 net_stats
->multicast
= mac_cb
->hw_stats
.rx_mc_pkts
;
575 void hns_ae_get_stats(struct hnae_handle
*handle
, u64
*data
)
578 struct hns_mac_cb
*mac_cb
;
579 struct hns_ppe_cb
*ppe_cb
;
581 struct hnae_vf_cb
*vf_cb
;
583 if (!handle
|| !data
) {
584 pr_err("hns_ae_get_stats NULL handle or data pointer!\n");
588 vf_cb
= hns_ae_get_vf_cb(handle
);
589 mac_cb
= hns_get_mac_cb(handle
);
590 ppe_cb
= hns_get_ppe_cb(handle
);
592 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
593 hns_rcb_get_stats(handle
->qs
[idx
], p
);
594 p
+= hns_rcb_get_ring_sset_count((int)ETH_SS_STATS
);
597 hns_ppe_get_stats(ppe_cb
, p
);
598 p
+= hns_ppe_get_sset_count((int)ETH_SS_STATS
);
600 hns_mac_get_stats(mac_cb
, p
);
601 p
+= hns_mac_get_sset_count(mac_cb
, (int)ETH_SS_STATS
);
603 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
604 hns_dsaf_get_stats(vf_cb
->dsaf_dev
, p
, vf_cb
->port_index
);
607 void hns_ae_get_strings(struct hnae_handle
*handle
,
608 u32 stringset
, u8
*data
)
612 struct hns_mac_cb
*mac_cb
;
613 struct hns_ppe_cb
*ppe_cb
;
614 struct dsaf_device
*dsaf_dev
= hns_ae_get_dsaf_dev(handle
->dev
);
616 struct hnae_vf_cb
*vf_cb
;
620 vf_cb
= hns_ae_get_vf_cb(handle
);
621 port
= vf_cb
->port_index
;
622 mac_cb
= hns_get_mac_cb(handle
);
623 ppe_cb
= hns_get_ppe_cb(handle
);
625 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
626 hns_rcb_get_strings(stringset
, p
, idx
);
627 p
+= ETH_GSTRING_LEN
* hns_rcb_get_ring_sset_count(stringset
);
630 hns_ppe_get_strings(ppe_cb
, stringset
, p
);
631 p
+= ETH_GSTRING_LEN
* hns_ppe_get_sset_count(stringset
);
633 hns_mac_get_strings(mac_cb
, stringset
, p
);
634 p
+= ETH_GSTRING_LEN
* hns_mac_get_sset_count(mac_cb
, stringset
);
636 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
637 hns_dsaf_get_strings(stringset
, p
, port
, dsaf_dev
);
640 int hns_ae_get_sset_count(struct hnae_handle
*handle
, int stringset
)
643 struct hns_mac_cb
*mac_cb
;
644 struct dsaf_device
*dsaf_dev
= hns_ae_get_dsaf_dev(handle
->dev
);
648 mac_cb
= hns_get_mac_cb(handle
);
650 sset_count
+= hns_rcb_get_ring_sset_count(stringset
) * handle
->q_num
;
651 sset_count
+= hns_ppe_get_sset_count(stringset
);
652 sset_count
+= hns_mac_get_sset_count(mac_cb
, stringset
);
654 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
655 sset_count
+= hns_dsaf_get_sset_count(dsaf_dev
, stringset
);
660 static int hns_ae_config_loopback(struct hnae_handle
*handle
,
661 enum hnae_loop loop
, int en
)
664 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
665 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
666 struct dsaf_device
*dsaf_dev
= mac_cb
->dsaf_dev
;
669 case MAC_INTERNALLOOP_PHY
:
672 case MAC_INTERNALLOOP_SERDES
:
673 ret
= dsaf_dev
->misc_op
->cfg_serdes_loopback(vf_cb
->mac_cb
,
676 case MAC_INTERNALLOOP_MAC
:
677 ret
= hns_mac_config_mac_loopback(vf_cb
->mac_cb
, loop
, en
);
684 hns_dsaf_set_inner_lb(mac_cb
->dsaf_dev
, mac_cb
->mac_id
, en
);
689 void hns_ae_update_led_status(struct hnae_handle
*handle
)
691 struct hns_mac_cb
*mac_cb
;
694 mac_cb
= hns_get_mac_cb(handle
);
695 if (!mac_cb
->cpld_ctrl
)
697 hns_set_led_opt(mac_cb
);
700 int hns_ae_cpld_set_led_id(struct hnae_handle
*handle
,
701 enum hnae_led_state status
)
703 struct hns_mac_cb
*mac_cb
;
707 mac_cb
= hns_get_mac_cb(handle
);
709 return hns_cpld_led_set_id(mac_cb
, status
);
712 void hns_ae_get_regs(struct hnae_handle
*handle
, void *data
)
716 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
717 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
719 hns_ppe_get_regs(ppe_cb
, p
);
720 p
+= hns_ppe_get_regs_count();
722 hns_rcb_get_common_regs(vf_cb
->dsaf_dev
->rcb_common
[0], p
);
723 p
+= hns_rcb_get_common_regs_count();
725 for (i
= 0; i
< handle
->q_num
; i
++) {
726 hns_rcb_get_ring_regs(handle
->qs
[i
], p
);
727 p
+= hns_rcb_get_ring_regs_count();
730 hns_mac_get_regs(vf_cb
->mac_cb
, p
);
731 p
+= hns_mac_get_regs_count(vf_cb
->mac_cb
);
733 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
734 hns_dsaf_get_regs(vf_cb
->dsaf_dev
, vf_cb
->port_index
, p
);
737 int hns_ae_get_regs_len(struct hnae_handle
*handle
)
740 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
742 total_num
= hns_ppe_get_regs_count();
743 total_num
+= hns_rcb_get_common_regs_count();
744 total_num
+= hns_rcb_get_ring_regs_count() * handle
->q_num
;
745 total_num
+= hns_mac_get_regs_count(vf_cb
->mac_cb
);
747 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
748 total_num
+= hns_dsaf_get_regs_count();
753 static u32
hns_ae_get_rss_key_size(struct hnae_handle
*handle
)
755 return HNS_PPEV2_RSS_KEY_SIZE
;
758 static u32
hns_ae_get_rss_indir_size(struct hnae_handle
*handle
)
760 return HNS_PPEV2_RSS_IND_TBL_SIZE
;
763 static int hns_ae_get_rss(struct hnae_handle
*handle
, u32
*indir
, u8
*key
,
766 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
768 /* currently we support only one type of hash function i.e. Toep hash */
770 *hfunc
= ETH_RSS_HASH_TOP
;
772 /* get the RSS Key required by the user */
774 memcpy(key
, ppe_cb
->rss_key
, HNS_PPEV2_RSS_KEY_SIZE
);
776 /* update the current hash->queue mappings from the shadow RSS table */
777 memcpy(indir
, ppe_cb
->rss_indir_table
,
778 HNS_PPEV2_RSS_IND_TBL_SIZE
* sizeof(*indir
));
783 static int hns_ae_set_rss(struct hnae_handle
*handle
, const u32
*indir
,
784 const u8
*key
, const u8 hfunc
)
786 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
788 /* set the RSS Hash Key if specififed by the user */
790 hns_ppe_set_rss_key(ppe_cb
, (u32
*)key
);
792 /* update the shadow RSS table with user specified qids */
793 memcpy(ppe_cb
->rss_indir_table
, indir
,
794 HNS_PPEV2_RSS_IND_TBL_SIZE
* sizeof(*indir
));
796 /* now update the hardware */
797 hns_ppe_set_indir_table(ppe_cb
, ppe_cb
->rss_indir_table
);
802 static struct hnae_ae_ops hns_dsaf_ops
= {
803 .get_handle
= hns_ae_get_handle
,
804 .put_handle
= hns_ae_put_handle
,
805 .init_queue
= hns_ae_init_queue
,
806 .fini_queue
= hns_ae_fini_queue
,
807 .start
= hns_ae_start
,
809 .reset
= hns_ae_reset
,
810 .toggle_ring_irq
= hns_ae_toggle_ring_irq
,
811 .toggle_queue_status
= hns_ae_toggle_queue_status
,
812 .get_status
= hns_ae_get_link_status
,
813 .get_info
= hns_ae_get_mac_info
,
814 .adjust_link
= hns_ae_adjust_link
,
815 .set_loopback
= hns_ae_config_loopback
,
816 .get_ring_bdnum_limit
= hns_ae_get_ring_bdnum_limit
,
817 .get_pauseparam
= hns_ae_get_pauseparam
,
818 .set_autoneg
= hns_ae_set_autoneg
,
819 .get_autoneg
= hns_ae_get_autoneg
,
820 .set_pauseparam
= hns_ae_set_pauseparam
,
821 .get_coalesce_usecs
= hns_ae_get_coalesce_usecs
,
822 .get_rx_max_coalesced_frames
= hns_ae_get_rx_max_coalesced_frames
,
823 .set_coalesce_usecs
= hns_ae_set_coalesce_usecs
,
824 .set_coalesce_frames
= hns_ae_set_coalesce_frames
,
825 .get_coalesce_range
= hns_ae_get_coalesce_range
,
826 .set_promisc_mode
= hns_ae_set_promisc_mode
,
827 .set_mac_addr
= hns_ae_set_mac_address
,
828 .set_mc_addr
= hns_ae_set_multicast_one
,
829 .set_mtu
= hns_ae_set_mtu
,
830 .update_stats
= hns_ae_update_stats
,
831 .set_tso_stats
= hns_ae_set_tso_stats
,
832 .get_stats
= hns_ae_get_stats
,
833 .get_strings
= hns_ae_get_strings
,
834 .get_sset_count
= hns_ae_get_sset_count
,
835 .update_led_status
= hns_ae_update_led_status
,
836 .set_led_id
= hns_ae_cpld_set_led_id
,
837 .get_regs
= hns_ae_get_regs
,
838 .get_regs_len
= hns_ae_get_regs_len
,
839 .get_rss_key_size
= hns_ae_get_rss_key_size
,
840 .get_rss_indir_size
= hns_ae_get_rss_indir_size
,
841 .get_rss
= hns_ae_get_rss
,
842 .set_rss
= hns_ae_set_rss
845 int hns_dsaf_ae_init(struct dsaf_device
*dsaf_dev
)
847 struct hnae_ae_dev
*ae_dev
= &dsaf_dev
->ae_dev
;
848 static atomic_t id
= ATOMIC_INIT(-1);
850 switch (dsaf_dev
->dsaf_ver
) {
852 hns_dsaf_ops
.toggle_ring_irq
= hns_ae_toggle_ring_irq
;
855 hns_dsaf_ops
.toggle_ring_irq
= hns_aev2_toggle_ring_irq
;
861 snprintf(ae_dev
->name
, AE_NAME_SIZE
, "%s%d", DSAF_DEVICE_NAME
,
862 (int)atomic_inc_return(&id
));
863 ae_dev
->ops
= &hns_dsaf_ops
;
864 ae_dev
->dev
= dsaf_dev
->dev
;
866 return hnae_ae_register(ae_dev
, THIS_MODULE
);
869 void hns_dsaf_ae_uninit(struct dsaf_device
*dsaf_dev
)
871 hnae_ae_unregister(&dsaf_dev
->ae_dev
);