This patch adds hardware initialization routine to be
invoked at driver's .probe routine.
Signed-off-by: Taku Izumi izumi.t...@jp.fujitsu.com
---
drivers/net/fjes/Makefile| 2 +-
drivers/net/fjes/fjes.h | 2 +-
drivers/net/fjes/fjes_hw.c | 296 +++
drivers/net/fjes/fjes_hw.h | 251
drivers/net/fjes/fjes_regs.h | 102 +++
5 files changed, 651 insertions(+), 2 deletions(-)
create mode 100644 drivers/net/fjes/fjes_hw.c
create mode 100644 drivers/net/fjes/fjes_hw.h
create mode 100644 drivers/net/fjes/fjes_regs.h
diff --git a/drivers/net/fjes/Makefile b/drivers/net/fjes/Makefile
index 98e59cb..a67f65d8 100644
--- a/drivers/net/fjes/Makefile
+++ b/drivers/net/fjes/Makefile
@@ -27,5 +27,5 @@
obj-$(CONFIG_FUJITSU_ES) += fjes.o
-fjes-objs := fjes_main.o
+fjes-objs := fjes_main.o fjes_hw.o
diff --git a/drivers/net/fjes/fjes.h b/drivers/net/fjes/fjes.h
index 4622da1..15ded96 100644
--- a/drivers/net/fjes/fjes.h
+++ b/drivers/net/fjes/fjes.h
@@ -28,6 +28,6 @@
extern char fjes_driver_name[];
extern char fjes_driver_version[];
-extern u32 fjes_support_mtu[];
+extern const u32 fjes_support_mtu[];
#endif /* FJES_H_ */
diff --git a/drivers/net/fjes/fjes_hw.c b/drivers/net/fjes/fjes_hw.c
new file mode 100644
index 000..e94538f
--- /dev/null
+++ b/drivers/net/fjes/fjes_hw.c
@@ -0,0 +1,296 @@
+/*
+ * FUJITSU Extended Socket Network Device driver
+ * Copyright (c) 2015 FUJITSU LIMITED
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, see http://www.gnu.org/licenses/.
+ *
+ * The full GNU General Public License is included in this distribution in
+ * the file called COPYING.
+ *
+ */
+
+#include fjes_hw.h
+#include fjes.h
+
+/* supported MTU list */
+const u32 fjes_support_mtu[] = {
+ FJES_MTU_DEFINE(8 * 1024),
+ FJES_MTU_DEFINE(16 * 1024),
+ FJES_MTU_DEFINE(32 * 1024),
+ FJES_MTU_DEFINE(64 * 1024),
+ 0
+};
+
+u32 fjes_hw_rd32(struct fjes_hw *hw, u32 reg)
+{
+ u8 *base = hw-base;
+ u32 value = 0;
+
+ value = readl(base[reg]);
+
+ return value;
+}
+
+static u8 *fjes_hw_iomap(struct fjes_hw *hw)
+{
+ u8 *base;
+
+ if (!request_mem_region(hw-hw_res.start, hw-hw_res.size,
+ fjes_driver_name)) {
+ pr_err(request_mem_region failed\n);
+ return NULL;
+ }
+
+ base = (u8 *)ioremap_nocache(hw-hw_res.start, hw-hw_res.size);
+
+ return base;
+}
+
+int fjes_hw_reset(struct fjes_hw *hw)
+{
+ int timeout;
+ union REG_DCTL dctl;
+
+ dctl.reg = 0;
+ dctl.bits.reset = 1;
+ wr32(XSCT_DCTL, dctl.reg);
+
+ timeout = FJES_DEVICE_RESET_TIMEOUT * 1000;
+ dctl.reg = rd32(XSCT_DCTL);
+ while ((dctl.bits.reset == 1) (timeout 0)) {
+ msleep(1000);
+ dctl.reg = rd32(XSCT_DCTL);
+ timeout -= 1000;
+ }
+
+ return timeout 0 ? 0 : -EIO;
+}
+
+static int fjes_hw_get_max_epid(struct fjes_hw *hw)
+{
+ union REG_MAX_EP info;
+
+ info.reg = rd32(XSCT_MAX_EP);
+
+ return info.bits.maxep;
+}
+
+static int fjes_hw_get_my_epid(struct fjes_hw *hw)
+{
+ union REG_OWNER_EPID info;
+
+ info.reg = rd32(XSCT_OWNER_EPID);
+
+ return info.bits.epid;
+}
+
+static int fjes_hw_alloc_shared_status_region(struct fjes_hw *hw)
+{
+ size_t size;
+
+ size = sizeof(struct fjes_device_shared_info) +
+ (sizeof(u8) * hw-max_epid);
+ hw-hw_info.share = kzalloc(size, GFP_KERNEL);
+ if (!hw-hw_info.share)
+ return -ENOMEM;
+
+ hw-hw_info.share-epnum = hw-max_epid;
+
+ return 0;
+}
+
+static int fjes_hw_alloc_epbuf(struct epbuf_handler *epbh)
+{
+ void *mem;
+
+ mem = vzalloc(EP_BUFFER_SIZE);
+ if (!mem)
+ return -ENOMEM;
+
+ epbh-buffer = mem;
+ epbh-size = EP_BUFFER_SIZE;
+
+ epbh-info = (union ep_buffer_info *)mem;
+ epbh-ring = (u8 *)(mem + sizeof(union ep_buffer_info));
+
+ return 0;
+}
+
+void fjes_hw_setup_epbuf(struct epbuf_handler *epbh, u8 *mac_addr, u32 mtu)
+{
+ union ep_buffer_info *info = epbh-info;
+ int i;
+ u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
+
+ for (i = 0; i EP_BUFFER_SUPPORT_VLAN_MAX; i++)
+ vlan_id[i] = info-v1i.vlan_id[i];
+
+ memset(info, 0, sizeof(union ep_buffer_info));
+
+