| .. | .. |
|---|
| 31 | 31 | } |
|---|
| 32 | 32 | |
|---|
| 33 | 33 | /** |
|---|
| 34 | + * pci_ats_supported - check if the device can use ATS |
|---|
| 35 | + * @dev: the PCI device |
|---|
| 36 | + * |
|---|
| 37 | + * Returns true if the device supports ATS and is allowed to use it, false |
|---|
| 38 | + * otherwise. |
|---|
| 39 | + */ |
|---|
| 40 | +bool pci_ats_supported(struct pci_dev *dev) |
|---|
| 41 | +{ |
|---|
| 42 | + if (!dev->ats_cap) |
|---|
| 43 | + return false; |
|---|
| 44 | + |
|---|
| 45 | + return (dev->untrusted == 0); |
|---|
| 46 | +} |
|---|
| 47 | +EXPORT_SYMBOL_GPL(pci_ats_supported); |
|---|
| 48 | + |
|---|
| 49 | +/** |
|---|
| 34 | 50 | * pci_enable_ats - enable the ATS capability |
|---|
| 35 | 51 | * @dev: the PCI device |
|---|
| 36 | 52 | * @ps: the IOMMU page shift |
|---|
| .. | .. |
|---|
| 42 | 58 | u16 ctrl; |
|---|
| 43 | 59 | struct pci_dev *pdev; |
|---|
| 44 | 60 | |
|---|
| 45 | | - if (!dev->ats_cap) |
|---|
| 61 | + if (!pci_ats_supported(dev)) |
|---|
| 46 | 62 | return -EINVAL; |
|---|
| 47 | 63 | |
|---|
| 48 | 64 | if (WARN_ON(dev->ats_enabled)) |
|---|
| .. | .. |
|---|
| 60 | 76 | pdev = pci_physfn(dev); |
|---|
| 61 | 77 | if (pdev->ats_stu != ps) |
|---|
| 62 | 78 | return -EINVAL; |
|---|
| 63 | | - |
|---|
| 64 | | - atomic_inc(&pdev->ats_ref_cnt); /* count enabled VFs */ |
|---|
| 65 | 79 | } else { |
|---|
| 66 | 80 | dev->ats_stu = ps; |
|---|
| 67 | 81 | ctrl |= PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU); |
|---|
| .. | .. |
|---|
| 79 | 93 | */ |
|---|
| 80 | 94 | void pci_disable_ats(struct pci_dev *dev) |
|---|
| 81 | 95 | { |
|---|
| 82 | | - struct pci_dev *pdev; |
|---|
| 83 | 96 | u16 ctrl; |
|---|
| 84 | 97 | |
|---|
| 85 | 98 | if (WARN_ON(!dev->ats_enabled)) |
|---|
| 86 | 99 | return; |
|---|
| 87 | | - |
|---|
| 88 | | - if (atomic_read(&dev->ats_ref_cnt)) |
|---|
| 89 | | - return; /* VFs still enabled */ |
|---|
| 90 | | - |
|---|
| 91 | | - if (dev->is_virtfn) { |
|---|
| 92 | | - pdev = pci_physfn(dev); |
|---|
| 93 | | - atomic_dec(&pdev->ats_ref_cnt); |
|---|
| 94 | | - } |
|---|
| 95 | 100 | |
|---|
| 96 | 101 | pci_read_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, &ctrl); |
|---|
| 97 | 102 | ctrl &= ~PCI_ATS_CTRL_ENABLE; |
|---|
| .. | .. |
|---|
| 113 | 118 | ctrl |= PCI_ATS_CTRL_STU(dev->ats_stu - PCI_ATS_MIN_STU); |
|---|
| 114 | 119 | pci_write_config_word(dev, dev->ats_cap + PCI_ATS_CTRL, ctrl); |
|---|
| 115 | 120 | } |
|---|
| 116 | | -EXPORT_SYMBOL_GPL(pci_restore_ats_state); |
|---|
| 117 | 121 | |
|---|
| 118 | 122 | /** |
|---|
| 119 | 123 | * pci_ats_queue_depth - query the ATS Invalidate Queue Depth |
|---|
| .. | .. |
|---|
| 140 | 144 | pci_read_config_word(dev, dev->ats_cap + PCI_ATS_CAP, &cap); |
|---|
| 141 | 145 | return PCI_ATS_CAP_QDEP(cap) ? PCI_ATS_CAP_QDEP(cap) : PCI_ATS_MAX_QDEP; |
|---|
| 142 | 146 | } |
|---|
| 143 | | -EXPORT_SYMBOL_GPL(pci_ats_queue_depth); |
|---|
| 147 | + |
|---|
| 148 | +/** |
|---|
| 149 | + * pci_ats_page_aligned - Return Page Aligned Request bit status. |
|---|
| 150 | + * @pdev: the PCI device |
|---|
| 151 | + * |
|---|
| 152 | + * Returns 1, if the Untranslated Addresses generated by the device |
|---|
| 153 | + * are always aligned or 0 otherwise. |
|---|
| 154 | + * |
|---|
| 155 | + * Per PCIe spec r4.0, sec 10.5.1.2, if the Page Aligned Request bit |
|---|
| 156 | + * is set, it indicates the Untranslated Addresses generated by the |
|---|
| 157 | + * device are always aligned to a 4096 byte boundary. |
|---|
| 158 | + */ |
|---|
| 159 | +int pci_ats_page_aligned(struct pci_dev *pdev) |
|---|
| 160 | +{ |
|---|
| 161 | + u16 cap; |
|---|
| 162 | + |
|---|
| 163 | + if (!pdev->ats_cap) |
|---|
| 164 | + return 0; |
|---|
| 165 | + |
|---|
| 166 | + pci_read_config_word(pdev, pdev->ats_cap + PCI_ATS_CAP, &cap); |
|---|
| 167 | + |
|---|
| 168 | + if (cap & PCI_ATS_CAP_PAGE_ALIGNED) |
|---|
| 169 | + return 1; |
|---|
| 170 | + |
|---|
| 171 | + return 0; |
|---|
| 172 | +} |
|---|
| 144 | 173 | |
|---|
| 145 | 174 | #ifdef CONFIG_PCI_PRI |
|---|
| 175 | +void pci_pri_init(struct pci_dev *pdev) |
|---|
| 176 | +{ |
|---|
| 177 | + u16 status; |
|---|
| 178 | + |
|---|
| 179 | + pdev->pri_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI); |
|---|
| 180 | + |
|---|
| 181 | + if (!pdev->pri_cap) |
|---|
| 182 | + return; |
|---|
| 183 | + |
|---|
| 184 | + pci_read_config_word(pdev, pdev->pri_cap + PCI_PRI_STATUS, &status); |
|---|
| 185 | + if (status & PCI_PRI_STATUS_PASID) |
|---|
| 186 | + pdev->pasid_required = 1; |
|---|
| 187 | +} |
|---|
| 188 | + |
|---|
| 146 | 189 | /** |
|---|
| 147 | 190 | * pci_enable_pri - Enable PRI capability |
|---|
| 148 | | - * @ pdev: PCI device structure |
|---|
| 191 | + * @pdev: PCI device structure |
|---|
| 192 | + * @reqs: outstanding requests |
|---|
| 149 | 193 | * |
|---|
| 150 | 194 | * Returns 0 on success, negative value on error |
|---|
| 151 | 195 | */ |
|---|
| .. | .. |
|---|
| 153 | 197 | { |
|---|
| 154 | 198 | u16 control, status; |
|---|
| 155 | 199 | u32 max_requests; |
|---|
| 156 | | - int pos; |
|---|
| 200 | + int pri = pdev->pri_cap; |
|---|
| 201 | + |
|---|
| 202 | + /* |
|---|
| 203 | + * VFs must not implement the PRI Capability. If their PF |
|---|
| 204 | + * implements PRI, it is shared by the VFs, so if the PF PRI is |
|---|
| 205 | + * enabled, it is also enabled for the VF. |
|---|
| 206 | + */ |
|---|
| 207 | + if (pdev->is_virtfn) { |
|---|
| 208 | + if (pci_physfn(pdev)->pri_enabled) |
|---|
| 209 | + return 0; |
|---|
| 210 | + return -EINVAL; |
|---|
| 211 | + } |
|---|
| 157 | 212 | |
|---|
| 158 | 213 | if (WARN_ON(pdev->pri_enabled)) |
|---|
| 159 | 214 | return -EBUSY; |
|---|
| 160 | 215 | |
|---|
| 161 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI); |
|---|
| 162 | | - if (!pos) |
|---|
| 216 | + if (!pri) |
|---|
| 163 | 217 | return -EINVAL; |
|---|
| 164 | 218 | |
|---|
| 165 | | - pci_read_config_word(pdev, pos + PCI_PRI_STATUS, &status); |
|---|
| 219 | + pci_read_config_word(pdev, pri + PCI_PRI_STATUS, &status); |
|---|
| 166 | 220 | if (!(status & PCI_PRI_STATUS_STOPPED)) |
|---|
| 167 | 221 | return -EBUSY; |
|---|
| 168 | 222 | |
|---|
| 169 | | - pci_read_config_dword(pdev, pos + PCI_PRI_MAX_REQ, &max_requests); |
|---|
| 223 | + pci_read_config_dword(pdev, pri + PCI_PRI_MAX_REQ, &max_requests); |
|---|
| 170 | 224 | reqs = min(max_requests, reqs); |
|---|
| 171 | 225 | pdev->pri_reqs_alloc = reqs; |
|---|
| 172 | | - pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs); |
|---|
| 226 | + pci_write_config_dword(pdev, pri + PCI_PRI_ALLOC_REQ, reqs); |
|---|
| 173 | 227 | |
|---|
| 174 | 228 | control = PCI_PRI_CTRL_ENABLE; |
|---|
| 175 | | - pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control); |
|---|
| 229 | + pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control); |
|---|
| 176 | 230 | |
|---|
| 177 | 231 | pdev->pri_enabled = 1; |
|---|
| 178 | 232 | |
|---|
| 179 | 233 | return 0; |
|---|
| 180 | 234 | } |
|---|
| 181 | | -EXPORT_SYMBOL_GPL(pci_enable_pri); |
|---|
| 182 | 235 | |
|---|
| 183 | 236 | /** |
|---|
| 184 | 237 | * pci_disable_pri - Disable PRI capability |
|---|
| .. | .. |
|---|
| 189 | 242 | void pci_disable_pri(struct pci_dev *pdev) |
|---|
| 190 | 243 | { |
|---|
| 191 | 244 | u16 control; |
|---|
| 192 | | - int pos; |
|---|
| 245 | + int pri = pdev->pri_cap; |
|---|
| 246 | + |
|---|
| 247 | + /* VFs share the PF PRI */ |
|---|
| 248 | + if (pdev->is_virtfn) |
|---|
| 249 | + return; |
|---|
| 193 | 250 | |
|---|
| 194 | 251 | if (WARN_ON(!pdev->pri_enabled)) |
|---|
| 195 | 252 | return; |
|---|
| 196 | 253 | |
|---|
| 197 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI); |
|---|
| 198 | | - if (!pos) |
|---|
| 254 | + if (!pri) |
|---|
| 199 | 255 | return; |
|---|
| 200 | 256 | |
|---|
| 201 | | - pci_read_config_word(pdev, pos + PCI_PRI_CTRL, &control); |
|---|
| 257 | + pci_read_config_word(pdev, pri + PCI_PRI_CTRL, &control); |
|---|
| 202 | 258 | control &= ~PCI_PRI_CTRL_ENABLE; |
|---|
| 203 | | - pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control); |
|---|
| 259 | + pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control); |
|---|
| 204 | 260 | |
|---|
| 205 | 261 | pdev->pri_enabled = 0; |
|---|
| 206 | 262 | } |
|---|
| .. | .. |
|---|
| 214 | 270 | { |
|---|
| 215 | 271 | u16 control = PCI_PRI_CTRL_ENABLE; |
|---|
| 216 | 272 | u32 reqs = pdev->pri_reqs_alloc; |
|---|
| 217 | | - int pos; |
|---|
| 273 | + int pri = pdev->pri_cap; |
|---|
| 274 | + |
|---|
| 275 | + if (pdev->is_virtfn) |
|---|
| 276 | + return; |
|---|
| 218 | 277 | |
|---|
| 219 | 278 | if (!pdev->pri_enabled) |
|---|
| 220 | 279 | return; |
|---|
| 221 | 280 | |
|---|
| 222 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI); |
|---|
| 223 | | - if (!pos) |
|---|
| 281 | + if (!pri) |
|---|
| 224 | 282 | return; |
|---|
| 225 | 283 | |
|---|
| 226 | | - pci_write_config_dword(pdev, pos + PCI_PRI_ALLOC_REQ, reqs); |
|---|
| 227 | | - pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control); |
|---|
| 284 | + pci_write_config_dword(pdev, pri + PCI_PRI_ALLOC_REQ, reqs); |
|---|
| 285 | + pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control); |
|---|
| 228 | 286 | } |
|---|
| 229 | | -EXPORT_SYMBOL_GPL(pci_restore_pri_state); |
|---|
| 230 | 287 | |
|---|
| 231 | 288 | /** |
|---|
| 232 | 289 | * pci_reset_pri - Resets device's PRI state |
|---|
| .. | .. |
|---|
| 238 | 295 | int pci_reset_pri(struct pci_dev *pdev) |
|---|
| 239 | 296 | { |
|---|
| 240 | 297 | u16 control; |
|---|
| 241 | | - int pos; |
|---|
| 298 | + int pri = pdev->pri_cap; |
|---|
| 299 | + |
|---|
| 300 | + if (pdev->is_virtfn) |
|---|
| 301 | + return 0; |
|---|
| 242 | 302 | |
|---|
| 243 | 303 | if (WARN_ON(pdev->pri_enabled)) |
|---|
| 244 | 304 | return -EBUSY; |
|---|
| 245 | 305 | |
|---|
| 246 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI); |
|---|
| 247 | | - if (!pos) |
|---|
| 306 | + if (!pri) |
|---|
| 248 | 307 | return -EINVAL; |
|---|
| 249 | 308 | |
|---|
| 250 | 309 | control = PCI_PRI_CTRL_RESET; |
|---|
| 251 | | - pci_write_config_word(pdev, pos + PCI_PRI_CTRL, control); |
|---|
| 310 | + pci_write_config_word(pdev, pri + PCI_PRI_CTRL, control); |
|---|
| 252 | 311 | |
|---|
| 253 | 312 | return 0; |
|---|
| 254 | 313 | } |
|---|
| 255 | | -EXPORT_SYMBOL_GPL(pci_reset_pri); |
|---|
| 314 | + |
|---|
| 315 | +/** |
|---|
| 316 | + * pci_prg_resp_pasid_required - Return PRG Response PASID Required bit |
|---|
| 317 | + * status. |
|---|
| 318 | + * @pdev: PCI device structure |
|---|
| 319 | + * |
|---|
| 320 | + * Returns 1 if PASID is required in PRG Response Message, 0 otherwise. |
|---|
| 321 | + */ |
|---|
| 322 | +int pci_prg_resp_pasid_required(struct pci_dev *pdev) |
|---|
| 323 | +{ |
|---|
| 324 | + if (pdev->is_virtfn) |
|---|
| 325 | + pdev = pci_physfn(pdev); |
|---|
| 326 | + |
|---|
| 327 | + return pdev->pasid_required; |
|---|
| 328 | +} |
|---|
| 329 | + |
|---|
| 330 | +/** |
|---|
| 331 | + * pci_pri_supported - Check if PRI is supported. |
|---|
| 332 | + * @pdev: PCI device structure |
|---|
| 333 | + * |
|---|
| 334 | + * Returns true if PRI capability is present, false otherwise. |
|---|
| 335 | + */ |
|---|
| 336 | +bool pci_pri_supported(struct pci_dev *pdev) |
|---|
| 337 | +{ |
|---|
| 338 | + /* VFs share the PF PRI */ |
|---|
| 339 | + if (pci_physfn(pdev)->pri_cap) |
|---|
| 340 | + return true; |
|---|
| 341 | + return false; |
|---|
| 342 | +} |
|---|
| 343 | +EXPORT_SYMBOL_GPL(pci_pri_supported); |
|---|
| 256 | 344 | #endif /* CONFIG_PCI_PRI */ |
|---|
| 257 | 345 | |
|---|
| 258 | 346 | #ifdef CONFIG_PCI_PASID |
|---|
| 347 | +void pci_pasid_init(struct pci_dev *pdev) |
|---|
| 348 | +{ |
|---|
| 349 | + pdev->pasid_cap = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID); |
|---|
| 350 | +} |
|---|
| 351 | + |
|---|
| 259 | 352 | /** |
|---|
| 260 | 353 | * pci_enable_pasid - Enable the PASID capability |
|---|
| 261 | 354 | * @pdev: PCI device structure |
|---|
| .. | .. |
|---|
| 268 | 361 | int pci_enable_pasid(struct pci_dev *pdev, int features) |
|---|
| 269 | 362 | { |
|---|
| 270 | 363 | u16 control, supported; |
|---|
| 271 | | - int pos; |
|---|
| 364 | + int pasid = pdev->pasid_cap; |
|---|
| 365 | + |
|---|
| 366 | + /* |
|---|
| 367 | + * VFs must not implement the PASID Capability, but if a PF |
|---|
| 368 | + * supports PASID, its VFs share the PF PASID configuration. |
|---|
| 369 | + */ |
|---|
| 370 | + if (pdev->is_virtfn) { |
|---|
| 371 | + if (pci_physfn(pdev)->pasid_enabled) |
|---|
| 372 | + return 0; |
|---|
| 373 | + return -EINVAL; |
|---|
| 374 | + } |
|---|
| 272 | 375 | |
|---|
| 273 | 376 | if (WARN_ON(pdev->pasid_enabled)) |
|---|
| 274 | 377 | return -EBUSY; |
|---|
| .. | .. |
|---|
| 276 | 379 | if (!pdev->eetlp_prefix_path) |
|---|
| 277 | 380 | return -EINVAL; |
|---|
| 278 | 381 | |
|---|
| 279 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID); |
|---|
| 280 | | - if (!pos) |
|---|
| 382 | + if (!pasid) |
|---|
| 281 | 383 | return -EINVAL; |
|---|
| 282 | 384 | |
|---|
| 283 | | - pci_read_config_word(pdev, pos + PCI_PASID_CAP, &supported); |
|---|
| 385 | + pci_read_config_word(pdev, pasid + PCI_PASID_CAP, &supported); |
|---|
| 284 | 386 | supported &= PCI_PASID_CAP_EXEC | PCI_PASID_CAP_PRIV; |
|---|
| 285 | 387 | |
|---|
| 286 | 388 | /* User wants to enable anything unsupported? */ |
|---|
| .. | .. |
|---|
| 290 | 392 | control = PCI_PASID_CTRL_ENABLE | features; |
|---|
| 291 | 393 | pdev->pasid_features = features; |
|---|
| 292 | 394 | |
|---|
| 293 | | - pci_write_config_word(pdev, pos + PCI_PASID_CTRL, control); |
|---|
| 395 | + pci_write_config_word(pdev, pasid + PCI_PASID_CTRL, control); |
|---|
| 294 | 396 | |
|---|
| 295 | 397 | pdev->pasid_enabled = 1; |
|---|
| 296 | 398 | |
|---|
| .. | .. |
|---|
| 305 | 407 | void pci_disable_pasid(struct pci_dev *pdev) |
|---|
| 306 | 408 | { |
|---|
| 307 | 409 | u16 control = 0; |
|---|
| 308 | | - int pos; |
|---|
| 410 | + int pasid = pdev->pasid_cap; |
|---|
| 411 | + |
|---|
| 412 | + /* VFs share the PF PASID configuration */ |
|---|
| 413 | + if (pdev->is_virtfn) |
|---|
| 414 | + return; |
|---|
| 309 | 415 | |
|---|
| 310 | 416 | if (WARN_ON(!pdev->pasid_enabled)) |
|---|
| 311 | 417 | return; |
|---|
| 312 | 418 | |
|---|
| 313 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID); |
|---|
| 314 | | - if (!pos) |
|---|
| 419 | + if (!pasid) |
|---|
| 315 | 420 | return; |
|---|
| 316 | 421 | |
|---|
| 317 | | - pci_write_config_word(pdev, pos + PCI_PASID_CTRL, control); |
|---|
| 422 | + pci_write_config_word(pdev, pasid + PCI_PASID_CTRL, control); |
|---|
| 318 | 423 | |
|---|
| 319 | 424 | pdev->pasid_enabled = 0; |
|---|
| 320 | 425 | } |
|---|
| .. | .. |
|---|
| 327 | 432 | void pci_restore_pasid_state(struct pci_dev *pdev) |
|---|
| 328 | 433 | { |
|---|
| 329 | 434 | u16 control; |
|---|
| 330 | | - int pos; |
|---|
| 435 | + int pasid = pdev->pasid_cap; |
|---|
| 436 | + |
|---|
| 437 | + if (pdev->is_virtfn) |
|---|
| 438 | + return; |
|---|
| 331 | 439 | |
|---|
| 332 | 440 | if (!pdev->pasid_enabled) |
|---|
| 333 | 441 | return; |
|---|
| 334 | 442 | |
|---|
| 335 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID); |
|---|
| 336 | | - if (!pos) |
|---|
| 443 | + if (!pasid) |
|---|
| 337 | 444 | return; |
|---|
| 338 | 445 | |
|---|
| 339 | 446 | control = PCI_PASID_CTRL_ENABLE | pdev->pasid_features; |
|---|
| 340 | | - pci_write_config_word(pdev, pos + PCI_PASID_CTRL, control); |
|---|
| 447 | + pci_write_config_word(pdev, pasid + PCI_PASID_CTRL, control); |
|---|
| 341 | 448 | } |
|---|
| 342 | | -EXPORT_SYMBOL_GPL(pci_restore_pasid_state); |
|---|
| 343 | 449 | |
|---|
| 344 | 450 | /** |
|---|
| 345 | 451 | * pci_pasid_features - Check which PASID features are supported |
|---|
| .. | .. |
|---|
| 354 | 460 | int pci_pasid_features(struct pci_dev *pdev) |
|---|
| 355 | 461 | { |
|---|
| 356 | 462 | u16 supported; |
|---|
| 357 | | - int pos; |
|---|
| 463 | + int pasid; |
|---|
| 358 | 464 | |
|---|
| 359 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID); |
|---|
| 360 | | - if (!pos) |
|---|
| 465 | + if (pdev->is_virtfn) |
|---|
| 466 | + pdev = pci_physfn(pdev); |
|---|
| 467 | + |
|---|
| 468 | + pasid = pdev->pasid_cap; |
|---|
| 469 | + if (!pasid) |
|---|
| 361 | 470 | return -EINVAL; |
|---|
| 362 | 471 | |
|---|
| 363 | | - pci_read_config_word(pdev, pos + PCI_PASID_CAP, &supported); |
|---|
| 472 | + pci_read_config_word(pdev, pasid + PCI_PASID_CAP, &supported); |
|---|
| 364 | 473 | |
|---|
| 365 | 474 | supported &= PCI_PASID_CAP_EXEC | PCI_PASID_CAP_PRIV; |
|---|
| 366 | 475 | |
|---|
| .. | .. |
|---|
| 375 | 484 | * @pdev: PCI device structure |
|---|
| 376 | 485 | * |
|---|
| 377 | 486 | * Returns negative value when PASID capability is not present. |
|---|
| 378 | | - * Otherwise it returns the numer of supported PASIDs. |
|---|
| 487 | + * Otherwise it returns the number of supported PASIDs. |
|---|
| 379 | 488 | */ |
|---|
| 380 | 489 | int pci_max_pasids(struct pci_dev *pdev) |
|---|
| 381 | 490 | { |
|---|
| 382 | 491 | u16 supported; |
|---|
| 383 | | - int pos; |
|---|
| 492 | + int pasid; |
|---|
| 384 | 493 | |
|---|
| 385 | | - pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PASID); |
|---|
| 386 | | - if (!pos) |
|---|
| 494 | + if (pdev->is_virtfn) |
|---|
| 495 | + pdev = pci_physfn(pdev); |
|---|
| 496 | + |
|---|
| 497 | + pasid = pdev->pasid_cap; |
|---|
| 498 | + if (!pasid) |
|---|
| 387 | 499 | return -EINVAL; |
|---|
| 388 | 500 | |
|---|
| 389 | | - pci_read_config_word(pdev, pos + PCI_PASID_CAP, &supported); |
|---|
| 501 | + pci_read_config_word(pdev, pasid + PCI_PASID_CAP, &supported); |
|---|
| 390 | 502 | |
|---|
| 391 | 503 | supported = (supported & PASID_NUMBER_MASK) >> PASID_NUMBER_SHIFT; |
|---|
| 392 | 504 | |
|---|