Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / brcm80211 / brcmsmac / main.c
index bb00b6528d8f3bbb01925650f77d3bed50aa34c6..cb73f2250b11db1ae976fe131d6cbc202f7da126 100644 (file)
@@ -269,7 +269,7 @@ struct brcms_c_bit_desc {
  */
 
 /* Starting corerev for the fifo size table */
-#define XMTFIFOTBL_STARTREV    20
+#define XMTFIFOTBL_STARTREV    17
 
 struct d11init {
        __le16 addr;
@@ -333,6 +333,12 @@ const u8 wlc_prio2prec_map[] = {
 };
 
 static const u16 xmtfifo_sz[][NFIFO] = {
+       /* corerev 17: 5120, 49152, 49152, 5376, 4352, 1280 */
+       {20, 192, 192, 21, 17, 5},
+       /* corerev 18: */
+       {0, 0, 0, 0, 0, 0},
+       /* corerev 19: */
+       {0, 0, 0, 0, 0, 0},
        /* corerev 20: 5120, 49152, 49152, 5376, 4352, 1280 */
        {20, 192, 192, 21, 17, 5},
        /* corerev 21: 2304, 14848, 5632, 3584, 3584, 1280 */
@@ -343,6 +349,14 @@ static const u16 xmtfifo_sz[][NFIFO] = {
        {20, 192, 192, 21, 17, 5},
        /* corerev 24: 2304, 14848, 5632, 3584, 3584, 1280 */
        {9, 58, 22, 14, 14, 5},
+       /* corerev 25: */
+       {0, 0, 0, 0, 0, 0},
+       /* corerev 26: */
+       {0, 0, 0, 0, 0, 0},
+       /* corerev 27: */
+       {0, 0, 0, 0, 0, 0},
+       /* corerev 28: 2304, 14848, 5632, 3584, 3584, 1280 */
+       {9, 58, 22, 14, 14, 5},
 };
 
 #ifdef DEBUG
@@ -1942,7 +1956,8 @@ static bool brcms_b_radio_read_hwdisabled(struct brcms_hardware *wlc_hw)
                 * accesses phyreg throughput mac. This can be skipped since
                 * only mac reg is accessed below
                 */
-               flags |= SICF_PCLKE;
+               if (D11REV_GE(wlc_hw->corerev, 18))
+                       flags |= SICF_PCLKE;
 
                /*
                 * TODO: test suspend/resume
@@ -2023,7 +2038,8 @@ void brcms_b_corereset(struct brcms_hardware *wlc_hw, u32 flags)
         * phyreg throughput mac, AND phy_reset is skipped at early stage when
         * band->pi is invalid. need to enable PHY CLK
         */
-       flags |= SICF_PCLKE;
+       if (D11REV_GE(wlc_hw->corerev, 18))
+               flags |= SICF_PCLKE;
 
        /*
         * reset the core
@@ -2126,8 +2142,8 @@ void brcms_b_switch_macfreq(struct brcms_hardware *wlc_hw, u8 spurmode)
 {
        struct bcma_device *core = wlc_hw->d11core;
 
-       if ((ai_get_chip_id(wlc_hw->sih) == BCM43224_CHIP_ID) ||
-           (ai_get_chip_id(wlc_hw->sih) == BCM43225_CHIP_ID)) {
+       if ((ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM43224) ||
+           (ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM43225)) {
                if (spurmode == WL_SPURAVOID_ON2) {     /* 126Mhz */
                        bcma_write16(core, D11REGOFFS(tsf_clk_frac_l), 0x2082);
                        bcma_write16(core, D11REGOFFS(tsf_clk_frac_h), 0x8);
@@ -2791,7 +2807,7 @@ void brcms_b_core_phypll_ctl(struct brcms_hardware *wlc_hw, bool on)
        tmp = 0;
 
        if (on) {
-               if ((ai_get_chip_id(wlc_hw->sih) == BCM4313_CHIP_ID)) {
+               if ((ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM4313)) {
                        bcma_set32(core, D11REGOFFS(clk_ctl_st),
                                   CCS_ERSRC_REQ_HT |
                                   CCS_ERSRC_REQ_D11PLL |
@@ -4218,9 +4234,8 @@ static void brcms_c_radio_timer(void *arg)
 }
 
 /* common low-level watchdog code */
-static void brcms_b_watchdog(void *arg)
+static void brcms_b_watchdog(struct brcms_c_info *wlc)
 {
-       struct brcms_c_info *wlc = (struct brcms_c_info *) arg;
        struct brcms_hardware *wlc_hw = wlc->hw;
 
        BCMMSG(wlc->wiphy, "wl%d\n", wlc_hw->unit);
@@ -4241,10 +4256,8 @@ static void brcms_b_watchdog(void *arg)
 }
 
 /* common watchdog code */
-static void brcms_c_watchdog(void *arg)
+static void brcms_c_watchdog(struct brcms_c_info *wlc)
 {
-       struct brcms_c_info *wlc = (struct brcms_c_info *) arg;
-
        BCMMSG(wlc->wiphy, "wl%d\n", wlc->pub->unit);
 
        if (!wlc->pub->up)
@@ -4284,7 +4297,9 @@ static void brcms_c_watchdog(void *arg)
 
 static void brcms_c_watchdog_by_timer(void *arg)
 {
-       brcms_c_watchdog(arg);
+       struct brcms_c_info *wlc = (struct brcms_c_info *) arg;
+
+       brcms_c_watchdog(wlc);
 }
 
 static bool brcms_c_timers_init(struct brcms_c_info *wlc, int unit)
@@ -4454,11 +4469,9 @@ static int brcms_b_attach(struct brcms_c_info *wlc, struct bcma_device *core,
        }
 
        /* verify again the device is supported */
-       if (core->bus->hosttype == BCMA_HOSTTYPE_PCI &&
-           !brcms_c_chipmatch(pcidev->vendor, pcidev->device)) {
-               wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported "
-                       "vendor/device (0x%x/0x%x)\n",
-                        unit, pcidev->vendor, pcidev->device);
+       if (!brcms_c_chipmatch(core)) {
+               wiphy_err(wiphy, "wl%d: brcms_b_attach: Unsupported device\n",
+                        unit);
                err = 12;
                goto fail;
        }
@@ -4528,7 +4541,7 @@ static int brcms_b_attach(struct brcms_c_info *wlc, struct bcma_device *core,
        else
                wlc_hw->_nbands = 1;
 
-       if ((ai_get_chip_id(wlc_hw->sih) == BCM43225_CHIP_ID))
+       if ((ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM43225))
                wlc_hw->_nbands = 1;
 
        /* BMAC_NOTE: remove init of pub values when brcms_c_attach()
@@ -4595,8 +4608,12 @@ static int brcms_b_attach(struct brcms_c_info *wlc, struct bcma_device *core,
                wlc_hw->machwcap_backup = wlc_hw->machwcap;
 
                /* init tx fifo size */
+               WARN_ON((wlc_hw->corerev - XMTFIFOTBL_STARTREV) < 0 ||
+                       (wlc_hw->corerev - XMTFIFOTBL_STARTREV) >
+                               ARRAY_SIZE(xmtfifo_sz));
                wlc_hw->xmtfifo_sz =
                    xmtfifo_sz[(wlc_hw->corerev - XMTFIFOTBL_STARTREV)];
+               WARN_ON(!wlc_hw->xmtfifo_sz[0]);
 
                /* Get a phy for this band */
                wlc_hw->band->pi =
@@ -5036,7 +5053,7 @@ static void brcms_b_hw_up(struct brcms_hardware *wlc_hw)
        wlc_hw->wlc->pub->hw_up = true;
 
        if ((wlc_hw->boardflags & BFL_FEM)
-           && (ai_get_chip_id(wlc_hw->sih) == BCM4313_CHIP_ID)) {
+           && (ai_get_chip_id(wlc_hw->sih) == BCMA_CHIP_ID_BCM4313)) {
                if (!
                    (wlc_hw->boardrev >= 0x1250
                     && (wlc_hw->boardflags & BFL_FEM_BT)))
@@ -5130,7 +5147,7 @@ int brcms_c_up(struct brcms_c_info *wlc)
        }
 
        if ((wlc->pub->boardflags & BFL_FEM)
-           && (ai_get_chip_id(wlc->hw->sih) == BCM4313_CHIP_ID)) {
+           && (ai_get_chip_id(wlc->hw->sih) == BCMA_CHIP_ID_BCM4313)) {
                if (wlc->pub->boardrev >= 0x1250
                    && (wlc->pub->boardflags & BFL_FEM_BT))
                        brcms_b_mhf(wlc->hw, MHF5, MHF5_4313_GPIOCTRL,
@@ -5767,8 +5784,12 @@ void brcms_c_print_txstatus(struct tx_status *txs)
                 (txs->ackphyrxsh & PRXS1_SQ_MASK) >> PRXS1_SQ_SHIFT);
 }
 
-bool brcms_c_chipmatch(u16 vendor, u16 device)
+static bool brcms_c_chipmatch_pci(struct bcma_device *core)
 {
+       struct pci_dev *pcidev = core->bus->host_pci;
+       u16 vendor = pcidev->vendor;
+       u16 device = pcidev->device;
+
        if (vendor != PCI_VENDOR_ID_BROADCOM) {
                pr_err("unknown vendor id %04x\n", vendor);
                return false;
@@ -5787,6 +5808,30 @@ bool brcms_c_chipmatch(u16 vendor, u16 device)
        return false;
 }
 
+static bool brcms_c_chipmatch_soc(struct bcma_device *core)
+{
+       struct bcma_chipinfo *chipinfo = &core->bus->chipinfo;
+
+       if (chipinfo->id == BCMA_CHIP_ID_BCM4716)
+               return true;
+
+       pr_err("unknown chip id %04x\n", chipinfo->id);
+       return false;
+}
+
+bool brcms_c_chipmatch(struct bcma_device *core)
+{
+       switch (core->bus->hosttype) {
+       case BCMA_HOSTTYPE_PCI:
+               return brcms_c_chipmatch_pci(core);
+       case BCMA_HOSTTYPE_SOC:
+               return brcms_c_chipmatch_soc(core);
+       default:
+               pr_err("unknown host type: %i\n", core->bus->hosttype);
+               return false;
+       }
+}
+
 #if defined(DEBUG)
 void brcms_c_print_txdesc(struct d11txh *txh)
 {