The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/cxgb/cxgb_l2t.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /**************************************************************************
    2 
    3 Copyright (c) 2007, Chelsio Inc.
    4 All rights reserved.
    5 
    6 Redistribution and use in source and binary forms, with or without
    7 modification, are permitted provided that the following conditions are met:
    8 
    9  1. Redistributions of source code must retain the above copyright notice,
   10     this list of conditions and the following disclaimer.
   11 
   12  2. Neither the name of the Chelsio Corporation nor the names of its
   13     contributors may be used to endorse or promote products derived from
   14     this software without specific prior written permission.
   15 
   16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
   20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   26 POSSIBILITY OF SUCH DAMAGE.
   27 
   28 $FreeBSD: releng/6.4/sys/dev/cxgb/cxgb_l2t.h 170962 2007-06-21 03:30:18Z kmacy $
   29 
   30 ***************************************************************************/
   31 #ifndef _CHELSIO_L2T_H
   32 #define _CHELSIO_L2T_H
   33 
   34 #ifdef CONFIG_DEFINED
   35 #include <ulp/toecore/toedev.h>
   36 #else
   37 #include <dev/cxgb/ulp/toecore/toedev.h>
   38 #endif
   39 
   40 #include <sys/lock.h>
   41 #include <sys/mutex.h>
   42 #if __FreeBSD_version > 700000
   43 #include <sys/rwlock.h>
   44 #else
   45 #define rwlock mtx
   46 #define rw_wlock(x) mtx_lock((x))
   47 #define rw_wunlock(x) mtx_unlock((x))
   48 #define rw_rlock(x) mtx_lock((x))
   49 #define rw_runlock(x) mtx_unlock((x))
   50 #define rw_init(x, str) mtx_init((x), (str), NULL, MTX_DEF)
   51 #define rw_destroy(x) mtx_destroy((x))
   52 
   53 #endif
   54 
   55 enum {
   56         L2T_STATE_VALID,      /* entry is up to date */
   57         L2T_STATE_STALE,      /* entry may be used but needs revalidation */
   58         L2T_STATE_RESOLVING,  /* entry needs address resolution */
   59         L2T_STATE_UNUSED      /* entry not in use */
   60 };
   61 
   62 
   63 /*
   64  * Each L2T entry plays multiple roles.  First of all, it keeps state for the
   65  * corresponding entry of the HW L2 table and maintains a queue of offload
   66  * packets awaiting address resolution.  Second, it is a node of a hash table
   67  * chain, where the nodes of the chain are linked together through their next
   68  * pointer.  Finally, each node is a bucket of a hash table, pointing to the
   69  * first element in its chain through its first pointer.
   70  */
   71 struct l2t_entry {
   72         uint16_t state;               /* entry state */
   73         uint16_t idx;                 /* entry index */
   74         uint32_t addr;                /* dest IP address */
   75         int ifindex;                  /* neighbor's net_device's ifindex */
   76         uint16_t smt_idx;             /* SMT index */
   77         uint16_t vlan;                /* VLAN TCI (id: bits 0-11, prio: 13-15 */
   78         struct rtentry *neigh;        /* associated neighbour */
   79         struct l2t_entry *first;      /* start of hash chain */
   80         struct l2t_entry *next;       /* next l2t_entry on chain */
   81         struct mbuf *arpq_head;       /* queue of packets awaiting resolution */
   82         struct mbuf *arpq_tail;
   83         struct mtx lock;
   84         volatile uint32_t refcnt;     /* entry reference count */
   85         uint8_t dmac[6];              /* neighbour's MAC address */
   86 #ifndef NETEVENT
   87 #ifdef CONFIG_CHELSIO_T3_MODULE
   88         struct timer_list update_timer;
   89         struct toedev *tdev;
   90 #endif
   91 #endif
   92 };
   93 
   94 struct l2t_data {
   95         unsigned int nentries;      /* number of entries */
   96         struct l2t_entry *rover;    /* starting point for next allocation */
   97         volatile uint32_t nfree;    /* number of free entries */
   98         struct rwlock lock;
   99         struct l2t_entry l2tab[0];
  100 };
  101 
  102 typedef void (*arp_failure_handler_func)(struct toedev *dev,
  103                                          struct mbuf *m);
  104 
  105 /*
  106  * Callback stored in an skb to handle address resolution failure.
  107  */
  108 struct l2t_mbuf_cb {
  109         arp_failure_handler_func arp_failure_handler;
  110 };
  111 
  112 /*
  113  * XXX 
  114  */
  115 #define L2T_MBUF_CB(skb) ((struct l2t_mbuf_cb *)(skb)->cb)
  116 
  117 
  118 static __inline void set_arp_failure_handler(struct mbuf *m,
  119                                            arp_failure_handler_func hnd)
  120 {
  121 #if 0
  122         L2T_SKB_CB(skb)->arp_failure_handler = hnd;
  123 #endif
  124         panic("implement me");
  125 }
  126 
  127 /*
  128  * Getting to the L2 data from an offload device.
  129  */
  130 #define L2DATA(dev) ((dev)->l2opt)
  131 
  132 void t3_l2e_free(struct l2t_data *d, struct l2t_entry *e);
  133 void t3_l2t_update(struct toedev *dev, struct rtentry *ifp);
  134 struct l2t_entry *t3_l2t_get(struct toedev *dev, struct rtentry *neigh,
  135                              unsigned int smt_idx);
  136 int t3_l2t_send_slow(struct toedev *dev, struct mbuf *m,
  137                      struct l2t_entry *e);
  138 void t3_l2t_send_event(struct toedev *dev, struct l2t_entry *e);
  139 struct l2t_data *t3_init_l2t(unsigned int l2t_capacity);
  140 void t3_free_l2t(struct l2t_data *d);
  141 
  142 #ifdef CONFIG_PROC_FS
  143 int t3_l2t_proc_setup(struct proc_dir_entry *dir, struct l2t_data *d);
  144 void t3_l2t_proc_free(struct proc_dir_entry *dir);
  145 #else
  146 #define l2t_proc_setup(dir, d) 0
  147 #define l2t_proc_free(dir)
  148 #endif
  149 
  150 int cxgb_ofld_send(struct toedev *dev, struct mbuf *m);
  151 
  152 static inline int l2t_send(struct toedev *dev, struct mbuf *m,
  153                            struct l2t_entry *e)
  154 {
  155         if (__predict_true(e->state == L2T_STATE_VALID))
  156                 return cxgb_ofld_send(dev, m);
  157         return t3_l2t_send_slow(dev, m, e);
  158 }
  159 
  160 static inline void l2t_release(struct l2t_data *d, struct l2t_entry *e)
  161 {
  162         if (atomic_fetchadd_int(&e->refcnt, -1) == 1)
  163                 t3_l2e_free(d, e);
  164 }
  165 
  166 static inline void l2t_hold(struct l2t_data *d, struct l2t_entry *e)
  167 {
  168         if (atomic_fetchadd_int(&e->refcnt, 1) == 1)  /* 0 -> 1 transition */
  169                 atomic_add_int(&d->nfree, 1);
  170 }
  171 
  172 #endif

Cache object: c0cb4590ee47f0d49600508de7c7c59d


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.