U-Boot
Threads by month
- ----- 2025 -----
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2000 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
January 2016
- 195 participants
- 740 discussions

[U-Boot] [RFC PATCH] get_maintainer: fix perl 5.22/5.24 deprecated/incompatible "\C" use
by Heiko Schocher 04 Jan '16
by Heiko Schocher 04 Jan '16
04 Jan '16
from linux commit ce8155f7a3d5:
Perl 5.22 emits a deprecated message when "\C" is used in a regex. Perl
5.24 will disallow it altogether.
Fix it by using [A-Z] instead of \C.
>From linux adapted to U-Boot by:
Signed-off-by: Heiko Schocher <hs(a)denx.de>
---
running get_maintainer.pl drops warnings with PERL > 5.22 .
In linux this is fixed though above commit.
With the original linux patch applied to u-boot, there
is following warning:
^* matches null string many times in regex; marked by <-- HERE in m/^* <-- HERE / at ./scripts/get_maintainer.pl line 739.
^* matches null string many times in regex; marked by <-- HERE in m/^* <-- HERE // at ./scripts/get_maintainer.pl line 735.
The change in MAINTAINERS fixes this, but I get differences
when running the python script:
import os
import subprocess
root_dir = '.'
for directory, subdirectories, files in os.walk(root_dir):
for file in files:
tmp=os.path.join(directory, file)
print(tmp)
ret = subprocess.call(["scripts/get_maintainer.pl", "-f", tmp])
and comparing the output from it, based on the original
u-boot code and the code with this patch ...
I have no PERL experience, so made this patch as RFC, maybe
someone with better PERL skills can fix it correct.
MAINTAINERS | 4 ++--
scripts/get_maintainer.pl | 22 +++++++++++-----------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/MAINTAINERS b/MAINTAINERS
index 5b3c93a..a197cd0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -417,5 +417,5 @@ L: u-boot(a)lists.denx.de
Q: http://patchwork.ozlabs.org/project/uboot/list/
S: Maintained
T: git git://git.denx.de/u-boot.git
-F: *
-F: */
+F: .*
+F: .*/
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 4707dfd..308d7f0 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -298,7 +298,7 @@ sub read_maintainers {
while (<$maint>) {
my $line = $_;
- if ($line =~ m/^(\C):\s*(.*)/) {
+ if ($line =~ m/^(\[A-Z]):\s*(.*)/) {
my $type = $1;
my $value = $2;
@@ -533,7 +533,7 @@ sub range_is_maintained {
for (my $i = $start; $i < $end; $i++) {
my $line = $typevalue[$i];
- if ($line =~ m/^(\C):\s*(.*)/) {
+ if ($line =~ m/^([A-Z]):\s*(.*)/) {
my $type = $1;
my $value = $2;
if ($type eq 'S') {
@@ -551,7 +551,7 @@ sub range_has_maintainer {
for (my $i = $start; $i < $end; $i++) {
my $line = $typevalue[$i];
- if ($line =~ m/^(\C):\s*(.*)/) {
+ if ($line =~ m/^([A-Z]):\s*(.*)/) {
my $type = $1;
my $value = $2;
if ($type eq 'M') {
@@ -600,7 +600,7 @@ sub get_maintainers {
for ($i = $start; $i < $end; $i++) {
my $line = $typevalue[$i];
- if ($line =~ m/^(\C):\s*(.*)/) {
+ if ($line =~ m/^([A-Z]):\s*(.*)/) {
my $type = $1;
my $value = $2;
if ($type eq 'X') {
@@ -615,7 +615,7 @@ sub get_maintainers {
if (!$exclude) {
for ($i = $start; $i < $end; $i++) {
my $line = $typevalue[$i];
- if ($line =~ m/^(\C):\s*(.*)/) {
+ if ($line =~ m/^([A-Z]):\s*(.*)/) {
my $type = $1;
my $value = $2;
if ($type eq 'F') {
@@ -917,7 +917,7 @@ sub find_first_section {
while ($index < @typevalue) {
my $tv = $typevalue[$index];
- if (($tv =~ m/^(\C):\s*(.*)/)) {
+ if (($tv =~ m/^([A-Z]):\s*(.*)/)) {
last;
}
$index++;
@@ -931,7 +931,7 @@ sub find_starting_index {
while ($index > 0) {
my $tv = $typevalue[$index];
- if (!($tv =~ m/^(\C):\s*(.*)/)) {
+ if (!($tv =~ m/^([A-Z]):\s*(.*)/)) {
last;
}
$index--;
@@ -945,7 +945,7 @@ sub find_ending_index {
while ($index < @typevalue) {
my $tv = $typevalue[$index];
- if (!($tv =~ m/^(\C):\s*(.*)/)) {
+ if (!($tv =~ m/^([A-Z]):\s*(.*)/)) {
last;
}
$index++;
@@ -971,7 +971,7 @@ sub get_maintainer_role {
for ($i = $start + 1; $i < $end; $i++) {
my $tv = $typevalue[$i];
- if ($tv =~ m/^(\C):\s*(.*)/) {
+ if ($tv =~ m/^([A-Z]):\s*(.*)/) {
my $ptype = $1;
my $pvalue = $2;
if ($ptype eq "S") {
@@ -1030,7 +1030,7 @@ sub add_categories {
for ($i = $start + 1; $i < $end; $i++) {
my $tv = $typevalue[$i];
- if ($tv =~ m/^(\C):\s*(.*)/) {
+ if ($tv =~ m/^([A-Z]):\s*(.*)/) {
my $ptype = $1;
my $pvalue = $2;
if ($ptype eq "L") {
@@ -1072,7 +1072,7 @@ sub add_categories {
if ($name eq "") {
if ($i > 0) {
my $tv = $typevalue[$i - 1];
- if ($tv =~ m/^(\C):\s*(.*)/) {
+ if ($tv =~ m/^([A-Z]):\s*(.*)/) {
if ($1 eq "P") {
$name = $2;
$pvalue = format_email($name, $address, $email_usename);
--
2.5.0
2
1
Hello Tom,
please pull from u-boot-ubi.git master
The following changes since commit 8e8106dcd540e4c735da6a0b71919747c15ce93a:
altera_qspi: allow ctrl-c to abort the erase ops (2015-12-28 09:32:43 +0800)
are available in the git repository at:
git://git.denx.de/u-boot-ubi.git master
for you to fetch changes up to 6a4595600b968bafcae8ad603bfc1175b6efe1d8:
UBI: Fix compile error when CONFIG_UBI_SILENCE_MSG defined (2016-01-04 09:11:10 +0100)
----------------------------------------------------------------
Ladislav Michl (1):
UBI: Fix compile error when CONFIG_UBI_SILENCE_MSG defined
drivers/mtd/ubi/io.c | 1 -
1 file changed, 1 deletion(-)
bye,
Heiko
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
2
1

[U-Boot] [PATCH 4/4] rapidio: add driver for TI KeyStone RapidIO
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
04 Jan '16
From: Aurelien Jacquiot <a-jacquiot(a)ti.com>
This commit includes the KeyStone device driver for RapidIO
allowing to use the RapidIO boot functionality.
Today only K2HK devices have RapidIO support.
Signed-off-by: Aurelien Jacquiot <a-jacquiot(a)ti.com>
---
Makefile | 1 +
configs/k2hk_evm_defconfig | 2 +
drivers/Kconfig | 2 +
drivers/rapidio/Kconfig | 5 +
drivers/rapidio/Makefile | 8 +
drivers/rapidio/keystone_rio.c | 1374 ++++++++++++++++++++++++++++++++++++++++
drivers/rapidio/keystone_rio.h | 650 +++++++++++++++++++
7 files changed, 2042 insertions(+), 0 deletions(-)
create mode 100644 drivers/rapidio/Kconfig
create mode 100644 drivers/rapidio/Makefile
create mode 100644 drivers/rapidio/keystone_rio.c
create mode 100644 drivers/rapidio/keystone_rio.h
diff --git a/Makefile b/Makefile
index 3c21f8d..67e6b25 100644
--- a/Makefile
+++ b/Makefile
@@ -661,6 +661,7 @@ libs-y += drivers/usb/musb/
libs-y += drivers/usb/musb-new/
libs-y += drivers/usb/phy/
libs-y += drivers/usb/ulpi/
+libs-y += drivers/rapidio/
libs-y += common/
libs-$(CONFIG_API) += api/
libs-$(CONFIG_HAS_POST) += post/
diff --git a/configs/k2hk_evm_defconfig b/configs/k2hk_evm_defconfig
index d5a4ef2..e350ea4 100644
--- a/configs/k2hk_evm_defconfig
+++ b/configs/k2hk_evm_defconfig
@@ -11,3 +11,5 @@ CONFIG_SYS_PROMPT="K2HK EVM # "
CONFIG_OF_CONTROL=y
CONFIG_DM=y
CONFIG_SPI_FLASH=y
+CONFIG_CMD_RIO=y
+CONFIG_KEYSTONE_RIO=y
diff --git a/drivers/Kconfig b/drivers/Kconfig
index c481e93..37a37a6 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -70,6 +70,8 @@ source "drivers/video/Kconfig"
source "drivers/watchdog/Kconfig"
+source "drivers/rapidio/Kconfig"
+
config PHYS_TO_BUS
bool "Custom physical to bus address mapping"
help
diff --git a/drivers/rapidio/Kconfig b/drivers/rapidio/Kconfig
new file mode 100644
index 0000000..2560957
--- /dev/null
+++ b/drivers/rapidio/Kconfig
@@ -0,0 +1,5 @@
+config KEYSTONE_RIO
+ bool "Support for TI KeyStone RapidIO"
+ depends on TARGET_K2HK_EVM
+ ---help---
+ Say Y here if you want to use RapidIO to boot your board.
diff --git a/drivers/rapidio/Makefile b/drivers/rapidio/Makefile
new file mode 100644
index 0000000..bd7ec50
--- /dev/null
+++ b/drivers/rapidio/Makefile
@@ -0,0 +1,8 @@
+#
+# (C) Copyright 2015
+# Texas Instruments Incorporated, <www.ti.com>
+#
+# SPDX-License-Identifier: GPL-2.0+
+#
+
+obj-$(CONFIG_KEYSTONE_RIO) += keystone_rio.o
diff --git a/drivers/rapidio/keystone_rio.c b/drivers/rapidio/keystone_rio.c
new file mode 100644
index 0000000..9fe93c3
--- /dev/null
+++ b/drivers/rapidio/keystone_rio.c
@@ -0,0 +1,1374 @@
+/*
+ * (C) Copyright 2015
+ * Texas Instruments Incorporated, <www.ti.com>
+ * Authors: Aurelien Jacquiot <a-jacquiot(a)ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <command.h>
+#include <malloc.h>
+#include <asm/dma-mapping.h>
+#include <asm/io.h>
+#include <asm/arch/psc_defs.h>
+#include <rio.h>
+
+#include "keystone_rio.h"
+
+#define DRIVER_VER "v1.1"
+
+#ifdef CONFIG_SOC_K2HK
+#define KEYSTONE_RIO_IS_K2 1
+#else
+#define KEYSTONE_RIO_IS_K2 0
+#endif
+
+#define K2_SERDES(p) ((p)->board_rio_cfg.keystone2_serdes)
+
+static unsigned int rio_dbg;
+
+#define debug_rio(fmt, args...) if (rio_dbg) printf(fmt, ##args)
+
+/*
+ * Main KeyStone RapidIO driver data
+ */
+struct keystone_rio_data {
+ int riohdid;
+ u32 rio_pe_feat;
+
+ u32 ports_registering;
+ u32 port_chk_cnt;
+
+ u32 *jtagid_reg;
+ u32 *serdes_sts_reg;
+ struct keystone_srio_serdes_regs *serdes_regs;
+ struct keystone_rio_regs *regs;
+
+ struct keystone_rio_car_csr_regs *car_csr_regs;
+ struct keystone_rio_serial_port_regs *serial_port_regs;
+ struct keystone_rio_err_mgmt_regs *err_mgmt_regs;
+ struct keystone_rio_phy_layer_regs *phy_regs;
+ struct keystone_rio_transport_layer_regs *transport_regs;
+ struct keystone_rio_pkt_buf_regs *pkt_buf_regs;
+ struct keystone_rio_evt_mgmt_regs *evt_mgmt_regs;
+ struct keystone_rio_port_write_regs *port_write_regs;
+ struct keystone_rio_link_layer_regs *link_regs;
+ struct keystone_rio_fabric_regs *fabric_regs;
+ u32 car_csr_regs_base;
+
+ struct keystone_rio_board_controller_info board_rio_cfg;
+} __krio_priv;
+
+/*--------------------- Maintenance Request Management ---------------------*/
+
+static u32 keystone_rio_dio_get_lsu_cc(u32 lsu_id, u8 ltid, u8 *lcb,
+ struct keystone_rio_data *krio_priv)
+{
+ u32 idx;
+ u32 shift;
+ u32 value;
+ u32 cc;
+ /* lSU shadow register status mapping */
+ u32 lsu_index[8] = { 0, 9, 15, 20, 24, 33, 39, 44 };
+
+ /* Compute LSU stat index from LSU id and LTID */
+ idx = (lsu_index[lsu_id] + ltid) >> 3;
+ shift = ((lsu_index[lsu_id] + ltid) & 0x7) << 2;
+
+ /* Get completion code and context */
+ value = readl(&(krio_priv->regs->lsu_stat_reg[idx]));
+ cc = (value >> (shift + 1)) & 0x7;
+ *lcb = (value >> shift) & 0x1;
+
+ return cc;
+}
+
+/**
+ * maint_request - Perform a maintenance request
+ * @port_id: output port ID of transaction
+ * @dest_id: destination ID of target device
+ * @hopcount: hopcount for this request
+ * @offset: offset in the RapidIO configuration space
+ * @buff: dma address of the data on the host
+ * @buff_len: length of the data
+ * @size: 1 for 16bit, 0 for 8bit ID size
+ * @type: packet type
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+static inline int keystone_rio_maint_request(
+ int port_id,
+ u32 dest_id,
+ u8 hopcount,
+ u32 offset,
+ dma_addr_t buff,
+ int buff_len,
+ u16 size,
+ u16 type,
+ struct keystone_rio_data *krio_priv)
+{
+ unsigned int count;
+ unsigned int status = 0;
+ unsigned int res = 0;
+ u8 context;
+ u8 ltid;
+
+ /* Check is there is space in the LSU shadow reg and that it is free */
+ count = 0;
+ while (1) {
+ status = readl(&(krio_priv->regs->lsu_reg[0].busy_full));
+ if (((status & KEYSTONE_RIO_LSU_FULL_MASK) == 0x0) &&
+ ((status & KEYSTONE_RIO_LSU_BUSY_MASK) == 0x0))
+ break;
+ count++;
+
+ if (count >= KEYSTONE_RIO_TIMEOUT_CNT) {
+ debug_rio("RIO: no LSU available, status = 0x%x\n",
+ status);
+ res = -1;
+ goto out;
+ }
+ udelay(1);
+ }
+
+ /* Get LCB and LTID, LSU reg 6 is already read */
+ context = (status >> 4) & 0x1;
+ ltid = status & 0xf;
+
+ /* LSU Reg 0 - MSB of RapidIO address */
+ writel(0, &(krio_priv->regs->lsu_reg[0].addr_msb));
+
+ /* LSU Reg 1 - LSB of destination */
+ writel(offset, &(krio_priv->regs->lsu_reg[0].addr_lsb_cfg_ofs));
+
+ /* LSU Reg 2 - source address */
+ writel(buff, &(krio_priv->regs->lsu_reg[0].dsp_addr));
+
+ /* LSU Reg 3 - byte count */
+ writel(buff_len,
+ &(krio_priv->regs->lsu_reg[0].dbell_val_byte_cnt));
+
+ /* LSU Reg 4 - */
+ writel(((port_id << 8)
+ | (KEYSTONE_RIO_LSU_PRIO << 4)
+ | (size ? (1 << 10) : 0)
+ | ((u32) dest_id << 16)),
+ &(krio_priv->regs->lsu_reg[0].destid));
+
+ /* LSU Reg 5 */
+ writel(((hopcount & 0xff) << 8) | (type & 0xff),
+ &(krio_priv->regs->lsu_reg[0].dbell_info_fttype));
+
+ /* Retrieve our completion code */
+ count = 0;
+ res = 0;
+ while (1) {
+ u8 lcb;
+
+ status = keystone_rio_dio_get_lsu_cc(0, ltid, &lcb, krio_priv);
+ if (lcb == context)
+ break;
+ count++;
+ if (count >= KEYSTONE_RIO_TIMEOUT_CNT) {
+ debug_rio(
+ "RIO: timeout %d, ltid = %d, context = %d, lcb = %d, cc = %d\n",
+ count, ltid, context, lcb, status);
+ res = -2;
+ break;
+ }
+ udelay(1);
+ }
+out:
+ if (res)
+ return res;
+
+ if (status)
+ debug_rio("RIO: transfer error = 0x%x\n", status);
+
+ switch (status) {
+ case KEYSTONE_RIO_LSU_CC_TIMEOUT:
+ case KEYSTONE_RIO_LSU_CC_XOFF:
+ case KEYSTONE_RIO_LSU_CC_ERROR:
+ case KEYSTONE_RIO_LSU_CC_INVALID:
+ case KEYSTONE_RIO_LSU_CC_DMA:
+ return -3;
+ break;
+ case KEYSTONE_RIO_LSU_CC_RETRY:
+ return -4;
+ break;
+ case KEYSTONE_RIO_LSU_CC_CANCELED:
+ return -5;
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+/**
+ * rio_config_read - Generate a RIO read maintenance transaction
+ * @portid: Output port ID of transaction
+ * @destid: Destination ID of transaction
+ * @hopcount: Number of hops to target device
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @val: Location to be read into
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_config_read(int portid,
+ u16 destid,
+ u8 hopcount,
+ u32 offset,
+ int len,
+ u32 *val)
+{
+ struct keystone_rio_data *krio_priv = &__krio_priv;
+ u32 *tbuf;
+ int res;
+ dma_addr_t dma;
+
+ tbuf = malloc(len);
+ if (!tbuf)
+ return -1;
+
+ memset(tbuf, 0, len);
+
+ dma = dma_map_single(tbuf, len, DMA_FROM_DEVICE);
+
+ res = keystone_rio_maint_request(portid, destid, hopcount, offset, dma,
+ len, krio_priv->board_rio_cfg.size,
+ KEYSTONE_RIO_PACKET_TYPE_MAINT_R,
+ krio_priv);
+
+ dma_unmap_single((void *)tbuf, len, dma);
+
+ /* Taking care of byteswap */
+ switch (len) {
+ case 1:
+ *val = *((u8 *)tbuf);
+ break;
+ case 2:
+ *val = ntohs(*((u16 *)tbuf));
+ break;
+ default:
+ *val = ntohl(*((u32 *)tbuf));
+ break;
+ }
+
+ free(tbuf);
+
+ debug_rio(
+ "RIO: %s portid %d destid %d hopcount %d offset 0x%x len %d val 0x%x res %d\n",
+ __func__, portid, destid, hopcount, offset, len, *val,
+ res);
+
+ return res;
+}
+
+/**
+ * rio_config_write - Generate a RIO write maintenance transaction
+ * @portid: Output port ID of transaction
+ * @destid: Destination ID of transaction
+ * @hopcount: Number of hops to target device
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @val: Value to be written
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_config_write(int portid,
+ u16 destid,
+ u8 hopcount,
+ u32 offset,
+ int len,
+ u32 val)
+{
+ struct keystone_rio_data *krio_priv = &__krio_priv;
+ u32 *tbuf;
+ int res;
+ dma_addr_t dma;
+
+ tbuf = malloc(len);
+ if (!tbuf)
+ return -1;
+
+ memset(tbuf, 0, len);
+
+ /* Taking care of byteswap */
+ switch (len) {
+ case 1:
+ *tbuf = ((u8) val);
+ break;
+ case 2:
+ *tbuf = htons((u16) val);
+ break;
+ default:
+ *tbuf = htonl((u32) val);
+ break;
+ }
+
+ dma = dma_map_single(tbuf, len, DMA_TO_DEVICE);
+
+ res = keystone_rio_maint_request(portid, destid, hopcount, offset, dma,
+ len, krio_priv->board_rio_cfg.size,
+ KEYSTONE_RIO_PACKET_TYPE_MAINT_W,
+ krio_priv);
+
+ dma_unmap_single((void *)tbuf, len, dma);
+
+ debug_rio(
+ "RIO: %s portid %d destid %d hopcount %d offset 0x%x len %d val 0x%x res %d\n",
+ __func__, portid, destid, hopcount, offset, len, val,
+ res);
+
+ free(tbuf);
+
+ return res;
+}
+
+/**
+ * rio_local_config_read - RIO local config space read
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @data: Value to be read into
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_local_config_read(u32 offset, int len, u32 *data)
+{
+ struct keystone_rio_data *krio_priv = &__krio_priv;
+
+ *data = readl((void *)(krio_priv->car_csr_regs_base + offset));
+
+ debug_rio("RIO: %s offset 0x%x data 0x%x\n",
+ __func__, offset, *data);
+
+ return 0;
+}
+
+/**
+ * rio_local_config_write - RIO local config space write
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @data: Value to be written
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_local_config_write(u32 offset, int len, u32 data)
+{
+ struct keystone_rio_data *krio_priv = &__krio_priv;
+
+ debug_rio("RIO: %s offset 0x%x data 0x%x\n",
+ __func__, offset, data);
+
+ writel(data, (void *)(krio_priv->car_csr_regs_base + offset));
+
+ return 0;
+}
+
+/*------------------------- RapidIO hw controller setup ---------------------*/
+
+struct keystone_lane_config {
+ int start; /* lane start number of the port */
+ int end; /* lane end number of the port */
+};
+
+/*
+ * Table with the various lanes per port configuration modes:
+ * path mode 0: 4 ports in 1x
+ * path mode 1: 3 ports in 2x/1x
+ * path mode 2: 3 ports in 1x/2x
+ * path mode 3: 2 ports in 2x
+ * path mode 4: 1 ports in 4x
+ */
+static struct keystone_lane_config keystone_lane_configs[5][4] = {
+ { {0, 1}, {1, 2}, {2, 3}, {3, 4} },
+ { {0, 2}, {-1, -1}, {2, 3}, {3, 4} },
+ { {0, 1}, {1, 2}, {2, 4}, {-1, -1} },
+ { {0, 2}, {-1, -1}, {2, 4}, {-1, -1} },
+ { {0, 4}, {-1, -1}, {-1, -1}, {-1, -1} },
+};
+
+/* Retrieve the corresponding lanes bitmask from ports bitmask and path_mode */
+static int keystone_rio_get_lane_config(u32 ports, u32 path_mode)
+{
+ u32 lanes = 0;
+
+ while (ports) {
+ u32 lane;
+ u32 port = ffs(ports) - 1;
+ ports &= ~(1 << port);
+
+ if (keystone_lane_configs[path_mode][port].start == -1)
+ return -1;
+
+ for (lane = keystone_lane_configs[path_mode][port].start;
+ lane < keystone_lane_configs[path_mode][port].end;
+ lane++) {
+ lanes |= (1 << lane);
+ }
+ }
+ return (int) lanes;
+}
+
+#define reg_fmkr(msb, lsb, val) \
+ (((val) & ((1 << ((msb) - (lsb) + 1)) - 1)) << (lsb))
+
+#define reg_finsr(addr, msb, lsb, val) \
+ writel(((readl(addr) \
+ & ~(((1 << ((msb) - (lsb) + 1)) - 1) << (lsb))) \
+ | reg_fmkr(msb, lsb, val)), (addr))
+
+static void k2_rio_serdes_init_3g(u32 lanes,
+ struct keystone_rio_data *krio_priv)
+{
+ void __iomem *reg = (void __iomem *)krio_priv->serdes_regs;
+
+ /* Uses 6G half rate configuration */
+ reg_finsr((reg + 0x0000), 31, 24, 0x00);
+ reg_finsr((reg + 0x0014), 7, 0, 0x82);
+ reg_finsr((reg + 0x0014), 15, 8, 0x82);
+ reg_finsr((reg + 0x0060), 7, 0, 0x48);
+ reg_finsr((reg + 0x0060), 15, 8, 0x2c);
+ reg_finsr((reg + 0x0060), 23, 16, 0x13);
+ reg_finsr((reg + 0x0064), 15, 8, 0xc7);
+ reg_finsr((reg + 0x0064), 23, 16, 0xc3);
+ reg_finsr((reg + 0x0078), 15, 8, 0xc0);
+
+ /* Setting lane 0 SerDes to 3GHz */
+ reg_finsr((reg + 0x0204), 7, 0, 0x80);
+ reg_finsr((reg + 0x0204), 31, 24, 0x78);
+ reg_finsr((reg + 0x0208), 7, 0, 0x24);
+ reg_finsr((reg + 0x020c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0210), 31, 24, 0x1b);
+ reg_finsr((reg + 0x0214), 7, 0, 0x7c);
+ reg_finsr((reg + 0x0214), 15, 8, 0x6e);
+ reg_finsr((reg + 0x0218), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0218), 23, 16, 0x80);
+ reg_finsr((reg + 0x0218), 31, 24, 0x75);
+ reg_finsr((reg + 0x022c), 15, 8, 0x08);
+ reg_finsr((reg + 0x022c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0280), 7, 0, 0x70);
+ reg_finsr((reg + 0x0280), 23, 16, 0x70);
+ reg_finsr((reg + 0x0284), 7, 0, 0x85);
+ reg_finsr((reg + 0x0284), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0284), 31, 24, 0x1d);
+ reg_finsr((reg + 0x028c), 15, 8, 0x3b);
+
+ /* Setting lane 1 SerDes to 3GHz */
+ reg_finsr((reg + 0x0404), 7, 0, 0x80);
+ reg_finsr((reg + 0x0404), 31, 24, 0x78);
+ reg_finsr((reg + 0x0408), 7, 0, 0x24);
+ reg_finsr((reg + 0x040c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0410), 31, 24, 0x1b);
+ reg_finsr((reg + 0x0414), 7, 0, 0x7c);
+ reg_finsr((reg + 0x0414), 15, 8, 0x6e);
+ reg_finsr((reg + 0x0418), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0418), 23, 16, 0x80);
+ reg_finsr((reg + 0x0418), 31, 24, 0x75);
+ reg_finsr((reg + 0x042c), 15, 8, 0x08);
+ reg_finsr((reg + 0x042c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0480), 7, 0, 0x70);
+ reg_finsr((reg + 0x0480), 23, 16, 0x70);
+ reg_finsr((reg + 0x0484), 7, 0, 0x85);
+ reg_finsr((reg + 0x0484), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0484), 31, 24, 0x1d);
+ reg_finsr((reg + 0x048c), 15, 8, 0x3b);
+
+ /* Setting lane 2 SerDes to 3GHz */
+ reg_finsr((reg + 0x0604), 7, 0, 0x80);
+ reg_finsr((reg + 0x0604), 31, 24, 0x78);
+ reg_finsr((reg + 0x0608), 7, 0, 0x24);
+ reg_finsr((reg + 0x060c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0610), 31, 24, 0x1b);
+ reg_finsr((reg + 0x0614), 7, 0, 0x7c);
+ reg_finsr((reg + 0x0614), 15, 8, 0x6e);
+ reg_finsr((reg + 0x0618), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0618), 23, 16, 0x80);
+ reg_finsr((reg + 0x0618), 31, 24, 0x75);
+ reg_finsr((reg + 0x062c), 15, 8, 0x08);
+ reg_finsr((reg + 0x062c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0680), 7, 0, 0x70);
+ reg_finsr((reg + 0x0680), 23, 16, 0x70);
+ reg_finsr((reg + 0x0684), 7, 0, 0x85);
+ reg_finsr((reg + 0x0684), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0684), 31, 24, 0x1d);
+ reg_finsr((reg + 0x068c), 15, 8, 0x3b);
+
+ /* Setting lane 3 SerDes to 3GHz */
+ reg_finsr((reg + 0x0804), 7, 0, 0x80);
+ reg_finsr((reg + 0x0804), 31, 24, 0x78);
+ reg_finsr((reg + 0x0808), 7, 0, 0x24);
+ reg_finsr((reg + 0x080c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0810), 31, 24, 0x1b);
+ reg_finsr((reg + 0x0814), 7, 0, 0x7c);
+ reg_finsr((reg + 0x0814), 15, 8, 0x6e);
+ reg_finsr((reg + 0x0818), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0818), 23, 16, 0x80);
+ reg_finsr((reg + 0x0818), 31, 24, 0x75);
+ reg_finsr((reg + 0x082c), 15, 8, 0x08);
+ reg_finsr((reg + 0x082c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0880), 7, 0, 0x70);
+ reg_finsr((reg + 0x0880), 23, 16, 0x70);
+ reg_finsr((reg + 0x0884), 7, 0, 0x85);
+ reg_finsr((reg + 0x0884), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0884), 31, 24, 0x1d);
+ reg_finsr((reg + 0x088c), 15, 8, 0x3b);
+
+ reg_finsr((reg + 0x0a00), 15, 8, 0x08);
+ reg_finsr((reg + 0x0a08), 23, 16, 0x72);
+ reg_finsr((reg + 0x0a08), 31, 24, 0x37);
+ reg_finsr((reg + 0x0a30), 15, 8, 0x77);
+ reg_finsr((reg + 0x0a30), 23, 16, 0x77);
+ reg_finsr((reg + 0x0a84), 15, 8, 0x06);
+ reg_finsr((reg + 0x0a94), 31, 24, 0x10);
+ reg_finsr((reg + 0x0aa0), 31, 24, 0x81);
+ reg_finsr((reg + 0x0abc), 31, 24, 0xff);
+ reg_finsr((reg + 0x0ac0), 7, 0, 0x8b);
+ reg_finsr((reg + 0x0a48), 15, 8, 0x8c);
+ reg_finsr((reg + 0x0a48), 23, 16, 0xfd);
+ reg_finsr((reg + 0x0a54), 7, 0, 0x72);
+ reg_finsr((reg + 0x0a54), 15, 8, 0xec);
+ reg_finsr((reg + 0x0a54), 23, 16, 0x2f);
+ reg_finsr((reg + 0x0a58), 15, 8, 0x21);
+ reg_finsr((reg + 0x0a58), 23, 16, 0xf9);
+ reg_finsr((reg + 0x0a58), 31, 24, 0x00);
+ reg_finsr((reg + 0x0a5c), 7, 0, 0x60);
+ reg_finsr((reg + 0x0a5c), 15, 8, 0x00);
+ reg_finsr((reg + 0x0a5c), 23, 16, 0x04);
+ reg_finsr((reg + 0x0a5c), 31, 24, 0x00);
+ reg_finsr((reg + 0x0a60), 7, 0, 0x00);
+ reg_finsr((reg + 0x0a60), 15, 8, 0x80);
+ reg_finsr((reg + 0x0a60), 23, 16, 0x00);
+ reg_finsr((reg + 0x0a60), 31, 24, 0x00);
+ reg_finsr((reg + 0x0a64), 7, 0, 0x20);
+ reg_finsr((reg + 0x0a64), 15, 8, 0x12);
+ reg_finsr((reg + 0x0a64), 23, 16, 0x58);
+ reg_finsr((reg + 0x0a64), 31, 24, 0x0c);
+ reg_finsr((reg + 0x0a68), 7, 0, 0x02);
+ reg_finsr((reg + 0x0a68), 15, 8, 0x06);
+ reg_finsr((reg + 0x0a68), 23, 16, 0x3b);
+ reg_finsr((reg + 0x0a68), 31, 24, 0xe1);
+ reg_finsr((reg + 0x0a6c), 7, 0, 0xc1);
+ reg_finsr((reg + 0x0a6c), 15, 8, 0x4c);
+ reg_finsr((reg + 0x0a6c), 23, 16, 0x07);
+ reg_finsr((reg + 0x0a6c), 31, 24, 0xb8);
+ reg_finsr((reg + 0x0a70), 7, 0, 0x89);
+ reg_finsr((reg + 0x0a70), 15, 8, 0xe9);
+ reg_finsr((reg + 0x0a70), 23, 16, 0x02);
+ reg_finsr((reg + 0x0a70), 31, 24, 0x3f);
+ reg_finsr((reg + 0x0a74), 7, 0, 0x01);
+ reg_finsr((reg + 0x0b20), 23, 16, 0x37);
+ reg_finsr((reg + 0x0b1c), 31, 24, 0x37);
+ reg_finsr((reg + 0x0b20), 7, 0, 0x5d);
+ reg_finsr((reg + 0x0000), 7, 0, 0x03);
+ reg_finsr((reg + 0x0a00), 7, 0, 0x5f);
+}
+
+static void k2_rio_serdes_init_5g(u32 lanes,
+ struct keystone_rio_data *krio_priv)
+{
+ void __iomem *reg = (void __iomem *)krio_priv->serdes_regs;
+
+ /* Uses 5Gbps full rate configuration by default */
+ reg_finsr((reg + 0x0000), 31, 24, 0x00);
+ reg_finsr((reg + 0x0014), 7, 0, 0x82);
+ reg_finsr((reg + 0x0014), 15, 8, 0x82);
+ reg_finsr((reg + 0x0060), 7, 0, 0x38);
+ reg_finsr((reg + 0x0060), 15, 8, 0x24);
+ reg_finsr((reg + 0x0060), 23, 16, 0x14);
+ reg_finsr((reg + 0x0064), 15, 8, 0xc7);
+ reg_finsr((reg + 0x0064), 23, 16, 0xc3);
+ reg_finsr((reg + 0x0078), 15, 8, 0xc0);
+
+ /* Setting lane 0 SerDes to 5GHz */
+ reg_finsr((reg + 0x0204), 7, 0, 0x80);
+ reg_finsr((reg + 0x0204), 31, 24, 0x78);
+ reg_finsr((reg + 0x0208), 7, 0, 0x26);
+ reg_finsr((reg + 0x020c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0214), 7, 0, 0x38);
+ reg_finsr((reg + 0x0214), 15, 8, 0x6f);
+ reg_finsr((reg + 0x0218), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0218), 23, 16, 0x80);
+ reg_finsr((reg + 0x0218), 31, 24, 0x75);
+ reg_finsr((reg + 0x022c), 15, 8, 0x08);
+ reg_finsr((reg + 0x022c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0280), 7, 0, 0x86);
+ reg_finsr((reg + 0x0280), 23, 16, 0x86);
+ reg_finsr((reg + 0x0284), 7, 0, 0x85);
+ reg_finsr((reg + 0x0284), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0284), 31, 24, 0x1d);
+ reg_finsr((reg + 0x028c), 15, 8, 0x2c);
+
+ /* Setting lane 1 SerDes to 5GHz */
+ reg_finsr((reg + 0x0404), 7, 0, 0x80);
+ reg_finsr((reg + 0x0404), 31, 24, 0x78);
+ reg_finsr((reg + 0x0408), 7, 0, 0x26);
+ reg_finsr((reg + 0x040c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0414), 7, 0, 0x38);
+ reg_finsr((reg + 0x0414), 15, 8, 0x6f);
+ reg_finsr((reg + 0x0418), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0418), 23, 16, 0x80);
+ reg_finsr((reg + 0x0418), 31, 24, 0x75);
+ reg_finsr((reg + 0x042c), 15, 8, 0x08);
+ reg_finsr((reg + 0x042c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0480), 7, 0, 0x86);
+ reg_finsr((reg + 0x0480), 23, 16, 0x86);
+ reg_finsr((reg + 0x0484), 7, 0, 0x85);
+ reg_finsr((reg + 0x0484), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0484), 31, 24, 0x1d);
+ reg_finsr((reg + 0x048c), 15, 8, 0x2c);
+
+ /* Setting lane 2 SerDes to 5GHz */
+ reg_finsr((reg + 0x0604), 7, 0, 0x80);
+ reg_finsr((reg + 0x0604), 31, 24, 0x78);
+ reg_finsr((reg + 0x0608), 7, 0, 0x26);
+ reg_finsr((reg + 0x060c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0614), 7, 0, 0x38);
+ reg_finsr((reg + 0x0614), 15, 8, 0x6f);
+ reg_finsr((reg + 0x0618), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0618), 23, 16, 0x80);
+ reg_finsr((reg + 0x0618), 31, 24, 0x75);
+ reg_finsr((reg + 0x062c), 15, 8, 0x08);
+ reg_finsr((reg + 0x062c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0680), 7, 0, 0x86);
+ reg_finsr((reg + 0x0680), 23, 16, 0x86);
+ reg_finsr((reg + 0x0684), 7, 0, 0x85);
+ reg_finsr((reg + 0x0684), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0684), 31, 24, 0x1d);
+ reg_finsr((reg + 0x068c), 15, 8, 0x2c);
+
+ /* Setting lane 3 SerDes to 5GHz */
+ reg_finsr((reg + 0x0804), 7, 0, 0x80);
+ reg_finsr((reg + 0x0804), 31, 24, 0x78);
+ reg_finsr((reg + 0x0808), 7, 0, 0x26);
+ reg_finsr((reg + 0x080c), 31, 24, 0x02);
+ reg_finsr((reg + 0x0814), 7, 0, 0x38);
+ reg_finsr((reg + 0x0814), 15, 8, 0x6f);
+ reg_finsr((reg + 0x0818), 7, 0, 0xe4);
+ reg_finsr((reg + 0x0818), 23, 16, 0x80);
+ reg_finsr((reg + 0x0818), 31, 24, 0x75);
+ reg_finsr((reg + 0x082c), 15, 8, 0x08);
+ reg_finsr((reg + 0x082c), 23, 16, 0x20);
+ reg_finsr((reg + 0x0880), 7, 0, 0x86);
+ reg_finsr((reg + 0x0880), 23, 16, 0x86);
+ reg_finsr((reg + 0x0884), 7, 0, 0x85);
+ reg_finsr((reg + 0x0884), 23, 16, 0x0f);
+ reg_finsr((reg + 0x0884), 31, 24, 0x1d);
+ reg_finsr((reg + 0x088c), 15, 8, 0x2c);
+
+ reg_finsr((reg + 0x0a00), 15, 8, 0x80);
+ reg_finsr((reg + 0x0a08), 23, 16, 0xd2);
+ reg_finsr((reg + 0x0a08), 31, 24, 0x38);
+ reg_finsr((reg + 0x0a30), 15, 8, 0x8d);
+ reg_finsr((reg + 0x0a30), 23, 16, 0x8d);
+ reg_finsr((reg + 0x0a84), 15, 8, 0x06);
+ reg_finsr((reg + 0x0a94), 31, 24, 0x10);
+ reg_finsr((reg + 0x0aa0), 31, 24, 0x81);
+ reg_finsr((reg + 0x0abc), 31, 24, 0xff);
+ reg_finsr((reg + 0x0ac0), 7, 0, 0x8b);
+ reg_finsr((reg + 0x0a48), 15, 8, 0x8c);
+ reg_finsr((reg + 0x0a48), 23, 16, 0xfd);
+ reg_finsr((reg + 0x0a54), 7, 0, 0x72);
+ reg_finsr((reg + 0x0a54), 15, 8, 0xec);
+ reg_finsr((reg + 0x0a54), 23, 16, 0x2f);
+ reg_finsr((reg + 0x0a58), 15, 8, 0x21);
+ reg_finsr((reg + 0x0a58), 23, 16, 0xf9);
+ reg_finsr((reg + 0x0a58), 31, 24, 0x00);
+ reg_finsr((reg + 0x0a5c), 7, 0, 0x60);
+ reg_finsr((reg + 0x0a5c), 15, 8, 0x00);
+ reg_finsr((reg + 0x0a5c), 23, 16, 0x04);
+ reg_finsr((reg + 0x0a5c), 31, 24, 0x00);
+ reg_finsr((reg + 0x0a60), 7, 0, 0x00);
+ reg_finsr((reg + 0x0a60), 15, 8, 0x80);
+ reg_finsr((reg + 0x0a60), 23, 16, 0x00);
+ reg_finsr((reg + 0x0a60), 31, 24, 0x00);
+ reg_finsr((reg + 0x0a64), 7, 0, 0x20);
+ reg_finsr((reg + 0x0a64), 15, 8, 0x12);
+ reg_finsr((reg + 0x0a64), 23, 16, 0x58);
+ reg_finsr((reg + 0x0a64), 31, 24, 0x0c);
+ reg_finsr((reg + 0x0a68), 7, 0, 0x02);
+ reg_finsr((reg + 0x0a68), 15, 8, 0x06);
+ reg_finsr((reg + 0x0a68), 23, 16, 0x3b);
+ reg_finsr((reg + 0x0a68), 31, 24, 0xe1);
+ reg_finsr((reg + 0x0a6c), 7, 0, 0xc1);
+ reg_finsr((reg + 0x0a6c), 15, 8, 0x4c);
+ reg_finsr((reg + 0x0a6c), 23, 16, 0x07);
+ reg_finsr((reg + 0x0a6c), 31, 24, 0xb8);
+ reg_finsr((reg + 0x0a70), 7, 0, 0x89);
+ reg_finsr((reg + 0x0a70), 15, 8, 0xe9);
+ reg_finsr((reg + 0x0a70), 23, 16, 0x02);
+ reg_finsr((reg + 0x0a70), 31, 24, 0x3f);
+ reg_finsr((reg + 0x0a74), 7, 0, 0x01);
+ reg_finsr((reg + 0x0b20), 23, 16, 0x37);
+ reg_finsr((reg + 0x0b1c), 31, 24, 0x37);
+ reg_finsr((reg + 0x0b20), 7, 0, 0x5d);
+ reg_finsr((reg + 0x0000), 7, 0, 0x03);
+ reg_finsr((reg + 0x0a00), 7, 0, 0x5f);
+}
+
+static void k2_rio_serdes_lane_enable(u32 lane, u32 rate,
+ struct keystone_rio_data *krio_priv)
+{
+ void *regs = (void *)krio_priv->serdes_regs;
+ u32 val;
+
+ /* Bit 28 Toggled. Bring it out of Reset TX PLL for all lanes */
+ val = readl(regs + 0x200 * (lane + 1) + 0x28);
+ val &= ~BIT(29);
+ writel(val, regs + 0x200 * (lane + 1) + 0x28);
+
+ /* Set Lane Control Rate */
+ switch (rate) {
+ case KEYSTONE_RIO_FULL_RATE:
+ writel(0xF0C0F0F0, regs + 0x1fe0 + 4 * lane);
+ break;
+ case KEYSTONE_RIO_HALF_RATE:
+ writel(0xF4C0F4F0, regs + 0x1fe0 + 4 * lane);
+ break;
+ case KEYSTONE_RIO_QUARTER_RATE:
+ writel(0xF8C0F8F0, regs + 0x1fe0 + 4 * lane);
+ break;
+ default:
+ return;
+ }
+}
+
+static int k2_rio_serdes_config(u32 lanes, u32 baud,
+ struct keystone_rio_data *krio_priv)
+{
+ void *regs = (void *)krio_priv->serdes_regs;
+ u32 rate;
+ u32 val;
+
+ /* Disable pll before configuring the SerDes registers */
+ writel(0x00000000, regs + 0x1ff4);
+
+ switch (baud) {
+ case KEYSTONE_RIO_BAUD_1_250:
+ rate = KEYSTONE_RIO_QUARTER_RATE;
+ k2_rio_serdes_init_5g(lanes, krio_priv);
+ break;
+ case KEYSTONE_RIO_BAUD_2_500:
+ rate = KEYSTONE_RIO_HALF_RATE;
+ k2_rio_serdes_init_5g(lanes, krio_priv);
+ break;
+ case KEYSTONE_RIO_BAUD_5_000:
+ rate = KEYSTONE_RIO_FULL_RATE;
+ k2_rio_serdes_init_5g(lanes, krio_priv);
+ break;
+ case KEYSTONE_RIO_BAUD_3_125:
+ rate = KEYSTONE_RIO_HALF_RATE;
+ k2_rio_serdes_init_3g(lanes, krio_priv);
+ break;
+ default:
+ printf("RIO: unsupported baud rate %d\n", baud);
+ return -1;
+ }
+
+ /* Enable serdes for requested lanes */
+ while (lanes) {
+ u32 lane = ffs(lanes) - 1;
+ lanes &= ~(1 << lane);
+
+ if (lane >= KEYSTONE_RIO_MAX_PORT)
+ return -1;
+
+ k2_rio_serdes_lane_enable(lane, rate, krio_priv);
+ }
+
+ /* Enable pll via the pll_ctrl 0x0014 */
+ writel(0xe0000000, regs + 0x1ff4);
+
+ /* Wait until CMU_OK bit is set */
+ do {
+ val = readl(regs + 0xbf8);
+ } while (!(val & BIT(16)));
+
+ return 0;
+}
+
+static int k2_rio_serdes_wait_lock(struct keystone_rio_data *krio_priv,
+ u32 lanes)
+{
+ u32 loop;
+ u32 val;
+ u32 val_mask;
+ void *regs = (void *)krio_priv->serdes_regs;
+
+ val_mask = lanes | (lanes << 8);
+
+ /* Wait for the SerDes PLL lock */
+ for (loop = 0; loop < 100000; loop++) {
+ /* read PLL_CTRL */
+ val = readl(regs + 0x1ff4);
+ if ((val & val_mask) == val_mask)
+ break;
+ udelay(10);
+ }
+
+ if (loop == 100000)
+ return -1;
+
+ return 0;
+}
+
+/**
+ * keystone_rio_hw_init - Configure a RapidIO controller
+ * @mode: serdes configuration
+ * @hostid: device id of the host
+ */
+static void keystone_rio_hw_init(u32 mode, u32 baud,
+ struct keystone_rio_data *krio_priv)
+{
+ u32 val;
+ u32 block;
+ struct keystone_serdes_config *serdes_config
+ = &(krio_priv->board_rio_cfg.serdes_config[mode]);
+
+ /* Set sRIO out of reset */
+ writel(0x00000011, &krio_priv->regs->pcr);
+
+ /* Clear BOOT_COMPLETE bit (allowing write) */
+ writel(0x00000000, &krio_priv->regs->per_set_cntl);
+
+ /* Enable blocks */
+ writel(1, &krio_priv->regs->gbl_en);
+ for (block = 0; block <= KEYSTONE_RIO_BLK_NUM; block++)
+ writel(1, &(krio_priv->regs->blk[block].enable));
+
+ /* Set control register 1 configuration */
+ writel(0x00000000, &krio_priv->regs->per_set_cntl1);
+
+ /* Set Control register */
+ writel(serdes_config->cfg_cntl, &krio_priv->regs->per_set_cntl);
+
+ if (K2_SERDES(krio_priv)) {
+ u32 path_mode = krio_priv->board_rio_cfg.path_mode;
+ u32 ports = krio_priv->board_rio_cfg.ports;
+ int res;
+
+ /* K2 SerDes main configuration */
+ res = keystone_rio_get_lane_config(ports, path_mode);
+ if (res > 0) {
+ u32 lanes = (u32) res;
+ res = k2_rio_serdes_config(lanes, baud, krio_priv);
+ }
+ } else {
+ u32 port;
+
+ /* K1 SerDes main configuration */
+ writel(serdes_config->serdes_cfg_pll,
+ &krio_priv->serdes_regs->pll);
+
+ /* Per-port SerDes configuration */
+ for (port = 0; port < KEYSTONE_RIO_MAX_PORT; port++) {
+ writel(serdes_config->rx_chan_config[port],
+ &krio_priv->serdes_regs->channel[port].rx);
+ writel(serdes_config->tx_chan_config[port],
+ &krio_priv->serdes_regs->channel[port].tx);
+ }
+
+ /* Check for RIO SerDes PLL lock */
+ do {
+ val = readl(krio_priv->serdes_sts_reg);
+ } while ((val & 0x1) != 0x1);
+ }
+
+ /* Set prescalar for ip_clk */
+ writel(serdes_config->prescalar_srv_clk,
+ &krio_priv->link_regs->prescalar_srv_clk);
+
+ /* Peripheral-specific configuration and capabilities */
+ writel(KEYSTONE_RIO_DEV_ID_VAL,
+ &krio_priv->car_csr_regs->dev_id);
+ writel(KEYSTONE_RIO_DEV_INFO_VAL,
+ &krio_priv->car_csr_regs->dev_info);
+ writel(KEYSTONE_RIO_ID_TI,
+ &krio_priv->car_csr_regs->assembly_id);
+ writel(KEYSTONE_RIO_EXT_FEAT_PTR,
+ &krio_priv->car_csr_regs->assembly_info);
+
+ /* Set host device id */
+ writel((krio_priv->riohdid & 0xffff)
+ | ((krio_priv->riohdid & 0xff) << 16),
+ &krio_priv->car_csr_regs->base_dev_id);
+
+ krio_priv->rio_pe_feat = RIO_PEF_PROCESSOR
+ | RIO_PEF_CTLS
+ | KEYSTONE_RIO_PEF_FLOW_CONTROL
+ | RIO_PEF_EXT_FEATURES
+ | RIO_PEF_ADDR_34
+ | RIO_PEF_STD_RT
+ | RIO_PEF_INB_DOORBELL
+ | RIO_PEF_INB_MBOX;
+
+ writel(krio_priv->rio_pe_feat,
+ &krio_priv->car_csr_regs->pe_feature);
+
+ writel(KEYSTONE_RIO_MAX_PORT << 8,
+ &krio_priv->car_csr_regs->sw_port);
+
+ writel((RIO_SRC_OPS_READ
+ | RIO_SRC_OPS_WRITE
+ | RIO_SRC_OPS_STREAM_WRITE
+ | RIO_SRC_OPS_WRITE_RESPONSE
+ | RIO_SRC_OPS_DATA_MSG
+ | RIO_SRC_OPS_DOORBELL
+ | RIO_SRC_OPS_ATOMIC_TST_SWP
+ | RIO_SRC_OPS_ATOMIC_INC
+ | RIO_SRC_OPS_ATOMIC_DEC
+ | RIO_SRC_OPS_ATOMIC_SET
+ | RIO_SRC_OPS_ATOMIC_CLR
+ | RIO_SRC_OPS_PORT_WRITE),
+ &krio_priv->car_csr_regs->src_op);
+
+ writel((RIO_DST_OPS_READ
+ | RIO_DST_OPS_WRITE
+ | RIO_DST_OPS_STREAM_WRITE
+ | RIO_DST_OPS_WRITE_RESPONSE
+ | RIO_DST_OPS_DATA_MSG
+ | RIO_DST_OPS_DOORBELL
+ | RIO_DST_OPS_PORT_WRITE),
+ &krio_priv->car_csr_regs->dest_op);
+
+ writel(RIO_PELL_ADDR_34,
+ &krio_priv->car_csr_regs->pe_logical_ctl);
+
+ val = (((KEYSTONE_RIO_SP_HDR_NEXT_BLK_PTR & 0xffff) << 16) |
+ KEYSTONE_RIO_SP_HDR_EP_REC_ID);
+ writel(val, &krio_priv->serial_port_regs->sp_maint_blk_hdr);
+
+ /* clear high bits of local config space base addr */
+ writel(0x00000000, &krio_priv->car_csr_regs->local_cfg_hbar);
+
+ /* set local config space base addr */
+ writel(0x00520000, &krio_priv->car_csr_regs->local_cfg_bar);
+
+ /* Enable HOST & MASTER_ENABLE bits */
+ writel(0xe0000000, &krio_priv->serial_port_regs->sp_gen_ctl);
+
+ /* set link timeout value */
+ writel(0x000FFF00,
+ &krio_priv->serial_port_regs->sp_link_timeout_ctl);
+
+ /* set response timeout value */
+ writel(0x000FFF00,
+ &krio_priv->serial_port_regs->sp_rsp_timeout_ctl);
+
+ /* allows SELF_RESET and PWDN_PORT resets to clear sticky reg bits */
+ writel(0x00000001, &krio_priv->link_regs->reg_rst_ctl);
+
+ /* Set error detection mode */
+ /* clear all errors */
+ writel(0x00000000, &krio_priv->err_mgmt_regs->err_det);
+
+ /* enable all error detection */
+ writel(0x00000000, &krio_priv->err_mgmt_regs->err_en);
+
+ /* set err det block header */
+ val = (((KEYSTONE_RIO_ERR_HDR_NEXT_BLK_PTR & 0xffff) << 16) |
+ KEYSTONE_RIO_ERR_EXT_FEAT_ID);
+ writel(val, &krio_priv->err_mgmt_regs->err_report_blk_hdr);
+
+ /* clear msb of err catptured addr reg */
+ writel(0x00000000, &krio_priv->err_mgmt_regs->h_addr_capt);
+
+ /* clear lsb of err catptured addr reg */
+ writel(0x00000000, &krio_priv->err_mgmt_regs->addr_capt);
+
+ /* clear err catptured source and dest devID reg */
+ writel(0x00000000, &krio_priv->err_mgmt_regs->id_capt);
+
+ /* clear err catptured packet info */
+ writel(0x00000000, &krio_priv->err_mgmt_regs->ctrl_capt);
+
+ /* Force all writes to finish */
+ val = readl(&krio_priv->err_mgmt_regs->ctrl_capt);
+}
+
+/**
+ * keystone_rio_start - Start RapidIO controller
+ */
+static void keystone_rio_start(struct keystone_rio_data *krio_priv)
+{
+ u32 val;
+
+ /* set PEREN bit to enable logical layer data flow */
+ val = (KEYSTONE_RIO_PER_EN | KEYSTONE_RIO_PER_FREE);
+ writel(val, &krio_priv->regs->pcr);
+
+ /* set BOOT_COMPLETE bit */
+ val = readl(&krio_priv->regs->per_set_cntl);
+ writel(val | KEYSTONE_RIO_BOOT_COMPLETE,
+ &krio_priv->regs->per_set_cntl);
+}
+
+/**
+ * keystone_rio_port_status - Return if the port is OK or not
+ * @port: index of the port
+ *
+ * Return %0 if the port is ready or %-EIO on failure.
+ */
+static int keystone_rio_port_status(int port,
+ struct keystone_rio_data *krio_priv)
+{
+ unsigned int count, value;
+ int solid_ok = 0;
+
+ if (port >= KEYSTONE_RIO_MAX_PORT)
+ return -1;
+
+ /* Check port status */
+ for (count = 0; count < 300; count++) {
+ value = readl(
+ &(krio_priv->serial_port_regs->sp[port].err_stat));
+
+ if (value & RIO_PORT_N_ERR_STS_PORT_OK) {
+ solid_ok++;
+ if (solid_ok == 100)
+ break;
+ } else {
+ if (solid_ok) {
+ debug_rio(
+ "RIO: unstable port %d (solid_ok = %d)\n",
+ port, solid_ok);
+ return -2;
+ }
+ solid_ok = 0;
+ }
+ udelay(20);
+ }
+
+ return 0;
+}
+
+/**
+ * keystone_rio_port_disable - Disable a RapidIO port
+ * @port: index of the port to configure
+ */
+static void keystone_rio_port_disable(u32 port,
+ struct keystone_rio_data *krio_priv)
+{
+ /* Disable port */
+ writel(0x800000, &(krio_priv->serial_port_regs->sp[port].ctl));
+}
+
+/**
+ * keystone_rio_port_init - Configure a RapidIO port
+ * @port: index of the port to configure
+ * @mode: serdes configuration
+ */
+static int keystone_rio_port_init(u32 port, u32 path_mode,
+ struct keystone_rio_data *krio_priv)
+{
+ if (port >= KEYSTONE_RIO_MAX_PORT)
+ return -1;
+
+ /* Disable packet forwarding */
+ writel(0xffffffff, &(krio_priv->regs->pkt_fwd_cntl[port].pf_16b));
+ writel(0x0003ffff, &(krio_priv->regs->pkt_fwd_cntl[port].pf_8b));
+
+ /* Silence and discovery timers */
+ if ((port == 0) || (port == 2)) {
+ writel(0x20000000,
+ &(krio_priv->phy_regs->phy_sp[port].silence_timer));
+ writel(0x20000000,
+ &(krio_priv->phy_regs->phy_sp[port].discovery_timer));
+ }
+
+ /* Enable port in input and output */
+ writel(0x600000, &(krio_priv->serial_port_regs->sp[port].ctl));
+
+ /* Program channel allocation to ports (1x, 2x or 4x) */
+ writel(path_mode, &(krio_priv->phy_regs->phy_sp[port].path_ctl));
+
+ return 0;
+}
+
+/**
+ * keystone_rio_port_activate - Start using a RapidIO port
+ * @port: index of the port to configure
+ */
+static int keystone_rio_port_activate(u32 port,
+ struct keystone_rio_data *krio_priv)
+{
+ /* Cleanup port error status */
+ writel(KEYSTONE_RIO_PORT_ERROR_MASK,
+ &(krio_priv->serial_port_regs->sp[port].err_stat));
+ writel(0, &(krio_priv->err_mgmt_regs->sp_err[port].det));
+
+ /* Enable promiscuous */
+ writel(0x00309000,
+ &(krio_priv->transport_regs->transport_sp[port].control));
+
+ return 0;
+}
+
+/*------------------------ Main driver functions -----------------------*/
+
+static void keystone_rio_get_controller_defaults(
+ struct keystone_rio_data *krio_priv,
+ int riosize,
+ u32 rioports,
+ int riopmode,
+ int riobaudrate)
+{
+ struct keystone_rio_board_controller_info *c
+ = &krio_priv->board_rio_cfg;
+ int i;
+
+ c->keystone2_serdes = KEYSTONE_RIO_IS_K2;
+
+ if (K2_SERDES(krio_priv)) {
+ /* K2 configuration */
+ c->rio_regs_base = 0x2900000;
+ c->rio_regs_size = 0x40000;
+ c->boot_cfg_regs_base = 0x2620000;
+ c->boot_cfg_regs_size = 0x1000;
+ c->serdes_cfg_regs_base = 0x232c000;
+ c->serdes_cfg_regs_size = 0x1000;
+ } else {
+ /* K1 configuration */
+ c->rio_regs_base = 0x2900000;
+ c->rio_regs_size = 0x21000;
+ c->boot_cfg_regs_base = 0x2620000;
+ c->boot_cfg_regs_size = 0x3b0;
+ c->serdes_cfg_regs_base = 0x2900360;
+ c->serdes_cfg_regs_size = 0x1000;
+ }
+
+ /* dev-id-size */
+ c->size = riosize;
+
+ /* ports to use */
+ c->ports = rioports;
+
+ /* SerDes config */
+ c->serdes_config_num = 1; /* total number of serdes_config[] entries */
+ c->mode = 0; /* default serdes_config[] entry to use */
+ c->path_mode = riopmode;
+
+ if (K2_SERDES(krio_priv)) {
+ /*
+ * K2 sRIO config 0
+ */
+ c->serdes_config[0].prescalar_srv_clk = 0x001f;
+ c->serdes_baudrate = riobaudrate;
+ } else {
+ /*
+ * K1 sRIO config 0: MPY = 5x, div rate = half,
+ * link rate = 3.125 Gbps, mode 1x
+ */
+
+ /* setting control register config */
+ c->serdes_config[0].cfg_cntl = 0x0c053860;
+
+ /* SerDes PLL configuration */
+ c->serdes_config[0].serdes_cfg_pll = 0x0229;
+
+ /* prescalar_srv_clk */
+ c->serdes_config[0].prescalar_srv_clk = 0x001e;
+
+ /* serdes rx_chan_config */
+ for (i = 0; i < KEYSTONE_RIO_MAX_PORT; i++)
+ c->serdes_config[0].rx_chan_config[i] = 0x00440495;
+
+ /* serdes tx_chan_config */
+ for (i = 0; i < KEYSTONE_RIO_MAX_PORT; i++)
+ c->serdes_config[0].tx_chan_config[i] = 0x00180795;
+ }
+}
+
+/*
+ * Platform configuration setup
+ */
+static int keystone_rio_setup_controller(struct keystone_rio_data *krio_priv)
+{
+ u32 ports;
+ u32 p;
+ u32 mode;
+ u32 baud;
+ u32 path_mode;
+ u32 size = 0;
+ int res = 0;
+ char str[8];
+
+ size = krio_priv->board_rio_cfg.size;
+ ports = krio_priv->board_rio_cfg.ports;
+ mode = krio_priv->board_rio_cfg.mode;
+ baud = krio_priv->board_rio_cfg.serdes_baudrate;
+ path_mode = krio_priv->board_rio_cfg.path_mode;
+
+ debug_rio(
+ "RIO: size = %d, ports = 0x%x, mode = %d, baud = %d, path_mode = %d\n",
+ size, ports, mode, baud, path_mode);
+
+ if (mode >= krio_priv->board_rio_cfg.serdes_config_num) {
+ mode = 0;
+ printf("RIO: invalid port mode, forcing it to %d\n", mode);
+ }
+
+ if (baud > KEYSTONE_RIO_BAUD_5_000) {
+ baud = KEYSTONE_RIO_BAUD_5_000;
+ printf("RIO: invalid baud rate, forcing it to 5Gbps\n");
+ }
+
+ switch (baud) {
+ case KEYSTONE_RIO_BAUD_1_250:
+ snprintf(str, sizeof(str), "1.25");
+ break;
+ case KEYSTONE_RIO_BAUD_2_500:
+ snprintf(str, sizeof(str), "2.50");
+ break;
+ case KEYSTONE_RIO_BAUD_3_125:
+ snprintf(str, sizeof(str), "3.125");
+ break;
+ case KEYSTONE_RIO_BAUD_5_000:
+ snprintf(str, sizeof(str), "5.00");
+ break;
+ default:
+ return -1;
+ }
+
+ printf("RIO: initializing %s Gbps interface with port configuration %d\n",
+ str, path_mode);
+
+ /* Hardware set up of the controller */
+ keystone_rio_hw_init(mode, baud, krio_priv);
+
+ /* Disable all ports */
+ for (p = 0; p < KEYSTONE_RIO_MAX_PORT; p++)
+ keystone_rio_port_disable(p, krio_priv);
+
+ /* Start the controller */
+ keystone_rio_start(krio_priv);
+
+ /* Try to lock K2 SerDes*/
+ if (K2_SERDES(krio_priv)) {
+ int lanes = keystone_rio_get_lane_config(ports, path_mode);
+ if (lanes > 0) {
+ res = k2_rio_serdes_wait_lock(krio_priv, (u32) lanes);
+ if (res < 0)
+ debug_rio(
+ "SerDes for lane mask 0x%x on %s Gbps not locked\n",
+ lanes, str);
+ }
+ }
+
+ /* Use and check ports status (but only the requested ones) */
+ krio_priv->ports_registering = ports;
+ while (ports) {
+ int status;
+ u32 port = ffs(ports) - 1;
+ if (port > 32)
+ return 0;
+ ports &= ~(1 << port);
+
+ res = keystone_rio_port_init(port, path_mode, krio_priv);
+ if (res < 0) {
+ printf("RIO: initialization of port %d failed\n", p);
+ return res;
+ }
+
+ /* Start the port */
+ keystone_rio_port_activate(port, krio_priv);
+
+ /* Check the port status */
+ status = keystone_rio_port_status(port, krio_priv);
+ if (status == 0) {
+ krio_priv->ports_registering &= ~(1 << port);
+ printf("RIO: port RIO%d ready\n", port);
+ } else {
+ printf("RIO: port %d not ready (status %d)\n",
+ port, status);
+ }
+ }
+
+ if (krio_priv->ports_registering != 0)
+ return -1;
+
+ return res;
+}
+
+/**
+ * rio_init - Initialize RapidIO subsystem
+ * @riohdid: RapidIO host device ID
+ * @riosize: RapidIO device ID size
+ * @rioports: bitmask of ports to configure
+ * @riopmode: path mode (lanes to ports mapping)
+ * @riobaudrate: link baudrate
+ *
+ * Returns riohandle on success or %NULL on failure.
+ */
+void *rio_init(int riohdid,
+ int riosize,
+ u32 rioports,
+ int riopmode,
+ int riobaudrate)
+{
+ struct keystone_rio_data *krio_priv = &__krio_priv;
+ int res = 0;
+ void *regs;
+
+ keystone_rio_get_controller_defaults(krio_priv,
+ riosize,
+ rioports,
+ riopmode,
+ riobaudrate);
+
+ regs = (void *)krio_priv->board_rio_cfg.boot_cfg_regs_base;
+ krio_priv->jtagid_reg = regs + 0x0018;
+ krio_priv->serdes_sts_reg = regs + 0x0154;
+
+ regs = (void *)krio_priv->board_rio_cfg.serdes_cfg_regs_base;
+ krio_priv->serdes_regs = regs;
+
+ regs = (void *)krio_priv->board_rio_cfg.rio_regs_base;
+ krio_priv->regs = regs;
+ krio_priv->car_csr_regs = regs + 0x0b000;
+ krio_priv->serial_port_regs = regs + 0x0b100;
+ krio_priv->err_mgmt_regs = regs + 0x0c000;
+ krio_priv->phy_regs = regs + 0x1b000;
+ krio_priv->transport_regs = regs + 0x1b300;
+ krio_priv->pkt_buf_regs = regs + 0x1b600;
+ krio_priv->evt_mgmt_regs = regs + 0x1b900;
+ krio_priv->port_write_regs = regs + 0x1ba00;
+ krio_priv->link_regs = regs + 0x1bd00;
+ krio_priv->fabric_regs = regs + 0x1be00;
+ krio_priv->car_csr_regs_base = (u32) regs + 0xb000;
+
+ krio_priv->riohdid = riohdid;
+
+ /* Enable srio clock */
+ psc_enable_module(KS2_LPSC_SRIO);
+
+ printf("KeyStone RapidIO driver %s, hdid=%d\n", DRIVER_VER, riohdid);
+
+ /* Setup the sRIO controller */
+ res = keystone_rio_setup_controller(krio_priv);
+ if (res < 0)
+ return NULL;
+
+ return (void *)krio_priv;
+}
+
+/**
+ * rio_shutdown - Shutdown RapidIO subsystem
+ * @riohandle: RapidIO handle (returned by rio_init)
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_shutdown(void *riohandle)
+{
+ if (riohandle != &__krio_priv)
+ return -1;
+
+ /* Power off */
+ psc_disable_module(KS2_LPSC_SRIO);
+
+ return 0;
+}
diff --git a/drivers/rapidio/keystone_rio.h b/drivers/rapidio/keystone_rio.h
new file mode 100644
index 0000000..92547ae
--- /dev/null
+++ b/drivers/rapidio/keystone_rio.h
@@ -0,0 +1,650 @@
+/*
+ * (C) Copyright 2015
+ * Texas Instruments Incorporated, <www.ti.com>
+ * Authors: Aurelien Jacquiot <a-jacquiot(a)ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef KEYSTONE_RIO_H
+#define KEYSTONE_RIO_H
+
+#include <asm/setup.h>
+#include <asm/cache.h>
+#include <asm/io.h>
+
+#define BIT(x) (1 << (x))
+
+#define KEYSTONE_RIO_MAP_FLAG_SEGMENT BIT(0)
+#define KEYSTONE_RIO_MAP_FLAG_SRC_PROMISC BIT(1)
+#define KEYSTONE_RIO_MAP_FLAG_TT_16 BIT(13)
+#define KEYSTONE_RIO_MAP_FLAG_DST_PROMISC BIT(15)
+#define KEYSTONE_RIO_DESC_FLAG_TT_16 BIT(9)
+
+#define KEYSTONE_RIO_BOOT_COMPLETE BIT(24)
+#define KEYSTONE_RIO_PER_EN BIT(2)
+#define KEYSTONE_RIO_PER_FREE BIT(0)
+#define KEYSTONE_RIO_PEF_FLOW_CONTROL BIT(7)
+
+/*
+ * Packet types
+ */
+#define KEYSTONE_RIO_PACKET_TYPE_NREAD 0x24
+#define KEYSTONE_RIO_PACKET_TYPE_NWRITE 0x54
+#define KEYSTONE_RIO_PACKET_TYPE_NWRITE_R 0x55
+#define KEYSTONE_RIO_PACKET_TYPE_SWRITE 0x60
+#define KEYSTONE_RIO_PACKET_TYPE_DBELL 0xa0
+#define KEYSTONE_RIO_PACKET_TYPE_MAINT_R 0x80
+#define KEYSTONE_RIO_PACKET_TYPE_MAINT_W 0x81
+#define KEYSTONE_RIO_PACKET_TYPE_MAINT_RR 0x82
+#define KEYSTONE_RIO_PACKET_TYPE_MAINT_WR 0x83
+#define KEYSTONE_RIO_PACKET_TYPE_MAINT_PW 0x84
+
+/*
+ * LSU defines
+ */
+#define KEYSTONE_RIO_LSU_PRIO 0
+
+#define KEYSTONE_RIO_LSU_BUSY_MASK BIT(31)
+#define KEYSTONE_RIO_LSU_FULL_MASK BIT(30)
+
+#define KEYSTONE_RIO_LSU_CC_MASK 0x0f
+#define KEYSTONE_RIO_LSU_CC_TIMEOUT 0x01
+#define KEYSTONE_RIO_LSU_CC_XOFF 0x02
+#define KEYSTONE_RIO_LSU_CC_ERROR 0x03
+#define KEYSTONE_RIO_LSU_CC_INVALID 0x04
+#define KEYSTONE_RIO_LSU_CC_DMA 0x05
+#define KEYSTONE_RIO_LSU_CC_RETRY 0x06
+#define KEYSTONE_RIO_LSU_CC_CANCELED 0x07
+
+/* Mask for receiving both error and good completion LSU interrupts */
+#define KEYSTONE_RIO_ICSR_LSU0(src_id) ((0x10001) << (src_id))
+
+/* Keystone2 supported baud rates */
+#define KEYSTONE_RIO_BAUD_1_250 0
+#define KEYSTONE_RIO_BAUD_2_500 1
+#define KEYSTONE_RIO_BAUD_3_125 2
+#define KEYSTONE_RIO_BAUD_5_000 3
+
+#define KEYSTONE_RIO_FULL_RATE 0
+#define KEYSTONE_RIO_HALF_RATE 1
+#define KEYSTONE_RIO_QUARTER_RATE 2
+
+/* Max ports configuration per path modes */
+#define KEYSTONE_MAX_PORTS_PATH_MODE_0 0xf /* 4 ports */
+#define KEYSTONE_MAX_PORTS_PATH_MODE_1 0xd /* 3 ports */
+#define KEYSTONE_MAX_PORTS_PATH_MODE_2 0x7 /* 3 ports */
+#define KEYSTONE_MAX_PORTS_PATH_MODE_3 0x5 /* 2 ports */
+#define KEYSTONE_MAX_PORTS_PATH_MODE_4 0x1 /* 1 ports */
+
+#define SERDES_LANE(lane_num) (0x01 << lane_num)
+#define IS_SERDES_LANE_USED(lanes, lane_num) (lanes & SERDES_LANE(lane_num))
+
+/*
+ * Various RIO defines
+ */
+#define KEYSTONE_RIO_TIMEOUT_CNT 1000
+
+/*
+ * RIO error, reset and special event interrupt defines
+ */
+#define KEYSTONE_RIO_PORT_ERROR_OUT_PKT_DROP BIT(26)
+#define KEYSTONE_RIO_PORT_ERROR_OUT_FAILED BIT(25)
+#define KEYSTONE_RIO_PORT_ERROR_OUT_DEGRADED BIT(24)
+#define KEYSTONE_RIO_PORT_ERROR_OUT_RETRY BIT(20)
+#define KEYSTONE_RIO_PORT_ERROR_OUT_ERROR BIT(17)
+#define KEYSTONE_RIO_PORT_ERROR_IN_ERROR BIT(9)
+#define KEYSTONE_RIO_PORT_ERROR_PW_PENDING BIT(4)
+#define KEYSTONE_RIO_PORT_ERROR_PORT_ERR BIT(2)
+
+#define KEYSTONE_RIO_PORT_ERROR_MASK \
+ (KEYSTONE_RIO_PORT_ERROR_OUT_PKT_DROP |\
+ KEYSTONE_RIO_PORT_ERROR_OUT_FAILED |\
+ KEYSTONE_RIO_PORT_ERROR_OUT_DEGRADED |\
+ KEYSTONE_RIO_PORT_ERROR_OUT_RETRY |\
+ KEYSTONE_RIO_PORT_ERROR_OUT_ERROR |\
+ KEYSTONE_RIO_PORT_ERROR_IN_ERROR |\
+ KEYSTONE_RIO_PORT_ERROR_PW_PENDING |\
+ KEYSTONE_RIO_PORT_ERROR_PORT_ERR)
+
+
+#define KEYSTONE_RIO_SP_HDR_NEXT_BLK_PTR 0x1000
+#define KEYSTONE_RIO_SP_HDR_EP_REC_ID 0x0002
+#define KEYSTONE_RIO_ERR_HDR_NEXT_BLK_PTR 0x3000
+#define KEYSTONE_RIO_ERR_EXT_FEAT_ID 0x0007
+
+/*
+ * RapidIO global definitions
+ */
+#define KEYSTONE_RIO_MAX_PORT 4
+#define KEYSTONE_RIO_BLK_NUM 9
+#define KEYSTONE_RIO_MAINT_BUF_SIZE 64
+
+/*
+ * Dev Id and dev revision
+ */
+#define KEYSTONE_RIO_DEV_ID_VAL \
+ ((((__raw_readl(krio_priv->jtagid_reg)) << 4) & 0xffff0000) | 0x30)
+
+#define KEYSTONE_RIO_DEV_INFO_VAL \
+ (((__raw_readl(krio_priv->jtagid_reg)) >> 28) & 0xf)
+
+#define KEYSTONE_RIO_ID_TI (0x00000030)
+#define KEYSTONE_RIO_EXT_FEAT_PTR (0x00000100)
+
+/*
+ * SerDes configurations
+ */
+struct keystone_serdes_config {
+ u32 cfg_cntl; /* setting control register config */
+ u16 serdes_cfg_pll; /* SerDes PLL configuration */
+ u16 prescalar_srv_clk; /* prescalar fo ip_clk */
+
+ /* SerDes receive channel configuration (per-port) */
+ u32 rx_chan_config[KEYSTONE_RIO_MAX_PORT];
+
+ /* SerDes transmit channel configuration (per-port) */
+ u32 tx_chan_config[KEYSTONE_RIO_MAX_PORT];
+};
+
+/*
+ * Per board RIO devices controller configuration
+ */
+struct keystone_rio_board_controller_info {
+ u32 rio_regs_base;
+ u32 rio_regs_size;
+
+ u32 boot_cfg_regs_base;
+ u32 boot_cfg_regs_size;
+
+ u32 serdes_cfg_regs_base;
+ u32 serdes_cfg_regs_size;
+
+ u16 ports; /* bitfield of port(s) to probe on this controller */
+ u16 mode; /* hw mode (default serdes config).
+ index into serdes_config[] */
+ u16 id; /* host id */
+ u16 size; /* RapidIO common transport system size.
+ * 0 - Small size. 256 devices.
+ * 1 - Large size, 65536 devices. */
+ u16 keystone2_serdes;
+ u16 serdes_config_num;
+ u32 serdes_baudrate;
+ u32 path_mode;
+
+ struct keystone_serdes_config serdes_config[4];
+};
+
+struct keystone_rio_data;
+
+/*
+ * RapidIO Registers
+ */
+
+struct keystone_srio_serdes_regs {
+ u32 pll;
+
+ struct {
+ u32 rx;
+ u32 tx;
+ } channel[4];
+};
+
+/* RIO Registers 0000 - 2fff */
+struct keystone_rio_regs {
+/* Required Peripheral Registers */
+ u32 pid; /* 0000 */
+ u32 pcr; /* 0004 */
+ u32 __rsvd0[3]; /* 0008 - 0010 */
+
+/* Peripheral Settting Control Registers */
+ u32 per_set_cntl; /* 0014 */
+ u32 per_set_cntl1; /* 0018 */
+
+ u32 __rsvd1[2]; /* 001c - 0020 */
+
+ u32 gbl_en; /* 0024 */
+ u32 gbl_en_stat; /* 0028 */
+
+ struct {
+ u32 enable; /* 002c */
+ u32 status; /* 0030 */
+ } blk[10]; /* 002c - 0078 */
+
+ /* ID Registers */
+ u32 __rsvd2[17]; /* 007c - 00bc */
+ u32 multiid_reg[8]; /* 00c0 - 00dc */
+
+/* Hardware Packet Forwarding Registers */
+ struct {
+ u32 pf_16b;
+ u32 pf_8b;
+ } pkt_fwd_cntl[8]; /* 00e0 - 011c */
+
+ u32 __rsvd3[24]; /* 0120 - 017c */
+
+/* Interrupt Registers */
+ struct {
+ u32 status;
+ u32 __rsvd0;
+ u32 clear;
+ u32 __rsvd1;
+ } doorbell_int[4]; /* 0180 - 01bc */
+
+ struct {
+ u32 status;
+ u32 __rsvd0;
+ u32 clear;
+ u32 __rsvd1;
+ } lsu_int[2]; /* 01c0 - 01dc */
+
+ u32 err_rst_evnt_int_stat; /* 01e0 */
+ u32 __rsvd4;
+ u32 err_rst_evnt_int_clear; /* 01e8 */
+ u32 __rsvd5;
+
+ u32 __rsvd6[4]; /* 01f0 - 01fc */
+
+ struct {
+ u32 route; /* 0200 */
+ u32 route2; /* 0204 */
+ u32 __rsvd; /* 0208 */
+ } doorbell_int_route[4]; /* 0200 - 022c */
+
+ u32 lsu0_int_route[4]; /* 0230 - 023c */
+ u32 lsu1_int_route1; /* 0240 */
+
+ u32 __rsvd7[3]; /* 0244 - 024c */
+
+ u32 err_rst_evnt_int_route[3]; /* 0250 - 0258 */
+
+ u32 __rsvd8[2]; /* 025c - 0260 */
+
+ u32 interupt_ctl; /* 0264 */
+
+ u32 __rsvd9[26]; /* 0268, 026c, 0270 - 02cc */
+
+ u32 intdst_rate_cntl[16]; /* 02d0 - 030c */
+ u32 intdst_rate_disable; /* 0310 */
+
+ u32 __rsvd10[59]; /* 0314 - 03fc */
+
+/* RXU Registers */
+ struct {
+ u32 ltr_mbox_src;
+ u32 dest_prom_seg;
+ u32 flow_qid;
+ } rxu_map[64]; /* 0400 - 06fc */
+
+ struct {
+ u32 cos_src;
+ u32 dest_prom;
+ u32 stream;
+ } rxu_type9_map[64]; /* 0700 - 09fc */
+
+ u32 __rsvd11[192]; /* 0a00 - 0cfc */
+
+/* LSU/MAU Registers */
+ struct {
+ u32 addr_msb; /* 0d00 */
+ u32 addr_lsb_cfg_ofs; /* 0d04 */
+ u32 dsp_addr; /* 0d08 */
+ u32 dbell_val_byte_cnt; /* 0d0c */
+ u32 destid; /* 0d10 */
+ u32 dbell_info_fttype; /* 0d14 */
+ u32 busy_full; /* 0d18 */
+ } lsu_reg[8]; /* 0d00 - 0ddc */
+
+ u32 lsu_setup_reg[2]; /* 0de0 - 0de4 */
+ u32 lsu_stat_reg[6]; /* 0de8 - 0dfc */
+ u32 lsu_flow_masks[4]; /* 0e00 - 0e0c */
+
+ u32 __rsvd12[16]; /* 0e10 - 0e4c */
+
+/* Flow Control Registers */
+ u32 flow_cntl[16]; /* 0e50 - 0e8c */
+ u32 __rsvd13[8]; /* 0e90 - 0eac */
+
+/* TXU Registers 0eb0 - 0efc */
+ u32 tx_cppi_flow_masks[8]; /* 0eb0 - 0ecc */
+ u32 tx_queue_sch_info[4]; /* 0ed0 - 0edc */
+ u32 garbage_coll_qid[3]; /* 0ee0 - 0ee8 */
+
+ u32 __rsvd14[69]; /* 0eec, 0ef0 - 0ffc */
+
+};
+
+/* CDMAHP Registers 1000 - 2ffc */
+struct keystone_rio_pktdma_regs {
+ u32 __rsvd[2048]; /* 1000 - 2ffc */
+};
+
+/* CSR/CAR Registers b000+ */
+struct keystone_rio_car_csr_regs {
+ u32 dev_id; /* b000 */
+ u32 dev_info; /* b004 */
+ u32 assembly_id; /* b008 */
+ u32 assembly_info; /* b00c */
+ u32 pe_feature; /* b010 */
+
+ u32 sw_port; /* b014 */
+
+ u32 src_op; /* b018 */
+ u32 dest_op; /* b01c */
+
+ u32 __rsvd1[7]; /* b020 - b038 */
+
+ u32 data_stm_info; /* b03c */
+
+ u32 __rsvd2[2]; /* b040 - b044 */
+
+ u32 data_stm_logical_ctl; /* b048 */
+ u32 pe_logical_ctl; /* b04c */
+
+ u32 __rsvd3[2]; /* b050 - b054 */
+
+ u32 local_cfg_hbar; /* b058 */
+ u32 local_cfg_bar; /* b05c */
+
+ u32 base_dev_id; /* b060 */
+ u32 __rsvd4;
+ u32 host_base_id_lock; /* b068 */
+ u32 component_tag; /* b06c */
+ /* b070 - b0fc */
+};
+
+struct keystone_rio_serial_port_regs {
+ u32 sp_maint_blk_hdr; /* b100 */
+ u32 __rsvd6[7]; /* b104 - b11c */
+
+ u32 sp_link_timeout_ctl; /* b120 */
+ u32 sp_rsp_timeout_ctl; /* b124 */
+ u32 __rsvd7[5]; /* b128 - b138 */
+ u32 sp_gen_ctl; /* b13c */
+
+ struct {
+ u32 link_maint_req; /* b140 */
+ u32 link_maint_resp;/* b144 */
+ u32 ackid_stat; /* b148 */
+ u32 __rsvd[2]; /* b14c - b150 */
+ u32 ctl2; /* b154 */
+ u32 err_stat; /* b158 */
+ u32 ctl; /* b15c */
+ } sp[4]; /* b140 - b1bc */
+
+ /* b1c0 - bffc */
+};
+
+struct keystone_rio_err_mgmt_regs {
+ u32 err_report_blk_hdr; /* c000 */
+ u32 __rsvd9;
+ u32 err_det; /* c008 */
+ u32 err_en; /* c00c */
+ u32 h_addr_capt; /* c010 */
+ u32 addr_capt; /* c014 */
+ u32 id_capt; /* c018 */
+ u32 ctrl_capt; /* c01c */
+ u32 __rsvd10[2]; /* c020 - c024 */
+ u32 port_write_tgt_id; /* c028 */
+ u32 __rsvd11[5]; /* c02c - c03c */
+
+ struct {
+ u32 det; /* c040 */
+ u32 rate_en; /* c044 */
+ u32 attr_capt_dbg0; /* c048 */
+ u32 capt_0_dbg1; /* c04c */
+ u32 capt_1_dbg2; /* c050 */
+ u32 capt_2_dbg3; /* c054 */
+ u32 capt_3_dbg4; /* c058 */
+ u32 __rsvd0[3]; /* c05c - c064 */
+ u32 rate; /* c068 */
+ u32 thresh; /* c06c */
+ u32 __rsvd1[4]; /* c070 - c07c */
+ } sp_err[4]; /* c040 - c13c */
+
+ u32 __rsvd12[1972]; /* c140 - e00c */
+
+ struct {
+ u32 stat0; /* e010 */
+ u32 stat1; /* e014 */
+ u32 __rsvd[6]; /* e018 - e02c */
+ } lane_stat[4]; /* e010 - e08c */
+
+ /* e090 - 1affc */
+};
+
+struct keystone_rio_phy_layer_regs {
+ u32 phy_blk_hdr; /* 1b000 */
+ u32 __rsvd14[31]; /* 1b004 - 1b07c */
+ struct {
+ u32 imp_spec_ctl; /* 1b080 */
+ u32 pwdn_ctl; /* 1b084 */
+ u32 __rsvd0[2];
+
+ u32 status; /* 1b090 */
+ u32 int_enable; /* 1b094 */
+ u32 port_wr_enable; /* 1b098 */
+ u32 event_gen; /* 1b09c */
+
+ u32 all_int_en; /* 1b0a0 */
+ u32 all_port_wr_en; /* 1b0a4 */
+ u32 __rsvd1[2];
+
+ u32 path_ctl; /* 1b0b0 */
+ u32 discovery_timer;/* 1b0b4 */
+ u32 silence_timer; /* 1b0b8 */
+ u32 vmin_exp; /* 1b0bc */
+
+ u32 pol_ctl; /* 1b0c0 */
+ u32 __rsvd2;
+ u32 denial_ctl; /* 1b0c8 */
+ u32 __rsvd3;
+
+ u32 rcvd_mecs; /* 1b0d0 */
+ u32 __rsvd4;
+ u32 mecs_fwd; /* 1b0d8 */
+ u32 __rsvd5;
+
+ u32 long_cs_tx1; /* 1b0e0 */
+ u32 long_cs_tx2; /* 1b0e4 */
+ u32 __rsvd[6]; /* 1b0e8, 1b0ec, 1b0f0 - 1b0fc */
+ } phy_sp[4]; /* 1b080 - 1b27c */
+
+ /* 1b280 - 1b2fc */
+};
+
+struct keystone_rio_transport_layer_regs {
+ u32 transport_blk_hdr; /* 1b300 */
+ u32 __rsvd16[31]; /* 1b304 - 1b37c */
+
+ struct {
+ u32 control; /*1b380 */
+ u32 __rsvd0[3];
+
+ u32 status; /* 1b390 */
+ u32 int_enable; /* 1b394 */
+ u32 port_wr_enable; /* 1b398 */
+ u32 event_gen; /* 1b39c */
+
+ struct {
+ u32 ctl; /* 1b3a0 */
+ u32 pattern_match; /* 1b3a4 */
+ u32 __rsvd[2]; /* 1b3a8 - 1b3ac */
+ } base_route[4]; /* 1b3a0 - 1b3dc */
+
+ u32 __rsvd1[8]; /* 1b3e0 - 1b3fc */
+
+ } transport_sp[4]; /* 1b380 - 1b57c */
+
+ /* 1b580 - 1b5fc */
+};
+
+struct keystone_rio_pkt_buf_regs {
+ u32 pkt_buf_blk_hdr; /* 1b600 */
+ u32 __rsvd18[31]; /* 1b604 - 1b67c */
+
+ struct {
+ u32 control; /* 1b680 */
+ u32 __rsvd0[3];
+
+ u32 status; /* 1b690 */
+ u32 int_enable; /* 1b694 */
+ u32 port_wr_enable; /* 1b698 */
+ u32 event_gen; /* 1b69c */
+
+ u32 ingress_rsc; /* 1b6a0 */
+ u32 egress_rsc; /* 1b6a4 */
+ u32 __rsvd1[2];
+
+ u32 ingress_watermark[4]; /* 1b6b0 - 1b6bc */
+ u32 __rsvd2[16]; /* 1b6c0 - 1b6fc */
+
+ } pkt_buf_sp[4]; /* 1b680 - 1b87c */
+
+ /* 1b880 - 1b8fc */
+};
+
+struct keystone_rio_evt_mgmt_regs {
+ u32 evt_mgmt_blk_hdr; /* 1b900 */
+ u32 __rsvd20[3];
+
+ u32 evt_mgmt_int_stat; /* 1b910 */
+ u32 evt_mgmt_int_enable; /* 1b914 */
+ u32 evt_mgmt_int_port_stat; /* 1b918 */
+ u32 __rsvd21;
+
+ u32 evt_mgmt_port_wr_stat; /* 1b920 */
+ u32 evt_mgmt_port_wr_enable;/* 1b924 */
+ u32 evt_mgmt_port_wr_port_stat; /* 1b928 */
+ u32 __rsvd22;
+
+ u32 evt_mgmt_dev_int_en; /* 1b930 */
+ u32 evt_mgmt_dev_port_wr_en; /* 1b934 */
+ u32 __rsvd23;
+ u32 evt_mgmt_mecs_stat; /* 1b93c */
+
+ u32 evt_mgmt_mecs_int_en; /* 1b940 */
+ u32 evt_mgmt_mecs_cap_en; /* 1b944 */
+ u32 evt_mgmt_mecs_trig_en; /* 1b948 */
+ u32 evt_mgmt_mecs_req; /* 1b94c */
+
+ u32 evt_mgmt_mecs_port_stat;/* 1b950 */
+ u32 __rsvd24[2];
+ u32 evt_mgmt_mecs_event_gen;/* 1b95c */
+
+ u32 evt_mgmt_rst_port_stat; /* 1b960 */
+ u32 __rsvd25;
+ u32 evt_mgmt_rst_int_en; /* 1b968 */
+ u32 __rsvd26;
+
+ u32 evt_mgmt_rst_port_wr_en;/* 1b970 */
+ /* 1b974 - 1b9fc */
+};
+
+struct keystone_rio_port_write_regs {
+ u32 port_wr_blk_hdr; /* 1ba00 */
+ u32 port_wr_ctl; /* 1ba04 */
+ u32 port_wr_route; /* 1ba08 */
+ u32 __rsvd28;
+
+ u32 port_wr_rx_stat; /* 1ba10 */
+ u32 port_wr_rx_event_gen; /* 1ba14 */
+ u32 __rsvd29[2];
+
+ u32 port_wr_rx_capt[4]; /* 1ba20 - 1ba2c */
+ /* 1ba30 - 1bcfc */
+};
+
+struct keystone_rio_link_layer_regs {
+ u32 link_blk_hdr; /* 1bd00 */
+ u32 __rsvd31[8]; /* 1bd04 - 1bd20 */
+ u32 whiteboard; /* 1bd24 */
+ u32 port_number; /* 1bd28 */
+
+ u32 __rsvd32; /* 1bd2c */
+
+ u32 prescalar_srv_clk; /* 1bd30 */
+ u32 reg_rst_ctl; /* 1bd34 */
+ u32 __rsvd33[4]; /* 1bd38, 1bd3c, 1bd40, 1bd44 */
+ u32 local_err_det; /* 1bd48 */
+ u32 local_err_en; /* 1bd4c */
+
+ u32 local_h_addr_capt; /* 1bd50 */
+ u32 local_addr_capt; /* 1bd54 */
+ u32 local_id_capt; /* 1bd58 */
+ u32 local_ctrl_capt; /* 1bd5c */
+
+ /* 1bd60 - 1bdfc */
+};
+
+struct keystone_rio_fabric_regs {
+ u32 fabric_hdr; /* 1be00 */
+ u32 __rsvd35[3]; /* 1be04 - 1be0c */
+
+ u32 fabric_csr; /* 1be10 */
+ u32 __rsvd36[11]; /* 1be14 - 1be3c */
+
+ u32 sp_fabric_status[4]; /* 1be40 - 1be4c */
+};
+
+/**
+ * keystone_rio_config_read - Generate a KeyStone read maintenance transaction
+ * @portid: Output port ID of transaction
+ * @destid: Destination ID of transaction
+ * @hopcount: Number of hops to target device
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @val: Location to be read into
+ *
+ * Generates a KeyStone read maintenance transaction. Returns %0 on
+ * success or %-1 on failure.
+ */
+int keystone_rio_config_read(int portid,
+ u16 destid,
+ u8 hopcount,
+ u32 offset,
+ int len,
+ u32 *val);
+
+/**
+ * keystone_rio_config_write - Generate a KeyStone write maintenance transaction
+ * @portid: Output port ID of transaction
+ * @destid: Destination ID of transaction
+ * @hopcount: Number of hops to target device
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @val: Value to be written
+ *
+ * Generates an KeyStone write maintenance transaction. Returns %0 on
+ * success or %-1 on failure.
+ */
+int keystone_rio_config_write(int portid,
+ u16 destid,
+ u8 hopcount,
+ u32 offset,
+ int len,
+ u32 val);
+
+/**
+ * keystone_local_config_read - Generate a KeyStone local config space read
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @data: Value to be read into
+ *
+ * Generates a KeyStone local configuration space read. Returns %0 on
+ * success or %-1 on failure.
+ */
+int keystone_local_config_read(u32 offset, int len, u32 *data);
+
+/**
+ * keystone_local_config_write - Generate a KeyStone local config space write
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @data: Value to be written
+ *
+ * Generates a KeyStone local configuration space write. Returns %0 on
+ * success or %-EINVAL on failure.
+ */
+int keystone_local_config_write(u32 offset, int len, u32 data);
+
+#endif /* KEYSTONE_RIO_H */
--
1.6.2.1
2
1

[U-Boot] [PATCH 3/4] rapidio: add documentation for RapidIO boot
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
04 Jan '16
From: Aurelien Jacquiot <a-jacquiot(a)ti.com>
This commit adds the RapidIO boot functionality documentation.
Its explains what RapidIO boot feature does, how to use it and the
basic API that must be provided by a RapidIO hw controller driver.
Signed-off-by: Aurelien Jacquiot <a-jacquiot(a)ti.com>
---
doc/README.rapidio | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 158 insertions(+), 0 deletions(-)
create mode 100644 doc/README.rapidio
diff --git a/doc/README.rapidio b/doc/README.rapidio
new file mode 100644
index 0000000..e360a7f
--- /dev/null
+++ b/doc/README.rapidio
@@ -0,0 +1,158 @@
+ RapidIO support for TI KeyStone devices
+ =======================================
+
+
+This feature allows to boot a device through RapidIO using DirectI/O (DIO).
+A new set of commands is added to U-Boot for this purpose.
+
+This feature is today designed to work with Texas Instruments KeyStone devices
+but may be easily extended to be used on different architectures.
+
+How it works
+------------
+
+This booting mechanism uses the DirectI/O functionality which allows a
+remote devices to directly read and write into the device address space
+(so basically here into the DDR or any mapped memory such as MSM).
+
+The boot sequence is pretty simple. The RIO boot initializes the RapidIO
+controller then the link partner needs to push the various images (kernel,
+fdt, ...). When images are loaded into their respective locations by the peer,
+U-Boot can start the images normally like with any other boot mechanismes.
+
+It is the link partner responsability to push the various images in the device
+memory then signaling U-Boot that images have been loaded.
+
+for that purpose, the simpler way is to use the 'mwait' U-Boot command which
+allows to wait a defined value in memory. The link partner has only to write
+the expected value at a given address when it has pushed all images.
+
+Basically the sequence should be the following (A is the device to be booted, B
+is the link partner device which pushes the images to boot):
+
+ [B]: board is up and booted, RapidIO controller is initialized but not the link
+ [A]: board is powered on, entering U-Boot
+ [A]: the 'rio init' command is called
+ [A]: U-Boot configures the local RapidIO controller and hardware waits the link
+ establishement
+ [B]: Linux kernel starts the RapidIO link configuration and eventually the
+ RapidIO enumeration/discovery process (see Linux kernel RapidIO subsytem
+ driver for more information)
+ [AB]: RapidIO link is now established between the both link partners
+ [A]: the 'mwait 0x80000000 0xbadface' command is called
+ [A]: U-Boot reads the first word at beginning of the DDR in loop and waits
+ until it is set to 0xbadface
+ [B]: system pushes the kernel image using DIO
+ [B]: system pushes the dtb image using DIO
+ [B]: system pushes the skern image using DIO
+ [B]: system set the 0xbadface value at the first word of the remote DDR
+ [A]: U-Boot detects that first DDR word has changed to 0xbadface and exits the
+ mwait command
+ [A]: skern, fdt and kernel can be installed and started normally with the
+ 'mon_install' and 'bootm' U-Boot commands
+
+RapidIO subsystem commands
+--------------------------
+
+ - rio init [dev_id] [id_size] [port_mask] [pathmode] [baudrate]:
+ This command is used to initialize the RapidIO controller. Optional
+ parameters are used to define the RapidIO configuration.
+ Note that environment variables can be instead of parameters.
+
+ 1) dev_id ('riohdid' environment variable) to set the host device Id.
+ By default if not specified it is set to -1.
+
+ 2) id_size ('riosize' environment variable) to indicate the Ids size
+ (0 for small, 1 for big). By default it is set to 0 (small Ids).
+
+ 3) port_mask ('rioports' environment variable) is a bitmask of ports to use.
+ By default it is set to 0x1 (port 0).
+
+ 4) pathmode ('riopathmode' environment variable) defines the port path mode
+ (mapping of ports over lanes). The default mode is 0 (4 independent ports
+ in 1x).
+
+ 5) baudrate ('riobaudrate' environment variable) defines the port speed:
+ 0 for 1.25Gbps, 1 for 2.5Gbps, 2 for 3.125Gbps, 3 for 5Gbps and 4 for
+ 6.25Gpbs (if supported). It is set by default to 2 (2.5Gbps).
+
+ - rio shutdown: It disables the RapidIO controller.
+
+ - rio r port dev_id hopcount offset: This command allows to read the remote
+ RapidIO configuration space by performing a maintenance read request.
+
+ - rio w port dev_id hopcount offset value: This command allows to write into
+ the remote RapidIO configuration space by performing a maintenance write
+ request.
+
+ - rio lr offset: This performs a local RapidIO configuration space read.
+
+ - rio lw offset value: This performs a local RapidIO configuration space write.
+
+Device support
+--------------
+
+The RapidIO controller of the KeyStone devices is supported through the
+drivers/rapidio/keystone_rio.c device driver.
+
+The RapidIO driver must export the following functions (see include/rio.h for
+full prototypes).
+
+ - rio_init() : initialize RapidIO controller
+ - rio_shutdown(): shutdown RapidIO controller
+ - rio_config_read(): perform a RapidIO maintenance read transaction
+ - rio_config_write(): perform a RapidIO maintenance read transaction
+ - rio_local_config_read(): local configuration space read
+ - rio_local_config_write(): local configuration space write
+
+Booting with RapidIO
+--------------------
+
+Example of RapidIO booting with U-Boot:
+
+K2HK EVM # rio init -1 0 0x1 4 3
+rioboot: waiting for link up ...
+KeyStone RapidIO driver v1.1, hdid=-1
+RIO: initializing 5.00 Gbps interface with port configuration 4
+RIO: port RIO0 ready
+K2HK EVM # mwait 0x80000000 0xbadface
+waiting 0xbadface at 0x80000000...
+K2HK EVM # mon_install ${addr_mon}
+## installed monitor, freq [200000000], status 0
+K2HK EVM # bootm ${addr_kern} ${addr_uninitrd} ${addr_fdt}
+## Booting kernel from Legacy Image at 88000000 ...
+ Image Name: Linux-3.8.4
+ Created: 2014-01-27 17:48:10 UTC
+ Image Type: ARM Linux Kernel Image (uncompressed)
+ Data Size: 3990680 Bytes = 3.8 MiB
+ Load Address: 80008000
+ Entry Point: 80008000
+ Verifying Checksum ... OK
+
+-----
+
+Here is an example under Linux using the riodio utility and the riodev feature
+of the booting of a remote device which uses U-Boot RapidIO booting mechanism
+(like the example above):
+
+# riodio -f uImage /dev/rio0.1 0x88000000
+# riodio -f k2hk-evm.dtb /dev/rio0.1 0x87000000
+# riodio -f skern-keystone-evm.bin /dev/rio0.1 0xc5f0000
+# riodio -v 0xbadface /dev/rio0.1 0x80000000
+
+This will push the various images and notify U-Boot.
+
+-----
+
+Example of (local and remote) read/write commands:
+
+K2HK EVM # rio r 0 -1 1 0x0
+00000000: b9810030 0...
+K2HK EVM # rio r 0 -1 1 0x4
+00000004: 00000000 ....
+K2HK EVM # rio r 0 -1 1 0x8
+00000008: 00000030 0...
+K2HK EVM # rio lr 0
+00000000: b9810030 0...
+K2HK EVM # rio lr 8
+00000008: 00000030 0...
--
1.6.2.1
2
1

[U-Boot] [PATCH 2/4] rapidio: add support for RapidIO boot
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
04 Jan '16
From: Aurelien Jacquiot <a-jacquiot(a)ti.com>
RapidIO is a high-performance packet-switched interconnect technology
(www.rapidio.org) that can be used for messaging or memory transfers
like Ethernet or PCIe.
This commit adds the RapidIO boot functionality for slave mode (i.e.
U-Boot does not fetch the images, images are pushed by a peer device/board).
A new 'rio' command group allows to initialize and perform basic RapidIO
operations.
This feature has been firstly designed for TI KeyStone architecture but can
used by any device that has hardware RapidIO support and corresponding
driver.
For more information, read the doc/README.rapidio documentation.
Signed-off-by: Aurelien Jacquiot <a-jacquiot(a)ti.com>
---
common/Kconfig | 7 +-
common/Makefile | 1 +
common/cmd_rio.c | 260 +++++++++++++++++++++++++++++++++++++
include/rio.h | 382 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 649 insertions(+), 1 deletions(-)
create mode 100644 common/cmd_rio.c
create mode 100644 include/rio.h
diff --git a/common/Kconfig b/common/Kconfig
index 0388a6c..2a3dbd2 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -355,8 +355,13 @@ config CMD_REMOTEPROC
depends on REMOTEPROC
help
Support for Remote Processor control
-endmenu
+config CMD_RIO
+ bool "rapidio"
+ help
+ RapidIO support.
+
+endmenu
menu "Shell scripting commands"
diff --git a/common/Makefile b/common/Makefile
index d986cde..7380958 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -195,6 +195,7 @@ obj-$(CONFIG_YAFFS2) += cmd_yaffs2.o
obj-$(CONFIG_CMD_SPL) += cmd_spl.o
obj-$(CONFIG_CMD_ZIP) += cmd_zip.o
obj-$(CONFIG_CMD_ZFS) += cmd_zfs.o
+obj-$(CONFIG_CMD_RIO) += cmd_rio.o
# others
obj-$(CONFIG_BOOTSTAGE) += bootstage.o
diff --git a/common/cmd_rio.c b/common/cmd_rio.c
new file mode 100644
index 0000000..72db7d1
--- /dev/null
+++ b/common/cmd_rio.c
@@ -0,0 +1,260 @@
+/*
+ * (C) Copyright 2015
+ * Texas Instruments Incorporated, <www.ti.com>
+ * Authors: Aurelien Jacquiot <a-jacquiot(a)ti.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * RapidIO support
+ */
+#include <common.h>
+#include <command.h>
+#include <asm/io.h>
+#include <watchdog.h>
+#include <rio.h>
+
+static void *rio_handle;
+
+static int rio_cmd_init(int argc, char * const argv[])
+{
+ int riohdid = -1; /* none */
+ int riosize = 0; /* small Ids */
+ u32 rioports = 0x1; /* port 0 */
+ int riopmode = 0; /* 4 ports in 1x */
+ int riobaudrate = 1; /* 2.5Gbps */
+ char *s;
+
+ if (rio_handle) {
+ printf("RapidIO device already initialized!\n");
+ return CMD_RET_FAILURE;
+ }
+
+ /* hostid */
+ if (argc >= 2) {
+ riohdid = simple_strtol(argv[2], NULL, 10);
+ } else {
+ s = getenv("riohdid");
+ if (s != NULL)
+ riohdid = simple_strtol(s, NULL, 10);
+ goto call_init;
+ }
+
+ /* dev-id size */
+ if (argc >= 3) {
+ riosize = simple_strtol(argv[3], NULL, 10);
+ } else {
+ s = getenv("riosize");
+ if (s != NULL)
+ riosize = simple_strtol(s, NULL, 10);
+ goto call_init;
+ }
+
+ /* port bitmask */
+ if (argc >= 4) {
+ rioports = simple_strtoul(argv[4], NULL, 16);
+ } else {
+ s = getenv("rioports");
+ if (s != NULL)
+ rioports = simple_strtoul(s, NULL, 16);
+ goto call_init;
+ }
+
+ /* port path mode */
+ if (argc >= 5) {
+ riopmode = simple_strtol(argv[5], NULL, 10);
+ } else {
+ s = getenv("riopathmode");
+ if (s != NULL)
+ riopmode = simple_strtol(s, NULL, 10);
+ goto call_init;
+ }
+
+ /* baudrate */
+ if (argc >= 6) {
+ riobaudrate = simple_strtol(argv[6], NULL, 10);
+ } else {
+ s = getenv("riobaudrate");
+ if (s != NULL)
+ riobaudrate = simple_strtol(s, NULL, 10);
+ }
+
+call_init:
+ printf("rioboot: waiting for link up ...\n");
+
+ /* Initialize RIO */
+ rio_handle = rio_init(riohdid, riosize, rioports, riopmode,
+ riobaudrate);
+ if (!rio_handle)
+ return CMD_RET_FAILURE;
+
+ return CMD_RET_SUCCESS;
+}
+
+static int rio_cmd(int argc, char * const argv[])
+{
+ char *cmd;
+
+ if (argc == 1)
+ return CMD_RET_USAGE;
+
+ if (!rio_handle) {
+ printf("RapidIO device not initialized!\n");
+ return CMD_RET_FAILURE;
+ }
+
+ cmd = argv[1];
+
+ if ((strncmp(cmd, "r", 1) == 0) || (strncmp(cmd, "w", 1) == 0)) {
+ int portid;
+ u16 destid;
+ u8 hopcount;
+ u32 offset;
+
+ if (argc < 5)
+ return CMD_RET_USAGE;
+
+ portid = simple_strtol(argv[2], NULL, 10);
+ destid = simple_strtol(argv[3], NULL, 10) & 0xffff;
+ hopcount = simple_strtoul(argv[4], NULL, 10) & 0xff;
+ offset = simple_strtoul(argv[5], NULL, 16);
+
+ if (strncmp(cmd, "r", 1) == 0) {
+ int res;
+ u32 val;
+
+ /* Do maintenance read */
+ res = rio_config_read(portid,
+ destid,
+ hopcount,
+ offset,
+ sizeof(val),
+ &val);
+
+ if (res) {
+ printf("cannot perform maintenance read\n");
+ return CMD_RET_FAILURE;
+ }
+
+ /* Display value */
+ print_buffer(offset, (const void *)&val, sizeof(val),
+ 1, 0);
+ }
+
+ if (strncmp(cmd, "w", 1) == 0) {
+ int res;
+ u32 val;
+
+ if (argc < 6)
+ return CMD_RET_USAGE;
+
+ val = simple_strtoul(argv[6], NULL, 16);
+
+ /* Do maintenance write */
+ res = rio_config_write(portid,
+ destid,
+ hopcount,
+ offset,
+ sizeof(val),
+ val);
+
+ if (res) {
+ printf("cannot perform maintenance write\n");
+ return CMD_RET_FAILURE;
+ }
+ }
+
+ return CMD_RET_SUCCESS;
+ }
+
+ if ((strncmp(cmd, "lr", 2) == 0) || (strncmp(cmd, "lw", 2) == 0)) {
+ u32 offset;
+
+ if (argc < 2)
+ return CMD_RET_USAGE;
+
+ offset = simple_strtoul(argv[2], NULL, 16);
+
+ if (strncmp(cmd, "lr", 2) == 0) {
+ int res;
+ u32 val;
+
+ /* Do local read */
+ res = rio_local_config_read(offset,
+ sizeof(val),
+ &val);
+
+ if (res) {
+ printf("cannot perform local read\n");
+ return CMD_RET_FAILURE;
+ }
+
+ /* Display value */
+ print_buffer(offset, (const void *)&val, sizeof(val),
+ 1, 0);
+ }
+
+ if (strncmp(cmd, "lw", 2) == 0) {
+ int res;
+ u32 val;
+
+ if (argc < 3)
+ return CMD_RET_USAGE;
+
+ val = simple_strtoul(argv[3], NULL, 16);
+
+ /* Do local write */
+ res = rio_local_config_write(offset,
+ sizeof(val),
+ val);
+
+ if (res) {
+ printf("cannot perform local write\n");
+ return CMD_RET_FAILURE;
+ }
+ }
+
+ return CMD_RET_SUCCESS;
+ }
+
+ return CMD_RET_USAGE;
+}
+
+static int do_rio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ char *cmd = argv[1];
+ int ret;
+
+ if (strncmp(cmd, "init", 4) == 0)
+ return rio_cmd_init(argc, argv);
+
+ if (strncmp(cmd, "shutdown", 8) == 0) {
+ if (rio_handle) {
+ rio_shutdown(rio_handle);
+ rio_handle = NULL;
+ return CMD_RET_SUCCESS;
+ } else {
+ printf("RapidIO device not initialized!\n");
+ return CMD_RET_FAILURE;
+ }
+ }
+
+ ret = rio_cmd(argc, argv);
+
+ if (ret == CMD_RET_USAGE)
+ return cmd_usage(cmdtp);
+
+ return ret;
+}
+
+U_BOOT_CMD(rio, CONFIG_SYS_MAXARGS, 1, do_rio,
+ "RapidIO sub-system",
+ "init [dev_id] [id_size] [port_mask] [pathmode] [baudrate]\n"
+ " - initialized RapidIO device\n"
+ "rio shutdown - shutdown RapidIO device\n"
+ "rio r port dev_id hopcount offset - perform config read\n"
+ "rio w port dev_id hopcount offset value - perform config write\n"
+ "rio lr offset - perform local config read\n"
+ "rio lw offset value - perform local config write\n"
+);
diff --git a/include/rio.h b/include/rio.h
new file mode 100644
index 0000000..6b9341d
--- /dev/null
+++ b/include/rio.h
@@ -0,0 +1,382 @@
+/*
+ * (C) Copyright 2015
+ * Texas Instruments Incorporated, <www.ti.com>
+ * Authors: Aurelien Jacquiot <a-jacquiot(a)ti.com>
+ *
+ * Part of this file is borrowed from Linux rio_regs.h.
+ * (C) Copyright 2005 MontaVista Software, Inc.
+ * Matt Porter <mporter(a)kernel.crashing.org>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _RIO_H_
+#define _RIO_H_
+
+/*
+ * In RapidIO, each device has a 16MB configuration space that is
+ * accessed via maintenance transactions. Portions of configuration
+ * space are standardized and/or reserved.
+ */
+#define RIO_DEV_ID_CAR 0x00
+#define RIO_DEV_INFO_CAR 0x04
+#define RIO_ASM_ID_CAR 0x08
+#define RIO_ASM_ID_MASK 0xffff0000
+#define RIO_ASM_VEN_ID_MASK 0x0000ffff
+
+#define RIO_ASM_INFO_CAR 0x0c
+#define RIO_ASM_REV_MASK 0xffff0000
+#define RIO_EXT_FTR_PTR_MASK 0x0000ffff
+
+#define RIO_PEF_CAR 0x10
+#define RIO_PEF_BRIDGE 0x80000000
+#define RIO_PEF_MEMORY 0x40000000
+#define RIO_PEF_PROCESSOR 0x20000000
+#define RIO_PEF_SWITCH 0x10000000
+#define RIO_PEF_INB_MBOX 0x00f00000
+#define RIO_PEF_INB_MBOX0 0x00800000
+#define RIO_PEF_INB_MBOX1 0x00400000
+#define RIO_PEF_INB_MBOX2 0x00200000
+#define RIO_PEF_INB_MBOX3 0x00100000
+#define RIO_PEF_INB_DOORBELL 0x00080000
+#define RIO_PEF_EXT_RT 0x00000200
+#define RIO_PEF_STD_RT 0x00000100
+#define RIO_PEF_CTLS 0x00000010
+#define RIO_PEF_FLOW_CONTROL 0x00000080
+#define RIO_PEF_EXT_FEATURES 0x00000008
+#define RIO_PEF_ADDR_66 0x00000004
+#define RIO_PEF_ADDR_50 0x00000002
+#define RIO_PEF_ADDR_34 0x00000001
+
+#define RIO_SWP_INFO_CAR 0x14
+#define RIO_SWP_INFO_PORT_TOTAL_MASK 0x0000ff00
+#define RIO_SWP_INFO_PORT_NUM_MASK 0x000000ff
+
+#define RIO_SRC_OPS_CAR 0x18
+#define RIO_SRC_OPS_READ 0x00008000
+#define RIO_SRC_OPS_WRITE 0x00004000
+#define RIO_SRC_OPS_STREAM_WRITE 0x00002000
+#define RIO_SRC_OPS_WRITE_RESPONSE 0x00001000
+#define RIO_SRC_OPS_DATA_MSG 0x00000800
+#define RIO_SRC_OPS_DOORBELL 0x00000400
+#define RIO_SRC_OPS_ATOMIC_TST_SWP 0x00000100
+#define RIO_SRC_OPS_ATOMIC_INC 0x00000080
+#define RIO_SRC_OPS_ATOMIC_DEC 0x00000040
+#define RIO_SRC_OPS_ATOMIC_SET 0x00000020
+#define RIO_SRC_OPS_ATOMIC_CLR 0x00000010
+#define RIO_SRC_OPS_PORT_WRITE 0x00000004
+
+#define RIO_DST_OPS_CAR 0x1c
+#define RIO_DST_OPS_READ 0x00008000
+#define RIO_DST_OPS_WRITE 0x00004000
+#define RIO_DST_OPS_STREAM_WRITE 0x00002000
+#define RIO_DST_OPS_WRITE_RESPONSE 0x00001000
+#define RIO_DST_OPS_DATA_MSG 0x00000800
+#define RIO_DST_OPS_DOORBELL 0x00000400
+#define RIO_DST_OPS_ATOMIC_TST_SWP 0x00000100
+#define RIO_DST_OPS_ATOMIC_INC 0x00000080
+#define RIO_DST_OPS_ATOMIC_DEC 0x00000040
+#define RIO_DST_OPS_ATOMIC_SET 0x00000020
+#define RIO_DST_OPS_ATOMIC_CLR 0x00000010
+#define RIO_DST_OPS_PORT_WRITE 0x00000004
+
+#define RIO_OPS_READ 0x00008000
+#define RIO_OPS_WRITE 0x00004000
+#define RIO_OPS_STREAM_WRITE 0x00002000
+#define RIO_OPS_WRITE_RESPONSE 0x00001000
+#define RIO_OPS_DATA_MSG 0x00000800
+#define RIO_OPS_DOORBELL 0x00000400
+#define RIO_OPS_ATOMIC_TST_SWP 0x00000100
+#define RIO_OPS_ATOMIC_INC 0x00000080
+#define RIO_OPS_ATOMIC_DEC 0x00000040
+#define RIO_OPS_ATOMIC_SET 0x00000020
+#define RIO_OPS_ATOMIC_CLR 0x00000010
+#define RIO_OPS_PORT_WRITE 0x00000004
+
+ /* 0x20-0x30 *//* Reserved */
+
+#define RIO_SWITCH_RT_LIMIT 0x34
+#define RIO_RT_MAX_DESTID 0x0000ffff
+
+#define RIO_MBOX_CSR 0x40
+#define RIO_MBOX0_AVAIL 0x80000000
+#define RIO_MBOX0_FULL 0x40000000
+#define RIO_MBOX0_EMPTY 0x20000000
+#define RIO_MBOX0_BUSY 0x10000000
+#define RIO_MBOX0_FAIL 0x08000000
+#define RIO_MBOX0_ERROR 0x04000000
+#define RIO_MBOX1_AVAIL 0x00800000
+#define RIO_MBOX1_FULL 0x00200000
+#define RIO_MBOX1_EMPTY 0x00200000
+#define RIO_MBOX1_BUSY 0x00100000
+#define RIO_MBOX1_FAIL 0x00080000
+#define RIO_MBOX1_ERROR 0x00040000
+#define RIO_MBOX2_AVAIL 0x00008000
+#define RIO_MBOX2_FULL 0x00004000
+#define RIO_MBOX2_EMPTY 0x00002000
+#define RIO_MBOX2_BUSY 0x00001000
+#define RIO_MBOX2_FAIL 0x00000800
+#define RIO_MBOX2_ERROR 0x00000400
+#define RIO_MBOX3_AVAIL 0x00000080
+#define RIO_MBOX3_FULL 0x00000040
+#define RIO_MBOX3_EMPTY 0x00000020
+#define RIO_MBOX3_BUSY 0x00000010
+#define RIO_MBOX3_FAIL 0x00000008
+#define RIO_MBOX3_ERROR 0x00000004
+
+#define RIO_WRITE_PORT_CSR 0x44
+#define RIO_DOORBELL_CSR 0x44
+#define RIO_DOORBELL_AVAIL 0x80000000
+#define RIO_DOORBELL_FULL 0x40000000
+#define RIO_DOORBELL_EMPTY 0x20000000
+#define RIO_DOORBELL_BUSY 0x10000000
+#define RIO_DOORBELL_FAILED 0x08000000
+#define RIO_DOORBELL_ERROR 0x04000000
+#define RIO_WRITE_PORT_AVAILABLE 0x00000080
+#define RIO_WRITE_PORT_FULL 0x00000040
+#define RIO_WRITE_PORT_EMPTY 0x00000020
+#define RIO_WRITE_PORT_BUSY 0x00000010
+#define RIO_WRITE_PORT_FAILED 0x00000008
+#define RIO_WRITE_PORT_ERROR 0x00000004
+
+ /* 0x48 *//* Reserved */
+
+#define RIO_PELL_CTRL_CSR 0x4c
+#define RIO_PELL_ADDR_66 0x00000004
+#define RIO_PELL_ADDR_50 0x00000002
+#define RIO_PELL_ADDR_34 0x00000001
+
+ /* 0x50-0x54 *//* Reserved */
+
+#define RIO_LCSH_BA 0x58
+#define RIO_LCSL_BA 0x5c
+
+#define RIO_DID_CSR 0x60
+
+ /* 0x64 *//* Reserved */
+
+#define RIO_HOST_DID_LOCK_CSR 0x68
+#define RIO_COMPONENT_TAG_CSR 0x6c
+
+#define RIO_STD_RTE_CONF_DESTID_SEL_CSR 0x70
+#define RIO_STD_RTE_CONF_PORT_SEL_CSR 0x74
+#define RIO_STD_RTE_DEFAULT_PORT 0x78
+
+ /* 0x7c-0xf8 *//* Reserved */
+ /* 0x100-0xfff8 *//* [I] Extended Features Space */
+
+#define RIO_PORT_LINK_MAINT_REQ_CSR 0x140
+#define RIO_PORT_LINK_MAINT_RESP_CSR 0x144
+#define RIO_PORT_LOCAL_ACKID_CSR 0x148
+#define RIO_PORT_ERR_STAT_CSR 0x158
+#define RIO_PORT_CTRL_CSR 0x15c
+
+#define RIO_PORT_OFFSET 0x20
+
+#define RIO_PORT_CTRL_TYPE_SERIAL 0x00000001
+#define RIO_PORT_CTRL_ENUM_BOUNDARY 0x00020000
+#define RIO_PORT_CTRL_MCAST_EVT_PART 0x00080000
+#define RIO_PORT_CTRL_ERR_CHECK_DIS 0x00100000
+#define RIO_PORT_CTRL_INPUT_PORT_EN 0x00200000
+#define RIO_PORT_CTRL_OUTPUT_PORT_EN 0x00400000
+#define RIO_PORT_CTRL_PORT_DIS 0x00800000
+
+ /* 0x10000-0xfffff8 *//* [I] Implementation-defined Space */
+
+/*
+ * Extended Features Space is a configuration space area where
+ * functionality is mapped into extended feature blocks via a
+ * singly linked list of extended feature pointers (EFT_PTR).
+ *
+ * Each extended feature block can be identified/located in
+ * Extended Features Space by walking the extended feature
+ * list starting with the Extended Feature Pointer located
+ * in the Assembly Information CAR.
+ *
+ * Extended Feature Blocks (EFBs) are identified with an assigned
+ * EFB ID. Extended feature block offsets in the definitions are
+ * relative to the offset of the EFB within the Extended Features
+ * Space.
+ */
+
+/* Helper macros to parse the Extended Feature Block header */
+#define RIO_EFB_PTR_MASK 0xffff0000
+#define RIO_EFB_ID_MASK 0x0000ffff
+#define RIO_GET_BLOCK_PTR(x) ((x & RIO_EFB_PTR_MASK) >> 16)
+#define RIO_GET_BLOCK_ID(x) (x & RIO_EFB_ID_MASK)
+
+/* Extended Feature Block IDs */
+#define RIO_EFB_PAR_EP_ID 0x0001
+#define RIO_EFB_PAR_EP_REC_ID 0x0002
+#define RIO_EFB_PAR_EP_FREE_ID 0x0003
+#define RIO_EFB_SER_EP_ID_V13P 0x0001
+#define RIO_EFB_SER_EP_REC_ID_V13P 0x0002
+#define RIO_EFB_SER_EP_FREE_ID_V13P 0x0003
+#define RIO_EFB_SER_EP_ID 0x0004
+#define RIO_EFB_SER_EP_REC_ID 0x0005
+#define RIO_EFB_SER_EP_FREE_ID 0x0006
+#define RIO_EFB_SER_EP_FREC_ID 0x0009
+#define RIO_EFB_ERR_MGMNT 0x0007
+
+/*
+ * Physical 8/16 LP-LVDS
+ * ID=0x0001, Generic End Point Devices
+ * ID=0x0002, Generic End Point Devices, software assisted recovery option
+ * ID=0x0003, Generic End Point Free Devices
+ *
+ * Physical LP-Serial
+ * ID=0x0004, Generic End Point Devices
+ * ID=0x0005, Generic End Point Devices, software assisted recovery option
+ * ID=0x0006, Generic End Point Free Devices
+ */
+#define RIO_PORT_MNT_HEADER 0x0000
+#define RIO_PORT_REQ_CTL_CSR 0x0020
+#define RIO_PORT_RSP_CTL_CSR 0x0024 /* 0x0001/0x0002 */
+#define RIO_PORT_LINKTO_CTL_CSR 0x0020 /* Serial */
+#define RIO_PORT_RSPTO_CTL_CSR 0x0024 /* Serial */
+#define RIO_PORT_GEN_CTL_CSR 0x003c
+#define RIO_PORT_GEN_HOST 0x80000000
+#define RIO_PORT_GEN_MASTER 0x40000000
+#define RIO_PORT_GEN_DISCOVERED 0x20000000
+#define RIO_PORT_N_MNT_REQ_CSR(x) (0x0040 + x*0x20)
+#define RIO_PORT_N_MNT_RSP_CSR(x) (0x0044 + x*0x20)
+#define RIO_PORT_N_MNT_RSP_RVAL 0x80000000
+#define RIO_PORT_N_MNT_RSP_ASTAT 0x000003e0
+#define RIO_PORT_N_MNT_RSP_LSTAT 0x0000001f
+#define RIO_PORT_N_ACK_STS_CSR(x) (0x0048 + x*0x20)
+#define RIO_PORT_N_ACK_CLEAR 0x80000000
+#define RIO_PORT_N_ACK_INBOUND 0x1f000000
+#define RIO_PORT_N_ACK_OUTSTAND 0x00001f00
+#define RIO_PORT_N_ACK_OUTBOUND 0x0000001f
+#define RIO_PORT_N_ERR_STS_CSR(x) (0x0058 + x*0x20)
+#define RIO_PORT_N_ERR_STS_PW_OUT_ES 0x00010000 /* Output Error-stopped */
+#define RIO_PORT_N_ERR_STS_PW_INP_ES 0x00000100 /* Input Error-stopped */
+#define RIO_PORT_N_ERR_STS_PW_PEND 0x00000010 /* Port-Write Pending */
+#define RIO_PORT_N_ERR_STS_PORT_ERR 0x00000004
+#define RIO_PORT_N_ERR_STS_PORT_OK 0x00000002
+#define RIO_PORT_N_ERR_STS_PORT_UNINIT 0x00000001
+#define RIO_PORT_N_ERR_STS_CLR_MASK 0x07120204
+#define RIO_PORT_N_CTL_CSR(x) (0x005c + x*0x20)
+#define RIO_PORT_N_CTL_PWIDTH 0xc0000000
+#define RIO_PORT_N_CTL_PWIDTH_1 0x00000000
+#define RIO_PORT_N_CTL_PWIDTH_4 0x40000000
+#define RIO_PORT_N_CTL_P_TYP_SER 0x00000001
+#define RIO_PORT_N_CTL_LOCKOUT 0x00000002
+#define RIO_PORT_N_CTL_EN_RX_SER 0x00200000
+#define RIO_PORT_N_CTL_EN_TX_SER 0x00400000
+#define RIO_PORT_N_CTL_EN_RX_PAR 0x08000000
+#define RIO_PORT_N_CTL_EN_TX_PAR 0x40000000
+
+/*
+ * Error Management Extensions (RapidIO 1.3+, Part 8)
+ *
+ * Extended Features Block ID=0x0007
+ */
+
+/* General EM Registers (Common for all Ports) */
+
+#define RIO_EM_EFB_HEADER 0x000
+#define RIO_EM_LTL_ERR_DETECT 0x008
+#define RIO_EM_LTL_ERR_EN 0x00c
+#define RIO_EM_LTL_HIADDR_CAP 0x010
+#define RIO_EM_LTL_ADDR_CAP 0x014
+#define RIO_EM_LTL_DEVID_CAP 0x018
+#define RIO_EM_LTL_CTRL_CAP 0x01c
+#define RIO_EM_PW_TGT_DEVID 0x028
+#define RIO_EM_PKT_TTL 0x02c
+
+/* Per-Port EM Registers */
+
+#define RIO_EM_PN_ERR_DETECT(x) (0x040 + x*0x40)
+#define REM_PED_IMPL_SPEC 0x80000000
+#define REM_PED_LINK_TO 0x00000001
+#define RIO_EM_PN_ERRRATE_EN(x) (0x044 + x*0x40)
+#define RIO_EM_PN_ATTRIB_CAP(x) (0x048 + x*0x40)
+#define RIO_EM_PN_PKT_CAP_0(x) (0x04c + x*0x40)
+#define RIO_EM_PN_PKT_CAP_1(x) (0x050 + x*0x40)
+#define RIO_EM_PN_PKT_CAP_2(x) (0x054 + x*0x40)
+#define RIO_EM_PN_PKT_CAP_3(x) (0x058 + x*0x40)
+#define RIO_EM_PN_ERRRATE(x) (0x068 + x*0x40)
+#define RIO_EM_PN_ERRRATE_TR(x) (0x06c + x*0x40)
+
+/**
+ * rio_init - Initialize RapidIO subsystem
+ * @riohdid: RapidIO host device ID
+ * @riosize: RapidIO device ID size
+ * @rioports: bitmask of ports to configure
+ * @riopmode: path mode (lanes to ports mapping)
+ * @riobaudrate: link baudrate
+ *
+ * Returns riohandle on success or %NULL on failure.
+ */
+void *rio_init(int riohdid,
+ int riosize,
+ u32 rioports,
+ int riopmode,
+ int riobaudrate);
+
+/**
+ * rio_shutdown - Shutdown RapidIO subsystem
+ * @riohandle: RapidIO handle (returned by rio_init)
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_shutdown(void *riohandle);
+
+/**
+ * rio_config_read - Generate a RIO read maintenance transaction
+ * @portid: Output port ID of transaction
+ * @destid: Destination ID of transaction
+ * @hopcount: Number of hops to target device
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @val: Location to be read into
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_config_read(int portid,
+ u16 destid,
+ u8 hopcount,
+ u32 offset,
+ int len,
+ u32 *val);
+
+/**
+ * rio_config_write - Generate a RIO write maintenance transaction
+ * @portid: Output port ID of transaction
+ * @destid: Destination ID of transaction
+ * @hopcount: Number of hops to target device
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @val: Value to be written
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_config_write(int portid,
+ u16 destid,
+ u8 hopcount,
+ u32 offset,
+ int len,
+ u32 val);
+
+/**
+ * rio_local_config_read - RIO local config space read
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @data: Value to be read into
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_local_config_read(u32 offset, int len, u32 *data);
+
+/**
+ * rio_local_config_write - RIO local config space write
+ * @offset: Offset into configuration space
+ * @len: Length (in bytes) of the maintenance transaction
+ * @data: Value to be written
+ *
+ * Returns %0 on success or %-1 on failure.
+ */
+int rio_local_config_write(u32 offset, int len, u32 data);
+
+#endif /* _RIO_H_ */
--
1.6.2.1
2
1

[U-Boot] [PATCH 1/4] cmd_mem.c: add a memory wait (mwait) command
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
by jacquiot.aurelienï¼ gmail.com 04 Jan '16
04 Jan '16
From: Aurelien Jacquiot <a-jacquiot(a)ti.com>
This new memory command allows to wait a given value in memory.
It can be useful when U-Boot is used in a slave mode (another device
is pushing images to the local memory) such as RapidIO or any
RDMA kind of transport. We can then be notified that images have been
loaded to our memory before booting.
Usage is: mwait[.b, .w, .l, .q] address value
Signed-off-by: Aurelien Jacquiot <a-jacquiot(a)ti.com>
---
common/cmd_mem.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index 43c3fb6..af6e39d 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -1238,6 +1238,65 @@ static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#endif
+static int
+do_mem_mwait(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+ ulong addr;
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+ u64 val, readval;
+#else
+ ulong val, readval;
+#endif
+ int size;
+
+ if (argc != 3)
+ return CMD_RET_USAGE;
+
+ /* check for size specification */
+ size = cmd_get_data_size(argv[0], 4);
+ if (size < 1)
+ return 1;
+
+ /* first arg: address */
+ addr = simple_strtoul(argv[1], NULL, 16);
+
+ /* second arg: expected value */
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+ val = simple_strtoull(argv[2], NULL, 16);
+ printf("waiting 0x%llx at 0x%lx...\n", val, addr);
+#else
+ val = simple_strtoul(argv[2], NULL, 16);
+ printf("waiting 0x%lx at 0x%lx...\n", val, addr);
+#endif
+
+ for (;;) {
+ if (size == 4)
+ readval = *((u32 *)addr);
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+ else if (size == 8)
+ readval = *((u64 *)addr);
+#endif
+ else if (size == 2)
+ readval = *((u16 *)addr);
+ else
+ readval = *((u8 *)addr);
+
+ if (readval == val)
+ return 0;
+
+ /* check for ctrl-c to abort... */
+ if (ctrlc()) {
+ puts("Abort\n");
+ return 0;
+ }
+
+ WATCHDOG_RESET();
+ udelay(1000);
+ }
+
+ return 0;
+}
+
/**************************************************/
U_BOOT_CMD(
md, 3, 1, do_mem_md,
@@ -1399,6 +1458,16 @@ U_BOOT_CMD(
);
#endif /* CONFIG_MX_CYCLIC */
+U_BOOT_CMD(
+ mwait, 3, 1, do_mem_mwait,
+ "memory wait for value",
+#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
+ "[.b, .w, .l, .q] address value\n"
+#else
+ "[.b, .w, .l] address value\n"
+#endif
+);
+
#ifdef CONFIG_CMD_MEMINFO
U_BOOT_CMD(
meminfo, 3, 1, do_mem_info,
--
1.6.2.1
2
1
The following changes since commit 78680314c53a95c0bb25e942662979843b60d7b9:
Merge branch 'master' of http://git.denx.de/u-boot-sunxi (2015-12-27 09:15:57
-0500)
are available in the git repository at:
git://git.denx.de/u-boot-usb.git master
for you to fetch changes up to f3643fe7d0dcd8a799fe8882db0903b3477e6338:
usb: musb: Fix hub port setting for SPLIT transactions (2015-12-31 10:05:32
+0100)
----------------------------------------------------------------
Stefan Brüns (4):
usb: Alloc buffer for USB descriptor dynamically
usb: dwc2: avoid out of bounds access
usb: Move determination of TT hub address/port into separate function
usb: musb: Fix hub port setting for SPLIT transactions
common/usb.c | 98
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
drivers/usb/host/dwc2.c | 7 ++++---
drivers/usb/host/ehci-hcd.c | 50
+++++---------------------------------------------
drivers/usb/musb-new/musb_host.c | 10 +++++++---
drivers/usb/musb-new/usb-compat.h | 53
-----------------------------------------------------
include/usb.h | 17 +++++++++++++++--
6 files changed, 115 insertions(+), 120 deletions(-)
2
5
Hi Tom,
my first PR of the year ! Please pull from u-boot-imx, thanks !
The following changes since commit 1d149eddcc0661b683002f76a8240491eba00dbb:
dm: Add timeline and guide for porting serial drivers (2015-11-20
13:59:54 -0500)
are available in the git repository at:
git://www.denx.de/git/u-boot-imx.git master
for you to fetch changes up to ccf4326bac0371774265be0a8b13c150b445e703:
imx: mx6qsabreauto: support lvds display (2016-01-03 16:03:14 +0100)
----------------------------------------------------------------
Eric Nelson (1):
ARM: imx: fsl_esdhc: fix usage of low 4 bits of sysctl register
Fabio Estevam (1):
mx6sxsabresd: Fix Ethernet PHY reset sequence
Gong Qianyu (1):
i2c: mxc: add a condition in case the parameter is NULL
Jeroen Hofstee (1):
imx: mx6: add missing return value
Marek Vasut (3):
arm: mx6: Reduce SPL malloc pool size
arm: imx6: novena, gw_ventana: Fix use of pfuze100 bit definitions
arm: imx6: novena: Enable extfs support in SPL
Maximilian Schwerin (1):
serial_mxc: Fix setup of UARTx_UFCR register
Michael Heimpold (2):
ARM: mxs: fix VDDD brownout setting
ARM: mxs: allow boards to select DC-DC switching clock source
Michael Schanz (1):
cgtqmx6eval: fix pad configuration for SPI bus
Måns Rullgård (2):
net: fec_mxc: configure MDIO hold time
net: fec_mxc: unregister mdio bus on probe error
Otavio Salvador (7):
cgtqmx6eval: Add SPI NOR flash support
cgtqmx6eval: Use SPI NOR to store the environment
cgtqmx6eval: Add fastboot support
cgtqmx6eval: Add SPL support
iomux-v3: Take MX6D in consideration for imx_iomux_v3_setup_pad()
cgtqmx6eval: Add DFU support
cgtqmx6eval: Fix defconfig name
Peng Fan (5):
video: ipu: simplify if else code
imx: mx7: enable CONFIG_FSL_CLK
imx: mx6: fix reg base address when runtime usage
imx: ddr: drop duplicated debug info
imx: mx6qsabreauto: support lvds display
Sanchayan Maity (1):
colibri_vf: Add board_usb_phy_mode function
Stefano Babic (1):
imx_common: check for Serial Downloader in spl_boot_device
Vagrant Cascadian (1):
arm: novena: Switch novena to config_distro_bootcmd
Ye.Li (1):
mx6: clock: Modify GPMI clock to support mx6sx
arch/arm/cpu/arm926ejs/mxs/spl_power_init.c | 38 ++++++++++-
arch/arm/cpu/armv7/mx6/Kconfig | 3 +
arch/arm/cpu/armv7/mx6/clock.c | 14 ++++
arch/arm/cpu/armv7/mx6/ddr.c | 1 -
arch/arm/imx-common/spl.c | 8 +++
arch/arm/include/asm/arch-mx6/imx-regs.h | 8 +--
arch/arm/include/asm/arch-mxs/sys_proto.h | 2 +
arch/arm/include/asm/imx-common/iomux-v3.h | 2 +-
board/congatec/cgtqmx6eval/MAINTAINERS | 2 +-
board/congatec/cgtqmx6eval/README | 78
++++++++++++++++------
board/congatec/cgtqmx6eval/cgtqmx6eval.c | 599
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
board/congatec/cgtqmx6eval/imximage.cfg | 143
-----------------------------------------
board/freescale/mx6qsabreauto/mx6qsabreauto.c | 87
++++++++++++++++++++++++-
board/freescale/mx6sxsabresd/mx6sxsabresd.c | 10 ++-
board/gateworks/gw_ventana/common.c | 2 +-
board/kosagi/novena/novena.c | 2 +-
board/toradex/colibri_vf/colibri_vf.c | 33 +++++++++-
configs/{cgtqmx6qeval_defconfig => cgtqmx6eval_defconfig} | 5 +-
doc/README.imx6 | 51
+++++++++++++++
drivers/i2c/mxc_i2c.c | 12 +++-
drivers/mmc/fsl_esdhc.c | 15 ++++-
drivers/net/fec_mxc.c | 20 +++++-
drivers/serial/serial_mxc.c | 9 ++-
drivers/video/ipu_disp.c | 4 +-
include/configs/cgtqmx6eval.h | 68
++++++++++++++++++--
include/configs/imx6_spl.h | 6 +-
include/configs/mx7_common.h | 2 +
include/configs/novena.h | 24 ++++++-
include/fsl_esdhc.h | 2 +
29 files changed, 956 insertions(+), 294 deletions(-)
delete mode 100644 board/congatec/cgtqmx6eval/imximage.cfg
rename configs/{cgtqmx6qeval_defconfig => cgtqmx6eval_defconfig} (72%)
--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic(a)denx.de
=====================================================================
2
1

04 Jan '16
From: Thomas Gleixner <tglx(a)linutronix.de>
This is an update of Thomas's patch:
https://patchwork.ozlabs.org/patch/367306/
patch still depends on spl_nand_simple implementation:
https://patchwork.ozlabs.org/patch/367305/
Changes from original version:
- fixes ubi_calc_fm_size to include also sizeof(struct ubi_fm_sb)
- dropped private copy of ubi-media.h
- accomodate for actual Makefile
As original patch is more that a year old, should we update to current
linux fastmap code?
Signed-off-by: Thomas Gleixner <tglx(a)linutronix.de>
Signed-off-by: Ladislav Michl <ladis(a)linux-mips.org>
---
README | 4 +
doc/README.ubispl | 144 ++++++
drivers/Makefile | 3 +-
drivers/mtd/ubispl/Makefile | 1 +
drivers/mtd/ubispl/ubi-wrapper.h | 104 +++++
drivers/mtd/ubispl/ubispl.c | 921 +++++++++++++++++++++++++++++++++++++++
drivers/mtd/ubispl/ubispl.h | 136 ++++++
include/ubispl.h | 90 ++++
8 files changed, 1402 insertions(+), 1 deletion(-)
create mode 100644 doc/README.ubispl
create mode 100644 drivers/mtd/ubispl/Makefile
create mode 100644 drivers/mtd/ubispl/ubi-wrapper.h
create mode 100644 drivers/mtd/ubispl/ubispl.c
create mode 100644 drivers/mtd/ubispl/ubispl.h
create mode 100644 include/ubispl.h
diff --git a/README b/README
index 43f307f..b6d01a9 100644
--- a/README
+++ b/README
@@ -3654,6 +3654,10 @@ FIT uImage format:
Support for NAND boot using simple NAND drivers that
expose the cmd_ctrl() interface.
+ CONFIG_SPL_UBI
+ Support for a lightweight UBI (fastmap) scanner and
+ loader
+
CONFIG_SPL_MTD_SUPPORT
Support for the MTD subsystem within SPL. Useful for
environment on NAND support within SPL.
diff --git a/doc/README.ubispl b/doc/README.ubispl
new file mode 100644
index 0000000..f90e0a1
--- /dev/null
+++ b/doc/README.ubispl
@@ -0,0 +1,144 @@
+Lightweight UBI and UBI fastmap support
+
+# Copyright (C) Thomas Gleixner <tglx(a)linutronix.de>
+#
+# SPDX-License-Identifier: GPL-2.0+
+
+Scans the UBI information and loads the requested static volumes into
+memory.
+
+Configuration Options:
+
+ CONFIG_SPL_UBI
+ Enables the SPL UBI support
+
+ CONFIG_SPL_UBI_MAX_VOL_LEBS
+ The maximum number of logical eraseblocks which a static volume
+ to load can contain. Used for sizing the scan data structure
+
+ CONFIG_SPL_UBI_MAX_PEB_SIZE
+ The maximum physical erase block size. Either a compile time
+ constant or runtime detection. Used for sizing the scan data
+ structure
+
+ CONFIG_SPL_UBI_MAX_PEBS
+ The maximum physical erase block count. Either a compile time
+ constant or runtime detection. Used for sizing the scan data
+ structure
+
+ CONFIG_SPL_UBI_VOL_IDS
+ The maximum volume ids which can be loaded. Used for sizing the
+ scan data structure.
+
+Usage notes:
+
+In the board config file define for example:
+
+#define CONFIG_SPL_UBI
+#define CONFIG_SPL_UBI_MAX_VOL_LEBS 256
+#define CONFIG_SPL_UBI_MAX_PEB_SIZE (256*1024)
+#define CONFIG_SPL_UBI_MAX_PEBS 4096
+#define CONFIG_SPL_UBI_VOL_IDS 8
+
+The size requirement is roughly as follows:
+
+ 2k for the basic data structure
+ + CONFIG_SPL_UBI_VOL_IDS * CONFIG_SPL_UBI_MAX_VOL_LEBS * 8
+ + CONFIG_SPL_UBI_MAX_PEBS * 64
+ + CONFIG_SPL_UBI_MAX_PEB_SIZE * UBI_FM_MAX_BLOCKS
+
+The last one is big, but I really don't care in that stage. Real world
+implementations only use the first couple of blocks, but the code
+handles up to UBI_FM_MAX_BLOCKS.
+
+Given the above configuration example the requirement is about 5M
+which is usually not a problem to reserve in the RAM along with the
+other areas like the kernel/dts load address.
+
+So something like this will do the trick:
+
+#define SPL_FINFO_ADDR 0x80800000
+#define SPL_DTB_LOAD_ADDR 0x81800000
+#define SPL_KERNEL_LOAD_ADDR 0x82000000
+
+In the board file, implement the following:
+
+static struct ubispl_load myvolumes[] = {
+ {
+ .name = "Kernel",
+ .vol_id = 0,
+ .load_addr = (void *)SPL_KERNEL_LOAD_ADDR,
+ },
+ {
+ .name = "DTB",
+ .vol_id = 1,
+ .load_addr = (void *)SPL_DTB_LOAD_ADDR,
+ }
+};
+
+int spl_start_uboot(void)
+{
+ struct ubispl_info info;
+
+ info.ubi = (struct ubi_scan_info *) SPL_FINFO_ADDR;
+ info.fastmap = 1;
+ info.read = nand_spl_read_flash;
+
+#if COMPILE_TIME_DEFINED
+ /*
+ * MY_NAND_NR_SPL_PEBS is the number of physical erase blocks
+ * in the FLASH which are reserved for the SPL. Think about
+ * mtd partitions:
+ *
+ * part_spl { .start = 0, .end = 4 }
+ * part_ubi { .start = 4, .end = NR_PEBS }
+ */
+ info.peb_offset = MY_NAND_NR_SPL_PEBS;
+ info.peb_size = CONFIG_SYS_NAND_BLOCK_SIZE;
+ info.vid_offset = MY_NAND_UBI_VID_OFFS;
+ info.leb_start = MY_NAND_UBI_DATA_OFFS;
+ info.peb_count = MY_NAND_UBI_NUM_PEBS;
+#else
+ get_flash_info(&flash_info);
+ info.peb_offset = MY_NAND_NR_SPL_PEBS;
+ info.peb_size = flash_info.peb_size;
+
+ /*
+ * The VID and Data offset depend on the capability of the
+ * FLASH chip to do subpage writes.
+ *
+ * If the flash chip supports subpage writes, then the VID
+ * header starts at the second subpage. So for 2k pages size
+ * with 4 subpages the VID offset is 512. The DATA offset is 2k.
+ *
+ * If the flash chip does not support subpage writes then the
+ * VID offset is FLASH_PAGE_SIZE and the DATA offset
+ * 2 * FLASH_PAGE_SIZE
+ */
+ info.vid_offset = flash_info.vid_offset;
+ info.leb_start = flash_info.data_offset;
+
+ /*
+ * The flash reports the total number of erase blocks, so
+ * we need to subtract the number of blocks which are reserved
+ * for the SPL itself and not managed by UBI.
+ */
+ info.peb_count = flash_info.peb_count - MY_NAND_NR_SPL_PEBS;
+#endif
+
+ ret = ubispl_load_volumes(&info, myvolumes, ARRAY_SIZE(myvolumes);
+
+ ....
+
+}
+
+Note: you can load any payload that way. You can even load u-boot from
+UBI, so the only non UBI managed FLASH area is the one which is
+reserved for the SPL itself and read from the SoC ROM.
+
+And you can do fallback scenarios:
+
+ if (ubispl_load_volumes(&info, volumes0, ARRAY_SIZE(volumes0)))
+ if (ubispl_load_volumes(&info, volumes1, ARRAY_SIZE(volumes1)))
+ ubispl_load_volumes(&info, vol_uboot, ARRAY_SIZE(vol_uboot));
+
diff --git a/drivers/Makefile b/drivers/Makefile
index c9031f2..e0bcb52 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -22,10 +22,11 @@ obj-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += mtd/spi/
obj-$(CONFIG_SPL_SPI_SUPPORT) += spi/
obj-$(CONFIG_SPL_POWER_SUPPORT) += power/ power/pmic/
obj-$(CONFIG_SPL_POWER_SUPPORT) += power/regulator/
+obj-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += misc/
obj-$(CONFIG_SPL_MTD_SUPPORT) += mtd/
obj-$(CONFIG_SPL_NAND_SUPPORT) += mtd/nand/
-obj-$(CONFIG_SPL_DRIVERS_MISC_SUPPORT) += misc/
obj-$(CONFIG_SPL_ONENAND_SUPPORT) += mtd/onenand/
+obj-$(CONFIG_SPL_UBI) += mtd/ubispl/
obj-$(CONFIG_SPL_DMA_SUPPORT) += dma/
obj-$(CONFIG_SPL_ETH_SUPPORT) += net/
obj-$(CONFIG_SPL_ETH_SUPPORT) += net/phy/
diff --git a/drivers/mtd/ubispl/Makefile b/drivers/mtd/ubispl/Makefile
new file mode 100644
index 0000000..740dbed
--- /dev/null
+++ b/drivers/mtd/ubispl/Makefile
@@ -0,0 +1 @@
+obj-y += ubispl.o ../ubi/crc32.o
diff --git a/drivers/mtd/ubispl/ubi-wrapper.h b/drivers/mtd/ubispl/ubi-wrapper.h
new file mode 100644
index 0000000..dd76e6b
--- /dev/null
+++ b/drivers/mtd/ubispl/ubi-wrapper.h
@@ -0,0 +1,104 @@
+/*
+ * The parts taken from the kernel implementation are:
+ *
+ * Copyright (c) International Business Machines Corp., 2006
+ *
+ * UBISPL specific wrappers and defines:
+ *
+ * Copyright (c) Thomas Gleixner <tglx(a)linutronix.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * Contains various defines, wrappers to make the upstream fastboot
+ * code happy.
+ */
+#ifndef __UBOOT_UBI_WRAPPER_H
+#define __UBOOT_UBI_WRAPPER_H
+
+/*
+ * Error codes returned by the I/O sub-system.
+ *
+ * UBI_IO_FF: the read region of flash contains only 0xFFs
+ * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data
+ * integrity error reported by the MTD driver
+ * (uncorrectable ECC error in case of NAND)
+ * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
+ * UBI_IO_BAD_HDR_EBADMSG: the same as %UBI_IO_BAD_HDR, but also there was a
+ * data integrity error reported by the MTD driver
+ * (uncorrectable ECC error in case of NAND)
+ * UBI_IO_BITFLIPS: bit-flips were detected and corrected
+ *
+ * UBI_FASTMAP_ANCHOR: u-boot SPL add on to tell the caller that the fastmap
+ * anchor block has been found
+ *
+ * Note, it is probably better to have bit-flip and ebadmsg as flags which can
+ * be or'ed with other error code. But this is a big change because there are
+ * may callers, so it does not worth the risk of introducing a bug
+ */
+enum {
+ UBI_IO_FF = 1,
+ UBI_IO_FF_BITFLIPS,
+ UBI_IO_BAD_HDR,
+ UBI_IO_BAD_HDR_EBADMSG,
+ UBI_IO_BITFLIPS,
+ UBI_FASTMAP_ANCHOR,
+};
+
+/*
+ * UBI volume type constants.
+ *
+ * @UBI_DYNAMIC_VOLUME: dynamic volume
+ * @UBI_STATIC_VOLUME: static volume
+ */
+enum {
+ UBI_DYNAMIC_VOLUME = 3,
+ UBI_STATIC_VOLUME = 4,
+};
+
+#define UBI_BAD_FASTMAP (-1)
+
+/*
+ * Stub structure so the fastmap code is happy.
+ */
+struct ubi_attach_info {
+ int i;
+};
+
+/**
+ * struct ubi_fastmap_layout - in-memory fastmap data structure.
+ * @e: PEBs used by the current fastmap
+ * @to_be_tortured: if non-zero tortured this PEB
+ * @used_blocks: number of used PEBs
+ * @max_pool_size: maximal size of the user pool
+ * @max_wl_pool_size: maximal size of the pool used by the WL sub-system
+ */
+struct ubi_fastmap_layout {
+ struct ubi_wl_entry *e[UBI_FM_MAX_BLOCKS];
+ int to_be_tortured[UBI_FM_MAX_BLOCKS];
+ int used_blocks;
+ int max_pool_size;
+ int max_wl_pool_size;
+};
+
+/**
+ * struct ubi_fm_pool - in-memory fastmap pool
+ * @pebs: PEBs in this pool
+ * @used: number of used PEBs
+ * @size: total number of PEBs in this pool
+ * @max_size: maximal size of the pool
+ *
+ * A pool gets filled with up to max_size.
+ * If all PEBs within the pool are used a new fastmap will be written
+ * to the flash and the pool gets refilled with empty PEBs.
+ *
+ */
+struct ubi_fm_pool {
+ int pebs[UBI_FM_MAX_POOL_SIZE];
+ int used;
+ int size;
+ int max_size;
+};
+
+#endif
diff --git a/drivers/mtd/ubispl/ubispl.c b/drivers/mtd/ubispl/ubispl.c
new file mode 100644
index 0000000..9b11bd4
--- /dev/null
+++ b/drivers/mtd/ubispl/ubispl.c
@@ -0,0 +1,921 @@
+/*
+ * Copyright (c) Thomas Gleixner <tglx(a)linutronix.de>
+ *
+ * The parts taken from the kernel implementation are:
+ *
+ * Copyright (c) International Business Machines Corp., 2006
+
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <ubispl.h>
+
+#include <linux/crc32.h>
+
+#include "ubispl.h"
+
+/**
+ * ubi_calc_fm_size - calculates the fastmap size in bytes for an UBI device.
+ * @ubi: UBI device description object
+ */
+static size_t ubi_calc_fm_size(struct ubi_scan_info *ubi)
+{
+ size_t size;
+
+ size = sizeof(struct ubi_fm_sb) +
+ sizeof(struct ubi_fm_hdr) +
+ sizeof(struct ubi_fm_scan_pool) +
+ sizeof(struct ubi_fm_scan_pool) +
+ (ubi->peb_count * sizeof(struct ubi_fm_ec)) +
+ (sizeof(struct ubi_fm_eba) +
+ (ubi->peb_count * sizeof(__be32))) +
+ sizeof(struct ubi_fm_volhdr) * UBI_MAX_VOLUMES;
+ return roundup(size, ubi->leb_size);
+}
+
+static int ubi_io_read(struct ubi_scan_info *ubi, void *buf, int pnum,
+ unsigned long from, unsigned long len)
+{
+ return ubi->read(pnum + ubi->peb_offset, from, len, buf);
+}
+
+static int ubi_io_is_bad(struct ubi_scan_info *ubi, int peb)
+{
+ return peb >= ubi->peb_count || peb < 0;
+}
+
+static int ubi_io_read_vid_hdr(struct ubi_scan_info *ubi, int pnum,
+ struct ubi_vid_hdr *vh, int unused)
+{
+ u32 magic;
+ int res;
+
+ /* No point in rescanning a corrupt block */
+ if (test_bit(pnum, ubi->corrupt))
+ return -1;
+ /*
+ * If the block has been scanned already, no need to rescan
+ */
+ if (test_and_set_bit(pnum, ubi->scanned))
+ return 0;
+
+ res = ubi_io_read(ubi, vh, pnum, ubi->vid_offset, sizeof(*vh));
+
+ /*
+ * Bad block, unrecoverable ECC error, skip the block
+ */
+ if (res) {
+ ubi_dbg("Skipping bad or unreadable block %d", pnum);
+ vh->magic = 0;
+ generic_set_bit(pnum, ubi->corrupt);
+ return res;
+ }
+
+ /* Magic number available ? */
+ magic = be32_to_cpu(vh->magic);
+ if ((magic != UBI_VID_HDR_MAGIC)) {
+ generic_set_bit(pnum, ubi->corrupt);
+ if (magic == 0xffffffff)
+ return UBI_IO_FF;
+ ubi_msg("Bad magic in block 0%d %08x", pnum, magic);
+ return UBI_IO_BAD_HDR;
+ }
+
+ /* Header CRC correct ? */
+ if (crc32(UBI_CRC32_INIT, vh, UBI_VID_HDR_SIZE_CRC) !=
+ be32_to_cpu(vh->hdr_crc)) {
+ ubi_msg("Bad CRC in block 0%d", pnum);
+ generic_set_bit(pnum, ubi->corrupt);
+ return UBI_IO_BAD_HDR;
+ }
+
+ ubi_dbg("RV: pnum: %i sqnum %llu", pnum, be64_to_cpu(vh->sqnum));
+
+ return 0;
+}
+
+static int ubi_rescan_fm_vid_hdr(struct ubi_scan_info *ubi,
+ struct ubi_vid_hdr *vh,
+ u32 fm_pnum, u32 fm_vol_id, u32 fm_lnum)
+{
+ int res;
+
+ if (ubi_io_is_bad(ubi, fm_pnum))
+ return -1;
+
+ res = ubi_io_read_vid_hdr(ubi, fm_pnum, vh, 0);
+ if (!res) {
+ /* Check volume id, volume type and lnum */
+ if (be32_to_cpu(vh->vol_id) == fm_vol_id &&
+ vh->vol_type == UBI_VID_STATIC &&
+ be32_to_cpu(vh->lnum) == fm_lnum)
+ return 0;
+ ubi_dbg("RS: PEB %u vol: %u : %u typ %u lnum %u %u",
+ fm_pnum, fm_vol_id, vh->vol_type,
+ be32_to_cpu(vh->vol_id),
+ fm_lnum, be32_to_cpu(vh->lnum));
+ }
+ return -1;
+}
+
+/* Insert the logic block into the volume info */
+static int ubi_add_peb_to_vol(struct ubi_scan_info *ubi,
+ struct ubi_vid_hdr *vh, u32 vol_id,
+ u32 vol_type, u32 pnum, u32 lnum)
+{
+ struct ubi_vol_info *vi = ubi->volinfo + vol_id;
+ u32 *ltp;
+
+ /*
+ * We only care about static volumes with an id <
+ * UBI_SPL_VOL_IDS.
+ */
+ if (vol_id >= UBI_SPL_VOL_IDS || vol_type != UBI_VID_STATIC)
+ return 0;
+
+ /*
+ * If the volume is larger than expected, yell and give up :(
+ */
+ if (lnum >= UBI_MAX_VOL_LEBS) {
+ ubi_warn("Vol: %u LEB %d > %d", vol_id, lnum, UBI_MAX_VOL_LEBS);
+ return -1;
+ }
+
+ ubi_dbg("SC: Add PEB %u to Vol %u as LEB %u fnd %d sc %d",
+ pnum, vol_id, lnum, !!test_bit(lnum, vi->found),
+ !!test_bit(pnum, ubi->scanned));
+
+ /* Points to the translation entry */
+ ltp = vi->lebs_to_pebs + lnum;
+
+ /* If the block is already assigned, check sqnum */
+ if (__test_and_set_bit(lnum, vi->found)) {
+ u32 cur_pnum = *ltp;
+ struct ubi_vid_hdr *cur = ubi->blockinfo + cur_pnum;
+
+ /*
+ * If the current block hase not yet been scanned, we
+ * need to do that. The other block might be stale or
+ * the current block corrupted and the FM not yet
+ * updated.
+ */
+ if (!test_bit(cur_pnum, ubi->scanned)) {
+ /*
+ * If the scan fails, we use the valid block
+ */
+ if (ubi_rescan_fm_vid_hdr(ubi, cur, cur_pnum, vol_id,
+ lnum)) {
+ *ltp = pnum;
+ return 0;
+ }
+ }
+
+ /*
+ * Should not happen ....
+ */
+ if (test_bit(cur_pnum, ubi->corrupt)) {
+ *ltp = pnum;
+ return 0;
+ }
+
+ ubi_dbg("Vol %u LEB %u PEB %u->sqnum %llu NPEB %u->sqnum %llu",
+ vol_id, lnum, cur_pnum, be64_to_cpu(cur->sqnum), pnum,
+ be64_to_cpu(vh->sqnum));
+
+ /*
+ * Compare sqnum and take the newer one
+ */
+ if (be64_to_cpu(cur->sqnum) < be64_to_cpu(vh->sqnum))
+ *ltp = pnum;
+ } else {
+ *ltp = pnum;
+ if (lnum > vi->last_block)
+ vi->last_block = lnum;
+ }
+
+ return 0;
+}
+
+static int ubi_scan_vid_hdr(struct ubi_scan_info *ubi, struct ubi_vid_hdr *vh,
+ u32 pnum)
+{
+ u32 vol_id, lnum;
+ int res;
+
+ if (ubi_io_is_bad(ubi, pnum))
+ return -1;
+
+ res = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
+ if (res)
+ return res;
+
+ /* Get volume id */
+ vol_id = be32_to_cpu(vh->vol_id);
+
+ /* If this is the fastmap anchor, return right away */
+ if (vol_id == UBI_FM_SB_VOLUME_ID)
+ return ubi->fm_enabled ? UBI_FASTMAP_ANCHOR : 0;
+
+ /* We are only interested in the volumes to load */
+ if (!test_bit(vol_id, ubi->toload))
+ return 0;
+
+ lnum = be32_to_cpu(vh->lnum);
+
+ return ubi_add_peb_to_vol(ubi, vh, vol_id, vh->vol_type, pnum, lnum);
+}
+
+static int assign_aeb_to_av(struct ubi_scan_info *ubi, u32 pnum, u32 lnum,
+ u32 vol_id, u32 vol_type, u32 used)
+{
+ struct ubi_vid_hdr *vh;
+
+ if (ubi_io_is_bad(ubi, pnum))
+ return -1;
+
+ ubi->fastmap_pebs++;
+
+ if (vol_id >= UBI_SPL_VOL_IDS || vol_type != UBI_STATIC_VOLUME)
+ return 0;
+
+ /* We are only interested in the volumes to load */
+ if (!test_bit(vol_id, ubi->toload))
+ return 0;
+
+ vh = ubi->blockinfo + pnum;
+
+ return ubi_scan_vid_hdr(ubi, vh, pnum);
+}
+
+static int scan_pool(struct ubi_scan_info *ubi, __be32 *pebs, int pool_size)
+{
+ struct ubi_vid_hdr *vh;
+ u32 pnum;
+ int i;
+
+ ubi_dbg("Scanning pool size: %d", pool_size);
+
+ for (i = 0; i < pool_size; i++) {
+ pnum = be32_to_cpu(pebs[i]);
+
+ if (ubi_io_is_bad(ubi, pnum)) {
+ ubi_err("FM: Bad PEB in fastmap pool! %u", pnum);
+ return UBI_BAD_FASTMAP;
+ }
+
+ vh = ubi->blockinfo + pnum;
+ /*
+ * We allow the scan to fail here. The loader will notice
+ * and look for a replacement.
+ */
+ ubi_scan_vid_hdr(ubi, vh, pnum);
+ }
+ return 0;
+}
+
+static int ubi_attach_fastmap(struct ubi_scan_info *ubi,
+ struct ubi_attach_info *ai,
+ struct ubi_fastmap_layout *fm)
+{
+ struct ubi_fm_hdr *fmhdr;
+ struct ubi_fm_scan_pool *fmpl1, *fmpl2;
+ struct ubi_fm_ec *fmec;
+ struct ubi_fm_volhdr *fmvhdr;
+ struct ubi_fm_eba *fm_eba;
+ int ret, i, j, pool_size, wl_pool_size;
+ size_t fm_pos = 0, fm_size = ubi->fm_size;
+ void *fm_raw = ubi->fm_buf;
+
+ memset(ubi->fm_used, 0, sizeof(ubi->fm_used));
+
+ fm_pos += sizeof(struct ubi_fm_sb);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+
+ fmhdr = (struct ubi_fm_hdr *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmhdr);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+
+ if (be32_to_cpu(fmhdr->magic) != UBI_FM_HDR_MAGIC) {
+ ubi_err("bad fastmap header magic: 0x%x, expected: 0x%x",
+ be32_to_cpu(fmhdr->magic), UBI_FM_HDR_MAGIC);
+ goto fail_bad;
+ }
+
+ fmpl1 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmpl1);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+ if (be32_to_cpu(fmpl1->magic) != UBI_FM_POOL_MAGIC) {
+ ubi_err("bad fastmap pool magic: 0x%x, expected: 0x%x",
+ be32_to_cpu(fmpl1->magic), UBI_FM_POOL_MAGIC);
+ goto fail_bad;
+ }
+
+ fmpl2 = (struct ubi_fm_scan_pool *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmpl2);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+ if (be32_to_cpu(fmpl2->magic) != UBI_FM_POOL_MAGIC) {
+ ubi_err("bad fastmap pool magic: 0x%x, expected: 0x%x",
+ be32_to_cpu(fmpl2->magic), UBI_FM_POOL_MAGIC);
+ goto fail_bad;
+ }
+
+ pool_size = be16_to_cpu(fmpl1->size);
+ wl_pool_size = be16_to_cpu(fmpl2->size);
+ fm->max_pool_size = be16_to_cpu(fmpl1->max_size);
+ fm->max_wl_pool_size = be16_to_cpu(fmpl2->max_size);
+
+ if (pool_size > UBI_FM_MAX_POOL_SIZE || pool_size < 0) {
+ ubi_err("bad pool size: %i", pool_size);
+ goto fail_bad;
+ }
+
+ if (wl_pool_size > UBI_FM_MAX_POOL_SIZE || wl_pool_size < 0) {
+ ubi_err("bad WL pool size: %i", wl_pool_size);
+ goto fail_bad;
+ }
+
+ if (fm->max_pool_size > UBI_FM_MAX_POOL_SIZE ||
+ fm->max_pool_size < 0) {
+ ubi_err("bad maximal pool size: %i", fm->max_pool_size);
+ goto fail_bad;
+ }
+
+ if (fm->max_wl_pool_size > UBI_FM_MAX_POOL_SIZE ||
+ fm->max_wl_pool_size < 0) {
+ ubi_err("bad maximal WL pool size: %i", fm->max_wl_pool_size);
+ goto fail_bad;
+ }
+
+ /* read EC values from free list */
+ for (i = 0; i < be32_to_cpu(fmhdr->free_peb_count); i++) {
+ fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmec);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+ }
+
+ /* read EC values from used list */
+ for (i = 0; i < be32_to_cpu(fmhdr->used_peb_count); i++) {
+ fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmec);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+
+ generic_set_bit(be32_to_cpu(fmec->pnum), ubi->fm_used);
+ }
+
+ /* read EC values from scrub list */
+ for (i = 0; i < be32_to_cpu(fmhdr->scrub_peb_count); i++) {
+ fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmec);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+ }
+
+ /* read EC values from erase list */
+ for (i = 0; i < be32_to_cpu(fmhdr->erase_peb_count); i++) {
+ fmec = (struct ubi_fm_ec *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmec);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+ }
+
+ /* Iterate over all volumes and read their EBA table */
+ for (i = 0; i < be32_to_cpu(fmhdr->vol_count); i++) {
+ u32 vol_id, vol_type, used, reserved;
+
+ fmvhdr = (struct ubi_fm_volhdr *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fmvhdr);
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+
+ if (be32_to_cpu(fmvhdr->magic) != UBI_FM_VHDR_MAGIC) {
+ ubi_err("bad fastmap vol header magic: 0x%x, " \
+ "expected: 0x%x",
+ be32_to_cpu(fmvhdr->magic), UBI_FM_VHDR_MAGIC);
+ goto fail_bad;
+ }
+
+ vol_id = be32_to_cpu(fmvhdr->vol_id);
+ vol_type = fmvhdr->vol_type;
+ used = be32_to_cpu(fmvhdr->used_ebs);
+
+ fm_eba = (struct ubi_fm_eba *)(fm_raw + fm_pos);
+ fm_pos += sizeof(*fm_eba);
+ fm_pos += (sizeof(__be32) * be32_to_cpu(fm_eba->reserved_pebs));
+ if (fm_pos >= fm_size)
+ goto fail_bad;
+
+ if (be32_to_cpu(fm_eba->magic) != UBI_FM_EBA_MAGIC) {
+ ubi_err("bad fastmap EBA header magic: 0x%x, " \
+ "expected: 0x%x",
+ be32_to_cpu(fm_eba->magic), UBI_FM_EBA_MAGIC);
+ goto fail_bad;
+ }
+
+ reserved = be32_to_cpu(fm_eba->reserved_pebs);
+ ubi_dbg("FA: vol %u used %u res: %u", vol_id, used, reserved);
+ for (j = 0; j < reserved; j++) {
+ int pnum = be32_to_cpu(fm_eba->pnum[j]);
+
+ if ((int)be32_to_cpu(fm_eba->pnum[j]) < 0)
+ continue;
+
+ if (!__test_and_clear_bit(pnum, ubi->fm_used))
+ continue;
+
+ /*
+ * We only handle static volumes so used_ebs
+ * needs to be handed in. And we do not assign
+ * the reserved blocks
+ */
+ if (j >= used)
+ continue;
+
+ ret = assign_aeb_to_av(ubi, pnum, j, vol_id,
+ vol_type, used);
+ if (!ret)
+ continue;
+
+ /*
+ * Nasty: The fastmap claims that the volume
+ * has one block more than it, but that block
+ * is always empty and the other blocks have
+ * the correct number of total LEBs in the
+ * headers. Deal with it.
+ */
+ if (ret != UBI_IO_FF && j != used - 1)
+ goto fail_bad;
+ ubi_dbg("FA: Vol: %u Ignoring empty LEB %d of %d",
+ vol_id, j, used);
+ }
+ }
+
+ ret = scan_pool(ubi, fmpl1->pebs, pool_size);
+ if (ret)
+ goto fail;
+
+ ret = scan_pool(ubi, fmpl2->pebs, wl_pool_size);
+ if (ret)
+ goto fail;
+
+#ifdef CHECKME
+ /*
+ * If fastmap is leaking PEBs (must not happen), raise a
+ * fat warning and fall back to scanning mode.
+ * We do this here because in ubi_wl_init() it's too late
+ * and we cannot fall back to scanning.
+ */
+ if (WARN_ON(count_fastmap_pebs(ai) != ubi->peb_count -
+ ai->bad_peb_count - fm->used_blocks))
+ goto fail_bad;
+#endif
+
+ return 0;
+
+fail_bad:
+ ret = UBI_BAD_FASTMAP;
+fail:
+ return ret;
+}
+
+static int ubi_scan_fastmap(struct ubi_scan_info *ubi, struct ubi_attach_info *ai,
+ int fm_anchor)
+{
+ struct ubi_fm_sb *fmsb, *fmsb2;
+ struct ubi_vid_hdr *vh;
+ struct ubi_fastmap_layout *fm;
+ int i, used_blocks, pnum, ret = 0;
+ unsigned int fsize, nblocks;
+ size_t fm_size;
+ __be32 crc, tmp_crc;
+ unsigned long long sqnum = 0;
+
+ fmsb = &ubi->fm_sb;
+ fm = &ubi->fm_layout;
+
+ ret = ubi_io_read(ubi, fmsb, fm_anchor, ubi->leb_start, sizeof(*fmsb));
+ if (ret && ret != UBI_IO_BITFLIPS)
+ goto free_fm_sb;
+ else if (ret == UBI_IO_BITFLIPS)
+ fm->to_be_tortured[0] = 1;
+
+ if (be32_to_cpu(fmsb->magic) != UBI_FM_SB_MAGIC) {
+ ubi_err("bad super block magic: 0x%x, expected: 0x%x",
+ be32_to_cpu(fmsb->magic), UBI_FM_SB_MAGIC);
+ ret = UBI_BAD_FASTMAP;
+ goto free_fm_sb;
+ }
+
+ if (fmsb->version != UBI_FM_FMT_VERSION) {
+ ubi_err("bad fastmap version: %i, expected: %i",
+ fmsb->version, UBI_FM_FMT_VERSION);
+ ret = UBI_BAD_FASTMAP;
+ goto free_fm_sb;
+ }
+
+ used_blocks = be32_to_cpu(fmsb->used_blocks);
+ if (used_blocks > UBI_FM_MAX_BLOCKS || used_blocks < 1) {
+ ubi_err("number of fastmap blocks is invalid: %i", used_blocks);
+ ret = UBI_BAD_FASTMAP;
+ goto free_fm_sb;
+ }
+
+ fm_size = ubi->leb_size * used_blocks;
+ if (fm_size != ubi->fm_size) {
+ ubi_err("bad fastmap size: %zi, expected: %zi", fm_size,
+ ubi->fm_size);
+ ret = UBI_BAD_FASTMAP;
+ goto free_fm_sb;
+ }
+
+ vh = &ubi->fm_vh;
+
+ for (i = 0; i < used_blocks; i++) {
+
+ pnum = be32_to_cpu(fmsb->block_loc[i]);
+
+ if (ubi_io_is_bad(ubi, pnum)) {
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ }
+
+#ifdef LATER
+ int image_seq;
+ ret = ubi_io_read_ec_hdr(ubi, pnum, ech, 0);
+ if (ret && ret != UBI_IO_BITFLIPS) {
+ ubi_err("unable to read fastmap block# %i EC (PEB: %i)",
+ i, pnum);
+ if (ret > 0)
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ } else if (ret == UBI_IO_BITFLIPS)
+ fm->to_be_tortured[i] = 1;
+
+ image_seq = be32_to_cpu(ech->image_seq);
+ if (!ubi->image_seq)
+ ubi->image_seq = image_seq;
+ /*
+ * Older UBI implementations have image_seq set to zero, so
+ * we shouldn't fail if image_seq == 0.
+ */
+ if (image_seq && (image_seq != ubi->image_seq)) {
+ ubi_err("wrong image seq:%d instead of %d",
+ be32_to_cpu(ech->image_seq), ubi->image_seq);
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ }
+#endif
+ ret = ubi_io_read_vid_hdr(ubi, pnum, vh, 0);
+ if (ret && ret != UBI_IO_BITFLIPS) {
+ ubi_err("unable to read fastmap block# %i (PEB: %i)",
+ i, pnum);
+ goto free_hdr;
+ }
+
+ /*
+ * Mainline code rescans the anchor header. We've done
+ * that already so we merily copy it over.
+ */
+ if (pnum == fm_anchor)
+ memcpy(vh, ubi->blockinfo + pnum, sizeof(*fm));
+
+ if (i == 0) {
+ if (be32_to_cpu(vh->vol_id) != UBI_FM_SB_VOLUME_ID) {
+ ubi_err("bad fastmap anchor vol_id: 0x%x," \
+ " expected: 0x%x",
+ be32_to_cpu(vh->vol_id),
+ UBI_FM_SB_VOLUME_ID);
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ }
+ } else {
+ if (be32_to_cpu(vh->vol_id) != UBI_FM_DATA_VOLUME_ID) {
+ ubi_err("bad fastmap data vol_id: 0x%x," \
+ " expected: 0x%x",
+ be32_to_cpu(vh->vol_id),
+ UBI_FM_DATA_VOLUME_ID);
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ }
+ }
+
+ if (sqnum < be64_to_cpu(vh->sqnum))
+ sqnum = be64_to_cpu(vh->sqnum);
+
+ ret = ubi_io_read(ubi, ubi->fm_buf + (ubi->leb_size * i), pnum,
+ ubi->leb_start, ubi->leb_size);
+ if (ret && ret != UBI_IO_BITFLIPS) {
+ ubi_err("unable to read fastmap block# %i (PEB: %i, " \
+ "err: %i)", i, pnum, ret);
+ goto free_hdr;
+ }
+ }
+
+ fmsb2 = (struct ubi_fm_sb *)(ubi->fm_buf);
+ tmp_crc = be32_to_cpu(fmsb2->data_crc);
+ fmsb2->data_crc = 0;
+ crc = crc32(UBI_CRC32_INIT, ubi->fm_buf, fm_size);
+ if (crc != tmp_crc) {
+ ubi_err("fastmap data CRC is invalid");
+ ubi_err("CRC should be: 0x%x, calc: 0x%x", tmp_crc, crc);
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ }
+
+ fmsb2->sqnum = sqnum;
+
+ fm->used_blocks = used_blocks;
+
+ ret = ubi_attach_fastmap(ubi, ai, fm);
+ if (ret) {
+ if (ret > 0)
+ ret = UBI_BAD_FASTMAP;
+ goto free_hdr;
+ }
+
+ ubi->fm = fm;
+ ubi->fm_pool.max_size = ubi->fm->max_pool_size;
+ ubi->fm_wl_pool.max_size = ubi->fm->max_wl_pool_size;
+ nblocks = ubi->peb_count;
+ fsize = ubi->fsize_mb;
+ ubi_msg("attached by fastmap %uMB %u blocks", fsize, nblocks);
+ ubi_dbg("fastmap pool size: %d", ubi->fm_pool.max_size);
+ ubi_dbg("fastmap WL pool size: %d", ubi->fm_wl_pool.max_size);
+
+out:
+ if (ret)
+ ubi_err("Attach by fastmap failed, doing a full scan!");
+ return ret;
+
+free_hdr:
+free_fm_sb:
+ goto out;
+}
+
+/*
+ * Scan the flash and attempt to attach via fastmap
+ */
+static void ipl_scan(struct ubi_scan_info *ubi)
+{
+ unsigned int pnum;
+ int res;
+
+ /*
+ * Scan first for the fastmap super block
+ */
+ for (pnum = 0; pnum < UBI_FM_MAX_START; pnum++) {
+ res = ubi_scan_vid_hdr(ubi, ubi->blockinfo + pnum, pnum);
+ /*
+ * We ignore errors here as we are meriliy scanning
+ * the headers.
+ */
+ if (res != UBI_FASTMAP_ANCHOR)
+ continue;
+
+ /*
+ * If fastmap is disabled, continue scanning. This
+ * might happen because the previous attempt failed or
+ * the caller disabled it right away.
+ */
+ if (!ubi->fm_enabled)
+ continue;
+
+ /*
+ * Try to attach the fastmap, if that fails continue
+ * scanning.
+ */
+ if (!ubi_scan_fastmap(ubi, NULL, pnum))
+ return;
+ /*
+ * Fastmap failed. Clear everything we have and start
+ * over. We are paranoid and do not trust anything.
+ */
+ memset(ubi->volinfo, 0, sizeof(ubi->volinfo));
+ pnum = 0;
+ break;
+ }
+
+ /*
+ * Continue scanning, ignore errors, we might find what we are
+ * looking for,
+ */
+ for (; pnum < ubi->peb_count; pnum++)
+ ubi_scan_vid_hdr(ubi, ubi->blockinfo + pnum, pnum);
+}
+
+/*
+ * Load a logical block of a volume into memory
+ */
+static int ubi_load_block(struct ubi_scan_info *ubi, uint8_t *laddr,
+ struct ubi_vol_info *vi, u32 vol_id, u32 lnum,
+ u32 last)
+{
+ struct ubi_vid_hdr *vh, *vrepl;
+ u32 pnum, crc, dlen;
+
+retry:
+ /*
+ * If this is a fastmap run, we try to rescan full, otherwise
+ * we simply give up.
+ */
+ if (!test_bit(lnum, vi->found)) {
+ ubi_warn("LEB %d of %d is missing", lnum, last);
+ return -1;
+ }
+
+ pnum = vi->lebs_to_pebs[lnum];
+
+ ubi_dbg("Load vol %u LEB %u PEB %u", vol_id, lnum, pnum);
+
+ if (ubi_io_is_bad(ubi, pnum)) {
+ ubi_warn("Corrupted mapping block %d PB %d\n", lnum, pnum);
+ return -1;
+ }
+
+ if (test_bit(pnum, ubi->corrupt))
+ goto find_other;
+
+ /*
+ * Lets try to read that block
+ */
+ vh = ubi->blockinfo + pnum;
+
+ if (!test_bit(pnum, ubi->scanned)) {
+ ubi_warn("Vol: %u LEB %u PEB %u not yet scanned", vol_id,
+ lnum, pnum);
+ if (ubi_rescan_fm_vid_hdr(ubi, vh, pnum, vol_id, lnum))
+ goto find_other;
+ }
+
+ /*
+ * Check, if the total number of blocks is correct
+ */
+ if (be32_to_cpu(vh->used_ebs) != last) {
+ ubi_dbg("Block count missmatch.");
+ ubi_dbg("vh->used_ebs: %d nrblocks: %d",
+ be32_to_cpu(vh->used_ebs), last);
+ generic_set_bit(pnum, ubi->corrupt);
+ goto find_other;
+ }
+
+ /*
+ * Get the data length of this block.
+ */
+ dlen = be32_to_cpu(vh->data_size);
+
+ /*
+ * Read the data into RAM. We ignore the return value
+ * here as the only thing which might go wrong are
+ * bitflips. Try nevertheless.
+ */
+ ubi_io_read(ubi, laddr, pnum, ubi->leb_start, dlen);
+
+ /* Calculate CRC over the data */
+ crc = crc32(UBI_CRC32_INIT, laddr, dlen);
+
+ if (crc != be32_to_cpu(vh->data_crc)) {
+ ubi_warn("Vol: %u LEB %u PEB %u data CRC failure", vol_id,
+ lnum, pnum);
+ generic_set_bit(pnum, ubi->corrupt);
+ goto find_other;
+ }
+
+ /* We are good. Return the data length we read */
+ return dlen;
+
+find_other:
+ ubi_dbg("Find replacement for LEB %u PEB %u", lnum, pnum);
+ generic_clear_bit(lnum, vi->found);
+ vrepl = NULL;
+
+ for (pnum = 0; pnum < ubi->peb_count; pnum++) {
+ struct ubi_vid_hdr *tmp = ubi->blockinfo + pnum;
+ u32 t_vol_id = be32_to_cpu(tmp->vol_id);
+ u32 t_lnum = be32_to_cpu(tmp->lnum);
+
+ if (test_bit(pnum, ubi->corrupt))
+ continue;
+
+ if (t_vol_id != vol_id || t_lnum != lnum)
+ continue;
+
+ if (!test_bit(pnum, ubi->scanned)) {
+ ubi_warn("Vol: %u LEB %u PEB %u not yet scanned", vol_id,
+ lnum, pnum);
+ if (ubi_rescan_fm_vid_hdr(ubi, tmp, pnum, vol_id, lnum))
+ continue;
+ }
+
+ /*
+ * We found one. If its the first, assign it otherwise
+ * compare the sqnum
+ */
+ generic_set_bit(lnum, vi->found);
+
+ if (!vrepl) {
+ vrepl = tmp;
+ continue;
+ }
+
+ if (be64_to_cpu(vrepl->sqnum) < be64_to_cpu(tmp->sqnum))
+ vrepl = tmp;
+ }
+
+ if (vrepl) {
+ /* Update the vi table */
+ pnum = vrepl - ubi->blockinfo;
+ vi->lebs_to_pebs[lnum] = pnum;
+ ubi_dbg("Trying PEB %u for LEB %u", pnum, lnum);
+ vh = vrepl;
+ }
+ goto retry;
+}
+
+/*
+ * Load a volume into RAM
+ */
+static int ipl_load(struct ubi_scan_info *ubi, const u32 vol_id, uint8_t *laddr)
+{
+ struct ubi_vol_info *vi;
+ u32 lnum, last;
+
+ if (vol_id >= UBI_SPL_VOL_IDS)
+ return -1;
+
+ vi = ubi->volinfo + vol_id;
+ last = vi->last_block + 1;
+
+ /* Read the blocks to RAM, check CRC */
+ for (lnum = 0 ; lnum < last; lnum++) {
+ int res = ubi_load_block(ubi, laddr, vi, vol_id, lnum, last);
+
+ if (res < 0) {
+ ubi_warn("Failed to load volume %u", vol_id);
+ return res;
+ }
+ /* res is the data length of the read block */
+ laddr += res;
+ }
+ return 0;
+}
+
+int ubispl_load_volumes(struct ubispl_info *info, struct ubispl_load *lvols,
+ int nrvols)
+{
+ struct ubi_scan_info *ubi = info->ubi;
+ int res, i, fastmap = info->fastmap;
+ u32 fsize;
+
+retry:
+ /*
+ * We do a partial initializiation of @ubi. Cleaning fm_buf is
+ * not necessary.
+ */
+ memset(ubi, 0, offsetof(struct ubi_scan_info, fm_buf));
+
+ ubi->read = info->read;
+
+ /* Precalculate the offsets */
+ ubi->vid_offset = info->vid_offset;
+ ubi->leb_start = info->leb_start;
+ ubi->leb_size = info->peb_size - ubi->leb_start;
+ ubi->peb_count = info->peb_count;
+ ubi->peb_offset = info->peb_offset;
+
+ fsize = info->peb_size * info->peb_count;
+ ubi->fsize_mb = fsize >> 20;
+
+ /* Fastmap init */
+ ubi->fm_size = ubi_calc_fm_size(ubi);
+ ubi->fm_enabled = fastmap;
+
+ for (i = 0; i < nrvols; i++) {
+ struct ubispl_load *lv = lvols + i;
+
+ generic_set_bit(lv->vol_id, ubi->toload);
+ }
+
+ ipl_scan(ubi);
+
+ for (i = 0; i < nrvols; i++) {
+ struct ubispl_load *lv = lvols + i;
+
+ ubi_msg("Load %s (#%d)", lv->name, lv->vol_id);
+ res = ipl_load(ubi, lv->vol_id, lv->load_addr);
+ if (res) {
+ if (fastmap) {
+ fastmap = 0;
+ goto retry;
+ }
+ ubi_warn("Failed \n");
+ return res;
+ }
+ }
+ return 0;
+}
diff --git a/drivers/mtd/ubispl/ubispl.h b/drivers/mtd/ubispl/ubispl.h
new file mode 100644
index 0000000..a64a394
--- /dev/null
+++ b/drivers/mtd/ubispl/ubispl.h
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) Thomas Gleixner <tglx(a)linutronix.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#ifndef _UBOOT_MTD_UBISPL_H
+#define _UBOOT_MTD_UBISPL_H
+
+#include "../ubi/ubi-media.h"
+#include "ubi-wrapper.h"
+
+/*
+ * The maximum number of volume ids we scan. So you can load volume id
+ * 0 to (CONFIG_SPL_UBI_VOL_ID_MAX - 1)
+ */
+#define UBI_SPL_VOL_IDS CONFIG_SPL_UBI_VOL_IDS
+/*
+ * The size of the read buffer for the fastmap blocks. In theory up to
+ * UBI_FM_MAX_BLOCKS * CONFIG_SPL_MAX_PEB_SIZE. In practice today
+ * one or two blocks.
+ */
+#define UBI_FM_BUF_SIZE (UBI_FM_MAX_BLOCKS * CONFIG_SPL_UBI_MAX_PEB_SIZE)
+/*
+ * The size of the bitmaps for the attach/ scan
+ */
+#define UBI_FM_BM_SIZE ((CONFIG_SPL_UBI_MAX_PEBS / BITS_PER_LONG) + 1)
+/*
+ * The maximum number of logical erase blocks per loadable volume
+ */
+#define UBI_MAX_VOL_LEBS CONFIG_SPL_UBI_MAX_VOL_LEBS
+/*
+ * The bitmap size for the above to denote the found blocks inside the volume
+ */
+#define UBI_VOL_BM_SIZE ((UBI_MAX_VOL_LEBS / BITS_PER_LONG) + 1)
+
+/**
+ * struct ubi_vol_info - UBISPL internal volume represenation
+ * @last_block: The last block (highest LEB) found for this volume
+ * @found: Bitmap to mark found LEBS
+ * @lebs_to_pebs: LEB to PEB translation table
+ */
+struct ubi_vol_info {
+ u32 last_block;
+ unsigned long found[UBI_VOL_BM_SIZE];
+ u32 lebs_to_pebs[UBI_MAX_VOL_LEBS];
+};
+
+/**
+ * struct ubi_scan_info - UBISPL internal data for FM attach and full scan
+ *
+ * @read: Read function to access the flash provided by the caller
+ * @peb_count: Number of physical erase blocks in the UBI FLASH area
+ * aka MTD partition.
+ * @peb_offset: Offset of PEB0 in the UBI FLASH area (aka MTD partition)
+ * to the real start of the FLASH in erase blocks.
+ * @fsize_mb: Size of the scanned FLASH area in MB (stats only)
+ * @vid_offset: Offset from the start of a PEB to the VID header
+ * @leb_start: Offset from the start of a PEB to the data area
+ * @leb_size: Size of the data area
+ *
+ * @fastmap_pebs: Counter of PEBs "attached" by fastmap
+ * @fastmap_anchor: The anchor PEB of the fastmap
+ * @fm_sb: The fastmap super block data
+ * @fm_vh: The fastmap VID header
+ * @fm: Pointer to the fastmap layout
+ * @fm_layout: The fastmap layout itself
+ * @fm_pool: The pool of PEBs to scan at fastmap attach time
+ * @fm_wl_pool: The pool of PEBs scheduled for wearleveling
+ *
+ * @fm_enabled: Indicator whether fastmap attachment is enabled.
+ * @fm_used: Bitmap to indicate the PEBS covered by fastmap
+ * @scanned: Bitmap to indicate the PEBS of which the VID header
+ * hase been physically scanned.
+ * @corrupt: Bitmap to indicate corrupt blocks
+ * @toload: Bitmap to indicate the volumes which should be loaded
+ *
+ * @blockinfo: The vid headers of the scanned blocks
+ * @volinfo: The volume information of the interesting (toload)
+ * volumes
+ *
+ * @fm_buf: The large fastmap attach buffer
+ */
+struct ubi_scan_info {
+ int (*read)(u32 pnum, u32 offset, u32 len, void *dest);
+ unsigned int fsize_mb;
+ unsigned int peb_count;
+ unsigned int peb_offset;
+
+ unsigned long vid_offset;
+ unsigned long leb_start;
+ unsigned long leb_size;
+
+ /* Fastmap: The upstream required fields */
+ int fastmap_pebs;
+ int fastmap_anchor;
+ size_t fm_size;
+ struct ubi_fm_sb fm_sb;
+ struct ubi_vid_hdr fm_vh;
+ struct ubi_fastmap_layout *fm;
+ struct ubi_fastmap_layout fm_layout;
+ struct ubi_fm_pool fm_pool;
+ struct ubi_fm_pool fm_wl_pool;
+
+ /* Fastmap: UBISPL specific data */
+ int fm_enabled;
+ unsigned long fm_used[UBI_FM_BM_SIZE];
+ unsigned long scanned[UBI_FM_BM_SIZE];
+ unsigned long corrupt[UBI_FM_BM_SIZE];
+ unsigned long toload[UBI_FM_BM_SIZE];
+
+ /* Data for storing the VID and volume information */
+ struct ubi_vol_info volinfo[UBI_SPL_VOL_IDS];
+ struct ubi_vid_hdr blockinfo[CONFIG_SPL_UBI_MAX_PEBS];
+
+ /* The large buffer for the fastmap */
+ uint8_t fm_buf[UBI_FM_BUF_SIZE];
+};
+
+#ifdef CFG_DEBUG
+#define ubi_dbg(fmt, ...) printf("UBI: debug:" fmt "\n", ##__VA_ARGS__)
+#else
+#define ubi_dbg(fmt, ...)
+#endif
+
+#ifdef CONFIG_UBI_SILENCE_MSG
+#define ubi_msg(fmt, ...)
+#else
+#define ubi_msg(fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__)
+#endif
+/* UBI warning messages */
+#define ubi_warn(fmt, ...) printf("UBI warning: " fmt "\n", ##__VA_ARGS__)
+/* UBI error messages */
+#define ubi_err(fmt, ...) printf("UBI error: " fmt "\n", ##__VA_ARGS__)
+
+#endif
diff --git a/include/ubispl.h b/include/ubispl.h
new file mode 100644
index 0000000..df4b0e1
--- /dev/null
+++ b/include/ubispl.h
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) Thomas Gleixner <tglx(a)linutronix.de>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+#ifndef __UBOOT_UBISPL_H
+#define __UBOOT_UBISPL_H
+
+/*
+ * The following CONFIG options are relevant for UBISPL
+ *
+ * #define CONFIG_SPL_UBI_MAX_VOL_LEBS 256
+ *
+ * Defines the maximum number of logical erase blocks per loadable
+ * (static) volume to size the ubispl internal arrays.
+ *
+ * #define CONFIG_SPL_UBI_MAX_PEB_SIZE (256*1024)
+ *
+ * Defines the maximum physical erase block size to size the fastmap
+ * buffer for ubispl.
+ *
+ * #define CONFIG_SPL_UBI_MAX_PEBS 4096
+ *
+ * Define the maximum number of physical erase blocks to size the
+ * ubispl internal arrays.
+ *
+ * #define CONFIG_SPL_UBI_VOL_IDS 8
+ *
+ * Defines the maximum number of volumes in which UBISPL is
+ * interested. Limits the amount of memory for the scan data and
+ * speeds up the scan process as we simply ignore stuff which we dont
+ * want to load from the SPL anyway. So the volumes which can be
+ * loaded in the above example are ids 0 - 7
+ */
+
+/*
+ * The struct definition is in drivers/mtd/ubispl/ubispl.h. It does
+ * not fit into the BSS due to the large buffer requirement of the
+ * upstream fastmap code. So the caller of ubispl_load_volumes needs
+ * to hand in a pointer to a free memory area where ubispl will place
+ * its data. The area is not required to be initialized.
+ */
+struct ubi_scan_info;
+
+/**
+ * struct ubispl_info - description structure for fast ubi scan
+ * @ubi: Pointer to memory space for ubi scan info structure
+ * @peb_size: Physical erase block size
+ * @vid_offset: Offset of the VID header
+ * @leb_start: Start of the logical erase block, i.e. offset of data
+ * @peb_count: Number of physical erase blocks in the UBI FLASH area
+ * aka MTD partition.
+ * @peb_offset: Offset of PEB0 in the UBI FLASH area (aka MTD partition)
+ * to the real start of the FLASH in erase blocks.
+ * @fastmap: Enable fastmap attachment
+ * @read: Read function to access the flash
+ */
+struct ubispl_info {
+ struct ubi_scan_info *ubi;
+ u32 peb_size;
+ u32 vid_offset;
+ u32 leb_start;
+ u32 peb_count;
+ u32 peb_offset;
+ int fastmap;
+ int (*read)(u32 pnum, u32 offset, u32 len, void *dest);
+};
+
+/**
+ * struct ubispl_load - structure to describe a volume to load
+ * @name: Name of the volume
+ * @vol_id: Volume id
+ * @load_addr: Load address of the volume
+ */
+struct ubispl_load {
+ char *name;
+ int vol_id;
+ void *load_addr;
+};
+
+/**
+ * ubispl_load_volumes - Scan flash and load volumes
+ * @info: Pointer to the ubi scan info structure
+ * @lovls: Pointer to array of volumes to load
+ * @nrvols: Array size of @lovls
+ */
+extern int ubispl_load_volumes(struct ubispl_info *info,
+ struct ubispl_load *lvols, int nrvols);
+
+#endif
--
2.1.4
2
2

[U-Boot] [PATCH v2 13/13] board: Add gpio and ethernet support to pic32mzdask board.
by Purna Chandra Mandal 04 Jan '16
by Purna Chandra Mandal 04 Jan '16
04 Jan '16
Signed-off-by: Purna Chandra Mandal <purna.mandal(a)microchip.com>
---
Changes in v2:
- replace unbounded loop with wait_for_bit()
- replace register access as readl/writel(base + offset)
- translate (dts provided) physical address to MIPS kseg1 address before use
arch/mips/dts/pic32mzda.dtsi | 93 ++++++++++++++++++++++++++++++++++++++++++
arch/mips/dts/pic32mzda_sk.dts | 5 +++
configs/pic32mzdask_defconfig | 11 ++++-
include/configs/pic32mzdask.h | 30 +++++++++++++-
4 files changed, 136 insertions(+), 3 deletions(-)
diff --git a/arch/mips/dts/pic32mzda.dtsi b/arch/mips/dts/pic32mzda.dtsi
index bdddb93..a354037 100644
--- a/arch/mips/dts/pic32mzda.dtsi
+++ b/arch/mips/dts/pic32mzda.dtsi
@@ -5,6 +5,7 @@
* SPDX-License-Identifier: GPL-2.0+
*/
+#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
#include <dt-bindings/clock/microchip,clock.h>
#include "skeleton.dtsi"
@@ -12,6 +13,19 @@
/ {
compatible = "microchip,pic32mzda", "microchip,pic32mz";
+ aliases {
+ gpio0 = &gpioA;
+ gpio1 = &gpioB;
+ gpio2 = &gpioC;
+ gpio3 = &gpioD;
+ gpio4 = &gpioE;
+ gpio5 = &gpioF;
+ gpio6 = &gpioG;
+ gpio7 = &gpioH;
+ gpio8 = &gpioJ;
+ gpio9 = &gpioK;
+ };
+
cpus {
cpu@0 {
compatible = "mips,mips14kc";
@@ -62,6 +76,76 @@
status = "disabled";
};
+ gpioA: gpio0@1f860000 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860000 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioB: gpio1@1f860100 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860100 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioC: gpio2@1f860200 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860200 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioD: gpio3@1f860300 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860300 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioE: gpio4@1f860400 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860400 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioF: gpio5@1f860500 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860500 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioG: gpio6@1f860600 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860600 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioH: gpio7@1f860700 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860700 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioJ: gpio8@1f860800 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860800 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
+ gpioK: gpio9@1f860900 {
+ compatible = "microchip,pic32mzda-gpio";
+ reg = <0x1f860900 0x24>;
+ gpio-controller;
+ #gpio-cells = <2>;
+ };
+
sdhci: sdhci@1f8ec000 {
compatible = "microchip,pic32mzda-sdhci";
reg = <0x1f8ec000 0x100>;
@@ -74,4 +158,13 @@
clock-irq-pins = <1>,<1>;
status = "disabled";
};
+
+ ethernet: ethernet@1f882000 {
+ compatible = "microchip,pic32mzda-eth";
+ reg = <0x1f882000 0x1000>;
+ interrupts = <153 IRQ_TYPE_LEVEL_HIGH>;
+ clocks = <&clock PB5CLK>;
+ phy-mode = "rmii";
+ status = "disabled";
+ };
};
diff --git a/arch/mips/dts/pic32mzda_sk.dts b/arch/mips/dts/pic32mzda_sk.dts
index f886a0f..fb69a4c 100644
--- a/arch/mips/dts/pic32mzda_sk.dts
+++ b/arch/mips/dts/pic32mzda_sk.dts
@@ -42,4 +42,9 @@
&sdhci {
status = "okay";
+};
+
+ðernet {
+ reset-gpios = <&gpioJ 15 0>;
+ status = "okay";
};
\ No newline at end of file
diff --git a/configs/pic32mzdask_defconfig b/configs/pic32mzdask_defconfig
index d11eddd..6b20e68 100644
--- a/configs/pic32mzdask_defconfig
+++ b/configs/pic32mzdask_defconfig
@@ -6,6 +6,7 @@ CONFIG_SYS_LITTLE_ENDIAN=y
CONFIG_HUSH_PARSER=y
CONFIG_SYS_HUSH_PARSER=y
CONFIG_SYS_PROMPT="dask # "
+CONFIG_CMD_NET=y
CONFIG_CMD_TIME=y
# CONFIG_CMD_IMLS is not set
CONFIG_SUPPORT_OF_CONTROL=y
@@ -20,4 +21,12 @@ CONFIG_PINCTRL=y
# CONFIG_PINCTRL_FULL is not set
CONFIG_PIC32_PINCTRL=y
CONFIG_DM_MMC=y
-CONFIG_PIC32_SDHCI=y
\ No newline at end of file
+CONFIG_PIC32_SDHCI=y
+CONFIG_DM_GPIO=y
+CONFIG_CMD_GPIO=y
+CONFIG_PIC32_GPIO=y
+CONFIG_NET=y
+CONFIG_DM_ETH=y
+CONFIG_PHYLIB=y
+CONFIG_NETDEVICES=y
+CONFIG_PIC32_ETH=y
\ No newline at end of file
diff --git a/include/configs/pic32mzdask.h b/include/configs/pic32mzdask.h
index 52e53e9..d08f6ad 100644
--- a/include/configs/pic32mzdask.h
+++ b/include/configs/pic32mzdask.h
@@ -79,6 +79,28 @@
(CONFIG_SYS_CBSIZE + sizeof(CONFIG_SYS_PROMPT) + 16)
#define CONFIG_CMDLINE_EDITING 1
+/*-----------------------------------------------------------------------
+ * Networking Configuration
+ */
+#define CONFIG_MII
+#define CONFIG_PHY_SMSC
+#define CONFIG_PHY_ADDR 0 /* LAN87XX */
+#define CONFIG_SYS_RX_ETH_BUFFER 8
+#define CONFIG_NET_RETRY_COUNT 20
+#define CONFIG_ARP_TIMEOUT 500 /* millisec */
+
+#define CONFIG_CMD_MII
+#define CONFIG_CMD_PING
+#define CONFIG_CMD_DHCP
+
+/*
+ * BOOTP options
+ */
+#define CONFIG_BOOTP_BOOTFILESIZE
+#define CONFIG_BOOTP_BOOTPATH
+#define CONFIG_BOOTP_GATEWAY
+#define CONFIG_BOOTP_HOSTNAME
+
/*
* Handover flattened device tree (dtb file) to Linux kernel
*/
@@ -133,12 +155,16 @@
"importbootenv= " \
"env import -t -r ${uenvaddr} ${filesize};\0" \
\
+ "tftploadenv=tftp ${uenvaddr} ${uenvfile} \0" \
+ "tftploadscr=tftp ${uenvaddr} ${scriptfile} \0" \
+ "tftploadub=tftp ${loadaddr} ${ubootfile} \0" \
+ \
"mmcloadenv=fatload mmc 0 ${uenvaddr} ${uenvfile}\0" \
"mmcloadscr=fatload mmc 0 ${uenvaddr} ${scriptfile}\0" \
"mmcloadub=fatload mmc 0 ${loadaddr} ${ubootfile}\0" \
\
- "loadbootenv=run mmcloadenv\0" \
- "loadbootscr=run mmcloadscr\0" \
+ "loadbootenv=run mmcloadenv || run tftploadenv\0" \
+ "loadbootscr=run mmcloadscr || run tftploadscr\0" \
"bootcmd_root= " \
"if run loadbootenv; then " \
"echo Loaded environment ${uenvfile}; " \
--
1.8.3.1
1
0