Commit | Line | Data |
---|---|---|
5b435de0 AS |
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 | ||
d14f78b9 HM |
17 | #ifndef BRCMFMAC_BUS_H |
18 | #define BRCMFMAC_BUS_H | |
5b435de0 | 19 | |
a8e8ed34 | 20 | #include "debug.h" |
bb350711 | 21 | |
9a1bb602 HM |
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 | ||
a8a363ac FL |
34 | /* The level of bus communication with the dongle */ |
35 | enum brcmf_bus_state { | |
36 | BRCMF_BUS_DOWN, /* Not ready for frame transfers */ | |
a1cee865 | 37 | BRCMF_BUS_UP /* Ready for frame transfers */ |
a8a363ac FL |
38 | }; |
39 | ||
943258b6 HM |
40 | /* The level of bus communication with the dongle */ |
41 | enum brcmf_bus_protocol_type { | |
42 | BRCMF_PROTO_BCDC, | |
43 | BRCMF_PROTO_MSGBUF | |
44 | }; | |
45 | ||
135e4c61 FL |
46 | struct brcmf_bus_dcmd { |
47 | char *name; | |
48 | char *param; | |
49 | int param_len; | |
50 | struct list_head list; | |
51 | }; | |
52 | ||
d9cb2596 AS |
53 | /** |
54 | * struct brcmf_bus_ops - bus callback operations. | |
55 | * | |
cf458287 | 56 | * @preinit: execute bus/device specific dongle init commands (optional). |
d9cb2596 AS |
57 | * @init: prepare for communication with dongle. |
58 | * @stop: clear pending frames, disable data flow. | |
4061f895 AS |
59 | * @txdata: send a data frame to the dongle. When the data |
60 | * has been transferred, the common driver must be | |
61 | * notified using brcmf_txcomplete(). The common | |
62 | * driver calls this function with interrupts | |
63 | * disabled. | |
d9cb2596 AS |
64 | * @txctl: transmit a control request message to dongle. |
65 | * @rxctl: receive a control response message from dongle. | |
e2432b67 | 66 | * @gettxq: obtain a reference of bus transmit queue (optional). |
4eb3af7c | 67 | * @wowl_config: specify if dongle is configured for wowl when going to suspend |
d9cb2596 AS |
68 | * |
69 | * This structure provides an abstract interface towards the | |
70 | * bus specific driver. For control messages to common driver | |
e2432b67 AS |
71 | * will assure there is only one active transaction. Unless |
72 | * indicated otherwise these callbacks are mandatory. | |
d9cb2596 AS |
73 | */ |
74 | struct brcmf_bus_ops { | |
cf458287 | 75 | int (*preinit)(struct device *dev); |
d9cb2596 AS |
76 | void (*stop)(struct device *dev); |
77 | int (*txdata)(struct device *dev, struct sk_buff *skb); | |
78 | int (*txctl)(struct device *dev, unsigned char *msg, uint len); | |
79 | int (*rxctl)(struct device *dev, unsigned char *msg, uint len); | |
e2432b67 | 80 | struct pktq * (*gettxq)(struct device *dev); |
4eb3af7c | 81 | void (*wowl_config)(struct device *dev, bool enabled); |
d9cb2596 AS |
82 | }; |
83 | ||
9a1bb602 HM |
84 | |
85 | /** | |
86 | * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf. | |
87 | * | |
88 | * @commonrings: commonrings which are always there. | |
89 | * @flowrings: commonrings which are dynamically created and destroyed for data. | |
90 | * @rx_dataoffset: if set then all rx data has this this offset. | |
91 | * @max_rxbufpost: maximum number of buffers to post for rx. | |
92 | * @nrof_flowrings: number of flowrings. | |
93 | */ | |
94 | struct brcmf_bus_msgbuf { | |
95 | struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS]; | |
96 | struct brcmf_commonring **flowrings; | |
97 | u32 rx_dataoffset; | |
98 | u32 max_rxbufpost; | |
99 | u32 nrof_flowrings; | |
100 | }; | |
101 | ||
102 | ||
d9cb2596 AS |
103 | /** |
104 | * struct brcmf_bus - interface structure between common and bus layer | |
105 | * | |
106 | * @bus_priv: pointer to private bus device. | |
943258b6 | 107 | * @proto_type: protocol type, bcdc or msgbuf |
d9cb2596 AS |
108 | * @dev: device pointer of bus device. |
109 | * @drvr: public driver information. | |
110 | * @state: operational state of the bus interface. | |
111 | * @maxctl: maximum size for rxctl request message. | |
d9cb2596 AS |
112 | * @tx_realloc: number of tx packets realloced for headroom. |
113 | * @dstats: dongle-based statistical data. | |
d9cb2596 | 114 | * @dcmd_list: bus/device specific dongle initialization commands. |
75d907d3 | 115 | * @chip: device identifier of the dongle chip. |
4eb3af7c | 116 | * @wowl_supported: is wowl supported by bus driver. |
75d907d3 | 117 | * @chiprev: revision of the dongle chip. |
d9cb2596 | 118 | */ |
a8a363ac | 119 | struct brcmf_bus { |
0a332e46 | 120 | union { |
0a332e46 | 121 | struct brcmf_sdio_dev *sdio; |
71bb244b | 122 | struct brcmf_usbdev *usb; |
9e37f045 | 123 | struct brcmf_pciedev *pcie; |
0a332e46 | 124 | } bus_priv; |
943258b6 | 125 | enum brcmf_bus_protocol_type proto_type; |
d9cb2596 AS |
126 | struct device *dev; |
127 | struct brcmf_pub *drvr; | |
a8a363ac | 128 | enum brcmf_bus_state state; |
d9cb2596 | 129 | uint maxctl; |
d9cb2596 | 130 | unsigned long tx_realloc; |
75d907d3 AS |
131 | u32 chip; |
132 | u32 chiprev; | |
9cd18359 | 133 | bool always_use_fws_queue; |
4eb3af7c | 134 | bool wowl_supported; |
a8a363ac | 135 | |
d9cb2596 | 136 | struct brcmf_bus_ops *ops; |
9a1bb602 | 137 | struct brcmf_bus_msgbuf *msgbuf; |
a8a363ac FL |
138 | }; |
139 | ||
d9cb2596 AS |
140 | /* |
141 | * callback wrappers | |
142 | */ | |
cf458287 AS |
143 | static inline int brcmf_bus_preinit(struct brcmf_bus *bus) |
144 | { | |
145 | if (!bus->ops->preinit) | |
146 | return 0; | |
147 | return bus->ops->preinit(bus->dev); | |
148 | } | |
149 | ||
d9cb2596 AS |
150 | static inline void brcmf_bus_stop(struct brcmf_bus *bus) |
151 | { | |
152 | bus->ops->stop(bus->dev); | |
153 | } | |
154 | ||
155 | static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb) | |
156 | { | |
157 | return bus->ops->txdata(bus->dev, skb); | |
158 | } | |
159 | ||
160 | static inline | |
161 | int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len) | |
162 | { | |
163 | return bus->ops->txctl(bus->dev, msg, len); | |
164 | } | |
165 | ||
166 | static inline | |
167 | int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len) | |
168 | { | |
169 | return bus->ops->rxctl(bus->dev, msg, len); | |
170 | } | |
171 | ||
e2432b67 AS |
172 | static inline |
173 | struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus) | |
174 | { | |
175 | if (!bus->ops->gettxq) | |
176 | return ERR_PTR(-ENOENT); | |
177 | ||
178 | return bus->ops->gettxq(bus->dev); | |
179 | } | |
bb350711 | 180 | |
4eb3af7c HM |
181 | static inline |
182 | void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled) | |
183 | { | |
184 | if (bus->ops->wowl_config) | |
185 | bus->ops->wowl_config(bus->dev, enabled); | |
186 | } | |
187 | ||
a8a363ac FL |
188 | /* |
189 | * interface functions from common layer | |
190 | */ | |
191 | ||
9bd91f3c JP |
192 | bool brcmf_c_prec_enq(struct device *dev, struct pktq *q, struct sk_buff *pkt, |
193 | int prec); | |
a8a363ac FL |
194 | |
195 | /* Receive frame for delivery to OS. Callee disposes of rxp. */ | |
7009deab | 196 | void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp); |
a8a363ac FL |
197 | |
198 | /* Indication from bus module regarding presence/insertion of dongle. */ | |
8dee77ba | 199 | int brcmf_attach(struct device *dev); |
a8a363ac | 200 | /* Indication from bus module regarding removal/absence of dongle */ |
9bd91f3c | 201 | void brcmf_detach(struct device *dev); |
81d5f1bb | 202 | /* Indication from bus module that dongle should be reset */ |
9bd91f3c | 203 | void brcmf_dev_reset(struct device *dev); |
a8a363ac | 204 | /* Indication from bus module to change flow-control state */ |
9bd91f3c | 205 | void brcmf_txflowblock(struct device *dev, bool state); |
a8a363ac | 206 | |
7f4bceec | 207 | /* Notify the bus has transferred the tx packet to firmware */ |
9bd91f3c | 208 | void brcmf_txcomplete(struct device *dev, struct sk_buff *txp, bool success); |
a8a363ac | 209 | |
649f38ae HM |
210 | /* Configure the "global" bus state used by upper layers */ |
211 | void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state); | |
212 | ||
9bd91f3c | 213 | int brcmf_bus_start(struct device *dev); |
d14f78b9 | 214 | s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len); |
8dee77ba | 215 | void brcmf_bus_add_txhdrlen(struct device *dev, uint len); |
a8a363ac | 216 | |
f3d7cdc3 | 217 | #ifdef CONFIG_BRCMFMAC_SDIO |
9bd91f3c JP |
218 | void brcmf_sdio_exit(void); |
219 | void brcmf_sdio_init(void); | |
4fbef95a | 220 | void brcmf_sdio_register(void); |
f3d7cdc3 | 221 | #endif |
71bb244b | 222 | #ifdef CONFIG_BRCMFMAC_USB |
9bd91f3c | 223 | void brcmf_usb_exit(void); |
4fbef95a | 224 | void brcmf_usb_register(void); |
71bb244b | 225 | #endif |
f3d7cdc3 | 226 | |
d14f78b9 | 227 | #endif /* BRCMFMAC_BUS_H */ |