Skip to content

Conversation

@AaronDot
Copy link
Contributor

Introduction to the patchset:

Patch-1: ACPI support for LoongArch SE driver, which was an absence from the previous patchset.
Patch 2-3: backported from upstream
Patch 4-6: related driver fixes

ACPI HID for Loongson SE is "LOONG0011", for Loongson SDF is
"LOON0012". And cleanned up coding style. Moved SE header
file form arch/loongarch/include/asm to include/soc/loongson.

Signed-off-by: Zhao Qunqin <[email protected]>
Signed-off-by: Binbin Zhou <[email protected]>
commit 3784950 upstream.

Loongson's HDA devices do not support TCSEL functionality.

Signed-off-by: Qunqin Zhao <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Takashi Iwai <[email protected]>
Signed-off-by: Binbin Zhou <[email protected]>
commit b62a030 upstream.

SMT cores and their sibling cores share the same L1 and L2 private
caches (of course last level cache is also shared), so correct the
cacheinfo sharing information to let shared_cpu_map correctly reflect
this relationship.

Below is the output of "lscpu" on Loongson-3A6000 (4 cores, 8 threads).

1. Before patch:

  L1d:                    512 KiB (8 instances)
  L1i:                    512 KiB (8 instances)
  L2:                     2 MiB (8 instances)
  L3:                     16 MiB (1 instance)

2. After patch:

  L1d:                    256 KiB (4 instances)
  L1i:                    256 KiB (4 instances)
  L2:                     1 MiB (4 instances)
  L3:                     16 MiB (1 instance)

Reported-by: Chao Li <[email protected]>
Signed-off-by: Juxin Gao <[email protected]>
Signed-off-by: Huacai Chen <[email protected]>
Signed-off-by: Binbin Zhou <[email protected]>
When CONFIG_CMA_SIZE_MBYTES is not zero and its value is small,
error log appear in dmesg as following:
[12689.920994][ T2178] cma: cma_alloc: reserved: alloc failed, req-size: 4 pages, ret: -12
[12689.934128][ T2178] cma: cma_alloc: reserved: alloc failed, req-size: 4 pages, ret: -12

So set CONFIG_CMA_SIZE_MBYTES to 0 to hide the error log.

Signed-off-by: Ming Wang <[email protected]>
Signed-off-by: Hongchen Zhang <[email protected]>
Signed-off-by: Binbin Zhou <[email protected]>
new_rcp->recipe_bitmap was written to as if it were an aligned bitmap.
It is an 8-byte array, but aligned only to 4.
Use put_unaligned to set its value.

Additionally, values in ice commands are typically in little-endian.
I assume the recipe bitmap should be too, so use the *_le64 conversion.
I don't have a big-endian system with ice to test this.

I tested that the driver does not crash when probing on aarch64 anymore,
which is good enough for me. I don't know if the LAG feature actually
works.

This is what the crash looked like without the fix:
[   17.599009] Unable to handle kernel paging request at virtual address ffff07ff9c6dc004
[   17.599011] Mem abort info:
[   17.599011]   ESR = 0x0000000096000021
[   17.599012]   EC = 0x25: DABT (current EL), IL = 32 bits
[   17.599013]   SET = 0, FnV = 0
[   17.599014]   EA = 0, S1PTW = 0
[   17.599014]   FSC = 0x21: alignment fault
[   17.599015] Data abort info:
[   17.599016]   ISV = 0, ISS = 0x00000021, ISS2 = 0x00000000
[   17.599016]   CM = 0, WnR = 0, TnD = 0, TagAccess = 0
[   17.599017]   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[   17.599019] swapper pgtable: 4k pages, 48-bit VAs, pgdp=0000080dd6bd0000
[   17.599020] [ffff07ff9c6dc004] pgd=1800083fffacf003, p4d=1800083fffacf003, pud=1800083ffface003, pmd=1800083fff9ea003, pte=006808001c6dcf07
[   17.599025] Internal error: Oops: 0000000096000021 [deepin-community#1] SMP
[   17.599027] Modules linked in: crct10dif_ce ghash_ce sha2_ce sha256_arm64 mlx5_core sha1_ce sbsa_gwdt ice(+) nvme nvme_core mlxfw igb tls nvme_common psample i2c_algo_bit gnss pci_hyperv_intf i2c_designware_platform i2c_designware_core xgene_hwmon dm_mirror dm_region_hash dm_log dm_mod
[   17.599043] CPU: 0 PID: 18 Comm: kworker/0:1 Not tainted 5.14.0-407.el9.aarch64 deepin-community#1
[   17.599044] Hardware name: GIGABYTE R272-P31-00/MP32-AR1-00, BIOS F31L (SCP: 2.10.20220531) 09/29/2022
[   17.599046] Workqueue: events work_for_cpu_fn
[   17.599051] pstate: 60400009 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[   17.599053] pc : ice_create_lag_recipe.constprop.0+0xbc/0x11c [ice]
[   17.599091] lr : ice_create_lag_recipe.constprop.0+0x54/0x11c [ice]
[   17.599121] sp : ffff8000084a3c50
[   17.599122] x29: ffff8000084a3c50 x28: ffffabc4a6790f00 x27: ffffabc4a6200fa0
[   17.599124] x26: ffff07ff809e5c34 x25: ffff083e5f41980d x24: ffff07ff8610a0c0
[   17.599126] x23: 0000000000000000 x22: ffff07ff9fe894c0 x21: ffff07ffb771a460
[   17.599128] x20: ffff07ff9c6dc000 x19: 0000000000000000 x18: 0000000000000014
[   17.599130] x17: 00000000c3142fa2 x16: 000000007e77e163 x15: 0000000018c66856
[   17.599132] x14: 00000000b8afd426 x13: 000000007e8b3b19 x12: 000000004a34fdf7
[   17.599134] x11: 00000000a7cb2fcc x10: 00000000ffffff8a x9 : 0000000000000000
[   17.599136] x8 : 0000002000000005 x7 : 0000000000000001 x6 : ffffabc487a054d8
[   17.599138] x5 : ffff07ff9c6dc004 x4 : 000000000000000a x3 : 0000000000000000
[   17.599140] x2 : 0000000000000000 x1 : 0000000000000400 x0 : ffff07ff9c6dc004
[   17.599142] Call trace:
[   17.599143]  ice_create_lag_recipe.constprop.0+0xbc/0x11c [ice]
[   17.599172]  ice_init_lag+0xcc/0x22c [ice]
[   17.599201]  ice_init_features+0x160/0x2b4 [ice]
[   17.599230]  ice_probe+0x2d0/0x30c [ice]
[   17.599258]  local_pci_probe+0x58/0xb0
[   17.599262]  work_for_cpu_fn+0x20/0x30
[   17.599264]  process_one_work+0x1e4/0x4c0
[   17.599266]  worker_thread+0x220/0x450
[   17.599268]  kthread+0xe8/0xf4
[   17.599270]  ret_from_fork+0x10/0x20
[   17.599273] Code: 380044a4 f800429f 8b000ca0 d503201f (f821301f)
[   17.599274] ---[ end trace 168d79e2ecf9f7e3 ]---
[   17.599275] Kernel panic - not syncing: Oops: Fatal exception
[   17.893321] SMP: stopping secondary CPUs
[   17.897374] Kernel Offset: 0x2bc49c400000 from 0xffff800008000000
[   17.903453] PHYS_OFFSET: 0x80000000
[   17.906928] CPU features: 0x0,00000001,70028143,1041720b
[   17.912226] Memory Limit: none
[   17.915268] ---[ end Kernel panic - not syncing: Oops: Fatal exception ]---

Link: https://lore.kernel.org/all/[email protected]/

Fixes: 1e0f988 ("ice: Flesh out implementation of support for SRIOV on bonded interface")
Signed-off-by: Michal Schmidt <[email protected]>
Signed-off-by: Hongchen Zhang <[email protected]>
Signed-off-by: Binbin Zhou <[email protected]>
There are suspend, resume and suspend before hibernation, Loongson need
to wait until the previous resume is completely over before the last
suspending. Otherwise, it may cause S4 suspend failure in Loongson
platform.

Signed-off-by: Zhao Qunqin <[email protected]>
Signed-off-by: Binbin Zhou <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Mar 19, 2025

Reviewer's Guide by Sourcery

This pull request includes several driver fixes and backports for the Loongarch architecture. It introduces ACPI support for the Loongson SE driver, backports changes from upstream, and addresses driver-related issues. The changes span across different drivers including loongson_se, lsse_sdf_cdev, cacheinfo.c, ice_switch.c, ice_lag.c, hda_intel.c, and btusb.c.

Sequence diagram for sending a request to the SE

sequenceDiagram
    participant CPU
    participant loongson_se
    participant sub-dev

    CPU->>loongson_se: se_send_request(req)
    activate loongson_se
    loongson_se->>loongson_se: se_writel(req->u.data[i], SE_DATA_S + i * 4)
    loongson_se->>loongson_se: se_writel(req->int_bit, SE_L2SINT_SET)
    loop until status & req->int_bit
        loongson_se->>loongson_se: readl_relaxed_poll_timeout_atomic
    end
    loongson_se->>sub-dev: Command
    deactivate loongson_se
Loading

Sequence diagram for receiving a response from the SE

sequenceDiagram
    participant CPU
    participant loongson_se
    participant sub-dev

    CPU->>loongson_se: se_get_response(res)
    activate loongson_se
    alt se_readl(SE_S2LINT_STAT) & res->int_bit
        loop i < ARRAY_SIZE(res->u.data)
            loongson_se->>loongson_se: res->u.data[i] = se_readl(SE_DATA_L + i * 4)
        end
        loongson_se->>loongson_se: se_writel(res->int_bit, SE_S2LINT_CL)
        loongson_se-->>CPU: Response
    else Interrupt not received
        loongson_se-->>CPU: -EBUSY
    end
    deactivate loongson_se
Loading

Updated class diagram for loongson_se and lsse_ch

classDiagram
    class loongson_se {
        -void *base
        -dma_addr_t mem_addr
        -unsigned long *mem_map
        -int mem_map_pages
        -void *smsg
        -void *rmsg
        -struct completion cmd_completion
        -struct lsse_ch chs[SE_CH_MAX]
    }
    class lsse_ch {
        -struct loongson_se *se
        -int id
        -u32 int_bit
        -void *data_buffer
        -dma_addr_t data_addr
        -int data_size
        -void *smsg
        -void *rmsg
        -int msg_size
        -void (*complete)(struct lsse_ch *se_ch)
        -void *priv
    }
    loongson_se -- lsse_ch : contains
    note for loongson_se "Represents the Loongson SE device and its resources."
    note for lsse_ch "Represents a channel within the Loongson SE device."
Loading

File-Level Changes

Change Details Files
Refactors the Loongson SE driver to use ACPI, improve code readability, and enhance functionality.
  • Replaced the GPL-2.0 license with GPL-2.0+
  • Added ACPI support.
  • Improved code comments and descriptions.
  • Reorganized the code for better readability.
  • Modified the driver to use struct se_data instead of struct se_mailbox_data for data transfer.
  • Replaced se_mem_size and se_mem_page module parameters with device property dmam_size.
  • Removed the registration of lsse_miscdev and lsse_sdf_pdev.
drivers/char/loongson_se.c
include/soc/loongson/se.h
Updates the Loongson SDF driver to align with the Loongson SE driver changes and improve code maintainability.
  • Updated the license to GPL-2.0+.
  • Modified the driver to use the new se_init_ch function.
  • Removed the global se_sdf_dev variable.
  • Replaced lsse_sdf_complete, lsse_sdf_open, lsse_sdf_write, lsse_sdf_read, lsse_sdf_release, lsse_sdf_probe, and lsse_sdf_remove with sdf_complete, sdf_open, sdf_write, sdf_recvu, sdf_recvk, sdf_release, sdf_probe, and sdf_remove respectively.
  • Added ACPI match table.
drivers/char/lsse_sdf_cdev.c
Fixes a cacheinfo setup issue for SMT cores.
  • Added a check for sibling cores in cache_cpumap_setup to ensure SMT cores share all caches.
arch/loongarch/kernel/cacheinfo.c
Optimizes recipe bitmap handling in the ice driver.
  • Replaced bitmap operations with a direct memory write using put_unaligned_le64 for setting the recipe index in the recipe bitmap.
drivers/net/ethernet/intel/ice/ice_switch.c
drivers/net/ethernet/intel/ice/ice_lag.c
Adds a flag to disable TCSEL and fix device id for Loongson HDAudio.
  • Added AZX_DCAPS_NO_TCSEL flag for Loongson HDAudio devices.
  • Fixed device id for Loongson HDMI.
sound/pci/hda/hda_intel.c
Adds a delay to btusb suspend for LoongArch architecture.
  • Added a conditional mdelay(1) call within the btusb_suspend function, specifically for the LoongArch architecture.
drivers/bluetooth/btusb.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mingcongbai for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link

Hi @AaronDot. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @AaronDot - I've reviewed your changes - here's some feedback:

Overall Comments:

  • It looks like the driver is being converted to use standard kernel conventions, which is good.
  • Consider using devm_bitmap_alloc instead of bitmap_zalloc to have the bitmap automatically freed on driver removal.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

* DMA | | IRQ
* v v
* +-----------------------------------+
* | Loongson Security Module |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (performance): Revisit the use of HZ for timeout.

Switching from msecs_to_jiffies(0x1000) (approximately 1000ms) to HZ may yield a different timeout duration on some platforms. Confirm that this shorter timeout is intentional and sufficient for the SE command completion.

int err;

spin_lock_irqsave(&se->se_ch->ch_lock, flag);
spin_lock_irq(&se->se_ch->ch_lock);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (bug_risk): Use of spin_lock_irq without saving flags.

Switching to spin_lock_irq may be acceptable if it is guaranteed that the calling context already has appropriate interrupt settings. Confirm that IRQ state restoration is not needed in this context.

Comment on lines +4116 to +4117
#ifdef CONFIG_LOONGARCH
mdelay(1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (performance): Added delay in btusb suspend on Loongarch.

The 1ms delay introduced for Loongarch platforms appears intended to allow hardware settling. Confirm that this delay is sufficient and does not adversely affect system suspend latency across all targeted devices.

@AaronDot AaronDot changed the title Loongarch driver fixes and backport [linux-6.6,y]Loongarch driver fixes and backport Mar 19, 2025
@AaronDot AaronDot changed the title [linux-6.6,y]Loongarch driver fixes and backport [linux-6.6.y]Loongarch driver fixes and backport Mar 19, 2025
@opsiff
Copy link
Member

opsiff commented Mar 20, 2025

/ok-to-test

@opsiff
Copy link
Member

opsiff commented Mar 26, 2025

1.drivers/char: add ACPI firmware support for Loongson SE driver
在3A6000上测试没有效果 手动加载模块后也没有效果
先合入待有效果产生再进行测试。
2.ALSA: hda: Add AZX_DCAPS_NO_TCSEL flag for Loongson HDA devices
上游提交 待测
3.LoongArch: Correct the cacheinfo sharing information
上游提交 在3A6000上测试过
4.LoongArch: set CONFIG_CMA_SIZE_MBYTES to 0
检查内核日志 未有错误 deepin配置已包括 合入
5.ice: fix unaligned access in ice_create_lag_recipe
无条件测试 代码review ok
6.blutetooth/btusb: delay 1ms while suspending
不清楚原理 待后续排查看是否可以替换或去掉 可以暂时合入作为workaround

@Avenger-285714 Avenger-285714 merged commit 1fbe04f into deepin-community:linux-6.6.y Mar 26, 2025
5 of 6 checks passed
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. arch/loongarch/configs/loongson3_defconfig文件中,新增的CONFIG_CMA_SIZE_MBYTES=0配置项没有注释说明其用途和影响,建议添加注释说明。

  2. arch/loongarch/kernel/cacheinfo.c文件中,新增的代码块if (cpus_are_siblings(i, cpu))if (cache_leaves_are_shared(this_leaf, sib_leaf))没有注释说明其逻辑和用途,建议添加注释说明。

  3. drivers/bluetooth/btusb.c文件中,新增的#ifdef CONFIG_LOONGARCH#endif宏定义用于条件编译,但没有注释说明其目的,建议添加注释说明。

  4. drivers/char/loongson_se.c文件中,se_readlse_writel函数的参数列表进行了修改,但是没有更新所有调用这些函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  5. drivers/char/loongson_se.c文件中,se_send_requestse_get_response函数的参数类型从struct se_mailbox_data更改为struct se_data,但是没有更新所有调用这些函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  6. drivers/char/loongson_se.c文件中,se_send_genl_cmd函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  7. drivers/char/loongson_se.c文件中,loongson_se_get_res函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  8. drivers/char/loongson_se.c文件中,se_init_hw函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  9. drivers/char/loongson_se.c文件中,se_disable_hw函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  10. drivers/char/loongson_se.c文件中,se_send_ch_request函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  11. drivers/char/loongson_se.c文件中,se_init_ch函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  12. drivers/char/loongson_se.c文件中,se_deinit_ch函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  13. drivers/char/lsse_sdf_cdev.c文件中,lsse_sdf_complete函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  14. drivers/char/lsse_sdf_cdev.c文件中,se_send_sdf_cmd函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  15. drivers/char/lsse_sdf_cdev.c文件中,lsse_sdf_recv函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  16. drivers/char/lsse_sdf_cdev.c文件中,lsse_sdf_send函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  17. drivers/char/lsse_sdf_cdev.c文件中,lsse_sdf_release函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  18. drivers/char/lsse_sdf_cdev.c文件中,lsse_sdf_open函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  19. drivers/net/ethernet/intel/ice/ice_lag.c文件中,ice_create_lag_recipe函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  20. drivers/net/ethernet/intel/ice/ice_switch.c文件中,ice_add_sw_recipe函数的参数列表进行了修改,但是没有更新所有调用这个函数的地方,可能会导致编译错误,建议检查并更新所有调用。

  21. arch/loongarch/include/asm/se.h文件中,SE_MAILBOX_SSE_MAILBOX_L宏定义被重命名为SE_DATA_SSE_DATA_L,但是没有更新所有调用这些宏定义的地方,可能会导致编译错误,建议检查并更新所有调用。

  22. sound/pci/hda/hda_intel.c文件中,azx_ids数组中的AZX_DRIVER_LOONGSON被修改为AZX_DRIVER_LOONGSON | AZX_DCAPS_NO_TCSEL,但是没有更新所有调用这个宏定义的地方,可能会导致编译错误,建议检查并更新所有调用。

以上是代码审查意见,希望能够帮助到您。

@AaronDot AaronDot deleted the loongarch-sync branch May 7, 2025 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants