1 // SPDX-License-Identifier: ISC 2 /* 3 * Copyright (c) 2010 Broadcom Corporation 4 */ 5 6 #ifndef BRCMFMAC_BUS_H 7 #define BRCMFMAC_BUS_H 8 9 #include <linux/kernel.h> 10 #include <linux/firmware.h> 11 #include "debug.h" 12 13 /* IDs of the 6 default common rings of msgbuf protocol */ 14 #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 0 15 #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT 1 16 #define BRCMF_H2D_MSGRING_FLOWRING_IDSTART 2 17 #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE 2 18 #define BRCMF_D2H_MSGRING_TX_COMPLETE 3 19 #define BRCMF_D2H_MSGRING_RX_COMPLETE 4 20 21 22 #define BRCMF_NROF_H2D_COMMON_MSGRINGS 2 23 #define BRCMF_NROF_D2H_COMMON_MSGRINGS 3 24 #define BRCMF_NROF_COMMON_MSGRINGS (BRCMF_NROF_H2D_COMMON_MSGRINGS + \ 25 BRCMF_NROF_D2H_COMMON_MSGRINGS) 26 27 /* The interval to poll console */ 28 #define BRCMF_CONSOLE 10 29 30 /* The maximum console interval value (5 mins) */ 31 #define MAX_CONSOLE_INTERVAL (5 * 60) 32 33 /* The level of bus communication with the dongle */ 34 enum brcmf_bus_state { 35 BRCMF_BUS_DOWN, /* Not ready for frame transfers */ 36 BRCMF_BUS_UP /* Ready for frame transfers */ 37 }; 38 39 /* The level of bus communication with the dongle */ 40 enum brcmf_bus_protocol_type { 41 BRCMF_PROTO_BCDC, 42 BRCMF_PROTO_MSGBUF 43 }; 44 45 /* Firmware blobs that may be available */ 46 enum brcmf_blob_type { 47 BRCMF_BLOB_CLM, 48 }; 49 50 struct brcmf_mp_device; 51 52 struct brcmf_bus_dcmd { 53 char *name; 54 char *param; 55 int param_len; 56 struct list_head list; 57 }; 58 59 /** 60 * struct brcmf_bus_ops - bus callback operations. 61 * 62 * @preinit: execute bus/device specific dongle init commands (optional). 63 * @init: prepare for communication with dongle. 64 * @stop: clear pending frames, disable data flow. 65 * @txdata: send a data frame to the dongle. When the data 66 * has been transferred, the common driver must be 67 * notified using brcmf_txcomplete(). The common 68 * driver calls this function with interrupts 69 * disabled. 70 * @txctl: transmit a control request message to dongle. 71 * @rxctl: receive a control response message from dongle. 72 * @gettxq: obtain a reference of bus transmit queue (optional). 73 * @wowl_config: specify if dongle is configured for wowl when going to suspend 74 * @get_ramsize: obtain size of device memory. 75 * @get_memdump: obtain device memory dump in provided buffer. 76 * @get_blob: obtain a firmware blob. 77 * 78 * This structure provides an abstract interface towards the 79 * bus specific driver. For control messages to common driver 80 * will assure there is only one active transaction. Unless 81 * indicated otherwise these callbacks are mandatory. 82 */ 83 struct brcmf_bus_ops { 84 int (*preinit)(struct device *dev); 85 void (*stop)(struct device *dev); 86 int (*txdata)(struct device *dev, struct sk_buff *skb); 87 int (*txctl)(struct device *dev, unsigned char *msg, uint len); 88 int (*rxctl)(struct device *dev, unsigned char *msg, uint len); 89 struct pktq * (*gettxq)(struct device *dev); 90 void (*wowl_config)(struct device *dev, bool enabled); 91 size_t (*get_ramsize)(struct device *dev); 92 int (*get_memdump)(struct device *dev, void *data, size_t len); 93 int (*get_blob)(struct device *dev, const struct firmware **fw, 94 enum brcmf_blob_type type); 95 void (*debugfs_create)(struct device *dev); 96 int (*reset)(struct device *dev); 97 }; 98 99 100 /** 101 * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf. 102 * 103 * @commonrings: commonrings which are always there. 104 * @flowrings: commonrings which are dynamically created and destroyed for data. 105 * @rx_dataoffset: if set then all rx data has this offset. 106 * @max_rxbufpost: maximum number of buffers to post for rx. 107 * @max_flowrings: maximum number of tx flow rings supported. 108 * @max_submissionrings: maximum number of submission rings(h2d) supported. 109 * @max_completionrings: maximum number of completion rings(d2h) supported. 110 */ 111 struct brcmf_bus_msgbuf { 112 struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS]; 113 struct brcmf_commonring **flowrings; 114 u32 rx_dataoffset; 115 u32 max_rxbufpost; 116 u16 max_flowrings; 117 u16 max_submissionrings; 118 u16 max_completionrings; 119 }; 120 121 122 /** 123 * struct brcmf_bus_stats - bus statistic counters. 124 * 125 * @pktcowed: packets cowed for extra headroom/unorphan. 126 * @pktcow_failed: packets dropped due to failed cow-ing. 127 */ 128 struct brcmf_bus_stats { 129 atomic_t pktcowed; 130 atomic_t pktcow_failed; 131 }; 132 133 /** 134 * struct brcmf_bus - interface structure between common and bus layer 135 * 136 * @bus_priv: pointer to private bus device. 137 * @proto_type: protocol type, bcdc or msgbuf 138 * @dev: device pointer of bus device. 139 * @drvr: public driver information. 140 * @state: operational state of the bus interface. 141 * @stats: statistics shared between common and bus layer. 142 * @maxctl: maximum size for rxctl request message. 143 * @chip: device identifier of the dongle chip. 144 * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive. 145 * @wowl_supported: is wowl supported by bus driver. 146 * @chiprev: revision of the dongle chip. 147 * @msgbuf: msgbuf protocol parameters provided by bus layer. 148 */ 149 struct brcmf_bus { 150 union { 151 struct brcmf_sdio_dev *sdio; 152 struct brcmf_usbdev *usb; 153 struct brcmf_pciedev *pcie; 154 } bus_priv; 155 enum brcmf_bus_protocol_type proto_type; 156 struct device *dev; 157 struct brcmf_pub *drvr; 158 enum brcmf_bus_state state; 159 struct brcmf_bus_stats stats; 160 uint maxctl; 161 u32 chip; 162 u32 chiprev; 163 bool always_use_fws_queue; 164 bool wowl_supported; 165 166 const struct brcmf_bus_ops *ops; 167 struct brcmf_bus_msgbuf *msgbuf; 168 }; 169 170 /* 171 * callback wrappers 172 */ 173 static inline int brcmf_bus_preinit(struct brcmf_bus *bus) 174 { 175 if (!bus->ops->preinit) 176 return 0; 177 return bus->ops->preinit(bus->dev); 178 } 179 180 static inline void brcmf_bus_stop(struct brcmf_bus *bus) 181 { 182 bus->ops->stop(bus->dev); 183 } 184 185 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb) 186 { 187 return bus->ops->txdata(bus->dev, skb); 188 } 189 190 static inline 191 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len) 192 { 193 return bus->ops->txctl(bus->dev, msg, len); 194 } 195 196 static inline 197 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len) 198 { 199 return bus->ops->rxctl(bus->dev, msg, len); 200 } 201 202 static inline 203 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus) 204 { 205 if (!bus->ops->gettxq) 206 return ERR_PTR(-ENOENT); 207 208 return bus->ops->gettxq(bus->dev); 209 } 210 211 static inline 212 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled) 213 { 214 if (bus->ops->wowl_config) 215 bus->ops->wowl_config(bus->dev, enabled); 216 } 217 218 static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus) 219 { 220 if (!bus->ops->get_ramsize) 221 return 0; 222 223 return bus->ops->get_ramsize(bus->dev); 224 } 225 226 static inline 227 int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len) 228 { 229 if (!bus->ops->get_memdump) 230 return -EOPNOTSUPP; 231 232 return bus->ops->get_memdump(bus->dev, data, len); 233 } 234 235 static inline 236 int brcmf_bus_get_blob(struct brcmf_bus *bus, const struct firmware **fw, 237 enum brcmf_blob_type type) 238 { 239 return bus->ops->get_blob(bus->dev, fw, type); 240 } 241 242 static inline 243 void brcmf_bus_debugfs_create(struct brcmf_bus *bus) 244 { 245 if (!bus->ops->debugfs_create) 246 return; 247 248 return bus->ops->debugfs_create(bus->dev); 249 } 250 251 static inline 252 int brcmf_bus_reset(struct brcmf_bus *bus) 253 { 254 if (!bus->ops->reset) 255 return -EOPNOTSUPP; 256 257 return bus->ops->reset(bus->dev); 258 } 259 260 /* 261 * interface functions from common layer 262 */ 263 264 /* Receive frame for delivery to OS. Callee disposes of rxp. */ 265 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event, 266 bool inirq); 267 /* Receive async event packet from firmware. Callee disposes of rxp. */ 268 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp); 269 270 int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings); 271 /* Indication from bus module regarding presence/insertion of dongle. */ 272 int brcmf_attach(struct device *dev); 273 /* Indication from bus module regarding removal/absence of dongle */ 274 void brcmf_detach(struct device *dev); 275 void brcmf_free(struct device *dev); 276 /* Indication from bus module that dongle should be reset */ 277 void brcmf_dev_reset(struct device *dev); 278 /* Request from bus module to initiate a coredump */ 279 void brcmf_dev_coredump(struct device *dev); 280 /* Indication that firmware has halted or crashed */ 281 void brcmf_fw_crashed(struct device *dev); 282 283 /* Configure the "global" bus state used by upper layers */ 284 void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state); 285 286 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len); 287 void brcmf_bus_add_txhdrlen(struct device *dev, uint len); 288 289 #ifdef CONFIG_BRCMFMAC_SDIO 290 void brcmf_sdio_exit(void); 291 int brcmf_sdio_register(void); 292 #else 293 static inline void brcmf_sdio_exit(void) { } 294 static inline int brcmf_sdio_register(void) { return 0; } 295 #endif 296 297 #ifdef CONFIG_BRCMFMAC_USB 298 void brcmf_usb_exit(void); 299 int brcmf_usb_register(void); 300 #else 301 static inline void brcmf_usb_exit(void) { } 302 static inline int brcmf_usb_register(void) { return 0; } 303 #endif 304 305 #ifdef CONFIG_BRCMFMAC_PCIE 306 void brcmf_pcie_exit(void); 307 int brcmf_pcie_register(void); 308 #else 309 static inline void brcmf_pcie_exit(void) { } 310 static inline int brcmf_pcie_register(void) { return 0; } 311 #endif 312 313 #endif /* BRCMFMAC_BUS_H */ 314