1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2010 Broadcom Corporation
11 /* IDs of the 6 default common rings of msgbuf protocol */
12 #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 0
13 #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT 1
14 #define BRCMF_H2D_MSGRING_FLOWRING_IDSTART 2
15 #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE 2
16 #define BRCMF_D2H_MSGRING_TX_COMPLETE 3
17 #define BRCMF_D2H_MSGRING_RX_COMPLETE 4
20 #define BRCMF_NROF_H2D_COMMON_MSGRINGS 2
21 #define BRCMF_NROF_D2H_COMMON_MSGRINGS 3
22 #define BRCMF_NROF_COMMON_MSGRINGS (BRCMF_NROF_H2D_COMMON_MSGRINGS + \
23 BRCMF_NROF_D2H_COMMON_MSGRINGS)
25 /* The level of bus communication with the dongle */
26 enum brcmf_bus_state {
27 BRCMF_BUS_DOWN, /* Not ready for frame transfers */
28 BRCMF_BUS_UP /* Ready for frame transfers */
31 /* The level of bus communication with the dongle */
32 enum brcmf_bus_protocol_type {
37 struct brcmf_mp_device;
39 struct brcmf_bus_dcmd {
43 struct list_head list;
47 * struct brcmf_bus_ops - bus callback operations.
49 * @preinit: execute bus/device specific dongle init commands (optional).
50 * @init: prepare for communication with dongle.
51 * @stop: clear pending frames, disable data flow.
52 * @txdata: send a data frame to the dongle. When the data
53 * has been transferred, the common driver must be
54 * notified using brcmf_txcomplete(). The common
55 * driver calls this function with interrupts
57 * @txctl: transmit a control request message to dongle.
58 * @rxctl: receive a control response message from dongle.
59 * @gettxq: obtain a reference of bus transmit queue (optional).
60 * @wowl_config: specify if dongle is configured for wowl when going to suspend
61 * @get_ramsize: obtain size of device memory.
62 * @get_memdump: obtain device memory dump in provided buffer.
63 * @get_fwname: obtain firmware name.
65 * This structure provides an abstract interface towards the
66 * bus specific driver. For control messages to common driver
67 * will assure there is only one active transaction. Unless
68 * indicated otherwise these callbacks are mandatory.
70 struct brcmf_bus_ops {
71 int (*preinit)(struct device *dev);
72 void (*stop)(struct device *dev);
73 int (*txdata)(struct device *dev, struct sk_buff *skb);
74 int (*txctl)(struct device *dev, unsigned char *msg, uint len);
75 int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
76 struct pktq * (*gettxq)(struct device *dev);
77 void (*wowl_config)(struct device *dev, bool enabled);
78 size_t (*get_ramsize)(struct device *dev);
79 int (*get_memdump)(struct device *dev, void *data, size_t len);
80 int (*get_fwname)(struct device *dev, const char *ext,
81 unsigned char *fw_name, bool board_specific);
82 void (*debugfs_create)(struct device *dev);
83 int (*reset)(struct device *dev);
88 * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
90 * @commonrings: commonrings which are always there.
91 * @flowrings: commonrings which are dynamically created and destroyed for data.
92 * @rx_dataoffset: if set then all rx data has this this offset.
93 * @max_rxbufpost: maximum number of buffers to post for rx.
94 * @max_flowrings: maximum number of tx flow rings supported.
95 * @max_submissionrings: maximum number of submission rings(h2d) supported.
96 * @max_completionrings: maximum number of completion rings(d2h) supported.
98 struct brcmf_bus_msgbuf {
99 struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
100 struct brcmf_commonring **flowrings;
104 u16 max_submissionrings;
105 u16 max_completionrings;
110 * struct brcmf_bus_stats - bus statistic counters.
112 * @pktcowed: packets cowed for extra headroom/unorphan.
113 * @pktcow_failed: packets dropped due to failed cow-ing.
115 struct brcmf_bus_stats {
117 atomic_t pktcow_failed;
121 * struct brcmf_bus - interface structure between common and bus layer
123 * @bus_priv: pointer to private bus device.
124 * @proto_type: protocol type, bcdc or msgbuf
125 * @dev: device pointer of bus device.
126 * @drvr: public driver information.
127 * @state: operational state of the bus interface.
128 * @stats: statistics shared between common and bus layer.
129 * @maxctl: maximum size for rxctl request message.
130 * @chip: device identifier of the dongle chip.
131 * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.
132 * @wowl_supported: is wowl supported by bus driver.
133 * @chiprev: revision of the dongle chip.
134 * @msgbuf: msgbuf protocol parameters provided by bus layer.
138 struct brcmf_sdio_dev *sdio;
139 struct brcmf_usbdev *usb;
140 struct brcmf_pciedev *pcie;
142 enum brcmf_bus_protocol_type proto_type;
144 struct brcmf_pub *drvr;
145 enum brcmf_bus_state state;
146 struct brcmf_bus_stats stats;
150 bool always_use_fws_queue;
153 const struct brcmf_bus_ops *ops;
154 struct brcmf_bus_msgbuf *msgbuf;
160 static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
162 if (!bus->ops->preinit)
164 return bus->ops->preinit(bus->dev);
167 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
169 bus->ops->stop(bus->dev);
172 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
174 return bus->ops->txdata(bus->dev, skb);
178 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
180 return bus->ops->txctl(bus->dev, msg, len);
184 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
186 return bus->ops->rxctl(bus->dev, msg, len);
190 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
192 if (!bus->ops->gettxq)
193 return ERR_PTR(-ENOENT);
195 return bus->ops->gettxq(bus->dev);
199 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
201 if (bus->ops->wowl_config)
202 bus->ops->wowl_config(bus->dev, enabled);
205 static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
207 if (!bus->ops->get_ramsize)
210 return bus->ops->get_ramsize(bus->dev);
214 int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
216 if (!bus->ops->get_memdump)
219 return bus->ops->get_memdump(bus->dev, data, len);
223 int brcmf_bus_get_fwname(struct brcmf_bus *bus, const char *ext,
224 unsigned char *fw_name)
226 return bus->ops->get_fwname(bus->dev, ext, fw_name, false);
230 int brcmf_bus_get_board_fwname(struct brcmf_bus *bus, const char *ext,
231 unsigned char *fw_name)
233 return bus->ops->get_fwname(bus->dev, ext, fw_name, true);
237 void brcmf_bus_debugfs_create(struct brcmf_bus *bus)
239 if (!bus->ops->debugfs_create)
242 return bus->ops->debugfs_create(bus->dev);
246 int brcmf_bus_reset(struct brcmf_bus *bus)
248 if (!bus->ops->reset)
251 return bus->ops->reset(bus->dev);
255 * interface functions from common layer
258 /* Receive frame for delivery to OS. Callee disposes of rxp. */
259 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event,
261 /* Receive async event packet from firmware. Callee disposes of rxp. */
262 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
264 int brcmf_alloc(struct device *dev, struct brcmf_mp_device *settings);
265 /* Indication from bus module regarding presence/insertion of dongle. */
266 int brcmf_attach(struct device *dev);
267 /* Indication from bus module regarding removal/absence of dongle */
268 void brcmf_detach(struct device *dev);
269 void brcmf_free(struct device *dev);
270 /* Indication from bus module that dongle should be reset */
271 void brcmf_dev_reset(struct device *dev);
272 /* Request from bus module to initiate a coredump */
273 void brcmf_dev_coredump(struct device *dev);
274 /* Indication that firmware has halted or crashed */
275 void brcmf_fw_crashed(struct device *dev);
277 /* Configure the "global" bus state used by upper layers */
278 void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
280 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
281 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
283 #ifdef CONFIG_BRCMFMAC_SDIO
284 void brcmf_sdio_exit(void);
285 int brcmf_sdio_register(void);
287 static inline void brcmf_sdio_exit(void) { }
288 static inline int brcmf_sdio_register(void) { return 0; }
291 #ifdef CONFIG_BRCMFMAC_USB
292 void brcmf_usb_exit(void);
293 int brcmf_usb_register(void);
295 static inline void brcmf_usb_exit(void) { }
296 static inline int brcmf_usb_register(void) { return 0; }
299 #ifdef CONFIG_BRCMFMAC_PCIE
300 void brcmf_pcie_exit(void);
301 int brcmf_pcie_register(void);
303 static inline void brcmf_pcie_exit(void) { }
304 static inline int brcmf_pcie_register(void) { return 0; }
307 #endif /* BRCMFMAC_BUS_H */