summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorAlexander Yurchenko <grange@cvs.openbsd.org>2004-12-22 12:02:48 +0000
committerAlexander Yurchenko <grange@cvs.openbsd.org>2004-12-22 12:02:48 +0000
commit447d7f1539a230f93ad9916ff4e453a6393e27c1 (patch)
tree1fdaa13326a8cc09e6c2d9dd2b7312bea3281071 /sys/dev
parentdc8b73a929338f8bcf900dc6bd5fecda5acf9e8f (diff)
Use vfs firmware loader for fxp(4) interrupt coalescing microcode.
Initial work by Dmitry Bogdan <bogdan@eastonline.ru> with a help from me and Theo. ok deraadt@
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ic/fxp.c66
-rw-r--r--sys/dev/microcode/Makefile4
-rw-r--r--sys/dev/microcode/fxp/Makefile27
-rw-r--r--sys/dev/microcode/fxp/build.c65
-rw-r--r--sys/dev/microcode/fxp/fxp-license39
5 files changed, 162 insertions, 39 deletions
diff --git a/sys/dev/ic/fxp.c b/sys/dev/ic/fxp.c
index 0d738c053fb..ec23490c3c6 100644
--- a/sys/dev/ic/fxp.c
+++ b/sys/dev/ic/fxp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fxp.c,v 1.61 2004/12/08 22:35:13 pascoe Exp $ */
+/* $OpenBSD: fxp.c,v 1.62 2004/12/22 12:02:47 grange Exp $ */
/* $NetBSD: if_fxp.c,v 1.2 1997/06/05 02:01:55 thorpej Exp $ */
/*
@@ -1826,48 +1826,29 @@ fxp_mc_setup(sc, doit)
#ifndef SMALL_KERNEL
#include <dev/microcode/fxp/rcvbundl.h>
-
-const u_int32_t fxp_ucode_d101a[] = D101_A_RCVBUNDLE_UCODE;
-const u_int32_t fxp_ucode_d101b0[] = D101_B0_RCVBUNDLE_UCODE;
-const u_int32_t fxp_ucode_d101ma[] = D101M_B_RCVBUNDLE_UCODE;
-const u_int32_t fxp_ucode_d101s[] = D101S_RCVBUNDLE_UCODE;
-const u_int32_t fxp_ucode_d102[] = D102_B_RCVBUNDLE_UCODE;
-const u_int32_t fxp_ucode_d102c[] = D102_C_RCVBUNDLE_UCODE;
-
-#define UCODE(x) sizeof(x) / sizeof(u_int32_t), x
-
struct ucode {
u_int16_t revision;
u_int16_t int_delay_offset;
u_int16_t bundle_max_offset;
- u_int16_t length;
- const u_int32_t *ucode;
+ const char *uname;
} const ucode_table[] = {
- { FXP_REV_82558_A4,
- D101_CPUSAVER_DWORD, 0,
- UCODE(fxp_ucode_d101a) },
+ { FXP_REV_82558_A4, D101_CPUSAVER_DWORD, 0, "fxp-d101a" },
- { FXP_REV_82558_B0,
- D101_CPUSAVER_DWORD, 0,
- UCODE(fxp_ucode_d101b0), },
+ { FXP_REV_82558_B0, D101_CPUSAVER_DWORD, 0, "fxp-d101b0" },
- { FXP_REV_82559_A0,
- D101M_CPUSAVER_DWORD, D101M_CPUSAVER_BUNDLE_MAX_DWORD,
- UCODE(fxp_ucode_d101ma) },
+ { FXP_REV_82559_A0, D101M_CPUSAVER_DWORD,
+ D101M_CPUSAVER_BUNDLE_MAX_DWORD, "fxp-d101ma" },
- { FXP_REV_82559S_A,
- D101S_CPUSAVER_DWORD, D101S_CPUSAVER_BUNDLE_MAX_DWORD,
- UCODE(fxp_ucode_d101s) },
+ { FXP_REV_82559S_A, D101S_CPUSAVER_DWORD,
+ D101S_CPUSAVER_BUNDLE_MAX_DWORD, "fxp-d101s" },
- { FXP_REV_82550,
- D102_B_CPUSAVER_DWORD, D102_B_CPUSAVER_BUNDLE_MAX_DWORD,
- UCODE(fxp_ucode_d102) },
+ { FXP_REV_82550, D102_B_CPUSAVER_DWORD,
+ D102_B_CPUSAVER_BUNDLE_MAX_DWORD, "fxp-d102" },
- { FXP_REV_82550_C,
- D102_C_CPUSAVER_DWORD, D102_C_CPUSAVER_BUNDLE_MAX_DWORD,
- UCODE(fxp_ucode_d102c) },
+ { FXP_REV_82550_C, D102_C_CPUSAVER_DWORD,
+ D102_C_CPUSAVER_BUNDLE_MAX_DWORD, "fxp-d102c" },
- { 0, 0, 0, 0, NULL }
+ { 0, 0, 0, NULL }
};
void
@@ -1875,22 +1856,31 @@ fxp_load_ucode(struct fxp_softc *sc)
{
const struct ucode *uc;
struct fxp_cb_ucode *cbp = &sc->sc_ctrl->u.code;
- int i;
+ int i, error;
+ u_int32_t *ucode_buf;
+ size_t ucode_len;
if (sc->sc_flags & FXPF_UCODE)
return;
- for (uc = ucode_table; uc->ucode != NULL; uc++)
+ for (uc = ucode_table; uc->revision != 0; uc++)
if (sc->sc_revision == uc->revision)
break;
- if (uc->ucode == NULL)
+ if (uc->revision == NULL)
return; /* no ucode for this chip is found */
+ error = loadfirmware(uc->uname, (u_char **)&ucode_buf, &ucode_len);
+ if (error) {
+ printf("%s: failed loadfirmware of file %s: errno %d\n",
+ sc->sc_dev.dv_xname, uc->uname, error);
+ return;
+ }
+
cbp->cb_status = 0;
cbp->cb_command = htole16(FXP_CB_COMMAND_UCODE|FXP_CB_COMMAND_EL);
cbp->link_addr = 0xffffffff; /* (no) next command */
- for (i = 0; i < uc->length; i++)
- cbp->ucode[i] = htole32(uc->ucode[i]);
+ for (i = 0; i < (ucode_len / sizeof(u_int32_t)); i++)
+ cbp->ucode[i] = ucode_buf[i];
if (uc->int_delay_offset)
*((u_int16_t *)&cbp->ucode[uc->int_delay_offset]) =
@@ -1918,6 +1908,7 @@ fxp_load_ucode(struct fxp_softc *sc)
} while (((cbp->cb_status & htole16(FXP_CB_STATUS_C)) == 0) && --i);
if (i == 0) {
printf("%s: timeout loading microcode\n", sc->sc_dev.dv_xname);
+ free(ucode_buf, M_DEVBUF);
return;
}
@@ -1931,6 +1922,7 @@ fxp_load_ucode(struct fxp_softc *sc)
printf("\n");
#endif
+ free(ucode_buf, M_DEVBUF);
sc->sc_flags |= FXPF_UCODE;
}
#endif /* SMALL_KERNEL */
diff --git a/sys/dev/microcode/Makefile b/sys/dev/microcode/Makefile
index ff73b6fe833..ba49932b5db 100644
--- a/sys/dev/microcode/Makefile
+++ b/sys/dev/microcode/Makefile
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile,v 1.9 2004/12/20 12:29:40 deraadt Exp $
+# $OpenBSD: Makefile,v 1.10 2004/12/22 12:02:47 grange Exp $
-SUBDIR= atmel tigon neomagic symbol kue typhoon uyap cirruslogic yds
+SUBDIR= atmel tigon neomagic symbol kue typhoon uyap cirruslogic yds fxp
.include <bsd.subdir.mk>
diff --git a/sys/dev/microcode/fxp/Makefile b/sys/dev/microcode/fxp/Makefile
new file mode 100644
index 00000000000..edf0f030c0a
--- /dev/null
+++ b/sys/dev/microcode/fxp/Makefile
@@ -0,0 +1,27 @@
+# $OpenBSD: Makefile,v 1.1 2004/12/22 12:02:47 grange Exp $
+
+NOPROG=
+NOMAN=
+
+# PCI capable systems only
+.if (${MACHINE} == "i386") || (${MACHINE} == "amd64") || \
+ (${MACHINE} == "alpha") || (${MACHINE} == "sparc64") || \
+ (${MACHINE_ARCH} == "powerpc") || (${MACHINE} == "cats") || \
+ (${MACHINE} == "hppa") || (${MACHINE} == "sgi")
+
+FIRM= fxp-d101a fxp-d101b0 fxp-d101ma fxp-d101s fxp-d102 fxp-d102c
+
+CLEANFILES+= ${FIRM} build
+
+all: build
+ ${.OBJDIR}/build
+
+afterinstall:
+ ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \
+ ${FIRM} ${DESTDIR}/etc/firmware
+ ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 644 \
+ ${.CURDIR}/fxp-license ${DESTDIR}/etc/firmware
+
+.endif
+
+.include <bsd.prog.mk>
diff --git a/sys/dev/microcode/fxp/build.c b/sys/dev/microcode/fxp/build.c
new file mode 100644
index 00000000000..c1488c60cbc
--- /dev/null
+++ b/sys/dev/microcode/fxp/build.c
@@ -0,0 +1,65 @@
+/* $OpenBSD: build.c,v 1.1 2004/12/22 12:02:47 grange Exp $ */
+
+/*
+ * Copyright (c) 2004 Theo de Raadt <deraadt@openbsd.org>
+ * Copyright (c) 2004 Dmitry Bogdan
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include "rcvbundl.h"
+
+const u_int32_t fxp_ucode_d101a[] = D101_A_RCVBUNDLE_UCODE;
+const u_int32_t fxp_ucode_d101b0[] = D101_B0_RCVBUNDLE_UCODE;
+const u_int32_t fxp_ucode_d101ma[] = D101M_B_RCVBUNDLE_UCODE;
+const u_int32_t fxp_ucode_d101s[] = D101S_RCVBUNDLE_UCODE;
+const u_int32_t fxp_ucode_d102[] = D102_B_RCVBUNDLE_UCODE;
+const u_int32_t fxp_ucode_d102c[] = D102_C_RCVBUNDLE_UCODE;
+
+#define UCODE(x) x, sizeof(x)
+
+static void
+output(const char *name, const u_int32_t *ucode, const int ucode_len)
+{
+ int fd, i;
+ u_int32_t dword;
+
+ printf("creating %s length %d (microcode: %d DWORDS)\n",
+ name, ucode_len, ucode_len / sizeof(u_int32_t));
+ fd = open(name, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+ if (fd == -1)
+ err(1, "%s", name);
+ for (i = 0; i < ucode_len / sizeof(u_int32_t); i++) {
+ dword = htole32(ucode[i]);
+ write(fd, &dword, sizeof(dword));
+ }
+ close(fd);
+}
+
+int
+main(int argc, char *argv[])
+{
+ output("fxp-d101a", UCODE(fxp_ucode_d101a));
+ output("fxp-d101b0", UCODE(fxp_ucode_d101b0));
+ output("fxp-d101ma", UCODE(fxp_ucode_d101ma));
+ output("fxp-d101s", UCODE(fxp_ucode_d101s));
+ output("fxp-d102", UCODE(fxp_ucode_d102));
+ output("fxp-d102c", UCODE(fxp_ucode_d102c));
+
+ return (0);
+}
diff --git a/sys/dev/microcode/fxp/fxp-license b/sys/dev/microcode/fxp/fxp-license
new file mode 100644
index 00000000000..5d331e2b69c
--- /dev/null
+++ b/sys/dev/microcode/fxp/fxp-license
@@ -0,0 +1,39 @@
+Copyright (c) 1999-2001, Intel Corporation
+
+All rights reserved.
+
+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. Neither the name of Intel Corporation nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``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 CONTRIBUTORS 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.
+
+The following files are under this license:
+
+fxp-d101a
+fxp-d101b0
+fxp-d101ma
+fxp-d101s
+fxp-d102
+fxp-d102c
+
+These files are needed by various models of fxp(4) devices.