--- zzzz-none-000/linux-5.15.111/net/core/dev.c 2023-05-11 14:00:40.000000000 +0000 +++ puma7-arm-6670-761/linux-5.15.111/net/core/dev.c 2024-02-07 09:28:09.000000000 +0000 @@ -67,6 +67,35 @@ * J Hadi Salim : - Backlog queue sampling * - netif_rx() feedback */ +/*---------------------------------------------------------------------------- +// Copyright 2007, Texas Instruments Incorporated +// +// This program has been modified from its original operation by Texas Instruments +// to do the following: +// +// 1. Device Specific Protocol Handling. +// 2. TI Meta Data Extension Console Dump for debugging. +// 3. Device Index Reuse +// 4. TI Layer 2 Selective Forwarder +// 5. TI Packet Processor Enhancements +// 6. TI Egress Hook Feature. +// +// THIS MODIFIED SOFTWARE AND DOCUMENTATION ARE PROVIDED +// "AS IS," AND TEXAS INSTRUMENTS MAKES NO REPRESENTATIONS +// OR WARRENTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY +// PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR +// DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, +// COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. +// +// These changes are covered as per original license +//-----------------------------------------------------------------------------*/ +/* + * Includes Maxlinear's changes dated: 2021. + * Changed portions - Copyright © 2021, MaxLinear, Inc. + * Includes Intel Corporation's changes dated: 2016, 2020. + * Changed portions - Copyright © 2016-2020, Intel Corporation. + */ #include #include @@ -119,6 +148,7 @@ #include #include #include +#include #include #include #include @@ -491,6 +521,34 @@ } #endif +#ifdef CONFIG_TI_DEVICE_PROTOCOL_HANDLING +extern int ti_protocol_handler (struct net_device* dev, struct sk_buff *skb); +#endif + +#ifdef CONFIG_TI_DEVICE_INDEX_REUSE +extern int ti_dev_new_index(struct net *net); +#endif /* CONFIG_TI_DEVICE_INDEX_REUSE */ + +#ifdef CONFIG_TI_L2_SELECTIVE_FORWARDER +extern void ti_save_netdevice_info(struct net_device *dev); +extern void ti_free_netdevice_info(struct net_device *dev); +#endif /* CONFIG_TI_L2_SELECTIVE_FORWARDER */ + + +#ifdef CONFIG_TI_EGRESS_HOOK +extern int ti_egress_hook_handler (struct net_device* dev, struct sk_buff *skb); +#endif /* CONFIG_TI_EGRESS_HOOK */ + + +#ifdef CONFIG_TI_DOCSIS_EGRESS_HOOK +extern int ti_docsis_egress_hook_handler (struct net_device* dev, struct sk_buff *skb); +#endif /* CONFIG_TI_DOCSIS_EGRESS_HOOK */ + + +#ifdef CONFIG_TI_GW_EGRESS_HOOK +extern int ti_gw_egress_hook_handler (struct net_device* dev, struct sk_buff *skb); +#endif /* CONFIG_TI_GW_EGRESS_HOOK */ + /******************************************************************************* * * Protocol management and registration routines @@ -4149,6 +4207,29 @@ bool again = false; skb_reset_mac_header(skb); + + /* Print the Message on the console indicating that the meta-data is succesfully available + * till the core networking device layers. */ +#ifdef CONFIG_TI_META_DATA_CONSOLE_DUMP + if (skb->ti_meta_info != 0x0) + printk ("Core Networking Device Layer: %s SKB 0x%p has META Data 0x%x\n", skb->dev->name, skb, skb->ti_meta_info); +#endif /* CONFIG_TI_META_DATA_CONSOLE_DUMP */ + +#ifdef CONFIG_TI_GW_EGRESS_HOOK + if (ti_gw_egress_hook_handler(dev, skb) < 0) + return rc; +#endif /* CONFIG_TI_GW_EGRESS_HOOK */ + +#ifdef CONFIG_TI_EGRESS_HOOK + if (ti_egress_hook_handler(dev, skb) < 0) + return rc; +#endif /* CONFIG_TI_EGRESS_HOOK */ + +#ifdef CONFIG_TI_DOCSIS_EGRESS_HOOK + if (ti_docsis_egress_hook_handler(dev, skb) < 0) + return rc; +#endif /* CONFIG_TI_DOCSIS_EGRESS_HOOK */ + skb_assert_len(skb); if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP)) @@ -5270,6 +5351,17 @@ pt_prev = NULL; another_round: +#ifdef CONFIG_TI_DEVICE_PROTOCOL_HANDLING + /* Pass the packet to the device specific protocol handler */ + if (ti_protocol_handler (skb->dev, skb) < 0) + { + /* Device Specific Protocol handler has "captured" the packet + * and does not want to send it up the networking stack; so + * return immediately. */ + ret = NET_RX_SUCCESS; + goto out; + } +#endif /* CONFIG_TI_DEVICE_PROTOCOL_HANDLING */ skb->skb_iif = skb->dev->ifindex; __this_cpu_inc(softnet_data.processed); @@ -6197,9 +6289,9 @@ break; case GRO_MERGED_FREE: - if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) + if (NAPI_GRO_CB(skb)->free == NAPI_GRO_FREE_STOLEN_HEAD) { napi_skb_free_stolen_head(skb); - else if (skb->fclone != SKB_FCLONE_UNAVAILABLE) + } else if (skb->fclone != SKB_FCLONE_UNAVAILABLE) __kfree_skb(skb); else __kfree_skb_defer(skb); @@ -9791,6 +9883,14 @@ */ static int dev_new_index(struct net *net) { +#ifdef CONFIG_TI_DEVICE_INDEX_REUSE + /* Original implementation does not limit the number of indexes that + * can be allocated. This can cause data overflow. + * The "index reuse feature" limits the number of devices to 32 and reuses + * freed up indexes. + */ + return (ti_dev_new_index(net)); +#else int ifindex = net->ifindex; for (;;) { @@ -9799,6 +9899,7 @@ if (!__dev_get_by_index(net, ifindex)) return net->ifindex = ifindex; } +#endif /* CONFIG_TI_DEVICE_INDEX_REUSE */ } /* Delayed registration/unregisteration */ @@ -10272,8 +10373,22 @@ } ret = -EBUSY; - if (!dev->ifindex) + if (!dev->ifindex) { dev->ifindex = dev_new_index(net); +#ifdef CONFIG_TI_DEVICE_INDEX_REUSE + /* Original dev_new_index() implementation gaurantees a unique device + * index by not limiting on the number of devices that can be registered. + * The "index reuse feature" limits the number of devices to 32. Free + * the allocated divert_blk + */ + + if (dev->ifindex == -1) + { + ret = -EINVAL; + goto err_uninit; + } +#endif /* CONFIG_TI_DEVICE_INDEX_REUSE */ + } else if (__dev_get_by_index(net, dev->ifindex)) goto err_uninit; @@ -10344,6 +10459,10 @@ dev_init_scheduler(dev); dev_hold(dev); +#ifdef CONFIG_TI_L2_SELECTIVE_FORWARDER + /* Store the netdevice pointer in global array */ + ti_save_netdevice_info(dev); +#endif /* CONFIG_TI_L2_SELECTIVE_FORWARDER */ list_netdevice(dev); add_device_randomness(dev->dev_addr, dev->addr_len); @@ -10681,6 +10800,12 @@ storage->rx_dropped += (unsigned long)atomic_long_read(&dev->rx_dropped); storage->tx_dropped += (unsigned long)atomic_long_read(&dev->tx_dropped); storage->rx_nohandler += (unsigned long)atomic_long_read(&dev->rx_nohandler); + +#ifdef CONFIG_TI_PACKET_PROCESSOR + if (dev->add_offload_stats) + dev->add_offload_stats(dev, storage); +#endif + return storage; } EXPORT_SYMBOL(dev_get_stats); @@ -10858,6 +10983,27 @@ hash_init(dev->qdisc_hash); #endif dev->priv_flags = IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM; +#ifdef CONFIG_TI_PACKET_PROCESSOR + /* Initialize the PID and VPID handle. By default the devices are not attached + * to the Packet Processor PDSP. The PID handle will be overwritten by the + * driver if this networking device is also a PHYSICAL device. The VPID handle + * is overwritten by the PROFILE if this networking device is a networking + * endpoint i.e. connected to the bridge or IP stack. */ + dev->pid_handle = -1; + dev->vpid_handle = -1; + memset ((void *)&dev->vpid_block, 0xFF, sizeof(dev->vpid_block)); +#if !(PUMA7_OR_NEWER_SOC_TYPE) + dev->vpid_block.qos_clusters_count = 0; +#endif +#ifdef CONFIG_MACH_PUMA5 + dev->vpid_block.priv_vpid_flags = 0; +#else + dev->vpid_block.flags = 0; +#endif + + + dev->qos_virtual_scheme_idx = NETDEV_PP_QOS_PROFILE_DEFAULT; +#endif /* CONFIG_TI_PACKET_PROCESSOR */ setup(dev); if (!dev->tx_queue_len) { @@ -10988,6 +11134,10 @@ void unregister_netdevice_queue(struct net_device *dev, struct list_head *head) { ASSERT_RTNL(); +#ifdef CONFIG_TI_L2_SELECTIVE_FORWARDER + /* Clear the netdevice pointer stored in the global array */ + ti_free_netdevice_info(dev); +#endif /* CONFIG_TI_L2_SELECTIVE_FORWARDER */ if (head) { list_move_tail(&dev->unreg_list, head); @@ -11632,6 +11782,35 @@ if (register_pernet_subsys(&netdev_net_ops)) goto out; +#ifdef CONFIG_TI_PACKET_PROCESSOR + /* Initialize the HIL Core Layer. */ + if (ti_hil_initialize() < 0) + { + printk ("Error: Unable to initialize the HIL Core\n"); + return -1; + } +#endif /* CONFIG_TI_PACKET_PROCESSOR */ + +#ifdef CONFIG_TI_HIL_PROFILE_INTRUSIVE + { + extern TI_HIL_PROFILE hil_intrusive_profile; + + /* Load the Intrusive mode HIL Profile for the system */ + if (ti_hil_register_profile(&hil_intrusive_profile) < 0) + return -1; + } +#endif /* CONFIG_TI_HIL_PROFILE_INTRUSIVE */ + +#ifdef CONFIG_TI_HIL_PROFILE_STATIC + { + extern TI_HIL_PROFILE hil_static_profile; + + /* Load the Static HIL Profile for the system */ + if (ti_hil_register_profile(&hil_static_profile) < 0) + return -1; + } +#endif /* CONFIG_TI_HIL_PROFILE_STATIC */ + /* * Initialise the packet receive queues. */