/* Fixed IDs for control/svc protocols */
-/* Device ID of SVC and AP */
-#define GB_DEVICE_ID_SVC 0
-#define GB_DEVICE_ID_AP 1
-#define GB_DEVICE_ID_MODULES_START 2
+/* SVC switch-port device ids */
+#define GB_SVC_DEVICE_ID_SVC 0
+#define GB_SVC_DEVICE_ID_AP 1
+#define GB_SVC_DEVICE_ID_MIN 2
+#define GB_SVC_DEVICE_ID_MAX 31
#define GB_SVC_CPORT_ID 0
#define GB_CONTROL_BUNDLE_ID 0
#include "greybus.h"
+#define GB_INTERFACE_DEVICE_ID_BAD 0xff
+
+
static int gb_interface_route_create(struct gb_interface *intf)
{
struct gb_svc *svc = intf->hd->svc;
u8 device_id;
int ret;
- /*
- * Create a device id for the interface:
- * - device id 0 (GB_DEVICE_ID_SVC) belongs to the SVC
- * - device id 1 (GB_DEVICE_ID_AP) belongs to the AP
- *
- * XXX Do we need to allocate device ID for SVC or the AP here? And what
- * XXX about an AP with multiple interface blocks?
- */
+ /* Allocate an interface device id. */
ret = ida_simple_get(&svc->device_id_map,
- GB_DEVICE_ID_MODULES_START, 0, GFP_KERNEL);
+ GB_SVC_DEVICE_ID_MIN, GB_SVC_DEVICE_ID_MAX + 1,
+ GFP_KERNEL);
if (ret < 0) {
dev_err(&intf->dev, "failed to allocate device id: %d\n", ret);
return ret;
goto err_ida_remove;
}
- /* Create a two-way route between the AP and the new interface. */
- ret = gb_svc_route_create(svc, svc->ap_intf_id, GB_DEVICE_ID_AP,
+ /* FIXME: Hard-coded AP device id. */
+ ret = gb_svc_route_create(svc, svc->ap_intf_id, GB_SVC_DEVICE_ID_AP,
intf_id, device_id);
if (ret) {
dev_err(&intf->dev, "failed to create route: %d\n", ret);
{
struct gb_svc *svc = intf->hd->svc;
- if (intf->device_id == GB_DEVICE_ID_BAD)
+ if (intf->device_id == GB_INTERFACE_DEVICE_ID_BAD)
return;
gb_svc_route_destroy(svc, svc->ap_intf_id, intf->interface_id);
ida_simple_remove(&svc->device_id_map, intf->device_id);
- intf->device_id = GB_DEVICE_ID_BAD;
+ intf->device_id = GB_INTERFACE_DEVICE_ID_BAD;
}
/*
INIT_LIST_HEAD(&intf->manifest_descs);
/* Invalid device id to start with */
- intf->device_id = GB_DEVICE_ID_BAD;
+ intf->device_id = GB_INTERFACE_DEVICE_ID_BAD;
intf->dev.parent = &hd->dev;
intf->dev.bus = &greybus_bus_type;