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 */ 717ec161116SJason Yan adapter->has_eeprom = false; 71838df6492SMark Einon return -EIO; 71938df6492SMark Einon } 72038df6492SMark Einon } 721ec161116SJason Yan adapter->has_eeprom = true; 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 95438df6492SMark Einon /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision 95538df6492SMark Einon * the multi-cast LIST. If it is NOT specified, (and "ALL" is not 95638df6492SMark Einon * specified) then we should pass NO multi-cast addresses to the 95738df6492SMark Einon * driver. 95838df6492SMark Einon */ 95938df6492SMark Einon if (adapter->packet_filter & ET131X_PACKET_TYPE_MULTICAST) { 96038df6492SMark Einon int i; 96138df6492SMark Einon 96238df6492SMark Einon /* Loop through our multicast array and set up the device */ 96338df6492SMark Einon for (i = 0; i < adapter->multicast_addr_count; i++) { 96438df6492SMark Einon u32 result; 96538df6492SMark Einon 96638df6492SMark Einon result = ether_crc(6, adapter->multicast_list[i]); 96738df6492SMark Einon 96838df6492SMark Einon result = (result & 0x3F800000) >> 23; 96938df6492SMark Einon 97038df6492SMark Einon if (result < 32) { 97138df6492SMark Einon hash1 |= (1 << result); 97238df6492SMark Einon } else if ((31 < result) && (result < 64)) { 97338df6492SMark Einon result -= 32; 97438df6492SMark Einon hash2 |= (1 << result); 97538df6492SMark Einon } else if ((63 < result) && (result < 96)) { 97638df6492SMark Einon result -= 64; 97738df6492SMark Einon hash3 |= (1 << result); 97838df6492SMark Einon } else { 97938df6492SMark Einon result -= 96; 98038df6492SMark Einon hash4 |= (1 << result); 98138df6492SMark Einon } 98238df6492SMark Einon } 98338df6492SMark Einon } 98438df6492SMark Einon 98538df6492SMark Einon /* Write out the new hash to the device */ 98638df6492SMark Einon if (!et1310_in_phy_coma(adapter)) { 98738df6492SMark Einon writel(hash1, &rxmac->multi_hash1); 98838df6492SMark Einon writel(hash2, &rxmac->multi_hash2); 98938df6492SMark Einon writel(hash3, &rxmac->multi_hash3); 99038df6492SMark Einon writel(hash4, &rxmac->multi_hash4); 99138df6492SMark Einon } 99238df6492SMark Einon } 99338df6492SMark Einon 99438df6492SMark Einon static void et1310_setup_device_for_unicast(struct et131x_adapter *adapter) 99538df6492SMark Einon { 99638df6492SMark Einon struct rxmac_regs __iomem *rxmac = &adapter->regs->rxmac; 99738df6492SMark Einon u32 uni_pf1; 99838df6492SMark Einon u32 uni_pf2; 99938df6492SMark Einon u32 uni_pf3; 100038df6492SMark Einon 100138df6492SMark Einon /* Set up unicast packet filter reg 3 to be the first two octets of 100238df6492SMark Einon * the MAC address for both address 100338df6492SMark Einon * 100438df6492SMark Einon * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the 100538df6492SMark Einon * MAC address for second address 100638df6492SMark Einon * 100738df6492SMark Einon * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the 100838df6492SMark Einon * MAC address for first address 100938df6492SMark Einon */ 101038df6492SMark Einon uni_pf3 = (adapter->addr[0] << ET_RX_UNI_PF_ADDR2_1_SHIFT) | 101138df6492SMark Einon (adapter->addr[1] << ET_RX_UNI_PF_ADDR2_2_SHIFT) | 101238df6492SMark Einon (adapter->addr[0] << ET_RX_UNI_PF_ADDR1_1_SHIFT) | 101338df6492SMark Einon adapter->addr[1]; 101438df6492SMark Einon 101538df6492SMark Einon uni_pf2 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR2_3_SHIFT) | 101638df6492SMark Einon (adapter->addr[3] << ET_RX_UNI_PF_ADDR2_4_SHIFT) | 101738df6492SMark Einon (adapter->addr[4] << ET_RX_UNI_PF_ADDR2_5_SHIFT) | 101838df6492SMark Einon adapter->addr[5]; 101938df6492SMark Einon 102038df6492SMark Einon uni_pf1 = (adapter->addr[2] << ET_RX_UNI_PF_ADDR1_3_SHIFT) | 102138df6492SMark Einon (adapter->addr[3] << ET_RX_UNI_PF_ADDR1_4_SHIFT) | 102238df6492SMark Einon (adapter->addr[4] << ET_RX_UNI_PF_ADDR1_5_SHIFT) | 102338df6492SMark Einon adapter->addr[5]; 102438df6492SMark Einon 102538df6492SMark Einon if (!et1310_in_phy_coma(adapter)) { 102638df6492SMark Einon writel(uni_pf1, &rxmac->uni_pf_addr1); 102738df6492SMark Einon writel(uni_pf2, &rxmac->uni_pf_addr2); 102838df6492SMark Einon writel(uni_pf3, &rxmac->uni_pf_addr3); 102938df6492SMark Einon } 103038df6492SMark Einon } 103138df6492SMark Einon 103238df6492SMark Einon static void et1310_config_rxmac_regs(struct et131x_adapter *adapter) 103338df6492SMark Einon { 103438df6492SMark Einon struct rxmac_regs __iomem *rxmac = &adapter->regs->rxmac; 1035a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 103638df6492SMark Einon u32 sa_lo; 103738df6492SMark Einon u32 sa_hi = 0; 103838df6492SMark Einon u32 pf_ctrl = 0; 103938df6492SMark Einon u32 __iomem *wolw; 104038df6492SMark Einon 104138df6492SMark Einon /* Disable the MAC while it is being configured (also disable WOL) */ 104238df6492SMark Einon writel(0x8, &rxmac->ctrl); 104338df6492SMark Einon 104438df6492SMark Einon /* Initialize WOL to disabled. */ 104538df6492SMark Einon writel(0, &rxmac->crc0); 104638df6492SMark Einon writel(0, &rxmac->crc12); 104738df6492SMark Einon writel(0, &rxmac->crc34); 104838df6492SMark Einon 104938df6492SMark Einon /* We need to set the WOL mask0 - mask4 next. We initialize it to 105038df6492SMark Einon * its default Values of 0x00000000 because there are not WOL masks 105138df6492SMark Einon * as of this time. 105238df6492SMark Einon */ 105338df6492SMark Einon for (wolw = &rxmac->mask0_word0; wolw <= &rxmac->mask4_word3; wolw++) 105438df6492SMark Einon writel(0, wolw); 105538df6492SMark Einon 105638df6492SMark Einon /* Lets setup the WOL Source Address */ 105738df6492SMark Einon sa_lo = (adapter->addr[2] << ET_RX_WOL_LO_SA3_SHIFT) | 105838df6492SMark Einon (adapter->addr[3] << ET_RX_WOL_LO_SA4_SHIFT) | 105938df6492SMark Einon (adapter->addr[4] << ET_RX_WOL_LO_SA5_SHIFT) | 106038df6492SMark Einon adapter->addr[5]; 106138df6492SMark Einon writel(sa_lo, &rxmac->sa_lo); 106238df6492SMark Einon 106338df6492SMark Einon sa_hi = (u32)(adapter->addr[0] << ET_RX_WOL_HI_SA1_SHIFT) | 106438df6492SMark Einon adapter->addr[1]; 106538df6492SMark Einon writel(sa_hi, &rxmac->sa_hi); 106638df6492SMark Einon 106738df6492SMark Einon /* Disable all Packet Filtering */ 106838df6492SMark Einon writel(0, &rxmac->pf_ctrl); 106938df6492SMark Einon 107038df6492SMark Einon /* Let's initialize the Unicast Packet filtering address */ 107138df6492SMark Einon if (adapter->packet_filter & ET131X_PACKET_TYPE_DIRECTED) { 107238df6492SMark Einon et1310_setup_device_for_unicast(adapter); 107338df6492SMark Einon pf_ctrl |= ET_RX_PFCTRL_UNICST_FILTER_ENABLE; 107438df6492SMark Einon } else { 107538df6492SMark Einon writel(0, &rxmac->uni_pf_addr1); 107638df6492SMark Einon writel(0, &rxmac->uni_pf_addr2); 107738df6492SMark Einon writel(0, &rxmac->uni_pf_addr3); 107838df6492SMark Einon } 107938df6492SMark Einon 108038df6492SMark Einon /* Let's initialize the Multicast hash */ 108138df6492SMark Einon if (!(adapter->packet_filter & ET131X_PACKET_TYPE_ALL_MULTICAST)) { 108238df6492SMark Einon pf_ctrl |= ET_RX_PFCTRL_MLTCST_FILTER_ENABLE; 108338df6492SMark Einon et1310_setup_device_for_multicast(adapter); 108438df6492SMark Einon } 108538df6492SMark Einon 108638df6492SMark Einon /* Runt packet filtering. Didn't work in version A silicon. */ 108738df6492SMark Einon pf_ctrl |= (NIC_MIN_PACKET_SIZE + 4) << ET_RX_PFCTRL_MIN_PKT_SZ_SHIFT; 108838df6492SMark Einon pf_ctrl |= ET_RX_PFCTRL_FRAG_FILTER_ENABLE; 108938df6492SMark Einon 109038df6492SMark Einon if (adapter->registry_jumbo_packet > 8192) 109138df6492SMark Einon /* In order to transmit jumbo packets greater than 8k, the 109238df6492SMark Einon * FIFO between RxMAC and RxDMA needs to be reduced in size 109338df6492SMark Einon * to (16k - Jumbo packet size). In order to implement this, 109438df6492SMark Einon * we must use "cut through" mode in the RxMAC, which chops 109538df6492SMark Einon * packets down into segments which are (max_size * 16). In 109638df6492SMark Einon * this case we selected 256 bytes, since this is the size of 109738df6492SMark Einon * the PCI-Express TLP's that the 1310 uses. 109838df6492SMark Einon * 109938df6492SMark Einon * seg_en on, fc_en off, size 0x10 110038df6492SMark Einon */ 110138df6492SMark Einon writel(0x41, &rxmac->mcif_ctrl_max_seg); 110238df6492SMark Einon else 110338df6492SMark Einon writel(0, &rxmac->mcif_ctrl_max_seg); 110438df6492SMark Einon 110538df6492SMark Einon writel(0, &rxmac->mcif_water_mark); 110638df6492SMark Einon writel(0, &rxmac->mif_ctrl); 110738df6492SMark Einon writel(0, &rxmac->space_avail); 110838df6492SMark Einon 1109e3e2bad7SJilin Yuan /* Initialize the mif_ctrl register 111038df6492SMark Einon * bit 3: Receive code error. One or more nibbles were signaled as 111138df6492SMark Einon * errors during the reception of the packet. Clear this 111238df6492SMark Einon * bit in Gigabit, set it in 100Mbit. This was derived 111338df6492SMark Einon * experimentally at UNH. 111438df6492SMark Einon * bit 4: Receive CRC error. The packet's CRC did not match the 111538df6492SMark Einon * internally generated CRC. 111638df6492SMark Einon * bit 5: Receive length check error. Indicates that frame length 111738df6492SMark Einon * field value in the packet does not match the actual data 111838df6492SMark Einon * byte length and is not a type field. 111938df6492SMark Einon * bit 16: Receive frame truncated. 112038df6492SMark Einon * bit 17: Drop packet enable 112138df6492SMark Einon */ 112238df6492SMark Einon if (phydev && phydev->speed == SPEED_100) 112338df6492SMark Einon writel(0x30038, &rxmac->mif_ctrl); 112438df6492SMark Einon else 112538df6492SMark Einon writel(0x30030, &rxmac->mif_ctrl); 112638df6492SMark Einon 112738df6492SMark Einon /* Finally we initialize RxMac to be enabled & WOL disabled. Packet 112838df6492SMark Einon * filter is always enabled since it is where the runt packets are 112938df6492SMark Einon * supposed to be dropped. For version A silicon, runt packet 113038df6492SMark Einon * dropping doesn't work, so it is disabled in the pf_ctrl register, 113138df6492SMark Einon * but we still leave the packet filter on. 113238df6492SMark Einon */ 113338df6492SMark Einon writel(pf_ctrl, &rxmac->pf_ctrl); 113438df6492SMark Einon writel(ET_RX_CTRL_RXMAC_ENABLE | ET_RX_CTRL_WOL_DISABLE, &rxmac->ctrl); 113538df6492SMark Einon } 113638df6492SMark Einon 113738df6492SMark Einon static void et1310_config_txmac_regs(struct et131x_adapter *adapter) 113838df6492SMark Einon { 113938df6492SMark Einon struct txmac_regs __iomem *txmac = &adapter->regs->txmac; 114038df6492SMark Einon 114138df6492SMark Einon /* We need to update the Control Frame Parameters 114238df6492SMark Einon * cfpt - control frame pause timer set to 64 (0x40) 114338df6492SMark Einon * cfep - control frame extended pause timer set to 0x0 114438df6492SMark Einon */ 114538df6492SMark Einon if (adapter->flow == FLOW_NONE) 114638df6492SMark Einon writel(0, &txmac->cf_param); 114738df6492SMark Einon else 114838df6492SMark Einon writel(0x40, &txmac->cf_param); 114938df6492SMark Einon } 115038df6492SMark Einon 115138df6492SMark Einon static void et1310_config_macstat_regs(struct et131x_adapter *adapter) 115238df6492SMark Einon { 115338df6492SMark Einon struct macstat_regs __iomem *macstat = &adapter->regs->macstat; 115438df6492SMark Einon u32 __iomem *reg; 115538df6492SMark Einon 115638df6492SMark Einon /* initialize all the macstat registers to zero on the device */ 115738df6492SMark Einon for (reg = &macstat->txrx_0_64_byte_frames; 115838df6492SMark Einon reg <= &macstat->carry_reg2; reg++) 115938df6492SMark Einon writel(0, reg); 116038df6492SMark Einon 116138df6492SMark Einon /* Unmask any counters that we want to track the overflow of. 116238df6492SMark Einon * Initially this will be all counters. It may become clear later 116338df6492SMark Einon * that we do not need to track all counters. 116438df6492SMark Einon */ 116538df6492SMark Einon writel(0xFFFFBE32, &macstat->carry_reg1_mask); 116638df6492SMark Einon writel(0xFFFE7E8B, &macstat->carry_reg2_mask); 116738df6492SMark Einon } 116838df6492SMark Einon 116938df6492SMark Einon static int et131x_phy_mii_read(struct et131x_adapter *adapter, u8 addr, 117038df6492SMark Einon u8 reg, u16 *value) 117138df6492SMark Einon { 117238df6492SMark Einon struct mac_regs __iomem *mac = &adapter->regs->mac; 117338df6492SMark Einon int status = 0; 117438df6492SMark Einon u32 delay = 0; 117538df6492SMark Einon u32 mii_addr; 117638df6492SMark Einon u32 mii_cmd; 117738df6492SMark Einon u32 mii_indicator; 117838df6492SMark Einon 117938df6492SMark Einon /* Save a local copy of the registers we are dealing with so we can 118038df6492SMark Einon * set them back 118138df6492SMark Einon */ 118238df6492SMark Einon mii_addr = readl(&mac->mii_mgmt_addr); 118338df6492SMark Einon mii_cmd = readl(&mac->mii_mgmt_cmd); 118438df6492SMark Einon 118538df6492SMark Einon /* Stop the current operation */ 118638df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 118738df6492SMark Einon 118838df6492SMark Einon /* Set up the register we need to read from on the correct PHY */ 118938df6492SMark Einon writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr); 119038df6492SMark Einon 119138df6492SMark Einon writel(0x1, &mac->mii_mgmt_cmd); 119238df6492SMark Einon 119338df6492SMark Einon do { 119438df6492SMark Einon udelay(50); 119538df6492SMark Einon delay++; 119638df6492SMark Einon mii_indicator = readl(&mac->mii_mgmt_indicator); 119738df6492SMark Einon } while ((mii_indicator & ET_MAC_MGMT_WAIT) && delay < 50); 119838df6492SMark Einon 119938df6492SMark Einon /* If we hit the max delay, we could not read the register */ 120038df6492SMark Einon if (delay == 50) { 120138df6492SMark Einon dev_warn(&adapter->pdev->dev, 120238df6492SMark Einon "reg 0x%08x could not be read\n", reg); 120338df6492SMark Einon dev_warn(&adapter->pdev->dev, "status is 0x%08x\n", 120438df6492SMark Einon mii_indicator); 120538df6492SMark Einon 120638df6492SMark Einon status = -EIO; 120738df6492SMark Einon goto out; 120838df6492SMark Einon } 120938df6492SMark Einon 121038df6492SMark Einon /* If we hit here we were able to read the register and we need to 121138df6492SMark Einon * return the value to the caller 121238df6492SMark Einon */ 121338df6492SMark Einon *value = readl(&mac->mii_mgmt_stat) & ET_MAC_MIIMGMT_STAT_PHYCRTL_MASK; 121438df6492SMark Einon 121538df6492SMark Einon out: 121638df6492SMark Einon /* Stop the read operation */ 121738df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 121838df6492SMark Einon 121938df6492SMark Einon /* set the registers we touched back to the state at which we entered 122038df6492SMark Einon * this function 122138df6492SMark Einon */ 122238df6492SMark Einon writel(mii_addr, &mac->mii_mgmt_addr); 122338df6492SMark Einon writel(mii_cmd, &mac->mii_mgmt_cmd); 122438df6492SMark Einon 122538df6492SMark Einon return status; 122638df6492SMark Einon } 122738df6492SMark Einon 122838df6492SMark Einon static int et131x_mii_read(struct et131x_adapter *adapter, u8 reg, u16 *value) 122938df6492SMark Einon { 1230a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 123138df6492SMark Einon 123238df6492SMark Einon if (!phydev) 123338df6492SMark Einon return -EIO; 123438df6492SMark Einon 1235e5a03bfdSAndrew Lunn return et131x_phy_mii_read(adapter, phydev->mdio.addr, reg, value); 123638df6492SMark Einon } 123738df6492SMark Einon 123838df6492SMark Einon static int et131x_mii_write(struct et131x_adapter *adapter, u8 addr, u8 reg, 123938df6492SMark Einon u16 value) 124038df6492SMark Einon { 124138df6492SMark Einon struct mac_regs __iomem *mac = &adapter->regs->mac; 124238df6492SMark Einon int status = 0; 124338df6492SMark Einon u32 delay = 0; 124438df6492SMark Einon u32 mii_addr; 124538df6492SMark Einon u32 mii_cmd; 124638df6492SMark Einon u32 mii_indicator; 124738df6492SMark Einon 124838df6492SMark Einon /* Save a local copy of the registers we are dealing with so we can 124938df6492SMark Einon * set them back 125038df6492SMark Einon */ 125138df6492SMark Einon mii_addr = readl(&mac->mii_mgmt_addr); 125238df6492SMark Einon mii_cmd = readl(&mac->mii_mgmt_cmd); 125338df6492SMark Einon 125438df6492SMark Einon /* Stop the current operation */ 125538df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 125638df6492SMark Einon 125738df6492SMark Einon /* Set up the register we need to write to on the correct PHY */ 125838df6492SMark Einon writel(ET_MAC_MII_ADDR(addr, reg), &mac->mii_mgmt_addr); 125938df6492SMark Einon 126038df6492SMark Einon /* Add the value to write to the registers to the mac */ 126138df6492SMark Einon writel(value, &mac->mii_mgmt_ctrl); 126238df6492SMark Einon 126338df6492SMark Einon do { 126438df6492SMark Einon udelay(50); 126538df6492SMark Einon delay++; 126638df6492SMark Einon mii_indicator = readl(&mac->mii_mgmt_indicator); 126738df6492SMark Einon } while ((mii_indicator & ET_MAC_MGMT_BUSY) && delay < 100); 126838df6492SMark Einon 126938df6492SMark Einon /* If we hit the max delay, we could not write the register */ 127038df6492SMark Einon if (delay == 100) { 127138df6492SMark Einon u16 tmp; 127238df6492SMark Einon 127338df6492SMark Einon dev_warn(&adapter->pdev->dev, 127438df6492SMark Einon "reg 0x%08x could not be written", reg); 127538df6492SMark Einon dev_warn(&adapter->pdev->dev, "status is 0x%08x\n", 127638df6492SMark Einon mii_indicator); 127738df6492SMark Einon dev_warn(&adapter->pdev->dev, "command is 0x%08x\n", 127838df6492SMark Einon readl(&mac->mii_mgmt_cmd)); 127938df6492SMark Einon 128038df6492SMark Einon et131x_mii_read(adapter, reg, &tmp); 128138df6492SMark Einon 128238df6492SMark Einon status = -EIO; 128338df6492SMark Einon } 128438df6492SMark Einon /* Stop the write operation */ 128538df6492SMark Einon writel(0, &mac->mii_mgmt_cmd); 128638df6492SMark Einon 128738df6492SMark Einon /* set the registers we touched back to the state at which we entered 128838df6492SMark Einon * this function 128938df6492SMark Einon */ 129038df6492SMark Einon writel(mii_addr, &mac->mii_mgmt_addr); 129138df6492SMark Einon writel(mii_cmd, &mac->mii_mgmt_cmd); 129238df6492SMark Einon 129338df6492SMark Einon return status; 129438df6492SMark Einon } 129538df6492SMark Einon 129638df6492SMark Einon static void et1310_phy_read_mii_bit(struct et131x_adapter *adapter, 129738df6492SMark Einon u16 regnum, 129838df6492SMark Einon u16 bitnum, 129938df6492SMark Einon u8 *value) 130038df6492SMark Einon { 130138df6492SMark Einon u16 reg; 130238df6492SMark Einon u16 mask = 1 << bitnum; 130338df6492SMark Einon 130438df6492SMark Einon et131x_mii_read(adapter, regnum, ®); 130538df6492SMark Einon 130638df6492SMark Einon *value = (reg & mask) >> bitnum; 130738df6492SMark Einon } 130838df6492SMark Einon 130938df6492SMark Einon static void et1310_config_flow_control(struct et131x_adapter *adapter) 131038df6492SMark Einon { 1311a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 131238df6492SMark Einon 131338df6492SMark Einon if (phydev->duplex == DUPLEX_HALF) { 131438df6492SMark Einon adapter->flow = FLOW_NONE; 131538df6492SMark Einon } else { 131638df6492SMark Einon char remote_pause, remote_async_pause; 131738df6492SMark Einon 131838df6492SMark Einon et1310_phy_read_mii_bit(adapter, 5, 10, &remote_pause); 131938df6492SMark Einon et1310_phy_read_mii_bit(adapter, 5, 11, &remote_async_pause); 132038df6492SMark Einon 132138df6492SMark Einon if (remote_pause && remote_async_pause) { 132238df6492SMark Einon adapter->flow = adapter->wanted_flow; 132338df6492SMark Einon } else if (remote_pause && !remote_async_pause) { 132438df6492SMark Einon if (adapter->wanted_flow == FLOW_BOTH) 132538df6492SMark Einon adapter->flow = FLOW_BOTH; 132638df6492SMark Einon else 132738df6492SMark Einon adapter->flow = FLOW_NONE; 132838df6492SMark Einon } else if (!remote_pause && !remote_async_pause) { 132938df6492SMark Einon adapter->flow = FLOW_NONE; 133038df6492SMark Einon } else { 133138df6492SMark Einon if (adapter->wanted_flow == FLOW_BOTH) 133238df6492SMark Einon adapter->flow = FLOW_RXONLY; 133338df6492SMark Einon else 133438df6492SMark Einon adapter->flow = FLOW_NONE; 133538df6492SMark Einon } 133638df6492SMark Einon } 133738df6492SMark Einon } 133838df6492SMark Einon 133938df6492SMark Einon /* et1310_update_macstat_host_counters - Update local copy of the statistics */ 134038df6492SMark Einon static void et1310_update_macstat_host_counters(struct et131x_adapter *adapter) 134138df6492SMark Einon { 134238df6492SMark Einon struct ce_stats *stats = &adapter->stats; 134338df6492SMark Einon struct macstat_regs __iomem *macstat = 134438df6492SMark Einon &adapter->regs->macstat; 134538df6492SMark Einon 134638df6492SMark Einon stats->tx_collisions += readl(&macstat->tx_total_collisions); 134738df6492SMark Einon stats->tx_first_collisions += readl(&macstat->tx_single_collisions); 134838df6492SMark Einon stats->tx_deferred += readl(&macstat->tx_deferred); 134938df6492SMark Einon stats->tx_excessive_collisions += 135038df6492SMark Einon readl(&macstat->tx_multiple_collisions); 135138df6492SMark Einon stats->tx_late_collisions += readl(&macstat->tx_late_collisions); 135238df6492SMark Einon stats->tx_underflows += readl(&macstat->tx_undersize_frames); 135338df6492SMark Einon stats->tx_max_pkt_errs += readl(&macstat->tx_oversize_frames); 135438df6492SMark Einon 135538df6492SMark Einon stats->rx_align_errs += readl(&macstat->rx_align_errs); 135638df6492SMark Einon stats->rx_crc_errs += readl(&macstat->rx_code_errs); 135738df6492SMark Einon stats->rcvd_pkts_dropped += readl(&macstat->rx_drops); 135838df6492SMark Einon stats->rx_overflows += readl(&macstat->rx_oversize_packets); 135938df6492SMark Einon stats->rx_code_violations += readl(&macstat->rx_fcs_errs); 136038df6492SMark Einon stats->rx_length_errs += readl(&macstat->rx_frame_len_errs); 136138df6492SMark Einon stats->rx_other_errs += readl(&macstat->rx_fragment_packets); 136238df6492SMark Einon } 136338df6492SMark Einon 136438df6492SMark Einon /* et1310_handle_macstat_interrupt 136538df6492SMark Einon * 136638df6492SMark Einon * One of the MACSTAT counters has wrapped. Update the local copy of 136738df6492SMark Einon * the statistics held in the adapter structure, checking the "wrap" 136838df6492SMark Einon * bit for each counter. 136938df6492SMark Einon */ 137038df6492SMark Einon static void et1310_handle_macstat_interrupt(struct et131x_adapter *adapter) 137138df6492SMark Einon { 137238df6492SMark Einon u32 carry_reg1; 137338df6492SMark Einon u32 carry_reg2; 137438df6492SMark Einon 137538df6492SMark Einon /* Read the interrupt bits from the register(s). These are Clear On 137638df6492SMark Einon * Write. 137738df6492SMark Einon */ 137838df6492SMark Einon carry_reg1 = readl(&adapter->regs->macstat.carry_reg1); 137938df6492SMark Einon carry_reg2 = readl(&adapter->regs->macstat.carry_reg2); 138038df6492SMark Einon 138138df6492SMark Einon writel(carry_reg1, &adapter->regs->macstat.carry_reg1); 138238df6492SMark Einon writel(carry_reg2, &adapter->regs->macstat.carry_reg2); 138338df6492SMark Einon 138438df6492SMark Einon /* We need to do update the host copy of all the MAC_STAT counters. 138538df6492SMark Einon * For each counter, check it's overflow bit. If the overflow bit is 138638df6492SMark Einon * set, then increment the host version of the count by one complete 138738df6492SMark Einon * revolution of the counter. This routine is called when the counter 138838df6492SMark Einon * block indicates that one of the counters has wrapped. 138938df6492SMark Einon */ 139038df6492SMark Einon if (carry_reg1 & (1 << 14)) 139138df6492SMark Einon adapter->stats.rx_code_violations += COUNTER_WRAP_16_BIT; 139238df6492SMark Einon if (carry_reg1 & (1 << 8)) 139338df6492SMark Einon adapter->stats.rx_align_errs += COUNTER_WRAP_12_BIT; 139438df6492SMark Einon if (carry_reg1 & (1 << 7)) 139538df6492SMark Einon adapter->stats.rx_length_errs += COUNTER_WRAP_16_BIT; 139638df6492SMark Einon if (carry_reg1 & (1 << 2)) 139738df6492SMark Einon adapter->stats.rx_other_errs += COUNTER_WRAP_16_BIT; 139838df6492SMark Einon if (carry_reg1 & (1 << 6)) 139938df6492SMark Einon adapter->stats.rx_crc_errs += COUNTER_WRAP_16_BIT; 140038df6492SMark Einon if (carry_reg1 & (1 << 3)) 140138df6492SMark Einon adapter->stats.rx_overflows += COUNTER_WRAP_16_BIT; 140238df6492SMark Einon if (carry_reg1 & (1 << 0)) 140338df6492SMark Einon adapter->stats.rcvd_pkts_dropped += COUNTER_WRAP_16_BIT; 140438df6492SMark Einon if (carry_reg2 & (1 << 16)) 140538df6492SMark Einon adapter->stats.tx_max_pkt_errs += COUNTER_WRAP_12_BIT; 140638df6492SMark Einon if (carry_reg2 & (1 << 15)) 140738df6492SMark Einon adapter->stats.tx_underflows += COUNTER_WRAP_12_BIT; 140838df6492SMark Einon if (carry_reg2 & (1 << 6)) 140938df6492SMark Einon adapter->stats.tx_first_collisions += COUNTER_WRAP_12_BIT; 141038df6492SMark Einon if (carry_reg2 & (1 << 8)) 141138df6492SMark Einon adapter->stats.tx_deferred += COUNTER_WRAP_12_BIT; 141238df6492SMark Einon if (carry_reg2 & (1 << 5)) 141338df6492SMark Einon adapter->stats.tx_excessive_collisions += COUNTER_WRAP_12_BIT; 141438df6492SMark Einon if (carry_reg2 & (1 << 4)) 141538df6492SMark Einon adapter->stats.tx_late_collisions += COUNTER_WRAP_12_BIT; 141638df6492SMark Einon if (carry_reg2 & (1 << 2)) 141738df6492SMark Einon adapter->stats.tx_collisions += COUNTER_WRAP_12_BIT; 141838df6492SMark Einon } 141938df6492SMark Einon 142038df6492SMark Einon static int et131x_mdio_read(struct mii_bus *bus, int phy_addr, int reg) 142138df6492SMark Einon { 142238df6492SMark Einon struct net_device *netdev = bus->priv; 142338df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 142438df6492SMark Einon u16 value; 142538df6492SMark Einon int ret; 142638df6492SMark Einon 142738df6492SMark Einon ret = et131x_phy_mii_read(adapter, phy_addr, reg, &value); 142838df6492SMark Einon 142938df6492SMark Einon if (ret < 0) 143038df6492SMark Einon return ret; 143138df6492SMark Einon 143238df6492SMark Einon return value; 143338df6492SMark Einon } 143438df6492SMark Einon 143538df6492SMark Einon static int et131x_mdio_write(struct mii_bus *bus, int phy_addr, 143638df6492SMark Einon int reg, u16 value) 143738df6492SMark Einon { 143838df6492SMark Einon struct net_device *netdev = bus->priv; 143938df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 144038df6492SMark Einon 144138df6492SMark Einon return et131x_mii_write(adapter, phy_addr, reg, value); 144238df6492SMark Einon } 144338df6492SMark Einon 144438df6492SMark Einon /* et1310_phy_power_switch - PHY power control 144538df6492SMark Einon * @adapter: device to control 144638df6492SMark Einon * @down: true for off/false for back on 144738df6492SMark Einon * 144838df6492SMark Einon * one hundred, ten, one thousand megs 144938df6492SMark Einon * How would you like to have your LAN accessed 145038df6492SMark Einon * Can't you see that this code processed 145138df6492SMark Einon * Phy power, phy power.. 145238df6492SMark Einon */ 145338df6492SMark Einon static void et1310_phy_power_switch(struct et131x_adapter *adapter, bool down) 145438df6492SMark Einon { 145538df6492SMark Einon u16 data; 1456a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 145738df6492SMark Einon 145838df6492SMark Einon et131x_mii_read(adapter, MII_BMCR, &data); 145938df6492SMark Einon data &= ~BMCR_PDOWN; 146038df6492SMark Einon if (down) 146138df6492SMark Einon data |= BMCR_PDOWN; 1462e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, MII_BMCR, data); 146338df6492SMark Einon } 146438df6492SMark Einon 146538df6492SMark Einon /* et131x_xcvr_init - Init the phy if we are setting it into force mode */ 146638df6492SMark Einon static void et131x_xcvr_init(struct et131x_adapter *adapter) 146738df6492SMark Einon { 146838df6492SMark Einon u16 lcr2; 1469a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 147038df6492SMark Einon 147138df6492SMark Einon /* Set the LED behavior such that LED 1 indicates speed (off = 147238df6492SMark Einon * 10Mbits, blink = 100Mbits, on = 1000Mbits) and LED 2 indicates 147338df6492SMark Einon * link and activity (on for link, blink off for activity). 147438df6492SMark Einon * 147538df6492SMark Einon * NOTE: Some customizations have been added here for specific 147638df6492SMark Einon * vendors; The LED behavior is now determined by vendor data in the 147738df6492SMark Einon * EEPROM. However, the above description is the default. 147838df6492SMark Einon */ 147938df6492SMark Einon if ((adapter->eeprom_data[1] & 0x4) == 0) { 148038df6492SMark Einon et131x_mii_read(adapter, PHY_LED_2, &lcr2); 148138df6492SMark Einon 148238df6492SMark Einon lcr2 &= (ET_LED2_LED_100TX | ET_LED2_LED_1000T); 148338df6492SMark Einon lcr2 |= (LED_VAL_LINKON_ACTIVE << LED_LINK_SHIFT); 148438df6492SMark Einon 148538df6492SMark Einon if ((adapter->eeprom_data[1] & 0x8) == 0) 148638df6492SMark Einon lcr2 |= (LED_VAL_1000BT_100BTX << LED_TXRX_SHIFT); 148738df6492SMark Einon else 148838df6492SMark Einon lcr2 |= (LED_VAL_LINKON << LED_TXRX_SHIFT); 148938df6492SMark Einon 1490e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, PHY_LED_2, lcr2); 149138df6492SMark Einon } 149238df6492SMark Einon } 149338df6492SMark Einon 149438df6492SMark Einon /* et131x_configure_global_regs - configure JAGCore global regs */ 149538df6492SMark Einon static void et131x_configure_global_regs(struct et131x_adapter *adapter) 149638df6492SMark Einon { 149738df6492SMark Einon struct global_regs __iomem *regs = &adapter->regs->global; 149838df6492SMark Einon 149938df6492SMark Einon writel(0, ®s->rxq_start_addr); 150038df6492SMark Einon writel(INTERNAL_MEM_SIZE - 1, ®s->txq_end_addr); 150138df6492SMark Einon 150238df6492SMark Einon if (adapter->registry_jumbo_packet < 2048) { 150338df6492SMark Einon /* Tx / RxDMA and Tx/Rx MAC interfaces have a 1k word 150438df6492SMark Einon * block of RAM that the driver can split between Tx 150538df6492SMark Einon * and Rx as it desires. Our default is to split it 150638df6492SMark Einon * 50/50: 150738df6492SMark Einon */ 150838df6492SMark Einon writel(PARM_RX_MEM_END_DEF, ®s->rxq_end_addr); 150938df6492SMark Einon writel(PARM_RX_MEM_END_DEF + 1, ®s->txq_start_addr); 151038df6492SMark Einon } else if (adapter->registry_jumbo_packet < 8192) { 151138df6492SMark Einon /* For jumbo packets > 2k but < 8k, split 50-50. */ 151238df6492SMark Einon writel(INTERNAL_MEM_RX_OFFSET, ®s->rxq_end_addr); 151338df6492SMark Einon writel(INTERNAL_MEM_RX_OFFSET + 1, ®s->txq_start_addr); 151438df6492SMark Einon } else { 151538df6492SMark Einon /* 9216 is the only packet size greater than 8k that 151638df6492SMark Einon * is available. The Tx buffer has to be big enough 151738df6492SMark Einon * for one whole packet on the Tx side. We'll make 151838df6492SMark Einon * the Tx 9408, and give the rest to Rx 151938df6492SMark Einon */ 152038df6492SMark Einon writel(0x01b3, ®s->rxq_end_addr); 152138df6492SMark Einon writel(0x01b4, ®s->txq_start_addr); 152238df6492SMark Einon } 152338df6492SMark Einon 152438df6492SMark Einon /* Initialize the loopback register. Disable all loopbacks. */ 152538df6492SMark Einon writel(0, ®s->loopback); 152638df6492SMark Einon 152738df6492SMark Einon writel(0, ®s->msi_config); 152838df6492SMark Einon 152938df6492SMark Einon /* By default, disable the watchdog timer. It will be enabled when 153038df6492SMark Einon * a packet is queued. 153138df6492SMark Einon */ 153238df6492SMark Einon writel(0, ®s->watchdog_timer); 153338df6492SMark Einon } 153438df6492SMark Einon 153538df6492SMark Einon /* et131x_config_rx_dma_regs - Start of Rx_DMA init sequence */ 153638df6492SMark Einon static void et131x_config_rx_dma_regs(struct et131x_adapter *adapter) 153738df6492SMark Einon { 153838df6492SMark Einon struct rxdma_regs __iomem *rx_dma = &adapter->regs->rxdma; 153938df6492SMark Einon struct rx_ring *rx_local = &adapter->rx_ring; 154038df6492SMark Einon struct fbr_desc *fbr_entry; 154138df6492SMark Einon u32 entry; 154238df6492SMark Einon u32 psr_num_des; 154338df6492SMark Einon unsigned long flags; 154438df6492SMark Einon u8 id; 154538df6492SMark Einon 154638df6492SMark Einon et131x_rx_dma_disable(adapter); 154738df6492SMark Einon 154838df6492SMark Einon /* Load the completion writeback physical address */ 154938df6492SMark Einon writel(upper_32_bits(rx_local->rx_status_bus), &rx_dma->dma_wb_base_hi); 155038df6492SMark Einon writel(lower_32_bits(rx_local->rx_status_bus), &rx_dma->dma_wb_base_lo); 155138df6492SMark Einon 155238df6492SMark Einon memset(rx_local->rx_status_block, 0, sizeof(struct rx_status_block)); 155338df6492SMark Einon 155438df6492SMark Einon /* Set the address and parameters of the packet status ring */ 155538df6492SMark Einon writel(upper_32_bits(rx_local->ps_ring_physaddr), &rx_dma->psr_base_hi); 155638df6492SMark Einon writel(lower_32_bits(rx_local->ps_ring_physaddr), &rx_dma->psr_base_lo); 155738df6492SMark Einon writel(rx_local->psr_entries - 1, &rx_dma->psr_num_des); 155838df6492SMark Einon writel(0, &rx_dma->psr_full_offset); 155938df6492SMark Einon 156038df6492SMark Einon psr_num_des = readl(&rx_dma->psr_num_des) & ET_RXDMA_PSR_NUM_DES_MASK; 156138df6492SMark Einon writel((psr_num_des * LO_MARK_PERCENT_FOR_PSR) / 100, 156238df6492SMark Einon &rx_dma->psr_min_des); 156338df6492SMark Einon 156438df6492SMark Einon spin_lock_irqsave(&adapter->rcv_lock, flags); 156538df6492SMark Einon 156638df6492SMark Einon /* These local variables track the PSR in the adapter structure */ 156738df6492SMark Einon rx_local->local_psr_full = 0; 156838df6492SMark Einon 156938df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 157038df6492SMark Einon u32 __iomem *num_des; 157138df6492SMark Einon u32 __iomem *full_offset; 157238df6492SMark Einon u32 __iomem *min_des; 157338df6492SMark Einon u32 __iomem *base_hi; 157438df6492SMark Einon u32 __iomem *base_lo; 157538df6492SMark Einon struct fbr_lookup *fbr = rx_local->fbr[id]; 157638df6492SMark Einon 157738df6492SMark Einon if (id == 0) { 157838df6492SMark Einon num_des = &rx_dma->fbr0_num_des; 157938df6492SMark Einon full_offset = &rx_dma->fbr0_full_offset; 158038df6492SMark Einon min_des = &rx_dma->fbr0_min_des; 158138df6492SMark Einon base_hi = &rx_dma->fbr0_base_hi; 158238df6492SMark Einon base_lo = &rx_dma->fbr0_base_lo; 158338df6492SMark Einon } else { 158438df6492SMark Einon num_des = &rx_dma->fbr1_num_des; 158538df6492SMark Einon full_offset = &rx_dma->fbr1_full_offset; 158638df6492SMark Einon min_des = &rx_dma->fbr1_min_des; 158738df6492SMark Einon base_hi = &rx_dma->fbr1_base_hi; 158838df6492SMark Einon base_lo = &rx_dma->fbr1_base_lo; 158938df6492SMark Einon } 159038df6492SMark Einon 159138df6492SMark Einon /* Now's the best time to initialize FBR contents */ 159238df6492SMark Einon fbr_entry = fbr->ring_virtaddr; 159338df6492SMark Einon for (entry = 0; entry < fbr->num_entries; entry++) { 159438df6492SMark Einon fbr_entry->addr_hi = fbr->bus_high[entry]; 159538df6492SMark Einon fbr_entry->addr_lo = fbr->bus_low[entry]; 159638df6492SMark Einon fbr_entry->word2 = entry; 159738df6492SMark Einon fbr_entry++; 159838df6492SMark Einon } 159938df6492SMark Einon 160038df6492SMark Einon /* Set the address and parameters of Free buffer ring 1 and 0 */ 160138df6492SMark Einon writel(upper_32_bits(fbr->ring_physaddr), base_hi); 160238df6492SMark Einon writel(lower_32_bits(fbr->ring_physaddr), base_lo); 160338df6492SMark Einon writel(fbr->num_entries - 1, num_des); 160438df6492SMark Einon writel(ET_DMA10_WRAP, full_offset); 160538df6492SMark Einon 160638df6492SMark Einon /* This variable tracks the free buffer ring 1 full position, 160738df6492SMark Einon * so it has to match the above. 160838df6492SMark Einon */ 160938df6492SMark Einon fbr->local_full = ET_DMA10_WRAP; 161038df6492SMark Einon writel(((fbr->num_entries * LO_MARK_PERCENT_FOR_RX) / 100) - 1, 161138df6492SMark Einon min_des); 161238df6492SMark Einon } 161338df6492SMark Einon 161438df6492SMark Einon /* Program the number of packets we will receive before generating an 161538df6492SMark Einon * interrupt. 161638df6492SMark Einon * For version B silicon, this value gets updated once autoneg is 161738df6492SMark Einon *complete. 161838df6492SMark Einon */ 161938df6492SMark Einon writel(PARM_RX_NUM_BUFS_DEF, &rx_dma->num_pkt_done); 162038df6492SMark Einon 162138df6492SMark Einon /* The "time_done" is not working correctly to coalesce interrupts 162238df6492SMark Einon * after a given time period, but rather is giving us an interrupt 162338df6492SMark Einon * regardless of whether we have received packets. 162438df6492SMark Einon * This value gets updated once autoneg is complete. 162538df6492SMark Einon */ 162638df6492SMark Einon writel(PARM_RX_TIME_INT_DEF, &rx_dma->max_pkt_time); 162738df6492SMark Einon 162838df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 162938df6492SMark Einon } 163038df6492SMark Einon 163138df6492SMark Einon /* et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore. 163238df6492SMark Einon * 163338df6492SMark Einon * Configure the transmit engine with the ring buffers we have created 163438df6492SMark Einon * and prepare it for use. 163538df6492SMark Einon */ 163638df6492SMark Einon static void et131x_config_tx_dma_regs(struct et131x_adapter *adapter) 163738df6492SMark Einon { 163838df6492SMark Einon struct txdma_regs __iomem *txdma = &adapter->regs->txdma; 163938df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 164038df6492SMark Einon 164138df6492SMark Einon /* Load the hardware with the start of the transmit descriptor ring. */ 164238df6492SMark Einon writel(upper_32_bits(tx_ring->tx_desc_ring_pa), &txdma->pr_base_hi); 164338df6492SMark Einon writel(lower_32_bits(tx_ring->tx_desc_ring_pa), &txdma->pr_base_lo); 164438df6492SMark Einon 164538df6492SMark Einon /* Initialise the transmit DMA engine */ 164638df6492SMark Einon writel(NUM_DESC_PER_RING_TX - 1, &txdma->pr_num_des); 164738df6492SMark Einon 164838df6492SMark Einon /* Load the completion writeback physical address */ 164938df6492SMark Einon writel(upper_32_bits(tx_ring->tx_status_pa), &txdma->dma_wb_base_hi); 165038df6492SMark Einon writel(lower_32_bits(tx_ring->tx_status_pa), &txdma->dma_wb_base_lo); 165138df6492SMark Einon 165238df6492SMark Einon *tx_ring->tx_status = 0; 165338df6492SMark Einon 165438df6492SMark Einon writel(0, &txdma->service_request); 165538df6492SMark Einon tx_ring->send_idx = 0; 165638df6492SMark Einon } 165738df6492SMark Einon 165838df6492SMark Einon /* et131x_adapter_setup - Set the adapter up as per cassini+ documentation */ 165938df6492SMark Einon static void et131x_adapter_setup(struct et131x_adapter *adapter) 166038df6492SMark Einon { 166138df6492SMark Einon et131x_configure_global_regs(adapter); 166238df6492SMark Einon et1310_config_mac_regs1(adapter); 166338df6492SMark Einon 166438df6492SMark Einon /* Configure the MMC registers */ 166538df6492SMark Einon /* All we need to do is initialize the Memory Control Register */ 166638df6492SMark Einon writel(ET_MMC_ENABLE, &adapter->regs->mmc.mmc_ctrl); 166738df6492SMark Einon 166838df6492SMark Einon et1310_config_rxmac_regs(adapter); 166938df6492SMark Einon et1310_config_txmac_regs(adapter); 167038df6492SMark Einon 167138df6492SMark Einon et131x_config_rx_dma_regs(adapter); 167238df6492SMark Einon et131x_config_tx_dma_regs(adapter); 167338df6492SMark Einon 167438df6492SMark Einon et1310_config_macstat_regs(adapter); 167538df6492SMark Einon 167638df6492SMark Einon et1310_phy_power_switch(adapter, 0); 167738df6492SMark Einon et131x_xcvr_init(adapter); 167838df6492SMark Einon } 167938df6492SMark Einon 168038df6492SMark Einon /* et131x_soft_reset - Issue soft reset to the hardware, complete for ET1310 */ 168138df6492SMark Einon static void et131x_soft_reset(struct et131x_adapter *adapter) 168238df6492SMark Einon { 168338df6492SMark Einon u32 reg; 168438df6492SMark Einon 168538df6492SMark Einon /* Disable MAC Core */ 168638df6492SMark Einon reg = ET_MAC_CFG1_SOFT_RESET | ET_MAC_CFG1_SIM_RESET | 168738df6492SMark Einon ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | 168838df6492SMark Einon ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC; 168938df6492SMark Einon writel(reg, &adapter->regs->mac.cfg1); 169038df6492SMark Einon 169138df6492SMark Einon reg = ET_RESET_ALL; 169238df6492SMark Einon writel(reg, &adapter->regs->global.sw_reset); 169338df6492SMark Einon 169438df6492SMark Einon reg = ET_MAC_CFG1_RESET_RXMC | ET_MAC_CFG1_RESET_TXMC | 169538df6492SMark Einon ET_MAC_CFG1_RESET_RXFUNC | ET_MAC_CFG1_RESET_TXFUNC; 169638df6492SMark Einon writel(reg, &adapter->regs->mac.cfg1); 169738df6492SMark Einon writel(0, &adapter->regs->mac.cfg1); 169838df6492SMark Einon } 169938df6492SMark Einon 170038df6492SMark Einon static void et131x_enable_interrupts(struct et131x_adapter *adapter) 170138df6492SMark Einon { 170238df6492SMark Einon u32 mask; 170338df6492SMark Einon 170438df6492SMark Einon if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) 170538df6492SMark Einon mask = INT_MASK_ENABLE; 170638df6492SMark Einon else 170738df6492SMark Einon mask = INT_MASK_ENABLE_NO_FLOW; 170838df6492SMark Einon 170938df6492SMark Einon writel(mask, &adapter->regs->global.int_mask); 171038df6492SMark Einon } 171138df6492SMark Einon 171238df6492SMark Einon static void et131x_disable_interrupts(struct et131x_adapter *adapter) 171338df6492SMark Einon { 171438df6492SMark Einon writel(INT_MASK_DISABLE, &adapter->regs->global.int_mask); 171538df6492SMark Einon } 171638df6492SMark Einon 171738df6492SMark Einon static void et131x_tx_dma_disable(struct et131x_adapter *adapter) 171838df6492SMark Einon { 171938df6492SMark Einon /* Setup the transmit dma configuration register */ 172038df6492SMark Einon writel(ET_TXDMA_CSR_HALT | ET_TXDMA_SNGL_EPKT, 172138df6492SMark Einon &adapter->regs->txdma.csr); 172238df6492SMark Einon } 172338df6492SMark Einon 172438df6492SMark Einon static void et131x_enable_txrx(struct net_device *netdev) 172538df6492SMark Einon { 172638df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 172738df6492SMark Einon 172838df6492SMark Einon et131x_rx_dma_enable(adapter); 172938df6492SMark Einon et131x_tx_dma_enable(adapter); 173038df6492SMark Einon 173138df6492SMark Einon if (adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE) 173238df6492SMark Einon et131x_enable_interrupts(adapter); 173338df6492SMark Einon 173438df6492SMark Einon netif_start_queue(netdev); 173538df6492SMark Einon } 173638df6492SMark Einon 173738df6492SMark Einon static void et131x_disable_txrx(struct net_device *netdev) 173838df6492SMark Einon { 173938df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 174038df6492SMark Einon 174138df6492SMark Einon netif_stop_queue(netdev); 174238df6492SMark Einon 174338df6492SMark Einon et131x_rx_dma_disable(adapter); 174438df6492SMark Einon et131x_tx_dma_disable(adapter); 174538df6492SMark Einon 174638df6492SMark Einon et131x_disable_interrupts(adapter); 174738df6492SMark Einon } 174838df6492SMark Einon 174938df6492SMark Einon static void et131x_init_send(struct et131x_adapter *adapter) 175038df6492SMark Einon { 175138df6492SMark Einon int i; 175238df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 175338df6492SMark Einon struct tcb *tcb = tx_ring->tcb_ring; 175438df6492SMark Einon 175538df6492SMark Einon tx_ring->tcb_qhead = tcb; 175638df6492SMark Einon 175738df6492SMark Einon memset(tcb, 0, sizeof(struct tcb) * NUM_TCB); 175838df6492SMark Einon 175938df6492SMark Einon for (i = 0; i < NUM_TCB; i++) { 176038df6492SMark Einon tcb->next = tcb + 1; 176138df6492SMark Einon tcb++; 176238df6492SMark Einon } 176338df6492SMark Einon 176438df6492SMark Einon tcb--; 176538df6492SMark Einon tx_ring->tcb_qtail = tcb; 176638df6492SMark Einon tcb->next = NULL; 176738df6492SMark Einon /* Curr send queue should now be empty */ 176838df6492SMark Einon tx_ring->send_head = NULL; 176938df6492SMark Einon tx_ring->send_tail = NULL; 177038df6492SMark Einon } 177138df6492SMark Einon 177238df6492SMark Einon /* et1310_enable_phy_coma 177338df6492SMark Einon * 177438df6492SMark Einon * driver receive an phy status change interrupt while in D0 and check that 177538df6492SMark Einon * phy_status is down. 177638df6492SMark Einon * 177738df6492SMark Einon * -- gate off JAGCore; 177838df6492SMark Einon * -- set gigE PHY in Coma mode 177938df6492SMark Einon * -- wake on phy_interrupt; Perform software reset JAGCore, 178038df6492SMark Einon * re-initialize jagcore and gigE PHY 178138df6492SMark Einon */ 178238df6492SMark Einon static void et1310_enable_phy_coma(struct et131x_adapter *adapter) 178338df6492SMark Einon { 178438df6492SMark Einon u32 pmcsr = readl(&adapter->regs->global.pm_csr); 178538df6492SMark Einon 178638df6492SMark Einon /* Stop sending packets. */ 178738df6492SMark Einon adapter->flags |= FMP_ADAPTER_LOWER_POWER; 178838df6492SMark Einon 178938df6492SMark Einon /* Wait for outstanding Receive packets */ 179038df6492SMark Einon et131x_disable_txrx(adapter->netdev); 179138df6492SMark Einon 179238df6492SMark Einon /* Gate off JAGCore 3 clock domains */ 179338df6492SMark Einon pmcsr &= ~ET_PMCSR_INIT; 179438df6492SMark Einon writel(pmcsr, &adapter->regs->global.pm_csr); 179538df6492SMark Einon 179638df6492SMark Einon /* Program gigE PHY in to Coma mode */ 179738df6492SMark Einon pmcsr |= ET_PM_PHY_SW_COMA; 179838df6492SMark Einon writel(pmcsr, &adapter->regs->global.pm_csr); 179938df6492SMark Einon } 180038df6492SMark Einon 180138df6492SMark Einon static void et1310_disable_phy_coma(struct et131x_adapter *adapter) 180238df6492SMark Einon { 180338df6492SMark Einon u32 pmcsr; 180438df6492SMark Einon 180538df6492SMark Einon pmcsr = readl(&adapter->regs->global.pm_csr); 180638df6492SMark Einon 180738df6492SMark Einon /* Disable phy_sw_coma register and re-enable JAGCore clocks */ 180838df6492SMark Einon pmcsr |= ET_PMCSR_INIT; 180938df6492SMark Einon pmcsr &= ~ET_PM_PHY_SW_COMA; 181038df6492SMark Einon writel(pmcsr, &adapter->regs->global.pm_csr); 181138df6492SMark Einon 181238df6492SMark Einon /* Restore the GbE PHY speed and duplex modes; 181338df6492SMark Einon * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY 181438df6492SMark Einon */ 181538df6492SMark Einon 181638df6492SMark Einon /* Re-initialize the send structures */ 181738df6492SMark Einon et131x_init_send(adapter); 181838df6492SMark Einon 181938df6492SMark Einon /* Bring the device back to the state it was during init prior to 182038df6492SMark Einon * autonegotiation being complete. This way, when we get the auto-neg 182138df6492SMark Einon * complete interrupt, we can complete init by calling ConfigMacREGS2. 182238df6492SMark Einon */ 182338df6492SMark Einon et131x_soft_reset(adapter); 182438df6492SMark Einon 182538df6492SMark Einon et131x_adapter_setup(adapter); 182638df6492SMark Einon 182738df6492SMark Einon /* Allow Tx to restart */ 182838df6492SMark Einon adapter->flags &= ~FMP_ADAPTER_LOWER_POWER; 182938df6492SMark Einon 183038df6492SMark Einon et131x_enable_txrx(adapter->netdev); 183138df6492SMark Einon } 183238df6492SMark Einon 183338df6492SMark Einon static inline u32 bump_free_buff_ring(u32 *free_buff_ring, u32 limit) 183438df6492SMark Einon { 183538df6492SMark Einon u32 tmp_free_buff_ring = *free_buff_ring; 183638df6492SMark Einon 183738df6492SMark Einon tmp_free_buff_ring++; 183838df6492SMark Einon /* This works for all cases where limit < 1024. The 1023 case 183938df6492SMark Einon * works because 1023++ is 1024 which means the if condition is not 184038df6492SMark Einon * taken but the carry of the bit into the wrap bit toggles the wrap 184138df6492SMark Einon * value correctly 184238df6492SMark Einon */ 184338df6492SMark Einon if ((tmp_free_buff_ring & ET_DMA10_MASK) > limit) { 184438df6492SMark Einon tmp_free_buff_ring &= ~ET_DMA10_MASK; 184538df6492SMark Einon tmp_free_buff_ring ^= ET_DMA10_WRAP; 184638df6492SMark Einon } 184738df6492SMark Einon /* For the 1023 case */ 184838df6492SMark Einon tmp_free_buff_ring &= (ET_DMA10_MASK | ET_DMA10_WRAP); 184938df6492SMark Einon *free_buff_ring = tmp_free_buff_ring; 185038df6492SMark Einon return tmp_free_buff_ring; 185138df6492SMark Einon } 185238df6492SMark Einon 185338df6492SMark Einon /* et131x_rx_dma_memory_alloc 185438df6492SMark Einon * 185538df6492SMark Einon * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required, 185638df6492SMark Einon * and the Packet Status Ring. 185738df6492SMark Einon */ 185838df6492SMark Einon static int et131x_rx_dma_memory_alloc(struct et131x_adapter *adapter) 185938df6492SMark Einon { 186038df6492SMark Einon u8 id; 186138df6492SMark Einon u32 i, j; 186238df6492SMark Einon u32 bufsize; 186338df6492SMark Einon u32 psr_size; 186438df6492SMark Einon u32 fbr_chunksize; 186538df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 186638df6492SMark Einon struct fbr_lookup *fbr; 186738df6492SMark Einon 186838df6492SMark Einon /* Alloc memory for the lookup table */ 186938df6492SMark Einon rx_ring->fbr[0] = kzalloc(sizeof(*fbr), GFP_KERNEL); 187038df6492SMark Einon if (rx_ring->fbr[0] == NULL) 187138df6492SMark Einon return -ENOMEM; 187238df6492SMark Einon rx_ring->fbr[1] = kzalloc(sizeof(*fbr), GFP_KERNEL); 187338df6492SMark Einon if (rx_ring->fbr[1] == NULL) 187438df6492SMark Einon return -ENOMEM; 187538df6492SMark Einon 187638df6492SMark Einon /* The first thing we will do is configure the sizes of the buffer 187738df6492SMark Einon * rings. These will change based on jumbo packet support. Larger 187838df6492SMark Einon * jumbo packets increases the size of each entry in FBR0, and the 187938df6492SMark Einon * number of entries in FBR0, while at the same time decreasing the 188038df6492SMark Einon * number of entries in FBR1. 188138df6492SMark Einon * 188238df6492SMark Einon * FBR1 holds "large" frames, FBR0 holds "small" frames. If FBR1 188338df6492SMark Einon * entries are huge in order to accommodate a "jumbo" frame, then it 188438df6492SMark Einon * will have less entries. Conversely, FBR1 will now be relied upon 188538df6492SMark Einon * to carry more "normal" frames, thus it's entry size also increases 188638df6492SMark Einon * and the number of entries goes up too (since it now carries 188738df6492SMark Einon * "small" + "regular" packets. 188838df6492SMark Einon * 188938df6492SMark Einon * In this scheme, we try to maintain 512 entries between the two 189038df6492SMark Einon * rings. Also, FBR1 remains a constant size - when it's size doubles 189138df6492SMark Einon * the number of entries halves. FBR0 increases in size, however. 189238df6492SMark Einon */ 189338df6492SMark Einon if (adapter->registry_jumbo_packet < 2048) { 189438df6492SMark Einon rx_ring->fbr[0]->buffsize = 256; 189538df6492SMark Einon rx_ring->fbr[0]->num_entries = 512; 189638df6492SMark Einon rx_ring->fbr[1]->buffsize = 2048; 189738df6492SMark Einon rx_ring->fbr[1]->num_entries = 512; 189838df6492SMark Einon } else if (adapter->registry_jumbo_packet < 4096) { 189938df6492SMark Einon rx_ring->fbr[0]->buffsize = 512; 190038df6492SMark Einon rx_ring->fbr[0]->num_entries = 1024; 190138df6492SMark Einon rx_ring->fbr[1]->buffsize = 4096; 190238df6492SMark Einon rx_ring->fbr[1]->num_entries = 512; 190338df6492SMark Einon } else { 190438df6492SMark Einon rx_ring->fbr[0]->buffsize = 1024; 190538df6492SMark Einon rx_ring->fbr[0]->num_entries = 768; 190638df6492SMark Einon rx_ring->fbr[1]->buffsize = 16384; 190738df6492SMark Einon rx_ring->fbr[1]->num_entries = 128; 190838df6492SMark Einon } 190938df6492SMark Einon 191038df6492SMark Einon rx_ring->psr_entries = rx_ring->fbr[0]->num_entries + 191138df6492SMark Einon rx_ring->fbr[1]->num_entries; 191238df6492SMark Einon 191338df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 191438df6492SMark Einon fbr = rx_ring->fbr[id]; 191538df6492SMark Einon /* Allocate an area of memory for Free Buffer Ring */ 191638df6492SMark Einon bufsize = sizeof(struct fbr_desc) * fbr->num_entries; 191738df6492SMark Einon fbr->ring_virtaddr = dma_alloc_coherent(&adapter->pdev->dev, 191838df6492SMark Einon bufsize, 191938df6492SMark Einon &fbr->ring_physaddr, 192038df6492SMark Einon GFP_KERNEL); 192138df6492SMark Einon if (!fbr->ring_virtaddr) { 192238df6492SMark Einon dev_err(&adapter->pdev->dev, 192338df6492SMark Einon "Cannot alloc memory for Free Buffer Ring %d\n", 192438df6492SMark Einon id); 192538df6492SMark Einon return -ENOMEM; 192638df6492SMark Einon } 192738df6492SMark Einon } 192838df6492SMark Einon 192938df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 193038df6492SMark Einon fbr = rx_ring->fbr[id]; 193138df6492SMark Einon fbr_chunksize = (FBR_CHUNKS * fbr->buffsize); 193238df6492SMark Einon 193338df6492SMark Einon for (i = 0; i < fbr->num_entries / FBR_CHUNKS; i++) { 193438df6492SMark Einon dma_addr_t fbr_physaddr; 193538df6492SMark Einon 193638df6492SMark Einon fbr->mem_virtaddrs[i] = dma_alloc_coherent( 193738df6492SMark Einon &adapter->pdev->dev, fbr_chunksize, 193838df6492SMark Einon &fbr->mem_physaddrs[i], 193938df6492SMark Einon GFP_KERNEL); 194038df6492SMark Einon 194138df6492SMark Einon if (!fbr->mem_virtaddrs[i]) { 194238df6492SMark Einon dev_err(&adapter->pdev->dev, 194338df6492SMark Einon "Could not alloc memory\n"); 194438df6492SMark Einon return -ENOMEM; 194538df6492SMark Einon } 194638df6492SMark Einon 194738df6492SMark Einon /* See NOTE in "Save Physical Address" comment above */ 194838df6492SMark Einon fbr_physaddr = fbr->mem_physaddrs[i]; 194938df6492SMark Einon 195038df6492SMark Einon for (j = 0; j < FBR_CHUNKS; j++) { 195138df6492SMark Einon u32 k = (i * FBR_CHUNKS) + j; 195238df6492SMark Einon 195338df6492SMark Einon /* Save the Virtual address of this index for 195438df6492SMark Einon * quick access later 195538df6492SMark Einon */ 195638df6492SMark Einon fbr->virt[k] = (u8 *)fbr->mem_virtaddrs[i] + 195738df6492SMark Einon (j * fbr->buffsize); 195838df6492SMark Einon 195938df6492SMark Einon /* now store the physical address in the 196038df6492SMark Einon * descriptor so the device can access it 196138df6492SMark Einon */ 196238df6492SMark Einon fbr->bus_high[k] = upper_32_bits(fbr_physaddr); 196338df6492SMark Einon fbr->bus_low[k] = lower_32_bits(fbr_physaddr); 196438df6492SMark Einon fbr_physaddr += fbr->buffsize; 196538df6492SMark Einon } 196638df6492SMark Einon } 196738df6492SMark Einon } 196838df6492SMark Einon 196938df6492SMark Einon /* Allocate an area of memory for FIFO of Packet Status ring entries */ 197038df6492SMark Einon psr_size = sizeof(struct pkt_stat_desc) * rx_ring->psr_entries; 197138df6492SMark Einon 197238df6492SMark Einon rx_ring->ps_ring_virtaddr = dma_alloc_coherent(&adapter->pdev->dev, 197338df6492SMark Einon psr_size, 197438df6492SMark Einon &rx_ring->ps_ring_physaddr, 197538df6492SMark Einon GFP_KERNEL); 197638df6492SMark Einon 197738df6492SMark Einon if (!rx_ring->ps_ring_virtaddr) { 197838df6492SMark Einon dev_err(&adapter->pdev->dev, 197938df6492SMark Einon "Cannot alloc memory for Packet Status Ring\n"); 198038df6492SMark Einon return -ENOMEM; 198138df6492SMark Einon } 198238df6492SMark Einon 198338df6492SMark Einon /* Allocate an area of memory for writeback of status information */ 198438df6492SMark Einon rx_ring->rx_status_block = dma_alloc_coherent(&adapter->pdev->dev, 198538df6492SMark Einon sizeof(struct rx_status_block), 198638df6492SMark Einon &rx_ring->rx_status_bus, 198738df6492SMark Einon GFP_KERNEL); 198838df6492SMark Einon if (!rx_ring->rx_status_block) { 198938df6492SMark Einon dev_err(&adapter->pdev->dev, 199038df6492SMark Einon "Cannot alloc memory for Status Block\n"); 199138df6492SMark Einon return -ENOMEM; 199238df6492SMark Einon } 199338df6492SMark Einon rx_ring->num_rfd = NIC_DEFAULT_NUM_RFD; 199438df6492SMark Einon 199538df6492SMark Einon /* The RFDs are going to be put on lists later on, so initialize the 199638df6492SMark Einon * lists now. 199738df6492SMark Einon */ 199838df6492SMark Einon INIT_LIST_HEAD(&rx_ring->recv_list); 199938df6492SMark Einon return 0; 200038df6492SMark Einon } 200138df6492SMark Einon 200238df6492SMark Einon static void et131x_rx_dma_memory_free(struct et131x_adapter *adapter) 200338df6492SMark Einon { 200438df6492SMark Einon u8 id; 200538df6492SMark Einon u32 ii; 200638df6492SMark Einon u32 bufsize; 200738df6492SMark Einon u32 psr_size; 200838df6492SMark Einon struct rfd *rfd; 200938df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 201038df6492SMark Einon struct fbr_lookup *fbr; 201138df6492SMark Einon 201238df6492SMark Einon /* Free RFDs and associated packet descriptors */ 201338df6492SMark Einon WARN_ON(rx_ring->num_ready_recv != rx_ring->num_rfd); 201438df6492SMark Einon 201538df6492SMark Einon while (!list_empty(&rx_ring->recv_list)) { 201638df6492SMark Einon rfd = list_entry(rx_ring->recv_list.next, 201738df6492SMark Einon struct rfd, list_node); 201838df6492SMark Einon 201938df6492SMark Einon list_del(&rfd->list_node); 202038df6492SMark Einon rfd->skb = NULL; 202138df6492SMark Einon kfree(rfd); 202238df6492SMark Einon } 202338df6492SMark Einon 202438df6492SMark Einon /* Free Free Buffer Rings */ 202538df6492SMark Einon for (id = 0; id < NUM_FBRS; id++) { 202638df6492SMark Einon fbr = rx_ring->fbr[id]; 202738df6492SMark Einon 202838df6492SMark Einon if (!fbr || !fbr->ring_virtaddr) 202938df6492SMark Einon continue; 203038df6492SMark Einon 203138df6492SMark Einon /* First the packet memory */ 203238df6492SMark Einon for (ii = 0; ii < fbr->num_entries / FBR_CHUNKS; ii++) { 203338df6492SMark Einon if (fbr->mem_virtaddrs[ii]) { 203438df6492SMark Einon bufsize = fbr->buffsize * FBR_CHUNKS; 203538df6492SMark Einon 203638df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 203738df6492SMark Einon bufsize, 203838df6492SMark Einon fbr->mem_virtaddrs[ii], 203938df6492SMark Einon fbr->mem_physaddrs[ii]); 204038df6492SMark Einon 204138df6492SMark Einon fbr->mem_virtaddrs[ii] = NULL; 204238df6492SMark Einon } 204338df6492SMark Einon } 204438df6492SMark Einon 204538df6492SMark Einon bufsize = sizeof(struct fbr_desc) * fbr->num_entries; 204638df6492SMark Einon 204738df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 204838df6492SMark Einon bufsize, 204938df6492SMark Einon fbr->ring_virtaddr, 205038df6492SMark Einon fbr->ring_physaddr); 205138df6492SMark Einon 205238df6492SMark Einon fbr->ring_virtaddr = NULL; 205338df6492SMark Einon } 205438df6492SMark Einon 205538df6492SMark Einon /* Free Packet Status Ring */ 205638df6492SMark Einon if (rx_ring->ps_ring_virtaddr) { 205738df6492SMark Einon psr_size = sizeof(struct pkt_stat_desc) * rx_ring->psr_entries; 205838df6492SMark Einon 205938df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, psr_size, 206038df6492SMark Einon rx_ring->ps_ring_virtaddr, 206138df6492SMark Einon rx_ring->ps_ring_physaddr); 206238df6492SMark Einon 206338df6492SMark Einon rx_ring->ps_ring_virtaddr = NULL; 206438df6492SMark Einon } 206538df6492SMark Einon 206638df6492SMark Einon /* Free area of memory for the writeback of status information */ 206738df6492SMark Einon if (rx_ring->rx_status_block) { 206838df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 206938df6492SMark Einon sizeof(struct rx_status_block), 207038df6492SMark Einon rx_ring->rx_status_block, 207138df6492SMark Einon rx_ring->rx_status_bus); 207238df6492SMark Einon rx_ring->rx_status_block = NULL; 207338df6492SMark Einon } 207438df6492SMark Einon 207538df6492SMark Einon /* Free the FBR Lookup Table */ 207638df6492SMark Einon kfree(rx_ring->fbr[0]); 207738df6492SMark Einon kfree(rx_ring->fbr[1]); 207838df6492SMark Einon 207938df6492SMark Einon /* Reset Counters */ 208038df6492SMark Einon rx_ring->num_ready_recv = 0; 208138df6492SMark Einon } 208238df6492SMark Einon 208338df6492SMark Einon /* et131x_init_recv - Initialize receive data structures */ 208438df6492SMark Einon static int et131x_init_recv(struct et131x_adapter *adapter) 208538df6492SMark Einon { 208638df6492SMark Einon struct rfd *rfd; 208738df6492SMark Einon u32 rfdct; 208838df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 208938df6492SMark Einon 209038df6492SMark Einon /* Setup each RFD */ 209138df6492SMark Einon for (rfdct = 0; rfdct < rx_ring->num_rfd; rfdct++) { 209238df6492SMark Einon rfd = kzalloc(sizeof(*rfd), GFP_ATOMIC | GFP_DMA); 209338df6492SMark Einon if (!rfd) 209438df6492SMark Einon return -ENOMEM; 209538df6492SMark Einon 209638df6492SMark Einon rfd->skb = NULL; 209738df6492SMark Einon 209838df6492SMark Einon /* Add this RFD to the recv_list */ 209938df6492SMark Einon list_add_tail(&rfd->list_node, &rx_ring->recv_list); 210038df6492SMark Einon 210138df6492SMark Einon /* Increment the available RFD's */ 210238df6492SMark Einon rx_ring->num_ready_recv++; 210338df6492SMark Einon } 210438df6492SMark Einon 210538df6492SMark Einon return 0; 210638df6492SMark Einon } 210738df6492SMark Einon 210838df6492SMark Einon /* et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate */ 210938df6492SMark Einon static void et131x_set_rx_dma_timer(struct et131x_adapter *adapter) 211038df6492SMark Einon { 2111a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 211238df6492SMark Einon 211338df6492SMark Einon /* For version B silicon, we do not use the RxDMA timer for 10 and 100 211438df6492SMark Einon * Mbits/s line rates. We do not enable and RxDMA interrupt coalescing. 211538df6492SMark Einon */ 211638df6492SMark Einon if ((phydev->speed == SPEED_100) || (phydev->speed == SPEED_10)) { 211738df6492SMark Einon writel(0, &adapter->regs->rxdma.max_pkt_time); 211838df6492SMark Einon writel(1, &adapter->regs->rxdma.num_pkt_done); 211938df6492SMark Einon } 212038df6492SMark Einon } 212138df6492SMark Einon 212238df6492SMark Einon /* nic_return_rfd - Recycle a RFD and put it back onto the receive list */ 212338df6492SMark Einon static void nic_return_rfd(struct et131x_adapter *adapter, struct rfd *rfd) 212438df6492SMark Einon { 212538df6492SMark Einon struct rx_ring *rx_local = &adapter->rx_ring; 212638df6492SMark Einon struct rxdma_regs __iomem *rx_dma = &adapter->regs->rxdma; 212738df6492SMark Einon u16 buff_index = rfd->bufferindex; 212838df6492SMark Einon u8 ring_index = rfd->ringindex; 212938df6492SMark Einon unsigned long flags; 213038df6492SMark Einon struct fbr_lookup *fbr = rx_local->fbr[ring_index]; 213138df6492SMark Einon 213238df6492SMark Einon /* We don't use any of the OOB data besides status. Otherwise, we 213338df6492SMark Einon * need to clean up OOB data 213438df6492SMark Einon */ 213538df6492SMark Einon if (buff_index < fbr->num_entries) { 213638df6492SMark Einon u32 free_buff_ring; 213738df6492SMark Einon u32 __iomem *offset; 213838df6492SMark Einon struct fbr_desc *next; 213938df6492SMark Einon 214038df6492SMark Einon if (ring_index == 0) 214138df6492SMark Einon offset = &rx_dma->fbr0_full_offset; 214238df6492SMark Einon else 214338df6492SMark Einon offset = &rx_dma->fbr1_full_offset; 214438df6492SMark Einon 214538df6492SMark Einon next = (struct fbr_desc *)(fbr->ring_virtaddr) + 214638df6492SMark Einon INDEX10(fbr->local_full); 214738df6492SMark Einon 214838df6492SMark Einon /* Handle the Free Buffer Ring advancement here. Write 214938df6492SMark Einon * the PA / Buffer Index for the returned buffer into 215038df6492SMark Einon * the oldest (next to be freed)FBR entry 215138df6492SMark Einon */ 215238df6492SMark Einon next->addr_hi = fbr->bus_high[buff_index]; 215338df6492SMark Einon next->addr_lo = fbr->bus_low[buff_index]; 215438df6492SMark Einon next->word2 = buff_index; 215538df6492SMark Einon 215638df6492SMark Einon free_buff_ring = bump_free_buff_ring(&fbr->local_full, 215738df6492SMark Einon fbr->num_entries - 1); 215838df6492SMark Einon writel(free_buff_ring, offset); 215938df6492SMark Einon } else { 216038df6492SMark Einon dev_err(&adapter->pdev->dev, 216138df6492SMark Einon "%s illegal Buffer Index returned\n", __func__); 216238df6492SMark Einon } 216338df6492SMark Einon 216438df6492SMark Einon /* The processing on this RFD is done, so put it back on the tail of 216538df6492SMark Einon * our list 216638df6492SMark Einon */ 216738df6492SMark Einon spin_lock_irqsave(&adapter->rcv_lock, flags); 216838df6492SMark Einon list_add_tail(&rfd->list_node, &rx_local->recv_list); 216938df6492SMark Einon rx_local->num_ready_recv++; 217038df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 217138df6492SMark Einon 217238df6492SMark Einon WARN_ON(rx_local->num_ready_recv > rx_local->num_rfd); 217338df6492SMark Einon } 217438df6492SMark Einon 217538df6492SMark Einon /* nic_rx_pkts - Checks the hardware for available packets 217638df6492SMark Einon * 217738df6492SMark Einon * Checks the hardware for available packets, using completion ring 217838df6492SMark Einon * If packets are available, it gets an RFD from the recv_list, attaches 217938df6492SMark Einon * the packet to it, puts the RFD in the RecvPendList, and also returns 218038df6492SMark Einon * the pointer to the RFD. 218138df6492SMark Einon */ 218238df6492SMark Einon static struct rfd *nic_rx_pkts(struct et131x_adapter *adapter) 218338df6492SMark Einon { 218438df6492SMark Einon struct rx_ring *rx_local = &adapter->rx_ring; 218538df6492SMark Einon struct rx_status_block *status; 218638df6492SMark Einon struct pkt_stat_desc *psr; 218738df6492SMark Einon struct rfd *rfd; 218838df6492SMark Einon unsigned long flags; 218938df6492SMark Einon struct list_head *element; 219038df6492SMark Einon u8 ring_index; 219138df6492SMark Einon u16 buff_index; 219238df6492SMark Einon u32 len; 219338df6492SMark Einon u32 word0; 219438df6492SMark Einon u32 word1; 219538df6492SMark Einon struct sk_buff *skb; 219638df6492SMark Einon struct fbr_lookup *fbr; 219738df6492SMark Einon 219838df6492SMark Einon /* RX Status block is written by the DMA engine prior to every 219938df6492SMark Einon * interrupt. It contains the next to be used entry in the Packet 220038df6492SMark Einon * Status Ring, and also the two Free Buffer rings. 220138df6492SMark Einon */ 220238df6492SMark Einon status = rx_local->rx_status_block; 220338df6492SMark Einon word1 = status->word1 >> 16; 220438df6492SMark Einon 220538df6492SMark Einon /* Check the PSR and wrap bits do not match */ 220638df6492SMark Einon if ((word1 & 0x1FFF) == (rx_local->local_psr_full & 0x1FFF)) 220738df6492SMark Einon return NULL; /* Looks like this ring is not updated yet */ 220838df6492SMark Einon 220938df6492SMark Einon /* The packet status ring indicates that data is available. */ 221038df6492SMark Einon psr = (struct pkt_stat_desc *)(rx_local->ps_ring_virtaddr) + 221138df6492SMark Einon (rx_local->local_psr_full & 0xFFF); 221238df6492SMark Einon 221338df6492SMark Einon /* Grab any information that is required once the PSR is advanced, 221438df6492SMark Einon * since we can no longer rely on the memory being accurate 221538df6492SMark Einon */ 221638df6492SMark Einon len = psr->word1 & 0xFFFF; 221738df6492SMark Einon ring_index = (psr->word1 >> 26) & 0x03; 221838df6492SMark Einon fbr = rx_local->fbr[ring_index]; 221938df6492SMark Einon buff_index = (psr->word1 >> 16) & 0x3FF; 222038df6492SMark Einon word0 = psr->word0; 222138df6492SMark Einon 222238df6492SMark Einon /* Indicate that we have used this PSR entry. */ 222338df6492SMark Einon /* FIXME wrap 12 */ 222438df6492SMark Einon add_12bit(&rx_local->local_psr_full, 1); 222538df6492SMark Einon if ((rx_local->local_psr_full & 0xFFF) > rx_local->psr_entries - 1) { 222638df6492SMark Einon /* Clear psr full and toggle the wrap bit */ 222738df6492SMark Einon rx_local->local_psr_full &= ~0xFFF; 222838df6492SMark Einon rx_local->local_psr_full ^= 0x1000; 222938df6492SMark Einon } 223038df6492SMark Einon 223138df6492SMark Einon writel(rx_local->local_psr_full, &adapter->regs->rxdma.psr_full_offset); 223238df6492SMark Einon 223338df6492SMark Einon if (ring_index > 1 || buff_index > fbr->num_entries - 1) { 223438df6492SMark Einon /* Illegal buffer or ring index cannot be used by S/W*/ 223538df6492SMark Einon dev_err(&adapter->pdev->dev, 223638df6492SMark Einon "NICRxPkts PSR Entry %d indicates length of %d and/or bad bi(%d)\n", 223738df6492SMark Einon rx_local->local_psr_full & 0xFFF, len, buff_index); 223838df6492SMark Einon return NULL; 223938df6492SMark Einon } 224038df6492SMark Einon 224138df6492SMark Einon /* Get and fill the RFD. */ 224238df6492SMark Einon spin_lock_irqsave(&adapter->rcv_lock, flags); 224338df6492SMark Einon 224438df6492SMark Einon element = rx_local->recv_list.next; 224538df6492SMark Einon rfd = list_entry(element, struct rfd, list_node); 224638df6492SMark Einon 224738df6492SMark Einon if (!rfd) { 224838df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 224938df6492SMark Einon return NULL; 225038df6492SMark Einon } 225138df6492SMark Einon 225238df6492SMark Einon list_del(&rfd->list_node); 225338df6492SMark Einon rx_local->num_ready_recv--; 225438df6492SMark Einon 225538df6492SMark Einon spin_unlock_irqrestore(&adapter->rcv_lock, flags); 225638df6492SMark Einon 225738df6492SMark Einon rfd->bufferindex = buff_index; 225838df6492SMark Einon rfd->ringindex = ring_index; 225938df6492SMark Einon 226038df6492SMark Einon /* In V1 silicon, there is a bug which screws up filtering of runt 226138df6492SMark Einon * packets. Therefore runt packet filtering is disabled in the MAC and 226238df6492SMark Einon * the packets are dropped here. They are also counted here. 226338df6492SMark Einon */ 226438df6492SMark Einon if (len < (NIC_MIN_PACKET_SIZE + 4)) { 226538df6492SMark Einon adapter->stats.rx_other_errs++; 226638df6492SMark Einon rfd->len = 0; 226738df6492SMark Einon goto out; 226838df6492SMark Einon } 226938df6492SMark Einon 227038df6492SMark Einon if ((word0 & ALCATEL_MULTICAST_PKT) && !(word0 & ALCATEL_BROADCAST_PKT)) 227138df6492SMark Einon adapter->stats.multicast_pkts_rcvd++; 227238df6492SMark Einon 227338df6492SMark Einon rfd->len = len; 227438df6492SMark Einon 227538df6492SMark Einon skb = dev_alloc_skb(rfd->len + 2); 227638df6492SMark Einon if (!skb) 227738df6492SMark Einon return NULL; 227838df6492SMark Einon 227938df6492SMark Einon adapter->netdev->stats.rx_bytes += rfd->len; 228038df6492SMark Einon 228159ae1d12SJohannes Berg skb_put_data(skb, fbr->virt[buff_index], rfd->len); 228238df6492SMark Einon 228338df6492SMark Einon skb->protocol = eth_type_trans(skb, adapter->netdev); 228438df6492SMark Einon skb->ip_summed = CHECKSUM_NONE; 228538df6492SMark Einon netif_receive_skb(skb); 228638df6492SMark Einon 228738df6492SMark Einon out: 228838df6492SMark Einon nic_return_rfd(adapter, rfd); 228938df6492SMark Einon return rfd; 229038df6492SMark Einon } 229138df6492SMark Einon 229238df6492SMark Einon static int et131x_handle_recv_pkts(struct et131x_adapter *adapter, int budget) 229338df6492SMark Einon { 229438df6492SMark Einon struct rfd *rfd = NULL; 229538df6492SMark Einon int count = 0; 229638df6492SMark Einon int limit = budget; 229738df6492SMark Einon bool done = true; 229838df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 229938df6492SMark Einon 230038df6492SMark Einon if (budget > MAX_PACKETS_HANDLED) 230138df6492SMark Einon limit = MAX_PACKETS_HANDLED; 230238df6492SMark Einon 230338df6492SMark Einon /* Process up to available RFD's */ 230438df6492SMark Einon while (count < limit) { 230538df6492SMark Einon if (list_empty(&rx_ring->recv_list)) { 230638df6492SMark Einon WARN_ON(rx_ring->num_ready_recv != 0); 230738df6492SMark Einon done = false; 230838df6492SMark Einon break; 230938df6492SMark Einon } 231038df6492SMark Einon 231138df6492SMark Einon rfd = nic_rx_pkts(adapter); 231238df6492SMark Einon 231338df6492SMark Einon if (rfd == NULL) 231438df6492SMark Einon break; 231538df6492SMark Einon 231638df6492SMark Einon /* Do not receive any packets until a filter has been set. 231738df6492SMark Einon * Do not receive any packets until we have link. 231838df6492SMark Einon * If length is zero, return the RFD in order to advance the 231938df6492SMark Einon * Free buffer ring. 232038df6492SMark Einon */ 232138df6492SMark Einon if (!adapter->packet_filter || 232238df6492SMark Einon !netif_carrier_ok(adapter->netdev) || 232338df6492SMark Einon rfd->len == 0) 232438df6492SMark Einon continue; 232538df6492SMark Einon 232638df6492SMark Einon adapter->netdev->stats.rx_packets++; 232738df6492SMark Einon 232838df6492SMark Einon if (rx_ring->num_ready_recv < RFD_LOW_WATER_MARK) 232938df6492SMark Einon dev_warn(&adapter->pdev->dev, "RFD's are running out\n"); 233038df6492SMark Einon 233138df6492SMark Einon count++; 233238df6492SMark Einon } 233338df6492SMark Einon 233438df6492SMark Einon if (count == limit || !done) { 233538df6492SMark Einon rx_ring->unfinished_receives = true; 233638df6492SMark Einon writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, 233738df6492SMark Einon &adapter->regs->global.watchdog_timer); 233838df6492SMark Einon } else { 233938df6492SMark Einon /* Watchdog timer will disable itself if appropriate. */ 234038df6492SMark Einon rx_ring->unfinished_receives = false; 234138df6492SMark Einon } 234238df6492SMark Einon 234338df6492SMark Einon return count; 234438df6492SMark Einon } 234538df6492SMark Einon 234638df6492SMark Einon /* et131x_tx_dma_memory_alloc 234738df6492SMark Einon * 234838df6492SMark Einon * Allocates memory that will be visible both to the device and to the CPU. 234938df6492SMark Einon * The OS will pass us packets, pointers to which we will insert in the Tx 235038df6492SMark Einon * Descriptor queue. The device will read this queue to find the packets in 235138df6492SMark Einon * memory. The device will update the "status" in memory each time it xmits a 235238df6492SMark Einon * packet. 235338df6492SMark Einon */ 235438df6492SMark Einon static int et131x_tx_dma_memory_alloc(struct et131x_adapter *adapter) 235538df6492SMark Einon { 235638df6492SMark Einon int desc_size = 0; 235738df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 235838df6492SMark Einon 235938df6492SMark Einon /* Allocate memory for the TCB's (Transmit Control Block) */ 236038df6492SMark Einon tx_ring->tcb_ring = kcalloc(NUM_TCB, sizeof(struct tcb), 236147b69bf7SChristophe JAILLET GFP_KERNEL | GFP_DMA); 236238df6492SMark Einon if (!tx_ring->tcb_ring) 236338df6492SMark Einon return -ENOMEM; 236438df6492SMark Einon 236538df6492SMark Einon desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX); 236638df6492SMark Einon tx_ring->tx_desc_ring = dma_alloc_coherent(&adapter->pdev->dev, 236738df6492SMark Einon desc_size, 236838df6492SMark Einon &tx_ring->tx_desc_ring_pa, 236938df6492SMark Einon GFP_KERNEL); 237038df6492SMark Einon if (!tx_ring->tx_desc_ring) { 237138df6492SMark Einon dev_err(&adapter->pdev->dev, 237238df6492SMark Einon "Cannot alloc memory for Tx Ring\n"); 237338df6492SMark Einon return -ENOMEM; 237438df6492SMark Einon } 237538df6492SMark Einon 237638df6492SMark Einon tx_ring->tx_status = dma_alloc_coherent(&adapter->pdev->dev, 237738df6492SMark Einon sizeof(u32), 237838df6492SMark Einon &tx_ring->tx_status_pa, 237938df6492SMark Einon GFP_KERNEL); 2380562a9f91SInsu Yun if (!tx_ring->tx_status) { 238138df6492SMark Einon dev_err(&adapter->pdev->dev, 238238df6492SMark Einon "Cannot alloc memory for Tx status block\n"); 238338df6492SMark Einon return -ENOMEM; 238438df6492SMark Einon } 238538df6492SMark Einon return 0; 238638df6492SMark Einon } 238738df6492SMark Einon 238838df6492SMark Einon static void et131x_tx_dma_memory_free(struct et131x_adapter *adapter) 238938df6492SMark Einon { 239038df6492SMark Einon int desc_size = 0; 239138df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 239238df6492SMark Einon 239338df6492SMark Einon if (tx_ring->tx_desc_ring) { 239438df6492SMark Einon /* Free memory relating to Tx rings here */ 239538df6492SMark Einon desc_size = (sizeof(struct tx_desc) * NUM_DESC_PER_RING_TX); 239638df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 239738df6492SMark Einon desc_size, 239838df6492SMark Einon tx_ring->tx_desc_ring, 239938df6492SMark Einon tx_ring->tx_desc_ring_pa); 240038df6492SMark Einon tx_ring->tx_desc_ring = NULL; 240138df6492SMark Einon } 240238df6492SMark Einon 240338df6492SMark Einon /* Free memory for the Tx status block */ 240438df6492SMark Einon if (tx_ring->tx_status) { 240538df6492SMark Einon dma_free_coherent(&adapter->pdev->dev, 240638df6492SMark Einon sizeof(u32), 240738df6492SMark Einon tx_ring->tx_status, 240838df6492SMark Einon tx_ring->tx_status_pa); 240938df6492SMark Einon 241038df6492SMark Einon tx_ring->tx_status = NULL; 241138df6492SMark Einon } 241238df6492SMark Einon /* Free the memory for the tcb structures */ 241338df6492SMark Einon kfree(tx_ring->tcb_ring); 241438df6492SMark Einon } 241538df6492SMark Einon 241699f5a5f2SEric Dumazet #define MAX_TX_DESC_PER_PKT 24 241799f5a5f2SEric Dumazet 241838df6492SMark Einon /* nic_send_packet - NIC specific send handler for version B silicon. */ 241938df6492SMark Einon static int nic_send_packet(struct et131x_adapter *adapter, struct tcb *tcb) 242038df6492SMark Einon { 242138df6492SMark Einon u32 i; 242299f5a5f2SEric Dumazet struct tx_desc desc[MAX_TX_DESC_PER_PKT]; 242338df6492SMark Einon u32 frag = 0; 242438df6492SMark Einon u32 thiscopy, remainder; 242538df6492SMark Einon struct sk_buff *skb = tcb->skb; 242638df6492SMark Einon u32 nr_frags = skb_shinfo(skb)->nr_frags + 1; 2427d7840976SMatthew Wilcox (Oracle) skb_frag_t *frags = &skb_shinfo(skb)->frags[0]; 2428a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 242938df6492SMark Einon dma_addr_t dma_addr; 243038df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 243138df6492SMark Einon 243238df6492SMark Einon /* Part of the optimizations of this send routine restrict us to 243338df6492SMark Einon * sending 24 fragments at a pass. In practice we should never see 243438df6492SMark Einon * more than 5 fragments. 243538df6492SMark Einon */ 243638df6492SMark Einon 243738df6492SMark Einon memset(desc, 0, sizeof(struct tx_desc) * (nr_frags + 1)); 243838df6492SMark Einon 243938df6492SMark Einon for (i = 0; i < nr_frags; i++) { 244038df6492SMark Einon /* If there is something in this element, lets get a 244138df6492SMark Einon * descriptor from the ring and get the necessary data 244238df6492SMark Einon */ 244338df6492SMark Einon if (i == 0) { 244438df6492SMark Einon /* If the fragments are smaller than a standard MTU, 244538df6492SMark Einon * then map them to a single descriptor in the Tx 244638df6492SMark Einon * Desc ring. However, if they're larger, as is 244738df6492SMark Einon * possible with support for jumbo packets, then 244838df6492SMark Einon * split them each across 2 descriptors. 244938df6492SMark Einon * 245038df6492SMark Einon * This will work until we determine why the hardware 245138df6492SMark Einon * doesn't seem to like large fragments. 245238df6492SMark Einon */ 245338df6492SMark Einon if (skb_headlen(skb) <= 1514) { 245438df6492SMark Einon /* Low 16bits are length, high is vlan and 245538df6492SMark Einon * unused currently so zero 245638df6492SMark Einon */ 245738df6492SMark Einon desc[frag].len_vlan = skb_headlen(skb); 245838df6492SMark Einon dma_addr = dma_map_single(&adapter->pdev->dev, 245938df6492SMark Einon skb->data, 246038df6492SMark Einon skb_headlen(skb), 246138df6492SMark Einon DMA_TO_DEVICE); 246238df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 246338df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 246438df6492SMark Einon frag++; 246538df6492SMark Einon } else { 246638df6492SMark Einon desc[frag].len_vlan = skb_headlen(skb) / 2; 246738df6492SMark Einon dma_addr = dma_map_single(&adapter->pdev->dev, 246838df6492SMark Einon skb->data, 246938df6492SMark Einon skb_headlen(skb) / 2, 247038df6492SMark Einon DMA_TO_DEVICE); 247138df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 247238df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 247338df6492SMark Einon frag++; 247438df6492SMark Einon 247538df6492SMark Einon desc[frag].len_vlan = skb_headlen(skb) / 2; 247638df6492SMark Einon dma_addr = dma_map_single(&adapter->pdev->dev, 247738df6492SMark Einon skb->data + 247838df6492SMark Einon skb_headlen(skb) / 2, 247938df6492SMark Einon skb_headlen(skb) / 2, 248038df6492SMark Einon DMA_TO_DEVICE); 248138df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 248238df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 248338df6492SMark Einon frag++; 248438df6492SMark Einon } 248538df6492SMark Einon } else { 2486d7840976SMatthew Wilcox (Oracle) desc[frag].len_vlan = skb_frag_size(&frags[i - 1]); 248738df6492SMark Einon dma_addr = skb_frag_dma_map(&adapter->pdev->dev, 248838df6492SMark Einon &frags[i - 1], 248938df6492SMark Einon 0, 2490d7840976SMatthew Wilcox (Oracle) desc[frag].len_vlan, 249138df6492SMark Einon DMA_TO_DEVICE); 249238df6492SMark Einon desc[frag].addr_lo = lower_32_bits(dma_addr); 249338df6492SMark Einon desc[frag].addr_hi = upper_32_bits(dma_addr); 249438df6492SMark Einon frag++; 249538df6492SMark Einon } 249638df6492SMark Einon } 249738df6492SMark Einon 249838df6492SMark Einon if (phydev && phydev->speed == SPEED_1000) { 249938df6492SMark Einon if (++tx_ring->since_irq == PARM_TX_NUM_BUFS_DEF) { 250038df6492SMark Einon /* Last element & Interrupt flag */ 250138df6492SMark Einon desc[frag - 1].flags = 250238df6492SMark Einon TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; 250338df6492SMark Einon tx_ring->since_irq = 0; 250438df6492SMark Einon } else { /* Last element */ 250538df6492SMark Einon desc[frag - 1].flags = TXDESC_FLAG_LASTPKT; 250638df6492SMark Einon } 250738df6492SMark Einon } else { 250838df6492SMark Einon desc[frag - 1].flags = 250938df6492SMark Einon TXDESC_FLAG_INTPROC | TXDESC_FLAG_LASTPKT; 251038df6492SMark Einon } 251138df6492SMark Einon 251238df6492SMark Einon desc[0].flags |= TXDESC_FLAG_FIRSTPKT; 251338df6492SMark Einon 251438df6492SMark Einon tcb->index_start = tx_ring->send_idx; 251538df6492SMark Einon tcb->stale = 0; 251638df6492SMark Einon 251738df6492SMark Einon thiscopy = NUM_DESC_PER_RING_TX - INDEX10(tx_ring->send_idx); 251838df6492SMark Einon 251938df6492SMark Einon if (thiscopy >= frag) { 252038df6492SMark Einon remainder = 0; 252138df6492SMark Einon thiscopy = frag; 252238df6492SMark Einon } else { 252338df6492SMark Einon remainder = frag - thiscopy; 252438df6492SMark Einon } 252538df6492SMark Einon 252638df6492SMark Einon memcpy(tx_ring->tx_desc_ring + INDEX10(tx_ring->send_idx), 252738df6492SMark Einon desc, 252838df6492SMark Einon sizeof(struct tx_desc) * thiscopy); 252938df6492SMark Einon 253038df6492SMark Einon add_10bit(&tx_ring->send_idx, thiscopy); 253138df6492SMark Einon 253238df6492SMark Einon if (INDEX10(tx_ring->send_idx) == 0 || 253338df6492SMark Einon INDEX10(tx_ring->send_idx) == NUM_DESC_PER_RING_TX) { 253438df6492SMark Einon tx_ring->send_idx &= ~ET_DMA10_MASK; 253538df6492SMark Einon tx_ring->send_idx ^= ET_DMA10_WRAP; 253638df6492SMark Einon } 253738df6492SMark Einon 253838df6492SMark Einon if (remainder) { 253938df6492SMark Einon memcpy(tx_ring->tx_desc_ring, 254038df6492SMark Einon desc + thiscopy, 254138df6492SMark Einon sizeof(struct tx_desc) * remainder); 254238df6492SMark Einon 254338df6492SMark Einon add_10bit(&tx_ring->send_idx, remainder); 254438df6492SMark Einon } 254538df6492SMark Einon 254638df6492SMark Einon if (INDEX10(tx_ring->send_idx) == 0) { 254738df6492SMark Einon if (tx_ring->send_idx) 254838df6492SMark Einon tcb->index = NUM_DESC_PER_RING_TX - 1; 254938df6492SMark Einon else 255038df6492SMark Einon tcb->index = ET_DMA10_WRAP|(NUM_DESC_PER_RING_TX - 1); 255138df6492SMark Einon } else { 255238df6492SMark Einon tcb->index = tx_ring->send_idx - 1; 255338df6492SMark Einon } 255438df6492SMark Einon 255538df6492SMark Einon spin_lock(&adapter->tcb_send_qlock); 255638df6492SMark Einon 255738df6492SMark Einon if (tx_ring->send_tail) 255838df6492SMark Einon tx_ring->send_tail->next = tcb; 255938df6492SMark Einon else 256038df6492SMark Einon tx_ring->send_head = tcb; 256138df6492SMark Einon 256238df6492SMark Einon tx_ring->send_tail = tcb; 256338df6492SMark Einon 256438df6492SMark Einon WARN_ON(tcb->next != NULL); 256538df6492SMark Einon 256638df6492SMark Einon tx_ring->used++; 256738df6492SMark Einon 256838df6492SMark Einon spin_unlock(&adapter->tcb_send_qlock); 256938df6492SMark Einon 257038df6492SMark Einon /* Write the new write pointer back to the device. */ 257138df6492SMark Einon writel(tx_ring->send_idx, &adapter->regs->txdma.service_request); 257238df6492SMark Einon 257338df6492SMark Einon /* For Gig only, we use Tx Interrupt coalescing. Enable the software 257438df6492SMark Einon * timer to wake us up if this packet isn't followed by N more. 257538df6492SMark Einon */ 257638df6492SMark Einon if (phydev && phydev->speed == SPEED_1000) { 257738df6492SMark Einon writel(PARM_TX_TIME_INT_DEF * NANO_IN_A_MICRO, 257838df6492SMark Einon &adapter->regs->global.watchdog_timer); 257938df6492SMark Einon } 258038df6492SMark Einon return 0; 258138df6492SMark Einon } 258238df6492SMark Einon 258338df6492SMark Einon static int send_packet(struct sk_buff *skb, struct et131x_adapter *adapter) 258438df6492SMark Einon { 258538df6492SMark Einon int status; 258638df6492SMark Einon struct tcb *tcb; 258738df6492SMark Einon unsigned long flags; 258838df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 258938df6492SMark Einon 259038df6492SMark Einon /* All packets must have at least a MAC address and a protocol type */ 259138df6492SMark Einon if (skb->len < ETH_HLEN) 259238df6492SMark Einon return -EIO; 259338df6492SMark Einon 259438df6492SMark Einon spin_lock_irqsave(&adapter->tcb_ready_qlock, flags); 259538df6492SMark Einon 259638df6492SMark Einon tcb = tx_ring->tcb_qhead; 259738df6492SMark Einon 259838df6492SMark Einon if (tcb == NULL) { 259938df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 260038df6492SMark Einon return -ENOMEM; 260138df6492SMark Einon } 260238df6492SMark Einon 260338df6492SMark Einon tx_ring->tcb_qhead = tcb->next; 260438df6492SMark Einon 260538df6492SMark Einon if (tx_ring->tcb_qhead == NULL) 260638df6492SMark Einon tx_ring->tcb_qtail = NULL; 260738df6492SMark Einon 260838df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 260938df6492SMark Einon 261038df6492SMark Einon tcb->skb = skb; 261138df6492SMark Einon tcb->next = NULL; 261238df6492SMark Einon 261338df6492SMark Einon status = nic_send_packet(adapter, tcb); 261438df6492SMark Einon 261538df6492SMark Einon if (status != 0) { 261638df6492SMark Einon spin_lock_irqsave(&adapter->tcb_ready_qlock, flags); 261738df6492SMark Einon 261838df6492SMark Einon if (tx_ring->tcb_qtail) 261938df6492SMark Einon tx_ring->tcb_qtail->next = tcb; 262038df6492SMark Einon else 262138df6492SMark Einon /* Apparently ready Q is empty. */ 262238df6492SMark Einon tx_ring->tcb_qhead = tcb; 262338df6492SMark Einon 262438df6492SMark Einon tx_ring->tcb_qtail = tcb; 262538df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 262638df6492SMark Einon return status; 262738df6492SMark Einon } 262838df6492SMark Einon WARN_ON(tx_ring->used > NUM_TCB); 262938df6492SMark Einon return 0; 263038df6492SMark Einon } 263138df6492SMark Einon 263238df6492SMark Einon /* free_send_packet - Recycle a struct tcb */ 263338df6492SMark Einon static inline void free_send_packet(struct et131x_adapter *adapter, 263438df6492SMark Einon struct tcb *tcb) 263538df6492SMark Einon { 263638df6492SMark Einon unsigned long flags; 263738df6492SMark Einon struct tx_desc *desc = NULL; 263838df6492SMark Einon struct net_device_stats *stats = &adapter->netdev->stats; 263938df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 264038df6492SMark Einon u64 dma_addr; 264138df6492SMark Einon 264238df6492SMark Einon if (tcb->skb) { 264338df6492SMark Einon stats->tx_bytes += tcb->skb->len; 264438df6492SMark Einon 264538df6492SMark Einon /* Iterate through the TX descriptors on the ring 264638df6492SMark Einon * corresponding to this packet and umap the fragments 264738df6492SMark Einon * they point to 264838df6492SMark Einon */ 264938df6492SMark Einon do { 265038df6492SMark Einon desc = tx_ring->tx_desc_ring + 265138df6492SMark Einon INDEX10(tcb->index_start); 265238df6492SMark Einon 265338df6492SMark Einon dma_addr = desc->addr_lo; 265438df6492SMark Einon dma_addr |= (u64)desc->addr_hi << 32; 265538df6492SMark Einon 265638df6492SMark Einon dma_unmap_single(&adapter->pdev->dev, 265738df6492SMark Einon dma_addr, 265838df6492SMark Einon desc->len_vlan, DMA_TO_DEVICE); 265938df6492SMark Einon 266038df6492SMark Einon add_10bit(&tcb->index_start, 1); 266138df6492SMark Einon if (INDEX10(tcb->index_start) >= 266238df6492SMark Einon NUM_DESC_PER_RING_TX) { 266338df6492SMark Einon tcb->index_start &= ~ET_DMA10_MASK; 266438df6492SMark Einon tcb->index_start ^= ET_DMA10_WRAP; 266538df6492SMark Einon } 266638df6492SMark Einon } while (desc != tx_ring->tx_desc_ring + INDEX10(tcb->index)); 266738df6492SMark Einon 266838df6492SMark Einon dev_kfree_skb_any(tcb->skb); 266938df6492SMark Einon } 267038df6492SMark Einon 267138df6492SMark Einon memset(tcb, 0, sizeof(struct tcb)); 267238df6492SMark Einon 267338df6492SMark Einon /* Add the TCB to the Ready Q */ 267438df6492SMark Einon spin_lock_irqsave(&adapter->tcb_ready_qlock, flags); 267538df6492SMark Einon 267638df6492SMark Einon stats->tx_packets++; 267738df6492SMark Einon 267838df6492SMark Einon if (tx_ring->tcb_qtail) 267938df6492SMark Einon tx_ring->tcb_qtail->next = tcb; 268038df6492SMark Einon else /* Apparently ready Q is empty. */ 268138df6492SMark Einon tx_ring->tcb_qhead = tcb; 268238df6492SMark Einon 268338df6492SMark Einon tx_ring->tcb_qtail = tcb; 268438df6492SMark Einon 268538df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_ready_qlock, flags); 268638df6492SMark Einon WARN_ON(tx_ring->used < 0); 268738df6492SMark Einon } 268838df6492SMark Einon 268938df6492SMark Einon /* et131x_free_busy_send_packets - Free and complete the stopped active sends */ 269038df6492SMark Einon static void et131x_free_busy_send_packets(struct et131x_adapter *adapter) 269138df6492SMark Einon { 269238df6492SMark Einon struct tcb *tcb; 269338df6492SMark Einon unsigned long flags; 269438df6492SMark Einon u32 freed = 0; 269538df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 269638df6492SMark Einon 269738df6492SMark Einon /* Any packets being sent? Check the first TCB on the send list */ 269838df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 269938df6492SMark Einon 270038df6492SMark Einon tcb = tx_ring->send_head; 270138df6492SMark Einon 270238df6492SMark Einon while (tcb != NULL && freed < NUM_TCB) { 270338df6492SMark Einon struct tcb *next = tcb->next; 270438df6492SMark Einon 270538df6492SMark Einon tx_ring->send_head = next; 270638df6492SMark Einon 270738df6492SMark Einon if (next == NULL) 270838df6492SMark Einon tx_ring->send_tail = NULL; 270938df6492SMark Einon 271038df6492SMark Einon tx_ring->used--; 271138df6492SMark Einon 271238df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 271338df6492SMark Einon 271438df6492SMark Einon freed++; 271538df6492SMark Einon free_send_packet(adapter, tcb); 271638df6492SMark Einon 271738df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 271838df6492SMark Einon 271938df6492SMark Einon tcb = tx_ring->send_head; 272038df6492SMark Einon } 272138df6492SMark Einon 272238df6492SMark Einon WARN_ON(freed == NUM_TCB); 272338df6492SMark Einon 272438df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 272538df6492SMark Einon 272638df6492SMark Einon tx_ring->used = 0; 272738df6492SMark Einon } 272838df6492SMark Einon 272938df6492SMark Einon /* et131x_handle_send_pkts 273038df6492SMark Einon * 273138df6492SMark Einon * Re-claim the send resources, complete sends and get more to send from 273238df6492SMark Einon * the send wait queue. 273338df6492SMark Einon */ 273438df6492SMark Einon static void et131x_handle_send_pkts(struct et131x_adapter *adapter) 273538df6492SMark Einon { 273638df6492SMark Einon unsigned long flags; 273738df6492SMark Einon u32 serviced; 273838df6492SMark Einon struct tcb *tcb; 273938df6492SMark Einon u32 index; 274038df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 274138df6492SMark Einon 274238df6492SMark Einon serviced = readl(&adapter->regs->txdma.new_service_complete); 274338df6492SMark Einon index = INDEX10(serviced); 274438df6492SMark Einon 274538df6492SMark Einon /* Has the ring wrapped? Process any descriptors that do not have 274638df6492SMark Einon * the same "wrap" indicator as the current completion indicator 274738df6492SMark Einon */ 274838df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 274938df6492SMark Einon 275038df6492SMark Einon tcb = tx_ring->send_head; 275138df6492SMark Einon 275238df6492SMark Einon while (tcb && 275338df6492SMark Einon ((serviced ^ tcb->index) & ET_DMA10_WRAP) && 275438df6492SMark Einon index < INDEX10(tcb->index)) { 275538df6492SMark Einon tx_ring->used--; 275638df6492SMark Einon tx_ring->send_head = tcb->next; 275738df6492SMark Einon if (tcb->next == NULL) 275838df6492SMark Einon tx_ring->send_tail = NULL; 275938df6492SMark Einon 276038df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 276138df6492SMark Einon free_send_packet(adapter, tcb); 276238df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 276338df6492SMark Einon 276438df6492SMark Einon /* Goto the next packet */ 276538df6492SMark Einon tcb = tx_ring->send_head; 276638df6492SMark Einon } 276738df6492SMark Einon while (tcb && 276838df6492SMark Einon !((serviced ^ tcb->index) & ET_DMA10_WRAP) && 276938df6492SMark Einon index > (tcb->index & ET_DMA10_MASK)) { 277038df6492SMark Einon tx_ring->used--; 277138df6492SMark Einon tx_ring->send_head = tcb->next; 277238df6492SMark Einon if (tcb->next == NULL) 277338df6492SMark Einon tx_ring->send_tail = NULL; 277438df6492SMark Einon 277538df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 277638df6492SMark Einon free_send_packet(adapter, tcb); 277738df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 277838df6492SMark Einon 277938df6492SMark Einon /* Goto the next packet */ 278038df6492SMark Einon tcb = tx_ring->send_head; 278138df6492SMark Einon } 278238df6492SMark Einon 278338df6492SMark Einon /* Wake up the queue when we hit a low-water mark */ 278438df6492SMark Einon if (tx_ring->used <= NUM_TCB / 3) 278538df6492SMark Einon netif_wake_queue(adapter->netdev); 278638df6492SMark Einon 278738df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 278838df6492SMark Einon } 278938df6492SMark Einon 279038df6492SMark Einon static int et131x_get_regs_len(struct net_device *netdev) 279138df6492SMark Einon { 279238df6492SMark Einon #define ET131X_REGS_LEN 256 279338df6492SMark Einon return ET131X_REGS_LEN * sizeof(u32); 279438df6492SMark Einon } 279538df6492SMark Einon 279638df6492SMark Einon static void et131x_get_regs(struct net_device *netdev, 279738df6492SMark Einon struct ethtool_regs *regs, void *regs_data) 279838df6492SMark Einon { 279938df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 280038df6492SMark Einon struct address_map __iomem *aregs = adapter->regs; 280138df6492SMark Einon u32 *regs_buff = regs_data; 280238df6492SMark Einon u32 num = 0; 280338df6492SMark Einon u16 tmp; 280438df6492SMark Einon 280538df6492SMark Einon memset(regs_data, 0, et131x_get_regs_len(netdev)); 280638df6492SMark Einon 280738df6492SMark Einon regs->version = (1 << 24) | (adapter->pdev->revision << 16) | 280838df6492SMark Einon adapter->pdev->device; 280938df6492SMark Einon 281038df6492SMark Einon /* PHY regs */ 281138df6492SMark Einon et131x_mii_read(adapter, MII_BMCR, &tmp); 281238df6492SMark Einon regs_buff[num++] = tmp; 281338df6492SMark Einon et131x_mii_read(adapter, MII_BMSR, &tmp); 281438df6492SMark Einon regs_buff[num++] = tmp; 281538df6492SMark Einon et131x_mii_read(adapter, MII_PHYSID1, &tmp); 281638df6492SMark Einon regs_buff[num++] = tmp; 281738df6492SMark Einon et131x_mii_read(adapter, MII_PHYSID2, &tmp); 281838df6492SMark Einon regs_buff[num++] = tmp; 281938df6492SMark Einon et131x_mii_read(adapter, MII_ADVERTISE, &tmp); 282038df6492SMark Einon regs_buff[num++] = tmp; 282138df6492SMark Einon et131x_mii_read(adapter, MII_LPA, &tmp); 282238df6492SMark Einon regs_buff[num++] = tmp; 282338df6492SMark Einon et131x_mii_read(adapter, MII_EXPANSION, &tmp); 282438df6492SMark Einon regs_buff[num++] = tmp; 282538df6492SMark Einon /* Autoneg next page transmit reg */ 282638df6492SMark Einon et131x_mii_read(adapter, 0x07, &tmp); 282738df6492SMark Einon regs_buff[num++] = tmp; 282838df6492SMark Einon /* Link partner next page reg */ 282938df6492SMark Einon et131x_mii_read(adapter, 0x08, &tmp); 283038df6492SMark Einon regs_buff[num++] = tmp; 283138df6492SMark Einon et131x_mii_read(adapter, MII_CTRL1000, &tmp); 283238df6492SMark Einon regs_buff[num++] = tmp; 283338df6492SMark Einon et131x_mii_read(adapter, MII_STAT1000, &tmp); 283438df6492SMark Einon regs_buff[num++] = tmp; 283538df6492SMark Einon et131x_mii_read(adapter, 0x0b, &tmp); 283638df6492SMark Einon regs_buff[num++] = tmp; 283738df6492SMark Einon et131x_mii_read(adapter, 0x0c, &tmp); 283838df6492SMark Einon regs_buff[num++] = tmp; 283938df6492SMark Einon et131x_mii_read(adapter, MII_MMD_CTRL, &tmp); 284038df6492SMark Einon regs_buff[num++] = tmp; 284138df6492SMark Einon et131x_mii_read(adapter, MII_MMD_DATA, &tmp); 284238df6492SMark Einon regs_buff[num++] = tmp; 284338df6492SMark Einon et131x_mii_read(adapter, MII_ESTATUS, &tmp); 284438df6492SMark Einon regs_buff[num++] = tmp; 284538df6492SMark Einon 284638df6492SMark Einon et131x_mii_read(adapter, PHY_INDEX_REG, &tmp); 284738df6492SMark Einon regs_buff[num++] = tmp; 284838df6492SMark Einon et131x_mii_read(adapter, PHY_DATA_REG, &tmp); 284938df6492SMark Einon regs_buff[num++] = tmp; 285038df6492SMark Einon et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, &tmp); 285138df6492SMark Einon regs_buff[num++] = tmp; 285238df6492SMark Einon et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL, &tmp); 285338df6492SMark Einon regs_buff[num++] = tmp; 285438df6492SMark Einon et131x_mii_read(adapter, PHY_LOOPBACK_CONTROL + 1, &tmp); 285538df6492SMark Einon regs_buff[num++] = tmp; 285638df6492SMark Einon 285738df6492SMark Einon et131x_mii_read(adapter, PHY_REGISTER_MGMT_CONTROL, &tmp); 285838df6492SMark Einon regs_buff[num++] = tmp; 285938df6492SMark Einon et131x_mii_read(adapter, PHY_CONFIG, &tmp); 286038df6492SMark Einon regs_buff[num++] = tmp; 286138df6492SMark Einon et131x_mii_read(adapter, PHY_PHY_CONTROL, &tmp); 286238df6492SMark Einon regs_buff[num++] = tmp; 286338df6492SMark Einon et131x_mii_read(adapter, PHY_INTERRUPT_MASK, &tmp); 286438df6492SMark Einon regs_buff[num++] = tmp; 286538df6492SMark Einon et131x_mii_read(adapter, PHY_INTERRUPT_STATUS, &tmp); 286638df6492SMark Einon regs_buff[num++] = tmp; 286738df6492SMark Einon et131x_mii_read(adapter, PHY_PHY_STATUS, &tmp); 286838df6492SMark Einon regs_buff[num++] = tmp; 286938df6492SMark Einon et131x_mii_read(adapter, PHY_LED_1, &tmp); 287038df6492SMark Einon regs_buff[num++] = tmp; 287138df6492SMark Einon et131x_mii_read(adapter, PHY_LED_2, &tmp); 287238df6492SMark Einon regs_buff[num++] = tmp; 287338df6492SMark Einon 287438df6492SMark Einon /* Global regs */ 287538df6492SMark Einon regs_buff[num++] = readl(&aregs->global.txq_start_addr); 287638df6492SMark Einon regs_buff[num++] = readl(&aregs->global.txq_end_addr); 287738df6492SMark Einon regs_buff[num++] = readl(&aregs->global.rxq_start_addr); 287838df6492SMark Einon regs_buff[num++] = readl(&aregs->global.rxq_end_addr); 287938df6492SMark Einon regs_buff[num++] = readl(&aregs->global.pm_csr); 288038df6492SMark Einon regs_buff[num++] = adapter->stats.interrupt_status; 288138df6492SMark Einon regs_buff[num++] = readl(&aregs->global.int_mask); 288238df6492SMark Einon regs_buff[num++] = readl(&aregs->global.int_alias_clr_en); 288338df6492SMark Einon regs_buff[num++] = readl(&aregs->global.int_status_alias); 288438df6492SMark Einon regs_buff[num++] = readl(&aregs->global.sw_reset); 288538df6492SMark Einon regs_buff[num++] = readl(&aregs->global.slv_timer); 288638df6492SMark Einon regs_buff[num++] = readl(&aregs->global.msi_config); 288738df6492SMark Einon regs_buff[num++] = readl(&aregs->global.loopback); 288838df6492SMark Einon regs_buff[num++] = readl(&aregs->global.watchdog_timer); 288938df6492SMark Einon 289038df6492SMark Einon /* TXDMA regs */ 289138df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.csr); 289238df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.pr_base_hi); 289338df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.pr_base_lo); 289438df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.pr_num_des); 289538df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.txq_wr_addr); 289638df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.txq_wr_addr_ext); 289738df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.txq_rd_addr); 289838df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.dma_wb_base_hi); 289938df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.dma_wb_base_lo); 290038df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.service_request); 290138df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.service_complete); 290238df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.cache_rd_index); 290338df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.cache_wr_index); 290438df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.tx_dma_error); 290538df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.desc_abort_cnt); 290638df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.payload_abort_cnt); 290738df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.writeback_abort_cnt); 290838df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.desc_timeout_cnt); 290938df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.payload_timeout_cnt); 291038df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.writeback_timeout_cnt); 291138df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.desc_error_cnt); 291238df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.payload_error_cnt); 291338df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.writeback_error_cnt); 291438df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.dropped_tlp_cnt); 291538df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.new_service_complete); 291638df6492SMark Einon regs_buff[num++] = readl(&aregs->txdma.ethernet_packet_cnt); 291738df6492SMark Einon 291838df6492SMark Einon /* RXDMA regs */ 291938df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.csr); 292038df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.dma_wb_base_hi); 292138df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.dma_wb_base_lo); 292238df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.num_pkt_done); 292338df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.max_pkt_time); 292438df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.rxq_rd_addr); 292538df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.rxq_rd_addr_ext); 292638df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.rxq_wr_addr); 292738df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_base_hi); 292838df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_base_lo); 292938df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_num_des); 293038df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_avail_offset); 293138df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_full_offset); 293238df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_access_index); 293338df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.psr_min_des); 293438df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_base_lo); 293538df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_base_hi); 293638df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_num_des); 293738df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_avail_offset); 293838df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_full_offset); 293938df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_rd_index); 294038df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr0_min_des); 294138df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_base_lo); 294238df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_base_hi); 294338df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_num_des); 294438df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_avail_offset); 294538df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_full_offset); 294638df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_rd_index); 294738df6492SMark Einon regs_buff[num++] = readl(&aregs->rxdma.fbr1_min_des); 294838df6492SMark Einon } 294938df6492SMark Einon 295038df6492SMark Einon static void et131x_get_drvinfo(struct net_device *netdev, 295138df6492SMark Einon struct ethtool_drvinfo *info) 295238df6492SMark Einon { 295338df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 295438df6492SMark Einon 2955f029c781SWolfram Sang strscpy(info->driver, DRIVER_NAME, sizeof(info->driver)); 2956f029c781SWolfram Sang strscpy(info->bus_info, pci_name(adapter->pdev), 295738df6492SMark Einon sizeof(info->bus_info)); 295838df6492SMark Einon } 295938df6492SMark Einon 29601eff7002SJulia Lawall static const struct ethtool_ops et131x_ethtool_ops = { 296138df6492SMark Einon .get_drvinfo = et131x_get_drvinfo, 296238df6492SMark Einon .get_regs_len = et131x_get_regs_len, 296338df6492SMark Einon .get_regs = et131x_get_regs, 296438df6492SMark Einon .get_link = ethtool_op_get_link, 2965adc01582SPhilippe Reynes .get_link_ksettings = phy_ethtool_get_link_ksettings, 2966adc01582SPhilippe Reynes .set_link_ksettings = phy_ethtool_set_link_ksettings, 296738df6492SMark Einon }; 296838df6492SMark Einon 296938df6492SMark Einon /* et131x_hwaddr_init - set up the MAC Address */ 297038df6492SMark Einon static void et131x_hwaddr_init(struct et131x_adapter *adapter) 297138df6492SMark Einon { 297238df6492SMark Einon /* If have our default mac from init and no mac address from 297338df6492SMark Einon * EEPROM then we need to generate the last octet and set it on the 297438df6492SMark Einon * device 297538df6492SMark Einon */ 297638df6492SMark Einon if (is_zero_ether_addr(adapter->rom_addr)) { 297738df6492SMark Einon /* We need to randomly generate the last octet so we 297838df6492SMark Einon * decrease our chances of setting the mac address to 297938df6492SMark Einon * same as another one of our cards in the system 298038df6492SMark Einon */ 298138df6492SMark Einon get_random_bytes(&adapter->addr[5], 1); 298238df6492SMark Einon /* We have the default value in the register we are 298338df6492SMark Einon * working with so we need to copy the current 298438df6492SMark Einon * address into the permanent address 298538df6492SMark Einon */ 298638df6492SMark Einon ether_addr_copy(adapter->rom_addr, adapter->addr); 298738df6492SMark Einon } else { 298838df6492SMark Einon /* We do not have an override address, so set the 298938df6492SMark Einon * current address to the permanent address and add 299038df6492SMark Einon * it to the device 299138df6492SMark Einon */ 299238df6492SMark Einon ether_addr_copy(adapter->addr, adapter->rom_addr); 299338df6492SMark Einon } 299438df6492SMark Einon } 299538df6492SMark Einon 299638df6492SMark Einon static int et131x_pci_init(struct et131x_adapter *adapter, 299738df6492SMark Einon struct pci_dev *pdev) 299838df6492SMark Einon { 299938df6492SMark Einon u16 max_payload; 300038df6492SMark Einon int i, rc; 300138df6492SMark Einon 300238df6492SMark Einon rc = et131x_init_eeprom(adapter); 300338df6492SMark Einon if (rc < 0) 300438df6492SMark Einon goto out; 300538df6492SMark Einon 300638df6492SMark Einon if (!pci_is_pcie(pdev)) { 300738df6492SMark Einon dev_err(&pdev->dev, "Missing PCIe capabilities\n"); 300838df6492SMark Einon goto err_out; 300938df6492SMark Einon } 301038df6492SMark Einon 301138df6492SMark Einon /* Program the Ack/Nak latency and replay timers */ 301238df6492SMark Einon max_payload = pdev->pcie_mpss; 301338df6492SMark Einon 301438df6492SMark Einon if (max_payload < 2) { 301538df6492SMark Einon static const u16 acknak[2] = { 0x76, 0xD0 }; 301638df6492SMark Einon static const u16 replay[2] = { 0x1E0, 0x2ED }; 301738df6492SMark Einon 301838df6492SMark Einon if (pci_write_config_word(pdev, ET1310_PCI_ACK_NACK, 301938df6492SMark Einon acknak[max_payload])) { 302038df6492SMark Einon dev_err(&pdev->dev, 302138df6492SMark Einon "Could not write PCI config space for ACK/NAK\n"); 302238df6492SMark Einon goto err_out; 302338df6492SMark Einon } 302438df6492SMark Einon if (pci_write_config_word(pdev, ET1310_PCI_REPLAY, 302538df6492SMark Einon replay[max_payload])) { 302638df6492SMark Einon dev_err(&pdev->dev, 302738df6492SMark Einon "Could not write PCI config space for Replay Timer\n"); 302838df6492SMark Einon goto err_out; 302938df6492SMark Einon } 303038df6492SMark Einon } 303138df6492SMark Einon 303238df6492SMark Einon /* l0s and l1 latency timers. We are using default values. 303338df6492SMark Einon * Representing 001 for L0s and 010 for L1 303438df6492SMark Einon */ 303538df6492SMark Einon if (pci_write_config_byte(pdev, ET1310_PCI_L0L1LATENCY, 0x11)) { 303638df6492SMark Einon dev_err(&pdev->dev, 303738df6492SMark Einon "Could not write PCI config space for Latency Timers\n"); 303838df6492SMark Einon goto err_out; 303938df6492SMark Einon } 304038df6492SMark Einon 304138df6492SMark Einon /* Change the max read size to 2k */ 304238df6492SMark Einon if (pcie_set_readrq(pdev, 2048)) { 304338df6492SMark Einon dev_err(&pdev->dev, 304438df6492SMark Einon "Couldn't change PCI config space for Max read size\n"); 304538df6492SMark Einon goto err_out; 304638df6492SMark Einon } 304738df6492SMark Einon 304838df6492SMark Einon /* Get MAC address from config space if an eeprom exists, otherwise 304938df6492SMark Einon * the MAC address there will not be valid 305038df6492SMark Einon */ 305138df6492SMark Einon if (!adapter->has_eeprom) { 305238df6492SMark Einon et131x_hwaddr_init(adapter); 305338df6492SMark Einon return 0; 305438df6492SMark Einon } 305538df6492SMark Einon 305638df6492SMark Einon for (i = 0; i < ETH_ALEN; i++) { 305738df6492SMark Einon if (pci_read_config_byte(pdev, ET1310_PCI_MAC_ADDRESS + i, 305838df6492SMark Einon adapter->rom_addr + i)) { 305938df6492SMark Einon dev_err(&pdev->dev, "Could not read PCI config space for MAC address\n"); 306038df6492SMark Einon goto err_out; 306138df6492SMark Einon } 306238df6492SMark Einon } 306338df6492SMark Einon ether_addr_copy(adapter->addr, adapter->rom_addr); 306438df6492SMark Einon out: 306538df6492SMark Einon return rc; 306638df6492SMark Einon err_out: 306738df6492SMark Einon rc = -EIO; 306838df6492SMark Einon goto out; 306938df6492SMark Einon } 307038df6492SMark Einon 307138df6492SMark Einon /* et131x_error_timer_handler 307238df6492SMark Einon * @data: timer-specific variable; here a pointer to our adapter structure 307338df6492SMark Einon * 307438df6492SMark Einon * The routine called when the error timer expires, to track the number of 307538df6492SMark Einon * recurring errors. 307638df6492SMark Einon */ 3077e99e88a9SKees Cook static void et131x_error_timer_handler(struct timer_list *t) 307838df6492SMark Einon { 3079e99e88a9SKees Cook struct et131x_adapter *adapter = from_timer(adapter, t, error_timer); 3080a0bbb9feSPhilippe Reynes struct phy_device *phydev = adapter->netdev->phydev; 308138df6492SMark Einon 308238df6492SMark Einon if (et1310_in_phy_coma(adapter)) { 308338df6492SMark Einon /* Bring the device immediately out of coma, to 308438df6492SMark Einon * prevent it from sleeping indefinitely, this 308538df6492SMark Einon * mechanism could be improved! 308638df6492SMark Einon */ 308738df6492SMark Einon et1310_disable_phy_coma(adapter); 308838df6492SMark Einon adapter->boot_coma = 20; 308938df6492SMark Einon } else { 309038df6492SMark Einon et1310_update_macstat_host_counters(adapter); 309138df6492SMark Einon } 309238df6492SMark Einon 309338df6492SMark Einon if (!phydev->link && adapter->boot_coma < 11) 309438df6492SMark Einon adapter->boot_coma++; 309538df6492SMark Einon 309638df6492SMark Einon if (adapter->boot_coma == 10) { 309738df6492SMark Einon if (!phydev->link) { 309838df6492SMark Einon if (!et1310_in_phy_coma(adapter)) { 309938df6492SMark Einon /* NOTE - This was originally a 'sync with 310038df6492SMark Einon * interrupt'. How to do that under Linux? 310138df6492SMark Einon */ 310238df6492SMark Einon et131x_enable_interrupts(adapter); 310338df6492SMark Einon et1310_enable_phy_coma(adapter); 310438df6492SMark Einon } 310538df6492SMark Einon } 310638df6492SMark Einon } 310738df6492SMark Einon 310838df6492SMark Einon /* This is a periodic timer, so reschedule */ 3109bc2f3873SNicholas Mc Guire mod_timer(&adapter->error_timer, jiffies + 3110bc2f3873SNicholas Mc Guire msecs_to_jiffies(TX_ERROR_PERIOD)); 311138df6492SMark Einon } 311238df6492SMark Einon 311338df6492SMark Einon static void et131x_adapter_memory_free(struct et131x_adapter *adapter) 311438df6492SMark Einon { 311538df6492SMark Einon et131x_tx_dma_memory_free(adapter); 311638df6492SMark Einon et131x_rx_dma_memory_free(adapter); 311738df6492SMark Einon } 311838df6492SMark Einon 311938df6492SMark Einon static int et131x_adapter_memory_alloc(struct et131x_adapter *adapter) 312038df6492SMark Einon { 312138df6492SMark Einon int status; 312238df6492SMark Einon 312338df6492SMark Einon status = et131x_tx_dma_memory_alloc(adapter); 312438df6492SMark Einon if (status) { 312538df6492SMark Einon dev_err(&adapter->pdev->dev, 312638df6492SMark Einon "et131x_tx_dma_memory_alloc FAILED\n"); 312738df6492SMark Einon et131x_tx_dma_memory_free(adapter); 312838df6492SMark Einon return status; 312938df6492SMark Einon } 313038df6492SMark Einon 313138df6492SMark Einon status = et131x_rx_dma_memory_alloc(adapter); 313238df6492SMark Einon if (status) { 313338df6492SMark Einon dev_err(&adapter->pdev->dev, 313438df6492SMark Einon "et131x_rx_dma_memory_alloc FAILED\n"); 313538df6492SMark Einon et131x_adapter_memory_free(adapter); 313638df6492SMark Einon return status; 313738df6492SMark Einon } 313838df6492SMark Einon 313938df6492SMark Einon status = et131x_init_recv(adapter); 314038df6492SMark Einon if (status) { 314138df6492SMark Einon dev_err(&adapter->pdev->dev, "et131x_init_recv FAILED\n"); 314238df6492SMark Einon et131x_adapter_memory_free(adapter); 314338df6492SMark Einon } 314438df6492SMark Einon return status; 314538df6492SMark Einon } 314638df6492SMark Einon 314738df6492SMark Einon static void et131x_adjust_link(struct net_device *netdev) 314838df6492SMark Einon { 314938df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 3150a0bbb9feSPhilippe Reynes struct phy_device *phydev = netdev->phydev; 315138df6492SMark Einon 315238df6492SMark Einon if (!phydev) 315338df6492SMark Einon return; 315438df6492SMark Einon if (phydev->link == adapter->link) 315538df6492SMark Einon return; 315638df6492SMark Einon 315738df6492SMark Einon /* Check to see if we are in coma mode and if 315838df6492SMark Einon * so, disable it because we will not be able 315938df6492SMark Einon * to read PHY values until we are out. 316038df6492SMark Einon */ 316138df6492SMark Einon if (et1310_in_phy_coma(adapter)) 316238df6492SMark Einon et1310_disable_phy_coma(adapter); 316338df6492SMark Einon 316438df6492SMark Einon adapter->link = phydev->link; 316538df6492SMark Einon phy_print_status(phydev); 316638df6492SMark Einon 316738df6492SMark Einon if (phydev->link) { 316838df6492SMark Einon adapter->boot_coma = 20; 316938df6492SMark Einon if (phydev->speed == SPEED_10) { 317038df6492SMark Einon u16 register18; 317138df6492SMark Einon 317238df6492SMark Einon et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, 317338df6492SMark Einon ®ister18); 3174e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 317538df6492SMark Einon PHY_MPHY_CONTROL_REG, 317638df6492SMark Einon register18 | 0x4); 3177e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 3178e5a03bfdSAndrew Lunn PHY_INDEX_REG, register18 | 0x8402); 3179e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 3180e5a03bfdSAndrew Lunn PHY_DATA_REG, register18 | 511); 3181e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 318238df6492SMark Einon PHY_MPHY_CONTROL_REG, register18); 318338df6492SMark Einon } 318438df6492SMark Einon 318538df6492SMark Einon et1310_config_flow_control(adapter); 318638df6492SMark Einon 318738df6492SMark Einon if (phydev->speed == SPEED_1000 && 318838df6492SMark Einon adapter->registry_jumbo_packet > 2048) { 318938df6492SMark Einon u16 reg; 319038df6492SMark Einon 319138df6492SMark Einon et131x_mii_read(adapter, PHY_CONFIG, ®); 319238df6492SMark Einon reg &= ~ET_PHY_CONFIG_TX_FIFO_DEPTH; 319338df6492SMark Einon reg |= ET_PHY_CONFIG_FIFO_DEPTH_32; 3194e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 3195e5a03bfdSAndrew Lunn PHY_CONFIG, reg); 319638df6492SMark Einon } 319738df6492SMark Einon 319838df6492SMark Einon et131x_set_rx_dma_timer(adapter); 319938df6492SMark Einon et1310_config_mac_regs2(adapter); 320038df6492SMark Einon } else { 320138df6492SMark Einon adapter->boot_coma = 0; 320238df6492SMark Einon 320338df6492SMark Einon if (phydev->speed == SPEED_10) { 320438df6492SMark Einon u16 register18; 320538df6492SMark Einon 320638df6492SMark Einon et131x_mii_read(adapter, PHY_MPHY_CONTROL_REG, 320738df6492SMark Einon ®ister18); 3208e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 320938df6492SMark Einon PHY_MPHY_CONTROL_REG, 321038df6492SMark Einon register18 | 0x4); 3211e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 321238df6492SMark Einon PHY_INDEX_REG, register18 | 0x8402); 3213e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 321438df6492SMark Einon PHY_DATA_REG, register18 | 511); 3215e5a03bfdSAndrew Lunn et131x_mii_write(adapter, phydev->mdio.addr, 321638df6492SMark Einon PHY_MPHY_CONTROL_REG, register18); 321738df6492SMark Einon } 321838df6492SMark Einon 321938df6492SMark Einon et131x_free_busy_send_packets(adapter); 322038df6492SMark Einon et131x_init_send(adapter); 322138df6492SMark Einon 322238df6492SMark Einon /* Bring the device back to the state it was during 322338df6492SMark Einon * init prior to autonegotiation being complete. This 322438df6492SMark Einon * way, when we get the auto-neg complete interrupt, 322538df6492SMark Einon * we can complete init by calling config_mac_regs2. 322638df6492SMark Einon */ 322738df6492SMark Einon et131x_soft_reset(adapter); 322838df6492SMark Einon 322938df6492SMark Einon et131x_adapter_setup(adapter); 323038df6492SMark Einon 323138df6492SMark Einon et131x_disable_txrx(netdev); 323238df6492SMark Einon et131x_enable_txrx(netdev); 323338df6492SMark Einon } 323438df6492SMark Einon } 323538df6492SMark Einon 323638df6492SMark Einon static int et131x_mii_probe(struct net_device *netdev) 323738df6492SMark Einon { 323838df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 323938df6492SMark Einon struct phy_device *phydev = NULL; 324038df6492SMark Einon 324138df6492SMark Einon phydev = phy_find_first(adapter->mii_bus); 324238df6492SMark Einon if (!phydev) { 324338df6492SMark Einon dev_err(&adapter->pdev->dev, "no PHY found\n"); 324438df6492SMark Einon return -ENODEV; 324538df6492SMark Einon } 324638df6492SMark Einon 324784eff6d1SAndrew Lunn phydev = phy_connect(netdev, phydev_name(phydev), 324838df6492SMark Einon &et131x_adjust_link, PHY_INTERFACE_MODE_MII); 324938df6492SMark Einon 325038df6492SMark Einon if (IS_ERR(phydev)) { 325138df6492SMark Einon dev_err(&adapter->pdev->dev, "Could not attach to PHY\n"); 325238df6492SMark Einon return PTR_ERR(phydev); 325338df6492SMark Einon } 325438df6492SMark Einon 325558056c1eSAndrew Lunn phy_set_max_speed(phydev, SPEED_100); 325638df6492SMark Einon 325738df6492SMark Einon if (adapter->pdev->device != ET131X_PCI_DEVICE_ID_FAST) 325858056c1eSAndrew Lunn phy_set_max_speed(phydev, SPEED_1000); 325938df6492SMark Einon 326038df6492SMark Einon phydev->autoneg = AUTONEG_ENABLE; 326138df6492SMark Einon 32622220943aSAndrew Lunn phy_attached_info(phydev); 326338df6492SMark Einon 326438df6492SMark Einon return 0; 326538df6492SMark Einon } 326638df6492SMark Einon 326738df6492SMark Einon static struct et131x_adapter *et131x_adapter_init(struct net_device *netdev, 326838df6492SMark Einon struct pci_dev *pdev) 326938df6492SMark Einon { 327038df6492SMark Einon static const u8 default_mac[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 }; 327138df6492SMark Einon 327238df6492SMark Einon struct et131x_adapter *adapter; 327338df6492SMark Einon 327438df6492SMark Einon adapter = netdev_priv(netdev); 327538df6492SMark Einon adapter->pdev = pci_dev_get(pdev); 327638df6492SMark Einon adapter->netdev = netdev; 327738df6492SMark Einon 327838df6492SMark Einon spin_lock_init(&adapter->tcb_send_qlock); 327938df6492SMark Einon spin_lock_init(&adapter->tcb_ready_qlock); 328038df6492SMark Einon spin_lock_init(&adapter->rcv_lock); 328138df6492SMark Einon 328238df6492SMark Einon adapter->registry_jumbo_packet = 1514; /* 1514-9216 */ 328338df6492SMark Einon 328438df6492SMark Einon ether_addr_copy(adapter->addr, default_mac); 328538df6492SMark Einon 328638df6492SMark Einon return adapter; 328738df6492SMark Einon } 328838df6492SMark Einon 328938df6492SMark Einon static void et131x_pci_remove(struct pci_dev *pdev) 329038df6492SMark Einon { 329138df6492SMark Einon struct net_device *netdev = pci_get_drvdata(pdev); 329238df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 329338df6492SMark Einon 329438df6492SMark Einon unregister_netdev(netdev); 329538df6492SMark Einon netif_napi_del(&adapter->napi); 3296a0bbb9feSPhilippe Reynes phy_disconnect(netdev->phydev); 329738df6492SMark Einon mdiobus_unregister(adapter->mii_bus); 329838df6492SMark Einon mdiobus_free(adapter->mii_bus); 329938df6492SMark Einon 330038df6492SMark Einon et131x_adapter_memory_free(adapter); 330138df6492SMark Einon iounmap(adapter->regs); 330238df6492SMark Einon pci_dev_put(pdev); 330338df6492SMark Einon 330438df6492SMark Einon free_netdev(netdev); 330538df6492SMark Einon pci_release_regions(pdev); 330638df6492SMark Einon pci_disable_device(pdev); 330738df6492SMark Einon } 330838df6492SMark Einon 330938df6492SMark Einon static void et131x_up(struct net_device *netdev) 331038df6492SMark Einon { 331138df6492SMark Einon et131x_enable_txrx(netdev); 3312a0bbb9feSPhilippe Reynes phy_start(netdev->phydev); 331338df6492SMark Einon } 331438df6492SMark Einon 331538df6492SMark Einon static void et131x_down(struct net_device *netdev) 331638df6492SMark Einon { 331738df6492SMark Einon /* Save the timestamp for the TX watchdog, prevent a timeout */ 3318860e9538SFlorian Westphal netif_trans_update(netdev); 331938df6492SMark Einon 3320a0bbb9feSPhilippe Reynes phy_stop(netdev->phydev); 332138df6492SMark Einon et131x_disable_txrx(netdev); 332238df6492SMark Einon } 332338df6492SMark Einon 332438df6492SMark Einon #ifdef CONFIG_PM_SLEEP 332538df6492SMark Einon static int et131x_suspend(struct device *dev) 332638df6492SMark Einon { 332738df6492SMark Einon struct pci_dev *pdev = to_pci_dev(dev); 332838df6492SMark Einon struct net_device *netdev = pci_get_drvdata(pdev); 332938df6492SMark Einon 333038df6492SMark Einon if (netif_running(netdev)) { 333138df6492SMark Einon netif_device_detach(netdev); 333238df6492SMark Einon et131x_down(netdev); 333338df6492SMark Einon pci_save_state(pdev); 333438df6492SMark Einon } 333538df6492SMark Einon 333638df6492SMark Einon return 0; 333738df6492SMark Einon } 333838df6492SMark Einon 333938df6492SMark Einon static int et131x_resume(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 pci_restore_state(pdev); 334638df6492SMark Einon et131x_up(netdev); 334738df6492SMark Einon netif_device_attach(netdev); 334838df6492SMark Einon } 334938df6492SMark Einon 335038df6492SMark Einon return 0; 335138df6492SMark Einon } 335238df6492SMark Einon #endif 335338df6492SMark Einon 335438df6492SMark Einon static SIMPLE_DEV_PM_OPS(et131x_pm_ops, et131x_suspend, et131x_resume); 335538df6492SMark Einon 335638df6492SMark Einon static irqreturn_t et131x_isr(int irq, void *dev_id) 335738df6492SMark Einon { 335838df6492SMark Einon bool handled = true; 335938df6492SMark Einon bool enable_interrupts = true; 336038df6492SMark Einon struct net_device *netdev = dev_id; 336138df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 336238df6492SMark Einon struct address_map __iomem *iomem = adapter->regs; 336338df6492SMark Einon struct rx_ring *rx_ring = &adapter->rx_ring; 336438df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 336538df6492SMark Einon u32 status; 336638df6492SMark Einon 336738df6492SMark Einon if (!netif_device_present(netdev)) { 336838df6492SMark Einon handled = false; 336938df6492SMark Einon enable_interrupts = false; 337038df6492SMark Einon goto out; 337138df6492SMark Einon } 337238df6492SMark Einon 337338df6492SMark Einon et131x_disable_interrupts(adapter); 337438df6492SMark Einon 337538df6492SMark Einon status = readl(&adapter->regs->global.int_status); 337638df6492SMark Einon 337738df6492SMark Einon if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) 337838df6492SMark Einon status &= ~INT_MASK_ENABLE; 337938df6492SMark Einon else 338038df6492SMark Einon status &= ~INT_MASK_ENABLE_NO_FLOW; 338138df6492SMark Einon 338238df6492SMark Einon /* Make sure this is our interrupt */ 338338df6492SMark Einon if (!status) { 338438df6492SMark Einon handled = false; 338538df6492SMark Einon et131x_enable_interrupts(adapter); 338638df6492SMark Einon goto out; 338738df6492SMark Einon } 338838df6492SMark Einon 338938df6492SMark Einon /* This is our interrupt, so process accordingly */ 339038df6492SMark Einon if (status & ET_INTR_WATCHDOG) { 339138df6492SMark Einon struct tcb *tcb = tx_ring->send_head; 339238df6492SMark Einon 339338df6492SMark Einon if (tcb) 339438df6492SMark Einon if (++tcb->stale > 1) 339538df6492SMark Einon status |= ET_INTR_TXDMA_ISR; 339638df6492SMark Einon 339738df6492SMark Einon if (rx_ring->unfinished_receives) 339838df6492SMark Einon status |= ET_INTR_RXDMA_XFR_DONE; 339938df6492SMark Einon else if (tcb == NULL) 340038df6492SMark Einon writel(0, &adapter->regs->global.watchdog_timer); 340138df6492SMark Einon 340238df6492SMark Einon status &= ~ET_INTR_WATCHDOG; 340338df6492SMark Einon } 340438df6492SMark Einon 340538df6492SMark Einon if (status & (ET_INTR_RXDMA_XFR_DONE | ET_INTR_TXDMA_ISR)) { 340638df6492SMark Einon enable_interrupts = false; 340738df6492SMark Einon napi_schedule(&adapter->napi); 340838df6492SMark Einon } 340938df6492SMark Einon 341038df6492SMark Einon status &= ~(ET_INTR_TXDMA_ISR | ET_INTR_RXDMA_XFR_DONE); 341138df6492SMark Einon 341238df6492SMark Einon if (!status) 341338df6492SMark Einon goto out; 341438df6492SMark Einon 341538df6492SMark Einon if (status & ET_INTR_TXDMA_ERR) { 341638df6492SMark Einon /* Following read also clears the register (COR) */ 341738df6492SMark Einon u32 txdma_err = readl(&iomem->txdma.tx_dma_error); 341838df6492SMark Einon 341938df6492SMark Einon dev_warn(&adapter->pdev->dev, 342038df6492SMark Einon "TXDMA_ERR interrupt, error = %d\n", 342138df6492SMark Einon txdma_err); 342238df6492SMark Einon } 342338df6492SMark Einon 342438df6492SMark Einon if (status & (ET_INTR_RXDMA_FB_R0_LOW | ET_INTR_RXDMA_FB_R1_LOW)) { 342538df6492SMark Einon /* This indicates the number of unused buffers in RXDMA free 342638df6492SMark Einon * buffer ring 0 is <= the limit you programmed. Free buffer 342738df6492SMark Einon * resources need to be returned. Free buffers are consumed as 342838df6492SMark Einon * packets are passed from the network to the host. The host 342938df6492SMark Einon * becomes aware of the packets from the contents of the packet 343038df6492SMark Einon * status ring. This ring is queried when the packet done 343138df6492SMark Einon * interrupt occurs. Packets are then passed to the OS. When 343238df6492SMark Einon * the OS is done with the packets the resources can be 343338df6492SMark Einon * returned to the ET1310 for re-use. This interrupt is one 343438df6492SMark Einon * method of returning resources. 343538df6492SMark Einon */ 343638df6492SMark Einon 343738df6492SMark Einon /* If the user has flow control on, then we will 343838df6492SMark Einon * send a pause packet, otherwise just exit 343938df6492SMark Einon */ 344038df6492SMark Einon if (adapter->flow == FLOW_TXONLY || adapter->flow == FLOW_BOTH) { 344138df6492SMark Einon /* Tell the device to send a pause packet via the back 344238df6492SMark Einon * pressure register (bp req and bp xon/xoff) 344338df6492SMark Einon */ 344438df6492SMark Einon if (!et1310_in_phy_coma(adapter)) 344538df6492SMark Einon writel(3, &iomem->txmac.bp_ctrl); 344638df6492SMark Einon } 344738df6492SMark Einon } 344838df6492SMark Einon 344938df6492SMark Einon /* Handle Packet Status Ring Low Interrupt */ 345038df6492SMark Einon if (status & ET_INTR_RXDMA_STAT_LOW) { 345138df6492SMark Einon /* Same idea as with the two Free Buffer Rings. Packets going 345238df6492SMark Einon * from the network to the host each consume a free buffer 345338df6492SMark Einon * resource and a packet status resource. These resources are 345438df6492SMark Einon * passed to the OS. When the OS is done with the resources, 345538df6492SMark Einon * they need to be returned to the ET1310. This is one method 345638df6492SMark Einon * of returning the resources. 345738df6492SMark Einon */ 345838df6492SMark Einon } 345938df6492SMark Einon 346038df6492SMark Einon if (status & ET_INTR_RXDMA_ERR) { 346138df6492SMark Einon /* The rxdma_error interrupt is sent when a time-out on a 346238df6492SMark Einon * request issued by the JAGCore has occurred or a completion is 346338df6492SMark Einon * returned with an un-successful status. In both cases the 346438df6492SMark Einon * request is considered complete. The JAGCore will 346538df6492SMark Einon * automatically re-try the request in question. Normally 346638df6492SMark Einon * information on events like these are sent to the host using 346738df6492SMark Einon * the "Advanced Error Reporting" capability. This interrupt is 346838df6492SMark Einon * another way of getting similar information. The only thing 346938df6492SMark Einon * required is to clear the interrupt by reading the ISR in the 347038df6492SMark Einon * global resources. The JAGCore will do a re-try on the 347138df6492SMark Einon * request. Normally you should never see this interrupt. If 347238df6492SMark Einon * you start to see this interrupt occurring frequently then 347338df6492SMark Einon * something bad has occurred. A reset might be the thing to do. 347438df6492SMark Einon */ 347538df6492SMark Einon /* TRAP();*/ 347638df6492SMark Einon 347738df6492SMark Einon dev_warn(&adapter->pdev->dev, "RxDMA_ERR interrupt, error %x\n", 347838df6492SMark Einon readl(&iomem->txmac.tx_test)); 347938df6492SMark Einon } 348038df6492SMark Einon 348138df6492SMark Einon /* Handle the Wake on LAN Event */ 348238df6492SMark Einon if (status & ET_INTR_WOL) { 348338df6492SMark Einon /* This is a secondary interrupt for wake on LAN. The driver 348438df6492SMark Einon * should never see this, if it does, something serious is 348538df6492SMark Einon * wrong. 348638df6492SMark Einon */ 348738df6492SMark Einon dev_err(&adapter->pdev->dev, "WAKE_ON_LAN interrupt\n"); 348838df6492SMark Einon } 348938df6492SMark Einon 349038df6492SMark Einon if (status & ET_INTR_TXMAC) { 349138df6492SMark Einon u32 err = readl(&iomem->txmac.err); 349238df6492SMark Einon 349338df6492SMark Einon /* When any of the errors occur and TXMAC generates an 349438df6492SMark Einon * interrupt to report these errors, it usually means that 349538df6492SMark Einon * TXMAC has detected an error in the data stream retrieved 349638df6492SMark Einon * from the on-chip Tx Q. All of these errors are catastrophic 349738df6492SMark Einon * and TXMAC won't be able to recover data when these errors 349838df6492SMark Einon * occur. In a nutshell, the whole Tx path will have to be reset 349938df6492SMark Einon * and re-configured afterwards. 350038df6492SMark Einon */ 350138df6492SMark Einon dev_warn(&adapter->pdev->dev, "TXMAC interrupt, error 0x%08x\n", 350238df6492SMark Einon err); 350338df6492SMark Einon 350438df6492SMark Einon /* If we are debugging, we want to see this error, otherwise we 350538df6492SMark Einon * just want the device to be reset and continue 350638df6492SMark Einon */ 350738df6492SMark Einon } 350838df6492SMark Einon 350938df6492SMark Einon if (status & ET_INTR_RXMAC) { 351038df6492SMark Einon /* These interrupts are catastrophic to the device, what we need 351138df6492SMark Einon * to do is disable the interrupts and set the flag to cause us 351238df6492SMark Einon * to reset so we can solve this issue. 351338df6492SMark Einon */ 351438df6492SMark Einon dev_warn(&adapter->pdev->dev, 351538df6492SMark Einon "RXMAC interrupt, error 0x%08x. Requesting reset\n", 351638df6492SMark Einon readl(&iomem->rxmac.err_reg)); 351738df6492SMark Einon 351838df6492SMark Einon dev_warn(&adapter->pdev->dev, 351938df6492SMark Einon "Enable 0x%08x, Diag 0x%08x\n", 352038df6492SMark Einon readl(&iomem->rxmac.ctrl), 352138df6492SMark Einon readl(&iomem->rxmac.rxq_diag)); 352238df6492SMark Einon 352338df6492SMark Einon /* If we are debugging, we want to see this error, otherwise we 352438df6492SMark Einon * just want the device to be reset and continue 352538df6492SMark Einon */ 352638df6492SMark Einon } 352738df6492SMark Einon 352838df6492SMark Einon if (status & ET_INTR_MAC_STAT) { 352938df6492SMark Einon /* This means at least one of the un-masked counters in the 353038df6492SMark Einon * MAC_STAT block has rolled over. Use this to maintain the top, 353138df6492SMark Einon * software managed bits of the counter(s). 353238df6492SMark Einon */ 353338df6492SMark Einon et1310_handle_macstat_interrupt(adapter); 353438df6492SMark Einon } 353538df6492SMark Einon 353638df6492SMark Einon if (status & ET_INTR_SLV_TIMEOUT) { 353738df6492SMark Einon /* This means a timeout has occurred on a read or write request 353838df6492SMark Einon * to one of the JAGCore registers. The Global Resources block 353938df6492SMark Einon * has terminated the request and on a read request, returned a 354038df6492SMark Einon * "fake" value. The most likely reasons are: Bad Address or the 354138df6492SMark Einon * addressed module is in a power-down state and can't respond. 354238df6492SMark Einon */ 354338df6492SMark Einon } 354438df6492SMark Einon 354538df6492SMark Einon out: 354638df6492SMark Einon if (enable_interrupts) 354738df6492SMark Einon et131x_enable_interrupts(adapter); 354838df6492SMark Einon 354938df6492SMark Einon return IRQ_RETVAL(handled); 355038df6492SMark Einon } 355138df6492SMark Einon 355238df6492SMark Einon static int et131x_poll(struct napi_struct *napi, int budget) 355338df6492SMark Einon { 355438df6492SMark Einon struct et131x_adapter *adapter = 355538df6492SMark Einon container_of(napi, struct et131x_adapter, napi); 355638df6492SMark Einon int work_done = et131x_handle_recv_pkts(adapter, budget); 355738df6492SMark Einon 355838df6492SMark Einon et131x_handle_send_pkts(adapter); 355938df6492SMark Einon 356038df6492SMark Einon if (work_done < budget) { 35616ad20165SEric Dumazet napi_complete_done(&adapter->napi, work_done); 356238df6492SMark Einon et131x_enable_interrupts(adapter); 356338df6492SMark Einon } 356438df6492SMark Einon 356538df6492SMark Einon return work_done; 356638df6492SMark Einon } 356738df6492SMark Einon 356838df6492SMark Einon /* et131x_stats - Return the current device statistics */ 356938df6492SMark Einon static struct net_device_stats *et131x_stats(struct net_device *netdev) 357038df6492SMark Einon { 357138df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 357238df6492SMark Einon struct net_device_stats *stats = &adapter->netdev->stats; 357338df6492SMark Einon struct ce_stats *devstat = &adapter->stats; 357438df6492SMark Einon 357538df6492SMark Einon stats->rx_errors = devstat->rx_length_errs + 357638df6492SMark Einon devstat->rx_align_errs + 357738df6492SMark Einon devstat->rx_crc_errs + 357838df6492SMark Einon devstat->rx_code_violations + 357938df6492SMark Einon devstat->rx_other_errs; 358038df6492SMark Einon stats->tx_errors = devstat->tx_max_pkt_errs; 358138df6492SMark Einon stats->multicast = devstat->multicast_pkts_rcvd; 358238df6492SMark Einon stats->collisions = devstat->tx_collisions; 358338df6492SMark Einon 358438df6492SMark Einon stats->rx_length_errors = devstat->rx_length_errs; 358538df6492SMark Einon stats->rx_over_errors = devstat->rx_overflows; 358638df6492SMark Einon stats->rx_crc_errors = devstat->rx_crc_errs; 358738df6492SMark Einon stats->rx_dropped = devstat->rcvd_pkts_dropped; 358838df6492SMark Einon 358938df6492SMark Einon /* NOTE: Not used, can't find analogous statistics */ 359038df6492SMark Einon /* stats->rx_frame_errors = devstat->; */ 359138df6492SMark Einon /* stats->rx_fifo_errors = devstat->; */ 359238df6492SMark Einon /* stats->rx_missed_errors = devstat->; */ 359338df6492SMark Einon 359438df6492SMark Einon /* stats->tx_aborted_errors = devstat->; */ 359538df6492SMark Einon /* stats->tx_carrier_errors = devstat->; */ 359638df6492SMark Einon /* stats->tx_fifo_errors = devstat->; */ 359738df6492SMark Einon /* stats->tx_heartbeat_errors = devstat->; */ 359838df6492SMark Einon /* stats->tx_window_errors = devstat->; */ 359938df6492SMark Einon return stats; 360038df6492SMark Einon } 360138df6492SMark Einon 360238df6492SMark Einon static int et131x_open(struct net_device *netdev) 360338df6492SMark Einon { 360438df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 360538df6492SMark Einon struct pci_dev *pdev = adapter->pdev; 360638df6492SMark Einon unsigned int irq = pdev->irq; 360738df6492SMark Einon int result; 360838df6492SMark Einon 360938df6492SMark Einon /* Start the timer to track NIC errors */ 3610e99e88a9SKees Cook timer_setup(&adapter->error_timer, et131x_error_timer_handler, 0); 3611bc2f3873SNicholas Mc Guire adapter->error_timer.expires = jiffies + 3612bc2f3873SNicholas Mc Guire msecs_to_jiffies(TX_ERROR_PERIOD); 361338df6492SMark Einon add_timer(&adapter->error_timer); 361438df6492SMark Einon 361538df6492SMark Einon result = request_irq(irq, et131x_isr, 361638df6492SMark Einon IRQF_SHARED, netdev->name, netdev); 361738df6492SMark Einon if (result) { 361838df6492SMark Einon dev_err(&pdev->dev, "could not register IRQ %d\n", irq); 361938df6492SMark Einon return result; 362038df6492SMark Einon } 362138df6492SMark Einon 362238df6492SMark Einon adapter->flags |= FMP_ADAPTER_INTERRUPT_IN_USE; 362338df6492SMark Einon 362438df6492SMark Einon napi_enable(&adapter->napi); 362538df6492SMark Einon 362638df6492SMark Einon et131x_up(netdev); 362738df6492SMark Einon 362838df6492SMark Einon return result; 362938df6492SMark Einon } 363038df6492SMark Einon 363138df6492SMark Einon static int et131x_close(struct net_device *netdev) 363238df6492SMark Einon { 363338df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 363438df6492SMark Einon 363538df6492SMark Einon et131x_down(netdev); 363638df6492SMark Einon napi_disable(&adapter->napi); 363738df6492SMark Einon 363838df6492SMark Einon adapter->flags &= ~FMP_ADAPTER_INTERRUPT_IN_USE; 363938df6492SMark Einon free_irq(adapter->pdev->irq, netdev); 364038df6492SMark Einon 364138df6492SMark Einon /* Stop the error timer */ 364238df6492SMark Einon return del_timer_sync(&adapter->error_timer); 364338df6492SMark Einon } 364438df6492SMark Einon 364538df6492SMark Einon /* et131x_set_packet_filter - Configures the Rx Packet filtering */ 364638df6492SMark Einon static int et131x_set_packet_filter(struct et131x_adapter *adapter) 364738df6492SMark Einon { 364838df6492SMark Einon int filter = adapter->packet_filter; 364938df6492SMark Einon u32 ctrl; 365038df6492SMark Einon u32 pf_ctrl; 365138df6492SMark Einon 365238df6492SMark Einon ctrl = readl(&adapter->regs->rxmac.ctrl); 365338df6492SMark Einon pf_ctrl = readl(&adapter->regs->rxmac.pf_ctrl); 365438df6492SMark Einon 365538df6492SMark Einon /* Default to disabled packet filtering */ 365638df6492SMark Einon ctrl |= 0x04; 365738df6492SMark Einon 365838df6492SMark Einon /* Set us to be in promiscuous mode so we receive everything, this 365938df6492SMark Einon * is also true when we get a packet filter of 0 366038df6492SMark Einon */ 366138df6492SMark Einon if ((filter & ET131X_PACKET_TYPE_PROMISCUOUS) || filter == 0) 366238df6492SMark Einon pf_ctrl &= ~7; /* Clear filter bits */ 366338df6492SMark Einon else { 366438df6492SMark Einon /* Set us up with Multicast packet filtering. Three cases are 366538df6492SMark Einon * possible - (1) we have a multi-cast list, (2) we receive ALL 366638df6492SMark Einon * multicast entries or (3) we receive none. 366738df6492SMark Einon */ 366838df6492SMark Einon if (filter & ET131X_PACKET_TYPE_ALL_MULTICAST) 366938df6492SMark Einon pf_ctrl &= ~2; /* Multicast filter bit */ 367038df6492SMark Einon else { 367138df6492SMark Einon et1310_setup_device_for_multicast(adapter); 367238df6492SMark Einon pf_ctrl |= 2; 367338df6492SMark Einon ctrl &= ~0x04; 367438df6492SMark Einon } 367538df6492SMark Einon 367638df6492SMark Einon /* Set us up with Unicast packet filtering */ 367738df6492SMark Einon if (filter & ET131X_PACKET_TYPE_DIRECTED) { 367838df6492SMark Einon et1310_setup_device_for_unicast(adapter); 367938df6492SMark Einon pf_ctrl |= 4; 368038df6492SMark Einon ctrl &= ~0x04; 368138df6492SMark Einon } 368238df6492SMark Einon 368338df6492SMark Einon /* Set us up with Broadcast packet filtering */ 368438df6492SMark Einon if (filter & ET131X_PACKET_TYPE_BROADCAST) { 368538df6492SMark Einon pf_ctrl |= 1; /* Broadcast filter bit */ 368638df6492SMark Einon ctrl &= ~0x04; 368738df6492SMark Einon } else { 368838df6492SMark Einon pf_ctrl &= ~1; 368938df6492SMark Einon } 369038df6492SMark Einon 369138df6492SMark Einon /* Setup the receive mac configuration registers - Packet 369238df6492SMark Einon * Filter control + the enable / disable for packet filter 369338df6492SMark Einon * in the control reg. 369438df6492SMark Einon */ 369538df6492SMark Einon writel(pf_ctrl, &adapter->regs->rxmac.pf_ctrl); 369638df6492SMark Einon writel(ctrl, &adapter->regs->rxmac.ctrl); 369738df6492SMark Einon } 369838df6492SMark Einon return 0; 369938df6492SMark Einon } 370038df6492SMark Einon 370138df6492SMark Einon static void et131x_multicast(struct net_device *netdev) 370238df6492SMark Einon { 370338df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 370438df6492SMark Einon int packet_filter; 370538df6492SMark Einon struct netdev_hw_addr *ha; 370638df6492SMark Einon int i; 370738df6492SMark Einon 370838df6492SMark Einon /* Before we modify the platform-independent filter flags, store them 370938df6492SMark Einon * locally. This allows us to determine if anything's changed and if 371038df6492SMark Einon * we even need to bother the hardware 371138df6492SMark Einon */ 371238df6492SMark Einon packet_filter = adapter->packet_filter; 371338df6492SMark Einon 371438df6492SMark Einon /* Clear the 'multicast' flag locally; because we only have a single 371538df6492SMark Einon * flag to check multicast, and multiple multicast addresses can be 371638df6492SMark Einon * set, this is the easiest way to determine if more than one 371738df6492SMark Einon * multicast address is being set. 371838df6492SMark Einon */ 371938df6492SMark Einon packet_filter &= ~ET131X_PACKET_TYPE_MULTICAST; 372038df6492SMark Einon 372138df6492SMark Einon /* Check the net_device flags and set the device independent flags 372238df6492SMark Einon * accordingly 372338df6492SMark Einon */ 372438df6492SMark Einon if (netdev->flags & IFF_PROMISC) 372538df6492SMark Einon adapter->packet_filter |= ET131X_PACKET_TYPE_PROMISCUOUS; 372638df6492SMark Einon else 372738df6492SMark Einon adapter->packet_filter &= ~ET131X_PACKET_TYPE_PROMISCUOUS; 372838df6492SMark Einon 372938df6492SMark Einon if ((netdev->flags & IFF_ALLMULTI) || 373038df6492SMark Einon (netdev_mc_count(netdev) > NIC_MAX_MCAST_LIST)) 373138df6492SMark Einon adapter->packet_filter |= ET131X_PACKET_TYPE_ALL_MULTICAST; 373238df6492SMark Einon 373338df6492SMark Einon if (netdev_mc_count(netdev) < 1) { 373438df6492SMark Einon adapter->packet_filter &= ~ET131X_PACKET_TYPE_ALL_MULTICAST; 373538df6492SMark Einon adapter->packet_filter &= ~ET131X_PACKET_TYPE_MULTICAST; 373638df6492SMark Einon } else { 373738df6492SMark Einon adapter->packet_filter |= ET131X_PACKET_TYPE_MULTICAST; 373838df6492SMark Einon } 373938df6492SMark Einon 374038df6492SMark Einon /* Set values in the private adapter struct */ 374138df6492SMark Einon i = 0; 374238df6492SMark Einon netdev_for_each_mc_addr(ha, netdev) { 374338df6492SMark Einon if (i == NIC_MAX_MCAST_LIST) 374438df6492SMark Einon break; 374538df6492SMark Einon ether_addr_copy(adapter->multicast_list[i++], ha->addr); 374638df6492SMark Einon } 374738df6492SMark Einon adapter->multicast_addr_count = i; 374838df6492SMark Einon 374938df6492SMark Einon /* Are the new flags different from the previous ones? If not, then no 375038df6492SMark Einon * action is required 375138df6492SMark Einon * 375238df6492SMark Einon * NOTE - This block will always update the multicast_list with the 375338df6492SMark Einon * hardware, even if the addresses aren't the same. 375438df6492SMark Einon */ 375538df6492SMark Einon if (packet_filter != adapter->packet_filter) 375638df6492SMark Einon et131x_set_packet_filter(adapter); 375738df6492SMark Einon } 375838df6492SMark Einon 375938df6492SMark Einon static netdev_tx_t et131x_tx(struct sk_buff *skb, struct net_device *netdev) 376038df6492SMark Einon { 376138df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 376238df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 376338df6492SMark Einon 376499f5a5f2SEric Dumazet /* This driver does not support TSO, it is very unlikely 376599f5a5f2SEric Dumazet * this condition is true. 376699f5a5f2SEric Dumazet */ 376799f5a5f2SEric Dumazet if (unlikely(skb_shinfo(skb)->nr_frags > MAX_TX_DESC_PER_PKT - 2)) { 376899f5a5f2SEric Dumazet if (skb_linearize(skb)) 376999f5a5f2SEric Dumazet goto drop_err; 377099f5a5f2SEric Dumazet } 377138df6492SMark Einon /* stop the queue if it's getting full */ 377238df6492SMark Einon if (tx_ring->used >= NUM_TCB - 1 && !netif_queue_stopped(netdev)) 377338df6492SMark Einon netif_stop_queue(netdev); 377438df6492SMark Einon 377538df6492SMark Einon /* Save the timestamp for the TX timeout watchdog */ 3776860e9538SFlorian Westphal netif_trans_update(netdev); 377738df6492SMark Einon 377838df6492SMark Einon /* TCB is not available */ 377938df6492SMark Einon if (tx_ring->used >= NUM_TCB) 378038df6492SMark Einon goto drop_err; 378138df6492SMark Einon 378238df6492SMark Einon if ((adapter->flags & FMP_ADAPTER_FAIL_SEND_MASK) || 378338df6492SMark Einon !netif_carrier_ok(netdev)) 378438df6492SMark Einon goto drop_err; 378538df6492SMark Einon 378638df6492SMark Einon if (send_packet(skb, adapter)) 378738df6492SMark Einon goto drop_err; 378838df6492SMark Einon 378938df6492SMark Einon return NETDEV_TX_OK; 379038df6492SMark Einon 379138df6492SMark Einon drop_err: 379238df6492SMark Einon dev_kfree_skb_any(skb); 379338df6492SMark Einon adapter->netdev->stats.tx_dropped++; 379438df6492SMark Einon return NETDEV_TX_OK; 379538df6492SMark Einon } 379638df6492SMark Einon 379738df6492SMark Einon /* et131x_tx_timeout - Timeout handler 379838df6492SMark Einon * 379938df6492SMark Einon * The handler called when a Tx request times out. The timeout period is 380038df6492SMark Einon * specified by the 'tx_timeo" element in the net_device structure (see 380138df6492SMark Einon * et131x_alloc_device() to see how this value is set). 380238df6492SMark Einon */ 38030290bd29SMichael S. Tsirkin static void et131x_tx_timeout(struct net_device *netdev, unsigned int txqueue) 380438df6492SMark Einon { 380538df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 380638df6492SMark Einon struct tx_ring *tx_ring = &adapter->tx_ring; 380738df6492SMark Einon struct tcb *tcb; 380838df6492SMark Einon unsigned long flags; 380938df6492SMark Einon 381038df6492SMark Einon /* If the device is closed, ignore the timeout */ 3811de702da7SFlorian Fainelli if (!(adapter->flags & FMP_ADAPTER_INTERRUPT_IN_USE)) 381238df6492SMark Einon return; 381338df6492SMark Einon 381438df6492SMark Einon /* Any nonrecoverable hardware error? 381538df6492SMark Einon * Checks adapter->flags for any failure in phy reading 381638df6492SMark Einon */ 381738df6492SMark Einon if (adapter->flags & FMP_ADAPTER_NON_RECOVER_ERROR) 381838df6492SMark Einon return; 381938df6492SMark Einon 382038df6492SMark Einon /* Hardware failure? */ 382138df6492SMark Einon if (adapter->flags & FMP_ADAPTER_HARDWARE_ERROR) { 382238df6492SMark Einon dev_err(&adapter->pdev->dev, "hardware error - reset\n"); 382338df6492SMark Einon return; 382438df6492SMark Einon } 382538df6492SMark Einon 382638df6492SMark Einon /* Is send stuck? */ 382738df6492SMark Einon spin_lock_irqsave(&adapter->tcb_send_qlock, flags); 382838df6492SMark Einon tcb = tx_ring->send_head; 382938df6492SMark Einon spin_unlock_irqrestore(&adapter->tcb_send_qlock, flags); 383038df6492SMark Einon 383138df6492SMark Einon if (tcb) { 383238df6492SMark Einon tcb->count++; 383338df6492SMark Einon 383438df6492SMark Einon if (tcb->count > NIC_SEND_HANG_THRESHOLD) { 383538df6492SMark Einon dev_warn(&adapter->pdev->dev, 383638df6492SMark Einon "Send stuck - reset. tcb->WrIndex %x\n", 383738df6492SMark Einon tcb->index); 383838df6492SMark Einon 383938df6492SMark Einon adapter->netdev->stats.tx_errors++; 384038df6492SMark Einon 384138df6492SMark Einon /* perform reset of tx/rx */ 384238df6492SMark Einon et131x_disable_txrx(netdev); 384338df6492SMark Einon et131x_enable_txrx(netdev); 384438df6492SMark Einon } 384538df6492SMark Einon } 384638df6492SMark Einon } 384738df6492SMark Einon 384838df6492SMark Einon static int et131x_change_mtu(struct net_device *netdev, int new_mtu) 384938df6492SMark Einon { 385038df6492SMark Einon int result = 0; 385138df6492SMark Einon struct et131x_adapter *adapter = netdev_priv(netdev); 385238df6492SMark Einon 385338df6492SMark Einon et131x_disable_txrx(netdev); 385438df6492SMark Einon 385538df6492SMark Einon netdev->mtu = new_mtu; 385638df6492SMark Einon 385738df6492SMark Einon et131x_adapter_memory_free(adapter); 385838df6492SMark Einon 385938df6492SMark Einon /* Set the config parameter for Jumbo Packet support */ 386038df6492SMark Einon adapter->registry_jumbo_packet = new_mtu + 14; 386138df6492SMark Einon et131x_soft_reset(adapter); 386238df6492SMark Einon 386338df6492SMark Einon result = et131x_adapter_memory_alloc(adapter); 386438df6492SMark Einon if (result != 0) { 386538df6492SMark Einon dev_warn(&adapter->pdev->dev, 386638df6492SMark Einon "Change MTU failed; couldn't re-alloc DMA memory\n"); 386738df6492SMark Einon return result; 386838df6492SMark Einon } 386938df6492SMark Einon 387038df6492SMark Einon et131x_init_send(adapter); 387138df6492SMark Einon et131x_hwaddr_init(adapter); 3872f3956ebbSJakub Kicinski eth_hw_addr_set(netdev, adapter->addr); 387338df6492SMark Einon 387438df6492SMark Einon /* Init the device with the new settings */ 387538df6492SMark Einon et131x_adapter_setup(adapter); 387638df6492SMark Einon et131x_enable_txrx(netdev); 387738df6492SMark Einon 387838df6492SMark Einon return result; 387938df6492SMark Einon } 388038df6492SMark Einon 388138df6492SMark Einon static const struct net_device_ops et131x_netdev_ops = { 388238df6492SMark Einon .ndo_open = et131x_open, 388338df6492SMark Einon .ndo_stop = et131x_close, 388438df6492SMark Einon .ndo_start_xmit = et131x_tx, 388538df6492SMark Einon .ndo_set_rx_mode = et131x_multicast, 388638df6492SMark Einon .ndo_tx_timeout = et131x_tx_timeout, 388738df6492SMark Einon .ndo_change_mtu = et131x_change_mtu, 388838df6492SMark Einon .ndo_set_mac_address = eth_mac_addr, 388938df6492SMark Einon .ndo_validate_addr = eth_validate_addr, 389038df6492SMark Einon .ndo_get_stats = et131x_stats, 3891a7605370SArnd Bergmann .ndo_eth_ioctl = phy_do_ioctl, 389238df6492SMark Einon }; 389338df6492SMark Einon 389438df6492SMark Einon static int et131x_pci_setup(struct pci_dev *pdev, 389538df6492SMark Einon const struct pci_device_id *ent) 389638df6492SMark Einon { 389738df6492SMark Einon struct net_device *netdev; 389838df6492SMark Einon struct et131x_adapter *adapter; 389938df6492SMark Einon int rc; 390038df6492SMark Einon 390138df6492SMark Einon rc = pci_enable_device(pdev); 390238df6492SMark Einon if (rc < 0) { 390338df6492SMark Einon dev_err(&pdev->dev, "pci_enable_device() failed\n"); 390438df6492SMark Einon goto out; 390538df6492SMark Einon } 390638df6492SMark Einon 390738df6492SMark Einon /* Perform some basic PCI checks */ 390838df6492SMark Einon if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { 390938df6492SMark Einon dev_err(&pdev->dev, "Can't find PCI device's base address\n"); 391038df6492SMark Einon rc = -ENODEV; 391138df6492SMark Einon goto err_disable; 391238df6492SMark Einon } 391338df6492SMark Einon 391438df6492SMark Einon rc = pci_request_regions(pdev, DRIVER_NAME); 391538df6492SMark Einon if (rc < 0) { 391638df6492SMark Einon dev_err(&pdev->dev, "Can't get PCI resources\n"); 391738df6492SMark Einon goto err_disable; 391838df6492SMark Einon } 391938df6492SMark Einon 392038df6492SMark Einon pci_set_master(pdev); 392138df6492SMark Einon 392238df6492SMark Einon /* Check the DMA addressing support of this device */ 3923948f6b29SChristophe JAILLET rc = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); 3924948f6b29SChristophe JAILLET if (rc) { 392538df6492SMark Einon dev_err(&pdev->dev, "No usable DMA addressing method\n"); 392638df6492SMark Einon goto err_release_res; 392738df6492SMark Einon } 392838df6492SMark Einon 392938df6492SMark Einon netdev = alloc_etherdev(sizeof(struct et131x_adapter)); 393038df6492SMark Einon if (!netdev) { 393138df6492SMark Einon dev_err(&pdev->dev, "Couldn't alloc netdev struct\n"); 393238df6492SMark Einon rc = -ENOMEM; 393338df6492SMark Einon goto err_release_res; 393438df6492SMark Einon } 393538df6492SMark Einon 393638df6492SMark Einon netdev->watchdog_timeo = ET131X_TX_TIMEOUT; 393738df6492SMark Einon netdev->netdev_ops = &et131x_netdev_ops; 393844770e11SJarod Wilson netdev->min_mtu = ET131X_MIN_MTU; 393944770e11SJarod Wilson netdev->max_mtu = ET131X_MAX_MTU; 394038df6492SMark Einon 394138df6492SMark Einon SET_NETDEV_DEV(netdev, &pdev->dev); 394238df6492SMark Einon netdev->ethtool_ops = &et131x_ethtool_ops; 394338df6492SMark Einon 394438df6492SMark Einon adapter = et131x_adapter_init(netdev, pdev); 394538df6492SMark Einon 394638df6492SMark Einon rc = et131x_pci_init(adapter, pdev); 394738df6492SMark Einon if (rc < 0) 394838df6492SMark Einon goto err_free_dev; 394938df6492SMark Einon 395038df6492SMark Einon /* Map the bus-relative registers to system virtual memory */ 395138df6492SMark Einon adapter->regs = pci_ioremap_bar(pdev, 0); 395238df6492SMark Einon if (!adapter->regs) { 395338df6492SMark Einon dev_err(&pdev->dev, "Cannot map device registers\n"); 395438df6492SMark Einon rc = -ENOMEM; 395538df6492SMark Einon goto err_free_dev; 395638df6492SMark Einon } 395738df6492SMark Einon 395838df6492SMark Einon /* If Phy COMA mode was enabled when we went down, disable it here. */ 395938df6492SMark Einon writel(ET_PMCSR_INIT, &adapter->regs->global.pm_csr); 396038df6492SMark Einon 396138df6492SMark Einon et131x_soft_reset(adapter); 396238df6492SMark Einon et131x_disable_interrupts(adapter); 396338df6492SMark Einon 396438df6492SMark Einon rc = et131x_adapter_memory_alloc(adapter); 396538df6492SMark Einon if (rc < 0) { 396638df6492SMark Einon dev_err(&pdev->dev, "Could not alloc adapter memory (DMA)\n"); 396738df6492SMark Einon goto err_iounmap; 396838df6492SMark Einon } 396938df6492SMark Einon 397038df6492SMark Einon et131x_init_send(adapter); 397138df6492SMark Einon 3972*b48b89f9SJakub Kicinski netif_napi_add(netdev, &adapter->napi, et131x_poll); 397338df6492SMark Einon 3974f3956ebbSJakub Kicinski eth_hw_addr_set(netdev, adapter->addr); 397538df6492SMark Einon 397638df6492SMark Einon rc = -ENOMEM; 397738df6492SMark Einon 397838df6492SMark Einon adapter->mii_bus = mdiobus_alloc(); 397938df6492SMark Einon if (!adapter->mii_bus) { 398038df6492SMark Einon dev_err(&pdev->dev, "Alloc of mii_bus struct failed\n"); 398138df6492SMark Einon goto err_mem_free; 398238df6492SMark Einon } 398338df6492SMark Einon 398438df6492SMark Einon adapter->mii_bus->name = "et131x_eth_mii"; 398538df6492SMark Einon snprintf(adapter->mii_bus->id, MII_BUS_ID_SIZE, "%x", 398638df6492SMark Einon (adapter->pdev->bus->number << 8) | adapter->pdev->devfn); 398738df6492SMark Einon adapter->mii_bus->priv = netdev; 398838df6492SMark Einon adapter->mii_bus->read = et131x_mdio_read; 398938df6492SMark Einon adapter->mii_bus->write = et131x_mdio_write; 399038df6492SMark Einon 399138df6492SMark Einon rc = mdiobus_register(adapter->mii_bus); 399238df6492SMark Einon if (rc < 0) { 399338df6492SMark Einon dev_err(&pdev->dev, "failed to register MII bus\n"); 3994e7f4dc35SAndrew Lunn goto err_mdio_free; 399538df6492SMark Einon } 399638df6492SMark Einon 399738df6492SMark Einon rc = et131x_mii_probe(netdev); 399838df6492SMark Einon if (rc < 0) { 399938df6492SMark Einon dev_err(&pdev->dev, "failed to probe MII bus\n"); 400038df6492SMark Einon goto err_mdio_unregister; 400138df6492SMark Einon } 400238df6492SMark Einon 400338df6492SMark Einon et131x_adapter_setup(adapter); 400438df6492SMark Einon 400538df6492SMark Einon /* Init variable for counting how long we do not have link status */ 400638df6492SMark Einon adapter->boot_coma = 0; 400738df6492SMark Einon et1310_disable_phy_coma(adapter); 400838df6492SMark Einon 400938df6492SMark Einon /* We can enable interrupts now 401038df6492SMark Einon * 401138df6492SMark Einon * NOTE - Because registration of interrupt handler is done in the 401238df6492SMark Einon * device's open(), defer enabling device interrupts to that 401338df6492SMark Einon * point 401438df6492SMark Einon */ 401538df6492SMark Einon 401638df6492SMark Einon rc = register_netdev(netdev); 401738df6492SMark Einon if (rc < 0) { 401838df6492SMark Einon dev_err(&pdev->dev, "register_netdev() failed\n"); 401938df6492SMark Einon goto err_phy_disconnect; 402038df6492SMark Einon } 402138df6492SMark Einon 402238df6492SMark Einon /* Register the net_device struct with the PCI subsystem. Save a copy 402338df6492SMark Einon * of the PCI config space for this device now that the device has 402438df6492SMark Einon * been initialized, just in case it needs to be quickly restored. 402538df6492SMark Einon */ 402638df6492SMark Einon pci_set_drvdata(pdev, netdev); 402738df6492SMark Einon out: 402838df6492SMark Einon return rc; 402938df6492SMark Einon 403038df6492SMark Einon err_phy_disconnect: 4031a0bbb9feSPhilippe Reynes phy_disconnect(netdev->phydev); 403238df6492SMark Einon err_mdio_unregister: 403338df6492SMark Einon mdiobus_unregister(adapter->mii_bus); 403438df6492SMark Einon err_mdio_free: 403538df6492SMark Einon mdiobus_free(adapter->mii_bus); 403638df6492SMark Einon err_mem_free: 403738df6492SMark Einon et131x_adapter_memory_free(adapter); 403838df6492SMark Einon err_iounmap: 403938df6492SMark Einon iounmap(adapter->regs); 404038df6492SMark Einon err_free_dev: 404138df6492SMark Einon pci_dev_put(pdev); 404238df6492SMark Einon free_netdev(netdev); 404338df6492SMark Einon err_release_res: 404438df6492SMark Einon pci_release_regions(pdev); 404538df6492SMark Einon err_disable: 404638df6492SMark Einon pci_disable_device(pdev); 404738df6492SMark Einon goto out; 404838df6492SMark Einon } 404938df6492SMark Einon 405038df6492SMark Einon static const struct pci_device_id et131x_pci_table[] = { 405138df6492SMark Einon { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_GIG), 0UL}, 405238df6492SMark Einon { PCI_VDEVICE(ATT, ET131X_PCI_DEVICE_ID_FAST), 0UL}, 405338df6492SMark Einon { 0,} 405438df6492SMark Einon }; 405538df6492SMark Einon MODULE_DEVICE_TABLE(pci, et131x_pci_table); 405638df6492SMark Einon 405738df6492SMark Einon static struct pci_driver et131x_driver = { 405838df6492SMark Einon .name = DRIVER_NAME, 405938df6492SMark Einon .id_table = et131x_pci_table, 406038df6492SMark Einon .probe = et131x_pci_setup, 406138df6492SMark Einon .remove = et131x_pci_remove, 406238df6492SMark Einon .driver.pm = &et131x_pm_ops, 406338df6492SMark Einon }; 406438df6492SMark Einon 406538df6492SMark Einon module_pci_driver(et131x_driver); 4066