Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

sdla_fr.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002 * sdla_fr.c     WANPIPE(tm) Multiprotocol WAN Link Driver. Frame relay module.
00003 *
00004 * Author(s):    Nenad Corbic  <ncorbic@sangoma.com>
00005 *               Gideon Hack
00006 *
00007 * Copyright:    (c) 1995-1999 Sangoma Technologies Inc.
00008 *
00009 *               This program is free software; you can redistribute it and/or
00010 *               modify it under the terms of the GNU General Public License
00011 *               as published by the Free Software Foundation; either version
00012 *               2 of the License, or (at your option) any later version.
00013 * ============================================================================
00014 * Nov 08, 1999  Nenad Corbic    o Combined all debug UDP calls into one function
00015 *                               o Removed the ARP support. This has to be done
00016 *                                 in the next version.
00017 *                               o Only a Node can implement NO signalling.
00018 *                                 Initialize DLCI during if_open() if NO 
00019 *                                 signalling.
00020 *                               o Took out IPX support, implement in next
00021 *                                 version
00022 * Sep 29, 1999  Nenad Corbic    o Added SMP support and changed the update
00023 *                                 function to use timer interrupt.
00024 *                               o Fixed the CIR bug:  Set the value of BC
00025 *                                 to CIR when the CIR is enabled.
00026 *                               o Updated comments, statistics and tracing.
00027 * Jun 02, 1999  Gideon Hack     o Updated for S514 support.
00028 * Sep 18, 1998  Jaspreet Singh  o Updated for 2.2.X kernels.
00029 * Jul 31, 1998  Jaspreet Singh  o Removed wpf_poll routine.  The channel/DLCI 
00030 *                                 status is received through an event interrupt.
00031 * Jul 08, 1998  David Fong      o Added inverse ARP support.
00032 * Mar 26, 1997  Jaspreet Singh  o Returning return codes for failed UDP cmds.
00033 * Jan 28, 1997  Jaspreet Singh  o Improved handling of inactive DLCIs.
00034 * Dec 30, 1997  Jaspreet Singh  o Replaced dev_tint() with mark_bh(NET_BH)
00035 * Dec 16, 1997  Jaspreet Singh  o Implemented Multiple IPX support.
00036 * Nov 26, 1997  Jaspreet Singh  o Improved load sharing with multiple boards
00037 *                               o Added Cli() to protect enabling of interrupts
00038 *                                 while polling is called.
00039 * Nov 24, 1997  Jaspreet Singh  o Added counters to avoid enabling of interrupts
00040 *                                 when they have been disabled by another
00041 *                                 interface or routine (eg. wpf_poll).
00042 * Nov 06, 1997  Jaspreet Singh  o Added INTR_TEST_MODE to avoid polling 
00043 *                                 routine disable interrupts during interrupt
00044 *                                 testing.
00045 * Oct 20, 1997  Jaspreet Singh  o Added hooks in for Router UP time.
00046 * Oct 16, 1997  Jaspreet Singh  o The critical flag is used to maintain flow
00047 *                                 control by avoiding RACE conditions.  The
00048 *                                 cli() and restore_flags() are taken out.
00049 *                                 The fr_channel structure is appended for 
00050 *                                 Driver Statistics.
00051 * Oct 15, 1997  Farhan Thawar    o updated if_send() and receive for IPX
00052 * Aug 29, 1997  Farhan Thawar    o Removed most of the cli() and sti()
00053 *                                o Abstracted the UDP management stuff
00054 *                                o Now use tbusy and critical more intelligently
00055 * Jul 21, 1997  Jaspreet Singh   o Can configure T391, T392, N391, N392 & N393
00056 *                                  through router.conf.
00057 *                                o Protected calls to sdla_peek() by adDing 
00058 *                                  save_flags(), cli() and restore_flags().
00059 *                                o Added error message for Inactive DLCIs in
00060 *                                  fr_event() and update_chan_state().
00061 *                                o Fixed freeing up of buffers using kfree() 
00062 *                                  when packets are received.
00063 * Jul 07, 1997  Jaspreet Singh   o Added configurable TTL for UDP packets 
00064 *                                o Added ability to discard multicast and 
00065 *                                  broadcast source addressed packets
00066 * Jun 27, 1997  Jaspreet Singh   o Added FT1 monitor capabilities 
00067 *                                  New case (0x44) statement in if_send routine 
00068 *                                  Added a global variable rCount to keep track
00069 *                                  of FT1 status enabled on the board.
00070 * May 29, 1997  Jaspreet Singh   o Fixed major Flow Control Problem
00071 *                                  With multiple boards a problem was seen where
00072 *                                  the second board always stopped transmitting
00073 *                                  packet after running for a while. The code
00074 *                                  got into a stage where the interrupts were
00075 *                                  disabled and dev->tbusy was set to 1.
00076 *                                  This caused the If_send() routine to get into
00077 *                                  the if clause for it(0,dev->tbusy) 
00078 *                                  forever.
00079 *                                  The code got into this stage due to an 
00080 *                                  interrupt occurring within the if clause for 
00081 *                                  set_bit(0,dev->tbusy).  Since an interrupt 
00082 *                                  disables furhter transmit interrupt and 
00083 *                                  makes dev->tbusy = 0, this effect was undone 
00084 *                                  by making dev->tbusy = 1 in the if clause.
00085 *                                  The Fix checks to see if Transmit interrupts
00086 *                                  are disabled then do not make dev->tbusy = 1
00087 *                                  Introduced a global variable: int_occur and
00088 *                                  added tx_int_enabled in the wan_device 
00089 *                                  structure.   
00090 * May 21, 1997  Jaspreet Singh   o Fixed UDP Management for multiple
00091 *                                  boards.
00092 *
00093 * Apr 25, 1997  Farhan Thawar    o added UDP Management stuff
00094 *                                o fixed bug in if_send() and tx_intr() to
00095 *                                  sleep and wakeup all devices
00096 * Mar 11, 1997  Farhan Thawar   Version 3.1.1
00097 *                                o fixed (+1) bug in fr508_rx_intr()
00098 *                                o changed if_send() to return 0 if
00099 *                                  wandev.critical() is true
00100 *                                o free socket buffer in if_send() if
00101 *                                  returning 0 
00102 *                                o added tx_intr() routine
00103 * Jan 30, 1997  Gene Kozin      Version 3.1.0
00104 *                                o implemented exec() entry point
00105 *                                o fixed a bug causing driver configured as
00106 *                                  a FR switch to be stuck in WAN_
00107 *                                  mode
00108 * Jan 02, 1997  Gene Kozin      Initial version.
00109 *****************************************************************************/
00110 
00111 #include <linux/version.h>
00112 #include <linux/kernel.h>       /* printk(), and other useful stuff */
00113 #include <linux/stddef.h>       /* offsetof(), etc. */
00114 #include <linux/errno.h>        /* return codes */
00115 #include <linux/string.h>       /* inline memset(), etc. */
00116 #include <linux/malloc.h>       /* kmalloc(), kfree() */
00117 #include <linux/wanrouter.h>    /* WAN router definitions */
00118 #include <linux/wanpipe.h>      /* WANPIPE common user API definitions */
00119 #include <linux/if_arp.h>       /* ARPHRD_* defines */
00120 #include <asm/byteorder.h>      /* htons(), etc. */
00121 #include <asm/io.h>             /* for inb(), outb(), etc. */
00122 #include <linux/time.h>         /* for do_gettimeofday */       
00123 #include <linux/in.h>           /* sockaddr_in */
00124 #include <linux/inet.h>         /* in_ntoa(), etc... */
00125 #include <asm/uaccess.h>
00126 #include <linux/inetdevice.h>
00127 #include <linux/ip.h>
00128 #include <net/route.h>          /* Dynamic Route Creation */
00129 #include <linux/if.h>
00130 
00131 #include <linux/sdla_fr.h>      /* frame relay firmware API definitions */
00132 #if LINUX_VERSION_CODE < 0x020125
00133 #define test_and_set_bit set_bit
00134 #endif
00135  
00136 /****** Defines & Macros ****************************************************/
00137 
00138 #define MAX_CMD_RETRY   10              /* max number of firmware retries */
00139 
00140 #define FR_HEADER_LEN   8               /* max encapsulation header size */
00141 #define FR_CHANNEL_MTU  1500            /* unfragmented logical channel MTU */
00142 
00143 /* Q.922 frame types */
00144 #define Q922_UI         0x03            /* Unnumbered Info frame */
00145 #define Q922_XID        0xAF            
00146 
00147 /* DLCI configured or not */
00148 #define DLCI_NOT_CONFIGURED     0x00
00149 #define DLCI_CONFIG_PENDING     0x01
00150 #define DLCI_CONFIGURED         0x02
00151 
00152 /* CIR enabled or not */
00153 #define CIR_ENABLED     0x00
00154 #define CIR_DISABLED    0x01
00155 
00156 #define WANPIPE 0x00
00157 #define API     0x01
00158 #define FRAME_RELAY_API 1
00159 
00160 /* For handle_IPXWAN() */
00161 #define CVHexToAscii(b) (((unsigned char)(b) > (unsigned char)9) ? ((unsigned char)'A' + ((unsigned char)(b) - (unsigned char)10)) : ((unsigned char)'0' + (unsigned char)(b)))
00162  
00163 /****** Data Structures *****************************************************/
00164 
00165 /* This is an extention of the 'struct device' we create for each network
00166  * interface to keep the rest of channel-specific data.
00167  */
00168 typedef struct fr_channel
00169 {
00170         char name[WAN_IFNAME_SZ+1];     /* interface name, ASCIIZ */
00171         unsigned dlci_configured  ;     /* check whether configured or not */
00172         unsigned cir_status;            /* check whether CIR enabled or not */
00173         unsigned dlci;                  /* logical channel number */
00174         unsigned cir;                   /* committed information rate */
00175         unsigned bc;                    /* committed burst size */
00176         unsigned be;                    /* excess burst size */
00177         unsigned mc;                    /* multicast support on or off */
00178         unsigned tx_int_status;         /* Transmit Interrupt Status */ 
00179         unsigned short pkt_length;      /* Packet Length */
00180         unsigned long router_start_time;/* Router start time in seconds */
00181         unsigned long tick_counter;     /* counter for transmit time out */
00182         char dev_pending_devtint;       /* interface pending dev_tint() */
00183         char state;                     /* channel state */
00184         void *dlci_int_interface;       /* pointer to the DLCI Interface */ 
00185         unsigned long IB_addr;          /* physical address of Interface Byte */
00186         unsigned long state_tick;       /* time of the last state change */
00187         unsigned char enable_IPX;       /* Enable/Disable the use of IPX */
00188         unsigned long network_number;   /* Internal Network Number for IPX*/
00189         sdla_t *card;                   /* -> owner */
00190         unsigned route_flag;            /* Add/Rem dest addr in route tables */
00191         unsigned inarp;                 /* Inverse Arp Request status */ 
00192         int inarp_interval;             /* Time between InArp Requests */
00193         unsigned long inarp_tick;       /* InArp jiffies tick counter */
00194         struct net_device_stats ifstats;        /* interface statistics */
00195         if_send_stat_t drvstats_if_send;
00196         rx_intr_stat_t drvstats_rx_intr;
00197         pipe_mgmt_stat_t drvstats_gen;
00198 
00199         unsigned char usedby;  /* Used by WANPIPE or API */
00200 
00201         unsigned long router_up_time;
00202 
00203         unsigned short transmit_length;
00204         char transmit_buffer[FR_MAX_NO_DATA_BYTES_IN_FRAME];
00205 } fr_channel_t;
00206 
00207 /* Route Flag options */
00208 #define NO_ROUTE        0x00
00209 #define ADD_ROUTE       0x01
00210 #define ROUTE_ADDED     0x02
00211 #define REMOVE_ROUTE    0x03
00212 
00213 /* inarp options */
00214 #define INARP_NONE              0x00
00215 #define INARP_REQUEST           0x01
00216 #define INARP_CONFIGURED        0x02
00217 
00218 /* reasons for enabling the timer interrupt on the adapter */
00219 #define TMR_INT_ENABLED_UDP     0x01
00220 #define TMR_INT_ENABLED_UPDATE  0x02
00221 
00222 
00223 typedef struct dlci_status
00224 {
00225         unsigned short dlci     PACKED;
00226         unsigned char state     PACKED;
00227 } dlci_status_t;
00228 
00229 typedef struct dlci_IB_mapping
00230 {
00231         unsigned short dlci             PACKED;
00232         unsigned long  addr_value       PACKED;
00233 } dlci_IB_mapping_t;
00234 
00235 /* This structure is used for DLCI list Tx interrupt mode.  It is used to
00236    enable interrupt bit and set the packet length for transmission
00237  */
00238 typedef struct fr_dlci_interface 
00239 {
00240         unsigned char gen_interrupt     PACKED;
00241         unsigned short packet_length    PACKED;
00242         unsigned char reserved          PACKED;
00243 } fr_dlci_interface_t; 
00244 
00245 /* variable for keeping track of enabling/disabling FT1 monitor status */
00246 static int rCount = 0;
00247 
00248 extern int ip_rt_ioctl(unsigned int, void *);
00249 extern void disable_irq(unsigned int);
00250 extern void enable_irq(unsigned int);
00251 
00252 /* variable for keeping track of number of interrupts generated during 
00253  * interrupt test routine 
00254  */
00255 static int Intr_test_counter;
00256 /****** Function Prototypes *************************************************/
00257 
00258 /* WAN link driver entry points. These are called by the WAN router module. */
00259 static int update(wan_device_t *wandev);
00260 static int new_if(wan_device_t *wandev, struct device *dev, wanif_conf_t *conf);
00261 static int del_if(wan_device_t *wandev, struct device *dev);
00262 
00263 /* WANPIPE-specific entry points */
00264 static int wpf_exec(struct sdla *card, void *u_cmd, void *u_data);
00265 
00266 /* Network device interface */
00267 static int if_init(struct device *dev);
00268 static int if_open(struct device *dev);
00269 static int if_close(struct device *dev);
00270 static int if_header(struct sk_buff *skb, struct device *dev, unsigned short type, void *daddr, void *saddr, unsigned len);
00271 static int if_rebuild_hdr(struct sk_buff *skb);
00272 static int if_send(struct sk_buff *skb, struct device *dev);
00273 static int chk_bcast_mcast_addr(sdla_t *card, struct device* dev,
00274                                 struct sk_buff *skb);
00275 static struct net_device_stats *if_stats(struct device *dev);
00276 
00277 /* Interrupt handlers */
00278 static void fr_isr(sdla_t *card);
00279 static void rx_intr(sdla_t *card);
00280 static void tx_intr(sdla_t *card);
00281 static void timer_intr(sdla_t *card);
00282 static void spur_intr(sdla_t *card);
00283 
00284 /* Frame relay firmware interface functions */
00285 static int fr_read_version(sdla_t *card, char *str);
00286 static int fr_configure(sdla_t *card, fr_conf_t *conf);
00287 static int fr_dlci_configure(sdla_t *card, fr_dlc_conf_t *conf, unsigned dlci);
00288 static int fr_init_dlci (sdla_t *card, fr_channel_t *chan);
00289 static int fr_set_intr_mode (sdla_t *card, unsigned mode, unsigned mtu, unsigned short timeout);
00290 static int fr_comm_enable(sdla_t *card);
00291 static int fr_comm_disable(sdla_t *card);
00292 static int fr_get_err_stats(sdla_t *card);
00293 static int fr_get_stats(sdla_t *card);
00294 static int fr_add_dlci(sdla_t *card, int dlci);
00295 static int fr_activate_dlci(sdla_t *card, int dlci);
00296 static int fr_delete_dlci (sdla_t* card, int dlci);
00297 static int fr_issue_isf(sdla_t *card, int isf);
00298 static int fr_send(sdla_t *card, int dlci, unsigned char attr, int len,
00299         void *buf);
00300 
00301 /* Firmware asynchronous event handlers */
00302 static int fr_event(sdla_t *card, int event, fr_mbox_t *mbox);
00303 static int fr_modem_failure(sdla_t *card, fr_mbox_t *mbox);
00304 static int fr_dlci_change(sdla_t *card, fr_mbox_t *mbox);
00305 
00306 /* Miscellaneous functions */
00307 static int update_chan_state(struct device *dev);
00308 static void set_chan_state(struct device *dev, int state);
00309 static struct device *find_channel(sdla_t *card, unsigned dlci);
00310 static int is_tx_ready(sdla_t *card, fr_channel_t *chan);
00311 static unsigned int dec_to_uint(unsigned char *str, int len);
00312 static int reply_udp( unsigned char *data, unsigned int mbox_len );
00313 
00314 static int intr_test( sdla_t* card );
00315 static void init_chan_statistics( fr_channel_t* chan );
00316 static void init_global_statistics( sdla_t* card );
00317 static void read_DLCI_IB_mapping( sdla_t* card, fr_channel_t* chan );
00318 static void setup_for_delayed_transmit(struct device* dev, void* buf,
00319         unsigned len);
00320 
00321 
00322 /* Inverse ARP and Dynamic routing functions */
00323 int process_ARP(arphdr_1490_t *ArpPacket, sdla_t *card, struct device *dev);
00324 int is_arp(void *buf);
00325 int send_inarp_request(sdla_t *card, struct device *dev);
00326 
00327 /* Udp management functions */
00328 static int process_udp_mgmt_pkt(sdla_t *card);
00329 static int udp_pkt_type( struct sk_buff *skb, sdla_t *card );
00330 static int store_udp_mgmt_pkt(int udp_type, char udp_pkt_src, sdla_t* card,
00331                                 struct sk_buff *skb, int dlci);
00332 
00333 /* IPX functions */
00334 static void switch_net_numbers(unsigned char *sendpacket,
00335         unsigned long network_number, unsigned char incoming);
00336 
00337 static int handle_IPXWAN(unsigned char *sendpacket, char *devname,
00338         unsigned char enable_IPX, unsigned long network_number);
00339 
00340 /* Lock Functions: SMP supported */
00341 void    s508_s514_unlock(sdla_t *card, unsigned long *smp_flags);
00342 void    s508_s514_lock(sdla_t *card, unsigned long *smp_flags);
00343 
00344 unsigned short calc_checksum (char *, int);
00345 
00346 
00347 /****** Public Functions ****************************************************/
00348 
00349 /*============================================================================
00350  * Frame relay protocol initialization routine.
00351  *
00352  * This routine is called by the main WANPIPE module during setup.  At this
00353  * point adapter is completely initialized and firmware is running.
00354  *  o read firmware version (to make sure it's alive)
00355  *  o configure adapter
00356  *  o initialize protocol-specific fields of the adapter data space.
00357  *
00358  * Return:      0       o.k.
00359  *              < 0     failure.
00360  */
00361 int wpf_init(sdla_t *card, wandev_conf_t *conf)
00362 {
00363 
00364         int err;
00365 
00366         union
00367         {
00368                 char str[80];
00369                 fr_conf_t cfg;
00370         } u;
00371         fr_buf_info_t* buf_info;
00372         int i;
00373 
00374         /* Verify configuration ID */
00375         if (conf->config_id != WANCONFIG_FR) {
00376                 
00377                 printk(KERN_INFO "%s: invalid configuration ID %u!\n",
00378                         card->devname, conf->config_id);
00379                 return -EINVAL;
00380         
00381         }
00382 
00383         /* Initialize protocol-specific fields of adapter data space */
00384         switch (card->hw.fwid) {
00385         
00386                 case SFID_FR508:
00387                         card->mbox  = (void*)(card->hw.dpmbase + 
00388                                         FR508_MBOX_OFFS);
00389                         card->flags = (void*)(card->hw.dpmbase + 
00390                                         FR508_FLAG_OFFS);
00391                         if(card->hw.type == SDLA_S514) {
00392                                 card->mbox += FR_MB_VECTOR;
00393                                 card->flags += FR_MB_VECTOR;
00394                         }
00395                         card->isr = &fr_isr;
00396                         break;
00397 
00398                 default:
00399                         return -EINVAL;
00400         }
00401 
00402         /* Read firmware version.  Note that when adapter initializes, it
00403          * clears the mailbox, so it may appear that the first command was
00404          * executed successfully when in fact it was merely erased. To work
00405          * around this, we execute the first command twice.
00406          */
00407 
00408         if (fr_read_version(card, NULL) || fr_read_version(card, u.str))
00409                 return -EIO;
00410 
00411         printk(KERN_INFO "%s: running frame relay firmware v%s\n",
00412                 card->devname, u.str);
00413 
00414         /* Adjust configuration */
00415         conf->mtu += FR_HEADER_LEN;
00416         conf->mtu = (conf->mtu >= MIN_LGTH_FR_DATA_CFG) ?
00417                         min(conf->mtu, FR_MAX_NO_DATA_BYTES_IN_FRAME) :
00418                         FR_CHANNEL_MTU + FR_HEADER_LEN;
00419      
00420         conf->bps = min(conf->bps, 2048000);
00421 
00422         /* Initialze the configuration structure sent to the board to zero */
00423         memset(&u.cfg, 0, sizeof(u.cfg));
00424 
00425         memset(card->u.f.dlci_to_dev_map, 0, sizeof(card->u.f.dlci_to_dev_map));
00426         
00427         /* Configure adapter firmware */
00428         
00429         u.cfg.mtu       = conf->mtu;
00430         u.cfg.kbps      = conf->bps / 1000;
00431 
00432         u.cfg.cir_fwd = u.cfg.cir_bwd = 16;
00433         u.cfg.bc_fwd  = u.cfg.bc_bwd = 16;
00434         
00435         u.cfg.options   = 0x0000;
00436         printk(KERN_INFO "%s: Global CIR enabled by Default\n", card->devname);
00437         
00438         switch (conf->u.fr.signalling) {
00439 
00440                 case WANOPT_FR_ANSI:
00441                         u.cfg.options = 0x0000; 
00442                         break;          
00443         
00444                 case WANOPT_FR_Q933:    
00445                         u.cfg.options |= 0x0200; 
00446                         break;
00447         
00448                 case WANOPT_FR_LMI:     
00449                         u.cfg.options |= 0x0400; 
00450                         break;
00451 
00452                 case WANOPT_NO:
00453                         u.cfg.options |= 0x0800; 
00454                         break;
00455                 default:
00456                         printk(KERN_INFO "%s: Illegal Signalling option\n",
00457                                         card->wandev.name);
00458                         return -EINVAL;
00459         }
00460 
00461 
00462         card->wandev.signalling = conf->u.fr.signalling;
00463 
00464         if (conf->station == WANOPT_CPE) {
00465 
00466 
00467                 if (conf->u.fr.signalling == WANOPT_NO){
00468                         printk(KERN_INFO 
00469                                 "%s: ERROR - For NO signalling, station must be set to Node!",
00470                                          card->devname);
00471                         return -EINVAL;
00472                 }
00473 
00474                 u.cfg.station = 0;
00475                 u.cfg.options |= 0x8000;        /* auto config DLCI */
00476                 card->u.f.dlci_num  = 0;
00477         
00478         } else {
00479 
00480                 u.cfg.station = 1;      /* switch emulation mode */
00481 
00482                 /* For switch emulation we have to create a list of dlci(s)
00483                  * that will be sent to be global SET_DLCI_CONFIGURATION 
00484                  * command in fr_configure() routine. 
00485                  */
00486 
00487                 card->u.f.dlci_num  = min(max(conf->u.fr.dlci_num, 1), 100);
00488         
00489                 for ( i = 0; i < card->u.f.dlci_num; i++) {
00490 
00491                         card->u.f.node_dlci[i] = (unsigned short) 
00492                                 conf->u.fr.dlci[i] ? conf->u.fr.dlci[i] : 16;
00493         
00494                 }
00495         }
00496 
00497         if (conf->clocking == WANOPT_INTERNAL)
00498                 u.cfg.port |= 0x0001;
00499 
00500         if (conf->interface == WANOPT_RS232)
00501                 u.cfg.port |= 0x0002;
00502 
00503         if (conf->u.fr.t391)
00504                 u.cfg.t391 = min(conf->u.fr.t391, 30);
00505         else
00506                 u.cfg.t391 = 5;
00507 
00508         if (conf->u.fr.t392)
00509                 u.cfg.t392 = min(conf->u.fr.t392, 30);
00510         else
00511                 u.cfg.t392 = 15;
00512 
00513         if (conf->u.fr.n391)
00514                 u.cfg.n391 = min(conf->u.fr.n391, 255);
00515         else
00516                 u.cfg.n391 = 2;
00517 
00518         if (conf->u.fr.n392)
00519                 u.cfg.n392 = min(conf->u.fr.n392, 10);
00520         else
00521                 u.cfg.n392 = 3; 
00522 
00523         if (conf->u.fr.n393)
00524                 u.cfg.n393 = min(conf->u.fr.n393, 10);
00525         else
00526                 u.cfg.n393 = 4;
00527 
00528         if (fr_configure(card, &u.cfg))
00529                 return -EIO;
00530 
00531         if (card->hw.type == SDLA_S514) {
00532         
00533                 buf_info = (void*)(card->hw.dpmbase + FR_MB_VECTOR +
00534                         FR508_RXBC_OFFS);
00535 
00536                 card->rxmb = (void*)(buf_info->rse_next + card->hw.dpmbase);
00537 
00538                 card->u.f.rxmb_base =
00539                         (void*)(buf_info->rse_base + card->hw.dpmbase); 
00540 
00541                 card->u.f.rxmb_last =
00542                         (void*)(buf_info->rse_base +
00543                         (buf_info->rse_num - 1) * sizeof(fr_rx_buf_ctl_t) +
00544                         card->hw.dpmbase);
00545         }
00546 
00547         else {  
00548                 buf_info = (void*)(card->hw.dpmbase + FR508_RXBC_OFFS);
00549 
00550                 card->rxmb = (void*)(buf_info->rse_next -
00551                         FR_MB_VECTOR + card->hw.dpmbase);
00552                 
00553                 card->u.f.rxmb_base =
00554                         (void*)(buf_info->rse_base -
00555                         FR_MB_VECTOR + card->hw.dpmbase);
00556                 
00557                 card->u.f.rxmb_last =
00558                         (void*)(buf_info->rse_base +
00559                         (buf_info->rse_num - 1) * sizeof(fr_rx_buf_ctl_t) -
00560                         FR_MB_VECTOR + card->hw.dpmbase);
00561         }
00562 
00563         card->u.f.rx_base = buf_info->buf_base;
00564         card->u.f.rx_top  = buf_info->buf_top;
00565 
00566         card->u.f.tx_interrupts_pending = 0;
00567 
00568         card->wandev.mtu        = conf->mtu;
00569         card->wandev.bps        = conf->bps;
00570         card->wandev.interface  = conf->interface;
00571         card->wandev.clocking   = conf->clocking;
00572         card->wandev.station    = conf->station;
00573         card->poll              = NULL; 
00574         card->exec              = &wpf_exec;
00575         card->wandev.update     = &update;
00576         card->wandev.new_if     = &new_if;
00577         card->wandev.del_if     = &del_if;
00578         card->wandev.state      = WAN_DISCONNECTED;
00579         card->wandev.ttl        = conf->ttl;
00580         card->wandev.udp_port   = conf->udp_port;       
00581 
00582         /* Intialize global statistics for a card */
00583         init_global_statistics( card );
00584 
00585         card->TracingEnabled          = 0;
00586 
00587         /* Interrupt Test */
00588         Intr_test_counter = 0;
00589         card->intr_mode = INTR_TEST_MODE;
00590         err = intr_test( card );
00591 
00592         if (err || (Intr_test_counter < MAX_INTR_TEST_COUNTER)) {
00593                 printk( 
00594                         "%s: Interrupt Test Failed, Counter: %i\n", 
00595                         card->devname, Intr_test_counter);
00596                 printk( "Please choose another interrupt\n");
00597                 err = -EIO;
00598                 return err;
00599         }
00600 
00601         printk(KERN_INFO "%s: Interrupt Test Passed, Counter: %i\n",
00602                         card->devname, Intr_test_counter);
00603 
00604 
00605         return 0;
00606 }
00607 
00608 /******* WAN Device Driver Entry Points *************************************/
00609 
00610 /*============================================================================
00611  * Update device status & statistics.
00612  */
00613 static int update (wan_device_t* wandev)
00614 {
00615         volatile sdla_t* card;
00616         unsigned long timeout;
00617         fr508_flags_t* flags;
00618 
00619         /* sanity checks */
00620         if ((wandev == NULL) || (wandev->private == NULL))
00621                 return -EFAULT;
00622 
00623         if (wandev->state == WAN_UNCONFIGURED)
00624                 return -ENODEV;
00625 
00626         if (test_bit(1, (void*)&wandev->critical))
00627                 return -EAGAIN;
00628 
00629         card = wandev->private;
00630         flags = card->flags;
00631 
00632 
00633         card->u.f.update_comms_stats = 1;
00634         card->u.f.timer_int_enabled |= TMR_INT_ENABLED_UPDATE;
00635         flags->imask |= FR_INTR_TIMER;
00636         timeout = jiffies;
00637         for(;;) {
00638                 if(card->u.f.update_comms_stats == 0)
00639                         break;
00640                 if ((jiffies - timeout) > (1 * HZ)){
00641                         card->u.f.update_comms_stats = 0;
00642                         return -EAGAIN;
00643                 }
00644         }
00645         return 0;
00646 }
00647 
00648 /*============================================================================
00649  * Create new logical channel.
00650  * This routine is called by the router when ROUTER_IFNEW IOCTL is being
00651  * handled.
00652  * o parse media- and hardware-specific configuration
00653  * o make sure that a new channel can be created
00654  * o allocate resources, if necessary
00655  * o prepare network device structure for registaration.
00656  *
00657  * Return:      0       o.k.
00658  *              < 0     failure (channel will not be created)
00659  */
00660 static int new_if (wan_device_t* wandev, struct device* dev, wanif_conf_t* conf)
00661 {
00662         sdla_t* card = wandev->private;
00663         fr_channel_t* chan;
00664         int dlci = 0;
00665         int err = 0;
00666         
00667         if ((conf->name[0] == '\0') || (strlen(conf->name) > WAN_IFNAME_SZ)) {
00668                 
00669                 printk(KERN_INFO "%s: invalid interface name!\n",
00670                         card->devname);
00671                 return -EINVAL;
00672         }
00673 
00674         /* allocate and initialize private data */
00675         chan = kmalloc(sizeof(fr_channel_t), GFP_KERNEL);
00676 
00677         if (chan == NULL)
00678                 return -ENOMEM;
00679 
00680         memset(chan, 0, sizeof(fr_channel_t));
00681         strcpy(chan->name, conf->name);
00682         chan->card = card;
00683  
00684         /* verify media address */
00685         if (is_digit(conf->addr[0])) {
00686 
00687                 dlci = dec_to_uint(conf->addr, 0);
00688 
00689                 if (dlci && (dlci <= HIGHEST_VALID_DLCI)) {
00690                 
00691                         chan->dlci = dlci;
00692                 
00693                 } else {
00694                 
00695                         printk(KERN_ERR
00696                                 "%s: invalid DLCI %u on interface %s!\n",
00697                                 wandev->name, dlci, chan->name);
00698                         err = -EINVAL;
00699                 }
00700 
00701         } else {
00702                 printk(KERN_ERR
00703                         "%s: invalid media address on interface %s!\n",
00704                         wandev->name, chan->name);
00705                 err = -EINVAL;
00706         }
00707 
00708         /* Setup wanpipe as a router (WANPIPE) or as an API */
00709         if(strcmp(conf->usedby, "WANPIPE") == 0){
00710                 printk(KERN_INFO "%s: Running in WANPIPE mode %s\n",
00711                         wandev->name, chan->name);
00712                 chan->usedby = WANPIPE;
00713 
00714         } else if(strcmp(conf->usedby, "API") == 0){
00715 
00716 #ifdef FRAME_RELAY_API
00717                 chan->usedby = API;
00718                 printk(KERN_INFO "%s: Running in API mode %s\n",
00719                         wandev->name, chan->name);
00720 #else
00721                 printk(KERN_INFO "%s: API Mode is not supported !\n",
00722                         wandev->name);
00723                 printk(KERN_INFO
00724                         "%s: API patch can be obtained from Sangoma Tech.\n",
00725                                 wandev->name);
00726                 err = -EINVAL;
00727 #endif
00728         }
00729 
00730         if (err) {
00731                 
00732                 kfree(chan);
00733                 return err;
00734         }
00735 
00736         card->u.f.dlci_to_dev_map[dlci] = dev;
00737  
00738         /* place cir,be,bc and other channel specific information into the
00739          * chan structure 
00740          */
00741         if (conf->cir) {
00742 
00743                 chan->cir = max( 1, min( conf->cir, 512 ) );
00744                 chan->cir_status = CIR_ENABLED; 
00745 
00746                 
00747                 /* If CIR is enabled, force BC to equal CIR
00748                  * this solves number of potential problems if CIR is 
00749                  * set and BC is not 
00750                  */
00751                 chan->bc = chan->cir;
00752 
00753                 if (conf->be){
00754                         chan->be = max( 0, min( conf->be, 511) ); 
00755                 }else{  
00756                         conf->be = 0;
00757                 }
00758 
00759                 printk (KERN_INFO "%s: CIR enabled for DLCI %i \n",
00760                                 wandev->name,chan->dlci);
00761                 printk (KERN_INFO "%s:     CIR = %i ; BC = %i ; BE = %i\n",
00762                                 wandev->name,chan->cir,chan->bc,chan->be);
00763 
00764 
00765         }else{
00766                 chan->cir_status = CIR_DISABLED;
00767                 printk (KERN_INFO "%s: CIR disabled for DLCI %i\n",
00768                                 wandev->name,chan->dlci);
00769         }
00770 
00771         chan->mc = conf->mc;
00772 
00773         /* FIXME: ARP is not supported by this frame relay verson */
00774         if (conf->inarp == WANOPT_YES){
00775                 printk(KERN_INFO "%s: ERROR - This version of WANPIPE doesn't support ARPs\n",
00776                                 card->devname);
00777         
00778                 //chan->inarp = conf->inarp ? INARP_REQUEST : INARP_NONE;
00779                 //chan->inarp_interval = conf->inarp_interval ? conf->inarp_interval : 10;
00780                 kfree(chan);
00781                 return -EINVAL;
00782         }else{
00783                 chan->inarp = INARP_NONE;
00784                 chan->inarp_interval = 10;
00785         }
00786 
00787         chan->dlci_configured = DLCI_NOT_CONFIGURED;    
00788 
00789 
00790         /*FIXME: IPX disabled in this WANPIPE version */
00791         if (conf->enable_IPX == WANOPT_YES){
00792                 printk(KERN_INFO "%s: ERROR - This version of WANPIPE doesn't support IPX\n",
00793                                 card->devname);
00794                 kfree(chan);
00795                 return -EINVAL;
00796         }else{
00797                 chan->enable_IPX = WANOPT_NO;
00798         }       
00799 
00800         if (conf->network_number){
00801                 chan->network_number = conf->network_number;
00802         }else{
00803                 chan->network_number = 0xDEADBEEF;
00804         }
00805 
00806         chan->route_flag = NO_ROUTE;
00807         
00808         init_chan_statistics(chan);
00809 
00810         chan->transmit_length = 0;
00811 
00812         /* prepare network device data space for registration */
00813         dev->name = chan->name;
00814         dev->init = &if_init;
00815         dev->priv = chan;
00816 
00817 
00818         /* Enable Interrupts and Communications */
00819         if (!wandev->new_if_cnt){
00820                 fr508_flags_t* flags = card->flags;
00821 
00822                 wandev->new_if_cnt++;
00823 
00824                 /* 
00825                 If you enable comms and then set ints, you get a Tx int as you
00826                 perform the SET_INT_TRIGGERS command. So, we only set int
00827                 triggers and then adjust the interrupt mask (to disable Tx ints)
00828                 before enabling comms. 
00829                 */      
00830                 if (fr_set_intr_mode(card, (FR_INTR_RXRDY | FR_INTR_TXRDY |
00831                         FR_INTR_DLC | FR_INTR_TIMER | FR_INTR_TX_MULT_DLCIs) ,
00832                         card->wandev.mtu, 0)) {
00833                         kfree(chan);
00834                         return -EIO;
00835                 }
00836 
00837                 flags->imask &= ~(FR_INTR_TXRDY | FR_INTR_TIMER);
00838  
00839                 if (fr_comm_enable(card)) {
00840                         kfree(chan);
00841                         return -EIO;
00842                 }       
00843                 wanpipe_set_state(card, WAN_CONNECTED);
00844         }
00845 
00846         return 0;
00847 }
00848 
00849 /*============================================================================
00850  * Delete logical channel.
00851  */
00852 static int del_if (wan_device_t* wandev, struct device* dev)
00853 {
00854         sdla_t *card = wandev->private;
00855 
00856         /* Execute shutdown very first time we enter del_if */
00857 
00858         if (!wandev->del_if_cnt) {
00859                 wandev->del_if_cnt++;
00860                 wanpipe_set_state(card, WAN_DISCONNECTED);
00861                 fr_set_intr_mode(card, 0, 0, 0);
00862                 fr_comm_disable(card);
00863         }
00864 
00865         if (dev->priv) {
00866                 kfree(dev->priv);
00867                 dev->priv = NULL;
00868         }
00869 
00870         return 0;
00871 }
00872 
00873 /****** WANPIPE-specific entry points ***************************************/
00874 
00875 /*============================================================================
00876  * Execute adapter interface command.
00877  */
00878 static int wpf_exec (struct sdla* card, void* u_cmd, void* u_data)
00879 {
00880         fr_mbox_t* mbox = card->mbox;
00881         int retry = MAX_CMD_RETRY;
00882         int err, len;
00883         fr_cmd_t cmd;
00884 
00885         if(copy_from_user((void*)&cmd, u_cmd, sizeof(cmd)))
00886                 return -EFAULT;
00887         /* XXX: should check cmd.length against size allocated for mbox->data */
00888         
00889         /* execute command */
00890         do
00891         {
00892                 memcpy(&mbox->cmd, &cmd, sizeof(cmd));
00893                 
00894                 if (cmd.length){
00895                         if( copy_from_user((void*)&mbox->data, u_data, cmd.length))
00896                                 return -EFAULT;
00897                 }
00898                 
00899                 if (sdla_exec(mbox))
00900                         err = mbox->cmd.result;
00901 
00902                 else return -EIO;
00903         
00904         } while (err && retry-- && fr_event(card, err, mbox));
00905 
00906         /* return result */
00907         if (copy_to_user(u_cmd, (void*)&mbox->cmd, sizeof(fr_cmd_t)))
00908                 return -EFAULT;
00909 
00910         len = mbox->cmd.length;
00911 
00912         if (len && u_data && !copy_to_user(u_data, (void*)&mbox->data, len))
00913                 return -EFAULT;
00914         return 0;
00915 
00916 }
00917 
00918 /****** Network Device Interface ********************************************/
00919 
00920 /*============================================================================
00921  * Initialize Linux network interface.
00922  *
00923  * This routine is called only once for each interface, during Linux network
00924  * interface registration.  Returning anything but zero will fail interface
00925  * registration.
00926  */
00927 static int if_init (struct device* dev)
00928 {
00929         fr_channel_t* chan = dev->priv;
00930         sdla_t* card = chan->card;
00931         wan_device_t* wandev = &card->wandev;
00932 
00933         /* Initialize device driver entry points */
00934         dev->open               = &if_open;
00935         dev->stop               = &if_close;
00936         dev->hard_header        = &if_header;
00937         dev->rebuild_header     = &if_rebuild_hdr;
00938         dev->hard_start_xmit    = &if_send;
00939         dev->get_stats          = &if_stats;
00940 
00941         /* Initialize media-specific parameters */
00942         dev->type               = ARPHRD_DLCI;  /* ARP h/w type */
00943         dev->flags              |= IFF_POINTOPOINT;     
00944 
00945         /* Enable Multicast addressing */
00946         if (chan->mc == WANOPT_YES){
00947                 dev->flags      |= IFF_MULTICAST;
00948         }
00949 
00950         dev->mtu                = wandev->mtu - FR_HEADER_LEN;
00951         /* For an API, the maximum number of bytes that the stack will pass
00952            to the driver is (dev->mtu + dev->hard_header_len). So, adjust the
00953            mtu so that a frame of maximum size can be transmitted by the API. 
00954         */
00955         if(chan->usedby == API) {
00956                 dev->mtu += (sizeof(api_tx_hdr_t) - FR_HEADER_LEN);
00957         }
00958         
00959         dev->hard_header_len    = FR_HEADER_LEN;/* media header length */
00960         dev->addr_len           = 2;            /* hardware address length */
00961         *(unsigned short*)dev->dev_addr = htons(chan->dlci);
00962 
00963         /* Initialize hardware parameters (just for reference) */
00964         dev->irq        = wandev->irq;
00965         dev->dma        = wandev->dma;
00966         dev->base_addr  = wandev->ioport;
00967         dev->mem_start  = wandev->maddr;
00968         dev->mem_end    = wandev->maddr + wandev->msize - 1;
00969 
00970         /* Set transmit buffer queue length */
00971         dev->tx_queue_len = 100;
00972    
00973         /* Initialize socket buffers */
00974         dev_init_buffers(dev);
00975 
00976         set_chan_state(dev, WAN_DISCONNECTED);
00977         return 0;
00978 }
00979 
00980 /*============================================================================
00981  * Open network interface.
00982  * o if this is the first open, then enable communications and interrupts.
00983  * o prevent module from unloading by incrementing use count
00984  *
00985  * Return 0 if O.k. or errno.
00986  */
00987 static int if_open (struct device* dev)
00988 {
00989         fr_channel_t* chan = dev->priv;
00990         sdla_t* card = chan->card;
00991         int err = 0;
00992         struct timeval tv;
00993 
00994         if (dev->start)
00995                 return -EBUSY;          /* only one open is allowed */
00996 
00997         if (test_and_set_bit(1, (void*)&card->wandev.critical))
00998                 return -EAGAIN;
00999         
01000 
01001         /* If signalling is set to NO, then setup 
01002          * DLCI addresses right away.  Don't have to wait for
01003          * link to connect. 
01004          */
01005         if (card->wandev.signalling == WANOPT_NO){
01006                 printk(KERN_INFO "%s: Signalling set to NO: Mapping DLCI's\n",
01007                                         card->wandev.name);
01008                 if (fr_init_dlci(card,chan)){
01009                         return -EAGAIN;
01010                 }
01011         }
01012 
01013         if (card->wandev.station == WANOPT_CPE) {
01014 
01015                 /* CPE: issue full status enquiry */
01016                 fr_issue_isf(card, FR_ISF_FSE);
01017 
01018         } else {        /* FR switch: activate DLCI(s) */
01019                 
01020                 /* For Switch emulation we have to ADD and ACTIVATE
01021                  * the DLCI(s) that were configured with the SET_DLCI_
01022                  * CONFIGURATION command. Add and Activate will fail if
01023                  * DLCI specified is not included in the list.
01024                  *
01025                  * Also If_open is called once for each interface. But
01026                  * it does not get in here for all the interface. So
01027                  * we have to pass the entire list of DLCI(s) to add 
01028                  * activate routines.  
01029                  */ 
01030         
01031                 fr_add_dlci(card, chan->dlci);
01032                 fr_activate_dlci(card, chan->dlci);
01033         }
01034 
01035         dev->interrupt = 0;
01036         dev->tbusy = 0;
01037         dev->start = 1;
01038         wanpipe_open(card);
01039         update_chan_state(dev);
01040         do_gettimeofday( &tv );
01041         chan->router_start_time = tv.tv_sec;
01042         clear_bit(1, (void*)&card->wandev.critical);
01043         return err;
01044 }
01045 
01046 /*============================================================================
01047  * Close network interface.
01048  * o if this is the last open, then disable communications and interrupts.
01049  * o reset flags.
01050  */
01051 static int if_close (struct device* dev)
01052 {
01053         fr_channel_t* chan = dev->priv;
01054         sdla_t* card = chan->card;
01055 
01056         if (test_and_set_bit(1, (void*)&card->wandev.critical))
01057                 return -EAGAIN;
01058 
01059         dev->start = 0;
01060         wanpipe_close(card);
01061         if (card->wandev.station == WANOPT_NODE) {
01062                 fr_delete_dlci (card,chan->dlci);
01063         }
01064 
01065         clear_bit(1, (void*)&card->wandev.critical);
01066         return 0;
01067 }
01068 
01069 /*============================================================================
01070  * Build media header.
01071  * o encapsulate packet according to encapsulation type.
01072  *
01073  * The trick here is to put packet type (Ethertype) into 'protocol' field of
01074  * the socket buffer, so that we don't forget it.  If encapsulation fails,
01075  * set skb->protocol to 0 and discard packet later.
01076  *
01077  * Return:      media header length.
01078  */
01079 static int if_header (struct sk_buff* skb, struct device* dev,
01080         unsigned short type, void* daddr, void* saddr, unsigned len)
01081 {
01082         int hdr_len = 0;
01083         
01084         skb->protocol = type;
01085         hdr_len = wanrouter_encapsulate(skb, dev);
01086 
01087         if (hdr_len < 0) {
01088                 hdr_len = 0;
01089                 skb->protocol = 0;
01090         }
01091         skb_push(skb, 1);
01092         skb->data[0] = Q922_UI;
01093         ++hdr_len;
01094         return hdr_len;
01095 }
01096 
01097 /*============================================================================
01098  * Re-build media header.
01099  *
01100  * Return:      1       physical address resolved.
01101  *              0       physical address not resolved
01102  */
01103 static int if_rebuild_hdr (struct sk_buff* skb)
01104 {
01105         struct device *dev = skb->dev;
01106         fr_channel_t* chan = dev->priv;
01107         sdla_t* card = chan->card;
01108 
01109         printk(KERN_INFO "%s: rebuild_header() called for interface %s!\n",
01110                 card->devname, dev->name);
01111         return 1;
01112 }
01113 
01114 /*============================================================================
01115  * Send a packet on a network interface.
01116  * o set tbusy flag (marks start of the transmission) to block a timer-based
01117  *   transmit from overlapping.
01118  * o set critical flag when accessing board.
01119  * o check link state. If link is not up, then drop the packet.
01120  * o check channel status. If it's down then initiate a call.
01121  * o pass a packet to corresponding WAN device.
01122  * o free socket buffer
01123  *
01124  * Return:      0       complete (socket buffer must be freed)
01125  *              non-0   packet may be re-transmitted (tbusy must be set)
01126  *
01127  * Notes:
01128  * 1. This routine is called either by the protocol stack or by the "net
01129  *    bottom half" (with interrupts enabled).
01130  * 2. Setting tbusy flag will inhibit further transmit requests from the
01131  *    protocol stack and can be used for flow control with protocol layer.
01132  */
01133 static int if_send (struct sk_buff* skb, struct device* dev)
01134 {
01135         fr_channel_t* chan = dev->priv;
01136         sdla_t* card = chan->card;
01137         int err;
01138         unsigned char *sendpacket;
01139         fr508_flags_t* adptr_flags = card->flags;
01140         int udp_type, send_data;
01141         unsigned long smp_flags=0;
01142         void* data;
01143         unsigned len;
01144 
01145         chan->drvstats_if_send.if_send_entry++;
01146 
01147         if (skb == NULL) {             
01148                 /* if we get here, some higher layer thinks we've missed an
01149                  * tx-done interrupt.
01150                  */
01151                 printk(KERN_INFO "%s: interface %s got kicked!\n", 
01152                         card->devname, dev->name);
01153                 chan->drvstats_if_send.if_send_skb_null ++;
01154                 mark_bh(NET_BH);
01155                 return 0;
01156         }
01157 
01158         /* We must set the 'tbusy' flag if we already have a packet queued for
01159            transmission in the transmit interrupt handler. However, we must
01160            ensure that the transmit interrupt does not reset the 'tbusy' flag
01161            just before we set it, as this will result in a "transmit timeout".
01162         */
01163         set_bit(2, (void*)&card->wandev.critical);
01164         if(chan->transmit_length) {
01165                 dev->tbusy = 1;
01166                 chan->tick_counter = jiffies;
01167                 clear_bit(2, (void*)&card->wandev.critical);
01168                 return 1;
01169         }
01170         clear_bit(2, (void*)&card->wandev.critical);
01171   
01172         if (dev->tbusy) {
01173 
01174                 /* If our device stays busy for at least 5 seconds then we will
01175                  * kick start the device by making dev->tbusy = 0.  We expect
01176                  * that our device never stays busy more than 5 seconds. So this                 
01177                  * is only used as a last resort.
01178                  */
01179                 
01180                 chan->drvstats_if_send.if_send_tbusy++;
01181                 ++chan->ifstats.collisions;
01182 
01183                 if ((jiffies - chan->tick_counter) < (5 * HZ)) {
01184                         return 1;
01185                 }
01186 
01187                 printk(KERN_INFO "%s: Transmit timed out\n", chan->name);
01188                 chan->drvstats_if_send.if_send_tbusy_timeout ++;
01189                 dev->tbusy = 0;
01190         }
01191 
01192         data = skb->data;
01193         sendpacket = skb->data;
01194         len = skb->len;
01195 
01196         udp_type = udp_pkt_type(skb, card);
01197 
01198         if(udp_type != UDP_INVALID_TYPE) {
01199                 if(store_udp_mgmt_pkt(udp_type, UDP_PKT_FRM_STACK, card, skb,
01200                         chan->dlci)) {
01201                         adptr_flags->imask |= FR_INTR_TIMER;
01202                         if (udp_type == UDP_FPIPE_TYPE){
01203                                 chan->drvstats_if_send.
01204                                         if_send_PIPE_request ++;
01205                         }
01206                 }
01207                 return 0;
01208         }
01209 
01210         if((chan->usedby == API) && (len <= sizeof(api_tx_hdr_t))) {
01211                 //FIXME: increment some error statistic
01212                 dev_kfree_skb(skb);
01213                 return 0;
01214         }
01215  
01216         //FIXME: can we do better than sendpacket[2]?
01217         if ((chan->usedby == WANPIPE) && (sendpacket[2] == 0x45)) {
01218                 /* check to see if the source IP address is a broadcast or */
01219                 /* multicast IP address */
01220                 if(chk_bcast_mcast_addr(card, dev, skb))
01221                         return 0;
01222         }
01223 
01224         /* Lock the 508 card: SMP Supported */
01225         s508_s514_lock(card,&smp_flags);
01226 
01227         if (test_and_set_bit(0, (void*)&card->wandev.critical)) {
01228                 chan->drvstats_if_send.if_send_critical_non_ISR ++;
01229                 chan->ifstats.tx_dropped ++;
01230                 printk(KERN_INFO "%s Critical in IF_SEND %02X\n", 
01231                                 card->devname, card->wandev.critical);
01232                 dev_kfree_skb(skb);
01233                 /* Unlock the 508 card */
01234                 s508_s514_unlock(card,&smp_flags);
01235                 return 0;
01236         }
01237         
01238         if (card->wandev.state != WAN_CONNECTED) {
01239                 chan->drvstats_if_send.if_send_wan_disconnected ++;
01240                 ++chan->ifstats.tx_dropped;
01241                 ++card->wandev.stats.tx_dropped;
01242         
01243         } else if (chan->state != WAN_CONNECTED) {
01244                 chan->drvstats_if_send.if_send_dlci_disconnected ++;
01245                 /* Critical area on 514, since disabl_irq is not used
01246                  * thus, interrupt would execute a command at
01247                  * the same time as if_