accel/amdxdna: DMA buffer helpers and AIE4 work buffer support#1229
accel/amdxdna: DMA buffer helpers and AIE4 work buffer support#1229NishadSaraf wants to merge 3 commits intoamd:mainfrom
Conversation
|
@NishadSaraf I thought that we could make the mgmt buffer common. Thus all buffers including work buffer should be allocated by the amdxdna APIs, maybe move code in aie.c but API name as amdxdna_xxx for buffer alloc and free. The workbuffer alloc/free might be no-op for aie2. I discussed this with Max, we even bringstrom to have the workbuffer for aie2 even we don't use it today. Thus, we can make the code look simpler for the linux maintainer to review. After that the extra ops is the attach or register (I think those different naming APIs are doing the same thing, just using different mailbox messages across aie2, aie4) Given the current situation, I am not sure you plan. Are you going to make it done in next week? If yes, please arrange a meeting instead of chatting here for better communication. Please also include @hlaccabu, I asked him to get familiar with this area too. |
When unloading the driver, aie4_sriov_stop() unconditionally sends a destroy VFs firmware command even when no VFs were ever created. This causes the firmware to return an error: amdxdna: [drm] *ERROR* aie_send_mgmt_msg_wait: command opcode 0x20002 failed, status 0x1 amdxdna: [drm] *ERROR* aie4_destroy_vfs: destroy vfs op failed: -22 Fix this by checking pci_num_vf() at the top of aie4_sriov_stop() and returning early if no VFs exist. Signed-off-by: Nishad Saraf <nishads@amd.com>
Move aie2_alloc_msg_buffer() and aie2_free_msg_buffer() out of the AIE2-specific aie2_message.c into the common aie.c, renaming them to amdxdna_alloc_msg_buffer() and amdxdna_free_msg_buffer(). The first parameter changes from struct amdxdna_dev_hdl to struct amdxdna_dev so the helpers can be called from any device generation. Update call sites in aie2_message.c and aie2_error.c and remove the old declarations from aie2_pci.h. Signed-off-by: Nishad Saraf <nishads@amd.com>
NPU firmware requires a host-allocated DRAM work buffer before any hardware contexts can be created. Allocate a 4 MB (power-of-2 aligned) buffer during device init via the common amdxdna_alloc_msg_buffer() helper and attach it to firmware after mailbox init. The firmware releases the buffer internally during its suspend sequence, so no explicit detach is needed from the driver. Add the attach_work_buffer mailbox message, using GENMASK/FIELD_PREP for PASID register encoding. Signed-off-by: Nishad Saraf <nishads@amd.com>
This series introduces a common DMA buffer abstraction for the amdxdna
driver and uses it to add DRAM work buffer support for AIE4 devices.
The NPU firmware has strict constraints on host-allocated DMA buffers:
sizes must be power-of-2, addresses must be naturally aligned, and
buffers must not cross a 64 MB boundary. Currently, the AIE2 code
opens its own alloc/free helpers without enforcing these rules.
Patches 1-2 introduce struct aie_dma_hdl with alloc/free/clflush
helpers that enforce the firmware constraints, then migrate the
existing AIE2 call sites.
Patch 3 builds on this to allocate and attach a DRAM work buffer
required by AIE4 firmware for runtime operation. Only the PF driver
performs the allocation; VF devices skip it.
Patch 4 fixes a minor SR-IOV teardown issue where the driver
unconditionally sent a destroy-VFs command even when no VFs existed.