usb_ethernet.c (217556) | usb_ethernet.c (226709) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/net/usb_ethernet.c 217556 2011-01-18 21:14:23Z mdf $ */ | 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 | 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/stdint.h> 28#include <sys/stddef.h> | 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 |
29#include <sys/param.h> | 30#include <sys/param.h> |
30#include <sys/queue.h> 31#include <sys/types.h> | |
32#include <sys/systm.h> | 31#include <sys/systm.h> |
33#include <sys/kernel.h> | |
34#include <sys/bus.h> | 32#include <sys/bus.h> |
35#include <sys/module.h> | 33#include <sys/condvar.h> 34#include <sys/kernel.h> |
36#include <sys/lock.h> | 35#include <sys/lock.h> |
36#include <sys/malloc.h> 37#include <sys/mbuf.h> 38#include <sys/module.h> |
|
37#include <sys/mutex.h> | 39#include <sys/mutex.h> |
38#include <sys/condvar.h> | 40#include <sys/socket.h> 41#include <sys/sockio.h> |
39#include <sys/sysctl.h> 40#include <sys/sx.h> | 42#include <sys/sysctl.h> 43#include <sys/sx.h> |
41#include <sys/unistd.h> 42#include <sys/callout.h> 43#include <sys/malloc.h> 44#include <sys/priv.h> | |
45 | 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 |
|
46#include <dev/usb/usb.h> 47#include <dev/usb/usbdi.h> 48 49#include <dev/usb/usb_process.h> 50#include <dev/usb/net/usb_ethernet.h> 51 52SYSCTL_NODE(_net, OID_AUTO, ue, CTLFLAG_RD, 0, "USB Ethernet parameters"); 53 --- 138 unchanged lines hidden (view full) --- 192 ue->ue_methods->ue_attach_post(ue); 193 194 UE_UNLOCK(ue); 195 196 ue->ue_unit = alloc_unr(ueunit); 197 usb_callout_init_mtx(&ue->ue_watchdog, ue->ue_mtx, 0); 198 sysctl_ctx_init(&ue->ue_sysctl_ctx); 199 | 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; |
|
200 ifp = if_alloc(IFT_ETHER); 201 if (ifp == NULL) { 202 device_printf(ue->ue_dev, "could not allocate ifnet\n"); | 209 ifp = if_alloc(IFT_ETHER); 210 if (ifp == NULL) { 211 device_printf(ue->ue_dev, "could not allocate ifnet\n"); |
203 goto error; | 212 goto fail; |
204 } 205 206 ifp->if_softc = ue; 207 if_initname(ifp, "ue", ue->ue_unit); | 213 } 214 215 ifp->if_softc = ue; 216 if_initname(ifp, "ue", ue->ue_unit); |
208 ifp->if_mtu = ETHERMTU; 209 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; 210 if (ue->ue_methods->ue_ioctl != NULL) 211 ifp->if_ioctl = ue->ue_methods->ue_ioctl; 212 else 213 ifp->if_ioctl = uether_ioctl; 214 ifp->if_start = ue_start; 215 ifp->if_init = ue_init; 216 IFQ_SET_MAXLEN(&ifp->if_snd, ifqmaxlen); 217 ifp->if_snd.ifq_drv_maxlen = ifqmaxlen; 218 IFQ_SET_READY(&ifp->if_snd); 219 ue->ue_ifp = ifp; | 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; |
220 | 233 |
221 if (ue->ue_methods->ue_mii_upd != NULL && 222 ue->ue_methods->ue_mii_sts != NULL) { 223 mtx_lock(&Giant); /* device_xxx() depends on this */ 224 error = mii_attach(ue->ue_dev, &ue->ue_miibus, ifp, 225 ue_ifmedia_upd, ue->ue_methods->ue_mii_sts, 226 BMSR_DEFCAPMASK, MII_PHY_ANY, MII_OFFSET_ANY, 0); 227 mtx_unlock(&Giant); 228 if (error) { 229 device_printf(ue->ue_dev, "attaching PHYs failed\n"); 230 goto error; | 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); |
231 } 232 } 233 | 242 } 243 } 244 |
245 if (error) { 246 device_printf(ue->ue_dev, "attaching PHYs failed\n"); 247 goto fail; 248 } 249 |
|
234 if_printf(ifp, "<USB Ethernet> on %s\n", device_get_nameunit(ue->ue_dev)); 235 ether_ifattach(ifp, ue->ue_eaddr); | 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); |
|
236 237 snprintf(num, sizeof(num), "%u", ue->ue_unit); 238 ue->ue_sysctl_oid = SYSCTL_ADD_NODE(&ue->ue_sysctl_ctx, 239 &SYSCTL_NODE_CHILDREN(_net, ue), 240 OID_AUTO, num, CTLFLAG_RD, NULL, ""); 241 SYSCTL_ADD_PROC(&ue->ue_sysctl_ctx, 242 SYSCTL_CHILDREN(ue->ue_sysctl_oid), OID_AUTO, 243 "%parent", CTLTYPE_STRING | CTLFLAG_RD, ue, 0, 244 ue_sysctl_parent, "A", "parent device"); 245 246 UE_LOCK(ue); 247 return; 248 | 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 |
249error: | 268fail: |
250 free_unr(ueunit, ue->ue_unit); 251 if (ue->ue_ifp != NULL) { 252 if_free(ue->ue_ifp); 253 ue->ue_ifp = NULL; 254 } 255 UE_LOCK(ue); 256 return; 257} --- 44 unchanged lines hidden (view full) --- 302} 303 304uint8_t 305uether_is_gone(struct usb_ether *ue) 306{ 307 return (usb_proc_is_gone(&ue->ue_tq)); 308} 309 | 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 |
|
310static void 311ue_init(void *arg) 312{ 313 struct usb_ether *ue = arg; 314 315 UE_LOCK(ue); 316 ue_queue_command(ue, ue_start_task, 317 &ue->ue_sync_task[0].hdr, --- 29 unchanged lines hidden (view full) --- 347 348 UE_LOCK_ASSERT(ue, MA_OWNED); 349 350 usb_callout_stop(&ue->ue_watchdog); 351 352 ue->ue_methods->ue_stop(ue); 353} 354 | 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 |
|
355static void 356ue_start(struct ifnet *ifp) 357{ 358 struct usb_ether *ue = ifp->if_softc; 359 360 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) 361 return; 362 --- 17 unchanged lines hidden (view full) --- 380{ 381 struct usb_ether_cfg_task *task = 382 (struct usb_ether_cfg_task *)_task; 383 struct usb_ether *ue = task->ue; 384 385 ue->ue_methods->ue_setmulti(ue); 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 |
|
388static int 389ue_ifmedia_upd(struct ifnet *ifp) 390{ 391 struct usb_ether *ue = ifp->if_softc; 392 393 /* Defer to process context */ 394 UE_LOCK(ue); 395 ue_queue_command(ue, ue_ifmedia_task, --- 205 unchanged lines hidden --- | 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 --- |