Skip to content

Commit 370caa5

Browse files
grzegorz-andrejczukjgunthorpe
authored andcommitted
IB/hfi1: Add rx functions for dummy netdev
This patch adds the rx functions for the dummy netdev: - Functions to allocate/free the dummy netdev. - Functions to allocate/free receiving contexts for the netdev. - Functions to initialize/de-initialize the receive queue. - Functions to enable/disable the receive queue. Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Mike Marciniszyn <[email protected]> Reviewed-by: Dennis Dalessandro <[email protected]> Signed-off-by: Sadanand Warrier <[email protected]> Signed-off-by: Grzegorz Andrejczuk <[email protected]> Signed-off-by: Kaike Wan <[email protected]> Signed-off-by: Dennis Dalessandro <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 0bae02d commit 370caa5

File tree

5 files changed

+414
-2
lines changed

5 files changed

+414
-2
lines changed

drivers/infiniband/hw/hfi1/ipoib.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ int hfi1_ipoib_send_dma(struct net_device *dev,
154154
int hfi1_ipoib_txreq_init(struct hfi1_ipoib_dev_priv *priv);
155155
void hfi1_ipoib_txreq_deinit(struct hfi1_ipoib_dev_priv *priv);
156156

157+
int hfi1_ipoib_rxq_init(struct net_device *dev);
158+
void hfi1_ipoib_rxq_deinit(struct net_device *dev);
159+
157160
void hfi1_ipoib_napi_tx_enable(struct net_device *dev);
158161
void hfi1_ipoib_napi_tx_disable(struct net_device *dev);
159162

drivers/infiniband/hw/hfi1/ipoib_main.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@ static u32 qpn_from_mac(u8 *mac_arr)
1919
static int hfi1_ipoib_dev_init(struct net_device *dev)
2020
{
2121
struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
22+
int ret;
2223

2324
priv->netstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
2425

25-
return priv->netdev_ops->ndo_init(dev);
26+
ret = priv->netdev_ops->ndo_init(dev);
27+
if (ret)
28+
return ret;
29+
30+
ret = hfi1_netdev_add_data(priv->dd,
31+
qpn_from_mac(priv->netdev->dev_addr),
32+
dev);
33+
if (ret < 0) {
34+
priv->netdev_ops->ndo_uninit(dev);
35+
return ret;
36+
}
37+
38+
return 0;
2639
}
2740

2841
static void hfi1_ipoib_dev_uninit(struct net_device *dev)
2942
{
3043
struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
3144

45+
hfi1_netdev_remove_data(priv->dd, qpn_from_mac(priv->netdev->dev_addr));
46+
3247
priv->netdev_ops->ndo_uninit(dev);
3348
}
3449

@@ -55,6 +70,7 @@ static int hfi1_ipoib_dev_open(struct net_device *dev)
5570
priv->qp = qp;
5671
rcu_read_unlock();
5772

73+
hfi1_netdev_enable_queues(priv->dd);
5874
hfi1_ipoib_napi_tx_enable(dev);
5975
}
6076

@@ -69,6 +85,7 @@ static int hfi1_ipoib_dev_stop(struct net_device *dev)
6985
return 0;
7086

7187
hfi1_ipoib_napi_tx_disable(dev);
88+
hfi1_netdev_disable_queues(priv->dd);
7289

7390
rvt_put_qp(priv->qp);
7491
priv->qp = NULL;
@@ -195,6 +212,7 @@ static void hfi1_ipoib_netdev_dtor(struct net_device *dev)
195212
struct hfi1_ipoib_dev_priv *priv = hfi1_ipoib_priv(dev);
196213

197214
hfi1_ipoib_txreq_deinit(priv);
215+
hfi1_ipoib_rxq_deinit(priv->netdev);
198216

199217
free_percpu(priv->netstats);
200218
}
@@ -252,6 +270,13 @@ static int hfi1_ipoib_setup_rn(struct ib_device *device,
252270
return rc;
253271
}
254272

273+
rc = hfi1_ipoib_rxq_init(netdev);
274+
if (rc) {
275+
dd_dev_err(dd, "IPoIB netdev RX init - failed(%d)\n", rc);
276+
hfi1_ipoib_free_rdma_netdev(netdev);
277+
return rc;
278+
}
279+
255280
netdev->priv_destructor = hfi1_ipoib_netdev_dtor;
256281
netdev->needs_free_netdev = true;
257282

@@ -268,14 +293,15 @@ int hfi1_ipoib_rn_get_params(struct ib_device *device,
268293
if (type != RDMA_NETDEV_IPOIB)
269294
return -EOPNOTSUPP;
270295

271-
if (!HFI1_CAP_IS_KSET(AIP))
296+
if (!HFI1_CAP_IS_KSET(AIP) || !dd->num_netdev_contexts)
272297
return -EOPNOTSUPP;
273298

274299
if (!port_num || port_num > dd->num_pports)
275300
return -EINVAL;
276301

277302
params->sizeof_priv = sizeof(struct hfi1_ipoib_rdma_netdev);
278303
params->txqs = dd->num_sdma;
304+
params->rxqs = dd->num_netdev_contexts;
279305
params->param = NULL;
280306
params->initialize_rdma_netdev = hfi1_ipoib_setup_rn;
281307

drivers/infiniband/hw/hfi1/ipoib_rx.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,19 @@ struct sk_buff *hfi1_ipoib_prepare_skb(struct hfi1_netdev_rxq *rxq,
6969

7070
return skb;
7171
}
72+
73+
int hfi1_ipoib_rxq_init(struct net_device *netdev)
74+
{
75+
struct hfi1_ipoib_dev_priv *ipoib_priv = hfi1_ipoib_priv(netdev);
76+
struct hfi1_devdata *dd = ipoib_priv->dd;
77+
78+
return hfi1_netdev_rx_init(dd);
79+
}
80+
81+
void hfi1_ipoib_rxq_deinit(struct net_device *netdev)
82+
{
83+
struct hfi1_ipoib_dev_priv *ipoib_priv = hfi1_ipoib_priv(netdev);
84+
struct hfi1_devdata *dd = ipoib_priv->dd;
85+
86+
hfi1_netdev_rx_destroy(dd);
87+
}

drivers/infiniband/hw/hfi1/netdev.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ struct hfi1_ctxtdata *hfi1_netdev_get_ctxt(struct hfi1_devdata *dd, int ctxt)
8282
return priv->rxq[ctxt].rcd;
8383
}
8484

85+
void hfi1_netdev_enable_queues(struct hfi1_devdata *dd);
86+
void hfi1_netdev_disable_queues(struct hfi1_devdata *dd);
87+
int hfi1_netdev_rx_init(struct hfi1_devdata *dd);
88+
int hfi1_netdev_rx_destroy(struct hfi1_devdata *dd);
89+
int hfi1_netdev_alloc(struct hfi1_devdata *dd);
90+
void hfi1_netdev_free(struct hfi1_devdata *dd);
8591
int hfi1_netdev_add_data(struct hfi1_devdata *dd, int id, void *data);
8692
void *hfi1_netdev_remove_data(struct hfi1_devdata *dd, int id);
8793
void *hfi1_netdev_get_data(struct hfi1_devdata *dd, int id);

0 commit comments

Comments
 (0)