Netdev List
 help / color / mirror / Atom feed
* [PATCH v2 7/8] i2c-pnx.c: Remove duplicated i2c.h
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

The platforms using i2c-pnx.c both defined a duplicated i2c.h (used nowhere
else). This patch removes those and integrates the contents into the driver
itself.

Signed-off-by: Roland Stigge <stigge@antcom.de>

---

 Applies to v3.4-rc1

 arch/arm/mach-lpc32xx/include/mach/i2c.h |   63 ------------------------------
 arch/arm/mach-pnx4008/include/mach/i2c.h |   64 -------------------------------
 drivers/i2c/busses/i2c-pnx.c             |   49 ++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 130 deletions(-)

--- linux-2.6.orig/arch/arm/mach-lpc32xx/include/mach/i2c.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * PNX4008-specific tweaks for I2C IP3204 block
- *
- * Author: Vitaly Wool <vwool@ru.mvista.com>
- *
- * 2005 (c) MontaVista Software, Inc. This file is licensed under
- * the terms of the GNU General Public License version 2. This program
- * is licensed "as is" without any warranty of any kind, whether express
- * or implied.
- */
-
-#ifndef __ASM_ARCH_I2C_H
-#define __ASM_ARCH_I2C_H
-
-enum {
-	mstatus_tdi = 0x00000001,
-	mstatus_afi = 0x00000002,
-	mstatus_nai = 0x00000004,
-	mstatus_drmi = 0x00000008,
-	mstatus_active = 0x00000020,
-	mstatus_scl = 0x00000040,
-	mstatus_sda = 0x00000080,
-	mstatus_rff = 0x00000100,
-	mstatus_rfe = 0x00000200,
-	mstatus_tff = 0x00000400,
-	mstatus_tfe = 0x00000800,
-};
-
-enum {
-	mcntrl_tdie = 0x00000001,
-	mcntrl_afie = 0x00000002,
-	mcntrl_naie = 0x00000004,
-	mcntrl_drmie = 0x00000008,
-	mcntrl_daie = 0x00000020,
-	mcntrl_rffie = 0x00000040,
-	mcntrl_tffie = 0x00000080,
-	mcntrl_reset = 0x00000100,
-	mcntrl_cdbmode = 0x00000400,
-};
-
-enum {
-	rw_bit = 1 << 0,
-	start_bit = 1 << 8,
-	stop_bit = 1 << 9,
-};
-
-#define I2C_REG_RX(a)	((a)->ioaddr)		/* Rx FIFO reg (RO) */
-#define I2C_REG_TX(a)	((a)->ioaddr)		/* Tx FIFO reg (WO) */
-#define I2C_REG_STS(a)	((a)->ioaddr + 0x04)	/* Status reg (RO) */
-#define I2C_REG_CTL(a)	((a)->ioaddr + 0x08)	/* Ctl reg */
-#define I2C_REG_CKL(a)	((a)->ioaddr + 0x0c)	/* Clock divider low */
-#define I2C_REG_CKH(a)	((a)->ioaddr + 0x10)	/* Clock divider high */
-#define I2C_REG_ADR(a)	((a)->ioaddr + 0x14)	/* I2C address */
-#define I2C_REG_RFL(a)	((a)->ioaddr + 0x18)	/* Rx FIFO level (RO) */
-#define I2C_REG_TFL(a)	((a)->ioaddr + 0x1c)	/* Tx FIFO level (RO) */
-#define I2C_REG_RXB(a)	((a)->ioaddr + 0x20)	/* Num of bytes Rx-ed (RO) */
-#define I2C_REG_TXB(a)	((a)->ioaddr + 0x24)	/* Num of bytes Tx-ed (RO) */
-#define I2C_REG_TXS(a)	((a)->ioaddr + 0x28)	/* Tx slave FIFO (RO) */
-#define I2C_REG_STFL(a)	((a)->ioaddr + 0x2c)	/* Tx slave FIFO level (RO) */
-
-#define I2C_CHIP_NAME		"PNX4008-I2C"
-
-#endif				/* __ASM_ARCH_I2C_H */
--- linux-2.6.orig/arch/arm/mach-pnx4008/include/mach/i2c.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * PNX4008-specific tweaks for I2C IP3204 block
- *
- * Author: Vitaly Wool <vwool@ru.mvista.com>
- *
- * 2005 (c) MontaVista Software, Inc. This file is licensed under
- * the terms of the GNU General Public License version 2. This program
- * is licensed "as is" without any warranty of any kind, whether express
- * or implied.
- */
-
-#ifndef __ASM_ARCH_I2C_H__
-#define __ASM_ARCH_I2C_H__
-
-enum {
-	mstatus_tdi = 0x00000001,
-	mstatus_afi = 0x00000002,
-	mstatus_nai = 0x00000004,
-	mstatus_drmi = 0x00000008,
-	mstatus_active = 0x00000020,
-	mstatus_scl = 0x00000040,
-	mstatus_sda = 0x00000080,
-	mstatus_rff = 0x00000100,
-	mstatus_rfe = 0x00000200,
-	mstatus_tff = 0x00000400,
-	mstatus_tfe = 0x00000800,
-};
-
-enum {
-	mcntrl_tdie = 0x00000001,
-	mcntrl_afie = 0x00000002,
-	mcntrl_naie = 0x00000004,
-	mcntrl_drmie = 0x00000008,
-	mcntrl_daie = 0x00000020,
-	mcntrl_rffie = 0x00000040,
-	mcntrl_tffie = 0x00000080,
-	mcntrl_reset = 0x00000100,
-	mcntrl_cdbmode = 0x00000400,
-};
-
-enum {
-	rw_bit = 1 << 0,
-	start_bit = 1 << 8,
-	stop_bit = 1 << 9,
-};
-
-#define I2C_REG_RX(a)	((a)->ioaddr)		/* Rx FIFO reg (RO) */
-#define I2C_REG_TX(a)	((a)->ioaddr)		/* Tx FIFO reg (WO) */
-#define I2C_REG_STS(a)	((a)->ioaddr + 0x04)	/* Status reg (RO) */
-#define I2C_REG_CTL(a)	((a)->ioaddr + 0x08)	/* Ctl reg */
-#define I2C_REG_CKL(a)	((a)->ioaddr + 0x0c)	/* Clock divider low */
-#define I2C_REG_CKH(a)	((a)->ioaddr + 0x10)	/* Clock divider high */
-#define I2C_REG_ADR(a)	((a)->ioaddr + 0x14)	/* I2C address */
-#define I2C_REG_RFL(a)	((a)->ioaddr + 0x18)	/* Rx FIFO level (RO) */
-#define I2C_REG_TFL(a)	((a)->ioaddr + 0x1c)	/* Tx FIFO level (RO) */
-#define I2C_REG_RXB(a)	((a)->ioaddr + 0x20)	/* Num of bytes Rx-ed (RO) */
-#define I2C_REG_TXB(a)	((a)->ioaddr + 0x24)	/* Num of bytes Tx-ed (RO) */
-#define I2C_REG_TXS(a)	((a)->ioaddr + 0x28)	/* Tx slave FIFO (RO) */
-#define I2C_REG_STFL(a)	((a)->ioaddr + 0x2c)	/* Tx slave FIFO level (RO) */
-
-#define HCLK_MHZ		13
-#define I2C_CHIP_NAME		"PNX4008-I2C"
-
-#endif				/* __ASM_ARCH_I2C_H___ */
--- linux-2.6.orig/drivers/i2c/busses/i2c-pnx.c
+++ linux-2.6/drivers/i2c/busses/i2c-pnx.c
@@ -24,13 +24,56 @@
 #include <linux/clk.h>
 #include <linux/slab.h>
 
-#include <mach/hardware.h>
-#include <mach/i2c.h>
-
 #define I2C_PNX_TIMEOUT		10 /* msec */
 #define I2C_PNX_SPEED_KHZ	100
 #define I2C_PNX_REGION_SIZE	0x100
 
+enum {
+	mstatus_tdi = 0x00000001,
+	mstatus_afi = 0x00000002,
+	mstatus_nai = 0x00000004,
+	mstatus_drmi = 0x00000008,
+	mstatus_active = 0x00000020,
+	mstatus_scl = 0x00000040,
+	mstatus_sda = 0x00000080,
+	mstatus_rff = 0x00000100,
+	mstatus_rfe = 0x00000200,
+	mstatus_tff = 0x00000400,
+	mstatus_tfe = 0x00000800,
+};
+
+enum {
+	mcntrl_tdie = 0x00000001,
+	mcntrl_afie = 0x00000002,
+	mcntrl_naie = 0x00000004,
+	mcntrl_drmie = 0x00000008,
+	mcntrl_daie = 0x00000020,
+	mcntrl_rffie = 0x00000040,
+	mcntrl_tffie = 0x00000080,
+	mcntrl_reset = 0x00000100,
+	mcntrl_cdbmode = 0x00000400,
+};
+
+enum {
+	rw_bit = 1 << 0,
+	start_bit = 1 << 8,
+	stop_bit = 1 << 9,
+};
+
+#define I2C_REG_RX(a)	((a)->ioaddr)		/* Rx FIFO reg (RO) */
+#define I2C_REG_TX(a)	((a)->ioaddr)		/* Tx FIFO reg (WO) */
+#define I2C_REG_STS(a)	((a)->ioaddr + 0x04)	/* Status reg (RO) */
+#define I2C_REG_CTL(a)	((a)->ioaddr + 0x08)	/* Ctl reg */
+#define I2C_REG_CKL(a)	((a)->ioaddr + 0x0c)	/* Clock divider low */
+#define I2C_REG_CKH(a)	((a)->ioaddr + 0x10)	/* Clock divider high */
+#define I2C_REG_ADR(a)	((a)->ioaddr + 0x14)	/* I2C address */
+#define I2C_REG_RFL(a)	((a)->ioaddr + 0x18)	/* Rx FIFO level (RO) */
+#define I2C_REG_TFL(a)	((a)->ioaddr + 0x1c)	/* Tx FIFO level (RO) */
+#define I2C_REG_RXB(a)	((a)->ioaddr + 0x20)	/* Num of bytes Rx-ed (RO) */
+#define I2C_REG_TXB(a)	((a)->ioaddr + 0x24)	/* Num of bytes Tx-ed (RO) */
+#define I2C_REG_TXS(a)	((a)->ioaddr + 0x28)	/* Tx slave FIFO (RO) */
+#define I2C_REG_STFL(a)	((a)->ioaddr + 0x2c)	/* Tx slave FIFO level (RO) */
+
 static inline int wait_timeout(long timeout, struct i2c_pnx_algo_data *data)
 {
 	while (timeout > 0 &&

^ permalink raw reply

* [PATCH v2 6/8] i2c-pnx.c: Use resources in platforms
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

As a precondition for device tree conversion, the platforms using i2c-pnx.c are
converted to using mem and irq resources instead of platform data.

Signed-off-by: Roland Stigge <stigge@antcom.de>

---

 Applies to v3.4-rc1

 arch/arm/mach-lpc32xx/common.c |   75 +++++++++++++++++++++++++----------------
 arch/arm/mach-pnx4008/i2c.c    |   64 +++++++++++++++++++++-------------
 drivers/i2c/busses/i2c-pnx.c   |   47 +++++++++++++------------
 include/linux/i2c-pnx.h        |    9 +---
 4 files changed, 112 insertions(+), 83 deletions(-)

--- linux-2.6.orig/arch/arm/mach-lpc32xx/common.c
+++ linux-2.6/arch/arm/mach-lpc32xx/common.c
@@ -27,7 +27,6 @@
 
 #include <asm/mach/map.h>
 
-#include <mach/i2c.h>
 #include <mach/hardware.h>
 #include <mach/platform.h>
 #include "common.h"
@@ -53,46 +52,64 @@ struct platform_device lpc32xx_watchdog_
 /*
  * I2C busses
  */
-static struct i2c_pnx_data i2c0_data = {
-	.name = I2C_CHIP_NAME "1",
-	.base = LPC32XX_I2C1_BASE,
-	.irq = IRQ_LPC32XX_I2C_1,
-};
-
-static struct i2c_pnx_data i2c1_data = {
-	.name = I2C_CHIP_NAME "2",
-	.base = LPC32XX_I2C2_BASE,
-	.irq = IRQ_LPC32XX_I2C_2,
-};
-
-static struct i2c_pnx_data i2c2_data = {
-	.name = "USB-I2C",
-	.base = LPC32XX_OTG_I2C_BASE,
-	.irq = IRQ_LPC32XX_USB_I2C,
+static struct resource i2c0_resources[] = {
+	[0] = {
+		.start = LPC32XX_I2C1_BASE,
+		.end = LPC32XX_I2C1_BASE + 0x100 - 1,
+		.flags = IORESOURCE_MEM,
+	},
+	[1] = {
+		.start = IRQ_LPC32XX_I2C_1,
+		.end = IRQ_LPC32XX_I2C_1,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct resource i2c1_resources[] = {
+	[0] = {
+		.start = LPC32XX_I2C2_BASE,
+		.end = LPC32XX_I2C2_BASE + 0x100 - 1,
+		.flags = IORESOURCE_MEM,
+	},
+	[1] = {
+		.start = IRQ_LPC32XX_I2C_2,
+		.end = IRQ_LPC32XX_I2C_2,
+		.flags = IORESOURCE_IRQ,
+	},
+};
+
+static struct resource i2c2_resources[] = {
+	[0] = {
+		.start = LPC32XX_OTG_I2C_BASE,
+		.end = LPC32XX_OTG_I2C_BASE + 0x100 - 1,
+		.flags = IORESOURCE_MEM,
+	},
+	[1] = {
+		.start = IRQ_LPC32XX_USB_I2C,
+		.end = IRQ_LPC32XX_USB_I2C,
+		.flags = IORESOURCE_IRQ,
+	},
 };
 
 struct platform_device lpc32xx_i2c0_device = {
-	.name = "pnx-i2c",
+	.name = "pnx-i2c.0",
 	.id = 0,
-	.dev = {
-		.platform_data = &i2c0_data,
-	},
+	.num_resources = ARRAY_SIZE(i2c0_resources),
+	.resource = i2c0_resources,
 };
 
 struct platform_device lpc32xx_i2c1_device = {
-	.name = "pnx-i2c",
+	.name = "pnx-i2c.1",
 	.id = 1,
-	.dev = {
-		.platform_data = &i2c1_data,
-	},
+	.num_resources = ARRAY_SIZE(i2c1_resources),
+	.resource = i2c1_resources,
 };
 
 struct platform_device lpc32xx_i2c2_device = {
-	.name = "pnx-i2c",
+	.name = "pnx-i2c.2",
 	.id = 2,
-	.dev = {
-		.platform_data = &i2c2_data,
-	},
+	.num_resources = ARRAY_SIZE(i2c2_resources),
+	.resource = i2c2_resources,
 };
 
 /* TSC (Touch Screen Controller) */
--- linux-2.6.orig/arch/arm/mach-pnx4008/i2c.c
+++ linux-2.6/arch/arm/mach-pnx4008/i2c.c
@@ -16,48 +16,62 @@
 #include <linux/err.h>
 #include <mach/platform.h>
 #include <mach/irqs.h>
-#include <mach/i2c.h>
 
-static struct i2c_pnx_data i2c0_data = {
-	.name = I2C_CHIP_NAME "0",
-	.base = PNX4008_I2C1_BASE,
-	.irq = I2C_1_INT,
+static struct resource i2c0_resources[] = {
+	{
+		.start = PNX4008_I2C1_BASE,
+		.end = PNX4008_I2C1_BASE + SZ_4K - 1,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.start = I2C_1_INT,
+		.end = I2C_1_INT,
+		.flags = IORESOURCE_IRQ,
+	},
 };
 
-static struct i2c_pnx_data i2c1_data = {
-	.name = I2C_CHIP_NAME "1",
-	.base = PNX4008_I2C2_BASE,
-	.irq = I2C_2_INT,
+static struct resource i2c1_resources[] = {
+	{
+		.start = PNX4008_I2C2_BASE,
+		.end = PNX4008_I2C2_BASE + SZ_4K - 1,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.start = I2C_2_INT,
+		.end = I2C_2_INT,
+		.flags = IORESOURCE_IRQ,
+	},
 };
 
-static struct i2c_pnx_data i2c2_data = {
-	.name = "USB-I2C",
-	.base = (PNX4008_USB_CONFIG_BASE + 0x300),
-	.irq = USB_I2C_INT,
+static struct resource i2c2_resources[] = {
+	{
+		.start = PNX4008_USB_CONFIG_BASE + 0x300,
+		.end = PNX4008_USB_CONFIG_BASE + 0x300 + SZ_4K - 1,
+		.flags = IORESOURCE_MEM,
+	}, {
+		.start = USB_I2C_INT,
+		.end = USB_I2C_INT,
+		.flags = IORESOURCE_IRQ,
+	},
 };
 
 static struct platform_device i2c0_device = {
-	.name = "pnx-i2c",
+	.name = "pnx-i2c.0",
 	.id = 0,
-	.dev = {
-		.platform_data = &i2c0_data,
-	},
+	.resource = i2c0_resources,
+	.num_resources = ARRAY_SIZE(i2c0_resources),
 };
 
 static struct platform_device i2c1_device = {
-	.name = "pnx-i2c",
+	.name = "pnx-i2c.1",
 	.id = 1,
-	.dev = {
-		.platform_data = &i2c1_data,
-	},
+	.resource = i2c1_resources,
+	.num_resources = ARRAY_SIZE(i2c1_resources),
 };
 
 static struct platform_device i2c2_device = {
-	.name = "pnx-i2c",
+	.name = "pnx-i2c.2",
 	.id = 2,
-	.dev = {
-		.platform_data = &i2c2_data,
-	},
+	.resource = i2c2_resources,
+	.num_resources = ARRAY_SIZE(i2c2_resources),
 };
 
 static struct platform_device *devices[] __initdata = {
--- linux-2.6.orig/drivers/i2c/busses/i2c-pnx.c
+++ linux-2.6/drivers/i2c/busses/i2c-pnx.c
@@ -568,14 +568,7 @@ static int __devinit i2c_pnx_probe(struc
 	int ret = 0;
 	struct i2c_pnx_algo_data *alg_data;
 	unsigned long freq;
-	struct i2c_pnx_data *i2c_pnx = pdev->dev.platform_data;
-
-	if (!i2c_pnx || !i2c_pnx->name) {
-		dev_err(&pdev->dev, "%s: no platform data supplied\n",
-		       __func__);
-		ret = -EINVAL;
-		goto out;
-	}
+	struct resource *res;
 
 	alg_data = kzalloc(sizeof(*alg_data), GFP_KERNEL);
 	if (!alg_data) {
@@ -585,13 +578,10 @@ static int __devinit i2c_pnx_probe(struc
 
 	platform_set_drvdata(pdev, alg_data);
 
-	strlcpy(alg_data->adapter.name, i2c_pnx->name,
-		sizeof(alg_data->adapter.name));
 	alg_data->adapter.dev.parent = &pdev->dev;
 	alg_data->adapter.algo = &pnx_algorithm;
 	alg_data->adapter.algo_data = alg_data;
 	alg_data->adapter.nr = pdev->id;
-	alg_data->i2c_pnx = i2c_pnx;
 
 	alg_data->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(alg_data->clk)) {
@@ -603,17 +593,27 @@ static int __devinit i2c_pnx_probe(struc
 	alg_data->mif.timer.function = i2c_pnx_timeout;
 	alg_data->mif.timer.data = (unsigned long)alg_data;
 
+	snprintf(alg_data->adapter.name, sizeof(alg_data->adapter.name),
+		 "%s", pdev->name);
+
 	/* Register I/O resource */
-	if (!request_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE,
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "Unable to get mem resource.\n");
+		ret = -EBUSY;
+		goto out_clkget;
+	}
+	if (!request_mem_region(res->start, I2C_PNX_REGION_SIZE,
 				pdev->name)) {
 		dev_err(&pdev->dev,
 		       "I/O region 0x%08x for I2C already in use.\n",
-		       i2c_pnx->base);
+		       res->start);
 		ret = -ENODEV;
 		goto out_clkget;
 	}
 
-	alg_data->ioaddr = ioremap(i2c_pnx->base, I2C_PNX_REGION_SIZE);
+	alg_data->base = res->start;
+	alg_data->ioaddr = ioremap(res->start, I2C_PNX_REGION_SIZE);
 	if (!alg_data->ioaddr) {
 		dev_err(&pdev->dev, "Couldn't ioremap I2C I/O region\n");
 		ret = -ENOMEM;
@@ -650,7 +650,12 @@ static int __devinit i2c_pnx_probe(struc
 	}
 	init_completion(&alg_data->mif.complete);
 
-	ret = request_irq(i2c_pnx->irq, i2c_pnx_interrupt,
+	alg_data->irq = platform_get_irq(pdev, 0);
+	if (alg_data->irq < 0) {
+		dev_err(&pdev->dev, "Failed to get IRQ from platform resource\n");
+		goto out_irq;
+	}
+	ret = request_irq(alg_data->irq, i2c_pnx_interrupt,
 			0, pdev->name, alg_data);
 	if (ret)
 		goto out_clock;
@@ -663,38 +668,36 @@ static int __devinit i2c_pnx_probe(struc
 	}
 
 	dev_dbg(&pdev->dev, "%s: Master at %#8x, irq %d.\n",
-	       alg_data->adapter.name, i2c_pnx->base, i2c_pnx->irq);
+		alg_data->adapter.name, res->start, alg_data->irq);
 
 	return 0;
 
 out_irq:
-	free_irq(i2c_pnx->irq, alg_data);
+	free_irq(alg_data->irq, alg_data);
 out_clock:
 	clk_disable(alg_data->clk);
 out_unmap:
 	iounmap(alg_data->ioaddr);
 out_release:
-	release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE);
+	release_mem_region(res->start, I2C_PNX_REGION_SIZE);
 out_clkget:
 	clk_put(alg_data->clk);
 out_drvdata:
 	kfree(alg_data);
 err_kzalloc:
 	platform_set_drvdata(pdev, NULL);
-out:
 	return ret;
 }
 
 static int __devexit i2c_pnx_remove(struct platform_device *pdev)
 {
 	struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
-	struct i2c_pnx_data *i2c_pnx = alg_data->i2c_pnx;
 
-	free_irq(i2c_pnx->irq, alg_data);
+	free_irq(alg_data->irq, alg_data);
 	i2c_del_adapter(&alg_data->adapter);
 	clk_disable(alg_data->clk);
 	iounmap(alg_data->ioaddr);
-	release_mem_region(i2c_pnx->base, I2C_PNX_REGION_SIZE);
+	release_mem_region(alg_data->base, I2C_PNX_REGION_SIZE);
 	clk_put(alg_data->clk);
 	kfree(alg_data);
 	platform_set_drvdata(pdev, NULL);
--- linux-2.6.orig/include/linux/i2c-pnx.h
+++ linux-2.6/include/linux/i2c-pnx.h
@@ -29,14 +29,9 @@ struct i2c_pnx_algo_data {
 	struct i2c_pnx_mif	mif;
 	int			last;
 	struct clk		*clk;
-	struct i2c_pnx_data	*i2c_pnx;
 	struct i2c_adapter	adapter;
-};
-
-struct i2c_pnx_data {
-	const char *name;
-	u32 base;
-	int irq;
+	phys_addr_t		base;
+	int			irq;
 };
 
 #endif /* __I2C_PNX_H__ */

^ permalink raw reply

* [PATCH v2 5/8] i2c-pnx.c: Fix suspend
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge, stable
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

In the driver's suspend function, clk_enable() was used instead of
clk_disable(). This is corrected with this patch.

Signed-off-by: Roland Stigge <stigge@antcom.de>
CC: stable@vger.kernel.org

---

 Applies to v3.4-rc1

 drivers/i2c/busses/i2c-pnx.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--- linux-2.6.orig/drivers/i2c/busses/i2c-pnx.c
+++ linux-2.6/drivers/i2c/busses/i2c-pnx.c
@@ -546,8 +546,7 @@ static int i2c_pnx_controller_suspend(st
 {
 	struct i2c_pnx_algo_data *alg_data = platform_get_drvdata(pdev);
 
-	/* FIXME: shouldn't this be clk_disable? */
-	clk_enable(alg_data->clk);
+	clk_disable(alg_data->clk);
 
 	return 0;
 }

^ permalink raw reply

* [PATCH v2 4/8] wdt: Device tree support for pnx4008-wdt
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

This patch adds watchdog support to pnx4008-wdt.c

Signed-off-by: Roland Stigge <stigge@antcom.de>

---

 Applies to v3.4-rc1

 Documentation/devicetree/bindings/watchdog/pnx4008-wdt.txt |   13 +++++++++++++
 drivers/watchdog/pnx4008_wdt.c                             |   10 ++++++++++
 2 files changed, 23 insertions(+)

--- /dev/null
+++ linux-2.6/Documentation/devicetree/bindings/watchdog/pnx4008-wdt.txt
@@ -0,0 +1,13 @@
+* NXP PNX watchdog timer
+
+Required properties:
+- compatible: must be "nxp,pnx4008-wdt"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+
+Example:
+
+	watchdog@4003C000 {
+		compatible = "nxp,pnx4008-wdt";
+		reg = <0x4003C000 0x1000>;
+	};
--- linux-2.6.orig/drivers/watchdog/pnx4008_wdt.c
+++ linux-2.6/drivers/watchdog/pnx4008_wdt.c
@@ -32,6 +32,7 @@
 #include <linux/io.h>
 #include <linux/slab.h>
 #include <linux/err.h>
+#include <linux/of.h>
 #include <mach/hardware.h>
 
 /* WatchDog Timer - Chapter 23 Page 207 */
@@ -201,10 +202,19 @@ static int __devexit pnx4008_wdt_remove(
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id pnx4008_wdt_match[] = {
+	{ .compatible = "nxp,pnx4008-wdt" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, pnx4008_wdt_match);
+#endif
+
 static struct platform_driver platform_wdt_driver = {
 	.driver = {
 		.name = "pnx4008-watchdog",
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(pnx4008_wdt_match),
 	},
 	.probe = pnx4008_wdt_probe,
 	.remove = __devexit_p(pnx4008_wdt_remove),

^ permalink raw reply

* [PATCH v2 3/8] net: Add device tree support to LPC32xx
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

This patch adds device tree support for lpc_eth.c.

The runtime option for MII/RMII is solved via the "phy-mode" property, SRAM
("IRAM") usage for DMA can be chosen via "use-iram".

Signed-off-by: Roland Stigge <stigge@antcom.de>

---

 Applies to v3.4-rc1

 Documentation/devicetree/bindings/net/lpc-eth.txt |   24 ++++++
 drivers/net/ethernet/nxp/lpc_eth.c                |   77 +++++++++++++---------
 2 files changed, 70 insertions(+), 31 deletions(-)

--- /dev/null
+++ linux-2.6/Documentation/devicetree/bindings/net/lpc-eth.txt
@@ -0,0 +1,24 @@
+* NXP LPC32xx SoC Ethernet Controller
+
+Required properties:
+- compatible: Should be "nxp,lpc-eth"
+- reg: Address and length of the register set for the device
+- interrupts: Should contain ethernet controller interrupt
+
+Optional properties:
+- phy-mode: String, operation mode of the PHY interface.
+  Supported values are: "mii" (default), "rmii"
+- use-iram: Use LPC32xx internal SRAM (IRAM) for DMA buffering
+- local-mac-address : 6 bytes, mac address
+
+Example:
+
+	mac: ethernet@31060000 {
+		compatible = "nxp,lpc-eth";
+		reg = <0x31060000 0x1000>;
+		interrupt-parent = <&mic>;
+		interrupts = <29 0>;
+
+		phy-mode = "rmii";
+		use-iram;
+	};
--- linux-2.6.orig/drivers/net/ethernet/nxp/lpc_eth.c
+++ linux-2.6/drivers/net/ethernet/nxp/lpc_eth.c
@@ -340,27 +340,15 @@
  */
 #define LPC_POWERDOWN_MACAHB			(1 << 31)
 
-/* Upon the upcoming introduction of device tree usage in LPC32xx,
- * lpc_phy_interface_mode() and use_iram_for_net() will be extended with a
- * device parameter for access to device tree information at runtime, instead
- * of defining the values at compile time
- */
-static inline phy_interface_t lpc_phy_interface_mode(void)
+static phy_interface_t lpc_phy_interface_mode(struct device *dev)
 {
-#ifdef CONFIG_ARCH_LPC32XX_MII_SUPPORT
+	if (dev && dev->of_node) {
+		const char *mode = of_get_property(dev->of_node,
+						   "phy-mode", NULL);
+		if (mode && !strcmp(mode, "rmii"))
+			return PHY_INTERFACE_MODE_RMII;
+	}
 	return PHY_INTERFACE_MODE_MII;
-#else
-	return PHY_INTERFACE_MODE_RMII;
-#endif
-}
-
-static inline int use_iram_for_net(void)
-{
-#ifdef CONFIG_ARCH_LPC32XX_IRAM_FOR_NET
-	return 1;
-#else
-	return 0;
-#endif
 }
 
 /* Receive Status information word */
@@ -450,6 +438,7 @@ struct netdata_local {
 	int			speed;
 	int			duplex;
 	struct napi_struct	napi;
+	bool			use_iram;
 };
 
 /*
@@ -664,7 +653,7 @@ static void __lpc_eth_init(struct netdat
 	       LPC_ENET_CLRT(pldat->net_base));
 	writel(LPC_IPGR_LOAD_PART2(0x12), LPC_ENET_IPGR(pldat->net_base));
 
-	if (lpc_phy_interface_mode() == PHY_INTERFACE_MODE_MII)
+	if (lpc_phy_interface_mode(&pldat->pdev->dev) == PHY_INTERFACE_MODE_MII)
 		writel(LPC_COMMAND_PASSRUNTFRAME,
 		       LPC_ENET_COMMAND(pldat->net_base));
 	else {
@@ -804,12 +793,13 @@ static int lpc_mii_probe(struct net_devi
 	}
 
 	/* Attach to the PHY */
-	if (lpc_phy_interface_mode() == PHY_INTERFACE_MODE_MII)
+	if (lpc_phy_interface_mode(&pldat->pdev->dev) == PHY_INTERFACE_MODE_MII)
 		netdev_info(ndev, "using MII interface\n");
 	else
 		netdev_info(ndev, "using RMII interface\n");
 	phydev = phy_connect(ndev, dev_name(&phydev->dev),
-		&lpc_handle_link_change, 0, lpc_phy_interface_mode());
+			     &lpc_handle_link_change, 0,
+			     lpc_phy_interface_mode(&pldat->pdev->dev));
 
 	if (IS_ERR(phydev)) {
 		netdev_err(ndev, "Could not attach to PHY\n");
@@ -843,7 +833,7 @@ static int lpc_mii_init(struct netdata_l
 	}
 
 	/* Setup MII mode */
-	if (lpc_phy_interface_mode() == PHY_INTERFACE_MODE_MII)
+	if (lpc_phy_interface_mode(&pldat->pdev->dev) == PHY_INTERFACE_MODE_MII)
 		writel(LPC_COMMAND_PASSRUNTFRAME,
 		       LPC_ENET_COMMAND(pldat->net_base));
 	else {
@@ -1315,18 +1305,26 @@ static const struct net_device_ops lpc_n
 static int lpc_eth_drv_probe(struct platform_device *pdev)
 {
 	struct resource *res;
-	struct resource *dma_res;
 	struct net_device *ndev;
 	struct netdata_local *pldat;
 	struct phy_device *phydev;
 	dma_addr_t dma_handle;
 	int irq, ret;
+	u32 tmp;
+
+	/* Setup network interface for RMII mode */
+	tmp = __raw_readl(LPC32XX_CLKPWR_MACCLK_CTRL);
+	tmp &= ~LPC32XX_CLKPWR_MACCTRL_PINS_MSK;
+	if (lpc_phy_interface_mode(&pdev->dev) == PHY_INTERFACE_MODE_MII)
+		tmp |= LPC32XX_CLKPWR_MACCTRL_USE_MII_PINS;
+	else
+		tmp |= LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS;
+	__raw_writel(tmp, LPC32XX_CLKPWR_MACCLK_CTRL);
 
 	/* Get platform resources */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	irq = platform_get_irq(pdev, 0);
-	if ((!res) || (!dma_res) || (irq < 0) || (irq >= NR_IRQS)) {
+	if ((!res) || (irq < 0) || (irq >= NR_IRQS)) {
 		dev_err(&pdev->dev, "error getting resources.\n");
 		ret = -ENXIO;
 		goto err_exit;
@@ -1348,6 +1346,12 @@ static int lpc_eth_drv_probe(struct plat
 
 	spin_lock_init(&pldat->lock);
 
+	if (pdev->dev.of_node && of_get_property(pdev->dev.of_node,
+						 "use-iram", NULL))
+		pldat->use_iram = true;
+	else
+		pldat->use_iram = false;
+
 	/* Save resources */
 	ndev->irq = irq;
 
@@ -1389,17 +1393,19 @@ static int lpc_eth_drv_probe(struct plat
 		sizeof(struct txrx_desc_t) + sizeof(struct rx_status_t));
 	pldat->dma_buff_base_v = 0;
 
-	if (use_iram_for_net()) {
-		dma_handle = dma_res->start;
+	if (pldat->use_iram) {
+		dma_handle = LPC32XX_IRAM_BASE;
 		if (pldat->dma_buff_size <= lpc32xx_return_iram_size())
 			pldat->dma_buff_base_v =
-				io_p2v(dma_res->start);
+				io_p2v(LPC32XX_IRAM_BASE);
 		else
 			netdev_err(ndev,
 				"IRAM not big enough for net buffers, using SDRAM instead.\n");
 	}
 
 	if (pldat->dma_buff_base_v == 0) {
+		pldat->pdev->dev.coherent_dma_mask = 0xFFFFFFFF;
+		pldat->pdev->dev.dma_mask = &pldat->pdev->dev.coherent_dma_mask;
 		pldat->dma_buff_size = PAGE_ALIGN(pldat->dma_buff_size);
 
 		/* Allocate a chunk of memory for the DMA ethernet buffers
@@ -1488,7 +1494,7 @@ err_out_unregister_netdev:
 	platform_set_drvdata(pdev, NULL);
 	unregister_netdev(ndev);
 err_out_dma_unmap:
-	if (!use_iram_for_net() ||
+	if (!pldat->use_iram ||
 	    pldat->dma_buff_size > lpc32xx_return_iram_size())
 		dma_free_coherent(&pldat->pdev->dev, pldat->dma_buff_size,
 				  pldat->dma_buff_base_v,
@@ -1515,7 +1521,7 @@ static int lpc_eth_drv_remove(struct pla
 	unregister_netdev(ndev);
 	platform_set_drvdata(pdev, NULL);
 
-	if (!use_iram_for_net() ||
+	if (!pldat->use_iram ||
 	    pldat->dma_buff_size > lpc32xx_return_iram_size())
 		dma_free_coherent(&pldat->pdev->dev, pldat->dma_buff_size,
 				  pldat->dma_buff_base_v,
@@ -1584,6 +1590,14 @@ static int lpc_eth_drv_resume(struct pla
 }
 #endif
 
+#ifdef CONFIG_OF
+static const struct of_device_id lpc_eth_match[] = {
+	{ .compatible = "nxp,lpc-eth" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc_eth_match);
+#endif
+
 static struct platform_driver lpc_eth_driver = {
 	.probe		= lpc_eth_drv_probe,
 	.remove		= __devexit_p(lpc_eth_drv_remove),
@@ -1593,6 +1607,7 @@ static struct platform_driver lpc_eth_dr
 #endif
 	.driver		= {
 		.name	= MODNAME,
+		.of_match_table = of_match_ptr(lpc_eth_match),
 	},
 };

^ permalink raw reply

* [PATCH v2 2/8] rtc: Add device tree support for LPC32xx
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

This patch adds device tree support for rtc-lpc32xx.c

Signed-off-by: Roland Stigge <stigge@antcom.de>

---

 Applies to v3.4-rc1

 Documentation/devicetree/bindings/rtc/lpc32xx-rtc.txt |   15 +++++++++++++++
 drivers/rtc/rtc-lpc32xx.c                             |   12 +++++++++++-
 2 files changed, 26 insertions(+), 1 deletion(-)

--- /dev/null
+++ linux-2.6/Documentation/devicetree/bindings/rtc/lpc32xx-rtc.txt
@@ -0,0 +1,15 @@
+* NXP LPC32xx SoC Real Time Clock controller
+
+Required properties:
+- compatible: must be "nxp,lpc32xx-rtc"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: The RTC interrupt
+
+Example:
+
+	rtc@40024000 {
+		compatible = "nxp,lpc32xx-rtc";
+		reg = <0x40024000 0x1000>;
+		interrupts = <52 0>;
+	};
--- linux-2.6.orig/drivers/rtc/rtc-lpc32xx.c
+++ linux-2.6/drivers/rtc/rtc-lpc32xx.c
@@ -19,6 +19,7 @@
 #include <linux/rtc.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/of.h>
 
 /*
  * Clock and Power control register offsets
@@ -386,13 +387,22 @@ static const struct dev_pm_ops lpc32xx_r
 #define LPC32XX_RTC_PM_OPS NULL
 #endif
 
+#ifdef CONFIG_OF
+static const struct of_device_id lpc32xx_rtc_match[] = {
+	{ .compatible = "nxp,lpc32xx-rtc" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc32xx_rtc_match);
+#endif
+
 static struct platform_driver lpc32xx_rtc_driver = {
 	.probe		= lpc32xx_rtc_probe,
 	.remove		= __devexit_p(lpc32xx_rtc_remove),
 	.driver = {
 		.name	= RTC_NAME,
 		.owner	= THIS_MODULE,
-		.pm	= LPC32XX_RTC_PM_OPS
+		.pm	= LPC32XX_RTC_PM_OPS,
+		.of_match_table = of_match_ptr(lpc32xx_rtc_match),
 	},
 };

^ permalink raw reply

* [PATCH v2 1/8] iio: Add device tree support to LPC32xx ADC
From: Roland Stigge @ 2012-04-02 18:33 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge
In-Reply-To: <1333391587-26290-1-git-send-email-stigge@antcom.de>

This patch adds device tree support to the LPC32xx's ADC.

Signed-off-by: Roland Stigge <stigge@antcom.de>

---

 Applies to v3.4-rc1

 Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt |   16 ++++++++++
 drivers/staging/iio/adc/lpc32xx_adc.c                             |   10 ++++++
 2 files changed, 26 insertions(+)

--- /dev/null
+++ linux-2.6/Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt
@@ -0,0 +1,16 @@
+* NXP LPC32xx SoC ADC controller
+
+Required properties:
+- compatible: must be "nxp,lpc32xx-adc"
+- reg: physical base address of the controller and length of memory mapped
+  region.
+- interrupts: The ADC interrupt
+
+Example:
+
+	adc@40048000 {
+		compatible = "nxp,lpc32xx-adc";
+		reg = <0x40048000 0x1000>;
+		interrupt-parent = <&mic>;
+		interrupts = <39 0>;
+	};
--- linux-2.6.orig/drivers/staging/iio/adc/lpc32xx_adc.c
+++ linux-2.6/drivers/staging/iio/adc/lpc32xx_adc.c
@@ -30,6 +30,7 @@
 #include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/completion.h>
+#include <linux/of.h>
 
 #include "../iio.h"
 #include "../sysfs.h"
@@ -221,12 +222,21 @@ static int __devexit lpc32xx_adc_remove(
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id lpc32xx_adc_match[] = {
+	{ .compatible = "nxp,lpc32xx-adc" },
+	{},
+};
+MODULE_DEVICE_TABLE(of, lpc32xx_adc_match);
+#endif
+
 static struct platform_driver lpc32xx_adc_driver = {
 	.probe		= lpc32xx_adc_probe,
 	.remove		= __devexit_p(lpc32xx_adc_remove),
 	.driver		= {
 		.name	= MOD_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table = of_match_ptr(lpc32xx_adc_match),
 	},
 };

^ permalink raw reply

* [PATCH v2 0/8]: arm: lpc32xx: Device tree support
From: Roland Stigge @ 2012-04-02 18:32 UTC (permalink / raw)
  To: arm, linux-arm-kernel, linux-i2c, linux-kernel, w.sang,
	srinivas.bakki, kevin.wells, gregkh, netdev, rtc-linux, a.zummo,
	linux-watchdog, wim, jonsmirl
  Cc: Roland Stigge

This is the first series of patches to introduce device tree support for the
LPC32xx SoC. This series includes patches for the various subsystems to support
device tree to be used later by the machine's initialization.

The patches apply to various subsystems:

 * staging/iio/adc (1)
 * rtc (1)
 * net (1)
 * wdt (1)
 * i2c (4)
 * arm-soc (i2c related in the former, to be merged via i2c, as suggested by
	    Arnd Bergmann)

Based on v3.4-rc1

You can also pull from

  git://git.antcom.de/linux-2.6 lpc32xx/dt

I'm CC'ing the various subsystem maintainers and lists who can each see what's
going on and please pick their respective subsystem's changes. - Thanks!

Changes since patch v1:
 * Reorganized the changes for i2c (#5-8), fixes bisecting
 * Fixed device tree Documentation
 * Init .of_match_table via of_match_ptr() instead of #ifdef

Thanks to Arnd Bergmenn for reviewing!

Signed-off-by: Roland Stigge <stigge@antcom.de>

--

Roland Stigge (8):
 iio: Add device tree support to LPC32xx ADC
 rtc: Add device tree support for LPC32xx
 net: Add device tree support to LPC32xx
 wdt: Device tree support for pnx4008-wdt
 i2c-pnx.c: Fix suspend
 i2c-pnx.c: Use resources in platforms
 i2c-pnx.c: Remove duplicated i2c.h
 i2c: Add device tree support to i2c-pnx.c

 Documentation/devicetree/bindings/i2c/pnx.txt                     |   40 ++
 Documentation/devicetree/bindings/net/lpc-eth.txt                 |   24 +
 Documentation/devicetree/bindings/rtc/lpc32xx-rtc.txt             |   15 
 Documentation/devicetree/bindings/staging/iio/adc/lpc32xx-adc.txt |   16 
 Documentation/devicetree/bindings/watchdog/pnx4008-wdt.txt        |   13 
 arch/arm/mach-lpc32xx/common.c                                    |   75 ++--
 arch/arm/mach-lpc32xx/include/mach/i2c.h                          |   63 ---
 arch/arm/mach-pnx4008/i2c.c                                       |   70 ++--
 arch/arm/mach-pnx4008/include/mach/i2c.h                          |   64 ---
 drivers/i2c/busses/i2c-pnx.c                                      |  161 +++++++---
 drivers/net/ethernet/nxp/lpc_eth.c                                |   77 ++--
 drivers/rtc/rtc-lpc32xx.c                                         |   12 
 drivers/staging/iio/adc/lpc32xx_adc.c                             |   10 
 drivers/watchdog/pnx4008_wdt.c                                    |   10 
 include/linux/i2c-pnx.h                                           |   10 
 15 files changed, 394 insertions(+), 266 deletions(-)

^ permalink raw reply

* [PATCH] phonet: Check input from user before allocating
From: Sasha Levin @ 2012-04-02 20:31 UTC (permalink / raw)
  To: remi.denis-courmont, davem; +Cc: davej, netdev, linux-kernel, Sasha Levin

A phonet packet is limited to USHRT_MAX bytes, this is never checked during
tx which means that the user can specify any size he wishes, and the kernel
will attempt to allocate that size.

In the good case, it'll lead to the following warning, but it may also cause
the kernel to kick in the OOM and kill a random task on the server.

[ 8921.744094] WARNING: at mm/page_alloc.c:2255 __alloc_pages_slowpath+0x65/0x730()
[ 8921.749770] Pid: 5081, comm: trinity Tainted: G        W    3.4.0-rc1-next-20120402-sasha #46
[ 8921.756672] Call Trace:
[ 8921.758185]  [<ffffffff810b2ba7>] warn_slowpath_common+0x87/0xb0
[ 8921.762868]  [<ffffffff810b2be5>] warn_slowpath_null+0x15/0x20
[ 8921.765399]  [<ffffffff8117eae5>] __alloc_pages_slowpath+0x65/0x730
[ 8921.769226]  [<ffffffff81179c8a>] ? zone_watermark_ok+0x1a/0x20
[ 8921.771686]  [<ffffffff8117d045>] ? get_page_from_freelist+0x625/0x660
[ 8921.773919]  [<ffffffff8117f3a8>] __alloc_pages_nodemask+0x1f8/0x240
[ 8921.776248]  [<ffffffff811c03e0>] kmalloc_large_node+0x70/0xc0
[ 8921.778294]  [<ffffffff811c4bd4>] __kmalloc_node_track_caller+0x34/0x1c0
[ 8921.780847]  [<ffffffff821b0e3c>] ? sock_alloc_send_pskb+0xbc/0x260
[ 8921.783179]  [<ffffffff821b3c65>] __alloc_skb+0x75/0x170
[ 8921.784971]  [<ffffffff821b0e3c>] sock_alloc_send_pskb+0xbc/0x260
[ 8921.787111]  [<ffffffff821b002e>] ? release_sock+0x7e/0x90
[ 8921.788973]  [<ffffffff821b0ff0>] sock_alloc_send_skb+0x10/0x20
[ 8921.791052]  [<ffffffff824cfc20>] pep_sendmsg+0x60/0x380
[ 8921.792931]  [<ffffffff824cb4a6>] ? pn_socket_bind+0x156/0x180
[ 8921.794917]  [<ffffffff824cb50f>] ? pn_socket_autobind+0x3f/0x90
[ 8921.797053]  [<ffffffff824cb63f>] pn_socket_sendmsg+0x4f/0x70
[ 8921.798992]  [<ffffffff821ab8e7>] sock_aio_write+0x187/0x1b0
[ 8921.801395]  [<ffffffff810e325e>] ? sub_preempt_count+0xae/0xf0
[ 8921.803501]  [<ffffffff8111842c>] ? __lock_acquire+0x42c/0x4b0
[ 8921.805505]  [<ffffffff821ab760>] ? __sock_recv_ts_and_drops+0x140/0x140
[ 8921.807860]  [<ffffffff811e07cc>] do_sync_readv_writev+0xbc/0x110
[ 8921.809986]  [<ffffffff811958e7>] ? might_fault+0x97/0xa0
[ 8921.811998]  [<ffffffff817bd99e>] ? security_file_permission+0x1e/0x90
[ 8921.814595]  [<ffffffff811e17e2>] do_readv_writev+0xe2/0x1e0
[ 8921.816702]  [<ffffffff810b8dac>] ? do_setitimer+0x1ac/0x200
[ 8921.818819]  [<ffffffff810e2ec1>] ? get_parent_ip+0x11/0x50
[ 8921.820863]  [<ffffffff810e325e>] ? sub_preempt_count+0xae/0xf0
[ 8921.823318]  [<ffffffff811e1926>] vfs_writev+0x46/0x60
[ 8921.825219]  [<ffffffff811e1a3f>] sys_writev+0x4f/0xb0
[ 8921.827127]  [<ffffffff82658039>] system_call_fastpath+0x16/0x1b
[ 8921.829384] ---[ end trace dffe390f30db9eb7 ]---

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 net/phonet/pep.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 9f60008..caee99e 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -1130,6 +1130,9 @@ static int pep_sendmsg(struct kiocb *iocb, struct sock *sk,
 	int flags = msg->msg_flags;
 	int err, done;
 
+	if (len > USHRT_MAX)
+		return -E2BIG;
+
 	if ((msg->msg_flags & ~(MSG_DONTWAIT|MSG_EOR|MSG_NOSIGNAL|
 				MSG_CMSG_COMPAT)) ||
 			!(msg->msg_flags & MSG_EOR))
-- 
1.7.8.5

^ permalink raw reply related

* Re: [RFC PATCH 2/2] net: ethtool: Add capability to retrieve plug-in module EEPROM
From: Ben Hutchings @ 2012-04-02 18:18 UTC (permalink / raw)
  To: Stuart Hodgson; +Cc: netdev, davem, linux-kernel
In-Reply-To: <4F71FE15.7060708@solarflare.com>

On Tue, 2012-03-27 at 18:51 +0100, Stuart Hodgson wrote:
> Implementation in sfc driver to return the plugin module eeprom
> 
> Currently allows for SFP+ eeprom to be returned using the ethtool API.
> This can be extended in future to handle different eeprom formats
> and sizes.
> 
> Signed-off-by: Stuart Hodgson <smhodgson@solarflare.com>
> ---
>   drivers/net/ethernet/sfc/ethtool.c    |   36 +++++++++++
>   drivers/net/ethernet/sfc/mcdi_phy.c   |  105 
> +++++++++++++++++++++++++++++++++
>   drivers/net/ethernet/sfc/net_driver.h |    5 ++
>   3 files changed, 146 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sfc/ethtool.c 
> b/drivers/net/ethernet/sfc/ethtool.c
> index f22f45f..e77895f 100644
> --- a/drivers/net/ethernet/sfc/ethtool.c
> +++ b/drivers/net/ethernet/sfc/ethtool.c
> @@ -1108,6 +1108,40 @@ static int efx_ethtool_set_rxfh_indir(struct 
> net_device *net_dev,
>       return 0;
>   }
> 
> +static int efx_ethtool_get_module_eeprom(struct net_device *net_dev,
> +                     struct ethtool_eeprom *ee,
> +                     u8 *data)
> +{
> +    struct efx_nic *efx = netdev_priv(net_dev);
> +    int ret;
> +
> +    if (!efx->phy_op ||
> +        !efx->phy_op->get_module_eeprom)

No need to break that line.

[...]
> --- a/drivers/net/ethernet/sfc/mcdi_phy.c
> +++ b/drivers/net/ethernet/sfc/mcdi_phy.c
> @@ -304,6 +304,17 @@ static u32 mcdi_to_ethtool_media(u32 media)
>       }
>   }
> 
> +static u32 mcdi_to_module_eeprom_len(u32 media)
> +{
> +    switch (media) {
> +    case MC_CMD_MEDIA_SFP_PLUS:
> +        return SFF_8079_LEN;
> +    case MC_CMD_MEDIA_XFP:

Why split out XFP if we're not going to treat it any differently?

> +    default:
> +        return 0;
> +    }
> +}
> +
>   static int efx_mcdi_phy_probe(struct efx_nic *efx)
>   {
>       struct efx_mcdi_phy_data *phy_data;
> @@ -739,6 +750,98 @@ static const char *efx_mcdi_phy_test_name(struct 
> efx_nic *efx,
>       return NULL;
>   }
> 
> +#define SFP_PAGE_SIZE    128
> +#define NUM_PAGES    2

SFP_NUM_PAGES?

> +#define OFF_TO_BUFF(x)    (x + MC_CMD_GET_PHY_MEDIA_INFO_OUT_DATA_OFST)

This is not really worth defining for just the one use.

> +static int efx_mcdi_phy_get_module_eeprom(struct efx_nic *efx,
> +                      struct ethtool_eeprom *ee, u8 *data)
> +{
> +    u8 outbuf[MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX];
> +    u8 inbuf[MC_CMD_GET_PHY_MEDIA_INFO_IN_LEN];
> +    size_t outlen;
> +    int rc;
> +    int payload_len;
> +    int copied = 0;
> +    int space_remaining = ee->len;
> +    int page;
> +    int page_off;
> +    int to_copy;

None of payload_len..to_copy should be signed.

> +    u8 *user_data = data;
> +
> +    if (!data || !ee)
> +        return -EINVAL;

Neither of these is allowed to be NULL; don't bother checking.

> +    if (ee->offset > (SFP_PAGE_SIZE * NUM_PAGES)) {
> +        rc = -EINVAL;
> +        goto fail;
> +    }
> +
> +    page_off = (ee->offset % SFP_PAGE_SIZE);
> +    page = (ee->offset > SFP_PAGE_SIZE) ? 1 : 0;

Why not ee->offset / SFP_PAGE_SIZE?

> +    while (space_remaining && (page < NUM_PAGES)) {
> +
> +        MCDI_SET_DWORD(inbuf, GET_PHY_MEDIA_INFO_IN_PAGE, page);
> +
> +        rc = efx_mcdi_rpc(efx, MC_CMD_GET_PHY_MEDIA_INFO,
> +                  inbuf, sizeof(inbuf),
> +                  outbuf, sizeof(outbuf),
> + &outlen);
> +
> +        if (rc)
> +            goto fail;
> +
> +        /* Copy as much as we can into data */
> +        if (outlen < MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMIN ||
> +            outlen > MC_CMD_GET_PHY_MEDIA_INFO_OUT_LENMAX) {
> +            rc = -EIO;
> +            goto fail;
> +        }
> +
> +        payload_len = MCDI_DWORD(outbuf,
> +                     GET_PHY_MEDIA_INFO_OUT_DATALEN);
> +
> +        to_copy = (space_remaining < payload_len) ?
> +                space_remaining : payload_len;
> +
> +        to_copy -= page_off;

page_off is the number of bytes we need to discard from payload_len, but
we don't want do discard that from space_remaining.  I think the last
two statements should be changed to:

	payload_len -= page_off;
	to_copy = (space_remaining < payload_len) ?
		space_remaining : payload_len;

> +        memcpy(user_data,
> +               (outbuf + OFF_TO_BUFF(page_off)),
> +               to_copy);
> +
> +        space_remaining -= to_copy;
> +        user_data += to_copy;
> +        copied += to_copy;
> +        page_off = 0;
> +        page++;
> +    }
> +
> +    ee->len = copied;
> +
> +    return 0;
> +fail:
> +    return rc;

Nothing to clean up here, so you might as well return errors directly.

> +}
> +
> +static int efx_mcdi_phy_get_module_info(struct efx_nic *efx,
> +                    struct ethtool_modinfo *modinfo)
> +{
> +    /* This will return a length of the eeprom
> +     * type of the module that was detected during the probe,
> +     * if not modules inserted then phy_data will be NULL */
> +    struct efx_mcdi_phy_data *phy_cfg;
> +
> +    if (!efx || !efx->phy_data)
> +        return -EOPNOTSUPP;

efx certainly can't be NULL here and I don't believe efx->phy_data can
either.  (None of the other MCDI PHY operations check it.)

> +    phy_cfg = efx->phy_data;
> +    modinfo->eeprom_len = mcdi_to_module_eeprom_len(phy_cfg->media);
> +    modinfo->type = SFF_8079;
[...]

I don't think this makes sense.  If we're fixing the type as SFF_8079
then why are we calling a function to get the length?

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

^ permalink raw reply

* Re: [RFC PATCH 1/2] net: ethtool: Add capability to retrieve plug-in module EEPROM
From: Ben Hutchings @ 2012-04-02 18:14 UTC (permalink / raw)
  To: Stuart Hodgson
  Cc: netdev, bruce.w.allan, mirq-linux, decot, amit.salecha,
	alexander.h.duyck, davem, linux-kernel
In-Reply-To: <1333389160.2623.30.camel@bwh-desktop.uk.solarflarecom.com>

On Mon, 2012-04-02 at 18:52 +0100, Ben Hutchings wrote:
[...]
> > +    ret = ops->get_module_eeprom(dev, &eeprom, data);
> > +    if (ret)
> > +        goto out;
> > +
> > +
> > +    if (copy_to_user(userbuf, data, eeprom.len)) {
> > +        ret = -EFAULT;
> > +        goto out;
> > +    }
> > +
> > +    if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
> > +        ret = -EFAULT;
> [...]
> 
> I think you can drop this last copy as there's no information to return
> in the eeprom structure itself.
[...]

This is not the case because we need to cover short reads.

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

^ permalink raw reply

* Re: kernel BUG at include/net/netns/generic.h:41
From: Myklebust, Trond @ 2012-04-02 18:10 UTC (permalink / raw)
  To: Dave Jones, Stanislav Kinsbursky; +Cc: Linux Kernel, netdev@vger.kernel.org
In-Reply-To: <20120402172600.GA3728@redhat.com>

This looks related to the recent net namespace changes, so I'm adding
Stanislav.

Cheers
  Trond

On Mon, 2012-04-02 at 13:26 -0400, Dave Jones wrote:
> [added Trond to cc:]
> 
> still seeing this in 3.4rc1
> 
> 	Dave
> 
> 
> On Tue, Mar 27, 2012 at 08:23:46PM -0400, Dave Jones wrote:
>  > I started seeing this every boot.. (v3.3-6972-ge22057c)
>  > 
>  > [   17.103931] ------------[ cut here ]------------
>  > [   17.105987] RPC: Registered named UNIX socket transport module.
>  > [   17.105989] RPC: Registered udp transport module.
>  > [   17.105990] RPC: Registered tcp transport module.
>  > [   17.105992] RPC: Registered tcp NFSv4.1 backchannel transport module.
>  > [   17.104856] kernel BUG at include/net/netns/generic.h:41!
>  > [   17.104856] invalid opcode: 0000 [#1] PREEMPT SMP 
>  > [   17.104856] CPU 0 
>  > [   17.104856] Modules linked in: sunrpc btrfs zlib_deflate libcrc32c firewire_ohci firewire_core sata_sil crc_itu_t floppy radeon ttm drm_kms_helper drm i2c_algo_bit i2c_core
>  > [   17.104856] 
>  > [   17.104856] Pid: 416, comm: mount Not tainted 3.3.0+ #19                  /D975XBX
>  > [   17.104856] RIP: 0010:[<ffffffffa029068b>]  [<ffffffffa029068b>] rpc_fill_super+0x29b/0x2a0 [sunrpc]
>  > [   17.104856] RSP: 0018:ffff8800b52c5cf8  EFLAGS: 00010246
>  > [   17.104856] RAX: 0000000000000001 RBX: ffff8800a394dcd0 RCX: 0000000000000000
>  > [   17.104856] RDX: ffff8800a4c10000 RSI: ffffffff81c2cd00 RDI: ffff8800a4c10918
>  > [   17.104856] RBP: ffff8800b52c5d38 R08: 0000000000000001 R09: 0000000000000000
>  > [   17.104856] R10: 0000000000000001 R11: 0000000000000002 R12: 0000000000000000
>  > [   17.104856] R13: ffffffff82d0f140 R14: ffff8800ba54c000 R15: 0000000000000000
>  > [   17.104856] FS:  00007f1a97593800(0000) GS:ffff8800bf600000(0000) knlGS:0000000000000000
>  > [   17.104856] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
>  > [   17.104856] CR2: 0000003e92478a90 CR3: 00000000a4d22000 CR4: 00000000000007f0
>  > [   17.104856] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
>  > [   17.104856] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
>  > [   17.104856] Process mount (pid: 416, threadinfo ffff8800b52c4000, task ffff8800a4c10000)
>  > [   17.104856] Stack:
>  > [   17.104856]  ffffffffa02903f0 00000000000000d0 000060ff40002438 ffffffff82d0f140
>  > [   17.104856]  0000000000000000 ffffffffa02903f0 ffff8800a394dcd0 0000000000000000
>  > [   17.104856]  ffff8800b52c5d88 ffffffff811a9d8c 0000000000000003 ffffffff00000001
>  > [   17.104856] Call Trace:
>  > [   17.104856]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
>  > [   17.104856]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
>  > [   17.104856]  [<ffffffff811a9d8c>] mount_ns+0xac/0xe0
>  > [   17.104856]  [<ffffffffa028ea39>] rpc_mount+0x29/0x30 [sunrpc]
>  > [   17.104856]  [<ffffffff811aaab3>] mount_fs+0x43/0x1b0
>  > [   17.104856]  [<ffffffff8115dd80>] ? __alloc_percpu+0x10/0x20
>  > [   17.104856]  [<ffffffff811c8af2>] vfs_kern_mount+0x72/0x100
>  > [   17.104856]  [<ffffffff811c92d4>] do_kern_mount+0x54/0x110
>  > [   17.104856]  [<ffffffff811caa44>] do_mount+0x1a4/0x830
>  > [   17.104856]  [<ffffffff8115765b>] ? memdup_user+0x4b/0x90
>  > [   17.104856]  [<ffffffff811576fb>] ? strndup_user+0x5b/0x80
>  > [   17.104856]  [<ffffffff811cb210>] sys_mount+0x90/0xe0
>  > [   17.104856]  [<ffffffff816624d2>] system_call_fastpath+0x16/0x1b
>  > [   17.104856] Code: e8 db 7a e6 e0 84 c0 74 c9 48 c7 c7 00 cd c2 81 e8 bb e5 e1 e0 85 c0 0f 85 f4 fd ff ff eb b3 90 41 bf f4 ff ff ff e9 ce fe ff ff <0f> 0b 0f 0b 90 55 48 89 e5 41 54 53 48 83 ec 10 66 66 66 66 90 
>  > [   17.104856] RIP  [<ffffffffa029068b>] rpc_fill_super+0x29b/0x2a0 [sunrpc]
>  > [   17.104856]  RSP <ffff8800b52c5cf8>
>  > [   17.469688] ---[ end trace 74871f164631364c ]---
>  > [   17.488286] BUG: sleeping function called from invalid context at kernel/rwsem.c:21
>  > [   17.498626] in_atomic(): 0, irqs_disabled(): 0, pid: 416, name: mount
>  > [   17.498629] INFO: lockdep is turned off.
>  > [   17.498631] Pid: 416, comm: mount Tainted: G      D      3.3.0+ #19
>  > [   17.498632] Call Trace:
>  > [   17.498639]  [<ffffffff8107d96c>] __might_sleep+0x13c/0x1f0
>  > [   17.498644]  [<ffffffff81657c06>] down_read+0x26/0x93
>  > [   17.498646]  [<ffffffff81061164>] exit_signals+0x24/0x130
>  > [   17.498650]  [<ffffffff8104d3cf>] do_exit+0xbf/0xb60
>  > [   17.498652]  [<ffffffff8104a443>] ? kmsg_dump+0x1c3/0x2c0
>  > [   17.498654]  [<ffffffff8104a2ff>] ? kmsg_dump+0x7f/0x2c0
>  > [   17.498657]  [<ffffffff8165b9d4>] oops_end+0xa4/0xf0
>  > [   17.498660]  [<ffffffff81005be8>] die+0x58/0x90
>  > [   17.498662]  [<ffffffff8165b2f4>] do_trap+0xc4/0x170
>  > [   17.498665]  [<ffffffff81002f35>] ? do_invalid_op+0xa5/0xb0
>  > [   17.498667]  [<ffffffff81002f25>] do_invalid_op+0x95/0xb0
>  > [   17.498684]  [<ffffffffa029068b>] ? rpc_fill_super+0x29b/0x2a0 [sunrpc]
>  > [   17.498686]  [<ffffffff8165e3cd>] ? sub_preempt_count+0x9d/0xd0
>  > [   17.498689]  [<ffffffff8131baad>] ? trace_hardirqs_off_thunk+0x3a/0x3c
>  > [   17.498692]  [<ffffffff8165ac4d>] ? restore_args+0x30/0x30
>  > [   17.498696]  [<ffffffff81663755>] invalid_op+0x15/0x20
>  > [   17.498704]  [<ffffffffa029068b>] ? rpc_fill_super+0x29b/0x2a0 [sunrpc]
>  > [   17.498713]  [<ffffffffa0290675>] ? rpc_fill_super+0x285/0x2a0 [sunrpc]
>  > [   17.498721]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
>  > [   17.498731]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
>  > [   17.498734]  [<ffffffff811a9d8c>] mount_ns+0xac/0xe0
>  > [   17.498743]  [<ffffffffa028ea39>] rpc_mount+0x29/0x30 [sunrpc]
>  > [   17.498746]  [<ffffffff811aaab3>] mount_fs+0x43/0x1b0
>  > [   17.498750]  [<ffffffff8115dd80>] ? __alloc_percpu+0x10/0x20
>  > [   17.498754]  [<ffffffff811c8af2>] vfs_kern_mount+0x72/0x100
>  > [   17.498756]  [<ffffffff811c92d4>] do_kern_mount+0x54/0x110
>  > [   17.498760]  [<ffffffff811caa44>] do_mount+0x1a4/0x830
>  > [   17.498763]  [<ffffffff8115765b>] ? memdup_user+0x4b/0x90
>  > [   17.498765]  [<ffffffff811576fb>] ? strndup_user+0x5b/0x80
>  > [   17.498769]  [<ffffffff811cb210>] sys_mount+0x90/0xe0
>  > [   17.498773]  [<ffffffff816624d2>] system_call_fastpath+0x16/0x1b
>  > [   17.775067] systemd[1]: var-lib-nfs-rpc_pipefs.mount mount process exited, code=killed status=11
>  > [   17.829617] systemd[1]: Job nfs-idmap.service/start failed with result 'dependency'.
>  > [   17.856061] systemd[1]: Unit var-lib-nfs-rpc_pipefs.mount entered failed state.
>  > 
> ---end quoted text---

-- 
Trond Myklebust
Linux NFS client maintainer

NetApp
Trond.Myklebust@netapp.com
www.netapp.com


^ permalink raw reply

* Re: [PATCH V2 net-next 02/28] ethtool: Introduce a method for getting time stamping capabilities.
From: Richard Cochran @ 2012-04-02 18:04 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: netdev, David Miller, Martin Porter, Jacob Keller, Jeff Kirsher,
	John Ronciak, e1000-devel
In-Reply-To: <1333387973.2623.15.camel@bwh-desktop.uk.solarflarecom.com>

On Mon, Apr 02, 2012 at 06:32:53PM +0100, Ben Hutchings wrote:
> 
> Given that this doesn't require specific support from the driver,
> shouldn't it be made to work without dev->ethtool_ops being set at all
> (as for ETHTOOL_GDRVINFO)?

I'll take a look at that.
 
> Also should it require CAP_NET_ADMIN?  I think it probably shouldn't, in
> which case you need to add it to the list of commands for which we don't
> check that.

Agreed. Tomorrow I'll repost.

Thanks,
Richard

^ permalink raw reply

* Re: [RFC PATCH 1/2] net: ethtool: Add capability to retrieve plug-in module EEPROM
From: Ben Hutchings @ 2012-04-02 17:52 UTC (permalink / raw)
  To: Stuart Hodgson
  Cc: netdev, bruce.w.allan, mirq-linux, decot, amit.salecha,
	alexander.h.duyck, davem, linux-kernel
In-Reply-To: <4F71FE0A.3060203@solarflare.com>

We previously discussed the need for this in person, so I'm going to
review this as a submission rather than an RFC.

On Tue, 2012-03-27 at 18:51 +0100, Stuart Hodgson wrote:
> Added extensions to the ethtool API to obtain plugin module eeprom data
> This is useful for end users to be able to determine what the capabilities
> of the in use module are.
> 
> The first provides a new struct ethtool_modinfo that will return the
> type and size of plug-in module eeprom (such as SFP+) for parsing
> by userland program.
> 
> The second provides the API to get the raw eeprom information
> using the existing ethtool_eeprom structture to return the data
> 
> Signed-off-by: Stuart Hodgson <smhodgson@solarflare.com>
> ---
>   include/linux/ethtool.h |   20 ++++++++++++
>   net/core/ethtool.c      |   79 
> +++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 99 insertions(+), 0 deletions(-)

This is line-wrapped; you'll need to take care to avoid that when
submitting the patch for real.  Tabs have been converted to spaces,
which you also need to avoid.  See Documentation/email-clients.txt.

> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
> index da5b2de..50eaf35 100644
> --- a/include/linux/ethtool.h
> +++ b/include/linux/ethtool.h
> @@ -117,6 +117,14 @@ struct ethtool_eeprom {
>       __u8    data[0];
>   };
>
> +/* for passing plug-in module information */
> +struct ethtool_modinfo {
> +    __u32   cmd;
> +    __u32   type;
> +    __u32   eeprom_len;
> +    __u32   reserved[8];
> +};
> +

This needs a proper kernel-doc comment with a description of each of the
fields (except reserved).

>   /**
>    * struct ethtool_coalesce - coalescing parameters for IRQs and stats 
> updates
>    * @cmd: ETHTOOL_{G,S}COALESCE
> @@ -936,6 +944,10 @@ struct ethtool_ops {
>       int    (*get_dump_data)(struct net_device *,
>                    struct ethtool_dump *, void *);
>       int    (*set_dump)(struct net_device *, struct ethtool_dump *);
> +    int    (*get_module_info)(struct net_device *,
> +                   struct ethtool_modinfo *);
> +    int    (*get_module_eeprom)(struct net_device *,
> +                     struct ethtool_eeprom *, u8 *);

These need to be described in the kernel-doc comment for this structure.

>   };
>   #endif /* __KERNEL__ */
> @@ -1010,6 +1022,8 @@ struct ethtool_ops {
>   #define ETHTOOL_SET_DUMP    0x0000003e /* Set dump settings */
>   #define ETHTOOL_GET_DUMP_FLAG    0x0000003f /* Get dump settings */
>   #define ETHTOOL_GET_DUMP_DATA    0x00000040 /* Get dump data */
> +#define ETHTOOL_GMODULEINFO    0x00000041 /* Get plug-in module 
> information */
> +#define ETHTOOL_GMODULEEEPROM    0x00000042 /* Get plug-in module eeprom */
> 
>   /* compatibility with older code */
>   #define SPARC_ETH_GSET        ETHTOOL_GSET
> @@ -1159,6 +1173,12 @@ struct ethtool_ops {
>   #define RX_CLS_LOC_FIRST    0xfffffffe
>   #define RX_CLS_LOC_LAST        0xfffffffd
> 
> +/* EEPROM Standards for plug in modules */
> +#define SFF_8079        0x1
> +#define SFF_8079_LEN        256
> +#define SFF_8472        0x2
> +#define SFF_8472_LEN        512
> +

I think it's best to include a prefix of 'ethtool_' 'ETHTOOL_' or 'ETH_'
in new definitions in ethtool.h.  Since these are specific to modules I
would suggest a prefix of 'ETH_MODULE_'.

>   /* Reset flags */
>   /* The reset() operation must clear the flags for the components which
>    * were actually reset.  On successful return, the flags indicate the
> diff --git a/net/core/ethtool.c b/net/core/ethtool.c
> index 3f79db1..1e86bd9 100644
> --- a/net/core/ethtool.c
> +++ b/net/core/ethtool.c
[...]
> +static int ethtool_get_module_eeprom(struct net_device *dev,
> +        void __user *useraddr)
> +{
> +    int ret;
> +    struct ethtool_eeprom eeprom;
> +    struct ethtool_modinfo modinfo;
> +    const struct ethtool_ops *ops = dev->ethtool_ops;
> +    void __user *userbuf = useraddr + sizeof(eeprom);
> +    u8 *data;
> +
> +    if (!ops->get_module_info || !ops->get_module_eeprom)
> +        return -EOPNOTSUPP;
> +
> +    if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
> +        return -EFAULT;
> +
> +    /* Check for wrap and zero */
> +    if (eeprom.offset + eeprom.len <= eeprom.offset)
> +        return -EINVAL;
> +
> +    /* Get the modinfo to get the length */
> +    ret = ops->get_module_info(dev, &modinfo);
> +    if (ret)
> +        return ret;
> +
> +    if (eeprom.offset + eeprom.len > modinfo.eeprom_len)
> +        return -EINVAL;
> +
> +    data = kmalloc(PAGE_SIZE, GFP_USER);
> +    if (!data)
> +        return -ENOMEM;

What if some device has a larger EEPROM?  Surely this length should be
eeprom.len.

> +    ret = ops->get_module_eeprom(dev, &eeprom, data);
> +    if (ret)
> +        goto out;
> +
> +
> +    if (copy_to_user(userbuf, data, eeprom.len)) {
> +        ret = -EFAULT;
> +        goto out;
> +    }
> +
> +    if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
> +        ret = -EFAULT;
[...]

I think you can drop this last copy as there's no information to return
in the eeprom structure itself.

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

^ permalink raw reply

* Re: [PATCH V2 net-next 08/28] ethtool: Add a common function for drivers with transmit time stamping.
From: Ben Hutchings @ 2012-04-02 17:34 UTC (permalink / raw)
  To: Richard Cochran
  Cc: e1000-devel, netdev, Porter, John Ronciak, Martin, Jacob Keller,
	David Miller
In-Reply-To: <7eca521e2f9db67dab89a9c2bfd62b8fdff587f3.1333289292.git.richardcochran@gmail.com>

On Sun, 2012-04-01 at 17:19 +0200, Richard Cochran wrote:
> Currently, most drivers do not support transmit SO_TIMESTAMPING. For those
> that do support it, there is one appropriate response to the get_ts_info
> query. This patch adds a common function providing this response.

This looks fine but obviously depends on the other ethtool change.

Ben.

> Signed-off-by: Richard Cochran <richardcochran@gmail.com>
> ---
>  include/linux/ethtool.h |    1 +
>  net/core/ethtool.c      |   11 +++++++++++
>  2 files changed, 12 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
> index 776b3d0..0245d1d 100644
> --- a/include/linux/ethtool.h
> +++ b/include/linux/ethtool.h
> @@ -806,6 +806,7 @@ struct net_device;
>  
>  /* Some generic methods drivers may use in their ethtool_ops */
>  u32 ethtool_op_get_link(struct net_device *dev);
> +int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *eti);
>  
>  /**
>   * ethtool_rxfh_indir_default - get default value for RX flow hash indirection
> diff --git a/net/core/ethtool.c b/net/core/ethtool.c
> index d6eff4b..14bb8b1 100644
> --- a/net/core/ethtool.c
> +++ b/net/core/ethtool.c
> @@ -38,6 +38,17 @@ u32 ethtool_op_get_link(struct net_device *dev)
>  }
>  EXPORT_SYMBOL(ethtool_op_get_link);
>  
> +int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
> +{
> +	info->so_timestamping =
> +		SOF_TIMESTAMPING_TX_SOFTWARE |
> +		SOF_TIMESTAMPING_RX_SOFTWARE |
> +		SOF_TIMESTAMPING_SOFTWARE;
> +	info->phc_index = -1;
> +	return 0;
> +}
> +EXPORT_SYMBOL(ethtool_op_get_ts_info);
> +
>  /* Handlers for each ethtool command */
>  
>  #define ETHTOOL_DEV_FEATURE_WORDS	((NETDEV_FEATURE_COUNT + 31) / 32)

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
E1000-devel mailing list
E1000-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/e1000-devel
To learn more about Intel&#174; Ethernet, visit http://communities.intel.com/community/wired

^ permalink raw reply

* Re: [PATCH V2 net-next 02/28] ethtool: Introduce a method for getting time stamping capabilities.
From: Ben Hutchings @ 2012-04-02 17:32 UTC (permalink / raw)
  To: Richard Cochran
  Cc: netdev, David Miller, Martin Porter, Jacob Keller, Jeff Kirsher,
	John Ronciak, e1000-devel
In-Reply-To: <c212a85e0d09c1e6d38db901bcdfb605484984e9.1333289292.git.richardcochran@gmail.com>

On Sun, 2012-04-01 at 17:19 +0200, Richard Cochran wrote:
> This commit adds a new ethtool ioctl that exposes the SO_TIMESTAMPING
> capabilities of a network interface. In addition, user space programs
> can use this ioctl to discover the PTP Hardware Clock (PHC) device
> associated with the interface.
> 
> Since software receive time stamps are handled by the stack, the generic
> ethtool code can answer the query correctly in case the MAC or PHY
> drivers lack special time stamping features.
> 
> Signed-off-by: Richard Cochran <richardcochran@gmail.com>
> ---
>  include/linux/ethtool.h |   23 +++++++++++++++++++++++
>  include/linux/phy.h     |    3 +++
>  net/core/ethtool.c      |   36 ++++++++++++++++++++++++++++++++++++
>  3 files changed, 62 insertions(+), 0 deletions(-)
> 
> diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
> index e1d9e0e..776b3d0 100644
> --- a/include/linux/ethtool.h
> +++ b/include/linux/ethtool.h
> @@ -726,6 +726,24 @@ struct ethtool_sfeatures {
>  	struct ethtool_set_features_block features[0];
>  };
>  
> +/**
> + * struct ethtool_ts_info - holds a device's timestamping and PHC association
> + * @cmd: command number = %ETHTOOL_GET_TS_INFO
> + * @so_timestamping: bit mask of SO_TIMESTAMPING modes supported by the device

So that means a sum of SOF_TIMESTAMPING_mode flags

> + * @phc_index: device index of the associated PHC, or -1 if there is none
> + * @tx_types: bit mask of hwtstamp_tx_types modes supported by the device

whereas this is a sum of (1 << HWTSTAMP_TX_mode) flags

> + * @rx_filters: bit mask of hwtstamp_rx_filters modes supported by the device

and this is a sum of (1 << HWTSTAMP_FILTER_mode) flags?

Maybe you should explicitly point out the need for shifting in the
latter two.

[...]
> --- a/net/core/ethtool.c
> +++ b/net/core/ethtool.c
[...]
> @@ -1278,6 +1280,37 @@ out:
>  	return ret;
>  }
>  
> +static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
> +{
> +	int err = 0;
> +	struct ethtool_ts_info info;
> +	const struct ethtool_ops *ops = dev->ethtool_ops;
> +	struct phy_device *phydev = dev->phydev;
> +
> +	memset(&info, 0, sizeof(info));
> +	info.cmd = ETHTOOL_GET_TS_INFO;
> +
> +	if (phydev && phydev->drv && phydev->drv->ts_info)
> +		err = phydev->drv->ts_info(phydev, &info);
> +
> +	else if (dev->ethtool_ops->get_ts_info)
> +		err = ops->get_ts_info(dev, &info);
> +	else {
> +		info.so_timestamping =
> +			SOF_TIMESTAMPING_RX_SOFTWARE |
> +			SOF_TIMESTAMPING_SOFTWARE;
> +		info.phc_index = -1;
> +	}
[...]

Given that this doesn't require specific support from the driver,
shouldn't it be made to work without dev->ethtool_ops being set at all
(as for ETHTOOL_GDRVINFO)?

Also should it require CAP_NET_ADMIN?  I think it probably shouldn't, in
which case you need to add it to the list of commands for which we don't
check that.

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

^ permalink raw reply

* Re: kernel BUG at include/net/netns/generic.h:41
From: Dave Jones @ 2012-04-02 17:26 UTC (permalink / raw)
  To: Linux Kernel, netdev; +Cc: Trond.Myklebust
In-Reply-To: <20120328002346.GB3077@redhat.com>

[added Trond to cc:]

still seeing this in 3.4rc1

	Dave


On Tue, Mar 27, 2012 at 08:23:46PM -0400, Dave Jones wrote:
 > I started seeing this every boot.. (v3.3-6972-ge22057c)
 > 
 > [   17.103931] ------------[ cut here ]------------
 > [   17.105987] RPC: Registered named UNIX socket transport module.
 > [   17.105989] RPC: Registered udp transport module.
 > [   17.105990] RPC: Registered tcp transport module.
 > [   17.105992] RPC: Registered tcp NFSv4.1 backchannel transport module.
 > [   17.104856] kernel BUG at include/net/netns/generic.h:41!
 > [   17.104856] invalid opcode: 0000 [#1] PREEMPT SMP 
 > [   17.104856] CPU 0 
 > [   17.104856] Modules linked in: sunrpc btrfs zlib_deflate libcrc32c firewire_ohci firewire_core sata_sil crc_itu_t floppy radeon ttm drm_kms_helper drm i2c_algo_bit i2c_core
 > [   17.104856] 
 > [   17.104856] Pid: 416, comm: mount Not tainted 3.3.0+ #19                  /D975XBX
 > [   17.104856] RIP: 0010:[<ffffffffa029068b>]  [<ffffffffa029068b>] rpc_fill_super+0x29b/0x2a0 [sunrpc]
 > [   17.104856] RSP: 0018:ffff8800b52c5cf8  EFLAGS: 00010246
 > [   17.104856] RAX: 0000000000000001 RBX: ffff8800a394dcd0 RCX: 0000000000000000
 > [   17.104856] RDX: ffff8800a4c10000 RSI: ffffffff81c2cd00 RDI: ffff8800a4c10918
 > [   17.104856] RBP: ffff8800b52c5d38 R08: 0000000000000001 R09: 0000000000000000
 > [   17.104856] R10: 0000000000000001 R11: 0000000000000002 R12: 0000000000000000
 > [   17.104856] R13: ffffffff82d0f140 R14: ffff8800ba54c000 R15: 0000000000000000
 > [   17.104856] FS:  00007f1a97593800(0000) GS:ffff8800bf600000(0000) knlGS:0000000000000000
 > [   17.104856] CS:  0010 DS: 0000 ES: 0000 CR0: 000000008005003b
 > [   17.104856] CR2: 0000003e92478a90 CR3: 00000000a4d22000 CR4: 00000000000007f0
 > [   17.104856] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
 > [   17.104856] DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
 > [   17.104856] Process mount (pid: 416, threadinfo ffff8800b52c4000, task ffff8800a4c10000)
 > [   17.104856] Stack:
 > [   17.104856]  ffffffffa02903f0 00000000000000d0 000060ff40002438 ffffffff82d0f140
 > [   17.104856]  0000000000000000 ffffffffa02903f0 ffff8800a394dcd0 0000000000000000
 > [   17.104856]  ffff8800b52c5d88 ffffffff811a9d8c 0000000000000003 ffffffff00000001
 > [   17.104856] Call Trace:
 > [   17.104856]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
 > [   17.104856]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
 > [   17.104856]  [<ffffffff811a9d8c>] mount_ns+0xac/0xe0
 > [   17.104856]  [<ffffffffa028ea39>] rpc_mount+0x29/0x30 [sunrpc]
 > [   17.104856]  [<ffffffff811aaab3>] mount_fs+0x43/0x1b0
 > [   17.104856]  [<ffffffff8115dd80>] ? __alloc_percpu+0x10/0x20
 > [   17.104856]  [<ffffffff811c8af2>] vfs_kern_mount+0x72/0x100
 > [   17.104856]  [<ffffffff811c92d4>] do_kern_mount+0x54/0x110
 > [   17.104856]  [<ffffffff811caa44>] do_mount+0x1a4/0x830
 > [   17.104856]  [<ffffffff8115765b>] ? memdup_user+0x4b/0x90
 > [   17.104856]  [<ffffffff811576fb>] ? strndup_user+0x5b/0x80
 > [   17.104856]  [<ffffffff811cb210>] sys_mount+0x90/0xe0
 > [   17.104856]  [<ffffffff816624d2>] system_call_fastpath+0x16/0x1b
 > [   17.104856] Code: e8 db 7a e6 e0 84 c0 74 c9 48 c7 c7 00 cd c2 81 e8 bb e5 e1 e0 85 c0 0f 85 f4 fd ff ff eb b3 90 41 bf f4 ff ff ff e9 ce fe ff ff <0f> 0b 0f 0b 90 55 48 89 e5 41 54 53 48 83 ec 10 66 66 66 66 90 
 > [   17.104856] RIP  [<ffffffffa029068b>] rpc_fill_super+0x29b/0x2a0 [sunrpc]
 > [   17.104856]  RSP <ffff8800b52c5cf8>
 > [   17.469688] ---[ end trace 74871f164631364c ]---
 > [   17.488286] BUG: sleeping function called from invalid context at kernel/rwsem.c:21
 > [   17.498626] in_atomic(): 0, irqs_disabled(): 0, pid: 416, name: mount
 > [   17.498629] INFO: lockdep is turned off.
 > [   17.498631] Pid: 416, comm: mount Tainted: G      D      3.3.0+ #19
 > [   17.498632] Call Trace:
 > [   17.498639]  [<ffffffff8107d96c>] __might_sleep+0x13c/0x1f0
 > [   17.498644]  [<ffffffff81657c06>] down_read+0x26/0x93
 > [   17.498646]  [<ffffffff81061164>] exit_signals+0x24/0x130
 > [   17.498650]  [<ffffffff8104d3cf>] do_exit+0xbf/0xb60
 > [   17.498652]  [<ffffffff8104a443>] ? kmsg_dump+0x1c3/0x2c0
 > [   17.498654]  [<ffffffff8104a2ff>] ? kmsg_dump+0x7f/0x2c0
 > [   17.498657]  [<ffffffff8165b9d4>] oops_end+0xa4/0xf0
 > [   17.498660]  [<ffffffff81005be8>] die+0x58/0x90
 > [   17.498662]  [<ffffffff8165b2f4>] do_trap+0xc4/0x170
 > [   17.498665]  [<ffffffff81002f35>] ? do_invalid_op+0xa5/0xb0
 > [   17.498667]  [<ffffffff81002f25>] do_invalid_op+0x95/0xb0
 > [   17.498684]  [<ffffffffa029068b>] ? rpc_fill_super+0x29b/0x2a0 [sunrpc]
 > [   17.498686]  [<ffffffff8165e3cd>] ? sub_preempt_count+0x9d/0xd0
 > [   17.498689]  [<ffffffff8131baad>] ? trace_hardirqs_off_thunk+0x3a/0x3c
 > [   17.498692]  [<ffffffff8165ac4d>] ? restore_args+0x30/0x30
 > [   17.498696]  [<ffffffff81663755>] invalid_op+0x15/0x20
 > [   17.498704]  [<ffffffffa029068b>] ? rpc_fill_super+0x29b/0x2a0 [sunrpc]
 > [   17.498713]  [<ffffffffa0290675>] ? rpc_fill_super+0x285/0x2a0 [sunrpc]
 > [   17.498721]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
 > [   17.498731]  [<ffffffffa02903f0>] ? rpc_mkpipe_dentry+0x180/0x180 [sunrpc]
 > [   17.498734]  [<ffffffff811a9d8c>] mount_ns+0xac/0xe0
 > [   17.498743]  [<ffffffffa028ea39>] rpc_mount+0x29/0x30 [sunrpc]
 > [   17.498746]  [<ffffffff811aaab3>] mount_fs+0x43/0x1b0
 > [   17.498750]  [<ffffffff8115dd80>] ? __alloc_percpu+0x10/0x20
 > [   17.498754]  [<ffffffff811c8af2>] vfs_kern_mount+0x72/0x100
 > [   17.498756]  [<ffffffff811c92d4>] do_kern_mount+0x54/0x110
 > [   17.498760]  [<ffffffff811caa44>] do_mount+0x1a4/0x830
 > [   17.498763]  [<ffffffff8115765b>] ? memdup_user+0x4b/0x90
 > [   17.498765]  [<ffffffff811576fb>] ? strndup_user+0x5b/0x80
 > [   17.498769]  [<ffffffff811cb210>] sys_mount+0x90/0xe0
 > [   17.498773]  [<ffffffff816624d2>] system_call_fastpath+0x16/0x1b
 > [   17.775067] systemd[1]: var-lib-nfs-rpc_pipefs.mount mount process exited, code=killed status=11
 > [   17.829617] systemd[1]: Job nfs-idmap.service/start failed with result 'dependency'.
 > [   17.856061] systemd[1]: Unit var-lib-nfs-rpc_pipefs.mount entered failed state.
 > 
---end quoted text---

^ permalink raw reply

* Re: [PATCH 3.3.0 1/3] net:phy:bcm63xx: remove unnecessary code
From: Joe Perches @ 2012-04-02 17:02 UTC (permalink / raw)
  To: srinivas.kandagatla; +Cc: netdev, davem
In-Reply-To: <4F79D91A.2030403@st.com>

On Mon, 2012-04-02 at 17:51 +0100, Srinivas KANDAGATLA wrote:
> On 02/04/12 17:42, Joe Perches wrote:
> > On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
> > Do these really make any functional difference?
> No it does not make any functional difference.
> > Doesn't the compiler generate the same output?
> I think it will not generate same output.

Yes, you are right.  The code currently returns 0 for
non-error cases and you've changed it to possibly
return a positive value.

Have you checked all the callers to make sure this
doesn't introduce a new defect?

^ permalink raw reply

* Re: [PATCH 3.3.0 1/3] net:phy:bcm63xx: remove unnecessary code
From: Srinivas KANDAGATLA @ 2012-04-02 16:51 UTC (permalink / raw)
  To: Joe Perches; +Cc: netdev, davem
In-Reply-To: <1333384945.15422.14.camel@joe2Laptop>

On 02/04/12 17:42, Joe Perches wrote:
> On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
>> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
>>
>> Compile tested.
>> remove unnecessary code that matches this coccinelle pattern
>>
>> 	ret = phy_write(x, y , z)
>> 	if (ret < 0)
>> 		return ret;
>> 	return 0;
>>
>> As phy_write returns error code, we dont need to do not need extra check
>> before returning.
>
> Do these really make any functional difference?
No it does not make any functional difference.
> Doesn't the compiler generate the same output?
>
I think it will not generate same output.
> Many times, there's a code pattern that precedes these
> calls has a similar pattern and changing the pattern
> for the last call in a sequence can be jarring to a
> reader and changing the pattern can sometimes introduce
> errors as well.
There is a purpose(error handling) of having similar pattern for the
code above last call, However there is no value for doing an additional
check before returning.
If we look at other phy files(ex:boardcom.c..), we can see they do
something similar to what the patch does in config_init.

>
>

^ permalink raw reply

* Re: [PATCH 3.3.0 1/3] net:phy:bcm63xx: remove unnecessary code
From: Joe Perches @ 2012-04-02 16:42 UTC (permalink / raw)
  To: Srinivas KANDAGATLA; +Cc: netdev, davem
In-Reply-To: <1333383895-23889-1-git-send-email-srinivas.kandagatla@st.com>

On Mon, 2012-04-02 at 17:24 +0100, Srinivas KANDAGATLA wrote:
> From: Srinivas Kandagatla <srinivas.kandagatla@st.com>
> 
> Compile tested.
> remove unnecessary code that matches this coccinelle pattern
> 
> 	ret = phy_write(x, y , z)
> 	if (ret < 0)
> 		return ret;
> 	return 0;
> 
> As phy_write returns error code, we dont need to do not need extra check
> before returning.

Do these really make any functional difference?
Doesn't the compiler generate the same output?

Many times, there's a code pattern that precedes these
calls has a similar pattern and changing the pattern
for the last call in a sequence can be jarring to a
reader and changing the pattern can sometimes introduce
errors as well.

^ permalink raw reply

* [PATCH 3.3.0 3/3] net:phy:marvell: remove unnecessary code
From: Srinivas KANDAGATLA @ 2012-04-02 16:25 UTC (permalink / raw)
  To: netdev; +Cc: davem, srinivas.kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@st.com>

Compile tested.
remove unnecessary code that matches this coccinelle pattern

	ret = phy_write(x, y , z)
	if (ret < 0)
	       	return ret;
	return 0;

As phy_write returns error code, we dont need to do not need extra check
before returning.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
---
 drivers/net/phy/marvell.c |   18 +++---------------
 1 files changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c
index e8b9c53..418928d 100644
--- a/drivers/net/phy/marvell.c
+++ b/drivers/net/phy/marvell.c
@@ -455,11 +455,7 @@ static int m88e1111_config_init(struct phy_device *phydev)
 	if (err < 0)
 		return err;
 
-	err = phy_write(phydev, MII_BMCR, BMCR_RESET);
-	if (err < 0)
-		return err;
-
-	return 0;
+	return phy_write(phydev, MII_BMCR, BMCR_RESET);
 }
 
 static int m88e1118_config_aneg(struct phy_device *phydev)
@@ -515,11 +511,7 @@ static int m88e1118_config_init(struct phy_device *phydev)
 	if (err < 0)
 		return err;
 
-	err = phy_write(phydev, MII_BMCR, BMCR_RESET);
-	if (err < 0)
-		return err;
-
-	return 0;
+	return phy_write(phydev, MII_BMCR, BMCR_RESET);
 }
 
 static int m88e1149_config_init(struct phy_device *phydev)
@@ -545,11 +537,7 @@ static int m88e1149_config_init(struct phy_device *phydev)
 	if (err < 0)
 		return err;
 
-	err = phy_write(phydev, MII_BMCR, BMCR_RESET);
-	if (err < 0)
-		return err;
-
-	return 0;
+	return phy_write(phydev, MII_BMCR, BMCR_RESET);
 }
 
 static int m88e1145_config_init(struct phy_device *phydev)
-- 
1.7.0.4

^ permalink raw reply related

* [PATCH 3.3.0 2/3] net:phy:davicom: remove unnecessary code
From: Srinivas KANDAGATLA @ 2012-04-02 16:25 UTC (permalink / raw)
  To: netdev; +Cc: davem, srinivas.kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@st.com>

Compile tested.
remove unnecessary code that matches this coccinelle pattern

	ret = phy_write(x, y , z)
	if (ret < 0)
		return ret;
	return 0;

As phy_write returns error code, we dont need to do not need extra check
before returning.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
---
 drivers/net/phy/davicom.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/drivers/net/phy/davicom.c b/drivers/net/phy/davicom.c
index 2f774ac..5f59cc0 100644
--- a/drivers/net/phy/davicom.c
+++ b/drivers/net/phy/davicom.c
@@ -134,12 +134,7 @@ static int dm9161_config_init(struct phy_device *phydev)
 		return err;
 
 	/* Reconnect the PHY, and enable Autonegotiation */
-	err = phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
-
-	if (err < 0)
-		return err;
-
-	return 0;
+	return phy_write(phydev, MII_BMCR, BMCR_ANENABLE);
 }
 
 static int dm9161_ack_interrupt(struct phy_device *phydev)
-- 
1.7.0.4

^ permalink raw reply related

* [PATCH 3.3.0 1/3] net:phy:bcm63xx: remove unnecessary code
From: Srinivas KANDAGATLA @ 2012-04-02 16:24 UTC (permalink / raw)
  To: netdev; +Cc: davem, srinivas.kandagatla

From: Srinivas Kandagatla <srinivas.kandagatla@st.com>

Compile tested.
remove unnecessary code that matches this coccinelle pattern

	ret = phy_write(x, y , z)
	if (ret < 0)
		return ret;
	return 0;

As phy_write returns error code, we dont need to do not need extra check
before returning.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@st.com>
---
 drivers/net/phy/bcm63xx.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/drivers/net/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c
index e16f98c..cd802eb 100644
--- a/drivers/net/phy/bcm63xx.c
+++ b/drivers/net/phy/bcm63xx.c
@@ -39,10 +39,7 @@ static int bcm63xx_config_init(struct phy_device *phydev)
 		MII_BCM63XX_IR_SPEED |
 		MII_BCM63XX_IR_LINK) |
 		MII_BCM63XX_IR_EN;
-	err = phy_write(phydev, MII_BCM63XX_IR, reg);
-	if (err < 0)
-		return err;
-	return 0;
+	return phy_write(phydev, MII_BCM63XX_IR, reg);
 }
 
 static int bcm63xx_ack_interrupt(struct phy_device *phydev)
-- 
1.7.0.4

^ permalink raw reply related

* Re: [PATCH 03/10] stmmac: sanitize the rx coe and add the type-1 csum
From: deepaksi @ 2012-04-02 16:18 UTC (permalink / raw)
  To: Giuseppe CAVALLARO
  Cc: netdev@vger.kernel.org, davem@davemloft.net, Srinivas KANDAGATLA,
	spear-devel, Shiraz HASHIM, Viresh KUMAR,
	bhutchings@solarflare.com
In-Reply-To: <4F79887A.50804@st.com>

On 4/2/2012 4:37 PM, Giuseppe CAVALLARO wrote:
> On 3/24/2012 10:21 AM, Deepak SIKRI wrote:
>>
>>
>> On 3/23/2012 2:38 PM, Giuseppe CAVALLARO wrote:
>>> [snip]
>>>
>>>
>>> -    priv->rx_coe = priv->hw->mac->rx_coe(priv->ioaddr);
>>> -    if (priv->rx_coe)
>>> -        pr_info(" RX Checksum Offload Engine supported\n");
>>> +    if (priv->plat->rx_coe)
>>> +        pr_info(" RX Checksum Offload Engine supported (type %d)\n",
>>> +            priv->plat->rx_coe);
>>>        if (priv->plat->tx_coe)
>>>            pr_info(" TX Checksum insertion supported\n");
>>>
>> rx_coe needs to be enabled. Earlier it was being done. Any specific
>> reasons to remove this.
>> Instead this code needs to be moved post mac reset has been done.
> Hello Deepak
>
> sorry for this delay.
>
> I've not clear at all your question.
> The driver well uses the rx_coe as briefly described below:
>
> probe funct
>    |__ hw_init
>           |_ check the RX type from HW cap reg
>                   |__ Override the rx_coe if required
>
> After that the rx_coe is used and passed to the core as expected.
> In case of there is no HW cap register so the rx_coe from platform will
> be used.
>
> Peppe

In the same patch, this portion of the code has been removed.

-static int dwmac1000_rx_coe_supported(void __iomem *ioaddr)
-{
-	u32 value = readl(ioaddr + GMAC_CONTROL);
-
-	value |= GMAC_CONTROL_IPC;
-	writel(value, ioaddr + GMAC_CONTROL);
-
-	value = readl(ioaddr + GMAC_CONTROL);
-
-	return !!(value&  GMAC_CONTROL_IPC);
-}

Earlier this was taking care of setting the IP Checksum offloading feature
in case its available. This code has to be present, as I do not see any
other location where the IPC bit is being programmed.

Also, the location of setting the IPC should be post the mac has been reset.

I hope this clears the things a bit. Sorry for the miscommunication.

Rgds
Deepak






>> Regards
>> Deepak
>>
> .
>

^ permalink raw reply

* [PATCH net 2/2] net/bonding: correctly proxy slave neigh param setup ndo function
From: Or Gerlitz @ 2012-04-02 16:17 UTC (permalink / raw)
  To: davem; +Cc: roland, netdev, fubar, Or Gerlitz, Shlomo Pongratz
In-Reply-To: <1333383430-17456-1-git-send-email-ogerlitz@mellanox.com>

From: Shlomo Pongratz <shlomop@mellanox.com>

The current implemenation was buggy for slaves who use ndo_neigh_setup,
since the networking stack invokes the bonding device ndo entry (from
neigh_params_alloc) before any devices are enslaved, and the bonding
driver can't further delegate the call at that point in time. As a
result when bonding IPoIB devices, the neigh_cleanup hasn't been called.

Fix that by deferring the actual call into the slave ndo_neigh_setup
from the time the bonding neigh_setup is called.

Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com>
---
 drivers/net/bonding/bond_main.c |   51 ++++++++++++++++++++++++++++++++------
 1 files changed, 43 insertions(+), 8 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index b0a278d..2eed155 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3707,17 +3707,52 @@ static void bond_set_multicast_list(struct net_device *bond_dev)
 	read_unlock(&bond->lock);
 }
 
-static int bond_neigh_setup(struct net_device *dev, struct neigh_parms *parms)
+static int bond_neigh_init(struct neighbour *n)
 {
-	struct bonding *bond = netdev_priv(dev);
+	struct bonding *bond = netdev_priv(n->dev);
 	struct slave *slave = bond->first_slave;
+	const struct net_device_ops *slave_ops;
+	struct neigh_parms parms;
+	int ret;
+
+	if (!slave)
+		return 0;
+
+	slave_ops = slave->dev->netdev_ops;
+
+	if (!slave_ops->ndo_neigh_setup)
+		return 0;
+
+	parms.neigh_setup = NULL;
+	parms.neigh_cleanup = NULL;
+	ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
+	if (ret)
+		return ret;
+
+	/*
+	 * must bind here to the slave clenaup. Since when last slave is removed
+	 * there will be no slave device to dereference in a bonding
+	 * neigh_cleanup function that we have could add.
+	 */
+	n->parms->neigh_cleanup = parms.neigh_cleanup;
+
+	/* Does slave implement neigh_setup ? */
+	if (!parms.neigh_setup)
+		return 0;
+
+	return parms.neigh_setup(n);
+}
+
+/*
+ * The bonding ndo_neigh_setup is called at init time beofre any
+ * slave exists. So we must declare proxy setup function which will
+ * be used at run time to resolve the actual slave neigh param setup.
+ */
+static int bond_neigh_setup(struct net_device *dev,
+			    struct neigh_parms *parms)
+{
+	parms->neigh_setup   = bond_neigh_init;
 
-	if (slave) {
-		const struct net_device_ops *slave_ops
-			= slave->dev->netdev_ops;
-		if (slave_ops->ndo_neigh_setup)
-			return slave_ops->ndo_neigh_setup(slave->dev, parms);
-	}
 	return 0;
 }
 
-- 
1.7.1

^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox