1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * Linux WiMAX
4*4882a593Smuzhiyun * Implement and export a method for resetting a WiMAX device
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (C) 2008 Intel Corporation <linux-wimax@intel.com>
7*4882a593Smuzhiyun * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This implements a simple synchronous call to reset a WiMAX device.
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * Resets aim at being warm, keeping the device handles active;
12*4882a593Smuzhiyun * however, when that fails, it falls back to a cold reset (that will
13*4882a593Smuzhiyun * disconnect and reconnect the device).
14*4882a593Smuzhiyun */
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #include <net/wimax.h>
17*4882a593Smuzhiyun #include <net/genetlink.h>
18*4882a593Smuzhiyun #include <linux/wimax.h>
19*4882a593Smuzhiyun #include <linux/security.h>
20*4882a593Smuzhiyun #include <linux/export.h>
21*4882a593Smuzhiyun #include "wimax-internal.h"
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #define D_SUBMODULE op_reset
24*4882a593Smuzhiyun #include "debug-levels.h"
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun /**
28*4882a593Smuzhiyun * wimax_reset - Reset a WiMAX device
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * @wimax_dev: WiMAX device descriptor
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun * Returns:
33*4882a593Smuzhiyun *
34*4882a593Smuzhiyun * %0 if ok and a warm reset was done (the device still exists in
35*4882a593Smuzhiyun * the system).
36*4882a593Smuzhiyun *
37*4882a593Smuzhiyun * -%ENODEV if a cold/bus reset had to be done (device has
38*4882a593Smuzhiyun * disconnected and reconnected, so current handle is not valid
39*4882a593Smuzhiyun * any more).
40*4882a593Smuzhiyun *
41*4882a593Smuzhiyun * -%EINVAL if the device is not even registered.
42*4882a593Smuzhiyun *
43*4882a593Smuzhiyun * Any other negative error code shall be considered as
44*4882a593Smuzhiyun * non-recoverable.
45*4882a593Smuzhiyun *
46*4882a593Smuzhiyun * Description:
47*4882a593Smuzhiyun *
48*4882a593Smuzhiyun * Called when wanting to reset the device for any reason. Device is
49*4882a593Smuzhiyun * taken back to power on status.
50*4882a593Smuzhiyun *
51*4882a593Smuzhiyun * This call blocks; on successful return, the device has completed the
52*4882a593Smuzhiyun * reset process and is ready to operate.
53*4882a593Smuzhiyun */
wimax_reset(struct wimax_dev * wimax_dev)54*4882a593Smuzhiyun int wimax_reset(struct wimax_dev *wimax_dev)
55*4882a593Smuzhiyun {
56*4882a593Smuzhiyun int result = -EINVAL;
57*4882a593Smuzhiyun struct device *dev = wimax_dev_to_dev(wimax_dev);
58*4882a593Smuzhiyun enum wimax_st state;
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun might_sleep();
61*4882a593Smuzhiyun d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev);
62*4882a593Smuzhiyun mutex_lock(&wimax_dev->mutex);
63*4882a593Smuzhiyun dev_hold(wimax_dev->net_dev);
64*4882a593Smuzhiyun state = wimax_dev->state;
65*4882a593Smuzhiyun mutex_unlock(&wimax_dev->mutex);
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun if (state >= WIMAX_ST_DOWN) {
68*4882a593Smuzhiyun mutex_lock(&wimax_dev->mutex_reset);
69*4882a593Smuzhiyun result = wimax_dev->op_reset(wimax_dev);
70*4882a593Smuzhiyun mutex_unlock(&wimax_dev->mutex_reset);
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun dev_put(wimax_dev->net_dev);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun d_fnend(3, dev, "(wimax_dev %p) = %d\n", wimax_dev, result);
75*4882a593Smuzhiyun return result;
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun EXPORT_SYMBOL(wimax_reset);
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun * Exporting to user space over generic netlink
82*4882a593Smuzhiyun *
83*4882a593Smuzhiyun * Parse the reset command from user space, return error code.
84*4882a593Smuzhiyun *
85*4882a593Smuzhiyun * No attributes.
86*4882a593Smuzhiyun */
wimax_gnl_doit_reset(struct sk_buff * skb,struct genl_info * info)87*4882a593Smuzhiyun int wimax_gnl_doit_reset(struct sk_buff *skb, struct genl_info *info)
88*4882a593Smuzhiyun {
89*4882a593Smuzhiyun int result, ifindex;
90*4882a593Smuzhiyun struct wimax_dev *wimax_dev;
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info);
93*4882a593Smuzhiyun result = -ENODEV;
94*4882a593Smuzhiyun if (info->attrs[WIMAX_GNL_RESET_IFIDX] == NULL) {
95*4882a593Smuzhiyun pr_err("WIMAX_GNL_OP_RFKILL: can't find IFIDX attribute\n");
96*4882a593Smuzhiyun goto error_no_wimax_dev;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun ifindex = nla_get_u32(info->attrs[WIMAX_GNL_RESET_IFIDX]);
99*4882a593Smuzhiyun wimax_dev = wimax_dev_get_by_genl_info(info, ifindex);
100*4882a593Smuzhiyun if (wimax_dev == NULL)
101*4882a593Smuzhiyun goto error_no_wimax_dev;
102*4882a593Smuzhiyun /* Execute the operation and send the result back to user space */
103*4882a593Smuzhiyun result = wimax_reset(wimax_dev);
104*4882a593Smuzhiyun dev_put(wimax_dev->net_dev);
105*4882a593Smuzhiyun error_no_wimax_dev:
106*4882a593Smuzhiyun d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
107*4882a593Smuzhiyun return result;
108*4882a593Smuzhiyun }
109