1*2da066efSJohn Baldwin /*- 2*2da066efSJohn Baldwin * SPDX-License-Identifier: BSD-2-Clause 3*2da066efSJohn Baldwin * 4*2da066efSJohn Baldwin * Copyright (c) 2022-2024 Chelsio Communications, Inc. 5*2da066efSJohn Baldwin * Written by: John Baldwin <jhb@FreeBSD.org> 6*2da066efSJohn Baldwin */ 7*2da066efSJohn Baldwin 8*2da066efSJohn Baldwin #ifndef __LIBNVMF_INTERNAL_H__ 9*2da066efSJohn Baldwin #define __LIBNVMF_INTERNAL_H__ 10*2da066efSJohn Baldwin 11*2da066efSJohn Baldwin #include <sys/queue.h> 12*2da066efSJohn Baldwin 13*2da066efSJohn Baldwin struct nvmf_transport_ops { 14*2da066efSJohn Baldwin /* Association management. */ 15*2da066efSJohn Baldwin struct nvmf_association *(*allocate_association)(bool controller, 16*2da066efSJohn Baldwin const struct nvmf_association_params *params); 17*2da066efSJohn Baldwin void (*update_association)(struct nvmf_association *na, 18*2da066efSJohn Baldwin const struct nvme_controller_data *cdata); 19*2da066efSJohn Baldwin void (*free_association)(struct nvmf_association *na); 20*2da066efSJohn Baldwin 21*2da066efSJohn Baldwin /* Queue pair management. */ 22*2da066efSJohn Baldwin struct nvmf_qpair *(*allocate_qpair)(struct nvmf_association *na, 23*2da066efSJohn Baldwin const struct nvmf_qpair_params *params); 24*2da066efSJohn Baldwin void (*free_qpair)(struct nvmf_qpair *qp); 25*2da066efSJohn Baldwin 26*2da066efSJohn Baldwin /* Create params for kernel handoff. */ 27*2da066efSJohn Baldwin int (*kernel_handoff_params)(struct nvmf_qpair *qp, 28*2da066efSJohn Baldwin struct nvmf_handoff_qpair_params *qparams); 29*2da066efSJohn Baldwin 30*2da066efSJohn Baldwin /* Capsule operations. */ 31*2da066efSJohn Baldwin struct nvmf_capsule *(*allocate_capsule)(struct nvmf_qpair *qp); 32*2da066efSJohn Baldwin void (*free_capsule)(struct nvmf_capsule *nc); 33*2da066efSJohn Baldwin int (*transmit_capsule)(struct nvmf_capsule *nc); 34*2da066efSJohn Baldwin int (*receive_capsule)(struct nvmf_qpair *qp, 35*2da066efSJohn Baldwin struct nvmf_capsule **ncp); 36*2da066efSJohn Baldwin uint8_t (*validate_command_capsule)(const struct nvmf_capsule *nc); 37*2da066efSJohn Baldwin 38*2da066efSJohn Baldwin /* Transferring controller data. */ 39*2da066efSJohn Baldwin size_t (*capsule_data_len)(const struct nvmf_capsule *nc); 40*2da066efSJohn Baldwin int (*receive_controller_data)(const struct nvmf_capsule *nc, 41*2da066efSJohn Baldwin uint32_t data_offset, void *buf, size_t len); 42*2da066efSJohn Baldwin int (*send_controller_data)(const struct nvmf_capsule *nc, 43*2da066efSJohn Baldwin const void *buf, size_t len); 44*2da066efSJohn Baldwin }; 45*2da066efSJohn Baldwin 46*2da066efSJohn Baldwin struct nvmf_association { 47*2da066efSJohn Baldwin struct nvmf_transport_ops *na_ops; 48*2da066efSJohn Baldwin enum nvmf_trtype na_trtype; 49*2da066efSJohn Baldwin bool na_controller; 50*2da066efSJohn Baldwin 51*2da066efSJohn Baldwin struct nvmf_association_params na_params; 52*2da066efSJohn Baldwin 53*2da066efSJohn Baldwin /* Each qpair holds a reference on an association. */ 54*2da066efSJohn Baldwin u_int na_refs; 55*2da066efSJohn Baldwin 56*2da066efSJohn Baldwin char *na_last_error; 57*2da066efSJohn Baldwin }; 58*2da066efSJohn Baldwin 59*2da066efSJohn Baldwin struct nvmf_qpair { 60*2da066efSJohn Baldwin struct nvmf_association *nq_association; 61*2da066efSJohn Baldwin bool nq_admin; 62*2da066efSJohn Baldwin 63*2da066efSJohn Baldwin uint16_t nq_cid; /* host only */ 64*2da066efSJohn Baldwin 65*2da066efSJohn Baldwin /* 66*2da066efSJohn Baldwin * Queue sizes. This assumes the same size for both the 67*2da066efSJohn Baldwin * completion and submission queues within a pair. 68*2da066efSJohn Baldwin */ 69*2da066efSJohn Baldwin u_int nq_qsize; 70*2da066efSJohn Baldwin 71*2da066efSJohn Baldwin /* Flow control management for submission queues. */ 72*2da066efSJohn Baldwin bool nq_flow_control; 73*2da066efSJohn Baldwin uint16_t nq_sqhd; 74*2da066efSJohn Baldwin uint16_t nq_sqtail; /* host only */ 75*2da066efSJohn Baldwin 76*2da066efSJohn Baldwin /* Value in response to/from CONNECT. */ 77*2da066efSJohn Baldwin uint16_t nq_cntlid; 78*2da066efSJohn Baldwin 79*2da066efSJohn Baldwin uint32_t nq_kato; /* valid on admin queue only */ 80*2da066efSJohn Baldwin 81*2da066efSJohn Baldwin TAILQ_HEAD(, nvmf_capsule) nq_rx_capsules; 82*2da066efSJohn Baldwin }; 83*2da066efSJohn Baldwin 84*2da066efSJohn Baldwin struct nvmf_capsule { 85*2da066efSJohn Baldwin struct nvmf_qpair *nc_qpair; 86*2da066efSJohn Baldwin 87*2da066efSJohn Baldwin /* Either a SQE or CQE. */ 88*2da066efSJohn Baldwin union { 89*2da066efSJohn Baldwin struct nvme_command nc_sqe; 90*2da066efSJohn Baldwin struct nvme_completion nc_cqe; 91*2da066efSJohn Baldwin }; 92*2da066efSJohn Baldwin int nc_qe_len; 93*2da066efSJohn Baldwin 94*2da066efSJohn Baldwin /* 95*2da066efSJohn Baldwin * Is SQHD in received capsule valid? False for locally- 96*2da066efSJohn Baldwin * synthesized responses. 97*2da066efSJohn Baldwin */ 98*2da066efSJohn Baldwin bool nc_sqhd_valid; 99*2da066efSJohn Baldwin 100*2da066efSJohn Baldwin /* Data buffer. */ 101*2da066efSJohn Baldwin bool nc_send_data; 102*2da066efSJohn Baldwin void *nc_data; 103*2da066efSJohn Baldwin size_t nc_data_len; 104*2da066efSJohn Baldwin 105*2da066efSJohn Baldwin TAILQ_ENTRY(nvmf_capsule) nc_link; 106*2da066efSJohn Baldwin }; 107*2da066efSJohn Baldwin 108*2da066efSJohn Baldwin extern struct nvmf_transport_ops tcp_ops; 109*2da066efSJohn Baldwin 110*2da066efSJohn Baldwin void na_clear_error(struct nvmf_association *na); 111*2da066efSJohn Baldwin void na_error(struct nvmf_association *na, const char *fmt, ...); 112*2da066efSJohn Baldwin 113*2da066efSJohn Baldwin int nvmf_kernel_handoff_params(struct nvmf_qpair *qp, 114*2da066efSJohn Baldwin struct nvmf_handoff_qpair_params *qparams); 115*2da066efSJohn Baldwin 116*2da066efSJohn Baldwin #endif /* !__LIBNVMF_INTERNAL_H__ */ 117