]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/net/sfc/falcon.c
Merge branch 'master' of master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
[karo-tx-linux.git] / drivers / net / sfc / falcon.c
index e02f1d1728aa0012b6b095fac7902a56a1b13d2d..630406e142e5c7aa799695a7006a0511f07f6098 100644 (file)
@@ -13,6 +13,8 @@
 #include <linux/pci.h>
 #include <linux/module.h>
 #include <linux/seq_file.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
 #include "net_driver.h"
 #include "bitfield.h"
 #include "efx.h"
  * struct falcon_nic_data - Falcon NIC state
  * @next_buffer_table: First available buffer table id
  * @pci_dev2: The secondary PCI device if present
+ * @i2c_data: Operations and state for I2C bit-bashing algorithm
  */
 struct falcon_nic_data {
        unsigned next_buffer_table;
        struct pci_dev *pci_dev2;
+       struct i2c_algo_bit_data i2c_data;
 };
 
 /**************************************************************************
@@ -116,17 +120,8 @@ MODULE_PARM_DESC(rx_xon_thresh_bytes, "RX fifo XON threshold");
  **************************************************************************
  */
 
-/* DMA address mask (up to 46-bit, avoiding compiler warnings)
- *
- * Note that it is possible to have a platform with 64-bit longs and
- * 32-bit DMA addresses, or vice versa.  EFX_DMA_MASK takes care of the
- * platform DMA mask.
- */
-#if BITS_PER_LONG == 64
-#define FALCON_DMA_MASK EFX_DMA_MASK(0x00003fffffffffffUL)
-#else
-#define FALCON_DMA_MASK EFX_DMA_MASK(0x00003fffffffffffULL)
-#endif
+/* DMA address mask */
+#define FALCON_DMA_MASK DMA_BIT_MASK(46)
 
 /* TX DMA length mask (13-bit) */
 #define FALCON_TX_DMA_MASK (4096 - 1)
@@ -184,39 +179,57 @@ static inline int falcon_event_present(efx_qword_t *event)
  *
  **************************************************************************
  */
-static void falcon_setsdascl(struct efx_i2c_interface *i2c)
+static void falcon_setsda(void *data, int state)
+{
+       struct efx_nic *efx = (struct efx_nic *)data;
+       efx_oword_t reg;
+
+       falcon_read(efx, &reg, GPIO_CTL_REG_KER);
+       EFX_SET_OWORD_FIELD(reg, GPIO3_OEN, !state);
+       falcon_write(efx, &reg, GPIO_CTL_REG_KER);
+}
+
+static void falcon_setscl(void *data, int state)
 {
+       struct efx_nic *efx = (struct efx_nic *)data;
        efx_oword_t reg;
 
-       falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER);
-       EFX_SET_OWORD_FIELD(reg, GPIO0_OEN, (i2c->scl ? 0 : 1));
-       EFX_SET_OWORD_FIELD(reg, GPIO3_OEN, (i2c->sda ? 0 : 1));
-       falcon_write(i2c->efx, &reg, GPIO_CTL_REG_KER);
+       falcon_read(efx, &reg, GPIO_CTL_REG_KER);
+       EFX_SET_OWORD_FIELD(reg, GPIO0_OEN, !state);
+       falcon_write(efx, &reg, GPIO_CTL_REG_KER);
 }
 
-static int falcon_getsda(struct efx_i2c_interface *i2c)
+static int falcon_getsda(void *data)
 {
+       struct efx_nic *efx = (struct efx_nic *)data;
        efx_oword_t reg;
 
-       falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER);
+       falcon_read(efx, &reg, GPIO_CTL_REG_KER);
        return EFX_OWORD_FIELD(reg, GPIO3_IN);
 }
 
-static int falcon_getscl(struct efx_i2c_interface *i2c)
+static int falcon_getscl(void *data)
 {
+       struct efx_nic *efx = (struct efx_nic *)data;
        efx_oword_t reg;
 
-       falcon_read(i2c->efx, &reg, GPIO_CTL_REG_KER);
-       return EFX_DWORD_FIELD(reg, GPIO0_IN);
+       falcon_read(efx, &reg, GPIO_CTL_REG_KER);
+       return EFX_OWORD_FIELD(reg, GPIO0_IN);
 }
 
-static struct efx_i2c_bit_operations falcon_i2c_bit_operations = {
-       .setsda         = falcon_setsdascl,
-       .setscl         = falcon_setsdascl,
+static struct i2c_algo_bit_data falcon_i2c_bit_operations = {
+       .setsda         = falcon_setsda,
+       .setscl         = falcon_setscl,
        .getsda         = falcon_getsda,
        .getscl         = falcon_getscl,
-       .udelay         = 100,
-       .mdelay         = 10,
+       .udelay         = 5,
+       /*
+        * This is the number of system clock ticks after which
+        * i2c-algo-bit gives up waiting for SCL to become high.
+        * It must be at least 2 since the first tick can happen
+        * immediately after it starts waiting.
+        */
+       .timeout        = 2,
 };
 
 /**************************************************************************
@@ -742,8 +755,10 @@ void falcon_fini_rx(struct efx_rx_queue *rx_queue)
                        continue;
                break;
        }
-       if (rc)
+       if (rc) {
                EFX_ERR(efx, "failed to flush rx queue %d\n", rx_queue->queue);
+               efx_schedule_reset(efx, RESET_TYPE_INVISIBLE);
+       }
 
        /* Remove RX descriptor ring from card */
        EFX_ZERO_OWORD(rx_desc_ptr);
@@ -1405,7 +1420,7 @@ static inline void falcon_irq_ack_a1(struct efx_nic *efx)
 static irqreturn_t falcon_fatal_interrupt(struct efx_nic *efx)
 {
        struct falcon_nic_data *nic_data = efx->nic_data;
-       efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
+       efx_oword_t *int_ker = efx->irq_status.addr;
        efx_oword_t fatal_intr;
        int error, mem_perr;
        static int n_int_errors;
@@ -1451,8 +1466,8 @@ out:
  */
 static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
 {
-       struct efx_nic *efx = (struct efx_nic *)dev_id;
-       efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
+       struct efx_nic *efx = dev_id;
+       efx_oword_t *int_ker = efx->irq_status.addr;
        struct efx_channel *channel;
        efx_dword_t reg;
        u32 queues;
@@ -1489,8 +1504,8 @@ static irqreturn_t falcon_legacy_interrupt_b0(int irq, void *dev_id)
 
 static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
 {
-       struct efx_nic *efx = (struct efx_nic *)dev_id;
-       efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
+       struct efx_nic *efx = dev_id;
+       efx_oword_t *int_ker = efx->irq_status.addr;
        struct efx_channel *channel;
        int syserr;
        int queues;
@@ -1542,9 +1557,9 @@ static irqreturn_t falcon_legacy_interrupt_a1(int irq, void *dev_id)
  */
 static irqreturn_t falcon_msi_interrupt(int irq, void *dev_id)
 {
-       struct efx_channel *channel = (struct efx_channel *)dev_id;
+       struct efx_channel *channel = dev_id;
        struct efx_nic *efx = channel->efx;
-       efx_oword_t *int_ker = (efx_oword_t *) efx->irq_status.addr;
+       efx_oword_t *int_ker = efx->irq_status.addr;
        int syserr;
 
        efx->last_irq_cpu = raw_smp_processor_id();
@@ -1941,7 +1956,7 @@ static int falcon_gmii_wait(struct efx_nic *efx)
 static void falcon_mdio_write(struct net_device *net_dev, int phy_id,
                              int addr, int value)
 {
-       struct efx_nic *efx = (struct efx_nic *)net_dev->priv;
+       struct efx_nic *efx = net_dev->priv;
        unsigned int phy_id2 = phy_id & FALCON_PHY_ID_ID_MASK;
        efx_oword_t reg;
 
@@ -2009,7 +2024,7 @@ static void falcon_mdio_write(struct net_device *net_dev, int phy_id,
  * could be read, -1 will be returned. */
 static int falcon_mdio_read(struct net_device *net_dev, int phy_id, int addr)
 {
-       struct efx_nic *efx = (struct efx_nic *)net_dev->priv;
+       struct efx_nic *efx = net_dev->priv;
        unsigned int phy_addr = phy_id & FALCON_PHY_ID_ID_MASK;
        efx_oword_t reg;
        int value = -1;
@@ -2412,15 +2427,9 @@ int falcon_probe_nic(struct efx_nic *efx)
        struct falcon_nic_data *nic_data;
        int rc;
 
-       /* Initialise I2C interface state */
-       efx->i2c.efx = efx;
-       efx->i2c.op = &falcon_i2c_bit_operations;
-       efx->i2c.sda = 1;
-       efx->i2c.scl = 1;
-
        /* Allocate storage for hardware specific data */
        nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL);
-       efx->nic_data = (void *) nic_data;
+       efx->nic_data = nic_data;
 
        /* Determine number of ports etc. */
        rc = falcon_probe_nic_variant(efx);
@@ -2468,6 +2477,18 @@ int falcon_probe_nic(struct efx_nic *efx)
        if (rc)
                goto fail5;
 
+       /* Initialise I2C adapter */
+       efx->i2c_adap.owner = THIS_MODULE;
+       efx->i2c_adap.class = I2C_CLASS_HWMON;
+       nic_data->i2c_data = falcon_i2c_bit_operations;
+       nic_data->i2c_data.data = efx;
+       efx->i2c_adap.algo_data = &nic_data->i2c_data;
+       efx->i2c_adap.dev.parent = &efx->pci_dev->dev;
+       strcpy(efx->i2c_adap.name, "SFC4000 GPIO");
+       rc = i2c_bit_add_bus(&efx->i2c_adap);
+       if (rc)
+               goto fail5;
+
        return 0;
 
  fail5:
@@ -2490,13 +2511,10 @@ int falcon_probe_nic(struct efx_nic *efx)
  */
 int falcon_init_nic(struct efx_nic *efx)
 {
-       struct falcon_nic_data *data;
        efx_oword_t temp;
        unsigned thresh;
        int rc;
 
-       data = (struct falcon_nic_data *)efx->nic_data;
-
        /* Set up the address region register. This is only needed
         * for the B0 FPGA, but since we are just pushing in the
         * reset defaults this may as well be unconditional. */
@@ -2645,6 +2663,10 @@ int falcon_init_nic(struct efx_nic *efx)
 void falcon_remove_nic(struct efx_nic *efx)
 {
        struct falcon_nic_data *nic_data = efx->nic_data;
+       int rc;
+
+       rc = i2c_del_adapter(&efx->i2c_adap);
+       BUG_ON(rc);
 
        falcon_free_buffer(efx, &efx->irq_status);