14 Jul, 2016

7 commits

  • Add a new API, cxl_check_and_switch_mode() to allow for switching of
    bi-modal CAPI cards, such as the Mellanox CX-4 network card.

    When a driver requests to switch a card to CAPI mode, use PCI hotplug
    infrastructure to remove all PCI devices underneath the slot. We then write
    an updated mode control register to the CAPI VSEC, hot reset the card, and
    reprobe the card.

    As the card may present a different set of PCI devices after the mode
    switch, use the infrastructure provided by the pnv_php driver and the OPAL
    PCI slot management facilities to ensure that:

    * the old devices are removed from both the OPAL and Linux device trees
    * the new devices are probed by OPAL and added to the OPAL device tree
    * the new devices are added to the Linux device tree and probed through
    the regular PCI device probe path

    As such, introduce a new option, CONFIG_CXL_BIMODAL, with a dependency on
    the pnv_php driver.

    Refactor existing code that touches the mode control register in the
    regular single mode case into a new function, setup_cxl_protocol_area().

    Co-authored-by: Ian Munsie
    Cc: Gavin Shan
    Signed-off-by: Andrew Donnellan
    Signed-off-by: Ian Munsie
    Reviewed-by: Gavin Shan
    Signed-off-by: Michael Ellerman

    Andrew Donnellan
     
  • The Mellanox CX4 in cxl mode uses a hybrid interrupt model, where
    interrupts are routed from the networking hardware to the XSL using the
    MSIX table, and from there will be transformed back into an MSIX
    interrupt using the cxl style interrupts (i.e. using IVTE entries and
    ranges to map a PE and AFU interrupt number to an MSIX address).

    We want to hide the implementation details of cxl interrupts as much as
    possible. To this end, we use a special version of the MSI setup &
    teardown routines in the PHB while in cxl mode to allocate the cxl
    interrupts and configure the IVTE entries in the process element.

    This function does not configure the MSIX table - the CX4 card uses a
    custom format in that table and it would not be appropriate to fill that
    out in generic code. The rest of the functionality is similar to the
    "Full MSI-X mode" described in the CAIA, and this could be easily
    extended to support other adapters that use that mode in the future.

    The interrupts will be associated with the default context. If the
    maximum number of interrupts per context has been limited (e.g. by the
    mlx5 driver), it will automatically allocate additional kernel contexts
    to associate extra interrupts as required. These contexts will be
    started using the same WED that was used to start the default context.

    Signed-off-by: Ian Munsie
    Reviewed-by: Andrew Donnellan
    Signed-off-by: Michael Ellerman

    Ian Munsie
     
  • The Mellanox CX4 has a hardware limitation where only 4 bits of the
    AFU interrupt number can be passed to the XSL when sending an interrupt,
    limiting it to only 15 interrupts per context (AFU interrupt number 0 is
    invalid).

    In order to overcome this, we will allocate additional contexts linked
    to the default context as extra address space for the extra interrupts -
    this will be implemented in the next patch.

    This patch adds the preliminary support to allow this, by way of adding
    a linked list in the context structure that we use to keep track of the
    contexts dedicated to interrupts, and an API to simultaneously iterate
    over the related context structures, AFU interrupt numbers and hardware
    interrupt numbers. The point of using a single API to iterate these is
    to hide some of the details of the iteration from external code, and to
    reduce the number of APIs that need to be exported via base.c to allow
    built in code to call.

    Signed-off-by: Ian Munsie
    Reviewed-by: Frederic Barrat
    Reviewed-by: Andrew Donnellan
    Signed-off-by: Michael Ellerman

    Ian Munsie
     
  • These APIs will be used by the Mellanox CX4 support. While they function
    standalone to configure existing behaviour, their primary purpose is to
    allow the Mellanox driver to inform the cxl driver of a hardware
    limitation, which will be used in a future patch.

    Signed-off-by: Ian Munsie
    Reviewed-by: Frederic Barrat
    Reviewed-by: Andrew Donnellan
    Signed-off-by: Michael Ellerman

    Ian Munsie
     
  • The cxl kernel API has a concept of a default context associated with
    each PCI device under the virtual PHB. The Mellanox CX4 will also use
    the cxl kernel API, but it does not use a virtual PHB - rather, the AFU
    appears as a physical function as a peer to the networking functions.

    In order to allow the kernel API to work with those networking
    functions, we will need to associate a default context with them as
    well. To this end, refactor the corresponding code to do this in vphb.c
    and export it so that it can be called from the PHB code.

    Signed-off-by: Ian Munsie
    Reviewed-by: Frederic Barrat
    Reviewed-by: Andrew Donnellan
    Signed-off-by: Michael Ellerman

    Ian Munsie
     
  • The Mellanox CX4 uses a model where the AFU is one physical function of
    the device, and is used by other peer physical functions of the same
    device. This will require those other devices to grab a reference on the
    AFU when they are initialised to make sure that it does not go away
    during their lifetime.

    Move the AFU refcount functions to base.c so they can be called from
    the PHB code.

    Signed-off-by: Ian Munsie
    Reviewed-by: Andrew Donnellan
    Reviewed-by: Frederic Barrat
    Signed-off-by: Michael Ellerman

    Ian Munsie
     
  • This extends the check that the adapter is in a CAPI capable slot so
    that it may be called by external users in the kernel API. This will be
    used by the upcoming Mellanox CX4 support, which needs to know ahead of
    time if the card can be switched to cxl mode so that it can leave it in
    PCI mode if it is not.

    This API takes a parameter to check if CAPP DMA mode is supported, which
    it currently only allows on P8NVL systems, since that mode currently has
    issues accessing memory < 4GB on P8, and we cannot realistically avoid
    that.

    This API does not currently check if a CAPP unit is available (i.e. not
    already assigned to another PHB) on P8. Doing so would be racy since it
    is assigned on a first come first serve basis, and so long as CAPP DMA
    mode is not supported on P8 we don't need this, since the only
    anticipated user of this API requires CAPP DMA mode.

    Cc: Philippe Bergheaud
    Signed-off-by: Ian Munsie
    Reviewed-by: Andrew Donnellan
    Reviewed-by: Frederic Barrat
    Signed-off-by: Michael Ellerman

    Ian Munsie
     

28 Jun, 2016

2 commits

  • This provides AFU drivers a means to associate private data with a cxl
    context. This is particularly intended for make the new callbacks for
    driver specific events easier for AFU drivers to use, as they can easily
    get back to any private data structures they may use.

    Signed-off-by: Michael Neuling
    Signed-off-by: Ian Munsie
    Signed-off-by: Philippe Bergheaud
    Reviewed-by: Andrew Donnellan
    Signed-off-by: Michael Ellerman

    Michael Neuling
     
  • This adds an afu_driver_ops structure with fetch_event() and
    event_delivered() callbacks. An AFU driver such as cxlflash can fill
    this out and associate it with a context to enable passing custom AFU
    specific events to userspace.

    This also adds a new kernel API function cxl_context_pending_events(),
    that the AFU driver can use to notify the cxl driver that new specific
    events are ready to be delivered, and wake up anyone waiting on the
    context wait queue.

    The current count of AFU driver specific events is stored in the field
    afu_driver_events of the context structure.

    The cxl driver checks the afu_driver_events count during poll, select,
    read, etc. calls to check if an AFU driver specific event is pending,
    and calls fetch_event() to obtain and deliver that event. This way, the
    cxl driver takes care of all the usual locking semantics around these
    calls and handles all the generic cxl events, so that the AFU driver
    only needs to worry about it's own events.

    fetch_event() return a struct cxl_event_afu_driver_reserved, allocated
    by the AFU driver, and filled in with the specific event information and
    size. Total event size (header + data) should not be greater than
    CXL_READ_MIN_SIZE (4K).

    Th cxl driver prepends an appropriate cxl event header, copies the event
    to userspace, and finally calls event_delivered() to return the status of
    the operation to the AFU driver. The event is identified by the context
    and cxl_event_afu_driver_reserved pointers.

    Since AFU drivers provide their own means for userspace to obtain the
    AFU file descriptor (i.e. cxlflash uses an ioctl on their scsi file
    descriptor to obtain the AFU file descriptor) and the generic cxl driver
    will never use this event, the ABI of the event is up to each individual
    AFU driver.

    Signed-off-by: Philippe Bergheaud
    Signed-off-by: Michael Ellerman

    Philippe Bergheaud
     

11 May, 2016

1 commit

  • cxl devices typically access memory using an MMU in much the same way as
    the CPU, and each context includes a state register much like the MSR in
    the CPU. Like the CPU, the state register includes a bit to enable
    relocation, which we currently always enable.

    In some cases, it may be desirable to allow a device to access memory
    using real addresses instead of effective addresses, so this adds a new
    API, cxl_set_translation_mode, that can be used to disable relocation
    on a given kernel context. This can allow for the creation of a special
    privileged context that the device can use if it needs relocation
    disabled, and can use regular contexts at times when it needs relocation
    enabled.

    This interface is only available to users of the kernel API for obvious
    reasons, and will never be supported in a virtualised environment.

    This will be used by the upcoming cxl support in the mlx5 driver.

    Signed-off-by: Ian Munsie
    Signed-off-by: Michael Ellerman

    Ian Munsie
     

09 Mar, 2016

2 commits

  • The cxl_get_phys_dev() API returns a struct device pointer which could
    belong to either a struct pci_dev (bare-metal) or platform_device
    (powerVM). To avoid potential problems in drivers, remove that API. It
    was introduced to allow drivers to read the VPD of the adapter, but
    the cxl driver now provides the cxl_pci_read_adapter_vpd() API for
    that purpose.

    Co-authored-by: Christophe Lombard
    Signed-off-by: Frederic Barrat
    Signed-off-by: Christophe Lombard
    Acked-by: Ian Munsie
    Signed-off-by: Michael Ellerman

    Frederic Barrat
     
  • Like on bare-metal, the cxl driver creates a virtual PHB and a pci
    device for the AFU. The configuration space of the device is mapped to
    the configuration record of the AFU.

    Reuse the code defined in afu_cr_read8|16|32() when reading the
    configuration space of the AFU device.

    Even though the (virtual) AFU device is a pci device, the adapter is
    not. So a driver using the cxl kernel API cannot read the VPD of the
    adapter through the usual PCI interface. Therefore, we add a call to
    the cxl kernel API:
    ssize_t cxl_read_adapter_vpd(struct pci_dev *dev, void *buf, size_t count);

    Co-authored-by: Christophe Lombard
    Signed-off-by: Frederic Barrat
    Signed-off-by: Christophe Lombard
    Reviewed-by: Manoj Kumar
    Acked-by: Ian Munsie
    Signed-off-by: Michael Ellerman

    Frederic Barrat
     

14 Aug, 2015

1 commit

  • Provide a kernel API and a sysfs entry which allow a user to specify
    that when a card is PERSTed, it's image will stay the same, allowing
    it to participate in EEH.

    cxl_reset is used to reflash the card. In that case, we cannot safely
    assert that the image will not change. Therefore, disallow cxl_reset
    if the flag is set.

    Signed-off-by: Daniel Axtens
    Signed-off-by: Michael Ellerman

    Daniel Axtens
     

03 Jun, 2015

2 commits

  • This patch does two things.

    Firstly it presents the Accelerator Function Unit (AFUs) behind the POWER
    Service Layer (PSL) as PCI devices on a virtual PCI Host Bridge (vPHB). This
    in in addition to the PSL being a PCI device itself.

    As part of the Coherent Accelerator Interface Architecture (CAIA) AFUs can
    provide an AFU configuration. This AFU configuration recored is architected to
    be the same as a PCI config space.

    This patch sets discovers the AFU configuration records, provides AFU config
    space read/write functions to these configuration records. It then enumerates
    the PCI bus. It also hooks in PCI ops where appropriate. It also destroys the
    vPHB when the physical card is removed.

    Secondly, it add an in kernel API for AFU to use CXL. AFUs must present a
    driver that firstly binds as a PCI device. This PCI device can then be using
    to do CXL specific operations (that can't sit in the PCI ops) using this API.

    Signed-off-by: Michael Neuling
    Acked-by: Ian Munsie
    Signed-off-by: Michael Ellerman

    Michael Neuling
     
  • This moves the current include file from cxl.h -> cxl-base.h. This current
    include file is used only to pass information between the base driver that
    needs to be built into the kernel and the cxl module.

    This is to make way for a new include/misc/cxl.h which will
    contain just the kernel API for other driver to use

    Signed-off-by: Michael Neuling
    Acked-by: Ian Munsie
    Signed-off-by: Michael Ellerman

    Michael Neuling
     

08 Oct, 2014

1 commit

  • This new header adds callbacks and structs needed by the rest of the kernel to
    hook into the cxl infrastructure.

    This adds the cxl_ctx_in_use() function for use in the mm code to see if any
    cxl contexts are currently in use. This is used by the tlbie() to determine if
    it can do local TLB invalidations or not. This also adds get/put calls for the
    cxl driver module to refcount the active cxl contexts.

    cxl_ctx_get/put/in_use are static inlined here as they are called in tlbie
    which we want to be fast (mpe's suggestion).

    Empty functions are provided when CONFIG_CXL_BASE is not enabled.

    Signed-off-by: Ian Munsie
    Signed-off-by: Michael Neuling
    Signed-off-by: Michael Ellerman

    Ian Munsie
     

24 Sep, 2011

1 commit