[openib-general] [PATCH 2/10] Driver netpath files - abstraction of connection to VEx
Ramachandra K
rkuchimanchi at silverstorm.com
Mon Oct 2 13:03:55 PDT 2006
Adds the driver netpath files. These files implement
the netpath layer. Netpath is an an abstraction of a connection
to the VEx.
Signed-off-by: Ramachandra K <rkuchimanchi at silverstorm.com>
---
drivers/infiniband/ulp/vnic/vnic_netpath.c | 250 ++++++++++++++++++++++++++++
drivers/infiniband/ulp/vnic/vnic_netpath.h | 103 ++++++++++++
2 files changed, 353 insertions(+), 0 deletions(-)
diff --git a/drivers/infiniband/ulp/vnic/vnic_netpath.c b/drivers/infiniband/ulp/vnic/vnic_netpath.c
new file mode 100644
index 0000000..e02d602
--- /dev/null
+++ b/drivers/infiniband/ulp/vnic/vnic_netpath.c
@@ -0,0 +1,250 @@
+/*
+ * Copyright (c) 2006 SilverStorm Technologies Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <linux/netdevice.h>
+#include <linux/skbuff.h>
+
+#include "vnic_util.h"
+#include "vnic_main.h"
+#include "vnic_viport.h"
+#include "vnic_netpath.h"
+
+void netpath_init(struct netpath *netpath, struct vnic *vnic, int second_bias)
+{
+ netpath->parent = vnic;
+ netpath->carrier = 0;
+ netpath->viport = NULL;
+ netpath->second_bias = second_bias;
+ netpath->timer_state = NETPATH_TS_IDLE;
+ init_timer(&netpath->timer);
+ return;
+}
+
+void vnic_npevent_timeout(unsigned long data)
+{
+ struct netpath *netpath = (struct netpath *)data;
+ vnic_npevent_queue_evt(netpath, VNICNP_TIMEREXPIRED);
+}
+
+void netpath_timer(struct netpath *netpath, int timeout)
+{
+ if (netpath->timer_state == NETPATH_TS_ACTIVE) {
+ del_timer_sync(&netpath->timer);
+ }
+ if (timeout) {
+ init_timer(&netpath->timer);
+ netpath->timer_state = NETPATH_TS_ACTIVE;
+ netpath->timer.expires = jiffies + timeout;
+ netpath->timer.data = (unsigned long)netpath;
+ netpath->timer.function = vnic_npevent_timeout;
+ add_timer(&netpath->timer);
+ } else {
+ vnic_npevent_timeout((unsigned long)netpath);
+ }
+ return;
+}
+
+void netpath_timer_stop(struct netpath *netpath)
+{
+ if (netpath->timer_state == NETPATH_TS_ACTIVE) {
+ del_timer_sync(&netpath->timer);
+ vnic_npevent_dequeue_evt(netpath, VNICNP_TIMEREXPIRED);
+ netpath->timer_state = NETPATH_TS_IDLE;
+ }
+}
+
+void netpath_free(struct netpath *netpath)
+{
+ if (netpath->viport) {
+ netpath_remove_path(netpath, netpath->viport);
+ class_device_unregister(&netpath->class_dev_info.class_dev);
+ wait_for_completion(&netpath->class_dev_info.released);
+ }
+
+ return;
+}
+
+BOOLEAN netpath_add_path(struct netpath * netpath, struct viport * viport)
+{
+ if (netpath->viport) {
+ return FALSE;
+ } else {
+ netpath->viport = viport;
+ viport_set_parent(viport, netpath);
+ return TRUE;
+ }
+}
+
+BOOLEAN netpath_remove_path(struct netpath * netpath, struct viport * viport)
+{
+ if (netpath->viport != viport) {
+ return FALSE;
+ } else {
+ netpath->viport = NULL;
+ viport_unset_parent(viport, netpath);
+ return TRUE;
+ }
+}
+
+void netpath_connected(struct netpath *netpath, struct viport *viport)
+{
+ vnic_connected(netpath->parent, netpath);
+ return;
+}
+
+void netpath_disconnected(struct netpath *netpath, struct viport *viport)
+{
+ vnic_disconnected(netpath->parent, netpath);
+ return;
+}
+
+BOOLEAN netpath_set_link(struct netpath * netpath, u16 flags, u16 mtu)
+{
+ BOOLEAN ret = FALSE;
+
+ NETPATH_INFO("set %s receiver=%s. mtu=%d\n",
+ netpath_to_string(netpath->parent, netpath),
+ (flags & IFF_UP) ? "ON" : "OFF", mtu);
+ if (netpath->viport) {
+ ret = viport_set_link(netpath->viport, flags, mtu);
+ }
+ return ret;
+}
+
+BOOLEAN netpath_get_stats(struct netpath * netpath,
+ struct net_device_stats * stats)
+{
+ BOOLEAN ret = FALSE;
+
+ if (netpath->viport) {
+ ret = viport_get_stats(netpath->viport, stats);
+ }
+ return ret;
+}
+
+BOOLEAN netpath_set_unicast(struct netpath * netpath, u8 * address)
+{
+ BOOLEAN ret = FALSE;
+
+ NETPATH_INFO("set %s MAC to %02X:%02X:%02X:%02X:%02X:%02X\n",
+ netpath_to_string(netpath->parent, netpath),
+ address[0],
+ address[1],
+ address[2], address[3], address[4], address[5]);
+ if (netpath->viport) {
+ ret = viport_set_unicast(netpath->viport, address);
+ }
+ return ret;
+}
+
+BOOLEAN netpath_set_multicast(struct netpath * netpath,
+ struct dev_mc_list * mc_list, int mc_count)
+{
+ BOOLEAN ret = FALSE;
+
+ if (netpath->viport) {
+ ret = viport_set_multicast(netpath->viport, mc_list, mc_count);
+ }
+ return ret;
+}
+
+int netpath_max_mtu(struct netpath *netpath)
+{
+ int ret = MAX_PARAM_VALUE;
+
+ if (netpath->viport) {
+ ret = viport_max_mtu(netpath->viport);
+ }
+ return ret;
+}
+
+BOOLEAN netpath_xmit_packet(struct netpath * netpath, struct sk_buff * skb)
+{
+ BOOLEAN ret = FALSE;
+ if (netpath->viport) {
+ ret = viport_xmit_packet(netpath->viport, skb);
+ }
+ return ret;
+}
+
+void netpath_link_up(struct netpath *netpath, struct viport *viport)
+{
+ vnic_link_up(netpath->parent, netpath);
+ return;
+}
+
+void netpath_link_down(struct netpath *netpath, struct viport *viport)
+{
+ vnic_link_down(netpath->parent, netpath);
+ return;
+}
+
+void netpath_stop_xmit(struct netpath *netpath, struct viport *viport)
+{
+ vnic_stop_xmit(netpath->parent, netpath);
+ return;
+}
+
+void netpath_restart_xmit(struct netpath *netpath, struct viport *viport)
+{
+ vnic_restart_xmit(netpath->parent, netpath);
+ return;
+}
+
+
+/* viport on input calls this */
+void netpath_recv_packet(struct netpath *netpath, struct sk_buff *skb)
+{
+
+ vnic_recv_packet(netpath->parent, netpath, skb);
+ return;
+}
+
+void netpath_tx_timeout(struct netpath *netpath)
+{
+ if (netpath->viport) {
+ viport_failure(netpath->viport);
+ }
+}
+
+const char *netpath_to_string(struct vnic *vnic, struct netpath *netpath)
+{
+ if (!netpath) {
+ return "NULL";
+ } else if (netpath == &vnic->primary_path) {
+ return "PRIMARY";
+ } else if (netpath == &vnic->secondary_path) {
+ return "SECONDARY";
+ } else {
+ return "UNKNOWN";
+ }
+}
diff --git a/drivers/infiniband/ulp/vnic/vnic_netpath.h b/drivers/infiniband/ulp/vnic/vnic_netpath.h
new file mode 100644
index 0000000..707e3a1
--- /dev/null
+++ b/drivers/infiniband/ulp/vnic/vnic_netpath.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2006 SilverStorm Technologies Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#ifndef VNIC_NETPATH_H_INCLUDED
+#define VNIC_NETPATH_H_INCLUDED
+
+#include <linux/spinlock.h>
+
+#include "vnic_sys.h"
+
+struct viport;
+
+enum netpath_ts {
+ NETPATH_TS_IDLE,
+ NETPATH_TS_ACTIVE,
+ NETPATH_TS_EXPIRED
+};
+
+struct netpath {
+ int carrier;
+ struct vnic *parent;
+ struct viport *viport;
+ size_t path_idx;
+ u32 connect_time;
+ int second_bias;
+ struct timer_list timer;
+ enum netpath_ts timer_state;
+ struct class_dev_info class_dev_info;
+};
+
+void netpath_init(struct netpath *netpath, struct vnic *vnic, int second_bias);
+void netpath_free(struct netpath *netpath);
+
+BOOLEAN netpath_add_path(struct netpath *netpath, struct viport *viport);
+BOOLEAN netpath_remove_path(struct netpath *netpath, struct viport *viport);
+
+void netpath_connected(struct netpath *netpath, struct viport *viport);
+void netpath_disconnected(struct netpath *netpath, struct viport *viport);
+
+BOOLEAN netpath_set_link(struct netpath *netpath, u16 flags, u16 mtu);
+BOOLEAN netpath_get_stats(struct netpath *netpath,
+ struct net_device_stats *stats);
+
+BOOLEAN netpath_set_unicast(struct netpath *netpath, u8 * address);
+BOOLEAN netpath_set_multicast(struct netpath *netpath,
+ struct dev_mc_list *mc_list, int mc_count);
+
+int netpath_max_mtu(struct netpath *netpath);
+
+BOOLEAN netpath_xmit_packet(struct netpath *netpath, struct sk_buff *skb);
+
+void netpath_link_up(struct netpath *netpath, struct viport *viport);
+void netpath_link_down(struct netpath *netpath, struct viport *viport);
+
+void netpath_stop_xmit(struct netpath *netpath, struct viport *viport);
+void netpath_restart_xmit(struct netpath *netpath, struct viport *viport);
+
+void netpath_recv_packet(struct netpath *netpath, struct sk_buff *skb);
+
+void netpath_kick(struct netpath *netpath);
+
+void netpath_timer(struct netpath *netpath, int timeout);
+void netpath_timer_stop(struct netpath *netpath);
+
+void netpath_tx_timeout(struct netpath *netpath);
+
+const char *netpath_to_string(struct vnic *vnic, struct netpath *netpath);
+
+#define netpath_get_hw_addr(netpath, address) \
+ viport_get_hw_addr((netpath)->viport, address)
+#define netpath_is_connected(netpath) (netpath->state == NETPATH_CONNECTED)
+#define netpath_can_tx_csum(netpath) viport_can_tx_csum(netpath->viport)
+
+#endif /* VNIC_NETPATH_H_INCLUDED */
More information about the general
mailing list