Commit fae7a699 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jason Gunthorpe

opa_vnic: Convert vport_idr to XArray

Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent 059d48fb
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/xarray.h>
#include <rdma/ib_addr.h> #include <rdma/ib_addr.h>
#include <rdma/ib_verbs.h> #include <rdma/ib_verbs.h>
#include <rdma/opa_smi.h> #include <rdma/opa_smi.h>
...@@ -97,7 +98,7 @@ const char opa_vnic_driver_version[] = DRV_VERSION; ...@@ -97,7 +98,7 @@ const char opa_vnic_driver_version[] = DRV_VERSION;
* @class_port_info: Class port info information. * @class_port_info: Class port info information.
* @tid: Transaction id * @tid: Transaction id
* @port_num: OPA port number * @port_num: OPA port number
* @vport_idr: vnic ports idr * @vports: vnic ports
* @event_handler: ib event handler * @event_handler: ib event handler
* @lock: adapter interface lock * @lock: adapter interface lock
*/ */
...@@ -107,7 +108,7 @@ struct opa_vnic_vema_port { ...@@ -107,7 +108,7 @@ struct opa_vnic_vema_port {
struct opa_class_port_info class_port_info; struct opa_class_port_info class_port_info;
u64 tid; u64 tid;
u8 port_num; u8 port_num;
struct idr vport_idr; struct xarray vports;
struct ib_event_handler event_handler; struct ib_event_handler event_handler;
/* Lock to query/update network adapter */ /* Lock to query/update network adapter */
...@@ -148,7 +149,7 @@ vema_get_vport_adapter(struct opa_vnic_vema_mad *recvd_mad, ...@@ -148,7 +149,7 @@ vema_get_vport_adapter(struct opa_vnic_vema_mad *recvd_mad,
{ {
u8 vport_num = vema_get_vport_num(recvd_mad); u8 vport_num = vema_get_vport_num(recvd_mad);
return idr_find(&port->vport_idr, vport_num); return xa_load(&port->vports, vport_num);
} }
/** /**
...@@ -207,8 +208,7 @@ static struct opa_vnic_adapter *vema_add_vport(struct opa_vnic_vema_port *port, ...@@ -207,8 +208,7 @@ static struct opa_vnic_adapter *vema_add_vport(struct opa_vnic_vema_port *port,
int rc; int rc;
adapter->cport = cport; adapter->cport = cport;
rc = idr_alloc(&port->vport_idr, adapter, vport_num, rc = xa_insert(&port->vports, vport_num, adapter, GFP_KERNEL);
vport_num + 1, GFP_NOWAIT);
if (rc < 0) { if (rc < 0) {
opa_vnic_rem_netdev(adapter); opa_vnic_rem_netdev(adapter);
adapter = ERR_PTR(rc); adapter = ERR_PTR(rc);
...@@ -853,36 +853,14 @@ void opa_vnic_vema_send_trap(struct opa_vnic_adapter *adapter, ...@@ -853,36 +853,14 @@ void opa_vnic_vema_send_trap(struct opa_vnic_adapter *adapter,
v_err("Aborting trap\n"); v_err("Aborting trap\n");
} }
static int vema_rem_vport(int id, void *p, void *data)
{
struct opa_vnic_adapter *adapter = p;
opa_vnic_rem_netdev(adapter);
return 0;
}
static int vema_enable_vport(int id, void *p, void *data)
{
struct opa_vnic_adapter *adapter = p;
netif_carrier_on(adapter->netdev);
return 0;
}
static int vema_disable_vport(int id, void *p, void *data)
{
struct opa_vnic_adapter *adapter = p;
netif_carrier_off(adapter->netdev);
return 0;
}
static void opa_vnic_event(struct ib_event_handler *handler, static void opa_vnic_event(struct ib_event_handler *handler,
struct ib_event *record) struct ib_event *record)
{ {
struct opa_vnic_vema_port *port = struct opa_vnic_vema_port *port =
container_of(handler, struct opa_vnic_vema_port, event_handler); container_of(handler, struct opa_vnic_vema_port, event_handler);
struct opa_vnic_ctrl_port *cport = port->cport; struct opa_vnic_ctrl_port *cport = port->cport;
struct opa_vnic_adapter *adapter;
unsigned long index;
if (record->element.port_num != port->port_num) if (record->element.port_num != port->port_num)
return; return;
...@@ -891,10 +869,16 @@ static void opa_vnic_event(struct ib_event_handler *handler, ...@@ -891,10 +869,16 @@ static void opa_vnic_event(struct ib_event_handler *handler,
record->event, dev_name(&record->device->dev), record->event, dev_name(&record->device->dev),
record->element.port_num); record->element.port_num);
if (record->event == IB_EVENT_PORT_ERR) if (record->event != IB_EVENT_PORT_ERR ||
idr_for_each(&port->vport_idr, vema_disable_vport, NULL); record->event != IB_EVENT_PORT_ACTIVE)
return;
xa_for_each(&port->vports, index, adapter) {
if (record->event == IB_EVENT_PORT_ACTIVE) if (record->event == IB_EVENT_PORT_ACTIVE)
idr_for_each(&port->vport_idr, vema_enable_vport, NULL); netif_carrier_on(adapter->netdev);
else
netif_carrier_off(adapter->netdev);
}
} }
/** /**
...@@ -905,6 +889,8 @@ static void opa_vnic_event(struct ib_event_handler *handler, ...@@ -905,6 +889,8 @@ static void opa_vnic_event(struct ib_event_handler *handler,
*/ */
static void vema_unregister(struct opa_vnic_ctrl_port *cport) static void vema_unregister(struct opa_vnic_ctrl_port *cport)
{ {
struct opa_vnic_adapter *adapter;
unsigned long index;
int i; int i;
for (i = 1; i <= cport->num_ports; i++) { for (i = 1; i <= cport->num_ports; i++) {
...@@ -915,13 +901,14 @@ static void vema_unregister(struct opa_vnic_ctrl_port *cport) ...@@ -915,13 +901,14 @@ static void vema_unregister(struct opa_vnic_ctrl_port *cport)
/* Lock ensures no MAD is being processed */ /* Lock ensures no MAD is being processed */
mutex_lock(&port->lock); mutex_lock(&port->lock);
idr_for_each(&port->vport_idr, vema_rem_vport, NULL); xa_for_each(&port->vports, index, adapter)
opa_vnic_rem_netdev(adapter);
mutex_unlock(&port->lock); mutex_unlock(&port->lock);
ib_unregister_mad_agent(port->mad_agent); ib_unregister_mad_agent(port->mad_agent);
port->mad_agent = NULL; port->mad_agent = NULL;
mutex_destroy(&port->lock); mutex_destroy(&port->lock);
idr_destroy(&port->vport_idr); xa_destroy(&port->vports);
ib_unregister_event_handler(&port->event_handler); ib_unregister_event_handler(&port->event_handler);
} }
} }
...@@ -958,7 +945,7 @@ static int vema_register(struct opa_vnic_ctrl_port *cport) ...@@ -958,7 +945,7 @@ static int vema_register(struct opa_vnic_ctrl_port *cport)
cport->ibdev, opa_vnic_event); cport->ibdev, opa_vnic_event);
ib_register_event_handler(&port->event_handler); ib_register_event_handler(&port->event_handler);
idr_init(&port->vport_idr); xa_init(&port->vports);
mutex_init(&port->lock); mutex_init(&port->lock);
port->mad_agent = ib_register_mad_agent(cport->ibdev, i, port->mad_agent = ib_register_mad_agent(cport->ibdev, i,
IB_QPT_GSI, &reg_req, IB_QPT_GSI, &reg_req,
...@@ -969,7 +956,6 @@ static int vema_register(struct opa_vnic_ctrl_port *cport) ...@@ -969,7 +956,6 @@ static int vema_register(struct opa_vnic_ctrl_port *cport)
ret = PTR_ERR(port->mad_agent); ret = PTR_ERR(port->mad_agent);
port->mad_agent = NULL; port->mad_agent = NULL;
mutex_destroy(&port->lock); mutex_destroy(&port->lock);
idr_destroy(&port->vport_idr);
vema_unregister(cport); vema_unregister(cport);
return ret; return ret;
} }
......
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