xref: /openbsd/sys/dev/ic/ufshcivar.h (revision 3d5e1d3e)
1 /*	$OpenBSD: ufshcivar.h,v 1.12 2025/01/18 19:42:39 mglocker Exp $ */
2 
3 /*
4  * Copyright (c) 2022 Marcus Glocker <mglocker@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* #define UFSHCI_DEBUG */
20 #ifdef UFSHCI_DEBUG
21 extern int ufshci_debug;
22 #define DPRINTF(l, x...)        do { if ((l) <= ufshci_debug) printf(x); } \
23                                     while (0)
24 #else
25 #define DPRINTF(l, x...)
26 #endif
27 
28 #define UFSHCI_READ_4(sc, x) \
29     bus_space_read_4((sc)->sc_iot, (sc)->sc_ioh, (x))
30 #define UFSHCI_WRITE_4(sc, x, y) \
31     bus_space_write_4((sc)->sc_iot, (sc)->sc_ioh, (x), (y))
32 
33 #define UFSHCI_DMA_MAP(_udm)	((_udm)->udm_map)
34 #define UFSHCI_DMA_LEN(_udm)	((_udm)->udm_map->dm_segs[0].ds_len)
35 #define UFSHCI_DMA_DVA(_udm)	((uint64_t)(_udm)->udm_map->dm_segs[0].ds_addr)
36 #define UFSHCI_DMA_KVA(_udm)	((void *)(_udm)->udm_kva)
37 struct ufshci_dmamem {
38 	bus_dmamap_t		udm_map;
39 	bus_dma_segment_t	udm_seg;
40 	size_t			udm_size;
41 	caddr_t			udm_kva;
42 };
43 
44 struct ufshci_softc;
45 
46 /* SCSI */
47 enum ccb_status {
48 	CCB_STATUS_FREE,
49 	CCB_STATUS_INPROGRESS,
50 	CCB_STATUS_READY2FREE,
51 	CCB_STATUS_COUNT
52 };
53 struct ufshci_ccb {
54 	SIMPLEQ_ENTRY(ufshci_ccb)	 ccb_entry;
55 	bus_dmamap_t			 ccb_dmamap;
56 	void				*ccb_cookie;
57 	int				 ccb_slot;
58 	int				 ccb_status;
59 	void				 (*ccb_done)(struct ufshci_softc *,
60 					     struct ufshci_ccb *);
61 };
62 SIMPLEQ_HEAD(ufshci_ccb_list, ufshci_ccb);
63 
64 struct ufshci_softc {
65 	struct device		 sc_dev;
66 
67 	bus_space_tag_t		 sc_iot;
68 	bus_space_handle_t	 sc_ioh;
69 	bus_size_t		 sc_ios;
70 	bus_dma_tag_t		 sc_dmat;
71 
72 	uint8_t			 sc_iacth;
73 	struct mutex		 sc_cmd_mtx;
74 
75 #define UFSHCI_FLAGS_AGGR_INTR	 1
76 	uint8_t			 sc_flags;
77 	uint32_t		 sc_ver;
78 	uint32_t		 sc_cap;
79 	uint32_t		 sc_hcpid;
80 	uint32_t		 sc_hcmid;
81 	uint8_t			 sc_nutmrs;
82 	uint8_t			 sc_rtt;
83 	uint8_t			 sc_nutrs;
84 
85 	struct ufshci_dmamem	*sc_dmamem_utmrd;
86 	struct ufshci_dmamem	*sc_dmamem_utrd;
87 	struct ufshci_dmamem	*sc_dmamem_ucd;
88 
89 	/* SCSI */
90 	struct scsi_iopool	 sc_iopool;
91 	struct mutex		 sc_ccb_mtx;
92 	struct ufshci_ccb_list	 sc_ccb_list;
93 	struct ufshci_ccb	*sc_ccbs;
94 
95 	/* kstat */
96 	uint64_t		*sc_stats_slots;
97 	struct mutex		 sc_kstat_mtx_ccb;
98 	struct mutex		 sc_kstat_mtx_slot;
99 	struct kstat		*sc_kstat_ccb;
100 	struct kstat		*sc_kstat_slot;
101 };
102 
103 int	ufshci_intr(void *);
104 int	ufshci_attach(struct ufshci_softc *);
105 int	ufshci_activate(struct device *, int);
106