diff mbox series

[wpan-next,v2,27/27] net: ieee802154: ca8210: Refuse most of the scan operations

Message ID 20220112173312.764660-28-miquel.raynal@bootlin.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series IEEE 802.15.4 scan support | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Series has a cover letter
netdev/patch_count fail Series longer than 15 patches (and no cover letter)
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 3 this patch: 3
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 3 this patch: 3
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 37 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Miquel Raynal Jan. 12, 2022, 5:33 p.m. UTC
The Cascada 8210 hardware transceiver is kind of a hardMAC which
interfaces with the softMAC and in practice does not support sending
anything else than dataframes. This means we cannot send any BEACON_REQ
during active scans nor any BEACON in general. Refuse these operations
officially so that the user is aware of the limitation.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
 drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

Comments

Alexander Aring Jan. 12, 2022, 10:48 p.m. UTC | #1
Hi,

On Wed, 12 Jan 2022 at 12:34, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> The Cascada 8210 hardware transceiver is kind of a hardMAC which
> interfaces with the softMAC and in practice does not support sending
> anything else than dataframes. This means we cannot send any BEACON_REQ
> during active scans nor any BEACON in general. Refuse these operations
> officially so that the user is aware of the limitation.
>
> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> ---
>  drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> index d3a9e4fe05f4..49c274280e3c 100644
> --- a/drivers/net/ieee802154/ca8210.c
> +++ b/drivers/net/ieee802154/ca8210.c
> @@ -2385,6 +2385,25 @@ static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
>         return link_to_linux_err(status);
>  }
>
> +static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
> +                                 struct cfg802154_scan_request *request)
> +{
> +       /* This xceiver can only send dataframes */
> +       if (request->type != NL802154_SCAN_PASSIVE)
> +               return -EOPNOTSUPP;
> +
> +       return 0;
> +}
> +
> +static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
> +                                    struct cfg802154_beacons_request *request)
> +{
> +       /* This xceiver can only send dataframes */
> +       return -EOPNOTSUPP;
> +}
> +
> +static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
> +
>  static const struct ieee802154_ops ca8210_phy_ops = {
>         .start = ca8210_start,
>         .stop = ca8210_stop,
> @@ -2397,7 +2416,11 @@ static const struct ieee802154_ops ca8210_phy_ops = {
>         .set_cca_ed_level = ca8210_set_cca_ed_level,
>         .set_csma_params = ca8210_set_csma_params,
>         .set_frame_retries = ca8210_set_frame_retries,
> -       .set_promiscuous_mode = ca8210_set_promiscuous_mode
> +       .set_promiscuous_mode = ca8210_set_promiscuous_mode,
> +       .enter_scan_mode = ca8210_enter_scan_mode,
> +       .exit_scan_mode = ca8210_exit_scan_beacons_mode,
> +       .enter_beacons_mode = ca8210_enter_beacons_mode,
> +       .exit_beacons_mode = ca8210_exit_scan_beacons_mode,
>  };

so there is no flag that this driver can't support scanning currently
and it works now because the offload functionality will return
-ENOTSUPP? This is misleading because I would assume if it's not
supported we can do it by software which the driver can't do.

... I see that the offload functions now are getting used and have a
reason to be upstream, but the use of it is wrong.

- Alex
Miquel Raynal Jan. 13, 2022, 9:29 a.m. UTC | #2
Hi Alexander,

alex.aring@gmail.com wrote on Wed, 12 Jan 2022 17:48:59 -0500:

> Hi,
> 
> On Wed, 12 Jan 2022 at 12:34, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> >
> > The Cascada 8210 hardware transceiver is kind of a hardMAC which
> > interfaces with the softMAC and in practice does not support sending
> > anything else than dataframes. This means we cannot send any BEACON_REQ
> > during active scans nor any BEACON in general. Refuse these operations
> > officially so that the user is aware of the limitation.
> >
> > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > ---
> >  drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
> >  1 file changed, 24 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> > index d3a9e4fe05f4..49c274280e3c 100644
> > --- a/drivers/net/ieee802154/ca8210.c
> > +++ b/drivers/net/ieee802154/ca8210.c
> > @@ -2385,6 +2385,25 @@ static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
> >         return link_to_linux_err(status);
> >  }
> >
> > +static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
> > +                                 struct cfg802154_scan_request *request)
> > +{
> > +       /* This xceiver can only send dataframes */
> > +       if (request->type != NL802154_SCAN_PASSIVE)
> > +               return -EOPNOTSUPP;
> > +
> > +       return 0;
> > +}
> > +
> > +static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
> > +                                    struct cfg802154_beacons_request *request)
> > +{
> > +       /* This xceiver can only send dataframes */
> > +       return -EOPNOTSUPP;
> > +}
> > +
> > +static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
> > +
> >  static const struct ieee802154_ops ca8210_phy_ops = {
> >         .start = ca8210_start,
> >         .stop = ca8210_stop,
> > @@ -2397,7 +2416,11 @@ static const struct ieee802154_ops ca8210_phy_ops = {
> >         .set_cca_ed_level = ca8210_set_cca_ed_level,
> >         .set_csma_params = ca8210_set_csma_params,
> >         .set_frame_retries = ca8210_set_frame_retries,
> > -       .set_promiscuous_mode = ca8210_set_promiscuous_mode
> > +       .set_promiscuous_mode = ca8210_set_promiscuous_mode,
> > +       .enter_scan_mode = ca8210_enter_scan_mode,
> > +       .exit_scan_mode = ca8210_exit_scan_beacons_mode,
> > +       .enter_beacons_mode = ca8210_enter_beacons_mode,
> > +       .exit_beacons_mode = ca8210_exit_scan_beacons_mode,
> >  };  
> 
> so there is no flag that this driver can't support scanning currently
> and it works now because the offload functionality will return
> -ENOTSUPP? This is misleading because I would assume if it's not
> supported we can do it by software which the driver can't do.

I believe there is a misunderstanding.

This is what I have understood from your previous comments in v1:
"This driver does not support transmitting anything else than
datagrams", which is what I assumed was a regular data packet. IOW,
sending a MAC_CMD such as a beacon request or sending a beacon was not
supported physically by the hardware. Hence, most of the scans
operations cannot be performed and must be rejected (all but a passive
scan, assuming that receiving beacons was okay).

Please mind the update in that hook which currently is just an FYI from
the mac to the drivers and not a "do it by yourself" injunction. So
answering -EOPNOTSUPP to the mac here does not mean:
	"I cannot handle it by myself, the scan cannot happen"
but
	"I cannot handle the forged frames, so let's just not try"
 
> ... I see that the offload functions now are getting used and have a
> reason to be upstream, but the use of it is wrong.

As a personal matter of taste, I don't like flags when it comes to
something complex like supporting a specific operation. Just in the
scanning procedure there are 4 different actions and a driver might
support only a subset of these, which is totally fine but hard to
properly describe by well-named flags. Here the driver hooks say to
the driver which are interested "here is what is going to happen" and
then they can:
- ignore the details by just not implementing the hooks, let the mac do
  its job, they will then transmit the relevant frames forged by the
  mac
- eventually enter a specific mode internally for this operation, but
  basically do the same as above, ie. transmitting the frames forged
  by the mac
- refuse the operation by returning an error code if something cannot
  be done

I've experienced a number of situations in the MTD world and later with
IIO drivers where flags have been remodeled and reused in different
manners, until the flag description gets totally wrong and
undescriptive regarding what it actually does. Hence my main idea of
letting drivers refuse these operations instead of having the mac doing
it for them.

I can definitely use flags if you want, but in this case, what flags do
you want to see?

Thanks,
Miquèl
Alexander Aring Jan. 14, 2022, 1 a.m. UTC | #3
Hi,

On Thu, 13 Jan 2022 at 04:30, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Alexander,
>
> alex.aring@gmail.com wrote on Wed, 12 Jan 2022 17:48:59 -0500:
>
> > Hi,
> >
> > On Wed, 12 Jan 2022 at 12:34, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> > >
> > > The Cascada 8210 hardware transceiver is kind of a hardMAC which
> > > interfaces with the softMAC and in practice does not support sending
> > > anything else than dataframes. This means we cannot send any BEACON_REQ
> > > during active scans nor any BEACON in general. Refuse these operations
> > > officially so that the user is aware of the limitation.
> > >
> > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > > ---
> > >  drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
> > >  1 file changed, 24 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> > > index d3a9e4fe05f4..49c274280e3c 100644
> > > --- a/drivers/net/ieee802154/ca8210.c
> > > +++ b/drivers/net/ieee802154/ca8210.c
> > > @@ -2385,6 +2385,25 @@ static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
> > >         return link_to_linux_err(status);
> > >  }
> > >
> > > +static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
> > > +                                 struct cfg802154_scan_request *request)
> > > +{
> > > +       /* This xceiver can only send dataframes */
> > > +       if (request->type != NL802154_SCAN_PASSIVE)
> > > +               return -EOPNOTSUPP;
> > > +
> > > +       return 0;
> > > +}
> > > +
> > > +static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
> > > +                                    struct cfg802154_beacons_request *request)
> > > +{
> > > +       /* This xceiver can only send dataframes */
> > > +       return -EOPNOTSUPP;
> > > +}
> > > +
> > > +static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
> > > +
> > >  static const struct ieee802154_ops ca8210_phy_ops = {
> > >         .start = ca8210_start,
> > >         .stop = ca8210_stop,
> > > @@ -2397,7 +2416,11 @@ static const struct ieee802154_ops ca8210_phy_ops = {
> > >         .set_cca_ed_level = ca8210_set_cca_ed_level,
> > >         .set_csma_params = ca8210_set_csma_params,
> > >         .set_frame_retries = ca8210_set_frame_retries,
> > > -       .set_promiscuous_mode = ca8210_set_promiscuous_mode
> > > +       .set_promiscuous_mode = ca8210_set_promiscuous_mode,
> > > +       .enter_scan_mode = ca8210_enter_scan_mode,
> > > +       .exit_scan_mode = ca8210_exit_scan_beacons_mode,
> > > +       .enter_beacons_mode = ca8210_enter_beacons_mode,
> > > +       .exit_beacons_mode = ca8210_exit_scan_beacons_mode,
> > >  };
> >
> > so there is no flag that this driver can't support scanning currently
> > and it works now because the offload functionality will return
> > -ENOTSUPP? This is misleading because I would assume if it's not
> > supported we can do it by software which the driver can't do.
>
> I believe there is a misunderstanding.
>
> This is what I have understood from your previous comments in v1:
> "This driver does not support transmitting anything else than
> datagrams", which is what I assumed was a regular data packet. IOW,
> sending a MAC_CMD such as a beacon request or sending a beacon was not
> supported physically by the hardware. Hence, most of the scans
> operations cannot be performed and must be rejected (all but a passive
> scan, assuming that receiving beacons was okay).
>

and I said that this driver is a HardMAC transceiver connected to the
SoftMAC layer which is already wrong to exist (very special handling
is required here).
dataframes here are "data" type frames and I suppose it's also not
able to deliver/receive other types than data to mac802154.

It seems the author of this driver is happy to have data frames only
but we need to take care that additional mac802154 handling is simply
not possible to do here.

> Please mind the update in that hook which currently is just an FYI from
> the mac to the drivers and not a "do it by yourself" injunction. So
> answering -EOPNOTSUPP to the mac here does not mean:
>         "I cannot handle it by myself, the scan cannot happen"
> but
>         "I cannot handle the forged frames, so let's just not try"
>

The problem here is that a SoftMAC transceiver should always be
capable of doing it by software so the "but case" makes no sense in
this layer.
On a mac802154 layer and "offload" driver functions as they are and
they report me "-ENOTSUPP", I would assume that I can go back and do
it by software which again should always be possible to do in
mac802154.

> > ... I see that the offload functions now are getting used and have a
> > reason to be upstream, but the use of it is wrong.
>
> As a personal matter of taste, I don't like flags when it comes to
> something complex like supporting a specific operation. Just in the
> scanning procedure there are 4 different actions and a driver might
> support only a subset of these, which is totally fine but hard to
> properly describe by well-named flags. Here the driver hooks say to
> the driver which are interested "here is what is going to happen" and
> then they can:
> - ignore the details by just not implementing the hooks, let the mac do
>   its job, they will then transmit the relevant frames forged by the
>   mac
> - eventually enter a specific mode internally for this operation, but
>   basically do the same as above, ie. transmitting the frames forged
>   by the mac
> - refuse the operation by returning an error code if something cannot
>   be done
>
> I've experienced a number of situations in the MTD world and later with
> IIO drivers where flags have been remodeled and reused in different
> manners, until the flag description gets totally wrong and
> undescriptive regarding what it actually does. Hence my main idea of
> letting drivers refuse these operations instead of having the mac doing
> it for them.
>
> I can definitely use flags if you want, but in this case, what flags do
> you want to see?
>

Do some phy quirks flags which indicate that the transceiver is not
capable of doing scan operation by software. Or just use a boolean in
phy capabilities (but don't export them to userspace, note that this
flag should be removed later) if this operation is not allowed.

I don't like this flag either, it is a workaround to still support the
driver as it is and don't allow new fancy things because it cannot
handle it. We should work on it to remove this flag, but this is a
longer process. Either the driver is implementing those hooks "real"
to somehow run a scan (but at it's own risk) or it needs to be
implemented as a HardMAC driver. This driver is already difficult to
maintain because it doesn't fit here...

- Alex
Miquel Raynal Jan. 14, 2022, 6:37 p.m. UTC | #4
Hi Alexander,

alex.aring@gmail.com wrote on Thu, 13 Jan 2022 20:00:53 -0500:

> Hi,
> 
> On Thu, 13 Jan 2022 at 04:30, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> >
> > Hi Alexander,
> >
> > alex.aring@gmail.com wrote on Wed, 12 Jan 2022 17:48:59 -0500:
> >  
> > > Hi,
> > >
> > > On Wed, 12 Jan 2022 at 12:34, Miquel Raynal <miquel.raynal@bootlin.com> wrote:  
> > > >
> > > > The Cascada 8210 hardware transceiver is kind of a hardMAC which
> > > > interfaces with the softMAC and in practice does not support sending
> > > > anything else than dataframes. This means we cannot send any BEACON_REQ
> > > > during active scans nor any BEACON in general. Refuse these operations
> > > > officially so that the user is aware of the limitation.
> > > >
> > > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > > > ---
> > > >  drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
> > > >  1 file changed, 24 insertions(+), 1 deletion(-)
> > > >
> > > > diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> > > > index d3a9e4fe05f4..49c274280e3c 100644
> > > > --- a/drivers/net/ieee802154/ca8210.c
> > > > +++ b/drivers/net/ieee802154/ca8210.c
> > > > @@ -2385,6 +2385,25 @@ static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
> > > >         return link_to_linux_err(status);
> > > >  }
> > > >
> > > > +static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
> > > > +                                 struct cfg802154_scan_request *request)
> > > > +{
> > > > +       /* This xceiver can only send dataframes */
> > > > +       if (request->type != NL802154_SCAN_PASSIVE)
> > > > +               return -EOPNOTSUPP;
> > > > +
> > > > +       return 0;
> > > > +}
> > > > +
> > > > +static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
> > > > +                                    struct cfg802154_beacons_request *request)
> > > > +{
> > > > +       /* This xceiver can only send dataframes */
> > > > +       return -EOPNOTSUPP;
> > > > +}
> > > > +
> > > > +static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
> > > > +
> > > >  static const struct ieee802154_ops ca8210_phy_ops = {
> > > >         .start = ca8210_start,
> > > >         .stop = ca8210_stop,
> > > > @@ -2397,7 +2416,11 @@ static const struct ieee802154_ops ca8210_phy_ops = {
> > > >         .set_cca_ed_level = ca8210_set_cca_ed_level,
> > > >         .set_csma_params = ca8210_set_csma_params,
> > > >         .set_frame_retries = ca8210_set_frame_retries,
> > > > -       .set_promiscuous_mode = ca8210_set_promiscuous_mode
> > > > +       .set_promiscuous_mode = ca8210_set_promiscuous_mode,
> > > > +       .enter_scan_mode = ca8210_enter_scan_mode,
> > > > +       .exit_scan_mode = ca8210_exit_scan_beacons_mode,
> > > > +       .enter_beacons_mode = ca8210_enter_beacons_mode,
> > > > +       .exit_beacons_mode = ca8210_exit_scan_beacons_mode,
> > > >  };  
> > >
> > > so there is no flag that this driver can't support scanning currently
> > > and it works now because the offload functionality will return
> > > -ENOTSUPP? This is misleading because I would assume if it's not
> > > supported we can do it by software which the driver can't do.  
> >
> > I believe there is a misunderstanding.
> >
> > This is what I have understood from your previous comments in v1:
> > "This driver does not support transmitting anything else than
> > datagrams", which is what I assumed was a regular data packet. IOW,
> > sending a MAC_CMD such as a beacon request or sending a beacon was not
> > supported physically by the hardware. Hence, most of the scans
> > operations cannot be performed and must be rejected (all but a passive
> > scan, assuming that receiving beacons was okay).
> >  
> 
> and I said that this driver is a HardMAC transceiver connected to the
> SoftMAC layer which is already wrong to exist (very special handling
> is required here).
> dataframes here are "data" type frames and I suppose it's also not
> able to deliver/receive other types than data to mac802154.
> 
> It seems the author of this driver is happy to have data frames only
> but we need to take care that additional mac802154 handling is simply
> not possible to do here.
> 
> > Please mind the update in that hook which currently is just an FYI from
> > the mac to the drivers and not a "do it by yourself" injunction. So
> > answering -EOPNOTSUPP to the mac here does not mean:
> >         "I cannot handle it by myself, the scan cannot happen"
> > but
> >         "I cannot handle the forged frames, so let's just not try"
> >  
> 
> The problem here is that a SoftMAC transceiver should always be
> capable of doing it by software so the "but case" makes no sense in
> this layer.
> On a mac802154 layer and "offload" driver functions as they are and
> they report me "-ENOTSUPP", I would assume that I can go back and do
> it by software which again should always be possible to do in
> mac802154.
> 
> > > ... I see that the offload functions now are getting used and have a
> > > reason to be upstream, but the use of it is wrong.  
> >
> > As a personal matter of taste, I don't like flags when it comes to
> > something complex like supporting a specific operation. Just in the
> > scanning procedure there are 4 different actions and a driver might
> > support only a subset of these, which is totally fine but hard to
> > properly describe by well-named flags. Here the driver hooks say to
> > the driver which are interested "here is what is going to happen" and
> > then they can:
> > - ignore the details by just not implementing the hooks, let the mac do
> >   its job, they will then transmit the relevant frames forged by the
> >   mac
> > - eventually enter a specific mode internally for this operation, but
> >   basically do the same as above, ie. transmitting the frames forged
> >   by the mac
> > - refuse the operation by returning an error code if something cannot
> >   be done
> >
> > I've experienced a number of situations in the MTD world and later with
> > IIO drivers where flags have been remodeled and reused in different
> > manners, until the flag description gets totally wrong and
> > undescriptive regarding what it actually does. Hence my main idea of
> > letting drivers refuse these operations instead of having the mac doing
> > it for them.
> >
> > I can definitely use flags if you want, but in this case, what flags do
> > you want to see?
> >  
> 
> Do some phy quirks flags which indicate that the transceiver is not
> capable of doing scan operation by software. Or just use a boolean in
> phy capabilities (but don't export them to userspace, note that this
> flag should be removed later) if this operation is not allowed.

I've added a phy flag to distinguish this driver as early as possible.

> 
> I don't like this flag either, it is a workaround to still support the
> driver as it is and don't allow new fancy things because it cannot
> handle it. We should work on it to remove this flag, but this is a
> longer process. Either the driver is implementing those hooks "real"
> to somehow run a scan (but at it's own risk) or it needs to be
> implemented as a HardMAC driver. This driver is already difficult to
> maintain because it doesn't fit here...
> 
> - Alex


Thanks,
Miquèl
Alexander Aring Jan. 16, 2022, 10:48 p.m. UTC | #5
Hi,

On Fri, 14 Jan 2022 at 13:37, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
> Hi Alexander,
>
> alex.aring@gmail.com wrote on Thu, 13 Jan 2022 20:00:53 -0500:
>
> > Hi,
> >
> > On Thu, 13 Jan 2022 at 04:30, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> > >
> > > Hi Alexander,
> > >
> > > alex.aring@gmail.com wrote on Wed, 12 Jan 2022 17:48:59 -0500:
> > >
> > > > Hi,
> > > >
> > > > On Wed, 12 Jan 2022 at 12:34, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> > > > >
> > > > > The Cascada 8210 hardware transceiver is kind of a hardMAC which
> > > > > interfaces with the softMAC and in practice does not support sending
> > > > > anything else than dataframes. This means we cannot send any BEACON_REQ
> > > > > during active scans nor any BEACON in general. Refuse these operations
> > > > > officially so that the user is aware of the limitation.
> > > > >
> > > > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > > > > ---
> > > > >  drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
> > > > >  1 file changed, 24 insertions(+), 1 deletion(-)
> > > > >
> > > > > diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> > > > > index d3a9e4fe05f4..49c274280e3c 100644
> > > > > --- a/drivers/net/ieee802154/ca8210.c
> > > > > +++ b/drivers/net/ieee802154/ca8210.c
> > > > > @@ -2385,6 +2385,25 @@ static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
> > > > >         return link_to_linux_err(status);
> > > > >  }
> > > > >
> > > > > +static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
> > > > > +                                 struct cfg802154_scan_request *request)
> > > > > +{
> > > > > +       /* This xceiver can only send dataframes */
> > > > > +       if (request->type != NL802154_SCAN_PASSIVE)
> > > > > +               return -EOPNOTSUPP;
> > > > > +
> > > > > +       return 0;
> > > > > +}
> > > > > +
> > > > > +static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
> > > > > +                                    struct cfg802154_beacons_request *request)
> > > > > +{
> > > > > +       /* This xceiver can only send dataframes */
> > > > > +       return -EOPNOTSUPP;
> > > > > +}
> > > > > +
> > > > > +static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
> > > > > +
> > > > >  static const struct ieee802154_ops ca8210_phy_ops = {
> > > > >         .start = ca8210_start,
> > > > >         .stop = ca8210_stop,
> > > > > @@ -2397,7 +2416,11 @@ static const struct ieee802154_ops ca8210_phy_ops = {
> > > > >         .set_cca_ed_level = ca8210_set_cca_ed_level,
> > > > >         .set_csma_params = ca8210_set_csma_params,
> > > > >         .set_frame_retries = ca8210_set_frame_retries,
> > > > > -       .set_promiscuous_mode = ca8210_set_promiscuous_mode
> > > > > +       .set_promiscuous_mode = ca8210_set_promiscuous_mode,
> > > > > +       .enter_scan_mode = ca8210_enter_scan_mode,
> > > > > +       .exit_scan_mode = ca8210_exit_scan_beacons_mode,
> > > > > +       .enter_beacons_mode = ca8210_enter_beacons_mode,
> > > > > +       .exit_beacons_mode = ca8210_exit_scan_beacons_mode,
> > > > >  };
> > > >
> > > > so there is no flag that this driver can't support scanning currently
> > > > and it works now because the offload functionality will return
> > > > -ENOTSUPP? This is misleading because I would assume if it's not
> > > > supported we can do it by software which the driver can't do.
> > >
> > > I believe there is a misunderstanding.
> > >
> > > This is what I have understood from your previous comments in v1:
> > > "This driver does not support transmitting anything else than
> > > datagrams", which is what I assumed was a regular data packet. IOW,
> > > sending a MAC_CMD such as a beacon request or sending a beacon was not
> > > supported physically by the hardware. Hence, most of the scans
> > > operations cannot be performed and must be rejected (all but a passive
> > > scan, assuming that receiving beacons was okay).
> > >
> >
> > and I said that this driver is a HardMAC transceiver connected to the
> > SoftMAC layer which is already wrong to exist (very special handling
> > is required here).
> > dataframes here are "data" type frames and I suppose it's also not
> > able to deliver/receive other types than data to mac802154.
> >
> > It seems the author of this driver is happy to have data frames only
> > but we need to take care that additional mac802154 handling is simply
> > not possible to do here.
> >
> > > Please mind the update in that hook which currently is just an FYI from
> > > the mac to the drivers and not a "do it by yourself" injunction. So
> > > answering -EOPNOTSUPP to the mac here does not mean:
> > >         "I cannot handle it by myself, the scan cannot happen"
> > > but
> > >         "I cannot handle the forged frames, so let's just not try"
> > >
> >
> > The problem here is that a SoftMAC transceiver should always be
> > capable of doing it by software so the "but case" makes no sense in
> > this layer.
> > On a mac802154 layer and "offload" driver functions as they are and
> > they report me "-ENOTSUPP", I would assume that I can go back and do
> > it by software which again should always be possible to do in
> > mac802154.
> >
> > > > ... I see that the offload functions now are getting used and have a
> > > > reason to be upstream, but the use of it is wrong.
> > >
> > > As a personal matter of taste, I don't like flags when it comes to
> > > something complex like supporting a specific operation. Just in the
> > > scanning procedure there are 4 different actions and a driver might
> > > support only a subset of these, which is totally fine but hard to
> > > properly describe by well-named flags. Here the driver hooks say to
> > > the driver which are interested "here is what is going to happen" and
> > > then they can:
> > > - ignore the details by just not implementing the hooks, let the mac do
> > >   its job, they will then transmit the relevant frames forged by the
> > >   mac
> > > - eventually enter a specific mode internally for this operation, but
> > >   basically do the same as above, ie. transmitting the frames forged
> > >   by the mac
> > > - refuse the operation by returning an error code if something cannot
> > >   be done
> > >
> > > I've experienced a number of situations in the MTD world and later with
> > > IIO drivers where flags have been remodeled and reused in different
> > > manners, until the flag description gets totally wrong and
> > > undescriptive regarding what it actually does. Hence my main idea of
> > > letting drivers refuse these operations instead of having the mac doing
> > > it for them.
> > >
> > > I can definitely use flags if you want, but in this case, what flags do
> > > you want to see?
> > >
> >
> > Do some phy quirks flags which indicate that the transceiver is not
> > capable of doing scan operation by software. Or just use a boolean in
> > phy capabilities (but don't export them to userspace, note that this
> > flag should be removed later) if this operation is not allowed.
>
> I've added a phy flag to distinguish this driver as early as possible.

I was thinking about this a lot and I think the driver is already
buggy in many ways e.g. what happens when we do AF_PACKET raw sockets
and do some different frame types than data. I have no idea, maybe we
should leave it as it is... and simply don't care? Maybe the driver
needs to drop a lot of frames if they are different... it runs already
different than other transceivers which we don't check at all.

- Alex
Miquel Raynal Jan. 17, 2022, 9:04 a.m. UTC | #6
Hi Alexander,

alex.aring@gmail.com wrote on Sun, 16 Jan 2022 17:48:03 -0500:

> Hi,
> 
> On Fri, 14 Jan 2022 at 13:37, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> >
> > Hi Alexander,
> >
> > alex.aring@gmail.com wrote on Thu, 13 Jan 2022 20:00:53 -0500:
> >  
> > > Hi,
> > >
> > > On Thu, 13 Jan 2022 at 04:30, Miquel Raynal <miquel.raynal@bootlin.com> wrote:  
> > > >
> > > > Hi Alexander,
> > > >
> > > > alex.aring@gmail.com wrote on Wed, 12 Jan 2022 17:48:59 -0500:
> > > >  
> > > > > Hi,
> > > > >
> > > > > On Wed, 12 Jan 2022 at 12:34, Miquel Raynal <miquel.raynal@bootlin.com> wrote:  
> > > > > >
> > > > > > The Cascada 8210 hardware transceiver is kind of a hardMAC which
> > > > > > interfaces with the softMAC and in practice does not support sending
> > > > > > anything else than dataframes. This means we cannot send any BEACON_REQ
> > > > > > during active scans nor any BEACON in general. Refuse these operations
> > > > > > officially so that the user is aware of the limitation.
> > > > > >
> > > > > > Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
> > > > > > ---
> > > > > >  drivers/net/ieee802154/ca8210.c | 25 ++++++++++++++++++++++++-
> > > > > >  1 file changed, 24 insertions(+), 1 deletion(-)
> > > > > >
> > > > > > diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
> > > > > > index d3a9e4fe05f4..49c274280e3c 100644
> > > > > > --- a/drivers/net/ieee802154/ca8210.c
> > > > > > +++ b/drivers/net/ieee802154/ca8210.c
> > > > > > @@ -2385,6 +2385,25 @@ static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
> > > > > >         return link_to_linux_err(status);
> > > > > >  }
> > > > > >
> > > > > > +static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
> > > > > > +                                 struct cfg802154_scan_request *request)
> > > > > > +{
> > > > > > +       /* This xceiver can only send dataframes */
> > > > > > +       if (request->type != NL802154_SCAN_PASSIVE)
> > > > > > +               return -EOPNOTSUPP;
> > > > > > +
> > > > > > +       return 0;
> > > > > > +}
> > > > > > +
> > > > > > +static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
> > > > > > +                                    struct cfg802154_beacons_request *request)
> > > > > > +{
> > > > > > +       /* This xceiver can only send dataframes */
> > > > > > +       return -EOPNOTSUPP;
> > > > > > +}
> > > > > > +
> > > > > > +static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
> > > > > > +
> > > > > >  static const struct ieee802154_ops ca8210_phy_ops = {
> > > > > >         .start = ca8210_start,
> > > > > >         .stop = ca8210_stop,
> > > > > > @@ -2397,7 +2416,11 @@ static const struct ieee802154_ops ca8210_phy_ops = {
> > > > > >         .set_cca_ed_level = ca8210_set_cca_ed_level,
> > > > > >         .set_csma_params = ca8210_set_csma_params,
> > > > > >         .set_frame_retries = ca8210_set_frame_retries,
> > > > > > -       .set_promiscuous_mode = ca8210_set_promiscuous_mode
> > > > > > +       .set_promiscuous_mode = ca8210_set_promiscuous_mode,
> > > > > > +       .enter_scan_mode = ca8210_enter_scan_mode,
> > > > > > +       .exit_scan_mode = ca8210_exit_scan_beacons_mode,
> > > > > > +       .enter_beacons_mode = ca8210_enter_beacons_mode,
> > > > > > +       .exit_beacons_mode = ca8210_exit_scan_beacons_mode,
> > > > > >  };  
> > > > >
> > > > > so there is no flag that this driver can't support scanning currently
> > > > > and it works now because the offload functionality will return
> > > > > -ENOTSUPP? This is misleading because I would assume if it's not
> > > > > supported we can do it by software which the driver can't do.  
> > > >
> > > > I believe there is a misunderstanding.
> > > >
> > > > This is what I have understood from your previous comments in v1:
> > > > "This driver does not support transmitting anything else than
> > > > datagrams", which is what I assumed was a regular data packet. IOW,
> > > > sending a MAC_CMD such as a beacon request or sending a beacon was not
> > > > supported physically by the hardware. Hence, most of the scans
> > > > operations cannot be performed and must be rejected (all but a passive
> > > > scan, assuming that receiving beacons was okay).
> > > >  
> > >
> > > and I said that this driver is a HardMAC transceiver connected to the
> > > SoftMAC layer which is already wrong to exist (very special handling
> > > is required here).
> > > dataframes here are "data" type frames and I suppose it's also not
> > > able to deliver/receive other types than data to mac802154.
> > >
> > > It seems the author of this driver is happy to have data frames only
> > > but we need to take care that additional mac802154 handling is simply
> > > not possible to do here.
> > >  
> > > > Please mind the update in that hook which currently is just an FYI from
> > > > the mac to the drivers and not a "do it by yourself" injunction. So
> > > > answering -EOPNOTSUPP to the mac here does not mean:
> > > >         "I cannot handle it by myself, the scan cannot happen"
> > > > but
> > > >         "I cannot handle the forged frames, so let's just not try"
> > > >  
> > >
> > > The problem here is that a SoftMAC transceiver should always be
> > > capable of doing it by software so the "but case" makes no sense in
> > > this layer.
> > > On a mac802154 layer and "offload" driver functions as they are and
> > > they report me "-ENOTSUPP", I would assume that I can go back and do
> > > it by software which again should always be possible to do in
> > > mac802154.
> > >  
> > > > > ... I see that the offload functions now are getting used and have a
> > > > > reason to be upstream, but the use of it is wrong.  
> > > >
> > > > As a personal matter of taste, I don't like flags when it comes to
> > > > something complex like supporting a specific operation. Just in the
> > > > scanning procedure there are 4 different actions and a driver might
> > > > support only a subset of these, which is totally fine but hard to
> > > > properly describe by well-named flags. Here the driver hooks say to
> > > > the driver which are interested "here is what is going to happen" and
> > > > then they can:
> > > > - ignore the details by just not implementing the hooks, let the mac do
> > > >   its job, they will then transmit the relevant frames forged by the
> > > >   mac
> > > > - eventually enter a specific mode internally for this operation, but
> > > >   basically do the same as above, ie. transmitting the frames forged
> > > >   by the mac
> > > > - refuse the operation by returning an error code if something cannot
> > > >   be done
> > > >
> > > > I've experienced a number of situations in the MTD world and later with
> > > > IIO drivers where flags have been remodeled and reused in different
> > > > manners, until the flag description gets totally wrong and
> > > > undescriptive regarding what it actually does. Hence my main idea of
> > > > letting drivers refuse these operations instead of having the mac doing
> > > > it for them.
> > > >
> > > > I can definitely use flags if you want, but in this case, what flags do
> > > > you want to see?
> > > >  
> > >
> > > Do some phy quirks flags which indicate that the transceiver is not
> > > capable of doing scan operation by software. Or just use a boolean in
> > > phy capabilities (but don't export them to userspace, note that this
> > > flag should be removed later) if this operation is not allowed.  
> >
> > I've added a phy flag to distinguish this driver as early as possible.  
> 
> I was thinking about this a lot and I think the driver is already
> buggy in many ways e.g. what happens when we do AF_PACKET raw sockets
> and do some different frame types than data. I have no idea, maybe we
> should leave it as it is... and simply don't care? Maybe the driver
> needs to drop a lot of frames if they are different... it runs already
> different than other transceivers which we don't check at all.

For now I've handled it with a flag, I'll send the patch as it is so
that someone else can pick it up if you finally decide to not touch
this driver for now and change your mind later on.

I would however argue that having these constraint devices flagged in
some way is better than nothing. You personally know the issue, but
newcomers don't.

Thanks,
Miquèl
diff mbox series

Patch

diff --git a/drivers/net/ieee802154/ca8210.c b/drivers/net/ieee802154/ca8210.c
index d3a9e4fe05f4..49c274280e3c 100644
--- a/drivers/net/ieee802154/ca8210.c
+++ b/drivers/net/ieee802154/ca8210.c
@@ -2385,6 +2385,25 @@  static int ca8210_set_promiscuous_mode(struct ieee802154_hw *hw, const bool on)
 	return link_to_linux_err(status);
 }
 
+static int ca8210_enter_scan_mode(struct ieee802154_hw *hw,
+				  struct cfg802154_scan_request *request)
+{
+	/* This xceiver can only send dataframes */
+	if (request->type != NL802154_SCAN_PASSIVE)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+
+static int ca8210_enter_beacons_mode(struct ieee802154_hw *hw,
+				     struct cfg802154_beacons_request *request)
+{
+	/* This xceiver can only send dataframes */
+	return -EOPNOTSUPP;
+}
+
+static void ca8210_exit_scan_beacons_mode(struct ieee802154_hw *hw) { }
+
 static const struct ieee802154_ops ca8210_phy_ops = {
 	.start = ca8210_start,
 	.stop = ca8210_stop,
@@ -2397,7 +2416,11 @@  static const struct ieee802154_ops ca8210_phy_ops = {
 	.set_cca_ed_level = ca8210_set_cca_ed_level,
 	.set_csma_params = ca8210_set_csma_params,
 	.set_frame_retries = ca8210_set_frame_retries,
-	.set_promiscuous_mode = ca8210_set_promiscuous_mode
+	.set_promiscuous_mode = ca8210_set_promiscuous_mode,
+	.enter_scan_mode = ca8210_enter_scan_mode,
+	.exit_scan_mode = ca8210_exit_scan_beacons_mode,
+	.enter_beacons_mode = ca8210_enter_beacons_mode,
+	.exit_beacons_mode = ca8210_exit_scan_beacons_mode,
 };
 
 /* Test/EVBME Interface */