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) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * lec.c: Lan Emulation driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Marko Kiiskila <mkiiskila@yahoo.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) /* We are ethernet device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <net/dst.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) /* And atm device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/atmdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/atmlec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) /* Proxy LEC knows about bridging */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #if IS_ENABLED(CONFIG_BRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include "../bridge/br_private.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) /* Modular too */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) /* Hardening for Spectre-v1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include <linux/nospec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include "lec.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #include "lec_arpc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #include "resources.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define DUMP_PACKETS 0		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 				 * 0 = None,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 				 * 1 = 30 first bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 				 * 2 = Whole packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) #define LEC_UNRES_QUE_LEN 8	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 				 * number of tx packets to queue for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 				 * single destination while waiting for SVC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static int lec_open(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 				  struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static int lec_close(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 					  const unsigned char *mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static int lec_arp_remove(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 			  struct lec_arp_table *to_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) /* LANE2 functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 				const u8 *tlvs, u32 sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 			 u8 **tlvs, u32 *sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 			       const u8 *tlvs, u32 sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 			   unsigned long permanent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) static void lec_arp_check_empties(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 				  struct atm_vcc *vcc, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static void lec_arp_destroy(struct lec_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) static void lec_arp_init(struct lec_priv *priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 				       const unsigned char *mac_to_find,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 				       int is_rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 				       struct lec_arp_table **ret_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 			   const unsigned char *atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 			   unsigned long remoteflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 			   unsigned int targetless_le_arp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static void lec_set_flush_tran_id(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 				  const unsigned char *atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 				  unsigned long tran_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static void lec_vcc_added(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 			  const struct atmlec_ioc *ioc_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 			  struct atm_vcc *vcc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 			  void (*old_push)(struct atm_vcc *vcc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 					   struct sk_buff *skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) /* must be done under lec_arp_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static inline void lec_arp_hold(struct lec_arp_table *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	refcount_inc(&entry->usage);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) static inline void lec_arp_put(struct lec_arp_table *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	if (refcount_dec_and_test(&entry->usage))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		kfree(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static struct lane2_ops lane2_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	.resolve = lane2_resolve,		/* spec 3.1.3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	.associate_req = lane2_associate_req,	/* spec 3.1.4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	.associate_indicator = NULL             /* spec 3.1.5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) /* Device structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static struct net_device *dev_lec[MAX_LEC_ITF];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) #if IS_ENABLED(CONFIG_BRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	char *buff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	struct lec_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	 * Check if this is a BPDU. If so, ask zeppelin to send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	 * as the Config BPDU has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 	buff = skb->data + skb->dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 		struct sk_buff *skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 		struct atmlec_msg *mesg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		if (skb2 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		skb2->len = sizeof(struct atmlec_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		mesg = (struct atmlec_msg *)skb2->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		mesg->type = l_topology_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		buff += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		mesg->content.normal.flag = *buff & 0x01;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 					/* 0x01 is topology change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 		priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 		atm_force_charge(priv->lecd, skb2->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		sk = sk_atm(priv->lecd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		skb_queue_tail(&sk->sk_receive_queue, skb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		sk->sk_data_ready(sk);
^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) #endif /* IS_ENABLED(CONFIG_BRIDGE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  * Open/initialize the netdevice. This is called (in the current kernel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  * sometime after booting when the 'ifconfig' program is run.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  * This routine should set everything up anew at each open, even
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  * registers that "should" only need to be set once at boot, so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * there is non-reboot way to recover if something goes wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static int lec_open(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	netif_start_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	ATM_SKB(skb)->vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	atm_account_tx(vcc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	if (vcc->send(vcc, skb) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 		dev->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	dev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	dev->stats.tx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) static void lec_tx_timeout(struct net_device *dev, unsigned int txqueue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	pr_info("%s\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	netif_trans_update(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 				  struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	struct sk_buff *skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	struct lecdatahdr_8023 *lec_h;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	struct atm_vcc *vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	unsigned char *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	int min_frame_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	int is_rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 	pr_debug("called\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	if (!priv->lecd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		pr_info("%s:No lecd attached\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		dev->stats.tx_errors++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 		netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		kfree_skb(skb);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		 (long)skb_end_pointer(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) #if IS_ENABLED(CONFIG_BRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 	if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		lec_handle_bridge(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	/* Make sure we have room for lec_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	if (skb_headroom(skb) < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		pr_debug("reallocating skb\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 		if (unlikely(!skb2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 			return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 		consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		skb = skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	skb_push(skb, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	/* Put le header to place */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	lec_h = (struct lecdatahdr_8023 *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	lec_h->le_header = htons(priv->lecid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) #if DUMP_PACKETS >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) #define MAX_DUMP_SKB 99
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) #elif DUMP_PACKETS >= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) #define MAX_DUMP_SKB 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) #if DUMP_PACKETS >= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	       dev->name, skb->len, priv->lecid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 		       skb->data, min(skb->len, MAX_DUMP_SKB), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) #endif /* DUMP_PACKETS >= 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	/* Minimum ethernet-frame size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	min_frame_size = LEC_MINIMUM_8023_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	if (skb->len < min_frame_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 		if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 			skb2 = skb_copy_expand(skb, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 					       min_frame_size - skb->truesize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 					       GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 			dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 			if (skb2 == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 				dev->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 				return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 			skb = skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 		skb_put(skb, min_frame_size - skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	/* Send to right vcc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	is_rdesc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	dst = lec_h->h_dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	entry = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 	pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		 dev->name, vcc, vcc ? vcc->flags : 0, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 			pr_debug("%s:queuing packet, MAC address %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 				 dev->name, lec_h->h_dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 			skb_queue_tail(&entry->tx_wait, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 			pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 				 dev->name, lec_h->h_dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 			dev->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) #if DUMP_PACKETS > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	       dev->name, vcc->vpi, vcc->vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) #endif /* DUMP_PACKETS > 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		lec_send(vcc, skb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	lec_send(vcc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 	if (!atm_may_send(vcc, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		vpriv->xoff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		 * vcc->pop() might have occurred in between, making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		 * the vcc usuable again.  Since xmit is serialized,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		 * this is the only situation we have to re-test.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		if (atm_may_send(vcc, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	if (entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 		lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 	netif_trans_update(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) /* The inverse routine to net_open(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) static int lec_close(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	struct net_device *dev = (struct net_device *)vcc->proto_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	struct atmlec_msg *mesg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	char *tmp;		/* FIXME */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	WARN_ON(refcount_sub_and_test(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	mesg = (struct atmlec_msg *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	tmp = skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	tmp += sizeof(struct atmlec_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 	pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	switch (mesg->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 	case l_set_mac_addr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		for (i = 0; i < 6; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	case l_del_mac_addr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		for (i = 0; i < 6; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			dev->dev_addr[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	case l_addr_delete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		lec_addr_delete(priv, mesg->content.normal.atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 				mesg->content.normal.flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	case l_topology_change:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 		priv->topology_change = mesg->content.normal.flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	case l_flush_complete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 		lec_flush_complete(priv, mesg->content.normal.flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	case l_narp_req:	/* LANE2: see 7.1.35 in the lane2 spec */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 		spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 		entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		lec_arp_remove(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		if (mesg->content.normal.no_source_le_narp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	case l_arp_update:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		lec_arp_update(priv, mesg->content.normal.mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 			       mesg->content.normal.atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 			       mesg->content.normal.flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 			       mesg->content.normal.targetless_le_arp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		pr_debug("in l_arp_update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		if (mesg->sizeoftlvs != 0) {	/* LANE2 3.1.5 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 			pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 				 mesg->sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 			lane2_associate_ind(dev, mesg->content.normal.mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 					    tmp, mesg->sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	case l_config:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		priv->maximum_unknown_frame_count =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		    mesg->content.config.maximum_unknown_frame_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		priv->max_unknown_frame_time =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		    (mesg->content.config.max_unknown_frame_time * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 		priv->max_retry_count = mesg->content.config.max_retry_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		priv->aging_time = (mesg->content.config.aging_time * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 		priv->forward_delay_time =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 		    (mesg->content.config.forward_delay_time * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		priv->arp_response_time =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		    (mesg->content.config.arp_response_time * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		priv->path_switching_delay =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		    (mesg->content.config.path_switching_delay * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		priv->lane_version = mesg->content.config.lane_version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 					/* LANE2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 		priv->lane2_ops = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		if (priv->lane_version > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 			priv->lane2_ops = &lane2_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		if (dev_set_mtu(dev, mesg->content.config.mtu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 			pr_info("%s: change_mtu to %d failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 				dev->name, mesg->content.config.mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 		rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		priv->is_proxy = mesg->content.config.is_proxy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	case l_flush_tran_id:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 				      mesg->content.normal.flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	case l_set_lecid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		priv->lecid =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 		    (unsigned short)(0xffff & mesg->content.normal.flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	case l_should_bridge:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) #if IS_ENABLED(CONFIG_BRIDGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 		pr_debug("%s: bridge zeppelin asks about %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			 dev->name, mesg->content.proxy.mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 		if (br_fdb_test_addr_hook == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		if (br_fdb_test_addr_hook(dev, mesg->content.proxy.mac_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 			/* hit from bridge table, send LE_ARP_RESPONSE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 			struct sk_buff *skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 			struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 			pr_debug("%s: entry found, responding to zeppelin\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 				 dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 			skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			if (skb2 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 			skb2->len = sizeof(struct atmlec_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 			skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 			atm_force_charge(priv->lecd, skb2->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 			sk = sk_atm(priv->lecd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			skb_queue_tail(&sk->sk_receive_queue, skb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 			sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) #endif /* IS_ENABLED(CONFIG_BRIDGE) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 		pr_info("%s: Unknown message type %d\n", dev->name, mesg->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) static void lec_atm_close(struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	struct net_device *dev = (struct net_device *)vcc->proto_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	priv->lecd = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	/* Do something needful? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	netif_stop_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	lec_arp_destroy(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 	if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		pr_info("%s closing with messages pending\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		atm_return(vcc, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	pr_info("%s: Shut down!\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	module_put(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) static const struct atmdev_ops lecdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	.close = lec_atm_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	.send = lec_atm_send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) static struct atm_dev lecatm_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	.ops = &lecdev_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	.type = "lec",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	.number = 999,		/* dummy device number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	.lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505)  * LANE2: new argument struct sk_buff *data contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506)  * the LE_ARP based TLVs introduced in the LANE2 spec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	     const unsigned char *mac_addr, const unsigned char *atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	     struct sk_buff *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	struct sock *sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	struct atmlec_msg *mesg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 	if (!priv || !priv->lecd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	skb->len = sizeof(struct atmlec_msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	mesg = (struct atmlec_msg *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	memset(mesg, 0, sizeof(struct atmlec_msg));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	mesg->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	if (data != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		mesg->sizeoftlvs = data->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	if (mac_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		ether_addr_copy(mesg->content.normal.mac_addr, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 		mesg->content.normal.targetless_le_arp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 	if (atm_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 		memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	atm_force_charge(priv->lecd, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	sk = sk_atm(priv->lecd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	skb_queue_tail(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	if (data != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		pr_debug("about to send %d bytes of data\n", data->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		atm_force_charge(priv->lecd, data->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		skb_queue_tail(&sk->sk_receive_queue, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) static void lec_set_multicast_list(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	 * by default, all multicast frames arrive over the bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	 * eventually support selective multicast service
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) static const struct net_device_ops lec_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	.ndo_open		= lec_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	.ndo_stop		= lec_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	.ndo_start_xmit		= lec_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	.ndo_tx_timeout		= lec_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	.ndo_set_rx_mode	= lec_set_multicast_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) static const unsigned char lec_ctrl_magic[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	0x00,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	0x01,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) #define LEC_DATA_DIRECT_8023  2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) #define LEC_DATA_DIRECT_8025  3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) static int lec_is_data_direct(struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 		(vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	struct net_device *dev = (struct net_device *)vcc->proto_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) #if DUMP_PACKETS > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	       dev->name, vcc->vpi, vcc->vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		pr_debug("%s: null skb\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 		lec_vcc_close(priv, vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) #if DUMP_PACKETS >= 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) #define MAX_SKB_DUMP 99
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) #elif DUMP_PACKETS >= 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) #define MAX_SKB_DUMP 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) #if DUMP_PACKETS > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	       dev->name, skb->len, priv->lecid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		       skb->data, min(MAX_SKB_DUMP, skb->len), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) #endif /* DUMP_PACKETS > 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 				/* Control frame, to daemon */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		struct sock *sk = sk_atm(vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		pr_debug("%s: To daemon\n", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 		skb_queue_tail(&sk->sk_receive_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		sk->sk_data_ready(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	} else {		/* Data frame, queue to protocol handlers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 		struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 		unsigned char *src, *dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 		atm_return(vcc, skb->truesize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 		if (*(__be16 *) skb->data == htons(priv->lecid) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 		    !priv->lecd || !(dev->flags & IFF_UP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 			 * Probably looping back, or if lecd is missing,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 			 * lecd has gone down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 			pr_debug("Ignoring frame...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 		dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		 * If this is a Data Direct VCC, and the VCC does not match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		 * the LE_ARP cache entry, delete the LE_ARP cache entry.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		if (lec_is_data_direct(vcc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 			src = ((struct lecdatahdr_8023 *)skb->data)->h_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 			entry = lec_arp_find(priv, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			if (entry && entry->vcc != vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 				lec_arp_remove(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 				lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		if (!(dst[0] & 0x01) &&	/* Never filter Multi/Broadcast */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		    !priv->is_proxy &&	/* Proxy wants all the packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 		    memcmp(dst, dev->dev_addr, dev->addr_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			dev_kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		if (!hlist_empty(&priv->lec_arp_empty_ones))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			lec_arp_check_empties(priv, vcc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		skb_pull(skb, 2);	/* skip lec_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 		skb->protocol = eth_type_trans(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		netif_rx(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	struct net_device *dev = skb->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	if (vpriv == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		pr_info("vpriv = NULL!?!?!?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	vpriv->old_pop(vcc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	if (vpriv->xoff && atm_may_send(vcc, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		vpriv->xoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		if (netif_running(dev) && netif_queue_stopped(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	struct lec_vcc_priv *vpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	int bytes_left;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	struct atmlec_ioc ioc_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	/* Lecd must be up in this case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	if (bytes_left != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		pr_info("copy from user failed for %d bytes\n", bytes_left);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 	ioc_data.dev_num = array_index_nospec(ioc_data.dev_num, MAX_LEC_ITF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	if (!dev_lec[ioc_data.dev_num])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	if (!vpriv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	vpriv->xoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 	vpriv->old_pop = vcc->pop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	vcc->user_back = vpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	vcc->pop = lec_pop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 	lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		      &ioc_data, vcc, vcc->push);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	vcc->proto_data = dev_lec[ioc_data.dev_num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	vcc->push = lec_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	if (arg < 0 || arg >= MAX_LEC_ITF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	arg = array_index_nospec(arg, MAX_LEC_ITF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	if (!dev_lec[arg])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	vcc->proto_data = dev_lec[arg];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 	return lec_mcast_make(netdev_priv(dev_lec[arg]), vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) /* Initialize device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) static int lecd_attach(struct atm_vcc *vcc, int arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	struct lec_priv *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	if (arg < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 		arg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	if (arg >= MAX_LEC_ITF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	i = array_index_nospec(arg, MAX_LEC_ITF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	if (!dev_lec[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		size = sizeof(struct lec_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 		dev_lec[i] = alloc_etherdev(size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 		if (!dev_lec[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 		dev_lec[i]->netdev_ops = &lec_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		dev_lec[i]->max_mtu = 18190;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 		snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		if (register_netdev(dev_lec[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			free_netdev(dev_lec[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 		priv = netdev_priv(dev_lec[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 		priv = netdev_priv(dev_lec[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 		if (priv->lecd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 			return -EADDRINUSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	lec_arp_init(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	priv->itfnum = i;	/* LANE2 addition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	priv->lecd = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	vcc->dev = &lecatm_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	vcc_insert_socket(sk_atm(vcc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	vcc->proto_data = dev_lec[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	set_bit(ATM_VF_META, &vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	set_bit(ATM_VF_READY, &vcc->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	/* Set default values to these variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	priv->maximum_unknown_frame_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	priv->max_unknown_frame_time = (1 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	priv->vcc_timeout_period = (1200 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	priv->max_retry_count = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	priv->aging_time = (300 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	priv->forward_delay_time = (15 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	priv->topology_change = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	priv->arp_response_time = (1 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	priv->flush_timeout = (4 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	priv->path_switching_delay = (6 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	if (dev_lec[i]->flags & IFF_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 		netif_start_queue(dev_lec[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	__module_get(THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) static const char *lec_arp_get_status_string(unsigned char status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	static const char *const lec_arp_status_string[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 		"ESI_UNKNOWN       ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		"ESI_ARP_PENDING   ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		"ESI_VC_PENDING    ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 		"<Undefined>       ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 		"ESI_FLUSH_PENDING ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		"ESI_FORWARD_DIRECT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (status > ESI_FORWARD_DIRECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		status = 3;	/* ESI_UNDEFINED */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	return lec_arp_status_string[status];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 	seq_printf(seq, "%pM ", entry->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 	seq_printf(seq, "%*phN ", ATM_ESA_LEN, entry->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 	seq_printf(seq, "%s %4.4x", lec_arp_get_status_string(entry->status),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		   entry->flags & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	if (entry->vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 		seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		seq_printf(seq, "        ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	if (entry->recv_vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 		seq_printf(seq, "     %3d %3d", entry->recv_vcc->vpi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 			   entry->recv_vcc->vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	seq_putc(seq, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) struct lec_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	struct lec_priv *locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	struct hlist_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	int itf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	int arp_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 	int misc_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			  loff_t *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	struct hlist_node *e = state->node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 	if (!e)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		e = tbl->first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	if (e == SEQ_START_TOKEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		e = tbl->first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 		--*l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	for (; e; e = e->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 		if (--*l < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	state->node = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	return (*l < 0) ? state : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) static void *lec_arp_walk(struct lec_state *state, loff_t *l,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			  struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	void *v = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	int p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		if (v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	state->arp_table = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) static void *lec_misc_walk(struct lec_state *state, loff_t *l,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 			   struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	struct hlist_head *lec_misc_tables[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 		&priv->lec_arp_empty_ones,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		&priv->lec_no_forward,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		&priv->mcast_fwds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	void *v = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	int q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 	for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 		v = lec_tbl_walk(state, lec_misc_tables[q], l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		if (v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	state->misc_table = q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) static void *lec_priv_walk(struct lec_state *state, loff_t *l,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 			   struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	if (!state->locked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 		state->locked = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		state->locked = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		/* Partial state reset for the next time we get called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 		state->arp_table = state->misc_table = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 	return state->locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) static void *lec_itf_walk(struct lec_state *state, loff_t *l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	struct net_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 	void *v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 	dev = state->dev ? state->dev : dev_lec[state->itf];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 	v = (dev && netdev_priv(dev)) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	if (!v && dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		dev_put(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		/* Partial state reset for the next time we get called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	state->dev = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) static void *lec_get_idx(struct lec_state *state, loff_t l)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 	void *v = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	for (; state->itf < MAX_LEC_ITF; state->itf++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		v = lec_itf_walk(state, &l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		if (v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 	struct lec_state *state = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	state->itf = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	state->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	state->locked = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	state->arp_table = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	state->misc_table = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	state->node = SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) static void lec_seq_stop(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	struct lec_state *state = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	if (state->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 		spin_unlock_irqrestore(&state->locked->lec_arp_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 				       state->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		dev_put(state->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	struct lec_state *state = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	++*pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	return lec_get_idx(state, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) static int lec_seq_show(struct seq_file *seq, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	static const char lec_banner[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	    "Itf  MAC          ATM destination"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	    "                          Status            Flags "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	    "VPI/VCI Recv VPI/VCI\n";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	if (v == SEQ_START_TOKEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		seq_puts(seq, lec_banner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		struct lec_state *state = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 		struct net_device *dev = state->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		struct lec_arp_table *entry = hlist_entry(state->node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 							  struct lec_arp_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 							  next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		seq_printf(seq, "%s ", dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		lec_info(seq, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) static const struct seq_operations lec_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	.start = lec_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	.next = lec_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	.stop = lec_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	.show = lec_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	struct atm_vcc *vcc = ATM_SD(sock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	case ATMLEC_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	case ATMLEC_MCAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	case ATMLEC_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		if (!capable(CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 			return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 		return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	case ATMLEC_CTRL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 		err = lecd_attach(vcc, (int)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 		if (err >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 			sock->state = SS_CONNECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	case ATMLEC_MCAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 		err = lec_mcast_attach(vcc, (int)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	case ATMLEC_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		err = lec_vcc_attach(vcc, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) static struct atm_ioctl lane_ioctl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	.ioctl = lane_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static int __init lane_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	struct proc_dir_entry *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	p = proc_create_seq_private("lec", 0444, atm_proc_root, &lec_seq_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 			sizeof(struct lec_state), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		pr_err("Unable to initialize /proc/net/atm/lec\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	register_atm_ioctl(&lane_ioctl_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 	pr_info("lec.c: initialized\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) static void __exit lane_module_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	remove_proc_entry("lec", atm_proc_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	deregister_atm_ioctl(&lane_ioctl_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	for (i = 0; i < MAX_LEC_ITF; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		if (dev_lec[i] != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 			unregister_netdev(dev_lec[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 			free_netdev(dev_lec[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 			dev_lec[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) module_init(lane_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) module_exit(lane_module_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)  * LANE2: 3.1.3, LE_RESOLVE.request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)  * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)  * If sizeoftlvs == NULL the default TLVs associated with this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)  * lec will be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)  * If dst_mac == NULL, targetless LE_ARP will be sent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 			 u8 **tlvs, u32 *sizeoftlvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	struct lec_arp_table *table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	if (force == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		table = lec_arp_find(priv, dst_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 		spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 		if (table == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		*tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		if (*tlvs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 		*sizeoftlvs = table->sizeoftlvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	if (sizeoftlvs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		skb->len = *sizeoftlvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116)  * LANE2: 3.1.4, LE_ASSOCIATE.request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)  * Associate the *tlvs with the *lan_dst address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)  * Will overwrite any previous association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)  * Returns 1 for success, 0 for failure (out of memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			       const u8 *tlvs, u32 sizeoftlvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 	if (!ether_addr_equal(lan_dst, dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		return 0;	/* not our mac address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	kfree(priv->tlvs);	/* NULL if there was no previous association */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	if (priv->tlvs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	priv->sizeoftlvs = sizeoftlvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	skb->len = sizeoftlvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	if (retval != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		pr_info("lec.c: lane2_associate_req() failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	 * If the previous association has changed we must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	 * somehow notify other LANE entities about the change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * LANE2: 3.1.5, LE_ASSOCIATE.indication
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 				const u8 *tlvs, u32 sizeoftlvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	struct lec_priv *priv = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) #if 0				/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 				 * Why have the TLVs in LE_ARP entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 				 * since we do not use them? When you
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 				 * uncomment this code, make sure the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 				 * TLVs get freed when entry is killed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	if (entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		return;		/* should not happen */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	kfree(entry->tlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (entry->tlvs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	entry->sizeoftlvs = sizeoftlvs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	pr_info("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	while (i < sizeoftlvs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 		pr_cont("%02x ", tlvs[i++]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	/* tell MPOA about the TLVs we saw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 		priv->lane2_ops->associate_indicator(dev, mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 						     tlvs, sizeoftlvs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200)  * Here starts what used to lec_arpc.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)  * lec_arpc.c was added here when making
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)  * lane client modular. October 1997
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) #include <linux/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) #define pr_debug(format, args...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216)   #define pr_debug printk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) #define DEBUG_ARP_TABLE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) static void lec_arp_check_expire(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) static void lec_arp_expire_arp(struct timer_list *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)  * Arp table funcs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)  * Initialization of arp-cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) static void lec_arp_init(struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	unsigned short i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 		INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	INIT_HLIST_HEAD(&priv->lec_no_forward);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	INIT_HLIST_HEAD(&priv->mcast_fwds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	spin_lock_init(&priv->lec_arp_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) static void lec_arp_clear_vccs(struct lec_arp_table *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	if (entry->vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 		struct atm_vcc *vcc = entry->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 		struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 		struct net_device *dev = (struct net_device *)vcc->proto_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 		vcc->pop = vpriv->old_pop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 		if (vpriv->xoff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 			netif_wake_queue(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 		kfree(vpriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 		vcc->user_back = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 		vcc->push = entry->old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		vcc_release_async(vcc, -EPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		entry->vcc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	if (entry->recv_vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		struct atm_vcc *vcc = entry->recv_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		kfree(vpriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		vcc->user_back = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		entry->recv_vcc->push = entry->old_recv_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		vcc_release_async(entry->recv_vcc, -EPIPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		entry->recv_vcc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)  * Insert entry to lec_arp_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)  * LANE2: Add to the end of the list to satisfy 8.1.13
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	struct hlist_head *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	hlist_add_head(&entry->next, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	pr_debug("Added entry:%pM\n", entry->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294)  * Remove entry from lec_arp_table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	int i, remove_vcc = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	if (!to_remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	hlist_del(&to_remove->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	del_timer(&to_remove->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 	 * If this is the only MAC connected to this VCC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 	 * also tear down the VCC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 	if (to_remove->status >= ESI_FLUSH_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 			hlist_for_each_entry(entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 					     &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 				if (memcmp(to_remove->atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 					   entry->atm_addr, ATM_ESA_LEN) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 					remove_vcc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 		if (remove_vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 			lec_arp_clear_vccs(to_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	skb_queue_purge(&to_remove->tx_wait);	/* FIXME: good place for this? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) #if DEBUG_ARP_TABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) static const char *get_status_string(unsigned char st)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	switch (st) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 	case ESI_UNKNOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		return "ESI_UNKNOWN";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	case ESI_ARP_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 		return "ESI_ARP_PENDING";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	case ESI_VC_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		return "ESI_VC_PENDING";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	case ESI_FLUSH_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		return "ESI_FLUSH_PENDING";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 	case ESI_FORWARD_DIRECT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		return "ESI_FORWARD_DIRECT";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	return "<UNKNOWN>";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) static void dump_arp_table(struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	struct lec_arp_table *rulla;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	char buf[256];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	int i, offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	pr_info("Dump %p:\n", priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		hlist_for_each_entry(rulla,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 				     &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 			offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 			offset += sprintf(buf, "%d: %p\n", i, rulla);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 			offset += sprintf(buf + offset, "Mac: %pM ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 					  rulla->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 			offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 					  rulla->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 			offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 					  "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 					  rulla->vcc ? rulla->vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 					  rulla->vcc ? rulla->vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 					  rulla->recv_vcc ? rulla->recv_vcc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 					  vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 					  rulla->recv_vcc ? rulla->recv_vcc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 					  vci : 0, rulla->last_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 					  rulla->timestamp, rulla->no_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 			offset +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 			    sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 				    "Flags:%x, Packets_flooded:%x, Status: %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 				    rulla->flags, rulla->packets_flooded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 				    get_status_string(rulla->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 			pr_info("%s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	if (!hlist_empty(&priv->lec_no_forward))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		pr_info("No forward\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	hlist_for_each_entry(rulla, &priv->lec_no_forward, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 				  rulla->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 		offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 				  "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 				  rulla->vcc ? rulla->vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 				  rulla->vcc ? rulla->vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 				  rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 				  rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 				  rulla->last_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 				  rulla->timestamp, rulla->no_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 				  "Flags:%x, Packets_flooded:%x, Status: %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 				  rulla->flags, rulla->packets_flooded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 				  get_status_string(rulla->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		pr_info("%s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	if (!hlist_empty(&priv->lec_arp_empty_ones))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		pr_info("Empty ones\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	hlist_for_each_entry(rulla, &priv->lec_arp_empty_ones, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 		offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 		offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 				  rulla->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 				  "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 				  rulla->vcc ? rulla->vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 				  rulla->vcc ? rulla->vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 				  rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 				  rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 				  rulla->last_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 				  rulla->timestamp, rulla->no_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 		offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 				  "Flags:%x, Packets_flooded:%x, Status: %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 				  rulla->flags, rulla->packets_flooded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 				  get_status_string(rulla->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		pr_info("%s", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	if (!hlist_empty(&priv->mcast_fwds))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		pr_info("Multicast Forward VCCs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 	hlist_for_each_entry(rulla, &priv->mcast_fwds, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 		offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		offset += sprintf(buf + offset, "Mac: %pM ", rulla->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 		offset += sprintf(buf + offset, "Atm: %*ph ", ATM_ESA_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 				  rulla->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 				  "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 				  rulla->vcc ? rulla->vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 				  rulla->vcc ? rulla->vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 				  rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 				  rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 				  rulla->last_used,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 				  rulla->timestamp, rulla->no_tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 		offset += sprintf(buf + offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 				  "Flags:%x, Packets_flooded:%x, Status: %s ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 				  rulla->flags, rulla->packets_flooded,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 				  get_status_string(rulla->status));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		pr_info("%s\n", buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) #define dump_arp_table(priv) do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459)  * Destruction of arp-cache
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) static void lec_arp_destroy(struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 	struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	cancel_delayed_work_sync(&priv->lec_arp_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	 * Remove all entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 		hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 					  &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			lec_arp_remove(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 			lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 				  &priv->lec_arp_empty_ones, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 		del_timer_sync(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 		lec_arp_clear_vccs(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 		hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 		lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 				  &priv->lec_no_forward, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		del_timer_sync(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 		lec_arp_clear_vccs(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 		hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 		lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 	INIT_HLIST_HEAD(&priv->lec_no_forward);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	hlist_for_each_entry_safe(entry, next, &priv->mcast_fwds, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		/* No timer, LANEv2 7.1.20 and 2.3.5.3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		lec_arp_clear_vccs(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	INIT_HLIST_HEAD(&priv->mcast_fwds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	priv->mcast_vcc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)  * Find entry by mac_address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 					  const unsigned char *mac_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	struct hlist_head *head;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	pr_debug("%pM\n", mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	hlist_for_each_entry(entry, head, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 		if (ether_addr_equal(mac_addr, entry->mac_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 			return entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) static struct lec_arp_table *make_entry(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 					const unsigned char *mac_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	struct lec_arp_table *to_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 	to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 	if (!to_return)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	ether_addr_copy(to_return->mac_addr, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	INIT_HLIST_NODE(&to_return->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 	timer_setup(&to_return->timer, lec_arp_expire_arp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	to_return->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	to_return->priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	skb_queue_head_init(&to_return->tx_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	refcount_set(&to_return->usage, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	return to_return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) /* Arp sent timer expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) static void lec_arp_expire_arp(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	entry = from_timer(entry, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	if (entry->status == ESI_ARP_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 		if (entry->no_tries <= entry->priv->max_retry_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 			if (entry->is_rdesc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 				send_to_lecd(entry->priv, l_rdesc_arp_xmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 					     entry->mac_addr, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 				send_to_lecd(entry->priv, l_arp_xmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 					     entry->mac_addr, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 			entry->no_tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 		mod_timer(&entry->timer, jiffies + (1 * HZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) /* Unknown/unused vcc expire, remove associated entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) static void lec_arp_expire_vcc(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	struct lec_arp_table *to_remove = from_timer(to_remove, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	struct lec_priv *priv = to_remove->priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	del_timer(&to_remove->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	pr_debug("%p %p: vpi:%d vci:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 		 to_remove, priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 		 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 		 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	hlist_del(&to_remove->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 	lec_arp_clear_vccs(to_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	lec_arp_put(to_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) static bool __lec_arp_check_expire(struct lec_arp_table *entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 				   unsigned long now,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 				   struct lec_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	unsigned long time_to_check;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 		time_to_check = priv->forward_delay_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 		time_to_check = priv->aging_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	pr_debug("About to expire: %lx - %lx > %lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		 now, entry->last_used, time_to_check);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	if (time_after(now, entry->last_used + time_to_check) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	    !(entry->flags & LEC_PERMANENT_FLAG) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	    !(entry->mac_addr[0] & 0x01)) {	/* LANE2: 7.1.20 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 		/* Remove entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		pr_debug("Entry timed out\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 		lec_arp_remove(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 		lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 		/* Something else */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 		if ((entry->status == ESI_VC_PENDING ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 		     entry->status == ESI_ARP_PENDING) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 		    time_after_eq(now, entry->timestamp +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 				       priv->max_unknown_frame_time)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 			entry->timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			entry->packets_flooded = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 			if (entry->status == ESI_VC_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 				send_to_lecd(priv, l_svc_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 					     entry->mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 					     entry->atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 					     NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		if (entry->status == ESI_FLUSH_PENDING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 		    time_after_eq(now, entry->timestamp +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 				       priv->path_switching_delay)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			lec_arp_hold(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 			return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639)  * Expire entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640)  * 1. Re-set timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)  * 2. For each entry, delete entries that have aged past the age limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)  * 3. For each entry, depending on the status of the entry, perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643)  *    the following maintenance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)  *    a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645)  *       tick_count is above the max_unknown_frame_time, clear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646)  *       the tick_count to zero and clear the packets_flooded counter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647)  *       to zero. This supports the packet rate limit per address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)  *       while flooding unknowns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649)  *    b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650)  *       than or equal to the path_switching_delay, change the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)  *       to ESI_FORWARD_DIRECT. This causes the flush period to end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652)  *       regardless of the progress of the flush protocol.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) static void lec_arp_check_expire(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	struct lec_priv *priv =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		container_of(work, struct lec_priv, lec_arp_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	unsigned long now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	pr_debug("%p\n", priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	now = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 		hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 					  &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			if (__lec_arp_check_expire(entry, now, priv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 				struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 				struct atm_vcc *vcc = entry->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 				spin_unlock_irqrestore(&priv->lec_arp_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 						       flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 				while ((skb = skb_dequeue(&entry->tx_wait)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 					lec_send(vcc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 				entry->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 				entry->status = ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 				lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 				goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)  * Try to find vcc where mac_address is attached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 				       const unsigned char *mac_to_find,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 				       int is_rdesc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 				       struct lec_arp_table **ret_entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	struct atm_vcc *found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	if (mac_to_find[0] & 0x01) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 		switch (priv->lane_version) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 			return priv->mcast_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 		case 2:	/* LANE2 wants arp for multicast addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 			if (ether_addr_equal(mac_to_find, bus_mac))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 				return priv->mcast_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	entry = lec_arp_find(priv, mac_to_find);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	if (entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		if (entry->status == ESI_FORWARD_DIRECT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 			/* Connection Ok */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 			entry->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 			lec_arp_hold(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 			*ret_entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 			found = entry->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		 * If the LE_ARP cache entry is still pending, reset count to 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 		 * so another LE_ARP request can be made for this frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		if (entry->status == ESI_ARP_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 			entry->no_tries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 		 * Data direct VC not yet set up, check to see if the unknown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 		 * frame count is greater than the limit. If the limit has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 		 * not been reached, allow the caller to send packet to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 		 * BUS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		if (entry->status != ESI_FLUSH_PENDING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		    entry->packets_flooded <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 		    priv->maximum_unknown_frame_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 			entry->packets_flooded++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 			pr_debug("Flooding..\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 			found = priv->mcast_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 		 * We got here because entry->status == ESI_FLUSH_PENDING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 		 * or BUS flood limit was reached for an entry which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 		 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 		lec_arp_hold(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 		*ret_entry = entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 		pr_debug("entry->status %d entry->vcc %p\n", entry->status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 			 entry->vcc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 		found = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 		/* No matching entry was found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 		entry = make_entry(priv, mac_to_find);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 		pr_debug("Making entry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 		if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 			found = priv->mcast_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 		lec_arp_add(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 		/* We want arp-request(s) to be sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 		entry->packets_flooded = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		entry->status = ESI_ARP_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		entry->no_tries = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 		entry->last_used = entry->timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 		entry->is_rdesc = is_rdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 		if (entry->is_rdesc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 			send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 				     NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 			send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 		entry->timer.expires = jiffies + (1 * HZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 		entry->timer.function = lec_arp_expire_arp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 		add_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 		found = priv->mcast_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 		unsigned long permanent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	pr_debug("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 		hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 					  &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 			if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 			    (permanent ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 			     !(entry->flags & LEC_PERMANENT_FLAG))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 				lec_arp_remove(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 				lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 			spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)  * Notifies:  Response to arp_request (atm_addr != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	       const unsigned char *atm_addr, unsigned long remoteflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	       unsigned int targetless_le_arp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	struct lec_arp_table *entry, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	pr_debug("%smac:%pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 		 (targetless_le_arp) ? "targetless " : "", mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	entry = lec_arp_find(priv, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	if (entry == NULL && targetless_le_arp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		goto out;	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 				 * LANE2: ignore targetless LE_ARPs for which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 				 * we have no entry in the cache. 7.1.30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 	if (!hlist_empty(&priv->lec_arp_empty_ones)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 					  &priv->lec_arp_empty_ones, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 			if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 				hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 				del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 				tmp = lec_arp_find(priv, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 				if (tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 					del_timer(&tmp->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 					tmp->status = ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 					memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 					tmp->vcc = entry->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 					tmp->old_push = entry->old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 					tmp->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 					del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 					lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 					entry = tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 					entry->status = ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 					ether_addr_copy(entry->mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 							mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 					entry->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 					lec_arp_add(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 				if (remoteflag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 					entry->flags |= LEC_REMOTE_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 					entry->flags &= ~LEC_REMOTE_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 				pr_debug("After update\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 				dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	entry = lec_arp_find(priv, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 		entry = make_entry(priv, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 		if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 		entry->status = ESI_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 		lec_arp_add(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 		/* Temporary, changes before end of function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		hlist_for_each_entry(tmp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 				     &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 			if (entry != tmp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 			    !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 				/* Vcc to this host exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 				if (tmp->status > ESI_VC_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 					 * ESI_FLUSH_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 					 * ESI_FORWARD_DIRECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 					entry->vcc = tmp->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 					entry->old_push = tmp->old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 				entry->status = tmp->status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) 	if (remoteflag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 		entry->flags |= LEC_REMOTE_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 		entry->flags &= ~LEC_REMOTE_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 		entry->status = ESI_VC_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 		send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	pr_debug("After update2\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922)  * Notifies: Vcc setup ready
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	      struct atm_vcc *vcc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 	      void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 	int i, found_entry = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	/* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 	if (ioc_data->receive == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 		pr_debug("LEC_ARP: Attaching mcast forward\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 		entry = lec_arp_find(priv, bus_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 		if (!entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 			pr_info("LEC_ARP: Multicast entry not found!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 		memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 		entry->recv_vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 		entry->old_recv_push = old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 		entry = make_entry(priv, bus_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 		if (entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 		del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 		memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 		entry->recv_vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 		entry->old_recv_push = old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 		hlist_add_head(&entry->next, &priv->mcast_fwds);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 	} else if (ioc_data->receive == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) 		 * Vcc which we don't want to make default vcc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 		 * attach it anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 		pr_debug("LEC_ARP:Attaching data direct, not default: %*phN\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 			 ATM_ESA_LEN, ioc_data->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 		entry = make_entry(priv, bus_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 		if (entry == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 		memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 		eth_zero_addr(entry->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 		entry->recv_vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 		entry->old_recv_push = old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 		entry->status = ESI_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 		entry->timer.expires = jiffies + priv->vcc_timeout_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 		entry->timer.function = lec_arp_expire_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 		hlist_add_head(&entry->next, &priv->lec_no_forward);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 		add_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 	pr_debug("LEC_ARP:Attaching data direct, default: %*phN\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 		 ATM_ESA_LEN, ioc_data->atm_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 		hlist_for_each_entry(entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) 				     &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) 			if (memcmp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 			    (ioc_data->atm_addr, entry->atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 			     ATM_ESA_LEN) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 				pr_debug("LEC_ARP: Attaching data direct\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 				pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 					 entry->vcc ? entry->vcc->vci : 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 					 entry->recv_vcc ? entry->recv_vcc->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 					 vci : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 				found_entry = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 				del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 				entry->vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 				entry->old_push = old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 				if (entry->status == ESI_VC_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 					if (priv->maximum_unknown_frame_count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 					    == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 						entry->status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 						    ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 					else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 						entry->timestamp = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 						entry->status =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 						    ESI_FLUSH_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) 						send_to_lecd(priv, l_flush_xmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 							     NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) 							     entry->atm_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) 							     NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 					}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) 				} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) 					 * They were forming a connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) 					 * to us, and we to them. Our
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 					 * ATM address is numerically lower
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 					 * than theirs, so we make connection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 					 * we formed into default VCC (8.1.11).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) 					 * Connection they made gets torn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 					 * down. This might confuse some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) 					 * clients. Can be changed if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) 					 * someone reports trouble...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 					;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	if (found_entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) 		pr_debug("After vcc was added\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 		dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 	 * Not found, snatch address from first data packet that arrives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	 * from this vcc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	entry = make_entry(priv, bus_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	entry->vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	entry->old_push = old_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	eth_zero_addr(entry->mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) 	entry->status = ESI_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 	hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) 	entry->timer.expires = jiffies + priv->vcc_timeout_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) 	entry->timer.function = lec_arp_expire_vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	add_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 	pr_debug("After vcc was added\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 	pr_debug("%lx\n", tran_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 		hlist_for_each_entry(entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 				     &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 			if (entry->flush_tran_id == tran_id &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 			    entry->status == ESI_FLUSH_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 				struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 				struct atm_vcc *vcc = entry->vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) 				lec_arp_hold(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 				spin_unlock_irqrestore(&priv->lec_arp_lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) 						       flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) 				while ((skb = skb_dequeue(&entry->tx_wait)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 					lec_send(vcc, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 				entry->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 				entry->status = ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 				lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 				pr_debug("LEC_ARP: Flushed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 				goto restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) 	dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) lec_set_flush_tran_id(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 		      const unsigned char *atm_addr, unsigned long tran_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) 		hlist_for_each_entry(entry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) 				     &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 			if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 				entry->flush_tran_id = tran_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) 				pr_debug("Set flush transaction id to %lx for %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 					 tran_id, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 	unsigned char mac_addr[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) 		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	struct lec_arp_table *to_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 	struct lec_vcc_priv *vpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 	vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	if (!vpriv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) 	vpriv->xoff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 	vpriv->old_pop = vcc->pop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) 	vcc->user_back = vpriv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) 	vcc->pop = lec_pop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	to_add = make_entry(priv, mac_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 	if (!to_add) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 		vcc->pop = vpriv->old_pop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 		kfree(vpriv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 	memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	to_add->status = ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 	to_add->flags |= LEC_PERMANENT_FLAG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	to_add->vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) 	to_add->old_push = vcc->push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 	vcc->push = lec_push;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) 	priv->mcast_vcc = vcc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) 	lec_arp_add(priv, to_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	struct lec_arp_table *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 	for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) 		hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) 					  &priv->lec_arp_tables[i], next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 			if (vcc == entry->vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 				lec_arp_remove(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 				lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 				if (priv->mcast_vcc == vcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 					priv->mcast_vcc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 				  &priv->lec_arp_empty_ones, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 		if (entry->vcc == vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 			lec_arp_clear_vccs(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 			del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 			hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 			lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 	hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) 				  &priv->lec_no_forward, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) 		if (entry->recv_vcc == vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 			lec_arp_clear_vccs(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 			del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 			hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 			lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	hlist_for_each_entry_safe(entry, next, &priv->mcast_fwds, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 		if (entry->recv_vcc == vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 			lec_arp_clear_vccs(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 			/* No timer, LANEv2 7.1.20 and 2.3.5.3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 			hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 			lec_arp_put(entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	dump_arp_table(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) lec_arp_check_empties(struct lec_priv *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 		      struct atm_vcc *vcc, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	struct hlist_node *next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	struct lec_arp_table *entry, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 	struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	unsigned char *src = hdr->h_source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	spin_lock_irqsave(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	hlist_for_each_entry_safe(entry, next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 				  &priv->lec_arp_empty_ones, next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 		if (vcc == entry->vcc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 			del_timer(&entry->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 			ether_addr_copy(entry->mac_addr, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 			entry->status = ESI_FORWARD_DIRECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 			entry->last_used = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 			/* We might have got an entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 			tmp = lec_arp_find(priv, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 			if (tmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 				lec_arp_remove(priv, tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 				lec_arp_put(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 			hlist_del(&entry->next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 			lec_arp_add(priv, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) MODULE_LICENSE("GPL");