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
);
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
39 static int hns_ae_map_eport_to_dport(u32 port_id
)
43 if (port_id
< DSAF_DEBUG_NW_NUM
)
44 port_index
= port_id
+ DSAF_SERVICE_PORT_NUM_PER_DSAF
;
46 port_index
= port_id
- DSAF_DEBUG_NW_NUM
;
51 static struct dsaf_device
*hns_ae_get_dsaf_dev(struct hnae_ae_dev
*dev
)
53 return container_of(dev
, struct dsaf_device
, ae_dev
);
56 static struct hns_ppe_cb
*hns_get_ppe_cb(struct hnae_handle
*handle
)
60 struct ppe_common_cb
*ppe_comm
;
61 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
63 if (vf_cb
->port_index
< DSAF_SERVICE_PORT_NUM_PER_DSAF
) {
64 ppe_index
= vf_cb
->port_index
;
69 vf_cb
->port_index
- DSAF_SERVICE_PORT_NUM_PER_DSAF
+ 1;
71 ppe_comm
= vf_cb
->dsaf_dev
->ppe_common
[ppe_common_index
];
72 return &ppe_comm
->ppe_cb
[ppe_index
];
75 static int hns_ae_get_q_num_per_vf(
76 struct dsaf_device
*dsaf_dev
, int port
)
78 int common_idx
= hns_dsaf_get_comm_idx_by_port(port
);
80 return dsaf_dev
->rcb_common
[common_idx
]->max_q_per_vf
;
83 static int hns_ae_get_vf_num_per_port(
84 struct dsaf_device
*dsaf_dev
, int port
)
86 int common_idx
= hns_dsaf_get_comm_idx_by_port(port
);
88 return dsaf_dev
->rcb_common
[common_idx
]->max_vfn
;
91 static struct ring_pair_cb
*hns_ae_get_base_ring_pair(
92 struct dsaf_device
*dsaf_dev
, int port
)
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
;
99 if (common_idx
== HNS_DSAF_COMM_SERVICE_NW_IDX
)
100 return &rcb_comm
->ring_pair_cb
[port
* q_num
* vf_num
];
102 return &rcb_comm
->ring_pair_cb
[0];
105 static struct ring_pair_cb
*hns_ae_get_ring_pair(struct hnae_queue
*q
)
107 return container_of(q
, struct ring_pair_cb
, q
);
110 struct hnae_handle
*hns_ae_get_handle(struct hnae_ae_dev
*dev
,
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
;
122 dsaf_dev
= hns_ae_get_dsaf_dev(dev
);
123 port_idx
= hns_ae_map_eport_to_dport(port_id
);
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
);
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
);
136 ae_handle
= &vf_cb
->ae_handle
;
138 ae_handle
->owner_dev
= dsaf_dev
->dev
;
139 ae_handle
->dev
= dev
;
140 ae_handle
->q_num
= qnum_per_vf
;
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
)
147 ring_pair_cb
+= qnum_per_vf
;
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
);
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
];
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
;
165 ring_pair_cb
->port_id_in_dsa
= 0;
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
];
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
;
186 static void hns_ae_put_handle(struct hnae_handle
*handle
)
188 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
191 vf_cb
->mac_cb
= NULL
;
195 for (i
= 0; i
< handle
->q_num
; i
++)
196 hns_ae_get_ring_pair(handle
->qs
[i
])->used_by_vf
= 0;
199 static void hns_ae_ring_enable_all(struct hnae_handle
*handle
, int val
)
201 int q_num
= handle
->q_num
;
204 for (i
= 0; i
< q_num
; i
++)
205 hns_rcb_ring_enable_hw(handle
->qs
[i
], val
);
208 static void hns_ae_init_queue(struct hnae_queue
*q
)
210 struct ring_pair_cb
*ring
=
211 container_of(q
, struct ring_pair_cb
, q
);
213 hns_rcb_init_hw(ring
);
216 static void hns_ae_fini_queue(struct hnae_queue
*q
)
218 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(q
->handle
);
220 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
221 hns_rcb_reset_ring_hw(q
);
224 static int hns_ae_set_mac_address(struct hnae_handle
*handle
, void *p
)
227 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
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
;
234 ret
= hns_mac_change_vf_addr(mac_cb
, handle
->vf_id
, p
);
236 dev_err(handle
->owner_dev
,
237 "set_mac_address fail, ret=%d!\n", ret
);
244 static int hns_ae_set_multicast_one(struct hnae_handle
*handle
, void *addr
)
247 char *mac_addr
= (char *)addr
;
248 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
252 if (mac_cb
->mac_type
!= HNAE_PORT_SERVICE
)
255 ret
= hns_mac_set_multi(mac_cb
, mac_cb
->mac_id
, mac_addr
, true);
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
);
263 ret
= hns_mac_set_multi(mac_cb
, DSAF_BASE_INNER_PORT_NUM
,
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
);
273 static int hns_ae_set_mtu(struct hnae_handle
*handle
, int new_mtu
)
275 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
277 return hns_mac_set_mtu(mac_cb
, new_mtu
);
280 static void hns_ae_set_tso_stats(struct hnae_handle
*handle
, int enable
)
282 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
284 hns_ppe_set_tso_enable(ppe_cb
, enable
);
287 static int hns_ae_start(struct hnae_handle
*handle
)
290 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
292 ret
= hns_mac_vm_config_bc_en(mac_cb
, 0, true);
296 hns_ae_ring_enable_all(handle
, 1);
299 hns_mac_start(mac_cb
);
304 void hns_ae_stop(struct hnae_handle
*handle
)
306 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
308 /* just clean tx fbd, neednot rx fbd*/
309 hns_rcb_wait_fbd_clean(handle
->qs
, handle
->q_num
, RCB_INT_FLAG_TX
);
313 hns_mac_stop(mac_cb
);
315 usleep_range(10000, 20000);
317 hns_ae_ring_enable_all(handle
, 0);
319 (void)hns_mac_vm_config_bc_en(mac_cb
, 0, false);
322 static void hns_ae_reset(struct hnae_handle
*handle
)
324 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
326 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_DEBUG
) {
327 u8 ppe_common_index
=
328 vf_cb
->port_index
- DSAF_SERVICE_PORT_NUM_PER_DSAF
+ 1;
330 hns_mac_reset(vf_cb
->mac_cb
);
331 hns_ppe_reset_common(vf_cb
->dsaf_dev
, ppe_common_index
);
335 void hns_ae_toggle_ring_irq(struct hnae_ring
*ring
, u32 mask
)
339 if (is_tx_ring(ring
))
340 flag
= RCB_INT_FLAG_TX
;
342 flag
= RCB_INT_FLAG_RX
;
344 hns_rcb_int_ctrl_hw(ring
->q
, flag
, mask
);
347 static void hns_aev2_toggle_ring_irq(struct hnae_ring
*ring
, u32 mask
)
351 if (is_tx_ring(ring
))
352 flag
= RCB_INT_FLAG_TX
;
354 flag
= RCB_INT_FLAG_RX
;
356 hns_rcbv2_int_ctrl_hw(ring
->q
, flag
, mask
);
359 static void hns_ae_toggle_queue_status(struct hnae_queue
*queue
, u32 val
)
361 struct dsaf_device
*dsaf_dev
= hns_ae_get_dsaf_dev(queue
->dev
);
363 if (AE_IS_VER1(dsaf_dev
->dsaf_ver
))
364 hns_rcb_int_clr_hw(queue
, RCB_INT_FLAG_TX
| RCB_INT_FLAG_RX
);
366 hns_rcbv2_int_clr_hw(queue
, RCB_INT_FLAG_TX
| RCB_INT_FLAG_RX
);
368 hns_rcb_start(queue
, val
);
371 static int hns_ae_get_link_status(struct hnae_handle
*handle
)
374 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
376 hns_mac_get_link_status(mac_cb
, &link_status
);
378 return !!link_status
;
381 static int hns_ae_get_mac_info(struct hnae_handle
*handle
,
382 u8
*auto_neg
, u16
*speed
, u8
*duplex
)
384 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
386 return hns_mac_get_port_info(mac_cb
, auto_neg
, speed
, duplex
);
389 static void hns_ae_adjust_link(struct hnae_handle
*handle
, int speed
,
392 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
394 hns_mac_adjust_link(mac_cb
, speed
, duplex
);
397 static void hns_ae_get_ring_bdnum_limit(struct hnae_queue
*queue
,
400 *uplimit
= HNS_RCB_RING_MAX_PENDING_BD
;
403 static void hns_ae_get_pauseparam(struct hnae_handle
*handle
,
404 u32
*auto_neg
, u32
*rx_en
, u32
*tx_en
)
408 hns_mac_get_autoneg(hns_get_mac_cb(handle
), auto_neg
);
410 hns_mac_get_pauseparam(hns_get_mac_cb(handle
), rx_en
, tx_en
);
413 static int hns_ae_set_autoneg(struct hnae_handle
*handle
, u8 enable
)
417 return hns_mac_set_autoneg(hns_get_mac_cb(handle
), enable
);
420 static void hns_ae_set_promisc_mode(struct hnae_handle
*handle
, u32 en
)
422 hns_dsaf_set_promisc_mode(hns_ae_get_dsaf_dev(handle
->dev
), en
);
425 static int hns_ae_get_autoneg(struct hnae_handle
*handle
)
431 hns_mac_get_autoneg(hns_get_mac_cb(handle
), &auto_neg
);
436 static int hns_ae_set_pauseparam(struct hnae_handle
*handle
,
437 u32 autoneg
, u32 rx_en
, u32 tx_en
)
439 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
442 ret
= hns_mac_set_autoneg(mac_cb
, autoneg
);
446 return hns_mac_set_pauseparam(mac_cb
, rx_en
, tx_en
);
449 static void hns_ae_get_coalesce_usecs(struct hnae_handle
*handle
,
450 u32
*tx_usecs
, u32
*rx_usecs
)
454 port
= hns_ae_map_eport_to_dport(handle
->eport_id
);
456 *tx_usecs
= hns_rcb_get_coalesce_usecs(
457 hns_ae_get_dsaf_dev(handle
->dev
),
458 hns_dsaf_get_comm_idx_by_port(port
));
459 *rx_usecs
= hns_rcb_get_coalesce_usecs(
460 hns_ae_get_dsaf_dev(handle
->dev
),
461 hns_dsaf_get_comm_idx_by_port(port
));
464 static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle
*handle
,
465 u32
*tx_frames
, u32
*rx_frames
)
471 port
= hns_ae_map_eport_to_dport(handle
->eport_id
);
473 *tx_frames
= hns_rcb_get_coalesced_frames(
474 hns_ae_get_dsaf_dev(handle
->dev
), port
);
475 *rx_frames
= hns_rcb_get_coalesced_frames(
476 hns_ae_get_dsaf_dev(handle
->dev
), port
);
479 static void hns_ae_set_coalesce_usecs(struct hnae_handle
*handle
,
486 port
= hns_ae_map_eport_to_dport(handle
->eport_id
);
488 hns_rcb_set_coalesce_usecs(hns_ae_get_dsaf_dev(handle
->dev
),
492 static int hns_ae_set_coalesce_frames(struct hnae_handle
*handle
,
500 port
= hns_ae_map_eport_to_dport(handle
->eport_id
);
502 ret
= hns_rcb_set_coalesced_frames(hns_ae_get_dsaf_dev(handle
->dev
),
503 port
, coalesce_frames
);
507 void hns_ae_update_stats(struct hnae_handle
*handle
,
508 struct net_device_stats
*net_stats
)
512 struct dsaf_device
*dsaf_dev
;
513 struct hns_mac_cb
*mac_cb
;
514 struct hns_ppe_cb
*ppe_cb
;
515 struct hnae_queue
*queue
;
516 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
517 u64 tx_bytes
= 0, rx_bytes
= 0, tx_packets
= 0, rx_packets
= 0;
518 u64 rx_errors
= 0, tx_errors
= 0, tx_dropped
= 0;
519 u64 rx_missed_errors
= 0;
521 dsaf_dev
= hns_ae_get_dsaf_dev(handle
->dev
);
524 port
= vf_cb
->port_index
;
525 ppe_cb
= hns_get_ppe_cb(handle
);
526 mac_cb
= hns_get_mac_cb(handle
);
528 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
529 queue
= handle
->qs
[idx
];
530 hns_rcb_update_stats(queue
);
532 tx_bytes
+= queue
->tx_ring
.stats
.tx_bytes
;
533 tx_packets
+= queue
->tx_ring
.stats
.tx_pkts
;
534 rx_bytes
+= queue
->rx_ring
.stats
.rx_bytes
;
535 rx_packets
+= queue
->rx_ring
.stats
.rx_pkts
;
537 rx_errors
+= queue
->rx_ring
.stats
.err_pkt_len
538 + queue
->rx_ring
.stats
.l2_err
539 + queue
->rx_ring
.stats
.l3l4_csum_err
;
542 hns_ppe_update_stats(ppe_cb
);
543 rx_missed_errors
= ppe_cb
->hw_stats
.rx_drop_no_buf
;
544 tx_errors
+= ppe_cb
->hw_stats
.tx_err_checksum
545 + ppe_cb
->hw_stats
.tx_err_fifo_empty
;
547 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
) {
548 hns_dsaf_update_stats(dsaf_dev
, port
);
549 /* for port upline direction, i.e., rx. */
550 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].bp_drop
;
551 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].pad_drop
;
552 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].crc_false
;
554 /* for port downline direction, i.e., tx. */
555 port
= port
+ DSAF_PPE_INODE_BASE
;
556 hns_dsaf_update_stats(dsaf_dev
, port
);
557 tx_dropped
+= dsaf_dev
->hw_stats
[port
].bp_drop
;
558 tx_dropped
+= dsaf_dev
->hw_stats
[port
].pad_drop
;
559 tx_dropped
+= dsaf_dev
->hw_stats
[port
].crc_false
;
560 tx_dropped
+= dsaf_dev
->hw_stats
[port
].rslt_drop
;
561 tx_dropped
+= dsaf_dev
->hw_stats
[port
].vlan_drop
;
562 tx_dropped
+= dsaf_dev
->hw_stats
[port
].stp_drop
;
565 hns_mac_update_stats(mac_cb
);
566 rx_errors
+= mac_cb
->hw_stats
.rx_fifo_overrun_err
;
568 tx_errors
+= mac_cb
->hw_stats
.tx_bad_pkts
569 + mac_cb
->hw_stats
.tx_fragment_err
570 + mac_cb
->hw_stats
.tx_jabber_err
571 + mac_cb
->hw_stats
.tx_underrun_err
572 + mac_cb
->hw_stats
.tx_crc_err
;
574 net_stats
->tx_bytes
= tx_bytes
;
575 net_stats
->tx_packets
= tx_packets
;
576 net_stats
->rx_bytes
= rx_bytes
;
577 net_stats
->rx_dropped
= 0;
578 net_stats
->rx_packets
= rx_packets
;
579 net_stats
->rx_errors
= rx_errors
;
580 net_stats
->tx_errors
= tx_errors
;
581 net_stats
->tx_dropped
= tx_dropped
;
582 net_stats
->rx_missed_errors
= rx_missed_errors
;
583 net_stats
->rx_crc_errors
= mac_cb
->hw_stats
.rx_fcs_err
;
584 net_stats
->rx_frame_errors
= mac_cb
->hw_stats
.rx_align_err
;
585 net_stats
->rx_fifo_errors
= mac_cb
->hw_stats
.rx_fifo_overrun_err
;
586 net_stats
->rx_length_errors
= mac_cb
->hw_stats
.rx_len_err
;
587 net_stats
->multicast
= mac_cb
->hw_stats
.rx_mc_pkts
;
590 void hns_ae_get_stats(struct hnae_handle
*handle
, u64
*data
)
593 struct hns_mac_cb
*mac_cb
;
594 struct hns_ppe_cb
*ppe_cb
;
596 struct hnae_vf_cb
*vf_cb
;
598 if (!handle
|| !data
) {
599 pr_err("hns_ae_get_stats NULL handle or data pointer!\n");
603 vf_cb
= hns_ae_get_vf_cb(handle
);
604 mac_cb
= hns_get_mac_cb(handle
);
605 ppe_cb
= hns_get_ppe_cb(handle
);
607 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
608 hns_rcb_get_stats(handle
->qs
[idx
], p
);
609 p
+= hns_rcb_get_ring_sset_count((int)ETH_SS_STATS
);
612 hns_ppe_get_stats(ppe_cb
, p
);
613 p
+= hns_ppe_get_sset_count((int)ETH_SS_STATS
);
615 hns_mac_get_stats(mac_cb
, p
);
616 p
+= hns_mac_get_sset_count(mac_cb
, (int)ETH_SS_STATS
);
618 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
619 hns_dsaf_get_stats(vf_cb
->dsaf_dev
, p
, vf_cb
->port_index
);
622 void hns_ae_get_strings(struct hnae_handle
*handle
,
623 u32 stringset
, u8
*data
)
627 struct hns_mac_cb
*mac_cb
;
628 struct hns_ppe_cb
*ppe_cb
;
630 struct hnae_vf_cb
*vf_cb
;
634 vf_cb
= hns_ae_get_vf_cb(handle
);
635 port
= vf_cb
->port_index
;
636 mac_cb
= hns_get_mac_cb(handle
);
637 ppe_cb
= hns_get_ppe_cb(handle
);
639 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
640 hns_rcb_get_strings(stringset
, p
, idx
);
641 p
+= ETH_GSTRING_LEN
* hns_rcb_get_ring_sset_count(stringset
);
644 hns_ppe_get_strings(ppe_cb
, stringset
, p
);
645 p
+= ETH_GSTRING_LEN
* hns_ppe_get_sset_count(stringset
);
647 hns_mac_get_strings(mac_cb
, stringset
, p
);
648 p
+= ETH_GSTRING_LEN
* hns_mac_get_sset_count(mac_cb
, stringset
);
650 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
651 hns_dsaf_get_strings(stringset
, p
, port
);
654 int hns_ae_get_sset_count(struct hnae_handle
*handle
, int stringset
)
657 struct hns_mac_cb
*mac_cb
;
661 mac_cb
= hns_get_mac_cb(handle
);
663 sset_count
+= hns_rcb_get_ring_sset_count(stringset
) * handle
->q_num
;
664 sset_count
+= hns_ppe_get_sset_count(stringset
);
665 sset_count
+= hns_mac_get_sset_count(mac_cb
, stringset
);
667 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
668 sset_count
+= hns_dsaf_get_sset_count(stringset
);
673 static int hns_ae_config_loopback(struct hnae_handle
*handle
,
674 enum hnae_loop loop
, int en
)
677 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
680 case MAC_INTERNALLOOP_SERDES
:
681 ret
= hns_mac_config_sds_loopback(vf_cb
->mac_cb
, en
);
683 case MAC_INTERNALLOOP_MAC
:
684 ret
= hns_mac_config_mac_loopback(vf_cb
->mac_cb
, loop
, en
);
692 void hns_ae_update_led_status(struct hnae_handle
*handle
)
694 struct hns_mac_cb
*mac_cb
;
697 mac_cb
= hns_get_mac_cb(handle
);
698 if (!mac_cb
->cpld_vaddr
)
700 hns_set_led_opt(mac_cb
);
703 int hns_ae_cpld_set_led_id(struct hnae_handle
*handle
,
704 enum hnae_led_state status
)
706 struct hns_mac_cb
*mac_cb
;
710 mac_cb
= hns_get_mac_cb(handle
);
712 return hns_cpld_led_set_id(mac_cb
, status
);
715 void hns_ae_get_regs(struct hnae_handle
*handle
, void *data
)
720 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
721 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
723 hns_ppe_get_regs(ppe_cb
, p
);
724 p
+= hns_ppe_get_regs_count();
726 rcb_com_idx
= hns_dsaf_get_comm_idx_by_port(vf_cb
->port_index
);
727 hns_rcb_get_common_regs(vf_cb
->dsaf_dev
->rcb_common
[rcb_com_idx
], p
);
728 p
+= hns_rcb_get_common_regs_count();
730 for (i
= 0; i
< handle
->q_num
; i
++) {
731 hns_rcb_get_ring_regs(handle
->qs
[i
], p
);
732 p
+= hns_rcb_get_ring_regs_count();
735 hns_mac_get_regs(vf_cb
->mac_cb
, p
);
736 p
+= hns_mac_get_regs_count(vf_cb
->mac_cb
);
738 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
739 hns_dsaf_get_regs(vf_cb
->dsaf_dev
, vf_cb
->port_index
, p
);
742 int hns_ae_get_regs_len(struct hnae_handle
*handle
)
745 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
747 total_num
= hns_ppe_get_regs_count();
748 total_num
+= hns_rcb_get_common_regs_count();
749 total_num
+= hns_rcb_get_ring_regs_count() * handle
->q_num
;
750 total_num
+= hns_mac_get_regs_count(vf_cb
->mac_cb
);
752 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
753 total_num
+= hns_dsaf_get_regs_count();
758 static u32
hns_ae_get_rss_key_size(struct hnae_handle
*handle
)
760 return HNS_PPEV2_RSS_KEY_SIZE
;
763 static u32
hns_ae_get_rss_indir_size(struct hnae_handle
*handle
)
765 return HNS_PPEV2_RSS_IND_TBL_SIZE
;
768 static int hns_ae_get_rss(struct hnae_handle
*handle
, u32
*indir
, u8
*key
,
771 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
773 /* currently we support only one type of hash function i.e. Toep hash */
775 *hfunc
= ETH_RSS_HASH_TOP
;
777 /* get the RSS Key required by the user */
779 memcpy(key
, ppe_cb
->rss_key
, HNS_PPEV2_RSS_KEY_SIZE
);
781 /* update the current hash->queue mappings from the shadow RSS table */
782 memcpy(indir
, ppe_cb
->rss_indir_table
, HNS_PPEV2_RSS_IND_TBL_SIZE
);
787 static int hns_ae_set_rss(struct hnae_handle
*handle
, const u32
*indir
,
788 const u8
*key
, const u8 hfunc
)
790 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
792 /* set the RSS Hash Key if specififed by the user */
794 hns_ppe_set_rss_key(ppe_cb
, (int *)key
);
796 /* update the shadow RSS table with user specified qids */
797 memcpy(ppe_cb
->rss_indir_table
, indir
, HNS_PPEV2_RSS_IND_TBL_SIZE
);
799 /* now update the hardware */
800 hns_ppe_set_indir_table(ppe_cb
, ppe_cb
->rss_indir_table
);
805 static struct hnae_ae_ops hns_dsaf_ops
= {
806 .get_handle
= hns_ae_get_handle
,
807 .put_handle
= hns_ae_put_handle
,
808 .init_queue
= hns_ae_init_queue
,
809 .fini_queue
= hns_ae_fini_queue
,
810 .start
= hns_ae_start
,
812 .reset
= hns_ae_reset
,
813 .toggle_ring_irq
= hns_ae_toggle_ring_irq
,
814 .toggle_queue_status
= hns_ae_toggle_queue_status
,
815 .get_status
= hns_ae_get_link_status
,
816 .get_info
= hns_ae_get_mac_info
,
817 .adjust_link
= hns_ae_adjust_link
,
818 .set_loopback
= hns_ae_config_loopback
,
819 .get_ring_bdnum_limit
= hns_ae_get_ring_bdnum_limit
,
820 .get_pauseparam
= hns_ae_get_pauseparam
,
821 .set_autoneg
= hns_ae_set_autoneg
,
822 .get_autoneg
= hns_ae_get_autoneg
,
823 .set_pauseparam
= hns_ae_set_pauseparam
,
824 .get_coalesce_usecs
= hns_ae_get_coalesce_usecs
,
825 .get_rx_max_coalesced_frames
= hns_ae_get_rx_max_coalesced_frames
,
826 .set_coalesce_usecs
= hns_ae_set_coalesce_usecs
,
827 .set_coalesce_frames
= hns_ae_set_coalesce_frames
,
828 .set_promisc_mode
= hns_ae_set_promisc_mode
,
829 .set_mac_addr
= hns_ae_set_mac_address
,
830 .set_mc_addr
= hns_ae_set_multicast_one
,
831 .set_mtu
= hns_ae_set_mtu
,
832 .update_stats
= hns_ae_update_stats
,
833 .set_tso_stats
= hns_ae_set_tso_stats
,
834 .get_stats
= hns_ae_get_stats
,
835 .get_strings
= hns_ae_get_strings
,
836 .get_sset_count
= hns_ae_get_sset_count
,
837 .update_led_status
= hns_ae_update_led_status
,
838 .set_led_id
= hns_ae_cpld_set_led_id
,
839 .get_regs
= hns_ae_get_regs
,
840 .get_regs_len
= hns_ae_get_regs_len
,
841 .get_rss_key_size
= hns_ae_get_rss_key_size
,
842 .get_rss_indir_size
= hns_ae_get_rss_indir_size
,
843 .get_rss
= hns_ae_get_rss
,
844 .set_rss
= hns_ae_set_rss
847 int hns_dsaf_ae_init(struct dsaf_device
*dsaf_dev
)
849 struct hnae_ae_dev
*ae_dev
= &dsaf_dev
->ae_dev
;
851 switch (dsaf_dev
->dsaf_ver
) {
853 hns_dsaf_ops
.toggle_ring_irq
= hns_ae_toggle_ring_irq
;
856 hns_dsaf_ops
.toggle_ring_irq
= hns_aev2_toggle_ring_irq
;
861 ae_dev
->ops
= &hns_dsaf_ops
;
862 ae_dev
->dev
= dsaf_dev
->dev
;
864 return hnae_ae_register(ae_dev
, THIS_MODULE
);
867 void hns_dsaf_ae_uninit(struct dsaf_device
*dsaf_dev
)
869 hnae_ae_unregister(&dsaf_dev
->ae_dev
);