18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Intel Wireless WiMAX Connection 2400m
48c2ecf20Sopenharmony_ci * Sysfs interfaces to show driver and device information
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 2007 Intel Corporation <linux-wimax@intel.com>
78c2ecf20Sopenharmony_ci * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
118c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
128c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
138c2ecf20Sopenharmony_ci#include <linux/device.h>
148c2ecf20Sopenharmony_ci#include "i2400m.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#define D_SUBMODULE sysfs
188c2ecf20Sopenharmony_ci#include "debug-levels.h"
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * Set the idle timeout (msecs)
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * FIXME: eventually this should be a common WiMAX stack method, but
258c2ecf20Sopenharmony_ci * would like to wait to see how other devices manage it.
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_cistatic
288c2ecf20Sopenharmony_cissize_t i2400m_idle_timeout_store(struct device *dev,
298c2ecf20Sopenharmony_ci				  struct device_attribute *attr,
308c2ecf20Sopenharmony_ci				  const char *buf, size_t size)
318c2ecf20Sopenharmony_ci{
328c2ecf20Sopenharmony_ci	ssize_t result;
338c2ecf20Sopenharmony_ci	struct i2400m *i2400m = net_dev_to_i2400m(to_net_dev(dev));
348c2ecf20Sopenharmony_ci	unsigned val;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	result = -EINVAL;
378c2ecf20Sopenharmony_ci	if (sscanf(buf, "%u\n", &val) != 1)
388c2ecf20Sopenharmony_ci		goto error_no_unsigned;
398c2ecf20Sopenharmony_ci	if (val != 0 && (val < 100 || val > 300000 || val % 100 != 0)) {
408c2ecf20Sopenharmony_ci		dev_err(dev, "idle_timeout: %u: invalid msecs specification; "
418c2ecf20Sopenharmony_ci			"valid values are 0, 100-300000 in 100 increments\n",
428c2ecf20Sopenharmony_ci			val);
438c2ecf20Sopenharmony_ci		goto error_bad_value;
448c2ecf20Sopenharmony_ci	}
458c2ecf20Sopenharmony_ci	result = i2400m_set_idle_timeout(i2400m, val);
468c2ecf20Sopenharmony_ci	if (result >= 0)
478c2ecf20Sopenharmony_ci		result = size;
488c2ecf20Sopenharmony_cierror_no_unsigned:
498c2ecf20Sopenharmony_cierror_bad_value:
508c2ecf20Sopenharmony_ci	return result;
518c2ecf20Sopenharmony_ci}
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_cistatic
548c2ecf20Sopenharmony_ciDEVICE_ATTR_WO(i2400m_idle_timeout);
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistatic
578c2ecf20Sopenharmony_cistruct attribute *i2400m_dev_attrs[] = {
588c2ecf20Sopenharmony_ci	&dev_attr_i2400m_idle_timeout.attr,
598c2ecf20Sopenharmony_ci	NULL,
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct attribute_group i2400m_dev_attr_group = {
638c2ecf20Sopenharmony_ci	.name = NULL,		/* we want them in the same directory */
648c2ecf20Sopenharmony_ci	.attrs = i2400m_dev_attrs,
658c2ecf20Sopenharmony_ci};
66