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