p@2550: /**
p@2550: Network Driver for Beckhoff CCAT communication controller
p@2550: Copyright (C) 2014 Beckhoff Automation GmbH
p@2550: Author: Patrick Bruenn
p@2550:
p@2550: This program is free software; you can redistribute it and/or modify
p@2550: it under the terms of the GNU General Public License as published by
p@2550: the Free Software Foundation; either version 2 of the License, or
p@2550: (at your option) any later version.
p@2550:
p@2550: This program is distributed in the hope that it will be useful,
p@2550: but WITHOUT ANY WARRANTY; without even the implied warranty of
p@2550: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
p@2550: GNU General Public License for more details.
p@2550:
p@2550: You should have received a copy of the GNU General Public License along
p@2550: with this program; if not, write to the Free Software Foundation, Inc.,
p@2550: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
p@2550: */
p@2550:
p@2550: #include
p@2550: #include
p@2550: #include
p@2550: #include
p@2550: #include
p@2550: #include
p@2550: #include
p@2550: #include
p@2550:
p@2552: #include "compat.h"
p@2550: #include "module.h"
p@2550: #include "netdev.h"
p@2550: #include "print.h"
p@2550:
p@2550: /**
p@2550: * EtherCAT frame to enable forwarding on EtherCAT Terminals
p@2550: */
p@2550: static const UINT8 frameForwardEthernetFrames[] = {
p@2550: 0x01, 0x01, 0x05, 0x01, 0x00, 0x00,
p@2550: 0x00, 0x1b, 0x21, 0x36, 0x1b, 0xce,
p@2550: 0x88, 0xa4, 0x0e, 0x10,
p@2550: 0x08,
p@2550: 0x00,
p@2550: 0x00, 0x00,
p@2550: 0x00, 0x01,
p@2550: 0x02, 0x00,
p@2550: 0x00, 0x00,
p@2550: 0x00, 0x00,
p@2550: 0x00, 0x00
p@2550: };
p@2550:
p@2550: #define FIFO_LENGTH 64
p@2550: #define DMA_POLL_DELAY_RANGE_USECS 100, 100 /* time to sleep between rx/tx DMA polls */
p@2550: #define POLL_DELAY_RANGE_USECS 500, 1000 /* time to sleep between link state polls */
p@2550:
p@2550: static void ec_poll(struct net_device *dev);
p@2550: static int run_poll_thread(void *data);
p@2550: static int run_rx_thread(void *data);
p@2550: static int run_tx_thread(void *data);
p@2550:
p@2552: #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
p@2550: static struct rtnl_link_stats64 *ccat_eth_get_stats64(struct net_device *dev, struct rtnl_link_stats64
p@2550: *storage);
p@2552: #endif
p@2550: static int ccat_eth_open(struct net_device *dev);
p@2550: static netdev_tx_t ccat_eth_start_xmit(struct sk_buff *skb,
p@2550: struct net_device *dev);
p@2550: static int ccat_eth_stop(struct net_device *dev);
p@2550: static void ccat_eth_xmit_raw(struct net_device *dev, const char *data,
p@2550: size_t len);
p@2550:
p@2550: static const struct net_device_ops ccat_eth_netdev_ops = {
p@2552: #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
p@2550: .ndo_get_stats64 = ccat_eth_get_stats64,
p@2552: #endif
p@2550: .ndo_open = ccat_eth_open,
p@2550: .ndo_start_xmit = ccat_eth_start_xmit,
p@2550: .ndo_stop = ccat_eth_stop,
p@2550: };
p@2550:
p@2550: static void ecdev_kfree_skb_any(struct sk_buff *skb)
p@2550: {
p@2550: /* never release a skb in EtherCAT mode */
p@2550: }
p@2550:
p@2550: static void ecdev_carrier_on(struct net_device *const netdev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(netdev);
p@2550: ecdev_set_link(priv->ecdev, 1);
p@2550: }
p@2550:
p@2550: static void ecdev_carrier_off(struct net_device *const netdev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(netdev);
p@2550: ecdev_set_link(priv->ecdev, 0);
p@2550: }
p@2550:
p@2550: static void ecdev_nop(struct net_device *const netdev)
p@2550: {
p@2550: /* dummy called if nothing has to be done in EtherCAT operation mode */
p@2550: }
p@2550:
p@2550: static void ecdev_tx_fifo_full(struct net_device *const dev,
p@2550: const struct ccat_eth_frame *const frame)
p@2550: {
p@2550: /* we are polled -> there is nothing we can do in EtherCAT mode */
p@2550: }
p@2550:
p@2550: static void unregister_ecdev(struct net_device *const netdev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(netdev);
p@2550: ecdev_close(priv->ecdev);
p@2550: ecdev_withdraw(priv->ecdev);
p@2550: }
p@2550:
p@2550: typedef void (*fifo_add_function) (struct ccat_eth_frame *,
p@2550: struct ccat_eth_dma_fifo *);
p@2550:
p@2550: static void ccat_eth_rx_fifo_add(struct ccat_eth_frame *frame,
p@2550: struct ccat_eth_dma_fifo *fifo)
p@2550: {
p@2550: const size_t offset = ((void *)(frame) - fifo->dma.virt);
p@2550: const uint32_t addr_and_length = (1 << 31) | offset;
p@2550: frame->received = 0;
p@2550: iowrite32(addr_and_length, fifo->reg);
p@2550: }
p@2550:
p@2550: static void ccat_eth_tx_fifo_add_free(struct ccat_eth_frame *frame,
p@2550: struct ccat_eth_dma_fifo *fifo)
p@2550: {
p@2550: /* mark frame as ready to use for tx */
p@2550: frame->sent = 1;
p@2550: }
p@2550:
p@2550: static void ccat_eth_tx_fifo_full(struct net_device *const dev,
p@2550: const struct ccat_eth_frame *const frame)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: netif_stop_queue(dev);
p@2550: priv->next_tx_frame = frame;
p@2550: wake_up_process(priv->tx_thread);
p@2550: }
p@2550:
p@2550: static void ccat_eth_dma_fifo_reset(struct ccat_eth_dma_fifo *fifo)
p@2550: {
p@2550: struct ccat_eth_frame *frame = fifo->dma.virt;
p@2550: const struct ccat_eth_frame *const end = frame + FIFO_LENGTH;
p@2550:
p@2550: /* reset hw fifo */
p@2550: iowrite32(0, fifo->reg + 0x8);
p@2550: wmb();
p@2550:
p@2550: if (fifo->add) {
p@2550: while (frame < end) {
p@2550: fifo->add(frame, fifo);
p@2550: ++frame;
p@2550: }
p@2550: }
p@2550: }
p@2550:
p@2550: static int ccat_eth_dma_fifo_init(struct ccat_eth_dma_fifo *fifo,
p@2550: void __iomem * const fifo_reg,
p@2550: fifo_add_function add, size_t channel,
p@2550: struct ccat_eth_priv *const priv)
p@2550: {
p@2550: if (0 !=
p@2550: ccat_dma_init(&fifo->dma, channel, priv->ccatdev->bar[2].ioaddr,
p@2550: &priv->ccatdev->pdev->dev)) {
p@2550: pr_info("init DMA%llu memory failed.\n", (uint64_t) channel);
p@2550: return -1;
p@2550: }
p@2550: fifo->add = add;
p@2550: fifo->reg = fifo_reg;
p@2550: return 0;
p@2550: }
p@2550:
p@2550: /**
p@2550: * Stop both (Rx/Tx) DMA fifo's and free related management structures
p@2550: */
p@2550: static void ccat_eth_priv_free_dma(struct ccat_eth_priv *priv)
p@2550: {
p@2550: /* reset hw fifo's */
p@2550: iowrite32(0, priv->rx_fifo.reg + 0x8);
p@2550: iowrite32(0, priv->tx_fifo.reg + 0x8);
p@2550: wmb();
p@2550:
p@2550: /* release dma */
p@2550: ccat_dma_free(&priv->rx_fifo.dma);
p@2550: ccat_dma_free(&priv->tx_fifo.dma);
p@2550: pr_debug("DMA fifo's stopped.\n");
p@2550: }
p@2550:
p@2550: /**
p@2550: * Initalizes both (Rx/Tx) DMA fifo's and related management structures
p@2550: */
p@2550: static int ccat_eth_priv_init_dma(struct ccat_eth_priv *priv)
p@2550: {
p@2550: if (ccat_eth_dma_fifo_init
p@2550: (&priv->rx_fifo, priv->reg.rx_fifo, ccat_eth_rx_fifo_add,
p@2550: priv->info.rxDmaChn, priv)) {
p@2550: pr_warn("init Rx DMA fifo failed.\n");
p@2550: return -1;
p@2550: }
p@2550:
p@2550: if (ccat_eth_dma_fifo_init
p@2550: (&priv->tx_fifo, priv->reg.tx_fifo, ccat_eth_tx_fifo_add_free,
p@2550: priv->info.txDmaChn, priv)) {
p@2550: pr_warn("init Tx DMA fifo failed.\n");
p@2550: ccat_dma_free(&priv->rx_fifo.dma);
p@2550: return -1;
p@2550: }
p@2550:
p@2550: /* disable MAC filter */
p@2550: iowrite8(0, priv->reg.mii + 0x8 + 6);
p@2550: wmb();
p@2550: return 0;
p@2550: }
p@2550:
p@2550: /**
p@2550: * Initializes the CCat... members of the ccat_eth_priv structure.
p@2550: * Call this function only if info and ioaddr are already initialized!
p@2550: */
p@2550: static void ccat_eth_priv_init_mappings(struct ccat_eth_priv *priv)
p@2550: {
p@2550: CCatInfoBlockOffs offsets;
p@2550: void __iomem *const func_base =
p@2550: priv->ccatdev->bar[0].ioaddr + priv->info.nAddr;
p@2550: memcpy_fromio(&offsets, func_base, sizeof(offsets));
p@2550: priv->reg.mii = func_base + offsets.nMMIOffs;
p@2550: priv->reg.tx_fifo = func_base + offsets.nTxFifoOffs;
p@2550: priv->reg.rx_fifo = func_base + offsets.nTxFifoOffs + 0x10;
p@2550: priv->reg.mac = func_base + offsets.nMacRegOffs;
p@2550: priv->reg.rx_mem = func_base + offsets.nRxMemOffs;
p@2550: priv->reg.tx_mem = func_base + offsets.nTxMemOffs;
p@2550: priv->reg.misc = func_base + offsets.nMiscOffs;
p@2550: }
p@2550:
p@2550: /**
p@2550: * Read link state from CCAT hardware
p@2550: * @return 1 if link is up, 0 if not
p@2550: */
p@2550: inline static size_t ccat_eth_priv_read_link_state(const struct ccat_eth_priv
p@2550: *const priv)
p@2550: {
p@2550: return (1 << 24) == (ioread32(priv->reg.mii + 0x8 + 4) & (1 << 24));
p@2550: }
p@2550:
p@2552: #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
p@2550: static struct rtnl_link_stats64 *ccat_eth_get_stats64(struct net_device *dev, struct rtnl_link_stats64
p@2550: *storage)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: CCatMacRegs mac;
p@2550: memcpy_fromio(&mac, priv->reg.mac, sizeof(mac));
p@2550: storage->rx_packets = mac.rxFrameCnt; /* total packets received */
p@2550: storage->tx_packets = mac.txFrameCnt; /* total packets transmitted */
p@2550: storage->rx_bytes = atomic64_read(&priv->rx_bytes); /* total bytes received */
p@2550: storage->tx_bytes = atomic64_read(&priv->tx_bytes); /* total bytes transmitted */
p@2550: storage->rx_errors = mac.frameLenErrCnt + mac.dropFrameErrCnt + mac.crcErrCnt + mac.rxErrCnt; /* bad packets received */
p@2550: //TODO __u64 tx_errors; /* packet transmit problems */
p@2550: storage->rx_dropped = atomic64_read(&priv->rx_dropped); /* no space in linux buffers */
p@2550: storage->tx_dropped = atomic64_read(&priv->tx_dropped); /* no space available in linux */
p@2550: //TODO __u64 multicast; /* multicast packets received */
p@2550: //TODO __u64 collisions;
p@2550:
p@2550: /* detailed rx_errors: */
p@2550: storage->rx_length_errors = mac.frameLenErrCnt;
p@2550: storage->rx_over_errors = mac.dropFrameErrCnt; /* receiver ring buff overflow */
p@2550: storage->rx_crc_errors = mac.crcErrCnt; /* recved pkt with crc error */
p@2550: storage->rx_frame_errors = mac.rxErrCnt; /* recv'd frame alignment error */
p@2550: storage->rx_fifo_errors = mac.dropFrameErrCnt; /* recv'r fifo overrun */
p@2550: //TODO __u64 rx_missed_errors; /* receiver missed packet */
p@2550:
p@2550: /* detailed tx_errors */
p@2550: //TODO __u64 tx_aborted_errors;
p@2550: //TODO __u64 tx_carrier_errors;
p@2550: //TODO __u64 tx_fifo_errors;
p@2550: //TODO __u64 tx_heartbeat_errors;
p@2550: //TODO __u64 tx_window_errors;
p@2550:
p@2550: /* for cslip etc */
p@2550: //TODO __u64 rx_compressed;
p@2550: //TODO __u64 tx_compressed;
p@2550: return storage;
p@2550: }
p@2552: #endif
p@2550:
p@2550: struct ccat_eth_priv *ccat_eth_init(const struct ccat_device *const ccatdev,
p@2550: const void __iomem * const addr)
p@2550: {
p@2550: struct ccat_eth_priv *priv;
p@2550: struct net_device *const netdev = alloc_etherdev(sizeof(*priv));
p@2550: priv = netdev_priv(netdev);
p@2550: priv->netdev = netdev;
p@2550: priv->ccatdev = ccatdev;
p@2550:
p@2550: /* ccat register mappings */
p@2550: memcpy_fromio(&priv->info, addr, sizeof(priv->info));
p@2550: ccat_eth_priv_init_mappings(priv);
p@2550: ccat_print_function_info(priv);
p@2550:
p@2550: if (ccat_eth_priv_init_dma(priv)) {
p@2550: pr_warn("%s(): DMA initialization failed.\n", __FUNCTION__);
p@2550: free_netdev(netdev);
p@2550: return NULL;
p@2550: }
p@2550:
p@2550: /* init netdev with MAC and stack callbacks */
p@2550: memcpy_fromio(netdev->dev_addr, priv->reg.mii + 8, 6);
p@2550: netdev->netdev_ops = &ccat_eth_netdev_ops;
p@2550:
p@2550: /* use as EtherCAT device? */
p@2550: priv->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE);
p@2550: if (priv->ecdev) {
p@2550: priv->carrier_off = ecdev_carrier_off;
p@2550: priv->carrier_on = ecdev_carrier_on;
p@2550: priv->kfree_skb_any = ecdev_kfree_skb_any;
p@2550: priv->start_queue = ecdev_nop;
p@2550: priv->stop_queue = ecdev_nop;
p@2550: priv->tx_fifo_full = ecdev_tx_fifo_full;
p@2550: priv->unregister = unregister_ecdev;
p@2550: if (ecdev_open(priv->ecdev)) {
p@2550: pr_info("unable to register network device.\n");
p@2550: ecdev_withdraw(priv->ecdev);
p@2550: ccat_eth_priv_free_dma(priv);
p@2550: free_netdev(netdev);
p@2550: return NULL;
p@2550: }
p@2550: return priv;
p@2550: }
p@2550:
p@2550: /* EtherCAT disabled -> prepare normal ethernet mode */
p@2550: priv->carrier_off = netif_carrier_off;
p@2550: priv->carrier_on = netif_carrier_on;
p@2550: priv->kfree_skb_any = dev_kfree_skb_any;
p@2550: priv->start_queue = netif_start_queue;
p@2550: priv->stop_queue = netif_stop_queue;
p@2550: priv->tx_fifo_full = ccat_eth_tx_fifo_full;
p@2550: priv->unregister = unregister_netdev;
p@2550: if (register_netdev(netdev)) {
p@2550: pr_info("unable to register network device.\n");
p@2550: ccat_eth_priv_free_dma(priv);
p@2550: free_netdev(netdev);
p@2550: return NULL;
p@2550: }
p@2550: pr_info("registered %s as network device.\n", netdev->name);
p@2550: priv->rx_thread = kthread_run(run_rx_thread, netdev, "%s_rx", DRV_NAME);
p@2550: priv->tx_thread = kthread_run(run_tx_thread, netdev, "%s_tx", DRV_NAME);
p@2550: return priv;
p@2550: }
p@2550:
p@2550: void ccat_eth_remove(struct ccat_eth_priv *const priv)
p@2550: {
p@2550: if (priv->rx_thread) {
p@2550: kthread_stop(priv->rx_thread);
p@2550: }
p@2550: if (priv->tx_thread) {
p@2550: kthread_stop(priv->tx_thread);
p@2550: }
p@2550: priv->unregister(priv->netdev);
p@2550: ccat_eth_priv_free_dma(priv);
p@2550: free_netdev(priv->netdev);
p@2550: pr_debug("%s(): done\n", __FUNCTION__);
p@2550: }
p@2550:
p@2550: static int ccat_eth_open(struct net_device *dev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: priv->carrier_off(dev);
p@2550: priv->poll_thread =
p@2550: kthread_run(run_poll_thread, dev, "%s_poll", DRV_NAME);
p@2550:
p@2550: //TODO
p@2550: return 0;
p@2550: }
p@2550:
p@2550: static const size_t CCATRXDESC_HEADER_LEN = 20;
p@2550: static void ccat_eth_receive(struct net_device *const dev,
p@2550: const struct ccat_eth_frame *const frame)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: const size_t len = frame->length - CCATRXDESC_HEADER_LEN;
p@2550: struct sk_buff *skb = dev_alloc_skb(len + NET_IP_ALIGN);
p@2550: if (!skb) {
p@2550: pr_info("%s() out of memory :-(\n", __FUNCTION__);
p@2550: atomic64_inc(&priv->rx_dropped);
p@2550: return;
p@2550: }
p@2550: skb->dev = dev;
p@2550: skb_reserve(skb, NET_IP_ALIGN);
p@2550: skb_copy_to_linear_data(skb, frame->data, len);
p@2550: skb_put(skb, len);
p@2550: skb->protocol = eth_type_trans(skb, dev);
p@2550: skb->ip_summed = CHECKSUM_UNNECESSARY;
p@2550: atomic64_add(len, &priv->rx_bytes);
p@2550: netif_rx(skb);
p@2550: }
p@2550:
p@2550: /**
p@2550: * Rx handler in EtherCAT operation mode
p@2550: * priv->ecdev should always be valid!
p@2550: */
p@2550: static void ec_poll(struct net_device *dev)
p@2550: {
p@2550: static size_t next = 0;
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: struct ccat_eth_frame *frame =
p@2550: ((struct ccat_eth_frame *)priv->rx_fifo.dma.virt) + next;
p@2550: if (frame->received) {
p@2550: ecdev_receive(priv->ecdev, frame->data,
p@2550: frame->length - CCATRXDESC_HEADER_LEN);
p@2550: frame->received = 0;
p@2550: ccat_eth_rx_fifo_add(frame, &priv->rx_fifo);
p@2550: next = (next + 1) % FIFO_LENGTH;
p@2550: } else {
p@2550: //TODO dev_warn(&dev->dev, "%s(): frame was not ready\n", __FUNCTION__);
p@2550: }
p@2550: }
p@2550:
p@2550: static netdev_tx_t ccat_eth_start_xmit(struct sk_buff *skb,
p@2550: struct net_device *dev)
p@2550: {
p@2550: static size_t next = 0;
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: struct ccat_eth_frame *const frame =
p@2550: ((struct ccat_eth_frame *)priv->tx_fifo.dma.virt);
p@2550: uint32_t addr_and_length;
p@2550:
p@2550: if (skb_is_nonlinear(skb)) {
p@2550: pr_warn("Non linear skb not supported -> drop frame.\n");
p@2550: atomic64_inc(&priv->tx_dropped);
p@2550: priv->kfree_skb_any(skb);
p@2550: return NETDEV_TX_OK;
p@2550: }
p@2550:
p@2550: if (skb->len > sizeof(frame->data)) {
p@2550: pr_warn("skb.len %llu exceeds dma buffer %llu -> drop frame.\n",
p@2550: (uint64_t) skb->len, (uint64_t) sizeof(frame->data));
p@2550: atomic64_inc(&priv->tx_dropped);
p@2550: priv->kfree_skb_any(skb);
p@2550: return NETDEV_TX_OK;
p@2550: }
p@2550:
p@2550: if (!frame[next].sent) {
p@2550: netdev_err(dev, "BUG! Tx Ring full when queue awake!\n");
p@2550: ccat_eth_tx_fifo_full(dev, &frame[next]);
p@2550: return NETDEV_TX_BUSY;
p@2550: }
p@2550:
p@2550: /* prepare frame in DMA memory */
p@2550: frame[next].sent = 0;
p@2550: frame[next].length = skb->len;
p@2550: memcpy(frame[next].data, skb->data, skb->len);
p@2550:
p@2550: priv->kfree_skb_any(skb);
p@2550:
p@2550: addr_and_length = 8 + (next * sizeof(*frame));
p@2550: addr_and_length +=
p@2551: ((frame[next].length + CCAT_DMA_FRAME_HEADER_LENGTH) / 8) << 24;
p@2550: iowrite32(addr_and_length, priv->reg.tx_fifo); /* add to DMA fifo */
p@2550: atomic64_add(frame[next].length, &priv->tx_bytes); /* update stats */
p@2550:
p@2550: next = (next + 1) % FIFO_LENGTH;
p@2550: /* stop queue if tx ring is full */
p@2550: if (!frame[next].sent) {
p@2550: ccat_eth_tx_fifo_full(dev, &frame[next]);
p@2550: }
p@2550: return NETDEV_TX_OK;
p@2550: }
p@2550:
p@2550: static int ccat_eth_stop(struct net_device *dev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: priv->stop_queue(dev);
p@2550: if (priv->poll_thread) {
p@2550: /* TODO care about smp context? */
p@2550: kthread_stop(priv->poll_thread);
p@2550: priv->poll_thread = NULL;
p@2550: }
p@2550: netdev_info(dev, "stopped.\n");
p@2550: return 0;
p@2550: }
p@2550:
p@2550: static void ccat_eth_link_down(struct net_device *dev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: priv->stop_queue(dev);
p@2550: priv->carrier_off(dev);
p@2550: netdev_info(dev, "NIC Link is Down\n");
p@2550: }
p@2550:
p@2550: static void ccat_eth_link_up(struct net_device *const dev)
p@2550: {
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: netdev_info(dev, "NIC Link is Up\n");
p@2550: /* TODO netdev_info(dev, "NIC Link is Up %u Mbps %s Duplex\n",
p@2550: speed == SPEED_100 ? 100 : 10,
p@2550: cmd.duplex == DUPLEX_FULL ? "Full" : "Half"); */
p@2550:
p@2550: ccat_eth_dma_fifo_reset(&priv->rx_fifo);
p@2550: ccat_eth_dma_fifo_reset(&priv->tx_fifo);
p@2550: ccat_eth_xmit_raw(dev, frameForwardEthernetFrames,
p@2550: sizeof(frameForwardEthernetFrames));
p@2550: priv->carrier_on(dev);
p@2550: priv->start_queue(dev);
p@2550: }
p@2550:
p@2550: /**
p@2550: * Function to transmit a raw buffer to the network (f.e. frameForwardEthernetFrames)
p@2550: * @dev a valid net_device
p@2550: * @data pointer to your raw buffer
p@2550: * @len number of bytes in the raw buffer to transmit
p@2550: */
p@2550: static void ccat_eth_xmit_raw(struct net_device *dev, const char *const data,
p@2550: size_t len)
p@2550: {
p@2550: struct sk_buff *skb = dev_alloc_skb(len);
p@2550: skb->dev = dev;
p@2550: skb_copy_to_linear_data(skb, data, len);
p@2550: skb_put(skb, len);
p@2550: ccat_eth_start_xmit(skb, dev);
p@2550: }
p@2550:
p@2550: /**
p@2550: * Since CCAT doesn't support interrupts until now, we have to poll
p@2550: * some status bits to recognize things like link change etc.
p@2550: */
p@2550: static int run_poll_thread(void *data)
p@2550: {
p@2550: struct net_device *const dev = (struct net_device *)data;
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: size_t link = 0;
p@2550:
p@2550: while (!kthread_should_stop()) {
p@2550: if (ccat_eth_priv_read_link_state(priv) != link) {
p@2550: link = !link;
p@2550: link ? ccat_eth_link_up(dev) : ccat_eth_link_down(dev);
p@2550: }
p@2550: usleep_range(POLL_DELAY_RANGE_USECS);
p@2550: }
p@2550: pr_debug("%s() stopped.\n", __FUNCTION__);
p@2550: return 0;
p@2550: }
p@2550:
p@2550: static int run_rx_thread(void *data)
p@2550: {
p@2550: struct net_device *const dev = (struct net_device *)data;
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550: struct ccat_eth_frame *frame = priv->rx_fifo.dma.virt;
p@2550: const struct ccat_eth_frame *const end = frame + FIFO_LENGTH;
p@2550:
p@2550: while (!kthread_should_stop()) {
p@2550: /* wait until frame was used by DMA for Rx */
p@2550: while (!kthread_should_stop() && !frame->received) {
p@2550: usleep_range(DMA_POLL_DELAY_RANGE_USECS);
p@2550: }
p@2550:
p@2550: /* can be NULL, if we are asked to stop! */
p@2550: if (frame->received) {
p@2550: ccat_eth_receive(dev, frame);
p@2550: frame->received = 0;
p@2550: ccat_eth_rx_fifo_add(frame, &priv->rx_fifo);
p@2550: }
p@2550: if (++frame >= end) {
p@2550: frame = priv->rx_fifo.dma.virt;
p@2550: }
p@2550: }
p@2550: pr_debug("%s() stopped.\n", __FUNCTION__);
p@2550: return 0;
p@2550: }
p@2550:
p@2550: /**
p@2550: * Polling of tx dma descriptors in ethernet operating mode
p@2550: */
p@2550: static int run_tx_thread(void *data)
p@2550: {
p@2550: struct net_device *const dev = (struct net_device *)data;
p@2550: struct ccat_eth_priv *const priv = netdev_priv(dev);
p@2550:
p@2550: set_current_state(TASK_INTERRUPTIBLE);
p@2550: while (!kthread_should_stop()) {
p@2550: const struct ccat_eth_frame *const frame = priv->next_tx_frame;
p@2550: if (frame) {
p@2550: while (!kthread_should_stop() && !frame->sent) {
p@2550: usleep_range(DMA_POLL_DELAY_RANGE_USECS);
p@2550: }
p@2550: }
p@2550: netif_wake_queue(dev);
p@2550: schedule();
p@2550: set_current_state(TASK_INTERRUPTIBLE);
p@2550: }
p@2550: set_current_state(TASK_RUNNING);
p@2550: pr_debug("%s() stopped.\n", __FUNCTION__);
p@2550: return 0;
p@2550: }