Lines Matching refs:sw

203 	tb_dump_port(port->sw->tb, &port->config);  in tb_init_port()
212 static void tb_dump_switch(struct tb *tb, struct tb_regs_switch_header *sw) in tb_dump_switch() argument
216 sw->vendor_id, sw->device_id, sw->revision, in tb_dump_switch()
217 sw->thunderbolt_version); in tb_dump_switch()
218 tb_info(tb, " Max Port Number: %d\n", sw->max_port_number); in tb_dump_switch()
222 sw->upstream_port_number, sw->depth, in tb_dump_switch()
223 (((u64) sw->route_hi) << 32) | sw->route_lo, in tb_dump_switch()
224 sw->enabled, sw->plug_events_delay); in tb_dump_switch()
227 sw->__unknown1, sw->__unknown4); in tb_dump_switch()
254 struct tb_switch *get_switch_at_route(struct tb_switch *sw, u64 route) in get_switch_at_route() argument
261 return sw; in get_switch_at_route()
262 if (next_port > sw->config.max_port_number) in get_switch_at_route()
264 if (tb_is_upstream_port(&sw->ports[next_port])) in get_switch_at_route()
266 if (!sw->ports[next_port].remote) in get_switch_at_route()
268 return get_switch_at_route(sw->ports[next_port].remote->sw, in get_switch_at_route()
279 static int tb_plug_events_active(struct tb_switch *sw, bool active) in tb_plug_events_active() argument
284 sw->config.plug_events_delay = 0xff; in tb_plug_events_active()
285 res = tb_sw_write(sw, ((u32 *) &sw->config) + 4, TB_CFG_SWITCH, 4, 1); in tb_plug_events_active()
289 res = tb_sw_read(sw, &data, TB_CFG_SWITCH, sw->cap_plug_events + 1, 1); in tb_plug_events_active()
295 switch (sw->config.device_id) { in tb_plug_events_active()
306 return tb_sw_write(sw, &data, TB_CFG_SWITCH, in tb_plug_events_active()
307 sw->cap_plug_events + 1, 1); in tb_plug_events_active()
314 void tb_switch_free(struct tb_switch *sw) in tb_switch_free() argument
318 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_free()
319 if (tb_is_upstream_port(&sw->ports[i])) in tb_switch_free()
321 if (sw->ports[i].remote) in tb_switch_free()
322 tb_switch_free(sw->ports[i].remote->sw); in tb_switch_free()
323 sw->ports[i].remote = NULL; in tb_switch_free()
326 if (!sw->is_unplugged) in tb_switch_free()
327 tb_plug_events_active(sw, false); in tb_switch_free()
329 kfree(sw->ports); in tb_switch_free()
330 kfree(sw->drom); in tb_switch_free()
331 kfree(sw); in tb_switch_free()
343 struct tb_switch *sw; in tb_switch_alloc() local
348 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in tb_switch_alloc()
349 if (!sw) in tb_switch_alloc()
352 sw->tb = tb; in tb_switch_alloc()
353 if (tb_cfg_read(tb->ctl, &sw->config, route, 0, 2, 0, 5)) in tb_switch_alloc()
359 tb_dump_switch(tb, &sw->config); in tb_switch_alloc()
362 sw->config.upstream_port_number = upstream_port; in tb_switch_alloc()
363 sw->config.depth = tb_route_length(route); in tb_switch_alloc()
364 sw->config.route_lo = route; in tb_switch_alloc()
365 sw->config.route_hi = route >> 32; in tb_switch_alloc()
366 sw->config.enabled = 1; in tb_switch_alloc()
369 if (sw->config.vendor_id != 0x8086) in tb_switch_alloc()
370 tb_sw_warn(sw, "unknown switch vendor id %#x\n", in tb_switch_alloc()
371 sw->config.vendor_id); in tb_switch_alloc()
373 if (sw->config.device_id != 0x1547 && sw->config.device_id != 0x1549) in tb_switch_alloc()
374 tb_sw_warn(sw, "unsupported switch device id %#x\n", in tb_switch_alloc()
375 sw->config.device_id); in tb_switch_alloc()
378 if (tb_sw_write(sw, 1 + (u32 *) &sw->config, TB_CFG_SWITCH, 1, 3)) in tb_switch_alloc()
382 sw->ports = kcalloc(sw->config.max_port_number + 1, sizeof(*sw->ports), in tb_switch_alloc()
384 if (!sw->ports) in tb_switch_alloc()
387 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_alloc()
389 sw->ports[i].sw = sw; in tb_switch_alloc()
390 sw->ports[i].port = i; in tb_switch_alloc()
393 cap = tb_find_cap(&sw->ports[0], TB_CFG_SWITCH, TB_CAP_PLUG_EVENTS); in tb_switch_alloc()
395 tb_sw_warn(sw, "cannot find TB_CAP_PLUG_EVENTS aborting\n"); in tb_switch_alloc()
398 sw->cap_plug_events = cap; in tb_switch_alloc()
401 if (tb_drom_read(sw)) in tb_switch_alloc()
402 tb_sw_warn(sw, "tb_eeprom_read_rom failed, continuing\n"); in tb_switch_alloc()
403 tb_sw_info(sw, "uid: %#llx\n", sw->uid); in tb_switch_alloc()
405 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_switch_alloc()
406 if (sw->ports[i].disabled) { in tb_switch_alloc()
407 tb_port_info(&sw->ports[i], "disabled by eeprom\n"); in tb_switch_alloc()
410 if (tb_init_port(&sw->ports[i])) in tb_switch_alloc()
416 if (tb_plug_events_active(sw, true)) in tb_switch_alloc()
419 return sw; in tb_switch_alloc()
421 kfree(sw->ports); in tb_switch_alloc()
422 kfree(sw->drom); in tb_switch_alloc()
423 kfree(sw); in tb_switch_alloc()
430 void tb_sw_set_unpplugged(struct tb_switch *sw) in tb_sw_set_unpplugged() argument
433 if (sw == sw->tb->root_switch) { in tb_sw_set_unpplugged()
434 tb_sw_WARN(sw, "cannot unplug root switch\n"); in tb_sw_set_unpplugged()
437 if (sw->is_unplugged) { in tb_sw_set_unpplugged()
438 tb_sw_WARN(sw, "is_unplugged already set\n"); in tb_sw_set_unpplugged()
441 sw->is_unplugged = true; in tb_sw_set_unpplugged()
442 for (i = 0; i <= sw->config.max_port_number; i++) { in tb_sw_set_unpplugged()
443 if (!tb_is_upstream_port(&sw->ports[i]) && sw->ports[i].remote) in tb_sw_set_unpplugged()
444 tb_sw_set_unpplugged(sw->ports[i].remote->sw); in tb_sw_set_unpplugged()
448 int tb_switch_resume(struct tb_switch *sw) in tb_switch_resume() argument
452 tb_sw_info(sw, "resuming switch\n"); in tb_switch_resume()
454 err = tb_drom_read_uid_only(sw, &uid); in tb_switch_resume()
456 tb_sw_warn(sw, "uid read failed\n"); in tb_switch_resume()
459 if (sw->uid != uid) { in tb_switch_resume()
460 tb_sw_info(sw, in tb_switch_resume()
462 sw->uid, uid); in tb_switch_resume()
467 err = tb_sw_write(sw, 1 + (u32 *) &sw->config, TB_CFG_SWITCH, 1, 3); in tb_switch_resume()
471 err = tb_plug_events_active(sw, true); in tb_switch_resume()
476 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_resume()
477 struct tb_port *port = &sw->ports[i]; in tb_switch_resume()
483 || tb_switch_resume(port->remote->sw)) { in tb_switch_resume()
486 tb_sw_set_unpplugged(port->remote->sw); in tb_switch_resume()
492 void tb_switch_suspend(struct tb_switch *sw) in tb_switch_suspend() argument
495 err = tb_plug_events_active(sw, false); in tb_switch_suspend()
499 for (i = 1; i <= sw->config.max_port_number; i++) { in tb_switch_suspend()
500 if (!tb_is_upstream_port(&sw->ports[i]) && sw->ports[i].remote) in tb_switch_suspend()
501 tb_switch_suspend(sw->ports[i].remote->sw); in tb_switch_suspend()