1 // SPDX-License-Identifier: GPL-2.0 1 // SPDX-License-Identifier: GPL-2.0 2 2 3 #include <linux/netdevice.h> 3 #include <linux/netdevice.h> 4 #include <linux/mctp.h> 4 #include <linux/mctp.h> 5 #include <linux/if_arp.h> 5 #include <linux/if_arp.h> 6 6 7 #include <net/mctp.h> << 8 #include <net/mctpdevice.h> 7 #include <net/mctpdevice.h> 9 #include <net/pkt_sched.h> 8 #include <net/pkt_sched.h> 10 9 11 #include "utils.h" 10 #include "utils.h" 12 11 13 static netdev_tx_t mctp_test_dev_tx(struct sk_ 12 static netdev_tx_t mctp_test_dev_tx(struct sk_buff *skb, 14 struct net 13 struct net_device *ndev) 15 { 14 { 16 kfree_skb(skb); 15 kfree_skb(skb); 17 return NETDEV_TX_OK; 16 return NETDEV_TX_OK; 18 } 17 } 19 18 20 static const struct net_device_ops mctp_test_n 19 static const struct net_device_ops mctp_test_netdev_ops = { 21 .ndo_start_xmit = mctp_test_dev_tx, 20 .ndo_start_xmit = mctp_test_dev_tx, 22 }; 21 }; 23 22 24 static void mctp_test_dev_setup(struct net_dev 23 static void mctp_test_dev_setup(struct net_device *ndev) 25 { 24 { 26 ndev->type = ARPHRD_MCTP; 25 ndev->type = ARPHRD_MCTP; 27 ndev->mtu = MCTP_DEV_TEST_MTU; 26 ndev->mtu = MCTP_DEV_TEST_MTU; 28 ndev->hard_header_len = 0; 27 ndev->hard_header_len = 0; 29 ndev->addr_len = 0; 28 ndev->addr_len = 0; 30 ndev->tx_queue_len = DEFAULT_TX_QUEUE_ 29 ndev->tx_queue_len = DEFAULT_TX_QUEUE_LEN; 31 ndev->flags = IFF_NOARP; 30 ndev->flags = IFF_NOARP; 32 ndev->netdev_ops = &mctp_test_netdev_o 31 ndev->netdev_ops = &mctp_test_netdev_ops; 33 ndev->needs_free_netdev = true; 32 ndev->needs_free_netdev = true; 34 } 33 } 35 34 36 struct mctp_test_dev *mctp_test_create_dev(voi 35 struct mctp_test_dev *mctp_test_create_dev(void) 37 { 36 { 38 struct mctp_test_dev *dev; 37 struct mctp_test_dev *dev; 39 struct net_device *ndev; 38 struct net_device *ndev; 40 int rc; 39 int rc; 41 40 42 ndev = alloc_netdev(sizeof(*dev), "mct 41 ndev = alloc_netdev(sizeof(*dev), "mctptest%d", NET_NAME_ENUM, 43 mctp_test_dev_setu 42 mctp_test_dev_setup); 44 if (!ndev) 43 if (!ndev) 45 return NULL; 44 return NULL; 46 45 47 dev = netdev_priv(ndev); 46 dev = netdev_priv(ndev); 48 dev->ndev = ndev; 47 dev->ndev = ndev; 49 48 50 rc = register_netdev(ndev); 49 rc = register_netdev(ndev); 51 if (rc) { 50 if (rc) { 52 free_netdev(ndev); 51 free_netdev(ndev); 53 return NULL; 52 return NULL; 54 } 53 } 55 54 56 rcu_read_lock(); 55 rcu_read_lock(); 57 dev->mdev = __mctp_dev_get(ndev); 56 dev->mdev = __mctp_dev_get(ndev); 58 dev->mdev->net = mctp_default_net(dev_ << 59 rcu_read_unlock(); 57 rcu_read_unlock(); 60 58 61 return dev; 59 return dev; 62 } 60 } 63 61 64 void mctp_test_destroy_dev(struct mctp_test_de 62 void mctp_test_destroy_dev(struct mctp_test_dev *dev) 65 { 63 { 66 mctp_dev_put(dev->mdev); 64 mctp_dev_put(dev->mdev); 67 unregister_netdev(dev->ndev); 65 unregister_netdev(dev->ndev); 68 } 66 } 69 67
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.