Lines Matching +full:num +full:- +full:rings

1 // SPDX-License-Identifier: GPL-2.0-only
24 #define XEN_9PFS_RING_SIZE(ring) XEN_FLEX_RING_SIZE(ring->intf->ring_order)
57 struct xen_9pfs_dataring *rings; member
74 return -EINVAL; in p9_xen_create()
78 if (!strcmp(priv->tag, addr)) { in p9_xen_create()
79 priv->client = client; in p9_xen_create()
85 return -EINVAL; in p9_xen_create()
94 if (priv->client == client) { in p9_xen_close()
95 priv->client = NULL; in p9_xen_close()
107 cons = ring->intf->out_cons; in p9_xen_write_todo()
108 prod = ring->intf->out_prod; in p9_xen_write_todo()
111 return XEN_9PFS_RING_SIZE(ring) - in p9_xen_write_todo()
120 u32 size = p9_req->tc.size; in p9_xen_request()
122 int num; in p9_xen_request() local
126 if (priv->client == client) in p9_xen_request()
131 return -EINVAL; in p9_xen_request()
133 num = p9_req->tc.tag % XEN_9PFS_NUM_RINGS; in p9_xen_request()
134 ring = &priv->rings[num]; in p9_xen_request()
137 while (wait_event_killable(ring->wq, in p9_xen_request()
141 spin_lock_irqsave(&ring->lock, flags); in p9_xen_request()
142 cons = ring->intf->out_cons; in p9_xen_request()
143 prod = ring->intf->out_prod; in p9_xen_request()
146 if (XEN_9PFS_RING_SIZE(ring) - in p9_xen_request()
148 spin_unlock_irqrestore(&ring->lock, flags); in p9_xen_request()
155 xen_9pfs_write_packet(ring->data.out, p9_req->tc.sdata, size, in p9_xen_request()
159 WRITE_ONCE(p9_req->status, REQ_STATUS_SENT); in p9_xen_request()
162 ring->intf->out_prod = prod; in p9_xen_request()
163 spin_unlock_irqrestore(&ring->lock, flags); in p9_xen_request()
164 notify_remote_via_irq(ring->irq); in p9_xen_request()
180 priv = ring->priv; in p9_xen_response()
183 cons = ring->intf->in_cons; in p9_xen_response()
184 prod = ring->intf->in_prod; in p9_xen_response()
189 notify_remote_via_irq(ring->irq); in p9_xen_response()
197 xen_9pfs_read_packet(&h, ring->data.in, sizeof(h), in p9_xen_response()
201 req = p9_tag_lookup(priv->client, h.tag); in p9_xen_response()
202 if (!req || req->status != REQ_STATUS_SENT) { in p9_xen_response()
203 dev_warn(&priv->dev->dev, "Wrong req tag=%x\n", h.tag); in p9_xen_response()
206 ring->intf->in_cons = cons; in p9_xen_response()
210 if (h.size > req->rc.capacity) { in p9_xen_response()
211 dev_warn(&priv->dev->dev, in p9_xen_response()
213 h.size, h.tag, req->rc.capacity); in p9_xen_response()
214 WRITE_ONCE(req->status, REQ_STATUS_ERROR); in p9_xen_response()
218 req->rc.size = h.size; in p9_xen_response()
219 req->rc.id = h.id; in p9_xen_response()
220 req->rc.tag = h.tag; in p9_xen_response()
221 req->rc.offset = 0; in p9_xen_response()
225 xen_9pfs_read_packet(req->rc.sdata, ring->data.in, h.size, in p9_xen_response()
232 ring->intf->in_cons = cons; in p9_xen_response()
234 status = (req->status != REQ_STATUS_ERROR) ? in p9_xen_response()
237 p9_client_cb(priv->client, req, status); in p9_xen_response()
245 if (!ring || !ring->priv->client) { in xen_9pfs_front_event_handler()
250 wake_up_interruptible(&ring->wq); in xen_9pfs_front_event_handler()
251 schedule_work(&ring->work); in xen_9pfs_front_event_handler()
258 .maxsize = 1 << (XEN_9PFS_RING_ORDER + XEN_PAGE_SHIFT - 2),
278 list_del(&priv->list); in xen_9pfs_front_free()
282 struct xen_9pfs_dataring *ring = &priv->rings[i]; in xen_9pfs_front_free()
284 cancel_work_sync(&ring->work); in xen_9pfs_front_free()
286 if (!priv->rings[i].intf) in xen_9pfs_front_free()
288 if (priv->rings[i].irq > 0) in xen_9pfs_front_free()
289 unbind_from_irqhandler(priv->rings[i].irq, ring); in xen_9pfs_front_free()
290 if (priv->rings[i].data.in) { in xen_9pfs_front_free()
292 j < (1 << priv->rings[i].intf->ring_order); in xen_9pfs_front_free()
296 ref = priv->rings[i].intf->ref[j]; in xen_9pfs_front_free()
299 free_pages_exact(priv->rings[i].data.in, in xen_9pfs_front_free()
300 1UL << (priv->rings[i].intf->ring_order + in xen_9pfs_front_free()
303 gnttab_end_foreign_access(priv->rings[i].ref, NULL); in xen_9pfs_front_free()
304 free_page((unsigned long)priv->rings[i].intf); in xen_9pfs_front_free()
306 kfree(priv->rings); in xen_9pfs_front_free()
307 kfree(priv->tag); in xen_9pfs_front_free()
313 struct xen_9pfs_front_priv *priv = dev_get_drvdata(&dev->dev); in xen_9pfs_front_remove()
315 dev_set_drvdata(&dev->dev, NULL); in xen_9pfs_front_remove()
324 int ret = -ENOMEM; in xen_9pfs_front_alloc_dataring()
327 init_waitqueue_head(&ring->wq); in xen_9pfs_front_alloc_dataring()
328 spin_lock_init(&ring->lock); in xen_9pfs_front_alloc_dataring()
329 INIT_WORK(&ring->work, p9_xen_response); in xen_9pfs_front_alloc_dataring()
331 ring->intf = (struct xen_9pfs_data_intf *)get_zeroed_page(GFP_KERNEL); in xen_9pfs_front_alloc_dataring()
332 if (!ring->intf) in xen_9pfs_front_alloc_dataring()
334 ret = gnttab_grant_foreign_access(dev->otherend_id, in xen_9pfs_front_alloc_dataring()
335 virt_to_gfn(ring->intf), 0); in xen_9pfs_front_alloc_dataring()
338 ring->ref = ret; in xen_9pfs_front_alloc_dataring()
342 ret = -ENOMEM; in xen_9pfs_front_alloc_dataring()
347 dev->otherend_id, virt_to_gfn(bytes) + i, 0); in xen_9pfs_front_alloc_dataring()
350 ring->intf->ref[i] = ret; in xen_9pfs_front_alloc_dataring()
352 ring->intf->ring_order = order; in xen_9pfs_front_alloc_dataring()
353 ring->data.in = bytes; in xen_9pfs_front_alloc_dataring()
354 ring->data.out = bytes + XEN_FLEX_RING_SIZE(order); in xen_9pfs_front_alloc_dataring()
356 ret = xenbus_alloc_evtchn(dev, &ring->evtchn); in xen_9pfs_front_alloc_dataring()
359 ring->irq = bind_evtchn_to_irqhandler(ring->evtchn, in xen_9pfs_front_alloc_dataring()
361 0, "xen_9pfs-frontend", ring); in xen_9pfs_front_alloc_dataring()
362 if (ring->irq >= 0) in xen_9pfs_front_alloc_dataring()
365 xenbus_free_evtchn(dev, ring->evtchn); in xen_9pfs_front_alloc_dataring()
366 ret = ring->irq; in xen_9pfs_front_alloc_dataring()
369 for (i--; i >= 0; i--) in xen_9pfs_front_alloc_dataring()
370 gnttab_end_foreign_access(ring->intf->ref[i], NULL); in xen_9pfs_front_alloc_dataring()
373 gnttab_end_foreign_access(ring->ref, NULL); in xen_9pfs_front_alloc_dataring()
374 free_page((unsigned long)ring->intf); in xen_9pfs_front_alloc_dataring()
382 struct xen_9pfs_front_priv *priv = dev_get_drvdata(&dev->dev); in xen_9pfs_front_init()
386 versions = xenbus_read(XBT_NIL, dev->otherend, "versions", &len); in xen_9pfs_front_init()
397 return -EINVAL; in xen_9pfs_front_init()
400 max_rings = xenbus_read_unsigned(dev->otherend, "max-rings", 0); in xen_9pfs_front_init()
402 return -EINVAL; in xen_9pfs_front_init()
403 max_ring_order = xenbus_read_unsigned(dev->otherend, in xen_9pfs_front_init()
404 "max-ring-page-order", 0); in xen_9pfs_front_init()
410 priv->rings = kcalloc(XEN_9PFS_NUM_RINGS, sizeof(*priv->rings), in xen_9pfs_front_init()
412 if (!priv->rings) { in xen_9pfs_front_init()
414 return -ENOMEM; in xen_9pfs_front_init()
418 priv->rings[i].priv = priv; in xen_9pfs_front_init()
419 ret = xen_9pfs_front_alloc_dataring(dev, &priv->rings[i], in xen_9pfs_front_init()
431 ret = xenbus_printf(xbt, dev->nodename, "version", "%u", 1); in xen_9pfs_front_init()
434 ret = xenbus_printf(xbt, dev->nodename, "num-rings", "%u", in xen_9pfs_front_init()
443 sprintf(str, "ring-ref%d", i); in xen_9pfs_front_init()
444 ret = xenbus_printf(xbt, dev->nodename, str, "%d", in xen_9pfs_front_init()
445 priv->rings[i].ref); in xen_9pfs_front_init()
449 sprintf(str, "event-channel-%d", i); in xen_9pfs_front_init()
450 ret = xenbus_printf(xbt, dev->nodename, str, "%u", in xen_9pfs_front_init()
451 priv->rings[i].evtchn); in xen_9pfs_front_init()
455 priv->tag = xenbus_read(xbt, dev->nodename, "tag", NULL); in xen_9pfs_front_init()
456 if (IS_ERR(priv->tag)) { in xen_9pfs_front_init()
457 ret = PTR_ERR(priv->tag); in xen_9pfs_front_init()
462 if (ret == -EAGAIN) in xen_9pfs_front_init()
486 return -ENOMEM; in xen_9pfs_front_probe()
488 priv->dev = dev; in xen_9pfs_front_probe()
489 dev_set_drvdata(&dev->dev, priv); in xen_9pfs_front_probe()
492 list_add_tail(&priv->list, &xen_9pfs_devs); in xen_9pfs_front_probe()
500 dev_warn(&dev->dev, "suspend/resume unsupported\n"); in xen_9pfs_front_resume()
516 if (dev->state != XenbusStateInitialising) in xen_9pfs_front_changed()
527 if (dev->state == XenbusStateClosed) in xen_9pfs_front_changed()
549 return -ENODEV; in p9_trans_xen_init()