3838/**
3939 * struct pcie_bwctrl_data - PCIe bandwidth controller
4040 * @set_speed_mutex: Serializes link speed changes
41- * @lbms_count: Count for LBMS (since last reset)
4241 * @cdev: Thermal cooling device associated with the port
4342 */
4443struct pcie_bwctrl_data {
4544 struct mutex set_speed_mutex ;
46- atomic_t lbms_count ;
4745 struct thermal_cooling_device * cdev ;
4846};
4947
50- /*
51- * Prevent port removal during LBMS count accessors and Link Speed changes.
52- *
53- * These have to be differentiated because pcie_bwctrl_change_speed() calls
54- * pcie_retrain_link() which uses LBMS count reset accessor on success
55- * (using just one rwsem triggers "possible recursive locking detected"
56- * warning).
57- */
58- static DECLARE_RWSEM (pcie_bwctrl_lbms_rwsem );
48+ /* Prevent port removal during Link Speed changes. */
5949static DECLARE_RWSEM (pcie_bwctrl_setspeed_rwsem );
6050
6151static bool pcie_valid_speed (enum pci_bus_speed speed )
@@ -127,18 +117,7 @@ static int pcie_bwctrl_change_speed(struct pci_dev *port, u16 target_speed, bool
127117 if (ret != PCIBIOS_SUCCESSFUL )
128118 return pcibios_err_to_errno (ret );
129119
130- ret = pcie_retrain_link (port , use_lt );
131- if (ret < 0 )
132- return ret ;
133-
134- /*
135- * Ensure link speed updates also with platforms that have problems
136- * with notifications.
137- */
138- if (port -> subordinate )
139- pcie_update_link_speed (port -> subordinate );
140-
141- return 0 ;
120+ return pcie_retrain_link (port , use_lt );
142121}
143122
144123/**
@@ -202,15 +181,14 @@ int pcie_set_target_speed(struct pci_dev *port, enum pci_bus_speed speed_req,
202181
203182static void pcie_bwnotif_enable (struct pcie_device * srv )
204183{
205- struct pcie_bwctrl_data * data = srv -> port -> link_bwctrl ;
206184 struct pci_dev * port = srv -> port ;
207185 u16 link_status ;
208186 int ret ;
209187
210- /* Count LBMS seen so far as one */
188+ /* Note if LBMS has been seen so far */
211189 ret = pcie_capability_read_word (port , PCI_EXP_LNKSTA , & link_status );
212190 if (ret == PCIBIOS_SUCCESSFUL && link_status & PCI_EXP_LNKSTA_LBMS )
213- atomic_inc ( & data -> lbms_count );
191+ set_bit ( PCI_LINK_LBMS_SEEN , & port -> priv_flags );
214192
215193 pcie_capability_set_word (port , PCI_EXP_LNKCTL ,
216194 PCI_EXP_LNKCTL_LBMIE | PCI_EXP_LNKCTL_LABIE );
@@ -233,7 +211,6 @@ static void pcie_bwnotif_disable(struct pci_dev *port)
233211static irqreturn_t pcie_bwnotif_irq (int irq , void * context )
234212{
235213 struct pcie_device * srv = context ;
236- struct pcie_bwctrl_data * data = srv -> port -> link_bwctrl ;
237214 struct pci_dev * port = srv -> port ;
238215 u16 link_status , events ;
239216 int ret ;
@@ -247,7 +224,7 @@ static irqreturn_t pcie_bwnotif_irq(int irq, void *context)
247224 return IRQ_NONE ;
248225
249226 if (events & PCI_EXP_LNKSTA_LBMS )
250- atomic_inc ( & data -> lbms_count );
227+ set_bit ( PCI_LINK_LBMS_SEEN , & port -> priv_flags );
251228
252229 pcie_capability_write_word (port , PCI_EXP_LNKSTA , events );
253230
@@ -262,31 +239,10 @@ static irqreturn_t pcie_bwnotif_irq(int irq, void *context)
262239 return IRQ_HANDLED ;
263240}
264241
265- void pcie_reset_lbms_count (struct pci_dev * port )
242+ void pcie_reset_lbms (struct pci_dev * port )
266243{
267- struct pcie_bwctrl_data * data ;
268-
269- guard (rwsem_read )(& pcie_bwctrl_lbms_rwsem );
270- data = port -> link_bwctrl ;
271- if (data )
272- atomic_set (& data -> lbms_count , 0 );
273- else
274- pcie_capability_write_word (port , PCI_EXP_LNKSTA ,
275- PCI_EXP_LNKSTA_LBMS );
276- }
277-
278- int pcie_lbms_count (struct pci_dev * port , unsigned long * val )
279- {
280- struct pcie_bwctrl_data * data ;
281-
282- guard (rwsem_read )(& pcie_bwctrl_lbms_rwsem );
283- data = port -> link_bwctrl ;
284- if (!data )
285- return - ENOTTY ;
286-
287- * val = atomic_read (& data -> lbms_count );
288-
289- return 0 ;
244+ clear_bit (PCI_LINK_LBMS_SEEN , & port -> priv_flags );
245+ pcie_capability_write_word (port , PCI_EXP_LNKSTA , PCI_EXP_LNKSTA_LBMS );
290246}
291247
292248static int pcie_bwnotif_probe (struct pcie_device * srv )
@@ -308,18 +264,16 @@ static int pcie_bwnotif_probe(struct pcie_device *srv)
308264 return ret ;
309265
310266 scoped_guard (rwsem_write , & pcie_bwctrl_setspeed_rwsem ) {
311- scoped_guard (rwsem_write , & pcie_bwctrl_lbms_rwsem ) {
312- port -> link_bwctrl = data ;
313-
314- ret = request_irq (srv -> irq , pcie_bwnotif_irq ,
315- IRQF_SHARED , "PCIe bwctrl" , srv );
316- if (ret ) {
317- port -> link_bwctrl = NULL ;
318- return ret ;
319- }
267+ port -> link_bwctrl = data ;
320268
321- pcie_bwnotif_enable (srv );
269+ ret = request_irq (srv -> irq , pcie_bwnotif_irq ,
270+ IRQF_SHARED , "PCIe bwctrl" , srv );
271+ if (ret ) {
272+ port -> link_bwctrl = NULL ;
273+ return ret ;
322274 }
275+
276+ pcie_bwnotif_enable (srv );
323277 }
324278
325279 pci_dbg (port , "enabled with IRQ %d\n" , srv -> irq );
@@ -339,13 +293,11 @@ static void pcie_bwnotif_remove(struct pcie_device *srv)
339293 pcie_cooling_device_unregister (data -> cdev );
340294
341295 scoped_guard (rwsem_write , & pcie_bwctrl_setspeed_rwsem ) {
342- scoped_guard (rwsem_write , & pcie_bwctrl_lbms_rwsem ) {
343- pcie_bwnotif_disable (srv -> port );
296+ pcie_bwnotif_disable (srv -> port );
344297
345- free_irq (srv -> irq , srv );
298+ free_irq (srv -> irq , srv );
346299
347- srv -> port -> link_bwctrl = NULL ;
348- }
300+ srv -> port -> link_bwctrl = NULL ;
349301 }
350302}
351303
0 commit comments