rsi_91x_debugfs.c 25.9 KB
Newer Older
1
/**
2
 * Copyright (c) 2017 Redpine Signals Inc. All rights reserved.
3
 *
4 5
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
6
 *
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
 * 	1. Redistributions of source code must retain the above copyright
 * 	   notice, this list of conditions and the following disclaimer.
 *
 * 	2. 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.
 *
 * 	3. Neither the name of the copyright holder nor the names of its
 * 	   contributors may be used to endorse or promote products derived from
 * 	   this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION). HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
29 30 31 32
 */

#include "rsi_debugfs.h"
#include "rsi_sdio.h"
33 34 35 36 37 38
#include "rsi_mgmt.h"
#ifdef CONFIG_RSI_11K
#include "rsi_rrm.h"
#endif

extern int g_bgscan_enable;
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

/**
 * rsi_sdio_stats_read() - This function returns the sdio status of the driver.
 * @seq: Pointer to the sequence file structure.
 * @data: Pointer to the data.
 *
 * Return: 0 on success, -1 on failure.
 */
static int rsi_sdio_stats_read(struct seq_file *seq, void *data)
{
	struct rsi_common *common = seq->private;
	struct rsi_hw *adapter = common->priv;
	struct rsi_91x_sdiodev *dev =
		(struct rsi_91x_sdiodev *)adapter->rsi_dev;

	seq_printf(seq, "total_sdio_interrupts: %d\n",
		   dev->rx_info.sdio_int_counter);
	seq_printf(seq, "sdio_msdu_pending_intr_count: %d\n",
		   dev->rx_info.total_sdio_msdu_pending_intr);
	seq_printf(seq, "sdio_buff_full_count : %d\n",
		   dev->rx_info.buf_full_counter);
	seq_printf(seq, "sdio_buf_semi_full_count %d\n",
		   dev->rx_info.buf_semi_full_counter);
	seq_printf(seq, "sdio_unknown_intr_count: %d\n",
		   dev->rx_info.total_sdio_unknown_intr);
	/* RX Path Stats */
	seq_printf(seq, "BUFFER FULL STATUS  : %d\n",
		   dev->rx_info.buffer_full);
	seq_printf(seq, "SEMI BUFFER FULL STATUS  : %d\n",
		   dev->rx_info.semi_buffer_full);
	seq_printf(seq, "MGMT BUFFER FULL STATUS  : %d\n",
		   dev->rx_info.mgmt_buffer_full);
	seq_printf(seq, "BUFFER FULL COUNTER  : %d\n",
		   dev->rx_info.buf_full_counter);
	seq_printf(seq, "BUFFER SEMI FULL COUNTER  : %d\n",
		   dev->rx_info.buf_semi_full_counter);
	seq_printf(seq, "MGMT BUFFER FULL COUNTER  : %d\n",
		   dev->rx_info.mgmt_buf_full_counter);

	return 0;
}

/**
82
 * rsi_sdio_stats_open() - This function calls single open function of seq_file
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
 *			   to open file and read contents from it.
 * @inode: Pointer to the inode structure.
 * @file: Pointer to the file structure.
 *
 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
 */
static int rsi_sdio_stats_open(struct inode *inode,
			       struct file *file)
{
	return single_open(file, rsi_sdio_stats_read, inode->i_private);
}

/**
 * rsi_version_read() - This function gives driver and firmware version number.
 * @seq: Pointer to the sequence file structure.
 * @data: Pointer to the data.
 *
 * Return: 0 on success, -1 on failure.
 */
static int rsi_version_read(struct seq_file *seq, void *data)
{
	struct rsi_common *common = seq->private;

106 107
	seq_printf(seq, "Driver : %s\nLMAC   : %d.%d.%d.%d\n",
		   common->driver_ver,
108 109 110 111
		   common->lmac_ver.major,
		   common->lmac_ver.minor,
		   common->lmac_ver.release_num,
		   common->lmac_ver.patch_num);
112 113 114 115
	return 0;
}

/**
116
 * rsi_version_open() - This function calls single open function of seq_file to
117 118 119 120 121 122 123
 *			open file and read contents from it.
 * @inode: Pointer to the inode structure.
 * @file: Pointer to the file structure.
 *
 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
 */
static int rsi_version_open(struct inode *inode,
124
			    struct file *file)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
{
	return single_open(file, rsi_version_read, inode->i_private);
}

/**
 * rsi_stats_read() - This function return the status of the driver.
 * @seq: Pointer to the sequence file structure.
 * @data: Pointer to the data.
 *
 * Return: 0 on success, -1 on failure.
 */
static int rsi_stats_read(struct seq_file *seq, void *data)
{
	struct rsi_common *common = seq->private;

	unsigned char fsm_state[][32] = {
		"FSM_CARD_NOT_READY",
		"FSM_BOOT_PARAMS_SENT",
		"FSM_EEPROM_READ_MAC_ADDR",
		"FSM_RESET_MAC_SENT",
		"FSM_RADIO_CAPS_SENT",
		"FSM_BB_RF_PROG_SENT",
		"FSM_MAC_INIT_DONE"
	};
	seq_puts(seq, "==> RSI STA DRIVER STATUS <==\n");
	seq_puts(seq, "DRIVER_FSM_STATE: ");

	if (common->fsm_state <= FSM_MAC_INIT_DONE)
		seq_printf(seq, "%s", fsm_state[common->fsm_state]);

	seq_printf(seq, "(%d)\n\n", common->fsm_state);

	/* Mgmt TX Path Stats */
	seq_printf(seq, "total_mgmt_pkt_send : %d\n",
		   common->tx_stats.total_tx_pkt_send[MGMT_SOFT_Q]);
	seq_printf(seq, "total_mgmt_pkt_queued : %d\n",
161
		   skb_queue_len(&common->tx_queue[MGMT_SOFT_Q]));
162 163 164 165 166 167 168
	seq_printf(seq, "total_mgmt_pkt_freed  : %d\n",
		   common->tx_stats.total_tx_pkt_freed[MGMT_SOFT_Q]);

	/* Data TX Path Stats */
	seq_printf(seq, "total_data_vo_pkt_send: %8d\t",
		   common->tx_stats.total_tx_pkt_send[VO_Q]);
	seq_printf(seq, "total_data_vo_pkt_queued:  %8d\t",
169
		   skb_queue_len(&common->tx_queue[VO_Q]));
170 171 172 173 174
	seq_printf(seq, "total_vo_pkt_freed: %8d\n",
		   common->tx_stats.total_tx_pkt_freed[VO_Q]);
	seq_printf(seq, "total_data_vi_pkt_send: %8d\t",
		   common->tx_stats.total_tx_pkt_send[VI_Q]);
	seq_printf(seq, "total_data_vi_pkt_queued:  %8d\t",
175
		   skb_queue_len(&common->tx_queue[VI_Q]));
176 177 178 179 180
	seq_printf(seq, "total_vi_pkt_freed: %8d\n",
		   common->tx_stats.total_tx_pkt_freed[VI_Q]);
	seq_printf(seq,  "total_data_be_pkt_send: %8d\t",
		   common->tx_stats.total_tx_pkt_send[BE_Q]);
	seq_printf(seq, "total_data_be_pkt_queued:  %8d\t",
181
		   skb_queue_len(&common->tx_queue[BE_Q]));
182 183 184 185 186
	seq_printf(seq, "total_be_pkt_freed: %8d\n",
		   common->tx_stats.total_tx_pkt_freed[BE_Q]);
	seq_printf(seq, "total_data_bk_pkt_send: %8d\t",
		   common->tx_stats.total_tx_pkt_send[BK_Q]);
	seq_printf(seq, "total_data_bk_pkt_queued:  %8d\t",
187
		   skb_queue_len(&common->tx_queue[BK_Q]));
188 189 190 191 192 193 194 195
	seq_printf(seq, "total_bk_pkt_freed: %8d\n",
		   common->tx_stats.total_tx_pkt_freed[BK_Q]);

	seq_puts(seq, "\n");
	return 0;
}

/**
196
 * rsi_stats_open() - This function calls single open function of seq_file to
197 198 199 200 201 202 203 204 205 206 207 208 209
 *		      open file and read contents from it.
 * @inode: Pointer to the inode structure.
 * @file: Pointer to the file structure.
 *
 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
 */
static int rsi_stats_open(struct inode *inode,
			  struct file *file)
{
	return single_open(file, rsi_stats_read, inode->i_private);
}

/**
210 211
 * rsi_debug_zone_read() - This function display the currently
 *			enabled debug zones.
212 213 214 215 216 217 218 219 220 221 222 223 224 225
 * @seq: Pointer to the sequence file structure.
 * @data: Pointer to the data.
 *
 * Return: 0 on success, -1 on failure.
 */
static int rsi_debug_zone_read(struct seq_file *seq, void *data)
{
	rsi_dbg(FSM_ZONE, "%x: rsi_enabled zone", rsi_zone_enabled);
	seq_printf(seq, "The zones available are %#x\n",
		   rsi_zone_enabled);
	return 0;
}

/**
226
 * rsi_debug_read() - This function calls single open function of seq_file to
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268
 *		      open file and read contents from it.
 * @inode: Pointer to the inode structure.
 * @file: Pointer to the file structure.
 *
 * Return: Pointer to the opened file status: 0 on success, ENOMEM on failure.
 */
static int rsi_debug_read(struct inode *inode,
			  struct file *file)
{
	return single_open(file, rsi_debug_zone_read, inode->i_private);
}

/**
 * rsi_debug_zone_write() - This function writes into hal queues as per user
 *			    requirement.
 * @filp: Pointer to the file structure.
 * @buff: Pointer to the character buffer.
 * @len: Length of the data to be written into buffer.
 * @data: Pointer to the data.
 *
 * Return: len: Number of bytes read.
 */
static ssize_t rsi_debug_zone_write(struct file *filp,
				    const char __user *buff,
				    size_t len,
				    loff_t *data)
{
	unsigned long dbg_zone;
	int ret;

	if (!len)
		return 0;

	ret = kstrtoul_from_user(buff, len, 16, &dbg_zone);

	if (ret)
		return ret;

	rsi_zone_enabled = dbg_zone;
	return len;
}

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
/**
 * rsi_bgscan_int_read() - This function display the default bgscan param
 *			   values.
 * @seq: Pointer to the sequence file structure.
 * @data: Pointer to the data.
 *
 * Return: 0 on success, -1 on failure.
 */
static int rsi_bgscan_int_read(struct seq_file *file, void *data)
{
	struct rsi_common *common = file->private;
	struct bgscan_config_params *params = NULL;
	int cnt;

	if (!common) {
		rsi_dbg(ERR_ZONE, "No Interface\n");
		return -ENODEV;
	}
	if (common->iface_down) {
		rsi_dbg(ERR_ZONE, "Interface Down\n");
		return -ENODEV;
	}
	params = &common->bgscan_info;

	seq_printf(file, "%d %d %d %d %d %d %d %d\n",
		   common->bgscan_en,
		   params->bgscan_threshold,
		   params->roam_threshold,
		   params->bgscan_periodicity,
		   params->active_scan_duration,
		   params->passive_scan_duration,
		   params->two_probe,
		   params->num_bg_channels);

	for (cnt = 0; cnt < params->num_bg_channels; cnt++) {
		if (params->channels2scan[cnt] & (BIT(15)))
			seq_printf(file, "%d[DFS] ",
				   (params->channels2scan[cnt] & 0x7FFF));
		else
			seq_printf(file, "%d ", params->channels2scan[cnt]);
	}
	seq_printf(file, "\n");

	return 0;
}

static int rsi_bgscan_read(struct inode *inode, struct file *file)
{
	return single_open(file, rsi_bgscan_int_read, inode->i_private);
}

/**
 * rsi_bgscan_write() - This function gets the bgscan params from user
 *			    and configures to device.
 * @file: Pointer to the file structure.
 * @user_buff: user buffer.
 * @count: Length of the data written in buffer.
 * @ppos: offset.
 *
 * Return: Number of bytes read.
 */
static ssize_t rsi_bgscan_write(struct file *file,
			        const char __user *user_buff,
				size_t count,
				loff_t *ppos)

{
	struct rsi_common *common = file->f_inode->i_private;
	struct rsi_hw *adapter = NULL;
	struct ieee80211_bss_conf *bss = NULL;
	char bgscan_buf[200];
	int bgscan_vals[64] = { 0 };
	int total_bytes, cnt = 0;
	int bytes_read = 0, t_bytes;
	int ret;

	if (!common) {
		rsi_dbg(ERR_ZONE, "No Interface\n");
		return -ENODEV;
	}
	if (common->iface_down) {
		rsi_dbg(ERR_ZONE, "Interface Down\n");
		return -ENODEV;
	}
	adapter = common->priv;
	bss = &adapter->vifs[adapter->sc_nvifs - 1]->bss_conf;

	total_bytes = simple_write_to_buffer(bgscan_buf,
					     sizeof(bgscan_buf) - 1,
					     ppos, user_buff, count);
	if (total_bytes < 1)
		return -EINVAL;

	/* make sure that buf is null terminated */
	bgscan_buf[sizeof(bgscan_buf) - 1] = '\0';

	ret = sscanf(bgscan_buf, "%d%n",
		     (int *)&g_bgscan_enable, &t_bytes);
	if (ret <= 0)
		return -EINVAL;

	if (!g_bgscan_enable) {
		/* return here if bgscan is already disabled */
		if (!common->bgscan_en) {
#ifdef PLATFORM_X86
			rsi_dbg(ERR_ZONE, "bgscan already disabled\n");
#endif
			return total_bytes;
		}

		mutex_lock(&common->mutex);
		if (bss->assoc && !rsi_send_bgscan_params(common, 0)) {
#ifdef PLATFORM_X86
			rsi_dbg(ERR_ZONE, "*** bgscan disabled ***\n");
#endif
			common->bgscan_en = 0;
		}
		mutex_unlock(&common->mutex);

		return total_bytes;
	} else
		common->debugfs_bgscan = true;

	/* Return if bgscan is already in progress */
393 394
	if (common->bgscan_en && bss->assoc)
		common->bgscan_en = 0;
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452

	bytes_read += t_bytes;
	while (1) {
		ret = sscanf(bgscan_buf + bytes_read, "%d%n",
			     &bgscan_vals[cnt++],
			     &t_bytes);
		if (ret <= 0)
			break;
		bytes_read += t_bytes;
		
		if ((bgscan_vals[6] > 0) && (cnt > (6 + bgscan_vals[6])))
			break;
	}
	common->bgscan_info.bgscan_threshold = bgscan_vals[0];
	common->bgscan_info.roam_threshold = bgscan_vals[1];
	common->bgscan_info.bgscan_periodicity = bgscan_vals[2];
	common->bgscan_info.active_scan_duration = bgscan_vals[3];
	common->bgscan_info.passive_scan_duration = bgscan_vals[4];
	common->bgscan_info.two_probe = bgscan_vals[5];
	common->bgscan_info.num_user_channels = bgscan_vals[6];
	memset(&common->bgscan_info.user_channels, 0,
	       (MAX_BGSCAN_CHANNELS * 2));
	common->bgscan_info.num_user_channels = 
		((bgscan_vals[6] > MAX_BGSCAN_CHANNELS) ?
		 MAX_BGSCAN_CHANNELS : bgscan_vals[6]); 
	
	for (cnt = 0; cnt < common->bgscan_info.num_user_channels; cnt++)
		common->bgscan_info.user_channels[cnt] = bgscan_vals[7 + cnt];

#ifdef PLATFORM_X86
	rsi_dbg(INFO_ZONE,
		"bgscan_count = %d, roam_count = %d, periodicity = %d\n",
		common->bgscan_info.bgscan_threshold,
		common->bgscan_info.roam_threshold,
		common->bgscan_info.bgscan_periodicity);
	rsi_dbg(INFO_ZONE,
		"active_scan_dur = %d, passive_scan_dur = %d, two_probe = %d\n",
		common->bgscan_info.active_scan_duration,
		common->bgscan_info.passive_scan_duration,
		common->bgscan_info.two_probe);
	rsi_dbg(INFO_ZONE, "Number of scan channels = %d\n",
		common->bgscan_info.num_user_channels);
	rsi_hex_dump(INFO_ZONE, "bgscan channels",
		     (u8 *)common->bgscan_info.user_channels,
		     common->bgscan_info.num_user_channels * 2);
#endif

	/* If connection is not done don't send bgscan params */
	if (!bss->assoc) {
#ifdef PLATFORM_X86
		rsi_dbg(INFO_ZONE, "Station not connected; skip now\n");
#endif
		return total_bytes;
	}

	return total_bytes;
}

453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
#define FOPS(fopen) { \
	.owner = THIS_MODULE, \
	.open = (fopen), \
	.read = seq_read, \
	.llseek = seq_lseek, \
}

#define FOPS_RW(fopen, fwrite) { \
	.owner = THIS_MODULE, \
	.open = (fopen), \
	.read = seq_read, \
	.llseek = seq_lseek, \
	.write = (fwrite), \
}

468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738
#if defined(CONFIG_RSI_11K) && defined(RSI_DEBUG_RRM)
static ssize_t rsi_write_chload_meas_req(struct file *file,
					 const char __user *user_buff,
					 size_t count, loff_t *ppos)
{
	struct rsi_common *common = file->f_inode->i_private;
	char in_buf[200];
	int chan_load_vals[64] = { 0 };
	int total_bytes, bytes_read = 0;
	int ret, i;
        struct rsi_hw *adapter = common->priv;
	struct ieee80211_bss_conf *bss =
		&adapter->vifs[adapter->sc_nvifs - 1]->bss_conf;

	if (!bss->assoc) {
		rsi_dbg(ERR_ZONE,
			"unable to send channelload in non connected state\n");
		return -EINVAL;
	}

	total_bytes = simple_write_to_buffer(in_buf,
					     sizeof(in_buf) - 1,
					     ppos, user_buff, count);
	if (total_bytes < 1)
		return -EINVAL;
	in_buf[sizeof(in_buf) - 1] = '\0';
	ret = sscanf(in_buf + bytes_read, "%x%x%x%x%x%x%d%d%d%d%d%d",
		     &chan_load_vals[0], &chan_load_vals[1],
		     &chan_load_vals[2], &chan_load_vals[3],
		     &chan_load_vals[4], &chan_load_vals[5],
		     &chan_load_vals[6], &chan_load_vals[7],
		     &chan_load_vals[8], &chan_load_vals[9],
		     &chan_load_vals[10], &chan_load_vals[11]);
	rsi_hex_dump(INFO_ZONE, "Parsed values", (u8 *)chan_load_vals, 32);
	for (i = 0; i < ETH_ALEN; i++)
		common->rrm_chload_params.macid[i] = chan_load_vals[i];

	common->rrm_chload_params.regulatory_class = chan_load_vals[6];
	common->rrm_chload_params.channel_num = chan_load_vals[7];
	common->rrm_chload_params.rand_interval = chan_load_vals[8];
	common->rrm_chload_params.meas_duration = chan_load_vals[9];
	common->rrm_chload_params.meas_req_mode = chan_load_vals[10];
	common->rrm_chload_params.meas_type = chan_load_vals[11];

	if (!rsi_rrm_send_channel_load_req(common))
		rsi_dbg(ERR_ZONE, "Sent channel load measurement request\n");
	else
		rsi_dbg(ERR_ZONE,
			"Failed sending channel load measurement req\n");

	return total_bytes;
}

static ssize_t rsi_int_read_chload_params(struct seq_file *file, void *data)
{
	struct rsi_common *common = file->private;
	struct rsi_chload_meas_req_params *params = &common->rrm_chload_params;

	seq_printf(file, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x %d %d %d %d %d %d\n",
		   params->macid[0], params->macid[1], params->macid[2],
		   params->macid[3], params->macid[4], params->macid[5],
		   params->regulatory_class, params->channel_num,
		   params->rand_interval, params->meas_duration,
		   params->meas_req_mode, params->meas_type);
	seq_puts(file, "\n");

	return 0;
}

static int rsi_read_chload_meas_req(struct inode *inode, struct file *file)
{
	return single_open(file, rsi_int_read_chload_params, inode->i_private);
}

static ssize_t rsi_write_frame_meas_req(struct file *file,
					const char __user *user_buff,
					size_t count, loff_t *ppos)
{
	struct rsi_common *common = file->f_inode->i_private;
	char in_buf[200];
	int frame_load_vals[64] = { 0 };
	int total_bytes, bytes_read = 0;
	int ret, i;
        struct rsi_hw *adapter = common->priv;
	struct ieee80211_bss_conf *bss =
		&adapter->vifs[adapter->sc_nvifs - 1]->bss_conf;

	if (!bss->assoc) {
		rsi_dbg(ERR_ZONE,
			"unable to send frame req in non connected state\n");
		return -EINVAL;
	}
	total_bytes = simple_write_to_buffer(in_buf,
					     sizeof(in_buf) - 1,
					     ppos, user_buff, count);
	if (total_bytes < 1)
		return -EINVAL;
	in_buf[sizeof(in_buf) - 1] = '\0';
	ret = sscanf(in_buf + bytes_read, "%x%x%x%x%x%x%d%d%d%d%d%d%d\n"
		     "%x%x%x%x%x%x",
		     &frame_load_vals[0], &frame_load_vals[1],
		     &frame_load_vals[2], &frame_load_vals[3],
		     &frame_load_vals[4], &frame_load_vals[5],
		     &frame_load_vals[6], &frame_load_vals[7],
		     &frame_load_vals[8], &frame_load_vals[9],
		     &frame_load_vals[10], &frame_load_vals[11],
		     &frame_load_vals[12], &frame_load_vals[13],
		     &frame_load_vals[14], &frame_load_vals[15],
		     &frame_load_vals[16], &frame_load_vals[17],
		     &frame_load_vals[18]);
	rsi_hex_dump(INFO_ZONE, "Parsed values", (u8 *)frame_load_vals, 32);

	for (i = 0; i < ETH_ALEN; i++)
		common->rrm_frame_params.destid[i] = frame_load_vals[i];
	common->rrm_frame_params.regulatory_class = frame_load_vals[6];
	common->rrm_frame_params.channel_num = frame_load_vals[7];
	common->rrm_frame_params.rand_interval = frame_load_vals[8];
	common->rrm_frame_params.meas_duration = frame_load_vals[9];
	common->rrm_frame_params.meas_req_mode = frame_load_vals[10];
	common->rrm_frame_params.meas_type = frame_load_vals[11];
	common->rrm_frame_params.frame_req_type = frame_load_vals[12];
	for (i = 0; i < ETH_ALEN; i++)
		common->rrm_frame_params.macid[i] = frame_load_vals[13 + i];

	if (!rsi_rrm_send_frame_req(common))
		rsi_dbg(ERR_ZONE, "Sent frame measurement request\n");
	else
		rsi_dbg(ERR_ZONE, "Failed sending frame measurement req\n");

	return total_bytes;
}

static ssize_t rsi_int_read_frame_params(struct seq_file *file, void *data)
{
	struct rsi_common *common = file->private;
	struct rsi_frame_meas_req_params *params = &common->rrm_frame_params;

	seq_printf(file, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x %d %d %d %d %d %d %d\n"
		   "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
		   params->destid[0], params->destid[1], params->destid[2],
		   params->destid[3], params->destid[4], params->destid[5],
		   params->regulatory_class, params->channel_num,
		   params->rand_interval, params->meas_duration,
		   params->meas_req_mode, params->meas_type,
		   params->frame_req_type, params->macid[0],
		   params->macid[1], params->macid[2],
		   params->macid[3], params->macid[4],
		   params->macid[5]);
	seq_puts(file, "\n");

	return 0;
}

static int rsi_read_frame_meas_req(struct inode *inode, struct file *file)
{
	return single_open(file, rsi_int_read_frame_params, inode->i_private);
}

static ssize_t rsi_write_beacon_meas_req(struct file *file,
					 const char __user *user_buff,
					 size_t count, loff_t *ppos)
{
	struct rsi_common *common = file->f_inode->i_private;
	char in_buf[200];
	int beacon_load_vals[64] = { 0 };
	int total_bytes, bytes_read = 0;
	int ret;
	char str[32];
        struct rsi_hw *adapter = common->priv;
	struct ieee80211_bss_conf *bss =
		&adapter->vifs[adapter->sc_nvifs - 1]->bss_conf;

	if (!bss->assoc) {
		rsi_dbg(ERR_ZONE,
			"unable to send beacon req in non connected state\n");
		return -EINVAL;
	}
	total_bytes = simple_write_to_buffer(in_buf,
					     sizeof(in_buf) - 1,
					     ppos, user_buff, count);
	if (total_bytes < 1)
		return -EINVAL;
	in_buf[sizeof(in_buf) - 1] = '\0';
	ret = sscanf(in_buf + bytes_read, "%x%x%x%x%x%x%d%d%d%d%d%d%d\n"
					  "%x%x%x%x%x%x%s",
		     &beacon_load_vals[0], &beacon_load_vals[1],
		     &beacon_load_vals[2], &beacon_load_vals[3],
		     &beacon_load_vals[4], &beacon_load_vals[5],
		     &beacon_load_vals[6], &beacon_load_vals[7],
		     &beacon_load_vals[8], &beacon_load_vals[9],
		     &beacon_load_vals[10], &beacon_load_vals[11],
		     &beacon_load_vals[12], &beacon_load_vals[13],
		     &beacon_load_vals[14], &beacon_load_vals[15],
		     &beacon_load_vals[16], &beacon_load_vals[17],
		     &beacon_load_vals[18], str);
	rsi_hex_dump(INFO_ZONE, "Parsed values", (u8 *)beacon_load_vals, 32);

	common->rrm_beacon_params.destid[0] = beacon_load_vals[0];
	common->rrm_beacon_params.destid[1] = beacon_load_vals[1];
	common->rrm_beacon_params.destid[2] = beacon_load_vals[2];
	common->rrm_beacon_params.destid[3] = beacon_load_vals[3];
	common->rrm_beacon_params.destid[4] = beacon_load_vals[4];
	common->rrm_beacon_params.destid[5] = beacon_load_vals[5];
	common->rrm_beacon_params.regulatory_class = beacon_load_vals[6];
	common->rrm_beacon_params.channel_num = beacon_load_vals[7];
	common->rrm_beacon_params.rand_interval = beacon_load_vals[8];
	common->rrm_beacon_params.meas_duration = beacon_load_vals[9];
	common->rrm_beacon_params.meas_req_mode = beacon_load_vals[10];
	common->rrm_beacon_params.meas_type = beacon_load_vals[11];
	common->rrm_beacon_params.meas_mode = beacon_load_vals[12];
	common->rrm_beacon_params.bssid[0] = beacon_load_vals[13];
	common->rrm_beacon_params.bssid[1] = beacon_load_vals[14];
	common->rrm_beacon_params.bssid[2] = beacon_load_vals[15];
	common->rrm_beacon_params.bssid[3] = beacon_load_vals[16];
	common->rrm_beacon_params.bssid[4] = beacon_load_vals[17];
	common->rrm_beacon_params.bssid[5] = beacon_load_vals[18];
	memset(common->rrm_beacon_params.str, 0, 32);
	memcpy(common->rrm_beacon_params.str, str, strlen(str));

	rsi_dbg(INFO_ZONE, "regulatory class %d\n",
		common->rrm_beacon_params.regulatory_class);
	rsi_dbg(INFO_ZONE, "channel num %d\n",
		common->rrm_beacon_params.channel_num);
	rsi_dbg(INFO_ZONE, "rand_interval %d\n",
		common->rrm_beacon_params.rand_interval);
	rsi_dbg(INFO_ZONE, "meas_duration %d\n",
		common->rrm_beacon_params.meas_duration);
	rsi_dbg(INFO_ZONE, "meas_req_mode %d\n",
		common->rrm_beacon_params.meas_req_mode);
	rsi_dbg(INFO_ZONE, "meas_type %d\n",
		common->rrm_beacon_params.meas_type);
	rsi_dbg(INFO_ZONE, "meas_mode %d\n",
		common->rrm_beacon_params.meas_mode);
	rsi_dbg(INFO_ZONE, "ssid %s\n",
		common->rrm_beacon_params.str);

	if (!rsi_rrm_send_beacon_req(common))
		rsi_dbg(ERR_ZONE, "Sent Beacon measurement request\n");
	else
		rsi_dbg(ERR_ZONE, "Failed sending beacon measurement req\n");

	return total_bytes;
}

static ssize_t rsi_int_read_beacon_params(struct seq_file *file, void *data)
{
	struct rsi_common *common = file->private;
	struct rsi_beacon_meas_req_params *params = &common->rrm_beacon_params;

	seq_printf(file, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x %d %d %d %d %d %d %d "
			 "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x %s\n",
		   params->destid[0], params->destid[1], params->destid[2],
		   params->destid[3], params->destid[4], params->destid[5],
		   params->regulatory_class, params->channel_num,
		   params->rand_interval, params->meas_duration,
		   params->meas_req_mode, params->meas_type,
		   params->meas_mode, params->bssid[0],
		   params->bssid[1], params->bssid[2],
		   params->bssid[3], params->bssid[4],
		   params->bssid[5], params->str);
	seq_puts(file, "\n");

	return 0;
}

static int rsi_read_beacon_meas_req(struct inode *inode, struct file *file)
{
	return single_open(file, rsi_int_read_beacon_params, inode->i_private);
}
#endif

739 740 741 742
static const struct rsi_dbg_files dev_debugfs_files[] = {
	{"version", 0644, FOPS(rsi_version_open),},
	{"stats", 0644, FOPS(rsi_stats_open),},
	{"debug_zone", 0666, FOPS_RW(rsi_debug_read, rsi_debug_zone_write),},
743 744 745 746 747 748 749 750 751
	{"bgscan", 0666, FOPS_RW(rsi_bgscan_read, rsi_bgscan_write),},
#if defined(CONFIG_RSI_11K) && defined(RSI_DEBUG_RRM)
	{"rrm_chan_load_req", 0666, FOPS_RW(rsi_read_chload_meas_req,
					    rsi_write_chload_meas_req),},
	{"rrm_frame_req", 0666, FOPS_RW(rsi_read_frame_meas_req,
					rsi_write_frame_meas_req),},
	{"rrm_beacon_req", 0666, FOPS_RW(rsi_read_beacon_meas_req,
					 rsi_write_beacon_meas_req),},
#endif
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
	{"sdio_stats", 0644, FOPS(rsi_sdio_stats_open),},
};

/**
 * rsi_init_dbgfs() - This function initializes the dbgfs entry.
 * @adapter: Pointer to the adapter structure.
 *
 * Return: 0 on success, -1 on failure.
 */
int rsi_init_dbgfs(struct rsi_hw *adapter)
{
	struct rsi_common *common = adapter->priv;
	struct rsi_debugfs *dev_dbgfs;
	char devdir[6];
	int ii;
	const struct rsi_dbg_files *files;

	dev_dbgfs = kzalloc(sizeof(*dev_dbgfs), GFP_KERNEL);
770 771 772
	if (!dev_dbgfs)
		return -ENOMEM;

773 774 775 776 777
	adapter->dfsentry = dev_dbgfs;

	snprintf(devdir, sizeof(devdir), "%s",
		 wiphy_name(adapter->hw->wiphy));

778
	dev_dbgfs->subdir = debugfs_create_dir(devdir, NULL);
779

780
	if (!dev_dbgfs->subdir) {
781
		kfree(dev_dbgfs);
782 783 784 785 786 787 788 789 790 791 792
		return -ENOMEM;
	}

	for (ii = 0; ii < adapter->num_debugfs_entries; ii++) {
		files = &dev_debugfs_files[ii];
		dev_dbgfs->rsi_files[ii] =
		debugfs_create_file(files->name,
				    files->perms,
				    dev_dbgfs->subdir,
				    common,
				    &files->fops);
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
	}
	return 0;
}
EXPORT_SYMBOL_GPL(rsi_init_dbgfs);

/**
 * rsi_remove_dbgfs() - Removes the previously created dbgfs file entries
 *			in the reverse order of creation.
 * @adapter: Pointer to the adapter structure.
 *
 * Return: None.
 */
void rsi_remove_dbgfs(struct rsi_hw *adapter)
{
	struct rsi_debugfs *dev_dbgfs = adapter->dfsentry;

	if (!dev_dbgfs)
		return;

	debugfs_remove_recursive(dev_dbgfs->subdir);
}
EXPORT_SYMBOL_GPL(rsi_remove_dbgfs);