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 1413146ec9SThomas Chou #define __packed_1_ __packed __aligned(1) 15c960b13eSThomas Chou 16*38fa4acaSThomas Chou /* dma type */ 17*38fa4acaSThomas Chou #define ALT_SGDMA 0 18*38fa4acaSThomas Chou 19c960b13eSThomas Chou /* SGDMA Stuff */ 204c8df1d3SThomas Chou #define ALT_SGDMA_STATUS_BUSY_MSK BIT(4) 21c960b13eSThomas Chou 224c8df1d3SThomas Chou #define ALT_SGDMA_CONTROL_RUN_MSK BIT(5) 234c8df1d3SThomas Chou #define ALT_SGDMA_CONTROL_STOP_DMA_ER_MSK BIT(6) 244c8df1d3SThomas Chou #define ALT_SGDMA_CONTROL_SOFTWARERESET_MSK BIT(16) 25c960b13eSThomas Chou 26c960b13eSThomas Chou /* 27c960b13eSThomas Chou * Descriptor control bit masks & offsets 28c960b13eSThomas Chou * 29c960b13eSThomas Chou * Note: The control byte physically occupies bits [31:24] in memory. 30c960b13eSThomas Chou * The following bit-offsets are expressed relative to the LSB of 31c960b13eSThomas Chou * the control register bitfield. 32c960b13eSThomas Chou */ 334c8df1d3SThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_GENERATE_EOP_MSK BIT(0) 344c8df1d3SThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_READ_FIXED_ADDRESS_MSK BIT(1) 354c8df1d3SThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_WRITE_FIXED_ADDRESS_MSK BIT(2) 364c8df1d3SThomas Chou #define ALT_SGDMA_DESCRIPTOR_CONTROL_OWNED_BY_HW_MSK BIT(7) 37c960b13eSThomas Chou 38c960b13eSThomas Chou /* 39c960b13eSThomas Chou * Descriptor status bit masks & offsets 40c960b13eSThomas Chou * 41c960b13eSThomas Chou * Note: The status byte physically occupies bits [23:16] in memory. 42c960b13eSThomas Chou * The following bit-offsets are expressed relative to the LSB of 43c960b13eSThomas Chou * the status register bitfield. 44c960b13eSThomas Chou */ 454c8df1d3SThomas Chou #define ALT_SGDMA_DESCRIPTOR_STATUS_TERMINATED_BY_EOP_MSK BIT(7) 46c960b13eSThomas Chou 47c960b13eSThomas Chou /* 48c960b13eSThomas Chou * The SGDMA controller buffer descriptor allocates 49c960b13eSThomas Chou * 64 bits for each address. To support ANSI C, the 50c960b13eSThomas Chou * struct implementing a descriptor places 32-bits 51c960b13eSThomas Chou * of padding directly above each address; each pad must 52c960b13eSThomas Chou * be cleared when initializing a descriptor. 53c960b13eSThomas Chou */ 54c960b13eSThomas Chou 55c960b13eSThomas Chou /* 56c960b13eSThomas Chou * Buffer Descriptor data structure 57c960b13eSThomas Chou * 58c960b13eSThomas Chou */ 59c960b13eSThomas Chou struct alt_sgdma_descriptor { 602cd0a52eSThomas Chou u32 source; /* the address of data to be read. */ 612cd0a52eSThomas Chou u32 source_pad; 62c960b13eSThomas Chou 632cd0a52eSThomas Chou u32 destination; /* the address to write data */ 642cd0a52eSThomas Chou u32 destination_pad; 65c960b13eSThomas Chou 662cd0a52eSThomas Chou u32 next; /* the next descriptor in the list. */ 672cd0a52eSThomas Chou u32 next_pad; 68c960b13eSThomas Chou 692cd0a52eSThomas Chou u16 bytes_to_transfer; /* the number of bytes to transfer */ 702cd0a52eSThomas Chou u8 read_burst; 712cd0a52eSThomas Chou u8 write_burst; 72c960b13eSThomas Chou 732cd0a52eSThomas Chou u16 actual_bytes_transferred;/* bytes transferred by DMA */ 742cd0a52eSThomas Chou u8 descriptor_status; 752cd0a52eSThomas Chou u8 descriptor_control; 76c960b13eSThomas Chou 77c960b13eSThomas Chou } __packed_1_; 78c960b13eSThomas Chou 79c960b13eSThomas Chou /* SG-DMA Control/Status Slave registers map */ 80c960b13eSThomas Chou 81c960b13eSThomas Chou struct alt_sgdma_registers { 822cd0a52eSThomas Chou u32 status; 832cd0a52eSThomas Chou u32 status_pad[3]; 842cd0a52eSThomas Chou u32 control; 852cd0a52eSThomas Chou u32 control_pad[3]; 862cd0a52eSThomas Chou u32 next_descriptor_pointer; 872cd0a52eSThomas Chou u32 descriptor_pad[3]; 88c960b13eSThomas Chou }; 89c960b13eSThomas Chou 90c960b13eSThomas Chou /* TSE Stuff */ 914c8df1d3SThomas Chou #define ALTERA_TSE_CMD_TX_ENA_MSK BIT(0) 924c8df1d3SThomas Chou #define ALTERA_TSE_CMD_RX_ENA_MSK BIT(1) 934c8df1d3SThomas Chou #define ALTERA_TSE_CMD_ETH_SPEED_MSK BIT(3) 944c8df1d3SThomas Chou #define ALTERA_TSE_CMD_HD_ENA_MSK BIT(10) 954c8df1d3SThomas Chou #define ALTERA_TSE_CMD_SW_RESET_MSK BIT(13) 964c8df1d3SThomas Chou #define ALTERA_TSE_CMD_ENA_10_MSK BIT(25) 97c960b13eSThomas Chou 9896fa1e43SThomas Chou #define ALT_TSE_SW_RESET_TIMEOUT (3 * CONFIG_SYS_HZ) 9996fa1e43SThomas Chou #define ALT_TSE_SGDMA_BUSY_TIMEOUT (3 * CONFIG_SYS_HZ) 100c960b13eSThomas Chou 101c960b13eSThomas Chou /* MAC register Space */ 102c960b13eSThomas Chou 103c960b13eSThomas Chou struct alt_tse_mac { 1042cd0a52eSThomas Chou u32 megacore_revision; 1052cd0a52eSThomas Chou u32 scratch_pad; 1062cd0a52eSThomas Chou u32 command_config; 1072cd0a52eSThomas Chou u32 mac_addr_0; 1082cd0a52eSThomas Chou u32 mac_addr_1; 1092cd0a52eSThomas Chou u32 max_frame_length; 1102cd0a52eSThomas Chou u32 pause_quanta; 1112cd0a52eSThomas Chou u32 rx_sel_empty_threshold; 1122cd0a52eSThomas Chou u32 rx_sel_full_threshold; 1132cd0a52eSThomas Chou u32 tx_sel_empty_threshold; 1142cd0a52eSThomas Chou u32 tx_sel_full_threshold; 1152cd0a52eSThomas Chou u32 rx_almost_empty_threshold; 1162cd0a52eSThomas Chou u32 rx_almost_full_threshold; 1172cd0a52eSThomas Chou u32 tx_almost_empty_threshold; 1182cd0a52eSThomas Chou u32 tx_almost_full_threshold; 1192cd0a52eSThomas Chou u32 mdio_phy0_addr; 1202cd0a52eSThomas Chou u32 mdio_phy1_addr; 121c960b13eSThomas Chou 1222cd0a52eSThomas Chou u32 reserved1[0x29]; 123c960b13eSThomas Chou 124c960b13eSThomas Chou /*FIFO control register. */ 1252cd0a52eSThomas Chou u32 tx_cmd_stat; 1262cd0a52eSThomas Chou u32 rx_cmd_stat; 127c960b13eSThomas Chou 1282cd0a52eSThomas Chou u32 reserved2[0x44]; 129c960b13eSThomas Chou 130c960b13eSThomas Chou /*Registers 0 to 31 within PHY device 0/1 */ 1312cd0a52eSThomas Chou u32 mdio_phy0[0x20]; 1322cd0a52eSThomas Chou u32 mdio_phy1[0x20]; 133c960b13eSThomas Chou 134c960b13eSThomas Chou /*4 Supplemental MAC Addresses */ 1352cd0a52eSThomas Chou u32 supp_mac_addr_0_0; 1362cd0a52eSThomas Chou u32 supp_mac_addr_0_1; 1372cd0a52eSThomas Chou u32 supp_mac_addr_1_0; 1382cd0a52eSThomas Chou u32 supp_mac_addr_1_1; 1392cd0a52eSThomas Chou u32 supp_mac_addr_2_0; 1402cd0a52eSThomas Chou u32 supp_mac_addr_2_1; 1412cd0a52eSThomas Chou u32 supp_mac_addr_3_0; 1422cd0a52eSThomas Chou u32 supp_mac_addr_3_1; 143c960b13eSThomas Chou 1442cd0a52eSThomas Chou u32 reserved3[0x38]; 145c960b13eSThomas Chou }; 146c960b13eSThomas Chou 147*38fa4acaSThomas Chou struct tse_ops { 148*38fa4acaSThomas Chou int (*send)(struct udevice *dev, void *packet, int length); 149*38fa4acaSThomas Chou int (*recv)(struct udevice *dev, int flags, uchar **packetp); 150*38fa4acaSThomas Chou int (*free_pkt)(struct udevice *dev, uchar *packet, int length); 151*38fa4acaSThomas Chou void (*stop)(struct udevice *dev); 152*38fa4acaSThomas Chou }; 153*38fa4acaSThomas Chou 154c960b13eSThomas Chou struct altera_tse_priv { 15596fa1e43SThomas Chou struct alt_tse_mac *mac_dev; 156*38fa4acaSThomas Chou void *sgdma_rx; 157*38fa4acaSThomas Chou void *sgdma_tx; 15896fa1e43SThomas Chou unsigned int rx_fifo_depth; 15996fa1e43SThomas Chou unsigned int tx_fifo_depth; 160*38fa4acaSThomas Chou void *rx_desc; 161*38fa4acaSThomas Chou void *tx_desc; 16296fa1e43SThomas Chou unsigned char *rx_buf; 163c960b13eSThomas Chou unsigned int phyaddr; 16496fa1e43SThomas Chou unsigned int interface; 16596fa1e43SThomas Chou struct phy_device *phydev; 16696fa1e43SThomas Chou struct mii_dev *bus; 167*38fa4acaSThomas Chou const struct tse_ops *ops; 168*38fa4acaSThomas Chou int dma_type; 169c960b13eSThomas Chou }; 170c960b13eSThomas Chou 171c960b13eSThomas Chou #endif /* _ALTERA_TSE_H_ */ 172