/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to driver/compat.c

  • Committer: Suren A. Chilingaryan
  • Date: 2015-11-19 02:19:51 UTC
  • Revision ID: csa@suren.me-20151119021951-00bae7ma1vqy561h
Support setting payload size

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <linux/pci.h>
 
2
 
 
3
int pcidriver_pcie_get_mps(struct pci_dev *dev)
 
4
{
 
5
        u16 ctl;
 
6
 
 
7
        pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
 
8
 
 
9
        return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
 
10
}
 
11
 
 
12
int pcidriver_pcie_set_mps(struct pci_dev *dev, int mps)
 
13
{
 
14
        u16 v;
 
15
 
 
16
        if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
 
17
                return -EINVAL;
 
18
 
 
19
        v = ffs(mps) - 8;
 
20
        if (v > dev->pcie_mpss)
 
21
                return -EINVAL;
 
22
        v <<= 5;
 
23
 
 
24
        return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
 
25
                                                  PCI_EXP_DEVCTL_PAYLOAD, v);
 
26
}