Bryan O'Sullivan | d41d3ae | 2006-03-29 15:23:25 -0800 | [diff] [blame] | 1 | #ifndef IPS_COMMON_H |
| 2 | #define IPS_COMMON_H |
| 3 | /* |
| 4 | * Copyright (c) 2003, 2004, 2005, 2006 PathScale, Inc. All rights reserved. |
| 5 | * |
| 6 | * This software is available to you under a choice of one of two |
| 7 | * licenses. You may choose to be licensed under the terms of the GNU |
| 8 | * General Public License (GPL) Version 2, available from the file |
| 9 | * COPYING in the main directory of this source tree, or the |
| 10 | * OpenIB.org BSD license below: |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or |
| 13 | * without modification, are permitted provided that the following |
| 14 | * conditions are met: |
| 15 | * |
| 16 | * - Redistributions of source code must retain the above |
| 17 | * copyright notice, this list of conditions and the following |
| 18 | * disclaimer. |
| 19 | * |
| 20 | * - Redistributions in binary form must reproduce the above |
| 21 | * copyright notice, this list of conditions and the following |
| 22 | * disclaimer in the documentation and/or other materials |
| 23 | * provided with the distribution. |
| 24 | * |
| 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 26 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 27 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 29 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 30 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 31 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 32 | * SOFTWARE. |
| 33 | */ |
| 34 | |
| 35 | #include "ipath_common.h" |
| 36 | |
| 37 | struct ipath_header { |
| 38 | /* |
| 39 | * Version - 4 bits, Port - 4 bits, TID - 10 bits and Offset - |
| 40 | * 14 bits before ECO change ~28 Dec 03. After that, Vers 4, |
| 41 | * Port 3, TID 11, offset 14. |
| 42 | */ |
| 43 | __le32 ver_port_tid_offset; |
| 44 | __le16 chksum; |
| 45 | __le16 pkt_flags; |
| 46 | }; |
| 47 | |
| 48 | struct ips_message_header { |
| 49 | __be16 lrh[4]; |
| 50 | __be32 bth[3]; |
| 51 | /* fields below this point are in host byte order */ |
| 52 | struct ipath_header iph; |
| 53 | __u8 sub_opcode; |
| 54 | __u8 flags; |
| 55 | __u16 src_rank; |
| 56 | /* 24 bits. The upper 8 bit is available for other use */ |
| 57 | union { |
| 58 | struct { |
| 59 | unsigned ack_seq_num:24; |
| 60 | unsigned port:4; |
| 61 | unsigned unused:4; |
| 62 | }; |
| 63 | __u32 ack_seq_num_org; |
| 64 | }; |
| 65 | __u8 expected_tid_session_id; |
| 66 | __u8 tinylen; /* to aid MPI */ |
| 67 | union { |
| 68 | __u16 tag; /* to aid MPI */ |
| 69 | __u16 mqhdr; /* for PSM MQ */ |
| 70 | }; |
| 71 | union { |
| 72 | __u32 mpi[4]; /* to aid MPI */ |
| 73 | __u32 data[4]; |
| 74 | __u64 mq[2]; /* for PSM MQ */ |
| 75 | struct { |
| 76 | __u16 mtu; |
| 77 | __u8 major_ver; |
| 78 | __u8 minor_ver; |
| 79 | __u32 not_used; //free |
| 80 | __u32 run_id; |
| 81 | __u32 client_ver; |
| 82 | }; |
| 83 | }; |
| 84 | }; |
| 85 | |
| 86 | struct ether_header { |
| 87 | __be16 lrh[4]; |
| 88 | __be32 bth[3]; |
| 89 | struct ipath_header iph; |
| 90 | __u8 sub_opcode; |
| 91 | __u8 cmd; |
| 92 | __be16 lid; |
| 93 | __u16 mac[3]; |
| 94 | __u8 frag_num; |
| 95 | __u8 seq_num; |
| 96 | __le32 len; |
| 97 | /* MUST be of word size due to PIO write requirements */ |
Bryan O'Sullivan | ae15f54 | 2006-04-24 14:23:07 -0700 | [diff] [blame] | 98 | __le32 csum; |
Bryan O'Sullivan | d41d3ae | 2006-03-29 15:23:25 -0800 | [diff] [blame] | 99 | __le16 csum_offset; |
| 100 | __le16 flags; |
| 101 | __u16 first_2_bytes; |
| 102 | __u8 unused[2]; /* currently unused */ |
| 103 | }; |
| 104 | |
| 105 | /* |
| 106 | * The PIO buffer used for sending infinipath messages must only be written |
| 107 | * in 32-bit words, all the data must be written, and no writes can occur |
| 108 | * after the last word is written (which transfers "ownership" of the buffer |
| 109 | * to the chip and triggers the message to be sent). |
| 110 | * Since the Linux sk_buff structure can be recursive, non-aligned, and |
| 111 | * any number of bytes in each segment, we use the following structure |
| 112 | * to keep information about the overall state of the copy operation. |
| 113 | * This is used to save the information needed to store the checksum |
| 114 | * in the right place before sending the last word to the hardware and |
| 115 | * to buffer the last 0-3 bytes of non-word sized segments. |
| 116 | */ |
| 117 | struct copy_data_s { |
| 118 | struct ether_header *hdr; |
| 119 | /* addr of PIO buf to write csum to */ |
| 120 | __u32 __iomem *csum_pio; |
| 121 | __u32 __iomem *to; /* addr of PIO buf to write data to */ |
| 122 | __u32 device; /* which device to allocate PIO bufs from */ |
| 123 | __s32 error; /* set if there is an error. */ |
| 124 | __s32 extra; /* amount of data saved in u.buf below */ |
| 125 | __u32 len; /* total length to send in bytes */ |
| 126 | __u32 flen; /* frament length in words */ |
| 127 | __u32 csum; /* partial IP checksum */ |
| 128 | __u32 pos; /* position for partial checksum */ |
| 129 | __u32 offset; /* offset to where data currently starts */ |
| 130 | __s32 checksum_calc; /* set to 1 when csum has been calculated */ |
| 131 | struct sk_buff *skb; |
| 132 | union { |
| 133 | __u32 w; |
| 134 | __u8 buf[4]; |
| 135 | } u; |
| 136 | }; |
| 137 | |
| 138 | /* IB - LRH header consts */ |
| 139 | #define IPS_LRH_GRH 0x0003 /* 1. word of IB LRH - next header: GRH */ |
| 140 | #define IPS_LRH_BTH 0x0002 /* 1. word of IB LRH - next header: BTH */ |
| 141 | |
| 142 | #define IPS_OFFSET 0 |
| 143 | |
| 144 | /* |
| 145 | * defines the cut-off point between the header queue and eager/expected |
| 146 | * TID queue |
| 147 | */ |
| 148 | #define NUM_OF_EXTRA_WORDS_IN_HEADER_QUEUE \ |
| 149 | ((sizeof(struct ips_message_header) - \ |
| 150 | offsetof(struct ips_message_header, iph)) >> 2) |
| 151 | |
| 152 | /* OpCodes */ |
| 153 | #define OPCODE_IPS 0xC0 |
| 154 | #define OPCODE_ITH4X 0xC1 |
| 155 | |
| 156 | /* OpCode 30 is use by stand-alone test programs */ |
| 157 | #define OPCODE_RAW_DATA 0xDE |
| 158 | /* last OpCode (31) is reserved for test */ |
| 159 | #define OPCODE_TEST 0xDF |
| 160 | |
| 161 | /* sub OpCodes - ips */ |
| 162 | #define OPCODE_SEQ_DATA 0x01 |
| 163 | #define OPCODE_SEQ_CTRL 0x02 |
| 164 | |
| 165 | #define OPCODE_SEQ_MQ_DATA 0x03 |
| 166 | #define OPCODE_SEQ_MQ_CTRL 0x04 |
| 167 | |
| 168 | #define OPCODE_ACK 0x10 |
| 169 | #define OPCODE_NAK 0x11 |
| 170 | |
| 171 | #define OPCODE_ERR_CHK 0x20 |
| 172 | #define OPCODE_ERR_CHK_PLS 0x21 |
| 173 | |
| 174 | #define OPCODE_STARTUP 0x30 |
| 175 | #define OPCODE_STARTUP_ACK 0x31 |
| 176 | #define OPCODE_STARTUP_NAK 0x32 |
| 177 | |
| 178 | #define OPCODE_STARTUP_EXT 0x34 |
| 179 | #define OPCODE_STARTUP_ACK_EXT 0x35 |
| 180 | #define OPCODE_STARTUP_NAK_EXT 0x36 |
| 181 | |
| 182 | #define OPCODE_TIDS_RELEASE 0x40 |
| 183 | #define OPCODE_TIDS_RELEASE_CONFIRM 0x41 |
| 184 | |
| 185 | #define OPCODE_CLOSE 0x50 |
| 186 | #define OPCODE_CLOSE_ACK 0x51 |
| 187 | /* |
| 188 | * like OPCODE_CLOSE, but no complaint if other side has already closed. |
| 189 | * Used when doing abort(), MPI_Abort(), etc. |
| 190 | */ |
| 191 | #define OPCODE_ABORT 0x52 |
| 192 | |
| 193 | /* sub OpCodes - ith4x */ |
| 194 | #define OPCODE_ENCAP 0x81 |
| 195 | #define OPCODE_LID_ARP 0x82 |
| 196 | |
| 197 | /* Receive Header Queue: receive type (from infinipath) */ |
| 198 | #define RCVHQ_RCV_TYPE_EXPECTED 0 |
| 199 | #define RCVHQ_RCV_TYPE_EAGER 1 |
| 200 | #define RCVHQ_RCV_TYPE_NON_KD 2 |
| 201 | #define RCVHQ_RCV_TYPE_ERROR 3 |
| 202 | |
| 203 | /* misc. */ |
| 204 | #define SIZE_OF_CRC 1 |
| 205 | |
| 206 | #define EAGER_TID_ID INFINIPATH_I_TID_MASK |
| 207 | |
| 208 | #define IPS_DEFAULT_P_KEY 0xFFFF |
| 209 | |
| 210 | #define IPS_PERMISSIVE_LID 0xFFFF |
| 211 | #define IPS_MULTICAST_LID_BASE 0xC000 |
| 212 | |
| 213 | #define IPS_AETH_CREDIT_SHIFT 24 |
| 214 | #define IPS_AETH_CREDIT_MASK 0x1F |
| 215 | #define IPS_AETH_CREDIT_INVAL 0x1F |
| 216 | |
| 217 | #define IPS_PSN_MASK 0xFFFFFF |
| 218 | #define IPS_MSN_MASK 0xFFFFFF |
| 219 | #define IPS_QPN_MASK 0xFFFFFF |
| 220 | #define IPS_MULTICAST_QPN 0xFFFFFF |
| 221 | |
| 222 | /* functions for extracting fields from rcvhdrq entries */ |
| 223 | static inline __u32 ips_get_hdr_err_flags(const __le32 * rbuf) |
| 224 | { |
| 225 | return __le32_to_cpu(rbuf[1]); |
| 226 | } |
| 227 | |
| 228 | static inline __u32 ips_get_index(const __le32 * rbuf) |
| 229 | { |
| 230 | return (__le32_to_cpu(rbuf[0]) >> INFINIPATH_RHF_EGRINDEX_SHIFT) |
| 231 | & INFINIPATH_RHF_EGRINDEX_MASK; |
| 232 | } |
| 233 | |
| 234 | static inline __u32 ips_get_rcv_type(const __le32 * rbuf) |
| 235 | { |
| 236 | return (__le32_to_cpu(rbuf[0]) >> INFINIPATH_RHF_RCVTYPE_SHIFT) |
| 237 | & INFINIPATH_RHF_RCVTYPE_MASK; |
| 238 | } |
| 239 | |
| 240 | static inline __u32 ips_get_length_in_bytes(const __le32 * rbuf) |
| 241 | { |
| 242 | return ((__le32_to_cpu(rbuf[0]) >> INFINIPATH_RHF_LENGTH_SHIFT) |
| 243 | & INFINIPATH_RHF_LENGTH_MASK) << 2; |
| 244 | } |
| 245 | |
| 246 | static inline void *ips_get_first_protocol_header(const __u32 * rbuf) |
| 247 | { |
| 248 | return (void *)&rbuf[2]; |
| 249 | } |
| 250 | |
| 251 | static inline struct ips_message_header *ips_get_ips_header(const __u32 * |
| 252 | rbuf) |
| 253 | { |
| 254 | return (struct ips_message_header *)&rbuf[2]; |
| 255 | } |
| 256 | |
| 257 | static inline __u32 ips_get_ipath_ver(__le32 hdrword) |
| 258 | { |
| 259 | return (__le32_to_cpu(hdrword) >> INFINIPATH_I_VERS_SHIFT) |
| 260 | & INFINIPATH_I_VERS_MASK; |
| 261 | } |
| 262 | |
| 263 | #endif /* IPS_COMMON_H */ |