History

PCI/ATS: Cache PRI Capability offset

Previously each PRI interface searched for the PRI Capability. Cache the capability offset the first time we use it instead of searching each time. [bhelgaas: commit log, reorder patch to later, call pci_pri_init() from pci_init_capabilities()] Link: https://lore.kernel.org/r/0c5495d376faf6dbb8eb2165204c474438aaae65.156 7029860.git.sathyanarayanan.kuppuswamy@linux.intel.com Link: https://lore.kernel.org/r/20190905193146.90250-5-helgaas@kernel.org Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

Kuppuswamy Sathyanarayanan committed 7 years ago

Commit c0651901 parent 3ad62194 files · +36 −25Browse files

Unified · Split

4 files
  1. drivers/pci/ats.c +26 −25
  2. drivers/pci/pci.h +6 −0
  3. drivers/pci/probe.c +3 −0
  4. include/linux/pci.h +1 −0
drivers/pci/ats.c+26−25
@@ -159,6 +159,11 @@ int pci_ats_page_aligned(struct pci_dev *pdev) · 158 unmodified lines
159159 EXPORT_SYMBOL_GPL(pci_ats_page_aligned);
160160
161161 #ifdef CONFIG_PCI_PRI
162+void pci_pri_init(struct pci_dev *pdev)
163+{
164+ pdev->pri_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
165+}
166+
162167 /**
163168 * pci_enable_pri - Enable PRI capability
164169 * @ pdev: PCI device structure
@@ -169,7 +174,7 @@ int pci_enable_pri(struct pci_dev *pdev, u32 reqs) · 4 unmodified lines
169174 {
170175 u16 control, status;
171176 u32 max_requests;
172− int pos;
177+ int pri = pdev->pri_cap;
173178
174179 /*
175180 * VFs must not implement the PRI Capability. If their PF
@@ -185,21 +190,20 @@ int pci_enable_pri(struct pci_dev *pdev, u32 reqs) · 9 unmodified lines
185190 if (WARN_ON(pdev->pri_enabled))
186191 return -EBUSY;
187192
188− pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
189− if (!pos)
193+ if (!pri)
190194 return -EINVAL;
191195
192− pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status);
196+ pci_read_config_word(pdev, pri + PCI_PRI_STATUS, &status);
193197 if (!(status & PCI_PRI_STATUS_STOPPED))
194198 return -EBUSY;
195199
196− pci_read_config_dword(pdev, pos + PCI_PRI_MAX_REQ, &max_requests);
200+ pci_read_config_dword(pdev, pri + PCI_PRI_MAX_REQ, &max_requests);
197201 reqs = min(max_requests, reqs);
198202 pdev->pri_reqs_alloc = reqs;
199− pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs);
203+ pci_write_config_dword(pdev, pri + PCI_PRI_ALLOC_REQ, reqs);
200204
201205 control = PCI_PRI_CTRL_ENABLE;
202− pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
206+ pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control);
203207
204208 pdev->pri_enabled = 1;
205209
@@ -216,7 +220,7 @@ EXPORT_SYMBOL_GPL(pci_enable_pri); · 10 unmodified lines
216220 void pci_disable_pri(struct pci_dev *pdev)
217221 {
218222 u16 control;
219− int pos;
223+ int pri = pdev->pri_cap;
220224
221225 /* VFs share the PF PRI */
222226 if (pdev->is_virtfn)
@@ -225,13 +229,12 @@ void pci_disable_pri(struct pci_dev *pdev) · 2 unmodified lines
225229 if (WARN_ON(!pdev->pri_enabled))
226230 return;
227231
228− pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
229− if (!pos)
232+ if (!pri)
230233 return;
231234
232− pci_read_config_word(pdev, pos + PCI_PRI_CTRL, &control);
235+ pci_read_config_word(pdev, pri + PCI_PRI_CTRL, &control);
233236 control &= ~PCI_PRI_CTRL_ENABLE;
234− pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
237+ pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control);
235238
236239 pdev->pri_enabled = 0;
237240 }
@@ -245,7 +248,7 @@ void pci_restore_pri_state(struct pci_dev *pdev) · 7 unmodified lines
245248 {
246249 u16 control = PCI_PRI_CTRL_ENABLE;
247250 u32 reqs = pdev->pri_reqs_alloc;
248− int pos;
251+ int pri = pdev->pri_cap;
249252
250253 if (pdev->is_virtfn)
251254 return;
@@ -253,12 +256,11 @@ void pci_restore_pri_state(struct pci_dev *pdev) · 1 unmodified line
253256 if (!pdev->pri_enabled)
254257 return;
255258
256− pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
257− if (!pos)
259+ if (!pri)
258260 return;
259261
260− pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs);
261− pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
262+ pci_write_config_dword(pdev, pri + PCI_PRI_ALLOC_REQ, reqs);
263+ pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control);
262264 }
263265 EXPORT_SYMBOL_GPL(pci_restore_pri_state);
264266
@@ -272,7 +274,7 @@ EXPORT_SYMBOL_GPL(pci_restore_pri_state); · 7 unmodified lines
272274 int pci_reset_pri(struct pci_dev *pdev)
273275 {
274276 u16 control;
275− int pos;
277+ int pri = pdev->pri_cap;
276278
277279 if (pdev->is_virtfn)
278280 return 0;
@@ -280,12 +282,11 @@ int pci_reset_pri(struct pci_dev *pdev) · 1 unmodified line
280282 if (WARN_ON(pdev->pri_enabled))
281283 return -EBUSY;
282284
283− pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
284− if (!pos)
285+ if (!pri)
285286 return -EINVAL;
286287
287288 control = PCI_PRI_CTRL_RESET;
288− pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control);
289+ pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control);
289290
290291 return 0;
291292 }
@@ -301,16 +302,16 @@ EXPORT_SYMBOL_GPL(pci_reset_pri); · 9 unmodified lines
301302 int pci_prg_resp_pasid_required(struct pci_dev *pdev)
302303 {
303304 u16 status;
304− int pos;
305+ int pri;
305306
306307 if (pdev->is_virtfn)
307308 pdev = pci_physfn(pdev);
308309
309− pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI);
310− if (!pos)
310+ pri = pdev->pri_cap;
311+ if (!pri)
311312 return 0;
312313
313− pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status);
314+ pci_read_config_word(pdev, pri + PCI_PRI_STATUS, &status);
314315
315316 if (status & PCI_PRI_STATUS_PASID)
316317 return 1;
drivers/pci/pci.h+6−0
@@ -456,6 +456,12 @@ static inline void pci_ats_init(struct pci_dev *d) { } · 455 unmodified lines
456456 static inline void pci_restore_ats_state(struct pci_dev *dev) { }
457457 #endif /* CONFIG_PCI_ATS */
458458
459+#ifdef CONFIG_PCI_PRI
460+void pci_pri_init(struct pci_dev *dev);
461+#else
462+static inline void pci_pri_init(struct pci_dev *dev) { }
463+#endif
464+
459465 #ifdef CONFIG_PCI_IOV
460466 int pci_iov_init(struct pci_dev *dev);
461467 void pci_iov_release(struct pci_dev *dev);
drivers/pci/probe.c+3−0
@@ -2324,6 +2324,9 @@ static void pci_init_capabilities(struct pci_dev *dev) · 2323 unmodified lines
23242324 /* Address Translation Services */
23252325 pci_ats_init(dev);
23262326
2327+ /* Page Request Interface */
2328+ pci_pri_init(dev);
2329+
23272330 /* Enable ACS P2P upstream forwarding */
23282331 pci_enable_acs(dev);
23292332
include/linux/pci.h+1−0
@@ -454,6 +454,7 @@ struct pci_dev { · 453 unmodified lines
454454 u8 ats_stu; /* ATS Smallest Translation Unit */
455455 #endif
456456 #ifdef CONFIG_PCI_PRI
457+ u16 pri_cap; /* PRI Capability offset */
457458 u32 pri_reqs_alloc; /* Number of PRI requests allocated */
458459 #endif
459460 #ifdef CONFIG_PCI_PASID

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t