Path: blob/master/drivers/infiniband/hw/nes/nes_cm.h
15112 views
/*1* Copyright (c) 2006 - 2009 Intel Corporation. All rights reserved.2*3* This software is available to you under a choice of one of two4* licenses. You may choose to be licensed under the terms of the GNU5* General Public License (GPL) Version 2, available from the file6* COPYING in the main directory of this source tree, or the7* OpenIB.org BSD license below:8*9* Redistribution and use in source and binary forms, with or10* without modification, are permitted provided that the following11* conditions are met:12*13* - Redistributions of source code must retain the above14* copyright notice, this list of conditions and the following15* disclaimer.16*17* - Redistributions in binary form must reproduce the above18* copyright notice, this list of conditions and the following19* disclaimer in the documentation and/or other materials20* provided with the distribution.21*22* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,23* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF24* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND25* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS26* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN27* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN28* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE29* SOFTWARE.30*31*/3233#ifndef NES_CM_H34#define NES_CM_H3536#define QUEUE_EVENTS3738#define NES_MANAGE_APBVT_DEL 039#define NES_MANAGE_APBVT_ADD 14041#define NES_MPA_REQUEST_ACCEPT 142#define NES_MPA_REQUEST_REJECT 24344/* IETF MPA -- defines, enums, structs */45#define IEFT_MPA_KEY_REQ "MPA ID Req Frame"46#define IEFT_MPA_KEY_REP "MPA ID Rep Frame"47#define IETF_MPA_KEY_SIZE 1648#define IETF_MPA_VERSION 149#define IETF_MAX_PRIV_DATA_LEN 51250#define IETF_MPA_FRAME_SIZE 205152enum ietf_mpa_flags {53IETF_MPA_FLAGS_MARKERS = 0x80, /* receive Markers */54IETF_MPA_FLAGS_CRC = 0x40, /* receive Markers */55IETF_MPA_FLAGS_REJECT = 0x20, /* Reject */56};5758struct ietf_mpa_frame {59u8 key[IETF_MPA_KEY_SIZE];60u8 flags;61u8 rev;62__be16 priv_data_len;63u8 priv_data[0];64};6566#define ietf_mpa_req_resp_frame ietf_mpa_frame6768struct nes_v4_quad {69u32 rsvd0;70__le32 DstIpAdrIndex; /* Only most significant 5 bits are valid */71__be32 SrcIpadr;72__be16 TcpPorts[2]; /* src is low, dest is high */73};7475struct nes_cm_node;76enum nes_timer_type {77NES_TIMER_TYPE_SEND,78NES_TIMER_TYPE_RECV,79NES_TIMER_NODE_CLEANUP,80NES_TIMER_TYPE_CLOSE,81};8283#define NES_PASSIVE_STATE_INDICATED 084#define NES_DO_NOT_SEND_RESET_EVENT 185#define NES_SEND_RESET_EVENT 28687#define MAX_NES_IFS 48889#define SET_ACK 190#define SET_SYN 291#define SET_FIN 492#define SET_RST 89394#define TCP_OPTIONS_PADDING 39596struct option_base {97u8 optionnum;98u8 length;99};100101enum option_numbers {102OPTION_NUMBER_END,103OPTION_NUMBER_NONE,104OPTION_NUMBER_MSS,105OPTION_NUMBER_WINDOW_SCALE,106OPTION_NUMBER_SACK_PERM,107OPTION_NUMBER_SACK,108OPTION_NUMBER_WRITE0 = 0xbc109};110111struct option_mss {112u8 optionnum;113u8 length;114__be16 mss;115};116117struct option_windowscale {118u8 optionnum;119u8 length;120u8 shiftcount;121};122123union all_known_options {124char as_end;125struct option_base as_base;126struct option_mss as_mss;127struct option_windowscale as_windowscale;128};129130struct nes_timer_entry {131struct list_head list;132unsigned long timetosend; /* jiffies */133struct sk_buff *skb;134u32 type;135u32 retrycount;136u32 retranscount;137u32 context;138u32 seq_num;139u32 send_retrans;140int close_when_complete;141struct net_device *netdev;142};143144#define NES_DEFAULT_RETRYS 64145#define NES_DEFAULT_RETRANS 8146#ifdef CONFIG_INFINIBAND_NES_DEBUG147#define NES_RETRY_TIMEOUT (1000*HZ/1000)148#else149#define NES_RETRY_TIMEOUT (3000*HZ/1000)150#endif151#define NES_SHORT_TIME (10)152#define NES_LONG_TIME (2000*HZ/1000)153#define NES_MAX_TIMEOUT ((unsigned long) (12*HZ))154155#define NES_CM_HASHTABLE_SIZE 1024156#define NES_CM_TCP_TIMER_INTERVAL 3000157#define NES_CM_DEFAULT_MTU 1540158#define NES_CM_DEFAULT_FRAME_CNT 10159#define NES_CM_THREAD_STACK_SIZE 256160#define NES_CM_DEFAULT_RCV_WND 64240 // before we know that window scaling is allowed161#define NES_CM_DEFAULT_RCV_WND_SCALED 256960 // after we know that window scaling is allowed162#define NES_CM_DEFAULT_RCV_WND_SCALE 2163#define NES_CM_DEFAULT_FREE_PKTS 0x000A164#define NES_CM_FREE_PKT_LO_WATERMARK 2165166#define NES_CM_DEFAULT_MSS 536167168#define NES_CM_DEF_SEQ 0x159bf75f169#define NES_CM_DEF_LOCAL_ID 0x3b47170171#define NES_CM_DEF_SEQ2 0x18ed5740172#define NES_CM_DEF_LOCAL_ID2 0xb807173#define MAX_CM_BUFFER (IETF_MPA_FRAME_SIZE + IETF_MAX_PRIV_DATA_LEN)174175176typedef u32 nes_addr_t;177178#define nes_cm_tsa_context nes_qp_context179180struct nes_qp;181182/* cm node transition states */183enum nes_cm_node_state {184NES_CM_STATE_UNKNOWN,185NES_CM_STATE_INITED,186NES_CM_STATE_LISTENING,187NES_CM_STATE_SYN_RCVD,188NES_CM_STATE_SYN_SENT,189NES_CM_STATE_ONE_SIDE_ESTABLISHED,190NES_CM_STATE_ESTABLISHED,191NES_CM_STATE_ACCEPTING,192NES_CM_STATE_MPAREQ_SENT,193NES_CM_STATE_MPAREQ_RCVD,194NES_CM_STATE_MPAREJ_RCVD,195NES_CM_STATE_TSA,196NES_CM_STATE_FIN_WAIT1,197NES_CM_STATE_FIN_WAIT2,198NES_CM_STATE_CLOSE_WAIT,199NES_CM_STATE_TIME_WAIT,200NES_CM_STATE_LAST_ACK,201NES_CM_STATE_CLOSING,202NES_CM_STATE_LISTENER_DESTROYED,203NES_CM_STATE_CLOSED204};205206enum nes_tcpip_pkt_type {207NES_PKT_TYPE_UNKNOWN,208NES_PKT_TYPE_SYN,209NES_PKT_TYPE_SYNACK,210NES_PKT_TYPE_ACK,211NES_PKT_TYPE_FIN,212NES_PKT_TYPE_RST213};214215216/* type of nes connection */217enum nes_cm_conn_type {218NES_CM_IWARP_CONN_TYPE,219};220221/* CM context params */222struct nes_cm_tcp_context {223u8 client;224225u32 loc_seq_num;226u32 loc_ack_num;227u32 rem_ack_num;228u32 rcv_nxt;229230u32 loc_id;231u32 rem_id;232233u32 snd_wnd;234u32 max_snd_wnd;235236u32 rcv_wnd;237u32 mss;238u8 snd_wscale;239u8 rcv_wscale;240241struct nes_cm_tsa_context tsa_cntxt;242struct timeval sent_ts;243};244245246enum nes_cm_listener_state {247NES_CM_LISTENER_PASSIVE_STATE=1,248NES_CM_LISTENER_ACTIVE_STATE=2,249NES_CM_LISTENER_EITHER_STATE=3250};251252struct nes_cm_listener {253struct list_head list;254struct nes_cm_core *cm_core;255u8 loc_mac[ETH_ALEN];256nes_addr_t loc_addr;257u16 loc_port;258struct iw_cm_id *cm_id;259enum nes_cm_conn_type conn_type;260atomic_t ref_count;261struct nes_vnic *nesvnic;262atomic_t pend_accepts_cnt;263int backlog;264enum nes_cm_listener_state listener_state;265u32 reused_node;266};267268/* per connection node and node state information */269struct nes_cm_node {270nes_addr_t loc_addr, rem_addr;271u16 loc_port, rem_port;272273u8 loc_mac[ETH_ALEN];274u8 rem_mac[ETH_ALEN];275276enum nes_cm_node_state state;277struct nes_cm_tcp_context tcp_cntxt;278struct nes_cm_core *cm_core;279struct sk_buff_head resend_list;280atomic_t ref_count;281struct net_device *netdev;282283struct nes_cm_node *loopbackpartner;284285struct nes_timer_entry *send_entry;286287spinlock_t retrans_list_lock;288struct nes_timer_entry *recv_entry;289290int send_write0;291union {292struct ietf_mpa_frame mpa_frame;293u8 mpa_frame_buf[MAX_CM_BUFFER];294};295u16 mpa_frame_size;296struct iw_cm_id *cm_id;297struct list_head list;298int accelerated;299struct nes_cm_listener *listener;300enum nes_cm_conn_type conn_type;301struct nes_vnic *nesvnic;302int apbvt_set;303int accept_pend;304struct list_head timer_entry;305struct list_head reset_entry;306struct nes_qp *nesqp;307atomic_t passive_state;308};309310/* structure for client or CM to fill when making CM api calls. */311/* - only need to set relevant data, based on op. */312struct nes_cm_info {313union {314struct iw_cm_id *cm_id;315struct net_device *netdev;316};317318u16 loc_port;319u16 rem_port;320nes_addr_t loc_addr;321nes_addr_t rem_addr;322323enum nes_cm_conn_type conn_type;324int backlog;325};326327/* CM event codes */328enum nes_cm_event_type {329NES_CM_EVENT_UNKNOWN,330NES_CM_EVENT_ESTABLISHED,331NES_CM_EVENT_MPA_REQ,332NES_CM_EVENT_MPA_CONNECT,333NES_CM_EVENT_MPA_ACCEPT,334NES_CM_EVENT_MPA_REJECT,335NES_CM_EVENT_MPA_ESTABLISHED,336NES_CM_EVENT_CONNECTED,337NES_CM_EVENT_CLOSED,338NES_CM_EVENT_RESET,339NES_CM_EVENT_DROPPED_PKT,340NES_CM_EVENT_CLOSE_IMMED,341NES_CM_EVENT_CLOSE_HARD,342NES_CM_EVENT_CLOSE_CLEAN,343NES_CM_EVENT_ABORTED,344NES_CM_EVENT_SEND_FIRST345};346347/* event to post to CM event handler */348struct nes_cm_event {349enum nes_cm_event_type type;350351struct nes_cm_info cm_info;352struct work_struct event_work;353struct nes_cm_node *cm_node;354};355356struct nes_cm_core {357enum nes_cm_node_state state;358359atomic_t listen_node_cnt;360struct nes_cm_node listen_list;361spinlock_t listen_list_lock;362363u32 mtu;364u32 free_tx_pkt_max;365u32 rx_pkt_posted;366atomic_t ht_node_cnt;367struct list_head connected_nodes;368/* struct list_head hashtable[NES_CM_HASHTABLE_SIZE]; */369spinlock_t ht_lock;370371struct timer_list tcp_timer;372373struct nes_cm_ops *api;374375int (*post_event)(struct nes_cm_event *event);376atomic_t events_posted;377struct workqueue_struct *event_wq;378struct workqueue_struct *disconn_wq;379380atomic_t node_cnt;381u64 aborted_connects;382u32 options;383384struct nes_cm_node *current_listen_node;385};386387388#define NES_CM_SET_PKT_SIZE (1 << 1)389#define NES_CM_SET_FREE_PKT_Q_SIZE (1 << 2)390391/* CM ops/API for client interface */392struct nes_cm_ops {393int (*accelerated)(struct nes_cm_core *, struct nes_cm_node *);394struct nes_cm_listener * (*listen)(struct nes_cm_core *, struct nes_vnic *,395struct nes_cm_info *);396int (*stop_listener)(struct nes_cm_core *, struct nes_cm_listener *);397struct nes_cm_node * (*connect)(struct nes_cm_core *,398struct nes_vnic *, u16, void *,399struct nes_cm_info *);400int (*close)(struct nes_cm_core *, struct nes_cm_node *);401int (*accept)(struct nes_cm_core *, struct ietf_mpa_frame *,402struct nes_cm_node *);403int (*reject)(struct nes_cm_core *, struct ietf_mpa_frame *,404struct nes_cm_node *);405int (*recv_pkt)(struct nes_cm_core *, struct nes_vnic *,406struct sk_buff *);407int (*destroy_cm_core)(struct nes_cm_core *);408int (*get)(struct nes_cm_core *);409int (*set)(struct nes_cm_core *, u32, u32);410};411412int schedule_nes_timer(struct nes_cm_node *, struct sk_buff *,413enum nes_timer_type, int, int);414415int nes_accept(struct iw_cm_id *, struct iw_cm_conn_param *);416int nes_reject(struct iw_cm_id *, const void *, u8);417int nes_connect(struct iw_cm_id *, struct iw_cm_conn_param *);418int nes_create_listen(struct iw_cm_id *, int);419int nes_destroy_listen(struct iw_cm_id *);420421int nes_cm_recv(struct sk_buff *, struct net_device *);422int nes_cm_start(void);423int nes_cm_stop(void);424425#endif /* NES_CM_H */426427428