Re: [PATCH RFC 6/6] Modify tag_ksz.c to support other KSZ switch drivers

From: Andrew Lunn
Date: Mon Sep 18 2017 - 18:42:47 EST


On Mon, Sep 18, 2017 at 08:55:17PM +0000, Tristram.Ha@xxxxxxxxxxxxx wrote:
> > > > This is ugly. We have a clean separation between a switch driver and a
> > > > tag driver. Here you are mixing them together. Don't. Look at the
> > > > mailing lists for what Florian and I suggested to Pavel. It will also
> > > > solve your include file issue above.
> > >
> > > It seems to me all tag_*.c are hard-coded. They do not have access to
> > > the switch device and just use the bit definitions defined in the top to
> > > do the job.
> > >
> > > This creates a problem for all KSZ switch devices as they have different
> > > tail tag formats and lengths. There will be potentially 4 additional
> > > DSA_TAG_PROT_KSZ* just to handle them. Extra files will be added
> > > with about the same code.
> >
> > Hi Tristram
> >
> > Think about factoring out the common code into a shared functions.
> >
>
> I am a little unsure what you have in mind. Can you elaborate?

You say you need 4 DSA_TAG_PROT_KSZ. I guess the code is nearly
identical in them all? If i remember correctly, the two tag bytes are
the other way around?

static int ksz8k_xmit( *skb, struct net_device *dev)
{
uint8* tag;

tag = ksz_xmit(skb, dev)
if (!tag)
return NULL;

tag[0] = 1 << p->dp->index;
tag[1] = 0;

return skb;
}

static int ksz9k_xmit( *skb, struct net_device *dev)
{
uint8* tag;

tag = ksz_xmit(skb, dev)
if (!tag)
return NULL;

tag[0] = 0;
tag[1] = 1 << p->dp->index;

return skb;
}

const struct dsa_device_ops ksz8k_netdev_ops = {
.xmit = ksz8k_xmit,
.rcv = ksz8k_rcv,
};

const struct dsa_device_ops ksz9k_netdev_ops = {
.xmit = ksz9k_xmit,
.rcv = ksz9k_rcv,
};

Andrew