blob: 7a0fdd52f356365b14bfb088e84f3995620cbac0 [file] [log] [blame]
Saurabh Misra96998db2014-07-10 12:15:48 -07001/*
2 **************************************************************************
Stephen Wang3e2dbd12018-03-14 17:28:17 -07003 * Copyright (c) 2014-2018, The Linux Foundation. All rights reserved.
Saurabh Misra96998db2014-07-10 12:15:48 -07004 * 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 * nss_log.c
18 * NSS FW debug logger retrieval from DDR (memory)
19 *
20 */
21#include <linux/types.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/errno.h>
26#include <linux/mm.h>
27#include <linux/fs.h>
28#include <linux/miscdevice.h>
29#include <linux/posix-timers.h>
30#include <linux/interrupt.h>
31#include <linux/time.h>
32#include <linux/platform_device.h>
Saurabh Misra96998db2014-07-10 12:15:48 -070033#include <linux/device.h>
34#include <nss_hal.h>
35#include "nss_core.h"
36#include "nss_log.h"
37
38/*
Saurabh Misra96998db2014-07-10 12:15:48 -070039 * Private data for each device file open instance
40 */
41struct nss_log_data {
42 void *load_mem; /* Pointer to struct nss_log_descriptor - descriptor data */
43 dma_addr_t dma_addr; /* Handle to DMA */
44 uint32_t last_entry; /* Last known sampled entry (or index) */
45 uint32_t nentries; /* Caches the total number of entries of log buffer */
46 int nss_id; /* NSS Core id being used */
47};
48
Cemil Coskun5f51db52018-05-07 17:15:37 -070049struct nss_log_ring_buffer_addr nss_rbe[NSS_MAX_CORES];
Saurabh Misra96998db2014-07-10 12:15:48 -070050
51static DEFINE_MUTEX(nss_log_mutex);
52static wait_queue_head_t nss_log_wq;
53static nss_log_msg_callback_t nss_debug_interface_cb;
54static void *nss_debug_interface_app_data = NULL;
55
56static wait_queue_head_t msg_wq;
57enum nss_cmn_response msg_response;
58static bool msg_event;
59
60/*
61 * nss_log_llseek()
62 * Seek operation.
63 */
64static loff_t nss_log_llseek(struct file *file, loff_t offset, int origin)
65{
66 struct nss_log_data *data = file->private_data;
67
68 switch (origin) {
69 case SEEK_SET:
70 break;
71 case SEEK_CUR:
72 offset += file->f_pos;
73 break;
74 case SEEK_END:
75 offset = ((data->nentries * sizeof(struct nss_log_entry)) + sizeof(struct nss_log_descriptor)) - offset;
76 break;
77 default:
78 return -EINVAL;
79 }
80
81 return (offset >= 0) ? (file->f_pos = offset) : -EINVAL;
82}
83
84/*
85 * nss_log_open()
86 * Open operation for our device. We let as many instance run together
87 */
88static int nss_log_open(struct inode *inode, struct file *filp)
89{
90 struct nss_log_data *data = NULL;
91 struct nss_top_instance *nss_top;
92 struct nss_ctx_instance *nss_ctx;
93 int nss_id;
94
95 /*
96 * i_private is passed to us by debug_fs_create()
97 */
Stephen Wangaed46332016-12-12 17:29:03 -080098 nss_id = (int)(nss_ptr_t)inode->i_private;
Saurabh Misra96998db2014-07-10 12:15:48 -070099 if (nss_id < 0 || nss_id >= NSS_MAX_CORES) {
100 nss_warning("nss_id is not valid :%d\n", nss_id);
101 return -ENODEV;
102 }
103
104 nss_top = &nss_top_main;
105 nss_ctx = &nss_top->nss[nss_id];
106
107 data = kzalloc(sizeof(struct nss_log_data), GFP_KERNEL);
108 if (!data) {
109 nss_warning("%p: Failed to allocate memory for log_data", nss_ctx);
110 return -ENOMEM;
111 }
112
113 mutex_lock(&nss_log_mutex);
114 if (!nss_rbe[nss_id].addr) {
115 mutex_unlock(&nss_log_mutex);
116 kfree(data);
117 nss_warning("%p: Ring buffer not configured yet for nss_id:%d", nss_ctx, nss_id);
118 return -EIO;
119 }
120
121 /*
122 * Actual ring buffer.
123 */
124 data->load_mem = nss_rbe[nss_id].addr;
125 data->last_entry = 0;
126 data->nentries = nss_rbe[nss_id].nentries;
127 data->dma_addr = nss_rbe[nss_id].dma_addr;
128
129 /*
130 * Increment the reference count so that we don't free
131 * the memory
132 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700133 nss_rbe[nss_id].ref_cnt++;
Saurabh Misra96998db2014-07-10 12:15:48 -0700134 data->nss_id = nss_id;
135 filp->private_data = data;
136 mutex_unlock(&nss_log_mutex);
137
138 return 0;
139}
140
141/*
142 * nss_log_release()
143 * release gets called when close() is called on the file
144 * descriptor. We unmap the IO region.
145 */
146static int nss_log_release(struct inode *inode, struct file *filp)
147{
148 struct nss_log_data *data = filp->private_data;
149
150 if (!data) {
151 return -EINVAL;
152 }
153
154 mutex_lock(&nss_log_mutex);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700155 nss_rbe[data->nss_id].ref_cnt--;
156 BUG_ON(nss_rbe[data->nss_id].ref_cnt < 0);
157 if (!nss_rbe[data->nss_id].ref_cnt) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700158 wake_up(&nss_log_wq);
159 }
160 mutex_unlock(&nss_log_mutex);
161 kfree(data);
162 return 0;
163}
164
165/*
Saurabh Misra6d42da72015-03-05 14:57:01 -0800166 * nss_log_current_entry()
167 * Reads current entry index from NSS log descriptor.
168 */
169static uint32_t nss_log_current_entry(struct nss_log_descriptor *desc)
170{
171 rmb();
172 return desc->current_entry;
173}
174
175/*
Saurabh Misra96998db2014-07-10 12:15:48 -0700176 * nss_log_read()
177 * Read operation lets command like cat and tail read our memory log buffer data.
178 */
179static ssize_t nss_log_read(struct file *filp, char __user *buf, size_t size, loff_t *ppos)
180{
181 struct nss_log_data *data = filp->private_data;
182 struct nss_log_descriptor *desc;
183 size_t bytes = 0;
184 size_t b;
185 struct nss_log_entry *rb;
186 uint32_t entry;
187 uint32_t offset, index;
188 char msg[NSS_LOG_OUTPUT_LINE_SIZE];
189
190 if (!data) {
191 return -EINVAL;
192 }
193
194 desc = data->load_mem;
195 if (!desc) {
196 nss_warning("%p: load_mem is NULL", data);
197 return -EINVAL;
198 }
199
200 /*
201 * If buffer is too small to fit even one entry.
202 */
203 if (size < NSS_LOG_OUTPUT_LINE_SIZE) {
204 return 0;
205 }
206
207 /*
208 * Get the current index
209 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700210 dma_sync_single_for_cpu(NULL, data->dma_addr, sizeof(struct nss_log_descriptor), DMA_FROM_DEVICE);
Saurabh Misra6d42da72015-03-05 14:57:01 -0800211 entry = nss_log_current_entry(desc);
Saurabh Misra96998db2014-07-10 12:15:48 -0700212
213 /*
214 * If the current and last sampled indexes are same then bail out.
215 */
216 if (unlikely(data->last_entry == entry)) {
217 return 0;
218 }
219
220 /*
221 * If this is the first read (after open) on our device file.
222 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700223 if (unlikely(!(*ppos))) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700224 /*
225 * If log buffer has rolled over. Almost all the time
226 * it will be true.
227 */
228 if (likely(entry > data->nentries)) {
229 /*
230 * Determine how much we can stuff in one
231 * buffer passed to us and accordingly
232 * reduce our index.
233 */
234 data->last_entry = entry - data->nentries;
235 } else {
236 data->last_entry = 0;
237 }
238 } else if (unlikely(entry > data->nentries && ((entry - data->nentries) > data->last_entry))) {
239 /*
240 * If FW is producing debug buffer at a pace faster than
241 * we can consume, then we restrict our iteration.
242 */
243 data->last_entry = entry - data->nentries;
244 }
245
246 /*
247 * Iterate over indexes.
248 */
249 while (entry > data->last_entry) {
250 index = offset = (data->last_entry % data->nentries);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700251 offset = (offset * sizeof(struct nss_log_entry))
Saurabh Misra96998db2014-07-10 12:15:48 -0700252 + offsetof(struct nss_log_descriptor, log_ring_buffer);
253
254 dma_sync_single_for_cpu(NULL, data->dma_addr + offset,
255 sizeof(struct nss_log_entry), DMA_FROM_DEVICE);
256 rb = &desc->log_ring_buffer[index];
257
258 b = snprintf(msg, sizeof(msg), NSS_LOG_LINE_FORMAT,
259 rb->thread_num, rb->timestamp, rb->message);
260
261 data->last_entry++;
262
263 /*
264 * Copy to user buffer and if we fail then we return
265 * failure.
266 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700267 if (copy_to_user(buf + bytes, msg, b)) {
268 return -EFAULT;
Saurabh Misra96998db2014-07-10 12:15:48 -0700269 }
270
Cemil Coskun5f51db52018-05-07 17:15:37 -0700271 bytes += b;
272
Saurabh Misra96998db2014-07-10 12:15:48 -0700273 /*
274 * If we ran out of space in the buffer.
275 */
276 if ((bytes + NSS_LOG_OUTPUT_LINE_SIZE) >= size)
277 break;
278 }
279
280 if (bytes > 0)
281 *ppos = bytes;
282
283 return bytes;
284}
285
286struct file_operations nss_logs_core_ops = {
287 .owner = THIS_MODULE,
288 .open = nss_log_open,
289 .read = nss_log_read,
290 .release = nss_log_release,
291 .llseek = nss_log_llseek,
292};
293
294/*
295 * nss_debug_interface_set_callback()
296 * Sets the callback
297 */
298void nss_debug_interface_set_callback(nss_log_msg_callback_t cb, void *app_data)
299{
300 nss_debug_interface_cb = cb;
301 nss_debug_interface_app_data = app_data;
302}
303
304/*
305 * nss_debug_interface_event()
306 * Received an event from NSS FW
307 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700308static void nss_debug_interface_event(void *app_data, struct nss_log_debug_interface_msg *nim)
Saurabh Misra96998db2014-07-10 12:15:48 -0700309{
310 struct nss_cmn_msg *ncm = (struct nss_cmn_msg *)nim;
311
312 msg_response = ncm->response;
313 msg_event = true;
314 wake_up(&msg_wq);
315}
316
317/*
318 * nss_debug_interface_handler()
Cemil Coskun5f51db52018-05-07 17:15:37 -0700319 * handle NSS -> HLOS messages for debug interfaces
Saurabh Misra96998db2014-07-10 12:15:48 -0700320 */
321static void nss_debug_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
322{
Cemil Coskun5f51db52018-05-07 17:15:37 -0700323 struct nss_log_debug_interface_msg *ntm = (struct nss_log_debug_interface_msg *)ncm;
Saurabh Misra96998db2014-07-10 12:15:48 -0700324 nss_log_msg_callback_t cb;
325
326 BUG_ON(ncm->interface != NSS_DEBUG_INTERFACE);
327
328 /*
329 * Is this a valid request/response packet?
330 */
331 if (ncm->type > NSS_DEBUG_INTERFACE_TYPE_MAX) {
332 nss_warning("%p: received invalid message %d for CAPWAP interface", nss_ctx, ncm->type);
333 return;
334 }
335
Cemil Coskun5f51db52018-05-07 17:15:37 -0700336 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_log_debug_interface_msg)) {
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800337 nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Saurabh Misra96998db2014-07-10 12:15:48 -0700338 return;
339 }
340
341 nss_core_log_msg_failures(nss_ctx, ncm);
342
343 /*
344 * Update the callback and app_data for NOTIFY messages.
345 */
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +0530346 if (ncm->response == NSS_CMN_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800347 ncm->cb = (nss_ptr_t)nss_debug_interface_cb;
348 ncm->app_data = (nss_ptr_t)nss_debug_interface_app_data;
Saurabh Misra96998db2014-07-10 12:15:48 -0700349 }
350
351 /*
352 * Do we have a callback
353 */
354 if (!ncm->cb) {
355 nss_trace("%p: cb is null for interface %d", nss_ctx, ncm->interface);
356 return;
357 }
358
359 cb = (nss_log_msg_callback_t)ncm->cb;
360 cb((void *)ncm->app_data, ntm);
361}
362
363/*
364 * nss_debug_interface_tx()
Cemil Coskun5f51db52018-05-07 17:15:37 -0700365 * Transmit a debug interface message to NSS FW
Saurabh Misra96998db2014-07-10 12:15:48 -0700366 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700367static nss_tx_status_t nss_debug_interface_tx(struct nss_ctx_instance *nss_ctx, struct nss_log_debug_interface_msg *msg)
Saurabh Misra96998db2014-07-10 12:15:48 -0700368{
Saurabh Misra96998db2014-07-10 12:15:48 -0700369 struct nss_cmn_msg *ncm = &msg->cm;
Saurabh Misra96998db2014-07-10 12:15:48 -0700370
371 /*
372 * Sanity check the message
373 */
374 if (ncm->interface != NSS_DEBUG_INTERFACE) {
375 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
376 return NSS_TX_FAILURE;
377 }
378
379 if (ncm->type > NSS_DEBUG_INTERFACE_TYPE_MAX) {
380 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
381 return NSS_TX_FAILURE;
382 }
383
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700384 return nss_core_send_cmd(nss_ctx, msg, sizeof(*msg), NSS_NBUF_PAYLOAD_SIZE);
Saurabh Misra96998db2014-07-10 12:15:48 -0700385}
386
387/*
388 * nss_debug_log_buffer_alloc()
389 * Allocates and Initializes log buffer for the use in NSS FW (logging)
390 */
391bool nss_debug_log_buffer_alloc(uint8_t nss_id, uint32_t nentry)
392{
Cemil Coskun5f51db52018-05-07 17:15:37 -0700393 struct nss_log_debug_interface_msg msg;
394 struct nss_log_debug_memory_msg *dbg;
Saurabh Misra96998db2014-07-10 12:15:48 -0700395 struct nss_top_instance *nss_top;
396 struct nss_ctx_instance *nss_ctx;
397 dma_addr_t dma_addr;
398 uint32_t size;
399 void *addr = NULL;
400 nss_tx_status_t status;
Saurabh Misra96998db2014-07-10 12:15:48 -0700401
Radha krishna Simha Jigurudf53f022015-11-09 12:31:26 +0530402 if (nss_id >= NSS_MAX_CORES) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700403 return false;
404 }
405
406 nss_top = &nss_top_main;
407 nss_ctx = &nss_top->nss[nss_id];
408
409 if (nss_ctx->state != NSS_CORE_STATE_INITIALIZED) {
410 nss_warning("%p: NSS Core:%d is not initialized yet\n", nss_ctx, nss_id);
411 return false;
412 }
413
Cemil Coskun5f51db52018-05-07 17:15:37 -0700414 size = sizeof(struct nss_log_descriptor) + (sizeof(struct nss_log_entry) * nentry);
Saurabh Misra96998db2014-07-10 12:15:48 -0700415 addr = kmalloc(size, GFP_ATOMIC);
416 if (!addr) {
417 nss_warning("%p: Failed to allocate memory for logging (size:%d)\n", nss_ctx, size);
418 return false;
419 }
420
421 memset(addr, 0, size);
Stephen Wangefd38512017-01-24 14:01:02 -0800422 dma_addr = (uint32_t)dma_map_single(nss_ctx->dev, addr, size, DMA_FROM_DEVICE);
423 if (unlikely(dma_mapping_error(nss_ctx->dev, dma_addr))) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700424 nss_warning("%p: Failed to map address in DMA", nss_ctx);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700425 kfree(addr);
426 return false;
Saurabh Misra96998db2014-07-10 12:15:48 -0700427 }
428
429 /*
430 * If we already have ring buffer associated with nss_id, then
431 * we must wait before we attach a new ring buffer.
432 */
433 mutex_lock(&nss_log_mutex);
434 if (nss_rbe[nss_id].addr) {
435 mutex_unlock(&nss_log_mutex);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700436
437 /*
438 * Someone is using the current logbuffer. Wait until ref count become 0.
439 * We have to return mutex here, because the current user requires it to
440 * release the reference.
441 */
442 if (!wait_event_timeout(nss_log_wq, !nss_rbe[nss_id].ref_cnt, 5 * HZ)) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700443 nss_warning("%p: Timeout waiting for refcnt to become 0\n", nss_ctx);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700444 goto fail;
Saurabh Misra96998db2014-07-10 12:15:48 -0700445 }
446
447 mutex_lock(&nss_log_mutex);
448 if (!nss_rbe[nss_id].addr) {
449 mutex_unlock(&nss_log_mutex);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700450 goto fail;
Saurabh Misra96998db2014-07-10 12:15:48 -0700451 }
Cemil Coskun5f51db52018-05-07 17:15:37 -0700452 if (nss_rbe[nss_id].ref_cnt > 0) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700453 mutex_unlock(&nss_log_mutex);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700454 nss_warning("%p: Some other thread is contending..opting out\n", nss_ctx);
455 goto fail;
Saurabh Misra96998db2014-07-10 12:15:48 -0700456 }
Saurabh Misra96998db2014-07-10 12:15:48 -0700457 }
458
Cemil Coskun5f51db52018-05-07 17:15:37 -0700459 memset(&msg, 0, sizeof(struct nss_log_debug_interface_msg));
Saurabh Misra96998db2014-07-10 12:15:48 -0700460 nss_cmn_msg_init(&msg.cm, NSS_DEBUG_INTERFACE, NSS_DEBUG_INTERFACE_TYPE_LOG_BUF_INIT,
Cemil Coskun5f51db52018-05-07 17:15:37 -0700461 sizeof(struct nss_log_debug_memory_msg), nss_debug_interface_event, NULL);
Saurabh Misra96998db2014-07-10 12:15:48 -0700462
463 dbg = &msg.msg.addr;
464 dbg->nentry = nentry;
465 dbg->version = NSS_DEBUG_LOG_VERSION;
Saurabh Misra6d42da72015-03-05 14:57:01 -0800466 dbg->phy_addr = dma_addr;
Saurabh Misra96998db2014-07-10 12:15:48 -0700467
468 msg_event = false;
469 status = nss_debug_interface_tx(nss_ctx, &msg);
470 if (status != NSS_TX_SUCCESS) {
Cemil Coskun5f51db52018-05-07 17:15:37 -0700471 mutex_unlock(&nss_log_mutex);
Saurabh Misra96998db2014-07-10 12:15:48 -0700472 nss_warning("%p: Failed to send message to debug interface:%d\n", nss_ctx, status);
Cemil Coskun5f51db52018-05-07 17:15:37 -0700473 goto fail;
474 }
Saurabh Misra96998db2014-07-10 12:15:48 -0700475
Cemil Coskun5f51db52018-05-07 17:15:37 -0700476 /*
477 * Wait for 5 seconds since this is a critical operation.
478 * Mutex is not unlocked here because we do not want someone to acquire the mutex and use the logbuffer
479 * while we are waiting message from NSS.
480 */
481 if (!wait_event_timeout(msg_wq, msg_event, 5 * HZ)) {
482 mutex_unlock(&nss_log_mutex);
483 nss_warning("%p: Timeout send message to debug interface\n", nss_ctx);
484 goto fail;
485 }
486
487 if (msg_response != NSS_CMN_RESPONSE_ACK) {
488 mutex_unlock(&nss_log_mutex);
489 nss_warning("%p: Response error for send message to debug interface:%d\n", nss_ctx, msg_response);
490 goto fail;
Saurabh Misra96998db2014-07-10 12:15:48 -0700491 }
492
493 /*
494 * If we had to free the previous allocation for ring buffer.
495 */
Cemil Coskun5f51db52018-05-07 17:15:37 -0700496 if (nss_rbe[nss_id].addr) {
497 uint32_t old_size;
498 old_size = sizeof(struct nss_log_descriptor) +
499 (sizeof(struct nss_log_entry) * nss_rbe[nss_id].nentries);
500 dma_unmap_single(nss_ctx->dev, nss_rbe[nss_id].dma_addr, old_size, DMA_FROM_DEVICE);
501 kfree(nss_rbe[nss_id].addr);
Saurabh Misra96998db2014-07-10 12:15:48 -0700502 }
503
Cemil Coskun5f51db52018-05-07 17:15:37 -0700504 nss_rbe[nss_id].addr = addr;
505 nss_rbe[nss_id].nentries = nentry;
506 nss_rbe[nss_id].ref_cnt = 0;
507 nss_rbe[nss_id].dma_addr = dma_addr;
508 mutex_unlock(&nss_log_mutex);
509 wake_up(&nss_log_wq);
510 return true;
Saurabh Misra96998db2014-07-10 12:15:48 -0700511
Cemil Coskun5f51db52018-05-07 17:15:37 -0700512fail:
513 dma_unmap_single(NULL, dma_addr, size, DMA_FROM_DEVICE);
Saurabh Misra96998db2014-07-10 12:15:48 -0700514 kfree(addr);
515 wake_up(&nss_log_wq);
516 return false;
517}
518
519/*
520 * nss_logbuffer_handler()
521 * Enable NSS debug output
522 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700523int nss_logbuffer_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Saurabh Misra96998db2014-07-10 12:15:48 -0700524{
525 int ret;
Thomas Wucf215082017-08-02 14:23:37 -0700526 int core_status;
Saurabh Misra96998db2014-07-10 12:15:48 -0700527 int i;
528
529 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
530 if (ret) {
531 return ret;
532 }
533
534 if (!write) {
535 return ret;
536 }
537
538 if (nss_ctl_logbuf < 32) {
Cemil Coskun5f51db52018-05-07 17:15:37 -0700539 nss_warning("Invalid NSS FW logbuffer size:%d (must be > 32)\n", nss_ctl_logbuf);
Saurabh Misra96998db2014-07-10 12:15:48 -0700540 nss_ctl_logbuf = 0;
541 return ret;
542 }
543
544 for (i = 0; i < NSS_MAX_CORES; i++) {
Thomas Wucf215082017-08-02 14:23:37 -0700545 /*
546 * Register the callback handler and allocate the debug log buffers
547 */
548 core_status = nss_core_register_handler(&nss_top_main.nss[i], NSS_DEBUG_INTERFACE, nss_debug_interface_handler, NULL);
549 if (core_status != NSS_CORE_STATUS_SUCCESS) {
550 nss_warning("NSS logbuffer init failed with register handler:%d\n", core_status);
551 }
552
Cemil Coskun5f51db52018-05-07 17:15:37 -0700553 if (!nss_debug_log_buffer_alloc(i, nss_ctl_logbuf)) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700554 nss_warning("%d: Failed to set debug log buffer on NSS core", i);
555 }
556 }
557
558 return ret;
559}
560
561/*
562 * nss_log_init()
563 * Initializes NSS FW logs retrieval logic from /sys
564 */
565void nss_log_init(void)
566{
Saurabh Misra96998db2014-07-10 12:15:48 -0700567 int i;
Yu Huang8c107082017-07-24 14:58:26 -0700568 struct dentry *logs_dentry;
569 struct dentry *core_log_dentry;
Saurabh Misra96998db2014-07-10 12:15:48 -0700570
571 memset(nss_rbe, 0, sizeof(nss_rbe));
572 init_waitqueue_head(&nss_log_wq);
573 init_waitqueue_head(&msg_wq);
574
575 /*
576 * Create directory for obtaining NSS FW logs from each core
577 */
Yu Huang8c107082017-07-24 14:58:26 -0700578 logs_dentry = debugfs_create_dir("logs", nss_top_main.top_dentry);
579 if (unlikely(!logs_dentry)) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700580 nss_warning("Failed to create qca-nss-drv/logs directory in debugfs");
581 return;
582 }
583
584 for (i = 0; i < NSS_MAX_CORES; i++) {
585 char file[10];
586 extern struct file_operations nss_logs_core_ops;
587
588 snprintf(file, sizeof(file), "core%d", i);
Yu Huang8c107082017-07-24 14:58:26 -0700589 core_log_dentry = debugfs_create_file(file, 0400,
590 logs_dentry, (void *)(nss_ptr_t)i, &nss_logs_core_ops);
591 if (unlikely(!core_log_dentry)) {
Saurabh Misra96998db2014-07-10 12:15:48 -0700592 nss_warning("Failed to create qca-nss-drv/logs/%s file in debugfs", file);
593 return;
594 }
595 }
596
597 nss_debug_interface_set_callback(nss_debug_interface_event, NULL);
Saurabh Misra96998db2014-07-10 12:15:48 -0700598}