As the ntnic can support different speeds,
an abstraction layer for 100G speed is needed.
Signed-off-by: Serhii Iliushyk <sil-plv@napatech.com>
---
v10
* Use 8 spaces as indentation in meson
---
drivers/net/ntnic/adapter/nt4ga_adapter.c | 12 ++++-
.../link_mgmt/link_100g/nt4ga_link_100g.c | 49 +++++++++++++++++++
drivers/net/ntnic/meson.build | 1 +
drivers/net/ntnic/ntnic_mod_reg.c | 14 ++++++
drivers/net/ntnic/ntnic_mod_reg.h | 8 +++
5 files changed, 82 insertions(+), 2 deletions(-)
create mode 100644 drivers/net/ntnic/link_mgmt/link_100g/nt4ga_link_100g.c
@@ -125,6 +125,7 @@ static int nt4ga_adapter_init(struct adapter_info_s *p_adapter_info)
{
int i;
+ const struct link_ops_s *link_ops = NULL;
assert(fpga_info->n_fpga_prod_id > 0);
for (i = 0; i < NUM_ADAPTER_PORTS_MAX; i++) {
@@ -135,8 +136,15 @@ static int nt4ga_adapter_init(struct adapter_info_s *p_adapter_info)
switch (fpga_info->n_fpga_prod_id) {
/* NT200A01: 2x100G (Xilinx) */
case 9563: /* NT200A02 (Cap) */
- NT_LOG(ERR, NTNIC, "NT200A02 100G link module uninitialized\n");
- res = -1;
+ link_ops = get_100g_link_ops();
+
+ if (link_ops == NULL) {
+ NT_LOG(ERR, NTNIC, "NT200A02 100G link module uninitialized\n");
+ res = -1;
+ break;
+ }
+
+ res = link_ops->link_init(p_adapter_info, p_fpga);
break;
default:
new file mode 100644
@@ -0,0 +1,49 @@
+/*
+ * SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 Napatech A/S
+ */
+
+#include <string.h> /* memcmp, memset */
+
+#include "nt_util.h"
+#include "ntlog.h"
+#include "ntnic_mod_reg.h"
+
+/*
+ * Initialize all ports
+ * The driver calls this function during initialization (of the driver).
+ */
+static int nt4ga_link_100g_ports_init(struct adapter_info_s *p_adapter_info, nthw_fpga_t *fpga)
+{
+ (void)fpga;
+ const int adapter_no = p_adapter_info->adapter_no;
+ int res = 0;
+
+ NT_LOG(DBG, NTNIC, "%s: Initializing ports\n", p_adapter_info->mp_adapter_id_str);
+
+ /*
+ * Initialize global variables
+ */
+ assert(adapter_no >= 0 && adapter_no < NUM_ADAPTER_MAX);
+
+ if (res == 0 && !p_adapter_info->nt4ga_link.variables_initialized) {
+ if (res == 0) {
+ p_adapter_info->nt4ga_link.speed_capa = NT_LINK_SPEED_100G;
+ p_adapter_info->nt4ga_link.variables_initialized = true;
+ }
+ }
+
+ return res;
+}
+
+/*
+ * Init 100G link ops variables
+ */
+static struct link_ops_s link_100g_ops = {
+ .link_init = nt4ga_link_100g_ports_init,
+};
+
+void link_100g_init(void)
+{
+ register_100g_link_ops(&link_100g_ops);
+}
@@ -22,6 +22,7 @@ includes = [
# all sources
sources = files(
'adapter/nt4ga_adapter.c',
+ 'link_mgmt/link_100g/nt4ga_link_100g.c',
'link_mgmt/nt4ga_link.c',
'nthw/supported/nthw_fpga_9563_055_039_0000.c',
'nthw/supported/nthw_fpga_instances.c',
@@ -5,6 +5,20 @@
#include "ntnic_mod_reg.h"
+static struct link_ops_s *link_100g_ops;
+
+void register_100g_link_ops(struct link_ops_s *ops)
+{
+ link_100g_ops = ops;
+}
+
+const struct link_ops_s *get_100g_link_ops(void)
+{
+ if (link_100g_ops == NULL)
+ link_100g_init();
+ return link_100g_ops;
+}
+
static const struct port_ops *port_ops;
void register_port_ops(const struct port_ops *ops)
@@ -13,6 +13,14 @@
#include "nt4ga_adapter.h"
#include "ntnic_nthw_fpga_rst_nt200a0x.h"
+struct link_ops_s {
+ int (*link_init)(struct adapter_info_s *p_adapter_info, nthw_fpga_t *p_fpga);
+};
+
+void register_100g_link_ops(struct link_ops_s *ops);
+const struct link_ops_s *get_100g_link_ops(void);
+void link_100g_init(void);
+
struct port_ops {
/*
* port:s link mode