2 * Intel Wireless WiMAX Connection 2400m
3 * Implement backend for the WiMAX stack rfkill support
6 * Copyright (C) 2007-2008 Intel Corporation <linux-wimax@intel.com>
7 * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * The WiMAX kernel stack integrates into RF-Kill and keeps the
25 * switches's status. We just need to:
27 * - report changes in the HW RF Kill switch [with
28 * wimax_rfkill_{sw,hw}_report(), which happens when we detect those
29 * indications coming through hardware reports]. We also do it on
30 * initialization to let the stack know the initial HW state.
32 * - implement indications from the stack to change the SW RF Kill
33 * switch (coming from sysfs, the wimax stack or user space).
36 #include <linux/wimax/i2400m.h>
37 #include <linux/slab.h>
41 #define D_SUBMODULE rfkill
42 #include "debug-levels.h"
45 * Return true if the i2400m radio is in the requested wimax_rf_state state
49 int i2400m_radio_is(struct i2400m
*i2400m
, enum wimax_rf_state state
)
51 if (state
== WIMAX_RF_OFF
)
52 return i2400m
->state
== I2400M_SS_RF_OFF
53 || i2400m
->state
== I2400M_SS_RF_SHUTDOWN
;
54 else if (state
== WIMAX_RF_ON
)
55 /* state == WIMAX_RF_ON */
56 return i2400m
->state
!= I2400M_SS_RF_OFF
57 && i2400m
->state
!= I2400M_SS_RF_SHUTDOWN
;
60 return -EINVAL
; /* shut gcc warnings on certain arches */
66 * WiMAX stack operation: implement SW RFKill toggling
68 * @wimax_dev: device descriptor
69 * @skb: skb where the message has been received; skb->data is
70 * expected to point to the message payload.
71 * @genl_info: passed by the generic netlink layer
73 * Generic Netlink will call this function when a message is sent from
74 * userspace to change the software RF-Kill switch status.
76 * This function will set the device's software RF-Kill switch state to
77 * match what is requested.
79 * NOTE: the i2400m has a strict state machine; we can only set the
80 * RF-Kill switch when it is on, the HW RF-Kill is on and the
81 * device is initialized. So we ignore errors steaming from not
82 * being in the right state (-EILSEQ).
84 int i2400m_op_rfkill_sw_toggle(struct wimax_dev
*wimax_dev
,
85 enum wimax_rf_state state
)
88 struct i2400m
*i2400m
= wimax_dev_to_i2400m(wimax_dev
);
89 struct device
*dev
= i2400m_dev(i2400m
);
90 struct sk_buff
*ack_skb
;
92 struct i2400m_l3l4_hdr hdr
;
93 struct i2400m_tlv_rf_operation sw_rf
;
97 d_fnstart(4, dev
, "(wimax_dev %p state %d)\n", wimax_dev
, state
);
100 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
103 cmd
->hdr
.type
= cpu_to_le16(I2400M_MT_CMD_RF_CONTROL
);
104 cmd
->hdr
.length
= sizeof(cmd
->sw_rf
);
105 cmd
->hdr
.version
= cpu_to_le16(I2400M_L3L4_VERSION
);
106 cmd
->sw_rf
.hdr
.type
= cpu_to_le16(I2400M_TLV_RF_OPERATION
);
107 cmd
->sw_rf
.hdr
.length
= cpu_to_le16(sizeof(cmd
->sw_rf
.status
));
109 case WIMAX_RF_OFF
: /* RFKILL ON, radio OFF */
110 cmd
->sw_rf
.status
= cpu_to_le32(2);
112 case WIMAX_RF_ON
: /* RFKILL OFF, radio ON */
113 cmd
->sw_rf
.status
= cpu_to_le32(1);
119 ack_skb
= i2400m_msg_to_dev(i2400m
, cmd
, sizeof(*cmd
));
120 result
= PTR_ERR(ack_skb
);
121 if (IS_ERR(ack_skb
)) {
122 dev_err(dev
, "Failed to issue 'RF Control' command: %d\n",
124 goto error_msg_to_dev
;
126 result
= i2400m_msg_check_status(wimax_msg_data(ack_skb
),
127 strerr
, sizeof(strerr
));
129 dev_err(dev
, "'RF Control' (0x%04x) command failed: %d - %s\n",
130 I2400M_MT_CMD_RF_CONTROL
, result
, strerr
);
134 /* Now we wait for the state to change to RADIO_OFF or RADIO_ON */
135 result
= wait_event_timeout(
136 i2400m
->state_wq
, i2400m_radio_is(i2400m
, state
),
141 dev_err(dev
, "Error waiting for device to toggle RF state: "
148 d_fnend(4, dev
, "(wimax_dev %p state %d) = %d\n",
149 wimax_dev
, state
, result
);
155 * Inform the WiMAX stack of changes in the RF Kill switches reported
158 * @i2400m: device descriptor
159 * @rfss: TLV for RF Switches status; already validated
161 * NOTE: the reports on RF switch status cannot be trusted
162 * or used until the device is in a state of RADIO_OFF
165 void i2400m_report_tlv_rf_switches_status(
166 struct i2400m
*i2400m
,
167 const struct i2400m_tlv_rf_switches_status
*rfss
)
169 struct device
*dev
= i2400m_dev(i2400m
);
170 enum i2400m_rf_switch_status hw
, sw
;
171 enum wimax_st wimax_state
;
173 sw
= le32_to_cpu(rfss
->sw_rf_switch
);
174 hw
= le32_to_cpu(rfss
->hw_rf_switch
);
176 d_fnstart(3, dev
, "(i2400m %p rfss %p [hw %u sw %u])\n",
177 i2400m
, rfss
, hw
, sw
);
178 /* We only process rw switch evens when the device has been
179 * fully initialized */
180 wimax_state
= wimax_state_get(&i2400m
->wimax_dev
);
181 if (wimax_state
< WIMAX_ST_RADIO_OFF
) {
182 d_printf(3, dev
, "ignoring RF switches report, state %u\n",
187 case I2400M_RF_SWITCH_ON
: /* RF Kill disabled (radio on) */
188 wimax_report_rfkill_sw(&i2400m
->wimax_dev
, WIMAX_RF_ON
);
190 case I2400M_RF_SWITCH_OFF
: /* RF Kill enabled (radio off) */
191 wimax_report_rfkill_sw(&i2400m
->wimax_dev
, WIMAX_RF_OFF
);
194 dev_err(dev
, "HW BUG? Unknown RF SW state 0x%x\n", sw
);
198 case I2400M_RF_SWITCH_ON
: /* RF Kill disabled (radio on) */
199 wimax_report_rfkill_hw(&i2400m
->wimax_dev
, WIMAX_RF_ON
);
201 case I2400M_RF_SWITCH_OFF
: /* RF Kill enabled (radio off) */
202 wimax_report_rfkill_hw(&i2400m
->wimax_dev
, WIMAX_RF_OFF
);
205 dev_err(dev
, "HW BUG? Unknown RF HW state 0x%x\n", hw
);
208 d_fnend(3, dev
, "(i2400m %p rfss %p [hw %u sw %u]) = void\n",
209 i2400m
, rfss
, hw
, sw
);