Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/usb Driver for Realtek RTL8187/RTL8187B 802.11b/g US...
details: https://anonhg.NetBSD.org/src/rev/62597437fe7a
branches: trunk
changeset: 779454:62597437fe7a
user: christos <christos%NetBSD.org@localhost>
date: Tue May 29 14:06:23 2012 +0000
description:
Driver for Realtek RTL8187/RTL8187B 802.11b/g USB wireless adapter, from
OpenBSD by jmcneill.
diffstat:
sys/dev/usb/files.usb | 7 +-
sys/dev/usb/if_urtw.c | 4089 ++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/usb/if_urtwreg.h | 400 ++++
3 files changed, 4495 insertions(+), 1 deletions(-)
diffs (truncated from 4515 to 300 lines):
diff -r ea4c262e104c -r 62597437fe7a sys/dev/usb/files.usb
--- a/sys/dev/usb/files.usb Tue May 29 14:05:01 2012 +0000
+++ b/sys/dev/usb/files.usb Tue May 29 14:06:23 2012 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.usb,v 1.121 2012/03/25 00:11:16 nonaka Exp $
+# $NetBSD: files.usb,v 1.122 2012/05/29 14:06:23 christos Exp $
#
# Config file and device description for machine-independent USB code.
# Included by ports that need it. Ports that use it must provide
@@ -415,3 +415,8 @@
device urtwn: ether, ifnet, arp, wlan, firmload
attach urtwn at usbdevif
file dev/usb/if_urtwn.c urtwn
+
+# Realtek RTL8187/RTL8187B 802.11b/g USB wireless adapter
+device urtw: ether, ifnet, arp, wlan
+attach urtw at usbdevif
+file dev/usb/if_urtw.c urtw
diff -r ea4c262e104c -r 62597437fe7a sys/dev/usb/if_urtw.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/if_urtw.c Tue May 29 14:06:23 2012 +0000
@@ -0,0 +1,4089 @@
+/* $NetBSD: if_urtw.c,v 1.1 2012/05/29 14:06:23 christos Exp $ */
+/* $OpenBSD: if_urtw.c,v 1.39 2011/07/03 15:47:17 matthew Exp $ */
+
+/*-
+ * Copyright (c) 2009 Martynas Venckus <martynas%openbsd.org@localhost>
+ * Copyright (c) 2008 Weongyo Jeong <weongyo%FreeBSD.org@localhost>
+ *
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_urtw.c,v 1.1 2012/05/29 14:06:23 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/sockio.h>
+#include <sys/proc.h>
+#include <sys/mbuf.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/callout.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+
+#include <machine/endian.h>
+#include <net/bpf.h>
+#include <net/if.h>
+#include <net/if_arp.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+#include <net/if_types.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/if_inarp.h>
+#include <netinet/ip.h>
+
+#include <net80211/ieee80211_var.h>
+#include <net80211/ieee80211_radiotap.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdi_util.h>
+#include <dev/usb/usbdivar.h>
+#include <dev/usb/usbdevs.h>
+
+#include "if_urtwreg.h"
+
+#ifdef USB_DEBUG
+#define URTW_DEBUG
+#endif
+
+#ifdef URTW_DEBUG
+#define DPRINTF(x) do { if (urtw_debug) printf x; } while (0)
+#define DPRINTFN(n, x) do { if (urtw_debug >= (n)) printf x; } while (0)
+int urtw_debug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n, x)
+#endif
+
+/*
+ * Recognized device vendors/products.
+ */
+static const struct urtw_type {
+ struct usb_devno dev;
+ uint8_t rev;
+} urtw_devs[] = {
+#define URTW_DEV_RTL8187(v, p) \
+ { { USB_VENDOR_##v, USB_PRODUCT_##v##_##p }, URTW_HWREV_8187 }
+#define URTW_DEV_RTL8187B(v, p) \
+ { { USB_VENDOR_##v, USB_PRODUCT_##v##_##p }, URTW_HWREV_8187B }
+ /* Realtek RTL8187 devices. */
+ URTW_DEV_RTL8187(ASUSTEK, P5B_WIFI),
+ URTW_DEV_RTL8187(DICKSMITH, RTL8187),
+ URTW_DEV_RTL8187(LINKSYS4, WUSB54GC_2),
+ URTW_DEV_RTL8187(LOGITEC, RTL8187),
+ URTW_DEV_RTL8187(NETGEAR, WG111V2),
+ URTW_DEV_RTL8187(REALTEK, RTL8187),
+ URTW_DEV_RTL8187(SITECOMEU, WL168V1),
+ URTW_DEV_RTL8187(SPHAIRON, RTL8187),
+ URTW_DEV_RTL8187(SURECOM, EP9001G2A),
+ /* Realtek RTL8187B devices. */
+ URTW_DEV_RTL8187B(BELKIN, F5D7050E),
+ URTW_DEV_RTL8187B(NETGEAR, WG111V3),
+ URTW_DEV_RTL8187B(REALTEK, RTL8187B_0),
+ URTW_DEV_RTL8187B(REALTEK, RTL8187B_1),
+ URTW_DEV_RTL8187B(REALTEK, RTL8187B_2),
+ URTW_DEV_RTL8187B(SITECOMEU, WL168V4)
+#undef URTW_DEV_RTL8187
+#undef URTW_DEV_RTL8187B
+};
+#define urtw_lookup(v, p) \
+ ((const struct urtw_type *)usb_lookup(urtw_devs, v, p))
+
+/*
+ * Helper read/write macros.
+ */
+#define urtw_read8_m(sc, val, data) do { \
+ error = urtw_read8_c(sc, val, data, 0); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_read8_idx_m(sc, val, data, idx) do { \
+ error = urtw_read8_c(sc, val, data, idx); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_write8_m(sc, val, data) do { \
+ error = urtw_write8_c(sc, val, data, 0); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_write8_idx_m(sc, val, data, idx) do { \
+ error = urtw_write8_c(sc, val, data, idx); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_read16_m(sc, val, data) do { \
+ error = urtw_read16_c(sc, val, data, 0); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_read16_idx_m(sc, val, data, idx) do { \
+ error = urtw_read16_c(sc, val, data, idx); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_write16_m(sc, val, data) do { \
+ error = urtw_write16_c(sc, val, data, 0); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_write16_idx_m(sc, val, data, idx) do { \
+ error = urtw_write16_c(sc, val, data, idx); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_read32_m(sc, val, data) do { \
+ error = urtw_read32_c(sc, val, data, 0); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_read32_idx_m(sc, val, data, idx) do { \
+ error = urtw_read32_c(sc, val, data, idx); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_write32_m(sc, val, data) do { \
+ error = urtw_write32_c(sc, val, data, 0); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_write32_idx_m(sc, val, data, idx) do { \
+ error = urtw_write32_c(sc, val, data, idx); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_8187_write_phy_ofdm(sc, val, data) do { \
+ error = urtw_8187_write_phy_ofdm_c(sc, val, data); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_8187_write_phy_cck(sc, val, data) do { \
+ error = urtw_8187_write_phy_cck_c(sc, val, data); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+#define urtw_8225_write(sc, val, data) do { \
+ error = urtw_8225_write_c(sc, val, data); \
+ if (error != 0) \
+ goto fail; \
+} while (0)
+
+struct urtw_pair {
+ uint32_t reg;
+ uint32_t val;
+};
+
+struct urtw_pair_idx {
+ uint8_t reg;
+ uint8_t val;
+ uint8_t idx;
+};
+
+static struct urtw_pair_idx urtw_8187b_regtbl[] = {
+ { 0xf0, 0x32, 0 }, { 0xf1, 0x32, 0 }, { 0xf2, 0x00, 0 },
+ { 0xf3, 0x00, 0 }, { 0xf4, 0x32, 0 }, { 0xf5, 0x43, 0 },
+ { 0xf6, 0x00, 0 }, { 0xf7, 0x00, 0 }, { 0xf8, 0x46, 0 },
+ { 0xf9, 0xa4, 0 }, { 0xfa, 0x00, 0 }, { 0xfb, 0x00, 0 },
+ { 0xfc, 0x96, 0 }, { 0xfd, 0xa4, 0 }, { 0xfe, 0x00, 0 },
+ { 0xff, 0x00, 0 },
+
+ { 0x58, 0x4b, 1 }, { 0x59, 0x00, 1 }, { 0x5a, 0x4b, 1 },
+ { 0x5b, 0x00, 1 }, { 0x60, 0x4b, 1 }, { 0x61, 0x09, 1 },
+ { 0x62, 0x4b, 1 }, { 0x63, 0x09, 1 }, { 0xce, 0x0f, 1 },
+ { 0xcf, 0x00, 1 }, { 0xe0, 0xff, 1 }, { 0xe1, 0x0f, 1 },
+ { 0xe2, 0x00, 1 }, { 0xf0, 0x4e, 1 }, { 0xf1, 0x01, 1 },
+ { 0xf2, 0x02, 1 }, { 0xf3, 0x03, 1 }, { 0xf4, 0x04, 1 },
+ { 0xf5, 0x05, 1 }, { 0xf6, 0x06, 1 }, { 0xf7, 0x07, 1 },
+ { 0xf8, 0x08, 1 },
+
+ { 0x4e, 0x00, 2 }, { 0x0c, 0x04, 2 }, { 0x21, 0x61, 2 },
+ { 0x22, 0x68, 2 }, { 0x23, 0x6f, 2 }, { 0x24, 0x76, 2 },
+ { 0x25, 0x7d, 2 }, { 0x26, 0x84, 2 }, { 0x27, 0x8d, 2 },
+ { 0x4d, 0x08, 2 }, { 0x50, 0x05, 2 }, { 0x51, 0xf5, 2 },
+ { 0x52, 0x04, 2 }, { 0x53, 0xa0, 2 }, { 0x54, 0x1f, 2 },
+ { 0x55, 0x23, 2 }, { 0x56, 0x45, 2 }, { 0x57, 0x67, 2 },
+ { 0x58, 0x08, 2 }, { 0x59, 0x08, 2 }, { 0x5a, 0x08, 2 },
+ { 0x5b, 0x08, 2 }, { 0x60, 0x08, 2 }, { 0x61, 0x08, 2 },
+ { 0x62, 0x08, 2 }, { 0x63, 0x08, 2 }, { 0x64, 0xcf, 2 },
+ { 0x72, 0x56, 2 }, { 0x73, 0x9a, 2 },
+
+ { 0x34, 0xf0, 0 }, { 0x35, 0x0f, 0 }, { 0x5b, 0x40, 0 },
+ { 0x84, 0x88, 0 }, { 0x85, 0x24, 0 }, { 0x88, 0x54, 0 },
+ { 0x8b, 0xb8, 0 }, { 0x8c, 0x07, 0 }, { 0x8d, 0x00, 0 },
+ { 0x94, 0x1b, 0 }, { 0x95, 0x12, 0 }, { 0x96, 0x00, 0 },
+ { 0x97, 0x06, 0 }, { 0x9d, 0x1a, 0 }, { 0x9f, 0x10, 0 },
+ { 0xb4, 0x22, 0 }, { 0xbe, 0x80, 0 }, { 0xdb, 0x00, 0 },
+ { 0xee, 0x00, 0 }, { 0x91, 0x03, 0 },
+
+ { 0x4c, 0x00, 2 }, { 0x9f, 0x00, 3 }, { 0x8c, 0x01, 0 },
+ { 0x8d, 0x10, 0 }, { 0x8e, 0x08, 0 }, { 0x8f, 0x00, 0 }
+};
+
+static uint8_t urtw_8225_agc[] = {
+ 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9d, 0x9c, 0x9b,
+ 0x9a, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91, 0x90,
+ 0x8f, 0x8e, 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 0x85,
+ 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a,
+ 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f,
+ 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24,
+ 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19,
+ 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e,
+ 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
+ 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01
+};
+
+static uint32_t urtw_8225_channel[] = {
+ 0x0000, /* dummy channel 0 */
+ 0x085c, /* 1 */
+ 0x08dc, /* 2 */
+ 0x095c, /* 3 */
+ 0x09dc, /* 4 */
+ 0x0a5c, /* 5 */
+ 0x0adc, /* 6 */
+ 0x0b5c, /* 7 */
+ 0x0bdc, /* 8 */
+ 0x0c5c, /* 9 */
+ 0x0cdc, /* 10 */
+ 0x0d5c, /* 11 */
+ 0x0ddc, /* 12 */
+ 0x0e5c, /* 13 */
+ 0x0f72, /* 14 */
+};
+
+static uint8_t urtw_8225_gain[] = {
+ 0x23, 0x88, 0x7c, 0xa5, /* -82dbm */
+ 0x23, 0x88, 0x7c, 0xb5, /* -82dbm */
+ 0x23, 0x88, 0x7c, 0xc5, /* -82dbm */
+ 0x33, 0x80, 0x79, 0xc5, /* -78dbm */
Home |
Main Index |
Thread Index |
Old Index