Skip to content

Commit 08ff323

Browse files
ogerlitzrolandd
authored andcommitted
mlx4: 64-byte CQE/EQE support
ConnectX-3 devices can use either 64- or 32-byte completion queue entries (CQEs) and event queue entries (EQEs). Using 64-byte EQEs/CQEs performs better because each entry is aligned to a complete cacheline. This patch queries the HCA's capabilities, and if it supports 64-byte CQEs and EQES the driver will configure the HW to work in 64-byte mode. The 32-byte vs 64-byte mode is global per HCA and not per CQ or EQ. Since this mode is global, userspace (libmlx4) must be updated to work with the configured CQE size, and guests using SR-IOV virtual functions need to know both EQE and CQE size. In case one of the 64-byte CQE/EQE capabilities is activated, the patch makes sure that older guest drivers that use the QUERY_DEV_FUNC command (e.g as done in mlx4_core of Linux 3.3..3.6) will notice that they need an update to be able to work with the PPF. This is done by changing the returned pf_context_behaviour not to be zero any more. In case none of these capabilities is activated that value remains zero and older guest drivers can run OK. The SRIOV related flow is as follows 1. the PPF does the detection of the new capabilities using QUERY_DEV_CAP command. 2. the PPF activates the new capabilities using INIT_HCA. 3. the VF detects if the PPF activated the capabilities using QUERY_HCA, and if this is the case activates them for itself too. Note that the VF detects that it must be aware to the new PF behaviour using QUERY_FUNC_CAP. Steps 1 and 2 apply also for native mode. User space notification is done through a new field introduced in struct mlx4_ib_ucontext which holds device capabilities for which user space must take action. This changes the binary interface so the ABI towards libmlx4 exposed through uverbs is bumped from 3 to 4 but only when **needed** i.e. only when the driver does use 64-byte CQEs or future device capabilities which must be in sync by user space. This practice allows to work with unmodified libmlx4 on older devices (e.g A0, B0) which don't support 64-byte CQEs. In order to keep existing systems functional when they update to a newer kernel that contains these changes in VF and userspace ABI, a module parameter enable_64b_cqe_eqe must be set to enable 64-byte mode; the default is currently false. Signed-off-by: Eli Cohen <eli@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent f4a75d2 commit 08ff323

15 files changed

Lines changed: 175 additions & 31 deletions

File tree

‎drivers/infiniband/hw/mlx4/cq.c‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void mlx4_ib_cq_event(struct mlx4_cq *cq, enum mlx4_event type)
6666

6767
static void *get_cqe_from_buf(struct mlx4_ib_cq_buf *buf, int n)
6868
{
69-
return mlx4_buf_offset(&buf->buf, n * sizeof (struct mlx4_cqe));
69+
return mlx4_buf_offset(&buf->buf, n * buf->entry_size);
7070
}
7171

7272
static void *get_cqe(struct mlx4_ib_cq *cq, int n)
@@ -77,8 +77,9 @@ static void *get_cqe(struct mlx4_ib_cq *cq, int n)
7777
static void *get_sw_cqe(struct mlx4_ib_cq *cq, int n)
7878
{
7979
struct mlx4_cqe *cqe = get_cqe(cq, n & cq->ibcq.cqe);
80+
struct mlx4_cqe *tcqe = ((cq->buf.entry_size == 64) ? (cqe + 1) : cqe);
8081

81-
return (!!(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK) ^
82+
return (!!(tcqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK) ^
8283
!!(n & (cq->ibcq.cqe + 1))) ? NULL : cqe;
8384
}
8485

@@ -99,12 +100,13 @@ static int mlx4_ib_alloc_cq_buf(struct mlx4_ib_dev *dev, struct mlx4_ib_cq_buf *
99100
{
100101
int err;
101102

102-
err = mlx4_buf_alloc(dev->dev, nent * sizeof(struct mlx4_cqe),
103+
err = mlx4_buf_alloc(dev->dev, nent * dev->dev->caps.cqe_size,
103104
PAGE_SIZE * 2, &buf->buf);
104105

105106
if (err)
106107
goto out;
107108

109+
buf->entry_size = dev->dev->caps.cqe_size;
108110
err = mlx4_mtt_init(dev->dev, buf->buf.npages, buf->buf.page_shift,
109111
&buf->mtt);
110112
if (err)
@@ -120,25 +122,25 @@ static int mlx4_ib_alloc_cq_buf(struct mlx4_ib_dev *dev, struct mlx4_ib_cq_buf *
120122
mlx4_mtt_cleanup(dev->dev, &buf->mtt);
121123

122124
err_buf:
123-
mlx4_buf_free(dev->dev, nent * sizeof(struct mlx4_cqe),
124-
&buf->buf);
125+
mlx4_buf_free(dev->dev, nent * buf->entry_size, &buf->buf);
125126

126127
out:
127128
return err;
128129
}
129130

130131
static void mlx4_ib_free_cq_buf(struct mlx4_ib_dev *dev, struct mlx4_ib_cq_buf *buf, int cqe)
131132
{
132-
mlx4_buf_free(dev->dev, (cqe + 1) * sizeof(struct mlx4_cqe), &buf->buf);
133+
mlx4_buf_free(dev->dev, (cqe + 1) * buf->entry_size, &buf->buf);
133134
}
134135

135136
static int mlx4_ib_get_cq_umem(struct mlx4_ib_dev *dev, struct ib_ucontext *context,
136137
struct mlx4_ib_cq_buf *buf, struct ib_umem **umem,
137138
u64 buf_addr, int cqe)
138139
{
139140
int err;
141+
int cqe_size = dev->dev->caps.cqe_size;
140142

141-
*umem = ib_umem_get(context, buf_addr, cqe * sizeof (struct mlx4_cqe),
143+
*umem = ib_umem_get(context, buf_addr, cqe * cqe_size,
142144
IB_ACCESS_LOCAL_WRITE, 1);
143145
if (IS_ERR(*umem))
144146
return PTR_ERR(*umem);
@@ -331,16 +333,23 @@ static void mlx4_ib_cq_resize_copy_cqes(struct mlx4_ib_cq *cq)
331333
{
332334
struct mlx4_cqe *cqe, *new_cqe;
333335
int i;
336+
int cqe_size = cq->buf.entry_size;
337+
int cqe_inc = cqe_size == 64 ? 1 : 0;
334338

335339
i = cq->mcq.cons_index;
336340
cqe = get_cqe(cq, i & cq->ibcq.cqe);
341+
cqe += cqe_inc;
342+
337343
while ((cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) != MLX4_CQE_OPCODE_RESIZE) {
338344
new_cqe = get_cqe_from_buf(&cq->resize_buf->buf,
339345
(i + 1) & cq->resize_buf->cqe);
340-
memcpy(new_cqe, get_cqe(cq, i & cq->ibcq.cqe), sizeof(struct mlx4_cqe));
346+
memcpy(new_cqe, get_cqe(cq, i & cq->ibcq.cqe), cqe_size);
347+
new_cqe += cqe_inc;
348+
341349
new_cqe->owner_sr_opcode = (cqe->owner_sr_opcode & ~MLX4_CQE_OWNER_MASK) |
342350
(((i + 1) & (cq->resize_buf->cqe + 1)) ? MLX4_CQE_OWNER_MASK : 0);
343351
cqe = get_cqe(cq, ++i & cq->ibcq.cqe);
352+
cqe += cqe_inc;
344353
}
345354
++cq->mcq.cons_index;
346355
}
@@ -438,6 +447,7 @@ int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
438447

439448
out:
440449
mutex_unlock(&cq->resize_mutex);
450+
441451
return err;
442452
}
443453

@@ -586,6 +596,9 @@ static int mlx4_ib_poll_one(struct mlx4_ib_cq *cq,
586596
if (!cqe)
587597
return -EAGAIN;
588598

599+
if (cq->buf.entry_size == 64)
600+
cqe++;
601+
589602
++cq->mcq.cons_index;
590603

591604
/*
@@ -807,6 +820,7 @@ void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq)
807820
int nfreed = 0;
808821
struct mlx4_cqe *cqe, *dest;
809822
u8 owner_bit;
823+
int cqe_inc = cq->buf.entry_size == 64 ? 1 : 0;
810824

811825
/*
812826
* First we need to find the current producer index, so we
@@ -825,12 +839,16 @@ void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq)
825839
*/
826840
while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) {
827841
cqe = get_cqe(cq, prod_index & cq->ibcq.cqe);
842+
cqe += cqe_inc;
843+
828844
if ((be32_to_cpu(cqe->vlan_my_qpn) & MLX4_CQE_QPN_MASK) == qpn) {
829845
if (srq && !(cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK))
830846
mlx4_ib_free_srq_wqe(srq, be16_to_cpu(cqe->wqe_index));
831847
++nfreed;
832848
} else if (nfreed) {
833849
dest = get_cqe(cq, (prod_index + nfreed) & cq->ibcq.cqe);
850+
dest += cqe_inc;
851+
834852
owner_bit = dest->owner_sr_opcode & MLX4_CQE_OWNER_MASK;
835853
memcpy(dest, cqe, sizeof *cqe);
836854
dest->owner_sr_opcode = owner_bit |

‎drivers/infiniband/hw/mlx4/main.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,24 @@ static struct ib_ucontext *mlx4_ib_alloc_ucontext(struct ib_device *ibdev,
563563
{
564564
struct mlx4_ib_dev *dev = to_mdev(ibdev);
565565
struct mlx4_ib_ucontext *context;
566+
struct mlx4_ib_alloc_ucontext_resp_v3 resp_v3;
566567
struct mlx4_ib_alloc_ucontext_resp resp;
567568
int err;
568569

569570
if (!dev->ib_active)
570571
return ERR_PTR(-EAGAIN);
571572

572-
resp.qp_tab_size = dev->dev->caps.num_qps;
573-
resp.bf_reg_size = dev->dev->caps.bf_reg_size;
574-
resp.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
573+
if (ibdev->uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION) {
574+
resp_v3.qp_tab_size = dev->dev->caps.num_qps;
575+
resp_v3.bf_reg_size = dev->dev->caps.bf_reg_size;
576+
resp_v3.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
577+
} else {
578+
resp.dev_caps = dev->dev->caps.userspace_caps;
579+
resp.qp_tab_size = dev->dev->caps.num_qps;
580+
resp.bf_reg_size = dev->dev->caps.bf_reg_size;
581+
resp.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
582+
resp.cqe_size = dev->dev->caps.cqe_size;
583+
}
575584

576585
context = kmalloc(sizeof *context, GFP_KERNEL);
577586
if (!context)
@@ -586,7 +595,11 @@ static struct ib_ucontext *mlx4_ib_alloc_ucontext(struct ib_device *ibdev,
586595
INIT_LIST_HEAD(&context->db_page_list);
587596
mutex_init(&context->db_page_mutex);
588597

589-
err = ib_copy_to_udata(udata, &resp, sizeof resp);
598+
if (ibdev->uverbs_abi_ver == MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION)
599+
err = ib_copy_to_udata(udata, &resp_v3, sizeof(resp_v3));
600+
else
601+
err = ib_copy_to_udata(udata, &resp, sizeof(resp));
602+
590603
if (err) {
591604
mlx4_uar_free(to_mdev(ibdev)->dev, &context->uar);
592605
kfree(context);
@@ -1342,7 +1355,11 @@ static void *mlx4_ib_add(struct mlx4_dev *dev)
13421355
ibdev->ib_dev.num_comp_vectors = dev->caps.num_comp_vectors;
13431356
ibdev->ib_dev.dma_device = &dev->pdev->dev;
13441357

1345-
ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION;
1358+
if (dev->caps.userspace_caps)
1359+
ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION;
1360+
else
1361+
ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION;
1362+
13461363
ibdev->ib_dev.uverbs_cmd_mask =
13471364
(1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
13481365
(1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |

‎drivers/infiniband/hw/mlx4/mlx4_ib.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ struct mlx4_ib_xrcd {
9090
struct mlx4_ib_cq_buf {
9191
struct mlx4_buf buf;
9292
struct mlx4_mtt mtt;
93+
int entry_size;
9394
};
9495

9596
struct mlx4_ib_cq_resize {

‎drivers/infiniband/hw/mlx4/user.h‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
* Increment this value if any changes that break userspace ABI
4141
* compatibility are made.
4242
*/
43-
#define MLX4_IB_UVERBS_ABI_VERSION 3
43+
44+
#define MLX4_IB_UVERBS_NO_DEV_CAPS_ABI_VERSION 3
45+
#define MLX4_IB_UVERBS_ABI_VERSION 4
4446

4547
/*
4648
* Make sure that all structs defined in this file remain laid out so
@@ -50,10 +52,18 @@
5052
* instead.
5153
*/
5254

55+
struct mlx4_ib_alloc_ucontext_resp_v3 {
56+
__u32 qp_tab_size;
57+
__u16 bf_reg_size;
58+
__u16 bf_regs_per_page;
59+
};
60+
5361
struct mlx4_ib_alloc_ucontext_resp {
62+
__u32 dev_caps;
5463
__u32 qp_tab_size;
5564
__u16 bf_reg_size;
5665
__u16 bf_regs_per_page;
66+
__u32 cqe_size;
5767
};
5868

5969
struct mlx4_ib_alloc_pd_resp {

‎drivers/net/ethernet/mellanox/mlx4/cmd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ int mlx4_multi_func_init(struct mlx4_dev *dev)
17551755
spin_lock_init(&s_state->lock);
17561756
}
17571757

1758-
memset(&priv->mfunc.master.cmd_eqe, 0, sizeof(struct mlx4_eqe));
1758+
memset(&priv->mfunc.master.cmd_eqe, 0, dev->caps.eqe_size);
17591759
priv->mfunc.master.cmd_eqe.type = MLX4_EVENT_TYPE_CMD;
17601760
INIT_WORK(&priv->mfunc.master.comm_work,
17611761
mlx4_master_comm_channel);

‎drivers/net/ethernet/mellanox/mlx4/en_cq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ int mlx4_en_create_cq(struct mlx4_en_priv *priv,
5151
int err;
5252

5353
cq->size = entries;
54-
cq->buf_size = cq->size * sizeof(struct mlx4_cqe);
54+
cq->buf_size = cq->size * mdev->dev->caps.cqe_size;
5555

5656
cq->ring = ring;
5757
cq->is_tx = mode;

‎drivers/net/ethernet/mellanox/mlx4/en_netdev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,7 @@ int mlx4_en_init_netdev(struct mlx4_en_dev *mdev, int port,
16001600
goto out;
16011601
}
16021602
priv->rx_ring_num = prof->rx_ring_num;
1603+
priv->cqe_factor = (mdev->dev->caps.cqe_size == 64) ? 1 : 0;
16031604
priv->mac_index = -1;
16041605
priv->msg_enable = MLX4_EN_MSG_LEVEL;
16051606
spin_lock_init(&priv->stats_lock);

‎drivers/net/ethernet/mellanox/mlx4/en_rx.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
566566
struct ethhdr *ethh;
567567
dma_addr_t dma;
568568
u64 s_mac;
569+
int factor = priv->cqe_factor;
569570

570571
if (!priv->port_up)
571572
return 0;
@@ -574,7 +575,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
574575
* descriptor offset can be deduced from the CQE index instead of
575576
* reading 'cqe->index' */
576577
index = cq->mcq.cons_index & ring->size_mask;
577-
cqe = &cq->buf[index];
578+
cqe = &cq->buf[(index << factor) + factor];
578579

579580
/* Process all completed CQEs */
580581
while (XNOR(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK,
@@ -709,7 +710,7 @@ int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int bud
709710

710711
++cq->mcq.cons_index;
711712
index = (cq->mcq.cons_index) & ring->size_mask;
712-
cqe = &cq->buf[index];
713+
cqe = &cq->buf[(index << factor) + factor];
713714
if (++polled == budget) {
714715
/* We are here because we reached the NAPI budget -
715716
* flush only pending LRO sessions */

‎drivers/net/ethernet/mellanox/mlx4/en_tx.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,13 @@ static void mlx4_en_process_tx_cq(struct net_device *dev, struct mlx4_en_cq *cq)
315315
struct mlx4_cqe *buf = cq->buf;
316316
u32 packets = 0;
317317
u32 bytes = 0;
318+
int factor = priv->cqe_factor;
318319

319320
if (!priv->port_up)
320321
return;
321322

322323
index = cons_index & size_mask;
323-
cqe = &buf[index];
324+
cqe = &buf[(index << factor) + factor];
324325
ring_index = ring->cons & size_mask;
325326

326327
/* Process all completed CQEs */
@@ -349,7 +350,7 @@ static void mlx4_en_process_tx_cq(struct net_device *dev, struct mlx4_en_cq *cq)
349350

350351
++cons_index;
351352
index = cons_index & size_mask;
352-
cqe = &buf[index];
353+
cqe = &buf[(index << factor) + factor];
353354
}
354355

355356

‎drivers/net/ethernet/mellanox/mlx4/eq.c‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,21 @@ static void eq_set_ci(struct mlx4_eq *eq, int req_not)
101101
mb();
102102
}
103103

104-
static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry)
104+
static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry, u8 eqe_factor)
105105
{
106-
unsigned long off = (entry & (eq->nent - 1)) * MLX4_EQ_ENTRY_SIZE;
107-
return eq->page_list[off / PAGE_SIZE].buf + off % PAGE_SIZE;
106+
/* (entry & (eq->nent - 1)) gives us a cyclic array */
107+
unsigned long offset = (entry & (eq->nent - 1)) * (MLX4_EQ_ENTRY_SIZE << eqe_factor);
108+
/* CX3 is capable of extending the EQE from 32 to 64 bytes.
109+
* When this feature is enabled, the first (in the lower addresses)
110+
* 32 bytes in the 64 byte EQE are reserved and the next 32 bytes
111+
* contain the legacy EQE information.
112+
*/
113+
return eq->page_list[offset / PAGE_SIZE].buf + (offset + (eqe_factor ? MLX4_EQ_ENTRY_SIZE : 0)) % PAGE_SIZE;
108114
}
109115

110-
static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq)
116+
static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq, u8 eqe_factor)
111117
{
112-
struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index);
118+
struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index, eqe_factor);
113119
return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
114120
}
115121

@@ -177,7 +183,7 @@ static void slave_event(struct mlx4_dev *dev, u8 slave, struct mlx4_eqe *eqe)
177183
return;
178184
}
179185

180-
memcpy(s_eqe, eqe, sizeof(struct mlx4_eqe) - 1);
186+
memcpy(s_eqe, eqe, dev->caps.eqe_size - 1);
181187
s_eqe->slave_id = slave;
182188
/* ensure all information is written before setting the ownersip bit */
183189
wmb();
@@ -441,7 +447,7 @@ static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
441447
int i;
442448
enum slave_port_gen_event gen_event;
443449

444-
while ((eqe = next_eqe_sw(eq))) {
450+
while ((eqe = next_eqe_sw(eq, dev->caps.eqe_factor))) {
445451
/*
446452
* Make sure we read EQ entry contents after we've
447453
* checked the ownership bit.
@@ -864,7 +870,8 @@ static int mlx4_create_eq(struct mlx4_dev *dev, int nent,
864870

865871
eq->dev = dev;
866872
eq->nent = roundup_pow_of_two(max(nent, 2));
867-
npages = PAGE_ALIGN(eq->nent * MLX4_EQ_ENTRY_SIZE) / PAGE_SIZE;
873+
/* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes */
874+
npages = PAGE_ALIGN(eq->nent * (MLX4_EQ_ENTRY_SIZE << dev->caps.eqe_factor)) / PAGE_SIZE;
868875

869876
eq->page_list = kmalloc(npages * sizeof *eq->page_list,
870877
GFP_KERNEL);
@@ -966,8 +973,9 @@ static void mlx4_free_eq(struct mlx4_dev *dev,
966973
struct mlx4_priv *priv = mlx4_priv(dev);
967974
struct mlx4_cmd_mailbox *mailbox;
968975
int err;
969-
int npages = PAGE_ALIGN(MLX4_EQ_ENTRY_SIZE * eq->nent) / PAGE_SIZE;
970976
int i;
977+
/* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes */
978+
int npages = PAGE_ALIGN((MLX4_EQ_ENTRY_SIZE << dev->caps.eqe_factor) * eq->nent) / PAGE_SIZE;
971979

972980
mailbox = mlx4_alloc_cmd_mailbox(dev);
973981
if (IS_ERR(mailbox))

0 commit comments

Comments
 (0)