Procházet zdrojové kódy

[hermon] Add support for dual-protocol devices

Originally-implemented-by: Itay Gazit <itaygazit@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown před 14 roky
rodič
revize
5a981cff8e

+ 651
- 79
src/drivers/infiniband/hermon.c Zobrazit soubor

@@ -36,6 +36,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
36 36
 #include <ipxe/netdevice.h>
37 37
 #include <ipxe/infiniband.h>
38 38
 #include <ipxe/ib_smc.h>
39
+#include <ipxe/if_ether.h>
40
+#include <ipxe/ethernet.h>
39 41
 #include "hermon.h"
40 42
 
41 43
 /**
@@ -304,12 +306,13 @@ hermon_cmd_close_port ( struct hermon *hermon, unsigned int port ) {
304 306
 }
305 307
 
306 308
 static inline int
307
-hermon_cmd_set_port ( struct hermon *hermon, unsigned int port,
308
-		      union hermonprm_set_port *set_port ) {
309
+hermon_cmd_set_port ( struct hermon *hermon, int is_ethernet,
310
+		      unsigned int port_selector,
311
+		      const union hermonprm_set_port *set_port ) {
309 312
 	return hermon_cmd ( hermon,
310 313
 			    HERMON_HCR_IN_CMD ( HERMON_HCR_SET_PORT,
311 314
 						1, sizeof ( *set_port ) ),
312
-			    0, set_port, port, NULL );
315
+			    is_ethernet, set_port, port_selector, NULL );
313 316
 }
314 317
 
315 318
 static inline int
@@ -491,6 +494,24 @@ hermon_cmd_mgid_hash ( struct hermon *hermon, const union ib_gid *gid,
491 494
 			    0, gid, 0, hash );
492 495
 }
493 496
 
497
+static inline int
498
+hermon_cmd_query_port ( struct hermon *hermon, unsigned int port,
499
+			struct hermonprm_query_port_cap *query_port ) {
500
+	return hermon_cmd ( hermon,
501
+			    HERMON_HCR_OUT_CMD ( HERMON_HCR_QUERY_PORT,
502
+						 1, sizeof ( *query_port ) ),
503
+			    0, NULL, port, query_port );
504
+}
505
+
506
+static inline int
507
+hermon_cmd_sense_port ( struct hermon *hermon, unsigned int port,
508
+			struct hermonprm_sense_port *port_type ) {
509
+	return hermon_cmd ( hermon,
510
+                            HERMON_HCR_OUT_CMD ( HERMON_HCR_SENSE_PORT,
511
+                                                 1, sizeof ( *port_type ) ),
512
+                            0, NULL, port, port_type );
513
+}
514
+
494 515
 static inline int
495 516
 hermon_cmd_run_fw ( struct hermon *hermon ) {
496 517
 	return hermon_cmd ( hermon,
@@ -559,16 +580,6 @@ hermon_cmd_map_fa ( struct hermon *hermon,
559 580
 			    0, map, 1, NULL );
560 581
 }
561 582
 
562
-static inline int
563
-hermon_cmd_sense_port ( struct hermon *hermon, unsigned int port,
564
-			struct hermonprm_sense_port *port_type ) {
565
-	return hermon_cmd ( hermon,
566
-                            HERMON_HCR_OUT_CMD ( HERMON_HCR_SENSE_PORT,
567
-                                                 1, sizeof ( *port_type ) ),
568
-                            0, NULL, port, port_type );
569
-}
570
-
571
-
572 583
 /***************************************************************************
573 584
  *
574 585
  * Memory translation table operations
@@ -916,6 +927,7 @@ static int hermon_alloc_qpn ( struct ib_device *ibdev,
916 927
 		return 0;
917 928
 	case IB_QPT_UD:
918 929
 	case IB_QPT_RC:
930
+	case IB_QPT_ETH:
919 931
 		/* Find a free queue pair number */
920 932
 		qpn_offset = hermon_bitmask_alloc ( hermon->qp_inuse,
921 933
 						    HERMON_MAX_QPS, 1 );
@@ -982,6 +994,7 @@ static uint8_t hermon_qp_st[] = {
982 994
 	[IB_QPT_GSI] = HERMON_ST_MLX,
983 995
 	[IB_QPT_UD] = HERMON_ST_UD,
984 996
 	[IB_QPT_RC] = HERMON_ST_RC,
997
+	[IB_QPT_ETH] = HERMON_ST_MLX,
985 998
 };
986 999
 
987 1000
 /**
@@ -1163,7 +1176,9 @@ static int hermon_modify_qp ( struct ib_device *ibdev,
1163 1176
 	if ( hermon_qp->state < HERMON_QP_ST_RTR ) {
1164 1177
 		memset ( &qpctx, 0, sizeof ( qpctx ) );
1165 1178
 		MLX_FILL_2 ( &qpctx, 4,
1166
-			     qpc_eec_data.mtu, HERMON_MTU_2048,
1179
+			     qpc_eec_data.mtu,
1180
+			     ( ( qp->type == IB_QPT_ETH ) ?
1181
+			       HERMON_MTU_ETH : HERMON_MTU_2048 ),
1167 1182
 			     qpc_eec_data.msg_max, 31 );
1168 1183
 		MLX_FILL_1 ( &qpctx, 7,
1169 1184
 			     qpc_eec_data.remote_qpn_een, qp->av.qpn );
@@ -1402,6 +1417,38 @@ hermon_fill_rc_send_wqe ( struct ib_device *ibdev,
1402 1417
 	return HERMON_OPCODE_SEND;
1403 1418
 }
1404 1419
 
1420
+/**
1421
+ * Construct Ethernet send work queue entry
1422
+ *
1423
+ * @v ibdev		Infiniband device
1424
+ * @v qp		Queue pair
1425
+ * @v av		Address vector
1426
+ * @v iobuf		I/O buffer
1427
+ * @v wqe		Send work queue entry
1428
+ * @ret opcode		Control opcode
1429
+ */
1430
+static unsigned int
1431
+hermon_fill_eth_send_wqe ( struct ib_device *ibdev,
1432
+			   struct ib_queue_pair *qp __unused,
1433
+			   struct ib_address_vector *av __unused,
1434
+			   struct io_buffer *iobuf,
1435
+			   union hermon_send_wqe *wqe ) {
1436
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1437
+
1438
+	/* Fill work queue entry */
1439
+	MLX_FILL_1 ( &wqe->eth.ctrl, 1, ds,
1440
+		     ( ( offsetof ( typeof ( wqe->mlx ), data[1] ) / 16 ) ) );
1441
+	MLX_FILL_2 ( &wqe->eth.ctrl, 2,
1442
+		     c, 0x03 /* generate completion */,
1443
+		     s, 1 /* inhibit ICRC */ );
1444
+	MLX_FILL_1 ( &wqe->eth.data[0], 0,
1445
+		     byte_count, iob_len ( iobuf ) );
1446
+	MLX_FILL_1 ( &wqe->eth.data[0], 1, l_key, hermon->lkey );
1447
+	MLX_FILL_1 ( &wqe->eth.data[0], 3,
1448
+		     local_address_l, virt_to_bus ( iobuf->data ) );
1449
+	return HERMON_OPCODE_SEND;
1450
+}
1451
+
1405 1452
 /** Work queue entry constructors */
1406 1453
 static unsigned int
1407 1454
 ( * hermon_fill_send_wqe[] ) ( struct ib_device *ibdev,
@@ -1413,6 +1460,7 @@ static unsigned int
1413 1460
 	[IB_QPT_GSI] = hermon_fill_mlx_send_wqe,
1414 1461
 	[IB_QPT_UD] = hermon_fill_ud_send_wqe,
1415 1462
 	[IB_QPT_RC] = hermon_fill_rc_send_wqe,
1463
+	[IB_QPT_ETH] = hermon_fill_eth_send_wqe,
1416 1464
 };
1417 1465
 
1418 1466
 /**
@@ -1618,6 +1666,9 @@ static int hermon_complete ( struct ib_device *ibdev,
1618 1666
 		case IB_QPT_RC:
1619 1667
 			av = &qp->av;
1620 1668
 			break;
1669
+		case IB_QPT_ETH:
1670
+			av = NULL;
1671
+			break;
1621 1672
 		default:
1622 1673
 			assert ( 0 );
1623 1674
 			return -EINVAL;
@@ -1826,8 +1877,9 @@ static void hermon_event_port_state_change ( struct hermon *hermon,
1826 1877
 		return;
1827 1878
 	}
1828 1879
 
1829
-	/* Update MAD parameters */
1830
-	ib_smc_update ( hermon->ibdev[port], hermon_mad );
1880
+	/* Notify device of port state change */
1881
+	hermon->port[port].type->state_change ( hermon, &hermon->port[port],
1882
+						link_up );
1831 1883
 }
1832 1884
 
1833 1885
 /**
@@ -1898,39 +1950,6 @@ static void hermon_poll_eq ( struct ib_device *ibdev ) {
1898 1950
  ***************************************************************************
1899 1951
  */
1900 1952
 
1901
-/**
1902
- * Sense port type
1903
- *
1904
- * @v ibdev		Infiniband device
1905
- * @ret port_type	Port type, or negative error
1906
- */
1907
-static int hermon_sense_port_type ( struct ib_device *ibdev ) {
1908
-	struct hermon *hermon = ib_get_drvdata ( ibdev );
1909
-	struct hermonprm_sense_port sense_port;
1910
-	int port_type;
1911
-	int rc;
1912
-
1913
-	/* If DPDP is not supported, always assume Infiniband */
1914
-	if ( ! hermon->cap.dpdp ) {
1915
-		DBGC ( hermon, "Hermon %p does not support DPDP; assuming "
1916
-		       "Infiniband\n", hermon );
1917
-		return HERMON_PORT_TYPE_IB;
1918
-	}
1919
-
1920
-	/* Sense the port type */
1921
-	if ( ( rc = hermon_cmd_sense_port ( hermon, ibdev->port,
1922
-					    &sense_port ) ) != 0 ) {
1923
-		DBGC ( hermon, "Hermon %p port %d sense failed: %s\n",
1924
-		       hermon, ibdev->port, strerror ( rc ) );
1925
-		return rc;
1926
-	}
1927
-	port_type = MLX_GET ( &sense_port, port_type );
1928
-
1929
-	DBGC ( hermon, "Hermon %p port %d type %d\n",
1930
-	       hermon, ibdev->port, port_type );
1931
-	return port_type;
1932
-}
1933
-
1934 1953
 /**
1935 1954
  * Initialise Infiniband link
1936 1955
  *
@@ -1940,18 +1959,8 @@ static int hermon_sense_port_type ( struct ib_device *ibdev ) {
1940 1959
 static int hermon_open ( struct ib_device *ibdev ) {
1941 1960
 	struct hermon *hermon = ib_get_drvdata ( ibdev );
1942 1961
 	union hermonprm_set_port set_port;
1943
-	int port_type;
1944 1962
 	int rc;
1945 1963
 
1946
-	/* Check we are connected to an Infiniband network */
1947
-	if ( ( rc = port_type = hermon_sense_port_type ( ibdev ) ) < 0 )
1948
-		return rc;
1949
-	if ( port_type != HERMON_PORT_TYPE_IB ) {
1950
-		DBGC ( hermon, "Hermon %p port %d not connected to an "
1951
-		       "Infiniband network", hermon, ibdev->port );
1952
-		return -ENOTCONN;
1953
-        }
1954
-
1955 1964
 	/* Set port parameters */
1956 1965
 	memset ( &set_port, 0, sizeof ( set_port ) );
1957 1966
 	MLX_FILL_7 ( &set_port.ib, 0,
@@ -1965,7 +1974,7 @@ static int hermon_open ( struct ib_device *ibdev ) {
1965 1974
 	MLX_FILL_2 ( &set_port.ib, 10,
1966 1975
 		     max_pkey, 1,
1967 1976
 		     max_gid, 1 );
1968
-	if ( ( rc = hermon_cmd_set_port ( hermon, ibdev->port,
1977
+	if ( ( rc = hermon_cmd_set_port ( hermon, 0, ibdev->port,
1969 1978
 					  &set_port ) ) != 0 ) {
1970 1979
 		DBGC ( hermon, "Hermon %p port %d could not set port: %s\n",
1971 1980
 		       hermon, ibdev->port, strerror ( rc ) );
@@ -2136,6 +2145,530 @@ static struct ib_device_operations hermon_ib_operations = {
2136 2145
 	.set_pkey_table	= hermon_inform_sma,
2137 2146
 };
2138 2147
 
2148
+/**
2149
+ * Register Hermon Infiniband device
2150
+ *
2151
+ * @v hermon		Hermon device
2152
+ * @v port		Hermon port
2153
+ * @ret rc		Return status code
2154
+ */
2155
+static int hermon_register_ibdev ( struct hermon *hermon,
2156
+				   struct hermon_port *port ) {
2157
+	struct ib_device *ibdev = port->ibdev;
2158
+	int rc;
2159
+
2160
+	/* Initialise parameters using SMC */
2161
+	ib_smc_init ( ibdev, hermon_mad );
2162
+
2163
+	/* Register Infiniband device */
2164
+	if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
2165
+		DBGC ( hermon, "Hermon %p port %d could not register IB "
2166
+		       "device: %s\n", hermon, ibdev->port, strerror ( rc ) );
2167
+		return rc;
2168
+	}
2169
+
2170
+	return 0;
2171
+}
2172
+
2173
+/**
2174
+ * Handle Hermon Infiniband device port state change
2175
+ *
2176
+ * @v hermon		Hermon device
2177
+ * @v port		Hermon port
2178
+ * @v link_up		Link is up
2179
+ */
2180
+static void hermon_state_change_ibdev ( struct hermon *hermon __unused,
2181
+					struct hermon_port *port,
2182
+					int link_up __unused ) {
2183
+	struct ib_device *ibdev = port->ibdev;
2184
+
2185
+	/* Update MAD parameters */
2186
+	ib_smc_update ( ibdev, hermon_mad );
2187
+}
2188
+
2189
+/**
2190
+ * Unregister Hermon Infiniband device
2191
+ *
2192
+ * @v hermon		Hermon device
2193
+ * @v port		Hermon port
2194
+ */
2195
+static void hermon_unregister_ibdev ( struct hermon *hermon __unused,
2196
+				      struct hermon_port *port ) {
2197
+	struct ib_device *ibdev = port->ibdev;
2198
+
2199
+	unregister_ibdev ( ibdev );
2200
+}
2201
+
2202
+/** Hermon Infiniband port type */
2203
+static struct hermon_port_type hermon_port_type_ib = {
2204
+	.register_dev = hermon_register_ibdev,
2205
+	.state_change = hermon_state_change_ibdev,
2206
+	.unregister_dev = hermon_unregister_ibdev,
2207
+};
2208
+
2209
+/***************************************************************************
2210
+ *
2211
+ * Ethernet operation
2212
+ *
2213
+ ***************************************************************************
2214
+ */
2215
+
2216
+/** Number of Hermon Ethernet send work queue entries */
2217
+#define HERMON_ETH_NUM_SEND_WQES 2
2218
+
2219
+/** Number of Hermon Ethernet receive work queue entries */
2220
+#define HERMON_ETH_NUM_RECV_WQES 4
2221
+
2222
+/** Number of Hermon Ethernet completion entries */
2223
+#define HERMON_ETH_NUM_CQES 8
2224
+
2225
+/**
2226
+ * Transmit packet via Hermon Ethernet device
2227
+ *
2228
+ * @v netdev		Network device
2229
+ * @v iobuf		I/O buffer
2230
+ * @ret rc		Return status code
2231
+ */
2232
+static int hermon_eth_transmit ( struct net_device *netdev,
2233
+				 struct io_buffer *iobuf ) {
2234
+	struct hermon_port *port = netdev->priv;
2235
+	struct ib_device *ibdev = port->ibdev;
2236
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
2237
+	int rc;
2238
+
2239
+	/* Transmit packet */
2240
+	if ( ( rc = ib_post_send ( ibdev, port->eth_qp, NULL,
2241
+				   iobuf ) ) != 0 ) {
2242
+		DBGC ( hermon, "Hermon %p port %d could not transmit: %s\n",
2243
+		       hermon, ibdev->port, strerror ( rc ) );
2244
+		return rc;
2245
+	}
2246
+
2247
+	return 0;
2248
+}
2249
+
2250
+/**
2251
+ * Handle Hermon Ethernet device send completion
2252
+ *
2253
+ * @v ibdev		Infiniband device
2254
+ * @v qp		Queue pair
2255
+ * @v iobuf		I/O buffer
2256
+ * @v rc		Completion status code
2257
+ */
2258
+static void hermon_eth_complete_send ( struct ib_device *ibdev __unused,
2259
+				       struct ib_queue_pair *qp,
2260
+				       struct io_buffer *iobuf, int rc ) {
2261
+	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
2262
+
2263
+	netdev_tx_complete_err ( netdev, iobuf, rc );
2264
+}
2265
+
2266
+/**
2267
+ * Handle Hermon Ethernet device receive completion
2268
+ *
2269
+ * @v ibdev		Infiniband device
2270
+ * @v qp		Queue pair
2271
+ * @v av		Address vector, or NULL
2272
+ * @v iobuf		I/O buffer
2273
+ * @v rc		Completion status code
2274
+ */
2275
+static void hermon_eth_complete_recv ( struct ib_device *ibdev __unused,
2276
+				       struct ib_queue_pair *qp,
2277
+				       struct ib_address_vector *av __unused,
2278
+				       struct io_buffer *iobuf, int rc ) {
2279
+	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
2280
+
2281
+	/* Hand off to network layer */
2282
+	if ( rc == 0 ) {
2283
+		netdev_rx ( netdev, iobuf );
2284
+	} else {
2285
+		netdev_rx_err ( netdev, iobuf, rc );
2286
+	}
2287
+}
2288
+
2289
+/** Hermon Ethernet device completion operations */
2290
+static struct ib_completion_queue_operations hermon_eth_cq_op = {
2291
+	.complete_send = hermon_eth_complete_send,
2292
+	.complete_recv = hermon_eth_complete_recv,
2293
+};
2294
+
2295
+/**
2296
+ * Poll Hermon Ethernet device
2297
+ *
2298
+ * @v netdev		Network device
2299
+ */
2300
+static void hermon_eth_poll ( struct net_device *netdev ) {
2301
+	struct hermon_port *port = netdev->priv;
2302
+	struct ib_device *ibdev = port->ibdev;
2303
+
2304
+	ib_poll_eq ( ibdev );
2305
+}
2306
+
2307
+/**
2308
+ * Enable/disable interrupts on Hermon Ethernet device
2309
+ *
2310
+ * @v netdev		Network device
2311
+ * @v enable		Interrupts should be enabled
2312
+ */
2313
+static void hermon_eth_irq ( struct net_device *netdev __unused,
2314
+			     int enable __unused ) {
2315
+	/* No implementation */
2316
+}
2317
+
2318
+/**
2319
+ * Open Hermon Ethernet device
2320
+ *
2321
+ * @v netdev		Network device
2322
+ * @ret rc		Return status code
2323
+ */
2324
+static int hermon_eth_open ( struct net_device *netdev ) {
2325
+	struct hermon_port *port = netdev->priv;
2326
+	struct ib_device *ibdev = port->ibdev;
2327
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
2328
+	union hermonprm_set_port set_port;
2329
+	int rc;
2330
+
2331
+	/* Allocate completion queue */
2332
+	port->eth_cq = ib_create_cq ( ibdev, HERMON_ETH_NUM_CQES,
2333
+				      &hermon_eth_cq_op );
2334
+	if ( ! port->eth_cq ) {
2335
+		DBGC ( hermon, "Hermon %p port %d could not create completion "
2336
+		       "queue\n", hermon, ibdev->port );
2337
+		rc = -ENOMEM;
2338
+		goto err_create_cq;
2339
+	}
2340
+
2341
+	/* Allocate queue pair */
2342
+	port->eth_qp = ib_create_qp ( ibdev, IB_QPT_ETH,
2343
+				      HERMON_ETH_NUM_SEND_WQES, port->eth_cq,
2344
+				      HERMON_ETH_NUM_RECV_WQES, port->eth_cq );
2345
+	if ( ! port->eth_qp ) {
2346
+		DBGC ( hermon, "Hermon %p port %d could not create queue "
2347
+		       "pair\n", hermon, ibdev->port );
2348
+		rc = -ENOMEM;
2349
+		goto err_create_qp;
2350
+	}
2351
+	ib_qp_set_ownerdata ( port->eth_qp, netdev );
2352
+
2353
+	/* Activate queue pair */
2354
+	if ( ( rc = ib_modify_qp ( ibdev, port->eth_qp ) ) != 0 ) {
2355
+		DBGC ( hermon, "Hermon %p port %d could not modify queue "
2356
+		       "pair: %s\n", hermon, ibdev->port, strerror ( rc ) );
2357
+		goto err_modify_qp;
2358
+	}
2359
+
2360
+	/* Fill receive rings */
2361
+	ib_refill_recv ( ibdev, port->eth_qp );
2362
+
2363
+	/* Set port general parameters */
2364
+	memset ( &set_port, 0, sizeof ( set_port ) );
2365
+	MLX_FILL_3 ( &set_port.general, 0,
2366
+		     v_mtu, 1,
2367
+		     v_pprx, 1,
2368
+		     v_pptx, 1 );
2369
+	MLX_FILL_1 ( &set_port.general, 1,
2370
+		     mtu, ( ETH_FRAME_LEN + 40 /* Used by card */ ) );
2371
+	MLX_FILL_1 ( &set_port.general, 2, pptx, 1 );
2372
+	MLX_FILL_1 ( &set_port.general, 3, pprx, 1 );
2373
+	if ( ( rc = hermon_cmd_set_port ( hermon, 1,
2374
+					  ( HERMON_SET_PORT_GENERAL_PARAM |
2375
+					    ibdev->port ),
2376
+					  &set_port ) ) != 0 ) {
2377
+		DBGC ( hermon, "Hermon %p port %d could not set port general "
2378
+		       "parameters: %s\n",
2379
+		       hermon, ibdev->port, strerror ( rc ) );
2380
+		goto err_set_port_general_params;
2381
+	}
2382
+
2383
+	/* Set port receive QP */
2384
+	memset ( &set_port, 0, sizeof ( set_port ) );
2385
+	MLX_FILL_1 ( &set_port.rqp_calc, 0, base_qpn, port->eth_qp->qpn );
2386
+	MLX_FILL_1 ( &set_port.rqp_calc, 2,
2387
+		     mac_miss_index, 128 /* MAC misses go to promisc QP */ );
2388
+	MLX_FILL_2 ( &set_port.rqp_calc, 3,
2389
+		     vlan_miss_index, 127 /* VLAN misses go to promisc QP */,
2390
+		     no_vlan_index, 126 /* VLAN-free go to promisc QP */ );
2391
+	MLX_FILL_2 ( &set_port.rqp_calc, 5,
2392
+		     promisc_qpn, port->eth_qp->qpn,
2393
+		     en_uc_promisc, 1 );
2394
+	MLX_FILL_2 ( &set_port.rqp_calc, 6,
2395
+		     def_mcast_qpn, port->eth_qp->qpn,
2396
+		     mc_promisc_mode, 2 /* Receive all multicasts */ );
2397
+	if ( ( rc = hermon_cmd_set_port ( hermon, 1,
2398
+					  ( HERMON_SET_PORT_RECEIVE_QP |
2399
+					    ibdev->port ),
2400
+					  &set_port ) ) != 0 ) {
2401
+		DBGC ( hermon, "Hermon %p port %d could not set port receive "
2402
+		       "QP: %s\n", hermon, ibdev->port, strerror ( rc ) );
2403
+		goto err_set_port_receive_qp;
2404
+	}
2405
+
2406
+	/* Initialise port */
2407
+	if ( ( rc = hermon_cmd_init_port ( hermon, ibdev->port ) ) != 0 ) {
2408
+		DBGC ( hermon, "Hermon %p port %d could not initialise port: "
2409
+		       "%s\n", hermon, ibdev->port, strerror ( rc ) );
2410
+		goto err_init_port;
2411
+	}
2412
+
2413
+	return 0;
2414
+
2415
+ err_init_port:
2416
+ err_set_port_receive_qp:
2417
+ err_set_port_general_params:
2418
+ err_modify_qp:
2419
+	ib_destroy_qp ( ibdev, port->eth_qp );
2420
+ err_create_qp:
2421
+	ib_destroy_cq ( ibdev, port->eth_cq );
2422
+ err_create_cq:
2423
+	return rc;
2424
+}
2425
+
2426
+/**
2427
+ * Close Hermon Ethernet device
2428
+ *
2429
+ * @v netdev		Network device
2430
+ */
2431
+static void hermon_eth_close ( struct net_device *netdev ) {
2432
+	struct hermon_port *port = netdev->priv;
2433
+	struct ib_device *ibdev = port->ibdev;
2434
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
2435
+	int rc;
2436
+
2437
+	/* Close port */
2438
+	if ( ( rc = hermon_cmd_close_port ( hermon, ibdev->port ) ) != 0 ) {
2439
+		DBGC ( hermon, "Hermon %p port %d could not close port: %s\n",
2440
+		       hermon, ibdev->port, strerror ( rc ) );
2441
+		/* Nothing we can do about this */
2442
+	}
2443
+
2444
+	/* Tear down the queues */
2445
+	ib_destroy_qp ( ibdev, port->eth_qp );
2446
+	ib_destroy_cq ( ibdev, port->eth_cq );
2447
+}
2448
+
2449
+/** Hermon Ethernet network device operations */
2450
+static struct net_device_operations hermon_eth_operations = {
2451
+	.open		= hermon_eth_open,
2452
+	.close		= hermon_eth_close,
2453
+	.transmit	= hermon_eth_transmit,
2454
+	.poll		= hermon_eth_poll,
2455
+	.irq		= hermon_eth_irq,
2456
+};
2457
+
2458
+/**
2459
+ * Register Hermon Ethernet device
2460
+ *
2461
+ * @v hermon		Hermon device
2462
+ * @v port		Hermon port
2463
+ * @ret rc		Return status code
2464
+ */
2465
+static int hermon_register_netdev ( struct hermon *hermon,
2466
+				    struct hermon_port *port ) {
2467
+	struct net_device *netdev = port->netdev;
2468
+	struct ib_device *ibdev = port->ibdev;
2469
+	struct hermonprm_query_port_cap query_port;
2470
+	union {
2471
+		uint8_t bytes[8];
2472
+		uint32_t dwords[2];
2473
+	} mac;
2474
+	int rc;
2475
+
2476
+	/* Retrieve MAC address */
2477
+	if ( ( rc = hermon_cmd_query_port ( hermon, ibdev->port,
2478
+					    &query_port ) ) != 0 ) {
2479
+		DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
2480
+		       hermon, ibdev->port, strerror ( rc ) );
2481
+		return rc;
2482
+	}
2483
+	mac.dwords[0] = htonl ( MLX_GET ( &query_port, mac_47_32 ) );
2484
+	mac.dwords[1] = htonl ( MLX_GET ( &query_port, mac_31_0 ) );
2485
+	memcpy ( netdev->hw_addr,
2486
+		 &mac.bytes[ sizeof ( mac.bytes ) - ETH_ALEN ], ETH_ALEN );
2487
+
2488
+	/* Register network device */
2489
+	if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
2490
+		DBGC ( hermon, "Hermon %p port %d could not register network "
2491
+		       "device: %s\n", hermon, ibdev->port, strerror ( rc ) );
2492
+		return rc;
2493
+	}
2494
+
2495
+	return 0;
2496
+}
2497
+
2498
+/**
2499
+ * Handle Hermon Ethernet device port state change
2500
+ *
2501
+ * @v hermon		Hermon device
2502
+ * @v port		Hermon port
2503
+ * @v link_up		Link is up
2504
+ */
2505
+static void hermon_state_change_netdev ( struct hermon *hermon __unused,
2506
+					 struct hermon_port *port,
2507
+					 int link_up ) {
2508
+	struct net_device *netdev = port->netdev;
2509
+
2510
+	if ( link_up ) {
2511
+		netdev_link_up ( netdev );
2512
+	} else {
2513
+		netdev_link_down ( netdev );
2514
+	}
2515
+}
2516
+
2517
+/**
2518
+ * Unregister Hermon Ethernet device
2519
+ *
2520
+ * @v hermon		Hermon device
2521
+ * @v port		Hermon port
2522
+ */
2523
+static void hermon_unregister_netdev ( struct hermon *hermon __unused,
2524
+				       struct hermon_port *port ) {
2525
+	struct net_device *netdev = port->netdev;
2526
+
2527
+	unregister_netdev ( netdev );
2528
+}
2529
+
2530
+/** Hermon Ethernet port type */
2531
+static struct hermon_port_type hermon_port_type_eth = {
2532
+	.register_dev = hermon_register_netdev,
2533
+	.state_change = hermon_state_change_netdev,
2534
+	.unregister_dev = hermon_unregister_netdev,
2535
+};
2536
+
2537
+/***************************************************************************
2538
+ *
2539
+ * Port type detection
2540
+ *
2541
+ ***************************************************************************
2542
+ */
2543
+
2544
+/** Timeout for port sensing */
2545
+#define HERMON_SENSE_PORT_TIMEOUT ( TICKS_PER_SEC / 2 )
2546
+
2547
+/**
2548
+ * Name port type
2549
+ *
2550
+ * @v port_type		Port type
2551
+ * @v port_type_name	Port type name
2552
+ */
2553
+static inline const char * hermon_name_port_type ( unsigned int port_type ) {
2554
+	switch ( port_type ) {
2555
+	case HERMON_PORT_TYPE_UNKNOWN:	return "unknown";
2556
+	case HERMON_PORT_TYPE_IB:	return "Infiniband";
2557
+	case HERMON_PORT_TYPE_ETH:	return "Ethernet";
2558
+	default:			return "INVALID";
2559
+	}
2560
+}
2561
+
2562
+/**
2563
+ * Sense port type
2564
+ *
2565
+ * @v hermon		Hermon device
2566
+ * @v port		Hermon port
2567
+ * @ret port_type	Port type, or negative error
2568
+ */
2569
+static int hermon_sense_port_type ( struct hermon *hermon,
2570
+				    struct hermon_port *port ) {
2571
+	struct ib_device *ibdev = port->ibdev;
2572
+	struct hermonprm_sense_port sense_port;
2573
+	int port_type;
2574
+	int rc;
2575
+
2576
+	/* If DPDP is not supported, always assume Infiniband */
2577
+	if ( ! hermon->cap.dpdp ) {
2578
+		port_type = HERMON_PORT_TYPE_IB;
2579
+		DBGC ( hermon, "Hermon %p port %d does not support DPDP; "
2580
+		       "assuming an %s network\n", hermon, ibdev->port,
2581
+		       hermon_name_port_type ( port_type ) );
2582
+		return port_type;
2583
+	}
2584
+
2585
+	/* Sense the port type */
2586
+	if ( ( rc = hermon_cmd_sense_port ( hermon, ibdev->port,
2587
+					    &sense_port ) ) != 0 ) {
2588
+		DBGC ( hermon, "Hermon %p port %d sense failed: %s\n",
2589
+		       hermon, ibdev->port, strerror ( rc ) );
2590
+		return rc;
2591
+	}
2592
+	port_type = MLX_GET ( &sense_port, port_type );
2593
+
2594
+	DBGC ( hermon, "Hermon %p port %d sensed an %s network\n",
2595
+	       hermon, ibdev->port, hermon_name_port_type ( port_type ) );
2596
+	return port_type;
2597
+}
2598
+
2599
+/**
2600
+ * Set port type
2601
+ *
2602
+ * @v hermon		Hermon device
2603
+ * @v port		Hermon port
2604
+ * @ret rc		Return status code
2605
+ */
2606
+static int hermon_set_port_type ( struct hermon *hermon,
2607
+				  struct hermon_port *port ) {
2608
+	struct ib_device *ibdev = port->ibdev;
2609
+	struct hermonprm_query_port_cap query_port;
2610
+	int ib_supported;
2611
+	int eth_supported;
2612
+	int port_type;
2613
+	unsigned long start;
2614
+	unsigned long elapsed;
2615
+	int rc;
2616
+
2617
+	/* Check to see which types are supported */
2618
+	if ( ( rc = hermon_cmd_query_port ( hermon, ibdev->port,
2619
+					    &query_port ) ) != 0 ) {
2620
+		DBGC ( hermon, "Hermon %p port %d could not query port: %s\n",
2621
+		       hermon, ibdev->port, strerror ( rc ) );
2622
+		return rc;
2623
+	}
2624
+	ib_supported = MLX_GET ( &query_port, ib );
2625
+	eth_supported = MLX_GET ( &query_port, eth );
2626
+	DBGC ( hermon, "Hermon %p port %d supports%s%s%s\n",
2627
+	       hermon, ibdev->port, ( ib_supported ? " Infiniband" : "" ),
2628
+	       ( ( ib_supported && eth_supported ) ? " and" : "" ),
2629
+	       ( eth_supported ? " Ethernet" : "" ) );
2630
+
2631
+	/* Sense network, if applicable */
2632
+	if ( ib_supported && eth_supported ) {
2633
+
2634
+		/* Both types are supported; try sensing network */
2635
+		start = currticks();
2636
+		do {
2637
+			/* Try sensing port */
2638
+			port_type = hermon_sense_port_type ( hermon, port );
2639
+			if ( port_type < 0 ) {
2640
+				rc = port_type;
2641
+				return rc;
2642
+			}
2643
+		} while ( ( port_type == HERMON_PORT_TYPE_UNKNOWN ) &&
2644
+			  ( ( elapsed = ( currticks() - start ) ) <
2645
+			    HERMON_SENSE_PORT_TIMEOUT ) );
2646
+
2647
+		/* Set port type based on sensed network, defaulting
2648
+		 * to Infiniband if nothing was sensed.
2649
+		 */
2650
+		switch ( port_type ) {
2651
+		case HERMON_PORT_TYPE_ETH:
2652
+			port->type = &hermon_port_type_eth;
2653
+			break;
2654
+		case HERMON_PORT_TYPE_IB:
2655
+		case HERMON_PORT_TYPE_UNKNOWN:
2656
+			port->type = &hermon_port_type_ib;
2657
+			break;
2658
+		default:
2659
+			return -EINVAL;
2660
+		}
2661
+
2662
+	} else if ( eth_supported ) {
2663
+		port->type = &hermon_port_type_eth;
2664
+	} else {
2665
+		port->type = &hermon_port_type_ib;
2666
+	}
2667
+
2668
+	assert ( port->type != NULL );
2669
+	return 0;
2670
+}
2671
+
2139 2672
 /***************************************************************************
2140 2673
  *
2141 2674
  * Firmware control
@@ -2789,6 +3322,8 @@ static int hermon_probe ( struct pci_device *pci,
2789 3322
 			  const struct pci_device_id *id __unused ) {
2790 3323
 	struct hermon *hermon;
2791 3324
 	struct ib_device *ibdev;
3325
+	struct net_device *netdev;
3326
+	struct hermon_port *port;
2792 3327
 	struct hermonprm_init_hca init_hca;
2793 3328
 	unsigned int i;
2794 3329
 	int rc;
@@ -2842,13 +3377,26 @@ static int hermon_probe ( struct pci_device *pci,
2842 3377
 			rc = -ENOMEM;
2843 3378
 			goto err_alloc_ibdev;
2844 3379
 		}
2845
-		hermon->ibdev[i] = ibdev;
3380
+		hermon->port[i].ibdev = ibdev;
2846 3381
 		ibdev->op = &hermon_ib_operations;
2847 3382
 		ibdev->dev = &pci->dev;
2848 3383
 		ibdev->port = ( HERMON_PORT_BASE + i );
2849 3384
 		ib_set_drvdata ( ibdev, hermon );
2850 3385
 	}
2851 3386
 
3387
+	/* Allocate network devices */
3388
+	for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3389
+		netdev = alloc_etherdev ( 0 );
3390
+		if ( ! netdev ) {
3391
+			rc = -ENOMEM;
3392
+			goto err_alloc_netdev;
3393
+		}
3394
+		hermon->port[i].netdev = netdev;
3395
+		netdev_init ( netdev, &hermon_eth_operations );
3396
+		netdev->dev = &pci->dev;
3397
+		netdev->priv = &hermon->port[i];
3398
+	}
3399
+
2852 3400
 	/* Allocate ICM */
2853 3401
 	memset ( &init_hca, 0, sizeof ( init_hca ) );
2854 3402
 	if ( ( rc = hermon_alloc_icm ( hermon, &init_hca ) ) != 0 )
@@ -2868,7 +3416,7 @@ static int hermon_probe ( struct pci_device *pci,
2868 3416
 	if ( ( rc = hermon_setup_mpt ( hermon ) ) != 0 )
2869 3417
 		goto err_setup_mpt;
2870 3418
 	for ( i = 0 ; i < hermon->cap.num_ports ; i++ )
2871
-		hermon->ibdev[i]->rdma_key = hermon->lkey;
3419
+		hermon->port[i].ibdev->rdma_key = hermon->lkey;
2872 3420
 
2873 3421
 	/* Set up event queue */
2874 3422
 	if ( ( rc = hermon_create_eq ( hermon ) ) != 0 )
@@ -2878,26 +3426,29 @@ static int hermon_probe ( struct pci_device *pci,
2878 3426
 	if ( ( rc = hermon_configure_special_qps ( hermon ) ) != 0 )
2879 3427
 		goto err_conf_special_qps;
2880 3428
 
2881
-	/* Initialise parameters using SMC */
2882
-	for ( i = 0 ; i < hermon->cap.num_ports ; i++ )
2883
-		ib_smc_init ( hermon->ibdev[i], hermon_mad );
3429
+	/* Determine port types */
3430
+	for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
3431
+		port = &hermon->port[i];
3432
+		if ( ( rc = hermon_set_port_type ( hermon, port ) ) != 0 )
3433
+			goto err_set_port_type;
3434
+	}
2884 3435
 
2885
-	/* Register Infiniband devices */
3436
+	/* Register devices */
2886 3437
 	for ( i = 0 ; i < hermon->cap.num_ports ; i++ ) {
2887
-		if ( ( rc = register_ibdev ( hermon->ibdev[i] ) ) != 0 ) {
2888
-			DBGC ( hermon, "Hermon %p port %d could not register "
2889
-			       "IB device: %s\n", hermon,
2890
-			       hermon->ibdev[i]->port, strerror ( rc ) );
2891
-			goto err_register_ibdev;
2892
-		}
3438
+		port = &hermon->port[i];
3439
+		if ( ( rc = port->type->register_dev ( hermon, port ) ) != 0 )
3440
+			goto err_register;
2893 3441
 	}
2894 3442
 
2895 3443
 	return 0;
2896 3444
 
2897 3445
 	i = hermon->cap.num_ports;
2898
- err_register_ibdev:
2899
-	for ( i-- ; ( signed int ) i >= 0 ; i-- )
2900
-		unregister_ibdev ( hermon->ibdev[i] );
3446
+ err_register:
3447
+	for ( i-- ; ( signed int ) i >= 0 ; i-- ) {
3448
+		port = &hermon->port[i];
3449
+		port->type->unregister_dev ( hermon, port );
3450
+	}
3451
+ err_set_port_type:
2901 3452
  err_conf_special_qps:
2902 3453
 	hermon_destroy_eq ( hermon );
2903 3454
  err_create_eq:
@@ -2907,9 +3458,15 @@ static int hermon_probe ( struct pci_device *pci,
2907 3458
 	hermon_free_icm ( hermon );
2908 3459
  err_alloc_icm:
2909 3460
 	i = hermon->cap.num_ports;
3461
+ err_alloc_netdev:
3462
+	for ( i-- ; ( signed int ) i >= 0 ; i-- ) {
3463
+		netdev_nullify ( hermon->port[i].netdev );
3464
+		netdev_put ( hermon->port[i].netdev );
3465
+	}
3466
+	i = hermon->cap.num_ports;
2910 3467
  err_alloc_ibdev:
2911 3468
 	for ( i-- ; ( signed int ) i >= 0 ; i-- )
2912
-		ibdev_put ( hermon->ibdev[i] );
3469
+		ibdev_put ( hermon->port[i].ibdev );
2913 3470
  err_get_cap:
2914 3471
 	hermon_stop_firmware ( hermon );
2915 3472
  err_start_firmware:
@@ -2929,10 +3486,13 @@ static int hermon_probe ( struct pci_device *pci,
2929 3486
  */
2930 3487
 static void hermon_remove ( struct pci_device *pci ) {
2931 3488
 	struct hermon *hermon = pci_get_drvdata ( pci );
3489
+	struct hermon_port *port;
2932 3490
 	int i;
2933 3491
 
2934
-	for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- )
2935
-		unregister_ibdev ( hermon->ibdev[i] );
3492
+	for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- ) {
3493
+		port = &hermon->port[i];
3494
+		port->type->unregister_dev ( hermon, port );
3495
+	}
2936 3496
 	hermon_destroy_eq ( hermon );
2937 3497
 	hermon_cmd_close_hca ( hermon );
2938 3498
 	hermon_free_icm ( hermon );
@@ -2940,8 +3500,12 @@ static void hermon_remove ( struct pci_device *pci ) {
2940 3500
 	hermon_stop_firmware ( hermon );
2941 3501
 	free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
2942 3502
 	free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
3503
+	for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- ) {
3504
+		netdev_nullify ( hermon->port[i].netdev );
3505
+		netdev_put ( hermon->port[i].netdev );
3506
+	}
2943 3507
 	for ( i = ( hermon->cap.num_ports - 1 ) ; i >= 0 ; i-- )
2944
-		ibdev_put ( hermon->ibdev[i] );
3508
+		ibdev_put ( hermon->port[i].ibdev );
2945 3509
 	free ( hermon );
2946 3510
 }
2947 3511
 
@@ -2950,6 +3514,14 @@ static struct pci_device_id hermon_nics[] = {
2950 3514
 	PCI_ROM ( 0x15b3, 0x634a, "mt25418", "MT25418 HCA driver", 0 ),
2951 3515
 	PCI_ROM ( 0x15b3, 0x6732, "mt26418", "MT26418 HCA driver", 0 ),
2952 3516
 	PCI_ROM ( 0x15b3, 0x673c, "mt26428", "MT26428 HCA driver", 0 ),
3517
+	PCI_ROM ( 0x15b3, 0x6746, "mt26438", "MT26438 HCA driver", 0 ),
3518
+	PCI_ROM ( 0x15b3, 0x6778, "mt26488", "MT26488 HCA driver", 0 ),
3519
+	PCI_ROM ( 0x15b3, 0x6368, "mt25448", "MT25448 HCA driver", 0 ),
3520
+	PCI_ROM ( 0x15b3, 0x6750, "mt26448", "MT26448 HCA driver", 0 ),
3521
+	PCI_ROM ( 0x15b3, 0x6372, "mt25458", "MT25458 HCA driver", 0 ),
3522
+	PCI_ROM ( 0x15b3, 0x675a, "mt26458", "MT26458 HCA driver", 0 ),
3523
+	PCI_ROM ( 0x15b3, 0x6764, "mt26468", "MT26468 HCA driver", 0 ),
3524
+	PCI_ROM ( 0x15b3, 0x676e, "mt26478", "MT26478 HCA driver", 0 ),
2953 3525
 };
2954 3526
 
2955 3527
 struct pci_driver hermon_driver __pci_driver = {

+ 61
- 2
src/drivers/infiniband/hermon.h Zobrazit soubor

@@ -94,6 +94,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
94 94
 
95 95
 /* MTUs */
96 96
 #define HERMON_MTU_2048			0x04
97
+#define HERMON_MTU_ETH			0x07
97 98
 
98 99
 #define HERMON_INVALID_LKEY		0x00000100UL
99 100
 
@@ -110,6 +111,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
110 111
 #define HERMON_MAP_EQ			( 0UL << 31 )
111 112
 #define HERMON_UNMAP_EQ			( 1UL << 31 )
112 113
 
114
+#define HERMON_SET_PORT_GENERAL_PARAM	0x0000
115
+#define HERMON_SET_PORT_RECEIVE_QP	0x0100
116
+#define HERMON_SET_PORT_MAC_TABLE	0x0200
117
+#define HERMON_SET_PORT_VLAN_TABLE	0x0300
118
+#define HERMON_SET_PORT_PRIORITY_TABLE	0x0400
119
+#define HERMON_SET_PORT_GID_TABLE	0x0500
120
+
113 121
 #define HERMON_EV_PORT_STATE_CHANGE	0x09
114 122
 
115 123
 #define HERMON_SCHED_QP0		0x3f
@@ -449,6 +457,11 @@ struct hermonprm_rc_send_wqe {
449 457
 	struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
450 458
 } __attribute__ (( packed ));
451 459
 
460
+struct hermonprm_eth_send_wqe {
461
+	struct hermonprm_wqe_segment_ctrl_send ctrl;
462
+	struct hermonprm_wqe_segment_data_ptr data[HERMON_MAX_GATHER];
463
+} __attribute__ (( packed ));
464
+
452 465
 #define HERMON_MAX_SCATTER 1
453 466
 
454 467
 struct hermonprm_recv_wqe {
@@ -584,6 +597,7 @@ union hermon_send_wqe {
584 597
 	struct hermonprm_ud_send_wqe ud;
585 598
 	struct hermonprm_mlx_send_wqe mlx;
586 599
 	struct hermonprm_rc_send_wqe rc;
600
+	struct hermonprm_eth_send_wqe eth;
587 601
 	uint8_t force_align[HERMON_SEND_WQE_ALIGN];
588 602
 } __attribute__ (( packed ));
589 603
 
@@ -720,6 +734,51 @@ typedef uint32_t hermon_bitmask_t;
720 734
 	( ( (max_entries) + ( 8 * sizeof ( hermon_bitmask_t ) ) - 1 ) /	     \
721 735
 	  ( 8 * sizeof ( hermon_bitmask_t ) ) )
722 736
 
737
+struct hermon;
738
+struct hermon_port;
739
+
740
+/** A Hermon port type */
741
+struct hermon_port_type {
742
+	/** Register port
743
+	 *
744
+	 * @v hermon		Hermon device
745
+	 * @v port		Hermon port
746
+	 * @ret rc		Return status code
747
+	 */
748
+	int ( * register_dev ) ( struct hermon *hermon,
749
+				 struct hermon_port *port );
750
+	/** Port state changed
751
+	 *
752
+	 * @v hermon		Hermon device
753
+	 * @v port		Hermon port
754
+	 * @v link_up		Link is up
755
+	 */
756
+	void ( * state_change ) ( struct hermon *hermon,
757
+				  struct hermon_port *port,
758
+				  int link_up );
759
+	/** Unregister port
760
+	 *
761
+	 * @v hermon		Hermon device
762
+	 * @v port		Hermon port
763
+	 */
764
+	void ( * unregister_dev ) ( struct hermon *hermon,
765
+				    struct hermon_port *port );
766
+};
767
+
768
+/** A Hermon port */
769
+struct hermon_port {
770
+	/** Infiniband device */
771
+	struct ib_device *ibdev;
772
+	/** Network device */
773
+	struct net_device *netdev;
774
+	/** Ethernet completion queue */
775
+	struct ib_completion_queue *eth_cq;
776
+	/** Ethernet queue pair */
777
+	struct ib_queue_pair *eth_qp;
778
+	/** Port type */
779
+	struct hermon_port_type *type;
780
+};
781
+
723 782
 /** A Hermon device */
724 783
 struct hermon {
725 784
 	/** PCI configuration registers */
@@ -763,8 +822,8 @@ struct hermon {
763 822
 	/** QPN base */
764 823
 	unsigned long qpn_base;
765 824
 
766
-	/** Infiniband devices */
767
-	struct ib_device *ibdev[HERMON_MAX_PORTS];
825
+	/** Ports */
826
+	struct hermon_port port[HERMON_MAX_PORTS];
768 827
 };
769 828
 
770 829
 /** Global protection domain */

+ 0
- 1853
src/drivers/net/mtnic.c
Diff nebyl zobrazen, protože je příliš veliký
Zobrazit soubor


+ 0
- 722
src/drivers/net/mtnic.h Zobrazit soubor

@@ -1,722 +0,0 @@
1
-/*
2
- * Copyright (c) 2007 Mellanox Technologies. All rights reserved.
3
- *
4
- * This software is available to you under a choice of one of two
5
- * licenses.  You may choose to be licensed under the terms of the GNU
6
- * General Public License (GPL) Version 2, available from the file
7
- * COPYING in the main directory of this source tree, or the
8
- * OpenIB.org BSD license below:
9
- *
10
- *     Redistribution and use in source and binary forms, with or
11
- *     without modification, are permitted provided that the following
12
- *     conditions are met:
13
- *
14
- *      - Redistributions of source code must retain the above
15
- *        copyright notice, this list of conditions and the following
16
- *        disclaimer.
17
- *
18
- *      - Redistributions in binary form must reproduce the above
19
- *        copyright notice, this list of conditions and the following
20
- *        disclaimer in the documentation and/or other materials
21
- *        provided with the distribution.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
- * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
- * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
31
- *
32
- */
33
-
34
-FILE_LICENCE ( GPL2_ONLY );
35
-
36
-#ifndef H_MTNIC_IF_DEFS_H
37
-#define H_MTNIC_IF_DEFS_H
38
-
39
-
40
-
41
-/*
42
-* Device setup
43
-*/
44
-#define MTNIC_MAX_PORTS		2
45
-#define MTNIC_PORT1		0
46
-#define MTNIC_PORT2		1
47
-#define NUM_TX_RINGS		1
48
-#define NUM_RX_RINGS		1
49
-#define NUM_CQS 		(NUM_RX_RINGS + NUM_TX_RINGS)
50
-#define GO_BIT_TIMEOUT		6000
51
-#define TBIT_RETRIES		100
52
-#define UNITS_BUFFER_SIZE 	8 /* can be configured to 4/8/16 */
53
-#define MAX_GAP_PROD_CONS 	( UNITS_BUFFER_SIZE / 4 )
54
-#define ETH_DEF_LEN		1540          /* 40 bytes used by the card */
55
-#define ETH_FCS_LEN		14
56
-#define DEF_MTU 		ETH_DEF_LEN + ETH_FCS_LEN
57
-#define DEF_IOBUF_SIZE 		ETH_DEF_LEN
58
-
59
-#define MAC_ADDRESS_SIZE 	6
60
-#define NUM_EQES 		16
61
-#define ROUND_TO_CHECK		0x400
62
-
63
-#define DELAY_LINK_CHECK	300
64
-#define CHECK_LINK_TIMES	7
65
-
66
-
67
-#define XNOR(x,y)		(!(x) == !(y))
68
-#define dma_addr_t 		unsigned long
69
-#define PAGE_SIZE		4096
70
-#define PAGE_MASK		(PAGE_SIZE - 1)
71
-#define MTNIC_MAILBOX_SIZE	PAGE_SIZE
72
-
73
-
74
-
75
-
76
-/* BITOPS */
77
-#define MTNIC_BC_OFF(bc) ((bc) >> 8)
78
-#define MTNIC_BC_SZ(bc) ((bc) & 0xff)
79
-#define MTNIC_BC_ONES(size) (~((int)0x80000000 >> (31 - size)))
80
-#define MTNIC_BC_MASK(bc) \
81
-	(MTNIC_BC_ONES(MTNIC_BC_SZ(bc)) << MTNIC_BC_OFF(bc))
82
-#define MTNIC_BC_VAL(val, bc) \
83
-	(((val) & MTNIC_BC_ONES(MTNIC_BC_SZ(bc))) << MTNIC_BC_OFF(bc))
84
-/*
85
- * Sub word fields - bit code base extraction/setting etc
86
- */
87
-
88
-/* Encode two values */
89
-#define MTNIC_BC(off, size) ((off << 8) | (size & 0xff))
90
-
91
-/* Get value of field 'bc' from 'x' */
92
-#define MTNIC_BC_GET(x, bc) \
93
-	(((x) >> MTNIC_BC_OFF(bc)) & MTNIC_BC_ONES(MTNIC_BC_SZ(bc)))
94
-
95
-/* Set value of field 'bc' of 'x' to 'val' */
96
-#define MTNIC_BC_SET(x, val, bc) \
97
-	((x) = ((x) & ~MTNIC_BC_MASK(bc)) | MTNIC_BC_VAL(val, bc))
98
-
99
-/* Like MTNIC_BC_SET, except the previous value is assumed to be 0 */
100
-#define MTNIC_BC_PUT(x, val, bc) ((x) |= MTNIC_BC_VAL(val, bc))
101
-
102
-
103
-
104
-/*
105
- * Device constants
106
- */
107
-typedef enum mtnic_if_cmd {
108
-	/* NIC commands: */
109
-	MTNIC_IF_CMD_QUERY_FW  = 0x004, /* query FW (size, version, etc) */
110
-	MTNIC_IF_CMD_MAP_FW    = 0xfff, /* map pages for FW image */
111
-	MTNIC_IF_CMD_RUN_FW    = 0xff6, /* run the FW */
112
-	MTNIC_IF_CMD_QUERY_CAP = 0x001, /* query MTNIC capabilities */
113
-	MTNIC_IF_CMD_MAP_PAGES = 0x002, /* map physical pages to HW */
114
-	MTNIC_IF_CMD_OPEN_NIC  = 0x003, /* run the firmware */
115
-	MTNIC_IF_CMD_CONFIG_RX = 0x005, /* general receive configuration */
116
-	MTNIC_IF_CMD_CONFIG_TX = 0x006, /* general transmit configuration */
117
-	MTNIC_IF_CMD_CONFIG_INT_FREQ = 0x007, /* interrupt timers freq limits */
118
-	MTNIC_IF_CMD_HEART_BEAT = 0x008, /* NOP command testing liveliness */
119
-	MTNIC_IF_CMD_CLOSE_NIC = 0x009, /* release memory and stop the NIC */
120
-
121
-	/* Port commands: */
122
-	MTNIC_IF_CMD_CONFIG_PORT_RSS_STEER     = 0x10, /* set RSS mode */
123
-	MTNIC_IF_CMD_SET_PORT_RSS_INDIRECTION  = 0x11, /* set RSS indirection tbl */
124
-	MTNIC_IF_CMD_CONFIG_PORT_PRIO_STEERING = 0x12, /* set PRIORITY mode */
125
-	MTNIC_IF_CMD_CONFIG_PORT_ADDR_STEER    = 0x13, /* set Address steer mode */
126
-	MTNIC_IF_CMD_CONFIG_PORT_VLAN_FILTER   = 0x14, /* configure VLAN filter */
127
-	MTNIC_IF_CMD_CONFIG_PORT_MCAST_FILTER  = 0x15, /* configure mcast filter */
128
-	MTNIC_IF_CMD_ENABLE_PORT_MCAST_FILTER  = 0x16, /* enable/disable */
129
-	MTNIC_IF_CMD_SET_PORT_MTU              = 0x17, /* set port MTU */
130
-	MTNIC_IF_CMD_SET_PORT_PROMISCUOUS_MODE = 0x18, /* enable/disable promisc */
131
-	MTNIC_IF_CMD_SET_PORT_DEFAULT_RING     = 0x19, /* set the default ring */
132
-	MTNIC_IF_CMD_SET_PORT_STATE            = 0x1a, /* set link up/down */
133
-	MTNIC_IF_CMD_DUMP_STAT                 = 0x1b, /* dump statistics */
134
-	MTNIC_IF_CMD_ARM_PORT_STATE_EVENT      = 0x1c, /* arm the port state event */
135
-
136
-	/* Ring / Completion queue commands: */
137
-	MTNIC_IF_CMD_CONFIG_CQ            = 0x20,  /* set up completion queue */
138
-	MTNIC_IF_CMD_CONFIG_RX_RING       = 0x21,  /* setup Rx ring */
139
-	MTNIC_IF_CMD_SET_RX_RING_ADDR     = 0x22,  /* set Rx ring filter by address */
140
-	MTNIC_IF_CMD_SET_RX_RING_MCAST    = 0x23,  /* set Rx ring mcast filter */
141
-	MTNIC_IF_CMD_ARM_RX_RING_WM       = 0x24,  /* one-time low-watermark INT */
142
-	MTNIC_IF_CMD_CONFIG_TX_RING       = 0x25,  /* set up Tx ring */
143
-	MTNIC_IF_CMD_ENFORCE_TX_RING_ADDR = 0x26,  /* setup anti spoofing */
144
-	MTNIC_IF_CMD_CONFIG_EQ            = 0x27,  /* config EQ ring */
145
-	MTNIC_IF_CMD_RELEASE_RESOURCE     = 0x28,  /* release internal ref to resource */
146
-}
147
-mtnic_if_cmd_t;
148
-
149
-
150
-/** selectors for MTNIC_IF_CMD_QUERY_CAP */
151
-typedef enum mtnic_if_caps {
152
-	MTNIC_IF_CAP_MAX_TX_RING_PER_PORT = 0x0,
153
-	MTNIC_IF_CAP_MAX_RX_RING_PER_PORT = 0x1,
154
-	MTNIC_IF_CAP_MAX_CQ_PER_PORT      = 0x2,
155
-	MTNIC_IF_CAP_NUM_PORTS            = 0x3,
156
-	MTNIC_IF_CAP_MAX_TX_DESC          = 0x4,
157
-	MTNIC_IF_CAP_MAX_RX_DESC          = 0x5,
158
-	MTNIC_IF_CAP_MAX_CQES             = 0x6,
159
-	MTNIC_IF_CAP_MAX_TX_SG_ENTRIES    = 0x7,
160
-	MTNIC_IF_CAP_MAX_RX_SG_ENTRIES    = 0x8,
161
-	MTNIC_IF_CAP_MEM_KEY              = 0x9, /* key to mem (after map_pages) */
162
-	MTNIC_IF_CAP_RSS_HASH_TYPE        = 0xa, /* one of mtnic_if_rss_types_t */
163
-	MTNIC_IF_CAP_MAX_PORT_UCAST_ADDR  = 0xc,
164
-	MTNIC_IF_CAP_MAX_RING_UCAST_ADDR  = 0xd, /* only for ADDR steer */
165
-	MTNIC_IF_CAP_MAX_PORT_MCAST_ADDR  = 0xe,
166
-	MTNIC_IF_CAP_MAX_RING_MCAST_ADDR  = 0xf, /* only for ADDR steer */
167
-	MTNIC_IF_CAP_INTA                 = 0x10,
168
-	MTNIC_IF_CAP_BOARD_ID_LOW         = 0x11,
169
-	MTNIC_IF_CAP_BOARD_ID_HIGH        = 0x12,
170
-	MTNIC_IF_CAP_TX_CQ_DB_OFFSET      = 0x13, /* offset in bytes for TX, CQ doorbell record */
171
-	MTNIC_IF_CAP_EQ_DB_OFFSET         = 0x14, /* offset in bytes for EQ doorbell record */
172
-
173
-	/* These are per port - using port number from cap modifier field */
174
-	MTNIC_IF_CAP_SPEED                = 0x20,
175
-	MTNIC_IF_CAP_DEFAULT_MAC          = 0x21,
176
-	MTNIC_IF_CAP_EQ_OFFSET            = 0x22,
177
-	MTNIC_IF_CAP_CQ_OFFSET            = 0x23,
178
-	MTNIC_IF_CAP_TX_OFFSET            = 0x24,
179
-	MTNIC_IF_CAP_RX_OFFSET            = 0x25,
180
-
181
-} mtnic_if_caps_t;
182
-
183
-typedef enum mtnic_if_steer_types {
184
-	MTNIC_IF_STEER_NONE     = 0,
185
-	MTNIC_IF_STEER_PRIORITY = 1,
186
-	MTNIC_IF_STEER_RSS      = 2,
187
-	MTNIC_IF_STEER_ADDRESS  = 3,
188
-} mtnic_if_steer_types_t;
189
-
190
-/** types of memory access modes */
191
-typedef enum mtnic_if_memory_types {
192
-	MTNIC_IF_MEM_TYPE_SNOOP = 1,
193
-	MTNIC_IF_MEM_TYPE_NO_SNOOP = 2
194
-} mtnic_if_memory_types_t;
195
-
196
-
197
-enum {
198
-	MTNIC_HCR_BASE          = 0x1f000,
199
-	MTNIC_HCR_SIZE          = 0x0001c,
200
-	MTNIC_CLR_INT_SIZE      = 0x00008,
201
-};
202
-
203
-#define MTNIC_RESET_OFFSET 	0xF0010
204
-
205
-
206
-
207
-/********************************************************************
208
-* Device private data structures
209
-*
210
-* This section contains structures of all device private data:
211
-*	descriptors, rings, CQs, EQ ....
212
-*
213
-*
214
-*********************************************************************/
215
-/*
216
- * Descriptor format
217
- */
218
-struct mtnic_ctrl_seg {
219
-	u32 op_own;
220
-#define MTNIC_BIT_DESC_OWN	0x80000000
221
-#define MTNIC_OPCODE_SEND	0xa
222
-	u32 size_vlan;
223
-	u32 flags;
224
-#define MTNIC_BIT_NO_ICRC	0x2
225
-#define MTNIC_BIT_TX_COMP	0xc
226
-	u32 reserved;
227
-};
228
-
229
-struct mtnic_data_seg {
230
-	u32 count;
231
-#define MTNIC_INLINE		0x80000000
232
-	u32 mem_type;
233
-#define MTNIC_MEMTYPE_PAD	0x100
234
-	u32 addr_h;
235
-	u32 addr_l;
236
-};
237
-
238
-struct mtnic_tx_desc {
239
-	struct mtnic_ctrl_seg ctrl;
240
-	struct mtnic_data_seg data; /* at least one data segment */
241
-};
242
-
243
-struct mtnic_rx_desc {
244
-	u16 reserved1;
245
-	u16 next;
246
-	u32 reserved2[3];
247
-	struct mtnic_data_seg data; /* actual number of entries depends on
248
-				* rx ring stride */
249
-};
250
-
251
-/*
252
- * Rings
253
- */
254
-struct mtnic_rx_db_record {
255
-	u32 count;
256
-};
257
-
258
-struct mtnic_ring {
259
-	u32 size; /* REMOVE ____cacheline_aligned_in_smp; *//* number of Rx descs or TXBBs */
260
-	u32 size_mask;
261
-	u16 stride;
262
-	u16 cq; /* index of port CQ associated with this ring */
263
-	u32 prod;
264
-	u32 cons; /* holds the last consumed index */
265
-
266
-	/* Buffers */
267
-	u32 buf_size; /* ring buffer size in bytes */
268
-	dma_addr_t dma;
269
-	void *buf;
270
-	struct io_buffer *iobuf[UNITS_BUFFER_SIZE];
271
-
272
-	/* Tx only */
273
-	struct mtnic_txcq_db *txcq_db;
274
-	u32 db_offset;
275
-
276
-	/* Rx ring only */
277
-	dma_addr_t iobuf_dma;
278
-	struct mtnic_rx_db_record *db;
279
-	dma_addr_t db_dma;
280
-};
281
-
282
-/*
283
- * CQ
284
- */
285
-
286
-struct mtnic_cqe {
287
-	u8 vp; /* VLAN present */
288
-	u8 reserved1[3];
289
-	u32 rss_hash;
290
-	u32 reserved2;
291
-	u16 vlan_prio;
292
-	u16 reserved3;
293
-	u8 flags_h;
294
-	u8 flags_l_rht;
295
-	u8 ipv6_mask;
296
-	u8 enc_bf;
297
-#define MTNIC_BIT_BAD_FCS	0x10
298
-#define MTNIC_OPCODE_ERROR	0x1e
299
-	u32 byte_cnt;
300
-	u16 index;
301
-	u16 chksum;
302
-	u8 reserved4[3];
303
-	u8 op_tr_own;
304
-#define MTNIC_BIT_CQ_OWN	0x80
305
-};
306
-
307
-
308
-struct mtnic_cq_db_record {
309
-	u32 update_ci;
310
-	u32 cmd_ci;
311
-};
312
-
313
-struct mtnic_cq {
314
-	int num; /* CQ number (on attached port) */
315
-	u32 size; /* number of CQEs in CQ */
316
-	u32 last; /* number of CQEs consumed */
317
-	struct mtnic_cq_db_record *db;
318
-	struct net_device *dev;
319
-
320
-	dma_addr_t db_dma;
321
-	u8 is_rx;
322
-	u16 ring; /* ring associated with this CQ */
323
-	u32 offset_ind;
324
-
325
-	/* CQE ring */
326
-	u32 buf_size; /* ring size in bytes */
327
-	struct mtnic_cqe *buf;
328
-	dma_addr_t dma;
329
-};
330
-
331
-/*
332
- * EQ
333
- */
334
-
335
-struct mtnic_eqe {
336
-	u8 reserved1;
337
-	u8 type;
338
-	u8 reserved2;
339
-	u8 subtype;
340
-	u8 reserved3[3];
341
-	u8 ring_cq;
342
-	u32 reserved4;
343
-	u8 port;
344
-#define MTNIC_MASK_EQE_PORT    MTNIC_BC(4,2)
345
-	u8 reserved5[2];
346
-	u8 syndrome;
347
-	u8 reserved6[15];
348
-	u8 own;
349
-#define MTNIC_BIT_EQE_OWN      0x80
350
-};
351
-
352
-struct mtnic_eq {
353
-	u32 size; /* number of EQEs in ring */
354
-	u32 buf_size; /* EQ size in bytes */
355
-	void *buf;
356
-	dma_addr_t dma;
357
-};
358
-
359
-enum mtnic_state {
360
-	CARD_DOWN,
361
-	CARD_INITIALIZED,
362
-	CARD_UP,
363
-	CARD_LINK_DOWN,
364
-};
365
-
366
-/* FW */
367
-struct mtnic_pages {
368
-	u32 num;
369
-	u32 *buf;
370
-};
371
-struct mtnic_err_buf {
372
-	u64 offset;
373
-	u32 size;
374
-};
375
-
376
-
377
-
378
-struct mtnic_cmd {
379
-	void                    *buf;
380
-	unsigned long           mapping;
381
-	u32                     tbit;
382
-};
383
-
384
-
385
-struct mtnic_txcq_db {
386
-	u32 reserved1[5];
387
-	u32 send_db;
388
-	u32 reserved2[2];
389
-	u32 cq_arm;
390
-	u32 cq_ci;
391
-};
392
-
393
-
394
-
395
-/*
396
- * Device private data
397
- *
398
- */
399
-struct mtnic {
400
-	struct net_device               *netdev[MTNIC_MAX_PORTS];
401
-	struct mtnic_if_cmd_reg         *hcr;
402
-	struct mtnic_cmd                cmd;
403
-	struct pci_device               *pdev;
404
-
405
-	struct mtnic_eq                 eq;
406
-	u32                             *eq_db;
407
-
408
-	/* Firmware and board info */
409
-	u64                             fw_ver;
410
-	struct {
411
-		struct mtnic_pages      fw_pages;
412
-		struct mtnic_pages      extra_pages;
413
-		struct mtnic_err_buf    err_buf;
414
-		u16                     ifc_rev;
415
-		u8                      num_ports;
416
-		u64                     mac[MTNIC_MAX_PORTS];
417
-		u16                     cq_offset;
418
-		u16                     tx_offset[MTNIC_MAX_PORTS];
419
-		u16                     rx_offset[MTNIC_MAX_PORTS];
420
-		u32                     mem_type_snoop_be;
421
-		u32                     txcq_db_offset;
422
-		u32                     eq_db_offset;
423
-	} fw;
424
-};
425
-
426
-
427
-
428
-
429
-
430
-struct mtnic_port {
431
-
432
-	struct mtnic                    *mtnic;
433
-	u8                              port;
434
-
435
-	enum mtnic_state                state;
436
-
437
-	/* TX, RX, CQs, EQ */
438
-	struct mtnic_ring               tx_ring;
439
-	struct mtnic_ring               rx_ring;
440
-	struct mtnic_cq                 cq[NUM_CQS];
441
-	u32                             poll_counter;
442
-	struct net_device               *netdev;
443
-
444
-
445
-};
446
-
447
-
448
-
449
-
450
-
451
-
452
-
453
-
454
-
455
-
456
-
457
-
458
-/***************************************************************************
459
- * NIC COMMANDS
460
- *
461
- * The section below provides struct definition for commands parameters,
462
- * and arguments values enumeration.
463
- *
464
- * The format used for the struct names is:
465
- * mtnic_if_<cmd name>_<in|out>_<imm|mbox>
466
- *
467
- ***************************************************************************/
468
-/**
469
- *  Command Register (Command interface)
470
- */
471
-struct mtnic_if_cmd_reg {
472
-	unsigned long in_param_h;
473
-	u32 in_param_l;
474
-	u32 input_modifier;
475
-	u32 out_param_h;
476
-	u32 out_param_l;
477
-	u32 token;
478
-#define MTNIC_MASK_CMD_REG_TOKEN	 MTNIC_BC(16,32)
479
-	u32 status_go_opcode;
480
-#define MTNIC_MASK_CMD_REG_OPCODE MTNIC_BC(0,16)
481
-#define MTNIC_MASK_CMD_REG_T_BIT  MTNIC_BC(21,1)
482
-#define MTNIC_MASK_CMD_REG_GO_BIT MTNIC_BC(23,1)
483
-#define MTNIC_MASK_CMD_REG_STATUS MTNIC_BC(24,8)
484
-};
485
-
486
-
487
-
488
-/* CMD QUERY_FW */
489
-struct mtnic_if_query_fw_out_mbox {
490
-	u16 fw_pages;   /* Total number of memory pages the device requires */
491
-	u16 rev_maj;
492
-	u16 rev_smin;
493
-	u16 rev_min;
494
-	u16 reserved1;
495
-	u16 ifc_rev;    /* major revision of the command interface */
496
-	u8  ft;
497
-	u8  reserved2[3];
498
-	u32 reserved3[4];
499
-	u64 clr_int_base;
500
-	u32 reserved4[2];
501
-	u64 err_buf_start;
502
-	u32 err_buf_size;
503
-};
504
-
505
-/* CMD MTNIC_IF_CMD_QUERY_CAP */
506
-struct mtnic_if_query_cap_in_imm {
507
-	u16 reserved1;
508
-	u8               cap_modifier;   /* a modifier for the particular capability */
509
-	u8               cap_index;      /* the index of the capability queried */
510
-	u32 reserved2;
511
-};
512
-
513
-/* CMD OPEN_NIC */
514
-struct mtnic_if_open_nic_in_mbox {
515
-	u16 reserved1;
516
-	u16 mkey; /* number of mem keys for all chip*/
517
-	u32 mkey_entry; /* mem key entries for each key*/
518
-	u8 log_rx_p1; /* log2 rx rings for port1 */
519
-	u8 log_cq_p1; /* log2 cq for port1 */
520
-	u8 log_tx_p1; /* log2 tx rings for port1 */
521
-	u8 steer_p1;  /* port 1 steering mode */
522
-	u16 reserved2;
523
-	u8 log_vlan_p1; /* log2 vlan per rx port1 */
524
-	u8 log_mac_p1;  /* log2 mac per rx port1 */
525
-
526
-	u8 log_rx_p2; /* log2 rx rings for port1 */
527
-	u8 log_cq_p2; /* log2 cq for port1 */
528
-	u8 log_tx_p2; /* log2 tx rings for port1 */
529
-	u8 steer_p2;  /* port 1 steering mode */
530
-	u16 reserved3;
531
-	u8 log_vlan_p2; /* log2 vlan per rx port1 */
532
-	u8 log_mac_p2;  /* log2 mac per rx port1 */
533
-};
534
-
535
-
536
-/* CMD CONFIG_RX */
537
-struct mtnic_if_config_rx_in_imm {
538
-	u16 spkt_size; /* size of small packets interrupts enabled on CQ */
539
-	u16 resp_rcv_pause_frm_mcast_vlan_comp; /* Two flags see MASK below */
540
-	/* Enable response to receive pause frames */
541
-	/* Use VLAN in exact-match multicast checks (see SET_RX_RING_MCAST) */
542
-};
543
-
544
-/* CMD CONFIG_TX */
545
-struct mtnic_if_config_send_in_imm {
546
-	u32  enph_gpf; /* Enable PseudoHeader and GeneratePauseFrames flags */
547
-	u32  reserved;
548
-};
549
-
550
-/* CMD HEART_BEAT */
551
-struct mtnic_if_heart_beat_out_imm {
552
-	u32 flags; /* several flags */
553
-#define MTNIC_MASK_HEAR_BEAT_INT_ERROR  MTNIC_BC(31,1)
554
-	u32 reserved;
555
-};
556
-
557
-
558
-/*
559
- * PORT COMMANDS
560
- */
561
-/* CMD CONFIG_PORT_VLAN_FILTER */
562
-/* in mbox is a 4K bits mask - bit per VLAN */
563
-struct mtnic_if_config_port_vlan_filter_in_mbox {
564
-	u64 filter[64]; /* vlans[63:0] sit in filter[0], vlans[127:64] sit in filter[1] ..  */
565
-};
566
-
567
-
568
-/* CMD SET_PORT_MTU */
569
-struct mtnic_if_set_port_mtu_in_imm {
570
-	u16 reserved1;
571
-	u16 mtu;                        /* The MTU of the port in bytes */
572
-	u32 reserved2;
573
-};
574
-
575
-/* CMD SET_PORT_DEFAULT_RING */
576
-struct mtnic_if_set_port_default_ring_in_imm {
577
-	u8 reserved1[3];
578
-	u8 ring; /* Index of ring that collects promiscuous traffic */
579
-	u32 reserved2;
580
-};
581
-
582
-/* CMD SET_PORT_STATE */
583
-struct mtnic_if_set_port_state_in_imm {
584
-	u32 state; /* if 1 the port state should be up */
585
-#define MTNIC_MASK_CONFIG_PORT_STATE MTNIC_BC(0,1)
586
-	u32 reserved;
587
-};
588
-
589
-/* CMD CONFIG_CQ */
590
-struct mtnic_if_config_cq_in_mbox {
591
-	u8           reserved1;
592
-	u8           cq;
593
-	u8           size;        /* Num CQs is 2^size (size <= 22) */
594
-	u8           offset; /* start address of CQE in first page (11:6) */
595
-	u16  tlast;      /* interrupt moderation timer from last completion usec */
596
-	u8      flags;  /* flags */
597
-	u8          int_vector; /* MSI index if MSI is enabled, otherwise reserved */
598
-	u16 reserved2;
599
-	u16 max_cnt;    /* interrupt moderation counter */
600
-	u8          page_size;   /* each mapped page is 2^(12+page_size) bytes */
601
-	u8       reserved4[3];
602
-	u32 db_record_addr_h;  /*physical address of CQ doorbell record */
603
-	u32 db_record_addr_l;  /*physical address of CQ doorbell record */
604
-	u32 page_address[0]; /* 64 bit page addresses of CQ buffer */
605
-};
606
-
607
-/* CMD CONFIG_RX_RING */
608
-struct mtnic_if_config_rx_ring_in_mbox {
609
-	u8       reserved1;
610
-	u8       ring;                          /* The ring index (with offset) */
611
-	u8       stride_size;           /* stride and size */
612
-	/* Entry size = 16* (2^stride) bytes */
613
-#define MTNIC_MASK_CONFIG_RX_RING_STRIDE     MTNIC_BC(4,3)
614
-	/* Rx ring size is 2^size entries */
615
-#define MTNIC_MASK_CONFIG_RX_RING_SIZE	      MTNIC_BC(0,4)
616
-	u8       flags;                         /* Bit0 - header separation */
617
-	u8       page_size;                       /* Each mapped page is 2^(12+page_size) bytes */
618
-	u8       reserved2[2];
619
-	u8       cq;                                      /* CQ associated with this ring */
620
-	u32      db_record_addr_h;
621
-	u32      db_record_addr_l;
622
-	u32      page_address[0];/* Array of 2^size 64b page descriptor addresses */
623
-	/* Must hold all Rx descriptors + doorbell record. */
624
-};
625
-
626
-/* The modifier for SET_RX_RING_ADDR */
627
-struct mtnic_if_set_rx_ring_modifier {
628
-	u8 reserved;
629
-	u8 port_num;
630
-	u8 index;
631
-	u8 ring;
632
-};
633
-
634
-/* CMD SET_RX_RING_ADDR */
635
-struct mtnic_if_set_rx_ring_addr_in_imm {
636
-	u16 mac_47_32;           /* UCAST MAC Address bits 47:32 */
637
-	u16 flags_vlan_id; /* MAC/VLAN flags and vlan id */
638
-#define MTNIC_MASK_SET_RX_RING_ADDR_VLAN_ID MTNIC_BC(0,12)
639
-#define MTNIC_MASK_SET_RX_RING_ADDR_BY_MAC  MTNIC_BC(12,1)
640
-#define MTNIC_MASK_SET_RX_RING_ADDR_BY_VLAN MTNIC_BC(13,1)
641
-	u32 mac_31_0;   /* UCAST MAC Address bits 31:0 */
642
-};
643
-
644
-/* CMD CONFIG_TX_RING */
645
-struct mtnic_if_config_send_ring_in_mbox {
646
-	u16 ring;                       /* The ring index (with offset) */
647
-#define MTNIC_MASK_CONFIG_TX_RING_INDEX  MTNIC_BC(0,8)
648
-	u8       size;                          /* Tx ring size is 32*2^size bytes */
649
-#define MTNIC_MASK_CONFIG_TX_RING_SIZE	  MTNIC_BC(0,4)
650
-	u8       reserved;
651
-	u8       page_size;                     /* Each mapped page is 2^(12+page_size) bytes */
652
-	u8       qos_class;                     /* The COS used for this Tx */
653
-	u16 cq;                         /* CQ associated with this ring */
654
-#define MTNIC_MASK_CONFIG_TX_CQ_INDEX	  MTNIC_BC(0,8)
655
-	u32 page_address[0]; /* 64 bit page addresses of descriptor buffer. */
656
-	/* The buffer must accommodate all Tx descriptors */
657
-};
658
-
659
-/* CMD CONFIG_EQ */
660
-struct mtnic_if_config_eq_in_mbox {
661
-	u8 reserved1;
662
-	u8 int_vector; /* MSI index if MSI enabled; otherwise reserved */
663
-#define MTNIC_MASK_CONFIG_EQ_INT_VEC MTNIC_BC(0,6)
664
-	u8 size;                        /* Num CQs is 2^size entries (size <= 22) */
665
-#define MTNIC_MASK_CONFIG_EQ_SIZE	 MTNIC_BC(0,5)
666
-	u8 offset;              /* Start address of CQE in first page (11:6) */
667
-#define MTNIC_MASK_CONFIG_EQ_OFFSET	 MTNIC_BC(0,6)
668
-	u8 page_size; /* Each mapped page is 2^(12+page_size) bytes*/
669
-	u8 reserved[3];
670
-	u32 page_address[0]; /* 64 bit page addresses of EQ buffer */
671
-};
672
-
673
-/* CMD RELEASE_RESOURCE */
674
-enum mtnic_if_resource_types {
675
-	MTNIC_IF_RESOURCE_TYPE_CQ = 0,
676
-	MTNIC_IF_RESOURCE_TYPE_RX_RING,
677
-	MTNIC_IF_RESOURCE_TYPE_TX_RING,
678
-	MTNIC_IF_RESOURCE_TYPE_EQ
679
-};
680
-
681
-struct mtnic_if_release_resource_in_imm {
682
-	u8 reserved1;
683
-	u8 index;         /* must be 0 for TYPE_EQ */
684
-	u8 reserved2;
685
-	u8 type;          /* see enum mtnic_if_resource_types */
686
-	u32 reserved3;
687
-};
688
-
689
-
690
-
691
-
692
-
693
-
694
-
695
-
696
-
697
-/*******************************************************************
698
-*
699
-* PCI addon structures
700
-*
701
-********************************************************************/
702
-
703
-struct pcidev {
704
-	unsigned long bar[6];
705
-	u32 dev_config_space[64];
706
-	struct pci_device *dev;
707
-	u8 bus;
708
-	u8 devfn;
709
-};
710
-
711
-struct dev_pci_struct {
712
-	struct pcidev dev;
713
-	struct pcidev br;
714
-};
715
-
716
-/* The only global var */
717
-struct dev_pci_struct mtnic_pci_dev;
718
-
719
-
720
-
721
-#endif /* H_MTNIC_IF_DEFS_H */
722
-

Načítá se…
Zrušit
Uložit