1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Thunderbolt driver - bus logic (NHI independent)
5 * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
6 * Copyright (C) 2018, Intel Corporation
12 #include <linux/nvmem-provider.h>
13 #include <linux/pci.h>
14 #include <linux/thunderbolt.h>
15 #include <linux/uuid.h>
21 #define NVM_MIN_SIZE SZ_32K
22 #define NVM_MAX_SIZE SZ_512K
23 #define NVM_DATA_DWORDS 16
25 /* Intel specific NVM offsets */
26 #define NVM_DEVID 0x05
27 #define NVM_VERSION 0x08
28 #define NVM_FLASH_SIZE 0x45
31 * struct tb_nvm - Structure holding NVM information
32 * @dev: Owner of the NVM
33 * @major: Major version number of the active NVM portion
34 * @minor: Minor version number of the active NVM portion
35 * @id: Identifier used with both NVM portions
36 * @active: Active portion NVMem device
37 * @non_active: Non-active portion NVMem device
38 * @buf: Buffer where the NVM image is stored before it is written to
39 * the actual NVM flash device
40 * @buf_data_size: Number of bytes actually consumed by the new NVM
42 * @authenticating: The device is authenticating the new NVM
43 * @flushed: The image has been flushed to the storage area
45 * The user of this structure needs to handle serialization of possible
53 struct nvmem_device *active;
54 struct nvmem_device *non_active;
61 enum tb_nvm_write_ops {
62 WRITE_AND_AUTHENTICATE = 1,
64 AUTHENTICATE_ONLY = 3,
67 #define TB_SWITCH_KEY_SIZE 32
68 #define TB_SWITCH_MAX_DEPTH 6
69 #define USB4_SWITCH_MAX_DEPTH 5
72 * enum tb_switch_tmu_rate - TMU refresh rate
73 * @TB_SWITCH_TMU_RATE_OFF: %0 (Disable Time Sync handshake)
74 * @TB_SWITCH_TMU_RATE_HIFI: %16 us time interval between successive
75 * transmission of the Delay Request TSNOS
76 * (Time Sync Notification Ordered Set) on a Link
77 * @TB_SWITCH_TMU_RATE_NORMAL: %1 ms time interval between successive
78 * transmission of the Delay Request TSNOS on
81 enum tb_switch_tmu_rate {
82 TB_SWITCH_TMU_RATE_OFF = 0,
83 TB_SWITCH_TMU_RATE_HIFI = 16,
84 TB_SWITCH_TMU_RATE_NORMAL = 1000,
88 * struct tb_switch_tmu - Structure holding switch TMU configuration
89 * @cap: Offset to the TMU capability (%0 if not found)
90 * @has_ucap: Does the switch support uni-directional mode
91 * @rate: TMU refresh rate related to upstream switch. In case of root
92 * switch this holds the domain rate. Reflects the HW setting.
93 * @unidirectional: Is the TMU in uni-directional or bi-directional mode
94 * related to upstream switch. Don't care for root switch.
95 * Reflects the HW setting.
96 * @unidirectional_request: Is the new TMU mode: uni-directional or bi-directional
97 * that is requested to be set. Related to upstream switch.
98 * Don't care for root switch.
99 * @rate_request: TMU new refresh rate related to upstream switch that is
100 * requested to be set. In case of root switch, this holds
101 * the new domain rate that is requested to be set.
103 struct tb_switch_tmu {
106 enum tb_switch_tmu_rate rate;
108 bool unidirectional_request;
109 enum tb_switch_tmu_rate rate_request;
120 * struct tb_switch - a thunderbolt switch
121 * @dev: Device for the switch
122 * @config: Switch configuration
123 * @ports: Ports in this switch
124 * @dma_port: If the switch has port supporting DMA configuration based
125 * mailbox this will hold the pointer to that (%NULL
126 * otherwise). If set it also means the switch has
128 * @tmu: The switch TMU configuration
129 * @tb: Pointer to the domain the switch belongs to
130 * @uid: Unique ID of the switch
131 * @uuid: UUID of the switch (or %NULL if not supported)
132 * @vendor: Vendor ID of the switch
133 * @device: Device ID of the switch
134 * @vendor_name: Name of the vendor (or %NULL if not known)
135 * @device_name: Name of the device (or %NULL if not known)
136 * @link_speed: Speed of the link in Gb/s
137 * @link_width: Width of the link (1 or 2)
138 * @link_usb4: Upstream link is USB4
139 * @generation: Switch Thunderbolt generation
140 * @cap_plug_events: Offset to the plug events capability (%0 if not found)
141 * @cap_vsec_tmu: Offset to the TMU vendor specific capability (%0 if not found)
142 * @cap_lc: Offset to the link controller capability (%0 if not found)
143 * @cap_lp: Offset to the low power (CLx for TBT) capability (%0 if not found)
144 * @is_unplugged: The switch is going away
145 * @drom: DROM of the switch (%NULL if not found)
146 * @nvm: Pointer to the NVM if the switch has one (%NULL otherwise)
147 * @no_nvm_upgrade: Prevent NVM upgrade of this switch
148 * @safe_mode: The switch is in safe-mode
149 * @boot: Whether the switch was already authorized on boot or not
150 * @rpm: The switch supports runtime PM
151 * @authorized: Whether the switch is authorized by user or policy
152 * @security_level: Switch supported security level
153 * @debugfs_dir: Pointer to the debugfs structure
154 * @key: Contains the key used to challenge the device or %NULL if not
155 * supported. Size of the key is %TB_SWITCH_KEY_SIZE.
156 * @connection_id: Connection ID used with ICM messaging
157 * @connection_key: Connection key used with ICM messaging
158 * @link: Root switch link this switch is connected (ICM only)
159 * @depth: Depth in the chain this switch is connected (ICM only)
160 * @rpm_complete: Completion used to wait for runtime resume to
161 * complete (ICM only)
162 * @quirks: Quirks used for this Thunderbolt switch
163 * @credit_allocation: Are the below buffer allocation parameters valid
164 * @max_usb3_credits: Router preferred number of buffers for USB 3.x
165 * @min_dp_aux_credits: Router preferred minimum number of buffers for DP AUX
166 * @min_dp_main_credits: Router preferred minimum number of buffers for DP MAIN
167 * @max_pcie_credits: Router preferred number of buffers for PCIe
168 * @max_dma_credits: Router preferred number of buffers for DMA/P2P
169 * @clx: CLx state on the upstream link of the router
171 * When the switch is being added or removed to the domain (other
172 * switches) you need to have domain lock held.
174 * In USB4 terminology this structure represents a router.
178 struct tb_regs_switch_header config;
179 struct tb_port *ports;
180 struct tb_dma_port *dma_port;
181 struct tb_switch_tmu tmu;
187 const char *vendor_name;
188 const char *device_name;
189 unsigned int link_speed;
190 unsigned int link_width;
192 unsigned int generation;
204 unsigned int authorized;
205 enum tb_security_level security_level;
206 struct dentry *debugfs_dir;
212 struct completion rpm_complete;
213 unsigned long quirks;
214 bool credit_allocation;
215 unsigned int max_usb3_credits;
216 unsigned int min_dp_aux_credits;
217 unsigned int min_dp_main_credits;
218 unsigned int max_pcie_credits;
219 unsigned int max_dma_credits;
224 * struct tb_port - a thunderbolt port, part of a tb_switch
225 * @config: Cached port configuration read from registers
226 * @sw: Switch the port belongs to
227 * @remote: Remote port (%NULL if not connected)
228 * @xdomain: Remote host (%NULL if not connected)
229 * @cap_phy: Offset, zero if not found
230 * @cap_tmu: Offset of the adapter specific TMU capability (%0 if not present)
231 * @cap_adap: Offset of the adapter specific capability (%0 if not present)
232 * @cap_usb4: Offset to the USB4 port capability (%0 if not present)
233 * @usb4: Pointer to the USB4 port structure (only if @cap_usb4 is != %0)
234 * @port: Port number on switch
235 * @disabled: Disabled by eeprom or enabled but not implemented
236 * @bonded: true if the port is bonded (two lanes combined as one)
237 * @dual_link_port: If the switch is connected using two ports, points
239 * @link_nr: Is this primary or secondary port on the dual_link.
240 * @in_hopids: Currently allocated input HopIDs
241 * @out_hopids: Currently allocated output HopIDs
242 * @list: Used to link ports to DP resources list
243 * @total_credits: Total number of buffers available for this port
244 * @ctl_credits: Buffers reserved for control path
245 * @dma_credits: Number of credits allocated for DMA tunneling for all
246 * DMA paths through this port.
248 * In USB4 terminology this structure represents an adapter (protocol or
252 struct tb_regs_port_header config;
253 struct tb_switch *sw;
254 struct tb_port *remote;
255 struct tb_xdomain *xdomain;
260 struct usb4_port *usb4;
264 struct tb_port *dual_link_port;
266 struct ida in_hopids;
267 struct ida out_hopids;
268 struct list_head list;
269 unsigned int total_credits;
270 unsigned int ctl_credits;
271 unsigned int dma_credits;
275 * struct usb4_port - USB4 port device
276 * @dev: Device for the port
277 * @port: Pointer to the lane 0 adapter
278 * @can_offline: Does the port have necessary platform support to moved
279 * it into offline mode and back
280 * @offline: The port is currently in offline mode
284 struct tb_port *port;
290 * tb_retimer: Thunderbolt retimer
291 * @dev: Device for the retimer
292 * @tb: Pointer to the domain the retimer belongs to
293 * @index: Retimer index facing the router USB4 port
294 * @vendor: Vendor ID of the retimer
295 * @device: Device ID of the retimer
296 * @port: Pointer to the lane 0 adapter
297 * @nvm: Pointer to the NVM if the retimer has one (%NULL otherwise)
298 * @auth_status: Status of last NVM authentication
306 struct tb_port *port;
312 * struct tb_path_hop - routing information for a tb_path
313 * @in_port: Ingress port of a switch
314 * @out_port: Egress port of a switch where the packet is routed out
315 * (must be on the same switch than @in_port)
316 * @in_hop_index: HopID where the path configuration entry is placed in
317 * the path config space of @in_port.
318 * @in_counter_index: Used counter index (not used in the driver
319 * currently, %-1 to disable)
320 * @next_hop_index: HopID of the packet when it is routed out from @out_port
321 * @initial_credits: Number of initial flow control credits allocated for
323 * @nfc_credits: Number of non-flow controlled buffers allocated for the
326 * Hop configuration is always done on the IN port of a switch.
327 * in_port and out_port have to be on the same switch. Packets arriving on
328 * in_port with "hop" = in_hop_index will get routed to through out_port. The
329 * next hop to take (on out_port->remote) is determined by
330 * next_hop_index. When routing packet to another switch (out->remote is
331 * set) the @next_hop_index must match the @in_hop_index of that next
332 * hop to make routing possible.
334 * in_counter_index is the index of a counter (in TB_CFG_COUNTERS) on the in
338 struct tb_port *in_port;
339 struct tb_port *out_port;
341 int in_counter_index;
343 unsigned int initial_credits;
344 unsigned int nfc_credits;
348 * enum tb_path_port - path options mask
349 * @TB_PATH_NONE: Do not activate on any hop on path
350 * @TB_PATH_SOURCE: Activate on the first hop (out of src)
351 * @TB_PATH_INTERNAL: Activate on the intermediate hops (not the first/last)
352 * @TB_PATH_DESTINATION: Activate on the last hop (into dst)
353 * @TB_PATH_ALL: Activate on all hops on the path
358 TB_PATH_INTERNAL = 2,
359 TB_PATH_DESTINATION = 4,
364 * struct tb_path - a unidirectional path between two ports
365 * @tb: Pointer to the domain structure
366 * @name: Name of the path (used for debugging)
367 * @ingress_shared_buffer: Shared buffering used for ingress ports on the path
368 * @egress_shared_buffer: Shared buffering used for egress ports on the path
369 * @ingress_fc_enable: Flow control for ingress ports on the path
370 * @egress_fc_enable: Flow control for egress ports on the path
371 * @priority: Priority group if the path
372 * @weight: Weight of the path inside the priority group
373 * @drop_packages: Drop packages from queue tail or head
374 * @activated: Is the path active
375 * @clear_fc: Clear all flow control from the path config space entries
376 * when deactivating this path
378 * @path_length: How many hops the path uses
379 * @alloc_hopid: Does this path consume port HopID
381 * A path consists of a number of hops (see &struct tb_path_hop). To
382 * establish a PCIe tunnel two paths have to be created between the two
388 enum tb_path_port ingress_shared_buffer;
389 enum tb_path_port egress_shared_buffer;
390 enum tb_path_port ingress_fc_enable;
391 enum tb_path_port egress_fc_enable;
393 unsigned int priority:3;
398 struct tb_path_hop *hops;
403 /* HopIDs 0-7 are reserved by the Thunderbolt protocol */
404 #define TB_PATH_MIN_HOPID 8
406 * Support paths from the farthest (depth 6) router to the host and back
407 * to the same level (not necessarily to the same router).
409 #define TB_PATH_MAX_HOPS (7 * 2)
411 /* Possible wake types */
412 #define TB_WAKE_ON_CONNECT BIT(0)
413 #define TB_WAKE_ON_DISCONNECT BIT(1)
414 #define TB_WAKE_ON_USB4 BIT(2)
415 #define TB_WAKE_ON_USB3 BIT(3)
416 #define TB_WAKE_ON_PCIE BIT(4)
417 #define TB_WAKE_ON_DP BIT(5)
420 * struct tb_cm_ops - Connection manager specific operations vector
421 * @driver_ready: Called right after control channel is started. Used by
422 * ICM to send driver ready message to the firmware.
423 * @start: Starts the domain
424 * @stop: Stops the domain
425 * @suspend_noirq: Connection manager specific suspend_noirq
426 * @resume_noirq: Connection manager specific resume_noirq
427 * @suspend: Connection manager specific suspend
428 * @freeze_noirq: Connection manager specific freeze_noirq
429 * @thaw_noirq: Connection manager specific thaw_noirq
430 * @complete: Connection manager specific complete
431 * @runtime_suspend: Connection manager specific runtime_suspend
432 * @runtime_resume: Connection manager specific runtime_resume
433 * @runtime_suspend_switch: Runtime suspend a switch
434 * @runtime_resume_switch: Runtime resume a switch
435 * @handle_event: Handle thunderbolt event
436 * @get_boot_acl: Get boot ACL list
437 * @set_boot_acl: Set boot ACL list
438 * @disapprove_switch: Disapprove switch (disconnect PCIe tunnel)
439 * @approve_switch: Approve switch
440 * @add_switch_key: Add key to switch
441 * @challenge_switch_key: Challenge switch using key
442 * @disconnect_pcie_paths: Disconnects PCIe paths before NVM update
443 * @approve_xdomain_paths: Approve (establish) XDomain DMA paths
444 * @disconnect_xdomain_paths: Disconnect XDomain DMA paths
445 * @usb4_switch_op: Optional proxy for USB4 router operations. If set
446 * this will be called whenever USB4 router operation is
447 * performed. If this returns %-EOPNOTSUPP then the
448 * native USB4 router operation is called.
449 * @usb4_switch_nvm_authenticate_status: Optional callback that the CM
450 * implementation can be used to
451 * return status of USB4 NVM_AUTH
455 int (*driver_ready)(struct tb *tb);
456 int (*start)(struct tb *tb);
457 void (*stop)(struct tb *tb);
458 int (*suspend_noirq)(struct tb *tb);
459 int (*resume_noirq)(struct tb *tb);
460 int (*suspend)(struct tb *tb);
461 int (*freeze_noirq)(struct tb *tb);
462 int (*thaw_noirq)(struct tb *tb);
463 void (*complete)(struct tb *tb);
464 int (*runtime_suspend)(struct tb *tb);
465 int (*runtime_resume)(struct tb *tb);
466 int (*runtime_suspend_switch)(struct tb_switch *sw);
467 int (*runtime_resume_switch)(struct tb_switch *sw);
468 void (*handle_event)(struct tb *tb, enum tb_cfg_pkg_type,
469 const void *buf, size_t size);
470 int (*get_boot_acl)(struct tb *tb, uuid_t *uuids, size_t nuuids);
471 int (*set_boot_acl)(struct tb *tb, const uuid_t *uuids, size_t nuuids);
472 int (*disapprove_switch)(struct tb *tb, struct tb_switch *sw);
473 int (*approve_switch)(struct tb *tb, struct tb_switch *sw);
474 int (*add_switch_key)(struct tb *tb, struct tb_switch *sw);
475 int (*challenge_switch_key)(struct tb *tb, struct tb_switch *sw,
476 const u8 *challenge, u8 *response);
477 int (*disconnect_pcie_paths)(struct tb *tb);
478 int (*approve_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd,
479 int transmit_path, int transmit_ring,
480 int receive_path, int receive_ring);
481 int (*disconnect_xdomain_paths)(struct tb *tb, struct tb_xdomain *xd,
482 int transmit_path, int transmit_ring,
483 int receive_path, int receive_ring);
484 int (*usb4_switch_op)(struct tb_switch *sw, u16 opcode, u32 *metadata,
485 u8 *status, const void *tx_data, size_t tx_data_len,
486 void *rx_data, size_t rx_data_len);
487 int (*usb4_switch_nvm_authenticate_status)(struct tb_switch *sw,
491 static inline void *tb_priv(struct tb *tb)
493 return (void *)tb->privdata;
496 #define TB_AUTOSUSPEND_DELAY 15000 /* ms */
498 /* helper functions & macros */
501 * tb_upstream_port() - return the upstream port of a switch
503 * Every switch has an upstream port (for the root switch it is the NHI).
505 * During switch alloc/init tb_upstream_port()->remote may be NULL, even for
506 * non root switches (on the NHI port remote is always NULL).
508 * Return: Returns the upstream port of the switch.
510 static inline struct tb_port *tb_upstream_port(struct tb_switch *sw)
512 return &sw->ports[sw->config.upstream_port_number];
516 * tb_is_upstream_port() - Is the port upstream facing
517 * @port: Port to check
519 * Returns true if @port is upstream facing port. In case of dual link
520 * ports both return true.
522 static inline bool tb_is_upstream_port(const struct tb_port *port)
524 const struct tb_port *upstream_port = tb_upstream_port(port->sw);
525 return port == upstream_port || port->dual_link_port == upstream_port;
528 static inline u64 tb_route(const struct tb_switch *sw)
530 return ((u64) sw->config.route_hi) << 32 | sw->config.route_lo;
533 static inline struct tb_port *tb_port_at(u64 route, struct tb_switch *sw)
537 port = route >> (sw->config.depth * 8);
538 if (WARN_ON(port > sw->config.max_port_number))
540 return &sw->ports[port];
544 * tb_port_has_remote() - Does the port have switch connected downstream
545 * @port: Port to check
547 * Returns true only when the port is primary port and has remote set.
549 static inline bool tb_port_has_remote(const struct tb_port *port)
551 if (tb_is_upstream_port(port))
555 if (port->dual_link_port && port->link_nr)
561 static inline bool tb_port_is_null(const struct tb_port *port)
563 return port && port->port && port->config.type == TB_TYPE_PORT;
566 static inline bool tb_port_is_nhi(const struct tb_port *port)
568 return port && port->config.type == TB_TYPE_NHI;
571 static inline bool tb_port_is_pcie_down(const struct tb_port *port)
573 return port && port->config.type == TB_TYPE_PCIE_DOWN;
576 static inline bool tb_port_is_pcie_up(const struct tb_port *port)
578 return port && port->config.type == TB_TYPE_PCIE_UP;
581 static inline bool tb_port_is_dpin(const struct tb_port *port)
583 return port && port->config.type == TB_TYPE_DP_HDMI_IN;
586 static inline bool tb_port_is_dpout(const struct tb_port *port)
588 return port && port->config.type == TB_TYPE_DP_HDMI_OUT;
591 static inline bool tb_port_is_usb3_down(const struct tb_port *port)
593 return port && port->config.type == TB_TYPE_USB3_DOWN;
596 static inline bool tb_port_is_usb3_up(const struct tb_port *port)
598 return port && port->config.type == TB_TYPE_USB3_UP;
601 static inline int tb_sw_read(struct tb_switch *sw, void *buffer,
602 enum tb_cfg_space space, u32 offset, u32 length)
604 if (sw->is_unplugged)
606 return tb_cfg_read(sw->tb->ctl,
615 static inline int tb_sw_write(struct tb_switch *sw, const void *buffer,
616 enum tb_cfg_space space, u32 offset, u32 length)
618 if (sw->is_unplugged)
620 return tb_cfg_write(sw->tb->ctl,
629 static inline int tb_port_read(struct tb_port *port, void *buffer,
630 enum tb_cfg_space space, u32 offset, u32 length)
632 if (port->sw->is_unplugged)
634 return tb_cfg_read(port->sw->tb->ctl,
643 static inline int tb_port_write(struct tb_port *port, const void *buffer,
644 enum tb_cfg_space space, u32 offset, u32 length)
646 if (port->sw->is_unplugged)
648 return tb_cfg_write(port->sw->tb->ctl,
657 #define tb_err(tb, fmt, arg...) dev_err(&(tb)->nhi->pdev->dev, fmt, ## arg)
658 #define tb_WARN(tb, fmt, arg...) dev_WARN(&(tb)->nhi->pdev->dev, fmt, ## arg)
659 #define tb_warn(tb, fmt, arg...) dev_warn(&(tb)->nhi->pdev->dev, fmt, ## arg)
660 #define tb_info(tb, fmt, arg...) dev_info(&(tb)->nhi->pdev->dev, fmt, ## arg)
661 #define tb_dbg(tb, fmt, arg...) dev_dbg(&(tb)->nhi->pdev->dev, fmt, ## arg)
663 #define __TB_SW_PRINT(level, sw, fmt, arg...) \
665 const struct tb_switch *__sw = (sw); \
666 level(__sw->tb, "%llx: " fmt, \
667 tb_route(__sw), ## arg); \
669 #define tb_sw_WARN(sw, fmt, arg...) __TB_SW_PRINT(tb_WARN, sw, fmt, ##arg)
670 #define tb_sw_warn(sw, fmt, arg...) __TB_SW_PRINT(tb_warn, sw, fmt, ##arg)
671 #define tb_sw_info(sw, fmt, arg...) __TB_SW_PRINT(tb_info, sw, fmt, ##arg)
672 #define tb_sw_dbg(sw, fmt, arg...) __TB_SW_PRINT(tb_dbg, sw, fmt, ##arg)
674 #define __TB_PORT_PRINT(level, _port, fmt, arg...) \
676 const struct tb_port *__port = (_port); \
677 level(__port->sw->tb, "%llx:%x: " fmt, \
678 tb_route(__port->sw), __port->port, ## arg); \
680 #define tb_port_WARN(port, fmt, arg...) \
681 __TB_PORT_PRINT(tb_WARN, port, fmt, ##arg)
682 #define tb_port_warn(port, fmt, arg...) \
683 __TB_PORT_PRINT(tb_warn, port, fmt, ##arg)
684 #define tb_port_info(port, fmt, arg...) \
685 __TB_PORT_PRINT(tb_info, port, fmt, ##arg)
686 #define tb_port_dbg(port, fmt, arg...) \
687 __TB_PORT_PRINT(tb_dbg, port, fmt, ##arg)
689 struct tb *icm_probe(struct tb_nhi *nhi);
690 struct tb *tb_probe(struct tb_nhi *nhi);
692 extern struct device_type tb_domain_type;
693 extern struct device_type tb_retimer_type;
694 extern struct device_type tb_switch_type;
695 extern struct device_type usb4_port_device_type;
697 int tb_domain_init(void);
698 void tb_domain_exit(void);
699 int tb_xdomain_init(void);
700 void tb_xdomain_exit(void);
702 struct tb *tb_domain_alloc(struct tb_nhi *nhi, int timeout_msec, size_t privsize);
703 int tb_domain_add(struct tb *tb);
704 void tb_domain_remove(struct tb *tb);
705 int tb_domain_suspend_noirq(struct tb *tb);
706 int tb_domain_resume_noirq(struct tb *tb);
707 int tb_domain_suspend(struct tb *tb);
708 int tb_domain_freeze_noirq(struct tb *tb);
709 int tb_domain_thaw_noirq(struct tb *tb);
710 void tb_domain_complete(struct tb *tb);
711 int tb_domain_runtime_suspend(struct tb *tb);
712 int tb_domain_runtime_resume(struct tb *tb);
713 int tb_domain_disapprove_switch(struct tb *tb, struct tb_switch *sw);
714 int tb_domain_approve_switch(struct tb *tb, struct tb_switch *sw);
715 int tb_domain_approve_switch_key(struct tb *tb, struct tb_switch *sw);
716 int tb_domain_challenge_switch_key(struct tb *tb, struct tb_switch *sw);
717 int tb_domain_disconnect_pcie_paths(struct tb *tb);
718 int tb_domain_approve_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
719 int transmit_path, int transmit_ring,
720 int receive_path, int receive_ring);
721 int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
722 int transmit_path, int transmit_ring,
723 int receive_path, int receive_ring);
724 int tb_domain_disconnect_all_paths(struct tb *tb);
726 static inline struct tb *tb_domain_get(struct tb *tb)
729 get_device(&tb->dev);
733 static inline void tb_domain_put(struct tb *tb)
735 put_device(&tb->dev);
738 struct tb_nvm *tb_nvm_alloc(struct device *dev);
739 int tb_nvm_add_active(struct tb_nvm *nvm, size_t size, nvmem_reg_read_t reg_read);
740 int tb_nvm_write_buf(struct tb_nvm *nvm, unsigned int offset, void *val,
742 int tb_nvm_add_non_active(struct tb_nvm *nvm, size_t size,
743 nvmem_reg_write_t reg_write);
744 void tb_nvm_free(struct tb_nvm *nvm);
745 void tb_nvm_exit(void);
747 typedef int (*read_block_fn)(void *, unsigned int, void *, size_t);
748 typedef int (*write_block_fn)(void *, unsigned int, const void *, size_t);
750 int tb_nvm_read_data(unsigned int address, void *buf, size_t size,
751 unsigned int retries, read_block_fn read_block,
752 void *read_block_data);
753 int tb_nvm_write_data(unsigned int address, const void *buf, size_t size,
754 unsigned int retries, write_block_fn write_next_block,
755 void *write_block_data);
757 struct tb_switch *tb_switch_alloc(struct tb *tb, struct device *parent,
759 struct tb_switch *tb_switch_alloc_safe_mode(struct tb *tb,
760 struct device *parent, u64 route);
761 int tb_switch_configure(struct tb_switch *sw);
762 int tb_switch_add(struct tb_switch *sw);
763 void tb_switch_remove(struct tb_switch *sw);
764 void tb_switch_suspend(struct tb_switch *sw, bool runtime);
765 int tb_switch_resume(struct tb_switch *sw);
766 int tb_switch_reset(struct tb_switch *sw);
767 int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit,
768 u32 value, int timeout_msec);
769 void tb_sw_set_unplugged(struct tb_switch *sw);
770 struct tb_port *tb_switch_find_port(struct tb_switch *sw,
771 enum tb_port_type type);
772 struct tb_switch *tb_switch_find_by_link_depth(struct tb *tb, u8 link,
774 struct tb_switch *tb_switch_find_by_uuid(struct tb *tb, const uuid_t *uuid);
775 struct tb_switch *tb_switch_find_by_route(struct tb *tb, u64 route);
778 * tb_switch_for_each_port() - Iterate over each switch port
779 * @sw: Switch whose ports to iterate
780 * @p: Port used as iterator
782 * Iterates over each switch port skipping the control port (port %0).
784 #define tb_switch_for_each_port(sw, p) \
785 for ((p) = &(sw)->ports[1]; \
786 (p) <= &(sw)->ports[(sw)->config.max_port_number]; (p)++)
788 static inline struct tb_switch *tb_switch_get(struct tb_switch *sw)
791 get_device(&sw->dev);
795 static inline void tb_switch_put(struct tb_switch *sw)
797 put_device(&sw->dev);
800 static inline bool tb_is_switch(const struct device *dev)
802 return dev->type == &tb_switch_type;
805 static inline struct tb_switch *tb_to_switch(struct device *dev)
807 if (tb_is_switch(dev))
808 return container_of(dev, struct tb_switch, dev);
812 static inline struct tb_switch *tb_switch_parent(struct tb_switch *sw)
814 return tb_to_switch(sw->dev.parent);
817 static inline bool tb_switch_is_light_ridge(const struct tb_switch *sw)
819 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL &&
820 sw->config.device_id == PCI_DEVICE_ID_INTEL_LIGHT_RIDGE;
823 static inline bool tb_switch_is_eagle_ridge(const struct tb_switch *sw)
825 return sw->config.vendor_id == PCI_VENDOR_ID_INTEL &&
826 sw->config.device_id == PCI_DEVICE_ID_INTEL_EAGLE_RIDGE;
829 static inline bool tb_switch_is_cactus_ridge(const struct tb_switch *sw)
831 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
832 switch (sw->config.device_id) {
833 case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_2C:
834 case PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C:
841 static inline bool tb_switch_is_falcon_ridge(const struct tb_switch *sw)
843 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
844 switch (sw->config.device_id) {
845 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE:
846 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE:
853 static inline bool tb_switch_is_alpine_ridge(const struct tb_switch *sw)
855 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
856 switch (sw->config.device_id) {
857 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_2C_BRIDGE:
858 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_LP_BRIDGE:
859 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_4C_BRIDGE:
860 case PCI_DEVICE_ID_INTEL_ALPINE_RIDGE_C_2C_BRIDGE:
867 static inline bool tb_switch_is_titan_ridge(const struct tb_switch *sw)
869 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
870 switch (sw->config.device_id) {
871 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_2C_BRIDGE:
872 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_4C_BRIDGE:
873 case PCI_DEVICE_ID_INTEL_TITAN_RIDGE_DD_BRIDGE:
880 static inline bool tb_switch_is_tiger_lake(const struct tb_switch *sw)
882 if (sw->config.vendor_id == PCI_VENDOR_ID_INTEL) {
883 switch (sw->config.device_id) {
884 case PCI_DEVICE_ID_INTEL_TGL_NHI0:
885 case PCI_DEVICE_ID_INTEL_TGL_NHI1:
886 case PCI_DEVICE_ID_INTEL_TGL_H_NHI0:
887 case PCI_DEVICE_ID_INTEL_TGL_H_NHI1:
895 * tb_switch_is_usb4() - Is the switch USB4 compliant
896 * @sw: Switch to check
898 * Returns true if the @sw is USB4 compliant router, false otherwise.
900 static inline bool tb_switch_is_usb4(const struct tb_switch *sw)
902 return sw->config.thunderbolt_version == USB4_VERSION_1_0;
906 * tb_switch_is_icm() - Is the switch handled by ICM firmware
907 * @sw: Switch to check
909 * In case there is a need to differentiate whether ICM firmware or SW CM
910 * is handling @sw this function can be called. It is valid to call this
911 * after tb_switch_alloc() and tb_switch_configure() has been called
912 * (latter only for SW CM case).
914 static inline bool tb_switch_is_icm(const struct tb_switch *sw)
916 return !sw->config.enabled;
919 int tb_switch_lane_bonding_enable(struct tb_switch *sw);
920 void tb_switch_lane_bonding_disable(struct tb_switch *sw);
921 int tb_switch_configure_link(struct tb_switch *sw);
922 void tb_switch_unconfigure_link(struct tb_switch *sw);
924 bool tb_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
925 int tb_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
926 void tb_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
928 int tb_switch_tmu_init(struct tb_switch *sw);
929 int tb_switch_tmu_post_time(struct tb_switch *sw);
930 int tb_switch_tmu_disable(struct tb_switch *sw);
931 int tb_switch_tmu_enable(struct tb_switch *sw);
932 void tb_switch_tmu_configure(struct tb_switch *sw,
933 enum tb_switch_tmu_rate rate,
934 bool unidirectional);
936 * tb_switch_tmu_hifi_is_enabled() - Checks if the specified TMU mode is enabled
937 * @sw: Router whose TMU mode to check
938 * @unidirectional: If uni-directional (bi-directional otherwise)
940 * Return true if hardware TMU configuration matches the one passed in
941 * as parameter. That is HiFi and either uni-directional or bi-directional.
943 static inline bool tb_switch_tmu_hifi_is_enabled(const struct tb_switch *sw,
946 return sw->tmu.rate == TB_SWITCH_TMU_RATE_HIFI &&
947 sw->tmu.unidirectional == unidirectional;
950 int tb_switch_enable_clx(struct tb_switch *sw, enum tb_clx clx);
951 int tb_switch_disable_clx(struct tb_switch *sw, enum tb_clx clx);
954 * tb_switch_is_clx_enabled() - Checks if the CLx is enabled
955 * @sw: Router to check the CLx state for
957 * Checks if the CLx is enabled on the router upstream link.
958 * Not applicable for a host router.
960 static inline bool tb_switch_is_clx_enabled(const struct tb_switch *sw)
962 return sw->clx != TB_CLX_DISABLE;
966 * tb_switch_is_cl0s_enabled() - Checks if the CL0s is enabled
967 * @sw: Router to check for the CL0s
969 * Checks if the CL0s is enabled on the router upstream link.
970 * Not applicable for a host router.
972 static inline bool tb_switch_is_cl0s_enabled(const struct tb_switch *sw)
974 return sw->clx == TB_CL0S;
978 * tb_switch_is_clx_supported() - Is CLx supported on this type of router
979 * @sw: The router to check CLx support for
981 static inline bool tb_switch_is_clx_supported(const struct tb_switch *sw)
983 return tb_switch_is_usb4(sw) || tb_switch_is_titan_ridge(sw);
986 int tb_switch_mask_clx_objections(struct tb_switch *sw);
988 int tb_switch_pcie_l1_enable(struct tb_switch *sw);
990 int tb_wait_for_port(struct tb_port *port, bool wait_if_unplugged);
991 int tb_port_add_nfc_credits(struct tb_port *port, int credits);
992 int tb_port_clear_counter(struct tb_port *port, int counter);
993 int tb_port_unlock(struct tb_port *port);
994 int tb_port_enable(struct tb_port *port);
995 int tb_port_disable(struct tb_port *port);
996 int tb_port_alloc_in_hopid(struct tb_port *port, int hopid, int max_hopid);
997 void tb_port_release_in_hopid(struct tb_port *port, int hopid);
998 int tb_port_alloc_out_hopid(struct tb_port *port, int hopid, int max_hopid);
999 void tb_port_release_out_hopid(struct tb_port *port, int hopid);
1000 struct tb_port *tb_next_port_on_path(struct tb_port *start, struct tb_port *end,
1001 struct tb_port *prev);
1003 static inline bool tb_port_use_credit_allocation(const struct tb_port *port)
1005 return tb_port_is_null(port) && port->sw->credit_allocation;
1009 * tb_for_each_port_on_path() - Iterate over each port on path
1011 * @dst: Destination port
1012 * @p: Port used as iterator
1014 * Walks over each port on path from @src to @dst.
1016 #define tb_for_each_port_on_path(src, dst, p) \
1017 for ((p) = tb_next_port_on_path((src), (dst), NULL); (p); \
1018 (p) = tb_next_port_on_path((src), (dst), (p)))
1020 int tb_port_get_link_speed(struct tb_port *port);
1021 int tb_port_get_link_width(struct tb_port *port);
1022 int tb_port_state(struct tb_port *port);
1023 int tb_port_lane_bonding_enable(struct tb_port *port);
1024 void tb_port_lane_bonding_disable(struct tb_port *port);
1025 int tb_port_wait_for_link_width(struct tb_port *port, int width,
1027 int tb_port_update_credits(struct tb_port *port);
1029 int tb_switch_find_vse_cap(struct tb_switch *sw, enum tb_switch_vse_cap vsec);
1030 int tb_switch_find_cap(struct tb_switch *sw, enum tb_switch_cap cap);
1031 int tb_switch_next_cap(struct tb_switch *sw, unsigned int offset);
1032 int tb_port_find_cap(struct tb_port *port, enum tb_port_cap cap);
1033 int tb_port_next_cap(struct tb_port *port, unsigned int offset);
1034 bool tb_port_is_enabled(struct tb_port *port);
1036 bool tb_usb3_port_is_enabled(struct tb_port *port);
1037 int tb_usb3_port_enable(struct tb_port *port, bool enable);
1039 bool tb_pci_port_is_enabled(struct tb_port *port);
1040 int tb_pci_port_enable(struct tb_port *port, bool enable);
1042 int tb_dp_port_hpd_is_active(struct tb_port *port);
1043 int tb_dp_port_hpd_clear(struct tb_port *port);
1044 int tb_dp_port_set_hops(struct tb_port *port, unsigned int video,
1045 unsigned int aux_tx, unsigned int aux_rx);
1046 bool tb_dp_port_is_enabled(struct tb_port *port);
1047 int tb_dp_port_enable(struct tb_port *port, bool enable);
1049 struct tb_path *tb_path_discover(struct tb_port *src, int src_hopid,
1050 struct tb_port *dst, int dst_hopid,
1051 struct tb_port **last, const char *name,
1053 struct tb_path *tb_path_alloc(struct tb *tb, struct tb_port *src, int src_hopid,
1054 struct tb_port *dst, int dst_hopid, int link_nr,
1056 void tb_path_free(struct tb_path *path);
1057 int tb_path_activate(struct tb_path *path);
1058 void tb_path_deactivate(struct tb_path *path);
1059 bool tb_path_is_invalid(struct tb_path *path);
1060 bool tb_path_port_on_path(const struct tb_path *path,
1061 const struct tb_port *port);
1064 * tb_path_for_each_hop() - Iterate over each hop on path
1065 * @path: Path whose hops to iterate
1066 * @hop: Hop used as iterator
1068 * Iterates over each hop on path.
1070 #define tb_path_for_each_hop(path, hop) \
1071 for ((hop) = &(path)->hops[0]; \
1072 (hop) <= &(path)->hops[(path)->path_length - 1]; (hop)++)
1074 int tb_drom_read(struct tb_switch *sw);
1075 int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid);
1077 int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid);
1078 int tb_lc_configure_port(struct tb_port *port);
1079 void tb_lc_unconfigure_port(struct tb_port *port);
1080 int tb_lc_configure_xdomain(struct tb_port *port);
1081 void tb_lc_unconfigure_xdomain(struct tb_port *port);
1082 int tb_lc_start_lane_initialization(struct tb_port *port);
1083 bool tb_lc_is_clx_supported(struct tb_port *port);
1084 int tb_lc_set_wake(struct tb_switch *sw, unsigned int flags);
1085 int tb_lc_set_sleep(struct tb_switch *sw);
1086 bool tb_lc_lane_bonding_possible(struct tb_switch *sw);
1087 bool tb_lc_dp_sink_query(struct tb_switch *sw, struct tb_port *in);
1088 int tb_lc_dp_sink_alloc(struct tb_switch *sw, struct tb_port *in);
1089 int tb_lc_dp_sink_dealloc(struct tb_switch *sw, struct tb_port *in);
1090 int tb_lc_force_power(struct tb_switch *sw);
1092 static inline int tb_route_length(u64 route)
1094 return (fls64(route) + TB_ROUTE_SHIFT - 1) / TB_ROUTE_SHIFT;
1098 * tb_downstream_route() - get route to downstream switch
1100 * Port must not be the upstream port (otherwise a loop is created).
1102 * Return: Returns a route to the switch behind @port.
1104 static inline u64 tb_downstream_route(struct tb_port *port)
1106 return tb_route(port->sw)
1107 | ((u64) port->port << (port->sw->config.depth * 8));
1110 bool tb_is_xdomain_enabled(void);
1111 bool tb_xdomain_handle_request(struct tb *tb, enum tb_cfg_pkg_type type,
1112 const void *buf, size_t size);
1113 struct tb_xdomain *tb_xdomain_alloc(struct tb *tb, struct device *parent,
1114 u64 route, const uuid_t *local_uuid,
1115 const uuid_t *remote_uuid);
1116 void tb_xdomain_add(struct tb_xdomain *xd);
1117 void tb_xdomain_remove(struct tb_xdomain *xd);
1118 struct tb_xdomain *tb_xdomain_find_by_link_depth(struct tb *tb, u8 link,
1121 int tb_retimer_scan(struct tb_port *port, bool add);
1122 void tb_retimer_remove_all(struct tb_port *port);
1124 static inline bool tb_is_retimer(const struct device *dev)
1126 return dev->type == &tb_retimer_type;
1129 static inline struct tb_retimer *tb_to_retimer(struct device *dev)
1131 if (tb_is_retimer(dev))
1132 return container_of(dev, struct tb_retimer, dev);
1136 int usb4_switch_setup(struct tb_switch *sw);
1137 int usb4_switch_read_uid(struct tb_switch *sw, u64 *uid);
1138 int usb4_switch_drom_read(struct tb_switch *sw, unsigned int address, void *buf,
1140 bool usb4_switch_lane_bonding_possible(struct tb_switch *sw);
1141 int usb4_switch_set_wake(struct tb_switch *sw, unsigned int flags);
1142 int usb4_switch_set_sleep(struct tb_switch *sw);
1143 int usb4_switch_nvm_sector_size(struct tb_switch *sw);
1144 int usb4_switch_nvm_read(struct tb_switch *sw, unsigned int address, void *buf,
1146 int usb4_switch_nvm_set_offset(struct tb_switch *sw, unsigned int address);
1147 int usb4_switch_nvm_write(struct tb_switch *sw, unsigned int address,
1148 const void *buf, size_t size);
1149 int usb4_switch_nvm_authenticate(struct tb_switch *sw);
1150 int usb4_switch_nvm_authenticate_status(struct tb_switch *sw, u32 *status);
1151 int usb4_switch_credits_init(struct tb_switch *sw);
1152 bool usb4_switch_query_dp_resource(struct tb_switch *sw, struct tb_port *in);
1153 int usb4_switch_alloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1154 int usb4_switch_dealloc_dp_resource(struct tb_switch *sw, struct tb_port *in);
1155 struct tb_port *usb4_switch_map_pcie_down(struct tb_switch *sw,
1156 const struct tb_port *port);
1157 struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw,
1158 const struct tb_port *port);
1159 int usb4_switch_add_ports(struct tb_switch *sw);
1160 void usb4_switch_remove_ports(struct tb_switch *sw);
1162 int usb4_port_unlock(struct tb_port *port);
1163 int usb4_port_configure(struct tb_port *port);
1164 void usb4_port_unconfigure(struct tb_port *port);
1165 int usb4_port_configure_xdomain(struct tb_port *port);
1166 void usb4_port_unconfigure_xdomain(struct tb_port *port);
1167 int usb4_port_router_offline(struct tb_port *port);
1168 int usb4_port_router_online(struct tb_port *port);
1169 int usb4_port_enumerate_retimers(struct tb_port *port);
1170 bool usb4_port_clx_supported(struct tb_port *port);
1172 int usb4_port_retimer_set_inbound_sbtx(struct tb_port *port, u8 index);
1173 int usb4_port_retimer_read(struct tb_port *port, u8 index, u8 reg, void *buf,
1175 int usb4_port_retimer_write(struct tb_port *port, u8 index, u8 reg,
1176 const void *buf, u8 size);
1177 int usb4_port_retimer_is_last(struct tb_port *port, u8 index);
1178 int usb4_port_retimer_nvm_sector_size(struct tb_port *port, u8 index);
1179 int usb4_port_retimer_nvm_set_offset(struct tb_port *port, u8 index,
1180 unsigned int address);
1181 int usb4_port_retimer_nvm_write(struct tb_port *port, u8 index,
1182 unsigned int address, const void *buf,
1184 int usb4_port_retimer_nvm_authenticate(struct tb_port *port, u8 index);
1185 int usb4_port_retimer_nvm_authenticate_status(struct tb_port *port, u8 index,
1187 int usb4_port_retimer_nvm_read(struct tb_port *port, u8 index,
1188 unsigned int address, void *buf, size_t size);
1190 int usb4_usb3_port_max_link_rate(struct tb_port *port);
1191 int usb4_usb3_port_actual_link_rate(struct tb_port *port);
1192 int usb4_usb3_port_allocated_bandwidth(struct tb_port *port, int *upstream_bw,
1193 int *downstream_bw);
1194 int usb4_usb3_port_allocate_bandwidth(struct tb_port *port, int *upstream_bw,
1195 int *downstream_bw);
1196 int usb4_usb3_port_release_bandwidth(struct tb_port *port, int *upstream_bw,
1197 int *downstream_bw);
1199 static inline bool tb_is_usb4_port_device(const struct device *dev)
1201 return dev->type == &usb4_port_device_type;
1204 static inline struct usb4_port *tb_to_usb4_port_device(struct device *dev)
1206 if (tb_is_usb4_port_device(dev))
1207 return container_of(dev, struct usb4_port, dev);
1211 struct usb4_port *usb4_port_device_add(struct tb_port *port);
1212 void usb4_port_device_remove(struct usb4_port *usb4);
1213 int usb4_port_device_resume(struct usb4_port *usb4);
1215 /* Keep link controller awake during update */
1216 #define QUIRK_FORCE_POWER_LINK_CONTROLLER BIT(0)
1218 void tb_check_quirks(struct tb_switch *sw);
1221 void tb_acpi_add_links(struct tb_nhi *nhi);
1223 bool tb_acpi_is_native(void);
1224 bool tb_acpi_may_tunnel_usb3(void);
1225 bool tb_acpi_may_tunnel_dp(void);
1226 bool tb_acpi_may_tunnel_pcie(void);
1227 bool tb_acpi_is_xdomain_allowed(void);
1229 int tb_acpi_init(void);
1230 void tb_acpi_exit(void);
1231 int tb_acpi_power_on_retimers(struct tb_port *port);
1232 int tb_acpi_power_off_retimers(struct tb_port *port);
1234 static inline void tb_acpi_add_links(struct tb_nhi *nhi) { }
1236 static inline bool tb_acpi_is_native(void) { return true; }
1237 static inline bool tb_acpi_may_tunnel_usb3(void) { return true; }
1238 static inline bool tb_acpi_may_tunnel_dp(void) { return true; }
1239 static inline bool tb_acpi_may_tunnel_pcie(void) { return true; }
1240 static inline bool tb_acpi_is_xdomain_allowed(void) { return true; }
1242 static inline int tb_acpi_init(void) { return 0; }
1243 static inline void tb_acpi_exit(void) { }
1244 static inline int tb_acpi_power_on_retimers(struct tb_port *port) { return 0; }
1245 static inline int tb_acpi_power_off_retimers(struct tb_port *port) { return 0; }
1248 #ifdef CONFIG_DEBUG_FS
1249 void tb_debugfs_init(void);
1250 void tb_debugfs_exit(void);
1251 void tb_switch_debugfs_init(struct tb_switch *sw);
1252 void tb_switch_debugfs_remove(struct tb_switch *sw);
1253 void tb_service_debugfs_init(struct tb_service *svc);
1254 void tb_service_debugfs_remove(struct tb_service *svc);
1256 static inline void tb_debugfs_init(void) { }
1257 static inline void tb_debugfs_exit(void) { }
1258 static inline void tb_switch_debugfs_init(struct tb_switch *sw) { }
1259 static inline void tb_switch_debugfs_remove(struct tb_switch *sw) { }
1260 static inline void tb_service_debugfs_init(struct tb_service *svc) { }
1261 static inline void tb_service_debugfs_remove(struct tb_service *svc) { }
1264 #ifdef CONFIG_USB4_KUNIT_TEST
1265 int tb_test_init(void);
1266 void tb_test_exit(void);
1268 static inline int tb_test_init(void) { return 0; }
1269 static inline void tb_test_exit(void) { }