From owner-freebsd-arm@freebsd.org Fri Nov 11 14:43:13 2016 Return-Path: Delivered-To: freebsd-arm@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E230AC3BBB0 for ; Fri, 11 Nov 2016 14:43:13 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (mail.turbocat.net [IPv6:2a01:4f8:d16:4514::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 95DD51AD9 for ; Fri, 11 Nov 2016 14:43:13 +0000 (UTC) (envelope-from hps@selasky.org) Received: from laptop015.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 52E741FE022; Fri, 11 Nov 2016 15:43:11 +0100 (CET) Subject: Re: How to change MAC address on RPI-B? To: John.Kitz@xs4all.nl, freebsd-arm@freebsd.org References: <005701d23a7d$71400630$53c01290$@Kitz@xs4all.nl> <20161110065105.77a19e3b@X220.alogt.com> <000c01d23b3a$c06e1ef0$414a5cd0$@Kitz@xs4all.nl> <20161111094930.46f55a60@X220.alogt.com> <000f01d23c14$da3a6c00$8eaf4400$@Kitz@xs4all.nl> From: Hans Petter Selasky Message-ID: <445c56a4-2c35-cb4c-f729-950d4e758d8d@selasky.org> Date: Fri, 11 Nov 2016 15:48:22 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <000f01d23c14$da3a6c00$8eaf4400$@Kitz@xs4all.nl> Content-Type: multipart/mixed; boundary="------------03AE974032C9AA41663BC4B6" X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Porting FreeBSD to ARM processors." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Nov 2016 14:43:14 -0000 This is a multi-part message in MIME format. --------------03AE974032C9AA41663BC4B6 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Hi, Does the attached patch solve the problem? --HPS --------------03AE974032C9AA41663BC4B6 Content-Type: text/x-patch; name="if_smsc_mac.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="if_smsc_mac.diff" Index: sys/dev/usb/net/if_smsc.c =================================================================== --- sys/dev/usb/net/if_smsc.c (revision 308426) +++ sys/dev/usb/net/if_smsc.c (working copy) @@ -152,7 +152,7 @@ device_printf((sc)->sc_ue.ue_dev, "debug: " fmt, ##args); \ } while(0) #else -#define smsc_dbg_printf(sc, fmt, args...) +#define smsc_dbg_printf(sc, fmt, args...) do { } while (0) #endif #define smsc_warn_printf(sc, fmt, args...) \ @@ -187,6 +187,7 @@ static uether_fn_t smsc_stop; static uether_fn_t smsc_start; static uether_fn_t smsc_tick; +static uether_fn_t smsc_setmac; static uether_fn_t smsc_setmulti; static uether_fn_t smsc_setpromisc; @@ -234,6 +235,7 @@ .ue_init = smsc_init, .ue_stop = smsc_stop, .ue_tick = smsc_tick, + .ue_setmac = smsc_setmac, .ue_setmulti = smsc_setmulti, .ue_setpromisc = smsc_setpromisc, .ue_mii_upd = smsc_ifmedia_upd, @@ -822,7 +824,6 @@ return (0); } - /** * smsc_setmacaddress - Sets the mac address in the device * @sc: driver soft context @@ -860,6 +861,25 @@ } /** + * smsc_setmac - Setup new MAC address + * @ue: usb ethernet device context + * + * LOCKING: + * Should be called with the SMSC lock held. + */ +static void +smsc_setmac(struct usb_ether *ue) +{ + struct smsc_softc *sc = uether_getsc(ue); + struct ifnet *ifp = uether_getifp(ue); + + SMSC_LOCK_ASSERT(sc, MA_OWNED); + + if (smsc_setmacaddress(sc, IF_LLADDR(ifp))) + smsc_dbg_printf(sc, "setting MAC address failed\n"); +} + +/** * smsc_reset - Reset the SMSC chip * @sc: device soft context * Index: sys/dev/usb/net/usb_ethernet.c =================================================================== --- sys/dev/usb/net/usb_ethernet.c (revision 308426) +++ sys/dev/usb/net/usb_ethernet.c (working copy) @@ -72,6 +72,7 @@ static usb_proc_callback_t ue_attach_post_task; static usb_proc_callback_t ue_promisc_task; +static usb_proc_callback_t ue_setmac_task; static usb_proc_callback_t ue_setmulti_task; static usb_proc_callback_t ue_ifmedia_task; static usb_proc_callback_t ue_tick_task; @@ -410,7 +411,8 @@ (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - ue->ue_methods->ue_setpromisc(ue); + if (ue->ue_methods->ue_setpromisc != NULL) + ue->ue_methods->ue_setpromisc(ue); } static void @@ -420,9 +422,21 @@ (struct usb_ether_cfg_task *)_task; struct usb_ether *ue = task->ue; - ue->ue_methods->ue_setmulti(ue); + if (ue->ue_methods->ue_setmulti != NULL) + ue->ue_methods->ue_setmulti(ue); } +static void +ue_setmac_task(struct usb_proc_msg *_task) +{ + struct usb_ether_cfg_task *task = + (struct usb_ether_cfg_task *)_task; + struct usb_ether *ue = task->ue; + + if (ue->ue_methods->ue_setmac != NULL) + ue->ue_methods->ue_setmac(ue); +} + int uether_ifmedia_upd(struct ifnet *ifp) { @@ -529,6 +543,16 @@ } else error = ether_ioctl(ifp, command, data); break; + case SIOCGIFADDR: + error = ether_ioctl(ifp, command, data); + if (error == 0) { + UE_LOCK(ue); + ue_queue_command(ue, ue_setmac_task, + &ue->ue_mac_task[0].hdr, + &ue->ue_mac_task[1].hdr); + UE_UNLOCK(ue); + } + break; default: error = ether_ioctl(ifp, command, data); break; Index: sys/dev/usb/net/usb_ethernet.h =================================================================== --- sys/dev/usb/net/usb_ethernet.h (revision 308426) +++ sys/dev/usb/net/usb_ethernet.h (working copy) @@ -61,6 +61,7 @@ uether_fn_t *ue_start; uether_fn_t *ue_init; uether_fn_t *ue_stop; + uether_fn_t *ue_setmac; uether_fn_t *ue_setmulti; uether_fn_t *ue_setpromisc; uether_fn_t *ue_tick; @@ -96,6 +97,7 @@ struct usb_ether_cfg_task ue_multi_task[2]; struct usb_ether_cfg_task ue_promisc_task[2]; struct usb_ether_cfg_task ue_tick_task[2]; + struct usb_ether_cfg_task ue_mac_task[2]; int ue_unit; --------------03AE974032C9AA41663BC4B6--