ソースを参照

[Infiniband] Add preliminary support for multi-port devices.

Arbel and Hermon cards both have multiple ports.  Add the
infrastructure required to register each port as a separate IB
device.  Don't yet register more than one port, since registration
will currently fail unless a valid link is detected.

Use ib_*_{set,get}_{drv,owner}data wrappers to access driver- and
owner-private data on Infiniband structures.
tags/v0.9.4
Michael Brown 16年前
コミット
bc3f0a25c6

+ 67
- 48
src/drivers/infiniband/arbel.c ファイルの表示

@@ -43,9 +43,6 @@
43 43
  *
44 44
  */
45 45
 
46
-/* Port to use */
47
-#define PXE_IB_PORT 1
48
-
49 46
 /***************************************************************************
50 47
  *
51 48
  * Queue number allocation
@@ -482,7 +479,7 @@ arbel_cmd_map_fa ( struct arbel *arbel,
482 479
  */
483 480
 static int arbel_create_cq ( struct ib_device *ibdev,
484 481
 			     struct ib_completion_queue *cq ) {
485
-	struct arbel *arbel = ibdev->dev_priv;
482
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
486 483
 	struct arbel_completion_queue *arbel_cq;
487 484
 	struct arbelprm_completion_queue_context cqctx;
488 485
 	struct arbelprm_cq_ci_db_record *ci_db_rec;
@@ -560,7 +557,7 @@ static int arbel_create_cq ( struct ib_device *ibdev,
560 557
 	DBGC ( arbel, "Arbel %p CQN %#lx ring at [%p,%p)\n",
561 558
 	       arbel, cq->cqn, arbel_cq->cqe,
562 559
 	       ( ( ( void * ) arbel_cq->cqe ) + arbel_cq->cqe_size ) );
563
-	cq->dev_priv = arbel_cq;
560
+	ib_cq_set_drvdata ( cq, arbel_cq );
564 561
 	return 0;
565 562
 
566 563
  err_sw2hw_cq:
@@ -583,8 +580,8 @@ static int arbel_create_cq ( struct ib_device *ibdev,
583 580
  */
584 581
 static void arbel_destroy_cq ( struct ib_device *ibdev,
585 582
 			       struct ib_completion_queue *cq ) {
586
-	struct arbel *arbel = ibdev->dev_priv;
587
-	struct arbel_completion_queue *arbel_cq = cq->dev_priv;
583
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
584
+	struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
588 585
 	struct arbelprm_completion_queue_context cqctx;
589 586
 	struct arbelprm_cq_ci_db_record *ci_db_rec;
590 587
 	struct arbelprm_cq_arm_db_record *arm_db_rec;
@@ -613,7 +610,7 @@ static void arbel_destroy_cq ( struct ib_device *ibdev,
613 610
 	cqn_offset = ( cq->cqn - arbel->limits.reserved_cqs );
614 611
 	arbel_free_qn_offset ( arbel->cq_inuse, cqn_offset );
615 612
 
616
-	cq->dev_priv = NULL;
613
+	ib_cq_set_drvdata ( cq, NULL );
617 614
 }
618 615
 
619 616
 /***************************************************************************
@@ -712,7 +709,7 @@ static int arbel_create_recv_wq ( struct arbel_recv_work_queue *arbel_recv_wq,
712 709
  */
713 710
 static int arbel_create_qp ( struct ib_device *ibdev,
714 711
 			     struct ib_queue_pair *qp ) {
715
-	struct arbel *arbel = ibdev->dev_priv;
712
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
716 713
 	struct arbel_queue_pair *arbel_qp;
717 714
 	struct arbelprm_qp_ee_state_transitions qpctx;
718 715
 	struct arbelprm_qp_db_record *send_db_rec;
@@ -819,7 +816,7 @@ static int arbel_create_qp ( struct ib_device *ibdev,
819 816
 	DBGC ( arbel, "Arbel %p QPN %#lx receive ring at [%p,%p)\n",
820 817
 	       arbel, qp->qpn, arbel_qp->recv.wqe,
821 818
 	       ( ( (void *) arbel_qp->recv.wqe ) + arbel_qp->recv.wqe_size ) );
822
-	qp->dev_priv = arbel_qp;
819
+	ib_qp_set_drvdata ( qp, arbel_qp );
823 820
 	return 0;
824 821
 
825 822
  err_rtr2rts_qpee:
@@ -847,8 +844,8 @@ static int arbel_create_qp ( struct ib_device *ibdev,
847 844
  */
848 845
 static void arbel_destroy_qp ( struct ib_device *ibdev,
849 846
 			       struct ib_queue_pair *qp ) {
850
-	struct arbel *arbel = ibdev->dev_priv;
851
-	struct arbel_queue_pair *arbel_qp = qp->dev_priv;
847
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
848
+	struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
852 849
 	struct arbelprm_qp_db_record *send_db_rec;
853 850
 	struct arbelprm_qp_db_record *recv_db_rec;
854 851
 	int qpn_offset;
@@ -877,7 +874,7 @@ static void arbel_destroy_qp ( struct ib_device *ibdev,
877 874
 	qpn_offset = ( qp->qpn - ARBEL_QPN_BASE - arbel->limits.reserved_qps );
878 875
 	arbel_free_qn_offset ( arbel->qp_inuse, qpn_offset );
879 876
 
880
-	qp->dev_priv = NULL;
877
+	ib_qp_set_drvdata ( qp, NULL );
881 878
 }
882 879
 
883 880
 /***************************************************************************
@@ -926,8 +923,8 @@ static int arbel_post_send ( struct ib_device *ibdev,
926 923
 			     struct ib_queue_pair *qp,
927 924
 			     struct ib_address_vector *av,
928 925
 			     struct io_buffer *iobuf ) {
929
-	struct arbel *arbel = ibdev->dev_priv;
930
-	struct arbel_queue_pair *arbel_qp = qp->dev_priv;
926
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
927
+	struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
931 928
 	struct ib_work_queue *wq = &qp->send;
932 929
 	struct arbel_send_work_queue *arbel_send_wq = &arbel_qp->send;
933 930
 	struct arbelprm_ud_send_wqe *prev_wqe;
@@ -1016,8 +1013,8 @@ static int arbel_post_send ( struct ib_device *ibdev,
1016 1013
 static int arbel_post_recv ( struct ib_device *ibdev,
1017 1014
 			     struct ib_queue_pair *qp,
1018 1015
 			     struct io_buffer *iobuf ) {
1019
-	struct arbel *arbel = ibdev->dev_priv;
1020
-	struct arbel_queue_pair *arbel_qp = qp->dev_priv;
1016
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1017
+	struct arbel_queue_pair *arbel_qp = ib_qp_get_drvdata ( qp );
1021 1018
 	struct ib_work_queue *wq = &qp->recv;
1022 1019
 	struct arbel_recv_work_queue *arbel_recv_wq = &arbel_qp->recv;
1023 1020
 	struct arbelprm_recv_wqe *wqe;
@@ -1066,7 +1063,7 @@ static int arbel_complete ( struct ib_device *ibdev,
1066 1063
 			    union arbelprm_completion_entry *cqe,
1067 1064
 			    ib_completer_t complete_send,
1068 1065
 			    ib_completer_t complete_recv ) {
1069
-	struct arbel *arbel = ibdev->dev_priv;
1066
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1070 1067
 	struct ib_completion completion;
1071 1068
 	struct ib_work_queue *wq;
1072 1069
 	struct ib_queue_pair *qp;
@@ -1108,7 +1105,7 @@ static int arbel_complete ( struct ib_device *ibdev,
1108 1105
 		return -EIO;
1109 1106
 	}
1110 1107
 	qp = wq->qp;
1111
-	arbel_qp = qp->dev_priv;
1108
+	arbel_qp = ib_qp_get_drvdata ( qp );
1112 1109
 	arbel_send_wq = &arbel_qp->send;
1113 1110
 	arbel_recv_wq = &arbel_qp->recv;
1114 1111
 
@@ -1170,8 +1167,8 @@ static void arbel_poll_cq ( struct ib_device *ibdev,
1170 1167
 			    struct ib_completion_queue *cq,
1171 1168
 			    ib_completer_t complete_send,
1172 1169
 			    ib_completer_t complete_recv ) {
1173
-	struct arbel *arbel = ibdev->dev_priv;
1174
-	struct arbel_completion_queue *arbel_cq = cq->dev_priv;
1170
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1171
+	struct arbel_completion_queue *arbel_cq = ib_cq_get_drvdata ( cq );
1175 1172
 	struct arbelprm_cq_ci_db_record *ci_db_rec;
1176 1173
 	union arbelprm_completion_entry *cqe;
1177 1174
 	unsigned int cqe_idx_mask;
@@ -1220,7 +1217,7 @@ static void arbel_poll_cq ( struct ib_device *ibdev,
1220 1217
  * @ret rc		Return status code
1221 1218
  */
1222 1219
 static int arbel_open ( struct ib_device *ibdev ) {
1223
-	struct arbel *arbel = ibdev->dev_priv;
1220
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1224 1221
 	struct arbelprm_init_ib init_ib;
1225 1222
 	int rc;
1226 1223
 
@@ -1247,7 +1244,7 @@ static int arbel_open ( struct ib_device *ibdev ) {
1247 1244
  * @v ibdev		Infiniband device
1248 1245
  */
1249 1246
 static void arbel_close ( struct ib_device *ibdev ) {
1250
-	struct arbel *arbel = ibdev->dev_priv;
1247
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1251 1248
 	int rc;
1252 1249
 
1253 1250
 	if ( ( rc = arbel_cmd_close_ib ( arbel, ibdev->port ) ) != 0 ) {
@@ -1275,7 +1272,7 @@ static void arbel_close ( struct ib_device *ibdev ) {
1275 1272
 static int arbel_mcast_attach ( struct ib_device *ibdev,
1276 1273
 				struct ib_queue_pair *qp,
1277 1274
 				struct ib_gid *gid ) {
1278
-	struct arbel *arbel = ibdev->dev_priv;
1275
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1279 1276
 	struct arbelprm_mgm_hash hash;
1280 1277
 	struct arbelprm_mgm_entry mgm;
1281 1278
 	unsigned int index;
@@ -1330,7 +1327,7 @@ static int arbel_mcast_attach ( struct ib_device *ibdev,
1330 1327
 static void arbel_mcast_detach ( struct ib_device *ibdev,
1331 1328
 				 struct ib_queue_pair *qp __unused,
1332 1329
 				 struct ib_gid *gid ) {
1333
-	struct arbel *arbel = ibdev->dev_priv;
1330
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1334 1331
 	struct arbelprm_mgm_hash hash;
1335 1332
 	struct arbelprm_mgm_entry mgm;
1336 1333
 	unsigned int index;
@@ -1370,7 +1367,7 @@ static void arbel_mcast_detach ( struct ib_device *ibdev,
1370 1367
  */
1371 1368
 static int arbel_mad ( struct ib_device *ibdev, struct ib_mad_hdr *mad,
1372 1369
 		       size_t len ) {
1373
-	struct arbel *arbel = ibdev->dev_priv;
1370
+	struct arbel *arbel = ib_get_drvdata ( ibdev );
1374 1371
 	union arbelprm_mad mad_ifc;
1375 1372
 	int rc;
1376 1373
 
@@ -1837,23 +1834,33 @@ static int arbel_setup_mpt ( struct arbel *arbel ) {
1837 1834
  */
1838 1835
 static int arbel_probe ( struct pci_device *pci,
1839 1836
 			 const struct pci_device_id *id __unused ) {
1840
-	struct ib_device *ibdev;
1841 1837
 	struct arbel *arbel;
1838
+	struct ib_device *ibdev;
1842 1839
 	struct arbelprm_init_hca init_hca;
1840
+	int i;
1843 1841
 	int rc;
1844 1842
 
1845
-	/* Allocate Infiniband device */
1846
-	ibdev = alloc_ibdev ( sizeof ( *arbel ) );
1847
-	if ( ! ibdev ) {
1843
+	/* Allocate Arbel device */
1844
+	arbel = zalloc ( sizeof ( *arbel ) );
1845
+	if ( ! arbel ) {
1848 1846
 		rc = -ENOMEM;
1849
-		goto err_ibdev;
1847
+		goto err_alloc_arbel;
1848
+	}
1849
+	pci_set_drvdata ( pci, arbel );
1850
+
1851
+	/* Allocate Infiniband devices */
1852
+	for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
1853
+		ibdev = alloc_ibdev ( 0 );
1854
+		if ( ! ibdev ) {
1855
+			rc = -ENOMEM;
1856
+			goto err_alloc_ibdev;
1857
+		}
1858
+		arbel->ibdev[i] = ibdev;
1859
+		ibdev->op = &arbel_ib_operations;
1860
+		ibdev->dev = &pci->dev;
1861
+		ibdev->port = ( ARBEL_PORT_BASE + i );
1862
+		ib_set_drvdata ( ibdev, arbel );
1850 1863
 	}
1851
-	ibdev->op = &arbel_ib_operations;
1852
-	pci_set_drvdata ( pci, ibdev );
1853
-	ibdev->dev = &pci->dev;
1854
-	ibdev->port = PXE_IB_PORT;
1855
-	arbel = ibdev->dev_priv;
1856
-	memset ( arbel, 0, sizeof ( *arbel ) );
1857 1864
 
1858 1865
 	/* Fix up PCI device */
1859 1866
 	adjust_pci_device ( pci );
@@ -1902,16 +1909,21 @@ static int arbel_probe ( struct pci_device *pci,
1902 1909
 	if ( ( rc = arbel_setup_mpt ( arbel ) ) != 0 )
1903 1910
 		goto err_setup_mpt;
1904 1911
 
1905
-	/* Register Infiniband device */
1906
-	if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
1907
-		DBGC ( arbel, "Arbel %p could not register IB device: %s\n",
1908
-		       arbel, strerror ( rc ) );
1909
-		goto err_register_ibdev;
1912
+	/* Register Infiniband devices */
1913
+	for ( i = 0 ; i < ARBEL_NUM_PORTS ; i++ ) {
1914
+		if ( ( rc = register_ibdev ( arbel->ibdev[i] ) ) != 0 ) {
1915
+			DBGC ( arbel, "Arbel %p could not register IB "
1916
+			       "device: %s\n", arbel, strerror ( rc ) );
1917
+			goto err_register_ibdev;
1918
+		}
1910 1919
 	}
1911 1920
 
1912 1921
 	return 0;
1913 1922
 
1923
+	i = ( ARBEL_NUM_PORTS - 1 );
1914 1924
  err_register_ibdev:
1925
+	for ( ; i >= 0 ; i-- )
1926
+		unregister_ibdev ( arbel->ibdev[i] );
1915 1927
  err_setup_mpt:
1916 1928
 	arbel_cmd_close_hca ( arbel );
1917 1929
  err_init_hca:
@@ -1924,8 +1936,12 @@ static int arbel_probe ( struct pci_device *pci,
1924 1936
  err_mailbox_out:
1925 1937
 	free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
1926 1938
  err_mailbox_in:
1927
-	free_ibdev ( ibdev );
1928
- err_ibdev:
1939
+	i = ( ARBEL_NUM_PORTS - 1 );
1940
+ err_alloc_ibdev:
1941
+	for ( ; i >= 0 ; i-- )
1942
+		free_ibdev ( arbel->ibdev[i] );
1943
+	free ( arbel );
1944
+ err_alloc_arbel:
1929 1945
 	return rc;
1930 1946
 }
1931 1947
 
@@ -1935,17 +1951,20 @@ static int arbel_probe ( struct pci_device *pci,
1935 1951
  * @v pci		PCI device
1936 1952
  */
1937 1953
 static void arbel_remove ( struct pci_device *pci ) {
1938
-	struct ib_device *ibdev = pci_get_drvdata ( pci );
1939
-	struct arbel *arbel = ibdev->dev_priv;
1954
+	struct arbel *arbel = pci_get_drvdata ( pci );
1955
+	int i;
1940 1956
 
1941
-	unregister_ibdev ( ibdev );
1957
+	for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
1958
+		unregister_ibdev ( arbel->ibdev[i] );
1942 1959
 	arbel_cmd_close_hca ( arbel );
1943 1960
 	arbel_free_icm ( arbel );
1944 1961
 	arbel_stop_firmware ( arbel );
1945 1962
 	arbel_stop_firmware ( arbel );
1946 1963
 	free_dma ( arbel->mailbox_out, ARBEL_MBOX_SIZE );
1947 1964
 	free_dma ( arbel->mailbox_in, ARBEL_MBOX_SIZE );
1948
-	free_ibdev ( ibdev );
1965
+	for ( i = ( ARBEL_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
1966
+		free_ibdev ( arbel->ibdev[i] );
1967
+	free ( arbel );
1949 1968
 }
1950 1969
 
1951 1970
 static struct pci_device_id arbel_nics[] = {

+ 7
- 0
src/drivers/infiniband/arbel.h ファイルの表示

@@ -17,6 +17,10 @@
17 17
  *
18 18
  */
19 19
 
20
+/* Ports in existence */
21
+#define ARBEL_NUM_PORTS			1
22
+#define ARBEL_PORT_BASE			1
23
+
20 24
 /* PCI BARs */
21 25
 #define ARBEL_PCI_CONFIG_BAR		PCI_BASE_ADDRESS_0
22 26
 #define ARBEL_PCI_CONFIG_BAR_SIZE	0x100000
@@ -344,6 +348,9 @@ struct arbel {
344 348
 	
345 349
 	/** Device limits */
346 350
 	struct arbel_dev_limits limits;
351
+
352
+	/** Infiniband devices */
353
+	struct ib_device *ibdev[ARBEL_NUM_PORTS];
347 354
 };
348 355
 
349 356
 /** Global protection domain */

+ 67
- 48
src/drivers/infiniband/hermon.c ファイルの表示

@@ -41,9 +41,6 @@
41 41
  *
42 42
  */
43 43
 
44
-/* Port to use */
45
-#define PXE_IB_PORT 1
46
-
47 44
 /***************************************************************************
48 45
  *
49 46
  * Queue number allocation
@@ -599,7 +596,7 @@ static void hermon_free_mtt ( struct hermon *hermon,
599 596
  */
600 597
 static int hermon_create_cq ( struct ib_device *ibdev,
601 598
 			      struct ib_completion_queue *cq ) {
602
-	struct hermon *hermon = ibdev->dev_priv;
599
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
603 600
 	struct hermon_completion_queue *hermon_cq;
604 601
 	struct hermonprm_completion_queue_context cqctx;
605 602
 	int cqn_offset;
@@ -665,7 +662,7 @@ static int hermon_create_cq ( struct ib_device *ibdev,
665 662
 	DBGC ( hermon, "Hermon %p CQN %#lx ring at [%p,%p)\n",
666 663
 	       hermon, cq->cqn, hermon_cq->cqe,
667 664
 	       ( ( ( void * ) hermon_cq->cqe ) + hermon_cq->cqe_size ) );
668
-	cq->dev_priv = hermon_cq;
665
+	ib_cq_set_drvdata ( cq, hermon_cq );
669 666
 	return 0;
670 667
 
671 668
  err_sw2hw_cq:
@@ -688,8 +685,8 @@ static int hermon_create_cq ( struct ib_device *ibdev,
688 685
  */
689 686
 static void hermon_destroy_cq ( struct ib_device *ibdev,
690 687
 				struct ib_completion_queue *cq ) {
691
-	struct hermon *hermon = ibdev->dev_priv;
692
-	struct hermon_completion_queue *hermon_cq = cq->dev_priv;
688
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
689
+	struct hermon_completion_queue *hermon_cq = ib_cq_get_drvdata ( cq );
693 690
 	struct hermonprm_completion_queue_context cqctx;
694 691
 	int cqn_offset;
695 692
 	int rc;
@@ -713,7 +710,7 @@ static void hermon_destroy_cq ( struct ib_device *ibdev,
713 710
 	cqn_offset = ( cq->cqn - hermon->cap.reserved_cqs );
714 711
 	hermon_bitmask_free ( hermon->cq_inuse, cqn_offset, 1 );
715 712
 
716
-	cq->dev_priv = NULL;
713
+	ib_cq_set_drvdata ( cq, NULL );
717 714
 }
718 715
 
719 716
 /***************************************************************************
@@ -732,7 +729,7 @@ static void hermon_destroy_cq ( struct ib_device *ibdev,
732 729
  */
733 730
 static int hermon_create_qp ( struct ib_device *ibdev,
734 731
 			      struct ib_queue_pair *qp ) {
735
-	struct hermon *hermon = ibdev->dev_priv;
732
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
736 733
 	struct hermon_queue_pair *hermon_qp;
737 734
 	struct hermonprm_qp_ee_state_transitions qpctx;
738 735
 	int qpn_offset;
@@ -845,7 +842,7 @@ static int hermon_create_qp ( struct ib_device *ibdev,
845 842
 	DBGC ( hermon, "Hermon %p QPN %#lx receive ring at [%p,%p)\n",
846 843
 	       hermon, qp->qpn, hermon_qp->recv.wqe,
847 844
 	       ( ((void *)hermon_qp->recv.wqe ) + hermon_qp->recv.wqe_size ) );
848
-	qp->dev_priv = hermon_qp;
845
+	ib_qp_set_drvdata ( qp, hermon_qp );
849 846
 	return 0;
850 847
 
851 848
  err_rtr2rts_qp:
@@ -871,8 +868,8 @@ static int hermon_create_qp ( struct ib_device *ibdev,
871 868
  */
872 869
 static void hermon_destroy_qp ( struct ib_device *ibdev,
873 870
 				struct ib_queue_pair *qp ) {
874
-	struct hermon *hermon = ibdev->dev_priv;
875
-	struct hermon_queue_pair *hermon_qp = qp->dev_priv;
871
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
872
+	struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
876 873
 	int qpn_offset;
877 874
 	int rc;
878 875
 
@@ -896,7 +893,7 @@ static void hermon_destroy_qp ( struct ib_device *ibdev,
896 893
 		       hermon->cap.reserved_qps );
897 894
 	hermon_bitmask_free ( hermon->qp_inuse, qpn_offset, 1 );
898 895
 
899
-	qp->dev_priv = NULL;
896
+	ib_qp_set_drvdata ( qp, NULL );
900 897
 }
901 898
 
902 899
 /***************************************************************************
@@ -924,8 +921,8 @@ static int hermon_post_send ( struct ib_device *ibdev,
924 921
 			      struct ib_queue_pair *qp,
925 922
 			      struct ib_address_vector *av,
926 923
 			      struct io_buffer *iobuf ) {
927
-	struct hermon *hermon = ibdev->dev_priv;
928
-	struct hermon_queue_pair *hermon_qp = qp->dev_priv;
924
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
925
+	struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
929 926
 	struct ib_work_queue *wq = &qp->send;
930 927
 	struct hermon_send_work_queue *hermon_send_wq = &hermon_qp->send;
931 928
 	struct hermonprm_ud_send_wqe *wqe;
@@ -1000,8 +997,8 @@ static int hermon_post_send ( struct ib_device *ibdev,
1000 997
 static int hermon_post_recv ( struct ib_device *ibdev,
1001 998
 			      struct ib_queue_pair *qp,
1002 999
 			      struct io_buffer *iobuf ) {
1003
-	struct hermon *hermon = ibdev->dev_priv;
1004
-	struct hermon_queue_pair *hermon_qp = qp->dev_priv;
1000
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1001
+	struct hermon_queue_pair *hermon_qp = ib_qp_get_drvdata ( qp );
1005 1002
 	struct ib_work_queue *wq = &qp->recv;
1006 1003
 	struct hermon_recv_work_queue *hermon_recv_wq = &hermon_qp->recv;
1007 1004
 	struct hermonprm_recv_wqe *wqe;
@@ -1048,7 +1045,7 @@ static int hermon_complete ( struct ib_device *ibdev,
1048 1045
 			     union hermonprm_completion_entry *cqe,
1049 1046
 			     ib_completer_t complete_send,
1050 1047
 			     ib_completer_t complete_recv ) {
1051
-	struct hermon *hermon = ibdev->dev_priv;
1048
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1052 1049
 	struct ib_completion completion;
1053 1050
 	struct ib_work_queue *wq;
1054 1051
 	struct ib_queue_pair *qp;
@@ -1085,7 +1082,7 @@ static int hermon_complete ( struct ib_device *ibdev,
1085 1082
 		return -EIO;
1086 1083
 	}
1087 1084
 	qp = wq->qp;
1088
-	hermon_qp = qp->dev_priv;
1085
+	hermon_qp = ib_qp_get_drvdata ( qp );
1089 1086
 
1090 1087
 	/* Identify I/O buffer */
1091 1088
 	wqe_idx = ( MLX_GET ( &cqe->normal, wqe_counter ) &
@@ -1128,8 +1125,8 @@ static void hermon_poll_cq ( struct ib_device *ibdev,
1128 1125
 			     struct ib_completion_queue *cq,
1129 1126
 			     ib_completer_t complete_send,
1130 1127
 			     ib_completer_t complete_recv ) {
1131
-	struct hermon *hermon = ibdev->dev_priv;
1132
-	struct hermon_completion_queue *hermon_cq = cq->dev_priv;
1128
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1129
+	struct hermon_completion_queue *hermon_cq = ib_cq_get_drvdata ( cq );
1133 1130
 	union hermonprm_completion_entry *cqe;
1134 1131
 	unsigned int cqe_idx_mask;
1135 1132
 	int rc;
@@ -1177,7 +1174,7 @@ static void hermon_poll_cq ( struct ib_device *ibdev,
1177 1174
  * @ret rc		Return status code
1178 1175
  */
1179 1176
 static int hermon_open ( struct ib_device *ibdev ) {
1180
-	struct hermon *hermon = ibdev->dev_priv;
1177
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1181 1178
 	struct hermonprm_init_port init_port;
1182 1179
 	int rc;
1183 1180
 
@@ -1205,7 +1202,7 @@ static int hermon_open ( struct ib_device *ibdev ) {
1205 1202
  * @v ibdev		Infiniband device
1206 1203
  */
1207 1204
 static void hermon_close ( struct ib_device *ibdev ) {
1208
-	struct hermon *hermon = ibdev->dev_priv;
1205
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1209 1206
 	int rc;
1210 1207
 
1211 1208
 	if ( ( rc = hermon_cmd_close_port ( hermon, ibdev->port ) ) != 0 ) {
@@ -1233,7 +1230,7 @@ static void hermon_close ( struct ib_device *ibdev ) {
1233 1230
 static int hermon_mcast_attach ( struct ib_device *ibdev,
1234 1231
 				 struct ib_queue_pair *qp,
1235 1232
 				 struct ib_gid *gid ) {
1236
-	struct hermon *hermon = ibdev->dev_priv;
1233
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1237 1234
 	struct hermonprm_mgm_hash hash;
1238 1235
 	struct hermonprm_mcg_entry mcg;
1239 1236
 	unsigned int index;
@@ -1287,7 +1284,7 @@ static int hermon_mcast_attach ( struct ib_device *ibdev,
1287 1284
 static void hermon_mcast_detach ( struct ib_device *ibdev,
1288 1285
 				  struct ib_queue_pair *qp __unused,
1289 1286
 				  struct ib_gid *gid ) {
1290
-	struct hermon *hermon = ibdev->dev_priv;
1287
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1291 1288
 	struct hermonprm_mgm_hash hash;
1292 1289
 	struct hermonprm_mcg_entry mcg;
1293 1290
 	unsigned int index;
@@ -1327,7 +1324,7 @@ static void hermon_mcast_detach ( struct ib_device *ibdev,
1327 1324
  */
1328 1325
 static int hermon_mad ( struct ib_device *ibdev, struct ib_mad_hdr *mad,
1329 1326
 			size_t len ) {
1330
-	struct hermon *hermon = ibdev->dev_priv;
1327
+	struct hermon *hermon = ib_get_drvdata ( ibdev );
1331 1328
 	union hermonprm_mad mad_ifc;
1332 1329
 	int rc;
1333 1330
 
@@ -1870,23 +1867,33 @@ static int hermon_setup_mpt ( struct hermon *hermon ) {
1870 1867
  */
1871 1868
 static int hermon_probe ( struct pci_device *pci,
1872 1869
 			  const struct pci_device_id *id __unused ) {
1873
-	struct ib_device *ibdev;
1874 1870
 	struct hermon *hermon;
1871
+	struct ib_device *ibdev;
1875 1872
 	struct hermonprm_init_hca init_hca;
1873
+	int i;
1876 1874
 	int rc;
1877 1875
 
1878
-	/* Allocate Infiniband device */
1879
-	ibdev = alloc_ibdev ( sizeof ( *hermon ) );
1880
-	if ( ! ibdev ) {
1876
+	/* Allocate Hermon device */
1877
+	hermon = zalloc ( sizeof ( *hermon ) );
1878
+	if ( ! hermon ) {
1881 1879
 		rc = -ENOMEM;
1882
-		goto err_ibdev;
1880
+		goto err_alloc_hermon;
1881
+	}
1882
+	pci_set_drvdata ( pci, hermon );
1883
+
1884
+	/* Allocate Infiniband devices */
1885
+	for ( i = 0 ; i < HERMON_NUM_PORTS ; i++ ) {
1886
+	        ibdev = alloc_ibdev ( 0 );
1887
+		if ( ! ibdev ) {
1888
+			rc = -ENOMEM;
1889
+			goto err_alloc_ibdev;
1890
+		}
1891
+		hermon->ibdev[i] = ibdev;
1892
+		ibdev->op = &hermon_ib_operations;
1893
+		ibdev->dev = &pci->dev;
1894
+		ibdev->port = ( HERMON_PORT_BASE + i );
1895
+		ib_set_drvdata ( ibdev, hermon );
1883 1896
 	}
1884
-	ibdev->op = &hermon_ib_operations;
1885
-	pci_set_drvdata ( pci, ibdev );
1886
-	ibdev->dev = &pci->dev;
1887
-	ibdev->port = PXE_IB_PORT;
1888
-	hermon = ibdev->dev_priv;
1889
-	memset ( hermon, 0, sizeof ( *hermon ) );
1890 1897
 
1891 1898
 	/* Fix up PCI device */
1892 1899
 	adjust_pci_device ( pci );
@@ -1939,16 +1946,21 @@ static int hermon_probe ( struct pci_device *pci,
1939 1946
 	if ( ( rc = hermon_setup_mpt ( hermon ) ) != 0 )
1940 1947
 		goto err_setup_mpt;
1941 1948
 
1942
-	/* Register Infiniband device */
1943
-	if ( ( rc = register_ibdev ( ibdev ) ) != 0 ) {
1944
-		DBGC ( hermon, "Hermon %p could not register IB device: %s\n",
1945
-		       hermon, strerror ( rc ) );
1946
-		goto err_register_ibdev;
1949
+	/* Register Infiniband devices */
1950
+	for ( i = 0 ; i < HERMON_NUM_PORTS ; i++ ) {
1951
+		if ( ( rc = register_ibdev ( hermon->ibdev[i] ) ) != 0 ) {
1952
+			DBGC ( hermon, "Hermon %p could not register IB "
1953
+			       "device: %s\n", hermon, strerror ( rc ) );
1954
+			goto err_register_ibdev;
1955
+		}
1947 1956
 	}
1948 1957
 
1949 1958
 	return 0;
1950 1959
 
1960
+	i = ( HERMON_NUM_PORTS - 1 );
1951 1961
  err_register_ibdev:
1962
+	for ( ; i >= 0 ; i-- )
1963
+		unregister_ibdev ( hermon->ibdev[i] );
1952 1964
  err_setup_mpt:
1953 1965
 	hermon_cmd_close_hca ( hermon );
1954 1966
  err_init_hca:
@@ -1961,8 +1973,12 @@ static int hermon_probe ( struct pci_device *pci,
1961 1973
  err_mailbox_out:
1962 1974
 	free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
1963 1975
  err_mailbox_in:
1964
-	free_ibdev ( ibdev );
1965
- err_ibdev:
1976
+	i = ( HERMON_NUM_PORTS - 1 );
1977
+ err_alloc_ibdev:
1978
+	for ( ; i >= 0 ; i-- )
1979
+		free_ibdev ( hermon->ibdev[i] );
1980
+	free ( hermon );
1981
+ err_alloc_hermon:
1966 1982
 	return rc;
1967 1983
 }
1968 1984
 
@@ -1972,17 +1988,20 @@ static int hermon_probe ( struct pci_device *pci,
1972 1988
  * @v pci		PCI device
1973 1989
  */
1974 1990
 static void hermon_remove ( struct pci_device *pci ) {
1975
-	struct ib_device *ibdev = pci_get_drvdata ( pci );
1976
-	struct hermon *hermon = ibdev->dev_priv;
1991
+	struct hermon *hermon = pci_get_drvdata ( pci );
1992
+	int i;
1977 1993
 
1978
-	unregister_ibdev ( ibdev );
1994
+	for ( i = ( HERMON_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
1995
+		unregister_ibdev ( hermon->ibdev[i] );
1979 1996
 	hermon_cmd_close_hca ( hermon );
1980 1997
 	hermon_free_icm ( hermon );
1981 1998
 	hermon_stop_firmware ( hermon );
1982 1999
 	hermon_stop_firmware ( hermon );
1983 2000
 	free_dma ( hermon->mailbox_out, HERMON_MBOX_SIZE );
1984 2001
 	free_dma ( hermon->mailbox_in, HERMON_MBOX_SIZE );
1985
-	free_ibdev ( ibdev );
2002
+	for ( i = ( HERMON_NUM_PORTS - 1 ) ; i >= 0 ; i-- )
2003
+		free_ibdev ( hermon->ibdev[i] );
2004
+	free ( hermon );
1986 2005
 }
1987 2006
 
1988 2007
 static struct pci_device_id hermon_nics[] = {

+ 7
- 0
src/drivers/infiniband/hermon.h ファイルの表示

@@ -17,6 +17,10 @@
17 17
  *
18 18
  */
19 19
 
20
+/* Ports in existence */
21
+#define HERMON_NUM_PORTS		1
22
+#define HERMON_PORT_BASE		1
23
+
20 24
 /* PCI BARs */
21 25
 #define HERMON_PCI_CONFIG_BAR		PCI_BASE_ADDRESS_0
22 26
 #define HERMON_PCI_CONFIG_BAR_SIZE	0x100000
@@ -402,6 +406,9 @@ struct hermon {
402 406
 
403 407
 	/** Device capabilities */
404 408
 	struct hermon_dev_cap cap;
409
+
410
+	/** Infiniband devices */
411
+	struct ib_device *ibdev[HERMON_NUM_PORTS];
405 412
 };
406 413
 
407 414
 /** Global protection domain */

+ 5
- 5
src/drivers/net/ipoib.c ファイルの表示

@@ -294,7 +294,7 @@ static int ipoib_create_qset ( struct ipoib_device *ipoib,
294 294
 		rc = -ENOMEM;
295 295
 		goto err;
296 296
 	}
297
-	qset->qp->owner_priv = ipoib->netdev;
297
+	ib_qp_set_ownerdata ( qset->qp, ipoib->netdev );
298 298
 
299 299
 	return 0;
300 300
 
@@ -506,7 +506,7 @@ static void ipoib_data_complete_send ( struct ib_device *ibdev __unused,
506 506
 				       struct ib_queue_pair *qp,
507 507
 				       struct ib_completion *completion,
508 508
 				       struct io_buffer *iobuf ) {
509
-	struct net_device *netdev = qp->owner_priv;
509
+	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
510 510
 
511 511
 	netdev_tx_complete_err ( netdev, iobuf,
512 512
 				 ( completion->syndrome ? -EIO : 0 ) );
@@ -524,7 +524,7 @@ static void ipoib_data_complete_recv ( struct ib_device *ibdev __unused,
524 524
 				       struct ib_queue_pair *qp,
525 525
 				       struct ib_completion *completion,
526 526
 				       struct io_buffer *iobuf ) {
527
-	struct net_device *netdev = qp->owner_priv;
527
+	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
528 528
 	struct ipoib_device *ipoib = netdev->priv;
529 529
 	struct ipoib_pseudo_hdr *ipoib_pshdr;
530 530
 
@@ -572,7 +572,7 @@ static void ipoib_meta_complete_send ( struct ib_device *ibdev __unused,
572 572
 				       struct ib_queue_pair *qp,
573 573
 				       struct ib_completion *completion,
574 574
 				       struct io_buffer *iobuf ) {
575
-	struct net_device *netdev = qp->owner_priv;
575
+	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
576 576
 	struct ipoib_device *ipoib = netdev->priv;
577 577
 
578 578
 	if ( completion->syndrome ) {
@@ -640,7 +640,7 @@ static void ipoib_meta_complete_recv ( struct ib_device *ibdev __unused,
640 640
 				       struct ib_queue_pair *qp,
641 641
 				       struct ib_completion *completion,
642 642
 				       struct io_buffer *iobuf ) {
643
-	struct net_device *netdev = qp->owner_priv;
643
+	struct net_device *netdev = ib_qp_get_ownerdata ( qp );
644 644
 	struct ipoib_device *ipoib = netdev->priv;
645 645
 	union ib_mad *mad;
646 646
 

+ 124
- 14
src/include/gpxe/infiniband.h ファイルの表示

@@ -75,8 +75,8 @@ struct ib_work_queue {
75 75
 	unsigned long next_idx;
76 76
 	/** I/O buffers assigned to work queue */
77 77
 	struct io_buffer **iobufs;
78
-	/** Device private data */
79
-	void *dev_priv;
78
+	/** Driver private data */
79
+	void *drv_priv;
80 80
 };
81 81
 
82 82
 /** An Infiniband Queue Pair */
@@ -89,8 +89,8 @@ struct ib_queue_pair {
89 89
 	struct ib_work_queue send;
90 90
 	/** Receive queue */
91 91
 	struct ib_work_queue recv;
92
-	/** Device private data */
93
-	void *dev_priv;
92
+	/** Driver private data */
93
+	void *drv_priv;
94 94
 	/** Queue owner private data */
95 95
 	void *owner_priv;
96 96
 };
@@ -111,8 +111,8 @@ struct ib_completion_queue {
111 111
 	unsigned long next_idx;
112 112
 	/** List of work queues completing to this queue */
113 113
 	struct list_head work_queues;
114
-	/** Device private data */
115
-	void *dev_priv;
114
+	/** Driver private data */
115
+	void *drv_priv;
116 116
 };
117 117
 
118 118
 /** An Infiniband completion */
@@ -297,8 +297,8 @@ struct ib_device {
297 297
 	unsigned long sm_lid;
298 298
 	/** Partition key */
299 299
 	unsigned int pkey;
300
-	/** Device private data */
301
-	void *dev_priv;
300
+	/** Driver private data */
301
+	void *drv_priv;
302 302
 	/** Owner private data */
303 303
 	void *owner_priv;
304 304
 };
@@ -425,20 +425,130 @@ ib_mad ( struct ib_device *ibdev, struct ib_mad_hdr *mad, size_t len ) {
425 425
 }
426 426
 
427 427
 /**
428
- * Set Infiniband owner-private data
428
+ * Set Infiniband work queue driver-private data
429 429
  *
430
- * @v pci		Infiniband device
430
+ * @v wq		Work queue
431 431
  * @v priv		Private data
432 432
  */
433 433
 static inline __attribute__ (( always_inline )) void
434
-ib_set_ownerdata ( struct ib_device *ibdev, void *owner_priv ) {
435
-	ibdev->owner_priv = owner_priv;
434
+ib_wq_set_drvdata ( struct ib_work_queue *wq, void *priv ) {
435
+	wq->drv_priv = priv;
436 436
 }
437 437
 
438 438
 /**
439
- * Get Infiniband owner-private data
439
+ * Get Infiniband work queue driver-private data
440 440
  *
441
- * @v pci		Infiniband device
441
+ * @v wq		Work queue
442
+ * @ret priv		Private data
443
+ */
444
+static inline __attribute__ (( always_inline )) void *
445
+ib_wq_get_drvdata ( struct ib_work_queue *wq ) {
446
+	return wq->drv_priv;
447
+}
448
+
449
+/**
450
+ * Set Infiniband queue pair driver-private data
451
+ *
452
+ * @v qp		Queue pair
453
+ * @v priv		Private data
454
+ */
455
+static inline __attribute__ (( always_inline )) void
456
+ib_qp_set_drvdata ( struct ib_queue_pair *qp, void *priv ) {
457
+	qp->drv_priv = priv;
458
+}
459
+
460
+/**
461
+ * Get Infiniband queue pair driver-private data
462
+ *
463
+ * @v qp		Queue pair
464
+ * @ret priv		Private data
465
+ */
466
+static inline __attribute__ (( always_inline )) void *
467
+ib_qp_get_drvdata ( struct ib_queue_pair *qp ) {
468
+	return qp->drv_priv;
469
+}
470
+
471
+/**
472
+ * Set Infiniband queue pair owner-private data
473
+ *
474
+ * @v qp		Queue pair
475
+ * @v priv		Private data
476
+ */
477
+static inline __attribute__ (( always_inline )) void
478
+ib_qp_set_ownerdata ( struct ib_queue_pair *qp, void *priv ) {
479
+	qp->owner_priv = priv;
480
+}
481
+
482
+/**
483
+ * Get Infiniband queue pair owner-private data
484
+ *
485
+ * @v qp		Queue pair
486
+ * @ret priv		Private data
487
+ */
488
+static inline __attribute__ (( always_inline )) void *
489
+ib_qp_get_ownerdata ( struct ib_queue_pair *qp ) {
490
+	return qp->owner_priv;
491
+}
492
+
493
+/**
494
+ * Set Infiniband completion queue driver-private data
495
+ *
496
+ * @v cq		Completion queue
497
+ * @v priv		Private data
498
+ */
499
+static inline __attribute__ (( always_inline )) void
500
+ib_cq_set_drvdata ( struct ib_completion_queue *cq, void *priv ) {
501
+	cq->drv_priv = priv;
502
+}
503
+
504
+/**
505
+ * Get Infiniband completion queue driver-private data
506
+ *
507
+ * @v cq		Completion queue
508
+ * @ret priv		Private data
509
+ */
510
+static inline __attribute__ (( always_inline )) void *
511
+ib_cq_get_drvdata ( struct ib_completion_queue *cq ) {
512
+	return cq->drv_priv;
513
+}
514
+
515
+/**
516
+ * Set Infiniband device driver-private data
517
+ *
518
+ * @v ibdev		Infiniband device
519
+ * @v priv		Private data
520
+ */
521
+static inline __attribute__ (( always_inline )) void
522
+ib_set_drvdata ( struct ib_device *ibdev, void *priv ) {
523
+	ibdev->drv_priv = priv;
524
+}
525
+
526
+/**
527
+ * Get Infiniband device driver-private data
528
+ *
529
+ * @v ibdev		Infiniband device
530
+ * @ret priv		Private data
531
+ */
532
+static inline __attribute__ (( always_inline )) void *
533
+ib_get_drvdata ( struct ib_device *ibdev ) {
534
+	return ibdev->drv_priv;
535
+}
536
+
537
+/**
538
+ * Set Infiniband device owner-private data
539
+ *
540
+ * @v ibdev		Infiniband device
541
+ * @v priv		Private data
542
+ */
543
+static inline __attribute__ (( always_inline )) void
544
+ib_set_ownerdata ( struct ib_device *ibdev, void *priv ) {
545
+	ibdev->owner_priv = priv;
546
+}
547
+
548
+/**
549
+ * Get Infiniband device owner-private data
550
+ *
551
+ * @v ibdev		Infiniband device
442 552
  * @ret priv		Private data
443 553
  */
444 554
 static inline __attribute__ (( always_inline )) void *

+ 7
- 4
src/net/infiniband.c ファイルの表示

@@ -67,7 +67,8 @@ struct ib_completion_queue * ib_create_cq ( struct ib_device *ibdev,
67 67
 	}
68 68
 
69 69
 	DBGC ( ibdev, "IBDEV %p created %d-entry completion queue %p (%p) "
70
-	       "with CQN %#lx\n", ibdev, num_cqes, cq, cq->dev_priv, cq->cqn );
70
+	       "with CQN %#lx\n", ibdev, num_cqes, cq,
71
+	       ib_cq_get_drvdata ( cq ), cq->cqn );
71 72
 	return cq;
72 73
 }
73 74
 
@@ -141,7 +142,7 @@ struct ib_queue_pair * ib_create_qp ( struct ib_device *ibdev,
141 142
 	}
142 143
 
143 144
 	DBGC ( ibdev, "IBDEV %p created queue pair %p (%p) with QPN %#lx\n",
144
-	       ibdev, qp, qp->dev_priv, qp->qpn );
145
+	       ibdev, qp, ib_qp_get_drvdata ( qp ), qp->qpn );
145 146
 	DBGC ( ibdev, "IBDEV %p QPN %#lx has %d send entries at [%p,%p)\n",
146 147
 	       ibdev, qp->qpn, num_send_wqes, qp->send.iobufs,
147 148
 	       qp->recv.iobufs );
@@ -360,17 +361,19 @@ static int ib_get_mad_params ( struct ib_device *ibdev ) {
360 361
 /**
361 362
  * Allocate Infiniband device
362 363
  *
363
- * @v priv_size		Size of private data area
364
+ * @v priv_size		Size of driver private data area
364 365
  * @ret ibdev		Infiniband device, or NULL
365 366
  */
366 367
 struct ib_device * alloc_ibdev ( size_t priv_size ) {
367 368
 	struct ib_device *ibdev;
369
+	void *drv_priv;
368 370
 	size_t total_len;
369 371
 
370 372
 	total_len = ( sizeof ( *ibdev ) + priv_size );
371 373
 	ibdev = zalloc ( total_len );
372 374
 	if ( ibdev ) {
373
-		ibdev->dev_priv = ( ( ( void * ) ibdev ) + sizeof ( *ibdev ) );
375
+		drv_priv = ( ( ( void * ) ibdev ) + sizeof ( *ibdev ) );
376
+		ib_set_drvdata ( ibdev, drv_priv );
374 377
 	}
375 378
 	return ibdev;
376 379
 }

読み込み中…
キャンセル
保存