Skip to content

Commit 382d174

Browse files
haiyangzkuba-moo
authored andcommitted
net: mana: Add support for page sizes other than 4KB on ARM64
As defined by the MANA Hardware spec, the queue size for DMA is 4KB minimal, and power of 2. And, the HWC queue size has to be exactly 4KB. To support page sizes other than 4KB on ARM64, define the minimal queue size as a macro separately from the PAGE_SIZE, which we always assumed it to be 4KB before supporting ARM64. Also, add MANA specific macros and update code related to size alignment, DMA region calculations, etc. Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com> Reviewed-by: Michael Kelley <mhklinux@outlook.com> Link: https://lore.kernel.org/r/1718655446-6576-1-git-send-email-haiyangz@microsoft.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 2c6a4b9 commit 382d174

File tree

7 files changed

+35
-25
lines changed

7 files changed

+35
-25
lines changed

drivers/net/ethernet/microsoft/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if NET_VENDOR_MICROSOFT
1818
config MICROSOFT_MANA
1919
tristate "Microsoft Azure Network Adapter (MANA) support"
2020
depends on PCI_MSI
21-
depends on X86_64 || (ARM64 && !CPU_BIG_ENDIAN && ARM64_4K_PAGES)
21+
depends on X86_64 || (ARM64 && !CPU_BIG_ENDIAN)
2222
depends on PCI_HYPERV
2323
select AUXILIARY_BUS
2424
select PAGE_POOL

drivers/net/ethernet/microsoft/mana/gdma_main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ int mana_gd_alloc_memory(struct gdma_context *gc, unsigned int length,
182182
dma_addr_t dma_handle;
183183
void *buf;
184184

185-
if (length < PAGE_SIZE || !is_power_of_2(length))
185+
if (length < MANA_PAGE_SIZE || !is_power_of_2(length))
186186
return -EINVAL;
187187

188188
gmi->dev = gc->dev;
@@ -717,7 +717,7 @@ EXPORT_SYMBOL_NS(mana_gd_destroy_dma_region, NET_MANA);
717717
static int mana_gd_create_dma_region(struct gdma_dev *gd,
718718
struct gdma_mem_info *gmi)
719719
{
720-
unsigned int num_page = gmi->length / PAGE_SIZE;
720+
unsigned int num_page = gmi->length / MANA_PAGE_SIZE;
721721
struct gdma_create_dma_region_req *req = NULL;
722722
struct gdma_create_dma_region_resp resp = {};
723723
struct gdma_context *gc = gd->gdma_context;
@@ -727,10 +727,10 @@ static int mana_gd_create_dma_region(struct gdma_dev *gd,
727727
int err;
728728
int i;
729729

730-
if (length < PAGE_SIZE || !is_power_of_2(length))
730+
if (length < MANA_PAGE_SIZE || !is_power_of_2(length))
731731
return -EINVAL;
732732

733-
if (offset_in_page(gmi->virt_addr) != 0)
733+
if (!MANA_PAGE_ALIGNED(gmi->virt_addr))
734734
return -EINVAL;
735735

736736
hwc = gc->hwc.driver_data;
@@ -751,7 +751,7 @@ static int mana_gd_create_dma_region(struct gdma_dev *gd,
751751
req->page_addr_list_len = num_page;
752752

753753
for (i = 0; i < num_page; i++)
754-
req->page_addr_list[i] = gmi->dma_handle + i * PAGE_SIZE;
754+
req->page_addr_list[i] = gmi->dma_handle + i * MANA_PAGE_SIZE;
755755

756756
err = mana_gd_send_request(gc, req_msg_size, req, sizeof(resp), &resp);
757757
if (err)

drivers/net/ethernet/microsoft/mana/hw_channel.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ static int mana_hwc_create_cq(struct hw_channel_context *hwc, u16 q_depth,
362362
int err;
363363

364364
eq_size = roundup_pow_of_two(GDMA_EQE_SIZE * q_depth);
365-
if (eq_size < MINIMUM_SUPPORTED_PAGE_SIZE)
366-
eq_size = MINIMUM_SUPPORTED_PAGE_SIZE;
365+
if (eq_size < MANA_MIN_QSIZE)
366+
eq_size = MANA_MIN_QSIZE;
367367

368368
cq_size = roundup_pow_of_two(GDMA_CQE_SIZE * q_depth);
369-
if (cq_size < MINIMUM_SUPPORTED_PAGE_SIZE)
370-
cq_size = MINIMUM_SUPPORTED_PAGE_SIZE;
369+
if (cq_size < MANA_MIN_QSIZE)
370+
cq_size = MANA_MIN_QSIZE;
371371

372372
hwc_cq = kzalloc(sizeof(*hwc_cq), GFP_KERNEL);
373373
if (!hwc_cq)
@@ -429,7 +429,7 @@ static int mana_hwc_alloc_dma_buf(struct hw_channel_context *hwc, u16 q_depth,
429429

430430
dma_buf->num_reqs = q_depth;
431431

432-
buf_size = PAGE_ALIGN(q_depth * max_msg_size);
432+
buf_size = MANA_PAGE_ALIGN(q_depth * max_msg_size);
433433

434434
gmi = &dma_buf->mem_info;
435435
err = mana_gd_alloc_memory(gc, buf_size, gmi);
@@ -497,8 +497,8 @@ static int mana_hwc_create_wq(struct hw_channel_context *hwc,
497497
else
498498
queue_size = roundup_pow_of_two(GDMA_MAX_SQE_SIZE * q_depth);
499499

500-
if (queue_size < MINIMUM_SUPPORTED_PAGE_SIZE)
501-
queue_size = MINIMUM_SUPPORTED_PAGE_SIZE;
500+
if (queue_size < MANA_MIN_QSIZE)
501+
queue_size = MANA_MIN_QSIZE;
502502

503503
hwc_wq = kzalloc(sizeof(*hwc_wq), GFP_KERNEL);
504504
if (!hwc_wq)

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,10 +1904,10 @@ static int mana_create_txq(struct mana_port_context *apc,
19041904
* to prevent overflow.
19051905
*/
19061906
txq_size = MAX_SEND_BUFFERS_PER_QUEUE * 32;
1907-
BUILD_BUG_ON(!PAGE_ALIGNED(txq_size));
1907+
BUILD_BUG_ON(!MANA_PAGE_ALIGNED(txq_size));
19081908

19091909
cq_size = MAX_SEND_BUFFERS_PER_QUEUE * COMP_ENTRY_SIZE;
1910-
cq_size = PAGE_ALIGN(cq_size);
1910+
cq_size = MANA_PAGE_ALIGN(cq_size);
19111911

19121912
gc = gd->gdma_context;
19131913

@@ -2204,8 +2204,8 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc,
22042204
if (err)
22052205
goto out;
22062206

2207-
rq_size = PAGE_ALIGN(rq_size);
2208-
cq_size = PAGE_ALIGN(cq_size);
2207+
rq_size = MANA_PAGE_ALIGN(rq_size);
2208+
cq_size = MANA_PAGE_ALIGN(cq_size);
22092209

22102210
/* Create RQ */
22112211
memset(&spec, 0, sizeof(spec));

drivers/net/ethernet/microsoft/mana/shm_channel.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/io.h>
77
#include <linux/mm.h>
88

9+
#include <net/mana/gdma.h>
910
#include <net/mana/shm_channel.h>
1011

1112
#define PAGE_FRAME_L48_WIDTH_BYTES 6
@@ -155,8 +156,8 @@ int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
155156
return err;
156157
}
157158

158-
if (!PAGE_ALIGNED(eq_addr) || !PAGE_ALIGNED(cq_addr) ||
159-
!PAGE_ALIGNED(rq_addr) || !PAGE_ALIGNED(sq_addr))
159+
if (!MANA_PAGE_ALIGNED(eq_addr) || !MANA_PAGE_ALIGNED(cq_addr) ||
160+
!MANA_PAGE_ALIGNED(rq_addr) || !MANA_PAGE_ALIGNED(sq_addr))
160161
return -EINVAL;
161162

162163
if ((eq_msix_index & VECTOR_MASK) != eq_msix_index)
@@ -183,31 +184,31 @@ int mana_smc_setup_hwc(struct shm_channel *sc, bool reset_vf, u64 eq_addr,
183184

184185
/* EQ addr: low 48 bits of frame address */
185186
shmem = (u64 *)ptr;
186-
frame_addr = PHYS_PFN(eq_addr);
187+
frame_addr = MANA_PFN(eq_addr);
187188
*shmem = frame_addr & PAGE_FRAME_L48_MASK;
188189
all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
189190
(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
190191
ptr += PAGE_FRAME_L48_WIDTH_BYTES;
191192

192193
/* CQ addr: low 48 bits of frame address */
193194
shmem = (u64 *)ptr;
194-
frame_addr = PHYS_PFN(cq_addr);
195+
frame_addr = MANA_PFN(cq_addr);
195196
*shmem = frame_addr & PAGE_FRAME_L48_MASK;
196197
all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
197198
(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
198199
ptr += PAGE_FRAME_L48_WIDTH_BYTES;
199200

200201
/* RQ addr: low 48 bits of frame address */
201202
shmem = (u64 *)ptr;
202-
frame_addr = PHYS_PFN(rq_addr);
203+
frame_addr = MANA_PFN(rq_addr);
203204
*shmem = frame_addr & PAGE_FRAME_L48_MASK;
204205
all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
205206
(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);
206207
ptr += PAGE_FRAME_L48_WIDTH_BYTES;
207208

208209
/* SQ addr: low 48 bits of frame address */
209210
shmem = (u64 *)ptr;
210-
frame_addr = PHYS_PFN(sq_addr);
211+
frame_addr = MANA_PFN(sq_addr);
211212
*shmem = frame_addr & PAGE_FRAME_L48_MASK;
212213
all_addr_h4bits |= (frame_addr >> PAGE_FRAME_L48_WIDTH_BITS) <<
213214
(frame_addr_seq++ * PAGE_FRAME_H4_WIDTH_BITS);

include/net/mana/gdma.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ struct gdma_dev {
224224
struct auxiliary_device *adev;
225225
};
226226

227-
#define MINIMUM_SUPPORTED_PAGE_SIZE PAGE_SIZE
227+
/* MANA_PAGE_SIZE is the DMA unit */
228+
#define MANA_PAGE_SHIFT 12
229+
#define MANA_PAGE_SIZE BIT(MANA_PAGE_SHIFT)
230+
#define MANA_PAGE_ALIGN(x) ALIGN((x), MANA_PAGE_SIZE)
231+
#define MANA_PAGE_ALIGNED(addr) IS_ALIGNED((unsigned long)(addr), MANA_PAGE_SIZE)
232+
#define MANA_PFN(a) ((a) >> MANA_PAGE_SHIFT)
233+
234+
/* Required by HW */
235+
#define MANA_MIN_QSIZE MANA_PAGE_SIZE
228236

229237
#define GDMA_CQE_SIZE 64
230238
#define GDMA_EQE_SIZE 16

include/net/mana/mana.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ enum TRI_STATE {
4242

4343
#define MAX_SEND_BUFFERS_PER_QUEUE 256
4444

45-
#define EQ_SIZE (8 * PAGE_SIZE)
45+
#define EQ_SIZE (8 * MANA_PAGE_SIZE)
46+
4647
#define LOG2_EQ_THROTTLE 3
4748

4849
#define MAX_PORTS_IN_MANA_DEV 256

0 commit comments

Comments
 (0)