^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GPL-2.0
^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) X.25 Device Driver Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) ============================-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Version 1.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Jonathan Naylor 26.12.96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) This is a description of the messages to be passed between the X.25 Packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) Layer and the X.25 device driver. They are designed to allow for the easy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) setting of the LAPB mode from within the Packet Layer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) The X.25 device driver will be coded normally as per the Linux device driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) standards. Most X.25 device drivers will be moderately similar to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) already existing Ethernet device drivers. However unlike those drivers, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) X.25 device driver has a state associated with it, and this information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) needs to be passed to and from the Packet Layer for proper operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) All messages are held in sk_buff's just like real data to be transmitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) over the LAPB link. The first byte of the skbuff indicates the meaning of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) the rest of the skbuff, if any more information does exist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) Packet Layer to Device Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) First Byte = 0x00 (X25_IFACE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) This indicates that the rest of the skbuff contains data to be transmitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) over the LAPB link. The LAPB link should already exist before any data is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) passed down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) First Byte = 0x01 (X25_IFACE_CONNECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) Establish the LAPB link. If the link is already established then the connect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) confirmation message should be returned as soon as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) First Byte = 0x02 (X25_IFACE_DISCONNECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) Terminate the LAPB link. If it is already disconnected then the disconnect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) confirmation message should be returned as soon as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) First Byte = 0x03 (X25_IFACE_PARAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) LAPB parameters. To be defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) Device Driver to Packet Layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) -----------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) First Byte = 0x00 (X25_IFACE_DATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) This indicates that the rest of the skbuff contains data that has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) received over the LAPB link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) First Byte = 0x01 (X25_IFACE_CONNECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) LAPB link has been established. The same message is used for both a LAPB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) link connect_confirmation and a connect_indication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) First Byte = 0x02 (X25_IFACE_DISCONNECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) LAPB link has been terminated. This same message is used for both a LAPB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) link disconnect_confirmation and a disconnect_indication.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) First Byte = 0x03 (X25_IFACE_PARAMS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) LAPB parameters. To be defined.
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) Possible Problems
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) =================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) (Henner Eisen, 2000-10-28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) The X.25 packet layer protocol depends on a reliable datalink service.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) The LAPB protocol provides such reliable service. But this reliability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) is not preserved by the Linux network device driver interface:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) - With Linux 2.4.x (and above) SMP kernels, packet ordering is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) preserved. Even if a device driver calls netif_rx(skb1) and later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) netif_rx(skb2), skb2 might be delivered to the network layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) earlier that skb1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) - Data passed upstream by means of netif_rx() might be dropped by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) kernel if the backlog queue is congested.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) The X.25 packet layer protocol will detect this and reset the virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) call in question. But many upper layer protocols are not designed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) handle such N-Reset events gracefully. And frequent N-Reset events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) will always degrade performance.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) Thus, driver authors should make netif_rx() as reliable as possible:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) SMP re-ordering will not occur if the driver's interrupt handler is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) always executed on the same CPU. Thus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) - Driver authors should use irq affinity for the interrupt handler.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) The probability of packet loss due to backlog congestion can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) reduced by the following measures or a combination thereof:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) (1) Drivers for kernel versions 2.4.x and above should always check the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return value of netif_rx(). If it returns NET_RX_DROP, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) driver's LAPB protocol must not confirm reception of the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) to the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) This will reliably suppress packet loss. The LAPB protocol will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) automatically cause the peer to re-transmit the dropped packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) The lapb module interface was modified to support this. Its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) data_indication() method should now transparently pass the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) netif_rx() return value to the (lapb module) caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) (2) Drivers for kernel versions 2.2.x should always check the global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) variable netdev_dropping when a new frame is received. The driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) should only call netif_rx() if netdev_dropping is zero. Otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) the driver should not confirm delivery of the frame and drop it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) Alternatively, the driver can queue the frame internally and call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) netif_rx() later when netif_dropping is 0 again. In that case, delivery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) confirmation should also be deferred such that the internal queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) cannot grow to much.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) This will not reliably avoid packet loss, but the probability
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) of packet loss in netif_rx() path will be significantly reduced.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) (3) Additionally, driver authors might consider to support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) CONFIG_NET_HW_FLOWCONTROL. This allows the driver to be woken up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) when a previously congested backlog queue becomes empty again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) The driver could uses this for flow-controlling the peer by means
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) of the LAPB protocol's flow-control service.