From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29B1D33D4EE for ; Thu, 16 Apr 2026 17:57:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776362268; cv=none; b=FyLYtgM/e8RoOTlhAeWi5s9ZtuM649hqYdBsZXTTEgvFGVcHnsQ8oMfrc+3OlDN6rGgqmkQHDs9FiKhJqF7x4mR+88E6vO+N86h+beYAKqyU/tq9xZvgIVTUcOjO6moOVnk1zoXLJaCwrps4gAoeo4mni+ZVIDuCyfDOgrdNe44= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776362268; c=relaxed/simple; bh=V32wPKQw2sdeCcZwqo43xUBPb9zerB8+wnHt21LbQN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PZXNclwat/DPrR0WdXP0LQ4jg9MqzaB28P1qwh2jt3lemPcZbnoqlFLMoANryFV/19GibYWBEr7eAsDQZgPs00qVcoymSQSIqOqOnvFSGV6C71BfzmfKUI8se3BZpOSJmUgRInJrD7yLPsY08u6NQig/xHAvgt6gH++W6CiDiyM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=F3vtjfyR; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="F3vtjfyR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1776362266; x=1807898266; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=V32wPKQw2sdeCcZwqo43xUBPb9zerB8+wnHt21LbQN4=; b=F3vtjfyRBT+iouXmYIbVF5op2O1RLrvv8bs8LaVf0VKnV6MhNMMmoIgd D8kacPoLh9zPn7fC/ekFZsVby5BVhD8WvU7mr7Bs6ppVgqeerF6MMoXRz GUZHm/g23QOf3le7O5eqmkBKrvRmuIhjokgOC94gkocY9abcblxcgkLdQ 14f0fV/mDeheVig97MKGZ7DDWYTM8qUnh9Cpp5X/Q4y1MO+35AD0mh796 prOvMMkAyapQONEjv4rdgCLqcIDl3YDkMU8qeex50eR0YF3wHkcywlYXV CMZJRoS67RGx3JF5qY9kV4CUtts4L2rgmDVXjHXW9L50McK0wzUTGW39B A==; X-CSE-ConnectionGUID: H/QbI9xYSUivcF7FBYEDLA== X-CSE-MsgGUID: ByIaFKMCS4K9hat9aXn1GA== X-IronPort-AV: E=McAfee;i="6800,10657,11761"; a="94778426" X-IronPort-AV: E=Sophos;i="6.23,181,1770624000"; d="scan'208";a="94778426" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2026 10:57:46 -0700 X-CSE-ConnectionGUID: RSd6PmjzREqr2Hu/0SFdKw== X-CSE-MsgGUID: ycHRl2cKSHOhrAmf615lEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,181,1770624000"; d="scan'208";a="235784666" Received: from abityuts-desk.ger.corp.intel.com (HELO ahunter6-desk) ([10.245.244.222]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2026 10:57:45 -0700 From: Adrian Hunter To: alexandre.belloni@bootlin.com Cc: Frank.Li@nxp.com, linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 15/16] i3c: mipi-i3c-hci: Consolidate DMA ring allocation Date: Thu, 16 Apr 2026 20:57:03 +0300 Message-ID: <20260416175704.41217-16-adrian.hunter@intel.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260416175704.41217-1-adrian.hunter@intel.com> References: <20260416175704.41217-1-adrian.hunter@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Content-Transfer-Encoding: 8bit dma_alloc_coherent() allocates memory in whole pages, which can waste space when command and response queues are allocated separately. Allocate the DMA command and response queues from a single coherent allocation instead, while preserving the required 4-byte alignment. This reduces memory overhead without changing behavior. Signed-off-by: Adrian Hunter --- drivers/i3c/master/mipi-i3c-hci/dma.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/drivers/i3c/master/mipi-i3c-hci/dma.c b/drivers/i3c/master/mipi-i3c-hci/dma.c index 527c282e0734..b06405a9aa7b 100644 --- a/drivers/i3c/master/mipi-i3c-hci/dma.c +++ b/drivers/i3c/master/mipi-i3c-hci/dma.c @@ -186,14 +186,12 @@ static void hci_dma_free(void *data) for (int i = 0; i < rings->total; i++) { rh = &rings->headers[i]; - if (rh->xfer) - dma_free_coherent(rings->sysdev, - rh->xfer_struct_sz * rh->xfer_entries, - rh->xfer, rh->xfer_dma); - if (rh->resp) - dma_free_coherent(rings->sysdev, - rh->resp_struct_sz * rh->xfer_entries, - rh->resp, rh->resp_dma); + if (rh->xfer) { + size_t sz = round_up(rh->xfer_struct_sz * rh->xfer_entries, 4); + + sz += rh->resp_struct_sz * rh->xfer_entries; + dma_free_coherent(rings->sysdev, sz, rh->xfer, rh->xfer_dma); + } kfree(rh->src_xfers); if (rh->ibi_status) dma_free_coherent(rings->sysdev, @@ -359,17 +357,17 @@ static int hci_dma_init(struct i3c_hci *hci) dev_dbg(&hci->master.dev, "xfer_struct_sz = %d, resp_struct_sz = %d", rh->xfer_struct_sz, rh->resp_struct_sz); - xfers_sz = rh->xfer_struct_sz * rh->xfer_entries; + xfers_sz = round_up(rh->xfer_struct_sz * rh->xfer_entries, 4); resps_sz = rh->resp_struct_sz * rh->xfer_entries; - rh->xfer = dma_alloc_coherent(rings->sysdev, xfers_sz, + rh->xfer = dma_alloc_coherent(rings->sysdev, xfers_sz + resps_sz, &rh->xfer_dma, GFP_KERNEL); - rh->resp = dma_alloc_coherent(rings->sysdev, resps_sz, - &rh->resp_dma, GFP_KERNEL); + rh->resp = rh->xfer + xfers_sz; + rh->resp_dma = rh->xfer_dma + xfers_sz; rh->src_xfers = kzalloc_objs(*rh->src_xfers, rh->xfer_entries); ret = -ENOMEM; - if (!rh->xfer || !rh->resp || !rh->src_xfers) + if (!rh->xfer || !rh->src_xfers) goto err_out; /* IBIs */ -- 2.51.0