2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef BRCMFMAC_BUS_H
18 #define BRCMFMAC_BUS_H
22 /* IDs of the 6 default common rings of msgbuf protocol */
23 #define BRCMF_H2D_MSGRING_CONTROL_SUBMIT 0
24 #define BRCMF_H2D_MSGRING_RXPOST_SUBMIT 1
25 #define BRCMF_H2D_MSGRING_FLOWRING_IDSTART 2
26 #define BRCMF_D2H_MSGRING_CONTROL_COMPLETE 2
27 #define BRCMF_D2H_MSGRING_TX_COMPLETE 3
28 #define BRCMF_D2H_MSGRING_RX_COMPLETE 4
31 #define BRCMF_NROF_H2D_COMMON_MSGRINGS 2
32 #define BRCMF_NROF_D2H_COMMON_MSGRINGS 3
33 #define BRCMF_NROF_COMMON_MSGRINGS (BRCMF_NROF_H2D_COMMON_MSGRINGS + \
34 BRCMF_NROF_D2H_COMMON_MSGRINGS)
36 /* The level of bus communication with the dongle */
37 enum brcmf_bus_state {
38 BRCMF_BUS_DOWN, /* Not ready for frame transfers */
39 BRCMF_BUS_UP /* Ready for frame transfers */
42 /* The level of bus communication with the dongle */
43 enum brcmf_bus_protocol_type {
48 struct brcmf_mp_device;
50 struct brcmf_bus_dcmd {
54 struct list_head list;
58 * struct brcmf_bus_ops - bus callback operations.
60 * @preinit: execute bus/device specific dongle init commands (optional).
61 * @init: prepare for communication with dongle.
62 * @stop: clear pending frames, disable data flow.
63 * @txdata: send a data frame to the dongle. When the data
64 * has been transferred, the common driver must be
65 * notified using brcmf_txcomplete(). The common
66 * driver calls this function with interrupts
68 * @txctl: transmit a control request message to dongle.
69 * @rxctl: receive a control response message from dongle.
70 * @gettxq: obtain a reference of bus transmit queue (optional).
71 * @wowl_config: specify if dongle is configured for wowl when going to suspend
72 * @get_ramsize: obtain size of device memory.
73 * @get_memdump: obtain device memory dump in provided buffer.
75 * This structure provides an abstract interface towards the
76 * bus specific driver. For control messages to common driver
77 * will assure there is only one active transaction. Unless
78 * indicated otherwise these callbacks are mandatory.
80 struct brcmf_bus_ops {
81 int (*preinit)(struct device *dev);
82 void (*stop)(struct device *dev);
83 int (*txdata)(struct device *dev, struct sk_buff *skb);
84 int (*txctl)(struct device *dev, unsigned char *msg, uint len);
85 int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
86 struct pktq * (*gettxq)(struct device *dev);
87 void (*wowl_config)(struct device *dev, bool enabled);
88 size_t (*get_ramsize)(struct device *dev);
89 int (*get_memdump)(struct device *dev, void *data, size_t len);
94 * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
96 * @commonrings: commonrings which are always there.
97 * @flowrings: commonrings which are dynamically created and destroyed for data.
98 * @rx_dataoffset: if set then all rx data has this this offset.
99 * @max_rxbufpost: maximum number of buffers to post for rx.
100 * @max_flowrings: maximum number of tx flow rings supported.
101 * @max_submissionrings: maximum number of submission rings(h2d) supported.
102 * @max_completionrings: maximum number of completion rings(d2h) supported.
104 struct brcmf_bus_msgbuf {
105 struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
106 struct brcmf_commonring **flowrings;
110 u16 max_submissionrings;
111 u16 max_completionrings;
116 * struct brcmf_bus - interface structure between common and bus layer
118 * @bus_priv: pointer to private bus device.
119 * @proto_type: protocol type, bcdc or msgbuf
120 * @dev: device pointer of bus device.
121 * @drvr: public driver information.
122 * @state: operational state of the bus interface.
123 * @maxctl: maximum size for rxctl request message.
124 * @tx_realloc: number of tx packets realloced for headroom.
125 * @chip: device identifier of the dongle chip.
126 * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.
127 * @wowl_supported: is wowl supported by bus driver.
128 * @chiprev: revision of the dongle chip.
132 struct brcmf_sdio_dev *sdio;
133 struct brcmf_usbdev *usb;
134 struct brcmf_pciedev *pcie;
136 enum brcmf_bus_protocol_type proto_type;
138 struct brcmf_pub *drvr;
139 enum brcmf_bus_state state;
141 unsigned long tx_realloc;
144 bool always_use_fws_queue;
147 const struct brcmf_bus_ops *ops;
148 struct brcmf_bus_msgbuf *msgbuf;
154 static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
156 if (!bus->ops->preinit)
158 return bus->ops->preinit(bus->dev);
161 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
163 bus->ops->stop(bus->dev);
166 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
168 return bus->ops->txdata(bus->dev, skb);
172 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
174 return bus->ops->txctl(bus->dev, msg, len);
178 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
180 return bus->ops->rxctl(bus->dev, msg, len);
184 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
186 if (!bus->ops->gettxq)
187 return ERR_PTR(-ENOENT);
189 return bus->ops->gettxq(bus->dev);
193 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
195 if (bus->ops->wowl_config)
196 bus->ops->wowl_config(bus->dev, enabled);
199 static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
201 if (!bus->ops->get_ramsize)
204 return bus->ops->get_ramsize(bus->dev);
208 int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
210 if (!bus->ops->get_memdump)
213 return bus->ops->get_memdump(bus->dev, data, len);
217 * interface functions from common layer
220 /* Receive frame for delivery to OS. Callee disposes of rxp. */
221 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event);
222 /* Receive async event packet from firmware. Callee disposes of rxp. */
223 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
225 /* Indication from bus module regarding presence/insertion of dongle. */
226 int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings);
227 /* Indication from bus module regarding removal/absence of dongle */
228 void brcmf_detach(struct device *dev);
229 /* Indication from bus module that dongle should be reset */
230 void brcmf_dev_reset(struct device *dev);
232 /* Configure the "global" bus state used by upper layers */
233 void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);
235 int brcmf_bus_started(struct device *dev);
236 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
237 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
239 #ifdef CONFIG_BRCMFMAC_SDIO
240 void brcmf_sdio_exit(void);
241 void brcmf_sdio_register(void);
243 #ifdef CONFIG_BRCMFMAC_USB
244 void brcmf_usb_exit(void);
245 void brcmf_usb_register(void);
248 #endif /* BRCMFMAC_BUS_H */