Lines Matching refs:rt

29 int tb_retimer_nvm_read(struct tb_retimer *rt, unsigned int address, void *buf,  in tb_retimer_nvm_read()  argument
32 return usb4_port_retimer_nvm_read(rt->port, rt->index, address, buf, size); in tb_retimer_nvm_read()
38 struct tb_retimer *rt = tb_to_retimer(nvm->dev); in nvm_read() local
41 pm_runtime_get_sync(&rt->dev); in nvm_read()
43 if (!mutex_trylock(&rt->tb->lock)) { in nvm_read()
48 ret = tb_retimer_nvm_read(rt, offset, val, bytes); in nvm_read()
49 mutex_unlock(&rt->tb->lock); in nvm_read()
52 pm_runtime_mark_last_busy(&rt->dev); in nvm_read()
53 pm_runtime_put_autosuspend(&rt->dev); in nvm_read()
61 struct tb_retimer *rt = tb_to_retimer(nvm->dev); in nvm_write() local
64 if (!mutex_trylock(&rt->tb->lock)) in nvm_write()
68 mutex_unlock(&rt->tb->lock); in nvm_write()
73 static int tb_retimer_nvm_add(struct tb_retimer *rt) in tb_retimer_nvm_add() argument
78 nvm = tb_nvm_alloc(&rt->dev); in tb_retimer_nvm_add()
96 rt->nvm = nvm; in tb_retimer_nvm_add()
100 dev_dbg(&rt->dev, "NVM upgrade disabled\n"); in tb_retimer_nvm_add()
107 static int tb_retimer_nvm_validate_and_write(struct tb_retimer *rt) in tb_retimer_nvm_validate_and_write() argument
113 ret = tb_nvm_validate(rt->nvm); in tb_retimer_nvm_validate_and_write()
117 buf = rt->nvm->buf_data_start; in tb_retimer_nvm_validate_and_write()
118 image_size = rt->nvm->buf_data_size; in tb_retimer_nvm_validate_and_write()
120 ret = usb4_port_retimer_nvm_write(rt->port, rt->index, 0, buf, in tb_retimer_nvm_validate_and_write()
125 rt->nvm->flushed = true; in tb_retimer_nvm_validate_and_write()
129 static int tb_retimer_nvm_authenticate(struct tb_retimer *rt, bool auth_only) in tb_retimer_nvm_authenticate() argument
135 ret = usb4_port_retimer_nvm_set_offset(rt->port, rt->index, 0); in tb_retimer_nvm_authenticate()
140 ret = usb4_port_retimer_nvm_authenticate(rt->port, rt->index); in tb_retimer_nvm_authenticate()
150 ret = usb4_port_retimer_nvm_authenticate_status(rt->port, rt->index, in tb_retimer_nvm_authenticate()
153 rt->auth_status = status; in tb_retimer_nvm_authenticate()
163 struct tb_retimer *rt = tb_to_retimer(dev); in device_show() local
165 return sysfs_emit(buf, "%#x\n", rt->device); in device_show()
172 struct tb_retimer *rt = tb_to_retimer(dev); in nvm_authenticate_show() local
175 if (!mutex_trylock(&rt->tb->lock)) in nvm_authenticate_show()
178 if (!rt->nvm) in nvm_authenticate_show()
180 else if (rt->no_nvm_upgrade) in nvm_authenticate_show()
183 ret = sysfs_emit(buf, "%#x\n", rt->auth_status); in nvm_authenticate_show()
185 mutex_unlock(&rt->tb->lock); in nvm_authenticate_show()
243 struct tb_retimer *rt = tb_to_retimer(dev); in nvm_authenticate_store() local
246 pm_runtime_get_sync(&rt->dev); in nvm_authenticate_store()
248 if (!mutex_trylock(&rt->tb->lock)) { in nvm_authenticate_store()
253 if (!rt->nvm) { in nvm_authenticate_store()
263 rt->auth_status = 0; in nvm_authenticate_store()
273 tb_retimer_set_inbound_sbtx(rt->port); in nvm_authenticate_store()
275 ret = tb_retimer_nvm_authenticate(rt, true); in nvm_authenticate_store()
277 if (!rt->nvm->flushed) { in nvm_authenticate_store()
278 if (!rt->nvm->buf) { in nvm_authenticate_store()
283 ret = tb_retimer_nvm_validate_and_write(rt); in nvm_authenticate_store()
288 ret = tb_retimer_nvm_authenticate(rt, false); in nvm_authenticate_store()
294 tb_retimer_unset_inbound_sbtx(rt->port); in nvm_authenticate_store()
295 mutex_unlock(&rt->tb->lock); in nvm_authenticate_store()
297 pm_runtime_mark_last_busy(&rt->dev); in nvm_authenticate_store()
298 pm_runtime_put_autosuspend(&rt->dev); in nvm_authenticate_store()
309 struct tb_retimer *rt = tb_to_retimer(dev); in nvm_version_show() local
312 if (!mutex_trylock(&rt->tb->lock)) in nvm_version_show()
315 if (!rt->nvm) in nvm_version_show()
318 ret = sysfs_emit(buf, "%x.%x\n", rt->nvm->major, rt->nvm->minor); in nvm_version_show()
320 mutex_unlock(&rt->tb->lock); in nvm_version_show()
328 struct tb_retimer *rt = tb_to_retimer(dev); in vendor_show() local
330 return sysfs_emit(buf, "%#x\n", rt->vendor); in vendor_show()
353 struct tb_retimer *rt = tb_to_retimer(dev); in tb_retimer_release() local
355 kfree(rt); in tb_retimer_release()
366 struct tb_retimer *rt; in tb_retimer_add() local
394 rt = kzalloc(sizeof(*rt), GFP_KERNEL); in tb_retimer_add()
395 if (!rt) in tb_retimer_add()
398 rt->index = index; in tb_retimer_add()
399 rt->vendor = vendor; in tb_retimer_add()
400 rt->device = device; in tb_retimer_add()
401 rt->auth_status = auth_status; in tb_retimer_add()
402 rt->port = port; in tb_retimer_add()
403 rt->tb = port->sw->tb; in tb_retimer_add()
405 rt->dev.parent = &port->usb4->dev; in tb_retimer_add()
406 rt->dev.bus = &tb_bus_type; in tb_retimer_add()
407 rt->dev.type = &tb_retimer_type; in tb_retimer_add()
408 dev_set_name(&rt->dev, "%s:%u.%u", dev_name(&port->sw->dev), in tb_retimer_add()
411 ret = device_register(&rt->dev); in tb_retimer_add()
413 dev_err(&rt->dev, "failed to register retimer: %d\n", ret); in tb_retimer_add()
414 put_device(&rt->dev); in tb_retimer_add()
418 ret = tb_retimer_nvm_add(rt); in tb_retimer_add()
420 dev_err(&rt->dev, "failed to add NVM devices: %d\n", ret); in tb_retimer_add()
421 device_unregister(&rt->dev); in tb_retimer_add()
425 dev_info(&rt->dev, "new retimer found, vendor=%#x device=%#x\n", in tb_retimer_add()
426 rt->vendor, rt->device); in tb_retimer_add()
428 pm_runtime_no_callbacks(&rt->dev); in tb_retimer_add()
429 pm_runtime_set_active(&rt->dev); in tb_retimer_add()
430 pm_runtime_enable(&rt->dev); in tb_retimer_add()
431 pm_runtime_set_autosuspend_delay(&rt->dev, TB_AUTOSUSPEND_DELAY); in tb_retimer_add()
432 pm_runtime_mark_last_busy(&rt->dev); in tb_retimer_add()
433 pm_runtime_use_autosuspend(&rt->dev); in tb_retimer_add()
438 static void tb_retimer_remove(struct tb_retimer *rt) in tb_retimer_remove() argument
440 dev_info(&rt->dev, "retimer disconnected\n"); in tb_retimer_remove()
441 tb_nvm_free(rt->nvm); in tb_retimer_remove()
442 device_unregister(&rt->dev); in tb_retimer_remove()
453 struct tb_retimer *rt = tb_to_retimer(dev); in retimer_match() local
455 return rt && rt->port == lookup->port && rt->index == lookup->index; in retimer_match()
526 struct tb_retimer *rt; in tb_retimer_scan() local
528 rt = tb_port_find_retimer(port, i); in tb_retimer_scan()
529 if (rt) { in tb_retimer_scan()
530 put_device(&rt->dev); in tb_retimer_scan()
543 struct tb_retimer *rt = tb_to_retimer(dev); in remove_retimer() local
546 if (rt && rt->port == port) in remove_retimer()
547 tb_retimer_remove(rt); in remove_retimer()