qmc_hdlc
ret = framer_power_on(qmc_hdlc->framer);
dev_err(qmc_hdlc->dev, "framer power-on failed (%d)\n", ret);
ret = framer_get_status(qmc_hdlc->framer, &framer_status);
dev_err(qmc_hdlc->dev, "get framer status failed (%d)\n", ret);
qmc_hdlc->nb.notifier_call = qmc_hdlc_framer_notifier;
ret = framer_notifier_register(qmc_hdlc->framer, &qmc_hdlc->nb);
dev_err(qmc_hdlc->dev, "framer notifier register failed (%d)\n", ret);
framer_power_off(qmc_hdlc->framer);
static void qmc_hdlc_framer_stop(struct qmc_hdlc *qmc_hdlc)
if (!qmc_hdlc->framer)
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,
if (!qmc_hdlc->framer)
ret = framer_get_config(qmc_hdlc->framer, &config);
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)
if (!qmc_hdlc->framer) {
ret = framer_get_config(qmc_hdlc->framer, &config);
static int qmc_hdlc_framer_init(struct qmc_hdlc *qmc_hdlc)
if (!qmc_hdlc->framer)
ret = framer_init(qmc_hdlc->framer);
dev_err(qmc_hdlc->dev, "framer init failed (%d)\n", ret);
static void qmc_hdlc_framer_exit(struct qmc_hdlc *qmc_hdlc)
if (!qmc_hdlc->framer)
framer_exit(qmc_hdlc->framer);
static int qmc_hdlc_recv_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc, size_t size);
struct qmc_hdlc *qmc_hdlc;
qmc_hdlc = netdev_to_qmc_hdlc(netdev);
dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_FROM_DEVICE);
crc_size = qmc_hdlc->is_crc32 ? 4 : 2;
ret = qmc_hdlc_recv_queue(qmc_hdlc, desc, desc->dma_size);
dev_err(qmc_hdlc->dev, "queue recv desc failed (%d)\n", ret);
static int qmc_hdlc_recv_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc, size_t size)
desc->dma_addr = dma_map_single(qmc_hdlc->dev, desc->skb->data,
ret = dma_mapping_error(qmc_hdlc->dev, desc->dma_addr);
ret = qmc_chan_read_submit(qmc_hdlc->qmc_chan, desc->dma_addr, desc->dma_size,
dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_FROM_DEVICE);
struct qmc_hdlc *qmc_hdlc;
qmc_hdlc = netdev_to_qmc_hdlc(netdev);
scoped_guard(spinlock_irqsave, &qmc_hdlc->tx_lock) {
dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size, DMA_TO_DEVICE);
static int qmc_hdlc_xmit_queue(struct qmc_hdlc *qmc_hdlc, struct qmc_hdlc_desc *desc)
desc->dma_addr = dma_map_single(qmc_hdlc->dev, desc->skb->data,
ret = dma_mapping_error(qmc_hdlc->dev, desc->dma_addr);
dev_err(qmc_hdlc->dev, "failed to map skb\n");
ret = qmc_chan_write_submit(qmc_hdlc->qmc_chan, desc->dma_addr, desc->dma_size,
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);
struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev);
guard(spinlock_irqsave)(&qmc_hdlc->tx_lock);
desc = &qmc_hdlc->tx_descs[qmc_hdlc->tx_out];
err = qmc_hdlc_xmit_queue(qmc_hdlc, desc);
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)
static int qmc_hdlc_xlate_slot_map(struct qmc_hdlc *qmc_hdlc,
dev_err(qmc_hdlc->dev, "tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n",
dev_err(qmc_hdlc->dev, "Cannot translate timeslots %64pb -> (%64pb, %64pb)\n",
static int qmc_hdlc_xlate_ts_info(struct qmc_hdlc *qmc_hdlc,
dev_err(qmc_hdlc->dev, "tx and rx available timeslots mismatch (0x%llx, 0x%llx)\n",
dev_err(qmc_hdlc->dev, "tx and rx timeslots mismatch (0x%llx, 0x%llx)\n",
dev_err(qmc_hdlc->dev, "Cannot translate timeslots (%64pb, %64pb) -> %64pb\n",
dev_err(qmc_hdlc->dev, "Slot map out of 32bit (%64pb, %64pb) -> %64pb\n",
static int qmc_hdlc_set_iface(struct qmc_hdlc *qmc_hdlc, int if_iface, const te1_settings *te1)
ret = qmc_chan_get_ts_info(qmc_hdlc->qmc_chan, &ts_info);
dev_err(qmc_hdlc->dev, "get QMC channel ts info failed %d\n", ret);
ret = qmc_hdlc_xlate_slot_map(qmc_hdlc, te1->slot_map, &ts_info);
ret = qmc_chan_set_ts_info(qmc_hdlc->qmc_chan, &ts_info);
dev_err(qmc_hdlc->dev, "set QMC channel ts info failed %d\n", ret);
qmc_hdlc->slot_map = te1->slot_map;
ret = qmc_hdlc_framer_set_iface(qmc_hdlc, if_iface, te1);
static struct qmc_hdlc *netdev_to_qmc_hdlc(struct net_device *netdev)
dev_err(qmc_hdlc->dev, "framer set iface failed %d\n", ret);
struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev);
ret = qmc_hdlc_framer_get_iface(qmc_hdlc, &ifs->type, NULL);
ret = qmc_hdlc_framer_get_iface(qmc_hdlc, &ifs->type, &te1);
te1.slot_map = qmc_hdlc->slot_map;
static int qmc_hdlc_framer_set_carrier(struct qmc_hdlc *qmc_hdlc)
return qmc_hdlc_set_iface(qmc_hdlc, ifs->type, &te1);
struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev);
ret = qmc_hdlc_framer_start(qmc_hdlc);
qmc_hdlc_framer_set_carrier(qmc_hdlc);
chan_param.hdlc.is_crc32 = qmc_hdlc->is_crc32;
ret = qmc_chan_set_param(qmc_hdlc->qmc_chan, &chan_param);
dev_err(qmc_hdlc->dev, "failed to set param (%d)\n", ret);
for (i = 0; i < ARRAY_SIZE(qmc_hdlc->rx_descs); i++) {
desc = &qmc_hdlc->rx_descs[i];
ret = qmc_hdlc_recv_queue(qmc_hdlc, desc, chan_param.hdlc.max_rx_buf_size);
if (!qmc_hdlc->framer)
ret = qmc_chan_start(qmc_hdlc->qmc_chan, QMC_CHAN_ALL);
dev_err(qmc_hdlc->dev, "qmc chan start failed (%d)\n", ret);
qmc_chan_reset(qmc_hdlc->qmc_chan, QMC_CHAN_ALL);
desc = &qmc_hdlc->rx_descs[i];
dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size,
qmc_hdlc_framer_stop(qmc_hdlc);
guard(mutex)(&qmc_hdlc->carrier_lock);
struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev);
qmc_chan_stop(qmc_hdlc->qmc_chan, QMC_CHAN_ALL);
qmc_chan_reset(qmc_hdlc->qmc_chan, QMC_CHAN_ALL);
for (i = 0; i < ARRAY_SIZE(qmc_hdlc->tx_descs); i++) {
desc = &qmc_hdlc->tx_descs[i];
dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size,
ret = framer_get_status(qmc_hdlc->framer, &framer_status);
for (i = 0; i < ARRAY_SIZE(qmc_hdlc->rx_descs); i++) {
desc = &qmc_hdlc->rx_descs[i];
dma_unmap_single(qmc_hdlc->dev, desc->dma_addr, desc->dma_size,
qmc_hdlc_framer_stop(qmc_hdlc);
dev_err(qmc_hdlc->dev, "get framer status failed (%d)\n", ret);
struct qmc_hdlc *qmc_hdlc = netdev_to_qmc_hdlc(netdev);
qmc_hdlc->is_crc32 = false;
qmc_hdlc->is_crc32 = true;
dev_err(qmc_hdlc->dev, "unsupported parity %u\n", parity);
struct qmc_hdlc *qmc_hdlc;
qmc_hdlc = devm_kzalloc(dev, sizeof(*qmc_hdlc), GFP_KERNEL);
if (!qmc_hdlc)
netif_carrier_on(qmc_hdlc->netdev);
qmc_hdlc->dev = dev;
spin_lock_init(&qmc_hdlc->tx_lock);
mutex_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))
return dev_err_probe(dev, PTR_ERR(qmc_hdlc->qmc_chan),
ret = qmc_chan_get_info(qmc_hdlc->qmc_chan, &info);
ret = qmc_chan_get_ts_info(qmc_hdlc->qmc_chan, &ts_info);
netif_carrier_off(qmc_hdlc->netdev);
ret = qmc_hdlc_xlate_ts_info(qmc_hdlc, &ts_info, &qmc_hdlc->slot_map);
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);
qmc_hdlc->netdev = alloc_hdlcdev(qmc_hdlc);
if (!qmc_hdlc->netdev) {
hdlc = dev_to_hdlc(qmc_hdlc->netdev);
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);
platform_set_drvdata(pdev, qmc_hdlc);
free_netdev(qmc_hdlc->netdev);
qmc_hdlc_framer_exit(qmc_hdlc);
struct qmc_hdlc *qmc_hdlc = platform_get_drvdata(pdev);
unregister_hdlc_device(qmc_hdlc->netdev);
free_netdev(qmc_hdlc->netdev);
qmc_hdlc_framer_exit(qmc_hdlc);
struct qmc_hdlc *qmc_hdlc = container_of(nb, struct qmc_hdlc, nb);
ret = qmc_hdlc_framer_set_carrier(qmc_hdlc);
static int qmc_hdlc_framer_start(struct qmc_hdlc *qmc_hdlc)
if (!qmc_hdlc->framer)