3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
9 * Copyright (c) 2011 Mark Einon <mark.einon@gmail.com>
11 *------------------------------------------------------------------------------
15 * This software is provided subject to the following terms and conditions,
16 * which you should read carefully before using the software. Using this
17 * software indicates your acceptance of these terms and conditions. If you do
18 * not agree with these terms and conditions, do not use the software.
20 * Copyright © 2005 Agere Systems Inc.
21 * All rights reserved.
23 * Redistribution and use in source or binary forms, with or without
24 * modifications, are permitted provided that the following conditions are met:
26 * . Redistributions of source code must retain the above copyright notice, this
27 * list of conditions and the following Disclaimer as comments in the code as
28 * well as in the documentation and/or other materials provided with the
31 * . Redistributions in binary form must reproduce the above copyright notice,
32 * this list of conditions and the following Disclaimer in the documentation
33 * and/or other materials provided with the distribution.
35 * . Neither the name of Agere Systems Inc. nor the names of the contributors
36 * may be used to endorse or promote products derived from this software
37 * without specific prior written permission.
41 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
42 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
43 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
44 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
45 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
46 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
47 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
50 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
56 #include <linux/pci.h>
57 #include <linux/init.h>
58 #include <linux/module.h>
59 #include <linux/types.h>
60 #include <linux/kernel.h>
62 #include <linux/sched.h>
63 #include <linux/ptrace.h>
64 #include <linux/slab.h>
65 #include <linux/ctype.h>
66 #include <linux/string.h>
67 #include <linux/timer.h>
68 #include <linux/interrupt.h>
70 #include <linux/delay.h>
71 #include <linux/bitops.h>
73 #include <asm/system.h>
75 #include <linux/netdevice.h>
76 #include <linux/etherdevice.h>
77 #include <linux/skbuff.h>
78 #include <linux/if_arp.h>
79 #include <linux/ioport.h>
80 #include <linux/crc32.h>
81 #include <linux/random.h>
82 #include <linux/phy.h>
86 MODULE_AUTHOR("Victor Soriano <vjsoriano@agere.com>");
87 MODULE_AUTHOR("Mark Einon <mark.einon@gmail.com>");
88 MODULE_LICENSE("Dual BSD/GPL");
89 MODULE_DESCRIPTION("10/100/1000 Base-T Ethernet Driver "
90 "for the ET1310 by Agere Systems");
93 #define MAX_NUM_REGISTER_POLLS 1000
94 #define MAX_NUM_WRITE_RETRIES 2
97 #define COUNTER_WRAP_16_BIT 0x10000
98 #define COUNTER_WRAP_12_BIT 0x1000
101 #define INTERNAL_MEM_SIZE 0x400 /* 1024 of internal memory */
102 #define INTERNAL_MEM_RX_OFFSET 0x1FF /* 50% Tx, 50% Rx */
106 * For interrupts, normal running is:
107 * rxdma_xfr_done, phy_interrupt, mac_stat_interrupt,
108 * watchdog_interrupt & txdma_xfer_done
110 * In both cases, when flow control is enabled for either Tx or bi-direction,
111 * we additional enable rx_fbr0_low and rx_fbr1_low, so we know when the
112 * buffer rings are running low.
114 #define INT_MASK_DISABLE 0xffffffff
116 /* NOTE: Masking out MAC_STAT Interrupt for now...
117 * #define INT_MASK_ENABLE 0xfff6bf17
118 * #define INT_MASK_ENABLE_NO_FLOW 0xfff6bfd7
120 #define INT_MASK_ENABLE 0xfffebf17
121 #define INT_MASK_ENABLE_NO_FLOW 0xfffebfd7
123 /* General defines */
124 /* Packet and header sizes */
125 #define NIC_MIN_PACKET_SIZE 60
127 /* Multicast list size */
128 #define NIC_MAX_MCAST_LIST 128
130 /* Supported Filters */
131 #define ET131X_PACKET_TYPE_DIRECTED 0x0001
132 #define ET131X_PACKET_TYPE_MULTICAST 0x0002
133 #define ET131X_PACKET_TYPE_BROADCAST 0x0004
134 #define ET131X_PACKET_TYPE_PROMISCUOUS 0x0008
135 #define ET131X_PACKET_TYPE_ALL_MULTICAST 0x0010
138 #define ET131X_TX_TIMEOUT (1 * HZ)
139 #define NIC_SEND_HANG_THRESHOLD 0
142 #define fMP_DEST_MULTI 0x00000001
143 #define fMP_DEST_BROAD 0x00000002
145 /* MP_ADAPTER flags */
146 #define fMP_ADAPTER_RECV_LOOKASIDE 0x00000004
147 #define fMP_ADAPTER_INTERRUPT_IN_USE 0x00000008
149 /* MP_SHARED flags */
150 #define fMP_ADAPTER_LOWER_POWER 0x00200000
152 #define fMP_ADAPTER_NON_RECOVER_ERROR 0x00800000
153 #define fMP_ADAPTER_HARDWARE_ERROR 0x04000000
155 #define fMP_ADAPTER_FAIL_SEND_MASK 0x3ff00000
157 /* Some offsets in PCI config space that are actually used. */
158 #define ET1310_PCI_MAX_PYLD 0x4C
159 #define ET1310_PCI_MAC_ADDRESS 0xA4
160 #define ET1310_PCI_EEPROM_STATUS 0xB2
161 #define ET1310_PCI_ACK_NACK 0xC0
162 #define ET1310_PCI_REPLAY 0xC2
163 #define ET1310_PCI_L0L1LATENCY 0xCF
165 /* PCI Product IDs */
166 #define ET131X_PCI_DEVICE_ID_GIG 0xED00 /* ET1310 1000 Base-T 8 */
167 #define ET131X_PCI_DEVICE_ID_FAST 0xED01 /* ET1310 100 Base-T */
169 /* Define order of magnitude converter */
170 #define NANO_IN_A_MICRO 1000
172 #define PARM_RX_NUM_BUFS_DEF 4
173 #define PARM_RX_TIME_INT_DEF 10
174 #define PARM_RX_MEM_END_DEF 0x2bc
175 #define PARM_TX_TIME_INT_DEF 40
176 #define PARM_TX_NUM_BUFS_DEF 4
177 #define PARM_DMA_CACHE_DEF 0
182 #define FBR_CHUNKS 32
184 #define MAX_DESC_PER_RING_RX 1024
186 /* number of RFDs - default and min */
188 #define RFD_LOW_WATER_MARK 40
189 #define NIC_DEFAULT_NUM_RFD 1024
192 #define RFD_LOW_WATER_MARK 20
193 #define NIC_DEFAULT_NUM_RFD 256
197 #define NIC_MIN_NUM_RFD 64
199 #define NUM_PACKETS_HANDLED 256
201 #define ALCATEL_MULTICAST_PKT 0x01000000
202 #define ALCATEL_BROADCAST_PKT 0x02000000
204 /* typedefs for Free Buffer Descriptors */
208 u32 word2
; /* Bits 10-31 reserved, 0-9 descriptor */
211 /* Packet Status Ring Descriptors
215 * top 16 bits are from the Alcatel Status Word as enumerated in
216 * PE-MCXMAC Data Sheet IPD DS54 0210-1 (also IPD-DS80 0205-2)
219 * 1: ipa IP checksum assist
220 * 2: ipp IP checksum pass
221 * 3: tcpa TCP checksum assist
222 * 4: tcpp TCP checksum pass
224 * 6: rxmac_error RXMAC Error Indicator
225 * 7: drop Drop packet
226 * 8: ft Frame Truncated
230 * 16: asw_prev_pkt_dropped e.g. IFG too small on previous
231 * 17: asw_RX_DV_event short receive event detected
232 * 18: asw_false_carrier_event bad carrier since last good packet
233 * 19: asw_code_err one or more nibbles signalled as errors
234 * 20: asw_CRC_err CRC error
235 * 21: asw_len_chk_err frame length field incorrect
236 * 22: asw_too_long frame length > 1518 bytes
237 * 23: asw_OK valid CRC + no code error
238 * 24: asw_multicast has a multicast address
239 * 25: asw_broadcast has a broadcast address
240 * 26: asw_dribble_nibble spurious bits after EOP
241 * 27: asw_control_frame is a control frame
242 * 28: asw_pause_frame is a pause frame
243 * 29: asw_unsupported_op unsupported OP code
244 * 30: asw_VLAN_tag VLAN tag detected
245 * 31: asw_long_evt Rx long event
248 * 0-15: length length in bytes
249 * 16-25: bi Buffer Index
250 * 26-27: ri Ring Index
254 struct pkt_stat_desc
{
259 /* Typedefs for the RX DMA status word */
262 * rx status word 0 holds part of the status bits of the Rx DMA engine
263 * that get copied out to memory by the ET-1310. Word 0 is a 32 bit word
264 * which contains the Free Buffer ring 0 and 1 available offset.
266 * bit 0-9 FBR1 offset
267 * bit 10 Wrap flag for FBR1
268 * bit 16-25 FBR0 offset
269 * bit 26 Wrap flag for FBR0
273 * RXSTAT_WORD1_t structure holds part of the status bits of the Rx DMA engine
274 * that get copied out to memory by the ET-1310. Word 3 is a 32 bit word
275 * which contains the Packet Status Ring available offset.
278 * bit 16-27 PSRoffset
284 * struct rx_status_block is a structure representing the status of the Rx
285 * DMA engine it sits in free memory, and is pointed to by 0x101c / 0x1020
287 struct rx_status_block
{
293 * Structure for look-up table holding free buffer ring pointers, addresses
297 void *virt
[MAX_DESC_PER_RING_RX
];
298 void *buffer1
[MAX_DESC_PER_RING_RX
];
299 void *buffer2
[MAX_DESC_PER_RING_RX
];
300 u32 bus_high
[MAX_DESC_PER_RING_RX
];
301 u32 bus_low
[MAX_DESC_PER_RING_RX
];
303 dma_addr_t ring_physaddr
;
304 void *mem_virtaddrs
[MAX_DESC_PER_RING_RX
/ FBR_CHUNKS
];
305 dma_addr_t mem_physaddrs
[MAX_DESC_PER_RING_RX
/ FBR_CHUNKS
];
306 uint64_t real_physaddr
;
314 * struct rx_ring is the sructure representing the adaptor's local
315 * reference(s) to the rings
317 ******************************************************************************
318 * IMPORTANT NOTE :- fbr_lookup *fbr[NUM_FBRS] uses index 0 to refer to FBR1
319 * and index 1 to refer to FRB0
320 ******************************************************************************
323 struct fbr_lookup
*fbr
[NUM_FBRS
];
324 void *ps_ring_virtaddr
;
325 dma_addr_t ps_ring_physaddr
;
329 struct rx_status_block
*rx_status_block
;
330 dma_addr_t rx_status_bus
;
333 struct list_head recv_list
;
338 bool unfinished_receives
;
340 /* lookaside lists */
341 struct kmem_cache
*recv_lookaside
;
346 * word 2 of the control bits in the Tx Descriptor ring for the ET-1310
348 * 0-15: length of packet
351 * 29-31: VLAN priority
353 * word 3 of the control bits in the Tx Descriptor ring for the ET-1310
355 * 0: last packet in the sequence
356 * 1: first packet in the sequence
357 * 2: interrupt the processor when this pkt sent
358 * 3: Control word - no packet data
359 * 4: Issue half-duplex backpressure : XON/XOFF
360 * 5: send pause frame
361 * 6: Tx frame has error
365 * 10: Packet is a Huge packet
366 * 11: append VLAN tag
367 * 12: IP checksum assist
368 * 13: TCP checksum assist
369 * 14: UDP checksum assist
372 /* struct tx_desc represents each descriptor on the ring */
376 u32 len_vlan
; /* control words how to xmit the */
377 u32 flags
; /* data (detailed above) */
381 * The status of the Tx DMA engine it sits in free memory, and is pointed to
382 * by 0x101c / 0x1020. This is a DMA10 type
385 /* TCB (Transmit Control Block: Host Side) */
387 struct tcb
*next
; /* Next entry in ring */
388 u32 flags
; /* Our flags for the packet */
389 u32 count
; /* Used to spot stuck/lost packets */
390 u32 stale
; /* Used to spot stuck/lost packets */
391 struct sk_buff
*skb
; /* Network skb we are tied to */
392 u32 index
; /* Ring indexes */
396 /* Structure representing our local reference(s) to the ring */
398 /* TCB (Transmit Control Block) memory and lists */
399 struct tcb
*tcb_ring
;
401 /* List of TCBs that are ready to be used */
402 struct tcb
*tcb_qhead
;
403 struct tcb
*tcb_qtail
;
405 /* list of TCBs that are currently being sent. NOTE that access to all
406 * three of these (including used) are controlled via the
407 * TCBSendQLock. This lock should be secured prior to incementing /
408 * decrementing used, or any queue manipulation on send_head /
411 struct tcb
*send_head
;
412 struct tcb
*send_tail
;
415 /* The actual descriptor ring */
416 struct tx_desc
*tx_desc_ring
;
417 dma_addr_t tx_desc_ring_pa
;
419 /* send_idx indicates where we last wrote to in the descriptor ring. */
422 /* The location of the write-back status block */
424 dma_addr_t tx_status_pa
;
426 /* Packets since the last IRQ: used for interrupt coalescing */
430 /* ADAPTER defines */
432 * Do not change these values: if changed, then change also in respective
433 * TXdma and Rxdma engines
435 #define NUM_DESC_PER_RING_TX 512 /* TX Do not change these values */
439 * These values are all superseded by registry entries to facilitate tuning.
440 * Once the desired performance has been achieved, the optimal registry values
441 * should be re-populated to these #defines:
443 #define TX_ERROR_PERIOD 1000
445 #define LO_MARK_PERCENT_FOR_PSR 15
446 #define LO_MARK_PERCENT_FOR_RX 15
448 /* RFD (Receive Frame Descriptor) */
450 struct list_head list_node
;
452 u32 len
; /* total size of receive frame */
459 #define FLOW_TXONLY 1
460 #define FLOW_RXONLY 2
463 /* Struct to define some device statistics */
467 * NOTE: atomic_t types are only guaranteed to store 24-bits; if we
468 * MUST have 32, then we'll need another way to perform atomic
471 u32 unicast_pkts_rcvd
;
472 atomic_t unicast_pkts_xmtd
;
473 u32 multicast_pkts_rcvd
;
474 atomic_t multicast_pkts_xmtd
;
475 u32 broadcast_pkts_rcvd
;
476 atomic_t broadcast_pkts_xmtd
;
477 u32 rcvd_pkts_dropped
;
483 u32 tx_excessive_collisions
;
484 u32 tx_first_collisions
;
485 u32 tx_late_collisions
;
495 u32 rx_code_violations
;
498 u32 synchronous_iterations
;
499 u32 interrupt_status
;
502 /* The private adapter structure */
503 struct et131x_adapter
{
504 struct net_device
*netdev
;
505 struct pci_dev
*pdev
;
506 struct mii_bus
*mii_bus
;
507 struct phy_device
*phydev
;
508 struct work_struct task
;
510 /* Flags that indicate current state of the adapter */
513 /* local link state, to determine if a state change has occurred */
517 u8 rom_addr
[ETH_ALEN
];
525 spinlock_t tcb_send_qlock
;
526 spinlock_t tcb_ready_qlock
;
527 spinlock_t send_hw_lock
;
530 spinlock_t rcv_pend_lock
;
535 /* Packet Filter and look ahead size */
539 u32 multicast_addr_count
;
540 u8 multicast_list
[NIC_MAX_MCAST_LIST
][ETH_ALEN
];
542 /* Pointer to the device's PCI register space */
543 struct address_map __iomem
*regs
;
545 /* Registry parameters */
546 u8 wanted_flow
; /* Flow we want for 802.3x flow control */
547 u32 registry_jumbo_packet
; /* Max supported ethernet packet size */
549 /* Derived from the registry: */
550 u8 flowcontrol
; /* flow control validated by the far-end */
552 /* Minimize init-time */
553 struct timer_list error_timer
;
555 /* variable putting the phy into coma mode when boot up with no cable
556 * plugged in after 5 seconds
560 /* Next two used to save power information at power down. This
561 * information will be used during power up to set up parts of Power
562 * Management in JAGCore
567 /* Tx Memory Variables */
568 struct tx_ring tx_ring
;
570 /* Rx Memory Variables */
571 struct rx_ring rx_ring
;
574 struct ce_stats stats
;
576 struct net_device_stats net_stats
;
579 void et131x_rx_dma_disable(struct et131x_adapter
*adapter
);
580 void et131x_rx_dma_enable(struct et131x_adapter
*adapter
);
581 void et131x_init_send(struct et131x_adapter
*adapter
);
582 void et131x_tx_dma_enable(struct et131x_adapter
*adapter
);
584 /* EEPROM functions */
586 static int eeprom_wait_ready(struct pci_dev
*pdev
, u32
*status
)
592 * 1. Check LBCIF Status Register for bits 6 & 3:2 all equal to 0 and
593 * bits 7,1:0 both equal to 1, at least once after reset.
594 * Subsequent operations need only to check that bits 1:0 are equal
595 * to 1 prior to starting a single byte read/write
598 for (i
= 0; i
< MAX_NUM_REGISTER_POLLS
; i
++) {
599 /* Read registers grouped in DWORD1 */
600 if (pci_read_config_dword(pdev
, LBCIF_DWORD1_GROUP
, ®
))
603 /* I2C idle and Phy Queue Avail both true */
604 if ((reg
& 0x3000) == 0x3000) {
615 * eeprom_write - Write a byte to the ET1310's EEPROM
616 * @adapter: pointer to our private adapter structure
617 * @addr: the address to write
618 * @data: the value to write
620 * Returns 1 for a successful write.
622 static int eeprom_write(struct et131x_adapter
*adapter
, u32 addr
, u8 data
)
624 struct pci_dev
*pdev
= adapter
->pdev
;
634 * For an EEPROM, an I2C single byte write is defined as a START
635 * condition followed by the device address, EEPROM address, one byte
636 * of data and a STOP condition. The STOP condition will trigger the
637 * EEPROM's internally timed write cycle to the nonvolatile memory.
638 * All inputs are disabled during this write cycle and the EEPROM will
639 * not respond to any access until the internal write is complete.
642 err
= eeprom_wait_ready(pdev
, NULL
);
647 * 2. Write to the LBCIF Control Register: bit 7=1, bit 6=1, bit 3=0,
648 * and bits 1:0 both =0. Bit 5 should be set according to the
649 * type of EEPROM being accessed (1=two byte addressing, 0=one
652 if (pci_write_config_byte(pdev
, LBCIF_CONTROL_REGISTER
,
653 LBCIF_CONTROL_LBCIF_ENABLE
| LBCIF_CONTROL_I2C_WRITE
))
658 /* Prepare EEPROM address for Step 3 */
660 for (retries
= 0; retries
< MAX_NUM_WRITE_RETRIES
; retries
++) {
661 /* Write the address to the LBCIF Address Register */
662 if (pci_write_config_dword(pdev
, LBCIF_ADDRESS_REGISTER
, addr
))
665 * Write the data to the LBCIF Data Register (the I2C write
668 if (pci_write_config_byte(pdev
, LBCIF_DATA_REGISTER
, data
))
671 * Monitor bit 1:0 of the LBCIF Status Register. When bits
672 * 1:0 are both equal to 1, the I2C write has completed and the
673 * internal write cycle of the EEPROM is about to start.
674 * (bits 1:0 = 01 is a legal state while waiting from both
675 * equal to 1, but bits 1:0 = 10 is invalid and implies that
676 * something is broken).
678 err
= eeprom_wait_ready(pdev
, &status
);
683 * Check bit 3 of the LBCIF Status Register. If equal to 1,
684 * an error has occurred.Don't break here if we are revision
685 * 1, this is so we do a blind write for load bug.
687 if ((status
& LBCIF_STATUS_GENERAL_ERROR
)
688 && adapter
->pdev
->revision
== 0)
692 * Check bit 2 of the LBCIF Status Register. If equal to 1 an
693 * ACK error has occurred on the address phase of the write.
694 * This could be due to an actual hardware failure or the
695 * EEPROM may still be in its internal write cycle from a
696 * previous write. This write operation was ignored and must be
699 if (status
& LBCIF_STATUS_ACK_ERROR
) {
701 * This could be due to an actual hardware failure
702 * or the EEPROM may still be in its internal write
703 * cycle from a previous write. This write operation
704 * was ignored and must be repeated later.
715 * Set bit 6 of the LBCIF Control Register = 0.
720 if (pci_write_config_byte(pdev
, LBCIF_CONTROL_REGISTER
,
721 LBCIF_CONTROL_LBCIF_ENABLE
))
724 /* Do read until internal ACK_ERROR goes away meaning write
728 pci_write_config_dword(pdev
,
729 LBCIF_ADDRESS_REGISTER
,
732 pci_read_config_dword(pdev
,
733 LBCIF_DATA_REGISTER
, &val
);
734 } while ((val
& 0x00010000) == 0);
735 } while (val
& 0x00040000);
737 if ((val
& 0xFF00) != 0xC000 || index
== 10000)
741 return writeok
? 0 : -EIO
;
745 * eeprom_read - Read a byte from the ET1310's EEPROM
746 * @adapter: pointer to our private adapter structure
747 * @addr: the address from which to read
748 * @pdata: a pointer to a byte in which to store the value of the read
749 * @eeprom_id: the ID of the EEPROM
750 * @addrmode: how the EEPROM is to be accessed
752 * Returns 1 for a successful read
754 static int eeprom_read(struct et131x_adapter
*adapter
, u32 addr
, u8
*pdata
)
756 struct pci_dev
*pdev
= adapter
->pdev
;
761 * A single byte read is similar to the single byte write, with the
762 * exception of the data flow:
765 err
= eeprom_wait_ready(pdev
, NULL
);
769 * Write to the LBCIF Control Register: bit 7=1, bit 6=0, bit 3=0,
770 * and bits 1:0 both =0. Bit 5 should be set according to the type
771 * of EEPROM being accessed (1=two byte addressing, 0=one byte
774 if (pci_write_config_byte(pdev
, LBCIF_CONTROL_REGISTER
,
775 LBCIF_CONTROL_LBCIF_ENABLE
))
778 * Write the address to the LBCIF Address Register (I2C read will
781 if (pci_write_config_dword(pdev
, LBCIF_ADDRESS_REGISTER
, addr
))
784 * Monitor bit 0 of the LBCIF Status Register. When = 1, I2C read
785 * is complete. (if bit 1 =1 and bit 0 stays = 0, a hardware failure
788 err
= eeprom_wait_ready(pdev
, &status
);
792 * Regardless of error status, read data byte from LBCIF Data
797 * Check bit 2 of the LBCIF Status Register. If = 1,
798 * then an error has occurred.
800 return (status
& LBCIF_STATUS_ACK_ERROR
) ? -EIO
: 0;
803 int et131x_init_eeprom(struct et131x_adapter
*adapter
)
805 struct pci_dev
*pdev
= adapter
->pdev
;
808 /* We first need to check the EEPROM Status code located at offset
809 * 0xB2 of config space
811 pci_read_config_byte(pdev
, ET1310_PCI_EEPROM_STATUS
,
814 /* THIS IS A WORKAROUND:
815 * I need to call this function twice to get my card in a
816 * LG M1 Express Dual running. I tried also a msleep before this
817 * function, because I thougth there could be some time condidions
818 * but it didn't work. Call the whole function twice also work.
820 if (pci_read_config_byte(pdev
, ET1310_PCI_EEPROM_STATUS
, &eestatus
)) {
822 "Could not read PCI config space for EEPROM Status\n");
826 /* Determine if the error(s) we care about are present. If they are
827 * present we need to fail.
829 if (eestatus
& 0x4C) {
830 int write_failed
= 0;
831 if (pdev
->revision
== 0x01) {
833 static const u8 eedata
[4] = { 0xFE, 0x13, 0x10, 0xFF };
835 /* Re-write the first 4 bytes if we have an eeprom
836 * present and the revision id is 1, this fixes the
837 * corruption seen with 1310 B Silicon
839 for (i
= 0; i
< 3; i
++)
840 if (eeprom_write(adapter
, i
, eedata
[i
]) < 0)
843 if (pdev
->revision
!= 0x01 || write_failed
) {
845 "Fatal EEPROM Status Error - 0x%04x\n", eestatus
);
847 /* This error could mean that there was an error
848 * reading the eeprom or that the eeprom doesn't exist.
849 * We will treat each case the same and not try to
850 * gather additional information that normally would
851 * come from the eeprom, like MAC Address
853 adapter
->has_eeprom
= 0;
857 adapter
->has_eeprom
= 1;
859 /* Read the EEPROM for information regarding LED behavior. Refer to
860 * ET1310_phy.c, et131x_xcvr_init(), for its use.
862 eeprom_read(adapter
, 0x70, &adapter
->eeprom_data
[0]);
863 eeprom_read(adapter
, 0x71, &adapter
->eeprom_data
[1]);
865 if (adapter
->eeprom_data
[0] != 0xcd)
866 /* Disable all optional features */
867 adapter
->eeprom_data
[1] = 0x00;
875 * et1310_config_mac_regs1 - Initialize the first part of MAC regs
876 * @adapter: pointer to our adapter structure
878 void et1310_config_mac_regs1(struct et131x_adapter
*adapter
)
880 struct mac_regs __iomem
*macregs
= &adapter
->regs
->mac
;
885 /* First we need to reset everything. Write to MAC configuration
886 * register 1 to perform reset.
888 writel(0xC00F0000, ¯egs
->cfg1
);
890 /* Next lets configure the MAC Inter-packet gap register */
891 ipg
= 0x38005860; /* IPG1 0x38 IPG2 0x58 B2B 0x60 */
892 ipg
|= 0x50 << 8; /* ifg enforce 0x50 */
893 writel(ipg
, ¯egs
->ipg
);
895 /* Next lets configure the MAC Half Duplex register */
896 /* BEB trunc 0xA, Ex Defer, Rexmit 0xF Coll 0x37 */
897 writel(0x00A1F037, ¯egs
->hfdp
);
899 /* Next lets configure the MAC Interface Control register */
900 writel(0, ¯egs
->if_ctrl
);
902 /* Let's move on to setting up the mii management configuration */
903 writel(0x07, ¯egs
->mii_mgmt_cfg
); /* Clock reset 0x7 */
905 /* Next lets configure the MAC Station Address register. These
906 * values are read from the EEPROM during initialization and stored
907 * in the adapter structure. We write what is stored in the adapter
908 * structure to the MAC Station Address registers high and low. This
909 * station address is used for generating and checking pause control
912 station2
= (adapter
->addr
[1] << ET_MAC_STATION_ADDR2_OC2_SHIFT
) |
913 (adapter
->addr
[0] << ET_MAC_STATION_ADDR2_OC1_SHIFT
);
914 station1
= (adapter
->addr
[5] << ET_MAC_STATION_ADDR1_OC6_SHIFT
) |
915 (adapter
->addr
[4] << ET_MAC_STATION_ADDR1_OC5_SHIFT
) |
916 (adapter
->addr
[3] << ET_MAC_STATION_ADDR1_OC4_SHIFT
) |
918 writel(station1
, ¯egs
->station_addr_1
);
919 writel(station2
, ¯egs
->station_addr_2
);
921 /* Max ethernet packet in bytes that will passed by the mac without
922 * being truncated. Allow the MAC to pass 4 more than our max packet
923 * size. This is 4 for the Ethernet CRC.
925 * Packets larger than (registry_jumbo_packet) that do not contain a
926 * VLAN ID will be dropped by the Rx function.
928 writel(adapter
->registry_jumbo_packet
+ 4, ¯egs
->max_fm_len
);
930 /* clear out MAC config reset */
931 writel(0, ¯egs
->cfg1
);
935 * et1310_config_mac_regs2 - Initialize the second part of MAC regs
936 * @adapter: pointer to our adapter structure
938 void et1310_config_mac_regs2(struct et131x_adapter
*adapter
)
941 struct mac_regs __iomem
*mac
= &adapter
->regs
->mac
;
942 struct phy_device
*phydev
= adapter
->phydev
;
948 ctl
= readl(&adapter
->regs
->txmac
.ctl
);
949 cfg1
= readl(&mac
->cfg1
);
950 cfg2
= readl(&mac
->cfg2
);
951 ifctrl
= readl(&mac
->if_ctrl
);
953 /* Set up the if mode bits */
955 if (phydev
&& phydev
->speed
== SPEED_1000
) {
958 ifctrl
&= ~(1 << 24);
964 /* We need to enable Rx/Tx */
965 cfg1
|= CFG1_RX_ENABLE
| CFG1_TX_ENABLE
| CFG1_TX_FLOW
;
966 /* Initialize loop back to off */
967 cfg1
&= ~(CFG1_LOOPBACK
| CFG1_RX_FLOW
);
968 if (adapter
->flowcontrol
== FLOW_RXONLY
||
969 adapter
->flowcontrol
== FLOW_BOTH
)
970 cfg1
|= CFG1_RX_FLOW
;
971 writel(cfg1
, &mac
->cfg1
);
973 /* Now we need to initialize the MAC Configuration 2 register */
974 /* preamble 7, check length, huge frame off, pad crc, crc enable
979 /* Turn on duplex if needed */
980 if (phydev
&& phydev
->duplex
== DUPLEX_FULL
)
983 ifctrl
&= ~(1 << 26);
984 if (phydev
&& phydev
->duplex
== DUPLEX_HALF
)
985 ifctrl
|= (1<<26); /* Enable ghd */
987 writel(ifctrl
, &mac
->if_ctrl
);
988 writel(cfg2
, &mac
->cfg2
);
993 cfg1
= readl(&mac
->cfg1
);
994 } while ((cfg1
& CFG1_WAIT
) != CFG1_WAIT
&& delay
< 100);
997 dev_warn(&adapter
->pdev
->dev
,
998 "Syncd bits did not respond correctly cfg1 word 0x%08x\n",
1003 ctl
|= 0x09; /* TX mac enable, FC disable */
1004 writel(ctl
, &adapter
->regs
->txmac
.ctl
);
1006 /* Ready to start the RXDMA/TXDMA engine */
1007 if (adapter
->flags
& fMP_ADAPTER_LOWER_POWER
) {
1008 et131x_rx_dma_enable(adapter
);
1009 et131x_tx_dma_enable(adapter
);
1014 * et1310_in_phy_coma - check if the device is in phy coma
1015 * @adapter: pointer to our adapter structure
1017 * Returns 0 if the device is not in phy coma, 1 if it is in phy coma
1019 int et1310_in_phy_coma(struct et131x_adapter
*adapter
)
1023 pmcsr
= readl(&adapter
->regs
->global
.pm_csr
);
1025 return ET_PM_PHY_SW_COMA
& pmcsr
? 1 : 0;
1028 void et1310_setup_device_for_multicast(struct et131x_adapter
*adapter
)
1030 struct rxmac_regs __iomem
*rxmac
= &adapter
->regs
->rxmac
;
1039 /* If ET131X_PACKET_TYPE_MULTICAST is specified, then we provision
1040 * the multi-cast LIST. If it is NOT specified, (and "ALL" is not
1041 * specified) then we should pass NO multi-cast addresses to the
1044 if (adapter
->packet_filter
& ET131X_PACKET_TYPE_MULTICAST
) {
1045 /* Loop through our multicast array and set up the device */
1046 for (nIndex
= 0; nIndex
< adapter
->multicast_addr_count
;
1048 result
= ether_crc(6, adapter
->multicast_list
[nIndex
]);
1050 result
= (result
& 0x3F800000) >> 23;
1053 hash1
|= (1 << result
);
1054 } else if ((31 < result
) && (result
< 64)) {
1056 hash2
|= (1 << result
);
1057 } else if ((63 < result
) && (result
< 96)) {
1059 hash3
|= (1 << result
);
1062 hash4
|= (1 << result
);
1067 /* Write out the new hash to the device */
1068 pm_csr
= readl(&adapter
->regs
->global
.pm_csr
);
1069 if (!et1310_in_phy_coma(adapter
)) {
1070 writel(hash1
, &rxmac
->multi_hash1
);
1071 writel(hash2
, &rxmac
->multi_hash2
);
1072 writel(hash3
, &rxmac
->multi_hash3
);
1073 writel(hash4
, &rxmac
->multi_hash4
);
1077 void et1310_setup_device_for_unicast(struct et131x_adapter
*adapter
)
1079 struct rxmac_regs __iomem
*rxmac
= &adapter
->regs
->rxmac
;
1085 /* Set up unicast packet filter reg 3 to be the first two octets of
1086 * the MAC address for both address
1088 * Set up unicast packet filter reg 2 to be the octets 2 - 5 of the
1089 * MAC address for second address
1091 * Set up unicast packet filter reg 3 to be the octets 2 - 5 of the
1092 * MAC address for first address
1094 uni_pf3
= (adapter
->addr
[0] << ET_UNI_PF_ADDR2_1_SHIFT
) |
1095 (adapter
->addr
[1] << ET_UNI_PF_ADDR2_2_SHIFT
) |
1096 (adapter
->addr
[0] << ET_UNI_PF_ADDR1_1_SHIFT
) |
1099 uni_pf2
= (adapter
->addr
[2] << ET_UNI_PF_ADDR2_3_SHIFT
) |
1100 (adapter
->addr
[3] << ET_UNI_PF_ADDR2_4_SHIFT
) |
1101 (adapter
->addr
[4] << ET_UNI_PF_ADDR2_5_SHIFT
) |
1104 uni_pf1
= (adapter
->addr
[2] << ET_UNI_PF_ADDR1_3_SHIFT
) |
1105 (adapter
->addr
[3] << ET_UNI_PF_ADDR1_4_SHIFT
) |
1106 (adapter
->addr
[4] << ET_UNI_PF_ADDR1_5_SHIFT
) |
1109 pm_csr
= readl(&adapter
->regs
->global
.pm_csr
);
1110 if (!et1310_in_phy_coma(adapter
)) {
1111 writel(uni_pf1
, &rxmac
->uni_pf_addr1
);
1112 writel(uni_pf2
, &rxmac
->uni_pf_addr2
);
1113 writel(uni_pf3
, &rxmac
->uni_pf_addr3
);
1117 void et1310_config_rxmac_regs(struct et131x_adapter
*adapter
)
1119 struct rxmac_regs __iomem
*rxmac
= &adapter
->regs
->rxmac
;
1120 struct phy_device
*phydev
= adapter
->phydev
;
1125 /* Disable the MAC while it is being configured (also disable WOL) */
1126 writel(0x8, &rxmac
->ctrl
);
1128 /* Initialize WOL to disabled. */
1129 writel(0, &rxmac
->crc0
);
1130 writel(0, &rxmac
->crc12
);
1131 writel(0, &rxmac
->crc34
);
1133 /* We need to set the WOL mask0 - mask4 next. We initialize it to
1134 * its default Values of 0x00000000 because there are not WOL masks
1137 writel(0, &rxmac
->mask0_word0
);
1138 writel(0, &rxmac
->mask0_word1
);
1139 writel(0, &rxmac
->mask0_word2
);
1140 writel(0, &rxmac
->mask0_word3
);
1142 writel(0, &rxmac
->mask1_word0
);
1143 writel(0, &rxmac
->mask1_word1
);
1144 writel(0, &rxmac
->mask1_word2
);
1145 writel(0, &rxmac
->mask1_word3
);
1147 writel(0, &rxmac
->mask2_word0
);
1148 writel(0, &rxmac
->mask2_word1
);
1149 writel(0, &rxmac
->mask2_word2
);
1150 writel(0, &rxmac
->mask2_word3
);
1152 writel(0, &rxmac
->mask3_word0
);
1153 writel(0, &rxmac
->mask3_word1
);
1154 writel(0, &rxmac
->mask3_word2
);
1155 writel(0, &rxmac
->mask3_word3
);
1157 writel(0, &rxmac
->mask4_word0
);
1158 writel(0, &rxmac
->mask4_word1
);
1159 writel(0, &rxmac
->mask4_word2
);
1160 writel(0, &rxmac
->mask4_word3
);
1162 /* Lets setup the WOL Source Address */
1163 sa_lo
= (adapter
->addr
[2] << ET_WOL_LO_SA3_SHIFT
) |
1164 (adapter
->addr
[3] << ET_WOL_LO_SA4_SHIFT
) |
1165 (adapter
->addr
[4] << ET_WOL_LO_SA5_SHIFT
) |
1167 writel(sa_lo
, &rxmac
->sa_lo
);
1169 sa_hi
= (u32
) (adapter
->addr
[0] << ET_WOL_HI_SA1_SHIFT
) |
1171 writel(sa_hi
, &rxmac
->sa_hi
);
1173 /* Disable all Packet Filtering */
1174 writel(0, &rxmac
->pf_ctrl
);
1176 /* Let's initialize the Unicast Packet filtering address */
1177 if (adapter
->packet_filter
& ET131X_PACKET_TYPE_DIRECTED
) {
1178 et1310_setup_device_for_unicast(adapter
);
1179 pf_ctrl
|= 4; /* Unicast filter */
1181 writel(0, &rxmac
->uni_pf_addr1
);
1182 writel(0, &rxmac
->uni_pf_addr2
);
1183 writel(0, &rxmac
->uni_pf_addr3
);
1186 /* Let's initialize the Multicast hash */
1187 if (!(adapter
->packet_filter
& ET131X_PACKET_TYPE_ALL_MULTICAST
)) {
1188 pf_ctrl
|= 2; /* Multicast filter */
1189 et1310_setup_device_for_multicast(adapter
);
1192 /* Runt packet filtering. Didn't work in version A silicon. */
1193 pf_ctrl
|= (NIC_MIN_PACKET_SIZE
+ 4) << 16;
1194 pf_ctrl
|= 8; /* Fragment filter */
1196 if (adapter
->registry_jumbo_packet
> 8192)
1197 /* In order to transmit jumbo packets greater than 8k, the
1198 * FIFO between RxMAC and RxDMA needs to be reduced in size
1199 * to (16k - Jumbo packet size). In order to implement this,
1200 * we must use "cut through" mode in the RxMAC, which chops
1201 * packets down into segments which are (max_size * 16). In
1202 * this case we selected 256 bytes, since this is the size of
1203 * the PCI-Express TLP's that the 1310 uses.
1205 * seg_en on, fc_en off, size 0x10
1207 writel(0x41, &rxmac
->mcif_ctrl_max_seg
);
1209 writel(0, &rxmac
->mcif_ctrl_max_seg
);
1211 /* Initialize the MCIF water marks */
1212 writel(0, &rxmac
->mcif_water_mark
);
1214 /* Initialize the MIF control */
1215 writel(0, &rxmac
->mif_ctrl
);
1217 /* Initialize the Space Available Register */
1218 writel(0, &rxmac
->space_avail
);
1220 /* Initialize the the mif_ctrl register
1221 * bit 3: Receive code error. One or more nibbles were signaled as
1222 * errors during the reception of the packet. Clear this
1223 * bit in Gigabit, set it in 100Mbit. This was derived
1224 * experimentally at UNH.
1225 * bit 4: Receive CRC error. The packet's CRC did not match the
1226 * internally generated CRC.
1227 * bit 5: Receive length check error. Indicates that frame length
1228 * field value in the packet does not match the actual data
1229 * byte length and is not a type field.
1230 * bit 16: Receive frame truncated.
1231 * bit 17: Drop packet enable
1233 if (phydev
&& phydev
->speed
== SPEED_100
)
1234 writel(0x30038, &rxmac
->mif_ctrl
);
1236 writel(0x30030, &rxmac
->mif_ctrl
);
1238 /* Finally we initialize RxMac to be enabled & WOL disabled. Packet
1239 * filter is always enabled since it is where the runt packets are
1240 * supposed to be dropped. For version A silicon, runt packet
1241 * dropping doesn't work, so it is disabled in the pf_ctrl register,
1242 * but we still leave the packet filter on.
1244 writel(pf_ctrl
, &rxmac
->pf_ctrl
);
1245 writel(0x9, &rxmac
->ctrl
);
1248 void et1310_config_txmac_regs(struct et131x_adapter
*adapter
)
1250 struct txmac_regs __iomem
*txmac
= &adapter
->regs
->txmac
;
1252 /* We need to update the Control Frame Parameters
1253 * cfpt - control frame pause timer set to 64 (0x40)
1254 * cfep - control frame extended pause timer set to 0x0
1256 if (adapter
->flowcontrol
== FLOW_NONE
)
1257 writel(0, &txmac
->cf_param
);
1259 writel(0x40, &txmac
->cf_param
);
1262 void et1310_config_macstat_regs(struct et131x_adapter
*adapter
)
1264 struct macstat_regs __iomem
*macstat
=
1265 &adapter
->regs
->macstat
;
1267 /* Next we need to initialize all the macstat registers to zero on
1270 writel(0, &macstat
->txrx_0_64_byte_frames
);
1271 writel(0, &macstat
->txrx_65_127_byte_frames
);
1272 writel(0, &macstat
->txrx_128_255_byte_frames
);
1273 writel(0, &macstat
->txrx_256_511_byte_frames
);
1274 writel(0, &macstat
->txrx_512_1023_byte_frames
);
1275 writel(0, &macstat
->txrx_1024_1518_byte_frames
);
1276 writel(0, &macstat
->txrx_1519_1522_gvln_frames
);
1278 writel(0, &macstat
->rx_bytes
);
1279 writel(0, &macstat
->rx_packets
);
1280 writel(0, &macstat
->rx_fcs_errs
);
1281 writel(0, &macstat
->rx_multicast_packets
);
1282 writel(0, &macstat
->rx_broadcast_packets
);
1283 writel(0, &macstat
->rx_control_frames
);
1284 writel(0, &macstat
->rx_pause_frames
);
1285 writel(0, &macstat
->rx_unknown_opcodes
);
1286 writel(0, &macstat
->rx_align_errs
);
1287 writel(0, &macstat
->rx_frame_len_errs
);
1288 writel(0, &macstat
->rx_code_errs
);
1289 writel(0, &macstat
->rx_carrier_sense_errs
);
1290 writel(0, &macstat
->rx_undersize_packets
);
1291 writel(0, &macstat
->rx_oversize_packets
);
1292 writel(0, &macstat
->rx_fragment_packets
);
1293 writel(0, &macstat
->rx_jabbers
);
1294 writel(0, &macstat
->rx_drops
);
1296 writel(0, &macstat
->tx_bytes
);
1297 writel(0, &macstat
->tx_packets
);
1298 writel(0, &macstat
->tx_multicast_packets
);
1299 writel(0, &macstat
->tx_broadcast_packets
);
1300 writel(0, &macstat
->tx_pause_frames
);
1301 writel(0, &macstat
->tx_deferred
);
1302 writel(0, &macstat
->tx_excessive_deferred
);
1303 writel(0, &macstat
->tx_single_collisions
);
1304 writel(0, &macstat
->tx_multiple_collisions
);
1305 writel(0, &macstat
->tx_late_collisions
);
1306 writel(0, &macstat
->tx_excessive_collisions
);
1307 writel(0, &macstat
->tx_total_collisions
);
1308 writel(0, &macstat
->tx_pause_honored_frames
);
1309 writel(0, &macstat
->tx_drops
);
1310 writel(0, &macstat
->tx_jabbers
);
1311 writel(0, &macstat
->tx_fcs_errs
);
1312 writel(0, &macstat
->tx_control_frames
);
1313 writel(0, &macstat
->tx_oversize_frames
);
1314 writel(0, &macstat
->tx_undersize_frames
);
1315 writel(0, &macstat
->tx_fragments
);
1316 writel(0, &macstat
->carry_reg1
);
1317 writel(0, &macstat
->carry_reg2
);
1319 /* Unmask any counters that we want to track the overflow of.
1320 * Initially this will be all counters. It may become clear later
1321 * that we do not need to track all counters.
1323 writel(0xFFFFBE32, &macstat
->carry_reg1_mask
);
1324 writel(0xFFFE7E8B, &macstat
->carry_reg2_mask
);
1328 * et131x_phy_mii_read - Read from the PHY through the MII Interface on the MAC
1329 * @adapter: pointer to our private adapter structure
1330 * @addr: the address of the transceiver
1331 * @reg: the register to read
1332 * @value: pointer to a 16-bit value in which the value will be stored
1334 * Returns 0 on success, errno on failure (as defined in errno.h)
1336 int et131x_phy_mii_read(struct et131x_adapter
*adapter
, u8 addr
,
1339 struct mac_regs __iomem
*mac
= &adapter
->regs
->mac
;
1346 /* Save a local copy of the registers we are dealing with so we can
1349 mii_addr
= readl(&mac
->mii_mgmt_addr
);
1350 mii_cmd
= readl(&mac
->mii_mgmt_cmd
);
1352 /* Stop the current operation */
1353 writel(0, &mac
->mii_mgmt_cmd
);
1355 /* Set up the register we need to read from on the correct PHY */
1356 writel(MII_ADDR(addr
, reg
), &mac
->mii_mgmt_addr
);
1358 writel(0x1, &mac
->mii_mgmt_cmd
);
1363 mii_indicator
= readl(&mac
->mii_mgmt_indicator
);
1364 } while ((mii_indicator
& MGMT_WAIT
) && delay
< 50);
1366 /* If we hit the max delay, we could not read the register */
1368 dev_warn(&adapter
->pdev
->dev
,
1369 "reg 0x%08x could not be read\n", reg
);
1370 dev_warn(&adapter
->pdev
->dev
, "status is 0x%08x\n",
1376 /* If we hit here we were able to read the register and we need to
1377 * return the value to the caller */
1378 *value
= readl(&mac
->mii_mgmt_stat
) & 0xFFFF;
1380 /* Stop the read operation */
1381 writel(0, &mac
->mii_mgmt_cmd
);
1383 /* set the registers we touched back to the state at which we entered
1386 writel(mii_addr
, &mac
->mii_mgmt_addr
);
1387 writel(mii_cmd
, &mac
->mii_mgmt_cmd
);
1392 int et131x_mii_read(struct et131x_adapter
*adapter
, u8 reg
, u16
*value
)
1394 struct phy_device
*phydev
= adapter
->phydev
;
1399 return et131x_phy_mii_read(adapter
, phydev
->addr
, reg
, value
);
1403 * et131x_mii_write - Write to a PHY register through the MII interface of the MAC
1404 * @adapter: pointer to our private adapter structure
1405 * @reg: the register to read
1406 * @value: 16-bit value to write
1408 * FIXME: one caller in netdev still
1410 * Return 0 on success, errno on failure (as defined in errno.h)
1412 int et131x_mii_write(struct et131x_adapter
*adapter
, u8 reg
, u16 value
)
1414 struct mac_regs __iomem
*mac
= &adapter
->regs
->mac
;
1415 struct phy_device
*phydev
= adapter
->phydev
;
1426 addr
= phydev
->addr
;
1428 /* Save a local copy of the registers we are dealing with so we can
1431 mii_addr
= readl(&mac
->mii_mgmt_addr
);
1432 mii_cmd
= readl(&mac
->mii_mgmt_cmd
);
1434 /* Stop the current operation */
1435 writel(0, &mac
->mii_mgmt_cmd
);
1437 /* Set up the register we need to write to on the correct PHY */
1438 writel(MII_ADDR(addr
, reg
), &mac
->mii_mgmt_addr
);
1440 /* Add the value to write to the registers to the mac */
1441 writel(value
, &mac
->mii_mgmt_ctrl
);
1446 mii_indicator
= readl(&mac
->mii_mgmt_indicator
);
1447 } while ((mii_indicator
& MGMT_BUSY
) && delay
< 100);
1449 /* If we hit the max delay, we could not write the register */
1453 dev_warn(&adapter
->pdev
->dev
,
1454 "reg 0x%08x could not be written", reg
);
1455 dev_warn(&adapter
->pdev
->dev
, "status is 0x%08x\n",
1457 dev_warn(&adapter
->pdev
->dev
, "command is 0x%08x\n",
1458 readl(&mac
->mii_mgmt_cmd
));
1460 et131x_mii_read(adapter
, reg
, &tmp
);
1464 /* Stop the write operation */
1465 writel(0, &mac
->mii_mgmt_cmd
);
1468 * set the registers we touched back to the state at which we entered
1471 writel(mii_addr
, &mac
->mii_mgmt_addr
);
1472 writel(mii_cmd
, &mac
->mii_mgmt_cmd
);
1477 /* Still used from _mac for BIT_READ */
1478 void et1310_phy_access_mii_bit(struct et131x_adapter
*adapter
, u16 action
,
1479 u16 regnum
, u16 bitnum
, u8
*value
)
1482 u16 mask
= 0x0001 << bitnum
;
1484 /* Read the requested register */
1485 et131x_mii_read(adapter
, regnum
, ®
);
1488 case TRUEPHY_BIT_READ
:
1489 *value
= (reg
& mask
) >> bitnum
;
1492 case TRUEPHY_BIT_SET
:
1493 et131x_mii_write(adapter
, regnum
, reg
| mask
);
1496 case TRUEPHY_BIT_CLEAR
:
1497 et131x_mii_write(adapter
, regnum
, reg
& ~mask
);
1505 void et1310_config_flow_control(struct et131x_adapter
*adapter
)
1507 struct phy_device
*phydev
= adapter
->phydev
;
1509 if (phydev
->duplex
== DUPLEX_HALF
) {
1510 adapter
->flowcontrol
= FLOW_NONE
;
1512 char remote_pause
, remote_async_pause
;
1514 et1310_phy_access_mii_bit(adapter
,
1515 TRUEPHY_BIT_READ
, 5, 10, &remote_pause
);
1516 et1310_phy_access_mii_bit(adapter
,
1517 TRUEPHY_BIT_READ
, 5, 11,
1518 &remote_async_pause
);
1520 if ((remote_pause
== TRUEPHY_BIT_SET
) &&
1521 (remote_async_pause
== TRUEPHY_BIT_SET
)) {
1522 adapter
->flowcontrol
= adapter
->wanted_flow
;
1523 } else if ((remote_pause
== TRUEPHY_BIT_SET
) &&
1524 (remote_async_pause
== TRUEPHY_BIT_CLEAR
)) {
1525 if (adapter
->wanted_flow
== FLOW_BOTH
)
1526 adapter
->flowcontrol
= FLOW_BOTH
;
1528 adapter
->flowcontrol
= FLOW_NONE
;
1529 } else if ((remote_pause
== TRUEPHY_BIT_CLEAR
) &&
1530 (remote_async_pause
== TRUEPHY_BIT_CLEAR
)) {
1531 adapter
->flowcontrol
= FLOW_NONE
;
1532 } else {/* if (remote_pause == TRUEPHY_CLEAR_BIT &&
1533 remote_async_pause == TRUEPHY_SET_BIT) */
1534 if (adapter
->wanted_flow
== FLOW_BOTH
)
1535 adapter
->flowcontrol
= FLOW_RXONLY
;
1537 adapter
->flowcontrol
= FLOW_NONE
;
1543 * et1310_update_macstat_host_counters - Update the local copy of the statistics
1544 * @adapter: pointer to the adapter structure
1546 void et1310_update_macstat_host_counters(struct et131x_adapter
*adapter
)
1548 struct ce_stats
*stats
= &adapter
->stats
;
1549 struct macstat_regs __iomem
*macstat
=
1550 &adapter
->regs
->macstat
;
1552 stats
->tx_collisions
+= readl(&macstat
->tx_total_collisions
);
1553 stats
->tx_first_collisions
+= readl(&macstat
->tx_single_collisions
);
1554 stats
->tx_deferred
+= readl(&macstat
->tx_deferred
);
1555 stats
->tx_excessive_collisions
+=
1556 readl(&macstat
->tx_multiple_collisions
);
1557 stats
->tx_late_collisions
+= readl(&macstat
->tx_late_collisions
);
1558 stats
->tx_underflows
+= readl(&macstat
->tx_undersize_frames
);
1559 stats
->tx_max_pkt_errs
+= readl(&macstat
->tx_oversize_frames
);
1561 stats
->rx_align_errs
+= readl(&macstat
->rx_align_errs
);
1562 stats
->rx_crc_errs
+= readl(&macstat
->rx_code_errs
);
1563 stats
->rcvd_pkts_dropped
+= readl(&macstat
->rx_drops
);
1564 stats
->rx_overflows
+= readl(&macstat
->rx_oversize_packets
);
1565 stats
->rx_code_violations
+= readl(&macstat
->rx_fcs_errs
);
1566 stats
->rx_length_errs
+= readl(&macstat
->rx_frame_len_errs
);
1567 stats
->rx_other_errs
+= readl(&macstat
->rx_fragment_packets
);
1571 * et1310_handle_macstat_interrupt
1572 * @adapter: pointer to the adapter structure
1574 * One of the MACSTAT counters has wrapped. Update the local copy of
1575 * the statistics held in the adapter structure, checking the "wrap"
1576 * bit for each counter.
1578 void et1310_handle_macstat_interrupt(struct et131x_adapter
*adapter
)
1583 /* Read the interrupt bits from the register(s). These are Clear On
1586 carry_reg1
= readl(&adapter
->regs
->macstat
.carry_reg1
);
1587 carry_reg2
= readl(&adapter
->regs
->macstat
.carry_reg2
);
1589 writel(carry_reg1
, &adapter
->regs
->macstat
.carry_reg1
);
1590 writel(carry_reg2
, &adapter
->regs
->macstat
.carry_reg2
);
1592 /* We need to do update the host copy of all the MAC_STAT counters.
1593 * For each counter, check it's overflow bit. If the overflow bit is
1594 * set, then increment the host version of the count by one complete
1595 * revolution of the counter. This routine is called when the counter
1596 * block indicates that one of the counters has wrapped.
1598 if (carry_reg1
& (1 << 14))
1599 adapter
->stats
.rx_code_violations
+= COUNTER_WRAP_16_BIT
;
1600 if (carry_reg1
& (1 << 8))
1601 adapter
->stats
.rx_align_errs
+= COUNTER_WRAP_12_BIT
;
1602 if (carry_reg1
& (1 << 7))
1603 adapter
->stats
.rx_length_errs
+= COUNTER_WRAP_16_BIT
;
1604 if (carry_reg1
& (1 << 2))
1605 adapter
->stats
.rx_other_errs
+= COUNTER_WRAP_16_BIT
;
1606 if (carry_reg1
& (1 << 6))
1607 adapter
->stats
.rx_crc_errs
+= COUNTER_WRAP_16_BIT
;
1608 if (carry_reg1
& (1 << 3))
1609 adapter
->stats
.rx_overflows
+= COUNTER_WRAP_16_BIT
;
1610 if (carry_reg1
& (1 << 0))
1611 adapter
->stats
.rcvd_pkts_dropped
+= COUNTER_WRAP_16_BIT
;
1612 if (carry_reg2
& (1 << 16))
1613 adapter
->stats
.tx_max_pkt_errs
+= COUNTER_WRAP_12_BIT
;
1614 if (carry_reg2
& (1 << 15))
1615 adapter
->stats
.tx_underflows
+= COUNTER_WRAP_12_BIT
;
1616 if (carry_reg2
& (1 << 6))
1617 adapter
->stats
.tx_first_collisions
+= COUNTER_WRAP_12_BIT
;
1618 if (carry_reg2
& (1 << 8))
1619 adapter
->stats
.tx_deferred
+= COUNTER_WRAP_12_BIT
;
1620 if (carry_reg2
& (1 << 5))
1621 adapter
->stats
.tx_excessive_collisions
+= COUNTER_WRAP_12_BIT
;
1622 if (carry_reg2
& (1 << 4))
1623 adapter
->stats
.tx_late_collisions
+= COUNTER_WRAP_12_BIT
;
1624 if (carry_reg2
& (1 << 2))
1625 adapter
->stats
.tx_collisions
+= COUNTER_WRAP_12_BIT
;
1630 int et131x_mdio_read(struct mii_bus
*bus
, int phy_addr
, int reg
)
1632 struct net_device
*netdev
= bus
->priv
;
1633 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
1637 ret
= et131x_phy_mii_read(adapter
, phy_addr
, reg
, &value
);
1645 int et131x_mdio_write(struct mii_bus
*bus
, int phy_addr
, int reg
, u16 value
)
1647 struct net_device
*netdev
= bus
->priv
;
1648 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
1650 return et131x_mii_write(adapter
, reg
, value
);
1653 int et131x_mdio_reset(struct mii_bus
*bus
)
1655 struct net_device
*netdev
= bus
->priv
;
1656 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
1658 et131x_mii_write(adapter
, MII_BMCR
, BMCR_RESET
);
1664 * et1310_phy_power_down - PHY power control
1665 * @adapter: device to control
1666 * @down: true for off/false for back on
1668 * one hundred, ten, one thousand megs
1669 * How would you like to have your LAN accessed
1670 * Can't you see that this code processed
1671 * Phy power, phy power..
1673 void et1310_phy_power_down(struct et131x_adapter
*adapter
, bool down
)
1677 et131x_mii_read(adapter
, MII_BMCR
, &data
);
1678 data
&= ~BMCR_PDOWN
;
1681 et131x_mii_write(adapter
, MII_BMCR
, data
);
1685 * et131x_xcvr_init - Init the phy if we are setting it into force mode
1686 * @adapter: pointer to our private adapter structure
1689 void et131x_xcvr_init(struct et131x_adapter
*adapter
)
1695 et131x_mii_read(adapter
, PHY_INTERRUPT_STATUS
, &isr
);
1696 et131x_mii_read(adapter
, PHY_INTERRUPT_MASK
, &imr
);
1698 /* Set the link status interrupt only. Bad behavior when link status
1699 * and auto neg are set, we run into a nested interrupt problem
1701 imr
|= (ET_PHY_INT_MASK_AUTONEGSTAT
&
1702 ET_PHY_INT_MASK_LINKSTAT
&
1703 ET_PHY_INT_MASK_ENABLE
);
1705 et131x_mii_write(adapter
, PHY_INTERRUPT_MASK
, imr
);
1707 /* Set the LED behavior such that LED 1 indicates speed (off =
1708 * 10Mbits, blink = 100Mbits, on = 1000Mbits) and LED 2 indicates
1709 * link and activity (on for link, blink off for activity).
1711 * NOTE: Some customizations have been added here for specific
1712 * vendors; The LED behavior is now determined by vendor data in the
1713 * EEPROM. However, the above description is the default.
1715 if ((adapter
->eeprom_data
[1] & 0x4) == 0) {
1716 et131x_mii_read(adapter
, PHY_LED_2
, &lcr2
);
1718 lcr2
&= (ET_LED2_LED_100TX
& ET_LED2_LED_1000T
);
1719 lcr2
|= (LED_VAL_LINKON_ACTIVE
<< LED_LINK_SHIFT
);
1721 if ((adapter
->eeprom_data
[1] & 0x8) == 0)
1722 lcr2
|= (LED_VAL_1000BT_100BTX
<< LED_TXRX_SHIFT
);
1724 lcr2
|= (LED_VAL_LINKON
<< LED_TXRX_SHIFT
);
1726 et131x_mii_write(adapter
, PHY_LED_2
, lcr2
);
1731 * et131x_configure_global_regs - configure JAGCore global regs
1732 * @adapter: pointer to our adapter structure
1734 * Used to configure the global registers on the JAGCore
1736 void et131x_configure_global_regs(struct et131x_adapter
*adapter
)
1738 struct global_regs __iomem
*regs
= &adapter
->regs
->global
;
1740 writel(0, ®s
->rxq_start_addr
);
1741 writel(INTERNAL_MEM_SIZE
- 1, ®s
->txq_end_addr
);
1743 if (adapter
->registry_jumbo_packet
< 2048) {
1744 /* Tx / RxDMA and Tx/Rx MAC interfaces have a 1k word
1745 * block of RAM that the driver can split between Tx
1746 * and Rx as it desires. Our default is to split it
1749 writel(PARM_RX_MEM_END_DEF
, ®s
->rxq_end_addr
);
1750 writel(PARM_RX_MEM_END_DEF
+ 1, ®s
->txq_start_addr
);
1751 } else if (adapter
->registry_jumbo_packet
< 8192) {
1752 /* For jumbo packets > 2k but < 8k, split 50-50. */
1753 writel(INTERNAL_MEM_RX_OFFSET
, ®s
->rxq_end_addr
);
1754 writel(INTERNAL_MEM_RX_OFFSET
+ 1, ®s
->txq_start_addr
);
1756 /* 9216 is the only packet size greater than 8k that
1757 * is available. The Tx buffer has to be big enough
1758 * for one whole packet on the Tx side. We'll make
1759 * the Tx 9408, and give the rest to Rx
1761 writel(0x01b3, ®s
->rxq_end_addr
);
1762 writel(0x01b4, ®s
->txq_start_addr
);
1765 /* Initialize the loopback register. Disable all loopbacks. */
1766 writel(0, ®s
->loopback
);
1769 writel(0, ®s
->msi_config
);
1771 /* By default, disable the watchdog timer. It will be enabled when
1772 * a packet is queued.
1774 writel(0, ®s
->watchdog_timer
);
1780 * et131x_config_rx_dma_regs - Start of Rx_DMA init sequence
1781 * @adapter: pointer to our adapter structure
1783 void et131x_config_rx_dma_regs(struct et131x_adapter
*adapter
)
1785 struct rxdma_regs __iomem
*rx_dma
= &adapter
->regs
->rxdma
;
1786 struct rx_ring
*rx_local
= &adapter
->rx_ring
;
1787 struct fbr_desc
*fbr_entry
;
1790 unsigned long flags
;
1792 /* Halt RXDMA to perform the reconfigure. */
1793 et131x_rx_dma_disable(adapter
);
1795 /* Load the completion writeback physical address
1797 * NOTE : dma_alloc_coherent(), used above to alloc DMA regions,
1798 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
1799 * are ever returned, make sure the high part is retrieved here
1800 * before storing the adjusted address.
1802 writel((u32
) ((u64
)rx_local
->rx_status_bus
>> 32),
1803 &rx_dma
->dma_wb_base_hi
);
1804 writel((u32
) rx_local
->rx_status_bus
, &rx_dma
->dma_wb_base_lo
);
1806 memset(rx_local
->rx_status_block
, 0, sizeof(struct rx_status_block
));
1808 /* Set the address and parameters of the packet status ring into the
1811 writel((u32
) ((u64
)rx_local
->ps_ring_physaddr
>> 32),
1812 &rx_dma
->psr_base_hi
);
1813 writel((u32
) rx_local
->ps_ring_physaddr
, &rx_dma
->psr_base_lo
);
1814 writel(rx_local
->psr_num_entries
- 1, &rx_dma
->psr_num_des
);
1815 writel(0, &rx_dma
->psr_full_offset
);
1817 psr_num_des
= readl(&rx_dma
->psr_num_des
) & 0xFFF;
1818 writel((psr_num_des
* LO_MARK_PERCENT_FOR_PSR
) / 100,
1819 &rx_dma
->psr_min_des
);
1821 spin_lock_irqsave(&adapter
->rcv_lock
, flags
);
1823 /* These local variables track the PSR in the adapter structure */
1824 rx_local
->local_psr_full
= 0;
1826 /* Now's the best time to initialize FBR1 contents */
1827 fbr_entry
= (struct fbr_desc
*) rx_local
->fbr
[0]->ring_virtaddr
;
1828 for (entry
= 0; entry
< rx_local
->fbr
[0]->num_entries
; entry
++) {
1829 fbr_entry
->addr_hi
= rx_local
->fbr
[0]->bus_high
[entry
];
1830 fbr_entry
->addr_lo
= rx_local
->fbr
[0]->bus_low
[entry
];
1831 fbr_entry
->word2
= entry
;
1835 /* Set the address and parameters of Free buffer ring 1 (and 0 if
1836 * required) into the 1310's registers
1838 writel((u32
) (rx_local
->fbr
[0]->real_physaddr
>> 32),
1839 &rx_dma
->fbr1_base_hi
);
1840 writel((u32
) rx_local
->fbr
[0]->real_physaddr
, &rx_dma
->fbr1_base_lo
);
1841 writel(rx_local
->fbr
[0]->num_entries
- 1, &rx_dma
->fbr1_num_des
);
1842 writel(ET_DMA10_WRAP
, &rx_dma
->fbr1_full_offset
);
1844 /* This variable tracks the free buffer ring 1 full position, so it
1845 * has to match the above.
1847 rx_local
->fbr
[0]->local_full
= ET_DMA10_WRAP
;
1849 ((rx_local
->fbr
[0]->num_entries
* LO_MARK_PERCENT_FOR_RX
) / 100) - 1,
1850 &rx_dma
->fbr1_min_des
);
1853 /* Now's the best time to initialize FBR0 contents */
1854 fbr_entry
= (struct fbr_desc
*) rx_local
->fbr
[1]->ring_virtaddr
;
1855 for (entry
= 0; entry
< rx_local
->fbr
[1]->num_entries
; entry
++) {
1856 fbr_entry
->addr_hi
= rx_local
->fbr
[1]->bus_high
[entry
];
1857 fbr_entry
->addr_lo
= rx_local
->fbr
[1]->bus_low
[entry
];
1858 fbr_entry
->word2
= entry
;
1862 writel((u32
) (rx_local
->fbr
[1]->real_physaddr
>> 32),
1863 &rx_dma
->fbr0_base_hi
);
1864 writel((u32
) rx_local
->fbr
[1]->real_physaddr
, &rx_dma
->fbr0_base_lo
);
1865 writel(rx_local
->fbr
[1]->num_entries
- 1, &rx_dma
->fbr0_num_des
);
1866 writel(ET_DMA10_WRAP
, &rx_dma
->fbr0_full_offset
);
1868 /* This variable tracks the free buffer ring 0 full position, so it
1869 * has to match the above.
1871 rx_local
->fbr
[1]->local_full
= ET_DMA10_WRAP
;
1873 ((rx_local
->fbr
[1]->num_entries
* LO_MARK_PERCENT_FOR_RX
) / 100) - 1,
1874 &rx_dma
->fbr0_min_des
);
1877 /* Program the number of packets we will receive before generating an
1879 * For version B silicon, this value gets updated once autoneg is
1882 writel(PARM_RX_NUM_BUFS_DEF
, &rx_dma
->num_pkt_done
);
1884 /* The "time_done" is not working correctly to coalesce interrupts
1885 * after a given time period, but rather is giving us an interrupt
1886 * regardless of whether we have received packets.
1887 * This value gets updated once autoneg is complete.
1889 writel(PARM_RX_TIME_INT_DEF
, &rx_dma
->max_pkt_time
);
1891 spin_unlock_irqrestore(&adapter
->rcv_lock
, flags
);
1895 * et131x_config_tx_dma_regs - Set up the tx dma section of the JAGCore.
1896 * @adapter: pointer to our private adapter structure
1898 * Configure the transmit engine with the ring buffers we have created
1899 * and prepare it for use.
1901 void et131x_config_tx_dma_regs(struct et131x_adapter
*adapter
)
1903 struct txdma_regs __iomem
*txdma
= &adapter
->regs
->txdma
;
1905 /* Load the hardware with the start of the transmit descriptor ring. */
1906 writel((u32
) ((u64
)adapter
->tx_ring
.tx_desc_ring_pa
>> 32),
1907 &txdma
->pr_base_hi
);
1908 writel((u32
) adapter
->tx_ring
.tx_desc_ring_pa
,
1909 &txdma
->pr_base_lo
);
1911 /* Initialise the transmit DMA engine */
1912 writel(NUM_DESC_PER_RING_TX
- 1, &txdma
->pr_num_des
);
1914 /* Load the completion writeback physical address */
1915 writel((u32
)((u64
)adapter
->tx_ring
.tx_status_pa
>> 32),
1916 &txdma
->dma_wb_base_hi
);
1917 writel((u32
)adapter
->tx_ring
.tx_status_pa
, &txdma
->dma_wb_base_lo
);
1919 *adapter
->tx_ring
.tx_status
= 0;
1921 writel(0, &txdma
->service_request
);
1922 adapter
->tx_ring
.send_idx
= 0;
1926 * et131x_adapter_setup - Set the adapter up as per cassini+ documentation
1927 * @adapter: pointer to our private adapter structure
1929 * Returns 0 on success, errno on failure (as defined in errno.h)
1931 void et131x_adapter_setup(struct et131x_adapter
*adapter
)
1933 /* Configure the JAGCore */
1934 et131x_configure_global_regs(adapter
);
1936 et1310_config_mac_regs1(adapter
);
1938 /* Configure the MMC registers */
1939 /* All we need to do is initialize the Memory Control Register */
1940 writel(ET_MMC_ENABLE
, &adapter
->regs
->mmc
.mmc_ctrl
);
1942 et1310_config_rxmac_regs(adapter
);
1943 et1310_config_txmac_regs(adapter
);
1945 et131x_config_rx_dma_regs(adapter
);
1946 et131x_config_tx_dma_regs(adapter
);
1948 et1310_config_macstat_regs(adapter
);
1950 et1310_phy_power_down(adapter
, 0);
1951 et131x_xcvr_init(adapter
);
1955 * et131x_soft_reset - Issue a soft reset to the hardware, complete for ET1310
1956 * @adapter: pointer to our private adapter structure
1958 void et131x_soft_reset(struct et131x_adapter
*adapter
)
1960 /* Disable MAC Core */
1961 writel(0xc00f0000, &adapter
->regs
->mac
.cfg1
);
1963 /* Set everything to a reset value */
1964 writel(0x7F, &adapter
->regs
->global
.sw_reset
);
1965 writel(0x000f0000, &adapter
->regs
->mac
.cfg1
);
1966 writel(0x00000000, &adapter
->regs
->mac
.cfg1
);
1970 * et131x_enable_interrupts - enable interrupt
1971 * @adapter: et131x device
1973 * Enable the appropriate interrupts on the ET131x according to our
1976 void et131x_enable_interrupts(struct et131x_adapter
*adapter
)
1980 /* Enable all global interrupts */
1981 if (adapter
->flowcontrol
== FLOW_TXONLY
||
1982 adapter
->flowcontrol
== FLOW_BOTH
)
1983 mask
= INT_MASK_ENABLE
;
1985 mask
= INT_MASK_ENABLE_NO_FLOW
;
1987 writel(mask
, &adapter
->regs
->global
.int_mask
);
1991 * et131x_disable_interrupts - interrupt disable
1992 * @adapter: et131x device
1994 * Block all interrupts from the et131x device at the device itself
1996 void et131x_disable_interrupts(struct et131x_adapter
*adapter
)
1998 /* Disable all global interrupts */
1999 writel(INT_MASK_DISABLE
, &adapter
->regs
->global
.int_mask
);
2003 * et131x_tx_dma_disable - Stop of Tx_DMA on the ET1310
2004 * @adapter: pointer to our adapter structure
2006 void et131x_tx_dma_disable(struct et131x_adapter
*adapter
)
2008 /* Setup the tramsmit dma configuration register */
2009 writel(ET_TXDMA_CSR_HALT
|ET_TXDMA_SNGL_EPKT
,
2010 &adapter
->regs
->txdma
.csr
);
2014 * et131x_tx_dma_enable - re-start of Tx_DMA on the ET1310.
2015 * @adapter: pointer to our adapter structure
2017 * Mainly used after a return to the D0 (full-power) state from a lower state.
2019 void et131x_tx_dma_enable(struct et131x_adapter
*adapter
)
2021 /* Setup the transmit dma configuration register for normal
2024 writel(ET_TXDMA_SNGL_EPKT
|(PARM_DMA_CACHE_DEF
<< ET_TXDMA_CACHE_SHIFT
),
2025 &adapter
->regs
->txdma
.csr
);
2029 * et131x_enable_txrx - Enable tx/rx queues
2030 * @netdev: device to be enabled
2032 void et131x_enable_txrx(struct net_device
*netdev
)
2034 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
2036 /* Enable the Tx and Rx DMA engines (if not already enabled) */
2037 et131x_rx_dma_enable(adapter
);
2038 et131x_tx_dma_enable(adapter
);
2040 /* Enable device interrupts */
2041 if (adapter
->flags
& fMP_ADAPTER_INTERRUPT_IN_USE
)
2042 et131x_enable_interrupts(adapter
);
2044 /* We're ready to move some data, so start the queue */
2045 netif_start_queue(netdev
);
2049 * et131x_disable_txrx - Disable tx/rx queues
2050 * @netdev: device to be disabled
2052 void et131x_disable_txrx(struct net_device
*netdev
)
2054 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
2056 /* First thing is to stop the queue */
2057 netif_stop_queue(netdev
);
2059 /* Stop the Tx and Rx DMA engines */
2060 et131x_rx_dma_disable(adapter
);
2061 et131x_tx_dma_disable(adapter
);
2063 /* Disable device interrupts */
2064 et131x_disable_interrupts(adapter
);
2068 * et1310_enable_phy_coma - called when network cable is unplugged
2069 * @adapter: pointer to our adapter structure
2071 * driver receive an phy status change interrupt while in D0 and check that
2072 * phy_status is down.
2074 * -- gate off JAGCore;
2075 * -- set gigE PHY in Coma mode
2076 * -- wake on phy_interrupt; Perform software reset JAGCore,
2077 * re-initialize jagcore and gigE PHY
2079 * Add D0-ASPM-PhyLinkDown Support:
2080 * -- while in D0, when there is a phy_interrupt indicating phy link
2081 * down status, call the MPSetPhyComa routine to enter this active
2082 * state power saving mode
2083 * -- while in D0-ASPM-PhyLinkDown mode, when there is a phy_interrupt
2084 * indicating linkup status, call the MPDisablePhyComa routine to
2085 * restore JAGCore and gigE PHY
2087 void et1310_enable_phy_coma(struct et131x_adapter
*adapter
)
2089 unsigned long flags
;
2092 pmcsr
= readl(&adapter
->regs
->global
.pm_csr
);
2094 /* Save the GbE PHY speed and duplex modes. Need to restore this
2095 * when cable is plugged back in
2098 * TODO - when PM is re-enabled, check if we need to
2099 * perform a similar task as this -
2100 * adapter->pdown_speed = adapter->ai_force_speed;
2101 * adapter->pdown_duplex = adapter->ai_force_duplex;
2104 /* Stop sending packets. */
2105 spin_lock_irqsave(&adapter
->send_hw_lock
, flags
);
2106 adapter
->flags
|= fMP_ADAPTER_LOWER_POWER
;
2107 spin_unlock_irqrestore(&adapter
->send_hw_lock
, flags
);
2109 /* Wait for outstanding Receive packets */
2111 et131x_disable_txrx(adapter
->netdev
);
2113 /* Gate off JAGCore 3 clock domains */
2114 pmcsr
&= ~ET_PMCSR_INIT
;
2115 writel(pmcsr
, &adapter
->regs
->global
.pm_csr
);
2117 /* Program gigE PHY in to Coma mode */
2118 pmcsr
|= ET_PM_PHY_SW_COMA
;
2119 writel(pmcsr
, &adapter
->regs
->global
.pm_csr
);
2123 * et1310_disable_phy_coma - Disable the Phy Coma Mode
2124 * @adapter: pointer to our adapter structure
2126 void et1310_disable_phy_coma(struct et131x_adapter
*adapter
)
2130 pmcsr
= readl(&adapter
->regs
->global
.pm_csr
);
2132 /* Disable phy_sw_coma register and re-enable JAGCore clocks */
2133 pmcsr
|= ET_PMCSR_INIT
;
2134 pmcsr
&= ~ET_PM_PHY_SW_COMA
;
2135 writel(pmcsr
, &adapter
->regs
->global
.pm_csr
);
2137 /* Restore the GbE PHY speed and duplex modes;
2138 * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY
2140 /* TODO - when PM is re-enabled, check if we need to
2141 * perform a similar task as this -
2142 * adapter->ai_force_speed = adapter->pdown_speed;
2143 * adapter->ai_force_duplex = adapter->pdown_duplex;
2146 /* Re-initialize the send structures */
2147 et131x_init_send(adapter
);
2149 /* Bring the device back to the state it was during init prior to
2150 * autonegotiation being complete. This way, when we get the auto-neg
2151 * complete interrupt, we can complete init by calling ConfigMacREGS2.
2153 et131x_soft_reset(adapter
);
2155 /* setup et1310 as per the documentation ?? */
2156 et131x_adapter_setup(adapter
);
2158 /* Allow Tx to restart */
2159 adapter
->flags
&= ~fMP_ADAPTER_LOWER_POWER
;
2161 et131x_enable_txrx(adapter
->netdev
);
2166 static inline u32
bump_free_buff_ring(u32
*free_buff_ring
, u32 limit
)
2168 u32 tmp_free_buff_ring
= *free_buff_ring
;
2169 tmp_free_buff_ring
++;
2170 /* This works for all cases where limit < 1024. The 1023 case
2171 works because 1023++ is 1024 which means the if condition is not
2172 taken but the carry of the bit into the wrap bit toggles the wrap
2174 if ((tmp_free_buff_ring
& ET_DMA10_MASK
) > limit
) {
2175 tmp_free_buff_ring
&= ~ET_DMA10_MASK
;
2176 tmp_free_buff_ring
^= ET_DMA10_WRAP
;
2178 /* For the 1023 case */
2179 tmp_free_buff_ring
&= (ET_DMA10_MASK
|ET_DMA10_WRAP
);
2180 *free_buff_ring
= tmp_free_buff_ring
;
2181 return tmp_free_buff_ring
;
2185 * et131x_align_allocated_memory - Align allocated memory on a given boundary
2186 * @adapter: pointer to our adapter structure
2187 * @phys_addr: pointer to Physical address
2188 * @offset: pointer to the offset variable
2189 * @mask: correct mask
2191 void et131x_align_allocated_memory(struct et131x_adapter
*adapter
,
2192 uint64_t *phys_addr
,
2193 uint64_t *offset
, uint64_t mask
)
2199 new_addr
= *phys_addr
& ~mask
;
2201 if (new_addr
!= *phys_addr
) {
2202 /* Move to next aligned block */
2203 new_addr
+= mask
+ 1;
2204 /* Return offset for adjusting virt addr */
2205 *offset
= new_addr
- *phys_addr
;
2206 /* Return new physical address */
2207 *phys_addr
= new_addr
;
2212 * et131x_rx_dma_memory_alloc
2213 * @adapter: pointer to our private adapter structure
2215 * Returns 0 on success and errno on failure (as defined in errno.h)
2217 * Allocates Free buffer ring 1 for sure, free buffer ring 0 if required,
2218 * and the Packet Status Ring.
2220 int et131x_rx_dma_memory_alloc(struct et131x_adapter
*adapter
)
2224 u32 pktstat_ringsize
, fbr_chunksize
;
2225 struct rx_ring
*rx_ring
;
2227 /* Setup some convenience pointers */
2228 rx_ring
= &adapter
->rx_ring
;
2230 /* Alloc memory for the lookup table */
2232 rx_ring
->fbr
[1] = kmalloc(sizeof(struct fbr_lookup
), GFP_KERNEL
);
2234 rx_ring
->fbr
[0] = kmalloc(sizeof(struct fbr_lookup
), GFP_KERNEL
);
2236 /* The first thing we will do is configure the sizes of the buffer
2237 * rings. These will change based on jumbo packet support. Larger
2238 * jumbo packets increases the size of each entry in FBR0, and the
2239 * number of entries in FBR0, while at the same time decreasing the
2240 * number of entries in FBR1.
2242 * FBR1 holds "large" frames, FBR0 holds "small" frames. If FBR1
2243 * entries are huge in order to accommodate a "jumbo" frame, then it
2244 * will have less entries. Conversely, FBR1 will now be relied upon
2245 * to carry more "normal" frames, thus it's entry size also increases
2246 * and the number of entries goes up too (since it now carries
2247 * "small" + "regular" packets.
2249 * In this scheme, we try to maintain 512 entries between the two
2250 * rings. Also, FBR1 remains a constant size - when it's size doubles
2251 * the number of entries halves. FBR0 increases in size, however.
2254 if (adapter
->registry_jumbo_packet
< 2048) {
2256 rx_ring
->fbr
[1]->buffsize
= 256;
2257 rx_ring
->fbr
[1]->num_entries
= 512;
2259 rx_ring
->fbr
[0]->buffsize
= 2048;
2260 rx_ring
->fbr
[0]->num_entries
= 512;
2261 } else if (adapter
->registry_jumbo_packet
< 4096) {
2263 rx_ring
->fbr
[1]->buffsize
= 512;
2264 rx_ring
->fbr
[1]->num_entries
= 1024;
2266 rx_ring
->fbr
[0]->buffsize
= 4096;
2267 rx_ring
->fbr
[0]->num_entries
= 512;
2270 rx_ring
->fbr
[1]->buffsize
= 1024;
2271 rx_ring
->fbr
[1]->num_entries
= 768;
2273 rx_ring
->fbr
[0]->buffsize
= 16384;
2274 rx_ring
->fbr
[0]->num_entries
= 128;
2278 adapter
->rx_ring
.psr_num_entries
= adapter
->rx_ring
.fbr
[1]->num_entries
+
2279 adapter
->rx_ring
.fbr
[0]->num_entries
;
2281 adapter
->rx_ring
.psr_num_entries
= adapter
->rx_ring
.fbr
[0]->num_entries
;
2284 /* Allocate an area of memory for Free Buffer Ring 1 */
2285 bufsize
= (sizeof(struct fbr_desc
) * rx_ring
->fbr
[0]->num_entries
) + 0xfff;
2286 rx_ring
->fbr
[0]->ring_virtaddr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
2288 &rx_ring
->fbr
[0]->ring_physaddr
,
2290 if (!rx_ring
->fbr
[0]->ring_virtaddr
) {
2291 dev_err(&adapter
->pdev
->dev
,
2292 "Cannot alloc memory for Free Buffer Ring 1\n");
2296 /* Save physical address
2298 * NOTE: dma_alloc_coherent(), used above to alloc DMA regions,
2299 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
2300 * are ever returned, make sure the high part is retrieved here
2301 * before storing the adjusted address.
2303 rx_ring
->fbr
[0]->real_physaddr
= rx_ring
->fbr
[0]->ring_physaddr
;
2305 /* Align Free Buffer Ring 1 on a 4K boundary */
2306 et131x_align_allocated_memory(adapter
,
2307 &rx_ring
->fbr
[0]->real_physaddr
,
2308 &rx_ring
->fbr
[0]->offset
, 0x0FFF);
2310 rx_ring
->fbr
[0]->ring_virtaddr
=
2311 (void *)((u8
*) rx_ring
->fbr
[0]->ring_virtaddr
+
2312 rx_ring
->fbr
[0]->offset
);
2315 /* Allocate an area of memory for Free Buffer Ring 0 */
2316 bufsize
= (sizeof(struct fbr_desc
) * rx_ring
->fbr
[1]->num_entries
) + 0xfff;
2317 rx_ring
->fbr
[1]->ring_virtaddr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
2319 &rx_ring
->fbr
[1]->ring_physaddr
,
2321 if (!rx_ring
->fbr
[1]->ring_virtaddr
) {
2322 dev_err(&adapter
->pdev
->dev
,
2323 "Cannot alloc memory for Free Buffer Ring 0\n");
2327 /* Save physical address
2329 * NOTE: dma_alloc_coherent(), used above to alloc DMA regions,
2330 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
2331 * are ever returned, make sure the high part is retrieved here before
2332 * storing the adjusted address.
2334 rx_ring
->fbr
[1]->real_physaddr
= rx_ring
->fbr
[1]->ring_physaddr
;
2336 /* Align Free Buffer Ring 0 on a 4K boundary */
2337 et131x_align_allocated_memory(adapter
,
2338 &rx_ring
->fbr
[1]->real_physaddr
,
2339 &rx_ring
->fbr
[1]->offset
, 0x0FFF);
2341 rx_ring
->fbr
[1]->ring_virtaddr
=
2342 (void *)((u8
*) rx_ring
->fbr
[1]->ring_virtaddr
+
2343 rx_ring
->fbr
[1]->offset
);
2345 for (i
= 0; i
< (rx_ring
->fbr
[0]->num_entries
/ FBR_CHUNKS
); i
++) {
2347 u64 fbr1_tmp_physaddr
;
2350 /* This code allocates an area of memory big enough for N
2351 * free buffers + (buffer_size - 1) so that the buffers can
2352 * be aligned on 4k boundaries. If each buffer were aligned
2353 * to a buffer_size boundary, the effect would be to double
2354 * the size of FBR0. By allocating N buffers at once, we
2355 * reduce this overhead.
2357 if (rx_ring
->fbr
[0]->buffsize
> 4096)
2360 fbr1_align
= rx_ring
->fbr
[0]->buffsize
;
2363 (FBR_CHUNKS
* rx_ring
->fbr
[0]->buffsize
) + fbr1_align
- 1;
2364 rx_ring
->fbr
[0]->mem_virtaddrs
[i
] =
2365 dma_alloc_coherent(&adapter
->pdev
->dev
, fbr_chunksize
,
2366 &rx_ring
->fbr
[0]->mem_physaddrs
[i
], GFP_KERNEL
);
2368 if (!rx_ring
->fbr
[0]->mem_virtaddrs
[i
]) {
2369 dev_err(&adapter
->pdev
->dev
,
2370 "Could not alloc memory\n");
2374 /* See NOTE in "Save Physical Address" comment above */
2375 fbr1_tmp_physaddr
= rx_ring
->fbr
[0]->mem_physaddrs
[i
];
2377 et131x_align_allocated_memory(adapter
,
2379 &fbr1_offset
, (fbr1_align
- 1));
2381 for (j
= 0; j
< FBR_CHUNKS
; j
++) {
2382 u32 index
= (i
* FBR_CHUNKS
) + j
;
2384 /* Save the Virtual address of this index for quick
2387 rx_ring
->fbr
[0]->virt
[index
] =
2388 (u8
*) rx_ring
->fbr
[0]->mem_virtaddrs
[i
] +
2389 (j
* rx_ring
->fbr
[0]->buffsize
) + fbr1_offset
;
2391 /* now store the physical address in the descriptor
2392 * so the device can access it
2394 rx_ring
->fbr
[0]->bus_high
[index
] =
2395 (u32
) (fbr1_tmp_physaddr
>> 32);
2396 rx_ring
->fbr
[0]->bus_low
[index
] =
2397 (u32
) fbr1_tmp_physaddr
;
2399 fbr1_tmp_physaddr
+= rx_ring
->fbr
[0]->buffsize
;
2401 rx_ring
->fbr
[0]->buffer1
[index
] =
2402 rx_ring
->fbr
[0]->virt
[index
];
2403 rx_ring
->fbr
[0]->buffer2
[index
] =
2404 rx_ring
->fbr
[0]->virt
[index
] - 4;
2409 /* Same for FBR0 (if in use) */
2410 for (i
= 0; i
< (rx_ring
->fbr
[1]->num_entries
/ FBR_CHUNKS
); i
++) {
2412 u64 fbr0_tmp_physaddr
;
2415 ((FBR_CHUNKS
+ 1) * rx_ring
->fbr
[1]->buffsize
) - 1;
2416 rx_ring
->fbr
[1]->mem_virtaddrs
[i
] =
2417 dma_alloc_coherent(&adapter
->pdev
->dev
, fbr_chunksize
,
2418 &rx_ring
->fbr
[1]->mem_physaddrs
[i
], GFP_KERNEL
);
2420 if (!rx_ring
->fbr
[1]->mem_virtaddrs
[i
]) {
2421 dev_err(&adapter
->pdev
->dev
,
2422 "Could not alloc memory\n");
2426 /* See NOTE in "Save Physical Address" comment above */
2427 fbr0_tmp_physaddr
= rx_ring
->fbr
[1]->mem_physaddrs
[i
];
2429 et131x_align_allocated_memory(adapter
,
2432 rx_ring
->fbr
[1]->buffsize
- 1);
2434 for (j
= 0; j
< FBR_CHUNKS
; j
++) {
2435 u32 index
= (i
* FBR_CHUNKS
) + j
;
2437 rx_ring
->fbr
[1]->virt
[index
] =
2438 (u8
*) rx_ring
->fbr
[1]->mem_virtaddrs
[i
] +
2439 (j
* rx_ring
->fbr
[1]->buffsize
) + fbr0_offset
;
2441 rx_ring
->fbr
[1]->bus_high
[index
] =
2442 (u32
) (fbr0_tmp_physaddr
>> 32);
2443 rx_ring
->fbr
[1]->bus_low
[index
] =
2444 (u32
) fbr0_tmp_physaddr
;
2446 fbr0_tmp_physaddr
+= rx_ring
->fbr
[1]->buffsize
;
2448 rx_ring
->fbr
[1]->buffer1
[index
] =
2449 rx_ring
->fbr
[1]->virt
[index
];
2450 rx_ring
->fbr
[1]->buffer2
[index
] =
2451 rx_ring
->fbr
[1]->virt
[index
] - 4;
2456 /* Allocate an area of memory for FIFO of Packet Status ring entries */
2458 sizeof(struct pkt_stat_desc
) * adapter
->rx_ring
.psr_num_entries
;
2460 rx_ring
->ps_ring_virtaddr
= dma_alloc_coherent(&adapter
->pdev
->dev
,
2462 &rx_ring
->ps_ring_physaddr
,
2465 if (!rx_ring
->ps_ring_virtaddr
) {
2466 dev_err(&adapter
->pdev
->dev
,
2467 "Cannot alloc memory for Packet Status Ring\n");
2470 printk(KERN_INFO
"Packet Status Ring %lx\n",
2471 (unsigned long) rx_ring
->ps_ring_physaddr
);
2474 * NOTE : dma_alloc_coherent(), used above to alloc DMA regions,
2475 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
2476 * are ever returned, make sure the high part is retrieved here before
2477 * storing the adjusted address.
2480 /* Allocate an area of memory for writeback of status information */
2481 rx_ring
->rx_status_block
= dma_alloc_coherent(&adapter
->pdev
->dev
,
2482 sizeof(struct rx_status_block
),
2483 &rx_ring
->rx_status_bus
,
2485 if (!rx_ring
->rx_status_block
) {
2486 dev_err(&adapter
->pdev
->dev
,
2487 "Cannot alloc memory for Status Block\n");
2490 rx_ring
->num_rfd
= NIC_DEFAULT_NUM_RFD
;
2491 printk(KERN_INFO
"PRS %lx\n", (unsigned long)rx_ring
->rx_status_bus
);
2494 * kmem_cache_create initializes a lookaside list. After successful
2495 * creation, nonpaged fixed-size blocks can be allocated from and
2496 * freed to the lookaside list.
2497 * RFDs will be allocated from this pool.
2499 rx_ring
->recv_lookaside
= kmem_cache_create(adapter
->netdev
->name
,
2506 adapter
->flags
|= fMP_ADAPTER_RECV_LOOKASIDE
;
2508 /* The RFDs are going to be put on lists later on, so initialize the
2511 INIT_LIST_HEAD(&rx_ring
->recv_list
);
2516 * et131x_rx_dma_memory_free - Free all memory allocated within this module.
2517 * @adapter: pointer to our private adapter structure
2519 void et131x_rx_dma_memory_free(struct et131x_adapter
*adapter
)
2523 u32 pktstat_ringsize
;
2525 struct rx_ring
*rx_ring
;
2527 /* Setup some convenience pointers */
2528 rx_ring
= &adapter
->rx_ring
;
2530 /* Free RFDs and associated packet descriptors */
2531 WARN_ON(rx_ring
->num_ready_recv
!= rx_ring
->num_rfd
);
2533 while (!list_empty(&rx_ring
->recv_list
)) {
2534 rfd
= (struct rfd
*) list_entry(rx_ring
->recv_list
.next
,
2535 struct rfd
, list_node
);
2537 list_del(&rfd
->list_node
);
2539 kmem_cache_free(adapter
->rx_ring
.recv_lookaside
, rfd
);
2542 /* Free Free Buffer Ring 1 */
2543 if (rx_ring
->fbr
[0]->ring_virtaddr
) {
2544 /* First the packet memory */
2545 for (index
= 0; index
<
2546 (rx_ring
->fbr
[0]->num_entries
/ FBR_CHUNKS
); index
++) {
2547 if (rx_ring
->fbr
[0]->mem_virtaddrs
[index
]) {
2550 if (rx_ring
->fbr
[0]->buffsize
> 4096)
2553 fbr1_align
= rx_ring
->fbr
[0]->buffsize
;
2556 (rx_ring
->fbr
[0]->buffsize
* FBR_CHUNKS
) +
2559 dma_free_coherent(&adapter
->pdev
->dev
,
2561 rx_ring
->fbr
[0]->mem_virtaddrs
[index
],
2562 rx_ring
->fbr
[0]->mem_physaddrs
[index
]);
2564 rx_ring
->fbr
[0]->mem_virtaddrs
[index
] = NULL
;
2568 /* Now the FIFO itself */
2569 rx_ring
->fbr
[0]->ring_virtaddr
= (void *)((u8
*)
2570 rx_ring
->fbr
[0]->ring_virtaddr
- rx_ring
->fbr
[0]->offset
);
2572 bufsize
= (sizeof(struct fbr_desc
) * rx_ring
->fbr
[0]->num_entries
)
2575 dma_free_coherent(&adapter
->pdev
->dev
, bufsize
,
2576 rx_ring
->fbr
[0]->ring_virtaddr
,
2577 rx_ring
->fbr
[0]->ring_physaddr
);
2579 rx_ring
->fbr
[0]->ring_virtaddr
= NULL
;
2583 /* Now the same for Free Buffer Ring 0 */
2584 if (rx_ring
->fbr
[1]->ring_virtaddr
) {
2585 /* First the packet memory */
2586 for (index
= 0; index
<
2587 (rx_ring
->fbr
[1]->num_entries
/ FBR_CHUNKS
); index
++) {
2588 if (rx_ring
->fbr
[1]->mem_virtaddrs
[index
]) {
2590 (rx_ring
->fbr
[1]->buffsize
*
2591 (FBR_CHUNKS
+ 1)) - 1;
2593 dma_free_coherent(&adapter
->pdev
->dev
,
2595 rx_ring
->fbr
[1]->mem_virtaddrs
[index
],
2596 rx_ring
->fbr
[1]->mem_physaddrs
[index
]);
2598 rx_ring
->fbr
[1]->mem_virtaddrs
[index
] = NULL
;
2602 /* Now the FIFO itself */
2603 rx_ring
->fbr
[1]->ring_virtaddr
= (void *)((u8
*)
2604 rx_ring
->fbr
[1]->ring_virtaddr
- rx_ring
->fbr
[1]->offset
);
2606 bufsize
= (sizeof(struct fbr_desc
) * rx_ring
->fbr
[1]->num_entries
)
2609 dma_free_coherent(&adapter
->pdev
->dev
,
2611 rx_ring
->fbr
[1]->ring_virtaddr
,
2612 rx_ring
->fbr
[1]->ring_physaddr
);
2614 rx_ring
->fbr
[1]->ring_virtaddr
= NULL
;
2618 /* Free Packet Status Ring */
2619 if (rx_ring
->ps_ring_virtaddr
) {
2621 sizeof(struct pkt_stat_desc
) *
2622 adapter
->rx_ring
.psr_num_entries
;
2624 dma_free_coherent(&adapter
->pdev
->dev
, pktstat_ringsize
,
2625 rx_ring
->ps_ring_virtaddr
,
2626 rx_ring
->ps_ring_physaddr
);
2628 rx_ring
->ps_ring_virtaddr
= NULL
;
2631 /* Free area of memory for the writeback of status information */
2632 if (rx_ring
->rx_status_block
) {
2633 dma_free_coherent(&adapter
->pdev
->dev
,
2634 sizeof(struct rx_status_block
),
2635 rx_ring
->rx_status_block
, rx_ring
->rx_status_bus
);
2636 rx_ring
->rx_status_block
= NULL
;
2639 /* Destroy the lookaside (RFD) pool */
2640 if (adapter
->flags
& fMP_ADAPTER_RECV_LOOKASIDE
) {
2641 kmem_cache_destroy(rx_ring
->recv_lookaside
);
2642 adapter
->flags
&= ~fMP_ADAPTER_RECV_LOOKASIDE
;
2645 /* Free the FBR Lookup Table */
2647 kfree(rx_ring
->fbr
[1]);
2650 kfree(rx_ring
->fbr
[0]);
2652 /* Reset Counters */
2653 rx_ring
->num_ready_recv
= 0;
2657 * et131x_init_recv - Initialize receive data structures.
2658 * @adapter: pointer to our private adapter structure
2660 * Returns 0 on success and errno on failure (as defined in errno.h)
2662 int et131x_init_recv(struct et131x_adapter
*adapter
)
2664 int status
= -ENOMEM
;
2665 struct rfd
*rfd
= NULL
;
2668 struct rx_ring
*rx_ring
;
2670 /* Setup some convenience pointers */
2671 rx_ring
= &adapter
->rx_ring
;
2673 /* Setup each RFD */
2674 for (rfdct
= 0; rfdct
< rx_ring
->num_rfd
; rfdct
++) {
2675 rfd
= kmem_cache_alloc(rx_ring
->recv_lookaside
,
2676 GFP_ATOMIC
| GFP_DMA
);
2679 dev_err(&adapter
->pdev
->dev
,
2680 "Couldn't alloc RFD out of kmem_cache\n");
2687 /* Add this RFD to the recv_list */
2688 list_add_tail(&rfd
->list_node
, &rx_ring
->recv_list
);
2690 /* Increment both the available RFD's, and the total RFD's. */
2691 rx_ring
->num_ready_recv
++;
2695 if (numrfd
> NIC_MIN_NUM_RFD
)
2698 rx_ring
->num_rfd
= numrfd
;
2701 kmem_cache_free(rx_ring
->recv_lookaside
, rfd
);
2702 dev_err(&adapter
->pdev
->dev
,
2703 "Allocation problems in et131x_init_recv\n");
2709 * et131x_set_rx_dma_timer - Set the heartbeat timer according to line rate.
2710 * @adapter: pointer to our adapter structure
2712 void et131x_set_rx_dma_timer(struct et131x_adapter
*adapter
)
2714 struct phy_device
*phydev
= adapter
->phydev
;
2719 /* For version B silicon, we do not use the RxDMA timer for 10 and 100
2720 * Mbits/s line rates. We do not enable and RxDMA interrupt coalescing.
2722 if ((phydev
->speed
== SPEED_100
) || (phydev
->speed
== SPEED_10
)) {
2723 writel(0, &adapter
->regs
->rxdma
.max_pkt_time
);
2724 writel(1, &adapter
->regs
->rxdma
.num_pkt_done
);
2729 * NICReturnRFD - Recycle a RFD and put it back onto the receive list
2730 * @adapter: pointer to our adapter
2731 * @rfd: pointer to the RFD
2733 static void nic_return_rfd(struct et131x_adapter
*adapter
, struct rfd
*rfd
)
2735 struct rx_ring
*rx_local
= &adapter
->rx_ring
;
2736 struct rxdma_regs __iomem
*rx_dma
= &adapter
->regs
->rxdma
;
2737 u16 buff_index
= rfd
->bufferindex
;
2738 u8 ring_index
= rfd
->ringindex
;
2739 unsigned long flags
;
2741 /* We don't use any of the OOB data besides status. Otherwise, we
2742 * need to clean up OOB data
2746 (ring_index
== 0 && buff_index
< rx_local
->fbr
[1]->num_entries
) ||
2748 (ring_index
== 1 && buff_index
< rx_local
->fbr
[0]->num_entries
)) {
2749 spin_lock_irqsave(&adapter
->fbr_lock
, flags
);
2751 if (ring_index
== 1) {
2752 struct fbr_desc
*next
=
2753 (struct fbr_desc
*) (rx_local
->fbr
[0]->ring_virtaddr
) +
2754 INDEX10(rx_local
->fbr
[0]->local_full
);
2756 /* Handle the Free Buffer Ring advancement here. Write
2757 * the PA / Buffer Index for the returned buffer into
2758 * the oldest (next to be freed)FBR entry
2760 next
->addr_hi
= rx_local
->fbr
[0]->bus_high
[buff_index
];
2761 next
->addr_lo
= rx_local
->fbr
[0]->bus_low
[buff_index
];
2762 next
->word2
= buff_index
;
2764 writel(bump_free_buff_ring(&rx_local
->fbr
[0]->local_full
,
2765 rx_local
->fbr
[0]->num_entries
- 1),
2766 &rx_dma
->fbr1_full_offset
);
2770 struct fbr_desc
*next
= (struct fbr_desc
*)
2771 rx_local
->fbr
[1]->ring_virtaddr
+
2772 INDEX10(rx_local
->fbr
[1]->local_full
);
2774 /* Handle the Free Buffer Ring advancement here. Write
2775 * the PA / Buffer Index for the returned buffer into
2776 * the oldest (next to be freed) FBR entry
2778 next
->addr_hi
= rx_local
->fbr
[1]->bus_high
[buff_index
];
2779 next
->addr_lo
= rx_local
->fbr
[1]->bus_low
[buff_index
];
2780 next
->word2
= buff_index
;
2782 writel(bump_free_buff_ring(
2783 &rx_local
->fbr
[1]->local_full
,
2784 rx_local
->fbr
[1]->num_entries
- 1),
2785 &rx_dma
->fbr0_full_offset
);
2788 spin_unlock_irqrestore(&adapter
->fbr_lock
, flags
);
2790 dev_err(&adapter
->pdev
->dev
,
2791 "%s illegal Buffer Index returned\n", __func__
);
2794 /* The processing on this RFD is done, so put it back on the tail of
2797 spin_lock_irqsave(&adapter
->rcv_lock
, flags
);
2798 list_add_tail(&rfd
->list_node
, &rx_local
->recv_list
);
2799 rx_local
->num_ready_recv
++;
2800 spin_unlock_irqrestore(&adapter
->rcv_lock
, flags
);
2802 WARN_ON(rx_local
->num_ready_recv
> rx_local
->num_rfd
);
2806 * et131x_rx_dma_disable - Stop of Rx_DMA on the ET1310
2807 * @adapter: pointer to our adapter structure
2809 void et131x_rx_dma_disable(struct et131x_adapter
*adapter
)
2812 /* Setup the receive dma configuration register */
2813 writel(0x00002001, &adapter
->regs
->rxdma
.csr
);
2814 csr
= readl(&adapter
->regs
->rxdma
.csr
);
2815 if ((csr
& 0x00020000) == 0) { /* Check halt status (bit 17) */
2817 csr
= readl(&adapter
->regs
->rxdma
.csr
);
2818 if ((csr
& 0x00020000) == 0)
2819 dev_err(&adapter
->pdev
->dev
,
2820 "RX Dma failed to enter halt state. CSR 0x%08x\n",
2826 * et131x_rx_dma_enable - re-start of Rx_DMA on the ET1310.
2827 * @adapter: pointer to our adapter structure
2829 void et131x_rx_dma_enable(struct et131x_adapter
*adapter
)
2831 /* Setup the receive dma configuration register for normal operation */
2832 u32 csr
= 0x2000; /* FBR1 enable */
2834 if (adapter
->rx_ring
.fbr
[0]->buffsize
== 4096)
2836 else if (adapter
->rx_ring
.fbr
[0]->buffsize
== 8192)
2838 else if (adapter
->rx_ring
.fbr
[0]->buffsize
== 16384)
2841 csr
|= 0x0400; /* FBR0 enable */
2842 if (adapter
->rx_ring
.fbr
[1]->buffsize
== 256)
2844 else if (adapter
->rx_ring
.fbr
[1]->buffsize
== 512)
2846 else if (adapter
->rx_ring
.fbr
[1]->buffsize
== 1024)
2849 writel(csr
, &adapter
->regs
->rxdma
.csr
);
2851 csr
= readl(&adapter
->regs
->rxdma
.csr
);
2852 if ((csr
& 0x00020000) != 0) {
2854 csr
= readl(&adapter
->regs
->rxdma
.csr
);
2855 if ((csr
& 0x00020000) != 0) {
2856 dev_err(&adapter
->pdev
->dev
,
2857 "RX Dma failed to exit halt state. CSR 0x%08x\n",
2864 static inline void add_10bit(u32
*v
, int n
)
2866 *v
= INDEX10(*v
+ n
) | (*v
& ET_DMA10_WRAP
);
2869 static inline void add_12bit(u32
*v
, int n
)
2871 *v
= INDEX12(*v
+ n
) | (*v
& ET_DMA12_WRAP
);
2875 * nic_rx_pkts - Checks the hardware for available packets
2876 * @adapter: pointer to our adapter
2878 * Returns rfd, a pointer to our MPRFD.
2880 * Checks the hardware for available packets, using completion ring
2881 * If packets are available, it gets an RFD from the recv_list, attaches
2882 * the packet to it, puts the RFD in the RecvPendList, and also returns
2883 * the pointer to the RFD.
2885 static struct rfd
*nic_rx_pkts(struct et131x_adapter
*adapter
)
2887 struct rx_ring
*rx_local
= &adapter
->rx_ring
;
2888 struct rx_status_block
*status
;
2889 struct pkt_stat_desc
*psr
;
2893 unsigned long flags
;
2894 struct list_head
*element
;
2901 /* RX Status block is written by the DMA engine prior to every
2902 * interrupt. It contains the next to be used entry in the Packet
2903 * Status Ring, and also the two Free Buffer rings.
2905 status
= rx_local
->rx_status_block
;
2906 word1
= status
->word1
>> 16; /* Get the useful bits */
2908 /* Check the PSR and wrap bits do not match */
2909 if ((word1
& 0x1FFF) == (rx_local
->local_psr_full
& 0x1FFF))
2910 /* Looks like this ring is not updated yet */
2913 /* The packet status ring indicates that data is available. */
2914 psr
= (struct pkt_stat_desc
*) (rx_local
->ps_ring_virtaddr
) +
2915 (rx_local
->local_psr_full
& 0xFFF);
2917 /* Grab any information that is required once the PSR is
2918 * advanced, since we can no longer rely on the memory being
2921 len
= psr
->word1
& 0xFFFF;
2922 ring_index
= (psr
->word1
>> 26) & 0x03;
2923 buff_index
= (psr
->word1
>> 16) & 0x3FF;
2926 /* Indicate that we have used this PSR entry. */
2928 add_12bit(&rx_local
->local_psr_full
, 1);
2930 (rx_local
->local_psr_full
& 0xFFF) > rx_local
->psr_num_entries
- 1) {
2931 /* Clear psr full and toggle the wrap bit */
2932 rx_local
->local_psr_full
&= ~0xFFF;
2933 rx_local
->local_psr_full
^= 0x1000;
2936 writel(rx_local
->local_psr_full
,
2937 &adapter
->regs
->rxdma
.psr_full_offset
);
2940 if (ring_index
!= 1)
2945 if (ring_index
> 1 ||
2947 buff_index
> rx_local
->fbr
[1]->num_entries
- 1) ||
2949 buff_index
> rx_local
->fbr
[0]->num_entries
- 1))
2951 if (ring_index
!= 1 || buff_index
> rx_local
->fbr
[0]->num_entries
- 1)
2954 /* Illegal buffer or ring index cannot be used by S/W*/
2955 dev_err(&adapter
->pdev
->dev
,
2956 "NICRxPkts PSR Entry %d indicates "
2957 "length of %d and/or bad bi(%d)\n",
2958 rx_local
->local_psr_full
& 0xFFF,
2963 /* Get and fill the RFD. */
2964 spin_lock_irqsave(&adapter
->rcv_lock
, flags
);
2967 element
= rx_local
->recv_list
.next
;
2968 rfd
= (struct rfd
*) list_entry(element
, struct rfd
, list_node
);
2971 spin_unlock_irqrestore(&adapter
->rcv_lock
, flags
);
2975 list_del(&rfd
->list_node
);
2976 rx_local
->num_ready_recv
--;
2978 spin_unlock_irqrestore(&adapter
->rcv_lock
, flags
);
2980 rfd
->bufferindex
= buff_index
;
2981 rfd
->ringindex
= ring_index
;
2983 /* In V1 silicon, there is a bug which screws up filtering of
2984 * runt packets. Therefore runt packet filtering is disabled
2985 * in the MAC and the packets are dropped here. They are
2986 * also counted here.
2988 if (len
< (NIC_MIN_PACKET_SIZE
+ 4)) {
2989 adapter
->stats
.rx_other_errs
++;
2994 /* Determine if this is a multicast packet coming in */
2995 if ((word0
& ALCATEL_MULTICAST_PKT
) &&
2996 !(word0
& ALCATEL_BROADCAST_PKT
)) {
2997 /* Promiscuous mode and Multicast mode are
2998 * not mutually exclusive as was first
2999 * thought. I guess Promiscuous is just
3000 * considered a super-set of the other
3001 * filters. Generally filter is 0x2b when in
3004 if ((adapter
->packet_filter
&
3005 ET131X_PACKET_TYPE_MULTICAST
)
3006 && !(adapter
->packet_filter
&
3007 ET131X_PACKET_TYPE_PROMISCUOUS
)
3008 && !(adapter
->packet_filter
&
3009 ET131X_PACKET_TYPE_ALL_MULTICAST
)) {
3011 * Note - ring_index for fbr[] array is reversed
3014 buf
= rx_local
->fbr
[(ring_index
== 0 ? 1 : 0)]->
3017 /* Loop through our list to see if the
3018 * destination address of this packet
3019 * matches one in our list.
3021 for (i
= 0; i
< adapter
->multicast_addr_count
;
3024 adapter
->multicast_list
[i
][0]
3026 adapter
->multicast_list
[i
][1]
3028 adapter
->multicast_list
[i
][2]
3030 adapter
->multicast_list
[i
][3]
3032 adapter
->multicast_list
[i
][4]
3034 adapter
->multicast_list
[i
][5]) {
3039 /* If our index is equal to the number
3040 * of Multicast address we have, then
3041 * this means we did not find this
3042 * packet's matching address in our
3043 * list. Set the len to zero,
3044 * so we free our RFD when we return
3045 * from this function.
3047 if (i
== adapter
->multicast_addr_count
)
3052 adapter
->stats
.multicast_pkts_rcvd
++;
3053 } else if (word0
& ALCATEL_BROADCAST_PKT
)
3054 adapter
->stats
.broadcast_pkts_rcvd
++;
3056 /* Not sure what this counter measures in
3057 * promiscuous mode. Perhaps we should check
3058 * the MAC address to see if it is directed
3059 * to us in promiscuous mode.
3061 adapter
->stats
.unicast_pkts_rcvd
++;
3065 struct sk_buff
*skb
= NULL
;
3067 /*rfd->len = len - 4; */
3070 skb
= dev_alloc_skb(rfd
->len
+ 2);
3072 dev_err(&adapter
->pdev
->dev
,
3073 "Couldn't alloc an SKB for Rx\n");
3077 adapter
->net_stats
.rx_bytes
+= rfd
->len
;
3080 * Note - ring_index for fbr[] array is reversed,
3083 memcpy(skb_put(skb
, rfd
->len
),
3084 rx_local
->fbr
[(ring_index
== 0 ? 1 : 0)]->virt
[buff_index
],
3087 skb
->dev
= adapter
->netdev
;
3088 skb
->protocol
= eth_type_trans(skb
, adapter
->netdev
);
3089 skb
->ip_summed
= CHECKSUM_NONE
;
3096 nic_return_rfd(adapter
, rfd
);
3101 * et131x_handle_recv_interrupt - Interrupt handler for receive processing
3102 * @adapter: pointer to our adapter
3104 * Assumption, Rcv spinlock has been acquired.
3106 void et131x_handle_recv_interrupt(struct et131x_adapter
*adapter
)
3108 struct rfd
*rfd
= NULL
;
3112 /* Process up to available RFD's */
3113 while (count
< NUM_PACKETS_HANDLED
) {
3114 if (list_empty(&adapter
->rx_ring
.recv_list
)) {
3115 WARN_ON(adapter
->rx_ring
.num_ready_recv
!= 0);
3120 rfd
= nic_rx_pkts(adapter
);
3125 /* Do not receive any packets until a filter has been set.
3126 * Do not receive any packets until we have link.
3127 * If length is zero, return the RFD in order to advance the
3130 if (!adapter
->packet_filter
||
3131 !netif_carrier_ok(adapter
->netdev
) ||
3135 /* Increment the number of packets we received */
3136 adapter
->net_stats
.rx_packets
++;
3138 /* Set the status on the packet, either resources or success */
3139 if (adapter
->rx_ring
.num_ready_recv
< RFD_LOW_WATER_MARK
) {
3140 dev_warn(&adapter
->pdev
->dev
,
3141 "RFD's are running out\n");
3146 if (count
== NUM_PACKETS_HANDLED
|| !done
) {
3147 adapter
->rx_ring
.unfinished_receives
= true;
3148 writel(PARM_TX_TIME_INT_DEF
* NANO_IN_A_MICRO
,
3149 &adapter
->regs
->global
.watchdog_timer
);
3151 /* Watchdog timer will disable itself if appropriate. */
3152 adapter
->rx_ring
.unfinished_receives
= false;
3158 * et131x_tx_dma_memory_alloc
3159 * @adapter: pointer to our private adapter structure
3161 * Returns 0 on success and errno on failure (as defined in errno.h).
3163 * Allocates memory that will be visible both to the device and to the CPU.
3164 * The OS will pass us packets, pointers to which we will insert in the Tx
3165 * Descriptor queue. The device will read this queue to find the packets in
3166 * memory. The device will update the "status" in memory each time it xmits a
3169 int et131x_tx_dma_memory_alloc(struct et131x_adapter
*adapter
)
3172 struct tx_ring
*tx_ring
= &adapter
->tx_ring
;
3174 /* Allocate memory for the TCB's (Transmit Control Block) */
3175 adapter
->tx_ring
.tcb_ring
=
3176 kcalloc(NUM_TCB
, sizeof(struct tcb
), GFP_ATOMIC
| GFP_DMA
);
3177 if (!adapter
->tx_ring
.tcb_ring
) {
3178 dev_err(&adapter
->pdev
->dev
, "Cannot alloc memory for TCBs\n");
3182 /* Allocate enough memory for the Tx descriptor ring, and allocate
3183 * some extra so that the ring can be aligned on a 4k boundary.
3185 desc_size
= (sizeof(struct tx_desc
) * NUM_DESC_PER_RING_TX
) + 4096 - 1;
3186 tx_ring
->tx_desc_ring
=
3187 (struct tx_desc
*) dma_alloc_coherent(&adapter
->pdev
->dev
, desc_size
,
3188 &tx_ring
->tx_desc_ring_pa
, GFP_KERNEL
);
3189 if (!adapter
->tx_ring
.tx_desc_ring
) {
3190 dev_err(&adapter
->pdev
->dev
,
3191 "Cannot alloc memory for Tx Ring\n");
3195 /* Save physical address
3197 * NOTE: dma_alloc_coherent(), used above to alloc DMA regions,
3198 * ALWAYS returns SAC (32-bit) addresses. If DAC (64-bit) addresses
3199 * are ever returned, make sure the high part is retrieved here before
3200 * storing the adjusted address.
3202 /* Allocate memory for the Tx status block */
3203 tx_ring
->tx_status
= dma_alloc_coherent(&adapter
->pdev
->dev
,
3205 &tx_ring
->tx_status_pa
,
3207 if (!adapter
->tx_ring
.tx_status_pa
) {
3208 dev_err(&adapter
->pdev
->dev
,
3209 "Cannot alloc memory for Tx status block\n");
3216 * et131x_tx_dma_memory_free - Free all memory allocated within this module
3217 * @adapter: pointer to our private adapter structure
3219 * Returns 0 on success and errno on failure (as defined in errno.h).
3221 void et131x_tx_dma_memory_free(struct et131x_adapter
*adapter
)
3225 if (adapter
->tx_ring
.tx_desc_ring
) {
3226 /* Free memory relating to Tx rings here */
3227 desc_size
= (sizeof(struct tx_desc
) * NUM_DESC_PER_RING_TX
)
3229 dma_free_coherent(&adapter
->pdev
->dev
,
3231 adapter
->tx_ring
.tx_desc_ring
,
3232 adapter
->tx_ring
.tx_desc_ring_pa
);
3233 adapter
->tx_ring
.tx_desc_ring
= NULL
;
3236 /* Free memory for the Tx status block */
3237 if (adapter
->tx_ring
.tx_status
) {
3238 dma_free_coherent(&adapter
->pdev
->dev
,
3240 adapter
->tx_ring
.tx_status
,
3241 adapter
->tx_ring
.tx_status_pa
);
3243 adapter
->tx_ring
.tx_status
= NULL
;
3245 /* Free the memory for the tcb structures */
3246 kfree(adapter
->tx_ring
.tcb_ring
);
3250 * et131x_init_send - Initialize send data structures
3251 * @adapter: pointer to our private adapter structure
3253 void et131x_init_send(struct et131x_adapter
*adapter
)
3257 struct tx_ring
*tx_ring
;
3259 /* Setup some convenience pointers */
3260 tx_ring
= &adapter
->tx_ring
;
3261 tcb
= adapter
->tx_ring
.tcb_ring
;
3263 tx_ring
->tcb_qhead
= tcb
;
3265 memset(tcb
, 0, sizeof(struct tcb
) * NUM_TCB
);
3267 /* Go through and set up each TCB */
3268 for (ct
= 0; ct
++ < NUM_TCB
; tcb
++)
3269 /* Set the link pointer in HW TCB to the next TCB in the
3272 tcb
->next
= tcb
+ 1;
3274 /* Set the tail pointer */
3276 tx_ring
->tcb_qtail
= tcb
;
3278 /* Curr send queue should now be empty */
3279 tx_ring
->send_head
= NULL
;
3280 tx_ring
->send_tail
= NULL
;
3284 * nic_send_packet - NIC specific send handler for version B silicon.
3285 * @adapter: pointer to our adapter
3286 * @tcb: pointer to struct tcb
3288 * Returns 0 or errno.
3290 static int nic_send_packet(struct et131x_adapter
*adapter
, struct tcb
*tcb
)
3293 struct tx_desc desc
[24]; /* 24 x 16 byte */
3295 u32 thiscopy
, remainder
;
3296 struct sk_buff
*skb
= tcb
->skb
;
3297 u32 nr_frags
= skb_shinfo(skb
)->nr_frags
+ 1;
3298 struct skb_frag_struct
*frags
= &skb_shinfo(skb
)->frags
[0];
3299 unsigned long flags
;
3300 struct phy_device
*phydev
= adapter
->phydev
;
3302 /* Part of the optimizations of this send routine restrict us to
3303 * sending 24 fragments at a pass. In practice we should never see
3304 * more than 5 fragments.
3306 * NOTE: The older version of this function (below) can handle any
3307 * number of fragments. If needed, we can call this function,
3308 * although it is less efficient.
3313 memset(desc
, 0, sizeof(struct tx_desc
) * (nr_frags
+ 1));
3315 for (i
= 0; i
< nr_frags
; i
++) {
3316 /* If there is something in this element, lets get a
3317 * descriptor from the ring and get the necessary data
3320 /* If the fragments are smaller than a standard MTU,
3321 * then map them to a single descriptor in the Tx
3322 * Desc ring. However, if they're larger, as is
3323 * possible with support for jumbo packets, then
3324 * split them each across 2 descriptors.
3326 * This will work until we determine why the hardware
3327 * doesn't seem to like large fragments.
3329 if ((skb
->len
- skb
->data_len
) <= 1514) {
3330 desc
[frag
].addr_hi
= 0;
3331 /* Low 16bits are length, high is vlan and
3332 unused currently so zero */
3333 desc
[frag
].len_vlan
=
3334 skb
->len
- skb
->data_len
;
3336 /* NOTE: Here, the dma_addr_t returned from
3337 * dma_map_single() is implicitly cast as a
3338 * u32. Although dma_addr_t can be
3339 * 64-bit, the address returned by
3340 * dma_map_single() is always 32-bit
3341 * addressable (as defined by the pci/dma
3344 desc
[frag
++].addr_lo
=
3345 dma_map_single(&adapter
->pdev
->dev
,
3351 desc
[frag
].addr_hi
= 0;
3352 desc
[frag
].len_vlan
=
3353 (skb
->len
- skb
->data_len
) / 2;
3355 /* NOTE: Here, the dma_addr_t returned from
3356 * dma_map_single() is implicitly cast as a
3357 * u32. Although dma_addr_t can be
3358 * 64-bit, the address returned by
3359 * dma_map_single() is always 32-bit
3360 * addressable (as defined by the pci/dma
3363 desc
[frag
++].addr_lo
=
3364 dma_map_single(&adapter
->pdev
->dev
,
3367 skb
->data_len
) / 2),
3369 desc
[frag
].addr_hi
= 0;
3371 desc
[frag
].len_vlan
=
3372 (skb
->len
- skb
->data_len
) / 2;
3374 /* NOTE: Here, the dma_addr_t returned from
3375 * dma_map_single() is implicitly cast as a
3376 * u32. Although dma_addr_t can be
3377 * 64-bit, the address returned by
3378 * dma_map_single() is always 32-bit
3379 * addressable (as defined by the pci/dma
3382 desc
[frag
++].addr_lo
=
3383 dma_map_single(&adapter
->pdev
->dev
,
3386 skb
->data_len
) / 2),
3388 skb
->data_len
) / 2),
3392 desc
[frag
].addr_hi
= 0;
3393 desc
[frag
].len_vlan
=
3396 /* NOTE: Here, the dma_addr_t returned from
3397 * dma_map_page() is implicitly cast as a u32.
3398 * Although dma_addr_t can be 64-bit, the address
3399 * returned by dma_map_page() is always 32-bit
3400 * addressable (as defined by the pci/dma subsystem)
3402 desc
[frag
++].addr_lo
=
3403 dma_map_page(&adapter
->pdev
->dev
,
3405 frags
[i
- 1].page_offset
,
3414 if (phydev
&& phydev
->speed
== SPEED_1000
) {
3415 if (++adapter
->tx_ring
.since_irq
== PARM_TX_NUM_BUFS_DEF
) {
3416 /* Last element & Interrupt flag */
3417 desc
[frag
- 1].flags
= 0x5;
3418 adapter
->tx_ring
.since_irq
= 0;
3419 } else { /* Last element */
3420 desc
[frag
- 1].flags
= 0x1;
3423 desc
[frag
- 1].flags
= 0x5;
3425 desc
[0].flags
|= 2; /* First element flag */
3427 tcb
->index_start
= adapter
->tx_ring
.send_idx
;
3430 spin_lock_irqsave(&adapter
->send_hw_lock
, flags
);
3432 thiscopy
= NUM_DESC_PER_RING_TX
-
3433 INDEX10(adapter
->tx_ring
.send_idx
);
3435 if (thiscopy
>= frag
) {
3439 remainder
= frag
- thiscopy
;
3442 memcpy(adapter
->tx_ring
.tx_desc_ring
+
3443 INDEX10(adapter
->tx_ring
.send_idx
), desc
,
3444 sizeof(struct tx_desc
) * thiscopy
);
3446 add_10bit(&adapter
->tx_ring
.send_idx
, thiscopy
);
3448 if (INDEX10(adapter
->tx_ring
.send_idx
) == 0 ||
3449 INDEX10(adapter
->tx_ring
.send_idx
) == NUM_DESC_PER_RING_TX
) {
3450 adapter
->tx_ring
.send_idx
&= ~ET_DMA10_MASK
;
3451 adapter
->tx_ring
.send_idx
^= ET_DMA10_WRAP
;
3455 memcpy(adapter
->tx_ring
.tx_desc_ring
,
3457 sizeof(struct tx_desc
) * remainder
);
3459 add_10bit(&adapter
->tx_ring
.send_idx
, remainder
);
3462 if (INDEX10(adapter
->tx_ring
.send_idx
) == 0) {
3463 if (adapter
->tx_ring
.send_idx
)
3464 tcb
->index
= NUM_DESC_PER_RING_TX
- 1;
3466 tcb
->index
= ET_DMA10_WRAP
|(NUM_DESC_PER_RING_TX
- 1);
3468 tcb
->index
= adapter
->tx_ring
.send_idx
- 1;
3470 spin_lock(&adapter
->tcb_send_qlock
);
3472 if (adapter
->tx_ring
.send_tail
)
3473 adapter
->tx_ring
.send_tail
->next
= tcb
;
3475 adapter
->tx_ring
.send_head
= tcb
;
3477 adapter
->tx_ring
.send_tail
= tcb
;
3479 WARN_ON(tcb
->next
!= NULL
);
3481 adapter
->tx_ring
.used
++;
3483 spin_unlock(&adapter
->tcb_send_qlock
);
3485 /* Write the new write pointer back to the device. */
3486 writel(adapter
->tx_ring
.send_idx
,
3487 &adapter
->regs
->txdma
.service_request
);
3489 /* For Gig only, we use Tx Interrupt coalescing. Enable the software
3490 * timer to wake us up if this packet isn't followed by N more.
3492 if (phydev
&& phydev
->speed
== SPEED_1000
) {
3493 writel(PARM_TX_TIME_INT_DEF
* NANO_IN_A_MICRO
,
3494 &adapter
->regs
->global
.watchdog_timer
);
3496 spin_unlock_irqrestore(&adapter
->send_hw_lock
, flags
);
3502 * send_packet - Do the work to send a packet
3503 * @skb: the packet(s) to send
3504 * @adapter: a pointer to the device's private adapter structure
3506 * Return 0 in almost all cases; non-zero value in extreme hard failure only.
3508 * Assumption: Send spinlock has been acquired
3510 static int send_packet(struct sk_buff
*skb
, struct et131x_adapter
*adapter
)
3513 struct tcb
*tcb
= NULL
;
3515 unsigned long flags
;
3517 /* All packets must have at least a MAC address and a protocol type */
3518 if (skb
->len
< ETH_HLEN
)
3521 /* Get a TCB for this packet */
3522 spin_lock_irqsave(&adapter
->tcb_ready_qlock
, flags
);
3524 tcb
= adapter
->tx_ring
.tcb_qhead
;
3527 spin_unlock_irqrestore(&adapter
->tcb_ready_qlock
, flags
);
3531 adapter
->tx_ring
.tcb_qhead
= tcb
->next
;
3533 if (adapter
->tx_ring
.tcb_qhead
== NULL
)
3534 adapter
->tx_ring
.tcb_qtail
= NULL
;
3536 spin_unlock_irqrestore(&adapter
->tcb_ready_qlock
, flags
);
3540 if (skb
->data
!= NULL
&& skb
->len
- skb
->data_len
>= 6) {
3541 shbufva
= (u16
*) skb
->data
;
3543 if ((shbufva
[0] == 0xffff) &&
3544 (shbufva
[1] == 0xffff) && (shbufva
[2] == 0xffff)) {
3545 tcb
->flags
|= fMP_DEST_BROAD
;
3546 } else if ((shbufva
[0] & 0x3) == 0x0001) {
3547 tcb
->flags
|= fMP_DEST_MULTI
;
3553 /* Call the NIC specific send handler. */
3554 status
= nic_send_packet(adapter
, tcb
);
3557 spin_lock_irqsave(&adapter
->tcb_ready_qlock
, flags
);
3559 if (adapter
->tx_ring
.tcb_qtail
)
3560 adapter
->tx_ring
.tcb_qtail
->next
= tcb
;
3562 /* Apparently ready Q is empty. */
3563 adapter
->tx_ring
.tcb_qhead
= tcb
;
3565 adapter
->tx_ring
.tcb_qtail
= tcb
;
3566 spin_unlock_irqrestore(&adapter
->tcb_ready_qlock
, flags
);
3569 WARN_ON(adapter
->tx_ring
.used
> NUM_TCB
);
3574 * et131x_send_packets - This function is called by the OS to send packets
3575 * @skb: the packet(s) to send
3576 * @netdev:device on which to TX the above packet(s)
3578 * Return 0 in almost all cases; non-zero value in extreme hard failure only
3580 int et131x_send_packets(struct sk_buff
*skb
, struct net_device
*netdev
)
3583 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
3585 /* Send these packets
3587 * NOTE: The Linux Tx entry point is only given one packet at a time
3588 * to Tx, so the PacketCount and it's array used makes no sense here
3591 /* TCB is not available */
3592 if (adapter
->tx_ring
.used
>= NUM_TCB
) {
3593 /* NOTE: If there's an error on send, no need to queue the
3594 * packet under Linux; if we just send an error up to the
3595 * netif layer, it will resend the skb to us.
3599 /* We need to see if the link is up; if it's not, make the
3600 * netif layer think we're good and drop the packet
3602 if ((adapter
->flags
& fMP_ADAPTER_FAIL_SEND_MASK
) ||
3603 !netif_carrier_ok(netdev
)) {
3604 dev_kfree_skb_any(skb
);
3607 adapter
->net_stats
.tx_dropped
++;
3609 status
= send_packet(skb
, adapter
);
3610 if (status
!= 0 && status
!= -ENOMEM
) {
3611 /* On any other error, make netif think we're
3612 * OK and drop the packet
3614 dev_kfree_skb_any(skb
);
3616 adapter
->net_stats
.tx_dropped
++;
3624 * free_send_packet - Recycle a struct tcb
3625 * @adapter: pointer to our adapter
3626 * @tcb: pointer to struct tcb
3628 * Complete the packet if necessary
3629 * Assumption - Send spinlock has been acquired
3631 static inline void free_send_packet(struct et131x_adapter
*adapter
,
3634 unsigned long flags
;
3635 struct tx_desc
*desc
= NULL
;
3636 struct net_device_stats
*stats
= &adapter
->net_stats
;
3638 if (tcb
->flags
& fMP_DEST_BROAD
)
3639 atomic_inc(&adapter
->stats
.broadcast_pkts_xmtd
);
3640 else if (tcb
->flags
& fMP_DEST_MULTI
)
3641 atomic_inc(&adapter
->stats
.multicast_pkts_xmtd
);
3643 atomic_inc(&adapter
->stats
.unicast_pkts_xmtd
);
3646 stats
->tx_bytes
+= tcb
->skb
->len
;
3648 /* Iterate through the TX descriptors on the ring
3649 * corresponding to this packet and umap the fragments
3653 desc
= (struct tx_desc
*)
3654 (adapter
->tx_ring
.tx_desc_ring
+
3655 INDEX10(tcb
->index_start
));
3657 dma_unmap_single(&adapter
->pdev
->dev
,
3659 desc
->len_vlan
, DMA_TO_DEVICE
);
3661 add_10bit(&tcb
->index_start
, 1);
3662 if (INDEX10(tcb
->index_start
) >=
3663 NUM_DESC_PER_RING_TX
) {
3664 tcb
->index_start
&= ~ET_DMA10_MASK
;
3665 tcb
->index_start
^= ET_DMA10_WRAP
;
3667 } while (desc
!= (adapter
->tx_ring
.tx_desc_ring
+
3668 INDEX10(tcb
->index
)));
3670 dev_kfree_skb_any(tcb
->skb
);
3673 memset(tcb
, 0, sizeof(struct tcb
));
3675 /* Add the TCB to the Ready Q */
3676 spin_lock_irqsave(&adapter
->tcb_ready_qlock
, flags
);
3678 adapter
->net_stats
.tx_packets
++;
3680 if (adapter
->tx_ring
.tcb_qtail
)
3681 adapter
->tx_ring
.tcb_qtail
->next
= tcb
;
3683 /* Apparently ready Q is empty. */
3684 adapter
->tx_ring
.tcb_qhead
= tcb
;
3686 adapter
->tx_ring
.tcb_qtail
= tcb
;
3688 spin_unlock_irqrestore(&adapter
->tcb_ready_qlock
, flags
);
3689 WARN_ON(adapter
->tx_ring
.used
< 0);
3693 * et131x_free_busy_send_packets - Free and complete the stopped active sends
3694 * @adapter: pointer to our adapter
3696 * Assumption - Send spinlock has been acquired
3698 void et131x_free_busy_send_packets(struct et131x_adapter
*adapter
)
3701 unsigned long flags
;
3704 /* Any packets being sent? Check the first TCB on the send list */
3705 spin_lock_irqsave(&adapter
->tcb_send_qlock
, flags
);
3707 tcb
= adapter
->tx_ring
.send_head
;
3709 while (tcb
!= NULL
&& freed
< NUM_TCB
) {
3710 struct tcb
*next
= tcb
->next
;
3712 adapter
->tx_ring
.send_head
= next
;
3715 adapter
->tx_ring
.send_tail
= NULL
;
3717 adapter
->tx_ring
.used
--;
3719 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
, flags
);
3722 free_send_packet(adapter
, tcb
);
3724 spin_lock_irqsave(&adapter
->tcb_send_qlock
, flags
);
3726 tcb
= adapter
->tx_ring
.send_head
;
3729 WARN_ON(freed
== NUM_TCB
);
3731 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
, flags
);
3733 adapter
->tx_ring
.used
= 0;
3737 * et131x_handle_send_interrupt - Interrupt handler for sending processing
3738 * @adapter: pointer to our adapter
3740 * Re-claim the send resources, complete sends and get more to send from
3741 * the send wait queue.
3743 * Assumption - Send spinlock has been acquired
3745 void et131x_handle_send_interrupt(struct et131x_adapter
*adapter
)
3747 unsigned long flags
;
3752 serviced
= readl(&adapter
->regs
->txdma
.new_service_complete
);
3753 index
= INDEX10(serviced
);
3755 /* Has the ring wrapped? Process any descriptors that do not have
3756 * the same "wrap" indicator as the current completion indicator
3758 spin_lock_irqsave(&adapter
->tcb_send_qlock
, flags
);
3760 tcb
= adapter
->tx_ring
.send_head
;
3763 ((serviced
^ tcb
->index
) & ET_DMA10_WRAP
) &&
3764 index
< INDEX10(tcb
->index
)) {
3765 adapter
->tx_ring
.used
--;
3766 adapter
->tx_ring
.send_head
= tcb
->next
;
3767 if (tcb
->next
== NULL
)
3768 adapter
->tx_ring
.send_tail
= NULL
;
3770 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
, flags
);
3771 free_send_packet(adapter
, tcb
);
3772 spin_lock_irqsave(&adapter
->tcb_send_qlock
, flags
);
3774 /* Goto the next packet */
3775 tcb
= adapter
->tx_ring
.send_head
;
3778 !((serviced
^ tcb
->index
) & ET_DMA10_WRAP
)
3779 && index
> (tcb
->index
& ET_DMA10_MASK
)) {
3780 adapter
->tx_ring
.used
--;
3781 adapter
->tx_ring
.send_head
= tcb
->next
;
3782 if (tcb
->next
== NULL
)
3783 adapter
->tx_ring
.send_tail
= NULL
;
3785 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
, flags
);
3786 free_send_packet(adapter
, tcb
);
3787 spin_lock_irqsave(&adapter
->tcb_send_qlock
, flags
);
3789 /* Goto the next packet */
3790 tcb
= adapter
->tx_ring
.send_head
;
3793 /* Wake up the queue when we hit a low-water mark */
3794 if (adapter
->tx_ring
.used
<= NUM_TCB
/ 3)
3795 netif_wake_queue(adapter
->netdev
);
3797 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
, flags
);
3800 /* ETHTOOL functions */
3802 static int et131x_get_settings(struct net_device
*netdev
,
3803 struct ethtool_cmd
*cmd
)
3805 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
3807 return phy_ethtool_gset(adapter
->phydev
, cmd
);
3810 static int et131x_set_settings(struct net_device
*netdev
,
3811 struct ethtool_cmd
*cmd
)
3813 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
3815 return phy_ethtool_sset(adapter
->phydev
, cmd
);
3818 static int et131x_get_regs_len(struct net_device
*netdev
)
3820 #define ET131X_REGS_LEN 256
3821 return ET131X_REGS_LEN
* sizeof(u32
);
3824 static void et131x_get_regs(struct net_device
*netdev
,
3825 struct ethtool_regs
*regs
, void *regs_data
)
3827 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
3828 struct address_map __iomem
*aregs
= adapter
->regs
;
3829 u32
*regs_buff
= regs_data
;
3832 memset(regs_data
, 0, et131x_get_regs_len(netdev
));
3834 regs
->version
= (1 << 24) | (adapter
->pdev
->revision
<< 16) |
3835 adapter
->pdev
->device
;
3838 et131x_mii_read(adapter
, MII_BMCR
, (u16
*)®s_buff
[num
++]);
3839 et131x_mii_read(adapter
, MII_BMSR
, (u16
*)®s_buff
[num
++]);
3840 et131x_mii_read(adapter
, MII_PHYSID1
, (u16
*)®s_buff
[num
++]);
3841 et131x_mii_read(adapter
, MII_PHYSID2
, (u16
*)®s_buff
[num
++]);
3842 et131x_mii_read(adapter
, MII_ADVERTISE
, (u16
*)®s_buff
[num
++]);
3843 et131x_mii_read(adapter
, MII_LPA
, (u16
*)®s_buff
[num
++]);
3844 et131x_mii_read(adapter
, MII_EXPANSION
, (u16
*)®s_buff
[num
++]);
3845 /* Autoneg next page transmit reg */
3846 et131x_mii_read(adapter
, 0x07, (u16
*)®s_buff
[num
++]);
3847 /* Link partner next page reg */
3848 et131x_mii_read(adapter
, 0x08, (u16
*)®s_buff
[num
++]);
3849 et131x_mii_read(adapter
, MII_CTRL1000
, (u16
*)®s_buff
[num
++]);
3850 et131x_mii_read(adapter
, MII_STAT1000
, (u16
*)®s_buff
[num
++]);
3851 et131x_mii_read(adapter
, MII_ESTATUS
, (u16
*)®s_buff
[num
++]);
3852 et131x_mii_read(adapter
, PHY_INDEX_REG
, (u16
*)®s_buff
[num
++]);
3853 et131x_mii_read(adapter
, PHY_DATA_REG
, (u16
*)®s_buff
[num
++]);
3854 et131x_mii_read(adapter
, PHY_MPHY_CONTROL_REG
,
3855 (u16
*)®s_buff
[num
++]);
3856 et131x_mii_read(adapter
, PHY_LOOPBACK_CONTROL
,
3857 (u16
*)®s_buff
[num
++]);
3858 et131x_mii_read(adapter
, PHY_LOOPBACK_CONTROL
+1,
3859 (u16
*)®s_buff
[num
++]);
3860 et131x_mii_read(adapter
, PHY_REGISTER_MGMT_CONTROL
,
3861 (u16
*)®s_buff
[num
++]);
3862 et131x_mii_read(adapter
, PHY_CONFIG
, (u16
*)®s_buff
[num
++]);
3863 et131x_mii_read(adapter
, PHY_PHY_CONTROL
, (u16
*)®s_buff
[num
++]);
3864 et131x_mii_read(adapter
, PHY_INTERRUPT_MASK
, (u16
*)®s_buff
[num
++]);
3865 et131x_mii_read(adapter
, PHY_INTERRUPT_STATUS
,
3866 (u16
*)®s_buff
[num
++]);
3867 et131x_mii_read(adapter
, PHY_PHY_STATUS
, (u16
*)®s_buff
[num
++]);
3868 et131x_mii_read(adapter
, PHY_LED_1
, (u16
*)®s_buff
[num
++]);
3869 et131x_mii_read(adapter
, PHY_LED_2
, (u16
*)®s_buff
[num
++]);
3872 regs_buff
[num
++] = readl(&aregs
->global
.txq_start_addr
);
3873 regs_buff
[num
++] = readl(&aregs
->global
.txq_end_addr
);
3874 regs_buff
[num
++] = readl(&aregs
->global
.rxq_start_addr
);
3875 regs_buff
[num
++] = readl(&aregs
->global
.rxq_end_addr
);
3876 regs_buff
[num
++] = readl(&aregs
->global
.pm_csr
);
3877 regs_buff
[num
++] = adapter
->stats
.interrupt_status
;
3878 regs_buff
[num
++] = readl(&aregs
->global
.int_mask
);
3879 regs_buff
[num
++] = readl(&aregs
->global
.int_alias_clr_en
);
3880 regs_buff
[num
++] = readl(&aregs
->global
.int_status_alias
);
3881 regs_buff
[num
++] = readl(&aregs
->global
.sw_reset
);
3882 regs_buff
[num
++] = readl(&aregs
->global
.slv_timer
);
3883 regs_buff
[num
++] = readl(&aregs
->global
.msi_config
);
3884 regs_buff
[num
++] = readl(&aregs
->global
.loopback
);
3885 regs_buff
[num
++] = readl(&aregs
->global
.watchdog_timer
);
3888 regs_buff
[num
++] = readl(&aregs
->txdma
.csr
);
3889 regs_buff
[num
++] = readl(&aregs
->txdma
.pr_base_hi
);
3890 regs_buff
[num
++] = readl(&aregs
->txdma
.pr_base_lo
);
3891 regs_buff
[num
++] = readl(&aregs
->txdma
.pr_num_des
);
3892 regs_buff
[num
++] = readl(&aregs
->txdma
.txq_wr_addr
);
3893 regs_buff
[num
++] = readl(&aregs
->txdma
.txq_wr_addr_ext
);
3894 regs_buff
[num
++] = readl(&aregs
->txdma
.txq_rd_addr
);
3895 regs_buff
[num
++] = readl(&aregs
->txdma
.dma_wb_base_hi
);
3896 regs_buff
[num
++] = readl(&aregs
->txdma
.dma_wb_base_lo
);
3897 regs_buff
[num
++] = readl(&aregs
->txdma
.service_request
);
3898 regs_buff
[num
++] = readl(&aregs
->txdma
.service_complete
);
3899 regs_buff
[num
++] = readl(&aregs
->txdma
.cache_rd_index
);
3900 regs_buff
[num
++] = readl(&aregs
->txdma
.cache_wr_index
);
3901 regs_buff
[num
++] = readl(&aregs
->txdma
.tx_dma_error
);
3902 regs_buff
[num
++] = readl(&aregs
->txdma
.desc_abort_cnt
);
3903 regs_buff
[num
++] = readl(&aregs
->txdma
.payload_abort_cnt
);
3904 regs_buff
[num
++] = readl(&aregs
->txdma
.writeback_abort_cnt
);
3905 regs_buff
[num
++] = readl(&aregs
->txdma
.desc_timeout_cnt
);
3906 regs_buff
[num
++] = readl(&aregs
->txdma
.payload_timeout_cnt
);
3907 regs_buff
[num
++] = readl(&aregs
->txdma
.writeback_timeout_cnt
);
3908 regs_buff
[num
++] = readl(&aregs
->txdma
.desc_error_cnt
);
3909 regs_buff
[num
++] = readl(&aregs
->txdma
.payload_error_cnt
);
3910 regs_buff
[num
++] = readl(&aregs
->txdma
.writeback_error_cnt
);
3911 regs_buff
[num
++] = readl(&aregs
->txdma
.dropped_tlp_cnt
);
3912 regs_buff
[num
++] = readl(&aregs
->txdma
.new_service_complete
);
3913 regs_buff
[num
++] = readl(&aregs
->txdma
.ethernet_packet_cnt
);
3916 regs_buff
[num
++] = readl(&aregs
->rxdma
.csr
);
3917 regs_buff
[num
++] = readl(&aregs
->rxdma
.dma_wb_base_hi
);
3918 regs_buff
[num
++] = readl(&aregs
->rxdma
.dma_wb_base_lo
);
3919 regs_buff
[num
++] = readl(&aregs
->rxdma
.num_pkt_done
);
3920 regs_buff
[num
++] = readl(&aregs
->rxdma
.max_pkt_time
);
3921 regs_buff
[num
++] = readl(&aregs
->rxdma
.rxq_rd_addr
);
3922 regs_buff
[num
++] = readl(&aregs
->rxdma
.rxq_rd_addr_ext
);
3923 regs_buff
[num
++] = readl(&aregs
->rxdma
.rxq_wr_addr
);
3924 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_base_hi
);
3925 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_base_lo
);
3926 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_num_des
);
3927 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_avail_offset
);
3928 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_full_offset
);
3929 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_access_index
);
3930 regs_buff
[num
++] = readl(&aregs
->rxdma
.psr_min_des
);
3931 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_base_lo
);
3932 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_base_hi
);
3933 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_num_des
);
3934 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_avail_offset
);
3935 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_full_offset
);
3936 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_rd_index
);
3937 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr0_min_des
);
3938 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_base_lo
);
3939 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_base_hi
);
3940 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_num_des
);
3941 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_avail_offset
);
3942 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_full_offset
);
3943 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_rd_index
);
3944 regs_buff
[num
++] = readl(&aregs
->rxdma
.fbr1_min_des
);
3947 #define ET131X_DRVINFO_LEN 32 /* value from ethtool.h */
3948 static void et131x_get_drvinfo(struct net_device
*netdev
,
3949 struct ethtool_drvinfo
*info
)
3951 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
3953 strncpy(info
->driver
, DRIVER_NAME
, ET131X_DRVINFO_LEN
);
3954 strncpy(info
->version
, DRIVER_VERSION
, ET131X_DRVINFO_LEN
);
3955 strncpy(info
->bus_info
, pci_name(adapter
->pdev
), ET131X_DRVINFO_LEN
);
3958 static struct ethtool_ops et131x_ethtool_ops
= {
3959 .get_settings
= et131x_get_settings
,
3960 .set_settings
= et131x_set_settings
,
3961 .get_drvinfo
= et131x_get_drvinfo
,
3962 .get_regs_len
= et131x_get_regs_len
,
3963 .get_regs
= et131x_get_regs
,
3964 .get_link
= ethtool_op_get_link
,
3967 void et131x_set_ethtool_ops(struct net_device
*netdev
)
3969 SET_ETHTOOL_OPS(netdev
, &et131x_ethtool_ops
);
3975 * et131x_hwaddr_init - set up the MAC Address on the ET1310
3976 * @adapter: pointer to our private adapter structure
3978 void et131x_hwaddr_init(struct et131x_adapter
*adapter
)
3980 /* If have our default mac from init and no mac address from
3981 * EEPROM then we need to generate the last octet and set it on the
3984 if (adapter
->rom_addr
[0] == 0x00 &&
3985 adapter
->rom_addr
[1] == 0x00 &&
3986 adapter
->rom_addr
[2] == 0x00 &&
3987 adapter
->rom_addr
[3] == 0x00 &&
3988 adapter
->rom_addr
[4] == 0x00 &&
3989 adapter
->rom_addr
[5] == 0x00) {
3991 * We need to randomly generate the last octet so we
3992 * decrease our chances of setting the mac address to
3993 * same as another one of our cards in the system
3995 get_random_bytes(&adapter
->addr
[5], 1);
3997 * We have the default value in the register we are
3998 * working with so we need to copy the current
3999 * address into the permanent address
4001 memcpy(adapter
->rom_addr
,
4002 adapter
->addr
, ETH_ALEN
);
4004 /* We do not have an override address, so set the
4005 * current address to the permanent address and add
4008 memcpy(adapter
->addr
,
4009 adapter
->rom_addr
, ETH_ALEN
);
4014 * et131x_pci_init - initial PCI setup
4015 * @adapter: pointer to our private adapter structure
4016 * @pdev: our PCI device
4018 * Perform the initial setup of PCI registers and if possible initialise
4019 * the MAC address. At this point the I/O registers have yet to be mapped
4021 static int et131x_pci_init(struct et131x_adapter
*adapter
,
4022 struct pci_dev
*pdev
)
4028 if (et131x_init_eeprom(adapter
) < 0)
4031 /* Let's set up the PORT LOGIC Register. First we need to know what
4032 * the max_payload_size is
4034 if (pci_read_config_byte(pdev
, ET1310_PCI_MAX_PYLD
, &max_payload
)) {
4036 "Could not read PCI config space for Max Payload Size\n");
4040 /* Program the Ack/Nak latency and replay timers */
4041 max_payload
&= 0x07; /* Only the lower 3 bits are valid */
4043 if (max_payload
< 2) {
4044 static const u16 acknak
[2] = { 0x76, 0xD0 };
4045 static const u16 replay
[2] = { 0x1E0, 0x2ED };
4047 if (pci_write_config_word(pdev
, ET1310_PCI_ACK_NACK
,
4048 acknak
[max_payload
])) {
4050 "Could not write PCI config space for ACK/NAK\n");
4053 if (pci_write_config_word(pdev
, ET1310_PCI_REPLAY
,
4054 replay
[max_payload
])) {
4056 "Could not write PCI config space for Replay Timer\n");
4061 /* l0s and l1 latency timers. We are using default values.
4062 * Representing 001 for L0s and 010 for L1
4064 if (pci_write_config_byte(pdev
, ET1310_PCI_L0L1LATENCY
, 0x11)) {
4066 "Could not write PCI config space for Latency Timers\n");
4070 /* Change the max read size to 2k */
4071 if (pci_read_config_byte(pdev
, 0x51, &read_size_reg
)) {
4073 "Could not read PCI config space for Max read size\n");
4077 read_size_reg
&= 0x8f;
4078 read_size_reg
|= 0x40;
4080 if (pci_write_config_byte(pdev
, 0x51, read_size_reg
)) {
4082 "Could not write PCI config space for Max read size\n");
4086 /* Get MAC address from config space if an eeprom exists, otherwise
4087 * the MAC address there will not be valid
4089 if (!adapter
->has_eeprom
) {
4090 et131x_hwaddr_init(adapter
);
4094 for (i
= 0; i
< ETH_ALEN
; i
++) {
4095 if (pci_read_config_byte(pdev
, ET1310_PCI_MAC_ADDRESS
+ i
,
4096 adapter
->rom_addr
+ i
)) {
4097 dev_err(&pdev
->dev
, "Could not read PCI config space for MAC address\n");
4101 memcpy(adapter
->addr
, adapter
->rom_addr
, ETH_ALEN
);
4106 * et131x_error_timer_handler
4107 * @data: timer-specific variable; here a pointer to our adapter structure
4109 * The routine called when the error timer expires, to track the number of
4112 void et131x_error_timer_handler(unsigned long data
)
4114 struct et131x_adapter
*adapter
= (struct et131x_adapter
*) data
;
4115 struct phy_device
*phydev
= adapter
->phydev
;
4117 if (et1310_in_phy_coma(adapter
)) {
4118 /* Bring the device immediately out of coma, to
4119 * prevent it from sleeping indefinitely, this
4120 * mechanism could be improved! */
4121 et1310_disable_phy_coma(adapter
);
4122 adapter
->boot_coma
= 20;
4124 et1310_update_macstat_host_counters(adapter
);
4127 if (!phydev
->link
&& adapter
->boot_coma
< 11)
4128 adapter
->boot_coma
++;
4130 if (adapter
->boot_coma
== 10) {
4131 if (!phydev
->link
) {
4132 if (!et1310_in_phy_coma(adapter
)) {
4133 /* NOTE - This was originally a 'sync with
4134 * interrupt'. How to do that under Linux?
4136 et131x_enable_interrupts(adapter
);
4137 et1310_enable_phy_coma(adapter
);
4142 /* This is a periodic timer, so reschedule */
4143 mod_timer(&adapter
->error_timer
, jiffies
+
4144 TX_ERROR_PERIOD
* HZ
/ 1000);
4148 * et131x_adapter_memory_alloc
4149 * @adapter: pointer to our private adapter structure
4151 * Returns 0 on success, errno on failure (as defined in errno.h).
4153 * Allocate all the memory blocks for send, receive and others.
4155 int et131x_adapter_memory_alloc(struct et131x_adapter
*adapter
)
4159 /* Allocate memory for the Tx Ring */
4160 status
= et131x_tx_dma_memory_alloc(adapter
);
4162 dev_err(&adapter
->pdev
->dev
,
4163 "et131x_tx_dma_memory_alloc FAILED\n");
4166 /* Receive buffer memory allocation */
4167 status
= et131x_rx_dma_memory_alloc(adapter
);
4169 dev_err(&adapter
->pdev
->dev
,
4170 "et131x_rx_dma_memory_alloc FAILED\n");
4171 et131x_tx_dma_memory_free(adapter
);
4175 /* Init receive data structures */
4176 status
= et131x_init_recv(adapter
);
4178 dev_err(&adapter
->pdev
->dev
,
4179 "et131x_init_recv FAILED\n");
4180 et131x_tx_dma_memory_free(adapter
);
4181 et131x_rx_dma_memory_free(adapter
);
4187 * et131x_adapter_memory_free - Free all memory allocated for use by Tx & Rx
4188 * @adapter: pointer to our private adapter structure
4190 void et131x_adapter_memory_free(struct et131x_adapter
*adapter
)
4192 /* Free DMA memory */
4193 et131x_tx_dma_memory_free(adapter
);
4194 et131x_rx_dma_memory_free(adapter
);
4197 static void et131x_adjust_link(struct net_device
*netdev
)
4199 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4200 struct phy_device
*phydev
= adapter
->phydev
;
4202 if (netif_carrier_ok(netdev
)) {
4203 adapter
->boot_coma
= 20;
4205 if (phydev
&& phydev
->speed
== SPEED_10
) {
4207 * NOTE - Is there a way to query this without
4209 * && TRU_QueryCoreType(adapter->hTruePhy, 0)==
4210 * EMI_TRUEPHY_A13O) {
4214 et131x_mii_read(adapter
, PHY_MPHY_CONTROL_REG
,
4216 et131x_mii_write(adapter
, PHY_MPHY_CONTROL_REG
,
4218 et131x_mii_write(adapter
, PHY_INDEX_REG
,
4219 register18
| 0x8402);
4220 et131x_mii_write(adapter
, PHY_DATA_REG
,
4222 et131x_mii_write(adapter
, PHY_MPHY_CONTROL_REG
,
4226 et1310_config_flow_control(adapter
);
4228 if (phydev
&& phydev
->speed
== SPEED_1000
&&
4229 adapter
->registry_jumbo_packet
> 2048) {
4232 et131x_mii_read(adapter
, PHY_CONFIG
, ®
);
4233 reg
&= ~ET_PHY_CONFIG_TX_FIFO_DEPTH
;
4234 reg
|= ET_PHY_CONFIG_FIFO_DEPTH_32
;
4235 et131x_mii_write(adapter
, PHY_CONFIG
, reg
);
4238 et131x_set_rx_dma_timer(adapter
);
4239 et1310_config_mac_regs2(adapter
);
4242 if (phydev
&& phydev
->link
!= adapter
->link
) {
4244 * Check to see if we are in coma mode and if
4245 * so, disable it because we will not be able
4246 * to read PHY values until we are out.
4248 if (et1310_in_phy_coma(adapter
))
4249 et1310_disable_phy_coma(adapter
);
4252 adapter
->boot_coma
= 20;
4254 dev_warn(&adapter
->pdev
->dev
,
4255 "Link down - cable problem ?\n");
4256 adapter
->boot_coma
= 0;
4258 if (phydev
->speed
== SPEED_10
) {
4259 /* NOTE - Is there a way to query this without
4261 * && TRU_QueryCoreType(adapter->hTruePhy, 0) ==
4266 et131x_mii_read(adapter
, PHY_MPHY_CONTROL_REG
,
4268 et131x_mii_write(adapter
, PHY_MPHY_CONTROL_REG
,
4270 et131x_mii_write(adapter
, PHY_INDEX_REG
,
4271 register18
| 0x8402);
4272 et131x_mii_write(adapter
, PHY_DATA_REG
,
4274 et131x_mii_write(adapter
, PHY_MPHY_CONTROL_REG
,
4278 /* Free the packets being actively sent & stopped */
4279 et131x_free_busy_send_packets(adapter
);
4281 /* Re-initialize the send structures */
4282 et131x_init_send(adapter
);
4285 * Bring the device back to the state it was during
4286 * init prior to autonegotiation being complete. This
4287 * way, when we get the auto-neg complete interrupt,
4288 * we can complete init by calling config_mac_regs2.
4290 et131x_soft_reset(adapter
);
4292 /* Setup ET1310 as per the documentation */
4293 et131x_adapter_setup(adapter
);
4295 /* perform reset of tx/rx */
4296 et131x_disable_txrx(netdev
);
4297 et131x_enable_txrx(netdev
);
4300 adapter
->link
= phydev
->link
;
4302 phy_print_status(phydev
);
4306 static int et131x_mii_probe(struct net_device
*netdev
)
4308 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4309 struct phy_device
*phydev
= NULL
;
4311 phydev
= phy_find_first(adapter
->mii_bus
);
4313 dev_err(&adapter
->pdev
->dev
, "no PHY found\n");
4317 phydev
= phy_connect(netdev
, dev_name(&phydev
->dev
),
4318 &et131x_adjust_link
, 0, PHY_INTERFACE_MODE_MII
);
4320 if (IS_ERR(phydev
)) {
4321 dev_err(&adapter
->pdev
->dev
, "Could not attach to PHY\n");
4322 return PTR_ERR(phydev
);
4325 phydev
->supported
&= (SUPPORTED_10baseT_Half
4326 | SUPPORTED_10baseT_Full
4327 | SUPPORTED_100baseT_Half
4328 | SUPPORTED_100baseT_Full
4333 if (adapter
->pdev
->device
!= ET131X_PCI_DEVICE_ID_FAST
)
4334 phydev
->supported
|= SUPPORTED_1000baseT_Full
;
4336 phydev
->advertising
= phydev
->supported
;
4337 adapter
->phydev
= phydev
;
4339 dev_info(&adapter
->pdev
->dev
, "attached PHY driver [%s] "
4340 "(mii_bus:phy_addr=%s)\n",
4341 phydev
->drv
->name
, dev_name(&phydev
->dev
));
4347 * et131x_adapter_init
4348 * @adapter: pointer to the private adapter struct
4349 * @pdev: pointer to the PCI device
4351 * Initialize the data structures for the et131x_adapter object and link
4352 * them together with the platform provided device structures.
4354 static struct et131x_adapter
*et131x_adapter_init(struct net_device
*netdev
,
4355 struct pci_dev
*pdev
)
4357 static const u8 default_mac
[] = { 0x00, 0x05, 0x3d, 0x00, 0x02, 0x00 };
4359 struct et131x_adapter
*adapter
;
4361 /* Allocate private adapter struct and copy in relevant information */
4362 adapter
= netdev_priv(netdev
);
4363 adapter
->pdev
= pci_dev_get(pdev
);
4364 adapter
->netdev
= netdev
;
4366 /* Do the same for the netdev struct */
4367 netdev
->irq
= pdev
->irq
;
4368 netdev
->base_addr
= pci_resource_start(pdev
, 0);
4370 /* Initialize spinlocks here */
4371 spin_lock_init(&adapter
->lock
);
4372 spin_lock_init(&adapter
->tcb_send_qlock
);
4373 spin_lock_init(&adapter
->tcb_ready_qlock
);
4374 spin_lock_init(&adapter
->send_hw_lock
);
4375 spin_lock_init(&adapter
->rcv_lock
);
4376 spin_lock_init(&adapter
->rcv_pend_lock
);
4377 spin_lock_init(&adapter
->fbr_lock
);
4378 spin_lock_init(&adapter
->phy_lock
);
4380 adapter
->registry_jumbo_packet
= 1514; /* 1514-9216 */
4382 /* Set the MAC address to a default */
4383 memcpy(adapter
->addr
, default_mac
, ETH_ALEN
);
4390 * @pdev: a pointer to the device's pci_dev structure
4392 * Registered in the pci_driver structure, this function is called when the
4393 * PCI subsystem detects that a PCI device which matches the information
4394 * contained in the pci_device_id table has been removed.
4396 static void __devexit
et131x_pci_remove(struct pci_dev
*pdev
)
4398 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4399 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4401 unregister_netdev(netdev
);
4402 mdiobus_unregister(adapter
->mii_bus
);
4403 kfree(adapter
->mii_bus
->irq
);
4404 mdiobus_free(adapter
->mii_bus
);
4406 et131x_adapter_memory_free(adapter
);
4407 iounmap(adapter
->regs
);
4410 free_netdev(netdev
);
4411 pci_release_regions(pdev
);
4412 pci_disable_device(pdev
);
4416 * et131x_up - Bring up a device for use.
4417 * @netdev: device to be opened
4419 void et131x_up(struct net_device
*netdev
)
4421 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4423 et131x_enable_txrx(netdev
);
4424 phy_start(adapter
->phydev
);
4428 * et131x_down - Bring down the device
4429 * @netdev: device to be broght down
4431 void et131x_down(struct net_device
*netdev
)
4433 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4435 /* Save the timestamp for the TX watchdog, prevent a timeout */
4436 netdev
->trans_start
= jiffies
;
4438 phy_stop(adapter
->phydev
);
4439 et131x_disable_txrx(netdev
);
4442 #ifdef CONFIG_PM_SLEEP
4443 static int et131x_suspend(struct device
*dev
)
4445 struct pci_dev
*pdev
= to_pci_dev(dev
);
4446 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4448 if (netif_running(netdev
)) {
4449 netif_device_detach(netdev
);
4450 et131x_down(netdev
);
4451 pci_save_state(pdev
);
4457 static int et131x_resume(struct device
*dev
)
4459 struct pci_dev
*pdev
= to_pci_dev(dev
);
4460 struct net_device
*netdev
= pci_get_drvdata(pdev
);
4462 if (netif_running(netdev
)) {
4463 pci_restore_state(pdev
);
4465 netif_device_attach(netdev
);
4474 * et131x_isr - The Interrupt Service Routine for the driver.
4475 * @irq: the IRQ on which the interrupt was received.
4476 * @dev_id: device-specific info (here a pointer to a net_device struct)
4478 * Returns a value indicating if the interrupt was handled.
4480 irqreturn_t
et131x_isr(int irq
, void *dev_id
)
4482 bool handled
= true;
4483 struct net_device
*netdev
= (struct net_device
*)dev_id
;
4484 struct et131x_adapter
*adapter
= NULL
;
4487 if (!netif_device_present(netdev
)) {
4492 adapter
= netdev_priv(netdev
);
4494 /* If the adapter is in low power state, then it should not
4495 * recognize any interrupt
4498 /* Disable Device Interrupts */
4499 et131x_disable_interrupts(adapter
);
4501 /* Get a copy of the value in the interrupt status register
4502 * so we can process the interrupting section
4504 status
= readl(&adapter
->regs
->global
.int_status
);
4506 if (adapter
->flowcontrol
== FLOW_TXONLY
||
4507 adapter
->flowcontrol
== FLOW_BOTH
) {
4508 status
&= ~INT_MASK_ENABLE
;
4510 status
&= ~INT_MASK_ENABLE_NO_FLOW
;
4513 /* Make sure this is our interrupt */
4516 et131x_enable_interrupts(adapter
);
4520 /* This is our interrupt, so process accordingly */
4522 if (status
& ET_INTR_WATCHDOG
) {
4523 struct tcb
*tcb
= adapter
->tx_ring
.send_head
;
4526 if (++tcb
->stale
> 1)
4527 status
|= ET_INTR_TXDMA_ISR
;
4529 if (adapter
->rx_ring
.unfinished_receives
)
4530 status
|= ET_INTR_RXDMA_XFR_DONE
;
4531 else if (tcb
== NULL
)
4532 writel(0, &adapter
->regs
->global
.watchdog_timer
);
4534 status
&= ~ET_INTR_WATCHDOG
;
4538 /* This interrupt has in some way been "handled" by
4539 * the ISR. Either it was a spurious Rx interrupt, or
4540 * it was a Tx interrupt that has been filtered by
4543 et131x_enable_interrupts(adapter
);
4547 /* We need to save the interrupt status value for use in our
4548 * DPC. We will clear the software copy of that in that
4551 adapter
->stats
.interrupt_status
= status
;
4553 /* Schedule the ISR handler as a bottom-half task in the
4554 * kernel's tq_immediate queue, and mark the queue for
4557 schedule_work(&adapter
->task
);
4559 return IRQ_RETVAL(handled
);
4563 * et131x_isr_handler - The ISR handler
4564 * @p_adapter, a pointer to the device's private adapter structure
4566 * scheduled to run in a deferred context by the ISR. This is where the ISR's
4567 * work actually gets done.
4569 void et131x_isr_handler(struct work_struct
*work
)
4571 struct et131x_adapter
*adapter
=
4572 container_of(work
, struct et131x_adapter
, task
);
4573 u32 status
= adapter
->stats
.interrupt_status
;
4574 struct address_map __iomem
*iomem
= adapter
->regs
;
4577 * These first two are by far the most common. Once handled, we clear
4578 * their two bits in the status word. If the word is now zero, we
4581 /* Handle all the completed Transmit interrupts */
4582 if (status
& ET_INTR_TXDMA_ISR
)
4583 et131x_handle_send_interrupt(adapter
);
4585 /* Handle all the completed Receives interrupts */
4586 if (status
& ET_INTR_RXDMA_XFR_DONE
)
4587 et131x_handle_recv_interrupt(adapter
);
4589 status
&= 0xffffffd7;
4592 /* Handle the TXDMA Error interrupt */
4593 if (status
& ET_INTR_TXDMA_ERR
) {
4596 /* Following read also clears the register (COR) */
4597 txdma_err
= readl(&iomem
->txdma
.tx_dma_error
);
4599 dev_warn(&adapter
->pdev
->dev
,
4600 "TXDMA_ERR interrupt, error = %d\n",
4604 /* Handle Free Buffer Ring 0 and 1 Low interrupt */
4606 (ET_INTR_RXDMA_FB_R0_LOW
| ET_INTR_RXDMA_FB_R1_LOW
)) {
4608 * This indicates the number of unused buffers in
4609 * RXDMA free buffer ring 0 is <= the limit you
4610 * programmed. Free buffer resources need to be
4611 * returned. Free buffers are consumed as packets
4612 * are passed from the network to the host. The host
4613 * becomes aware of the packets from the contents of
4614 * the packet status ring. This ring is queried when
4615 * the packet done interrupt occurs. Packets are then
4616 * passed to the OS. When the OS is done with the
4617 * packets the resources can be returned to the
4618 * ET1310 for re-use. This interrupt is one method of
4619 * returning resources.
4622 /* If the user has flow control on, then we will
4623 * send a pause packet, otherwise just exit
4625 if (adapter
->flowcontrol
== FLOW_TXONLY
||
4626 adapter
->flowcontrol
== FLOW_BOTH
) {
4629 /* Tell the device to send a pause packet via
4630 * the back pressure register (bp req and
4633 pm_csr
= readl(&iomem
->global
.pm_csr
);
4634 if (!et1310_in_phy_coma(adapter
))
4635 writel(3, &iomem
->txmac
.bp_ctrl
);
4639 /* Handle Packet Status Ring Low Interrupt */
4640 if (status
& ET_INTR_RXDMA_STAT_LOW
) {
4643 * Same idea as with the two Free Buffer Rings.
4644 * Packets going from the network to the host each
4645 * consume a free buffer resource and a packet status
4646 * resource. These resoures are passed to the OS.
4647 * When the OS is done with the resources, they need
4648 * to be returned to the ET1310. This is one method
4649 * of returning the resources.
4653 /* Handle RXDMA Error Interrupt */
4654 if (status
& ET_INTR_RXDMA_ERR
) {
4656 * The rxdma_error interrupt is sent when a time-out
4657 * on a request issued by the JAGCore has occurred or
4658 * a completion is returned with an un-successful
4659 * status. In both cases the request is considered
4660 * complete. The JAGCore will automatically re-try the
4661 * request in question. Normally information on events
4662 * like these are sent to the host using the "Advanced
4663 * Error Reporting" capability. This interrupt is
4664 * another way of getting similar information. The
4665 * only thing required is to clear the interrupt by
4666 * reading the ISR in the global resources. The
4667 * JAGCore will do a re-try on the request. Normally
4668 * you should never see this interrupt. If you start
4669 * to see this interrupt occurring frequently then
4670 * something bad has occurred. A reset might be the
4675 dev_warn(&adapter
->pdev
->dev
,
4676 "RxDMA_ERR interrupt, error %x\n",
4677 readl(&iomem
->txmac
.tx_test
));
4680 /* Handle the Wake on LAN Event */
4681 if (status
& ET_INTR_WOL
) {
4683 * This is a secondary interrupt for wake on LAN.
4684 * The driver should never see this, if it does,
4685 * something serious is wrong. We will TRAP the
4686 * message when we are in DBG mode, otherwise we
4689 dev_err(&adapter
->pdev
->dev
, "WAKE_ON_LAN interrupt\n");
4692 /* Let's move on to the TxMac */
4693 if (status
& ET_INTR_TXMAC
) {
4694 u32 err
= readl(&iomem
->txmac
.err
);
4697 * When any of the errors occur and TXMAC generates
4698 * an interrupt to report these errors, it usually
4699 * means that TXMAC has detected an error in the data
4700 * stream retrieved from the on-chip Tx Q. All of
4701 * these errors are catastrophic and TXMAC won't be
4702 * able to recover data when these errors occur. In
4703 * a nutshell, the whole Tx path will have to be reset
4704 * and re-configured afterwards.
4706 dev_warn(&adapter
->pdev
->dev
,
4707 "TXMAC interrupt, error 0x%08x\n",
4710 /* If we are debugging, we want to see this error,
4711 * otherwise we just want the device to be reset and
4716 /* Handle RXMAC Interrupt */
4717 if (status
& ET_INTR_RXMAC
) {
4719 * These interrupts are catastrophic to the device,
4720 * what we need to do is disable the interrupts and
4721 * set the flag to cause us to reset so we can solve
4724 /* MP_SET_FLAG( adapter,
4725 fMP_ADAPTER_HARDWARE_ERROR); */
4727 dev_warn(&adapter
->pdev
->dev
,
4728 "RXMAC interrupt, error 0x%08x. Requesting reset\n",
4729 readl(&iomem
->rxmac
.err_reg
));
4731 dev_warn(&adapter
->pdev
->dev
,
4732 "Enable 0x%08x, Diag 0x%08x\n",
4733 readl(&iomem
->rxmac
.ctrl
),
4734 readl(&iomem
->rxmac
.rxq_diag
));
4737 * If we are debugging, we want to see this error,
4738 * otherwise we just want the device to be reset and
4743 /* Handle MAC_STAT Interrupt */
4744 if (status
& ET_INTR_MAC_STAT
) {
4746 * This means at least one of the un-masked counters
4747 * in the MAC_STAT block has rolled over. Use this
4748 * to maintain the top, software managed bits of the
4751 et1310_handle_macstat_interrupt(adapter
);
4754 /* Handle SLV Timeout Interrupt */
4755 if (status
& ET_INTR_SLV_TIMEOUT
) {
4757 * This means a timeout has occurred on a read or
4758 * write request to one of the JAGCore registers. The
4759 * Global Resources block has terminated the request
4760 * and on a read request, returned a "fake" value.
4761 * The most likely reasons are: Bad Address or the
4762 * addressed module is in a power-down state and
4767 et131x_enable_interrupts(adapter
);
4770 /* NETDEV functions */
4773 * et131x_stats - Return the current device statistics.
4774 * @netdev: device whose stats are being queried
4776 * Returns 0 on success, errno on failure (as defined in errno.h)
4778 static struct net_device_stats
*et131x_stats(struct net_device
*netdev
)
4780 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4781 struct net_device_stats
*stats
= &adapter
->net_stats
;
4782 struct ce_stats
*devstat
= &adapter
->stats
;
4784 stats
->rx_errors
= devstat
->rx_length_errs
+
4785 devstat
->rx_align_errs
+
4786 devstat
->rx_crc_errs
+
4787 devstat
->rx_code_violations
+
4788 devstat
->rx_other_errs
;
4789 stats
->tx_errors
= devstat
->tx_max_pkt_errs
;
4790 stats
->multicast
= devstat
->multicast_pkts_rcvd
;
4791 stats
->collisions
= devstat
->tx_collisions
;
4793 stats
->rx_length_errors
= devstat
->rx_length_errs
;
4794 stats
->rx_over_errors
= devstat
->rx_overflows
;
4795 stats
->rx_crc_errors
= devstat
->rx_crc_errs
;
4797 /* NOTE: These stats don't have corresponding values in CE_STATS,
4798 * so we're going to have to update these directly from within the
4801 /* stats->rx_bytes = 20; devstat->; */
4802 /* stats->tx_bytes = 20; devstat->; */
4803 /* stats->rx_dropped = devstat->; */
4804 /* stats->tx_dropped = devstat->; */
4806 /* NOTE: Not used, can't find analogous statistics */
4807 /* stats->rx_frame_errors = devstat->; */
4808 /* stats->rx_fifo_errors = devstat->; */
4809 /* stats->rx_missed_errors = devstat->; */
4811 /* stats->tx_aborted_errors = devstat->; */
4812 /* stats->tx_carrier_errors = devstat->; */
4813 /* stats->tx_fifo_errors = devstat->; */
4814 /* stats->tx_heartbeat_errors = devstat->; */
4815 /* stats->tx_window_errors = devstat->; */
4820 * et131x_open - Open the device for use.
4821 * @netdev: device to be opened
4823 * Returns 0 on success, errno on failure (as defined in errno.h)
4825 int et131x_open(struct net_device
*netdev
)
4828 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4830 /* Start the timer to track NIC errors */
4831 init_timer(&adapter
->error_timer
);
4832 adapter
->error_timer
.expires
= jiffies
+ TX_ERROR_PERIOD
* HZ
/ 1000;
4833 adapter
->error_timer
.function
= et131x_error_timer_handler
;
4834 adapter
->error_timer
.data
= (unsigned long)adapter
;
4835 add_timer(&adapter
->error_timer
);
4837 /* Register our IRQ */
4838 result
= request_irq(netdev
->irq
, et131x_isr
, IRQF_SHARED
,
4839 netdev
->name
, netdev
);
4841 dev_err(&adapter
->pdev
->dev
, "could not register IRQ %d\n",
4846 adapter
->flags
|= fMP_ADAPTER_INTERRUPT_IN_USE
;
4854 * et131x_close - Close the device
4855 * @netdev: device to be closed
4857 * Returns 0 on success, errno on failure (as defined in errno.h)
4859 int et131x_close(struct net_device
*netdev
)
4861 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4863 et131x_down(netdev
);
4865 adapter
->flags
&= ~fMP_ADAPTER_INTERRUPT_IN_USE
;
4866 free_irq(netdev
->irq
, netdev
);
4868 /* Stop the error timer */
4869 return del_timer_sync(&adapter
->error_timer
);
4873 * et131x_ioctl - The I/O Control handler for the driver
4874 * @netdev: device on which the control request is being made
4875 * @reqbuf: a pointer to the IOCTL request buffer
4876 * @cmd: the IOCTL command code
4878 * Returns 0 on success, errno on failure (as defined in errno.h)
4880 static int et131x_ioctl(struct net_device
*netdev
, struct ifreq
*reqbuf
, int cmd
)
4882 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4884 if (!adapter
->phydev
)
4887 return phy_mii_ioctl(adapter
->phydev
, reqbuf
, cmd
);
4891 * et131x_set_packet_filter - Configures the Rx Packet filtering on the device
4892 * @adapter: pointer to our private adapter structure
4894 * FIXME: lot of dups with MAC code
4896 * Returns 0 on success, errno on failure
4898 static int et131x_set_packet_filter(struct et131x_adapter
*adapter
)
4901 uint32_t filter
= adapter
->packet_filter
;
4905 ctrl
= readl(&adapter
->regs
->rxmac
.ctrl
);
4906 pf_ctrl
= readl(&adapter
->regs
->rxmac
.pf_ctrl
);
4908 /* Default to disabled packet filtering. Enable it in the individual
4909 * case statements that require the device to filter something
4913 /* Set us to be in promiscuous mode so we receive everything, this
4914 * is also true when we get a packet filter of 0
4916 if ((filter
& ET131X_PACKET_TYPE_PROMISCUOUS
) || filter
== 0)
4917 pf_ctrl
&= ~7; /* Clear filter bits */
4920 * Set us up with Multicast packet filtering. Three cases are
4921 * possible - (1) we have a multi-cast list, (2) we receive ALL
4922 * multicast entries or (3) we receive none.
4924 if (filter
& ET131X_PACKET_TYPE_ALL_MULTICAST
)
4925 pf_ctrl
&= ~2; /* Multicast filter bit */
4927 et1310_setup_device_for_multicast(adapter
);
4932 /* Set us up with Unicast packet filtering */
4933 if (filter
& ET131X_PACKET_TYPE_DIRECTED
) {
4934 et1310_setup_device_for_unicast(adapter
);
4939 /* Set us up with Broadcast packet filtering */
4940 if (filter
& ET131X_PACKET_TYPE_BROADCAST
) {
4941 pf_ctrl
|= 1; /* Broadcast filter bit */
4946 /* Setup the receive mac configuration registers - Packet
4947 * Filter control + the enable / disable for packet filter
4948 * in the control reg.
4950 writel(pf_ctrl
, &adapter
->regs
->rxmac
.pf_ctrl
);
4951 writel(ctrl
, &adapter
->regs
->rxmac
.ctrl
);
4957 * et131x_multicast - The handler to configure multicasting on the interface
4958 * @netdev: a pointer to a net_device struct representing the device
4960 static void et131x_multicast(struct net_device
*netdev
)
4962 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
4963 uint32_t packet_filter
= 0;
4964 unsigned long flags
;
4965 struct netdev_hw_addr
*ha
;
4968 spin_lock_irqsave(&adapter
->lock
, flags
);
4970 /* Before we modify the platform-independent filter flags, store them
4971 * locally. This allows us to determine if anything's changed and if
4972 * we even need to bother the hardware
4974 packet_filter
= adapter
->packet_filter
;
4976 /* Clear the 'multicast' flag locally; because we only have a single
4977 * flag to check multicast, and multiple multicast addresses can be
4978 * set, this is the easiest way to determine if more than one
4979 * multicast address is being set.
4981 packet_filter
&= ~ET131X_PACKET_TYPE_MULTICAST
;
4983 /* Check the net_device flags and set the device independent flags
4987 if (netdev
->flags
& IFF_PROMISC
)
4988 adapter
->packet_filter
|= ET131X_PACKET_TYPE_PROMISCUOUS
;
4990 adapter
->packet_filter
&= ~ET131X_PACKET_TYPE_PROMISCUOUS
;
4992 if (netdev
->flags
& IFF_ALLMULTI
)
4993 adapter
->packet_filter
|= ET131X_PACKET_TYPE_ALL_MULTICAST
;
4995 if (netdev_mc_count(netdev
) > NIC_MAX_MCAST_LIST
)
4996 adapter
->packet_filter
|= ET131X_PACKET_TYPE_ALL_MULTICAST
;
4998 if (netdev_mc_count(netdev
) < 1) {
4999 adapter
->packet_filter
&= ~ET131X_PACKET_TYPE_ALL_MULTICAST
;
5000 adapter
->packet_filter
&= ~ET131X_PACKET_TYPE_MULTICAST
;
5002 adapter
->packet_filter
|= ET131X_PACKET_TYPE_MULTICAST
;
5004 /* Set values in the private adapter struct */
5006 netdev_for_each_mc_addr(ha
, netdev
) {
5007 if (i
== NIC_MAX_MCAST_LIST
)
5009 memcpy(adapter
->multicast_list
[i
++], ha
->addr
, ETH_ALEN
);
5011 adapter
->multicast_addr_count
= i
;
5013 /* Are the new flags different from the previous ones? If not, then no
5014 * action is required
5016 * NOTE - This block will always update the multicast_list with the
5017 * hardware, even if the addresses aren't the same.
5019 if (packet_filter
!= adapter
->packet_filter
) {
5020 /* Call the device's filter function */
5021 et131x_set_packet_filter(adapter
);
5023 spin_unlock_irqrestore(&adapter
->lock
, flags
);
5027 * et131x_tx - The handler to tx a packet on the device
5028 * @skb: data to be Tx'd
5029 * @netdev: device on which data is to be Tx'd
5031 * Returns 0 on success, errno on failure (as defined in errno.h)
5033 static int et131x_tx(struct sk_buff
*skb
, struct net_device
*netdev
)
5036 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
5038 /* stop the queue if it's getting full */
5039 if(adapter
->tx_ring
.used
>= NUM_TCB
- 1 && !netif_queue_stopped(netdev
))
5040 netif_stop_queue(netdev
);
5042 /* Save the timestamp for the TX timeout watchdog */
5043 netdev
->trans_start
= jiffies
;
5045 /* Call the device-specific data Tx routine */
5046 status
= et131x_send_packets(skb
, netdev
);
5048 /* Check status and manage the netif queue if necessary */
5050 if (status
== -ENOMEM
) {
5051 status
= NETDEV_TX_BUSY
;
5053 status
= NETDEV_TX_OK
;
5060 * et131x_tx_timeout - Timeout handler
5061 * @netdev: a pointer to a net_device struct representing the device
5063 * The handler called when a Tx request times out. The timeout period is
5064 * specified by the 'tx_timeo" element in the net_device structure (see
5065 * et131x_alloc_device() to see how this value is set).
5067 static void et131x_tx_timeout(struct net_device
*netdev
)
5069 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
5071 unsigned long flags
;
5073 /* If the device is closed, ignore the timeout */
5074 if (~(adapter
->flags
& fMP_ADAPTER_INTERRUPT_IN_USE
))
5077 /* Any nonrecoverable hardware error?
5078 * Checks adapter->flags for any failure in phy reading
5080 if (adapter
->flags
& fMP_ADAPTER_NON_RECOVER_ERROR
)
5083 /* Hardware failure? */
5084 if (adapter
->flags
& fMP_ADAPTER_HARDWARE_ERROR
) {
5085 dev_err(&adapter
->pdev
->dev
, "hardware error - reset\n");
5089 /* Is send stuck? */
5090 spin_lock_irqsave(&adapter
->tcb_send_qlock
, flags
);
5092 tcb
= adapter
->tx_ring
.send_head
;
5097 if (tcb
->count
> NIC_SEND_HANG_THRESHOLD
) {
5098 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
,
5101 dev_warn(&adapter
->pdev
->dev
,
5102 "Send stuck - reset. tcb->WrIndex %x, flags 0x%08x\n",
5106 adapter
->net_stats
.tx_errors
++;
5108 /* perform reset of tx/rx */
5109 et131x_disable_txrx(netdev
);
5110 et131x_enable_txrx(netdev
);
5115 spin_unlock_irqrestore(&adapter
->tcb_send_qlock
, flags
);
5119 * et131x_change_mtu - The handler called to change the MTU for the device
5120 * @netdev: device whose MTU is to be changed
5121 * @new_mtu: the desired MTU
5123 * Returns 0 on success, errno on failure (as defined in errno.h)
5125 static int et131x_change_mtu(struct net_device
*netdev
, int new_mtu
)
5128 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
5130 /* Make sure the requested MTU is valid */
5131 if (new_mtu
< 64 || new_mtu
> 9216)
5134 et131x_disable_txrx(netdev
);
5135 et131x_handle_send_interrupt(adapter
);
5136 et131x_handle_recv_interrupt(adapter
);
5138 /* Set the new MTU */
5139 netdev
->mtu
= new_mtu
;
5141 /* Free Rx DMA memory */
5142 et131x_adapter_memory_free(adapter
);
5144 /* Set the config parameter for Jumbo Packet support */
5145 adapter
->registry_jumbo_packet
= new_mtu
+ 14;
5146 et131x_soft_reset(adapter
);
5148 /* Alloc and init Rx DMA memory */
5149 result
= et131x_adapter_memory_alloc(adapter
);
5151 dev_warn(&adapter
->pdev
->dev
,
5152 "Change MTU failed; couldn't re-alloc DMA memory\n");
5156 et131x_init_send(adapter
);
5158 et131x_hwaddr_init(adapter
);
5159 memcpy(netdev
->dev_addr
, adapter
->addr
, ETH_ALEN
);
5161 /* Init the device with the new settings */
5162 et131x_adapter_setup(adapter
);
5164 et131x_enable_txrx(netdev
);
5170 * et131x_set_mac_addr - handler to change the MAC address for the device
5171 * @netdev: device whose MAC is to be changed
5172 * @new_mac: the desired MAC address
5174 * Returns 0 on success, errno on failure (as defined in errno.h)
5176 * IMPLEMENTED BY : blux http://berndlux.de 22.01.2007 21:14
5178 static int et131x_set_mac_addr(struct net_device
*netdev
, void *new_mac
)
5181 struct et131x_adapter
*adapter
= netdev_priv(netdev
);
5182 struct sockaddr
*address
= new_mac
;
5186 if (adapter
== NULL
)
5189 /* Make sure the requested MAC is valid */
5190 if (!is_valid_ether_addr(address
->sa_data
))
5193 et131x_disable_txrx(netdev
);
5194 et131x_handle_send_interrupt(adapter
);
5195 et131x_handle_recv_interrupt(adapter
);
5197 /* Set the new MAC */
5198 /* netdev->set_mac_address = &new_mac; */
5200 memcpy(netdev
->dev_addr
, address
->sa_data
, netdev
->addr_len
);
5202 printk(KERN_INFO
"%s: Setting MAC address to %pM\n",
5203 netdev
->name
, netdev
->dev_addr
);
5205 /* Free Rx DMA memory */
5206 et131x_adapter_memory_free(adapter
);
5208 et131x_soft_reset(adapter
);
5210 /* Alloc and init Rx DMA memory */
5211 result
= et131x_adapter_memory_alloc(adapter
);
5213 dev_err(&adapter
->pdev
->dev
,
5214 "Change MAC failed; couldn't re-alloc DMA memory\n");
5218 et131x_init_send(adapter
);
5220 et131x_hwaddr_init(adapter
);
5222 /* Init the device with the new settings */
5223 et131x_adapter_setup(adapter
);
5225 et131x_enable_txrx(netdev
);
5230 static const struct net_device_ops et131x_netdev_ops
= {
5231 .ndo_open
= et131x_open
,
5232 .ndo_stop
= et131x_close
,
5233 .ndo_start_xmit
= et131x_tx
,
5234 .ndo_set_multicast_list
= et131x_multicast
,
5235 .ndo_tx_timeout
= et131x_tx_timeout
,
5236 .ndo_change_mtu
= et131x_change_mtu
,
5237 .ndo_set_mac_address
= et131x_set_mac_addr
,
5238 .ndo_validate_addr
= eth_validate_addr
,
5239 .ndo_get_stats
= et131x_stats
,
5240 .ndo_do_ioctl
= et131x_ioctl
,
5244 * et131x_device_alloc
5246 * Returns pointer to the allocated and initialized net_device struct for
5249 * Create instances of net_device and wl_private for the new adapter and
5250 * register the device's entry points in the net_device structure.
5252 struct net_device
*et131x_device_alloc(void)
5254 struct net_device
*netdev
;
5256 /* Alloc net_device and adapter structs */
5257 netdev
= alloc_etherdev(sizeof(struct et131x_adapter
));
5260 printk(KERN_ERR
"et131x: Alloc of net_device struct failed\n");
5265 * Setup the function registration table (and other data) for a
5268 netdev
->watchdog_timeo
= ET131X_TX_TIMEOUT
;
5269 netdev
->netdev_ops
= &et131x_netdev_ops
;
5272 /* netdev->poll = &et131x_poll; */
5273 /* netdev->poll_controller = &et131x_poll_controller; */
5278 * et131x_pci_setup - Perform device initialization
5279 * @pdev: a pointer to the device's pci_dev structure
5280 * @ent: this device's entry in the pci_device_id table
5282 * Returns 0 on success, errno on failure (as defined in errno.h)
5284 * Registered in the pci_driver structure, this function is called when the
5285 * PCI subsystem finds a new PCI device which matches the information
5286 * contained in the pci_device_id table. This routine is the equivalent to
5287 * a device insertion routine.
5289 static int __devinit
et131x_pci_setup(struct pci_dev
*pdev
,
5290 const struct pci_device_id
*ent
)
5293 struct net_device
*netdev
;
5294 struct et131x_adapter
*adapter
;
5297 result
= pci_enable_device(pdev
);
5299 dev_err(&pdev
->dev
, "pci_enable_device() failed\n");
5303 /* Perform some basic PCI checks */
5304 if (!(pci_resource_flags(pdev
, 0) & IORESOURCE_MEM
)) {
5305 dev_err(&pdev
->dev
, "Can't find PCI device's base address\n");
5309 if (pci_request_regions(pdev
, DRIVER_NAME
)) {
5310 dev_err(&pdev
->dev
, "Can't get PCI resources\n");
5314 pci_set_master(pdev
);
5316 /* Check the DMA addressing support of this device */
5317 if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(64))) {
5318 result
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(64));
5321 "Unable to obtain 64 bit DMA for consistent allocations\n");
5322 goto err_release_res
;
5324 } else if (!dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32))) {
5325 result
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
5328 "Unable to obtain 32 bit DMA for consistent allocations\n");
5329 goto err_release_res
;
5332 dev_err(&pdev
->dev
, "No usable DMA addressing method\n");
5334 goto err_release_res
;
5337 /* Allocate netdev and private adapter structs */
5338 netdev
= et131x_device_alloc();
5340 dev_err(&pdev
->dev
, "Couldn't alloc netdev struct\n");
5342 goto err_release_res
;
5345 SET_NETDEV_DEV(netdev
, &pdev
->dev
);
5346 et131x_set_ethtool_ops(netdev
);
5348 adapter
= et131x_adapter_init(netdev
, pdev
);
5350 /* Initialise the PCI setup for the device */
5351 et131x_pci_init(adapter
, pdev
);
5353 /* Map the bus-relative registers to system virtual memory */
5354 adapter
->regs
= pci_ioremap_bar(pdev
, 0);
5355 if (!adapter
->regs
) {
5356 dev_err(&pdev
->dev
, "Cannot map device registers\n");
5361 /* If Phy COMA mode was enabled when we went down, disable it here. */
5362 writel(ET_PMCSR_INIT
, &adapter
->regs
->global
.pm_csr
);
5364 /* Issue a global reset to the et1310 */
5365 et131x_soft_reset(adapter
);
5367 /* Disable all interrupts (paranoid) */
5368 et131x_disable_interrupts(adapter
);
5370 /* Allocate DMA memory */
5371 result
= et131x_adapter_memory_alloc(adapter
);
5373 dev_err(&pdev
->dev
, "Could not alloc adapater memory (DMA)\n");
5377 /* Init send data structures */
5378 et131x_init_send(adapter
);
5380 /* Set up the task structure for the ISR's deferred handler */
5381 INIT_WORK(&adapter
->task
, et131x_isr_handler
);
5383 /* Copy address into the net_device struct */
5384 memcpy(netdev
->dev_addr
, adapter
->addr
, ETH_ALEN
);
5386 /* Init variable for counting how long we do not have link status */
5387 adapter
->boot_coma
= 0;
5388 et1310_disable_phy_coma(adapter
);
5390 /* Setup the mii_bus struct */
5391 adapter
->mii_bus
= mdiobus_alloc();
5392 if (!adapter
->mii_bus
) {
5393 dev_err(&pdev
->dev
, "Alloc of mii_bus struct failed\n");
5397 adapter
->mii_bus
->name
= "et131x_eth_mii";
5398 snprintf(adapter
->mii_bus
->id
, MII_BUS_ID_SIZE
, "%x",
5399 (adapter
->pdev
->bus
->number
<< 8) | adapter
->pdev
->devfn
);
5400 adapter
->mii_bus
->priv
= netdev
;
5401 adapter
->mii_bus
->read
= et131x_mdio_read
;
5402 adapter
->mii_bus
->write
= et131x_mdio_write
;
5403 adapter
->mii_bus
->reset
= et131x_mdio_reset
;
5404 adapter
->mii_bus
->irq
= kmalloc(sizeof(int)*PHY_MAX_ADDR
, GFP_KERNEL
);
5405 if (!adapter
->mii_bus
->irq
) {
5406 dev_err(&pdev
->dev
, "mii_bus irq allocation failed\n");
5410 for (ii
= 0; ii
< PHY_MAX_ADDR
; ii
++)
5411 adapter
->mii_bus
->irq
[ii
] = PHY_POLL
;
5413 if (mdiobus_register(adapter
->mii_bus
)) {
5414 dev_err(&pdev
->dev
, "failed to register MII bus\n");
5415 mdiobus_free(adapter
->mii_bus
);
5416 goto err_mdio_free_irq
;
5419 if (et131x_mii_probe(netdev
)) {
5420 dev_err(&pdev
->dev
, "failed to probe MII bus\n");
5421 goto err_mdio_unregister
;
5424 /* Setup et1310 as per the documentation */
5425 et131x_adapter_setup(adapter
);
5427 /* We can enable interrupts now
5429 * NOTE - Because registration of interrupt handler is done in the
5430 * device's open(), defer enabling device interrupts to that
5434 /* Register the net_device struct with the Linux network layer */
5435 result
= register_netdev(netdev
);
5437 dev_err(&pdev
->dev
, "register_netdev() failed\n");
5438 goto err_mdio_unregister
;
5441 /* Register the net_device struct with the PCI subsystem. Save a copy
5442 * of the PCI config space for this device now that the device has
5443 * been initialized, just in case it needs to be quickly restored.
5445 pci_set_drvdata(pdev
, netdev
);
5446 pci_save_state(adapter
->pdev
);
5450 err_mdio_unregister
:
5451 mdiobus_unregister(adapter
->mii_bus
);
5453 kfree(adapter
->mii_bus
->irq
);
5455 mdiobus_free(adapter
->mii_bus
);
5457 et131x_adapter_memory_free(adapter
);
5459 iounmap(adapter
->regs
);
5462 free_netdev(netdev
);
5464 pci_release_regions(pdev
);
5466 pci_disable_device(pdev
);
5471 static SIMPLE_DEV_PM_OPS(et131x_pm_ops
, et131x_suspend
, et131x_resume
);
5472 #define ET131X_PM_OPS (&et131x_pm_ops)
5474 #define ET131X_PM_OPS NULL
5477 static DEFINE_PCI_DEVICE_TABLE(et131x_pci_table
) = {
5478 { PCI_VDEVICE(ATT
, ET131X_PCI_DEVICE_ID_GIG
), 0UL},
5479 { PCI_VDEVICE(ATT
, ET131X_PCI_DEVICE_ID_FAST
), 0UL},
5482 MODULE_DEVICE_TABLE(pci
, et131x_pci_table
);
5484 static struct pci_driver et131x_driver
= {
5485 .name
= DRIVER_NAME
,
5486 .id_table
= et131x_pci_table
,
5487 .probe
= et131x_pci_setup
,
5488 .remove
= __devexit_p(et131x_pci_remove
),
5489 .driver
.pm
= ET131X_PM_OPS
,
5493 * et131x_init_module - The "main" entry point called on driver initialization
5495 * Returns 0 on success, errno on failure (as defined in errno.h)
5497 static int __init
et131x_init_module(void)
5499 return pci_register_driver(&et131x_driver
);
5503 * et131x_cleanup_module - The entry point called on driver cleanup
5505 static void __exit
et131x_cleanup_module(void)
5507 pci_unregister_driver(&et131x_driver
);
5510 module_init(et131x_init_module
);
5511 module_exit(et131x_cleanup_module
);