Loading...
1/*
2 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 */
18
19#include <linux/module.h>
20#include <linux/gfp.h>
21
22#include <linux/pci.h>
23#include <linux/delay.h>
24#include <linux/netdevice.h>
25#include <linux/etherdevice.h>
26#include <linux/if_arp.h>
27#include <asm/byteorder.h>
28
29#include "prismcompat.h"
30#include "isl_38xx.h"
31#include "islpci_eth.h"
32#include "islpci_mgt.h"
33#include "oid_mgt.h"
34
35/******************************************************************************
36 Network Interface functions
37******************************************************************************/
38void
39islpci_eth_cleanup_transmit(islpci_private *priv,
40 isl38xx_control_block *control_block)
41{
42 struct sk_buff *skb;
43 u32 index;
44
45 /* compare the control block read pointer with the free pointer */
46 while (priv->free_data_tx !=
47 le32_to_cpu(control_block->
48 device_curr_frag[ISL38XX_CB_TX_DATA_LQ])) {
49 /* read the index of the first fragment to be freed */
50 index = priv->free_data_tx % ISL38XX_CB_TX_QSIZE;
51
52 /* check for holes in the arrays caused by multi fragment frames
53 * searching for the last fragment of a frame */
54 if (priv->pci_map_tx_address[index]) {
55 /* entry is the last fragment of a frame
56 * free the skb structure and unmap pci memory */
57 skb = priv->data_low_tx[index];
58
59#if VERBOSE > SHOW_ERROR_MESSAGES
60 DEBUG(SHOW_TRACING,
61 "cleanup skb %p skb->data %p skb->len %u truesize %u\n ",
62 skb, skb->data, skb->len, skb->truesize);
63#endif
64
65 pci_unmap_single(priv->pdev,
66 priv->pci_map_tx_address[index],
67 skb->len, PCI_DMA_TODEVICE);
68 dev_kfree_skb_irq(skb);
69 skb = NULL;
70 }
71 /* increment the free data low queue pointer */
72 priv->free_data_tx++;
73 }
74}
75
76netdev_tx_t
77islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
78{
79 islpci_private *priv = netdev_priv(ndev);
80 isl38xx_control_block *cb = priv->control_block;
81 u32 index;
82 dma_addr_t pci_map_address;
83 int frame_size;
84 isl38xx_fragment *fragment;
85 int offset;
86 struct sk_buff *newskb;
87 int newskb_offset;
88 unsigned long flags;
89 unsigned char wds_mac[6];
90 u32 curr_frag;
91
92#if VERBOSE > SHOW_ERROR_MESSAGES
93 DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_transmit\n");
94#endif
95
96 /* lock the driver code */
97 spin_lock_irqsave(&priv->slock, flags);
98
99 /* check whether the destination queue has enough fragments for the frame */
100 curr_frag = le32_to_cpu(cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ]);
101 if (unlikely(curr_frag - priv->free_data_tx >= ISL38XX_CB_TX_QSIZE)) {
102 printk(KERN_ERR "%s: transmit device queue full when awake\n",
103 ndev->name);
104 netif_stop_queue(ndev);
105
106 /* trigger the device */
107 isl38xx_w32_flush(priv->device_base, ISL38XX_DEV_INT_UPDATE,
108 ISL38XX_DEV_INT_REG);
109 udelay(ISL38XX_WRITEIO_DELAY);
110 goto drop_free;
111 }
112 /* Check alignment and WDS frame formatting. The start of the packet should
113 * be aligned on a 4-byte boundary. If WDS is enabled add another 6 bytes
114 * and add WDS address information */
115 if (likely(((long) skb->data & 0x03) | init_wds)) {
116 /* get the number of bytes to add and re-align */
117 offset = (4 - (long) skb->data) & 0x03;
118 offset += init_wds ? 6 : 0;
119
120 /* check whether the current skb can be used */
121 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
122 unsigned char *src = skb->data;
123
124#if VERBOSE > SHOW_ERROR_MESSAGES
125 DEBUG(SHOW_TRACING, "skb offset %i wds %i\n", offset,
126 init_wds);
127#endif
128
129 /* align the buffer on 4-byte boundary */
130 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
131 if (init_wds) {
132 /* wds requires an additional address field of 6 bytes */
133 skb_put(skb, 6);
134#ifdef ISLPCI_ETH_DEBUG
135 printk("islpci_eth_transmit:wds_mac\n");
136#endif
137 memmove(skb->data + 6, src, skb->len);
138 skb_copy_to_linear_data(skb, wds_mac, 6);
139 } else {
140 memmove(skb->data, src, skb->len);
141 }
142
143#if VERBOSE > SHOW_ERROR_MESSAGES
144 DEBUG(SHOW_TRACING, "memmove %p %p %i\n", skb->data,
145 src, skb->len);
146#endif
147 } else {
148 newskb =
149 dev_alloc_skb(init_wds ? skb->len + 6 : skb->len);
150 if (unlikely(newskb == NULL)) {
151 printk(KERN_ERR "%s: Cannot allocate skb\n",
152 ndev->name);
153 goto drop_free;
154 }
155 newskb_offset = (4 - (long) newskb->data) & 0x03;
156
157 /* Check if newskb->data is aligned */
158 if (newskb_offset)
159 skb_reserve(newskb, newskb_offset);
160
161 skb_put(newskb, init_wds ? skb->len + 6 : skb->len);
162 if (init_wds) {
163 skb_copy_from_linear_data(skb,
164 newskb->data + 6,
165 skb->len);
166 skb_copy_to_linear_data(newskb, wds_mac, 6);
167#ifdef ISLPCI_ETH_DEBUG
168 printk("islpci_eth_transmit:wds_mac\n");
169#endif
170 } else
171 skb_copy_from_linear_data(skb, newskb->data,
172 skb->len);
173
174#if VERBOSE > SHOW_ERROR_MESSAGES
175 DEBUG(SHOW_TRACING, "memcpy %p %p %i wds %i\n",
176 newskb->data, skb->data, skb->len, init_wds);
177#endif
178
179 newskb->dev = skb->dev;
180 dev_kfree_skb_irq(skb);
181 skb = newskb;
182 }
183 }
184 /* display the buffer contents for debugging */
185#if VERBOSE > SHOW_ERROR_MESSAGES
186 DEBUG(SHOW_BUFFER_CONTENTS, "\ntx %p ", skb->data);
187 display_buffer((char *) skb->data, skb->len);
188#endif
189
190 /* map the skb buffer to pci memory for DMA operation */
191 pci_map_address = pci_map_single(priv->pdev,
192 (void *) skb->data, skb->len,
193 PCI_DMA_TODEVICE);
194 if (unlikely(pci_map_address == 0)) {
195 printk(KERN_WARNING "%s: cannot map buffer to PCI\n",
196 ndev->name);
197 goto drop_free;
198 }
199 /* Place the fragment in the control block structure. */
200 index = curr_frag % ISL38XX_CB_TX_QSIZE;
201 fragment = &cb->tx_data_low[index];
202
203 priv->pci_map_tx_address[index] = pci_map_address;
204 /* store the skb address for future freeing */
205 priv->data_low_tx[index] = skb;
206 /* set the proper fragment start address and size information */
207 frame_size = skb->len;
208 fragment->size = cpu_to_le16(frame_size);
209 fragment->flags = cpu_to_le16(0); /* set to 1 if more fragments */
210 fragment->address = cpu_to_le32(pci_map_address);
211 curr_frag++;
212
213 /* The fragment address in the control block must have been
214 * written before announcing the frame buffer to device. */
215 wmb();
216 cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ] = cpu_to_le32(curr_frag);
217
218 if (curr_frag - priv->free_data_tx + ISL38XX_MIN_QTHRESHOLD
219 > ISL38XX_CB_TX_QSIZE) {
220 /* stop sends from upper layers */
221 netif_stop_queue(ndev);
222
223 /* set the full flag for the transmission queue */
224 priv->data_low_tx_full = 1;
225 }
226
227 ndev->stats.tx_packets++;
228 ndev->stats.tx_bytes += skb->len;
229
230 /* trigger the device */
231 islpci_trigger(priv);
232
233 /* unlock the driver code */
234 spin_unlock_irqrestore(&priv->slock, flags);
235
236 return NETDEV_TX_OK;
237
238 drop_free:
239 ndev->stats.tx_dropped++;
240 spin_unlock_irqrestore(&priv->slock, flags);
241 dev_kfree_skb(skb);
242 return NETDEV_TX_OK;
243}
244
245static inline int
246islpci_monitor_rx(islpci_private *priv, struct sk_buff **skb)
247{
248 /* The card reports full 802.11 packets but with a 20 bytes
249 * header and without the FCS. But there a is a bit that
250 * indicates if the packet is corrupted :-) */
251 struct rfmon_header *hdr = (struct rfmon_header *) (*skb)->data;
252
253 if (hdr->flags & 0x01)
254 /* This one is bad. Drop it ! */
255 return -1;
256 if (priv->ndev->type == ARPHRD_IEEE80211_PRISM) {
257 struct avs_80211_1_header *avs;
258 /* extract the relevant data from the header */
259 u32 clock = le32_to_cpu(hdr->clock);
260 u8 rate = hdr->rate;
261 u16 freq = le16_to_cpu(hdr->freq);
262 u8 rssi = hdr->rssi;
263
264 skb_pull(*skb, sizeof (struct rfmon_header));
265
266 if (skb_headroom(*skb) < sizeof (struct avs_80211_1_header)) {
267 struct sk_buff *newskb = skb_copy_expand(*skb,
268 sizeof (struct
269 avs_80211_1_header),
270 0, GFP_ATOMIC);
271 if (newskb) {
272 dev_kfree_skb_irq(*skb);
273 *skb = newskb;
274 } else
275 return -1;
276 /* This behavior is not very subtile... */
277 }
278
279 /* make room for the new header and fill it. */
280 avs =
281 (struct avs_80211_1_header *) skb_push(*skb,
282 sizeof (struct
283 avs_80211_1_header));
284
285 avs->version = cpu_to_be32(P80211CAPTURE_VERSION);
286 avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header));
287 avs->mactime = cpu_to_be64(clock);
288 avs->hosttime = cpu_to_be64(jiffies);
289 avs->phytype = cpu_to_be32(6); /*OFDM: 6 for (g), 8 for (a) */
290 avs->channel = cpu_to_be32(channel_of_freq(freq));
291 avs->datarate = cpu_to_be32(rate * 5);
292 avs->antenna = cpu_to_be32(0); /*unknown */
293 avs->priority = cpu_to_be32(0); /*unknown */
294 avs->ssi_type = cpu_to_be32(3); /*2: dBm, 3: raw RSSI */
295 avs->ssi_signal = cpu_to_be32(rssi & 0x7f);
296 avs->ssi_noise = cpu_to_be32(priv->local_iwstatistics.qual.noise); /*better than 'undefined', I assume */
297 avs->preamble = cpu_to_be32(0); /*unknown */
298 avs->encoding = cpu_to_be32(0); /*unknown */
299 } else
300 skb_pull(*skb, sizeof (struct rfmon_header));
301
302 (*skb)->protocol = htons(ETH_P_802_2);
303 skb_reset_mac_header(*skb);
304 (*skb)->pkt_type = PACKET_OTHERHOST;
305
306 return 0;
307}
308
309int
310islpci_eth_receive(islpci_private *priv)
311{
312 struct net_device *ndev = priv->ndev;
313 isl38xx_control_block *control_block = priv->control_block;
314 struct sk_buff *skb;
315 u16 size;
316 u32 index, offset;
317 unsigned char *src;
318 int discard = 0;
319
320#if VERBOSE > SHOW_ERROR_MESSAGES
321 DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_receive\n");
322#endif
323
324 /* the device has written an Ethernet frame in the data area
325 * of the sk_buff without updating the structure, do it now */
326 index = priv->free_data_rx % ISL38XX_CB_RX_QSIZE;
327 size = le16_to_cpu(control_block->rx_data_low[index].size);
328 skb = priv->data_low_rx[index];
329 offset = ((unsigned long)
330 le32_to_cpu(control_block->rx_data_low[index].address) -
331 (unsigned long) skb->data) & 3;
332
333#if VERBOSE > SHOW_ERROR_MESSAGES
334 DEBUG(SHOW_TRACING,
335 "frq->addr %x skb->data %p skb->len %u offset %u truesize %u\n ",
336 control_block->rx_data_low[priv->free_data_rx].address, skb->data,
337 skb->len, offset, skb->truesize);
338#endif
339
340 /* delete the streaming DMA mapping before processing the skb */
341 pci_unmap_single(priv->pdev,
342 priv->pci_map_rx_address[index],
343 MAX_FRAGMENT_SIZE_RX + 2, PCI_DMA_FROMDEVICE);
344
345 /* update the skb structure and align the buffer */
346 skb_put(skb, size);
347 if (offset) {
348 /* shift the buffer allocation offset bytes to get the right frame */
349 skb_pull(skb, 2);
350 skb_put(skb, 2);
351 }
352#if VERBOSE > SHOW_ERROR_MESSAGES
353 /* display the buffer contents for debugging */
354 DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
355 display_buffer((char *) skb->data, skb->len);
356#endif
357
358 /* check whether WDS is enabled and whether the data frame is a WDS frame */
359
360 if (init_wds) {
361 /* WDS enabled, check for the wds address on the first 6 bytes of the buffer */
362 src = skb->data + 6;
363 memmove(skb->data, src, skb->len - 6);
364 skb_trim(skb, skb->len - 6);
365 }
366#if VERBOSE > SHOW_ERROR_MESSAGES
367 DEBUG(SHOW_TRACING, "Fragment size %i in skb at %p\n", size, skb);
368 DEBUG(SHOW_TRACING, "Skb data at %p, length %i\n", skb->data, skb->len);
369
370 /* display the buffer contents for debugging */
371 DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
372 display_buffer((char *) skb->data, skb->len);
373#endif
374 /* take care of monitor mode and spy monitoring. */
375 if (unlikely(priv->iw_mode == IW_MODE_MONITOR)) {
376 skb->dev = ndev;
377 discard = islpci_monitor_rx(priv, &skb);
378 } else {
379 if (unlikely(skb->data[2 * ETH_ALEN] == 0)) {
380 /* The packet has a rx_annex. Read it for spy monitoring, Then
381 * remove it, while keeping the 2 leading MAC addr.
382 */
383 struct iw_quality wstats;
384 struct rx_annex_header *annex =
385 (struct rx_annex_header *) skb->data;
386 wstats.level = annex->rfmon.rssi;
387 /* The noise value can be a bit outdated if nobody's
388 * reading wireless stats... */
389 wstats.noise = priv->local_iwstatistics.qual.noise;
390 wstats.qual = wstats.level - wstats.noise;
391 wstats.updated = 0x07;
392 /* Update spy records */
393 wireless_spy_update(ndev, annex->addr2, &wstats);
394
395 skb_copy_from_linear_data(skb,
396 (skb->data +
397 sizeof(struct rfmon_header)),
398 2 * ETH_ALEN);
399 skb_pull(skb, sizeof (struct rfmon_header));
400 }
401 skb->protocol = eth_type_trans(skb, ndev);
402 }
403 skb->ip_summed = CHECKSUM_NONE;
404 ndev->stats.rx_packets++;
405 ndev->stats.rx_bytes += size;
406
407 /* deliver the skb to the network layer */
408#ifdef ISLPCI_ETH_DEBUG
409 printk
410 ("islpci_eth_receive:netif_rx %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
411 skb->data[0], skb->data[1], skb->data[2], skb->data[3],
412 skb->data[4], skb->data[5]);
413#endif
414 if (unlikely(discard)) {
415 dev_kfree_skb_irq(skb);
416 skb = NULL;
417 } else
418 netif_rx(skb);
419
420 /* increment the read index for the rx data low queue */
421 priv->free_data_rx++;
422
423 /* add one or more sk_buff structures */
424 while (index =
425 le32_to_cpu(control_block->
426 driver_curr_frag[ISL38XX_CB_RX_DATA_LQ]),
427 index - priv->free_data_rx < ISL38XX_CB_RX_QSIZE) {
428 /* allocate an sk_buff for received data frames storage
429 * include any required allignment operations */
430 skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2);
431 if (unlikely(skb == NULL)) {
432 /* error allocating an sk_buff structure elements */
433 DEBUG(SHOW_ERROR_MESSAGES, "Error allocating skb\n");
434 break;
435 }
436 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
437 /* store the new skb structure pointer */
438 index = index % ISL38XX_CB_RX_QSIZE;
439 priv->data_low_rx[index] = skb;
440
441#if VERBOSE > SHOW_ERROR_MESSAGES
442 DEBUG(SHOW_TRACING,
443 "new alloc skb %p skb->data %p skb->len %u index %u truesize %u\n ",
444 skb, skb->data, skb->len, index, skb->truesize);
445#endif
446
447 /* set the streaming DMA mapping for proper PCI bus operation */
448 priv->pci_map_rx_address[index] =
449 pci_map_single(priv->pdev, (void *) skb->data,
450 MAX_FRAGMENT_SIZE_RX + 2,
451 PCI_DMA_FROMDEVICE);
452 if (unlikely(!priv->pci_map_rx_address[index])) {
453 /* error mapping the buffer to device accessible memory address */
454 DEBUG(SHOW_ERROR_MESSAGES,
455 "Error mapping DMA address\n");
456
457 /* free the skbuf structure before aborting */
458 dev_kfree_skb_irq((struct sk_buff *) skb);
459 skb = NULL;
460 break;
461 }
462 /* update the fragment address */
463 control_block->rx_data_low[index].address =
464 cpu_to_le32((u32)priv->pci_map_rx_address[index]);
465 wmb();
466
467 /* increment the driver read pointer */
468 le32_add_cpu(&control_block->
469 driver_curr_frag[ISL38XX_CB_RX_DATA_LQ], 1);
470 }
471
472 /* trigger the device */
473 islpci_trigger(priv);
474
475 return 0;
476}
477
478void
479islpci_do_reset_and_wake(struct work_struct *work)
480{
481 islpci_private *priv = container_of(work, islpci_private, reset_task);
482
483 islpci_reset(priv, 1);
484 priv->reset_task_pending = 0;
485 smp_wmb();
486 netif_wake_queue(priv->ndev);
487}
488
489void
490islpci_eth_tx_timeout(struct net_device *ndev)
491{
492 islpci_private *priv = netdev_priv(ndev);
493
494 /* increment the transmit error counter */
495 ndev->stats.tx_errors++;
496
497 if (!priv->reset_task_pending) {
498 printk(KERN_WARNING
499 "%s: tx_timeout, scheduling reset", ndev->name);
500 netif_stop_queue(ndev);
501 priv->reset_task_pending = 1;
502 schedule_work(&priv->reset_task);
503 } else {
504 printk(KERN_WARNING
505 "%s: tx_timeout, waiting for reset", ndev->name);
506 }
507}
1/*
2 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/gfp.h>
20
21#include <linux/pci.h>
22#include <linux/delay.h>
23#include <linux/netdevice.h>
24#include <linux/etherdevice.h>
25#include <linux/if_arp.h>
26#include <asm/byteorder.h>
27
28#include "prismcompat.h"
29#include "isl_38xx.h"
30#include "islpci_eth.h"
31#include "islpci_mgt.h"
32#include "oid_mgt.h"
33
34/******************************************************************************
35 Network Interface functions
36******************************************************************************/
37void
38islpci_eth_cleanup_transmit(islpci_private *priv,
39 isl38xx_control_block *control_block)
40{
41 struct sk_buff *skb;
42 u32 index;
43
44 /* compare the control block read pointer with the free pointer */
45 while (priv->free_data_tx !=
46 le32_to_cpu(control_block->
47 device_curr_frag[ISL38XX_CB_TX_DATA_LQ])) {
48 /* read the index of the first fragment to be freed */
49 index = priv->free_data_tx % ISL38XX_CB_TX_QSIZE;
50
51 /* check for holes in the arrays caused by multi fragment frames
52 * searching for the last fragment of a frame */
53 if (priv->pci_map_tx_address[index]) {
54 /* entry is the last fragment of a frame
55 * free the skb structure and unmap pci memory */
56 skb = priv->data_low_tx[index];
57
58#if VERBOSE > SHOW_ERROR_MESSAGES
59 DEBUG(SHOW_TRACING,
60 "cleanup skb %p skb->data %p skb->len %u truesize %u\n ",
61 skb, skb->data, skb->len, skb->truesize);
62#endif
63
64 pci_unmap_single(priv->pdev,
65 priv->pci_map_tx_address[index],
66 skb->len, PCI_DMA_TODEVICE);
67 dev_kfree_skb_irq(skb);
68 skb = NULL;
69 }
70 /* increment the free data low queue pointer */
71 priv->free_data_tx++;
72 }
73}
74
75netdev_tx_t
76islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
77{
78 islpci_private *priv = netdev_priv(ndev);
79 isl38xx_control_block *cb = priv->control_block;
80 u32 index;
81 dma_addr_t pci_map_address;
82 int frame_size;
83 isl38xx_fragment *fragment;
84 int offset;
85 struct sk_buff *newskb;
86 int newskb_offset;
87 unsigned long flags;
88 unsigned char wds_mac[6];
89 u32 curr_frag;
90
91#if VERBOSE > SHOW_ERROR_MESSAGES
92 DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_transmit\n");
93#endif
94
95 /* lock the driver code */
96 spin_lock_irqsave(&priv->slock, flags);
97
98 /* check whether the destination queue has enough fragments for the frame */
99 curr_frag = le32_to_cpu(cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ]);
100 if (unlikely(curr_frag - priv->free_data_tx >= ISL38XX_CB_TX_QSIZE)) {
101 printk(KERN_ERR "%s: transmit device queue full when awake\n",
102 ndev->name);
103 netif_stop_queue(ndev);
104
105 /* trigger the device */
106 isl38xx_w32_flush(priv->device_base, ISL38XX_DEV_INT_UPDATE,
107 ISL38XX_DEV_INT_REG);
108 udelay(ISL38XX_WRITEIO_DELAY);
109 goto drop_free;
110 }
111 /* Check alignment and WDS frame formatting. The start of the packet should
112 * be aligned on a 4-byte boundary. If WDS is enabled add another 6 bytes
113 * and add WDS address information */
114 if (likely(((long) skb->data & 0x03) | init_wds)) {
115 /* get the number of bytes to add and re-align */
116 offset = (4 - (long) skb->data) & 0x03;
117 offset += init_wds ? 6 : 0;
118
119 /* check whether the current skb can be used */
120 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
121 unsigned char *src = skb->data;
122
123#if VERBOSE > SHOW_ERROR_MESSAGES
124 DEBUG(SHOW_TRACING, "skb offset %i wds %i\n", offset,
125 init_wds);
126#endif
127
128 /* align the buffer on 4-byte boundary */
129 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
130 if (init_wds) {
131 /* wds requires an additional address field of 6 bytes */
132 skb_put(skb, 6);
133#ifdef ISLPCI_ETH_DEBUG
134 printk("islpci_eth_transmit:wds_mac\n");
135#endif
136 memmove(skb->data + 6, src, skb->len);
137 skb_copy_to_linear_data(skb, wds_mac, 6);
138 } else {
139 memmove(skb->data, src, skb->len);
140 }
141
142#if VERBOSE > SHOW_ERROR_MESSAGES
143 DEBUG(SHOW_TRACING, "memmove %p %p %i\n", skb->data,
144 src, skb->len);
145#endif
146 } else {
147 newskb =
148 dev_alloc_skb(init_wds ? skb->len + 6 : skb->len);
149 if (unlikely(newskb == NULL)) {
150 printk(KERN_ERR "%s: Cannot allocate skb\n",
151 ndev->name);
152 goto drop_free;
153 }
154 newskb_offset = (4 - (long) newskb->data) & 0x03;
155
156 /* Check if newskb->data is aligned */
157 if (newskb_offset)
158 skb_reserve(newskb, newskb_offset);
159
160 skb_put(newskb, init_wds ? skb->len + 6 : skb->len);
161 if (init_wds) {
162 skb_copy_from_linear_data(skb,
163 newskb->data + 6,
164 skb->len);
165 skb_copy_to_linear_data(newskb, wds_mac, 6);
166#ifdef ISLPCI_ETH_DEBUG
167 printk("islpci_eth_transmit:wds_mac\n");
168#endif
169 } else
170 skb_copy_from_linear_data(skb, newskb->data,
171 skb->len);
172
173#if VERBOSE > SHOW_ERROR_MESSAGES
174 DEBUG(SHOW_TRACING, "memcpy %p %p %i wds %i\n",
175 newskb->data, skb->data, skb->len, init_wds);
176#endif
177
178 newskb->dev = skb->dev;
179 dev_kfree_skb_irq(skb);
180 skb = newskb;
181 }
182 }
183 /* display the buffer contents for debugging */
184#if VERBOSE > SHOW_ERROR_MESSAGES
185 DEBUG(SHOW_BUFFER_CONTENTS, "\ntx %p ", skb->data);
186 display_buffer((char *) skb->data, skb->len);
187#endif
188
189 /* map the skb buffer to pci memory for DMA operation */
190 pci_map_address = pci_map_single(priv->pdev,
191 (void *) skb->data, skb->len,
192 PCI_DMA_TODEVICE);
193 if (unlikely(pci_map_address == 0)) {
194 printk(KERN_WARNING "%s: cannot map buffer to PCI\n",
195 ndev->name);
196 goto drop_free;
197 }
198 /* Place the fragment in the control block structure. */
199 index = curr_frag % ISL38XX_CB_TX_QSIZE;
200 fragment = &cb->tx_data_low[index];
201
202 priv->pci_map_tx_address[index] = pci_map_address;
203 /* store the skb address for future freeing */
204 priv->data_low_tx[index] = skb;
205 /* set the proper fragment start address and size information */
206 frame_size = skb->len;
207 fragment->size = cpu_to_le16(frame_size);
208 fragment->flags = cpu_to_le16(0); /* set to 1 if more fragments */
209 fragment->address = cpu_to_le32(pci_map_address);
210 curr_frag++;
211
212 /* The fragment address in the control block must have been
213 * written before announcing the frame buffer to device. */
214 wmb();
215 cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ] = cpu_to_le32(curr_frag);
216
217 if (curr_frag - priv->free_data_tx + ISL38XX_MIN_QTHRESHOLD
218 > ISL38XX_CB_TX_QSIZE) {
219 /* stop sends from upper layers */
220 netif_stop_queue(ndev);
221
222 /* set the full flag for the transmission queue */
223 priv->data_low_tx_full = 1;
224 }
225
226 ndev->stats.tx_packets++;
227 ndev->stats.tx_bytes += skb->len;
228
229 /* trigger the device */
230 islpci_trigger(priv);
231
232 /* unlock the driver code */
233 spin_unlock_irqrestore(&priv->slock, flags);
234
235 return NETDEV_TX_OK;
236
237 drop_free:
238 ndev->stats.tx_dropped++;
239 spin_unlock_irqrestore(&priv->slock, flags);
240 dev_kfree_skb(skb);
241 return NETDEV_TX_OK;
242}
243
244static inline int
245islpci_monitor_rx(islpci_private *priv, struct sk_buff **skb)
246{
247 /* The card reports full 802.11 packets but with a 20 bytes
248 * header and without the FCS. But there a is a bit that
249 * indicates if the packet is corrupted :-) */
250 struct rfmon_header *hdr = (struct rfmon_header *) (*skb)->data;
251
252 if (hdr->flags & 0x01)
253 /* This one is bad. Drop it ! */
254 return -1;
255 if (priv->ndev->type == ARPHRD_IEEE80211_PRISM) {
256 struct avs_80211_1_header *avs;
257 /* extract the relevant data from the header */
258 u32 clock = le32_to_cpu(hdr->clock);
259 u8 rate = hdr->rate;
260 u16 freq = le16_to_cpu(hdr->freq);
261 u8 rssi = hdr->rssi;
262
263 skb_pull(*skb, sizeof (struct rfmon_header));
264
265 if (skb_headroom(*skb) < sizeof (struct avs_80211_1_header)) {
266 struct sk_buff *newskb = skb_copy_expand(*skb,
267 sizeof (struct
268 avs_80211_1_header),
269 0, GFP_ATOMIC);
270 if (newskb) {
271 dev_kfree_skb_irq(*skb);
272 *skb = newskb;
273 } else
274 return -1;
275 /* This behavior is not very subtile... */
276 }
277
278 /* make room for the new header and fill it. */
279 avs =
280 (struct avs_80211_1_header *) skb_push(*skb,
281 sizeof (struct
282 avs_80211_1_header));
283
284 avs->version = cpu_to_be32(P80211CAPTURE_VERSION);
285 avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header));
286 avs->mactime = cpu_to_be64(clock);
287 avs->hosttime = cpu_to_be64(jiffies);
288 avs->phytype = cpu_to_be32(6); /*OFDM: 6 for (g), 8 for (a) */
289 avs->channel = cpu_to_be32(channel_of_freq(freq));
290 avs->datarate = cpu_to_be32(rate * 5);
291 avs->antenna = cpu_to_be32(0); /*unknown */
292 avs->priority = cpu_to_be32(0); /*unknown */
293 avs->ssi_type = cpu_to_be32(3); /*2: dBm, 3: raw RSSI */
294 avs->ssi_signal = cpu_to_be32(rssi & 0x7f);
295 avs->ssi_noise = cpu_to_be32(priv->local_iwstatistics.qual.noise); /*better than 'undefined', I assume */
296 avs->preamble = cpu_to_be32(0); /*unknown */
297 avs->encoding = cpu_to_be32(0); /*unknown */
298 } else
299 skb_pull(*skb, sizeof (struct rfmon_header));
300
301 (*skb)->protocol = htons(ETH_P_802_2);
302 skb_reset_mac_header(*skb);
303 (*skb)->pkt_type = PACKET_OTHERHOST;
304
305 return 0;
306}
307
308int
309islpci_eth_receive(islpci_private *priv)
310{
311 struct net_device *ndev = priv->ndev;
312 isl38xx_control_block *control_block = priv->control_block;
313 struct sk_buff *skb;
314 u16 size;
315 u32 index, offset;
316 unsigned char *src;
317 int discard = 0;
318
319#if VERBOSE > SHOW_ERROR_MESSAGES
320 DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_receive\n");
321#endif
322
323 /* the device has written an Ethernet frame in the data area
324 * of the sk_buff without updating the structure, do it now */
325 index = priv->free_data_rx % ISL38XX_CB_RX_QSIZE;
326 size = le16_to_cpu(control_block->rx_data_low[index].size);
327 skb = priv->data_low_rx[index];
328 offset = ((unsigned long)
329 le32_to_cpu(control_block->rx_data_low[index].address) -
330 (unsigned long) skb->data) & 3;
331
332#if VERBOSE > SHOW_ERROR_MESSAGES
333 DEBUG(SHOW_TRACING,
334 "frq->addr %x skb->data %p skb->len %u offset %u truesize %u\n ",
335 control_block->rx_data_low[priv->free_data_rx].address, skb->data,
336 skb->len, offset, skb->truesize);
337#endif
338
339 /* delete the streaming DMA mapping before processing the skb */
340 pci_unmap_single(priv->pdev,
341 priv->pci_map_rx_address[index],
342 MAX_FRAGMENT_SIZE_RX + 2, PCI_DMA_FROMDEVICE);
343
344 /* update the skb structure and align the buffer */
345 skb_put(skb, size);
346 if (offset) {
347 /* shift the buffer allocation offset bytes to get the right frame */
348 skb_pull(skb, 2);
349 skb_put(skb, 2);
350 }
351#if VERBOSE > SHOW_ERROR_MESSAGES
352 /* display the buffer contents for debugging */
353 DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
354 display_buffer((char *) skb->data, skb->len);
355#endif
356
357 /* check whether WDS is enabled and whether the data frame is a WDS frame */
358
359 if (init_wds) {
360 /* WDS enabled, check for the wds address on the first 6 bytes of the buffer */
361 src = skb->data + 6;
362 memmove(skb->data, src, skb->len - 6);
363 skb_trim(skb, skb->len - 6);
364 }
365#if VERBOSE > SHOW_ERROR_MESSAGES
366 DEBUG(SHOW_TRACING, "Fragment size %i in skb at %p\n", size, skb);
367 DEBUG(SHOW_TRACING, "Skb data at %p, length %i\n", skb->data, skb->len);
368
369 /* display the buffer contents for debugging */
370 DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
371 display_buffer((char *) skb->data, skb->len);
372#endif
373 /* take care of monitor mode and spy monitoring. */
374 if (unlikely(priv->iw_mode == IW_MODE_MONITOR)) {
375 skb->dev = ndev;
376 discard = islpci_monitor_rx(priv, &skb);
377 } else {
378 if (unlikely(skb->data[2 * ETH_ALEN] == 0)) {
379 /* The packet has a rx_annex. Read it for spy monitoring, Then
380 * remove it, while keeping the 2 leading MAC addr.
381 */
382 struct iw_quality wstats;
383 struct rx_annex_header *annex =
384 (struct rx_annex_header *) skb->data;
385 wstats.level = annex->rfmon.rssi;
386 /* The noise value can be a bit outdated if nobody's
387 * reading wireless stats... */
388 wstats.noise = priv->local_iwstatistics.qual.noise;
389 wstats.qual = wstats.level - wstats.noise;
390 wstats.updated = 0x07;
391 /* Update spy records */
392 wireless_spy_update(ndev, annex->addr2, &wstats);
393
394 skb_copy_from_linear_data(skb,
395 (skb->data +
396 sizeof(struct rfmon_header)),
397 2 * ETH_ALEN);
398 skb_pull(skb, sizeof (struct rfmon_header));
399 }
400 skb->protocol = eth_type_trans(skb, ndev);
401 }
402 skb->ip_summed = CHECKSUM_NONE;
403 ndev->stats.rx_packets++;
404 ndev->stats.rx_bytes += size;
405
406 /* deliver the skb to the network layer */
407#ifdef ISLPCI_ETH_DEBUG
408 printk
409 ("islpci_eth_receive:netif_rx %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
410 skb->data[0], skb->data[1], skb->data[2], skb->data[3],
411 skb->data[4], skb->data[5]);
412#endif
413 if (unlikely(discard)) {
414 dev_kfree_skb_irq(skb);
415 skb = NULL;
416 } else
417 netif_rx(skb);
418
419 /* increment the read index for the rx data low queue */
420 priv->free_data_rx++;
421
422 /* add one or more sk_buff structures */
423 while (index =
424 le32_to_cpu(control_block->
425 driver_curr_frag[ISL38XX_CB_RX_DATA_LQ]),
426 index - priv->free_data_rx < ISL38XX_CB_RX_QSIZE) {
427 /* allocate an sk_buff for received data frames storage
428 * include any required allignment operations */
429 skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2);
430 if (unlikely(skb == NULL)) {
431 /* error allocating an sk_buff structure elements */
432 DEBUG(SHOW_ERROR_MESSAGES, "Error allocating skb\n");
433 break;
434 }
435 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
436 /* store the new skb structure pointer */
437 index = index % ISL38XX_CB_RX_QSIZE;
438 priv->data_low_rx[index] = skb;
439
440#if VERBOSE > SHOW_ERROR_MESSAGES
441 DEBUG(SHOW_TRACING,
442 "new alloc skb %p skb->data %p skb->len %u index %u truesize %u\n ",
443 skb, skb->data, skb->len, index, skb->truesize);
444#endif
445
446 /* set the streaming DMA mapping for proper PCI bus operation */
447 priv->pci_map_rx_address[index] =
448 pci_map_single(priv->pdev, (void *) skb->data,
449 MAX_FRAGMENT_SIZE_RX + 2,
450 PCI_DMA_FROMDEVICE);
451 if (unlikely(!priv->pci_map_rx_address[index])) {
452 /* error mapping the buffer to device accessible memory address */
453 DEBUG(SHOW_ERROR_MESSAGES,
454 "Error mapping DMA address\n");
455
456 /* free the skbuf structure before aborting */
457 dev_kfree_skb_irq(skb);
458 skb = NULL;
459 break;
460 }
461 /* update the fragment address */
462 control_block->rx_data_low[index].address =
463 cpu_to_le32((u32)priv->pci_map_rx_address[index]);
464 wmb();
465
466 /* increment the driver read pointer */
467 le32_add_cpu(&control_block->
468 driver_curr_frag[ISL38XX_CB_RX_DATA_LQ], 1);
469 }
470
471 /* trigger the device */
472 islpci_trigger(priv);
473
474 return 0;
475}
476
477void
478islpci_do_reset_and_wake(struct work_struct *work)
479{
480 islpci_private *priv = container_of(work, islpci_private, reset_task);
481
482 islpci_reset(priv, 1);
483 priv->reset_task_pending = 0;
484 smp_wmb();
485 netif_wake_queue(priv->ndev);
486}
487
488void
489islpci_eth_tx_timeout(struct net_device *ndev)
490{
491 islpci_private *priv = netdev_priv(ndev);
492
493 /* increment the transmit error counter */
494 ndev->stats.tx_errors++;
495
496 if (!priv->reset_task_pending) {
497 printk(KERN_WARNING
498 "%s: tx_timeout, scheduling reset", ndev->name);
499 netif_stop_queue(ndev);
500 priv->reset_task_pending = 1;
501 schedule_work(&priv->reset_task);
502 } else {
503 printk(KERN_WARNING
504 "%s: tx_timeout, waiting for reset", ndev->name);
505 }
506}