2015-09-21 15:52:41 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 17:47:22 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
2017-04-11 04:36:05 +00:00
|
|
|
* Copyright (c) NetApp, Inc.
|
2015-09-21 15:52:41 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2016-04-29 18:04:33 +00:00
|
|
|
/** \file
|
2016-08-10 17:21:45 +00:00
|
|
|
* Encapsulated third-party dependencies
|
2016-04-29 18:04:33 +00:00
|
|
|
*/
|
|
|
|
|
2016-08-10 17:21:45 +00:00
|
|
|
#ifndef SPDK_ENV_H
|
|
|
|
#define SPDK_ENV_H
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2017-05-01 20:22:48 +00:00
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-27 17:04:08 +00:00
|
|
|
#define SPDK_ENV_SOCKET_ID_ANY (-1)
|
2017-10-10 16:30:57 +00:00
|
|
|
#define SPDK_ENV_LCORE_ID_ANY (UINT32_MAX)
|
2017-01-27 17:04:08 +00:00
|
|
|
|
2016-08-10 17:41:12 +00:00
|
|
|
struct spdk_pci_device;
|
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
/**
|
|
|
|
* \brief Environment initialization options
|
|
|
|
*/
|
|
|
|
struct spdk_env_opts {
|
2018-03-02 19:49:36 +00:00
|
|
|
const char *name;
|
|
|
|
const char *core_mask;
|
|
|
|
int shm_id;
|
|
|
|
int mem_channel;
|
|
|
|
int master_core;
|
2017-06-16 08:41:13 +00:00
|
|
|
int mem_size;
|
2017-06-14 07:31:55 +00:00
|
|
|
bool no_pci;
|
2018-02-23 08:19:09 +00:00
|
|
|
bool hugepage_single_segments;
|
2017-10-10 20:35:44 +00:00
|
|
|
|
|
|
|
/** Opaque context for use of the env implementation. */
|
|
|
|
void *env_context;
|
2017-01-12 18:25:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Initialize the default value of opts
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2017-01-12 18:25:17 +00:00
|
|
|
void spdk_env_opts_init(struct spdk_env_opts *opts);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Initialize the environment library. This must be called prior to using
|
|
|
|
* any other functions in this library.
|
2017-12-18 19:57:01 +00:00
|
|
|
* \return 0 on success, or a negated errno value on failure.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2017-12-18 19:57:01 +00:00
|
|
|
int spdk_env_init(const struct spdk_env_opts *opts);
|
2017-01-12 18:25:17 +00:00
|
|
|
|
2016-10-21 22:31:31 +00:00
|
|
|
/**
|
|
|
|
* Allocate a pinned, physically contiguous memory buffer with the
|
|
|
|
* given size and alignment.
|
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr);
|
2016-10-21 22:31:31 +00:00
|
|
|
|
2017-05-04 17:31:53 +00:00
|
|
|
/**
|
|
|
|
* Allocate a pinned, physically contiguous memory buffer with the
|
|
|
|
* given size, alignment and socket id.
|
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id);
|
2017-05-04 17:31:53 +00:00
|
|
|
|
2016-08-10 17:37:12 +00:00
|
|
|
/**
|
|
|
|
* Allocate a pinned, physically contiguous memory buffer with the
|
|
|
|
* given size and alignment. The buffer will be zeroed.
|
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_zmalloc(size_t size, size_t align, uint64_t *phys_addr);
|
2016-08-10 17:37:12 +00:00
|
|
|
|
2017-05-04 17:31:53 +00:00
|
|
|
/**
|
|
|
|
* Allocate a pinned, physically contiguous memory buffer with the
|
|
|
|
* given size, alignment and socket id. The buffer will be zeroed.
|
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id);
|
2017-05-04 17:31:53 +00:00
|
|
|
|
2016-11-07 08:19:31 +00:00
|
|
|
/**
|
|
|
|
* Resize the allocated and pinned memory buffer with the given
|
|
|
|
* new size and alignment. Existing contents are preserved.
|
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr);
|
2016-11-07 08:19:31 +00:00
|
|
|
|
2016-08-10 17:37:12 +00:00
|
|
|
/**
|
2017-05-25 18:21:30 +00:00
|
|
|
* Free a memory buffer previously allocated with spdk_dma_zmalloc.
|
2016-08-10 17:37:12 +00:00
|
|
|
* This call is never made from the performance path.
|
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void spdk_dma_free(void *buf);
|
2016-08-10 17:37:12 +00:00
|
|
|
|
2016-09-08 21:30:58 +00:00
|
|
|
/**
|
|
|
|
* Reserve a named, process shared memory zone with the given size,
|
|
|
|
* socket_id and flags.
|
|
|
|
* Return a pointer to the allocated memory address. If the allocation
|
|
|
|
* cannot be done, return NULL.
|
2017-01-27 17:04:08 +00:00
|
|
|
* Note: to pick any socket id, just set socket_id to SPDK_ENV_SOCKET_ID_ANY.
|
2016-09-08 21:30:58 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void *spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup the memory zone identified by the given name.
|
|
|
|
* Return a pointer to the reserved memory address. If the reservation
|
|
|
|
* cannot be found, return NULL.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void *spdk_memzone_lookup(const char *name);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the memory zone identified by the given name.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
int spdk_memzone_free(const char *name);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
2016-10-03 21:26:07 +00:00
|
|
|
/**
|
|
|
|
* Dump debug information about all memzones.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_memzone_dump(FILE *f);
|
2016-10-03 21:26:07 +00:00
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
struct spdk_mempool;
|
|
|
|
|
2017-08-16 17:05:24 +00:00
|
|
|
#define SPDK_MEMPOOL_DEFAULT_CACHE_SIZE SIZE_MAX
|
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
/**
|
2017-08-16 17:05:24 +00:00
|
|
|
* Create a thread-safe memory pool.
|
2017-01-25 20:35:40 +00:00
|
|
|
*
|
2017-08-16 17:05:24 +00:00
|
|
|
* \param cache_size How many elements may be cached in per-core caches. Use
|
|
|
|
* SPDK_MEMPOOL_DEFAULT_CACHE_SIZE for a reasonable default, or 0 for no
|
|
|
|
* per-core cache.
|
2017-01-25 20:35:40 +00:00
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY for any socket.
|
2016-09-28 14:58:51 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
struct spdk_mempool *spdk_mempool_create(const char *name, size_t count,
|
2017-01-25 20:35:40 +00:00
|
|
|
size_t ele_size, size_t cache_size, int socket_id);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2017-12-11 04:37:27 +00:00
|
|
|
/**
|
|
|
|
* An object callback function for mempool.
|
|
|
|
*
|
|
|
|
* Used by spdk_mempool_create_ctor
|
|
|
|
*/
|
|
|
|
typedef void (spdk_mempool_obj_cb_t)(struct spdk_mempool *mp,
|
|
|
|
void *opaque, void *obj, unsigned obj_idx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a thread-safe memory pool with user provided initialization function and argument.
|
|
|
|
*
|
|
|
|
* \param cache_size How many elements may be cached in per-core caches. Use
|
|
|
|
* SPDK_MEMPOOL_DEFAULT_CACHE_SIZE for a reasonable default, or 0 for no
|
|
|
|
* per-core cache.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY for any socket.
|
2017-12-20 10:58:33 +00:00
|
|
|
* \param obj_init User provided object calllback initialization function.
|
|
|
|
* \param obj_init_arg User provided callback initialization function argument.
|
2017-12-11 04:37:27 +00:00
|
|
|
*/
|
|
|
|
struct spdk_mempool *spdk_mempool_create_ctor(const char *name, size_t count,
|
|
|
|
size_t ele_size, size_t cache_size, int socket_id,
|
|
|
|
spdk_mempool_obj_cb_t *obj_init, void *obj_init_arg);
|
|
|
|
|
2017-12-08 09:01:12 +00:00
|
|
|
/**
|
|
|
|
* Get the name of a mempool
|
|
|
|
*/
|
|
|
|
char *spdk_mempool_get_name(struct spdk_mempool *mp);
|
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
/**
|
|
|
|
* Free a memory pool.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_mempool_free(struct spdk_mempool *mp);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an element from a memory pool. If no elements remain, return NULL.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void *spdk_mempool_get(struct spdk_mempool *mp);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Put an element back into the memory pool.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_mempool_put(struct spdk_mempool *mp, void *ele);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2016-11-02 20:31:33 +00:00
|
|
|
/**
|
|
|
|
* Put multiple elements back into the memory pool.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_mempool_put_bulk(struct spdk_mempool *mp, void *const *ele_arr, size_t count);
|
2016-11-02 20:31:33 +00:00
|
|
|
|
2017-04-11 04:36:05 +00:00
|
|
|
/**
|
|
|
|
* Return the number of entries in the mempool.
|
|
|
|
*/
|
|
|
|
size_t spdk_mempool_count(const struct spdk_mempool *pool);
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
/**
|
|
|
|
* \brief Return the number of dedicated CPU cores utilized by
|
2018-03-02 19:49:36 +00:00
|
|
|
* this env abstraction
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_core_count(void);
|
|
|
|
|
|
|
|
/**
|
2017-10-10 16:30:57 +00:00
|
|
|
* \brief Return the CPU core index of the current thread.
|
|
|
|
*
|
|
|
|
* This will only function when called from threads set up by
|
|
|
|
* this environment abstraction. For any other threads
|
|
|
|
* \c SPDK_ENV_LCORE_ID_ANY will be returned.
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_current_core(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Return the index of the first dedicated CPU core for
|
|
|
|
* this application.
|
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_first_core(void);
|
|
|
|
|
2017-12-22 00:21:35 +00:00
|
|
|
/**
|
|
|
|
* \brief Return the index of the last dedicated CPU core for
|
|
|
|
* this application.
|
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_last_core(void);
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
/**
|
|
|
|
* \brief Return the index of the next dedicated CPU core for
|
|
|
|
* this application.
|
|
|
|
* If there is no next core, return UINT32_MAX.
|
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_next_core(uint32_t prev_core);
|
|
|
|
|
2017-04-03 22:02:49 +00:00
|
|
|
#define SPDK_ENV_FOREACH_CORE(i) \
|
|
|
|
for (i = spdk_env_get_first_core(); \
|
|
|
|
i < UINT32_MAX; \
|
|
|
|
i = spdk_env_get_next_core(i))
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
/**
|
|
|
|
* \brief Return the socket ID for the given core.
|
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_socket_id(uint32_t core);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2017-06-02 18:40:23 +00:00
|
|
|
typedef int (*thread_start_fn)(void *);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Launch a thread pinned to the given core. Only a single pinned thread
|
|
|
|
* may be launched per core. Subsequent attempts to launch pinned threads on
|
|
|
|
* that core will fail.
|
|
|
|
*
|
|
|
|
* \param core The core to pin the thread to.
|
|
|
|
* \param fn Entry point on the new thread.
|
|
|
|
* \param arg Argument apssed to thread_start_fn
|
|
|
|
*/
|
|
|
|
int spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Wait for all threads to exit before returning.
|
|
|
|
*/
|
|
|
|
void spdk_env_thread_wait_all(void);
|
|
|
|
|
2016-09-08 21:30:58 +00:00
|
|
|
/**
|
|
|
|
* Return true if the calling process is primary process
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
bool spdk_process_is_primary(void);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
2016-08-10 20:12:33 +00:00
|
|
|
/**
|
|
|
|
* Get a monotonic timestamp counter.
|
|
|
|
*/
|
|
|
|
uint64_t spdk_get_ticks(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tick rate of spdk_get_ticks() per second.
|
|
|
|
*/
|
|
|
|
uint64_t spdk_get_ticks_hz(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delay the given number of microseconds
|
|
|
|
*/
|
|
|
|
void spdk_delay_us(unsigned int us);
|
|
|
|
|
2017-05-09 17:48:16 +00:00
|
|
|
struct spdk_ring;
|
|
|
|
|
|
|
|
enum spdk_ring_type {
|
2017-05-24 12:34:12 +00:00
|
|
|
SPDK_RING_TYPE_SP_SC, /* Single-producer, single-consumer */
|
2017-05-09 17:48:16 +00:00
|
|
|
SPDK_RING_TYPE_MP_SC, /* Multi-producer, single-consumer */
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a ring
|
|
|
|
*/
|
2017-05-24 12:46:55 +00:00
|
|
|
struct spdk_ring *spdk_ring_create(enum spdk_ring_type type, size_t count, int socket_id);
|
2017-05-09 17:48:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the ring
|
|
|
|
*/
|
|
|
|
void spdk_ring_free(struct spdk_ring *ring);
|
|
|
|
|
2017-10-18 06:07:26 +00:00
|
|
|
/**
|
|
|
|
* Get the number of objects in the ring.
|
|
|
|
*
|
|
|
|
* \param ring the ring
|
|
|
|
* \return number of objects in the ring
|
|
|
|
*/
|
|
|
|
size_t spdk_ring_count(struct spdk_ring *ring);
|
|
|
|
|
2017-05-09 17:48:16 +00:00
|
|
|
/**
|
|
|
|
* Queue the array of objects (with length count) on the ring.
|
|
|
|
*
|
|
|
|
* Return the number of objects enqueued.
|
|
|
|
*/
|
|
|
|
size_t spdk_ring_enqueue(struct spdk_ring *ring, void **objs, size_t count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dequeue count objects from the ring into the array objs.
|
|
|
|
*
|
|
|
|
* Return the number of objects dequeued.
|
|
|
|
*/
|
|
|
|
size_t spdk_ring_dequeue(struct spdk_ring *ring, void **objs, size_t count);
|
|
|
|
|
2016-02-08 21:17:04 +00:00
|
|
|
#define SPDK_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL)
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-02-08 21:17:04 +00:00
|
|
|
uint64_t spdk_vtophys(void *buf);
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-10-08 00:01:54 +00:00
|
|
|
struct spdk_pci_addr {
|
2017-06-21 22:05:47 +00:00
|
|
|
uint32_t domain;
|
2016-10-08 00:01:54 +00:00
|
|
|
uint8_t bus;
|
|
|
|
uint8_t dev;
|
|
|
|
uint8_t func;
|
|
|
|
};
|
|
|
|
|
2016-10-28 18:11:45 +00:00
|
|
|
struct spdk_pci_id {
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint16_t subvendor_id;
|
|
|
|
uint16_t subdevice_id;
|
|
|
|
};
|
|
|
|
|
2016-08-10 17:41:12 +00:00
|
|
|
typedef int (*spdk_pci_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
|
|
|
|
2016-12-05 17:20:20 +00:00
|
|
|
int spdk_pci_nvme_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
|
|
|
|
int spdk_pci_ioat_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
|
2017-09-21 15:11:06 +00:00
|
|
|
int spdk_pci_virtio_enumerate(spdk_pci_enum_cb enum_cb, void *enum_ctx);
|
2016-08-10 17:41:12 +00:00
|
|
|
|
2018-03-28 22:50:52 +00:00
|
|
|
struct spdk_pci_device *spdk_pci_get_device(struct spdk_pci_addr *pci_addr)
|
|
|
|
__attribute__((deprecated));
|
2016-12-09 19:30:57 +00:00
|
|
|
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar,
|
|
|
|
void **mapped_addr, uint64_t *phys_addr, uint64_t *size);
|
|
|
|
int spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar, void *addr);
|
|
|
|
|
2017-06-21 22:05:47 +00:00
|
|
|
uint32_t spdk_pci_device_get_domain(struct spdk_pci_device *dev);
|
2016-08-10 17:41:12 +00:00
|
|
|
uint8_t spdk_pci_device_get_bus(struct spdk_pci_device *dev);
|
|
|
|
uint8_t spdk_pci_device_get_dev(struct spdk_pci_device *dev);
|
|
|
|
uint8_t spdk_pci_device_get_func(struct spdk_pci_device *dev);
|
2016-10-28 18:00:18 +00:00
|
|
|
|
|
|
|
struct spdk_pci_addr spdk_pci_device_get_addr(struct spdk_pci_device *dev);
|
|
|
|
|
2016-08-10 17:41:12 +00:00
|
|
|
uint16_t spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev);
|
|
|
|
uint16_t spdk_pci_device_get_device_id(struct spdk_pci_device *dev);
|
|
|
|
uint16_t spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev);
|
|
|
|
uint16_t spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev);
|
2016-10-28 18:11:45 +00:00
|
|
|
|
|
|
|
struct spdk_pci_id spdk_pci_device_get_id(struct spdk_pci_device *dev);
|
|
|
|
|
2017-01-31 00:39:23 +00:00
|
|
|
/**
|
|
|
|
* Get the NUMA socket ID of a PCI device.
|
|
|
|
*
|
|
|
|
* \param dev PCI device to get the socket ID of.
|
|
|
|
*
|
|
|
|
* \return Socket ID (>= 0), or negative if unknown.
|
|
|
|
*/
|
|
|
|
int spdk_pci_device_get_socket_id(struct spdk_pci_device *dev);
|
|
|
|
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len);
|
2017-11-02 23:54:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Claim a PCI device for exclusive SPDK userspace access.
|
|
|
|
*
|
|
|
|
* Uses F_SETLK on a shared memory file with the PCI address embedded in its name.
|
|
|
|
* As long as this file remains open with the lock acquired, other processes will
|
|
|
|
* not be able to successfully call this function on the same PCI device.
|
|
|
|
*
|
|
|
|
* \param pci_addr PCI address of the device to claim
|
|
|
|
*
|
|
|
|
* \return -1 if the device has already been claimed, an fd otherwise. This fd
|
|
|
|
* should be closed when the application no longer needs access to the
|
|
|
|
* PCI device (including when it is hot removed).
|
|
|
|
*/
|
2016-10-31 23:01:52 +00:00
|
|
|
int spdk_pci_device_claim(const struct spdk_pci_addr *pci_addr);
|
2016-11-15 01:53:14 +00:00
|
|
|
void spdk_pci_device_detach(struct spdk_pci_device *device);
|
2016-12-05 17:20:20 +00:00
|
|
|
|
|
|
|
int spdk_pci_nvme_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
|
|
|
|
struct spdk_pci_addr *pci_address);
|
|
|
|
int spdk_pci_ioat_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
|
|
|
|
struct spdk_pci_addr *pci_address);
|
2017-09-21 15:11:06 +00:00
|
|
|
int spdk_pci_virtio_device_attach(spdk_pci_enum_cb enum_cb, void *enum_ctx,
|
|
|
|
struct spdk_pci_addr *pci_address);
|
2016-08-10 17:41:12 +00:00
|
|
|
|
2017-09-21 16:59:10 +00:00
|
|
|
int spdk_pci_device_cfg_read(struct spdk_pci_device *dev, void *value, uint32_t len,
|
|
|
|
uint32_t offset);
|
|
|
|
int spdk_pci_device_cfg_write(struct spdk_pci_device *dev, void *value, uint32_t len,
|
|
|
|
uint32_t offset);
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset);
|
|
|
|
int spdk_pci_device_cfg_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset);
|
|
|
|
int spdk_pci_device_cfg_read16(struct spdk_pci_device *dev, uint16_t *value, uint32_t offset);
|
|
|
|
int spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uint32_t offset);
|
|
|
|
int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset);
|
|
|
|
int spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset);
|
|
|
|
|
2016-10-28 18:00:18 +00:00
|
|
|
/**
|
|
|
|
* Compare two PCI addresses.
|
|
|
|
*
|
|
|
|
* \return 0 if a1 == a2, less than 0 if a1 < a2, greater than 0 if a1 > a2
|
|
|
|
*/
|
|
|
|
int spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_addr *a2);
|
2016-10-08 00:01:54 +00:00
|
|
|
|
2016-10-31 23:29:52 +00:00
|
|
|
/**
|
|
|
|
* Convert a string representation of a PCI address into a struct spdk_pci_addr.
|
|
|
|
*
|
|
|
|
* \param addr PCI adddress output on success
|
2017-04-17 02:01:55 +00:00
|
|
|
* \param bdf PCI address in domain:bus:device.function format or
|
|
|
|
* domain.bus.device.function format
|
2016-10-31 23:29:52 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, or a negated errno value on failure.
|
|
|
|
*/
|
|
|
|
int spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf);
|
|
|
|
|
2016-12-02 18:00:55 +00:00
|
|
|
/**
|
|
|
|
* Convert a struct spdk_pci_addr to a string.
|
|
|
|
*
|
|
|
|
* \param bdf String into which a string will be output in the format
|
|
|
|
* domain:bus:device.function. The string must be at least
|
|
|
|
* 14 characters in size.
|
|
|
|
* \param sz Size of bdf. Must be at least 14.
|
|
|
|
* \param addr PCI address input
|
|
|
|
*
|
|
|
|
* \return 0 on success, or a negated errno value on failure.
|
|
|
|
*/
|
|
|
|
int spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr);
|
|
|
|
|
2017-06-22 19:48:33 +00:00
|
|
|
/**
|
|
|
|
* Removes any CPU affinitization from the current thread.
|
|
|
|
*/
|
|
|
|
void spdk_unaffinitize_thread(void);
|
|
|
|
|
2016-11-07 17:08:11 +00:00
|
|
|
/**
|
|
|
|
* Call a function with CPU affinity unset.
|
|
|
|
*
|
|
|
|
* This can be used to run a function that creates other threads without inheriting the calling
|
|
|
|
* thread's CPU affinity.
|
|
|
|
*
|
|
|
|
* \param cb function to call
|
|
|
|
* \param arg parameter to cb function
|
|
|
|
*
|
|
|
|
* \return the return value of cb()
|
|
|
|
*/
|
|
|
|
void *spdk_call_unaffinitized(void *cb(void *arg), void *arg);
|
|
|
|
|
2017-03-02 21:50:04 +00:00
|
|
|
/**
|
|
|
|
* Page-granularity memory address translation table
|
|
|
|
*/
|
|
|
|
struct spdk_mem_map;
|
|
|
|
|
|
|
|
enum spdk_mem_map_notify_action {
|
|
|
|
SPDK_MEM_MAP_NOTIFY_REGISTER,
|
|
|
|
SPDK_MEM_MAP_NOTIFY_UNREGISTER,
|
|
|
|
};
|
|
|
|
|
2017-08-08 10:54:37 +00:00
|
|
|
typedef int (*spdk_mem_map_notify_cb)(void *cb_ctx, struct spdk_mem_map *map,
|
|
|
|
enum spdk_mem_map_notify_action action,
|
|
|
|
void *vaddr, size_t size);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate a virtual memory address translation map
|
|
|
|
*/
|
|
|
|
struct spdk_mem_map *spdk_mem_map_alloc(uint64_t default_translation,
|
|
|
|
spdk_mem_map_notify_cb notify_cb, void *cb_ctx);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free a memory map previously allocated by spdk_mem_map_alloc()
|
|
|
|
*/
|
|
|
|
void spdk_mem_map_free(struct spdk_mem_map **pmap);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register an address translation for a range of virtual memory.
|
|
|
|
*
|
|
|
|
* \param map Memory map
|
|
|
|
* \param vaddr Virtual address of the region to register - must be 2 MB aligned.
|
|
|
|
* \param size Size of the region - must be 2 MB in the current implementation.
|
|
|
|
* \param translation Translation to store in the map for this address range.
|
|
|
|
*
|
|
|
|
* \sa spdk_mem_map_clear_translation()
|
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t size,
|
|
|
|
uint64_t translation);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister an address translation.
|
|
|
|
*
|
|
|
|
* \sa spdk_mem_map_set_translation()
|
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t size);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the translation of a virtual address in a memory map.
|
|
|
|
*/
|
|
|
|
uint64_t spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the specified memory region for address translation.
|
|
|
|
* The memory region must map to pinned huge pages (2MB or greater).
|
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_register(void *vaddr, size_t len);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister the specified memory region from vtophys address translation.
|
|
|
|
* The caller must ensure all in-flight DMA operations to this memory region
|
|
|
|
* are completed or cancelled before calling this function.
|
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_unregister(void *vaddr, size_t len);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|