xref: /openbmc/linux/drivers/net/wireless/ath/main.c (revision d15dd3e5)
1a1c55580SChristian Lamparter /*
2a1c55580SChristian Lamparter  * Copyright (c) 2009 Atheros Communications Inc.
3a1c55580SChristian Lamparter  *
4a1c55580SChristian Lamparter  * Permission to use, copy, modify, and/or distribute this software for any
5a1c55580SChristian Lamparter  * purpose with or without fee is hereby granted, provided that the above
6a1c55580SChristian Lamparter  * copyright notice and this permission notice appear in all copies.
7a1c55580SChristian Lamparter  *
8a1c55580SChristian Lamparter  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9a1c55580SChristian Lamparter  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10a1c55580SChristian Lamparter  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11a1c55580SChristian Lamparter  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12a1c55580SChristian Lamparter  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13a1c55580SChristian Lamparter  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14a1c55580SChristian Lamparter  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15a1c55580SChristian Lamparter  */
16a1c55580SChristian Lamparter 
17a1c55580SChristian Lamparter #include <linux/kernel.h>
18a1c55580SChristian Lamparter #include <linux/module.h>
19a1c55580SChristian Lamparter 
20d15dd3e5SLuis R. Rodriguez #include "ath.h"
21d15dd3e5SLuis R. Rodriguez 
22a1c55580SChristian Lamparter MODULE_AUTHOR("Atheros Communications");
23a1c55580SChristian Lamparter MODULE_DESCRIPTION("Shared library for Atheros wireless LAN cards.");
24a1c55580SChristian Lamparter MODULE_LICENSE("Dual BSD/GPL");
25d15dd3e5SLuis R. Rodriguez 
26d15dd3e5SLuis R. Rodriguez struct sk_buff *ath_rxbuf_alloc(struct ath_common *common,
27d15dd3e5SLuis R. Rodriguez 				u32 len,
28d15dd3e5SLuis R. Rodriguez 				gfp_t gfp_mask)
29d15dd3e5SLuis R. Rodriguez {
30d15dd3e5SLuis R. Rodriguez 	struct sk_buff *skb;
31d15dd3e5SLuis R. Rodriguez 	u32 off;
32d15dd3e5SLuis R. Rodriguez 
33d15dd3e5SLuis R. Rodriguez 	/*
34d15dd3e5SLuis R. Rodriguez 	 * Cache-line-align.  This is important (for the
35d15dd3e5SLuis R. Rodriguez 	 * 5210 at least) as not doing so causes bogus data
36d15dd3e5SLuis R. Rodriguez 	 * in rx'd frames.
37d15dd3e5SLuis R. Rodriguez 	 */
38d15dd3e5SLuis R. Rodriguez 
39d15dd3e5SLuis R. Rodriguez 	/* Note: the kernel can allocate a value greater than
40d15dd3e5SLuis R. Rodriguez 	 * what we ask it to give us. We really only need 4 KB as that
41d15dd3e5SLuis R. Rodriguez 	 * is this hardware supports and in fact we need at least 3849
42d15dd3e5SLuis R. Rodriguez 	 * as that is the MAX AMSDU size this hardware supports.
43d15dd3e5SLuis R. Rodriguez 	 * Unfortunately this means we may get 8 KB here from the
44d15dd3e5SLuis R. Rodriguez 	 * kernel... and that is actually what is observed on some
45d15dd3e5SLuis R. Rodriguez 	 * systems :( */
46d15dd3e5SLuis R. Rodriguez 	skb = __dev_alloc_skb(len + common->cachelsz - 1, gfp_mask);
47d15dd3e5SLuis R. Rodriguez 	if (skb != NULL) {
48d15dd3e5SLuis R. Rodriguez 		off = ((unsigned long) skb->data) % common->cachelsz;
49d15dd3e5SLuis R. Rodriguez 		if (off != 0)
50d15dd3e5SLuis R. Rodriguez 			skb_reserve(skb, common->cachelsz - off);
51d15dd3e5SLuis R. Rodriguez 	} else {
52d15dd3e5SLuis R. Rodriguez 		printk(KERN_ERR "skbuff alloc of size %u failed\n", len);
53d15dd3e5SLuis R. Rodriguez 		return NULL;
54d15dd3e5SLuis R. Rodriguez 	}
55d15dd3e5SLuis R. Rodriguez 
56d15dd3e5SLuis R. Rodriguez 	return skb;
57d15dd3e5SLuis R. Rodriguez }
58d15dd3e5SLuis R. Rodriguez EXPORT_SYMBOL(ath_rxbuf_alloc);
59