summaryrefslogtreecommitdiff
path: root/sys/dev/pci/trm_pci.c
blob: cc0830e7241404a8b1ef6d4169af4c71b34047d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*	$OpenBSD: trm_pci.c,v 1.10 2020/07/20 14:41:14 krw Exp $
 * ------------------------------------------------------------
 *       O.S     : OpenBSD
 *    FILE NAME  : trm_pci.c
 *         BY    : Erich Chen     (erich@tekram.com.tw)
 *    Description: Device Driver for Tekram DC395U/UW/F,DC315/U
 *                 PCI SCSI Bus Master Host Adapter
 *                 (SCSI chip set used Tekram ASIC TRM-S1040)
 * (C)Copyright 1995-1999 Tekram Technology Co., Ltd.
 * (C)Copyright 2001-2002 Ashley R. Martens and Kenneth R. Westerback
 * ------------------------------------------------------------
 *    HISTORY:
 *
 *  REV#   DATE          NAME           DESCRIPTION
 *  1.00   05/01/99      ERICH CHEN     First released for NetBSD 1.4.x
 *  1.01   00/00/00      MARTIN AKESSON Port to OpenBSD 2.8
 *  1.02   Sep 19, 2001  ASHLEY MARTENS Cleanup and formatting
 * ------------------------------------------------------------
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * ------------------------------------------------------------
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>

#include <dev/pci/pcidevs.h>
#include <dev/pci/pcivar.h>

#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>

#include <dev/ic/trm.h>

int	trm_pci_probe (struct device *, void *, void *);
void	trm_pci_attach (struct device *, struct device *, void *);

struct  cfattach trm_pci_ca = {
	sizeof(struct trm_softc),
	trm_pci_probe,
	trm_pci_attach,
	NULL,			/* Detach */
	NULL,			/* Activate */
};

struct  cfdriver trm_cd = {
        NULL, "trm", DV_DULL
};

struct scsi_adapter trm_switch = {
	trm_scsi_cmd, NULL, NULL, NULL, NULL
};


/*
 * ------------------------------------------------------------
 * Function : trm_pci_probe
 * Purpose  : Check the slots looking for a board we recognize.
 *            If we find one, note ti's address (slot) and call
 *            the actual probe routine to check it out.
 * Inputs   :
 * ------------------------------------------------------------
 */
int
trm_pci_probe(struct device *parent, void *match, void *aux)
{
	struct pci_attach_args *pa = aux;

	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TEKRAM2) {
		switch (PCI_PRODUCT(pa->pa_id)) {
		case PCI_PRODUCT_TEKRAM2_DC3X5U:
			return 1;
		}
	}
	return 0;
}

/*
 * ------------------------------------------------------------
 * Function : trm_pci_attach
 * Purpose  :
 * Inputs   :
 * ------------------------------------------------------------
 */
void
trm_pci_attach(struct device *parent, struct device *self, void *aux)
{
	struct pci_attach_args *pa = aux;
	struct scsibus_attach_args saa;
	bus_space_handle_t ioh;/* bus space handle */
	pci_intr_handle_t ih;
	struct trm_softc *sc = (void *)self;
	bus_space_tag_t iot;   /* bus space tag    */
	const char *intrstr;
	int unit;

	unit = sc->sc_device.dv_unit;

	if (PCI_PRODUCT(pa->pa_id) != PCI_PRODUCT_TEKRAM2_DC3X5U)
		return;

	/*
	 * mask for get correct base address of pci IO port
	 */
	if (pci_mapreg_map(pa, PCI_MAPREG_START, PCI_MAPREG_TYPE_IO, 0,
	    &iot, &ioh, NULL, NULL, 0) != 0) {
		printf("%s: unable to map registers\n", sc->sc_device.dv_xname);
		return;
	}

	/*
	 * test checksum of eeprom & initial "ACB" adapter control block
	 */
	sc->sc_iotag    = iot;
	sc->sc_iohandle = ioh;
	sc->sc_dmatag   = pa->pa_dmat;

	if (trm_init(sc, unit) != 0) {
		printf("%s: trm_init failed", sc->sc_device.dv_xname);
		return;
	}

	/*
	 *  Map and establish interrupt
	 */
	if (pci_intr_map(pa, &ih)) {
		printf("%s: couldn't map interrupt\n", sc->sc_device.dv_xname);
		return;
	}
	intrstr = pci_intr_string(pa->pa_pc, ih);

	if (pci_intr_establish(pa->pa_pc, ih, IPL_BIO, trm_Interrupt, sc,
	    sc->sc_device.dv_xname) == NULL) {
		printf("\n%s: couldn't establish interrupt", sc->sc_device.dv_xname);
		if (intrstr != NULL)
			printf(" at %s", intrstr);
		printf("\n");
	} else {
		if (intrstr != NULL)
			printf(": %s\n", intrstr);

		saa.saa_adapter_softc    = sc;
		saa.saa_adapter_target   = sc->sc_AdaptSCSIID;
		saa.saa_adapter          = &trm_switch;
		saa.saa_adapter_buswidth = ((sc->sc_config & HCC_WIDE_CARD) == 0) ? 8:16;
		saa.saa_luns		 = 8;
		saa.saa_openings         = 30; /* So TagMask (32 bit integer) always has space */
		saa.saa_pool		 = &sc->sc_iopool;
		saa.saa_quirks = saa.saa_flags = 0;
		saa.saa_wwpn = saa.saa_wwnn = 0;

		config_found(&sc->sc_device, &saa, scsiprint);
	}
}