kernel: bump 5.15 to 5.15.108
[openwrt/staging/dedeckeh.git] / target / linux / generic / backport-5.15 / 783-v6.1-net-sfp-re-implement-soft-state-polling-setup.patch
1 From 8475c4b70b040f9d8cbc308100f2c4d865f810b3 Mon Sep 17 00:00:00 2001
2 From: "Russell King (Oracle)" <rmk+kernel@armlinux.org.uk>
3 Date: Tue, 13 Sep 2022 20:06:27 +0100
4 Subject: [PATCH 1/1] net: sfp: re-implement soft state polling setup
5
6 Re-implement the decision making for soft state polling. Instead of
7 generating the soft state mask in sfp_soft_start_poll() by looking at
8 which GPIOs are available, record their availability in
9 sfp_sm_mod_probe() in sfp->state_hw_mask.
10
11 This will then allow us to clear bits in sfp->state_hw_mask in module
12 specific quirks when the hardware signals should not be used, thereby
13 allowing us to switch to using the software state polling.
14
15 Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
16 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
17 ---
18 drivers/net/phy/sfp.c | 38 ++++++++++++++++++++++++++------------
19 1 file changed, 26 insertions(+), 12 deletions(-)
20
21 --- a/drivers/net/phy/sfp.c
22 +++ b/drivers/net/phy/sfp.c
23 @@ -240,6 +240,7 @@ struct sfp {
24 bool need_poll;
25
26 struct mutex st_mutex; /* Protects state */
27 + unsigned int state_hw_mask;
28 unsigned int state_soft_mask;
29 unsigned int state;
30 struct delayed_work poll;
31 @@ -505,17 +506,18 @@ static void sfp_soft_set_state(struct sf
32 static void sfp_soft_start_poll(struct sfp *sfp)
33 {
34 const struct sfp_eeprom_id *id = &sfp->id;
35 + unsigned int mask = 0;
36
37 sfp->state_soft_mask = 0;
38 - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE &&
39 - !sfp->gpio[GPIO_TX_DISABLE])
40 - sfp->state_soft_mask |= SFP_F_TX_DISABLE;
41 - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT &&
42 - !sfp->gpio[GPIO_TX_FAULT])
43 - sfp->state_soft_mask |= SFP_F_TX_FAULT;
44 - if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS &&
45 - !sfp->gpio[GPIO_LOS])
46 - sfp->state_soft_mask |= SFP_F_LOS;
47 + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE)
48 + mask |= SFP_F_TX_DISABLE;
49 + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT)
50 + mask |= SFP_F_TX_FAULT;
51 + if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS)
52 + mask |= SFP_F_LOS;
53 +
54 + // Poll the soft state for hardware pins we want to ignore
55 + sfp->state_soft_mask = ~sfp->state_hw_mask & mask;
56
57 if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) &&
58 !sfp->need_poll)
59 @@ -529,10 +531,11 @@ static void sfp_soft_stop_poll(struct sf
60
61 static unsigned int sfp_get_state(struct sfp *sfp)
62 {
63 - unsigned int state = sfp->get_state(sfp);
64 + unsigned int soft = sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT);
65 + unsigned int state;
66
67 - if (state & SFP_F_PRESENT &&
68 - sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT))
69 + state = sfp->get_state(sfp) & sfp->state_hw_mask;
70 + if (state & SFP_F_PRESENT && soft)
71 state |= sfp_soft_get_state(sfp);
72
73 return state;
74 @@ -1942,6 +1945,15 @@ static int sfp_sm_mod_probe(struct sfp *
75 if (ret < 0)
76 return ret;
77
78 + /* Initialise state bits to use from hardware */
79 + sfp->state_hw_mask = SFP_F_PRESENT;
80 + if (sfp->gpio[GPIO_TX_DISABLE])
81 + sfp->state_hw_mask |= SFP_F_TX_DISABLE;
82 + if (sfp->gpio[GPIO_TX_FAULT])
83 + sfp->state_hw_mask |= SFP_F_TX_FAULT;
84 + if (sfp->gpio[GPIO_LOS])
85 + sfp->state_hw_mask |= SFP_F_LOS;
86 +
87 if (!memcmp(id.base.vendor_name, "ALCATELLUCENT ", 16) &&
88 !memcmp(id.base.vendor_pn, "3FE46541AA ", 16))
89 sfp->module_t_start_up = T_START_UP_BAD_GPON;
90 @@ -2568,6 +2580,8 @@ static int sfp_probe(struct platform_dev
91 return PTR_ERR(sfp->gpio[i]);
92 }
93
94 + sfp->state_hw_mask = SFP_F_PRESENT;
95 +
96 sfp->get_state = sfp_gpio_get_state;
97 sfp->set_state = sfp_gpio_set_state;
98