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