1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-12-24 05:11:46 +02:00

[package] broadcom-wl: make it work on the RT-N16 and other device using the BCMA bus

- refresh and reorder patches
	- introduce a unified BCMA/SSB glue driver to accomodate for both bus types on brcm47xx
	- extend wlunbind init script to detach device from bcma-pci-bridge as well


git-svn-id: svn://svn.openwrt.org/openwrt/trunk@27751 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
jow 2011-07-24 14:10:39 +00:00
parent 35fc833d4b
commit df14a3269c
9 changed files with 568 additions and 10 deletions

View File

@ -10,7 +10,7 @@ include $(INCLUDE_DIR)/kernel.mk
PKG_NAME:=broadcom-wl
PKG_VERSION:=5.10.56.27.3
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)_$(ARCH).tar.bz2
PKG_SOURCE_URL:=http://downloads.openwrt.org/sources
@ -34,8 +34,8 @@ define KernelPackage/brcm-wl/Default
SECTION:=kernel
DEPENDS:=@TARGET_brcm47xx||TARGET_brcm63xx +wireless-tools
TITLE:=Kernel driver for BCM43xx chipsets
FILES:=$(PKG_BUILD_DIR)/driver$(1)/wl.ko
AUTOLOAD:=$(call AutoLoad,30,wl)
FILES:=$(PKG_BUILD_DIR)/driver$(1)/wl.ko $(PKG_BUILD_DIR)/glue/wl_glue.ko
AUTOLOAD:=$(call AutoLoad,30,wl_glue wl)
endef
define KernelPackage/brcm-wl/Default/description
@ -100,6 +100,7 @@ MAKE_KMOD := $(MAKE) -C "$(LINUX_DIR)" \
define Build/Prepare
$(call Build/Prepare/Default)
$(CP) $(PKG_BUILD_DIR)/driver $(PKG_BUILD_DIR)/driver-mini
$(CP) ./src/glue $(PKG_BUILD_DIR)/glue
endef
define Build/Compile
@ -115,6 +116,11 @@ define Build/Compile
BUILD_TYPE="wl_apsta_mini" \
modules
# Compile glue driver
$(MAKE_KMOD) -C "$(LINUX_DIR)" \
SUBDIRS="$(PKG_BUILD_DIR)/glue" \
modules
# Compile libshared
$(MAKE) -C $(PKG_BUILD_DIR)/shared \
$(TARGET_CONFIGURE_OPTS) \

View File

@ -1,17 +1,18 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2010 OpenWrt.org
# Copyright (C) 2010-2011 OpenWrt.org
START=09
boot() {
local sysfs=/sys/bus/pci/drivers/b43-pci-bridge
unbind_driver() {
local driver="$1"
local sysfs="/sys/bus/pci/drivers/$driver"
if [ -d "$sysfs" ]; then
local lnk
for lnk in $sysfs/*; do
[ -h "$lnk" ] || continue
case "${lnk##*/}" in
*:*:*.*)
logger "Unbinding WL PCI device ${lnk##*/} from B43 SSB bridge"
logger "Unbinding WL PCI device ${lnk##*/} from $driver"
echo -n "${lnk##*/}" > "$sysfs/unbind"
;;
esac
@ -19,5 +20,10 @@ boot() {
fi
}
boot() {
unbind_driver b43-pci-bridge
unbind_driver bcma-pci-bridge
}
start() { :; }
stop() { :; }

View File

@ -11,8 +11,8 @@ Signed-off-by: George Kashperko <george@znau.edu.ua>
---
driver/linux_osl.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
--- broadcom-wl-5.10.56.27.3.orig/driver/linux_osl.c 2011-05-17 23:40:00.000000000 +0300
+++ broadcom-wl-5.10.56.27.3/driver/linux_osl.c 2011-05-17 23:46:01.000000000 +0300
--- a/driver/linux_osl.c
+++ b/driver/linux_osl.c
@@ -25,6 +25,9 @@
#include <asm/paccess.h>
#endif /* mips */

View File

@ -0,0 +1,184 @@
--- a/driver/wl_linux.c
+++ b/driver/wl_linux.c
@@ -85,10 +85,9 @@ typedef void wlc_hw_info_t;
#include <bcmjtag.h>
#endif /* BCMJTAG */
-
-#ifdef CONFIG_SSB
-#include <linux/ssb/ssb.h>
-#endif
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
+#include <wl_glue.h>
+#endif /* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
/* Linux wireless extension support */
#ifdef CONFIG_WIRELESS_EXT
@@ -997,62 +996,32 @@ static struct pci_driver wl_pci_driver =
#endif /* CONFIG_PCI */
#endif
+#ifdef BCMJTAG
+static bcmjtag_driver_t wl_jtag_driver = {
+ wl_jtag_probe,
+ wl_jtag_detach,
+ wl_jtag_poll,
+ };
+#endif /* BCMJTAG */
-static int wl_ssb_probe(struct ssb_device *dev, const struct ssb_device_id *id)
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
+static void * glue_attach_cb(u16 vendor, u16 device,
+ ulong mmio, void *dev, u32 irq)
{
- wl_info_t *wl;
- void *mmio;
-
- if (dev->bus->bustype != SSB_BUSTYPE_SSB) {
- printk("Attaching to SSB behind PCI is not supported. Please remove the b43 ssb bridge\n");
- return -EINVAL;
- }
-
- mmio = (void *) 0x18000000 + dev->core_index * 0x1000;
- wl = wl_attach(id->vendor, id->coreid, (ulong) mmio, SI_BUS, dev, dev->irq);
- if (!wl) {
- printk("wl_attach failed\n");
- return -ENODEV;
- }
-
- ssb_set_drvdata(dev, wl);
-
- return 0;
+ return wl_attach(vendor, device, mmio, SI_BUS, dev, irq);
}
-static void wl_ssb_remove(struct ssb_device *dev)
+static void glue_remove_cb(void *wldev)
{
- wl_info_t *wl = (wl_info_t *) ssb_get_drvdata(dev);
+ wl_info_t *wl = (wl_info_t *)wldev;
WL_LOCK(wl);
WL_APSTA_UPDN(("wl%d (%s): wl_remove() -> wl_down()\n", wl->pub->unit, wl->dev->name));
wl_down(wl);
WL_UNLOCK(wl);
wl_free(wl);
- ssb_set_drvdata(dev, NULL);
}
-
-static const struct ssb_device_id wl_ssb_tbl[] = {
- SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, SSB_ANY_REV),
- SSB_DEVTABLE_END
-};
-
-#ifdef CONFIG_SSB
-static struct ssb_driver wl_ssb_driver = {
- .name = KBUILD_MODNAME,
- .id_table = wl_ssb_tbl,
- .probe = wl_ssb_probe,
- .remove = wl_ssb_remove,
-};
-#endif
-
-#ifdef BCMJTAG
-static bcmjtag_driver_t wl_jtag_driver = {
- wl_jtag_probe,
- wl_jtag_detach,
- wl_jtag_poll,
- };
-#endif /* BCMJTAG */
+#endif/* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
/**
@@ -1067,11 +1036,13 @@ wl_module_init(void)
{
int error = -ENODEV;
-#ifdef CONFIG_SSB
- error = ssb_driver_register(&wl_ssb_driver);
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
+ wl_glue_set_attach_callback(&glue_attach_cb);
+ wl_glue_set_remove_callback(&glue_remove_cb);
+ error = wl_glue_register();
if (error)
return error;
-#endif /* CONFIG_SSB */
+#endif /* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
#ifdef CONFIG_PCI
error = pci_register_driver(&wl_pci_driver);
@@ -1082,7 +1053,9 @@ wl_module_init(void)
return 0;
error_pci:
- ssb_driver_unregister(&wl_ssb_driver);
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
+ wl_glue_unregister();
+#endif /* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
return error;
}
@@ -1099,9 +1072,9 @@ wl_module_exit(void)
#ifdef CONFIG_PCI
pci_unregister_driver(&wl_pci_driver);
#endif /* CONFIG_PCI */
-#ifdef CONFIG_SSB
- ssb_driver_unregister(&wl_ssb_driver);
-#endif /* CONFIG_SSB */
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
+ wl_glue_unregister();
+#endif /* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
}
module_init(wl_module_init);
--- a/driver/linux_osl.c
+++ b/driver/linux_osl.c
@@ -25,9 +25,9 @@
#include <asm/paccess.h>
#endif /* mips */
#include <pcicfg.h>
-#ifdef CONFIG_SSB
-#include <linux/ssb/ssb.h>
-#endif
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
+#include <wl_glue.h>
+#endif /* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
#define PCI_CFG_RETRY 10
@@ -370,15 +370,17 @@ osl_dma_consistent_align(void)
static struct device *
osl_get_dmadev(osl_t *osh)
{
-#ifdef CONFIG_SSB
+#if defined(CONFIG_SSB) || defined(CONFIG_BCMA)
if (osh->bustype == SI_BUS) {
- /* This can be SiliconBackplane emulated as pci with Broadcom or
- * ssb device. Less harmful is to check for pci_bus_type and if
- * no match then assume we got ssb */
+ /* This can be SiliconBackplane emulated as pci with Broadcom,
+ * ssb or bcma device. Less harmful is to check for pci_bus_type and if
+ * no match then assume we got either ssb or bcma */
if (((struct pci_dev *)osh->pdev)->dev.bus != &pci_bus_type)
- return ((struct ssb_device *)osh->pdev)->dma_dev;
+ {
+ return wl_glue_get_dmadev(osh->pdev);
+ }
}
-#endif
+#endif /* defined(CONFIG_SSB) || defined(CONFIG_BCMA) */
return &((struct pci_dev *)osh->pdev)->dev;
}
--- a/driver/Makefile
+++ b/driver/Makefile
@@ -1,7 +1,7 @@
BUILD_TYPE=wl_apsta
include $(src)/$(BUILD_TYPE)/buildflags.mk
-EXTRA_CFLAGS += -I$(src)/include -I$(src) -DBCMDRIVER $(WLFLAGS)
+EXTRA_CFLAGS += -I$(src)/include -I$(src) -I$(realpath $(src)/../glue) -DBCMDRIVER $(WLFLAGS)
wl-objs := $(BUILD_TYPE)/wl_prebuilt.o wl_iw.o wl_linux.o linux_osl.o siutils.o aiutils.o hndpmu.o bcmutils.o sbutils.o nicpci.o hnddma.o bcmsrom.o nvram_stub.o

View File

@ -23,7 +23,7 @@
/*
* Apply CRC over SROM content regardless SROM is present or not,
* and use variable <devpath>sromrev's existance in flash to decide
@@ -2120,6 +2130,58 @@ BCMATTACHFN(initvars_srom_pci)(si_t *sih
@@ -2120,6 +2129,58 @@ BCMATTACHFN(initvars_srom_pci)(si_t *sih
goto varscont;
}

View File

@ -0,0 +1,17 @@
#
# Makefile for wl_glue driver
#
# Copyright (C) 2011 Jo-Philipp Wich <jow@openwrt.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
obj-m := wl_glue.o
ifeq ($(MAKING_MODULES),1)
-include $(TOPDIR)/Rules.make
endif

View File

@ -0,0 +1,323 @@
/*
* wl_glue.c: Broadcom WL support module providing a unified SSB/BCMA handling.
* Copyright (C) 2011 Jo-Philipp Wich <jow@openwrt.org>
*/
#include "wl_glue.h"
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#ifdef CONFIG_BCM47XX
#include <bcm47xx.h>
#endif
#ifdef CONFIG_SSB
#include <linux/ssb/ssb.h>
#endif
#ifdef CONFIG_BCMA
#include <linux/bcma/bcma.h>
#endif
MODULE_AUTHOR("Jo-Philipp Wich (jow@openwrt.org)");
MODULE_DESCRIPTION("Broadcom WL SSB/BCMA compatibility layer");
MODULE_LICENSE("GPL");
static wl_glue_attach_cb_t attach_cb = NULL;
static wl_glue_remove_cb_t remove_cb = NULL;
static enum wl_glue_bus_type active_bus_type = WL_GLUE_BUS_TYPE_UNSPEC;
static int wl_glue_attached = 0;
#ifdef CONFIG_SSB
static int wl_glue_ssb_probe(struct ssb_device *dev, const struct ssb_device_id *id)
{
void *mmio;
void *wldev;
if (!attach_cb)
{
pr_err("No attach callback registered\n");
return -ENOSYS;
}
if (dev->bus->bustype != SSB_BUSTYPE_SSB)
{
pr_err("Attaching to SSB behind PCI is not supported. Please remove the b43 ssb bridge\n");
return -EINVAL;
}
mmio = (void *) 0x18000000 + dev->core_index * 0x1000;
wldev = attach_cb(id->vendor, id->coreid, (ulong)mmio, dev, dev->irq);
if (!wldev)
{
pr_err("The attach callback failed, SSB probe aborted\n");
return -ENODEV;
}
ssb_set_drvdata(dev, wldev);
return 0;
}
static void wl_glue_ssb_remove(struct ssb_device *dev)
{
void *wldev = ssb_get_drvdata(dev);
if (remove_cb)
remove_cb(wldev);
ssb_set_drvdata(dev, NULL);
}
static const struct ssb_device_id wl_glue_ssb_tbl[] = {
SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, SSB_ANY_REV),
SSB_DEVTABLE_END
};
static struct ssb_driver wl_glue_ssb_driver = {
.name = KBUILD_MODNAME,
.id_table = wl_glue_ssb_tbl,
.probe = wl_glue_ssb_probe,
.remove = wl_glue_ssb_remove,
};
#endif /* CONFIG_SSB */
#ifdef CONFIG_BCMA
static int wl_glue_bcma_probe(struct bcma_device *dev)
{
void *mmio;
void *wldev;
if (!attach_cb)
{
pr_err("No attach callback registered\n");
return -ENOSYS;
}
if (dev->bus->hosttype != BCMA_HOSTTYPE_SOC)
{
pr_err("Unsupported BCMA bus type %d\n", dev->bus->hosttype);
return -EINVAL;
}
/*
* NB:
* 0x18000000 = BCMA_ADDR_BASE
* 0x1000 = BCMA_CORE_SIZE
*/
mmio = (void *) 0x18000000 + dev->core_index * 0x1000;
wldev = attach_cb(dev->id.manuf, dev->id.id, (ulong)mmio, dev, dev->irq);
if (!wldev)
{
pr_err("The attach callback failed, BCMA probe aborted\n");
return -ENODEV;
}
bcma_set_drvdata(dev, wldev);
return 0;
}
static void wl_glue_bcma_remove(struct bcma_device *dev)
{
void *wldev = bcma_get_drvdata(dev);
if (remove_cb)
remove_cb(wldev);
bcma_set_drvdata(dev, NULL);
}
static const struct bcma_device_id wl_glue_bcma_tbl[] = {
BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, BCMA_ANY_REV, BCMA_ANY_CLASS),
BCMA_CORETABLE_END
};
static struct bcma_driver wl_glue_bcma_driver = {
.name = KBUILD_MODNAME,
.id_table = wl_glue_bcma_tbl,
.probe = wl_glue_bcma_probe,
.remove = wl_glue_bcma_remove,
};
#endif /* CONFIG_BCMA */
void wl_glue_set_attach_callback(wl_glue_attach_cb_t cb)
{
attach_cb = cb;
}
EXPORT_SYMBOL(wl_glue_set_attach_callback);
void wl_glue_set_remove_callback(wl_glue_remove_cb_t cb)
{
remove_cb = cb;
}
EXPORT_SYMBOL(wl_glue_set_remove_callback);
int wl_glue_register(void)
{
int err;
switch(active_bus_type)
{
#ifdef CONFIG_SSB
case WL_GLUE_BUS_TYPE_SSB:
err = ssb_driver_register(&wl_glue_ssb_driver);
break;
#endif /* CONFIG_SSB */
#ifdef CONFIG_BCMA
case WL_GLUE_BUS_TYPE_BCMA:
err = bcma_driver_register(&wl_glue_bcma_driver);
break;
#endif /* CONFIG_BCMA */
default:
pr_err("Not attaching through glue driver due to unsupported bus\n");
err = -ENOSYS;
break;
}
if (!err)
{
pr_info("SSB/BCMA glue driver successfully attached\n");
wl_glue_attached = 1;
}
return err;
}
EXPORT_SYMBOL(wl_glue_register);
int wl_glue_unregister(void)
{
int err;
if (!wl_glue_attached)
return -ENOSYS;
switch (active_bus_type)
{
#ifdef CONFIG_SSB
case WL_GLUE_BUS_TYPE_SSB:
ssb_driver_unregister(&wl_glue_ssb_driver);
err = 0;
break;
#endif /* CONFIG_SSB */
#ifdef CONFIG_BCMA
case WL_GLUE_BUS_TYPE_BCMA:
bcma_driver_unregister(&wl_glue_bcma_driver);
err = 0;
break;
#endif /* CONFIG_BCMA */
default:
pr_err("Not removing glue driver due to unsupported bus\n");
err = -ENOSYS;
break;
}
if (!err)
{
pr_info("SSB/BCMA glue driver successfully detached\n");
wl_glue_attached = 0;
}
return err;
}
EXPORT_SYMBOL(wl_glue_unregister);
struct device * wl_glue_get_dmadev(void *dev)
{
struct device *dma_dev;
if (!wl_glue_attached)
{
BUG();
return NULL;
}
switch (active_bus_type)
{
#ifdef CONFIG_SSB
case WL_GLUE_BUS_TYPE_SSB:
dma_dev = ((struct ssb_device *)dev)->dma_dev;
break;
#endif /* CONFIG_SSB */
#ifdef CONFIG_BCMA
case WL_GLUE_BUS_TYPE_BCMA:
dma_dev = ((struct bcma_device *)dev)->dma_dev;
break;
#endif /* CONFIG_BCMA */
default:
BUG();
dma_dev = NULL;
break;
}
return dma_dev;
}
EXPORT_SYMBOL(wl_glue_get_dmadev);
static int __init wl_glue_init(void)
{
#ifdef CONFIG_BCM47XX
/*
* BCM47xx currently supports either SSB or BCMA bus,
* determine the used one from the info set by the
* platform setup code.
*/
switch (bcm47xx_active_bus_type)
{
#ifdef CONFIG_SSB
case BCM47XX_BUS_TYPE_SSB:
active_bus_type = WL_GLUE_BUS_TYPE_SSB;
break;
#endif /* CONFIG_SSB */
#ifdef CONFIG_BCMA
case BCM47XX_BUS_TYPE_BCMA:
active_bus_type = WL_GLUE_BUS_TYPE_BCMA;
break;
#endif /* CONFIG_BCMA */
}
#endif /* CONFIG_BCM47XX */
#ifdef CONFIG_BCM63XX
#ifdef CONFIG_SSB
/*
* BCM63xx currently only uses SSB, so assume that.
*/
active_bus_type = WL_GLUE_BUS_TYPE_SSB;
#endif /* CONFIG_SSB */
#endif /* CONFIG_BCM63XX */
/* do not fail here, let wl_glue_register() return -ENOSYS later */
if (active_bus_type == WL_GLUE_BUS_TYPE_UNSPEC)
pr_err("Unable to determine used system bus type\n");
return 0;
}
static void __exit wl_glue_exit(void)
{
if (wl_glue_attached)
{
if (wl_glue_unregister())
pr_err("Failed to unregister glue driver\n");
wl_glue_attached = 0;
}
return;
}
module_init(wl_glue_init);
module_exit(wl_glue_exit);

View File

@ -0,0 +1,22 @@
/*
* wl_glue.h: Broadcom WL support module providing a unified SSB/BCMA handling.
* Copyright (C) 2011 Jo-Philipp Wich <jow@openwrt.org>
*/
#include <linux/types.h>
typedef void * (*wl_glue_attach_cb_t)(u16, u16, ulong, void *, u32);
typedef void (*wl_glue_remove_cb_t)(void *);
enum wl_glue_bus_type {
WL_GLUE_BUS_TYPE_UNSPEC,
WL_GLUE_BUS_TYPE_SSB,
WL_GLUE_BUS_TYPE_BCMA
};
extern void wl_glue_set_attach_callback(wl_glue_attach_cb_t cb);
extern void wl_glue_set_remove_callback(wl_glue_remove_cb_t cb);
extern int wl_glue_register(void);
extern int wl_glue_unregister(void);
extern struct device * wl_glue_get_dmadev(void *);