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