aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/rt2x00
diff options
context:
space:
mode:
authorIvo van Doorn <ivdoorn@gmail.com>2008-12-02 12:19:48 -0500
committerJohn W. Linville <linville@tuxdriver.com>2008-12-05 09:35:50 -0500
commit1ce9cdac482f0dfbbd22ba4b3e5c016a05543a42 (patch)
tree90ffda49f6558137efc2760f4badac6de791c49a /drivers/net/wireless/rt2x00
parentaac9207e45b1ec1f36d67e57d94f59ac036d37ee (diff)
rt2x00: Optimize IV/EIV handling
IV and EIV belong to eachother and don't require 2 seperate fields. Instead they can logically be merged into a single array with size 2. With this approach we can simplify the code in rt2x00crypto.c by using a single memcpy() when copying the iv/eiv data. Additionally we can move some code out of if-statements because the if-statement would always be true. Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net/wireless/rt2x00')
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00crypto.c44
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.h12
-rw-r--r--drivers/net/wireless/rt2x00/rt61pci.c8
-rw-r--r--drivers/net/wireless/rt2x00/rt73usb.c8
4 files changed, 26 insertions, 46 deletions
diff --git a/drivers/net/wireless/rt2x00/rt2x00crypto.c b/drivers/net/wireless/rt2x00/rt2x00crypto.c
index 5a858e5106c4..e0fc7c193040 100644
--- a/drivers/net/wireless/rt2x00/rt2x00crypto.c
+++ b/drivers/net/wireless/rt2x00/rt2x00crypto.c
@@ -78,10 +78,7 @@ void rt2x00crypto_tx_remove_iv(struct sk_buff *skb, unsigned int iv_len)
78 return; 78 return;
79 79
80 /* Copy IV/EIV data */ 80 /* Copy IV/EIV data */
81 if (iv_len >= 4) 81 memcpy(skbdesc->iv, skb->data + header_length, iv_len);
82 memcpy(&skbdesc->iv, skb->data + header_length, 4);
83 if (iv_len >= 8)
84 memcpy(&skbdesc->eiv, skb->data + header_length + 4, 4);
85 82
86 /* Move ieee80211 header */ 83 /* Move ieee80211 header */
87 memmove(skb->data + iv_len, skb->data, header_length); 84 memmove(skb->data + iv_len, skb->data, header_length);
@@ -98,7 +95,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
98 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb); 95 struct skb_frame_desc *skbdesc = get_skb_frame_desc(skb);
99 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb); 96 unsigned int header_length = ieee80211_get_hdrlen_from_skb(skb);
100 const unsigned int iv_len = 97 const unsigned int iv_len =
101 ((!!(skbdesc->iv)) * 4) + ((!!(skbdesc->eiv)) * 4); 98 ((!!(skbdesc->iv[0])) * 4) + ((!!(skbdesc->iv[1])) * 4);
102 99
103 if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED)) 100 if (!(skbdesc->flags & FRAME_DESC_IV_STRIPPED))
104 return; 101 return;
@@ -109,10 +106,7 @@ void rt2x00crypto_tx_insert_iv(struct sk_buff *skb)
109 memmove(skb->data, skb->data + iv_len, header_length); 106 memmove(skb->data, skb->data + iv_len, header_length);
110 107
111 /* Copy IV/EIV data */ 108 /* Copy IV/EIV data */
112 if (iv_len >= 4) 109 memcpy(skb->data + header_length, skbdesc->iv, iv_len);
113 memcpy(skb->data + header_length, &skbdesc->iv, 4);
114 if (iv_len >= 8)
115 memcpy(skb->data + header_length + 4, &skbdesc->eiv, 4);
116 110
117 /* IV/EIV data has returned into the frame */ 111 /* IV/EIV data has returned into the frame */
118 skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED; 112 skbdesc->flags &= ~FRAME_DESC_IV_STRIPPED;
@@ -172,17 +166,9 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
172 header_length); 166 header_length);
173 transfer += header_length; 167 transfer += header_length;
174 168
175 /* Copy IV data */ 169 /* Copy IV/EIV data */
176 if (iv_len >= 4) { 170 memcpy(skb->data + transfer, rxdesc->iv, iv_len);
177 memcpy(skb->data + transfer, &rxdesc->iv, 4); 171 transfer += iv_len;
178 transfer += 4;
179 }
180
181 /* Copy EIV data */
182 if (iv_len >= 8) {
183 memcpy(skb->data + transfer, &rxdesc->eiv, 4);
184 transfer += 4;
185 }
186 172
187 /* Move payload */ 173 /* Move payload */
188 if (align) { 174 if (align) {
@@ -198,16 +184,14 @@ void rt2x00crypto_rx_insert_iv(struct sk_buff *skb, unsigned int align,
198 */ 184 */
199 transfer += payload_len; 185 transfer += payload_len;
200 186
201 /* Copy ICV data */ 187 /*
202 if (icv_len >= 4) { 188 * Copy ICV data
203 memcpy(skb->data + transfer, &rxdesc->icv, 4); 189 * AES appends 8 bytes, we can't fill the upper
204 /* 190 * 4 bytes, but mac80211 doesn't care about what
205 * AES appends 8 bytes, we can't fill the upper 191 * we provide here anyway and strips it immediately.
206 * 4 bytes, but mac80211 doesn't care about what 192 */
207 * we provide here anyway and strips it immediately. 193 memcpy(skb->data + transfer, &rxdesc->icv, 4);
208 */ 194 transfer += icv_len;
209 transfer += icv_len;
210 }
211 195
212 /* IV/EIV/ICV has been inserted into frame */ 196 /* IV/EIV/ICV has been inserted into frame */
213 rxdesc->size = transfer; 197 rxdesc->size = transfer;
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.h b/drivers/net/wireless/rt2x00/rt2x00queue.h
index 2e99ab53ec65..7889f914b0ef 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.h
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.h
@@ -109,8 +109,7 @@ enum skb_frame_desc_flags {
109 * @desc: Pointer to descriptor part of the frame. 109 * @desc: Pointer to descriptor part of the frame.
110 * Note that this pointer could point to something outside 110 * Note that this pointer could point to something outside
111 * of the scope of the skb->data pointer. 111 * of the scope of the skb->data pointer.
112 * @iv: IV data used during encryption/decryption. 112 * @iv: IV/EIV data used during encryption/decryption.
113 * @eiv: EIV data used during encryption/decryption.
114 * @skb_dma: (PCI-only) the DMA address associated with the sk buffer. 113 * @skb_dma: (PCI-only) the DMA address associated with the sk buffer.
115 * @entry: The entry to which this sk buffer belongs. 114 * @entry: The entry to which this sk buffer belongs.
116 */ 115 */
@@ -123,8 +122,7 @@ struct skb_frame_desc {
123 122
124 void *desc; 123 void *desc;
125 124
126 __le32 iv; 125 __le32 iv[2];
127 __le32 eiv;
128 126
129 dma_addr_t skb_dma; 127 dma_addr_t skb_dma;
130 128
@@ -168,8 +166,7 @@ enum rxdone_entry_desc_flags {
168 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags). 166 * @dev_flags: Ralink receive flags (See &enum rxdone_entry_desc_flags).
169 * @cipher: Cipher type used during decryption. 167 * @cipher: Cipher type used during decryption.
170 * @cipher_status: Decryption status. 168 * @cipher_status: Decryption status.
171 * @iv: IV data used during decryption. 169 * @iv: IV/EIV data used during decryption.
172 * @eiv: EIV data used during decryption.
173 * @icv: ICV data used during decryption. 170 * @icv: ICV data used during decryption.
174 */ 171 */
175struct rxdone_entry_desc { 172struct rxdone_entry_desc {
@@ -182,8 +179,7 @@ struct rxdone_entry_desc {
182 u8 cipher; 179 u8 cipher;
183 u8 cipher_status; 180 u8 cipher_status;
184 181
185 __le32 iv; 182 __le32 iv[2];
186 __le32 eiv;
187 __le32 icv; 183 __le32 icv;
188}; 184};
189 185
diff --git a/drivers/net/wireless/rt2x00/rt61pci.c b/drivers/net/wireless/rt2x00/rt61pci.c
index d54443c25fe3..c1ebb658b6c4 100644
--- a/drivers/net/wireless/rt2x00/rt61pci.c
+++ b/drivers/net/wireless/rt2x00/rt61pci.c
@@ -1778,8 +1778,8 @@ static void rt61pci_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1778 rt2x00_desc_write(txd, 2, word); 1778 rt2x00_desc_write(txd, 2, word);
1779 1779
1780 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) { 1780 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1781 _rt2x00_desc_write(txd, 3, skbdesc->iv); 1781 _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
1782 _rt2x00_desc_write(txd, 4, skbdesc->eiv); 1782 _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
1783 } 1783 }
1784 1784
1785 rt2x00_desc_read(txd, 5, &word); 1785 rt2x00_desc_read(txd, 5, &word);
@@ -1949,8 +1949,8 @@ static void rt61pci_fill_rxdone(struct queue_entry *entry,
1949 } 1949 }
1950 1950
1951 if (rxdesc->cipher != CIPHER_NONE) { 1951 if (rxdesc->cipher != CIPHER_NONE) {
1952 _rt2x00_desc_read(entry_priv->desc, 2, &rxdesc->iv); 1952 _rt2x00_desc_read(entry_priv->desc, 2, &rxdesc->iv[0]);
1953 _rt2x00_desc_read(entry_priv->desc, 3, &rxdesc->eiv); 1953 _rt2x00_desc_read(entry_priv->desc, 3, &rxdesc->iv[1]);
1954 _rt2x00_desc_read(entry_priv->desc, 4, &rxdesc->icv); 1954 _rt2x00_desc_read(entry_priv->desc, 4, &rxdesc->icv);
1955 1955
1956 /* 1956 /*
diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
index 37a782dc8080..3c8b235bbdfb 100644
--- a/drivers/net/wireless/rt2x00/rt73usb.c
+++ b/drivers/net/wireless/rt2x00/rt73usb.c
@@ -1428,8 +1428,8 @@ static void rt73usb_write_tx_desc(struct rt2x00_dev *rt2x00dev,
1428 rt2x00_desc_write(txd, 2, word); 1428 rt2x00_desc_write(txd, 2, word);
1429 1429
1430 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) { 1430 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc->flags)) {
1431 _rt2x00_desc_write(txd, 3, skbdesc->iv); 1431 _rt2x00_desc_write(txd, 3, skbdesc->iv[0]);
1432 _rt2x00_desc_write(txd, 4, skbdesc->eiv); 1432 _rt2x00_desc_write(txd, 4, skbdesc->iv[1]);
1433 } 1433 }
1434 1434
1435 rt2x00_desc_read(txd, 5, &word); 1435 rt2x00_desc_read(txd, 5, &word);
@@ -1618,8 +1618,8 @@ static void rt73usb_fill_rxdone(struct queue_entry *entry,
1618 } 1618 }
1619 1619
1620 if (rxdesc->cipher != CIPHER_NONE) { 1620 if (rxdesc->cipher != CIPHER_NONE) {
1621 _rt2x00_desc_read(rxd, 2, &rxdesc->iv); 1621 _rt2x00_desc_read(rxd, 2, &rxdesc->iv[0]);
1622 _rt2x00_desc_read(rxd, 3, &rxdesc->eiv); 1622 _rt2x00_desc_read(rxd, 3, &rxdesc->iv[1]);
1623 _rt2x00_desc_read(rxd, 4, &rxdesc->icv); 1623 _rt2x00_desc_read(rxd, 4, &rxdesc->icv);
1624 1624
1625 /* 1625 /*