Home | History | Annotate | Line # | Download | only in cxgb
cxgb_offload.h revision 1.1.4.2
      1  1.1.4.2  rmind 
      2  1.1.4.2  rmind /**************************************************************************
      3  1.1.4.2  rmind 
      4  1.1.4.2  rmind Copyright (c) 2007, Chelsio Inc.
      5  1.1.4.2  rmind All rights reserved.
      6  1.1.4.2  rmind 
      7  1.1.4.2  rmind Redistribution and use in source and binary forms, with or without
      8  1.1.4.2  rmind modification, are permitted provided that the following conditions are met:
      9  1.1.4.2  rmind 
     10  1.1.4.2  rmind  1. Redistributions of source code must retain the above copyright notice,
     11  1.1.4.2  rmind     this list of conditions and the following disclaimer.
     12  1.1.4.2  rmind 
     13  1.1.4.2  rmind  2. Neither the name of the Chelsio Corporation nor the names of its
     14  1.1.4.2  rmind     contributors may be used to endorse or promote products derived from
     15  1.1.4.2  rmind     this software without specific prior written permission.
     16  1.1.4.2  rmind 
     17  1.1.4.2  rmind THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     18  1.1.4.2  rmind AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  1.1.4.2  rmind IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  1.1.4.2  rmind ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
     21  1.1.4.2  rmind LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22  1.1.4.2  rmind CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23  1.1.4.2  rmind SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24  1.1.4.2  rmind INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25  1.1.4.2  rmind CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26  1.1.4.2  rmind ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27  1.1.4.2  rmind POSSIBILITY OF SUCH DAMAGE.
     28  1.1.4.2  rmind 
     29  1.1.4.2  rmind ***************************************************************************/
     30  1.1.4.2  rmind 
     31  1.1.4.2  rmind #ifndef _CXGB_OFFLOAD_H
     32  1.1.4.2  rmind #define _CXGB_OFFLOAD_H
     33  1.1.4.2  rmind 
     34  1.1.4.2  rmind #ifdef CONFIG_DEFINED
     35  1.1.4.2  rmind #include <common/cxgb_version.h>
     36  1.1.4.2  rmind #include <cxgb_config.h>
     37  1.1.4.2  rmind #include <cxgb_l2t.h>
     38  1.1.4.2  rmind #include <common/cxgb_tcb.h>
     39  1.1.4.2  rmind #else
     40  1.1.4.2  rmind #include "cxgb_version.h"
     41  1.1.4.2  rmind #include "cxgb_config.h"
     42  1.1.4.2  rmind #include "cxgb_l2t.h"
     43  1.1.4.2  rmind #include "cxgb_tcb.h"
     44  1.1.4.2  rmind #endif
     45  1.1.4.2  rmind 
     46  1.1.4.2  rmind struct adapter;
     47  1.1.4.2  rmind struct cxgb_client;
     48  1.1.4.2  rmind 
     49  1.1.4.2  rmind void cxgb_offload_init(void);
     50  1.1.4.2  rmind void cxgb_offload_exit(void);
     51  1.1.4.2  rmind 
     52  1.1.4.2  rmind void cxgb_adapter_ofld(struct adapter *adapter);
     53  1.1.4.2  rmind void cxgb_adapter_unofld(struct adapter *adapter);
     54  1.1.4.2  rmind int cxgb_offload_activate(struct adapter *adapter);
     55  1.1.4.2  rmind void cxgb_offload_deactivate(struct adapter *adapter);
     56  1.1.4.2  rmind int cxgb_ofld_recv(struct toedev *dev, struct mbuf **m, int n);
     57  1.1.4.2  rmind 
     58  1.1.4.2  rmind void cxgb_set_dummy_ops(struct toedev *dev);
     59  1.1.4.2  rmind 
     60  1.1.4.2  rmind 
     61  1.1.4.2  rmind /*
     62  1.1.4.2  rmind  * Client registration.  Users of T3 driver must register themselves.
     63  1.1.4.2  rmind  * The T3 driver will call the add function of every client for each T3
     64  1.1.4.2  rmind  * adapter activated, passing up the toedev ptr.  Each client fills out an
     65  1.1.4.2  rmind  * array of callback functions to process CPL messages.
     66  1.1.4.2  rmind  */
     67  1.1.4.2  rmind 
     68  1.1.4.2  rmind void cxgb_register_client(struct cxgb_client *client);
     69  1.1.4.2  rmind void cxgb_unregister_client(struct cxgb_client *client);
     70  1.1.4.2  rmind void cxgb_add_clients(struct toedev *tdev);
     71  1.1.4.2  rmind void cxgb_remove_clients(struct toedev *tdev);
     72  1.1.4.2  rmind 
     73  1.1.4.2  rmind typedef int (*cxgb_cpl_handler_func)(struct toedev *dev,
     74  1.1.4.2  rmind                       struct mbuf *m, void *ctx);
     75  1.1.4.2  rmind 
     76  1.1.4.2  rmind struct cxgb_client {
     77  1.1.4.2  rmind     char            *name;
     78  1.1.4.2  rmind     void            (*add) (struct toedev *);
     79  1.1.4.2  rmind     void            (*remove) (struct toedev *);
     80  1.1.4.2  rmind     cxgb_cpl_handler_func   *handlers;
     81  1.1.4.2  rmind     int         (*redirect)(void *ctx, struct rtentry *old,
     82  1.1.4.2  rmind                         struct rtentry *new,
     83  1.1.4.2  rmind                         struct l2t_entry *l2t);
     84  1.1.4.2  rmind     TAILQ_ENTRY(cxgb_client)         client_entry;
     85  1.1.4.2  rmind };
     86  1.1.4.2  rmind 
     87  1.1.4.2  rmind /*
     88  1.1.4.2  rmind  * TID allocation services.
     89  1.1.4.2  rmind  */
     90  1.1.4.2  rmind int cxgb_alloc_atid(struct toedev *dev, struct cxgb_client *client,
     91  1.1.4.2  rmind              void *ctx);
     92  1.1.4.2  rmind int cxgb_alloc_stid(struct toedev *dev, struct cxgb_client *client,
     93  1.1.4.2  rmind              void *ctx);
     94  1.1.4.2  rmind void *cxgb_free_atid(struct toedev *dev, int atid);
     95  1.1.4.2  rmind void cxgb_free_stid(struct toedev *dev, int stid);
     96  1.1.4.2  rmind void cxgb_insert_tid(struct toedev *dev, struct cxgb_client *client,
     97  1.1.4.2  rmind               void *ctx,
     98  1.1.4.2  rmind     unsigned int tid);
     99  1.1.4.2  rmind void cxgb_queue_tid_release(struct toedev *dev, unsigned int tid);
    100  1.1.4.2  rmind void cxgb_remove_tid(struct toedev *dev, void *ctx, unsigned int tid);
    101  1.1.4.2  rmind 
    102  1.1.4.2  rmind struct toe_tid_entry {
    103  1.1.4.2  rmind     struct cxgb_client  *client;
    104  1.1.4.2  rmind     void            *ctx;
    105  1.1.4.2  rmind };
    106  1.1.4.2  rmind 
    107  1.1.4.2  rmind /* CPL message priority levels */
    108  1.1.4.2  rmind enum {
    109  1.1.4.2  rmind     CPL_PRIORITY_DATA = 0,     /* data messages */
    110  1.1.4.2  rmind     CPL_PRIORITY_SETUP = 1,    /* connection setup messages */
    111  1.1.4.2  rmind     CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */
    112  1.1.4.2  rmind     CPL_PRIORITY_LISTEN = 1,   /* listen start/stop messages */
    113  1.1.4.2  rmind     CPL_PRIORITY_ACK = 1,      /* RX ACK messages */
    114  1.1.4.2  rmind     CPL_PRIORITY_CONTROL = 1   /* offload control messages */
    115  1.1.4.2  rmind };
    116  1.1.4.2  rmind 
    117  1.1.4.2  rmind /* Flags for return value of CPL message handlers */
    118  1.1.4.2  rmind enum {
    119  1.1.4.2  rmind     CPL_RET_BUF_DONE = 1,   // buffer processing done, buffer may be freed
    120  1.1.4.2  rmind     CPL_RET_BAD_MSG = 2,    // bad CPL message (e.g., unknown opcode)
    121  1.1.4.2  rmind     CPL_RET_UNKNOWN_TID = 4 // unexpected unknown TID
    122  1.1.4.2  rmind };
    123  1.1.4.2  rmind 
    124  1.1.4.2  rmind typedef int (*cpl_handler_func)(struct toedev *dev, struct mbuf *m);
    125  1.1.4.2  rmind 
    126  1.1.4.2  rmind /*
    127  1.1.4.2  rmind  * Returns a pointer to the first byte of the CPL header in an sk_buff that
    128  1.1.4.2  rmind  * contains a CPL message.
    129  1.1.4.2  rmind  */
    130  1.1.4.2  rmind static inline void *cplhdr(struct mbuf *m)
    131  1.1.4.2  rmind {
    132  1.1.4.2  rmind     return mtod(m, uint8_t *);
    133  1.1.4.2  rmind }
    134  1.1.4.2  rmind 
    135  1.1.4.2  rmind void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
    136  1.1.4.2  rmind 
    137  1.1.4.2  rmind union listen_entry {
    138  1.1.4.2  rmind     struct toe_tid_entry toe_tid;
    139  1.1.4.2  rmind     union listen_entry *next;
    140  1.1.4.2  rmind };
    141  1.1.4.2  rmind 
    142  1.1.4.2  rmind union active_open_entry {
    143  1.1.4.2  rmind     struct toe_tid_entry toe_tid;
    144  1.1.4.2  rmind     union active_open_entry *next;
    145  1.1.4.2  rmind };
    146  1.1.4.2  rmind 
    147  1.1.4.2  rmind /*
    148  1.1.4.2  rmind  * Holds the size, base address, free list start, etc of the TID, server TID,
    149  1.1.4.2  rmind  * and active-open TID tables for a offload device.
    150  1.1.4.2  rmind  * The tables themselves are allocated dynamically.
    151  1.1.4.2  rmind  */
    152  1.1.4.2  rmind struct tid_info {
    153  1.1.4.2  rmind     struct toe_tid_entry *tid_tab;
    154  1.1.4.2  rmind     unsigned int ntids;
    155  1.1.4.2  rmind     volatile unsigned int tids_in_use;
    156  1.1.4.2  rmind 
    157  1.1.4.2  rmind     union listen_entry *stid_tab;
    158  1.1.4.2  rmind     unsigned int nstids;
    159  1.1.4.2  rmind     unsigned int stid_base;
    160  1.1.4.2  rmind 
    161  1.1.4.2  rmind     union active_open_entry *atid_tab;
    162  1.1.4.2  rmind     unsigned int natids;
    163  1.1.4.2  rmind     unsigned int atid_base;
    164  1.1.4.2  rmind 
    165  1.1.4.2  rmind     /*
    166  1.1.4.2  rmind      * The following members are accessed R/W so we put them in their own
    167  1.1.4.2  rmind      * cache lines.
    168  1.1.4.2  rmind      *
    169  1.1.4.2  rmind      * XXX We could combine the atid fields above with the lock here since
    170  1.1.4.2  rmind      * atids are use once (unlike other tids).  OTOH the above fields are
    171  1.1.4.2  rmind      * usually in cache due to tid_tab.
    172  1.1.4.2  rmind      */
    173  1.1.4.2  rmind     struct mtx atid_lock /* ____cacheline_aligned_in_smp */;
    174  1.1.4.2  rmind     union active_open_entry *afree;
    175  1.1.4.2  rmind     unsigned int atids_in_use;
    176  1.1.4.2  rmind 
    177  1.1.4.2  rmind     struct mtx stid_lock /*____cacheline_aligned */;
    178  1.1.4.2  rmind     union listen_entry *sfree;
    179  1.1.4.2  rmind     unsigned int stids_in_use;
    180  1.1.4.2  rmind };
    181  1.1.4.2  rmind 
    182  1.1.4.2  rmind struct toe_data {
    183  1.1.4.2  rmind #ifdef notyet
    184  1.1.4.2  rmind     struct list_head list_node;
    185  1.1.4.2  rmind #endif
    186  1.1.4.2  rmind     struct toedev *dev;
    187  1.1.4.2  rmind     unsigned int tx_max_chunk;  /* max payload for TX_DATA */
    188  1.1.4.2  rmind     unsigned int max_wrs;       /* max in-flight WRs per connection */
    189  1.1.4.2  rmind     unsigned int nmtus;
    190  1.1.4.2  rmind     const unsigned short *mtus;
    191  1.1.4.2  rmind     struct tid_info tid_maps;
    192  1.1.4.2  rmind 
    193  1.1.4.2  rmind     struct toe_tid_entry *tid_release_list;
    194  1.1.4.2  rmind     struct mtx tid_release_lock;
    195  1.1.4.2  rmind     struct cxgb_task tid_release_task;
    196  1.1.4.2  rmind };
    197  1.1.4.2  rmind 
    198  1.1.4.2  rmind /*
    199  1.1.4.2  rmind  * toedev -> toe_data accessor
    200  1.1.4.2  rmind  */
    201  1.1.4.2  rmind #define TOE_DATA(dev) (*(struct toe_data **)&(dev)->l4opt)
    202  1.1.4.2  rmind 
    203  1.1.4.2  rmind /*
    204  1.1.4.2  rmind  * Map an ATID or STID to their entries in the corresponding TID tables.
    205  1.1.4.2  rmind  */
    206  1.1.4.2  rmind static inline union active_open_entry *atid2entry(const struct tid_info *t,
    207  1.1.4.2  rmind                                                   unsigned int atid)
    208  1.1.4.2  rmind {
    209  1.1.4.2  rmind         return &t->atid_tab[atid - t->atid_base];
    210  1.1.4.2  rmind }
    211  1.1.4.2  rmind 
    212  1.1.4.2  rmind 
    213  1.1.4.2  rmind static inline union listen_entry *stid2entry(const struct tid_info *t,
    214  1.1.4.2  rmind                                              unsigned int stid)
    215  1.1.4.2  rmind {
    216  1.1.4.2  rmind         return &t->stid_tab[stid - t->stid_base];
    217  1.1.4.2  rmind }
    218  1.1.4.2  rmind 
    219  1.1.4.2  rmind /*
    220  1.1.4.2  rmind  * Find the connection corresponding to a TID.
    221  1.1.4.2  rmind  */
    222  1.1.4.2  rmind static inline struct toe_tid_entry *lookup_tid(const struct tid_info *t,
    223  1.1.4.2  rmind                                                unsigned int tid)
    224  1.1.4.2  rmind {
    225  1.1.4.2  rmind         return tid < t->ntids ? &(t->tid_tab[tid]) : NULL;
    226  1.1.4.2  rmind }
    227  1.1.4.2  rmind 
    228  1.1.4.2  rmind /*
    229  1.1.4.2  rmind  * Find the connection corresponding to a server TID.
    230  1.1.4.2  rmind  */
    231  1.1.4.2  rmind static inline struct toe_tid_entry *lookup_stid(const struct tid_info *t,
    232  1.1.4.2  rmind                                                 unsigned int tid)
    233  1.1.4.2  rmind {
    234  1.1.4.2  rmind         if (tid < t->stid_base || tid >= t->stid_base + t->nstids)
    235  1.1.4.2  rmind                 return NULL;
    236  1.1.4.2  rmind         return &(stid2entry(t, tid)->toe_tid);
    237  1.1.4.2  rmind }
    238  1.1.4.2  rmind 
    239  1.1.4.2  rmind /*
    240  1.1.4.2  rmind  * Find the connection corresponding to an active-open TID.
    241  1.1.4.2  rmind  */
    242  1.1.4.2  rmind static inline struct toe_tid_entry *lookup_atid(const struct tid_info *t,
    243  1.1.4.2  rmind                                                 unsigned int tid)
    244  1.1.4.2  rmind {
    245  1.1.4.2  rmind         if (tid < t->atid_base || tid >= t->atid_base + t->natids)
    246  1.1.4.2  rmind                 return NULL;
    247  1.1.4.2  rmind         return &(atid2entry(t, tid)->toe_tid);
    248  1.1.4.2  rmind }
    249  1.1.4.2  rmind 
    250  1.1.4.2  rmind void *cxgb_alloc_mem(unsigned long size);
    251  1.1.4.2  rmind void cxgb_free_mem(void *addr);
    252  1.1.4.2  rmind void cxgb_neigh_update(struct rtentry *rt);
    253  1.1.4.2  rmind void cxgb_redirect(struct rtentry *old, struct rtentry *new);
    254  1.1.4.2  rmind int process_rx(struct toedev *dev, struct mbuf **m, int n);
    255  1.1.4.2  rmind int attach_toedev(struct toedev *dev);
    256  1.1.4.2  rmind void detach_toedev(struct toedev *dev);
    257  1.1.4.2  rmind 
    258  1.1.4.2  rmind 
    259  1.1.4.2  rmind #endif
    260