mv88e6352.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. * net/dsa/mv88e6352.c - Marvell 88e6352 switch chip support
  3. *
  4. * Copyright (c) 2014 Guenter Roeck
  5. *
  6. * Derived from mv88e6123_61_65.c
  7. * Copyright (c) 2008-2009 Marvell Semiconductor
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/jiffies.h>
  16. #include <linux/list.h>
  17. #include <linux/module.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/phy.h>
  21. #include <net/dsa.h>
  22. #include "mv88e6xxx.h"
  23. static int mv88e6352_wait(struct dsa_switch *ds, int reg, u16 mask)
  24. {
  25. unsigned long timeout = jiffies + HZ / 10;
  26. while (time_before(jiffies, timeout)) {
  27. int ret;
  28. ret = REG_READ(REG_GLOBAL2, reg);
  29. if (ret < 0)
  30. return ret;
  31. if (!(ret & mask))
  32. return 0;
  33. usleep_range(1000, 2000);
  34. }
  35. return -ETIMEDOUT;
  36. }
  37. static inline int mv88e6352_phy_wait(struct dsa_switch *ds)
  38. {
  39. return mv88e6352_wait(ds, 0x18, 0x8000);
  40. }
  41. static inline int mv88e6352_eeprom_load_wait(struct dsa_switch *ds)
  42. {
  43. return mv88e6352_wait(ds, 0x14, 0x0800);
  44. }
  45. static inline int mv88e6352_eeprom_busy_wait(struct dsa_switch *ds)
  46. {
  47. return mv88e6352_wait(ds, 0x14, 0x8000);
  48. }
  49. static int __mv88e6352_phy_read(struct dsa_switch *ds, int addr, int regnum)
  50. {
  51. int ret;
  52. REG_WRITE(REG_GLOBAL2, 0x18, 0x9800 | (addr << 5) | regnum);
  53. ret = mv88e6352_phy_wait(ds);
  54. if (ret < 0)
  55. return ret;
  56. return REG_READ(REG_GLOBAL2, 0x19);
  57. }
  58. static int __mv88e6352_phy_write(struct dsa_switch *ds, int addr, int regnum,
  59. u16 val)
  60. {
  61. REG_WRITE(REG_GLOBAL2, 0x19, val);
  62. REG_WRITE(REG_GLOBAL2, 0x18, 0x9400 | (addr << 5) | regnum);
  63. return mv88e6352_phy_wait(ds);
  64. }
  65. static char *mv88e6352_probe(struct device *host_dev, int sw_addr)
  66. {
  67. struct mii_bus *bus = dsa_host_dev_to_mii_bus(host_dev);
  68. int ret;
  69. if (bus == NULL)
  70. return NULL;
  71. ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03);
  72. if (ret >= 0) {
  73. if ((ret & 0xfff0) == 0x1760)
  74. return "Marvell 88E6176";
  75. if (ret == 0x3521)
  76. return "Marvell 88E6352 (A0)";
  77. if (ret == 0x3522)
  78. return "Marvell 88E6352 (A1)";
  79. if ((ret & 0xfff0) == 0x3520)
  80. return "Marvell 88E6352";
  81. }
  82. return NULL;
  83. }
  84. static int mv88e6352_switch_reset(struct dsa_switch *ds)
  85. {
  86. unsigned long timeout;
  87. int ret;
  88. int i;
  89. /* Set all ports to the disabled state. */
  90. for (i = 0; i < 7; i++) {
  91. ret = REG_READ(REG_PORT(i), 0x04);
  92. REG_WRITE(REG_PORT(i), 0x04, ret & 0xfffc);
  93. }
  94. /* Wait for transmit queues to drain. */
  95. usleep_range(2000, 4000);
  96. /* Reset the switch. Keep PPU active (bit 14, undocumented).
  97. * The PPU needs to be active to support indirect phy register
  98. * accesses through global registers 0x18 and 0x19.
  99. */
  100. REG_WRITE(REG_GLOBAL, 0x04, 0xc000);
  101. /* Wait up to one second for reset to complete. */
  102. timeout = jiffies + 1 * HZ;
  103. while (time_before(jiffies, timeout)) {
  104. ret = REG_READ(REG_GLOBAL, 0x00);
  105. if ((ret & 0x8800) == 0x8800)
  106. break;
  107. usleep_range(1000, 2000);
  108. }
  109. if (time_after(jiffies, timeout))
  110. return -ETIMEDOUT;
  111. return 0;
  112. }
  113. static int mv88e6352_setup_global(struct dsa_switch *ds)
  114. {
  115. int ret;
  116. int i;
  117. /* Discard packets with excessive collisions,
  118. * mask all interrupt sources, enable PPU (bit 14, undocumented).
  119. */
  120. REG_WRITE(REG_GLOBAL, 0x04, 0x6000);
  121. /* Set the default address aging time to 5 minutes, and
  122. * enable address learn messages to be sent to all message
  123. * ports.
  124. */
  125. REG_WRITE(REG_GLOBAL, 0x0a, 0x0148);
  126. /* Configure the priority mapping registers. */
  127. ret = mv88e6xxx_config_prio(ds);
  128. if (ret < 0)
  129. return ret;
  130. /* Configure the upstream port, and configure the upstream
  131. * port as the port to which ingress and egress monitor frames
  132. * are to be sent.
  133. */
  134. REG_WRITE(REG_GLOBAL, 0x1a, (dsa_upstream_port(ds) * 0x1110));
  135. /* Disable remote management for now, and set the switch's
  136. * DSA device number.
  137. */
  138. REG_WRITE(REG_GLOBAL, 0x1c, ds->index & 0x1f);
  139. /* Send all frames with destination addresses matching
  140. * 01:80:c2:00:00:2x to the CPU port.
  141. */
  142. REG_WRITE(REG_GLOBAL2, 0x02, 0xffff);
  143. /* Send all frames with destination addresses matching
  144. * 01:80:c2:00:00:0x to the CPU port.
  145. */
  146. REG_WRITE(REG_GLOBAL2, 0x03, 0xffff);
  147. /* Disable the loopback filter, disable flow control
  148. * messages, disable flood broadcast override, disable
  149. * removing of provider tags, disable ATU age violation
  150. * interrupts, disable tag flow control, force flow
  151. * control priority to the highest, and send all special
  152. * multicast frames to the CPU at the highest priority.
  153. */
  154. REG_WRITE(REG_GLOBAL2, 0x05, 0x00ff);
  155. /* Program the DSA routing table. */
  156. for (i = 0; i < 32; i++) {
  157. int nexthop = 0x1f;
  158. if (i != ds->index && i < ds->dst->pd->nr_chips)
  159. nexthop = ds->pd->rtable[i] & 0x1f;
  160. REG_WRITE(REG_GLOBAL2, 0x06, 0x8000 | (i << 8) | nexthop);
  161. }
  162. /* Clear all trunk masks. */
  163. for (i = 0; i < 8; i++)
  164. REG_WRITE(REG_GLOBAL2, 0x07, 0x8000 | (i << 12) | 0x7f);
  165. /* Clear all trunk mappings. */
  166. for (i = 0; i < 16; i++)
  167. REG_WRITE(REG_GLOBAL2, 0x08, 0x8000 | (i << 11));
  168. /* Disable ingress rate limiting by resetting all ingress
  169. * rate limit registers to their initial state.
  170. */
  171. for (i = 0; i < 7; i++)
  172. REG_WRITE(REG_GLOBAL2, 0x09, 0x9000 | (i << 8));
  173. /* Initialise cross-chip port VLAN table to reset defaults. */
  174. REG_WRITE(REG_GLOBAL2, 0x0b, 0x9000);
  175. /* Clear the priority override table. */
  176. for (i = 0; i < 16; i++)
  177. REG_WRITE(REG_GLOBAL2, 0x0f, 0x8000 | (i << 8));
  178. /* @@@ initialise AVB (22/23) watchdog (27) sdet (29) registers */
  179. return 0;
  180. }
  181. static int mv88e6352_setup_port(struct dsa_switch *ds, int p)
  182. {
  183. int addr = REG_PORT(p);
  184. u16 val;
  185. /* MAC Forcing register: don't force link, speed, duplex
  186. * or flow control state to any particular values on physical
  187. * ports, but force the CPU port and all DSA ports to 1000 Mb/s
  188. * full duplex.
  189. */
  190. if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p))
  191. REG_WRITE(addr, 0x01, 0x003e);
  192. else
  193. REG_WRITE(addr, 0x01, 0x0003);
  194. /* Do not limit the period of time that this port can be
  195. * paused for by the remote end or the period of time that
  196. * this port can pause the remote end.
  197. */
  198. REG_WRITE(addr, 0x02, 0x0000);
  199. /* Port Control: disable Drop-on-Unlock, disable Drop-on-Lock,
  200. * disable Header mode, enable IGMP/MLD snooping, disable VLAN
  201. * tunneling, determine priority by looking at 802.1p and IP
  202. * priority fields (IP prio has precedence), and set STP state
  203. * to Forwarding.
  204. *
  205. * If this is the CPU link, use DSA or EDSA tagging depending
  206. * on which tagging mode was configured.
  207. *
  208. * If this is a link to another switch, use DSA tagging mode.
  209. *
  210. * If this is the upstream port for this switch, enable
  211. * forwarding of unknown unicasts and multicasts.
  212. */
  213. val = 0x0433;
  214. if (dsa_is_cpu_port(ds, p)) {
  215. if (ds->dst->tag_protocol == DSA_TAG_PROTO_EDSA)
  216. val |= 0x3300;
  217. else
  218. val |= 0x0100;
  219. }
  220. if (ds->dsa_port_mask & (1 << p))
  221. val |= 0x0100;
  222. if (p == dsa_upstream_port(ds))
  223. val |= 0x000c;
  224. REG_WRITE(addr, 0x04, val);
  225. /* Port Control 1: disable trunking. Also, if this is the
  226. * CPU port, enable learn messages to be sent to this port.
  227. */
  228. REG_WRITE(addr, 0x05, dsa_is_cpu_port(ds, p) ? 0x8000 : 0x0000);
  229. /* Port based VLAN map: give each port its own address
  230. * database, allow the CPU port to talk to each of the 'real'
  231. * ports, and allow each of the 'real' ports to only talk to
  232. * the upstream port.
  233. */
  234. val = (p & 0xf) << 12;
  235. if (dsa_is_cpu_port(ds, p))
  236. val |= ds->phys_port_mask;
  237. else
  238. val |= 1 << dsa_upstream_port(ds);
  239. REG_WRITE(addr, 0x06, val);
  240. /* Default VLAN ID and priority: don't set a default VLAN
  241. * ID, and set the default packet priority to zero.
  242. */
  243. REG_WRITE(addr, 0x07, 0x0000);
  244. /* Port Control 2: don't force a good FCS, set the maximum
  245. * frame size to 10240 bytes, don't let the switch add or
  246. * strip 802.1q tags, don't discard tagged or untagged frames
  247. * on this port, do a destination address lookup on all
  248. * received packets as usual, disable ARP mirroring and don't
  249. * send a copy of all transmitted/received frames on this port
  250. * to the CPU.
  251. */
  252. REG_WRITE(addr, 0x08, 0x2080);
  253. /* Egress rate control: disable egress rate control. */
  254. REG_WRITE(addr, 0x09, 0x0001);
  255. /* Egress rate control 2: disable egress rate control. */
  256. REG_WRITE(addr, 0x0a, 0x0000);
  257. /* Port Association Vector: when learning source addresses
  258. * of packets, add the address to the address database using
  259. * a port bitmap that has only the bit for this port set and
  260. * the other bits clear.
  261. */
  262. REG_WRITE(addr, 0x0b, 1 << p);
  263. /* Port ATU control: disable limiting the number of address
  264. * database entries that this port is allowed to use.
  265. */
  266. REG_WRITE(addr, 0x0c, 0x0000);
  267. /* Priority Override: disable DA, SA and VTU priority override. */
  268. REG_WRITE(addr, 0x0d, 0x0000);
  269. /* Port Ethertype: use the Ethertype DSA Ethertype value. */
  270. REG_WRITE(addr, 0x0f, ETH_P_EDSA);
  271. /* Tag Remap: use an identity 802.1p prio -> switch prio
  272. * mapping.
  273. */
  274. REG_WRITE(addr, 0x18, 0x3210);
  275. /* Tag Remap 2: use an identity 802.1p prio -> switch prio
  276. * mapping.
  277. */
  278. REG_WRITE(addr, 0x19, 0x7654);
  279. return 0;
  280. }
  281. #ifdef CONFIG_NET_DSA_HWMON
  282. static int mv88e6352_phy_page_read(struct dsa_switch *ds,
  283. int port, int page, int reg)
  284. {
  285. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  286. int ret;
  287. mutex_lock(&ps->phy_mutex);
  288. ret = __mv88e6352_phy_write(ds, port, 0x16, page);
  289. if (ret < 0)
  290. goto error;
  291. ret = __mv88e6352_phy_read(ds, port, reg);
  292. error:
  293. __mv88e6352_phy_write(ds, port, 0x16, 0x0);
  294. mutex_unlock(&ps->phy_mutex);
  295. return ret;
  296. }
  297. static int mv88e6352_phy_page_write(struct dsa_switch *ds,
  298. int port, int page, int reg, int val)
  299. {
  300. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  301. int ret;
  302. mutex_lock(&ps->phy_mutex);
  303. ret = __mv88e6352_phy_write(ds, port, 0x16, page);
  304. if (ret < 0)
  305. goto error;
  306. ret = __mv88e6352_phy_write(ds, port, reg, val);
  307. error:
  308. __mv88e6352_phy_write(ds, port, 0x16, 0x0);
  309. mutex_unlock(&ps->phy_mutex);
  310. return ret;
  311. }
  312. static int mv88e6352_get_temp(struct dsa_switch *ds, int *temp)
  313. {
  314. int ret;
  315. *temp = 0;
  316. ret = mv88e6352_phy_page_read(ds, 0, 6, 27);
  317. if (ret < 0)
  318. return ret;
  319. *temp = (ret & 0xff) - 25;
  320. return 0;
  321. }
  322. static int mv88e6352_get_temp_limit(struct dsa_switch *ds, int *temp)
  323. {
  324. int ret;
  325. *temp = 0;
  326. ret = mv88e6352_phy_page_read(ds, 0, 6, 26);
  327. if (ret < 0)
  328. return ret;
  329. *temp = (((ret >> 8) & 0x1f) * 5) - 25;
  330. return 0;
  331. }
  332. static int mv88e6352_set_temp_limit(struct dsa_switch *ds, int temp)
  333. {
  334. int ret;
  335. ret = mv88e6352_phy_page_read(ds, 0, 6, 26);
  336. if (ret < 0)
  337. return ret;
  338. temp = clamp_val(DIV_ROUND_CLOSEST(temp, 5) + 5, 0, 0x1f);
  339. return mv88e6352_phy_page_write(ds, 0, 6, 26,
  340. (ret & 0xe0ff) | (temp << 8));
  341. }
  342. static int mv88e6352_get_temp_alarm(struct dsa_switch *ds, bool *alarm)
  343. {
  344. int ret;
  345. *alarm = false;
  346. ret = mv88e6352_phy_page_read(ds, 0, 6, 26);
  347. if (ret < 0)
  348. return ret;
  349. *alarm = !!(ret & 0x40);
  350. return 0;
  351. }
  352. #endif /* CONFIG_NET_DSA_HWMON */
  353. static int mv88e6352_setup(struct dsa_switch *ds)
  354. {
  355. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  356. int ret;
  357. int i;
  358. mutex_init(&ps->smi_mutex);
  359. mutex_init(&ps->stats_mutex);
  360. mutex_init(&ps->phy_mutex);
  361. mutex_init(&ps->eeprom_mutex);
  362. ps->id = REG_READ(REG_PORT(0), 0x03) & 0xfff0;
  363. ret = mv88e6352_switch_reset(ds);
  364. if (ret < 0)
  365. return ret;
  366. /* @@@ initialise vtu and atu */
  367. ret = mv88e6352_setup_global(ds);
  368. if (ret < 0)
  369. return ret;
  370. for (i = 0; i < 7; i++) {
  371. ret = mv88e6352_setup_port(ds, i);
  372. if (ret < 0)
  373. return ret;
  374. }
  375. return 0;
  376. }
  377. static int mv88e6352_port_to_phy_addr(int port)
  378. {
  379. if (port >= 0 && port <= 4)
  380. return port;
  381. return -EINVAL;
  382. }
  383. static int
  384. mv88e6352_phy_read(struct dsa_switch *ds, int port, int regnum)
  385. {
  386. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  387. int addr = mv88e6352_port_to_phy_addr(port);
  388. int ret;
  389. if (addr < 0)
  390. return addr;
  391. mutex_lock(&ps->phy_mutex);
  392. ret = __mv88e6352_phy_read(ds, addr, regnum);
  393. mutex_unlock(&ps->phy_mutex);
  394. return ret;
  395. }
  396. static int
  397. mv88e6352_phy_write(struct dsa_switch *ds, int port, int regnum, u16 val)
  398. {
  399. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  400. int addr = mv88e6352_port_to_phy_addr(port);
  401. int ret;
  402. if (addr < 0)
  403. return addr;
  404. mutex_lock(&ps->phy_mutex);
  405. ret = __mv88e6352_phy_write(ds, addr, regnum, val);
  406. mutex_unlock(&ps->phy_mutex);
  407. return ret;
  408. }
  409. static struct mv88e6xxx_hw_stat mv88e6352_hw_stats[] = {
  410. { "in_good_octets", 8, 0x00, },
  411. { "in_bad_octets", 4, 0x02, },
  412. { "in_unicast", 4, 0x04, },
  413. { "in_broadcasts", 4, 0x06, },
  414. { "in_multicasts", 4, 0x07, },
  415. { "in_pause", 4, 0x16, },
  416. { "in_undersize", 4, 0x18, },
  417. { "in_fragments", 4, 0x19, },
  418. { "in_oversize", 4, 0x1a, },
  419. { "in_jabber", 4, 0x1b, },
  420. { "in_rx_error", 4, 0x1c, },
  421. { "in_fcs_error", 4, 0x1d, },
  422. { "out_octets", 8, 0x0e, },
  423. { "out_unicast", 4, 0x10, },
  424. { "out_broadcasts", 4, 0x13, },
  425. { "out_multicasts", 4, 0x12, },
  426. { "out_pause", 4, 0x15, },
  427. { "excessive", 4, 0x11, },
  428. { "collisions", 4, 0x1e, },
  429. { "deferred", 4, 0x05, },
  430. { "single", 4, 0x14, },
  431. { "multiple", 4, 0x17, },
  432. { "out_fcs_error", 4, 0x03, },
  433. { "late", 4, 0x1f, },
  434. { "hist_64bytes", 4, 0x08, },
  435. { "hist_65_127bytes", 4, 0x09, },
  436. { "hist_128_255bytes", 4, 0x0a, },
  437. { "hist_256_511bytes", 4, 0x0b, },
  438. { "hist_512_1023bytes", 4, 0x0c, },
  439. { "hist_1024_max_bytes", 4, 0x0d, },
  440. { "sw_in_discards", 4, 0x110, },
  441. { "sw_in_filtered", 2, 0x112, },
  442. { "sw_out_filtered", 2, 0x113, },
  443. };
  444. static int mv88e6352_read_eeprom_word(struct dsa_switch *ds, int addr)
  445. {
  446. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  447. int ret;
  448. mutex_lock(&ps->eeprom_mutex);
  449. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, 0x14,
  450. 0xc000 | (addr & 0xff));
  451. if (ret < 0)
  452. goto error;
  453. ret = mv88e6352_eeprom_busy_wait(ds);
  454. if (ret < 0)
  455. goto error;
  456. ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, 0x15);
  457. error:
  458. mutex_unlock(&ps->eeprom_mutex);
  459. return ret;
  460. }
  461. static int mv88e6352_get_eeprom(struct dsa_switch *ds,
  462. struct ethtool_eeprom *eeprom, u8 *data)
  463. {
  464. int offset;
  465. int len;
  466. int ret;
  467. offset = eeprom->offset;
  468. len = eeprom->len;
  469. eeprom->len = 0;
  470. eeprom->magic = 0xc3ec4951;
  471. ret = mv88e6352_eeprom_load_wait(ds);
  472. if (ret < 0)
  473. return ret;
  474. if (offset & 1) {
  475. int word;
  476. word = mv88e6352_read_eeprom_word(ds, offset >> 1);
  477. if (word < 0)
  478. return word;
  479. *data++ = (word >> 8) & 0xff;
  480. offset++;
  481. len--;
  482. eeprom->len++;
  483. }
  484. while (len >= 2) {
  485. int word;
  486. word = mv88e6352_read_eeprom_word(ds, offset >> 1);
  487. if (word < 0)
  488. return word;
  489. *data++ = word & 0xff;
  490. *data++ = (word >> 8) & 0xff;
  491. offset += 2;
  492. len -= 2;
  493. eeprom->len += 2;
  494. }
  495. if (len) {
  496. int word;
  497. word = mv88e6352_read_eeprom_word(ds, offset >> 1);
  498. if (word < 0)
  499. return word;
  500. *data++ = word & 0xff;
  501. offset++;
  502. len--;
  503. eeprom->len++;
  504. }
  505. return 0;
  506. }
  507. static int mv88e6352_eeprom_is_readonly(struct dsa_switch *ds)
  508. {
  509. int ret;
  510. ret = mv88e6xxx_reg_read(ds, REG_GLOBAL2, 0x14);
  511. if (ret < 0)
  512. return ret;
  513. if (!(ret & 0x0400))
  514. return -EROFS;
  515. return 0;
  516. }
  517. static int mv88e6352_write_eeprom_word(struct dsa_switch *ds, int addr,
  518. u16 data)
  519. {
  520. struct mv88e6xxx_priv_state *ps = ds_to_priv(ds);
  521. int ret;
  522. mutex_lock(&ps->eeprom_mutex);
  523. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, 0x15, data);
  524. if (ret < 0)
  525. goto error;
  526. ret = mv88e6xxx_reg_write(ds, REG_GLOBAL2, 0x14,
  527. 0xb000 | (addr & 0xff));
  528. if (ret < 0)
  529. goto error;
  530. ret = mv88e6352_eeprom_busy_wait(ds);
  531. error:
  532. mutex_unlock(&ps->eeprom_mutex);
  533. return ret;
  534. }
  535. static int mv88e6352_set_eeprom(struct dsa_switch *ds,
  536. struct ethtool_eeprom *eeprom, u8 *data)
  537. {
  538. int offset;
  539. int ret;
  540. int len;
  541. if (eeprom->magic != 0xc3ec4951)
  542. return -EINVAL;
  543. ret = mv88e6352_eeprom_is_readonly(ds);
  544. if (ret)
  545. return ret;
  546. offset = eeprom->offset;
  547. len = eeprom->len;
  548. eeprom->len = 0;
  549. ret = mv88e6352_eeprom_load_wait(ds);
  550. if (ret < 0)
  551. return ret;
  552. if (offset & 1) {
  553. int word;
  554. word = mv88e6352_read_eeprom_word(ds, offset >> 1);
  555. if (word < 0)
  556. return word;
  557. word = (*data++ << 8) | (word & 0xff);
  558. ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
  559. if (ret < 0)
  560. return ret;
  561. offset++;
  562. len--;
  563. eeprom->len++;
  564. }
  565. while (len >= 2) {
  566. int word;
  567. word = *data++;
  568. word |= *data++ << 8;
  569. ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
  570. if (ret < 0)
  571. return ret;
  572. offset += 2;
  573. len -= 2;
  574. eeprom->len += 2;
  575. }
  576. if (len) {
  577. int word;
  578. word = mv88e6352_read_eeprom_word(ds, offset >> 1);
  579. if (word < 0)
  580. return word;
  581. word = (word & 0xff00) | *data++;
  582. ret = mv88e6352_write_eeprom_word(ds, offset >> 1, word);
  583. if (ret < 0)
  584. return ret;
  585. offset++;
  586. len--;
  587. eeprom->len++;
  588. }
  589. return 0;
  590. }
  591. static void
  592. mv88e6352_get_strings(struct dsa_switch *ds, int port, uint8_t *data)
  593. {
  594. mv88e6xxx_get_strings(ds, ARRAY_SIZE(mv88e6352_hw_stats),
  595. mv88e6352_hw_stats, port, data);
  596. }
  597. static void
  598. mv88e6352_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data)
  599. {
  600. mv88e6xxx_get_ethtool_stats(ds, ARRAY_SIZE(mv88e6352_hw_stats),
  601. mv88e6352_hw_stats, port, data);
  602. }
  603. static int mv88e6352_get_sset_count(struct dsa_switch *ds)
  604. {
  605. return ARRAY_SIZE(mv88e6352_hw_stats);
  606. }
  607. struct dsa_switch_driver mv88e6352_switch_driver = {
  608. .tag_protocol = DSA_TAG_PROTO_EDSA,
  609. .priv_size = sizeof(struct mv88e6xxx_priv_state),
  610. .probe = mv88e6352_probe,
  611. .setup = mv88e6352_setup,
  612. .set_addr = mv88e6xxx_set_addr_indirect,
  613. .phy_read = mv88e6352_phy_read,
  614. .phy_write = mv88e6352_phy_write,
  615. .poll_link = mv88e6xxx_poll_link,
  616. .get_strings = mv88e6352_get_strings,
  617. .get_ethtool_stats = mv88e6352_get_ethtool_stats,
  618. .get_sset_count = mv88e6352_get_sset_count,
  619. #ifdef CONFIG_NET_DSA_HWMON
  620. .get_temp = mv88e6352_get_temp,
  621. .get_temp_limit = mv88e6352_get_temp_limit,
  622. .set_temp_limit = mv88e6352_set_temp_limit,
  623. .get_temp_alarm = mv88e6352_get_temp_alarm,
  624. #endif
  625. .get_eeprom = mv88e6352_get_eeprom,
  626. .set_eeprom = mv88e6352_set_eeprom,
  627. .get_regs_len = mv88e6xxx_get_regs_len,
  628. .get_regs = mv88e6xxx_get_regs,
  629. };
  630. MODULE_ALIAS("platform:mv88e6352");