xref: /netbsd-src/sys/dev/ic/mvsatavar.h (revision 3fa9d7b0da6716933d15329c9d458dbc1e653c27)
1*3fa9d7b0Sjdolecek /*	$NetBSD: mvsatavar.h,v 1.5 2018/10/22 20:13:47 jdolecek Exp $	*/
2ce1343fcSkiyohara /*
3ce1343fcSkiyohara  * Copyright (c) 2008 KIYOHARA Takashi
4ce1343fcSkiyohara  * All rights reserved.
5ce1343fcSkiyohara  *
6ce1343fcSkiyohara  * Redistribution and use in source and binary forms, with or without
7ce1343fcSkiyohara  * modification, are permitted provided that the following conditions
8ce1343fcSkiyohara  * are met:
9ce1343fcSkiyohara  * 1. Redistributions of source code must retain the above copyright
10ce1343fcSkiyohara  *    notice, this list of conditions and the following disclaimer.
11ce1343fcSkiyohara  * 2. Redistributions in binary form must reproduce the above copyright
12ce1343fcSkiyohara  *    notice, this list of conditions and the following disclaimer in the
13ce1343fcSkiyohara  *    documentation and/or other materials provided with the distribution.
14ce1343fcSkiyohara  *
15ce1343fcSkiyohara  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16ce1343fcSkiyohara  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17ce1343fcSkiyohara  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18ce1343fcSkiyohara  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19ce1343fcSkiyohara  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20ce1343fcSkiyohara  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21ce1343fcSkiyohara  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22ce1343fcSkiyohara  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23ce1343fcSkiyohara  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24ce1343fcSkiyohara  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25ce1343fcSkiyohara  * POSSIBILITY OF SUCH DAMAGE.
26ce1343fcSkiyohara  */
27ce1343fcSkiyohara 
28ce1343fcSkiyohara #ifndef _MVSATAVAR_H_
29ce1343fcSkiyohara #define _MVSATAVAR_H_
30ce1343fcSkiyohara 
3166dad590Skiyohara struct mvsata_product {
3266dad590Skiyohara 	int vendor;
3366dad590Skiyohara 	int model;
3466dad590Skiyohara 	int hc;
3566dad590Skiyohara 	int port;
3666dad590Skiyohara 	int generation;
3766dad590Skiyohara 	int flags;
3866dad590Skiyohara };
3966dad590Skiyohara 
40ce1343fcSkiyohara #define MVSATA_EDMAQ_LEN	32	/* keep compatibility to gen1 */
41ce1343fcSkiyohara #define MVSATA_EDMAQ_INC(i)	((i) = ((i) + 1) % MVSATA_EDMAQ_LEN)
42ce1343fcSkiyohara #define MVSATA_HC_MAX		2
43ce1343fcSkiyohara #define MVSATA_PORT_MAX		4
44ce1343fcSkiyohara #define MVSATA_CHANNEL_MAX	(MVSATA_HC_MAX * MVSATA_PORT_MAX)
45ce1343fcSkiyohara 
46ce1343fcSkiyohara 
47ce1343fcSkiyohara struct mvsata_port;
48ce1343fcSkiyohara 
49ce1343fcSkiyohara union mvsata_crqb {
50ce1343fcSkiyohara 	struct crqb crqb;
51ce1343fcSkiyohara 	struct crqb_gen2e crqb_gen2e;
52ce1343fcSkiyohara };
53ce1343fcSkiyohara 
54ce1343fcSkiyohara struct _fix_phy_param {
55ce1343fcSkiyohara 	uint32_t pre_amps;		/* Pre/SignalAmps */
56ce1343fcSkiyohara 
57ce1343fcSkiyohara 	void (*_fix_phy)(struct mvsata_port *);
58ce1343fcSkiyohara };
59ce1343fcSkiyohara 
6026cf6855Sjdolecek enum mvsata_edmamode {
6126cf6855Sjdolecek 	nodma,
6226cf6855Sjdolecek 	dma,
6326cf6855Sjdolecek 	queued,
6426cf6855Sjdolecek 	ncq,
6526cf6855Sjdolecek };
6626cf6855Sjdolecek 
67ce1343fcSkiyohara struct mvsata_port {
68ce1343fcSkiyohara 	struct ata_channel port_ata_channel;
69ce1343fcSkiyohara 
70ce1343fcSkiyohara 	int port;
71ce1343fcSkiyohara 	struct mvsata_hc *port_hc;
72ce1343fcSkiyohara 
7326cf6855Sjdolecek 	enum mvsata_edmamode port_edmamode_negotiated;
7426cf6855Sjdolecek 	enum mvsata_edmamode port_edmamode_curr;
75ce1343fcSkiyohara 
76ce1343fcSkiyohara 	int port_prev_erqqop;		/* previous Req Queue Out-Pointer */
77ce1343fcSkiyohara 	bus_dma_tag_t port_dmat;
78ce1343fcSkiyohara 	union mvsata_crqb *port_crqb;	/* EDMA Command Request Block */
79ce1343fcSkiyohara 	bus_dmamap_t port_crqb_dmamap;
80ce1343fcSkiyohara 	struct crpb *port_crpb;		/* EDMA Command Response Block */
81ce1343fcSkiyohara 	bus_dmamap_t port_crpb_dmamap;
82ce1343fcSkiyohara 	struct eprd *port_eprd;		/* EDMA Phy Region Description Table */
83ce1343fcSkiyohara 	bus_dmamap_t port_eprd_dmamap;
84ce1343fcSkiyohara 	struct {
85ce1343fcSkiyohara 		bus_dmamap_t data_dmamap;	/* DMA data buffer */
86ce1343fcSkiyohara 		bus_size_t eprd_offset;		/* offset of ePRD buffer */
87ce1343fcSkiyohara 		struct eprd *eprd;		/* ePRD buffer */
88ce1343fcSkiyohara 	} port_reqtbl[MVSATA_EDMAQ_LEN];
89ce1343fcSkiyohara 
90ce1343fcSkiyohara 	bus_space_tag_t port_iot;
91ce1343fcSkiyohara 	bus_space_handle_t port_ioh;
92ce1343fcSkiyohara 	bus_space_handle_t port_sata_scontrol;	/* SATA Interface control reg */
93ce1343fcSkiyohara 	bus_space_handle_t port_sata_serror;	/* SATA Interface error reg */
94ce1343fcSkiyohara 	bus_space_handle_t port_sata_sstatus;	/* SATA Interface status reg */
95ce1343fcSkiyohara 
96ce1343fcSkiyohara 	struct _fix_phy_param _fix_phy_param;
97ce1343fcSkiyohara };
98ce1343fcSkiyohara 
99ce1343fcSkiyohara struct mvsata_hc {
100ce1343fcSkiyohara 	int hc;
101ce1343fcSkiyohara 	struct mvsata_softc *hc_sc;
102ce1343fcSkiyohara 
103ce1343fcSkiyohara 	bus_space_tag_t hc_iot;		/* Tag for SATAHC Arbiter */
104ce1343fcSkiyohara 	bus_space_handle_t hc_ioh;	/* Handle for SATAHC Arbiter */
105ce1343fcSkiyohara 
106ce1343fcSkiyohara 	struct mvsata_port *hc_ports[MVSATA_CHANNEL_MAX];
107ce1343fcSkiyohara };
108ce1343fcSkiyohara 
109ce1343fcSkiyohara struct mvsata_softc {
110ce1343fcSkiyohara 	struct wdc_softc sc_wdcdev;	/* common wdc definitions */
111ce1343fcSkiyohara 
112ce1343fcSkiyohara 	int sc_model;
113ce1343fcSkiyohara 	int sc_rev;
114ce1343fcSkiyohara 	enum {
115ce1343fcSkiyohara 		gen_unknown = 0,
116ce1343fcSkiyohara 		gen1,
117ce1343fcSkiyohara 		gen2,
118ce1343fcSkiyohara 		gen2e
119ce1343fcSkiyohara 	} sc_gen;			/* Generation for LSI */
120ce1343fcSkiyohara 	int sc_hc;			/* number of host controller */
121ce1343fcSkiyohara 	int sc_port;			/* number of port/host */
122ce1343fcSkiyohara 
123ce1343fcSkiyohara 	bus_space_tag_t sc_iot;
124ce1343fcSkiyohara 	bus_space_handle_t sc_ioh;
125ce1343fcSkiyohara 	bus_dma_tag_t sc_dmat;
126ce1343fcSkiyohara 
127ce1343fcSkiyohara 	struct wdc_regs *sc_wdc_regs;
128ce1343fcSkiyohara 	struct ata_channel *sc_ata_channels[MVSATA_CHANNEL_MAX];
129ce1343fcSkiyohara 	struct mvsata_hc sc_hcs[MVSATA_HC_MAX];
130ce1343fcSkiyohara 
131ce1343fcSkiyohara 	int sc_flags;
132ce1343fcSkiyohara #define MVSATA_FLAGS_PCIE	(1 << 0)
133ce1343fcSkiyohara 
13426cf6855Sjdolecek 	void (*sc_edma_setup_crqb)(struct mvsata_port *, int,
13526cf6855Sjdolecek 				   struct ata_xfer *);
136ce1343fcSkiyohara 	void (*sc_enable_intr)(struct mvsata_port *, int);
137ce1343fcSkiyohara };
138ce1343fcSkiyohara 
1395705ba58Sjdolecek int mvsata_attach(struct mvsata_softc *, const struct mvsata_product *,
140ce1343fcSkiyohara 		  int (*mvsata_sreset)(struct mvsata_softc *),
141ce1343fcSkiyohara 		  int (*mvsata_misc_reset)(struct mvsata_softc *), int);
142ce1343fcSkiyohara int mvsata_intr(struct mvsata_hc *);
143ce1343fcSkiyohara int mvsata_error(struct mvsata_port *);
144ce1343fcSkiyohara 
145ce1343fcSkiyohara #endif	/* _MVSATAVAR_H_ */
146