nodedev: detect AP queues

Each AP card device can support upto 256 AP queues.  AP queues are
also detected by udev, so add support for libvirt nodedev driver.

https://www.kernel.org/doc/html/latest/s390/vfio-ap.html#ap-architectural-overview

Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
Signed-off-by: Shalini Chellathurai Saroja <shalini@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Shalini Chellathurai Saroja 2020-12-03 18:59:35 +01:00 committed by Erik Skultety
parent a920a17717
commit 0415611fe0
7 changed files with 135 additions and 0 deletions

View File

@ -439,6 +439,21 @@
<dd>AP Card identifier.</dd>
</dl>
</dd>
<dt><code>ap_queue</code></dt>
<dd>Describes the AP queue on a s390 host. An AP queue is
an AP domain on an AP adapter which is specified by an
adapter identifier and a domain identifier.
Sub-elements include:
<dl>
<dt><code>ap-adapter</code></dt>
<dd>The ap-adapter of an AP queue identifies the AP
card to which this AP queue belongs.</dd>
<dt><code>ap-domain</code></dt>
<dd>The ap-domain of an AP queue identifies the AP
domain to which this AP queue belongs.</dd>
<dd>AP Queue identifier.</dd>
</dl>
</dd>
</dl>
</dd>
</dl>

View File

@ -88,6 +88,7 @@
<ref name="capcssdev"/>
<ref name="capvdpa"/>
<ref name="capapcard"/>
<ref name="capapqueue"/>
</choice>
</element>
</define>
@ -678,6 +679,18 @@
</element>
</define>
<define name="capapqueue">
<attribute name="type">
<value>ap_queue</value>
</attribute>
<element name="ap-adapter">
<ref name="uint8"/>
</element>
<element name="ap-domain">
<ref name="apDomainRange"/>
</element>
</define>
<define name="address">
<element name="address">
<attribute name="domain"><ref name="hexuint"/></attribute>
@ -726,4 +739,16 @@
</element>
</define>
<define name="apDomainRange">
<choice>
<data type="string">
<param name="pattern">0x[0-9a-fA-F]{1,4}</param>
</data>
<data type="int">
<param name="minInclusive">0</param>
<param name="maxInclusive">255</param>
</data>
</choice>
</define>
</grammar>

View File

@ -68,6 +68,7 @@ VIR_ENUM_IMPL(virNodeDevCap,
"css",
"vdpa",
"ap_card",
"ap_queue",
);
VIR_ENUM_IMPL(virNodeDevNetCap,
@ -655,6 +656,12 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def)
virBufferAsprintf(&buf, "<ap-adapter>0x%02x</ap-adapter>\n",
data->ap_card.ap_adapter);
break;
case VIR_NODE_DEV_CAP_AP_QUEUE:
virBufferAsprintf(&buf, "<ap-adapter>0x%02x</ap-adapter>\n",
data->ap_queue.ap_adapter);
virBufferAsprintf(&buf, "<ap-domain>0x%04x</ap-domain>\n",
data->ap_queue.ap_domain);
break;
case VIR_NODE_DEV_CAP_MDEV_TYPES:
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
@ -983,6 +990,47 @@ virNodeDevCapAPCardParseXML(xmlXPathContextPtr ctxt,
}
static int
virNodeDevCapAPQueueParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def,
xmlNodePtr node,
virNodeDevCapAPQueuePtr ap_queue)
{
int ret = -1;
VIR_XPATH_NODE_AUTORESTORE(ctxt)
g_autofree char *dom = NULL;
ctxt->node = node;
ret = virNodeDevCapAPAdapterParseXML(ctxt, def, &ap_queue->ap_adapter);
if (ret < 0)
return ret;
if (!(dom = virXPathString("string(./ap-domain[1])", ctxt))) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("missing ap-domain value for '%s'"), def->name);
return -1;
}
if (virStrToLong_uip(dom, NULL, 0, &ap_queue->ap_domain) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("invalid ap-domain value '%s' for '%s'"),
dom, def->name);
return -1;
}
if (ap_queue->ap_domain > 255) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("ap-domain value '%s' is out of range for '%s'"),
dom, def->name);
return -1;
}
return 0;
}
static int
virNodeDevCapStorageParseXML(xmlXPathContextPtr ctxt,
virNodeDeviceDefPtr def,
@ -2025,6 +2073,10 @@ virNodeDevCapsDefParseXML(xmlXPathContextPtr ctxt,
ret = virNodeDevCapAPCardParseXML(ctxt, def, node,
&caps->data.ap_card);
break;
case VIR_NODE_DEV_CAP_AP_QUEUE:
ret = virNodeDevCapAPQueueParseXML(ctxt, def, node,
&caps->data.ap_queue);
break;
case VIR_NODE_DEV_CAP_MDEV_TYPES:
case VIR_NODE_DEV_CAP_FC_HOST:
case VIR_NODE_DEV_CAP_VPORTS:
@ -2353,6 +2405,7 @@ virNodeDevCapsDefFree(virNodeDevCapsDefPtr caps)
case VIR_NODE_DEV_CAP_CCW_DEV:
case VIR_NODE_DEV_CAP_VDPA:
case VIR_NODE_DEV_CAP_AP_CARD:
case VIR_NODE_DEV_CAP_AP_QUEUE:
case VIR_NODE_DEV_CAP_LAST:
/* This case is here to shutup the compiler */
break;
@ -2413,6 +2466,7 @@ virNodeDeviceUpdateCaps(virNodeDeviceDefPtr def)
case VIR_NODE_DEV_CAP_CCW_DEV:
case VIR_NODE_DEV_CAP_VDPA:
case VIR_NODE_DEV_CAP_AP_CARD:
case VIR_NODE_DEV_CAP_AP_QUEUE:
case VIR_NODE_DEV_CAP_LAST:
break;
}

View File

@ -67,6 +67,7 @@ typedef enum {
VIR_NODE_DEV_CAP_CSS_DEV, /* s390 channel subsystem device */
VIR_NODE_DEV_CAP_VDPA, /* vDPA device */
VIR_NODE_DEV_CAP_AP_CARD, /* s390 AP Card device */
VIR_NODE_DEV_CAP_AP_QUEUE, /* s390 AP Queue */
VIR_NODE_DEV_CAP_LAST
} virNodeDevCapType;
@ -296,6 +297,13 @@ struct _virNodeDevCapAPCard {
unsigned int ap_adapter;
};
typedef struct _virNodeDevCapAPQueue virNodeDevCapAPQueue;
typedef virNodeDevCapAPQueue *virNodeDevCapAPQueuePtr;
struct _virNodeDevCapAPQueue {
unsigned int ap_adapter;
unsigned int ap_domain;
};
typedef struct _virNodeDevCapData virNodeDevCapData;
typedef virNodeDevCapData *virNodeDevCapDataPtr;
struct _virNodeDevCapData {
@ -316,6 +324,7 @@ struct _virNodeDevCapData {
virNodeDevCapCCW ccw_dev;
virNodeDevCapVDPA vdpa;
virNodeDevCapAPCard ap_card;
virNodeDevCapAPQueue ap_queue;
};
};

View File

@ -718,6 +718,7 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *obj,
case VIR_NODE_DEV_CAP_CCW_DEV:
case VIR_NODE_DEV_CAP_VDPA:
case VIR_NODE_DEV_CAP_AP_CARD:
case VIR_NODE_DEV_CAP_AP_QUEUE:
case VIR_NODE_DEV_CAP_LAST:
break;
}

View File

@ -1208,6 +1208,32 @@ udevProcessAPCard(struct udev_device *device,
}
static int
udevProcessAPQueue(struct udev_device *device,
virNodeDeviceDefPtr def)
{
char *c;
virNodeDevCapDataPtr data = &def->caps->data;
/* The sysfs path would be in the format /sys/bus/ap/devices
/XX.YYYY, where XX is the ap adapter id and YYYY is the ap
domain id */
if ((c = strrchr(def->sysfs_path, '/')) == NULL ||
virStrToLong_ui(c + 1, &c, 16, &data->ap_queue.ap_adapter) < 0 ||
virStrToLong_ui(c + 1, &c, 16, &data->ap_queue.ap_domain) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse the AP Queue from sysfs path: '%s'"),
def->sysfs_path);
return -1;
}
if (udevGenerateDeviceName(device, def, NULL) != 0)
return -1;
return 0;
}
static int
udevGetDeviceNodes(struct udev_device *device,
virNodeDeviceDefPtr def)
@ -1264,6 +1290,8 @@ udevGetDeviceType(struct udev_device *device,
*type = VIR_NODE_DEV_CAP_DRM;
else if (STREQ(devtype, "ap_card"))
*type = VIR_NODE_DEV_CAP_AP_CARD;
else if (STREQ(devtype, "ap_queue"))
*type = VIR_NODE_DEV_CAP_AP_QUEUE;
} else {
/* PCI devices don't set the DEVTYPE property. */
if (udevHasDeviceProperty(device, "PCI_CLASS"))
@ -1341,6 +1369,8 @@ udevGetDeviceDetails(struct udev_device *device,
return udevProcessVDPA(device, def);
case VIR_NODE_DEV_CAP_AP_CARD:
return udevProcessAPCard(device, def);
case VIR_NODE_DEV_CAP_AP_QUEUE:
return udevProcessAPQueue(device, def);
case VIR_NODE_DEV_CAP_MDEV_TYPES:
case VIR_NODE_DEV_CAP_SYSTEM:
case VIR_NODE_DEV_CAP_FC_HOST:

View File

@ -468,6 +468,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
flags |= VIR_CONNECT_LIST_NODE_DEVICES_CAP_VDPA;
break;
case VIR_NODE_DEV_CAP_AP_CARD:
case VIR_NODE_DEV_CAP_AP_QUEUE:
case VIR_NODE_DEV_CAP_LAST:
break;
}