diff options
author | Michael Ellerman <mpe@ellerman.id.au> | 2015-04-13 19:29:23 -0400 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2015-04-13 19:29:23 -0400 |
commit | ad30cb9946515f72af5c3e89ad9de18870c1a1e7 (patch) | |
tree | b4c9b385e18ae8128da1522055a17b453f2309fc /drivers/pci | |
parent | b0a478ede669949682b9c698f6146c0065543b91 (diff) | |
parent | d4ed11aa4881246e1e36e0189f30f053f140370c (diff) |
Merge branch 'next-sriov' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc into next
Merge Richard's work to support SR-IOV on PowerNV. All generic PCI
patches acked by Bjorn.
Some minor conflicts with Daniel's pci_controller_ops work.
Conflicts:
arch/powerpc/include/asm/machdep.h
arch/powerpc/platforms/powernv/pci-ioda.c
Diffstat (limited to 'drivers/pci')
-rw-r--r-- | drivers/pci/iov.c | 155 | ||||
-rw-r--r-- | drivers/pci/pci.h | 2 | ||||
-rw-r--r-- | drivers/pci/setup-bus.c | 95 |
3 files changed, 195 insertions, 57 deletions
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 4b3a4eaad996..ee0ebff103a4 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c | |||
@@ -19,16 +19,59 @@ | |||
19 | 19 | ||
20 | #define VIRTFN_ID_LEN 16 | 20 | #define VIRTFN_ID_LEN 16 |
21 | 21 | ||
22 | static inline u8 virtfn_bus(struct pci_dev *dev, int id) | 22 | int pci_iov_virtfn_bus(struct pci_dev *dev, int vf_id) |
23 | { | 23 | { |
24 | if (!dev->is_physfn) | ||
25 | return -EINVAL; | ||
24 | return dev->bus->number + ((dev->devfn + dev->sriov->offset + | 26 | return dev->bus->number + ((dev->devfn + dev->sriov->offset + |
25 | dev->sriov->stride * id) >> 8); | 27 | dev->sriov->stride * vf_id) >> 8); |
26 | } | 28 | } |
27 | 29 | ||
28 | static inline u8 virtfn_devfn(struct pci_dev *dev, int id) | 30 | int pci_iov_virtfn_devfn(struct pci_dev *dev, int vf_id) |
29 | { | 31 | { |
32 | if (!dev->is_physfn) | ||
33 | return -EINVAL; | ||
30 | return (dev->devfn + dev->sriov->offset + | 34 | return (dev->devfn + dev->sriov->offset + |
31 | dev->sriov->stride * id) & 0xff; | 35 | dev->sriov->stride * vf_id) & 0xff; |
36 | } | ||
37 | |||
38 | /* | ||
39 | * Per SR-IOV spec sec 3.3.10 and 3.3.11, First VF Offset and VF Stride may | ||
40 | * change when NumVFs changes. | ||
41 | * | ||
42 | * Update iov->offset and iov->stride when NumVFs is written. | ||
43 | */ | ||
44 | static inline void pci_iov_set_numvfs(struct pci_dev *dev, int nr_virtfn) | ||
45 | { | ||
46 | struct pci_sriov *iov = dev->sriov; | ||
47 | |||
48 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, nr_virtfn); | ||
49 | pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_OFFSET, &iov->offset); | ||
50 | pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_STRIDE, &iov->stride); | ||
51 | } | ||
52 | |||
53 | /* | ||
54 | * The PF consumes one bus number. NumVFs, First VF Offset, and VF Stride | ||
55 | * determine how many additional bus numbers will be consumed by VFs. | ||
56 | * | ||
57 | * Iterate over all valid NumVFs and calculate the maximum number of bus | ||
58 | * numbers that could ever be required. | ||
59 | */ | ||
60 | static inline u8 virtfn_max_buses(struct pci_dev *dev) | ||
61 | { | ||
62 | struct pci_sriov *iov = dev->sriov; | ||
63 | int nr_virtfn; | ||
64 | u8 max = 0; | ||
65 | int busnr; | ||
66 | |||
67 | for (nr_virtfn = 1; nr_virtfn <= iov->total_VFs; nr_virtfn++) { | ||
68 | pci_iov_set_numvfs(dev, nr_virtfn); | ||
69 | busnr = pci_iov_virtfn_bus(dev, nr_virtfn - 1); | ||
70 | if (busnr > max) | ||
71 | max = busnr; | ||
72 | } | ||
73 | |||
74 | return max; | ||
32 | } | 75 | } |
33 | 76 | ||
34 | static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr) | 77 | static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr) |
@@ -57,6 +100,14 @@ static void virtfn_remove_bus(struct pci_bus *physbus, struct pci_bus *virtbus) | |||
57 | pci_remove_bus(virtbus); | 100 | pci_remove_bus(virtbus); |
58 | } | 101 | } |
59 | 102 | ||
103 | resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno) | ||
104 | { | ||
105 | if (!dev->is_physfn) | ||
106 | return 0; | ||
107 | |||
108 | return dev->sriov->barsz[resno - PCI_IOV_RESOURCES]; | ||
109 | } | ||
110 | |||
60 | static int virtfn_add(struct pci_dev *dev, int id, int reset) | 111 | static int virtfn_add(struct pci_dev *dev, int id, int reset) |
61 | { | 112 | { |
62 | int i; | 113 | int i; |
@@ -69,7 +120,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset) | |||
69 | struct pci_bus *bus; | 120 | struct pci_bus *bus; |
70 | 121 | ||
71 | mutex_lock(&iov->dev->sriov->lock); | 122 | mutex_lock(&iov->dev->sriov->lock); |
72 | bus = virtfn_add_bus(dev->bus, virtfn_bus(dev, id)); | 123 | bus = virtfn_add_bus(dev->bus, pci_iov_virtfn_bus(dev, id)); |
73 | if (!bus) | 124 | if (!bus) |
74 | goto failed; | 125 | goto failed; |
75 | 126 | ||
@@ -77,7 +128,7 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset) | |||
77 | if (!virtfn) | 128 | if (!virtfn) |
78 | goto failed0; | 129 | goto failed0; |
79 | 130 | ||
80 | virtfn->devfn = virtfn_devfn(dev, id); | 131 | virtfn->devfn = pci_iov_virtfn_devfn(dev, id); |
81 | virtfn->vendor = dev->vendor; | 132 | virtfn->vendor = dev->vendor; |
82 | pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device); | 133 | pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device); |
83 | pci_setup_device(virtfn); | 134 | pci_setup_device(virtfn); |
@@ -87,13 +138,12 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset) | |||
87 | virtfn->multifunction = 0; | 138 | virtfn->multifunction = 0; |
88 | 139 | ||
89 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { | 140 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { |
90 | res = dev->resource + PCI_IOV_RESOURCES + i; | 141 | res = &dev->resource[i + PCI_IOV_RESOURCES]; |
91 | if (!res->parent) | 142 | if (!res->parent) |
92 | continue; | 143 | continue; |
93 | virtfn->resource[i].name = pci_name(virtfn); | 144 | virtfn->resource[i].name = pci_name(virtfn); |
94 | virtfn->resource[i].flags = res->flags; | 145 | virtfn->resource[i].flags = res->flags; |
95 | size = resource_size(res); | 146 | size = pci_iov_resource_size(dev, i + PCI_IOV_RESOURCES); |
96 | do_div(size, iov->total_VFs); | ||
97 | virtfn->resource[i].start = res->start + size * id; | 147 | virtfn->resource[i].start = res->start + size * id; |
98 | virtfn->resource[i].end = virtfn->resource[i].start + size - 1; | 148 | virtfn->resource[i].end = virtfn->resource[i].start + size - 1; |
99 | rc = request_resource(res, &virtfn->resource[i]); | 149 | rc = request_resource(res, &virtfn->resource[i]); |
@@ -140,8 +190,8 @@ static void virtfn_remove(struct pci_dev *dev, int id, int reset) | |||
140 | struct pci_sriov *iov = dev->sriov; | 190 | struct pci_sriov *iov = dev->sriov; |
141 | 191 | ||
142 | virtfn = pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), | 192 | virtfn = pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), |
143 | virtfn_bus(dev, id), | 193 | pci_iov_virtfn_bus(dev, id), |
144 | virtfn_devfn(dev, id)); | 194 | pci_iov_virtfn_devfn(dev, id)); |
145 | if (!virtfn) | 195 | if (!virtfn) |
146 | return; | 196 | return; |
147 | 197 | ||
@@ -170,6 +220,11 @@ static void virtfn_remove(struct pci_dev *dev, int id, int reset) | |||
170 | pci_dev_put(dev); | 220 | pci_dev_put(dev); |
171 | } | 221 | } |
172 | 222 | ||
223 | int __weak pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs) | ||
224 | { | ||
225 | return 0; | ||
226 | } | ||
227 | |||
173 | static int sriov_enable(struct pci_dev *dev, int nr_virtfn) | 228 | static int sriov_enable(struct pci_dev *dev, int nr_virtfn) |
174 | { | 229 | { |
175 | int rc; | 230 | int rc; |
@@ -180,6 +235,8 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) | |||
180 | struct pci_dev *pdev; | 235 | struct pci_dev *pdev; |
181 | struct pci_sriov *iov = dev->sriov; | 236 | struct pci_sriov *iov = dev->sriov; |
182 | int bars = 0; | 237 | int bars = 0; |
238 | int bus; | ||
239 | int retval; | ||
183 | 240 | ||
184 | if (!nr_virtfn) | 241 | if (!nr_virtfn) |
185 | return 0; | 242 | return 0; |
@@ -204,7 +261,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) | |||
204 | nres = 0; | 261 | nres = 0; |
205 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { | 262 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { |
206 | bars |= (1 << (i + PCI_IOV_RESOURCES)); | 263 | bars |= (1 << (i + PCI_IOV_RESOURCES)); |
207 | res = dev->resource + PCI_IOV_RESOURCES + i; | 264 | res = &dev->resource[i + PCI_IOV_RESOURCES]; |
208 | if (res->parent) | 265 | if (res->parent) |
209 | nres++; | 266 | nres++; |
210 | } | 267 | } |
@@ -216,8 +273,10 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) | |||
216 | iov->offset = offset; | 273 | iov->offset = offset; |
217 | iov->stride = stride; | 274 | iov->stride = stride; |
218 | 275 | ||
219 | if (virtfn_bus(dev, nr_virtfn - 1) > dev->bus->busn_res.end) { | 276 | bus = pci_iov_virtfn_bus(dev, nr_virtfn - 1); |
220 | dev_err(&dev->dev, "SR-IOV: bus number out of range\n"); | 277 | if (bus > dev->bus->busn_res.end) { |
278 | dev_err(&dev->dev, "can't enable %d VFs (bus %02x out of range of %pR)\n", | ||
279 | nr_virtfn, bus, &dev->bus->busn_res); | ||
221 | return -ENOMEM; | 280 | return -ENOMEM; |
222 | } | 281 | } |
223 | 282 | ||
@@ -243,7 +302,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) | |||
243 | return rc; | 302 | return rc; |
244 | } | 303 | } |
245 | 304 | ||
246 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, nr_virtfn); | 305 | pci_iov_set_numvfs(dev, nr_virtfn); |
247 | iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE; | 306 | iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE; |
248 | pci_cfg_access_lock(dev); | 307 | pci_cfg_access_lock(dev); |
249 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); | 308 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); |
@@ -254,6 +313,12 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn) | |||
254 | if (nr_virtfn < initial) | 313 | if (nr_virtfn < initial) |
255 | initial = nr_virtfn; | 314 | initial = nr_virtfn; |
256 | 315 | ||
316 | if ((retval = pcibios_sriov_enable(dev, initial))) { | ||
317 | dev_err(&dev->dev, "failure %d from pcibios_sriov_enable()\n", | ||
318 | retval); | ||
319 | return retval; | ||
320 | } | ||
321 | |||
257 | for (i = 0; i < initial; i++) { | 322 | for (i = 0; i < initial; i++) { |
258 | rc = virtfn_add(dev, i, 0); | 323 | rc = virtfn_add(dev, i, 0); |
259 | if (rc) | 324 | if (rc) |
@@ -272,7 +337,7 @@ failed: | |||
272 | iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); | 337 | iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); |
273 | pci_cfg_access_lock(dev); | 338 | pci_cfg_access_lock(dev); |
274 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); | 339 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); |
275 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, 0); | 340 | pci_iov_set_numvfs(dev, 0); |
276 | ssleep(1); | 341 | ssleep(1); |
277 | pci_cfg_access_unlock(dev); | 342 | pci_cfg_access_unlock(dev); |
278 | 343 | ||
@@ -282,6 +347,11 @@ failed: | |||
282 | return rc; | 347 | return rc; |
283 | } | 348 | } |
284 | 349 | ||
350 | int __weak pcibios_sriov_disable(struct pci_dev *pdev) | ||
351 | { | ||
352 | return 0; | ||
353 | } | ||
354 | |||
285 | static void sriov_disable(struct pci_dev *dev) | 355 | static void sriov_disable(struct pci_dev *dev) |
286 | { | 356 | { |
287 | int i; | 357 | int i; |
@@ -293,6 +363,8 @@ static void sriov_disable(struct pci_dev *dev) | |||
293 | for (i = 0; i < iov->num_VFs; i++) | 363 | for (i = 0; i < iov->num_VFs; i++) |
294 | virtfn_remove(dev, i, 0); | 364 | virtfn_remove(dev, i, 0); |
295 | 365 | ||
366 | pcibios_sriov_disable(dev); | ||
367 | |||
296 | iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); | 368 | iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); |
297 | pci_cfg_access_lock(dev); | 369 | pci_cfg_access_lock(dev); |
298 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); | 370 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); |
@@ -303,12 +375,12 @@ static void sriov_disable(struct pci_dev *dev) | |||
303 | sysfs_remove_link(&dev->dev.kobj, "dep_link"); | 375 | sysfs_remove_link(&dev->dev.kobj, "dep_link"); |
304 | 376 | ||
305 | iov->num_VFs = 0; | 377 | iov->num_VFs = 0; |
306 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, 0); | 378 | pci_iov_set_numvfs(dev, 0); |
307 | } | 379 | } |
308 | 380 | ||
309 | static int sriov_init(struct pci_dev *dev, int pos) | 381 | static int sriov_init(struct pci_dev *dev, int pos) |
310 | { | 382 | { |
311 | int i; | 383 | int i, bar64; |
312 | int rc; | 384 | int rc; |
313 | int nres; | 385 | int nres; |
314 | u32 pgsz; | 386 | u32 pgsz; |
@@ -357,27 +429,29 @@ found: | |||
357 | pgsz &= ~(pgsz - 1); | 429 | pgsz &= ~(pgsz - 1); |
358 | pci_write_config_dword(dev, pos + PCI_SRIOV_SYS_PGSIZE, pgsz); | 430 | pci_write_config_dword(dev, pos + PCI_SRIOV_SYS_PGSIZE, pgsz); |
359 | 431 | ||
432 | iov = kzalloc(sizeof(*iov), GFP_KERNEL); | ||
433 | if (!iov) | ||
434 | return -ENOMEM; | ||
435 | |||
360 | nres = 0; | 436 | nres = 0; |
361 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { | 437 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { |
362 | res = dev->resource + PCI_IOV_RESOURCES + i; | 438 | res = &dev->resource[i + PCI_IOV_RESOURCES]; |
363 | i += __pci_read_base(dev, pci_bar_unknown, res, | 439 | bar64 = __pci_read_base(dev, pci_bar_unknown, res, |
364 | pos + PCI_SRIOV_BAR + i * 4); | 440 | pos + PCI_SRIOV_BAR + i * 4); |
365 | if (!res->flags) | 441 | if (!res->flags) |
366 | continue; | 442 | continue; |
367 | if (resource_size(res) & (PAGE_SIZE - 1)) { | 443 | if (resource_size(res) & (PAGE_SIZE - 1)) { |
368 | rc = -EIO; | 444 | rc = -EIO; |
369 | goto failed; | 445 | goto failed; |
370 | } | 446 | } |
447 | iov->barsz[i] = resource_size(res); | ||
371 | res->end = res->start + resource_size(res) * total - 1; | 448 | res->end = res->start + resource_size(res) * total - 1; |
449 | dev_info(&dev->dev, "VF(n) BAR%d space: %pR (contains BAR%d for %d VFs)\n", | ||
450 | i, res, i, total); | ||
451 | i += bar64; | ||
372 | nres++; | 452 | nres++; |
373 | } | 453 | } |
374 | 454 | ||
375 | iov = kzalloc(sizeof(*iov), GFP_KERNEL); | ||
376 | if (!iov) { | ||
377 | rc = -ENOMEM; | ||
378 | goto failed; | ||
379 | } | ||
380 | |||
381 | iov->pos = pos; | 455 | iov->pos = pos; |
382 | iov->nres = nres; | 456 | iov->nres = nres; |
383 | iov->ctrl = ctrl; | 457 | iov->ctrl = ctrl; |
@@ -400,15 +474,17 @@ found: | |||
400 | 474 | ||
401 | dev->sriov = iov; | 475 | dev->sriov = iov; |
402 | dev->is_physfn = 1; | 476 | dev->is_physfn = 1; |
477 | iov->max_VF_buses = virtfn_max_buses(dev); | ||
403 | 478 | ||
404 | return 0; | 479 | return 0; |
405 | 480 | ||
406 | failed: | 481 | failed: |
407 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { | 482 | for (i = 0; i < PCI_SRIOV_NUM_BARS; i++) { |
408 | res = dev->resource + PCI_IOV_RESOURCES + i; | 483 | res = &dev->resource[i + PCI_IOV_RESOURCES]; |
409 | res->flags = 0; | 484 | res->flags = 0; |
410 | } | 485 | } |
411 | 486 | ||
487 | kfree(iov); | ||
412 | return rc; | 488 | return rc; |
413 | } | 489 | } |
414 | 490 | ||
@@ -439,7 +515,7 @@ static void sriov_restore_state(struct pci_dev *dev) | |||
439 | pci_update_resource(dev, i); | 515 | pci_update_resource(dev, i); |
440 | 516 | ||
441 | pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); | 517 | pci_write_config_dword(dev, iov->pos + PCI_SRIOV_SYS_PGSIZE, iov->pgsz); |
442 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, iov->num_VFs); | 518 | pci_iov_set_numvfs(dev, iov->num_VFs); |
443 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); | 519 | pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); |
444 | if (iov->ctrl & PCI_SRIOV_CTRL_VFE) | 520 | if (iov->ctrl & PCI_SRIOV_CTRL_VFE) |
445 | msleep(100); | 521 | msleep(100); |
@@ -493,6 +569,12 @@ int pci_iov_resource_bar(struct pci_dev *dev, int resno) | |||
493 | 4 * (resno - PCI_IOV_RESOURCES); | 569 | 4 * (resno - PCI_IOV_RESOURCES); |
494 | } | 570 | } |
495 | 571 | ||
572 | resource_size_t __weak pcibios_iov_resource_alignment(struct pci_dev *dev, | ||
573 | int resno) | ||
574 | { | ||
575 | return pci_iov_resource_size(dev, resno); | ||
576 | } | ||
577 | |||
496 | /** | 578 | /** |
497 | * pci_sriov_resource_alignment - get resource alignment for VF BAR | 579 | * pci_sriov_resource_alignment - get resource alignment for VF BAR |
498 | * @dev: the PCI device | 580 | * @dev: the PCI device |
@@ -505,14 +587,7 @@ int pci_iov_resource_bar(struct pci_dev *dev, int resno) | |||
505 | */ | 587 | */ |
506 | resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno) | 588 | resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno) |
507 | { | 589 | { |
508 | struct resource tmp; | 590 | return pcibios_iov_resource_alignment(dev, resno); |
509 | int reg = pci_iov_resource_bar(dev, resno); | ||
510 | |||
511 | if (!reg) | ||
512 | return 0; | ||
513 | |||
514 | __pci_read_base(dev, pci_bar_unknown, &tmp, reg); | ||
515 | return resource_alignment(&tmp); | ||
516 | } | 591 | } |
517 | 592 | ||
518 | /** | 593 | /** |
@@ -535,15 +610,13 @@ void pci_restore_iov_state(struct pci_dev *dev) | |||
535 | int pci_iov_bus_range(struct pci_bus *bus) | 610 | int pci_iov_bus_range(struct pci_bus *bus) |
536 | { | 611 | { |
537 | int max = 0; | 612 | int max = 0; |
538 | u8 busnr; | ||
539 | struct pci_dev *dev; | 613 | struct pci_dev *dev; |
540 | 614 | ||
541 | list_for_each_entry(dev, &bus->devices, bus_list) { | 615 | list_for_each_entry(dev, &bus->devices, bus_list) { |
542 | if (!dev->is_physfn) | 616 | if (!dev->is_physfn) |
543 | continue; | 617 | continue; |
544 | busnr = virtfn_bus(dev, dev->sriov->total_VFs - 1); | 618 | if (dev->sriov->max_VF_buses > max) |
545 | if (busnr > max) | 619 | max = dev->sriov->max_VF_buses; |
546 | max = busnr; | ||
547 | } | 620 | } |
548 | 621 | ||
549 | return max ? max - bus->number : 0; | 622 | return max ? max - bus->number : 0; |
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index 4091f82239cd..bae593c04541 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h | |||
@@ -243,10 +243,12 @@ struct pci_sriov { | |||
243 | u16 stride; /* following VF stride */ | 243 | u16 stride; /* following VF stride */ |
244 | u32 pgsz; /* page size for BAR alignment */ | 244 | u32 pgsz; /* page size for BAR alignment */ |
245 | u8 link; /* Function Dependency Link */ | 245 | u8 link; /* Function Dependency Link */ |
246 | u8 max_VF_buses; /* max buses consumed by VFs */ | ||
246 | u16 driver_max_VFs; /* max num VFs driver supports */ | 247 | u16 driver_max_VFs; /* max num VFs driver supports */ |
247 | struct pci_dev *dev; /* lowest numbered PF */ | 248 | struct pci_dev *dev; /* lowest numbered PF */ |
248 | struct pci_dev *self; /* this PF */ | 249 | struct pci_dev *self; /* this PF */ |
249 | struct mutex lock; /* lock for VF bus */ | 250 | struct mutex lock; /* lock for VF bus */ |
251 | resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ | ||
250 | }; | 252 | }; |
251 | 253 | ||
252 | #ifdef CONFIG_PCI_ATS | 254 | #ifdef CONFIG_PCI_ATS |
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index e3e17f3c0f0f..6603d401bb7c 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
@@ -99,8 +99,8 @@ static void remove_from_list(struct list_head *head, | |||
99 | } | 99 | } |
100 | } | 100 | } |
101 | 101 | ||
102 | static resource_size_t get_res_add_size(struct list_head *head, | 102 | static struct pci_dev_resource *res_to_dev_res(struct list_head *head, |
103 | struct resource *res) | 103 | struct resource *res) |
104 | { | 104 | { |
105 | struct pci_dev_resource *dev_res; | 105 | struct pci_dev_resource *dev_res; |
106 | 106 | ||
@@ -109,17 +109,37 @@ static resource_size_t get_res_add_size(struct list_head *head, | |||
109 | int idx = res - &dev_res->dev->resource[0]; | 109 | int idx = res - &dev_res->dev->resource[0]; |
110 | 110 | ||
111 | dev_printk(KERN_DEBUG, &dev_res->dev->dev, | 111 | dev_printk(KERN_DEBUG, &dev_res->dev->dev, |
112 | "res[%d]=%pR get_res_add_size add_size %llx\n", | 112 | "res[%d]=%pR res_to_dev_res add_size %llx min_align %llx\n", |
113 | idx, dev_res->res, | 113 | idx, dev_res->res, |
114 | (unsigned long long)dev_res->add_size); | 114 | (unsigned long long)dev_res->add_size, |
115 | (unsigned long long)dev_res->min_align); | ||
115 | 116 | ||
116 | return dev_res->add_size; | 117 | return dev_res; |
117 | } | 118 | } |
118 | } | 119 | } |
119 | 120 | ||
120 | return 0; | 121 | return NULL; |
121 | } | 122 | } |
122 | 123 | ||
124 | static resource_size_t get_res_add_size(struct list_head *head, | ||
125 | struct resource *res) | ||
126 | { | ||
127 | struct pci_dev_resource *dev_res; | ||
128 | |||
129 | dev_res = res_to_dev_res(head, res); | ||
130 | return dev_res ? dev_res->add_size : 0; | ||
131 | } | ||
132 | |||
133 | static resource_size_t get_res_add_align(struct list_head *head, | ||
134 | struct resource *res) | ||
135 | { | ||
136 | struct pci_dev_resource *dev_res; | ||
137 | |||
138 | dev_res = res_to_dev_res(head, res); | ||
139 | return dev_res ? dev_res->min_align : 0; | ||
140 | } | ||
141 | |||
142 | |||
123 | /* Sort resources by alignment */ | 143 | /* Sort resources by alignment */ |
124 | static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) | 144 | static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) |
125 | { | 145 | { |
@@ -215,7 +235,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head, | |||
215 | struct resource *res; | 235 | struct resource *res; |
216 | struct pci_dev_resource *add_res, *tmp; | 236 | struct pci_dev_resource *add_res, *tmp; |
217 | struct pci_dev_resource *dev_res; | 237 | struct pci_dev_resource *dev_res; |
218 | resource_size_t add_size; | 238 | resource_size_t add_size, align; |
219 | int idx; | 239 | int idx; |
220 | 240 | ||
221 | list_for_each_entry_safe(add_res, tmp, realloc_head, list) { | 241 | list_for_each_entry_safe(add_res, tmp, realloc_head, list) { |
@@ -238,13 +258,13 @@ static void reassign_resources_sorted(struct list_head *realloc_head, | |||
238 | 258 | ||
239 | idx = res - &add_res->dev->resource[0]; | 259 | idx = res - &add_res->dev->resource[0]; |
240 | add_size = add_res->add_size; | 260 | add_size = add_res->add_size; |
261 | align = add_res->min_align; | ||
241 | if (!resource_size(res)) { | 262 | if (!resource_size(res)) { |
242 | res->start = add_res->start; | 263 | res->start = align; |
243 | res->end = res->start + add_size - 1; | 264 | res->end = res->start + add_size - 1; |
244 | if (pci_assign_resource(add_res->dev, idx)) | 265 | if (pci_assign_resource(add_res->dev, idx)) |
245 | reset_resource(res); | 266 | reset_resource(res); |
246 | } else { | 267 | } else { |
247 | resource_size_t align = add_res->min_align; | ||
248 | res->flags |= add_res->flags & | 268 | res->flags |= add_res->flags & |
249 | (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN); | 269 | (IORESOURCE_STARTALIGN|IORESOURCE_SIZEALIGN); |
250 | if (pci_reassign_resource(add_res->dev, idx, | 270 | if (pci_reassign_resource(add_res->dev, idx, |
@@ -368,8 +388,9 @@ static void __assign_resources_sorted(struct list_head *head, | |||
368 | LIST_HEAD(save_head); | 388 | LIST_HEAD(save_head); |
369 | LIST_HEAD(local_fail_head); | 389 | LIST_HEAD(local_fail_head); |
370 | struct pci_dev_resource *save_res; | 390 | struct pci_dev_resource *save_res; |
371 | struct pci_dev_resource *dev_res, *tmp_res; | 391 | struct pci_dev_resource *dev_res, *tmp_res, *dev_res2; |
372 | unsigned long fail_type; | 392 | unsigned long fail_type; |
393 | resource_size_t add_align, align; | ||
373 | 394 | ||
374 | /* Check if optional add_size is there */ | 395 | /* Check if optional add_size is there */ |
375 | if (!realloc_head || list_empty(realloc_head)) | 396 | if (!realloc_head || list_empty(realloc_head)) |
@@ -384,10 +405,44 @@ static void __assign_resources_sorted(struct list_head *head, | |||
384 | } | 405 | } |
385 | 406 | ||
386 | /* Update res in head list with add_size in realloc_head list */ | 407 | /* Update res in head list with add_size in realloc_head list */ |
387 | list_for_each_entry(dev_res, head, list) | 408 | list_for_each_entry_safe(dev_res, tmp_res, head, list) { |
388 | dev_res->res->end += get_res_add_size(realloc_head, | 409 | dev_res->res->end += get_res_add_size(realloc_head, |
389 | dev_res->res); | 410 | dev_res->res); |
390 | 411 | ||
412 | /* | ||
413 | * There are two kinds of additional resources in the list: | ||
414 | * 1. bridge resource -- IORESOURCE_STARTALIGN | ||
415 | * 2. SR-IOV resource -- IORESOURCE_SIZEALIGN | ||
416 | * Here just fix the additional alignment for bridge | ||
417 | */ | ||
418 | if (!(dev_res->res->flags & IORESOURCE_STARTALIGN)) | ||
419 | continue; | ||
420 | |||
421 | add_align = get_res_add_align(realloc_head, dev_res->res); | ||
422 | |||
423 | /* | ||
424 | * The "head" list is sorted by the alignment to make sure | ||
425 | * resources with bigger alignment will be assigned first. | ||
426 | * After we change the alignment of a dev_res in "head" list, | ||
427 | * we need to reorder the list by alignment to make it | ||
428 | * consistent. | ||
429 | */ | ||
430 | if (add_align > dev_res->res->start) { | ||
431 | dev_res->res->start = add_align; | ||
432 | dev_res->res->end = add_align + | ||
433 | resource_size(dev_res->res); | ||
434 | |||
435 | list_for_each_entry(dev_res2, head, list) { | ||
436 | align = pci_resource_alignment(dev_res2->dev, | ||
437 | dev_res2->res); | ||
438 | if (add_align > align) | ||
439 | list_move_tail(&dev_res->list, | ||
440 | &dev_res2->list); | ||
441 | } | ||
442 | } | ||
443 | |||
444 | } | ||
445 | |||
391 | /* Try updated head list with add_size added */ | 446 | /* Try updated head list with add_size added */ |
392 | assign_requested_resources_sorted(head, &local_fail_head); | 447 | assign_requested_resources_sorted(head, &local_fail_head); |
393 | 448 | ||
@@ -962,6 +1017,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, | |||
962 | struct resource *b_res = find_free_bus_resource(bus, | 1017 | struct resource *b_res = find_free_bus_resource(bus, |
963 | mask | IORESOURCE_PREFETCH, type); | 1018 | mask | IORESOURCE_PREFETCH, type); |
964 | resource_size_t children_add_size = 0; | 1019 | resource_size_t children_add_size = 0; |
1020 | resource_size_t children_add_align = 0; | ||
1021 | resource_size_t add_align = 0; | ||
965 | 1022 | ||
966 | if (!b_res) | 1023 | if (!b_res) |
967 | return -ENOSPC; | 1024 | return -ENOSPC; |
@@ -986,6 +1043,7 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, | |||
986 | /* put SRIOV requested res to the optional list */ | 1043 | /* put SRIOV requested res to the optional list */ |
987 | if (realloc_head && i >= PCI_IOV_RESOURCES && | 1044 | if (realloc_head && i >= PCI_IOV_RESOURCES && |
988 | i <= PCI_IOV_RESOURCE_END) { | 1045 | i <= PCI_IOV_RESOURCE_END) { |
1046 | add_align = max(pci_resource_alignment(dev, r), add_align); | ||
989 | r->end = r->start - 1; | 1047 | r->end = r->start - 1; |
990 | add_to_list(realloc_head, dev, r, r_size, 0/* don't care */); | 1048 | add_to_list(realloc_head, dev, r, r_size, 0/* don't care */); |
991 | children_add_size += r_size; | 1049 | children_add_size += r_size; |
@@ -1016,19 +1074,23 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, | |||
1016 | if (order > max_order) | 1074 | if (order > max_order) |
1017 | max_order = order; | 1075 | max_order = order; |
1018 | 1076 | ||
1019 | if (realloc_head) | 1077 | if (realloc_head) { |
1020 | children_add_size += get_res_add_size(realloc_head, r); | 1078 | children_add_size += get_res_add_size(realloc_head, r); |
1079 | children_add_align = get_res_add_align(realloc_head, r); | ||
1080 | add_align = max(add_align, children_add_align); | ||
1081 | } | ||
1021 | } | 1082 | } |
1022 | } | 1083 | } |
1023 | 1084 | ||
1024 | min_align = calculate_mem_align(aligns, max_order); | 1085 | min_align = calculate_mem_align(aligns, max_order); |
1025 | min_align = max(min_align, window_alignment(bus, b_res->flags)); | 1086 | min_align = max(min_align, window_alignment(bus, b_res->flags)); |
1026 | size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); | 1087 | size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); |
1088 | add_align = max(min_align, add_align); | ||
1027 | if (children_add_size > add_size) | 1089 | if (children_add_size > add_size) |
1028 | add_size = children_add_size; | 1090 | add_size = children_add_size; |
1029 | size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 : | 1091 | size1 = (!realloc_head || (realloc_head && !add_size)) ? size0 : |
1030 | calculate_memsize(size, min_size, add_size, | 1092 | calculate_memsize(size, min_size, add_size, |
1031 | resource_size(b_res), min_align); | 1093 | resource_size(b_res), add_align); |
1032 | if (!size0 && !size1) { | 1094 | if (!size0 && !size1) { |
1033 | if (b_res->start || b_res->end) | 1095 | if (b_res->start || b_res->end) |
1034 | dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n", | 1096 | dev_info(&bus->self->dev, "disabling bridge window %pR to %pR (unused)\n", |
@@ -1040,10 +1102,11 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, | |||
1040 | b_res->end = size0 + min_align - 1; | 1102 | b_res->end = size0 + min_align - 1; |
1041 | b_res->flags |= IORESOURCE_STARTALIGN; | 1103 | b_res->flags |= IORESOURCE_STARTALIGN; |
1042 | if (size1 > size0 && realloc_head) { | 1104 | if (size1 > size0 && realloc_head) { |
1043 | add_to_list(realloc_head, bus->self, b_res, size1-size0, min_align); | 1105 | add_to_list(realloc_head, bus->self, b_res, size1-size0, add_align); |
1044 | dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window %pR to %pR add_size %llx\n", | 1106 | dev_printk(KERN_DEBUG, &bus->self->dev, "bridge window %pR to %pR add_size %llx add_align %llx\n", |
1045 | b_res, &bus->busn_res, | 1107 | b_res, &bus->busn_res, |
1046 | (unsigned long long)size1-size0); | 1108 | (unsigned long long) (size1 - size0), |
1109 | (unsigned long long) add_align); | ||
1047 | } | 1110 | } |
1048 | return 0; | 1111 | return 0; |
1049 | } | 1112 | } |