Skip to content

Conversation

@Avenger-285714
Copy link
Member

@Avenger-285714 Avenger-285714 commented Feb 24, 2025

update Montage Mont-TSSE driver from 1.0.0 to 1.1.2 in 6.6. New version has optimized the code structure and IPC function and fixed some bugs.

Link: https://gitee.com/OpenCloudOS/OpenCloudOS-Kernel/pulls/311

[ WangYuli: Fix some conflict ]

Summary by Sourcery

This pull request updates the Montage Mont-TSSE driver from version 1.0.0 to 1.1.2, which includes code structure optimizations, IPC function improvements, and bug fixes. It also adds a mechanism to disable ASPM completely to avoid performance issues.

Bug Fixes:

  • Fixed bugs in the Montage Mont-TSSE driver.

Enhancements:

  • Improved the code structure of the Montage Mont-TSSE driver.
  • Optimized the IPC function in the Montage Mont-TSSE driver.

Build:

  • Updated the Montage Mont-TSSE driver from version 1.0.0 to 1.1.2.

CI:

  • Added a mechanism to disable ASPM completely to avoid performance issues.

update Montage Mont-TSSE driver from 1.0.0 to 1.1.2 in 6.6.
New version has optimized the code structure and IPC function and
fixed some bugs.

Link: https://gitee.com/OpenCloudOS/OpenCloudOS-Kernel/pulls/311
Signed-off-by: Carrie.Cai <carrie.cai@montage-tech.com>
[ WangYuli: Fix some conflict ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 24, 2025

Reviewer's Guide by Sourcery

This pull request updates the Montage Mont-TSSE driver from version 1.0.0 to 1.1.2. The update includes a refactored IPC mechanism using a new message structure and dispatching method, updates to the firmware loading process with firmware version retrieval, and refactored device management with handle-based device access. The copyright year has also been updated.

Sequence diagram for Host to Device Firmware Loading

sequenceDiagram
    participant Host
    participant TSSE Driver
    participant TSSE Device

    Host->>TSSE Driver: Requests firmware load (tsse_fw_manual_load_ipc)
    TSSE Driver->>TSSE Driver: Initializes IPC (ipc_hw_init)
    TSSE Driver->>TSSE Driver: Sends host init message (host_init_msg)
    TSSE Driver->>TSSE Device: Writes message to H2M (HOST2MAIN_IPC_OFFSET)
    TSSE Driver->>TSSE Device: Sets interrupt (HOST2MAIN_INTR_SET_OFFSET)
    TSSE Device->>TSSE Driver: Generates interrupt
    TSSE Driver->>TSSE Driver: Handles interrupt (tsse_ipc_d2h_irqhandler)
    TSSE Driver->>TSSE Driver: Processes message (tsse_ipc_bh_handler)
    TSSE Driver->>TSSE Driver: Routes service (service_rout)
    TSSE Driver->>TSSE Driver: Executes firmware service (fw_service)
    TSSE Driver->>TSSE Device: Writes firmware data to device memory
    TSSE Driver->>TSSE Device: Writes message to H2M (HOST2MAIN_IPC_OFFSET)
    TSSE Driver->>TSSE Device: Sets interrupt (HOST2MAIN_INTR_SET_OFFSET)
Loading

Updated class diagram for TSSE IPC

classDiagram
    class tsse_ipc {
        -struct device *dev
        -struct pci_dev *pdev
        -void __iomem *virt_addr
        -struct mutex list_lock
        -struct tasklet_struct ipc_handle
        -tsse_d2h_ipc_handler d2h_handlers[IPC_MESSAGE_CLASS_NUM]
        -u32 im_inited
    }
    class tsse_dev {

    }
    class tsse_d2h_ipc_handler{
        <<interface>>
        +int handle(int handle, void *msg_payload, uint32_t payload_length)
    }
    tsse_ipc -- tsse_dev : has a
    tsse_ipc .. tsse_d2h_ipc_handler : Uses
    note for tsse_ipc "Updated tsse_ipc class with d2h_handlers and im_inited field"
Loading

Class diagram for TSSE Service

classDiagram
    class tsse_service_instance {
        -u8 service_opened
        -u8 service_name[TSSE_IM_SERVICE_NAME_LEN]
        -int device_handle
        -tsse_im_cb_func cb
        -u64 service_epid
    }
    class tsse_im_cb_func{
        <<interface>>
        +int handle(tsse_im_service_handle handle, void *msg_payload, u32 payload_length)
    }
    class tsse_dev {

    }
    tsse_service_instance -- tsse_dev : Uses
    tsse_service_instance .. tsse_im_cb_func : Uses
    note for tsse_service_instance "Represents an instance of a TSSE service"
Loading

Class diagram for TSSE IPC Message

classDiagram
    class tsse_ipc_msg {
        -u16 type
        -u16 msg_len
        -u32 rev
        -u64 epid
        -u8 data[]
    }
    note for tsse_ipc_msg "Represents the structure of an IPC message"
Loading

File-Level Changes

Change Details Files
Updated the copyright year to include 2024.
  • Updated copyright year in tsse_ipc.c.
  • Updated copyright year in tsse_dev_mgr.c.
  • Updated copyright year in tsse_fw_service.c.
  • Updated copyright year in tsse_dev_drv.c.
  • Updated copyright year in tsse_ipc.h.
  • Updated copyright year in tsse_service.c.
  • Updated copyright year in tsse_dev.h.
  • Updated copyright year in tsse_fw_service.h.
  • Updated copyright year in tsse_service.h.
  • Updated copyright year in tsse_ipc_service.c.
  • Updated copyright year in tsse_ipc_setup.c.
  • Updated copyright year in tsse_ipc_drv.c.
  • Updated copyright year in tsse_ipc_api.c.
  • Updated copyright year in tsse_ipc_hash.c.
  • Updated copyright year in tsse_ipc_epid.c.
  • Updated copyright year in tsse_ipc_msg.h.
drivers/crypto/montage/tsse/tsse_ipc.c
drivers/crypto/montage/tsse/tsse_dev_mgr.c
drivers/crypto/montage/tsse/tsse_fw_service.c
drivers/crypto/montage/tsse/tsse_dev_drv.c
drivers/crypto/montage/tsse/tsse_ipc.h
drivers/crypto/montage/tsse/tsse_service.c
drivers/crypto/montage/tsse/tsse_dev.h
drivers/crypto/montage/tsse/tsse_fw_service.h
drivers/crypto/montage/tsse/tsse_service.h
drivers/crypto/montage/tsse/tsse_ipc_service.c
drivers/crypto/montage/tsse/tsse_ipc_setup.c
drivers/crypto/montage/tsse/tsse_ipc_drv.c
drivers/crypto/montage/tsse/tsse_ipc_api.c
drivers/crypto/montage/tsse/tsse_ipc_hash.c
drivers/crypto/montage/tsse/tsse_ipc_epid.c
drivers/crypto/montage/tsse/tsse_ipc_msg.h
Refactored the IPC mechanism to use a new message structure and dispatching method.
  • Introduced a new message structure tsse_ipc_msg.
  • Implemented a message dispatching function ipc_d2h_msg_dispatch.
  • Replaced the legacy message processing with the new dispatching mechanism.
  • Added new files related to the new IPC mechanism: tsse_ipc_service.c, tsse_ipc_setup.c, tsse_ipc_drv.c, tsse_ipc_api.c, tsse_ipc_hash.c, tsse_ipc_epid.c, and tsse_ipc_msg.h.
  • Modified tsse_ipc.c to use the new message structure and dispatching.
  • Removed legacy IPC-related functions and definitions.
  • Added functions for setting up and tearing down the IPC ring buffer.
  • Added functions for sending and receiving IPC messages.
drivers/crypto/montage/tsse/tsse_ipc.c
drivers/crypto/montage/tsse/tsse_ipc.h
drivers/crypto/montage/tsse/tsse_service.c
drivers/crypto/montage/tsse/Makefile
drivers/crypto/montage/tsse/tsse_ipc_service.c
drivers/crypto/montage/tsse/tsse_ipc_setup.c
drivers/crypto/montage/tsse/tsse_ipc_drv.c
drivers/crypto/montage/tsse/tsse_ipc_api.c
drivers/crypto/montage/tsse/tsse_ipc_hash.c
drivers/crypto/montage/tsse/tsse_ipc_epid.c
drivers/crypto/montage/tsse/tsse_ipc_msg.h
Updated the firmware loading process and added firmware version retrieval.
  • Modified tsse_fw_service.c to use the new IPC mechanism for firmware loading.
  • Added a function to retrieve the firmware version from the firmware image.
  • Modified tsse_dev_drv.c to load the firmware during device probe.
  • Modified tsse_dev_drv.c to allocate memory for firmware data.
  • Updated tsse_fw_service.h to define the maximum firmware length.
  • Modified tsse_dev_drv.c to disable ASPM (Active State Power Management) to avoid performance issues.
drivers/crypto/montage/tsse/tsse_fw_service.c
drivers/crypto/montage/tsse/tsse_fw_service.h
drivers/crypto/montage/tsse/tsse_dev_drv.c
drivers/crypto/montage/tsse/tsse_dev.h
Refactored device management and added handle-based device access.
  • Added functions to get a TSSE device by its handle and to get an available handle.
  • Modified tsse_dev_mgr.c to use a list for managing TSSE devices.
  • Added functions to get the IOMMU domain by handle.
  • Modified tsse_dev_drv.c to assign a unique ID to each device.
  • Added a header file tsse_handle.h for handle-related definitions.
  • Removed the qpairs bank from the device structure.
drivers/crypto/montage/tsse/tsse_dev_mgr.c
drivers/crypto/montage/tsse/tsse_dev_drv.c
drivers/crypto/montage/tsse/tsse_dev.h
drivers/crypto/montage/tsse/tsse_handle.h

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

@Avenger-285714
Copy link
Member Author

Test passed on clang-19.

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 @Avenger-285714 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using dev_printk instead of pr_info/pr_err to control verbosity.
  • It looks like you're adding a lot of new files - consider adding a short description of each in the commit message.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 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.

#define SET_BIT(bitmap, bit) (bitmap[(bit) / 8] |= (1 << ((bit) % 8)))
#define CLEAR_BIT(bitmap, bit) (bitmap[(bit) / 8] &= ~(1 << ((bit) % 8)))

static u8 service_id_bitmap[SERVICE_BITMAP_SIZE] = {0};
Copy link

Choose a reason for hiding this comment

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

suggestion (bug_risk): Consider adding locking for bitmap accesses.

The global 'service_id_bitmap' and the 'current_max_service_id' are accessed and updated in tsse_available_service_id without any explicit synchronization. In a concurrent environment, especially considering these functions might be invoked from different contexts, it would be safer to protect these accesses with a spinlock or another appropriate synchronization mechanism.


writel(0x0, tsseipc->virt_addr + MAIN2HOST_INTR_SET_OFFSET);
tasklet_schedule(&tsseipc->ipc_handle);
dev_err(tsseipc->dev, "irq%d\n", irq);
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider lowering the log level for IRQ handler messages.

Logging every IRQ as an error may lead to log spam if these interrupts are frequent and expected. If this message is informational, consider using dev_info or dev_dbg instead of dev_err to avoid unnecessary error logging.

Suggested change
dev_err(tsseipc->dev, "irq%d\n", irq);
dev_info(tsseipc->dev, "irq%d\n", irq);

return ret;
}

int tsse_service_msg_send(
Copy link

Choose a reason for hiding this comment

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

issue (complexity): Consider creating a common helper function to encapsulate the request setup and handling pattern used in several functions to reduce code duplication.

Consider consolidating the common request‐setup and handling pattern. For example, several functions allocate a request object and a user data block, initialize a completion, fill the header fields, send the message, and then call the post‐process function. Consolidating that flow into a common helper function will simplify the code and reduce duplication.

For example:

static int tsse_service_common_request(void *req, size_t req_size,
                                       tsse_im_service_handle handle,
                                       u32 service_cmd,
                                       post_process_func pp_func)
{
    struct tsse_service_user_data *user_data;
    int ret;

    user_data = kzalloc(sizeof(*user_data), GFP_ATOMIC);
    if (!user_data) {
        kfree(req);
        return -ENOMEM;
    }
    init_completion(&user_data->req_completion);

    /* Assuming all reqs start with tsse_service_req header */
    ((struct tsse_service_req *)req)->hdr.msg_type = IM_MSG_TYPE_REQ;
    ((struct tsse_service_req *)req)->hdr.cookie = (u64)user_data;

    ret = tsse_service_msg_send(handle, service_cmd, req, req_size);
    return service_request_post_process(ret, req, user_data, handle, pp_func);
}

Then refactor functions like tsse_service_open, tsse_service_close, and tsse_services_query_request to use this helper:

int tsse_service_open(tsse_im_service_handle handle)
{
    struct tsse_service_open_req *req;
    int ret;

    ret = tsse_alloc_service_epid(handle);
    if (ret)
        return ret;

    req = kzalloc(sizeof(*req), GFP_ATOMIC);
    if (!req)
        return -ENOMEM;

    /* Populate open specific data */
    tsse_service_instance_cast(handle)->service_opened = 0;
    memcpy(req->service_name, tsse_service_instance_cast(handle)->service_name,
           TSSE_IM_SERVICE_NAME_LEN);

    return tsse_service_common_request((void *)req, sizeof(*req),
                                       handle, TSSE_SERVICE_CMD_OPEN,
                                       tsse_service_open_post_process);
}

This refactoring pinpoints the shared pattern and reduces the repetitive code while keeping functionality intact.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sourcery-ai[bot]
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. 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

@Avenger-285714 Avenger-285714 merged commit 805de0b into deepin-community:linux-6.6.y Feb 24, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants