base.c (b61279809860690fe5c9fcb40441008d31fabab6) base.c (a180a13081708b78d42232c6d922ce3de63f12e0)
1/*-
2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * Copyright (c) 2004-2005 Atheros Communications, Inc.
4 * Copyright (c) 2006 Devicescape Software, Inc.
5 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
6 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
7 *
8 * All rights reserved.

--- 598 unchanged lines hidden (view full) ---

607
608 /* Setup interrupt handler */
609 ret = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
610 if (ret) {
611 ATH5K_ERR(sc, "request_irq failed\n");
612 goto err_free;
613 }
614
1/*-
2 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3 * Copyright (c) 2004-2005 Atheros Communications, Inc.
4 * Copyright (c) 2006 Devicescape Software, Inc.
5 * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
6 * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
7 *
8 * All rights reserved.

--- 598 unchanged lines hidden (view full) ---

607
608 /* Setup interrupt handler */
609 ret = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
610 if (ret) {
611 ATH5K_ERR(sc, "request_irq failed\n");
612 goto err_free;
613 }
614
615 /*If we passed the test malloc a ath5k_hw struct*/
615 /* If we passed the test, malloc an ath5k_hw struct */
616 sc->ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
617 if (!sc->ah) {
618 ret = -ENOMEM;
619 ATH5K_ERR(sc, "out of memory\n");
620 goto err_irq;
621 }
622
623 sc->ah->ah_sc = sc;

--- 157 unchanged lines hidden (view full) ---

781 u8 mac[ETH_ALEN] = {};
782 int ret;
783
784 ATH5K_DBG(sc, ATH5K_DEBUG_ANY, "devid 0x%x\n", pdev->device);
785
786 /*
787 * Check if the MAC has multi-rate retry support.
788 * We do this by trying to setup a fake extended
616 sc->ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
617 if (!sc->ah) {
618 ret = -ENOMEM;
619 ATH5K_ERR(sc, "out of memory\n");
620 goto err_irq;
621 }
622
623 sc->ah->ah_sc = sc;

--- 157 unchanged lines hidden (view full) ---

781 u8 mac[ETH_ALEN] = {};
782 int ret;
783
784 ATH5K_DBG(sc, ATH5K_DEBUG_ANY, "devid 0x%x\n", pdev->device);
785
786 /*
787 * Check if the MAC has multi-rate retry support.
788 * We do this by trying to setup a fake extended
789 * descriptor. MAC's that don't have support will
790 * return false w/o doing anything. MAC's that do
789 * descriptor. MACs that don't have support will
790 * return false w/o doing anything. MACs that do
791 * support it will return true w/o doing anything.
792 */
793 ret = ath5k_hw_setup_mrr_tx_desc(ah, NULL, 0, 0, 0, 0, 0, 0);
794
795 if (ret < 0)
796 goto err;
797 if (ret > 0)
798 __set_bit(ATH_STAT_MRRETRY, sc->status);

--- 23 unchanged lines hidden (view full) ---

822 if (ret) {
823 ATH5K_ERR(sc, "can't allocate descriptors\n");
824 goto err;
825 }
826
827 /*
828 * Allocate hardware transmit queues: one queue for
829 * beacon frames and one data queue for each QoS
791 * support it will return true w/o doing anything.
792 */
793 ret = ath5k_hw_setup_mrr_tx_desc(ah, NULL, 0, 0, 0, 0, 0, 0);
794
795 if (ret < 0)
796 goto err;
797 if (ret > 0)
798 __set_bit(ATH_STAT_MRRETRY, sc->status);

--- 23 unchanged lines hidden (view full) ---

822 if (ret) {
823 ATH5K_ERR(sc, "can't allocate descriptors\n");
824 goto err;
825 }
826
827 /*
828 * Allocate hardware transmit queues: one queue for
829 * beacon frames and one data queue for each QoS
830 * priority. Note that hw functions handle reseting
830 * priority. Note that hw functions handle resetting
831 * these queues at the needed time.
832 */
833 ret = ath5k_beaconq_setup(ah);
834 if (ret < 0) {
835 ATH5K_ERR(sc, "can't setup a beacon xmit queue\n");
836 goto err_desc;
837 }
838 sc->bhalq = ret;

--- 65 unchanged lines hidden (view full) ---

904static void
905ath5k_detach(struct pci_dev *pdev, struct ieee80211_hw *hw)
906{
907 struct ath5k_softc *sc = hw->priv;
908
909 /*
910 * NB: the order of these is important:
911 * o call the 802.11 layer before detaching ath5k_hw to
831 * these queues at the needed time.
832 */
833 ret = ath5k_beaconq_setup(ah);
834 if (ret < 0) {
835 ATH5K_ERR(sc, "can't setup a beacon xmit queue\n");
836 goto err_desc;
837 }
838 sc->bhalq = ret;

--- 65 unchanged lines hidden (view full) ---

904static void
905ath5k_detach(struct pci_dev *pdev, struct ieee80211_hw *hw)
906{
907 struct ath5k_softc *sc = hw->priv;
908
909 /*
910 * NB: the order of these is important:
911 * o call the 802.11 layer before detaching ath5k_hw to
912 * insure callbacks into the driver to delete global
912 * ensure callbacks into the driver to delete global
913 * key cache entries can be handled
914 * o reclaim the tx queue data structures after calling
915 * the 802.11 layer as we'll get called back to reclaim
916 * node state and potentially want to use them
917 * o to cleanup the tx queues the hal is called, so detach
918 * it last
919 * XXX: ??? detach ath5k_hw ???
920 * Other than that, it's straightforward...

--- 588 unchanged lines hidden (view full) ---

1509 .tqi_cw_min = AR5K_TXQ_USEDEFAULT,
1510 .tqi_cw_max = AR5K_TXQ_USEDEFAULT
1511 };
1512 int qnum;
1513
1514 /*
1515 * Enable interrupts only for EOL and DESC conditions.
1516 * We mark tx descriptors to receive a DESC interrupt
913 * key cache entries can be handled
914 * o reclaim the tx queue data structures after calling
915 * the 802.11 layer as we'll get called back to reclaim
916 * node state and potentially want to use them
917 * o to cleanup the tx queues the hal is called, so detach
918 * it last
919 * XXX: ??? detach ath5k_hw ???
920 * Other than that, it's straightforward...

--- 588 unchanged lines hidden (view full) ---

1509 .tqi_cw_min = AR5K_TXQ_USEDEFAULT,
1510 .tqi_cw_max = AR5K_TXQ_USEDEFAULT
1511 };
1512 int qnum;
1513
1514 /*
1515 * Enable interrupts only for EOL and DESC conditions.
1516 * We mark tx descriptors to receive a DESC interrupt
1517 * when a tx queue gets deep; otherwise waiting for the
1517 * when a tx queue gets deep; otherwise we wait for the
1518 * EOL to reap descriptors. Note that this is done to
1519 * reduce interrupt load and this only defers reaping
1520 * descriptors, never transmitting frames. Aside from
1521 * reducing interrupts this also permits more concurrency.
1522 * The only potential downside is if the tx queue backs
1523 * up in which case the top half of the kernel may backup
1524 * due to a lack of tx descriptors.
1525 */

--- 328 unchanged lines hidden (view full) ---

1854 ah->ah_beacon_rssi_avg = ath5k_moving_average(ah->ah_beacon_rssi_avg,
1855 rssi);
1856
1857 /* in IBSS mode we should keep RSSI statistics per neighbour */
1858 /* le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS */
1859}
1860
1861/*
1518 * EOL to reap descriptors. Note that this is done to
1519 * reduce interrupt load and this only defers reaping
1520 * descriptors, never transmitting frames. Aside from
1521 * reducing interrupts this also permits more concurrency.
1522 * The only potential downside is if the tx queue backs
1523 * up in which case the top half of the kernel may backup
1524 * due to a lack of tx descriptors.
1525 */

--- 328 unchanged lines hidden (view full) ---

1854 ah->ah_beacon_rssi_avg = ath5k_moving_average(ah->ah_beacon_rssi_avg,
1855 rssi);
1856
1857 /* in IBSS mode we should keep RSSI statistics per neighbour */
1858 /* le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS */
1859}
1860
1861/*
1862 * Compute padding position. skb must contains an IEEE 802.11 frame
1862 * Compute padding position. skb must contain an IEEE 802.11 frame
1863 */
1864static int ath5k_common_padpos(struct sk_buff *skb)
1865{
1866 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
1867 __le16 frame_control = hdr->frame_control;
1868 int padpos = 24;
1869
1870 if (ieee80211_has_a4(frame_control)) {
1871 padpos += ETH_ALEN;
1872 }
1873 if (ieee80211_is_data_qos(frame_control)) {
1874 padpos += IEEE80211_QOS_CTL_LEN;
1875 }
1876
1877 return padpos;
1878}
1879
1880/*
1863 */
1864static int ath5k_common_padpos(struct sk_buff *skb)
1865{
1866 struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
1867 __le16 frame_control = hdr->frame_control;
1868 int padpos = 24;
1869
1870 if (ieee80211_has_a4(frame_control)) {
1871 padpos += ETH_ALEN;
1872 }
1873 if (ieee80211_is_data_qos(frame_control)) {
1874 padpos += IEEE80211_QOS_CTL_LEN;
1875 }
1876
1877 return padpos;
1878}
1879
1880/*
1881 * This function expects a 802.11 frame and returns the number of
1882 * bytes added, or -1 if we don't have enought header room.
1881 * This function expects an 802.11 frame and returns the number of
1882 * bytes added, or -1 if we don't have enough header room.
1883 */
1883 */
1884
1885static int ath5k_add_padding(struct sk_buff *skb)
1886{
1887 int padpos = ath5k_common_padpos(skb);
1888 int padsize = padpos & 3;
1889
1890 if (padsize && skb->len>padpos) {
1891
1892 if (skb_headroom(skb) < padsize)
1893 return -1;
1894
1895 skb_push(skb, padsize);
1896 memmove(skb->data, skb->data+padsize, padpos);
1897 return padsize;
1898 }
1899
1900 return 0;
1901}
1902
1903/*
1884static int ath5k_add_padding(struct sk_buff *skb)
1885{
1886 int padpos = ath5k_common_padpos(skb);
1887 int padsize = padpos & 3;
1888
1889 if (padsize && skb->len>padpos) {
1890
1891 if (skb_headroom(skb) < padsize)
1892 return -1;
1893
1894 skb_push(skb, padsize);
1895 memmove(skb->data, skb->data+padsize, padpos);
1896 return padsize;
1897 }
1898
1899 return 0;
1900}
1901
1902/*
1904 * This function expects a 802.11 frame and returns the number of
1905 * bytes removed
1903 * The MAC header is padded to have 32-bit boundary if the
1904 * packet payload is non-zero. The general calculation for
1905 * padsize would take into account odd header lengths:
1906 * padsize = 4 - (hdrlen & 3); however, since only
1907 * even-length headers are used, padding can only be 0 or 2
1908 * bytes and we can optimize this a bit. We must not try to
1909 * remove padding from short control frames that do not have a
1910 * payload.
1911 *
1912 * This function expects an 802.11 frame and returns the number of
1913 * bytes removed.
1906 */
1914 */
1907
1908static int ath5k_remove_padding(struct sk_buff *skb)
1909{
1910 int padpos = ath5k_common_padpos(skb);
1911 int padsize = padpos & 3;
1912
1913 if (padsize && skb->len>=padpos+padsize) {
1914 memmove(skb->data + padsize, skb->data, padpos);
1915 skb_pull(skb, padsize);

--- 4 unchanged lines hidden (view full) ---

1920}
1921
1922static void
1923ath5k_receive_frame(struct ath5k_softc *sc, struct sk_buff *skb,
1924 struct ath5k_rx_status *rs)
1925{
1926 struct ieee80211_rx_status *rxs;
1927
1915static int ath5k_remove_padding(struct sk_buff *skb)
1916{
1917 int padpos = ath5k_common_padpos(skb);
1918 int padsize = padpos & 3;
1919
1920 if (padsize && skb->len>=padpos+padsize) {
1921 memmove(skb->data + padsize, skb->data, padpos);
1922 skb_pull(skb, padsize);

--- 4 unchanged lines hidden (view full) ---

1927}
1928
1929static void
1930ath5k_receive_frame(struct ath5k_softc *sc, struct sk_buff *skb,
1931 struct ath5k_rx_status *rs)
1932{
1933 struct ieee80211_rx_status *rxs;
1934
1928 /* The MAC header is padded to have 32-bit boundary if the
1929 * packet payload is non-zero. The general calculation for
1930 * padsize would take into account odd header lengths:
1931 * padsize = (4 - hdrlen % 4) % 4; However, since only
1932 * even-length headers are used, padding can only be 0 or 2
1933 * bytes and we can optimize this a bit. In addition, we must
1934 * not try to remove padding from short control frames that do
1935 * not have payload. */
1936 ath5k_remove_padding(skb);
1937
1938 rxs = IEEE80211_SKB_RXCB(skb);
1939
1940 rxs->flag = 0;
1941 if (unlikely(rs->rs_status & AR5K_RXERR_MIC))
1942 rxs->flag |= RX_FLAG_MMIC_ERROR;
1943

--- 332 unchanged lines hidden (view full) ---

2276 * When a client tries to associate, hw will keep
2277 * track of the tx antenna to be used for this client
2278 * automaticaly, based on ACKed packets.
2279 *
2280 * Note: AP still listens and transmits RTS on the
2281 * default antenna which is supposed to be an omni.
2282 *
2283 * Note2: On sectored scenarios it's possible to have
1935 ath5k_remove_padding(skb);
1936
1937 rxs = IEEE80211_SKB_RXCB(skb);
1938
1939 rxs->flag = 0;
1940 if (unlikely(rs->rs_status & AR5K_RXERR_MIC))
1941 rxs->flag |= RX_FLAG_MMIC_ERROR;
1942

--- 332 unchanged lines hidden (view full) ---

2275 * When a client tries to associate, hw will keep
2276 * track of the tx antenna to be used for this client
2277 * automaticaly, based on ACKed packets.
2278 *
2279 * Note: AP still listens and transmits RTS on the
2280 * default antenna which is supposed to be an omni.
2281 *
2282 * Note2: On sectored scenarios it's possible to have
2284 * multiple antennas (1omni -the default- and 14 sectors)
2285 * so if we choose to actually support this mode we need
2286 * to allow user to set how many antennas we have and tweak
2287 * the code below to send beacons on all of them.
2283 * multiple antennas (1 omni -- the default -- and 14
2284 * sectors), so if we choose to actually support this
2285 * mode, we need to allow the user to set how many antennas
2286 * we have and tweak the code below to send beacons
2287 * on all of them.
2288 */
2289 if (ah->ah_ant_mode == AR5K_ANTMODE_SECTOR_AP)
2290 antenna = sc->bsent & 4 ? 2 : 1;
2291
2292
2293 /* FIXME: If we are in g mode and rate is a CCK rate
2294 * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
2295 * from tx power (value is in dB units already) */

--- 32 unchanged lines hidden (view full) ---

2328
2329 if (unlikely(bf->skb == NULL || sc->opmode == NL80211_IFTYPE_STATION ||
2330 sc->opmode == NL80211_IFTYPE_MONITOR)) {
2331 ATH5K_WARN(sc, "bf=%p bf_skb=%p\n", bf, bf ? bf->skb : NULL);
2332 return;
2333 }
2334 /*
2335 * Check if the previous beacon has gone out. If
2288 */
2289 if (ah->ah_ant_mode == AR5K_ANTMODE_SECTOR_AP)
2290 antenna = sc->bsent & 4 ? 2 : 1;
2291
2292
2293 /* FIXME: If we are in g mode and rate is a CCK rate
2294 * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
2295 * from tx power (value is in dB units already) */

--- 32 unchanged lines hidden (view full) ---

2328
2329 if (unlikely(bf->skb == NULL || sc->opmode == NL80211_IFTYPE_STATION ||
2330 sc->opmode == NL80211_IFTYPE_MONITOR)) {
2331 ATH5K_WARN(sc, "bf=%p bf_skb=%p\n", bf, bf ? bf->skb : NULL);
2332 return;
2333 }
2334 /*
2335 * Check if the previous beacon has gone out. If
2336 * not don't don't try to post another, skip this
2336 * not, don't don't try to post another: skip this
2337 * period and wait for the next. Missed beacons
2338 * indicate a problem and should not occur. If we
2339 * miss too many consecutive beacons reset the device.
2340 */
2341 if (unlikely(ath5k_hw_num_tx_pending(ah, sc->bhalq) != 0)) {
2342 sc->bmisscount++;
2343 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
2344 "missed %u consecutive beacons\n", sc->bmisscount);

--- 555 unchanged lines hidden (view full) ---

2900 int padsize;
2901
2902 ath5k_debug_dump_skb(sc, skb, "TX ", 1);
2903
2904 if (sc->opmode == NL80211_IFTYPE_MONITOR)
2905 ATH5K_DBG(sc, ATH5K_DEBUG_XMIT, "tx in monitor (scan?)\n");
2906
2907 /*
2337 * period and wait for the next. Missed beacons
2338 * indicate a problem and should not occur. If we
2339 * miss too many consecutive beacons reset the device.
2340 */
2341 if (unlikely(ath5k_hw_num_tx_pending(ah, sc->bhalq) != 0)) {
2342 sc->bmisscount++;
2343 ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
2344 "missed %u consecutive beacons\n", sc->bmisscount);

--- 555 unchanged lines hidden (view full) ---

2900 int padsize;
2901
2902 ath5k_debug_dump_skb(sc, skb, "TX ", 1);
2903
2904 if (sc->opmode == NL80211_IFTYPE_MONITOR)
2905 ATH5K_DBG(sc, ATH5K_DEBUG_XMIT, "tx in monitor (scan?)\n");
2906
2907 /*
2908 * the hardware expects the header padded to 4 byte boundaries
2909 * if this is not the case we add the padding after the header
2908 * The hardware expects the header padded to 4 byte boundaries.
2909 * If this is not the case, we add the padding after the header.
2910 */
2911 padsize = ath5k_add_padding(skb);
2912 if (padsize < 0) {
2913 ATH5K_ERR(sc, "tx hdrlen not %%4: not enough"
2914 " headroom to pad");
2915 goto drop_packet;
2916 }
2917

--- 351 unchanged lines hidden (view full) ---

3269 break;
3270 }
3271
3272 /* Set filters */
3273 ath5k_hw_set_rx_filter(ah, rfilt);
3274
3275 /* Set multicast bits */
3276 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
2910 */
2911 padsize = ath5k_add_padding(skb);
2912 if (padsize < 0) {
2913 ATH5K_ERR(sc, "tx hdrlen not %%4: not enough"
2914 " headroom to pad");
2915 goto drop_packet;
2916 }
2917

--- 351 unchanged lines hidden (view full) ---

3269 break;
3270 }
3271
3272 /* Set filters */
3273 ath5k_hw_set_rx_filter(ah, rfilt);
3274
3275 /* Set multicast bits */
3276 ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
3277 /* Set the cached hw filter flags, this will alter actually
3277 /* Set the cached hw filter flags, this will later actually
3278 * be set in HW */
3279 sc->filter_flags = rfilt;
3280
3281 mutex_unlock(&sc->lock);
3282}
3283
3284static int
3285ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,

--- 265 unchanged lines hidden ---
3278 * be set in HW */
3279 sc->filter_flags = rfilt;
3280
3281 mutex_unlock(&sc->lock);
3282}
3283
3284static int
3285ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,

--- 265 unchanged lines hidden ---