|
|
e88930 |
From 264e48a0bda2d6cd5d0607acd2669894ee95b3b5 Mon Sep 17 00:00:00 2001
|
|
|
e88930 |
From: Nilesh Javali <nilesh.javali@cavium.com>
|
|
|
e88930 |
Date: Fri, 11 Nov 2016 08:17:51 +0200
|
|
|
e88930 |
Subject: iscsiuio: Add support for the new qedi transport
|
|
|
e88930 |
|
|
|
e88930 |
Signed-off-by: Manish Rangankar <manish.rangankar@cavium.com>
|
|
|
e88930 |
Signed-off-by: Adheer Chandravanshi <adheer.chandravanshi@qlogic.com>
|
|
|
e88930 |
Signed-off-by: Nilesh Javali <nilesh.javali@cavium.com>
|
|
|
e88930 |
---
|
|
|
e88930 |
iscsiuio/src/unix/libs/Makefile.am | 3 +-
|
|
|
e88930 |
iscsiuio/src/unix/libs/cnic.c | 9 +
|
|
|
e88930 |
iscsiuio/src/unix/libs/cnic.h | 2 +
|
|
|
e88930 |
iscsiuio/src/unix/libs/qedi.c | 1151 ++++++++++++++++++++++++++++++++++++
|
|
|
e88930 |
iscsiuio/src/unix/libs/qedi.h | 159 +++++
|
|
|
e88930 |
iscsiuio/src/unix/nic.c | 6 +-
|
|
|
e88930 |
iscsiuio/src/unix/nic.h | 1 +
|
|
|
e88930 |
iscsiuio/src/unix/nic_utils.c | 147 ++++-
|
|
|
e88930 |
iscsiuio/src/unix/nic_utils.h | 2 +
|
|
|
e88930 |
iscsiuio/src/unix/options.h | 1 +
|
|
|
e88930 |
10 files changed, 1475 insertions(+), 6 deletions(-)
|
|
|
e88930 |
create mode 100644 iscsiuio/src/unix/libs/qedi.c
|
|
|
e88930 |
create mode 100644 iscsiuio/src/unix/libs/qedi.h
|
|
|
e88930 |
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/libs/Makefile.am b/iscsiuio/src/unix/libs/Makefile.am
|
|
|
e88930 |
index 890415f5a79a..737546b04917 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/libs/Makefile.am
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/libs/Makefile.am
|
|
|
e88930 |
@@ -10,4 +10,5 @@ noinst_LIBRARIES = lib_iscsiuio_hw_cnic.a
|
|
|
e88930 |
lib_iscsiuio_hw_cnic_a_SOURCES = ../build_date.c \
|
|
|
e88930 |
cnic.c \
|
|
|
e88930 |
bnx2.c \
|
|
|
e88930 |
- bnx2x.c
|
|
|
e88930 |
+ bnx2x.c \
|
|
|
e88930 |
+ qedi.c
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/libs/cnic.c b/iscsiuio/src/unix/libs/cnic.c
|
|
|
e88930 |
index 228c4b9e25b1..5d60f898ad57 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/libs/cnic.c
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/libs/cnic.c
|
|
|
e88930 |
@@ -55,6 +55,7 @@
|
|
|
e88930 |
#include <sys/types.h>
|
|
|
e88930 |
#include <sys/user.h>
|
|
|
e88930 |
#include <sys/socket.h>
|
|
|
e88930 |
+#include <sys/mman.h>
|
|
|
e88930 |
|
|
|
e88930 |
#include "uip_arp.h"
|
|
|
e88930 |
#include "nic.h"
|
|
|
e88930 |
@@ -65,6 +66,7 @@
|
|
|
e88930 |
#include "cnic.h"
|
|
|
e88930 |
#include "iscsi_if.h"
|
|
|
e88930 |
#include "ipv6_ndpc.h"
|
|
|
e88930 |
+#include "qedi.h"
|
|
|
e88930 |
|
|
|
e88930 |
/*******************************************************************************
|
|
|
e88930 |
* Constants
|
|
|
e88930 |
@@ -81,6 +83,13 @@ const char bnx2i_library_transport_name[] = "bnx2i";
|
|
|
e88930 |
const size_t bnx2i_library_transport_name_size =
|
|
|
e88930 |
sizeof(bnx2i_library_transport_name);
|
|
|
e88930 |
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * Constants for qedi module
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+const char qedi_library_transport_name[] = "qedi";
|
|
|
e88930 |
+const size_t qedi_library_transport_name_size =
|
|
|
e88930 |
+ sizeof(qedi_library_transport_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
/******************************************************************************
|
|
|
e88930 |
* Netlink Functions
|
|
|
e88930 |
******************************************************************************/
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/libs/cnic.h b/iscsiuio/src/unix/libs/cnic.h
|
|
|
e88930 |
index 6244a94012c1..c86595c512b0 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/libs/cnic.h
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/libs/cnic.h
|
|
|
e88930 |
@@ -44,6 +44,8 @@
|
|
|
e88930 |
******************************************************************************/
|
|
|
e88930 |
extern const char bnx2i_library_transport_name[];
|
|
|
e88930 |
extern const size_t bnx2i_library_transport_name_size;
|
|
|
e88930 |
+extern const char qedi_library_transport_name[];
|
|
|
e88930 |
+extern const size_t qedi_library_transport_name_size;
|
|
|
e88930 |
|
|
|
e88930 |
int cnic_nl_open();
|
|
|
e88930 |
void cnic_nl_close();
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/libs/qedi.c b/iscsiuio/src/unix/libs/qedi.c
|
|
|
e88930 |
new file mode 100644
|
|
|
e88930 |
index 000000000000..c2096e59dad1
|
|
|
e88930 |
--- /dev/null
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/libs/qedi.c
|
|
|
e88930 |
@@ -0,0 +1,1151 @@
|
|
|
e88930 |
+/*
|
|
|
e88930 |
+ * Copyright (c) 2016, Cavium Inc.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * All rights reserved.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
e88930 |
+ * modification, are permitted provided that the following conditions
|
|
|
e88930 |
+ * are met:
|
|
|
e88930 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
e88930 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
e88930 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
e88930 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
e88930 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
e88930 |
+ * 3. All advertising materials mentioning features or use of this software
|
|
|
e88930 |
+ * must display the following acknowledgement:
|
|
|
e88930 |
+ * This product includes software developed by Adam Dunkels.
|
|
|
e88930 |
+ * 4. The name of the author may not be used to endorse or promote
|
|
|
e88930 |
+ * products derived from this software without specific prior
|
|
|
e88930 |
+ * written permission.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
e88930 |
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
e88930 |
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
e88930 |
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
e88930 |
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
e88930 |
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
e88930 |
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
e88930 |
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
e88930 |
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
e88930 |
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
e88930 |
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * qedi.c - qedi user space driver
|
|
|
e88930 |
+ * This file handles different qedi NIC operations,
|
|
|
e88930 |
+ * qedi_open - initializes all hardware resources under NIC device
|
|
|
e88930 |
+ * qedi_close - closes the NIC device
|
|
|
e88930 |
+ * qedi_read - reads data to the hardware
|
|
|
e88930 |
+ * qedi_write - writes data to the hardware
|
|
|
e88930 |
+ * qedi_start_xmit - sends a pkt of data on NIC device
|
|
|
e88930 |
+ * qedi_get_tx_pkt - gets a Tx pkt from NIC
|
|
|
e88930 |
+ * qedi_clear_tx_intr - clears the Tx interrupt
|
|
|
e88930 |
+ * NOTE: nic_t is used as NIC device,
|
|
|
e88930 |
+ * qedi is not attached to netdev hence it is not mandatory
|
|
|
e88930 |
+ * for netdev to be upd
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+#include <errno.h>
|
|
|
e88930 |
+#include <stdio.h>
|
|
|
e88930 |
+#include <string.h>
|
|
|
e88930 |
+#include <arpa/inet.h>
|
|
|
e88930 |
+#include <linux/types.h>
|
|
|
e88930 |
+#include <linux/sockios.h>
|
|
|
e88930 |
+#include <linux/ethtool.h>
|
|
|
e88930 |
+#include <linux/netlink.h>
|
|
|
e88930 |
+#include <sys/mman.h>
|
|
|
e88930 |
+#include <sys/ioctl.h>
|
|
|
e88930 |
+#include <sys/types.h>
|
|
|
e88930 |
+#include <sys/stat.h>
|
|
|
e88930 |
+#include <sys/user.h>
|
|
|
e88930 |
+#include <fcntl.h>
|
|
|
e88930 |
+#include <unistd.h>
|
|
|
e88930 |
+
|
|
|
e88930 |
+#include "config.h"
|
|
|
e88930 |
+
|
|
|
e88930 |
+#include "build_date.h"
|
|
|
e88930 |
+#include "bnx2x.h"
|
|
|
e88930 |
+#include "qedi.h"
|
|
|
e88930 |
+#include "cnic.h"
|
|
|
e88930 |
+#include "logger.h"
|
|
|
e88930 |
+#include "nic.h"
|
|
|
e88930 |
+#include "nic_id.h"
|
|
|
e88930 |
+#include "nic_utils.h"
|
|
|
e88930 |
+#include "options.h"
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define PFX "qedi "
|
|
|
e88930 |
+
|
|
|
e88930 |
+extern int nl_sock;
|
|
|
e88930 |
+
|
|
|
e88930 |
+/* Foward struct declarations */
|
|
|
e88930 |
+struct nic_ops qedi_op;
|
|
|
e88930 |
+
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * NIC Library Strings
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+static const char library_name[] = "qedi";
|
|
|
e88930 |
+static const char library_version[] = PACKAGE_VERSION;
|
|
|
e88930 |
+static const char library_uio_name[] = "qedi_uio";
|
|
|
e88930 |
+
|
|
|
e88930 |
+/* The name that should be returned from /sys/class/uio/uio0/name */
|
|
|
e88930 |
+static const char cnic_uio_sysfs_name_tempate[] = "/sys/class/uio/uio%i/name";
|
|
|
e88930 |
+static const char qedi_uio_sysfs_name[] = "qedi_uio";
|
|
|
e88930 |
+static const char qedi_host_mac_template[] =
|
|
|
e88930 |
+ "/sys/class/iscsi_host/host%i/hwaddress";
|
|
|
e88930 |
+
|
|
|
e88930 |
+struct qedi_driver_version qedi_version = {
|
|
|
e88930 |
+ QEDI_UNKNOWN_MAJOR_VERSION,
|
|
|
e88930 |
+ QEDI_UNKNOWN_MINOR_VERSION,
|
|
|
e88930 |
+ QEDI_UNKNOWN_SUB_MINOR_VERSION,
|
|
|
e88930 |
+};
|
|
|
e88930 |
+
|
|
|
e88930 |
+static int qedi_clear_tx_intr(nic_t *nic);
|
|
|
e88930 |
+
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * QEDI Library Functions
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_library_name() - Used to get the name of this NIC library
|
|
|
e88930 |
+ * @param name - This function will return the pointer to this NIC
|
|
|
e88930 |
+ * library name
|
|
|
e88930 |
+ * @param name_size
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static void qedi_get_library_name(char **name, size_t *name_size)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ *name = (char *)library_name;
|
|
|
e88930 |
+ *name_size = sizeof(library_name);
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_library_version() - Used to get the version string of this
|
|
|
e88930 |
+ * NIC library
|
|
|
e88930 |
+ * @param version - This function will return the pointer to this NIC
|
|
|
e88930 |
+ * library version string
|
|
|
e88930 |
+ * @param version_size - This will be set with the version size
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static void qedi_get_library_version(char **version, size_t *version_size)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ *version = (char *)library_version;
|
|
|
e88930 |
+ *version_size = sizeof(library_version);
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_build_date() - Used to get the build date string of this library
|
|
|
e88930 |
+ * @param version - This function will return the pointer to this NIC
|
|
|
e88930 |
+ * library build date string
|
|
|
e88930 |
+ * @param version_size - This will be set with the build date string size
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static void qedi_get_build_date(char **build, size_t *build_size)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ *build = (char *)build_date;
|
|
|
e88930 |
+ *build_size = sizeof(build_date);
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_transport_name() - Used to get the transport name associated
|
|
|
e88930 |
+ * with this this NIC library
|
|
|
e88930 |
+ * @param transport_name - This function will return the pointer to this NIC
|
|
|
e88930 |
+ * library's associated transport string
|
|
|
e88930 |
+ * @param transport_name_size - This will be set with the transport name size
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static void qedi_get_transport_name(char **transport_name,
|
|
|
e88930 |
+ size_t *transport_name_size)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ *transport_name = (char *)qedi_library_transport_name;
|
|
|
e88930 |
+ *transport_name_size = qedi_library_transport_name_size;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_uio_name() - Used to get the uio name associated with this this
|
|
|
e88930 |
+ * NIC library
|
|
|
e88930 |
+ * @param uio_name - This function will return the pointer to this NIC
|
|
|
e88930 |
+ * library's associated uio string
|
|
|
e88930 |
+ * @param transport_name_size - This will be set with the uio name size
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static void qedi_get_uio_name(char **uio_name, size_t *uio_name_size)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ *uio_name = (char *)library_uio_name;
|
|
|
e88930 |
+ *uio_name_size = sizeof(library_uio_name);
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_ops() - Used to get the NIC library op table
|
|
|
e88930 |
+ * @param op - The op table of this NIC library
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+struct nic_ops *qedi_get_ops()
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ return &qedi_op;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * qedi Utility Functions
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * Utility Functions Used to read register from the qedi device
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+static void qedi_set_drv_version_unknown(qedi_t *bp)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ bp->version.major = QEDI_UNKNOWN_MAJOR_VERSION;
|
|
|
e88930 |
+ bp->version.minor = QEDI_UNKNOWN_MINOR_VERSION;
|
|
|
e88930 |
+ bp->version.sub_minor = QEDI_UNKNOWN_SUB_MINOR_VERSION;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/* Return: 1 = Unknown, 0 = Known */
|
|
|
e88930 |
+static int qedi_is_drv_version_unknown(struct qedi_driver_version *version)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ if ((version->major == (uint16_t)QEDI_UNKNOWN_MAJOR_VERSION) &&
|
|
|
e88930 |
+ (version->minor == (uint16_t)QEDI_UNKNOWN_MINOR_VERSION) &&
|
|
|
e88930 |
+ (version->sub_minor == (uint16_t)QEDI_UNKNOWN_SUB_MINOR_VERSION)) {
|
|
|
e88930 |
+ return 1;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_drv_version() - Used to determine the driver version
|
|
|
e88930 |
+ * @param bp - Device used to determine qedi driver version
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_get_drv_version(qedi_t *bp)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ nic_t *nic = bp->parent;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /*
|
|
|
e88930 |
+ * CAPABILITIES: Get the iscsi driver version from qedi
|
|
|
e88930 |
+ * This may be obtained from sysfs
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: qedi driver using version %d.%d.%d",
|
|
|
e88930 |
+ nic->log_name,
|
|
|
e88930 |
+ bp->version.major, bp->version.minor, bp->version.sub_minor);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/******************************************************************************/
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_chip_id() - Used to retrieve the chip ID from the nic
|
|
|
e88930 |
+ * @param dev - Device used to determin NIC type
|
|
|
e88930 |
+ * @return Chip ID read from the MISC ID register
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_get_chip_id(qedi_t *bp)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ /* int val, id; */
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Get the chip revision id and number. */
|
|
|
e88930 |
+ /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
|
|
|
e88930 |
+ /*
|
|
|
e88930 |
+ * CAPABILITIES: Get the CHIP info from qedi through sysfs or uio struct.
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_uio_verify()
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_uio_verify(nic_t *nic)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ char *raw = NULL, *raw_tmp;
|
|
|
e88930 |
+ uint32_t raw_size = 0;
|
|
|
e88930 |
+ char temp_path[sizeof(cnic_uio_sysfs_name_tempate) + 8];
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Build the path to determine uio name */
|
|
|
e88930 |
+ snprintf(temp_path, sizeof(temp_path),
|
|
|
e88930 |
+ cnic_uio_sysfs_name_tempate, nic->uio_minor);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = capture_file(&raw, &raw_size, temp_path);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* sanitize name string by replacing newline with null termination */
|
|
|
e88930 |
+ raw_tmp = raw;
|
|
|
e88930 |
+ while (*raw_tmp != '\n')
|
|
|
e88930 |
+ raw_tmp++;
|
|
|
e88930 |
+ *raw_tmp = '\0';
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (strncmp(raw, qedi_uio_sysfs_name,
|
|
|
e88930 |
+ sizeof(qedi_uio_sysfs_name)) != 0) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: uio names not equal: expecting %s got %s from %s",
|
|
|
e88930 |
+ nic->log_name, qedi_uio_sysfs_name, raw, temp_path);
|
|
|
e88930 |
+ rc = -EIO;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ free(raw);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Verified is a qedi_uio device", nic->log_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
+error:
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+static int qedi_get_mac_addr(qedi_t *bp)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ nic_t *nic = bp->parent;
|
|
|
e88930 |
+ char *raw = NULL, *raw_tmp;
|
|
|
e88930 |
+ uint32_t raw_size = 0;
|
|
|
e88930 |
+ char temp_path[sizeof(qedi_host_mac_template) + 8];
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Build the path to determine mac address */
|
|
|
e88930 |
+ snprintf(temp_path, sizeof(temp_path),
|
|
|
e88930 |
+ qedi_host_mac_template, nic->host_no);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = capture_file(&raw, &raw_size, temp_path);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* sanitize name string by replacing newline with null termination */
|
|
|
e88930 |
+ raw_tmp = raw;
|
|
|
e88930 |
+ while (*raw_tmp != '\n')
|
|
|
e88930 |
+ raw_tmp++;
|
|
|
e88930 |
+ *raw_tmp = '\0';
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = sscanf(raw, "%02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
e88930 |
+ (uint32_t *)&nic->mac_addr[0], (uint32_t *)&nic->mac_addr[1],
|
|
|
e88930 |
+ (uint32_t *)&nic->mac_addr[2], (uint32_t *)&nic->mac_addr[3],
|
|
|
e88930 |
+ (uint32_t *)&nic->mac_addr[4], (uint32_t *)&nic->mac_addr[5]);
|
|
|
e88930 |
+ if (rc != 1) {
|
|
|
e88930 |
+ LOG_WARN(PFX "%s: Could not parse mac_addr",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ rc = -ENODEV;
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+error:
|
|
|
e88930 |
+ if (raw)
|
|
|
e88930 |
+ free(raw);
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * qedi Utility Functions to get to the hardware consumer indexes
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+
|
|
|
e88930 |
+static __u32 qedi_get_rx(qedi_t *bp)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ return ((struct qedi_uio_ctrl *)bp->uctrl_map)->host_rx_cons;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+static __u32 qedi_get_tx(qedi_t *bp)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ return ((struct qedi_uio_ctrl *)bp->uctrl_map)->hw_tx_cons;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_free() - Used to free a qedi structure
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static void qedi_free(nic_t *nic)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ if (nic->priv)
|
|
|
e88930 |
+ free(nic->priv);
|
|
|
e88930 |
+ nic->priv = NULL;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_alloc() - Used to allocate a qedi structure
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static qedi_t *qedi_alloc(nic_t *nic)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp = malloc(sizeof(*bp));
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (!bp) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Could not allocate QEDI space",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ return NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Clear out the CNIC contents */
|
|
|
e88930 |
+ memset(bp, 0, sizeof(*bp));
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->parent = nic;
|
|
|
e88930 |
+ nic->priv = (void *)bp;
|
|
|
e88930 |
+ get_iscsi_transport_handle(nic, &nic->transport_handle);
|
|
|
e88930 |
+ qedi_set_drv_version_unknown(bp);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return bp;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+int uio_get_map_offset(nic_t *nic, uint8_t map, uint32_t *offset)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ char *raw = NULL;
|
|
|
e88930 |
+ uint32_t raw_size = 0;
|
|
|
e88930 |
+ ssize_t elements_read;
|
|
|
e88930 |
+ char temp_path[sizeof(UIO_OFFSET_TMPL) + 8];
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Capture RX buffer size */
|
|
|
e88930 |
+ snprintf(temp_path, sizeof(temp_path),
|
|
|
e88930 |
+ UIO_OFFSET_TMPL, nic->uio_minor, map);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = capture_file(&raw, &raw_size, temp_path);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ elements_read = sscanf(raw, "0x%x", offset);
|
|
|
e88930 |
+ if (elements_read != 1) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Couldn't get the offset from %s",
|
|
|
e88930 |
+ nic->log_name, temp_path);
|
|
|
e88930 |
+ rc = -EIO;
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = 0;
|
|
|
e88930 |
+error:
|
|
|
e88930 |
+ if (raw)
|
|
|
e88930 |
+ free(raw);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+int uio_get_map_info(nic_t *nic, uint8_t map, char *attr, uint32_t *val)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ char *raw = NULL;
|
|
|
e88930 |
+ uint32_t raw_size = 0;
|
|
|
e88930 |
+ ssize_t elements_read;
|
|
|
e88930 |
+ char temp_path[sizeof(UIO_ATTR_TMPL) + 8];
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Capture RX buffer size */
|
|
|
e88930 |
+ snprintf(temp_path, sizeof(temp_path),
|
|
|
e88930 |
+ UIO_ATTR_TMPL, nic->uio_minor, map, attr);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = capture_file(&raw, &raw_size, temp_path);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ elements_read = sscanf(raw, "0x%x", val);
|
|
|
e88930 |
+ if (elements_read != 1) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Couldn't get the offset from %s",
|
|
|
e88930 |
+ nic->log_name, temp_path);
|
|
|
e88930 |
+ rc = -EIO;
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = 0;
|
|
|
e88930 |
+error:
|
|
|
e88930 |
+ if (raw)
|
|
|
e88930 |
+ free(raw);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_open() - This will initialize all the hardware resources underneath
|
|
|
e88930 |
+ * a struct cnic_uio device
|
|
|
e88930 |
+ * @param dev - The struct cnic_uio device to attach the hardware with
|
|
|
e88930 |
+ * @return 0 on success, on failure a errno will be returned
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_open(nic_t *nic)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp = NULL;
|
|
|
e88930 |
+ struct stat uio_stat;
|
|
|
e88930 |
+ int i, rc;
|
|
|
e88930 |
+ int count;
|
|
|
e88930 |
+ uint32_t bus;
|
|
|
e88930 |
+ uint32_t slot;
|
|
|
e88930 |
+ uint32_t func;
|
|
|
e88930 |
+ uint32_t offset;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Sanity Check: validate the parameters */
|
|
|
e88930 |
+ if (!nic) {
|
|
|
e88930 |
+ LOG_ERR(PFX "nic == NULL");
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if ((nic->priv) != NULL &&
|
|
|
e88930 |
+ (((qedi_t *)(nic->priv))->flags & QEDI_OPENED)) {
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (nic->host_no == INVALID_HOST_NO) {
|
|
|
e88930 |
+ rc = sscanf(nic->config_device_name, "host%d", &nic->host_no);
|
|
|
e88930 |
+ if (rc != 1) {
|
|
|
e88930 |
+ LOG_WARN(PFX "%s: Could not parse for host number",
|
|
|
e88930 |
+ nic->config_device_name);
|
|
|
e88930 |
+ rc = -ENODEV;
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp = qedi_alloc(nic);
|
|
|
e88930 |
+ if (!bp)
|
|
|
e88930 |
+ return -ENOMEM;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (qedi_is_drv_version_unknown(&qedi_version)) {
|
|
|
e88930 |
+ /* If version is unknown, go read from ethtool */
|
|
|
e88930 |
+ rc = qedi_get_drv_version(bp);
|
|
|
e88930 |
+ if (rc)
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ /* Version is not unknown, just use it */
|
|
|
e88930 |
+ qedi_version.major = bp->version.major;
|
|
|
e88930 |
+ qedi_version.minor = bp->version.minor;
|
|
|
e88930 |
+ qedi_version.sub_minor = bp->version.sub_minor;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ count = 0;
|
|
|
e88930 |
+ while ((nic->fd < 0) && count < 15) {
|
|
|
e88930 |
+ /* udev might not have created the file yet */
|
|
|
e88930 |
+ pthread_mutex_unlock(&nic->nic_mutex);
|
|
|
e88930 |
+ sleep(1);
|
|
|
e88930 |
+ pthread_mutex_lock(&nic->nic_mutex);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ nic->fd = open(nic->uio_device_name, O_RDWR | O_NONBLOCK);
|
|
|
e88930 |
+ if (nic->fd != INVALID_FD) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: uio device has been brought up via pid: %d on fd: %d",
|
|
|
e88930 |
+ nic->uio_device_name, getpid(), nic->fd);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = qedi_uio_verify(nic);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ continue;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ LOG_WARN(PFX "%s: Could not open device: %s, [%s]",
|
|
|
e88930 |
+ nic->log_name, nic->uio_device_name,
|
|
|
e88930 |
+ strerror(errno));
|
|
|
e88930 |
+
|
|
|
e88930 |
+ manually_trigger_uio_event(nic, nic->uio_minor);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* udev might not have created the file yet */
|
|
|
e88930 |
+ pthread_mutex_unlock(&nic->nic_mutex);
|
|
|
e88930 |
+ sleep(1);
|
|
|
e88930 |
+ pthread_mutex_lock(&nic->nic_mutex);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ count++;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ if (fstat(nic->fd, &uio_stat) < 0) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Could not fstat device", nic->log_name);
|
|
|
e88930 |
+ rc = -ENODEV;
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ nic->uio_minor = minor(uio_stat.st_rdev);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /*
|
|
|
e88930 |
+ * CAPABILITIES: acquire the rx buffer size and rx ring size from qedi
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->rx_ring_size = RX_RING_SIZE;
|
|
|
e88930 |
+ bp->rx_buffer_size = PKT_BUF_SIZE;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_DEBUG(PFX "%s: using rx ring size: %d, rx buffer size: %d",
|
|
|
e88930 |
+ nic->log_name, bp->rx_ring_size, bp->rx_buffer_size);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Determine the number of UIO events that have already occurred */
|
|
|
e88930 |
+ rc = detemine_initial_uio_events(nic, &nic->intr_count);
|
|
|
e88930 |
+ if (rc != 0) {
|
|
|
e88930 |
+ LOG_ERR(PFX "Could not get the no. of initial UIO events");
|
|
|
e88930 |
+ nic->intr_count = 0;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Allocate space for rx pkt ring */
|
|
|
e88930 |
+ bp->rx_pkt_ring = malloc(sizeof(void *) * bp->rx_ring_size);
|
|
|
e88930 |
+ if (!bp->rx_pkt_ring) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Could not allocate space for rx_pkt_ring",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ rc = errno;
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /*
|
|
|
e88930 |
+ * Map the uio struct and packet buffer
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ offset = 0;
|
|
|
e88930 |
+ rc = uio_get_map_info(nic, QEDI_UCTRL_MAP_REG, "size", &offset);
|
|
|
e88930 |
+ if (rc) {
|
|
|
e88930 |
+ LOG_INFO(PFX "Failed to get the map size rc=%d", rc);
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ LOG_INFO(PFX "uctrl map size=%u", offset);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ offset = 0;
|
|
|
e88930 |
+ rc = uio_get_map_info(nic, QEDI_RING_MAP_REG, "size", &offset);
|
|
|
e88930 |
+ if (rc) {
|
|
|
e88930 |
+ LOG_INFO(PFX "Failed to get the map size rc=%d", rc);
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ LOG_INFO(PFX "ring map size=%u", offset);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ offset = 0;
|
|
|
e88930 |
+ rc = uio_get_map_info(nic, QEDI_BUF_MAP_REG, "size", &offset);
|
|
|
e88930 |
+ if (rc) {
|
|
|
e88930 |
+ LOG_INFO(PFX "Failed to get the map size rc=%d", rc);
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ LOG_INFO(PFX "buf map size=%u", offset);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ offset = 0;
|
|
|
e88930 |
+ rc = uio_get_map_offset(nic, QEDI_UCTRL_MAP_REG, &offset);
|
|
|
e88930 |
+ if (rc) {
|
|
|
e88930 |
+ LOG_INFO(PFX "Failed to get the map offset rc=%d", rc);
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->uctrl_map = mmap(NULL, sizeof(struct qedi_uio_ctrl),
|
|
|
e88930 |
+ PROT_READ | PROT_WRITE,
|
|
|
e88930 |
+ MAP_SHARED | MAP_LOCKED,
|
|
|
e88930 |
+ nic->fd, (off_t)0);
|
|
|
e88930 |
+ if (bp->uctrl_map == MAP_FAILED) {
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Could not mmap uio ctrl struct: %s",
|
|
|
e88930 |
+ nic->log_name, strerror(errno));
|
|
|
e88930 |
+ bp->uctrl_map = NULL;
|
|
|
e88930 |
+ rc = errno;
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->uctrl_map_offset = offset;
|
|
|
e88930 |
+ bp->uctrl_map += offset;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->rx_comp_ring = mmap(NULL, nic->page_size,
|
|
|
e88930 |
+ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
|
|
|
e88930 |
+ nic->fd, (off_t)nic->page_size);
|
|
|
e88930 |
+ if (bp->rx_comp_ring == MAP_FAILED) {
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Could not mmap rx_comp_ring: %s",
|
|
|
e88930 |
+ nic->log_name, strerror(errno));
|
|
|
e88930 |
+ bp->rx_comp_ring = NULL;
|
|
|
e88930 |
+ rc = errno;
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->bufs = mmap(NULL, (bp->rx_ring_size + 1) * bp->rx_buffer_size,
|
|
|
e88930 |
+ PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED,
|
|
|
e88930 |
+ nic->fd, (off_t)2 * nic->page_size);
|
|
|
e88930 |
+ if (bp->bufs == MAP_FAILED) {
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Could not mmap pkt buffers: %s",
|
|
|
e88930 |
+ nic->log_name, strerror(errno));
|
|
|
e88930 |
+ bp->bufs = NULL;
|
|
|
e88930 |
+ rc = errno;
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /*
|
|
|
e88930 |
+ * Get all CHIP related info from qedi
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ bp->chip_id = qedi_get_chip_id(bp);
|
|
|
e88930 |
+ LOG_DEBUG(PFX "Chip ID: %x", bp->chip_id);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = get_bus_slot_func_num(nic, &bus, &slot, &func);
|
|
|
e88930 |
+ if (rc != 0) {
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Couldn't determine bus:slot.func",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ goto open_error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /*
|
|
|
e88930 |
+ * Get all function, pfid, client_id and cid info from qedi
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: func 0x%x, pfid 0x%x, client_id 0x%x, cid 0x%x",
|
|
|
e88930 |
+ nic->log_name, bp->func, bp->pfid, bp->client_id, bp->cid);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->get_rx_cons = qedi_get_rx;
|
|
|
e88930 |
+ bp->get_tx_cons = qedi_get_tx;
|
|
|
e88930 |
+ bp->tx_cons = 0;
|
|
|
e88930 |
+ bp->tx_prod = 0;
|
|
|
e88930 |
+ bp->tx_bd_prod = 0;
|
|
|
e88930 |
+ bp->tx_pkt = bp->bufs;
|
|
|
e88930 |
+ bp->rx_pkts = bp->bufs + bp->rx_buffer_size;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->rx_index = 0;
|
|
|
e88930 |
+ bp->rx_cons = 0;
|
|
|
e88930 |
+ bp->rx_bd_cons = 0;
|
|
|
e88930 |
+ bp->rx_prod = 127;
|
|
|
e88930 |
+ bp->rx_bd_prod = bp->rx_ring_size;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ for (i = 0; i < bp->rx_ring_size; i++) {
|
|
|
e88930 |
+ void *ptr = bp->bufs + (bp->rx_buffer_size * (i + 1));
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->rx_pkt_ring[i] = ptr;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_get_mac_addr(bp);
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Using mac address: %02x:%02x:%02x:%02x:%02x:%02x",
|
|
|
e88930 |
+ nic->log_name,
|
|
|
e88930 |
+ nic->mac_addr[0], nic->mac_addr[1], nic->mac_addr[2],
|
|
|
e88930 |
+ nic->mac_addr[3], nic->mac_addr[4], nic->mac_addr[5]);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_get_library_name(&nic->library_name, (size_t *)&count);
|
|
|
e88930 |
+ LOG_INFO("%s: qedi initialized", nic->log_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp->flags |= QEDI_OPENED;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+open_error:
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->bufs) {
|
|
|
e88930 |
+ munmap(bp->bufs, (bp->rx_ring_size + 1) * bp->rx_buffer_size);
|
|
|
e88930 |
+ bp->bufs = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->rx_comp_ring) {
|
|
|
e88930 |
+ munmap(bp->rx_comp_ring, nic->page_size);
|
|
|
e88930 |
+ bp->rx_comp_ring = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->uctrl_map) {
|
|
|
e88930 |
+ bp->uctrl_map -= bp->uctrl_map_offset;
|
|
|
e88930 |
+ munmap(bp->uctrl_map, sizeof(struct qedi_uio_ctrl));
|
|
|
e88930 |
+ bp->uctrl_map = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->rx_pkt_ring) {
|
|
|
e88930 |
+ free(bp->rx_pkt_ring);
|
|
|
e88930 |
+ bp->rx_pkt_ring = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (nic->fd != INVALID_FD) {
|
|
|
e88930 |
+ close(nic->fd);
|
|
|
e88930 |
+ nic->fd = INVALID_FD;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_free(nic);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_uio_close_resources() - Used to free resource for the NIC/CNIC
|
|
|
e88930 |
+ * @param nic - NIC device to free resource
|
|
|
e88930 |
+ * @param graceful - whether to wait to close gracefully
|
|
|
e88930 |
+ * @return 0 on success, <0 on failure
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_uio_close_resources(nic_t *nic, NIC_SHUTDOWN_T graceful)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Check if there is an assoicated qedi device */
|
|
|
e88930 |
+ if (!bp) {
|
|
|
e88930 |
+ LOG_WARN(PFX "%s: when closing resources there is no assoicated qedi",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ return -EIO;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Clean up allocated memory */
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->rx_pkt_ring) {
|
|
|
e88930 |
+ free(bp->rx_pkt_ring);
|
|
|
e88930 |
+ bp->rx_pkt_ring = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Clean up mapped registers */
|
|
|
e88930 |
+ if (bp->bufs) {
|
|
|
e88930 |
+ rc = munmap(bp->bufs,
|
|
|
e88930 |
+ (bp->rx_ring_size + 1) * bp->rx_buffer_size);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Couldn't unmap bufs", nic->log_name);
|
|
|
e88930 |
+ bp->bufs = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->rx_comp_ring) {
|
|
|
e88930 |
+ rc = munmap(bp->rx_comp_ring, nic->page_size);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Couldn't unmap ring", nic->log_name);
|
|
|
e88930 |
+ bp->rx_comp_ring = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->uctrl_map) {
|
|
|
e88930 |
+ bp->uctrl_map -= bp->uctrl_map_offset;
|
|
|
e88930 |
+ rc = munmap(bp->uctrl_map, sizeof(struct qedi_uio_ctrl));
|
|
|
e88930 |
+ if (rc != 0) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Couldn't unmap uio ctrl",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ bp->uctrl_map = NULL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (nic->fd != INVALID_FD) {
|
|
|
e88930 |
+ rc = close(nic->fd);
|
|
|
e88930 |
+ if (rc != 0) {
|
|
|
e88930 |
+ LOG_ERR(PFX
|
|
|
e88930 |
+ "%s: Couldn't close uio file descriptor: %d",
|
|
|
e88930 |
+ nic->log_name, nic->fd);
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ LOG_DEBUG(PFX "%s: Closed uio file descriptor: %d",
|
|
|
e88930 |
+ nic->log_name, nic->fd);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ nic->fd = INVALID_FD;
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Invalid uio file descriptor: %d",
|
|
|
e88930 |
+ nic->log_name, nic->fd);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_set_drv_version_unknown(bp);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_INFO(PFX "%s: Closed all resources", nic->log_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_close() - Used to close the NIC device
|
|
|
e88930 |
+ * @param nic - NIC device to close
|
|
|
e88930 |
+ * @param graceful - whether to wait to close gracefully
|
|
|
e88930 |
+ * @return 0 if successful, <0 if there is an error
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_close(nic_t *nic, NIC_SHUTDOWN_T graceful)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ /* Sanity Check: validate the parameters */
|
|
|
e88930 |
+ if (!nic) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: nic == NULL", __func__);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ if (!nic->priv) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: nic->priv == NULL", __func__);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_INFO(PFX "Closing NIC device: %s", nic->log_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_uio_close_resources(nic, graceful);
|
|
|
e88930 |
+ qedi_free(nic);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+static void qedi_prepare_xmit_packet(nic_t *nic,
|
|
|
e88930 |
+ nic_interface_t *nic_iface,
|
|
|
e88930 |
+ struct packet *pkt)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+ struct uip_vlan_eth_hdr *eth_vlan = (struct uip_vlan_eth_hdr *)pkt->buf;
|
|
|
e88930 |
+ struct uip_eth_hdr *eth = (struct uip_eth_hdr *)bp->tx_pkt;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (eth_vlan->tpid == htons(UIP_ETHTYPE_8021Q)) {
|
|
|
e88930 |
+ memcpy(bp->tx_pkt, pkt->buf, sizeof(struct uip_eth_hdr));
|
|
|
e88930 |
+ eth->type = eth_vlan->type;
|
|
|
e88930 |
+ pkt->buf_size -= (sizeof(struct uip_vlan_eth_hdr) -
|
|
|
e88930 |
+ sizeof(struct uip_eth_hdr));
|
|
|
e88930 |
+ memcpy(bp->tx_pkt + sizeof(struct uip_eth_hdr),
|
|
|
e88930 |
+ pkt->buf + sizeof(struct uip_vlan_eth_hdr),
|
|
|
e88930 |
+ pkt->buf_size - sizeof(struct uip_eth_hdr));
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ memcpy(bp->tx_pkt, pkt->buf, pkt->buf_size);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ msync(bp->tx_pkt, pkt->buf_size, MS_SYNC);
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_get_tx_pkt() - This function is used to a TX packet from the NIC
|
|
|
e88930 |
+ * @param nic - The NIC device to send the packet
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+void *qedi_get_tx_pkt(nic_t *nic)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return bp->tx_pkt;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_start_xmit() - This function is used to send a packet of data
|
|
|
e88930 |
+ * @param nic - The NIC device to send the packet
|
|
|
e88930 |
+ * @param len - the length of the TX packet
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+void qedi_start_xmit(nic_t *nic, size_t len, u16_t vlan_id)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+ uint8_t *ubuf;
|
|
|
e88930 |
+ struct iscsi_uevent *ev;
|
|
|
e88930 |
+ struct iscsi_path *path_data;
|
|
|
e88930 |
+ struct qedi_uio_ctrl *uctrl;
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+ uint16_t buflen;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ uctrl = (struct qedi_uio_ctrl *)bp->uctrl_map;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ buflen = sizeof(struct iscsi_uevent) + sizeof(struct iscsi_path);
|
|
|
e88930 |
+ ubuf = calloc(1, NLMSG_SPACE(buflen));
|
|
|
e88930 |
+ if (!ubuf) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: alloc failed for uevent buf", __func__);
|
|
|
e88930 |
+ return;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ memset(ubuf, 0, NLMSG_SPACE(buflen));
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* prepare the iscsi_uevent buffer */
|
|
|
e88930 |
+ ev = (struct iscsi_uevent *)ubuf;
|
|
|
e88930 |
+ ev->type = ISCSI_UEVENT_PATH_UPDATE;
|
|
|
e88930 |
+ ev->transport_handle = nic->transport_handle;
|
|
|
e88930 |
+ ev->u.set_path.host_no = nic->host_no;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Prepare the iscsi_path buffer */
|
|
|
e88930 |
+ path_data = (struct iscsi_path *)(ubuf + sizeof(struct iscsi_uevent));
|
|
|
e88930 |
+ path_data->handle = QEDI_PATH_HANDLE;
|
|
|
e88930 |
+ path_data->vlan_id = vlan_id;
|
|
|
e88930 |
+ uctrl->host_tx_pkt_len = len;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = __kipc_call(nl_sock, ev, buflen);
|
|
|
e88930 |
+ if (rc > 0) {
|
|
|
e88930 |
+ bp->tx_prod++;
|
|
|
e88930 |
+ uctrl->host_tx_prod++;
|
|
|
e88930 |
+ msync(uctrl, sizeof(struct qedi_uio_ctrl), MS_SYNC);
|
|
|
e88930 |
+ LOG_PACKET(PFX "%s: sent %d bytes using bp->tx_prod: %d",
|
|
|
e88930 |
+ nic->log_name, len, bp->tx_prod);
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ LOG_ERR(PFX "Pkt transmission failed: %d", rc);
|
|
|
e88930 |
+ pthread_mutex_unlock(&nic->xmit_mutex);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ free(ubuf);
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_write() - Used to write the data to the hardware
|
|
|
e88930 |
+ * @param nic - NIC hardware to read from
|
|
|
e88930 |
+ * @param pkt - The packet which will hold the data to be sent on the wire
|
|
|
e88930 |
+ * @return 0 if successful, <0 if failed
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+int qedi_write(nic_t *nic, nic_interface_t *nic_iface, packet_t *pkt)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp;
|
|
|
e88930 |
+ struct uip_stack *uip;
|
|
|
e88930 |
+ int i = 0;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Sanity Check: validate the parameters */
|
|
|
e88930 |
+ if (!nic || !nic_iface || !pkt) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: qedi_write() nic == 0x%p || nic_iface == 0x%p || pkt == 0x%x",
|
|
|
e88930 |
+ nic, nic_iface, pkt);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+ uip = &nic_iface->ustack;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (pkt->buf_size == 0) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Trying to transmitted 0 sized packet",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Try to wait for a TX completion */
|
|
|
e88930 |
+ for (i = 0; i < 15; i++) {
|
|
|
e88930 |
+ struct timespec sleep_req = {.tv_sec = 0, .tv_nsec = 5000000 },
|
|
|
e88930 |
+ sleep_rem;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (qedi_clear_tx_intr(nic) == 0)
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ nanosleep(&sleep_req, &sleep_rem);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (pthread_mutex_trylock(&nic->xmit_mutex) != 0) {
|
|
|
e88930 |
+ LOG_PACKET(PFX "%s: Dropped previous transmitted packet",
|
|
|
e88930 |
+ nic->log_name);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_prepare_xmit_packet(nic, nic_iface, pkt);
|
|
|
e88930 |
+ qedi_start_xmit(nic, pkt->buf_size,
|
|
|
e88930 |
+ (nic_iface->vlan_priority << 12) |
|
|
|
e88930 |
+ nic_iface->vlan_id);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* bump up the tx stats */
|
|
|
e88930 |
+ nic->stats.tx.packets++;
|
|
|
e88930 |
+ nic->stats.tx.bytes += uip->uip_len;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_PACKET(PFX "%s: transmitted %d bytes dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
|
|
|
e88930 |
+ nic->log_name, pkt->buf_size,
|
|
|
e88930 |
+ bp->tx_cons, bp->tx_prod, bp->tx_bd_prod);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_read() - Used to read the data from the hardware
|
|
|
e88930 |
+ * @param nic - NIC hardware to read from
|
|
|
e88930 |
+ * @param pkt - The packet which will hold the data
|
|
|
e88930 |
+ * @return 0 if successful, < 0 if failed
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int qedi_read(nic_t *nic, packet_t *pkt)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp;
|
|
|
e88930 |
+ void *rx_pkt;
|
|
|
e88930 |
+ int rc = 0;
|
|
|
e88930 |
+ uint32_t sw_cons, bd_cons;
|
|
|
e88930 |
+ uint32_t hw_prod;
|
|
|
e88930 |
+ uint32_t rx_pkt_idx;
|
|
|
e88930 |
+ int len;
|
|
|
e88930 |
+ struct qedi_rx_bd *rx_bd;
|
|
|
e88930 |
+ struct qedi_uio_ctrl *uctrl;
|
|
|
e88930 |
+ uint16_t vlan_id;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Sanity Check: validate the parameters */
|
|
|
e88930 |
+ if (!nic || !pkt) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: qedi_read() nic == 0x%p || pkt == 0x%x",
|
|
|
e88930 |
+ nic, pkt);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+ msync(bp->uctrl_map, sizeof(struct qedi_uio_ctrl), MS_SYNC);
|
|
|
e88930 |
+ msync(bp->rx_comp_ring, nic->page_size, MS_SYNC);
|
|
|
e88930 |
+ uctrl = (struct qedi_uio_ctrl *)bp->uctrl_map;
|
|
|
e88930 |
+ hw_prod = uctrl->hw_rx_prod;
|
|
|
e88930 |
+ sw_cons = uctrl->host_rx_cons;
|
|
|
e88930 |
+ bd_cons = uctrl->host_rx_bd_cons;
|
|
|
e88930 |
+ rx_bd = bp->rx_comp_ring + (bd_cons * sizeof(*rx_bd));
|
|
|
e88930 |
+ len = rx_bd->rx_pkt_len;
|
|
|
e88930 |
+ rx_pkt_idx = rx_bd->rx_pkt_index;
|
|
|
e88930 |
+ vlan_id = rx_bd->vlan_id;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (sw_cons != hw_prod) {
|
|
|
e88930 |
+ LOG_DEBUG(PFX "%s: clearing rx interrupt: %d %d",
|
|
|
e88930 |
+ nic->log_name, sw_cons, hw_prod);
|
|
|
e88930 |
+ rc = 1;
|
|
|
e88930 |
+ rx_pkt = bp->rx_pkts + (bp->rx_buffer_size * rx_pkt_idx);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (len > 0) {
|
|
|
e88930 |
+ msync(rx_pkt, len, MS_SYNC);
|
|
|
e88930 |
+ /* Copy the data */
|
|
|
e88930 |
+ memcpy(pkt->buf, rx_pkt, len);
|
|
|
e88930 |
+ pkt->buf_size = len;
|
|
|
e88930 |
+ if (vlan_id) {
|
|
|
e88930 |
+ pkt->vlan_tag = vlan_id;
|
|
|
e88930 |
+ pkt->flags |= VLAN_TAGGED;
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ pkt->vlan_tag = 0;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_DEBUG(PFX "%s: processing packet length: %d",
|
|
|
e88930 |
+ nic->log_name, len);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* bump up the recv stats */
|
|
|
e88930 |
+ nic->stats.rx.packets++;
|
|
|
e88930 |
+ nic->stats.rx.bytes += pkt->buf_size;
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ rc = 0;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ sw_cons = (sw_cons + 1) % RX_RING_SIZE;
|
|
|
e88930 |
+ bd_cons = (bd_cons + 1) % QEDI_NUM_RX_BD;
|
|
|
e88930 |
+ uctrl->host_rx_cons_cnt++;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ uctrl->host_rx_bd_cons = bd_cons;
|
|
|
e88930 |
+ uctrl->host_rx_cons = sw_cons;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ msync(uctrl, sizeof(struct qedi_uio_ctrl), MS_SYNC);
|
|
|
e88930 |
+ msync(bp->rx_comp_ring, nic->page_size, MS_SYNC);
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * Clearing TX interrupts
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+/**
|
|
|
e88930 |
+ * qedi_clear_tx_intr() - This routine is called when a TX interrupt occurs
|
|
|
e88930 |
+ * @param nic - the nic the interrupt occurred on
|
|
|
e88930 |
+ * @return 0 on success
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+
|
|
|
e88930 |
+static int qedi_clear_tx_intr(nic_t *nic)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ qedi_t *bp;
|
|
|
e88930 |
+ uint32_t hw_cons;
|
|
|
e88930 |
+ struct qedi_uio_ctrl *uctrl;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Sanity check: ensure the parameters passed in are valid */
|
|
|
e88930 |
+ if (unlikely(!nic)) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: nic == NULL", __func__);
|
|
|
e88930 |
+ return -EINVAL;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ bp = (qedi_t *)nic->priv;
|
|
|
e88930 |
+ uctrl = (struct qedi_uio_ctrl *)bp->uctrl_map;
|
|
|
e88930 |
+ msync(bp->uctrl_map, sizeof(struct qedi_uio_ctrl), MS_SYNC);
|
|
|
e88930 |
+ hw_cons = uctrl->hw_tx_cons;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (bp->tx_cons == hw_cons) {
|
|
|
e88930 |
+ if (bp->tx_cons == bp->tx_prod) {
|
|
|
e88930 |
+ /* Make sure the xmit_mutex lock is unlock */
|
|
|
e88930 |
+ if (pthread_mutex_trylock(&nic->xmit_mutex))
|
|
|
e88930 |
+ LOG_ERR(PFX "qedi tx lock with prod == cons");
|
|
|
e88930 |
+
|
|
|
e88930 |
+ pthread_mutex_unlock(&nic->xmit_mutex);
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ return -EAGAIN;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_PACKET(PFX "%s: clearing tx interrupt [%d %d]",
|
|
|
e88930 |
+ nic->log_name, bp->tx_cons, hw_cons);
|
|
|
e88930 |
+ bp->tx_cons = hw_cons;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* There is a queued TX packet that needs to be sent out. The usual
|
|
|
e88930 |
+ * case is when stack will send an ARP packet out before sending the
|
|
|
e88930 |
+ * intended packet
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ if (nic->tx_packet_queue) {
|
|
|
e88930 |
+ packet_t *pkt;
|
|
|
e88930 |
+ int i;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_PACKET(PFX "%s: sending queued tx packet", nic->log_name);
|
|
|
e88930 |
+ pkt = nic_dequeue_tx_packet(nic);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Got a TX packet buffer of the TX queue and put it onto
|
|
|
e88930 |
+ * the hardware
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+ if (pkt) {
|
|
|
e88930 |
+ qedi_prepare_xmit_packet(nic, pkt->nic_iface, pkt);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ qedi_start_xmit(nic, pkt->buf_size,
|
|
|
e88930 |
+ (pkt->nic_iface->vlan_priority << 12) |
|
|
|
e88930 |
+ pkt->nic_iface->vlan_id);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ LOG_PACKET(PFX "%s: transmitted queued packet %d bytes, dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
|
|
|
e88930 |
+ nic->log_name, pkt->buf_size,
|
|
|
e88930 |
+ bp->tx_cons, bp->tx_prod, bp->tx_bd_prod);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Try to wait for a TX completion */
|
|
|
e88930 |
+ for (i = 0; i < 15; i++) {
|
|
|
e88930 |
+ struct timespec sleep_req = {.tv_sec = 0,
|
|
|
e88930 |
+ .tv_nsec = 5000000
|
|
|
e88930 |
+ }, sleep_rem;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ hw_cons = uctrl->hw_tx_cons;
|
|
|
e88930 |
+ if (bp->tx_cons != hw_cons) {
|
|
|
e88930 |
+ LOG_PACKET(PFX
|
|
|
e88930 |
+ "%s: clearing tx interrupt [%d %d]",
|
|
|
e88930 |
+ nic->log_name, bp->tx_cons, hw_cons);
|
|
|
e88930 |
+ bp->tx_cons = hw_cons;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ nanosleep(&sleep_req, &sleep_rem);
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ pthread_mutex_unlock(&nic->xmit_mutex);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return 0;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/*******************************************************************************
|
|
|
e88930 |
+ * qedi NIC op's table
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+struct nic_ops qedi_op = {
|
|
|
e88930 |
+ .description = "qedi",
|
|
|
e88930 |
+ .open = qedi_open,
|
|
|
e88930 |
+ .close = qedi_close,
|
|
|
e88930 |
+ .write = qedi_write,
|
|
|
e88930 |
+ .get_tx_pkt = qedi_get_tx_pkt,
|
|
|
e88930 |
+ .start_xmit = qedi_start_xmit,
|
|
|
e88930 |
+ .read = qedi_read,
|
|
|
e88930 |
+ .clear_tx_intr = qedi_clear_tx_intr,
|
|
|
e88930 |
+ .handle_iscsi_path_req = cnic_handle_iscsi_path_req,
|
|
|
e88930 |
+
|
|
|
e88930 |
+ .lib_ops = {
|
|
|
e88930 |
+ .get_library_name = qedi_get_library_name,
|
|
|
e88930 |
+ .get_library_version = qedi_get_library_version,
|
|
|
e88930 |
+ .get_build_date = qedi_get_build_date,
|
|
|
e88930 |
+ .get_transport_name = qedi_get_transport_name,
|
|
|
e88930 |
+ .get_uio_name = qedi_get_uio_name,
|
|
|
e88930 |
+ },
|
|
|
e88930 |
+};
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/libs/qedi.h b/iscsiuio/src/unix/libs/qedi.h
|
|
|
e88930 |
new file mode 100644
|
|
|
e88930 |
index 000000000000..7e0140adb2ba
|
|
|
e88930 |
--- /dev/null
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/libs/qedi.h
|
|
|
e88930 |
@@ -0,0 +1,159 @@
|
|
|
e88930 |
+/*
|
|
|
e88930 |
+ * Copyright (c) 2016, Cavium Inc.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * All rights reserved.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * Redistribution and use in source and binary forms, with or without
|
|
|
e88930 |
+ * modification, are permitted provided that the following conditions
|
|
|
e88930 |
+ * are met:
|
|
|
e88930 |
+ * 1. Redistributions of source code must retain the above copyright
|
|
|
e88930 |
+ * notice, this list of conditions and the following disclaimer.
|
|
|
e88930 |
+ * 2. Redistributions in binary form must reproduce the above copyright
|
|
|
e88930 |
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
e88930 |
+ * documentation and/or other materials provided with the distribution.
|
|
|
e88930 |
+ * 3. All advertising materials mentioning features or use of this software
|
|
|
e88930 |
+ * must display the following acknowledgement:
|
|
|
e88930 |
+ * This product includes software developed by Adam Dunkels.
|
|
|
e88930 |
+ * 4. The name of the author may not be used to endorse or promote
|
|
|
e88930 |
+ * products derived from this software without specific prior
|
|
|
e88930 |
+ * written permission.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
|
|
e88930 |
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
e88930 |
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
e88930 |
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
e88930 |
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
e88930 |
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
|
|
e88930 |
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
e88930 |
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
e88930 |
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
e88930 |
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
e88930 |
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ * qedi.h - qedi user space driver
|
|
|
e88930 |
+ *
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+#ifndef __QEDI_H__
|
|
|
e88930 |
+#define __QEDI_H__
|
|
|
e88930 |
+
|
|
|
e88930 |
+#include "nic.h"
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define RX_RING_SIZE 15
|
|
|
e88930 |
+#define PKT_BUF_SIZE 0X400
|
|
|
e88930 |
+#define QEDI_PAGE_SIZE 4096
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define QEDI_UNKNOWN_MAJOR_VERSION -1
|
|
|
e88930 |
+#define QEDI_UNKNOWN_MINOR_VERSION -1
|
|
|
e88930 |
+#define QEDI_UNKNOWN_SUB_MINOR_VERSION -1
|
|
|
e88930 |
+struct qedi_driver_version {
|
|
|
e88930 |
+ uint16_t major;
|
|
|
e88930 |
+ uint16_t minor;
|
|
|
e88930 |
+ uint16_t sub_minor;
|
|
|
e88930 |
+};
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define QEDI_UCTRL_MAP_REG 0
|
|
|
e88930 |
+#define QEDI_RING_MAP_REG 1
|
|
|
e88930 |
+#define QEDI_BUF_MAP_REG 2
|
|
|
e88930 |
+#define UIO_ATTR_TMPL "/sys/class/uio/uio%u/maps/map%u/%s"
|
|
|
e88930 |
+#define UIO_ADDR_TMPL "/sys/class/uio/uio%u/maps/map%u/addr"
|
|
|
e88930 |
+#define UIO_OFFSET_TMPL "/sys/class/uio/uio%u/maps/map%u/offset"
|
|
|
e88930 |
+#define UIO_SIZE_TMPL "/sys/class/uio/uio%u/maps/map%u/size"
|
|
|
e88930 |
+
|
|
|
e88930 |
+struct qedi_uio_ctrl {
|
|
|
e88930 |
+ /* meta data */
|
|
|
e88930 |
+ __u32 uio_hsi_version;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* user writes */
|
|
|
e88930 |
+ __u32 host_tx_prod;
|
|
|
e88930 |
+ __u32 host_rx_cons;
|
|
|
e88930 |
+ __u32 host_rx_bd_cons;
|
|
|
e88930 |
+ __u32 host_tx_pkt_len;
|
|
|
e88930 |
+ __u32 host_rx_cons_cnt;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* driver writes */
|
|
|
e88930 |
+ __u32 hw_tx_cons;
|
|
|
e88930 |
+ __u32 hw_rx_prod;
|
|
|
e88930 |
+ __u32 hw_rx_bd_prod;
|
|
|
e88930 |
+ __u32 hw_rx_prod_cnt;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* other */
|
|
|
e88930 |
+ __u8 mac_addr[6];
|
|
|
e88930 |
+ __u8 reserve[2];
|
|
|
e88930 |
+};
|
|
|
e88930 |
+
|
|
|
e88930 |
+struct qedi_rx_bd {
|
|
|
e88930 |
+ __u32 rx_pkt_index;
|
|
|
e88930 |
+ __u32 rx_pkt_len;
|
|
|
e88930 |
+ __u16 vlan_id;
|
|
|
e88930 |
+};
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define QEDI_RX_DESC_CNT (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
|
|
|
e88930 |
+#define QEDI_MAX_RX_DESC_CNT (QEDI_RX_DESC_CNT - 1)
|
|
|
e88930 |
+#define QEDI_NUM_RX_BD (QEDI_RX_DESC_CNT * 1)
|
|
|
e88930 |
+#define QEDI_MAX_RX_BD (QEDI_NUM_RX_BD - 1)
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
|
|
|
e88930 |
+ (QEDI_MAX_RX_DESC_CNT - 1)) ? \
|
|
|
e88930 |
+ (x) + 2 : (x) + 1)
|
|
|
e88930 |
+
|
|
|
e88930 |
+#define QEDI_PATH_HANDLE 0xFE0000000
|
|
|
e88930 |
+
|
|
|
e88930 |
+typedef struct qedi {
|
|
|
e88930 |
+ nic_t *parent;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ struct qedi_driver_version version;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ uint16_t flags;
|
|
|
e88930 |
+#define CNIC_UIO_UNITIALIZED 0x0001
|
|
|
e88930 |
+#define CNIC_UIO_INITIALIZED 0x0002
|
|
|
e88930 |
+#define CNIC_UIO_ENABLED 0x0004
|
|
|
e88930 |
+#define CNIC_UIO_DISABLED 0x0008
|
|
|
e88930 |
+#define CNIC_UIO_IPv6_ENABLED 0x0010
|
|
|
e88930 |
+#define CNIC_UIO_ADDED_MULICAST 0x0020
|
|
|
e88930 |
+#define CNIC_UIO_MSIX_ENABLED 0x0200
|
|
|
e88930 |
+#define CNIC_UIO_TX_HAS_SENT 0x0400
|
|
|
e88930 |
+#define QEDI_OPENED 0x0800
|
|
|
e88930 |
+
|
|
|
e88930 |
+ __u32 chip_id;
|
|
|
e88930 |
+ int func;
|
|
|
e88930 |
+ int port;
|
|
|
e88930 |
+ int pfid;
|
|
|
e88930 |
+ __u32 cid;
|
|
|
e88930 |
+ __u32 client_id;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ __u32 tx_prod;
|
|
|
e88930 |
+ __u32 tx_bd_prod;
|
|
|
e88930 |
+ __u32 tx_cons;
|
|
|
e88930 |
+ __u8 tx_vlan_tag_bit;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ __u32 rx_prod;
|
|
|
e88930 |
+ __u32 rx_bd_prod;
|
|
|
e88930 |
+ __u32 rx_cons;
|
|
|
e88930 |
+ __u32 rx_bd_cons;
|
|
|
e88930 |
+ __u32 rx_hw_prod;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ __u32 (*get_rx_cons)(struct qedi *);
|
|
|
e88930 |
+ __u32 (*get_tx_cons)(struct qedi *);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* RX ring parameters */
|
|
|
e88930 |
+ uint32_t rx_ring_size;
|
|
|
e88930 |
+ uint32_t rx_buffer_size;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ void *bufs; /* Pointer to the mapped buffer space */
|
|
|
e88930 |
+ void *uctrl_map; /* UIO control structure */
|
|
|
e88930 |
+ uint32_t uctrl_map_offset; /* UIO control structure mmap offset */
|
|
|
e88930 |
+
|
|
|
e88930 |
+ uint32_t rx_index;
|
|
|
e88930 |
+ void *rx_comp_ring;
|
|
|
e88930 |
+ void **rx_pkt_ring;
|
|
|
e88930 |
+ void *tx_pkt;
|
|
|
e88930 |
+ void *rx_pkts;
|
|
|
e88930 |
+} qedi_t;
|
|
|
e88930 |
+
|
|
|
e88930 |
+/******************************************************************************
|
|
|
e88930 |
+ * qedi Function Declarations
|
|
|
e88930 |
+ ******************************************************************************/
|
|
|
e88930 |
+void qedi_start_xmit(nic_t *nic, size_t len, u16_t vlan_id);
|
|
|
e88930 |
+struct nic_ops *qedi_get_ops();
|
|
|
e88930 |
+
|
|
|
e88930 |
+#endif /* __QEDI_H__ */
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/nic.c b/iscsiuio/src/unix/nic.c
|
|
|
e88930 |
index 8825f00b7216..a5f714a91923 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/nic.c
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/nic.c
|
|
|
e88930 |
@@ -65,6 +65,7 @@
|
|
|
e88930 |
|
|
|
e88930 |
#include "bnx2.h"
|
|
|
e88930 |
#include "bnx2x.h"
|
|
|
e88930 |
+#include "qedi.h"
|
|
|
e88930 |
#include "ipv6.h"
|
|
|
e88930 |
|
|
|
e88930 |
/******************************************************************************
|
|
|
e88930 |
@@ -180,7 +181,7 @@ error:
|
|
|
e88930 |
}
|
|
|
e88930 |
|
|
|
e88930 |
static struct nic_ops *(*nic_get_ops[]) () = {
|
|
|
e88930 |
-bnx2_get_ops, bnx2x_get_ops,};
|
|
|
e88930 |
+bnx2_get_ops, bnx2x_get_ops, qedi_get_ops};
|
|
|
e88930 |
|
|
|
e88930 |
int load_all_nic_libraries()
|
|
|
e88930 |
{
|
|
|
e88930 |
@@ -404,6 +405,7 @@ nic_t *nic_init()
|
|
|
e88930 |
memset(nic, 0, sizeof(*nic));
|
|
|
e88930 |
nic->uio_minor = -1;
|
|
|
e88930 |
nic->fd = INVALID_FD;
|
|
|
e88930 |
+ nic->host_no = INVALID_HOST_NO;
|
|
|
e88930 |
nic->next = NULL;
|
|
|
e88930 |
nic->thread = INVALID_THREAD;
|
|
|
e88930 |
nic->enable_thread = INVALID_THREAD;
|
|
|
e88930 |
@@ -1070,6 +1072,8 @@ int process_packets(nic_t *nic,
|
|
|
e88930 |
}
|
|
|
e88930 |
nic_iface_present:
|
|
|
e88930 |
pkt->nic_iface = nic_iface;
|
|
|
e88930 |
+ LOG_DEBUG(PFX "%s: found nic iface, type=0x%x, bufsize=%d",
|
|
|
e88930 |
+ nic->log_name, type, pkt->buf_size);
|
|
|
e88930 |
|
|
|
e88930 |
ustack = &nic_iface->ustack;
|
|
|
e88930 |
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/nic.h b/iscsiuio/src/unix/nic.h
|
|
|
e88930 |
index ec157815a375..2c41e6e3c25a 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/nic.h
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/nic.h
|
|
|
e88930 |
@@ -334,6 +334,7 @@ typedef struct nic {
|
|
|
e88930 |
|
|
|
e88930 |
/* The thread used to perform ping */
|
|
|
e88930 |
pthread_t ping_thread;
|
|
|
e88930 |
+ uint64_t transport_handle;
|
|
|
e88930 |
} nic_t;
|
|
|
e88930 |
|
|
|
e88930 |
/******************************************************************************
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/nic_utils.c b/iscsiuio/src/unix/nic_utils.c
|
|
|
e88930 |
index 0daffd2fcb6d..6e580f862eea 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/nic_utils.c
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/nic_utils.c
|
|
|
e88930 |
@@ -81,6 +81,10 @@ static const char iscsi_host_path_netdev_template[] =
|
|
|
e88930 |
"/sys/class/iscsi_host/host%d/netdev";
|
|
|
e88930 |
static const char cnic_uio_sysfs_resc_template[] =
|
|
|
e88930 |
"/sys/class/uio/uio%i/device/resource%i";
|
|
|
e88930 |
+static const char iscsi_transport_handle_template[] =
|
|
|
e88930 |
+ "/sys/class/iscsi_transport/%s/handle";
|
|
|
e88930 |
+static const char eth_pfx[] = "eth";
|
|
|
e88930 |
+static const char host_pfx[] = "host";
|
|
|
e88930 |
|
|
|
e88930 |
/**
|
|
|
e88930 |
* manually_trigger_uio_event() - If the uio file node doesn't exist then
|
|
|
e88930 |
@@ -250,6 +254,7 @@ int nic_discover_iscsi_hosts()
|
|
|
e88930 |
strncpy(nic->eth_device_name, raw, raw_size);
|
|
|
e88930 |
nic->config_device_name = nic->eth_device_name;
|
|
|
e88930 |
nic->log_name = nic->eth_device_name;
|
|
|
e88930 |
+ nic->host_no = host_no;
|
|
|
e88930 |
|
|
|
e88930 |
if (nic_fill_name(nic) != 0) {
|
|
|
e88930 |
free(nic);
|
|
|
e88930 |
@@ -557,6 +562,102 @@ error:
|
|
|
e88930 |
}
|
|
|
e88930 |
|
|
|
e88930 |
/**
|
|
|
e88930 |
+ * from_uio_find_associated_host() - Given the uio minor number
|
|
|
e88930 |
+ * this function will try to find the assoicated iscsi host
|
|
|
e88930 |
+ * @param uio_minor - minor number of the UIO device
|
|
|
e88930 |
+ * @param name - char buffer which will be filled if successful
|
|
|
e88930 |
+ * @param name_size - size of the name buffer
|
|
|
e88930 |
+ * @return >0 minor number <0 an error
|
|
|
e88930 |
+ */
|
|
|
e88930 |
+static int from_uio_find_associated_host(nic_t *nic, int uio_minor,
|
|
|
e88930 |
+ char *name, size_t name_size)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ char *path;
|
|
|
e88930 |
+ int rc;
|
|
|
e88930 |
+ int count;
|
|
|
e88930 |
+ struct dirent **files;
|
|
|
e88930 |
+ char *parsed_name;
|
|
|
e88930 |
+ int i;
|
|
|
e88930 |
+ int path_iterator;
|
|
|
e88930 |
+ char *search_paths[] = { "/sys/class/uio/uio%i/device/" };
|
|
|
e88930 |
+ int path_to[] = { 5, 1 };
|
|
|
e88930 |
+ int (*search_filters[]) (const struct dirent *) = { filter_host_name, };
|
|
|
e88930 |
+ char *(*extract_name[]) (struct dirent **files) = { extract_none, };
|
|
|
e88930 |
+ int extract_name_offset[] = { 0 };
|
|
|
e88930 |
+
|
|
|
e88930 |
+ path = malloc(PATH_MAX);
|
|
|
e88930 |
+ if (!path) {
|
|
|
e88930 |
+ LOG_ERR(PFX "Could not allocate memory for path");
|
|
|
e88930 |
+ rc = -ENOMEM;
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ for (path_iterator = 0;
|
|
|
e88930 |
+ path_iterator < sizeof(search_paths) / sizeof(search_paths[0]);
|
|
|
e88930 |
+ path_iterator++) {
|
|
|
e88930 |
+ /* Build the path to determine uio name */
|
|
|
e88930 |
+ rc = sprintf(path, search_paths[path_iterator], uio_minor);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ wait_for_file_node_timed(nic, path, path_to[path_iterator]);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ count = scandir(path, &files,
|
|
|
e88930 |
+ search_filters[path_iterator], alphasort);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ switch (count) {
|
|
|
e88930 |
+ case 1:
|
|
|
e88930 |
+ parsed_name = (*extract_name[path_iterator]) (files);
|
|
|
e88930 |
+ if (!parsed_name) {
|
|
|
e88930 |
+ LOG_WARN(PFX "Couldn't find delimiter in: %s",
|
|
|
e88930 |
+ files[0]->d_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ strncpy(name,
|
|
|
e88930 |
+ parsed_name +
|
|
|
e88930 |
+ extract_name_offset[path_iterator], name_size);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ free(files[0]);
|
|
|
e88930 |
+ free(files);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = 0;
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ case 0:
|
|
|
e88930 |
+ rc = -EINVAL;
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ case -1:
|
|
|
e88930 |
+ LOG_WARN(PFX "Error when scanning path: %s[%s]",
|
|
|
e88930 |
+ path, strerror(errno));
|
|
|
e88930 |
+ rc = -EINVAL;
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ default:
|
|
|
e88930 |
+ LOG_WARN(PFX
|
|
|
e88930 |
+ "Too many entries when looking for device: %s",
|
|
|
e88930 |
+ path);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Cleanup the scandir() call */
|
|
|
e88930 |
+ for (i = 0; i < count; i++)
|
|
|
e88930 |
+ free(files[i]);
|
|
|
e88930 |
+ free(files);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = -EINVAL;
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ if (rc == 0)
|
|
|
e88930 |
+ break;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+error:
|
|
|
e88930 |
+ free(path);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+/**
|
|
|
e88930 |
* filter_uio_name() - This is the callback used by scandir when looking for
|
|
|
e88930 |
* the number of uio entries
|
|
|
e88930 |
*/
|
|
|
e88930 |
@@ -652,10 +753,16 @@ int from_phys_name_find_assoicated_uio_device(nic_t *nic)
|
|
|
e88930 |
continue;
|
|
|
e88930 |
}
|
|
|
e88930 |
|
|
|
e88930 |
- rc = from_uio_find_associated_eth_device(nic,
|
|
|
e88930 |
- uio_minor,
|
|
|
e88930 |
- eth_name,
|
|
|
e88930 |
- sizeof(eth_name));
|
|
|
e88930 |
+ if (!memcmp(host_pfx, nic->config_device_name,
|
|
|
e88930 |
+ strlen(host_pfx))) {
|
|
|
e88930 |
+ rc = from_uio_find_associated_host(nic, uio_minor,
|
|
|
e88930 |
+ eth_name,
|
|
|
e88930 |
+ sizeof(eth_name));
|
|
|
e88930 |
+ } else {
|
|
|
e88930 |
+ rc = from_uio_find_associated_eth_device(nic, uio_minor,
|
|
|
e88930 |
+ eth_name,
|
|
|
e88930 |
+ sizeof(eth_name));
|
|
|
e88930 |
+ }
|
|
|
e88930 |
if (rc != 0) {
|
|
|
e88930 |
LOG_WARN("uio minor: %d not valid [%D]", uio_minor, rc);
|
|
|
e88930 |
continue;
|
|
|
e88930 |
@@ -1124,6 +1231,38 @@ int detemine_initial_uio_events(nic_t *nic, uint32_t *num_of_events)
|
|
|
e88930 |
|
|
|
e88930 |
rc = 0;
|
|
|
e88930 |
error:
|
|
|
e88930 |
+ if (raw)
|
|
|
e88930 |
+ free(raw);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ return rc;
|
|
|
e88930 |
+}
|
|
|
e88930 |
+
|
|
|
e88930 |
+int get_iscsi_transport_handle(nic_t *nic, uint64_t *handle)
|
|
|
e88930 |
+{
|
|
|
e88930 |
+ char *raw = NULL;
|
|
|
e88930 |
+ uint32_t raw_size = 0;
|
|
|
e88930 |
+ ssize_t elements_read;
|
|
|
e88930 |
+ char temp_path[sizeof(iscsi_transport_handle_template) + 8];
|
|
|
e88930 |
+ int rc;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ /* Capture RX buffer size */
|
|
|
e88930 |
+ snprintf(temp_path, sizeof(temp_path),
|
|
|
e88930 |
+ iscsi_transport_handle_template, nic->library_name);
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = capture_file(&raw, &raw_size, temp_path);
|
|
|
e88930 |
+ if (rc != 0)
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+
|
|
|
e88930 |
+ elements_read = sscanf(raw, "%lu", handle);
|
|
|
e88930 |
+ if (elements_read != 1) {
|
|
|
e88930 |
+ LOG_ERR(PFX "%s: Couldn't parse transport handle from %s",
|
|
|
e88930 |
+ nic->log_name, temp_path);
|
|
|
e88930 |
+ rc = -EIO;
|
|
|
e88930 |
+ goto error;
|
|
|
e88930 |
+ }
|
|
|
e88930 |
+
|
|
|
e88930 |
+ rc = 0;
|
|
|
e88930 |
+error:
|
|
|
e88930 |
if (raw != NULL)
|
|
|
e88930 |
free(raw);
|
|
|
e88930 |
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/nic_utils.h b/iscsiuio/src/unix/nic_utils.h
|
|
|
e88930 |
index d5c1b580f340..e4cf5c13177e 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/nic_utils.h
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/nic_utils.h
|
|
|
e88930 |
@@ -99,4 +99,6 @@ void dump_packet_to_log(struct nic_interface *iface,
|
|
|
e88930 |
int determine_file_size_read(const char *filepath);
|
|
|
e88930 |
int capture_file(char **raw, uint32_t *raw_size, const char *path);
|
|
|
e88930 |
|
|
|
e88930 |
+int get_iscsi_transport_handle(nic_t *nic, uint64_t *handle);
|
|
|
e88930 |
+
|
|
|
e88930 |
#endif /* __NIC_UTILS_H__ */
|
|
|
e88930 |
diff --git a/iscsiuio/src/unix/options.h b/iscsiuio/src/unix/options.h
|
|
|
e88930 |
index df03255f7a87..63b86357aafa 100644
|
|
|
e88930 |
--- a/iscsiuio/src/unix/options.h
|
|
|
e88930 |
+++ b/iscsiuio/src/unix/options.h
|
|
|
e88930 |
@@ -87,6 +87,7 @@
|
|
|
e88930 |
|
|
|
e88930 |
#define INVALID_FD -1
|
|
|
e88930 |
#define INVALID_THREAD -1
|
|
|
e88930 |
+#define INVALID_HOST_NO -1
|
|
|
e88930 |
|
|
|
e88930 |
struct options {
|
|
|
e88930 |
char debug;
|
|
|
e88930 |
--
|
|
|
e88930 |
2.9.3
|
|
|
e88930 |
|