hwtstamp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Marvell 88E6xxx Switch hardware timestamping support
  4. *
  5. * Copyright (c) 2008 Marvell Semiconductor
  6. *
  7. * Copyright (c) 2017 National Instruments
  8. * Erik Hons <[email protected]>
  9. * Brandon Streiff <[email protected]>
  10. * Dane Wagner <[email protected]>
  11. */
  12. #include "chip.h"
  13. #include "global2.h"
  14. #include "hwtstamp.h"
  15. #include "ptp.h"
  16. #include <linux/ptp_classify.h>
  17. #define SKB_PTP_TYPE(__skb) (*(unsigned int *)((__skb)->cb))
  18. static int mv88e6xxx_port_ptp_read(struct mv88e6xxx_chip *chip, int port,
  19. int addr, u16 *data, int len)
  20. {
  21. if (!chip->info->ops->avb_ops->port_ptp_read)
  22. return -EOPNOTSUPP;
  23. return chip->info->ops->avb_ops->port_ptp_read(chip, port, addr,
  24. data, len);
  25. }
  26. static int mv88e6xxx_port_ptp_write(struct mv88e6xxx_chip *chip, int port,
  27. int addr, u16 data)
  28. {
  29. if (!chip->info->ops->avb_ops->port_ptp_write)
  30. return -EOPNOTSUPP;
  31. return chip->info->ops->avb_ops->port_ptp_write(chip, port, addr,
  32. data);
  33. }
  34. static int mv88e6xxx_ptp_write(struct mv88e6xxx_chip *chip, int addr,
  35. u16 data)
  36. {
  37. if (!chip->info->ops->avb_ops->ptp_write)
  38. return -EOPNOTSUPP;
  39. return chip->info->ops->avb_ops->ptp_write(chip, addr, data);
  40. }
  41. static int mv88e6xxx_ptp_read(struct mv88e6xxx_chip *chip, int addr,
  42. u16 *data)
  43. {
  44. if (!chip->info->ops->avb_ops->ptp_read)
  45. return -EOPNOTSUPP;
  46. return chip->info->ops->avb_ops->ptp_read(chip, addr, data, 1);
  47. }
  48. /* TX_TSTAMP_TIMEOUT: This limits the time spent polling for a TX
  49. * timestamp. When working properly, hardware will produce a timestamp
  50. * within 1ms. Software may enounter delays due to MDIO contention, so
  51. * the timeout is set accordingly.
  52. */
  53. #define TX_TSTAMP_TIMEOUT msecs_to_jiffies(40)
  54. int mv88e6xxx_get_ts_info(struct dsa_switch *ds, int port,
  55. struct ethtool_ts_info *info)
  56. {
  57. const struct mv88e6xxx_ptp_ops *ptp_ops;
  58. struct mv88e6xxx_chip *chip;
  59. chip = ds->priv;
  60. ptp_ops = chip->info->ops->ptp_ops;
  61. if (!chip->info->ptp_support)
  62. return -EOPNOTSUPP;
  63. info->so_timestamping =
  64. SOF_TIMESTAMPING_TX_HARDWARE |
  65. SOF_TIMESTAMPING_RX_HARDWARE |
  66. SOF_TIMESTAMPING_RAW_HARDWARE;
  67. info->phc_index = ptp_clock_index(chip->ptp_clock);
  68. info->tx_types =
  69. (1 << HWTSTAMP_TX_OFF) |
  70. (1 << HWTSTAMP_TX_ON);
  71. info->rx_filters = ptp_ops->rx_filters;
  72. return 0;
  73. }
  74. static int mv88e6xxx_set_hwtstamp_config(struct mv88e6xxx_chip *chip, int port,
  75. struct hwtstamp_config *config)
  76. {
  77. const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
  78. struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
  79. bool tstamp_enable = false;
  80. /* Prevent the TX/RX paths from trying to interact with the
  81. * timestamp hardware while we reconfigure it.
  82. */
  83. clear_bit_unlock(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state);
  84. switch (config->tx_type) {
  85. case HWTSTAMP_TX_OFF:
  86. tstamp_enable = false;
  87. break;
  88. case HWTSTAMP_TX_ON:
  89. tstamp_enable = true;
  90. break;
  91. default:
  92. return -ERANGE;
  93. }
  94. /* The switch supports timestamping both L2 and L4; one cannot be
  95. * disabled independently of the other.
  96. */
  97. if (!(BIT(config->rx_filter) & ptp_ops->rx_filters)) {
  98. config->rx_filter = HWTSTAMP_FILTER_NONE;
  99. dev_dbg(chip->dev, "Unsupported rx_filter %d\n",
  100. config->rx_filter);
  101. return -ERANGE;
  102. }
  103. switch (config->rx_filter) {
  104. case HWTSTAMP_FILTER_NONE:
  105. tstamp_enable = false;
  106. break;
  107. case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
  108. case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
  109. case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
  110. case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
  111. case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
  112. case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
  113. case HWTSTAMP_FILTER_PTP_V2_EVENT:
  114. case HWTSTAMP_FILTER_PTP_V2_SYNC:
  115. case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
  116. config->rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
  117. break;
  118. case HWTSTAMP_FILTER_ALL:
  119. default:
  120. config->rx_filter = HWTSTAMP_FILTER_NONE;
  121. return -ERANGE;
  122. }
  123. mv88e6xxx_reg_lock(chip);
  124. if (tstamp_enable) {
  125. chip->enable_count += 1;
  126. if (chip->enable_count == 1 && ptp_ops->global_enable)
  127. ptp_ops->global_enable(chip);
  128. if (ptp_ops->port_enable)
  129. ptp_ops->port_enable(chip, port);
  130. } else {
  131. if (ptp_ops->port_disable)
  132. ptp_ops->port_disable(chip, port);
  133. chip->enable_count -= 1;
  134. if (chip->enable_count == 0 && ptp_ops->global_disable)
  135. ptp_ops->global_disable(chip);
  136. }
  137. mv88e6xxx_reg_unlock(chip);
  138. /* Once hardware has been configured, enable timestamp checks
  139. * in the RX/TX paths.
  140. */
  141. if (tstamp_enable)
  142. set_bit(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state);
  143. return 0;
  144. }
  145. int mv88e6xxx_port_hwtstamp_set(struct dsa_switch *ds, int port,
  146. struct ifreq *ifr)
  147. {
  148. struct mv88e6xxx_chip *chip = ds->priv;
  149. struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
  150. struct hwtstamp_config config;
  151. int err;
  152. if (!chip->info->ptp_support)
  153. return -EOPNOTSUPP;
  154. if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
  155. return -EFAULT;
  156. err = mv88e6xxx_set_hwtstamp_config(chip, port, &config);
  157. if (err)
  158. return err;
  159. /* Save the chosen configuration to be returned later. */
  160. memcpy(&ps->tstamp_config, &config, sizeof(config));
  161. return copy_to_user(ifr->ifr_data, &config, sizeof(config)) ?
  162. -EFAULT : 0;
  163. }
  164. int mv88e6xxx_port_hwtstamp_get(struct dsa_switch *ds, int port,
  165. struct ifreq *ifr)
  166. {
  167. struct mv88e6xxx_chip *chip = ds->priv;
  168. struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
  169. struct hwtstamp_config *config = &ps->tstamp_config;
  170. if (!chip->info->ptp_support)
  171. return -EOPNOTSUPP;
  172. return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ?
  173. -EFAULT : 0;
  174. }
  175. /* Returns a pointer to the PTP header if the caller should time stamp,
  176. * or NULL if the caller should not.
  177. */
  178. static struct ptp_header *mv88e6xxx_should_tstamp(struct mv88e6xxx_chip *chip,
  179. int port, struct sk_buff *skb,
  180. unsigned int type)
  181. {
  182. struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
  183. struct ptp_header *hdr;
  184. if (!chip->info->ptp_support)
  185. return NULL;
  186. hdr = ptp_parse_header(skb, type);
  187. if (!hdr)
  188. return NULL;
  189. if (!test_bit(MV88E6XXX_HWTSTAMP_ENABLED, &ps->state))
  190. return NULL;
  191. return hdr;
  192. }
  193. static int mv88e6xxx_ts_valid(u16 status)
  194. {
  195. if (!(status & MV88E6XXX_PTP_TS_VALID))
  196. return 0;
  197. if (status & MV88E6XXX_PTP_TS_STATUS_MASK)
  198. return 0;
  199. return 1;
  200. }
  201. static int seq_match(struct sk_buff *skb, u16 ts_seqid)
  202. {
  203. unsigned int type = SKB_PTP_TYPE(skb);
  204. struct ptp_header *hdr;
  205. hdr = ptp_parse_header(skb, type);
  206. return ts_seqid == ntohs(hdr->sequence_id);
  207. }
  208. static void mv88e6xxx_get_rxts(struct mv88e6xxx_chip *chip,
  209. struct mv88e6xxx_port_hwtstamp *ps,
  210. struct sk_buff *skb, u16 reg,
  211. struct sk_buff_head *rxq)
  212. {
  213. u16 buf[4] = { 0 }, status, seq_id;
  214. struct skb_shared_hwtstamps *shwt;
  215. struct sk_buff_head received;
  216. u64 ns, timelo, timehi;
  217. unsigned long flags;
  218. int err;
  219. /* The latched timestamp belongs to one of the received frames. */
  220. __skb_queue_head_init(&received);
  221. spin_lock_irqsave(&rxq->lock, flags);
  222. skb_queue_splice_tail_init(rxq, &received);
  223. spin_unlock_irqrestore(&rxq->lock, flags);
  224. mv88e6xxx_reg_lock(chip);
  225. err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
  226. reg, buf, ARRAY_SIZE(buf));
  227. mv88e6xxx_reg_unlock(chip);
  228. if (err)
  229. pr_err("failed to get the receive time stamp\n");
  230. status = buf[0];
  231. timelo = buf[1];
  232. timehi = buf[2];
  233. seq_id = buf[3];
  234. if (status & MV88E6XXX_PTP_TS_VALID) {
  235. mv88e6xxx_reg_lock(chip);
  236. err = mv88e6xxx_port_ptp_write(chip, ps->port_id, reg, 0);
  237. mv88e6xxx_reg_unlock(chip);
  238. if (err)
  239. pr_err("failed to clear the receive status\n");
  240. }
  241. /* Since the device can only handle one time stamp at a time,
  242. * we purge any extra frames from the queue.
  243. */
  244. for ( ; skb; skb = __skb_dequeue(&received)) {
  245. if (mv88e6xxx_ts_valid(status) && seq_match(skb, seq_id)) {
  246. ns = timehi << 16 | timelo;
  247. mv88e6xxx_reg_lock(chip);
  248. ns = timecounter_cyc2time(&chip->tstamp_tc, ns);
  249. mv88e6xxx_reg_unlock(chip);
  250. shwt = skb_hwtstamps(skb);
  251. memset(shwt, 0, sizeof(*shwt));
  252. shwt->hwtstamp = ns_to_ktime(ns);
  253. status &= ~MV88E6XXX_PTP_TS_VALID;
  254. }
  255. netif_rx(skb);
  256. }
  257. }
  258. static void mv88e6xxx_rxtstamp_work(struct mv88e6xxx_chip *chip,
  259. struct mv88e6xxx_port_hwtstamp *ps)
  260. {
  261. const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
  262. struct sk_buff *skb;
  263. skb = skb_dequeue(&ps->rx_queue);
  264. if (skb)
  265. mv88e6xxx_get_rxts(chip, ps, skb, ptp_ops->arr0_sts_reg,
  266. &ps->rx_queue);
  267. skb = skb_dequeue(&ps->rx_queue2);
  268. if (skb)
  269. mv88e6xxx_get_rxts(chip, ps, skb, ptp_ops->arr1_sts_reg,
  270. &ps->rx_queue2);
  271. }
  272. static int is_pdelay_resp(const struct ptp_header *hdr)
  273. {
  274. return (hdr->tsmt & 0xf) == 3;
  275. }
  276. bool mv88e6xxx_port_rxtstamp(struct dsa_switch *ds, int port,
  277. struct sk_buff *skb, unsigned int type)
  278. {
  279. struct mv88e6xxx_port_hwtstamp *ps;
  280. struct mv88e6xxx_chip *chip;
  281. struct ptp_header *hdr;
  282. chip = ds->priv;
  283. ps = &chip->port_hwtstamp[port];
  284. if (ps->tstamp_config.rx_filter != HWTSTAMP_FILTER_PTP_V2_EVENT)
  285. return false;
  286. hdr = mv88e6xxx_should_tstamp(chip, port, skb, type);
  287. if (!hdr)
  288. return false;
  289. SKB_PTP_TYPE(skb) = type;
  290. if (is_pdelay_resp(hdr))
  291. skb_queue_tail(&ps->rx_queue2, skb);
  292. else
  293. skb_queue_tail(&ps->rx_queue, skb);
  294. ptp_schedule_worker(chip->ptp_clock, 0);
  295. return true;
  296. }
  297. static int mv88e6xxx_txtstamp_work(struct mv88e6xxx_chip *chip,
  298. struct mv88e6xxx_port_hwtstamp *ps)
  299. {
  300. const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
  301. struct skb_shared_hwtstamps shhwtstamps;
  302. u16 departure_block[4], status;
  303. struct sk_buff *tmp_skb;
  304. u32 time_raw;
  305. int err;
  306. u64 ns;
  307. if (!ps->tx_skb)
  308. return 0;
  309. mv88e6xxx_reg_lock(chip);
  310. err = mv88e6xxx_port_ptp_read(chip, ps->port_id,
  311. ptp_ops->dep_sts_reg,
  312. departure_block,
  313. ARRAY_SIZE(departure_block));
  314. mv88e6xxx_reg_unlock(chip);
  315. if (err)
  316. goto free_and_clear_skb;
  317. if (!(departure_block[0] & MV88E6XXX_PTP_TS_VALID)) {
  318. if (time_is_before_jiffies(ps->tx_tstamp_start +
  319. TX_TSTAMP_TIMEOUT)) {
  320. dev_warn(chip->dev, "p%d: clearing tx timestamp hang\n",
  321. ps->port_id);
  322. goto free_and_clear_skb;
  323. }
  324. /* The timestamp should be available quickly, while getting it
  325. * is high priority and time bounded to only 10ms. A poll is
  326. * warranted so restart the work.
  327. */
  328. return 1;
  329. }
  330. /* We have the timestamp; go ahead and clear valid now */
  331. mv88e6xxx_reg_lock(chip);
  332. mv88e6xxx_port_ptp_write(chip, ps->port_id, ptp_ops->dep_sts_reg, 0);
  333. mv88e6xxx_reg_unlock(chip);
  334. status = departure_block[0] & MV88E6XXX_PTP_TS_STATUS_MASK;
  335. if (status != MV88E6XXX_PTP_TS_STATUS_NORMAL) {
  336. dev_warn(chip->dev, "p%d: tx timestamp overrun\n", ps->port_id);
  337. goto free_and_clear_skb;
  338. }
  339. if (departure_block[3] != ps->tx_seq_id) {
  340. dev_warn(chip->dev, "p%d: unexpected seq. id\n", ps->port_id);
  341. goto free_and_clear_skb;
  342. }
  343. memset(&shhwtstamps, 0, sizeof(shhwtstamps));
  344. time_raw = ((u32)departure_block[2] << 16) | departure_block[1];
  345. mv88e6xxx_reg_lock(chip);
  346. ns = timecounter_cyc2time(&chip->tstamp_tc, time_raw);
  347. mv88e6xxx_reg_unlock(chip);
  348. shhwtstamps.hwtstamp = ns_to_ktime(ns);
  349. dev_dbg(chip->dev,
  350. "p%d: txtstamp %llx status 0x%04x skb ID 0x%04x hw ID 0x%04x\n",
  351. ps->port_id, ktime_to_ns(shhwtstamps.hwtstamp),
  352. departure_block[0], ps->tx_seq_id, departure_block[3]);
  353. /* skb_complete_tx_timestamp() will free up the client to make
  354. * another timestamp-able transmit. We have to be ready for it
  355. * -- by clearing the ps->tx_skb "flag" -- beforehand.
  356. */
  357. tmp_skb = ps->tx_skb;
  358. ps->tx_skb = NULL;
  359. clear_bit_unlock(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state);
  360. skb_complete_tx_timestamp(tmp_skb, &shhwtstamps);
  361. return 0;
  362. free_and_clear_skb:
  363. dev_kfree_skb_any(ps->tx_skb);
  364. ps->tx_skb = NULL;
  365. clear_bit_unlock(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state);
  366. return 0;
  367. }
  368. long mv88e6xxx_hwtstamp_work(struct ptp_clock_info *ptp)
  369. {
  370. struct mv88e6xxx_chip *chip = ptp_to_chip(ptp);
  371. struct dsa_switch *ds = chip->ds;
  372. struct mv88e6xxx_port_hwtstamp *ps;
  373. int i, restart = 0;
  374. for (i = 0; i < ds->num_ports; i++) {
  375. if (!dsa_is_user_port(ds, i))
  376. continue;
  377. ps = &chip->port_hwtstamp[i];
  378. if (test_bit(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state))
  379. restart |= mv88e6xxx_txtstamp_work(chip, ps);
  380. mv88e6xxx_rxtstamp_work(chip, ps);
  381. }
  382. return restart ? 1 : -1;
  383. }
  384. void mv88e6xxx_port_txtstamp(struct dsa_switch *ds, int port,
  385. struct sk_buff *skb)
  386. {
  387. struct mv88e6xxx_chip *chip = ds->priv;
  388. struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
  389. struct ptp_header *hdr;
  390. struct sk_buff *clone;
  391. unsigned int type;
  392. type = ptp_classify_raw(skb);
  393. if (type == PTP_CLASS_NONE)
  394. return;
  395. hdr = mv88e6xxx_should_tstamp(chip, port, skb, type);
  396. if (!hdr)
  397. return;
  398. clone = skb_clone_sk(skb);
  399. if (!clone)
  400. return;
  401. if (test_and_set_bit_lock(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS,
  402. &ps->state)) {
  403. kfree_skb(clone);
  404. return;
  405. }
  406. ps->tx_skb = clone;
  407. ps->tx_tstamp_start = jiffies;
  408. ps->tx_seq_id = be16_to_cpu(hdr->sequence_id);
  409. ptp_schedule_worker(chip->ptp_clock, 0);
  410. }
  411. int mv88e6165_global_disable(struct mv88e6xxx_chip *chip)
  412. {
  413. u16 val;
  414. int err;
  415. err = mv88e6xxx_ptp_read(chip, MV88E6165_PTP_CFG, &val);
  416. if (err)
  417. return err;
  418. val |= MV88E6165_PTP_CFG_DISABLE_PTP;
  419. return mv88e6xxx_ptp_write(chip, MV88E6165_PTP_CFG, val);
  420. }
  421. int mv88e6165_global_enable(struct mv88e6xxx_chip *chip)
  422. {
  423. u16 val;
  424. int err;
  425. err = mv88e6xxx_ptp_read(chip, MV88E6165_PTP_CFG, &val);
  426. if (err)
  427. return err;
  428. val &= ~(MV88E6165_PTP_CFG_DISABLE_PTP | MV88E6165_PTP_CFG_TSPEC_MASK);
  429. return mv88e6xxx_ptp_write(chip, MV88E6165_PTP_CFG, val);
  430. }
  431. int mv88e6352_hwtstamp_port_disable(struct mv88e6xxx_chip *chip, int port)
  432. {
  433. return mv88e6xxx_port_ptp_write(chip, port, MV88E6XXX_PORT_PTP_CFG0,
  434. MV88E6XXX_PORT_PTP_CFG0_DISABLE_PTP);
  435. }
  436. int mv88e6352_hwtstamp_port_enable(struct mv88e6xxx_chip *chip, int port)
  437. {
  438. return mv88e6xxx_port_ptp_write(chip, port, MV88E6XXX_PORT_PTP_CFG0,
  439. MV88E6XXX_PORT_PTP_CFG0_DISABLE_TSPEC_MATCH);
  440. }
  441. static int mv88e6xxx_hwtstamp_port_setup(struct mv88e6xxx_chip *chip, int port)
  442. {
  443. const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
  444. struct mv88e6xxx_port_hwtstamp *ps = &chip->port_hwtstamp[port];
  445. ps->port_id = port;
  446. skb_queue_head_init(&ps->rx_queue);
  447. skb_queue_head_init(&ps->rx_queue2);
  448. if (ptp_ops->port_disable)
  449. return ptp_ops->port_disable(chip, port);
  450. return 0;
  451. }
  452. int mv88e6xxx_hwtstamp_setup(struct mv88e6xxx_chip *chip)
  453. {
  454. const struct mv88e6xxx_ptp_ops *ptp_ops = chip->info->ops->ptp_ops;
  455. int err;
  456. int i;
  457. /* Disable timestamping on all ports. */
  458. for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) {
  459. err = mv88e6xxx_hwtstamp_port_setup(chip, i);
  460. if (err)
  461. return err;
  462. }
  463. /* Disable PTP globally */
  464. if (ptp_ops->global_disable) {
  465. err = ptp_ops->global_disable(chip);
  466. if (err)
  467. return err;
  468. }
  469. /* Set the ethertype of L2 PTP messages */
  470. err = mv88e6xxx_ptp_write(chip, MV88E6XXX_PTP_GC_ETYPE, ETH_P_1588);
  471. if (err)
  472. return err;
  473. /* MV88E6XXX_PTP_MSG_TYPE is a mask of PTP message types to
  474. * timestamp. This affects all ports that have timestamping enabled,
  475. * but the timestamp config is per-port; thus we configure all events
  476. * here and only support the HWTSTAMP_FILTER_*_EVENT filter types.
  477. */
  478. err = mv88e6xxx_ptp_write(chip, MV88E6XXX_PTP_MSGTYPE,
  479. MV88E6XXX_PTP_MSGTYPE_ALL_EVENT);
  480. if (err)
  481. return err;
  482. /* Use ARRIVAL1 for peer delay response messages. */
  483. err = mv88e6xxx_ptp_write(chip, MV88E6XXX_PTP_TS_ARRIVAL_PTR,
  484. MV88E6XXX_PTP_MSGTYPE_PDLAY_RES);
  485. if (err)
  486. return err;
  487. /* 88E6341 devices default to timestamping at the PHY, but this has
  488. * a hardware issue that results in unreliable timestamps. Force
  489. * these devices to timestamp at the MAC.
  490. */
  491. if (chip->info->family == MV88E6XXX_FAMILY_6341) {
  492. u16 val = MV88E6341_PTP_CFG_UPDATE |
  493. MV88E6341_PTP_CFG_MODE_IDX |
  494. MV88E6341_PTP_CFG_MODE_TS_AT_MAC;
  495. err = mv88e6xxx_ptp_write(chip, MV88E6341_PTP_CFG, val);
  496. if (err)
  497. return err;
  498. }
  499. return 0;
  500. }
  501. void mv88e6xxx_hwtstamp_free(struct mv88e6xxx_chip *chip)
  502. {
  503. }