aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2008-11-17 19:47:21 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-11-18 17:26:26 -0500
commit4018517a1a69a85c3d61b20fa02f187b80773137 (patch)
tree08209615ff38b6c9e9af994c7360976e0a494ac6 /drivers
parent8e3bad65a59915f2ddc40f62a180ad81695d8440 (diff)
iwlagn: fix RX skb alignment
So I dug deeper into the DMA problems I had with iwlagn and a kind soul helped me in that he said something about pci-e alignment and mentioned the iwl_rx_allocate function to check for crossing 4KB boundaries. Since there's 8KB A-MPDU support, crossing 4k boundaries didn't seem like something the device would fail with, but when I looked into the function for a minute anyway I stumbled over this little gem: BUG_ON(rxb->dma_addr & (~DMA_BIT_MASK(36) & 0xff)); Clearly, that is a totally bogus check, one would hope the compiler removes it entirely. (Think about it) After fixing it, I obviously ran into it, nothing guarantees the alignment the way you want it, because of the way skbs and their headroom are allocated. I won't explain that here nor double-check that I'm right, that goes beyond what most of the CC'ed people care about. So then I came up with the patch below, and so far my system has survived minutes with 64K pages, when it would previously fail in seconds. And I haven't seen a single instance of the TX bug either. But when you see the patch it'll be pretty obvious to you why. This should fix the following reported kernel bugs: http://bugzilla.kernel.org/show_bug.cgi?id=11596 http://bugzilla.kernel.org/show_bug.cgi?id=11393 http://bugzilla.kernel.org/show_bug.cgi?id=11983 I haven't checked if there are any elsewhere, but I suppose RHBZ will have a few instances too... I'd like to ask anyone who is CC'ed (those are people I know ran into the bug) to try this patch. I am convinced that this patch is correct in spirit, but I haven't understood why, for example, there are so many unmap calls. I'm not entirely convinced that this is the only bug leading to the TX reply errors. Signed-off-by: Johannes Berg <johannes@sipsolutions.net> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c26
3 files changed, 22 insertions, 13 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 6751bb2b8ae2..444c5cc05f03 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -1384,7 +1384,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
1384 1384
1385 rxq->queue[i] = NULL; 1385 rxq->queue[i] = NULL;
1386 1386
1387 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr, 1387 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->aligned_dma_addr,
1388 priv->hw_params.rx_buf_size, 1388 priv->hw_params.rx_buf_size,
1389 PCI_DMA_FROMDEVICE); 1389 PCI_DMA_FROMDEVICE);
1390 pkt = (struct iwl_rx_packet *)rxb->skb->data; 1390 pkt = (struct iwl_rx_packet *)rxb->skb->data;
@@ -1436,8 +1436,8 @@ void iwl_rx_handle(struct iwl_priv *priv)
1436 rxb->skb = NULL; 1436 rxb->skb = NULL;
1437 } 1437 }
1438 1438
1439 pci_unmap_single(priv->pci_dev, rxb->dma_addr, 1439 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
1440 priv->hw_params.rx_buf_size, 1440 priv->hw_params.rx_buf_size + 256,
1441 PCI_DMA_FROMDEVICE); 1441 PCI_DMA_FROMDEVICE);
1442 spin_lock_irqsave(&rxq->lock, flags); 1442 spin_lock_irqsave(&rxq->lock, flags);
1443 list_add_tail(&rxb->list, &priv->rxq.rx_used); 1443 list_add_tail(&rxb->list, &priv->rxq.rx_used);
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index c018121085e9..9966d4e384ce 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -89,7 +89,8 @@ extern struct iwl_cfg iwl5100_abg_cfg;
89#define DEFAULT_LONG_RETRY_LIMIT 4U 89#define DEFAULT_LONG_RETRY_LIMIT 4U
90 90
91struct iwl_rx_mem_buffer { 91struct iwl_rx_mem_buffer {
92 dma_addr_t dma_addr; 92 dma_addr_t real_dma_addr;
93 dma_addr_t aligned_dma_addr;
93 struct sk_buff *skb; 94 struct sk_buff *skb;
94 struct list_head list; 95 struct list_head list;
95}; 96};
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 7cde9d76ff5d..0509c16dbe75 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -204,7 +204,7 @@ int iwl_rx_queue_restock(struct iwl_priv *priv)
204 list_del(element); 204 list_del(element);
205 205
206 /* Point to Rx buffer via next RBD in circular buffer */ 206 /* Point to Rx buffer via next RBD in circular buffer */
207 rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->dma_addr); 207 rxq->bd[rxq->write] = iwl_dma_addr2rbd_ptr(priv, rxb->aligned_dma_addr);
208 rxq->queue[rxq->write] = rxb; 208 rxq->queue[rxq->write] = rxb;
209 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK; 209 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
210 rxq->free_count--; 210 rxq->free_count--;
@@ -251,7 +251,7 @@ void iwl_rx_allocate(struct iwl_priv *priv)
251 rxb = list_entry(element, struct iwl_rx_mem_buffer, list); 251 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
252 252
253 /* Alloc a new receive buffer */ 253 /* Alloc a new receive buffer */
254 rxb->skb = alloc_skb(priv->hw_params.rx_buf_size, 254 rxb->skb = alloc_skb(priv->hw_params.rx_buf_size + 256,
255 __GFP_NOWARN | GFP_ATOMIC); 255 __GFP_NOWARN | GFP_ATOMIC);
256 if (!rxb->skb) { 256 if (!rxb->skb) {
257 if (net_ratelimit()) 257 if (net_ratelimit())
@@ -266,9 +266,17 @@ void iwl_rx_allocate(struct iwl_priv *priv)
266 list_del(element); 266 list_del(element);
267 267
268 /* Get physical address of RB/SKB */ 268 /* Get physical address of RB/SKB */
269 rxb->dma_addr = 269 rxb->real_dma_addr = pci_map_single(
270 pci_map_single(priv->pci_dev, rxb->skb->data, 270 priv->pci_dev,
271 priv->hw_params.rx_buf_size, PCI_DMA_FROMDEVICE); 271 rxb->skb->data,
272 priv->hw_params.rx_buf_size + 256,
273 PCI_DMA_FROMDEVICE);
274 /* dma address must be no more than 36 bits */
275 BUG_ON(rxb->real_dma_addr & ~DMA_BIT_MASK(36));
276 /* and also 256 byte aligned! */
277 rxb->aligned_dma_addr = ALIGN(rxb->real_dma_addr, 256);
278 skb_reserve(rxb->skb, rxb->aligned_dma_addr - rxb->real_dma_addr);
279
272 list_add_tail(&rxb->list, &rxq->rx_free); 280 list_add_tail(&rxb->list, &rxq->rx_free);
273 rxq->free_count++; 281 rxq->free_count++;
274 } 282 }
@@ -300,8 +308,8 @@ void iwl_rx_queue_free(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
300 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) { 308 for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
301 if (rxq->pool[i].skb != NULL) { 309 if (rxq->pool[i].skb != NULL) {
302 pci_unmap_single(priv->pci_dev, 310 pci_unmap_single(priv->pci_dev,
303 rxq->pool[i].dma_addr, 311 rxq->pool[i].real_dma_addr,
304 priv->hw_params.rx_buf_size, 312 priv->hw_params.rx_buf_size + 256,
305 PCI_DMA_FROMDEVICE); 313 PCI_DMA_FROMDEVICE);
306 dev_kfree_skb(rxq->pool[i].skb); 314 dev_kfree_skb(rxq->pool[i].skb);
307 } 315 }
@@ -354,8 +362,8 @@ void iwl_rx_queue_reset(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
354 * to an SKB, so we need to unmap and free potential storage */ 362 * to an SKB, so we need to unmap and free potential storage */
355 if (rxq->pool[i].skb != NULL) { 363 if (rxq->pool[i].skb != NULL) {
356 pci_unmap_single(priv->pci_dev, 364 pci_unmap_single(priv->pci_dev,
357 rxq->pool[i].dma_addr, 365 rxq->pool[i].real_dma_addr,
358 priv->hw_params.rx_buf_size, 366 priv->hw_params.rx_buf_size + 256,
359 PCI_DMA_FROMDEVICE); 367 PCI_DMA_FROMDEVICE);
360 priv->alloc_rxb_skb--; 368 priv->alloc_rxb_skb--;
361 dev_kfree_skb(rxq->pool[i].skb); 369 dev_kfree_skb(rxq->pool[i].skb);