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