Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: ISC
0002 /*
0003  * Copyright (c) 2010 Broadcom Corporation
0004  */
0005 
0006 #ifndef BRCMFMAC_BUS_H
0007 #define BRCMFMAC_BUS_H
0008 
0009 #include "debug.h"
0010 
0011 /* IDs of the 6 default common rings of msgbuf protocol */
0012 #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT    0
0013 #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT     1
0014 #define BRCMF_H2D_MSGRING_FLOWRING_IDSTART  2
0015 #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE  2
0016 #define BRCMF_D2H_MSGRING_TX_COMPLETE       3
0017 #define BRCMF_D2H_MSGRING_RX_COMPLETE       4
0018 
0019 
0020 #define BRCMF_NROF_H2D_COMMON_MSGRINGS      2
0021 #define BRCMF_NROF_D2H_COMMON_MSGRINGS      3
0022 #define BRCMF_NROF_COMMON_MSGRINGS  (BRCMF_NROF_H2D_COMMON_MSGRINGS + \
0023                      BRCMF_NROF_D2H_COMMON_MSGRINGS)
0024 
0025 /* The level of bus communication with the dongle */
0026 enum brcmf_bus_state {
0027     BRCMF_BUS_DOWN,     /* Not ready for frame transfers */
0028     BRCMF_BUS_UP        /* Ready for frame transfers */
0029 };
0030 
0031 /* The level of bus communication with the dongle */
0032 enum brcmf_bus_protocol_type {
0033     BRCMF_PROTO_BCDC,
0034     BRCMF_PROTO_MSGBUF
0035 };
0036 
0037 struct brcmf_mp_device;
0038 
0039 struct brcmf_bus_dcmd {
0040     char *name;
0041     char *param;
0042     int param_len;
0043     struct list_head list;
0044 };
0045 
0046 /**
0047  * struct brcmf_bus_ops - bus callback operations.
0048  *
0049  * @preinit: execute bus/device specific dongle init commands (optional).
0050  * @init: prepare for communication with dongle.
0051  * @stop: clear pending frames, disable data flow.
0052  * @txdata: send a data frame to the dongle. When the data
0053  *  has been transferred, the common driver must be
0054  *  notified using brcmf_txcomplete(). The common
0055  *  driver calls this function with interrupts
0056  *  disabled.
0057  * @txctl: transmit a control request message to dongle.
0058  * @rxctl: receive a control response message from dongle.
0059  * @gettxq: obtain a reference of bus transmit queue (optional).
0060  * @wowl_config: specify if dongle is configured for wowl when going to suspend
0061  * @get_ramsize: obtain size of device memory.
0062  * @get_memdump: obtain device memory dump in provided buffer.
0063  * @get_fwname: obtain firmware name.
0064  *
0065  * This structure provides an abstract interface towards the
0066  * bus specific driver. For control messages to common driver
0067  * will assure there is only one active transaction. Unless
0068  * indicated otherwise these callbacks are mandatory.
0069  */
0070 struct brcmf_bus_ops {
0071     int (*preinit)(struct device *dev);
0072     void (*stop)(struct device *dev);
0073     int (*txdata)(struct device *dev, struct sk_buff *skb);
0074     int (*txctl)(struct device *dev, unsigned char *msg, uint len);
0075     int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
0076     struct pktq * (*gettxq)(struct device *dev);
0077     void (*wowl_config)(struct device *dev, bool enabled);
0078     size_t (*get_ramsize)(struct device *dev);
0079     int (*get_memdump)(struct device *dev, void *data, size_t len);
0080     int (*get_fwname)(struct device *dev, const char *ext,
0081               unsigned char *fw_name);
0082     void (*debugfs_create)(struct device *dev);
0083     int (*reset)(struct device *dev);
0084 };
0085 
0086 
0087 /**
0088  * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
0089  *
0090  * @commonrings: commonrings which are always there.
0091  * @flowrings: commonrings which are dynamically created and destroyed for data.
0092  * @rx_dataoffset: if set then all rx data has this offset.
0093  * @max_rxbufpost: maximum number of buffers to post for rx.
0094  * @max_flowrings: maximum number of tx flow rings supported.
0095  * @max_submissionrings: maximum number of submission rings(h2d) supported.
0096  * @max_completionrings: maximum number of completion rings(d2h) supported.
0097  */
0098 struct brcmf_bus_msgbuf {
0099     struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
0100     struct brcmf_commonring **flowrings;
0101     u32 rx_dataoffset;
0102     u32 max_rxbufpost;
0103     u16 max_flowrings;
0104     u16 max_submissionrings;
0105     u16 max_completionrings;
0106 };
0107 
0108 
0109 /**
0110  * struct brcmf_bus_stats - bus statistic counters.
0111  *
0112  * @pktcowed: packets cowed for extra headroom/unorphan.
0113  * @pktcow_failed: packets dropped due to failed cow-ing.
0114  */
0115 struct brcmf_bus_stats {
0116     atomic_t pktcowed;
0117     atomic_t pktcow_failed;
0118 };
0119 
0120 /**
0121  * struct brcmf_bus - interface structure between common and bus layer
0122  *
0123  * @bus_priv: pointer to private bus device.
0124  * @proto_type: protocol type, bcdc or msgbuf
0125  * @dev: device pointer of bus device.
0126  * @drvr: public driver information.
0127  * @state: operational state of the bus interface.
0128  * @stats: statistics shared between common and bus layer.
0129  * @maxctl: maximum size for rxctl request message.
0130  * @chip: device identifier of the dongle chip.
0131  * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.
0132  * @wowl_supported: is wowl supported by bus driver.
0133  * @chiprev: revision of the dongle chip.
0134  * @msgbuf: msgbuf protocol parameters provided by bus layer.
0135  */
0136 struct brcmf_bus {
0137     union {
0138         struct brcmf_sdio_dev *sdio;
0139         struct brcmf_usbdev *usb;
0140         struct brcmf_pciedev *pcie;
0141     } bus_priv;
0142     enum brcmf_bus_protocol_type proto_type;
0143     struct device *dev;
0144     struct brcmf_pub *drvr;
0145     enum brcmf_bus_state state;
0146     struct brcmf_bus_stats stats;
0147     uint maxctl;
0148     u32 chip;
0149     u32 chiprev;
0150     bool always_use_fws_queue;
0151     bool wowl_supported;
0152 
0153     const struct brcmf_bus_ops *ops;
0154     struct brcmf_bus_msgbuf *msgbuf;
0155 };
0156 
0157 /*
0158  * callback wrappers
0159  */
0160 static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
0161 {
0162     if (!bus->ops->preinit)
0163         return 0;
0164     return bus->ops->preinit(bus->dev);
0165 }
0166 
0167 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
0168 {
0169     bus->ops->stop(bus->dev);
0170 }
0171 
0172 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
0173 {
0174     return bus->ops->txdata(bus->dev, skb);
0175 }
0176 
0177 static inline
0178 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
0179 {
0180     return bus->ops->txctl(bus->dev, msg, len);
0181 }
0182 
0183 static inline
0184 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
0185 {
0186     return bus->ops->rxctl(bus->dev, msg, len);
0187 }
0188 
0189 static inline
0190 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
0191 {
0192     if (!bus->ops->gettxq)
0193         return ERR_PTR(-ENOENT);
0194 
0195     return bus->ops->gettxq(bus->dev);
0196 }
0197 
0198 static inline
0199 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
0200 {
0201     if (bus->ops->wowl_config)
0202         bus->ops->wowl_config(bus->dev, enabled);
0203 }
0204 
0205 static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
0206 {
0207     if (!bus->ops->get_ramsize)
0208         return 0;
0209 
0210     return bus->ops->get_ramsize(bus->dev);
0211 }
0212 
0213 static inline
0214 int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
0215 {
0216     if (!bus->ops->get_memdump)
0217         return -EOPNOTSUPP;
0218 
0219     return bus->ops->get_memdump(bus->dev, data, len);
0220 }
0221 
0222 static inline
0223 int brcmf_bus_get_fwname(struct brcmf_bus *bus, const char *ext,
0224              unsigned char *fw_name)
0225 {
0226     return bus->ops->get_fwname(bus->dev, ext, fw_name);
0227 }
0228 
0229 static inline
0230 void brcmf_bus_debugfs_create(struct brcmf_bus *bus)
0231 {
0232     if (!bus->ops->debugfs_create)
0233         return;
0234 
0235     return bus->ops->debugfs_create(bus->dev);
0236 }
0237 
0238 static inline
0239 int brcmf_bus_reset(struct brcmf_bus *bus)
0240 {
0241     if (!bus->ops->reset)
0242         return -EOPNOTSUPP;
0243 
0244     return bus->ops->reset(bus->dev);
0245 }
0246 
0247 /*
0248  * interface functions from common layer
0249  */
0250 
0251 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
0252 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event,
0253             bool inirq);
0254 /* Receive async event packet from firmware. Callee disposes of rxp. */
0255 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
0256 
0257 int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings);
0258 /* Indication from bus module regarding presence/insertion of dongle. */
0259 int brcmf_attach(struct device *dev);
0260 /* Indication from bus module regarding removal/absence of dongle */
0261 void brcmf_detach(struct device *dev);
0262 void brcmf_free(struct device *dev);
0263 /* Indication from bus module that dongle should be reset */
0264 void brcmf_dev_reset(struct device *dev);
0265 /* Request from bus module to initiate a coredump */
0266 void brcmf_dev_coredump(struct device *dev);
0267 /* Indication that firmware has halted or crashed */
0268 void brcmf_fw_crashed(struct device *dev);
0269 
0270 /* Configure the "global" bus state used by upper layers */
0271 void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
0272 
0273 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
0274 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
0275 
0276 #ifdef CONFIG_BRCMFMAC_SDIO
0277 void brcmf_sdio_exit(void);
0278 int brcmf_sdio_register(void);
0279 #else
0280 static inline void brcmf_sdio_exit(void) { }
0281 static inline int brcmf_sdio_register(void) { return 0; }
0282 #endif
0283 
0284 #ifdef CONFIG_BRCMFMAC_USB
0285 void brcmf_usb_exit(void);
0286 int brcmf_usb_register(void);
0287 #else
0288 static inline void brcmf_usb_exit(void) { }
0289 static inline int brcmf_usb_register(void) { return 0; }
0290 #endif
0291 
0292 #ifdef CONFIG_BRCMFMAC_PCIE
0293 void brcmf_pcie_exit(void);
0294 int brcmf_pcie_register(void);
0295 #else
0296 static inline void brcmf_pcie_exit(void) { }
0297 static inline int brcmf_pcie_register(void) { return 0; }
0298 #endif
0299 
0300 #endif /* BRCMFMAC_BUS_H */