Re: [PATCH net v5 2/2] net: fec: Let fec_ptp have its own interrupt routine

2017-11-07 Thread David Miller
From: Troy Kisky 
Date: Fri,  3 Nov 2017 10:29:59 -0700

> This is better for code locality and should slightly
> speed up normal interrupts.
> 
> This also allows PPS clock output to start working for
> i.mx7. This is because i.mx7 was already using the limit
> of 3 interrupts, and needed another.
> 
> Signed-off-by: Troy Kisky 

Applied to net-next, thank you.

I am assume that patch #1 will go via the ARM tree.


RE: [PATCH net v5 2/2] net: fec: Let fec_ptp have its own interrupt routine

2017-11-05 Thread Andy Duan
From: Troy Kisky  Sent: Saturday, November 04, 
2017 1:30 AM
>This is better for code locality and should slightly speed up normal 
>interrupts.
>
>This also allows PPS clock output to start working for i.mx7. This is because
>i.mx7 was already using the limit of 3 interrupts, and needed another.
>
>Signed-off-by: Troy Kisky 
>

This version seems fine for me. Thanks.
Acked-by: Fugang Duan 

>---
>
>v2: made this change independent of any devicetree change so that old dtbs
>continue to work.
>
>Continue to register ptp clock if interrupt is not found.
>
>v3: renamed "ptp" interrupt to "pps" interrupt
>
>v4: no change
>
>v5: moving binding documentation to this patch
>   as requested by Shawn Guo
>s/irq_index/irq_idx/
>add function fec_enet_get_irq_cnt() to encapsulate if,
>   as requested by Andy Duan
>---
> Documentation/devicetree/bindings/net/fsl-fec.txt | 13 
> drivers/net/ethernet/freescale/fec.h  |  3 +-
> drivers/net/ethernet/freescale/fec_main.c | 31 ++---
> drivers/net/ethernet/freescale/fec_ptp.c  | 82 +--
> 4 files changed, 84 insertions(+), 45 deletions(-)
>
>diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt
>b/Documentation/devicetree/bindings/net/fsl-fec.txt
>index 6f55bdd52f8a..f0dc94409107 100644
>--- a/Documentation/devicetree/bindings/net/fsl-fec.txt
>+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
>@@ -34,6 +34,19 @@ Optional properties:
> - fsl,err006687-workaround-present: If present indicates that the system has
>   the hardware workaround for ERR006687 applied and does not need a
>software
>   workaround.
>+ -interrupt-names:  names of the interrupts listed in interrupts
>+property in
>+  the same order. The defaults if not specified are
>+  __Number of interrupts__   __Default__
>+  1   "int0"
>+  2   "int0", "pps"
>+  3   "int0", "int1", "int2"
>+  4   "int0", "int1", "int2", "pps"
>+  The order may be changed as long as they correspond to the interrupts
>+  property. Currently, only i.mx7 uses "int1" and "int2". They
>+correspond to
>+  tx/rx queues 1 and 2. "int0" will be used for queue 0 and ENET_MII
>interrupts.
>+  For imx6sx, "int0" handles all 3 queues and ENET_MII. "pps" is for
>+the pulse
>+  per second interrupt associated with 1588 precision time protocol(PTP).
>+
>
> Optional subnodes:
> - mdio : specifies the mdio bus in the FEC, used as a container for phy nodes
>diff --git a/drivers/net/ethernet/freescale/fec.h
>b/drivers/net/ethernet/freescale/fec.h
>index ede1876a9a19..0af58991ca8f 100644
>--- a/drivers/net/ethernet/freescale/fec.h
>+++ b/drivers/net/ethernet/freescale/fec.h
>@@ -582,12 +582,11 @@ struct fec_enet_private {
>   u64 ethtool_stats[0];
> };
>
>-void fec_ptp_init(struct platform_device *pdev);
>+void fec_ptp_init(struct platform_device *pdev, int irq_idx);
> void fec_ptp_stop(struct platform_device *pdev);  void
>fec_ptp_start_cyclecounter(struct net_device *ndev);  int fec_ptp_set(struct
>net_device *ndev, struct ifreq *ifr);  int fec_ptp_get(struct net_device *ndev,
>struct ifreq *ifr); -uint fec_ptp_check_pps_event(struct fec_enet_private
>*fep);
>
>
>/**
>**/
> #endif /* FEC_H */
>diff --git a/drivers/net/ethernet/freescale/fec_main.c
>b/drivers/net/ethernet/freescale/fec_main.c
>index 3dc2d771a222..610573855213 100644
>--- a/drivers/net/ethernet/freescale/fec_main.c
>+++ b/drivers/net/ethernet/freescale/fec_main.c
>@@ -1602,10 +1602,6 @@ fec_enet_interrupt(int irq, void *dev_id)
>   ret = IRQ_HANDLED;
>   complete(>mdio_done);
>   }
>-
>-  if (fep->ptp_clock)
>-  if (fec_ptp_check_pps_event(fep))
>-  ret = IRQ_HANDLED;
>   return ret;
> }
>
>@@ -3312,6 +3308,19 @@ fec_enet_get_queue_num(struct platform_device
>*pdev, int *num_tx, int *num_rx)
>
> }
>
>+static int fec_enet_get_irq_cnt(struct platform_device *pdev) {
>+  int irq_cnt = platform_irq_count(pdev);
>+
>+  if (irq_cnt > FEC_IRQ_NUM)
>+  irq_cnt = FEC_IRQ_NUM;  /* last for pps */
>+  else if (irq_cnt == 2)
>+  irq_cnt = 1;/* last for pps */
>+  else if (irq_cnt <= 0)
>+  irq_cnt = 1;/* At least 1 irq is needed */
>+  return irq_cnt;
>+}
>+
> static int
> fec_probe(struct platform_device *pdev)  { @@ -3325,6 +3334,8 @@
>fec_probe(struct platform_device *pdev)
>   struct device_node *np = pdev->dev.of_node, *phy_node;
>   int num_tx_qs;
>   int num_rx_qs;
>+  char irq_name[8];
>+  int irq_cnt;
>
>   fec_enet_get_queue_num(pdev, _tx_qs, _rx_qs);
>
>@@ -3465,18 +3476,20 @@ fec_probe(struct platform_device *pdev)
>   if (ret)
>   goto failed_reset;
>
>+  irq_cnt = 

[PATCH net v5 2/2] net: fec: Let fec_ptp have its own interrupt routine

2017-11-03 Thread Troy Kisky
This is better for code locality and should slightly
speed up normal interrupts.

This also allows PPS clock output to start working for
i.mx7. This is because i.mx7 was already using the limit
of 3 interrupts, and needed another.

Signed-off-by: Troy Kisky 

---

v2: made this change independent of any devicetree change
so that old dtbs continue to work.

Continue to register ptp clock if interrupt is not found.

v3: renamed "ptp" interrupt to "pps" interrupt

v4: no change

v5: moving binding documentation to this patch
as requested by Shawn Guo
s/irq_index/irq_idx/
add function fec_enet_get_irq_cnt() to encapsulate if,
as requested by Andy Duan
---
 Documentation/devicetree/bindings/net/fsl-fec.txt | 13 
 drivers/net/ethernet/freescale/fec.h  |  3 +-
 drivers/net/ethernet/freescale/fec_main.c | 31 ++---
 drivers/net/ethernet/freescale/fec_ptp.c  | 82 +--
 4 files changed, 84 insertions(+), 45 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/fsl-fec.txt 
b/Documentation/devicetree/bindings/net/fsl-fec.txt
index 6f55bdd52f8a..f0dc94409107 100644
--- a/Documentation/devicetree/bindings/net/fsl-fec.txt
+++ b/Documentation/devicetree/bindings/net/fsl-fec.txt
@@ -34,6 +34,19 @@ Optional properties:
 - fsl,err006687-workaround-present: If present indicates that the system has
   the hardware workaround for ERR006687 applied and does not need a software
   workaround.
+ -interrupt-names:  names of the interrupts listed in interrupts property in
+  the same order. The defaults if not specified are
+  __Number of interrupts__   __Default__
+   1   "int0"
+   2   "int0", "pps"
+   3   "int0", "int1", "int2"
+   4   "int0", "int1", "int2", "pps"
+  The order may be changed as long as they correspond to the interrupts
+  property. Currently, only i.mx7 uses "int1" and "int2". They correspond to
+  tx/rx queues 1 and 2. "int0" will be used for queue 0 and ENET_MII 
interrupts.
+  For imx6sx, "int0" handles all 3 queues and ENET_MII. "pps" is for the pulse
+  per second interrupt associated with 1588 precision time protocol(PTP).
+
 
 Optional subnodes:
 - mdio : specifies the mdio bus in the FEC, used as a container for phy nodes
diff --git a/drivers/net/ethernet/freescale/fec.h 
b/drivers/net/ethernet/freescale/fec.h
index ede1876a9a19..0af58991ca8f 100644
--- a/drivers/net/ethernet/freescale/fec.h
+++ b/drivers/net/ethernet/freescale/fec.h
@@ -582,12 +582,11 @@ struct fec_enet_private {
u64 ethtool_stats[0];
 };
 
-void fec_ptp_init(struct platform_device *pdev);
+void fec_ptp_init(struct platform_device *pdev, int irq_idx);
 void fec_ptp_stop(struct platform_device *pdev);
 void fec_ptp_start_cyclecounter(struct net_device *ndev);
 int fec_ptp_set(struct net_device *ndev, struct ifreq *ifr);
 int fec_ptp_get(struct net_device *ndev, struct ifreq *ifr);
-uint fec_ptp_check_pps_event(struct fec_enet_private *fep);
 
 //
 #endif /* FEC_H */
diff --git a/drivers/net/ethernet/freescale/fec_main.c 
b/drivers/net/ethernet/freescale/fec_main.c
index 3dc2d771a222..610573855213 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -1602,10 +1602,6 @@ fec_enet_interrupt(int irq, void *dev_id)
ret = IRQ_HANDLED;
complete(>mdio_done);
}
-
-   if (fep->ptp_clock)
-   if (fec_ptp_check_pps_event(fep))
-   ret = IRQ_HANDLED;
return ret;
 }
 
@@ -3312,6 +3308,19 @@ fec_enet_get_queue_num(struct platform_device *pdev, int 
*num_tx, int *num_rx)
 
 }
 
+static int fec_enet_get_irq_cnt(struct platform_device *pdev)
+{
+   int irq_cnt = platform_irq_count(pdev);
+
+   if (irq_cnt > FEC_IRQ_NUM)
+   irq_cnt = FEC_IRQ_NUM;  /* last for pps */
+   else if (irq_cnt == 2)
+   irq_cnt = 1;/* last for pps */
+   else if (irq_cnt <= 0)
+   irq_cnt = 1;/* At least 1 irq is needed */
+   return irq_cnt;
+}
+
 static int
 fec_probe(struct platform_device *pdev)
 {
@@ -3325,6 +3334,8 @@ fec_probe(struct platform_device *pdev)
struct device_node *np = pdev->dev.of_node, *phy_node;
int num_tx_qs;
int num_rx_qs;
+   char irq_name[8];
+   int irq_cnt;
 
fec_enet_get_queue_num(pdev, _tx_qs, _rx_qs);
 
@@ -3465,18 +3476,20 @@ fec_probe(struct platform_device *pdev)
if (ret)
goto failed_reset;
 
+   irq_cnt = fec_enet_get_irq_cnt(pdev);
if (fep->bufdesc_ex)
-   fec_ptp_init(pdev);
+   fec_ptp_init(pdev, irq_cnt);
 
ret = fec_enet_init(ndev);
if (ret)
goto failed_init;
 
-   for (i = 0; i < FEC_IRQ_NUM; i++) {
-