This source file includes following definitions.
- islpci_eth_cleanup_transmit
- islpci_eth_transmit
- islpci_monitor_rx
- islpci_eth_receive
- islpci_do_reset_and_wake
- islpci_eth_tx_timeout
   1 
   2 
   3 
   4 
   5 
   6 
   7 #include <linux/module.h>
   8 #include <linux/gfp.h>
   9 
  10 #include <linux/pci.h>
  11 #include <linux/delay.h>
  12 #include <linux/netdevice.h>
  13 #include <linux/etherdevice.h>
  14 #include <linux/if_arp.h>
  15 #include <asm/byteorder.h>
  16 
  17 #include "prismcompat.h"
  18 #include "isl_38xx.h"
  19 #include "islpci_eth.h"
  20 #include "islpci_mgt.h"
  21 #include "oid_mgt.h"
  22 
  23 
  24 
  25 
  26 void
  27 islpci_eth_cleanup_transmit(islpci_private *priv,
  28                             isl38xx_control_block *control_block)
  29 {
  30         struct sk_buff *skb;
  31         u32 index;
  32 
  33         
  34         while (priv->free_data_tx !=
  35                le32_to_cpu(control_block->
  36                            device_curr_frag[ISL38XX_CB_TX_DATA_LQ])) {
  37                 
  38                 index = priv->free_data_tx % ISL38XX_CB_TX_QSIZE;
  39 
  40                 
  41 
  42                 if (priv->pci_map_tx_address[index]) {
  43                         
  44 
  45                         skb = priv->data_low_tx[index];
  46 
  47 #if VERBOSE > SHOW_ERROR_MESSAGES
  48                         DEBUG(SHOW_TRACING,
  49                               "cleanup skb %p skb->data %p skb->len %u truesize %u\n",
  50                               skb, skb->data, skb->len, skb->truesize);
  51 #endif
  52 
  53                         pci_unmap_single(priv->pdev,
  54                                          priv->pci_map_tx_address[index],
  55                                          skb->len, PCI_DMA_TODEVICE);
  56                         dev_kfree_skb_irq(skb);
  57                         skb = NULL;
  58                 }
  59                 
  60                 priv->free_data_tx++;
  61         }
  62 }
  63 
  64 netdev_tx_t
  65 islpci_eth_transmit(struct sk_buff *skb, struct net_device *ndev)
  66 {
  67         islpci_private *priv = netdev_priv(ndev);
  68         isl38xx_control_block *cb = priv->control_block;
  69         u32 index;
  70         dma_addr_t pci_map_address;
  71         int frame_size;
  72         isl38xx_fragment *fragment;
  73         int offset;
  74         struct sk_buff *newskb;
  75         int newskb_offset;
  76         unsigned long flags;
  77         unsigned char wds_mac[6];
  78         u32 curr_frag;
  79 
  80 #if VERBOSE > SHOW_ERROR_MESSAGES
  81         DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_transmit\n");
  82 #endif
  83 
  84         
  85         spin_lock_irqsave(&priv->slock, flags);
  86 
  87         
  88         curr_frag = le32_to_cpu(cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ]);
  89         if (unlikely(curr_frag - priv->free_data_tx >= ISL38XX_CB_TX_QSIZE)) {
  90                 printk(KERN_ERR "%s: transmit device queue full when awake\n",
  91                        ndev->name);
  92                 netif_stop_queue(ndev);
  93 
  94                 
  95                 isl38xx_w32_flush(priv->device_base, ISL38XX_DEV_INT_UPDATE,
  96                                   ISL38XX_DEV_INT_REG);
  97                 udelay(ISL38XX_WRITEIO_DELAY);
  98                 goto drop_free;
  99         }
 100         
 101 
 102 
 103         if (likely(((long) skb->data & 0x03) | init_wds)) {
 104                 
 105                 offset = (4 - (long) skb->data) & 0x03;
 106                 offset += init_wds ? 6 : 0;
 107 
 108                 
 109                 if (!skb_cloned(skb) && (skb_tailroom(skb) >= offset)) {
 110                         unsigned char *src = skb->data;
 111 
 112 #if VERBOSE > SHOW_ERROR_MESSAGES
 113                         DEBUG(SHOW_TRACING, "skb offset %i wds %i\n", offset,
 114                               init_wds);
 115 #endif
 116 
 117                         
 118                         skb_reserve(skb, (4 - (long) skb->data) & 0x03);
 119                         if (init_wds) {
 120                                 
 121                                 skb_put(skb, 6);
 122 #ifdef ISLPCI_ETH_DEBUG
 123                                 printk("islpci_eth_transmit:wds_mac\n");
 124 #endif
 125                                 memmove(skb->data + 6, src, skb->len);
 126                                 skb_copy_to_linear_data(skb, wds_mac, 6);
 127                         } else {
 128                                 memmove(skb->data, src, skb->len);
 129                         }
 130 
 131 #if VERBOSE > SHOW_ERROR_MESSAGES
 132                         DEBUG(SHOW_TRACING, "memmove %p %p %i\n", skb->data,
 133                               src, skb->len);
 134 #endif
 135                 } else {
 136                         newskb =
 137                             dev_alloc_skb(init_wds ? skb->len + 6 : skb->len);
 138                         if (unlikely(newskb == NULL)) {
 139                                 printk(KERN_ERR "%s: Cannot allocate skb\n",
 140                                        ndev->name);
 141                                 goto drop_free;
 142                         }
 143                         newskb_offset = (4 - (long) newskb->data) & 0x03;
 144 
 145                         
 146                         if (newskb_offset)
 147                                 skb_reserve(newskb, newskb_offset);
 148 
 149                         skb_put(newskb, init_wds ? skb->len + 6 : skb->len);
 150                         if (init_wds) {
 151                                 skb_copy_from_linear_data(skb,
 152                                                           newskb->data + 6,
 153                                                           skb->len);
 154                                 skb_copy_to_linear_data(newskb, wds_mac, 6);
 155 #ifdef ISLPCI_ETH_DEBUG
 156                                 printk("islpci_eth_transmit:wds_mac\n");
 157 #endif
 158                         } else
 159                                 skb_copy_from_linear_data(skb, newskb->data,
 160                                                           skb->len);
 161 
 162 #if VERBOSE > SHOW_ERROR_MESSAGES
 163                         DEBUG(SHOW_TRACING, "memcpy %p %p %i wds %i\n",
 164                               newskb->data, skb->data, skb->len, init_wds);
 165 #endif
 166 
 167                         newskb->dev = skb->dev;
 168                         dev_kfree_skb_irq(skb);
 169                         skb = newskb;
 170                 }
 171         }
 172         
 173 #if VERBOSE > SHOW_ERROR_MESSAGES
 174         DEBUG(SHOW_BUFFER_CONTENTS, "\ntx %p ", skb->data);
 175         display_buffer((char *) skb->data, skb->len);
 176 #endif
 177 
 178         
 179         pci_map_address = pci_map_single(priv->pdev,
 180                                          (void *) skb->data, skb->len,
 181                                          PCI_DMA_TODEVICE);
 182         if (pci_dma_mapping_error(priv->pdev, pci_map_address)) {
 183                 printk(KERN_WARNING "%s: cannot map buffer to PCI\n",
 184                        ndev->name);
 185                 goto drop_free;
 186         }
 187         
 188         index = curr_frag % ISL38XX_CB_TX_QSIZE;
 189         fragment = &cb->tx_data_low[index];
 190 
 191         priv->pci_map_tx_address[index] = pci_map_address;
 192         
 193         priv->data_low_tx[index] = skb;
 194         
 195         frame_size = skb->len;
 196         fragment->size = cpu_to_le16(frame_size);
 197         fragment->flags = cpu_to_le16(0);       
 198         fragment->address = cpu_to_le32(pci_map_address);
 199         curr_frag++;
 200 
 201         
 202 
 203         wmb();
 204         cb->driver_curr_frag[ISL38XX_CB_TX_DATA_LQ] = cpu_to_le32(curr_frag);
 205 
 206         if (curr_frag - priv->free_data_tx + ISL38XX_MIN_QTHRESHOLD
 207             > ISL38XX_CB_TX_QSIZE) {
 208                 
 209                 netif_stop_queue(ndev);
 210 
 211                 
 212                 priv->data_low_tx_full = 1;
 213         }
 214 
 215         ndev->stats.tx_packets++;
 216         ndev->stats.tx_bytes += skb->len;
 217 
 218         
 219         islpci_trigger(priv);
 220 
 221         
 222         spin_unlock_irqrestore(&priv->slock, flags);
 223 
 224         return NETDEV_TX_OK;
 225 
 226       drop_free:
 227         ndev->stats.tx_dropped++;
 228         spin_unlock_irqrestore(&priv->slock, flags);
 229         dev_kfree_skb(skb);
 230         return NETDEV_TX_OK;
 231 }
 232 
 233 static inline int
 234 islpci_monitor_rx(islpci_private *priv, struct sk_buff **skb)
 235 {
 236         
 237 
 238 
 239         struct rfmon_header *hdr = (struct rfmon_header *) (*skb)->data;
 240 
 241         if (hdr->flags & 0x01)
 242                 
 243                 return -1;
 244         if (priv->ndev->type == ARPHRD_IEEE80211_PRISM) {
 245                 struct avs_80211_1_header *avs;
 246                 
 247                 u32 clock = le32_to_cpu(hdr->clock);
 248                 u8 rate = hdr->rate;
 249                 u16 freq = le16_to_cpu(hdr->freq);
 250                 u8 rssi = hdr->rssi;
 251 
 252                 skb_pull(*skb, sizeof (struct rfmon_header));
 253 
 254                 if (skb_headroom(*skb) < sizeof (struct avs_80211_1_header)) {
 255                         struct sk_buff *newskb = skb_copy_expand(*skb,
 256                                                                  sizeof (struct
 257                                                                          avs_80211_1_header),
 258                                                                  0, GFP_ATOMIC);
 259                         if (newskb) {
 260                                 dev_kfree_skb_irq(*skb);
 261                                 *skb = newskb;
 262                         } else
 263                                 return -1;
 264                         
 265                 }
 266 
 267                 
 268                 avs = skb_push(*skb, sizeof(struct avs_80211_1_header));
 269 
 270                 avs->version = cpu_to_be32(P80211CAPTURE_VERSION);
 271                 avs->length = cpu_to_be32(sizeof (struct avs_80211_1_header));
 272                 avs->mactime = cpu_to_be64(clock);
 273                 avs->hosttime = cpu_to_be64(jiffies);
 274                 avs->phytype = cpu_to_be32(6);  
 275                 avs->channel = cpu_to_be32(channel_of_freq(freq));
 276                 avs->datarate = cpu_to_be32(rate * 5);
 277                 avs->antenna = cpu_to_be32(0);  
 278                 avs->priority = cpu_to_be32(0); 
 279                 avs->ssi_type = cpu_to_be32(3); 
 280                 avs->ssi_signal = cpu_to_be32(rssi & 0x7f);
 281                 avs->ssi_noise = cpu_to_be32(priv->local_iwstatistics.qual.noise);      
 282                 avs->preamble = cpu_to_be32(0); 
 283                 avs->encoding = cpu_to_be32(0); 
 284         } else
 285                 skb_pull(*skb, sizeof (struct rfmon_header));
 286 
 287         (*skb)->protocol = htons(ETH_P_802_2);
 288         skb_reset_mac_header(*skb);
 289         (*skb)->pkt_type = PACKET_OTHERHOST;
 290 
 291         return 0;
 292 }
 293 
 294 int
 295 islpci_eth_receive(islpci_private *priv)
 296 {
 297         struct net_device *ndev = priv->ndev;
 298         isl38xx_control_block *control_block = priv->control_block;
 299         struct sk_buff *skb;
 300         u16 size;
 301         u32 index, offset;
 302         unsigned char *src;
 303         int discard = 0;
 304 
 305 #if VERBOSE > SHOW_ERROR_MESSAGES
 306         DEBUG(SHOW_FUNCTION_CALLS, "islpci_eth_receive\n");
 307 #endif
 308 
 309         
 310 
 311         index = priv->free_data_rx % ISL38XX_CB_RX_QSIZE;
 312         size = le16_to_cpu(control_block->rx_data_low[index].size);
 313         skb = priv->data_low_rx[index];
 314         offset = ((unsigned long)
 315                   le32_to_cpu(control_block->rx_data_low[index].address) -
 316                   (unsigned long) skb->data) & 3;
 317 
 318 #if VERBOSE > SHOW_ERROR_MESSAGES
 319         DEBUG(SHOW_TRACING,
 320               "frq->addr %x skb->data %p skb->len %u offset %u truesize %u\n",
 321               control_block->rx_data_low[priv->free_data_rx].address, skb->data,
 322               skb->len, offset, skb->truesize);
 323 #endif
 324 
 325         
 326         pci_unmap_single(priv->pdev,
 327                          priv->pci_map_rx_address[index],
 328                          MAX_FRAGMENT_SIZE_RX + 2, PCI_DMA_FROMDEVICE);
 329 
 330         
 331         skb_put(skb, size);
 332         if (offset) {
 333                 
 334                 skb_pull(skb, 2);
 335                 skb_put(skb, 2);
 336         }
 337 #if VERBOSE > SHOW_ERROR_MESSAGES
 338         
 339         DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
 340         display_buffer((char *) skb->data, skb->len);
 341 #endif
 342 
 343         
 344 
 345         if (init_wds) {
 346                 
 347                 src = skb->data + 6;
 348                 memmove(skb->data, src, skb->len - 6);
 349                 skb_trim(skb, skb->len - 6);
 350         }
 351 #if VERBOSE > SHOW_ERROR_MESSAGES
 352         DEBUG(SHOW_TRACING, "Fragment size %i in skb at %p\n", size, skb);
 353         DEBUG(SHOW_TRACING, "Skb data at %p, length %i\n", skb->data, skb->len);
 354 
 355         
 356         DEBUG(SHOW_BUFFER_CONTENTS, "\nrx %p ", skb->data);
 357         display_buffer((char *) skb->data, skb->len);
 358 #endif
 359         
 360         if (unlikely(priv->iw_mode == IW_MODE_MONITOR)) {
 361                 skb->dev = ndev;
 362                 discard = islpci_monitor_rx(priv, &skb);
 363         } else {
 364                 if (unlikely(skb->data[2 * ETH_ALEN] == 0)) {
 365                         
 366 
 367 
 368                         struct iw_quality wstats;
 369                         struct rx_annex_header *annex =
 370                             (struct rx_annex_header *) skb->data;
 371                         wstats.level = annex->rfmon.rssi;
 372                         
 373 
 374                         wstats.noise = priv->local_iwstatistics.qual.noise;
 375                         wstats.qual = wstats.level - wstats.noise;
 376                         wstats.updated = 0x07;
 377                         
 378                         wireless_spy_update(ndev, annex->addr2, &wstats);
 379 
 380                         skb_copy_from_linear_data(skb,
 381                                                   (skb->data +
 382                                                    sizeof(struct rfmon_header)),
 383                                                   2 * ETH_ALEN);
 384                         skb_pull(skb, sizeof (struct rfmon_header));
 385                 }
 386                 skb->protocol = eth_type_trans(skb, ndev);
 387         }
 388         skb->ip_summed = CHECKSUM_NONE;
 389         ndev->stats.rx_packets++;
 390         ndev->stats.rx_bytes += size;
 391 
 392         
 393 #ifdef ISLPCI_ETH_DEBUG
 394         printk
 395             ("islpci_eth_receive:netif_rx %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n",
 396              skb->data[0], skb->data[1], skb->data[2], skb->data[3],
 397              skb->data[4], skb->data[5]);
 398 #endif
 399         if (unlikely(discard)) {
 400                 dev_kfree_skb_irq(skb);
 401                 skb = NULL;
 402         } else
 403                 netif_rx(skb);
 404 
 405         
 406         priv->free_data_rx++;
 407 
 408         
 409         while (index =
 410                le32_to_cpu(control_block->
 411                            driver_curr_frag[ISL38XX_CB_RX_DATA_LQ]),
 412                index - priv->free_data_rx < ISL38XX_CB_RX_QSIZE) {
 413                 
 414 
 415                 skb = dev_alloc_skb(MAX_FRAGMENT_SIZE_RX + 2);
 416                 if (unlikely(skb == NULL)) {
 417                         
 418                         DEBUG(SHOW_ERROR_MESSAGES, "Error allocating skb\n");
 419                         break;
 420                 }
 421                 skb_reserve(skb, (4 - (long) skb->data) & 0x03);
 422                 
 423                 index = index % ISL38XX_CB_RX_QSIZE;
 424                 priv->data_low_rx[index] = skb;
 425 
 426 #if VERBOSE > SHOW_ERROR_MESSAGES
 427                 DEBUG(SHOW_TRACING,
 428                       "new alloc skb %p skb->data %p skb->len %u index %u truesize %u\n",
 429                       skb, skb->data, skb->len, index, skb->truesize);
 430 #endif
 431 
 432                 
 433                 priv->pci_map_rx_address[index] =
 434                     pci_map_single(priv->pdev, (void *) skb->data,
 435                                    MAX_FRAGMENT_SIZE_RX + 2,
 436                                    PCI_DMA_FROMDEVICE);
 437                 if (pci_dma_mapping_error(priv->pdev,
 438                                           priv->pci_map_rx_address[index])) {
 439                         
 440                         DEBUG(SHOW_ERROR_MESSAGES,
 441                               "Error mapping DMA address\n");
 442 
 443                         
 444                         dev_kfree_skb_irq(skb);
 445                         skb = NULL;
 446                         break;
 447                 }
 448                 
 449                 control_block->rx_data_low[index].address =
 450                         cpu_to_le32((u32)priv->pci_map_rx_address[index]);
 451                 wmb();
 452 
 453                 
 454                 le32_add_cpu(&control_block->
 455                              driver_curr_frag[ISL38XX_CB_RX_DATA_LQ], 1);
 456         }
 457 
 458         
 459         islpci_trigger(priv);
 460 
 461         return 0;
 462 }
 463 
 464 void
 465 islpci_do_reset_and_wake(struct work_struct *work)
 466 {
 467         islpci_private *priv = container_of(work, islpci_private, reset_task);
 468 
 469         islpci_reset(priv, 1);
 470         priv->reset_task_pending = 0;
 471         smp_wmb();
 472         netif_wake_queue(priv->ndev);
 473 }
 474 
 475 void
 476 islpci_eth_tx_timeout(struct net_device *ndev)
 477 {
 478         islpci_private *priv = netdev_priv(ndev);
 479 
 480         
 481         ndev->stats.tx_errors++;
 482 
 483         if (!priv->reset_task_pending) {
 484                 printk(KERN_WARNING
 485                         "%s: tx_timeout, scheduling reset", ndev->name);
 486                 netif_stop_queue(ndev);
 487                 priv->reset_task_pending = 1;
 488                 schedule_work(&priv->reset_task);
 489         } else {
 490                 printk(KERN_WARNING
 491                         "%s: tx_timeout, waiting for reset", ndev->name);
 492         }
 493 }