Re: [PATCH v3 3/3] staging: vt6655: Replace VNSvInPortD with ioread32

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/29/22 17:25, Greg Kroah-Hartman wrote:
On Fri, Apr 29, 2022 at 05:18:28PM +0200, Philipp Hortmann wrote:
On 4/27/22 07:55, Greg Kroah-Hartman wrote:
MACvRegBitsOn(iobase, MAC_REG_TFTCTL, TFTCTL_TSFCNTRRD);
   	for (ww = 0; ww < W_MAX_TIMEOUT; ww++) {
@@ -753,8 +754,9 @@ bool CARDbGetCurrentTSF(struct vnt_private *priv, u64 *pqwCurrTSF)
   	}
   	if (ww == W_MAX_TIMEOUT)
   		return false;
-	VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
-	VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
+	low = ioread32(iobase + MAC_REG_TSFCNTR);
+	high = ioread32(iobase + MAC_REG_TSFCNTR + 4);
+	*pqwCurrTSF = low + ((u64)high << 32);
Are you_sure_  this is doing the same thing?

To compare I used the following code:
VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF *pqwCurrTSF: %llx",
*pqwCurrTSF);
low = ioread32(iobase + MAC_REG_TSFCNTR);
high = ioread32(iobase + MAC_REG_TSFCNTR + 4);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF low/high: %llx", low +
((u64)high << 32));

Output:
vt6655 0000:01:05.0: CARDbGetCurrentTSF *pqwCurrTSF: 1155ba
vt6655 0000:01:05.0: CARDbGetCurrentTSF low/high:    1155ba
vt6655 0000:01:05.0: CARDbGetCurrentTSF *pqwCurrTSF: 35d7cbd7c
vt6655 0000:01:05.0: CARDbGetCurrentTSF low/high:    35d7cbd7c
vt6655 0000:01:05.0: CARDbGetCurrentTSF *pqwCurrTSF: 35d7cbd8a
vt6655 0000:01:05.0: CARDbGetCurrentTSF low/high:    35d7cbd8a

So no different results for numbers larger than 32 Bit.
And for a big endian system?  Do you get the same result?


Using ioread32be to simulate output of the big endian computer.

Code:
	u32 *temp = (u32 *)pqwCurrTSF;	
	
	VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
	VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF *pqwCurrTSF: 0x%016llx", *pqwCurrTSF);

	temp++;
	*temp = ioread32be(iobase + MAC_REG_TSFCNTR);
	temp--;
	*temp = ioread32be(iobase + MAC_REG_TSFCNTR + 4);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF big-endian: 0x%016llx", *pqwCurrTSF);

	*temp = ioread32(iobase + MAC_REG_TSFCNTR);
	temp++;
	*temp = ioread32(iobase + MAC_REG_TSFCNTR + 4);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF little endian: 0x%016llx", *pqwCurrTSF);

Output:
[21250.521826] vt6655 0000:01:05.0: CARDbGetCurrentTSF *pqwCurrTSF: 0x00 00 00 05 f8 55 1d 9b [21250.521831] vt6655 0000:01:05.0: CARDbGetCurrentTSF big-endian: 0x9b 1d 55 f8 05 00 00 00 [21250.521835] vt6655 0000:01:05.0: CARDbGetCurrentTSF little endian: 0x00 00 00 05 f8 55 1d 9b

Code 2:
	u32 high, low;
	
	VNSvInPortD(iobase + MAC_REG_TSFCNTR, (u32 *)pqwCurrTSF);
	VNSvInPortD(iobase + MAC_REG_TSFCNTR + 4, (u32 *)pqwCurrTSF + 1);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF *pqwCurrTSF: 0x%016llx", *pqwCurrTSF);

	low = ioread32be(iobase + MAC_REG_TSFCNTR);
	high = ioread32be(iobase + MAC_REG_TSFCNTR + 4);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF big-endian: 0x%016llx", high + ((u64)low << 32));

	low = ioread32(iobase + MAC_REG_TSFCNTR);
	high = ioread32(iobase + MAC_REG_TSFCNTR + 4);
dev_info(&priv->pcid->dev, "CARDbGetCurrentTSF little endian: 0x%016llx", low + ((u64)high << 32));

Output 2:
[21996.659694] vt6655 0000:01:05.0: CARDbGetCurrentTSF *pqwCurrTSF: 0x00 00 00 06 24 cd 8d 91 [21996.659698] vt6655 0000:01:05.0: CARDbGetCurrentTSF big-endian: 0x91 8d cd 24 06 00 00 00 [21996.659701] vt6655 0000:01:05.0: CARDbGetCurrentTSF little endian: 0x00 00 00 06 24 cd 8d 91

[22453.448296] vt6655 0000:01:05.0: CARDbGetCurrentTSF *pqwCurrTSF: 0x00 00 00 06 40 07 dd a3 [22453.448300] vt6655 0000:01:05.0: CARDbGetCurrentTSF big-endian: 0xa3 dd 07 40 06 00 00 00 [22453.448304] vt6655 0000:01:05.0: CARDbGetCurrentTSF little endian: 0x00 00 00 06 40 07 dd a3

I am assuming that in case the big endian computer is used the ioread32 will be automatically converted to ioread32be. So I have only to care about the u32 to be exchanged. That is easier with the second example.

Code:
	low = ioread32(iobase + MAC_REG_TSFCNTR);
	high = ioread32(iobase + MAC_REG_TSFCNTR + 4);

#ifdef __BIG_ENDIAN
	*pqwCurrTSF = high + ((u64)low << 32);
#else
	*pqwCurrTSF = low + ((u64)high << 32);
#endif

Comments are welcome.

This is the article that helped me a lot:
https://en.wikipedia.org/wiki/Endianness#Bit_endianness
Especially the "Endian example" picture

Thanks,
Bye Philipp




[Index of Archives]     [Linux Driver Development]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux