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>
|
|
|
|
#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 *
|
|
|
|
nvme_malloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
|
|
|
{
|
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 OUTBUF_SIZE 1024
|
|
|
|
extern char outbuf[OUTBUF_SIZE];
|
|
|
|
#define nvme_printf(ctrlr, fmt, args...) snprintf(outbuf, OUTBUF_SIZE, fmt, ##args)
|
|
|
|
#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)
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#define nvme_alloc_request(bufp) \
|
|
|
|
do \
|
|
|
|
{ \
|
2016-06-27 16:35:05 +00:00
|
|
|
if (posix_memalign((void **)(bufp), 64, sizeof(struct nvme_request))) { \
|
|
|
|
*(bufp) = NULL; \
|
|
|
|
} \
|
2015-09-21 15:52:41 +00:00
|
|
|
} \
|
2015-09-28 17:08:37 +00:00
|
|
|
while (0)
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2015-10-20 00:03:04 +00:00
|
|
|
#define nvme_dealloc_request(buf) free(buf)
|
2016-01-29 20:15:29 +00:00
|
|
|
|
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-01-29 20:15:29 +00:00
|
|
|
static inline int
|
2016-02-03 21:36:26 +00:00
|
|
|
nvme_pci_enumerate(int (*enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev), void *enum_ctx)
|
2016-01-29 20:15:29 +00:00
|
|
|
{
|
|
|
|
/* TODO: enumeration is not needed in any unit tests yet, so it's not implemented */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-09-22 19:37:21 +00:00
|
|
|
#define nvme_pcicfg_read32(handle, var, offset) do { *(var) = 0xFFFFFFFFu; } while (0)
|
|
|
|
#define nvme_pcicfg_write32(handle, var, offset) do { (void)(var); } while (0)
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-03-01 23:51:02 +00:00
|
|
|
extern struct spdk_nvme_registers g_ut_nvme_regs;
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
static inline
|
|
|
|
int nvme_pcicfg_map_bar(void *pci_handle, int bar, int read_only, void **addr)
|
|
|
|
{
|
2016-03-01 23:51:02 +00:00
|
|
|
*addr = &g_ut_nvme_regs;
|
2015-09-21 15:52:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-05 01:41:16 +00:00
|
|
|
static inline int
|
|
|
|
nvme_pcicfg_map_bar_write_combine(void *devhandle, uint32_t bar, void **addr)
|
|
|
|
{
|
|
|
|
*addr = &g_ut_nvme_regs;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
static inline int
|
|
|
|
nvme_pcicfg_unmap_bar(void *devhandle, uint32_t bar, void *addr)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-05 01:41:16 +00:00
|
|
|
static inline void
|
|
|
|
nvme_pcicfg_get_bar_addr_len(void *devhandle, uint32_t bar, uint64_t *addr, uint64_t *size)
|
|
|
|
{
|
|
|
|
*addr = 0;
|
|
|
|
*size = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#endif /* __NVME_IMPL_H__ */
|