47
47
/* Message with data needs at least two words (for header & data). */
48
48
#define MLXBF_TMFIFO_DATA_MIN_WORDS 2
49
49
50
+ /* ACPI UID for BlueField-3. */
51
+ #define TMFIFO_BF3_UID 1
52
+
50
53
struct mlxbf_tmfifo ;
51
54
52
55
/**
@@ -136,12 +139,26 @@ struct mlxbf_tmfifo_irq_info {
136
139
int index ;
137
140
};
138
141
142
+ /**
143
+ * mlxbf_tmfifo_io - Structure of the TmFifo IO resource (for both rx & tx)
144
+ * @ctl: control register offset (TMFIFO_RX_CTL / TMFIFO_TX_CTL)
145
+ * @sts: status register offset (TMFIFO_RX_STS / TMFIFO_TX_STS)
146
+ * @data: data register offset (TMFIFO_RX_DATA / TMFIFO_TX_DATA)
147
+ */
148
+ struct mlxbf_tmfifo_io {
149
+ void __iomem * ctl ;
150
+ void __iomem * sts ;
151
+ void __iomem * data ;
152
+ };
153
+
139
154
/**
140
155
* mlxbf_tmfifo - Structure of the TmFifo
141
156
* @vdev: array of the virtual devices running over the TmFifo
142
157
* @lock: lock to protect the TmFifo access
143
- * @rx_base: mapped register base address for the Rx FIFO
144
- * @tx_base: mapped register base address for the Tx FIFO
158
+ * @res0: mapped resource block 0
159
+ * @res1: mapped resource block 1
160
+ * @rx: rx io resource
161
+ * @tx: tx io resource
145
162
* @rx_fifo_size: number of entries of the Rx FIFO
146
163
* @tx_fifo_size: number of entries of the Tx FIFO
147
164
* @pend_events: pending bits for deferred events
@@ -155,8 +172,10 @@ struct mlxbf_tmfifo_irq_info {
155
172
struct mlxbf_tmfifo {
156
173
struct mlxbf_tmfifo_vdev * vdev [MLXBF_TMFIFO_VDEV_MAX ];
157
174
struct mutex lock ; /* TmFifo lock */
158
- void __iomem * rx_base ;
159
- void __iomem * tx_base ;
175
+ void __iomem * res0 ;
176
+ void __iomem * res1 ;
177
+ struct mlxbf_tmfifo_io rx ;
178
+ struct mlxbf_tmfifo_io tx ;
160
179
int rx_fifo_size ;
161
180
int tx_fifo_size ;
162
181
unsigned long pend_events ;
@@ -472,7 +491,7 @@ static int mlxbf_tmfifo_get_rx_avail(struct mlxbf_tmfifo *fifo)
472
491
{
473
492
u64 sts ;
474
493
475
- sts = readq (fifo -> rx_base + MLXBF_TMFIFO_RX_STS );
494
+ sts = readq (fifo -> rx . sts );
476
495
return FIELD_GET (MLXBF_TMFIFO_RX_STS__COUNT_MASK , sts );
477
496
}
478
497
@@ -489,7 +508,7 @@ static int mlxbf_tmfifo_get_tx_avail(struct mlxbf_tmfifo *fifo, int vdev_id)
489
508
else
490
509
tx_reserve = 1 ;
491
510
492
- sts = readq (fifo -> tx_base + MLXBF_TMFIFO_TX_STS );
511
+ sts = readq (fifo -> tx . sts );
493
512
count = FIELD_GET (MLXBF_TMFIFO_TX_STS__COUNT_MASK , sts );
494
513
return fifo -> tx_fifo_size - tx_reserve - count ;
495
514
}
@@ -525,7 +544,7 @@ static void mlxbf_tmfifo_console_tx(struct mlxbf_tmfifo *fifo, int avail)
525
544
/* Write header. */
526
545
hdr .type = VIRTIO_ID_CONSOLE ;
527
546
hdr .len = htons (size );
528
- writeq (* (u64 * )& hdr , fifo -> tx_base + MLXBF_TMFIFO_TX_DATA );
547
+ writeq (* (u64 * )& hdr , fifo -> tx . data );
529
548
530
549
/* Use spin-lock to protect the 'cons->tx_buf'. */
531
550
spin_lock_irqsave (& fifo -> spin_lock [0 ], flags );
@@ -542,7 +561,7 @@ static void mlxbf_tmfifo_console_tx(struct mlxbf_tmfifo *fifo, int avail)
542
561
memcpy ((u8 * )& data + seg , cons -> tx_buf .buf ,
543
562
sizeof (u64 ) - seg );
544
563
}
545
- writeq (data , fifo -> tx_base + MLXBF_TMFIFO_TX_DATA );
564
+ writeq (data , fifo -> tx . data );
546
565
547
566
if (size >= sizeof (u64 )) {
548
567
cons -> tx_buf .tail = (cons -> tx_buf .tail + sizeof (u64 )) %
@@ -573,7 +592,7 @@ static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring,
573
592
574
593
/* Read a word from FIFO for Rx. */
575
594
if (is_rx )
576
- data = readq (fifo -> rx_base + MLXBF_TMFIFO_RX_DATA );
595
+ data = readq (fifo -> rx . data );
577
596
578
597
if (vring -> cur_len + sizeof (u64 ) <= len ) {
579
598
/* The whole word. */
@@ -595,7 +614,7 @@ static void mlxbf_tmfifo_rxtx_word(struct mlxbf_tmfifo_vring *vring,
595
614
596
615
/* Write the word into FIFO for Tx. */
597
616
if (!is_rx )
598
- writeq (data , fifo -> tx_base + MLXBF_TMFIFO_TX_DATA );
617
+ writeq (data , fifo -> tx . data );
599
618
}
600
619
601
620
/*
@@ -617,7 +636,7 @@ static void mlxbf_tmfifo_rxtx_header(struct mlxbf_tmfifo_vring *vring,
617
636
/* Read/Write packet header. */
618
637
if (is_rx ) {
619
638
/* Drain one word from the FIFO. */
620
- * (u64 * )& hdr = readq (fifo -> rx_base + MLXBF_TMFIFO_RX_DATA );
639
+ * (u64 * )& hdr = readq (fifo -> rx . data );
621
640
622
641
/* Skip the length 0 packets (keepalive). */
623
642
if (hdr .len == 0 )
@@ -661,7 +680,7 @@ static void mlxbf_tmfifo_rxtx_header(struct mlxbf_tmfifo_vring *vring,
661
680
hdr .type = (vring -> vdev_id == VIRTIO_ID_NET ) ?
662
681
VIRTIO_ID_NET : VIRTIO_ID_CONSOLE ;
663
682
hdr .len = htons (vring -> pkt_len - hdr_len );
664
- writeq (* (u64 * )& hdr , fifo -> tx_base + MLXBF_TMFIFO_TX_DATA );
683
+ writeq (* (u64 * )& hdr , fifo -> tx . data );
665
684
}
666
685
667
686
vring -> cur_len = hdr_len ;
@@ -1157,7 +1176,7 @@ static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo)
1157
1176
u64 ctl ;
1158
1177
1159
1178
/* Get Tx FIFO size and set the low/high watermark. */
1160
- ctl = readq (fifo -> tx_base + MLXBF_TMFIFO_TX_CTL );
1179
+ ctl = readq (fifo -> tx . ctl );
1161
1180
fifo -> tx_fifo_size =
1162
1181
FIELD_GET (MLXBF_TMFIFO_TX_CTL__MAX_ENTRIES_MASK , ctl );
1163
1182
ctl = (ctl & ~MLXBF_TMFIFO_TX_CTL__LWM_MASK ) |
@@ -1166,17 +1185,17 @@ static void mlxbf_tmfifo_set_threshold(struct mlxbf_tmfifo *fifo)
1166
1185
ctl = (ctl & ~MLXBF_TMFIFO_TX_CTL__HWM_MASK ) |
1167
1186
FIELD_PREP (MLXBF_TMFIFO_TX_CTL__HWM_MASK ,
1168
1187
fifo -> tx_fifo_size - 1 );
1169
- writeq (ctl , fifo -> tx_base + MLXBF_TMFIFO_TX_CTL );
1188
+ writeq (ctl , fifo -> tx . ctl );
1170
1189
1171
1190
/* Get Rx FIFO size and set the low/high watermark. */
1172
- ctl = readq (fifo -> rx_base + MLXBF_TMFIFO_RX_CTL );
1191
+ ctl = readq (fifo -> rx . ctl );
1173
1192
fifo -> rx_fifo_size =
1174
1193
FIELD_GET (MLXBF_TMFIFO_RX_CTL__MAX_ENTRIES_MASK , ctl );
1175
1194
ctl = (ctl & ~MLXBF_TMFIFO_RX_CTL__LWM_MASK ) |
1176
1195
FIELD_PREP (MLXBF_TMFIFO_RX_CTL__LWM_MASK , 0 );
1177
1196
ctl = (ctl & ~MLXBF_TMFIFO_RX_CTL__HWM_MASK ) |
1178
1197
FIELD_PREP (MLXBF_TMFIFO_RX_CTL__HWM_MASK , 1 );
1179
- writeq (ctl , fifo -> rx_base + MLXBF_TMFIFO_RX_CTL );
1198
+ writeq (ctl , fifo -> rx . ctl );
1180
1199
}
1181
1200
1182
1201
static void mlxbf_tmfifo_cleanup (struct mlxbf_tmfifo * fifo )
@@ -1197,8 +1216,15 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev)
1197
1216
struct virtio_net_config net_config ;
1198
1217
struct device * dev = & pdev -> dev ;
1199
1218
struct mlxbf_tmfifo * fifo ;
1219
+ u64 dev_id ;
1200
1220
int i , rc ;
1201
1221
1222
+ rc = acpi_dev_uid_to_integer (ACPI_COMPANION (dev ), & dev_id );
1223
+ if (rc ) {
1224
+ dev_err (dev , "Cannot retrieve UID\n" );
1225
+ return rc ;
1226
+ }
1227
+
1202
1228
fifo = devm_kzalloc (dev , sizeof (* fifo ), GFP_KERNEL );
1203
1229
if (!fifo )
1204
1230
return - ENOMEM ;
@@ -1209,14 +1235,30 @@ static int mlxbf_tmfifo_probe(struct platform_device *pdev)
1209
1235
mutex_init (& fifo -> lock );
1210
1236
1211
1237
/* Get the resource of the Rx FIFO. */
1212
- fifo -> rx_base = devm_platform_ioremap_resource (pdev , 0 );
1213
- if (IS_ERR (fifo -> rx_base ))
1214
- return PTR_ERR (fifo -> rx_base );
1238
+ fifo -> res0 = devm_platform_ioremap_resource (pdev , 0 );
1239
+ if (IS_ERR (fifo -> res0 ))
1240
+ return PTR_ERR (fifo -> res0 );
1215
1241
1216
1242
/* Get the resource of the Tx FIFO. */
1217
- fifo -> tx_base = devm_platform_ioremap_resource (pdev , 1 );
1218
- if (IS_ERR (fifo -> tx_base ))
1219
- return PTR_ERR (fifo -> tx_base );
1243
+ fifo -> res1 = devm_platform_ioremap_resource (pdev , 1 );
1244
+ if (IS_ERR (fifo -> res1 ))
1245
+ return PTR_ERR (fifo -> res1 );
1246
+
1247
+ if (dev_id == TMFIFO_BF3_UID ) {
1248
+ fifo -> rx .ctl = fifo -> res1 + MLXBF_TMFIFO_RX_CTL_BF3 ;
1249
+ fifo -> rx .sts = fifo -> res1 + MLXBF_TMFIFO_RX_STS_BF3 ;
1250
+ fifo -> rx .data = fifo -> res0 + MLXBF_TMFIFO_RX_DATA_BF3 ;
1251
+ fifo -> tx .ctl = fifo -> res1 + MLXBF_TMFIFO_TX_CTL_BF3 ;
1252
+ fifo -> tx .sts = fifo -> res1 + MLXBF_TMFIFO_TX_STS_BF3 ;
1253
+ fifo -> tx .data = fifo -> res0 + MLXBF_TMFIFO_TX_DATA_BF3 ;
1254
+ } else {
1255
+ fifo -> rx .ctl = fifo -> res0 + MLXBF_TMFIFO_RX_CTL ;
1256
+ fifo -> rx .sts = fifo -> res0 + MLXBF_TMFIFO_RX_STS ;
1257
+ fifo -> rx .data = fifo -> res0 + MLXBF_TMFIFO_RX_DATA ;
1258
+ fifo -> tx .ctl = fifo -> res1 + MLXBF_TMFIFO_TX_CTL ;
1259
+ fifo -> tx .sts = fifo -> res1 + MLXBF_TMFIFO_TX_STS ;
1260
+ fifo -> tx .data = fifo -> res1 + MLXBF_TMFIFO_TX_DATA ;
1261
+ }
1220
1262
1221
1263
platform_set_drvdata (pdev , fifo );
1222
1264
0 commit comments