138df6492SMark Einon /* Agere Systems Inc. 238df6492SMark Einon * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs 338df6492SMark Einon * 438df6492SMark Einon * Copyright © 2005 Agere Systems Inc. 538df6492SMark Einon * All rights reserved. 638df6492SMark Einon * http://www.agere.com 738df6492SMark Einon * 838df6492SMark Einon * Copyright (c) 2011 Mark Einon <mark.einon@gmail.com> 938df6492SMark Einon * 1038df6492SMark Einon *------------------------------------------------------------------------------ 1138df6492SMark Einon * 1238df6492SMark Einon * SOFTWARE LICENSE 1338df6492SMark Einon * 1438df6492SMark Einon * This software is provided subject to the following terms and conditions, 1538df6492SMark Einon * which you should read carefully before using the software. Using this 1638df6492SMark Einon * software indicates your acceptance of these terms and conditions. If you do 1738df6492SMark Einon * not agree with these terms and conditions, do not use the software. 1838df6492SMark Einon * 1938df6492SMark Einon * Copyright © 2005 Agere Systems Inc. 2038df6492SMark Einon * All rights reserved. 2138df6492SMark Einon * 2238df6492SMark Einon * Redistribution and use in source or binary forms, with or without 2338df6492SMark Einon * modifications, are permitted provided that the following conditions are met: 2438df6492SMark Einon * 2538df6492SMark Einon * . Redistributions of source code must retain the above copyright notice, this 2638df6492SMark Einon * list of conditions and the following Disclaimer as comments in the code as 2738df6492SMark Einon * well as in the documentation and/or other materials provided with the 2838df6492SMark Einon * distribution. 2938df6492SMark Einon * 3038df6492SMark Einon * . Redistributions in binary form must reproduce the above copyright notice, 3138df6492SMark Einon * this list of conditions and the following Disclaimer in the documentation 3238df6492SMark Einon * and/or other materials provided with the distribution. 3338df6492SMark Einon * 3438df6492SMark Einon * . Neither the name of Agere Systems Inc. nor the names of the contributors 3538df6492SMark Einon * may be used to endorse or promote products derived from this software 3638df6492SMark Einon * without specific prior written permission. 3738df6492SMark Einon * 3838df6492SMark Einon * Disclaimer 3938df6492SMark Einon * 4038df6492SMark Einon * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 4138df6492SMark Einon * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF 4238df6492SMark Einon * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY 4338df6492SMark Einon * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN 4438df6492SMark Einon * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY 4538df6492SMark Einon * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 4638df6492SMark Einon * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 4738df6492SMark Einon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 4838df6492SMark Einon * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT 4938df6492SMark Einon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 5038df6492SMark Einon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 5138df6492SMark Einon * DAMAGE. 5238df6492SMark Einon */ 5338df6492SMark Einon 5438df6492SMark Einon #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5538df6492SMark Einon 5638df6492SMark Einon #include <linux/pci.h> 5738df6492SMark Einon #include <linux/module.h> 5838df6492SMark Einon #include <linux/types.h> 5938df6492SMark Einon #include <linux/kernel.h> 6038df6492SMark Einon 6138df6492SMark Einon #include <linux/sched.h> 6238df6492SMark Einon #include <linux/ptrace.h> 6338df6492SMark Einon #include <linux/slab.h> 6438df6492SMark Einon #include <linux/ctype.h> 6538df6492SMark Einon #include <linux/string.h> 6638df6492SMark Einon #include <linux/timer.h> 6738df6492SMark Einon #include <linux/interrupt.h> 6838df6492SMark Einon #include <linux/in.h> 6938df6492SMark Einon #include <linux/delay.h> 7038df6492SMark Einon #include <linux/bitops.h> 7138df6492SMark Einon #include <linux/io.h> 7238df6492SMark Einon 7338df6492SMark Einon #include <linux/netdevice.h> 7438df6492SMark Einon #include <linux/etherdevice.h> 7538df6492SMark Einon #include <linux/skbuff.h> 7638df6492SMark Einon #include <linux/if_arp.h> 7738df6492SMark Einon #include <linux/ioport.h> 7838df6492SMark Einon #include <linux/crc32.h> 7938df6492SMark Einon #include <linux/random.h> 8038df6492SMark Einon #include <linux/phy.h> 8138df6492SMark Einon 8238df6492SMark Einon #include "et131x.h" 8338df6492SMark Einon 8438df6492SMark Einon MODULE_AUTHOR("Victor Soriano <vjsoriano@agere.com>"); 8538df6492SMark Einon MODULE_AUTHOR("Mark Einon <mark.einon@gmail.com>"); 8638df6492SMark Einon MODULE_LICENSE("Dual BSD/GPL"); 8738df6492SMark Einon MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver for the ET1310 by Agere Systems"); 8838df6492SMark Einon 8938df6492SMark Einon /* EEPROM defines */ 9038df6492SMark Einon #define MAX_NUM_REGISTER_POLLS 1000 9138df6492SMark Einon #define MAX_NUM_WRITE_RETRIES 2 9238df6492SMark Einon 9338df6492SMark Einon /* MAC defines */ 9438df6492SMark Einon #define COUNTER_WRAP_16_BIT 0x10000 9538df6492SMark Einon #define COUNTER_WRAP_12_BIT 0x1000 9638df6492SMark Einon 9738df6492SMark Einon /* PCI defines */ 9838df6492SMark Einon #define INTERNAL_MEM_SIZE 0x400 /* 1024 of internal memory */ 9938df6492SMark Einon #define INTERNAL_MEM_RX_OFFSET 0x1FF /* 50% Tx, 50% Rx */ 10038df6492SMark Einon 10138df6492SMark Einon /* ISR defines */ 10238df6492SMark Einon /* For interrupts, normal running is: 10338df6492SMark Einon * rxdma_xfr_done, phy_interrupt, mac_stat_interrupt, 10438df6492SMark Einon * watchdog_interrupt & txdma_xfer_done 10538df6492SMark Einon * 10638df6492SMark Einon * In both cases, when flow control is enabled for either Tx or bi-direction, 10738df6492SMark Einon * we additional enable rx_fbr0_low and rx_fbr1_low, so we know when the 10838df6492SMark Einon * buffer rings are running low. 10938df6492SMark Einon */ 11038df6492SMark Einon #define INT_MASK_DISABLE 0xffffffff 11138df6492SMark Einon 11238df6492SMark Einon /* NOTE: Masking out MAC_STAT Interrupt for now... 11338df6492SMark Einon * #define INT_MASK_ENABLE 0xfff6bf17 11438df6492SMark Einon * #define INT_MASK_ENABLE_NO_FLOW 0xfff6bfd7 11538df6492SMark Einon */ 11638df6492SMark Einon #define INT_MASK_ENABLE 0xfffebf17 11738df6492SMark Einon #define INT_MASK_ENABLE_NO_FLOW 0xfffebfd7 11838df6492SMark Einon 11938df6492SMark Einon /* General defines */ 12038df6492SMark Einon /* Packet and header sizes */ 12138df6492SMark Einon #define NIC_MIN_PACKET_SIZE 60 12238df6492SMark Einon 12338df6492SMark Einon /* Multicast list size */ 12438df6492SMark Einon #define NIC_MAX_MCAST_LIST 128 12538df6492SMark Einon 12638df6492SMark Einon /* Supported Filters */ 12738df6492SMark Einon #define ET131X_PACKET_TYPE_DIRECTED 0x0001 12838df6492SMark Einon #define ET131X_PACKET_TYPE_MULTICAST 0x0002 12938df6492SMark Einon #define ET131X_PACKET_TYPE_BROADCAST 0x0004 13038df6492SMark Einon #define ET131X_PACKET_TYPE_PROMISCUOUS 0x0008 13138df6492SMark Einon #define ET131X_PACKET_TYPE_ALL_MULTICAST 0x0010 13238df6492SMark Einon 13338df6492SMark Einon /* Tx Timeout */ 13438df6492SMark Einon #define ET131X_TX_TIMEOUT (1 * HZ) 13538df6492SMark Einon #define NIC_SEND_HANG_THRESHOLD 0 13638df6492SMark Einon 13738df6492SMark Einon /* MP_ADAPTER flags */ 13838df6492SMark Einon #define FMP_ADAPTER_INTERRUPT_IN_USE 0x00000008 13938df6492SMark Einon 14038df6492SMark Einon /* MP_SHARED flags */ 14138df6492SMark Einon #define FMP_ADAPTER_LOWER_POWER 0x00200000 14238df6492SMark Einon 14338df6492SMark Einon #define FMP_ADAPTER_NON_RECOVER_ERROR 0x00800000 14438df6492SMark Einon #define FMP_ADAPTER_HARDWARE_ERROR 0x04000000 14538df6492SMark Einon 14638df6492SMark Einon #define FMP_ADAPTER_FAIL_SEND_MASK 0x3ff00000 14738df6492SMark Einon 14838df6492SMark Einon /* Some offsets in PCI config space that are actually used. */ 14938df6492SMark Einon #define ET1310_PCI_MAC_ADDRESS 0xA4 15038df6492SMark Einon #define ET1310_PCI_EEPROM_STATUS 0xB2 15138df6492SMark Einon #define ET1310_PCI_ACK_NACK 0xC0 15238df6492SMark Einon #define ET1310_PCI_REPLAY 0xC2 15338df6492SMark Einon #define ET1310_PCI_L0L1LATENCY 0xCF 15438df6492SMark Einon 15538df6492SMark Einon /* PCI Product IDs */ 15638df6492SMark Einon #define ET131X_PCI_DEVICE_ID_GIG 0xED00 /* ET1310 1000 Base-T 8 */ 15738df6492SMark Einon #define ET131X_PCI_DEVICE_ID_FAST 0xED01 /* ET1310 100 Base-T */ 15838df6492SMark Einon 15938df6492SMark Einon /* Define order of magnitude converter */ 16038df6492SMark Einon #define NANO_IN_A_MICRO 1000 16138df6492SMark Einon 16238df6492SMark Einon #define PARM_RX_NUM_BUFS_DEF 4 16338df6492SMark Einon #define PARM_RX_TIME_INT_DEF 10 16438df6492SMark Einon #define PARM_RX_MEM_END_DEF 0x2bc 16538df6492SMark Einon #define PARM_TX_TIME_INT_DEF 40 16638df6492SMark Einon #define PARM_TX_NUM_BUFS_DEF 4 16738df6492SMark Einon #define PARM_DMA_CACHE_DEF 0 16838df6492SMark Einon 16938df6492SMark Einon /* RX defines */ 17038df6492SMark Einon #define FBR_CHUNKS 32 17138df6492SMark Einon #define MAX_DESC_PER_RING_RX 1024 17238df6492SMark Einon 17338df6492SMark Einon /* number of RFDs - default and min */ 17438df6492SMark Einon #define RFD_LOW_WATER_MARK 40 17538df6492SMark Einon #define NIC_DEFAULT_NUM_RFD 1024 17638df6492SMark Einon #define NUM_FBRS 2 17738df6492SMark Einon 17838df6492SMark Einon #define MAX_PACKETS_HANDLED 256 17944770e11SJarod Wilson #define ET131X_MIN_MTU 64 18044770e11SJarod Wilson #define ET131X_MAX_MTU 9216 18138df6492SMark Einon 18238df6492SMark Einon #define ALCATEL_MULTICAST_PKT 0x01000000 18338df6492SMark Einon #define ALCATEL_BROADCAST_PKT 0x02000000 18438df6492SMark Einon 18538df6492SMark Einon /* typedefs for Free Buffer Descriptors */ 18638df6492SMark Einon struct fbr_desc { 18738df6492SMark Einon u32 addr_lo; 18838df6492SMark Einon u32 addr_hi; 18938df6492SMark Einon u32 word2; /* Bits 10-31 reserved, 0-9 descriptor */ 19038df6492SMark Einon }; 19138df6492SMark Einon 19238df6492SMark Einon /* Packet Status Ring Descriptors 19338df6492SMark Einon * 19438df6492SMark Einon * Word 0: 19538df6492SMark Einon * 19638df6492SMark Einon * top 16 bits are from the Alcatel Status Word as enumerated in 19738df6492SMark Einon * PE-MCXMAC Data Sheet IPD DS54 0210-1 (also IPD-DS80 0205-2) 19838df6492SMark Einon * 19938df6492SMark Einon * 0: hp hash pass 20038df6492SMark Einon * 1: ipa IP checksum assist 20138df6492SMark Einon * 2: ipp IP checksum pass 20238df6492SMark Einon * 3: tcpa TCP checksum assist 20338df6492SMark Einon * 4: tcpp TCP checksum pass 20438df6492SMark Einon * 5: wol WOL Event 20538df6492SMark Einon * 6: rxmac_error RXMAC Error Indicator 20638df6492SMark Einon * 7: drop Drop packet 20738df6492SMark Einon * 8: ft Frame Truncated 20838df6492SMark Einon * 9: jp Jumbo Packet 20938df6492SMark Einon * 10: vp VLAN Packet 21038df6492SMark Einon * 11-15: unused 21138df6492SMark Einon * 16: asw_prev_pkt_dropped e.g. IFG too small on previous 21238df6492SMark Einon * 17: asw_RX_DV_event short receive event detected 21338df6492SMark Einon * 18: asw_false_carrier_event bad carrier since last good packet 21438df6492SMark Einon * 19: asw_code_err one or more nibbles signalled as errors 21538df6492SMark Einon * 20: asw_CRC_err CRC error 21638df6492SMark Einon * 21: asw_len_chk_err frame length field incorrect 21738df6492SMark Einon * 22: asw_too_long frame length > 1518 bytes 21838df6492SMark Einon * 23: asw_OK valid CRC + no code error 21938df6492SMark Einon * 24: asw_multicast has a multicast address 22038df6492SMark Einon * 25: asw_broadcast has a broadcast address 22138df6492SMark Einon * 26: asw_dribble_nibble spurious bits after EOP 22238df6492SMark Einon * 27: asw_control_frame is a control frame 22338df6492SMark Einon * 28: asw_pause_frame is a pause frame 22438df6492SMark Einon * 29: asw_unsupported_op unsupported OP code 22538df6492SMark Einon * 30: asw_VLAN_tag VLAN tag detected 22638df6492SMark Einon * 31: asw_long_evt Rx long event 22738df6492SMark Einon * 22838df6492SMark Einon * Word 1: 22938df6492SMark Einon * 0-15: length length in bytes 23038df6492SMark Einon * 16-25: bi Buffer Index 23138df6492SMark Einon * 26-27: ri Ring Index 23238df6492SMark Einon * 28-31: reserved 23338df6492SMark Einon */ 23438df6492SMark Einon struct pkt_stat_desc { 23538df6492SMark Einon u32 word0; 23638df6492SMark Einon u32 word1; 23738df6492SMark Einon }; 23838df6492SMark Einon 23938df6492SMark Einon /* Typedefs for the RX DMA status word */ 24038df6492SMark Einon 24138df6492SMark Einon /* rx status word 0 holds part of the status bits of the Rx DMA engine 24238df6492SMark Einon * that get copied out to memory by the ET-1310. Word 0 is a 32 bit word 24338df6492SMark Einon * which contains the Free Buffer ring 0 and 1 available offset. 24438df6492SMark Einon * 24538df6492SMark Einon * bit 0-9 FBR1 offset 24638df6492SMark Einon * bit 10 Wrap flag for FBR1 24738df6492SMark Einon * bit 16-25 FBR0 offset 24838df6492SMark Einon * bit 26 Wrap flag for FBR0 24938df6492SMark Einon */ 25038df6492SMark Einon 25138df6492SMark Einon /* RXSTAT_WORD1_t structure holds part of the status bits of the Rx DMA engine 25238df6492SMark Einon * that get copied out to memory by the ET-1310. Word 3 is a 32 bit word 25338df6492SMark Einon * which contains the Packet Status Ring available offset. 25438df6492SMark Einon * 25538df6492SMark Einon * bit 0-15 reserved 25638df6492SMark Einon * bit 16-27 PSRoffset 25738df6492SMark Einon * bit 28 PSRwrap 25838df6492SMark Einon * bit 29-31 unused 25938df6492SMark Einon */ 26038df6492SMark Einon 26138df6492SMark Einon /* struct rx_status_block is a structure representing the status of the Rx 26238df6492SMark Einon * DMA engine it sits in free memory, and is pointed to by 0x101c / 0x1020 26338df6492SMark Einon */ 26438df6492SMark Einon struct rx_status_block { 26538df6492SMark Einon u32 word0; 26638df6492SMark Einon u32 word1; 26738df6492SMark Einon }; 26838df6492SMark Einon 26938df6492SMark Einon /* Structure for look-up table holding free buffer ring pointers, addresses 27038df6492SMark Einon * and state. 27138df6492SMark Einon */ 27238df6492SMark Einon struct fbr_lookup { 27338df6492SMark Einon void *virt[MAX_DESC_PER_RING_RX]; 27438df6492SMark Einon u32 bus_high[MAX_DESC_PER_RING_RX]; 27538df6492SMark Einon u32 bus_low[MAX_DESC_PER_RING_RX]; 27638df6492SMark Einon void *ring_virtaddr; 27738df6492SMark Einon dma_addr_t ring_physaddr; 27838df6492SMark Einon void *mem_virtaddrs[MAX_DESC_PER_RING_RX / FBR_CHUNKS]; 27938df6492SMark Einon dma_addr_t mem_physaddrs[MAX_DESC_PER_RING_RX / FBR_CHUNKS]; 28038df6492SMark Einon u32 local_full; 28138df6492SMark Einon u32 num_entries; 28238df6492SMark Einon dma_addr_t buffsize; 28338df6492SMark Einon }; 28438df6492SMark Einon 28538df6492SMark Einon /* struct rx_ring is the structure representing the adaptor's local 28638df6492SMark Einon * reference(s) to the rings 28738df6492SMark Einon */ 28838df6492SMark Einon struct rx_ring { 28938df6492SMark Einon struct fbr_lookup *fbr[NUM_FBRS]; 29038df6492SMark Einon void *ps_ring_virtaddr; 29138df6492SMark Einon dma_addr_t ps_ring_physaddr; 29238df6492SMark Einon u32 local_psr_full; 29338df6492SMark Einon u32 psr_entries; 29438df6492SMark Einon 29538df6492SMark Einon struct rx_status_block *rx_status_block; 29638df6492SMark Einon dma_addr_t rx_status_bus; 29738df6492SMark Einon 29838df6492SMark Einon struct list_head recv_list; 29938df6492SMark Einon u32 num_ready_recv; 30038df6492SMark Einon 30138df6492SMark Einon u32 num_rfd; 30238df6492SMark Einon 30338df6492SMark Einon bool unfinished_receives; 30438df6492SMark Einon }; 30538df6492SMark Einon 30638df6492SMark Einon /* TX defines */ 30738df6492SMark Einon /* word 2 of the control bits in the Tx Descriptor ring for the ET-1310 30838df6492SMark Einon * 30938df6492SMark Einon * 0-15: length of packet 31038df6492SMark Einon * 16-27: VLAN tag 31138df6492SMark Einon * 28: VLAN CFI 31238df6492SMark Einon * 29-31: VLAN priority 31338df6492SMark Einon * 31438df6492SMark Einon * word 3 of the control bits in the Tx Descriptor ring for the ET-1310 31538df6492SMark Einon * 31638df6492SMark Einon * 0: last packet in the sequence 31738df6492SMark Einon * 1: first packet in the sequence 31838df6492SMark Einon * 2: interrupt the processor when this pkt sent 31938df6492SMark Einon * 3: Control word - no packet data 32038df6492SMark Einon * 4: Issue half-duplex backpressure : XON/XOFF 32138df6492SMark Einon * 5: send pause frame 32238df6492SMark Einon * 6: Tx frame has error 32338df6492SMark Einon * 7: append CRC 32438df6492SMark Einon * 8: MAC override 32538df6492SMark Einon * 9: pad packet 32638df6492SMark Einon * 10: Packet is a Huge packet 32738df6492SMark Einon * 11: append VLAN tag 32838df6492SMark Einon * 12: IP checksum assist 32938df6492SMark Einon * 13: TCP checksum assist 33038df6492SMark Einon * 14: UDP checksum assist 33138df6492SMark Einon */ 33238df6492SMark Einon #define TXDESC_FLAG_LASTPKT 0x0001 33338df6492SMark Einon #define TXDESC_FLAG_FIRSTPKT 0x0002 33438df6492SMark Einon #define TXDESC_FLAG_INTPROC 0x0004 33538df6492SMark Einon 33638df6492SMark Einon /* struct tx_desc represents each descriptor on the ring */ 33738df6492SMark Einon struct tx_desc { 33838df6492SMark Einon u32 addr_hi; 33938df6492SMark Einon u32 addr_lo; 34038df6492SMark Einon u32 len_vlan; /* control words how to xmit the */ 34138df6492SMark Einon u32 flags; /* data (detailed above) */ 34238df6492SMark Einon }; 34338df6492SMark Einon 34438df6492SMark Einon /* The status of the Tx DMA engine it sits in free memory, and is pointed to 34538df6492SMark Einon * by 0x101c / 0x1020. This is a DMA10 type 34638df6492SMark Einon */ 34738df6492SMark Einon 34838df6492SMark Einon /* TCB (Transmit Control Block: Host Side) */ 34938df6492SMark Einon struct tcb { 35038df6492SMark Einon struct tcb *next; /* Next entry in ring */ 35138df6492SMark Einon u32 count; /* Used to spot stuck/lost packets */ 35238df6492SMark Einon u32 stale; /* Used to spot stuck/lost packets */ 35338df6492SMark Einon struct sk_buff *skb; /* Network skb we are tied to */ 35438df6492SMark Einon u32 index; /* Ring indexes */ 35538df6492SMark Einon u32 index_start; 35638df6492SMark Einon }; 35738df6492SMark Einon 35838df6492SMark Einon /* Structure representing our local reference(s) to the ring */ 35938df6492SMark Einon struct tx_ring { 36038df6492SMark Einon /* TCB (Transmit Control Block) memory and lists */ 36138df6492SMark Einon struct tcb *tcb_ring; 36238df6492SMark Einon 36338df6492SMark Einon /* List of TCBs that are ready to be used */ 36438df6492SMark Einon struct tcb *tcb_qhead; 36538df6492SMark Einon struct tcb *tcb_qtail; 36638df6492SMark Einon 36738df6492SMark Einon /* list of TCBs that are currently being sent. */ 36838df6492SMark Einon struct tcb *send_head; 36938df6492SMark Einon struct tcb *send_tail; 37038df6492SMark Einon int used; 37138df6492SMark Einon 37238df6492SMark Einon /* The actual descriptor ring */ 37338df6492SMark Einon struct tx_desc *tx_desc_ring; 37438df6492SMark Einon dma_addr_t tx_desc_ring_pa; 37538df6492SMark Einon 37638df6492SMark Einon /* send_idx indicates where we last wrote to in the descriptor ring. */ 37738df6492SMark Einon u32 send_idx; 37838df6492SMark Einon 37938df6492SMark Einon /* The location of the write-back status block */ 38038df6492SMark Einon u32 *tx_status; 38138df6492SMark Einon dma_addr_t tx_status_pa; 38238df6492SMark Einon 38338df6492SMark Einon /* Packets since the last IRQ: used for interrupt coalescing */ 38438df6492SMark Einon int since_irq; 38538df6492SMark Einon }; 38638df6492SMark Einon 38738df6492SMark Einon /* Do not change these values: if changed, then change also in respective 38838df6492SMark Einon * TXdma and Rxdma engines 38938df6492SMark Einon */ 39038df6492SMark Einon #define NUM_DESC_PER_RING_TX 512 /* TX Do not change these values */ 39138df6492SMark Einon #define NUM_TCB 64 39238df6492SMark Einon 39338df6492SMark Einon /* These values are all superseded by registry entries to facilitate tuning. 39438df6492SMark Einon * Once the desired performance has been achieved, the optimal registry values 39538df6492SMark Einon * should be re-populated to these #defines: 39638df6492SMark Einon */ 39738df6492SMark Einon #define TX_ERROR_PERIOD 1000 39838df6492SMark Einon 39938df6492SMark Einon #define LO_MARK_PERCENT_FOR_PSR 15 40038df6492SMark Einon #define LO_MARK_PERCENT_FOR_RX 15 40138df6492SMark Einon 40238df6492SMark Einon /* RFD (Receive Frame Descriptor) */ 40338df6492SMark Einon struct rfd { 40438df6492SMark Einon struct list_head list_node; 40538df6492SMark Einon struct sk_buff *skb; 40638df6492SMark Einon u32 len; /* total size of receive frame */ 40738df6492SMark Einon u16 bufferindex; 40838df6492SMark Einon u8 ringindex; 40938df6492SMark Einon }; 41038df6492SMark Einon 41138df6492SMark Einon /* Flow Control */ 41238df6492SMark Einon #define FLOW_BOTH 0 41338df6492SMark Einon #define FLOW_TXONLY 1 41438df6492SMark Einon #define FLOW_RXONLY 2 41538df6492SMark Einon #define FLOW_NONE 3 41638df6492SMark Einon 41738df6492SMark Einon /* Struct to define some device statistics */ 41838df6492SMark Einon struct ce_stats { 41938df6492SMark Einon u32 multicast_pkts_rcvd; 42038df6492SMark Einon u32 rcvd_pkts_dropped; 42138df6492SMark Einon 42238df6492SMark Einon u32 tx_underflows; 42338df6492SMark Einon u32 tx_collisions; 42438df6492SMark Einon u32 tx_excessive_collisions; 42538df6492SMark Einon u32 tx_first_collisions; 42638df6492SMark Einon u32 tx_late_collisions; 42738df6492SMark Einon u32 tx_max_pkt_errs; 42838df6492SMark Einon u32 tx_deferred; 42938df6492SMark Einon 43038df6492SMark Einon u32 rx_overflows; 43138df6492SMark Einon u32 rx_length_errs; 43238df6492SMark Einon u32 rx_align_errs; 43338df6492SMark Einon u32 rx_crc_errs; 43438df6492SMark Einon u32 rx_code_violations; 43538df6492SMark Einon u32 rx_other_errs; 43638df6492SMark Einon 43738df6492SMark Einon u32 interrupt_status; 43838df6492SMark Einon }; 43938df6492SMark Einon 44038df6492SMark Einon /* The private adapter structure */ 44138df6492SMark Einon struct et131x_adapter { 44238df6492SMark Einon struct net_device *netdev; 44338df6492SMark Einon struct pci_dev *pdev; 44438df6492SMark Einon struct mii_bus *mii_bus; 44538df6492SMark Einon struct napi_struct napi; 44638df6492SMark Einon 44738df6492SMark Einon /* Flags that indicate current state of the adapter */ 44838df6492SMark Einon u32 flags; 44938df6492SMark Einon 45038df6492SMark Einon /* local link state, to determine if a state change has occurred */ 45138df6492SMark Einon int link; 45238df6492SMark Einon 45338df6492SMark Einon /* Configuration */ 45438df6492SMark Einon u8 rom_addr[ETH_ALEN]; 45538df6492SMark Einon u8 addr[ETH_ALEN]; 45638df6492SMark Einon bool has_eeprom; 45738df6492SMark Einon u8 eeprom_data[2]; 45838df6492SMark Einon 45938df6492SMark Einon spinlock_t tcb_send_qlock; /* protects the tx_ring send tcb list */ 46038df6492SMark Einon spinlock_t tcb_ready_qlock; /* protects the tx_ring ready tcb list */ 46138df6492SMark Einon spinlock_t rcv_lock; /* protects the rx_ring receive list */ 46238df6492SMark Einon 46338df6492SMark Einon /* Packet Filter and look ahead size */ 46438df6492SMark Einon u32 packet_filter; 46538df6492SMark Einon 46638df6492SMark Einon /* multicast list */ 46738df6492SMark Einon u32 multicast_addr_count; 46838df6492SMark Einon u8 multicast_list[NIC_MAX_MCAST_LIST][ETH_ALEN]; 46938df6492SMark Einon 47038df6492SMark Einon /* Pointer to the device's PCI register space */ 47138df6492SMark Einon struct address_map __iomem *regs; 47238df6492SMark Einon 47338df6492SMark Einon /* Registry parameters */ 47438df6492SMark Einon u8 wanted_flow; /* Flow we want for 802.3x flow control */ 47538df6492SMark Einon u32 registry_jumbo_packet; /* Max supported ethernet packet size */ 47638df6492SMark Einon 47738df6492SMark Einon /* Derived from the registry: */ 47838df6492SMark Einon u8 flow; /* flow control validated by the far-end */ 47938df6492SMark Einon 48038df6492SMark Einon /* Minimize init-time */ 48138df6492SMark Einon struct timer_list error_timer; 48238df6492SMark Einon 48338df6492SMark Einon /* variable putting the phy into coma mode when boot up with no cable 48438df6492SMark Einon * plugged in after 5 seconds 48538df6492SMark Einon */ 48638df6492SMark Einon u8 boot_coma; 48738df6492SMark Einon 48838df6492SMark Einon /* Tx Memory Variables */ 48938df6492SMark Einon struct tx_ring tx_ring; 49038df6492SMark Einon 49138df6492SMark Einon /* Rx Memory Variables */ 49238df6492SMark Einon struct rx_ring rx_ring; 49338df6492SMark Einon 49438df6492SMark Einon struct ce_stats stats; 49538df6492SMark Einon }; 49638df6492SMark Einon 49738df6492SMark Einon static int eeprom_wait_ready(struct pci_dev *pdev, u32 *status) 49838df6492SMark Einon { 49938df6492SMark Einon u32 reg; 50038df6492SMark Einon int i; 50138df6492SMark Einon 50238df6492SMark Einon /* 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and 50338df6492SMark Einon * bits 7,1:0 both equal to 1, at least once after reset. 50438df6492SMark Einon * Subsequent operations need only to check that bits 1:0 are equal 50538df6492SMark Einon * to 1 prior to starting a single byte read/write 50638df6492SMark Einon */ 50738df6492SMark Einon for (i = 0; i < MAX_NUM_REGISTER_POLLS; i++) { 50838df6492SMark Einon if (pci_read_config_dword(pdev, LBCIF_DWORD1_GROUP, ®)) 50938df6492SMark Einon return -EIO; 51038df6492SMark Einon 51138df6492SMark Einon /* I2C idle and Phy Queue Avail both true */ 51238df6492SMark Einon if ((reg & 0x3000) == 0x3000) { 51338df6492SMark Einon if (status) 51438df6492SMark Einon *status = reg; 51538df6492SMark Einon return reg & 0xFF; 51638df6492SMark Einon } 51738df6492SMark Einon } 51838df6492SMark Einon return -ETIMEDOUT; 51938df6492SMark Einon } 52038df6492SMark Einon 52138df6492SMark Einon static int eeprom_write(struct et131x_adapter *adapter, u32 addr, u8 data) 52238df6492SMark Einon { 52338df6492SMark Einon struct pci_dev *pdev = adapter->pdev; 52438df6492SMark Einon int index = 0; 52538df6492SMark Einon int retries; 52638df6492SMark Einon int err = 0; 52738df6492SMark Einon int writeok = 0; 52838df6492SMark Einon u32 status; 52938df6492SMark Einon u32 val = 0; 53038df6492SMark Einon 53138df6492SMark Einon /* For an EEPROM, an I2C single byte write is defined as a START 53238df6492SMark Einon * condition followed by the device address, EEPROM address, one byte 53338df6492SMark Einon * of data and a STOP condition. The STOP condition will trigger the 53438df6492SMark Einon * EEPROM's internally timed write cycle to the nonvolatile memory. 53538df6492SMark Einon * All inputs are disabled during this write cycle and the EEPROM will 53638df6492SMark Einon * not respond to any access until the internal write is complete. 53738df6492SMark Einon */ 53838df6492SMark Einon err = eeprom_wait_ready(pdev, NULL); 53938df6492SMark Einon if (err < 0) 54038df6492SMark Einon return err; 54138df6492SMark Einon 54238df6492SMark Einon /* 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0, 54338df6492SMark Einon * and bits 1:0 both =0. Bit 5 should be set according to the 54438df6492SMark Einon * type of EEPROM being accessed (1=two byte addressing, 0=one 54538df6492SMark Einon * byte addressing). 54638df6492SMark Einon */ 54738df6492SMark Einon if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, 54838df6492SMark Einon LBCIF_CONTROL_LBCIF_ENABLE | 54938df6492SMark Einon LBCIF_CONTROL_I2C_WRITE)) 55038df6492SMark Einon return -EIO; 55138df6492SMark Einon 55238df6492SMark Einon /* Prepare EEPROM address for Step 3 */ 55338df6492SMark Einon for (retries = 0; retries < MAX_NUM_WRITE_RETRIES; retries++) { 55438df6492SMark Einon if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr)) 55538df6492SMark Einon break; 55638df6492SMark Einon /* Write the data to the LBCIF Data Register (the I2C write 55738df6492SMark Einon * will begin). 55838df6492SMark Einon */ 55938df6492SMark Einon if (pci_write_config_byte(pdev, LBCIF_DATA_REGISTER, data)) 56038df6492SMark Einon break; 56138df6492SMark Einon /* Monitor bit 1:0 of the LBCIF Status Register. When bits 56238df6492SMark Einon * 1:0 are both equal to 1, the I2C write has completed and the 56338df6492SMark Einon * internal write cycle of the EEPROM is about to start. 56438df6492SMark Einon * (bits 1:0 = 01 is a legal state while waiting from both 56538df6492SMark Einon * equal to 1, but bits 1:0 = 10 is invalid and implies that 56638df6492SMark Einon * something is broken). 56738df6492SMark Einon */ 56838df6492SMark Einon err = eeprom_wait_ready(pdev, &status); 56938df6492SMark Einon if (err < 0) 57038df6492SMark Einon return 0; 57138df6492SMark Einon 57238df6492SMark Einon /* Check bit 3 of the LBCIF Status Register. If equal to 1, 57338df6492SMark Einon * an error has occurred.Don't break here if we are revision 57438df6492SMark Einon * 1, this is so we do a blind write for load bug. 57538df6492SMark Einon */ 57638df6492SMark Einon if ((status & LBCIF_STATUS_GENERAL_ERROR) && 57738df6492SMark Einon adapter->pdev->revision == 0) 57838df6492SMark Einon break; 57938df6492SMark Einon 58038df6492SMark Einon /* Check bit 2 of the LBCIF Status Register. If equal to 1 an 58138df6492SMark Einon * ACK error has occurred on the address phase of the write. 58238df6492SMark Einon * This could be due to an actual hardware failure or the 58338df6492SMark Einon * EEPROM may still be in its internal write cycle from a 58438df6492SMark Einon * previous write. This write operation was ignored and must be 58538df6492SMark Einon *repeated later. 58638df6492SMark Einon */ 58738df6492SMark Einon if (status & LBCIF_STATUS_ACK_ERROR) { 58838df6492SMark Einon /* This could be due to an actual hardware failure 58938df6492SMark Einon * or the EEPROM may still be in its internal write 59038df6492SMark Einon * cycle from a previous write. This write operation 59138df6492SMark Einon * was ignored and must be repeated later. 59238df6492SMark Einon */ 59338df6492SMark Einon udelay(10); 59438df6492SMark Einon continue; 59538df6492SMark Einon } 59638df6492SMark Einon 59738df6492SMark Einon writeok = 1; 59838df6492SMark Einon break; 59938df6492SMark Einon } 60038df6492SMark Einon 60138df6492SMark Einon udelay(10); 60238df6492SMark Einon 60338df6492SMark Einon while (1) { 60438df6492SMark Einon if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, 60538df6492SMark Einon LBCIF_CONTROL_LBCIF_ENABLE)) 60638df6492SMark Einon writeok = 0; 60738df6492SMark Einon 60838df6492SMark Einon /* Do read until internal ACK_ERROR goes away meaning write 60938df6492SMark Einon * completed 61038df6492SMark Einon */ 61138df6492SMark Einon do { 61238df6492SMark Einon pci_write_config_dword(pdev, 61338df6492SMark Einon LBCIF_ADDRESS_REGISTER, 61438df6492SMark Einon addr); 61538df6492SMark Einon do { 61638df6492SMark Einon pci_read_config_dword(pdev, 61738df6492SMark Einon LBCIF_DATA_REGISTER, 61838df6492SMark Einon &val); 61938df6492SMark Einon } while ((val & 0x00010000) == 0); 62038df6492SMark Einon } while (val & 0x00040000); 62138df6492SMark Einon 62238df6492SMark Einon if ((val & 0xFF00) != 0xC000 || index == 10000) 62338df6492SMark Einon break; 62438df6492SMark Einon index++; 62538df6492SMark Einon } 62638df6492SMark Einon return writeok ? 0 : -EIO; 62738df6492SMark Einon } 62838df6492SMark Einon 62938df6492SMark Einon static int eeprom_read(struct et131x_adapter *adapter, u32 addr, u8 *pdata) 63038df6492SMark Einon { 63138df6492SMark Einon struct pci_dev *pdev = adapter->pdev; 63238df6492SMark Einon int err; 63338df6492SMark Einon u32 status; 63438df6492SMark Einon 63538df6492SMark Einon /* A single byte read is similar to the single byte write, with the 63638df6492SMark Einon * exception of the data flow: 63738df6492SMark Einon */ 63838df6492SMark Einon err = eeprom_wait_ready(pdev, NULL); 63938df6492SMark Einon if (err < 0) 64038df6492SMark Einon return err; 64138df6492SMark Einon /* Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0, 64238df6492SMark Einon * and bits 1:0 both =0. Bit 5 should be set according to the type 64338df6492SMark Einon * of EEPROM being accessed (1=two byte addressing, 0=one byte 64438df6492SMark Einon * addressing). 64538df6492SMark Einon */ 64638df6492SMark Einon if (pci_write_config_byte(pdev, LBCIF_CONTROL_REGISTER, 64738df6492SMark Einon LBCIF_CONTROL_LBCIF_ENABLE)) 64838df6492SMark Einon return -EIO; 64938df6492SMark Einon /* Write the address to the LBCIF Address Register (I2C read will 65038df6492SMark Einon * begin). 65138df6492SMark Einon */ 65238df6492SMark Einon if (pci_write_config_dword(pdev, LBCIF_ADDRESS_REGISTER, addr)) 65338df6492SMark Einon return -EIO; 65438df6492SMark Einon /* Monitor bit 0 of the LBCIF Status Register. When = 1, I2C read 65538df6492SMark Einon * is complete. (if bit 1 =1 and bit 0 stays = 0, a hardware failure 65638df6492SMark Einon * has occurred). 65738df6492SMark Einon */ 65838df6492SMark Einon err = eeprom_wait_ready(pdev, &status); 65938df6492SMark Einon if (err < 0) 66038df6492SMark Einon return err; 66138df6492SMark Einon /* Regardless of error status, read data byte from LBCIF Data 66238df6492SMark Einon * Register. 66338df6492SMark Einon */ 66438df6492SMark Einon *pdata = err; 66538df6492SMark Einon 66638df6492SMark Einon return (status & LBCIF_STATUS_ACK_ERROR) ? -EIO : 0; 66738df6492SMark Einon } 66838df6492SMark Einon 66938df6492SMark Einon static int et131x_init_eeprom(struct et131x_adapter *adapter) 67038df6492SMark Einon { 67138df6492SMark Einon struct pci_dev *pdev = adapter->pdev; 67238df6492SMark Einon u8 eestatus; 67338df6492SMark Einon 67438df6492SMark Einon pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus); 67538df6492SMark Einon 67638df6492SMark Einon /* THIS IS A WORKAROUND: 67738df6492SMark Einon * I need to call this function twice to get my card in a 67838df6492SMark Einon * LG M1 Express Dual running. I tried also a msleep before this 67938df6492SMark Einon * function, because I thought there could be some time conditions 68038df6492SMark Einon * but it didn't work. Call the whole function twice also work. 68138df6492SMark Einon */ 68238df6492SMark Einon if (pci_read_config_byte(pdev, ET1310_PCI_EEPROM_STATUS, &eestatus)) { 68338df6492SMark Einon dev_err(&pdev->dev, 68438df6492SMark Einon "Could not read PCI config space for EEPROM Status\n"); 68538df6492SMark Einon return -EIO; 68638df6492SMark Einon } 68738df6492SMark Einon 68838df6492SMark Einon /* Determine if the error(s) we care about are present. If they are 68938df6492SMark Einon * present we need to fail. 69038df6492SMark Einon */ 69138df6492SMark Einon if (eestatus & 0x4C) { 69238df6492SMark Einon int write_failed = 0; 69338df6492SMark Einon 69438df6492SMark Einon if (pdev->revision == 0x01) { 69538df6492SMark Einon int i; 69638df6492SMark Einon static const u8 eedata[4] = { 0xFE, 0x13, 0x10, 0xFF }; 69738df6492SMark Einon 69838df6492SMark Einon /* Re-write the first 4 bytes if we have an eeprom 69938df6492SMark Einon * present and the revision id is 1, this fixes the 70038df6492SMark Einon * corruption seen with 1310 B Silicon 70138df6492SMark Einon */ 70238df6492SMark Einon for (i = 0; i < 3; i++) 70338df6492SMark Einon if (eeprom_write(adapter, i, eedata[i]) < 0) 70438df6492SMark Einon write_failed = 1; 70538df6492SMark Einon } 70638df6492SMark Einon if (pdev->revision != 0x01 || write_failed) { 70738df6492SMark Einon dev_err(&pdev->dev, 70838df6492SMark Einon "Fatal EEPROM Status Error - 0x%04x\n", 70938df6492SMark Einon eestatus); 71038df6492SMark Einon 71138df6492SMark Einon /* This error could mean that there was an error 71238df6492SMark Einon * reading the eeprom or that the eeprom doesn't exist. 71338df6492SMark Einon * We will treat each case the same and not try to 71438df6492SMark Einon * gather additional information that normally would 71538df6492SMark Einon * come from the eeprom, like MAC Address 71638df6492SMark Einon */ 71738df6492SMark Einon adapter->has_eeprom = 0; 71838df6492SMark Einon return -EIO; 71938df6492SMark Einon } 72038df6492SMark Einon } 72138df6492SMark Einon adapter->has_eeprom = 1; 72238df6492SMark Einon 72338df6492SMark Einon /* Read the EEPROM for information regarding LED behavior. Refer to 72438df6492SMark Einon * et131x_xcvr_init() for its use. 72538df6492SMark Einon */ 72638df6492SMark Einon eeprom_read(adapter, 0x70, &adapter->eeprom_data[0]); 72738df6492SMark Einon eeprom_read(adapter, 0x71, &adapter->eeprom_data[1]); 72838df6492SMark Einon 72938df6492SMark Einon if (adapter->eeprom_data[0] != 0xcd) 73038df6492SMark Einon /* Disable all optional features */ 73138df6492SMark Einon adapter->eeprom_data[1] = 0x00; 73238df6492SMark Einon 73338df6492SMark Einon return 0; 73438df6492SMark Einon } 73538df6492SMark Einon 73638df6492SMark Einon static void et131x_rx_dma_enable(struct et131x_adapter *adapter) 73738df6492SMark Einon { 73838df6492SMark Einon /* Setup the receive dma configuration register for normal operation */ 73938df6492SMark Einon u32 csr = ET_RXDMA_CSR_FBR1_ENABLE; 74038df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 74138df6492SMark Einon 74238df6492SMark Einon if (rx_ring->fbr[1]->buffsize == 4096) 74338df6492SMark Einon csr |= ET_RXDMA_CSR_FBR1_SIZE_LO; 74438df6492SMark Einon else if (rx_ring->fbr[1]->buffsize == 8192) 74538df6492SMark Einon csr |= ET_RXDMA_CSR_FBR1_SIZE_HI; 74638df6492SMark Einon else if (rx_ring->fbr[1]->buffsize == 16384) 74738df6492SMark Einon csr |= ET_RXDMA_CSR_FBR1_SIZE_LO | ET_RXDMA_CSR_FBR1_SIZE_HI; 74838df6492SMark Einon 74938df6492SMark Einon csr |= ET_RXDMA_CSR_FBR0_ENABLE; 75038df6492SMark Einon if (rx_ring->fbr[0]->buffsize == 256) 75138df6492SMark Einon csr |= ET_RXDMA_CSR_FBR0_SIZE_LO; 75238df6492SMark Einon else if (rx_ring->fbr[0]->buffsize == 512) 75338df6492SMark Einon csr |= ET_RXDMA_CSR_FBR0_SIZE_HI; 75438df6492SMark Einon else if (rx_ring->fbr[0]->buffsize == 1024) 75538df6492SMark Einon csr |= ET_RXDMA_CSR_FBR0_SIZE_LO | ET_RXDMA_CSR_FBR0_SIZE_HI; 75638df6492SMark Einon writel(csr, &adapter->regs->rxdma.csr); 75738df6492SMark Einon 75838df6492SMark Einon csr = readl(&adapter->regs->rxdma.csr); 75938df6492SMark Einon if (csr & ET_RXDMA_CSR_HALT_STATUS) { 76038df6492SMark Einon udelay(5); 76138df6492SMark Einon csr = readl(&adapter->regs->rxdma.csr); 76238df6492SMark Einon if (csr & ET_RXDMA_CSR_HALT_STATUS) { 76338df6492SMark Einon dev_err(&adapter->pdev->dev, 76438df6492SMark Einon "RX Dma failed to exit halt state. CSR 0x%08x\n", 76538df6492SMark Einon csr); 76638df6492SMark Einon } 76738df6492SMark Einon } 76838df6492SMark Einon } 76938df6492SMark Einon 77038df6492SMark Einon static void et131x_rx_dma_disable(struct et131x_adapter *adapter) 77138df6492SMark Einon { 77238df6492SMark Einon u32 csr; 77338df6492SMark Einon /* Setup the receive dma configuration register */ 77438df6492SMark Einon writel(ET_RXDMA_CSR_HALT | ET_RXDMA_CSR_FBR1_ENABLE, 77538df6492SMark Einon &adapter->regs->rxdma.csr); 77638df6492SMark Einon csr = readl(&adapter->regs->rxdma.csr); 77738df6492SMark Einon if (!(csr & ET_RXDMA_CSR_HALT_STATUS)) { 77838df6492SMark Einon udelay(5); 77938df6492SMark Einon csr = readl(&adapter->regs->rxdma.csr); 78038df6492SMark Einon if (!(csr & ET_RXDMA_CSR_HALT_STATUS)) 78138df6492SMark Einon dev_err(&adapter->pdev->dev, 78238df6492SMark Einon "RX Dma failed to enter halt state. CSR 0x%08x\n", 78338df6492SMark Einon csr); 78438df6492SMark Einon } 78538df6492SMark Einon } 78638df6492SMark Einon 78738df6492SMark Einon static void et131x_tx_dma_enable(struct et131x_adapter *adapter) 78838df6492SMark Einon { 78938df6492SMark Einon /* Setup the transmit dma configuration register for normal 79038df6492SMark Einon * operation 79138df6492SMark Einon */ 79238df6492SMark Einon writel(ET_TXDMA_SNGL_EPKT | (PARM_DMA_CACHE_DEF << ET_TXDMA_CACHE_SHIFT), 79338df6492SMark Einon &adapter->regs->txdma.csr); 79438df6492SMark Einon } 79538df6492SMark Einon 79638df6492SMark Einon static inline void add_10bit(u32 *v, int n) 79738df6492SMark Einon { 79838df6492SMark Einon *v = INDEX10(*v + n) | (*v & ET_DMA10_WRAP); 79938df6492SMark Einon } 80038df6492SMark Einon 80138df6492SMark Einon static inline void add_12bit(u32 *v, int n) 80238df6492SMark Einon { 80338df6492SMark Einon *v = INDEX12(*v + n) | (*v & ET_DMA12_WRAP); 80438df6492SMark Einon } 80538df6492SMark Einon 80638df6492SMark Einon static void et1310_config_mac_regs1(struct et131x_adapter *adapter) 80738df6492SMark Einon { 80838df6492SMark Einon struct mac_regs __iomem *macregs = &adapter->regs->mac; 80938df6492SMark Einon u32 station1; 81038df6492SMark Einon u32 station2; 81138df6492SMark Einon u32 ipg; 81238df6492SMark Einon 81338df6492SMark Einon /* First we need to reset everything. Write to MAC configuration 81438df6492SMark Einon * register 1 to perform reset. 81538df6492SMark Einon */ 81638df6492SMark Einon writel(ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET | 81738df6492SMark Einon ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | 81838df6492SMark Einon ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC, 81938df6492SMark Einon ¯egs->cfg1); 82038df6492SMark Einon 82138df6492SMark Einon /* Next lets configure the MAC Inter-packet gap register */ 82238df6492SMark Einon ipg = 0x38005860; /* IPG1 0x38 IPG2 0x58 B2B 0x60 */ 82338df6492SMark Einon ipg |= 0x50 << 8; /* ifg enforce 0x50 */ 82438df6492SMark Einon writel(ipg, ¯egs->ipg); 82538df6492SMark Einon 82638df6492SMark Einon /* Next lets configure the MAC Half Duplex register */ 82738df6492SMark Einon /* BEB trunc 0xA, Ex Defer, Rexmit 0xF Coll 0x37 */ 82838df6492SMark Einon writel(0x00A1F037, ¯egs->hfdp); 82938df6492SMark Einon 83038df6492SMark Einon /* Next lets configure the MAC Interface Control register */ 83138df6492SMark Einon writel(0, ¯egs->if_ctrl); 83238df6492SMark Einon 83338df6492SMark Einon writel(ET_MAC_MIIMGMT_CLK_RST, ¯egs->mii_mgmt_cfg); 83438df6492SMark Einon 83538df6492SMark Einon /* Next lets configure the MAC Station Address register. These 83638df6492SMark Einon * values are read from the EEPROM during initialization and stored 83738df6492SMark Einon * in the adapter structure. We write what is stored in the adapter 83838df6492SMark Einon * structure to the MAC Station Address registers high and low. This 83938df6492SMark Einon * station address is used for generating and checking pause control 84038df6492SMark Einon * packets. 84138df6492SMark Einon */ 84238df6492SMark Einon station2 = (adapter->addr[1] << ET_MAC_STATION_ADDR2_OC2_SHIFT) | 84338df6492SMark Einon (adapter->addr[0] << ET_MAC_STATION_ADDR2_OC1_SHIFT); 84438df6492SMark Einon station1 = (adapter->addr[5] << ET_MAC_STATION_ADDR1_OC6_SHIFT) | 84538df6492SMark Einon (adapter->addr[4] << ET_MAC_STATION_ADDR1_OC5_SHIFT) | 84638df6492SMark Einon (adapter->addr[3] << ET_MAC_STATION_ADDR1_OC4_SHIFT) | 84738df6492SMark Einon adapter->addr[2]; 84838df6492SMark Einon writel(station1, ¯egs->station_addr_1); 84938df6492SMark Einon writel(station2, ¯egs->station_addr_2); 85038df6492SMark Einon 85138df6492SMark Einon /* Max ethernet packet in bytes that will be passed by the mac without 85238df6492SMark Einon * being truncated. Allow the MAC to pass 4 more than our max packet 85338df6492SMark Einon * size. This is 4 for the Ethernet CRC. 85438df6492SMark Einon * 85538df6492SMark Einon * Packets larger than (registry_jumbo_packet) that do not contain a 85638df6492SMark Einon * VLAN ID will be dropped by the Rx function. 85738df6492SMark Einon */ 85838df6492SMark Einon writel(adapter->registry_jumbo_packet + 4, ¯egs->max_fm_len); 85938df6492SMark Einon 86038df6492SMark Einon /* clear out MAC config reset */ 86138df6492SMark Einon writel(0, ¯egs->cfg1); 86238df6492SMark Einon } 86338df6492SMark Einon 86438df6492SMark Einon static void et1310_config_mac_regs2(struct et131x_adapter *adapter) 86538df6492SMark Einon { 86638df6492SMark Einon int32_t delay = 0; 86738df6492SMark Einon struct mac_regs __iomem *mac = &adapter->regs->mac; 868a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 86938df6492SMark Einon u32 cfg1; 87038df6492SMark Einon u32 cfg2; 87138df6492SMark Einon u32 ifctrl; 87238df6492SMark Einon u32 ctl; 87338df6492SMark Einon 87438df6492SMark Einon ctl = readl(&adapter->regs->txmac.ctl); 87538df6492SMark Einon cfg1 = readl(&mac->cfg1); 87638df6492SMark Einon cfg2 = readl(&mac->cfg2); 87738df6492SMark Einon ifctrl = readl(&mac->if_ctrl); 87838df6492SMark Einon 87938df6492SMark Einon /* Set up the if mode bits */ 88038df6492SMark Einon cfg2 &= ~ET_MAC_CFG2_IFMODE_MASK; 88138df6492SMark Einon if (phydev->speed == SPEED_1000) { 88238df6492SMark Einon cfg2 |= ET_MAC_CFG2_IFMODE_1000; 88338df6492SMark Einon ifctrl &= ~ET_MAC_IFCTRL_PHYMODE; 88438df6492SMark Einon } else { 88538df6492SMark Einon cfg2 |= ET_MAC_CFG2_IFMODE_100; 88638df6492SMark Einon ifctrl |= ET_MAC_IFCTRL_PHYMODE; 88738df6492SMark Einon } 88838df6492SMark Einon 88938df6492SMark Einon cfg1 |= ET_MAC_CFG1_RX_ENABLE | ET_MAC_CFG1_TX_ENABLE | 89038df6492SMark Einon ET_MAC_CFG1_TX_FLOW; 89138df6492SMark Einon 89238df6492SMark Einon cfg1 &= ~(ET_MAC_CFG1_LOOPBACK | ET_MAC_CFG1_RX_FLOW); 89338df6492SMark Einon if (adapter->flow == FLOW_RXONLY || adapter->flow == FLOW_BOTH) 89438df6492SMark Einon cfg1 |= ET_MAC_CFG1_RX_FLOW; 89538df6492SMark Einon writel(cfg1, &mac->cfg1); 89638df6492SMark Einon 89738df6492SMark Einon /* Now we need to initialize the MAC Configuration 2 register */ 89838df6492SMark Einon /* preamble 7, check length, huge frame off, pad crc, crc enable 89938df6492SMark Einon * full duplex off 90038df6492SMark Einon */ 90138df6492SMark Einon cfg2 |= 0x7 << ET_MAC_CFG2_PREAMBLE_SHIFT; 90238df6492SMark Einon cfg2 |= ET_MAC_CFG2_IFMODE_LEN_CHECK; 90338df6492SMark Einon cfg2 |= ET_MAC_CFG2_IFMODE_PAD_CRC; 90438df6492SMark Einon cfg2 |= ET_MAC_CFG2_IFMODE_CRC_ENABLE; 90538df6492SMark Einon cfg2 &= ~ET_MAC_CFG2_IFMODE_HUGE_FRAME; 90638df6492SMark Einon cfg2 &= ~ET_MAC_CFG2_IFMODE_FULL_DPLX; 90738df6492SMark Einon 90838df6492SMark Einon if (phydev->duplex == DUPLEX_FULL) 90938df6492SMark Einon cfg2 |= ET_MAC_CFG2_IFMODE_FULL_DPLX; 91038df6492SMark Einon 91138df6492SMark Einon ifctrl &= ~ET_MAC_IFCTRL_GHDMODE; 91238df6492SMark Einon if (phydev->duplex == DUPLEX_HALF) 91338df6492SMark Einon ifctrl |= ET_MAC_IFCTRL_GHDMODE; 91438df6492SMark Einon 91538df6492SMark Einon writel(ifctrl, &mac->if_ctrl); 91638df6492SMark Einon writel(cfg2, &mac->cfg2); 91738df6492SMark Einon 91838df6492SMark Einon do { 91938df6492SMark Einon udelay(10); 92038df6492SMark Einon delay++; 92138df6492SMark Einon cfg1 = readl(&mac->cfg1); 92238df6492SMark Einon } while ((cfg1 & ET_MAC_CFG1_WAIT) != ET_MAC_CFG1_WAIT && delay < 100); 92338df6492SMark Einon 92438df6492SMark Einon if (delay == 100) { 92538df6492SMark Einon dev_warn(&adapter->pdev->dev, 92638df6492SMark Einon "Syncd bits did not respond correctly cfg1 word 0x%08x\n", 92738df6492SMark Einon cfg1); 92838df6492SMark Einon } 92938df6492SMark Einon 93038df6492SMark Einon ctl |= ET_TX_CTRL_TXMAC_ENABLE | ET_TX_CTRL_FC_DISABLE; 93138df6492SMark Einon writel(ctl, &adapter->regs->txmac.ctl); 93238df6492SMark Einon 93338df6492SMark Einon if (adapter->flags & FMP_ADAPTER_LOWER_POWER) { 93438df6492SMark Einon et131x_rx_dma_enable(adapter); 93538df6492SMark Einon et131x_tx_dma_enable(adapter); 93638df6492SMark Einon } 93738df6492SMark Einon } 93838df6492SMark Einon 93938df6492SMark Einon static int et1310_in_phy_coma(struct et131x_adapter *adapter) 94038df6492SMark Einon { 94138df6492SMark Einon u32 pmcsr = readl(&adapter->regs->global.pm_csr); 94238df6492SMark Einon 94338df6492SMark Einon return ET_PM_PHY_SW_COMA & pmcsr ? 1 : 0; 94438df6492SMark Einon } 94538df6492SMark Einon 94638df6492SMark Einon static void et1310_setup_device_for_multicast(struct et131x_adapter *adapter) 94738df6492SMark Einon { 94838df6492SMark Einon struct rxmac_regs __iomem *rxmac = &adapter->regs->rxmac; 94938df6492SMark Einon u32 hash1 = 0; 95038df6492SMark Einon u32 hash2 = 0; 95138df6492SMark Einon u32 hash3 = 0; 95238df6492SMark Einon u32 hash4 = 0; 95338df6492SMark Einon u32 pm_csr; 95438df6492SMark Einon 95538df6492SMark Einon /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision 95638df6492SMark Einon * the multi-cast LIST. If it is NOT specified, (and "ALL" is not 95738df6492SMark Einon * specified) then we should pass NO multi-cast addresses to the 95838df6492SMark Einon * driver. 95938df6492SMark Einon */ 96038df6492SMark Einon if (adapter->packet_filter & ET131X_PACKET_TYPE_MULTICAST) { 96138df6492SMark Einon int i; 96238df6492SMark Einon 96338df6492SMark Einon /* Loop through our multicast array and set up the device */ 96438df6492SMark Einon for (i = 0; i < adapter->multicast_addr_count; i++) { 96538df6492SMark Einon u32 result; 96638df6492SMark Einon 96738df6492SMark Einon result = ether_crc(6, adapter->multicast_list[i]); 96838df6492SMark Einon 96938df6492SMark Einon result = (result & 0x3F800000) >> 23; 97038df6492SMark Einon 97138df6492SMark Einon if (result < 32) { 97238df6492SMark Einon hash1 |= (1 << result); 97338df6492SMark Einon } else if ((31 < result) && (result < 64)) { 97438df6492SMark Einon result -= 32; 97538df6492SMark Einon hash2 |= (1 << result); 97638df6492SMark Einon } else if ((63 < result) && (result < 96)) { 97738df6492SMark Einon result -= 64; 97838df6492SMark Einon hash3 |= (1 << result); 97938df6492SMark Einon } else { 98038df6492SMark Einon result -= 96; 98138df6492SMark Einon hash4 |= (1 << result); 98238df6492SMark Einon } 98338df6492SMark Einon } 98438df6492SMark Einon } 98538df6492SMark Einon 98638df6492SMark Einon /* Write out the new hash to the device */ 98738df6492SMark Einon pm_csr = readl(&adapter->regs->global.pm_csr); 98838df6492SMark Einon if (!et1310_in_phy_coma(adapter)) { 98938df6492SMark Einon writel(hash1, &rxmac->multi_hash1); 99038df6492SMark Einon writel(hash2, &rxmac->multi_hash2); 99138df6492SMark Einon writel(hash3, &rxmac->multi_hash3); 99238df6492SMark Einon writel(hash4, &rxmac->multi_hash4); 99338df6492SMark Einon } 99438df6492SMark Einon } 99538df6492SMark Einon 99638df6492SMark Einon static void et1310_setup_device_for_unicast(struct et131x_adapter *adapter) 99738df6492SMark Einon { 99838df6492SMark Einon struct rxmac_regs __iomem *rxmac = &adapter->regs->rxmac; 99938df6492SMark Einon u32 uni_pf1; 100038df6492SMark Einon u32 uni_pf2; 100138df6492SMark Einon u32 uni_pf3; 100238df6492SMark Einon u32 pm_csr; 100338df6492SMark Einon 100438df6492SMark Einon /* Set up unicast packet filter reg 3 to be the first two octets of 100538df6492SMark Einon * the MAC address for both address 100638df6492SMark Einon * 100738df6492SMark Einon * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the 100838df6492SMark Einon * MAC address for second address 100938df6492SMark Einon * 101038df6492SMark Einon * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the 101138df6492SMark Einon * MAC address for first address 101238df6492SMark Einon */ 101338df6492SMark Einon uni_pf3 = (adapter->addr[0] << ET_RX_UNI_PF_ADDR2_1_SHIFT) | 101438df6492SMark Einon (adapter->addr[1] << ET_RX_UNI_PF_ADDR2_2_SHIFT) | 101538df6492SMark Einon (adapter->addr[0] << ET_RX_UNI_PF_ADDR1_1_SHIFT) | 101638df6492SMark Einon adapter->addr[1]; 101738df6492SMark Einon 101838df6492SMark Einon uni_pf2 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR2_3_SHIFT) | 101938df6492SMark Einon (adapter->addr[3] << ET_RX_UNI_PF_ADDR2_4_SHIFT) | 102038df6492SMark Einon (adapter->addr[4] << ET_RX_UNI_PF_ADDR2_5_SHIFT) | 102138df6492SMark Einon adapter->addr[5]; 102238df6492SMark Einon 102338df6492SMark Einon uni_pf1 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR1_3_SHIFT) | 102438df6492SMark Einon (adapter->addr[3] << ET_RX_UNI_PF_ADDR1_4_SHIFT) | 102538df6492SMark Einon (adapter->addr[4] << ET_RX_UNI_PF_ADDR1_5_SHIFT) | 102638df6492SMark Einon adapter->addr[5]; 102738df6492SMark Einon 102838df6492SMark Einon pm_csr = readl(&adapter->regs->global.pm_csr); 102938df6492SMark Einon if (!et1310_in_phy_coma(adapter)) { 103038df6492SMark Einon writel(uni_pf1, &rxmac->uni_pf_addr1); 103138df6492SMark Einon writel(uni_pf2, &rxmac->uni_pf_addr2); 103238df6492SMark Einon writel(uni_pf3, &rxmac->uni_pf_addr3); 103338df6492SMark Einon } 103438df6492SMark Einon } 103538df6492SMark Einon 103638df6492SMark Einon static void et1310_config_rxmac_regs(struct et131x_adapter *adapter) 103738df6492SMark Einon { 103838df6492SMark Einon struct rxmac_regs __iomem *rxmac = &adapter->regs->rxmac; 1039a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 104038df6492SMark Einon u32 sa_lo; 104138df6492SMark Einon u32 sa_hi = 0; 104238df6492SMark Einon u32 pf_ctrl = 0; 104338df6492SMark Einon u32 __iomem *wolw; 104438df6492SMark Einon 104538df6492SMark Einon /* Disable the MAC while it is being configured (also disable WOL) */ 104638df6492SMark Einon writel(0x8, &rxmac->ctrl); 104738df6492SMark Einon 104838df6492SMark Einon /* Initialize WOL to disabled. */ 104938df6492SMark Einon writel(0, &rxmac->crc0); 105038df6492SMark Einon writel(0, &rxmac->crc12); 105138df6492SMark Einon writel(0, &rxmac->crc34); 105238df6492SMark Einon 105338df6492SMark Einon /* We need to set the WOL mask0 - mask4 next. We initialize it to 105438df6492SMark Einon * its default Values of 0x00000000 because there are not WOL masks 105538df6492SMark Einon * as of this time. 105638df6492SMark Einon */ 105738df6492SMark Einon for (wolw = &rxmac->mask0_word0; wolw <= &rxmac->mask4_word3; wolw++) 105838df6492SMark Einon writel(0, wolw); 105938df6492SMark Einon 106038df6492SMark Einon /* Lets setup the WOL Source Address */ 106138df6492SMark Einon sa_lo = (adapter->addr[2] << ET_RX_WOL_LO_SA3_SHIFT) | 106238df6492SMark Einon (adapter->addr[3] << ET_RX_WOL_LO_SA4_SHIFT) | 106338df6492SMark Einon (adapter->addr[4] << ET_RX_WOL_LO_SA5_SHIFT) | 106438df6492SMark Einon adapter->addr[5]; 106538df6492SMark Einon writel(sa_lo, &rxmac->sa_lo); 106638df6492SMark Einon 106738df6492SMark Einon sa_hi = (u32)(adapter->addr[0] << ET_RX_WOL_HI_SA1_SHIFT) | 106838df6492SMark Einon adapter->addr[1]; 106938df6492SMark Einon writel(sa_hi, &rxmac->sa_hi); 107038df6492SMark Einon 107138df6492SMark Einon /* Disable all Packet Filtering */ 107238df6492SMark Einon writel(0, &rxmac->pf_ctrl); 107338df6492SMark Einon 107438df6492SMark Einon /* Let's initialize the Unicast Packet filtering address */ 107538df6492SMark Einon if (adapter->packet_filter & ET131X_PACKET_TYPE_DIRECTED) { 107638df6492SMark Einon et1310_setup_device_for_unicast(adapter); 107738df6492SMark Einon pf_ctrl |= ET_RX_PFCTRL_UNICST_FILTER_ENABLE; 107838df6492SMark Einon } else { 107938df6492SMark Einon writel(0, &rxmac->uni_pf_addr1); 108038df6492SMark Einon writel(0, &rxmac->uni_pf_addr2); 108138df6492SMark Einon writel(0, &rxmac->uni_pf_addr3); 108238df6492SMark Einon } 108338df6492SMark Einon 108438df6492SMark Einon /* Let's initialize the Multicast hash */ 108538df6492SMark Einon if (!(adapter->packet_filter & ET131X_PACKET_TYPE_ALL_MULTICAST)) { 108638df6492SMark Einon pf_ctrl |= ET_RX_PFCTRL_MLTCST_FILTER_ENABLE; 108738df6492SMark Einon et1310_setup_device_for_multicast(adapter); 108838df6492SMark Einon } 108938df6492SMark Einon 109038df6492SMark Einon /* Runt packet filtering. Didn't work in version A silicon. */ 109138df6492SMark Einon pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << ET_RX_PFCTRL_MIN_PKT_SZ_SHIFT; 109238df6492SMark Einon pf_ctrl |= ET_RX_PFCTRL_FRAG_FILTER_ENABLE; 109338df6492SMark Einon 109438df6492SMark Einon if (adapter->registry_jumbo_packet > 8192) 109538df6492SMark Einon /* In order to transmit jumbo packets greater than 8k, the 109638df6492SMark Einon * FIFO between RxMAC and RxDMA needs to be reduced in size 109738df6492SMark Einon * to (16k - Jumbo packet size). In order to implement this, 109838df6492SMark Einon * we must use "cut through" mode in the RxMAC, which chops 109938df6492SMark Einon * packets down into segments which are (max_size * 16). In 110038df6492SMark Einon * this case we selected 256 bytes, since this is the size of 110138df6492SMark Einon * the PCI-Express TLP's that the 1310 uses. 110238df6492SMark Einon * 110338df6492SMark Einon * seg_en on, fc_en off, size 0x10 110438df6492SMark Einon */ 110538df6492SMark Einon writel(0x41, &rxmac->mcif_ctrl_max_seg); 110638df6492SMark Einon else 110738df6492SMark Einon writel(0, &rxmac->mcif_ctrl_max_seg); 110838df6492SMark Einon 110938df6492SMark Einon writel(0, &rxmac->mcif_water_mark); 111038df6492SMark Einon writel(0, &rxmac->mif_ctrl); 111138df6492SMark Einon writel(0, &rxmac->space_avail); 111238df6492SMark Einon 111338df6492SMark Einon /* Initialize the the mif_ctrl register 111438df6492SMark Einon * bit 3: Receive code error. One or more nibbles were signaled as 111538df6492SMark Einon * errors during the reception of the packet. Clear this 111638df6492SMark Einon * bit in Gigabit, set it in 100Mbit. This was derived 111738df6492SMark Einon * experimentally at UNH. 111838df6492SMark Einon * bit 4: Receive CRC error. The packet's CRC did not match the 111938df6492SMark Einon * internally generated CRC. 112038df6492SMark Einon * bit 5: Receive length check error. Indicates that frame length 112138df6492SMark Einon * field value in the packet does not match the actual data 112238df6492SMark Einon * byte length and is not a type field. 112338df6492SMark Einon * bit 16: Receive frame truncated. 112438df6492SMark Einon * bit 17: Drop packet enable 112538df6492SMark Einon */ 112638df6492SMark Einon if (phydev && phydev->speed == SPEED_100) 112738df6492SMark Einon writel(0x30038, &rxmac->mif_ctrl); 112838df6492SMark Einon else 112938df6492SMark Einon writel(0x30030, &rxmac->mif_ctrl); 113038df6492SMark Einon 113138df6492SMark Einon /* Finally we initialize RxMac to be enabled & WOL disabled. Packet 113238df6492SMark Einon * filter is always enabled since it is where the runt packets are 113338df6492SMark Einon * supposed to be dropped. For version A silicon, runt packet 113438df6492SMark Einon * dropping doesn't work, so it is disabled in the pf_ctrl register, 113538df6492SMark Einon * but we still leave the packet filter on. 113638df6492SMark Einon */ 113738df6492SMark Einon writel(pf_ctrl, &rxmac->pf_ctrl); 113838df6492SMark Einon writel(ET_RX_CTRL_RXMAC_ENABLE | ET_RX_CTRL_WOL_DISABLE, &rxmac->ctrl); 113938df6492SMark Einon } 114038df6492SMark Einon 114138df6492SMark Einon static void et1310_config_txmac_regs(struct et131x_adapter *adapter) 114238df6492SMark Einon { 114338df6492SMark Einon struct txmac_regs __iomem *txmac = &adapter->regs->txmac; 114438df6492SMark Einon 114538df6492SMark Einon /* We need to update the Control Frame Parameters 114638df6492SMark Einon * cfpt - control frame pause timer set to 64 (0x40) 114738df6492SMark Einon * cfep - control frame extended pause timer set to 0x0 114838df6492SMark Einon */ 114938df6492SMark Einon if (adapter->flow == FLOW_NONE) 115038df6492SMark Einon writel(0, &txmac->cf_param); 115138df6492SMark Einon else 115238df6492SMark Einon writel(0x40, &txmac->cf_param); 115338df6492SMark Einon } 115438df6492SMark Einon 115538df6492SMark Einon static void et1310_config_macstat_regs(struct et131x_adapter *adapter) 115638df6492SMark Einon { 115738df6492SMark Einon struct macstat_regs __iomem *macstat = &adapter->regs->macstat; 115838df6492SMark Einon u32 __iomem *reg; 115938df6492SMark Einon 116038df6492SMark Einon /* initialize all the macstat registers to zero on the device */ 116138df6492SMark Einon for (reg = &macstat->txrx_0_64_byte_frames; 116238df6492SMark Einon reg <= &macstat->carry_reg2; reg++) 116338df6492SMark Einon writel(0, reg); 116438df6492SMark Einon 116538df6492SMark Einon /* Unmask any counters that we want to track the overflow of. 116638df6492SMark Einon * Initially this will be all counters. It may become clear later 116738df6492SMark Einon * that we do not need to track all counters. 116838df6492SMark Einon */ 116938df6492SMark Einon writel(0xFFFFBE32, &macstat->carry_reg1_mask); 117038df6492SMark Einon writel(0xFFFE7E8B, &macstat->carry_reg2_mask); 117138df6492SMark Einon } 117238df6492SMark Einon 117338df6492SMark Einon static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr, 117438df6492SMark Einon u8 reg, u16 *value) 117538df6492SMark Einon { 117638df6492SMark Einon struct mac_regs __iomem *mac = &adapter->regs->mac; 117738df6492SMark Einon int status = 0; 117838df6492SMark Einon u32 delay = 0; 117938df6492SMark Einon u32 mii_addr; 118038df6492SMark Einon u32 mii_cmd; 118138df6492SMark Einon u32 mii_indicator; 118238df6492SMark Einon 118338df6492SMark Einon /* Save a local copy of the registers we are dealing with so we can 118438df6492SMark Einon * set them back 118538df6492SMark Einon */ 118638df6492SMark Einon mii_addr = readl(&mac->mii_mgmt_addr); 118738df6492SMark Einon mii_cmd = readl(&mac->mii_mgmt_cmd); 118838df6492SMark Einon 118938df6492SMark Einon /* Stop the current operation */ 119038df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 119138df6492SMark Einon 119238df6492SMark Einon /* Set up the register we need to read from on the correct PHY */ 119338df6492SMark Einon writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr); 119438df6492SMark Einon 119538df6492SMark Einon writel(0x1, &mac->mii_mgmt_cmd); 119638df6492SMark Einon 119738df6492SMark Einon do { 119838df6492SMark Einon udelay(50); 119938df6492SMark Einon delay++; 120038df6492SMark Einon mii_indicator = readl(&mac->mii_mgmt_indicator); 120138df6492SMark Einon } while ((mii_indicator & ET_MAC_MGMT_WAIT) && delay < 50); 120238df6492SMark Einon 120338df6492SMark Einon /* If we hit the max delay, we could not read the register */ 120438df6492SMark Einon if (delay == 50) { 120538df6492SMark Einon dev_warn(&adapter->pdev->dev, 120638df6492SMark Einon "reg 0x%08x could not be read\n", reg); 120738df6492SMark Einon dev_warn(&adapter->pdev->dev, "status is 0x%08x\n", 120838df6492SMark Einon mii_indicator); 120938df6492SMark Einon 121038df6492SMark Einon status = -EIO; 121138df6492SMark Einon goto out; 121238df6492SMark Einon } 121338df6492SMark Einon 121438df6492SMark Einon /* If we hit here we were able to read the register and we need to 121538df6492SMark Einon * return the value to the caller 121638df6492SMark Einon */ 121738df6492SMark Einon *value = readl(&mac->mii_mgmt_stat) & ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK; 121838df6492SMark Einon 121938df6492SMark Einon out: 122038df6492SMark Einon /* Stop the read operation */ 122138df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 122238df6492SMark Einon 122338df6492SMark Einon /* set the registers we touched back to the state at which we entered 122438df6492SMark Einon * this function 122538df6492SMark Einon */ 122638df6492SMark Einon writel(mii_addr, &mac->mii_mgmt_addr); 122738df6492SMark Einon writel(mii_cmd, &mac->mii_mgmt_cmd); 122838df6492SMark Einon 122938df6492SMark Einon return status; 123038df6492SMark Einon } 123138df6492SMark Einon 123238df6492SMark Einon static int et131x_mii_read(struct et131x_adapter *adapter, u8 reg, u16 *value) 123338df6492SMark Einon { 1234a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 123538df6492SMark Einon 123638df6492SMark Einon if (!phydev) 123738df6492SMark Einon return -EIO; 123838df6492SMark Einon 1239e5a03bfdSAndrew Lunn return et131x_phy_mii_read(adapter, phydev->mdio.addr, reg, value); 124038df6492SMark Einon } 124138df6492SMark Einon 124238df6492SMark Einon static int et131x_mii_write(struct et131x_adapter *adapter, u8 addr, u8 reg, 124338df6492SMark Einon u16 value) 124438df6492SMark Einon { 124538df6492SMark Einon struct mac_regs __iomem *mac = &adapter->regs->mac; 124638df6492SMark Einon int status = 0; 124738df6492SMark Einon u32 delay = 0; 124838df6492SMark Einon u32 mii_addr; 124938df6492SMark Einon u32 mii_cmd; 125038df6492SMark Einon u32 mii_indicator; 125138df6492SMark Einon 125238df6492SMark Einon /* Save a local copy of the registers we are dealing with so we can 125338df6492SMark Einon * set them back 125438df6492SMark Einon */ 125538df6492SMark Einon mii_addr = readl(&mac->mii_mgmt_addr); 125638df6492SMark Einon mii_cmd = readl(&mac->mii_mgmt_cmd); 125738df6492SMark Einon 125838df6492SMark Einon /* Stop the current operation */ 125938df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 126038df6492SMark Einon 126138df6492SMark Einon /* Set up the register we need to write to on the correct PHY */ 126238df6492SMark Einon writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr); 126338df6492SMark Einon 126438df6492SMark Einon /* Add the value to write to the registers to the mac */ 126538df6492SMark Einon writel(value, &mac->mii_mgmt_ctrl); 126638df6492SMark Einon 126738df6492SMark Einon do { 126838df6492SMark Einon udelay(50); 126938df6492SMark Einon delay++; 127038df6492SMark Einon mii_indicator = readl(&mac->mii_mgmt_indicator); 127138df6492SMark Einon } while ((mii_indicator & ET_MAC_MGMT_BUSY) && delay < 100); 127238df6492SMark Einon 127338df6492SMark Einon /* If we hit the max delay, we could not write the register */ 127438df6492SMark Einon if (delay == 100) { 127538df6492SMark Einon u16 tmp; 127638df6492SMark Einon 127738df6492SMark Einon dev_warn(&adapter->pdev->dev, 127838df6492SMark Einon "reg 0x%08x could not be written", reg); 127938df6492SMark Einon dev_warn(&adapter->pdev->dev, "status is 0x%08x\n", 128038df6492SMark Einon mii_indicator); 128138df6492SMark Einon dev_warn(&adapter->pdev->dev, "command is 0x%08x\n", 128238df6492SMark Einon readl(&mac->mii_mgmt_cmd)); 128338df6492SMark Einon 128438df6492SMark Einon et131x_mii_read(adapter, reg, &tmp); 128538df6492SMark Einon 128638df6492SMark Einon status = -EIO; 128738df6492SMark Einon } 128838df6492SMark Einon /* Stop the write operation */ 128938df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 129038df6492SMark Einon 129138df6492SMark Einon /* set the registers we touched back to the state at which we entered 129238df6492SMark Einon * this function 129338df6492SMark Einon */ 129438df6492SMark Einon writel(mii_addr, &mac->mii_mgmt_addr); 129538df6492SMark Einon writel(mii_cmd, &mac->mii_mgmt_cmd); 129638df6492SMark Einon 129738df6492SMark Einon return status; 129838df6492SMark Einon } 129938df6492SMark Einon 130038df6492SMark Einon static void et1310_phy_read_mii_bit(struct et131x_adapter *adapter, 130138df6492SMark Einon u16 regnum, 130238df6492SMark Einon u16 bitnum, 130338df6492SMark Einon u8 *value) 130438df6492SMark Einon { 130538df6492SMark Einon u16 reg; 130638df6492SMark Einon u16 mask = 1 << bitnum; 130738df6492SMark Einon 130838df6492SMark Einon et131x_mii_read(adapter, regnum, ®); 130938df6492SMark Einon 131038df6492SMark Einon *value = (reg & mask) >> bitnum; 131138df6492SMark Einon } 131238df6492SMark Einon 131338df6492SMark Einon static void et1310_config_flow_control(struct et131x_adapter *adapter) 131438df6492SMark Einon { 1315a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 131638df6492SMark Einon 131738df6492SMark Einon if (phydev->duplex == DUPLEX_HALF) { 131838df6492SMark Einon adapter->flow = FLOW_NONE; 131938df6492SMark Einon } else { 132038df6492SMark Einon char remote_pause, remote_async_pause; 132138df6492SMark Einon 132238df6492SMark Einon et1310_phy_read_mii_bit(adapter, 5, 10, &remote_pause); 132338df6492SMark Einon et1310_phy_read_mii_bit(adapter, 5, 11, &remote_async_pause); 132438df6492SMark Einon 132538df6492SMark Einon if (remote_pause && remote_async_pause) { 132638df6492SMark Einon adapter->flow = adapter->wanted_flow; 132738df6492SMark Einon } else if (remote_pause && !remote_async_pause) { 132838df6492SMark Einon if (adapter->wanted_flow == FLOW_BOTH) 132938df6492SMark Einon adapter->flow = FLOW_BOTH; 133038df6492SMark Einon else 133138df6492SMark Einon adapter->flow = FLOW_NONE; 133238df6492SMark Einon } else if (!remote_pause && !remote_async_pause) { 133338df6492SMark Einon adapter->flow = FLOW_NONE; 133438df6492SMark Einon } else { 133538df6492SMark Einon if (adapter->wanted_flow == FLOW_BOTH) 133638df6492SMark Einon adapter->flow = FLOW_RXONLY; 133738df6492SMark Einon else 133838df6492SMark Einon adapter->flow = FLOW_NONE; 133938df6492SMark Einon } 134038df6492SMark Einon } 134138df6492SMark Einon } 134238df6492SMark Einon 134338df6492SMark Einon /* et1310_update_macstat_host_counters - Update local copy of the statistics */ 134438df6492SMark Einon static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter) 134538df6492SMark Einon { 134638df6492SMark Einon struct ce_stats *stats = &adapter->stats; 134738df6492SMark Einon struct macstat_regs __iomem *macstat = 134838df6492SMark Einon &adapter->regs->macstat; 134938df6492SMark Einon 135038df6492SMark Einon stats->tx_collisions += readl(&macstat->tx_total_collisions); 135138df6492SMark Einon stats->tx_first_collisions += readl(&macstat->tx_single_collisions); 135238df6492SMark Einon stats->tx_deferred += readl(&macstat->tx_deferred); 135338df6492SMark Einon stats->tx_excessive_collisions += 135438df6492SMark Einon readl(&macstat->tx_multiple_collisions); 135538df6492SMark Einon stats->tx_late_collisions += readl(&macstat->tx_late_collisions); 135638df6492SMark Einon stats->tx_underflows += readl(&macstat->tx_undersize_frames); 135738df6492SMark Einon stats->tx_max_pkt_errs += readl(&macstat->tx_oversize_frames); 135838df6492SMark Einon 135938df6492SMark Einon stats->rx_align_errs += readl(&macstat->rx_align_errs); 136038df6492SMark Einon stats->rx_crc_errs += readl(&macstat->rx_code_errs); 136138df6492SMark Einon stats->rcvd_pkts_dropped += readl(&macstat->rx_drops); 136238df6492SMark Einon stats->rx_overflows += readl(&macstat->rx_oversize_packets); 136338df6492SMark Einon stats->rx_code_violations += readl(&macstat->rx_fcs_errs); 136438df6492SMark Einon stats->rx_length_errs += readl(&macstat->rx_frame_len_errs); 136538df6492SMark Einon stats->rx_other_errs += readl(&macstat->rx_fragment_packets); 136638df6492SMark Einon } 136738df6492SMark Einon 136838df6492SMark Einon /* et1310_handle_macstat_interrupt 136938df6492SMark Einon * 137038df6492SMark Einon * One of the MACSTAT counters has wrapped. Update the local copy of 137138df6492SMark Einon * the statistics held in the adapter structure, checking the "wrap" 137238df6492SMark Einon * bit for each counter. 137338df6492SMark Einon */ 137438df6492SMark Einon static void et1310_handle_macstat_interrupt(struct et131x_adapter *adapter) 137538df6492SMark Einon { 137638df6492SMark Einon u32 carry_reg1; 137738df6492SMark Einon u32 carry_reg2; 137838df6492SMark Einon 137938df6492SMark Einon /* Read the interrupt bits from the register(s). These are Clear On 138038df6492SMark Einon * Write. 138138df6492SMark Einon */ 138238df6492SMark Einon carry_reg1 = readl(&adapter->regs->macstat.carry_reg1); 138338df6492SMark Einon carry_reg2 = readl(&adapter->regs->macstat.carry_reg2); 138438df6492SMark Einon 138538df6492SMark Einon writel(carry_reg1, &adapter->regs->macstat.carry_reg1); 138638df6492SMark Einon writel(carry_reg2, &adapter->regs->macstat.carry_reg2); 138738df6492SMark Einon 138838df6492SMark Einon /* We need to do update the host copy of all the MAC_STAT counters. 138938df6492SMark Einon * For each counter, check it's overflow bit. If the overflow bit is 139038df6492SMark Einon * set, then increment the host version of the count by one complete 139138df6492SMark Einon * revolution of the counter. This routine is called when the counter 139238df6492SMark Einon * block indicates that one of the counters has wrapped. 139338df6492SMark Einon */ 139438df6492SMark Einon if (carry_reg1 & (1 << 14)) 139538df6492SMark Einon adapter->stats.rx_code_violations += COUNTER_WRAP_16_BIT; 139638df6492SMark Einon if (carry_reg1 & (1 << 8)) 139738df6492SMark Einon adapter->stats.rx_align_errs += COUNTER_WRAP_12_BIT; 139838df6492SMark Einon if (carry_reg1 & (1 << 7)) 139938df6492SMark Einon adapter->stats.rx_length_errs += COUNTER_WRAP_16_BIT; 140038df6492SMark Einon if (carry_reg1 & (1 << 2)) 140138df6492SMark Einon adapter->stats.rx_other_errs += COUNTER_WRAP_16_BIT; 140238df6492SMark Einon if (carry_reg1 & (1 << 6)) 140338df6492SMark Einon adapter->stats.rx_crc_errs += COUNTER_WRAP_16_BIT; 140438df6492SMark Einon if (carry_reg1 & (1 << 3)) 140538df6492SMark Einon adapter->stats.rx_overflows += COUNTER_WRAP_16_BIT; 140638df6492SMark Einon if (carry_reg1 & (1 << 0)) 140738df6492SMark Einon adapter->stats.rcvd_pkts_dropped += COUNTER_WRAP_16_BIT; 140838df6492SMark Einon if (carry_reg2 & (1 << 16)) 140938df6492SMark Einon adapter->stats.tx_max_pkt_errs += COUNTER_WRAP_12_BIT; 141038df6492SMark Einon if (carry_reg2 & (1 << 15)) 141138df6492SMark Einon adapter->stats.tx_underflows += COUNTER_WRAP_12_BIT; 141238df6492SMark Einon if (carry_reg2 & (1 << 6)) 141338df6492SMark Einon adapter->stats.tx_first_collisions += COUNTER_WRAP_12_BIT; 141438df6492SMark Einon if (carry_reg2 & (1 << 8)) 141538df6492SMark Einon adapter->stats.tx_deferred += COUNTER_WRAP_12_BIT; 141638df6492SMark Einon if (carry_reg2 & (1 << 5)) 141738df6492SMark Einon adapter->stats.tx_excessive_collisions += COUNTER_WRAP_12_BIT; 141838df6492SMark Einon if (carry_reg2 & (1 << 4)) 141938df6492SMark Einon adapter->stats.tx_late_collisions += COUNTER_WRAP_12_BIT; 142038df6492SMark Einon if (carry_reg2 & (1 << 2)) 142138df6492SMark Einon adapter->stats.tx_collisions += COUNTER_WRAP_12_BIT; 142238df6492SMark Einon } 142338df6492SMark Einon 142438df6492SMark Einon static int et131x_mdio_read(struct mii_bus *bus, int phy_addr, int reg) 142538df6492SMark Einon { 142638df6492SMark Einon struct net_device *netdev = bus->priv; 142738df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 142838df6492SMark Einon u16 value; 142938df6492SMark Einon int ret; 143038df6492SMark Einon 143138df6492SMark Einon ret = et131x_phy_mii_read(adapter, phy_addr, reg, &value); 143238df6492SMark Einon 143338df6492SMark Einon if (ret < 0) 143438df6492SMark Einon return ret; 143538df6492SMark Einon 143638df6492SMark Einon return value; 143738df6492SMark Einon } 143838df6492SMark Einon 143938df6492SMark Einon static int et131x_mdio_write(struct mii_bus *bus, int phy_addr, 144038df6492SMark Einon int reg, u16 value) 144138df6492SMark Einon { 144238df6492SMark Einon struct net_device *netdev = bus->priv; 144338df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 144438df6492SMark Einon 144538df6492SMark Einon return et131x_mii_write(adapter, phy_addr, reg, value); 144638df6492SMark Einon } 144738df6492SMark Einon 144838df6492SMark Einon /* et1310_phy_power_switch - PHY power control 144938df6492SMark Einon * @adapter: device to control 145038df6492SMark Einon * @down: true for off/false for back on 145138df6492SMark Einon * 145238df6492SMark Einon * one hundred, ten, one thousand megs 145338df6492SMark Einon * How would you like to have your LAN accessed 145438df6492SMark Einon * Can't you see that this code processed 145538df6492SMark Einon * Phy power, phy power.. 145638df6492SMark Einon */ 145738df6492SMark Einon static void et1310_phy_power_switch(struct et131x_adapter *adapter, bool down) 145838df6492SMark Einon { 145938df6492SMark Einon u16 data; 1460a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 146138df6492SMark Einon 146238df6492SMark Einon et131x_mii_read(adapter, MII_BMCR, &data); 146338df6492SMark Einon data &= ~BMCR_PDOWN; 146438df6492SMark Einon if (down) 146538df6492SMark Einon data |= BMCR_PDOWN; 1466e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, MII_BMCR, data); 146738df6492SMark Einon } 146838df6492SMark Einon 146938df6492SMark Einon /* et131x_xcvr_init - Init the phy if we are setting it into force mode */ 147038df6492SMark Einon static void et131x_xcvr_init(struct et131x_adapter *adapter) 147138df6492SMark Einon { 147238df6492SMark Einon u16 lcr2; 1473a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 147438df6492SMark Einon 147538df6492SMark Einon /* Set the LED behavior such that LED 1 indicates speed (off = 147638df6492SMark Einon * 10Mbits, blink = 100Mbits, on = 1000Mbits) and LED 2 indicates 147738df6492SMark Einon * link and activity (on for link, blink off for activity). 147838df6492SMark Einon * 147938df6492SMark Einon * NOTE: Some customizations have been added here for specific 148038df6492SMark Einon * vendors; The LED behavior is now determined by vendor data in the 148138df6492SMark Einon * EEPROM. However, the above description is the default. 148238df6492SMark Einon */ 148338df6492SMark Einon if ((adapter->eeprom_data[1] & 0x4) == 0) { 148438df6492SMark Einon et131x_mii_read(adapter, PHY_LED_2, &lcr2); 148538df6492SMark Einon 148638df6492SMark Einon lcr2 &= (ET_LED2_LED_100TX | ET_LED2_LED_1000T); 148738df6492SMark Einon lcr2 |= (LED_VAL_LINKON_ACTIVE << LED_LINK_SHIFT); 148838df6492SMark Einon 148938df6492SMark Einon if ((adapter->eeprom_data[1] & 0x8) == 0) 149038df6492SMark Einon lcr2 |= (LED_VAL_1000BT_100BTX << LED_TXRX_SHIFT); 149138df6492SMark Einon else 149238df6492SMark Einon lcr2 |= (LED_VAL_LINKON << LED_TXRX_SHIFT); 149338df6492SMark Einon 1494e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, PHY_LED_2, lcr2); 149538df6492SMark Einon } 149638df6492SMark Einon } 149738df6492SMark Einon 149838df6492SMark Einon /* et131x_configure_global_regs - configure JAGCore global regs */ 149938df6492SMark Einon static void et131x_configure_global_regs(struct et131x_adapter *adapter) 150038df6492SMark Einon { 150138df6492SMark Einon struct global_regs __iomem *regs = &adapter->regs->global; 150238df6492SMark Einon 150338df6492SMark Einon writel(0, ®s->rxq_start_addr); 150438df6492SMark Einon writel(INTERNAL_MEM_SIZE - 1, ®s->txq_end_addr); 150538df6492SMark Einon 150638df6492SMark Einon if (adapter->registry_jumbo_packet < 2048) { 150738df6492SMark Einon /* Tx / RxDMA and Tx/Rx MAC interfaces have a 1k word 150838df6492SMark Einon * block of RAM that the driver can split between Tx 150938df6492SMark Einon * and Rx as it desires. Our default is to split it 151038df6492SMark Einon * 50/50: 151138df6492SMark Einon */ 151238df6492SMark Einon writel(PARM_RX_MEM_END_DEF, ®s->rxq_end_addr); 151338df6492SMark Einon writel(PARM_RX_MEM_END_DEF + 1, ®s->txq_start_addr); 151438df6492SMark Einon } else if (adapter->registry_jumbo_packet < 8192) { 151538df6492SMark Einon /* For jumbo packets > 2k but < 8k, split 50-50. */ 151638df6492SMark Einon writel(INTERNAL_MEM_RX_OFFSET, ®s->rxq_end_addr); 151738df6492SMark Einon writel(INTERNAL_MEM_RX_OFFSET + 1, ®s->txq_start_addr); 151838df6492SMark Einon } else { 151938df6492SMark Einon /* 9216 is the only packet size greater than 8k that 152038df6492SMark Einon * is available. The Tx buffer has to be big enough 152138df6492SMark Einon * for one whole packet on the Tx side. We'll make 152238df6492SMark Einon * the Tx 9408, and give the rest to Rx 152338df6492SMark Einon */ 152438df6492SMark Einon writel(0x01b3, ®s->rxq_end_addr); 152538df6492SMark Einon writel(0x01b4, ®s->txq_start_addr); 152638df6492SMark Einon } 152738df6492SMark Einon 152838df6492SMark Einon /* Initialize the loopback register. Disable all loopbacks. */ 152938df6492SMark Einon writel(0, ®s->loopback); 153038df6492SMark Einon 153138df6492SMark Einon writel(0, ®s->msi_config); 153238df6492SMark Einon 153338df6492SMark Einon /* By default, disable the watchdog timer. It will be enabled when 153438df6492SMark Einon * a packet is queued. 153538df6492SMark Einon */ 153638df6492SMark Einon writel(0, ®s->watchdog_timer); 153738df6492SMark Einon } 153838df6492SMark Einon 153938df6492SMark Einon /* et131x_config_rx_dma_regs - Start of Rx_DMA init sequence */ 154038df6492SMark Einon static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) 154138df6492SMark Einon { 154238df6492SMark Einon struct rxdma_regs __iomem *rx_dma = &adapter->regs->rxdma; 154338df6492SMark Einon struct rx_ring *rx_local = &adapter->rx_ring; 154438df6492SMark Einon struct fbr_desc *fbr_entry; 154538df6492SMark Einon u32 entry; 154638df6492SMark Einon u32 psr_num_des; 154738df6492SMark Einon unsigned long flags; 154838df6492SMark Einon u8 id; 154938df6492SMark Einon 155038df6492SMark Einon et131x_rx_dma_disable(adapter); 155138df6492SMark Einon 155238df6492SMark Einon /* Load the completion writeback physical address */ 155338df6492SMark Einon writel(upper_32_bits(rx_local->rx_status_bus), &rx_dma->dma_wb_base_hi); 155438df6492SMark Einon writel(lower_32_bits(rx_local->rx_status_bus), &rx_dma->dma_wb_base_lo); 155538df6492SMark Einon 155638df6492SMark Einon memset(rx_local->rx_status_block, 0, sizeof(struct rx_status_block)); 155738df6492SMark Einon 155838df6492SMark Einon /* Set the address and parameters of the packet status ring */ 155938df6492SMark Einon writel(upper_32_bits(rx_local->ps_ring_physaddr), &rx_dma->psr_base_hi); 156038df6492SMark Einon writel(lower_32_bits(rx_local->ps_ring_physaddr), &rx_dma->psr_base_lo); 156138df6492SMark Einon writel(rx_local->psr_entries - 1, &rx_dma->psr_num_des); 156238df6492SMark Einon writel(0, &rx_dma->psr_full_offset); 156338df6492SMark Einon 156438df6492SMark Einon psr_num_des = readl(&rx_dma->psr_num_des) & ET_RXDMA_PSR_NUM_DES_MASK; 156538df6492SMark Einon writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100, 156638df6492SMark Einon &rx_dma->psr_min_des); 156738df6492SMark Einon 156838df6492SMark Einon spin_lock_irqsave(&adapter->rcv_lock, flags); 156938df6492SMark Einon 157038df6492SMark Einon /* These local variables track the PSR in the adapter structure */ 157138df6492SMark Einon rx_local->local_psr_full = 0; 157238df6492SMark Einon 157338df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 157438df6492SMark Einon u32 __iomem *num_des; 157538df6492SMark Einon u32 __iomem *full_offset; 157638df6492SMark Einon u32 __iomem *min_des; 157738df6492SMark Einon u32 __iomem *base_hi; 157838df6492SMark Einon u32 __iomem *base_lo; 157938df6492SMark Einon struct fbr_lookup *fbr = rx_local->fbr[id]; 158038df6492SMark Einon 158138df6492SMark Einon if (id == 0) { 158238df6492SMark Einon num_des = &rx_dma->fbr0_num_des; 158338df6492SMark Einon full_offset = &rx_dma->fbr0_full_offset; 158438df6492SMark Einon min_des = &rx_dma->fbr0_min_des; 158538df6492SMark Einon base_hi = &rx_dma->fbr0_base_hi; 158638df6492SMark Einon base_lo = &rx_dma->fbr0_base_lo; 158738df6492SMark Einon } else { 158838df6492SMark Einon num_des = &rx_dma->fbr1_num_des; 158938df6492SMark Einon full_offset = &rx_dma->fbr1_full_offset; 159038df6492SMark Einon min_des = &rx_dma->fbr1_min_des; 159138df6492SMark Einon base_hi = &rx_dma->fbr1_base_hi; 159238df6492SMark Einon base_lo = &rx_dma->fbr1_base_lo; 159338df6492SMark Einon } 159438df6492SMark Einon 159538df6492SMark Einon /* Now's the best time to initialize FBR contents */ 159638df6492SMark Einon fbr_entry = fbr->ring_virtaddr; 159738df6492SMark Einon for (entry = 0; entry < fbr->num_entries; entry++) { 159838df6492SMark Einon fbr_entry->addr_hi = fbr->bus_high[entry]; 159938df6492SMark Einon fbr_entry->addr_lo = fbr->bus_low[entry]; 160038df6492SMark Einon fbr_entry->word2 = entry; 160138df6492SMark Einon fbr_entry++; 160238df6492SMark Einon } 160338df6492SMark Einon 160438df6492SMark Einon /* Set the address and parameters of Free buffer ring 1 and 0 */ 160538df6492SMark Einon writel(upper_32_bits(fbr->ring_physaddr), base_hi); 160638df6492SMark Einon writel(lower_32_bits(fbr->ring_physaddr), base_lo); 160738df6492SMark Einon writel(fbr->num_entries - 1, num_des); 160838df6492SMark Einon writel(ET_DMA10_WRAP, full_offset); 160938df6492SMark Einon 161038df6492SMark Einon /* This variable tracks the free buffer ring 1 full position, 161138df6492SMark Einon * so it has to match the above. 161238df6492SMark Einon */ 161338df6492SMark Einon fbr->local_full = ET_DMA10_WRAP; 161438df6492SMark Einon writel(((fbr->num_entries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, 161538df6492SMark Einon min_des); 161638df6492SMark Einon } 161738df6492SMark Einon 161838df6492SMark Einon /* Program the number of packets we will receive before generating an 161938df6492SMark Einon * interrupt. 162038df6492SMark Einon * For version B silicon, this value gets updated once autoneg is 162138df6492SMark Einon *complete. 162238df6492SMark Einon */ 162338df6492SMark Einon writel(PARM_RX_NUM_BUFS_DEF, &rx_dma->num_pkt_done); 162438df6492SMark Einon 162538df6492SMark Einon /* The "time_done" is not working correctly to coalesce interrupts 162638df6492SMark Einon * after a given time period, but rather is giving us an interrupt 162738df6492SMark Einon * regardless of whether we have received packets. 162838df6492SMark Einon * This value gets updated once autoneg is complete. 162938df6492SMark Einon */ 163038df6492SMark Einon writel(PARM_RX_TIME_INT_DEF, &rx_dma->max_pkt_time); 163138df6492SMark Einon 163238df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 163338df6492SMark Einon } 163438df6492SMark Einon 163538df6492SMark Einon /* et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore. 163638df6492SMark Einon * 163738df6492SMark Einon * Configure the transmit engine with the ring buffers we have created 163838df6492SMark Einon * and prepare it for use. 163938df6492SMark Einon */ 164038df6492SMark Einon static void et131x_config_tx_dma_regs(struct et131x_adapter *adapter) 164138df6492SMark Einon { 164238df6492SMark Einon struct txdma_regs __iomem *txdma = &adapter->regs->txdma; 164338df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 164438df6492SMark Einon 164538df6492SMark Einon /* Load the hardware with the start of the transmit descriptor ring. */ 164638df6492SMark Einon writel(upper_32_bits(tx_ring->tx_desc_ring_pa), &txdma->pr_base_hi); 164738df6492SMark Einon writel(lower_32_bits(tx_ring->tx_desc_ring_pa), &txdma->pr_base_lo); 164838df6492SMark Einon 164938df6492SMark Einon /* Initialise the transmit DMA engine */ 165038df6492SMark Einon writel(NUM_DESC_PER_RING_TX - 1, &txdma->pr_num_des); 165138df6492SMark Einon 165238df6492SMark Einon /* Load the completion writeback physical address */ 165338df6492SMark Einon writel(upper_32_bits(tx_ring->tx_status_pa), &txdma->dma_wb_base_hi); 165438df6492SMark Einon writel(lower_32_bits(tx_ring->tx_status_pa), &txdma->dma_wb_base_lo); 165538df6492SMark Einon 165638df6492SMark Einon *tx_ring->tx_status = 0; 165738df6492SMark Einon 165838df6492SMark Einon writel(0, &txdma->service_request); 165938df6492SMark Einon tx_ring->send_idx = 0; 166038df6492SMark Einon } 166138df6492SMark Einon 166238df6492SMark Einon /* et131x_adapter_setup - Set the adapter up as per cassini+ documentation */ 166338df6492SMark Einon static void et131x_adapter_setup(struct et131x_adapter *adapter) 166438df6492SMark Einon { 166538df6492SMark Einon et131x_configure_global_regs(adapter); 166638df6492SMark Einon et1310_config_mac_regs1(adapter); 166738df6492SMark Einon 166838df6492SMark Einon /* Configure the MMC registers */ 166938df6492SMark Einon /* All we need to do is initialize the Memory Control Register */ 167038df6492SMark Einon writel(ET_MMC_ENABLE, &adapter->regs->mmc.mmc_ctrl); 167138df6492SMark Einon 167238df6492SMark Einon et1310_config_rxmac_regs(adapter); 167338df6492SMark Einon et1310_config_txmac_regs(adapter); 167438df6492SMark Einon 167538df6492SMark Einon et131x_config_rx_dma_regs(adapter); 167638df6492SMark Einon et131x_config_tx_dma_regs(adapter); 167738df6492SMark Einon 167838df6492SMark Einon et1310_config_macstat_regs(adapter); 167938df6492SMark Einon 168038df6492SMark Einon et1310_phy_power_switch(adapter, 0); 168138df6492SMark Einon et131x_xcvr_init(adapter); 168238df6492SMark Einon } 168338df6492SMark Einon 168438df6492SMark Einon /* et131x_soft_reset - Issue soft reset to the hardware, complete for ET1310 */ 168538df6492SMark Einon static void et131x_soft_reset(struct et131x_adapter *adapter) 168638df6492SMark Einon { 168738df6492SMark Einon u32 reg; 168838df6492SMark Einon 168938df6492SMark Einon /* Disable MAC Core */ 169038df6492SMark Einon reg = ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET | 169138df6492SMark Einon ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | 169238df6492SMark Einon ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC; 169338df6492SMark Einon writel(reg, &adapter->regs->mac.cfg1); 169438df6492SMark Einon 169538df6492SMark Einon reg = ET_RESET_ALL; 169638df6492SMark Einon writel(reg, &adapter->regs->global.sw_reset); 169738df6492SMark Einon 169838df6492SMark Einon reg = ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | 169938df6492SMark Einon ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC; 170038df6492SMark Einon writel(reg, &adapter->regs->mac.cfg1); 170138df6492SMark Einon writel(0, &adapter->regs->mac.cfg1); 170238df6492SMark Einon } 170338df6492SMark Einon 170438df6492SMark Einon static void et131x_enable_interrupts(struct et131x_adapter *adapter) 170538df6492SMark Einon { 170638df6492SMark Einon u32 mask; 170738df6492SMark Einon 170838df6492SMark Einon if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) 170938df6492SMark Einon mask = INT_MASK_ENABLE; 171038df6492SMark Einon else 171138df6492SMark Einon mask = INT_MASK_ENABLE_NO_FLOW; 171238df6492SMark Einon 171338df6492SMark Einon writel(mask, &adapter->regs->global.int_mask); 171438df6492SMark Einon } 171538df6492SMark Einon 171638df6492SMark Einon static void et131x_disable_interrupts(struct et131x_adapter *adapter) 171738df6492SMark Einon { 171838df6492SMark Einon writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask); 171938df6492SMark Einon } 172038df6492SMark Einon 172138df6492SMark Einon static void et131x_tx_dma_disable(struct et131x_adapter *adapter) 172238df6492SMark Einon { 172338df6492SMark Einon /* Setup the transmit dma configuration register */ 172438df6492SMark Einon writel(ET_TXDMA_CSR_HALT | ET_TXDMA_SNGL_EPKT, 172538df6492SMark Einon &adapter->regs->txdma.csr); 172638df6492SMark Einon } 172738df6492SMark Einon 172838df6492SMark Einon static void et131x_enable_txrx(struct net_device *netdev) 172938df6492SMark Einon { 173038df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 173138df6492SMark Einon 173238df6492SMark Einon et131x_rx_dma_enable(adapter); 173338df6492SMark Einon et131x_tx_dma_enable(adapter); 173438df6492SMark Einon 173538df6492SMark Einon if (adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE) 173638df6492SMark Einon et131x_enable_interrupts(adapter); 173738df6492SMark Einon 173838df6492SMark Einon netif_start_queue(netdev); 173938df6492SMark Einon } 174038df6492SMark Einon 174138df6492SMark Einon static void et131x_disable_txrx(struct net_device *netdev) 174238df6492SMark Einon { 174338df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 174438df6492SMark Einon 174538df6492SMark Einon netif_stop_queue(netdev); 174638df6492SMark Einon 174738df6492SMark Einon et131x_rx_dma_disable(adapter); 174838df6492SMark Einon et131x_tx_dma_disable(adapter); 174938df6492SMark Einon 175038df6492SMark Einon et131x_disable_interrupts(adapter); 175138df6492SMark Einon } 175238df6492SMark Einon 175338df6492SMark Einon static void et131x_init_send(struct et131x_adapter *adapter) 175438df6492SMark Einon { 175538df6492SMark Einon int i; 175638df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 175738df6492SMark Einon struct tcb *tcb = tx_ring->tcb_ring; 175838df6492SMark Einon 175938df6492SMark Einon tx_ring->tcb_qhead = tcb; 176038df6492SMark Einon 176138df6492SMark Einon memset(tcb, 0, sizeof(struct tcb) * NUM_TCB); 176238df6492SMark Einon 176338df6492SMark Einon for (i = 0; i < NUM_TCB; i++) { 176438df6492SMark Einon tcb->next = tcb + 1; 176538df6492SMark Einon tcb++; 176638df6492SMark Einon } 176738df6492SMark Einon 176838df6492SMark Einon tcb--; 176938df6492SMark Einon tx_ring->tcb_qtail = tcb; 177038df6492SMark Einon tcb->next = NULL; 177138df6492SMark Einon /* Curr send queue should now be empty */ 177238df6492SMark Einon tx_ring->send_head = NULL; 177338df6492SMark Einon tx_ring->send_tail = NULL; 177438df6492SMark Einon } 177538df6492SMark Einon 177638df6492SMark Einon /* et1310_enable_phy_coma 177738df6492SMark Einon * 177838df6492SMark Einon * driver receive an phy status change interrupt while in D0 and check that 177938df6492SMark Einon * phy_status is down. 178038df6492SMark Einon * 178138df6492SMark Einon * -- gate off JAGCore; 178238df6492SMark Einon * -- set gigE PHY in Coma mode 178338df6492SMark Einon * -- wake on phy_interrupt; Perform software reset JAGCore, 178438df6492SMark Einon * re-initialize jagcore and gigE PHY 178538df6492SMark Einon */ 178638df6492SMark Einon static void et1310_enable_phy_coma(struct et131x_adapter *adapter) 178738df6492SMark Einon { 178838df6492SMark Einon u32 pmcsr = readl(&adapter->regs->global.pm_csr); 178938df6492SMark Einon 179038df6492SMark Einon /* Stop sending packets. */ 179138df6492SMark Einon adapter->flags |= FMP_ADAPTER_LOWER_POWER; 179238df6492SMark Einon 179338df6492SMark Einon /* Wait for outstanding Receive packets */ 179438df6492SMark Einon et131x_disable_txrx(adapter->netdev); 179538df6492SMark Einon 179638df6492SMark Einon /* Gate off JAGCore 3 clock domains */ 179738df6492SMark Einon pmcsr &= ~ET_PMCSR_INIT; 179838df6492SMark Einon writel(pmcsr, &adapter->regs->global.pm_csr); 179938df6492SMark Einon 180038df6492SMark Einon /* Program gigE PHY in to Coma mode */ 180138df6492SMark Einon pmcsr |= ET_PM_PHY_SW_COMA; 180238df6492SMark Einon writel(pmcsr, &adapter->regs->global.pm_csr); 180338df6492SMark Einon } 180438df6492SMark Einon 180538df6492SMark Einon static void et1310_disable_phy_coma(struct et131x_adapter *adapter) 180638df6492SMark Einon { 180738df6492SMark Einon u32 pmcsr; 180838df6492SMark Einon 180938df6492SMark Einon pmcsr = readl(&adapter->regs->global.pm_csr); 181038df6492SMark Einon 181138df6492SMark Einon /* Disable phy_sw_coma register and re-enable JAGCore clocks */ 181238df6492SMark Einon pmcsr |= ET_PMCSR_INIT; 181338df6492SMark Einon pmcsr &= ~ET_PM_PHY_SW_COMA; 181438df6492SMark Einon writel(pmcsr, &adapter->regs->global.pm_csr); 181538df6492SMark Einon 181638df6492SMark Einon /* Restore the GbE PHY speed and duplex modes; 181738df6492SMark Einon * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY 181838df6492SMark Einon */ 181938df6492SMark Einon 182038df6492SMark Einon /* Re-initialize the send structures */ 182138df6492SMark Einon et131x_init_send(adapter); 182238df6492SMark Einon 182338df6492SMark Einon /* Bring the device back to the state it was during init prior to 182438df6492SMark Einon * autonegotiation being complete. This way, when we get the auto-neg 182538df6492SMark Einon * complete interrupt, we can complete init by calling ConfigMacREGS2. 182638df6492SMark Einon */ 182738df6492SMark Einon et131x_soft_reset(adapter); 182838df6492SMark Einon 182938df6492SMark Einon et131x_adapter_setup(adapter); 183038df6492SMark Einon 183138df6492SMark Einon /* Allow Tx to restart */ 183238df6492SMark Einon adapter->flags &= ~FMP_ADAPTER_LOWER_POWER; 183338df6492SMark Einon 183438df6492SMark Einon et131x_enable_txrx(adapter->netdev); 183538df6492SMark Einon } 183638df6492SMark Einon 183738df6492SMark Einon static inline u32 bump_free_buff_ring(u32 *free_buff_ring, u32 limit) 183838df6492SMark Einon { 183938df6492SMark Einon u32 tmp_free_buff_ring = *free_buff_ring; 184038df6492SMark Einon 184138df6492SMark Einon tmp_free_buff_ring++; 184238df6492SMark Einon /* This works for all cases where limit < 1024. The 1023 case 184338df6492SMark Einon * works because 1023++ is 1024 which means the if condition is not 184438df6492SMark Einon * taken but the carry of the bit into the wrap bit toggles the wrap 184538df6492SMark Einon * value correctly 184638df6492SMark Einon */ 184738df6492SMark Einon if ((tmp_free_buff_ring & ET_DMA10_MASK) > limit) { 184838df6492SMark Einon tmp_free_buff_ring &= ~ET_DMA10_MASK; 184938df6492SMark Einon tmp_free_buff_ring ^= ET_DMA10_WRAP; 185038df6492SMark Einon } 185138df6492SMark Einon /* For the 1023 case */ 185238df6492SMark Einon tmp_free_buff_ring &= (ET_DMA10_MASK | ET_DMA10_WRAP); 185338df6492SMark Einon *free_buff_ring = tmp_free_buff_ring; 185438df6492SMark Einon return tmp_free_buff_ring; 185538df6492SMark Einon } 185638df6492SMark Einon 185738df6492SMark Einon /* et131x_rx_dma_memory_alloc 185838df6492SMark Einon * 185938df6492SMark Einon * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required, 186038df6492SMark Einon * and the Packet Status Ring. 186138df6492SMark Einon */ 186238df6492SMark Einon static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) 186338df6492SMark Einon { 186438df6492SMark Einon u8 id; 186538df6492SMark Einon u32 i, j; 186638df6492SMark Einon u32 bufsize; 186738df6492SMark Einon u32 psr_size; 186838df6492SMark Einon u32 fbr_chunksize; 186938df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 187038df6492SMark Einon struct fbr_lookup *fbr; 187138df6492SMark Einon 187238df6492SMark Einon /* Alloc memory for the lookup table */ 187338df6492SMark Einon rx_ring->fbr[0] = kzalloc(sizeof(*fbr), GFP_KERNEL); 187438df6492SMark Einon if (rx_ring->fbr[0] == NULL) 187538df6492SMark Einon return -ENOMEM; 187638df6492SMark Einon rx_ring->fbr[1] = kzalloc(sizeof(*fbr), GFP_KERNEL); 187738df6492SMark Einon if (rx_ring->fbr[1] == NULL) 187838df6492SMark Einon return -ENOMEM; 187938df6492SMark Einon 188038df6492SMark Einon /* The first thing we will do is configure the sizes of the buffer 188138df6492SMark Einon * rings. These will change based on jumbo packet support. Larger 188238df6492SMark Einon * jumbo packets increases the size of each entry in FBR0, and the 188338df6492SMark Einon * number of entries in FBR0, while at the same time decreasing the 188438df6492SMark Einon * number of entries in FBR1. 188538df6492SMark Einon * 188638df6492SMark Einon * FBR1 holds "large" frames, FBR0 holds "small" frames. If FBR1 188738df6492SMark Einon * entries are huge in order to accommodate a "jumbo" frame, then it 188838df6492SMark Einon * will have less entries. Conversely, FBR1 will now be relied upon 188938df6492SMark Einon * to carry more "normal" frames, thus it's entry size also increases 189038df6492SMark Einon * and the number of entries goes up too (since it now carries 189138df6492SMark Einon * "small" + "regular" packets. 189238df6492SMark Einon * 189338df6492SMark Einon * In this scheme, we try to maintain 512 entries between the two 189438df6492SMark Einon * rings. Also, FBR1 remains a constant size - when it's size doubles 189538df6492SMark Einon * the number of entries halves. FBR0 increases in size, however. 189638df6492SMark Einon */ 189738df6492SMark Einon if (adapter->registry_jumbo_packet < 2048) { 189838df6492SMark Einon rx_ring->fbr[0]->buffsize = 256; 189938df6492SMark Einon rx_ring->fbr[0]->num_entries = 512; 190038df6492SMark Einon rx_ring->fbr[1]->buffsize = 2048; 190138df6492SMark Einon rx_ring->fbr[1]->num_entries = 512; 190238df6492SMark Einon } else if (adapter->registry_jumbo_packet < 4096) { 190338df6492SMark Einon rx_ring->fbr[0]->buffsize = 512; 190438df6492SMark Einon rx_ring->fbr[0]->num_entries = 1024; 190538df6492SMark Einon rx_ring->fbr[1]->buffsize = 4096; 190638df6492SMark Einon rx_ring->fbr[1]->num_entries = 512; 190738df6492SMark Einon } else { 190838df6492SMark Einon rx_ring->fbr[0]->buffsize = 1024; 190938df6492SMark Einon rx_ring->fbr[0]->num_entries = 768; 191038df6492SMark Einon rx_ring->fbr[1]->buffsize = 16384; 191138df6492SMark Einon rx_ring->fbr[1]->num_entries = 128; 191238df6492SMark Einon } 191338df6492SMark Einon 191438df6492SMark Einon rx_ring->psr_entries = rx_ring->fbr[0]->num_entries + 191538df6492SMark Einon rx_ring->fbr[1]->num_entries; 191638df6492SMark Einon 191738df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 191838df6492SMark Einon fbr = rx_ring->fbr[id]; 191938df6492SMark Einon /* Allocate an area of memory for Free Buffer Ring */ 192038df6492SMark Einon bufsize = sizeof(struct fbr_desc) * fbr->num_entries; 192138df6492SMark Einon fbr->ring_virtaddr = dma_alloc_coherent(&adapter->pdev->dev, 192238df6492SMark Einon bufsize, 192338df6492SMark Einon &fbr->ring_physaddr, 192438df6492SMark Einon GFP_KERNEL); 192538df6492SMark Einon if (!fbr->ring_virtaddr) { 192638df6492SMark Einon dev_err(&adapter->pdev->dev, 192738df6492SMark Einon "Cannot alloc memory for Free Buffer Ring %d\n", 192838df6492SMark Einon id); 192938df6492SMark Einon return -ENOMEM; 193038df6492SMark Einon } 193138df6492SMark Einon } 193238df6492SMark Einon 193338df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 193438df6492SMark Einon fbr = rx_ring->fbr[id]; 193538df6492SMark Einon fbr_chunksize = (FBR_CHUNKS * fbr->buffsize); 193638df6492SMark Einon 193738df6492SMark Einon for (i = 0; i < fbr->num_entries / FBR_CHUNKS; i++) { 193838df6492SMark Einon dma_addr_t fbr_physaddr; 193938df6492SMark Einon 194038df6492SMark Einon fbr->mem_virtaddrs[i] = dma_alloc_coherent( 194138df6492SMark Einon &adapter->pdev->dev, fbr_chunksize, 194238df6492SMark Einon &fbr->mem_physaddrs[i], 194338df6492SMark Einon GFP_KERNEL); 194438df6492SMark Einon 194538df6492SMark Einon if (!fbr->mem_virtaddrs[i]) { 194638df6492SMark Einon dev_err(&adapter->pdev->dev, 194738df6492SMark Einon "Could not alloc memory\n"); 194838df6492SMark Einon return -ENOMEM; 194938df6492SMark Einon } 195038df6492SMark Einon 195138df6492SMark Einon /* See NOTE in "Save Physical Address" comment above */ 195238df6492SMark Einon fbr_physaddr = fbr->mem_physaddrs[i]; 195338df6492SMark Einon 195438df6492SMark Einon for (j = 0; j < FBR_CHUNKS; j++) { 195538df6492SMark Einon u32 k = (i * FBR_CHUNKS) + j; 195638df6492SMark Einon 195738df6492SMark Einon /* Save the Virtual address of this index for 195838df6492SMark Einon * quick access later 195938df6492SMark Einon */ 196038df6492SMark Einon fbr->virt[k] = (u8 *)fbr->mem_virtaddrs[i] + 196138df6492SMark Einon (j * fbr->buffsize); 196238df6492SMark Einon 196338df6492SMark Einon /* now store the physical address in the 196438df6492SMark Einon * descriptor so the device can access it 196538df6492SMark Einon */ 196638df6492SMark Einon fbr->bus_high[k] = upper_32_bits(fbr_physaddr); 196738df6492SMark Einon fbr->bus_low[k] = lower_32_bits(fbr_physaddr); 196838df6492SMark Einon fbr_physaddr += fbr->buffsize; 196938df6492SMark Einon } 197038df6492SMark Einon } 197138df6492SMark Einon } 197238df6492SMark Einon 197338df6492SMark Einon /* Allocate an area of memory for FIFO of Packet Status ring entries */ 197438df6492SMark Einon psr_size = sizeof(struct pkt_stat_desc) * rx_ring->psr_entries; 197538df6492SMark Einon 197638df6492SMark Einon rx_ring->ps_ring_virtaddr = dma_alloc_coherent(&adapter->pdev->dev, 197738df6492SMark Einon psr_size, 197838df6492SMark Einon &rx_ring->ps_ring_physaddr, 197938df6492SMark Einon GFP_KERNEL); 198038df6492SMark Einon 198138df6492SMark Einon if (!rx_ring->ps_ring_virtaddr) { 198238df6492SMark Einon dev_err(&adapter->pdev->dev, 198338df6492SMark Einon "Cannot alloc memory for Packet Status Ring\n"); 198438df6492SMark Einon return -ENOMEM; 198538df6492SMark Einon } 198638df6492SMark Einon 198738df6492SMark Einon /* Allocate an area of memory for writeback of status information */ 198838df6492SMark Einon rx_ring->rx_status_block = dma_alloc_coherent(&adapter->pdev->dev, 198938df6492SMark Einon sizeof(struct rx_status_block), 199038df6492SMark Einon &rx_ring->rx_status_bus, 199138df6492SMark Einon GFP_KERNEL); 199238df6492SMark Einon if (!rx_ring->rx_status_block) { 199338df6492SMark Einon dev_err(&adapter->pdev->dev, 199438df6492SMark Einon "Cannot alloc memory for Status Block\n"); 199538df6492SMark Einon return -ENOMEM; 199638df6492SMark Einon } 199738df6492SMark Einon rx_ring->num_rfd = NIC_DEFAULT_NUM_RFD; 199838df6492SMark Einon 199938df6492SMark Einon /* The RFDs are going to be put on lists later on, so initialize the 200038df6492SMark Einon * lists now. 200138df6492SMark Einon */ 200238df6492SMark Einon INIT_LIST_HEAD(&rx_ring->recv_list); 200338df6492SMark Einon return 0; 200438df6492SMark Einon } 200538df6492SMark Einon 200638df6492SMark Einon static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) 200738df6492SMark Einon { 200838df6492SMark Einon u8 id; 200938df6492SMark Einon u32 ii; 201038df6492SMark Einon u32 bufsize; 201138df6492SMark Einon u32 psr_size; 201238df6492SMark Einon struct rfd *rfd; 201338df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 201438df6492SMark Einon struct fbr_lookup *fbr; 201538df6492SMark Einon 201638df6492SMark Einon /* Free RFDs and associated packet descriptors */ 201738df6492SMark Einon WARN_ON(rx_ring->num_ready_recv != rx_ring->num_rfd); 201838df6492SMark Einon 201938df6492SMark Einon while (!list_empty(&rx_ring->recv_list)) { 202038df6492SMark Einon rfd = list_entry(rx_ring->recv_list.next, 202138df6492SMark Einon struct rfd, list_node); 202238df6492SMark Einon 202338df6492SMark Einon list_del(&rfd->list_node); 202438df6492SMark Einon rfd->skb = NULL; 202538df6492SMark Einon kfree(rfd); 202638df6492SMark Einon } 202738df6492SMark Einon 202838df6492SMark Einon /* Free Free Buffer Rings */ 202938df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 203038df6492SMark Einon fbr = rx_ring->fbr[id]; 203138df6492SMark Einon 203238df6492SMark Einon if (!fbr || !fbr->ring_virtaddr) 203338df6492SMark Einon continue; 203438df6492SMark Einon 203538df6492SMark Einon /* First the packet memory */ 203638df6492SMark Einon for (ii = 0; ii < fbr->num_entries / FBR_CHUNKS; ii++) { 203738df6492SMark Einon if (fbr->mem_virtaddrs[ii]) { 203838df6492SMark Einon bufsize = fbr->buffsize * FBR_CHUNKS; 203938df6492SMark Einon 204038df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 204138df6492SMark Einon bufsize, 204238df6492SMark Einon fbr->mem_virtaddrs[ii], 204338df6492SMark Einon fbr->mem_physaddrs[ii]); 204438df6492SMark Einon 204538df6492SMark Einon fbr->mem_virtaddrs[ii] = NULL; 204638df6492SMark Einon } 204738df6492SMark Einon } 204838df6492SMark Einon 204938df6492SMark Einon bufsize = sizeof(struct fbr_desc) * fbr->num_entries; 205038df6492SMark Einon 205138df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 205238df6492SMark Einon bufsize, 205338df6492SMark Einon fbr->ring_virtaddr, 205438df6492SMark Einon fbr->ring_physaddr); 205538df6492SMark Einon 205638df6492SMark Einon fbr->ring_virtaddr = NULL; 205738df6492SMark Einon } 205838df6492SMark Einon 205938df6492SMark Einon /* Free Packet Status Ring */ 206038df6492SMark Einon if (rx_ring->ps_ring_virtaddr) { 206138df6492SMark Einon psr_size = sizeof(struct pkt_stat_desc) * rx_ring->psr_entries; 206238df6492SMark Einon 206338df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, psr_size, 206438df6492SMark Einon rx_ring->ps_ring_virtaddr, 206538df6492SMark Einon rx_ring->ps_ring_physaddr); 206638df6492SMark Einon 206738df6492SMark Einon rx_ring->ps_ring_virtaddr = NULL; 206838df6492SMark Einon } 206938df6492SMark Einon 207038df6492SMark Einon /* Free area of memory for the writeback of status information */ 207138df6492SMark Einon if (rx_ring->rx_status_block) { 207238df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 207338df6492SMark Einon sizeof(struct rx_status_block), 207438df6492SMark Einon rx_ring->rx_status_block, 207538df6492SMark Einon rx_ring->rx_status_bus); 207638df6492SMark Einon rx_ring->rx_status_block = NULL; 207738df6492SMark Einon } 207838df6492SMark Einon 207938df6492SMark Einon /* Free the FBR Lookup Table */ 208038df6492SMark Einon kfree(rx_ring->fbr[0]); 208138df6492SMark Einon kfree(rx_ring->fbr[1]); 208238df6492SMark Einon 208338df6492SMark Einon /* Reset Counters */ 208438df6492SMark Einon rx_ring->num_ready_recv = 0; 208538df6492SMark Einon } 208638df6492SMark Einon 208738df6492SMark Einon /* et131x_init_recv - Initialize receive data structures */ 208838df6492SMark Einon static int et131x_init_recv(struct et131x_adapter *adapter) 208938df6492SMark Einon { 209038df6492SMark Einon struct rfd *rfd; 209138df6492SMark Einon u32 rfdct; 209238df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 209338df6492SMark Einon 209438df6492SMark Einon /* Setup each RFD */ 209538df6492SMark Einon for (rfdct = 0; rfdct < rx_ring->num_rfd; rfdct++) { 209638df6492SMark Einon rfd = kzalloc(sizeof(*rfd), GFP_ATOMIC | GFP_DMA); 209738df6492SMark Einon if (!rfd) 209838df6492SMark Einon return -ENOMEM; 209938df6492SMark Einon 210038df6492SMark Einon rfd->skb = NULL; 210138df6492SMark Einon 210238df6492SMark Einon /* Add this RFD to the recv_list */ 210338df6492SMark Einon list_add_tail(&rfd->list_node, &rx_ring->recv_list); 210438df6492SMark Einon 210538df6492SMark Einon /* Increment the available RFD's */ 210638df6492SMark Einon rx_ring->num_ready_recv++; 210738df6492SMark Einon } 210838df6492SMark Einon 210938df6492SMark Einon return 0; 211038df6492SMark Einon } 211138df6492SMark Einon 211238df6492SMark Einon /* et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate */ 211338df6492SMark Einon static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter) 211438df6492SMark Einon { 2115a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 211638df6492SMark Einon 211738df6492SMark Einon /* For version B silicon, we do not use the RxDMA timer for 10 and 100 211838df6492SMark Einon * Mbits/s line rates. We do not enable and RxDMA interrupt coalescing. 211938df6492SMark Einon */ 212038df6492SMark Einon if ((phydev->speed == SPEED_100) || (phydev->speed == SPEED_10)) { 212138df6492SMark Einon writel(0, &adapter->regs->rxdma.max_pkt_time); 212238df6492SMark Einon writel(1, &adapter->regs->rxdma.num_pkt_done); 212338df6492SMark Einon } 212438df6492SMark Einon } 212538df6492SMark Einon 212638df6492SMark Einon /* nic_return_rfd - Recycle a RFD and put it back onto the receive list */ 212738df6492SMark Einon static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd) 212838df6492SMark Einon { 212938df6492SMark Einon struct rx_ring *rx_local = &adapter->rx_ring; 213038df6492SMark Einon struct rxdma_regs __iomem *rx_dma = &adapter->regs->rxdma; 213138df6492SMark Einon u16 buff_index = rfd->bufferindex; 213238df6492SMark Einon u8 ring_index = rfd->ringindex; 213338df6492SMark Einon unsigned long flags; 213438df6492SMark Einon struct fbr_lookup *fbr = rx_local->fbr[ring_index]; 213538df6492SMark Einon 213638df6492SMark Einon /* We don't use any of the OOB data besides status. Otherwise, we 213738df6492SMark Einon * need to clean up OOB data 213838df6492SMark Einon */ 213938df6492SMark Einon if (buff_index < fbr->num_entries) { 214038df6492SMark Einon u32 free_buff_ring; 214138df6492SMark Einon u32 __iomem *offset; 214238df6492SMark Einon struct fbr_desc *next; 214338df6492SMark Einon 214438df6492SMark Einon if (ring_index == 0) 214538df6492SMark Einon offset = &rx_dma->fbr0_full_offset; 214638df6492SMark Einon else 214738df6492SMark Einon offset = &rx_dma->fbr1_full_offset; 214838df6492SMark Einon 214938df6492SMark Einon next = (struct fbr_desc *)(fbr->ring_virtaddr) + 215038df6492SMark Einon INDEX10(fbr->local_full); 215138df6492SMark Einon 215238df6492SMark Einon /* Handle the Free Buffer Ring advancement here. Write 215338df6492SMark Einon * the PA / Buffer Index for the returned buffer into 215438df6492SMark Einon * the oldest (next to be freed)FBR entry 215538df6492SMark Einon */ 215638df6492SMark Einon next->addr_hi = fbr->bus_high[buff_index]; 215738df6492SMark Einon next->addr_lo = fbr->bus_low[buff_index]; 215838df6492SMark Einon next->word2 = buff_index; 215938df6492SMark Einon 216038df6492SMark Einon free_buff_ring = bump_free_buff_ring(&fbr->local_full, 216138df6492SMark Einon fbr->num_entries - 1); 216238df6492SMark Einon writel(free_buff_ring, offset); 216338df6492SMark Einon } else { 216438df6492SMark Einon dev_err(&adapter->pdev->dev, 216538df6492SMark Einon "%s illegal Buffer Index returned\n", __func__); 216638df6492SMark Einon } 216738df6492SMark Einon 216838df6492SMark Einon /* The processing on this RFD is done, so put it back on the tail of 216938df6492SMark Einon * our list 217038df6492SMark Einon */ 217138df6492SMark Einon spin_lock_irqsave(&adapter->rcv_lock, flags); 217238df6492SMark Einon list_add_tail(&rfd->list_node, &rx_local->recv_list); 217338df6492SMark Einon rx_local->num_ready_recv++; 217438df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 217538df6492SMark Einon 217638df6492SMark Einon WARN_ON(rx_local->num_ready_recv > rx_local->num_rfd); 217738df6492SMark Einon } 217838df6492SMark Einon 217938df6492SMark Einon /* nic_rx_pkts - Checks the hardware for available packets 218038df6492SMark Einon * 218138df6492SMark Einon * Checks the hardware for available packets, using completion ring 218238df6492SMark Einon * If packets are available, it gets an RFD from the recv_list, attaches 218338df6492SMark Einon * the packet to it, puts the RFD in the RecvPendList, and also returns 218438df6492SMark Einon * the pointer to the RFD. 218538df6492SMark Einon */ 218638df6492SMark Einon static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter) 218738df6492SMark Einon { 218838df6492SMark Einon struct rx_ring *rx_local = &adapter->rx_ring; 218938df6492SMark Einon struct rx_status_block *status; 219038df6492SMark Einon struct pkt_stat_desc *psr; 219138df6492SMark Einon struct rfd *rfd; 219238df6492SMark Einon unsigned long flags; 219338df6492SMark Einon struct list_head *element; 219438df6492SMark Einon u8 ring_index; 219538df6492SMark Einon u16 buff_index; 219638df6492SMark Einon u32 len; 219738df6492SMark Einon u32 word0; 219838df6492SMark Einon u32 word1; 219938df6492SMark Einon struct sk_buff *skb; 220038df6492SMark Einon struct fbr_lookup *fbr; 220138df6492SMark Einon 220238df6492SMark Einon /* RX Status block is written by the DMA engine prior to every 220338df6492SMark Einon * interrupt. It contains the next to be used entry in the Packet 220438df6492SMark Einon * Status Ring, and also the two Free Buffer rings. 220538df6492SMark Einon */ 220638df6492SMark Einon status = rx_local->rx_status_block; 220738df6492SMark Einon word1 = status->word1 >> 16; 220838df6492SMark Einon 220938df6492SMark Einon /* Check the PSR and wrap bits do not match */ 221038df6492SMark Einon if ((word1 & 0x1FFF) == (rx_local->local_psr_full & 0x1FFF)) 221138df6492SMark Einon return NULL; /* Looks like this ring is not updated yet */ 221238df6492SMark Einon 221338df6492SMark Einon /* The packet status ring indicates that data is available. */ 221438df6492SMark Einon psr = (struct pkt_stat_desc *)(rx_local->ps_ring_virtaddr) + 221538df6492SMark Einon (rx_local->local_psr_full & 0xFFF); 221638df6492SMark Einon 221738df6492SMark Einon /* Grab any information that is required once the PSR is advanced, 221838df6492SMark Einon * since we can no longer rely on the memory being accurate 221938df6492SMark Einon */ 222038df6492SMark Einon len = psr->word1 & 0xFFFF; 222138df6492SMark Einon ring_index = (psr->word1 >> 26) & 0x03; 222238df6492SMark Einon fbr = rx_local->fbr[ring_index]; 222338df6492SMark Einon buff_index = (psr->word1 >> 16) & 0x3FF; 222438df6492SMark Einon word0 = psr->word0; 222538df6492SMark Einon 222638df6492SMark Einon /* Indicate that we have used this PSR entry. */ 222738df6492SMark Einon /* FIXME wrap 12 */ 222838df6492SMark Einon add_12bit(&rx_local->local_psr_full, 1); 222938df6492SMark Einon if ((rx_local->local_psr_full & 0xFFF) > rx_local->psr_entries - 1) { 223038df6492SMark Einon /* Clear psr full and toggle the wrap bit */ 223138df6492SMark Einon rx_local->local_psr_full &= ~0xFFF; 223238df6492SMark Einon rx_local->local_psr_full ^= 0x1000; 223338df6492SMark Einon } 223438df6492SMark Einon 223538df6492SMark Einon writel(rx_local->local_psr_full, &adapter->regs->rxdma.psr_full_offset); 223638df6492SMark Einon 223738df6492SMark Einon if (ring_index > 1 || buff_index > fbr->num_entries - 1) { 223838df6492SMark Einon /* Illegal buffer or ring index cannot be used by S/W*/ 223938df6492SMark Einon dev_err(&adapter->pdev->dev, 224038df6492SMark Einon "NICRxPkts PSR Entry %d indicates length of %d and/or bad bi(%d)\n", 224138df6492SMark Einon rx_local->local_psr_full & 0xFFF, len, buff_index); 224238df6492SMark Einon return NULL; 224338df6492SMark Einon } 224438df6492SMark Einon 224538df6492SMark Einon /* Get and fill the RFD. */ 224638df6492SMark Einon spin_lock_irqsave(&adapter->rcv_lock, flags); 224738df6492SMark Einon 224838df6492SMark Einon element = rx_local->recv_list.next; 224938df6492SMark Einon rfd = list_entry(element, struct rfd, list_node); 225038df6492SMark Einon 225138df6492SMark Einon if (!rfd) { 225238df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 225338df6492SMark Einon return NULL; 225438df6492SMark Einon } 225538df6492SMark Einon 225638df6492SMark Einon list_del(&rfd->list_node); 225738df6492SMark Einon rx_local->num_ready_recv--; 225838df6492SMark Einon 225938df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 226038df6492SMark Einon 226138df6492SMark Einon rfd->bufferindex = buff_index; 226238df6492SMark Einon rfd->ringindex = ring_index; 226338df6492SMark Einon 226438df6492SMark Einon /* In V1 silicon, there is a bug which screws up filtering of runt 226538df6492SMark Einon * packets. Therefore runt packet filtering is disabled in the MAC and 226638df6492SMark Einon * the packets are dropped here. They are also counted here. 226738df6492SMark Einon */ 226838df6492SMark Einon if (len < (NIC_MIN_PACKET_SIZE + 4)) { 226938df6492SMark Einon adapter->stats.rx_other_errs++; 227038df6492SMark Einon rfd->len = 0; 227138df6492SMark Einon goto out; 227238df6492SMark Einon } 227338df6492SMark Einon 227438df6492SMark Einon if ((word0 & ALCATEL_MULTICAST_PKT) && !(word0 & ALCATEL_BROADCAST_PKT)) 227538df6492SMark Einon adapter->stats.multicast_pkts_rcvd++; 227638df6492SMark Einon 227738df6492SMark Einon rfd->len = len; 227838df6492SMark Einon 227938df6492SMark Einon skb = dev_alloc_skb(rfd->len + 2); 228038df6492SMark Einon if (!skb) 228138df6492SMark Einon return NULL; 228238df6492SMark Einon 228338df6492SMark Einon adapter->netdev->stats.rx_bytes += rfd->len; 228438df6492SMark Einon 228559ae1d12SJohannes Berg skb_put_data(skb, fbr->virt[buff_index], rfd->len); 228638df6492SMark Einon 228738df6492SMark Einon skb->protocol = eth_type_trans(skb, adapter->netdev); 228838df6492SMark Einon skb->ip_summed = CHECKSUM_NONE; 228938df6492SMark Einon netif_receive_skb(skb); 229038df6492SMark Einon 229138df6492SMark Einon out: 229238df6492SMark Einon nic_return_rfd(adapter, rfd); 229338df6492SMark Einon return rfd; 229438df6492SMark Einon } 229538df6492SMark Einon 229638df6492SMark Einon static int et131x_handle_recv_pkts(struct et131x_adapter *adapter, int budget) 229738df6492SMark Einon { 229838df6492SMark Einon struct rfd *rfd = NULL; 229938df6492SMark Einon int count = 0; 230038df6492SMark Einon int limit = budget; 230138df6492SMark Einon bool done = true; 230238df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 230338df6492SMark Einon 230438df6492SMark Einon if (budget > MAX_PACKETS_HANDLED) 230538df6492SMark Einon limit = MAX_PACKETS_HANDLED; 230638df6492SMark Einon 230738df6492SMark Einon /* Process up to available RFD's */ 230838df6492SMark Einon while (count < limit) { 230938df6492SMark Einon if (list_empty(&rx_ring->recv_list)) { 231038df6492SMark Einon WARN_ON(rx_ring->num_ready_recv != 0); 231138df6492SMark Einon done = false; 231238df6492SMark Einon break; 231338df6492SMark Einon } 231438df6492SMark Einon 231538df6492SMark Einon rfd = nic_rx_pkts(adapter); 231638df6492SMark Einon 231738df6492SMark Einon if (rfd == NULL) 231838df6492SMark Einon break; 231938df6492SMark Einon 232038df6492SMark Einon /* Do not receive any packets until a filter has been set. 232138df6492SMark Einon * Do not receive any packets until we have link. 232238df6492SMark Einon * If length is zero, return the RFD in order to advance the 232338df6492SMark Einon * Free buffer ring. 232438df6492SMark Einon */ 232538df6492SMark Einon if (!adapter->packet_filter || 232638df6492SMark Einon !netif_carrier_ok(adapter->netdev) || 232738df6492SMark Einon rfd->len == 0) 232838df6492SMark Einon continue; 232938df6492SMark Einon 233038df6492SMark Einon adapter->netdev->stats.rx_packets++; 233138df6492SMark Einon 233238df6492SMark Einon if (rx_ring->num_ready_recv < RFD_LOW_WATER_MARK) 233338df6492SMark Einon dev_warn(&adapter->pdev->dev, "RFD's are running out\n"); 233438df6492SMark Einon 233538df6492SMark Einon count++; 233638df6492SMark Einon } 233738df6492SMark Einon 233838df6492SMark Einon if (count == limit || !done) { 233938df6492SMark Einon rx_ring->unfinished_receives = true; 234038df6492SMark Einon writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, 234138df6492SMark Einon &adapter->regs->global.watchdog_timer); 234238df6492SMark Einon } else { 234338df6492SMark Einon /* Watchdog timer will disable itself if appropriate. */ 234438df6492SMark Einon rx_ring->unfinished_receives = false; 234538df6492SMark Einon } 234638df6492SMark Einon 234738df6492SMark Einon return count; 234838df6492SMark Einon } 234938df6492SMark Einon 235038df6492SMark Einon /* et131x_tx_dma_memory_alloc 235138df6492SMark Einon * 235238df6492SMark Einon * Allocates memory that will be visible both to the device and to the CPU. 235338df6492SMark Einon * The OS will pass us packets, pointers to which we will insert in the Tx 235438df6492SMark Einon * Descriptor queue. The device will read this queue to find the packets in 235538df6492SMark Einon * memory. The device will update the "status" in memory each time it xmits a 235638df6492SMark Einon * packet. 235738df6492SMark Einon */ 235838df6492SMark Einon static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter) 235938df6492SMark Einon { 236038df6492SMark Einon int desc_size = 0; 236138df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 236238df6492SMark Einon 236338df6492SMark Einon /* Allocate memory for the TCB's (Transmit Control Block) */ 236438df6492SMark Einon tx_ring->tcb_ring = kcalloc(NUM_TCB, sizeof(struct tcb), 236538df6492SMark Einon GFP_ATOMIC | GFP_DMA); 236638df6492SMark Einon if (!tx_ring->tcb_ring) 236738df6492SMark Einon return -ENOMEM; 236838df6492SMark Einon 236938df6492SMark Einon desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX); 237038df6492SMark Einon tx_ring->tx_desc_ring = dma_alloc_coherent(&adapter->pdev->dev, 237138df6492SMark Einon desc_size, 237238df6492SMark Einon &tx_ring->tx_desc_ring_pa, 237338df6492SMark Einon GFP_KERNEL); 237438df6492SMark Einon if (!tx_ring->tx_desc_ring) { 237538df6492SMark Einon dev_err(&adapter->pdev->dev, 237638df6492SMark Einon "Cannot alloc memory for Tx Ring\n"); 237738df6492SMark Einon return -ENOMEM; 237838df6492SMark Einon } 237938df6492SMark Einon 238038df6492SMark Einon tx_ring->tx_status = dma_alloc_coherent(&adapter->pdev->dev, 238138df6492SMark Einon sizeof(u32), 238238df6492SMark Einon &tx_ring->tx_status_pa, 238338df6492SMark Einon GFP_KERNEL); 2384562a9f91SInsu Yun if (!tx_ring->tx_status) { 238538df6492SMark Einon dev_err(&adapter->pdev->dev, 238638df6492SMark Einon "Cannot alloc memory for Tx status block\n"); 238738df6492SMark Einon return -ENOMEM; 238838df6492SMark Einon } 238938df6492SMark Einon return 0; 239038df6492SMark Einon } 239138df6492SMark Einon 239238df6492SMark Einon static void et131x_tx_dma_memory_free(struct et131x_adapter *adapter) 239338df6492SMark Einon { 239438df6492SMark Einon int desc_size = 0; 239538df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 239638df6492SMark Einon 239738df6492SMark Einon if (tx_ring->tx_desc_ring) { 239838df6492SMark Einon /* Free memory relating to Tx rings here */ 239938df6492SMark Einon desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX); 240038df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 240138df6492SMark Einon desc_size, 240238df6492SMark Einon tx_ring->tx_desc_ring, 240338df6492SMark Einon tx_ring->tx_desc_ring_pa); 240438df6492SMark Einon tx_ring->tx_desc_ring = NULL; 240538df6492SMark Einon } 240638df6492SMark Einon 240738df6492SMark Einon /* Free memory for the Tx status block */ 240838df6492SMark Einon if (tx_ring->tx_status) { 240938df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 241038df6492SMark Einon sizeof(u32), 241138df6492SMark Einon tx_ring->tx_status, 241238df6492SMark Einon tx_ring->tx_status_pa); 241338df6492SMark Einon 241438df6492SMark Einon tx_ring->tx_status = NULL; 241538df6492SMark Einon } 241638df6492SMark Einon /* Free the memory for the tcb structures */ 241738df6492SMark Einon kfree(tx_ring->tcb_ring); 241838df6492SMark Einon } 241938df6492SMark Einon 242038df6492SMark Einon /* nic_send_packet - NIC specific send handler for version B silicon. */ 242138df6492SMark Einon static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb) 242238df6492SMark Einon { 242338df6492SMark Einon u32 i; 242438df6492SMark Einon struct tx_desc desc[24]; 242538df6492SMark Einon u32 frag = 0; 242638df6492SMark Einon u32 thiscopy, remainder; 242738df6492SMark Einon struct sk_buff *skb = tcb->skb; 242838df6492SMark Einon u32 nr_frags = skb_shinfo(skb)->nr_frags + 1; 242938df6492SMark Einon struct skb_frag_struct *frags = &skb_shinfo(skb)->frags[0]; 2430a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 243138df6492SMark Einon dma_addr_t dma_addr; 243238df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 243338df6492SMark Einon 243438df6492SMark Einon /* Part of the optimizations of this send routine restrict us to 243538df6492SMark Einon * sending 24 fragments at a pass. In practice we should never see 243638df6492SMark Einon * more than 5 fragments. 243738df6492SMark Einon */ 243838df6492SMark Einon 243938df6492SMark Einon /* nr_frags should be no more than 18. */ 244038df6492SMark Einon BUILD_BUG_ON(MAX_SKB_FRAGS + 1 > 23); 244138df6492SMark Einon 244238df6492SMark Einon memset(desc, 0, sizeof(struct tx_desc) * (nr_frags + 1)); 244338df6492SMark Einon 244438df6492SMark Einon for (i = 0; i < nr_frags; i++) { 244538df6492SMark Einon /* If there is something in this element, lets get a 244638df6492SMark Einon * descriptor from the ring and get the necessary data 244738df6492SMark Einon */ 244838df6492SMark Einon if (i == 0) { 244938df6492SMark Einon /* If the fragments are smaller than a standard MTU, 245038df6492SMark Einon * then map them to a single descriptor in the Tx 245138df6492SMark Einon * Desc ring. However, if they're larger, as is 245238df6492SMark Einon * possible with support for jumbo packets, then 245338df6492SMark Einon * split them each across 2 descriptors. 245438df6492SMark Einon * 245538df6492SMark Einon * This will work until we determine why the hardware 245638df6492SMark Einon * doesn't seem to like large fragments. 245738df6492SMark Einon */ 245838df6492SMark Einon if (skb_headlen(skb) <= 1514) { 245938df6492SMark Einon /* Low 16bits are length, high is vlan and 246038df6492SMark Einon * unused currently so zero 246138df6492SMark Einon */ 246238df6492SMark Einon desc[frag].len_vlan = skb_headlen(skb); 246338df6492SMark Einon dma_addr = dma_map_single(&adapter->pdev->dev, 246438df6492SMark Einon skb->data, 246538df6492SMark Einon skb_headlen(skb), 246638df6492SMark Einon DMA_TO_DEVICE); 246738df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 246838df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 246938df6492SMark Einon frag++; 247038df6492SMark Einon } else { 247138df6492SMark Einon desc[frag].len_vlan = skb_headlen(skb) / 2; 247238df6492SMark Einon dma_addr = dma_map_single(&adapter->pdev->dev, 247338df6492SMark Einon skb->data, 247438df6492SMark Einon skb_headlen(skb) / 2, 247538df6492SMark Einon DMA_TO_DEVICE); 247638df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 247738df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 247838df6492SMark Einon frag++; 247938df6492SMark Einon 248038df6492SMark Einon desc[frag].len_vlan = skb_headlen(skb) / 2; 248138df6492SMark Einon dma_addr = dma_map_single(&adapter->pdev->dev, 248238df6492SMark Einon skb->data + 248338df6492SMark Einon skb_headlen(skb) / 2, 248438df6492SMark Einon skb_headlen(skb) / 2, 248538df6492SMark Einon DMA_TO_DEVICE); 248638df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 248738df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 248838df6492SMark Einon frag++; 248938df6492SMark Einon } 249038df6492SMark Einon } else { 249138df6492SMark Einon desc[frag].len_vlan = frags[i - 1].size; 249238df6492SMark Einon dma_addr = skb_frag_dma_map(&adapter->pdev->dev, 249338df6492SMark Einon &frags[i - 1], 249438df6492SMark Einon 0, 249538df6492SMark Einon frags[i - 1].size, 249638df6492SMark Einon DMA_TO_DEVICE); 249738df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 249838df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 249938df6492SMark Einon frag++; 250038df6492SMark Einon } 250138df6492SMark Einon } 250238df6492SMark Einon 250338df6492SMark Einon if (phydev && phydev->speed == SPEED_1000) { 250438df6492SMark Einon if (++tx_ring->since_irq == PARM_TX_NUM_BUFS_DEF) { 250538df6492SMark Einon /* Last element & Interrupt flag */ 250638df6492SMark Einon desc[frag - 1].flags = 250738df6492SMark Einon TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; 250838df6492SMark Einon tx_ring->since_irq = 0; 250938df6492SMark Einon } else { /* Last element */ 251038df6492SMark Einon desc[frag - 1].flags = TXDESC_FLAG_LASTPKT; 251138df6492SMark Einon } 251238df6492SMark Einon } else { 251338df6492SMark Einon desc[frag - 1].flags = 251438df6492SMark Einon TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; 251538df6492SMark Einon } 251638df6492SMark Einon 251738df6492SMark Einon desc[0].flags |= TXDESC_FLAG_FIRSTPKT; 251838df6492SMark Einon 251938df6492SMark Einon tcb->index_start = tx_ring->send_idx; 252038df6492SMark Einon tcb->stale = 0; 252138df6492SMark Einon 252238df6492SMark Einon thiscopy = NUM_DESC_PER_RING_TX - INDEX10(tx_ring->send_idx); 252338df6492SMark Einon 252438df6492SMark Einon if (thiscopy >= frag) { 252538df6492SMark Einon remainder = 0; 252638df6492SMark Einon thiscopy = frag; 252738df6492SMark Einon } else { 252838df6492SMark Einon remainder = frag - thiscopy; 252938df6492SMark Einon } 253038df6492SMark Einon 253138df6492SMark Einon memcpy(tx_ring->tx_desc_ring + INDEX10(tx_ring->send_idx), 253238df6492SMark Einon desc, 253338df6492SMark Einon sizeof(struct tx_desc) * thiscopy); 253438df6492SMark Einon 253538df6492SMark Einon add_10bit(&tx_ring->send_idx, thiscopy); 253638df6492SMark Einon 253738df6492SMark Einon if (INDEX10(tx_ring->send_idx) == 0 || 253838df6492SMark Einon INDEX10(tx_ring->send_idx) == NUM_DESC_PER_RING_TX) { 253938df6492SMark Einon tx_ring->send_idx &= ~ET_DMA10_MASK; 254038df6492SMark Einon tx_ring->send_idx ^= ET_DMA10_WRAP; 254138df6492SMark Einon } 254238df6492SMark Einon 254338df6492SMark Einon if (remainder) { 254438df6492SMark Einon memcpy(tx_ring->tx_desc_ring, 254538df6492SMark Einon desc + thiscopy, 254638df6492SMark Einon sizeof(struct tx_desc) * remainder); 254738df6492SMark Einon 254838df6492SMark Einon add_10bit(&tx_ring->send_idx, remainder); 254938df6492SMark Einon } 255038df6492SMark Einon 255138df6492SMark Einon if (INDEX10(tx_ring->send_idx) == 0) { 255238df6492SMark Einon if (tx_ring->send_idx) 255338df6492SMark Einon tcb->index = NUM_DESC_PER_RING_TX - 1; 255438df6492SMark Einon else 255538df6492SMark Einon tcb->index = ET_DMA10_WRAP|(NUM_DESC_PER_RING_TX - 1); 255638df6492SMark Einon } else { 255738df6492SMark Einon tcb->index = tx_ring->send_idx - 1; 255838df6492SMark Einon } 255938df6492SMark Einon 256038df6492SMark Einon spin_lock(&adapter->tcb_send_qlock); 256138df6492SMark Einon 256238df6492SMark Einon if (tx_ring->send_tail) 256338df6492SMark Einon tx_ring->send_tail->next = tcb; 256438df6492SMark Einon else 256538df6492SMark Einon tx_ring->send_head = tcb; 256638df6492SMark Einon 256738df6492SMark Einon tx_ring->send_tail = tcb; 256838df6492SMark Einon 256938df6492SMark Einon WARN_ON(tcb->next != NULL); 257038df6492SMark Einon 257138df6492SMark Einon tx_ring->used++; 257238df6492SMark Einon 257338df6492SMark Einon spin_unlock(&adapter->tcb_send_qlock); 257438df6492SMark Einon 257538df6492SMark Einon /* Write the new write pointer back to the device. */ 257638df6492SMark Einon writel(tx_ring->send_idx, &adapter->regs->txdma.service_request); 257738df6492SMark Einon 257838df6492SMark Einon /* For Gig only, we use Tx Interrupt coalescing. Enable the software 257938df6492SMark Einon * timer to wake us up if this packet isn't followed by N more. 258038df6492SMark Einon */ 258138df6492SMark Einon if (phydev && phydev->speed == SPEED_1000) { 258238df6492SMark Einon writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, 258338df6492SMark Einon &adapter->regs->global.watchdog_timer); 258438df6492SMark Einon } 258538df6492SMark Einon return 0; 258638df6492SMark Einon } 258738df6492SMark Einon 258838df6492SMark Einon static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter) 258938df6492SMark Einon { 259038df6492SMark Einon int status; 259138df6492SMark Einon struct tcb *tcb; 259238df6492SMark Einon unsigned long flags; 259338df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 259438df6492SMark Einon 259538df6492SMark Einon /* All packets must have at least a MAC address and a protocol type */ 259638df6492SMark Einon if (skb->len < ETH_HLEN) 259738df6492SMark Einon return -EIO; 259838df6492SMark Einon 259938df6492SMark Einon spin_lock_irqsave(&adapter->tcb_ready_qlock, flags); 260038df6492SMark Einon 260138df6492SMark Einon tcb = tx_ring->tcb_qhead; 260238df6492SMark Einon 260338df6492SMark Einon if (tcb == NULL) { 260438df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 260538df6492SMark Einon return -ENOMEM; 260638df6492SMark Einon } 260738df6492SMark Einon 260838df6492SMark Einon tx_ring->tcb_qhead = tcb->next; 260938df6492SMark Einon 261038df6492SMark Einon if (tx_ring->tcb_qhead == NULL) 261138df6492SMark Einon tx_ring->tcb_qtail = NULL; 261238df6492SMark Einon 261338df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 261438df6492SMark Einon 261538df6492SMark Einon tcb->skb = skb; 261638df6492SMark Einon tcb->next = NULL; 261738df6492SMark Einon 261838df6492SMark Einon status = nic_send_packet(adapter, tcb); 261938df6492SMark Einon 262038df6492SMark Einon if (status != 0) { 262138df6492SMark Einon spin_lock_irqsave(&adapter->tcb_ready_qlock, flags); 262238df6492SMark Einon 262338df6492SMark Einon if (tx_ring->tcb_qtail) 262438df6492SMark Einon tx_ring->tcb_qtail->next = tcb; 262538df6492SMark Einon else 262638df6492SMark Einon /* Apparently ready Q is empty. */ 262738df6492SMark Einon tx_ring->tcb_qhead = tcb; 262838df6492SMark Einon 262938df6492SMark Einon tx_ring->tcb_qtail = tcb; 263038df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 263138df6492SMark Einon return status; 263238df6492SMark Einon } 263338df6492SMark Einon WARN_ON(tx_ring->used > NUM_TCB); 263438df6492SMark Einon return 0; 263538df6492SMark Einon } 263638df6492SMark Einon 263738df6492SMark Einon /* free_send_packet - Recycle a struct tcb */ 263838df6492SMark Einon static inline void free_send_packet(struct et131x_adapter *adapter, 263938df6492SMark Einon struct tcb *tcb) 264038df6492SMark Einon { 264138df6492SMark Einon unsigned long flags; 264238df6492SMark Einon struct tx_desc *desc = NULL; 264338df6492SMark Einon struct net_device_stats *stats = &adapter->netdev->stats; 264438df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 264538df6492SMark Einon u64 dma_addr; 264638df6492SMark Einon 264738df6492SMark Einon if (tcb->skb) { 264838df6492SMark Einon stats->tx_bytes += tcb->skb->len; 264938df6492SMark Einon 265038df6492SMark Einon /* Iterate through the TX descriptors on the ring 265138df6492SMark Einon * corresponding to this packet and umap the fragments 265238df6492SMark Einon * they point to 265338df6492SMark Einon */ 265438df6492SMark Einon do { 265538df6492SMark Einon desc = tx_ring->tx_desc_ring + 265638df6492SMark Einon INDEX10(tcb->index_start); 265738df6492SMark Einon 265838df6492SMark Einon dma_addr = desc->addr_lo; 265938df6492SMark Einon dma_addr |= (u64)desc->addr_hi << 32; 266038df6492SMark Einon 266138df6492SMark Einon dma_unmap_single(&adapter->pdev->dev, 266238df6492SMark Einon dma_addr, 266338df6492SMark Einon desc->len_vlan, DMA_TO_DEVICE); 266438df6492SMark Einon 266538df6492SMark Einon add_10bit(&tcb->index_start, 1); 266638df6492SMark Einon if (INDEX10(tcb->index_start) >= 266738df6492SMark Einon NUM_DESC_PER_RING_TX) { 266838df6492SMark Einon tcb->index_start &= ~ET_DMA10_MASK; 266938df6492SMark Einon tcb->index_start ^= ET_DMA10_WRAP; 267038df6492SMark Einon } 267138df6492SMark Einon } while (desc != tx_ring->tx_desc_ring + INDEX10(tcb->index)); 267238df6492SMark Einon 267338df6492SMark Einon dev_kfree_skb_any(tcb->skb); 267438df6492SMark Einon } 267538df6492SMark Einon 267638df6492SMark Einon memset(tcb, 0, sizeof(struct tcb)); 267738df6492SMark Einon 267838df6492SMark Einon /* Add the TCB to the Ready Q */ 267938df6492SMark Einon spin_lock_irqsave(&adapter->tcb_ready_qlock, flags); 268038df6492SMark Einon 268138df6492SMark Einon stats->tx_packets++; 268238df6492SMark Einon 268338df6492SMark Einon if (tx_ring->tcb_qtail) 268438df6492SMark Einon tx_ring->tcb_qtail->next = tcb; 268538df6492SMark Einon else /* Apparently ready Q is empty. */ 268638df6492SMark Einon tx_ring->tcb_qhead = tcb; 268738df6492SMark Einon 268838df6492SMark Einon tx_ring->tcb_qtail = tcb; 268938df6492SMark Einon 269038df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 269138df6492SMark Einon WARN_ON(tx_ring->used < 0); 269238df6492SMark Einon } 269338df6492SMark Einon 269438df6492SMark Einon /* et131x_free_busy_send_packets - Free and complete the stopped active sends */ 269538df6492SMark Einon static void et131x_free_busy_send_packets(struct et131x_adapter *adapter) 269638df6492SMark Einon { 269738df6492SMark Einon struct tcb *tcb; 269838df6492SMark Einon unsigned long flags; 269938df6492SMark Einon u32 freed = 0; 270038df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 270138df6492SMark Einon 270238df6492SMark Einon /* Any packets being sent? Check the first TCB on the send list */ 270338df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 270438df6492SMark Einon 270538df6492SMark Einon tcb = tx_ring->send_head; 270638df6492SMark Einon 270738df6492SMark Einon while (tcb != NULL && freed < NUM_TCB) { 270838df6492SMark Einon struct tcb *next = tcb->next; 270938df6492SMark Einon 271038df6492SMark Einon tx_ring->send_head = next; 271138df6492SMark Einon 271238df6492SMark Einon if (next == NULL) 271338df6492SMark Einon tx_ring->send_tail = NULL; 271438df6492SMark Einon 271538df6492SMark Einon tx_ring->used--; 271638df6492SMark Einon 271738df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 271838df6492SMark Einon 271938df6492SMark Einon freed++; 272038df6492SMark Einon free_send_packet(adapter, tcb); 272138df6492SMark Einon 272238df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 272338df6492SMark Einon 272438df6492SMark Einon tcb = tx_ring->send_head; 272538df6492SMark Einon } 272638df6492SMark Einon 272738df6492SMark Einon WARN_ON(freed == NUM_TCB); 272838df6492SMark Einon 272938df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 273038df6492SMark Einon 273138df6492SMark Einon tx_ring->used = 0; 273238df6492SMark Einon } 273338df6492SMark Einon 273438df6492SMark Einon /* et131x_handle_send_pkts 273538df6492SMark Einon * 273638df6492SMark Einon * Re-claim the send resources, complete sends and get more to send from 273738df6492SMark Einon * the send wait queue. 273838df6492SMark Einon */ 273938df6492SMark Einon static void et131x_handle_send_pkts(struct et131x_adapter *adapter) 274038df6492SMark Einon { 274138df6492SMark Einon unsigned long flags; 274238df6492SMark Einon u32 serviced; 274338df6492SMark Einon struct tcb *tcb; 274438df6492SMark Einon u32 index; 274538df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 274638df6492SMark Einon 274738df6492SMark Einon serviced = readl(&adapter->regs->txdma.new_service_complete); 274838df6492SMark Einon index = INDEX10(serviced); 274938df6492SMark Einon 275038df6492SMark Einon /* Has the ring wrapped? Process any descriptors that do not have 275138df6492SMark Einon * the same "wrap" indicator as the current completion indicator 275238df6492SMark Einon */ 275338df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 275438df6492SMark Einon 275538df6492SMark Einon tcb = tx_ring->send_head; 275638df6492SMark Einon 275738df6492SMark Einon while (tcb && 275838df6492SMark Einon ((serviced ^ tcb->index) & ET_DMA10_WRAP) && 275938df6492SMark Einon index < INDEX10(tcb->index)) { 276038df6492SMark Einon tx_ring->used--; 276138df6492SMark Einon tx_ring->send_head = tcb->next; 276238df6492SMark Einon if (tcb->next == NULL) 276338df6492SMark Einon tx_ring->send_tail = NULL; 276438df6492SMark Einon 276538df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 276638df6492SMark Einon free_send_packet(adapter, tcb); 276738df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 276838df6492SMark Einon 276938df6492SMark Einon /* Goto the next packet */ 277038df6492SMark Einon tcb = tx_ring->send_head; 277138df6492SMark Einon } 277238df6492SMark Einon while (tcb && 277338df6492SMark Einon !((serviced ^ tcb->index) & ET_DMA10_WRAP) && 277438df6492SMark Einon index > (tcb->index & ET_DMA10_MASK)) { 277538df6492SMark Einon tx_ring->used--; 277638df6492SMark Einon tx_ring->send_head = tcb->next; 277738df6492SMark Einon if (tcb->next == NULL) 277838df6492SMark Einon tx_ring->send_tail = NULL; 277938df6492SMark Einon 278038df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 278138df6492SMark Einon free_send_packet(adapter, tcb); 278238df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 278338df6492SMark Einon 278438df6492SMark Einon /* Goto the next packet */ 278538df6492SMark Einon tcb = tx_ring->send_head; 278638df6492SMark Einon } 278738df6492SMark Einon 278838df6492SMark Einon /* Wake up the queue when we hit a low-water mark */ 278938df6492SMark Einon if (tx_ring->used <= NUM_TCB / 3) 279038df6492SMark Einon netif_wake_queue(adapter->netdev); 279138df6492SMark Einon 279238df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 279338df6492SMark Einon } 279438df6492SMark Einon 279538df6492SMark Einon static int et131x_get_regs_len(struct net_device *netdev) 279638df6492SMark Einon { 279738df6492SMark Einon #define ET131X_REGS_LEN 256 279838df6492SMark Einon return ET131X_REGS_LEN * sizeof(u32); 279938df6492SMark Einon } 280038df6492SMark Einon 280138df6492SMark Einon static void et131x_get_regs(struct net_device *netdev, 280238df6492SMark Einon struct ethtool_regs *regs, void *regs_data) 280338df6492SMark Einon { 280438df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 280538df6492SMark Einon struct address_map __iomem *aregs = adapter->regs; 280638df6492SMark Einon u32 *regs_buff = regs_data; 280738df6492SMark Einon u32 num = 0; 280838df6492SMark Einon u16 tmp; 280938df6492SMark Einon 281038df6492SMark Einon memset(regs_data, 0, et131x_get_regs_len(netdev)); 281138df6492SMark Einon 281238df6492SMark Einon regs->version = (1 << 24) | (adapter->pdev->revision << 16) | 281338df6492SMark Einon adapter->pdev->device; 281438df6492SMark Einon 281538df6492SMark Einon /* PHY regs */ 281638df6492SMark Einon et131x_mii_read(adapter, MII_BMCR, &tmp); 281738df6492SMark Einon regs_buff[num++] = tmp; 281838df6492SMark Einon et131x_mii_read(adapter, MII_BMSR, &tmp); 281938df6492SMark Einon regs_buff[num++] = tmp; 282038df6492SMark Einon et131x_mii_read(adapter, MII_PHYSID1, &tmp); 282138df6492SMark Einon regs_buff[num++] = tmp; 282238df6492SMark Einon et131x_mii_read(adapter, MII_PHYSID2, &tmp); 282338df6492SMark Einon regs_buff[num++] = tmp; 282438df6492SMark Einon et131x_mii_read(adapter, MII_ADVERTISE, &tmp); 282538df6492SMark Einon regs_buff[num++] = tmp; 282638df6492SMark Einon et131x_mii_read(adapter, MII_LPA, &tmp); 282738df6492SMark Einon regs_buff[num++] = tmp; 282838df6492SMark Einon et131x_mii_read(adapter, MII_EXPANSION, &tmp); 282938df6492SMark Einon regs_buff[num++] = tmp; 283038df6492SMark Einon /* Autoneg next page transmit reg */ 283138df6492SMark Einon et131x_mii_read(adapter, 0x07, &tmp); 283238df6492SMark Einon regs_buff[num++] = tmp; 283338df6492SMark Einon /* Link partner next page reg */ 283438df6492SMark Einon et131x_mii_read(adapter, 0x08, &tmp); 283538df6492SMark Einon regs_buff[num++] = tmp; 283638df6492SMark Einon et131x_mii_read(adapter, MII_CTRL1000, &tmp); 283738df6492SMark Einon regs_buff[num++] = tmp; 283838df6492SMark Einon et131x_mii_read(adapter, MII_STAT1000, &tmp); 283938df6492SMark Einon regs_buff[num++] = tmp; 284038df6492SMark Einon et131x_mii_read(adapter, 0x0b, &tmp); 284138df6492SMark Einon regs_buff[num++] = tmp; 284238df6492SMark Einon et131x_mii_read(adapter, 0x0c, &tmp); 284338df6492SMark Einon regs_buff[num++] = tmp; 284438df6492SMark Einon et131x_mii_read(adapter, MII_MMD_CTRL, &tmp); 284538df6492SMark Einon regs_buff[num++] = tmp; 284638df6492SMark Einon et131x_mii_read(adapter, MII_MMD_DATA, &tmp); 284738df6492SMark Einon regs_buff[num++] = tmp; 284838df6492SMark Einon et131x_mii_read(adapter, MII_ESTATUS, &tmp); 284938df6492SMark Einon regs_buff[num++] = tmp; 285038df6492SMark Einon 285138df6492SMark Einon et131x_mii_read(adapter, PHY_INDEX_REG, &tmp); 285238df6492SMark Einon regs_buff[num++] = tmp; 285338df6492SMark Einon et131x_mii_read(adapter, PHY_DATA_REG, &tmp); 285438df6492SMark Einon regs_buff[num++] = tmp; 285538df6492SMark Einon et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, &tmp); 285638df6492SMark Einon regs_buff[num++] = tmp; 285738df6492SMark Einon et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL, &tmp); 285838df6492SMark Einon regs_buff[num++] = tmp; 285938df6492SMark Einon et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL + 1, &tmp); 286038df6492SMark Einon regs_buff[num++] = tmp; 286138df6492SMark Einon 286238df6492SMark Einon et131x_mii_read(adapter, PHY_REGISTER_MGMT_CONTROL, &tmp); 286338df6492SMark Einon regs_buff[num++] = tmp; 286438df6492SMark Einon et131x_mii_read(adapter, PHY_CONFIG, &tmp); 286538df6492SMark Einon regs_buff[num++] = tmp; 286638df6492SMark Einon et131x_mii_read(adapter, PHY_PHY_CONTROL, &tmp); 286738df6492SMark Einon regs_buff[num++] = tmp; 286838df6492SMark Einon et131x_mii_read(adapter, PHY_INTERRUPT_MASK, &tmp); 286938df6492SMark Einon regs_buff[num++] = tmp; 287038df6492SMark Einon et131x_mii_read(adapter, PHY_INTERRUPT_STATUS, &tmp); 287138df6492SMark Einon regs_buff[num++] = tmp; 287238df6492SMark Einon et131x_mii_read(adapter, PHY_PHY_STATUS, &tmp); 287338df6492SMark Einon regs_buff[num++] = tmp; 287438df6492SMark Einon et131x_mii_read(adapter, PHY_LED_1, &tmp); 287538df6492SMark Einon regs_buff[num++] = tmp; 287638df6492SMark Einon et131x_mii_read(adapter, PHY_LED_2, &tmp); 287738df6492SMark Einon regs_buff[num++] = tmp; 287838df6492SMark Einon 287938df6492SMark Einon /* Global regs */ 288038df6492SMark Einon regs_buff[num++] = readl(&aregs->global.txq_start_addr); 288138df6492SMark Einon regs_buff[num++] = readl(&aregs->global.txq_end_addr); 288238df6492SMark Einon regs_buff[num++] = readl(&aregs->global.rxq_start_addr); 288338df6492SMark Einon regs_buff[num++] = readl(&aregs->global.rxq_end_addr); 288438df6492SMark Einon regs_buff[num++] = readl(&aregs->global.pm_csr); 288538df6492SMark Einon regs_buff[num++] = adapter->stats.interrupt_status; 288638df6492SMark Einon regs_buff[num++] = readl(&aregs->global.int_mask); 288738df6492SMark Einon regs_buff[num++] = readl(&aregs->global.int_alias_clr_en); 288838df6492SMark Einon regs_buff[num++] = readl(&aregs->global.int_status_alias); 288938df6492SMark Einon regs_buff[num++] = readl(&aregs->global.sw_reset); 289038df6492SMark Einon regs_buff[num++] = readl(&aregs->global.slv_timer); 289138df6492SMark Einon regs_buff[num++] = readl(&aregs->global.msi_config); 289238df6492SMark Einon regs_buff[num++] = readl(&aregs->global.loopback); 289338df6492SMark Einon regs_buff[num++] = readl(&aregs->global.watchdog_timer); 289438df6492SMark Einon 289538df6492SMark Einon /* TXDMA regs */ 289638df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.csr); 289738df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.pr_base_hi); 289838df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.pr_base_lo); 289938df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.pr_num_des); 290038df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.txq_wr_addr); 290138df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.txq_wr_addr_ext); 290238df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.txq_rd_addr); 290338df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.dma_wb_base_hi); 290438df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.dma_wb_base_lo); 290538df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.service_request); 290638df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.service_complete); 290738df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.cache_rd_index); 290838df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.cache_wr_index); 290938df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.tx_dma_error); 291038df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.desc_abort_cnt); 291138df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.payload_abort_cnt); 291238df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.writeback_abort_cnt); 291338df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.desc_timeout_cnt); 291438df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.payload_timeout_cnt); 291538df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.writeback_timeout_cnt); 291638df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.desc_error_cnt); 291738df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.payload_error_cnt); 291838df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.writeback_error_cnt); 291938df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.dropped_tlp_cnt); 292038df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.new_service_complete); 292138df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.ethernet_packet_cnt); 292238df6492SMark Einon 292338df6492SMark Einon /* RXDMA regs */ 292438df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.csr); 292538df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.dma_wb_base_hi); 292638df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.dma_wb_base_lo); 292738df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.num_pkt_done); 292838df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.max_pkt_time); 292938df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.rxq_rd_addr); 293038df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.rxq_rd_addr_ext); 293138df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.rxq_wr_addr); 293238df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_base_hi); 293338df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_base_lo); 293438df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_num_des); 293538df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_avail_offset); 293638df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_full_offset); 293738df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_access_index); 293838df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_min_des); 293938df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_base_lo); 294038df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_base_hi); 294138df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_num_des); 294238df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_avail_offset); 294338df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_full_offset); 294438df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_rd_index); 294538df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_min_des); 294638df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_base_lo); 294738df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_base_hi); 294838df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_num_des); 294938df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_avail_offset); 295038df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_full_offset); 295138df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_rd_index); 295238df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_min_des); 295338df6492SMark Einon } 295438df6492SMark Einon 295538df6492SMark Einon static void et131x_get_drvinfo(struct net_device *netdev, 295638df6492SMark Einon struct ethtool_drvinfo *info) 295738df6492SMark Einon { 295838df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 295938df6492SMark Einon 296038df6492SMark Einon strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver)); 296138df6492SMark Einon strlcpy(info->version, DRIVER_VERSION, sizeof(info->version)); 296238df6492SMark Einon strlcpy(info->bus_info, pci_name(adapter->pdev), 296338df6492SMark Einon sizeof(info->bus_info)); 296438df6492SMark Einon } 296538df6492SMark Einon 29661eff7002SJulia Lawall static const struct ethtool_ops et131x_ethtool_ops = { 296738df6492SMark Einon .get_drvinfo = et131x_get_drvinfo, 296838df6492SMark Einon .get_regs_len = et131x_get_regs_len, 296938df6492SMark Einon .get_regs = et131x_get_regs, 297038df6492SMark Einon .get_link = ethtool_op_get_link, 2971adc01582SPhilippe Reynes .get_link_ksettings = phy_ethtool_get_link_ksettings, 2972adc01582SPhilippe Reynes .set_link_ksettings = phy_ethtool_set_link_ksettings, 297338df6492SMark Einon }; 297438df6492SMark Einon 297538df6492SMark Einon /* et131x_hwaddr_init - set up the MAC Address */ 297638df6492SMark Einon static void et131x_hwaddr_init(struct et131x_adapter *adapter) 297738df6492SMark Einon { 297838df6492SMark Einon /* If have our default mac from init and no mac address from 297938df6492SMark Einon * EEPROM then we need to generate the last octet and set it on the 298038df6492SMark Einon * device 298138df6492SMark Einon */ 298238df6492SMark Einon if (is_zero_ether_addr(adapter->rom_addr)) { 298338df6492SMark Einon /* We need to randomly generate the last octet so we 298438df6492SMark Einon * decrease our chances of setting the mac address to 298538df6492SMark Einon * same as another one of our cards in the system 298638df6492SMark Einon */ 298738df6492SMark Einon get_random_bytes(&adapter->addr[5], 1); 298838df6492SMark Einon /* We have the default value in the register we are 298938df6492SMark Einon * working with so we need to copy the current 299038df6492SMark Einon * address into the permanent address 299138df6492SMark Einon */ 299238df6492SMark Einon ether_addr_copy(adapter->rom_addr, adapter->addr); 299338df6492SMark Einon } else { 299438df6492SMark Einon /* We do not have an override address, so set the 299538df6492SMark Einon * current address to the permanent address and add 299638df6492SMark Einon * it to the device 299738df6492SMark Einon */ 299838df6492SMark Einon ether_addr_copy(adapter->addr, adapter->rom_addr); 299938df6492SMark Einon } 300038df6492SMark Einon } 300138df6492SMark Einon 300238df6492SMark Einon static int et131x_pci_init(struct et131x_adapter *adapter, 300338df6492SMark Einon struct pci_dev *pdev) 300438df6492SMark Einon { 300538df6492SMark Einon u16 max_payload; 300638df6492SMark Einon int i, rc; 300738df6492SMark Einon 300838df6492SMark Einon rc = et131x_init_eeprom(adapter); 300938df6492SMark Einon if (rc < 0) 301038df6492SMark Einon goto out; 301138df6492SMark Einon 301238df6492SMark Einon if (!pci_is_pcie(pdev)) { 301338df6492SMark Einon dev_err(&pdev->dev, "Missing PCIe capabilities\n"); 301438df6492SMark Einon goto err_out; 301538df6492SMark Einon } 301638df6492SMark Einon 301738df6492SMark Einon /* Program the Ack/Nak latency and replay timers */ 301838df6492SMark Einon max_payload = pdev->pcie_mpss; 301938df6492SMark Einon 302038df6492SMark Einon if (max_payload < 2) { 302138df6492SMark Einon static const u16 acknak[2] = { 0x76, 0xD0 }; 302238df6492SMark Einon static const u16 replay[2] = { 0x1E0, 0x2ED }; 302338df6492SMark Einon 302438df6492SMark Einon if (pci_write_config_word(pdev, ET1310_PCI_ACK_NACK, 302538df6492SMark Einon acknak[max_payload])) { 302638df6492SMark Einon dev_err(&pdev->dev, 302738df6492SMark Einon "Could not write PCI config space for ACK/NAK\n"); 302838df6492SMark Einon goto err_out; 302938df6492SMark Einon } 303038df6492SMark Einon if (pci_write_config_word(pdev, ET1310_PCI_REPLAY, 303138df6492SMark Einon replay[max_payload])) { 303238df6492SMark Einon dev_err(&pdev->dev, 303338df6492SMark Einon "Could not write PCI config space for Replay Timer\n"); 303438df6492SMark Einon goto err_out; 303538df6492SMark Einon } 303638df6492SMark Einon } 303738df6492SMark Einon 303838df6492SMark Einon /* l0s and l1 latency timers. We are using default values. 303938df6492SMark Einon * Representing 001 for L0s and 010 for L1 304038df6492SMark Einon */ 304138df6492SMark Einon if (pci_write_config_byte(pdev, ET1310_PCI_L0L1LATENCY, 0x11)) { 304238df6492SMark Einon dev_err(&pdev->dev, 304338df6492SMark Einon "Could not write PCI config space for Latency Timers\n"); 304438df6492SMark Einon goto err_out; 304538df6492SMark Einon } 304638df6492SMark Einon 304738df6492SMark Einon /* Change the max read size to 2k */ 304838df6492SMark Einon if (pcie_set_readrq(pdev, 2048)) { 304938df6492SMark Einon dev_err(&pdev->dev, 305038df6492SMark Einon "Couldn't change PCI config space for Max read size\n"); 305138df6492SMark Einon goto err_out; 305238df6492SMark Einon } 305338df6492SMark Einon 305438df6492SMark Einon /* Get MAC address from config space if an eeprom exists, otherwise 305538df6492SMark Einon * the MAC address there will not be valid 305638df6492SMark Einon */ 305738df6492SMark Einon if (!adapter->has_eeprom) { 305838df6492SMark Einon et131x_hwaddr_init(adapter); 305938df6492SMark Einon return 0; 306038df6492SMark Einon } 306138df6492SMark Einon 306238df6492SMark Einon for (i = 0; i < ETH_ALEN; i++) { 306338df6492SMark Einon if (pci_read_config_byte(pdev, ET1310_PCI_MAC_ADDRESS + i, 306438df6492SMark Einon adapter->rom_addr + i)) { 306538df6492SMark Einon dev_err(&pdev->dev, "Could not read PCI config space for MAC address\n"); 306638df6492SMark Einon goto err_out; 306738df6492SMark Einon } 306838df6492SMark Einon } 306938df6492SMark Einon ether_addr_copy(adapter->addr, adapter->rom_addr); 307038df6492SMark Einon out: 307138df6492SMark Einon return rc; 307238df6492SMark Einon err_out: 307338df6492SMark Einon rc = -EIO; 307438df6492SMark Einon goto out; 307538df6492SMark Einon } 307638df6492SMark Einon 307738df6492SMark Einon /* et131x_error_timer_handler 307838df6492SMark Einon * @data: timer-specific variable; here a pointer to our adapter structure 307938df6492SMark Einon * 308038df6492SMark Einon * The routine called when the error timer expires, to track the number of 308138df6492SMark Einon * recurring errors. 308238df6492SMark Einon */ 3083*e99e88a9SKees Cook static void et131x_error_timer_handler(struct timer_list *t) 308438df6492SMark Einon { 3085*e99e88a9SKees Cook struct et131x_adapter *adapter = from_timer(adapter, t, error_timer); 3086a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 308738df6492SMark Einon 308838df6492SMark Einon if (et1310_in_phy_coma(adapter)) { 308938df6492SMark Einon /* Bring the device immediately out of coma, to 309038df6492SMark Einon * prevent it from sleeping indefinitely, this 309138df6492SMark Einon * mechanism could be improved! 309238df6492SMark Einon */ 309338df6492SMark Einon et1310_disable_phy_coma(adapter); 309438df6492SMark Einon adapter->boot_coma = 20; 309538df6492SMark Einon } else { 309638df6492SMark Einon et1310_update_macstat_host_counters(adapter); 309738df6492SMark Einon } 309838df6492SMark Einon 309938df6492SMark Einon if (!phydev->link && adapter->boot_coma < 11) 310038df6492SMark Einon adapter->boot_coma++; 310138df6492SMark Einon 310238df6492SMark Einon if (adapter->boot_coma == 10) { 310338df6492SMark Einon if (!phydev->link) { 310438df6492SMark Einon if (!et1310_in_phy_coma(adapter)) { 310538df6492SMark Einon /* NOTE - This was originally a 'sync with 310638df6492SMark Einon * interrupt'. How to do that under Linux? 310738df6492SMark Einon */ 310838df6492SMark Einon et131x_enable_interrupts(adapter); 310938df6492SMark Einon et1310_enable_phy_coma(adapter); 311038df6492SMark Einon } 311138df6492SMark Einon } 311238df6492SMark Einon } 311338df6492SMark Einon 311438df6492SMark Einon /* This is a periodic timer, so reschedule */ 3115bc2f3873SNicholas Mc Guire mod_timer(&adapter->error_timer, jiffies + 3116bc2f3873SNicholas Mc Guire msecs_to_jiffies(TX_ERROR_PERIOD)); 311738df6492SMark Einon } 311838df6492SMark Einon 311938df6492SMark Einon static void et131x_adapter_memory_free(struct et131x_adapter *adapter) 312038df6492SMark Einon { 312138df6492SMark Einon et131x_tx_dma_memory_free(adapter); 312238df6492SMark Einon et131x_rx_dma_memory_free(adapter); 312338df6492SMark Einon } 312438df6492SMark Einon 312538df6492SMark Einon static int et131x_adapter_memory_alloc(struct et131x_adapter *adapter) 312638df6492SMark Einon { 312738df6492SMark Einon int status; 312838df6492SMark Einon 312938df6492SMark Einon status = et131x_tx_dma_memory_alloc(adapter); 313038df6492SMark Einon if (status) { 313138df6492SMark Einon dev_err(&adapter->pdev->dev, 313238df6492SMark Einon "et131x_tx_dma_memory_alloc FAILED\n"); 313338df6492SMark Einon et131x_tx_dma_memory_free(adapter); 313438df6492SMark Einon return status; 313538df6492SMark Einon } 313638df6492SMark Einon 313738df6492SMark Einon status = et131x_rx_dma_memory_alloc(adapter); 313838df6492SMark Einon if (status) { 313938df6492SMark Einon dev_err(&adapter->pdev->dev, 314038df6492SMark Einon "et131x_rx_dma_memory_alloc FAILED\n"); 314138df6492SMark Einon et131x_adapter_memory_free(adapter); 314238df6492SMark Einon return status; 314338df6492SMark Einon } 314438df6492SMark Einon 314538df6492SMark Einon status = et131x_init_recv(adapter); 314638df6492SMark Einon if (status) { 314738df6492SMark Einon dev_err(&adapter->pdev->dev, "et131x_init_recv FAILED\n"); 314838df6492SMark Einon et131x_adapter_memory_free(adapter); 314938df6492SMark Einon } 315038df6492SMark Einon return status; 315138df6492SMark Einon } 315238df6492SMark Einon 315338df6492SMark Einon static void et131x_adjust_link(struct net_device *netdev) 315438df6492SMark Einon { 315538df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 3156a0bbb9feSPhilippe Reynes struct phy_device *phydev = netdev->phydev; 315738df6492SMark Einon 315838df6492SMark Einon if (!phydev) 315938df6492SMark Einon return; 316038df6492SMark Einon if (phydev->link == adapter->link) 316138df6492SMark Einon return; 316238df6492SMark Einon 316338df6492SMark Einon /* Check to see if we are in coma mode and if 316438df6492SMark Einon * so, disable it because we will not be able 316538df6492SMark Einon * to read PHY values until we are out. 316638df6492SMark Einon */ 316738df6492SMark Einon if (et1310_in_phy_coma(adapter)) 316838df6492SMark Einon et1310_disable_phy_coma(adapter); 316938df6492SMark Einon 317038df6492SMark Einon adapter->link = phydev->link; 317138df6492SMark Einon phy_print_status(phydev); 317238df6492SMark Einon 317338df6492SMark Einon if (phydev->link) { 317438df6492SMark Einon adapter->boot_coma = 20; 317538df6492SMark Einon if (phydev->speed == SPEED_10) { 317638df6492SMark Einon u16 register18; 317738df6492SMark Einon 317838df6492SMark Einon et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, 317938df6492SMark Einon ®ister18); 3180e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 318138df6492SMark Einon PHY_MPHY_CONTROL_REG, 318238df6492SMark Einon register18 | 0x4); 3183e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 3184e5a03bfdSAndrew Lunn PHY_INDEX_REG, register18 | 0x8402); 3185e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 3186e5a03bfdSAndrew Lunn PHY_DATA_REG, register18 | 511); 3187e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 318838df6492SMark Einon PHY_MPHY_CONTROL_REG, register18); 318938df6492SMark Einon } 319038df6492SMark Einon 319138df6492SMark Einon et1310_config_flow_control(adapter); 319238df6492SMark Einon 319338df6492SMark Einon if (phydev->speed == SPEED_1000 && 319438df6492SMark Einon adapter->registry_jumbo_packet > 2048) { 319538df6492SMark Einon u16 reg; 319638df6492SMark Einon 319738df6492SMark Einon et131x_mii_read(adapter, PHY_CONFIG, ®); 319838df6492SMark Einon reg &= ~ET_PHY_CONFIG_TX_FIFO_DEPTH; 319938df6492SMark Einon reg |= ET_PHY_CONFIG_FIFO_DEPTH_32; 3200e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 3201e5a03bfdSAndrew Lunn PHY_CONFIG, reg); 320238df6492SMark Einon } 320338df6492SMark Einon 320438df6492SMark Einon et131x_set_rx_dma_timer(adapter); 320538df6492SMark Einon et1310_config_mac_regs2(adapter); 320638df6492SMark Einon } else { 320738df6492SMark Einon adapter->boot_coma = 0; 320838df6492SMark Einon 320938df6492SMark Einon if (phydev->speed == SPEED_10) { 321038df6492SMark Einon u16 register18; 321138df6492SMark Einon 321238df6492SMark Einon et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, 321338df6492SMark Einon ®ister18); 3214e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 321538df6492SMark Einon PHY_MPHY_CONTROL_REG, 321638df6492SMark Einon register18 | 0x4); 3217e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 321838df6492SMark Einon PHY_INDEX_REG, register18 | 0x8402); 3219e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 322038df6492SMark Einon PHY_DATA_REG, register18 | 511); 3221e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 322238df6492SMark Einon PHY_MPHY_CONTROL_REG, register18); 322338df6492SMark Einon } 322438df6492SMark Einon 322538df6492SMark Einon et131x_free_busy_send_packets(adapter); 322638df6492SMark Einon et131x_init_send(adapter); 322738df6492SMark Einon 322838df6492SMark Einon /* Bring the device back to the state it was during 322938df6492SMark Einon * init prior to autonegotiation being complete. This 323038df6492SMark Einon * way, when we get the auto-neg complete interrupt, 323138df6492SMark Einon * we can complete init by calling config_mac_regs2. 323238df6492SMark Einon */ 323338df6492SMark Einon et131x_soft_reset(adapter); 323438df6492SMark Einon 323538df6492SMark Einon et131x_adapter_setup(adapter); 323638df6492SMark Einon 323738df6492SMark Einon et131x_disable_txrx(netdev); 323838df6492SMark Einon et131x_enable_txrx(netdev); 323938df6492SMark Einon } 324038df6492SMark Einon } 324138df6492SMark Einon 324238df6492SMark Einon static int et131x_mii_probe(struct net_device *netdev) 324338df6492SMark Einon { 324438df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 324538df6492SMark Einon struct phy_device *phydev = NULL; 324638df6492SMark Einon 324738df6492SMark Einon phydev = phy_find_first(adapter->mii_bus); 324838df6492SMark Einon if (!phydev) { 324938df6492SMark Einon dev_err(&adapter->pdev->dev, "no PHY found\n"); 325038df6492SMark Einon return -ENODEV; 325138df6492SMark Einon } 325238df6492SMark Einon 325384eff6d1SAndrew Lunn phydev = phy_connect(netdev, phydev_name(phydev), 325438df6492SMark Einon &et131x_adjust_link, PHY_INTERFACE_MODE_MII); 325538df6492SMark Einon 325638df6492SMark Einon if (IS_ERR(phydev)) { 325738df6492SMark Einon dev_err(&adapter->pdev->dev, "Could not attach to PHY\n"); 325838df6492SMark Einon return PTR_ERR(phydev); 325938df6492SMark Einon } 326038df6492SMark Einon 326138df6492SMark Einon phydev->supported &= (SUPPORTED_10baseT_Half | 326238df6492SMark Einon SUPPORTED_10baseT_Full | 326338df6492SMark Einon SUPPORTED_100baseT_Half | 326438df6492SMark Einon SUPPORTED_100baseT_Full | 326538df6492SMark Einon SUPPORTED_Autoneg | 326638df6492SMark Einon SUPPORTED_MII | 326738df6492SMark Einon SUPPORTED_TP); 326838df6492SMark Einon 326938df6492SMark Einon if (adapter->pdev->device != ET131X_PCI_DEVICE_ID_FAST) 327038df6492SMark Einon phydev->supported |= SUPPORTED_1000baseT_Half | 327138df6492SMark Einon SUPPORTED_1000baseT_Full; 327238df6492SMark Einon 327338df6492SMark Einon phydev->advertising = phydev->supported; 327438df6492SMark Einon phydev->autoneg = AUTONEG_ENABLE; 327538df6492SMark Einon 32762220943aSAndrew Lunn phy_attached_info(phydev); 327738df6492SMark Einon 327838df6492SMark Einon return 0; 327938df6492SMark Einon } 328038df6492SMark Einon 328138df6492SMark Einon static struct et131x_adapter *et131x_adapter_init(struct net_device *netdev, 328238df6492SMark Einon struct pci_dev *pdev) 328338df6492SMark Einon { 328438df6492SMark Einon static const u8 default_mac[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 }; 328538df6492SMark Einon 328638df6492SMark Einon struct et131x_adapter *adapter; 328738df6492SMark Einon 328838df6492SMark Einon adapter = netdev_priv(netdev); 328938df6492SMark Einon adapter->pdev = pci_dev_get(pdev); 329038df6492SMark Einon adapter->netdev = netdev; 329138df6492SMark Einon 329238df6492SMark Einon spin_lock_init(&adapter->tcb_send_qlock); 329338df6492SMark Einon spin_lock_init(&adapter->tcb_ready_qlock); 329438df6492SMark Einon spin_lock_init(&adapter->rcv_lock); 329538df6492SMark Einon 329638df6492SMark Einon adapter->registry_jumbo_packet = 1514; /* 1514-9216 */ 329738df6492SMark Einon 329838df6492SMark Einon ether_addr_copy(adapter->addr, default_mac); 329938df6492SMark Einon 330038df6492SMark Einon return adapter; 330138df6492SMark Einon } 330238df6492SMark Einon 330338df6492SMark Einon static void et131x_pci_remove(struct pci_dev *pdev) 330438df6492SMark Einon { 330538df6492SMark Einon struct net_device *netdev = pci_get_drvdata(pdev); 330638df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 330738df6492SMark Einon 330838df6492SMark Einon unregister_netdev(netdev); 330938df6492SMark Einon netif_napi_del(&adapter->napi); 3310a0bbb9feSPhilippe Reynes phy_disconnect(netdev->phydev); 331138df6492SMark Einon mdiobus_unregister(adapter->mii_bus); 331238df6492SMark Einon mdiobus_free(adapter->mii_bus); 331338df6492SMark Einon 331438df6492SMark Einon et131x_adapter_memory_free(adapter); 331538df6492SMark Einon iounmap(adapter->regs); 331638df6492SMark Einon pci_dev_put(pdev); 331738df6492SMark Einon 331838df6492SMark Einon free_netdev(netdev); 331938df6492SMark Einon pci_release_regions(pdev); 332038df6492SMark Einon pci_disable_device(pdev); 332138df6492SMark Einon } 332238df6492SMark Einon 332338df6492SMark Einon static void et131x_up(struct net_device *netdev) 332438df6492SMark Einon { 332538df6492SMark Einon et131x_enable_txrx(netdev); 3326a0bbb9feSPhilippe Reynes phy_start(netdev->phydev); 332738df6492SMark Einon } 332838df6492SMark Einon 332938df6492SMark Einon static void et131x_down(struct net_device *netdev) 333038df6492SMark Einon { 333138df6492SMark Einon /* Save the timestamp for the TX watchdog, prevent a timeout */ 3332860e9538SFlorian Westphal netif_trans_update(netdev); 333338df6492SMark Einon 3334a0bbb9feSPhilippe Reynes phy_stop(netdev->phydev); 333538df6492SMark Einon et131x_disable_txrx(netdev); 333638df6492SMark Einon } 333738df6492SMark Einon 333838df6492SMark Einon #ifdef CONFIG_PM_SLEEP 333938df6492SMark Einon static int et131x_suspend(struct device *dev) 334038df6492SMark Einon { 334138df6492SMark Einon struct pci_dev *pdev = to_pci_dev(dev); 334238df6492SMark Einon struct net_device *netdev = pci_get_drvdata(pdev); 334338df6492SMark Einon 334438df6492SMark Einon if (netif_running(netdev)) { 334538df6492SMark Einon netif_device_detach(netdev); 334638df6492SMark Einon et131x_down(netdev); 334738df6492SMark Einon pci_save_state(pdev); 334838df6492SMark Einon } 334938df6492SMark Einon 335038df6492SMark Einon return 0; 335138df6492SMark Einon } 335238df6492SMark Einon 335338df6492SMark Einon static int et131x_resume(struct device *dev) 335438df6492SMark Einon { 335538df6492SMark Einon struct pci_dev *pdev = to_pci_dev(dev); 335638df6492SMark Einon struct net_device *netdev = pci_get_drvdata(pdev); 335738df6492SMark Einon 335838df6492SMark Einon if (netif_running(netdev)) { 335938df6492SMark Einon pci_restore_state(pdev); 336038df6492SMark Einon et131x_up(netdev); 336138df6492SMark Einon netif_device_attach(netdev); 336238df6492SMark Einon } 336338df6492SMark Einon 336438df6492SMark Einon return 0; 336538df6492SMark Einon } 336638df6492SMark Einon #endif 336738df6492SMark Einon 336838df6492SMark Einon static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume); 336938df6492SMark Einon 337038df6492SMark Einon static irqreturn_t et131x_isr(int irq, void *dev_id) 337138df6492SMark Einon { 337238df6492SMark Einon bool handled = true; 337338df6492SMark Einon bool enable_interrupts = true; 337438df6492SMark Einon struct net_device *netdev = dev_id; 337538df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 337638df6492SMark Einon struct address_map __iomem *iomem = adapter->regs; 337738df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 337838df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 337938df6492SMark Einon u32 status; 338038df6492SMark Einon 338138df6492SMark Einon if (!netif_device_present(netdev)) { 338238df6492SMark Einon handled = false; 338338df6492SMark Einon enable_interrupts = false; 338438df6492SMark Einon goto out; 338538df6492SMark Einon } 338638df6492SMark Einon 338738df6492SMark Einon et131x_disable_interrupts(adapter); 338838df6492SMark Einon 338938df6492SMark Einon status = readl(&adapter->regs->global.int_status); 339038df6492SMark Einon 339138df6492SMark Einon if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) 339238df6492SMark Einon status &= ~INT_MASK_ENABLE; 339338df6492SMark Einon else 339438df6492SMark Einon status &= ~INT_MASK_ENABLE_NO_FLOW; 339538df6492SMark Einon 339638df6492SMark Einon /* Make sure this is our interrupt */ 339738df6492SMark Einon if (!status) { 339838df6492SMark Einon handled = false; 339938df6492SMark Einon et131x_enable_interrupts(adapter); 340038df6492SMark Einon goto out; 340138df6492SMark Einon } 340238df6492SMark Einon 340338df6492SMark Einon /* This is our interrupt, so process accordingly */ 340438df6492SMark Einon if (status & ET_INTR_WATCHDOG) { 340538df6492SMark Einon struct tcb *tcb = tx_ring->send_head; 340638df6492SMark Einon 340738df6492SMark Einon if (tcb) 340838df6492SMark Einon if (++tcb->stale > 1) 340938df6492SMark Einon status |= ET_INTR_TXDMA_ISR; 341038df6492SMark Einon 341138df6492SMark Einon if (rx_ring->unfinished_receives) 341238df6492SMark Einon status |= ET_INTR_RXDMA_XFR_DONE; 341338df6492SMark Einon else if (tcb == NULL) 341438df6492SMark Einon writel(0, &adapter->regs->global.watchdog_timer); 341538df6492SMark Einon 341638df6492SMark Einon status &= ~ET_INTR_WATCHDOG; 341738df6492SMark Einon } 341838df6492SMark Einon 341938df6492SMark Einon if (status & (ET_INTR_RXDMA_XFR_DONE | ET_INTR_TXDMA_ISR)) { 342038df6492SMark Einon enable_interrupts = false; 342138df6492SMark Einon napi_schedule(&adapter->napi); 342238df6492SMark Einon } 342338df6492SMark Einon 342438df6492SMark Einon status &= ~(ET_INTR_TXDMA_ISR | ET_INTR_RXDMA_XFR_DONE); 342538df6492SMark Einon 342638df6492SMark Einon if (!status) 342738df6492SMark Einon goto out; 342838df6492SMark Einon 342938df6492SMark Einon if (status & ET_INTR_TXDMA_ERR) { 343038df6492SMark Einon /* Following read also clears the register (COR) */ 343138df6492SMark Einon u32 txdma_err = readl(&iomem->txdma.tx_dma_error); 343238df6492SMark Einon 343338df6492SMark Einon dev_warn(&adapter->pdev->dev, 343438df6492SMark Einon "TXDMA_ERR interrupt, error = %d\n", 343538df6492SMark Einon txdma_err); 343638df6492SMark Einon } 343738df6492SMark Einon 343838df6492SMark Einon if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) { 343938df6492SMark Einon /* This indicates the number of unused buffers in RXDMA free 344038df6492SMark Einon * buffer ring 0 is <= the limit you programmed. Free buffer 344138df6492SMark Einon * resources need to be returned. Free buffers are consumed as 344238df6492SMark Einon * packets are passed from the network to the host. The host 344338df6492SMark Einon * becomes aware of the packets from the contents of the packet 344438df6492SMark Einon * status ring. This ring is queried when the packet done 344538df6492SMark Einon * interrupt occurs. Packets are then passed to the OS. When 344638df6492SMark Einon * the OS is done with the packets the resources can be 344738df6492SMark Einon * returned to the ET1310 for re-use. This interrupt is one 344838df6492SMark Einon * method of returning resources. 344938df6492SMark Einon */ 345038df6492SMark Einon 345138df6492SMark Einon /* If the user has flow control on, then we will 345238df6492SMark Einon * send a pause packet, otherwise just exit 345338df6492SMark Einon */ 345438df6492SMark Einon if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) { 345538df6492SMark Einon u32 pm_csr; 345638df6492SMark Einon 345738df6492SMark Einon /* Tell the device to send a pause packet via the back 345838df6492SMark Einon * pressure register (bp req and bp xon/xoff) 345938df6492SMark Einon */ 346038df6492SMark Einon pm_csr = readl(&iomem->global.pm_csr); 346138df6492SMark Einon if (!et1310_in_phy_coma(adapter)) 346238df6492SMark Einon writel(3, &iomem->txmac.bp_ctrl); 346338df6492SMark Einon } 346438df6492SMark Einon } 346538df6492SMark Einon 346638df6492SMark Einon /* Handle Packet Status Ring Low Interrupt */ 346738df6492SMark Einon if (status & ET_INTR_RXDMA_STAT_LOW) { 346838df6492SMark Einon /* Same idea as with the two Free Buffer Rings. Packets going 346938df6492SMark Einon * from the network to the host each consume a free buffer 347038df6492SMark Einon * resource and a packet status resource. These resources are 347138df6492SMark Einon * passed to the OS. When the OS is done with the resources, 347238df6492SMark Einon * they need to be returned to the ET1310. This is one method 347338df6492SMark Einon * of returning the resources. 347438df6492SMark Einon */ 347538df6492SMark Einon } 347638df6492SMark Einon 347738df6492SMark Einon if (status & ET_INTR_RXDMA_ERR) { 347838df6492SMark Einon /* The rxdma_error interrupt is sent when a time-out on a 347938df6492SMark Einon * request issued by the JAGCore has occurred or a completion is 348038df6492SMark Einon * returned with an un-successful status. In both cases the 348138df6492SMark Einon * request is considered complete. The JAGCore will 348238df6492SMark Einon * automatically re-try the request in question. Normally 348338df6492SMark Einon * information on events like these are sent to the host using 348438df6492SMark Einon * the "Advanced Error Reporting" capability. This interrupt is 348538df6492SMark Einon * another way of getting similar information. The only thing 348638df6492SMark Einon * required is to clear the interrupt by reading the ISR in the 348738df6492SMark Einon * global resources. The JAGCore will do a re-try on the 348838df6492SMark Einon * request. Normally you should never see this interrupt. If 348938df6492SMark Einon * you start to see this interrupt occurring frequently then 349038df6492SMark Einon * something bad has occurred. A reset might be the thing to do. 349138df6492SMark Einon */ 349238df6492SMark Einon /* TRAP();*/ 349338df6492SMark Einon 349438df6492SMark Einon dev_warn(&adapter->pdev->dev, "RxDMA_ERR interrupt, error %x\n", 349538df6492SMark Einon readl(&iomem->txmac.tx_test)); 349638df6492SMark Einon } 349738df6492SMark Einon 349838df6492SMark Einon /* Handle the Wake on LAN Event */ 349938df6492SMark Einon if (status & ET_INTR_WOL) { 350038df6492SMark Einon /* This is a secondary interrupt for wake on LAN. The driver 350138df6492SMark Einon * should never see this, if it does, something serious is 350238df6492SMark Einon * wrong. 350338df6492SMark Einon */ 350438df6492SMark Einon dev_err(&adapter->pdev->dev, "WAKE_ON_LAN interrupt\n"); 350538df6492SMark Einon } 350638df6492SMark Einon 350738df6492SMark Einon if (status & ET_INTR_TXMAC) { 350838df6492SMark Einon u32 err = readl(&iomem->txmac.err); 350938df6492SMark Einon 351038df6492SMark Einon /* When any of the errors occur and TXMAC generates an 351138df6492SMark Einon * interrupt to report these errors, it usually means that 351238df6492SMark Einon * TXMAC has detected an error in the data stream retrieved 351338df6492SMark Einon * from the on-chip Tx Q. All of these errors are catastrophic 351438df6492SMark Einon * and TXMAC won't be able to recover data when these errors 351538df6492SMark Einon * occur. In a nutshell, the whole Tx path will have to be reset 351638df6492SMark Einon * and re-configured afterwards. 351738df6492SMark Einon */ 351838df6492SMark Einon dev_warn(&adapter->pdev->dev, "TXMAC interrupt, error 0x%08x\n", 351938df6492SMark Einon err); 352038df6492SMark Einon 352138df6492SMark Einon /* If we are debugging, we want to see this error, otherwise we 352238df6492SMark Einon * just want the device to be reset and continue 352338df6492SMark Einon */ 352438df6492SMark Einon } 352538df6492SMark Einon 352638df6492SMark Einon if (status & ET_INTR_RXMAC) { 352738df6492SMark Einon /* These interrupts are catastrophic to the device, what we need 352838df6492SMark Einon * to do is disable the interrupts and set the flag to cause us 352938df6492SMark Einon * to reset so we can solve this issue. 353038df6492SMark Einon */ 353138df6492SMark Einon dev_warn(&adapter->pdev->dev, 353238df6492SMark Einon "RXMAC interrupt, error 0x%08x. Requesting reset\n", 353338df6492SMark Einon readl(&iomem->rxmac.err_reg)); 353438df6492SMark Einon 353538df6492SMark Einon dev_warn(&adapter->pdev->dev, 353638df6492SMark Einon "Enable 0x%08x, Diag 0x%08x\n", 353738df6492SMark Einon readl(&iomem->rxmac.ctrl), 353838df6492SMark Einon readl(&iomem->rxmac.rxq_diag)); 353938df6492SMark Einon 354038df6492SMark Einon /* If we are debugging, we want to see this error, otherwise we 354138df6492SMark Einon * just want the device to be reset and continue 354238df6492SMark Einon */ 354338df6492SMark Einon } 354438df6492SMark Einon 354538df6492SMark Einon if (status & ET_INTR_MAC_STAT) { 354638df6492SMark Einon /* This means at least one of the un-masked counters in the 354738df6492SMark Einon * MAC_STAT block has rolled over. Use this to maintain the top, 354838df6492SMark Einon * software managed bits of the counter(s). 354938df6492SMark Einon */ 355038df6492SMark Einon et1310_handle_macstat_interrupt(adapter); 355138df6492SMark Einon } 355238df6492SMark Einon 355338df6492SMark Einon if (status & ET_INTR_SLV_TIMEOUT) { 355438df6492SMark Einon /* This means a timeout has occurred on a read or write request 355538df6492SMark Einon * to one of the JAGCore registers. The Global Resources block 355638df6492SMark Einon * has terminated the request and on a read request, returned a 355738df6492SMark Einon * "fake" value. The most likely reasons are: Bad Address or the 355838df6492SMark Einon * addressed module is in a power-down state and can't respond. 355938df6492SMark Einon */ 356038df6492SMark Einon } 356138df6492SMark Einon 356238df6492SMark Einon out: 356338df6492SMark Einon if (enable_interrupts) 356438df6492SMark Einon et131x_enable_interrupts(adapter); 356538df6492SMark Einon 356638df6492SMark Einon return IRQ_RETVAL(handled); 356738df6492SMark Einon } 356838df6492SMark Einon 356938df6492SMark Einon static int et131x_poll(struct napi_struct *napi, int budget) 357038df6492SMark Einon { 357138df6492SMark Einon struct et131x_adapter *adapter = 357238df6492SMark Einon container_of(napi, struct et131x_adapter, napi); 357338df6492SMark Einon int work_done = et131x_handle_recv_pkts(adapter, budget); 357438df6492SMark Einon 357538df6492SMark Einon et131x_handle_send_pkts(adapter); 357638df6492SMark Einon 357738df6492SMark Einon if (work_done < budget) { 35786ad20165SEric Dumazet napi_complete_done(&adapter->napi, work_done); 357938df6492SMark Einon et131x_enable_interrupts(adapter); 358038df6492SMark Einon } 358138df6492SMark Einon 358238df6492SMark Einon return work_done; 358338df6492SMark Einon } 358438df6492SMark Einon 358538df6492SMark Einon /* et131x_stats - Return the current device statistics */ 358638df6492SMark Einon static struct net_device_stats *et131x_stats(struct net_device *netdev) 358738df6492SMark Einon { 358838df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 358938df6492SMark Einon struct net_device_stats *stats = &adapter->netdev->stats; 359038df6492SMark Einon struct ce_stats *devstat = &adapter->stats; 359138df6492SMark Einon 359238df6492SMark Einon stats->rx_errors = devstat->rx_length_errs + 359338df6492SMark Einon devstat->rx_align_errs + 359438df6492SMark Einon devstat->rx_crc_errs + 359538df6492SMark Einon devstat->rx_code_violations + 359638df6492SMark Einon devstat->rx_other_errs; 359738df6492SMark Einon stats->tx_errors = devstat->tx_max_pkt_errs; 359838df6492SMark Einon stats->multicast = devstat->multicast_pkts_rcvd; 359938df6492SMark Einon stats->collisions = devstat->tx_collisions; 360038df6492SMark Einon 360138df6492SMark Einon stats->rx_length_errors = devstat->rx_length_errs; 360238df6492SMark Einon stats->rx_over_errors = devstat->rx_overflows; 360338df6492SMark Einon stats->rx_crc_errors = devstat->rx_crc_errs; 360438df6492SMark Einon stats->rx_dropped = devstat->rcvd_pkts_dropped; 360538df6492SMark Einon 360638df6492SMark Einon /* NOTE: Not used, can't find analogous statistics */ 360738df6492SMark Einon /* stats->rx_frame_errors = devstat->; */ 360838df6492SMark Einon /* stats->rx_fifo_errors = devstat->; */ 360938df6492SMark Einon /* stats->rx_missed_errors = devstat->; */ 361038df6492SMark Einon 361138df6492SMark Einon /* stats->tx_aborted_errors = devstat->; */ 361238df6492SMark Einon /* stats->tx_carrier_errors = devstat->; */ 361338df6492SMark Einon /* stats->tx_fifo_errors = devstat->; */ 361438df6492SMark Einon /* stats->tx_heartbeat_errors = devstat->; */ 361538df6492SMark Einon /* stats->tx_window_errors = devstat->; */ 361638df6492SMark Einon return stats; 361738df6492SMark Einon } 361838df6492SMark Einon 361938df6492SMark Einon static int et131x_open(struct net_device *netdev) 362038df6492SMark Einon { 362138df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 362238df6492SMark Einon struct pci_dev *pdev = adapter->pdev; 362338df6492SMark Einon unsigned int irq = pdev->irq; 362438df6492SMark Einon int result; 362538df6492SMark Einon 362638df6492SMark Einon /* Start the timer to track NIC errors */ 3627*e99e88a9SKees Cook timer_setup(&adapter->error_timer, et131x_error_timer_handler, 0); 3628bc2f3873SNicholas Mc Guire adapter->error_timer.expires = jiffies + 3629bc2f3873SNicholas Mc Guire msecs_to_jiffies(TX_ERROR_PERIOD); 363038df6492SMark Einon add_timer(&adapter->error_timer); 363138df6492SMark Einon 363238df6492SMark Einon result = request_irq(irq, et131x_isr, 363338df6492SMark Einon IRQF_SHARED, netdev->name, netdev); 363438df6492SMark Einon if (result) { 363538df6492SMark Einon dev_err(&pdev->dev, "could not register IRQ %d\n", irq); 363638df6492SMark Einon return result; 363738df6492SMark Einon } 363838df6492SMark Einon 363938df6492SMark Einon adapter->flags |= FMP_ADAPTER_INTERRUPT_IN_USE; 364038df6492SMark Einon 364138df6492SMark Einon napi_enable(&adapter->napi); 364238df6492SMark Einon 364338df6492SMark Einon et131x_up(netdev); 364438df6492SMark Einon 364538df6492SMark Einon return result; 364638df6492SMark Einon } 364738df6492SMark Einon 364838df6492SMark Einon static int et131x_close(struct net_device *netdev) 364938df6492SMark Einon { 365038df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 365138df6492SMark Einon 365238df6492SMark Einon et131x_down(netdev); 365338df6492SMark Einon napi_disable(&adapter->napi); 365438df6492SMark Einon 365538df6492SMark Einon adapter->flags &= ~FMP_ADAPTER_INTERRUPT_IN_USE; 365638df6492SMark Einon free_irq(adapter->pdev->irq, netdev); 365738df6492SMark Einon 365838df6492SMark Einon /* Stop the error timer */ 365938df6492SMark Einon return del_timer_sync(&adapter->error_timer); 366038df6492SMark Einon } 366138df6492SMark Einon 366238df6492SMark Einon static int et131x_ioctl(struct net_device *netdev, struct ifreq *reqbuf, 366338df6492SMark Einon int cmd) 366438df6492SMark Einon { 3665a0bbb9feSPhilippe Reynes if (!netdev->phydev) 366638df6492SMark Einon return -EINVAL; 366738df6492SMark Einon 3668a0bbb9feSPhilippe Reynes return phy_mii_ioctl(netdev->phydev, reqbuf, cmd); 366938df6492SMark Einon } 367038df6492SMark Einon 367138df6492SMark Einon /* et131x_set_packet_filter - Configures the Rx Packet filtering */ 367238df6492SMark Einon static int et131x_set_packet_filter(struct et131x_adapter *adapter) 367338df6492SMark Einon { 367438df6492SMark Einon int filter = adapter->packet_filter; 367538df6492SMark Einon u32 ctrl; 367638df6492SMark Einon u32 pf_ctrl; 367738df6492SMark Einon 367838df6492SMark Einon ctrl = readl(&adapter->regs->rxmac.ctrl); 367938df6492SMark Einon pf_ctrl = readl(&adapter->regs->rxmac.pf_ctrl); 368038df6492SMark Einon 368138df6492SMark Einon /* Default to disabled packet filtering */ 368238df6492SMark Einon ctrl |= 0x04; 368338df6492SMark Einon 368438df6492SMark Einon /* Set us to be in promiscuous mode so we receive everything, this 368538df6492SMark Einon * is also true when we get a packet filter of 0 368638df6492SMark Einon */ 368738df6492SMark Einon if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) 368838df6492SMark Einon pf_ctrl &= ~7; /* Clear filter bits */ 368938df6492SMark Einon else { 369038df6492SMark Einon /* Set us up with Multicast packet filtering. Three cases are 369138df6492SMark Einon * possible - (1) we have a multi-cast list, (2) we receive ALL 369238df6492SMark Einon * multicast entries or (3) we receive none. 369338df6492SMark Einon */ 369438df6492SMark Einon if (filter & ET131X_PACKET_TYPE_ALL_MULTICAST) 369538df6492SMark Einon pf_ctrl &= ~2; /* Multicast filter bit */ 369638df6492SMark Einon else { 369738df6492SMark Einon et1310_setup_device_for_multicast(adapter); 369838df6492SMark Einon pf_ctrl |= 2; 369938df6492SMark Einon ctrl &= ~0x04; 370038df6492SMark Einon } 370138df6492SMark Einon 370238df6492SMark Einon /* Set us up with Unicast packet filtering */ 370338df6492SMark Einon if (filter & ET131X_PACKET_TYPE_DIRECTED) { 370438df6492SMark Einon et1310_setup_device_for_unicast(adapter); 370538df6492SMark Einon pf_ctrl |= 4; 370638df6492SMark Einon ctrl &= ~0x04; 370738df6492SMark Einon } 370838df6492SMark Einon 370938df6492SMark Einon /* Set us up with Broadcast packet filtering */ 371038df6492SMark Einon if (filter & ET131X_PACKET_TYPE_BROADCAST) { 371138df6492SMark Einon pf_ctrl |= 1; /* Broadcast filter bit */ 371238df6492SMark Einon ctrl &= ~0x04; 371338df6492SMark Einon } else { 371438df6492SMark Einon pf_ctrl &= ~1; 371538df6492SMark Einon } 371638df6492SMark Einon 371738df6492SMark Einon /* Setup the receive mac configuration registers - Packet 371838df6492SMark Einon * Filter control + the enable / disable for packet filter 371938df6492SMark Einon * in the control reg. 372038df6492SMark Einon */ 372138df6492SMark Einon writel(pf_ctrl, &adapter->regs->rxmac.pf_ctrl); 372238df6492SMark Einon writel(ctrl, &adapter->regs->rxmac.ctrl); 372338df6492SMark Einon } 372438df6492SMark Einon return 0; 372538df6492SMark Einon } 372638df6492SMark Einon 372738df6492SMark Einon static void et131x_multicast(struct net_device *netdev) 372838df6492SMark Einon { 372938df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 373038df6492SMark Einon int packet_filter; 373138df6492SMark Einon struct netdev_hw_addr *ha; 373238df6492SMark Einon int i; 373338df6492SMark Einon 373438df6492SMark Einon /* Before we modify the platform-independent filter flags, store them 373538df6492SMark Einon * locally. This allows us to determine if anything's changed and if 373638df6492SMark Einon * we even need to bother the hardware 373738df6492SMark Einon */ 373838df6492SMark Einon packet_filter = adapter->packet_filter; 373938df6492SMark Einon 374038df6492SMark Einon /* Clear the 'multicast' flag locally; because we only have a single 374138df6492SMark Einon * flag to check multicast, and multiple multicast addresses can be 374238df6492SMark Einon * set, this is the easiest way to determine if more than one 374338df6492SMark Einon * multicast address is being set. 374438df6492SMark Einon */ 374538df6492SMark Einon packet_filter &= ~ET131X_PACKET_TYPE_MULTICAST; 374638df6492SMark Einon 374738df6492SMark Einon /* Check the net_device flags and set the device independent flags 374838df6492SMark Einon * accordingly 374938df6492SMark Einon */ 375038df6492SMark Einon if (netdev->flags & IFF_PROMISC) 375138df6492SMark Einon adapter->packet_filter |= ET131X_PACKET_TYPE_PROMISCUOUS; 375238df6492SMark Einon else 375338df6492SMark Einon adapter->packet_filter &= ~ET131X_PACKET_TYPE_PROMISCUOUS; 375438df6492SMark Einon 375538df6492SMark Einon if ((netdev->flags & IFF_ALLMULTI) || 375638df6492SMark Einon (netdev_mc_count(netdev) > NIC_MAX_MCAST_LIST)) 375738df6492SMark Einon adapter->packet_filter |= ET131X_PACKET_TYPE_ALL_MULTICAST; 375838df6492SMark Einon 375938df6492SMark Einon if (netdev_mc_count(netdev) < 1) { 376038df6492SMark Einon adapter->packet_filter &= ~ET131X_PACKET_TYPE_ALL_MULTICAST; 376138df6492SMark Einon adapter->packet_filter &= ~ET131X_PACKET_TYPE_MULTICAST; 376238df6492SMark Einon } else { 376338df6492SMark Einon adapter->packet_filter |= ET131X_PACKET_TYPE_MULTICAST; 376438df6492SMark Einon } 376538df6492SMark Einon 376638df6492SMark Einon /* Set values in the private adapter struct */ 376738df6492SMark Einon i = 0; 376838df6492SMark Einon netdev_for_each_mc_addr(ha, netdev) { 376938df6492SMark Einon if (i == NIC_MAX_MCAST_LIST) 377038df6492SMark Einon break; 377138df6492SMark Einon ether_addr_copy(adapter->multicast_list[i++], ha->addr); 377238df6492SMark Einon } 377338df6492SMark Einon adapter->multicast_addr_count = i; 377438df6492SMark Einon 377538df6492SMark Einon /* Are the new flags different from the previous ones? If not, then no 377638df6492SMark Einon * action is required 377738df6492SMark Einon * 377838df6492SMark Einon * NOTE - This block will always update the multicast_list with the 377938df6492SMark Einon * hardware, even if the addresses aren't the same. 378038df6492SMark Einon */ 378138df6492SMark Einon if (packet_filter != adapter->packet_filter) 378238df6492SMark Einon et131x_set_packet_filter(adapter); 378338df6492SMark Einon } 378438df6492SMark Einon 378538df6492SMark Einon static netdev_tx_t et131x_tx(struct sk_buff *skb, struct net_device *netdev) 378638df6492SMark Einon { 378738df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 378838df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 378938df6492SMark Einon 379038df6492SMark Einon /* stop the queue if it's getting full */ 379138df6492SMark Einon if (tx_ring->used >= NUM_TCB - 1 && !netif_queue_stopped(netdev)) 379238df6492SMark Einon netif_stop_queue(netdev); 379338df6492SMark Einon 379438df6492SMark Einon /* Save the timestamp for the TX timeout watchdog */ 3795860e9538SFlorian Westphal netif_trans_update(netdev); 379638df6492SMark Einon 379738df6492SMark Einon /* TCB is not available */ 379838df6492SMark Einon if (tx_ring->used >= NUM_TCB) 379938df6492SMark Einon goto drop_err; 380038df6492SMark Einon 380138df6492SMark Einon if ((adapter->flags & FMP_ADAPTER_FAIL_SEND_MASK) || 380238df6492SMark Einon !netif_carrier_ok(netdev)) 380338df6492SMark Einon goto drop_err; 380438df6492SMark Einon 380538df6492SMark Einon if (send_packet(skb, adapter)) 380638df6492SMark Einon goto drop_err; 380738df6492SMark Einon 380838df6492SMark Einon return NETDEV_TX_OK; 380938df6492SMark Einon 381038df6492SMark Einon drop_err: 381138df6492SMark Einon dev_kfree_skb_any(skb); 381238df6492SMark Einon adapter->netdev->stats.tx_dropped++; 381338df6492SMark Einon return NETDEV_TX_OK; 381438df6492SMark Einon } 381538df6492SMark Einon 381638df6492SMark Einon /* et131x_tx_timeout - Timeout handler 381738df6492SMark Einon * 381838df6492SMark Einon * The handler called when a Tx request times out. The timeout period is 381938df6492SMark Einon * specified by the 'tx_timeo" element in the net_device structure (see 382038df6492SMark Einon * et131x_alloc_device() to see how this value is set). 382138df6492SMark Einon */ 382238df6492SMark Einon static void et131x_tx_timeout(struct net_device *netdev) 382338df6492SMark Einon { 382438df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 382538df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 382638df6492SMark Einon struct tcb *tcb; 382738df6492SMark Einon unsigned long flags; 382838df6492SMark Einon 382938df6492SMark Einon /* If the device is closed, ignore the timeout */ 3830de702da7SFlorian Fainelli if (!(adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE)) 383138df6492SMark Einon return; 383238df6492SMark Einon 383338df6492SMark Einon /* Any nonrecoverable hardware error? 383438df6492SMark Einon * Checks adapter->flags for any failure in phy reading 383538df6492SMark Einon */ 383638df6492SMark Einon if (adapter->flags & FMP_ADAPTER_NON_RECOVER_ERROR) 383738df6492SMark Einon return; 383838df6492SMark Einon 383938df6492SMark Einon /* Hardware failure? */ 384038df6492SMark Einon if (adapter->flags & FMP_ADAPTER_HARDWARE_ERROR) { 384138df6492SMark Einon dev_err(&adapter->pdev->dev, "hardware error - reset\n"); 384238df6492SMark Einon return; 384338df6492SMark Einon } 384438df6492SMark Einon 384538df6492SMark Einon /* Is send stuck? */ 384638df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 384738df6492SMark Einon tcb = tx_ring->send_head; 384838df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 384938df6492SMark Einon 385038df6492SMark Einon if (tcb) { 385138df6492SMark Einon tcb->count++; 385238df6492SMark Einon 385338df6492SMark Einon if (tcb->count > NIC_SEND_HANG_THRESHOLD) { 385438df6492SMark Einon dev_warn(&adapter->pdev->dev, 385538df6492SMark Einon "Send stuck - reset. tcb->WrIndex %x\n", 385638df6492SMark Einon tcb->index); 385738df6492SMark Einon 385838df6492SMark Einon adapter->netdev->stats.tx_errors++; 385938df6492SMark Einon 386038df6492SMark Einon /* perform reset of tx/rx */ 386138df6492SMark Einon et131x_disable_txrx(netdev); 386238df6492SMark Einon et131x_enable_txrx(netdev); 386338df6492SMark Einon } 386438df6492SMark Einon } 386538df6492SMark Einon } 386638df6492SMark Einon 386738df6492SMark Einon static int et131x_change_mtu(struct net_device *netdev, int new_mtu) 386838df6492SMark Einon { 386938df6492SMark Einon int result = 0; 387038df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 387138df6492SMark Einon 387238df6492SMark Einon et131x_disable_txrx(netdev); 387338df6492SMark Einon 387438df6492SMark Einon netdev->mtu = new_mtu; 387538df6492SMark Einon 387638df6492SMark Einon et131x_adapter_memory_free(adapter); 387738df6492SMark Einon 387838df6492SMark Einon /* Set the config parameter for Jumbo Packet support */ 387938df6492SMark Einon adapter->registry_jumbo_packet = new_mtu + 14; 388038df6492SMark Einon et131x_soft_reset(adapter); 388138df6492SMark Einon 388238df6492SMark Einon result = et131x_adapter_memory_alloc(adapter); 388338df6492SMark Einon if (result != 0) { 388438df6492SMark Einon dev_warn(&adapter->pdev->dev, 388538df6492SMark Einon "Change MTU failed; couldn't re-alloc DMA memory\n"); 388638df6492SMark Einon return result; 388738df6492SMark Einon } 388838df6492SMark Einon 388938df6492SMark Einon et131x_init_send(adapter); 389038df6492SMark Einon et131x_hwaddr_init(adapter); 389138df6492SMark Einon ether_addr_copy(netdev->dev_addr, adapter->addr); 389238df6492SMark Einon 389338df6492SMark Einon /* Init the device with the new settings */ 389438df6492SMark Einon et131x_adapter_setup(adapter); 389538df6492SMark Einon et131x_enable_txrx(netdev); 389638df6492SMark Einon 389738df6492SMark Einon return result; 389838df6492SMark Einon } 389938df6492SMark Einon 390038df6492SMark Einon static const struct net_device_ops et131x_netdev_ops = { 390138df6492SMark Einon .ndo_open = et131x_open, 390238df6492SMark Einon .ndo_stop = et131x_close, 390338df6492SMark Einon .ndo_start_xmit = et131x_tx, 390438df6492SMark Einon .ndo_set_rx_mode = et131x_multicast, 390538df6492SMark Einon .ndo_tx_timeout = et131x_tx_timeout, 390638df6492SMark Einon .ndo_change_mtu = et131x_change_mtu, 390738df6492SMark Einon .ndo_set_mac_address = eth_mac_addr, 390838df6492SMark Einon .ndo_validate_addr = eth_validate_addr, 390938df6492SMark Einon .ndo_get_stats = et131x_stats, 391038df6492SMark Einon .ndo_do_ioctl = et131x_ioctl, 391138df6492SMark Einon }; 391238df6492SMark Einon 391338df6492SMark Einon static int et131x_pci_setup(struct pci_dev *pdev, 391438df6492SMark Einon const struct pci_device_id *ent) 391538df6492SMark Einon { 391638df6492SMark Einon struct net_device *netdev; 391738df6492SMark Einon struct et131x_adapter *adapter; 391838df6492SMark Einon int rc; 391938df6492SMark Einon 392038df6492SMark Einon rc = pci_enable_device(pdev); 392138df6492SMark Einon if (rc < 0) { 392238df6492SMark Einon dev_err(&pdev->dev, "pci_enable_device() failed\n"); 392338df6492SMark Einon goto out; 392438df6492SMark Einon } 392538df6492SMark Einon 392638df6492SMark Einon /* Perform some basic PCI checks */ 392738df6492SMark Einon if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 392838df6492SMark Einon dev_err(&pdev->dev, "Can't find PCI device's base address\n"); 392938df6492SMark Einon rc = -ENODEV; 393038df6492SMark Einon goto err_disable; 393138df6492SMark Einon } 393238df6492SMark Einon 393338df6492SMark Einon rc = pci_request_regions(pdev, DRIVER_NAME); 393438df6492SMark Einon if (rc < 0) { 393538df6492SMark Einon dev_err(&pdev->dev, "Can't get PCI resources\n"); 393638df6492SMark Einon goto err_disable; 393738df6492SMark Einon } 393838df6492SMark Einon 393938df6492SMark Einon pci_set_master(pdev); 394038df6492SMark Einon 394138df6492SMark Einon /* Check the DMA addressing support of this device */ 394238df6492SMark Einon if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) && 394338df6492SMark Einon dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32))) { 394438df6492SMark Einon dev_err(&pdev->dev, "No usable DMA addressing method\n"); 394538df6492SMark Einon rc = -EIO; 394638df6492SMark Einon goto err_release_res; 394738df6492SMark Einon } 394838df6492SMark Einon 394938df6492SMark Einon netdev = alloc_etherdev(sizeof(struct et131x_adapter)); 395038df6492SMark Einon if (!netdev) { 395138df6492SMark Einon dev_err(&pdev->dev, "Couldn't alloc netdev struct\n"); 395238df6492SMark Einon rc = -ENOMEM; 395338df6492SMark Einon goto err_release_res; 395438df6492SMark Einon } 395538df6492SMark Einon 395638df6492SMark Einon netdev->watchdog_timeo = ET131X_TX_TIMEOUT; 395738df6492SMark Einon netdev->netdev_ops = &et131x_netdev_ops; 395844770e11SJarod Wilson netdev->min_mtu = ET131X_MIN_MTU; 395944770e11SJarod Wilson netdev->max_mtu = ET131X_MAX_MTU; 396038df6492SMark Einon 396138df6492SMark Einon SET_NETDEV_DEV(netdev, &pdev->dev); 396238df6492SMark Einon netdev->ethtool_ops = &et131x_ethtool_ops; 396338df6492SMark Einon 396438df6492SMark Einon adapter = et131x_adapter_init(netdev, pdev); 396538df6492SMark Einon 396638df6492SMark Einon rc = et131x_pci_init(adapter, pdev); 396738df6492SMark Einon if (rc < 0) 396838df6492SMark Einon goto err_free_dev; 396938df6492SMark Einon 397038df6492SMark Einon /* Map the bus-relative registers to system virtual memory */ 397138df6492SMark Einon adapter->regs = pci_ioremap_bar(pdev, 0); 397238df6492SMark Einon if (!adapter->regs) { 397338df6492SMark Einon dev_err(&pdev->dev, "Cannot map device registers\n"); 397438df6492SMark Einon rc = -ENOMEM; 397538df6492SMark Einon goto err_free_dev; 397638df6492SMark Einon } 397738df6492SMark Einon 397838df6492SMark Einon /* If Phy COMA mode was enabled when we went down, disable it here. */ 397938df6492SMark Einon writel(ET_PMCSR_INIT, &adapter->regs->global.pm_csr); 398038df6492SMark Einon 398138df6492SMark Einon et131x_soft_reset(adapter); 398238df6492SMark Einon et131x_disable_interrupts(adapter); 398338df6492SMark Einon 398438df6492SMark Einon rc = et131x_adapter_memory_alloc(adapter); 398538df6492SMark Einon if (rc < 0) { 398638df6492SMark Einon dev_err(&pdev->dev, "Could not alloc adapter memory (DMA)\n"); 398738df6492SMark Einon goto err_iounmap; 398838df6492SMark Einon } 398938df6492SMark Einon 399038df6492SMark Einon et131x_init_send(adapter); 399138df6492SMark Einon 399238df6492SMark Einon netif_napi_add(netdev, &adapter->napi, et131x_poll, 64); 399338df6492SMark Einon 399438df6492SMark Einon ether_addr_copy(netdev->dev_addr, adapter->addr); 399538df6492SMark Einon 399638df6492SMark Einon rc = -ENOMEM; 399738df6492SMark Einon 399838df6492SMark Einon adapter->mii_bus = mdiobus_alloc(); 399938df6492SMark Einon if (!adapter->mii_bus) { 400038df6492SMark Einon dev_err(&pdev->dev, "Alloc of mii_bus struct failed\n"); 400138df6492SMark Einon goto err_mem_free; 400238df6492SMark Einon } 400338df6492SMark Einon 400438df6492SMark Einon adapter->mii_bus->name = "et131x_eth_mii"; 400538df6492SMark Einon snprintf(adapter->mii_bus->id, MII_BUS_ID_SIZE, "%x", 400638df6492SMark Einon (adapter->pdev->bus->number << 8) | adapter->pdev->devfn); 400738df6492SMark Einon adapter->mii_bus->priv = netdev; 400838df6492SMark Einon adapter->mii_bus->read = et131x_mdio_read; 400938df6492SMark Einon adapter->mii_bus->write = et131x_mdio_write; 401038df6492SMark Einon 401138df6492SMark Einon rc = mdiobus_register(adapter->mii_bus); 401238df6492SMark Einon if (rc < 0) { 401338df6492SMark Einon dev_err(&pdev->dev, "failed to register MII bus\n"); 4014e7f4dc35SAndrew Lunn goto err_mdio_free; 401538df6492SMark Einon } 401638df6492SMark Einon 401738df6492SMark Einon rc = et131x_mii_probe(netdev); 401838df6492SMark Einon if (rc < 0) { 401938df6492SMark Einon dev_err(&pdev->dev, "failed to probe MII bus\n"); 402038df6492SMark Einon goto err_mdio_unregister; 402138df6492SMark Einon } 402238df6492SMark Einon 402338df6492SMark Einon et131x_adapter_setup(adapter); 402438df6492SMark Einon 402538df6492SMark Einon /* Init variable for counting how long we do not have link status */ 402638df6492SMark Einon adapter->boot_coma = 0; 402738df6492SMark Einon et1310_disable_phy_coma(adapter); 402838df6492SMark Einon 402938df6492SMark Einon /* We can enable interrupts now 403038df6492SMark Einon * 403138df6492SMark Einon * NOTE - Because registration of interrupt handler is done in the 403238df6492SMark Einon * device's open(), defer enabling device interrupts to that 403338df6492SMark Einon * point 403438df6492SMark Einon */ 403538df6492SMark Einon 403638df6492SMark Einon rc = register_netdev(netdev); 403738df6492SMark Einon if (rc < 0) { 403838df6492SMark Einon dev_err(&pdev->dev, "register_netdev() failed\n"); 403938df6492SMark Einon goto err_phy_disconnect; 404038df6492SMark Einon } 404138df6492SMark Einon 404238df6492SMark Einon /* Register the net_device struct with the PCI subsystem. Save a copy 404338df6492SMark Einon * of the PCI config space for this device now that the device has 404438df6492SMark Einon * been initialized, just in case it needs to be quickly restored. 404538df6492SMark Einon */ 404638df6492SMark Einon pci_set_drvdata(pdev, netdev); 404738df6492SMark Einon out: 404838df6492SMark Einon return rc; 404938df6492SMark Einon 405038df6492SMark Einon err_phy_disconnect: 4051a0bbb9feSPhilippe Reynes phy_disconnect(netdev->phydev); 405238df6492SMark Einon err_mdio_unregister: 405338df6492SMark Einon mdiobus_unregister(adapter->mii_bus); 405438df6492SMark Einon err_mdio_free: 405538df6492SMark Einon mdiobus_free(adapter->mii_bus); 405638df6492SMark Einon err_mem_free: 405738df6492SMark Einon et131x_adapter_memory_free(adapter); 405838df6492SMark Einon err_iounmap: 405938df6492SMark Einon iounmap(adapter->regs); 406038df6492SMark Einon err_free_dev: 406138df6492SMark Einon pci_dev_put(pdev); 406238df6492SMark Einon free_netdev(netdev); 406338df6492SMark Einon err_release_res: 406438df6492SMark Einon pci_release_regions(pdev); 406538df6492SMark Einon err_disable: 406638df6492SMark Einon pci_disable_device(pdev); 406738df6492SMark Einon goto out; 406838df6492SMark Einon } 406938df6492SMark Einon 407038df6492SMark Einon static const struct pci_device_id et131x_pci_table[] = { 407138df6492SMark Einon { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL}, 407238df6492SMark Einon { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL}, 407338df6492SMark Einon { 0,} 407438df6492SMark Einon }; 407538df6492SMark Einon MODULE_DEVICE_TABLE(pci, et131x_pci_table); 407638df6492SMark Einon 407738df6492SMark Einon static struct pci_driver et131x_driver = { 407838df6492SMark Einon .name = DRIVER_NAME, 407938df6492SMark Einon .id_table = et131x_pci_table, 408038df6492SMark Einon .probe = et131x_pci_setup, 408138df6492SMark Einon .remove = et131x_pci_remove, 408238df6492SMark Einon .driver.pm = &et131x_pm_ops, 408338df6492SMark Einon }; 408438df6492SMark Einon 408538df6492SMark Einon module_pci_driver(et131x_driver); 4086