1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
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
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
|
/*
* WUSB Wire Adapter: WLP interface
* Driver for the Linux Network stack.
*
* Copyright (C) 2005-2006 Intel Corporation
* Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*
* FIXME: docs
*
* Implementation of the netdevice linkage (except tx and rx related stuff).
*
* ROADMAP:
*
* ENTRY POINTS (Net device):
*
* i1480u_open(): Called when we ifconfig up the interface;
* associates to a UWB host controller, reserves
* bandwidth (MAS), sets up RX USB URB and starts
* the queue.
*
* i1480u_stop(): Called when we ifconfig down a interface;
* reverses _open().
*
* i1480u_set_config():
*/
#include <linux/if_arp.h>
#include <linux/etherdevice.h>
#include <linux/uwb/debug.h>
#include "i1480u-wlp.h"
struct i1480u_cmd_set_ip_mas {
struct uwb_rccb rccb;
struct uwb_dev_addr addr;
u8 stream;
u8 owner;
u8 type; /* enum uwb_drp_type */
u8 baMAS[32];
} __attribute__((packed));
static
int i1480u_set_ip_mas(
struct uwb_rc *rc,
const struct uwb_dev_addr *dstaddr,
u8 stream, u8 owner, u8 type, unsigned long *mas)
{
int result;
struct i1480u_cmd_set_ip_mas *cmd;
struct uwb_rc_evt_confirm reply;
result = -ENOMEM;
cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
if (cmd == NULL)
goto error_kzalloc;
cmd->rccb.bCommandType = 0xfd;
cmd->rccb.wCommand = cpu_to_le16(0x000e);
cmd->addr = *dstaddr;
cmd->stream = stream;
cmd->owner = owner;
cmd->type = type;
if (mas == NULL)
memset(cmd->baMAS, 0x00, sizeof(cmd->baMAS));
else
memcpy(cmd->baMAS, mas, sizeof(cmd->baMAS));
reply.rceb.bEventType = 0xfd;
reply.rceb.wEvent = cpu_to_le16(0x000e);
result = uwb_rc_cmd(rc, "SET-IP-MAS", &cmd->rccb, sizeof(*cmd),
&reply.rceb, sizeof(reply));
if (result < 0)
goto error_cmd;
if (reply.bResultCode != UWB_RC_RES_FAIL) {
dev_err(&rc->uwb_dev.dev,
"SET-IP-MAS: command execution failed: %d\n",
reply.bResultCode);
result = -EIO;
}
error_cmd:
kfree(cmd);
error_kzalloc:
return result;
}
/*
* Inform a WLP interface of a MAS reservation
*
* @rc is assumed refcnted.
*/
/* FIXME: detect if remote device is WLP capable? */
static int i1480u_mas_set_dev(struct uwb_dev *uwb_dev, struct uwb_rc *rc,
u8 stream, u8 owner, u8 type, unsigned long *mas)
{
int result = 0;
struct device *dev = &rc->uwb_dev.dev;
result = i1480u_set_ip_mas(rc, &uwb_dev->dev_addr, stream, owner,
type, mas);
if (result < 0) {
char rcaddrbuf[UWB_ADDR_STRSIZE], devaddrbuf[UWB_ADDR_STRSIZE];
uwb_dev_addr_print(rcaddrbuf, sizeof(rcaddrbuf),
&rc->uwb_dev.dev_addr);
uwb_dev_addr_print(devaddrbuf, sizeof(devaddrbuf),
&uwb_dev->dev_addr);
dev_err(dev, "Set IP MAS (%s to %s) failed: %d\n",
rcaddrbuf, devaddrbuf, result);
}
return result;
}
/**
* Called by bandwidth allocator when change occurs in reservation.
*
* @rsv: The reservation that is being established, modified, or
* terminated.
*
* When a reservation is established, modified, or terminated the upper layer
* (WLP here) needs set/update the currently available Media Access Slots
* that can be use for IP traffic.
*
* Our action taken during failure depends on how the reservation is being
* changed:
* - if reservation is being established we do nothing if we cannot set the
* new MAS to be used
* - if reservation is being terminated we revert back to PCA whether the
* SET IP MAS command succeeds or not.
*/
void i1480u_bw_alloc_cb(struct uwb_rsv *rsv)
{
int result = 0;
struct i1480u *i1480u = rsv->pal_priv;
struct device *dev = &i1480u->usb_iface->dev;
struct uwb_dev *target_dev = rsv->target.dev;
struct uwb_rc *rc = i1480u->wlp.rc;
u8 stream = rsv->stream;
int type = rsv->type;
int is_owner = rsv->owner == &rc->uwb_dev;
unsigned long *bmp = rsv->mas.bm;
dev_err(dev, "WLP callback called - sending set ip mas\n");
/*user cannot change options while setting configuration*/
mutex_lock(&i1480u->options.mutex);
switch (rsv->state) {
case UWB_RSV_STATE_T_ACCEPTED:
case UWB_RSV_STATE_O_ESTABLISHED:
result = i1480u_mas_set_dev(target_dev, rc, stream, is_owner,
type, bmp);
if (result < 0) {
dev_err(dev, "MAS reservation failed: %d\n", result);
goto out;
}
if (is_owner) {
wlp_tx_hdr_set_delivery_id_type(&i1480u->options.def_tx_hdr,
WLP_DRP | stream);
wlp_tx_hdr_set_rts_cts(&i1480u->options.def_tx_hdr, 0);
}
break;
case UWB_RSV_STATE_NONE:
/* revert back to PCA */
result = i1480u_mas_set_dev(target_dev, rc, stream, is_owner,
type, bmp);
if (result < 0)
dev_err(dev, "MAS reservation failed: %d\n", result);
/* Revert to PCA even though SET IP MAS failed. */
wlp_tx_hdr_set_delivery_id_type(&i1480u->options.def_tx_hdr,
i1480u->options.pca_base_priority);
wlp_tx_hdr_set_rts_cts(&i1480u->options.def_tx_hdr, 1);
break;
default:
dev_err(dev, "unexpected WLP reservation state: %s (%d).\n",
uwb_rsv_state_str(rsv->state), rsv->state);
break;
}
out:
mutex_unlock(&i1480u->options.mutex);
return;
}
/**
*
* Called on 'ifconfig up'
*/
int i1480u_open(struct net_device *net_dev)
{
int result;
struct i1480u *i1480u = netdev_priv(net_dev);
struct wlp *wlp = &i1480u->wlp;
struct uwb_rc *rc;
struct device *dev = &i1480u->usb_iface->dev;
rc = wlp->rc;
result = i1480u_rx_setup(i1480u); /* Alloc RX stuff */
if (result < 0)
goto error_rx_setup;
netif_wake_queue(net_dev);
#ifdef i1480u_FLOW_CONTROL
result = usb_submit_urb(i1480u->notif_urb, GFP_KERNEL);;
if (result < 0) {
dev_err(dev, "Can't submit notification URB: %d\n", result);
goto error_notif_urb_submit;
}
#endif
i1480u->uwb_notifs_handler.cb = i1480u_uwb_notifs_cb;
i1480u->uwb_notifs_handler.data = i1480u;
if (uwb_bg_joined(rc))
netif_carrier_on(net_dev);
else
netif_carrier_off(net_dev);
uwb_notifs_register(rc, &i1480u->uwb_notifs_handler);
/* Interface is up with an address, now we can create WSS */
result = wlp_wss_setup(net_dev, &wlp->wss);
if (result < 0) {
dev_err(dev, "Can't create WSS: %d. \n", result);
goto error_notif_deregister;
}
return 0;
error_notif_deregister:
uwb_notifs_deregister(rc, &i1480u->uwb_notifs_handler);
#ifdef i1480u_FLOW_CONTROL
error_notif_urb_submit:
#endif
netif_stop_queue(net_dev);
i1480u_rx_release(i1480u);
error_rx_setup:
return result;
}
/**
* Called on 'ifconfig down'
*/
int i1480u_stop(struct net_device *net_dev)
{
struct i1480u *i1480u = netdev_priv(net_dev);
struct wlp *wlp = &i1480u->wlp;
struct uwb_rc *rc = wlp->rc;
BUG_ON(wlp->rc == NULL);
wlp_wss_remove(&wlp->wss);
uwb_notifs_deregister(rc, &i1480u->uwb_notifs_handler);
netif_carrier_off(net_dev);
#ifdef i1480u_FLOW_CONTROL
usb_kill_urb(i1480u->notif_urb);
#endif
netif_stop_queue(net_dev);
i1480u_rx_release(i1480u);
i1480u_tx_release(i1480u);
return 0;
}
/** Report statistics */
struct net_device_stats *i1480u_get_stats(struct net_device *net_dev)
{
struct i1480u *i1480u = netdev_priv(net_dev);
return &i1480u->stats;
}
/**
*
* Change the interface config--we probably don't have to do anything.
*/
int i1480u_set_config(struct net_device *net_dev, struct ifmap *map)
{
int result;
struct i1480u *i1480u = netdev_priv(net_dev);
BUG_ON(i1480u->wlp.rc == NULL);
result = 0;
return result;
}
/**
* Change the MTU of the interface
*/
int i1480u_change_mtu(struct net_device *net_dev, int mtu)
{
static union {
struct wlp_tx_hdr tx;
struct wlp_rx_hdr rx;
} i1480u_all_hdrs;
if (mtu < ETH_HLEN) /* We encap eth frames */
return -ERANGE;
if (mtu > 4000 - sizeof(i1480u_all_hdrs))
return -ERANGE;
net_dev->mtu = mtu;
return 0;
}
/**
* Callback function to handle events from UWB
* When we see other devices we know the carrier is ok,
* if we are the only device in the beacon group we set the carrier
* state to off.
* */
void i1480u_uwb_notifs_cb(void *data, struct uwb_dev *uwb_dev,
enum uwb_notifs event)
{
struct i1480u *i1480u = data;
struct net_device *net_dev = i1480u->net_dev;
struct device *dev = &i1480u->usb_iface->dev;
switch (event) {
case UWB_NOTIF_BG_JOIN:
netif_carrier_on(net_dev);
dev_info(dev, "Link is up\n");
break;
case UWB_NOTIF_BG_LEAVE:
netif_carrier_off(net_dev);
dev_info(dev, "Link is down\n");
break;
default:
dev_err(dev, "don't know how to handle event %d from uwb\n",
event);
}
}
/**
* Stop the network queue
*
* Enable WLP substack to stop network queue. We also set the flow control
* threshold at this time to prevent the flow control from restarting the
* queue.
*
* we are loosing the current threshold value here ... FIXME?
*/
void i1480u_stop_queue(struct wlp *wlp)
{
struct i1480u *i1480u = container_of(wlp, struct i1480u, wlp);
struct net_device *net_dev = i1480u->net_dev;
i1480u->tx_inflight.threshold = 0;
netif_stop_queue(net_dev);
}
/**
* Start the network queue
*
* Enable WLP substack to start network queue. Also re-enable the flow
* control to manage the queue again.
*
* We re-enable the flow control by storing the default threshold in the
* flow control threshold. This means that if the user modified the
* threshold before the queue was stopped and restarted that information
* will be lost. FIXME?
*/
void i1480u_start_queue(struct wlp *wlp)
{
struct i1480u *i1480u = container_of(wlp, struct i1480u, wlp);
struct net_device *net_dev = i1480u->net_dev;
i1480u->tx_inflight.threshold = i1480u_TX_INFLIGHT_THRESHOLD;
netif_start_queue(net_dev);
}
|