From: Andrew Lunn Subject: Re: [PATCH v3 net-next] net: dsa: Modify tag_ksz.c so that tail tag code can be used by other KSZ switch drivers Date: Thu, 7 Dec 2017 00:23:06 +0100 Message-ID: <20171206232306.GF28774@lunn.ch> References: <1512524834-16290-1-git-send-email-Tristram.Ha@microchip.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Florian Fainelli , Pavel Machek , Ruediger Schmitt , muvarov@gmail.com, nathan.leigh.conrad@gmail.com, vivien.didelot@savoirfairelinux.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org To: Tristram.Ha@microchip.com Return-path: Received: from vps0.lunn.ch ([185.16.172.187]:50229 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751604AbdLFXXJ (ORCPT ); Wed, 6 Dec 2017 18:23:09 -0500 Content-Disposition: inline In-Reply-To: <1512524834-16290-1-git-send-email-Tristram.Ha@microchip.com> Sender: netdev-owner@vger.kernel.org List-ID: On Tue, Dec 05, 2017 at 05:47:14PM -0800, Tristram.Ha@microchip.com wrote: > +static int ksz9477_get_tag(u8 *tag, int *port) > +{ > + *port = tag[0] & 7; > + return KSZ_EGRESS_TAG_LEN; > +} > + > +static void ksz9477_set_tag(void *ptr, u8 *addr, int p) > +{ > + u16 *tag = (u16 *)ptr; > + > + *tag = 1 << p; > + *tag = cpu_to_be16(*tag); > +} Hi Tristram It would be more normal to create an ops structure struct ksz_tag_ops { int (*get_tag)(u8 *tag, int *port); void (*set_tag)(void *ptr, u8 *addr, int p) }; static const struct ksz_tag_ops ksz9477_tag_ops = { .get_tag = ksz9477_get_tag, .set_tag = ksz9477_set_tag, } and then pass this to the functions. It might even be possible to make this more generic, use it for other tag drivers. Andrew