Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
0003  *
0004  * This software is available to you under a choice of one of two
0005  * licenses.  You may choose to be licensed under the terms of the GNU
0006  * General Public License (GPL) Version 2, available from the file
0007  * COPYING in the main directory of this source tree, or the
0008  * OpenIB.org BSD license below:
0009  *
0010  *     Redistribution and use in source and binary forms, with or
0011  *     without modification, are permitted provided that the following
0012  *     conditions are met:
0013  *
0014  *      - Redistributions of source code must retain the above
0015  *        copyright notice, this list of conditions and the following
0016  *        disclaimer.
0017  *
0018  *      - Redistributions in binary form must reproduce the above
0019  *        copyright notice, this list of conditions and the following
0020  *        disclaimer in the documentation and/or other materials
0021  *        provided with the distribution.
0022  *
0023  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0024  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0025  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0026  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
0027  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
0028  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0029  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
0030  * SOFTWARE.
0031  */
0032 #ifndef _CXGB3_OFFLOAD_H
0033 #define _CXGB3_OFFLOAD_H
0034 
0035 #include <linux/list.h>
0036 #include <linux/skbuff.h>
0037 
0038 #include "l2t.h"
0039 
0040 #include "t3cdev.h"
0041 #include "t3_cpl.h"
0042 
0043 struct adapter;
0044 
0045 void cxgb3_offload_init(void);
0046 
0047 void cxgb3_adapter_ofld(struct adapter *adapter);
0048 void cxgb3_adapter_unofld(struct adapter *adapter);
0049 int cxgb3_offload_activate(struct adapter *adapter);
0050 void cxgb3_offload_deactivate(struct adapter *adapter);
0051 
0052 void cxgb3_set_dummy_ops(struct t3cdev *dev);
0053 
0054 struct t3cdev *dev2t3cdev(struct net_device *dev);
0055 
0056 /*
0057  * Client registration.  Users of T3 driver must register themselves.
0058  * The T3 driver will call the add function of every client for each T3
0059  * adapter activated, passing up the t3cdev ptr.  Each client fills out an
0060  * array of callback functions to process CPL messages.
0061  */
0062 
0063 void cxgb3_register_client(struct cxgb3_client *client);
0064 void cxgb3_unregister_client(struct cxgb3_client *client);
0065 void cxgb3_add_clients(struct t3cdev *tdev);
0066 void cxgb3_remove_clients(struct t3cdev *tdev);
0067 void cxgb3_event_notify(struct t3cdev *tdev, u32 event, u32 port);
0068 
0069 typedef int (*cxgb3_cpl_handler_func)(struct t3cdev *dev,
0070                       struct sk_buff *skb, void *ctx);
0071 
0072 enum {
0073     OFFLOAD_STATUS_UP,
0074     OFFLOAD_STATUS_DOWN,
0075     OFFLOAD_PORT_DOWN,
0076     OFFLOAD_PORT_UP,
0077     OFFLOAD_DB_FULL,
0078     OFFLOAD_DB_EMPTY,
0079     OFFLOAD_DB_DROP
0080 };
0081 
0082 struct cxgb3_client {
0083     char *name;
0084     void (*add) (struct t3cdev *);
0085     void (*remove) (struct t3cdev *);
0086     cxgb3_cpl_handler_func *handlers;
0087     int (*redirect)(void *ctx, struct dst_entry *old,
0088             struct dst_entry *new, struct l2t_entry *l2t);
0089     struct list_head client_list;
0090     void (*event_handler)(struct t3cdev *tdev, u32 event, u32 port);
0091 };
0092 
0093 /*
0094  * TID allocation services.
0095  */
0096 int cxgb3_alloc_atid(struct t3cdev *dev, struct cxgb3_client *client,
0097              void *ctx);
0098 int cxgb3_alloc_stid(struct t3cdev *dev, struct cxgb3_client *client,
0099              void *ctx);
0100 void *cxgb3_free_atid(struct t3cdev *dev, int atid);
0101 void cxgb3_free_stid(struct t3cdev *dev, int stid);
0102 void cxgb3_insert_tid(struct t3cdev *dev, struct cxgb3_client *client,
0103               void *ctx, unsigned int tid);
0104 void cxgb3_queue_tid_release(struct t3cdev *dev, unsigned int tid);
0105 void cxgb3_remove_tid(struct t3cdev *dev, void *ctx, unsigned int tid);
0106 
0107 struct t3c_tid_entry {
0108     struct cxgb3_client *client;
0109     void *ctx;
0110 };
0111 
0112 /* CPL message priority levels */
0113 enum {
0114     CPL_PRIORITY_DATA = 0,  /* data messages */
0115     CPL_PRIORITY_SETUP = 1, /* connection setup messages */
0116     CPL_PRIORITY_TEARDOWN = 0,  /* connection teardown messages */
0117     CPL_PRIORITY_LISTEN = 1,    /* listen start/stop messages */
0118     CPL_PRIORITY_ACK = 1,   /* RX ACK messages */
0119     CPL_PRIORITY_CONTROL = 1    /* offload control messages */
0120 };
0121 
0122 /* Flags for return value of CPL message handlers */
0123 enum {
0124     CPL_RET_BUF_DONE = 1, /* buffer processing done, buffer may be freed */
0125     CPL_RET_BAD_MSG = 2,  /* bad CPL message (e.g., unknown opcode) */
0126     CPL_RET_UNKNOWN_TID = 4 /* unexpected unknown TID */
0127 };
0128 
0129 typedef int (*cpl_handler_func)(struct t3cdev *dev, struct sk_buff *skb);
0130 
0131 /*
0132  * Returns a pointer to the first byte of the CPL header in an sk_buff that
0133  * contains a CPL message.
0134  */
0135 static inline void *cplhdr(struct sk_buff *skb)
0136 {
0137     return skb->data;
0138 }
0139 
0140 void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h);
0141 
0142 union listen_entry {
0143     struct t3c_tid_entry t3c_tid;
0144     union listen_entry *next;
0145 };
0146 
0147 union active_open_entry {
0148     struct t3c_tid_entry t3c_tid;
0149     union active_open_entry *next;
0150 };
0151 
0152 /*
0153  * Holds the size, base address, free list start, etc of the TID, server TID,
0154  * and active-open TID tables for a offload device.
0155  * The tables themselves are allocated dynamically.
0156  */
0157 struct tid_info {
0158     struct t3c_tid_entry *tid_tab;
0159     unsigned int ntids;
0160     atomic_t tids_in_use;
0161 
0162     union listen_entry *stid_tab;
0163     unsigned int nstids;
0164     unsigned int stid_base;
0165 
0166     union active_open_entry *atid_tab;
0167     unsigned int natids;
0168     unsigned int atid_base;
0169 
0170     /*
0171      * The following members are accessed R/W so we put them in their own
0172      * cache lines.
0173      *
0174      * XXX We could combine the atid fields above with the lock here since
0175      * atids are use once (unlike other tids).  OTOH the above fields are
0176      * usually in cache due to tid_tab.
0177      */
0178     spinlock_t atid_lock ____cacheline_aligned_in_smp;
0179     union active_open_entry *afree;
0180     unsigned int atids_in_use;
0181 
0182     spinlock_t stid_lock ____cacheline_aligned;
0183     union listen_entry *sfree;
0184     unsigned int stids_in_use;
0185 };
0186 
0187 struct t3c_data {
0188     struct list_head list_node;
0189     struct t3cdev *dev;
0190     unsigned int tx_max_chunk;  /* max payload for TX_DATA */
0191     unsigned int max_wrs;   /* max in-flight WRs per connection */
0192     unsigned int nmtus;
0193     const unsigned short *mtus;
0194     struct tid_info tid_maps;
0195 
0196     struct t3c_tid_entry *tid_release_list;
0197     spinlock_t tid_release_lock;
0198     struct work_struct tid_release_task;
0199 
0200     struct sk_buff *nofail_skb;
0201     unsigned int release_list_incomplete;
0202 };
0203 
0204 /*
0205  * t3cdev -> t3c_data accessor
0206  */
0207 #define T3C_DATA(dev) (*(struct t3c_data **)&(dev)->l4opt)
0208 
0209 #endif