1c960b13eSThomas Chou /* 2c960b13eSThomas Chou * Altera 10/100/1000 triple speed ethernet mac 3c960b13eSThomas Chou * 4c960b13eSThomas Chou * Copyright (C) 2008 Altera Corporation. 5c960b13eSThomas Chou * Copyright (C) 2010 Thomas Chou <thomas@wytron.com.tw> 6c960b13eSThomas Chou * 7c960b13eSThomas Chou * This program is free software; you can redistribute it and/or modify 8c960b13eSThomas Chou * it under the terms of the GNU General Public License version 2 as 9c960b13eSThomas Chou * published by the Free Software Foundation. 10c960b13eSThomas Chou */ 11c960b13eSThomas Chou #ifndef _ALTERA_TSE_H_ 12c960b13eSThomas Chou #define _ALTERA_TSE_H_ 13c960b13eSThomas Chou 14c960b13eSThomas Chou #define __packed_1_ __attribute__ ((packed, aligned(1))) 15c960b13eSThomas Chou 16c960b13eSThomas Chou /* SGDMA Stuff */ 17c960b13eSThomas Chou #define ALT_SGDMA_STATUS_BUSY_MSK (0x00000010) 18c960b13eSThomas Chou 19c960b13eSThomas Chou #define ALT_SGDMA_CONTROL_RUN_MSK (0x00000020) 20c960b13eSThomas Chou #define ALT_SGDMA_CONTROL_STOP_DMA_ER_MSK (0x00000040) 21c960b13eSThomas Chou #define ALT_SGDMA_CONTROL_SOFTWARERESET_MSK (0x00010000) 22c960b13eSThomas Chou 23c960b13eSThomas Chou /* 24c960b13eSThomas Chou * Descriptor control bit masks & offsets 25c960b13eSThomas Chou * 26c960b13eSThomas Chou * Note: The control byte physically occupies bits [31:24] in memory. 27c960b13eSThomas Chou * The following bit-offsets are expressed relative to the LSB of 28c960b13eSThomas Chou * the control register bitfield. 29c960b13eSThomas Chou */ 30c960b13eSThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_GENERATE_EOP_MSK (0x00000001) 31c960b13eSThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_READ_FIXED_ADDRESS_MSK (0x00000002) 32c960b13eSThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_WRITE_FIXED_ADDRESS_MSK (0x00000004) 33c960b13eSThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK (0x00000080) 34c960b13eSThomas Chou 35c960b13eSThomas Chou /* 36c960b13eSThomas Chou * Descriptor status bit masks & offsets 37c960b13eSThomas Chou * 38c960b13eSThomas Chou * Note: The status byte physically occupies bits [23:16] in memory. 39c960b13eSThomas Chou * The following bit-offsets are expressed relative to the LSB of 40c960b13eSThomas Chou * the status register bitfield. 41c960b13eSThomas Chou */ 42c960b13eSThomas Chou #define ALT_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_MSK (0x00000080) 43c960b13eSThomas Chou 44c960b13eSThomas Chou /* 45c960b13eSThomas Chou * The SGDMA controller buffer descriptor allocates 46c960b13eSThomas Chou * 64 bits for each address. To support ANSI C, the 47c960b13eSThomas Chou * struct implementing a descriptor places 32-bits 48c960b13eSThomas Chou * of padding directly above each address; each pad must 49c960b13eSThomas Chou * be cleared when initializing a descriptor. 50c960b13eSThomas Chou */ 51c960b13eSThomas Chou 52c960b13eSThomas Chou /* 53c960b13eSThomas Chou * Buffer Descriptor data structure 54c960b13eSThomas Chou * 55c960b13eSThomas Chou */ 56c960b13eSThomas Chou struct alt_sgdma_descriptor { 57*2cd0a52eSThomas Chou u32 source; /* the address of data to be read. */ 58*2cd0a52eSThomas Chou u32 source_pad; 59c960b13eSThomas Chou 60*2cd0a52eSThomas Chou u32 destination; /* the address to write data */ 61*2cd0a52eSThomas Chou u32 destination_pad; 62c960b13eSThomas Chou 63*2cd0a52eSThomas Chou u32 next; /* the next descriptor in the list. */ 64*2cd0a52eSThomas Chou u32 next_pad; 65c960b13eSThomas Chou 66*2cd0a52eSThomas Chou u16 bytes_to_transfer; /* the number of bytes to transfer */ 67*2cd0a52eSThomas Chou u8 read_burst; 68*2cd0a52eSThomas Chou u8 write_burst; 69c960b13eSThomas Chou 70*2cd0a52eSThomas Chou u16 actual_bytes_transferred;/* bytes transferred by DMA */ 71*2cd0a52eSThomas Chou u8 descriptor_status; 72*2cd0a52eSThomas Chou u8 descriptor_control; 73c960b13eSThomas Chou 74c960b13eSThomas Chou } __packed_1_; 75c960b13eSThomas Chou 76c960b13eSThomas Chou /* SG-DMA Control/Status Slave registers map */ 77c960b13eSThomas Chou 78c960b13eSThomas Chou struct alt_sgdma_registers { 79*2cd0a52eSThomas Chou u32 status; 80*2cd0a52eSThomas Chou u32 status_pad[3]; 81*2cd0a52eSThomas Chou u32 control; 82*2cd0a52eSThomas Chou u32 control_pad[3]; 83*2cd0a52eSThomas Chou u32 next_descriptor_pointer; 84*2cd0a52eSThomas Chou u32 descriptor_pad[3]; 85c960b13eSThomas Chou }; 86c960b13eSThomas Chou 87c960b13eSThomas Chou /* TSE Stuff */ 88c960b13eSThomas Chou #define ALTERA_TSE_CMD_TX_ENA_MSK (0x00000001) 89c960b13eSThomas Chou #define ALTERA_TSE_CMD_RX_ENA_MSK (0x00000002) 90c960b13eSThomas Chou #define ALTERA_TSE_CMD_ETH_SPEED_MSK (0x00000008) 91c960b13eSThomas Chou #define ALTERA_TSE_CMD_HD_ENA_MSK (0x00000400) 92c960b13eSThomas Chou #define ALTERA_TSE_CMD_SW_RESET_MSK (0x00002000) 93c960b13eSThomas Chou #define ALTERA_TSE_CMD_ENA_10_MSK (0x02000000) 94c960b13eSThomas Chou 9596fa1e43SThomas Chou #define ALT_TSE_SW_RESET_TIMEOUT (3 * CONFIG_SYS_HZ) 9696fa1e43SThomas Chou #define ALT_TSE_SGDMA_BUSY_TIMEOUT (3 * CONFIG_SYS_HZ) 97c960b13eSThomas Chou 98c960b13eSThomas Chou /* MAC register Space */ 99c960b13eSThomas Chou 100c960b13eSThomas Chou struct alt_tse_mac { 101*2cd0a52eSThomas Chou u32 megacore_revision; 102*2cd0a52eSThomas Chou u32 scratch_pad; 103*2cd0a52eSThomas Chou u32 command_config; 104*2cd0a52eSThomas Chou u32 mac_addr_0; 105*2cd0a52eSThomas Chou u32 mac_addr_1; 106*2cd0a52eSThomas Chou u32 max_frame_length; 107*2cd0a52eSThomas Chou u32 pause_quanta; 108*2cd0a52eSThomas Chou u32 rx_sel_empty_threshold; 109*2cd0a52eSThomas Chou u32 rx_sel_full_threshold; 110*2cd0a52eSThomas Chou u32 tx_sel_empty_threshold; 111*2cd0a52eSThomas Chou u32 tx_sel_full_threshold; 112*2cd0a52eSThomas Chou u32 rx_almost_empty_threshold; 113*2cd0a52eSThomas Chou u32 rx_almost_full_threshold; 114*2cd0a52eSThomas Chou u32 tx_almost_empty_threshold; 115*2cd0a52eSThomas Chou u32 tx_almost_full_threshold; 116*2cd0a52eSThomas Chou u32 mdio_phy0_addr; 117*2cd0a52eSThomas Chou u32 mdio_phy1_addr; 118c960b13eSThomas Chou 119*2cd0a52eSThomas Chou u32 reserved1[0x29]; 120c960b13eSThomas Chou 121c960b13eSThomas Chou /*FIFO control register. */ 122*2cd0a52eSThomas Chou u32 tx_cmd_stat; 123*2cd0a52eSThomas Chou u32 rx_cmd_stat; 124c960b13eSThomas Chou 125*2cd0a52eSThomas Chou u32 reserved2[0x44]; 126c960b13eSThomas Chou 127c960b13eSThomas Chou /*Registers 0 to 31 within PHY device 0/1 */ 128*2cd0a52eSThomas Chou u32 mdio_phy0[0x20]; 129*2cd0a52eSThomas Chou u32 mdio_phy1[0x20]; 130c960b13eSThomas Chou 131c960b13eSThomas Chou /*4 Supplemental MAC Addresses */ 132*2cd0a52eSThomas Chou u32 supp_mac_addr_0_0; 133*2cd0a52eSThomas Chou u32 supp_mac_addr_0_1; 134*2cd0a52eSThomas Chou u32 supp_mac_addr_1_0; 135*2cd0a52eSThomas Chou u32 supp_mac_addr_1_1; 136*2cd0a52eSThomas Chou u32 supp_mac_addr_2_0; 137*2cd0a52eSThomas Chou u32 supp_mac_addr_2_1; 138*2cd0a52eSThomas Chou u32 supp_mac_addr_3_0; 139*2cd0a52eSThomas Chou u32 supp_mac_addr_3_1; 140c960b13eSThomas Chou 141*2cd0a52eSThomas Chou u32 reserved3[0x38]; 142c960b13eSThomas Chou }; 143c960b13eSThomas Chou 144c960b13eSThomas Chou struct altera_tse_priv { 14596fa1e43SThomas Chou struct alt_tse_mac *mac_dev; 14696fa1e43SThomas Chou struct alt_sgdma_registers *sgdma_rx; 14796fa1e43SThomas Chou struct alt_sgdma_registers *sgdma_tx; 14896fa1e43SThomas Chou unsigned int rx_fifo_depth; 14996fa1e43SThomas Chou unsigned int tx_fifo_depth; 15096fa1e43SThomas Chou struct alt_sgdma_descriptor *rx_desc; 15196fa1e43SThomas Chou struct alt_sgdma_descriptor *tx_desc; 15296fa1e43SThomas Chou unsigned char *rx_buf; 153c960b13eSThomas Chou unsigned int phyaddr; 15496fa1e43SThomas Chou unsigned int interface; 15596fa1e43SThomas Chou struct phy_device *phydev; 15696fa1e43SThomas Chou struct mii_dev *bus; 157c960b13eSThomas Chou }; 158c960b13eSThomas Chou 159c960b13eSThomas Chou #endif /* _ALTERA_TSE_H_ */ 160