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