openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

knet-cb.c (2793B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  */
      7 
      8 /*
      9  * Test driver for call-back functions in Linux KNET driver.
     10  *
     11  * The module can be built from the standard Linux user mode target
     12  * directories using the following command (assuming bash), e.g.
     13  *
     14  *   cd $SDK/systems/linux/user/gto-2_6
     15  *   BUILD_KNET_CB=1 make -s mod
     16  */
     17 
     18 #include <gmodule.h> /* Must be included first */
     19 #include <kcom.h>
     20 #include <bcm-knet.h>
     21 
     22 MODULE_AUTHOR("Broadcom Corporation");
     23 MODULE_DESCRIPTION("Broadcom Linux KNET Call-Back Driver");
     24 MODULE_LICENSE("Proprietary");
     25 
     26 /* Module Information */
     27 #define MODULE_MAJOR 121
     28 #define MODULE_NAME "linux-knet-cb"
     29 
     30 static void
     31 show_mac(struct sk_buff *skb)
     32 {
     33     printk("DMAC=%02X:%02X:%02X:%02X:%02X:%02X\n",
     34            skb->data[0], skb->data[1], skb->data[2],
     35            skb->data[3], skb->data[4], skb->data[5]);
     36 }
     37 
     38 static struct sk_buff *
     39 test_rx_cb(struct sk_buff *skb, int dev_no, void *meta)
     40 {
     41     printk("rx_cb for dev %d\n", dev_no);
     42     printk("netif user data 0x%x\n", KNET_SKB_CB(skb)->netif_user_data);
     43     printk("filter user data 0x%x\n", KNET_SKB_CB(skb)->filter_user_data);
     44     printk("dcb type 0x%x\n", KNET_SKB_CB(skb)->dcb_type);
     45     if (skb->data[5] == 0x03) {
     46         dev_kfree_skb(skb);
     47         return NULL;
     48     }
     49     show_mac(skb);
     50     return skb;
     51 }
     52 
     53 static struct sk_buff *
     54 test_tx_cb(struct sk_buff *skb, int dev_no, void *meta)
     55 {
     56     printk("tx_cb for dev %d\n", dev_no);
     57     show_mac(skb);
     58     skb->data[5] += 1;
     59     return skb;
     60 }
     61 
     62 static int
     63 test_filter_cb(uint8_t *pkt, int size, int dev_no, void *meta,
     64                int chan, kcom_filter_t *kf)
     65 {
     66     printk("filter_cb (%d) for dev %d\n", kf->dest_id, dev_no);
     67     if (pkt[12] == 0x81 && pkt[13] == 0x00) {
     68         printk("  VTAG %d\n", pkt[15]);
     69         kf->dest_type = KCOM_DEST_T_NETIF;
     70         kf->dest_id = pkt[15];
     71         return 1;
     72     }
     73     return 0;
     74 }
     75 
     76 /*
     77  * Generic module functions
     78  */
     79 
     80 static int
     81 _pprint(void)
     82 {   
     83     pprintf("Broadcom Linux KNET Call-Back Driver\n");
     84 
     85     return 0;
     86 }
     87 
     88 static int
     89 _cleanup(void)
     90 {
     91     bkn_rx_skb_cb_unregister(test_rx_cb);
     92     bkn_tx_skb_cb_unregister(test_tx_cb);
     93     bkn_filter_cb_unregister(test_filter_cb);
     94 
     95     return 0;
     96 }   
     97 
     98 static int
     99 _init(void)
    100 {
    101     bkn_rx_skb_cb_register(test_rx_cb);
    102     bkn_tx_skb_cb_register(test_tx_cb);
    103     bkn_filter_cb_register(test_filter_cb);
    104 
    105     return 0;
    106 }
    107 
    108 static gmodule_t _gmodule = {
    109     name: MODULE_NAME, 
    110     major: MODULE_MAJOR, 
    111     init: _init,
    112     cleanup: _cleanup, 
    113     pprint: _pprint, 
    114     ioctl: NULL,
    115     open: NULL, 
    116     close: NULL, 
    117 }; 
    118 
    119 gmodule_t*
    120 gmodule_get(void)
    121 {
    122     EXPORT_NO_SYMBOLS;
    123     return &_gmodule;
    124 }