Commit | Line | Data |
---|---|---|
9a1bb602 HM |
1 | /* Copyright (c) 2014 Broadcom Corporation |
2 | * | |
3 | * Permission to use, copy, modify, and/or distribute this software for any | |
4 | * purpose with or without fee is hereby granted, provided that the above | |
5 | * copyright notice and this permission notice appear in all copies. | |
6 | * | |
7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
14 | */ | |
15 | ||
16 | /******************************************************************************* | |
17 | * Communicates with the dongle by using dcmd codes. | |
18 | * For certain dcmd codes, the dongle interprets string data from the host. | |
19 | ******************************************************************************/ | |
20 | ||
21 | #include <linux/types.h> | |
22 | #include <linux/netdevice.h> | |
23 | ||
24 | #include <brcmu_utils.h> | |
25 | #include <brcmu_wifi.h> | |
26 | ||
122d3d04 | 27 | #include "core.h" |
a8e8ed34 | 28 | #include "debug.h" |
9a1bb602 HM |
29 | #include "proto.h" |
30 | #include "msgbuf.h" | |
31 | #include "commonring.h" | |
32 | #include "flowring.h" | |
d14f78b9 | 33 | #include "bus.h" |
9a1bb602 HM |
34 | #include "tracepoint.h" |
35 | ||
36 | ||
37 | #define MSGBUF_IOCTL_RESP_TIMEOUT 2000 | |
38 | ||
39 | #define MSGBUF_TYPE_GEN_STATUS 0x1 | |
40 | #define MSGBUF_TYPE_RING_STATUS 0x2 | |
41 | #define MSGBUF_TYPE_FLOW_RING_CREATE 0x3 | |
42 | #define MSGBUF_TYPE_FLOW_RING_CREATE_CMPLT 0x4 | |
43 | #define MSGBUF_TYPE_FLOW_RING_DELETE 0x5 | |
44 | #define MSGBUF_TYPE_FLOW_RING_DELETE_CMPLT 0x6 | |
45 | #define MSGBUF_TYPE_FLOW_RING_FLUSH 0x7 | |
46 | #define MSGBUF_TYPE_FLOW_RING_FLUSH_CMPLT 0x8 | |
47 | #define MSGBUF_TYPE_IOCTLPTR_REQ 0x9 | |
48 | #define MSGBUF_TYPE_IOCTLPTR_REQ_ACK 0xA | |
49 | #define MSGBUF_TYPE_IOCTLRESP_BUF_POST 0xB | |
50 | #define MSGBUF_TYPE_IOCTL_CMPLT 0xC | |
51 | #define MSGBUF_TYPE_EVENT_BUF_POST 0xD | |
52 | #define MSGBUF_TYPE_WL_EVENT 0xE | |
53 | #define MSGBUF_TYPE_TX_POST 0xF | |
54 | #define MSGBUF_TYPE_TX_STATUS 0x10 | |
55 | #define MSGBUF_TYPE_RXBUF_POST 0x11 | |
56 | #define MSGBUF_TYPE_RX_CMPLT 0x12 | |
57 | #define MSGBUF_TYPE_LPBK_DMAXFER 0x13 | |
58 | #define MSGBUF_TYPE_LPBK_DMAXFER_CMPLT 0x14 | |
59 | ||
60 | #define NR_TX_PKTIDS 2048 | |
61 | #define NR_RX_PKTIDS 1024 | |
62 | ||
63 | #define BRCMF_IOCTL_REQ_PKTID 0xFFFE | |
64 | ||
65 | #define BRCMF_MSGBUF_MAX_PKT_SIZE 2048 | |
66 | #define BRCMF_MSGBUF_RXBUFPOST_THRESHOLD 32 | |
67 | #define BRCMF_MSGBUF_MAX_IOCTLRESPBUF_POST 8 | |
68 | #define BRCMF_MSGBUF_MAX_EVENTBUF_POST 8 | |
69 | ||
70 | #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3 0x01 | |
71 | #define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5 | |
72 | ||
73 | #define BRCMF_MSGBUF_TX_FLUSH_CNT1 32 | |
74 | #define BRCMF_MSGBUF_TX_FLUSH_CNT2 96 | |
75 | ||
5ef1e604 HM |
76 | #define BRCMF_MSGBUF_DELAY_TXWORKER_THRS 64 |
77 | #define BRCMF_MSGBUF_TRICKLE_TXWORKER_THRS 32 | |
9a1bb602 HM |
78 | |
79 | struct msgbuf_common_hdr { | |
80 | u8 msgtype; | |
81 | u8 ifidx; | |
82 | u8 flags; | |
83 | u8 rsvd0; | |
84 | __le32 request_id; | |
85 | }; | |
86 | ||
87 | struct msgbuf_buf_addr { | |
88 | __le32 low_addr; | |
89 | __le32 high_addr; | |
90 | }; | |
91 | ||
92 | struct msgbuf_ioctl_req_hdr { | |
93 | struct msgbuf_common_hdr msg; | |
94 | __le32 cmd; | |
95 | __le16 trans_id; | |
96 | __le16 input_buf_len; | |
97 | __le16 output_buf_len; | |
98 | __le16 rsvd0[3]; | |
99 | struct msgbuf_buf_addr req_buf_addr; | |
100 | __le32 rsvd1[2]; | |
101 | }; | |
102 | ||
103 | struct msgbuf_tx_msghdr { | |
104 | struct msgbuf_common_hdr msg; | |
105 | u8 txhdr[ETH_HLEN]; | |
106 | u8 flags; | |
107 | u8 seg_cnt; | |
108 | struct msgbuf_buf_addr metadata_buf_addr; | |
109 | struct msgbuf_buf_addr data_buf_addr; | |
110 | __le16 metadata_buf_len; | |
111 | __le16 data_len; | |
112 | __le32 rsvd0; | |
113 | }; | |
114 | ||
115 | struct msgbuf_rx_bufpost { | |
116 | struct msgbuf_common_hdr msg; | |
117 | __le16 metadata_buf_len; | |
118 | __le16 data_buf_len; | |
119 | __le32 rsvd0; | |
120 | struct msgbuf_buf_addr metadata_buf_addr; | |
121 | struct msgbuf_buf_addr data_buf_addr; | |
122 | }; | |
123 | ||
124 | struct msgbuf_rx_ioctl_resp_or_event { | |
125 | struct msgbuf_common_hdr msg; | |
126 | __le16 host_buf_len; | |
127 | __le16 rsvd0[3]; | |
128 | struct msgbuf_buf_addr host_buf_addr; | |
129 | __le32 rsvd1[4]; | |
130 | }; | |
131 | ||
132 | struct msgbuf_completion_hdr { | |
133 | __le16 status; | |
134 | __le16 flow_ring_id; | |
135 | }; | |
136 | ||
137 | struct msgbuf_rx_event { | |
138 | struct msgbuf_common_hdr msg; | |
139 | struct msgbuf_completion_hdr compl_hdr; | |
140 | __le16 event_data_len; | |
141 | __le16 seqnum; | |
142 | __le16 rsvd0[4]; | |
143 | }; | |
144 | ||
145 | struct msgbuf_ioctl_resp_hdr { | |
146 | struct msgbuf_common_hdr msg; | |
147 | struct msgbuf_completion_hdr compl_hdr; | |
148 | __le16 resp_len; | |
149 | __le16 trans_id; | |
150 | __le32 cmd; | |
151 | __le32 rsvd0; | |
152 | }; | |
153 | ||
154 | struct msgbuf_tx_status { | |
155 | struct msgbuf_common_hdr msg; | |
156 | struct msgbuf_completion_hdr compl_hdr; | |
157 | __le16 metadata_len; | |
158 | __le16 tx_status; | |
159 | }; | |
160 | ||
161 | struct msgbuf_rx_complete { | |
162 | struct msgbuf_common_hdr msg; | |
163 | struct msgbuf_completion_hdr compl_hdr; | |
164 | __le16 metadata_len; | |
165 | __le16 data_len; | |
166 | __le16 data_offset; | |
167 | __le16 flags; | |
168 | __le32 rx_status_0; | |
169 | __le32 rx_status_1; | |
170 | __le32 rsvd0; | |
171 | }; | |
172 | ||
173 | struct msgbuf_tx_flowring_create_req { | |
174 | struct msgbuf_common_hdr msg; | |
175 | u8 da[ETH_ALEN]; | |
176 | u8 sa[ETH_ALEN]; | |
177 | u8 tid; | |
178 | u8 if_flags; | |
179 | __le16 flow_ring_id; | |
180 | u8 tc; | |
181 | u8 priority; | |
182 | __le16 int_vector; | |
183 | __le16 max_items; | |
184 | __le16 len_item; | |
185 | struct msgbuf_buf_addr flow_ring_addr; | |
186 | }; | |
187 | ||
188 | struct msgbuf_tx_flowring_delete_req { | |
189 | struct msgbuf_common_hdr msg; | |
190 | __le16 flow_ring_id; | |
191 | __le16 reason; | |
192 | __le32 rsvd0[7]; | |
193 | }; | |
194 | ||
195 | struct msgbuf_flowring_create_resp { | |
196 | struct msgbuf_common_hdr msg; | |
197 | struct msgbuf_completion_hdr compl_hdr; | |
198 | __le32 rsvd0[3]; | |
199 | }; | |
200 | ||
201 | struct msgbuf_flowring_delete_resp { | |
202 | struct msgbuf_common_hdr msg; | |
203 | struct msgbuf_completion_hdr compl_hdr; | |
204 | __le32 rsvd0[3]; | |
205 | }; | |
206 | ||
207 | struct msgbuf_flowring_flush_resp { | |
208 | struct msgbuf_common_hdr msg; | |
209 | struct msgbuf_completion_hdr compl_hdr; | |
210 | __le32 rsvd0[3]; | |
211 | }; | |
212 | ||
3ba06610 HM |
213 | struct brcmf_msgbuf_work_item { |
214 | struct list_head queue; | |
215 | u32 flowid; | |
216 | int ifidx; | |
217 | u8 sa[ETH_ALEN]; | |
218 | u8 da[ETH_ALEN]; | |
219 | }; | |
220 | ||
9a1bb602 HM |
221 | struct brcmf_msgbuf { |
222 | struct brcmf_pub *drvr; | |
223 | ||
224 | struct brcmf_commonring **commonrings; | |
225 | struct brcmf_commonring **flowrings; | |
226 | dma_addr_t *flowring_dma_handle; | |
227 | u16 nrof_flowrings; | |
228 | ||
229 | u16 rx_dataoffset; | |
230 | u32 max_rxbufpost; | |
231 | u16 rx_metadata_offset; | |
232 | u32 rxbufpost; | |
233 | ||
234 | u32 max_ioctlrespbuf; | |
235 | u32 cur_ioctlrespbuf; | |
236 | u32 max_eventbuf; | |
237 | u32 cur_eventbuf; | |
238 | ||
239 | void *ioctbuf; | |
240 | dma_addr_t ioctbuf_handle; | |
241 | u32 ioctbuf_phys_hi; | |
242 | u32 ioctbuf_phys_lo; | |
ff0a6230 | 243 | int ioctl_resp_status; |
9a1bb602 HM |
244 | u32 ioctl_resp_ret_len; |
245 | u32 ioctl_resp_pktid; | |
246 | ||
247 | u16 data_seq_no; | |
248 | u16 ioctl_seq_no; | |
249 | u32 reqid; | |
250 | wait_queue_head_t ioctl_resp_wait; | |
251 | bool ctl_completed; | |
252 | ||
253 | struct brcmf_msgbuf_pktids *tx_pktids; | |
254 | struct brcmf_msgbuf_pktids *rx_pktids; | |
255 | struct brcmf_flowring *flow; | |
256 | ||
257 | struct workqueue_struct *txflow_wq; | |
258 | struct work_struct txflow_work; | |
259 | unsigned long *flow_map; | |
260 | unsigned long *txstatus_done_map; | |
3ba06610 HM |
261 | |
262 | struct work_struct flowring_work; | |
263 | spinlock_t flowring_work_lock; | |
264 | struct list_head work_queue; | |
9a1bb602 HM |
265 | }; |
266 | ||
267 | struct brcmf_msgbuf_pktid { | |
268 | atomic_t allocated; | |
269 | u16 data_offset; | |
270 | struct sk_buff *skb; | |
271 | dma_addr_t physaddr; | |
272 | }; | |
273 | ||
274 | struct brcmf_msgbuf_pktids { | |
275 | u32 array_size; | |
276 | u32 last_allocated_idx; | |
277 | enum dma_data_direction direction; | |
278 | struct brcmf_msgbuf_pktid *array; | |
279 | }; | |
280 | ||
281 | ||
282 | /* dma flushing needs implementation for mips and arm platforms. Should | |
283 | * be put in util. Note, this is not real flushing. It is virtual non | |
284 | * cached memory. Only write buffers should have to be drained. Though | |
285 | * this may be different depending on platform...... | |
286 | */ | |
287 | #define brcmf_dma_flush(addr, len) | |
288 | #define brcmf_dma_invalidate_cache(addr, len) | |
289 | ||
290 | ||
291 | static void brcmf_msgbuf_rxbuf_ioctlresp_post(struct brcmf_msgbuf *msgbuf); | |
292 | ||
293 | ||
294 | static struct brcmf_msgbuf_pktids * | |
295 | brcmf_msgbuf_init_pktids(u32 nr_array_entries, | |
296 | enum dma_data_direction direction) | |
297 | { | |
298 | struct brcmf_msgbuf_pktid *array; | |
299 | struct brcmf_msgbuf_pktids *pktids; | |
300 | ||
3ba06610 | 301 | array = kcalloc(nr_array_entries, sizeof(*array), GFP_KERNEL); |
9a1bb602 HM |
302 | if (!array) |
303 | return NULL; | |
304 | ||
3ba06610 | 305 | pktids = kzalloc(sizeof(*pktids), GFP_KERNEL); |
9a1bb602 HM |
306 | if (!pktids) { |
307 | kfree(array); | |
308 | return NULL; | |
309 | } | |
310 | pktids->array = array; | |
311 | pktids->array_size = nr_array_entries; | |
312 | ||
313 | return pktids; | |
314 | } | |
315 | ||
316 | ||
317 | static int | |
318 | brcmf_msgbuf_alloc_pktid(struct device *dev, | |
319 | struct brcmf_msgbuf_pktids *pktids, | |
320 | struct sk_buff *skb, u16 data_offset, | |
321 | dma_addr_t *physaddr, u32 *idx) | |
322 | { | |
323 | struct brcmf_msgbuf_pktid *array; | |
324 | u32 count; | |
325 | ||
326 | array = pktids->array; | |
327 | ||
328 | *physaddr = dma_map_single(dev, skb->data + data_offset, | |
329 | skb->len - data_offset, pktids->direction); | |
330 | ||
331 | if (dma_mapping_error(dev, *physaddr)) { | |
332 | brcmf_err("dma_map_single failed !!\n"); | |
333 | return -ENOMEM; | |
334 | } | |
335 | ||
336 | *idx = pktids->last_allocated_idx; | |
337 | ||
338 | count = 0; | |
339 | do { | |
340 | (*idx)++; | |
341 | if (*idx == pktids->array_size) | |
342 | *idx = 0; | |
343 | if (array[*idx].allocated.counter == 0) | |
344 | if (atomic_cmpxchg(&array[*idx].allocated, 0, 1) == 0) | |
345 | break; | |
346 | count++; | |
347 | } while (count < pktids->array_size); | |
348 | ||
349 | if (count == pktids->array_size) | |
350 | return -ENOMEM; | |
351 | ||
352 | array[*idx].data_offset = data_offset; | |
353 | array[*idx].physaddr = *physaddr; | |
354 | array[*idx].skb = skb; | |
355 | ||
356 | pktids->last_allocated_idx = *idx; | |
357 | ||
358 | return 0; | |
359 | } | |
360 | ||
361 | ||
362 | static struct sk_buff * | |
363 | brcmf_msgbuf_get_pktid(struct device *dev, struct brcmf_msgbuf_pktids *pktids, | |
364 | u32 idx) | |
365 | { | |
366 | struct brcmf_msgbuf_pktid *pktid; | |
367 | struct sk_buff *skb; | |
368 | ||
369 | if (idx >= pktids->array_size) { | |
370 | brcmf_err("Invalid packet id %d (max %d)\n", idx, | |
371 | pktids->array_size); | |
372 | return NULL; | |
373 | } | |
374 | if (pktids->array[idx].allocated.counter) { | |
375 | pktid = &pktids->array[idx]; | |
376 | dma_unmap_single(dev, pktid->physaddr, | |
377 | pktid->skb->len - pktid->data_offset, | |
378 | pktids->direction); | |
379 | skb = pktid->skb; | |
380 | pktid->allocated.counter = 0; | |
381 | return skb; | |
382 | } else { | |
383 | brcmf_err("Invalid packet id %d (not in use)\n", idx); | |
384 | } | |
385 | ||
386 | return NULL; | |
387 | } | |
388 | ||
389 | ||
390 | static void | |
391 | brcmf_msgbuf_release_array(struct device *dev, | |
392 | struct brcmf_msgbuf_pktids *pktids) | |
393 | { | |
394 | struct brcmf_msgbuf_pktid *array; | |
395 | struct brcmf_msgbuf_pktid *pktid; | |
396 | u32 count; | |
397 | ||
398 | array = pktids->array; | |
399 | count = 0; | |
400 | do { | |
401 | if (array[count].allocated.counter) { | |
402 | pktid = &array[count]; | |
403 | dma_unmap_single(dev, pktid->physaddr, | |
404 | pktid->skb->len - pktid->data_offset, | |
405 | pktids->direction); | |
406 | brcmu_pkt_buf_free_skb(pktid->skb); | |
407 | } | |
408 | count++; | |
409 | } while (count < pktids->array_size); | |
410 | ||
411 | kfree(array); | |
412 | kfree(pktids); | |
413 | } | |
414 | ||
415 | ||
416 | static void brcmf_msgbuf_release_pktids(struct brcmf_msgbuf *msgbuf) | |
417 | { | |
418 | if (msgbuf->rx_pktids) | |
419 | brcmf_msgbuf_release_array(msgbuf->drvr->bus_if->dev, | |
420 | msgbuf->rx_pktids); | |
421 | if (msgbuf->tx_pktids) | |
422 | brcmf_msgbuf_release_array(msgbuf->drvr->bus_if->dev, | |
423 | msgbuf->tx_pktids); | |
424 | } | |
425 | ||
426 | ||
427 | static int brcmf_msgbuf_tx_ioctl(struct brcmf_pub *drvr, int ifidx, | |
428 | uint cmd, void *buf, uint len) | |
429 | { | |
430 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
431 | struct brcmf_commonring *commonring; | |
432 | struct msgbuf_ioctl_req_hdr *request; | |
433 | u16 buf_len; | |
434 | void *ret_ptr; | |
435 | int err; | |
436 | ||
437 | commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_CONTROL_SUBMIT]; | |
438 | brcmf_commonring_lock(commonring); | |
439 | ret_ptr = brcmf_commonring_reserve_for_write(commonring); | |
440 | if (!ret_ptr) { | |
441 | brcmf_err("Failed to reserve space in commonring\n"); | |
442 | brcmf_commonring_unlock(commonring); | |
443 | return -ENOMEM; | |
444 | } | |
445 | ||
446 | msgbuf->reqid++; | |
447 | ||
448 | request = (struct msgbuf_ioctl_req_hdr *)ret_ptr; | |
449 | request->msg.msgtype = MSGBUF_TYPE_IOCTLPTR_REQ; | |
450 | request->msg.ifidx = (u8)ifidx; | |
451 | request->msg.flags = 0; | |
452 | request->msg.request_id = cpu_to_le32(BRCMF_IOCTL_REQ_PKTID); | |
453 | request->cmd = cpu_to_le32(cmd); | |
454 | request->output_buf_len = cpu_to_le16(len); | |
455 | request->trans_id = cpu_to_le16(msgbuf->reqid); | |
456 | ||
457 | buf_len = min_t(u16, len, BRCMF_TX_IOCTL_MAX_MSG_SIZE); | |
458 | request->input_buf_len = cpu_to_le16(buf_len); | |
459 | request->req_buf_addr.high_addr = cpu_to_le32(msgbuf->ioctbuf_phys_hi); | |
460 | request->req_buf_addr.low_addr = cpu_to_le32(msgbuf->ioctbuf_phys_lo); | |
461 | if (buf) | |
462 | memcpy(msgbuf->ioctbuf, buf, buf_len); | |
463 | else | |
464 | memset(msgbuf->ioctbuf, 0, buf_len); | |
465 | brcmf_dma_flush(ioctl_buf, buf_len); | |
466 | ||
467 | err = brcmf_commonring_write_complete(commonring); | |
468 | brcmf_commonring_unlock(commonring); | |
469 | ||
470 | return err; | |
471 | } | |
472 | ||
473 | ||
474 | static int brcmf_msgbuf_ioctl_resp_wait(struct brcmf_msgbuf *msgbuf) | |
475 | { | |
476 | return wait_event_timeout(msgbuf->ioctl_resp_wait, | |
477 | msgbuf->ctl_completed, | |
478 | msecs_to_jiffies(MSGBUF_IOCTL_RESP_TIMEOUT)); | |
479 | } | |
480 | ||
481 | ||
482 | static void brcmf_msgbuf_ioctl_resp_wake(struct brcmf_msgbuf *msgbuf) | |
483 | { | |
484 | if (waitqueue_active(&msgbuf->ioctl_resp_wait)) { | |
485 | msgbuf->ctl_completed = true; | |
486 | wake_up(&msgbuf->ioctl_resp_wait); | |
487 | } | |
488 | } | |
489 | ||
490 | ||
491 | static int brcmf_msgbuf_query_dcmd(struct brcmf_pub *drvr, int ifidx, | |
492 | uint cmd, void *buf, uint len) | |
493 | { | |
494 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
495 | struct sk_buff *skb = NULL; | |
496 | int timeout; | |
497 | int err; | |
498 | ||
499 | brcmf_dbg(MSGBUF, "ifidx=%d, cmd=%d, len=%d\n", ifidx, cmd, len); | |
500 | msgbuf->ctl_completed = false; | |
501 | err = brcmf_msgbuf_tx_ioctl(drvr, ifidx, cmd, buf, len); | |
502 | if (err) | |
503 | return err; | |
504 | ||
505 | timeout = brcmf_msgbuf_ioctl_resp_wait(msgbuf); | |
506 | if (!timeout) { | |
507 | brcmf_err("Timeout on response for query command\n"); | |
508 | return -EIO; | |
509 | } | |
510 | ||
511 | skb = brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, | |
512 | msgbuf->rx_pktids, | |
513 | msgbuf->ioctl_resp_pktid); | |
514 | if (msgbuf->ioctl_resp_ret_len != 0) { | |
515 | if (!skb) { | |
516 | brcmf_err("Invalid packet id idx recv'd %d\n", | |
517 | msgbuf->ioctl_resp_pktid); | |
518 | return -EBADF; | |
519 | } | |
520 | memcpy(buf, skb->data, (len < msgbuf->ioctl_resp_ret_len) ? | |
521 | len : msgbuf->ioctl_resp_ret_len); | |
522 | } | |
ac96ce83 | 523 | brcmu_pkt_buf_free_skb(skb); |
9a1bb602 HM |
524 | |
525 | return msgbuf->ioctl_resp_status; | |
526 | } | |
527 | ||
528 | ||
529 | static int brcmf_msgbuf_set_dcmd(struct brcmf_pub *drvr, int ifidx, | |
530 | uint cmd, void *buf, uint len) | |
531 | { | |
532 | return brcmf_msgbuf_query_dcmd(drvr, ifidx, cmd, buf, len); | |
533 | } | |
534 | ||
535 | ||
536 | static int brcmf_msgbuf_hdrpull(struct brcmf_pub *drvr, bool do_fws, | |
537 | u8 *ifidx, struct sk_buff *skb) | |
538 | { | |
539 | return -ENODEV; | |
540 | } | |
541 | ||
542 | ||
543 | static void | |
544 | brcmf_msgbuf_remove_flowring(struct brcmf_msgbuf *msgbuf, u16 flowid) | |
545 | { | |
546 | u32 dma_sz; | |
547 | void *dma_buf; | |
548 | ||
549 | brcmf_dbg(MSGBUF, "Removing flowring %d\n", flowid); | |
550 | ||
551 | dma_sz = BRCMF_H2D_TXFLOWRING_MAX_ITEM * BRCMF_H2D_TXFLOWRING_ITEMSIZE; | |
552 | dma_buf = msgbuf->flowrings[flowid]->buf_addr; | |
553 | dma_free_coherent(msgbuf->drvr->bus_if->dev, dma_sz, dma_buf, | |
554 | msgbuf->flowring_dma_handle[flowid]); | |
555 | ||
556 | brcmf_flowring_delete(msgbuf->flow, flowid); | |
557 | } | |
558 | ||
559 | ||
3ba06610 HM |
560 | static struct brcmf_msgbuf_work_item * |
561 | brcmf_msgbuf_dequeue_work(struct brcmf_msgbuf *msgbuf) | |
562 | { | |
563 | struct brcmf_msgbuf_work_item *work = NULL; | |
564 | ulong flags; | |
565 | ||
566 | spin_lock_irqsave(&msgbuf->flowring_work_lock, flags); | |
567 | if (!list_empty(&msgbuf->work_queue)) { | |
568 | work = list_first_entry(&msgbuf->work_queue, | |
569 | struct brcmf_msgbuf_work_item, queue); | |
570 | list_del(&work->queue); | |
571 | } | |
572 | spin_unlock_irqrestore(&msgbuf->flowring_work_lock, flags); | |
573 | ||
574 | return work; | |
575 | } | |
576 | ||
577 | ||
578 | static u32 | |
579 | brcmf_msgbuf_flowring_create_worker(struct brcmf_msgbuf *msgbuf, | |
580 | struct brcmf_msgbuf_work_item *work) | |
9a1bb602 HM |
581 | { |
582 | struct msgbuf_tx_flowring_create_req *create; | |
9a1bb602 HM |
583 | struct brcmf_commonring *commonring; |
584 | void *ret_ptr; | |
585 | u32 flowid; | |
586 | void *dma_buf; | |
587 | u32 dma_sz; | |
83297aaa | 588 | u64 address; |
9a1bb602 HM |
589 | int err; |
590 | ||
3ba06610 | 591 | flowid = work->flowid; |
9a1bb602 | 592 | dma_sz = BRCMF_H2D_TXFLOWRING_MAX_ITEM * BRCMF_H2D_TXFLOWRING_ITEMSIZE; |
9a1bb602 HM |
593 | dma_buf = dma_alloc_coherent(msgbuf->drvr->bus_if->dev, dma_sz, |
594 | &msgbuf->flowring_dma_handle[flowid], | |
3ba06610 | 595 | GFP_KERNEL); |
9a1bb602 HM |
596 | if (!dma_buf) { |
597 | brcmf_err("dma_alloc_coherent failed\n"); | |
598 | brcmf_flowring_delete(msgbuf->flow, flowid); | |
599 | return BRCMF_FLOWRING_INVALID_ID; | |
600 | } | |
601 | ||
602 | brcmf_commonring_config(msgbuf->flowrings[flowid], | |
603 | BRCMF_H2D_TXFLOWRING_MAX_ITEM, | |
604 | BRCMF_H2D_TXFLOWRING_ITEMSIZE, dma_buf); | |
605 | ||
606 | commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_CONTROL_SUBMIT]; | |
607 | brcmf_commonring_lock(commonring); | |
608 | ret_ptr = brcmf_commonring_reserve_for_write(commonring); | |
609 | if (!ret_ptr) { | |
610 | brcmf_err("Failed to reserve space in commonring\n"); | |
611 | brcmf_commonring_unlock(commonring); | |
612 | brcmf_msgbuf_remove_flowring(msgbuf, flowid); | |
613 | return BRCMF_FLOWRING_INVALID_ID; | |
614 | } | |
615 | ||
616 | create = (struct msgbuf_tx_flowring_create_req *)ret_ptr; | |
617 | create->msg.msgtype = MSGBUF_TYPE_FLOW_RING_CREATE; | |
3ba06610 | 618 | create->msg.ifidx = work->ifidx; |
9a1bb602 HM |
619 | create->msg.request_id = 0; |
620 | create->tid = brcmf_flowring_tid(msgbuf->flow, flowid); | |
621 | create->flow_ring_id = cpu_to_le16(flowid + | |
622 | BRCMF_NROF_H2D_COMMON_MSGRINGS); | |
3ba06610 HM |
623 | memcpy(create->sa, work->sa, ETH_ALEN); |
624 | memcpy(create->da, work->da, ETH_ALEN); | |
83297aaa | 625 | address = (u64)msgbuf->flowring_dma_handle[flowid]; |
9a1bb602 HM |
626 | create->flow_ring_addr.high_addr = cpu_to_le32(address >> 32); |
627 | create->flow_ring_addr.low_addr = cpu_to_le32(address & 0xffffffff); | |
628 | create->max_items = cpu_to_le16(BRCMF_H2D_TXFLOWRING_MAX_ITEM); | |
629 | create->len_item = cpu_to_le16(BRCMF_H2D_TXFLOWRING_ITEMSIZE); | |
630 | ||
631 | brcmf_dbg(MSGBUF, "Send Flow Create Req flow ID %d for peer %pM prio %d ifindex %d\n", | |
3ba06610 | 632 | flowid, work->da, create->tid, work->ifidx); |
9a1bb602 HM |
633 | |
634 | err = brcmf_commonring_write_complete(commonring); | |
635 | brcmf_commonring_unlock(commonring); | |
636 | if (err) { | |
637 | brcmf_err("Failed to write commonring\n"); | |
638 | brcmf_msgbuf_remove_flowring(msgbuf, flowid); | |
639 | return BRCMF_FLOWRING_INVALID_ID; | |
640 | } | |
641 | ||
642 | return flowid; | |
643 | } | |
644 | ||
645 | ||
3ba06610 HM |
646 | static void brcmf_msgbuf_flowring_worker(struct work_struct *work) |
647 | { | |
648 | struct brcmf_msgbuf *msgbuf; | |
649 | struct brcmf_msgbuf_work_item *create; | |
650 | ||
651 | msgbuf = container_of(work, struct brcmf_msgbuf, flowring_work); | |
652 | ||
653 | while ((create = brcmf_msgbuf_dequeue_work(msgbuf))) { | |
654 | brcmf_msgbuf_flowring_create_worker(msgbuf, create); | |
655 | kfree(create); | |
656 | } | |
657 | } | |
658 | ||
659 | ||
660 | static u32 brcmf_msgbuf_flowring_create(struct brcmf_msgbuf *msgbuf, int ifidx, | |
661 | struct sk_buff *skb) | |
662 | { | |
663 | struct brcmf_msgbuf_work_item *create; | |
664 | struct ethhdr *eh = (struct ethhdr *)(skb->data); | |
665 | u32 flowid; | |
666 | ulong flags; | |
667 | ||
668 | create = kzalloc(sizeof(*create), GFP_ATOMIC); | |
669 | if (create == NULL) | |
670 | return BRCMF_FLOWRING_INVALID_ID; | |
671 | ||
672 | flowid = brcmf_flowring_create(msgbuf->flow, eh->h_dest, | |
673 | skb->priority, ifidx); | |
674 | if (flowid == BRCMF_FLOWRING_INVALID_ID) { | |
675 | kfree(create); | |
676 | return flowid; | |
677 | } | |
678 | ||
679 | create->flowid = flowid; | |
680 | create->ifidx = ifidx; | |
681 | memcpy(create->sa, eh->h_source, ETH_ALEN); | |
682 | memcpy(create->da, eh->h_dest, ETH_ALEN); | |
683 | ||
684 | spin_lock_irqsave(&msgbuf->flowring_work_lock, flags); | |
685 | list_add_tail(&create->queue, &msgbuf->work_queue); | |
686 | spin_unlock_irqrestore(&msgbuf->flowring_work_lock, flags); | |
687 | schedule_work(&msgbuf->flowring_work); | |
688 | ||
689 | return flowid; | |
690 | } | |
691 | ||
692 | ||
9a1bb602 HM |
693 | static void brcmf_msgbuf_txflow(struct brcmf_msgbuf *msgbuf, u8 flowid) |
694 | { | |
695 | struct brcmf_flowring *flow = msgbuf->flow; | |
696 | struct brcmf_commonring *commonring; | |
697 | void *ret_ptr; | |
698 | u32 count; | |
699 | struct sk_buff *skb; | |
700 | dma_addr_t physaddr; | |
701 | u32 pktid; | |
702 | struct msgbuf_tx_msghdr *tx_msghdr; | |
83297aaa | 703 | u64 address; |
9a1bb602 HM |
704 | |
705 | commonring = msgbuf->flowrings[flowid]; | |
706 | if (!brcmf_commonring_write_available(commonring)) | |
707 | return; | |
708 | ||
709 | brcmf_commonring_lock(commonring); | |
710 | ||
711 | count = BRCMF_MSGBUF_TX_FLUSH_CNT2 - BRCMF_MSGBUF_TX_FLUSH_CNT1; | |
712 | while (brcmf_flowring_qlen(flow, flowid)) { | |
713 | skb = brcmf_flowring_dequeue(flow, flowid); | |
714 | if (skb == NULL) { | |
715 | brcmf_err("No SKB, but qlen %d\n", | |
716 | brcmf_flowring_qlen(flow, flowid)); | |
717 | break; | |
718 | } | |
719 | skb_orphan(skb); | |
720 | if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, | |
721 | msgbuf->tx_pktids, skb, ETH_HLEN, | |
722 | &physaddr, &pktid)) { | |
723 | brcmf_flowring_reinsert(flow, flowid, skb); | |
724 | brcmf_err("No PKTID available !!\n"); | |
725 | break; | |
726 | } | |
727 | ret_ptr = brcmf_commonring_reserve_for_write(commonring); | |
728 | if (!ret_ptr) { | |
729 | brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, | |
730 | msgbuf->tx_pktids, pktid); | |
731 | brcmf_flowring_reinsert(flow, flowid, skb); | |
732 | break; | |
733 | } | |
734 | count++; | |
735 | ||
736 | tx_msghdr = (struct msgbuf_tx_msghdr *)ret_ptr; | |
737 | ||
738 | tx_msghdr->msg.msgtype = MSGBUF_TYPE_TX_POST; | |
739 | tx_msghdr->msg.request_id = cpu_to_le32(pktid); | |
740 | tx_msghdr->msg.ifidx = brcmf_flowring_ifidx_get(flow, flowid); | |
741 | tx_msghdr->flags = BRCMF_MSGBUF_PKT_FLAGS_FRAME_802_3; | |
742 | tx_msghdr->flags |= (skb->priority & 0x07) << | |
743 | BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT; | |
744 | tx_msghdr->seg_cnt = 1; | |
745 | memcpy(tx_msghdr->txhdr, skb->data, ETH_HLEN); | |
746 | tx_msghdr->data_len = cpu_to_le16(skb->len - ETH_HLEN); | |
83297aaa | 747 | address = (u64)physaddr; |
9a1bb602 HM |
748 | tx_msghdr->data_buf_addr.high_addr = cpu_to_le32(address >> 32); |
749 | tx_msghdr->data_buf_addr.low_addr = | |
750 | cpu_to_le32(address & 0xffffffff); | |
751 | tx_msghdr->metadata_buf_len = 0; | |
752 | tx_msghdr->metadata_buf_addr.high_addr = 0; | |
753 | tx_msghdr->metadata_buf_addr.low_addr = 0; | |
5ef1e604 | 754 | atomic_inc(&commonring->outstanding_tx); |
9a1bb602 HM |
755 | if (count >= BRCMF_MSGBUF_TX_FLUSH_CNT2) { |
756 | brcmf_commonring_write_complete(commonring); | |
757 | count = 0; | |
758 | } | |
759 | } | |
760 | if (count) | |
761 | brcmf_commonring_write_complete(commonring); | |
762 | brcmf_commonring_unlock(commonring); | |
763 | } | |
764 | ||
765 | ||
766 | static void brcmf_msgbuf_txflow_worker(struct work_struct *worker) | |
767 | { | |
768 | struct brcmf_msgbuf *msgbuf; | |
769 | u32 flowid; | |
770 | ||
771 | msgbuf = container_of(worker, struct brcmf_msgbuf, txflow_work); | |
772 | for_each_set_bit(flowid, msgbuf->flow_map, msgbuf->nrof_flowrings) { | |
773 | clear_bit(flowid, msgbuf->flow_map); | |
774 | brcmf_msgbuf_txflow(msgbuf, flowid); | |
775 | } | |
776 | } | |
777 | ||
778 | ||
5ef1e604 HM |
779 | static int brcmf_msgbuf_schedule_txdata(struct brcmf_msgbuf *msgbuf, u32 flowid, |
780 | bool force) | |
9a1bb602 | 781 | { |
5ef1e604 HM |
782 | struct brcmf_commonring *commonring; |
783 | ||
9a1bb602 | 784 | set_bit(flowid, msgbuf->flow_map); |
5ef1e604 HM |
785 | commonring = msgbuf->flowrings[flowid]; |
786 | if ((force) || (atomic_read(&commonring->outstanding_tx) < | |
787 | BRCMF_MSGBUF_DELAY_TXWORKER_THRS)) | |
788 | queue_work(msgbuf->txflow_wq, &msgbuf->txflow_work); | |
9a1bb602 HM |
789 | |
790 | return 0; | |
791 | } | |
792 | ||
793 | ||
794 | static int brcmf_msgbuf_txdata(struct brcmf_pub *drvr, int ifidx, | |
795 | u8 offset, struct sk_buff *skb) | |
796 | { | |
797 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
798 | struct brcmf_flowring *flow = msgbuf->flow; | |
799 | struct ethhdr *eh = (struct ethhdr *)(skb->data); | |
800 | u32 flowid; | |
801 | ||
802 | flowid = brcmf_flowring_lookup(flow, eh->h_dest, skb->priority, ifidx); | |
803 | if (flowid == BRCMF_FLOWRING_INVALID_ID) { | |
804 | flowid = brcmf_msgbuf_flowring_create(msgbuf, ifidx, skb); | |
805 | if (flowid == BRCMF_FLOWRING_INVALID_ID) | |
806 | return -ENOMEM; | |
807 | } | |
808 | brcmf_flowring_enqueue(flow, flowid, skb); | |
5ef1e604 | 809 | brcmf_msgbuf_schedule_txdata(msgbuf, flowid, false); |
9a1bb602 HM |
810 | |
811 | return 0; | |
812 | } | |
813 | ||
814 | ||
815 | static void | |
816 | brcmf_msgbuf_configure_addr_mode(struct brcmf_pub *drvr, int ifidx, | |
817 | enum proto_addr_mode addr_mode) | |
818 | { | |
819 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
820 | ||
821 | brcmf_flowring_configure_addr_mode(msgbuf->flow, ifidx, addr_mode); | |
822 | } | |
823 | ||
824 | ||
825 | static void | |
826 | brcmf_msgbuf_delete_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN]) | |
827 | { | |
828 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
829 | ||
830 | brcmf_flowring_delete_peer(msgbuf->flow, ifidx, peer); | |
831 | } | |
832 | ||
833 | ||
70b7d94b HM |
834 | static void |
835 | brcmf_msgbuf_add_tdls_peer(struct brcmf_pub *drvr, int ifidx, u8 peer[ETH_ALEN]) | |
836 | { | |
837 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
838 | ||
839 | brcmf_flowring_add_tdls_peer(msgbuf->flow, ifidx, peer); | |
840 | } | |
841 | ||
842 | ||
9a1bb602 HM |
843 | static void |
844 | brcmf_msgbuf_process_ioctl_complete(struct brcmf_msgbuf *msgbuf, void *buf) | |
845 | { | |
846 | struct msgbuf_ioctl_resp_hdr *ioctl_resp; | |
847 | ||
848 | ioctl_resp = (struct msgbuf_ioctl_resp_hdr *)buf; | |
849 | ||
ff0a6230 HM |
850 | msgbuf->ioctl_resp_status = |
851 | (s16)le16_to_cpu(ioctl_resp->compl_hdr.status); | |
9a1bb602 HM |
852 | msgbuf->ioctl_resp_ret_len = le16_to_cpu(ioctl_resp->resp_len); |
853 | msgbuf->ioctl_resp_pktid = le32_to_cpu(ioctl_resp->msg.request_id); | |
854 | ||
855 | brcmf_msgbuf_ioctl_resp_wake(msgbuf); | |
856 | ||
857 | if (msgbuf->cur_ioctlrespbuf) | |
858 | msgbuf->cur_ioctlrespbuf--; | |
859 | brcmf_msgbuf_rxbuf_ioctlresp_post(msgbuf); | |
860 | } | |
861 | ||
862 | ||
863 | static void | |
864 | brcmf_msgbuf_process_txstatus(struct brcmf_msgbuf *msgbuf, void *buf) | |
865 | { | |
5ef1e604 | 866 | struct brcmf_commonring *commonring; |
9a1bb602 HM |
867 | struct msgbuf_tx_status *tx_status; |
868 | u32 idx; | |
869 | struct sk_buff *skb; | |
870 | u16 flowid; | |
871 | ||
872 | tx_status = (struct msgbuf_tx_status *)buf; | |
873 | idx = le32_to_cpu(tx_status->msg.request_id); | |
874 | flowid = le16_to_cpu(tx_status->compl_hdr.flow_ring_id); | |
875 | flowid -= BRCMF_NROF_H2D_COMMON_MSGRINGS; | |
876 | skb = brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, | |
877 | msgbuf->tx_pktids, idx); | |
878 | if (!skb) { | |
879 | brcmf_err("Invalid packet id idx recv'd %d\n", idx); | |
880 | return; | |
881 | } | |
882 | ||
883 | set_bit(flowid, msgbuf->txstatus_done_map); | |
5ef1e604 HM |
884 | commonring = msgbuf->flowrings[flowid]; |
885 | atomic_dec(&commonring->outstanding_tx); | |
9a1bb602 HM |
886 | |
887 | brcmf_txfinalize(msgbuf->drvr, skb, tx_status->msg.ifidx, true); | |
888 | } | |
889 | ||
890 | ||
891 | static u32 brcmf_msgbuf_rxbuf_data_post(struct brcmf_msgbuf *msgbuf, u32 count) | |
892 | { | |
893 | struct brcmf_commonring *commonring; | |
894 | void *ret_ptr; | |
895 | struct sk_buff *skb; | |
896 | u16 alloced; | |
897 | u32 pktlen; | |
898 | dma_addr_t physaddr; | |
899 | struct msgbuf_rx_bufpost *rx_bufpost; | |
83297aaa | 900 | u64 address; |
9a1bb602 HM |
901 | u32 pktid; |
902 | u32 i; | |
903 | ||
904 | commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_RXPOST_SUBMIT]; | |
905 | ret_ptr = brcmf_commonring_reserve_for_write_multiple(commonring, | |
906 | count, | |
907 | &alloced); | |
908 | if (!ret_ptr) { | |
d2e2472c | 909 | brcmf_dbg(MSGBUF, "Failed to reserve space in commonring\n"); |
9a1bb602 HM |
910 | return 0; |
911 | } | |
912 | ||
913 | for (i = 0; i < alloced; i++) { | |
914 | rx_bufpost = (struct msgbuf_rx_bufpost *)ret_ptr; | |
915 | memset(rx_bufpost, 0, sizeof(*rx_bufpost)); | |
916 | ||
917 | skb = brcmu_pkt_buf_get_skb(BRCMF_MSGBUF_MAX_PKT_SIZE); | |
918 | ||
919 | if (skb == NULL) { | |
920 | brcmf_err("Failed to alloc SKB\n"); | |
921 | brcmf_commonring_write_cancel(commonring, alloced - i); | |
922 | break; | |
923 | } | |
924 | ||
925 | pktlen = skb->len; | |
926 | if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, | |
927 | msgbuf->rx_pktids, skb, 0, | |
928 | &physaddr, &pktid)) { | |
929 | dev_kfree_skb_any(skb); | |
930 | brcmf_err("No PKTID available !!\n"); | |
931 | brcmf_commonring_write_cancel(commonring, alloced - i); | |
932 | break; | |
933 | } | |
934 | ||
935 | if (msgbuf->rx_metadata_offset) { | |
83297aaa | 936 | address = (u64)physaddr; |
9a1bb602 HM |
937 | rx_bufpost->metadata_buf_len = |
938 | cpu_to_le16(msgbuf->rx_metadata_offset); | |
939 | rx_bufpost->metadata_buf_addr.high_addr = | |
940 | cpu_to_le32(address >> 32); | |
941 | rx_bufpost->metadata_buf_addr.low_addr = | |
942 | cpu_to_le32(address & 0xffffffff); | |
943 | ||
944 | skb_pull(skb, msgbuf->rx_metadata_offset); | |
945 | pktlen = skb->len; | |
946 | physaddr += msgbuf->rx_metadata_offset; | |
947 | } | |
948 | rx_bufpost->msg.msgtype = MSGBUF_TYPE_RXBUF_POST; | |
949 | rx_bufpost->msg.request_id = cpu_to_le32(pktid); | |
950 | ||
83297aaa | 951 | address = (u64)physaddr; |
9a1bb602 HM |
952 | rx_bufpost->data_buf_len = cpu_to_le16((u16)pktlen); |
953 | rx_bufpost->data_buf_addr.high_addr = | |
954 | cpu_to_le32(address >> 32); | |
955 | rx_bufpost->data_buf_addr.low_addr = | |
956 | cpu_to_le32(address & 0xffffffff); | |
957 | ||
958 | ret_ptr += brcmf_commonring_len_item(commonring); | |
959 | } | |
960 | ||
961 | if (i) | |
962 | brcmf_commonring_write_complete(commonring); | |
963 | ||
964 | return i; | |
965 | } | |
966 | ||
967 | ||
968 | static void | |
969 | brcmf_msgbuf_rxbuf_data_fill(struct brcmf_msgbuf *msgbuf) | |
970 | { | |
971 | u32 fillbufs; | |
972 | u32 retcount; | |
973 | ||
974 | fillbufs = msgbuf->max_rxbufpost - msgbuf->rxbufpost; | |
975 | ||
976 | while (fillbufs) { | |
977 | retcount = brcmf_msgbuf_rxbuf_data_post(msgbuf, fillbufs); | |
978 | if (!retcount) | |
979 | break; | |
980 | msgbuf->rxbufpost += retcount; | |
981 | fillbufs -= retcount; | |
982 | } | |
983 | } | |
984 | ||
985 | ||
986 | static void | |
987 | brcmf_msgbuf_update_rxbufpost_count(struct brcmf_msgbuf *msgbuf, u16 rxcnt) | |
988 | { | |
989 | msgbuf->rxbufpost -= rxcnt; | |
990 | if (msgbuf->rxbufpost <= (msgbuf->max_rxbufpost - | |
991 | BRCMF_MSGBUF_RXBUFPOST_THRESHOLD)) | |
992 | brcmf_msgbuf_rxbuf_data_fill(msgbuf); | |
993 | } | |
994 | ||
995 | ||
996 | static u32 | |
997 | brcmf_msgbuf_rxbuf_ctrl_post(struct brcmf_msgbuf *msgbuf, bool event_buf, | |
998 | u32 count) | |
999 | { | |
1000 | struct brcmf_commonring *commonring; | |
1001 | void *ret_ptr; | |
1002 | struct sk_buff *skb; | |
1003 | u16 alloced; | |
1004 | u32 pktlen; | |
1005 | dma_addr_t physaddr; | |
1006 | struct msgbuf_rx_ioctl_resp_or_event *rx_bufpost; | |
83297aaa | 1007 | u64 address; |
9a1bb602 HM |
1008 | u32 pktid; |
1009 | u32 i; | |
1010 | ||
1011 | commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_CONTROL_SUBMIT]; | |
1012 | brcmf_commonring_lock(commonring); | |
1013 | ret_ptr = brcmf_commonring_reserve_for_write_multiple(commonring, | |
1014 | count, | |
1015 | &alloced); | |
1016 | if (!ret_ptr) { | |
1017 | brcmf_err("Failed to reserve space in commonring\n"); | |
1018 | brcmf_commonring_unlock(commonring); | |
1019 | return 0; | |
1020 | } | |
1021 | ||
1022 | for (i = 0; i < alloced; i++) { | |
1023 | rx_bufpost = (struct msgbuf_rx_ioctl_resp_or_event *)ret_ptr; | |
1024 | memset(rx_bufpost, 0, sizeof(*rx_bufpost)); | |
1025 | ||
1026 | skb = brcmu_pkt_buf_get_skb(BRCMF_MSGBUF_MAX_PKT_SIZE); | |
1027 | ||
1028 | if (skb == NULL) { | |
1029 | brcmf_err("Failed to alloc SKB\n"); | |
1030 | brcmf_commonring_write_cancel(commonring, alloced - i); | |
1031 | break; | |
1032 | } | |
1033 | ||
1034 | pktlen = skb->len; | |
1035 | if (brcmf_msgbuf_alloc_pktid(msgbuf->drvr->bus_if->dev, | |
1036 | msgbuf->rx_pktids, skb, 0, | |
1037 | &physaddr, &pktid)) { | |
1038 | dev_kfree_skb_any(skb); | |
1039 | brcmf_err("No PKTID available !!\n"); | |
1040 | brcmf_commonring_write_cancel(commonring, alloced - i); | |
1041 | break; | |
1042 | } | |
1043 | if (event_buf) | |
1044 | rx_bufpost->msg.msgtype = MSGBUF_TYPE_EVENT_BUF_POST; | |
1045 | else | |
1046 | rx_bufpost->msg.msgtype = | |
1047 | MSGBUF_TYPE_IOCTLRESP_BUF_POST; | |
1048 | rx_bufpost->msg.request_id = cpu_to_le32(pktid); | |
1049 | ||
83297aaa | 1050 | address = (u64)physaddr; |
9a1bb602 HM |
1051 | rx_bufpost->host_buf_len = cpu_to_le16((u16)pktlen); |
1052 | rx_bufpost->host_buf_addr.high_addr = | |
1053 | cpu_to_le32(address >> 32); | |
1054 | rx_bufpost->host_buf_addr.low_addr = | |
1055 | cpu_to_le32(address & 0xffffffff); | |
1056 | ||
1057 | ret_ptr += brcmf_commonring_len_item(commonring); | |
1058 | } | |
1059 | ||
1060 | if (i) | |
1061 | brcmf_commonring_write_complete(commonring); | |
1062 | ||
1063 | brcmf_commonring_unlock(commonring); | |
1064 | ||
1065 | return i; | |
1066 | } | |
1067 | ||
1068 | ||
1069 | static void brcmf_msgbuf_rxbuf_ioctlresp_post(struct brcmf_msgbuf *msgbuf) | |
1070 | { | |
1071 | u32 count; | |
1072 | ||
1073 | count = msgbuf->max_ioctlrespbuf - msgbuf->cur_ioctlrespbuf; | |
1074 | count = brcmf_msgbuf_rxbuf_ctrl_post(msgbuf, false, count); | |
1075 | msgbuf->cur_ioctlrespbuf += count; | |
1076 | } | |
1077 | ||
1078 | ||
1079 | static void brcmf_msgbuf_rxbuf_event_post(struct brcmf_msgbuf *msgbuf) | |
1080 | { | |
1081 | u32 count; | |
1082 | ||
1083 | count = msgbuf->max_eventbuf - msgbuf->cur_eventbuf; | |
1084 | count = brcmf_msgbuf_rxbuf_ctrl_post(msgbuf, true, count); | |
1085 | msgbuf->cur_eventbuf += count; | |
1086 | } | |
1087 | ||
1088 | ||
1089 | static void | |
1090 | brcmf_msgbuf_rx_skb(struct brcmf_msgbuf *msgbuf, struct sk_buff *skb, | |
1091 | u8 ifidx) | |
1092 | { | |
1093 | struct brcmf_if *ifp; | |
1094 | ||
94a61208 HM |
1095 | /* The ifidx is the idx to map to matching netdev/ifp. When receiving |
1096 | * events this is easy because it contains the bssidx which maps | |
1097 | * 1-on-1 to the netdev/ifp. But for data frames the ifidx is rcvd. | |
1098 | * bssidx 1 is used for p2p0 and no data can be received or | |
1099 | * transmitted on it. Therefor bssidx is ifidx + 1 if ifidx > 0 | |
1100 | */ | |
1101 | if (ifidx) | |
1102 | (ifidx)++; | |
9a1bb602 HM |
1103 | ifp = msgbuf->drvr->iflist[ifidx]; |
1104 | if (!ifp || !ifp->ndev) { | |
94a61208 | 1105 | brcmf_err("Received pkt for invalid ifidx %d\n", ifidx); |
9a1bb602 HM |
1106 | brcmu_pkt_buf_free_skb(skb); |
1107 | return; | |
1108 | } | |
1109 | brcmf_netif_rx(ifp, skb); | |
1110 | } | |
1111 | ||
1112 | ||
1113 | static void brcmf_msgbuf_process_event(struct brcmf_msgbuf *msgbuf, void *buf) | |
1114 | { | |
1115 | struct msgbuf_rx_event *event; | |
1116 | u32 idx; | |
1117 | u16 buflen; | |
1118 | struct sk_buff *skb; | |
1119 | ||
1120 | event = (struct msgbuf_rx_event *)buf; | |
1121 | idx = le32_to_cpu(event->msg.request_id); | |
1122 | buflen = le16_to_cpu(event->event_data_len); | |
1123 | ||
1124 | if (msgbuf->cur_eventbuf) | |
1125 | msgbuf->cur_eventbuf--; | |
1126 | brcmf_msgbuf_rxbuf_event_post(msgbuf); | |
1127 | ||
1128 | skb = brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, | |
1129 | msgbuf->rx_pktids, idx); | |
1130 | if (!skb) | |
1131 | return; | |
1132 | ||
1133 | if (msgbuf->rx_dataoffset) | |
1134 | skb_pull(skb, msgbuf->rx_dataoffset); | |
1135 | ||
1136 | skb_trim(skb, buflen); | |
1137 | ||
1138 | brcmf_msgbuf_rx_skb(msgbuf, skb, event->msg.ifidx); | |
1139 | } | |
1140 | ||
1141 | ||
1142 | static void | |
1143 | brcmf_msgbuf_process_rx_complete(struct brcmf_msgbuf *msgbuf, void *buf) | |
1144 | { | |
1145 | struct msgbuf_rx_complete *rx_complete; | |
1146 | struct sk_buff *skb; | |
1147 | u16 data_offset; | |
1148 | u16 buflen; | |
1149 | u32 idx; | |
1150 | ||
1151 | brcmf_msgbuf_update_rxbufpost_count(msgbuf, 1); | |
1152 | ||
1153 | rx_complete = (struct msgbuf_rx_complete *)buf; | |
1154 | data_offset = le16_to_cpu(rx_complete->data_offset); | |
1155 | buflen = le16_to_cpu(rx_complete->data_len); | |
1156 | idx = le32_to_cpu(rx_complete->msg.request_id); | |
1157 | ||
1158 | skb = brcmf_msgbuf_get_pktid(msgbuf->drvr->bus_if->dev, | |
1159 | msgbuf->rx_pktids, idx); | |
1160 | ||
1161 | if (data_offset) | |
1162 | skb_pull(skb, data_offset); | |
1163 | else if (msgbuf->rx_dataoffset) | |
1164 | skb_pull(skb, msgbuf->rx_dataoffset); | |
1165 | ||
1166 | skb_trim(skb, buflen); | |
1167 | ||
1168 | brcmf_msgbuf_rx_skb(msgbuf, skb, rx_complete->msg.ifidx); | |
1169 | } | |
1170 | ||
1171 | ||
1172 | static void | |
1173 | brcmf_msgbuf_process_flow_ring_create_response(struct brcmf_msgbuf *msgbuf, | |
1174 | void *buf) | |
1175 | { | |
1176 | struct msgbuf_flowring_create_resp *flowring_create_resp; | |
1177 | u16 status; | |
1178 | u16 flowid; | |
1179 | ||
1180 | flowring_create_resp = (struct msgbuf_flowring_create_resp *)buf; | |
1181 | ||
1182 | flowid = le16_to_cpu(flowring_create_resp->compl_hdr.flow_ring_id); | |
1183 | flowid -= BRCMF_NROF_H2D_COMMON_MSGRINGS; | |
1184 | status = le16_to_cpu(flowring_create_resp->compl_hdr.status); | |
1185 | ||
1186 | if (status) { | |
1187 | brcmf_err("Flowring creation failed, code %d\n", status); | |
1188 | brcmf_msgbuf_remove_flowring(msgbuf, flowid); | |
1189 | return; | |
1190 | } | |
1191 | brcmf_dbg(MSGBUF, "Flowring %d Create response status %d\n", flowid, | |
1192 | status); | |
1193 | ||
1194 | brcmf_flowring_open(msgbuf->flow, flowid); | |
1195 | ||
5ef1e604 | 1196 | brcmf_msgbuf_schedule_txdata(msgbuf, flowid, true); |
9a1bb602 HM |
1197 | } |
1198 | ||
1199 | ||
1200 | static void | |
1201 | brcmf_msgbuf_process_flow_ring_delete_response(struct brcmf_msgbuf *msgbuf, | |
1202 | void *buf) | |
1203 | { | |
1204 | struct msgbuf_flowring_delete_resp *flowring_delete_resp; | |
1205 | u16 status; | |
1206 | u16 flowid; | |
1207 | ||
1208 | flowring_delete_resp = (struct msgbuf_flowring_delete_resp *)buf; | |
1209 | ||
1210 | flowid = le16_to_cpu(flowring_delete_resp->compl_hdr.flow_ring_id); | |
1211 | flowid -= BRCMF_NROF_H2D_COMMON_MSGRINGS; | |
1212 | status = le16_to_cpu(flowring_delete_resp->compl_hdr.status); | |
1213 | ||
1214 | if (status) { | |
1215 | brcmf_err("Flowring deletion failed, code %d\n", status); | |
1216 | brcmf_flowring_delete(msgbuf->flow, flowid); | |
1217 | return; | |
1218 | } | |
1219 | brcmf_dbg(MSGBUF, "Flowring %d Delete response status %d\n", flowid, | |
1220 | status); | |
1221 | ||
1222 | brcmf_msgbuf_remove_flowring(msgbuf, flowid); | |
1223 | } | |
1224 | ||
1225 | ||
1226 | static void brcmf_msgbuf_process_msgtype(struct brcmf_msgbuf *msgbuf, void *buf) | |
1227 | { | |
1228 | struct msgbuf_common_hdr *msg; | |
1229 | ||
1230 | msg = (struct msgbuf_common_hdr *)buf; | |
1231 | switch (msg->msgtype) { | |
1232 | case MSGBUF_TYPE_FLOW_RING_CREATE_CMPLT: | |
1233 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_FLOW_RING_CREATE_CMPLT\n"); | |
1234 | brcmf_msgbuf_process_flow_ring_create_response(msgbuf, buf); | |
1235 | break; | |
1236 | case MSGBUF_TYPE_FLOW_RING_DELETE_CMPLT: | |
1237 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_FLOW_RING_DELETE_CMPLT\n"); | |
1238 | brcmf_msgbuf_process_flow_ring_delete_response(msgbuf, buf); | |
1239 | break; | |
1240 | case MSGBUF_TYPE_IOCTLPTR_REQ_ACK: | |
1241 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_IOCTLPTR_REQ_ACK\n"); | |
1242 | break; | |
1243 | case MSGBUF_TYPE_IOCTL_CMPLT: | |
1244 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_IOCTL_CMPLT\n"); | |
1245 | brcmf_msgbuf_process_ioctl_complete(msgbuf, buf); | |
1246 | break; | |
1247 | case MSGBUF_TYPE_WL_EVENT: | |
1248 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_WL_EVENT\n"); | |
1249 | brcmf_msgbuf_process_event(msgbuf, buf); | |
1250 | break; | |
1251 | case MSGBUF_TYPE_TX_STATUS: | |
1252 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_TX_STATUS\n"); | |
1253 | brcmf_msgbuf_process_txstatus(msgbuf, buf); | |
1254 | break; | |
1255 | case MSGBUF_TYPE_RX_CMPLT: | |
1256 | brcmf_dbg(MSGBUF, "MSGBUF_TYPE_RX_CMPLT\n"); | |
1257 | brcmf_msgbuf_process_rx_complete(msgbuf, buf); | |
1258 | break; | |
1259 | default: | |
1260 | brcmf_err("Unsupported msgtype %d\n", msg->msgtype); | |
1261 | break; | |
1262 | } | |
1263 | } | |
1264 | ||
1265 | ||
1266 | static void brcmf_msgbuf_process_rx(struct brcmf_msgbuf *msgbuf, | |
1267 | struct brcmf_commonring *commonring) | |
1268 | { | |
1269 | void *buf; | |
1270 | u16 count; | |
1271 | ||
1272 | again: | |
1273 | buf = brcmf_commonring_get_read_ptr(commonring, &count); | |
1274 | if (buf == NULL) | |
1275 | return; | |
1276 | ||
1277 | while (count) { | |
1278 | brcmf_msgbuf_process_msgtype(msgbuf, | |
1279 | buf + msgbuf->rx_dataoffset); | |
1280 | buf += brcmf_commonring_len_item(commonring); | |
1281 | count--; | |
1282 | } | |
1283 | brcmf_commonring_read_complete(commonring); | |
1284 | ||
1285 | if (commonring->r_ptr == 0) | |
1286 | goto again; | |
1287 | } | |
1288 | ||
1289 | ||
1290 | int brcmf_proto_msgbuf_rx_trigger(struct device *dev) | |
1291 | { | |
1292 | struct brcmf_bus *bus_if = dev_get_drvdata(dev); | |
1293 | struct brcmf_pub *drvr = bus_if->drvr; | |
1294 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
5ef1e604 | 1295 | struct brcmf_commonring *commonring; |
9a1bb602 HM |
1296 | void *buf; |
1297 | u32 flowid; | |
5ef1e604 | 1298 | int qlen; |
9a1bb602 HM |
1299 | |
1300 | buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_RX_COMPLETE]; | |
1301 | brcmf_msgbuf_process_rx(msgbuf, buf); | |
1302 | buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_TX_COMPLETE]; | |
1303 | brcmf_msgbuf_process_rx(msgbuf, buf); | |
1304 | buf = msgbuf->commonrings[BRCMF_D2H_MSGRING_CONTROL_COMPLETE]; | |
1305 | brcmf_msgbuf_process_rx(msgbuf, buf); | |
1306 | ||
1307 | for_each_set_bit(flowid, msgbuf->txstatus_done_map, | |
1308 | msgbuf->nrof_flowrings) { | |
1309 | clear_bit(flowid, msgbuf->txstatus_done_map); | |
5ef1e604 HM |
1310 | commonring = msgbuf->flowrings[flowid]; |
1311 | qlen = brcmf_flowring_qlen(msgbuf->flow, flowid); | |
1312 | if ((qlen > BRCMF_MSGBUF_TRICKLE_TXWORKER_THRS) || | |
1313 | ((qlen) && (atomic_read(&commonring->outstanding_tx) < | |
1314 | BRCMF_MSGBUF_TRICKLE_TXWORKER_THRS))) | |
1315 | brcmf_msgbuf_schedule_txdata(msgbuf, flowid, true); | |
9a1bb602 HM |
1316 | } |
1317 | ||
1318 | return 0; | |
1319 | } | |
1320 | ||
1321 | ||
1322 | void brcmf_msgbuf_delete_flowring(struct brcmf_pub *drvr, u8 flowid) | |
1323 | { | |
1324 | struct brcmf_msgbuf *msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
1325 | struct msgbuf_tx_flowring_delete_req *delete; | |
1326 | struct brcmf_commonring *commonring; | |
1327 | void *ret_ptr; | |
1328 | u8 ifidx; | |
1329 | int err; | |
1330 | ||
1331 | commonring = msgbuf->commonrings[BRCMF_H2D_MSGRING_CONTROL_SUBMIT]; | |
1332 | brcmf_commonring_lock(commonring); | |
1333 | ret_ptr = brcmf_commonring_reserve_for_write(commonring); | |
1334 | if (!ret_ptr) { | |
1335 | brcmf_err("FW unaware, flowring will be removed !!\n"); | |
1336 | brcmf_commonring_unlock(commonring); | |
1337 | brcmf_msgbuf_remove_flowring(msgbuf, flowid); | |
1338 | return; | |
1339 | } | |
1340 | ||
1341 | delete = (struct msgbuf_tx_flowring_delete_req *)ret_ptr; | |
1342 | ||
1343 | ifidx = brcmf_flowring_ifidx_get(msgbuf->flow, flowid); | |
1344 | ||
1345 | delete->msg.msgtype = MSGBUF_TYPE_FLOW_RING_DELETE; | |
1346 | delete->msg.ifidx = ifidx; | |
1347 | delete->msg.request_id = 0; | |
1348 | ||
1349 | delete->flow_ring_id = cpu_to_le16(flowid + | |
1350 | BRCMF_NROF_H2D_COMMON_MSGRINGS); | |
1351 | delete->reason = 0; | |
1352 | ||
1353 | brcmf_dbg(MSGBUF, "Send Flow Delete Req flow ID %d, ifindex %d\n", | |
1354 | flowid, ifidx); | |
1355 | ||
1356 | err = brcmf_commonring_write_complete(commonring); | |
1357 | brcmf_commonring_unlock(commonring); | |
1358 | if (err) { | |
1359 | brcmf_err("Failed to submit RING_DELETE, flowring will be removed\n"); | |
1360 | brcmf_msgbuf_remove_flowring(msgbuf, flowid); | |
1361 | } | |
1362 | } | |
1363 | ||
1364 | ||
1365 | int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) | |
1366 | { | |
1367 | struct brcmf_bus_msgbuf *if_msgbuf; | |
1368 | struct brcmf_msgbuf *msgbuf; | |
83297aaa | 1369 | u64 address; |
9a1bb602 HM |
1370 | u32 count; |
1371 | ||
1372 | if_msgbuf = drvr->bus_if->msgbuf; | |
3ba06610 | 1373 | msgbuf = kzalloc(sizeof(*msgbuf), GFP_KERNEL); |
9a1bb602 HM |
1374 | if (!msgbuf) |
1375 | goto fail; | |
1376 | ||
1377 | msgbuf->txflow_wq = create_singlethread_workqueue("msgbuf_txflow"); | |
1378 | if (msgbuf->txflow_wq == NULL) { | |
1379 | brcmf_err("workqueue creation failed\n"); | |
1380 | goto fail; | |
1381 | } | |
1382 | INIT_WORK(&msgbuf->txflow_work, brcmf_msgbuf_txflow_worker); | |
1383 | count = BITS_TO_LONGS(if_msgbuf->nrof_flowrings); | |
333c2aa0 | 1384 | count = count * sizeof(unsigned long); |
3ba06610 | 1385 | msgbuf->flow_map = kzalloc(count, GFP_KERNEL); |
9a1bb602 HM |
1386 | if (!msgbuf->flow_map) |
1387 | goto fail; | |
1388 | ||
3ba06610 | 1389 | msgbuf->txstatus_done_map = kzalloc(count, GFP_KERNEL); |
9a1bb602 HM |
1390 | if (!msgbuf->txstatus_done_map) |
1391 | goto fail; | |
1392 | ||
1393 | msgbuf->drvr = drvr; | |
1394 | msgbuf->ioctbuf = dma_alloc_coherent(drvr->bus_if->dev, | |
1395 | BRCMF_TX_IOCTL_MAX_MSG_SIZE, | |
1396 | &msgbuf->ioctbuf_handle, | |
3ba06610 | 1397 | GFP_KERNEL); |
9a1bb602 HM |
1398 | if (!msgbuf->ioctbuf) |
1399 | goto fail; | |
83297aaa | 1400 | address = (u64)msgbuf->ioctbuf_handle; |
9a1bb602 HM |
1401 | msgbuf->ioctbuf_phys_hi = address >> 32; |
1402 | msgbuf->ioctbuf_phys_lo = address & 0xffffffff; | |
1403 | ||
1404 | drvr->proto->hdrpull = brcmf_msgbuf_hdrpull; | |
1405 | drvr->proto->query_dcmd = brcmf_msgbuf_query_dcmd; | |
1406 | drvr->proto->set_dcmd = brcmf_msgbuf_set_dcmd; | |
1407 | drvr->proto->txdata = brcmf_msgbuf_txdata; | |
1408 | drvr->proto->configure_addr_mode = brcmf_msgbuf_configure_addr_mode; | |
1409 | drvr->proto->delete_peer = brcmf_msgbuf_delete_peer; | |
70b7d94b | 1410 | drvr->proto->add_tdls_peer = brcmf_msgbuf_add_tdls_peer; |
9a1bb602 HM |
1411 | drvr->proto->pd = msgbuf; |
1412 | ||
1413 | init_waitqueue_head(&msgbuf->ioctl_resp_wait); | |
1414 | ||
1415 | msgbuf->commonrings = | |
1416 | (struct brcmf_commonring **)if_msgbuf->commonrings; | |
1417 | msgbuf->flowrings = (struct brcmf_commonring **)if_msgbuf->flowrings; | |
1418 | msgbuf->nrof_flowrings = if_msgbuf->nrof_flowrings; | |
1419 | msgbuf->flowring_dma_handle = kzalloc(msgbuf->nrof_flowrings * | |
3ba06610 | 1420 | sizeof(*msgbuf->flowring_dma_handle), GFP_KERNEL); |
2d116b88 AS |
1421 | if (!msgbuf->flowring_dma_handle) |
1422 | goto fail; | |
9a1bb602 HM |
1423 | |
1424 | msgbuf->rx_dataoffset = if_msgbuf->rx_dataoffset; | |
1425 | msgbuf->max_rxbufpost = if_msgbuf->max_rxbufpost; | |
1426 | ||
1427 | msgbuf->max_ioctlrespbuf = BRCMF_MSGBUF_MAX_IOCTLRESPBUF_POST; | |
1428 | msgbuf->max_eventbuf = BRCMF_MSGBUF_MAX_EVENTBUF_POST; | |
1429 | ||
1430 | msgbuf->tx_pktids = brcmf_msgbuf_init_pktids(NR_TX_PKTIDS, | |
1431 | DMA_TO_DEVICE); | |
1432 | if (!msgbuf->tx_pktids) | |
1433 | goto fail; | |
1434 | msgbuf->rx_pktids = brcmf_msgbuf_init_pktids(NR_RX_PKTIDS, | |
1435 | DMA_FROM_DEVICE); | |
1436 | if (!msgbuf->rx_pktids) | |
1437 | goto fail; | |
1438 | ||
1439 | msgbuf->flow = brcmf_flowring_attach(drvr->bus_if->dev, | |
1440 | if_msgbuf->nrof_flowrings); | |
1441 | if (!msgbuf->flow) | |
1442 | goto fail; | |
1443 | ||
1444 | ||
1445 | brcmf_dbg(MSGBUF, "Feeding buffers, rx data %d, rx event %d, rx ioctl resp %d\n", | |
1446 | msgbuf->max_rxbufpost, msgbuf->max_eventbuf, | |
1447 | msgbuf->max_ioctlrespbuf); | |
1448 | count = 0; | |
1449 | do { | |
1450 | brcmf_msgbuf_rxbuf_data_fill(msgbuf); | |
1451 | if (msgbuf->max_rxbufpost != msgbuf->rxbufpost) | |
1452 | msleep(10); | |
1453 | else | |
1454 | break; | |
1455 | count++; | |
1456 | } while (count < 10); | |
1457 | brcmf_msgbuf_rxbuf_event_post(msgbuf); | |
1458 | brcmf_msgbuf_rxbuf_ioctlresp_post(msgbuf); | |
1459 | ||
3ba06610 HM |
1460 | INIT_WORK(&msgbuf->flowring_work, brcmf_msgbuf_flowring_worker); |
1461 | spin_lock_init(&msgbuf->flowring_work_lock); | |
1462 | INIT_LIST_HEAD(&msgbuf->work_queue); | |
1463 | ||
9a1bb602 HM |
1464 | return 0; |
1465 | ||
1466 | fail: | |
1467 | if (msgbuf) { | |
1468 | kfree(msgbuf->flow_map); | |
1469 | kfree(msgbuf->txstatus_done_map); | |
1470 | brcmf_msgbuf_release_pktids(msgbuf); | |
2d116b88 | 1471 | kfree(msgbuf->flowring_dma_handle); |
9a1bb602 HM |
1472 | if (msgbuf->ioctbuf) |
1473 | dma_free_coherent(drvr->bus_if->dev, | |
1474 | BRCMF_TX_IOCTL_MAX_MSG_SIZE, | |
1475 | msgbuf->ioctbuf, | |
1476 | msgbuf->ioctbuf_handle); | |
1477 | kfree(msgbuf); | |
1478 | } | |
1479 | return -ENOMEM; | |
1480 | } | |
1481 | ||
1482 | ||
1483 | void brcmf_proto_msgbuf_detach(struct brcmf_pub *drvr) | |
1484 | { | |
1485 | struct brcmf_msgbuf *msgbuf; | |
3ba06610 | 1486 | struct brcmf_msgbuf_work_item *work; |
9a1bb602 HM |
1487 | |
1488 | brcmf_dbg(TRACE, "Enter\n"); | |
1489 | if (drvr->proto->pd) { | |
1490 | msgbuf = (struct brcmf_msgbuf *)drvr->proto->pd; | |
3ba06610 HM |
1491 | cancel_work_sync(&msgbuf->flowring_work); |
1492 | while (!list_empty(&msgbuf->work_queue)) { | |
1493 | work = list_first_entry(&msgbuf->work_queue, | |
1494 | struct brcmf_msgbuf_work_item, | |
1495 | queue); | |
1496 | list_del(&work->queue); | |
1497 | kfree(work); | |
1498 | } | |
9a1bb602 HM |
1499 | kfree(msgbuf->flow_map); |
1500 | kfree(msgbuf->txstatus_done_map); | |
1501 | if (msgbuf->txflow_wq) | |
1502 | destroy_workqueue(msgbuf->txflow_wq); | |
1503 | ||
1504 | brcmf_flowring_detach(msgbuf->flow); | |
1505 | dma_free_coherent(drvr->bus_if->dev, | |
1506 | BRCMF_TX_IOCTL_MAX_MSG_SIZE, | |
1507 | msgbuf->ioctbuf, msgbuf->ioctbuf_handle); | |
1508 | brcmf_msgbuf_release_pktids(msgbuf); | |
2d116b88 | 1509 | kfree(msgbuf->flowring_dma_handle); |
9a1bb602 HM |
1510 | kfree(msgbuf); |
1511 | drvr->proto->pd = NULL; | |
1512 | } | |
1513 | } |