Lines Matching +full:sparx5 +full:- +full:switch
1 // SPDX-License-Identifier: GPL-2.0+
2 /* Microchip Sparx5 Switch driver
19 #define XTR_VALID_BYTES(x) (4 - ((x) & 3))
23 void sparx5_xtr_flush(struct sparx5 *sparx5, u8 grp) in sparx5_xtr_flush() argument
26 spx5_wr(QS_XTR_FLUSH_FLUSH_SET(BIT(grp)), sparx5, QS_XTR_FLUSH); in sparx5_xtr_flush()
32 spx5_wr(0, sparx5, QS_XTR_FLUSH); in sparx5_xtr_flush()
39 /* FWD is bit 45-72 (28 bits), but we only read the 27 LSB for now */ in sparx5_ifh_parse()
46 info->src_port = FIELD_GET(GENMASK(7, 1), fwd); in sparx5_ifh_parse()
49 * Bit 270-271 are occasionally unexpectedly set by the hardware, in sparx5_ifh_parse()
52 info->timestamp = in sparx5_ifh_parse()
59 static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap) in sparx5_xtr_grp() argument
72 ifh[i] = spx5_rd(sparx5, QS_XTR_RD(grp)); in sparx5_xtr_grp()
79 sparx5->ports[fi.src_port] : NULL; in sparx5_xtr_grp()
80 if (!port || !port->ndev) { in sparx5_xtr_grp()
81 dev_err(sparx5->dev, "Data on inactive port %d\n", fi.src_port); in sparx5_xtr_grp()
82 sparx5_xtr_flush(sparx5, grp); in sparx5_xtr_grp()
87 netdev = port->ndev; in sparx5_xtr_grp()
88 skb = netdev_alloc_skb(netdev, netdev->mtu + ETH_HLEN); in sparx5_xtr_grp()
90 sparx5_xtr_flush(sparx5, grp); in sparx5_xtr_grp()
91 dev_err(sparx5->dev, "No skb allocated\n"); in sparx5_xtr_grp()
92 netdev->stats.rx_dropped++; in sparx5_xtr_grp()
95 rxbuf = (u32 *)skb->data; in sparx5_xtr_grp()
99 u32 val = spx5_rd(sparx5, QS_XTR_RD(grp)); in sparx5_xtr_grp()
105 switch (cmp) { in sparx5_xtr_grp()
122 byte_cnt -= (4 - XTR_VALID_BYTES(val)); in sparx5_xtr_grp()
131 *rxbuf = spx5_rd(sparx5, QS_XTR_RD(grp)); in sparx5_xtr_grp()
146 netdev->stats.rx_dropped++; in sparx5_xtr_grp()
153 if (test_bit(port->portno, sparx5->bridge_mask)) in sparx5_xtr_grp()
154 skb->offload_fwd_mark = 1; in sparx5_xtr_grp()
157 skb_put(skb, byte_cnt - ETH_FCS_LEN); in sparx5_xtr_grp()
159 sparx5_ptp_rxtstamp(sparx5, skb, fi.timestamp); in sparx5_xtr_grp()
160 skb->protocol = eth_type_trans(skb, netdev); in sparx5_xtr_grp()
161 netdev->stats.rx_bytes += skb->len; in sparx5_xtr_grp()
162 netdev->stats.rx_packets++; in sparx5_xtr_grp()
166 static int sparx5_inject(struct sparx5 *sparx5, in sparx5_inject() argument
175 val = spx5_rd(sparx5, QS_INJ_STATUS); in sparx5_inject()
179 return -EBUSY; in sparx5_inject()
185 sparx5, QS_INJ_CTRL(grp)); in sparx5_inject()
189 spx5_wr(ifh[w], sparx5, QS_INJ_WR(grp)); in sparx5_inject()
192 count = DIV_ROUND_UP(skb->len, 4); in sparx5_inject()
193 buf = skb->data; in sparx5_inject()
196 spx5_wr(val, sparx5, QS_INJ_WR(grp)); in sparx5_inject()
201 spx5_wr(0, sparx5, QS_INJ_WR(grp)); in sparx5_inject()
207 QS_INJ_CTRL_VLD_BYTES_SET(skb->len < 60 ? 0 : skb->len % 4) | in sparx5_inject()
209 sparx5, QS_INJ_CTRL(grp)); in sparx5_inject()
212 spx5_wr(0, sparx5, QS_INJ_WR(grp)); in sparx5_inject()
215 val = spx5_rd(sparx5, QS_INJ_STATUS); in sparx5_inject()
222 hrtimer_start(&port->inj_timer, INJ_TIMEOUT_NS, in sparx5_inject()
231 struct net_device_stats *stats = &dev->stats; in sparx5_port_xmit_impl()
233 struct sparx5 *sparx5 = port->sparx5; in sparx5_port_xmit_impl() local
238 sparx5_set_port_ifh(ifh, port->portno); in sparx5_port_xmit_impl()
240 if (sparx5->ptp && skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP) { in sparx5_port_xmit_impl()
244 sparx5_set_port_ifh_rew_op(ifh, SPARX5_SKB_CB(skb)->rew_op); in sparx5_port_xmit_impl()
245 sparx5_set_port_ifh_pdu_type(ifh, SPARX5_SKB_CB(skb)->pdu_type); in sparx5_port_xmit_impl()
246 sparx5_set_port_ifh_pdu_w16_offset(ifh, SPARX5_SKB_CB(skb)->pdu_w16_offset); in sparx5_port_xmit_impl()
247 sparx5_set_port_ifh_timestamp(ifh, SPARX5_SKB_CB(skb)->ts_id); in sparx5_port_xmit_impl()
251 spin_lock(&sparx5->tx_lock); in sparx5_port_xmit_impl()
252 if (sparx5->fdma_irq > 0) in sparx5_port_xmit_impl()
253 ret = sparx5_fdma_xmit(sparx5, ifh, skb); in sparx5_port_xmit_impl()
255 ret = sparx5_inject(sparx5, ifh, skb, dev); in sparx5_port_xmit_impl()
256 spin_unlock(&sparx5->tx_lock); in sparx5_port_xmit_impl()
258 if (ret == -EBUSY) in sparx5_port_xmit_impl()
263 stats->tx_bytes += skb->len; in sparx5_port_xmit_impl()
264 stats->tx_packets++; in sparx5_port_xmit_impl()
265 sparx5->tx.packets++; in sparx5_port_xmit_impl()
267 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && in sparx5_port_xmit_impl()
268 SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP) in sparx5_port_xmit_impl()
274 stats->tx_dropped++; in sparx5_port_xmit_impl()
275 sparx5->tx.dropped++; in sparx5_port_xmit_impl()
279 if (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP && in sparx5_port_xmit_impl()
280 SPARX5_SKB_CB(skb)->rew_op == IFH_REW_OP_TWO_STEP_PTP) in sparx5_port_xmit_impl()
292 val = spx5_rd(port->sparx5, QS_INJ_STATUS); in sparx5_injection_timeout()
298 port->sparx5, in sparx5_injection_timeout()
299 DSM_DEV_TX_STOP_WM_CFG(port->portno)); in sparx5_injection_timeout()
301 netif_wake_queue(port->ndev); in sparx5_injection_timeout()
305 int sparx5_manual_injection_mode(struct sparx5 *sparx5) in sparx5_manual_injection_mode() argument
314 sparx5, QS_XTR_GRP_CFG(XTR_QUEUE)); in sparx5_manual_injection_mode()
317 sparx5, QS_INJ_GRP_CFG(INJ_QUEUE)); in sparx5_manual_injection_mode()
325 sparx5, ASM_PORT_CFG(portno)); in sparx5_manual_injection_mode()
330 sparx5, in sparx5_manual_injection_mode()
336 sparx5, in sparx5_manual_injection_mode()
343 sparx5, in sparx5_manual_injection_mode()
351 struct sparx5 *s5 = _sparx5; in sparx5_xtr_handler()
355 while (spx5_rd(s5, QS_XTR_DATA_PRESENT) & BIT(XTR_QUEUE) && poll-- > 0) in sparx5_xtr_handler()
363 hrtimer_init(&port->inj_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); in sparx5_port_inj_timer_setup()
364 port->inj_timer.function = sparx5_injection_timeout; in sparx5_port_inj_timer_setup()