linux-cvs-patches
[Top] [All Lists]

CVS Update@linux-mips.org: linux

To: linux-cvs-patches@linux-mips.org
Subject: CVS Update@linux-mips.org: linux
From: macro@linux-mips.org
Date: Wed, 19 Jan 2005 06:17:31 +0000
Reply-to: linux-mips@linux-mips.org
Sender: linux-cvs-patches-bounce@linux-mips.org
CVSROOT:        /home/cvs
Module name:    linux
Changes by:     macro@ftp.linux-mips.org        05/01/19 06:17:24

Modified files:
        drivers/net    : saa9730.c saa9730.h 

Log message:
        Chainsaw adjustments to make it work.  Handle with care.

diff -urN linux/drivers/net/saa9730.c linux/drivers/net/saa9730.c
--- linux/drivers/net/saa9730.c 2004/12/28 07:52:36     1.17
+++ linux/drivers/net/saa9730.c 2005/01/19 06:17:24     1.18
@@ -1,6 +1,7 @@
 /*
- * Carsten Langgaard, carstenl@mips.com
- * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
+ * Copyright (C) 2000, 2005  MIPS Technologies, Inc.  All rights reserved.
+ *     Authors: Carsten Langgaard <carstenl@mips.com>
+ *              Maciej W. Rozycki <macro@mips.com>
  *
  *  This program is free software; you can distribute it and/or modify it
  *  under the terms of the GNU General Public License (Version 2) as
@@ -18,10 +19,10 @@
  * SAA9730 ethernet driver.
  *
  * Changes:
- * Angelo Dell'Aera <buffer@antifork.org> : Conversion to the new PCI API 
(pci_driver).
- *                                          Conversion to spinlocks.
- *                                          Error handling fixes.
- *                                           
+ * Angelo Dell'Aera <buffer@antifork.org> :    Conversion to the new PCI API
+ *                                             (pci_driver).
+ *                                             Conversion to spinlocks.
+ *                                             Error handling fixes.
  */
 
 #include <linux/init.h>
@@ -32,8 +33,11 @@
 #include <linux/skbuff.h>
 #include <linux/pci.h>
 #include <linux/spinlock.h>
+#include <linux/types.h>
 
 #include <asm/addrspace.h>
+#include <asm/io.h>
+
 #include <asm/mips-boards/prom.h>
 
 #include "saa9730.h"
@@ -48,7 +52,7 @@
 
 static struct pci_device_id saa9730_pci_tbl[] = {
        { PCI_VENDOR_ID_PHILIPS, PCI_DEVICE_ID_PHILIPS_SAA9730,
-          PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0UL },
        { 0, }
 };
 
@@ -57,8 +61,8 @@
 /* Non-zero only if the current card is a PCI with BIOS-set IRQ. */
 static unsigned int pci_irq_line;
 
-#define INL(a)     inl((unsigned long)a)
-#define OUTL(x,a)  outl(x,(unsigned long)a)
+#define INL(a)         readl(a)
+#define OUTL(x, a)     writel(x, a)
 
 static void evm_saa9730_enable_lan_int(struct lan_saa9730_private *lp)
 {
@@ -210,20 +214,53 @@
        }
 }
 
-static int lan_saa9730_allocate_buffers(struct pci_dev *pdev, struct 
lan_saa9730_private *lp)
+static void lan_saa9730_free_buffers(struct pci_dev *pdev,
+                                    struct lan_saa9730_private *lp)
 {
-       void *Pa;
-       unsigned int i, j, RcvBufferSize, TxmBufferSize;
+       pci_free_consistent(pdev, lp->buffer_size, lp->buffer_start,
+                           lp->dma_addr);
+}
 
-       Pa = (void *)ALIGN((unsigned long)lp->buffer_start, 
LAN_SAA9730_PACKET_SIZE);
+static int lan_saa9730_allocate_buffers(struct pci_dev *pdev,
+                                       struct lan_saa9730_private *lp)
+{
+       void *Pa;
+       unsigned int i, j, rxoffset, txoffset;
+       int ret;
 
        /* Initialize buffer space */
-       RcvBufferSize = LAN_SAA9730_PACKET_SIZE;
-       TxmBufferSize = LAN_SAA9730_PACKET_SIZE;
        lp->DmaRcvPackets = LAN_SAA9730_RCV_Q_SIZE;
        lp->DmaTxmPackets = LAN_SAA9730_TXM_Q_SIZE;
 
-       
+       /* Initialize Rx Buffer Index */
+       lp->NextRcvPacketIndex = 0;
+       lp->NextRcvBufferIndex = 0;
+
+       /* Set current buffer index & next available packet index */
+       lp->NextTxmPacketIndex = 0;
+       lp->NextTxmBufferIndex = 0;
+       lp->PendingTxmPacketIndex = 0;
+       lp->PendingTxmBufferIndex = 0;
+
+       /*
+        * Allocate all RX and TX packets in one chunk.
+        * The Rx and Tx packets must be PACKET_SIZE aligned.
+        */
+       lp->buffer_size = ((LAN_SAA9730_RCV_Q_SIZE + LAN_SAA9730_TXM_Q_SIZE) *
+                          LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS) +
+                         LAN_SAA9730_PACKET_SIZE;
+       lp->buffer_start = pci_alloc_consistent(pdev, lp->buffer_size,
+                                               &lp->dma_addr);
+       if (!lp->buffer_start) {
+               ret = -ENOMEM;
+               goto out;
+       }
+
+       Pa = (void *)ALIGN((unsigned long)lp->buffer_start,
+                          LAN_SAA9730_PACKET_SIZE);
+
+       rxoffset = Pa - lp->buffer_start;
+
        /* Init RX buffers */
        for (i = 0; i < LAN_SAA9730_BUFFERS; i++) {
                for (j = 0; j < LAN_SAA9730_RCV_Q_SIZE; j++) {
@@ -231,10 +268,12 @@
                            cpu_to_le32(RXSF_READY <<
                                        RX_STAT_CTL_OWNER_SHF);
                        lp->RcvBuffer[i][j] = Pa;
-                       Pa += RcvBufferSize;
+                       Pa += LAN_SAA9730_PACKET_SIZE;
                }
        }
 
+       txoffset = Pa - lp->buffer_start;
+
        /* Init TX buffers */
        for (i = 0; i < LAN_SAA9730_BUFFERS; i++) {
                for (j = 0; j < LAN_SAA9730_TXM_Q_SIZE; j++) {
@@ -242,33 +281,29 @@
                            cpu_to_le32(TXSF_EMPTY <<
                                        TX_STAT_CTL_OWNER_SHF);
                        lp->TxmBuffer[i][j] = Pa;
-                       Pa += TxmBufferSize;
+                       Pa += LAN_SAA9730_PACKET_SIZE;
                }
        }
 
-       /* 
-        * Set rx buffer A and rx buffer B to point to the first two buffer 
+       /*
+        * Set rx buffer A and rx buffer B to point to the first two buffer
         * spaces.
         */
-       OUTL(lp->dma_addr + (lp->RcvBuffer[0][0] - (void *)lp), 
&lp->lan_saa9730_regs->RxBuffA);
-       OUTL(lp->dma_addr + (lp->RcvBuffer[1][0] - (void *)lp), 
&lp->lan_saa9730_regs->RxBuffB);
-
-       /* Initialize Buffer Index */
-       lp->NextRcvPacketIndex = 0;
-       lp->NextRcvToUseIsA = 1;
-
-       /* Set current buffer index & next available packet index */
-       lp->NextTxmPacketIndex = 0;
-       lp->NextTxmBufferIndex = 0;
-       lp->PendingTxmPacketIndex = 0;
-       lp->PendingTxmBufferIndex = 0;
+       OUTL(lp->dma_addr + rxoffset,
+            &lp->lan_saa9730_regs->RxBuffA);
+       OUTL(lp->dma_addr + rxoffset +
+            LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_RCV_Q_SIZE,
+            &lp->lan_saa9730_regs->RxBuffB);
 
-       /* 
+       /*
         * Set txm_buf_a and txm_buf_b to point to the first two buffer
-        * space 
+        * space
         */
-       OUTL(lp->dma_addr + (lp->TxmBuffer[0][0] - (void *)lp), 
&lp->lan_saa9730_regs->TxBuffA);
-       OUTL(lp->dma_addr + (lp->TxmBuffer[1][0] - (void *)lp), 
&lp->lan_saa9730_regs->TxBuffB);
+       OUTL(lp->dma_addr + txoffset,
+            &lp->lan_saa9730_regs->TxBuffA);
+       OUTL(lp->dma_addr + txoffset +
+            LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_TXM_Q_SIZE,
+            &lp->lan_saa9730_regs->TxBuffB);
 
        /* Set packet number */
        OUTL((lp->DmaRcvPackets << PK_COUNT_RX_A_SHF) |
@@ -278,6 +313,9 @@
             &lp->lan_saa9730_regs->PacketCount);
 
        return 0;
+
+out:
+       return ret;
 }
 
 static int lan_saa9730_cam_load(struct lan_saa9730_private *lp)
@@ -440,9 +478,9 @@
        OUTL(CAM_CONTROL_COMP_EN | CAM_CONTROL_BROAD_ACC,
             &lp->lan_saa9730_regs->CamCtl);
 
-       /* 
+       /*
         * Initialize CAM enable register, only turn on first entry, should
-        * contain own addr. 
+        * contain own addr.
         */
        OUTL(0x0001, &lp->lan_saa9730_regs->CamEnable);
 
@@ -472,7 +510,7 @@
        OUTL(INL(&lp->lan_saa9730_regs->MacCtl) | MAC_CONTROL_RESET,
             &lp->lan_saa9730_regs->MacCtl);
 
-       /* 
+       /*
         * Wait for MAC reset to have finished. The reset bit is auto cleared
         * when the reset is done.
         */
@@ -507,9 +545,9 @@
 
        /* Initialize Rx Buffer Index */
        lp->NextRcvPacketIndex = 0;
-       lp->NextRcvToUseIsA = 1;
+       lp->NextRcvBufferIndex = 0;
 
-       /* Set current buffer index & next availble packet index */
+       /* Set current buffer index & next available packet index */
        lp->NextTxmPacketIndex = 0;
        lp->NextTxmBufferIndex = 0;
        lp->PendingTxmPacketIndex = 0;
@@ -526,9 +564,8 @@
        OUTL(INL(&lp->lan_saa9730_regs->RxCtl) | RX_CTL_RX_EN,
             &lp->lan_saa9730_regs->RxCtl);
 
-       /* Set Ok2Use to let hardware owns the buffers */
-       OUTL(OK2USE_RX_A | OK2USE_RX_B | OK2USE_TX_A | OK2USE_TX_B,
-            &lp->lan_saa9730_regs->Ok2Use);
+       /* Set Ok2Use to let hardware own the buffers.  */
+       OUTL(OK2USE_RX_A | OK2USE_RX_B, &lp->lan_saa9730_regs->Ok2Use);
 
        return 0;
 }
@@ -554,10 +591,8 @@
        OUTL(DMA_STATUS_MAC_TX_INT, &lp->lan_saa9730_regs->DmaStatus);
 
        while (1) {
-               pPacket =
-                   (unsigned int *) lp->TxmBuffer[lp->
-                                                  PendingTxmBufferIndex]
-                   [lp->PendingTxmPacketIndex];
+               pPacket = lp->TxmBuffer[lp->PendingTxmBufferIndex]
+                                      [lp->PendingTxmPacketIndex];
 
                /* Get status of first packet transmitted. */
                tx_status = le32_to_cpu(*pPacket);
@@ -575,23 +610,22 @@
                        lp->stats.tx_errors++;
                        if (tx_status &
                            (TX_STATUS_EX_COLL << TX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.tx_aborted_errors++;
+                               lp->stats.tx_aborted_errors++;
                        if (tx_status &
-                           (TX_STATUS_LATE_COLL <<
-                            TX_STAT_CTL_STATUS_SHF)) lp->stats.
-            tx_window_errors++;
+                           (TX_STATUS_LATE_COLL << TX_STAT_CTL_STATUS_SHF))
+                               lp->stats.tx_window_errors++;
                        if (tx_status &
                            (TX_STATUS_L_CARR << TX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.tx_carrier_errors++;
+                               lp->stats.tx_carrier_errors++;
                        if (tx_status &
                            (TX_STATUS_UNDER << TX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.tx_fifo_errors++;
+                               lp->stats.tx_fifo_errors++;
                        if (tx_status &
                            (TX_STATUS_SQ_ERR << TX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.tx_heartbeat_errors++;
+                               lp->stats.tx_heartbeat_errors++;
 
                        lp->stats.collisions +=
-                           tx_status & TX_STATUS_TX_COLL_MSK;
+                               tx_status & TX_STATUS_TX_COLL_MSK;
                }
 
                /* Free buffer. */
@@ -606,13 +640,8 @@
                }
        }
 
-       /* Make sure A and B are available to hardware. */
-       OUTL(OK2USE_TX_A | OK2USE_TX_B, &lp->lan_saa9730_regs->Ok2Use);
-
-       if (netif_queue_stopped(dev)) {
-               /* The tx buffer is no longer full. */
-               netif_wake_queue(dev);
-       }
+       /* The tx buffer is no longer full. */
+       netif_wake_queue(dev);
 
        return 0;
 }
@@ -636,12 +665,9 @@
             DMA_STATUS_RX_TO_INT, &lp->lan_saa9730_regs->DmaStatus);
 
        /* Address next packet */
-       if (lp->NextRcvToUseIsA)
-               BufferIndex = 0;
-       else
-               BufferIndex = 1;
+       BufferIndex = lp->NextRcvBufferIndex;
        PacketIndex = lp->NextRcvPacketIndex;
-       pPacket = (unsigned int *) lp->RcvBuffer[BufferIndex][PacketIndex];
+       pPacket = lp->RcvBuffer[BufferIndex][PacketIndex];
        rx_status = le32_to_cpu(*pPacket);
 
        /* Process each packet. */
@@ -684,51 +710,39 @@
                        lp->stats.rx_errors++;
                        if (rx_status &
                            (RX_STATUS_CRC_ERR << RX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.rx_crc_errors++;
+                               lp->stats.rx_crc_errors++;
                        if (rx_status &
-                           (RX_STATUS_ALIGN_ERR <<
-                            RX_STAT_CTL_STATUS_SHF)) lp->stats.
-            rx_frame_errors++;
+                           (RX_STATUS_ALIGN_ERR << RX_STAT_CTL_STATUS_SHF))
+                               lp->stats.rx_frame_errors++;
                        if (rx_status &
                            (RX_STATUS_OVERFLOW << RX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.rx_fifo_errors++;
+                               lp->stats.rx_fifo_errors++;
                        if (rx_status &
                            (RX_STATUS_LONG_ERR << RX_STAT_CTL_STATUS_SHF))
-                                   lp->stats.rx_length_errors++;
+                               lp->stats.rx_length_errors++;
                }
 
                /* Indicate we have processed the buffer. */
-               *pPacket =
-                   cpu_to_le32(RXSF_READY << RX_STAT_CTL_OWNER_SHF);
+               *pPacket = cpu_to_le32(RXSF_READY << RX_STAT_CTL_OWNER_SHF);
+
+               /* Make sure A or B is available to hardware as appropriate. */
+               OUTL(BufferIndex ? OK2USE_RX_B : OK2USE_RX_A,
+                    &lp->lan_saa9730_regs->Ok2Use);
 
                /* Go to next packet in sequence. */
                lp->NextRcvPacketIndex++;
                if (lp->NextRcvPacketIndex >= LAN_SAA9730_RCV_Q_SIZE) {
                        lp->NextRcvPacketIndex = 0;
-                       if (BufferIndex) {
-                               lp->NextRcvToUseIsA = 1;
-                       } else {
-                               lp->NextRcvToUseIsA = 0;
-                       }
+                       lp->NextRcvBufferIndex ^= 1;
                }
-               OUTL(OK2USE_RX_A | OK2USE_RX_B,
-                    &lp->lan_saa9730_regs->Ok2Use);
 
                /* Address next packet */
-               if (lp->NextRcvToUseIsA)
-                       BufferIndex = 0;
-               else
-                       BufferIndex = 1;
+               BufferIndex = lp->NextRcvBufferIndex;
                PacketIndex = lp->NextRcvPacketIndex;
-               pPacket =
-                   (unsigned int *) lp->
-                   RcvBuffer[BufferIndex][PacketIndex];
+               pPacket = lp->RcvBuffer[BufferIndex][PacketIndex];
                rx_status = le32_to_cpu(*pPacket);
        }
 
-       /* Make sure A and B are available to hardware. */
-       OUTL(OK2USE_RX_A | OK2USE_RX_B, &lp->lan_saa9730_regs->Ok2Use);
-
        return 0;
 }
 
@@ -762,11 +776,6 @@
        return IRQ_HANDLED;
 }
 
-static int lan_saa9730_open_fail(struct net_device *dev)
-{
-       return -ENODEV;
-}
-
 static int lan_saa9730_open(struct net_device *dev)
 {
        struct lan_saa9730_private *lp = netdev_priv(dev);
@@ -806,9 +815,8 @@
        BufferIndex = lp->NextTxmBufferIndex;
        PacketIndex = lp->NextTxmPacketIndex;
 
-       tx_status =
-           le32_to_cpu(*(unsigned int *) lp->
-                       TxmBuffer[BufferIndex][PacketIndex]);
+       tx_status = le32_to_cpu(*(unsigned int *)lp->TxmBuffer[BufferIndex]
+                                                             [PacketIndex]);
        if ((tx_status & TX_STAT_CTL_OWNER_MSK) !=

[%d lines skipped]
285diff -urN linux/drivers/net/saa9730.h linux/drivers/net/saa9730.h
--- linux/drivers/net/saa9730.h 2003/11/15 10:46:56     1.4
+++ linux/drivers/net/saa9730.h 2005/01/19 06:17:24     1.5
@@ -1,6 +1,7 @@
 /*
- * Carsten Langgaard, carstenl@mips.com
- * Copyright (C) 2000 MIPS Technologies, Inc.  All rights reserved.
+ * Copyright (C) 2000, 2005  MIPS Technologies, Inc.  All rights reserved.
+ *     Authors: Carsten Langgaard <carstenl@mips.com>
+ *              Maciej W. Rozycki <macro@mips.com>
  *
  * ########################################################################
  *
@@ -265,6 +266,7 @@
 
 /* The SAA9730 (LAN) controller register map, as seen via the PCI-bus. */
 #define SAA9730_LAN_REGS_ADDR   0x20400
+#define SAA9730_LAN_REGS_SIZE   0x00400
 
 struct lan_saa9730_regmap {
        volatile unsigned int TxBuffA;                  /* 0x20400 */
@@ -309,6 +311,7 @@
 
 /* The SAA9730 (EVM) controller register map, as seen via the PCI-bus. */
 #define SAA9730_EVM_REGS_ADDR   0x02000
+#define SAA9730_EVM_REGS_SIZE   0x00400
 
 struct evm_saa9730_regmap {
        volatile unsigned int InterruptStatus1;         /* 0x2000 */
@@ -329,12 +332,17 @@
 
 
 struct lan_saa9730_private {
-       /* Rx/Tx packet buffers. The Rx and Tx packets must be PACKET_SIZE 
aligned. */
-       char    buffer_start[(LAN_SAA9730_RCV_Q_SIZE + LAN_SAA9730_TXM_Q_SIZE)
-                            * LAN_SAA9730_PACKET_SIZE * LAN_SAA9730_BUFFERS
-                            + LAN_SAA9730_PACKET_SIZE - 1];
-
-       /* DMA address of beginning of this object, returned by 
pci_alloc_consistent */
+       /*
+        * Rx/Tx packet buffers.
+        * The Rx and Tx packets must be PACKET_SIZE aligned.
+        */
+       void            *buffer_start;
+       unsigned int    buffer_size;
+
+       /*
+        * DMA address of beginning of this object, returned
+        * by pci_alloc_consistent().
+        */
        dma_addr_t      dma_addr;
 
        /* Pointer to the associated pci device structure */
@@ -346,10 +354,10 @@
        /* Pointer to the SAA9730 EVM register. */
        t_evm_saa9730_regmap *evm_saa9730_regs;
 
-       /* TRUE if the next buffer to write is RxBuffA,  FALSE if RxBuffB. */
-       unsigned char NextRcvToUseIsA;
        /* Rcv buffer Index. */
        unsigned char NextRcvPacketIndex;
+       /* Next buffer index. */
+       unsigned char NextRcvBufferIndex;
 
        /* Index of next packet to use in that buffer. */
        unsigned char NextTxmPacketIndex;
@@ -364,9 +372,6 @@
        unsigned char DmaRcvPackets;
        unsigned char DmaTxmPackets;
 
-       unsigned char RcvAIndex;        /* index into RcvBufferSpace[] for Blk 
A */
-       unsigned char RcvBIndex;        /* index into RcvBufferSpace[] for Blk 
B */
-
        void          *TxmBuffer[LAN_SAA9730_BUFFERS][LAN_SAA9730_TXM_Q_SIZE];
        void          *RcvBuffer[LAN_SAA9730_BUFFERS][LAN_SAA9730_RCV_Q_SIZE];
        unsigned int TxBufferFree[LAN_SAA9730_BUFFERS];

<Prev in Thread] Current Thread [Next in Thread>