Linux CXL
 help / color / mirror / Atom feed
From: Ben Cheatham <benjamin.cheatham@amd.com>
To: Dan Williams <dan.j.williams@intel.com>,
	<alejandro.lucero-palau@amd.com>
Cc: Alejandro Lucero <alucerop@amd.com>, <linux-cxl@vger.kernel.org>
Subject: Re: [RFC type cxl initialization 1/2] cxl: add type2 device basic support
Date: Mon, 3 Mar 2025 15:26:24 -0600	[thread overview]
Message-ID: <9de17a5d-3f2d-4417-b45b-78f9d55ae8d1@amd.com> (raw)
In-Reply-To: <67c61643c3cfa_1a77294b9@dwillia2-xfh.jf.intel.com.notmuch>



On 3/3/25 2:51 PM, Dan Williams wrote:
> Ben Cheatham wrote:
>> On 2/20/25 2:00 PM, alejandro.lucero-palau@amd.com wrote:
>>> From: Alejandro Lucero <alucerop@amd.com>
>>>
>>> Differentiate CXL memory expanders (type 3) from CXL device accelerators
>>> (type 2) with a new function for initializing cxl_dev_state and a macro
>>> for helping accel drivers to embed cxl_dev_state inside a private
>>> struct.
>>>
>>> Move structs to include/cxl as the size of the accel driver private
>>> struct embedding cxl_dev_state needs to know the size of this struct.
>>>
>>> Signed-off-by: Alejandro Lucero <alucerop@amd.com>
> [..]
>> diff --git a/drivers/cxl/core/mbox.c b/drivers/cxl/core/mbox.c
>> index 2c49e33851b2..14d7f93e4584 100644
>> --- a/drivers/cxl/core/mbox.c
>> +++ b/drivers/cxl/core/mbox.c
>> @@ -1484,24 +1484,31 @@ int cxl_mailbox_init(struct cxl_mailbox *cxl_mbox, struct device *host)
>>  }
>>  EXPORT_SYMBOL_NS_GPL(cxl_mailbox_init, "CXL");
>>
>> +static void cxl_memdev_state_destroy(void *cxlmds)
>> +{
>> +       kfree(cxlmds);
>> +}
>> +
>>  struct cxl_memdev_state *cxl_memdev_state_create(struct device *dev, u64 serial,
>>                                                  u16 dvsec)
>>  {
>>         struct cxl_memdev_state *mds;
>>         int rc;
>>
>> -       mds = devm_kzalloc(dev, sizeof(*mds), GFP_KERNEL);
>> +       mds = cxl_dev_state_create(dev, serial, dvsec,
>> +                                  CXL_DEVTYPE_CLASSMEM,
>> +                                  struct cxl_memdev_state,
>> +                                  cxlds);
>>         if (!mds) {
>>                 dev_err(dev, "No memory available\n");
>>                 return ERR_PTR(-ENOMEM);
>>         }
>>
>> +       rc = devm_add_action_or_reset(dev, cxl_memdev_state_destroy, mds);
>> +       if (rc)
>> +               return ERR_PTR(rc);
>> +
>>         mutex_init(&mds->event.log_lock);
>> -       mds->cxlds.dev = dev;
>> -       mds->cxlds.reg_map.host = dev;
>> -       mds->cxlds.cxl_mbox.host = dev;
>> -       mds->cxlds.reg_map.resource = CXL_RESOURCE_NONE;
>> -       mds->cxlds.type = CXL_DEVTYPE_CLASSMEM;
>>
>>
>> Looking at the above, it occurs to me that it may be good to either:
>>
>> a) Have a devm version of cxl_dev_state_create() or,
>> b) Have an init macro (in addition) that takes a pointer so that you can use an
>> allocator of your choice
> 
> The caller can always wrap the result with devm_add_action_or_reset().
> No need to force comsumer drivers into an allocation regime.
Sounds good to me, figured I would suggest it more as a convenience option
than anything.

Thanks,
Ben

  reply	other threads:[~2025-03-03 21:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 20:00 [RFC 0/2] type2 cxl initialization alejandro.lucero-palau
2025-02-20 20:00 ` [RFC type cxl initialization 1/2] cxl: add type2 device basic support alejandro.lucero-palau
2025-03-03 20:15   ` Dan Williams
2025-03-04 14:21     ` Alejandro Lucero Palau
2025-03-03 20:39   ` Ben Cheatham
2025-03-03 20:51     ` Dan Williams
2025-03-03 21:26       ` Ben Cheatham [this message]
2025-02-20 20:00 ` [RFC type cxl initialization 2/2] sfc: add cxl support alejandro.lucero-palau
2025-03-03 20:26   ` Dan Williams
2025-03-03 20:38 ` [RFC 0/2] type2 cxl initialization Ben Cheatham
2025-03-03 20:49   ` Dan Williams
2025-03-03 21:26     ` Ben Cheatham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9de17a5d-3f2d-4417-b45b-78f9d55ae8d1@amd.com \
    --to=benjamin.cheatham@amd.com \
    --cc=alejandro.lucero-palau@amd.com \
    --cc=alucerop@amd.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox