* @internal * Allocates a new ethdev slot for an Ethernet device and returns the pointer * to that slot for the driver to use. * * @param dev * Pointer to the PCI device * * @param private_data_size * Size of private data structure * * @return * A pointer to a rte_eth_dev or NULL if allocation failed. */
| 77 | * A pointer to a rte_eth_dev or NULL if allocation failed. |
| 78 | */ |
| 79 | static inline struct rte_eth_dev * |
| 80 | rte_eth_dev_pci_allocate(struct rte_pci_device *dev, size_t private_data_size) |
| 81 | { |
| 82 | struct rte_eth_dev *eth_dev; |
| 83 | const char *name; |
| 84 | |
| 85 | if (!dev) |
| 86 | return NULL; |
| 87 | |
| 88 | name = dev->device.name; |
| 89 | |
| 90 | if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
| 91 | eth_dev = rte_eth_dev_allocate(name); |
| 92 | if (!eth_dev) |
| 93 | return NULL; |
| 94 | |
| 95 | if (private_data_size) { |
| 96 | /* Try and alloc the private-data structure on socket local to the device */ |
| 97 | eth_dev->data->dev_private = rte_zmalloc_socket(name, |
| 98 | private_data_size, RTE_CACHE_LINE_SIZE, |
| 99 | dev->device.numa_node); |
| 100 | |
| 101 | /* if cannot allocate memory on the socket local to the device |
| 102 | * use rte_malloc to allocate memory on some other socket, if available. |
| 103 | */ |
| 104 | if (eth_dev->data->dev_private == NULL) { |
| 105 | eth_dev->data->dev_private = rte_zmalloc(name, |
| 106 | private_data_size, RTE_CACHE_LINE_SIZE); |
| 107 | |
| 108 | if (eth_dev->data->dev_private == NULL) { |
| 109 | rte_eth_dev_release_port(eth_dev); |
| 110 | return NULL; |
| 111 | } |
| 112 | /* got memory, but not local, so issue warning */ |
| 113 | RTE_ETHDEV_LOG(WARNING, |
| 114 | "Private data for ethdev '%s' not allocated on local NUMA node %d\n", |
| 115 | dev->device.name, dev->device.numa_node); |
| 116 | } |
| 117 | } |
| 118 | } else { |
| 119 | eth_dev = rte_eth_dev_attach_secondary(name); |
| 120 | if (!eth_dev) |
| 121 | return NULL; |
| 122 | } |
| 123 | |
| 124 | eth_dev->device = &dev->device; |
| 125 | rte_eth_copy_pci_info(eth_dev, dev); |
| 126 | return eth_dev; |
| 127 | } |
| 128 | |
| 129 | typedef int (*eth_dev_pci_callback_t)(struct rte_eth_dev *eth_dev); |
| 130 |
no test coverage detected