knet-cb.c (3207B)
1 /* 2 * Copyright 2017 Broadcom 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License, version 2, as 6 * published by the Free Software Foundation (the "GPL"). 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * General Public License version 2 (GPLv2) for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * version 2 (GPLv2) along with this source code. 15 */ 16 17 /* 18 * Test driver for call-back functions in Linux KNET driver. 19 * 20 * The module can be built from the standard Linux user mode target 21 * directories using the following command (assuming bash), e.g. 22 * 23 * cd $SDK/systems/linux/user/gto-2_6 24 * BUILD_KNET_CB=1 make -s mod 25 * 26 */ 27 28 #include <gmodule.h> /* Must be included first */ 29 #include <kcom.h> 30 #include <bcm-knet.h> 31 32 MODULE_AUTHOR("Broadcom Corporation"); 33 MODULE_DESCRIPTION("Broadcom Linux KNET Call-Back Driver"); 34 MODULE_LICENSE("GPL"); 35 36 /* Module Information */ 37 #define MODULE_MAJOR 121 38 #define MODULE_NAME "linux-knet-cb" 39 40 static void 41 show_mac(struct sk_buff *skb) 42 { 43 printk("DMAC=%02X:%02X:%02X:%02X:%02X:%02X\n", 44 skb->data[0], skb->data[1], skb->data[2], 45 skb->data[3], skb->data[4], skb->data[5]); 46 } 47 48 static struct sk_buff * 49 test_rx_cb(struct sk_buff *skb, int dev_no, void *meta) 50 { 51 printk("rx_cb for dev %d\n", dev_no); 52 printk("netif user data 0x%x\n", KNET_SKB_CB(skb)->netif_user_data); 53 printk("filter user data 0x%x\n", KNET_SKB_CB(skb)->filter_user_data); 54 printk("dcb type 0x%x\n", KNET_SKB_CB(skb)->dcb_type); 55 if (skb->data[5] == 0x03) { 56 dev_kfree_skb(skb); 57 return NULL; 58 } 59 show_mac(skb); 60 return skb; 61 } 62 63 static struct sk_buff * 64 test_tx_cb(struct sk_buff *skb, int dev_no, void *meta) 65 { 66 printk("tx_cb for dev %d\n", dev_no); 67 show_mac(skb); 68 skb->data[5] += 1; 69 return skb; 70 } 71 72 static int 73 test_filter_cb(uint8_t *pkt, int size, int dev_no, void *meta, 74 int chan, kcom_filter_t *kf) 75 { 76 printk("filter_cb (%d) for dev %d\n", kf->dest_id, dev_no); 77 if (pkt[12] == 0x81 && pkt[13] == 0x00) { 78 printk(" VTAG %d\n", pkt[15]); 79 kf->dest_type = KCOM_DEST_T_NETIF; 80 kf->dest_id = pkt[15]; 81 return 1; 82 } 83 return 0; 84 } 85 86 /* 87 * Generic module functions 88 */ 89 90 static int 91 _pprint(void) 92 { 93 pprintf("Broadcom Linux KNET Call-Back Driver\n"); 94 95 return 0; 96 } 97 98 static int 99 _cleanup(void) 100 { 101 bkn_rx_skb_cb_unregister(test_rx_cb); 102 bkn_tx_skb_cb_unregister(test_tx_cb); 103 bkn_filter_cb_unregister(test_filter_cb); 104 105 return 0; 106 } 107 108 static int 109 _init(void) 110 { 111 bkn_rx_skb_cb_register(test_rx_cb); 112 bkn_tx_skb_cb_register(test_tx_cb); 113 bkn_filter_cb_register(test_filter_cb); 114 115 return 0; 116 } 117 118 static gmodule_t _gmodule = { 119 name: MODULE_NAME, 120 major: MODULE_MAJOR, 121 init: _init, 122 cleanup: _cleanup, 123 pprint: _pprint, 124 ioctl: NULL, 125 open: NULL, 126 close: NULL, 127 }; 128 129 gmodule_t* 130 gmodule_get(void) 131 { 132 EXPORT_NO_SYMBOLS; 133 return &_gmodule; 134 }