summaryrefslogtreecommitdiffstats
path: root/src/net/infiniband/xsigo.c
blob: 5e805fa0264c6da19769c4be2ee27c25148d9414 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
/*
 * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 * You can also choose to distribute this program under the terms of
 * the Unmodified Binary Distribution Licence (as given in the file
 * COPYING.UBDL), provided that you have satisfied its requirements.
 */

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );

#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/version.h>
#include <ipxe/timer.h>
#include <ipxe/malloc.h>
#include <ipxe/iobuf.h>
#include <ipxe/retry.h>
#include <ipxe/process.h>
#include <ipxe/settings.h>
#include <ipxe/infiniband.h>
#include <ipxe/ib_service.h>
#include <ipxe/ib_cmrc.h>
#include <ipxe/if_ether.h>
#include <ipxe/ethernet.h>
#include <ipxe/eoib.h>
#include <ipxe/xsigo.h>

/** @file
 *
 * Xsigo virtual Ethernet devices
 *
 */

/** A Xsigo device */
struct xsigo_device {
	/** Reference count */
	struct refcnt refcnt;
	/** Underlying Infiniband device */
	struct ib_device *ibdev;
	/** List of Xsigo devices */
	struct list_head list;
	/** Device name */
	const char *name;

	/** Link opener timer */
	struct retry_timer opener;

	/** Discovery timer */
	struct retry_timer discovery;
	/** Discovery management transaction (if any) */
	struct ib_mad_transaction *madx;

	/** List of configuration managers */
	struct list_head managers;
};

/** A Xsigo configuration manager */
struct xsigo_manager {
	/** Reference count */
	struct refcnt refcnt;
	/** Xsigo device */
	struct xsigo_device *xdev;
	/** List of managers */
	struct list_head list;
	/** Device name */
	char name[16];
	/** Manager ID */
	struct xsigo_manager_id id;

	/** Data transfer interface */
	struct interface xfer;
	/** Connection timer */
	struct retry_timer reopen;
	/** Keepalive timer */
	struct retry_timer keepalive;
	/** Transmission process */
	struct process process;
	/** Pending transmissions */
	unsigned int pending;
	/** Transmit sequence number */
	uint32_t seq;

	/** List of virtual Ethernet devices */
	struct list_head nics;
};

/** Configuration manager pending transmissions */
enum xsigo_manager_pending {
	/** Send connection request */
	XCM_TX_CONNECT = 0x0001,
	/** Send registration message */
	XCM_TX_REGISTER = 0x0002,
};

/** A Xsigo virtual Ethernet device */
struct xsigo_nic {
	/** Configuration manager */
	struct xsigo_manager *xcm;
	/** List of virtual Ethernet devices */
	struct list_head list;
	/** Device name */
	char name[16];

	/** Resource identifier */
	union ib_guid resource;
	/** MAC address */
	uint8_t mac[ETH_ALEN];
	/** Network ID */
	unsigned long network;
};

/** Configuration manager service ID */
static union ib_guid xcm_service_id = {
	.bytes = XCM_SERVICE_ID,
};

/** List of all Xsigo devices */
static LIST_HEAD ( xsigo_devices );

/**
 * Free Xsigo device
 *
 * @v refcnt		Reference count
 */
static void xsigo_free ( struct refcnt *refcnt ) {
	struct xsigo_device *xdev =
		container_of ( refcnt, struct xsigo_device, refcnt );

	/* Sanity checks */
	assert ( ! timer_running ( &xdev->opener ) );
	assert ( ! timer_running ( &xdev->discovery ) );
	assert ( xdev->madx == NULL );
	assert ( list_empty ( &xdev->managers ) );

	/* Drop reference to Infiniband device */
	ibdev_put ( xdev->ibdev );

	/* Free device */
	free ( xdev );
}

/**
 * Free configuration manager
 *
 * @v refcnt		Reference count
 */
static void xcm_free ( struct refcnt *refcnt ) {
	struct xsigo_manager *xcm =
		container_of ( refcnt, struct xsigo_manager, refcnt );

	/* Sanity checks */
	assert ( ! timer_running ( &xcm->reopen ) );
	assert ( ! timer_running ( &xcm->keepalive ) );
	assert ( ! process_running ( &xcm->process ) );
	assert ( list_empty ( &xcm->nics ) );

	/* Drop reference to Xsigo device */
	ref_put ( &xcm->xdev->refcnt );

	/* Free manager */
	free ( xcm );
}

/****************************************************************************
 *
 * Virtual Ethernet (XVE) devices
 *
 ****************************************************************************
 */

/**
 * Create virtual Ethernet device
 *
 * @v xcm		Configuration manager
 * @v resource		Resource identifier
 * @v mac		Ethernet MAC
 * @v network		Network identifier
 * @v name		Device name
 * @ret rc		Return status code
 */
static int xve_create ( struct xsigo_manager *xcm, union ib_guid *resource,
			const uint8_t *mac, unsigned long network,
			unsigned long qkey, const char *name ) {
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	struct xsigo_nic *xve;
	struct ib_address_vector broadcast;
	int rc;

	/* Allocate and initialise structure */
	xve = zalloc ( sizeof ( *xve ) );
	if ( ! xve ) {
		rc = -ENOMEM;
		goto err_alloc;
	}
	xve->xcm = xcm;
	snprintf ( xve->name, sizeof ( xve->name ), "%s", name );
	memcpy ( &xve->resource, resource, sizeof ( xve->resource ) );
	memcpy ( xve->mac, mac, ETH_ALEN );
	xve->network = network;
	DBGC ( xve, "XVE %s created for %s " IB_GUID_FMT "\n",
	       xve->name, xcm->name, IB_GUID_ARGS ( resource ) );
	DBGC ( xve, "XVE %s is MAC %s on network %ld\n",
	       xve->name, eth_ntoa ( mac ), network );

	/* Construct broadcast address vector */
	memset ( &broadcast, 0, sizeof ( broadcast ) );
	broadcast.qpn = IB_QPN_BROADCAST;
	broadcast.qkey = qkey;
	broadcast.gid_present = 1;
	broadcast.gid.dwords[0] = htonl ( XVE_PREFIX );
	broadcast.gid.words[2] = htons ( ibdev->pkey );
	broadcast.gid.dwords[3] = htonl ( network );

	/* Create EoIB device */
	if ( ( rc = eoib_create ( ibdev, xve->mac, &broadcast,
				  xve->name ) ) != 0 ) {
		DBGC ( xve, "XVE %s could not create EoIB device: %s\n",
		       xve->name, strerror ( rc ) );
		goto err_create;
	}

	/* Add to list of virtual Ethernet devices.  Do this only
	 * after creating the EoIB device, so that our net device
	 * notifier won't attempt to send an operational state update
	 * before we have acknowledged the installation.
	 */
	list_add ( &xve->list, &xcm->nics );

	return 0;

	list_del ( &xve->list );
 err_create:
	free ( xve );
 err_alloc:
	return rc;
}

/**
 * Find virtual Ethernet device
 *
 * @v xcm		Configuration manager
 * @v resource		Resource identifier
 * @ret xve		Virtual Ethernet device, or NULL
 */
static struct xsigo_nic * xve_find ( struct xsigo_manager *xcm,
				     union ib_guid *resource ) {
	struct xsigo_nic *xve;

	list_for_each_entry ( xve, &xcm->nics, list ) {
		if ( memcmp ( resource, &xve->resource,
			      sizeof ( *resource ) ) == 0 )
			return xve;
	}
	return NULL;
}

/**
 * Destroy virtual Ethernet device
 *
 * @v xve		Virtual Ethernet device
 */
static void xve_destroy ( struct xsigo_nic *xve ) {
	struct xsigo_manager *xcm = xve->xcm;
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	struct eoib_device *eoib;

	/* Destroy corresponding EoIB device, if any */
	if ( ( eoib = eoib_find ( ibdev, xve->mac ) ) )
		eoib_destroy ( eoib );

	/* Remove from list of virtual Ethernet devices */
	list_del ( &xve->list );

	/* Free virtual Ethernet device */
	DBGC ( xve, "XVE %s destroyed\n", xve->name );
	free ( xve );
}

/**
 * Update virtual Ethernet device MTU
 *
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @v mtu		New MTU (excluding Ethernet and EoIB headers)
 * @ret rc		Return status code
 */
static int xve_update_mtu ( struct xsigo_nic *xve, struct eoib_device *eoib,
			    size_t mtu ) {
	struct net_device *netdev = eoib->netdev;
	size_t max;

	/* Check that we can support this MTU */
	max = ( IB_MAX_PAYLOAD_SIZE - ( sizeof ( struct ethhdr ) +
					sizeof ( struct eoib_header ) ) );
	if ( mtu > max ) {
		DBGC ( xve, "XVE %s cannot support MTU %zd (max %zd)\n",
		       xve->name, mtu, max );
		return -ERANGE;
	}

	/* Update MTU.  No need to close/reopen the network device,
	 * since our Infiniband stack uses a fixed MTU anyway.  Note
	 * that the network device sees the Ethernet frame header but
	 * not the EoIB header.
	 */
	netdev->max_pkt_len = ( mtu + sizeof ( struct ethhdr ) );
	netdev->mtu = mtu;
	DBGC ( xve, "XVE %s has MTU %zd\n", xve->name, mtu );

	return 0;
}

/**
 * Open virtual Ethernet device
 *
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @v open		New administrative state
 * @ret rc		Return status code
 */
static int xve_open ( struct xsigo_nic *xve, struct eoib_device *eoib ) {
	struct net_device *netdev = eoib->netdev;
	int rc;

	/* Do nothing if network device is already open */
	if ( netdev_is_open ( netdev ) )
		return 0;
	DBGC ( xve, "XVE %s opening network device\n", xve->name );

	/* Open network device */
	if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
		DBGC ( xve, "XVE %s could not open: %s\n",
		       xve->name, strerror ( rc ) );
		return rc;
	}

	return 0;
}

/**
 * Close virtual Ethernet device
 *
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 */
static void xve_close ( struct xsigo_nic *xve, struct eoib_device *eoib ) {
	struct net_device *netdev = eoib->netdev;

	/* Do nothing if network device is already closed */
	if ( ! netdev_is_open ( netdev ) )
		return;

	/* Close network device */
	netdev_close ( netdev );
	DBGC ( xve, "XVE %s closed network device\n", xve->name );
}

/**
 * Update virtual Ethernet device administrative state
 *
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @v open		New administrative state
 * @ret rc		Return status code
 */
static int xve_update_state ( struct xsigo_nic *xve, struct eoib_device *eoib,
			      int open ) {

	/* Open or close device, as applicable */
	if ( open ) {
		return xve_open ( xve, eoib );
	} else {
		xve_close ( xve, eoib );
		return 0;
	}
}

/**
 * Update gateway (TCA)
 *
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @v av		Address vector, or NULL if no gateway
 * @ret rc		Return status code
 */
static int xve_update_tca ( struct xsigo_nic *xve, struct eoib_device *eoib,
			    struct ib_address_vector *av ) {

	/* Update gateway address */
	eoib_set_gateway ( eoib, av );
	if ( av ) {
		DBGC ( xve, "XVE %s has TCA " IB_GID_FMT " data %#lx qkey "
		       "%#lx\n", xve->name, IB_GID_ARGS ( &av->gid ), av->qpn,
		       av->qkey );
	} else {
		DBGC ( xve, "XVE %s has no TCA\n", xve->name );
	}

	/* The Linux driver will modify the local device's link state
	 * to reflect the EoIB-to-Ethernet gateway's link state, but
	 * this seems philosophically incorrect since communication
	 * within the EoIB broadcast domain still works regardless of
	 * the state of the gateway.
	 */

	return 0;
}

/****************************************************************************
 *
 * Server management protocol (XSMP) session messages
 *
 ****************************************************************************
 */

/**
 * Get session message name (for debugging)
 *
 * @v type		Message type
 * @ret name		Message name
 */
static const char * xsmp_session_type ( unsigned int type ) {
	static char buf[16];

	switch ( type ) {
	case XSMP_SESSION_TYPE_HELLO:		return "HELLO";
	case XSMP_SESSION_TYPE_REGISTER:	return "REGISTER";
	case XSMP_SESSION_TYPE_CONFIRM:		return "CONFIRM";
	case XSMP_SESSION_TYPE_REJECT:		return "REJECT";
	case XSMP_SESSION_TYPE_SHUTDOWN:	return "SHUTDOWN";
	default:
		snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", type );
		return buf;
	}
}

/**
 * Extract chassis name (for debugging)
 *
 * @v msg		Session message
 * @ret chassis		Chassis name
 */
static const char * xsmp_chassis_name ( struct xsmp_session_message *msg ) {
	static char chassis[ sizeof ( msg->chassis ) + 1 /* NUL */ ];

	memcpy ( chassis, msg->chassis, sizeof ( msg->chassis ) );
	return chassis;
}

/**
 * Extract session name (for debugging)
 *
 * @v msg		Session message
 * @ret session		Session name
 */
static const char * xsmp_session_name ( struct xsmp_session_message *msg ) {
	static char session[ sizeof ( msg->session ) + 1 /* NUL */ ];

	memcpy ( session, msg->session, sizeof ( msg->session ) );
	return session;
}

/**
 * Send session message
 *
 * @v xcm		Configuration manager
 * @v type		Message type
 * @ret rc		Return status code
 */
static int xsmp_tx_session ( struct xsigo_manager *xcm, unsigned int type ) {
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	struct xsmp_session_message msg;
	int rc;

	/* Construct session message */
	memset ( &msg, 0, sizeof ( msg ) );
	msg.hdr.type = XSMP_TYPE_SESSION;
	msg.hdr.len = htons ( sizeof ( msg ) );
	msg.hdr.seq = htonl ( ++xcm->seq );
	memcpy ( &msg.hdr.src.guid, &ibdev->gid.s.guid,
		 sizeof ( msg.hdr.src.guid ) );
	memcpy ( &msg.hdr.dst.guid, &xcm->id.guid,
		 sizeof ( msg.hdr.dst.guid ) );
	msg.type = type;
	msg.len = htons ( sizeof ( msg ) - sizeof ( msg.hdr ) );
	msg.os_type = XSIGO_OS_TYPE_GENERIC;
	msg.resources = htons ( XSIGO_RESOURCE_XVE |
				XSIGO_RESOURCE_NO_HA );
	msg.boot = htonl ( XSMP_BOOT_PXE );
	DBGCP ( xcm, "XCM %s TX[%d] session %s\n", xcm->name,
		ntohl ( msg.hdr.seq ), xsmp_session_type ( msg.type ) );
	DBGCP_HDA ( xcm, 0, &msg, sizeof ( msg ) );

	/* Send session message */
	if ( ( rc = xfer_deliver_raw ( &xcm->xfer, &msg,
				       sizeof ( msg ) ) ) != 0 ) {
		DBGC ( xcm, "XCM %s TX session %s failed: %s\n", xcm->name,
		       xsmp_session_type ( msg.type ), strerror ( rc ) );
		return rc;
	}

	return 0;
}

/**
 * Send registration message
 *
 * @v xcm		Configuration manager
 * @ret rc		Return status code
 */
static inline int xsmp_tx_session_register ( struct xsigo_manager *xcm ) {

	DBGC ( xcm, "XCM %s registering with " IB_GUID_FMT "\n",
	       xcm->name, IB_GUID_ARGS ( &xcm->id.guid ) );

	/* Send registration message */
	return xsmp_tx_session ( xcm, XSMP_SESSION_TYPE_REGISTER );
}

/**
 * Send keepalive message
 *
 * @v xcm		Configuration manager
 * @ret rc		Return status code
 */
static int xsmp_tx_session_hello ( struct xsigo_manager *xcm ) {

	/* Send keepalive message */
	return xsmp_tx_session ( xcm, XSMP_SESSION_TYPE_HELLO );
}

/**
 * Handle received keepalive message
 *
 * @v xcm		Configuration manager
 * @v msg		Keepalive message
 * @ret rc		Return status code
 */
static int xsmp_rx_session_hello ( struct xsigo_manager *xcm,
				   struct xsmp_session_message *msg __unused ) {

	/* Respond to keepalive message.  Note that the XCM doesn't
	 * seem to actually ever send these.
	 */
	return xsmp_tx_session_hello ( xcm );
}

/**
 * Handle received registration confirmation message
 *
 * @v xcm		Configuration manager
 * @v msg		Registration confirmation message
 * @ret rc		Return status code
 */
static int xsmp_rx_session_confirm ( struct xsigo_manager *xcm,
				     struct xsmp_session_message *msg ) {

	DBGC ( xcm, "XCM %s registered with \"%s\" as \"%s\"\n", xcm->name,
	       xsmp_chassis_name ( msg ), xsmp_session_name ( msg ) );

	return 0;
}

/**
 * Handle received registration rejection message
 *
 * @v xcm		Configuration manager
 * @v msg		Registration confirmation message
 * @ret rc		Return status code
 */
static int xsmp_rx_session_reject ( struct xsigo_manager *xcm,
				    struct xsmp_session_message *msg ) {

	DBGC ( xcm, "XCM %s rejected by \"%s\":\n",
	       xcm->name, xsmp_chassis_name ( msg ) );
	DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );

	return -EPERM;
}

/**
 * Handle received shutdown message
 *
 * @v xcm		Configuration manager
 * @v msg		Registration confirmation message
 * @ret rc		Return status code
 */
static int xsmp_rx_session_shutdown ( struct xsigo_manager *xcm,
				      struct xsmp_session_message *msg ) {

	DBGC ( xcm, "XCM %s shut down by \"%s\":\n",
	       xcm->name, xsmp_chassis_name ( msg ) );
	DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );

	return -ENOTCONN;
}

/**
 * Handle received session message
 *
 * @v xcm		Configuration manager
 * @v msg		Session message
 * @ret rc		Return status code
 */
static int xsmp_rx_session ( struct xsigo_manager *xcm,
			     struct xsmp_session_message *msg ) {

	DBGCP ( xcm, "XCM %s RX[%d] session %s\n", xcm->name,
		ntohl ( msg->hdr.seq ), xsmp_session_type ( msg->type ) );
	DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) );

	/* Handle message according to type */
	switch ( msg->type ) {
	case XSMP_SESSION_TYPE_HELLO:
		return xsmp_rx_session_hello ( xcm, msg );
	case XSMP_SESSION_TYPE_CONFIRM:
		return xsmp_rx_session_confirm ( xcm, msg );
	case XSMP_SESSION_TYPE_REJECT:
		return xsmp_rx_session_reject ( xcm, msg );
	case XSMP_SESSION_TYPE_SHUTDOWN:
		return xsmp_rx_session_shutdown ( xcm, msg );
	default:
		DBGC ( xcm, "XCM %s RX[%d] session unexpected %s:\n", xcm->name,
		       ntohl ( msg->hdr.seq ), xsmp_session_type ( msg->type ));
		DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );
		return -EPROTO;
	}
}

/****************************************************************************
 *
 * Server management protocol (XSMP) virtual Ethernet (XVE) messages
 *
 ****************************************************************************
 */

/**
 * Get virtual Ethernet message name (for debugging)
 *
 * @v type		Message type
 * @ret name		Message name
 */
static const char * xsmp_xve_type ( unsigned int type ) {
	static char buf[16];

	switch ( type ) {
	case XSMP_XVE_TYPE_INSTALL:		return "INSTALL";
	case XSMP_XVE_TYPE_DELETE:		return "DELETE";
	case XSMP_XVE_TYPE_UPDATE:		return "UPDATE";
	case XSMP_XVE_TYPE_OPER_UP:		return "OPER_UP";
	case XSMP_XVE_TYPE_OPER_DOWN:		return "OPER_DOWN";
	case XSMP_XVE_TYPE_OPER_REQ:		return "OPER_REQ";
	case XSMP_XVE_TYPE_READY:		return "READY";
	default:
		snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", type );
		return buf;
	}
}

/**
 * Send virtual Ethernet message
 *
 * @v xcm		Configuration manager
 * @v msg		Partial message
 * @ret rc		Return status code
 */
static int xsmp_tx_xve ( struct xsigo_manager *xcm,
			 struct xsmp_xve_message *msg ) {
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	int rc;

	/* Fill in common header fields */
	msg->hdr.type = XSMP_TYPE_XVE;
	msg->hdr.len = htons ( sizeof ( *msg ) );
	msg->hdr.seq = htonl ( ++xcm->seq );
	memcpy ( &msg->hdr.src.guid, &ibdev->gid.s.guid,
		 sizeof ( msg->hdr.src.guid ) );
	memcpy ( &msg->hdr.dst.guid, &xcm->id.guid,
		 sizeof ( msg->hdr.dst.guid ) );
	msg->len = htons ( sizeof ( *msg ) - sizeof ( msg->hdr ) );
	DBGCP ( xcm, "XCM %s TX[%d] xve %s code %#02x\n", xcm->name,
		ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ),
		msg->code );
	DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) );

	/* Send virtual Ethernet message */
	if ( ( rc = xfer_deliver_raw ( &xcm->xfer, msg,
				       sizeof ( *msg ) ) ) != 0 ) {
		DBGC ( xcm, "XCM %s TX xve %s failed: %s\n", xcm->name,
		       xsmp_xve_type ( msg->type ), strerror ( rc ) );
		return rc;
	}

	return 0;
}

/**
 * Send virtual Ethernet message including current device parameters
 *
 * @v xcm		Configuration manager
 * @v msg		Partial virtual Ethernet message
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @ret rc		Return status code
 */
static int xsmp_tx_xve_params ( struct xsigo_manager *xcm,
				struct xsmp_xve_message *msg,
				struct xsigo_nic *xve,
				struct eoib_device *eoib ) {
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	struct net_device *netdev = eoib->netdev;

	/* Set successful response code */
	msg->code = 0;

	/* Include network identifier, MTU, and current HCA parameters */
	msg->network = htonl ( xve->network );
	msg->mtu = htons ( netdev->max_pkt_len - sizeof ( struct ethhdr ) );
	msg->hca.prefix_le.qword = bswap_64 ( ibdev->gid.s.prefix.qword );
	msg->hca.pkey = htons ( ibdev->pkey );
	msg->hca.qkey = msg->tca.qkey;
	if ( eoib->qp ) {
		msg->hca.data = htonl ( eoib->qp->ext_qpn );
		msg->hca.qkey = htons ( eoib->qp->qkey );
	}

	/* The message type field is (ab)used to return the current
	 * operational status.
	 */
	if ( msg->type == XSMP_XVE_TYPE_OPER_REQ ) {
		msg->type = ( netdev_is_open ( netdev ) ?
			      XSMP_XVE_TYPE_OPER_UP : XSMP_XVE_TYPE_OPER_DOWN );
	}

	/* Send message */
	DBGC ( xve, "XVE %s network %d MTU %d ctrl %#x data %#x qkey %#04x "
	       "%s\n", xve->name, ntohl ( msg->network ), ntohs ( msg->mtu ),
	       ntohl ( msg->hca.ctrl ), ntohl ( msg->hca.data ),
	       ntohs ( msg->hca.qkey ), xsmp_xve_type ( msg->type ) );

	return xsmp_tx_xve ( xcm, msg );
}

/**
 * Send virtual Ethernet error response
 *
 * @v xcm		Configuration manager
 * @v msg		Partial virtual Ethernet message
 * @ret rc		Return status code
 */
static inline int xsmp_tx_xve_nack ( struct xsigo_manager *xcm,
				     struct xsmp_xve_message *msg ) {

	/* Set error response code.  (There aren't any meaningful
	 * detailed response codes defined by the wire protocol.)
	 */
	msg->code = XSMP_XVE_CODE_ERROR;

	/* Send message */
	return xsmp_tx_xve ( xcm, msg );
}

/**
 * Send virtual Ethernet notification
 *
 * @v xcm		Configuration manager
 * @v type		Message type
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @ret rc		Return status code
 */
static int xsmp_tx_xve_notify ( struct xsigo_manager *xcm,
				unsigned int type,
				struct xsigo_nic *xve,
				struct eoib_device *eoib ) {
	struct xsmp_xve_message msg;

	/* Construct message */
	memset ( &msg, 0, sizeof ( msg ) );
	msg.type = type;
	memcpy ( &msg.resource, &xve->resource, sizeof ( msg.resource ) );

	/* Send message */
	return xsmp_tx_xve_params ( xcm, &msg, xve, eoib );
}

/**
 * Send virtual Ethernet current operational state
 *
 * @v xcm		Configuration manager
 * @v xve		Virtual Ethernet device
 * @v eoib		EoIB device
 * @ret rc		Return status code
 */
static inline int xsmp_tx_xve_oper ( struct xsigo_manager *xcm,
				     struct xsigo_nic *xve,
				     struct eoib_device *eoib ) {

	/* Send notification */
	return xsmp_tx_xve_notify ( xcm, XSMP_XVE_TYPE_OPER_REQ, xve, eoib );
}

/**
 * Handle received virtual Ethernet modification message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @v update		Update bitmask
 * @ret rc		Return status code
 */
static int xsmp_rx_xve_modify ( struct xsigo_manager *xcm,
				struct xsmp_xve_message *msg,
				unsigned int update ) {
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	struct xsigo_nic *xve;
	struct eoib_device *eoib;
	struct ib_address_vector tca;
	size_t mtu;
	int rc;

	/* Avoid returning uninitialised HCA parameters in response */
	memset ( &msg->hca, 0, sizeof ( msg->hca ) );

	/* Find virtual Ethernet device */
	xve = xve_find ( xcm, &msg->resource );
	if ( ! xve ) {
		DBGC ( xcm, "XCM %s unrecognised resource " IB_GUID_FMT "\n",
		       xcm->name, IB_GUID_ARGS ( &msg->resource ) );
		rc = -ENOENT;
		goto err_no_xve;
	}

	/* Find corresponding EoIB device */
	eoib = eoib_find ( ibdev, xve->mac );
	if ( ! eoib ) {
		DBGC ( xve, "XVE %s has no EoIB device\n", xve->name );
		rc = -EPIPE;
		goto err_no_eoib;
	}

	/* The Xsigo management software fails to create the EoIB
	 * multicast group.  This is a fundamental design flaw.
	 */
	eoib_force_group_creation ( eoib );

	/* Extract modifiable parameters.  Note that the TCA GID is
	 * erroneously transmitted as little-endian.
	 */
	mtu = ntohs ( msg->mtu );
	memset ( &tca, 0, sizeof ( tca ) );
	tca.qpn = ntohl ( msg->tca.data );
	tca.qkey = ntohs ( msg->tca.qkey );
	tca.gid_present = 1;
	tca.gid.s.prefix.qword = bswap_64 ( msg->tca.prefix_le.qword );
	tca.gid.s.guid.qword = bswap_64 ( msg->guid_le.qword );

	/* Update MTU, if applicable */
	if ( ( update & XSMP_XVE_UPDATE_MTU ) &&
	     ( ( rc = xve_update_mtu ( xve, eoib, mtu ) ) != 0 ) )
		goto err_mtu;
	update &= ~XSMP_XVE_UPDATE_MTU;

	/* Update admin state, if applicable */
	if ( ( update & XSMP_XVE_UPDATE_STATE ) &&
	     ( ( rc = xve_update_state ( xve, eoib, msg->state ) ) != 0 ) )
		goto err_state;
	update &= ~XSMP_XVE_UPDATE_STATE;

	/* Remove gateway, if applicable */
	if ( ( update & XSMP_XVE_UPDATE_GW_DOWN ) &&
	     ( ( rc = xve_update_tca ( xve, eoib, NULL ) ) != 0 ) )
		goto err_gw_down;
	update &= ~XSMP_XVE_UPDATE_GW_DOWN;

	/* Update gateway, if applicable */
	if ( ( update & XSMP_XVE_UPDATE_GW_CHANGE ) &&
	     ( ( rc = xve_update_tca ( xve, eoib, &tca ) ) != 0 ) )
		goto err_gw_change;
	update &= ~XSMP_XVE_UPDATE_GW_CHANGE;

	/* Warn about unexpected updates */
	if ( update ) {
		DBGC ( xve, "XVE %s unrecognised update(s) %#08x\n",
		       xve->name, update );
	}

	xsmp_tx_xve_params ( xcm, msg, xve, eoib );
	return 0;

 err_gw_change:
 err_gw_down:
 err_state:
 err_mtu:
 err_no_eoib:
 err_no_xve:
	/* Send NACK */
	xsmp_tx_xve_nack ( xcm, msg );
	return rc;
}

/**
 * Handle received virtual Ethernet installation message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @ret rc		Return status code
 */
static int xsmp_rx_xve_install ( struct xsigo_manager *xcm,
				 struct xsmp_xve_message *msg ) {
	union {
		struct xsmp_xve_mac msg;
		uint8_t raw[ETH_ALEN];
	} mac;
	char name[ sizeof ( msg->name ) + 1 /* NUL */ ];
	unsigned long network;
	unsigned long qkey;
	unsigned int update;
	int rc;

	/* Demangle MAC address (which is erroneously transmitted as
	 * little-endian).
	 */
	mac.msg.high = bswap_16 ( msg->mac_le.high );
	mac.msg.low = bswap_32 ( msg->mac_le.low );

	/* Extract interface name (which may not be NUL-terminated) */
	memcpy ( name, msg->name, ( sizeof ( name ) - 1 /* NUL */ ) );
	name[ sizeof ( name ) - 1 /* NUL */ ] = '\0';

	/* Extract remaining message parameters */
	network = ntohl ( msg->network );
	qkey = ntohs ( msg->tca.qkey );
	DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " install \"%s\" %s net %ld qkey "
		"%#lx\n", xcm->name, IB_GUID_ARGS ( &msg->resource ), name,
		eth_ntoa ( mac.raw ), network, qkey );

	/* Create virtual Ethernet device, if applicable */
	if ( ( xve_find ( xcm, &msg->resource ) == NULL ) &&
	     ( ( rc = xve_create ( xcm, &msg->resource, mac.raw, network,
				   qkey, name ) ) != 0 ) )
		goto err_create;

	/* Handle remaining parameters as for a modification message */
	update = XSMP_XVE_UPDATE_MTU;
	if ( msg->uplink == XSMP_XVE_UPLINK )
		update |= XSMP_XVE_UPDATE_GW_CHANGE;
	return xsmp_rx_xve_modify ( xcm, msg, update );

 err_create:
	/* Send NACK */
	xsmp_tx_xve_nack ( xcm, msg );
	return rc;
}

/**
 * Handle received virtual Ethernet deletion message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @ret rc		Return status code
 */
static int xsmp_rx_xve_delete ( struct xsigo_manager *xcm,
				struct xsmp_xve_message *msg ) {
	struct xsigo_nic *xve;

	DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " delete\n",
		xcm->name, IB_GUID_ARGS ( &msg->resource ) );

	/* Destroy virtual Ethernet device (if any) */
	if ( ( xve = xve_find ( xcm, &msg->resource ) ) )
		xve_destroy ( xve );

	/* Send ACK */
	msg->code = 0;
	xsmp_tx_xve ( xcm, msg );

	return 0;
}

/**
 * Handle received virtual Ethernet update message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @ret rc		Return status code
 */
static int xsmp_rx_xve_update ( struct xsigo_manager *xcm,
				struct xsmp_xve_message *msg ) {
	unsigned int update = ntohl ( msg->update );

	DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " update (%08x)\n",
		xcm->name, IB_GUID_ARGS ( &msg->resource ), update );

	/* Handle as a modification message */
	return xsmp_rx_xve_modify ( xcm, msg, update );
}

/**
 * Handle received virtual Ethernet operational request message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @ret rc		Return status code
 */
static int xsmp_rx_xve_oper_req ( struct xsigo_manager *xcm,
				  struct xsmp_xve_message *msg ) {

	DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " operational request\n",
		xcm->name, IB_GUID_ARGS ( &msg->resource ) );

	/* Handle as a nullipotent modification message */
	return xsmp_rx_xve_modify ( xcm, msg, 0 );
}

/**
 * Handle received virtual Ethernet readiness message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @ret rc		Return status code
 */
static int xsmp_rx_xve_ready ( struct xsigo_manager *xcm,
			       struct xsmp_xve_message *msg ) {
	int rc;

	DBGC2 ( xcm, "XCM %s " IB_GUID_FMT " ready\n",
		xcm->name, IB_GUID_ARGS ( &msg->resource ) );

	/* Handle as a nullipotent modification message */
	if ( ( rc = xsmp_rx_xve_modify ( xcm, msg, 0 ) ) != 0 )
		return rc;

	/* Send an unsolicited operational state update, since there
	 * is no other way to convey the current operational state.
	 */
	msg->type = XSMP_XVE_TYPE_OPER_REQ;
	if ( ( rc = xsmp_rx_xve_modify ( xcm, msg, 0 ) ) != 0 )
		return rc;

	return 0;
}

/**
 * Handle received virtual Ethernet message
 *
 * @v xcm		Configuration manager
 * @v msg		Virtual Ethernet message
 * @ret rc		Return status code
 */
static int xsmp_rx_xve ( struct xsigo_manager *xcm,
			 struct xsmp_xve_message *msg ) {

	DBGCP ( xcm, "XCM %s RX[%d] xve %s\n", xcm->name,
		ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ) );
	DBGCP_HDA ( xcm, 0, msg, sizeof ( *msg ) );

	/* Handle message according to type */
	switch ( msg->type ) {
	case XSMP_XVE_TYPE_INSTALL:
		return xsmp_rx_xve_install ( xcm, msg );
	case XSMP_XVE_TYPE_DELETE:
		return xsmp_rx_xve_delete ( xcm, msg );
	case XSMP_XVE_TYPE_UPDATE:
		return xsmp_rx_xve_update ( xcm, msg );
	case XSMP_XVE_TYPE_OPER_REQ:
		return xsmp_rx_xve_oper_req ( xcm, msg );
	case XSMP_XVE_TYPE_READY:
		return xsmp_rx_xve_ready ( xcm, msg );
	default:
		DBGC ( xcm, "XCM %s RX[%d] xve unexpected %s:\n", xcm->name,
		       ntohl ( msg->hdr.seq ), xsmp_xve_type ( msg->type ) );
		DBGC_HDA ( xcm, 0, msg, sizeof ( *msg ) );
		return -EPROTO;
	}
}

/****************************************************************************
 *
 * Configuration managers (XCM)
 *
 ****************************************************************************
 */

/**
 * Close configuration manager connection
 *
 * @v xcm		Configuration manager
 * @v rc		Reason for close
 */
static void xcm_close ( struct xsigo_manager *xcm, int rc ) {

	DBGC ( xcm, "XCM %s closed: %s\n", xcm->name, strerror ( rc ) );

	/* Stop transmission process */
	process_del ( &xcm->process );

	/* Stop keepalive timer */
	stop_timer ( &xcm->keepalive );

	/* Restart data transfer interface */
	intf_restart ( &xcm->xfer, rc );

	/* Schedule reconnection attempt */
	start_timer ( &xcm->reopen );
}

/**
 * Send data to configuration manager
 *
 * @v xcm		Configuration manager
 */
static void xcm_step ( struct xsigo_manager *xcm ) {
	int rc;

	/* Do nothing unless we have something to send */
	if ( ! xcm->pending )
		return;

	/* Send (empty) connection request, if applicable */
	if ( xcm->pending & XCM_TX_CONNECT ) {
		if ( ( rc = xfer_deliver_raw ( &xcm->xfer, NULL, 0 ) ) != 0 ) {
			DBGC ( xcm, "XCM %s could not send connection request: "
			       "%s\n", xcm->name, strerror ( rc ) );
			goto err;
		}
		xcm->pending &= ~XCM_TX_CONNECT;
		return;
	}

	/* Wait until data transfer interface is connected */
	if ( ! xfer_window ( &xcm->xfer ) )
		return;

	/* Send registration message, if applicable */
	if ( xcm->pending & XCM_TX_REGISTER ) {
		if ( ( rc = xsmp_tx_session_register ( xcm ) ) != 0 )
			goto err;
		xcm->pending &= ~XCM_TX_REGISTER;
		return;
	}

	return;

 err:
	xcm_close ( xcm, rc );
}

/**
 * Receive data from configuration manager
 *
 * @v xcm		Configuration manager
 * @v iobuf		I/O buffer
 * @v meta		Data transfer metadata
 * @ret rc		Return status code
 */
static int xcm_deliver ( struct xsigo_manager *xcm, struct io_buffer *iobuf,
			 struct xfer_metadata *meta __unused ) {
	union xsmp_message *msg;
	size_t len = iob_len ( iobuf );
	int rc;

	/* Sanity check */
	if ( len < sizeof ( msg->hdr ) ) {
		DBGC ( xcm, "XCM %s underlength message:\n", xcm->name );
		DBGC_HDA ( xcm, 0, iobuf->data, iob_len ( iobuf ) );
		rc = -EPROTO;
		goto out;
	}
	msg = iobuf->data;

	/* Handle message according to type */
	if ( ! msg->hdr.type ) {

		/* Ignore unused communication manager private data blocks */
		rc = 0;

	} else if ( ( msg->hdr.type == XSMP_TYPE_SESSION ) &&
		    ( len >= sizeof ( msg->sess ) ) ) {

		/* Session message */
		rc = xsmp_rx_session ( xcm, &msg->sess );

	} else if ( ( msg->hdr.type == XSMP_TYPE_XVE ) &&
		    ( len >= sizeof ( msg->xve ) ) ) {

		/* Virtual Ethernet message */
		xsmp_rx_xve ( xcm, &msg->xve );

		/* Virtual Ethernet message errors are non-fatal */
		rc = 0;

	} else {

		/* Unknown message */
		DBGC ( xcm, "XCM %s unexpected message type %d:\n",
		       xcm->name, msg->hdr.type );
		DBGC_HDA ( xcm, 0, iobuf->data, iob_len ( iobuf ) );
		rc = -EPROTO;
	}

 out:
	free_iob ( iobuf );
	if ( rc != 0 )
		xcm_close ( xcm, rc );
	return rc;
}

/** Configuration manager data transfer interface operations */
static struct interface_operation xcm_xfer_op[] = {
	INTF_OP ( xfer_deliver, struct xsigo_manager *, xcm_deliver ),
	INTF_OP ( xfer_window_changed, struct xsigo_manager *, xcm_step ),
	INTF_OP ( intf_close, struct xsigo_manager *, xcm_close ),
};

/** Configuration manager data transfer interface descriptor */
static struct interface_descriptor xcm_xfer_desc =
	INTF_DESC ( struct xsigo_manager, xfer, xcm_xfer_op );

/** Configuration manager process descriptor */
static struct process_descriptor xcm_process_desc =
	PROC_DESC_ONCE ( struct xsigo_manager, process, xcm_step );

/**
 * Handle configuration manager connection timer expiry
 *
 * @v timer		Connection timer
 * @v fail		Failure indicator
 */
static void xcm_reopen ( struct retry_timer *timer, int fail __unused ) {
	struct xsigo_manager *xcm =
		container_of ( timer, struct xsigo_manager, reopen );
	struct xsigo_device *xdev = xcm->xdev;
	struct ib_device *ibdev = xdev->ibdev;
	union ib_gid gid;
	int rc;

	/* Stop transmission process */
	process_del ( &xcm->process );

	/* Stop keepalive timer */
	stop_timer ( &xcm->keepalive );

	/* Restart data transfer interface */
	intf_restart ( &xcm->xfer, -ECANCELED );

	/* Reset sequence number */
	xcm->seq = 0;

	/* Construct GID */
	memcpy ( &gid.s.prefix, &ibdev->gid.s.prefix, sizeof ( gid.s.prefix ) );
	memcpy ( &gid.s.guid, &xcm->id.guid, sizeof ( gid.s.guid ) );
	DBGC ( xcm, "XCM %s connecting to " IB_GID_FMT "\n",
	       xcm->name, IB_GID_ARGS ( &gid ) );

	/* Open CMRC connection */
	if ( ( rc = ib_cmrc_open ( &xcm->xfer, ibdev, &gid,
				   &xcm_service_id, xcm->name ) ) != 0 ) {
		DBGC ( xcm, "XCM %s could not open CMRC connection: %s\n",
		       xcm->name, strerror ( rc ) );
		start_timer ( &xcm->reopen );
		return;
	}

	/* Schedule transmissions */
	xcm->pending |= ( XCM_TX_CONNECT | XCM_TX_REGISTER );
	process_add ( &xcm->process );

	/* Start keepalive timer */
	start_timer_fixed ( &xcm->keepalive, XSIGO_KEEPALIVE_INTERVAL );

	return;
}

/**
 * Handle configuration manager keepalive timer expiry
 *
 * @v timer		Connection timer
 * @v fail		Failure indicator
 */
static void xcm_keepalive ( struct retry_timer *timer, int fail __unused ) {
	struct xsigo_manager *xcm =
		container_of ( timer, struct xsigo_manager, keepalive );
	int rc;

	/* Send keepalive message.  The server won't actually respond
	 * to these, but it gives the RC queue pair a chance to
	 * complain if it doesn't ever at least get an ACK.
	 */
	if ( ( rc = xsmp_tx_session_hello ( xcm ) ) != 0 ) {
		xcm_close ( xcm, rc );
		return;
	}

	/* Restart keepalive timer */
	start_timer_fixed ( &xcm->keepalive, XSIGO_KEEPALIVE_INTERVAL );
}

/**
 * Create configuration manager
 *
 * @v xsigo		Xsigo device
 * @v id		Configuration manager ID
 * @ret rc		Return status code
 */
static int xcm_create ( struct xsigo_device *xdev,
			struct xsigo_manager_id *id ) {
	struct xsigo_manager *xcm;

	/* Allocate and initialise structure */
	xcm = zalloc ( sizeof ( *xcm ) );
	if ( ! xcm )
		return -ENOMEM;
	ref_init ( &xcm->refcnt, xcm_free );
	xcm->xdev = xdev;
	ref_get ( &xcm->xdev->refcnt );
	snprintf ( xcm->name, sizeof ( xcm->name ), "%s:xcm-%d",
		   xdev->name, ntohs ( id->lid ) );
	memcpy ( &xcm->id, id, sizeof ( xcm->id ) );
	intf_init ( &xcm->xfer, &xcm_xfer_desc, &xcm->refcnt );
	timer_init ( &xcm->keepalive, xcm_keepalive, &xcm->refcnt );
	timer_init ( &xcm->reopen, xcm_reopen, &xcm->refcnt );
	process_init_stopped ( &xcm->process, &xcm_process_desc, &xcm->refcnt );
	INIT_LIST_HEAD ( &xcm->nics );

	/* Start timer to open connection */
	start_timer_nodelay ( &xcm->reopen );

	/* Add to list of managers and transfer reference to list */
	list_add ( &xcm->list, &xdev->managers );
	DBGC ( xcm, "XCM %s created for " IB_GUID_FMT " (LID %d)\n", xcm->name,
	       IB_GUID_ARGS ( &xcm->id.guid ), ntohs ( id->lid ) );
	return 0;
}

/**
 * Find configuration manager
 *
 * @v xsigo		Xsigo device
 * @v id		Configuration manager ID
 * @ret xcm		Configuration manager, or NULL
 */
static struct xsigo_manager * xcm_find ( struct xsigo_device *xdev,
					 struct xsigo_manager_id *id ) {
	struct xsigo_manager *xcm;
	union ib_guid *guid = &id->guid;

	/* Find configuration manager */
	list_for_each_entry ( xcm, &xdev->managers, list ) {
		if ( memcmp ( guid, &xcm->id.guid, sizeof ( *guid ) ) == 0 )
			return xcm;
	}
	return NULL;
}

/**
 * Destroy configuration manager
 *
 * @v xcm		Configuration manager
 */
static void xcm_destroy ( struct xsigo_manager *xcm ) {
	struct xsigo_nic *xve;

	/* Remove all EoIB NICs */
	while ( ( xve = list_first_entry ( &xcm->nics, struct xsigo_nic,
					   list ) ) ) {
		xve_destroy ( xve );
	}

	/* Stop transmission process */
	process_del ( &xcm->process );

	/* Stop timers */
	stop_timer ( &xcm->keepalive );
	stop_timer ( &xcm->reopen );

	/* Shut down data transfer interface */
	intf_shutdown ( &xcm->xfer, 0 );

	/* Remove from list of managers and drop list's reference */
	DBGC ( xcm, "XCM %s destroyed\n", xcm->name );
	list_del ( &xcm->list );
	ref_put ( &xcm->refcnt );
}

/**
 * Synchronise list of configuration managers
 *
 * @v xdev		Xsigo device
 * @v ids		List of manager IDs
 * @v count		Number of manager IDs
 * @ret rc		Return status code
 */
static int xcm_list ( struct xsigo_device *xdev, struct xsigo_manager_id *ids,
		      unsigned int count ) {
	struct xsigo_manager_id *id;
	struct xsigo_manager *xcm;
	struct xsigo_manager *tmp;
	struct list_head list;
	unsigned int i;
	int rc;

	/* Create list of managers to be retained */
	INIT_LIST_HEAD ( &list );
	for ( i = 0, id = ids ; i < count ; i++, id++ ) {
		if ( ( xcm = xcm_find ( xdev, id ) ) ) {
			list_del ( &xcm->list );
			list_add_tail ( &xcm->list, &list );
		}
	}

	/* Destroy any managers not in the list */
	list_for_each_entry_safe ( xcm, tmp, &xdev->managers, list )
		xcm_destroy ( xcm );
	list_splice ( &list, &xdev->managers );

	/* Create any new managers in the list, and force reconnection
	 * for any changed LIDs.
	 */
	for ( i = 0, id = ids ; i < count ; i++, id++ ) {
		if ( ( xcm = xcm_find ( xdev, id ) ) ) {
			if ( xcm->id.lid != id->lid )
				start_timer_nodelay ( &xcm->reopen );
			continue;
		}
		if ( ( rc = xcm_create ( xdev, id ) ) != 0 ) {
			DBGC ( xdev, "XDEV %s could not create manager: %s\n",
			       xdev->name, strerror ( rc ) );
			return rc;
		}
	}

	return 0;
}

/****************************************************************************
 *
 * Configuration manager discovery
 *
 ****************************************************************************
 */

/** A stage of discovery */
struct xsigo_discovery {
	/** Name */
	const char *name;
	/** Management transaction operations */
	struct ib_mad_transaction_operations op;
};

/**
 * Handle configuration manager lookup completion
 *
 * @v ibdev		Infiniband device
 * @v mi		Management interface
 * @v madx		Management transaction
 * @v rc		Status code
 * @v mad		Received MAD (or NULL on error)
 * @v av		Source address vector (or NULL on error)
 */
static void xsigo_xcm_complete ( struct ib_device *ibdev,
				 struct ib_mad_interface *mi __unused,
				 struct ib_mad_transaction *madx,
				 int rc, union ib_mad *mad,
				 struct ib_address_vector *av __unused ) {
	struct xsigo_device *xdev = ib_madx_get_ownerdata ( madx );
	union xsigo_mad *xsmad = container_of ( mad, union xsigo_mad, mad );
	struct xsigo_managers_reply *reply = &xsmad->reply;

	/* Check for failures */
	if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) )
		rc = -ENODEV;
	if ( rc != 0 ) {
		DBGC ( xdev, "XDEV %s manager lookup failed: %s\n",
		       xdev->name, strerror ( rc ) );
		goto out;
	}

	/* Sanity checks */
	if ( reply->count > ( sizeof ( reply->manager ) /
			      sizeof ( reply->manager[0] ) ) ) {
		DBGC ( xdev, "XDEV %s has too many managers (%d)\n",
		       xdev->name, reply->count );
		goto out;
	}

	/* Synchronise list of managers */
	if ( ( rc = xcm_list ( xdev, reply->manager, reply->count ) ) != 0 )
		goto out;

	/* Report an empty list of managers */
	if ( reply->count == 0 )
		DBGC ( xdev, "XDEV %s has no managers\n", xdev->name );

	/* Delay next discovery attempt */
	start_timer_fixed ( &xdev->discovery, XSIGO_DISCOVERY_SUCCESS_DELAY );

out:
	/* Destroy the completed transaction */
	ib_destroy_madx ( ibdev, ibdev->gsi, madx );
	xdev->madx = NULL;
}

/** Configuration manager lookup discovery stage */
static struct xsigo_discovery xsigo_xcm_discovery = {
	.name = "manager",
	.op = {
		.complete = xsigo_xcm_complete,
	},
};

/**
 * Handle directory service lookup completion
 *
 * @v ibdev		Infiniband device
 * @v mi		Management interface
 * @v madx		Management transaction
 * @v rc		Status code
 * @v mad		Received MAD (or NULL on error)
 * @v av		Source address vector (or NULL on error)
 */
static void xsigo_xds_complete ( struct ib_device *ibdev,
				 struct ib_mad_interface *mi __unused,
				 struct ib_mad_transaction *madx,
				 int rc, union ib_mad *mad,
				 struct ib_address_vector *av __unused ) {
	struct xsigo_device *xdev = ib_madx_get_ownerdata ( madx );
	union xsigo_mad *xsmad = container_of ( mad, union xsigo_mad, mad );
	struct xsigo_managers_request *request = &xsmad->request;
	struct ib_service_record *svc;
	struct ib_address_vector dest;
	union ib_guid *guid;

	/* Allow for reuse of transaction pointer */
	xdev->madx = NULL;

	/* Check for failures */
	if ( ( rc == 0 ) && ( mad->hdr.status != htons ( IB_MGMT_STATUS_OK ) ) )
		rc = -ENODEV;
	if ( rc != 0 ) {
		DBGC ( xdev, "XDEV %s directory lookup failed: %s\n",
		       xdev->name, strerror ( rc ) );
		goto out;
	}

	/* Construct address vector */
	memset ( &dest, 0, sizeof ( dest ) );
	svc = &mad->sa.sa_data.service_record;
	dest.lid = ntohs ( svc->data16[0] );
	dest.sl = ibdev->sm_sl;
	dest.qpn = IB_QPN_GSI;
	dest.qkey = IB_QKEY_GSI;
	guid = ( ( union ib_guid * ) &svc->data64[0] );
	DBGC2 ( xdev, "XDEV %s found directory at LID %d GUID " IB_GUID_FMT
		"\n", xdev->name, dest.lid, IB_GUID_ARGS ( guid ) );

	/* Construct request (reusing MAD buffer) */
	memset ( request, 0, sizeof ( *request ) );
	request->mad_hdr.mgmt_class = XSIGO_MGMT_CLASS;
	request->mad_hdr.class_version = XSIGO_MGMT_CLASS_VERSION;
	request->mad_hdr.method = IB_MGMT_METHOD_GET;
	request->mad_hdr.attr_id = htons ( XSIGO_ATTR_XCM_REQUEST );
	memcpy ( &request->server.guid, &ibdev->gid.s.guid,
		 sizeof ( request->server.guid ) );
	snprintf ( request->os_version, sizeof ( request->os_version ),
		   "%s %s", product_short_name, product_version );
	snprintf ( request->arch, sizeof ( request->arch ), _S2 ( ARCH ) );
	request->os_type = XSIGO_OS_TYPE_GENERIC;
	request->resources = htons ( XSIGO_RESOURCES_PRESENT |
				     XSIGO_RESOURCE_XVE |
				     XSIGO_RESOURCE_NO_HA );

	/* The handling of this request on the server side is a
	 * textbook example of how not to design a wire protocol.  The
	 * server uses the _driver_ version number to determine which
	 * fields are present.
	 */
	request->driver_version = htonl ( 0x2a2a2a );

	/* The build version field is ignored unless it happens to
	 * contain the substring "xg-".
	 */
	snprintf ( request->build, sizeof ( request->build ),
		   "not-xg-%08lx", build_id );

	/* The server side user interface occasionally has no way to
	 * refer to an entry with an empty hostname.
	 */
	fetch_string_setting ( NULL, &hostname_setting, request->hostname,
			       sizeof ( request->hostname ) );
	if ( ! request->hostname[0] ) {
		snprintf ( request->hostname, sizeof ( request->hostname ),
			   "%s-" IB_GUID_FMT, product_short_name,
			   IB_GUID_ARGS ( &ibdev->gid.s.guid ) );
	}

	/* Start configuration manager lookup */
	xdev->madx = ib_create_madx ( ibdev, ibdev->gsi, mad, &dest,
				      &xsigo_xcm_discovery.op );
	if ( ! xdev->madx ) {
		DBGC ( xdev, "XDEV %s could not start manager lookup\n",
		       xdev->name );
		goto out;
	}
	ib_madx_set_ownerdata ( xdev->madx, xdev );

out:
	/* Destroy the completed transaction */
	ib_destroy_madx ( ibdev, ibdev->gsi, madx );
}

/** Directory service lookup discovery stage */
static struct xsigo_discovery xsigo_xds_discovery = {
	.name = "directory",
	.op = {
		.complete = xsigo_xds_complete,
	},
};

/**
 * Discover configuration managers
 *
 * @v timer		Retry timer
 * @v over		Failure indicator
 */
static void xsigo_discover ( struct retry_timer *timer, int over __unused ) {
	struct xsigo_device *xdev =
		container_of ( timer, struct xsigo_device, discovery );
	struct ib_device *ibdev = xdev->ibdev;
	struct xsigo_discovery *discovery;

	/* Restart timer */
	start_timer_fixed ( &xdev->discovery, XSIGO_DISCOVERY_FAILURE_DELAY );

	/* Cancel any pending discovery transaction */
	if ( xdev->madx ) {
		discovery = container_of ( xdev->madx->op,
					   struct xsigo_discovery, op );
		DBGC ( xdev, "XDEV %s timed out waiting for %s lookup\n",
		       xdev->name, discovery->name );
		ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx );
		xdev->madx = NULL;
	}

	/* Start directory service lookup */
	xdev->madx = ib_create_service_madx ( ibdev, ibdev->gsi,
					      XDS_SERVICE_NAME,
					      &xsigo_xds_discovery.op );
	if ( ! xdev->madx ) {
		DBGC ( xdev, "XDEV %s could not start directory lookup\n",
		       xdev->name );
		return;
	}
	ib_madx_set_ownerdata ( xdev->madx, xdev );
}

/****************************************************************************
 *
 * Infiniband device driver
 *
 ****************************************************************************
 */

/**
 * Open link and start discovery
 *
 * @v opener		Link opener
 * @v over		Failure indicator
 */
static void xsigo_ib_open ( struct retry_timer *opener, int over __unused ) {
	struct xsigo_device *xdev =
		container_of ( opener, struct xsigo_device, opener );
	struct ib_device *ibdev = xdev->ibdev;
	int rc;

	/* Open Infiniband device */
	if ( ( rc = ib_open ( ibdev ) ) != 0 ) {
		DBGC ( xdev, "XDEV %s could not open: %s\n",
		       xdev->name, strerror ( rc ) );
		/* Delay and try again */
		start_timer_fixed ( &xdev->opener, XSIGO_OPEN_RETRY_DELAY );
		return;
	}

	/* If link is already up, then start discovery */
	if ( ib_link_ok ( ibdev ) )
		start_timer_nodelay ( &xdev->discovery );
}

/**
 * Probe Xsigo device
 *
 * @v ibdev		Infiniband device
 * @ret rc		Return status code
 */
static int xsigo_ib_probe ( struct ib_device *ibdev ) {
	struct xsigo_device *xdev;

	/* Allocate and initialise structure */
	xdev = zalloc ( sizeof ( *xdev ) );
	if ( ! xdev )
		return -ENOMEM;
	ref_init ( &xdev->refcnt, xsigo_free );
	xdev->ibdev = ibdev_get ( ibdev );
	xdev->name = ibdev->name;
	timer_init ( &xdev->opener, xsigo_ib_open, &xdev->refcnt );
	timer_init ( &xdev->discovery, xsigo_discover, &xdev->refcnt );
	INIT_LIST_HEAD ( &xdev->managers );

	/* Start timer to open Infiniband device.  (We are currently
	 * within the Infiniband device probe callback list; opening
	 * the device here would have interesting side-effects.)
	 */
	start_timer_nodelay ( &xdev->opener );

	/* Add to list of devices and transfer reference to list */
	list_add_tail ( &xdev->list, &xsigo_devices );
	DBGC ( xdev, "XDEV %s created for " IB_GUID_FMT "\n",
	       xdev->name, IB_GUID_ARGS ( &ibdev->gid.s.guid ) );
	return 0;
}

/**
 * Handle device or link status change
 *
 * @v ibdev		Infiniband device
 */
static void xsigo_ib_notify ( struct ib_device *ibdev ) {
	struct xsigo_device *xdev;

	/* Stop/restart discovery on any attached devices */
	list_for_each_entry ( xdev, &xsigo_devices, list ) {

		/* Skip non-attached devices */
		if ( xdev->ibdev != ibdev )
			continue;

		/* Stop any ongoing discovery */
		if ( xdev->madx ) {
			ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx );
			xdev->madx = NULL;
		}
		stop_timer ( &xdev->discovery );

		/* If link is up, then start discovery */
		if ( ib_link_ok ( ibdev ) )
			start_timer_nodelay ( &xdev->discovery );
	}
}

/**
 * Remove Xsigo device
 *
 * @v ibdev		Infiniband device
 */
static void xsigo_ib_remove ( struct ib_device *ibdev ) {
	struct xsigo_device *xdev;
	struct xsigo_device *tmp;

	/* Remove any attached Xsigo devices */
	list_for_each_entry_safe ( xdev, tmp, &xsigo_devices, list ) {

		/* Skip non-attached devices */
		if ( xdev->ibdev != ibdev )
			continue;

		/* Stop any ongoing discovery */
		if ( xdev->madx ) {
			ib_destroy_madx ( ibdev, ibdev->gsi, xdev->madx );
			xdev->madx = NULL;
		}
		stop_timer ( &xdev->discovery );

		/* Destroy all configuration managers */
		xcm_list ( xdev, NULL, 0 );

		/* Close Infiniband device, if applicable */
		if ( ! timer_running ( &xdev->opener ) )
			ib_close ( xdev->ibdev );

		/* Stop link opener */
		stop_timer ( &xdev->opener );

		/* Remove from list of devices and drop list's reference */
		DBGC ( xdev, "XDEV %s destroyed\n", xdev->name );
		list_del ( &xdev->list );
		ref_put ( &xdev->refcnt );
	}
}

/** Xsigo Infiniband driver */
struct ib_driver xsigo_ib_driver __ib_driver = {
	.name = "Xsigo",
	.probe = xsigo_ib_probe,
	.notify = xsigo_ib_notify,
	.remove = xsigo_ib_remove,
};

/****************************************************************************
 *
 * Network device driver
 *
 ****************************************************************************
 */

/**
 * Handle device or link status change
 *
 * @v netdev		Network device
 * @v priv		Private data
 */
static void xsigo_net_notify ( struct net_device *netdev,
			       void *priv __unused ) {
	struct xsigo_device *xdev;
	struct ib_device *ibdev;
	struct xsigo_manager *xcm;
	struct xsigo_nic *xve;
	struct eoib_device *eoib;

	/* Send current operational state to XCM, if applicable */
	list_for_each_entry ( xdev, &xsigo_devices, list ) {
		ibdev = xdev->ibdev;
		list_for_each_entry ( xcm, &xdev->managers, list ) {
			list_for_each_entry ( xve, &xcm->nics, list ) {
				eoib = eoib_find ( ibdev, xve->mac );
				if ( ! eoib )
					continue;
				if ( eoib->netdev != netdev )
					continue;
				xsmp_tx_xve_oper ( xcm, xve, eoib );
			}
		}
	}
}

/** Xsigo network driver */
struct net_driver xsigo_net_driver __net_driver = {
	.name = "Xsigo",
	.notify = xsigo_net_notify,
};