mv88e6352.c 18 KB

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