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