Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2 | * Copyright (C) 2001,2002,2003,2004 Broadcom Corporation |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 3 | * Copyright (c) 2006, 2007 Maciej W. Rozycki |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | * |
| 20 | * This driver is designed for the Broadcom SiByte SOC built-in |
| 21 | * Ethernet controllers. Written by Mitch Lichtenberg at Broadcom Corp. |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 22 | * |
| 23 | * Updated to the driver model and the PHY abstraction layer |
| 24 | * by Maciej W. Rozycki. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 26 | |
| 27 | #include <linux/bug.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/timer.h> |
| 32 | #include <linux/errno.h> |
| 33 | #include <linux/ioport.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/netdevice.h> |
| 37 | #include <linux/etherdevice.h> |
| 38 | #include <linux/skbuff.h> |
| 39 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/bitops.h> |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 41 | #include <linux/err.h> |
| 42 | #include <linux/ethtool.h> |
| 43 | #include <linux/mii.h> |
| 44 | #include <linux/phy.h> |
| 45 | #include <linux/platform_device.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/cache.h> |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 48 | #include <asm/io.h> |
| 49 | #include <asm/processor.h> /* Processor type for cache alignment. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /* This is only here until the firmware is ready. In that case, |
| 52 | the firmware leaves the ethernet address in the register for us. */ |
| 53 | #ifdef CONFIG_SIBYTE_STANDALONE |
| 54 | #define SBMAC_ETH0_HWADDR "40:00:00:00:01:00" |
| 55 | #define SBMAC_ETH1_HWADDR "40:00:00:00:01:01" |
| 56 | #define SBMAC_ETH2_HWADDR "40:00:00:00:01:02" |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 57 | #define SBMAC_ETH3_HWADDR "40:00:00:00:01:03" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | |
| 61 | /* These identify the driver base version and may not be removed. */ |
| 62 | #if 0 |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 63 | static char version1[] __initdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | "sb1250-mac.c:1.00 1/11/2001 Written by Mitch Lichtenberg\n"; |
| 65 | #endif |
| 66 | |
| 67 | |
| 68 | /* Operational parameters that usually are not changed. */ |
| 69 | |
| 70 | #define CONFIG_SBMAC_COALESCE |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* Time in jiffies before concluding the transmitter is hung. */ |
| 73 | #define TX_TIMEOUT (2*HZ) |
| 74 | |
| 75 | |
| 76 | MODULE_AUTHOR("Mitch Lichtenberg (Broadcom Corp.)"); |
| 77 | MODULE_DESCRIPTION("Broadcom SiByte SOC GB Ethernet driver"); |
| 78 | |
| 79 | /* A few user-configurable values which may be modified when a driver |
| 80 | module is loaded. */ |
| 81 | |
| 82 | /* 1 normal messages, 0 quiet .. 7 verbose. */ |
| 83 | static int debug = 1; |
| 84 | module_param(debug, int, S_IRUGO); |
| 85 | MODULE_PARM_DESC(debug, "Debug messages"); |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #ifdef CONFIG_SBMAC_COALESCE |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 88 | static int int_pktcnt_tx = 255; |
| 89 | module_param(int_pktcnt_tx, int, S_IRUGO); |
| 90 | MODULE_PARM_DESC(int_pktcnt_tx, "TX packet count"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 92 | static int int_timeout_tx = 255; |
| 93 | module_param(int_timeout_tx, int, S_IRUGO); |
| 94 | MODULE_PARM_DESC(int_timeout_tx, "TX timeout value"); |
| 95 | |
| 96 | static int int_pktcnt_rx = 64; |
| 97 | module_param(int_pktcnt_rx, int, S_IRUGO); |
| 98 | MODULE_PARM_DESC(int_pktcnt_rx, "RX packet count"); |
| 99 | |
| 100 | static int int_timeout_rx = 64; |
| 101 | module_param(int_timeout_rx, int, S_IRUGO); |
| 102 | MODULE_PARM_DESC(int_timeout_rx, "RX timeout value"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | #endif |
| 104 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 105 | #include <asm/sibyte/board.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #include <asm/sibyte/sb1250.h> |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 107 | #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80) |
| 108 | #include <asm/sibyte/bcm1480_regs.h> |
| 109 | #include <asm/sibyte/bcm1480_int.h> |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 110 | #define R_MAC_DMA_OODPKTLOST_RX R_MAC_DMA_OODPKTLOST |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 111 | #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #include <asm/sibyte/sb1250_regs.h> |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 113 | #include <asm/sibyte/sb1250_int.h> |
| 114 | #else |
| 115 | #error invalid SiByte MAC configuation |
| 116 | #endif |
| 117 | #include <asm/sibyte/sb1250_scd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #include <asm/sibyte/sb1250_mac.h> |
| 119 | #include <asm/sibyte/sb1250_dma.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 121 | #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80) |
| 122 | #define UNIT_INT(n) (K_BCM1480_INT_MAC_0 + ((n) * 2)) |
| 123 | #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X) |
| 124 | #define UNIT_INT(n) (K_INT_MAC_0 + (n)) |
| 125 | #else |
| 126 | #error invalid SiByte MAC configuation |
| 127 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 129 | #ifdef K_INT_PHY |
| 130 | #define SBMAC_PHY_INT K_INT_PHY |
| 131 | #else |
| 132 | #define SBMAC_PHY_INT PHY_POLL |
| 133 | #endif |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /********************************************************************** |
| 136 | * Simple types |
| 137 | ********************************************************************* */ |
| 138 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 139 | enum sbmac_speed { |
| 140 | sbmac_speed_none = 0, |
| 141 | sbmac_speed_10 = SPEED_10, |
| 142 | sbmac_speed_100 = SPEED_100, |
| 143 | sbmac_speed_1000 = SPEED_1000, |
| 144 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 146 | enum sbmac_duplex { |
| 147 | sbmac_duplex_none = -1, |
| 148 | sbmac_duplex_half = DUPLEX_HALF, |
| 149 | sbmac_duplex_full = DUPLEX_FULL, |
| 150 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 152 | enum sbmac_fc { |
| 153 | sbmac_fc_none, |
| 154 | sbmac_fc_disabled, |
| 155 | sbmac_fc_frame, |
| 156 | sbmac_fc_collision, |
| 157 | sbmac_fc_carrier, |
| 158 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 160 | enum sbmac_state { |
| 161 | sbmac_state_uninit, |
| 162 | sbmac_state_off, |
| 163 | sbmac_state_on, |
| 164 | sbmac_state_broken, |
| 165 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
| 167 | |
| 168 | /********************************************************************** |
| 169 | * Macros |
| 170 | ********************************************************************* */ |
| 171 | |
| 172 | |
| 173 | #define SBDMA_NEXTBUF(d,f) ((((d)->f+1) == (d)->sbdma_dscrtable_end) ? \ |
| 174 | (d)->sbdma_dscrtable : (d)->f+1) |
| 175 | |
| 176 | |
| 177 | #define NUMCACHEBLKS(x) (((x)+SMP_CACHE_BYTES-1)/SMP_CACHE_BYTES) |
| 178 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 179 | #define SBMAC_MAX_TXDESCR 256 |
| 180 | #define SBMAC_MAX_RXDESCR 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 182 | #define ETHER_ADDR_LEN 6 |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 183 | #define ENET_PACKET_SIZE 1518 |
| 184 | /*#define ENET_PACKET_SIZE 9216 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | /********************************************************************** |
| 187 | * DMA Descriptor structure |
| 188 | ********************************************************************* */ |
| 189 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 190 | struct sbdmadscr { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | uint64_t dscr_a; |
| 192 | uint64_t dscr_b; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 193 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /********************************************************************** |
| 196 | * DMA Controller structure |
| 197 | ********************************************************************* */ |
| 198 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 199 | struct sbmacdma { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 200 | |
| 201 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | * This stuff is used to identify the channel and the registers |
| 203 | * associated with it. |
| 204 | */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 205 | struct sbmac_softc *sbdma_eth; /* back pointer to associated |
| 206 | MAC */ |
| 207 | int sbdma_channel; /* channel number */ |
| 208 | int sbdma_txdir; /* direction (1=transmit) */ |
| 209 | int sbdma_maxdescr; /* total # of descriptors |
| 210 | in ring */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | #ifdef CONFIG_SBMAC_COALESCE |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 212 | int sbdma_int_pktcnt; |
| 213 | /* # descriptors rx/tx |
| 214 | before interrupt */ |
| 215 | int sbdma_int_timeout; |
| 216 | /* # usec rx/tx interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | #endif |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 218 | void __iomem *sbdma_config0; /* DMA config register 0 */ |
| 219 | void __iomem *sbdma_config1; /* DMA config register 1 */ |
| 220 | void __iomem *sbdma_dscrbase; |
| 221 | /* descriptor base address */ |
| 222 | void __iomem *sbdma_dscrcnt; /* descriptor count register */ |
| 223 | void __iomem *sbdma_curdscr; /* current descriptor |
| 224 | address */ |
| 225 | void __iomem *sbdma_oodpktlost; |
| 226 | /* pkt drop (rx only) */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 227 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | /* |
| 229 | * This stuff is for maintenance of the ring |
| 230 | */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 231 | void *sbdma_dscrtable_unaligned; |
| 232 | struct sbdmadscr *sbdma_dscrtable; |
| 233 | /* base of descriptor table */ |
| 234 | struct sbdmadscr *sbdma_dscrtable_end; |
| 235 | /* end of descriptor table */ |
| 236 | struct sk_buff **sbdma_ctxtable; |
| 237 | /* context table, one |
| 238 | per descr */ |
| 239 | dma_addr_t sbdma_dscrtable_phys; |
| 240 | /* and also the phys addr */ |
| 241 | struct sbdmadscr *sbdma_addptr; /* next dscr for sw to add */ |
| 242 | struct sbdmadscr *sbdma_remptr; /* next dscr for sw |
| 243 | to remove */ |
| 244 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | |
| 247 | /********************************************************************** |
| 248 | * Ethernet softc structure |
| 249 | ********************************************************************* */ |
| 250 | |
| 251 | struct sbmac_softc { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | /* |
| 254 | * Linux-specific things |
| 255 | */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 256 | struct net_device *sbm_dev; /* pointer to linux device */ |
| 257 | struct napi_struct napi; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 258 | struct phy_device *phy_dev; /* the associated PHY device */ |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 259 | struct mii_bus *mii_bus; /* the MII bus */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 260 | int phy_irq[PHY_MAX_ADDR]; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 261 | spinlock_t sbm_lock; /* spin lock */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 262 | int sbm_devflags; /* current device flags */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /* |
| 265 | * Controller-specific things |
| 266 | */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 267 | void __iomem *sbm_base; /* MAC's base address */ |
| 268 | enum sbmac_state sbm_state; /* current state */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 269 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 270 | void __iomem *sbm_macenable; /* MAC Enable Register */ |
| 271 | void __iomem *sbm_maccfg; /* MAC Config Register */ |
| 272 | void __iomem *sbm_fifocfg; /* FIFO Config Register */ |
| 273 | void __iomem *sbm_framecfg; /* Frame Config Register */ |
| 274 | void __iomem *sbm_rxfilter; /* Receive Filter Register */ |
| 275 | void __iomem *sbm_isr; /* Interrupt Status Register */ |
| 276 | void __iomem *sbm_imr; /* Interrupt Mask Register */ |
| 277 | void __iomem *sbm_mdio; /* MDIO Register */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 278 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 279 | enum sbmac_speed sbm_speed; /* current speed */ |
| 280 | enum sbmac_duplex sbm_duplex; /* current duplex */ |
| 281 | enum sbmac_fc sbm_fc; /* cur. flow control setting */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 282 | int sbm_pause; /* current pause setting */ |
| 283 | int sbm_link; /* current link state */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 284 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 285 | unsigned char sbm_hwaddr[ETHER_ADDR_LEN]; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 286 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 287 | struct sbmacdma sbm_txdma; /* only channel 0 for now */ |
| 288 | struct sbmacdma sbm_rxdma; |
| 289 | int rx_hw_checksum; |
| 290 | int sbe_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
| 293 | |
| 294 | /********************************************************************** |
| 295 | * Externs |
| 296 | ********************************************************************* */ |
| 297 | |
| 298 | /********************************************************************** |
| 299 | * Prototypes |
| 300 | ********************************************************************* */ |
| 301 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 302 | static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan, |
| 303 | int txrx, int maxdescr); |
| 304 | static void sbdma_channel_start(struct sbmacdma *d, int rxtx); |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 305 | static int sbdma_add_rcvbuffer(struct sbmac_softc *sc, struct sbmacdma *d, |
| 306 | struct sk_buff *m); |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 307 | static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *m); |
| 308 | static void sbdma_emptyring(struct sbmacdma *d); |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 309 | static void sbdma_fillring(struct sbmac_softc *sc, struct sbmacdma *d); |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 310 | static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d, |
| 311 | int work_to_do, int poll); |
| 312 | static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d, |
| 313 | int poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | static int sbmac_initctx(struct sbmac_softc *s); |
| 315 | static void sbmac_channel_start(struct sbmac_softc *s); |
| 316 | static void sbmac_channel_stop(struct sbmac_softc *s); |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 317 | static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *, |
| 318 | enum sbmac_state); |
| 319 | static void sbmac_promiscuous_mode(struct sbmac_softc *sc, int onoff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | static uint64_t sbmac_addr2reg(unsigned char *ptr); |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 321 | static irqreturn_t sbmac_intr(int irq, void *dev_instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev); |
| 323 | static void sbmac_setmulti(struct sbmac_softc *sc); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 324 | static int sbmac_init(struct platform_device *pldev, long long base); |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 325 | static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed); |
| 326 | static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex, |
| 327 | enum sbmac_fc fc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | static int sbmac_open(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | static void sbmac_tx_timeout (struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | static void sbmac_set_rx_mode(struct net_device *dev); |
| 332 | static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); |
| 333 | static int sbmac_close(struct net_device *dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 334 | static int sbmac_poll(struct napi_struct *napi, int budget); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 335 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 336 | static void sbmac_mii_poll(struct net_device *dev); |
Ralf Baechle | 59b8182 | 2005-10-20 12:01:28 +0100 | [diff] [blame] | 337 | static int sbmac_mii_probe(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 339 | static void sbmac_mii_sync(void __iomem *sbm_mdio); |
| 340 | static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data, |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 341 | int bitcnt); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 342 | static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx); |
| 343 | static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx, |
| 344 | u16 val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | |
| 347 | /********************************************************************** |
| 348 | * Globals |
| 349 | ********************************************************************* */ |
| 350 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 351 | static char sbmac_string[] = "sb1250-mac"; |
| 352 | static char sbmac_pretty[] = "SB1250 MAC"; |
| 353 | |
| 354 | static char sbmac_mdio_string[] = "sb1250-mac-mdio"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | |
| 357 | /********************************************************************** |
| 358 | * MDIO constants |
| 359 | ********************************************************************* */ |
| 360 | |
| 361 | #define MII_COMMAND_START 0x01 |
| 362 | #define MII_COMMAND_READ 0x02 |
| 363 | #define MII_COMMAND_WRITE 0x01 |
| 364 | #define MII_COMMAND_ACK 0x02 |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | #define M_MAC_MDIO_DIR_OUTPUT 0 /* for clarity */ |
| 367 | |
| 368 | #define ENABLE 1 |
| 369 | #define DISABLE 0 |
| 370 | |
| 371 | /********************************************************************** |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 372 | * SBMAC_MII_SYNC(sbm_mdio) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 373 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | * Synchronize with the MII - send a pattern of bits to the MII |
| 375 | * that will guarantee that it is ready to accept a command. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 376 | * |
| 377 | * Input parameters: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 378 | * sbm_mdio - address of the MAC's MDIO register |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 379 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | * Return value: |
| 381 | * nothing |
| 382 | ********************************************************************* */ |
| 383 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 384 | static void sbmac_mii_sync(void __iomem *sbm_mdio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
| 386 | int cnt; |
| 387 | uint64_t bits; |
| 388 | int mac_mdio_genc; |
| 389 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 390 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | bits = M_MAC_MDIO_DIR_OUTPUT | M_MAC_MDIO_OUT; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 393 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 394 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | for (cnt = 0; cnt < 32; cnt++) { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 397 | __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio); |
| 398 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | /********************************************************************** |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 403 | * SBMAC_MII_SENDDATA(sbm_mdio, data, bitcnt) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 404 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | * Send some bits to the MII. The bits to be sent are right- |
| 406 | * justified in the 'data' parameter. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 407 | * |
| 408 | * Input parameters: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 409 | * sbm_mdio - address of the MAC's MDIO register |
| 410 | * data - data to send |
| 411 | * bitcnt - number of bits to send |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | ********************************************************************* */ |
| 413 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 414 | static void sbmac_mii_senddata(void __iomem *sbm_mdio, unsigned int data, |
| 415 | int bitcnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | { |
| 417 | int i; |
| 418 | uint64_t bits; |
| 419 | unsigned int curmask; |
| 420 | int mac_mdio_genc; |
| 421 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 422 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | bits = M_MAC_MDIO_DIR_OUTPUT; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 425 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | curmask = 1 << (bitcnt - 1); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | for (i = 0; i < bitcnt; i++) { |
| 430 | if (data & curmask) |
| 431 | bits |= M_MAC_MDIO_OUT; |
| 432 | else bits &= ~M_MAC_MDIO_OUT; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 433 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
| 434 | __raw_writeq(bits | M_MAC_MDC | mac_mdio_genc, sbm_mdio); |
| 435 | __raw_writeq(bits | mac_mdio_genc, sbm_mdio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | curmask >>= 1; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | |
| 441 | |
| 442 | /********************************************************************** |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 443 | * SBMAC_MII_READ(bus, phyaddr, regidx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | * Read a PHY register. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 445 | * |
| 446 | * Input parameters: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 447 | * bus - MDIO bus handle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | * phyaddr - PHY's address |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 449 | * regnum - index of register to read |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 450 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | * Return value: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 452 | * value read, or 0xffff if an error occurred. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | ********************************************************************* */ |
| 454 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 455 | static int sbmac_mii_read(struct mii_bus *bus, int phyaddr, int regidx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 457 | struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv; |
| 458 | void __iomem *sbm_mdio = sc->sbm_mdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | int idx; |
| 460 | int error; |
| 461 | int regval; |
| 462 | int mac_mdio_genc; |
| 463 | |
| 464 | /* |
| 465 | * Synchronize ourselves so that the PHY knows the next |
| 466 | * thing coming down is a command |
| 467 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 468 | sbmac_mii_sync(sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* |
| 471 | * Send the data to the PHY. The sequence is |
| 472 | * a "start" command (2 bits) |
| 473 | * a "read" command (2 bits) |
| 474 | * the PHY addr (5 bits) |
| 475 | * the register index (5 bits) |
| 476 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 477 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2); |
| 478 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_READ, 2); |
| 479 | sbmac_mii_senddata(sbm_mdio, phyaddr, 5); |
| 480 | sbmac_mii_senddata(sbm_mdio, regidx, 5); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 481 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 482 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 483 | |
| 484 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | * Switch the port around without a clock transition. |
| 486 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 487 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* |
| 490 | * Send out a clock pulse to signal we want the status |
| 491 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 492 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, |
| 493 | sbm_mdio); |
| 494 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 495 | |
| 496 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | * If an error occurred, the PHY will signal '1' back |
| 498 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 499 | error = __raw_readq(sbm_mdio) & M_MAC_MDIO_IN; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 500 | |
| 501 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | * Issue an 'idle' clock pulse, but keep the direction |
| 503 | * the same. |
| 504 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 505 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, |
| 506 | sbm_mdio); |
| 507 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | regval = 0; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | for (idx = 0; idx < 16; idx++) { |
| 512 | regval <<= 1; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | if (error == 0) { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 515 | if (__raw_readq(sbm_mdio) & M_MAC_MDIO_IN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | regval |= 1; |
| 517 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 518 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 519 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | M_MAC_MDC | mac_mdio_genc, |
| 520 | sbm_mdio); |
| 521 | __raw_writeq(M_MAC_MDIO_DIR_INPUT | mac_mdio_genc, sbm_mdio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | /* Switch back to output */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 525 | __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | if (error == 0) |
| 528 | return regval; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 529 | return 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | |
| 533 | /********************************************************************** |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 534 | * SBMAC_MII_WRITE(bus, phyaddr, regidx, regval) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 535 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | * Write a value to a PHY register. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 537 | * |
| 538 | * Input parameters: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 539 | * bus - MDIO bus handle |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | * phyaddr - PHY to use |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 541 | * regidx - register within the PHY |
| 542 | * regval - data to write to register |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 543 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | * Return value: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 545 | * 0 for success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | ********************************************************************* */ |
| 547 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 548 | static int sbmac_mii_write(struct mii_bus *bus, int phyaddr, int regidx, |
| 549 | u16 regval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 551 | struct sbmac_softc *sc = (struct sbmac_softc *)bus->priv; |
| 552 | void __iomem *sbm_mdio = sc->sbm_mdio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | int mac_mdio_genc; |
| 554 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 555 | sbmac_mii_sync(sbm_mdio); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 556 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 557 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_START, 2); |
| 558 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_WRITE, 2); |
| 559 | sbmac_mii_senddata(sbm_mdio, phyaddr, 5); |
| 560 | sbmac_mii_senddata(sbm_mdio, regidx, 5); |
| 561 | sbmac_mii_senddata(sbm_mdio, MII_COMMAND_ACK, 2); |
| 562 | sbmac_mii_senddata(sbm_mdio, regval, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 564 | mac_mdio_genc = __raw_readq(sbm_mdio) & M_MAC_GENC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 566 | __raw_writeq(M_MAC_MDIO_DIR_OUTPUT | mac_mdio_genc, sbm_mdio); |
| 567 | |
| 568 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | |
| 572 | |
| 573 | /********************************************************************** |
| 574 | * SBDMA_INITCTX(d,s,chan,txrx,maxdescr) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 575 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | * Initialize a DMA channel context. Since there are potentially |
| 577 | * eight DMA channels per MAC, it's nice to do this in a standard |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 578 | * way. |
| 579 | * |
| 580 | * Input parameters: |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 581 | * d - struct sbmacdma (DMA channel context) |
| 582 | * s - struct sbmac_softc (pointer to a MAC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | * chan - channel number (0..1 right now) |
| 584 | * txrx - Identifies DMA_TX or DMA_RX for channel direction |
| 585 | * maxdescr - number of descriptors |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 586 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | * Return value: |
| 588 | * nothing |
| 589 | ********************************************************************* */ |
| 590 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 591 | static void sbdma_initctx(struct sbmacdma *d, struct sbmac_softc *s, int chan, |
| 592 | int txrx, int maxdescr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 594 | #ifdef CONFIG_SBMAC_COALESCE |
| 595 | int int_pktcnt, int_timeout; |
| 596 | #endif |
| 597 | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 598 | /* |
| 599 | * Save away interesting stuff in the structure |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | d->sbdma_eth = s; |
| 603 | d->sbdma_channel = chan; |
| 604 | d->sbdma_txdir = txrx; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | #if 0 |
| 607 | /* RMON clearing */ |
| 608 | s->sbe_idx =(s->sbm_base - A_MAC_BASE_0)/MAC_SPACING; |
| 609 | #endif |
| 610 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 611 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BYTES); |
| 612 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_COLLISIONS); |
| 613 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_LATE_COL); |
| 614 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_EX_COL); |
| 615 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_FCS_ERROR); |
| 616 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_ABORT); |
| 617 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_BAD); |
| 618 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_GOOD); |
| 619 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_RUNT); |
| 620 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_TX_OVERSIZE); |
| 621 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BYTES); |
| 622 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_MCAST); |
| 623 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BCAST); |
| 624 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_BAD); |
| 625 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_GOOD); |
| 626 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_RUNT); |
| 627 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_OVERSIZE); |
| 628 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_FCS_ERROR); |
| 629 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_LENGTH_ERROR); |
| 630 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_CODE_ERROR); |
| 631 | __raw_writeq(0, s->sbm_base + R_MAC_RMON_RX_ALIGN_ERROR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 633 | /* |
| 634 | * initialize register pointers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 636 | |
| 637 | d->sbdma_config0 = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG0); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 639 | d->sbdma_config1 = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CONFIG1); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 641 | d->sbdma_dscrbase = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_BASE); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 643 | d->sbdma_dscrcnt = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_DSCR_CNT); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 645 | d->sbdma_curdscr = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_CUR_DSCRADDR); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 647 | if (d->sbdma_txdir) |
| 648 | d->sbdma_oodpktlost = NULL; |
| 649 | else |
| 650 | d->sbdma_oodpktlost = |
| 651 | s->sbm_base + R_MAC_DMA_REGISTER(txrx,chan,R_MAC_DMA_OODPKTLOST_RX); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 652 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | /* |
| 654 | * Allocate memory for the ring |
| 655 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | d->sbdma_maxdescr = maxdescr; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 658 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 659 | d->sbdma_dscrtable_unaligned = kcalloc(d->sbdma_maxdescr + 1, |
| 660 | sizeof(*d->sbdma_dscrtable), |
| 661 | GFP_KERNEL); |
Ralf Baechle | 04115de | 2005-10-10 14:50:36 +0100 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * The descriptor table must be aligned to at least 16 bytes or the |
| 665 | * MAC will corrupt it. |
| 666 | */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 667 | d->sbdma_dscrtable = (struct sbdmadscr *) |
| 668 | ALIGN((unsigned long)d->sbdma_dscrtable_unaligned, |
| 669 | sizeof(*d->sbdma_dscrtable)); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | d->sbdma_dscrtable_end = d->sbdma_dscrtable + d->sbdma_maxdescr; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | d->sbdma_dscrtable_phys = virt_to_phys(d->sbdma_dscrtable); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* |
| 676 | * And context table |
| 677 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 678 | |
Mariusz Kozlowski | c477f33 | 2007-07-31 23:58:36 +0200 | [diff] [blame] | 679 | d->sbdma_ctxtable = kcalloc(d->sbdma_maxdescr, |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 680 | sizeof(*d->sbdma_ctxtable), GFP_KERNEL); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | #ifdef CONFIG_SBMAC_COALESCE |
| 683 | /* |
| 684 | * Setup Rx/Tx DMA coalescing defaults |
| 685 | */ |
| 686 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 687 | int_pktcnt = (txrx == DMA_TX) ? int_pktcnt_tx : int_pktcnt_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | if ( int_pktcnt ) { |
| 689 | d->sbdma_int_pktcnt = int_pktcnt; |
| 690 | } else { |
| 691 | d->sbdma_int_pktcnt = 1; |
| 692 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 693 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 694 | int_timeout = (txrx == DMA_TX) ? int_timeout_tx : int_timeout_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | if ( int_timeout ) { |
| 696 | d->sbdma_int_timeout = int_timeout; |
| 697 | } else { |
| 698 | d->sbdma_int_timeout = 0; |
| 699 | } |
| 700 | #endif |
| 701 | |
| 702 | } |
| 703 | |
| 704 | /********************************************************************** |
| 705 | * SBDMA_CHANNEL_START(d) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 706 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | * Initialize the hardware registers for a DMA channel. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 708 | * |
| 709 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | * d - DMA channel to init (context must be previously init'd |
| 711 | * rxtx - DMA_RX or DMA_TX depending on what type of channel |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 712 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | * Return value: |
| 714 | * nothing |
| 715 | ********************************************************************* */ |
| 716 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 717 | static void sbdma_channel_start(struct sbmacdma *d, int rxtx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | { |
| 719 | /* |
| 720 | * Turn on the DMA channel |
| 721 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | #ifdef CONFIG_SBMAC_COALESCE |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 724 | __raw_writeq(V_DMA_INT_TIMEOUT(d->sbdma_int_timeout) | |
| 725 | 0, d->sbdma_config1); |
| 726 | __raw_writeq(M_DMA_EOP_INT_EN | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | V_DMA_RINGSZ(d->sbdma_maxdescr) | |
| 728 | V_DMA_INT_PKTCNT(d->sbdma_int_pktcnt) | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 729 | 0, d->sbdma_config0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | #else |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 731 | __raw_writeq(0, d->sbdma_config1); |
| 732 | __raw_writeq(V_DMA_RINGSZ(d->sbdma_maxdescr) | |
| 733 | 0, d->sbdma_config0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | #endif |
| 735 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 736 | __raw_writeq(d->sbdma_dscrtable_phys, d->sbdma_dscrbase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
| 738 | /* |
| 739 | * Initialize ring pointers |
| 740 | */ |
| 741 | |
| 742 | d->sbdma_addptr = d->sbdma_dscrtable; |
| 743 | d->sbdma_remptr = d->sbdma_dscrtable; |
| 744 | } |
| 745 | |
| 746 | /********************************************************************** |
| 747 | * SBDMA_CHANNEL_STOP(d) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 748 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | * Initialize the hardware registers for a DMA channel. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 750 | * |
| 751 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | * d - DMA channel to init (context must be previously init'd |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 753 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | * Return value: |
| 755 | * nothing |
| 756 | ********************************************************************* */ |
| 757 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 758 | static void sbdma_channel_stop(struct sbmacdma *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
| 760 | /* |
| 761 | * Turn off the DMA channel |
| 762 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 763 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 764 | __raw_writeq(0, d->sbdma_config1); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 765 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 766 | __raw_writeq(0, d->sbdma_dscrbase); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 767 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 768 | __raw_writeq(0, d->sbdma_config0); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 769 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | /* |
| 771 | * Zero ring pointers |
| 772 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 773 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 774 | d->sbdma_addptr = NULL; |
| 775 | d->sbdma_remptr = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 778 | static inline void sbdma_align_skb(struct sk_buff *skb, |
| 779 | unsigned int power2, unsigned int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 781 | unsigned char *addr = skb->data; |
| 782 | unsigned char *newaddr = PTR_ALIGN(addr, power2); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 783 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 784 | skb_reserve(skb, newaddr - addr + offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | |
| 788 | /********************************************************************** |
| 789 | * SBDMA_ADD_RCVBUFFER(d,sb) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 790 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | * Add a buffer to the specified DMA channel. For receive channels, |
| 792 | * this queues a buffer for inbound packets. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 793 | * |
| 794 | * Input parameters: |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 795 | * sc - softc structure |
| 796 | * d - DMA channel descriptor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | * sb - sk_buff to add, or NULL if we should allocate one |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 798 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | * Return value: |
| 800 | * 0 if buffer could not be added (ring is full) |
| 801 | * 1 if buffer added successfully |
| 802 | ********************************************************************* */ |
| 803 | |
| 804 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 805 | static int sbdma_add_rcvbuffer(struct sbmac_softc *sc, struct sbmacdma *d, |
| 806 | struct sk_buff *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | { |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 808 | struct net_device *dev = sc->sbm_dev; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 809 | struct sbdmadscr *dsc; |
| 810 | struct sbdmadscr *nextdsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | struct sk_buff *sb_new = NULL; |
| 812 | int pktsize = ENET_PACKET_SIZE; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | /* get pointer to our current place in the ring */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 815 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | dsc = d->sbdma_addptr; |
| 817 | nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | /* |
| 820 | * figure out if the ring is full - if the next descriptor |
| 821 | * is the same as the one that we're going to remove from |
| 822 | * the ring, the ring is full |
| 823 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | if (nextdsc == d->sbdma_remptr) { |
| 826 | return -ENOSPC; |
| 827 | } |
| 828 | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 829 | /* |
| 830 | * Allocate a sk_buff if we don't already have one. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | * If we do have an sk_buff, reset it so that it's empty. |
| 832 | * |
| 833 | * Note: sk_buffs don't seem to be guaranteed to have any sort |
| 834 | * of alignment when they are allocated. Therefore, allocate enough |
| 835 | * extra space to make sure that: |
| 836 | * |
| 837 | * 1. the data does not start in the middle of a cache line. |
| 838 | * 2. The data does not end in the middle of a cache line |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 839 | * 3. The buffer can be aligned such that the IP addresses are |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | * naturally aligned. |
| 841 | * |
| 842 | * Remember, the SOCs MAC writes whole cache lines at a time, |
| 843 | * without reading the old contents first. So, if the sk_buff's |
| 844 | * data portion starts in the middle of a cache line, the SOC |
| 845 | * DMA will trash the beginning (and ending) portions. |
| 846 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | if (sb == NULL) { |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 849 | sb_new = netdev_alloc_skb(dev, ENET_PACKET_SIZE + |
| 850 | SMP_CACHE_BYTES * 2 + |
| 851 | NET_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if (sb_new == NULL) { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 853 | pr_info("%s: sk_buff allocation failed\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | d->sbdma_eth->sbm_dev->name); |
| 855 | return -ENOBUFS; |
| 856 | } |
| 857 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 858 | sbdma_align_skb(sb_new, SMP_CACHE_BYTES, NET_IP_ALIGN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | else { |
| 861 | sb_new = sb; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 862 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | * nothing special to reinit buffer, it's already aligned |
| 864 | * and sb->data already points to a good place. |
| 865 | */ |
| 866 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 869 | * fill in the descriptor |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | #ifdef CONFIG_SBMAC_COALESCE |
| 873 | /* |
| 874 | * Do not interrupt per DMA transfer. |
| 875 | */ |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 876 | dsc->dscr_a = virt_to_phys(sb_new->data) | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 877 | V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize + NET_IP_ALIGN)) | 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | #else |
David S. Miller | 689be43 | 2005-06-28 15:25:31 -0700 | [diff] [blame] | 879 | dsc->dscr_a = virt_to_phys(sb_new->data) | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 880 | V_DMA_DSCRA_A_SIZE(NUMCACHEBLKS(pktsize + NET_IP_ALIGN)) | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | M_DMA_DSCRA_INTERRUPT; |
| 882 | #endif |
| 883 | |
| 884 | /* receiving: no options */ |
| 885 | dsc->dscr_b = 0; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 888 | * fill in the context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb_new; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 892 | |
| 893 | /* |
| 894 | * point at next packet |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 896 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | d->sbdma_addptr = nextdsc; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 898 | |
| 899 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | * Give the buffer to the DMA engine. |
| 901 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 902 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 903 | __raw_writeq(1, d->sbdma_dscrcnt); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return 0; /* we did it */ |
| 906 | } |
| 907 | |
| 908 | /********************************************************************** |
| 909 | * SBDMA_ADD_TXBUFFER(d,sb) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 910 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | * Add a transmit buffer to the specified DMA channel, causing a |
| 912 | * transmit to start. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 913 | * |
| 914 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | * d - DMA channel descriptor |
| 916 | * sb - sk_buff to add |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 917 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | * Return value: |
| 919 | * 0 transmit queued successfully |
| 920 | * otherwise error code |
| 921 | ********************************************************************* */ |
| 922 | |
| 923 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 924 | static int sbdma_add_txbuffer(struct sbmacdma *d, struct sk_buff *sb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | { |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 926 | struct sbdmadscr *dsc; |
| 927 | struct sbdmadscr *nextdsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | uint64_t phys; |
| 929 | uint64_t ncb; |
| 930 | int length; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | /* get pointer to our current place in the ring */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 933 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | dsc = d->sbdma_addptr; |
| 935 | nextdsc = SBDMA_NEXTBUF(d,sbdma_addptr); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | /* |
| 938 | * figure out if the ring is full - if the next descriptor |
| 939 | * is the same as the one that we're going to remove from |
| 940 | * the ring, the ring is full |
| 941 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 942 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | if (nextdsc == d->sbdma_remptr) { |
| 944 | return -ENOSPC; |
| 945 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | /* |
| 948 | * Under Linux, it's not necessary to copy/coalesce buffers |
| 949 | * like it is on NetBSD. We think they're all contiguous, |
| 950 | * but that may not be true for GBE. |
| 951 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | length = sb->len; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | /* |
| 956 | * fill in the descriptor. Note that the number of cache |
| 957 | * blocks in the descriptor is the number of blocks |
| 958 | * *spanned*, so we need to add in the offset (if any) |
| 959 | * while doing the calculation. |
| 960 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | phys = virt_to_phys(sb->data); |
| 963 | ncb = NUMCACHEBLKS(length+(phys & (SMP_CACHE_BYTES - 1))); |
| 964 | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 965 | dsc->dscr_a = phys | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | V_DMA_DSCRA_A_SIZE(ncb) | |
| 967 | #ifndef CONFIG_SBMAC_COALESCE |
| 968 | M_DMA_DSCRA_INTERRUPT | |
| 969 | #endif |
| 970 | M_DMA_ETHTX_SOP; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | /* transmitting: set outbound options and length */ |
| 973 | |
| 974 | dsc->dscr_b = V_DMA_DSCRB_OPTIONS(K_DMA_ETHTX_APPENDCRC_APPENDPAD) | |
| 975 | V_DMA_DSCRB_PKT_SIZE(length); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 978 | * fill in the context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 980 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | d->sbdma_ctxtable[dsc-d->sbdma_dscrtable] = sb; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 982 | |
| 983 | /* |
| 984 | * point at next packet |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 986 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | d->sbdma_addptr = nextdsc; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 988 | |
| 989 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | * Give the buffer to the DMA engine. |
| 991 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 992 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 993 | __raw_writeq(1, d->sbdma_dscrcnt); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 994 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | return 0; /* we did it */ |
| 996 | } |
| 997 | |
| 998 | |
| 999 | |
| 1000 | |
| 1001 | /********************************************************************** |
| 1002 | * SBDMA_EMPTYRING(d) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1003 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | * Free all allocated sk_buffs on the specified DMA channel; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1005 | * |
| 1006 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | * d - DMA channel |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1008 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | * Return value: |
| 1010 | * nothing |
| 1011 | ********************************************************************* */ |
| 1012 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1013 | static void sbdma_emptyring(struct sbmacdma *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | { |
| 1015 | int idx; |
| 1016 | struct sk_buff *sb; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | for (idx = 0; idx < d->sbdma_maxdescr; idx++) { |
| 1019 | sb = d->sbdma_ctxtable[idx]; |
| 1020 | if (sb) { |
| 1021 | dev_kfree_skb(sb); |
| 1022 | d->sbdma_ctxtable[idx] = NULL; |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | |
| 1028 | /********************************************************************** |
| 1029 | * SBDMA_FILLRING(d) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1030 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | * Fill the specified DMA channel (must be receive channel) |
| 1032 | * with sk_buffs |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1033 | * |
| 1034 | * Input parameters: |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1035 | * sc - softc structure |
| 1036 | * d - DMA channel |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1037 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | * Return value: |
| 1039 | * nothing |
| 1040 | ********************************************************************* */ |
| 1041 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1042 | static void sbdma_fillring(struct sbmac_softc *sc, struct sbmacdma *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | { |
| 1044 | int idx; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1045 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1046 | for (idx = 0; idx < SBMAC_MAX_RXDESCR - 1; idx++) { |
| 1047 | if (sbdma_add_rcvbuffer(sc, d, NULL) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | |
Deepak Saxena | d683001 | 2007-03-19 15:43:11 -0700 | [diff] [blame] | 1052 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1053 | static void sbmac_netpoll(struct net_device *netdev) |
| 1054 | { |
| 1055 | struct sbmac_softc *sc = netdev_priv(netdev); |
| 1056 | int irq = sc->sbm_dev->irq; |
| 1057 | |
| 1058 | __raw_writeq(0, sc->sbm_imr); |
| 1059 | |
Yoann Padioleau | 0da2f0f | 2007-07-06 02:39:56 -0700 | [diff] [blame] | 1060 | sbmac_intr(irq, netdev); |
Deepak Saxena | d683001 | 2007-03-19 15:43:11 -0700 | [diff] [blame] | 1061 | |
| 1062 | #ifdef CONFIG_SBMAC_COALESCE |
| 1063 | __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | |
| 1064 | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), |
| 1065 | sc->sbm_imr); |
| 1066 | #else |
Jeff Garzik | 7d2e3cb | 2008-05-13 01:41:58 -0400 | [diff] [blame] | 1067 | __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | |
Deepak Saxena | d683001 | 2007-03-19 15:43:11 -0700 | [diff] [blame] | 1068 | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr); |
| 1069 | #endif |
| 1070 | } |
| 1071 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
| 1073 | /********************************************************************** |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1074 | * SBDMA_RX_PROCESS(sc,d,work_to_do,poll) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | * |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1076 | * Process "completed" receive buffers on the specified DMA channel. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1077 | * |
| 1078 | * Input parameters: |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1079 | * sc - softc structure |
| 1080 | * d - DMA channel context |
| 1081 | * work_to_do - no. of packets to process before enabling interrupt |
| 1082 | * again (for NAPI) |
| 1083 | * poll - 1: using polling (for NAPI) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1084 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | * Return value: |
| 1086 | * nothing |
| 1087 | ********************************************************************* */ |
| 1088 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1089 | static int sbdma_rx_process(struct sbmac_softc *sc, struct sbmacdma *d, |
| 1090 | int work_to_do, int poll) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1092 | struct net_device *dev = sc->sbm_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | int curidx; |
| 1094 | int hwidx; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1095 | struct sbdmadscr *dsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | struct sk_buff *sb; |
| 1097 | int len; |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1098 | int work_done = 0; |
| 1099 | int dropped = 0; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1100 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1101 | prefetch(d); |
| 1102 | |
| 1103 | again: |
| 1104 | /* Check if the HW dropped any frames */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1105 | dev->stats.rx_fifo_errors |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1106 | += __raw_readq(sc->sbm_rxdma.sbdma_oodpktlost) & 0xffff; |
| 1107 | __raw_writeq(0, sc->sbm_rxdma.sbdma_oodpktlost); |
| 1108 | |
| 1109 | while (work_to_do-- > 0) { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1110 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | * figure out where we are (as an index) and where |
| 1112 | * the hardware is (also as an index) |
| 1113 | * |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1114 | * This could be done faster if (for example) the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | * descriptor table was page-aligned and contiguous in |
| 1116 | * both virtual and physical memory -- you could then |
| 1117 | * just compare the low-order bits of the virtual address |
| 1118 | * (sbdma_remptr) and the physical address (sbdma_curdscr CSR) |
| 1119 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1120 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1121 | dsc = d->sbdma_remptr; |
| 1122 | curidx = dsc - d->sbdma_dscrtable; |
| 1123 | |
| 1124 | prefetch(dsc); |
| 1125 | prefetch(&d->sbdma_ctxtable[curidx]); |
| 1126 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1127 | hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) - |
| 1128 | d->sbdma_dscrtable_phys) / |
| 1129 | sizeof(*d->sbdma_dscrtable); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | /* |
| 1132 | * If they're the same, that means we've processed all |
| 1133 | * of the descriptors up to (but not including) the one that |
| 1134 | * the hardware is working on right now. |
| 1135 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | if (curidx == hwidx) |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1138 | goto done; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | /* |
| 1141 | * Otherwise, get the packet's sk_buff ptr back |
| 1142 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | sb = d->sbdma_ctxtable[curidx]; |
| 1145 | d->sbdma_ctxtable[curidx] = NULL; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | len = (int)G_DMA_DSCRB_PKT_SIZE(dsc->dscr_b) - 4; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | /* |
| 1150 | * Check packet status. If good, process it. |
| 1151 | * If not, silently drop it and put it back on the |
| 1152 | * receive ring. |
| 1153 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1154 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1155 | if (likely (!(dsc->dscr_a & M_DMA_ETHRX_BAD))) { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | /* |
| 1158 | * Add a new buffer to replace the old one. If we fail |
| 1159 | * to allocate a buffer, we're going to drop this |
| 1160 | * packet and put it right back on the receive ring. |
| 1161 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1162 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1163 | if (unlikely(sbdma_add_rcvbuffer(sc, d, NULL) == |
| 1164 | -ENOBUFS)) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1165 | dev->stats.rx_dropped++; |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1166 | /* Re-add old buffer */ |
| 1167 | sbdma_add_rcvbuffer(sc, d, sb); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1168 | /* No point in continuing at the moment */ |
| 1169 | printk(KERN_ERR "dropped packet (1)\n"); |
| 1170 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); |
| 1171 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } else { |
| 1173 | /* |
| 1174 | * Set length into the packet |
| 1175 | */ |
| 1176 | skb_put(sb,len); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | /* |
| 1179 | * Buffer has been replaced on the |
| 1180 | * receive ring. Pass the buffer to |
| 1181 | * the kernel |
| 1182 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | sb->protocol = eth_type_trans(sb,d->sbdma_eth->sbm_dev); |
| 1184 | /* Check hw IPv4/TCP checksum if supported */ |
| 1185 | if (sc->rx_hw_checksum == ENABLE) { |
| 1186 | if (!((dsc->dscr_a) & M_DMA_ETHRX_BADIP4CS) && |
| 1187 | !((dsc->dscr_a) & M_DMA_ETHRX_BADTCPCS)) { |
| 1188 | sb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1189 | /* don't need to set sb->csum */ |
| 1190 | } else { |
| 1191 | sb->ip_summed = CHECKSUM_NONE; |
| 1192 | } |
| 1193 | } |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1194 | prefetch(sb->data); |
| 1195 | prefetch((const void *)(((char *)sb->data)+32)); |
| 1196 | if (poll) |
| 1197 | dropped = netif_receive_skb(sb); |
| 1198 | else |
| 1199 | dropped = netif_rx(sb); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1200 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1201 | if (dropped == NET_RX_DROP) { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1202 | dev->stats.rx_dropped++; |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1203 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); |
| 1204 | goto done; |
| 1205 | } |
| 1206 | else { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1207 | dev->stats.rx_bytes += len; |
| 1208 | dev->stats.rx_packets++; |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } else { |
| 1212 | /* |
| 1213 | * Packet was mangled somehow. Just drop it and |
| 1214 | * put it back on the receive ring. |
| 1215 | */ |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1216 | dev->stats.rx_errors++; |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1217 | sbdma_add_rcvbuffer(sc, d, sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1219 | |
| 1220 | |
| 1221 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | * .. and advance to the next buffer. |
| 1223 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1226 | work_done++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | } |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1228 | if (!poll) { |
| 1229 | work_to_do = 32; |
| 1230 | goto again; /* collect fifo drop statistics again */ |
| 1231 | } |
| 1232 | done: |
| 1233 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | /********************************************************************** |
| 1237 | * SBDMA_TX_PROCESS(sc,d) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1238 | * |
| 1239 | * Process "completed" transmit buffers on the specified DMA channel. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | * This is normally called within the interrupt service routine. |
| 1241 | * Note that this isn't really ideal for priority channels, since |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1242 | * it processes all of the packets on a given channel before |
| 1243 | * returning. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | * |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1245 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | * sc - softc structure |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1247 | * d - DMA channel context |
| 1248 | * poll - 1: using polling (for NAPI) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1249 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | * Return value: |
| 1251 | * nothing |
| 1252 | ********************************************************************* */ |
| 1253 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1254 | static void sbdma_tx_process(struct sbmac_softc *sc, struct sbmacdma *d, |
| 1255 | int poll) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | { |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1257 | struct net_device *dev = sc->sbm_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | int curidx; |
| 1259 | int hwidx; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1260 | struct sbdmadscr *dsc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | struct sk_buff *sb; |
| 1262 | unsigned long flags; |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1263 | int packets_handled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
| 1265 | spin_lock_irqsave(&(sc->sbm_lock), flags); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1266 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1267 | if (d->sbdma_remptr == d->sbdma_addptr) |
| 1268 | goto end_unlock; |
| 1269 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1270 | hwidx = ((__raw_readq(d->sbdma_curdscr) & M_DMA_CURDSCR_ADDR) - |
| 1271 | d->sbdma_dscrtable_phys) / sizeof(*d->sbdma_dscrtable); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | for (;;) { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1274 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | * figure out where we are (as an index) and where |
| 1276 | * the hardware is (also as an index) |
| 1277 | * |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1278 | * This could be done faster if (for example) the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | * descriptor table was page-aligned and contiguous in |
| 1280 | * both virtual and physical memory -- you could then |
| 1281 | * just compare the low-order bits of the virtual address |
| 1282 | * (sbdma_remptr) and the physical address (sbdma_curdscr CSR) |
| 1283 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | curidx = d->sbdma_remptr - d->sbdma_dscrtable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
| 1287 | /* |
| 1288 | * If they're the same, that means we've processed all |
| 1289 | * of the descriptors up to (but not including) the one that |
| 1290 | * the hardware is working on right now. |
| 1291 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1292 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | if (curidx == hwidx) |
| 1294 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | /* |
| 1297 | * Otherwise, get the packet's sk_buff ptr back |
| 1298 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1299 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | dsc = &(d->sbdma_dscrtable[curidx]); |
| 1301 | sb = d->sbdma_ctxtable[curidx]; |
| 1302 | d->sbdma_ctxtable[curidx] = NULL; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | /* |
| 1305 | * Stats |
| 1306 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1307 | |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 1308 | dev->stats.tx_bytes += sb->len; |
| 1309 | dev->stats.tx_packets++; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | /* |
| 1312 | * for transmits, we just free buffers. |
| 1313 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | dev_kfree_skb_irq(sb); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1316 | |
| 1317 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | * .. and advance to the next buffer. |
| 1319 | */ |
| 1320 | |
| 1321 | d->sbdma_remptr = SBDMA_NEXTBUF(d,sbdma_remptr); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1322 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1323 | packets_handled++; |
| 1324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | /* |
| 1328 | * Decide if we should wake up the protocol or not. |
| 1329 | * Other drivers seem to do this when we reach a low |
| 1330 | * watermark on the transmit queue. |
| 1331 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1332 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1333 | if (packets_handled) |
| 1334 | netif_wake_queue(d->sbdma_eth->sbm_dev); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1335 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1336 | end_unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | spin_unlock_irqrestore(&(sc->sbm_lock), flags); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | /********************************************************************** |
| 1344 | * SBMAC_INITCTX(s) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1345 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | * Initialize an Ethernet context structure - this is called |
| 1347 | * once per MAC on the 1250. Memory is allocated here, so don't |
| 1348 | * call it again from inside the ioctl routines that bring the |
| 1349 | * interface up/down |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1350 | * |
| 1351 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | * s - sbmac context structure |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1353 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | * Return value: |
| 1355 | * 0 |
| 1356 | ********************************************************************* */ |
| 1357 | |
| 1358 | static int sbmac_initctx(struct sbmac_softc *s) |
| 1359 | { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1360 | |
| 1361 | /* |
| 1362 | * figure out the addresses of some ports |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | s->sbm_macenable = s->sbm_base + R_MAC_ENABLE; |
| 1366 | s->sbm_maccfg = s->sbm_base + R_MAC_CFG; |
| 1367 | s->sbm_fifocfg = s->sbm_base + R_MAC_THRSH_CFG; |
| 1368 | s->sbm_framecfg = s->sbm_base + R_MAC_FRAMECFG; |
| 1369 | s->sbm_rxfilter = s->sbm_base + R_MAC_ADFILTER_CFG; |
| 1370 | s->sbm_isr = s->sbm_base + R_MAC_STATUS; |
| 1371 | s->sbm_imr = s->sbm_base + R_MAC_INT_MASK; |
| 1372 | s->sbm_mdio = s->sbm_base + R_MAC_MDIO; |
| 1373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | /* |
| 1375 | * Initialize the DMA channels. Right now, only one per MAC is used |
| 1376 | * Note: Only do this _once_, as it allocates memory from the kernel! |
| 1377 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | sbdma_initctx(&(s->sbm_txdma),s,0,DMA_TX,SBMAC_MAX_TXDESCR); |
| 1380 | sbdma_initctx(&(s->sbm_rxdma),s,0,DMA_RX,SBMAC_MAX_RXDESCR); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | /* |
| 1383 | * initial state is OFF |
| 1384 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | s->sbm_state = sbmac_state_off; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1387 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | return 0; |
| 1389 | } |
| 1390 | |
| 1391 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1392 | static void sbdma_uninitctx(struct sbmacdma *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | { |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 1394 | if (d->sbdma_dscrtable_unaligned) { |
| 1395 | kfree(d->sbdma_dscrtable_unaligned); |
| 1396 | d->sbdma_dscrtable_unaligned = d->sbdma_dscrtable = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | if (d->sbdma_ctxtable) { |
| 1400 | kfree(d->sbdma_ctxtable); |
| 1401 | d->sbdma_ctxtable = NULL; |
| 1402 | } |
| 1403 | } |
| 1404 | |
| 1405 | |
| 1406 | static void sbmac_uninitctx(struct sbmac_softc *sc) |
| 1407 | { |
| 1408 | sbdma_uninitctx(&(sc->sbm_txdma)); |
| 1409 | sbdma_uninitctx(&(sc->sbm_rxdma)); |
| 1410 | } |
| 1411 | |
| 1412 | |
| 1413 | /********************************************************************** |
| 1414 | * SBMAC_CHANNEL_START(s) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1415 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | * Start packet processing on this MAC. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1417 | * |
| 1418 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | * s - sbmac structure |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1420 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | * Return value: |
| 1422 | * nothing |
| 1423 | ********************************************************************* */ |
| 1424 | |
| 1425 | static void sbmac_channel_start(struct sbmac_softc *s) |
| 1426 | { |
| 1427 | uint64_t reg; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1428 | void __iomem *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | uint64_t cfg,fifo,framecfg; |
| 1430 | int idx, th_value; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | /* |
| 1433 | * Don't do this if running |
| 1434 | */ |
| 1435 | |
| 1436 | if (s->sbm_state == sbmac_state_on) |
| 1437 | return; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | /* |
| 1440 | * Bring the controller out of reset, but leave it off. |
| 1441 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1442 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1443 | __raw_writeq(0, s->sbm_macenable); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | /* |
| 1446 | * Ignore all received packets |
| 1447 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1448 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1449 | __raw_writeq(0, s->sbm_rxfilter); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1450 | |
| 1451 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | * Calculate values for various control registers. |
| 1453 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | cfg = M_MAC_RETRY_EN | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1456 | M_MAC_TX_HOLD_SOP_EN | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | V_MAC_TX_PAUSE_CNT_16K | |
| 1458 | M_MAC_AP_STAT_EN | |
| 1459 | M_MAC_FAST_SYNC | |
| 1460 | M_MAC_SS_EN | |
| 1461 | 0; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1462 | |
| 1463 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | * Be sure that RD_THRSH+WR_THRSH <= 32 for pass1 pars |
| 1465 | * and make sure that RD_THRSH + WR_THRSH <=128 for pass2 and above |
| 1466 | * Use a larger RD_THRSH for gigabit |
| 1467 | */ |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 1468 | if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | th_value = 28; |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 1470 | else |
| 1471 | th_value = 64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
| 1473 | fifo = V_MAC_TX_WR_THRSH(4) | /* Must be '4' or '8' */ |
| 1474 | ((s->sbm_speed == sbmac_speed_1000) |
| 1475 | ? V_MAC_TX_RD_THRSH(th_value) : V_MAC_TX_RD_THRSH(4)) | |
| 1476 | V_MAC_TX_RL_THRSH(4) | |
| 1477 | V_MAC_RX_PL_THRSH(4) | |
| 1478 | V_MAC_RX_RD_THRSH(4) | /* Must be '4' */ |
| 1479 | V_MAC_RX_PL_THRSH(4) | |
| 1480 | V_MAC_RX_RL_THRSH(8) | |
| 1481 | 0; |
| 1482 | |
| 1483 | framecfg = V_MAC_MIN_FRAMESZ_DEFAULT | |
| 1484 | V_MAC_MAX_FRAMESZ_DEFAULT | |
| 1485 | V_MAC_BACKOFF_SEL(1); |
| 1486 | |
| 1487 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1488 | * Clear out the hash address map |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1490 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | port = s->sbm_base + R_MAC_HASH_BASE; |
| 1492 | for (idx = 0; idx < MAC_HASH_COUNT; idx++) { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1493 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | port += sizeof(uint64_t); |
| 1495 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | /* |
| 1498 | * Clear out the exact-match table |
| 1499 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | port = s->sbm_base + R_MAC_ADDR_BASE; |
| 1502 | for (idx = 0; idx < MAC_ADDR_COUNT; idx++) { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1503 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | port += sizeof(uint64_t); |
| 1505 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | /* |
| 1508 | * Clear out the DMA Channel mapping table registers |
| 1509 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | port = s->sbm_base + R_MAC_CHUP0_BASE; |
| 1512 | for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1513 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | port += sizeof(uint64_t); |
| 1515 | } |
| 1516 | |
| 1517 | |
| 1518 | port = s->sbm_base + R_MAC_CHLO0_BASE; |
| 1519 | for (idx = 0; idx < MAC_CHMAP_COUNT; idx++) { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1520 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | port += sizeof(uint64_t); |
| 1522 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1523 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | /* |
| 1525 | * Program the hardware address. It goes into the hardware-address |
| 1526 | * register as well as the first filter register. |
| 1527 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1528 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | reg = sbmac_addr2reg(s->sbm_hwaddr); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | port = s->sbm_base + R_MAC_ADDR_BASE; |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1532 | __raw_writeq(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | port = s->sbm_base + R_MAC_ETHERNET_ADDR; |
| 1534 | |
| 1535 | #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS |
| 1536 | /* |
| 1537 | * Pass1 SOCs do not receive packets addressed to the |
| 1538 | * destination address in the R_MAC_ETHERNET_ADDR register. |
| 1539 | * Set the value to zero. |
| 1540 | */ |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1541 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | #else |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1543 | __raw_writeq(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | #endif |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | /* |
| 1547 | * Set the receive filter for no packets, and write values |
| 1548 | * to the various config registers |
| 1549 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1550 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1551 | __raw_writeq(0, s->sbm_rxfilter); |
| 1552 | __raw_writeq(0, s->sbm_imr); |
| 1553 | __raw_writeq(framecfg, s->sbm_framecfg); |
| 1554 | __raw_writeq(fifo, s->sbm_fifocfg); |
| 1555 | __raw_writeq(cfg, s->sbm_maccfg); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | /* |
| 1558 | * Initialize DMA channels (rings should be ok now) |
| 1559 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | sbdma_channel_start(&(s->sbm_rxdma), DMA_RX); |
| 1562 | sbdma_channel_start(&(s->sbm_txdma), DMA_TX); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | /* |
| 1565 | * Configure the speed, duplex, and flow control |
| 1566 | */ |
| 1567 | |
| 1568 | sbmac_set_speed(s,s->sbm_speed); |
| 1569 | sbmac_set_duplex(s,s->sbm_duplex,s->sbm_fc); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | /* |
| 1572 | * Fill the receive ring |
| 1573 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1574 | |
Stephen Hemminger | 789585e | 2008-05-18 04:45:09 +0100 | [diff] [blame] | 1575 | sbdma_fillring(s, &(s->sbm_rxdma)); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1576 | |
| 1577 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | * Turn on the rest of the bits in the enable register |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1579 | */ |
| 1580 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 1581 | #if defined(CONFIG_SIBYTE_BCM1x55) || defined(CONFIG_SIBYTE_BCM1x80) |
| 1582 | __raw_writeq(M_MAC_RXDMA_EN0 | |
| 1583 | M_MAC_TXDMA_EN0, s->sbm_macenable); |
| 1584 | #elif defined(CONFIG_SIBYTE_SB1250) || defined(CONFIG_SIBYTE_BCM112X) |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1585 | __raw_writeq(M_MAC_RXDMA_EN0 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | M_MAC_TXDMA_EN0 | |
| 1587 | M_MAC_RX_ENABLE | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1588 | M_MAC_TX_ENABLE, s->sbm_macenable); |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 1589 | #else |
| 1590 | #error invalid SiByte MAC configuation |
| 1591 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
| 1593 | #ifdef CONFIG_SBMAC_COALESCE |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1594 | __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | |
| 1595 | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), s->sbm_imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | #else |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1597 | __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | |
| 1598 | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), s->sbm_imr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | #endif |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1602 | * Enable receiving unicasts and broadcasts |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1604 | |
| 1605 | __raw_writeq(M_MAC_UCAST_EN | M_MAC_BCAST_EN, s->sbm_rxfilter); |
| 1606 | |
| 1607 | /* |
| 1608 | * we're running now. |
| 1609 | */ |
| 1610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | s->sbm_state = sbmac_state_on; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1612 | |
| 1613 | /* |
| 1614 | * Program multicast addresses |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | sbmac_setmulti(s); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1618 | |
| 1619 | /* |
| 1620 | * If channel was in promiscuous mode before, turn that on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | if (s->sbm_devflags & IFF_PROMISC) { |
| 1624 | sbmac_promiscuous_mode(s,1); |
| 1625 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | |
| 1630 | /********************************************************************** |
| 1631 | * SBMAC_CHANNEL_STOP(s) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1632 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | * Stop packet processing on this MAC. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1634 | * |
| 1635 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | * s - sbmac structure |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1637 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | * Return value: |
| 1639 | * nothing |
| 1640 | ********************************************************************* */ |
| 1641 | |
| 1642 | static void sbmac_channel_stop(struct sbmac_softc *s) |
| 1643 | { |
| 1644 | /* don't do this if already stopped */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | if (s->sbm_state == sbmac_state_off) |
| 1647 | return; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1649 | /* don't accept any packets, disable all interrupts */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1650 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1651 | __raw_writeq(0, s->sbm_rxfilter); |
| 1652 | __raw_writeq(0, s->sbm_imr); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | /* Turn off ticker */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | /* XXX */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | /* turn off receiver and transmitter */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1659 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1660 | __raw_writeq(0, s->sbm_macenable); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | /* We're stopped now. */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1663 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | s->sbm_state = sbmac_state_off; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | /* |
| 1667 | * Stop DMA channels (rings should be ok now) |
| 1668 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | sbdma_channel_stop(&(s->sbm_rxdma)); |
| 1671 | sbdma_channel_stop(&(s->sbm_txdma)); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | /* Empty the receive and transmit rings */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | sbdma_emptyring(&(s->sbm_rxdma)); |
| 1676 | sbdma_emptyring(&(s->sbm_txdma)); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | } |
| 1679 | |
| 1680 | /********************************************************************** |
| 1681 | * SBMAC_SET_CHANNEL_STATE(state) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1682 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | * Set the channel's state ON or OFF |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1684 | * |
| 1685 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | * state - new state |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1687 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | * Return value: |
| 1689 | * old state |
| 1690 | ********************************************************************* */ |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1691 | static enum sbmac_state sbmac_set_channel_state(struct sbmac_softc *sc, |
| 1692 | enum sbmac_state state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | { |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1694 | enum sbmac_state oldstate = sc->sbm_state; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1695 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | /* |
| 1697 | * If same as previous state, return |
| 1698 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | if (state == oldstate) { |
| 1701 | return oldstate; |
| 1702 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1703 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1705 | * If new state is ON, turn channel on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1707 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | if (state == sbmac_state_on) { |
| 1709 | sbmac_channel_start(sc); |
| 1710 | } |
| 1711 | else { |
| 1712 | sbmac_channel_stop(sc); |
| 1713 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | /* |
| 1716 | * Return previous state |
| 1717 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | return oldstate; |
| 1720 | } |
| 1721 | |
| 1722 | |
| 1723 | /********************************************************************** |
| 1724 | * SBMAC_PROMISCUOUS_MODE(sc,onoff) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1725 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | * Turn on or off promiscuous mode |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1727 | * |
| 1728 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | * sc - softc |
| 1730 | * onoff - 1 to turn on, 0 to turn off |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1731 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | * Return value: |
| 1733 | * nothing |
| 1734 | ********************************************************************* */ |
| 1735 | |
| 1736 | static void sbmac_promiscuous_mode(struct sbmac_softc *sc,int onoff) |
| 1737 | { |
| 1738 | uint64_t reg; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | if (sc->sbm_state != sbmac_state_on) |
| 1741 | return; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1742 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1743 | if (onoff) { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1744 | reg = __raw_readq(sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | reg |= M_MAC_ALLPKT_EN; |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1746 | __raw_writeq(reg, sc->sbm_rxfilter); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1747 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | else { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1749 | reg = __raw_readq(sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | reg &= ~M_MAC_ALLPKT_EN; |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1751 | __raw_writeq(reg, sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | /********************************************************************** |
| 1756 | * SBMAC_SETIPHDR_OFFSET(sc,onoff) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1757 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | * Set the iphdr offset as 15 assuming ethernet encapsulation |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1759 | * |
| 1760 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 | * sc - softc |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1762 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | * Return value: |
| 1764 | * nothing |
| 1765 | ********************************************************************* */ |
| 1766 | |
| 1767 | static void sbmac_set_iphdr_offset(struct sbmac_softc *sc) |
| 1768 | { |
| 1769 | uint64_t reg; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1770 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | /* Hard code the off set to 15 for now */ |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1772 | reg = __raw_readq(sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | reg &= ~M_MAC_IPHDR_OFFSET | V_MAC_IPHDR_OFFSET(15); |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1774 | __raw_writeq(reg, sc->sbm_rxfilter); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1775 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 1776 | /* BCM1250 pass1 didn't have hardware checksum. Everything |
| 1777 | later does. */ |
| 1778 | if (soc_type == K_SYS_SOC_TYPE_BCM1250 && periph_rev < 2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | sc->rx_hw_checksum = DISABLE; |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 1780 | } else { |
| 1781 | sc->rx_hw_checksum = ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | |
| 1786 | /********************************************************************** |
| 1787 | * SBMAC_ADDR2REG(ptr) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1788 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | * Convert six bytes into the 64-bit register value that |
| 1790 | * we typically write into the SBMAC's address/mcast registers |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1791 | * |
| 1792 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | * ptr - pointer to 6 bytes |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1794 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | * Return value: |
| 1796 | * register value |
| 1797 | ********************************************************************* */ |
| 1798 | |
| 1799 | static uint64_t sbmac_addr2reg(unsigned char *ptr) |
| 1800 | { |
| 1801 | uint64_t reg = 0; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | ptr += 6; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1804 | |
| 1805 | reg |= (uint64_t) *(--ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | reg <<= 8; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1807 | reg |= (uint64_t) *(--ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | reg <<= 8; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1809 | reg |= (uint64_t) *(--ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | reg <<= 8; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1811 | reg |= (uint64_t) *(--ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | reg <<= 8; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1813 | reg |= (uint64_t) *(--ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | reg <<= 8; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1815 | reg |= (uint64_t) *(--ptr); |
| 1816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1817 | return reg; |
| 1818 | } |
| 1819 | |
| 1820 | |
| 1821 | /********************************************************************** |
| 1822 | * SBMAC_SET_SPEED(s,speed) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1823 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | * Configure LAN speed for the specified MAC. |
| 1825 | * Warning: must be called when MAC is off! |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1826 | * |
| 1827 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | * s - sbmac structure |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1829 | * speed - speed to set MAC to (see enum sbmac_speed) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1830 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | * Return value: |
| 1832 | * 1 if successful |
| 1833 | * 0 indicates invalid parameters |
| 1834 | ********************************************************************* */ |
| 1835 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1836 | static int sbmac_set_speed(struct sbmac_softc *s, enum sbmac_speed speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | { |
| 1838 | uint64_t cfg; |
| 1839 | uint64_t framecfg; |
| 1840 | |
| 1841 | /* |
| 1842 | * Save new current values |
| 1843 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1844 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | s->sbm_speed = speed; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | if (s->sbm_state == sbmac_state_on) |
| 1848 | return 0; /* save for next restart */ |
| 1849 | |
| 1850 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1851 | * Read current register values |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1853 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1854 | cfg = __raw_readq(s->sbm_maccfg); |
| 1855 | framecfg = __raw_readq(s->sbm_framecfg); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | /* |
| 1858 | * Mask out the stuff we want to change |
| 1859 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1860 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | cfg &= ~(M_MAC_BURST_EN | M_MAC_SPEED_SEL); |
| 1862 | framecfg &= ~(M_MAC_IFG_RX | M_MAC_IFG_TX | M_MAC_IFG_THRSH | |
| 1863 | M_MAC_SLOT_SIZE); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1864 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | /* |
| 1866 | * Now add in the new bits |
| 1867 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | switch (speed) { |
| 1870 | case sbmac_speed_10: |
| 1871 | framecfg |= V_MAC_IFG_RX_10 | |
| 1872 | V_MAC_IFG_TX_10 | |
| 1873 | K_MAC_IFG_THRSH_10 | |
| 1874 | V_MAC_SLOT_SIZE_10; |
| 1875 | cfg |= V_MAC_SPEED_SEL_10MBPS; |
| 1876 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1877 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | case sbmac_speed_100: |
| 1879 | framecfg |= V_MAC_IFG_RX_100 | |
| 1880 | V_MAC_IFG_TX_100 | |
| 1881 | V_MAC_IFG_THRSH_100 | |
| 1882 | V_MAC_SLOT_SIZE_100; |
| 1883 | cfg |= V_MAC_SPEED_SEL_100MBPS ; |
| 1884 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1885 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | case sbmac_speed_1000: |
| 1887 | framecfg |= V_MAC_IFG_RX_1000 | |
| 1888 | V_MAC_IFG_TX_1000 | |
| 1889 | V_MAC_IFG_THRSH_1000 | |
| 1890 | V_MAC_SLOT_SIZE_1000; |
| 1891 | cfg |= V_MAC_SPEED_SEL_1000MBPS | M_MAC_BURST_EN; |
| 1892 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | default: |
| 1895 | return 0; |
| 1896 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1897 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1899 | * Send the bits back to the hardware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1901 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1902 | __raw_writeq(framecfg, s->sbm_framecfg); |
| 1903 | __raw_writeq(cfg, s->sbm_maccfg); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1904 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | return 1; |
| 1906 | } |
| 1907 | |
| 1908 | /********************************************************************** |
| 1909 | * SBMAC_SET_DUPLEX(s,duplex,fc) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1910 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | * Set Ethernet duplex and flow control options for this MAC |
| 1912 | * Warning: must be called when MAC is off! |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1913 | * |
| 1914 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | * s - sbmac structure |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1916 | * duplex - duplex setting (see enum sbmac_duplex) |
| 1917 | * fc - flow control setting (see enum sbmac_fc) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1918 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | * Return value: |
| 1920 | * 1 if ok |
| 1921 | * 0 if an invalid parameter combination was specified |
| 1922 | ********************************************************************* */ |
| 1923 | |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 1924 | static int sbmac_set_duplex(struct sbmac_softc *s, enum sbmac_duplex duplex, |
| 1925 | enum sbmac_fc fc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | { |
| 1927 | uint64_t cfg; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1928 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | /* |
| 1930 | * Save new current values |
| 1931 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | s->sbm_duplex = duplex; |
| 1934 | s->sbm_fc = fc; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | if (s->sbm_state == sbmac_state_on) |
| 1937 | return 0; /* save for next restart */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1938 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1939 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1940 | * Read current register values |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1942 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1943 | cfg = __raw_readq(s->sbm_maccfg); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | /* |
| 1946 | * Mask off the stuff we're about to change |
| 1947 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1948 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1949 | cfg &= ~(M_MAC_FC_SEL | M_MAC_FC_CMD | M_MAC_HDX_EN); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1950 | |
| 1951 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | switch (duplex) { |
| 1953 | case sbmac_duplex_half: |
| 1954 | switch (fc) { |
| 1955 | case sbmac_fc_disabled: |
| 1956 | cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_DISABLED; |
| 1957 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | case sbmac_fc_collision: |
| 1960 | cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENABLED; |
| 1961 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1962 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | case sbmac_fc_carrier: |
| 1964 | cfg |= M_MAC_HDX_EN | V_MAC_FC_CMD_ENAB_FALSECARR; |
| 1965 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | case sbmac_fc_frame: /* not valid in half duplex */ |
| 1968 | default: /* invalid selection */ |
| 1969 | return 0; |
| 1970 | } |
| 1971 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1972 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1973 | case sbmac_duplex_full: |
| 1974 | switch (fc) { |
| 1975 | case sbmac_fc_disabled: |
| 1976 | cfg |= V_MAC_FC_CMD_DISABLED; |
| 1977 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | case sbmac_fc_frame: |
| 1980 | cfg |= V_MAC_FC_CMD_ENABLED; |
| 1981 | break; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | case sbmac_fc_collision: /* not valid in full duplex */ |
| 1984 | case sbmac_fc_carrier: /* not valid in full duplex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1985 | default: |
| 1986 | return 0; |
| 1987 | } |
| 1988 | break; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 1989 | default: |
| 1990 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1992 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1994 | * Send the bits back to the hardware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1996 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 1997 | __raw_writeq(cfg, s->sbm_maccfg); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 1998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | return 1; |
| 2000 | } |
| 2001 | |
| 2002 | |
| 2003 | |
| 2004 | |
| 2005 | /********************************************************************** |
| 2006 | * SBMAC_INTR() |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2007 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | * Interrupt handler for MAC interrupts |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2009 | * |
| 2010 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | * MAC structure |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2012 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | * Return value: |
| 2014 | * nothing |
| 2015 | ********************************************************************* */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2016 | static irqreturn_t sbmac_intr(int irq,void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | { |
| 2018 | struct net_device *dev = (struct net_device *) dev_instance; |
| 2019 | struct sbmac_softc *sc = netdev_priv(dev); |
| 2020 | uint64_t isr; |
| 2021 | int handled = 0; |
| 2022 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2023 | /* |
| 2024 | * Read the ISR (this clears the bits in the real |
| 2025 | * register, except for counter addr) |
| 2026 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2027 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2028 | isr = __raw_readq(sc->sbm_isr) & ~M_MAC_COUNTER_ADDR; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2029 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2030 | if (isr == 0) |
| 2031 | return IRQ_RETVAL(0); |
| 2032 | handled = 1; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2033 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2034 | /* |
| 2035 | * Transmits on channel 0 |
| 2036 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2038 | if (isr & (M_MAC_INT_CHANNEL << S_MAC_TX_CH0)) |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2039 | sbdma_tx_process(sc,&(sc->sbm_txdma), 0); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2040 | |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2041 | if (isr & (M_MAC_INT_CHANNEL << S_MAC_RX_CH0)) { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2042 | if (netif_rx_schedule_prep(dev, &sc->napi)) { |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2043 | __raw_writeq(0, sc->sbm_imr); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2044 | __netif_rx_schedule(dev, &sc->napi); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2045 | /* Depend on the exit from poll to reenable intr */ |
| 2046 | } |
| 2047 | else { |
| 2048 | /* may leave some packets behind */ |
| 2049 | sbdma_rx_process(sc,&(sc->sbm_rxdma), |
| 2050 | SBMAC_MAX_RXDESCR * 2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | return IRQ_RETVAL(handled); |
| 2054 | } |
| 2055 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | /********************************************************************** |
| 2057 | * SBMAC_START_TX(skb,dev) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2058 | * |
| 2059 | * Start output on the specified interface. Basically, we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | * queue as many buffers as we can until the ring fills up, or |
| 2061 | * we run off the end of the queue, whichever comes first. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2062 | * |
| 2063 | * Input parameters: |
| 2064 | * |
| 2065 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | * Return value: |
| 2067 | * nothing |
| 2068 | ********************************************************************* */ |
| 2069 | static int sbmac_start_tx(struct sk_buff *skb, struct net_device *dev) |
| 2070 | { |
| 2071 | struct sbmac_softc *sc = netdev_priv(dev); |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2072 | unsigned long flags; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | /* lock eth irq */ |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2075 | spin_lock_irqsave(&sc->sbm_lock, flags); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | /* |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2078 | * Put the buffer on the transmit ring. If we |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | * don't have room, stop the queue. |
| 2080 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2081 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | if (sbdma_add_txbuffer(&(sc->sbm_txdma),skb)) { |
| 2083 | /* XXX save skb that we could not send */ |
| 2084 | netif_stop_queue(dev); |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2085 | spin_unlock_irqrestore(&sc->sbm_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | |
| 2087 | return 1; |
| 2088 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | dev->trans_start = jiffies; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2091 | |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2092 | spin_unlock_irqrestore(&sc->sbm_lock, flags); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2093 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | return 0; |
| 2095 | } |
| 2096 | |
| 2097 | /********************************************************************** |
| 2098 | * SBMAC_SETMULTI(sc) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2099 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | * Reprogram the multicast table into the hardware, given |
| 2101 | * the list of multicasts associated with the interface |
| 2102 | * structure. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2103 | * |
| 2104 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | * sc - softc |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2106 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | * Return value: |
| 2108 | * nothing |
| 2109 | ********************************************************************* */ |
| 2110 | |
| 2111 | static void sbmac_setmulti(struct sbmac_softc *sc) |
| 2112 | { |
| 2113 | uint64_t reg; |
Maciej W. Rozycki | 73d7396 | 2007-09-20 19:14:01 +0100 | [diff] [blame] | 2114 | void __iomem *port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | int idx; |
| 2116 | struct dev_mc_list *mclist; |
| 2117 | struct net_device *dev = sc->sbm_dev; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2118 | |
| 2119 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | * Clear out entire multicast table. We do this by nuking |
| 2121 | * the entire hash table and all the direct matches except |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2122 | * the first one, which is used for our station address |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2123 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | for (idx = 1; idx < MAC_ADDR_COUNT; idx++) { |
| 2126 | port = sc->sbm_base + R_MAC_ADDR_BASE+(idx*sizeof(uint64_t)); |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2127 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2128 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | for (idx = 0; idx < MAC_HASH_COUNT; idx++) { |
| 2131 | port = sc->sbm_base + R_MAC_HASH_BASE+(idx*sizeof(uint64_t)); |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2132 | __raw_writeq(0, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | /* |
| 2136 | * Clear the filter to say we don't want any multicasts. |
| 2137 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2138 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2139 | reg = __raw_readq(sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | reg &= ~(M_MAC_MCAST_INV | M_MAC_MCAST_EN); |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2141 | __raw_writeq(reg, sc->sbm_rxfilter); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | if (dev->flags & IFF_ALLMULTI) { |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2144 | /* |
| 2145 | * Enable ALL multicasts. Do this by inverting the |
| 2146 | * multicast enable bit. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | */ |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2148 | reg = __raw_readq(sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | reg |= (M_MAC_MCAST_INV | M_MAC_MCAST_EN); |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2150 | __raw_writeq(reg, sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | return; |
| 2152 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2153 | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2154 | |
| 2155 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2156 | * Progam new multicast entries. For now, only use the |
| 2157 | * perfect filter. In the future we'll need to use the |
| 2158 | * hash filter if the perfect filter overflows |
| 2159 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | /* XXX only using perfect filter for now, need to use hash |
| 2162 | * XXX if the table overflows */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | idx = 1; /* skip station address */ |
| 2165 | mclist = dev->mc_list; |
| 2166 | while (mclist && (idx < MAC_ADDR_COUNT)) { |
| 2167 | reg = sbmac_addr2reg(mclist->dmi_addr); |
| 2168 | port = sc->sbm_base + R_MAC_ADDR_BASE+(idx * sizeof(uint64_t)); |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2169 | __raw_writeq(reg, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | idx++; |
| 2171 | mclist = mclist->next; |
| 2172 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2173 | |
| 2174 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | * Enable the "accept multicast bits" if we programmed at least one |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2176 | * multicast. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2177 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | if (idx > 1) { |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2180 | reg = __raw_readq(sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | reg |= M_MAC_MCAST_EN; |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2182 | __raw_writeq(reg, sc->sbm_rxfilter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2186 | #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | /********************************************************************** |
| 2188 | * SBMAC_PARSE_XDIGIT(str) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2189 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | * Parse a hex digit, returning its value |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2191 | * |
| 2192 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2193 | * str - character |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2194 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | * Return value: |
| 2196 | * hex value, or -1 if invalid |
| 2197 | ********************************************************************* */ |
| 2198 | |
| 2199 | static int sbmac_parse_xdigit(char str) |
| 2200 | { |
| 2201 | int digit; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | if ((str >= '0') && (str <= '9')) |
| 2204 | digit = str - '0'; |
| 2205 | else if ((str >= 'a') && (str <= 'f')) |
| 2206 | digit = str - 'a' + 10; |
| 2207 | else if ((str >= 'A') && (str <= 'F')) |
| 2208 | digit = str - 'A' + 10; |
| 2209 | else |
| 2210 | return -1; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | return digit; |
| 2213 | } |
| 2214 | |
| 2215 | /********************************************************************** |
| 2216 | * SBMAC_PARSE_HWADDR(str,hwaddr) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2217 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | * Convert a string in the form xx:xx:xx:xx:xx:xx into a 6-byte |
| 2219 | * Ethernet address. |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2220 | * |
| 2221 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2222 | * str - string |
| 2223 | * hwaddr - pointer to hardware address |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2224 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2225 | * Return value: |
| 2226 | * 0 if ok, else -1 |
| 2227 | ********************************************************************* */ |
| 2228 | |
| 2229 | static int sbmac_parse_hwaddr(char *str, unsigned char *hwaddr) |
| 2230 | { |
| 2231 | int digit1,digit2; |
| 2232 | int idx = 6; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2233 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2234 | while (*str && (idx > 0)) { |
| 2235 | digit1 = sbmac_parse_xdigit(*str); |
| 2236 | if (digit1 < 0) |
| 2237 | return -1; |
| 2238 | str++; |
| 2239 | if (!*str) |
| 2240 | return -1; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | if ((*str == ':') || (*str == '-')) { |
| 2243 | digit2 = digit1; |
| 2244 | digit1 = 0; |
| 2245 | } |
| 2246 | else { |
| 2247 | digit2 = sbmac_parse_xdigit(*str); |
| 2248 | if (digit2 < 0) |
| 2249 | return -1; |
| 2250 | str++; |
| 2251 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | *hwaddr++ = (digit1 << 4) | digit2; |
| 2254 | idx--; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | if (*str == '-') |
| 2257 | str++; |
| 2258 | if (*str == ':') |
| 2259 | str++; |
| 2260 | } |
| 2261 | return 0; |
| 2262 | } |
| 2263 | #endif |
| 2264 | |
| 2265 | static int sb1250_change_mtu(struct net_device *_dev, int new_mtu) |
| 2266 | { |
| 2267 | if (new_mtu > ENET_PACKET_SIZE) |
| 2268 | return -EINVAL; |
| 2269 | _dev->mtu = new_mtu; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2270 | pr_info("changing the mtu to %d\n", new_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2271 | return 0; |
| 2272 | } |
| 2273 | |
| 2274 | /********************************************************************** |
| 2275 | * SBMAC_INIT(dev) |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2276 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | * Attach routine - init hardware and hook ourselves into linux |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2278 | * |
| 2279 | * Input parameters: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | * dev - net_device structure |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2281 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2282 | * Return value: |
| 2283 | * status |
| 2284 | ********************************************************************* */ |
| 2285 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2286 | static int sbmac_init(struct platform_device *pldev, long long base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2287 | { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2288 | struct net_device *dev = pldev->dev.driver_data; |
| 2289 | int idx = pldev->id; |
| 2290 | struct sbmac_softc *sc = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | unsigned char *eaddr; |
| 2292 | uint64_t ea_reg; |
| 2293 | int i; |
| 2294 | int err; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | sc->sbm_dev = dev; |
| 2297 | sc->sbe_idx = idx; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | eaddr = sc->sbm_hwaddr; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2300 | |
| 2301 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | * Read the ethernet address. The firwmare left this programmed |
| 2303 | * for us in the ethernet address register for each mac. |
| 2304 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2305 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2306 | ea_reg = __raw_readq(sc->sbm_base + R_MAC_ETHERNET_ADDR); |
| 2307 | __raw_writeq(0, sc->sbm_base + R_MAC_ETHERNET_ADDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | for (i = 0; i < 6; i++) { |
| 2309 | eaddr[i] = (uint8_t) (ea_reg & 0xFF); |
| 2310 | ea_reg >>= 8; |
| 2311 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | for (i = 0; i < 6; i++) { |
| 2314 | dev->dev_addr[i] = eaddr[i]; |
| 2315 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2316 | |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2317 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | * Initialize context (get pointers to registers and stuff), then |
| 2319 | * allocate the memory for the descriptor tables. |
| 2320 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | sbmac_initctx(sc); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | /* |
| 2325 | * Set up Linux device callins |
| 2326 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | spin_lock_init(&(sc->sbm_lock)); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | dev->open = sbmac_open; |
| 2331 | dev->hard_start_xmit = sbmac_start_tx; |
| 2332 | dev->stop = sbmac_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | dev->set_multicast_list = sbmac_set_rx_mode; |
| 2334 | dev->do_ioctl = sbmac_mii_ioctl; |
| 2335 | dev->tx_timeout = sbmac_tx_timeout; |
| 2336 | dev->watchdog_timeo = TX_TIMEOUT; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2337 | |
| 2338 | netif_napi_add(dev, &sc->napi, sbmac_poll, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | |
| 2340 | dev->change_mtu = sb1250_change_mtu; |
Deepak Saxena | d683001 | 2007-03-19 15:43:11 -0700 | [diff] [blame] | 2341 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2342 | dev->poll_controller = sbmac_netpoll; |
| 2343 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2345 | dev->irq = UNIT_INT(idx); |
| 2346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | /* This is needed for PASS2 for Rx H/W checksum feature */ |
| 2348 | sbmac_set_iphdr_offset(sc); |
| 2349 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2350 | sc->mii_bus = mdiobus_alloc(); |
| 2351 | if (sc->mii_bus == NULL) { |
| 2352 | sbmac_uninitctx(sc); |
| 2353 | return -ENOMEM; |
| 2354 | } |
| 2355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | err = register_netdev(dev); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2357 | if (err) { |
| 2358 | printk(KERN_ERR "%s.%d: unable to register netdev\n", |
| 2359 | sbmac_string, idx); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2360 | mdiobus_free(sc->mii_bus); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2361 | sbmac_uninitctx(sc); |
| 2362 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2365 | pr_info("%s.%d: registered as %s\n", sbmac_string, idx, dev->name); |
| 2366 | |
| 2367 | if (sc->rx_hw_checksum == ENABLE) |
| 2368 | pr_info("%s: enabling TCP rcv checksum\n", dev->name); |
| 2369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | /* |
| 2371 | * Display Ethernet address (this is called during the config |
| 2372 | * process so we need to finish off the config message that |
| 2373 | * was being displayed) |
| 2374 | */ |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 2375 | pr_info("%s: SiByte Ethernet at 0x%08Lx, address: %pM\n", |
| 2376 | dev->name, base, eaddr); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2377 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2378 | sc->mii_bus->name = sbmac_mdio_string; |
| 2379 | snprintf(sc->mii_bus->id, MII_BUS_ID_SIZE, "%x", idx); |
| 2380 | sc->mii_bus->priv = sc; |
| 2381 | sc->mii_bus->read = sbmac_mii_read; |
| 2382 | sc->mii_bus->write = sbmac_mii_write; |
| 2383 | sc->mii_bus->irq = sc->phy_irq; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2384 | for (i = 0; i < PHY_MAX_ADDR; ++i) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2385 | sc->mii_bus->irq[i] = SBMAC_PHY_INT; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2386 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2387 | sc->mii_bus->parent = &pldev->dev; |
| 2388 | dev_set_drvdata(&pldev->dev, sc->mii_bus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2389 | |
| 2390 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | |
| 2394 | static int sbmac_open(struct net_device *dev) |
| 2395 | { |
| 2396 | struct sbmac_softc *sc = netdev_priv(dev); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2397 | int err; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2398 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2399 | if (debug > 1) |
| 2400 | pr_debug("%s: sbmac_open() irq %d.\n", dev->name, dev->irq); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2401 | |
| 2402 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | * map/route interrupt (clear status first, in case something |
| 2404 | * weird is pending; we haven't initialized the mac registers |
| 2405 | * yet) |
| 2406 | */ |
| 2407 | |
Ralf Baechle | 2039973 | 2005-10-19 15:39:05 +0100 | [diff] [blame] | 2408 | __raw_readq(sc->sbm_isr); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2409 | err = request_irq(dev->irq, &sbmac_intr, IRQF_SHARED, dev->name, dev); |
| 2410 | if (err) { |
| 2411 | printk(KERN_ERR "%s: unable to get IRQ %d\n", dev->name, |
| 2412 | dev->irq); |
| 2413 | goto out_err; |
Ralf Baechle | 59b8182 | 2005-10-20 12:01:28 +0100 | [diff] [blame] | 2414 | } |
| 2415 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2416 | /* |
| 2417 | * Probe PHY address |
| 2418 | */ |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2419 | err = mdiobus_register(sc->mii_bus); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2420 | if (err) { |
| 2421 | printk(KERN_ERR "%s: unable to register MDIO bus\n", |
| 2422 | dev->name); |
| 2423 | goto out_unirq; |
| 2424 | } |
| 2425 | |
| 2426 | sc->sbm_speed = sbmac_speed_none; |
| 2427 | sc->sbm_duplex = sbmac_duplex_none; |
| 2428 | sc->sbm_fc = sbmac_fc_none; |
| 2429 | sc->sbm_pause = -1; |
| 2430 | sc->sbm_link = 0; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2431 | |
Ralf Baechle | 59b8182 | 2005-10-20 12:01:28 +0100 | [diff] [blame] | 2432 | /* |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2433 | * Attach to the PHY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2435 | err = sbmac_mii_probe(dev); |
| 2436 | if (err) |
| 2437 | goto out_unregister; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | /* |
| 2440 | * Turn on the channel |
| 2441 | */ |
| 2442 | |
| 2443 | sbmac_set_channel_state(sc,sbmac_state_on); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | netif_start_queue(dev); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2447 | sbmac_set_rx_mode(dev); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2448 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2449 | phy_start(sc->phy_dev); |
| 2450 | |
| 2451 | napi_enable(&sc->napi); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2452 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | return 0; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2454 | |
| 2455 | out_unregister: |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2456 | mdiobus_unregister(sc->mii_bus); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2457 | |
| 2458 | out_unirq: |
| 2459 | free_irq(dev->irq, dev); |
| 2460 | |
| 2461 | out_err: |
| 2462 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2463 | } |
| 2464 | |
Ralf Baechle | 59b8182 | 2005-10-20 12:01:28 +0100 | [diff] [blame] | 2465 | static int sbmac_mii_probe(struct net_device *dev) |
| 2466 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | struct sbmac_softc *sc = netdev_priv(dev); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2468 | struct phy_device *phy_dev; |
| 2469 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2470 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2471 | for (i = 0; i < PHY_MAX_ADDR; i++) { |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2472 | phy_dev = sc->mii_bus->phy_map[i]; |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2473 | if (phy_dev) |
| 2474 | break; |
| 2475 | } |
| 2476 | if (!phy_dev) { |
| 2477 | printk(KERN_ERR "%s: no PHY found\n", dev->name); |
| 2478 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2479 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2480 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2481 | phy_dev = phy_connect(dev, phy_dev->dev.bus_id, &sbmac_mii_poll, 0, |
| 2482 | PHY_INTERFACE_MODE_GMII); |
| 2483 | if (IS_ERR(phy_dev)) { |
| 2484 | printk(KERN_ERR "%s: could not attach to PHY\n", dev->name); |
| 2485 | return PTR_ERR(phy_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | } |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2487 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2488 | /* Remove any features not supported by the controller */ |
| 2489 | phy_dev->supported &= SUPPORTED_10baseT_Half | |
| 2490 | SUPPORTED_10baseT_Full | |
| 2491 | SUPPORTED_100baseT_Half | |
| 2492 | SUPPORTED_100baseT_Full | |
| 2493 | SUPPORTED_1000baseT_Half | |
| 2494 | SUPPORTED_1000baseT_Full | |
| 2495 | SUPPORTED_Autoneg | |
| 2496 | SUPPORTED_MII | |
| 2497 | SUPPORTED_Pause | |
| 2498 | SUPPORTED_Asym_Pause; |
| 2499 | phy_dev->advertising = phy_dev->supported; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2500 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2501 | pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", |
| 2502 | dev->name, phy_dev->drv->name, |
| 2503 | phy_dev->dev.bus_id, phy_dev->irq); |
| 2504 | |
| 2505 | sc->phy_dev = phy_dev; |
| 2506 | |
| 2507 | return 0; |
| 2508 | } |
| 2509 | |
| 2510 | |
| 2511 | static void sbmac_mii_poll(struct net_device *dev) |
| 2512 | { |
| 2513 | struct sbmac_softc *sc = netdev_priv(dev); |
| 2514 | struct phy_device *phy_dev = sc->phy_dev; |
| 2515 | unsigned long flags; |
| 2516 | enum sbmac_fc fc; |
| 2517 | int link_chg, speed_chg, duplex_chg, pause_chg, fc_chg; |
| 2518 | |
| 2519 | link_chg = (sc->sbm_link != phy_dev->link); |
| 2520 | speed_chg = (sc->sbm_speed != phy_dev->speed); |
| 2521 | duplex_chg = (sc->sbm_duplex != phy_dev->duplex); |
| 2522 | pause_chg = (sc->sbm_pause != phy_dev->pause); |
| 2523 | |
| 2524 | if (!link_chg && !speed_chg && !duplex_chg && !pause_chg) |
| 2525 | return; /* Hmmm... */ |
| 2526 | |
| 2527 | if (!phy_dev->link) { |
| 2528 | if (link_chg) { |
| 2529 | sc->sbm_link = phy_dev->link; |
| 2530 | sc->sbm_speed = sbmac_speed_none; |
| 2531 | sc->sbm_duplex = sbmac_duplex_none; |
| 2532 | sc->sbm_fc = sbmac_fc_disabled; |
| 2533 | sc->sbm_pause = -1; |
| 2534 | pr_info("%s: link unavailable\n", dev->name); |
| 2535 | } |
| 2536 | return; |
| 2537 | } |
| 2538 | |
| 2539 | if (phy_dev->duplex == DUPLEX_FULL) { |
| 2540 | if (phy_dev->pause) |
| 2541 | fc = sbmac_fc_frame; |
| 2542 | else |
| 2543 | fc = sbmac_fc_disabled; |
| 2544 | } else |
| 2545 | fc = sbmac_fc_collision; |
| 2546 | fc_chg = (sc->sbm_fc != fc); |
| 2547 | |
| 2548 | pr_info("%s: link available: %dbase-%cD\n", dev->name, phy_dev->speed, |
| 2549 | phy_dev->duplex == DUPLEX_FULL ? 'F' : 'H'); |
| 2550 | |
| 2551 | spin_lock_irqsave(&sc->sbm_lock, flags); |
| 2552 | |
| 2553 | sc->sbm_speed = phy_dev->speed; |
| 2554 | sc->sbm_duplex = phy_dev->duplex; |
| 2555 | sc->sbm_fc = fc; |
| 2556 | sc->sbm_pause = phy_dev->pause; |
| 2557 | sc->sbm_link = phy_dev->link; |
| 2558 | |
| 2559 | if ((speed_chg || duplex_chg || fc_chg) && |
| 2560 | sc->sbm_state != sbmac_state_off) { |
| 2561 | /* |
| 2562 | * something changed, restart the channel |
| 2563 | */ |
| 2564 | if (debug > 1) |
| 2565 | pr_debug("%s: restarting channel " |
| 2566 | "because PHY state changed\n", dev->name); |
| 2567 | sbmac_channel_stop(sc); |
| 2568 | sbmac_channel_start(sc); |
| 2569 | } |
| 2570 | |
| 2571 | spin_unlock_irqrestore(&sc->sbm_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | |
| 2575 | static void sbmac_tx_timeout (struct net_device *dev) |
| 2576 | { |
| 2577 | struct sbmac_softc *sc = netdev_priv(dev); |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2578 | unsigned long flags; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2579 | |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2580 | spin_lock_irqsave(&sc->sbm_lock, flags); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2581 | |
| 2582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | dev->trans_start = jiffies; |
Jeff Garzik | 09f75cd | 2007-10-03 17:41:50 -0700 | [diff] [blame] | 2584 | dev->stats.tx_errors++; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2585 | |
Weiwei Wang | be61ea5 | 2008-09-18 08:23:48 +0800 | [diff] [blame] | 2586 | spin_unlock_irqrestore(&sc->sbm_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | |
| 2588 | printk (KERN_WARNING "%s: Transmit timed out\n",dev->name); |
| 2589 | } |
| 2590 | |
| 2591 | |
| 2592 | |
| 2593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2594 | static void sbmac_set_rx_mode(struct net_device *dev) |
| 2595 | { |
| 2596 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | struct sbmac_softc *sc = netdev_priv(dev); |
| 2598 | |
| 2599 | spin_lock_irqsave(&sc->sbm_lock, flags); |
| 2600 | if ((dev->flags ^ sc->sbm_devflags) & IFF_PROMISC) { |
| 2601 | /* |
| 2602 | * Promiscuous changed. |
| 2603 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2604 | |
| 2605 | if (dev->flags & IFF_PROMISC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | sbmac_promiscuous_mode(sc,1); |
| 2607 | } |
| 2608 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | sbmac_promiscuous_mode(sc,0); |
| 2610 | } |
| 2611 | } |
| 2612 | spin_unlock_irqrestore(&sc->sbm_lock, flags); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | /* |
| 2615 | * Program the multicasts. Do this every time. |
| 2616 | */ |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2617 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2618 | sbmac_setmulti(sc); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2623 | { |
| 2624 | struct sbmac_softc *sc = netdev_priv(dev); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2625 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2626 | if (!netif_running(dev) || !sc->phy_dev) |
| 2627 | return -EINVAL; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2628 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2629 | return phy_mii_ioctl(sc->phy_dev, if_mii(rq), cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | static int sbmac_close(struct net_device *dev) |
| 2633 | { |
| 2634 | struct sbmac_softc *sc = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2636 | napi_disable(&sc->napi); |
| 2637 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2638 | phy_stop(sc->phy_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2640 | sbmac_set_channel_state(sc, sbmac_state_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
| 2642 | netif_stop_queue(dev); |
| 2643 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2644 | if (debug > 1) |
| 2645 | pr_debug("%s: Shutting down ethercard\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2647 | phy_disconnect(sc->phy_dev); |
| 2648 | sc->phy_dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2650 | mdiobus_unregister(sc->mii_bus); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2651 | |
| 2652 | free_irq(dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | |
| 2654 | sbdma_emptyring(&(sc->sbm_txdma)); |
| 2655 | sbdma_emptyring(&(sc->sbm_rxdma)); |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | return 0; |
| 2658 | } |
| 2659 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2660 | static int sbmac_poll(struct napi_struct *napi, int budget) |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2661 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2662 | struct sbmac_softc *sc = container_of(napi, struct sbmac_softc, napi); |
| 2663 | struct net_device *dev = sc->sbm_dev; |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2664 | int work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2666 | work_done = sbdma_rx_process(sc, &(sc->sbm_rxdma), budget, 1); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2667 | sbdma_tx_process(sc, &(sc->sbm_txdma), 1); |
| 2668 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2669 | if (work_done < budget) { |
| 2670 | netif_rx_complete(dev, napi); |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2671 | |
| 2672 | #ifdef CONFIG_SBMAC_COALESCE |
| 2673 | __raw_writeq(((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_TX_CH0) | |
| 2674 | ((M_MAC_INT_EOP_COUNT | M_MAC_INT_EOP_TIMER) << S_MAC_RX_CH0), |
| 2675 | sc->sbm_imr); |
| 2676 | #else |
| 2677 | __raw_writeq((M_MAC_INT_CHANNEL << S_MAC_TX_CH0) | |
| 2678 | (M_MAC_INT_CHANNEL << S_MAC_RX_CH0), sc->sbm_imr); |
| 2679 | #endif |
| 2680 | } |
| 2681 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 2682 | return work_done; |
Mark Mason | 693aa94 | 2007-04-26 00:23:22 -0700 | [diff] [blame] | 2683 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2685 | |
| 2686 | static int __init sbmac_probe(struct platform_device *pldev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2688 | struct net_device *dev; |
| 2689 | struct sbmac_softc *sc; |
| 2690 | void __iomem *sbm_base; |
| 2691 | struct resource *res; |
| 2692 | u64 sbmac_orig_hwaddr; |
| 2693 | int err; |
| 2694 | |
| 2695 | res = platform_get_resource(pldev, IORESOURCE_MEM, 0); |
| 2696 | BUG_ON(!res); |
| 2697 | sbm_base = ioremap_nocache(res->start, res->end - res->start + 1); |
| 2698 | if (!sbm_base) { |
| 2699 | printk(KERN_ERR "%s: unable to map device registers\n", |
| 2700 | pldev->dev.bus_id); |
| 2701 | err = -ENOMEM; |
| 2702 | goto out_out; |
| 2703 | } |
| 2704 | |
| 2705 | /* |
| 2706 | * The R_MAC_ETHERNET_ADDR register will be set to some nonzero |
| 2707 | * value for us by the firmware if we're going to use this MAC. |
| 2708 | * If we find a zero, skip this MAC. |
| 2709 | */ |
| 2710 | sbmac_orig_hwaddr = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR); |
| 2711 | pr_debug("%s: %sconfiguring MAC at 0x%08Lx\n", pldev->dev.bus_id, |
| 2712 | sbmac_orig_hwaddr ? "" : "not ", (long long)res->start); |
| 2713 | if (sbmac_orig_hwaddr == 0) { |
| 2714 | err = 0; |
| 2715 | goto out_unmap; |
| 2716 | } |
| 2717 | |
| 2718 | /* |
| 2719 | * Okay, cool. Initialize this MAC. |
| 2720 | */ |
| 2721 | dev = alloc_etherdev(sizeof(struct sbmac_softc)); |
| 2722 | if (!dev) { |
| 2723 | printk(KERN_ERR "%s: unable to allocate etherdev\n", |
| 2724 | pldev->dev.bus_id); |
| 2725 | err = -ENOMEM; |
| 2726 | goto out_unmap; |
| 2727 | } |
| 2728 | |
| 2729 | pldev->dev.driver_data = dev; |
| 2730 | SET_NETDEV_DEV(dev, &pldev->dev); |
| 2731 | |
| 2732 | sc = netdev_priv(dev); |
| 2733 | sc->sbm_base = sbm_base; |
| 2734 | |
| 2735 | err = sbmac_init(pldev, res->start); |
| 2736 | if (err) |
| 2737 | goto out_kfree; |
| 2738 | |
| 2739 | return 0; |
| 2740 | |
| 2741 | out_kfree: |
| 2742 | free_netdev(dev); |
| 2743 | __raw_writeq(sbmac_orig_hwaddr, sbm_base + R_MAC_ETHERNET_ADDR); |
| 2744 | |
| 2745 | out_unmap: |
| 2746 | iounmap(sbm_base); |
| 2747 | |
| 2748 | out_out: |
| 2749 | return err; |
| 2750 | } |
| 2751 | |
| 2752 | static int __exit sbmac_remove(struct platform_device *pldev) |
| 2753 | { |
| 2754 | struct net_device *dev = pldev->dev.driver_data; |
| 2755 | struct sbmac_softc *sc = netdev_priv(dev); |
| 2756 | |
| 2757 | unregister_netdev(dev); |
| 2758 | sbmac_uninitctx(sc); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 2759 | mdiobus_free(sc->mii_bus); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2760 | iounmap(sc->sbm_base); |
| 2761 | free_netdev(dev); |
| 2762 | |
| 2763 | return 0; |
| 2764 | } |
| 2765 | |
| 2766 | |
| 2767 | static struct platform_device **sbmac_pldev; |
| 2768 | static int sbmac_max_units; |
| 2769 | |
| 2770 | #if defined(SBMAC_ETH0_HWADDR) || defined(SBMAC_ETH1_HWADDR) || defined(SBMAC_ETH2_HWADDR) || defined(SBMAC_ETH3_HWADDR) |
| 2771 | static void __init sbmac_setup_hwaddr(int idx, char *addr) |
| 2772 | { |
| 2773 | void __iomem *sbm_base; |
| 2774 | unsigned long start, end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | uint8_t eaddr[6]; |
| 2776 | uint64_t val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2778 | if (idx >= sbmac_max_units) |
| 2779 | return; |
| 2780 | |
| 2781 | start = A_MAC_CHANNEL_BASE(idx); |
| 2782 | end = A_MAC_CHANNEL_BASE(idx + 1) - 1; |
| 2783 | |
| 2784 | sbm_base = ioremap_nocache(start, end - start + 1); |
| 2785 | if (!sbm_base) { |
| 2786 | printk(KERN_ERR "%s: unable to map device registers\n", |
| 2787 | sbmac_string); |
| 2788 | return; |
| 2789 | } |
| 2790 | |
| 2791 | sbmac_parse_hwaddr(addr, eaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | val = sbmac_addr2reg(eaddr); |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2793 | __raw_writeq(val, sbm_base + R_MAC_ETHERNET_ADDR); |
| 2794 | val = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR); |
| 2795 | |
| 2796 | iounmap(sbm_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | } |
| 2798 | #endif |
| 2799 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2800 | static int __init sbmac_platform_probe_one(int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2802 | struct platform_device *pldev; |
| 2803 | struct { |
| 2804 | struct resource r; |
| 2805 | char name[strlen(sbmac_pretty) + 4]; |
| 2806 | } *res; |
| 2807 | int err; |
| 2808 | |
| 2809 | res = kzalloc(sizeof(*res), GFP_KERNEL); |
| 2810 | if (!res) { |
| 2811 | printk(KERN_ERR "%s.%d: unable to allocate memory\n", |
| 2812 | sbmac_string, idx); |
| 2813 | err = -ENOMEM; |
| 2814 | goto out_err; |
| 2815 | } |
| 2816 | |
| 2817 | /* |
| 2818 | * This is the base address of the MAC. |
| 2819 | */ |
| 2820 | snprintf(res->name, sizeof(res->name), "%s %d", sbmac_pretty, idx); |
| 2821 | res->r.name = res->name; |
| 2822 | res->r.flags = IORESOURCE_MEM; |
| 2823 | res->r.start = A_MAC_CHANNEL_BASE(idx); |
| 2824 | res->r.end = A_MAC_CHANNEL_BASE(idx + 1) - 1; |
| 2825 | |
| 2826 | pldev = platform_device_register_simple(sbmac_string, idx, &res->r, 1); |
| 2827 | if (IS_ERR(pldev)) { |
| 2828 | printk(KERN_ERR "%s.%d: unable to register platform device\n", |
| 2829 | sbmac_string, idx); |
| 2830 | err = PTR_ERR(pldev); |
| 2831 | goto out_kfree; |
| 2832 | } |
| 2833 | |
| 2834 | if (!pldev->dev.driver) { |
| 2835 | err = 0; /* No hardware at this address. */ |
| 2836 | goto out_unregister; |
| 2837 | } |
| 2838 | |
| 2839 | sbmac_pldev[idx] = pldev; |
| 2840 | return 0; |
| 2841 | |
| 2842 | out_unregister: |
| 2843 | platform_device_unregister(pldev); |
| 2844 | |
| 2845 | out_kfree: |
| 2846 | kfree(res); |
| 2847 | |
| 2848 | out_err: |
| 2849 | return err; |
| 2850 | } |
| 2851 | |
| 2852 | static void __init sbmac_platform_probe(void) |
| 2853 | { |
| 2854 | int i; |
Ralf Baechle | 74b0247 | 2005-10-19 15:40:02 +0100 | [diff] [blame] | 2855 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2856 | /* Set the number of available units based on the SOC type. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | switch (soc_type) { |
| 2858 | case K_SYS_SOC_TYPE_BCM1250: |
| 2859 | case K_SYS_SOC_TYPE_BCM1250_ALT: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2860 | sbmac_max_units = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | break; |
| 2862 | case K_SYS_SOC_TYPE_BCM1120: |
| 2863 | case K_SYS_SOC_TYPE_BCM1125: |
| 2864 | case K_SYS_SOC_TYPE_BCM1125H: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2865 | case K_SYS_SOC_TYPE_BCM1250_ALT2: /* Hybrid */ |
| 2866 | sbmac_max_units = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2867 | break; |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2868 | case K_SYS_SOC_TYPE_BCM1x55: |
| 2869 | case K_SYS_SOC_TYPE_BCM1x80: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2870 | sbmac_max_units = 4; |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2871 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | default: |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2873 | return; /* none */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2876 | /* |
| 2877 | * For bringup when not using the firmware, we can pre-fill |
| 2878 | * the MAC addresses using the environment variables |
| 2879 | * specified in this file (or maybe from the config file?) |
| 2880 | */ |
| 2881 | #ifdef SBMAC_ETH0_HWADDR |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2882 | sbmac_setup_hwaddr(0, SBMAC_ETH0_HWADDR); |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2883 | #endif |
| 2884 | #ifdef SBMAC_ETH1_HWADDR |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2885 | sbmac_setup_hwaddr(1, SBMAC_ETH1_HWADDR); |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2886 | #endif |
| 2887 | #ifdef SBMAC_ETH2_HWADDR |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2888 | sbmac_setup_hwaddr(2, SBMAC_ETH2_HWADDR); |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2889 | #endif |
| 2890 | #ifdef SBMAC_ETH3_HWADDR |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2891 | sbmac_setup_hwaddr(3, SBMAC_ETH3_HWADDR); |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2892 | #endif |
| 2893 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2894 | sbmac_pldev = kcalloc(sbmac_max_units, sizeof(*sbmac_pldev), |
| 2895 | GFP_KERNEL); |
| 2896 | if (!sbmac_pldev) { |
| 2897 | printk(KERN_ERR "%s: unable to allocate memory\n", |
| 2898 | sbmac_string); |
| 2899 | return; |
| 2900 | } |
| 2901 | |
Ralf Baechle | f90fdc3 | 2006-02-08 23:23:26 +0000 | [diff] [blame] | 2902 | /* |
| 2903 | * Walk through the Ethernet controllers and find |
| 2904 | * those who have their MAC addresses set. |
| 2905 | */ |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2906 | for (i = 0; i < sbmac_max_units; i++) |
| 2907 | if (sbmac_platform_probe_one(i)) |
| 2908 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
| 2911 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2912 | static void __exit sbmac_platform_cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | { |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2914 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2915 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2916 | for (i = 0; i < sbmac_max_units; i++) |
| 2917 | platform_device_unregister(sbmac_pldev[i]); |
| 2918 | kfree(sbmac_pldev); |
| 2919 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
Maciej W. Rozycki | f5279ff | 2007-09-21 12:52:10 +0100 | [diff] [blame] | 2921 | |
| 2922 | static struct platform_driver sbmac_driver = { |
| 2923 | .probe = sbmac_probe, |
| 2924 | .remove = __exit_p(sbmac_remove), |
| 2925 | .driver = { |
| 2926 | .name = sbmac_string, |
| 2927 | }, |
| 2928 | }; |
| 2929 | |
| 2930 | static int __init sbmac_init_module(void) |
| 2931 | { |
| 2932 | int err; |
| 2933 | |
| 2934 | err = platform_driver_register(&sbmac_driver); |
| 2935 | if (err) |
| 2936 | return err; |
| 2937 | |
| 2938 | sbmac_platform_probe(); |
| 2939 | |
| 2940 | return err; |
| 2941 | } |
| 2942 | |
| 2943 | static void __exit sbmac_cleanup_module(void) |
| 2944 | { |
| 2945 | sbmac_platform_cleanup(); |
| 2946 | platform_driver_unregister(&sbmac_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | module_init(sbmac_init_module); |
| 2950 | module_exit(sbmac_cleanup_module); |