]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/wireless/brcm80211/brcmfmac/dhd_bus.h
Merge branch 'for-john' of git://git.kernel.org/pub/scm/linux/kernel/git/jberg/mac802...
[karo-tx-linux.git] / drivers / net / wireless / brcm80211 / brcmfmac / dhd_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 _BRCMF_BUS_H_
18 #define _BRCMF_BUS_H_
19
20 /* The level of bus communication with the dongle */
21 enum brcmf_bus_state {
22         BRCMF_BUS_DOWN,         /* Not ready for frame transfers */
23         BRCMF_BUS_LOAD,         /* Download access only (CPU reset) */
24         BRCMF_BUS_DATA          /* Ready for frame transfers */
25 };
26
27 /* The level of bus communication with the dongle */
28 enum brcmf_bus_protocol_type {
29         BRCMF_PROTO_BCDC,
30         BRCMF_PROTO_MSGBUF
31 };
32
33 struct brcmf_bus_dcmd {
34         char *name;
35         char *param;
36         int param_len;
37         struct list_head list;
38 };
39
40 /**
41  * struct brcmf_bus_ops - bus callback operations.
42  *
43  * @preinit: execute bus/device specific dongle init commands (optional).
44  * @init: prepare for communication with dongle.
45  * @stop: clear pending frames, disable data flow.
46  * @txdata: send a data frame to the dongle. When the data
47  *      has been transferred, the common driver must be
48  *      notified using brcmf_txcomplete(). The common
49  *      driver calls this function with interrupts
50  *      disabled.
51  * @txctl: transmit a control request message to dongle.
52  * @rxctl: receive a control response message from dongle.
53  * @gettxq: obtain a reference of bus transmit queue (optional).
54  *
55  * This structure provides an abstract interface towards the
56  * bus specific driver. For control messages to common driver
57  * will assure there is only one active transaction. Unless
58  * indicated otherwise these callbacks are mandatory.
59  */
60 struct brcmf_bus_ops {
61         int (*preinit)(struct device *dev);
62         int (*init)(struct device *dev);
63         void (*stop)(struct device *dev);
64         int (*txdata)(struct device *dev, struct sk_buff *skb);
65         int (*txctl)(struct device *dev, unsigned char *msg, uint len);
66         int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
67         struct pktq * (*gettxq)(struct device *dev);
68 };
69
70 /**
71  * struct brcmf_bus - interface structure between common and bus layer
72  *
73  * @bus_priv: pointer to private bus device.
74  * @proto_type: protocol type, bcdc or msgbuf
75  * @dev: device pointer of bus device.
76  * @drvr: public driver information.
77  * @state: operational state of the bus interface.
78  * @maxctl: maximum size for rxctl request message.
79  * @tx_realloc: number of tx packets realloced for headroom.
80  * @dstats: dongle-based statistical data.
81  * @dcmd_list: bus/device specific dongle initialization commands.
82  * @chip: device identifier of the dongle chip.
83  * @chiprev: revision of the dongle chip.
84  */
85 struct brcmf_bus {
86         union {
87                 struct brcmf_sdio_dev *sdio;
88                 struct brcmf_usbdev *usb;
89         } bus_priv;
90         enum brcmf_bus_protocol_type proto_type;
91         struct device *dev;
92         struct brcmf_pub *drvr;
93         enum brcmf_bus_state state;
94         uint maxctl;
95         unsigned long tx_realloc;
96         u32 chip;
97         u32 chiprev;
98
99         struct brcmf_bus_ops *ops;
100 };
101
102 /*
103  * callback wrappers
104  */
105 static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
106 {
107         if (!bus->ops->preinit)
108                 return 0;
109         return bus->ops->preinit(bus->dev);
110 }
111
112 static inline int brcmf_bus_init(struct brcmf_bus *bus)
113 {
114         return bus->ops->init(bus->dev);
115 }
116
117 static inline void brcmf_bus_stop(struct brcmf_bus *bus)
118 {
119         bus->ops->stop(bus->dev);
120 }
121
122 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
123 {
124         return bus->ops->txdata(bus->dev, skb);
125 }
126
127 static inline
128 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
129 {
130         return bus->ops->txctl(bus->dev, msg, len);
131 }
132
133 static inline
134 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
135 {
136         return bus->ops->rxctl(bus->dev, msg, len);
137 }
138
139 static inline
140 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
141 {
142         if (!bus->ops->gettxq)
143                 return ERR_PTR(-ENOENT);
144
145         return bus->ops->gettxq(bus->dev);
146 }
147 /*
148  * interface functions from common layer
149  */
150
151 bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt,
152                       int prec);
153
154 /* Receive frame for delivery to OS.  Callee disposes of rxp. */
155 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp);
156
157 /* Indication from bus module regarding presence/insertion of dongle. */
158 int brcmf_attach(struct device *dev);
159 /* Indication from bus module regarding removal/absence of dongle */
160 void brcmf_detach(struct device *dev);
161 /* Indication from bus module that dongle should be reset */
162 void brcmf_dev_reset(struct device *dev);
163 /* Indication from bus module to change flow-control state */
164 void brcmf_txflowblock(struct device *dev, bool state);
165
166 /* Notify the bus has transferred the tx packet to firmware */
167 void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success);
168
169 int brcmf_bus_start(struct device *dev);
170 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data,
171                                 u32 len);
172 void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
173
174 #ifdef CONFIG_BRCMFMAC_SDIO
175 void brcmf_sdio_exit(void);
176 void brcmf_sdio_init(void);
177 void brcmf_sdio_register(void);
178 #endif
179 #ifdef CONFIG_BRCMFMAC_USB
180 void brcmf_usb_exit(void);
181 void brcmf_usb_register(void);
182 #endif
183
184 #endif                          /* _BRCMF_BUS_H_ */