diff mbox

[net-next-2.6] vlan: introduce ndo_vlan_[enable/disable]

Message ID 1310811359-4440-1-git-send-email-jpirko@redhat.com
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Jiri Pirko July 16, 2011, 10:15 a.m. UTC
Some devices are not able to enable/disable rx/tw vlan accel separately.
they depend on ndo_vlan_rx_register to know if to enable of disable
hw accel. And since ndo_vlan_rx_register is going to die soon,
this must be resolved.

One solution might be to enable accel on device start every time, even
if there are no vlan up on. But this would change behaviour and might
lead to possible regression (on older devices).

Better is to preserve current behaviour and introduce a couple of ndos
to let device driver know when to enable/disable vlan accel. They are
alled at the same time as ndo_vlan_rx_register.

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
---
 include/linux/netdevice.h |   14 ++++++++++++++
 net/8021q/vlan.c          |    4 ++++
 2 files changed, 18 insertions(+), 0 deletions(-)

Comments

=?ISO-8859-2?Q?Micha=B3_Miros=B3aw?= July 16, 2011, 2:14 p.m. UTC | #1
2011/7/16 Jiri Pirko <jpirko@redhat.com>:
> Some devices are not able to enable/disable rx/tw vlan accel separately.
> they depend on ndo_vlan_rx_register to know if to enable of disable
> hw accel. And since ndo_vlan_rx_register is going to die soon,
> this must be resolved.
>
> One solution might be to enable accel on device start every time, even
> if there are no vlan up on. But this would change behaviour and might
> lead to possible regression (on older devices).
[...]

Please describe the possible regression. As I see it, there won't be
any user visible change of behaviour - network code takes care of
reinserting VLAN tag when necessary. If you think that disabling tag
stripping is beneficial for cases where no VLANs are configured, it's
better to do that in netdev_fix_features() for devices which advertise
NETIF_F_HW_VLAN_RX in hw_features.

Best Regards,
Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Pirko July 17, 2011, 7:30 a.m. UTC | #2
Sat, Jul 16, 2011 at 04:14:36PM CEST, mirqus@gmail.com wrote:
>2011/7/16 Jiri Pirko <jpirko@redhat.com>:
>> Some devices are not able to enable/disable rx/tw vlan accel separately.
>> they depend on ndo_vlan_rx_register to know if to enable of disable
>> hw accel. And since ndo_vlan_rx_register is going to die soon,
>> this must be resolved.
>>
>> One solution might be to enable accel on device start every time, even
>> if there are no vlan up on. But this would change behaviour and might
>> lead to possible regression (on older devices).
>[...]
>
>Please describe the possible regression. As I see it, there won't be
>any user visible change of behaviour - network code takes care of
>reinserting VLAN tag when necessary. If you think that disabling tag
>stripping is beneficial for cases where no VLANs are configured, it's
>better to do that in netdev_fix_features() for devices which advertise
>NETIF_F_HW_VLAN_RX in hw_features.

Well I just wanted to preserve current behaviour which is that in many
drivers vlan accel is enabled only if some vid is registered upon the
device and it's disabled again when no vid is registered. I can see
no way to do this with current code after removing ndo_vlan_rx_register.

I expect unexpected problems on old cards when vlan accel would be
enabled all the time, but maybe I'm wrong...

One idea is for device which do not support sepatate rx/tx vlan accel
enabling/disabling they can probably use ndo_fix_features force to 
enable/disable rx/tx pair together. That would resolve the situation as
well giving user possibility to turn off vlan accel in case of any issues.

>
>Best Regards,
>Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
=?ISO-8859-2?Q?Micha=B3_Miros=B3aw?= July 17, 2011, 8:36 a.m. UTC | #3
W dniu 17 lipca 2011 09:30 użytkownik Jiri Pirko <jpirko@redhat.com> napisał:
> Sat, Jul 16, 2011 at 04:14:36PM CEST, mirqus@gmail.com wrote:
>>2011/7/16 Jiri Pirko <jpirko@redhat.com>:
>>> Some devices are not able to enable/disable rx/tw vlan accel separately.
>>> they depend on ndo_vlan_rx_register to know if to enable of disable
>>> hw accel. And since ndo_vlan_rx_register is going to die soon,
>>> this must be resolved.
>>>
>>> One solution might be to enable accel on device start every time, even
>>> if there are no vlan up on. But this would change behaviour and might
>>> lead to possible regression (on older devices).
>>[...]
>>
>>Please describe the possible regression. As I see it, there won't be
>>any user visible change of behaviour - network code takes care of
>>reinserting VLAN tag when necessary. If you think that disabling tag
>>stripping is beneficial for cases where no VLANs are configured, it's
>>better to do that in netdev_fix_features() for devices which advertise
>>NETIF_F_HW_VLAN_RX in hw_features.
>
> Well I just wanted to preserve current behaviour which is that in many
> drivers vlan accel is enabled only if some vid is registered upon the
> device and it's disabled again when no vid is registered. I can see
> no way to do this with current code after removing ndo_vlan_rx_register.
>
> I expect unexpected

:-D

> ... problems on old cards when vlan accel would be
> enabled all the time, but maybe I'm wrong...

Device has no way of knowing how the system uses VLAN tags, stripped
or not. Any problems would be driver problems and since you're making
it all use generic code, bugs will hit all drivers simultaneously or
(preferably) won't happen at all.

> One idea is for device which do not support sepatate rx/tx vlan accel
> enabling/disabling they can probably use ndo_fix_features force to
> enable/disable rx/tx pair together. That would resolve the situation as
> well giving user possibility to turn off vlan accel in case of any issues.

That is exactly the idea behind ndo_fix_features.

Best Regards,
Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Jiri Pirko July 17, 2011, 7:44 p.m. UTC | #4
Sun, Jul 17, 2011 at 10:36:04AM CEST, mirqus@gmail.com wrote:
>W dniu 17 lipca 2011 09:30 użytkownik Jiri Pirko <jpirko@redhat.com> napisał:
>> Sat, Jul 16, 2011 at 04:14:36PM CEST, mirqus@gmail.com wrote:
>>>2011/7/16 Jiri Pirko <jpirko@redhat.com>:
>>>> Some devices are not able to enable/disable rx/tw vlan accel separately.
>>>> they depend on ndo_vlan_rx_register to know if to enable of disable
>>>> hw accel. And since ndo_vlan_rx_register is going to die soon,
>>>> this must be resolved.
>>>>
>>>> One solution might be to enable accel on device start every time, even
>>>> if there are no vlan up on. But this would change behaviour and might
>>>> lead to possible regression (on older devices).
>>>[...]
>>>
>>>Please describe the possible regression. As I see it, there won't be
>>>any user visible change of behaviour - network code takes care of
>>>reinserting VLAN tag when necessary. If you think that disabling tag
>>>stripping is beneficial for cases where no VLANs are configured, it's
>>>better to do that in netdev_fix_features() for devices which advertise
>>>NETIF_F_HW_VLAN_RX in hw_features.
>>
>> Well I just wanted to preserve current behaviour which is that in many
>> drivers vlan accel is enabled only if some vid is registered upon the
>> device and it's disabled again when no vid is registered. I can see
>> no way to do this with current code after removing ndo_vlan_rx_register.
>>
>> I expect unexpected
>
>:-D
>
>> ... problems on old cards when vlan accel would be
>> enabled all the time, but maybe I'm wrong...
>
>Device has no way of knowing how the system uses VLAN tags, stripped
>or not. Any problems would be driver problems and since you're making
>it all use generic code, bugs will hit all drivers simultaneously or
>(preferably) won't happen at all.
>
>> One idea is for device which do not support sepatate rx/tx vlan accel
>> enabling/disabling they can probably use ndo_fix_features force to
>> enable/disable rx/tx pair together. That would resolve the situation as
>> well giving user possibility to turn off vlan accel in case of any issues.
>
>That is exactly the idea behind ndo_fix_features.

In netdev_fix_features add check if either one of NETIF_F_HW_VLAN_TX or
NETIF_F_HW_VLAN_RX is set and in that case set the other one. Of course
this would be done only for devices what do not support separate rx/tx
vlan on/off. But how to distinguish? NETIF_F_HW_VLAN_BOTH feature flag?

Thanks.

Jirka

>
>Best Regards,
>Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
=?ISO-8859-2?Q?Micha=B3_Miros=B3aw?= July 17, 2011, 9:06 p.m. UTC | #5
W dniu 17 lipca 2011 21:44 użytkownik Jiri Pirko <jpirko@redhat.com> napisał:
> Sun, Jul 17, 2011 at 10:36:04AM CEST, mirqus@gmail.com wrote:
>>W dniu 17 lipca 2011 09:30 użytkownik Jiri Pirko <jpirko@redhat.com> napisał:
>>> Sat, Jul 16, 2011 at 04:14:36PM CEST, mirqus@gmail.com wrote:
>>>>2011/7/16 Jiri Pirko <jpirko@redhat.com>:
>>>>> Some devices are not able to enable/disable rx/tw vlan accel separately.
>>>>> they depend on ndo_vlan_rx_register to know if to enable of disable
>>>>> hw accel. And since ndo_vlan_rx_register is going to die soon,
>>>>> this must be resolved.
>>>>>
>>>>> One solution might be to enable accel on device start every time, even
>>>>> if there are no vlan up on. But this would change behaviour and might
>>>>> lead to possible regression (on older devices).
>>>>[...]
>>>>
>>>>Please describe the possible regression. As I see it, there won't be
>>>>any user visible change of behaviour - network code takes care of
>>>>reinserting VLAN tag when necessary. If you think that disabling tag
>>>>stripping is beneficial for cases where no VLANs are configured, it's
>>>>better to do that in netdev_fix_features() for devices which advertise
>>>>NETIF_F_HW_VLAN_RX in hw_features.
>>>
>>> Well I just wanted to preserve current behaviour which is that in many
>>> drivers vlan accel is enabled only if some vid is registered upon the
>>> device and it's disabled again when no vid is registered. I can see
>>> no way to do this with current code after removing ndo_vlan_rx_register.
>>>
>>> I expect unexpected
>>
>>:-D
>>
>>> ... problems on old cards when vlan accel would be
>>> enabled all the time, but maybe I'm wrong...
>>
>>Device has no way of knowing how the system uses VLAN tags, stripped
>>or not. Any problems would be driver problems and since you're making
>>it all use generic code, bugs will hit all drivers simultaneously or
>>(preferably) won't happen at all.
>>
>>> One idea is for device which do not support sepatate rx/tx vlan accel
>>> enabling/disabling they can probably use ndo_fix_features force to
>>> enable/disable rx/tx pair together. That would resolve the situation as
>>> well giving user possibility to turn off vlan accel in case of any issues.
>>
>>That is exactly the idea behind ndo_fix_features.

> In netdev_fix_features add check if either one of NETIF_F_HW_VLAN_TX or
> NETIF_F_HW_VLAN_RX is set and in that case set the other one. Of course
> this would be done only for devices what do not support separate rx/tx
> vlan on/off. But how to distinguish? NETIF_F_HW_VLAN_BOTH feature flag?

Not in netdev_fix_features(). This case you describe should be handled
in driver-specific
ndo_fix_features callback. Because if NETIF_F_HW_VLAN_TX is disabled,
the network core will insert the tag anyway, this would cover the
restriction:

if (!(features & NEITF_F_HW_VLAN_RX))
  features &= ~NETIF_F_HW_VLAN_TX;

This works, because if HW_VLAN_TX is disabled, the driver never gets
packets which need tag insertion. Besides those already in the queue,
of course.

For netdev_fix_features() I thought that if no VLANs are configured, then it
could disable NETIF_F_HW_VLAN_RX (if set in hw_features). The
conditions for disabling it need some thought. For example, if the
device is not slave to some stacking device (bonding doesn't count, as
it passes VLAN registeration to its slaves) then packets with tags
would be either dropped or have tag reinserted (for network taps).

Best Regards,
Michał Mirosław
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index f84dfd2..8a69f33 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -775,6 +775,18 @@  struct netdev_tc_txq {
  *	when vlan groups for the device changes.  Note: grp is NULL
  *	if no vlan's groups are being used.
  *
+ * void (*ndo_vlan_enable)(struct net_device *dev);
+ *	This function is called when first vlan is registered on this device.
+ *	This is primary to be implemented for devices what can enable rx/tx
+ *	vlan accel only at one. Otherwise enabling of vlan accel should be
+ *	implemented using ndo_set_features.
+ *
+ * void (*ndo_vlan_disable)(struct net_device *dev);
+ *	This function is called when last vlan is unregistered on this device.
+ *	This is primary to be implemented for devices what can disable rx/tx
+ *	vlan accel only at one. Otherwise disabling of vlan accel should be
+ *	implemented using ndo_set_features.
+ *
  * void (*ndo_vlan_rx_add_vid)(struct net_device *dev, unsigned short vid);
  *	If device support VLAN filtering (dev->features & NETIF_F_HW_VLAN_FILTER)
  *	this function is called when a VLAN id is registered.
@@ -895,6 +907,8 @@  struct net_device_ops {
 
 	void			(*ndo_vlan_rx_register)(struct net_device *dev,
 						        struct vlan_group *grp);
+	void			(*ndo_vlan_enable)(struct net_device *dev);
+	void			(*ndo_vlan_disable)(struct net_device *dev);
 	void			(*ndo_vlan_rx_add_vid)(struct net_device *dev,
 						       unsigned short vid);
 	void			(*ndo_vlan_rx_kill_vid)(struct net_device *dev,
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index d24c464..051c3cd 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -136,6 +136,8 @@  void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
 		rcu_assign_pointer(real_dev->vlgrp, NULL);
 		if (ops->ndo_vlan_rx_register)
 			ops->ndo_vlan_rx_register(real_dev, NULL);
+		if (ops->ndo_vlan_disable)
+			ops->ndo_vlan_disable(real_dev);
 
 		/* Free the group, after all cpu's are done. */
 		call_rcu(&grp->rcu, vlan_rcu_free);
@@ -209,6 +211,8 @@  int register_vlan_dev(struct net_device *dev)
 	if (ngrp) {
 		if (ops->ndo_vlan_rx_register && (real_dev->features & NETIF_F_HW_VLAN_RX))
 			ops->ndo_vlan_rx_register(real_dev, ngrp);
+		if (ops->ndo_vlan_enable)
+			ops->ndo_vlan_enable(real_dev);
 		rcu_assign_pointer(real_dev->vlgrp, ngrp);
 	}
 	if (real_dev->features & NETIF_F_HW_VLAN_FILTER)