external_code/nvme: introduced nvme_ctrlr_get_data()
This function allows the user to retrieve the controller's identify data. Currently, that buffer is zeroed, but it'll be populated by the identify command. Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: I91a99feef25ecf94c43cf144c12ac3c541c76cd9 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6674 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Mellanox Build Bot Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
5555513653
commit
48a89ec7d3
@ -103,6 +103,8 @@ struct nvme_ctrlr {
|
||||
uint32_t page_size;
|
||||
/* Admin queue pair */
|
||||
struct nvme_qpair *admin_qpair;
|
||||
/* Controller's identify data */
|
||||
struct spdk_nvme_ctrlr_data *cdata;
|
||||
/* State of the controller */
|
||||
enum nvme_ctrlr_state state;
|
||||
TAILQ_ENTRY(nvme_ctrlr) tailq;
|
||||
@ -332,11 +334,21 @@ pcie_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
|
||||
ctrlr->page_size = 1 << (12 + cap.bits.mpsmin);
|
||||
ctrlr->doorbell_stride_u32 = 1 << cap.bits.dstrd;
|
||||
|
||||
ctrlr->cdata = spdk_zmalloc(sizeof(*ctrlr->cdata), ctrlr->page_size, NULL,
|
||||
SPDK_ENV_SOCKET_ID_ANY, SPDK_MALLOC_DMA);
|
||||
if (!ctrlr->cdata) {
|
||||
SPDK_ERRLOG("Failed to allocate identify data for NVMe controller: %s\n", addr);
|
||||
spdk_pci_device_unclaim(pci_dev);
|
||||
free(ctrlr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Initialize admin queue pair with minimum number of entries (2) */
|
||||
ctrlr->admin_qpair = init_qpair(ctrlr, 0, SPDK_NVME_ADMIN_QUEUE_MIN_ENTRIES);
|
||||
if (!ctrlr->admin_qpair) {
|
||||
SPDK_ERRLOG("Failed to initialize admin queue pair for controller: %s\n", addr);
|
||||
spdk_pci_device_unclaim(pci_dev);
|
||||
spdk_free(ctrlr->cdata);
|
||||
free(ctrlr);
|
||||
return -1;
|
||||
}
|
||||
@ -418,6 +430,7 @@ free_ctrlr(struct nvme_ctrlr *ctrlr)
|
||||
spdk_pci_device_unclaim(ctrlr->pci_device);
|
||||
spdk_pci_device_detach(ctrlr->pci_device);
|
||||
free_qpair(ctrlr->admin_qpair);
|
||||
spdk_free(ctrlr->cdata);
|
||||
free(ctrlr);
|
||||
}
|
||||
|
||||
@ -497,4 +510,10 @@ nvme_detach(struct nvme_ctrlr *ctrlr)
|
||||
free_ctrlr(ctrlr);
|
||||
}
|
||||
|
||||
const struct spdk_nvme_ctrlr_data *
|
||||
nvme_ctrlr_get_data(struct nvme_ctrlr *ctrlr)
|
||||
{
|
||||
return ctrlr->cdata;
|
||||
}
|
||||
|
||||
SPDK_LOG_REGISTER_COMPONENT(nvme_external)
|
||||
|
@ -35,6 +35,7 @@
|
||||
#define EXTERNAL_NVME_H
|
||||
|
||||
#include "spdk/env.h"
|
||||
#include "spdk/nvme_spec.h"
|
||||
|
||||
struct nvme_ctrlr;
|
||||
|
||||
@ -86,4 +87,16 @@ struct nvme_ctrlr *nvme_connect(struct spdk_pci_addr *addr);
|
||||
*/
|
||||
void nvme_detach(struct nvme_ctrlr *ctrlr);
|
||||
|
||||
/**
|
||||
* Get the identify controller data as defined by the NVMe specification.
|
||||
*
|
||||
* This function is thread safe and can be called at any point while the controller
|
||||
* is attached to the SPDK NVMe driver.
|
||||
*
|
||||
* \param ctrlr Opaque handle to NVMe controller.
|
||||
*
|
||||
* \return pointer to the identify controller data.
|
||||
*/
|
||||
const struct spdk_nvme_ctrlr_data *nvme_ctrlr_get_data(struct nvme_ctrlr *ctrlr);
|
||||
|
||||
#endif /* EXTERNAL_NVME_H */
|
||||
|
Loading…
Reference in New Issue
Block a user