1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2018 Solarflare Communications Inc.
5 * Copyright 2019-2020 Xilinx Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation, incorporated herein by reference.
11 #include "net_driver.h"
12 #include "mcdi_port_common.h"
13 #include "mcdi_functions.h"
14 #include "efx_common.h"
15 #include "efx_channels.h"
16 #include "tx_common.h"
17 #include "ef100_netdev.h"
18 #include "ef100_ethtool.h"
19 #include "efx_common.h"
20 #include "nic_common.h"
21 #include "ef100_nic.h"
23 #include "ef100_regs.h"
24 #include "mcdi_filters.h"
25 #include "rx_common.h"
27 static void ef100_update_name(struct efx_nic *efx)
29 strcpy(efx->name, efx->net_dev->name);
32 /* Initiate a packet transmission. We use one channel per CPU
33 * (sharing when we have more CPUs than channels).
35 * Context: non-blocking.
36 * Note that returning anything other than NETDEV_TX_OK will cause the
39 static netdev_tx_t ef100_hard_start_xmit(struct sk_buff *skb,
40 struct net_device *net_dev)
42 struct efx_nic *efx = netdev_priv(net_dev);
43 struct efx_tx_queue *tx_queue;
44 struct efx_channel *channel;
47 channel = efx_get_tx_channel(efx, skb_get_queue_mapping(skb));
48 netif_vdbg(efx, tx_queued, efx->net_dev,
49 "%s len %d data %d channel %d\n", __func__,
50 skb->len, skb->data_len, channel->channel);
51 if (!efx->n_channels || !efx->n_tx_channels || !channel) {
52 netif_stop_queue(net_dev);
56 tx_queue = &channel->tx_queue[0];
57 rc = ef100_enqueue_skb(tx_queue, skb);
62 net_dev->stats.tx_dropped++;
66 static const struct net_device_ops ef100_netdev_ops = {
67 .ndo_start_xmit = ef100_hard_start_xmit,
70 /* Netdev registration
72 int ef100_netdev_event(struct notifier_block *this,
73 unsigned long event, void *ptr)
75 struct efx_nic *efx = container_of(this, struct efx_nic, netdev_notifier);
76 struct net_device *net_dev = netdev_notifier_info_to_dev(ptr);
78 if (netdev_priv(net_dev) == efx && event == NETDEV_CHANGENAME)
79 ef100_update_name(efx);
84 int ef100_register_netdev(struct efx_nic *efx)
86 struct net_device *net_dev = efx->net_dev;
89 net_dev->watchdog_timeo = 5 * HZ;
90 net_dev->irq = efx->pci_dev->irq;
91 net_dev->netdev_ops = &ef100_netdev_ops;
92 net_dev->min_mtu = EFX_MIN_MTU;
93 net_dev->max_mtu = EFX_MAX_MTU;
94 net_dev->ethtool_ops = &ef100_ethtool_ops;
98 rc = dev_alloc_name(net_dev, net_dev->name);
101 ef100_update_name(efx);
103 rc = register_netdevice(net_dev);
107 /* Always start with carrier off; PHY events will detect the link */
108 netif_carrier_off(net_dev);
110 efx->state = STATE_READY;
112 efx_init_mcdi_logging(efx);
118 netif_err(efx, drv, efx->net_dev, "could not register net dev\n");
122 void ef100_unregister_netdev(struct efx_nic *efx)
124 if (efx_dev_registered(efx)) {
125 efx_fini_mcdi_logging(efx);
126 efx->state = STATE_UNINIT;
127 unregister_netdev(efx->net_dev);