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