Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 1 | /* |
Divy Le Ray | a02d44a | 2008-10-13 18:47:30 -0700 | [diff] [blame^] | 2 | * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved. |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | #ifndef _CXGB3_OFFLOAD_H |
| 33 | #define _CXGB3_OFFLOAD_H |
| 34 | |
| 35 | #include <linux/list.h> |
| 36 | #include <linux/skbuff.h> |
| 37 | |
| 38 | #include "l2t.h" |
| 39 | |
| 40 | #include "t3cdev.h" |
| 41 | #include "t3_cpl.h" |
| 42 | |
| 43 | struct adapter; |
| 44 | |
| 45 | void cxgb3_offload_init(void); |
| 46 | |
| 47 | void cxgb3_adapter_ofld(struct adapter *adapter); |
| 48 | void cxgb3_adapter_unofld(struct adapter *adapter); |
| 49 | int cxgb3_offload_activate(struct adapter *adapter); |
| 50 | void cxgb3_offload_deactivate(struct adapter *adapter); |
| 51 | |
| 52 | void cxgb3_set_dummy_ops(struct t3cdev *dev); |
| 53 | |
Divy Le Ray | 5fbf816 | 2007-08-29 19:15:47 -0700 | [diff] [blame] | 54 | struct t3cdev *dev2t3cdev(struct net_device *dev); |
| 55 | |
Divy Le Ray | 4d22de3 | 2007-01-18 22:04:14 -0500 | [diff] [blame] | 56 | /* |
| 57 | * Client registration. Users of T3 driver must register themselves. |
| 58 | * The T3 driver will call the add function of every client for each T3 |
| 59 | * adapter activated, passing up the t3cdev ptr. Each client fills out an |
| 60 | * array of callback functions to process CPL messages. |
| 61 | */ |
| 62 | |
| 63 | void cxgb3_register_client(struct cxgb3_client *client); |
| 64 | void cxgb3_unregister_client(struct cxgb3_client *client); |
| 65 | void cxgb3_add_clients(struct t3cdev *tdev); |
| 66 | void cxgb3_remove_clients(struct t3cdev *tdev); |
| 67 | |
| 68 | typedef int (*cxgb3_cpl_handler_func)(struct t3cdev *dev, |
| 69 | struct sk_buff *skb, void *ctx); |
| 70 | |
| 71 | struct cxgb3_client { |
| 72 | char *name; |
| 73 | void (*add) (struct t3cdev *); |
| 74 | void (*remove) (struct t3cdev *); |
| 75 | cxgb3_cpl_handler_func *handlers; |
| 76 | int (*redirect)(void *ctx, struct dst_entry *old, |
| 77 | struct dst_entry *new, struct l2t_entry *l2t); |
| 78 | struct list_head client_list; |
| 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * TID allocation services. |
| 83 | */ |
| 84 | int cxgb3_alloc_atid(struct t3cdev *dev, struct cxgb3_client *client, |
| 85 | void *ctx); |
| 86 | int cxgb3_alloc_stid(struct t3cdev *dev, struct cxgb3_client *client, |
| 87 | void *ctx); |
| 88 | void *cxgb3_free_atid(struct t3cdev *dev, int atid); |
| 89 | void cxgb3_free_stid(struct t3cdev *dev, int stid); |
| 90 | void cxgb3_insert_tid(struct t3cdev *dev, struct cxgb3_client *client, |
| 91 | void *ctx, unsigned int tid); |
| 92 | void cxgb3_queue_tid_release(struct t3cdev *dev, unsigned int tid); |
| 93 | void cxgb3_remove_tid(struct t3cdev *dev, void *ctx, unsigned int tid); |
| 94 | |
| 95 | struct t3c_tid_entry { |
| 96 | struct cxgb3_client *client; |
| 97 | void *ctx; |
| 98 | }; |
| 99 | |
| 100 | /* CPL message priority levels */ |
| 101 | enum { |
| 102 | CPL_PRIORITY_DATA = 0, /* data messages */ |
| 103 | CPL_PRIORITY_SETUP = 1, /* connection setup messages */ |
| 104 | CPL_PRIORITY_TEARDOWN = 0, /* connection teardown messages */ |
| 105 | CPL_PRIORITY_LISTEN = 1, /* listen start/stop messages */ |
| 106 | CPL_PRIORITY_ACK = 1, /* RX ACK messages */ |
| 107 | CPL_PRIORITY_CONTROL = 1 /* offload control messages */ |
| 108 | }; |
| 109 | |
| 110 | /* Flags for return value of CPL message handlers */ |
| 111 | enum { |
| 112 | CPL_RET_BUF_DONE = 1, /* buffer processing done, buffer may be freed */ |
| 113 | CPL_RET_BAD_MSG = 2, /* bad CPL message (e.g., unknown opcode) */ |
| 114 | CPL_RET_UNKNOWN_TID = 4 /* unexpected unknown TID */ |
| 115 | }; |
| 116 | |
| 117 | typedef int (*cpl_handler_func)(struct t3cdev *dev, struct sk_buff *skb); |
| 118 | |
| 119 | /* |
| 120 | * Returns a pointer to the first byte of the CPL header in an sk_buff that |
| 121 | * contains a CPL message. |
| 122 | */ |
| 123 | static inline void *cplhdr(struct sk_buff *skb) |
| 124 | { |
| 125 | return skb->data; |
| 126 | } |
| 127 | |
| 128 | void t3_register_cpl_handler(unsigned int opcode, cpl_handler_func h); |
| 129 | |
| 130 | union listen_entry { |
| 131 | struct t3c_tid_entry t3c_tid; |
| 132 | union listen_entry *next; |
| 133 | }; |
| 134 | |
| 135 | union active_open_entry { |
| 136 | struct t3c_tid_entry t3c_tid; |
| 137 | union active_open_entry *next; |
| 138 | }; |
| 139 | |
| 140 | /* |
| 141 | * Holds the size, base address, free list start, etc of the TID, server TID, |
| 142 | * and active-open TID tables for a offload device. |
| 143 | * The tables themselves are allocated dynamically. |
| 144 | */ |
| 145 | struct tid_info { |
| 146 | struct t3c_tid_entry *tid_tab; |
| 147 | unsigned int ntids; |
| 148 | atomic_t tids_in_use; |
| 149 | |
| 150 | union listen_entry *stid_tab; |
| 151 | unsigned int nstids; |
| 152 | unsigned int stid_base; |
| 153 | |
| 154 | union active_open_entry *atid_tab; |
| 155 | unsigned int natids; |
| 156 | unsigned int atid_base; |
| 157 | |
| 158 | /* |
| 159 | * The following members are accessed R/W so we put them in their own |
| 160 | * cache lines. |
| 161 | * |
| 162 | * XXX We could combine the atid fields above with the lock here since |
| 163 | * atids are use once (unlike other tids). OTOH the above fields are |
| 164 | * usually in cache due to tid_tab. |
| 165 | */ |
| 166 | spinlock_t atid_lock ____cacheline_aligned_in_smp; |
| 167 | union active_open_entry *afree; |
| 168 | unsigned int atids_in_use; |
| 169 | |
| 170 | spinlock_t stid_lock ____cacheline_aligned; |
| 171 | union listen_entry *sfree; |
| 172 | unsigned int stids_in_use; |
| 173 | }; |
| 174 | |
| 175 | struct t3c_data { |
| 176 | struct list_head list_node; |
| 177 | struct t3cdev *dev; |
| 178 | unsigned int tx_max_chunk; /* max payload for TX_DATA */ |
| 179 | unsigned int max_wrs; /* max in-flight WRs per connection */ |
| 180 | unsigned int nmtus; |
| 181 | const unsigned short *mtus; |
| 182 | struct tid_info tid_maps; |
| 183 | |
| 184 | struct t3c_tid_entry *tid_release_list; |
| 185 | spinlock_t tid_release_lock; |
| 186 | struct work_struct tid_release_task; |
| 187 | }; |
| 188 | |
| 189 | /* |
| 190 | * t3cdev -> t3c_data accessor |
| 191 | */ |
| 192 | #define T3C_DATA(dev) (*(struct t3c_data **)&(dev)->l4opt) |
| 193 | |
| 194 | #endif |