From fcf6b1bca8cdfefc986909b57277af4628955bd8 Mon Sep 17 00:00:00 2001 From: Bob Copeland Date: Sat, 10 Jan 2009 14:42:54 -0500 Subject: ath5k: fix bf->skb==NULL panic in ath5k_tasklet_rx Under memory pressure, we may not be able to allocate a new skb for new packets. If the allocation fails, ath5k_tasklet_rx will exit but will leave a buffer in the list with a NULL skb, eventually triggering a BUG_ON. Extract the skb allocation from ath5k_rxbuf_setup() and change the tasklet to allocate the next skb before accepting a packet. Changes-licensed-under: 3-Clause-BSD Signed-off-by: Bob Copeland Signed-off-by: John W. Linville --- drivers/net/wireless/ath5k/base.c | 85 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 32 deletions(-) (limited to 'drivers/net/wireless') diff --git a/drivers/net/wireless/ath5k/base.c b/drivers/net/wireless/ath5k/base.c index a533ed60bb4..1d77ee9d6e9 100644 --- a/drivers/net/wireless/ath5k/base.c +++ b/drivers/net/wireless/ath5k/base.c @@ -1098,6 +1098,42 @@ ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix) * Buffers setup * \***************/ +static +struct sk_buff *ath5k_rx_skb_alloc(struct ath5k_softc *sc, dma_addr_t *skb_addr) +{ + struct sk_buff *skb; + unsigned int off; + + /* + * Allocate buffer with headroom_needed space for the + * fake physical layer header at the start. + */ + skb = dev_alloc_skb(sc->rxbufsize + sc->cachelsz - 1); + + if (!skb) { + ATH5K_ERR(sc, "can't alloc skbuff of size %u\n", + sc->rxbufsize + sc->cachelsz - 1); + return NULL; + } + /* + * Cache-line-align. This is important (for the + * 5210 at least) as not doing so causes bogus data + * in rx'd frames. + */ + off = ((unsigned long)skb->data) % sc->cachelsz; + if (off != 0) + skb_reserve(skb, sc->cachelsz - off); + + *skb_addr = pci_map_single(sc->pdev, + skb->data, sc->rxbufsize, PCI_DMA_FROMDEVICE); + if (unlikely(pci_dma_mapping_error(sc->pdev, *skb_addr))) { + ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__); + dev_kfree_skb(skb); + return NULL; + } + return skb; +} + static int ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) { @@ -1105,37 +1141,11 @@ ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf) struct sk_buff *skb = bf->skb; struct ath5k_desc *ds; - if (likely(skb == NULL)) { - unsigned int off; - - /* - * Allocate buffer with headroom_needed space for the - * fake physical layer header at the start. - */ - skb = dev_alloc_skb(sc->rxbufsize + sc->cachelsz - 1); - if (unlikely(skb == NULL)) { - ATH5K_ERR(sc, "can't alloc skbuff of size %u\n", - sc->rxbufsize + sc->cachelsz - 1); + if (!skb) { + skb = ath5k_rx_skb_alloc(sc, &bf->skbaddr); + if (!skb) return -ENOMEM; - } - /* - * Cache-line-align. This is important (for the - * 5210 at least) as not doing so causes bogus data - * in rx'd frames. - */ - off = ((unsigned long)skb->data) % sc->cachelsz; - if (off != 0) - skb_reserve(skb, sc->cachelsz - off); - bf->skb = skb; - bf->skbaddr = pci_map_single(sc->pdev, - skb->data, sc->rxbufsize, PCI_DMA_FROMDEVICE); - if (unlikely(pci_dma_mapping_error(sc->pdev, bf->skbaddr))) { - ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__); - dev_kfree_skb(skb); - bf->skb = NULL; - return -ENOMEM; - } } /* @@ -1664,7 +1674,8 @@ ath5k_tasklet_rx(unsigned long data) { struct ieee80211_rx_status rxs = {}; struct ath5k_rx_status rs = {}; - struct sk_buff *skb; + struct sk_buff *skb, *next_skb; + dma_addr_t next_skb_addr; struct ath5k_softc *sc = (void *)data; struct ath5k_buf *bf, *bf_last; struct ath5k_desc *ds; @@ -1749,10 +1760,17 @@ ath5k_tasklet_rx(unsigned long data) goto next; } accept: + next_skb = ath5k_rx_skb_alloc(sc, &next_skb_addr); + + /* + * If we can't replace bf->skb with a new skb under memory + * pressure, just skip this packet + */ + if (!next_skb) + goto next; + pci_unmap_single(sc->pdev, bf->skbaddr, sc->rxbufsize, PCI_DMA_FROMDEVICE); - bf->skb = NULL; - skb_put(skb, rs.rs_datalen); /* The MAC header is padded to have 32-bit boundary if the @@ -1825,6 +1843,9 @@ accept: ath5k_check_ibss_tsf(sc, skb, &rxs); __ieee80211_rx(sc->hw, skb, &rxs); + + bf->skb = next_skb; + bf->skbaddr = next_skb_addr; next: list_move_tail(&bf->list, &sc->rxbuf); } while (ath5k_rxbuf_setup(sc, bf) == 0); -- cgit From 14990c69b5f51dd57b4e0e2373de50239ac861e2 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Sun, 8 Feb 2009 02:13:56 +0000 Subject: zd1211rw: adding 0ace:0xa211 as a ZD1211 device Christoph Biedl reported success in the sourceforge zd1211 mailing list on this addition. This product ID was supported by the vendor driver ZD1211LnxDrv 2.22.0.0 (and possibly earlier) and it probably should have been added earlier. Signed-off-by: Hin-Tak Leung Tested-by: Christoph Biedl Signed-off-by: John W. Linville --- drivers/net/wireless/zd1211rw/zd_usb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/net/wireless') diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c index 17527f765b3..f0e5e943f6e 100644 --- a/drivers/net/wireless/zd1211rw/zd_usb.c +++ b/drivers/net/wireless/zd1211rw/zd_usb.c @@ -37,6 +37,7 @@ static struct usb_device_id usb_ids[] = { /* ZD1211 */ { USB_DEVICE(0x0ace, 0x1211), .driver_info = DEVICE_ZD1211 }, + { USB_DEVICE(0x0ace, 0xa211), .driver_info = DEVICE_ZD1211 }, { USB_DEVICE(0x07b8, 0x6001), .driver_info = DEVICE_ZD1211 }, { USB_DEVICE(0x126f, 0xa006), .driver_info = DEVICE_ZD1211 }, { USB_DEVICE(0x6891, 0xa727), .driver_info = DEVICE_ZD1211 }, -- cgit From efb43f4b2ccf8066abc3920a0e6858e4350a65c7 Mon Sep 17 00:00:00 2001 From: Hin-Tak Leung Date: Wed, 4 Feb 2009 23:40:43 +0000 Subject: zd1211rw: treat MAXIM_NEW_RF(0x08) as UW2453_RF(0x09) for TP-Link WN322/422G Three people (Petr Mensik ["si" should be U+0161 U+00ED], Stephen Ho on zd1211-devs and Ismael Ojeda Perez on linux-wireless) reported success in getting TP-Link WN322G/WN422G working by treating MAXIM_NEW_RF(0x08) as UW2453_RF(0x09) for rf chip hardware initialization. Signed-off-by: Hin-Tak Leung Tested-by: Petr Mensik Tested-by: Stephen Ho Tested-by: Ismael Ojeda Perez Signed-off-by: John W. Linville --- drivers/net/wireless/zd1211rw/zd_rf.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/net/wireless') diff --git a/drivers/net/wireless/zd1211rw/zd_rf.c b/drivers/net/wireless/zd1211rw/zd_rf.c index 7207bfd2e6c..c875ee05e22 100644 --- a/drivers/net/wireless/zd1211rw/zd_rf.c +++ b/drivers/net/wireless/zd1211rw/zd_rf.c @@ -86,6 +86,7 @@ int zd_rf_init_hw(struct zd_rf *rf, u8 type) case AL7230B_RF: r = zd_rf_init_al7230b(rf); break; + case MAXIM_NEW_RF: case UW2453_RF: r = zd_rf_init_uw2453(rf); break; -- cgit From 89c581b3fb2986e303f1299e6458e3e9b115fa3f Mon Sep 17 00:00:00 2001 From: Reinette Chatre Date: Tue, 10 Feb 2009 12:02:49 -0800 Subject: iwlwifi: fix suspend/resume and its usage of pci saved state Here we do two things: First, revert "iwlwifi: save PCI state before suspend, restore after resume". That misguided patch led to being unable to use iwlwifi devices after resume. Next, indicate to PCI driver that the saved PCI state is valid during suspend. We restore PCI state and enable the device when network interface is created, similarly PCI state is saved and the device is disabled when network interface is removed. Thus, when .suspend is called the PCI state is saved and device is disabled. This is the case even if an interface is never created as PCI state is saved and device disabled during .probe. PCI driver assumes PCI state is saved in .suspend. Saving the state at this time will save state of disabled device and thus cause problems during resume (resuming a disabled device). We thus indicate directly to PCI driver that current PCI saved state is valid. Signed-off-by: Reinette Chatre Tested-by: Alex Riesen Signed-off-by: John W. Linville --- drivers/net/wireless/iwlwifi/iwl-agn.c | 15 +++++++++++++-- drivers/net/wireless/iwlwifi/iwl3945-base.c | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'drivers/net/wireless') diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c index c01ea48da5f..36bafeb353c 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn.c @@ -4042,7 +4042,19 @@ static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state) priv->is_open = 1; } - pci_save_state(pdev); + /* pci driver assumes state will be saved in this function. + * pci state is saved and device disabled when interface is + * stopped, so at this time pci device will always be disabled - + * whether interface was started or not. saving pci state now will + * cause saved state be that of a disabled device, which will cause + * problems during resume in that we will end up with a disabled device. + * + * indicate that the current saved state (from when interface was + * stopped) is valid. if interface was never up at time of suspend + * then the saved state will still be valid as it was saved during + * .probe. */ + pdev->state_saved = true; + pci_set_power_state(pdev, PCI_D3hot); return 0; @@ -4053,7 +4065,6 @@ static int iwl_pci_resume(struct pci_dev *pdev) struct iwl_priv *priv = pci_get_drvdata(pdev); pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); if (priv->is_open) iwl_mac_start(priv->hw); diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c index 5b44d322b99..93be74a1f13 100644 --- a/drivers/net/wireless/iwlwifi/iwl3945-base.c +++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c @@ -8143,7 +8143,19 @@ static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state) priv->is_open = 1; } - pci_save_state(pdev); + /* pci driver assumes state will be saved in this function. + * pci state is saved and device disabled when interface is + * stopped, so at this time pci device will always be disabled - + * whether interface was started or not. saving pci state now will + * cause saved state be that of a disabled device, which will cause + * problems during resume in that we will end up with a disabled device. + * + * indicate that the current saved state (from when interface was + * stopped) is valid. if interface was never up at time of suspend + * then the saved state will still be valid as it was saved during + * .probe. */ + pdev->state_saved = true; + pci_set_power_state(pdev, PCI_D3hot); return 0; @@ -8154,7 +8166,6 @@ static int iwl3945_pci_resume(struct pci_dev *pdev) struct iwl3945_priv *priv = pci_get_drvdata(pdev); pci_set_power_state(pdev, PCI_D0); - pci_restore_state(pdev); if (priv->is_open) iwl3945_mac_start(priv->hw); -- cgit