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
)
41 struct ppe_common_cb
*ppe_comm
;
42 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
44 if (vf_cb
->port_index
< DSAF_SERVICE_PORT_NUM_PER_DSAF
) {
45 ppe_index
= vf_cb
->port_index
;
50 vf_cb
->port_index
- DSAF_SERVICE_PORT_NUM_PER_DSAF
+ 1;
52 ppe_comm
= vf_cb
->dsaf_dev
->ppe_common
[ppe_common_index
];
53 return &ppe_comm
->ppe_cb
[ppe_index
];
56 static int hns_ae_get_q_num_per_vf(
57 struct dsaf_device
*dsaf_dev
, int port
)
59 int common_idx
= hns_dsaf_get_comm_idx_by_port(port
);
61 return dsaf_dev
->rcb_common
[common_idx
]->max_q_per_vf
;
64 static int hns_ae_get_vf_num_per_port(
65 struct dsaf_device
*dsaf_dev
, int port
)
67 int common_idx
= hns_dsaf_get_comm_idx_by_port(port
);
69 return dsaf_dev
->rcb_common
[common_idx
]->max_vfn
;
72 static struct ring_pair_cb
*hns_ae_get_base_ring_pair(
73 struct dsaf_device
*dsaf_dev
, int port
)
75 int common_idx
= hns_dsaf_get_comm_idx_by_port(port
);
76 struct rcb_common_cb
*rcb_comm
= dsaf_dev
->rcb_common
[common_idx
];
77 int q_num
= rcb_comm
->max_q_per_vf
;
78 int vf_num
= rcb_comm
->max_vfn
;
80 if (!HNS_DSAF_IS_DEBUG(dsaf_dev
))
81 return &rcb_comm
->ring_pair_cb
[port
* q_num
* vf_num
];
83 return &rcb_comm
->ring_pair_cb
[0];
86 static struct ring_pair_cb
*hns_ae_get_ring_pair(struct hnae_queue
*q
)
88 return container_of(q
, struct ring_pair_cb
, q
);
91 struct hnae_handle
*hns_ae_get_handle(struct hnae_ae_dev
*dev
,
97 struct dsaf_device
*dsaf_dev
;
98 struct hnae_handle
*ae_handle
;
99 struct ring_pair_cb
*ring_pair_cb
;
100 struct hnae_vf_cb
*vf_cb
;
102 dsaf_dev
= hns_ae_get_dsaf_dev(dev
);
104 ring_pair_cb
= hns_ae_get_base_ring_pair(dsaf_dev
, port_id
);
105 vfnum_per_port
= hns_ae_get_vf_num_per_port(dsaf_dev
, port_id
);
106 qnum_per_vf
= hns_ae_get_q_num_per_vf(dsaf_dev
, port_id
);
108 vf_cb
= kzalloc(sizeof(*vf_cb
) +
109 qnum_per_vf
* sizeof(struct hnae_queue
*), GFP_KERNEL
);
110 if (unlikely(!vf_cb
)) {
111 dev_err(dsaf_dev
->dev
, "malloc vf_cb fail!\n");
112 ae_handle
= ERR_PTR(-ENOMEM
);
115 ae_handle
= &vf_cb
->ae_handle
;
117 ae_handle
->owner_dev
= dsaf_dev
->dev
;
118 ae_handle
->dev
= dev
;
119 ae_handle
->q_num
= qnum_per_vf
;
121 /* find ring pair, and set vf id*/
122 for (ae_handle
->vf_id
= 0;
123 ae_handle
->vf_id
< vfnum_per_port
; ae_handle
->vf_id
++) {
124 if (!ring_pair_cb
->used_by_vf
)
126 ring_pair_cb
+= qnum_per_vf
;
128 if (ae_handle
->vf_id
>= vfnum_per_port
) {
129 dev_err(dsaf_dev
->dev
, "malloc queue fail!\n");
130 ae_handle
= ERR_PTR(-EINVAL
);
134 ae_handle
->qs
= (struct hnae_queue
**)(&ae_handle
->qs
+ 1);
135 for (i
= 0; i
< qnum_per_vf
; i
++) {
136 ae_handle
->qs
[i
] = &ring_pair_cb
->q
;
137 ae_handle
->qs
[i
]->rx_ring
.q
= ae_handle
->qs
[i
];
138 ae_handle
->qs
[i
]->tx_ring
.q
= ae_handle
->qs
[i
];
140 ring_pair_cb
->used_by_vf
= 1;
144 vf_cb
->dsaf_dev
= dsaf_dev
;
145 vf_cb
->port_index
= port_id
;
146 vf_cb
->mac_cb
= &dsaf_dev
->mac_cb
[port_id
];
148 ae_handle
->phy_if
= vf_cb
->mac_cb
->phy_if
;
149 ae_handle
->phy_node
= vf_cb
->mac_cb
->phy_node
;
150 ae_handle
->if_support
= vf_cb
->mac_cb
->if_support
;
151 ae_handle
->port_type
= vf_cb
->mac_cb
->mac_type
;
152 ae_handle
->dport_id
= port_id
;
161 static void hns_ae_put_handle(struct hnae_handle
*handle
)
163 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
166 vf_cb
->mac_cb
= NULL
;
170 for (i
= 0; i
< handle
->q_num
; i
++)
171 hns_ae_get_ring_pair(handle
->qs
[i
])->used_by_vf
= 0;
174 static void hns_ae_ring_enable_all(struct hnae_handle
*handle
, int val
)
176 int q_num
= handle
->q_num
;
179 for (i
= 0; i
< q_num
; i
++)
180 hns_rcb_ring_enable_hw(handle
->qs
[i
], val
);
183 static void hns_ae_init_queue(struct hnae_queue
*q
)
185 struct ring_pair_cb
*ring
=
186 container_of(q
, struct ring_pair_cb
, q
);
188 hns_rcb_init_hw(ring
);
191 static void hns_ae_fini_queue(struct hnae_queue
*q
)
193 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(q
->handle
);
195 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
196 hns_rcb_reset_ring_hw(q
);
199 static int hns_ae_set_mac_address(struct hnae_handle
*handle
, void *p
)
202 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
204 if (!p
|| !is_valid_ether_addr((const u8
*)p
)) {
205 dev_err(handle
->owner_dev
, "is not valid ether addr !\n");
206 return -EADDRNOTAVAIL
;
209 ret
= hns_mac_change_vf_addr(mac_cb
, handle
->vf_id
, p
);
211 dev_err(handle
->owner_dev
,
212 "set_mac_address fail, ret=%d!\n", ret
);
219 static int hns_ae_set_multicast_one(struct hnae_handle
*handle
, void *addr
)
222 char *mac_addr
= (char *)addr
;
223 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
227 if (mac_cb
->mac_type
!= HNAE_PORT_SERVICE
)
230 ret
= hns_mac_set_multi(mac_cb
, mac_cb
->mac_id
, mac_addr
, true);
232 dev_err(handle
->owner_dev
,
233 "mac add mul_mac:%pM port%d fail, ret = %#x!\n",
234 mac_addr
, mac_cb
->mac_id
, ret
);
238 ret
= hns_mac_set_multi(mac_cb
, DSAF_BASE_INNER_PORT_NUM
,
241 dev_err(handle
->owner_dev
,
242 "mac add mul_mac:%pM port%d fail, ret = %#x!\n",
243 mac_addr
, DSAF_BASE_INNER_PORT_NUM
, ret
);
248 static int hns_ae_set_mtu(struct hnae_handle
*handle
, int new_mtu
)
250 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
252 return hns_mac_set_mtu(mac_cb
, new_mtu
);
255 static void hns_ae_set_tso_stats(struct hnae_handle
*handle
, int enable
)
257 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
259 hns_ppe_set_tso_enable(ppe_cb
, enable
);
262 static int hns_ae_start(struct hnae_handle
*handle
)
265 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
267 ret
= hns_mac_vm_config_bc_en(mac_cb
, 0, true);
271 hns_ae_ring_enable_all(handle
, 1);
274 hns_mac_start(mac_cb
);
279 void hns_ae_stop(struct hnae_handle
*handle
)
281 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
283 /* just clean tx fbd, neednot rx fbd*/
284 hns_rcb_wait_fbd_clean(handle
->qs
, handle
->q_num
, RCB_INT_FLAG_TX
);
288 hns_mac_stop(mac_cb
);
290 usleep_range(10000, 20000);
292 hns_ae_ring_enable_all(handle
, 0);
294 (void)hns_mac_vm_config_bc_en(mac_cb
, 0, false);
297 static void hns_ae_reset(struct hnae_handle
*handle
)
299 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
301 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_DEBUG
) {
302 u8 ppe_common_index
=
303 vf_cb
->port_index
- DSAF_SERVICE_PORT_NUM_PER_DSAF
+ 1;
305 hns_mac_reset(vf_cb
->mac_cb
);
306 hns_ppe_reset_common(vf_cb
->dsaf_dev
, ppe_common_index
);
310 void hns_ae_toggle_ring_irq(struct hnae_ring
*ring
, u32 mask
)
314 if (is_tx_ring(ring
))
315 flag
= RCB_INT_FLAG_TX
;
317 flag
= RCB_INT_FLAG_RX
;
319 hns_rcb_int_ctrl_hw(ring
->q
, flag
, mask
);
322 static void hns_aev2_toggle_ring_irq(struct hnae_ring
*ring
, u32 mask
)
326 if (is_tx_ring(ring
))
327 flag
= RCB_INT_FLAG_TX
;
329 flag
= RCB_INT_FLAG_RX
;
331 hns_rcbv2_int_ctrl_hw(ring
->q
, flag
, mask
);
334 static void hns_ae_toggle_queue_status(struct hnae_queue
*queue
, u32 val
)
336 struct dsaf_device
*dsaf_dev
= hns_ae_get_dsaf_dev(queue
->dev
);
338 if (AE_IS_VER1(dsaf_dev
->dsaf_ver
))
339 hns_rcb_int_clr_hw(queue
, RCB_INT_FLAG_TX
| RCB_INT_FLAG_RX
);
341 hns_rcbv2_int_clr_hw(queue
, RCB_INT_FLAG_TX
| RCB_INT_FLAG_RX
);
343 hns_rcb_start(queue
, val
);
346 static int hns_ae_get_link_status(struct hnae_handle
*handle
)
349 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
351 hns_mac_get_link_status(mac_cb
, &link_status
);
353 return !!link_status
;
356 static int hns_ae_get_mac_info(struct hnae_handle
*handle
,
357 u8
*auto_neg
, u16
*speed
, u8
*duplex
)
359 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
361 return hns_mac_get_port_info(mac_cb
, auto_neg
, speed
, duplex
);
364 static void hns_ae_adjust_link(struct hnae_handle
*handle
, int speed
,
367 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
369 hns_mac_adjust_link(mac_cb
, speed
, duplex
);
372 static void hns_ae_get_ring_bdnum_limit(struct hnae_queue
*queue
,
375 *uplimit
= HNS_RCB_RING_MAX_PENDING_BD
;
378 static void hns_ae_get_pauseparam(struct hnae_handle
*handle
,
379 u32
*auto_neg
, u32
*rx_en
, u32
*tx_en
)
381 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
382 struct dsaf_device
*dsaf_dev
= mac_cb
->dsaf_dev
;
384 hns_mac_get_autoneg(mac_cb
, auto_neg
);
386 hns_mac_get_pauseparam(mac_cb
, rx_en
, tx_en
);
388 /* Service port's pause feature is provided by DSAF, not mac */
389 if (handle
->port_type
== HNAE_PORT_SERVICE
)
390 hns_dsaf_get_rx_mac_pause_en(dsaf_dev
, mac_cb
->mac_id
, rx_en
);
393 static int hns_ae_set_autoneg(struct hnae_handle
*handle
, u8 enable
)
397 return hns_mac_set_autoneg(hns_get_mac_cb(handle
), enable
);
400 static void hns_ae_set_promisc_mode(struct hnae_handle
*handle
, u32 en
)
402 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
404 hns_dsaf_set_promisc_mode(hns_ae_get_dsaf_dev(handle
->dev
), en
);
405 hns_mac_set_promisc(mac_cb
, (u8
)!!en
);
408 static int hns_ae_get_autoneg(struct hnae_handle
*handle
)
414 hns_mac_get_autoneg(hns_get_mac_cb(handle
), &auto_neg
);
419 static int hns_ae_set_pauseparam(struct hnae_handle
*handle
,
420 u32 autoneg
, u32 rx_en
, u32 tx_en
)
422 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
423 struct dsaf_device
*dsaf_dev
= mac_cb
->dsaf_dev
;
426 ret
= hns_mac_set_autoneg(mac_cb
, autoneg
);
430 /* Service port's pause feature is provided by DSAF, not mac */
431 if (handle
->port_type
== HNAE_PORT_SERVICE
) {
432 ret
= hns_dsaf_set_rx_mac_pause_en(dsaf_dev
,
433 mac_cb
->mac_id
, rx_en
);
438 return hns_mac_set_pauseparam(mac_cb
, rx_en
, tx_en
);
441 static void hns_ae_get_coalesce_usecs(struct hnae_handle
*handle
,
442 u32
*tx_usecs
, u32
*rx_usecs
)
444 struct ring_pair_cb
*ring_pair
=
445 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
447 *tx_usecs
= hns_rcb_get_coalesce_usecs(ring_pair
->rcb_common
,
448 ring_pair
->port_id_in_comm
);
449 *rx_usecs
= hns_rcb_get_coalesce_usecs(ring_pair
->rcb_common
,
450 ring_pair
->port_id_in_comm
);
453 static void hns_ae_get_rx_max_coalesced_frames(struct hnae_handle
*handle
,
454 u32
*tx_frames
, u32
*rx_frames
)
456 struct ring_pair_cb
*ring_pair
=
457 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
459 *tx_frames
= hns_rcb_get_coalesced_frames(ring_pair
->rcb_common
,
460 ring_pair
->port_id_in_comm
);
461 *rx_frames
= hns_rcb_get_coalesced_frames(ring_pair
->rcb_common
,
462 ring_pair
->port_id_in_comm
);
465 static int hns_ae_set_coalesce_usecs(struct hnae_handle
*handle
,
468 struct ring_pair_cb
*ring_pair
=
469 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
471 return hns_rcb_set_coalesce_usecs(
472 ring_pair
->rcb_common
, ring_pair
->port_id_in_comm
, timeout
);
475 static int hns_ae_set_coalesce_frames(struct hnae_handle
*handle
,
478 struct ring_pair_cb
*ring_pair
=
479 container_of(handle
->qs
[0], struct ring_pair_cb
, q
);
481 return hns_rcb_set_coalesced_frames(
482 ring_pair
->rcb_common
,
483 ring_pair
->port_id_in_comm
, coalesce_frames
);
486 void hns_ae_update_stats(struct hnae_handle
*handle
,
487 struct net_device_stats
*net_stats
)
491 struct dsaf_device
*dsaf_dev
;
492 struct hns_mac_cb
*mac_cb
;
493 struct hns_ppe_cb
*ppe_cb
;
494 struct hnae_queue
*queue
;
495 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
496 u64 tx_bytes
= 0, rx_bytes
= 0, tx_packets
= 0, rx_packets
= 0;
497 u64 rx_errors
= 0, tx_errors
= 0, tx_dropped
= 0;
498 u64 rx_missed_errors
= 0;
500 dsaf_dev
= hns_ae_get_dsaf_dev(handle
->dev
);
503 port
= vf_cb
->port_index
;
504 ppe_cb
= hns_get_ppe_cb(handle
);
505 mac_cb
= hns_get_mac_cb(handle
);
507 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
508 queue
= handle
->qs
[idx
];
509 hns_rcb_update_stats(queue
);
511 tx_bytes
+= queue
->tx_ring
.stats
.tx_bytes
;
512 tx_packets
+= queue
->tx_ring
.stats
.tx_pkts
;
513 rx_bytes
+= queue
->rx_ring
.stats
.rx_bytes
;
514 rx_packets
+= queue
->rx_ring
.stats
.rx_pkts
;
516 rx_errors
+= queue
->rx_ring
.stats
.err_pkt_len
517 + queue
->rx_ring
.stats
.l2_err
518 + queue
->rx_ring
.stats
.l3l4_csum_err
;
521 hns_ppe_update_stats(ppe_cb
);
522 rx_missed_errors
= ppe_cb
->hw_stats
.rx_drop_no_buf
;
523 tx_errors
+= ppe_cb
->hw_stats
.tx_err_checksum
524 + ppe_cb
->hw_stats
.tx_err_fifo_empty
;
526 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
) {
527 hns_dsaf_update_stats(dsaf_dev
, port
);
528 /* for port upline direction, i.e., rx. */
529 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].bp_drop
;
530 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].pad_drop
;
531 rx_missed_errors
+= dsaf_dev
->hw_stats
[port
].crc_false
;
533 /* for port downline direction, i.e., tx. */
534 port
= port
+ DSAF_PPE_INODE_BASE
;
535 hns_dsaf_update_stats(dsaf_dev
, port
);
536 tx_dropped
+= dsaf_dev
->hw_stats
[port
].bp_drop
;
537 tx_dropped
+= dsaf_dev
->hw_stats
[port
].pad_drop
;
538 tx_dropped
+= dsaf_dev
->hw_stats
[port
].crc_false
;
539 tx_dropped
+= dsaf_dev
->hw_stats
[port
].rslt_drop
;
540 tx_dropped
+= dsaf_dev
->hw_stats
[port
].vlan_drop
;
541 tx_dropped
+= dsaf_dev
->hw_stats
[port
].stp_drop
;
544 hns_mac_update_stats(mac_cb
);
545 rx_errors
+= mac_cb
->hw_stats
.rx_fifo_overrun_err
;
547 tx_errors
+= mac_cb
->hw_stats
.tx_bad_pkts
548 + mac_cb
->hw_stats
.tx_fragment_err
549 + mac_cb
->hw_stats
.tx_jabber_err
550 + mac_cb
->hw_stats
.tx_underrun_err
551 + mac_cb
->hw_stats
.tx_crc_err
;
553 net_stats
->tx_bytes
= tx_bytes
;
554 net_stats
->tx_packets
= tx_packets
;
555 net_stats
->rx_bytes
= rx_bytes
;
556 net_stats
->rx_dropped
= 0;
557 net_stats
->rx_packets
= rx_packets
;
558 net_stats
->rx_errors
= rx_errors
;
559 net_stats
->tx_errors
= tx_errors
;
560 net_stats
->tx_dropped
= tx_dropped
;
561 net_stats
->rx_missed_errors
= rx_missed_errors
;
562 net_stats
->rx_crc_errors
= mac_cb
->hw_stats
.rx_fcs_err
;
563 net_stats
->rx_frame_errors
= mac_cb
->hw_stats
.rx_align_err
;
564 net_stats
->rx_fifo_errors
= mac_cb
->hw_stats
.rx_fifo_overrun_err
;
565 net_stats
->rx_length_errors
= mac_cb
->hw_stats
.rx_len_err
;
566 net_stats
->multicast
= mac_cb
->hw_stats
.rx_mc_pkts
;
569 void hns_ae_get_stats(struct hnae_handle
*handle
, u64
*data
)
572 struct hns_mac_cb
*mac_cb
;
573 struct hns_ppe_cb
*ppe_cb
;
575 struct hnae_vf_cb
*vf_cb
;
577 if (!handle
|| !data
) {
578 pr_err("hns_ae_get_stats NULL handle or data pointer!\n");
582 vf_cb
= hns_ae_get_vf_cb(handle
);
583 mac_cb
= hns_get_mac_cb(handle
);
584 ppe_cb
= hns_get_ppe_cb(handle
);
586 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
587 hns_rcb_get_stats(handle
->qs
[idx
], p
);
588 p
+= hns_rcb_get_ring_sset_count((int)ETH_SS_STATS
);
591 hns_ppe_get_stats(ppe_cb
, p
);
592 p
+= hns_ppe_get_sset_count((int)ETH_SS_STATS
);
594 hns_mac_get_stats(mac_cb
, p
);
595 p
+= hns_mac_get_sset_count(mac_cb
, (int)ETH_SS_STATS
);
597 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
598 hns_dsaf_get_stats(vf_cb
->dsaf_dev
, p
, vf_cb
->port_index
);
601 void hns_ae_get_strings(struct hnae_handle
*handle
,
602 u32 stringset
, u8
*data
)
606 struct hns_mac_cb
*mac_cb
;
607 struct hns_ppe_cb
*ppe_cb
;
609 struct hnae_vf_cb
*vf_cb
;
613 vf_cb
= hns_ae_get_vf_cb(handle
);
614 port
= vf_cb
->port_index
;
615 mac_cb
= hns_get_mac_cb(handle
);
616 ppe_cb
= hns_get_ppe_cb(handle
);
618 for (idx
= 0; idx
< handle
->q_num
; idx
++) {
619 hns_rcb_get_strings(stringset
, p
, idx
);
620 p
+= ETH_GSTRING_LEN
* hns_rcb_get_ring_sset_count(stringset
);
623 hns_ppe_get_strings(ppe_cb
, stringset
, p
);
624 p
+= ETH_GSTRING_LEN
* hns_ppe_get_sset_count(stringset
);
626 hns_mac_get_strings(mac_cb
, stringset
, p
);
627 p
+= ETH_GSTRING_LEN
* hns_mac_get_sset_count(mac_cb
, stringset
);
629 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
630 hns_dsaf_get_strings(stringset
, p
, port
);
633 int hns_ae_get_sset_count(struct hnae_handle
*handle
, int stringset
)
636 struct hns_mac_cb
*mac_cb
;
640 mac_cb
= hns_get_mac_cb(handle
);
642 sset_count
+= hns_rcb_get_ring_sset_count(stringset
) * handle
->q_num
;
643 sset_count
+= hns_ppe_get_sset_count(stringset
);
644 sset_count
+= hns_mac_get_sset_count(mac_cb
, stringset
);
646 if (mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
647 sset_count
+= hns_dsaf_get_sset_count(stringset
);
652 static int hns_ae_config_loopback(struct hnae_handle
*handle
,
653 enum hnae_loop loop
, int en
)
656 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
657 struct hns_mac_cb
*mac_cb
= hns_get_mac_cb(handle
);
660 case MAC_INTERNALLOOP_PHY
:
663 case MAC_INTERNALLOOP_SERDES
:
664 ret
= hns_mac_config_sds_loopback(vf_cb
->mac_cb
, en
);
666 case MAC_INTERNALLOOP_MAC
:
667 ret
= hns_mac_config_mac_loopback(vf_cb
->mac_cb
, loop
, en
);
674 hns_dsaf_set_inner_lb(mac_cb
->dsaf_dev
, mac_cb
->mac_id
, en
);
679 void hns_ae_update_led_status(struct hnae_handle
*handle
)
681 struct hns_mac_cb
*mac_cb
;
684 mac_cb
= hns_get_mac_cb(handle
);
685 if (!mac_cb
->cpld_vaddr
)
687 hns_set_led_opt(mac_cb
);
690 int hns_ae_cpld_set_led_id(struct hnae_handle
*handle
,
691 enum hnae_led_state status
)
693 struct hns_mac_cb
*mac_cb
;
697 mac_cb
= hns_get_mac_cb(handle
);
699 return hns_cpld_led_set_id(mac_cb
, status
);
702 void hns_ae_get_regs(struct hnae_handle
*handle
, void *data
)
707 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
708 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
710 hns_ppe_get_regs(ppe_cb
, p
);
711 p
+= hns_ppe_get_regs_count();
713 rcb_com_idx
= hns_dsaf_get_comm_idx_by_port(vf_cb
->port_index
);
714 hns_rcb_get_common_regs(vf_cb
->dsaf_dev
->rcb_common
[rcb_com_idx
], p
);
715 p
+= hns_rcb_get_common_regs_count();
717 for (i
= 0; i
< handle
->q_num
; i
++) {
718 hns_rcb_get_ring_regs(handle
->qs
[i
], p
);
719 p
+= hns_rcb_get_ring_regs_count();
722 hns_mac_get_regs(vf_cb
->mac_cb
, p
);
723 p
+= hns_mac_get_regs_count(vf_cb
->mac_cb
);
725 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
726 hns_dsaf_get_regs(vf_cb
->dsaf_dev
, vf_cb
->port_index
, p
);
729 int hns_ae_get_regs_len(struct hnae_handle
*handle
)
732 struct hnae_vf_cb
*vf_cb
= hns_ae_get_vf_cb(handle
);
734 total_num
= hns_ppe_get_regs_count();
735 total_num
+= hns_rcb_get_common_regs_count();
736 total_num
+= hns_rcb_get_ring_regs_count() * handle
->q_num
;
737 total_num
+= hns_mac_get_regs_count(vf_cb
->mac_cb
);
739 if (vf_cb
->mac_cb
->mac_type
== HNAE_PORT_SERVICE
)
740 total_num
+= hns_dsaf_get_regs_count();
745 static u32
hns_ae_get_rss_key_size(struct hnae_handle
*handle
)
747 return HNS_PPEV2_RSS_KEY_SIZE
;
750 static u32
hns_ae_get_rss_indir_size(struct hnae_handle
*handle
)
752 return HNS_PPEV2_RSS_IND_TBL_SIZE
;
755 static int hns_ae_get_rss(struct hnae_handle
*handle
, u32
*indir
, u8
*key
,
758 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
760 /* currently we support only one type of hash function i.e. Toep hash */
762 *hfunc
= ETH_RSS_HASH_TOP
;
764 /* get the RSS Key required by the user */
766 memcpy(key
, ppe_cb
->rss_key
, HNS_PPEV2_RSS_KEY_SIZE
);
768 /* update the current hash->queue mappings from the shadow RSS table */
769 memcpy(indir
, ppe_cb
->rss_indir_table
,
770 HNS_PPEV2_RSS_IND_TBL_SIZE
* sizeof(*indir
));
775 static int hns_ae_set_rss(struct hnae_handle
*handle
, const u32
*indir
,
776 const u8
*key
, const u8 hfunc
)
778 struct hns_ppe_cb
*ppe_cb
= hns_get_ppe_cb(handle
);
780 /* set the RSS Hash Key if specififed by the user */
782 hns_ppe_set_rss_key(ppe_cb
, (u32
*)key
);
784 /* update the shadow RSS table with user specified qids */
785 memcpy(ppe_cb
->rss_indir_table
, indir
,
786 HNS_PPEV2_RSS_IND_TBL_SIZE
* sizeof(*indir
));
788 /* now update the hardware */
789 hns_ppe_set_indir_table(ppe_cb
, ppe_cb
->rss_indir_table
);
794 static struct hnae_ae_ops hns_dsaf_ops
= {
795 .get_handle
= hns_ae_get_handle
,
796 .put_handle
= hns_ae_put_handle
,
797 .init_queue
= hns_ae_init_queue
,
798 .fini_queue
= hns_ae_fini_queue
,
799 .start
= hns_ae_start
,
801 .reset
= hns_ae_reset
,
802 .toggle_ring_irq
= hns_ae_toggle_ring_irq
,
803 .toggle_queue_status
= hns_ae_toggle_queue_status
,
804 .get_status
= hns_ae_get_link_status
,
805 .get_info
= hns_ae_get_mac_info
,
806 .adjust_link
= hns_ae_adjust_link
,
807 .set_loopback
= hns_ae_config_loopback
,
808 .get_ring_bdnum_limit
= hns_ae_get_ring_bdnum_limit
,
809 .get_pauseparam
= hns_ae_get_pauseparam
,
810 .set_autoneg
= hns_ae_set_autoneg
,
811 .get_autoneg
= hns_ae_get_autoneg
,
812 .set_pauseparam
= hns_ae_set_pauseparam
,
813 .get_coalesce_usecs
= hns_ae_get_coalesce_usecs
,
814 .get_rx_max_coalesced_frames
= hns_ae_get_rx_max_coalesced_frames
,
815 .set_coalesce_usecs
= hns_ae_set_coalesce_usecs
,
816 .set_coalesce_frames
= hns_ae_set_coalesce_frames
,
817 .set_promisc_mode
= hns_ae_set_promisc_mode
,
818 .set_mac_addr
= hns_ae_set_mac_address
,
819 .set_mc_addr
= hns_ae_set_multicast_one
,
820 .set_mtu
= hns_ae_set_mtu
,
821 .update_stats
= hns_ae_update_stats
,
822 .set_tso_stats
= hns_ae_set_tso_stats
,
823 .get_stats
= hns_ae_get_stats
,
824 .get_strings
= hns_ae_get_strings
,
825 .get_sset_count
= hns_ae_get_sset_count
,
826 .update_led_status
= hns_ae_update_led_status
,
827 .set_led_id
= hns_ae_cpld_set_led_id
,
828 .get_regs
= hns_ae_get_regs
,
829 .get_regs_len
= hns_ae_get_regs_len
,
830 .get_rss_key_size
= hns_ae_get_rss_key_size
,
831 .get_rss_indir_size
= hns_ae_get_rss_indir_size
,
832 .get_rss
= hns_ae_get_rss
,
833 .set_rss
= hns_ae_set_rss
836 int hns_dsaf_ae_init(struct dsaf_device
*dsaf_dev
)
838 struct hnae_ae_dev
*ae_dev
= &dsaf_dev
->ae_dev
;
839 static atomic_t id
= ATOMIC_INIT(-1);
841 switch (dsaf_dev
->dsaf_ver
) {
843 hns_dsaf_ops
.toggle_ring_irq
= hns_ae_toggle_ring_irq
;
846 hns_dsaf_ops
.toggle_ring_irq
= hns_aev2_toggle_ring_irq
;
852 snprintf(ae_dev
->name
, AE_NAME_SIZE
, "%s%d", DSAF_DEVICE_NAME
,
853 (int)atomic_inc_return(&id
));
854 ae_dev
->ops
= &hns_dsaf_ops
;
855 ae_dev
->dev
= dsaf_dev
->dev
;
857 return hnae_ae_register(ae_dev
, THIS_MODULE
);
860 void hns_dsaf_ae_uninit(struct dsaf_device
*dsaf_dev
)
862 hnae_ae_unregister(&dsaf_dev
->ae_dev
);