Lines Matching refs:sw
14 static int tb_eeprom_ctl_write(struct tb_switch *sw, struct tb_eeprom_ctl *ctl) in tb_eeprom_ctl_write() argument
16 return tb_sw_write(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + 4, 1); in tb_eeprom_ctl_write()
22 static int tb_eeprom_ctl_read(struct tb_switch *sw, struct tb_eeprom_ctl *ctl) in tb_eeprom_ctl_read() argument
24 return tb_sw_read(sw, ctl, TB_CFG_SWITCH, sw->cap_plug_events + 4, 1); in tb_eeprom_ctl_read()
38 static int tb_eeprom_active(struct tb_switch *sw, bool enable) in tb_eeprom_active() argument
41 int res = tb_eeprom_ctl_read(sw, &ctl); in tb_eeprom_active()
46 res = tb_eeprom_ctl_write(sw, &ctl); in tb_eeprom_active()
50 return tb_eeprom_ctl_write(sw, &ctl); in tb_eeprom_active()
53 res = tb_eeprom_ctl_write(sw, &ctl); in tb_eeprom_active()
57 return tb_eeprom_ctl_write(sw, &ctl); in tb_eeprom_active()
67 static int tb_eeprom_transfer(struct tb_switch *sw, struct tb_eeprom_ctl *ctl, in tb_eeprom_transfer() argument
72 res = tb_eeprom_ctl_write(sw, ctl); in tb_eeprom_transfer()
77 res = tb_eeprom_ctl_write(sw, ctl); in tb_eeprom_transfer()
81 res = tb_eeprom_ctl_read(sw, ctl); in tb_eeprom_transfer()
86 return tb_eeprom_ctl_write(sw, ctl); in tb_eeprom_transfer()
92 static int tb_eeprom_out(struct tb_switch *sw, u8 val) in tb_eeprom_out() argument
96 int res = tb_eeprom_ctl_read(sw, &ctl); in tb_eeprom_out()
101 res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_OUT); in tb_eeprom_out()
112 static int tb_eeprom_in(struct tb_switch *sw, u8 *val) in tb_eeprom_in() argument
116 int res = tb_eeprom_ctl_read(sw, &ctl); in tb_eeprom_in()
122 res = tb_eeprom_transfer(sw, &ctl, TB_EEPROM_IN); in tb_eeprom_in()
133 static int tb_eeprom_read_n(struct tb_switch *sw, u16 offset, u8 *val, in tb_eeprom_read_n() argument
137 res = tb_eeprom_active(sw, true); in tb_eeprom_read_n()
140 res = tb_eeprom_out(sw, 3); in tb_eeprom_read_n()
143 res = tb_eeprom_out(sw, offset >> 8); in tb_eeprom_read_n()
146 res = tb_eeprom_out(sw, offset); in tb_eeprom_read_n()
150 res = tb_eeprom_in(sw, val + i); in tb_eeprom_read_n()
154 return tb_eeprom_active(sw, false); in tb_eeprom_read_n()
236 static int tb_eeprom_get_drom_offset(struct tb_switch *sw, u16 *offset) in tb_eeprom_get_drom_offset() argument
240 if (!sw->cap_plug_events) { in tb_eeprom_get_drom_offset()
241 tb_sw_warn(sw, "no TB_CAP_PLUG_EVENTS, cannot read eeprom\n"); in tb_eeprom_get_drom_offset()
244 res = tb_sw_read(sw, &cap, TB_CFG_SWITCH, sw->cap_plug_events, in tb_eeprom_get_drom_offset()
250 tb_sw_warn(sw, "no NVM\n"); in tb_eeprom_get_drom_offset()
255 tb_sw_warn(sw, "drom offset is larger than 0xffff: %#x\n", in tb_eeprom_get_drom_offset()
269 int tb_drom_read_uid_only(struct tb_switch *sw, u64 *uid) in tb_drom_read_uid_only() argument
274 int res = tb_eeprom_get_drom_offset(sw, &drom_offset); in tb_drom_read_uid_only()
279 res = tb_eeprom_read_n(sw, drom_offset, data, 9); in tb_drom_read_uid_only()
285 tb_sw_warn(sw, "uid crc8 missmatch (expected: %#x, got: %#x)\n", in tb_drom_read_uid_only()
300 &port->sw->ports[entry->dual_link_port_nr]; in tb_drom_parse_port_entry()
303 static int tb_drom_parse_entry(struct tb_switch *sw, in tb_drom_parse_entry() argument
313 port = &sw->ports[header->index]; in tb_drom_parse_entry()
326 tb_sw_warn(sw, in tb_drom_parse_entry()
341 static int tb_drom_parse_entries(struct tb_switch *sw) in tb_drom_parse_entries() argument
343 struct tb_drom_header *header = (void *) sw->drom; in tb_drom_parse_entries()
348 struct tb_drom_entry_header *entry = (void *) (sw->drom + pos); in tb_drom_parse_entries()
351 tb_sw_warn(sw, "drom buffer overrun, aborting\n"); in tb_drom_parse_entries()
355 tb_drom_parse_entry(sw, entry); in tb_drom_parse_entries()
365 int tb_drom_read(struct tb_switch *sw) in tb_drom_read() argument
372 if (sw->drom) in tb_drom_read()
375 if (tb_route(sw) == 0) { in tb_drom_read()
380 tb_drom_read_uid_only(sw, &sw->uid); in tb_drom_read()
382 sw->ports[1].link_nr = 0; in tb_drom_read()
383 sw->ports[2].link_nr = 1; in tb_drom_read()
384 sw->ports[1].dual_link_port = &sw->ports[2]; in tb_drom_read()
385 sw->ports[2].dual_link_port = &sw->ports[1]; in tb_drom_read()
387 sw->ports[3].link_nr = 0; in tb_drom_read()
388 sw->ports[4].link_nr = 1; in tb_drom_read()
389 sw->ports[3].dual_link_port = &sw->ports[4]; in tb_drom_read()
390 sw->ports[4].dual_link_port = &sw->ports[3]; in tb_drom_read()
394 res = tb_eeprom_get_drom_offset(sw, &drom_offset); in tb_drom_read()
398 res = tb_eeprom_read_n(sw, drom_offset + 14, (u8 *) &size, 2); in tb_drom_read()
403 tb_sw_info(sw, "reading drom (length: %#x)\n", size); in tb_drom_read()
405 tb_sw_warn(sw, "drom too small, aborting\n"); in tb_drom_read()
409 sw->drom = kzalloc(size, GFP_KERNEL); in tb_drom_read()
410 if (!sw->drom) in tb_drom_read()
412 res = tb_eeprom_read_n(sw, drom_offset, sw->drom, size); in tb_drom_read()
416 header = (void *) sw->drom; in tb_drom_read()
419 tb_sw_warn(sw, "drom size mismatch, aborting\n"); in tb_drom_read()
425 tb_sw_warn(sw, in tb_drom_read()
430 sw->uid = header->uid; in tb_drom_read()
432 crc = tb_crc32(sw->drom + TB_DROM_DATA_START, header->data_len); in tb_drom_read()
434 tb_sw_warn(sw, in tb_drom_read()
441 tb_sw_warn(sw, "drom device_rom_revision %#x unknown\n", in tb_drom_read()
444 return tb_drom_parse_entries(sw); in tb_drom_read()
446 kfree(sw->drom); in tb_drom_read()
447 sw->drom = NULL; in tb_drom_read()