Newer
Older
/**************************************************************************
TRANSMIT - Transmit a frame
***************************************************************************/
static int e1000_transmit(struct eth_device *nic, void *packet, int length)
void *nv_packet = (void *)packet;
struct e1000_hw *hw = nic->priv;
struct e1000_tx_desc *txp;
int i = 0;
txp = tx_base + tx_tail;
tx_tail = (tx_tail + 1) % 8;
txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
txp->upper.data = 0;
E1000_WRITE_REG(hw, TDT, tx_tail);
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
while (!(le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)) {
if (i++ > TOUT_LOOP) {
DEBUGOUT("e1000: tx timeout\n");
return 0;
}
udelay(10); /* give the nic a chance to write to the register */
}
return 1;
}
/*reset function*/
static inline int
e1000_reset(struct eth_device *nic)
{
struct e1000_hw *hw = nic->priv;
e1000_reset_hw(hw);
if (hw->mac_type >= e1000_82544) {
E1000_WRITE_REG(hw, WUC, 0);
}
return e1000_init_hw(nic);
}
/**************************************************************************
DISABLE - Turn off ethernet interface
***************************************************************************/
static void
e1000_disable(struct eth_device *nic)
{
struct e1000_hw *hw = nic->priv;
/* Turn off the ethernet interface */
E1000_WRITE_REG(hw, RCTL, 0);
E1000_WRITE_REG(hw, TCTL, 0);
/* Clear the transmit ring */
E1000_WRITE_REG(hw, TDH, 0);
E1000_WRITE_REG(hw, TDT, 0);
/* Clear the receive ring */
E1000_WRITE_REG(hw, RDH, 0);
E1000_WRITE_REG(hw, RDT, 0);
/* put the card in its initial state */
#if 0
E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
#endif
mdelay(10);
}
/**************************************************************************
INIT - set up ethernet interface(s)
***************************************************************************/
static int
e1000_init(struct eth_device *nic, bd_t * bis)
{
struct e1000_hw *hw = nic->priv;
int ret_val = 0;
ret_val = e1000_reset(nic);
if (ret_val < 0) {
if ((ret_val == -E1000_ERR_NOLINK) ||
(ret_val == -E1000_ERR_TIMEOUT)) {
E1000_ERR(hw->nic, "Valid Link not detected\n");
E1000_ERR(hw->nic, "Hardware Initialization Failed\n");
}
return 0;
}
e1000_configure_tx(hw);
e1000_setup_rctl(hw);
e1000_configure_rx(hw);
return 1;
}
/******************************************************************************
* Gets the current PCI bus type of hardware
*
* hw - Struct containing variables accessed by shared code
*****************************************************************************/
void e1000_get_bus_type(struct e1000_hw *hw)
{
uint32_t status;
switch (hw->mac_type) {
case e1000_82542_rev2_0:
case e1000_82542_rev2_1:
hw->bus_type = e1000_bus_type_pci;
break;
case e1000_82571:
case e1000_82572:
case e1000_82573:
case e1000_80003es2lan:
hw->bus_type = e1000_bus_type_pci_express;
break;
case e1000_ich8lan:
hw->bus_type = e1000_bus_type_pci_express;
break;
default:
status = E1000_READ_REG(hw, STATUS);
hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
e1000_bus_type_pcix : e1000_bus_type_pci;
break;
}
}
/* A list of all registered e1000 devices */
static LIST_HEAD(e1000_hw_list);
/**************************************************************************
PROBE - Look for an adapter, this routine's visible to the outside
You should omit the last argument struct pci_device * for a non-PCI NIC
***************************************************************************/
int
e1000_initialize(bd_t * bis)
{
/* Find and probe all the matching PCI devices */
for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
u32 val;
/*
* These will never get freed due to errors, this allows us to
* perform SPI EEPROM programming from U-boot, for example.
*/
struct eth_device *nic = malloc(sizeof(*nic));
struct e1000_hw *hw = malloc(sizeof(*hw));
if (!nic || !hw) {
printf("e1000#%u: Out of Memory!\n", i);
free(hw);
continue;
/* Make sure all of the fields are initially zeroed */
memset(nic, 0, sizeof(*nic));
memset(hw, 0, sizeof(*hw));
/* Assign the passed-in values */
hw->cardnum = i;
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
/* Generate a card name */
sprintf(nic->name, "e1000#%u", hw->cardnum);
/* Print a debug message with the IO base address */
pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
E1000_DBG(nic, "iobase 0x%08x\n", val & 0xfffffff0);
/* Try to enable I/O accesses and bus-mastering */
val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
pci_write_config_dword(devno, PCI_COMMAND, val);
/* Make sure it worked */
pci_read_config_dword(devno, PCI_COMMAND, &val);
if (!(val & PCI_COMMAND_MEMORY)) {
E1000_ERR(nic, "Can't enable I/O memory\n");
continue;
}
if (!(val & PCI_COMMAND_MASTER)) {
E1000_ERR(nic, "Can't enable bus-mastering\n");
continue;
}
/* Are these variables needed? */
hw->fc = e1000_fc_default;
hw->original_fc = e1000_fc_default;
hw->autoneg_failed = 0;
hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
PCI_REGION_MEM);
hw->mac_type = e1000_undefined;
/* MAC and Phy settings */
if (e1000_sw_init(nic) < 0) {
E1000_ERR(nic, "Software init failed\n");
continue;
E1000_ERR(nic, "PHY Reset is blocked!\n");
/* Basic init was OK, reset the hardware and allow SPI access */
list_add_tail(&hw->list_node, &e1000_hw_list);
/* Validate the EEPROM and get chipset information */
E1000_ERR(nic, "EEPROM is invalid!\n");
continue;
if (e1000_validate_eeprom_checksum(hw))
printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
/* Set up the function pointers and register the device */
nic->init = e1000_init;
nic->recv = e1000_poll;
nic->send = e1000_transmit;
nic->halt = e1000_disable;
eth_register(nic);
}
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
struct e1000_hw *e1000_find_card(unsigned int cardnum)
{
struct e1000_hw *hw;
list_for_each_entry(hw, &e1000_hw_list, list_node)
if (hw->cardnum == cardnum)
return hw;
return NULL;
}
#ifdef CONFIG_CMD_E1000
static int do_e1000(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
struct e1000_hw *hw;
if (argc < 3) {
cmd_usage(cmdtp);
return 1;
}
/* Make sure we can find the requested e1000 card */
hw = e1000_find_card(simple_strtoul(argv[1], NULL, 10));
if (!hw) {
printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
return 1;
}
if (!strcmp(argv[2], "print-mac-address")) {
unsigned char *mac = hw->nic->enetaddr;
printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return 0;
}
#ifdef CONFIG_E1000_SPI
/* Handle the "SPI" subcommand */
if (!strcmp(argv[2], "spi"))
return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
#endif
cmd_usage(cmdtp);
return 1;
}
U_BOOT_CMD(
e1000, 7, 0, do_e1000,
"Intel e1000 controller management",
/* */"<card#> print-mac-address\n"
#ifdef CONFIG_E1000_SPI
"e1000 <card#> spi show [<offset> [<length>]]\n"
"e1000 <card#> spi dump <addr> <offset> <length>\n"
"e1000 <card#> spi program <addr> <offset> <length>\n"
"e1000 <card#> spi checksum [update]\n"
#endif
" - Manage the Intel E1000 PCI device"
);
#endif /* not CONFIG_CMD_E1000 */