18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (C) 2002 Intersil Americas Inc.
48c2ecf20Sopenharmony_ci *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/module.h>
88c2ecf20Sopenharmony_ci#include <linux/gfp.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/pci.h>
118c2ecf20Sopenharmony_ci#include <linux/delay.h>
128c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
138c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
148c2ecf20Sopenharmony_ci#include <linux/if_arp.h>
158c2ecf20Sopenharmony_ci#include <asm/byteorder.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include "prismcompat.h"
188c2ecf20Sopenharmony_ci#include "isl_38xx.h"
198c2ecf20Sopenharmony_ci#include "islpci_eth.h"
208c2ecf20Sopenharmony_ci#include "islpci_mgt.h"
218c2ecf20Sopenharmony_ci#include "oid_mgt.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/******************************************************************************
248c2ecf20Sopenharmony_ci    Network Interface functions
258c2ecf20Sopenharmony_ci******************************************************************************/
268c2ecf20Sopenharmony_civoid
278c2ecf20Sopenharmony_ciislpci_eth_cleanup_transmit(islpci_private *priv,
288c2ecf20Sopenharmony_ci			    isl38xx_control_block *control_block)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	struct sk_buff *skb;
318c2ecf20Sopenharmony_ci	u32 index;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	/* compare the control block read pointer with the free pointer */
348c2ecf20Sopenharmony_ci	while (priv->free_data_tx !=
358c2ecf20Sopenharmony_ci	       le32_to_cpu(control_block->
368c2ecf20Sopenharmony_ci			   device_curr_frag[ISL38XX_CB_TX_DATA_LQ])) {
378c2ecf20Sopenharmony_ci		/* read the index of the first fragment to be freed */
388c2ecf20Sopenharmony_ci		index = priv->free_data_tx % ISL38XX_CB_TX_QSIZE;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci		/* check for holes in the arrays caused by multi fragment frames
418c2ecf20Sopenharmony_ci		 * searching for the last fragment of a frame */
428c2ecf20Sopenharmony_ci		if (priv->pci_map_tx_address[index]) {
438c2ecf20Sopenharmony_ci			/* entry is the last fragment of a frame
448c2ecf20Sopenharmony_ci			 * free the skb structure and unmap pci memory */
458c2ecf20Sopenharmony_ci			skb = priv->data_low_tx[index];
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
488c2ecf20Sopenharmony_ci			DEBUG(SHOW_TRACING,
498c2ecf20Sopenharmony_ci			      "cleanup skb %p skb->data %p skb->len %u truesize %u\n",
508c2ecf20Sopenharmony_ci			      skb, skb->data, skb->len, skb->truesize);
518c2ecf20Sopenharmony_ci#endif
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci			dma_unmap_single(&priv->pdev->dev,
548c2ecf20Sopenharmony_ci					 priv->pci_map_tx_address[index],
558c2ecf20Sopenharmony_ci					 skb->len, DMA_TO_DEVICE);
568c2ecf20Sopenharmony_ci			dev_kfree_skb_irq(skb);
578c2ecf20Sopenharmony_ci			skb = NULL;
588c2ecf20Sopenharmony_ci		}
598c2ecf20Sopenharmony_ci		/* increment the free data low queue pointer */
608c2ecf20Sopenharmony_ci		priv->free_data_tx++;
618c2ecf20Sopenharmony_ci	}
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cinetdev_tx_t
658c2ecf20Sopenharmony_ciislpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	islpci_private *priv = netdev_priv(ndev);
688c2ecf20Sopenharmony_ci	isl38xx_control_block *cb = priv->control_block;
698c2ecf20Sopenharmony_ci	u32 index;
708c2ecf20Sopenharmony_ci	dma_addr_t pci_map_address;
718c2ecf20Sopenharmony_ci	int frame_size;
728c2ecf20Sopenharmony_ci	isl38xx_fragment *fragment;
738c2ecf20Sopenharmony_ci	int offset;
748c2ecf20Sopenharmony_ci	struct sk_buff *newskb;
758c2ecf20Sopenharmony_ci	int newskb_offset;
768c2ecf20Sopenharmony_ci	unsigned long flags;
778c2ecf20Sopenharmony_ci	unsigned char wds_mac[6];
788c2ecf20Sopenharmony_ci	u32 curr_frag;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
818c2ecf20Sopenharmony_ci	DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_transmit\n");
828c2ecf20Sopenharmony_ci#endif
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	/* lock the driver code */
858c2ecf20Sopenharmony_ci	spin_lock_irqsave(&priv->slock, flags);
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	/* check whether the destination queue has enough fragments for the frame */
888c2ecf20Sopenharmony_ci	curr_frag = le32_to_cpu(cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ]);
898c2ecf20Sopenharmony_ci	if (unlikely(curr_frag - priv->free_data_tx >= ISL38XX_CB_TX_QSIZE)) {
908c2ecf20Sopenharmony_ci		printk(KERN_ERR "%s: transmit device queue full when awake\n",
918c2ecf20Sopenharmony_ci		       ndev->name);
928c2ecf20Sopenharmony_ci		netif_stop_queue(ndev);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci		/* trigger the device */
958c2ecf20Sopenharmony_ci		isl38xx_w32_flush(priv->device_base, ISL38XX_DEV_INT_UPDATE,
968c2ecf20Sopenharmony_ci				  ISL38XX_DEV_INT_REG);
978c2ecf20Sopenharmony_ci		udelay(ISL38XX_WRITEIO_DELAY);
988c2ecf20Sopenharmony_ci		goto drop_free;
998c2ecf20Sopenharmony_ci	}
1008c2ecf20Sopenharmony_ci	/* Check alignment and WDS frame formatting. The start of the packet should
1018c2ecf20Sopenharmony_ci	 * be aligned on a 4-byte boundary. If WDS is enabled add another 6 bytes
1028c2ecf20Sopenharmony_ci	 * and add WDS address information */
1038c2ecf20Sopenharmony_ci	if (likely(((long) skb->data & 0x03) | init_wds)) {
1048c2ecf20Sopenharmony_ci		/* get the number of bytes to add and re-align */
1058c2ecf20Sopenharmony_ci		offset = (4 - (long) skb->data) & 0x03;
1068c2ecf20Sopenharmony_ci		offset += init_wds ? 6 : 0;
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci		/* check whether the current skb can be used  */
1098c2ecf20Sopenharmony_ci		if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
1108c2ecf20Sopenharmony_ci			unsigned char *src = skb->data;
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
1138c2ecf20Sopenharmony_ci			DEBUG(SHOW_TRACING, "skb offset %i wds %i\n", offset,
1148c2ecf20Sopenharmony_ci			      init_wds);
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci			/* align the buffer on 4-byte boundary */
1188c2ecf20Sopenharmony_ci			skb_reserve(skb, (4 - (long) skb->data) & 0x03);
1198c2ecf20Sopenharmony_ci			if (init_wds) {
1208c2ecf20Sopenharmony_ci				/* wds requires an additional address field of 6 bytes */
1218c2ecf20Sopenharmony_ci				skb_put(skb, 6);
1228c2ecf20Sopenharmony_ci#ifdef ISLPCI_ETH_DEBUG
1238c2ecf20Sopenharmony_ci				printk("islpci_eth_transmit:wds_mac\n");
1248c2ecf20Sopenharmony_ci#endif
1258c2ecf20Sopenharmony_ci				memmove(skb->data + 6, src, skb->len);
1268c2ecf20Sopenharmony_ci				skb_copy_to_linear_data(skb, wds_mac, 6);
1278c2ecf20Sopenharmony_ci			} else {
1288c2ecf20Sopenharmony_ci				memmove(skb->data, src, skb->len);
1298c2ecf20Sopenharmony_ci			}
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
1328c2ecf20Sopenharmony_ci			DEBUG(SHOW_TRACING, "memmove %p %p %i\n", skb->data,
1338c2ecf20Sopenharmony_ci			      src, skb->len);
1348c2ecf20Sopenharmony_ci#endif
1358c2ecf20Sopenharmony_ci		} else {
1368c2ecf20Sopenharmony_ci			newskb =
1378c2ecf20Sopenharmony_ci			    dev_alloc_skb(init_wds ? skb->len + 6 : skb->len);
1388c2ecf20Sopenharmony_ci			if (unlikely(newskb == NULL)) {
1398c2ecf20Sopenharmony_ci				printk(KERN_ERR "%s: Cannot allocate skb\n",
1408c2ecf20Sopenharmony_ci				       ndev->name);
1418c2ecf20Sopenharmony_ci				goto drop_free;
1428c2ecf20Sopenharmony_ci			}
1438c2ecf20Sopenharmony_ci			newskb_offset = (4 - (long) newskb->data) & 0x03;
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci			/* Check if newskb->data is aligned */
1468c2ecf20Sopenharmony_ci			if (newskb_offset)
1478c2ecf20Sopenharmony_ci				skb_reserve(newskb, newskb_offset);
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci			skb_put(newskb, init_wds ? skb->len + 6 : skb->len);
1508c2ecf20Sopenharmony_ci			if (init_wds) {
1518c2ecf20Sopenharmony_ci				skb_copy_from_linear_data(skb,
1528c2ecf20Sopenharmony_ci							  newskb->data + 6,
1538c2ecf20Sopenharmony_ci							  skb->len);
1548c2ecf20Sopenharmony_ci				skb_copy_to_linear_data(newskb, wds_mac, 6);
1558c2ecf20Sopenharmony_ci#ifdef ISLPCI_ETH_DEBUG
1568c2ecf20Sopenharmony_ci				printk("islpci_eth_transmit:wds_mac\n");
1578c2ecf20Sopenharmony_ci#endif
1588c2ecf20Sopenharmony_ci			} else
1598c2ecf20Sopenharmony_ci				skb_copy_from_linear_data(skb, newskb->data,
1608c2ecf20Sopenharmony_ci							  skb->len);
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
1638c2ecf20Sopenharmony_ci			DEBUG(SHOW_TRACING, "memcpy %p %p %i wds %i\n",
1648c2ecf20Sopenharmony_ci			      newskb->data, skb->data, skb->len, init_wds);
1658c2ecf20Sopenharmony_ci#endif
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci			newskb->dev = skb->dev;
1688c2ecf20Sopenharmony_ci			dev_kfree_skb_irq(skb);
1698c2ecf20Sopenharmony_ci			skb = newskb;
1708c2ecf20Sopenharmony_ci		}
1718c2ecf20Sopenharmony_ci	}
1728c2ecf20Sopenharmony_ci	/* display the buffer contents for debugging */
1738c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
1748c2ecf20Sopenharmony_ci	DEBUG(SHOW_BUFFER_CONTENTS, "\ntx %p ", skb->data);
1758c2ecf20Sopenharmony_ci	display_buffer((char *) skb->data, skb->len);
1768c2ecf20Sopenharmony_ci#endif
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	/* map the skb buffer to pci memory for DMA operation */
1798c2ecf20Sopenharmony_ci	pci_map_address = dma_map_single(&priv->pdev->dev, (void *)skb->data,
1808c2ecf20Sopenharmony_ci					 skb->len, DMA_TO_DEVICE);
1818c2ecf20Sopenharmony_ci	if (dma_mapping_error(&priv->pdev->dev, pci_map_address)) {
1828c2ecf20Sopenharmony_ci		printk(KERN_WARNING "%s: cannot map buffer to PCI\n",
1838c2ecf20Sopenharmony_ci		       ndev->name);
1848c2ecf20Sopenharmony_ci		goto drop_free;
1858c2ecf20Sopenharmony_ci	}
1868c2ecf20Sopenharmony_ci	/* Place the fragment in the control block structure. */
1878c2ecf20Sopenharmony_ci	index = curr_frag % ISL38XX_CB_TX_QSIZE;
1888c2ecf20Sopenharmony_ci	fragment = &cb->tx_data_low[index];
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci	priv->pci_map_tx_address[index] = pci_map_address;
1918c2ecf20Sopenharmony_ci	/* store the skb address for future freeing  */
1928c2ecf20Sopenharmony_ci	priv->data_low_tx[index] = skb;
1938c2ecf20Sopenharmony_ci	/* set the proper fragment start address and size information */
1948c2ecf20Sopenharmony_ci	frame_size = skb->len;
1958c2ecf20Sopenharmony_ci	fragment->size = cpu_to_le16(frame_size);
1968c2ecf20Sopenharmony_ci	fragment->flags = cpu_to_le16(0);	/* set to 1 if more fragments */
1978c2ecf20Sopenharmony_ci	fragment->address = cpu_to_le32(pci_map_address);
1988c2ecf20Sopenharmony_ci	curr_frag++;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	/* The fragment address in the control block must have been
2018c2ecf20Sopenharmony_ci	 * written before announcing the frame buffer to device. */
2028c2ecf20Sopenharmony_ci	wmb();
2038c2ecf20Sopenharmony_ci	cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ] = cpu_to_le32(curr_frag);
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	if (curr_frag - priv->free_data_tx + ISL38XX_MIN_QTHRESHOLD
2068c2ecf20Sopenharmony_ci	    > ISL38XX_CB_TX_QSIZE) {
2078c2ecf20Sopenharmony_ci		/* stop sends from upper layers */
2088c2ecf20Sopenharmony_ci		netif_stop_queue(ndev);
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci		/* set the full flag for the transmission queue */
2118c2ecf20Sopenharmony_ci		priv->data_low_tx_full = 1;
2128c2ecf20Sopenharmony_ci	}
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci	ndev->stats.tx_packets++;
2158c2ecf20Sopenharmony_ci	ndev->stats.tx_bytes += skb->len;
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci	/* trigger the device */
2188c2ecf20Sopenharmony_ci	islpci_trigger(priv);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_ci	/* unlock the driver code */
2218c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&priv->slock, flags);
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci	return NETDEV_TX_OK;
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_ci      drop_free:
2268c2ecf20Sopenharmony_ci	ndev->stats.tx_dropped++;
2278c2ecf20Sopenharmony_ci	spin_unlock_irqrestore(&priv->slock, flags);
2288c2ecf20Sopenharmony_ci	dev_kfree_skb(skb);
2298c2ecf20Sopenharmony_ci	return NETDEV_TX_OK;
2308c2ecf20Sopenharmony_ci}
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cistatic inline int
2338c2ecf20Sopenharmony_ciislpci_monitor_rx(islpci_private *priv, struct sk_buff **skb)
2348c2ecf20Sopenharmony_ci{
2358c2ecf20Sopenharmony_ci	/* The card reports full 802.11 packets but with a 20 bytes
2368c2ecf20Sopenharmony_ci	 * header and without the FCS. But there a is a bit that
2378c2ecf20Sopenharmony_ci	 * indicates if the packet is corrupted :-) */
2388c2ecf20Sopenharmony_ci	struct rfmon_header *hdr = (struct rfmon_header *) (*skb)->data;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	if (hdr->flags & 0x01)
2418c2ecf20Sopenharmony_ci		/* This one is bad. Drop it ! */
2428c2ecf20Sopenharmony_ci		return -1;
2438c2ecf20Sopenharmony_ci	if (priv->ndev->type == ARPHRD_IEEE80211_PRISM) {
2448c2ecf20Sopenharmony_ci		struct avs_80211_1_header *avs;
2458c2ecf20Sopenharmony_ci		/* extract the relevant data from the header */
2468c2ecf20Sopenharmony_ci		u32 clock = le32_to_cpu(hdr->clock);
2478c2ecf20Sopenharmony_ci		u8 rate = hdr->rate;
2488c2ecf20Sopenharmony_ci		u16 freq = le16_to_cpu(hdr->freq);
2498c2ecf20Sopenharmony_ci		u8 rssi = hdr->rssi;
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci		skb_pull(*skb, sizeof (struct rfmon_header));
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_ci		if (skb_headroom(*skb) < sizeof (struct avs_80211_1_header)) {
2548c2ecf20Sopenharmony_ci			struct sk_buff *newskb = skb_copy_expand(*skb,
2558c2ecf20Sopenharmony_ci								 sizeof (struct
2568c2ecf20Sopenharmony_ci									 avs_80211_1_header),
2578c2ecf20Sopenharmony_ci								 0, GFP_ATOMIC);
2588c2ecf20Sopenharmony_ci			if (newskb) {
2598c2ecf20Sopenharmony_ci				dev_kfree_skb_irq(*skb);
2608c2ecf20Sopenharmony_ci				*skb = newskb;
2618c2ecf20Sopenharmony_ci			} else
2628c2ecf20Sopenharmony_ci				return -1;
2638c2ecf20Sopenharmony_ci			/* This behavior is not very subtile... */
2648c2ecf20Sopenharmony_ci		}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci		/* make room for the new header and fill it. */
2678c2ecf20Sopenharmony_ci		avs = skb_push(*skb, sizeof(struct avs_80211_1_header));
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_ci		avs->version = cpu_to_be32(P80211CAPTURE_VERSION);
2708c2ecf20Sopenharmony_ci		avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header));
2718c2ecf20Sopenharmony_ci		avs->mactime = cpu_to_be64(clock);
2728c2ecf20Sopenharmony_ci		avs->hosttime = cpu_to_be64(jiffies);
2738c2ecf20Sopenharmony_ci		avs->phytype = cpu_to_be32(6);	/*OFDM: 6 for (g), 8 for (a) */
2748c2ecf20Sopenharmony_ci		avs->channel = cpu_to_be32(channel_of_freq(freq));
2758c2ecf20Sopenharmony_ci		avs->datarate = cpu_to_be32(rate * 5);
2768c2ecf20Sopenharmony_ci		avs->antenna = cpu_to_be32(0);	/*unknown */
2778c2ecf20Sopenharmony_ci		avs->priority = cpu_to_be32(0);	/*unknown */
2788c2ecf20Sopenharmony_ci		avs->ssi_type = cpu_to_be32(3);	/*2: dBm, 3: raw RSSI */
2798c2ecf20Sopenharmony_ci		avs->ssi_signal = cpu_to_be32(rssi & 0x7f);
2808c2ecf20Sopenharmony_ci		avs->ssi_noise = cpu_to_be32(priv->local_iwstatistics.qual.noise);	/*better than 'undefined', I assume */
2818c2ecf20Sopenharmony_ci		avs->preamble = cpu_to_be32(0);	/*unknown */
2828c2ecf20Sopenharmony_ci		avs->encoding = cpu_to_be32(0);	/*unknown */
2838c2ecf20Sopenharmony_ci	} else
2848c2ecf20Sopenharmony_ci		skb_pull(*skb, sizeof (struct rfmon_header));
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci	(*skb)->protocol = htons(ETH_P_802_2);
2878c2ecf20Sopenharmony_ci	skb_reset_mac_header(*skb);
2888c2ecf20Sopenharmony_ci	(*skb)->pkt_type = PACKET_OTHERHOST;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	return 0;
2918c2ecf20Sopenharmony_ci}
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ciint
2948c2ecf20Sopenharmony_ciislpci_eth_receive(islpci_private *priv)
2958c2ecf20Sopenharmony_ci{
2968c2ecf20Sopenharmony_ci	struct net_device *ndev = priv->ndev;
2978c2ecf20Sopenharmony_ci	isl38xx_control_block *control_block = priv->control_block;
2988c2ecf20Sopenharmony_ci	struct sk_buff *skb;
2998c2ecf20Sopenharmony_ci	u16 size;
3008c2ecf20Sopenharmony_ci	u32 index, offset;
3018c2ecf20Sopenharmony_ci	unsigned char *src;
3028c2ecf20Sopenharmony_ci	int discard = 0;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
3058c2ecf20Sopenharmony_ci	DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_receive\n");
3068c2ecf20Sopenharmony_ci#endif
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_ci	/* the device has written an Ethernet frame in the data area
3098c2ecf20Sopenharmony_ci	 * of the sk_buff without updating the structure, do it now */
3108c2ecf20Sopenharmony_ci	index = priv->free_data_rx % ISL38XX_CB_RX_QSIZE;
3118c2ecf20Sopenharmony_ci	size = le16_to_cpu(control_block->rx_data_low[index].size);
3128c2ecf20Sopenharmony_ci	skb = priv->data_low_rx[index];
3138c2ecf20Sopenharmony_ci	offset = ((unsigned long)
3148c2ecf20Sopenharmony_ci		  le32_to_cpu(control_block->rx_data_low[index].address) -
3158c2ecf20Sopenharmony_ci		  (unsigned long) skb->data) & 3;
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
3188c2ecf20Sopenharmony_ci	DEBUG(SHOW_TRACING,
3198c2ecf20Sopenharmony_ci	      "frq->addr %x skb->data %p skb->len %u offset %u truesize %u\n",
3208c2ecf20Sopenharmony_ci	      control_block->rx_data_low[priv->free_data_rx].address, skb->data,
3218c2ecf20Sopenharmony_ci	      skb->len, offset, skb->truesize);
3228c2ecf20Sopenharmony_ci#endif
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci	/* delete the streaming DMA mapping before processing the skb */
3258c2ecf20Sopenharmony_ci	dma_unmap_single(&priv->pdev->dev, priv->pci_map_rx_address[index],
3268c2ecf20Sopenharmony_ci			 MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE);
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	/* update the skb structure and align the buffer */
3298c2ecf20Sopenharmony_ci	skb_put(skb, size);
3308c2ecf20Sopenharmony_ci	if (offset) {
3318c2ecf20Sopenharmony_ci		/* shift the buffer allocation offset bytes to get the right frame */
3328c2ecf20Sopenharmony_ci		skb_pull(skb, 2);
3338c2ecf20Sopenharmony_ci		skb_put(skb, 2);
3348c2ecf20Sopenharmony_ci	}
3358c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
3368c2ecf20Sopenharmony_ci	/* display the buffer contents for debugging */
3378c2ecf20Sopenharmony_ci	DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
3388c2ecf20Sopenharmony_ci	display_buffer((char *) skb->data, skb->len);
3398c2ecf20Sopenharmony_ci#endif
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	/* check whether WDS is enabled and whether the data frame is a WDS frame */
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	if (init_wds) {
3448c2ecf20Sopenharmony_ci		/* WDS enabled, check for the wds address on the first 6 bytes of the buffer */
3458c2ecf20Sopenharmony_ci		src = skb->data + 6;
3468c2ecf20Sopenharmony_ci		memmove(skb->data, src, skb->len - 6);
3478c2ecf20Sopenharmony_ci		skb_trim(skb, skb->len - 6);
3488c2ecf20Sopenharmony_ci	}
3498c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
3508c2ecf20Sopenharmony_ci	DEBUG(SHOW_TRACING, "Fragment size %i in skb at %p\n", size, skb);
3518c2ecf20Sopenharmony_ci	DEBUG(SHOW_TRACING, "Skb data at %p, length %i\n", skb->data, skb->len);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	/* display the buffer contents for debugging */
3548c2ecf20Sopenharmony_ci	DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
3558c2ecf20Sopenharmony_ci	display_buffer((char *) skb->data, skb->len);
3568c2ecf20Sopenharmony_ci#endif
3578c2ecf20Sopenharmony_ci	/* take care of monitor mode and spy monitoring. */
3588c2ecf20Sopenharmony_ci	if (unlikely(priv->iw_mode == IW_MODE_MONITOR)) {
3598c2ecf20Sopenharmony_ci		skb->dev = ndev;
3608c2ecf20Sopenharmony_ci		discard = islpci_monitor_rx(priv, &skb);
3618c2ecf20Sopenharmony_ci	} else {
3628c2ecf20Sopenharmony_ci		if (unlikely(skb->data[2 * ETH_ALEN] == 0)) {
3638c2ecf20Sopenharmony_ci			/* The packet has a rx_annex. Read it for spy monitoring, Then
3648c2ecf20Sopenharmony_ci			 * remove it, while keeping the 2 leading MAC addr.
3658c2ecf20Sopenharmony_ci			 */
3668c2ecf20Sopenharmony_ci			struct iw_quality wstats;
3678c2ecf20Sopenharmony_ci			struct rx_annex_header *annex =
3688c2ecf20Sopenharmony_ci			    (struct rx_annex_header *) skb->data;
3698c2ecf20Sopenharmony_ci			wstats.level = annex->rfmon.rssi;
3708c2ecf20Sopenharmony_ci			/* The noise value can be a bit outdated if nobody's
3718c2ecf20Sopenharmony_ci			 * reading wireless stats... */
3728c2ecf20Sopenharmony_ci			wstats.noise = priv->local_iwstatistics.qual.noise;
3738c2ecf20Sopenharmony_ci			wstats.qual = wstats.level - wstats.noise;
3748c2ecf20Sopenharmony_ci			wstats.updated = 0x07;
3758c2ecf20Sopenharmony_ci			/* Update spy records */
3768c2ecf20Sopenharmony_ci			wireless_spy_update(ndev, annex->addr2, &wstats);
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci			skb_copy_from_linear_data(skb,
3798c2ecf20Sopenharmony_ci						  (skb->data +
3808c2ecf20Sopenharmony_ci						   sizeof(struct rfmon_header)),
3818c2ecf20Sopenharmony_ci						  2 * ETH_ALEN);
3828c2ecf20Sopenharmony_ci			skb_pull(skb, sizeof (struct rfmon_header));
3838c2ecf20Sopenharmony_ci		}
3848c2ecf20Sopenharmony_ci		skb->protocol = eth_type_trans(skb, ndev);
3858c2ecf20Sopenharmony_ci	}
3868c2ecf20Sopenharmony_ci	skb->ip_summed = CHECKSUM_NONE;
3878c2ecf20Sopenharmony_ci	ndev->stats.rx_packets++;
3888c2ecf20Sopenharmony_ci	ndev->stats.rx_bytes += size;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	/* deliver the skb to the network layer */
3918c2ecf20Sopenharmony_ci#ifdef ISLPCI_ETH_DEBUG
3928c2ecf20Sopenharmony_ci	printk
3938c2ecf20Sopenharmony_ci	    ("islpci_eth_receive:netif_rx %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
3948c2ecf20Sopenharmony_ci	     skb->data[0], skb->data[1], skb->data[2], skb->data[3],
3958c2ecf20Sopenharmony_ci	     skb->data[4], skb->data[5]);
3968c2ecf20Sopenharmony_ci#endif
3978c2ecf20Sopenharmony_ci	if (unlikely(discard)) {
3988c2ecf20Sopenharmony_ci		dev_kfree_skb_irq(skb);
3998c2ecf20Sopenharmony_ci		skb = NULL;
4008c2ecf20Sopenharmony_ci	} else
4018c2ecf20Sopenharmony_ci		netif_rx(skb);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	/* increment the read index for the rx data low queue */
4048c2ecf20Sopenharmony_ci	priv->free_data_rx++;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	/* add one or more sk_buff structures */
4078c2ecf20Sopenharmony_ci	while (index =
4088c2ecf20Sopenharmony_ci	       le32_to_cpu(control_block->
4098c2ecf20Sopenharmony_ci			   driver_curr_frag[ISL38XX_CB_RX_DATA_LQ]),
4108c2ecf20Sopenharmony_ci	       index - priv->free_data_rx < ISL38XX_CB_RX_QSIZE) {
4118c2ecf20Sopenharmony_ci		/* allocate an sk_buff for received data frames storage
4128c2ecf20Sopenharmony_ci		 * include any required allignment operations */
4138c2ecf20Sopenharmony_ci		skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2);
4148c2ecf20Sopenharmony_ci		if (unlikely(skb == NULL)) {
4158c2ecf20Sopenharmony_ci			/* error allocating an sk_buff structure elements */
4168c2ecf20Sopenharmony_ci			DEBUG(SHOW_ERROR_MESSAGES, "Error allocating skb\n");
4178c2ecf20Sopenharmony_ci			break;
4188c2ecf20Sopenharmony_ci		}
4198c2ecf20Sopenharmony_ci		skb_reserve(skb, (4 - (long) skb->data) & 0x03);
4208c2ecf20Sopenharmony_ci		/* store the new skb structure pointer */
4218c2ecf20Sopenharmony_ci		index = index % ISL38XX_CB_RX_QSIZE;
4228c2ecf20Sopenharmony_ci		priv->data_low_rx[index] = skb;
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#if VERBOSE > SHOW_ERROR_MESSAGES
4258c2ecf20Sopenharmony_ci		DEBUG(SHOW_TRACING,
4268c2ecf20Sopenharmony_ci		      "new alloc skb %p skb->data %p skb->len %u index %u truesize %u\n",
4278c2ecf20Sopenharmony_ci		      skb, skb->data, skb->len, index, skb->truesize);
4288c2ecf20Sopenharmony_ci#endif
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_ci		/* set the streaming DMA mapping for proper PCI bus operation */
4318c2ecf20Sopenharmony_ci		priv->pci_map_rx_address[index] =
4328c2ecf20Sopenharmony_ci		    dma_map_single(&priv->pdev->dev, (void *)skb->data,
4338c2ecf20Sopenharmony_ci				   MAX_FRAGMENT_SIZE_RX + 2, DMA_FROM_DEVICE);
4348c2ecf20Sopenharmony_ci		if (dma_mapping_error(&priv->pdev->dev, priv->pci_map_rx_address[index])) {
4358c2ecf20Sopenharmony_ci			/* error mapping the buffer to device accessible memory address */
4368c2ecf20Sopenharmony_ci			DEBUG(SHOW_ERROR_MESSAGES,
4378c2ecf20Sopenharmony_ci			      "Error mapping DMA address\n");
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci			/* free the skbuf structure before aborting */
4408c2ecf20Sopenharmony_ci			dev_kfree_skb_irq(skb);
4418c2ecf20Sopenharmony_ci			skb = NULL;
4428c2ecf20Sopenharmony_ci			break;
4438c2ecf20Sopenharmony_ci		}
4448c2ecf20Sopenharmony_ci		/* update the fragment address */
4458c2ecf20Sopenharmony_ci		control_block->rx_data_low[index].address =
4468c2ecf20Sopenharmony_ci			cpu_to_le32((u32)priv->pci_map_rx_address[index]);
4478c2ecf20Sopenharmony_ci		wmb();
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci		/* increment the driver read pointer */
4508c2ecf20Sopenharmony_ci		le32_add_cpu(&control_block->
4518c2ecf20Sopenharmony_ci			     driver_curr_frag[ISL38XX_CB_RX_DATA_LQ], 1);
4528c2ecf20Sopenharmony_ci	}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci	/* trigger the device */
4558c2ecf20Sopenharmony_ci	islpci_trigger(priv);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci	return 0;
4588c2ecf20Sopenharmony_ci}
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_civoid
4618c2ecf20Sopenharmony_ciislpci_do_reset_and_wake(struct work_struct *work)
4628c2ecf20Sopenharmony_ci{
4638c2ecf20Sopenharmony_ci	islpci_private *priv = container_of(work, islpci_private, reset_task);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	islpci_reset(priv, 1);
4668c2ecf20Sopenharmony_ci	priv->reset_task_pending = 0;
4678c2ecf20Sopenharmony_ci	smp_wmb();
4688c2ecf20Sopenharmony_ci	netif_wake_queue(priv->ndev);
4698c2ecf20Sopenharmony_ci}
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_civoid
4728c2ecf20Sopenharmony_ciislpci_eth_tx_timeout(struct net_device *ndev, unsigned int txqueue)
4738c2ecf20Sopenharmony_ci{
4748c2ecf20Sopenharmony_ci	islpci_private *priv = netdev_priv(ndev);
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci	/* increment the transmit error counter */
4778c2ecf20Sopenharmony_ci	ndev->stats.tx_errors++;
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	if (!priv->reset_task_pending) {
4808c2ecf20Sopenharmony_ci		printk(KERN_WARNING
4818c2ecf20Sopenharmony_ci			"%s: tx_timeout, scheduling reset", ndev->name);
4828c2ecf20Sopenharmony_ci		netif_stop_queue(ndev);
4838c2ecf20Sopenharmony_ci		priv->reset_task_pending = 1;
4848c2ecf20Sopenharmony_ci		schedule_work(&priv->reset_task);
4858c2ecf20Sopenharmony_ci	} else {
4868c2ecf20Sopenharmony_ci		printk(KERN_WARNING
4878c2ecf20Sopenharmony_ci			"%s: tx_timeout, waiting for reset", ndev->name);
4888c2ecf20Sopenharmony_ci	}
4898c2ecf20Sopenharmony_ci}
490