Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

IB/pack: IBoE UD packet packing support

Add support for packing IBoE packet headers.

Signed-off-by: Eli Cohen <eli@mellanox.co.il>

[ Clean up and fix ib_ud_header_init() a bit. - Roland ]

Signed-off-by: Roland Dreier <rolandd@cisco.com>

authored by

Eli Cohen and committed by
Roland Dreier
ff7f5aab 3c86aa70

+112 -37
+88 -27
drivers/infiniband/core/ud_header.c
··· 80 80 .size_bits = 16 } 81 81 }; 82 82 83 + static const struct ib_field eth_table[] = { 84 + { STRUCT_FIELD(eth, dmac_h), 85 + .offset_words = 0, 86 + .offset_bits = 0, 87 + .size_bits = 32 }, 88 + { STRUCT_FIELD(eth, dmac_l), 89 + .offset_words = 1, 90 + .offset_bits = 0, 91 + .size_bits = 16 }, 92 + { STRUCT_FIELD(eth, smac_h), 93 + .offset_words = 1, 94 + .offset_bits = 16, 95 + .size_bits = 16 }, 96 + { STRUCT_FIELD(eth, smac_l), 97 + .offset_words = 2, 98 + .offset_bits = 0, 99 + .size_bits = 32 }, 100 + { STRUCT_FIELD(eth, type), 101 + .offset_words = 3, 102 + .offset_bits = 0, 103 + .size_bits = 16 } 104 + }; 105 + 83 106 static const struct ib_field grh_table[] = { 84 107 { STRUCT_FIELD(grh, ip_version), 85 108 .offset_words = 0, ··· 203 180 /** 204 181 * ib_ud_header_init - Initialize UD header structure 205 182 * @payload_bytes:Length of packet payload 183 + * @lrh_present: specify if LRH is present 184 + * @eth_present: specify if Eth header is present 206 185 * @grh_present:GRH flag (if non-zero, GRH will be included) 207 - * @immediate_present: specify if immediate data should be used 186 + * @immediate_present: specify if immediate data is present 208 187 * @header:Structure to initialize 209 - * 210 - * ib_ud_header_init() initializes the lrh.link_version, lrh.link_next_header, 211 - * lrh.packet_length, grh.ip_version, grh.payload_length, 212 - * grh.next_header, bth.opcode, bth.pad_count and 213 - * bth.transport_header_version fields of a &struct ib_ud_header given 214 - * the payload length and whether a GRH will be included. 215 188 */ 216 189 void ib_ud_header_init(int payload_bytes, 190 + int lrh_present, 191 + int eth_present, 217 192 int grh_present, 218 193 int immediate_present, 219 194 struct ib_ud_header *header) 220 195 { 221 - u16 packet_length; 222 - 223 196 memset(header, 0, sizeof *header); 224 197 225 - header->lrh.link_version = 0; 226 - header->lrh.link_next_header = 227 - grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL; 228 - packet_length = (IB_LRH_BYTES + 229 - IB_BTH_BYTES + 230 - IB_DETH_BYTES + 231 - payload_bytes + 232 - 4 + /* ICRC */ 233 - 3) / 4; /* round up */ 198 + if (lrh_present) { 199 + u16 packet_length; 234 200 235 - header->grh_present = grh_present; 201 + header->lrh.link_version = 0; 202 + header->lrh.link_next_header = 203 + grh_present ? IB_LNH_IBA_GLOBAL : IB_LNH_IBA_LOCAL; 204 + packet_length = (IB_LRH_BYTES + 205 + IB_BTH_BYTES + 206 + IB_DETH_BYTES + 207 + (grh_present ? IB_GRH_BYTES : 0) + 208 + payload_bytes + 209 + 4 + /* ICRC */ 210 + 3) / 4; /* round up */ 211 + header->lrh.packet_length = cpu_to_be16(packet_length); 212 + } 213 + 236 214 if (grh_present) { 237 - packet_length += IB_GRH_BYTES / 4; 238 215 header->grh.ip_version = 6; 239 216 header->grh.payload_length = 240 217 cpu_to_be16((IB_BTH_BYTES + ··· 245 222 header->grh.next_header = 0x1b; 246 223 } 247 224 248 - header->lrh.packet_length = cpu_to_be16(packet_length); 249 - 250 - header->immediate_present = immediate_present; 251 225 if (immediate_present) 252 226 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE; 253 227 else 254 228 header->bth.opcode = IB_OPCODE_UD_SEND_ONLY; 255 229 header->bth.pad_count = (4 - payload_bytes) & 3; 256 230 header->bth.transport_header_version = 0; 231 + 232 + header->lrh_present = lrh_present; 233 + header->eth_present = eth_present; 234 + header->grh_present = grh_present; 235 + header->immediate_present = immediate_present; 257 236 } 258 237 EXPORT_SYMBOL(ib_ud_header_init); 238 + 239 + /** 240 + * ib_lrh_header_pack - Pack LRH header struct into wire format 241 + * @lrh:unpacked LRH header struct 242 + * @buf:Buffer to pack into 243 + * 244 + * ib_lrh_header_pack() packs the LRH header structure @lrh into 245 + * wire format in the buffer @buf. 246 + */ 247 + int ib_lrh_header_pack(struct ib_unpacked_lrh *lrh, void *buf) 248 + { 249 + ib_pack(lrh_table, ARRAY_SIZE(lrh_table), lrh, buf); 250 + return 0; 251 + } 252 + EXPORT_SYMBOL(ib_lrh_header_pack); 253 + 254 + /** 255 + * ib_lrh_header_unpack - Unpack LRH structure from wire format 256 + * @lrh:unpacked LRH header struct 257 + * @buf:Buffer to pack into 258 + * 259 + * ib_lrh_header_unpack() unpacks the LRH header structure from 260 + * wire format (in buf) into @lrh. 261 + */ 262 + int ib_lrh_header_unpack(void *buf, struct ib_unpacked_lrh *lrh) 263 + { 264 + ib_unpack(lrh_table, ARRAY_SIZE(lrh_table), buf, lrh); 265 + return 0; 266 + } 267 + EXPORT_SYMBOL(ib_lrh_header_unpack); 259 268 260 269 /** 261 270 * ib_ud_header_pack - Pack UD header struct into wire format ··· 302 247 { 303 248 int len = 0; 304 249 305 - ib_pack(lrh_table, ARRAY_SIZE(lrh_table), 306 - &header->lrh, buf); 307 - len += IB_LRH_BYTES; 308 - 250 + if (header->lrh_present) { 251 + ib_pack(lrh_table, ARRAY_SIZE(lrh_table), 252 + &header->lrh, buf + len); 253 + len += IB_LRH_BYTES; 254 + } 255 + if (header->eth_present) { 256 + ib_pack(eth_table, ARRAY_SIZE(eth_table), 257 + &header->eth, buf + len); 258 + len += IB_ETH_BYTES; 259 + } 309 260 if (header->grh_present) { 310 261 ib_pack(grh_table, ARRAY_SIZE(grh_table), 311 262 &header->grh, buf + len);
+1 -1
drivers/infiniband/hw/mlx4/qp.c
··· 1231 1231 for (i = 0; i < wr->num_sge; ++i) 1232 1232 send_size += wr->sg_list[i].length; 1233 1233 1234 - ib_ud_header_init(send_size, mlx4_ib_ah_grh_present(ah), 0, &sqp->ud_header); 1234 + ib_ud_header_init(send_size, 1, 0, mlx4_ib_ah_grh_present(ah), 0, &sqp->ud_header); 1235 1235 1236 1236 sqp->ud_header.lrh.service_level = 1237 1237 be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 28;
+1 -1
drivers/infiniband/hw/mthca/mthca_qp.c
··· 1493 1493 int err; 1494 1494 u16 pkey; 1495 1495 1496 - ib_ud_header_init(256, /* assume a MAD */ 1496 + ib_ud_header_init(256, /* assume a MAD */ 1, 0, 1497 1497 mthca_ah_grh_present(to_mah(wr->wr.ud.ah)), 0, 1498 1498 &sqp->ud_header); 1499 1499
+22 -8
include/rdma/ib_pack.h
··· 37 37 38 38 enum { 39 39 IB_LRH_BYTES = 8, 40 + IB_ETH_BYTES = 14, 40 41 IB_GRH_BYTES = 40, 41 42 IB_BTH_BYTES = 12, 42 43 IB_DETH_BYTES = 8 ··· 211 210 __be32 source_qpn; 212 211 }; 213 212 213 + struct ib_unpacked_eth { 214 + u8 dmac_h[4]; 215 + u8 dmac_l[2]; 216 + u8 smac_h[2]; 217 + u8 smac_l[4]; 218 + __be16 type; 219 + }; 220 + 214 221 struct ib_ud_header { 222 + int lrh_present; 215 223 struct ib_unpacked_lrh lrh; 216 - int grh_present; 217 - struct ib_unpacked_grh grh; 218 - struct ib_unpacked_bth bth; 224 + int eth_present; 225 + struct ib_unpacked_eth eth; 226 + int grh_present; 227 + struct ib_unpacked_grh grh; 228 + struct ib_unpacked_bth bth; 219 229 struct ib_unpacked_deth deth; 220 - int immediate_present; 221 - __be32 immediate_data; 230 + int immediate_present; 231 + __be32 immediate_data; 222 232 }; 223 233 224 234 void ib_pack(const struct ib_field *desc, ··· 242 230 void *buf, 243 231 void *structure); 244 232 245 - void ib_ud_header_init(int payload_bytes, 246 - int grh_present, 247 - int immediate_present, 233 + void ib_ud_header_init(int payload_bytes, 234 + int lrh_present, 235 + int eth_present, 236 + int grh_present, 237 + int immediate_present, 248 238 struct ib_ud_header *header); 249 239 250 240 int ib_ud_header_pack(struct ib_ud_header *header,