Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[cascardo/linux.git] / drivers / net / wireless / brcm80211 / brcmfmac / bus.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
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.
7  *
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.
15  */
16
17 #ifndef BRCMFMAC_BUS_H
18 #define BRCMFMAC_BUS_H
19
20 #include "debug.h"
21
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_D2H_MSGRING_CONTROL_COMPLETE      2
26 #define BRCMF_D2H_MSGRING_TX_COMPLETE           3
27 #define BRCMF_D2H_MSGRING_RX_COMPLETE           4
28
29 #define BRCMF_NROF_H2D_COMMON_MSGRINGS          2
30 #define BRCMF_NROF_D2H_COMMON_MSGRINGS          3
31 #define BRCMF_NROF_COMMON_MSGRINGS      (BRCMF_NROF_H2D_COMMON_MSGRINGS + \
32                                          BRCMF_NROF_D2H_COMMON_MSGRINGS)
33
34 /* The level of bus communication with the dongle */
35 enum brcmf_bus_state {
36         BRCMF_BUS_UNKNOWN,      /* Not determined yet */
37         BRCMF_BUS_NOMEDIUM,     /* No medium access to dongle */
38         BRCMF_BUS_DOWN,         /* Not ready for frame transfers */
39         BRCMF_BUS_LOAD,         /* Download access only (CPU reset) */
40         BRCMF_BUS_DATA          /* Ready for frame transfers */
41 };
42
43 /* The level of bus communication with the dongle */
44 enum brcmf_bus_protocol_type {
45         BRCMF_PROTO_BCDC,
46         BRCMF_PROTO_MSGBUF
47 };
48
49 struct brcmf_bus_dcmd {
50         char *name;
51         char *param;
52         int param_len;
53         struct list_head list;
54 };
55
56 /**
57  * struct brcmf_bus_ops - bus callback operations.
58  *
59  * @preinit: execute bus/device specific dongle init commands (optional).
60  * @init: prepare for communication with dongle.
61  * @stop: clear pending frames, disable data flow.
62  * @txdata: send a data frame to the dongle. When the data
63  *      has been transferred, the common driver must be
64  *      notified using brcmf_txcomplete(). The common
65  *      driver calls this function with interrupts
66  *      disabled.
67  * @txctl: transmit a control request message to dongle.
68  * @rxctl: receive a control response message from dongle.
69  * @gettxq: obtain a reference of bus transmit queue (optional).
70  * @wowl_config: specify if dongle is configured for wowl when going to suspend
71  *
72  * This structure provides an abstract interface towards the
73  * bus specific driver. For control messages to common driver
74  * will assure there is only one active transaction. Unless
75  * indicated otherwise these callbacks are mandatory.
76  */
77 struct brcmf_bus_ops {
78         int (*preinit)(struct device *dev);
79         void (*stop)(struct device *dev);
80         int (*txdata)(struct device *dev, struct sk_buff *skb);
81         int (*txctl)(struct device *dev, unsigned char *msg, uint len);
82         int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
83         struct pktq * (*gettxq)(struct device *dev);
84         void (*wowl_config)(struct device *dev, bool enabled);
85 };
86
87
88 /**
89  * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
90  *
91  * @commonrings: commonrings which are always there.
92  * @flowrings: commonrings which are dynamically created and destroyed for data.
93  * @rx_dataoffset: if set then all rx data has this this offset.
94  * @max_rxbufpost: maximum number of buffers to post for rx.
95  * @nrof_flowrings: number of flowrings.
96  */
97 struct brcmf_bus_msgbuf {
98         struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
99         struct brcmf_commonring **flowrings;
100         u32 rx_dataoffset;
101         u32 max_rxbufpost;
102         u32 nrof_flowrings;
103 };
104
105
106 /**
107  * struct brcmf_bus - interface structure between common and bus layer
108  *
109  * @bus_priv: pointer to private bus device.
110  * @proto_type: protocol type, bcdc or msgbuf
111  * @dev: device pointer of bus device.
112  * @drvr: public driver information.
113  * @state: operational state of the bus interface.
114  * @maxctl: maximum size for rxctl request message.
115  * @tx_realloc: number of tx packets realloced for headroom.
116  * @dstats: dongle-based statistical data.
117  * @dcmd_list: bus/device specific dongle initialization commands.
118  * @chip: device identifier of the dongle chip.
119  * @wowl_supported: is wowl supported by bus driver.
120  * @chiprev: revision of the dongle chip.
121  */
122 struct brcmf_bus {
123         union {
124                 struct brcmf_sdio_dev *sdio;
125                 struct brcmf_usbdev *usb;
126                 struct brcmf_pciedev *pcie;
127         } bus_priv;
128         enum brcmf_bus_protocol_type proto_type;
129         struct device *dev;
130         struct brcmf_pub *drvr;
131         enum brcmf_bus_state state;
132         uint maxctl;
133         unsigned long tx_realloc;
134         u32 chip;
135         u32 chiprev;
136         bool always_use_fws_queue;
137         bool wowl_supported;
138
139         struct brcmf_bus_ops *ops;
140         struct brcmf_bus_msgbuf *msgbuf;
141 };
142
143 /*
144  * callback wrappers
145  */
146 static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
147 {
148         if (!bus->ops->preinit)
149                 return 0;
150         return bus->ops->preinit(bus->dev);
151 }
152
153 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
154 {
155         bus->ops->stop(bus->dev);
156 }
157
158 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
159 {
160         return bus->ops->txdata(bus->dev, skb);
161 }
162
163 static inline
164 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
165 {
166         return bus->ops->txctl(bus->dev, msg, len);
167 }
168
169 static inline
170 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
171 {
172         return bus->ops->rxctl(bus->dev, msg, len);
173 }
174
175 static inline
176 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
177 {
178         if (!bus->ops->gettxq)
179                 return ERR_PTR(-ENOENT);
180
181         return bus->ops->gettxq(bus->dev);
182 }
183
184 static inline
185 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
186 {
187         if (bus->ops->wowl_config)
188                 bus->ops->wowl_config(bus->dev, enabled);
189 }
190
191 static inline bool brcmf_bus_ready(struct brcmf_bus *bus)
192 {
193         return bus->state == BRCMF_BUS_LOAD || bus->state == BRCMF_BUS_DATA;
194 }
195
196 static inline void brcmf_bus_change_state(struct brcmf_bus *bus,
197                                           enum brcmf_bus_state new_state)
198 {
199         /* NOMEDIUM is permanent */
200         if (bus->state == BRCMF_BUS_NOMEDIUM)
201                 return;
202
203         brcmf_dbg(TRACE, "%d -> %d\n", bus->state, new_state);
204         bus->state = new_state;
205 }
206
207 /*
208  * interface functions from common layer
209  */
210
211 bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
212                       int prec);
213
214 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
215 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
216
217 /* Indication from bus module regarding presence/insertion of dongle. */
218 int brcmf_attach(struct device *dev);
219 /* Indication from bus module regarding removal/absence of dongle */
220 void brcmf_detach(struct device *dev);
221 /* Indication from bus module that dongle should be reset */
222 void brcmf_dev_reset(struct device *dev);
223 /* Indication from bus module to change flow-control state */
224 void brcmf_txflowblock(struct device *dev, bool state);
225
226 /* Notify the bus has transferred the tx packet to firmware */
227 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
228
229 int brcmf_bus_start(struct device *dev);
230 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
231 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
232
233 #ifdef CONFIG_BRCMFMAC_SDIO
234 void brcmf_sdio_exit(void);
235 void brcmf_sdio_init(void);
236 void brcmf_sdio_register(void);
237 #endif
238 #ifdef CONFIG_BRCMFMAC_USB
239 void brcmf_usb_exit(void);
240 void brcmf_usb_register(void);
241 #endif
242
243 #endif /* BRCMFMAC_BUS_H */