Path: blob/main/sys/contrib/dev/broadcom/brcm80211/brcmfmac/bus.h
178665 views
// SPDX-License-Identifier: ISC1/*2* Copyright (c) 2010 Broadcom Corporation3*/45#ifndef BRCMFMAC_BUS_H6#define BRCMFMAC_BUS_H78#include <linux/kernel.h>9#include <linux/firmware.h>10#include <linux/device.h>11#include "debug.h"1213/* IDs of the 6 default common rings of msgbuf protocol */14#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 015#define BRCMF_H2D_MSGRING_RXPOST_SUBMIT 116#define BRCMF_H2D_MSGRING_FLOWRING_IDSTART 217#define BRCMF_D2H_MSGRING_CONTROL_COMPLETE 218#define BRCMF_D2H_MSGRING_TX_COMPLETE 319#define BRCMF_D2H_MSGRING_RX_COMPLETE 4202122#define BRCMF_NROF_H2D_COMMON_MSGRINGS 223#define BRCMF_NROF_D2H_COMMON_MSGRINGS 324#define BRCMF_NROF_COMMON_MSGRINGS (BRCMF_NROF_H2D_COMMON_MSGRINGS + \25BRCMF_NROF_D2H_COMMON_MSGRINGS)2627/* The interval to poll console */28#define BRCMF_CONSOLE 102930/* The maximum console interval value (5 mins) */31#define MAX_CONSOLE_INTERVAL (5 * 60)3233enum brcmf_fwvendor {34BRCMF_FWVENDOR_WCC,35BRCMF_FWVENDOR_CYW,36BRCMF_FWVENDOR_BCA,37/* keep last */38BRCMF_FWVENDOR_NUM,39BRCMF_FWVENDOR_INVALID40};4142/* The level of bus communication with the dongle */43enum brcmf_bus_state {44BRCMF_BUS_DOWN, /* Not ready for frame transfers */45BRCMF_BUS_UP /* Ready for frame transfers */46};4748/* The level of bus communication with the dongle */49enum brcmf_bus_protocol_type {50BRCMF_PROTO_BCDC,51BRCMF_PROTO_MSGBUF52};5354/* Firmware blobs that may be available */55enum brcmf_blob_type {56BRCMF_BLOB_CLM,57BRCMF_BLOB_TXCAP,58};5960struct brcmf_mp_device;6162struct brcmf_bus_dcmd {63char *name;64char *param;65int param_len;66struct list_head list;67};6869/**70* struct brcmf_bus_ops - bus callback operations.71*72* @preinit: execute bus/device specific dongle init commands (optional).73* @init: prepare for communication with dongle.74* @stop: clear pending frames, disable data flow.75* @txdata: send a data frame to the dongle. When the data76* has been transferred, the common driver must be77* notified using brcmf_txcomplete(). The common78* driver calls this function with interrupts79* disabled.80* @txctl: transmit a control request message to dongle.81* @rxctl: receive a control response message from dongle.82* @gettxq: obtain a reference of bus transmit queue (optional).83* @wowl_config: specify if dongle is configured for wowl when going to suspend84* @get_ramsize: obtain size of device memory.85* @get_memdump: obtain device memory dump in provided buffer.86* @get_blob: obtain a firmware blob.87* @remove: initiate unbind of the device.88*89* This structure provides an abstract interface towards the90* bus specific driver. For control messages to common driver91* will assure there is only one active transaction. Unless92* indicated otherwise these callbacks are mandatory.93*/94struct brcmf_bus_ops {95int (*preinit)(struct device *dev);96void (*stop)(struct device *dev);97int (*txdata)(struct device *dev, struct sk_buff *skb);98int (*txctl)(struct device *dev, unsigned char *msg, uint len);99int (*rxctl)(struct device *dev, unsigned char *msg, uint len);100struct pktq * (*gettxq)(struct device *dev);101void (*wowl_config)(struct device *dev, bool enabled);102size_t (*get_ramsize)(struct device *dev);103int (*get_memdump)(struct device *dev, void *data, size_t len);104int (*get_blob)(struct device *dev, const struct firmware **fw,105enum brcmf_blob_type type);106void (*debugfs_create)(struct device *dev);107int (*reset)(struct device *dev);108void (*remove)(struct device *dev);109};110111112/**113* struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.114*115* @commonrings: commonrings which are always there.116* @flowrings: commonrings which are dynamically created and destroyed for data.117* @rx_dataoffset: if set then all rx data has this offset.118* @max_rxbufpost: maximum number of buffers to post for rx.119* @max_flowrings: maximum number of tx flow rings supported.120* @max_submissionrings: maximum number of submission rings(h2d) supported.121* @max_completionrings: maximum number of completion rings(d2h) supported.122*/123struct brcmf_bus_msgbuf {124struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];125struct brcmf_commonring **flowrings;126u32 rx_dataoffset;127u32 max_rxbufpost;128u16 max_flowrings;129u16 max_submissionrings;130u16 max_completionrings;131};132133134/**135* struct brcmf_bus_stats - bus statistic counters.136*137* @pktcowed: packets cowed for extra headroom/unorphan.138* @pktcow_failed: packets dropped due to failed cow-ing.139*/140struct brcmf_bus_stats {141atomic_t pktcowed;142atomic_t pktcow_failed;143};144145/**146* struct brcmf_bus - interface structure between common and bus layer147*148* @bus_priv: pointer to private bus device.149* @proto_type: protocol type, bcdc or msgbuf150* @dev: device pointer of bus device.151* @drvr: public driver information.152* @state: operational state of the bus interface.153* @stats: statistics shared between common and bus layer.154* @maxctl: maximum size for rxctl request message.155* @chip: device identifier of the dongle chip.156* @chiprev: revision of the dongle chip.157* @fwvid: firmware vendor-support identifier of the device.158* @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.159* @wowl_supported: is wowl supported by bus driver.160* @ops: callbacks for this bus instance.161* @msgbuf: msgbuf protocol parameters provided by bus layer.162* @list: member used to add this bus instance to linked list.163*/164struct brcmf_bus {165union {166struct brcmf_sdio_dev *sdio;167struct brcmf_usbdev *usb;168struct brcmf_pciedev *pcie;169} bus_priv;170enum brcmf_bus_protocol_type proto_type;171struct device *dev;172struct brcmf_pub *drvr;173enum brcmf_bus_state state;174struct brcmf_bus_stats stats;175uint maxctl;176u32 chip;177u32 chiprev;178enum brcmf_fwvendor fwvid;179bool always_use_fws_queue;180bool wowl_supported;181182const struct brcmf_bus_ops *ops;183struct brcmf_bus_msgbuf *msgbuf;184185struct list_head list;186};187188/*189* callback wrappers190*/191static inline int brcmf_bus_preinit(struct brcmf_bus *bus)192{193if (!bus->ops->preinit)194return 0;195return bus->ops->preinit(bus->dev);196}197198static inline void brcmf_bus_stop(struct brcmf_bus *bus)199{200bus->ops->stop(bus->dev);201}202203static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)204{205return bus->ops->txdata(bus->dev, skb);206}207208static inline209int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)210{211return bus->ops->txctl(bus->dev, msg, len);212}213214static inline215int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)216{217return bus->ops->rxctl(bus->dev, msg, len);218}219220static inline221struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)222{223if (!bus->ops->gettxq)224return ERR_PTR(-ENOENT);225226return bus->ops->gettxq(bus->dev);227}228229static inline230void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)231{232if (bus->ops->wowl_config)233bus->ops->wowl_config(bus->dev, enabled);234}235236static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)237{238if (!bus->ops->get_ramsize)239return 0;240241return bus->ops->get_ramsize(bus->dev);242}243244static inline245int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)246{247if (!bus->ops->get_memdump)248return -EOPNOTSUPP;249250return bus->ops->get_memdump(bus->dev, data, len);251}252253static inline254int brcmf_bus_get_blob(struct brcmf_bus *bus, const struct firmware **fw,255enum brcmf_blob_type type)256{257return bus->ops->get_blob(bus->dev, fw, type);258}259260static inline261void brcmf_bus_debugfs_create(struct brcmf_bus *bus)262{263if (!bus->ops->debugfs_create)264return;265266return bus->ops->debugfs_create(bus->dev);267}268269static inline270int brcmf_bus_reset(struct brcmf_bus *bus)271{272if (!bus->ops->reset)273return -EOPNOTSUPP;274275return bus->ops->reset(bus->dev);276}277278static inline void brcmf_bus_remove(struct brcmf_bus *bus)279{280if (!bus->ops->remove) {281device_release_driver(bus->dev);282return;283}284285bus->ops->remove(bus->dev);286}287288/*289* interface functions from common layer290*/291292/* Receive frame for delivery to OS. Callee disposes of rxp. */293void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event,294bool inirq);295/* Receive async event packet from firmware. Callee disposes of rxp. */296void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);297298int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings);299/* Indication from bus module regarding presence/insertion of dongle. */300int brcmf_attach(struct device *dev);301/* Indication from bus module regarding removal/absence of dongle */302void brcmf_detach(struct device *dev);303void brcmf_free(struct device *dev);304/* Indication from bus module that dongle should be reset */305void brcmf_dev_reset(struct device *dev);306/* Request from bus module to initiate a coredump */307void brcmf_dev_coredump(struct device *dev);308/* Indication that firmware has halted or crashed */309void brcmf_fw_crashed(struct device *dev);310311/* Configure the "global" bus state used by upper layers */312void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);313314s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);315void brcmf_bus_add_txhdrlen(struct device *dev, uint len);316317#ifdef CONFIG_BRCMFMAC_SDIO318void brcmf_sdio_exit(void);319int brcmf_sdio_register(void);320#else321static inline void brcmf_sdio_exit(void) { }322static inline int brcmf_sdio_register(void) { return 0; }323#endif324325#ifdef CONFIG_BRCMFMAC_USB326void brcmf_usb_exit(void);327int brcmf_usb_register(void);328#else329static inline void brcmf_usb_exit(void) { }330static inline int brcmf_usb_register(void) { return 0; }331#endif332333#ifdef CONFIG_BRCMFMAC_PCIE334void brcmf_pcie_exit(void);335int brcmf_pcie_register(void);336#else337static inline void brcmf_pcie_exit(void) { }338static inline int brcmf_pcie_register(void) { return 0; }339#endif340341#endif /* BRCMFMAC_BUS_H */342343344