brcmfmac: rework bus interface
authorArend van Spriel <arend@broadcom.com>
Wed, 5 Dec 2012 14:25:54 +0000 (15:25 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Mon, 10 Dec 2012 20:33:05 +0000 (15:33 -0500)
Rework the bus interface between common driver part and bus-specific
driver part. It prepares for adding tracing in bus-specific callback
functions.

Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: Hante Meuleman <meuleman@broadcom.com>
Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/brcm80211/brcmfmac/dhd.h
drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
drivers/net/wireless/brcm80211/brcmfmac/dhd_cdc.c
drivers/net/wireless/brcm80211/brcmfmac/dhd_dbg.c
drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
drivers/net/wireless/brcm80211/brcmfmac/dhd_sdio.c
drivers/net/wireless/brcm80211/brcmfmac/usb.c
drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h

index 24bc4e3e162bba09693a6a84674f0a8b102b6247..fd672bf53867f6b7aac803fae15686d0d750ccee 100644 (file)
@@ -470,7 +470,6 @@ struct brcmf_pub {
        struct brcmf_bus *bus_if;
        struct brcmf_proto *prot;
        struct brcmf_cfg80211_info *config;
-       struct device *dev;             /* fullmac dongle device pointer */
 
        /* Internal brcmf items */
        uint hdrlen;            /* Total BRCMF header length (proto + bus) */
index b8f248797f621f5a66062c9a0d8796e5def31edb..dd38b78a9726f75861bcb1f92ef3d511a81b92db 100644 (file)
@@ -43,35 +43,89 @@ struct brcmf_bus_dcmd {
        struct list_head list;
 };
 
-/* interface structure between common and bus layer */
+/**
+ * struct brcmf_bus_ops - bus callback operations.
+ *
+ * @init: prepare for communication with dongle.
+ * @stop: clear pending frames, disable data flow.
+ * @txdata: send a data frame to the dongle (callee disposes skb).
+ * @txctl: transmit a control request message to dongle.
+ * @rxctl: receive a control response message from dongle.
+ *
+ * This structure provides an abstract interface towards the
+ * bus specific driver. For control messages to common driver
+ * will assure there is only one active transaction.
+ */
+struct brcmf_bus_ops {
+       int (*init)(struct device *dev);
+       void (*stop)(struct device *dev);
+       int (*txdata)(struct device *dev, struct sk_buff *skb);
+       int (*txctl)(struct device *dev, unsigned char *msg, uint len);
+       int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
+};
+
+/**
+ * struct brcmf_bus - interface structure between common and bus layer
+ *
+ * @bus_priv: pointer to private bus device.
+ * @dev: device pointer of bus device.
+ * @drvr: public driver information.
+ * @state: operational state of the bus interface.
+ * @maxctl: maximum size for rxctl request message.
+ * @drvr_up: indicates driver up/down status.
+ * @tx_realloc: number of tx packets realloced for headroom.
+ * @dstats: dongle-based statistical data.
+ * @align: alignment requirement for the bus.
+ * @dcmd_list: bus/device specific dongle initialization commands.
+ */
 struct brcmf_bus {
        union {
                struct brcmf_sdio_dev *sdio;
                struct brcmf_usbdev *usb;
        } bus_priv;
-       struct brcmf_pub *drvr; /* pointer to driver pub structure brcmf_pub */
+       struct device *dev;
+       struct brcmf_pub *drvr;
        enum brcmf_bus_state state;
-       uint maxctl;            /* Max size rxctl request from proto to bus */
-       bool drvr_up;           /* Status flag of driver up/down */
-       unsigned long tx_realloc;       /* Tx packets realloced for headroom */
-       struct dngl_stats dstats;       /* Stats for dongle-based data */
-       u8 align;               /* bus alignment requirement */
+       uint maxctl;
+       bool drvr_up;
+       unsigned long tx_realloc;
+       struct dngl_stats dstats;
+       u8 align;
        struct list_head dcmd_list;
 
-       /* interface functions pointers */
-       /* Stop bus module: clear pending frames, disable data flow */
-       void (*brcmf_bus_stop)(struct device *);
-       /* Initialize bus module: prepare for communication w/dongle */
-       int (*brcmf_bus_init)(struct device *);
-       /* Send a data frame to the dongle.  Callee disposes of txp. */
-       int (*brcmf_bus_txdata)(struct device *, struct sk_buff *);
-       /* Send/receive a control message to/from the dongle.
-        * Expects caller to enforce a single outstanding transaction.
-        */
-       int (*brcmf_bus_txctl)(struct device *, unsigned char *, uint);
-       int (*brcmf_bus_rxctl)(struct device *, unsigned char *, uint);
+       struct brcmf_bus_ops *ops;
 };
 
+/*
+ * callback wrappers
+ */
+static inline int brcmf_bus_init(struct brcmf_bus *bus)
+{
+       return bus->ops->init(bus->dev);
+}
+
+static inline void brcmf_bus_stop(struct brcmf_bus *bus)
+{
+       bus->ops->stop(bus->dev);
+}
+
+static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
+{
+       return bus->ops->txdata(bus->dev, skb);
+}
+
+static inline
+int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
+{
+       return bus->ops->txctl(bus->dev, msg, len);
+}
+
+static inline
+int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
+{
+       return bus->ops->rxctl(bus->dev, msg, len);
+}
+
 /*
  * interface functions from common layer
  */
index 87536d38a4ca35b9fc05dc31efc00c5b477270a8..b123d25366cd39441fc399cb6e72faa3a27c98cb 100644 (file)
@@ -117,9 +117,7 @@ static int brcmf_proto_cdc_msg(struct brcmf_pub *drvr)
                len = CDC_MAX_MSG_SIZE;
 
        /* Send request */
-       return drvr->bus_if->brcmf_bus_txctl(drvr->dev,
-                                            (unsigned char *)&prot->msg,
-                                            len);
+       return brcmf_bus_txctl(drvr->bus_if, (unsigned char *)&prot->msg, len);
 }
 
 static int brcmf_proto_cdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len)
@@ -128,11 +126,10 @@ static int brcmf_proto_cdc_cmplt(struct brcmf_pub *drvr, u32 id, u32 len)
        struct brcmf_proto *prot = drvr->prot;
 
        brcmf_dbg(TRACE, "Enter\n");
-
+       len += sizeof(struct brcmf_proto_cdc_dcmd);
        do {
-               ret = drvr->bus_if->brcmf_bus_rxctl(drvr->dev,
-                               (unsigned char *)&prot->msg,
-                               len + sizeof(struct brcmf_proto_cdc_dcmd));
+               ret = brcmf_bus_rxctl(drvr->bus_if, (unsigned char *)&prot->msg,
+                                     len);
                if (ret < 0)
                        break;
        } while (CDC_DCMD_ID(le32_to_cpu(prot->msg.flags)) != id);
index 7e58e8ce9aba68981e0590f7c34f11d8ae3459d9..57671eddf79dda2a204ed0da5ece8524d91733ba 100644 (file)
@@ -20,6 +20,7 @@
 #include <brcmu_wifi.h>
 #include <brcmu_utils.h>
 #include "dhd.h"
+#include "dhd_bus.h"
 #include "dhd_dbg.h"
 
 static struct dentry *root_folder;
@@ -42,10 +43,12 @@ void brcmf_debugfs_exit(void)
 
 int brcmf_debugfs_attach(struct brcmf_pub *drvr)
 {
+       struct device *dev = drvr->bus_if->dev;
+
        if (!root_folder)
                return -ENODEV;
 
-       drvr->dbgfs_dir = debugfs_create_dir(dev_name(drvr->dev), root_folder);
+       drvr->dbgfs_dir = debugfs_create_dir(dev_name(dev), root_folder);
        return PTR_RET(drvr->dbgfs_dir);
 }
 
index b6c86b046c15df2ff502aec761347bbf4bc5bd4b..421b49c95fb0180084242dc0d1aa7e74d28fd438 100644 (file)
@@ -219,7 +219,7 @@ static int brcmf_netdev_start_xmit(struct sk_buff *skb, struct net_device *ndev)
        brcmf_proto_hdrpush(drvr, ifp->idx, skb);
 
        /* Use bus module to send data frame */
-       ret =  drvr->bus_if->brcmf_bus_txdata(drvr->dev, skb);
+       ret =  brcmf_bus_txdata(drvr->bus_if, skb);
 
 done:
        if (ret)
@@ -397,7 +397,7 @@ static void brcmf_ethtool_get_drvinfo(struct net_device *ndev,
 
        sprintf(info->driver, KBUILD_MODNAME);
        sprintf(info->version, "%lu", drvr->drv_version);
-       sprintf(info->bus_info, "%s", dev_name(drvr->dev));
+       sprintf(info->bus_info, "%s", dev_name(drvr->bus_if->dev));
 }
 
 static const struct ethtool_ops brcmf_ethtool_ops = {
@@ -753,7 +753,6 @@ int brcmf_attach(uint bus_hdrlen, struct device *dev)
        drvr->hdrlen = bus_hdrlen;
        drvr->bus_if = dev_get_drvdata(dev);
        drvr->bus_if->drvr = drvr;
-       drvr->dev = dev;
 
        /* create device debugfs folder */
        brcmf_debugfs_attach(drvr);
@@ -790,7 +789,7 @@ int brcmf_bus_start(struct device *dev)
        brcmf_dbg(TRACE, "\n");
 
        /* Bring up the bus */
-       ret = bus_if->brcmf_bus_init(dev);
+       ret = brcmf_bus_init(bus_if);
        if (ret != 0) {
                brcmf_dbg(ERROR, "brcmf_sdbrcm_bus_init failed %d\n", ret);
                return ret;
@@ -809,7 +808,7 @@ int brcmf_bus_start(struct device *dev)
        if (ret < 0)
                goto fail;
 
-       drvr->config = brcmf_cfg80211_attach(drvr);
+       drvr->config = brcmf_cfg80211_attach(drvr, bus_if->dev);
        if (drvr->config == NULL) {
                ret = -ENOMEM;
                goto fail;
@@ -842,7 +841,7 @@ static void brcmf_bus_detach(struct brcmf_pub *drvr)
                brcmf_proto_stop(drvr);
 
                /* Stop the bus module */
-               drvr->bus_if->brcmf_bus_stop(drvr->dev);
+               brcmf_bus_stop(drvr->bus_if);
        }
 }
 
index 45725454714d5561583939c6212ef03cea5199e6..f2293bbb3c9b4366b009241d032a4b4cd9f715e8 100644 (file)
@@ -3883,6 +3883,14 @@ static void brcmf_sdbrcm_release(struct brcmf_sdio *bus)
        brcmf_dbg(TRACE, "Disconnected\n");
 }
 
+static struct brcmf_bus_ops brcmf_sdio_bus_ops = {
+       .stop = brcmf_sdbrcm_bus_stop,
+       .init = brcmf_sdbrcm_bus_init,
+       .txdata = brcmf_sdbrcm_bus_txdata,
+       .txctl = brcmf_sdbrcm_bus_txctl,
+       .rxctl = brcmf_sdbrcm_bus_rxctl,
+};
+
 void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev)
 {
        int ret;
@@ -3946,11 +3954,9 @@ void *brcmf_sdbrcm_probe(u32 regsva, struct brcmf_sdio_dev *sdiodev)
        spin_lock_init(&bus->dpc_tl_lock);
 
        /* Assign bus interface call back */
-       bus->sdiodev->bus_if->brcmf_bus_stop = brcmf_sdbrcm_bus_stop;
-       bus->sdiodev->bus_if->brcmf_bus_init = brcmf_sdbrcm_bus_init;
-       bus->sdiodev->bus_if->brcmf_bus_txdata = brcmf_sdbrcm_bus_txdata;
-       bus->sdiodev->bus_if->brcmf_bus_txctl = brcmf_sdbrcm_bus_txctl;
-       bus->sdiodev->bus_if->brcmf_bus_rxctl = brcmf_sdbrcm_bus_rxctl;
+       bus->sdiodev->bus_if->dev = bus->sdiodev->dev;
+       bus->sdiodev->bus_if->ops = &brcmf_sdio_bus_ops;
+
        /* Attach to the brcmf/OS/network interface */
        ret = brcmf_attach(SDPCM_RESERVE, bus->sdiodev->dev);
        if (ret != 0) {
index 39a5baa92f217ef93aede25e77b90884751fa821..5eb7bf86184861c697122264eaaeae7f1354779f 100644 (file)
@@ -1228,6 +1228,14 @@ error:
        return NULL;
 }
 
+static struct brcmf_bus_ops brcmf_usb_bus_ops = {
+       .txdata = brcmf_usb_tx,
+       .init = brcmf_usb_up,
+       .stop = brcmf_usb_down,
+       .txctl = brcmf_usb_tx_ctlpkt,
+       .rxctl = brcmf_usb_rx_ctlpkt,
+};
+
 static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
 {
        struct brcmf_bus *bus = NULL;
@@ -1246,14 +1254,11 @@ static int brcmf_usb_probe_cb(struct brcmf_usbdev_info *devinfo)
                goto fail;
        }
 
+       bus->dev = dev;
        bus_pub->bus = bus;
-       bus->brcmf_bus_txdata = brcmf_usb_tx;
-       bus->brcmf_bus_init = brcmf_usb_up;
-       bus->brcmf_bus_stop = brcmf_usb_down;
-       bus->brcmf_bus_txctl = brcmf_usb_tx_ctlpkt;
-       bus->brcmf_bus_rxctl = brcmf_usb_rx_ctlpkt;
        bus->bus_priv.usb = bus_pub;
        dev_set_drvdata(dev, bus);
+       bus->ops = &brcmf_usb_bus_ops;
 
        /* Attach to the common driver interface */
        ret = brcmf_attach(0, dev);
index 96bc349d7f6cb40abd61aeda69577eb79f3cf039..4ddd58f1e9fe4ad079b0e1a6b26c33515e8dd9de 100644 (file)
@@ -4271,10 +4271,10 @@ static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
        brcmf_deinit_priv_mem(cfg);
 }
 
-struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr)
+struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
+                                                 struct device *busdev)
 {
        struct net_device *ndev = drvr->iflist[0]->ndev;
-       struct device *busdev = drvr->dev;
        struct brcmf_cfg80211_info *cfg;
        struct wiphy *wiphy;
        struct brcmf_cfg80211_vif *vif;
index d60de187e7d9ce840869ffd877d931a8ad6f6c3e..c163e4dea9729cfd620993f3b1c5572066575e36 100644 (file)
@@ -450,7 +450,8 @@ brcmf_cfg80211_connect_info *cfg_to_conn(struct brcmf_cfg80211_info *cfg)
        return &cfg->conn_info;
 }
 
-struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr);
+struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
+                                                 struct device *busdev);
 void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg);
 s32 brcmf_cfg80211_up(struct net_device *ndev);
 s32 brcmf_cfg80211_down(struct net_device *ndev);