Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * This file is part of the Chelsio T4 Ethernet driver for Linux.
0003  *
0004  * Copyright (c) 2003-2014 Chelsio Communications, Inc. All rights reserved.
0005  *
0006  * This software is available to you under a choice of one of two
0007  * licenses.  You may choose to be licensed under the terms of the GNU
0008  * General Public License (GPL) Version 2, available from the file
0009  * COPYING in the main directory of this source tree, or the
0010  * OpenIB.org BSD license below:
0011  *
0012  *     Redistribution and use in source and binary forms, with or
0013  *     without modification, are permitted provided that the following
0014  *     conditions are met:
0015  *
0016  *      - Redistributions of source code must retain the above
0017  *        copyright notice, this list of conditions and the following
0018  *        disclaimer.
0019  *
0020  *      - Redistributions in binary form must reproduce the above
0021  *        copyright notice, this list of conditions and the following
0022  *        disclaimer in the documentation and/or other materials
0023  *        provided with the distribution.
0024  *
0025  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0026  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0027  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0028  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0029  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0030  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0031  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0032  * SOFTWARE.
0033  */
0034 
0035 #ifndef __CXGB4_L2T_H
0036 #define __CXGB4_L2T_H
0037 
0038 #include <linux/spinlock.h>
0039 #include <linux/if_ether.h>
0040 #include <linux/atomic.h>
0041 
0042 #define VLAN_NONE 0xfff
0043 
0044 enum { L2T_SIZE = 4096 };     /* # of L2T entries */
0045 
0046 enum {
0047     L2T_STATE_VALID,      /* entry is up to date */
0048     L2T_STATE_STALE,      /* entry may be used but needs revalidation */
0049     L2T_STATE_RESOLVING,  /* entry needs address resolution */
0050     L2T_STATE_SYNC_WRITE, /* synchronous write of entry underway */
0051     L2T_STATE_NOARP,      /* Netdev down or removed*/
0052 
0053     /* when state is one of the below the entry is not hashed */
0054     L2T_STATE_SWITCHING,  /* entry is being used by a switching filter */
0055     L2T_STATE_UNUSED      /* entry not in use */
0056 };
0057 
0058 struct adapter;
0059 struct l2t_data;
0060 struct neighbour;
0061 struct net_device;
0062 struct file_operations;
0063 struct cpl_l2t_write_rpl;
0064 
0065 /*
0066  * Each L2T entry plays multiple roles.  First of all, it keeps state for the
0067  * corresponding entry of the HW L2 table and maintains a queue of offload
0068  * packets awaiting address resolution.  Second, it is a node of a hash table
0069  * chain, where the nodes of the chain are linked together through their next
0070  * pointer.  Finally, each node is a bucket of a hash table, pointing to the
0071  * first element in its chain through its first pointer.
0072  */
0073 struct l2t_entry {
0074     u16 state;                  /* entry state */
0075     u16 idx;                    /* entry index within in-memory table */
0076     u32 addr[4];                /* next hop IP or IPv6 address */
0077     int ifindex;                /* neighbor's net_device's ifindex */
0078     struct neighbour *neigh;    /* associated neighbour */
0079     struct l2t_entry *first;    /* start of hash chain */
0080     struct l2t_entry *next;     /* next l2t_entry on chain */
0081     struct sk_buff_head arpq;   /* packet queue awaiting resolution */
0082     spinlock_t lock;
0083     atomic_t refcnt;            /* entry reference count */
0084     u16 hash;                   /* hash bucket the entry is on */
0085     u16 vlan;                   /* VLAN TCI (id: bits 0-11, prio: 13-15 */
0086     u8 v6;                      /* whether entry is for IPv6 */
0087     u8 lport;                   /* associated offload logical interface */
0088     u8 dmac[ETH_ALEN];          /* neighbour's MAC address */
0089 };
0090 
0091 typedef void (*arp_err_handler_t)(void *handle, struct sk_buff *skb);
0092 
0093 /*
0094  * Callback stored in an skb to handle address resolution failure.
0095  */
0096 struct l2t_skb_cb {
0097     void *handle;
0098     arp_err_handler_t arp_err_handler;
0099 };
0100 
0101 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
0102 
0103 static inline void t4_set_arp_err_handler(struct sk_buff *skb, void *handle,
0104                       arp_err_handler_t handler)
0105 {
0106     L2T_SKB_CB(skb)->handle = handle;
0107     L2T_SKB_CB(skb)->arp_err_handler = handler;
0108 }
0109 
0110 void cxgb4_l2t_release(struct l2t_entry *e);
0111 int cxgb4_l2t_send(struct net_device *dev, struct sk_buff *skb,
0112            struct l2t_entry *e);
0113 struct l2t_entry *cxgb4_l2t_get(struct l2t_data *d, struct neighbour *neigh,
0114                 const struct net_device *physdev,
0115                 unsigned int priority);
0116 u64 cxgb4_select_ntuple(struct net_device *dev,
0117             const struct l2t_entry *l2t);
0118 struct l2t_entry *cxgb4_l2t_alloc_switching(struct net_device *dev, u16 vlan,
0119                         u8 port, u8 *dmac);
0120 void t4_l2t_update(struct adapter *adap, struct neighbour *neigh);
0121 struct l2t_entry *t4_l2t_alloc_switching(struct adapter *adap, u16 vlan,
0122                      u8 port, u8 *dmac);
0123 struct l2t_data *t4_init_l2t(unsigned int l2t_start, unsigned int l2t_end);
0124 void do_l2t_write_rpl(struct adapter *p, const struct cpl_l2t_write_rpl *rpl);
0125 bool cxgb4_check_l2t_valid(struct l2t_entry *e);
0126 
0127 extern const struct file_operations t4_l2t_fops;
0128 #endif  /* __CXGB4_L2T_H */