Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Broadcom Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <linux/netdevice.h> |
| 18 | |
| 19 | #include <brcm_hw_ids.h> |
Hante Meuleman | 122d3d0 | 2014-10-28 14:56:18 +0100 | [diff] [blame] | 20 | #include "core.h" |
Hante Meuleman | d14f78b | 2014-10-28 14:56:14 +0100 | [diff] [blame] | 21 | #include "bus.h" |
Hante Meuleman | a8e8ed3 | 2014-10-28 14:56:13 +0100 | [diff] [blame] | 22 | #include "debug.h" |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 23 | #include "fwil.h" |
| 24 | #include "feature.h" |
| 25 | |
| 26 | /* |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 27 | * expand feature list to array of feature strings. |
| 28 | */ |
| 29 | #define BRCMF_FEAT_DEF(_f) \ |
| 30 | #_f, |
| 31 | static const char *brcmf_feat_names[] = { |
| 32 | BRCMF_FEAT_LIST |
| 33 | }; |
| 34 | #undef BRCMF_FEAT_DEF |
| 35 | |
| 36 | #ifdef DEBUG |
| 37 | /* |
| 38 | * expand quirk list to array of quirk strings. |
| 39 | */ |
| 40 | #define BRCMF_QUIRK_DEF(_q) \ |
| 41 | #_q, |
| 42 | static const char * const brcmf_quirk_names[] = { |
| 43 | BRCMF_QUIRK_LIST |
| 44 | }; |
| 45 | #undef BRCMF_QUIRK_DEF |
| 46 | |
| 47 | /** |
| 48 | * brcmf_feat_debugfs_read() - expose feature info to debugfs. |
| 49 | * |
| 50 | * @seq: sequence for debugfs entry. |
| 51 | * @data: raw data pointer. |
| 52 | */ |
| 53 | static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data) |
| 54 | { |
| 55 | struct brcmf_bus *bus_if = dev_get_drvdata(seq->private); |
| 56 | u32 feats = bus_if->drvr->feat_flags; |
| 57 | u32 quirks = bus_if->drvr->chip_quirks; |
| 58 | int id; |
| 59 | |
| 60 | seq_printf(seq, "Features: %08x\n", feats); |
| 61 | for (id = 0; id < BRCMF_FEAT_LAST; id++) |
| 62 | if (feats & BIT(id)) |
| 63 | seq_printf(seq, "\t%s\n", brcmf_feat_names[id]); |
| 64 | seq_printf(seq, "\nQuirks: %08x\n", quirks); |
| 65 | for (id = 0; id < BRCMF_FEAT_QUIRK_LAST; id++) |
| 66 | if (quirks & BIT(id)) |
| 67 | seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]); |
| 68 | return 0; |
| 69 | } |
| 70 | #else |
| 71 | static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data) |
| 72 | { |
| 73 | return 0; |
| 74 | } |
| 75 | #endif /* DEBUG */ |
| 76 | |
| 77 | /** |
| 78 | * brcmf_feat_iovar_int_get() - determine feature through iovar query. |
| 79 | * |
| 80 | * @ifp: interface to query. |
| 81 | * @id: feature id. |
| 82 | * @name: iovar name. |
| 83 | */ |
| 84 | static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp, |
| 85 | enum brcmf_feat_id id, char *name) |
| 86 | { |
| 87 | u32 data; |
| 88 | int err; |
| 89 | |
| 90 | err = brcmf_fil_iovar_int_get(ifp, name, &data); |
| 91 | if (err == 0) { |
| 92 | brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); |
| 93 | ifp->drvr->feat_flags |= BIT(id); |
| 94 | } else { |
| 95 | brcmf_dbg(TRACE, "%s feature check failed: %d\n", |
| 96 | brcmf_feat_names[id], err); |
| 97 | } |
| 98 | } |
| 99 | |
Hante Meuleman | a44aa40 | 2014-12-03 21:05:33 +0100 | [diff] [blame] | 100 | /** |
| 101 | * brcmf_feat_iovar_int_set() - determine feature through iovar set. |
| 102 | * |
| 103 | * @ifp: interface to query. |
| 104 | * @id: feature id. |
| 105 | * @name: iovar name. |
| 106 | */ |
| 107 | static void brcmf_feat_iovar_int_set(struct brcmf_if *ifp, |
| 108 | enum brcmf_feat_id id, char *name, u32 val) |
| 109 | { |
| 110 | int err; |
| 111 | |
| 112 | err = brcmf_fil_iovar_int_set(ifp, name, val); |
| 113 | if (err == 0) { |
| 114 | brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); |
| 115 | ifp->drvr->feat_flags |= BIT(id); |
| 116 | } else { |
| 117 | brcmf_dbg(TRACE, "%s feature check failed: %d\n", |
| 118 | brcmf_feat_names[id], err); |
| 119 | } |
| 120 | } |
| 121 | |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 122 | void brcmf_feat_attach(struct brcmf_pub *drvr) |
| 123 | { |
| 124 | struct brcmf_if *ifp = drvr->iflist[0]; |
| 125 | |
| 126 | brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MCHAN, "mchan"); |
Arend van Spriel | 7a7a87d | 2015-04-14 20:10:27 +0200 | [diff] [blame] | 127 | brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn"); |
Hante Meuleman | 4eb3af7 | 2014-09-30 10:23:18 +0200 | [diff] [blame] | 128 | if (drvr->bus_if->wowl_supported) |
| 129 | brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl"); |
Arend van Spriel | f93a25b | 2015-03-20 22:18:17 +0100 | [diff] [blame] | 130 | if (drvr->bus_if->chip != BRCM_CC_43362_CHIP_ID) |
| 131 | brcmf_feat_iovar_int_set(ifp, BRCMF_FEAT_MBSS, "mbss", 0); |
Arend van Spriel | c08437b | 2014-07-12 08:49:39 +0200 | [diff] [blame] | 132 | |
| 133 | /* set chip related quirks */ |
| 134 | switch (drvr->bus_if->chip) { |
| 135 | case BRCM_CC_43236_CHIP_ID: |
| 136 | drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH); |
| 137 | break; |
| 138 | case BRCM_CC_4329_CHIP_ID: |
| 139 | drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC); |
| 140 | break; |
| 141 | default: |
| 142 | /* no quirks */ |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read); |
| 147 | } |
| 148 | |
| 149 | bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id) |
| 150 | { |
| 151 | return (ifp->drvr->feat_flags & BIT(id)); |
| 152 | } |
| 153 | |
| 154 | bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp, |
| 155 | enum brcmf_feat_quirk quirk) |
| 156 | { |
| 157 | return (ifp->drvr->chip_quirks & BIT(quirk)); |
| 158 | } |