# Re: \[PATCH v3 net-next\] net: dsa: Modify tag\_ksz.c so that tail tag code can be used by other KSZ switch drivers

- From: Andrew Lunn \<andrew@lunn.ch\>
- Date: 2017-12-06 23:23:09 
- List: netdev
- Page: https://ratatoskr.run/netdev/2017/12/11075780
- Thread: https://ratatoskr.run/netdev/2017/12/11075670/t.md

```text
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
```
