Lines Matching refs:ctl

18 	struct tb_ctl *ctl;  member
43 #define tb_ctl_WARN(ctl, format, arg...) \ argument
44 dev_WARN(&(ctl)->nhi->pdev->dev, format, ## arg)
46 #define tb_ctl_err(ctl, format, arg...) \ argument
47 dev_err(&(ctl)->nhi->pdev->dev, format, ## arg)
49 #define tb_ctl_warn(ctl, format, arg...) \ argument
50 dev_warn(&(ctl)->nhi->pdev->dev, format, ## arg)
52 #define tb_ctl_info(ctl, format, arg...) \ argument
53 dev_info(&(ctl)->nhi->pdev->dev, format, ## arg)
237 static void tb_cfg_print_error(struct tb_ctl *ctl, in tb_cfg_print_error() argument
251 tb_ctl_WARN(ctl, in tb_cfg_print_error()
261 tb_ctl_WARN(ctl, "CFG_ERROR(%llx:%x): Invalid port\n", in tb_cfg_print_error()
265 tb_ctl_WARN(ctl, "CFG_ERROR(%llx:%x): Route contains a loop\n", in tb_cfg_print_error()
270 tb_ctl_WARN(ctl, "CFG_ERROR(%llx:%x): Unknown error\n", in tb_cfg_print_error()
298 dma_pool_free(pkg->ctl->frame_pool, in tb_ctl_pkg_free()
304 static struct ctl_pkg *tb_ctl_pkg_alloc(struct tb_ctl *ctl) in tb_ctl_pkg_alloc() argument
309 pkg->ctl = ctl; in tb_ctl_pkg_alloc()
310 pkg->buffer = dma_pool_alloc(ctl->frame_pool, GFP_KERNEL, in tb_ctl_pkg_alloc()
336 static int tb_ctl_tx(struct tb_ctl *ctl, void *data, size_t len, in tb_ctl_tx() argument
342 tb_ctl_WARN(ctl, "TX: invalid size: %zu\n", len); in tb_ctl_tx()
346 tb_ctl_WARN(ctl, "TX: packet too large: %zu/%d\n", in tb_ctl_tx()
350 pkg = tb_ctl_pkg_alloc(ctl); in tb_ctl_tx()
360 res = ring_tx(ctl->tx, &pkg->frame); in tb_ctl_tx()
369 static void tb_ctl_handle_plug_event(struct tb_ctl *ctl, in tb_ctl_handle_plug_event() argument
376 tb_ctl_warn(ctl, "malformed TB_CFG_PKG_EVENT\n"); in tb_ctl_handle_plug_event()
380 if (tb_cfg_error(ctl, route, pkg->port, TB_CFG_ERROR_ACK_PLUG_EVENT)) in tb_ctl_handle_plug_event()
381 tb_ctl_warn(ctl, "could not ack plug event on %llx:%x\n", in tb_ctl_handle_plug_event()
384 ctl->callback(ctl->callback_data, route, pkg->port, pkg->unplug); in tb_ctl_handle_plug_event()
389 ring_rx(pkg->ctl->rx, &pkg->frame); /* in tb_ctl_rx_submit()
409 tb_ctl_err(pkg->ctl, "RX: invalid size %#x, dropping packet\n", in tb_ctl_rx_callback()
417 tb_ctl_err(pkg->ctl, in tb_ctl_rx_callback()
424 tb_ctl_handle_plug_event(pkg->ctl, pkg); in tb_ctl_rx_callback()
427 if (!kfifo_put(&pkg->ctl->response_fifo, pkg)) { in tb_ctl_rx_callback()
428 tb_ctl_err(pkg->ctl, "RX: fifo is full\n"); in tb_ctl_rx_callback()
431 complete(&pkg->ctl->response_ready); in tb_ctl_rx_callback()
440 static struct tb_cfg_result tb_ctl_rx(struct tb_ctl *ctl, void *buffer, in tb_ctl_rx() argument
447 if (!wait_for_completion_timeout(&ctl->response_ready, in tb_ctl_rx()
449 tb_ctl_WARN(ctl, "RX: timeout\n"); in tb_ctl_rx()
452 if (!kfifo_get(&ctl->response_fifo, &pkg)) { in tb_ctl_rx()
453 tb_ctl_WARN(ctl, "empty kfifo\n"); in tb_ctl_rx()
477 struct tb_ctl *ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); in tb_ctl_alloc() local
478 if (!ctl) in tb_ctl_alloc()
480 ctl->nhi = nhi; in tb_ctl_alloc()
481 ctl->callback = cb; in tb_ctl_alloc()
482 ctl->callback_data = cb_data; in tb_ctl_alloc()
484 init_completion(&ctl->response_ready); in tb_ctl_alloc()
485 INIT_KFIFO(ctl->response_fifo); in tb_ctl_alloc()
486 ctl->frame_pool = dma_pool_create("thunderbolt_ctl", &nhi->pdev->dev, in tb_ctl_alloc()
488 if (!ctl->frame_pool) in tb_ctl_alloc()
491 ctl->tx = ring_alloc_tx(nhi, 0, 10); in tb_ctl_alloc()
492 if (!ctl->tx) in tb_ctl_alloc()
495 ctl->rx = ring_alloc_rx(nhi, 0, 10); in tb_ctl_alloc()
496 if (!ctl->rx) in tb_ctl_alloc()
500 ctl->rx_packets[i] = tb_ctl_pkg_alloc(ctl); in tb_ctl_alloc()
501 if (!ctl->rx_packets[i]) in tb_ctl_alloc()
503 ctl->rx_packets[i]->frame.callback = tb_ctl_rx_callback; in tb_ctl_alloc()
506 tb_ctl_info(ctl, "control channel created\n"); in tb_ctl_alloc()
507 return ctl; in tb_ctl_alloc()
509 tb_ctl_free(ctl); in tb_ctl_alloc()
520 void tb_ctl_free(struct tb_ctl *ctl) in tb_ctl_free() argument
523 if (ctl->rx) in tb_ctl_free()
524 ring_free(ctl->rx); in tb_ctl_free()
525 if (ctl->tx) in tb_ctl_free()
526 ring_free(ctl->tx); in tb_ctl_free()
530 tb_ctl_pkg_free(ctl->rx_packets[i]); in tb_ctl_free()
533 if (ctl->frame_pool) in tb_ctl_free()
534 dma_pool_destroy(ctl->frame_pool); in tb_ctl_free()
535 kfree(ctl); in tb_ctl_free()
541 void tb_ctl_start(struct tb_ctl *ctl) in tb_ctl_start() argument
544 tb_ctl_info(ctl, "control channel starting...\n"); in tb_ctl_start()
545 ring_start(ctl->tx); /* is used to ack hotplug packets, start first */ in tb_ctl_start()
546 ring_start(ctl->rx); in tb_ctl_start()
548 tb_ctl_rx_submit(ctl->rx_packets[i]); in tb_ctl_start()
559 void tb_ctl_stop(struct tb_ctl *ctl) in tb_ctl_stop() argument
561 ring_stop(ctl->rx); in tb_ctl_stop()
562 ring_stop(ctl->tx); in tb_ctl_stop()
564 if (!kfifo_is_empty(&ctl->response_fifo)) in tb_ctl_stop()
565 tb_ctl_WARN(ctl, "dangling response in response_fifo\n"); in tb_ctl_stop()
566 kfifo_reset(&ctl->response_fifo); in tb_ctl_stop()
567 tb_ctl_info(ctl, "control channel stopped\n"); in tb_ctl_stop()
577 int tb_cfg_error(struct tb_ctl *ctl, u64 route, u32 port, in tb_cfg_error() argument
585 tb_ctl_info(ctl, "resetting error on %llx:%x.\n", route, port); in tb_cfg_error()
586 return tb_ctl_tx(ctl, &pkg, sizeof(pkg), TB_CFG_PKG_ERROR); in tb_cfg_error()
596 struct tb_cfg_result tb_cfg_reset(struct tb_ctl *ctl, u64 route, in tb_cfg_reset() argument
603 err = tb_ctl_tx(ctl, &request, sizeof(request), TB_CFG_PKG_RESET); in tb_cfg_reset()
607 return tb_ctl_rx(ctl, &reply, sizeof(reply), timeout_msec, route, in tb_cfg_reset()
616 struct tb_cfg_result tb_cfg_read_raw(struct tb_ctl *ctl, void *buffer, in tb_cfg_read_raw() argument
632 res.err = tb_ctl_tx(ctl, &request, sizeof(request), TB_CFG_PKG_READ); in tb_cfg_read_raw()
636 res = tb_ctl_rx(ctl, &reply, 12 + 4 * length, timeout_msec, route, in tb_cfg_read_raw()
653 struct tb_cfg_result tb_cfg_write_raw(struct tb_ctl *ctl, void *buffer, in tb_cfg_write_raw() argument
671 res.err = tb_ctl_tx(ctl, &request, 12 + 4 * length, TB_CFG_PKG_WRITE); in tb_cfg_write_raw()
675 res = tb_ctl_rx(ctl, &reply, sizeof(reply), timeout_msec, route, in tb_cfg_write_raw()
685 int tb_cfg_read(struct tb_ctl *ctl, void *buffer, u64 route, u32 port, in tb_cfg_read() argument
688 struct tb_cfg_result res = tb_cfg_read_raw(ctl, buffer, route, port, in tb_cfg_read()
691 tb_cfg_print_error(ctl, &res); in tb_cfg_read()
698 int tb_cfg_write(struct tb_ctl *ctl, void *buffer, u64 route, u32 port, in tb_cfg_write() argument
701 struct tb_cfg_result res = tb_cfg_write_raw(ctl, buffer, route, port, in tb_cfg_write()
704 tb_cfg_print_error(ctl, &res); in tb_cfg_write()
720 int tb_cfg_get_upstream_port(struct tb_ctl *ctl, u64 route) in tb_cfg_get_upstream_port() argument
723 struct tb_cfg_result res = tb_cfg_read_raw(ctl, &dummy, route, 0, in tb_cfg_get_upstream_port()