fp@2589: /** fp@2589: Network Driver for Beckhoff CCAT communication controller fp@2589: Copyright (C) 2014 Beckhoff Automation GmbH fp@2589: Author: Patrick Bruenn fp@2589: fp@2589: This program is free software; you can redistribute it and/or modify fp@2589: it under the terms of the GNU General Public License as published by fp@2589: the Free Software Foundation; either version 2 of the License, or fp@2589: (at your option) any later version. fp@2589: fp@2589: This program is distributed in the hope that it will be useful, fp@2589: but WITHOUT ANY WARRANTY; without even the implied warranty of fp@2589: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fp@2589: GNU General Public License for more details. fp@2589: fp@2589: You should have received a copy of the GNU General Public License along fp@2589: with this program; if not, write to the Free Software Foundation, Inc., fp@2589: 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. fp@2589: */ fp@2589: fp@2589: #include fp@2589: #include fp@2589: #include fp@2589: #include fp@2589: fp@2589: #include "module.h" fp@2589: #include "netdev.h" fp@2589: fp@2589: /** fp@2589: * EtherCAT frame to enable forwarding on EtherCAT Terminals fp@2589: */ fp@2589: static const u8 frameForwardEthernetFrames[] = { fp@2589: 0x01, 0x01, 0x05, 0x01, 0x00, 0x00, fp@2589: 0x00, 0x1b, 0x21, 0x36, 0x1b, 0xce, fp@2589: 0x88, 0xa4, 0x0e, 0x10, fp@2589: 0x08, fp@2589: 0x00, fp@2589: 0x00, 0x00, fp@2589: 0x00, 0x01, fp@2589: 0x02, 0x00, fp@2589: 0x00, 0x00, fp@2589: 0x00, 0x00, fp@2589: 0x00, 0x00 fp@2589: }; fp@2589: fp@2589: #define FIFO_LENGTH 64 fp@2589: #define POLL_TIME ktime_set(0, 100 * NSEC_PER_USEC) fp@2589: fp@2589: /** fp@2589: * Helper to check if frame in tx dma memory was already marked as sent by CCAT fp@2589: */ fp@2589: static inline bool ccat_eth_frame_sent(const struct ccat_eth_frame *const frame) fp@2589: { fp@2589: return le32_to_cpu(frame->tx_flags) & CCAT_FRAME_SENT; fp@2589: } fp@2589: fp@2589: /** fp@2589: * Helper to check if frame in tx dma memory was already marked as sent by CCAT fp@2589: */ fp@2589: static inline bool ccat_eth_frame_received(const struct ccat_eth_frame *const fp@2589: frame) fp@2589: { fp@2589: return le32_to_cpu(frame->rx_flags) & CCAT_FRAME_RECEIVED; fp@2589: } fp@2589: fp@2589: static void ecdev_kfree_skb_any(struct sk_buff *skb) fp@2589: { fp@2589: /* never release a skb in EtherCAT mode */ fp@2589: } fp@2589: fp@2589: static bool ecdev_carrier_ok(const struct net_device *const netdev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(netdev); fp@2589: return ecdev_get_link(priv->ecdev); fp@2589: } fp@2589: fp@2589: static void ecdev_carrier_on(struct net_device *const netdev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(netdev); fp@2589: ecdev_set_link(priv->ecdev, 1); fp@2589: } fp@2589: fp@2589: static void ecdev_carrier_off(struct net_device *const netdev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(netdev); fp@2589: ecdev_set_link(priv->ecdev, 0); fp@2589: } fp@2589: fp@2589: static void ecdev_nop(struct net_device *const netdev) fp@2589: { fp@2589: /* dummy called if nothing has to be done in EtherCAT operation mode */ fp@2589: } fp@2589: fp@2589: static void unregister_ecdev(struct net_device *const netdev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(netdev); fp@2589: ecdev_close(priv->ecdev); fp@2589: ecdev_withdraw(priv->ecdev); fp@2589: } fp@2589: fp@2589: static void ccat_eth_fifo_inc(struct ccat_eth_dma_fifo *fifo) fp@2589: { fp@2589: if (++fifo->next >= fifo->end) fp@2589: fifo->next = fifo->dma.virt; fp@2589: } fp@2589: fp@2589: typedef void (*fifo_add_function) (struct ccat_eth_dma_fifo *, fp@2589: struct ccat_eth_frame *); fp@2589: fp@2589: static void ccat_eth_rx_fifo_add(struct ccat_eth_dma_fifo *fifo, fp@2589: struct ccat_eth_frame *frame) fp@2589: { fp@2589: const size_t offset = ((void *)(frame) - fifo->dma.virt); fp@2589: const u32 addr_and_length = (1 << 31) | offset; fp@2589: fp@2589: frame->rx_flags = cpu_to_le32(0); fp@2589: iowrite32(addr_and_length, fifo->reg); fp@2589: } fp@2589: fp@2589: static void ccat_eth_tx_fifo_add_free(struct ccat_eth_dma_fifo *fifo, fp@2589: struct ccat_eth_frame *frame) fp@2589: { fp@2589: /* mark frame as ready to use for tx */ fp@2589: frame->tx_flags = cpu_to_le32(CCAT_FRAME_SENT); fp@2589: } fp@2589: fp@2589: static void ccat_eth_dma_fifo_reset(struct ccat_eth_dma_fifo *fifo) fp@2589: { fp@2589: /* reset hw fifo */ fp@2589: iowrite32(0, fifo->reg + 0x8); fp@2589: wmb(); fp@2589: fp@2589: if (fifo->add) { fp@2589: fifo->next = fifo->dma.virt; fp@2589: do { fp@2589: fifo->add(fifo, fifo->next); fp@2589: ccat_eth_fifo_inc(fifo); fp@2589: } while (fifo->next != fifo->dma.virt); fp@2589: } fp@2589: } fp@2589: fp@2589: static int ccat_eth_dma_fifo_init(struct ccat_eth_dma_fifo *fifo, fp@2589: void __iomem * const fifo_reg, fp@2589: fifo_add_function add, size_t channel, fp@2589: struct ccat_eth_priv *const priv) fp@2589: { fp@2589: if (0 != fp@2589: ccat_dma_init(&fifo->dma, channel, priv->ccatdev->bar[2].ioaddr, fp@2589: &priv->ccatdev->pdev->dev)) { fp@2589: pr_info("init DMA%llu memory failed.\n", (u64) channel); fp@2589: return -1; fp@2589: } fp@2589: fifo->add = add; fp@2589: fifo->end = ((struct ccat_eth_frame *)fifo->dma.virt) + FIFO_LENGTH; fp@2589: fifo->reg = fifo_reg; fp@2589: return 0; fp@2589: } fp@2589: fp@2589: /** fp@2589: * Stop both (Rx/Tx) DMA fifo's and free related management structures fp@2589: */ fp@2589: static void ccat_eth_priv_free_dma(struct ccat_eth_priv *priv) fp@2589: { fp@2589: /* reset hw fifo's */ fp@2589: iowrite32(0, priv->rx_fifo.reg + 0x8); fp@2589: iowrite32(0, priv->tx_fifo.reg + 0x8); fp@2589: wmb(); fp@2589: fp@2589: /* release dma */ fp@2589: ccat_dma_free(&priv->rx_fifo.dma); fp@2589: ccat_dma_free(&priv->tx_fifo.dma); fp@2589: } fp@2589: fp@2589: /** fp@2589: * Initalizes both (Rx/Tx) DMA fifo's and related management structures fp@2589: */ fp@2589: static int ccat_eth_priv_init_dma(struct ccat_eth_priv *priv) fp@2589: { fp@2589: if (ccat_eth_dma_fifo_init fp@2589: (&priv->rx_fifo, priv->reg.rx_fifo, ccat_eth_rx_fifo_add, fp@2589: priv->info.rx_dma_chan, priv)) { fp@2589: pr_warn("init Rx DMA fifo failed.\n"); fp@2589: return -1; fp@2589: } fp@2589: fp@2589: if (ccat_eth_dma_fifo_init fp@2589: (&priv->tx_fifo, priv->reg.tx_fifo, ccat_eth_tx_fifo_add_free, fp@2589: priv->info.tx_dma_chan, priv)) { fp@2589: pr_warn("init Tx DMA fifo failed.\n"); fp@2589: ccat_dma_free(&priv->rx_fifo.dma); fp@2589: return -1; fp@2589: } fp@2589: fp@2589: /* disable MAC filter */ fp@2589: iowrite8(0, priv->reg.mii + 0x8 + 6); fp@2589: wmb(); fp@2589: return 0; fp@2589: } fp@2589: fp@2589: /** fp@2589: * Initializes the CCat... members of the ccat_eth_priv structure. fp@2589: * Call this function only if info and ioaddr are already initialized! fp@2589: */ fp@2589: static void ccat_eth_priv_init_mappings(struct ccat_eth_priv *priv) fp@2589: { fp@2589: struct ccat_mac_infoblock offsets; fp@2589: void __iomem *const func_base = fp@2589: priv->ccatdev->bar[0].ioaddr + priv->info.addr; fp@2589: fp@2589: memcpy_fromio(&offsets, func_base, sizeof(offsets)); fp@2589: priv->reg.mii = func_base + offsets.mii; fp@2589: priv->reg.tx_fifo = func_base + offsets.tx_fifo; fp@2589: priv->reg.rx_fifo = func_base + offsets.tx_fifo + 0x10; fp@2589: priv->reg.mac = func_base + offsets.mac; fp@2589: priv->reg.rx_mem = func_base + offsets.rx_mem; fp@2589: priv->reg.tx_mem = func_base + offsets.tx_mem; fp@2589: priv->reg.misc = func_base + offsets.misc; fp@2589: } fp@2589: fp@2589: static netdev_tx_t ccat_eth_start_xmit(struct sk_buff *skb, fp@2589: struct net_device *dev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: struct ccat_eth_dma_fifo *const fifo = &priv->tx_fifo; fp@2589: u32 addr_and_length; fp@2589: fp@2589: if (skb_is_nonlinear(skb)) { fp@2589: pr_warn("Non linear skb not supported -> drop frame.\n"); fp@2589: atomic64_inc(&priv->tx_dropped); fp@2589: priv->kfree_skb_any(skb); fp@2589: return NETDEV_TX_OK; fp@2589: } fp@2589: fp@2589: if (skb->len > sizeof(fifo->next->data)) { fp@2589: pr_warn("skb.len %llu exceeds dma buffer %llu -> drop frame.\n", fp@2589: (u64) skb->len, (u64) sizeof(fifo->next->data)); fp@2589: atomic64_inc(&priv->tx_dropped); fp@2589: priv->kfree_skb_any(skb); fp@2589: return NETDEV_TX_OK; fp@2589: } fp@2589: fp@2589: if (!ccat_eth_frame_sent(fifo->next)) { fp@2589: netdev_err(dev, "BUG! Tx Ring full when queue awake!\n"); fp@2589: priv->stop_queue(priv->netdev); fp@2589: return NETDEV_TX_BUSY; fp@2589: } fp@2589: fp@2589: /* prepare frame in DMA memory */ fp@2589: fifo->next->tx_flags = cpu_to_le32(0); fp@2589: fifo->next->length = cpu_to_le16(skb->len); fp@2589: memcpy(fifo->next->data, skb->data, skb->len); fp@2589: fp@2589: /* Queue frame into CCAT TX-FIFO, CCAT ignores the first 8 bytes of the tx descriptor */ fp@2589: addr_and_length = offsetof(struct ccat_eth_frame, length); fp@2589: addr_and_length += ((void *)fifo->next - fifo->dma.virt); fp@2589: addr_and_length += ((skb->len + CCAT_ETH_FRAME_HEAD_LEN) / 8) << 24; fp@2589: iowrite32(addr_and_length, priv->reg.tx_fifo); fp@2589: fp@2589: /* update stats */ fp@2589: atomic64_add(skb->len, &priv->tx_bytes); fp@2589: fp@2589: priv->kfree_skb_any(skb); fp@2589: fp@2589: ccat_eth_fifo_inc(fifo); fp@2589: /* stop queue if tx ring is full */ fp@2589: if (!ccat_eth_frame_sent(fifo->next)) { fp@2589: priv->stop_queue(priv->netdev); fp@2589: } fp@2589: return NETDEV_TX_OK; fp@2589: } fp@2589: fp@2589: /** fp@2589: * Function to transmit a raw buffer to the network (f.e. frameForwardEthernetFrames) fp@2589: * @dev a valid net_device fp@2589: * @data pointer to your raw buffer fp@2589: * @len number of bytes in the raw buffer to transmit fp@2589: */ fp@2589: static void ccat_eth_xmit_raw(struct net_device *dev, const char *const data, fp@2589: size_t len) fp@2589: { fp@2589: struct sk_buff *skb = dev_alloc_skb(len); fp@2589: fp@2589: skb->dev = dev; fp@2589: skb_copy_to_linear_data(skb, data, len); fp@2589: skb_put(skb, len); fp@2589: ccat_eth_start_xmit(skb, dev); fp@2589: } fp@2589: fp@2589: static void ccat_eth_receive(struct net_device *const dev, fp@2589: const void *const data, const size_t len) fp@2589: { fp@2589: struct sk_buff *const skb = dev_alloc_skb(len + NET_IP_ALIGN); fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: fp@2589: if (!skb) { fp@2589: pr_info("%s() out of memory :-(\n", __FUNCTION__); fp@2589: atomic64_inc(&priv->rx_dropped); fp@2589: return; fp@2589: } fp@2589: skb->dev = dev; fp@2589: skb_reserve(skb, NET_IP_ALIGN); fp@2589: skb_copy_to_linear_data(skb, data, len); fp@2589: skb_put(skb, len); fp@2589: skb->protocol = eth_type_trans(skb, dev); fp@2589: skb->ip_summed = CHECKSUM_UNNECESSARY; fp@2589: atomic64_add(len, &priv->rx_bytes); fp@2589: netif_rx(skb); fp@2589: } fp@2589: fp@2589: static void ccat_eth_link_down(struct net_device *const dev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: fp@2589: priv->stop_queue(dev); fp@2589: priv->carrier_off(dev); fp@2589: netdev_info(dev, "NIC Link is Down\n"); fp@2589: } fp@2589: fp@2589: static void ccat_eth_link_up(struct net_device *const dev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: fp@2589: netdev_info(dev, "NIC Link is Up\n"); fp@2589: /* TODO netdev_info(dev, "NIC Link is Up %u Mbps %s Duplex\n", fp@2589: speed == SPEED_100 ? 100 : 10, fp@2589: cmd.duplex == DUPLEX_FULL ? "Full" : "Half"); */ fp@2589: fp@2589: ccat_eth_dma_fifo_reset(&priv->rx_fifo); fp@2589: ccat_eth_dma_fifo_reset(&priv->tx_fifo); fp@2589: fp@2589: /* TODO reset CCAT MAC register */ fp@2589: fp@2589: ccat_eth_xmit_raw(dev, frameForwardEthernetFrames, fp@2589: sizeof(frameForwardEthernetFrames)); fp@2589: priv->carrier_on(dev); fp@2589: priv->start_queue(dev); fp@2589: } fp@2589: fp@2589: /** fp@2589: * Read link state from CCAT hardware fp@2589: * @return 1 if link is up, 0 if not fp@2589: */ fp@2589: inline static size_t ccat_eth_priv_read_link_state(const struct ccat_eth_priv fp@2589: *const priv) fp@2589: { fp@2589: return (1 << 24) == (ioread32(priv->reg.mii + 0x8 + 4) & (1 << 24)); fp@2589: } fp@2589: fp@2589: /** fp@2589: * Poll for link state changes fp@2589: */ fp@2589: static void poll_link(struct ccat_eth_priv *const priv) fp@2589: { fp@2589: const size_t link = ccat_eth_priv_read_link_state(priv); fp@2589: fp@2589: if (link != priv->carrier_ok(priv->netdev)) { fp@2589: if (link) fp@2589: ccat_eth_link_up(priv->netdev); fp@2589: else fp@2589: ccat_eth_link_down(priv->netdev); fp@2589: } fp@2589: } fp@2589: fp@2589: /** fp@2589: * Poll for available rx dma descriptors in ethernet operating mode fp@2589: */ fp@2589: static void poll_rx(struct ccat_eth_priv *const priv) fp@2589: { fp@2589: static const size_t overhead = CCAT_ETH_FRAME_HEAD_LEN - 4; fp@2589: struct ccat_eth_dma_fifo *const fifo = &priv->rx_fifo; fp@2589: fp@2589: /* TODO omit possible deadlock in situations with heavy traffic */ fp@2589: while (ccat_eth_frame_received(fifo->next)) { fp@2589: const size_t len = le16_to_cpu(fifo->next->length) - overhead; fp@2589: if (priv->ecdev) { fp@2589: ecdev_receive(priv->ecdev, fifo->next->data, len); fp@2589: } else { fp@2589: ccat_eth_receive(priv->netdev, fifo->next->data, len); fp@2589: } fp@2589: ccat_eth_rx_fifo_add(fifo, fifo->next); fp@2589: ccat_eth_fifo_inc(fifo); fp@2589: } fp@2589: } fp@2589: fp@2589: static void ec_poll_rx(struct net_device *dev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: poll_rx(priv); fp@2589: } fp@2589: fp@2589: /** fp@2589: * Poll for available tx dma descriptors in ethernet operating mode fp@2589: */ fp@2589: static void poll_tx(struct ccat_eth_priv *const priv) fp@2589: { fp@2589: if (ccat_eth_frame_sent(priv->tx_fifo.next)) { fp@2589: netif_wake_queue(priv->netdev); fp@2589: } fp@2589: } fp@2589: fp@2589: /** fp@2589: * Since CCAT doesn't support interrupts until now, we have to poll fp@2589: * some status bits to recognize things like link change etc. fp@2589: */ fp@2589: static enum hrtimer_restart poll_timer_callback(struct hrtimer *timer) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = fp@2589: container_of(timer, struct ccat_eth_priv, poll_timer); fp@2589: fp@2589: poll_link(priv); fp@2589: if(!priv->ecdev) { fp@2589: poll_rx(priv); fp@2589: poll_tx(priv); fp@2589: } fp@2589: hrtimer_forward_now(timer, POLL_TIME); fp@2589: return HRTIMER_RESTART; fp@2589: } fp@2589: fp@2589: static struct rtnl_link_stats64 *ccat_eth_get_stats64(struct net_device *dev, struct rtnl_link_stats64 fp@2589: *storage) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: struct ccat_mac_register mac; fp@2589: memcpy_fromio(&mac, priv->reg.mac, sizeof(mac)); fp@2589: storage->rx_packets = mac.rx_frames; /* total packets received */ fp@2589: storage->tx_packets = mac.tx_frames; /* total packets transmitted */ fp@2589: storage->rx_bytes = atomic64_read(&priv->rx_bytes); /* total bytes received */ fp@2589: storage->tx_bytes = atomic64_read(&priv->tx_bytes); /* total bytes transmitted */ fp@2589: storage->rx_errors = mac.frame_len_err + mac.rx_mem_full + mac.crc_err + mac.rx_err; /* bad packets received */ fp@2589: storage->tx_errors = mac.tx_mem_full; /* packet transmit problems */ fp@2589: storage->rx_dropped = atomic64_read(&priv->rx_dropped); /* no space in linux buffers */ fp@2589: storage->tx_dropped = atomic64_read(&priv->tx_dropped); /* no space available in linux */ fp@2589: //TODO __u64 multicast; /* multicast packets received */ fp@2589: //TODO __u64 collisions; fp@2589: fp@2589: /* detailed rx_errors: */ fp@2589: storage->rx_length_errors = mac.frame_len_err; fp@2589: storage->rx_over_errors = mac.rx_mem_full; /* receiver ring buff overflow */ fp@2589: storage->rx_crc_errors = mac.crc_err; /* recved pkt with crc error */ fp@2589: storage->rx_frame_errors = mac.rx_err; /* recv'd frame alignment error */ fp@2589: storage->rx_fifo_errors = mac.rx_mem_full; /* recv'r fifo overrun */ fp@2589: //TODO __u64 rx_missed_errors; /* receiver missed packet */ fp@2589: fp@2589: /* detailed tx_errors */ fp@2589: //TODO __u64 tx_aborted_errors; fp@2589: //TODO __u64 tx_carrier_errors; fp@2589: //TODO __u64 tx_fifo_errors; fp@2589: //TODO __u64 tx_heartbeat_errors; fp@2589: //TODO __u64 tx_window_errors; fp@2589: fp@2589: /* for cslip etc */ fp@2589: //TODO __u64 rx_compressed; fp@2589: //TODO __u64 tx_compressed; fp@2589: return storage; fp@2589: } fp@2589: fp@2589: static int ccat_eth_open(struct net_device *dev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: fp@2589: hrtimer_init(&priv->poll_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); fp@2589: priv->poll_timer.function = poll_timer_callback; fp@2589: hrtimer_start(&priv->poll_timer, POLL_TIME, HRTIMER_MODE_REL); fp@2589: return 0; fp@2589: } fp@2589: fp@2589: static int ccat_eth_stop(struct net_device *dev) fp@2589: { fp@2589: struct ccat_eth_priv *const priv = netdev_priv(dev); fp@2589: fp@2589: priv->stop_queue(dev); fp@2589: hrtimer_cancel(&priv->poll_timer); fp@2589: return 0; fp@2589: } fp@2589: fp@2589: static const struct net_device_ops ccat_eth_netdev_ops = { fp@2589: .ndo_get_stats64 = ccat_eth_get_stats64, fp@2589: .ndo_open = ccat_eth_open, fp@2589: .ndo_start_xmit = ccat_eth_start_xmit, fp@2589: .ndo_stop = ccat_eth_stop, fp@2589: }; fp@2589: fp@2589: struct ccat_eth_priv *ccat_eth_init(const struct ccat_device *const ccatdev, fp@2589: const void __iomem * const addr) fp@2589: { fp@2589: struct ccat_eth_priv *priv; fp@2589: struct net_device *const netdev = alloc_etherdev(sizeof(*priv)); fp@2589: fp@2589: priv = netdev_priv(netdev); fp@2589: priv->netdev = netdev; fp@2589: priv->ccatdev = ccatdev; fp@2589: fp@2589: /* ccat register mappings */ fp@2589: memcpy_fromio(&priv->info, addr, sizeof(priv->info)); fp@2589: ccat_eth_priv_init_mappings(priv); fp@2589: fp@2589: if (ccat_eth_priv_init_dma(priv)) { fp@2589: pr_warn("%s(): DMA initialization failed.\n", __FUNCTION__); fp@2589: free_netdev(netdev); fp@2589: return NULL; fp@2589: } fp@2589: fp@2589: /* init netdev with MAC and stack callbacks */ fp@2589: memcpy_fromio(netdev->dev_addr, priv->reg.mii + 8, netdev->addr_len); fp@2589: netdev->netdev_ops = &ccat_eth_netdev_ops; fp@2589: fp@2589: /* use as EtherCAT device? */ fp@2589: priv->ecdev = ecdev_offer(netdev, ec_poll_rx, THIS_MODULE); fp@2589: if (priv->ecdev) { fp@2589: priv->carrier_off = ecdev_carrier_off; fp@2589: priv->carrier_ok = ecdev_carrier_ok; fp@2589: priv->carrier_on = ecdev_carrier_on; fp@2589: priv->kfree_skb_any = ecdev_kfree_skb_any; fp@2589: priv->start_queue = ecdev_nop; fp@2589: priv->stop_queue = ecdev_nop; fp@2589: priv->unregister = unregister_ecdev; fp@2589: fp@2589: priv->carrier_off(netdev); fp@2589: if (ecdev_open(priv->ecdev)) { fp@2589: pr_info("unable to register network device.\n"); fp@2589: ecdev_withdraw(priv->ecdev); fp@2589: ccat_eth_priv_free_dma(priv); fp@2589: free_netdev(netdev); fp@2589: return NULL; fp@2589: } fp@2589: return priv; fp@2589: } fp@2589: fp@2589: /* EtherCAT disabled -> prepare normal ethernet mode */ fp@2589: priv->carrier_off = netif_carrier_off; fp@2589: priv->carrier_ok = netif_carrier_ok; fp@2589: priv->carrier_on = netif_carrier_on; fp@2589: priv->kfree_skb_any = dev_kfree_skb_any; fp@2589: priv->start_queue = netif_start_queue; fp@2589: priv->stop_queue = netif_stop_queue; fp@2589: priv->unregister = unregister_netdev; fp@2589: fp@2589: priv->carrier_off(netdev); fp@2589: if (register_netdev(netdev)) { fp@2589: pr_info("unable to register network device.\n"); fp@2589: ccat_eth_priv_free_dma(priv); fp@2589: free_netdev(netdev); fp@2589: return NULL; fp@2589: } fp@2589: pr_info("registered %s as network device.\n", netdev->name); fp@2589: return priv; fp@2589: } fp@2589: fp@2589: void ccat_eth_remove(struct ccat_eth_priv *const priv) fp@2589: { fp@2589: priv->unregister(priv->netdev); fp@2589: ccat_eth_priv_free_dma(priv); fp@2589: free_netdev(priv->netdev); fp@2589: }