[golan] Add Connect-IB, ConnectX-4 and ConnectX-4 Lx (Infiniband) support
[ipxe.git] / src / drivers / infiniband / flexboot_nodnic.h
1 #ifndef SRC_DRIVERS_INFINIBAND_FLEXBOOT_NODNIC_FLEXBOOT_NODNIC_H_
2 #define SRC_DRIVERS_INFINIBAND_FLEXBOOT_NODNIC_FLEXBOOT_NODNIC_H_
3
4 /*
5 * Copyright (C) 2015 Mellanox Technologies Ltd.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301, USA.
21 */
22
23 FILE_LICENCE ( GPL2_OR_LATER );
24
25 #include "mlx_nodnic/include/mlx_nodnic_data_structures.h"
26 #include "nodnic_prm.h"
27 #include <ipxe/io.h>
28 #include <ipxe/infiniband.h>
29 #include <ipxe/netdevice.h>
30
31 /*
32 * If defined, use interrupts in NODNIC driver
33 */
34 #define NODNIC_IRQ_ENABLED
35
36 #define FLEXBOOT_NODNIC_MAX_PORTS 2
37 #define FLEXBOOT_NODNIC_PORT_BASE 1
38
39 #define FLEXBOOT_NODNIC_OPCODE_SEND 0xa
40
41 /* Port protocol */
42 enum flexboot_nodnic_protocol {
43 FLEXBOOT_NODNIC_PROT_IB_IPV6 = 0,
44 FLEXBOOT_NODNIC_PROT_ETH,
45 FLEXBOOT_NODNIC_PROT_IB_IPV4,
46 FLEXBOOT_NODNIC_PROT_FCOE
47 };
48
49 /** A flexboot nodnic port */
50 struct flexboot_nodnic_port {
51 /** Infiniband device */
52 struct ib_device *ibdev;
53 /** Network device */
54 struct net_device *netdev;
55 /** nodic port */
56 nodnic_port_priv port_priv;
57 /** Port type */
58 struct flexboot_nodnic_port_type *type;
59 /** Ethernet completion queue */
60 struct ib_completion_queue *eth_cq;
61 /** Ethernet queue pair */
62 struct ib_queue_pair *eth_qp;
63 };
64
65
66 /** A flexboot nodnic queue pair */
67 struct flexboot_nodnic_queue_pair {
68 nodnic_qp *nodnic_queue_pair;
69 };
70
71 /** A flexboot nodnic cq */
72 struct flexboot_nodnic_completion_queue {
73 nodnic_cq *nodnic_completion_queue;
74 };
75
76 /** A flexboot_nodnic device */
77 struct flexboot_nodnic {
78 /** PCI device */
79 struct pci_device *pci;
80 /** nic specific data*/
81 struct flexboot_nodnic_callbacks *callbacks;
82 /**nodnic device*/
83 nodnic_device_priv device_priv;
84 /**flexboot_nodnic ports*/
85 struct flexboot_nodnic_port port[FLEXBOOT_NODNIC_MAX_PORTS];
86 /** Device open request counter */
87 unsigned int open_count;
88 /** Port masking */
89 u16 port_mask;
90 /** device private data */
91 void *priv_data;
92 };
93
94 /** A flexboot_nodnic port type */
95 struct flexboot_nodnic_port_type {
96 /** Register port
97 *
98 * @v flexboot_nodnic flexboot_nodnic device
99 * @v port flexboot_nodnic port
100 * @ret mlx_status Return status code
101 */
102 mlx_status ( * register_dev ) (
103 struct flexboot_nodnic *flexboot_nodnic,
104 struct flexboot_nodnic_port *port
105 );
106 /** Port state changed
107 *
108 * @v flexboot_nodnic flexboot_nodnic device
109 * @v port flexboot_nodnic port
110 * @v link_up Link is up
111 */
112 void ( * state_change ) (
113 struct flexboot_nodnic *flexboot_nodnic,
114 struct flexboot_nodnic_port *port,
115 int link_up
116 );
117 /** Unregister port
118 *
119 * @v flexboot_nodnic flexboot_nodnic device
120 * @v port flexboot_nodnic port
121 */
122 void ( * unregister_dev ) (
123 struct flexboot_nodnic *flexboot_nodnic,
124 struct flexboot_nodnic_port *port
125 );
126 };
127
128 struct cqe_data{
129 mlx_boolean owner;
130 mlx_uint32 qpn;
131 mlx_uint32 is_send;
132 mlx_uint32 is_error;
133 mlx_uint32 syndrome;
134 mlx_uint32 vendor_err_syndrome;
135 mlx_uint32 wqe_counter;
136 mlx_uint32 byte_cnt;
137 };
138
139 struct flexboot_nodnic_callbacks {
140 mlx_status ( * fill_completion ) ( void *cqe, struct cqe_data *cqe_data );
141 mlx_status ( * cqe_set_owner ) ( void *cq, unsigned int num_cqes );
142 mlx_size ( * get_cqe_size ) ();
143 mlx_status ( * fill_send_wqe[5] ) (
144 struct ib_device *ibdev,
145 struct ib_queue_pair *qp,
146 struct ib_address_vector *av,
147 struct io_buffer *iobuf,
148 struct nodnic_send_wqbb *wqbb,
149 unsigned long wqe_idx
150 );
151 void ( * irq ) ( struct net_device *netdev, int enable );
152 };
153
154 int flexboot_nodnic_probe ( struct pci_device *pci,
155 struct flexboot_nodnic_callbacks *callbacks,
156 void *drv_priv );
157 void flexboot_nodnic_remove ( struct pci_device *pci );
158 void flexboot_nodnic_eth_irq ( struct net_device *netdev, int enable );
159 int flexboot_nodnic_is_supported ( struct pci_device *pci );
160 void flexboot_nodnic_copy_mac ( uint8_t mac_addr[], uint32_t low_byte,
161 uint16_t high_byte );
162
163 #endif /* SRC_DRIVERS_INFINIBAND_FLEXBOOT_NODNIC_FLEXBOOT_NODNIC_H_ */