Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * This file is provided under a dual BSD/GPLv2 license.  When using or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *   redistributing this file, you may do so under either license.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *   GPL LICENSE SUMMARY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *   Copyright(c) 2012 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   Copyright (C) 2015 EMC Corporation. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *   This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *   it under the terms of version 2 of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *   BSD LICENSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *   Copyright(c) 2012 Intel Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *   Copyright (C) 2015 EMC Corporation. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *   Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *   modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *   are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *     * Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *       notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  *     * Redistributions in binary form must reproduce the above copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *       notice, this list of conditions and the following disclaimer in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *       the documentation and/or other materials provided with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *       distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *     * Neither the name of Intel Corporation nor the names of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  *       contributors may be used to endorse or promote products derived
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  *       from this software without specific prior written permission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  * PCIe NTB Network Linux driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * Contact Information:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Jon Mason <jon.mason@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #include <linux/ntb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include <linux/ntb_transport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) #define NTB_NETDEV_VER	"0.7"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) MODULE_DESCRIPTION(KBUILD_MODNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) MODULE_VERSION(NTB_NETDEV_VER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) MODULE_LICENSE("Dual BSD/GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) MODULE_AUTHOR("Intel Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) /* Time in usecs for tx resource reaper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static unsigned int tx_time = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) /* Number of descriptors to free before resuming tx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static unsigned int tx_start = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) /* Number of descriptors still available before stop upper layer tx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static unsigned int tx_stop = 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) struct ntb_netdev {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct net_device *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct ntb_transport_qp *qp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct timer_list tx_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) #define	NTB_TX_TIMEOUT_MS	1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) #define	NTB_RXQ_SIZE		100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static void ntb_netdev_event_handler(void *data, int link_is_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct net_device *ndev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	netdev_dbg(ndev, "Event %x, Link %x\n", link_is_up,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		   ntb_transport_link_query(dev->qp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (link_is_up) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		if (ntb_transport_link_query(dev->qp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			netif_carrier_on(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		netif_carrier_off(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static void ntb_netdev_rx_handler(struct ntb_transport_qp *qp, void *qp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				  void *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct net_device *ndev = qp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	skb = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	netdev_dbg(ndev, "%s: %d byte payload received\n", __func__, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (len < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		ndev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		ndev->stats.rx_length_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		goto enqueue_again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	skb_put(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	skb->protocol = eth_type_trans(skb, ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	skb->ip_summed = CHECKSUM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (netif_rx(skb) == NET_RX_DROP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		ndev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		ndev->stats.rx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		ndev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		ndev->stats.rx_bytes += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	skb = netdev_alloc_skb(ndev, ndev->mtu + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		ndev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		ndev->stats.rx_frame_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) enqueue_again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	rc = ntb_transport_rx_enqueue(qp, skb, skb->data, ndev->mtu + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		ndev->stats.rx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		ndev->stats.rx_fifo_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int __ntb_netdev_maybe_stop_tx(struct net_device *netdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 				      struct ntb_transport_qp *qp, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	struct ntb_netdev *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	netif_stop_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	/* Make sure to see the latest value of ntb_transport_tx_free_entry()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	 * since the queue was last started.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (likely(ntb_transport_tx_free_entry(qp) < size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		mod_timer(&dev->tx_timer, jiffies + usecs_to_jiffies(tx_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	netif_start_queue(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static int ntb_netdev_maybe_stop_tx(struct net_device *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				    struct ntb_transport_qp *qp, int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (netif_queue_stopped(ndev) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	    (ntb_transport_tx_free_entry(qp) >= size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	return __ntb_netdev_maybe_stop_tx(ndev, qp, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static void ntb_netdev_tx_handler(struct ntb_transport_qp *qp, void *qp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 				  void *data, int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	struct net_device *ndev = qp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	skb = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (!skb || !ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (len > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		ndev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		ndev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		ndev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		ndev->stats.tx_aborted_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (ntb_transport_tx_free_entry(dev->qp) >= tx_start) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		/* Make sure anybody stopping the queue after this sees the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		 * value of ntb_transport_tx_free_entry()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		if (netif_queue_stopped(ndev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			netif_wake_queue(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static netdev_tx_t ntb_netdev_start_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 					 struct net_device *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	ntb_netdev_maybe_stop_tx(ndev, dev->qp, tx_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	rc = ntb_transport_tx_enqueue(dev->qp, skb, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* check for next submit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	ntb_netdev_maybe_stop_tx(ndev, dev->qp, tx_stop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	ndev->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	ndev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return NETDEV_TX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static void ntb_netdev_tx_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	struct ntb_netdev *dev = from_timer(dev, t, tx_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	struct net_device *ndev = dev->ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	if (ntb_transport_tx_free_entry(dev->qp) < tx_stop) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		mod_timer(&dev->tx_timer, jiffies + usecs_to_jiffies(tx_time));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		/* Make sure anybody stopping the queue after this sees the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		 * value of ntb_transport_tx_free_entry()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		smp_mb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (netif_queue_stopped(ndev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			netif_wake_queue(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) static int ntb_netdev_open(struct net_device *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	int rc, i, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	/* Add some empty rx bufs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	for (i = 0; i < NTB_RXQ_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		skb = netdev_alloc_skb(ndev, ndev->mtu + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		rc = ntb_transport_rx_enqueue(dev->qp, skb, skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 					      ndev->mtu + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	timer_setup(&dev->tx_timer, ntb_netdev_tx_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	netif_carrier_off(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	ntb_transport_link_up(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	netif_start_queue(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	while ((skb = ntb_transport_rx_remove(dev->qp, &len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int ntb_netdev_close(struct net_device *ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	ntb_transport_link_down(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	while ((skb = ntb_transport_rx_remove(dev->qp, &len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	del_timer_sync(&dev->tx_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) static int ntb_netdev_change_mtu(struct net_device *ndev, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	int len, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	if (new_mtu > ntb_transport_max_size(dev->qp) - ETH_HLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!netif_running(ndev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		ndev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* Bring down the link and dispose of posted rx entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	ntb_transport_link_down(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (ndev->mtu < new_mtu) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		for (i = 0; (skb = ntb_transport_rx_remove(dev->qp, &len)); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 			dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		for (; i; i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			skb = netdev_alloc_skb(ndev, new_mtu + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 				rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 			rc = ntb_transport_rx_enqueue(dev->qp, skb, skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 						      new_mtu + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 			if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 				dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 				goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	ndev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	ntb_transport_link_up(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	ntb_transport_link_down(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	while ((skb = ntb_transport_rx_remove(dev->qp, &len)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	netdev_err(ndev, "Error changing MTU, device inoperable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) static const struct net_device_ops ntb_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.ndo_open = ntb_netdev_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	.ndo_stop = ntb_netdev_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	.ndo_start_xmit = ntb_netdev_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	.ndo_change_mtu = ntb_netdev_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	.ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static void ntb_get_drvinfo(struct net_device *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 			    struct ethtool_drvinfo *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	strlcpy(info->version, NTB_NETDEV_VER, sizeof(info->version));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	strlcpy(info->bus_info, pci_name(dev->pdev), sizeof(info->bus_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static int ntb_get_link_ksettings(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 				  struct ethtool_link_ksettings *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	ethtool_link_ksettings_zero_link_mode(cmd, supported);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	ethtool_link_ksettings_add_link_mode(cmd, supported, Backplane);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ethtool_link_ksettings_zero_link_mode(cmd, advertising);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	ethtool_link_ksettings_add_link_mode(cmd, advertising, Backplane);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	cmd->base.speed = SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	cmd->base.duplex = DUPLEX_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	cmd->base.port = PORT_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	cmd->base.phy_address = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	cmd->base.autoneg = AUTONEG_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static const struct ethtool_ops ntb_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	.get_drvinfo = ntb_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	.get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	.get_link_ksettings = ntb_get_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) static const struct ntb_queue_handlers ntb_netdev_handlers = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	.tx_handler = ntb_netdev_tx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	.rx_handler = ntb_netdev_rx_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	.event_handler = ntb_netdev_event_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) static int ntb_netdev_probe(struct device *client_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	struct ntb_dev *ntb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	struct net_device *ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	struct pci_dev *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	struct ntb_netdev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	ntb = dev_ntb(client_dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	pdev = ntb->pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	ndev = alloc_etherdev(sizeof(*dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (!ndev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	SET_NETDEV_DEV(ndev, client_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	dev->ndev = ndev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	dev->pdev = pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	ndev->features = NETIF_F_HIGHDMA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	ndev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	ndev->hw_features = ndev->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	ndev->watchdog_timeo = msecs_to_jiffies(NTB_TX_TIMEOUT_MS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	eth_random_addr(ndev->perm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	memcpy(ndev->dev_addr, ndev->perm_addr, ndev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	ndev->netdev_ops = &ntb_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	ndev->ethtool_ops = &ntb_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	ndev->min_mtu = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	ndev->max_mtu = ETH_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	dev->qp = ntb_transport_create_queue(ndev, client_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 					     &ntb_netdev_handlers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (!dev->qp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	ndev->mtu = ntb_transport_max_size(dev->qp) - ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	rc = register_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		goto err1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	dev_set_drvdata(client_dev, ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	dev_info(&pdev->dev, "%s created\n", ndev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) err1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	ntb_transport_free_queue(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	free_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) static void ntb_netdev_remove(struct device *client_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	struct net_device *ndev = dev_get_drvdata(client_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	struct ntb_netdev *dev = netdev_priv(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	unregister_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 	ntb_transport_free_queue(dev->qp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	free_netdev(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static struct ntb_transport_client ntb_netdev_client = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	.driver.name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	.driver.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	.probe = ntb_netdev_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	.remove = ntb_netdev_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static int __init ntb_netdev_init_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	rc = ntb_transport_register_client_dev(KBUILD_MODNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	return ntb_transport_register_client(&ntb_netdev_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) module_init(ntb_netdev_init_module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static void __exit ntb_netdev_exit_module(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 	ntb_transport_unregister_client(&ntb_netdev_client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	ntb_transport_unregister_client_dev(KBUILD_MODNAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) module_exit(ntb_netdev_exit_module);