Deleted Added
sdiff udiff text old ( 217556 ) new ( 226709 )
full compact
1/* $FreeBSD: head/sys/dev/usb/net/usb_ethernet.c 226709 2011-10-24 23:38:11Z yongari $ */
2/*-
3 * Copyright (c) 2009 Andrew Thompson (thompsa@FreeBSD.org)
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/usb/net/usb_ethernet.c 226709 2011-10-24 23:38:11Z yongari $");
29
30#include <sys/param.h>
31#include <sys/systm.h>
32#include <sys/bus.h>
33#include <sys/condvar.h>
34#include <sys/kernel.h>
35#include <sys/lock.h>
36#include <sys/malloc.h>
37#include <sys/mbuf.h>
38#include <sys/module.h>
39#include <sys/mutex.h>
40#include <sys/socket.h>
41#include <sys/sockio.h>
42#include <sys/sysctl.h>
43#include <sys/sx.h>
44
45#include <net/if.h>
46#include <net/ethernet.h>
47#include <net/if_types.h>
48#include <net/if_media.h>
49#include <net/if_vlan_var.h>
50
51#include <dev/mii/mii.h>
52#include <dev/mii/miivar.h>
53
54#include <dev/usb/usb.h>
55#include <dev/usb/usbdi.h>
56
57#include <dev/usb/usb_process.h>
58#include <dev/usb/net/usb_ethernet.h>
59
60SYSCTL_NODE(_net, OID_AUTO, ue, CTLFLAG_RD, 0, "USB Ethernet parameters");
61

--- 138 unchanged lines hidden (view full) ---

200 ue->ue_methods->ue_attach_post(ue);
201
202 UE_UNLOCK(ue);
203
204 ue->ue_unit = alloc_unr(ueunit);
205 usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_mtx, 0);
206 sysctl_ctx_init(&ue->ue_sysctl_ctx);
207
208 error = 0;
209 ifp = if_alloc(IFT_ETHER);
210 if (ifp == NULL) {
211 device_printf(ue->ue_dev, "could not allocate ifnet\n");
212 goto fail;
213 }
214
215 ifp->if_softc = ue;
216 if_initname(ifp, "ue", ue->ue_unit);
217 if (ue->ue_methods->ue_attach_post_sub != NULL) {
218 ue->ue_ifp = ifp;
219 error = ue->ue_methods->ue_attach_post_sub(ue);
220 } else {
221 ifp->if_mtu = ETHERMTU;
222 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
223 if (ue->ue_methods->ue_ioctl != NULL)
224 ifp->if_ioctl = ue->ue_methods->ue_ioctl;
225 else
226 ifp->if_ioctl = uether_ioctl;
227 ifp->if_start = ue_start;
228 ifp->if_init = ue_init;
229 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen);
230 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen;
231 IFQ_SET_READY(&ifp->if_snd);
232 ue->ue_ifp = ifp;
233
234 if (ue->ue_methods->ue_mii_upd != NULL &&
235 ue->ue_methods->ue_mii_sts != NULL) {
236 /* device_xxx() depends on this */
237 mtx_lock(&Giant);
238 error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp,
239 ue_ifmedia_upd, ue->ue_methods->ue_mii_sts,
240 BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0);
241 mtx_unlock(&Giant);
242 }
243 }
244
245 if (error) {
246 device_printf(ue->ue_dev, "attaching PHYs failed\n");
247 goto fail;
248 }
249
250 if_printf(ifp, "<USB Ethernet> on %s\n", device_get_nameunit(ue->ue_dev));
251 ether_ifattach(ifp, ue->ue_eaddr);
252 /* Tell upper layer we support VLAN oversized frames. */
253 if (ifp->if_capabilities & IFCAP_VLAN_MTU)
254 ifp->if_hdrlen = sizeof(struct ether_vlan_header);
255
256 snprintf(num, sizeof(num), "%u", ue->ue_unit);
257 ue->ue_sysctl_oid = SYSCTL_ADD_NODE(&ue->ue_sysctl_ctx,
258 &SYSCTL_NODE_CHILDREN(_net, ue),
259 OID_AUTO, num, CTLFLAG_RD, NULL, "");
260 SYSCTL_ADD_PROC(&ue->ue_sysctl_ctx,
261 SYSCTL_CHILDREN(ue->ue_sysctl_oid), OID_AUTO,
262 "%parent", CTLTYPE_STRING | CTLFLAG_RD, ue, 0,
263 ue_sysctl_parent, "A", "parent device");
264
265 UE_LOCK(ue);
266 return;
267
268fail:
269 free_unr(ueunit, ue->ue_unit);
270 if (ue->ue_ifp != NULL) {
271 if_free(ue->ue_ifp);
272 ue->ue_ifp = NULL;
273 }
274 UE_LOCK(ue);
275 return;
276}

--- 44 unchanged lines hidden (view full) ---

321}
322
323uint8_t
324uether_is_gone(struct usb_ether *ue)
325{
326 return (usb_proc_is_gone(&ue->ue_tq));
327}
328
329void
330uether_init(void *arg)
331{
332
333 ue_init(arg);
334}
335
336static void
337ue_init(void *arg)
338{
339 struct usb_ether *ue = arg;
340
341 UE_LOCK(ue);
342 ue_queue_command(ue, ue_start_task,
343 &ue->ue_sync_task[0].hdr,

--- 29 unchanged lines hidden (view full) ---

373
374 UE_LOCK_ASSERT(ue, MA_OWNED);
375
376 usb_callout_stop(&ue->ue_watchdog);
377
378 ue->ue_methods->ue_stop(ue);
379}
380
381void
382uether_start(struct ifnet *ifp)
383{
384
385 ue_start(ifp);
386}
387
388static void
389ue_start(struct ifnet *ifp)
390{
391 struct usb_ether *ue = ifp->if_softc;
392
393 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0)
394 return;
395

--- 17 unchanged lines hidden (view full) ---

413{
414 struct usb_ether_cfg_task *task =
415 (struct usb_ether_cfg_task *)_task;
416 struct usb_ether *ue = task->ue;
417
418 ue->ue_methods->ue_setmulti(ue);
419}
420
421int
422uether_ifmedia_upd(struct ifnet *ifp)
423{
424
425 return (ue_ifmedia_upd(ifp));
426}
427
428static int
429ue_ifmedia_upd(struct ifnet *ifp)
430{
431 struct usb_ether *ue = ifp->if_softc;
432
433 /* Defer to process context */
434 UE_LOCK(ue);
435 ue_queue_command(ue, ue_ifmedia_task,

--- 205 unchanged lines hidden ---