net/i40e: fix request queue in VF
[dpdk.git] / drivers / net / ipn3ke / ipn3ke_representor.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2019 Intel Corporation
3  */
4
5 #include <stdint.h>
6 #include <unistd.h>
7
8 #include <rte_bus_pci.h>
9 #include <rte_ethdev.h>
10 #include <rte_pci.h>
11 #include <rte_malloc.h>
12
13 #include <rte_mbuf.h>
14 #include <rte_sched.h>
15 #include <rte_ethdev_driver.h>
16 #include <rte_spinlock.h>
17
18 #include <rte_io.h>
19 #include <rte_rawdev.h>
20 #include <rte_rawdev_pmd.h>
21 #include <rte_bus_ifpga.h>
22 #include <ifpga_logs.h>
23
24 #include "ipn3ke_rawdev_api.h"
25 #include "ipn3ke_flow.h"
26 #include "ipn3ke_logs.h"
27 #include "ipn3ke_ethdev.h"
28
29 static int ipn3ke_rpst_scan_num;
30 static pthread_t ipn3ke_rpst_scan_thread;
31
32 /** Double linked list of representor port. */
33 TAILQ_HEAD(ipn3ke_rpst_list, ipn3ke_rpst);
34
35 static struct ipn3ke_rpst_list ipn3ke_rpst_list =
36         TAILQ_HEAD_INITIALIZER(ipn3ke_rpst_list);
37
38 static rte_spinlock_t ipn3ke_link_notify_list_lk = RTE_SPINLOCK_INITIALIZER;
39
40 static int
41 ipn3ke_rpst_link_check(struct ipn3ke_rpst *rpst);
42
43 static void
44 ipn3ke_rpst_dev_infos_get(struct rte_eth_dev *ethdev,
45         struct rte_eth_dev_info *dev_info)
46 {
47         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
48         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
49
50         dev_info->speed_capa =
51                 (hw->retimer.mac_type ==
52                         IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) ?
53                 ETH_LINK_SPEED_10G :
54                 ((hw->retimer.mac_type ==
55                         IFPGA_RAWDEV_RETIMER_MAC_TYPE_25GE_25GAUI) ?
56                 ETH_LINK_SPEED_25G :
57                 ETH_LINK_SPEED_AUTONEG);
58
59         dev_info->max_rx_queues  = 1;
60         dev_info->max_tx_queues  = 1;
61         dev_info->min_rx_bufsize = IPN3KE_AFU_BUF_SIZE_MIN;
62         dev_info->max_rx_pktlen  = IPN3KE_AFU_FRAME_SIZE_MAX;
63         dev_info->max_mac_addrs  = hw->port_num;
64         dev_info->max_vfs = 0;
65         dev_info->default_txconf = (struct rte_eth_txconf) {
66                 .offloads = 0,
67         };
68         dev_info->rx_queue_offload_capa = 0;
69         dev_info->rx_offload_capa =
70                 DEV_RX_OFFLOAD_VLAN_STRIP |
71                 DEV_RX_OFFLOAD_QINQ_STRIP |
72                 DEV_RX_OFFLOAD_IPV4_CKSUM |
73                 DEV_RX_OFFLOAD_UDP_CKSUM |
74                 DEV_RX_OFFLOAD_TCP_CKSUM |
75                 DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM |
76                 DEV_RX_OFFLOAD_VLAN_EXTEND |
77                 DEV_RX_OFFLOAD_VLAN_FILTER |
78                 DEV_RX_OFFLOAD_JUMBO_FRAME;
79
80         dev_info->tx_queue_offload_capa = DEV_TX_OFFLOAD_MBUF_FAST_FREE;
81         dev_info->tx_offload_capa =
82                 DEV_TX_OFFLOAD_VLAN_INSERT |
83                 DEV_TX_OFFLOAD_QINQ_INSERT |
84                 DEV_TX_OFFLOAD_IPV4_CKSUM |
85                 DEV_TX_OFFLOAD_UDP_CKSUM |
86                 DEV_TX_OFFLOAD_TCP_CKSUM |
87                 DEV_TX_OFFLOAD_SCTP_CKSUM |
88                 DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
89                 DEV_TX_OFFLOAD_TCP_TSO |
90                 DEV_TX_OFFLOAD_VXLAN_TNL_TSO |
91                 DEV_TX_OFFLOAD_GRE_TNL_TSO |
92                 DEV_TX_OFFLOAD_IPIP_TNL_TSO |
93                 DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
94                 DEV_TX_OFFLOAD_MULTI_SEGS |
95                 dev_info->tx_queue_offload_capa;
96
97         dev_info->dev_capa =
98                 RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
99                 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
100
101         dev_info->switch_info.name = ethdev->device->name;
102         dev_info->switch_info.domain_id = rpst->switch_domain_id;
103         dev_info->switch_info.port_id = rpst->port_id;
104 }
105
106 static int
107 ipn3ke_rpst_dev_configure(__rte_unused struct rte_eth_dev *dev)
108 {
109         return 0;
110 }
111
112 static int
113 ipn3ke_rpst_dev_start(struct rte_eth_dev *dev)
114 {
115         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(dev);
116         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(dev);
117         struct rte_rawdev *rawdev;
118         uint64_t base_mac;
119         uint32_t val;
120         char attr_name[IPN3KE_RAWDEV_ATTR_LEN_MAX];
121
122         rawdev = hw->rawdev;
123
124         memset(attr_name, 0, sizeof(attr_name));
125         snprintf(attr_name, IPN3KE_RAWDEV_ATTR_LEN_MAX, "%s",
126                         "LineSideBaseMAC");
127         rawdev->dev_ops->attr_get(rawdev, attr_name, &base_mac);
128         rte_ether_addr_copy((struct rte_ether_addr *)&base_mac,
129                         &rpst->mac_addr);
130
131         rte_ether_addr_copy(&rpst->mac_addr, &dev->data->mac_addrs[0]);
132         dev->data->mac_addrs->addr_bytes[RTE_ETHER_ADDR_LEN - 1] =
133                 (uint8_t)rpst->port_id + 1;
134
135         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
136                 /* Set mac address */
137                 rte_memcpy(((char *)(&val)),
138                         (char *)&dev->data->mac_addrs->addr_bytes[0],
139                         sizeof(uint32_t));
140                 (*hw->f_mac_write)(hw,
141                                 val,
142                                 IPN3KE_MAC_PRIMARY_MAC_ADDR0,
143                                 rpst->port_id,
144                                 0);
145                 rte_memcpy(((char *)(&val)),
146                         (char *)&dev->data->mac_addrs->addr_bytes[4],
147                         sizeof(uint16_t));
148                 (*hw->f_mac_write)(hw,
149                                 val,
150                                 IPN3KE_MAC_PRIMARY_MAC_ADDR1,
151                                 rpst->port_id,
152                                 0);
153
154                 /* Enable the TX path */
155                 ipn3ke_xmac_tx_enable(hw, rpst->port_id, 0);
156
157                 /* Disables source address override */
158                 ipn3ke_xmac_smac_ovd_dis(hw, rpst->port_id, 0);
159
160                 /* Enable the RX path */
161                 ipn3ke_xmac_rx_enable(hw, rpst->port_id, 0);
162
163                 /* Clear line side TX statistics counters */
164                 ipn3ke_xmac_tx_clr_10G_stcs(hw, rpst->port_id, 0);
165
166                 /* Clear line side RX statistics counters */
167                 ipn3ke_xmac_rx_clr_10G_stcs(hw, rpst->port_id, 0);
168
169                 /* Clear NIC side TX statistics counters */
170                 ipn3ke_xmac_tx_clr_10G_stcs(hw, rpst->port_id, 1);
171
172                 /* Clear NIC side RX statistics counters */
173                 ipn3ke_xmac_rx_clr_10G_stcs(hw, rpst->port_id, 1);
174         } else if (hw->retimer.mac_type ==
175                                 IFPGA_RAWDEV_RETIMER_MAC_TYPE_25GE_25GAUI) {
176                 /* Clear line side TX statistics counters */
177                 ipn3ke_xmac_tx_clr_25G_stcs(hw, rpst->port_id, 0);
178
179                 /* Clear line side RX statistics counters */
180                 ipn3ke_xmac_rx_clr_25G_stcs(hw, rpst->port_id, 0);
181
182                 /* Clear NIC side TX statistics counters */
183                 ipn3ke_xmac_tx_clr_25G_stcs(hw, rpst->port_id, 1);
184
185                 /* Clear NIC side RX statistics counters */
186                 ipn3ke_xmac_rx_clr_25G_stcs(hw, rpst->port_id, 1);
187         }
188
189         ipn3ke_rpst_link_update(dev, 0);
190
191         return 0;
192 }
193
194 static void
195 ipn3ke_rpst_dev_stop(struct rte_eth_dev *dev)
196 {
197         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(dev);
198         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(dev);
199
200         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
201                 /* Disable the TX path */
202                 ipn3ke_xmac_tx_disable(hw, rpst->port_id, 0);
203
204                 /* Disable the RX path */
205                 ipn3ke_xmac_rx_disable(hw, rpst->port_id, 0);
206         }
207 }
208
209 static void
210 ipn3ke_rpst_dev_close(struct rte_eth_dev *dev)
211 {
212         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(dev);
213         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(dev);
214
215         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
216                 /* Disable the TX path */
217                 ipn3ke_xmac_tx_disable(hw, rpst->port_id, 0);
218
219                 /* Disable the RX path */
220                 ipn3ke_xmac_rx_disable(hw, rpst->port_id, 0);
221         }
222 }
223
224 /*
225  * Reset PF device only to re-initialize resources in PMD layer
226  */
227 static int
228 ipn3ke_rpst_dev_reset(struct rte_eth_dev *dev)
229 {
230         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(dev);
231         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(dev);
232
233         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
234                 /* Disable the TX path */
235                 ipn3ke_xmac_tx_disable(hw, rpst->port_id, 0);
236
237                 /* Disable the RX path */
238                 ipn3ke_xmac_rx_disable(hw, rpst->port_id, 0);
239         }
240
241         return 0;
242 }
243
244 static int
245 ipn3ke_rpst_rx_queue_start(__rte_unused struct rte_eth_dev *dev,
246         __rte_unused uint16_t rx_queue_id)
247 {
248         return 0;
249 }
250
251 static int
252 ipn3ke_rpst_rx_queue_stop(__rte_unused struct rte_eth_dev *dev,
253         __rte_unused uint16_t rx_queue_id)
254 {
255         return 0;
256 }
257
258 static int
259 ipn3ke_rpst_tx_queue_start(__rte_unused struct rte_eth_dev *dev,
260         __rte_unused uint16_t tx_queue_id)
261 {
262         return 0;
263 }
264
265 static int
266 ipn3ke_rpst_tx_queue_stop(__rte_unused struct rte_eth_dev *dev,
267         __rte_unused uint16_t tx_queue_id)
268 {
269         return 0;
270 }
271
272 static int
273 ipn3ke_rpst_rx_queue_setup(__rte_unused struct rte_eth_dev *dev,
274         __rte_unused uint16_t queue_idx, __rte_unused uint16_t nb_desc,
275         __rte_unused unsigned int socket_id,
276         __rte_unused const struct rte_eth_rxconf *rx_conf,
277         __rte_unused struct rte_mempool *mp)
278 {
279         return 0;
280 }
281
282 static void
283 ipn3ke_rpst_rx_queue_release(__rte_unused void *rxq)
284 {
285 }
286
287 static int
288 ipn3ke_rpst_tx_queue_setup(__rte_unused struct rte_eth_dev *dev,
289         __rte_unused uint16_t queue_idx, __rte_unused uint16_t nb_desc,
290         __rte_unused unsigned int socket_id,
291         __rte_unused const struct rte_eth_txconf *tx_conf)
292 {
293         return 0;
294 }
295
296 static void
297 ipn3ke_rpst_tx_queue_release(__rte_unused void *txq)
298 {
299 }
300
301 /* Statistics collected by each port, VSI, VEB, and S-channel */
302 struct ipn3ke_rpst_eth_stats {
303         uint64_t tx_bytes;               /* gotc */
304         uint64_t tx_multicast;           /* mptc */
305         uint64_t tx_broadcast;           /* bptc */
306         uint64_t tx_unicast;             /* uptc */
307         uint64_t tx_discards;            /* tdpc */
308         uint64_t tx_errors;              /* tepc */
309         uint64_t rx_bytes;               /* gorc */
310         uint64_t rx_multicast;           /* mprc */
311         uint64_t rx_broadcast;           /* bprc */
312         uint64_t rx_unicast;             /* uprc */
313         uint64_t rx_discards;            /* rdpc */
314         uint64_t rx_unknown_protocol;    /* rupp */
315 };
316
317 /* store statistics names and its offset in stats structure */
318 struct ipn3ke_rpst_xstats_name_offset {
319         char name[RTE_ETH_XSTATS_NAME_SIZE];
320         unsigned int offset;
321 };
322
323 static const struct ipn3ke_rpst_xstats_name_offset
324 ipn3ke_rpst_stats_strings[] = {
325         {"tx_multicast_packets",          offsetof(struct ipn3ke_rpst_eth_stats,
326                                                         tx_multicast)},
327         {"tx_broadcast_packets",          offsetof(struct ipn3ke_rpst_eth_stats,
328                                                         tx_broadcast)},
329         {"tx_unicast_packets",            offsetof(struct ipn3ke_rpst_eth_stats,
330                                                         tx_unicast)},
331         {"tx_dropped_packets",            offsetof(struct ipn3ke_rpst_eth_stats,
332                                                         tx_discards)},
333         {"rx_multicast_packets",          offsetof(struct ipn3ke_rpst_eth_stats,
334                                                         rx_multicast)},
335         {"rx_broadcast_packets",          offsetof(struct ipn3ke_rpst_eth_stats,
336                                                         rx_broadcast)},
337         {"rx_unicast_packets",            offsetof(struct ipn3ke_rpst_eth_stats,
338                                                         rx_unicast)},
339         {"rx_dropped_packets",            offsetof(struct ipn3ke_rpst_eth_stats,
340                                                         rx_discards)},
341         {"rx_unknown_protocol_packets", offsetof(struct ipn3ke_rpst_eth_stats,
342                                                         rx_unknown_protocol)},
343 };
344
345 #define IPN3KE_RPST_ETH_XSTATS_CNT (sizeof(ipn3ke_rpst_stats_strings) / \
346                 sizeof(ipn3ke_rpst_stats_strings[0]))
347
348 #define IPN3KE_RPST_PRIO_XSTATS_CNT    8
349
350 /* Statistics collected by the MAC */
351 struct ipn3ke_rpst_hw_port_stats {
352         /* eth stats collected by the port */
353         struct ipn3ke_rpst_eth_stats eth;
354
355         /* additional port specific stats */
356         uint64_t tx_dropped_link_down;
357         uint64_t crc_errors;
358         uint64_t illegal_bytes;
359         uint64_t error_bytes;
360         uint64_t mac_local_faults;
361         uint64_t mac_remote_faults;
362         uint64_t rx_length_errors;
363         uint64_t link_xon_rx;
364         uint64_t link_xoff_rx;
365         uint64_t priority_xon_rx[IPN3KE_RPST_PRIO_XSTATS_CNT];
366         uint64_t priority_xoff_rx[IPN3KE_RPST_PRIO_XSTATS_CNT];
367         uint64_t link_xon_tx;
368         uint64_t link_xoff_tx;
369         uint64_t priority_xon_tx[IPN3KE_RPST_PRIO_XSTATS_CNT];
370         uint64_t priority_xoff_tx[IPN3KE_RPST_PRIO_XSTATS_CNT];
371         uint64_t priority_xon_2_xoff[IPN3KE_RPST_PRIO_XSTATS_CNT];
372         uint64_t rx_size_64;
373         uint64_t rx_size_65_127;
374         uint64_t rx_size_128_255;
375         uint64_t rx_size_256_511;
376         uint64_t rx_size_512_1023;
377         uint64_t rx_size_1024_1518;
378         uint64_t rx_size_big;
379         uint64_t rx_undersize;
380         uint64_t rx_fragments;
381         uint64_t rx_oversize;
382         uint64_t rx_jabber;
383         uint64_t tx_size_64;
384         uint64_t tx_size_65_127;
385         uint64_t tx_size_128_255;
386         uint64_t tx_size_256_511;
387         uint64_t tx_size_512_1023;
388         uint64_t tx_size_1024_1518;
389         uint64_t tx_size_1519_to_max;
390         uint64_t mac_short_packet_dropped;
391         uint64_t checksum_error;
392         /* flow director stats */
393         uint64_t fd_atr_match;
394         uint64_t fd_sb_match;
395         uint64_t fd_atr_tunnel_match;
396         uint32_t fd_atr_status;
397         uint32_t fd_sb_status;
398         /* EEE LPI */
399         uint32_t tx_lpi_status;
400         uint32_t rx_lpi_status;
401         uint64_t tx_lpi_count;
402         uint64_t rx_lpi_count;
403 };
404
405 static const struct ipn3ke_rpst_xstats_name_offset
406 ipn3ke_rpst_hw_port_strings[] = {
407         {"tx_link_down_dropped",      offsetof(struct ipn3ke_rpst_hw_port_stats,
408                                                 tx_dropped_link_down)},
409         {"rx_crc_errors",             offsetof(struct ipn3ke_rpst_hw_port_stats,
410                                                 crc_errors)},
411         {"rx_illegal_byte_errors",    offsetof(struct ipn3ke_rpst_hw_port_stats,
412                                                 illegal_bytes)},
413         {"rx_error_bytes",            offsetof(struct ipn3ke_rpst_hw_port_stats,
414                                                 error_bytes)},
415         {"mac_local_errors",          offsetof(struct ipn3ke_rpst_hw_port_stats,
416                                                 mac_local_faults)},
417         {"mac_remote_errors",         offsetof(struct ipn3ke_rpst_hw_port_stats,
418                                                 mac_remote_faults)},
419         {"rx_length_errors",          offsetof(struct ipn3ke_rpst_hw_port_stats,
420                                                 rx_length_errors)},
421         {"tx_xon_packets",            offsetof(struct ipn3ke_rpst_hw_port_stats,
422                                                 link_xon_tx)},
423         {"rx_xon_packets",            offsetof(struct ipn3ke_rpst_hw_port_stats,
424                                                 link_xon_rx)},
425         {"tx_xoff_packets",           offsetof(struct ipn3ke_rpst_hw_port_stats,
426                                                 link_xoff_tx)},
427         {"rx_xoff_packets",           offsetof(struct ipn3ke_rpst_hw_port_stats,
428                                                 link_xoff_rx)},
429         {"rx_size_64_packets",        offsetof(struct ipn3ke_rpst_hw_port_stats,
430                                                 rx_size_64)},
431         {"rx_size_65_to_127_packets", offsetof(struct ipn3ke_rpst_hw_port_stats,
432                                                 rx_size_65_127)},
433         {"rx_size_128_to_255_packets",
434                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
435                                          rx_size_128_255)},
436         {"rx_size_256_to_511_packets",
437                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
438                                          rx_size_256_511)},
439         {"rx_size_512_to_1023_packets",
440                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
441                                          rx_size_512_1023)},
442         {"rx_size_1024_to_1518_packets",
443                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
444                                          rx_size_1024_1518)},
445         {"rx_size_1519_to_max_packets",
446                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
447                                          rx_size_big)},
448         {"rx_undersized_errors",      offsetof(struct ipn3ke_rpst_hw_port_stats,
449                                                rx_undersize)},
450         {"rx_oversize_errors",        offsetof(struct ipn3ke_rpst_hw_port_stats,
451                                                rx_oversize)},
452         {"rx_mac_short_dropped",      offsetof(struct ipn3ke_rpst_hw_port_stats,
453                                                mac_short_packet_dropped)},
454         {"rx_fragmented_errors",      offsetof(struct ipn3ke_rpst_hw_port_stats,
455                                                rx_fragments)},
456         {"rx_jabber_errors",          offsetof(struct ipn3ke_rpst_hw_port_stats,
457                                                rx_jabber)},
458         {"tx_size_64_packets",        offsetof(struct ipn3ke_rpst_hw_port_stats,
459                                                tx_size_64)},
460         {"tx_size_65_to_127_packets",
461                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
462                                          tx_size_65_127)},
463         {"tx_size_128_to_255_packets",
464                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
465                                          tx_size_128_255)},
466         {"tx_size_256_to_511_packets",
467                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
468                                          tx_size_256_511)},
469         {"tx_size_512_to_1023_packets",
470                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
471                                          tx_size_512_1023)},
472         {"tx_size_1024_to_1518_packets",
473                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
474                                          tx_size_1024_1518)},
475         {"tx_size_1519_to_max_packets",
476                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
477                                          tx_size_1519_to_max)},
478         {"rx_flow_director_atr_match_packets",
479                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
480                                          fd_atr_match)},
481         {"rx_flow_director_sb_match_packets",
482                                 offsetof(struct ipn3ke_rpst_hw_port_stats,
483                                          fd_sb_match)},
484         {"tx_low_power_idle_status",  offsetof(struct ipn3ke_rpst_hw_port_stats,
485                                                tx_lpi_status)},
486         {"rx_low_power_idle_status",  offsetof(struct ipn3ke_rpst_hw_port_stats,
487                                                rx_lpi_status)},
488         {"tx_low_power_idle_count",   offsetof(struct ipn3ke_rpst_hw_port_stats,
489                                                tx_lpi_count)},
490         {"rx_low_power_idle_count",   offsetof(struct ipn3ke_rpst_hw_port_stats,
491                                                rx_lpi_count)},
492 };
493
494 #define IPN3KE_RPST_HW_PORT_XSTATS_CNT (sizeof(ipn3ke_rpst_hw_port_strings) \
495                 / sizeof(ipn3ke_rpst_hw_port_strings[0]))
496
497 static const struct ipn3ke_rpst_xstats_name_offset
498 ipn3ke_rpst_rxq_prio_strings[] = {
499         {"xon_packets",               offsetof(struct ipn3ke_rpst_hw_port_stats,
500                                                priority_xon_rx)},
501         {"xoff_packets",              offsetof(struct ipn3ke_rpst_hw_port_stats,
502                                                priority_xoff_rx)},
503 };
504
505 #define IPN3KE_RPST_RXQ_PRIO_XSTATS_CNT (sizeof(ipn3ke_rpst_rxq_prio_strings) \
506                 / sizeof(ipn3ke_rpst_rxq_prio_strings[0]))
507
508 static const struct ipn3ke_rpst_xstats_name_offset
509 ipn3ke_rpst_txq_prio_strings[] = {
510         {"xon_packets",               offsetof(struct ipn3ke_rpst_hw_port_stats,
511                                                priority_xon_tx)},
512         {"xoff_packets",              offsetof(struct ipn3ke_rpst_hw_port_stats,
513                                                priority_xoff_tx)},
514         {"xon_to_xoff_packets",       offsetof(struct ipn3ke_rpst_hw_port_stats,
515                                                priority_xon_2_xoff)},
516 };
517
518 #define IPN3KE_RPST_TXQ_PRIO_XSTATS_CNT (sizeof(ipn3ke_rpst_txq_prio_strings) \
519                 / sizeof(ipn3ke_rpst_txq_prio_strings[0]))
520
521 static uint32_t
522 ipn3ke_rpst_xstats_calc_num(void)
523 {
524         return IPN3KE_RPST_ETH_XSTATS_CNT
525                 + IPN3KE_RPST_HW_PORT_XSTATS_CNT
526                 + (IPN3KE_RPST_RXQ_PRIO_XSTATS_CNT
527                         * IPN3KE_RPST_PRIO_XSTATS_CNT)
528                 + (IPN3KE_RPST_TXQ_PRIO_XSTATS_CNT
529                         * IPN3KE_RPST_PRIO_XSTATS_CNT);
530 }
531
532 static void
533 ipn3ke_rpst_25g_nic_side_tx_stats_reset(struct ipn3ke_hw *hw,
534 uint16_t port_id)
535 {
536         uint32_t tmp = 0x00000001;
537         /* Bit[0]: Software can set this bit to the value of 1
538          * to reset all of the TX statistics registers at the same time.
539          * This bit is selfclearing.
540          */
541         (*hw->f_mac_write)(hw,
542                         tmp,
543                         IPN3KE_25G_TX_STATISTICS_CONFIG,
544                         port_id,
545                         1);
546
547         while (tmp & 0x00000001) {
548                 tmp = 0x00000000;
549                 (*hw->f_mac_read)(hw,
550                                 &tmp,
551                                 IPN3KE_25G_TX_STATISTICS_CONFIG,
552                                 port_id,
553                                 1);
554                 if (tmp & 0x00000001)
555                         usleep(5);
556                 else
557                         return;
558         }
559 }
560
561 static void
562 ipn3ke_rpst_25g_nic_side_rx_stats_reset(struct ipn3ke_hw *hw,
563 uint16_t port_id)
564 {
565         uint32_t tmp = 0x00000001;
566         /* Bit[0]: Software can set this bit to the value of 1
567          * to reset all of the RX statistics registers at the same time.
568          * This bit is selfclearing.
569          */
570         (*hw->f_mac_write)(hw,
571                         tmp,
572                         IPN3KE_25G_RX_STATISTICS_CONFIG,
573                         port_id,
574                         1);
575
576         while (tmp & 0x00000001) {
577                 tmp = 0x00000000;
578                 (*hw->f_mac_read)(hw,
579                                 &tmp,
580                                 IPN3KE_25G_RX_STATISTICS_CONFIG,
581                                 port_id,
582                                 1);
583                 if (tmp & 0x00000001)
584                         usleep(5);
585                 else
586                         return;
587         }
588 }
589
590 static void
591 ipn3ke_rpst_10g_nic_side_tx_stats_reset(struct ipn3ke_hw *hw,
592 uint16_t port_id)
593 {
594         uint32_t tmp;
595
596         /*Bit [0]: Set this register to 1 to clear all TX statistics
597          *counters.
598          *The IP core clears this bit when all counters are cleared.
599          *Bits [31:1]: Reserved.
600          */
601         tmp = 0x00000000;
602         (*hw->f_mac_read)(hw,
603                 &tmp,
604                 IPN3KE_10G_TX_STATS_CLR,
605                 port_id,
606                 1);
607         tmp |= 0x00000001;
608         (*hw->f_mac_write)(hw,
609                 tmp,
610                 IPN3KE_10G_TX_STATS_CLR,
611                 port_id,
612                 1);
613 }
614
615 static void
616 ipn3ke_rpst_10g_nic_side_rx_stats_reset(struct ipn3ke_hw *hw,
617 uint16_t port_id)
618 {
619         uint32_t tmp;
620
621         /*Bit [0]: Set this register to 1 to clear all RX statistics
622          *counters.
623          *The IP core clears this bit when all counters are cleared.
624          *Bits [31:1]: Reserved
625          */
626         tmp = 0x00000000;
627         (*hw->f_mac_read)(hw,
628                 &tmp,
629                 IPN3KE_10G_RX_STATS_CLR,
630                 port_id,
631                 1);
632         tmp |= 0x00000001;
633         (*hw->f_mac_write)(hw,
634                 tmp,
635                 IPN3KE_10G_RX_STATS_CLR,
636                 port_id,
637                 1);
638 }
639
640 static uint64_t
641 ipn3ke_rpst_read_64bits_statistics_register(uint32_t addr_lo,
642 uint32_t addr_hi, struct ipn3ke_hw *hw, uint16_t port_id)
643 {
644         uint32_t statistics_lo = 0x00000000;
645         uint32_t statistics_hi = 0x00000000;
646         uint64_t statistics = 0x0000000000000000;
647
648         (*hw->f_mac_read)(hw,
649                         &statistics_lo,
650                         addr_lo,
651                         port_id,
652                         0);
653
654         (*hw->f_mac_read)(hw,
655                         &statistics_hi,
656                         addr_hi,
657                         port_id,
658                         0);
659
660         statistics += statistics_hi;
661         statistics = statistics << IPN3KE_REGISTER_WIDTH;
662         statistics += statistics_lo;
663         return statistics;
664
665 }
666
667 static int
668 ipn3ke_rpst_read_25g_lineside_stats_registers
669 (struct ipn3ke_hw *hw,
670 uint16_t port_id,
671 struct ipn3ke_rpst_hw_port_stats *hw_stats)
672 {
673         uint32_t tmp;
674         uint64_t statistics;
675
676         memset(hw_stats, 0, sizeof(*hw_stats));
677
678         /*check Tx statistics is real time.
679          *if statistics has been paused, make it real time.
680          */
681         tmp = 0x00000000;
682         (*hw->f_mac_read)(hw,
683                         &tmp,
684                         IPN3KE_25G_TX_STATISTICS_CONFIG,
685                         port_id,
686                         0);
687
688         if (tmp & IPN3KE_25G_TX_STATISTICS_CONFIG_SHADOW_REQUEST_MASK) {
689                 tmp &= 0xfffffffb;
690                 (*hw->f_mac_write)(hw,
691                         tmp,
692                         IPN3KE_25G_TX_STATISTICS_CONFIG,
693                         port_id,
694                         0);
695         }
696
697         tmp = 0x00000000;
698         (*hw->f_mac_read)(hw,
699                 &tmp,
700                 IPN3KE_25G_TX_STATISTICS_STATUS,
701                 port_id,
702                 1);
703         if (tmp & IPN3KE_25G_TX_STATISTICS_STATUS_SHADOW_REQUEST_MASK) {
704                 tmp = 0x00000000;
705                 (*hw->f_mac_read)(hw,
706                         &tmp,
707                         IPN3KE_25G_TX_STATISTICS_CONFIG,
708                         port_id,
709                         0);
710                 tmp &= 0xfffffffb;
711                 (*hw->f_mac_write)(hw,
712                         tmp,
713                         IPN3KE_25G_TX_STATISTICS_CONFIG,
714                         port_id,
715                         0);
716         }
717
718         /*check Rx statistics is real time.
719          *if statistics has been paused, make it real time.
720          */
721         tmp = 0x00000000;
722         (*hw->f_mac_read)(hw,
723                         &tmp,
724                         IPN3KE_25G_RX_STATISTICS_CONFIG,
725                         port_id,
726                         0);
727         if (tmp & IPN3KE_25G_RX_STATISTICS_CONFIG_SHADOW_REQUEST_MASK) {
728                 tmp &= 0xfffffffb;
729                 (*hw->f_mac_write)(hw,
730                         tmp,
731                         IPN3KE_25G_RX_STATISTICS_CONFIG,
732                         port_id,
733                         0);
734         }
735
736         tmp = 0x00000000;
737         (*hw->f_mac_read)(hw,
738                 &tmp,
739                 IPN3KE_25G_RX_STATISTICS_STATUS,
740                 port_id,
741                 0);
742
743         if (tmp & IPN3KE_25G_RX_STATISTICS_STATUS_SHADOW_REQUEST_MASK) {
744                 tmp = 0x00000000;
745                 (*hw->f_mac_read)(hw,
746                         &tmp,
747                         IPN3KE_25G_RX_STATISTICS_CONFIG,
748                         port_id,
749                         0);
750                 tmp &= 0xfffffffb;
751                 (*hw->f_mac_write)(hw,
752                         tmp,
753                         IPN3KE_25G_RX_STATISTICS_CONFIG,
754                         port_id,
755                         0);
756         }
757
758         /* pause Tx counter to read the statistics */
759         tmp = 0x00000000;
760         (*hw->f_mac_read)(hw,
761                 &tmp,
762                 IPN3KE_25G_TX_STATISTICS_CONFIG,
763                 port_id,
764                 0);
765         tmp |= 0x00000004;
766         (*hw->f_mac_write)(hw,
767                 tmp,
768                 IPN3KE_25G_TX_STATISTICS_CONFIG,
769                 port_id,
770                 0);
771
772         /* pause Rx counter to read the statistics */
773         tmp = 0x00000000;
774         (*hw->f_mac_read)(hw,
775                 &tmp,
776                 IPN3KE_25G_RX_STATISTICS_CONFIG,
777                 port_id,
778                 0);
779         tmp |= 0x00000004;
780         (*hw->f_mac_write)(hw,
781                 tmp,
782                 IPN3KE_25G_RX_STATISTICS_CONFIG,
783                 port_id,
784                 0);
785
786         /*Number of transmitted frames less than 64 bytes
787          *and reporting a CRC error
788          */
789         statistics = ipn3ke_rpst_read_64bits_statistics_register(
790                 IPN3KE_25G_CNTR_TX_FRAGMENTS_LO,
791                 IPN3KE_25G_CNTR_TX_FRAGMENTS_HI,
792                 hw, port_id);
793         hw_stats->eth.tx_errors += statistics;
794         hw_stats->crc_errors += statistics;
795
796         /*Number of transmitted oversized frames reporting a CRC error*/
797         statistics = ipn3ke_rpst_read_64bits_statistics_register(
798                 IPN3KE_25G_CNTR_TX_JABBERS_LO,
799                 IPN3KE_25G_CNTR_TX_JABBERS_HI,
800                 hw, port_id);
801         hw_stats->eth.tx_errors += statistics;
802         hw_stats->crc_errors += statistics;
803
804         /* Number of transmitted packets with FCS errors */
805         statistics = ipn3ke_rpst_read_64bits_statistics_register(
806                 IPN3KE_25G_CNTR_TX_FCS_LO,
807                 IPN3KE_25G_CNTR_TX_FCS_HI,
808                 hw, port_id);
809         hw_stats->eth.tx_errors += statistics;
810         hw_stats->checksum_error += statistics;
811
812         /*Number of transmitted frames with a frame of length at
813          *least 64 reporting a CRC error
814          */
815         statistics = ipn3ke_rpst_read_64bits_statistics_register(
816                 IPN3KE_25G_CNTR_TX_CRCERR_LO,
817                 IPN3KE_25G_CNTR_TX_CRCERR_HI,
818                 hw, port_id);
819         hw_stats->eth.tx_errors += statistics;
820         hw_stats->crc_errors += statistics;
821
822         /*Number of errored multicast frames transmitted,
823          *excluding control frames
824          */
825         statistics = ipn3ke_rpst_read_64bits_statistics_register(
826                 IPN3KE_25G_CNTR_TX_MCAST_DATA_ERR_LO,
827                 IPN3KE_25G_CNTR_TX_MCAST_DATA_ERR_HI,
828                 hw, port_id);
829         hw_stats->eth.tx_errors += statistics;
830
831         /*Number of errored broadcast frames transmitted,
832          *excluding control frames
833          */
834         statistics = ipn3ke_rpst_read_64bits_statistics_register(
835                 IPN3KE_25G_CNTR_TX_BCAST_DATA_ERR_LO,
836                 IPN3KE_25G_CNTR_TX_BCAST_DATA_ERR_HI,
837                 hw, port_id);
838         hw_stats->eth.tx_errors += statistics;
839
840         /*Number of errored unicast frames transmitted,
841          *excluding control frames
842          */
843         statistics = ipn3ke_rpst_read_64bits_statistics_register(
844                 IPN3KE_25G_CNTR_TX_UCAST_DATA_ERR_LO,
845                 IPN3KE_25G_CNTR_TX_UCAST_DATA_ERR_HI,
846                 hw, port_id);
847         hw_stats->eth.tx_errors += statistics;
848
849         /* Number of errored multicast control frames transmitted */
850         statistics = ipn3ke_rpst_read_64bits_statistics_register(
851                 IPN3KE_25G_CNTR_TX_MCAST_CTRL_ERR_LO,
852                 IPN3KE_25G_CNTR_TX_MCAST_CTRL_ERR_HI,
853                 hw, port_id);
854         hw_stats->eth.tx_errors += statistics;
855
856         /* Number of errored broadcast control frames transmitted */
857         statistics = ipn3ke_rpst_read_64bits_statistics_register(
858                 IPN3KE_25G_CNTR_TX_BCAST_CTRL_ERR_LO,
859                 IPN3KE_25G_CNTR_TX_BCAST_CTRL_ERR_HI,
860                 hw, port_id);
861         hw_stats->eth.tx_errors += statistics;
862
863         /* Number of errored unicast control frames transmitted */
864         statistics = ipn3ke_rpst_read_64bits_statistics_register(
865                 IPN3KE_25G_CNTR_TX_UCAST_CTRL_ERR_LO,
866                 IPN3KE_25G_CNTR_TX_UCAST_CTRL_ERR_HI,
867                 hw, port_id);
868         hw_stats->eth.tx_errors += statistics;
869
870         /* Number of errored pause frames transmitted */
871         statistics = ipn3ke_rpst_read_64bits_statistics_register(
872                 IPN3KE_25G_CNTR_TX_PAUSE_ERR_LO,
873                 IPN3KE_25G_CNTR_TX_PAUSE_ERR_HI,
874                 hw, port_id);
875         hw_stats->eth.tx_errors += statistics;
876
877         /*Number of 64-byte transmitted frames,
878          *including the CRC field but excluding the preamble
879          *and SFD bytes
880          */
881         statistics = ipn3ke_rpst_read_64bits_statistics_register(
882                 IPN3KE_25G_CNTR_TX_64B_LO,
883                 IPN3KE_25G_CNTR_TX_64B_HI,
884                 hw, port_id);
885         hw_stats->tx_size_64 += statistics;
886
887         /* Number of transmitted frames between 65 and 127 bytes */
888         statistics = ipn3ke_rpst_read_64bits_statistics_register(
889                 IPN3KE_25G_CNTR_TX_65_127B_LO,
890                 IPN3KE_25G_CNTR_TX_65_127B_HI,
891                 hw, port_id);
892         hw_stats->tx_size_65_127 += statistics;
893
894         /* Number of transmitted frames between 128 and 255 bytes */
895         statistics = ipn3ke_rpst_read_64bits_statistics_register(
896                 IPN3KE_25G_CNTR_TX_128_255B_LO,
897                 IPN3KE_25G_CNTR_TX_128_255B_HI,
898                 hw, port_id);
899         hw_stats->tx_size_128_255 += statistics;
900
901         /* Number of transmitted frames between 256 and 511 bytes */
902         statistics = ipn3ke_rpst_read_64bits_statistics_register(
903                 IPN3KE_25G_CNTR_TX_256_511B_LO,
904                 IPN3KE_25G_CNTR_TX_256_511B_HI,
905                 hw, port_id);
906         hw_stats->tx_size_256_511 += statistics;
907
908         /* Number of transmitted frames between 512 and 1023 bytes */
909         statistics = ipn3ke_rpst_read_64bits_statistics_register(
910                 IPN3KE_25G_CNTR_TX_512_1023B_LO,
911                 IPN3KE_25G_CNTR_TX_512_1023B_HI,
912                 hw, port_id);
913         hw_stats->tx_size_512_1023 += statistics;
914
915         /* Number of transmitted frames between 1024 and 1518 bytes */
916         statistics = ipn3ke_rpst_read_64bits_statistics_register(
917                 IPN3KE_25G_CNTR_TX_1024_1518B_LO,
918                 IPN3KE_25G_CNTR_TX_1024_1518B_HI,
919                 hw, port_id);
920         hw_stats->tx_size_1024_1518 += statistics;
921
922         /*Number of transmitted frames of size between 1519 bytes
923          *and the number of bytes specified in the MAX_TX_SIZE_CONFIG
924          *register
925          */
926         statistics = ipn3ke_rpst_read_64bits_statistics_register(
927                 IPN3KE_25G_CNTR_TX_1519_MAXB_LO,
928                 IPN3KE_25G_CNTR_TX_1519_MAXB_HI,
929                 hw, port_id);
930         hw_stats->tx_size_1519_to_max += statistics;
931
932         /*Number of oversized frames (frames with more bytes than the
933          *number specified in the MAX_TX_SIZE_CONFIG register)
934          *transmitted
935          */
936         statistics = ipn3ke_rpst_read_64bits_statistics_register(
937                 IPN3KE_25G_CNTR_TX_OVERSIZE_LO,
938                 IPN3KE_25G_CNTR_TX_OVERSIZE_HI,
939                 hw, port_id);
940
941         /*Number of valid multicast frames transmitted,
942          *excluding control frames
943          */
944         statistics = ipn3ke_rpst_read_64bits_statistics_register(
945                 IPN3KE_25G_CNTR_TX_MCAST_DATA_OK_LO,
946                 IPN3KE_25G_CNTR_TX_MCAST_DATA_OK_HI,
947                 hw, port_id);
948         hw_stats->eth.tx_multicast += statistics;
949
950         /*Number of valid broadcast frames transmitted,
951          *excluding control frames
952          */
953         statistics = ipn3ke_rpst_read_64bits_statistics_register(
954                 IPN3KE_25G_CNTR_TX_BCAST_DATA_OK_LO,
955                 IPN3KE_25G_CNTR_TX_BCAST_DATA_OK_HI,
956                 hw, port_id);
957         hw_stats->eth.tx_broadcast += statistics;
958
959         /*Number of valid unicast frames transmitted,
960          *excluding control frames
961          */
962         statistics = ipn3ke_rpst_read_64bits_statistics_register(
963                 IPN3KE_25G_CNTR_TX_UCAST_DATA_OK_LO,
964                 IPN3KE_25G_CNTR_TX_UCAST_DATA_OK_HI,
965                 hw, port_id);
966         hw_stats->eth.tx_unicast += statistics;
967
968         /*Number of valid multicast frames transmitted,
969          *excluding data frames
970          */
971         statistics = ipn3ke_rpst_read_64bits_statistics_register(
972                 IPN3KE_25G_CNTR_TX_MCAST_CTRL_LO,
973                 IPN3KE_25G_CNTR_TX_MCAST_CTRL_HI,
974                 hw, port_id);
975         hw_stats->eth.tx_multicast += statistics;
976
977         /*Number of valid broadcast frames transmitted,
978          *excluding data frames
979          */
980         statistics = ipn3ke_rpst_read_64bits_statistics_register(
981                 IPN3KE_25G_CNTR_TX_BCAST_CTRL_LO,
982                 IPN3KE_25G_CNTR_TX_BCAST_CTRL_HI,
983                 hw, port_id);
984         hw_stats->eth.tx_broadcast += statistics;
985
986         /*Number of valid unicast frames transmitted,
987          *excluding data frames
988          */
989         statistics = ipn3ke_rpst_read_64bits_statistics_register(
990                 IPN3KE_25G_CNTR_TX_UCAST_CTRL_LO,
991                 IPN3KE_25G_CNTR_TX_UCAST_CTRL_HI,
992                 hw, port_id);
993         hw_stats->eth.tx_unicast += statistics;
994
995         /* Number of valid pause frames transmitted */
996         statistics = ipn3ke_rpst_read_64bits_statistics_register(
997                 IPN3KE_25G_CNTR_TX_PAUSE_LO,
998                 IPN3KE_25G_CNTR_TX_PAUSE_HI,
999                 hw, port_id);
1000
1001         /*Number of transmitted runt packets. The IP core does not
1002          *transmit frames of length less than nine bytes.
1003          *The IP core pads frames of length nine bytes to 64 bytes to
1004          *extend them to 64 bytes. Therefore, this counter does not
1005          *increment in normal operating conditions.
1006          */
1007         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1008                 IPN3KE_25G_CNTR_TX_RUNT_LO,
1009                 IPN3KE_25G_CNTR_TX_RUNT_HI,
1010                 hw, port_id);
1011
1012         /*Number of transmitted payload bytes in frames with no FCS,
1013          *undersized, oversized, or payload length errors.
1014          *If VLAN detection is turned off for the TX MAC (bit[1]
1015          *of the TX_MAC_CONTROL register at offset 0x40A has
1016          *the value of 1), the IP core counts the VLAN header bytes
1017          *(4 bytes for VLAN and 8 bytes for stacked VLAN)
1018          *as payload bytes. This register is compliant with
1019          *the requirements for aOctetsTransmittedOK in section
1020          *5.2.2.1.8 of the IEEE Standard 802.3-2008.
1021          */
1022         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1023                 IPN3KE_25G_TX_PAYLOAD_OCTETS_OK_LO,
1024                 IPN3KE_25G_TX_PAYLOAD_OCTETS_OK_HI,
1025                 hw, port_id);
1026         hw_stats->eth.tx_bytes += statistics;
1027
1028         /*Number of transmitted bytes in frames with no FCS, undersized,
1029          *oversized, or payload length errors. This register is
1030          *compliant with the requirements for ifOutOctets in RFC3635
1031          *(Managed Objects for Ethernet-like Interface Types)
1032          *and TX etherStatsOctets in RFC2819(Remote Network Monitoring
1033          *Management Information Base (RMON)).
1034          */
1035         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1036                 IPN3KE_25G_TX_FRAME_OCTETS_OK_LO,
1037                 IPN3KE_25G_TX_FRAME_OCTETS_OK_HI,
1038                 hw, port_id);
1039
1040         /*Number of received frames less than 64 bytes
1041          *and reporting a CRC error
1042          */
1043         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1044                 IPN3KE_25G_CNTR_RX_FRAGMENTS_LO,
1045                 IPN3KE_25G_CNTR_RX_FRAGMENTS_HI,
1046                 hw, port_id);
1047         hw_stats->eth.rx_discards += statistics;
1048         hw_stats->crc_errors += statistics;
1049         hw_stats->rx_length_errors += statistics;
1050
1051         /* Number of received oversized frames reporting a CRC error */
1052         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1053                 IPN3KE_25G_CNTR_RX_JABBERS_LO,
1054                 IPN3KE_25G_CNTR_RX_JABBERS_HI,
1055                 hw, port_id);
1056         hw_stats->eth.rx_discards += statistics;
1057         hw_stats->crc_errors += statistics;
1058         hw_stats->rx_length_errors += statistics;
1059
1060         /*Number of received packets with FCS errors.
1061          *This register maintains a count of the number of pulses
1062          *on the "l<n>_rx_fcs_error" or "rx_fcs_error" output signal
1063          */
1064         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1065                 IPN3KE_25G_CNTR_RX_FCS_LO,
1066                 IPN3KE_25G_CNTR_RX_FCS_HI,
1067                 hw, port_id);
1068         hw_stats->eth.rx_discards += statistics;
1069         hw_stats->checksum_error += statistics;
1070
1071         /*Number of received frames with a frame of length at least 64
1072          *with CRC error
1073          */
1074         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1075                 IPN3KE_25G_CNTR_RX_CRCERR_LO,
1076                 IPN3KE_25G_CNTR_RX_CRCERR_HI,
1077                 hw, port_id);
1078         hw_stats->eth.rx_discards += statistics;
1079         hw_stats->crc_errors += statistics;
1080
1081         /*Number of errored multicast frames received,
1082          *excluding control frames
1083          */
1084         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1085                 IPN3KE_25G_CNTR_RX_MCAST_DATA_ERR_LO,
1086                 IPN3KE_25G_CNTR_RX_MCAST_DATA_ERR_HI,
1087                 hw, port_id);
1088         hw_stats->eth.rx_discards += statistics;
1089
1090         /*Number of errored broadcast frames received,
1091          *excluding control frames
1092          */
1093         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1094                 IPN3KE_25G_CNTR_RX_BCAST_DATA_ERR_LO,
1095                 IPN3KE_25G_CNTR_RX_BCAST_DATA_ERR_HI,
1096                 hw, port_id);
1097         hw_stats->eth.rx_discards += statistics;
1098
1099         /*Number of errored unicast frames received,
1100          *excluding control frames
1101          */
1102         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1103                 IPN3KE_25G_CNTR_RX_UCAST_DATA_ERR_LO,
1104                 IPN3KE_25G_CNTR_RX_UCAST_DATA_ERR_HI,
1105                 hw, port_id);
1106         hw_stats->eth.rx_discards += statistics;
1107
1108         /* Number of errored multicast control frames received */
1109         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1110                 IPN3KE_25G_CNTR_RX_MCAST_CTRL_ERR_LO,
1111                 IPN3KE_25G_CNTR_RX_MCAST_CTRL_ERR_HI,
1112                 hw, port_id);
1113         hw_stats->eth.rx_discards += statistics;
1114
1115         /* Number of errored broadcast control frames received */
1116         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1117                 IPN3KE_25G_CNTR_RX_BCAST_CTRL_ERR_LO,
1118                 IPN3KE_25G_CNTR_RX_BCAST_CTRL_ERR_HI,
1119                 hw, port_id);
1120         hw_stats->eth.rx_discards += statistics;
1121
1122         /* Number of errored unicast control frames received */
1123         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1124                 IPN3KE_25G_CNTR_RX_UCAST_CTRL_ERR_LO,
1125                 IPN3KE_25G_CNTR_RX_UCAST_CTRL_ERR_HI,
1126                 hw, port_id);
1127         hw_stats->eth.rx_discards += statistics;
1128
1129         /* Number of errored pause frames received */
1130         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1131                 IPN3KE_25G_CNTR_RX_PAUSE_ERR_LO,
1132                 IPN3KE_25G_CNTR_RX_PAUSE_ERR_HI,
1133                 hw, port_id);
1134         hw_stats->eth.rx_discards += statistics;
1135
1136         /*Number of 64-byte received frames,
1137          *including the CRC field but excluding the preamble
1138          *and SFD bytes
1139          */
1140         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1141                 IPN3KE_25G_CNTR_RX_64B_LO,
1142                 IPN3KE_25G_CNTR_RX_64B_HI,
1143                 hw, port_id);
1144         hw_stats->rx_size_64 += statistics;
1145
1146         /*Number of received frames between 65 and 127 bytes */
1147         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1148                 IPN3KE_25G_CNTR_RX_65_127B_LO,
1149                 IPN3KE_25G_CNTR_RX_65_127B_HI,
1150                 hw, port_id);
1151         hw_stats->rx_size_65_127 += statistics;
1152
1153         /*Number of received frames between 128 and 255 bytes
1154          */
1155         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1156                 IPN3KE_25G_CNTR_RX_128_255B_LO,
1157                 IPN3KE_25G_CNTR_RX_128_255B_HI,
1158                 hw, port_id);
1159         hw_stats->rx_size_128_255 += statistics;
1160
1161         /*Number of received frames between 256 and 511 bytes
1162          */
1163         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1164                 IPN3KE_25G_CNTR_RX_256_511B_LO,
1165                 IPN3KE_25G_CNTR_RX_256_511B_HI,
1166                 hw, port_id);
1167         hw_stats->rx_size_256_511 += statistics;
1168
1169         /*Number of received frames between 512 and 1023 bytes
1170          */
1171         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1172                 IPN3KE_25G_CNTR_RX_512_1023B_LO,
1173                 IPN3KE_25G_CNTR_RX_512_1023B_HI,
1174                 hw, port_id);
1175         hw_stats->rx_size_512_1023 += statistics;
1176
1177         /*Number of received frames between 1024 and 1518 bytes
1178          */
1179         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1180                 IPN3KE_25G_CNTR_RX_1024_1518B_LO,
1181                 IPN3KE_25G_CNTR_RX_1024_1518B_HI,
1182                 hw, port_id);
1183         hw_stats->rx_size_1024_1518 += statistics;
1184
1185         /*Number of received frames of size between 1519 bytes
1186          *and the number of bytes specified in the MAX_TX_SIZE_CONFIG
1187          *register
1188          */
1189         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1190                 IPN3KE_25G_CNTR_RX_1519_MAXB_LO,
1191                 IPN3KE_25G_CNTR_RX_1519_MAXB_HI,
1192                 hw, port_id);
1193         hw_stats->rx_size_big += statistics;
1194
1195         /*Number of oversized frames (frames with more bytes
1196          *than the number specified in the MAX_TX_SIZE_CONFIG register)
1197          *received
1198          */
1199         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1200                 IPN3KE_25G_CNTR_RX_OVERSIZE_LO,
1201                 IPN3KE_25G_CNTR_RX_OVERSIZE_HI,
1202                 hw, port_id);
1203         hw_stats->rx_jabber += statistics;
1204
1205         /*Number of valid multicast frames received,
1206          *excluding control frames
1207          */
1208         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1209                 IPN3KE_25G_CNTR_RX_MCAST_DATA_OK_LO,
1210                 IPN3KE_25G_CNTR_RX_MCAST_DATA_OK_HI,
1211                 hw, port_id);
1212         hw_stats->eth.rx_multicast += statistics;
1213
1214         /*Number of valid broadcast frames received,
1215          *excluding control frames
1216          */
1217         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1218                 IPN3KE_25G_CNTR_RX_BCAST_DATA_OK_LO,
1219                 IPN3KE_25G_CNTR_RX_BCAST_DATA_OK_HI,
1220                 hw, port_id);
1221         hw_stats->eth.rx_broadcast += statistics;
1222
1223         /*Number of valid unicast frames received,
1224          *excluding control frames
1225          */
1226         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1227                 IPN3KE_25G_CNTR_RX_UCAST_DATA_OK_LO,
1228                 IPN3KE_25G_CNTR_RX_UCAST_DATA_OK_HI,
1229                 hw, port_id);
1230         hw_stats->eth.rx_unicast += statistics;
1231
1232         /*Number of valid multicast frames received,
1233          *excluding data frames
1234          */
1235         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1236                 IPN3KE_25G_CNTR_RX_MCAST_CTRL_LO,
1237                 IPN3KE_25G_CNTR_RX_MCAST_CTRL_HI,
1238                 hw, port_id);
1239         hw_stats->eth.rx_multicast += statistics;
1240
1241         /*Number of valid broadcast frames received,
1242          *excluding data frames
1243          */
1244         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1245                 IPN3KE_25G_CNTR_RX_BCAST_CTRL_LO,
1246                 IPN3KE_25G_CNTR_RX_BCAST_CTRL_HI,
1247                 hw, port_id);
1248         hw_stats->eth.rx_broadcast += statistics;
1249
1250         /*Number of valid unicast frames received,
1251          *excluding data frames
1252          */
1253         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1254                 IPN3KE_25G_CNTR_RX_UCAST_CTRL_LO,
1255                 IPN3KE_25G_CNTR_RX_UCAST_CTRL_HI,
1256                 hw, port_id);
1257         hw_stats->eth.rx_unicast += statistics;
1258
1259         /*Number of received pause frames, with or without error
1260          */
1261         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1262                 IPN3KE_25G_CNTR_RX_PAUSE_LO,
1263                 IPN3KE_25G_CNTR_RX_PAUSE_HI,
1264                 hw, port_id);
1265
1266         /*Number of received runt packets. A runt is a packet of size
1267          *less than 64 bytes but greater than eight bytes.
1268          *If a packet is eight bytes or smaller, it is considered
1269          *a decoding error and not a runt frame, and the IP core
1270          *does not flag it nor count it as a runt.
1271          */
1272         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1273                 IPN3KE_25G_CNTR_RX_RUNT_LO,
1274                 IPN3KE_25G_CNTR_RX_RUNT_HI,
1275                 hw, port_id);
1276
1277         /*Number of received payload bytes in frames with no FCS,
1278          *undersized, oversized, or payload length errors.
1279          *If VLAN detection is turned off for the RX MAC (bit [1] of the
1280          *"RXMAC_CONTROL" register at offset 0x50A has the value of 1),
1281          *the IP core counts the VLAN header bytes (4 bytes for VLAN and
1282          *8 bytes for stacked VLAN) as payload bytes.
1283          *This register is compliant with the requirements for
1284          *aOctetsReceivedOK in section 5.2.2.1.14 of the IEEE Standard
1285          *802.3-2008
1286          */
1287         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1288                 IPN3KE_25G_RX_PAYLOAD_OCTETS_OK_LO,
1289                 IPN3KE_25G_RX_PAYLOAD_OCTETS_OK_HI,
1290                 hw, port_id);
1291         hw_stats->eth.rx_bytes += statistics;
1292
1293         /*Number of received bytes in frames with no FCS, undersized,
1294          *oversized, or payload length errors.
1295          *This register is compliant with the requirements for
1296          *ifInOctets in RFC3635 (Managed Objects for Ethernet-like
1297          *Interface Types) and RX etherStatsOctets in RFC2819
1298          *(Remote Network Monitoring Management Information Base
1299          *(RMON)).
1300          */
1301         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1302                 IPN3KE_25G_RX_FRAME_OCTETS_OK_LO,
1303                 IPN3KE_25G_RX_FRAME_OCTETS_OK_HI,
1304                 hw, port_id);
1305
1306         /*resume Tx counter to real time
1307          */
1308         tmp = 0x00000000;
1309         (*hw->f_mac_read)(hw,
1310                         &tmp,
1311                         IPN3KE_25G_TX_STATISTICS_CONFIG,
1312                         port_id,
1313                         0);
1314         tmp &= 0xfffffffb;
1315         (*hw->f_mac_write)(hw,
1316                         tmp,
1317                         IPN3KE_25G_TX_STATISTICS_CONFIG,
1318                         port_id,
1319                         0);
1320
1321         /*resume Rx counter to real time
1322          */
1323         tmp = 0x00000000;
1324         (*hw->f_mac_read)(hw,
1325                         &tmp,
1326                         IPN3KE_25G_RX_STATISTICS_CONFIG,
1327                         port_id,
1328                         0);
1329         tmp &= 0xfffffffb;
1330         (*hw->f_mac_write)(hw,
1331                         tmp,
1332                         IPN3KE_25G_RX_STATISTICS_CONFIG,
1333                         port_id,
1334                         0);
1335
1336         return 0;
1337 }
1338
1339 static void
1340 ipn3ke_rpst_25g_lineside_tx_stats_reset(struct ipn3ke_hw *hw,
1341 uint16_t port_id)
1342 {
1343         uint32_t tmp = 0x00000001;
1344         /* Bit[0]: Software can set this bit to the value of 1
1345          * to reset all of the TX statistics registers at the same time.
1346          * This bit is selfclearing.
1347          */
1348         (*hw->f_mac_write)(hw,
1349                         tmp,
1350                         IPN3KE_25G_TX_STATISTICS_CONFIG,
1351                         port_id,
1352                         0);
1353
1354         while (tmp & 0x00000001) {
1355                 tmp = 0x00000000;
1356                 (*hw->f_mac_read)(hw,
1357                                 &tmp,
1358                                 IPN3KE_25G_TX_STATISTICS_CONFIG,
1359                                 port_id,
1360                                 0);
1361                 if (tmp & 0x00000001)
1362                         usleep(5);
1363                 else
1364                         return;
1365         }
1366 }
1367
1368 static void
1369 ipn3ke_rpst_25g_lineside_rx_stats_reset(struct ipn3ke_hw *hw,
1370 uint16_t port_id)
1371 {
1372         uint32_t tmp = 0x00000001;
1373         /* Bit[0]: Software can set this bit to the value of 1
1374          * to reset all of the RX statistics registers at the same time.
1375          * This bit is selfclearing.
1376          */
1377         (*hw->f_mac_write)(hw,
1378                         tmp,
1379                         IPN3KE_25G_RX_STATISTICS_CONFIG,
1380                         port_id,
1381                         0);
1382
1383         while (tmp & 0x00000001) {
1384                 tmp = 0x00000000;
1385                 (*hw->f_mac_read)(hw,
1386                                 &tmp,
1387                                 IPN3KE_25G_RX_STATISTICS_CONFIG,
1388                                 port_id,
1389                                 0);
1390                 if (tmp & 0x00000001)
1391                         usleep(5);
1392                 else
1393                         return;
1394         }
1395 }
1396
1397 static uint64_t
1398 ipn3ke_rpst_read_36bits_statistics_register(uint32_t addr_lo,
1399 uint32_t addr_hi, struct ipn3ke_hw *hw, uint16_t port_id)
1400 {
1401         uint32_t statistics_lo = 0x00000000;
1402         uint32_t statistics_hi = 0x00000000;
1403         uint64_t statistics = 0x0000000000000000;
1404
1405         (*hw->f_mac_read)(hw,
1406                         &statistics_lo,
1407                         addr_lo,
1408                         port_id,
1409                         0);
1410         (*hw->f_mac_read)(hw,
1411                         &statistics_hi,
1412                         addr_hi,
1413                         port_id,
1414                         0);
1415         statistics_hi &= IPN3KE_10G_STATS_HI_VALID_MASK;
1416         statistics += statistics_hi;
1417         statistics = statistics << IPN3KE_REGISTER_WIDTH;
1418         statistics += statistics_lo;
1419         return statistics;
1420 }
1421
1422 static int
1423 ipn3ke_rpst_read_10g_lineside_stats_registers
1424 (struct ipn3ke_hw *hw,
1425 uint16_t port_id,
1426 struct ipn3ke_rpst_hw_port_stats *hw_stats,
1427 struct rte_eth_stats *stats)
1428 {
1429         uint64_t statistics = 0;
1430
1431         memset(hw_stats, 0, sizeof(*hw_stats));
1432         memset(stats, 0, sizeof(*stats));
1433
1434         /*36-bit statistics counter that collects the number of frames
1435          *that are successfully transmitted, including control frames.
1436          */
1437         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1438                 IPN3KE_10G_TX_STATS_FRAME_OK_LO,
1439                 IPN3KE_10G_TX_STATS_FRAME_OK_HI,
1440                 hw, port_id);
1441         stats->opackets = statistics;
1442
1443         /*36-bit statistics counter that collects the number of frames
1444          *that are successfully received, including control frames.
1445          */
1446         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1447                 IPN3KE_10G_RX_STATS_FRAME_OK_LO,
1448                 IPN3KE_10G_RX_STATS_FRAME_OK_HI,
1449                 hw, port_id);
1450         stats->ipackets = statistics;
1451
1452         /*36-bit statistics counter that collects the number of frames
1453          *transmitted with error, including control frames.
1454          */
1455         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1456                 IPN3KE_10G_TX_STATS_FRAME_ERR_LO,
1457                 IPN3KE_10G_TX_STATS_FRAME_ERR_HI,
1458                 hw, port_id);
1459         stats->oerrors = statistics;
1460         hw_stats->eth.tx_errors = statistics;
1461
1462         /*36-bit statistics counter that collects the number of frames
1463          *received with error, including control frames.
1464          */
1465         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1466                 IPN3KE_10G_RX_STATS_FRAME_ERR_LO,
1467                 IPN3KE_10G_RX_STATS_FRAME_ERR_HI,
1468                 hw, port_id);
1469         stats->ierrors = statistics;
1470         hw_stats->eth.rx_discards = statistics;
1471
1472         /*36-bit statistics counter that collects the number
1473          *of RX frames with CRC error.
1474          */
1475         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1476                 IPN3KE_10G_RX_STATS_FRAME_CRC_ERR_LO,
1477                 IPN3KE_10G_RX_STATS_FRAME_CRC_ERR_HI,
1478                 hw, port_id);
1479         hw_stats->crc_errors = statistics;
1480
1481         /*64-bit statistics counter that collects the payload length,
1482          *including the bytes in control frames.
1483          *The payload length is the number of data and padding bytes
1484          *transmitted.
1485          *If the tx_vlan_detection[0] register bit is set to 1,
1486          *the VLAN and stacked VLAN tags are counted as part of
1487          *the TX payload.
1488          */
1489         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1490                 IPN3KE_10G_TX_STATS_OCTETS_OK_LO,
1491                 IPN3KE_10G_TX_STATS_OCTETS_OK_HI,
1492                 hw, port_id);
1493         stats->obytes = statistics;
1494         hw_stats->eth.tx_bytes = statistics;
1495
1496         /*64-bit statistics counter that collects the payload length,
1497          *including the bytes in control frames.
1498          *The payload length is the number of data and padding bytes
1499          *received.
1500          *If the rx_vlan_detection[0] register bit is set to 1,
1501          *the VLAN and stacked VLAN tags are counted as part of
1502          *the RX payload.
1503          */
1504         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1505                 IPN3KE_10G_RX_STATS_OCTETS_OK_LO,
1506                 IPN3KE_10G_RX_STATS_OCTETS_OK_HI,
1507                 hw, port_id);
1508         stats->ibytes = statistics;
1509         hw_stats->eth.rx_bytes = statistics;
1510
1511         /*36-bit statistics counter that collects the number of
1512          *valid pause frames transmitted.
1513          */
1514         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1515                 IPN3KE_10G_TX_STATS_PAUSE_MAC_CTRL_FRAMES_LO,
1516                 IPN3KE_10G_TX_STATS_PAUSE_MAC_CTRL_FRAMES_HI,
1517                 hw, port_id);
1518
1519         /*36-bit statistics counter that collects the number of
1520          *valid pause frames received.
1521          */
1522         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1523                 IPN3KE_10G_RX_STATS_PAUSE_MAC_CTRL_FRAMES_LO,
1524                 IPN3KE_10G_RX_STATS_PAUSE_MAC_CTRL_FRAMES_HI,
1525                 hw, port_id);
1526
1527         /*36-bit statistics counter that collects the number of frames
1528          *transmitted that are invalid and with error.
1529          */
1530         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1531                 IPN3KE_10G_TX_STATS_IF_ERRORS_LO,
1532                 IPN3KE_10G_TX_STATS_IF_ERRORS_HI,
1533                 hw, port_id);
1534
1535         /*36-bit statistics counter that collects the number of frames
1536          *received that are invalid and with error.
1537          */
1538         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1539                 IPN3KE_10G_RX_STATS_IF_ERRORS_LO,
1540                 IPN3KE_10G_RX_STATS_IF_ERRORS_HI,
1541                 hw, port_id);
1542
1543         /*36-bit statistics counter that collects the number of
1544          *good unicast frames transmitted,
1545          *excluding control frames.
1546          */
1547         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1548                 IPN3KE_10G_TX_STATS_UNICAST_FRAME_OK_LO,
1549                 IPN3KE_10G_TX_STATS_UNICAST_FRAME_OK_HI,
1550                 hw, port_id);
1551         hw_stats->eth.tx_unicast = statistics;
1552
1553         /*36-bit statistics counter that collects the number of
1554          *good unicast frames received,
1555          *excluding control frames.
1556          */
1557         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1558                 IPN3KE_10G_RX_STATS_UNICAST_FRAME_OK_LO,
1559                 IPN3KE_10G_RX_STATS_UNICAST_FRAME_OK_HI,
1560                 hw, port_id);
1561         hw_stats->eth.rx_unicast = statistics;
1562
1563         /*36-bit statistics counter that collects the number of
1564          *unicast frames transmitted with error,
1565          *excluding control frames.
1566          */
1567         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1568                 IPN3KE_10G_TX_STATS_UNICAST_FRAME_ERR_LO,
1569                 IPN3KE_10G_TX_STATS_UNICAST_FRAME_ERR_HI,
1570                 hw, port_id);
1571
1572         /*36-bit statistics counter that collects the number of
1573          *unicast frames received with error,
1574          *excluding control frames.
1575          */
1576         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1577                 IPN3KE_10G_RX_STATS_UNICAST_FRAME_ERR_LO,
1578                 IPN3KE_10G_RX_STATS_UNICAST_FRAME_ERR_HI,
1579                 hw, port_id);
1580
1581         /*36-bit statistics counter that collects the number of
1582          *good multicast frames transmitted,
1583          *excluding control frames.
1584          */
1585         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1586                 IPN3KE_10G_TX_STATS_MULTICAST_FRAME_OK_LO,
1587                 IPN3KE_10G_TX_STATS_MULTICAST_FRAME_OK_HI,
1588                 hw, port_id);
1589         hw_stats->eth.tx_multicast = statistics;
1590
1591         /*36-bit statistics counter that collects the number of
1592          *good multicast frames received,
1593          *excluding control frames.
1594          */
1595         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1596                 IPN3KE_10G_RX_STATS_MULTICAST_FRAME_OK_LO,
1597                 IPN3KE_10G_RX_STATS_MULTICAST_FRAME_OK_HI,
1598                 hw, port_id);
1599         hw_stats->eth.rx_multicast = statistics;
1600
1601         /*36-bit statistics counter that collects the number of
1602          *multicast frames transmitted with error,
1603          *excluding control frames.
1604          */
1605         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1606                 IPN3KE_10G_TX_STATS_MULTICAST_FRAME_ERR_LO,
1607                 IPN3KE_10G_TX_STATS_MULTICAST_FRAME_ERR_HI,
1608                 hw, port_id);
1609
1610         /*36-bit statistics counter that collects the number
1611          *of multicast frames received with error,
1612          *excluding control frames.
1613          */
1614         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1615                 IPN3KE_10G_RX_STATS_MULTICAST_FRAME_ERR_LO,
1616                 IPN3KE_10G_RX_STATS_MULTICAST_FRAME_ERR_HI,
1617                 hw, port_id);
1618
1619         /*36-bit statistics counter that collects the number of
1620          *good broadcast frames transmitted,
1621          *excluding control frames.
1622          */
1623         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1624                 IPN3KE_10G_TX_STATS_BROADCAST_FRAME_OK_LO,
1625                 IPN3KE_10G_TX_STATS_BROADCAST_FRAME_OK_HI,
1626                 hw, port_id);
1627         hw_stats->eth.tx_broadcast = statistics;
1628
1629         /*36-bit statistics counter that collects the number of
1630          *good broadcast frames received,
1631          *excluding control frames.
1632          */
1633         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1634                 IPN3KE_10G_RX_STATS_BROADCAST_FRAME_OK_LO,
1635                 IPN3KE_10G_RX_STATS_BROADCAST_FRAME_OK_HI,
1636                 hw, port_id);
1637         hw_stats->eth.rx_broadcast = statistics;
1638
1639         /*36-bit statistics counter that collects the number
1640          *of broadcast frames transmitted with error,
1641          *excluding control frames.
1642          */
1643         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1644                 IPN3KE_10G_TX_STATS_BROADCAST_FRAME_ERR_LO,
1645                 IPN3KE_10G_TX_STATS_BROADCAST_FRAME_ERR_HI,
1646                 hw, port_id);
1647
1648         /*36-bit statistics counter that collects the number of
1649          *broadcast frames received with error,
1650          *excluding control frames.
1651          */
1652         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1653                 IPN3KE_10G_RX_STATS_BROADCAST_FRAME_ERR_LO,
1654                 IPN3KE_10G_RX_STATS_BROADCAST_FRAME_ERR_HI,
1655                 hw, port_id);
1656
1657         /*64-bit statistics counter that collects the total number of
1658          *octets transmitted.
1659          *This count includes good, errored, and invalid frames.
1660          */
1661         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1662                 IPN3KE_10G_TX_STATS_ETHER_STATS_OCTETS_LO,
1663                 IPN3KE_10G_TX_STATS_ETHER_STATS_OCTETS_HI,
1664                 hw, port_id);
1665
1666         /*64-bit statistics counter that collects the total number of
1667          *octets received.
1668          *This count includes good, errored, and invalid frames.
1669          */
1670         statistics = ipn3ke_rpst_read_64bits_statistics_register(
1671                 IPN3KE_10G_RX_STATS_ETHER_STATS_OCTETS_LO,
1672                 IPN3KE_10G_RX_STATS_ETHER_STATS_OCTETS_HI,
1673                 hw, port_id);
1674
1675         /*36-bit statistics counter that collects the total number of
1676          *good, errored, and invalid frames transmitted.
1677          */
1678         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1679                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_LO,
1680                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_HI,
1681                 hw, port_id);
1682
1683         /*36-bit statistics counter that collects the total number of
1684          *good, errored, and invalid frames received.
1685          */
1686         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1687                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_LO,
1688                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_HI,
1689                 hw, port_id);
1690
1691         /*36-bit statistics counter that collects the number of
1692          *undersized TX frames.
1693          */
1694         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1695                 IPN3KE_10G_TX_STATS_ETHER_STATS_UNDER_SIZE_PKTS_LO,
1696                 IPN3KE_10G_TX_STATS_ETHER_STATS_UNDER_SIZE_PKTS_HI,
1697                 hw, port_id);
1698
1699         /*36-bit statistics counter that collects the number of
1700          *undersized RX frames.
1701          */
1702         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1703                 IPN3KE_10G_RX_STATS_ETHER_STATS_UNDER_SIZE_PKTS_LO,
1704                 IPN3KE_10G_RX_STATS_ETHER_STATS_UNDER_SIZE_PKTS_HI,
1705                 hw, port_id);
1706         hw_stats->rx_undersize = statistics;
1707
1708         /*36-bit statistics counter that collects the number of
1709          *TX frames whose length exceeds the maximum frame length
1710          *specified.
1711          */
1712         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1713                 IPN3KE_10G_TX_STATS_ETHER_STATS_OVER_SIZE_PKTS_LO,
1714                 IPN3KE_10G_TX_STATS_ETHER_STATS_OVER_SIZE_PKTS_HI,
1715                 hw, port_id);
1716
1717         /*36-bit statistics counter that collects the number of
1718          *RX frames whose length exceeds the maximum frame length
1719          *specified.
1720          */
1721         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1722                 IPN3KE_10G_RX_STATS_ETHER_STATS_OVER_SIZE_PKTS_LO,
1723                 IPN3KE_10G_RX_STATS_ETHER_STATS_OVER_SIZE_PKTS_HI,
1724                 hw, port_id);
1725         hw_stats->rx_oversize = statistics;
1726
1727         /*36-bit statistics counter that collects the number of
1728          *64-byte TX frames,
1729          *including the CRC field
1730          *but excluding the preamble and SFD bytes.
1731          *This count includes good, errored, and invalid frames.
1732          */
1733         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1734                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_64_OCTETS_LO,
1735                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_64_OCTETS_HI,
1736                 hw, port_id);
1737         hw_stats->tx_size_64 = statistics;
1738
1739         /*36-bit statistics counter that collects the number of
1740          *64-byte RX frames,
1741          *including the CRC field
1742          *but excluding the preamble and SFD bytes.
1743          *This count includes good, errored, and invalid frames.
1744          */
1745         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1746                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_64_OCTETS_LO,
1747                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_64_OCTETS_HI,
1748                 hw, port_id);
1749         hw_stats->rx_size_64 = statistics;
1750
1751         /*36-bit statistics counter that collects the number of
1752          *TX frames between the length of 65 and 127 bytes,
1753          *including the CRC field
1754          *but excluding the preamble and SFD bytes.
1755          *This count includes good, errored, and invalid frames.
1756          */
1757         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1758                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_65_127_OCTETS_LO,
1759                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_65_127_OCTETS_HI,
1760                 hw, port_id);
1761         hw_stats->tx_size_65_127 = statistics;
1762
1763         /*36-bit statistics counter that collects the number of
1764          *RX frames between the length of 65 and 127 bytes,
1765          *including the CRC field
1766          *but excluding the preamble and SFD bytes.
1767          *This count includes good, errored, and invalid frames.
1768          */
1769         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1770                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_65_127_OCTETS_LO,
1771                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_65_127_OCTETS_HI,
1772                 hw, port_id);
1773         hw_stats->rx_size_65_127 = statistics;
1774
1775         /*36-bit statistics counter that collects the number of
1776          *TX frames between the length of 128 and 255 bytes,
1777          *including the CRC field
1778          *but excluding the preamble and SFD bytes.
1779          *This count includes good, errored, and invalid frames.
1780          */
1781         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1782                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_128_255_OCTETS_LO,
1783                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_128_255_OCTETS_HI,
1784                 hw, port_id);
1785         hw_stats->tx_size_128_255 = statistics;
1786
1787         /*36-bit statistics counter that collects the number of
1788          *RX frames between the length of 128 and 255 bytes,
1789          *including the CRC field
1790          *but excluding the preamble and SFD bytes.
1791          *This count includes good, errored, and invalid frames.
1792          */
1793         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1794                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_128_255_OCTETS_LO,
1795                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_128_255_OCTETS_HI,
1796                 hw, port_id);
1797         hw_stats->rx_size_128_255 = statistics;
1798
1799         /*36-bit statistics counter that collects the number of
1800          *TX frames between the length of 256 and 511 bytes,
1801          *including the CRC field
1802          *but excluding the preamble and SFD bytes.
1803          *This count includes good, errored, and invalid frames.
1804          */
1805         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1806                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_256_511_OCTETS_LO,
1807                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_256_511_OCTETS_HI,
1808                 hw, port_id);
1809         hw_stats->tx_size_256_511 = statistics;
1810
1811         /*36-bit statistics counter that collects the number of
1812          *RX frames between the length of 256 and 511 bytes,
1813          *including the CRC field
1814          *but excluding the preamble and SFD bytes.
1815          *This count includes good, errored, and invalid frames.
1816          */
1817         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1818                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_256_511_OCTETS_LO,
1819                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_256_511_OCTETS_HI,
1820                 hw, port_id);
1821         hw_stats->rx_size_256_511 = statistics;
1822
1823         /*36-bit statistics counter that collects the number of
1824          *TX frames between the length of 512 and 1023 bytes,
1825          *including the CRC field
1826          *but excluding the preamble and SFD bytes.
1827          *This count includes good, errored, and invalid frames.
1828          */
1829         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1830                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_512_1023_OCTETS_LO,
1831                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_512_1023_OCTETS_HI,
1832                 hw, port_id);
1833         hw_stats->tx_size_512_1023 = statistics;
1834
1835         /*36-bit statistics counter that collects the number of
1836          *RX frames between the length of 512 and 1023 bytes,
1837          *including the CRC field
1838          *but excluding the preamble and SFD bytes.
1839          *This count includes good, errored, and invalid frames.
1840          */
1841         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1842                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_512_1023_OCTETS_LO,
1843                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_512_1023_OCTETS_HI,
1844                 hw, port_id);
1845         hw_stats->rx_size_512_1023 = statistics;
1846
1847         /*36-bit statistics counter that collects the number of
1848          *TX frames between the length of 1024 and 1518 bytes,
1849          *including the CRC field but
1850          *excluding the preamble and SFD bytes.
1851          *This count includes good, errored, and invalid frames.
1852          */
1853         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1854                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_1024_1518_OCTETS_LO,
1855                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_1024_1518_OCTETS_HI,
1856                 hw, port_id);
1857         hw_stats->tx_size_1024_1518 = statistics;
1858
1859         /*36-bit statistics counter that collects the number of
1860          *RX frames between the length of 1024 and 1518 bytes,
1861          *including the CRC field
1862          *but excluding the preamble and SFD bytes.
1863          *This count includes good, errored, and invalid frames.
1864          */
1865         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1866                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_1024_1518_OCTETS_LO,
1867                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_1024_1518_OCTETS_HI,
1868                 hw, port_id);
1869         hw_stats->rx_size_1024_1518 = statistics;
1870
1871         /*36-bit statistics counter that collects the number of
1872          *TX frames equal or more than the length of 1,519 bytes,
1873          *including the CRC field
1874          *but excluding the preamble and SFD bytes.
1875          *This count includes good, errored, and invalid frames.
1876          */
1877         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1878                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_1519_X_OCTETS_LO,
1879                 IPN3KE_10G_TX_STATS_ETHER_STATS_PKTS_1519_X_OCTETS_HI,
1880                 hw, port_id);
1881         hw_stats->tx_size_1519_to_max = statistics;
1882
1883         /*36-bit statistics counter that collects the number of
1884          *RX frames equal or more than the length of 1,519 bytes,
1885          *including the CRC field
1886          *but excluding the preamble and SFD bytes.
1887          *This count includes good,
1888          *errored, and invalid frames.
1889          */
1890         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1891                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_1519_X_OCTETS_LO,
1892                 IPN3KE_10G_RX_STATS_ETHER_STATS_PKTS_1519_X_OCTETS_HI,
1893                 hw, port_id);
1894         hw_stats->rx_size_big = statistics;
1895
1896         /*36-bit statistics counter that collects the total number of
1897          *RX frames with length less than 64 bytes and CRC error.
1898          *The MAC does not drop these frames.
1899          */
1900         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1901                 IPN3KE_10G_RX_STATS_ETHER_STATS_FRAGMENTS_LO,
1902                 IPN3KE_10G_RX_STATS_ETHER_STATS_FRAGMENTS_HI,
1903                 hw, port_id);
1904
1905         /*36-bit statistics counter that collects the number of
1906          *oversized RX frames with CRC error.
1907          *The MAC does not drop these frames.
1908          */
1909         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1910                 IPN3KE_10G_RX_STATS_ETHER_STATS_JABBERS_LO,
1911                 IPN3KE_10G_RX_STATS_ETHER_STATS_JABBERS_HI,
1912                 hw, port_id);
1913
1914         /*36-bit statistics counter that collects the number of
1915          *RX frames with CRC error,
1916          *whose length is between 64 and the maximum frame length
1917          *specified in the register.
1918          *The MAC does not drop these frames.
1919          */
1920         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1921                 IPN3KE_10G_RX_STATS_ETHER_STATS_CRC_ERR_LO,
1922                 IPN3KE_10G_RX_STATS_ETHER_STATS_CRC_ERR_HI,
1923                 hw, port_id);
1924
1925         /*36-bit statistics counter that collects the number of
1926          *valid TX unicast control frames.
1927          */
1928         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1929                 IPN3KE_10G_TX_STATS_UNICAST_MAC_CTRL_FRAMES_LO,
1930                 IPN3KE_10G_TX_STATS_UNICAST_MAC_CTRL_FRAMES_HI,
1931                 hw, port_id);
1932         hw_stats->eth.tx_unicast += statistics;
1933
1934         /*36-bit statistics counter that collects the number of
1935          *valid RX unicast control frames.
1936          */
1937         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1938                 IPN3KE_10G_RX_STATS_UNICAST_MAC_CTRL_FRAMES_LO,
1939                 IPN3KE_10G_RX_STATS_UNICAST_MAC_CTRL_FRAMES_HI,
1940                 hw, port_id);
1941         hw_stats->eth.rx_unicast += statistics;
1942
1943         /*36-bit statistics counter that collects the number of
1944          *valid TX multicast control frames.
1945          */
1946         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1947                 IPN3KE_10G_TX_STATS_MULTICAST_MAC_CTRL_FRAMES_LO,
1948                 IPN3KE_10G_TX_STATS_MULTICAST_MAC_CTRL_FRAMES_HI,
1949                 hw, port_id);
1950         hw_stats->eth.tx_multicast += statistics;
1951
1952         /*36-bit statistics counter that collects the number of
1953          *valid RX multicast control frames.
1954          */
1955         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1956                 IPN3KE_10G_RX_STATS_MULTICAST_MAC_CTRL_FRAMES_LO,
1957                 IPN3KE_10G_RX_STATS_MULTICAST_MAC_CTRL_FRAMES_HI,
1958                 hw, port_id);
1959         hw_stats->eth.rx_multicast += statistics;
1960
1961         /*36-bit statistics counter that collects the number of
1962          *valid TX broadcast control frames.
1963          */
1964         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1965                 IPN3KE_10G_TX_STATS_BROADCAST_MAC_CTRL_FRAMES_LO,
1966                 IPN3KE_10G_TX_STATS_BROADCAST_MAC_CTRL_FRAMES_HI,
1967                 hw, port_id);
1968         hw_stats->eth.tx_broadcast += statistics;
1969
1970         /*36-bit statistics counter that collects the number of
1971          *valid RX broadcast control frames.
1972          */
1973         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1974                 IPN3KE_10G_RX_STATS_BROADCAST_MAC_CTRL_FRAMES_LO,
1975                 IPN3KE_10G_RX_STATS_BROADCAST_MAC_CTRL_FRAMES_HI,
1976                 hw, port_id);
1977         hw_stats->eth.rx_broadcast += statistics;
1978
1979         /*36-bit statistics counter that collects the number of
1980          *valid TX PFC frames.
1981          */
1982         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1983                 IPN3KE_10G_TX_STATS_PFC_MAC_CTRL_FRAMES_LO,
1984                 IPN3KE_10G_TX_STATS_PFC_MAC_CTRL_FRAMES_HI,
1985                 hw, port_id);
1986
1987         /*36-bit statistics counter that collects the number of
1988          *valid RX PFC frames.
1989          */
1990         statistics = ipn3ke_rpst_read_36bits_statistics_register(
1991                 IPN3KE_10G_RX_STATS_PFC_MAC_CTRL_FRAMES_LO,
1992                 IPN3KE_10G_RX_STATS_PFC_MAC_CTRL_FRAMES_HI,
1993                 hw, port_id);
1994
1995         return 0;
1996 }
1997
1998 static void
1999 ipn3ke_rpst_10g_lineside_tx_stats_reset(struct ipn3ke_hw *hw,
2000 uint16_t port_id)
2001 {
2002         uint32_t tmp;
2003
2004         /*Bit [0]: Set this register to 1 to clear all TX statistics
2005          *counters.
2006          *The IP core clears this bit when all counters are cleared.
2007          *Bits [31:1]: Reserved.
2008          */
2009         tmp = 0x00000000;
2010         (*hw->f_mac_read)(hw,
2011                 &tmp,
2012                 IPN3KE_10G_TX_STATS_CLR,
2013                 port_id,
2014                 0);
2015         tmp |= 0x00000001;
2016         (*hw->f_mac_write)(hw,
2017                 tmp,
2018                 IPN3KE_10G_TX_STATS_CLR,
2019                 port_id,
2020                 0);
2021 }
2022
2023 static void
2024 ipn3ke_rpst_10g_lineside_rx_stats_reset(struct ipn3ke_hw *hw,
2025 uint16_t port_id)
2026 {
2027         uint32_t tmp;
2028
2029         /*Bit [0]: Set this register to 1 to clear all RX statistics
2030          *counters.
2031          *The IP core clears this bit when all counters are cleared.
2032          *Bits [31:1]: Reserved
2033          */
2034         tmp = 0x00000000;
2035         (*hw->f_mac_read)(hw,
2036                 &tmp,
2037                 IPN3KE_10G_RX_STATS_CLR,
2038                 port_id,
2039                 0);
2040         tmp |= 0x00000001;
2041         (*hw->f_mac_write)(hw,
2042                 tmp,
2043                 IPN3KE_10G_RX_STATS_CLR,
2044                 port_id,
2045                 0);
2046 }
2047
2048 static void
2049 ipn3ke_rpst_stats_reset(struct rte_eth_dev *ethdev)
2050 {
2051         uint16_t port_id = 0;
2052         char *ch;
2053         int cnt = 0;
2054         struct rte_afu_device *afu_dev = NULL;
2055         struct ipn3ke_hw *hw = NULL;
2056
2057         if (!ethdev) {
2058                 IPN3KE_AFU_PMD_ERR("ethernet device to reset is NULL!");
2059                 return;
2060         }
2061
2062         afu_dev = RTE_ETH_DEV_TO_AFU(ethdev);
2063         if (!afu_dev) {
2064                 IPN3KE_AFU_PMD_ERR("afu device to reset is NULL!");
2065                 return;
2066         }
2067
2068         if (!afu_dev->shared.data) {
2069                 IPN3KE_AFU_PMD_ERR("hardware data to reset is NULL!");
2070                 return;
2071         }
2072
2073         hw = afu_dev->shared.data;
2074
2075         ch = ethdev->data->name;
2076         if (!ch) {
2077                 IPN3KE_AFU_PMD_ERR("ethdev name is NULL!");
2078                 return;
2079         }
2080         while (ch) {
2081                 if (*ch == '_')
2082                         cnt++;
2083                 ch++;
2084                 if (cnt == 3)
2085                         break;
2086         }
2087         if (!ch) {
2088                 IPN3KE_AFU_PMD_ERR("Can not get port_id from ethdev name!");
2089                 return;
2090         }
2091         port_id = atoi(ch);
2092
2093         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_25GE_25GAUI) {
2094                 ipn3ke_rpst_25g_nic_side_tx_stats_reset(hw, port_id);
2095                 ipn3ke_rpst_25g_nic_side_rx_stats_reset(hw, port_id);
2096                 ipn3ke_rpst_25g_lineside_tx_stats_reset(hw, port_id);
2097                 ipn3ke_rpst_25g_lineside_rx_stats_reset(hw, port_id);
2098         } else if (hw->retimer.mac_type ==
2099                         IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
2100                 ipn3ke_rpst_10g_nic_side_tx_stats_reset(hw, port_id);
2101                 ipn3ke_rpst_10g_nic_side_rx_stats_reset(hw, port_id);
2102                 ipn3ke_rpst_10g_lineside_tx_stats_reset(hw, port_id);
2103                 ipn3ke_rpst_10g_lineside_rx_stats_reset(hw, port_id);
2104         }
2105 }
2106
2107 static int
2108 ipn3ke_rpst_stats_get
2109 (struct rte_eth_dev *ethdev, struct rte_eth_stats *stats)
2110 {
2111         uint16_t port_id = 0;
2112         char *ch;
2113         int cnt = 0;
2114         int i = 0;
2115         struct rte_afu_device *afu_dev = NULL;
2116         struct ipn3ke_hw *hw = NULL;
2117         struct ipn3ke_rpst_hw_port_stats hw_stats;
2118
2119         if (!ethdev) {
2120                 IPN3KE_AFU_PMD_ERR("ethernet device to get statistics is NULL");
2121                 return -EINVAL;
2122         }
2123         if (!stats) {
2124                 IPN3KE_AFU_PMD_ERR("Address to return statistics is NULL!");
2125                 return -EINVAL;
2126         }
2127
2128         afu_dev = RTE_ETH_DEV_TO_AFU(ethdev);
2129         if (!afu_dev) {
2130                 IPN3KE_AFU_PMD_ERR("afu device to get statistics is NULL!");
2131                 return -EINVAL;
2132         }
2133
2134         if (!afu_dev->shared.data) {
2135                 IPN3KE_AFU_PMD_ERR("hardware data to get statistics is NULL!");
2136                 return -EINVAL;
2137         }
2138
2139         hw = afu_dev->shared.data;
2140
2141         ch = ethdev->data->name;
2142         if (!ch) {
2143                 IPN3KE_AFU_PMD_ERR("ethdev name is NULL!");
2144                 return -EINVAL;
2145         }
2146         while (ch) {
2147                 if (*ch == '_')
2148                         cnt++;
2149                 ch++;
2150                 if (cnt == 3)
2151                         break;
2152         }
2153         if (!ch) {
2154                 IPN3KE_AFU_PMD_ERR("Can not get port_id from ethdev name!");
2155                 return -EINVAL;
2156         }
2157         port_id = atoi(ch);
2158
2159         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_25GE_25GAUI) {
2160                 ipn3ke_rpst_read_25g_lineside_stats_registers(hw,
2161                                                         port_id,
2162                                                         &hw_stats);
2163
2164                 stats->ipackets  = hw_stats.rx_size_64
2165                                         + hw_stats.rx_size_65_127
2166                                         + hw_stats.rx_size_128_255
2167                                         + hw_stats.rx_size_256_511
2168                                         + hw_stats.rx_size_512_1023
2169                                         + hw_stats.rx_size_1024_1518
2170                                         + hw_stats.rx_size_big
2171                                         + hw_stats.rx_undersize
2172                                         + hw_stats.rx_fragments
2173                                         + hw_stats.rx_oversize
2174                                         + hw_stats.rx_jabber;
2175                 stats->opackets  = hw_stats.tx_size_64
2176                                         + hw_stats.tx_size_65_127
2177                                         + hw_stats.tx_size_128_255
2178                                         + hw_stats.tx_size_256_511
2179                                         + hw_stats.tx_size_512_1023
2180                                         + hw_stats.tx_size_1024_1518
2181                                         + hw_stats.tx_size_1519_to_max;
2182                 stats->ibytes    = hw_stats.eth.rx_bytes;
2183                 stats->obytes    = hw_stats.eth.tx_bytes;
2184                 stats->imissed   = 0;
2185                 stats->ierrors   = hw_stats.eth.rx_discards
2186                                         + hw_stats.eth.rx_unknown_protocol;
2187                 stats->oerrors   = hw_stats.eth.tx_discards
2188                                         + hw_stats.eth.tx_errors;
2189                 stats->rx_nombuf = 0;
2190                 for (i = 0; i < RTE_ETHDEV_QUEUE_STAT_CNTRS; i++) {
2191                         stats->q_ipackets[i] = 0;
2192                         stats->q_opackets[i] = 0;
2193                         stats->q_ibytes[i] = 0;
2194                         stats->q_obytes[i] = 0;
2195                         stats->q_errors[i] = 0;
2196                 }
2197         } else {
2198                 ipn3ke_rpst_read_10g_lineside_stats_registers(hw,
2199                                                         port_id,
2200                                                         &hw_stats,
2201                                                         stats);
2202         }
2203
2204         return 0;
2205 }
2206
2207 static int
2208 ipn3ke_rpst_xstats_get
2209 (struct rte_eth_dev *ethdev, struct rte_eth_xstat *xstats, unsigned int n)
2210 {
2211         uint16_t port_id = 0;
2212         char *ch = NULL;
2213         int cnt = 0;
2214         unsigned int i, count, prio;
2215         struct rte_afu_device *afu_dev = NULL;
2216         struct ipn3ke_hw *hw = NULL;
2217         struct ipn3ke_rpst_hw_port_stats hw_stats;
2218         struct rte_eth_stats stats;
2219
2220         if (!xstats)
2221                 return 0;
2222
2223         if (!ethdev) {
2224                 IPN3KE_AFU_PMD_ERR("ethernet device to get statistics is NULL");
2225                 return -EINVAL;
2226         }
2227
2228         afu_dev = RTE_ETH_DEV_TO_AFU(ethdev);
2229         if (!afu_dev) {
2230                 IPN3KE_AFU_PMD_ERR("afu device to get statistics is NULL!");
2231                 return -EINVAL;
2232         }
2233
2234         if (!afu_dev->shared.data) {
2235                 IPN3KE_AFU_PMD_ERR("hardware data to get statistics is NULL!");
2236                 return -EINVAL;
2237         }
2238
2239         hw = afu_dev->shared.data;
2240
2241         ch = ethdev->data->name;
2242         if (!ch) {
2243                 IPN3KE_AFU_PMD_ERR("ethdev name is NULL!");
2244                 return -EINVAL;
2245         }
2246         while (ch) {
2247                 if (*ch == '_')
2248                         cnt++;
2249                 ch++;
2250                 if (cnt == 3)
2251                         break;
2252         }
2253         if (!ch) {
2254                 IPN3KE_AFU_PMD_ERR("Can not get port_id from ethdev name!");
2255                 return -EINVAL;
2256         }
2257         port_id = atoi(ch);
2258
2259         count = ipn3ke_rpst_xstats_calc_num();
2260         if (n < count)
2261                 return count;
2262
2263         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_25GE_25GAUI) {
2264                 ipn3ke_rpst_read_25g_lineside_stats_registers(hw,
2265                                                         port_id,
2266                                                         &hw_stats);
2267         } else {
2268                 ipn3ke_rpst_read_10g_lineside_stats_registers(hw,
2269                                                         port_id,
2270                                                         &hw_stats,
2271                                                         &stats);
2272         }
2273
2274         count = 0;
2275
2276         /* Get stats from ipn3ke_rpst_stats */
2277         for (i = 0; i < IPN3KE_RPST_ETH_XSTATS_CNT; i++) {
2278                 xstats[count].value = *(uint64_t *)(((char *)&hw_stats.eth)
2279                         + ipn3ke_rpst_stats_strings[i].offset);
2280                 xstats[count].id = count;
2281                 count++;
2282         }
2283
2284         /* Get individiual stats from ipn3ke_rpst_hw_port */
2285         for (i = 0; i < IPN3KE_RPST_HW_PORT_XSTATS_CNT; i++) {
2286                 xstats[count].value = *(uint64_t *)(((char *)(&hw_stats)) +
2287                         ipn3ke_rpst_hw_port_strings[i].offset);
2288                 xstats[count].id = count;
2289                 count++;
2290         }
2291
2292         /* Get individiual stats from ipn3ke_rpst_rxq_pri */
2293         for (i = 0; i < IPN3KE_RPST_RXQ_PRIO_XSTATS_CNT; i++) {
2294                 for (prio = 0; prio < IPN3KE_RPST_PRIO_XSTATS_CNT; prio++) {
2295                         xstats[count].value =
2296                                 *(uint64_t *)(((char *)(&hw_stats)) +
2297                                 ipn3ke_rpst_rxq_prio_strings[i].offset +
2298                                 (sizeof(uint64_t) * prio));
2299                         xstats[count].id = count;
2300                         count++;
2301                 }
2302         }
2303
2304         /* Get individiual stats from ipn3ke_rpst_txq_prio */
2305         for (i = 0; i < IPN3KE_RPST_TXQ_PRIO_XSTATS_CNT; i++) {
2306                 for (prio = 0; prio < IPN3KE_RPST_PRIO_XSTATS_CNT; prio++) {
2307                         xstats[count].value =
2308                                 *(uint64_t *)(((char *)(&hw_stats)) +
2309                                 ipn3ke_rpst_txq_prio_strings[i].offset +
2310                                 (sizeof(uint64_t) * prio));
2311                         xstats[count].id = count;
2312                         count++;
2313                 }
2314         }
2315
2316         return count;
2317 }
2318
2319 static int
2320 ipn3ke_rpst_xstats_get_names
2321 (__rte_unused struct rte_eth_dev *dev,
2322 struct rte_eth_xstat_name *xstats_names,
2323 __rte_unused unsigned int limit)
2324 {
2325         unsigned int count = 0;
2326         unsigned int i, prio;
2327
2328         if (!xstats_names)
2329                 return ipn3ke_rpst_xstats_calc_num();
2330
2331         /* Note: limit checked in rte_eth_xstats_names() */
2332
2333         /* Get stats from ipn3ke_rpst_stats */
2334         for (i = 0; i < IPN3KE_RPST_ETH_XSTATS_CNT; i++) {
2335                 snprintf(xstats_names[count].name,
2336                          sizeof(xstats_names[count].name),
2337                          "%s",
2338                          ipn3ke_rpst_stats_strings[i].name);
2339                 count++;
2340         }
2341
2342         /* Get individiual stats from ipn3ke_rpst_hw_port */
2343         for (i = 0; i < IPN3KE_RPST_HW_PORT_XSTATS_CNT; i++) {
2344                 snprintf(xstats_names[count].name,
2345                          sizeof(xstats_names[count].name),
2346                          "%s",
2347                          ipn3ke_rpst_hw_port_strings[i].name);
2348                 count++;
2349         }
2350
2351         /* Get individiual stats from ipn3ke_rpst_rxq_pri */
2352         for (i = 0; i < IPN3KE_RPST_RXQ_PRIO_XSTATS_CNT; i++) {
2353                 for (prio = 0; prio < 8; prio++) {
2354                         snprintf(xstats_names[count].name,
2355                                  sizeof(xstats_names[count].name),
2356                                  "rx_priority%u_%s",
2357                                  prio,
2358                                  ipn3ke_rpst_rxq_prio_strings[i].name);
2359                         count++;
2360                 }
2361         }
2362
2363         /* Get individiual stats from ipn3ke_rpst_txq_prio */
2364         for (i = 0; i < IPN3KE_RPST_TXQ_PRIO_XSTATS_CNT; i++) {
2365                 for (prio = 0; prio < 8; prio++) {
2366                         snprintf(xstats_names[count].name,
2367                                  sizeof(xstats_names[count].name),
2368                                  "tx_priority%u_%s",
2369                                  prio,
2370                                  ipn3ke_rpst_txq_prio_strings[i].name);
2371                         count++;
2372                 }
2373         }
2374         return count;
2375 }
2376
2377 static void
2378 ipn3ke_update_link(struct rte_rawdev *rawdev,
2379         uint16_t port, struct rte_eth_link *link)
2380 {
2381         uint64_t line_link_bitmap = 0;
2382         enum ifpga_rawdev_link_speed link_speed;
2383
2384         rawdev->dev_ops->attr_get(rawdev,
2385                                 "LineSideLinkStatus",
2386                                 (uint64_t *)&line_link_bitmap);
2387
2388         /* Parse the link status */
2389         if ((1 << port) & line_link_bitmap)
2390                 link->link_status = 1;
2391         else
2392                 link->link_status = 0;
2393
2394         IPN3KE_AFU_PMD_DEBUG("port is %d\n", port);
2395         IPN3KE_AFU_PMD_DEBUG("link->link_status is %d\n", link->link_status);
2396
2397         rawdev->dev_ops->attr_get(rawdev,
2398                                 "LineSideLinkSpeed",
2399                                 (uint64_t *)&link_speed);
2400         switch (link_speed) {
2401         case IFPGA_RAWDEV_LINK_SPEED_10GB:
2402                 link->link_speed = ETH_SPEED_NUM_10G;
2403                 break;
2404         case IFPGA_RAWDEV_LINK_SPEED_25GB:
2405                 link->link_speed = ETH_SPEED_NUM_25G;
2406                 break;
2407         default:
2408                 IPN3KE_AFU_PMD_ERR("Unknown link speed info %u", link_speed);
2409                 break;
2410         }
2411 }
2412
2413 /*
2414  * Set device link up.
2415  */
2416 int
2417 ipn3ke_rpst_dev_set_link_up(struct rte_eth_dev *dev)
2418 {
2419         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(dev);
2420         struct rte_eth_dev *pf;
2421         int ret = 0;
2422
2423         if (rpst->i40e_pf_eth) {
2424                 ret = rte_eth_dev_set_link_up(rpst->i40e_pf_eth_port_id);
2425                 pf = rpst->i40e_pf_eth;
2426                 (*rpst->i40e_pf_eth->dev_ops->link_update)(pf, 1);
2427         }
2428
2429         return ret;
2430 }
2431
2432 /*
2433  * Set device link down.
2434  */
2435 int
2436 ipn3ke_rpst_dev_set_link_down(struct rte_eth_dev *dev)
2437 {
2438         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(dev);
2439         struct rte_eth_dev *pf;
2440         int ret = 0;
2441
2442         if (rpst->i40e_pf_eth) {
2443                 ret = rte_eth_dev_set_link_down(rpst->i40e_pf_eth_port_id);
2444                 pf = rpst->i40e_pf_eth;
2445                 (*rpst->i40e_pf_eth->dev_ops->link_update)(pf, 1);
2446         }
2447
2448         return ret;
2449 }
2450
2451 int
2452 ipn3ke_rpst_link_update(struct rte_eth_dev *ethdev,
2453         __rte_unused int wait_to_complete)
2454 {
2455         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2456         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2457         struct rte_rawdev *rawdev;
2458         struct rte_eth_link link;
2459         struct rte_eth_dev *pf;
2460
2461         memset(&link, 0, sizeof(link));
2462
2463         link.link_duplex = ETH_LINK_FULL_DUPLEX;
2464         link.link_autoneg = !(ethdev->data->dev_conf.link_speeds &
2465                                 ETH_LINK_SPEED_FIXED);
2466
2467         rawdev = hw->rawdev;
2468         ipn3ke_update_link(rawdev, rpst->port_id, &link);
2469
2470         if (!rpst->ori_linfo.link_status &&
2471                 link.link_status) {
2472                 IPN3KE_AFU_PMD_DEBUG("Update Rpst %d Up\n", rpst->port_id);
2473                 rpst->ori_linfo.link_status = link.link_status;
2474                 rpst->ori_linfo.link_speed = link.link_speed;
2475
2476                 rte_eth_linkstatus_set(ethdev, &link);
2477
2478                 if (rpst->i40e_pf_eth) {
2479                         IPN3KE_AFU_PMD_DEBUG("Update FVL PF %d Up\n",
2480                                 rpst->i40e_pf_eth_port_id);
2481                         rte_eth_dev_set_link_up(rpst->i40e_pf_eth_port_id);
2482                         pf = rpst->i40e_pf_eth;
2483                         (*rpst->i40e_pf_eth->dev_ops->link_update)(pf, 1);
2484                 }
2485         } else if (rpst->ori_linfo.link_status &&
2486                                 !link.link_status) {
2487                 IPN3KE_AFU_PMD_DEBUG("Update Rpst %d Down\n",
2488                         rpst->port_id);
2489                 rpst->ori_linfo.link_status = link.link_status;
2490                 rpst->ori_linfo.link_speed = link.link_speed;
2491
2492                 rte_eth_linkstatus_set(ethdev, &link);
2493
2494                 if (rpst->i40e_pf_eth) {
2495                         IPN3KE_AFU_PMD_DEBUG("Update FVL PF %d Down\n",
2496                                 rpst->i40e_pf_eth_port_id);
2497                         rte_eth_dev_set_link_down(rpst->i40e_pf_eth_port_id);
2498                         pf = rpst->i40e_pf_eth;
2499                         (*rpst->i40e_pf_eth->dev_ops->link_update)(pf, 1);
2500                 }
2501         }
2502
2503         return 0;
2504 }
2505
2506 static int
2507 ipn3ke_rpst_link_check(struct ipn3ke_rpst *rpst)
2508 {
2509         struct ipn3ke_hw *hw;
2510         struct rte_rawdev *rawdev;
2511         struct rte_eth_link link;
2512         struct rte_eth_dev *pf;
2513
2514         if (rpst == NULL)
2515                 return -1;
2516
2517         hw = rpst->hw;
2518
2519         memset(&link, 0, sizeof(link));
2520
2521         link.link_duplex = ETH_LINK_FULL_DUPLEX;
2522         link.link_autoneg = !(rpst->ethdev->data->dev_conf.link_speeds &
2523                                 ETH_LINK_SPEED_FIXED);
2524
2525         rawdev = hw->rawdev;
2526         ipn3ke_update_link(rawdev, rpst->port_id, &link);
2527
2528         if (!rpst->ori_linfo.link_status &&
2529                                 link.link_status) {
2530                 IPN3KE_AFU_PMD_DEBUG("Check Rpst %d Up\n", rpst->port_id);
2531                 rpst->ori_linfo.link_status = link.link_status;
2532                 rpst->ori_linfo.link_speed = link.link_speed;
2533
2534                 rte_eth_linkstatus_set(rpst->ethdev, &link);
2535
2536                 if (rpst->i40e_pf_eth) {
2537                         IPN3KE_AFU_PMD_DEBUG("Check FVL PF %d Up\n",
2538                                 rpst->i40e_pf_eth_port_id);
2539                         rte_eth_dev_set_link_up(rpst->i40e_pf_eth_port_id);
2540                         pf = rpst->i40e_pf_eth;
2541                         (*rpst->i40e_pf_eth->dev_ops->link_update)(pf, 1);
2542                 }
2543         } else if (rpst->ori_linfo.link_status &&
2544                 !link.link_status) {
2545                 IPN3KE_AFU_PMD_DEBUG("Check Rpst %d Down\n", rpst->port_id);
2546                 rpst->ori_linfo.link_status = link.link_status;
2547                 rpst->ori_linfo.link_speed = link.link_speed;
2548
2549                 rte_eth_linkstatus_set(rpst->ethdev, &link);
2550
2551                 if (rpst->i40e_pf_eth) {
2552                         IPN3KE_AFU_PMD_DEBUG("Check FVL PF %d Down\n",
2553                                 rpst->i40e_pf_eth_port_id);
2554                         rte_eth_dev_set_link_down(rpst->i40e_pf_eth_port_id);
2555                         pf = rpst->i40e_pf_eth;
2556                         (*rpst->i40e_pf_eth->dev_ops->link_update)(pf, 1);
2557                 }
2558         }
2559
2560         return 0;
2561 }
2562
2563 static void *
2564 ipn3ke_rpst_scan_handle_request(__rte_unused void *param)
2565 {
2566         struct ipn3ke_rpst *rpst;
2567         int num = 0;
2568 #define MS 1000
2569 #define SCAN_NUM 32
2570
2571         for (;;) {
2572                 num = 0;
2573                 TAILQ_FOREACH(rpst, &ipn3ke_rpst_list, next) {
2574                         if (rpst->i40e_pf_eth &&
2575                                 rpst->ethdev->data->dev_started &&
2576                                 rpst->i40e_pf_eth->data->dev_started)
2577                                 ipn3ke_rpst_link_check(rpst);
2578
2579                         if (++num > SCAN_NUM)
2580                                 rte_delay_us(1 * MS);
2581                 }
2582                 rte_delay_us(50 * MS);
2583
2584                 if (num == 0xffffff)
2585                         return NULL;
2586         }
2587
2588         return NULL;
2589 }
2590
2591 static int
2592 ipn3ke_rpst_scan_check(void)
2593 {
2594         int ret;
2595
2596         if (ipn3ke_rpst_scan_num == 1) {
2597                 ret = pthread_create(&ipn3ke_rpst_scan_thread,
2598                         NULL,
2599                         ipn3ke_rpst_scan_handle_request, NULL);
2600                 if (ret) {
2601                         IPN3KE_AFU_PMD_ERR("Fail to create ipn3ke rpst scan thread");
2602                         return -1;
2603                 }
2604         } else if (ipn3ke_rpst_scan_num == 0) {
2605                 ret = pthread_cancel(ipn3ke_rpst_scan_thread);
2606                 if (ret)
2607                         IPN3KE_AFU_PMD_ERR("Can't cancel the thread");
2608
2609                 ret = pthread_join(ipn3ke_rpst_scan_thread, NULL);
2610                 if (ret)
2611                         IPN3KE_AFU_PMD_ERR("Can't join the thread");
2612
2613                 return ret;
2614         }
2615
2616         return 0;
2617 }
2618
2619 void
2620 ipn3ke_rpst_promiscuous_enable(struct rte_eth_dev *ethdev)
2621 {
2622         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2623         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2624         uint32_t rddata, val;
2625
2626         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
2627                 /* Enable all unicast */
2628                 (*hw->f_mac_read)(hw,
2629                                 &rddata,
2630                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2631                                 rpst->port_id,
2632                                 0);
2633                 val = 1;
2634                 val &= IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLUCAST_MASK;
2635                 val |= rddata;
2636                 (*hw->f_mac_write)(hw,
2637                                 val,
2638                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2639                                 rpst->port_id,
2640                                 0);
2641         }
2642 }
2643
2644 void
2645 ipn3ke_rpst_promiscuous_disable(struct rte_eth_dev *ethdev)
2646 {
2647         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2648         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2649         uint32_t rddata, val;
2650
2651         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
2652                 /* Disable all unicast */
2653                 (*hw->f_mac_read)(hw,
2654                                 &rddata,
2655                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2656                                 rpst->port_id,
2657                                 0);
2658                 val = 0;
2659                 val &= IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLUCAST_MASK;
2660                 val |= rddata;
2661                 (*hw->f_mac_write)(hw,
2662                                 val,
2663                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2664                                 rpst->port_id,
2665                                 0);
2666         }
2667 }
2668
2669 void
2670 ipn3ke_rpst_allmulticast_enable(struct rte_eth_dev *ethdev)
2671 {
2672         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2673         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2674         uint32_t rddata, val;
2675
2676         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
2677                 /* Enable all unicast */
2678                 (*hw->f_mac_read)(hw,
2679                                 &rddata,
2680                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2681                                 rpst->port_id,
2682                                 0);
2683                 val = 1;
2684                 val <<= IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_SHIFT;
2685                 val &= IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_MASK;
2686                 val |= rddata;
2687                 (*hw->f_mac_write)(hw,
2688                                 val,
2689                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2690                                 rpst->port_id,
2691                                 0);
2692         }
2693 }
2694
2695 void
2696 ipn3ke_rpst_allmulticast_disable(struct rte_eth_dev *ethdev)
2697 {
2698         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2699         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2700         uint32_t rddata, val;
2701
2702         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
2703                 /* Disable all unicast */
2704                 (*hw->f_mac_read)(hw,
2705                                 &rddata,
2706                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2707                                 rpst->port_id,
2708                                 0);
2709                 val = 0;
2710                 val <<= IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_SHIFT;
2711                 val &= IPN3KE_MAC_RX_FRAME_CONTROL_EN_ALLMCAST_MASK;
2712                 val |= rddata;
2713                 (*hw->f_mac_write)(hw,
2714                                 val,
2715                                 IPN3KE_MAC_RX_FRAME_CONTROL,
2716                                 rpst->port_id,
2717                                 0);
2718         }
2719 }
2720
2721 int
2722 ipn3ke_rpst_mac_addr_set(struct rte_eth_dev *ethdev,
2723                                 struct rte_ether_addr *mac_addr)
2724 {
2725         struct ipn3ke_hw *hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2726         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2727         uint32_t val;
2728
2729         if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
2730                 IPN3KE_AFU_PMD_ERR("Tried to set invalid MAC address.");
2731                 return -EINVAL;
2732         }
2733
2734         if (hw->retimer.mac_type == IFPGA_RAWDEV_RETIMER_MAC_TYPE_10GE_XFI) {
2735                 rte_ether_addr_copy(&mac_addr[0], &rpst->mac_addr);
2736
2737                 /* Set mac address */
2738                 rte_memcpy(((char *)(&val)), &mac_addr[0], sizeof(uint32_t));
2739                 (*hw->f_mac_write)(hw,
2740                                 val,
2741                                 IPN3KE_MAC_PRIMARY_MAC_ADDR0,
2742                                 rpst->port_id,
2743                                 0);
2744                 rte_memcpy(((char *)(&val)), &mac_addr[4], sizeof(uint16_t));
2745                 (*hw->f_mac_write)(hw,
2746                                 val,
2747                                 IPN3KE_MAC_PRIMARY_MAC_ADDR0,
2748                                 rpst->port_id,
2749                                 0);
2750         }
2751
2752         return 0;
2753 }
2754
2755 int
2756 ipn3ke_rpst_mtu_set(struct rte_eth_dev *ethdev, uint16_t mtu)
2757 {
2758         int ret = 0;
2759         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2760         struct rte_eth_dev_data *dev_data = ethdev->data;
2761         uint32_t frame_size = mtu  + IPN3KE_ETH_OVERHEAD;
2762
2763         /* check if mtu is within the allowed range */
2764         if (mtu < RTE_ETHER_MIN_MTU ||
2765                 frame_size > IPN3KE_MAC_FRAME_SIZE_MAX)
2766                 return -EINVAL;
2767
2768         /* mtu setting is forbidden if port is start */
2769         /* make sure NIC port is stopped */
2770         if (rpst->i40e_pf_eth && rpst->i40e_pf_eth->data->dev_started) {
2771                 IPN3KE_AFU_PMD_ERR("NIC port %d must "
2772                         "be stopped before configuration",
2773                         rpst->i40e_pf_eth->data->port_id);
2774                 return -EBUSY;
2775         }
2776         /* mtu setting is forbidden if port is start */
2777         if (dev_data->dev_started) {
2778                 IPN3KE_AFU_PMD_ERR("FPGA port %d must "
2779                         "be stopped before configuration",
2780                         dev_data->port_id);
2781                 return -EBUSY;
2782         }
2783
2784         if (frame_size > RTE_ETHER_MAX_LEN)
2785                 dev_data->dev_conf.rxmode.offloads |=
2786                         (uint64_t)(DEV_RX_OFFLOAD_JUMBO_FRAME);
2787         else
2788                 dev_data->dev_conf.rxmode.offloads &=
2789                         (uint64_t)(~DEV_RX_OFFLOAD_JUMBO_FRAME);
2790
2791         dev_data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
2792
2793         if (rpst->i40e_pf_eth) {
2794                 ret = rpst->i40e_pf_eth->dev_ops->mtu_set(rpst->i40e_pf_eth,
2795                                                         mtu);
2796                 if (!ret)
2797                         rpst->i40e_pf_eth->data->mtu = mtu;
2798         }
2799
2800         return ret;
2801 }
2802
2803 static int
2804 ipn3ke_afu_filter_ctrl(struct rte_eth_dev *ethdev,
2805         enum rte_filter_type filter_type, enum rte_filter_op filter_op,
2806         void *arg)
2807 {
2808         int ret = 0;
2809         struct ipn3ke_hw *hw;
2810         struct ipn3ke_rpst *rpst;
2811
2812         if (ethdev == NULL)
2813                 return -EINVAL;
2814
2815         hw = IPN3KE_DEV_PRIVATE_TO_HW(ethdev);
2816         rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2817
2818         if (hw->acc_flow)
2819                 switch (filter_type) {
2820                 case RTE_ETH_FILTER_GENERIC:
2821                         if (filter_op != RTE_ETH_FILTER_GET)
2822                                 return -EINVAL;
2823                         *(const void **)arg = &ipn3ke_flow_ops;
2824                         break;
2825                 default:
2826                         IPN3KE_AFU_PMD_WARN("Filter type (%d) not supported",
2827                                         filter_type);
2828                         ret = -EINVAL;
2829                         break;
2830                 }
2831         else if (rpst->i40e_pf_eth)
2832                 (*rpst->i40e_pf_eth->dev_ops->filter_ctrl)(ethdev,
2833                                                         filter_type,
2834                                                         filter_op,
2835                                                         arg);
2836         else
2837                 return -EINVAL;
2838
2839         return ret;
2840 }
2841
2842 static const struct eth_dev_ops ipn3ke_rpst_dev_ops = {
2843         .dev_infos_get        = ipn3ke_rpst_dev_infos_get,
2844
2845         .dev_configure        = ipn3ke_rpst_dev_configure,
2846         .dev_start            = ipn3ke_rpst_dev_start,
2847         .dev_stop             = ipn3ke_rpst_dev_stop,
2848         .dev_close            = ipn3ke_rpst_dev_close,
2849         .dev_reset            = ipn3ke_rpst_dev_reset,
2850
2851         .stats_get            = ipn3ke_rpst_stats_get,
2852         .xstats_get           = ipn3ke_rpst_xstats_get,
2853         .xstats_get_names     = ipn3ke_rpst_xstats_get_names,
2854         .stats_reset          = ipn3ke_rpst_stats_reset,
2855         .xstats_reset         = ipn3ke_rpst_stats_reset,
2856
2857         .filter_ctrl          = ipn3ke_afu_filter_ctrl,
2858
2859         .rx_queue_start       = ipn3ke_rpst_rx_queue_start,
2860         .rx_queue_stop        = ipn3ke_rpst_rx_queue_stop,
2861         .tx_queue_start       = ipn3ke_rpst_tx_queue_start,
2862         .tx_queue_stop        = ipn3ke_rpst_tx_queue_stop,
2863         .rx_queue_setup       = ipn3ke_rpst_rx_queue_setup,
2864         .rx_queue_release     = ipn3ke_rpst_rx_queue_release,
2865         .tx_queue_setup       = ipn3ke_rpst_tx_queue_setup,
2866         .tx_queue_release     = ipn3ke_rpst_tx_queue_release,
2867
2868         .dev_set_link_up      = ipn3ke_rpst_dev_set_link_up,
2869         .dev_set_link_down    = ipn3ke_rpst_dev_set_link_down,
2870         .link_update          = ipn3ke_rpst_link_update,
2871
2872         .promiscuous_enable   = ipn3ke_rpst_promiscuous_enable,
2873         .promiscuous_disable  = ipn3ke_rpst_promiscuous_disable,
2874         .allmulticast_enable  = ipn3ke_rpst_allmulticast_enable,
2875         .allmulticast_disable = ipn3ke_rpst_allmulticast_disable,
2876         .mac_addr_set         = ipn3ke_rpst_mac_addr_set,
2877         .mtu_set              = ipn3ke_rpst_mtu_set,
2878
2879         .tm_ops_get           = ipn3ke_tm_ops_get,
2880 };
2881
2882 static uint16_t ipn3ke_rpst_recv_pkts(__rte_unused void *rx_q,
2883         __rte_unused struct rte_mbuf **rx_pkts, __rte_unused uint16_t nb_pkts)
2884 {
2885         return 0;
2886 }
2887
2888 static uint16_t
2889 ipn3ke_rpst_xmit_pkts(__rte_unused void *tx_queue,
2890         __rte_unused struct rte_mbuf **tx_pkts, __rte_unused uint16_t nb_pkts)
2891 {
2892         return 0;
2893 }
2894
2895 int
2896 ipn3ke_rpst_init(struct rte_eth_dev *ethdev, void *init_params)
2897 {
2898         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2899         struct ipn3ke_rpst *representor_param =
2900                         (struct ipn3ke_rpst *)init_params;
2901
2902         if (representor_param->port_id >= representor_param->hw->port_num)
2903                 return -ENODEV;
2904
2905         rpst->ethdev = ethdev;
2906         rpst->switch_domain_id = representor_param->switch_domain_id;
2907         rpst->port_id = representor_param->port_id;
2908         rpst->hw = representor_param->hw;
2909         rpst->i40e_pf_eth = NULL;
2910         rpst->i40e_pf_eth_port_id = 0xFFFF;
2911
2912         ethdev->data->mac_addrs = rte_zmalloc("ipn3ke", RTE_ETHER_ADDR_LEN, 0);
2913         if (!ethdev->data->mac_addrs) {
2914                 IPN3KE_AFU_PMD_ERR("Failed to "
2915                         "allocated memory for storing mac address");
2916                 return -ENODEV;
2917         }
2918
2919         if (rpst->hw->tm_hw_enable)
2920                 ipn3ke_tm_init(rpst);
2921
2922         /* Set representor device ops */
2923         ethdev->dev_ops = &ipn3ke_rpst_dev_ops;
2924
2925         /* No data-path, but need stub Rx/Tx functions to avoid crash
2926          * when testing with the likes of testpmd.
2927          */
2928         ethdev->rx_pkt_burst = ipn3ke_rpst_recv_pkts;
2929         ethdev->tx_pkt_burst = ipn3ke_rpst_xmit_pkts;
2930
2931         ethdev->data->nb_rx_queues = 1;
2932         ethdev->data->nb_tx_queues = 1;
2933
2934         ethdev->data->mac_addrs = rte_zmalloc("ipn3ke_afu_representor",
2935                                                 RTE_ETHER_ADDR_LEN,
2936                                                 0);
2937         if (!ethdev->data->mac_addrs) {
2938                 IPN3KE_AFU_PMD_ERR("Failed to "
2939                         "allocated memory for storing mac address");
2940                 return -ENODEV;
2941         }
2942
2943         ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
2944
2945         rte_spinlock_lock(&ipn3ke_link_notify_list_lk);
2946         TAILQ_INSERT_TAIL(&ipn3ke_rpst_list, rpst, next);
2947         ipn3ke_rpst_scan_num++;
2948         ipn3ke_rpst_scan_check();
2949         rte_spinlock_unlock(&ipn3ke_link_notify_list_lk);
2950
2951         return 0;
2952 }
2953
2954 int
2955 ipn3ke_rpst_uninit(struct rte_eth_dev *ethdev)
2956 {
2957         struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
2958
2959         rte_spinlock_lock(&ipn3ke_link_notify_list_lk);
2960         TAILQ_REMOVE(&ipn3ke_rpst_list, rpst, next);
2961         ipn3ke_rpst_scan_num--;
2962         ipn3ke_rpst_scan_check();
2963         rte_spinlock_unlock(&ipn3ke_link_notify_list_lk);
2964
2965         return 0;
2966 }