Home | History | Annotate | Line # | Download | only in ic
nvmeio.h revision 1.1.20.1
      1  1.1.20.1  pgoyette /*	$NetBSD: nvmeio.h,v 1.1.20.1 2018/04/22 07:20:20 pgoyette Exp $	*/
      2       1.1    nonaka 
      3       1.1    nonaka /*-
      4       1.1    nonaka  * Copyright (C) 2012-2013 Intel Corporation
      5       1.1    nonaka  * All rights reserved.
      6       1.1    nonaka  *
      7       1.1    nonaka  * Redistribution and use in source and binary forms, with or without
      8       1.1    nonaka  * modification, are permitted provided that the following conditions
      9       1.1    nonaka  * are met:
     10       1.1    nonaka  * 1. Redistributions of source code must retain the above copyright
     11       1.1    nonaka  *    notice, this list of conditions and the following disclaimer.
     12       1.1    nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1    nonaka  *    notice, this list of conditions and the following disclaimer in the
     14       1.1    nonaka  *    documentation and/or other materials provided with the distribution.
     15       1.1    nonaka  *
     16       1.1    nonaka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17       1.1    nonaka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18       1.1    nonaka  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19       1.1    nonaka  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20       1.1    nonaka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21       1.1    nonaka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22       1.1    nonaka  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23       1.1    nonaka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24       1.1    nonaka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25       1.1    nonaka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26       1.1    nonaka  * SUCH DAMAGE.
     27       1.1    nonaka  *
     28  1.1.20.1  pgoyette  * $FreeBSD: head/sys/dev/nvme/nvme.h 329824 2018-02-22 13:32:31Z wma $
     29       1.1    nonaka  */
     30       1.1    nonaka 
     31       1.1    nonaka #ifndef __NVMEIO_H__
     32       1.1    nonaka #define __NVMEIO_H__
     33       1.1    nonaka 
     34  1.1.20.1  pgoyette #include <sys/endian.h>
     35       1.1    nonaka #include <sys/ioccom.h>
     36       1.1    nonaka #include <dev/ic/nvmereg.h>
     37       1.1    nonaka 
     38       1.1    nonaka #define	NVME_PASSTHROUGH_CMD		_IOWR('n', 0, struct nvme_pt_command)
     39       1.1    nonaka 
     40       1.1    nonaka #define	nvme_completion_is_error(cpl)					\
     41       1.1    nonaka 	((NVME_CQE_SC((cpl)->flags) != NVME_CQE_SC_SUCCESS)   		\
     42       1.1    nonaka 	    || (NVME_CQE_SCT((cpl)->flags) != NVME_CQE_SCT_GENERIC))
     43       1.1    nonaka 
     44       1.1    nonaka struct nvme_pt_command {
     45       1.1    nonaka 
     46       1.1    nonaka 	/*
     47       1.1    nonaka 	 * cmd is used to specify a passthrough command to a controller or
     48       1.1    nonaka 	 *  namespace.
     49       1.1    nonaka 	 *
     50       1.1    nonaka 	 * The following fields from cmd may be specified by the caller:
     51       1.1    nonaka 	 *	* opcode
     52       1.1    nonaka 	 *	* nsid (namespace id) - for admin commands only
     53       1.1    nonaka 	 *	* cdw10-cdw15
     54       1.1    nonaka 	 *
     55       1.1    nonaka 	 * Remaining fields must be set to 0 by the caller.
     56       1.1    nonaka 	 */
     57       1.1    nonaka 	struct nvme_sqe		cmd;
     58       1.1    nonaka 
     59       1.1    nonaka 	/*
     60       1.1    nonaka 	 * cpl returns completion status for the passthrough command
     61       1.1    nonaka 	 *  specified by cmd.
     62       1.1    nonaka 	 *
     63       1.1    nonaka 	 * The following fields will be filled out by the driver, for
     64       1.1    nonaka 	 *  consumption by the caller:
     65       1.1    nonaka 	 *	* cdw0
     66       1.1    nonaka 	 *	* flags (except for phase)
     67       1.1    nonaka 	 *
     68       1.1    nonaka 	 * Remaining fields will be set to 0 by the driver.
     69       1.1    nonaka 	 */
     70       1.1    nonaka 	struct nvme_cqe		cpl;
     71       1.1    nonaka 
     72       1.1    nonaka 	/* buf is the data buffer associated with this passthrough command. */
     73       1.1    nonaka 	void			*buf;
     74       1.1    nonaka 
     75       1.1    nonaka 	/*
     76       1.1    nonaka 	 * len is the length of the data buffer associated with this
     77       1.1    nonaka 	 *  passthrough command.
     78       1.1    nonaka 	 */
     79       1.1    nonaka 	uint32_t		len;
     80       1.1    nonaka 
     81       1.1    nonaka 	/*
     82       1.1    nonaka 	 * is_read = 1 if the passthrough command will read data into the
     83       1.1    nonaka 	 *  supplied buffer from the controller.
     84       1.1    nonaka 	 *
     85       1.1    nonaka 	 * is_read = 0 if the passthrough command will write data from the
     86       1.1    nonaka 	 *  supplied buffer to the controller.
     87       1.1    nonaka 	 */
     88       1.1    nonaka 	uint32_t		is_read;
     89       1.1    nonaka 
     90       1.1    nonaka 	/*
     91       1.1    nonaka 	 * timeout (unit: ms)
     92       1.1    nonaka 	 *
     93       1.1    nonaka 	 * 0: use default timeout value
     94       1.1    nonaka 	 */
     95       1.1    nonaka 	uint32_t		timeout;
     96       1.1    nonaka };
     97       1.1    nonaka 
     98  1.1.20.1  pgoyette /* Endianess conversion functions for NVMe structs */
     99  1.1.20.1  pgoyette static __inline void
    100  1.1.20.1  pgoyette nvme_le128toh(uint64_t v[2])
    101  1.1.20.1  pgoyette {
    102  1.1.20.1  pgoyette #if _BYTE_ORDER != _LITTLE_ENDIAN
    103  1.1.20.1  pgoyette 	uint64_t t;
    104  1.1.20.1  pgoyette 
    105  1.1.20.1  pgoyette 	t = le64toh(v[0]);
    106  1.1.20.1  pgoyette 	v[0] = le64toh(v[1]);
    107  1.1.20.1  pgoyette 	v[1] = t;
    108  1.1.20.1  pgoyette #endif
    109  1.1.20.1  pgoyette }
    110  1.1.20.1  pgoyette 
    111  1.1.20.1  pgoyette static __inline void
    112  1.1.20.1  pgoyette nvme_namespace_format_swapbytes(struct nvm_namespace_format *format)
    113  1.1.20.1  pgoyette {
    114  1.1.20.1  pgoyette 
    115  1.1.20.1  pgoyette #if _BYTE_ORDER != _LITTLE_ENDIAN
    116  1.1.20.1  pgoyette 	format->ms = le16toh(format->ms);
    117  1.1.20.1  pgoyette #endif
    118  1.1.20.1  pgoyette }
    119  1.1.20.1  pgoyette 
    120  1.1.20.1  pgoyette static __inline void
    121  1.1.20.1  pgoyette nvme_identify_namespace_swapbytes(struct nvm_identify_namespace *identify)
    122  1.1.20.1  pgoyette {
    123  1.1.20.1  pgoyette #if _BYTE_ORDER != _LITTLE_ENDIAN
    124  1.1.20.1  pgoyette 	u_int i;
    125  1.1.20.1  pgoyette 
    126  1.1.20.1  pgoyette 	identify->nsze = le64toh(identify->nsze);
    127  1.1.20.1  pgoyette 	identify->ncap = le64toh(identify->ncap);
    128  1.1.20.1  pgoyette 	identify->nuse = le64toh(identify->nuse);
    129  1.1.20.1  pgoyette 	identify->nawun = le16toh(identify->nawun);
    130  1.1.20.1  pgoyette 	identify->nawupf = le16toh(identify->nawupf);
    131  1.1.20.1  pgoyette 	identify->nacwu = le16toh(identify->nacwu);
    132  1.1.20.1  pgoyette 	identify->nabsn = le16toh(identify->nabsn);
    133  1.1.20.1  pgoyette 	identify->nabo = le16toh(identify->nabo);
    134  1.1.20.1  pgoyette 	identify->nabspf = le16toh(identify->nabspf);
    135  1.1.20.1  pgoyette 	identify->noiob = le16toh(identify->noiob);
    136  1.1.20.1  pgoyette 	for (i = 0; i < __arraycount(identify->lbaf); i++)
    137  1.1.20.1  pgoyette 		nvme_namespace_format_swapbytes(&identify->lbaf[i]);
    138  1.1.20.1  pgoyette #endif
    139  1.1.20.1  pgoyette }
    140  1.1.20.1  pgoyette 
    141  1.1.20.1  pgoyette static __inline void
    142  1.1.20.1  pgoyette nvme_identify_psd_swapbytes(struct nvm_identify_psd *psd)
    143  1.1.20.1  pgoyette {
    144  1.1.20.1  pgoyette 
    145  1.1.20.1  pgoyette #if _BYTE_ORDER != _LITTLE_ENDIAN
    146  1.1.20.1  pgoyette 	psd->mp = le16toh(psd->mp);
    147  1.1.20.1  pgoyette 	psd->enlat = le32toh(psd->enlat);
    148  1.1.20.1  pgoyette 	psd->exlat = le32toh(psd->exlat);
    149  1.1.20.1  pgoyette 	psd->idlp = le16toh(psd->idlp);
    150  1.1.20.1  pgoyette 	psd->actp = le16toh(psd->actp);
    151  1.1.20.1  pgoyette 	psd->ap = le16toh(psd->ap);
    152  1.1.20.1  pgoyette #endif
    153  1.1.20.1  pgoyette }
    154  1.1.20.1  pgoyette 
    155  1.1.20.1  pgoyette static __inline void
    156  1.1.20.1  pgoyette nvme_identify_controller_swapbytes(struct nvm_identify_controller *identify)
    157  1.1.20.1  pgoyette {
    158  1.1.20.1  pgoyette #if _BYTE_ORDER != _LITTLE_ENDIAN
    159  1.1.20.1  pgoyette 	u_int i;
    160  1.1.20.1  pgoyette 
    161  1.1.20.1  pgoyette 	identify->vid = le16toh(identify->vid);
    162  1.1.20.1  pgoyette 	identify->ssvid = le16toh(identify->ssvid);
    163  1.1.20.1  pgoyette 	identify->cntlid = le16toh(identify->cntlid);
    164  1.1.20.1  pgoyette 	identify->ver = le32toh(identify->ver);
    165  1.1.20.1  pgoyette 	identify->rtd3r = le32toh(identify->rtd3r);
    166  1.1.20.1  pgoyette 	identify->rtd3e = le32toh(identify->rtd3e);
    167  1.1.20.1  pgoyette 	identify->oaes = le32toh(identify->oaes);
    168  1.1.20.1  pgoyette 	identify->ctrattr = le32toh(identify->ctrattr);
    169  1.1.20.1  pgoyette 	identify->oacs = le16toh(identify->oacs);
    170  1.1.20.1  pgoyette 	identify->wctemp = le16toh(identify->wctemp);
    171  1.1.20.1  pgoyette 	identify->cctemp = le16toh(identify->cctemp);
    172  1.1.20.1  pgoyette 	identify->mtfa = le16toh(identify->mtfa);
    173  1.1.20.1  pgoyette 	identify->hmpre = le32toh(identify->hmpre);
    174  1.1.20.1  pgoyette 	identify->hmmin = le32toh(identify->hmmin);
    175  1.1.20.1  pgoyette 	nvme_le128toh(identify->untncap.tnvmcap);
    176  1.1.20.1  pgoyette 	nvme_le128toh(identify->untncap.unvmcap);
    177  1.1.20.1  pgoyette 	identify->rpmbs = le32toh(identify->rpmbs);
    178  1.1.20.1  pgoyette 	identify->edstt = le16toh(identify->edstt);
    179  1.1.20.1  pgoyette 	identify->kas = le16toh(identify->kas);
    180  1.1.20.1  pgoyette 	identify->hctma = le16toh(identify->hctma);
    181  1.1.20.1  pgoyette 	identify->mntmt = le16toh(identify->mntmt);
    182  1.1.20.1  pgoyette 	identify->mxtmt = le16toh(identify->mxtmt);
    183  1.1.20.1  pgoyette 	identify->sanicap = le32toh(identify->sanicap);
    184  1.1.20.1  pgoyette 	identify->maxcmd = le16toh(identify->maxcmd);
    185  1.1.20.1  pgoyette 	identify->nn = le32toh(identify->nn);
    186  1.1.20.1  pgoyette 	identify->oncs = le16toh(identify->oncs);
    187  1.1.20.1  pgoyette 	identify->fuses = le16toh(identify->fuses);
    188  1.1.20.1  pgoyette 	identify->awun = le16toh(identify->awun);
    189  1.1.20.1  pgoyette 	identify->awupf = le16toh(identify->awupf);
    190  1.1.20.1  pgoyette 	identify->acwu = le16toh(identify->acwu);
    191  1.1.20.1  pgoyette 	identify->sgls = le32toh(identify->sgls);
    192  1.1.20.1  pgoyette 	for (i = 0; i < __arraycount(identify->psd); i++)
    193  1.1.20.1  pgoyette 		nvme_identify_psd_swapbytes(&identify->psd[i]);
    194  1.1.20.1  pgoyette #endif
    195  1.1.20.1  pgoyette }
    196  1.1.20.1  pgoyette 
    197       1.1    nonaka #endif /* __NVMEIO_H__ */
    198