bfe.c revision dd52495f0d9ba8ff6d84921ec0500be837896554
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi * CDDL HEADER START
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * The contents of this file are subject to the terms of the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Common Development and Distribution License (the "License").
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * You may not use this file except in compliance with the License.
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * or http://www.opensolaris.org/os/licensing.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * See the License for the specific language governing permissions
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * and limitations under the License.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * When distributing Covered Code, include this CDDL HEADER in each
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * If applicable, add the following below this CDDL HEADER, with the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * CDDL HEADER END
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Use is subject to license terms.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/stream.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/strsun.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/stat.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/pci.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/modctl.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/kstat.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/ethernet.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/devops.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/debug.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/conf.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/sysmacros.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/dditypes.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/ddi.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/sunddi.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/miiregs.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/byteorder.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/cyclic.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/note.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/crc32.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/mac_provider.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/mac_ether.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/vlan.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/errno.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/sdt.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include <sys/strsubr.h>
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include "bfe.h"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#include "bfe_hw.h"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Broadcom BCM4401 chipsets use two rings :
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * - One TX : For sending packets down the wire.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * - One RX : For receving packets.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Each ring can have any number of descriptors (configured during attach).
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * As of now we configure only 128 descriptor per ring (TX/RX). Each descriptor
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * has address (desc_addr) and control (desc_ctl) which holds a DMA buffer for
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * the packet and control information (like start/end of frame or end of table).
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * The descriptor table is allocated first and then a DMA buffer (for a packet)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * is allocated and linked to each descriptor.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Each descriptor entry is bfe_desc_t structure in bfe. During TX/RX
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * interrupt, the stat register will point to current descriptor being
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * processed.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Here's an example of TX and RX ring :
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * TX:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Base of the descriptor table is programmed using BFE_DMATX_CTRL control
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * register. Each 'addr' points to DMA buffer (or packet data buffer) to
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * be transmitted and 'ctl' has the length of the packet (usually MTU).
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | addr |Descriptor 0 |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ctl | |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | addr |Descriptor 1 | SOF (start of the frame)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ctl | |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ... |Descriptor... | EOF (end of the frame)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ... | |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | addr |Descritor 127 |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ctl | EOT | EOT (End of Table)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * 'r_curr_desc' : pointer to current descriptor which can be used to transmit
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * a packet.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * 'r_avail_desc' : decremented whenever a packet is being sent.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * 'r_cons_desc' : incremented whenever a packet is sent down the wire and
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * notified by an interrupt to bfe driver.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * RX:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Base of the descriptor table is programmed using BFE_DMARX_CTRL control
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * register. Each 'addr' points to DMA buffer (or packet data buffer). 'ctl'
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * contains the size of the DMA buffer and all the DMA buffers are
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * pre-allocated during attach and hence the maxmium size of the packet is
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * also known (r_buf_len from the bfe_rint_t structure). During RX interrupt
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * the packet length is embedded in bfe_header_t which is added by the
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * chip in the beginning of the packet.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | addr |Descriptor 0 |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ctl | |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | addr |Descriptor 1 |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ctl | |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ... |Descriptor... |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ... | |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | addr |Descriptor 127|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * | ctl | EOT | EOT (End of Table)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * ----------------------|
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * 'r_curr_desc' : pointer to current descriptor while receving a packet.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define MODULE_NAME "bfe"
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Used for checking PHY (link state, speed)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define BFE_TIMEOUT_INTERVAL (1000 * 1000 * 1000)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Chip restart action and reason for restart
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define BFE_ACTION_RESTART 0x1 /* For restarting the chip */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define BFE_ACTION_RESTART_SETPROP 0x2 /* restart due to setprop */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define BFE_ACTION_RESTART_FAULT 0x4 /* restart due to fault */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define BFE_ACTION_RESTART_PKT 0x8 /* restart due to pkt timeout */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic char bfe_ident[] = "bfe driver for Broadcom BCM4401 chipsets";
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Function Prototypes for bfe driver.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int bfe_check_link(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_report_link(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_chip_halt(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_chip_reset(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_tx_desc_init(bfe_ring_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_rx_desc_init(bfe_ring_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_set_rx_mode(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_enable_chip_intrs(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_chip_restart(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_init_vars(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_clear_stats(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_gather_stats(bfe_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void bfe_error(dev_info_t *, char *, ...);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int bfe_mac_getprop(void *, const char *, mac_prop_id_t, uint_t,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint_t, void *, uint_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int bfe_mac_setprop(void *, const char *, mac_prop_id_t, uint_t,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe const void *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int bfe_tx_reclaim(bfe_ring_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Loweint bfe_mac_set_ether_addr(void *, const uint8_t *);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Macros for ddi_dma_sync().
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define SYNC_DESC(r, s, l, d) \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) ddi_dma_sync(r->r_desc_dma_handle, \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (off_t)(s * sizeof (bfe_desc_t)), \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (size_t)(l * sizeof (bfe_desc_t)), \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe d)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define SYNC_BUF(r, s, b, l, d) \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) ddi_dma_sync(r->r_buf_dma[s].handle, \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (off_t)(b), (size_t)(l), d)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Supported Broadcom BCM4401 Cards.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic bfe_cards_t bfe_cards[] = {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe { 0x14e4, 0x170c, "BCM4401 100Base-TX"},
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * DMA attributes for device registers, packet data (buffer) and
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * descriptor table.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic struct ddi_device_acc_attr bfe_dev_attr = {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_DEVICE_ATTR_V0,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_STRUCTURE_LE_ACC,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_STRICTORDER_ACC
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic struct ddi_device_acc_attr bfe_buf_attr = {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_DEVICE_ATTR_V0,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_NEVERSWAP_ACC, /* native endianness */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_STRICTORDER_ACC
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic ddi_dma_attr_t bfe_dma_attr_buf = {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DMA_ATTR_V0, /* dma_attr_version */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0, /* dma_attr_addr_lo */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_PCI_DMA - 1, /* dma_attr_addr_hi */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0x1fff, /* dma_attr_count_max */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 8, /* dma_attr_align */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0, /* dma_attr_burstsizes */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 1, /* dma_attr_minxfer */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0x1fff, /* dma_attr_maxxfer */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_PCI_DMA - 1, /* dma_attr_seg */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 1, /* dma_attr_sgllen */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 1, /* dma_attr_granular */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0 /* dma_attr_flags */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic ddi_dma_attr_t bfe_dma_attr_desc = {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DMA_ATTR_V0, /* dma_attr_version */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0, /* dma_attr_addr_lo */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_PCI_DMA - 1, /* dma_attr_addr_hi */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_PCI_DMA - 1, /* dma_attr_count_max */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_DESC_ALIGN, /* dma_attr_align */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0, /* dma_attr_burstsizes */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 1, /* dma_attr_minxfer */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_PCI_DMA - 1, /* dma_attr_maxxfer */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_PCI_DMA - 1, /* dma_attr_seg */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 1, /* dma_attr_sgllen */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 1, /* dma_attr_granular */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0 /* dma_attr_flags */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Ethernet broadcast addresses.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic uchar_t bfe_broadcast[ETHERADDRL] = {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe#define ASSERT_ALL_LOCKS(bfe) { \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ASSERT(mutex_owned(&bfe->bfe_tx_ring.r_lock)); \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ASSERT(rw_write_held(&bfe->bfe_rwlock)); \
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Debugging and error reproting code.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_error(dev_info_t *dip, char *fmt, ...)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe va_list ap;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe char buf[256];
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe va_start(ap, fmt);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) vsnprintf(buf, sizeof (buf), fmt, ap);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe va_end(ap);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (dip) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe cmn_err(CE_WARN, "%s%d: %s",
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ddi_driver_name(dip), ddi_get_instance(dip), buf);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe cmn_err(CE_WARN, "bfe: %s", buf);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Grabs all necessary locks to block any other operation on the chip.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_grab_locks(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_ring_t *tx = &bfe->bfe_tx_ring;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Grab all the locks.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * - bfe_rwlock : locks down whole chip including RX.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * - tx's r_lock : locks down only TX side.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe rw_enter(&bfe->bfe_rwlock, RW_WRITER);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe mutex_enter(&tx->r_lock);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Note that we don't use RX's r_lock.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Release lock on chip/drver.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_release_locks(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_ring_t *tx = &bfe->bfe_tx_ring;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Release all the locks in the order in which they were grabbed.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe mutex_exit(&tx->r_lock);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe rw_exit(&bfe->bfe_rwlock);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * It's used to make sure that the write to device register was successful.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_wait_bit(bfe_t *bfe, uint32_t reg, uint32_t bit,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ulong_t t, const int clear)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ulong_t i;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t v;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < t; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = INL(bfe, reg);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (clear && !(v & bit))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe break;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (!clear && (v & bit))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe break;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(10);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* if device still didn't see the value */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (i == t)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (-1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * PHY functions (read, write, stop, reset and startup)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_read_phy(bfe_t *bfe, uint32_t reg)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_MDIO_DATA, (BFE_MDIO_SB_START |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (BFE_MDIO_OP_READ << BFE_MDIO_OP_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (bfe->bfe_phy_addr << BFE_MDIO_PMD_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (reg << BFE_MDIO_RA_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (BFE_MDIO_TA_VALID << BFE_MDIO_TA_SHIFT)));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII, 10, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return ((INL(bfe, BFE_MDIO_DATA) & BFE_MDIO_DATA_DATA));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_write_phy(bfe_t *bfe, uint32_t reg, uint32_t val)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_MDIO_DATA, (BFE_MDIO_SB_START |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (BFE_MDIO_OP_WRITE << BFE_MDIO_OP_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (bfe->bfe_phy_addr << BFE_MDIO_PMD_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (reg << BFE_MDIO_RA_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (BFE_MDIO_TA_VALID << BFE_MDIO_TA_SHIFT) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (val & BFE_MDIO_DATA_DATA)));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_EMAC_ISTAT, BFE_EMAC_INT_MII, 10, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * It resets the PHY layer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_reset_phy(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t i;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_write_phy(bfe, MII_CONTROL, MII_CONTROL_RESET);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(100);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < 10; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe_read_phy(bfe, MII_CONTROL) &
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe MII_CONTROL_RESET) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(500);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe continue;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe break;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (i == 10) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_error(bfe->bfe_dip, "Timeout waiting for PHY to reset");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_state = BFE_PHY_RESET_TIMEOUT;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_FAILURE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_state = BFE_PHY_RESET_DONE;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_SUCCESS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Make sure timer function is out of our way and especially during
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * detach.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_stop_timer(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_periodic_id) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ddi_periodic_delete(bfe->bfe_periodic_id);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_periodic_id = NULL;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Stops the PHY
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_stop_phy(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_write_phy(bfe, MII_CONTROL, MII_CONTROL_PWRDN |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe MII_CONTROL_ISOLATE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.link = LINK_STATE_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_state = BFE_PHY_STOPPED;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Report the link status to MAC layer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_machdl != NULL)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_report_link(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchibfe_probe_phy(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int phy;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t status;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_phy_addr) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe status = bfe_read_phy(bfe, MII_STATUS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (status != 0xffff && status != 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_write_phy(bfe, MII_CONTROL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_SUCCESS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (phy = 0; phy < 32; phy++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_addr = phy;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe status = bfe_read_phy(bfe, MII_STATUS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (status != 0xffff && status != 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_write_phy(bfe, MII_CONTROL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_SUCCESS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_FAILURE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * This timeout function fires at BFE_TIMEOUT_INTERVAL to check the link
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * status.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_timeout(void *arg)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_t *bfe = (bfe_t *)arg;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * We don't grab any lock because bfe can't go away.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * untimeout() will wait for this timeout instance to complete.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_chip_action & BFE_ACTION_RESTART) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Restart the chip.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_grab_locks(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_chip_restart(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_action &= ~BFE_ACTION_RESTART;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_action &= ~BFE_ACTION_RESTART_FAULT;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_action &= ~BFE_ACTION_RESTART_PKT;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_release_locks(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe mac_tx_update(bfe->bfe_machdl);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Restart will register a new timeout */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe rw_enter(&bfe->bfe_rwlock, RW_READER);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_chip_state == BFE_CHIP_ACTIVE) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe hrtime_t hr;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe hr = gethrtime();
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_tx_stall_time != 0 &&
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe hr > bfe->bfe_tx_stall_time) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DTRACE_PROBE2(chip__restart, int, bfe->bfe_unit,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe char *, "pkt timeout");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_action |=
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (BFE_ACTION_RESTART | BFE_ACTION_RESTART_PKT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_tx_stall_time = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_phy_state == BFE_PHY_STARTED) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Report the link status to MAC layer if link status changed.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe_check_link(bfe)) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_report_link(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_chip.link == LINK_STATE_UP) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t val, flow;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_TX_CTRL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val &= ~BFE_TX_DUPLEX;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_chip.duplex == LINK_DUPLEX_FULL) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val |= BFE_TX_DUPLEX;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe flow = INL(bfe, BFE_RXCONF);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe flow &= ~BFE_RXCONF_FLOW;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_RXCONF, flow);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe flow = INL(bfe, BFE_MAC_FLOW);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe flow &= ~(BFE_FLOW_RX_HIWAT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_MAC_FLOW, flow);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_TX_CTRL, val);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DTRACE_PROBE1(link__up,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int, bfe->bfe_unit);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe rw_exit(&bfe->bfe_rwlock);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Starts PHY layer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_startup_phy(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint16_t bmsr, bmcr, anar;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int prog, s;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int phyid1, phyid2;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe_probe_phy(bfe) == BFE_FAILURE) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_state = BFE_PHY_NOTFOUND;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_FAILURE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_reset_phy(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe phyid1 = bfe_read_phy(bfe, MII_PHYIDH);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe phyid2 = bfe_read_phy(bfe, MII_PHYIDL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_id = (phyid1 << 16) | phyid2;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmsr = bfe_read_phy(bfe, MII_STATUS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar = bfe_read_phy(bfe, MII_AN_ADVERT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Loweagain:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar &= ~(MII_ABILITY_100BASE_T4 |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe MII_ABILITY_100BASE_TX_FD | MII_ABILITY_100BASE_TX |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe MII_ABILITY_10BASE_T_FD | MII_ABILITY_10BASE_T);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Supported hardware modes are in bmsr.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.bmsr = bmsr;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Assume no capabilities are supported in the hardware.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_aneg = bfe->bfe_cap_100T4 =
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_100fdx = bfe->bfe_cap_100hdx =
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_10fdx = bfe->bfe_cap_10hdx = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Assume property is set.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe s = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (!(bfe->bfe_chip_action & BFE_ACTION_RESTART_SETPROP)) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Property is not set which means bfe_mac_setprop()
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * is not called on us.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe s = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = prog = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmsr & MII_STATUS_100_BASEX_FD) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_100fdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_100BASE_TX_FD;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_adv_100fdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (bfe->bfe_adv_100fdx) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_100BASE_TX_FD;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmsr & MII_STATUS_100_BASE_T4) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_100T4 = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_100BASE_T4;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_adv_100T4 = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (bfe->bfe_adv_100T4) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_100BASE_T4;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmsr & MII_STATUS_100_BASEX) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_100hdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_100BASE_TX;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_adv_100hdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (bfe->bfe_adv_100hdx) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_100BASE_TX;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmsr & MII_STATUS_10_FD) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_10fdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_10BASE_T_FD;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_adv_10fdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (bfe->bfe_adv_10fdx) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_10BASE_T_FD;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmsr & MII_STATUS_10) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_10hdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_10BASE_T;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_adv_10hdx = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (bfe->bfe_adv_10hdx) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar |= MII_ABILITY_10BASE_T;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe prog++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmsr & MII_STATUS_CANAUTONEG) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_cap_aneg = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_adv_aneg = 1;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (prog == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (s == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_error(bfe->bfe_dip,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe "No valid link mode selected. Powering down PHY");
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_stop_phy(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_report_link(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_FAILURE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * If property is set then user would have goofed up. So we
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * go back to default properties.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_action &= ~BFE_ACTION_RESTART_SETPROP;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe goto again;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_adv_aneg && (bmsr & MII_STATUS_CANAUTONEG)) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = (MII_CONTROL_ANE | MII_CONTROL_RSAN);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_adv_100fdx)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = (MII_CONTROL_100MB | MII_CONTROL_FDUPLEX);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe else if (bfe->bfe_adv_100hdx)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = MII_CONTROL_100MB;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe else if (bfe->bfe_adv_10fdx)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = MII_CONTROL_FDUPLEX;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe else
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = 0; /* 10HDX */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (prog)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_write_phy(bfe, MII_AN_ADVERT, anar);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmcr)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_write_phy(bfe, MII_CONTROL, bmcr);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_anar = anar;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_bmcr = bmcr;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_phy_state = BFE_PHY_STARTED;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_periodic_id == NULL) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_periodic_id = ddi_periodic_add(bfe_timeout,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void *)bfe, BFE_TIMEOUT_INTERVAL, DDI_IPL_0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DTRACE_PROBE1(first__timeout, int, bfe->bfe_unit);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DTRACE_PROBE4(phy_started, int, bfe->bfe_unit,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int, bmsr, int, bmcr, int, anar);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (BFE_SUCCESS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Reports link status back to MAC Layer.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_report_link(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe mac_link_update(bfe->bfe_machdl, bfe->bfe_chip.link);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Reads PHY/MII registers and get the link status for us.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_check_link(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint16_t bmsr, bmcr, anar, anlpar;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int speed, duplex, link;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe speed = bfe->bfe_chip.speed;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe duplex = bfe->bfe_chip.duplex;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe link = bfe->bfe_chip.link;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmsr = bfe_read_phy(bfe, MII_STATUS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_bmsr = bmsr;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bmcr = bfe_read_phy(bfe, MII_CONTROL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anar = bfe_read_phy(bfe, MII_AN_ADVERT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_anar = anar;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe anlpar = bfe_read_phy(bfe, MII_AN_LPABLE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_anlpar = anlpar;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_exp = bfe_read_phy(bfe, MII_AN_EXPANSION);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * If exp register is not present in PHY.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_mii_exp == 0xffff) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_mii_exp = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if ((bmsr & MII_STATUS_LINKUP) == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.link = LINK_STATE_DOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe goto done;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.link = LINK_STATE_UP;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (!(bmcr & MII_CONTROL_ANE)) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Forced mode */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmcr & MII_CONTROL_100MB)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 100000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe else
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 10000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bmcr & MII_CONTROL_FDUPLEX)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_FULL;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe else
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_HALF;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if ((!(bmsr & MII_STATUS_CANAUTONEG)) ||
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (!(bmsr & MII_STATUS_ANDONE))) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (anar & anlpar & MII_ABILITY_100BASE_TX_FD) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 100000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_FULL;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (anar & anlpar & MII_ABILITY_100BASE_T4) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 100000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_HALF;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (anar & anlpar & MII_ABILITY_100BASE_TX) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 100000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_HALF;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (anar & anlpar & MII_ABILITY_10BASE_T_FD) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 10000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_FULL;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (anar & anlpar & MII_ABILITY_10BASE_T) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 10000000;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_HALF;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowedone:
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * If speed or link status or duplex mode changed then report to
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * MAC layer which is done by the caller.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (speed != bfe->bfe_chip.speed ||
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe duplex != bfe->bfe_chip.duplex ||
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe link != bfe->bfe_chip.link) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_cam_write(bfe_t *bfe, uchar_t *d, int index)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t v;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = ((uint32_t)d[2] << 24);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v |= ((uint32_t)d[3] << 16);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v |= ((uint32_t)d[4] << 8);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v |= (uint32_t)d[5];
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_CAM_DATA_LO, v);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = (BFE_CAM_HI_VALID |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (((uint32_t)d[0]) << 8) |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (((uint32_t)d[1])));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_CAM_DATA_HI, v);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_CAM_CTRL, (BFE_CAM_WRITE |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ((uint32_t)index << BFE_CAM_INDEX_SHIFT)));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_CAM_CTRL, BFE_CAM_BUSY, 10, 1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Chip related functions (halt, reset, start).
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi */
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchistatic void
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchibfe_chip_halt(bfe_t *bfe)
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi{
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi /*
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi * Disables interrupts.
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi */
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi OUTL(bfe, BFE_INTR_MASK, 0);
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi FLUSH(bfe, BFE_INTR_MASK);
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi OUTL(bfe, BFE_ENET_CTRL, BFE_ENET_DISABLE);
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi /*
43051d2742bbe5911de73322064cb573b6aff975Robert Mustacchi * Wait until TX and RX finish their job.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_ENET_CTRL, BFE_ENET_DISABLE, 20, 1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Disables DMA engine.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMARX_CTRL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMATX_CTRL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(10);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_state = BFE_CHIP_HALT;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_chip_restart(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DTRACE_PROBE2(chip__restart, int, bfe->bfe_unit,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int, bfe->bfe_chip_action);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Halt chip and PHY.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_chip_halt(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_stop_phy(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_state = BFE_CHIP_STOPPED;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Init variables.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_init_vars(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Reset chip and start PHY.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_chip_reset(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * DMA descriptor rings.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_tx_desc_init(&bfe->bfe_tx_ring);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_rx_desc_init(&bfe->bfe_rx_ring);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_state = BFE_CHIP_ACTIVE;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_set_rx_mode(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_enable_chip_intrs(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Disables core by stopping the clock.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_core_disable(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if ((INL(bfe, BFE_SBTMSLOW) & BFE_RESET))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSLOW, (BFE_REJECT | BFE_CLOCK));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_SBTMSLOW, BFE_REJECT, 100, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_SBTMSHIGH, BFE_BUSY, 100, 1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSLOW, (BFE_FGC | BFE_CLOCK | BFE_REJECT | BFE_RESET));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_SBTMSLOW);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(10);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSLOW, (BFE_REJECT | BFE_RESET));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(10);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Resets core.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_core_reset(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t val;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * First disable the core.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_core_disable(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSLOW, (BFE_RESET | BFE_CLOCK | BFE_FGC));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_SBTMSLOW);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (INL(bfe, BFE_SBTMSHIGH) & BFE_SERR)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSHIGH, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_SBIMSTATE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (val & (BFE_IBE | BFE_TO))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBIMSTATE, val & ~(BFE_IBE | BFE_TO));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSLOW, (BFE_CLOCK | BFE_FGC));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_SBTMSLOW);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBTMSLOW, BFE_CLOCK);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_SBTMSLOW);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_setup_config(bfe_t *bfe, uint32_t cores)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t bar_orig, val;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Change bar0 window to map sbtopci registers.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bar_orig = pci_config_get32(bfe->bfe_conf_handle, BFE_BAR0_WIN);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe pci_config_put32(bfe->bfe_conf_handle, BFE_BAR0_WIN, BFE_REG_PCI);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Just read it and don't do anything */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_SBIDHIGH) & BFE_IDH_CORE;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_SBINTVEC);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val |= cores;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SBINTVEC, val);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_SSB_PCI_TRANS_2);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val |= BFE_SSB_PCI_PREF | BFE_SSB_PCI_BURST;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_SSB_PCI_TRANS_2, val);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Restore bar0 window mapping.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe pci_config_put32(bfe->bfe_conf_handle, BFE_BAR0_WIN, bar_orig);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Resets chip and starts PHY.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_chip_reset(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t val;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Set the interrupt vector for the enet core */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_setup_config(bfe, BFE_INTVEC_ENET0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* check if core is up */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_SBTMSLOW) &
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (BFE_RESET | BFE_REJECT | BFE_CLOCK);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (val == BFE_CLOCK) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_RCV_LAZY, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_ENET_CTRL, BFE_ENET_DISABLE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_ENET_CTRL,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_ENET_DISABLE, 10, 1);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMATX_CTRL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_DMARX_STAT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(20000); /* 20 milli seconds */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (INL(bfe, BFE_DMARX_STAT) & BFE_STAT_EMASK) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_wait_bit(bfe, BFE_DMARX_STAT, BFE_STAT_SIDLE,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe 10, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMARX_CTRL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_core_reset(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_clear_stats(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_MDIO_CTRL, 0x8d);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_DEVCTRL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (!(val & BFE_IPP))
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_ENET_CTRL, BFE_ENET_EPSEL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe else if (INL(bfe, BFE_DEVCTRL & BFE_EPR)) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL_AND(bfe, BFE_DEVCTRL, ~BFE_EPR);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe drv_usecwait(20000); /* 20 milli seconds */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL_OR(bfe, BFE_MAC_CTRL, BFE_CTRL_CRC32_ENAB | BFE_CTRL_LED);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL_AND(bfe, BFE_MAC_CTRL, ~BFE_CTRL_PDOWN);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_RCV_LAZY, ((1 << BFE_LAZY_FC_SHIFT) &
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_LAZY_FC_MASK));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL_OR(bfe, BFE_RCV_LAZY, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_RXMAXLEN, bfe->bfe_rx_ring.r_buf_len);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_TXMAXLEN, bfe->bfe_tx_ring.r_buf_len);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_TX_WMARK, 56);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Program DMA channels */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMATX_CTRL, BFE_TX_CTRL_ENABLE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * DMA addresses need to be added to BFE_PCI_DMA
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMATX_ADDR,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_tx_ring.r_desc_cookie.dmac_laddress + BFE_PCI_DMA);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMARX_CTRL, (BFE_RX_OFFSET << BFE_RX_CTRL_ROSHIFT)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe | BFE_RX_CTRL_ENABLE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_DMARX_ADDR,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_rx_ring.r_desc_cookie.dmac_laddress + BFE_PCI_DMA);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_startup_phy(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_state = BFE_CHIP_INITIALIZED;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * It enables interrupts. Should be the last step while starting chip.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_enable_chip_intrs(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Enable the chip and core */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_ENET_CTRL, BFE_ENET_ENABLE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Enable interrupts */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_INTR_MASK, BFE_IMASK_DEF);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Common code to take care of setting RX side mode (filter).
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_set_rx_mode(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t val;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int i;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ether_addr_t mac[ETHERADDRL] = {0, 0, 0, 0, 0, 0};
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * We don't touch RX filter if we were asked to suspend. It's fine
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * if chip is not active (no interface is plumbed on us).
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_chip_state == BFE_CHIP_SUSPENDED)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val = INL(bfe, BFE_RXCONF);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val &= ~BFE_RXCONF_PROMISC;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val &= ~BFE_RXCONF_DBCAST;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if ((bfe->bfe_chip_mode & BFE_RX_MODE_ENABLE) == 0) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_CAM_CTRL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_CAM_CTRL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else if (bfe->bfe_chip_mode & BFE_RX_MODE_PROMISC) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val |= BFE_RXCONF_PROMISC;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val &= ~BFE_RXCONF_DBCAST;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe } else {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe if (bfe->bfe_chip_state == BFE_CHIP_ACTIVE) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Flush everything */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_RXCONF, val |
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe BFE_RXCONF_PROMISC | BFE_RXCONF_ALLMULTI);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_RXCONF);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Disable CAM */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_CAM_CTRL, 0);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_CAM_CTRL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * We receive all multicast packets.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe val |= BFE_RXCONF_ALLMULTI;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < BFE_MAX_MULTICAST_TABLE - 1; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_cam_write(bfe, (uchar_t *)mac, i);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_cam_write(bfe, bfe->bfe_ether_addr, i);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Enable CAM */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL_OR(bfe, BFE_CAM_CTRL, BFE_CAM_ENABLE);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_CAM_CTRL);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DTRACE_PROBE2(rx__mode__filter, int, bfe->bfe_unit,
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int, val);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_RXCONF, val);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe FLUSH(bfe, BFE_RXCONF);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Reset various variable values to initial state.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_init_vars(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_mode = BFE_RX_MODE_ENABLE;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Initial assumption */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.link = LINK_STATE_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.speed = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip.duplex = LINK_DUPLEX_UNKNOWN;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_periodic_id = NULL;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_state = BFE_CHIP_UNINITIALIZED;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_tx_stall_time = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Initializes TX side descriptor entries (bfe_desc_t). Each descriptor entry
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * has control (desc_ctl) and address (desc_addr) member.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_tx_desc_init(bfe_ring_t *r)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int i;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t v;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < r->r_ndesc; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe PUT_DESC(r, (uint32_t *)&(r->r_desc[i].desc_ctl),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (r->r_buf_dma[i].len & BFE_DESC_LEN));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * DMA addresses need to be added to BFE_PCI_DMA
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe PUT_DESC(r, (uint32_t *)&(r->r_desc[i].desc_addr),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (r->r_buf_dma[i].cookie.dmac_laddress + BFE_PCI_DMA));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = GET_DESC(r, (uint32_t *)&(r->r_desc[i - 1].desc_ctl));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe PUT_DESC(r, (uint32_t *)&(r->r_desc[i - 1].desc_ctl),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v | BFE_DESC_EOT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) SYNC_DESC(r, 0, r->r_ndesc, DDI_DMA_SYNC_FORDEV);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe r->r_curr_desc = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe r->r_avail_desc = TX_NUM_DESC;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe r->r_cons_desc = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Initializes RX side descriptor entries (bfe_desc_t). Each descriptor entry
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * has control (desc_ctl) and address (desc_addr) member.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_rx_desc_init(bfe_ring_t *r)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe int i;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t v;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (i = 0; i < r->r_ndesc; i++) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe PUT_DESC(r, (uint32_t *)&(r->r_desc[i].desc_ctl),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (r->r_buf_dma[i].len& BFE_DESC_LEN));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe PUT_DESC(r, (uint32_t *)&(r->r_desc[i].desc_addr),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (r->r_buf_dma[i].cookie.dmac_laddress + BFE_PCI_DMA));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Initialize rx header (len, flags) */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bzero(r->r_buf_dma[i].addr, sizeof (bfe_rx_header_t));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) SYNC_BUF(r, i, 0, sizeof (bfe_rx_header_t),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe DDI_DMA_SYNC_FORDEV);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = GET_DESC(r, (uint32_t *)&(r->r_desc[i - 1].desc_ctl));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe PUT_DESC(r, (uint32_t *)&(r->r_desc[i - 1].desc_ctl),
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v | BFE_DESC_EOT);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) SYNC_DESC(r, 0, r->r_ndesc, DDI_DMA_SYNC_FORDEV);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* TAIL of RX Descriptor */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(r->r_bfe, BFE_DMARX_PTR, ((i) * sizeof (bfe_desc_t)));
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe r->r_curr_desc = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe r->r_avail_desc = RX_NUM_DESC;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic int
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_chip_start(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_grab_locks(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Stop the chip first & then Reset the chip. At last enable interrupts.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_chip_halt(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_stop_phy(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Reset chip and start PHY.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_chip_reset(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Initailize Descriptor Rings.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_tx_desc_init(&bfe->bfe_tx_ring);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_rx_desc_init(&bfe->bfe_rx_ring);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_state = BFE_CHIP_ACTIVE;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe->bfe_chip_mode |= BFE_RX_MODE_ENABLE;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_set_rx_mode(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_enable_chip_intrs(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /* Check link, speed and duplex mode */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) bfe_check_link(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe bfe_release_locks(bfe);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe mac_tx_update(bfe->bfe_machdl);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe return (DDI_SUCCESS);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Clear chip statistics.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_clear_stats(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ulong_t r;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe OUTL(bfe, BFE_MIB_CTRL, BFE_MIB_CLR_ON_READ);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Stat registers are cleared by reading.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (r = BFE_TX_GOOD_O; r <= BFE_TX_PAUSE; r += 4)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) INL(bfe, r);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (r = BFE_RX_GOOD_O; r <= BFE_RX_NPAUSE; r += 4)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe (void) INL(bfe, r);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe}
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe/*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * Collect chip statistics.
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe */
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowestatic void
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowebfe_gather_stats(bfe_t *bfe)
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe{
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe ulong_t r;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t *v;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe uint32_t txerr = 0, rxerr = 0, coll = 0;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = &bfe->bfe_hw_stats.tx_good_octets;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (r = BFE_TX_GOOD_O; r <= BFE_TX_PAUSE; r += 4) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *v += INL(bfe, r);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v = &bfe->bfe_hw_stats.rx_good_octets;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe for (r = BFE_RX_GOOD_O; r <= BFE_RX_NPAUSE; r += 4) {
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *v += INL(bfe, r);
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe v++;
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe }
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe /*
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * TX :
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * -------
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_good_octets, tx_good_pkts, tx_octets
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_pkts, tx_broadcast_pkts, tx_multicast_pkts
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_len_64, tx_len_65_to_127, tx_len_128_to_255
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_len_256_to_511, tx_len_512_to_1023, tx_len_1024_to_max
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_jabber_pkts, tx_oversize_pkts, tx_fragment_pkts
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_underruns, tx_total_cols, tx_single_cols
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_multiple_cols, tx_excessive_cols, tx_late_cols
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * tx_defered, tx_carrier_lost, tx_pause_pkts
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe *
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * RX :
c10c16dec587a0662068f6e2991c29ed3a9db943Richard Lowe * -------
* rx_good_octets, rx_good_pkts, rx_octets
* rx_pkts, rx_broadcast_pkts, rx_multicast_pkts
* rx_len_64, rx_len_65_to_127, rx_len_128_to_255
* rx_len_256_to_511, rx_len_512_to_1023, rx_len_1024_to_max
* rx_jabber_pkts, rx_oversize_pkts, rx_fragment_pkts
* rx_missed_pkts, rx_crc_align_errs, rx_undersize
* rx_crc_errs, rx_align_errs, rx_symbol_errs
* rx_pause_pkts, rx_nonpause_pkts
*/
bfe->bfe_stats.ether_stat_carrier_errors =
bfe->bfe_hw_stats.tx_carrier_lost;
/* txerr += bfe->bfe_hw_stats.tx_carrier_lost; */
bfe->bfe_stats.ether_stat_ex_collisions =
bfe->bfe_hw_stats.tx_excessive_cols;
txerr += bfe->bfe_hw_stats.tx_excessive_cols;
coll += bfe->bfe_hw_stats.tx_excessive_cols;
bfe->bfe_stats.ether_stat_fcs_errors =
bfe->bfe_hw_stats.rx_crc_errs;
rxerr += bfe->bfe_hw_stats.rx_crc_errs;
bfe->bfe_stats.ether_stat_first_collisions =
bfe->bfe_hw_stats.tx_single_cols;
coll += bfe->bfe_hw_stats.tx_single_cols;
bfe->bfe_stats.ether_stat_multi_collisions =
bfe->bfe_hw_stats.tx_multiple_cols;
coll += bfe->bfe_hw_stats.tx_multiple_cols;
bfe->bfe_stats.ether_stat_toolong_errors =
bfe->bfe_hw_stats.rx_oversize_pkts;
rxerr += bfe->bfe_hw_stats.rx_oversize_pkts;
bfe->bfe_stats.ether_stat_tooshort_errors =
bfe->bfe_hw_stats.rx_undersize;
rxerr += bfe->bfe_hw_stats.rx_undersize;
bfe->bfe_stats.ether_stat_tx_late_collisions +=
bfe->bfe_hw_stats.tx_late_cols;
bfe->bfe_stats.ether_stat_defer_xmts +=
bfe->bfe_hw_stats.tx_defered;
bfe->bfe_stats.ether_stat_macrcv_errors += rxerr;
bfe->bfe_stats.ether_stat_macxmt_errors += txerr;
bfe->bfe_stats.collisions += coll;
}
/*
* Gets the state for dladm command and all.
*/
int
bfe_mac_getstat(void *arg, uint_t stat, uint64_t *val)
{
bfe_t *bfe = (bfe_t *)arg;
uint64_t v;
int err = 0;
rw_enter(&bfe->bfe_rwlock, RW_READER);
switch (stat) {
default:
err = ENOTSUP;
break;
case MAC_STAT_IFSPEED:
/*
* MAC layer will ask for IFSPEED first and hence we
* collect it only once.
*/
if (bfe->bfe_chip_state == BFE_CHIP_ACTIVE) {
/*
* Update stats from the hardware.
*/
bfe_gather_stats(bfe);
}
v = bfe->bfe_chip.speed;
break;
case ETHER_STAT_ADV_CAP_100T4:
v = bfe->bfe_adv_100T4;
break;
case ETHER_STAT_ADV_CAP_100FDX:
v = (bfe->bfe_mii_anar & MII_ABILITY_100BASE_TX_FD) != 0;
break;
case ETHER_STAT_ADV_CAP_100HDX:
v = (bfe->bfe_mii_anar & MII_ABILITY_100BASE_TX) != 0;
break;
case ETHER_STAT_ADV_CAP_10FDX:
v = (bfe->bfe_mii_anar & MII_ABILITY_10BASE_T_FD) != 0;
break;
case ETHER_STAT_ADV_CAP_10HDX:
v = (bfe->bfe_mii_anar & MII_ABILITY_10BASE_T) != 0;
break;
case ETHER_STAT_ADV_CAP_ASMPAUSE:
v = 0;
break;
case ETHER_STAT_ADV_CAP_AUTONEG:
v = bfe->bfe_adv_aneg;
break;
case ETHER_STAT_ADV_CAP_PAUSE:
v = (bfe->bfe_mii_anar & MII_ABILITY_PAUSE) != 0;
break;
case ETHER_STAT_ADV_REMFAULT:
v = (bfe->bfe_mii_anar & MII_AN_ADVERT_REMFAULT) != 0;
break;
case ETHER_STAT_ALIGN_ERRORS:
/* MIB */
v = bfe->bfe_stats.ether_stat_align_errors;
break;
case ETHER_STAT_CAP_100T4:
v = (bfe->bfe_mii_bmsr & MII_STATUS_100_BASE_T4) != 0;
break;
case ETHER_STAT_CAP_100FDX:
v = (bfe->bfe_mii_bmsr & MII_STATUS_100_BASEX_FD) != 0;
break;
case ETHER_STAT_CAP_100HDX:
v = (bfe->bfe_mii_bmsr & MII_STATUS_100_BASEX) != 0;
break;
case ETHER_STAT_CAP_10FDX:
v = (bfe->bfe_mii_bmsr & MII_STATUS_10_FD) != 0;
break;
case ETHER_STAT_CAP_10HDX:
v = (bfe->bfe_mii_bmsr & MII_STATUS_10) != 0;
break;
case ETHER_STAT_CAP_ASMPAUSE:
v = 0;
break;
case ETHER_STAT_CAP_AUTONEG:
v = ((bfe->bfe_mii_bmsr & MII_STATUS_CANAUTONEG) != 0);
break;
case ETHER_STAT_CAP_PAUSE:
v = 1;
break;
case ETHER_STAT_CAP_REMFAULT:
v = (bfe->bfe_mii_bmsr & MII_STATUS_REMFAULT) != 0;
break;
case ETHER_STAT_CARRIER_ERRORS:
v = bfe->bfe_stats.ether_stat_carrier_errors;
break;
case ETHER_STAT_JABBER_ERRORS:
err = ENOTSUP;
break;
case ETHER_STAT_DEFER_XMTS:
v = bfe->bfe_stats.ether_stat_defer_xmts;
break;
case ETHER_STAT_EX_COLLISIONS:
/* MIB */
v = bfe->bfe_stats.ether_stat_ex_collisions;
break;
case ETHER_STAT_FCS_ERRORS:
/* MIB */
v = bfe->bfe_stats.ether_stat_fcs_errors;
break;
case ETHER_STAT_FIRST_COLLISIONS:
/* MIB */
v = bfe->bfe_stats.ether_stat_first_collisions;
break;
case ETHER_STAT_LINK_ASMPAUSE:
v = 0;
break;
case ETHER_STAT_LINK_AUTONEG:
v = (bfe->bfe_mii_bmcr & MII_CONTROL_ANE) != 0 &&
(bfe->bfe_mii_bmsr & MII_STATUS_ANDONE) != 0;
break;
case ETHER_STAT_LINK_DUPLEX:
v = bfe->bfe_chip.duplex;
break;
case ETHER_STAT_LP_CAP_100T4:
v = (bfe->bfe_mii_anlpar & MII_ABILITY_100BASE_T4) != 0;
break;
case ETHER_STAT_LP_CAP_100FDX:
v = (bfe->bfe_mii_anlpar & MII_ABILITY_100BASE_TX_FD) != 0;
break;
case ETHER_STAT_LP_CAP_100HDX:
v = (bfe->bfe_mii_anlpar & MII_ABILITY_100BASE_TX) != 0;
break;
case ETHER_STAT_LP_CAP_10FDX:
v = (bfe->bfe_mii_anlpar & MII_ABILITY_10BASE_T_FD) != 0;
break;
case ETHER_STAT_LP_CAP_10HDX:
v = (bfe->bfe_mii_anlpar & MII_ABILITY_10BASE_T) != 0;
break;
case ETHER_STAT_LP_CAP_ASMPAUSE:
v = 0;
break;
case ETHER_STAT_LP_CAP_AUTONEG:
v = (bfe->bfe_mii_exp & MII_AN_EXP_LPCANAN) != 0;
break;
case ETHER_STAT_LP_CAP_PAUSE:
v = (bfe->bfe_mii_anlpar & MII_ABILITY_PAUSE) != 0;
break;
case ETHER_STAT_LP_REMFAULT:
v = (bfe->bfe_mii_anlpar & MII_STATUS_REMFAULT) != 0;
break;
case ETHER_STAT_MACRCV_ERRORS:
v = bfe->bfe_stats.ether_stat_macrcv_errors;
break;
case ETHER_STAT_MACXMT_ERRORS:
v = bfe->bfe_stats.ether_stat_macxmt_errors;
break;
case ETHER_STAT_MULTI_COLLISIONS:
v = bfe->bfe_stats.ether_stat_multi_collisions;
break;
case ETHER_STAT_SQE_ERRORS:
err = ENOTSUP;
break;
case ETHER_STAT_TOOLONG_ERRORS:
v = bfe->bfe_stats.ether_stat_toolong_errors;
break;
case ETHER_STAT_TOOSHORT_ERRORS:
v = bfe->bfe_stats.ether_stat_tooshort_errors;
break;
case ETHER_STAT_TX_LATE_COLLISIONS:
v = bfe->bfe_stats.ether_stat_tx_late_collisions;
break;
case ETHER_STAT_XCVR_ADDR:
v = bfe->bfe_phy_addr;
break;
case ETHER_STAT_XCVR_ID:
v = bfe->bfe_phy_id;
break;
case MAC_STAT_BRDCSTRCV:
v = bfe->bfe_stats.brdcstrcv;
break;
case MAC_STAT_BRDCSTXMT:
v = bfe->bfe_stats.brdcstxmt;
break;
case MAC_STAT_MULTIXMT:
v = bfe->bfe_stats.multixmt;
break;
case MAC_STAT_COLLISIONS:
v = bfe->bfe_stats.collisions;
break;
case MAC_STAT_IERRORS:
v = bfe->bfe_stats.ierrors;
break;
case MAC_STAT_IPACKETS:
v = bfe->bfe_stats.ipackets;
break;
case MAC_STAT_MULTIRCV:
v = bfe->bfe_stats.multircv;
break;
case MAC_STAT_NORCVBUF:
v = bfe->bfe_stats.norcvbuf;
break;
case MAC_STAT_NOXMTBUF:
v = bfe->bfe_stats.noxmtbuf;
break;
case MAC_STAT_OBYTES:
v = bfe->bfe_stats.obytes;
break;
case MAC_STAT_OERRORS:
/* MIB */
v = bfe->bfe_stats.ether_stat_macxmt_errors;
break;
case MAC_STAT_OPACKETS:
v = bfe->bfe_stats.opackets;
break;
case MAC_STAT_RBYTES:
v = bfe->bfe_stats.rbytes;
break;
case MAC_STAT_UNDERFLOWS:
v = bfe->bfe_stats.underflows;
break;
case MAC_STAT_OVERFLOWS:
v = bfe->bfe_stats.overflows;
break;
}
rw_exit(&bfe->bfe_rwlock);
*val = v;
return (err);
}
/*ARGSUSED*/
int
bfe_mac_getprop(void *arg, const char *name, mac_prop_id_t num, uint_t flags,
uint_t sz, void *val, uint_t *perm)
{
bfe_t *bfe = (bfe_t *)arg;
int err = 0;
boolean_t dfl = flags & MAC_PROP_DEFAULT;
if (sz == 0)
return (EINVAL);
*perm = MAC_PROP_PERM_RW;
switch (num) {
case MAC_PROP_DUPLEX:
*perm = MAC_PROP_PERM_READ;
if (sz >= sizeof (link_duplex_t)) {
bcopy(&bfe->bfe_chip.duplex, val,
sizeof (link_duplex_t));
} else {
err = EINVAL;
}
break;
case MAC_PROP_SPEED:
*perm = MAC_PROP_PERM_READ;
if (sz >= sizeof (uint64_t)) {
bcopy(&bfe->bfe_chip.speed, val, sizeof (uint64_t));
} else {
err = EINVAL;
}
break;
case MAC_PROP_AUTONEG:
*(uint8_t *)val =
dfl ? bfe->bfe_cap_aneg : bfe->bfe_adv_aneg;
break;
case MAC_PROP_ADV_100FDX_CAP:
*perm = MAC_PROP_PERM_READ;
*(uint8_t *)val =
dfl ? bfe->bfe_cap_100fdx : bfe->bfe_adv_100fdx;
break;
case MAC_PROP_EN_100FDX_CAP:
*(uint8_t *)val =
dfl ? bfe->bfe_cap_100fdx : bfe->bfe_adv_100fdx;
break;
case MAC_PROP_ADV_100HDX_CAP:
*perm = MAC_PROP_PERM_READ;
*(uint8_t *)val =
dfl ? bfe->bfe_cap_100hdx : bfe->bfe_adv_100hdx;
break;
case MAC_PROP_EN_100HDX_CAP:
*(uint8_t *)val =
dfl ? bfe->bfe_cap_100hdx : bfe->bfe_adv_100hdx;
break;
case MAC_PROP_ADV_10FDX_CAP:
*perm = MAC_PROP_PERM_READ;
*(uint8_t *)val =
dfl ? bfe->bfe_cap_10fdx : bfe->bfe_adv_10fdx;
break;
case MAC_PROP_EN_10FDX_CAP:
*(uint8_t *)val =
dfl ? bfe->bfe_cap_10fdx : bfe->bfe_adv_10fdx;
break;
case MAC_PROP_ADV_10HDX_CAP:
*perm = MAC_PROP_PERM_READ;
*(uint8_t *)val =
dfl ? bfe->bfe_cap_10hdx : bfe->bfe_adv_10hdx;
break;
case MAC_PROP_EN_10HDX_CAP:
*(uint8_t *)val =
dfl ? bfe->bfe_cap_10hdx : bfe->bfe_adv_10hdx;
break;
case MAC_PROP_ADV_100T4_CAP:
*perm = MAC_PROP_PERM_READ;
*(uint8_t *)val =
dfl ? bfe->bfe_cap_100T4 : bfe->bfe_adv_100T4;
break;
case MAC_PROP_EN_100T4_CAP:
*(uint8_t *)val =
dfl ? bfe->bfe_cap_100T4 : bfe->bfe_adv_100T4;
break;
default:
err = ENOTSUP;
}
return (err);
}
/*ARGSUSED*/
int
bfe_mac_setprop(void *arg, const char *name, mac_prop_id_t num, uint_t sz,
const void *val)
{
bfe_t *bfe = (bfe_t *)arg;
uint8_t *advp;
uint8_t *capp;
int r = 0;
switch (num) {
case MAC_PROP_EN_100FDX_CAP:
advp = &bfe->bfe_adv_100fdx;
capp = &bfe->bfe_cap_100fdx;
break;
case MAC_PROP_EN_100HDX_CAP:
advp = &bfe->bfe_adv_100hdx;
capp = &bfe->bfe_cap_100hdx;
break;
case MAC_PROP_EN_10FDX_CAP:
advp = &bfe->bfe_adv_10fdx;
capp = &bfe->bfe_cap_10fdx;
break;
case MAC_PROP_EN_10HDX_CAP:
advp = &bfe->bfe_adv_10hdx;
capp = &bfe->bfe_cap_10hdx;
break;
case MAC_PROP_EN_100T4_CAP:
advp = &bfe->bfe_adv_100T4;
capp = &bfe->bfe_cap_100T4;
break;
case MAC_PROP_AUTONEG:
advp = &bfe->bfe_adv_aneg;
capp = &bfe->bfe_cap_aneg;
break;
default:
return (ENOTSUP);
}
if (*capp == 0)
return (ENOTSUP);
bfe_grab_locks(bfe);
if (*advp != *(const uint8_t *)val) {
*advp = *(const uint8_t *)val;
bfe->bfe_chip_action = BFE_ACTION_RESTART_SETPROP;
if (bfe->bfe_chip_state == BFE_CHIP_ACTIVE) {
/*
* We need to stop the timer before grabbing locks
* otherwise we can land-up in deadlock with untimeout.
*/
bfe_stop_timer(bfe);
bfe->bfe_chip_action |= BFE_ACTION_RESTART;
bfe_chip_restart(bfe);
/*
* We leave SETPROP because properties can be
* temporary.
*/
bfe->bfe_chip_action &= ~(BFE_ACTION_RESTART);
r = 1;
}
}
bfe_release_locks(bfe);
/* kick-off a potential stopped downstream */
if (r)
mac_tx_update(bfe->bfe_machdl);
return (0);
}
int
bfe_mac_set_ether_addr(void *arg, const uint8_t *ea)
{
bfe_t *bfe = (bfe_t *)arg;
bfe_grab_locks(bfe);
bcopy(ea, bfe->bfe_ether_addr, ETHERADDRL);
bfe_set_rx_mode(bfe);
bfe_release_locks(bfe);
return (0);
}
int
bfe_mac_start(void *arg)
{
bfe_t *bfe = (bfe_t *)arg;
if (bfe_chip_start(bfe) == DDI_FAILURE)
return (EINVAL);
return (0);
}
void
bfe_mac_stop(void *arg)
{
bfe_t *bfe = (bfe_t *)arg;
/*
* We need to stop the timer before grabbing locks otherwise
* we can land-up in deadlock with untimeout.
*/
bfe_stop_timer(bfe);
bfe_grab_locks(bfe);
/*
* First halt the chip by disabling interrupts.
*/
bfe_chip_halt(bfe);
bfe_stop_phy(bfe);
bfe->bfe_chip_state = BFE_CHIP_STOPPED;
/*
* This will leave the PHY running.
*/
bfe_chip_reset(bfe);
/*
* Disable RX register.
*/
bfe->bfe_chip_mode &= ~BFE_RX_MODE_ENABLE;
bfe_set_rx_mode(bfe);
bfe_release_locks(bfe);
}
/*
* Send a packet down the wire.
*/
static int
bfe_send_a_packet(bfe_t *bfe, mblk_t *mp)
{
bfe_ring_t *r = &bfe->bfe_tx_ring;
uint32_t cur = r->r_curr_desc;
uint32_t next;
size_t pktlen = msgsize(mp);
uchar_t *buf;
uint32_t v;
ASSERT(MUTEX_HELD(&r->r_lock));
ASSERT(mp != NULL);
if (pktlen > r->r_buf_len) {
freemsg(mp);
return (BFE_SUCCESS);
}
/*
* There is a big reason why we don't check for '0'. It becomes easy
* for us to not roll over the ring since we are based on producer (tx)
* and consumer (reclaim by an interrupt) model. Especially when we
* run out of TX descriptor, chip will send a single interrupt and
* both producer and consumer counter will be same. So we keep a
* difference of 1 always.
*/
if (r->r_avail_desc <= 1) {
bfe->bfe_stats.noxmtbuf++;
bfe->bfe_tx_resched = 1;
return (BFE_FAILURE);
}
/*
* Get the DMA buffer to hold packet.
*/
buf = (uchar_t *)r->r_buf_dma[cur].addr;
mcopymsg(mp, buf); /* it also frees mp */
/*
* Gather statistics.
*/
if (buf[0] & 0x1) {
if (bcmp(buf, bfe_broadcast, ETHERADDRL) != 0)
bfe->bfe_stats.multixmt++;
else
bfe->bfe_stats.brdcstxmt++;
}
bfe->bfe_stats.opackets++;
bfe->bfe_stats.obytes += pktlen;
/*
* Program the DMA descriptor (start and end of frame are same).
*/
next = cur;
v = (pktlen & BFE_DESC_LEN) | BFE_DESC_IOC | BFE_DESC_SOF |
BFE_DESC_EOF;
if (cur == (TX_NUM_DESC - 1))
v |= BFE_DESC_EOT;
PUT_DESC(r, (uint32_t *)&(r->r_desc[cur].desc_ctl), v);
/*
* DMA addresses need to be added to BFE_PCI_DMA
*/
PUT_DESC(r, (uint32_t *)&(r->r_desc[cur].desc_addr),
(r->r_buf_dma[cur].cookie.dmac_laddress + BFE_PCI_DMA));
/*
* Sync the packet data for the device.
*/
(void) SYNC_BUF(r, cur, 0, pktlen, DDI_DMA_SYNC_FORDEV);
/* Move to next descriptor slot */
BFE_INC_SLOT(next, TX_NUM_DESC);
(void) SYNC_DESC(r, 0, r->r_ndesc, DDI_DMA_SYNC_FORDEV);
r->r_curr_desc = next;
/*
* The order should be 1,2,3,... for BFE_DMATX_PTR if 0,1,2,3,...
* descriptor slot are being programmed.
*/
OUTL(bfe, BFE_DMATX_PTR, next * sizeof (bfe_desc_t));
FLUSH(bfe, BFE_DMATX_PTR);
r->r_avail_desc--;
/*
* Let timeout know that it must reset the chip if a
* packet is not sent down the wire for more than 5 seconds.
*/
bfe->bfe_tx_stall_time = gethrtime() + (5 * 1000000000ULL);
return (BFE_SUCCESS);
}
mblk_t *
bfe_mac_transmit_packet(void *arg, mblk_t *mp)
{
bfe_t *bfe = (bfe_t *)arg;
bfe_ring_t *r = &bfe->bfe_tx_ring;
mblk_t *nmp;
mutex_enter(&r->r_lock);
if (bfe->bfe_chip_state != BFE_CHIP_ACTIVE) {
bfe_error(bfe->bfe_dip, "bfe_mac_transmit_packet(): sending pkt"
" while chip/link is not up");
freemsgchain(mp);
mutex_exit(&r->r_lock);
return (NULL);
}
while (mp != NULL) {
nmp = mp->b_next;
mp->b_next = NULL;
if (bfe_send_a_packet(bfe, mp) == BFE_FAILURE) {
mp->b_next = nmp;
break;
}
mp = nmp;
}
mutex_exit(&r->r_lock);
return (mp);
}
int
bfe_mac_set_promisc(void *arg, boolean_t promiscflag)
{
bfe_t *bfe = (bfe_t *)arg;
bfe_grab_locks(bfe);
if (bfe->bfe_chip_state != BFE_CHIP_ACTIVE) {
bfe_release_locks(bfe);
return (EIO);
}
if (promiscflag) {
/* Set Promiscous on */
bfe->bfe_chip_mode |= BFE_RX_MODE_PROMISC;
} else {
bfe->bfe_chip_mode &= ~BFE_RX_MODE_PROMISC;
}
bfe_set_rx_mode(bfe);
bfe_release_locks(bfe);
return (0);
}
int
bfe_mac_set_multicast(void *arg, boolean_t add, const uint8_t *macaddr)
{
/*
* It was too much of pain to implement multicast in CAM. Instead
* we never disable multicast filter.
*/
return (0);
}
static mac_callbacks_t bfe_mac_callbacks = {
MC_SETPROP | MC_GETPROP,
bfe_mac_getstat, /* gets stats */
bfe_mac_start, /* starts mac */
bfe_mac_stop, /* stops mac */
bfe_mac_set_promisc, /* sets promisc mode for snoop */
bfe_mac_set_multicast, /* multicast implementation */
bfe_mac_set_ether_addr, /* sets ethernet address (unicast) */
bfe_mac_transmit_packet, /* transmits packet */
NULL, /* ioctl */
NULL, /* getcap */
NULL, /* open */
NULL, /* close */
bfe_mac_setprop,
bfe_mac_getprop,
};
static void
bfe_error_handler(bfe_t *bfe, int intr_mask)
{
uint32_t v;
if (intr_mask & BFE_ISTAT_RFO) {
bfe->bfe_stats.overflows++;
return;
}
if (intr_mask & BFE_ISTAT_TFU) {
bfe->bfe_stats.underflows++;
return;
}
/* Descriptor Protocol Error */
if (intr_mask & BFE_ISTAT_DPE) {
bfe_error(bfe->bfe_dip,
"Descriptor Protocol Error. Halting Chip");
bfe->bfe_chip_action |=
(BFE_ACTION_RESTART | BFE_ACTION_RESTART_FAULT);
goto action;
}
/* Descriptor Error */
if (intr_mask & BFE_ISTAT_DSCE && halt == 0) {
bfe_error(bfe->bfe_dip, "Descriptor Error. Restarting Chip");
goto action;
}
/* Receive Descr. Underflow */
if (intr_mask & BFE_ISTAT_RDU) {
bfe_error(bfe->bfe_dip,
"Receive Descriptor Underflow. Restarting Chip");
bfe->bfe_stats.ether_stat_macrcv_errors++;
bfe->bfe_chip_action |=
(BFE_ACTION_RESTART | BFE_ACTION_RESTART_FAULT);
goto action;
}
v = INL(bfe, BFE_DMATX_STAT);
/* Error while sending a packet */
if (v & BFE_STAT_EMASK) {
bfe->bfe_stats.ether_stat_macxmt_errors++;
bfe_error(bfe->bfe_dip,
"Error while sending a packet. Restarting Chip");
}
/* Error while receiving a packet */
v = INL(bfe, BFE_DMARX_STAT);
if (v & BFE_RX_FLAG_ERRORS) {
bfe->bfe_stats.ierrors++;
bfe_error(bfe->bfe_dip,
"Error while receiving a packet. Restarting Chip");
}
bfe->bfe_chip_action |=
(BFE_ACTION_RESTART | BFE_ACTION_RESTART_FAULT);
action:
bfe_chip_halt(bfe);
}
/*
* It will recycle a RX descriptor slot.
*/
static void
bfe_rx_desc_buf_reinit(bfe_t *bfe, uint_t slot)
{
bfe_ring_t *r = &bfe->bfe_rx_ring;
uint32_t v;
slot %= RX_NUM_DESC;
bzero(r->r_buf_dma[slot].addr, sizeof (bfe_rx_header_t));
(void) SYNC_BUF(r, slot, 0, BFE_RX_OFFSET, DDI_DMA_SYNC_FORDEV);
v = r->r_buf_dma[slot].len & BFE_DESC_LEN;
if (slot == (RX_NUM_DESC - 1))
v |= BFE_DESC_EOT;
PUT_DESC(r, (uint32_t *)&(r->r_desc[slot].desc_ctl), v);
/*
* DMA addresses need to be added to BFE_PCI_DMA
*/
PUT_DESC(r, (uint32_t *)&(r->r_desc[slot].desc_addr),
(r->r_buf_dma[slot].cookie.dmac_laddress + BFE_PCI_DMA));
}
/*
* Gets called from interrupt context to handle RX interrupt.
*/
static mblk_t *
bfe_receive(bfe_t *bfe, int intr_mask)
{
int rxstat, current;
mblk_t *mp = NULL, *rx_head, *rx_tail;
uchar_t *rx_header;
uint16_t len;
uchar_t *bp;
bfe_ring_t *r = &bfe->bfe_rx_ring;
int i;
rxstat = INL(bfe, BFE_DMARX_STAT);
current = (rxstat & BFE_STAT_CDMASK) / sizeof (bfe_desc_t);
i = r->r_curr_desc;
rx_head = rx_tail = NULL;
DTRACE_PROBE3(receive, int, bfe->bfe_unit,
int, r->r_curr_desc,
int, current);
for (i = r->r_curr_desc; i != current;
BFE_INC_SLOT(i, RX_NUM_DESC)) {
/*
* Sync the buffer associated with the descriptor table entry.
*/
(void) SYNC_BUF(r, i, 0, r->r_buf_dma[i].len,
DDI_DMA_SYNC_FORKERNEL);
rx_header = (void *)r->r_buf_dma[i].addr;
/*
* We do this to make sure we are endian neutral. Chip is
* big endian.
*
* The header looks like :-
*
* Offset 0 -> uint16_t len
* Offset 2 -> uint16_t flags
* Offset 4 -> uint16_t pad[12]
*/
len = (rx_header[1] << 8) | rx_header[0];
len -= 4; /* CRC bytes need to be removed */
/*
* Don't receive this packet if pkt length is greater than
* MTU + VLAN_TAGSZ.
*/
if (len > r->r_buf_len) {
/* Recycle slot for later use */
bfe_rx_desc_buf_reinit(bfe, i);
continue;
}
if ((mp = allocb(len + VLAN_TAGSZ, BPRI_MED)) != NULL) {
mp->b_rptr += VLAN_TAGSZ;
bp = mp->b_rptr;
mp->b_wptr = bp + len;
/* sizeof (bfe_rx_header_t) + 2 */
bcopy(r->r_buf_dma[i].addr +
BFE_RX_OFFSET, bp, len);
mp->b_next = NULL;
if (rx_tail == NULL)
rx_head = rx_tail = mp;
else {
rx_tail->b_next = mp;
rx_tail = mp;
}
/* Number of packets received so far */
bfe->bfe_stats.ipackets++;
/* Total bytes of packets received so far */
bfe->bfe_stats.rbytes += len;
if (bcmp(mp->b_rptr, bfe_broadcast, ETHERADDRL) == 0)
bfe->bfe_stats.brdcstrcv++;
else
bfe->bfe_stats.multircv++;
} else {
bfe->bfe_stats.norcvbuf++;
/* Recycle the slot for later use */
bfe_rx_desc_buf_reinit(bfe, i);
break;
}
/*
* Reinitialize the current descriptor slot's buffer so that
* it can be reused.
*/
bfe_rx_desc_buf_reinit(bfe, i);
}
r->r_curr_desc = i;
(void) SYNC_DESC(r, 0, r->r_ndesc, DDI_DMA_SYNC_FORDEV);
return (rx_head);
}
static int
bfe_tx_reclaim(bfe_ring_t *r)
{
uint32_t cur, start;
uint32_t v;
cur = INL(r->r_bfe, BFE_DMATX_STAT) & BFE_STAT_CDMASK;
cur = cur / sizeof (bfe_desc_t);
/*
* Start with the last descriptor consumed by the chip.
*/
start = r->r_cons_desc;
DTRACE_PROBE3(tx__reclaim, int, r->r_bfe->bfe_unit,
int, start,
int, cur);
/*
* There will be at least one descriptor to process.
*/
while (start != cur) {
r->r_avail_desc++;
v = r->r_buf_dma[start].len & BFE_DESC_LEN;
if (start == (TX_NUM_DESC - 1))
v |= BFE_DESC_EOT;
PUT_DESC(r, (uint32_t *)&(r->r_desc[start].desc_ctl), v);
PUT_DESC(r, (uint32_t *)&(r->r_desc[start].desc_addr),
(r->r_buf_dma[start].cookie.dmac_laddress + BFE_PCI_DMA));
/* Move to next descriptor in TX ring */
BFE_INC_SLOT(start, TX_NUM_DESC);
}
(void) ddi_dma_sync(r->r_desc_dma_handle,
0, (r->r_ndesc * sizeof (bfe_desc_t)),
DDI_DMA_SYNC_FORDEV);
r->r_cons_desc = start; /* consumed pointer */
r->r_bfe->bfe_tx_stall_time = 0;
return (cur);
}
static int
bfe_tx_done(bfe_t *bfe, int intr_mask)
{
bfe_ring_t *r = &bfe->bfe_tx_ring;
int resched = 0;
mutex_enter(&r->r_lock);
(void) bfe_tx_reclaim(r);
if (bfe->bfe_tx_resched) {
resched = 1;
bfe->bfe_tx_resched = 0;
}
mutex_exit(&r->r_lock);
return (resched);
}
/*
* ISR for interrupt handling
*/
static uint_t
bfe_interrupt(caddr_t arg1, caddr_t arg2)
{
bfe_t *bfe = (void *)arg1;
uint32_t intr_stat;
mblk_t *rx_head = NULL;
int resched = 0;
/*
* Grab the lock to avoid stopping the chip while this interrupt
* is handled.
*/
rw_enter(&bfe->bfe_rwlock, RW_READER);
/*
* It's necessary to read intr stat again because masking interrupt
* register does not really mask interrupts coming from the chip.
*/
intr_stat = INL(bfe, BFE_INTR_STAT);
intr_stat &= BFE_IMASK_DEF;
OUTL(bfe, BFE_INTR_STAT, intr_stat);
(void) INL(bfe, BFE_INTR_STAT);
if (intr_stat == 0) {
rw_exit(&bfe->bfe_rwlock);
return (DDI_INTR_UNCLAIMED);
}
if (bfe->bfe_chip_state != BFE_CHIP_ACTIVE) {
/*
* If chip is suspended then we just return.
*/
if (bfe->bfe_chip_state == BFE_CHIP_SUSPENDED) {
rw_exit(&bfe->bfe_rwlock);
DTRACE_PROBE1(interrupt__chip__is__suspend, int,
bfe->bfe_unit);
return (DDI_INTR_CLAIMED);
}
/*
* Halt the chip again i.e basically disable interrupts.
*/
bfe_chip_halt(bfe);
rw_exit(&bfe->bfe_rwlock);
DTRACE_PROBE1(interrupt__chip__not__active, int,
bfe->bfe_unit);
return (DDI_INTR_CLAIMED);
}
/* A packet was received */
if (intr_stat & BFE_ISTAT_RX) {
rx_head = bfe_receive(bfe, intr_stat);
}
/* A packet was sent down the wire */
if (intr_stat & BFE_ISTAT_TX) {
resched = bfe_tx_done(bfe, intr_stat);
}
/* There was an error */
if (intr_stat & BFE_ISTAT_ERRORS) {
bfe_error_handler(bfe, intr_stat);
}
rw_exit(&bfe->bfe_rwlock);
/*
* Pass the list of packets received from chip to MAC layer.
*/
if (rx_head) {
mac_rx(bfe->bfe_machdl, 0, rx_head);
}
/*
* Let the MAC start sending pkts to a potential stopped stream.
*/
if (resched)
mac_tx_update(bfe->bfe_machdl);
return (DDI_INTR_CLAIMED);
}
/*
* Removes registered interrupt handler.
*/
static void
bfe_remove_intr(bfe_t *bfe)
{
(void) ddi_intr_remove_handler(bfe->bfe_intrhdl);
(void) ddi_intr_free(bfe->bfe_intrhdl);
}
/*
* Add an interrupt for the driver.
*/
static int
bfe_add_intr(bfe_t *bfe)
{
int nintrs = 1;
int ret;
ret = ddi_intr_alloc(bfe->bfe_dip, &bfe->bfe_intrhdl,
DDI_INTR_TYPE_FIXED, /* type */
0, /* inumber */
1, /* count */
&nintrs, /* actual nintrs */
DDI_INTR_ALLOC_STRICT);
if (ret != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "ddi_intr_alloc() failed"
" : ret : %d", ret);
return (DDI_FAILURE);
}
ret = ddi_intr_add_handler(bfe->bfe_intrhdl, bfe_interrupt, bfe, NULL);
if (ret != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "ddi_intr_add_handler() failed");
(void) ddi_intr_free(bfe->bfe_intrhdl);
return (DDI_FAILURE);
}
ret = ddi_intr_get_pri(bfe->bfe_intrhdl, &bfe->bfe_intrpri);
if (ret != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "ddi_intr_get_pri() failed");
bfe_remove_intr(bfe);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* Identify chipset family.
*/
static int
bfe_identify_hardware(bfe_t *bfe)
{
uint16_t vid, did;
int i;
vid = pci_config_get16(bfe->bfe_conf_handle, PCI_CONF_VENID);
did = pci_config_get16(bfe->bfe_conf_handle, PCI_CONF_DEVID);
for (i = 0; i < (sizeof (bfe_cards) / sizeof (bfe_cards_t)); i++) {
if (bfe_cards[i].vendor_id == vid &&
bfe_cards[i].device_id == did) {
return (BFE_SUCCESS);
}
}
bfe_error(bfe->bfe_dip, "bfe driver is attaching to unknown pci%d,%d"
" vendor/device-id card", vid, did);
return (BFE_SUCCESS);
}
/*
* Maps device registers.
*/
static int
bfe_regs_map(bfe_t *bfe)
{
dev_info_t *dip = bfe->bfe_dip;
int ret;
ret = ddi_regs_map_setup(dip, 1, &bfe->bfe_mem_regset.addr, 0, 0,
&bfe_dev_attr, &bfe->bfe_mem_regset.hdl);
if (ret != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "ddi_regs_map_setup failed");
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
bfe_unmap_regs(bfe_t *bfe)
{
ddi_regs_map_free(&bfe->bfe_mem_regset.hdl);
}
static int
bfe_get_chip_config(bfe_t *bfe)
{
uint32_t prom[BFE_EEPROM_SIZE];
int i;
/*
* Read EEPROM in prom[]
*/
for (i = 0; i < BFE_EEPROM_SIZE; i++) {
prom[i] = INL(bfe, BFE_EEPROM_BASE + i * sizeof (uint32_t));
}
bfe->bfe_dev_addr[0] = bfe->bfe_ether_addr[0] =
INB(bfe, BFE_EEPROM_BASE + 79);
bfe->bfe_dev_addr[1] = bfe->bfe_ether_addr[1] =
INB(bfe, BFE_EEPROM_BASE + 78);
bfe->bfe_dev_addr[2] = bfe->bfe_ether_addr[2] =
INB(bfe, BFE_EEPROM_BASE + 81);
bfe->bfe_dev_addr[3] = bfe->bfe_ether_addr[3] =
INB(bfe, BFE_EEPROM_BASE + 80);
bfe->bfe_dev_addr[4] = bfe->bfe_ether_addr[4] =
INB(bfe, BFE_EEPROM_BASE + 83);
bfe->bfe_dev_addr[5] = bfe->bfe_ether_addr[5] =
INB(bfe, BFE_EEPROM_BASE + 82);
bfe->bfe_phy_addr = -1;
return (DDI_SUCCESS);
}
/*
* Ring Management routines
*/
static int
bfe_ring_buf_alloc(bfe_t *bfe, bfe_ring_t *r, int slot, int d)
{
int err;
uint_t count = 0;
err = ddi_dma_alloc_handle(bfe->bfe_dip,
&bfe_dma_attr_buf, DDI_DMA_SLEEP, NULL,
&r->r_buf_dma[slot].handle);
if (err != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, " bfe_ring_buf_alloc() :"
" alloc_handle failed");
goto fail0;
}
err = ddi_dma_mem_alloc(r->r_buf_dma[slot].handle,
r->r_buf_len, &bfe_buf_attr, DDI_DMA_STREAMING,
DDI_DMA_SLEEP, NULL, &r->r_buf_dma[slot].addr,
&r->r_buf_dma[slot].len,
&r->r_buf_dma[slot].acchdl);
if (err != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, " bfe_ring_buf_alloc() :"
" mem_alloc failed :%d", err);
goto fail1;
}
err = ddi_dma_addr_bind_handle(r->r_buf_dma[slot].handle,
NULL, r->r_buf_dma[slot].addr,
r->r_buf_dma[slot].len,
(DDI_DMA_RDWR | DDI_DMA_STREAMING),
DDI_DMA_SLEEP, NULL,
&r->r_buf_dma[slot].cookie,
&count);
if (err != DDI_DMA_MAPPED) {
bfe_error(bfe->bfe_dip, " bfe_ring_buf_alloc() :"
" bind_handle failed");
goto fail2;
}
if (count > 1) {
bfe_error(bfe->bfe_dip, " bfe_ring_buf_alloc() :"
" more than one DMA cookie");
(void) ddi_dma_unbind_handle(r->r_buf_dma[slot].handle);
goto fail2;
}
return (DDI_SUCCESS);
fail2:
ddi_dma_mem_free(&r->r_buf_dma[slot].acchdl);
fail1:
ddi_dma_free_handle(&r->r_buf_dma[slot].handle);
fail0:
return (DDI_FAILURE);
}
static void
bfe_ring_buf_free(bfe_ring_t *r, int slot)
{
if (r->r_buf_dma == NULL)
return;
(void) ddi_dma_unbind_handle(r->r_buf_dma[slot].handle);
ddi_dma_mem_free(&r->r_buf_dma[slot].acchdl);
ddi_dma_free_handle(&r->r_buf_dma[slot].handle);
}
static void
bfe_buffer_free(bfe_ring_t *r)
{
int i;
for (i = 0; i < r->r_ndesc; i++) {
bfe_ring_buf_free(r, i);
}
}
static void
bfe_ring_desc_free(bfe_ring_t *r)
{
(void) ddi_dma_unbind_handle(r->r_desc_dma_handle);
ddi_dma_mem_free(&r->r_desc_acc_handle);
ddi_dma_free_handle(&r->r_desc_dma_handle);
kmem_free(r->r_buf_dma, r->r_ndesc * sizeof (bfe_dma_t));
r->r_buf_dma = NULL;
r->r_desc = NULL;
}
static int
bfe_ring_desc_alloc(bfe_t *bfe, bfe_ring_t *r, int d)
{
int err, i, fail = 0;
caddr_t ring;
size_t size_krnl = 0, size_dma = 0, ring_len = 0;
ddi_dma_cookie_t cookie;
uint_t count = 0;
ASSERT(bfe != NULL);
size_krnl = r->r_ndesc * sizeof (bfe_dma_t);
size_dma = r->r_ndesc * sizeof (bfe_desc_t);
r->r_buf_dma = kmem_zalloc(size_krnl, KM_SLEEP);
err = ddi_dma_alloc_handle(bfe->bfe_dip, &bfe_dma_attr_desc,
DDI_DMA_SLEEP, NULL, &r->r_desc_dma_handle);
if (err != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "bfe_ring_desc_alloc() failed on"
" ddi_dma_alloc_handle()");
kmem_free(r->r_buf_dma, size_krnl);
return (DDI_FAILURE);
}
err = ddi_dma_mem_alloc(r->r_desc_dma_handle,
size_dma, &bfe_buf_attr,
DDI_DMA_CONSISTENT, DDI_DMA_SLEEP, NULL,
&ring, &ring_len, &r->r_desc_acc_handle);
if (err != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "bfe_ring_desc_alloc() failed on"
" ddi_dma_mem_alloc()");
ddi_dma_free_handle(&r->r_desc_dma_handle);
kmem_free(r->r_buf_dma, size_krnl);
return (DDI_FAILURE);
}
err = ddi_dma_addr_bind_handle(r->r_desc_dma_handle,
NULL, ring, ring_len,
DDI_DMA_RDWR | DDI_DMA_CONSISTENT,
DDI_DMA_SLEEP, NULL,
&cookie, &count);
if (err != DDI_SUCCESS) {
bfe_error(bfe->bfe_dip, "bfe_ring_desc_alloc() failed on"
" ddi_dma_addr_bind_handle()");
ddi_dma_mem_free(&r->r_desc_acc_handle);
ddi_dma_free_handle(&r->r_desc_dma_handle);
kmem_free(r->r_buf_dma, size_krnl);
return (DDI_FAILURE);
}
/*
* We don't want to have multiple cookies. Descriptor should be
* aligned to PAGESIZE boundary.
*/
ASSERT(count == 1);
/* The actual descriptor for the ring */
r->r_desc_len = ring_len;
r->r_desc_cookie = cookie;
r->r_desc = (void *)ring;
bzero(r->r_desc, size_dma);
bzero(r->r_desc, ring_len);
/* For each descriptor, allocate a DMA buffer */
fail = 0;
for (i = 0; i < r->r_ndesc; i++) {
if (bfe_ring_buf_alloc(bfe, r, i, d) != DDI_SUCCESS) {
i--;
fail = 1;
break;
}
}
if (fail) {
while (i-- >= 0) {
bfe_ring_buf_free(r, i);
}
/* We don't need the descriptor anymore */
bfe_ring_desc_free(r);
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static int
bfe_rings_alloc(bfe_t *bfe)
{
/* TX */
mutex_init(&bfe->bfe_tx_ring.r_lock, NULL, MUTEX_DRIVER, NULL);
bfe->bfe_tx_ring.r_lockp = &bfe->bfe_tx_ring.r_lock;
bfe->bfe_tx_ring.r_buf_len = BFE_MTU + sizeof (struct ether_header) +
VLAN_TAGSZ + ETHERFCSL;
bfe->bfe_tx_ring.r_ndesc = TX_NUM_DESC;
bfe->bfe_tx_ring.r_bfe = bfe;
bfe->bfe_tx_ring.r_avail_desc = TX_NUM_DESC;
/* RX */
mutex_init(&bfe->bfe_rx_ring.r_lock, NULL, MUTEX_DRIVER, NULL);
bfe->bfe_rx_ring.r_lockp = &bfe->bfe_rx_ring.r_lock;
bfe->bfe_rx_ring.r_buf_len = BFE_MTU + sizeof (struct ether_header) +
VLAN_TAGSZ + ETHERFCSL + RX_HEAD_ROOM;
bfe->bfe_rx_ring.r_ndesc = RX_NUM_DESC;
bfe->bfe_rx_ring.r_bfe = bfe;
bfe->bfe_rx_ring.r_avail_desc = RX_NUM_DESC;
/* Allocate TX Ring */
if (bfe_ring_desc_alloc(bfe, &bfe->bfe_tx_ring,
DDI_DMA_WRITE) != DDI_SUCCESS)
return (DDI_FAILURE);
/* Allocate RX Ring */
if (bfe_ring_desc_alloc(bfe, &bfe->bfe_rx_ring,
DDI_DMA_READ) != DDI_SUCCESS) {
cmn_err(CE_NOTE, "RX ring allocation failed");
bfe_ring_desc_free(&bfe->bfe_tx_ring);
return (DDI_FAILURE);
}
bfe->bfe_tx_ring.r_flags = BFE_RING_ALLOCATED;
bfe->bfe_rx_ring.r_flags = BFE_RING_ALLOCATED;
return (DDI_SUCCESS);
}
static int
bfe_resume(dev_info_t *dip)
{
bfe_t *bfe;
int err = DDI_SUCCESS;
if ((bfe = ddi_get_driver_private(dip)) == NULL) {
bfe_error(dip, "Unexpected error (no driver private data)"
" while resume");
return (DDI_FAILURE);
}
/*
* Grab all the locks first.
*/
bfe_grab_locks(bfe);
bfe->bfe_chip_state = BFE_CHIP_RESUME;
bfe_init_vars(bfe);
/* PHY will also start running */
bfe_chip_reset(bfe);
if (bfe_chip_start(bfe) == DDI_FAILURE) {
bfe_error(dip, "Could not resume chip");
err = DDI_FAILURE;
goto done;
}
done:
bfe_release_locks(bfe);
return (err);
}
static int
bfe_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
int unit;
bfe_t *bfe;
mac_register_t *macreg;
int ret;
switch (cmd) {
case DDI_RESUME:
return (bfe_resume(dip));
case DDI_ATTACH:
break;
default:
return (DDI_FAILURE);
}
unit = ddi_get_instance(dip);
bfe = kmem_zalloc(sizeof (bfe_t), KM_SLEEP);
bfe->bfe_dip = dip;
bfe->bfe_unit = unit;
if (pci_config_setup(dip, &bfe->bfe_conf_handle) != DDI_SUCCESS) {
bfe_error(dip, "pci_config_setup failed");
goto fail0;
}
/*
* Enable IO space, Bus Master and Memory Space accessess.
*/
ret = pci_config_get16(bfe->bfe_conf_handle, PCI_CONF_COMM);
pci_config_put16(bfe->bfe_conf_handle, PCI_CONF_COMM,
PCI_COMM_IO | PCI_COMM_MAE | PCI_COMM_ME | ret);
ddi_set_driver_private(dip, bfe);
/* Identify hardware */
if (bfe_identify_hardware(bfe) == BFE_FAILURE) {
bfe_error(dip, "Could not identify device");
goto fail1;
}
if (bfe_regs_map(bfe) != DDI_SUCCESS) {
bfe_error(dip, "Could not map device registers");
goto fail1;
}
(void) bfe_get_chip_config(bfe);
/*
* Register with MAC layer
*/
if ((macreg = mac_alloc(MAC_VERSION)) == NULL) {
bfe_error(dip, "mac_alloc() failed");
goto fail2;
}
macreg->m_type_ident = MAC_PLUGIN_IDENT_ETHER;
macreg->m_driver = bfe;
macreg->m_dip = dip;
macreg->m_instance = unit;
macreg->m_src_addr = bfe->bfe_ether_addr;
macreg->m_callbacks = &bfe_mac_callbacks;
macreg->m_min_sdu = 0;
macreg->m_max_sdu = ETHERMTU;
macreg->m_margin = VLAN_TAGSZ;
if ((ret = mac_register(macreg, &bfe->bfe_machdl)) != 0) {
bfe_error(dip, "mac_register() failed with %d error", ret);
mac_free(macreg);
goto fail2;
}
mac_free(macreg);
rw_init(&bfe->bfe_rwlock, NULL, RW_DRIVER,
DDI_INTR_PRI(bfe->bfe_intrpri));
if (bfe_add_intr(bfe) != DDI_SUCCESS) {
bfe_error(dip, "Could not add interrupt");
goto fail3;
}
if (bfe_rings_alloc(bfe) != DDI_SUCCESS) {
bfe_error(dip, "Could not allocate TX/RX Ring");
goto fail4;
}
/* Init and then reset the chip */
bfe->bfe_chip_action = 0;
bfe_init_vars(bfe);
/* PHY will also start running */
bfe_chip_reset(bfe);
/*
* Even though we enable the interrupts here but chip's interrupt
* is not enabled yet. It will be enabled once we plumb the interface.
*/
if (ddi_intr_enable(bfe->bfe_intrhdl) != DDI_SUCCESS) {
bfe_error(dip, "Could not enable interrupt");
goto fail4;
}
return (DDI_SUCCESS);
fail4:
bfe_remove_intr(bfe);
fail3:
mac_unregister(bfe->bfe_machdl);
fail2:
bfe_unmap_regs(bfe);
fail1:
pci_config_teardown(&bfe->bfe_conf_handle);
fail0:
kmem_free(bfe, sizeof (bfe_t));
return (DDI_FAILURE);
}
static int
bfe_detach(dev_info_t *devinfo, ddi_detach_cmd_t cmd)
{
bfe_t *bfe;
bfe = ddi_get_driver_private(devinfo);
switch (cmd) {
case DDI_DETACH:
/*
* We need to stop the timer before grabbing locks otherwise
* we can land-up in deadlock with untimeout.
*/
bfe_stop_timer(bfe);
/*
* First unregister with MAC layer before stopping DMA
* engine.
*/
if (mac_unregister(bfe->bfe_machdl) != DDI_SUCCESS)
return (DDI_FAILURE);
bfe->bfe_machdl = NULL;
/*
* Quiesce the chip first.
*/
bfe_grab_locks(bfe);
bfe_chip_halt(bfe);
bfe_stop_phy(bfe);
bfe_release_locks(bfe);
(void) ddi_intr_disable(bfe->bfe_intrhdl);
/* Make sure timer is gone. */
bfe_stop_timer(bfe);
/*
* Free the DMA resources for buffer and then descriptors
*/
if (bfe->bfe_tx_ring.r_flags == BFE_RING_ALLOCATED) {
/* TX */
bfe_buffer_free(&bfe->bfe_tx_ring);
bfe_ring_desc_free(&bfe->bfe_tx_ring);
}
if (bfe->bfe_rx_ring.r_flags == BFE_RING_ALLOCATED) {
/* RX */
bfe_buffer_free(&bfe->bfe_rx_ring);
bfe_ring_desc_free(&bfe->bfe_rx_ring);
}
bfe_remove_intr(bfe);
bfe_unmap_regs(bfe);
pci_config_teardown(&bfe->bfe_conf_handle);
mutex_destroy(&bfe->bfe_tx_ring.r_lock);
mutex_destroy(&bfe->bfe_rx_ring.r_lock);
rw_destroy(&bfe->bfe_rwlock);
kmem_free(bfe, sizeof (bfe_t));
ddi_set_driver_private(devinfo, NULL);
return (DDI_SUCCESS);
case DDI_SUSPEND:
/*
* We need to stop the timer before grabbing locks otherwise
* we can land-up in deadlock with untimeout.
*/
bfe_stop_timer(bfe);
/*
* Grab all the locks first.
*/
bfe_grab_locks(bfe);
bfe_chip_halt(bfe);
bfe_stop_phy(bfe);
bfe->bfe_chip_state = BFE_CHIP_SUSPENDED;
bfe_release_locks(bfe);
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
/*
* Quiesce the card for fast reboot
*/
int
bfe_quiesce(dev_info_t *dev_info)
{
bfe_t *bfe;
bfe = ddi_get_driver_private(dev_info);
bfe_chip_halt(bfe);
bfe_stop_phy(bfe);
bfe->bfe_chip_state = BFE_CHIP_QUIESCED;
return (DDI_SUCCESS);
}
static struct cb_ops bfe_cb_ops = {
nulldev, /* cb_open */
nulldev, /* cb_close */
nodev, /* cb_strategy */
nodev, /* cb_print */
nodev, /* cb_dump */
nodev, /* cb_read */
nodev, /* cb_write */
nodev, /* cb_ioctl */
nodev, /* cb_devmap */
nodev, /* cb_mmap */
nodev, /* cb_segmap */
nochpoll, /* cb_chpoll */
ddi_prop_op, /* cb_prop_op */
NULL, /* cb_stream */
D_MP | D_HOTPLUG, /* cb_flag */
CB_REV, /* cb_rev */
nodev, /* cb_aread */
nodev /* cb_awrite */
};
static struct dev_ops bfe_dev_ops = {
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
NULL, /* devo_getinfo */
nulldev, /* devo_identify */
nulldev, /* devo_probe */
bfe_attach, /* devo_attach */
bfe_detach, /* devo_detach */
nodev, /* devo_reset */
&bfe_cb_ops, /* devo_cb_ops */
NULL, /* devo_bus_ops */
ddi_power, /* devo_power */
bfe_quiesce /* devo_quiesce */
};
static struct modldrv bfe_modldrv = {
&mod_driverops,
bfe_ident,
&bfe_dev_ops
};
static struct modlinkage modlinkage = {
MODREV_1, (void *)&bfe_modldrv, NULL
};
int
_info(struct modinfo *modinfop)
{
return (mod_info(&modlinkage, modinfop));
}
int
_init(void)
{
int status;
mac_init_ops(&bfe_dev_ops, MODULE_NAME);
status = mod_install(&modlinkage);
if (status == DDI_FAILURE)
mac_fini_ops(&bfe_dev_ops);
return (status);
}
int
_fini(void)
{
int status;
status = mod_remove(&modlinkage);
if (status == 0) {
mac_fini_ops(&bfe_dev_ops);
}
return (status);
}