Commit 0ee3b915 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jason Gunthorpe

hfi1: Convert vesw_idr to XArray

Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 736b5a70
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/idr.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/completion.h> #include <linux/completion.h>
...@@ -1021,8 +1020,8 @@ struct hfi1_asic_data { ...@@ -1021,8 +1020,8 @@ struct hfi1_asic_data {
struct hfi1_vnic_data { struct hfi1_vnic_data {
struct hfi1_ctxtdata *ctxt[HFI1_NUM_VNIC_CTXT]; struct hfi1_ctxtdata *ctxt[HFI1_NUM_VNIC_CTXT];
struct kmem_cache *txreq_cache; struct kmem_cache *txreq_cache;
struct xarray vesws;
u8 num_vports; u8 num_vports;
struct idr vesw_idr;
u8 rmt_start; u8 rmt_start;
u8 num_ctxt; u8 num_ctxt;
}; };
......
...@@ -162,12 +162,12 @@ static void deallocate_vnic_ctxt(struct hfi1_devdata *dd, ...@@ -162,12 +162,12 @@ static void deallocate_vnic_ctxt(struct hfi1_devdata *dd,
void hfi1_vnic_setup(struct hfi1_devdata *dd) void hfi1_vnic_setup(struct hfi1_devdata *dd)
{ {
idr_init(&dd->vnic.vesw_idr); xa_init(&dd->vnic.vesws);
} }
void hfi1_vnic_cleanup(struct hfi1_devdata *dd) void hfi1_vnic_cleanup(struct hfi1_devdata *dd)
{ {
idr_destroy(&dd->vnic.vesw_idr); WARN_ON(!xa_empty(&dd->vnic.vesws));
} }
#define SUM_GRP_COUNTERS(stats, qstats, x_grp) do { \ #define SUM_GRP_COUNTERS(stats, qstats, x_grp) do { \
...@@ -534,7 +534,7 @@ void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet) ...@@ -534,7 +534,7 @@ void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet)
l4_type = hfi1_16B_get_l4(packet->ebuf); l4_type = hfi1_16B_get_l4(packet->ebuf);
if (likely(l4_type == OPA_16B_L4_ETHR)) { if (likely(l4_type == OPA_16B_L4_ETHR)) {
vesw_id = HFI1_VNIC_GET_VESWID(packet->ebuf); vesw_id = HFI1_VNIC_GET_VESWID(packet->ebuf);
vinfo = idr_find(&dd->vnic.vesw_idr, vesw_id); vinfo = xa_load(&dd->vnic.vesws, vesw_id);
/* /*
* In case of invalid vesw id, count the error on * In case of invalid vesw id, count the error on
...@@ -542,9 +542,10 @@ void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet) ...@@ -542,9 +542,10 @@ void hfi1_vnic_bypass_rcv(struct hfi1_packet *packet)
*/ */
if (unlikely(!vinfo)) { if (unlikely(!vinfo)) {
struct hfi1_vnic_vport_info *vinfo_tmp; struct hfi1_vnic_vport_info *vinfo_tmp;
int id_tmp = 0; unsigned long index = 0;
vinfo_tmp = idr_get_next(&dd->vnic.vesw_idr, &id_tmp); vinfo_tmp = xa_find(&dd->vnic.vesws, &index, ULONG_MAX,
XA_PRESENT);
if (vinfo_tmp) { if (vinfo_tmp) {
spin_lock(&vport_cntr_lock); spin_lock(&vport_cntr_lock);
vinfo_tmp->stats[0].netstats.rx_nohandler++; vinfo_tmp->stats[0].netstats.rx_nohandler++;
...@@ -598,8 +599,7 @@ static int hfi1_vnic_up(struct hfi1_vnic_vport_info *vinfo) ...@@ -598,8 +599,7 @@ static int hfi1_vnic_up(struct hfi1_vnic_vport_info *vinfo)
if (!vinfo->vesw_id) if (!vinfo->vesw_id)
return -EINVAL; return -EINVAL;
rc = idr_alloc(&dd->vnic.vesw_idr, vinfo, vinfo->vesw_id, rc = xa_insert(&dd->vnic.vesws, vinfo->vesw_id, vinfo, GFP_KERNEL);
vinfo->vesw_id + 1, GFP_NOWAIT);
if (rc < 0) if (rc < 0)
return rc; return rc;
...@@ -625,7 +625,7 @@ static void hfi1_vnic_down(struct hfi1_vnic_vport_info *vinfo) ...@@ -625,7 +625,7 @@ static void hfi1_vnic_down(struct hfi1_vnic_vport_info *vinfo)
clear_bit(HFI1_VNIC_UP, &vinfo->flags); clear_bit(HFI1_VNIC_UP, &vinfo->flags);
netif_carrier_off(vinfo->netdev); netif_carrier_off(vinfo->netdev);
netif_tx_disable(vinfo->netdev); netif_tx_disable(vinfo->netdev);
idr_remove(&dd->vnic.vesw_idr, vinfo->vesw_id); xa_erase(&dd->vnic.vesws, vinfo->vesw_id);
/* ensure irqs see the change */ /* ensure irqs see the change */
msix_vnic_synchronize_irq(dd); msix_vnic_synchronize_irq(dd);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment