| 322 | } |
| 323 | |
| 324 | void * |
| 325 | eth_dev_shared_data_prepare(void) |
| 326 | { |
| 327 | const struct rte_memzone *mz; |
| 328 | |
| 329 | if (rte_eal_process_type() == RTE_PROC_PRIMARY) { |
| 330 | const unsigned int flags = 0; |
| 331 | |
| 332 | if (eth_dev_shared_mz != NULL) |
| 333 | goto out; |
| 334 | |
| 335 | /* Allocate port data and ownership shared memory. */ |
| 336 | mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA, |
| 337 | sizeof(*eth_dev_shared_data), |
| 338 | rte_socket_id(), flags); |
| 339 | if (mz == NULL) { |
| 340 | RTE_ETHDEV_LOG(ERR, "Cannot allocate ethdev shared data\n"); |
| 341 | goto out; |
| 342 | } |
| 343 | |
| 344 | eth_dev_shared_mz = mz; |
| 345 | eth_dev_shared_data = mz->addr; |
| 346 | eth_dev_shared_data->allocated_owners = 0; |
| 347 | eth_dev_shared_data->next_owner_id = |
| 348 | RTE_ETH_DEV_NO_OWNER + 1; |
| 349 | eth_dev_shared_data->allocated_ports = 0; |
| 350 | memset(eth_dev_shared_data->data, 0, |
| 351 | sizeof(eth_dev_shared_data->data)); |
| 352 | } else { |
| 353 | mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA); |
| 354 | if (mz == NULL) { |
| 355 | /* Clean remaining any traces of a previous shared mem */ |
| 356 | eth_dev_shared_mz = NULL; |
| 357 | eth_dev_shared_data = NULL; |
| 358 | RTE_ETHDEV_LOG(ERR, "Cannot lookup ethdev shared data\n"); |
| 359 | goto out; |
| 360 | } |
| 361 | if (mz == eth_dev_shared_mz && mz->addr == eth_dev_shared_data) |
| 362 | goto out; |
| 363 | |
| 364 | /* Shared mem changed in primary process, refresh pointers */ |
| 365 | eth_dev_shared_mz = mz; |
| 366 | eth_dev_shared_data = mz->addr; |
| 367 | } |
| 368 | out: |
| 369 | return eth_dev_shared_data; |
| 370 | } |
| 371 | |
| 372 | void |
| 373 | eth_dev_shared_data_release(void) |
no test coverage detected