Make netboot generate a BTINFO_NET bootinfo node for the Synology sk(4) NIC.

It will pass the MAC address, which is read from Flash ROM, into the kernel.
The kernel creates a "mac-address" device-property, which is used by sk(4),
when given, before reading the MAC from its EEPROM.
This commit is contained in:
phx 2010-05-16 11:27:49 +00:00
parent 5a6d00fa0a
commit 5929d8aee3
7 changed files with 147 additions and 37 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: bootinfo.h,v 1.4 2007/10/17 19:56:56 garbled Exp $ */
/* $NetBSD: bootinfo.h,v 1.5 2010/05/16 11:27:49 phx Exp $ */
/*
* Copyright (c) 1997
@ -42,6 +42,7 @@ struct btinfo_common {
#define BTINFO_CLOCK 4
#define BTINFO_BOOTPATH 5
#define BTINFO_ROOTDEVICE 6
#define BTINFO_NET 7
struct btinfo_magic {
struct btinfo_common common;
@ -76,6 +77,12 @@ struct btinfo_rootdevice {
unsigned cookie;
};
struct btinfo_net {
struct btinfo_common common;
char devname[16];
uint8_t mac_address[6];
};
#define BOOTINFO_MAXSIZE 4096
#ifdef _KERNEL

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.19 2009/03/18 10:22:35 cegger Exp $ */
/* $NetBSD: autoconf.c,v 1.20 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -35,22 +35,25 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.19 2009/03/18 10:22:35 cegger Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.20 2010/05/16 11:27:49 phx Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <dev/cons.h>
#include <dev/pci/pcivar.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <machine/bootinfo.h>
#include <machine/pio.h>
static struct btinfo_rootdevice *bi_rdev;
static struct btinfo_bootpath *bi_path;
#include <dev/cons.h>
#include <machine/pio.h>
static struct btinfo_net *bi_net;
/*
* Determine i/o configuration for a machine.
@ -61,6 +64,7 @@ cpu_configure(void)
bi_rdev = lookup_bootinfo(BTINFO_ROOTDEVICE);
bi_path = lookup_bootinfo(BTINFO_BOOTPATH);
bi_net = lookup_bootinfo(BTINFO_NET);
if (config_rootfound("mainbus", NULL) == NULL)
panic("configure: mainbus not configured");
@ -85,18 +89,28 @@ cpu_rootconf(void)
void
device_register(struct device *dev, void *aux)
{
struct pci_attach_args *pa;
if (bi_rdev == NULL)
return; /* no clue to determine */
if (dev->dv_class == DV_IFNET
&& device_is_a(dev, bi_rdev->devname)) {
struct pci_attach_args *pa = aux;
if (bi_rdev->cookie == pa->pa_tag)
if (dev->dv_class == DV_IFNET) {
pa = aux;
if (bi_rdev != NULL && device_is_a(dev, bi_rdev->devname)
&& bi_rdev->cookie == pa->pa_tag)
booted_device = dev;
if (bi_net != NULL && device_is_a(dev, bi_net->devname)) {
prop_data_t pd;
pd = prop_data_create_data_nocopy(bi_net->mac_address,
ETHER_ADDR_LEN);
KASSERT(pd != NULL);
if (prop_dictionary_set(device_properties(dev),
"mac-address", pd) == false)
printf("WARNING: unable to set mac-addr "
"property for %s\n", dev->dv_xname);
prop_object_release(pd);
bi_net = NULL; /* do it just once */
}
}
if (dev->dv_class == DV_DISK
if (bi_rdev != NULL && dev->dv_class == DV_DISK
&& device_is_a(dev, bi_rdev->devname)) {
booted_device = dev;
booted_partition = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: brdsetup.c,v 1.13 2010/05/13 10:40:02 phx Exp $ */
/* $NetBSD: brdsetup.c,v 1.14 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -707,3 +707,77 @@ pcifixup(void)
break;
}
}
struct fis_dir_entry {
char name[16];
uint32_t startaddr;
uint32_t loadaddr;
uint32_t flashsize;
uint32_t entryaddr;
uint32_t filesize;
char pad[256 - (16 + 5 * sizeof(uint32_t))];
};
#define FIS_LOWER_LIMIT 0xfff00000
/*
* Look for a Redboot-style Flash Image System FIS-directory and
* return a pointer to the start address of the requested file.
*/
static void *
redboot_fis_lookup(const char *filename)
{
static const char FISdirname[16] = {
'F', 'I', 'S', ' ',
'd', 'i', 'r', 'e', 'c', 't', 'o', 'r', 'y', 0, 0, 0
};
struct fis_dir_entry *dir;
/*
* The FIS directory is usually in the last sector of the flash.
* But we do not know the sector size (erase size), so start
* at 0xffffff00 and scan backwards in steps of the FIS directory
* entry size (0x100).
*/
for (dir = (struct fis_dir_entry *)0xffffff00;
(uint32_t)dir >= FIS_LOWER_LIMIT; dir--)
if (memcmp(dir->name, FISdirname, sizeof(FISdirname)) == 0)
break;
if ((uint32_t)dir < FIS_LOWER_LIMIT) {
printf("No FIS directory found!\n");
return NULL;
}
/* Now find filename by scanning the directory from beginning. */
dir = (struct fis_dir_entry *)dir->startaddr;
while (dir->name[0] != 0xff && (uint32_t)dir < 0xffffff00) {
if (strcmp(dir->name, filename) == 0)
return (void *)dir->startaddr; /* found */
dir++;
}
printf("\"%s\" not found in FIS directory!\n", filename);
return NULL;
}
/*
* For cost saving reasons some NAS boxes are missing the ROM for the
* NIC's ethernet address and keep it in their Flash memory.
*/
void
read_mac_from_flash(uint8_t *mac)
{
uint8_t *p;
if (brdtype == BRD_SYNOLOGY) {
p = redboot_fis_lookup("vendor");
if (p != NULL) {
memcpy(mac, p, 6);
return;
}
} else
printf("Warning: This board has no known method defined "
"to determine its MAC address!\n");
/* set to 00:00:00:00:00:00 in case of error */
memset(mac, 0, 6);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: globals.h,v 1.14 2010/05/08 19:41:07 phx Exp $ */
/* $NetBSD: globals.h,v 1.15 2010/05/16 11:27:49 phx Exp $ */
/* clock feed */
#ifndef EXT_CLK_FREQ
@ -23,6 +23,7 @@ extern int ticks_per_sec;
extern uint32_t cpuclock, busclock;
unsigned mpc107memsize(void);
void read_mac_from_flash(uint8_t *);
/* PPC processor ctl */
void __syncicache(void *, size_t);

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.28 2010/05/13 10:40:02 phx Exp $ */
/* $NetBSD: main.c,v 1.29 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -69,6 +69,7 @@ main(void)
struct btinfo_clock bi_clk;
struct btinfo_bootpath bi_path;
struct btinfo_rootdevice bi_rdev;
struct btinfo_net bi_net;
unsigned long marks[MARK_MAX];
unsigned lata[1][2], lnif[1][2];
unsigned memsize, tag;
@ -158,12 +159,19 @@ main(void)
snprintf(bi_path.bootpath, sizeof(bi_path.bootpath), bootfile);
snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), rootdev);
bi_rdev.cookie = tag; /* PCI tag for fxp netboot case */
if (brdtype == BRD_SYNOLOGY) {
/* need to set MAC address for Marvell-SKnet */
strcpy(bi_net.devname, "sk");
memcpy(bi_net.mac_address, en, sizeof(en));
}
bi_add(&bi_cons, BTINFO_CONSOLE, sizeof(bi_cons));
bi_add(&bi_mem, BTINFO_MEMORY, sizeof(bi_mem));
bi_add(&bi_clk, BTINFO_CLOCK, sizeof(bi_clk));
bi_add(&bi_path, BTINFO_BOOTPATH, sizeof(bi_path));
bi_add(&bi_rdev, BTINFO_ROOTDEVICE, sizeof(bi_rdev));
if (brdtype == BRD_SYNOLOGY)
bi_add(&bi_net, BTINFO_NET, sizeof(bi_net));
printf("entry=%p, ssym=%p, esym=%p\n",
(void *)marks[MARK_ENTRY],

View File

@ -1,4 +1,4 @@
/* $NetBSD: skg.c,v 1.2 2010/05/03 18:55:09 phx Exp $ */
/* $NetBSD: skg.c,v 1.3 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2010 Frank Wille.
@ -227,25 +227,20 @@ skg_init(unsigned tag, void *data)
/* read ethernet address */
en = data;
for (i = 0; i < 6; i++)
en[i] = CSR_READ_1(l, SK_MAC0 + i);
if (brdtype == BRD_SYNOLOGY)
read_mac_from_flash(en);
else
for (i = 0; i < 6; i++)
en[i] = CSR_READ_1(l, SK_MAC0 + i);
printf("MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
en[0], en[1], en[2], en[3], en[4], en[5]);
printf("PHY %d (%04x.%04x)\n", l->phy,
mii_read(l, l->phy, 2), mii_read(l, l->phy, 3));
/* set station address */
for (i = 0; i < 3; i++) {
#if 0
CSR_WRITE_2(l, YUKON_SA1 + i * 4,
CSR_READ_2(l, SK_MAC0 + i * 2));
CSR_WRITE_2(l, YUKON_SA2 + i * 4,
CSR_READ_2(l, SK_MAC1 + i * 2));
#else
for (i = 0; i < 3; i++)
CSR_WRITE_2(l, YUKON_SA1 + i * 4,
(en[i * 2] << 8) | en[i * 2 + 1]);
#endif
}
/* configure RX and TX MAC FIFO */
CSR_WRITE_1(l, SK_RXMF1_CTRL_TEST, RFCTL_RESET_CLEAR);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_sk.c,v 1.66 2010/04/05 07:20:27 joerg Exp $ */
/* $NetBSD: if_sk.c,v 1.67 2010/05/16 11:27:49 phx Exp $ */
/*-
* Copyright (c) 2003 The NetBSD Foundation, Inc.
@ -115,7 +115,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_sk.c,v 1.66 2010/04/05 07:20:27 joerg Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_sk.c,v 1.67 2010/05/16 11:27:49 phx Exp $");
#include "rnd.h"
@ -1209,6 +1209,7 @@ sk_attach(device_t parent, device_t self, void *aux)
struct ifnet *ifp;
bus_dma_segment_t seg;
bus_dmamap_t dmamap;
prop_data_t data;
void *kva;
int i, rseg;
int mii_flags = 0;
@ -1236,10 +1237,20 @@ sk_attach(device_t parent, device_t self, void *aux)
* are operating in failover mode. Currently we don't
* use this extra address.
*/
for (i = 0; i < ETHER_ADDR_LEN; i++)
sc_if->sk_enaddr[i] =
sk_win_read_1(sc, SK_MAC0_0 + (sa->skc_port * 8) + i);
data = prop_dictionary_get(device_properties(self), "mac-address");
if (data != NULL) {
/*
* Try to get the station address from device properties
* first, in case the ROM is missing.
*/
KASSERT(prop_object_type(data) == PROP_TYPE_DATA);
KASSERT(prop_data_size(data) == ETHER_ADDR_LEN);
memcpy(sc_if->sk_enaddr, prop_data_data_nocopy(data),
ETHER_ADDR_LEN);
} else
for (i = 0; i < ETHER_ADDR_LEN; i++)
sc_if->sk_enaddr[i] = sk_win_read_1(sc,
SK_MAC0_0 + (sa->skc_port * 8) + i);
aprint_normal(": Ethernet address %s\n",
ether_sprintf(sc_if->sk_enaddr));