xref: /freebsd/sys/dev/nvmf/controller/nvmft_subr.h (revision abd87254)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2023-2024 Chelsio Communications, Inc.
5  * Written by: John Baldwin <jhb@FreeBSD.org>
6  */
7 
8 #ifndef __NVMFT_SUBR_H__
9 #define	__NVMFT_SUBR_H__
10 
11 /*
12  * Lower-level controller-specific routines shared between the kernel
13  * and userland.
14  */
15 
16 /* Validate a NVMe Qualified Name. */
17 bool	nvmf_nqn_valid(const char *nqn);
18 
19 /* Compute the initial state of CAP for a controller. */
20 uint64_t _nvmf_controller_cap(uint32_t max_io_qsize, uint8_t enable_timeout);
21 
22 /*
23  * Validate if a new value for CC is legal given the existing values of
24  * CAP and CC.
25  */
26 bool	_nvmf_validate_cc(uint32_t max_io_qsize, uint64_t cap, uint32_t old_cc,
27     uint32_t new_cc);
28 
29 /* Generate a serial number string from a host ID. */
30 void	nvmf_controller_serial(char *buf, size_t len, u_long hostid);
31 
32 /*
33  * Copy an ASCII string into the destination buffer but pad the end of
34  * the buffer with spaces and no terminating nul.
35  */
36 void	nvmf_strpad(char *dst, const char *src, size_t len);
37 
38 /*
39  * Populate an Identify Controller data structure for an I/O
40  * controller.
41  */
42 void	_nvmf_init_io_controller_data(uint16_t cntlid, uint32_t max_io_qsize,
43     const char *serial, const char *model, const char *firmware_version,
44     const char *subnqn, int nn, uint32_t ioccsz, uint32_t iorcsz,
45     struct nvme_controller_data *cdata);
46 
47 #endif	/* !__NVMFT_SUBR_H__ */
48