Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thunderbolt: Move driver ready handling to struct icm

Intel Titan Ridge uses slightly different format for ICM driver ready
response, so add a new ->driver_ready() callback to struct icm and move
the existing handling to a separate function which we then use in Falcon
Ridge and Alpine Ridge.

No functional changes intended.

Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

+35 -13
+31 -11
drivers/thunderbolt/icm.c
··· 59 59 * @is_supported: Checks if we can support ICM on this controller 60 60 * @get_mode: Read and return the ICM firmware mode (optional) 61 61 * @get_route: Find a route string for given switch 62 + * @driver_ready: Send driver ready message to ICM 62 63 * @device_connected: Handle device connected ICM message 63 64 * @device_disconnected: Handle device disconnected ICM message 64 65 * @xdomain_connected - Handle XDomain connected ICM message ··· 74 73 bool (*is_supported)(struct tb *tb); 75 74 int (*get_mode)(struct tb *tb); 76 75 int (*get_route)(struct tb *tb, u8 link, u8 depth, u64 *route); 76 + int (*driver_ready)(struct tb *tb, 77 + enum tb_security_level *security_level); 77 78 void (*device_connected)(struct tb *tb, 78 79 const struct icm_pkg_header *hdr); 79 80 void (*device_disconnected)(struct tb *tb, ··· 247 244 err_free: 248 245 kfree(switches); 249 246 return ret; 247 + } 248 + 249 + static int 250 + icm_fr_driver_ready(struct tb *tb, enum tb_security_level *security_level) 251 + { 252 + struct icm_fr_pkg_driver_ready_response reply; 253 + struct icm_pkg_driver_ready request = { 254 + .hdr.code = ICM_DRIVER_READY, 255 + }; 256 + int ret; 257 + 258 + memset(&reply, 0, sizeof(reply)); 259 + ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), 260 + 1, ICM_TIMEOUT); 261 + if (ret) 262 + return ret; 263 + 264 + if (security_level) 265 + *security_level = reply.security_level & ICM_FR_SLEVEL_MASK; 266 + 267 + return 0; 250 268 } 251 269 252 270 static int icm_fr_approve_switch(struct tb *tb, struct tb_switch *sw) ··· 893 869 static int 894 870 __icm_driver_ready(struct tb *tb, enum tb_security_level *security_level) 895 871 { 896 - struct icm_pkg_driver_ready_response reply; 897 - struct icm_pkg_driver_ready request = { 898 - .hdr.code = ICM_DRIVER_READY, 899 - }; 872 + struct icm *icm = tb_priv(tb); 900 873 unsigned int retries = 50; 901 874 int ret; 902 875 903 - memset(&reply, 0, sizeof(reply)); 904 - ret = icm_request(tb, &request, sizeof(request), &reply, sizeof(reply), 905 - 1, ICM_TIMEOUT); 906 - if (ret) 876 + ret = icm->driver_ready(tb, security_level); 877 + if (ret) { 878 + tb_err(tb, "failed to send driver ready to ICM\n"); 907 879 return ret; 908 - 909 - if (security_level) 910 - *security_level = reply.security_level & 0xf; 880 + } 911 881 912 882 /* 913 883 * Hold on here until the switch config space is accessible so ··· 1347 1329 case PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI: 1348 1330 icm->is_supported = icm_fr_is_supported; 1349 1331 icm->get_route = icm_fr_get_route; 1332 + icm->driver_ready = icm_fr_driver_ready; 1350 1333 icm->device_connected = icm_fr_device_connected; 1351 1334 icm->device_disconnected = icm_fr_device_disconnected; 1352 1335 icm->xdomain_connected = icm_fr_xdomain_connected; ··· 1363 1344 icm->is_supported = icm_ar_is_supported; 1364 1345 icm->get_mode = icm_ar_get_mode; 1365 1346 icm->get_route = icm_ar_get_route; 1347 + icm->driver_ready = icm_fr_driver_ready; 1366 1348 icm->device_connected = icm_fr_device_connected; 1367 1349 icm->device_disconnected = icm_fr_device_disconnected; 1368 1350 icm->xdomain_connected = icm_fr_xdomain_connected;
+4 -2
drivers/thunderbolt/tb_msgs.h
··· 127 127 struct icm_pkg_header hdr; 128 128 }; 129 129 130 - struct icm_pkg_driver_ready_response { 130 + /* Falcon Ridge & Alpine Ridge common messages */ 131 + 132 + struct icm_fr_pkg_driver_ready_response { 131 133 struct icm_pkg_header hdr; 132 134 u8 romver; 133 135 u8 ramver; 134 136 u16 security_level; 135 137 }; 136 138 137 - /* Falcon Ridge & Alpine Ridge common messages */ 139 + #define ICM_FR_SLEVEL_MASK 0xf 138 140 139 141 struct icm_fr_pkg_get_topology { 140 142 struct icm_pkg_header hdr;