aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src/hicn/config/controlSetStrategy.c
blob: 3229c1864f655a63ef88ac8010a4e4731cfb7631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
 * Copyright (c) 2017-2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <hicn/hicn-light/config.h>

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <parc/assert/parc_Assert.h>

#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>

#include <hicn/config/controlSetDebug.h>
#include <hicn/core/dispatcher.h>
#include <hicn/core/forwarder.h>

#include <hicn/utils/commands.h>
#include <hicn/utils/utils.h>

static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
                                                 CommandOps *ops,
                                                 PARCList *args,
                                                 char *output,
                                                 size_t output_size);
static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser,
                                                     CommandOps *ops,
                                                     PARCList *args,
                                                     char *output,
                                                     size_t output_size);

static const char *_commandSetStrategy = "set strategy";
static const char *_commandSetStrategyHelp = "help set strategy";

static const char *_commandSetStrategyOptions[LAST_STRATEGY_VALUE] = {
    "loadbalancer",
    "random",
    "low_latency",
};

// ====================================================

CommandOps *controlSetStrategy_Create(ControlState *state) {
  return commandOps_Create(state, _commandSetStrategy, NULL,
                           _controlSetStrategy_Execute, commandOps_Destroy);
}

CommandOps *controlSetStrategy_HelpCreate(ControlState *state) {
  return commandOps_Create(state, _commandSetStrategyHelp, NULL,
                           _controlSetStrategy_HelpExecute, commandOps_Destroy);
}

// ====================================================

strategy_type _validStrategy(const char *strategy) {
  strategy_type validStrategy = LAST_STRATEGY_VALUE;

  for (int i = 0; i < LAST_STRATEGY_VALUE; i++) {
    if (strcmp(_commandSetStrategyOptions[i], strategy) == 0) {
      validStrategy = i;
      break;
    }
  }
  return validStrategy;
}

static void _getAddressAndLen(const char * prefixStr, char *addr, uint32_t *len){
  char *slash;
  strcpy(addr, prefixStr);
  slash = strrchr(addr, '/');
  if (slash != NULL) {
    *len = atoi(slash + 1);
    *slash = '\0';
  }
}

static bool _checkAndSetIp(set_strategy_command * setStrategyCommand,
                           int index,
                           char * addr,
                           uint32_t len,
                           char *output,
                          size_t output_size){
  // check and set IP address
  int res;
  if(index == -1)
    res = inet_pton(AF_INET, addr, &setStrategyCommand->address.v4.as_u32);
  else
    res = inet_pton(AF_INET, addr,
              &setStrategyCommand->addresses[index].v4.as_u32);

  if(res == 1) {
    if (len == UINT32_MAX) {
      snprintf(output, output_size, "Netmask not specified: set to 32 by default\n");
      len = 32;
    } else if (len > 32) {
      snprintf(output, output_size, "ERROR: exceeded INET mask length, max=32\n");
      return false;
    }
    if(index == -1)
      setStrategyCommand->addressType = ADDR_INET;
    else
      setStrategyCommand->addresses_type[index] = ADDR_INET;

  } else {

    if(index == -1)
      res = inet_pton(AF_INET6, addr,
            &setStrategyCommand->address.v6.as_in6addr);
    else
      res = inet_pton(AF_INET6, addr,
            &setStrategyCommand->addresses[index].v6.as_in6addr);

    if(res == 1) {
      if (len == UINT32_MAX) {
        snprintf(output, output_size, "Netmask not specified: set to 128 by default\n");
        len = 128;
      } else if (len > 128) {
        snprintf(output, output_size, "ERROR: exceeded INET6 mask length, max=128\n");
        return false;
      }

      if(index == -1)
        setStrategyCommand->addressType = ADDR_INET6;
      else
        setStrategyCommand->addresses_type[index] = ADDR_INET6;

    } else {
      snprintf(output, output_size, "Error: %s is not a valid network address \n", addr);

      return false;
    }
  }
  return true;
}

static CommandReturn _controlSetStrategy_HelpExecute(CommandParser *parser,
                                                     CommandOps *ops,
                                                     PARCList *args,
                                                     char *output,
                                                     size_t output_size) {
  snprintf(output, output_size,
                     "set strategy <prefix> <strategy> "
                     "[related_prefix1 related_preifx2  ...]\n"
                     "prefix: ipv4/ipv6 address (ex: 1234::/64)\n"
                     "strategy: strategy identifier\n"
                     "optinal: list of related prefixes (max %u)\n"
                     "available strategies:\n"
                     "    random\n"
                     "    loadbalancer\n"
                     "    low_latency\n\n",
                     MAX_FWD_STRATEGY_RELATED_PREFIXES);
  return CommandReturn_Success;
}


static CommandReturn _controlSetStrategy_Execute(CommandParser *parser,
                                                 CommandOps *ops,
                                                 PARCList *args,
                                                 char *output,
                                                 size_t output_size) {
  if (output) {
    output[0] = '\0';
  }
  ControlState *state = ops->closure;

  if (parcList_Size(args) < 4 ||
          parcList_Size(args) > (4 + MAX_FWD_STRATEGY_RELATED_PREFIXES)) {
    _controlSetStrategy_HelpExecute(parser, ops, args, output, output_size);
    return CommandReturn_Failure;
  }

  if (((strcmp(parcList_GetAtIndex(args, 0), "set") != 0) ||
       (strcmp(parcList_GetAtIndex(args, 1), "strategy") != 0))) {
    _controlSetStrategy_HelpExecute(parser, ops, args, output, output_size);
    return CommandReturn_Failure;
  }

  const char *prefixStr = parcList_GetAtIndex(args, 2);
  char *addr = (char *)malloc(sizeof(char) * (strlen(prefixStr) + 1));
  uint32_t len = UINT32_MAX;
  _getAddressAndLen(prefixStr, addr, &len);

  // allocate command payload
  set_strategy_command *setStrategyCommand =
      parcMemory_AllocateAndClear(sizeof(set_strategy_command));

  bool success = _checkAndSetIp(setStrategyCommand, -1, addr, len, output, output_size);
  if(!success){
    parcMemory_Deallocate(&setStrategyCommand);
    free(addr);
    return CommandReturn_Failure;
  }

  const char *strategyStr = parcList_GetAtIndex(args, 3);
  // check valid strategy
  strategy_type strategy;
  if ((strategy = _validStrategy(strategyStr)) == LAST_STRATEGY_VALUE) {
    size_t output_offset = strlen(output);
    output_offset += snprintf(output + output_offset, output_size - output_offset, "Error: invalid strategy \n");
    
    parcMemory_Deallocate(&setStrategyCommand);
    _controlSetStrategy_HelpExecute(parser, ops, args, output + output_offset, output_size - output_offset);
    free(addr);
    return CommandReturn_Failure;
  }

  free(addr);

  // Fill remaining payload fields
  setStrategyCommand->len = len;
  setStrategyCommand->strategyType = strategy;
  size_t output_offset = strlen(output);
  //check additional prefixes
  if(parcList_Size(args) > 4){
    uint32_t index = 4; //first realted prefix
    uint32_t addr_index = 0;
    setStrategyCommand->related_prefixes = parcList_Size(args) - 4;
    while(index < parcList_Size(args)){
      const char *str = parcList_GetAtIndex(args, index);
      char *rel_addr = (char *)malloc(sizeof(char) * (strlen(str) + 1));
      uint32_t rel_len = UINT32_MAX;
      _getAddressAndLen(str, rel_addr, &rel_len);
      bool success = _checkAndSetIp(setStrategyCommand, addr_index,
                                          rel_addr, rel_len, output + output_offset, output_size - output_offset);
      if(!success){
        parcMemory_Deallocate(&setStrategyCommand);
        free(rel_addr);
        return CommandReturn_Failure;
      }
      output_offset = strlen(output);
      setStrategyCommand->lens[addr_index] = rel_len;
      free(rel_addr);
      index++;
      addr_index++;
    }
  }else{
    setStrategyCommand->related_prefixes = 0;
  }

  // send message and receive response
  struct iovec *response = utils_SendRequest(
      state, SET_STRATEGY, setStrategyCommand, sizeof(set_strategy_command));

  if (!response) {  // get NULL pointer
    return CommandReturn_Failure;
  }

  parcMemory_Deallocate(&response);  // free iovec pointer
  return CommandReturn_Success;
}
lass="n">bnx2x_alloc_ilt_mem(sc) != 0) { PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_ilt_mem was failed"); return -ENXIO; } /* allocate the host hardware/software hsi structures */ if (bnx2x_alloc_hsi_mem(sc) != 0) { PMD_DRV_LOG(ERR, sc, "bnx2x_alloc_hsi_mem was failed"); bnx2x_free_ilt_mem(sc); return -ENXIO; } return 0; } static int bnx2x_dev_start(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; int ret = 0; PMD_INIT_FUNC_TRACE(sc); ret = bnx2x_init(sc); if (ret) { PMD_DRV_LOG(DEBUG, sc, "bnx2x_init failed (%d)", ret); return -1; } if (IS_PF(sc)) { rte_intr_callback_register(&(dev->pci_dev->intr_handle), bnx2x_interrupt_handler, (void *)dev); if(rte_intr_enable(&(dev->pci_dev->intr_handle))) PMD_DRV_LOG(ERR, sc, "rte_intr_enable failed"); } ret = bnx2x_dev_rx_init(dev); if (ret != 0) { PMD_DRV_LOG(DEBUG, sc, "bnx2x_dev_rx_init returned error code"); return -3; } /* Print important adapter info for the user. */ bnx2x_print_adapter_info(sc); return ret; } static void bnx2x_dev_stop(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; int ret = 0; PMD_INIT_FUNC_TRACE(sc); if (IS_PF(sc)) { rte_intr_disable(&(dev->pci_dev->intr_handle)); rte_intr_callback_unregister(&(dev->pci_dev->intr_handle), bnx2x_interrupt_handler, (void *)dev); } ret = bnx2x_nic_unload(sc, UNLOAD_NORMAL, FALSE); if (ret) { PMD_DRV_LOG(DEBUG, sc, "bnx2x_nic_unload failed (%d)", ret); return; } return; } static void bnx2x_dev_close(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); if (IS_VF(sc)) bnx2x_vf_close(sc); bnx2x_dev_clear_queues(dev); memset(&(dev->data->dev_link), 0 , sizeof(struct rte_eth_link)); /* free the host hardware/software hsi structures */ bnx2x_free_hsi_mem(sc); /* free ilt */ bnx2x_free_ilt_mem(sc); } static void bnx2x_promisc_enable(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); sc->rx_mode = BNX2X_RX_MODE_PROMISC; if (rte_eth_allmulticast_get(dev->data->port_id) == 1) sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC; bnx2x_set_rx_mode(sc); } static void bnx2x_promisc_disable(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); sc->rx_mode = BNX2X_RX_MODE_NORMAL; if (rte_eth_allmulticast_get(dev->data->port_id) == 1) sc->rx_mode = BNX2X_RX_MODE_ALLMULTI; bnx2x_set_rx_mode(sc); } static void bnx2x_dev_allmulticast_enable(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); sc->rx_mode = BNX2X_RX_MODE_ALLMULTI; if (rte_eth_promiscuous_get(dev->data->port_id) == 1) sc->rx_mode = BNX2X_RX_MODE_ALLMULTI_PROMISC; bnx2x_set_rx_mode(sc); } static void bnx2x_dev_allmulticast_disable(struct rte_eth_dev *dev) { struct bnx2x_softc *sc = dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); sc->rx_mode = BNX2X_RX_MODE_NORMAL; if (rte_eth_promiscuous_get(dev->data->port_id) == 1) sc->rx_mode = BNX2X_RX_MODE_PROMISC; bnx2x_set_rx_mode(sc); } static int bnx2x_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) { struct bnx2x_softc *sc = dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); int old_link_status = dev->data->dev_link.link_status; bnx2x_link_update(dev); return old_link_status == dev->data->dev_link.link_status ? -1 : 0; } static int bnx2xvf_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete) { int old_link_status = dev->data->dev_link.link_status; struct bnx2x_softc *sc = dev->data->dev_private; bnx2x_link_update(dev); bnx2x_check_bull(sc); if (sc->old_bulletin.valid_bitmap & (1 << CHANNEL_DOWN)) { PMD_DRV_LOG(ERR, sc, "PF indicated channel is down." "VF device is no longer operational"); dev->data->dev_link.link_status = ETH_LINK_DOWN; } return old_link_status == dev->data->dev_link.link_status ? -1 : 0; } static void bnx2x_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats) { struct bnx2x_softc *sc = dev->data->dev_private; uint32_t brb_truncate_discard; uint64_t brb_drops; uint64_t brb_truncates; PMD_INIT_FUNC_TRACE(sc); bnx2x_stats_handle(sc, STATS_EVENT_UPDATE); memset(stats, 0, sizeof (struct rte_eth_stats)); stats->ipackets = HILO_U64(sc->eth_stats.total_unicast_packets_received_hi, sc->eth_stats.total_unicast_packets_received_lo) + HILO_U64(sc->eth_stats.total_multicast_packets_received_hi, sc->eth_stats.total_multicast_packets_received_lo) + HILO_U64(sc->eth_stats.total_broadcast_packets_received_hi, sc->eth_stats.total_broadcast_packets_received_lo); stats->opackets = HILO_U64(sc->eth_stats.total_unicast_packets_transmitted_hi, sc->eth_stats.total_unicast_packets_transmitted_lo) + HILO_U64(sc->eth_stats.total_multicast_packets_transmitted_hi, sc->eth_stats.total_multicast_packets_transmitted_lo) + HILO_U64(sc->eth_stats.total_broadcast_packets_transmitted_hi, sc->eth_stats.total_broadcast_packets_transmitted_lo); stats->ibytes = HILO_U64(sc->eth_stats.total_bytes_received_hi, sc->eth_stats.total_bytes_received_lo); stats->obytes = HILO_U64(sc->eth_stats.total_bytes_transmitted_hi, sc->eth_stats.total_bytes_transmitted_lo); stats->ierrors = HILO_U64(sc->eth_stats.error_bytes_received_hi, sc->eth_stats.error_bytes_received_lo); stats->oerrors = 0; stats->rx_nombuf = HILO_U64(sc->eth_stats.no_buff_discard_hi, sc->eth_stats.no_buff_discard_lo); brb_drops = HILO_U64(sc->eth_stats.brb_drop_hi, sc->eth_stats.brb_drop_lo); brb_truncates = HILO_U64(sc->eth_stats.brb_truncate_hi, sc->eth_stats.brb_truncate_lo); brb_truncate_discard = sc->eth_stats.brb_truncate_discard; stats->imissed = brb_drops + brb_truncates + brb_truncate_discard + stats->rx_nombuf; } static int bnx2x_get_xstats_names(__rte_unused struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit) { unsigned int i, stat_cnt = RTE_DIM(bnx2x_xstats_strings); if (xstats_names != NULL) for (i = 0; i < stat_cnt; i++) snprintf(xstats_names[i].name, sizeof(xstats_names[i].name), "%s", bnx2x_xstats_strings[i].name); return stat_cnt; } static int bnx2x_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats, unsigned int n) { struct bnx2x_softc *sc = dev->data->dev_private; unsigned int num = RTE_DIM(bnx2x_xstats_strings); if (n < num) return num; bnx2x_stats_handle(sc, STATS_EVENT_UPDATE); for (num = 0; num < n; num++) { if (bnx2x_xstats_strings[num].offset_hi != bnx2x_xstats_strings[num].offset_lo) xstats[num].value = HILO_U64( *(uint32_t *)((char *)&sc->eth_stats + bnx2x_xstats_strings[num].offset_hi), *(uint32_t *)((char *)&sc->eth_stats + bnx2x_xstats_strings[num].offset_lo)); else xstats[num].value = *(uint64_t *)((char *)&sc->eth_stats + bnx2x_xstats_strings[num].offset_lo); xstats[num].id = num; } return num; } static void bnx2x_dev_infos_get(struct rte_eth_dev *dev, __rte_unused struct rte_eth_dev_info *dev_info) { struct bnx2x_softc *sc = dev->data->dev_private; dev_info->max_rx_queues = sc->max_rx_queues; dev_info->max_tx_queues = sc->max_tx_queues; dev_info->min_rx_bufsize = BNX2X_MIN_RX_BUF_SIZE; dev_info->max_rx_pktlen = BNX2X_MAX_RX_PKT_LEN; dev_info->max_mac_addrs = BNX2X_MAX_MAC_ADDRS; dev_info->speed_capa = ETH_LINK_SPEED_10G | ETH_LINK_SPEED_20G; } static void bnx2x_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr, uint32_t index, uint32_t pool) { struct bnx2x_softc *sc = dev->data->dev_private; if (sc->mac_ops.mac_addr_add) sc->mac_ops.mac_addr_add(dev, mac_addr, index, pool); } static void bnx2x_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index) { struct bnx2x_softc *sc = dev->data->dev_private; if (sc->mac_ops.mac_addr_remove) sc->mac_ops.mac_addr_remove(dev, index); } static const struct eth_dev_ops bnx2x_eth_dev_ops = { .dev_configure = bnx2x_dev_configure, .dev_start = bnx2x_dev_start, .dev_stop = bnx2x_dev_stop, .dev_close = bnx2x_dev_close, .promiscuous_enable = bnx2x_promisc_enable, .promiscuous_disable = bnx2x_promisc_disable, .allmulticast_enable = bnx2x_dev_allmulticast_enable, .allmulticast_disable = bnx2x_dev_allmulticast_disable, .link_update = bnx2x_dev_link_update, .stats_get = bnx2x_dev_stats_get, .xstats_get = bnx2x_dev_xstats_get, .xstats_get_names = bnx2x_get_xstats_names, .dev_infos_get = bnx2x_dev_infos_get, .rx_queue_setup = bnx2x_dev_rx_queue_setup, .rx_queue_release = bnx2x_dev_rx_queue_release, .tx_queue_setup = bnx2x_dev_tx_queue_setup, .tx_queue_release = bnx2x_dev_tx_queue_release, .mac_addr_add = bnx2x_mac_addr_add, .mac_addr_remove = bnx2x_mac_addr_remove, }; /* * dev_ops for virtual function */ static const struct eth_dev_ops bnx2xvf_eth_dev_ops = { .dev_configure = bnx2x_dev_configure, .dev_start = bnx2x_dev_start, .dev_stop = bnx2x_dev_stop, .dev_close = bnx2x_dev_close, .promiscuous_enable = bnx2x_promisc_enable, .promiscuous_disable = bnx2x_promisc_disable, .allmulticast_enable = bnx2x_dev_allmulticast_enable, .allmulticast_disable = bnx2x_dev_allmulticast_disable, .link_update = bnx2xvf_dev_link_update, .stats_get = bnx2x_dev_stats_get, .xstats_get = bnx2x_dev_xstats_get, .xstats_get_names = bnx2x_get_xstats_names, .dev_infos_get = bnx2x_dev_infos_get, .rx_queue_setup = bnx2x_dev_rx_queue_setup, .rx_queue_release = bnx2x_dev_rx_queue_release, .tx_queue_setup = bnx2x_dev_tx_queue_setup, .tx_queue_release = bnx2x_dev_tx_queue_release, .mac_addr_add = bnx2x_mac_addr_add, .mac_addr_remove = bnx2x_mac_addr_remove, }; static int bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf) { int ret = 0; struct rte_pci_device *pci_dev; struct rte_pci_addr pci_addr; struct bnx2x_softc *sc; /* Extract key data structures */ sc = eth_dev->data->dev_private; pci_dev = eth_dev->pci_dev; pci_addr = pci_dev->addr; snprintf(sc->devinfo.name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u", pci_addr.bus, pci_addr.devid, pci_addr.function, eth_dev->data->port_id); PMD_INIT_FUNC_TRACE(sc); eth_dev->dev_ops = is_vf ? &bnx2xvf_eth_dev_ops : &bnx2x_eth_dev_ops; rte_eth_copy_pci_info(eth_dev, pci_dev); sc->pcie_bus = pci_dev->addr.bus; sc->pcie_device = pci_dev->addr.devid; sc->devinfo.vendor_id = pci_dev->id.vendor_id; sc->devinfo.device_id = pci_dev->id.device_id; sc->devinfo.subvendor_id = pci_dev->id.subsystem_vendor_id; sc->devinfo.subdevice_id = pci_dev->id.subsystem_device_id; if (is_vf) sc->flags = BNX2X_IS_VF_FLAG; sc->pcie_func = pci_dev->addr.function; sc->bar[BAR0].base_addr = (void *)pci_dev->mem_resource[0].addr; if (is_vf) sc->bar[BAR1].base_addr = (void *) ((uintptr_t)pci_dev->mem_resource[0].addr + PXP_VF_ADDR_DB_START); else sc->bar[BAR1].base_addr = pci_dev->mem_resource[2].addr; assert(sc->bar[BAR0].base_addr); assert(sc->bar[BAR1].base_addr); bnx2x_load_firmware(sc); assert(sc->firmware); if (eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf & ETH_RSS_NONFRAG_IPV4_UDP) sc->udp_rss = 1; sc->rx_budget = BNX2X_RX_BUDGET; sc->hc_rx_ticks = BNX2X_RX_TICKS; sc->hc_tx_ticks = BNX2X_TX_TICKS; sc->interrupt_mode = INTR_MODE_SINGLE_MSIX; sc->rx_mode = BNX2X_RX_MODE_NORMAL; sc->pci_dev = pci_dev; ret = bnx2x_attach(sc); if (ret) { PMD_DRV_LOG(ERR, sc, "bnx2x_attach failed (%d)", ret); return ret; } eth_dev->data->mac_addrs = (struct ether_addr *)sc->link_params.mac_addr; PMD_DRV_LOG(INFO, sc, "pcie_bus=%d, pcie_device=%d", sc->pcie_bus, sc->pcie_device); PMD_DRV_LOG(INFO, sc, "bar0.addr=%p, bar1.addr=%p", sc->bar[BAR0].base_addr, sc->bar[BAR1].base_addr); PMD_DRV_LOG(INFO, sc, "port=%d, path=%d, vnic=%d, func=%d", PORT_ID(sc), PATH_ID(sc), VNIC_ID(sc), FUNC_ID(sc)); PMD_DRV_LOG(INFO, sc, "portID=%d vendorID=0x%x deviceID=0x%x", eth_dev->data->port_id, pci_dev->id.vendor_id, pci_dev->id.device_id); if (IS_VF(sc)) { rte_spinlock_init(&sc->vf2pf_lock); if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_mbx_msg), &sc->vf2pf_mbox_mapping, "vf2pf_mbox", RTE_CACHE_LINE_SIZE) != 0) return -ENOMEM; sc->vf2pf_mbox = (struct bnx2x_vf_mbx_msg *) sc->vf2pf_mbox_mapping.vaddr; if (bnx2x_dma_alloc(sc, sizeof(struct bnx2x_vf_bulletin), &sc->pf2vf_bulletin_mapping, "vf2pf_bull", RTE_CACHE_LINE_SIZE) != 0) return -ENOMEM; sc->pf2vf_bulletin = (struct bnx2x_vf_bulletin *) sc->pf2vf_bulletin_mapping.vaddr; ret = bnx2x_vf_get_resources(sc, sc->max_tx_queues, sc->max_rx_queues); if (ret) return ret; } return 0; } static int eth_bnx2x_dev_init(struct rte_eth_dev *eth_dev) { struct bnx2x_softc *sc = eth_dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); return bnx2x_common_dev_init(eth_dev, 0); } static int eth_bnx2xvf_dev_init(struct rte_eth_dev *eth_dev) { struct bnx2x_softc *sc = eth_dev->data->dev_private; PMD_INIT_FUNC_TRACE(sc); return bnx2x_common_dev_init(eth_dev, 1); } static struct eth_driver rte_bnx2x_pmd = { .pci_drv = { .id_table = pci_id_bnx2x_map, .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC, .probe = rte_eth_dev_pci_probe, .remove = rte_eth_dev_pci_remove, }, .eth_dev_init = eth_bnx2x_dev_init, .dev_private_size = sizeof(struct bnx2x_softc), }; /* * virtual function driver struct */ static struct eth_driver rte_bnx2xvf_pmd = { .pci_drv = { .id_table = pci_id_bnx2xvf_map, .drv_flags = RTE_PCI_DRV_NEED_MAPPING, .probe = rte_eth_dev_pci_probe, .remove = rte_eth_dev_pci_remove, }, .eth_dev_init = eth_bnx2xvf_dev_init, .dev_private_size = sizeof(struct bnx2x_softc), }; RTE_PMD_REGISTER_PCI(net_bnx2x, rte_bnx2x_pmd.pci_drv); RTE_PMD_REGISTER_PCI_TABLE(net_bnx2x, pci_id_bnx2x_map); RTE_PMD_REGISTER_PCI(net_bnx2xvf, rte_bnx2xvf_pmd.pci_drv); RTE_PMD_REGISTER_PCI_TABLE(net_bnx2xvf, pci_id_bnx2xvf_map);