^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Greybus Host Device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2014-2015 Google Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2014-2015 Linaro Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/greybus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "greybus_trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_del);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) EXPORT_TRACEPOINT_SYMBOL_GPL(gb_hd_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) EXPORT_TRACEPOINT_SYMBOL_GPL(gb_message_submit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static struct ida gb_hd_bus_id_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int gb_hd_output(struct gb_host_device *hd, void *req, u16 size, u8 cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) bool async)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (!hd || !hd->driver || !hd->driver->output)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return hd->driver->output(hd, req, size, cmd, async);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) EXPORT_SYMBOL_GPL(gb_hd_output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static ssize_t bus_id_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct gb_host_device *hd = to_gb_host_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return sprintf(buf, "%d\n", hd->bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static DEVICE_ATTR_RO(bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct attribute *bus_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) &dev_attr_bus_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ATTRIBUTE_GROUPS(bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int gb_hd_cport_reserve(struct gb_host_device *hd, u16 cport_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct ida *id_map = &hd->cport_id_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ret = ida_simple_get(id_map, cport_id, cport_id + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) dev_err(&hd->dev, "failed to reserve cport %u\n", cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) EXPORT_SYMBOL_GPL(gb_hd_cport_reserve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) void gb_hd_cport_release_reserved(struct gb_host_device *hd, u16 cport_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct ida *id_map = &hd->cport_id_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ida_simple_remove(id_map, cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) EXPORT_SYMBOL_GPL(gb_hd_cport_release_reserved);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* Locking: Caller guarantees serialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int gb_hd_cport_allocate(struct gb_host_device *hd, int cport_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct ida *id_map = &hd->cport_id_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int ida_start, ida_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (hd->driver->cport_allocate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) return hd->driver->cport_allocate(hd, cport_id, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (cport_id < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) ida_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) ida_end = hd->num_cports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } else if (cport_id < hd->num_cports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ida_start = cport_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ida_end = cport_id + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dev_err(&hd->dev, "cport %d not available\n", cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return ida_simple_get(id_map, ida_start, ida_end, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /* Locking: Caller guarantees serialisation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void gb_hd_cport_release(struct gb_host_device *hd, u16 cport_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (hd->driver->cport_release) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) hd->driver->cport_release(hd, cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) ida_simple_remove(&hd->cport_id_map, cport_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static void gb_hd_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct gb_host_device *hd = to_gb_host_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) trace_gb_hd_release(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if (hd->svc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) gb_svc_put(hd->svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) ida_simple_remove(&gb_hd_bus_id_map, hd->bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ida_destroy(&hd->cport_id_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) kfree(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct device_type greybus_hd_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .name = "greybus_host_device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .release = gb_hd_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct gb_host_device *gb_hd_create(struct gb_hd_driver *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct device *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) size_t buffer_size_max,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) size_t num_cports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct gb_host_device *hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * Validate that the driver implements all of the callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * so that we don't have to every time we make them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if ((!driver->message_send) || (!driver->message_cancel)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dev_err(parent, "mandatory hd-callbacks missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (buffer_size_max < GB_OPERATION_MESSAGE_SIZE_MIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) dev_err(parent, "greybus host-device buffers too small\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (num_cports == 0 || num_cports > CPORT_ID_MAX + 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) dev_err(parent, "Invalid number of CPorts: %zu\n", num_cports);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * Make sure to never allocate messages larger than what the Greybus
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * protocol supports.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (buffer_size_max > GB_OPERATION_MESSAGE_SIZE_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) dev_warn(parent, "limiting buffer size to %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) GB_OPERATION_MESSAGE_SIZE_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) buffer_size_max = GB_OPERATION_MESSAGE_SIZE_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) hd = kzalloc(sizeof(*hd) + driver->hd_priv_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if (!hd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ret = ida_simple_get(&gb_hd_bus_id_map, 1, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) kfree(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) hd->bus_id = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) hd->driver = driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) INIT_LIST_HEAD(&hd->modules);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) INIT_LIST_HEAD(&hd->connections);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) ida_init(&hd->cport_id_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) hd->buffer_size_max = buffer_size_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) hd->num_cports = num_cports;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) hd->dev.parent = parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) hd->dev.bus = &greybus_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) hd->dev.type = &greybus_hd_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) hd->dev.groups = bus_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) hd->dev.dma_mask = hd->dev.parent->dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) device_initialize(&hd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) dev_set_name(&hd->dev, "greybus%d", hd->bus_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) trace_gb_hd_create(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) hd->svc = gb_svc_create(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!hd->svc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) dev_err(&hd->dev, "failed to create svc\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) put_device(&hd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return hd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) EXPORT_SYMBOL_GPL(gb_hd_create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int gb_hd_add(struct gb_host_device *hd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ret = device_add(&hd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ret = gb_svc_add(hd->svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) device_del(&hd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) trace_gb_hd_add(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) EXPORT_SYMBOL_GPL(gb_hd_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) void gb_hd_del(struct gb_host_device *hd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) trace_gb_hd_del(hd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * Tear down the svc and flush any on-going hotplug processing before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * removing the remaining interfaces.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) gb_svc_del(hd->svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) device_del(&hd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) EXPORT_SYMBOL_GPL(gb_hd_del);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) void gb_hd_shutdown(struct gb_host_device *hd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) gb_svc_del(hd->svc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) EXPORT_SYMBOL_GPL(gb_hd_shutdown);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) void gb_hd_put(struct gb_host_device *hd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) put_device(&hd->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) EXPORT_SYMBOL_GPL(gb_hd_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int __init gb_hd_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ida_init(&gb_hd_bus_id_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) void gb_hd_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ida_destroy(&gb_hd_bus_id_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }