Add support for QMC HDLC
Subsystems (5)
Herve Codina
maintainerv6 cover Add support for QMC HDLC
Hi,
This series introduces the QMC HDLC support.
Patches were previously sent as part of a full feature series and were previously reviewed in that context:
"Add support for QMC HDLC, framer infrastructure and PEF2256 framer" [1]
In order to ease the merge, the full feature series has been split and needed parts were merged in v6.8-rc1:
- "Prepare the PowerQUICC QMC and TSA for the HDLC QMC driver" [2]
- "Add support for framer infrastructure and PEF2256 framer" [3]
This series contains patches related to the QMC HDLC part (QMC HDLC driver):
- Introduce the QMC HDLC driver (patches 1 and 2)
- Add timeslots change support in QMC HDLC (patch 3)
- Add framer support as a framer consumer in QMC HDLC (patch 4)
Compare to the original full feature series, a modification was done on patch 3 in order to use a coherent prefix in the commit title.
I kept the patches unsquashed as they were previously sent and reviewed. Of course, I can squash them if needed.
Compared to the previous iteration:
https://lore.kernel.org/linux-kernel/[email protected]/
this v6 series mainly:
- Adds missing header file inclusion.
- Reworks loop in error handler.
- Improves readability.
- Adds 'Reviewed-by' tags.
Best regards,
Hervé
[1]: https://lore.kernel.org/linux-kernel/[email protected]/
[2]: https://lore.kernel.org/linux-kernel/[email protected]/
[3]: https://lore.kernel.org/linux-kernel/[email protected]/
Changes v5 -> v6
- Patch 1
Add missing header file inclusion.
Rework loop in qmc_hdlc_open() error handler.
Add 'Reviewed-by: Andy Shevchenko <[email protected]>'
- Patch 2
No changes.
- Patch 3
Avoid breaking API calls in kernel-doc to improve readability. Remove Andy's credit. Keep only his signed-off-by.
- Patch 4 and 5
Add 'Reviewed-by: Andy Shevchenko <[email protected]>'.
Changes v4 -> v5
- Patch 1
Update QMC_HDLC_RX_ERROR_FLAGS to improve readability. Display an error message after releasing resources instead of before.
Use 'struct device *dev' in probe().
Use dev_err_probe() in probe().
Do not print a message on -ENOMEM.
Use guard() and scoped_guard().
- Patch 3
Use '(). See' constructing in kernel-doc instead of '() (See ...' Add 'Co-developed-by: Herve Codina <[email protected]>'
- Patch 4
Use 'struct device *dev' in probe().
Use dev_err_probe() in probe().
Use '%64pb' instead of '%*pb' in printk formats.
- Patch 5
Use 'struct device *dev' in probe().
Use guard()
Changes v3 -> v4
- Patch 1
Remove of.h and of_platform.h includes, add mod_devicetable.h. Add a blank line in the includes list.
- Path 2
No changes.
- v3 patches 3 and 4 removed
- Patch 3 (new patch in v4)
Introduce bitmap_{scatter,gather}() based on the original patch done by Andy Shevchenko.
Address comments already done on the original patch:
https://lore.kernel.org/lkml/[email protected]/
- Removed the returned values.
- Used 'unsigned int' for all indexes.
- Added a 'visual' description of the operations in kernel-doc.
- Described the relationship between bitmap_scatter() and bitmap_gather().
- Moved bitmap_{scatter,gather}() to the bitmap.h file.
- Improved bitmap_{scatter,gather}() test.
- Reworked the commit log.
- Patch 4 (v3 patch 5)
Use bitmap_{scatter,gather}()
- Patches 5 (v3 patch 6)
No changes.
Changes v2 -> v3
- Patch 1
Remove 'inline' function specifier from .c file.
Fix a bug introduced when added WARN_ONCE(). The warn condition must be desc->skb (descriptor used) instead of !desc->skb. Remove a lock/unlock section locking the entire qmc_hdlc_xmit() function.
- Patch 5
Use bitmap_from_u64() everywhere instead of bitmap_from_arr32() and bitmap_from_arr64().
Changes v1 -> v2
- Patch 1
Use the same qmc_hdlc initialisation in qmc_hcld_recv_complete() than the one present in qmc_hcld_xmit_complete().
Use WARN_ONCE()
- Patch 3 (new patch in v2)
Make bitmap_onto() available to users
- Patch 4 (new patch in v2)
Introduce bitmap_off()
- Patch 5 (patch 3 in v1)
Use bitmap_*() functions
- Patch 6 (patch 4 in v1)
No changes
Changes compare to the full feature series:
- Patch 3
Use 'net: wan: fsl_qmc_hdlc:' as commit title prefix
Patches extracted:
- Patch 1 : full feature series patch 7
- Patch 2 : full feature series patch 8
- Patch 3 : full feature series patch 20
- Patch 4 : full feature series patch 27
Andy Shevchenko (1):
lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
Herve Codina (4):
net: wan: Add support for QMC HDLC
MAINTAINERS: Add the Freescale QMC HDLC driver entry
net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
net: wan: fsl_qmc_hdlc: Add framer support
MAINTAINERS | 7 + drivers/net/wan/Kconfig | 12 + drivers/net/wan/Makefile | 1 + drivers/net/wan/fsl_qmc_hdlc.c | 791 +++++++++++++++++++++++++++++++++ include/linux/bitmap.h | 101 +++++ lib/test_bitmap.c | 42 ++ 6 files changed, 954 insertions(+) create mode 100644 drivers/net/wan/fsl_qmc_hdlc.c
Signature · 1 line
2.43.0
Herve Codina
maintainerPATCH v6 1/5 net: wan: Add support for QMC HDLC
The QMC HDLC driver provides support for HDLC using the QMC (QUICC Multichannel Controller) to transfer the HDLC data.
--- drivers/net/wan/Kconfig | 12 + drivers/net/wan/Makefile | 1 + drivers/net/wan/fsl_qmc_hdlc.c | 413 +++++++++++++++++++++++++++++++++ 3 files changed, 426 insertions(+) create mode 100644 drivers/net/wan/fsl_qmc_hdlc.c
drivers/net/wan/Kconfig +12 -0
@@ -197,6 +197,18 @@ config FARSYNC To compile this driver as a module, choose M here: the module will be called farsync. +config FSL_QMC_HDLC + tristate "Freescale QMC HDLC support" + depends on HDLC + depends on CPM_QMC + help + HDLC support using the Freescale QUICC Multichannel Controller (QMC). + + To compile this driver as a module, choose M here: the + module will be called fsl_qmc_hdlc. + + If unsure, say N. + config FSL_UCC_HDLC tristate "Freescale QUICC Engine HDLC support" depends on HDLC
drivers/net/wan/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_WANXL) += wanxl.o obj-$(CONFIG_PCI200SYN) += pci200syn.o obj-$(CONFIG_PC300TOO) += pc300too.o obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o +obj-$(CONFIG_FSL_QMC_HDLC) += fsl_qmc_hdlc.o obj-$(CONFIG_FSL_UCC_HDLC) += fsl_ucc_hdlc.o obj-$(CONFIG_SLIC_DS26522) += slic_ds26522.o
drivers/net/wan/fsl_qmc_hdlc.c new file +413 -0
413 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Quoted 104 lines · Herve Codina
The QMC HDLC driver provides support for HDLC using the QMC (QUICC Multichannel Controller) to transfer the HDLC data.
Signed-off-by Herve Codina <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Acked-by Jakub Kicinski <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- drivers/net/wan/Kconfig | 12 + drivers/net/wan/Makefile | 1 + drivers/net/wan/fsl_qmc_hdlc.c | 413 +++++++++++++++++++++++++++++++++ 3 files changed, 426 insertions(+) create mode 100644 drivers/net/wan/fsl_qmc_hdlc.cdrivers/net/wan/Kconfig +12
-0@@ -197,6 +197,18 @@ config FARSYNC To compile this driver as a module, choose M here: the module will be called farsync. +config FSL_QMC_HDLC + tristate "Freescale QMC HDLC support" + depends on HDLC + depends on CPM_QMC + help + HDLC support using the Freescale QUICC Multichannel Controller (QMC). + + To compile this driver as a module, choose M here: the + module will be called fsl_qmc_hdlc. + + If unsure, say N. + config FSL_UCC_HDLC tristate "Freescale QUICC Engine HDLC support" depends on HDLCdrivers/net/wan/Makefile +1
-0@@ -25,6 +25,7 @@ obj-$(CONFIG_WANXL) += wanxl.o obj-$(CONFIG_PCI200SYN) += pci200syn.o obj-$(CONFIG_PC300TOO) += pc300too.o obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o +obj-$(CONFIG_FSL_QMC_HDLC) += fsl_qmc_hdlc.o obj-$(CONFIG_FSL_UCC_HDLC) += fsl_ucc_hdlc.o obj-$(CONFIG_SLIC_DS26522) += slic_ds26522.odrivers/net/wan/fsl_qmc_hdlc.c new file +49
-0@@ -0,0 +1,413 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Freescale QMC HDLC Device Driver +* +* Copyright 2023 CS GROUP France +* +* Author: Herve Codina <[email protected]> +*/ + +#include <linux/array_size.h> +#include <linux/bug.h> +#include <linux/cleanup.h> +#include <linux/dma-mapping.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/hdlc.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/types.h> + +#include <soc/fsl/qe/qmc.h> + +struct qmc_hdlc_desc { +struct net_device *netdev; +struct sk_buff *skb;/* NULL if the descriptor is not in use */ +dma_addr_t dma_addr; +size_t dma_size; +}; + +struct qmc_hdlc { +struct device *dev; +struct qmc_chan *qmc_chan; +struct net_device *netdev; +bool is_crc32; +spinlock_t tx_lock;/* Protect tx descriptors */ +struct qmc_hdlc_desc tx_descs[8 ]; +unsigned int tx_out; +struct qmc_hdlc_desc rx_descs[4 ]; +}; + +static struct qmc_hdlc *netdev_to_qmc_hdlc (struct net_device *netdev) +{ +return dev_to_hdlc (netdev)->priv; +} + +static int qmc_hdlc_recv_queue (struct qmc_hdlc *qmc_hdlc,struct qmc_hdlc_desc *desc,size_t size);
drivers/net/wan/fsl_qmc_hdlc.c line 59
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+ +#define QMC_HDLC_RX_ERROR_FLAGS \ + (QMC_RX_FLAG_HDLC_OVF | QMC_RX_FLAG_HDLC_UNA | \ + QMC_RX_FLAG_HDLC_CRC | QMC_RX_FLAG_HDLC_ABORT) + +static void qmc_hcld_recv_complete (void *context,size_t length,unsigned int flags) +{ +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);
Reverse xmas tree
Quoted 58 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +58
-0+int ret; + +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size,DMA_FROM_DEVICE ); + +if (flags &QMC_HDLC_RX_ERROR_FLAGS ) { + netdev->stats.rx_errors++; +if (flags &QMC_RX_FLAG_HDLC_OVF )/* Data overflow */ + netdev->stats.rx_over_errors++; +if (flags &QMC_RX_FLAG_HDLC_UNA )/* bits received not multiple of 8 */ + netdev->stats.rx_frame_errors++; +if (flags &QMC_RX_FLAG_HDLC_ABORT )/* Received an abort sequence */ + netdev->stats.rx_frame_errors++; +if (flags &QMC_RX_FLAG_HDLC_CRC )/* CRC error */ + netdev->stats.rx_crc_errors++; +kfree_skb (desc->skb); + }else { + netdev->stats.rx_packets++; + netdev->stats.rx_bytes += length; + +skb_put (desc->skb, length); + desc->skb->protocol =hdlc_type_trans (desc->skb, netdev); +netif_rx (desc->skb); + } + +/* Re-queue a transfer using the same descriptor */ + ret =qmc_hdlc_recv_queue (qmc_hdlc, desc, desc->dma_size); +if (ret) { +dev_err (qmc_hdlc->dev,"queue recv desc failed (%d)\n" , ret); + netdev->stats.rx_errors++; + } +} + +static int qmc_hdlc_recv_queue (struct qmc_hdlc *qmc_hdlc,struct qmc_hdlc_desc *desc,size_t size) +{ +int ret; + + desc->skb =dev_alloc_skb (size); +if (!desc->skb) +return -ENOMEM ; + + desc->dma_size = size; + desc->dma_addr =dma_map_single (qmc_hdlc->dev, desc->skb->data, + desc->dma_size,DMA_FROM_DEVICE ); + ret =dma_mapping_error (qmc_hdlc->dev, desc->dma_addr); +if (ret) + goto free_skb; + + ret =qmc_chan_read_submit (qmc_hdlc->qmc_chan, desc->dma_addr, desc->dma_size, + qmc_hcld_recv_complete, desc); +if (ret) + goto dma_unmap; + +return 0 ; + +dma_unmap: +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size,DMA_FROM_DEVICE ); +free_skb: +kfree_skb (desc->skb);
drivers/net/wan/fsl_qmc_hdlc.c line 127
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+ desc->skb =NULL ; +return ret; +} + +static void qmc_hdlc_xmit_complete (void *context) +{ +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct sk_buff *skb;
Reverse xmas tree
Quoted 63 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +63
-0+ + scoped_guard(spinlock_irqsave, &qmc_hdlc->tx_lock) { +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size,DMA_TO_DEVICE ); + skb = desc->skb; + desc->skb =NULL ;/* Release the descriptor */ +if (netif_queue_stopped (netdev)) +netif_wake_queue (netdev); + } + + netdev->stats.tx_packets++; + netdev->stats.tx_bytes += skb->len; + +dev_consume_skb_any (skb); +} + +static int qmc_hdlc_xmit_queue (struct qmc_hdlc *qmc_hdlc,struct qmc_hdlc_desc *desc) +{ +int ret; + + desc->dma_addr =dma_map_single (qmc_hdlc->dev, desc->skb->data, + desc->dma_size,DMA_TO_DEVICE ); + ret =dma_mapping_error (qmc_hdlc->dev, desc->dma_addr); +if (ret) { +dev_err (qmc_hdlc->dev,"failed to map skb\n" ); +return ret; + } + + ret =qmc_chan_write_submit (qmc_hdlc->qmc_chan, desc->dma_addr, desc->dma_size, + qmc_hdlc_xmit_complete, desc); +if (ret) { +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size,DMA_TO_DEVICE ); +dev_err (qmc_hdlc->dev,"qmc chan write returns %d\n" , ret); +return ret; + } + +return 0 ; +} + +static netdev_tx_t qmc_hdlc_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct qmc_hdlc_desc *desc; +int err; + +guard (spinlock_irqsave)(&qmc_hdlc->tx_lock); + + desc = &qmc_hdlc->tx_descs[qmc_hdlc->tx_out]; +if (WARN_ONCE (desc->skb,"No tx descriptors available\n" )) { +/* Should never happen. +* Previous xmit should have already stopped the queue. +*/ +netif_stop_queue (netdev); +return NETDEV_TX_BUSY ; + } + + desc->netdev = netdev; + desc->dma_size = skb->len; + desc->skb = skb; + err =qmc_hdlc_xmit_queue (qmc_hdlc, desc); +if (err) { + desc->skb =NULL ;/* Release the descriptor */ +if (err == -EBUSY ) { +netif_stop_queue (netdev);
drivers/net/wan/fsl_qmc_hdlc.c line 200
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+return NETDEV_TX_BUSY ; + } +dev_kfree_skb (skb); + netdev->stats.tx_dropped++; +return NETDEV_TX_OK ; + } + + qmc_hdlc->tx_out = (qmc_hdlc->tx_out +1 ) %ARRAY_SIZE (qmc_hdlc->tx_descs); + +if (qmc_hdlc->tx_descs[qmc_hdlc->tx_out].skb)
wont it race if tx completion and this function context run in different cpu ?
Quoted 45 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +45
-0+netif_stop_queue (netdev); + +return NETDEV_TX_OK ; +} + +static int qmc_hdlc_open (struct net_device *netdev) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct qmc_chan_param chan_param; +struct qmc_hdlc_desc *desc; +int ret; +int i; + + ret =hdlc_open (netdev); +if (ret) +return ret; + + chan_param.mode =QMC_HDLC ; +/* HDLC_MAX_MRU + 4 for the CRC +* HDLC_MAX_MRU + 4 + 8 for the CRC and some extraspace needed by the QMC +*/ + chan_param.hdlc.max_rx_buf_size =HDLC_MAX_MRU +4 +8 ; + chan_param.hdlc.max_rx_frame_size =HDLC_MAX_MRU +4 ; + chan_param.hdlc.is_crc32 = qmc_hdlc->is_crc32; + ret =qmc_chan_set_param (qmc_hdlc->qmc_chan, &chan_param); +if (ret) { +dev_err (qmc_hdlc->dev,"failed to set param (%d)\n" , ret); + goto hdlc_close; + } + +/* Queue as many recv descriptors as possible */ +for (i =0 ; i <ARRAY_SIZE (qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; + + desc->netdev = netdev; + ret =qmc_hdlc_recv_queue (qmc_hdlc, desc, chan_param.hdlc.max_rx_buf_size); +if (ret == -EBUSY && i !=0 ) +break ;/* We use all the QMC chan capability */ +if (ret) + goto free_desc; + } + + ret =qmc_chan_start (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +if (ret) { +dev_err (qmc_hdlc->dev,"qmc chan start failed (%d)\n" , ret);
drivers/net/wan/fsl_qmc_hdlc.c line 255
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+ goto free_desc; + } + +netif_start_queue (netdev); + +return 0 ; + +free_desc: +qmc_chan_reset (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +while (i--) {
Double free ? i'th descriptor skb is freed in qmc_hdlc_recv_queue() function's error handler itself. Should we be predecrement of i ?
Quoted 160 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +158
-1+ desc = &qmc_hdlc->rx_descs[i]; +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size, +DMA_FROM_DEVICE ); +kfree_skb (desc->skb); + desc->skb =NULL ; + } +hdlc_close: +hdlc_close (netdev); +return ret; +} + +static int qmc_hdlc_close (struct net_device *netdev) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct qmc_hdlc_desc *desc; +int i; + +qmc_chan_stop (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +qmc_chan_reset (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); + +netif_stop_queue (netdev); + +for (i =0 ; i <ARRAY_SIZE (qmc_hdlc->tx_descs); i++) { + desc = &qmc_hdlc->tx_descs[i]; +if (!desc->skb) +continue ; +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size, +DMA_TO_DEVICE ); +kfree_skb (desc->skb); + desc->skb =NULL ; + } + +for (i =0 ; i <ARRAY_SIZE (qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; +if (!desc->skb) +continue ; +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size, +DMA_FROM_DEVICE ); +kfree_skb (desc->skb); + desc->skb =NULL ; + } + +hdlc_close (netdev); +return 0 ; +} + +static int qmc_hdlc_attach (struct net_device *netdev,unsigned short encoding, +unsigned short parity) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); + +if (encoding !=ENCODING_NRZ ) +return -EINVAL ; + +switch (parity) { +case PARITY_CRC16_PR1_CCITT : + qmc_hdlc->is_crc32 = false; +break ; +case PARITY_CRC32_PR1_CCITT : + qmc_hdlc->is_crc32 = true; +break ; +default : +dev_err (qmc_hdlc->dev,"unsupported parity %u\n" , parity); +return -EINVAL ; + } + +return 0 ; +} + +static const struct net_device_ops qmc_hdlc_netdev_ops = { + .ndo_open = qmc_hdlc_open, + .ndo_stop = qmc_hdlc_close, + .ndo_start_xmit = hdlc_start_xmit, + .ndo_siocwandev = hdlc_ioctl, +}; + +static int qmc_hdlc_probe (struct platform_device *pdev) +{ +struct device *dev = &pdev->dev; +struct qmc_hdlc *qmc_hdlc; +struct qmc_chan_info info; +hdlc_device *hdlc; +int ret; + + qmc_hdlc =devm_kzalloc (dev,sizeof (*qmc_hdlc),GFP_KERNEL ); +if (!qmc_hdlc) +return -ENOMEM ; + + qmc_hdlc->dev = dev; +spin_lock_init (&qmc_hdlc->tx_lock); + + qmc_hdlc->qmc_chan =devm_qmc_chan_get_bychild (dev, dev->of_node); +if (IS_ERR (qmc_hdlc->qmc_chan)) +return dev_err_probe (dev,PTR_ERR (qmc_hdlc->qmc_chan), +"get QMC channel failed\n" ); + + ret =qmc_chan_get_info (qmc_hdlc->qmc_chan, &info); +if (ret) +return dev_err_probe (dev, ret,"get QMC channel info failed\n" ); + +if (info.mode !=QMC_HDLC ) +return dev_err_probe (dev, -EINVAL ,"QMC chan mode %d is not QMC_HDLC\n" , + info.mode); + + qmc_hdlc->netdev =alloc_hdlcdev (qmc_hdlc); +if (!qmc_hdlc->netdev) +return -ENOMEM ; + + hdlc =dev_to_hdlc (qmc_hdlc->netdev); + hdlc->attach = qmc_hdlc_attach; + hdlc->xmit = qmc_hdlc_xmit; +SET_NETDEV_DEV (qmc_hdlc->netdev, dev); + qmc_hdlc->netdev->tx_queue_len =ARRAY_SIZE (qmc_hdlc->tx_descs); + qmc_hdlc->netdev->netdev_ops = &qmc_hdlc_netdev_ops; + ret =register_hdlc_device (qmc_hdlc->netdev); +if (ret) { +dev_err_probe (dev, ret,"failed to register hdlc device\n" ); + goto free_netdev; + } + +platform_set_drvdata (pdev, qmc_hdlc); + +return 0 ; + +free_netdev: +free_netdev (qmc_hdlc->netdev); +return ret; +} + +static int qmc_hdlc_remove (struct platform_device *pdev) +{ +struct qmc_hdlc *qmc_hdlc =platform_get_drvdata (pdev); + +unregister_hdlc_device (qmc_hdlc->netdev); +free_netdev (qmc_hdlc->netdev); + +return 0 ; +} + +static const struct of_device_id qmc_hdlc_id_table[] = { + { .compatible ="fsl,qmc-hdlc" }, + {}/* sentinel */ +}; +MODULE_DEVICE_TABLE (of, qmc_hdlc_driver); + +static struct platform_driver qmc_hdlc_driver = { + .driver = { + .name ="fsl-qmc-hdlc" , + .of_match_table = qmc_hdlc_id_table, + }, + .probe = qmc_hdlc_probe, + .remove = qmc_hdlc_remove, +}; +module_platform_driver (qmc_hdlc_driver); + +MODULE_AUTHOR ("Herve Codina <[email protected]>" ); +MODULE_DESCRIPTION ("QMC HDLC driver" ); +MODULE_LICENSE ("GPL" ); --2.43.0
Herve Codina
maintainerRe: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Hi Ratheesh
On Wed, 6 Mar 2024 16:26:51 +0530
Ratheesh Kannoth <[email protected]> wrote:
...
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c line 59
Quoted 5 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +5
-0+static void qmc_hcld_recv_complete (void *context,size_t length,unsigned int flags) +{ +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);Reverse xmas tree
The reverse xmas tree order cannot be used here. qmc_hdlc depends on netdev, netdev depends on desc.
...
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c line 127
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +6
-0+static void qmc_hdlc_xmit_complete (void *context) +{ +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct sk_buff *skb;Reverse xmas tree
Ditto
Quoted 15 lines
Quoted 15 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +15
-0+ + scoped_guard(spinlock_irqsave, &qmc_hdlc->tx_lock) { +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size,DMA_TO_DEVICE ); + skb = desc->skb; + desc->skb =NULL ;/* Release the descriptor */ +if (netif_queue_stopped (netdev)) +netif_wake_queue (netdev); + } + + netdev->stats.tx_packets++; + netdev->stats.tx_bytes += skb->len; + +dev_consume_skb_any (skb); +} +
...
Quoted 29 lines
Quoted 29 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +29
-0+ +static netdev_tx_t qmc_hdlc_xmit (struct sk_buff *skb,struct net_device *netdev) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct qmc_hdlc_desc *desc; +int err; + +guard (spinlock_irqsave)(&qmc_hdlc->tx_lock); + + desc = &qmc_hdlc->tx_descs[qmc_hdlc->tx_out]; +if (WARN_ONCE (desc->skb,"No tx descriptors available\n" )) { +/* Should never happen. +* Previous xmit should have already stopped the queue. +*/ +netif_stop_queue (netdev); +return NETDEV_TX_BUSY ; + } + + desc->netdev = netdev; + desc->dma_size = skb->len; + desc->skb = skb; + err =qmc_hdlc_xmit_queue (qmc_hdlc, desc); +if (err) { + desc->skb =NULL ;/* Release the descriptor */ +if (err == -EBUSY ) { +netif_stop_queue (netdev); +return NETDEV_TX_BUSY ; + } +dev_kfree_skb (skb);
Quoted 8 lines
drivers/net/wan/fsl_qmc_hdlc.c line 200
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +7
-0+ netdev->stats.tx_dropped++; +return NETDEV_TX_OK ; + } + + qmc_hdlc->tx_out = (qmc_hdlc->tx_out +1 ) %ARRAY_SIZE (qmc_hdlc->tx_descs); + +if (qmc_hdlc->tx_descs[qmc_hdlc->tx_out].skb)wont it race if tx completion and this function context run in different cpu ?
We are protected by the qmc_hdlc->tx_lock spinlock.
guard() call in this function and scoped_guard() call in qmc_hdlc_xmit_complete().
What is the race you thought of ?
Quoted 6 lines
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +5
-0+netif_stop_queue (netdev); + +return NETDEV_TX_OK ; +} +
...
Quoted 19 lines
Quoted 19 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +19
-0+/* Queue as many recv descriptors as possible */ +for (i =0 ; i <ARRAY_SIZE (qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; + + desc->netdev = netdev; + ret =qmc_hdlc_recv_queue (qmc_hdlc, desc, chan_param.hdlc.max_rx_buf_size); +if (ret == -EBUSY && i !=0 ) +break ;/* We use all the QMC chan capability */ +if (ret) + goto free_desc; + } + + ret =qmc_chan_start (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +if (ret) { +dev_err (qmc_hdlc->dev,"qmc chan start failed (%d)\n" , ret); + goto free_desc; + } + +netif_start_queue (netdev);
Quoted 8 lines
drivers/net/wan/fsl_qmc_hdlc.c line 255
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +6
-0+ +return 0 ; + +free_desc: +qmc_chan_reset (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +while (i--) {Double free ? i'th descriptor skb is freed in
qmc_hdlc_recv_queue()function's error handler itself. Should we be predecrement of i ?
Suppose a failure on i = 5. The item 5 is already cleaned (done by qmc_hdlc_recv_queue() itself).
The 'while (i--)' set i to 4 and operations are performed with i = 4, 3, 2, 1 and 0.
Where is the double free ?
Do I miss something ?
Quoted 13 lines
drivers/net/wan/fsl_qmc_hdlc.c line 272
Quoted 13 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +12
-0+ desc = &qmc_hdlc->rx_descs[i]; +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size, +DMA_FROM_DEVICE ); +kfree_skb (desc->skb); + desc->skb =NULL ; + } +hdlc_close: +hdlc_close (netdev); +return ret; +} + +
Best regards,
Hervé
RE: [EXTERNAL] Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Quoted 13 lines
From: Herve Codina <[email protected]>
Sent: Wednesday, March 6, 2024 7:08 PM
To: Ratheesh Kannoth <[email protected]>
Cc: [email protected]; [email protected]
Subject: [EXTERNAL] Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLCQuoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c line 59
Quoted 5 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +5
-0+static void qmc_hcld_recv_complete (void *context,size_t length, +unsigned int flags) { +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);Reverse xmas tree
Quoted 3 lines
The reverse xmas tree order cannot be used here.
qmc_hdlcdepends on netdev, netdev depends on desc.
ACK. Usually I get comments to split declaration and assignment for my patches in upstream.
Quoted 10 lines
...
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c line 127
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +6
-0+static void qmc_hdlc_xmit_complete (void *context) +{ +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct sk_buff *skb;Reverse xmas tree
Ditto
Same as above.
Quoted 58 lines
Quoted 17 lines
drivers/net/wan/fsl_qmc_hdlc.c
Quoted 4 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +3
-0+ + scoped_guard(spinlock_irqsave, &qmc_hdlc->tx_lock) { + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc-
dma_size,DMA_TO_DEVICE);Quoted 12 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +12
-0+ skb = desc->skb; + desc->skb =NULL ;/* Release the descriptor */ +if (netif_queue_stopped (netdev)) +netif_wake_queue (netdev); + } + + netdev->stats.tx_packets++; + netdev->stats.tx_bytes += skb->len; + +dev_consume_skb_any (skb); +} +...
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ +static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device*netdev)
Quoted 33 lines
Quoted 22 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +22
-0+{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +struct qmc_hdlc_desc *desc; +int err; + +guard (spinlock_irqsave)(&qmc_hdlc->tx_lock); + + desc = &qmc_hdlc->tx_descs[qmc_hdlc->tx_out]; +if (WARN_ONCE (desc->skb,"No tx descriptors available\n" )) { +/* Should never happen. +* Previous xmit should have already stopped the queue. +*/ +netif_stop_queue (netdev); +return NETDEV_TX_BUSY ; + } + + desc->netdev = netdev; + desc->dma_size = skb->len; + desc->skb = skb; + err =qmc_hdlc_xmit_queue (qmc_hdlc, desc); +if (err) { + desc->skb =NULL ;/* Release the descriptor */ drivers/net/wan/fsl_qmc_hdlc.c
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+if (err == -EBUSY ) { +netif_stop_queue (netdev); +return NETDEV_TX_BUSY ; + } +dev_kfree_skb (skb); + netdev->stats.tx_dropped++; +return NETDEV_TX_OK ; + } + + qmc_hdlc->tx_out = (qmc_hdlc->tx_out + 1) % ARRAY_SIZE(qmc_hdlc-
tx_descs);Quoted 3 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + if (qmc_hdlc->tx_descs[qmc_hdlc->tx_out].skb)wont it race if tx completion and this function context run in different cpu ?
Quoted 6 lines
We are protected by the
qmc_hdlc->tx_lockspinlock.
guard()call in this function andscoped_guard()call inqmc_hdlc_xmit_complete().What is the race you thought of ?
ACK. Thanks for clarification.
Quoted 36 lines
Quoted 7 lines
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +5
-0+netif_stop_queue (netdev); + +return NETDEV_TX_OK ; +} +...
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c
Quoted 6 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +6
-0+/* Queue as many recv descriptors as possible */ +for (i =0 ; i <ARRAY_SIZE (qmc_hdlc->rx_descs); i++) { + desc = &qmc_hdlc->rx_descs[i]; + + desc->netdev = netdev; + ret = qmc_hdlc_recv_queue(qmc_hdlc, desc,chan_param.hdlc.max_rx_buf_size);
Quoted 12 lines
Quoted 12 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +12
-0+if (ret == -EBUSY && i !=0 ) +break ;/* We use all the QMC chan capability */ +if (ret) + goto free_desc; + } + + ret =qmc_chan_start (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +if (ret) { +dev_err (qmc_hdlc->dev,"qmc chan start failed (%d)\n" , ret); + goto free_desc; + } +Quoted 8 lines
drivers/net/wan/fsl_qmc_hdlc.c line 255
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +7
-0+netif_start_queue (netdev); + +return 0 ; + +free_desc: +qmc_chan_reset (qmc_hdlc->qmc_chan,QMC_CHAN_ALL ); +while (i--) {Double free ? i'th descriptor skb is freed in
qmc_hdlc_recv_queue()function's error handler itself.
Quoted 8 lines
Quoted 1 line
Should we be predecrement of i ?
Suppose a failure on i = 5. The item 5 is already cleaned (done by
qmc_hdlc_recv_queue()itself).
The 'while (i--)' set i to 4 and operations are performed with i = 4, 3, 2, 1 and 0.Where is the double free ?
Do I miss something ?
My bad. ACK.
Quoted 17 lines
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ desc = &qmc_hdlc->rx_descs[i]; + dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc-
dma_size,Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c line 272
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+ DMA_FROM_DEVICE); +kfree_skb (desc->skb); + desc->skb =NULL ; + } +hdlc_close: +hdlc_close (netdev); +return ret; +} + +Best regards,
Hervé
Jakub Kicinski
maintainerRe: [EXTERNAL] Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Quoted 10 lines · On Wed, 6 Mar 2024 16:01:48 +0000 Ratheesh Kannoth wrote:
Quoted 8 lines
Quoted 4 lines
drivers/net/wan/fsl_qmc_hdlc.c line 59
Quoted 3 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +3
-0+struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);Reverse xmas tree
The reverse xmas tree order cannot be used here.
qmc_hdlcdepends on netdev, netdev depends on desc.ACK. Usually I get comments to split declaration and assignment for my patches in upstream.
Yup, that's our general preference, to split the init out of the definition.
Herve Codina
maintainerRe: [EXTERNAL] Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Hi Jakub,
Quoted 6 lines · On Wed, 6 Mar 2024 08:22:30 -0800 Jakub Kicinski <[email protected]> wrote:
Quoted 5 lines · On Wed, 6 Mar 2024 16:01:48 +0000 Ratheesh Kannoth wrote:
Quoted 5 lines
Quoted 4 lines
drivers/net/wan/fsl_qmc_hdlc.c line 59
Quoted 3 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +3
-0+struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);Reverse xmas tree
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
The reverse xmas tree order cannot be used here.
qmc_hdlcdepends on netdev, netdev depends on desc.ACK. Usually I get comments to split declaration and assignment for my patches in upstream.
Yup, that's our general preference, to split the init out of the definition.
Does it mean that I need to update in a next iteration ?
Best regards,
Hervé
Jakub Kicinski
maintainerRe: [EXTERNAL] Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Quoted 7 lines · On Wed, 6 Mar 2024 18:46:11 +0100 Herve Codina wrote:
Quoted 5 lines
Quoted 2 lines
ACK. Usually I get comments to split declaration and assignment for my patches in upstream.
Yup, that's our general preference, to split the init out of the definition.
Does it mean that I need to update in a next iteration ?
If you'd be so kind.
Yury Norov
maintainerRe: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
In reply to Herve CodinaQuoted 118 lines · Herve Codina
The QMC HDLC driver provides support for HDLC using the QMC (QUICC Multichannel Controller) to transfer the HDLC data.
Signed-off-by Herve Codina <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Acked-by Jakub Kicinski <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- drivers/net/wan/Kconfig | 12 + drivers/net/wan/Makefile | 1 + drivers/net/wan/fsl_qmc_hdlc.c | 413 +++++++++++++++++++++++++++++++++ 3 files changed, 426 insertions(+) create mode 100644 drivers/net/wan/fsl_qmc_hdlc.cdrivers/net/wan/Kconfig +12
-0@@ -197,6 +197,18 @@ config FARSYNC To compile this driver as a module, choose M here: the module will be called farsync. +config FSL_QMC_HDLC + tristate "Freescale QMC HDLC support" + depends on HDLC + depends on CPM_QMC + help + HDLC support using the Freescale QUICC Multichannel Controller (QMC). + + To compile this driver as a module, choose M here: the + module will be called fsl_qmc_hdlc. + + If unsure, say N. + config FSL_UCC_HDLC tristate "Freescale QUICC Engine HDLC support" depends on HDLCdrivers/net/wan/Makefile +1
-0@@ -25,6 +25,7 @@ obj-$(CONFIG_WANXL) += wanxl.o obj-$(CONFIG_PCI200SYN) += pci200syn.o obj-$(CONFIG_PC300TOO) += pc300too.o obj-$(CONFIG_IXP4XX_HSS) += ixp4xx_hss.o +obj-$(CONFIG_FSL_QMC_HDLC) += fsl_qmc_hdlc.o obj-$(CONFIG_FSL_UCC_HDLC) += fsl_ucc_hdlc.o obj-$(CONFIG_SLIC_DS26522) += slic_ds26522.odrivers/net/wan/fsl_qmc_hdlc.c new file +63
-0@@ -0,0 +1,413 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Freescale QMC HDLC Device Driver +* +* Copyright 2023 CS GROUP France +* +* Author: Herve Codina <[email protected]> +*/ + +#include <linux/array_size.h> +#include <linux/bug.h> +#include <linux/cleanup.h> +#include <linux/dma-mapping.h> +#include <linux/device.h> +#include <linux/err.h> +#include <linux/hdlc.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/spinlock.h> +#include <linux/types.h> + +#include <soc/fsl/qe/qmc.h> + +struct qmc_hdlc_desc { +struct net_device *netdev; +struct sk_buff *skb;/* NULL if the descriptor is not in use */ +dma_addr_t dma_addr; +size_t dma_size; +}; + +struct qmc_hdlc { +struct device *dev; +struct qmc_chan *qmc_chan; +struct net_device *netdev; +bool is_crc32; +spinlock_t tx_lock;/* Protect tx descriptors */ +struct qmc_hdlc_desc tx_descs[8 ]; +unsigned int tx_out; +struct qmc_hdlc_desc rx_descs[4 ]; +}; + +static struct qmc_hdlc *netdev_to_qmc_hdlc (struct net_device *netdev) +{ +return dev_to_hdlc (netdev)->priv; +} + +static int qmc_hdlc_recv_queue (struct qmc_hdlc *qmc_hdlc,struct qmc_hdlc_desc *desc,size_t size); + +#define QMC_HDLC_RX_ERROR_FLAGS \ + (QMC_RX_FLAG_HDLC_OVF | QMC_RX_FLAG_HDLC_UNA | \ + QMC_RX_FLAG_HDLC_CRC | QMC_RX_FLAG_HDLC_ABORT) + +static void qmc_hcld_recv_complete (void *context,size_t length,unsigned int flags) +{ +struct qmc_hdlc_desc *desc = context; +struct net_device *netdev = desc->netdev; +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +int ret; + +dma_unmap_single (qmc_hdlc->dev, desc->dma_addr, desc->dma_size,DMA_FROM_DEVICE ); +
drivers/net/wan/fsl_qmc_hdlc.c line 73
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +10
-0+if (flags &QMC_HDLC_RX_ERROR_FLAGS ) { + netdev->stats.rx_errors++; +if (flags &QMC_RX_FLAG_HDLC_OVF )/* Data overflow */ + netdev->stats.rx_over_errors++; +if (flags &QMC_RX_FLAG_HDLC_UNA )/* bits received not multiple of 8 */ + netdev->stats.rx_frame_errors++; +if (flags &QMC_RX_FLAG_HDLC_ABORT )/* Received an abort sequence */ + netdev->stats.rx_frame_errors++; +if (flags &QMC_RX_FLAG_HDLC_CRC )/* CRC error */ + netdev->stats.rx_crc_errors++;
It's minor, but you can avoid conditionals doing something like:
netdev->stats.rx_over_errors += !!(flags & QMC_RX_FLAG_HDLC_OVF);
Thanks,
Yury
Quoted 17 lines
drivers/net/wan/fsl_qmc_hdlc.c new file +17
-0+kfree_skb (desc->skb); + }else { + netdev->stats.rx_packets++; + netdev->stats.rx_bytes += length; + +skb_put (desc->skb, length); + desc->skb->protocol =hdlc_type_trans (desc->skb, netdev); +netif_rx (desc->skb); + } + +/* Re-queue a transfer using the same descriptor */ + ret =qmc_hdlc_recv_queue (qmc_hdlc, desc, desc->dma_size); +if (ret) { +dev_err (qmc_hdlc->dev,"queue recv desc failed (%d)\n" , ret); + netdev->stats.rx_errors++; + } +}
Re: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:17AM +0100, Herve Codina wrote:
...
Quoted 3 lines
It's minor, but you can avoid conditionals doing something like:
netdev->stats.rx_over_errors += !!(flags & QMC_RX_FLAG_HDLC_OVF);
This is harder to read. And IIUC net subsystem dislikes the proposed one (I tried to submit a patch to clarify some boolean types vs. integer ones
and it was rejected because of the reason I have mentioned).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jakub Kicinski
maintainerRe: [PATCH v6 1/5] net: wan: Add support for QMC HDLC
Quoted 5 lines · On Wed, 6 Mar 2024 15:38:10 +0200 Andy Shevchenko wrote:
Quoted 3 lines
It's minor, but you can avoid conditionals doing something like:
netdev->stats.rx_over_errors += !!(flags & QMC_RX_FLAG_HDLC_OVF);This is harder to read.
+1
Herve Codina
maintainerPATCH v6 2/5 MAINTAINERS: Add the Freescale QMC HDLC driver entry
In reply to Herve CodinaAfter contributing the driver, add myself as the maintainer for the Freescale QMC HDLC driver.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -8584,6 +8584,13 @@ F: Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,cpm1-scc-qmc.yaml F: drivers/soc/fsl/qe/qmc.c F: include/soc/fsl/qe/qmc.h +FREESCALE QUICC ENGINE QMC HDLC DRIVER +M: Herve Codina <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: drivers/net/wan/fsl_qmc_hdlc.c + FREESCALE QUICC ENGINE TSA DRIVER M: Herve Codina <[email protected]> L: [email protected]
Signature · 1 line
2.43.0
Herve Codina
maintainerPATCH v6 3/5 lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
In reply to Herve CodinaFrom: Andy Shevchenko <[email protected]>
These helpers scatters or gathers a bitmap with the help of the mask position bits parameter.
bitmap_scatter() does the following:
src: 0000000001011010
||||||
+------+|||||
| +----+||||
| |+----+|||
| || +-+||
| || | ||
mask: ...v..vv...v..vv
...0..11...0..10dst: 0000001100000010
and bitmap_gather() performs this one:
mask: ...v..vv...v..vv
src: 0000001100000010
^ ^^ ^ 0
| || | 10
| || > 010
| |+--> 1010
| +--> 11010
+----> 011010
dst: 0000000000011010bitmap_gather() can the seen as the reverse bitmap_scatter() operation.
--- include/linux/bitmap.h | 101 +++++++++++++++++++++++++++++++++++++++++ lib/test_bitmap.c | 42 +++++++++++++++++ 2 files changed, 143 insertions(+)
include/linux/bitmap.h +101 -0
@@ -62,6 +62,8 @@ struct device;* bitmap_shift_left(dst, src, n, nbits) *dst = *src << n * bitmap_cut(dst, src, first, n, nbits) Cut n bits from first, copy rest * bitmap_replace(dst, old, new, mask, nbits) *dst = (*old & ~(*mask)) | (*new & *mask) +* bitmap_scatter(dst, src, mask, nbits) *dst = map(dense, sparse)(src) +* bitmap_gather(dst, src, mask, nbits) *dst = map(sparse, dense)(src) * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap
@@ -487,6 +489,105 @@ static inline void bitmap_replace(unsigned long *dst,__bitmap_replace (dst, old, new, mask, nbits); } +/** +* bitmap_scatter - Scatter a bitmap according to the given mask +* @dst: scattered bitmap +* @src: gathered bitmap +* @mask: mask representing bits to assign to in the scattered bitmap +* @nbits: number of bits in each of these bitmaps +* +* Scatters bitmap with sequential bits according to the given @mask. +* +* Example: +* If @src bitmap = 0x005a, with @mask = 0x1313, @dst will be 0x0302. +* +* Or in binary form +* @src @mask @dst +* 0000000001011010 0001001100010011 0000001100000010 +* +* (Bits 0, 1, 2, 3, 4, 5 are copied to the bits 0, 1, 4, 8, 9, 12) +* +* A more 'visual' description of the operation: +* src: 0000000001011010 +* |||||| +* +------+||||| +* | +----+|||| +* | |+----+||| +* | || +-+|| +* | || | || +* mask: ...v..vv...v..vv +* ...0..11...0..10 +* dst: 0000001100000010 +* +* A relationship exists between bitmap_scatter() and bitmap_gather(). +* bitmap_gather() can be seen as the 'reverse' bitmap_scatter() operation. +* See bitmap_scatter() for details related to this relationship. +*/ +static inline void bitmap_scatter (unsigned long *dst,const unsigned long *src, +const unsigned long *mask,unsigned int nbits) +{ +unsigned int n =0 ; +unsigned int bit; + +bitmap_zero (dst, nbits); + +for_each_set_bit (bit, mask, nbits) +__assign_bit (bit, dst,test_bit (n++, src)); +} + +/** +* bitmap_gather - Gather a bitmap according to given mask +* @dst: gathered bitmap +* @src: scattered bitmap +* @mask: mask representing bits to extract from in the scattered bitmap +* @nbits: number of bits in each of these bitmaps +* +* Gathers bitmap with sparse bits according to the given @mask. +* +* Example: +* If @src bitmap = 0x0302, with @mask = 0x1313, @dst will be 0x001a. +* +* Or in binary form +* @src @mask @dst +* 0000001100000010 0001001100010011 0000000000011010 +* +* (Bits 0, 1, 4, 8, 9, 12 are copied to the bits 0, 1, 2, 3, 4, 5) +* +* A more 'visual' description of the operation: +* mask: ...v..vv...v..vv +* src: 0000001100000010 +* ^ ^^ ^ 0 +* | || | 10 +* | || > 010 +* | |+--> 1010 +* | +--> 11010 +* +----> 011010 +* dst: 0000000000011010 +* +* A relationship exists between bitmap_gather() and bitmap_scatter(). See +* bitmap_scatter() for the bitmap scatter detailed operations. +* Suppose scattered computed using bitmap_scatter(scattered, src, mask, n). +* The operation bitmap_gather(result, scattered, mask, n) leads to a result +* equal or equivalent to src. +* +* The result can be 'equivalent' because bitmap_scatter() and bitmap_gather() +* are not bijective. +* The result and src values are equivalent in that sense that a call to +* bitmap_scatter(res, src, mask, n) and a call to +* bitmap_scatter(res, result, mask, n) will lead to the same res value. +*/ +static inline void bitmap_gather (unsigned long *dst,const unsigned long *src, +const unsigned long *mask,unsigned int nbits) +{ +unsigned int n =0 ; +unsigned int bit; + +bitmap_zero (dst, nbits); + +for_each_set_bit (bit, mask, nbits) +__assign_bit (n++, dst,test_bit (bit, src)); +} +static inline void bitmap_next_set_region (unsigned long *bitmap,unsigned int *rs,unsigned int *re,unsigned int end)
lib/test_bitmap.c +42 -0
54 lines not on this page · raw message
Signature · 1 line
2.43.0
Yury Norov
maintainerRe: [PATCH v6 3/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
Quoted 28 lines · Herve Codina
From: Andy Shevchenko <[email protected]>
These helpers scatters or gathers a bitmap with the help of the mask position bits parameter.
bitmap_scatter()does the following:
src: 0000000001011010|||||| +------+||||| | +----+|||| | |+----+||| | || +-+|| | || | || mask: ...v..vv...v..vv ...0..11...0..10dst: 0000001100000010
and
bitmap_gather()performs this one:mask: ...v..vv...v..vv src: 0000001100000010 ^ ^^ ^ 0 | || | 10 | || > 010 | |+--> 1010 | +--> 11010 +----> 011010 dst: 0000000000011010
Quoted 6 lines
bitmap_gather()can the seen as the reversebitmap_scatter()operation.Signed-off-by Andy Shevchenko <[email protected]>Co-developed-by Herve Codina <[email protected]>Signed-off-by Herve Codina <[email protected]>
Would you like to move this with the rest of the series? If so please pull my Sof-by, otherwise I can move it with bitmap-for-next.
Quoted 186 lines
--- include/linux/bitmap.h | 101 +++++++++++++++++++++++++++++++++++++++++ lib/test_bitmap.c | 42 +++++++++++++++++ 2 files changed, 143 insertions(+)include/linux/bitmap.h +101
-0@@ -62,6 +62,8 @@ struct device;* bitmap_shift_left(dst, src, n, nbits) *dst = *src << n * bitmap_cut(dst, src, first, n, nbits) Cut n bits from first, copy rest * bitmap_replace(dst, old, new, mask, nbits) *dst = (*old & ~(*mask)) | (*new & *mask) +* bitmap_scatter(dst, src, mask, nbits) *dst = map(dense, sparse)(src) +* bitmap_gather(dst, src, mask, nbits) *dst = map(sparse, dense)(src) * bitmap_remap(dst, src, old, new, nbits) *dst = map(old, new)(src) * bitmap_bitremap(oldbit, old, new, nbits) newbit = map(old, new)(oldbit) * bitmap_onto(dst, orig, relmap, nbits) *dst = orig relative to relmap @@ -487,6 +489,105 @@ static inline void bitmap_replace(unsigned long *dst,__bitmap_replace (dst, old, new, mask, nbits); } +/** +* bitmap_scatter - Scatter a bitmap according to the given mask +* @dst: scattered bitmap +* @src: gathered bitmap +* @mask: mask representing bits to assign to in the scattered bitmap +* @nbits: number of bits in each of these bitmaps +* +* Scatters bitmap with sequential bits according to the given @mask. +* +* Example: +* If @src bitmap = 0x005a, with @mask = 0x1313, @dst will be 0x0302. +* +* Or in binary form +* @src @mask @dst +* 0000000001011010 0001001100010011 0000001100000010 +* +* (Bits 0, 1, 2, 3, 4, 5 are copied to the bits 0, 1, 4, 8, 9, 12) +* +* A more 'visual' description of the operation: +* src: 0000000001011010 +* |||||| +* +------+||||| +* | +----+|||| +* | |+----+||| +* | || +-+|| +* | || | || +* mask: ...v..vv...v..vv +* ...0..11...0..10 +* dst: 0000001100000010 +* +* A relationship exists between bitmap_scatter() and bitmap_gather(). +* bitmap_gather() can be seen as the 'reverse' bitmap_scatter() operation. +* See bitmap_scatter() for details related to this relationship. +*/ +static inline void bitmap_scatter (unsigned long *dst,const unsigned long *src, +const unsigned long *mask,unsigned int nbits) +{ +unsigned int n =0 ; +unsigned int bit; + +bitmap_zero (dst, nbits); + +for_each_set_bit (bit, mask, nbits) +__assign_bit (bit, dst,test_bit (n++, src)); +} + +/** +* bitmap_gather - Gather a bitmap according to given mask +* @dst: gathered bitmap +* @src: scattered bitmap +* @mask: mask representing bits to extract from in the scattered bitmap +* @nbits: number of bits in each of these bitmaps +* +* Gathers bitmap with sparse bits according to the given @mask. +* +* Example: +* If @src bitmap = 0x0302, with @mask = 0x1313, @dst will be 0x001a. +* +* Or in binary form +* @src @mask @dst +* 0000001100000010 0001001100010011 0000000000011010 +* +* (Bits 0, 1, 4, 8, 9, 12 are copied to the bits 0, 1, 2, 3, 4, 5) +* +* A more 'visual' description of the operation: +* mask: ...v..vv...v..vv +* src: 0000001100000010 +* ^ ^^ ^ 0 +* | || | 10 +* | || > 010 +* | |+--> 1010 +* | +--> 11010 +* +----> 011010 +* dst: 0000000000011010 +* +* A relationship exists between bitmap_gather() and bitmap_scatter(). See +* bitmap_scatter() for the bitmap scatter detailed operations. +* Suppose scattered computed using bitmap_scatter(scattered, src, mask, n). +* The operation bitmap_gather(result, scattered, mask, n) leads to a result +* equal or equivalent to src. +* +* The result can be 'equivalent' because bitmap_scatter() and bitmap_gather() +* are not bijective. +* The result and src values are equivalent in that sense that a call to +* bitmap_scatter(res, src, mask, n) and a call to +* bitmap_scatter(res, result, mask, n) will lead to the same res value. +*/ +static inline void bitmap_gather (unsigned long *dst,const unsigned long *src, +const unsigned long *mask,unsigned int nbits) +{ +unsigned int n =0 ; +unsigned int bit; + +bitmap_zero (dst, nbits); + +for_each_set_bit (bit, mask, nbits) +__assign_bit (n++, dst,test_bit (bit, src)); +} +static inline void bitmap_next_set_region (unsigned long *bitmap,unsigned int *rs,unsigned int *re,unsigned int end)lib/test_bitmap.c +42
-0@@ -380,6 +380,47 @@ static void __init test_replace(void)expect_eq_bitmap (bmap, exp3_1_0, nbits); } +static const unsigned long sg_mask[]__initconst = { +BITMAP_FROM_U64 (0x000000000000035aULL ), +}; + +static const unsigned long sg_src[]__initconst = { +BITMAP_FROM_U64 (0x0000000000000667ULL ), +}; + +static const unsigned long sg_gather_exp[]__initconst = { +BITMAP_FROM_U64 (0x0000000000000029ULL ), +}; + +static const unsigned long sg_scatter_exp[]__initconst = { +BITMAP_FROM_U64 (0x000000000000021aULL ), +}; + +static void __init test_bitmap_sg (void ) +{ +unsigned int nbits =64 ; +DECLARE_BITMAP (bmap_gather,100 ); +DECLARE_BITMAP (bmap_scatter,100 ); +DECLARE_BITMAP (bmap_tmp,100 ); +DECLARE_BITMAP (bmap_res,100 ); + +/* Simple gather call */ +bitmap_zero (bmap_gather,100 ); +bitmap_gather (bmap_gather, sg_src, sg_mask, nbits); +expect_eq_bitmap (sg_gather_exp, bmap_gather, nbits); + +/* Simple scatter call */ +bitmap_zero (bmap_scatter,100 ); +bitmap_scatter (bmap_scatter, sg_src, sg_mask, nbits); +expect_eq_bitmap (sg_scatter_exp, bmap_scatter, nbits); + +/* Scatter/gather relationship */ +bitmap_zero (bmap_tmp,100 ); +bitmap_gather (bmap_tmp, bmap_scatter, sg_mask, nbits); +bitmap_scatter (bmap_res, bmap_tmp, sg_mask, nbits); +expect_eq_bitmap (bmap_scatter, bmap_res, nbits); +} +#define PARSE_TIME 0x1#define NO_LEN 0x2@@ -1252,6 +1293,7 @@ static void __init selftest(void)test_copy ();test_bitmap_region ();test_replace (); +test_bitmap_sg ();test_bitmap_arr32 ();test_bitmap_arr64 ();test_bitmap_parse ();Signature · 1 line
2.43.0
Re: [PATCH v6 3/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:19AM +0100, Herve Codina wrote:
...
Quoted 1 line
Signed-off-by Yury Norov <[email protected]>
Why? Shouldn't be Acked-by?
Quoted 2 lines
Would you like to move this with the rest of the series? If so please pull my Sof-by, otherwise I can move it with bitmap-for-next.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Herve Codina
maintainerRe: [PATCH v6 3/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
Hi Yury,
Quoted 12 lines · On Wed, 6 Mar 2024 15:39:06 +0200 Andy Shevchenko…
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:19AM +0100, Herve Codina wrote:
...
Quoted 1 line
Signed-off-by Yury Norov <[email protected]>Why? Shouldn't be Acked-by?
Quoted 2 lines
Would you like to move this with the rest of the series? If so please pull my Sof-by, otherwise I can move it with bitmap-for-next.
A new iteration of the series is planned. Yury, may I add your Acked-by in the next iteration ?
Best regards,
Hervé
Yury Norov
maintainerRe: [PATCH v6 3/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers
Quoted 18 lines · Herve Codina
Hi Yury,
Quoted 12 lines · On Wed, 6 Mar 2024 15:39:06 +0200 Andy Shevchenko…
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:19AM +0100, Herve Codina wrote:
...
Quoted 1 line
Signed-off-by Yury Norov <[email protected]>Why? Shouldn't be Acked-by?
Quoted 2 lines
Would you like to move this with the rest of the series? If so please pull my Sof-by, otherwise I can move it with bitmap-for-next.
Quoted 6 lines
A new iteration of the series is planned. Yury, may I add your Acked-by in the next iteration ?
Best regards,
Hervé
Please scratch my sign-off and add ack.
Quoted 1 line
Herve Codina
maintainerPATCH v6 4/5 net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
In reply to Herve CodinaQMC channels support runtime timeslots changes but nothing is done at the QMC HDLC driver to handle these changes.
Use existing IFACE ioctl in order to configure the timeslots to use.
--- drivers/net/wan/fsl_qmc_hdlc.c | 151 ++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-)
drivers/net/wan/fsl_qmc_hdlc.c +150 -1
@@ -10,6 +10,7 @@#include <linux/array_size.h> #include <linux/bug.h> #include <linux/cleanup.h> +#include <linux/bitmap.h> #include <linux/dma-mapping.h> #include <linux/device.h> #include <linux/err.h>
@@ -39,6 +40,7 @@ struct qmc_hdlc {struct qmc_hdlc_desc tx_descs[8 ];unsigned int tx_out;struct qmc_hdlc_desc rx_descs[4 ]; +u32 slot_map; };static struct qmc_hdlc *netdev_to_qmc_hdlc (struct net_device *netdev)
@@ -203,6 +205,144 @@ static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev)return NETDEV_TX_OK ; } +static int qmc_hdlc_xlate_slot_map (struct qmc_hdlc *qmc_hdlc, +u32 slot_map,struct qmc_chan_ts_info *ts_info) +{ +DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 ); + +/* Tx and Rx available masks must be identical */ +if (ts_info->rx_ts_mask_avail != ts_info->tx_ts_mask_avail) { +dev_err (qmc_hdlc->dev,"tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n" , + ts_info->rx_ts_mask_avail, ts_info->tx_ts_mask_avail); +return -EINVAL ; + } + +bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (map, slot_map); +bitmap_scatter (ts_mask, map, ts_mask_avail,64 ); + +if (bitmap_weight (ts_mask,64 ) !=bitmap_weight (map,64 )) { +dev_err (qmc_hdlc->dev,"Cannot translate timeslots %64pb -> (%64pb, %64pb)\n" , + map, ts_mask_avail, ts_mask); +return -EINVAL ; + } + +bitmap_to_arr64 (&ts_info->tx_ts_mask, ts_mask,64 ); + ts_info->rx_ts_mask = ts_info->tx_ts_mask; +return 0 ; +} + +static int qmc_hdlc_xlate_ts_info (struct qmc_hdlc *qmc_hdlc, +const struct qmc_chan_ts_info *ts_info,u32 *slot_map) +{ +DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 ); +u32 array32[2 ]; + +/* Tx and Rx masks and available masks must be identical */ +if (ts_info->rx_ts_mask_avail != ts_info->tx_ts_mask_avail) { +dev_err (qmc_hdlc->dev,"tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n" , + ts_info->rx_ts_mask_avail, ts_info->tx_ts_mask_avail); +return -EINVAL ; + } +if (ts_info->rx_ts_mask != ts_info->tx_ts_mask) { +dev_err (qmc_hdlc->dev,"tx and rx timeslots mismatch (0x%llx, 0x%llx)\n" , + ts_info->rx_ts_mask, ts_info->tx_ts_mask); +return -EINVAL ; + } + +bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (ts_mask, ts_info->rx_ts_mask); +bitmap_gather (map, ts_mask, ts_mask_avail,64 ); + +if (bitmap_weight (ts_mask,64 ) !=bitmap_weight (map,64 )) { +dev_err (qmc_hdlc->dev,"Cannot translate timeslots (%64pb, %64pb) -> %64pb\n" , + ts_mask_avail, ts_mask, map); +return -EINVAL ; + } + +bitmap_to_arr32 (array32, map,64 ); +if (array32[1 ]) { +dev_err (qmc_hdlc->dev,"Slot map out of 32bit (%64pb, %64pb) -> %64pb\n" , + ts_mask_avail, ts_mask, map); +return -EINVAL ; + } + + *slot_map = array32[0 ]; +return 0 ; +} + +static int qmc_hdlc_set_iface (struct qmc_hdlc *qmc_hdlc,int if_iface,const te1_settings *te1) +{ +struct qmc_chan_ts_info ts_info; +int ret; + + ret =qmc_chan_get_ts_info (qmc_hdlc->qmc_chan, &ts_info); +if (ret) { +dev_err (qmc_hdlc->dev,"get QMC channel ts info failed %d\n" , ret); +return ret; + } + ret =qmc_hdlc_xlate_slot_map (qmc_hdlc, te1->slot_map, &ts_info); +if (ret) +return ret; + + ret =qmc_chan_set_ts_info (qmc_hdlc->qmc_chan, &ts_info); +if (ret) { +dev_err (qmc_hdlc->dev,"set QMC channel ts info failed %d\n" , ret); +return ret; + } + + qmc_hdlc->slot_map = te1->slot_map; + +return 0 ; +} + +static int qmc_hdlc_ioctl (struct net_device *netdev,struct if_settings *ifs) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +te1_settings te1; + +switch (ifs->type) { +case IF_GET_IFACE : + ifs->type =IF_IFACE_E1 ; +if (ifs->size <sizeof (te1)) { +if (!ifs->size) +return 0 ;/* only type requested */ + + ifs->size =sizeof (te1);/* data size wanted */ +return -ENOBUFS ; + } + +memset (&te1,0 ,sizeof (te1)); + +/* Update slot_map */ + te1.slot_map = qmc_hdlc->slot_map; + +if (copy_to_user (ifs->ifs_ifsu.te1, &te1,sizeof (te1))) +return -EFAULT ; +return 0 ; + +case IF_IFACE_E1 : +case IF_IFACE_T1 : +if (!capable (CAP_NET_ADMIN )) +return -EPERM ; + +if (netdev->flags &IFF_UP ) +return -EBUSY ; + +if (copy_from_user (&te1, ifs->ifs_ifsu.te1,sizeof (te1))) +return -EFAULT ; + +return qmc_hdlc_set_iface (qmc_hdlc, ifs->type, &te1); + +default : +return hdlc_ioctl (netdev, ifs); + } +} +static int qmc_hdlc_open (struct net_device *netdev) {struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);
@@ -326,12 +466,13 @@ static const struct net_device_ops qmc_hdlc_netdev_ops = { .ndo_open = qmc_hdlc_open, .ndo_stop = qmc_hdlc_close, .ndo_start_xmit = hdlc_start_xmit, - .ndo_siocwandev = hdlc_ioctl, + .ndo_siocwandev = qmc_hdlc_ioctl, };static int qmc_hdlc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct qmc_chan_ts_info ts_info;struct qmc_hdlc *qmc_hdlc;struct qmc_chan_info info;hdlc_device *hdlc;
@@ -357,6 +498,14 @@ static int qmc_hdlc_probe(struct platform_device *pdev)return dev_err_probe (dev, -EINVAL ,"QMC chan mode %d is not QMC_HDLC\n" , info.mode); + ret =qmc_chan_get_ts_info (qmc_hdlc->qmc_chan, &ts_info); +if (ret) +return dev_err_probe (dev, ret,"get QMC channel ts info failed\n" ); + + ret =qmc_hdlc_xlate_ts_info (qmc_hdlc, &ts_info, &qmc_hdlc->slot_map); +if (ret) +return ret; + qmc_hdlc->netdev =alloc_hdlcdev (qmc_hdlc);if (!qmc_hdlc->netdev)return -ENOMEM ;
Signature · 1 line
2.43.0
Yury Norov
maintainerRe: [PATCH v6 4/5] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
Quoted 44 lines · Herve Codina
QMC channels support runtime timeslots changes but nothing is done at the QMC HDLC driver to handle these changes.
Use existing IFACE ioctl in order to configure the timeslots to use.
Signed-off-by Herve Codina <[email protected]>Reviewed-by Christophe Leroy <[email protected]>Acked-by Jakub Kicinski <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>--- drivers/net/wan/fsl_qmc_hdlc.c | 151 ++++++++++++++++++++++++++++++++- 1 file changed, 150 insertions(+), 1 deletion(-)drivers/net/wan/fsl_qmc_hdlc.c +9
-0@@ -10,6 +10,7 @@#include <linux/array_size.h> #include <linux/bug.h> #include <linux/cleanup.h> +#include <linux/bitmap.h> #include <linux/dma-mapping.h> #include <linux/device.h> #include <linux/err.h> @@ -39,6 +40,7 @@ struct qmc_hdlc {struct qmc_hdlc_desc tx_descs[8 ];unsigned int tx_out;struct qmc_hdlc_desc rx_descs[4 ]; +u32 slot_map; };static struct qmc_hdlc *netdev_to_qmc_hdlc (struct net_device *netdev)@@ -203,6 +205,144 @@ static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev)return NETDEV_TX_OK ; } +static int qmc_hdlc_xlate_slot_map (struct qmc_hdlc *qmc_hdlc, +u32 slot_map,struct qmc_chan_ts_info *ts_info) +{ +DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 ); +
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 224
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c +10
-0+/* Tx and Rx available masks must be identical */ +if (ts_info->rx_ts_mask_avail != ts_info->tx_ts_mask_avail) { +dev_err (qmc_hdlc->dev,"tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n" , + ts_info->rx_ts_mask_avail, ts_info->tx_ts_mask_avail); +return -EINVAL ; + } + +bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (map, slot_map); +bitmap_scatter (ts_mask, map, ts_mask_avail,64 );
We've got a BITMAP_FROM_U64() for this:
DECLARE_BITMAP(ts_mask_avail, 64) = { BITMAP_FROM_U64(ts_info->rx_ts_mask_avail) };
DECLARE_BITMAP(map, 64) = { BITMAP_FROM_U64(slot_map) };Quoted 9 lines
drivers/net/wan/fsl_qmc_hdlc.c +9
-0+ +if (bitmap_weight (ts_mask,64 ) !=bitmap_weight (map,64 )) { +dev_err (qmc_hdlc->dev,"Cannot translate timeslots %64pb -> (%64pb, %64pb)\n" , + map, ts_mask_avail, ts_mask); +return -EINVAL ; + } + +bitmap_to_arr64 (&ts_info->tx_ts_mask, ts_mask,64 ); + ts_info->rx_ts_mask = ts_info->tx_ts_mask;
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 243
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c +10
-0+return 0 ; +} + +static int qmc_hdlc_xlate_ts_info (struct qmc_hdlc *qmc_hdlc, +const struct qmc_chan_ts_info *ts_info,u32 *slot_map) +{ +DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 ); +u32 array32[2 ];
NIT. Bad name. I'd suggest slot_array, or something.
Quoted 4 lines
drivers/net/wan/fsl_qmc_hdlc.c +4
-0+/* Tx and Rx masks and available masks must be identical */ +if (ts_info->rx_ts_mask_avail != ts_info->tx_ts_mask_avail) { +dev_err (qmc_hdlc->dev,"tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n" , + ts_info->rx_ts_mask_avail, ts_info->tx_ts_mask_avail);
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 258
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c +10
-0+return -EINVAL ; + } +if (ts_info->rx_ts_mask != ts_info->tx_ts_mask) { +dev_err (qmc_hdlc->dev,"tx and rx timeslots mismatch (0x%llx, 0x%llx)\n" , + ts_info->rx_ts_mask, ts_info->tx_ts_mask); +return -EINVAL ; + } + +bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (ts_mask, ts_info->rx_ts_mask);
Same as above, can you try using BITMAP_FROM_U64()?
Thanks,
Yury
Quoted 122 lines
drivers/net/wan/fsl_qmc_hdlc.c +97
-1+bitmap_gather (map, ts_mask, ts_mask_avail,64 ); + +if (bitmap_weight (ts_mask,64 ) !=bitmap_weight (map,64 )) { +dev_err (qmc_hdlc->dev,"Cannot translate timeslots (%64pb, %64pb) -> %64pb\n" , + ts_mask_avail, ts_mask, map); +return -EINVAL ; + } + +bitmap_to_arr32 (array32, map,64 ); +if (array32[1 ]) { +dev_err (qmc_hdlc->dev,"Slot map out of 32bit (%64pb, %64pb) -> %64pb\n" , + ts_mask_avail, ts_mask, map); +return -EINVAL ; + } + + *slot_map = array32[0 ]; +return 0 ; +} + +static int qmc_hdlc_set_iface (struct qmc_hdlc *qmc_hdlc,int if_iface,const te1_settings *te1) +{ +struct qmc_chan_ts_info ts_info; +int ret; + + ret =qmc_chan_get_ts_info (qmc_hdlc->qmc_chan, &ts_info); +if (ret) { +dev_err (qmc_hdlc->dev,"get QMC channel ts info failed %d\n" , ret); +return ret; + } + ret =qmc_hdlc_xlate_slot_map (qmc_hdlc, te1->slot_map, &ts_info); +if (ret) +return ret; + + ret =qmc_chan_set_ts_info (qmc_hdlc->qmc_chan, &ts_info); +if (ret) { +dev_err (qmc_hdlc->dev,"set QMC channel ts info failed %d\n" , ret); +return ret; + } + + qmc_hdlc->slot_map = te1->slot_map; + +return 0 ; +} + +static int qmc_hdlc_ioctl (struct net_device *netdev,struct if_settings *ifs) +{ +struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev); +te1_settings te1; + +switch (ifs->type) { +case IF_GET_IFACE : + ifs->type =IF_IFACE_E1 ; +if (ifs->size <sizeof (te1)) { +if (!ifs->size) +return 0 ;/* only type requested */ + + ifs->size =sizeof (te1);/* data size wanted */ +return -ENOBUFS ; + } + +memset (&te1,0 ,sizeof (te1)); + +/* Update slot_map */ + te1.slot_map = qmc_hdlc->slot_map; + +if (copy_to_user (ifs->ifs_ifsu.te1, &te1,sizeof (te1))) +return -EFAULT ; +return 0 ; + +case IF_IFACE_E1 : +case IF_IFACE_T1 : +if (!capable (CAP_NET_ADMIN )) +return -EPERM ; + +if (netdev->flags &IFF_UP ) +return -EBUSY ; + +if (copy_from_user (&te1, ifs->ifs_ifsu.te1,sizeof (te1))) +return -EFAULT ; + +return qmc_hdlc_set_iface (qmc_hdlc, ifs->type, &te1); + +default : +return hdlc_ioctl (netdev, ifs); + } +} +static int qmc_hdlc_open (struct net_device *netdev) {struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);@@ -326,12 +466,13 @@ static const struct net_device_ops qmc_hdlc_netdev_ops = { .ndo_open = qmc_hdlc_open, .ndo_stop = qmc_hdlc_close, .ndo_start_xmit = hdlc_start_xmit, - .ndo_siocwandev = hdlc_ioctl, + .ndo_siocwandev = qmc_hdlc_ioctl, };static int qmc_hdlc_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +struct qmc_chan_ts_info ts_info;struct qmc_hdlc *qmc_hdlc;struct qmc_chan_info info;hdlc_device *hdlc;@@ -357,6 +498,14 @@ static int qmc_hdlc_probe(struct platform_device *pdev)return dev_err_probe (dev, -EINVAL ,"QMC chan mode %d is not QMC_HDLC\n" , info.mode); + ret =qmc_chan_get_ts_info (qmc_hdlc->qmc_chan, &ts_info); +if (ret) +return dev_err_probe (dev, ret,"get QMC channel ts info failed\n" ); + + ret =qmc_hdlc_xlate_ts_info (qmc_hdlc, &ts_info, &qmc_hdlc->slot_map); +if (ret) +return ret; + qmc_hdlc->netdev =alloc_hdlcdev (qmc_hdlc);if (!qmc_hdlc->netdev)return -ENOMEM ;Signature · 1 line
2.43.0
Re: [PATCH v6 4/5] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:20AM +0100, Herve Codina wrote:
...
Quoted 5 lines
Quoted 3 lines
drivers/net/wan/fsl_qmc_hdlc.c +3
-0+DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 );
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 223
Quoted 2 lines
drivers/net/wan/fsl_qmc_hdlc.c +2
-0+bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (map, slot_map);We've got a
BITMAP_FROM_U64()for this:DECLARE_BITMAP(ts_mask_avail, 64) = { BITMAP_FROM_U64(ts_info->rx_ts_mask_avail) }; DECLARE_BITMAP(map, 64) = { BITMAP_FROM_U64(slot_map) };
This looks ugly. Can we rather provide a macro that does this under the hood?
Roughly:
#define DEFINE_BITMAP_64(name, src) \
DECLARE_BITMAP(name, 64) = { BITMAP_FROM_U64(src) }Signature · 2 lines
With Best Regards, Andy Shevchenko
Herve Codina
maintainerRe: [PATCH v6 4/5] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
Hi Andy, Yury,
Quoted 18 lines · On Wed, 6 Mar 2024 15:43:04 +0200 Andy Shevchenko…
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:20AM +0100, Herve Codina wrote:
...
Quoted 5 lines
Quoted 3 lines
drivers/net/wan/fsl_qmc_hdlc.c +3
-0+DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 );Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 223
Quoted 2 lines
drivers/net/wan/fsl_qmc_hdlc.c +2
-0+bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (map, slot_map);We've got a
BITMAP_FROM_U64()for this:DECLARE_BITMAP(ts_mask_avail, 64) = { BITMAP_FROM_U64(ts_info->rx_ts_mask_avail) }; DECLARE_BITMAP(map, 64) = { BITMAP_FROM_U64(slot_map) };
Quoted 7 lines
This looks ugly. Can we rather provide a macro that does this under the hood?
Roughly:
#define DEFINE_BITMAP_64(name, src) \ DECLARE_BITMAP(name, 64) = { BITMAP_FROM_U64(src) }
Well, the construction I used:
DECLARE_BITMAP(foo, 64); ... bitmap_from_u64(foo, init_value); ...
can be found in several places in the kernel.
Having the DEFINE_BITMAP_64() macro can be a way to remove this construction but I am not sure that this should be done in this series.
IMHO, a specific series introducing the macro and updating pieces of code in the kernel everywhere it is needed to replace this construction would make much more sense.
Best regards,
Hervé
Re: [PATCH v6 4/5] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
Quoted 4 lines · Herve Codina
Quoted 2 lines · On Wed, 6 Mar 2024 15:43:04 +0200 Andy Shevchenko…
Quoted 1 line · Yury Norov
On Wed, Mar 06, 2024 at 09:07:20AM +0100, Herve Codina wrote:
...
Quoted 26 lines
Quoted 13 lines
Quoted 5 lines
Quoted 3 lines
drivers/net/wan/fsl_qmc_hdlc.c +3
-0+DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 );Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 223
Quoted 2 lines
drivers/net/wan/fsl_qmc_hdlc.c +2
-0+bitmap_from_u64 (ts_mask_avail, ts_info->rx_ts_mask_avail); +bitmap_from_u64 (map, slot_map);We've got a
BITMAP_FROM_U64()for this:DECLARE_BITMAP(ts_mask_avail, 64) = { BITMAP_FROM_U64(ts_info->rx_ts_mask_avail) }; DECLARE_BITMAP(map, 64) = { BITMAP_FROM_U64(slot_map) };Quoted 7 lines
This looks ugly. Can we rather provide a macro that does this under the hood?
Roughly:
#define DEFINE_BITMAP_64(name, src) \ DECLARE_BITMAP(name, 64) = { BITMAP_FROM_U64(src) }Well, the construction I used:
DECLARE_BITMAP(foo, 64); ... bitmap_from_u64(foo, init_value); ...
Quoted 5 lines
can be found in several places in the kernel.
Having the
DEFINE_BITMAP_64()macro can be a way to remove this construction but I am not sure that this should be done in this series.
I also think that this can be done later, above is just a pure suggestion how.
Quoted 3 lines
IMHO, a specific series introducing the macro and updating pieces of code in the kernel everywhere it is needed to replace this construction would make much more sense.
Right.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Herve Codina
maintainerRe: [PATCH v6 4/5] net: wan: fsl_qmc_hdlc: Add runtime timeslots changes support
In reply to Yury NorovHi Yury,
On Wed, 6 Mar 2024 05:06:12 -0800
Yury Norov <[email protected]> wrote:
...
Quoted 10 lines
drivers/net/wan/fsl_qmc_hdlc.c static netdev_tx_t qmc_hdlc_xmit(struct sk_buff *skb, struct net_device *netdev) · line 243
Quoted 7 lines
drivers/net/wan/fsl_qmc_hdlc.c +7
-0+static int qmc_hdlc_xlate_ts_info (struct qmc_hdlc *qmc_hdlc, +const struct qmc_chan_ts_info *ts_info,u32 *slot_map) +{ +DECLARE_BITMAP (ts_mask_avail,64 ); +DECLARE_BITMAP (ts_mask,64 ); +DECLARE_BITMAP (map,64 ); +u32 array32[2 ];NIT. Bad name. I'd suggest
slot_array, or something.
A new iteration of this series is planned.
I will change to slot_array as suggested.
Best regards,
Hervé
Herve Codina
maintainerPATCH v6 5/5 net: wan: fsl_qmc_hdlc: Add framer support
In reply to Herve CodinaAdd framer support in the fsl_qmc_hdlc driver in order to be able to signal carrier changes to the network stack based on the framer status Also use this framer to provide information related to the E1/T1 line interface on IF_GET_IFACE and configure the line interface according to IF_IFACE_{E1,T1} information.
--- drivers/net/wan/fsl_qmc_hdlc.c | 239 ++++++++++++++++++++++++++++++++- 1 file changed, 234 insertions(+), 5 deletions(-)
drivers/net/wan/fsl_qmc_hdlc.c +234 -5
@@ -14,6 +14,7 @@#include <linux/dma-mapping.h> #include <linux/device.h> #include <linux/err.h> +#include <linux/framer/framer.h> #include <linux/hdlc.h> #include <linux/mod_devicetable.h> #include <linux/module.h>
@@ -35,6 +36,9 @@ struct qmc_hdlc {struct device *dev;struct qmc_chan *qmc_chan;struct net_device *netdev; +struct framer *framer; +spinlock_t carrier_lock;/* Protect carrier detection */ +struct notifier_block nb;bool is_crc32;spinlock_t tx_lock;/* Protect tx descriptors */ struct qmc_hdlc_desc tx_descs[8 ];
@@ -48,6 +52,192 @@ static struct qmc_hdlc *netdev_to_qmc_hdlc(struct net_device *netdev)return dev_to_hdlc (netdev)->priv; } +static int qmc_hdlc_framer_set_carrier (struct qmc_hdlc *qmc_hdlc) +{ +struct framer_status framer_status; +int ret; + +if (!qmc_hdlc->framer) +return 0 ; + +guard (spinlock_irqsave)(&qmc_hdlc->carrier_lock); + + ret =framer_get_status (qmc_hdlc->framer, &framer_status); +if (ret) { +dev_err (qmc_hdlc->dev,"get framer status failed (%d)\n" , ret); +return ret; + } +if (framer_status.link_is_on) +netif_carrier_on (qmc_hdlc->netdev); +else +netif_carrier_off (qmc_hdlc->netdev); + +return 0 ; +} + +static int qmc_hdlc_framer_notifier (struct notifier_block *nb,unsigned long action, +void *data) +{ + struct qmc_hdlc *qmc_hdlc = container_of(nb, struct qmc_hdlc, nb); +int ret; + +if (action !=FRAMER_EVENT_STATUS ) +return NOTIFY_DONE ; + + ret =qmc_hdlc_framer_set_carrier (qmc_hdlc); +return ret ?NOTIFY_DONE :NOTIFY_OK ; +} + +static int qmc_hdlc_framer_start (struct qmc_hdlc *qmc_hdlc) +{ +struct framer_status framer_status; +int ret; + +if (!qmc_hdlc->framer) +return 0 ; + + ret =framer_power_on (qmc_hdlc->framer); +if (ret) { +dev_err (qmc_hdlc->dev,"framer power-on failed (%d)\n" , ret); +return ret; + } + +/* Be sure that get_status is supported */ + ret =framer_get_status (qmc_hdlc->framer, &framer_status); +if (ret) { +dev_err (qmc_hdlc->dev,"get framer status failed (%d)\n" , ret); + goto framer_power_off; + } + + qmc_hdlc->nb.notifier_call = qmc_hdlc_framer_notifier; + ret =framer_notifier_register (qmc_hdlc->framer, &qmc_hdlc->nb); +if (ret) { +dev_err (qmc_hdlc->dev,"framer notifier register failed (%d)\n" , ret); + goto framer_power_off; + } + +return 0 ; + +framer_power_off: +framer_power_off (qmc_hdlc->framer); +return ret; +} + +static void qmc_hdlc_framer_stop (struct qmc_hdlc *qmc_hdlc) +{ +if (!qmc_hdlc->framer) +return ; + +framer_notifier_unregister (qmc_hdlc->framer, &qmc_hdlc->nb); +framer_power_off (qmc_hdlc->framer); +} + +static int qmc_hdlc_framer_set_iface (struct qmc_hdlc *qmc_hdlc,int if_iface, +const te1_settings *te1) +{ +struct framer_config config; +int ret; + +if (!qmc_hdlc->framer) +return 0 ; + + ret =framer_get_config (qmc_hdlc->framer, &config); +if (ret) +return ret; + +switch (if_iface) { +case IF_IFACE_E1 : + config.iface =FRAMER_IFACE_E1 ; +break ; +case IF_IFACE_T1 : + config.iface =FRAMER_IFACE_T1 ; +break ; +default : +return -EINVAL ; + } + +switch (te1->clock_type) { +case CLOCK_DEFAULT : +/* Keep current value */ +break ; +case CLOCK_EXT : + config.clock_type =FRAMER_CLOCK_EXT ; +break ; +case CLOCK_INT : + config.clock_type =FRAMER_CLOCK_INT ; +break ; +default : +return -EINVAL ; + } + config.line_clock_rate = te1->clock_rate; + +return framer_set_config (qmc_hdlc->framer, &config); +} + +static int qmc_hdlc_framer_get_iface (struct qmc_hdlc *qmc_hdlc,int *if_iface,te1_settings *te1) +{ +struct framer_config config; +int ret; + +if (!qmc_hdlc->framer) { + *if_iface =IF_IFACE_E1 ; +return 0 ; + } + + ret =framer_get_config (qmc_hdlc->framer, &config); +if (ret) +return ret; + +switch (config.iface) { +case FRAMER_IFACE_E1 : + *if_iface =IF_IFACE_E1 ; +break ; +case FRAMER_IFACE_T1 : + *if_iface =IF_IFACE_T1 ; +break ; + } + +if (!te1) +return 0 ;/* Only iface type requested */ + +switch (config.clock_type) { +case FRAMER_CLOCK_EXT : + te1->clock_type =CLOCK_EXT ; +break ; +case FRAMER_CLOCK_INT : + te1->clock_type =CLOCK_INT ; +break ; +default : +return -EINVAL ; + } + te1->clock_rate = config.line_clock_rate; +return 0 ; +} + +static int qmc_hdlc_framer_init (struct qmc_hdlc *qmc_hdlc) +{ +int ret; + +if (!qmc_hdlc->framer) +return 0 ; + + ret =framer_init (qmc_hdlc->framer); +if (ret) { +dev_err (qmc_hdlc->dev,"framer init failed (%d)\n" , ret); +return ret; + } + +return 0 ; +} + +static void qmc_hdlc_framer_exit (struct qmc_hdlc *qmc_hdlc) +{ +if (!qmc_hdlc->framer) +return ; + +framer_exit (qmc_hdlc->framer); +} +static int qmc_hdlc_recv_queue (struct qmc_hdlc *qmc_hdlc,struct qmc_hdlc_desc *desc,size_t size);#define QMC_HDLC_RX_ERROR_FLAGS \
@@ -297,6 +487,12 @@ static int qmc_hdlc_set_iface(struct qmc_hdlc *qmc_hdlc, int if_iface, const te1 qmc_hdlc->slot_map = te1->slot_map; + ret =qmc_hdlc_framer_set_iface (qmc_hdlc, if_iface, te1); +if (ret) { +dev_err (qmc_hdlc->dev,"framer set iface failed %d\n" , ret); +return ret; + } +return 0 ; }
@@ -304,11 +500,16 @@ static int qmc_hdlc_ioctl(struct net_device *netdev, struct if_settings *ifs) {struct qmc_hdlc *qmc_hdlc =netdev_to_qmc_hdlc (netdev);te1_settings te1; +int ret;switch (ifs->type) {case IF_GET_IFACE : - ifs->type =IF_IFACE_E1 ;if (ifs->size <sizeof (te1)) { +/* Retrieve type only */ + ret =qmc_hdlc_framer_get_iface (qmc_hdlc, &ifs->type,NULL ); +if (ret) +return ret; +if (!ifs->size)return 0 ;/* only type requested */
@@ -318,6 +519,11 @@ static int qmc_hdlc_ioctl(struct net_device *netdev, struct if_settings *ifs)memset (&te1,0 ,sizeof (te1)); +/* Retrieve info from framer */ + ret =qmc_hdlc_framer_get_iface (qmc_hdlc, &ifs->type, &te1); +if (ret) +return ret; +/* Update slot_map */ te1.slot_map = qmc_hdlc->slot_map;
@@ -351,10 +557,17 @@ static int qmc_hdlc_open(struct net_device *netdev)int ret;int i; - ret =hdlc_open (netdev); + ret =qmc_hdlc_framer_start (qmc_hdlc);if (ret)return ret; + ret =hdlc_open (netdev); +if (ret) + goto framer_stop; + +/* Update carrier */ +qmc_hdlc_framer_set_carrier (qmc_hdlc); + chan_param.mode =QMC_HDLC ;/* HDLC_MAX_MRU + 4 for the CRC * HDLC_MAX_MRU + 4 + 8 for the CRC and some extraspace needed by the QMC
@@ -401,6 +614,8 @@ static int qmc_hdlc_open(struct net_device *netdev) } hdlc_close:hdlc_close (netdev); +framer_stop: +qmc_hdlc_framer_stop (qmc_hdlc);return ret; }
@@ -436,6 +651,7 @@ static int qmc_hdlc_close(struct net_device *netdev) }hdlc_close (netdev); +qmc_hdlc_framer_stop (qmc_hdlc);return 0 ; }
@@ -484,6 +700,7 @@ static int qmc_hdlc_probe(struct platform_device *pdev) qmc_hdlc->dev = dev;spin_lock_init (&qmc_hdlc->tx_lock); +spin_lock_init (&qmc_hdlc->carrier_lock); qmc_hdlc->qmc_chan =devm_qmc_chan_get_bychild (dev, dev->of_node);if (IS_ERR (qmc_hdlc->qmc_chan))
@@ -506,9 +723,19 @@ static int qmc_hdlc_probe(struct platform_device *pdev)if (ret)return ret; + qmc_hdlc->framer =devm_framer_optional_get (dev,"fsl,framer" ); +if (IS_ERR (qmc_hdlc->framer)) +return PTR_ERR (qmc_hdlc->framer); + + ret =qmc_hdlc_framer_init (qmc_hdlc); +if (ret) +return ret; + qmc_hdlc->netdev =alloc_hdlcdev (qmc_hdlc); -if (!qmc_hdlc->netdev) -return -ENOMEM ; +if (!qmc_hdlc->netdev) { + ret = -ENOMEM ; + goto framer_exit; + } hdlc =dev_to_hdlc (qmc_hdlc->netdev); hdlc->attach = qmc_hdlc_attach;
@@ -523,11 +750,12 @@ static int qmc_hdlc_probe(struct platform_device *pdev) }platform_set_drvdata (pdev, qmc_hdlc); -return 0 ; free_netdev:free_netdev (qmc_hdlc->netdev); +framer_exit: +qmc_hdlc_framer_exit (qmc_hdlc);return ret; }
@@ -537,6 +765,7 @@ static int qmc_hdlc_remove(struct platform_device *pdev)unregister_hdlc_device (qmc_hdlc->netdev);free_netdev (qmc_hdlc->netdev); +qmc_hdlc_framer_exit (qmc_hdlc);return 0 ; }
Signature · 1 line
2.43.0