Follow new design patters, fix a return bug
Change-Id: Ia1dcccfcf7120355654a8a2315f26c6e3b819ff6
Signed-off-by: Sol Kavy <skavy@codeaurora.org>
diff --git a/nss_lag.c b/nss_lag.c
new file mode 100755
index 0000000..a39bd36
--- /dev/null
+++ b/nss_lag.c
@@ -0,0 +1,68 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2014, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+/*
+ * nss_tx_rx_lag.c
+ * NSS LAG Tx APIs
+ */
+
+#include <linux/if_bonding.h>
+
+#include "nss_tx_rx_common.h"
+
+/*
+ * nss_lag_tx()
+ * Transmit a LAG msg to the firmware.
+ */
+nss_tx_status_t nss_lag_tx(struct nss_ctx_instance *nss_ctx, struct nss_lag_msg *msg)
+{
+ struct sk_buff *nbuf;
+ int32_t status;
+ struct nss_lag_msg *nm;
+
+ nss_info("%p: NSS LAG Tx\n", nss_ctx);
+
+ NSS_VERIFY_CTX_MAGIC(nss_ctx);
+ if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
+ nss_warning("%p: LAG msg dropped as core not ready", nss_ctx);
+ return NSS_TX_FAILURE_NOT_READY;
+ }
+
+ nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
+ if (unlikely(!nbuf)) {
+ spin_lock_bh(&nss_ctx->nss_top->stats_lock);
+ nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
+ spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
+ nss_warning("%p: LAG msg dropped as command allocation failed", nss_ctx);
+ return NSS_TX_FAILURE;
+ }
+
+ nm = (struct nss_lag_msg *)skb_put(nbuf, sizeof(struct nss_lag_msg));
+ memcpy(nm, msg, sizeof(struct nss_lag_msg));
+
+ status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
+ if (status != NSS_CORE_STATUS_SUCCESS) {
+ dev_kfree_skb_any(nbuf);
+ nss_warning("%p: Unable to enqueue LAG msg\n", nss_ctx);
+ return NSS_TX_FAILURE;
+ }
+ nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
+ NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
+
+ NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
+ return NSS_TX_SUCCESS;
+}
+EXPORT_SYMBOL(nss_lag_tx);