aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/p54/p54common.c
diff options
context:
space:
mode:
authorChristian Lamparter <chunkeey@web.de>2009-01-09 15:05:31 -0500
committerJohn W. Linville <linville@tuxdriver.com>2009-01-29 16:00:18 -0500
commit63f2dc9f2fd63c8b66f49c53cd26236f3f0785fd (patch)
treed5735a0bcc21ea3c9a037c8cfc85d4ab86ad10be /drivers/net/wireless/p54/p54common.c
parent6dd1bf3118b62a3ce241dc2b7e05e3d4a28c9eb1 (diff)
p54: refactor p54_alloc_skb
Old firmwares had no problems processing frames which filled eighth of the memory window. However we have to be a bit more careful with fat frames when we talk to new firmwares. Apart from that, I confess the old logic was a bit weird and not very sophisticated. Signed-off-by: Christian Lamparter <chunkeey@web.de> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/p54/p54common.c')
-rw-r--r--drivers/net/wireless/p54/p54common.c74
1 files changed, 33 insertions, 41 deletions
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index e463c7c3a7e0..c6dcf98aad3e 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -1104,25 +1104,29 @@ static int p54_assign_address(struct ieee80211_hw *dev, struct sk_buff *skb,
1104 return 0; 1104 return 0;
1105} 1105}
1106 1106
1107static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev, 1107static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev, u16 hdr_flags,
1108 u16 hdr_flags, u16 len, u16 type, gfp_t memflags) 1108 u16 payload_len, u16 type, gfp_t memflags)
1109{ 1109{
1110 struct p54_common *priv = dev->priv; 1110 struct p54_common *priv = dev->priv;
1111 struct p54_hdr *hdr; 1111 struct p54_hdr *hdr;
1112 struct sk_buff *skb; 1112 struct sk_buff *skb;
1113 size_t frame_len = sizeof(*hdr) + payload_len;
1113 1114
1114 skb = __dev_alloc_skb(len + priv->tx_hdr_len, memflags); 1115 if (frame_len > P54_MAX_CTRL_FRAME_LEN)
1116 return NULL;
1117
1118 skb = __dev_alloc_skb(priv->tx_hdr_len + frame_len, memflags);
1115 if (!skb) 1119 if (!skb)
1116 return NULL; 1120 return NULL;
1117 skb_reserve(skb, priv->tx_hdr_len); 1121 skb_reserve(skb, priv->tx_hdr_len);
1118 1122
1119 hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr)); 1123 hdr = (struct p54_hdr *) skb_put(skb, sizeof(*hdr));
1120 hdr->flags = cpu_to_le16(hdr_flags); 1124 hdr->flags = cpu_to_le16(hdr_flags);
1121 hdr->len = cpu_to_le16(len - sizeof(*hdr)); 1125 hdr->len = cpu_to_le16(payload_len);
1122 hdr->type = cpu_to_le16(type); 1126 hdr->type = cpu_to_le16(type);
1123 hdr->tries = hdr->rts_tries = 0; 1127 hdr->tries = hdr->rts_tries = 0;
1124 1128
1125 if (unlikely(p54_assign_address(dev, skb, hdr, len))) { 1129 if (p54_assign_address(dev, skb, hdr, frame_len)) {
1126 kfree_skb(skb); 1130 kfree_skb(skb);
1127 return NULL; 1131 return NULL;
1128 } 1132 }
@@ -1132,7 +1136,6 @@ static struct sk_buff *p54_alloc_skb(struct ieee80211_hw *dev,
1132int p54_read_eeprom(struct ieee80211_hw *dev) 1136int p54_read_eeprom(struct ieee80211_hw *dev)
1133{ 1137{
1134 struct p54_common *priv = dev->priv; 1138 struct p54_common *priv = dev->priv;
1135 struct p54_hdr *hdr = NULL;
1136 struct p54_eeprom_lm86 *eeprom_hdr; 1139 struct p54_eeprom_lm86 *eeprom_hdr;
1137 struct sk_buff *skb; 1140 struct sk_buff *skb;
1138 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize; 1141 size_t eeprom_size = 0x2020, offset = 0, blocksize, maxblocksize;
@@ -1145,9 +1148,9 @@ int p54_read_eeprom(struct ieee80211_hw *dev)
1145 else 1148 else
1146 maxblocksize -= 0x4; 1149 maxblocksize -= 0x4;
1147 1150
1148 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(*hdr) + 1151 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(*eeprom_hdr) +
1149 sizeof(*eeprom_hdr) + maxblocksize, 1152 maxblocksize, P54_CONTROL_TYPE_EEPROM_READBACK,
1150 P54_CONTROL_TYPE_EEPROM_READBACK, GFP_KERNEL); 1153 GFP_KERNEL);
1151 if (!skb) 1154 if (!skb)
1152 goto free; 1155 goto free;
1153 priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL); 1156 priv->eeprom = kzalloc(EEPROM_READBACK_LEN, GFP_KERNEL);
@@ -1203,9 +1206,8 @@ static int p54_set_tim(struct ieee80211_hw *dev, struct ieee80211_sta *sta,
1203 struct sk_buff *skb; 1206 struct sk_buff *skb;
1204 struct p54_tim *tim; 1207 struct p54_tim *tim;
1205 1208
1206 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, 1209 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*tim),
1207 sizeof(struct p54_hdr) + sizeof(*tim), 1210 P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
1208 P54_CONTROL_TYPE_TIM, GFP_ATOMIC);
1209 if (!skb) 1211 if (!skb)
1210 return -ENOMEM; 1212 return -ENOMEM;
1211 1213
@@ -1222,9 +1224,8 @@ static int p54_sta_unlock(struct ieee80211_hw *dev, u8 *addr)
1222 struct sk_buff *skb; 1224 struct sk_buff *skb;
1223 struct p54_sta_unlock *sta; 1225 struct p54_sta_unlock *sta;
1224 1226
1225 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, 1227 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*sta),
1226 sizeof(struct p54_hdr) + sizeof(*sta), 1228 P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
1227 P54_CONTROL_TYPE_PSM_STA_UNLOCK, GFP_ATOMIC);
1228 if (!skb) 1229 if (!skb)
1229 return -ENOMEM; 1230 return -ENOMEM;
1230 1231
@@ -1264,9 +1265,8 @@ static int p54_tx_cancel(struct ieee80211_hw *dev, struct sk_buff *entry)
1264 struct p54_hdr *hdr; 1265 struct p54_hdr *hdr;
1265 struct p54_txcancel *cancel; 1266 struct p54_txcancel *cancel;
1266 1267
1267 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, 1268 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*cancel),
1268 sizeof(struct p54_hdr) + sizeof(*cancel), 1269 P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
1269 P54_CONTROL_TYPE_TXCANCEL, GFP_ATOMIC);
1270 if (!skb) 1270 if (!skb)
1271 return -ENOMEM; 1271 return -ENOMEM;
1272 1272
@@ -1548,9 +1548,8 @@ static int p54_setup_mac(struct ieee80211_hw *dev)
1548 struct p54_setup_mac *setup; 1548 struct p54_setup_mac *setup;
1549 u16 mode; 1549 u16 mode;
1550 1550
1551 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup) + 1551 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*setup),
1552 sizeof(struct p54_hdr), P54_CONTROL_TYPE_SETUP, 1552 P54_CONTROL_TYPE_SETUP, GFP_ATOMIC);
1553 GFP_ATOMIC);
1554 if (!skb) 1553 if (!skb)
1555 return -ENOMEM; 1554 return -ENOMEM;
1556 1555
@@ -1628,9 +1627,8 @@ static int p54_scan(struct ieee80211_hw *dev, u16 mode, u16 dwell)
1628 __le16 freq = cpu_to_le16(dev->conf.channel->center_freq); 1627 __le16 freq = cpu_to_le16(dev->conf.channel->center_freq);
1629 int band = dev->conf.channel->band; 1628 int band = dev->conf.channel->band;
1630 1629
1631 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan) + 1630 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*chan),
1632 sizeof(struct p54_hdr), P54_CONTROL_TYPE_SCAN, 1631 P54_CONTROL_TYPE_SCAN, GFP_ATOMIC);
1633 GFP_ATOMIC);
1634 if (!skb) 1632 if (!skb)
1635 return -ENOMEM; 1633 return -ENOMEM;
1636 1634
@@ -1710,9 +1708,8 @@ static int p54_set_leds(struct ieee80211_hw *dev, int mode, int link, int act)
1710 struct sk_buff *skb; 1708 struct sk_buff *skb;
1711 struct p54_led *led; 1709 struct p54_led *led;
1712 1710
1713 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led) + 1711 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*led),
1714 sizeof(struct p54_hdr), P54_CONTROL_TYPE_LED, 1712 P54_CONTROL_TYPE_LED, GFP_ATOMIC);
1715 GFP_ATOMIC);
1716 if (!skb) 1713 if (!skb)
1717 return -ENOMEM; 1714 return -ENOMEM;
1718 1715
@@ -1739,9 +1736,8 @@ static int p54_set_edcf(struct ieee80211_hw *dev)
1739 struct sk_buff *skb; 1736 struct sk_buff *skb;
1740 struct p54_edcf *edcf; 1737 struct p54_edcf *edcf;
1741 1738
1742 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf) + 1739 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*edcf),
1743 sizeof(struct p54_hdr), P54_CONTROL_TYPE_DCFINIT, 1740 P54_CONTROL_TYPE_DCFINIT, GFP_ATOMIC);
1744 GFP_ATOMIC);
1745 if (!skb) 1741 if (!skb)
1746 return -ENOMEM; 1742 return -ENOMEM;
1747 1743
@@ -1778,9 +1774,8 @@ static int p54_set_ps(struct ieee80211_hw *dev)
1778 else 1774 else
1779 mode = P54_PSM_CAM; 1775 mode = P54_PSM_CAM;
1780 1776
1781 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*psm) + 1777 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*psm),
1782 sizeof(struct p54_hdr), P54_CONTROL_TYPE_PSM, 1778 P54_CONTROL_TYPE_PSM, GFP_ATOMIC);
1783 GFP_ATOMIC);
1784 if (!skb) 1779 if (!skb)
1785 return -ENOMEM; 1780 return -ENOMEM;
1786 1781
@@ -2083,10 +2078,8 @@ static int p54_init_xbow_synth(struct ieee80211_hw *dev)
2083 struct sk_buff *skb; 2078 struct sk_buff *skb;
2084 struct p54_xbow_synth *xbow; 2079 struct p54_xbow_synth *xbow;
2085 2080
2086 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow) + 2081 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*xbow),
2087 sizeof(struct p54_hdr), 2082 P54_CONTROL_TYPE_XBOW_SYNTH_CFG, GFP_KERNEL);
2088 P54_CONTROL_TYPE_XBOW_SYNTH_CFG,
2089 GFP_KERNEL);
2090 if (!skb) 2083 if (!skb)
2091 return -ENOMEM; 2084 return -ENOMEM;
2092 2085
@@ -2115,7 +2108,7 @@ static void p54_work(struct work_struct *work)
2115 * 2. cancel stuck frames / reset the device if necessary. 2108 * 2. cancel stuck frames / reset the device if necessary.
2116 */ 2109 */
2117 2110
2118 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL, sizeof(struct p54_hdr) + 2111 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL,
2119 sizeof(struct p54_statistics), 2112 sizeof(struct p54_statistics),
2120 P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL); 2113 P54_CONTROL_TYPE_STAT_READBACK, GFP_KERNEL);
2121 if (!skb) 2114 if (!skb)
@@ -2226,9 +2219,8 @@ static int p54_set_key(struct ieee80211_hw *dev, enum set_key_cmd cmd,
2226 } 2219 }
2227 2220
2228 mutex_lock(&priv->conf_mutex); 2221 mutex_lock(&priv->conf_mutex);
2229 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey) + 2222 skb = p54_alloc_skb(dev, P54_HDR_FLAG_CONTROL_OPSET, sizeof(*rxkey),
2230 sizeof(struct p54_hdr), P54_CONTROL_TYPE_RX_KEYCACHE, 2223 P54_CONTROL_TYPE_RX_KEYCACHE, GFP_ATOMIC);
2231 GFP_ATOMIC);
2232 if (!skb) { 2224 if (!skb) {
2233 mutex_unlock(&priv->conf_mutex); 2225 mutex_unlock(&priv->conf_mutex);
2234 return -ENOMEM; 2226 return -ENOMEM;