blob: 772c6c8a1a420510fe97ef2590162aa70290067c [file] [log] [blame]
Tushar Mathur66506542014-04-03 22:01:40 +05301/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Tushar Mathur66506542014-04-03 22:01:40 +05304 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all copies.
7 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
13 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14 **************************************************************************
15 */
16
17/*
18 * nss_tx_rx_lag.c
19 * NSS LAG Tx APIs
20 */
21
22#include <linux/if_bonding.h>
23
24#include "nss_tx_rx_common.h"
25
26/*
27 * nss_lag_tx()
Sol Kavycd1bd5c2014-04-04 11:09:44 -070028 * Transmit a LAG msg to the firmware.
Tushar Mathur66506542014-04-03 22:01:40 +053029 */
30nss_tx_status_t nss_lag_tx(struct nss_ctx_instance *nss_ctx, struct nss_lag_msg *msg)
31{
32 struct sk_buff *nbuf;
33 int32_t status;
34 struct nss_lag_msg *nm;
35
36 nss_info("%p: NSS LAG Tx\n", nss_ctx);
37
38 NSS_VERIFY_CTX_MAGIC(nss_ctx);
39 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
Sol Kavycd1bd5c2014-04-04 11:09:44 -070040 nss_warning("%p: LAG msg dropped as core not ready", nss_ctx);
Tushar Mathur66506542014-04-03 22:01:40 +053041 return NSS_TX_FAILURE_NOT_READY;
42 }
43
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053044 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Tushar Mathur66506542014-04-03 22:01:40 +053045 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -080046 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Sol Kavycd1bd5c2014-04-04 11:09:44 -070047 nss_warning("%p: LAG msg dropped as command allocation failed", nss_ctx);
Tushar Mathur66506542014-04-03 22:01:40 +053048 return NSS_TX_FAILURE;
49 }
50
51 nm = (struct nss_lag_msg *)skb_put(nbuf, sizeof(struct nss_lag_msg));
52 memcpy(nm, msg, sizeof(struct nss_lag_msg));
53
54 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
55 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +053056 dev_kfree_skb_any(nbuf);
Sol Kavycd1bd5c2014-04-04 11:09:44 -070057 nss_warning("%p: Unable to enqueue LAG msg\n", nss_ctx);
58 return NSS_TX_FAILURE;
Tushar Mathur66506542014-04-03 22:01:40 +053059 }
Stephen Wang90c67de2016-04-26 15:15:59 -070060 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Tushar Mathur66506542014-04-03 22:01:40 +053061
62 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
63 return NSS_TX_SUCCESS;
64}
65EXPORT_SYMBOL(nss_lag_tx);
Tushar Mathura3e03052014-04-07 20:17:28 +053066
67/**
68 * nss_register_lag_if()
69 */
Gareth Williamsb52af512014-04-25 19:31:15 +010070void *nss_register_lag_if(uint32_t if_num,
Tushar Mathura3e03052014-04-07 20:17:28 +053071 nss_lag_callback_t lag_cb,
72 nss_lag_event_callback_t lag_ev_cb,
73 struct net_device *netdev)
74{
Sundarajan Srinivasan70374842014-11-19 15:22:52 -080075 uint32_t features = 0;
76
Suman Ghoshcf8ed1c2015-09-07 18:57:04 +053077 nss_assert((if_num == NSS_LAG0_INTERFACE_NUM) || (if_num == NSS_LAG1_INTERFACE_NUM) ||
78 (if_num == NSS_LAG2_INTERFACE_NUM) || (if_num == NSS_LAG3_INTERFACE_NUM));
Tushar Mathura3e03052014-04-07 20:17:28 +053079
Sundarajan Srinivasan70374842014-11-19 15:22:52 -080080 nss_top_main.subsys_dp_register[if_num].ndev = netdev;
81 nss_top_main.subsys_dp_register[if_num].cb = lag_cb;
82 nss_top_main.subsys_dp_register[if_num].app_data = NULL;
83 nss_top_main.subsys_dp_register[if_num].features = features;
84
Tushar Mathura3e03052014-04-07 20:17:28 +053085 nss_top_main.lag_event_callback = lag_ev_cb;
Gareth Williamsb52af512014-04-25 19:31:15 +010086
87 /*
88 * Return the NSS driver context for LAG (same as for ipv4 functions)
89 */
90 return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
Tushar Mathura3e03052014-04-07 20:17:28 +053091}
92EXPORT_SYMBOL(nss_register_lag_if);
93
94
95/**
96 * nss_unregister_lag_if()
97 */
98void nss_unregister_lag_if(uint32_t if_num)
99{
Suman Ghoshcf8ed1c2015-09-07 18:57:04 +0530100 nss_assert((if_num == NSS_LAG0_INTERFACE_NUM) || (if_num == NSS_LAG1_INTERFACE_NUM) ||
101 (if_num == NSS_LAG2_INTERFACE_NUM) || (if_num == NSS_LAG3_INTERFACE_NUM));
Tushar Mathura3e03052014-04-07 20:17:28 +0530102
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800103 nss_top_main.subsys_dp_register[if_num].cb = NULL;
104 nss_top_main.subsys_dp_register[if_num].ndev = NULL;
105 nss_top_main.subsys_dp_register[if_num].app_data = NULL;
106 nss_top_main.subsys_dp_register[if_num].features = 0;
107
Tushar Mathura3e03052014-04-07 20:17:28 +0530108 nss_top_main.lag_event_callback = NULL;
109}
110EXPORT_SYMBOL(nss_unregister_lag_if);
111
112
113/**
114 * nss_lag_handler()
115 */
116void nss_lag_handler(struct nss_ctx_instance *nss_ctx,
117 struct nss_cmn_msg *ncm,
118 void *app_data)
119{
120 struct nss_lag_msg *lm = (struct nss_lag_msg *)ncm;
121 void *ctx = NULL;
122 nss_lag_event_callback_t cb;
123
124 BUG_ON(ncm->interface != NSS_LAG0_INTERFACE_NUM
Suman Ghoshcf8ed1c2015-09-07 18:57:04 +0530125 && ncm->interface != NSS_LAG1_INTERFACE_NUM
126 && ncm->interface != NSS_LAG2_INTERFACE_NUM
127 && ncm->interface != NSS_LAG3_INTERFACE_NUM);
Tushar Mathura3e03052014-04-07 20:17:28 +0530128
129 if (ncm->type >= NSS_TX_METADATA_LAG_MAX) {
130 nss_warning("%p: received invalid message %d for LAG interface", nss_ctx, ncm->type);
131 return;
132 }
133
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800134 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_lag_msg)) {
135 nss_warning("%p: invalid length for LAG message: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Tushar Mathura3e03052014-04-07 20:17:28 +0530136 return;
137 }
138
139 /**
140 * Update the callback and app_data for NOTIFY messages.
141 * LAG sends all notify messages to the same callback.
142 */
143 if (ncm->response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800144 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->lag_event_callback;
Tushar Mathura3e03052014-04-07 20:17:28 +0530145 }
146
147 /**
148 * Log failures
149 */
150 nss_core_log_msg_failures(nss_ctx, ncm);
151
152 /**
153 * Do we have a call back
154 */
155 if (!ncm->cb) {
156 return;
157 }
158
159 /**
160 * callback
161 */
162 cb = (nss_lag_event_callback_t)ncm->cb;
Sundarajan Srinivasan70374842014-11-19 15:22:52 -0800163 ctx = nss_ctx->nss_top->subsys_dp_register[ncm->interface].ndev;
Tushar Mathura3e03052014-04-07 20:17:28 +0530164
165 cb(ctx, lm);
166}
167
168
169/**
170 * nss_lag_register_handler()
171 */
172void nss_lag_register_handler(void)
173{
174 nss_core_register_handler(NSS_LAG0_INTERFACE_NUM, nss_lag_handler, NULL);
175 nss_core_register_handler(NSS_LAG1_INTERFACE_NUM, nss_lag_handler, NULL);
Suman Ghoshcf8ed1c2015-09-07 18:57:04 +0530176 nss_core_register_handler(NSS_LAG2_INTERFACE_NUM, nss_lag_handler, NULL);
177 nss_core_register_handler(NSS_LAG3_INTERFACE_NUM, nss_lag_handler, NULL);
Tushar Mathura3e03052014-04-07 20:17:28 +0530178}
179
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700180/**
181 * nss_lag_msg_init()
182 * Initialize lag message
183 */
184void nss_lag_msg_init(struct nss_lag_msg *nlm, uint16_t lag_num, uint32_t type, uint32_t len,
Sundarajan Srinivasan30a53d42015-01-30 10:52:08 -0800185 nss_lag_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700186{
187 nss_cmn_msg_init(&nlm->cm, lag_num, type, len, (void *)cb, app_data);
188}
189EXPORT_SYMBOL(nss_lag_msg_init);