2 * Copyright (c) 2010 Broadcom Corporation
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.
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.
17 #include <linux/types.h>
18 #include <linux/netdevice.h>
24 #include <dngl_stats.h>
26 #include <dhd_proto.h>
30 int wifi_get_mac_addr(unsigned char *buf
);
33 extern int dhd_preinit_ioctls(dhd_pub_t
*dhd
);
35 /* Packet alignment for most efficient SDIO (can change based on platform) */
37 #define DHD_SDALIGN 32
39 #if !ISPOWEROF2(DHD_SDALIGN)
40 #error DHD_SDALIGN is not a power of 2!
43 #define RETRIES 2 /* # of retries to retrieve matching ioctl response */
44 #define BUS_HEADER_LEN (16+DHD_SDALIGN) /* Must be atleast SDPCM_RESERVE
45 * defined in dhd_sdio.c
46 * (amount of header tha might be added)
47 * plus any space that might be needed
48 * for alignment padding.
50 #define ROUND_UP_MARGIN 2048 /* Biggest SDIO block size possible for
51 * round off at the end of buffer
54 typedef struct dhd_prot
{
58 u8 bus_header
[BUS_HEADER_LEN
];
60 unsigned char buf
[WLC_IOCTL_MAXLEN
+ ROUND_UP_MARGIN
];
63 static int dhdcdc_msg(dhd_pub_t
*dhd
)
65 dhd_prot_t
*prot
= dhd
->prot
;
66 int len
= le32_to_cpu(prot
->msg
.len
) + sizeof(cdc_ioctl_t
);
68 DHD_TRACE(("%s: Enter\n", __func__
));
70 /* NOTE : cdc->msg.len holds the desired length of the buffer to be
71 * returned. Only up to CDC_MAX_MSG_SIZE of this buffer area
72 * is actually sent to the dongle
74 if (len
> CDC_MAX_MSG_SIZE
)
75 len
= CDC_MAX_MSG_SIZE
;
78 return dhd_bus_txctl(dhd
->bus
, (unsigned char *)&prot
->msg
, len
);
81 static int dhdcdc_cmplt(dhd_pub_t
*dhd
, u32 id
, u32 len
)
84 dhd_prot_t
*prot
= dhd
->prot
;
86 DHD_TRACE(("%s: Enter\n", __func__
));
90 dhd_bus_rxctl(dhd
->bus
, (unsigned char *)&prot
->msg
,
91 len
+ sizeof(cdc_ioctl_t
));
94 } while (CDC_IOC_ID(le32_to_cpu(prot
->msg
.flags
)) != id
);
100 dhdcdc_query_ioctl(dhd_pub_t
*dhd
, int ifidx
, uint cmd
, void *buf
, uint len
)
102 dhd_prot_t
*prot
= dhd
->prot
;
103 cdc_ioctl_t
*msg
= &prot
->msg
;
105 int ret
= 0, retries
= 0;
108 DHD_TRACE(("%s: Enter\n", __func__
));
109 DHD_CTL(("%s: cmd %d len %d\n", __func__
, cmd
, len
));
111 /* Respond "bcmerror" and "bcmerrorstr" with local cache */
112 if (cmd
== WLC_GET_VAR
&& buf
) {
113 if (!strcmp((char *)buf
, "bcmerrorstr")) {
114 strncpy((char *)buf
, bcmerrorstr(dhd
->dongle_error
),
117 } else if (!strcmp((char *)buf
, "bcmerror")) {
118 *(int *)buf
= dhd
->dongle_error
;
123 memset(msg
, 0, sizeof(cdc_ioctl_t
));
125 msg
->cmd
= cpu_to_le32(cmd
);
126 msg
->len
= cpu_to_le32(len
);
127 msg
->flags
= (++prot
->reqid
<< CDCF_IOC_ID_SHIFT
);
128 CDC_SET_IF_IDX(msg
, ifidx
);
129 msg
->flags
= cpu_to_le32(msg
->flags
);
132 memcpy(prot
->buf
, buf
, len
);
134 ret
= dhdcdc_msg(dhd
);
136 DHD_ERROR(("dhdcdc_query_ioctl: dhdcdc_msg failed w/status "
142 /* wait for interrupt and get first fragment */
143 ret
= dhdcdc_cmplt(dhd
, prot
->reqid
, len
);
147 flags
= le32_to_cpu(msg
->flags
);
148 id
= (flags
& CDCF_IOC_ID_MASK
) >> CDCF_IOC_ID_SHIFT
;
150 if ((id
< prot
->reqid
) && (++retries
< RETRIES
))
152 if (id
!= prot
->reqid
) {
153 DHD_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
154 dhd_ifname(dhd
, ifidx
), __func__
, id
, prot
->reqid
));
159 /* Check info buffer */
160 info
= (void *)&msg
[1];
162 /* Copy info buffer */
166 memcpy(buf
, info
, len
);
169 /* Check the ERROR flag */
170 if (flags
& CDCF_IOC_ERROR
) {
171 ret
= le32_to_cpu(msg
->status
);
172 /* Cache error from dongle */
173 dhd
->dongle_error
= ret
;
180 int dhdcdc_set_ioctl(dhd_pub_t
*dhd
, int ifidx
, uint cmd
, void *buf
, uint len
)
182 dhd_prot_t
*prot
= dhd
->prot
;
183 cdc_ioctl_t
*msg
= &prot
->msg
;
187 DHD_TRACE(("%s: Enter\n", __func__
));
188 DHD_CTL(("%s: cmd %d len %d\n", __func__
, cmd
, len
));
190 memset(msg
, 0, sizeof(cdc_ioctl_t
));
192 msg
->cmd
= cpu_to_le32(cmd
);
193 msg
->len
= cpu_to_le32(len
);
194 msg
->flags
= (++prot
->reqid
<< CDCF_IOC_ID_SHIFT
) | CDCF_IOC_SET
;
195 CDC_SET_IF_IDX(msg
, ifidx
);
196 msg
->flags
= cpu_to_le32(msg
->flags
);
199 memcpy(prot
->buf
, buf
, len
);
201 ret
= dhdcdc_msg(dhd
);
205 ret
= dhdcdc_cmplt(dhd
, prot
->reqid
, len
);
209 flags
= le32_to_cpu(msg
->flags
);
210 id
= (flags
& CDCF_IOC_ID_MASK
) >> CDCF_IOC_ID_SHIFT
;
212 if (id
!= prot
->reqid
) {
213 DHD_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
214 dhd_ifname(dhd
, ifidx
), __func__
, id
, prot
->reqid
));
219 /* Check the ERROR flag */
220 if (flags
& CDCF_IOC_ERROR
) {
221 ret
= le32_to_cpu(msg
->status
);
222 /* Cache error from dongle */
223 dhd
->dongle_error
= ret
;
230 extern int dhd_bus_interface(struct dhd_bus
*bus
, uint arg
, void *arg2
);
232 dhd_prot_ioctl(dhd_pub_t
*dhd
, int ifidx
, wl_ioctl_t
*ioc
, void *buf
, int len
)
234 dhd_prot_t
*prot
= dhd
->prot
;
237 if (dhd
->busstate
== DHD_BUS_DOWN
) {
238 DHD_ERROR(("%s : bus is down. we have nothing to do\n",
242 dhd_os_proto_block(dhd
);
244 DHD_TRACE(("%s: Enter\n", __func__
));
246 ASSERT(len
<= WLC_IOCTL_MAXLEN
);
248 if (len
> WLC_IOCTL_MAXLEN
)
251 if (prot
->pending
== true) {
252 DHD_TRACE(("CDC packet is pending!!!! cmd=0x%x (%lu) "
253 "lastcmd=0x%x (%lu)\n",
254 ioc
->cmd
, (unsigned long)ioc
->cmd
, prot
->lastcmd
,
255 (unsigned long)prot
->lastcmd
));
256 if ((ioc
->cmd
== WLC_SET_VAR
) || (ioc
->cmd
== WLC_GET_VAR
)) {
257 DHD_TRACE(("iovar cmd=%s\n", (char *)buf
));
262 prot
->pending
= true;
263 prot
->lastcmd
= ioc
->cmd
;
265 ret
= dhdcdc_set_ioctl(dhd
, ifidx
, ioc
->cmd
, buf
, len
);
267 ret
= dhdcdc_query_ioctl(dhd
, ifidx
, ioc
->cmd
, buf
, len
);
269 ioc
->used
= ret
- sizeof(cdc_ioctl_t
);
272 /* Too many programs assume ioctl() returns 0 on success */
276 cdc_ioctl_t
*msg
= &prot
->msg
;
277 /* len == needed when set/query fails from dongle */
278 ioc
->needed
= le32_to_cpu(msg
->len
);
281 /* Intercept the wme_dp ioctl here */
282 if ((!ret
) && (ioc
->cmd
== WLC_SET_VAR
) && (!strcmp(buf
, "wme_dp"))) {
285 slen
= strlen("wme_dp") + 1;
286 if (len
>= (int)(slen
+ sizeof(int)))
287 memcpy(&val
, (char *)buf
+ slen
, sizeof(int));
288 dhd
->wme_dp
= (u8
) le32_to_cpu(val
);
291 prot
->pending
= false;
294 dhd_os_proto_unblock(dhd
);
299 #define PKTSUMNEEDED(skb) \
300 (((struct sk_buff *)(skb))->ip_summed == CHECKSUM_PARTIAL)
301 #define PKTSETSUMGOOD(skb, x) \
302 (((struct sk_buff *)(skb))->ip_summed = \
303 ((x) ? CHECKSUM_UNNECESSARY : CHECKSUM_NONE))
305 /* PKTSETSUMNEEDED and PKTSUMGOOD are not possible because
306 skb->ip_summed is overloaded */
309 dhd_prot_iovar_op(dhd_pub_t
*dhdp
, const char *name
,
310 void *params
, int plen
, void *arg
, int len
, bool set
)
312 return BCME_UNSUPPORTED
;
315 void dhd_prot_dump(dhd_pub_t
*dhdp
, struct bcmstrbuf
*strbuf
)
317 bcm_bprintf(strbuf
, "Protocol CDC: reqid %d\n", dhdp
->prot
->reqid
);
320 void dhd_prot_hdrpush(dhd_pub_t
*dhd
, int ifidx
, struct sk_buff
*pktbuf
)
323 struct bdc_header
*h
;
326 DHD_TRACE(("%s: Enter\n", __func__
));
329 /* Push BDC header used to convey priority for buses that don't */
331 skb_push(pktbuf
, BDC_HEADER_LEN
);
333 h
= (struct bdc_header
*)(pktbuf
->data
);
335 h
->flags
= (BDC_PROTO_VER
<< BDC_FLAG_VER_SHIFT
);
336 if (PKTSUMNEEDED(pktbuf
))
337 h
->flags
|= BDC_FLAG_SUM_NEEDED
;
339 h
->priority
= (pktbuf
->priority
& BDC_PRIORITY_MASK
);
343 BDC_SET_IF_IDX(h
, ifidx
);
346 int dhd_prot_hdrpull(dhd_pub_t
*dhd
, int *ifidx
, struct sk_buff
*pktbuf
)
349 struct bdc_header
*h
;
352 DHD_TRACE(("%s: Enter\n", __func__
));
355 /* Pop BDC header used to convey priority for buses that don't */
357 if (pktbuf
->len
< BDC_HEADER_LEN
) {
358 DHD_ERROR(("%s: rx data too short (%d < %d)\n", __func__
,
359 pktbuf
->len
, BDC_HEADER_LEN
));
363 h
= (struct bdc_header
*)(pktbuf
->data
);
365 *ifidx
= BDC_GET_IF_IDX(h
);
366 if (*ifidx
>= DHD_MAX_IFS
) {
367 DHD_ERROR(("%s: rx data ifnum out of range (%d)\n",
372 if (((h
->flags
& BDC_FLAG_VER_MASK
) >> BDC_FLAG_VER_SHIFT
) !=
374 DHD_ERROR(("%s: non-BDC packet received, flags 0x%x\n",
375 dhd_ifname(dhd
, *ifidx
), h
->flags
));
379 if (h
->flags
& BDC_FLAG_SUM_GOOD
) {
380 DHD_INFO(("%s: BDC packet received with good rx-csum, "
382 dhd_ifname(dhd
, *ifidx
), h
->flags
));
383 PKTSETSUMGOOD(pktbuf
, true);
386 pktbuf
->priority
= h
->priority
& BDC_PRIORITY_MASK
;
388 skb_pull(pktbuf
, BDC_HEADER_LEN
);
394 int dhd_prot_attach(dhd_pub_t
*dhd
)
398 cdc
= kzalloc(sizeof(dhd_prot_t
), GFP_ATOMIC
);
400 DHD_ERROR(("%s: kmalloc failed\n", __func__
));
404 /* ensure that the msg buf directly follows the cdc msg struct */
405 if ((unsigned long)(&cdc
->msg
+ 1) != (unsigned long)cdc
->buf
) {
406 DHD_ERROR(("dhd_prot_t is not correctly defined\n"));
412 dhd
->hdrlen
+= BDC_HEADER_LEN
;
414 dhd
->maxctl
= WLC_IOCTL_MAXLEN
+ sizeof(cdc_ioctl_t
) + ROUND_UP_MARGIN
;
422 /* ~NOTE~ What if another thread is waiting on the semaphore? Holding it? */
423 void dhd_prot_detach(dhd_pub_t
*dhd
)
429 void dhd_prot_dstats(dhd_pub_t
*dhd
)
431 /* No stats from dongle added yet, copy bus stats */
432 dhd
->dstats
.tx_packets
= dhd
->tx_packets
;
433 dhd
->dstats
.tx_errors
= dhd
->tx_errors
;
434 dhd
->dstats
.rx_packets
= dhd
->rx_packets
;
435 dhd
->dstats
.rx_errors
= dhd
->rx_errors
;
436 dhd
->dstats
.rx_dropped
= dhd
->rx_dropped
;
437 dhd
->dstats
.multicast
= dhd
->rx_multicast
;
441 int dhd_prot_init(dhd_pub_t
*dhd
)
446 DHD_TRACE(("%s: Enter\n", __func__
));
448 dhd_os_proto_block(dhd
);
450 /* Get the device MAC address */
451 strcpy(buf
, "cur_etheraddr");
452 ret
= dhdcdc_query_ioctl(dhd
, 0, WLC_GET_VAR
, buf
, sizeof(buf
));
454 dhd_os_proto_unblock(dhd
);
457 memcpy(dhd
->mac
, buf
, ETH_ALEN
);
459 dhd_os_proto_unblock(dhd
);
461 #ifdef EMBEDDED_PLATFORM
462 ret
= dhd_preinit_ioctls(dhd
);
463 #endif /* EMBEDDED_PLATFORM */
465 /* Always assumes wl for now */
471 void dhd_prot_stop(dhd_pub_t
*dhd
)
473 /* Nothing to do for CDC */
This page took 0.059562 seconds and 6 git commands to generate.