mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net/e1000: allow to overwrite flash size from device tree
@ 2018-07-12  9:29 Uwe Kleine-König
  2018-07-12  9:39 ` [PATCH] fixup! " Uwe Kleine-König
  2018-07-13  6:24 ` [PATCH] " Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2018-07-12  9:29 UTC (permalink / raw)
  To: barebox

When barebox probes the e1000 driver and the flash on the i210 device is
unprogrammed, the driver assumes the flash has a size of only 4 kiB.
This is annoying because to program the flash an image must be written
that is bigger than 4 kiB. So you first have to flash the first sector
to make barebox detect the right size on the next boot. Then reset the
board to be able to write the remaining data.

To work around that limitation, try to read the actual size from the
device tree. (Note however that barebox' pci code currently doesn't use
the device tree and so currently this try always fails without further
patching.)

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/net/e1000/eeprom.c | 57 ++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 14 deletions(-)

diff --git a/drivers/net/e1000/eeprom.c b/drivers/net/e1000/eeprom.c
index 3f39db7164db..97cb09a718f9 100644
--- a/drivers/net/e1000/eeprom.c
+++ b/drivers/net/e1000/eeprom.c
@@ -3,6 +3,8 @@
 #include <malloc.h>
 #include <linux/math64.h>
 #include <linux/sizes.h>
+#include <of_device.h>
+#include <linux/pci.h>
 #include <linux/mtd/spi-nor.h>
 
 #include "e1000.h"
@@ -406,6 +408,46 @@ static void e1000_eeprom_uses_microwire(struct e1000_eeprom_info *eeprom,
 }
 
 
+size_t e1000_igb_get_flash_size(struct e1000_hw *hw)
+{
+	struct device_node *node =
+		hw->pdev->dev.device_node;
+	u32 flash_size;
+	uint32_t fla;
+	int ret = 0;
+
+	/*
+	 * There are two potential places where the size of the flash can be
+	 * specified. In the device tree, and in the flash itself.  Use the
+	 * first that looks valid.
+	 */
+
+	ret = of_property_read_u32(node, "flash-size", &flash_size);
+	if (ret == 0) {
+		dev_info(hw->dev,
+			 "Determined flash size from device tree (%u)\n",
+			 flash_size);
+		return flash_size;
+	}
+
+	fla = e1000_read_reg(hw, E1000_FLA);
+	fla &= E1000_FLA_FL_SIZE_MASK;
+	fla >>= E1000_FLA_FL_SIZE_SHIFT;
+
+	if (fla) {
+		flash_size = SZ_64K << fla;
+		dev_info(hw->dev,
+			 "Determined flash size from E1000_FLA.FL_SIZE (%u)\n",
+			 flash_size);
+		return flash_size;
+	}
+
+	dev_info(hw->dev,
+		 "Unprogrammed Flash detected and no flash-size found in device tree, limiting access to first 4 kiB\n");
+
+	return 4096;
+}
+
 /******************************************************************************
  * Sets up eeprom variables in the hw struct.  Must be called after mac_type
  * is configured.  Additionally, if this is ICH8, the flash controller GbE
@@ -480,20 +522,7 @@ int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
 
 	case e1000_igb:
 		if (eecd & E1000_EECD_I210_FLASH_DETECTED) {
-			uint32_t fla;
-
-			fla  = e1000_read_reg(hw, E1000_FLA);
-			fla &= E1000_FLA_FL_SIZE_MASK;
-			fla >>= E1000_FLA_FL_SIZE_SHIFT;
-
-			if (fla) {
-				eeprom->word_size = (SZ_64K << fla) / 2;
-			} else {
-				eeprom->word_size = 2048;
-				dev_info(hw->dev, "Unprogrammed Flash detected, "
-					 "limiting access to first 4KB\n");
-			}
-
+			eeprom->word_size = e1000_igb_get_flash_size(hw) / 2;
 			eeprom->acquire = e1000_acquire_eeprom_flash;
 			eeprom->release = e1000_release_eeprom_flash;
 		}
-- 
2.18.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] fixup! net/e1000: allow to overwrite flash size from device tree
  2018-07-12  9:29 [PATCH] net/e1000: allow to overwrite flash size from device tree Uwe Kleine-König
@ 2018-07-12  9:39 ` Uwe Kleine-König
  2018-07-13  6:24 ` [PATCH] " Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2018-07-12  9:39 UTC (permalink / raw)
  To: barebox

---
 drivers/net/e1000/eeprom.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/e1000/eeprom.c b/drivers/net/e1000/eeprom.c
index 97cb09a718f9..dda022e05437 100644
--- a/drivers/net/e1000/eeprom.c
+++ b/drivers/net/e1000/eeprom.c
@@ -407,7 +407,6 @@ static void e1000_eeprom_uses_microwire(struct e1000_eeprom_info *eeprom,
 	eeprom->read = e1000_read_eeprom_microwire;
 }
 
-
 size_t e1000_igb_get_flash_size(struct e1000_hw *hw)
 {
 	struct device_node *node =
-- 
2.18.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net/e1000: allow to overwrite flash size from device tree
  2018-07-12  9:29 [PATCH] net/e1000: allow to overwrite flash size from device tree Uwe Kleine-König
  2018-07-12  9:39 ` [PATCH] fixup! " Uwe Kleine-König
@ 2018-07-13  6:24 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2018-07-13  6:24 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On Thu, Jul 12, 2018 at 11:29:11AM +0200, Uwe Kleine-König wrote:
> When barebox probes the e1000 driver and the flash on the i210 device is
> unprogrammed, the driver assumes the flash has a size of only 4 kiB.
> This is annoying because to program the flash an image must be written
> that is bigger than 4 kiB. So you first have to flash the first sector
> to make barebox detect the right size on the next boot. Then reset the
> board to be able to write the remaining data.
> 
> To work around that limitation, try to read the actual size from the
> device tree. (Note however that barebox' pci code currently doesn't use
> the device tree and so currently this try always fails without further
> patching.)
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
>  drivers/net/e1000/eeprom.c | 57 ++++++++++++++++++++++++++++----------
>  1 file changed, 43 insertions(+), 14 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/net/e1000/eeprom.c b/drivers/net/e1000/eeprom.c
> index 3f39db7164db..97cb09a718f9 100644
> --- a/drivers/net/e1000/eeprom.c
> +++ b/drivers/net/e1000/eeprom.c
> @@ -3,6 +3,8 @@
>  #include <malloc.h>
>  #include <linux/math64.h>
>  #include <linux/sizes.h>
> +#include <of_device.h>
> +#include <linux/pci.h>
>  #include <linux/mtd/spi-nor.h>
>  
>  #include "e1000.h"
> @@ -406,6 +408,46 @@ static void e1000_eeprom_uses_microwire(struct e1000_eeprom_info *eeprom,
>  }
>  
>  
> +size_t e1000_igb_get_flash_size(struct e1000_hw *hw)
> +{
> +	struct device_node *node =
> +		hw->pdev->dev.device_node;
> +	u32 flash_size;
> +	uint32_t fla;
> +	int ret = 0;
> +
> +	/*
> +	 * There are two potential places where the size of the flash can be
> +	 * specified. In the device tree, and in the flash itself.  Use the
> +	 * first that looks valid.
> +	 */
> +
> +	ret = of_property_read_u32(node, "flash-size", &flash_size);
> +	if (ret == 0) {
> +		dev_info(hw->dev,
> +			 "Determined flash size from device tree (%u)\n",
> +			 flash_size);
> +		return flash_size;
> +	}
> +
> +	fla = e1000_read_reg(hw, E1000_FLA);
> +	fla &= E1000_FLA_FL_SIZE_MASK;
> +	fla >>= E1000_FLA_FL_SIZE_SHIFT;
> +
> +	if (fla) {
> +		flash_size = SZ_64K << fla;
> +		dev_info(hw->dev,
> +			 "Determined flash size from E1000_FLA.FL_SIZE (%u)\n",
> +			 flash_size);
> +		return flash_size;
> +	}
> +
> +	dev_info(hw->dev,
> +		 "Unprogrammed Flash detected and no flash-size found in device tree, limiting access to first 4 kiB\n");
> +
> +	return 4096;
> +}
> +
>  /******************************************************************************
>   * Sets up eeprom variables in the hw struct.  Must be called after mac_type
>   * is configured.  Additionally, if this is ICH8, the flash controller GbE
> @@ -480,20 +522,7 @@ int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
>  
>  	case e1000_igb:
>  		if (eecd & E1000_EECD_I210_FLASH_DETECTED) {
> -			uint32_t fla;
> -
> -			fla  = e1000_read_reg(hw, E1000_FLA);
> -			fla &= E1000_FLA_FL_SIZE_MASK;
> -			fla >>= E1000_FLA_FL_SIZE_SHIFT;
> -
> -			if (fla) {
> -				eeprom->word_size = (SZ_64K << fla) / 2;
> -			} else {
> -				eeprom->word_size = 2048;
> -				dev_info(hw->dev, "Unprogrammed Flash detected, "
> -					 "limiting access to first 4KB\n");
> -			}
> -
> +			eeprom->word_size = e1000_igb_get_flash_size(hw) / 2;
>  			eeprom->acquire = e1000_acquire_eeprom_flash;
>  			eeprom->release = e1000_release_eeprom_flash;
>  		}
> -- 
> 2.18.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-13  6:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-12  9:29 [PATCH] net/e1000: allow to overwrite flash size from device tree Uwe Kleine-König
2018-07-12  9:39 ` [PATCH] fixup! " Uwe Kleine-König
2018-07-13  6:24 ` [PATCH] " Sascha Hauer

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