/* * Thunderbolt Cactus Ridge driver - PCIe tunnel * * Copyright (c) 2014 Andreas Noever */ #include #include #include "tunnel_pci.h" #include "tb.h" #define __TB_TUNNEL_PRINT(level, tunnel, fmt, arg...) \ do { \ struct tb_pci_tunnel *__tunnel = (tunnel); \ level(__tunnel->tb, "%llx:%x <-> %llx:%x (PCI): " fmt, \ tb_route(__tunnel->down_port->sw), \ __tunnel->down_port->port, \ tb_route(__tunnel->up_port->sw), \ __tunnel->up_port->port, \ ## arg); \ } while (0) #define tb_tunnel_WARN(tunnel, fmt, arg...) \ __TB_TUNNEL_PRINT(tb_WARN, tunnel, fmt, ##arg) #define tb_tunnel_warn(tunnel, fmt, arg...) \ __TB_TUNNEL_PRINT(tb_warn, tunnel, fmt, ##arg) #define tb_tunnel_info(tunnel, fmt, arg...) \ __TB_TUNNEL_PRINT(tb_info, tunnel, fmt, ##arg) static void tb_pci_init_path(struct tb_path *path) { path->egress_fc_enable = TB_PATH_SOURCE | TB_PATH_INTERNAL; path->egress_shared_buffer = TB_PATH_NONE; path->ingress_fc_enable = TB_PATH_ALL; path->ingress_shared_buffer = TB_PATH_NONE; path->priority = 3; path->weight = 1; path->drop_packages = 0; path->nfc_credits = 0; } /** * tb_pci_alloc() - allocate a pci tunnel * * Allocate a PCI tunnel. The ports must be of type TB_TYPE_PCIE_UP and * TB_TYPE_PCIE_DOWN. * * Currently only paths consisting of two hops are supported (that is the * ports must be on "adjacent" switches). * * The paths are hard-coded to use hop 8 (the only working hop id available on * my thunderbolt devices). Therefore at most ONE path per device may be * activated. * * Return: Returns a tb_pci_tunnel on success or NULL on failure. */ struct tb_pci_tunnel *tb_pci_alloc(struct tb *tb, struct tb_port *up, struct tb_port *down) { struct tb_pci_tunnel *tunnel = kzalloc(sizeof(*tunnel), GFP_KERNEL); if (!tunnel) goto err; tunnel->tb = tb; tunnel->down_port = down; tunnel->up_port = up; INIT_LIST_HEAD(&tunnel->list); tunnel->path_to_up = tb_path_alloc(up->sw->tb, 2); if (!tunnel->path_to_up) goto err; tunnel->path_to_down = tb_path_alloc(up->sw->tb, 2); if (!tunnel->path_to_down) goto err; tb_pci_init_path(tunnel->path_to_up); tb_pci_init_path(tunnel->path_to_down); tunnel->path_to_up->hops[0].in_port = down; tunnel->path_to_up->hops[0].in_hop_index = 8; tunnel->path_to_up->hops[0].in_counter_index = -1; tunnel->path_to_up->hops[0].out_port = tb_upstream_port(up->sw)->remote; tunnel->path_to_up->hops[0].next_hop_index = 8; tunnel->path_to_up->hops[1].in_port = tb_upstream_port(up->sw); tunnel->path_to_up->hops[1].in_hop_index = 8; tunnel->path_to_up->hops[1].in_counter_index = -1; tunnel->path_to_up->hops[1].out_port = up; tunnel->path_to_up->hops[1].next_hop_index = 8; tunnel->path_to_down->hops[0].in_port = up; tunnel->path_to_down->hops[0].in_hop_index = 8; tunnel->path_to_down->hops[0].in_counter_index = -1; tunnel->path_to_down->hops[0].out_port = tb_upstream_port(up->sw); tunnel->path_to_down->hops[0].next_hop_index = 8; tunnel->path_to_down->hops[1].in_port = tb_upstream_port(up->sw)->remote; tunnel->path_to_down->hops[1].in_hop_index = 8; tunnel->path_to_down->hops[1].in_counter_index = -1; tunnel->path_to_down->hops[1].out_port = down; tunnel->path_to_down->hops[1].next_hop_index = 8; return tunnel; err: if (tunnel) { if (tunnel->path_to_down) tb_path_free(tunnel->path_to_down); if (tunnel->path_to_up) tb_path_free(tunnel->path_to_up); kfree(tunnel); } return NULL; } /** * tb_pci_free() - free a tunnel * * The tunnel must have been deactivated. */ void tb_pci_free(struct tb_pci_tunnel *tunnel) { if (tunnel->path_to_up->activated || tunnel->path_to_down->activated) { tb_tunnel_WARN(tunnel, "trying to free an activated tunnel\n"); return; } tb_path_free(tunnel->path_to_up); tb_path_free(tunnel->path_to_down); kfree(tunnel); } /** * tb_pci_is_invalid - check whether an activated path is still valid */ bool tb_pci_is_invalid(struct tb_pci_tunnel *tunnel) { WARN_ON(!tunnel->path_to_up->activated); WARN_ON(!tunnel->path_to_down->activated); return tb_path_is_invalid(tunnel->path_to_up) || tb_path_is_invalid(tunnel->path_to_down); } /** * tb_pci_port_active() - activate/deactivate PCI capability * * Return: Returns 0 on success or an error code on failure. */ static int tb_pci_port_active(struct tb_port *port, bool active) { u32 word = active ? 0x80000000 : 0x0; int cap = tb_find_cap(port, TB_CFG_PORT, TB_CAP_PCIE); if (cap <= 0) { tb_port_warn(port, "TB_CAP_PCIE not found: %d\n", cap); return cap ? cap : -ENXIO; } return tb_port_write(port, &word, TB_CFG_PORT, cap, 1); } /** * tb_pci_restart() - activate a tunnel after a hardware reset */ int tb_pci_restart(struct tb_pci_tunnel *tunnel) { int res; tunnel->path_to_up->activated = false; tunnel->path_to_down->activated = false; tb_tunnel_info(tunnel, "activating\n"); res = tb_path_activate(tunnel->path_to_up); if (res) goto err; res = tb_path_activate(tunnel->path_to_down); if (res) goto err; res = tb_pci_port_active(tunnel->down_port, true); if (res) goto err; res = tb_pci_port_active(tunnel->up_port, true); if (res) goto err; return 0; err: tb_tunnel_warn(tunnel, "activation failed\n"); tb_pci_deactivate(tunnel); return res; } /** * tb_pci_activate() - activate a tunnel * * Return: Returns 0 on success or an error code on failure. */ int tb_pci_activate(struct tb_pci_tunnel *tunnel) { int res; if (tunnel->path_to_up->activated || tunnel->path_to_down->activated) { tb_tunnel_WARN(tunnel, "trying to activate an already activated tunnel\n"); return -EINVAL; } res = tb_pci_restart(tunnel); if (res) return res; list_add(&tunnel->list, &tunnel->tb->tunnel_list); return 0; } /** * tb_pci_deactivate() - deactivate a tunnel */ void tb_pci_deactivate(struct tb_pci_tunnel *tunnel) { tb_tunnel_info(tunnel, "deactivating\n"); /* * TODO: enable reset by writing 0x04000000 to TB_CAP_PCIE + 1 on up * port. Seems to have no effect? */ tb_pci_port_active(tunnel->up_port, false); tb_pci_port_active(tunnel->down_port, false); if (tunnel->path_to_down->activated) tb_path_deactivate(tunnel->path_to_down); if (tunnel->path_to_up->activated) tb_path_deactivate(tunnel->path_to_up); list_del_init(&tunnel->list); } -rotation-180 ============================================================================= BUG kmalloc-128 (Tainted: G U ): Object already free ----------------------------------------------------------------------------- Disabling lock debugging due to kernel taint INFO: Allocated in drm_atomic_helper_setup_commit+0x285/0x2f0 [drm_kms_helper] age=0 cpu=3 pid=1529 ___slab_alloc+0x308/0x3b0 __slab_alloc+0xd/0x20 kmem_cache_alloc_trace+0x92/0x1c0 drm_atomic_helper_setup_commit+0x285/0x2f0 [drm_kms_helper] intel_atomic_commit+0x35/0x4f0 [i915] drm_atomic_commit+0x46/0x50 [drm] drm_mode_atomic_ioctl+0x7d4/0xab0 [drm] drm_ioctl+0x2b3/0x490 [drm] do_vfs_ioctl+0x69c/0x700 SyS_ioctl+0x4e/0x80 entry_SYSCALL_64_fastpath+0x13/0x94 INFO: Freed in drm_event_cancel_free+0xa3/0xb0 [drm] age=0 cpu=3 pid=1529 __slab_free+0x48/0x2e0 kfree+0x159/0x1a0 drm_event_cancel_free+0xa3/0xb0 [drm] drm_mode_atomic_ioctl+0x86d/0xab0 [drm] drm_ioctl+0x2b3/0x490 [drm] do_vfs_ioctl+0x69c/0x700 SyS_ioctl+0x4e/0x80 entry_SYSCALL_64_fastpath+0x13/0x94 INFO: Slab 0xffffde1f0997b080 objects=17 used=2 fp=0xffff92fb65ec2578 flags=0x200000000008101 INFO: Object 0xffff92fb65ec2578 @offset=1400 fp=0xffff92fb65ec2ae8 Redzone ffff92fb65ec2570: bb bb bb bb bb bb bb bb ........ Object ffff92fb65ec2578: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec2588: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec2598: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25a8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25b8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25c8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25d8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b kkkkkkkkkkkkkkkk Object ffff92fb65ec25e8: 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b 6b a5 kkkkkkkkkkkkkkk. Redzone ffff92fb65ec25f8: bb bb bb bb bb bb bb bb ........ Padding ffff92fb65ec2738: 5a 5a 5a 5a 5a 5a 5a 5a ZZZZZZZZ CPU: 3 PID: 180 Comm: kworker/3:2 Tainted: G BU 4.10.0-rc6-patser+ #5039 Hardware name: /NUC5PPYB, BIOS PYBSWCEL.86A.0031.2015.0601.1712 06/01/2015 Workqueue: events intel_atomic_helper_free_state [i915] Call Trace: dump_stack+0x4d/0x6d print_trailer+0x20c/0x220 free_debug_processing+0x1c6/0x330 ? drm_atomic_state_default_clear+0xf7/0x1c0 [drm] __slab_free+0x48/0x2e0 ? drm_atomic_state_default_clear+0xf7/0x1c0 [drm] kfree+0x159/0x1a0 drm_atomic_state_default_clear+0xf7/0x1c0 [drm] ? drm_atomic_state_clear+0x30/0x30 [drm] intel_atomic_state_clear+0xd/0x20 [i915] drm_atomic_state_clear+0x1a/0x30 [drm] __drm_atomic_state_free+0x13/0x60 [drm] intel_atomic_helper_free_state+0x5d/0x70 [i915] process_one_work+0x260/0x4a0 worker_thread+0x2d1/0x4f0 kthread+0x127/0x130 ? process_one_work+0x4a0/0x4a0 ? kthread_stop+0x120/0x120 ret_from_fork+0x29/0x40 FIX kmalloc-128: Object at 0xffff92fb65ec2578 not freed Fixes: 3b24f7d67581 ("drm/atomic: Add struct drm_crtc_commit to track async updates") Fixes: 9626014258a5 ("drm/fence: add in-fences support") Cc: <stable@vger.kernel.org> # v4.8+ Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/1485854725-27640-1-git-send-email-maarten.lankhorst@linux.intel.com
Diffstat (limited to 'fs/afs/cache.c')