linux/drivers/infiniband/hw/nes/nes_cm.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2006 - 2009 Intel-NE, Inc.  All rights reserved.
   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 */
  33
  34#ifndef NES_CM_H
  35#define NES_CM_H
  36
  37#define QUEUE_EVENTS
  38
  39#define NES_MANAGE_APBVT_DEL 0
  40#define NES_MANAGE_APBVT_ADD 1
  41
  42#define NES_MPA_REQUEST_ACCEPT  1
  43#define NES_MPA_REQUEST_REJECT  2
  44
  45/* IETF MPA -- defines, enums, structs */
  46#define IEFT_MPA_KEY_REQ  "MPA ID Req Frame"
  47#define IEFT_MPA_KEY_REP  "MPA ID Rep Frame"
  48#define IETF_MPA_KEY_SIZE 16
  49#define IETF_MPA_VERSION  1
  50
  51enum ietf_mpa_flags {
  52        IETF_MPA_FLAGS_MARKERS = 0x80,  /* receive Markers */
  53        IETF_MPA_FLAGS_CRC     = 0x40,  /* receive Markers */
  54        IETF_MPA_FLAGS_REJECT  = 0x20,  /* Reject */
  55};
  56
  57struct ietf_mpa_frame {
  58        u8 key[IETF_MPA_KEY_SIZE];
  59        u8 flags;
  60        u8 rev;
  61        __be16 priv_data_len;
  62        u8 priv_data[0];
  63};
  64
  65#define ietf_mpa_req_resp_frame ietf_mpa_frame
  66
  67struct nes_v4_quad {
  68        u32 rsvd0;
  69        __le32 DstIpAdrIndex;   /* Only most significant 5 bits are valid */
  70        __be32 SrcIpadr;
  71        __be16 TcpPorts[2];             /* src is low, dest is high */
  72};
  73
  74struct nes_cm_node;
  75enum nes_timer_type {
  76        NES_TIMER_TYPE_SEND,
  77        NES_TIMER_TYPE_RECV,
  78        NES_TIMER_NODE_CLEANUP,
  79        NES_TIMER_TYPE_CLOSE,
  80};
  81
  82#define NES_PASSIVE_STATE_INDICATED     0
  83#define NES_DO_NOT_SEND_RESET_EVENT     1
  84#define NES_SEND_RESET_EVENT            2
  85
  86#define MAX_NES_IFS 4
  87
  88#define SET_ACK 1
  89#define SET_SYN 2
  90#define SET_FIN 4
  91#define SET_RST 8
  92
  93#define TCP_OPTIONS_PADDING     3
  94
  95struct option_base {
  96        u8 optionnum;
  97        u8 length;
  98};
  99
 100enum option_numbers {
 101        OPTION_NUMBER_END,
 102        OPTION_NUMBER_NONE,
 103        OPTION_NUMBER_MSS,
 104        OPTION_NUMBER_WINDOW_SCALE,
 105        OPTION_NUMBER_SACK_PERM,
 106        OPTION_NUMBER_SACK,
 107        OPTION_NUMBER_WRITE0 = 0xbc
 108};
 109
 110struct option_mss {
 111        u8 optionnum;
 112        u8 length;
 113        __be16 mss;
 114};
 115
 116struct option_windowscale {
 117        u8 optionnum;
 118        u8 length;
 119        u8 shiftcount;
 120};
 121
 122union all_known_options {
 123        char as_end;
 124        struct option_base as_base;
 125        struct option_mss as_mss;
 126        struct option_windowscale as_windowscale;
 127};
 128
 129struct nes_timer_entry {
 130        struct list_head list;
 131        unsigned long timetosend;       /* jiffies */
 132        struct sk_buff *skb;
 133        u32 type;
 134        u32 retrycount;
 135        u32 retranscount;
 136        u32 context;
 137        u32 seq_num;
 138        u32 send_retrans;
 139        int close_when_complete;
 140        struct net_device *netdev;
 141};
 142
 143#define NES_DEFAULT_RETRYS  64
 144#define NES_DEFAULT_RETRANS 8
 145#ifdef CONFIG_INFINIBAND_NES_DEBUG
 146#define NES_RETRY_TIMEOUT   (1000*HZ/1000)
 147#else
 148#define NES_RETRY_TIMEOUT   (3000*HZ/1000)
 149#endif
 150#define NES_SHORT_TIME      (10)
 151#define NES_LONG_TIME       (2000*HZ/1000)
 152#define NES_MAX_TIMEOUT     ((unsigned long) (12*HZ))
 153
 154#define NES_CM_HASHTABLE_SIZE         1024
 155#define NES_CM_TCP_TIMER_INTERVAL     3000
 156#define NES_CM_DEFAULT_MTU            1540
 157#define NES_CM_DEFAULT_FRAME_CNT      10
 158#define NES_CM_THREAD_STACK_SIZE      256
 159#define NES_CM_DEFAULT_RCV_WND        64240     // before we know that window scaling is allowed
 160#define NES_CM_DEFAULT_RCV_WND_SCALED 256960  // after we know that window scaling is allowed
 161#define NES_CM_DEFAULT_RCV_WND_SCALE  2
 162#define NES_CM_DEFAULT_FREE_PKTS      0x000A
 163#define NES_CM_FREE_PKT_LO_WATERMARK  2
 164
 165#define NES_CM_DEFAULT_MSS   536
 166
 167#define NES_CM_DEF_SEQ       0x159bf75f
 168#define NES_CM_DEF_LOCAL_ID  0x3b47
 169
 170#define NES_CM_DEF_SEQ2      0x18ed5740
 171#define NES_CM_DEF_LOCAL_ID2 0xb807
 172#define MAX_CM_BUFFER   512
 173
 174
 175typedef u32 nes_addr_t;
 176
 177#define nes_cm_tsa_context nes_qp_context
 178
 179struct nes_qp;
 180
 181/* cm node transition states */
 182enum nes_cm_node_state {
 183        NES_CM_STATE_UNKNOWN,
 184        NES_CM_STATE_INITED,
 185        NES_CM_STATE_LISTENING,
 186        NES_CM_STATE_SYN_RCVD,
 187        NES_CM_STATE_SYN_SENT,
 188        NES_CM_STATE_ONE_SIDE_ESTABLISHED,
 189        NES_CM_STATE_ESTABLISHED,
 190        NES_CM_STATE_ACCEPTING,
 191        NES_CM_STATE_MPAREQ_SENT,
 192        NES_CM_STATE_MPAREQ_RCVD,
 193        NES_CM_STATE_MPAREJ_RCVD,
 194        NES_CM_STATE_TSA,
 195        NES_CM_STATE_FIN_WAIT1,
 196        NES_CM_STATE_FIN_WAIT2,
 197        NES_CM_STATE_CLOSE_WAIT,
 198        NES_CM_STATE_TIME_WAIT,
 199        NES_CM_STATE_LAST_ACK,
 200        NES_CM_STATE_CLOSING,
 201        NES_CM_STATE_CLOSED
 202};
 203
 204enum nes_tcpip_pkt_type {
 205        NES_PKT_TYPE_UNKNOWN,
 206        NES_PKT_TYPE_SYN,
 207        NES_PKT_TYPE_SYNACK,
 208        NES_PKT_TYPE_ACK,
 209        NES_PKT_TYPE_FIN,
 210        NES_PKT_TYPE_RST
 211};
 212
 213
 214/* type of nes connection */
 215enum nes_cm_conn_type {
 216        NES_CM_IWARP_CONN_TYPE,
 217};
 218
 219/* CM context params */
 220struct nes_cm_tcp_context {
 221        u8  client;
 222
 223        u32 loc_seq_num;
 224        u32 loc_ack_num;
 225        u32 rem_ack_num;
 226        u32 rcv_nxt;
 227
 228        u32 loc_id;
 229        u32 rem_id;
 230
 231        u32 snd_wnd;
 232        u32 max_snd_wnd;
 233
 234        u32 rcv_wnd;
 235        u32 mss;
 236        u8  snd_wscale;
 237        u8  rcv_wscale;
 238
 239        struct nes_cm_tsa_context tsa_cntxt;
 240        struct timeval            sent_ts;
 241};
 242
 243
 244enum nes_cm_listener_state {
 245        NES_CM_LISTENER_PASSIVE_STATE=1,
 246        NES_CM_LISTENER_ACTIVE_STATE=2,
 247        NES_CM_LISTENER_EITHER_STATE=3
 248};
 249
 250struct nes_cm_listener {
 251        struct list_head           list;
 252        struct nes_cm_core         *cm_core;
 253        u8                         loc_mac[ETH_ALEN];
 254        nes_addr_t                 loc_addr;
 255        u16                        loc_port;
 256        struct iw_cm_id            *cm_id;
 257        enum nes_cm_conn_type      conn_type;
 258        atomic_t                   ref_count;
 259        struct nes_vnic            *nesvnic;
 260        atomic_t                   pend_accepts_cnt;
 261        int                        backlog;
 262        enum nes_cm_listener_state listener_state;
 263        u32                        reused_node;
 264};
 265
 266/* per connection node and node state information */
 267struct nes_cm_node {
 268        nes_addr_t                loc_addr, rem_addr;
 269        u16                       loc_port, rem_port;
 270
 271        u8                        loc_mac[ETH_ALEN];
 272        u8                        rem_mac[ETH_ALEN];
 273
 274        enum nes_cm_node_state    state;
 275        struct nes_cm_tcp_context tcp_cntxt;
 276        struct nes_cm_core        *cm_core;
 277        struct sk_buff_head       resend_list;
 278        atomic_t                  ref_count;
 279        struct net_device         *netdev;
 280
 281        struct nes_cm_node        *loopbackpartner;
 282
 283        struct nes_timer_entry  *send_entry;
 284
 285        spinlock_t                retrans_list_lock;
 286        struct nes_timer_entry  *recv_entry;
 287
 288        int                       send_write0;
 289        union {
 290                struct ietf_mpa_frame mpa_frame;
 291                u8                    mpa_frame_buf[MAX_CM_BUFFER];
 292        };
 293        u16                       mpa_frame_size;
 294        struct iw_cm_id           *cm_id;
 295        struct list_head          list;
 296        int                       accelerated;
 297        struct nes_cm_listener    *listener;
 298        enum nes_cm_conn_type     conn_type;
 299        struct nes_vnic           *nesvnic;
 300        int                       apbvt_set;
 301        int                       accept_pend;
 302        struct list_head        timer_entry;
 303        struct list_head        reset_entry;
 304        struct nes_qp           *nesqp;
 305        atomic_t                passive_state;
 306};
 307
 308/* structure for client or CM to fill when making CM api calls. */
 309/*      - only need to set relevant data, based on op. */
 310struct nes_cm_info {
 311        union {
 312                struct iw_cm_id   *cm_id;
 313                struct net_device *netdev;
 314        };
 315
 316        u16 loc_port;
 317        u16 rem_port;
 318        nes_addr_t loc_addr;
 319        nes_addr_t rem_addr;
 320
 321        enum nes_cm_conn_type  conn_type;
 322        int backlog;
 323};
 324
 325/* CM event codes */
 326enum  nes_cm_event_type {
 327        NES_CM_EVENT_UNKNOWN,
 328        NES_CM_EVENT_ESTABLISHED,
 329        NES_CM_EVENT_MPA_REQ,
 330        NES_CM_EVENT_MPA_CONNECT,
 331        NES_CM_EVENT_MPA_ACCEPT,
 332        NES_CM_EVENT_MPA_REJECT,
 333        NES_CM_EVENT_MPA_ESTABLISHED,
 334        NES_CM_EVENT_CONNECTED,
 335        NES_CM_EVENT_CLOSED,
 336        NES_CM_EVENT_RESET,
 337        NES_CM_EVENT_DROPPED_PKT,
 338        NES_CM_EVENT_CLOSE_IMMED,
 339        NES_CM_EVENT_CLOSE_HARD,
 340        NES_CM_EVENT_CLOSE_CLEAN,
 341        NES_CM_EVENT_ABORTED,
 342        NES_CM_EVENT_SEND_FIRST
 343};
 344
 345/* event to post to CM event handler */
 346struct nes_cm_event {
 347        enum nes_cm_event_type type;
 348
 349        struct nes_cm_info cm_info;
 350        struct work_struct event_work;
 351        struct nes_cm_node *cm_node;
 352};
 353
 354struct nes_cm_core {
 355        enum nes_cm_node_state  state;
 356
 357        atomic_t                listen_node_cnt;
 358        struct nes_cm_node      listen_list;
 359        spinlock_t              listen_list_lock;
 360
 361        u32                     mtu;
 362        u32                     free_tx_pkt_max;
 363        u32                     rx_pkt_posted;
 364        atomic_t                ht_node_cnt;
 365        struct list_head        connected_nodes;
 366        /* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */
 367        spinlock_t              ht_lock;
 368
 369        struct timer_list       tcp_timer;
 370
 371        struct nes_cm_ops       *api;
 372
 373        int (*post_event)(struct nes_cm_event *event);
 374        atomic_t                events_posted;
 375        struct workqueue_struct *event_wq;
 376        struct workqueue_struct *disconn_wq;
 377
 378        atomic_t                node_cnt;
 379        u64                     aborted_connects;
 380        u32                     options;
 381
 382        struct nes_cm_node      *current_listen_node;
 383};
 384
 385
 386#define NES_CM_SET_PKT_SIZE        (1 << 1)
 387#define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)
 388
 389/* CM ops/API for client interface */
 390struct nes_cm_ops {
 391        int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);
 392        struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,
 393                        struct nes_cm_info *);
 394        int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);
 395        struct nes_cm_node * (*connect)(struct nes_cm_core *,
 396                        struct nes_vnic *, u16, void *,
 397                        struct nes_cm_info *);
 398        int (*close)(struct nes_cm_core *, struct nes_cm_node *);
 399        int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,
 400                        struct nes_cm_node *);
 401        int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,
 402                        struct nes_cm_node *);
 403        int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,
 404                        struct sk_buff *);
 405        int (*destroy_cm_core)(struct nes_cm_core *);
 406        int (*get)(struct nes_cm_core *);
 407        int (*set)(struct nes_cm_core *, u32, u32);
 408};
 409
 410int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,
 411                enum nes_timer_type, int, int);
 412
 413int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);
 414int nes_reject(struct iw_cm_id *, const void *, u8);
 415int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);
 416int nes_create_listen(struct iw_cm_id *, int);
 417int nes_destroy_listen(struct iw_cm_id *);
 418
 419int nes_cm_recv(struct sk_buff *, struct net_device *);
 420int nes_cm_start(void);
 421int nes_cm_stop(void);
 422
 423#endif                  /* NES_CM_H */
 424