bus.h 8.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (c) 2010 Broadcom Corporation
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

17 18
#ifndef BRCMFMAC_BUS_H
#define BRCMFMAC_BUS_H
19

20
#include "debug.h"
21

22 23 24
/* IDs of the 6 default common rings of msgbuf protocol */
#define BRCMF_H2D_MSGRING_CONTROL_SUBMIT	0
#define BRCMF_H2D_MSGRING_RXPOST_SUBMIT		1
25
#define BRCMF_H2D_MSGRING_FLOWRING_IDSTART	2
26 27 28 29
#define BRCMF_D2H_MSGRING_CONTROL_COMPLETE	2
#define BRCMF_D2H_MSGRING_TX_COMPLETE		3
#define BRCMF_D2H_MSGRING_RX_COMPLETE		4

30

31 32 33 34 35
#define BRCMF_NROF_H2D_COMMON_MSGRINGS		2
#define BRCMF_NROF_D2H_COMMON_MSGRINGS		3
#define BRCMF_NROF_COMMON_MSGRINGS	(BRCMF_NROF_H2D_COMMON_MSGRINGS + \
					 BRCMF_NROF_D2H_COMMON_MSGRINGS)

36 37 38
/* The level of bus communication with the dongle */
enum brcmf_bus_state {
	BRCMF_BUS_DOWN,		/* Not ready for frame transfers */
39
	BRCMF_BUS_UP		/* Ready for frame transfers */
40 41
};

42 43 44 45 46 47
/* The level of bus communication with the dongle */
enum brcmf_bus_protocol_type {
	BRCMF_PROTO_BCDC,
	BRCMF_PROTO_MSGBUF
};

48 49
struct brcmf_mp_device;

50 51 52 53 54 55 56
struct brcmf_bus_dcmd {
	char *name;
	char *param;
	int param_len;
	struct list_head list;
};

A
Arend van Spriel 已提交
57 58 59
/**
 * struct brcmf_bus_ops - bus callback operations.
 *
60
 * @preinit: execute bus/device specific dongle init commands (optional).
A
Arend van Spriel 已提交
61 62
 * @init: prepare for communication with dongle.
 * @stop: clear pending frames, disable data flow.
63 64 65 66 67
 * @txdata: send a data frame to the dongle. When the data
 *	has been transferred, the common driver must be
 *	notified using brcmf_txcomplete(). The common
 *	driver calls this function with interrupts
 *	disabled.
A
Arend van Spriel 已提交
68 69
 * @txctl: transmit a control request message to dongle.
 * @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 73
 * @get_ramsize: obtain size of device memory.
 * @get_memdump: obtain device memory dump in provided buffer.
74
 * @get_fwname: obtain firmware name.
A
Arend van Spriel 已提交
75 76 77
 *
 * This structure provides an abstract interface towards the
 * bus specific driver. For control messages to common driver
78 79
 * will assure there is only one active transaction. Unless
 * indicated otherwise these callbacks are mandatory.
A
Arend van Spriel 已提交
80 81
 */
struct brcmf_bus_ops {
82
	int (*preinit)(struct device *dev);
A
Arend van Spriel 已提交
83 84 85 86
	void (*stop)(struct device *dev);
	int (*txdata)(struct device *dev, struct sk_buff *skb);
	int (*txctl)(struct device *dev, unsigned char *msg, uint len);
	int (*rxctl)(struct device *dev, unsigned char *msg, uint len);
87
	struct pktq * (*gettxq)(struct device *dev);
88
	void (*wowl_config)(struct device *dev, bool enabled);
89 90
	size_t (*get_ramsize)(struct device *dev);
	int (*get_memdump)(struct device *dev, void *data, size_t len);
91
	int (*get_fwname)(struct device *dev, const char *ext,
92
			  unsigned char *fw_name);
A
Arend van Spriel 已提交
93 94
};

95 96 97 98 99 100 101 102

/**
 * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf.
 *
 * @commonrings: commonrings which are always there.
 * @flowrings: commonrings which are dynamically created and destroyed for data.
 * @rx_dataoffset: if set then all rx data has this this offset.
 * @max_rxbufpost: maximum number of buffers to post for rx.
103 104 105
 * @max_flowrings: maximum number of tx flow rings supported.
 * @max_submissionrings: maximum number of submission rings(h2d) supported.
 * @max_completionrings: maximum number of completion rings(d2h) supported.
106 107 108 109 110 111
 */
struct brcmf_bus_msgbuf {
	struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS];
	struct brcmf_commonring **flowrings;
	u32 rx_dataoffset;
	u32 max_rxbufpost;
112 113 114
	u16 max_flowrings;
	u16 max_submissionrings;
	u16 max_completionrings;
115 116 117
};


118 119 120 121 122 123 124 125 126 127 128
/**
 * struct brcmf_bus_stats - bus statistic counters.
 *
 * @pktcowed: packets cowed for extra headroom/unorphan.
 * @pktcow_failed: packets dropped due to failed cow-ing.
 */
struct brcmf_bus_stats {
	atomic_t pktcowed;
	atomic_t pktcow_failed;
};

A
Arend van Spriel 已提交
129 130 131 132
/**
 * struct brcmf_bus - interface structure between common and bus layer
 *
 * @bus_priv: pointer to private bus device.
133
 * @proto_type: protocol type, bcdc or msgbuf
A
Arend van Spriel 已提交
134 135 136
 * @dev: device pointer of bus device.
 * @drvr: public driver information.
 * @state: operational state of the bus interface.
137
 * @stats: statistics shared between common and bus layer.
A
Arend van Spriel 已提交
138
 * @maxctl: maximum size for rxctl request message.
139
 * @chip: device identifier of the dongle chip.
140
 * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive.
141
 * @wowl_supported: is wowl supported by bus driver.
142
 * @chiprev: revision of the dongle chip.
A
Arend van Spriel 已提交
143
 */
144
struct brcmf_bus {
145 146
	union {
		struct brcmf_sdio_dev *sdio;
147
		struct brcmf_usbdev *usb;
148
		struct brcmf_pciedev *pcie;
149
	} bus_priv;
150
	enum brcmf_bus_protocol_type proto_type;
A
Arend van Spriel 已提交
151 152
	struct device *dev;
	struct brcmf_pub *drvr;
153
	enum brcmf_bus_state state;
154
	struct brcmf_bus_stats stats;
A
Arend van Spriel 已提交
155
	uint maxctl;
156 157
	u32 chip;
	u32 chiprev;
158
	bool always_use_fws_queue;
159
	bool wowl_supported;
160

161
	const struct brcmf_bus_ops *ops;
162
	struct brcmf_bus_msgbuf *msgbuf;
163 164
};

A
Arend van Spriel 已提交
165 166 167
/*
 * callback wrappers
 */
168 169 170 171 172 173 174
static inline int brcmf_bus_preinit(struct brcmf_bus *bus)
{
	if (!bus->ops->preinit)
		return 0;
	return bus->ops->preinit(bus->dev);
}

A
Arend van Spriel 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
static inline void brcmf_bus_stop(struct brcmf_bus *bus)
{
	bus->ops->stop(bus->dev);
}

static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb)
{
	return bus->ops->txdata(bus->dev, skb);
}

static inline
int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
{
	return bus->ops->txctl(bus->dev, msg, len);
}

static inline
int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len)
{
	return bus->ops->rxctl(bus->dev, msg, len);
}

197 198 199 200 201 202 203 204
static inline
struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus)
{
	if (!bus->ops->gettxq)
		return ERR_PTR(-ENOENT);

	return bus->ops->gettxq(bus->dev);
}
205

206 207 208 209 210 211 212
static inline
void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled)
{
	if (bus->ops->wowl_config)
		bus->ops->wowl_config(bus->dev, enabled);
}

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus)
{
	if (!bus->ops->get_ramsize)
		return 0;

	return bus->ops->get_ramsize(bus->dev);
}

static inline
int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len)
{
	if (!bus->ops->get_memdump)
		return -EOPNOTSUPP;

	return bus->ops->get_memdump(bus->dev, data, len);
}

230
static inline
231
int brcmf_bus_get_fwname(struct brcmf_bus *bus, const char *ext,
232 233
			 unsigned char *fw_name)
{
234
	return bus->ops->get_fwname(bus->dev, ext, fw_name);
235 236
}

237 238 239 240 241
/*
 * interface functions from common layer
 */

/* Receive frame for delivery to OS.  Callee disposes of rxp. */
242
void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event);
243 244
/* Receive async event packet from firmware. Callee disposes of rxp. */
void brcmf_rx_event(struct device *dev, struct sk_buff *rxp);
245 246

/* Indication from bus module regarding presence/insertion of dongle. */
247
int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings);
248
/* Indication from bus module regarding removal/absence of dongle */
249
void brcmf_detach(struct device *dev);
250
/* Indication from bus module that dongle should be reset */
251
void brcmf_dev_reset(struct device *dev);
252

253 254 255
/* Configure the "global" bus state used by upper layers */
void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state);

256
s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len);
257
void brcmf_bus_add_txhdrlen(struct device *dev, uint len);
258

259
#ifdef CONFIG_BRCMFMAC_SDIO
260
void brcmf_sdio_exit(void);
261
void brcmf_sdio_register(void);
262
#endif
263
#ifdef CONFIG_BRCMFMAC_USB
264
void brcmf_usb_exit(void);
265
void brcmf_usb_register(void);
266
#endif
267

268
#endif /* BRCMFMAC_BUS_H */