Lines Matching +full:wo +full:- +full:ccif
1 // SPDX-License-Identifier: GPL-2.0-only
9 #include <linux/dma-mapping.h>
21 mtk_wed_mmio_r32(struct mtk_wed_wo *wo, u32 reg) in mtk_wed_mmio_r32() argument
25 if (regmap_read(wo->mmio.regs, reg, &val)) in mtk_wed_mmio_r32()
32 mtk_wed_mmio_w32(struct mtk_wed_wo *wo, u32 reg, u32 val) in mtk_wed_mmio_w32() argument
34 regmap_write(wo->mmio.regs, reg, val); in mtk_wed_mmio_w32()
38 mtk_wed_wo_get_isr(struct mtk_wed_wo *wo) in mtk_wed_wo_get_isr() argument
40 u32 val = mtk_wed_mmio_r32(wo, MTK_WED_WO_CCIF_RCHNUM); in mtk_wed_wo_get_isr()
46 mtk_wed_wo_set_isr(struct mtk_wed_wo *wo, u32 mask) in mtk_wed_wo_set_isr() argument
48 mtk_wed_mmio_w32(wo, MTK_WED_WO_CCIF_IRQ0_MASK, mask); in mtk_wed_wo_set_isr()
52 mtk_wed_wo_set_ack(struct mtk_wed_wo *wo, u32 mask) in mtk_wed_wo_set_ack() argument
54 mtk_wed_mmio_w32(wo, MTK_WED_WO_CCIF_ACK, mask); in mtk_wed_wo_set_ack()
58 mtk_wed_wo_set_isr_mask(struct mtk_wed_wo *wo, u32 mask, u32 val, bool set) in mtk_wed_wo_set_isr_mask() argument
62 spin_lock_irqsave(&wo->mmio.lock, flags); in mtk_wed_wo_set_isr_mask()
63 wo->mmio.irq_mask &= ~mask; in mtk_wed_wo_set_isr_mask()
64 wo->mmio.irq_mask |= val; in mtk_wed_wo_set_isr_mask()
66 mtk_wed_wo_set_isr(wo, wo->mmio.irq_mask); in mtk_wed_wo_set_isr_mask()
67 spin_unlock_irqrestore(&wo->mmio.lock, flags); in mtk_wed_wo_set_isr_mask()
71 mtk_wed_wo_irq_enable(struct mtk_wed_wo *wo, u32 mask) in mtk_wed_wo_irq_enable() argument
73 mtk_wed_wo_set_isr_mask(wo, 0, mask, false); in mtk_wed_wo_irq_enable()
74 tasklet_schedule(&wo->mmio.irq_tasklet); in mtk_wed_wo_irq_enable()
78 mtk_wed_wo_irq_disable(struct mtk_wed_wo *wo, u32 mask) in mtk_wed_wo_irq_disable() argument
80 mtk_wed_wo_set_isr_mask(wo, mask, 0, true); in mtk_wed_wo_irq_disable()
84 mtk_wed_wo_kickout(struct mtk_wed_wo *wo) in mtk_wed_wo_kickout() argument
86 mtk_wed_mmio_w32(wo, MTK_WED_WO_CCIF_BUSY, 1 << MTK_WED_WO_TXCH_NUM); in mtk_wed_wo_kickout()
87 mtk_wed_mmio_w32(wo, MTK_WED_WO_CCIF_TCHNUM, MTK_WED_WO_TXCH_NUM); in mtk_wed_wo_kickout()
91 mtk_wed_wo_queue_kick(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, in mtk_wed_wo_queue_kick() argument
95 mtk_wed_mmio_w32(wo, q->regs.cpu_idx, val); in mtk_wed_wo_queue_kick()
99 mtk_wed_wo_dequeue(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, u32 *len, in mtk_wed_wo_dequeue() argument
102 int buf_len = SKB_WITH_OVERHEAD(q->buf_size); in mtk_wed_wo_dequeue()
103 int index = (q->tail + 1) % q->n_desc; in mtk_wed_wo_dequeue()
108 if (!q->queued) in mtk_wed_wo_dequeue()
112 q->desc[index].ctrl |= cpu_to_le32(MTK_WED_WO_CTL_DMA_DONE); in mtk_wed_wo_dequeue()
113 else if (!(q->desc[index].ctrl & cpu_to_le32(MTK_WED_WO_CTL_DMA_DONE))) in mtk_wed_wo_dequeue()
116 q->tail = index; in mtk_wed_wo_dequeue()
117 q->queued--; in mtk_wed_wo_dequeue()
119 desc = &q->desc[index]; in mtk_wed_wo_dequeue()
120 entry = &q->entry[index]; in mtk_wed_wo_dequeue()
121 buf = entry->buf; in mtk_wed_wo_dequeue()
124 le32_to_cpu(READ_ONCE(desc->ctrl))); in mtk_wed_wo_dequeue()
126 dma_unmap_single(wo->hw->dev, entry->addr, buf_len, in mtk_wed_wo_dequeue()
128 entry->buf = NULL; in mtk_wed_wo_dequeue()
134 mtk_wed_wo_queue_refill(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, in mtk_wed_wo_queue_refill() argument
140 while (q->queued < q->n_desc) { in mtk_wed_wo_queue_refill()
145 buf = page_frag_alloc(&q->cache, q->buf_size, in mtk_wed_wo_queue_refill()
150 addr = dma_map_single(wo->hw->dev, buf, q->buf_size, dir); in mtk_wed_wo_queue_refill()
151 if (unlikely(dma_mapping_error(wo->hw->dev, addr))) { in mtk_wed_wo_queue_refill()
156 q->head = (q->head + 1) % q->n_desc; in mtk_wed_wo_queue_refill()
157 entry = &q->entry[q->head]; in mtk_wed_wo_queue_refill()
158 entry->addr = addr; in mtk_wed_wo_queue_refill()
159 entry->len = q->buf_size; in mtk_wed_wo_queue_refill()
160 q->entry[q->head].buf = buf; in mtk_wed_wo_queue_refill()
163 struct mtk_wed_wo_queue_desc *desc = &q->desc[q->head]; in mtk_wed_wo_queue_refill()
166 entry->len); in mtk_wed_wo_queue_refill()
168 WRITE_ONCE(desc->buf0, cpu_to_le32(addr)); in mtk_wed_wo_queue_refill()
169 WRITE_ONCE(desc->ctrl, cpu_to_le32(ctrl)); in mtk_wed_wo_queue_refill()
171 q->queued++; in mtk_wed_wo_queue_refill()
179 mtk_wed_wo_rx_complete(struct mtk_wed_wo *wo) in mtk_wed_wo_rx_complete() argument
181 mtk_wed_wo_set_ack(wo, MTK_WED_WO_RXCH_INT_MASK); in mtk_wed_wo_rx_complete()
182 mtk_wed_wo_irq_enable(wo, MTK_WED_WO_RXCH_INT_MASK); in mtk_wed_wo_rx_complete()
186 mtk_wed_wo_rx_run_queue(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) in mtk_wed_wo_rx_run_queue() argument
194 data = mtk_wed_wo_dequeue(wo, q, &len, false); in mtk_wed_wo_rx_run_queue()
198 skb = build_skb(data, q->buf_size); in mtk_wed_wo_rx_run_queue()
205 if (mtk_wed_mcu_check_msg(wo, skb)) { in mtk_wed_wo_rx_run_queue()
210 hdr = (struct mtk_wed_mcu_hdr *)skb->data; in mtk_wed_wo_rx_run_queue()
211 if (hdr->flag & cpu_to_le16(MTK_WED_WARP_CMD_FLAG_RSP)) in mtk_wed_wo_rx_run_queue()
212 mtk_wed_mcu_rx_event(wo, skb); in mtk_wed_wo_rx_run_queue()
214 mtk_wed_mcu_rx_unsolicited_event(wo, skb); in mtk_wed_wo_rx_run_queue()
217 if (mtk_wed_wo_queue_refill(wo, q, true)) { in mtk_wed_wo_rx_run_queue()
218 u32 index = (q->head - 1) % q->n_desc; in mtk_wed_wo_rx_run_queue()
220 mtk_wed_wo_queue_kick(wo, q, index); in mtk_wed_wo_rx_run_queue()
227 struct mtk_wed_wo *wo = data; in mtk_wed_wo_irq_handler() local
229 mtk_wed_wo_set_isr(wo, 0); in mtk_wed_wo_irq_handler()
230 tasklet_schedule(&wo->mmio.irq_tasklet); in mtk_wed_wo_irq_handler()
237 struct mtk_wed_wo *wo = from_tasklet(wo, t, mmio.irq_tasklet); in mtk_wed_wo_irq_tasklet() local
241 mtk_wed_wo_set_isr(wo, 0); in mtk_wed_wo_irq_tasklet()
243 intr = mtk_wed_wo_get_isr(wo); in mtk_wed_wo_irq_tasklet()
244 intr &= wo->mmio.irq_mask; in mtk_wed_wo_irq_tasklet()
246 mtk_wed_wo_irq_disable(wo, mask); in mtk_wed_wo_irq_tasklet()
249 mtk_wed_wo_rx_run_queue(wo, &wo->q_rx); in mtk_wed_wo_irq_tasklet()
250 mtk_wed_wo_rx_complete(wo); in mtk_wed_wo_irq_tasklet()
254 /* mtk wed wo hw queues */
257 mtk_wed_wo_queue_alloc(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, in mtk_wed_wo_queue_alloc() argument
261 q->regs = *regs; in mtk_wed_wo_queue_alloc()
262 q->n_desc = n_desc; in mtk_wed_wo_queue_alloc()
263 q->buf_size = buf_size; in mtk_wed_wo_queue_alloc()
265 q->desc = dmam_alloc_coherent(wo->hw->dev, n_desc * sizeof(*q->desc), in mtk_wed_wo_queue_alloc()
266 &q->desc_dma, GFP_KERNEL); in mtk_wed_wo_queue_alloc()
267 if (!q->desc) in mtk_wed_wo_queue_alloc()
268 return -ENOMEM; in mtk_wed_wo_queue_alloc()
270 q->entry = devm_kzalloc(wo->hw->dev, n_desc * sizeof(*q->entry), in mtk_wed_wo_queue_alloc()
272 if (!q->entry) in mtk_wed_wo_queue_alloc()
273 return -ENOMEM; in mtk_wed_wo_queue_alloc()
279 mtk_wed_wo_queue_free(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) in mtk_wed_wo_queue_free() argument
281 mtk_wed_mmio_w32(wo, q->regs.cpu_idx, 0); in mtk_wed_wo_queue_free()
282 dma_free_coherent(wo->hw->dev, q->n_desc * sizeof(*q->desc), q->desc, in mtk_wed_wo_queue_free()
283 q->desc_dma); in mtk_wed_wo_queue_free()
287 mtk_wed_wo_queue_tx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) in mtk_wed_wo_queue_tx_clean() argument
291 for (i = 0; i < q->n_desc; i++) { in mtk_wed_wo_queue_tx_clean()
292 struct mtk_wed_wo_queue_entry *entry = &q->entry[i]; in mtk_wed_wo_queue_tx_clean()
294 if (!entry->buf) in mtk_wed_wo_queue_tx_clean()
297 dma_unmap_single(wo->hw->dev, entry->addr, entry->len, in mtk_wed_wo_queue_tx_clean()
299 skb_free_frag(entry->buf); in mtk_wed_wo_queue_tx_clean()
300 entry->buf = NULL; in mtk_wed_wo_queue_tx_clean()
303 page_frag_cache_drain(&q->cache); in mtk_wed_wo_queue_tx_clean()
307 mtk_wed_wo_queue_rx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) in mtk_wed_wo_queue_rx_clean() argument
310 void *buf = mtk_wed_wo_dequeue(wo, q, NULL, true); in mtk_wed_wo_queue_rx_clean()
318 page_frag_cache_drain(&q->cache); in mtk_wed_wo_queue_rx_clean()
322 mtk_wed_wo_queue_reset(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q) in mtk_wed_wo_queue_reset() argument
324 mtk_wed_mmio_w32(wo, q->regs.cpu_idx, 0); in mtk_wed_wo_queue_reset()
325 mtk_wed_mmio_w32(wo, q->regs.desc_base, q->desc_dma); in mtk_wed_wo_queue_reset()
326 mtk_wed_mmio_w32(wo, q->regs.ring_size, q->n_desc); in mtk_wed_wo_queue_reset()
329 int mtk_wed_wo_queue_tx_skb(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q, in mtk_wed_wo_queue_tx_skb() argument
337 q->tail = mtk_wed_mmio_r32(wo, q->regs.dma_idx); in mtk_wed_wo_queue_tx_skb()
338 index = (q->head + 1) % q->n_desc; in mtk_wed_wo_queue_tx_skb()
339 if (q->tail == index) { in mtk_wed_wo_queue_tx_skb()
340 ret = -ENOMEM; in mtk_wed_wo_queue_tx_skb()
344 entry = &q->entry[index]; in mtk_wed_wo_queue_tx_skb()
345 if (skb->len > entry->len) { in mtk_wed_wo_queue_tx_skb()
346 ret = -ENOMEM; in mtk_wed_wo_queue_tx_skb()
350 desc = &q->desc[index]; in mtk_wed_wo_queue_tx_skb()
351 q->head = index; in mtk_wed_wo_queue_tx_skb()
353 dma_sync_single_for_cpu(wo->hw->dev, entry->addr, skb->len, in mtk_wed_wo_queue_tx_skb()
355 memcpy(entry->buf, skb->data, skb->len); in mtk_wed_wo_queue_tx_skb()
356 dma_sync_single_for_device(wo->hw->dev, entry->addr, skb->len, in mtk_wed_wo_queue_tx_skb()
359 ctrl = FIELD_PREP(MTK_WED_WO_CTL_SD_LEN0, skb->len) | in mtk_wed_wo_queue_tx_skb()
361 WRITE_ONCE(desc->buf0, cpu_to_le32(entry->addr)); in mtk_wed_wo_queue_tx_skb()
362 WRITE_ONCE(desc->ctrl, cpu_to_le32(ctrl)); in mtk_wed_wo_queue_tx_skb()
364 mtk_wed_wo_queue_kick(wo, q, q->head); in mtk_wed_wo_queue_tx_skb()
365 mtk_wed_wo_kickout(wo); in mtk_wed_wo_queue_tx_skb()
373 mtk_wed_wo_exception_init(struct mtk_wed_wo *wo) in mtk_wed_wo_exception_init() argument
379 mtk_wed_wo_hardware_init(struct mtk_wed_wo *wo) in mtk_wed_wo_hardware_init() argument
385 np = of_parse_phandle(wo->hw->node, "mediatek,wo-ccif", 0); in mtk_wed_wo_hardware_init()
387 return -ENODEV; in mtk_wed_wo_hardware_init()
389 wo->mmio.regs = syscon_regmap_lookup_by_phandle(np, NULL); in mtk_wed_wo_hardware_init()
390 if (IS_ERR(wo->mmio.regs)) { in mtk_wed_wo_hardware_init()
391 ret = PTR_ERR(wo->mmio.regs); in mtk_wed_wo_hardware_init()
395 wo->mmio.irq = irq_of_parse_and_map(np, 0); in mtk_wed_wo_hardware_init()
396 wo->mmio.irq_mask = MTK_WED_WO_ALL_INT_MASK; in mtk_wed_wo_hardware_init()
397 spin_lock_init(&wo->mmio.lock); in mtk_wed_wo_hardware_init()
398 tasklet_setup(&wo->mmio.irq_tasklet, mtk_wed_wo_irq_tasklet); in mtk_wed_wo_hardware_init()
400 ret = devm_request_irq(wo->hw->dev, wo->mmio.irq, in mtk_wed_wo_hardware_init()
402 KBUILD_MODNAME, wo); in mtk_wed_wo_hardware_init()
411 ret = mtk_wed_wo_queue_alloc(wo, &wo->q_tx, MTK_WED_WO_RING_SIZE, in mtk_wed_wo_hardware_init()
417 mtk_wed_wo_queue_refill(wo, &wo->q_tx, false); in mtk_wed_wo_hardware_init()
418 mtk_wed_wo_queue_reset(wo, &wo->q_tx); in mtk_wed_wo_hardware_init()
425 ret = mtk_wed_wo_queue_alloc(wo, &wo->q_rx, MTK_WED_WO_RING_SIZE, in mtk_wed_wo_hardware_init()
431 mtk_wed_wo_queue_refill(wo, &wo->q_rx, true); in mtk_wed_wo_hardware_init()
432 mtk_wed_wo_queue_reset(wo, &wo->q_rx); in mtk_wed_wo_hardware_init()
435 mtk_wed_wo_set_isr(wo, wo->mmio.irq_mask); in mtk_wed_wo_hardware_init()
440 devm_free_irq(wo->hw->dev, wo->mmio.irq, wo); in mtk_wed_wo_hardware_init()
447 mtk_wed_wo_hw_deinit(struct mtk_wed_wo *wo) in mtk_wed_wo_hw_deinit() argument
450 mtk_wed_wo_set_isr(wo, 0); in mtk_wed_wo_hw_deinit()
452 tasklet_disable(&wo->mmio.irq_tasklet); in mtk_wed_wo_hw_deinit()
454 disable_irq(wo->mmio.irq); in mtk_wed_wo_hw_deinit()
455 devm_free_irq(wo->hw->dev, wo->mmio.irq, wo); in mtk_wed_wo_hw_deinit()
457 mtk_wed_wo_queue_tx_clean(wo, &wo->q_tx); in mtk_wed_wo_hw_deinit()
458 mtk_wed_wo_queue_rx_clean(wo, &wo->q_rx); in mtk_wed_wo_hw_deinit()
459 mtk_wed_wo_queue_free(wo, &wo->q_tx); in mtk_wed_wo_hw_deinit()
460 mtk_wed_wo_queue_free(wo, &wo->q_rx); in mtk_wed_wo_hw_deinit()
465 struct mtk_wed_wo *wo; in mtk_wed_wo_init() local
468 wo = devm_kzalloc(hw->dev, sizeof(*wo), GFP_KERNEL); in mtk_wed_wo_init()
469 if (!wo) in mtk_wed_wo_init()
470 return -ENOMEM; in mtk_wed_wo_init()
472 hw->wed_wo = wo; in mtk_wed_wo_init()
473 wo->hw = hw; in mtk_wed_wo_init()
475 ret = mtk_wed_wo_hardware_init(wo); in mtk_wed_wo_init()
479 ret = mtk_wed_mcu_init(wo); in mtk_wed_wo_init()
483 return mtk_wed_wo_exception_init(wo); in mtk_wed_wo_init()
488 struct mtk_wed_wo *wo = hw->wed_wo; in mtk_wed_wo_deinit() local
490 mtk_wed_wo_hw_deinit(wo); in mtk_wed_wo_deinit()