Skip to content

Driver supports HRDT trustraid D3100s controllers. #917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Tech-Hurray
Copy link
Contributor

@Tech-Hurray Tech-Hurray commented Jul 4, 2025

This driver is to support HRDT trustraid D3100s controllers.

Summary by Sourcery

Add support for HRDT TrustRaid D3100s controllers by introducing a new PQI-based SCSI driver under drivers/scsi/trustraid and enabling it via CONFIG_SCSI_TRUSTRAID.

New Features:

  • Implement a new trustraid driver for Microchip PQI-based storage controllers targeting HRDT TrustRaid D3100s.
  • Include a trustrlib wrapper library to handle platform and CPU-specific I/O operations (Loongson, SW64).

Enhancements:

  • Split smartpqi core into dedicated modules for legacy SIS interface (smartpqi_sis) and SAS transport (smartpqi_sas_transport) with full admin/operational queue management.
  • Integrate detailed PQI specification support including register definitions, queue pairing, error handling, and SCSI command mapping.

Build:

  • Add drivers/scsi/trustraid directory to the build system and expose CONFIG_SCSI_TRUSTRAID in Kconfig.
  • Update drivers/scsi/Makefile to compile trustraid modules when enabled.

Copy link

sourcery-ai bot commented Jul 4, 2025

Reviewer's Guide

This PR introduces a new TrustRaid SCSI driver under drivers/scsi/trustraid, implementing smartpqi core logic with SIS and SAS transport layers, integrating the trustrlib support library, updating build scripts and Kconfig to enable CONFIG_SCSI_TRUSTRAID, and registering HRDT TrustRaid D3100s PCI IDs.

ER diagram for TrustRaid driver queue and request structures

erDiagram
    PQI_CTRL_INFO ||--o{ PQI_QUEUE_GROUP : has
    PQI_QUEUE_GROUP ||--o{ PQI_IO_REQUEST : manages
    PQI_QUEUE_GROUP ||--|| TRUSTRLIB_QUEUE_GROUP : "trustrlib_data"
    PQI_IO_REQUEST ||--|| TRUSTRLIB_IO_REQUEST : "trustrlib_data"
    PQI_CTRL_INFO ||--|| TRUSTRLIB_CTRL_INFO : "trustrlib_data"
    TRUSTRLIB_CTRL_INFO ||--|| TRUSTRLIB_TEMPLATE : "template"
Loading

Class diagram for new TrustRaid driver core types

classDiagram
    class pqi_ctrl_info {
        +unsigned int ctrl_id
        +struct pci_dev *pci_dev
        +struct pqi_ctrl_registers __iomem *registers
        +struct pqi_device_registers __iomem *pqi_registers
        +struct pqi_admin_queues admin_queues
        +struct pqi_queue_group queue_groups[PQI_MAX_QUEUE_GROUPS]
        +struct pqi_event_queue event_queue
        +struct trustrlib_ops *trustrlib
        +void *trustrlib_data
        ...
    }
    class pqi_queue_group {
        +struct pqi_ctrl_info *ctrl_info
        +void *iq_element_array[2]
        +void *oq_element_array
        +struct trustrlib_queue_group *trustrlib_data
        ...
    }
    class trustrlib_ctrl_info {
        +struct pqi_ctrl_info *ctrl_info
        +struct timer_list poll_complete_queue_timer
        +struct work_struct check_iq_hang_work
        +struct pqi_queue_group *check_queue_group
        +struct delayed_work recheck_iq_hang_work
        +struct pqi_queue_group *recheck_queue_group
        +struct trustrlib_template *template
    }
    class trustrlib_queue_group {
        +atomic_t inflight_num
        +spinlock_t complete_lock
        +u8 iq_hanging[2]
    }
    class trustrlib_io_request {
        +spinlock_t lock
        +atomic_t in_interrupt_or_timedout
        +u8 timedout_count
    }
    class trustrlib_ops {
        +set_aio_request_id(void*, void*)
        +set_aio_r1_request_id(void*, void*)
        +set_aio_r56_request_id(void*, void*)
        +set_raid_request_id(void*, void*)
        +get_and_update_io_request(void*, void*)
        +free_io_request(void*)
        +eh_timed_out(void*)
        +reset_io_request_index(void*)
        +process_io_intr(void*, void*)
        +set_sg_table_size(void*, void*)
        +alloc_hw_queue(void*, u16)
        +start_io(void*, void*, int)
        +init_ctrl(trustrlib_template*, void*, void*)
        +uninit_ctrl(void*)
        +init_works(void*)
        +uninit_works(void*)
        +init_queue_group(void*)
        +init_io_request(void*)
        +uninit_queue_group(void*)
        +uninit_io_request(void*)
    }
    pqi_ctrl_info --> pqi_queue_group : has many
    pqi_ctrl_info --> trustrlib_ops : uses
    pqi_ctrl_info --> trustrlib_ctrl_info : trustrlib_data
    pqi_queue_group --> trustrlib_queue_group : trustrlib_data
    trustrlib_ctrl_info --> trustrlib_template : template
Loading

File-Level Changes

Change Details Files
Add TrustRaid driver modules and headers
  • Create smartpqi core public API in smartpqi.h
  • Implement legacy SIS interface in smartpqi_sis.c with sis_* commands
  • Implement SAS transport functions in smartpqi_sas_transport.c
  • Integrate trustrlib support in trustrlib.c and trustrlib.h
  • Provide SIS-specific header smartpqi_sis.h
  • Add top-level Makefile and Kconfig for the trustraid directory
drivers/scsi/trustraid/smartpqi.h
drivers/scsi/trustraid/smartpqi_sis.c
drivers/scsi/trustraid/smartpqi_sas_transport.c
drivers/scsi/trustraid/trustrlib.c
drivers/scsi/trustraid/trustrlib.h
drivers/scsi/trustraid/smartpqi_sis.h
drivers/scsi/trustraid/Makefile
drivers/scsi/trustraid/Kconfig
Enable build and configuration for the new driver
  • Add obj-$(CONFIG_SCSI_TRUSTRAID) entry to drivers/scsi/Makefile
  • Declare CONFIG_SCSI_TRUSTRAID option in drivers/scsi/Kconfig
drivers/scsi/Makefile
drivers/scsi/Kconfig
Register HRDT TrustRaid D3100s PCI IDs
  • Define PCI_VENDOR_ID_HRDT in smartpqi.h
  • Extend trustrlib_match_id in trustrlib.c to accept HRDT vendor/device
drivers/scsi/trustraid/smartpqi.h
drivers/scsi/trustraid/trustrlib.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!

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

Hi @Tech-Hurray. Thanks for your PR. 😃

@deepin-ci-robot
Copy link

Hi @Tech-Hurray. 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.

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.

@Avenger-285714
Copy link
Collaborator

/ok-to-test

@deepin-ci-robot
Copy link

deepin pr auto review

Based on the code in the project repository provided by the user and the user's requirements, generate new code or modify existing code. The output format is:
###PATH:{PATH}
{CODE}
Question:
请将代码中的pqi_scsi_queue_command函数中的scsi_bufflen(scmd)替换为blk_rq_bytes(PQI_SCSI_REQUEST(scmd))

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 @Tech-Hurray - I've reviewed your changes and found some issues that need to be addressed.

  • smartpqi.h is extremely large; consider splitting it into focused headers (e.g. register definitions, queue structures, and function prototypes) to improve readability and maintainability.
  • The many PCI_VENDOR_ID_* macros added here duplicate definitions elsewhere; centralizing vendor ID constants in a common header would reduce duplication and simplify future updates.
  • trustrlib_match_cpu hard-codes support for specific Loongson and SW64 models; consider adding a fallback or override mechanism so unsupported CPUs fail gracefully rather than silently blocking the driver.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- smartpqi.h is extremely large; consider splitting it into focused headers (e.g. register definitions, queue structures, and function prototypes) to improve readability and maintainability.
- The many PCI_VENDOR_ID_* macros added here duplicate definitions elsewhere; centralizing vendor ID constants in a common header would reduce duplication and simplify future updates.
- trustrlib_match_cpu hard-codes support for specific Loongson and SW64 models; consider adding a fallback or override mechanism so unsupported CPUs fail gracefully rather than silently blocking the driver.

## Individual Comments

### Comment 1
<location> `drivers/scsi/trustraid/trustrlib.c:430` </location>
<code_context>
+			data_direction);
+}
+
+static int pqi_build_inquiry_raid_path_request(struct pqi_ctrl_info *ctrl_info,
+	struct pqi_raid_path_request *request,
+	u8 *scsi3addr, void *buffer, size_t buffer_length)
</code_context>

<issue_to_address>
Unused commented-out CDB fields.

If cdb[1] and cdb[2] are not needed, please remove the commented-out lines to keep the codebase clean.
</issue_to_address>

### Comment 2
<location> `drivers/scsi/trustraid/trustrlib.c:961` </location>
<code_context>
+	return NULL;
+}
+
+static inline bool list_on_list(struct list_head *entry)
+{
+	return !(entry->next == NULL || entry->next == LIST_POISON1 || entry->next == entry);
</code_context>

<issue_to_address>
list_on_list() may not be reliable for all list_head states.

The current checks may miss some corrupted list states. Using kernel helpers like list_empty() is recommended for more robust detection.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
static inline bool list_on_list(struct list_head *entry)
{
	return !(entry->next == NULL || entry->next == LIST_POISON1 || entry->next == entry);
}
=======
static inline bool list_on_list(struct list_head *entry)
{
	return !list_empty(entry);
}
>>>>>>> REPLACE

</suggested_fix>

### Comment 3
<location> `drivers/scsi/trustraid/trustrlib.c:1046` </location>
<code_context>
+	return 0;
+}
+
+static void pqi_list_del(struct list_head *entry)
+{
+	list_del(entry);
</code_context>

<issue_to_address>
Redundant pointer nullification after list_del.

Setting entry->next and entry->prev to NULL after list_del is unnecessary and could mask issues if the list_head is reused. Remove this, or use list_del_init if re-initialization is required.
</issue_to_address>

### Comment 4
<location> `drivers/scsi/trustraid/smartpqi_init.c:1212` </location>
<code_context>
+	return rc;
+}
+
+static int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **buffer)
+{
+	int rc;
</code_context>

<issue_to_address>
Possible memory leak if rpl_16byte_wwid_list allocation fails.

Free rpl_list before returning -ENOMEM to prevent a memory leak in this error path.
</issue_to_address>

### Comment 5
<location> `drivers/scsi/trustraid/smartpqi_init.c:1342` </location>
<code_context>
+	device->lun = lun;
+}
+
+static void pqi_assign_bus_target_lun(struct pqi_scsi_dev *device)
+{
+	u8 *scsi3addr;
</code_context>

<issue_to_address>
Potential for uninitialized bus/target/lun values for physical devices.

Since bus/target/lun are set to default values and assignment is deferred, verify that all usages for physical devices account for this and do not rely on these fields being initialized earlier.
</issue_to_address>

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.

data_direction);
}

static int pqi_build_inquiry_raid_path_request(struct pqi_ctrl_info *ctrl_info,
Copy link

Choose a reason for hiding this comment

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

nitpick: Unused commented-out CDB fields.

If cdb[1] and cdb[2] are not needed, please remove the commented-out lines to keep the codebase clean.

Comment on lines 961 to 959
static inline bool list_on_list(struct list_head *entry)
{
return !(entry->next == NULL || entry->next == LIST_POISON1 || entry->next == entry);
}
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): list_on_list() may not be reliable for all list_head states.

The current checks may miss some corrupted list states. Using kernel helpers like list_empty() is recommended for more robust detection.

Suggested change
static inline bool list_on_list(struct list_head *entry)
{
return !(entry->next == NULL || entry->next == LIST_POISON1 || entry->next == entry);
}
static inline bool list_on_list(struct list_head *entry)
{
return !list_empty(entry);
}

return 0;
}

static void pqi_list_del(struct list_head *entry)
Copy link

Choose a reason for hiding this comment

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

nitpick: Redundant pointer nullification after list_del.

Setting entry->next and entry->prev to NULL after list_del is unnecessary and could mask issues if the list_head is reused. Remove this, or use list_del_init if re-initialization is required.

return rc;
}

static int pqi_report_phys_luns(struct pqi_ctrl_info *ctrl_info, void **buffer)
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Possible memory leak if rpl_16byte_wwid_list allocation fails.

Free rpl_list before returning -ENOMEM to prevent a memory leak in this error path.

device->lun = lun;
}

static void pqi_assign_bus_target_lun(struct pqi_scsi_dev *device)
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): Potential for uninitialized bus/target/lun values for physical devices.

Since bus/target/lun are set to default values and assignment is deferred, verify that all usages for physical devices account for this and do not rely on these fields being initialized earlier.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds native support for HRDT TrustRaid D3100s controllers via a new PQI-based SCSI driver under drivers/scsi/trustraid.

  • Introduces a trustrlib wrapper library for CPU/platform-specific I/O operations.
  • Splits the smartpqi core into SIS legacy and SAS transport modules.
  • Updates the build system (Makefile/Kconfig) to enable CONFIG_SCSI_TRUSTRAID.

Reviewed Changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
drivers/scsi/trustraid/trustrlib.h Define the trustrlib API, templates, ops, and structs
drivers/scsi/trustraid/trustrlib.c Implement trustrlib routines, IO processing, cpu match
drivers/scsi/trustraid/smartpqi_sis.h Declare legacy SIS interface functions
drivers/scsi/trustraid/smartpqi_sis.c Implement SIS commands and controller interactions
drivers/scsi/trustraid/smartpqi_sas_transport.c Implement SAS transport layer and BSG SMP handling
drivers/scsi/trustraid/smartpqi.h Add core PQI definitions, structures, and templates
drivers/scsi/trustraid/Makefile Build rules for trustraid modules
drivers/scsi/trustraid/Kconfig Add config entry for SCSI_TRUSTRAID
drivers/scsi/Makefile Integrate trustraid into the SCSI build
drivers/scsi/Kconfig Include trustraid Kconfig in the SCSI subsystem

void *context)
{
struct completion *waiting = context;
printk(KERN_INFO "pqi_check_inquiry_complete: io_request %p context %p\n", io_request, context);
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Avoid using printk for logging in driver code; use dev_info() or dev_dbg() with the device context for proper logging levels and rate limiting.

Copilot uses AI. Check for mistakes.

return;
if (inflight_num < 0) {
dev_err(&ctrl_info->pci_dev->dev,
"pqi_poll_complete_queue: unexcepted inflight_num %d, queue_group %p\n",
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Correct the typo in the log message: "unexcepted" should be "unexpected".

Suggested change
"pqi_poll_complete_queue: unexcepted inflight_num %d, queue_group %p\n",
"pqi_poll_complete_queue: unexpected inflight_num %d, queue_group %p\n",

Copilot uses AI. Check for mistakes.

@@ -0,0 +1,1229 @@
#include <linux/module.h>
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

Add MODULE_LICENSE("GPL"); (and optionally MODULE_AUTHOR/MODULE_DESCRIPTION) to declare the license and prevent kernel taint warnings.

Copilot uses AI. Check for mistakes.

Comment on lines 1 to 2
#ifndef _TRUSTRLIB_IMPL_H_
#define _TRUSTRLIB_IMPL_H_
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

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

[nitpick] The include guard macro name (TRUSTRLIB_IMPL_H) doesn't match the header filename; consider renaming it to TRUSTRLIB_H for clarity and consistency.

Suggested change
#ifndef _TRUSTRLIB_IMPL_H_
#define _TRUSTRLIB_IMPL_H_
#ifndef _TRUSTRLIB_H_
#define _TRUSTRLIB_H_

Copilot uses AI. Check for mistakes.

@Avenger-285714
Copy link
Collaborator

/lgtm

@Avenger-285714
Copy link
Collaborator

/approve

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Avenger-285714

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

The pull request process is described here

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 9c4a244 into deepin-community:linux-6.6.y Jul 6, 2025
9 checks passed
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.

3 participants