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