eeprom.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Thunderbolt driver - eeprom access
  4. *
  5. * Copyright (c) 2014 Andreas Noever <andreas.noever@gmail.com>
  6. * Copyright (C) 2018, Intel Corporation
  7. */
  8. #include <linux/crc32.h>
  9. #include <linux/delay.h>
  10. #include <linux/property.h>
  11. #include <linux/slab.h>
  12. #include "tb.h"
  13. /*
  14. * tb_eeprom_ctl_write() - write control word
  15. */
  16. static int tb_eeprom_ctl_write(struct tb_switch *sw, struct tb_eeprom_ctl *ctl)
  17. {
  18. return tb_sw_write(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + ROUTER_CS_4, 1);
  19. }
  20. /*
  21. * tb_eeprom_ctl_write() - read control word
  22. */
  23. static int tb_eeprom_ctl_read(struct tb_switch *sw, struct tb_eeprom_ctl *ctl)
  24. {
  25. return tb_sw_read(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + ROUTER_CS_4, 1);
  26. }
  27. enum tb_eeprom_transfer {
  28. TB_EEPROM_IN,
  29. TB_EEPROM_OUT,
  30. };
  31. /*
  32. * tb_eeprom_active - enable rom access
  33. *
  34. * WARNING: Always disable access after usage. Otherwise the controller will
  35. * fail to reprobe.
  36. */
  37. static int tb_eeprom_active(struct tb_switch *sw, bool enable)
  38. {
  39. struct tb_eeprom_ctl ctl;
  40. int res = tb_eeprom_ctl_read(sw, &ctl);
  41. if (res)
  42. return res;
  43. if (enable) {
  44. ctl.bit_banging_enable = 1;
  45. res = tb_eeprom_ctl_write(sw, &ctl);
  46. if (res)
  47. return res;
  48. ctl.fl_cs = 0;
  49. return tb_eeprom_ctl_write(sw, &ctl);
  50. } else {
  51. ctl.fl_cs = 1;
  52. res = tb_eeprom_ctl_write(sw, &ctl);
  53. if (res)
  54. return res;
  55. ctl.bit_banging_enable = 0;
  56. return tb_eeprom_ctl_write(sw, &ctl);
  57. }
  58. }
  59. /*
  60. * tb_eeprom_transfer - transfer one bit
  61. *
  62. * If TB_EEPROM_IN is passed, then the bit can be retrieved from ctl->fl_do.
  63. * If TB_EEPROM_OUT is passed, then ctl->fl_di will be written.
  64. */
  65. static int tb_eeprom_transfer(struct tb_switch *sw, struct tb_eeprom_ctl *ctl,
  66. enum tb_eeprom_transfer direction)
  67. {
  68. int res;
  69. if (direction == TB_EEPROM_OUT) {
  70. res = tb_eeprom_ctl_write(sw, ctl);
  71. if (res)
  72. return res;
  73. }
  74. ctl->fl_sk = 1;
  75. res = tb_eeprom_ctl_write(sw, ctl);
  76. if (res)
  77. return res;
  78. if (direction == TB_EEPROM_IN) {
  79. res = tb_eeprom_ctl_read(sw, ctl);
  80. if (res)
  81. return res;
  82. }
  83. ctl->fl_sk = 0;
  84. return tb_eeprom_ctl_write(sw, ctl);
  85. }
  86. /*
  87. * tb_eeprom_out - write one byte to the bus
  88. */
  89. static int tb_eeprom_out(struct tb_switch *sw, u8 val)
  90. {
  91. struct tb_eeprom_ctl ctl;
  92. int i;
  93. int res = tb_eeprom_ctl_read(sw, &ctl);
  94. if (res)
  95. return res;
  96. for (i = 0; i < 8; i++) {
  97. ctl.fl_di = val & 0x80;
  98. res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_OUT);
  99. if (res)
  100. return res;
  101. val <<= 1;
  102. }
  103. return 0;
  104. }
  105. /*
  106. * tb_eeprom_in - read one byte from the bus
  107. */
  108. static int tb_eeprom_in(struct tb_switch *sw, u8 *val)
  109. {
  110. struct tb_eeprom_ctl ctl;
  111. int i;
  112. int res = tb_eeprom_ctl_read(sw, &ctl);
  113. if (res)
  114. return res;
  115. *val = 0;
  116. for (i = 0; i < 8; i++) {
  117. *val <<= 1;
  118. res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_IN);
  119. if (res)
  120. return res;
  121. *val |= ctl.fl_do;
  122. }
  123. return 0;
  124. }
  125. /*
  126. * tb_eeprom_get_drom_offset - get drom offset within eeprom
  127. */
  128. static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset)
  129. {
  130. struct tb_cap_plug_events cap;
  131. int res;
  132. if (!sw->cap_plug_events) {
  133. tb_sw_warn(sw, "no TB_CAP_PLUG_EVENTS, cannot read eeprom\n");
  134. return -ENODEV;
  135. }
  136. res = tb_sw_read(sw, &cap, TB_CFG_SWITCH, sw->cap_plug_events,
  137. sizeof(cap) / 4);
  138. if (res)
  139. return res;
  140. if (!cap.eeprom_ctl.present || cap.eeprom_ctl.not_present) {
  141. tb_sw_warn(sw, "no NVM\n");
  142. return -ENODEV;
  143. }
  144. if (cap.drom_offset > 0xffff) {
  145. tb_sw_warn(sw, "drom offset is larger than 0xffff: %#x\n",
  146. cap.drom_offset);
  147. return -ENXIO;
  148. }
  149. *offset = cap.drom_offset;
  150. return 0;
  151. }
  152. /*
  153. * tb_eeprom_read_n - read count bytes from offset into val
  154. */
  155. static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val,
  156. size_t count)
  157. {
  158. u16 drom_offset;
  159. int i, res;
  160. res = tb_eeprom_get_drom_offset(sw, &drom_offset);
  161. if (res)
  162. return res;
  163. offset += drom_offset;
  164. res = tb_eeprom_active(sw, true);
  165. if (res)
  166. return res;
  167. res = tb_eeprom_out(sw, 3);
  168. if (res)
  169. return res;
  170. res = tb_eeprom_out(sw, offset >> 8);
  171. if (res)
  172. return res;
  173. res = tb_eeprom_out(sw, offset);
  174. if (res)
  175. return res;
  176. for (i = 0; i < count; i++) {
  177. res = tb_eeprom_in(sw, val + i);
  178. if (res)
  179. return res;
  180. }
  181. return tb_eeprom_active(sw, false);
  182. }
  183. static u8 tb_crc8(u8 *data, int len)
  184. {
  185. int i, j;
  186. u8 val = 0xff;
  187. for (i = 0; i < len; i++) {
  188. val ^= data[i];
  189. for (j = 0; j < 8; j++)
  190. val = (val << 1) ^ ((val & 0x80) ? 7 : 0);
  191. }
  192. return val;
  193. }
  194. static u32 tb_crc32(void *data, size_t len)
  195. {
  196. return ~__crc32c_le(~0, data, len);
  197. }
  198. #define TB_DROM_DATA_START 13
  199. #define TB_DROM_HEADER_SIZE 22
  200. #define USB4_DROM_HEADER_SIZE 16
  201. struct tb_drom_header {
  202. /* BYTE 0 */
  203. u8 uid_crc8; /* checksum for uid */
  204. /* BYTES 1-8 */
  205. u64 uid;
  206. /* BYTES 9-12 */
  207. u32 data_crc32; /* checksum for data_len bytes starting at byte 13 */
  208. /* BYTE 13 */
  209. u8 device_rom_revision; /* should be <= 1 */
  210. u16 data_len:12;
  211. u8 reserved:4;
  212. /* BYTES 16-21 - Only for TBT DROM, nonexistent in USB4 DROM */
  213. u16 vendor_id;
  214. u16 model_id;
  215. u8 model_rev;
  216. u8 eeprom_rev;
  217. } __packed;
  218. enum tb_drom_entry_type {
  219. /* force unsigned to prevent "one-bit signed bitfield" warning */
  220. TB_DROM_ENTRY_GENERIC = 0U,
  221. TB_DROM_ENTRY_PORT,
  222. };
  223. struct tb_drom_entry_header {
  224. u8 len;
  225. u8 index:6;
  226. bool port_disabled:1; /* only valid if type is TB_DROM_ENTRY_PORT */
  227. enum tb_drom_entry_type type:1;
  228. } __packed;
  229. struct tb_drom_entry_generic {
  230. struct tb_drom_entry_header header;
  231. u8 data[];
  232. } __packed;
  233. struct tb_drom_entry_port {
  234. /* BYTES 0-1 */
  235. struct tb_drom_entry_header header;
  236. /* BYTE 2 */
  237. u8 dual_link_port_rid:4;
  238. u8 link_nr:1;
  239. u8 unknown1:2;
  240. bool has_dual_link_port:1;
  241. /* BYTE 3 */
  242. u8 dual_link_port_nr:6;
  243. u8 unknown2:2;
  244. /* BYTES 4 - 5 TODO decode */
  245. u8 micro2:4;
  246. u8 micro1:4;
  247. u8 micro3;
  248. /* BYTES 6-7, TODO: verify (find hardware that has these set) */
  249. u8 peer_port_rid:4;
  250. u8 unknown3:3;
  251. bool has_peer_port:1;
  252. u8 peer_port_nr:6;
  253. u8 unknown4:2;
  254. } __packed;
  255. /* USB4 product descriptor */
  256. struct tb_drom_entry_desc {
  257. struct tb_drom_entry_header header;
  258. u16 bcdUSBSpec;
  259. u16 idVendor;
  260. u16 idProduct;
  261. u16 bcdProductFWRevision;
  262. u32 TID;
  263. u8 productHWRevision;
  264. };
  265. /**
  266. * tb_drom_read_uid_only() - Read UID directly from DROM
  267. * @sw: Router whose UID to read
  268. * @uid: UID is placed here
  269. *
  270. * Does not use the cached copy in sw->drom. Used during resume to check switch
  271. * identity.
  272. */
  273. int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid)
  274. {
  275. u8 data[9];
  276. u8 crc;
  277. int res;
  278. /* read uid */
  279. res = tb_eeprom_read_n(sw, 0, data, 9);
  280. if (res)
  281. return res;
  282. crc = tb_crc8(data + 1, 8);
  283. if (crc != data[0]) {
  284. tb_sw_warn(sw, "uid crc8 mismatch (expected: %#x, got: %#x)\n",
  285. data[0], crc);
  286. return -EIO;
  287. }
  288. *uid = *(u64 *)(data+1);
  289. return 0;
  290. }
  291. static int tb_drom_parse_entry_generic(struct tb_switch *sw,
  292. struct tb_drom_entry_header *header)
  293. {
  294. const struct tb_drom_entry_generic *entry =
  295. (const struct tb_drom_entry_generic *)header;
  296. switch (header->index) {
  297. case 1:
  298. /* Length includes 2 bytes header so remove it before copy */
  299. sw->vendor_name = kstrndup(entry->data,
  300. header->len - sizeof(*header), GFP_KERNEL);
  301. if (!sw->vendor_name)
  302. return -ENOMEM;
  303. break;
  304. case 2:
  305. sw->device_name = kstrndup(entry->data,
  306. header->len - sizeof(*header), GFP_KERNEL);
  307. if (!sw->device_name)
  308. return -ENOMEM;
  309. break;
  310. case 9: {
  311. const struct tb_drom_entry_desc *desc =
  312. (const struct tb_drom_entry_desc *)entry;
  313. if (!sw->vendor && !sw->device) {
  314. sw->vendor = desc->idVendor;
  315. sw->device = desc->idProduct;
  316. }
  317. break;
  318. }
  319. }
  320. return 0;
  321. }
  322. static int tb_drom_parse_entry_port(struct tb_switch *sw,
  323. struct tb_drom_entry_header *header)
  324. {
  325. struct tb_port *port;
  326. int res;
  327. enum tb_port_type type;
  328. /*
  329. * Some DROMs list more ports than the controller actually has
  330. * so we skip those but allow the parser to continue.
  331. */
  332. if (header->index > sw->config.max_port_number) {
  333. dev_info_once(&sw->dev, "ignoring unnecessary extra entries in DROM\n");
  334. return 0;
  335. }
  336. port = &sw->ports[header->index];
  337. port->disabled = header->port_disabled;
  338. if (port->disabled)
  339. return 0;
  340. res = tb_port_read(port, &type, TB_CFG_PORT, 2, 1);
  341. if (res)
  342. return res;
  343. type &= 0xffffff;
  344. if (type == TB_TYPE_PORT) {
  345. struct tb_drom_entry_port *entry = (void *) header;
  346. if (header->len != sizeof(*entry)) {
  347. tb_sw_warn(sw,
  348. "port entry has size %#x (expected %#zx)\n",
  349. header->len, sizeof(struct tb_drom_entry_port));
  350. return -EIO;
  351. }
  352. port->link_nr = entry->link_nr;
  353. if (entry->has_dual_link_port)
  354. port->dual_link_port =
  355. &port->sw->ports[entry->dual_link_port_nr];
  356. }
  357. return 0;
  358. }
  359. /*
  360. * tb_drom_parse_entries - parse the linked list of drom entries
  361. *
  362. * Drom must have been copied to sw->drom.
  363. */
  364. static int tb_drom_parse_entries(struct tb_switch *sw, size_t header_size)
  365. {
  366. struct tb_drom_header *header = (void *) sw->drom;
  367. u16 pos = header_size;
  368. u16 drom_size = header->data_len + TB_DROM_DATA_START;
  369. int res;
  370. while (pos < drom_size) {
  371. struct tb_drom_entry_header *entry = (void *) (sw->drom + pos);
  372. if (pos + 1 == drom_size || pos + entry->len > drom_size
  373. || !entry->len) {
  374. tb_sw_warn(sw, "DROM buffer overrun\n");
  375. return -EIO;
  376. }
  377. switch (entry->type) {
  378. case TB_DROM_ENTRY_GENERIC:
  379. res = tb_drom_parse_entry_generic(sw, entry);
  380. break;
  381. case TB_DROM_ENTRY_PORT:
  382. res = tb_drom_parse_entry_port(sw, entry);
  383. break;
  384. }
  385. if (res)
  386. return res;
  387. pos += entry->len;
  388. }
  389. return 0;
  390. }
  391. /*
  392. * tb_drom_copy_efi - copy drom supplied by EFI to sw->drom if present
  393. */
  394. static int tb_drom_copy_efi(struct tb_switch *sw, u16 *size)
  395. {
  396. struct device *dev = &sw->tb->nhi->pdev->dev;
  397. int len, res;
  398. len = device_property_count_u8(dev, "ThunderboltDROM");
  399. if (len < 0 || len < sizeof(struct tb_drom_header))
  400. return -EINVAL;
  401. sw->drom = kmalloc(len, GFP_KERNEL);
  402. if (!sw->drom)
  403. return -ENOMEM;
  404. res = device_property_read_u8_array(dev, "ThunderboltDROM", sw->drom,
  405. len);
  406. if (res)
  407. goto err;
  408. *size = ((struct tb_drom_header *)sw->drom)->data_len +
  409. TB_DROM_DATA_START;
  410. if (*size > len)
  411. goto err;
  412. return 0;
  413. err:
  414. kfree(sw->drom);
  415. sw->drom = NULL;
  416. return -EINVAL;
  417. }
  418. static int tb_drom_copy_nvm(struct tb_switch *sw, u16 *size)
  419. {
  420. u16 drom_offset;
  421. int ret;
  422. if (!sw->dma_port)
  423. return -ENODEV;
  424. ret = tb_eeprom_get_drom_offset(sw, &drom_offset);
  425. if (ret)
  426. return ret;
  427. if (!drom_offset)
  428. return -ENODEV;
  429. ret = dma_port_flash_read(sw->dma_port, drom_offset + 14, size,
  430. sizeof(*size));
  431. if (ret)
  432. return ret;
  433. /* Size includes CRC8 + UID + CRC32 */
  434. *size += 1 + 8 + 4;
  435. sw->drom = kzalloc(*size, GFP_KERNEL);
  436. if (!sw->drom)
  437. return -ENOMEM;
  438. ret = dma_port_flash_read(sw->dma_port, drom_offset, sw->drom, *size);
  439. if (ret)
  440. goto err_free;
  441. /*
  442. * Read UID from the minimal DROM because the one in NVM is just
  443. * a placeholder.
  444. */
  445. tb_drom_read_uid_only(sw, &sw->uid);
  446. return 0;
  447. err_free:
  448. kfree(sw->drom);
  449. sw->drom = NULL;
  450. return ret;
  451. }
  452. static int usb4_copy_drom(struct tb_switch *sw, u16 *size)
  453. {
  454. int ret;
  455. ret = usb4_switch_drom_read(sw, 14, size, sizeof(*size));
  456. if (ret)
  457. return ret;
  458. /* Size includes CRC8 + UID + CRC32 */
  459. *size += 1 + 8 + 4;
  460. sw->drom = kzalloc(*size, GFP_KERNEL);
  461. if (!sw->drom)
  462. return -ENOMEM;
  463. ret = usb4_switch_drom_read(sw, 0, sw->drom, *size);
  464. if (ret) {
  465. kfree(sw->drom);
  466. sw->drom = NULL;
  467. }
  468. return ret;
  469. }
  470. static int tb_drom_bit_bang(struct tb_switch *sw, u16 *size)
  471. {
  472. int ret;
  473. ret = tb_eeprom_read_n(sw, 14, (u8 *)size, 2);
  474. if (ret)
  475. return ret;
  476. *size &= 0x3ff;
  477. *size += TB_DROM_DATA_START;
  478. tb_sw_dbg(sw, "reading DROM (length: %#x)\n", *size);
  479. if (*size < sizeof(struct tb_drom_header)) {
  480. tb_sw_warn(sw, "DROM too small, aborting\n");
  481. return -EIO;
  482. }
  483. sw->drom = kzalloc(*size, GFP_KERNEL);
  484. if (!sw->drom)
  485. return -ENOMEM;
  486. ret = tb_eeprom_read_n(sw, 0, sw->drom, *size);
  487. if (ret)
  488. goto err;
  489. return 0;
  490. err:
  491. kfree(sw->drom);
  492. sw->drom = NULL;
  493. return ret;
  494. }
  495. static int tb_drom_parse_v1(struct tb_switch *sw)
  496. {
  497. const struct tb_drom_header *header =
  498. (const struct tb_drom_header *)sw->drom;
  499. u32 crc;
  500. crc = tb_crc8((u8 *) &header->uid, 8);
  501. if (crc != header->uid_crc8) {
  502. tb_sw_warn(sw,
  503. "DROM UID CRC8 mismatch (expected: %#x, got: %#x)\n",
  504. header->uid_crc8, crc);
  505. return -EIO;
  506. }
  507. if (!sw->uid)
  508. sw->uid = header->uid;
  509. sw->vendor = header->vendor_id;
  510. sw->device = header->model_id;
  511. crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len);
  512. if (crc != header->data_crc32) {
  513. tb_sw_warn(sw,
  514. "DROM data CRC32 mismatch (expected: %#x, got: %#x), continuing\n",
  515. header->data_crc32, crc);
  516. }
  517. return tb_drom_parse_entries(sw, TB_DROM_HEADER_SIZE);
  518. }
  519. static int usb4_drom_parse(struct tb_switch *sw)
  520. {
  521. const struct tb_drom_header *header =
  522. (const struct tb_drom_header *)sw->drom;
  523. u32 crc;
  524. crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len);
  525. if (crc != header->data_crc32) {
  526. tb_sw_warn(sw,
  527. "DROM data CRC32 mismatch (expected: %#x, got: %#x), continuing\n",
  528. header->data_crc32, crc);
  529. }
  530. return tb_drom_parse_entries(sw, USB4_DROM_HEADER_SIZE);
  531. }
  532. static int tb_drom_parse(struct tb_switch *sw, u16 size)
  533. {
  534. const struct tb_drom_header *header = (const void *)sw->drom;
  535. int ret;
  536. if (header->data_len + TB_DROM_DATA_START != size) {
  537. tb_sw_warn(sw, "DROM size mismatch\n");
  538. ret = -EIO;
  539. goto err;
  540. }
  541. tb_sw_dbg(sw, "DROM version: %d\n", header->device_rom_revision);
  542. switch (header->device_rom_revision) {
  543. case 3:
  544. ret = usb4_drom_parse(sw);
  545. break;
  546. default:
  547. tb_sw_warn(sw, "DROM device_rom_revision %#x unknown\n",
  548. header->device_rom_revision);
  549. fallthrough;
  550. case 1:
  551. ret = tb_drom_parse_v1(sw);
  552. break;
  553. }
  554. if (ret) {
  555. tb_sw_warn(sw, "parsing DROM failed\n");
  556. goto err;
  557. }
  558. return 0;
  559. err:
  560. kfree(sw->drom);
  561. sw->drom = NULL;
  562. return ret;
  563. }
  564. static int tb_drom_host_read(struct tb_switch *sw)
  565. {
  566. u16 size;
  567. if (tb_switch_is_usb4(sw)) {
  568. usb4_switch_read_uid(sw, &sw->uid);
  569. if (!usb4_copy_drom(sw, &size))
  570. return tb_drom_parse(sw, size);
  571. } else {
  572. if (!tb_drom_copy_efi(sw, &size))
  573. return tb_drom_parse(sw, size);
  574. if (!tb_drom_copy_nvm(sw, &size))
  575. return tb_drom_parse(sw, size);
  576. tb_drom_read_uid_only(sw, &sw->uid);
  577. }
  578. return 0;
  579. }
  580. static int tb_drom_device_read(struct tb_switch *sw)
  581. {
  582. u16 size;
  583. int ret;
  584. if (tb_switch_is_usb4(sw)) {
  585. usb4_switch_read_uid(sw, &sw->uid);
  586. ret = usb4_copy_drom(sw, &size);
  587. } else {
  588. ret = tb_drom_bit_bang(sw, &size);
  589. }
  590. if (ret)
  591. return ret;
  592. return tb_drom_parse(sw, size);
  593. }
  594. /**
  595. * tb_drom_read() - Copy DROM to sw->drom and parse it
  596. * @sw: Router whose DROM to read and parse
  597. *
  598. * This function reads router DROM and if successful parses the entries and
  599. * populates the fields in @sw accordingly. Can be called for any router
  600. * generation.
  601. *
  602. * Returns %0 in case of success and negative errno otherwise.
  603. */
  604. int tb_drom_read(struct tb_switch *sw)
  605. {
  606. if (sw->drom)
  607. return 0;
  608. if (!tb_route(sw))
  609. return tb_drom_host_read(sw);
  610. return tb_drom_device_read(sw);
  611. }