mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-28 11:18:45 +07:00
2c000f4dba
When loading the budget_av driver for ie. a KNC1 DVB-C TDA10024 card, which makes use of the ttpci eeprom check functionality (that always fails on these cards, but that's no issue at all), this is printed to the kernel log: [ 10.497333] saa7146 (0): dma buffer size 192512 [ 10.497335] dvbdev: DVB: registering new adapter (KNC1 DVB-C TDA10024) [ 10.545007] adapter failed MAC signature check [ 10.545009] encoded MAC from EEPROM was [ 10.545010] ff: [ 10.545011] ff: [ 10.545011] ff: ... [ 10.545021] ff [ 10.832422] budget_av: KNC1-4: MAC addr = 00:09:d6:6d:b3:be with the 'ff' being repeated for a total of 20 times. Improve that by using the %*phC format specifier instead dprintk()'ing every byte of the encoded MAC separately. This obsoletes the int i, and the kernel log looks cleaner: [ 3234.383153] saa7146 (0): dma buffer size 192512 [ 3234.383154] dvbdev: DVB: registering new adapter (KNC1 DVB-C TDA10024) [ 3234.428745] adapter failed MAC signature check [ 3234.428747] encoded MAC from EEPROM was ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff [ 3234.728194] budget_av: KNC1-0: MAC addr = 00:09:d6:6d:b3:be Signed-off-by: Daniel Scheller <d.scheller@gmx.net> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
172 lines
4.5 KiB
C
172 lines
4.5 KiB
C
/*
|
|
Retrieve encoded MAC address from 24C16 serial 2-wire EEPROM,
|
|
decode it and store it in the associated adapter struct for
|
|
use by dvb_net.c
|
|
|
|
This card appear to have the 24C16 write protect held to ground,
|
|
thus permitting normal read/write operation. Theoretically it
|
|
would be possible to write routines to burn a different (encoded)
|
|
MAC address into the EEPROM.
|
|
|
|
Robert Schlabbach GMX
|
|
Michael Glaum KVH Industries
|
|
Holger Waechtler Convergence
|
|
|
|
Copyright (C) 2002-2003 Ralph Metzler <rjkm@metzlerbros.de>
|
|
Metzler Brothers Systementwicklung GbR
|
|
|
|
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
|
|
(at your option) 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
#include <asm/errno.h>
|
|
#include <linux/init.h>
|
|
#include <linux/module.h>
|
|
#include <linux/string.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include "ttpci-eeprom.h"
|
|
|
|
#if 1
|
|
#define dprintk(x...) do { printk(x); } while (0)
|
|
#else
|
|
#define dprintk(x...) do { } while (0)
|
|
#endif
|
|
|
|
|
|
static int check_mac_tt(u8 *buf)
|
|
{
|
|
int i;
|
|
u16 tmp = 0xffff;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
tmp = (tmp << 8) | ((tmp >> 8) ^ buf[i]);
|
|
tmp ^= (tmp >> 4) & 0x0f;
|
|
tmp ^= (tmp << 12) ^ ((tmp & 0xff) << 5);
|
|
}
|
|
tmp ^= 0xffff;
|
|
return (((tmp >> 8) ^ buf[8]) | ((tmp & 0xff) ^ buf[9]));
|
|
}
|
|
|
|
static int getmac_tt(u8 * decodedMAC, u8 * encodedMAC)
|
|
{
|
|
u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
|
|
0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
|
|
0x1d, 0x36, 0x64, 0x78};
|
|
u8 data[20];
|
|
int i;
|
|
|
|
/* In case there is a sig check failure have the orig contents available */
|
|
memcpy(data, encodedMAC, 20);
|
|
|
|
for (i = 0; i < 20; i++)
|
|
data[i] ^= xor[i];
|
|
for (i = 0; i < 10; i++)
|
|
data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
|
|
>> ((data[2 * i + 1] >> 6) & 3);
|
|
|
|
if (check_mac_tt(data))
|
|
return -ENODEV;
|
|
|
|
decodedMAC[0] = data[2]; decodedMAC[1] = data[1]; decodedMAC[2] = data[0];
|
|
decodedMAC[3] = data[6]; decodedMAC[4] = data[5]; decodedMAC[5] = data[4];
|
|
return 0;
|
|
}
|
|
|
|
int ttpci_eeprom_decode_mac(u8 *decodedMAC, u8 *encodedMAC)
|
|
{
|
|
u8 xor[20] = { 0x72, 0x23, 0x68, 0x19, 0x5c, 0xa8, 0x71, 0x2c,
|
|
0x54, 0xd3, 0x7b, 0xf1, 0x9E, 0x23, 0x16, 0xf6,
|
|
0x1d, 0x36, 0x64, 0x78};
|
|
u8 data[20];
|
|
int i;
|
|
|
|
memcpy(data, encodedMAC, 20);
|
|
|
|
for (i = 0; i < 20; i++)
|
|
data[i] ^= xor[i];
|
|
for (i = 0; i < 10; i++)
|
|
data[i] = ((data[2 * i + 1] << 8) | data[2 * i])
|
|
>> ((data[2 * i + 1] >> 6) & 3);
|
|
|
|
if (check_mac_tt(data))
|
|
return -ENODEV;
|
|
|
|
decodedMAC[0] = data[2];
|
|
decodedMAC[1] = data[1];
|
|
decodedMAC[2] = data[0];
|
|
decodedMAC[3] = data[6];
|
|
decodedMAC[4] = data[5];
|
|
decodedMAC[5] = data[4];
|
|
return 0;
|
|
}
|
|
EXPORT_SYMBOL(ttpci_eeprom_decode_mac);
|
|
|
|
static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encodedMAC)
|
|
{
|
|
int ret;
|
|
u8 b0[] = { 0xcc };
|
|
|
|
struct i2c_msg msg[] = {
|
|
{ .addr = 0x50, .flags = 0, .buf = b0, .len = 1 },
|
|
{ .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
|
|
};
|
|
|
|
/* dprintk("%s\n", __func__); */
|
|
|
|
ret = i2c_transfer(adapter, msg, 2);
|
|
|
|
if (ret != 2) /* Assume EEPROM isn't there */
|
|
return (-ENODEV);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int ttpci_eeprom_parse_mac(struct i2c_adapter *adapter, u8 *proposed_mac)
|
|
{
|
|
int ret;
|
|
u8 encodedMAC[20];
|
|
u8 decodedMAC[6];
|
|
|
|
ret = ttpci_eeprom_read_encodedMAC(adapter, encodedMAC);
|
|
|
|
if (ret != 0) { /* Will only be -ENODEV */
|
|
dprintk("Couldn't read from EEPROM: not there?\n");
|
|
eth_zero_addr(proposed_mac);
|
|
return ret;
|
|
}
|
|
|
|
ret = getmac_tt(decodedMAC, encodedMAC);
|
|
if( ret != 0 ) {
|
|
dprintk("adapter failed MAC signature check\n");
|
|
dprintk("encoded MAC from EEPROM was %*phC",
|
|
(int)sizeof(encodedMAC), &encodedMAC);
|
|
eth_zero_addr(proposed_mac);
|
|
return ret;
|
|
}
|
|
|
|
memcpy(proposed_mac, decodedMAC, 6);
|
|
dprintk("adapter has MAC addr = %pM\n", decodedMAC);
|
|
return 0;
|
|
}
|
|
|
|
EXPORT_SYMBOL(ttpci_eeprom_parse_mac);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Ralph Metzler, Marcus Metzler, others");
|
|
MODULE_DESCRIPTION("Decode dvb_net MAC address from EEPROM of PCI DVB cards made by Siemens, Technotrend, Hauppauge");
|