| 72 | } |
| 73 | |
| 74 | struct rte_eth_dev * |
| 75 | rte_eth_dev_allocate(const char *name) |
| 76 | { |
| 77 | uint16_t port_id; |
| 78 | struct rte_eth_dev *eth_dev = NULL; |
| 79 | size_t name_len; |
| 80 | |
| 81 | name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN); |
| 82 | if (name_len == 0) { |
| 83 | RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); |
| 84 | return NULL; |
| 85 | } |
| 86 | |
| 87 | if (name_len >= RTE_ETH_NAME_MAX_LEN) { |
| 88 | RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); |
| 89 | return NULL; |
| 90 | } |
| 91 | |
| 92 | /* Synchronize port creation between primary and secondary processes. */ |
| 93 | rte_spinlock_lock(rte_mcfg_ethdev_get_lock()); |
| 94 | |
| 95 | if (eth_dev_shared_data_prepare() == NULL) |
| 96 | goto unlock; |
| 97 | |
| 98 | if (eth_dev_allocated(name) != NULL) { |
| 99 | RTE_ETHDEV_LOG(ERR, |
| 100 | "Ethernet device with name %s already allocated\n", |
| 101 | name); |
| 102 | goto unlock; |
| 103 | } |
| 104 | |
| 105 | port_id = eth_dev_find_free_port(); |
| 106 | if (port_id == RTE_MAX_ETHPORTS) { |
| 107 | RTE_ETHDEV_LOG(ERR, |
| 108 | "Reached maximum number of Ethernet ports\n"); |
| 109 | goto unlock; |
| 110 | } |
| 111 | |
| 112 | eth_dev = eth_dev_get(port_id); |
| 113 | strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name)); |
| 114 | eth_dev->data->port_id = port_id; |
| 115 | eth_dev->data->backer_port_id = RTE_MAX_ETHPORTS; |
| 116 | eth_dev->data->mtu = RTE_ETHER_MTU; |
| 117 | pthread_mutex_init(ð_dev->data->flow_ops_mutex, NULL); |
| 118 | RTE_ASSERT(rte_eal_process_type() == RTE_PROC_PRIMARY); |
| 119 | eth_dev_shared_data->allocated_ports++; |
| 120 | |
| 121 | unlock: |
| 122 | rte_spinlock_unlock(rte_mcfg_ethdev_get_lock()); |
| 123 | |
| 124 | return eth_dev; |
| 125 | } |
| 126 | |
| 127 | struct rte_eth_dev * |
| 128 | rte_eth_dev_allocated(const char *name) |