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