2015-09-21 15:52:41 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 17:47:22 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NVME_IMPL_H__
|
|
|
|
#define __NVME_IMPL_H__
|
|
|
|
|
2015-09-28 17:08:37 +00:00
|
|
|
#include <assert.h>
|
2015-09-21 15:52:41 +00:00
|
|
|
#include <stdio.h>
|
2015-09-24 17:04:33 +00:00
|
|
|
#include <stdlib.h>
|
2015-09-21 15:52:41 +00:00
|
|
|
#include <stdint.h>
|
2016-08-05 02:59:38 +00:00
|
|
|
#include <stdbool.h>
|
2015-09-21 15:52:41 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2016-03-01 23:51:02 +00:00
|
|
|
#include "spdk/nvme_spec.h"
|
|
|
|
|
2016-02-03 21:36:26 +00:00
|
|
|
struct spdk_pci_device;
|
|
|
|
|
2015-09-24 17:04:33 +00:00
|
|
|
static inline void *
|
2016-08-10 17:37:12 +00:00
|
|
|
nvme_malloc(size_t size, unsigned align, uint64_t *phys_addr)
|
2015-09-24 17:04:33 +00:00
|
|
|
{
|
2016-06-27 16:35:05 +00:00
|
|
|
void *buf = NULL;
|
|
|
|
if (posix_memalign(&buf, align, size)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-24 17:04:33 +00:00
|
|
|
*phys_addr = (uint64_t)buf;
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#define nvme_free(buf) free(buf)
|
|
|
|
#define nvme_get_num_ioq() 8
|
|
|
|
#define nvme_get_ioq_idx() 0
|
2015-09-28 17:08:37 +00:00
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
uint64_t nvme_vtophys(void *buf);
|
2015-11-02 19:58:19 +00:00
|
|
|
#define NVME_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL)
|
|
|
|
|
2016-02-22 23:01:36 +00:00
|
|
|
extern uint64_t g_ut_tsc;
|
|
|
|
#define nvme_get_tsc() (g_ut_tsc)
|
|
|
|
#define nvme_get_tsc_hz() (1000000)
|
|
|
|
|
2016-08-05 02:59:38 +00:00
|
|
|
static inline void *
|
|
|
|
nvme_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags)
|
|
|
|
{
|
|
|
|
return malloc(len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
nvme_memzone_lookup(const char *name)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
nvme_memzone_free(const char *name)
|
|
|
|
{
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool
|
|
|
|
nvme_process_is_primary(void)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-09 08:17:09 +00:00
|
|
|
#define NVME_SOCKET_ID_ANY -1
|
|
|
|
|
|
|
|
typedef unsigned nvme_mempool_t;
|
|
|
|
|
|
|
|
static inline nvme_mempool_t *
|
2016-09-28 14:58:51 +00:00
|
|
|
nvme_mempool_create(const char *name, size_t n,
|
|
|
|
size_t elt_size, size_t cache_size)
|
2016-08-09 08:17:09 +00:00
|
|
|
{
|
|
|
|
static int mp;
|
|
|
|
|
|
|
|
return ∓
|
|
|
|
}
|
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
static inline void *
|
|
|
|
nvme_mempool_get(nvme_mempool_t *mp)
|
2016-08-09 08:17:09 +00:00
|
|
|
{
|
2016-09-28 14:58:51 +00:00
|
|
|
void *buf;
|
|
|
|
|
|
|
|
if (posix_memalign(&buf, 64, 0x1000)) {
|
|
|
|
buf = NULL;
|
2016-09-27 22:34:34 +00:00
|
|
|
}
|
2016-09-28 14:58:51 +00:00
|
|
|
|
|
|
|
return buf;
|
2016-08-09 08:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
nvme_mempool_put(nvme_mempool_t *mp, void *buf)
|
|
|
|
{
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#endif /* __NVME_IMPL_H__ */
|