^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Intel Wireless WiMAX Connection 2400m
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Sysfs interfaces to show driver and device information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2007 Intel Corporation <linux-wimax@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "i2400m.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define D_SUBMODULE sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "debug-levels.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * Set the idle timeout (msecs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * FIXME: eventually this should be a common WiMAX stack method, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * would like to wait to see how other devices manage it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) ssize_t i2400m_idle_timeout_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) const char *buf, size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ssize_t result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct i2400m *i2400m = net_dev_to_i2400m(to_net_dev(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (sscanf(buf, "%u\n", &val) != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) goto error_no_unsigned;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (val != 0 && (val < 100 || val > 300000 || val % 100 != 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) dev_err(dev, "idle_timeout: %u: invalid msecs specification; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) "valid values are 0, 100-300000 in 100 increments\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) goto error_bad_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) result = i2400m_set_idle_timeout(i2400m, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (result >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) result = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) error_no_unsigned:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) error_bad_value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) DEVICE_ATTR_WO(i2400m_idle_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct attribute *i2400m_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) &dev_attr_i2400m_idle_timeout.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct attribute_group i2400m_dev_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .name = NULL, /* we want them in the same directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .attrs = i2400m_dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };