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_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 29 30 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) 35 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 */ 40 }; 41 42 /* The level of bus communication with the dongle */ 43 enum brcmf_bus_protocol_type { 44 BRCMF_PROTO_BCDC, 45 BRCMF_PROTO_MSGBUF 46 }; 47 48 struct brcmf_mp_device; 49 50 struct brcmf_bus_dcmd { 51 char *name; 52 char *param; 53 int param_len; 54 struct list_head list; 55 }; 56 57 /** 58 * struct brcmf_bus_ops - bus callback operations. 59 * 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 67 * disabled. 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. 74 * @get_fwname: obtain firmware name. 75 * 76 * This structure provides an abstract interface towards the 77 * bus specific driver. For control messages to common driver 78 * will assure there is only one active transaction. Unless 79 * indicated otherwise these callbacks are mandatory. 80 */ 81 struct brcmf_bus_ops { 82 int (*preinit)(struct device *dev); 83 void (*stop)(struct device *dev); 84 int (*txdata)(struct device *dev, struct sk_buff *skb); 85 int (*txctl)(struct device *dev, unsigned char *msg, uint len); 86 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 size_t (*get_ramsize)(struct device *dev); 90 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); 93 void (*debugfs_create)(struct device *dev); 94 int (*reset)(struct device *dev); 95 }; 96 97 98 /** 99 * struct brcmf_bus_msgbuf - bus ringbuf if in case of msgbuf. 100 * 101 * @commonrings: commonrings which are always there. 102 * @flowrings: commonrings which are dynamically created and destroyed for data. 103 * @rx_dataoffset: if set then all rx data has this this offset. 104 * @max_rxbufpost: maximum number of buffers to post for rx. 105 * @max_flowrings: maximum number of tx flow rings supported. 106 * @max_submissionrings: maximum number of submission rings(h2d) supported. 107 * @max_completionrings: maximum number of completion rings(d2h) supported. 108 */ 109 struct brcmf_bus_msgbuf { 110 struct brcmf_commonring *commonrings[BRCMF_NROF_COMMON_MSGRINGS]; 111 struct brcmf_commonring **flowrings; 112 u32 rx_dataoffset; 113 u32 max_rxbufpost; 114 u16 max_flowrings; 115 u16 max_submissionrings; 116 u16 max_completionrings; 117 }; 118 119 120 /** 121 * struct brcmf_bus_stats - bus statistic counters. 122 * 123 * @pktcowed: packets cowed for extra headroom/unorphan. 124 * @pktcow_failed: packets dropped due to failed cow-ing. 125 */ 126 struct brcmf_bus_stats { 127 atomic_t pktcowed; 128 atomic_t pktcow_failed; 129 }; 130 131 /** 132 * struct brcmf_bus - interface structure between common and bus layer 133 * 134 * @bus_priv: pointer to private bus device. 135 * @proto_type: protocol type, bcdc or msgbuf 136 * @dev: device pointer of bus device. 137 * @drvr: public driver information. 138 * @state: operational state of the bus interface. 139 * @stats: statistics shared between common and bus layer. 140 * @maxctl: maximum size for rxctl request message. 141 * @chip: device identifier of the dongle chip. 142 * @always_use_fws_queue: bus wants use queue also when fwsignal is inactive. 143 * @wowl_supported: is wowl supported by bus driver. 144 * @chiprev: revision of the dongle chip. 145 * @msgbuf: msgbuf protocol parameters provided by bus layer. 146 */ 147 struct brcmf_bus { 148 union { 149 struct brcmf_sdio_dev *sdio; 150 struct brcmf_usbdev *usb; 151 struct brcmf_pciedev *pcie; 152 } bus_priv; 153 enum brcmf_bus_protocol_type proto_type; 154 struct device *dev; 155 struct brcmf_pub *drvr; 156 enum brcmf_bus_state state; 157 struct brcmf_bus_stats stats; 158 uint maxctl; 159 u32 chip; 160 u32 chiprev; 161 bool always_use_fws_queue; 162 bool wowl_supported; 163 164 const struct brcmf_bus_ops *ops; 165 struct brcmf_bus_msgbuf *msgbuf; 166 }; 167 168 /* 169 * callback wrappers 170 */ 171 static inline int brcmf_bus_preinit(struct brcmf_bus *bus) 172 { 173 if (!bus->ops->preinit) 174 return 0; 175 return bus->ops->preinit(bus->dev); 176 } 177 178 static inline void brcmf_bus_stop(struct brcmf_bus *bus) 179 { 180 bus->ops->stop(bus->dev); 181 } 182 183 static inline int brcmf_bus_txdata(struct brcmf_bus *bus, struct sk_buff *skb) 184 { 185 return bus->ops->txdata(bus->dev, skb); 186 } 187 188 static inline 189 int brcmf_bus_txctl(struct brcmf_bus *bus, unsigned char *msg, uint len) 190 { 191 return bus->ops->txctl(bus->dev, msg, len); 192 } 193 194 static inline 195 int brcmf_bus_rxctl(struct brcmf_bus *bus, unsigned char *msg, uint len) 196 { 197 return bus->ops->rxctl(bus->dev, msg, len); 198 } 199 200 static inline 201 struct pktq *brcmf_bus_gettxq(struct brcmf_bus *bus) 202 { 203 if (!bus->ops->gettxq) 204 return ERR_PTR(-ENOENT); 205 206 return bus->ops->gettxq(bus->dev); 207 } 208 209 static inline 210 void brcmf_bus_wowl_config(struct brcmf_bus *bus, bool enabled) 211 { 212 if (bus->ops->wowl_config) 213 bus->ops->wowl_config(bus->dev, enabled); 214 } 215 216 static inline size_t brcmf_bus_get_ramsize(struct brcmf_bus *bus) 217 { 218 if (!bus->ops->get_ramsize) 219 return 0; 220 221 return bus->ops->get_ramsize(bus->dev); 222 } 223 224 static inline 225 int brcmf_bus_get_memdump(struct brcmf_bus *bus, void *data, size_t len) 226 { 227 if (!bus->ops->get_memdump) 228 return -EOPNOTSUPP; 229 230 return bus->ops->get_memdump(bus->dev, data, len); 231 } 232 233 static inline 234 int brcmf_bus_get_fwname(struct brcmf_bus *bus, const char *ext, 235 unsigned char *fw_name) 236 { 237 return bus->ops->get_fwname(bus->dev, ext, fw_name); 238 } 239 240 static inline 241 void brcmf_bus_debugfs_create(struct brcmf_bus *bus) 242 { 243 if (!bus->ops->debugfs_create) 244 return; 245 246 return bus->ops->debugfs_create(bus->dev); 247 } 248 249 static inline 250 int brcmf_bus_reset(struct brcmf_bus *bus) 251 { 252 if (!bus->ops->reset) 253 return -EOPNOTSUPP; 254 255 return bus->ops->reset(bus->dev); 256 } 257 258 /* 259 * interface functions from common layer 260 */ 261 262 /* Receive frame for delivery to OS. Callee disposes of rxp. */ 263 void brcmf_rx_frame(struct device *dev, struct sk_buff *rxp, bool handle_event); 264 /* Receive async event packet from firmware. Callee disposes of rxp. */ 265 void brcmf_rx_event(struct device *dev, struct sk_buff *rxp); 266 267 /* Indication from bus module regarding presence/insertion of dongle. */ 268 int brcmf_attach(struct device *dev, struct brcmf_mp_device *settings); 269 /* Indication from bus module regarding removal/absence of dongle */ 270 void brcmf_detach(struct device *dev); 271 /* Indication from bus module that dongle should be reset */ 272 void brcmf_dev_reset(struct device *dev); 273 /* Request from bus module to initiate a coredump */ 274 void brcmf_dev_coredump(struct device *dev); 275 /* Indication that firmware has halted or crashed */ 276 void brcmf_fw_crashed(struct device *dev); 277 278 /* Configure the "global" bus state used by upper layers */ 279 void brcmf_bus_change_state(struct brcmf_bus *bus, enum brcmf_bus_state state); 280 281 s32 brcmf_iovar_data_set(struct device *dev, char *name, void *data, u32 len); 282 void brcmf_bus_add_txhdrlen(struct device *dev, uint len); 283 284 #ifdef CONFIG_BRCMFMAC_SDIO 285 void brcmf_sdio_exit(void); 286 void brcmf_sdio_register(void); 287 #endif 288 #ifdef CONFIG_BRCMFMAC_USB 289 void brcmf_usb_exit(void); 290 void brcmf_usb_register(void); 291 #endif 292 293 #endif /* BRCMFMAC_BUS_H */ 294