1 #ifndef _IPXE_EOIB_H
2 #define _IPXE_EOIB_H
3 
4 /** @file
5  *
6  * Ethernet over Infiniband
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 
12 #include <stdint.h>
13 #include <byteswap.h>
14 #include <ipxe/netdevice.h>
15 #include <ipxe/infiniband.h>
16 #include <ipxe/ib_mcast.h>
17 
18 /** An EoIB header */
19 struct eoib_header {
20 	/** Signature */
21 	uint16_t magic;
22 	/** Reserved */
23 	uint16_t reserved;
24 } __attribute__ (( packed ));
25 
26 /** EoIB magic signature */
27 #define EOIB_MAGIC 0x8919
28 
29 /** An EoIB device */
30 struct eoib_device {
31 	/** Name */
32 	const char *name;
33 	/** Network device */
34 	struct net_device *netdev;
35 	/** Underlying Infiniband device */
36 	struct ib_device *ibdev;
37 	/** List of EoIB devices */
38 	struct list_head list;
39 	/** Broadcast address */
40 	struct ib_address_vector broadcast;
41 
42 	/** Completion queue */
43 	struct ib_completion_queue *cq;
44 	/** Queue pair */
45 	struct ib_queue_pair *qp;
46 	/** Broadcast group membership */
47 	struct ib_mc_membership membership;
48 
49 	/** Peer cache */
50 	struct list_head peers;
51 
52 	/** Send duplicate packet to gateway (or NULL)
53 	 *
54 	 * @v eoib		EoIB device
55 	 * @v original		Original I/O buffer
56 	 */
57 	void ( * duplicate ) ( struct eoib_device *eoib,
58 			       struct io_buffer *original );
59 	/** Gateway (if any) */
60 	struct ib_address_vector gateway;
61 	/** Multicast group additional component mask */
62 	unsigned int mask;
63 };
64 
65 /**
66  * Check if EoIB device uses a gateway
67  *
68  * @v eoib		EoIB device
69  * @v has_gw		EoIB device uses a gateway
70  */
eoib_has_gateway(struct eoib_device * eoib)71 static inline int eoib_has_gateway ( struct eoib_device *eoib ) {
72 
73 	return ( eoib->duplicate != NULL );
74 }
75 
76 /**
77  * Force creation of multicast group
78  *
79  * @v eoib		EoIB device
80  */
eoib_force_group_creation(struct eoib_device * eoib)81 static inline void eoib_force_group_creation ( struct eoib_device *eoib ) {
82 
83 	/* Some dubious EoIB implementations require each endpoint to
84 	 * force the creation of the multicast group.  Yes, this makes
85 	 * it impossible for the group parameters (e.g. SL) to ever be
86 	 * modified without breaking backwards compatiblity with every
87 	 * existing driver.
88 	 */
89 	eoib->mask = ( IB_SA_MCMEMBER_REC_PKEY | IB_SA_MCMEMBER_REC_QKEY |
90 		       IB_SA_MCMEMBER_REC_SL | IB_SA_MCMEMBER_REC_FLOW_LABEL |
91 		       IB_SA_MCMEMBER_REC_TRAFFIC_CLASS );
92 }
93 
94 extern int eoib_create ( struct ib_device *ibdev, const uint8_t *hw_addr,
95 			 struct ib_address_vector *broadcast,
96 			 const char *name );
97 extern struct eoib_device * eoib_find ( struct ib_device *ibdev,
98 					const uint8_t *hw_addr );
99 extern void eoib_destroy ( struct eoib_device *eoib );
100 extern void eoib_set_gateway ( struct eoib_device *eoib,
101 			       struct ib_address_vector *av );
102 
103 #endif /* _IPXE_EOIB_H */
104