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-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) Jonathan Naylor G4KLX (g4klx@g4klx.demon.co.uk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/sockios.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/net.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <net/ax25.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/rose.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  *	This procedure is passed a buffer descriptor for an iframe. It builds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *	the rest of the control part of the frame and then writes it out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void rose_send_iframe(struct sock *sk, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	skb->data[2] |= (rose->vr << 5) & 0xE0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	skb->data[2] |= (rose->vs << 1) & 0x0E;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	rose_start_idletimer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	rose_transmit_link(skb, rose->neighbour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) void rose_kick(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	struct sk_buff *skb, *skbn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	unsigned short start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	if (rose->state != ROSE_STATE_3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (rose->condition & ROSE_COND_PEER_RX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (!skb_peek(&sk->sk_write_queue))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	start = (skb_peek(&rose->ack_queue) == NULL) ? rose->va : rose->vs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	end   = (rose->va + sysctl_rose_window_size) % ROSE_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (start == end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	rose->vs = start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 * Transmit data until either we're out of data to send or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	 * the window is full.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	skb  = skb_dequeue(&sk->sk_write_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			skb_queue_head(&sk->sk_write_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		skb_set_owner_w(skbn, sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		 * Transmit the frame copy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		rose_send_iframe(sk, skbn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		rose->vs = (rose->vs + 1) % ROSE_MODULUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		 * Requeue the original data frame.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		skb_queue_tail(&rose->ack_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	} while (rose->vs != end &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		 (skb = skb_dequeue(&sk->sk_write_queue)) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	rose->vl         = rose->vr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	rose->condition &= ~ROSE_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * The following routines are taken from page 170 of the 7th ARRL Computer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * Networking Conference paper, as is the whole state machine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void rose_enquiry_response(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct rose_sock *rose = rose_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (rose->condition & ROSE_COND_OWN_RX_BUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		rose_write_internal(sk, ROSE_RNR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		rose_write_internal(sk, ROSE_RR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	rose->vl         = rose->vr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	rose->condition &= ~ROSE_COND_ACK_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	rose_stop_timer(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }