mlx_pci.c revision 1.5.6.2 1 1.5.6.2 he /* $NetBSD: mlx_pci.c,v 1.5.6.2 2001/10/25 18:02:41 he Exp $ */
2 1.5.6.2 he
3 1.5.6.2 he /*-
4 1.5.6.2 he * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.5.6.2 he * All rights reserved.
6 1.5.6.2 he *
7 1.5.6.2 he * This code is derived from software contributed to The NetBSD Foundation
8 1.5.6.2 he * by Andrew Doran.
9 1.5.6.2 he *
10 1.5.6.2 he * Redistribution and use in source and binary forms, with or without
11 1.5.6.2 he * modification, are permitted provided that the following conditions
12 1.5.6.2 he * are met:
13 1.5.6.2 he * 1. Redistributions of source code must retain the above copyright
14 1.5.6.2 he * notice, this list of conditions and the following disclaimer.
15 1.5.6.2 he * 2. Redistributions in binary form must reproduce the above copyright
16 1.5.6.2 he * notice, this list of conditions and the following disclaimer in the
17 1.5.6.2 he * documentation and/or other materials provided with the distribution.
18 1.5.6.2 he * 3. All advertising materials mentioning features or use of this software
19 1.5.6.2 he * must display the following acknowledgement:
20 1.5.6.2 he * This product includes software developed by the NetBSD
21 1.5.6.2 he * Foundation, Inc. and its contributors.
22 1.5.6.2 he * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.5.6.2 he * contributors may be used to endorse or promote products derived
24 1.5.6.2 he * from this software without specific prior written permission.
25 1.5.6.2 he *
26 1.5.6.2 he * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.5.6.2 he * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.5.6.2 he * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.5.6.2 he * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.5.6.2 he * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.5.6.2 he * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.5.6.2 he * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.5.6.2 he * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.5.6.2 he * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.5.6.2 he * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.5.6.2 he * POSSIBILITY OF SUCH DAMAGE.
37 1.5.6.2 he */
38 1.5.6.2 he
39 1.5.6.2 he /*-
40 1.5.6.2 he * Copyright (c) 1999 Michael Smith
41 1.5.6.2 he * All rights reserved.
42 1.5.6.2 he *
43 1.5.6.2 he * Redistribution and use in source and binary forms, with or without
44 1.5.6.2 he * modification, are permitted provided that the following conditions
45 1.5.6.2 he * are met:
46 1.5.6.2 he * 1. Redistributions of source code must retain the above copyright
47 1.5.6.2 he * notice, this list of conditions and the following disclaimer.
48 1.5.6.2 he * 2. Redistributions in binary form must reproduce the above copyright
49 1.5.6.2 he * notice, this list of conditions and the following disclaimer in the
50 1.5.6.2 he * documentation and/or other materials provided with the distribution.
51 1.5.6.2 he *
52 1.5.6.2 he * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
53 1.5.6.2 he * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 1.5.6.2 he * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 1.5.6.2 he * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
56 1.5.6.2 he * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 1.5.6.2 he * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 1.5.6.2 he * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 1.5.6.2 he * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 1.5.6.2 he * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 1.5.6.2 he * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 1.5.6.2 he * SUCH DAMAGE.
63 1.5.6.2 he *
64 1.5.6.2 he * from FreeBSD: mlx_pci.c,v 1.4.2.4 2000/10/28 10:48:09 msmith Exp
65 1.5.6.2 he */
66 1.5.6.2 he
67 1.5.6.2 he /*
68 1.5.6.2 he * PCI front-end for the mlx(4) driver.
69 1.5.6.2 he */
70 1.5.6.2 he
71 1.5.6.2 he #include <sys/param.h>
72 1.5.6.2 he #include <sys/systm.h>
73 1.5.6.2 he #include <sys/kernel.h>
74 1.5.6.2 he #include <sys/device.h>
75 1.5.6.2 he #include <sys/queue.h>
76 1.5.6.2 he #include <sys/callout.h>
77 1.5.6.2 he
78 1.5.6.2 he #include <machine/endian.h>
79 1.5.6.2 he #include <machine/bus.h>
80 1.5.6.2 he
81 1.5.6.2 he #include <dev/ic/mlxreg.h>
82 1.5.6.2 he #include <dev/ic/mlxio.h>
83 1.5.6.2 he #include <dev/ic/mlxvar.h>
84 1.5.6.2 he
85 1.5.6.2 he #include <dev/pci/pcireg.h>
86 1.5.6.2 he #include <dev/pci/pcivar.h>
87 1.5.6.2 he #include <dev/pci/pcidevs.h>
88 1.5.6.2 he
89 1.5.6.2 he static void mlx_pci_attach(struct device *, struct device *, void *);
90 1.5.6.2 he static int mlx_pci_match(struct device *, struct cfdata *, void *);
91 1.5.6.2 he static const struct mlx_pci_ident *mlx_pci_findmpi(struct pci_attach_args *);
92 1.5.6.2 he
93 1.5.6.2 he static int mlx_v3_submit(struct mlx_softc *, struct mlx_ccb *);
94 1.5.6.2 he static int mlx_v3_findcomplete(struct mlx_softc *, u_int *, u_int *);
95 1.5.6.2 he static void mlx_v3_intaction(struct mlx_softc *, int);
96 1.5.6.2 he static int mlx_v3_fw_handshake(struct mlx_softc *, int *, int *, int *);
97 1.5.6.2 he #ifdef MLX_RESET
98 1.5.6.2 he static int mlx_v3_reset(struct mlx_softc *);
99 1.5.6.2 he #endif
100 1.5.6.2 he
101 1.5.6.2 he static int mlx_v4_submit(struct mlx_softc *, struct mlx_ccb *);
102 1.5.6.2 he static int mlx_v4_findcomplete(struct mlx_softc *, u_int *, u_int *);
103 1.5.6.2 he static void mlx_v4_intaction(struct mlx_softc *, int);
104 1.5.6.2 he static int mlx_v4_fw_handshake(struct mlx_softc *, int *, int *, int *);
105 1.5.6.2 he
106 1.5.6.2 he static int mlx_v5_submit(struct mlx_softc *, struct mlx_ccb *);
107 1.5.6.2 he static int mlx_v5_findcomplete(struct mlx_softc *, u_int *, u_int *);
108 1.5.6.2 he static void mlx_v5_intaction(struct mlx_softc *, int);
109 1.5.6.2 he static int mlx_v5_fw_handshake(struct mlx_softc *, int *, int *, int *);
110 1.5.6.2 he
111 1.5.6.2 he struct mlx_pci_ident {
112 1.5.6.2 he u_short mpi_vendor;
113 1.5.6.2 he u_short mpi_product;
114 1.5.6.2 he u_short mpi_subvendor;
115 1.5.6.2 he u_short mpi_subproduct;
116 1.5.6.2 he int mpi_iftype;
117 1.5.6.2 he } static const mlx_pci_ident[] = {
118 1.5.6.2 he {
119 1.5.6.2 he PCI_VENDOR_MYLEX,
120 1.5.6.2 he PCI_PRODUCT_MYLEX_RAID_V2,
121 1.5.6.2 he 0x0000,
122 1.5.6.2 he 0x0000,
123 1.5.6.2 he 2,
124 1.5.6.2 he },
125 1.5.6.2 he {
126 1.5.6.2 he PCI_VENDOR_MYLEX,
127 1.5.6.2 he PCI_PRODUCT_MYLEX_RAID_V3,
128 1.5.6.2 he 0x0000,
129 1.5.6.2 he 0x0000,
130 1.5.6.2 he 3,
131 1.5.6.2 he },
132 1.5.6.2 he {
133 1.5.6.2 he PCI_VENDOR_MYLEX,
134 1.5.6.2 he PCI_PRODUCT_MYLEX_RAID_V4,
135 1.5.6.2 he 0x0000,
136 1.5.6.2 he 0x0000,
137 1.5.6.2 he 4,
138 1.5.6.2 he },
139 1.5.6.2 he {
140 1.5.6.2 he PCI_VENDOR_DEC,
141 1.5.6.2 he PCI_PRODUCT_DEC_SWXCR,
142 1.5.6.2 he PCI_VENDOR_MYLEX,
143 1.5.6.2 he PCI_PRODUCT_MYLEX_RAID_V5,
144 1.5.6.2 he 5,
145 1.5.6.2 he },
146 1.5.6.2 he };
147 1.5.6.2 he
148 1.5.6.2 he struct cfattach mlx_pci_ca = {
149 1.5.6.2 he sizeof(struct mlx_softc), mlx_pci_match, mlx_pci_attach
150 1.5.6.2 he };
151 1.5.6.2 he
152 1.5.6.2 he /*
153 1.5.6.2 he * Try to find a `mlx_pci_ident' entry corresponding to this board.
154 1.5.6.2 he */
155 1.5.6.2 he static const struct mlx_pci_ident *
156 1.5.6.2 he mlx_pci_findmpi(struct pci_attach_args *pa)
157 1.5.6.2 he {
158 1.5.6.2 he const struct mlx_pci_ident *mpi, *maxmpi;
159 1.5.6.2 he pcireg_t reg;
160 1.5.6.2 he
161 1.5.6.2 he mpi = mlx_pci_ident;
162 1.5.6.2 he maxmpi = mpi + sizeof(mlx_pci_ident) / sizeof(mlx_pci_ident[0]);
163 1.5.6.2 he
164 1.5.6.2 he for (; mpi < maxmpi; mpi++) {
165 1.5.6.2 he if (PCI_VENDOR(pa->pa_id) != mpi->mpi_vendor ||
166 1.5.6.2 he PCI_PRODUCT(pa->pa_id) != mpi->mpi_product)
167 1.5.6.2 he continue;
168 1.5.6.2 he
169 1.5.6.2 he if (mpi->mpi_subvendor == 0x0000)
170 1.5.6.2 he return (mpi);
171 1.5.6.2 he
172 1.5.6.2 he reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
173 1.5.6.2 he
174 1.5.6.2 he if (PCI_VENDOR(reg) == mpi->mpi_subvendor &&
175 1.5.6.2 he PCI_PRODUCT(reg) == mpi->mpi_subproduct)
176 1.5.6.2 he return (mpi);
177 1.5.6.2 he }
178 1.5.6.2 he
179 1.5.6.2 he return (NULL);
180 1.5.6.2 he }
181 1.5.6.2 he
182 1.5.6.2 he /*
183 1.5.6.2 he * Match a supported board.
184 1.5.6.2 he */
185 1.5.6.2 he static int
186 1.5.6.2 he mlx_pci_match(struct device *parent, struct cfdata *cfdata, void *aux)
187 1.5.6.2 he {
188 1.5.6.2 he
189 1.5.6.2 he return (mlx_pci_findmpi(aux) != NULL);
190 1.5.6.2 he }
191 1.5.6.2 he
192 1.5.6.2 he /*
193 1.5.6.2 he * Attach a supported board.
194 1.5.6.2 he */
195 1.5.6.2 he static void
196 1.5.6.2 he mlx_pci_attach(struct device *parent, struct device *self, void *aux)
197 1.5.6.2 he {
198 1.5.6.2 he struct pci_attach_args *pa;
199 1.5.6.2 he struct mlx_softc *mlx;
200 1.5.6.2 he pci_chipset_tag_t pc;
201 1.5.6.2 he pci_intr_handle_t ih;
202 1.5.6.2 he bus_space_handle_t memh, ioh;
203 1.5.6.2 he bus_space_tag_t memt, iot;
204 1.5.6.2 he pcireg_t reg;
205 1.5.6.2 he const char *intrstr;
206 1.5.6.2 he int ior, memr, i;
207 1.5.6.2 he const struct mlx_pci_ident *mpi;
208 1.5.6.2 he
209 1.5.6.2 he mlx = (struct mlx_softc *)self;
210 1.5.6.2 he pa = aux;
211 1.5.6.2 he pc = pa->pa_pc;
212 1.5.6.2 he mpi = mlx_pci_findmpi(aux);
213 1.5.6.2 he
214 1.5.6.2 he mlx->mlx_dmat = pa->pa_dmat;
215 1.5.6.2 he mlx->mlx_iftype = mpi->mpi_iftype;
216 1.5.6.2 he
217 1.5.6.2 he printf(": Mylex RAID (v%d interface)\n", mpi->mpi_iftype);
218 1.5.6.2 he
219 1.5.6.2 he /*
220 1.5.6.2 he * Map the PCI register window.
221 1.5.6.2 he */
222 1.5.6.2 he memr = -1;
223 1.5.6.2 he ior = -1;
224 1.5.6.2 he
225 1.5.6.2 he for (i = 0x10; i <= 0x14; i += 4) {
226 1.5.6.2 he reg = pci_conf_read(pa->pa_pc, pa->pa_tag, i);
227 1.5.6.2 he
228 1.5.6.2 he if (PCI_MAPREG_TYPE(reg) == PCI_MAPREG_TYPE_IO) {
229 1.5.6.2 he if (ior == -1 && PCI_MAPREG_IO_SIZE(reg) != 0)
230 1.5.6.2 he ior = i;
231 1.5.6.2 he } else {
232 1.5.6.2 he if (memr == -1 && PCI_MAPREG_MEM_SIZE(reg) != 0)
233 1.5.6.2 he memr = i;
234 1.5.6.2 he }
235 1.5.6.2 he }
236 1.5.6.2 he
237 1.5.6.2 he if (memr != -1)
238 1.5.6.2 he if (pci_mapreg_map(pa, memr, PCI_MAPREG_TYPE_MEM, 0,
239 1.5.6.2 he &memt, &memh, NULL, NULL))
240 1.5.6.2 he memr = -1;
241 1.5.6.2 he if (ior != -1)
242 1.5.6.2 he if (pci_mapreg_map(pa, ior, PCI_MAPREG_TYPE_IO, 0,
243 1.5.6.2 he &iot, &ioh, NULL, NULL))
244 1.5.6.2 he ior = -1;
245 1.5.6.2 he
246 1.5.6.2 he if (memr != -1) {
247 1.5.6.2 he mlx->mlx_iot = memt;
248 1.5.6.2 he mlx->mlx_ioh = memh;
249 1.5.6.2 he } else if (ior != -1) {
250 1.5.6.2 he mlx->mlx_iot = iot;
251 1.5.6.2 he mlx->mlx_ioh = ioh;
252 1.5.6.2 he } else {
253 1.5.6.2 he printf("%s: can't map i/o or memory space\n", self->dv_xname);
254 1.5.6.2 he return;
255 1.5.6.2 he }
256 1.5.6.2 he
257 1.5.6.2 he /* Enable the device. */
258 1.5.6.2 he reg = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
259 1.5.6.2 he pci_conf_write(pa->pa_pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
260 1.5.6.2 he reg | PCI_COMMAND_MASTER_ENABLE);
261 1.5.6.2 he
262 1.5.6.2 he /* Map and establish the interrupt. */
263 1.5.6.2 he if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, pa->pa_intrline,
264 1.5.6.2 he &ih)) {
265 1.5.6.2 he printf("%s: can't map interrupt\n", self->dv_xname);
266 1.5.6.2 he return;
267 1.5.6.2 he }
268 1.5.6.2 he intrstr = pci_intr_string(pc, ih);
269 1.5.6.2 he mlx->mlx_ih = pci_intr_establish(pc, ih, IPL_BIO, mlx_intr, mlx);
270 1.5.6.2 he if (mlx->mlx_ih == NULL) {
271 1.5.6.2 he printf("%s: can't establish interrupt", self->dv_xname);
272 1.5.6.2 he if (intrstr != NULL)
273 1.5.6.2 he printf(" at %s", intrstr);
274 1.5.6.2 he printf("\n");
275 1.5.6.2 he return;
276 1.5.6.2 he }
277 1.5.6.2 he
278 1.5.6.2 he /* Select linkage based on controller interface type. */
279 1.5.6.2 he switch (mlx->mlx_iftype) {
280 1.5.6.2 he case 2:
281 1.5.6.2 he case 3:
282 1.5.6.2 he mlx->mlx_submit = mlx_v3_submit;
283 1.5.6.2 he mlx->mlx_findcomplete = mlx_v3_findcomplete;
284 1.5.6.2 he mlx->mlx_intaction = mlx_v3_intaction;
285 1.5.6.2 he mlx->mlx_fw_handshake = mlx_v3_fw_handshake;
286 1.5.6.2 he #ifdef MLX_RESET
287 1.5.6.2 he mlx->mlx_reset = mlx_v3_reset;
288 1.5.6.2 he #endif
289 1.5.6.2 he break;
290 1.5.6.2 he
291 1.5.6.2 he case 4:
292 1.5.6.2 he mlx->mlx_submit = mlx_v4_submit;
293 1.5.6.2 he mlx->mlx_findcomplete = mlx_v4_findcomplete;
294 1.5.6.2 he mlx->mlx_intaction = mlx_v4_intaction;
295 1.5.6.2 he mlx->mlx_fw_handshake = mlx_v4_fw_handshake;
296 1.5.6.2 he break;
297 1.5.6.2 he
298 1.5.6.2 he case 5:
299 1.5.6.2 he mlx->mlx_submit = mlx_v5_submit;
300 1.5.6.2 he mlx->mlx_findcomplete = mlx_v5_findcomplete;
301 1.5.6.2 he mlx->mlx_intaction = mlx_v5_intaction;
302 1.5.6.2 he mlx->mlx_fw_handshake = mlx_v5_fw_handshake;
303 1.5.6.2 he break;
304 1.5.6.2 he }
305 1.5.6.2 he
306 1.5.6.2 he mlx_init(mlx, intrstr);
307 1.5.6.2 he }
308 1.5.6.2 he
309 1.5.6.2 he /*
310 1.5.6.2 he * ================= V3 interface linkage =================
311 1.5.6.2 he */
312 1.5.6.2 he
313 1.5.6.2 he /*
314 1.5.6.2 he * Try to give (mc) to the controller. Returns 1 if successful, 0 on
315 1.5.6.2 he * failure (the controller is not ready to take a command).
316 1.5.6.2 he *
317 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
318 1.5.6.2 he */
319 1.5.6.2 he static int
320 1.5.6.2 he mlx_v3_submit(struct mlx_softc *mlx, struct mlx_ccb *mc)
321 1.5.6.2 he {
322 1.5.6.2 he
323 1.5.6.2 he /* Ready for our command? */
324 1.5.6.2 he if ((mlx_inb(mlx, MLX_V3REG_IDB) & MLX_V3_IDB_FULL) == 0) {
325 1.5.6.2 he /* Copy mailbox data to window. */
326 1.5.6.2 he bus_space_write_region_1(mlx->mlx_iot, mlx->mlx_ioh,
327 1.5.6.2 he MLX_V3REG_MAILBOX, mc->mc_mbox, MLX_V3_MAILBOX_LEN);
328 1.5.6.2 he bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh,
329 1.5.6.2 he MLX_V3REG_MAILBOX, MLX_V3_MAILBOX_LEN,
330 1.5.6.2 he BUS_SPACE_BARRIER_WRITE);
331 1.5.6.2 he
332 1.5.6.2 he /* Post command. */
333 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_IDB, MLX_V3_IDB_FULL);
334 1.5.6.2 he return (1);
335 1.5.6.2 he }
336 1.5.6.2 he
337 1.5.6.2 he return (0);
338 1.5.6.2 he }
339 1.5.6.2 he
340 1.5.6.2 he /*
341 1.5.6.2 he * See if a command has been completed, if so acknowledge its completion and
342 1.5.6.2 he * recover the slot number and status code.
343 1.5.6.2 he *
344 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
345 1.5.6.2 he */
346 1.5.6.2 he static int
347 1.5.6.2 he mlx_v3_findcomplete(struct mlx_softc *mlx, u_int *slot, u_int *status)
348 1.5.6.2 he {
349 1.5.6.2 he
350 1.5.6.2 he /* Status available? */
351 1.5.6.2 he if ((mlx_inb(mlx, MLX_V3REG_ODB) & MLX_V3_ODB_SAVAIL) != 0) {
352 1.5.6.2 he *slot = mlx_inb(mlx, MLX_V3REG_STATUS_IDENT);
353 1.5.6.2 he *status = mlx_inw(mlx, MLX_V3REG_STATUS);
354 1.5.6.2 he
355 1.5.6.2 he /* Acknowledge completion. */
356 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_ODB, MLX_V3_ODB_SAVAIL);
357 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_IDB, MLX_V3_IDB_SACK);
358 1.5.6.2 he return (1);
359 1.5.6.2 he }
360 1.5.6.2 he
361 1.5.6.2 he return (0);
362 1.5.6.2 he }
363 1.5.6.2 he
364 1.5.6.2 he /*
365 1.5.6.2 he * Enable/disable interrupts as requested. (No acknowledge required)
366 1.5.6.2 he *
367 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
368 1.5.6.2 he */
369 1.5.6.2 he static void
370 1.5.6.2 he mlx_v3_intaction(struct mlx_softc *mlx, int action)
371 1.5.6.2 he {
372 1.5.6.2 he
373 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_IE, action != 0);
374 1.5.6.2 he }
375 1.5.6.2 he
376 1.5.6.2 he /*
377 1.5.6.2 he * Poll for firmware error codes during controller initialisation.
378 1.5.6.2 he *
379 1.5.6.2 he * Returns 0 if initialisation is complete, 1 if still in progress but no
380 1.5.6.2 he * error has been fetched, 2 if an error has been retrieved.
381 1.5.6.2 he */
382 1.5.6.2 he static int
383 1.5.6.2 he mlx_v3_fw_handshake(struct mlx_softc *mlx, int *error, int *param1, int *param2)
384 1.5.6.2 he {
385 1.5.6.2 he u_int8_t fwerror;
386 1.5.6.2 he
387 1.5.6.2 he /* First time around, clear any hardware completion status. */
388 1.5.6.2 he if ((mlx->mlx_flags & MLXF_FW_INITTED) == 0) {
389 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_IDB, MLX_V3_IDB_SACK);
390 1.5.6.2 he DELAY(1000);
391 1.5.6.2 he mlx->mlx_flags |= MLXF_FW_INITTED;
392 1.5.6.2 he }
393 1.5.6.2 he
394 1.5.6.2 he /* Init in progress? */
395 1.5.6.2 he if ((mlx_inb(mlx, MLX_V3REG_IDB) & MLX_V3_IDB_INIT_BUSY) == 0)
396 1.5.6.2 he return (0);
397 1.5.6.2 he
398 1.5.6.2 he /* Test error value. */
399 1.5.6.2 he fwerror = mlx_inb(mlx, MLX_V3REG_FWERROR);
400 1.5.6.2 he
401 1.5.6.2 he if ((fwerror & MLX_V3_FWERROR_PEND) == 0)
402 1.5.6.2 he return (1);
403 1.5.6.2 he
404 1.5.6.2 he /* Mask status pending bit, fetch status. */
405 1.5.6.2 he *error = fwerror & ~MLX_V3_FWERROR_PEND;
406 1.5.6.2 he *param1 = mlx_inb(mlx, MLX_V3REG_FWERROR_PARAM1);
407 1.5.6.2 he *param2 = mlx_inb(mlx, MLX_V3REG_FWERROR_PARAM2);
408 1.5.6.2 he
409 1.5.6.2 he /* Acknowledge. */
410 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_FWERROR, 0);
411 1.5.6.2 he
412 1.5.6.2 he return (2);
413 1.5.6.2 he }
414 1.5.6.2 he
415 1.5.6.2 he #ifdef MLX_RESET
416 1.5.6.2 he /*
417 1.5.6.2 he * Reset the controller. Return non-zero on failure.
418 1.5.6.2 he */
419 1.5.6.2 he static int
420 1.5.6.2 he mlx_v3_reset(struct mlx_softc *mlx)
421 1.5.6.2 he {
422 1.5.6.2 he int i;
423 1.5.6.2 he
424 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_IDB, MLX_V3_IDB_SACK);
425 1.5.6.2 he delay(1000000);
426 1.5.6.2 he
427 1.5.6.2 he /* Wait up to 2 minutes for the bit to clear. */
428 1.5.6.2 he for (i = 120; i != 0; i--) {
429 1.5.6.2 he delay(1000000);
430 1.5.6.2 he if ((mlx_inb(mlx, MLX_V3REG_IDB) & MLX_V3_IDB_SACK) == 0)
431 1.5.6.2 he break;
432 1.5.6.2 he }
433 1.5.6.2 he if (i == 0) {
434 1.5.6.2 he /* ZZZ */
435 1.5.6.2 he printf("mlx0: SACK didn't clear\n");
436 1.5.6.2 he return (-1);
437 1.5.6.2 he }
438 1.5.6.2 he
439 1.5.6.2 he mlx_outb(mlx, MLX_V3REG_IDB, MLX_V3_IDB_RESET);
440 1.5.6.2 he
441 1.5.6.2 he /* Wait up to 5 seconds for the bit to clear. */
442 1.5.6.2 he for (i = 5; i != 0; i--) {
443 1.5.6.2 he delay(1000000);
444 1.5.6.2 he if ((mlx_inb(mlx, MLX_V3REG_IDB) & MLX_V3_IDB_RESET) == 0)
445 1.5.6.2 he break;
446 1.5.6.2 he }
447 1.5.6.2 he if (i == 0) {
448 1.5.6.2 he /* ZZZ */
449 1.5.6.2 he printf("mlx0: RESET didn't clear\n");
450 1.5.6.2 he return (-1);
451 1.5.6.2 he }
452 1.5.6.2 he
453 1.5.6.2 he return (0);
454 1.5.6.2 he }
455 1.5.6.2 he #endif /* MLX_RESET */
456 1.5.6.2 he
457 1.5.6.2 he /*
458 1.5.6.2 he * ================= V4 interface linkage =================
459 1.5.6.2 he */
460 1.5.6.2 he
461 1.5.6.2 he /*
462 1.5.6.2 he * Try to give (mc) to the controller. Returns 1 if successful, 0 on
463 1.5.6.2 he * failure (the controller is not ready to take a command).
464 1.5.6.2 he *
465 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
466 1.5.6.2 he */
467 1.5.6.2 he static int
468 1.5.6.2 he mlx_v4_submit(struct mlx_softc *mlx, struct mlx_ccb *mc)
469 1.5.6.2 he {
470 1.5.6.2 he
471 1.5.6.2 he /* Ready for our command? */
472 1.5.6.2 he if ((mlx_inl(mlx, MLX_V4REG_IDB) & MLX_V4_IDB_FULL) == 0) {
473 1.5.6.2 he /* Copy mailbox data to window. */
474 1.5.6.2 he bus_space_write_region_1(mlx->mlx_iot, mlx->mlx_ioh,
475 1.5.6.2 he MLX_V4REG_MAILBOX, mc->mc_mbox, MLX_V4_MAILBOX_LEN);
476 1.5.6.2 he bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh,
477 1.5.6.2 he MLX_V4REG_MAILBOX, MLX_V4_MAILBOX_LEN,
478 1.5.6.2 he BUS_SPACE_BARRIER_WRITE);
479 1.5.6.2 he
480 1.5.6.2 he /* Post command. */
481 1.5.6.2 he mlx_outl(mlx, MLX_V4REG_IDB, MLX_V4_IDB_HWMBOX_CMD);
482 1.5.6.2 he return (1);
483 1.5.6.2 he }
484 1.5.6.2 he
485 1.5.6.2 he return (0);
486 1.5.6.2 he }
487 1.5.6.2 he
488 1.5.6.2 he /*
489 1.5.6.2 he * See if a command has been completed, if so acknowledge its completion and
490 1.5.6.2 he * recover the slot number and status code.
491 1.5.6.2 he *
492 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
493 1.5.6.2 he */
494 1.5.6.2 he static int
495 1.5.6.2 he mlx_v4_findcomplete(struct mlx_softc *mlx, u_int *slot, u_int *status)
496 1.5.6.2 he {
497 1.5.6.2 he
498 1.5.6.2 he /* Status available? */
499 1.5.6.2 he if ((mlx_inl(mlx, MLX_V4REG_ODB) & MLX_V4_ODB_HWSAVAIL) != 0) {
500 1.5.6.2 he *slot = mlx_inb(mlx, MLX_V4REG_STATUS_IDENT);
501 1.5.6.2 he *status = mlx_inw(mlx, MLX_V4REG_STATUS);
502 1.5.6.2 he
503 1.5.6.2 he /* Acknowledge completion. */
504 1.5.6.2 he mlx_outl(mlx, MLX_V4REG_ODB, MLX_V4_ODB_HWMBOX_ACK);
505 1.5.6.2 he mlx_outl(mlx, MLX_V4REG_IDB, MLX_V4_IDB_SACK);
506 1.5.6.2 he return (1);
507 1.5.6.2 he }
508 1.5.6.2 he
509 1.5.6.2 he return (0);
510 1.5.6.2 he }
511 1.5.6.2 he
512 1.5.6.2 he /*
513 1.5.6.2 he * Enable/disable interrupts as requested.
514 1.5.6.2 he *
515 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
516 1.5.6.2 he */
517 1.5.6.2 he static void
518 1.5.6.2 he mlx_v4_intaction(struct mlx_softc *mlx, int action)
519 1.5.6.2 he {
520 1.5.6.2 he u_int32_t ier;
521 1.5.6.2 he
522 1.5.6.2 he if (!action)
523 1.5.6.2 he ier = MLX_V4_IE_MASK | MLX_V4_IE_DISINT;
524 1.5.6.2 he else
525 1.5.6.2 he ier = MLX_V4_IE_MASK & ~MLX_V4_IE_DISINT;
526 1.5.6.2 he
527 1.5.6.2 he mlx_outl(mlx, MLX_V4REG_IE, ier);
528 1.5.6.2 he }
529 1.5.6.2 he
530 1.5.6.2 he /*
531 1.5.6.2 he * Poll for firmware error codes during controller initialisation.
532 1.5.6.2 he *
533 1.5.6.2 he * Returns 0 if initialisation is complete, 1 if still in progress but no
534 1.5.6.2 he * error has been fetched, 2 if an error has been retrieved.
535 1.5.6.2 he */
536 1.5.6.2 he static int
537 1.5.6.2 he mlx_v4_fw_handshake(struct mlx_softc *mlx, int *error, int *param1, int *param2)
538 1.5.6.2 he {
539 1.5.6.2 he u_int8_t fwerror;
540 1.5.6.2 he
541 1.5.6.2 he /* First time around, clear any hardware completion status. */
542 1.5.6.2 he if ((mlx->mlx_flags & MLXF_FW_INITTED) == 0) {
543 1.5.6.2 he mlx_outl(mlx, MLX_V4REG_IDB, MLX_V4_IDB_SACK);
544 1.5.6.2 he DELAY(1000);
545 1.5.6.2 he mlx->mlx_flags |= MLXF_FW_INITTED;
546 1.5.6.2 he }
547 1.5.6.2 he
548 1.5.6.2 he /* Init in progress? */
549 1.5.6.2 he if ((mlx_inl(mlx, MLX_V4REG_IDB) & MLX_V4_IDB_INIT_BUSY) == 0)
550 1.5.6.2 he return (0);
551 1.5.6.2 he
552 1.5.6.2 he /* Test error value */
553 1.5.6.2 he fwerror = mlx_inb(mlx, MLX_V4REG_FWERROR);
554 1.5.6.2 he if ((fwerror & MLX_V4_FWERROR_PEND) == 0)
555 1.5.6.2 he return (1);
556 1.5.6.2 he
557 1.5.6.2 he /* Mask status pending bit, fetch status. */
558 1.5.6.2 he *error = fwerror & ~MLX_V4_FWERROR_PEND;
559 1.5.6.2 he *param1 = mlx_inb(mlx, MLX_V4REG_FWERROR_PARAM1);
560 1.5.6.2 he *param2 = mlx_inb(mlx, MLX_V4REG_FWERROR_PARAM2);
561 1.5.6.2 he
562 1.5.6.2 he /* Acknowledge. */
563 1.5.6.2 he mlx_outb(mlx, MLX_V4REG_FWERROR, 0);
564 1.5.6.2 he
565 1.5.6.2 he return (2);
566 1.5.6.2 he }
567 1.5.6.2 he
568 1.5.6.2 he /*
569 1.5.6.2 he * ================= V5 interface linkage =================
570 1.5.6.2 he */
571 1.5.6.2 he
572 1.5.6.2 he /*
573 1.5.6.2 he * Try to give (mc) to the controller. Returns 1 if successful, 0 on failure
574 1.5.6.2 he * (the controller is not ready to take a command).
575 1.5.6.2 he *
576 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
577 1.5.6.2 he */
578 1.5.6.2 he static int
579 1.5.6.2 he mlx_v5_submit(struct mlx_softc *mlx, struct mlx_ccb *mc)
580 1.5.6.2 he {
581 1.5.6.2 he
582 1.5.6.2 he /* Ready for our command? */
583 1.5.6.2 he if ((mlx_inb(mlx, MLX_V5REG_IDB) & MLX_V5_IDB_EMPTY) != 0) {
584 1.5.6.2 he /* Copy mailbox data to window. */
585 1.5.6.2 he bus_space_write_region_1(mlx->mlx_iot, mlx->mlx_ioh,
586 1.5.6.2 he MLX_V5REG_MAILBOX, mc->mc_mbox, MLX_V5_MAILBOX_LEN);
587 1.5.6.2 he bus_space_barrier(mlx->mlx_iot, mlx->mlx_ioh,
588 1.5.6.2 he MLX_V5REG_MAILBOX, MLX_V5_MAILBOX_LEN,
589 1.5.6.2 he BUS_SPACE_BARRIER_WRITE);
590 1.5.6.2 he
591 1.5.6.2 he /* Post command */
592 1.5.6.2 he mlx_outb(mlx, MLX_V5REG_IDB, MLX_V5_IDB_HWMBOX_CMD);
593 1.5.6.2 he return (1);
594 1.5.6.2 he }
595 1.5.6.2 he
596 1.5.6.2 he return (0);
597 1.5.6.2 he }
598 1.5.6.2 he
599 1.5.6.2 he /*
600 1.5.6.2 he * See if a command has been completed, if so acknowledge its completion and
601 1.5.6.2 he * recover the slot number and status code.
602 1.5.6.2 he *
603 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
604 1.5.6.2 he */
605 1.5.6.2 he static int
606 1.5.6.2 he mlx_v5_findcomplete(struct mlx_softc *mlx, u_int *slot, u_int *status)
607 1.5.6.2 he {
608 1.5.6.2 he
609 1.5.6.2 he /* Status available? */
610 1.5.6.2 he if ((mlx_inb(mlx, MLX_V5REG_ODB) & MLX_V5_ODB_HWSAVAIL) != 0) {
611 1.5.6.2 he *slot = mlx_inb(mlx, MLX_V5REG_STATUS_IDENT);
612 1.5.6.2 he *status = mlx_inw(mlx, MLX_V5REG_STATUS);
613 1.5.6.2 he
614 1.5.6.2 he /* Acknowledge completion. */
615 1.5.6.2 he mlx_outb(mlx, MLX_V5REG_ODB, MLX_V5_ODB_HWMBOX_ACK);
616 1.5.6.2 he mlx_outb(mlx, MLX_V5REG_IDB, MLX_V5_IDB_SACK);
617 1.5.6.2 he return (1);
618 1.5.6.2 he }
619 1.5.6.2 he
620 1.5.6.2 he return (0);
621 1.5.6.2 he }
622 1.5.6.2 he
623 1.5.6.2 he /*
624 1.5.6.2 he * Enable/disable interrupts as requested.
625 1.5.6.2 he *
626 1.5.6.2 he * Must be called at splbio or in a fashion that prevents reentry.
627 1.5.6.2 he */
628 1.5.6.2 he static void
629 1.5.6.2 he mlx_v5_intaction(struct mlx_softc *mlx, int action)
630 1.5.6.2 he {
631 1.5.6.2 he u_int8_t ier;
632 1.5.6.2 he
633 1.5.6.2 he if (!action)
634 1.5.6.2 he ier = 0xff & MLX_V5_IE_DISINT;
635 1.5.6.2 he else
636 1.5.6.2 he ier = 0xff & ~MLX_V5_IE_DISINT;
637 1.5.6.2 he
638 1.5.6.2 he mlx_outb(mlx, MLX_V5REG_IE, ier);
639 1.5.6.2 he }
640 1.5.6.2 he
641 1.5.6.2 he /*
642 1.5.6.2 he * Poll for firmware error codes during controller initialisation.
643 1.5.6.2 he *
644 1.5.6.2 he * Returns 0 if initialisation is complete, 1 if still in progress but no
645 1.5.6.2 he * error has been fetched, 2 if an error has been retrieved.
646 1.5.6.2 he */
647 1.5.6.2 he static int
648 1.5.6.2 he mlx_v5_fw_handshake(struct mlx_softc *mlx, int *error, int *param1, int *param2)
649 1.5.6.2 he {
650 1.5.6.2 he u_int8_t fwerror;
651 1.5.6.2 he
652 1.5.6.2 he /* First time around, clear any hardware completion status. */
653 1.5.6.2 he if ((mlx->mlx_flags & MLXF_FW_INITTED) == 0) {
654 1.5.6.2 he mlx_outb(mlx, MLX_V5REG_IDB, MLX_V5_IDB_SACK);
655 1.5.6.2 he DELAY(1000);
656 1.5.6.2 he mlx->mlx_flags |= MLXF_FW_INITTED;
657 1.5.6.2 he }
658 1.5.6.2 he
659 1.5.6.2 he /* Init in progress? */
660 1.5.6.2 he if ((mlx_inb(mlx, MLX_V5REG_IDB) & MLX_V5_IDB_INIT_DONE) != 0)
661 1.5.6.2 he return (0);
662 1.5.6.2 he
663 1.5.6.2 he /* Test for error value. */
664 1.5.6.2 he fwerror = mlx_inb(mlx, MLX_V5REG_FWERROR);
665 1.5.6.2 he if ((fwerror & MLX_V5_FWERROR_PEND) == 0)
666 1.5.6.2 he return (1);
667 1.5.6.2 he
668 1.5.6.2 he /* Mask status pending bit, fetch status. */
669 1.5.6.2 he *error = fwerror & ~MLX_V5_FWERROR_PEND;
670 1.5.6.2 he *param1 = mlx_inb(mlx, MLX_V5REG_FWERROR_PARAM1);
671 1.5.6.2 he *param2 = mlx_inb(mlx, MLX_V5REG_FWERROR_PARAM2);
672 1.5.6.2 he
673 1.5.6.2 he /* Acknowledge. */
674 1.5.6.2 he mlx_outb(mlx, MLX_V5REG_FWERROR, 0xff);
675 1.5.6.2 he
676 1.5.6.2 he return (2);
677 1.5.6.2 he }
678