1. 14 Jul, 2016 7 commits
    • Andrew Donnellan's avatar
      cxl: Add cxl_check_and_switch_mode() API to switch bi-modal cards · b0b5e591
      Andrew Donnellan authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Cc: Gavin Shan <gwshan@linux.vnet.ibm.com>
      Signed-off-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Signed-off-by: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarGavin Shan <gwshan@linux.vnet.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      b0b5e591
    • Ian Munsie's avatar
      cxl: Add support for interrupts on the Mellanox CX4 · a2f67d5e
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      a2f67d5e
    • Ian Munsie's avatar
      cxl: Add preliminary workaround for CX4 interrupt limitation · cbce0917
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      cbce0917
    • Ian Munsie's avatar
      cxl: Add kernel APIs to get & set the max irqs per context · 79384e4b
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      79384e4b
    • Ian Munsie's avatar
      cxl: Allow a default context to be associated with an external pci_dev · a19bd79e
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      a19bd79e
    • Ian Munsie's avatar
      cxl: Move cxl_afu_get / cxl_afu_put to base · 62ccf2d2
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Reviewed-by: 's avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      62ccf2d2
    • Ian Munsie's avatar
      cxl: Add cxl_slot_is_supported API · 4e56f858
      Ian Munsie authored
      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 <felix@linux.vnet.ibm.com>
      Signed-off-by: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Reviewed-by: 's avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      4e56f858
  2. 28 Jun, 2016 2 commits
    • Michael Neuling's avatar
      cxl: Add set and get private data to context struct · ad42de85
      Michael Neuling authored
      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: 's avatarMichael Neuling <mikey@neuling.org>
      Signed-off-by: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Signed-off-by: Philippe Bergheaud <felix@linux.vnet.ibm.com
      Reviewed-by: 's avatarMatthew R. Ochs <mrochs@linux.vnet.ibm.com>
      Reviewed-by: 's avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      ad42de85
    • Philippe Bergheaud's avatar
      cxl: Add mechanism for delivering AFU driver specific events · b810253b
      Philippe Bergheaud authored
      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: 's avatarPhilippe Bergheaud <felix@linux.vnet.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      b810253b
  3. 11 May, 2016 1 commit
    • Ian Munsie's avatar
      cxl: Add kernel API to allow a context to operate with relocate disabled · 7a0d85d3
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      7a0d85d3
  4. 09 Mar, 2016 2 commits
  5. 14 Aug, 2015 1 commit
  6. 02 Jun, 2015 2 commits
    • Michael Neuling's avatar
      cxl: Add AFU virtual PHB and kernel API · 6f7f0b3d
      Michael Neuling authored
      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: 's avatarMichael Neuling <mikey@neuling.org>
      Acked-by: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      6f7f0b3d
    • Michael Neuling's avatar
      cxl: Move include file cxl.h -> cxl-base.h · ec249dd8
      Michael Neuling authored
      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: 's avatarMichael Neuling <mikey@neuling.org>
      Acked-by: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      ec249dd8
  7. 08 Oct, 2014 1 commit
    • Ian Munsie's avatar
      cxl: Add new header for call backs and structs · 1cd258d7
      Ian Munsie authored
      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: 's avatarIan Munsie <imunsie@au1.ibm.com>
      Signed-off-by: 's avatarMichael Neuling <mikey@neuling.org>
      Signed-off-by: 's avatarMichael Ellerman <mpe@ellerman.id.au>
      1cd258d7
  8. 23 Sep, 2011 1 commit