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