Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This code is derived from the VIA reference driver (copyright message |
| 3 | * below) provided to Red Hat by VIA Networking Technologies, Inc. for |
| 4 | * addition to the Linux kernel. |
| 5 | * |
| 6 | * The code has been merged into one source file, cleaned up to follow |
| 7 | * Linux coding style, ported to the Linux 2.6 kernel tree and cleaned |
| 8 | * for 64bit hardware platforms. |
| 9 | * |
| 10 | * TODO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * rx_copybreak/alignment |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * More testing |
| 13 | * |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 14 | * The changes are (c) Copyright 2004, Red Hat Inc. <alan@lxorguk.ukuu.org.uk> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Additional fixes and clean up: Francois Romieu |
| 16 | * |
| 17 | * This source has not been verified for use in safety critical systems. |
| 18 | * |
| 19 | * Please direct queries about the revamped driver to the linux-kernel |
| 20 | * list not VIA. |
| 21 | * |
| 22 | * Original code: |
| 23 | * |
| 24 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 25 | * All rights reserved. |
| 26 | * |
| 27 | * This software may be redistributed and/or modified under |
| 28 | * the terms of the GNU General Public License as published by the Free |
| 29 | * Software Foundation; either version 2 of the License, or |
| 30 | * any later version. |
| 31 | * |
| 32 | * This program is distributed in the hope that it will be useful, but |
| 33 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 34 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 35 | * for more details. |
| 36 | * |
| 37 | * Author: Chuang Liang-Shing, AJ Jiang |
| 38 | * |
| 39 | * Date: Jan 24, 2003 |
| 40 | * |
| 41 | * MODULE_LICENSE("GPL"); |
| 42 | * |
| 43 | */ |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/module.h> |
| 46 | #include <linux/types.h> |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 47 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/init.h> |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 49 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/mm.h> |
| 51 | #include <linux/errno.h> |
| 52 | #include <linux/ioport.h> |
| 53 | #include <linux/pci.h> |
| 54 | #include <linux/kernel.h> |
| 55 | #include <linux/netdevice.h> |
| 56 | #include <linux/etherdevice.h> |
| 57 | #include <linux/skbuff.h> |
| 58 | #include <linux/delay.h> |
| 59 | #include <linux/timer.h> |
| 60 | #include <linux/slab.h> |
| 61 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <linux/string.h> |
| 63 | #include <linux/wait.h> |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 64 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <linux/if.h> |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 66 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <linux/proc_fs.h> |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 68 | #include <linux/of_address.h> |
| 69 | #include <linux/of_device.h> |
| 70 | #include <linux/of_irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #include <linux/inetdevice.h> |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 72 | #include <linux/platform_device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include <linux/reboot.h> |
| 74 | #include <linux/ethtool.h> |
| 75 | #include <linux/mii.h> |
| 76 | #include <linux/in.h> |
| 77 | #include <linux/if_arp.h> |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 78 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #include <linux/ip.h> |
| 80 | #include <linux/tcp.h> |
| 81 | #include <linux/udp.h> |
| 82 | #include <linux/crc-ccitt.h> |
| 83 | #include <linux/crc32.h> |
| 84 | |
| 85 | #include "via-velocity.h" |
| 86 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 87 | enum velocity_bus_type { |
| 88 | BUS_PCI, |
| 89 | BUS_PLATFORM, |
| 90 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 92 | static int velocity_nics; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | static int msglevel = MSG_LEVEL_INFO; |
| 94 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 95 | static void velocity_set_power_state(struct velocity_info *vptr, char state) |
| 96 | { |
| 97 | void *addr = vptr->mac_regs; |
| 98 | |
| 99 | if (vptr->pdev) |
| 100 | pci_set_power_state(vptr->pdev, state); |
| 101 | else |
| 102 | writeb(state, addr + 0x154); |
| 103 | } |
| 104 | |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 105 | /** |
| 106 | * mac_get_cam_mask - Read a CAM mask |
| 107 | * @regs: register block for this velocity |
| 108 | * @mask: buffer to store mask |
| 109 | * |
| 110 | * Fetch the mask bits of the selected CAM and store them into the |
| 111 | * provided mask buffer. |
| 112 | */ |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 113 | static void mac_get_cam_mask(struct mac_regs __iomem *regs, u8 *mask) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 114 | { |
| 115 | int i; |
| 116 | |
| 117 | /* Select CAM mask */ |
| 118 | BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 119 | |
| 120 | writeb(0, ®s->CAMADDR); |
| 121 | |
| 122 | /* read mask */ |
| 123 | for (i = 0; i < 8; i++) |
| 124 | *mask++ = readb(&(regs->MARCAM[i])); |
| 125 | |
| 126 | /* disable CAMEN */ |
| 127 | writeb(0, ®s->CAMADDR); |
| 128 | |
| 129 | /* Select mar */ |
| 130 | BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 133 | /** |
| 134 | * mac_set_cam_mask - Set a CAM mask |
| 135 | * @regs: register block for this velocity |
| 136 | * @mask: CAM mask to load |
| 137 | * |
| 138 | * Store a new mask into a CAM |
| 139 | */ |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 140 | static void mac_set_cam_mask(struct mac_regs __iomem *regs, u8 *mask) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 141 | { |
| 142 | int i; |
| 143 | /* Select CAM mask */ |
| 144 | BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 145 | |
| 146 | writeb(CAMADDR_CAMEN, ®s->CAMADDR); |
| 147 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 148 | for (i = 0; i < 8; i++) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 149 | writeb(*mask++, &(regs->MARCAM[i])); |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 150 | |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 151 | /* disable CAMEN */ |
| 152 | writeb(0, ®s->CAMADDR); |
| 153 | |
| 154 | /* Select mar */ |
| 155 | BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 156 | } |
| 157 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 158 | static void mac_set_vlan_cam_mask(struct mac_regs __iomem *regs, u8 *mask) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 159 | { |
| 160 | int i; |
| 161 | /* Select CAM mask */ |
| 162 | BYTE_REG_BITS_SET(CAMCR_PS_CAM_MASK, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 163 | |
| 164 | writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL, ®s->CAMADDR); |
| 165 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 166 | for (i = 0; i < 8; i++) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 167 | writeb(*mask++, &(regs->MARCAM[i])); |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 168 | |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 169 | /* disable CAMEN */ |
| 170 | writeb(0, ®s->CAMADDR); |
| 171 | |
| 172 | /* Select mar */ |
| 173 | BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * mac_set_cam - set CAM data |
| 178 | * @regs: register block of this velocity |
| 179 | * @idx: Cam index |
| 180 | * @addr: 2 or 6 bytes of CAM data |
| 181 | * |
| 182 | * Load an address or vlan tag into a CAM |
| 183 | */ |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 184 | static void mac_set_cam(struct mac_regs __iomem *regs, int idx, const u8 *addr) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 185 | { |
| 186 | int i; |
| 187 | |
| 188 | /* Select CAM mask */ |
| 189 | BYTE_REG_BITS_SET(CAMCR_PS_CAM_DATA, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 190 | |
| 191 | idx &= (64 - 1); |
| 192 | |
| 193 | writeb(CAMADDR_CAMEN | idx, ®s->CAMADDR); |
| 194 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 195 | for (i = 0; i < 6; i++) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 196 | writeb(*addr++, &(regs->MARCAM[i])); |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 197 | |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 198 | BYTE_REG_BITS_ON(CAMCR_CAMWR, ®s->CAMCR); |
| 199 | |
| 200 | udelay(10); |
| 201 | |
| 202 | writeb(0, ®s->CAMADDR); |
| 203 | |
| 204 | /* Select mar */ |
| 205 | BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 206 | } |
| 207 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 208 | static void mac_set_vlan_cam(struct mac_regs __iomem *regs, int idx, |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 209 | const u8 *addr) |
| 210 | { |
| 211 | |
| 212 | /* Select CAM mask */ |
| 213 | BYTE_REG_BITS_SET(CAMCR_PS_CAM_DATA, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 214 | |
| 215 | idx &= (64 - 1); |
| 216 | |
| 217 | writeb(CAMADDR_CAMEN | CAMADDR_VCAMSL | idx, ®s->CAMADDR); |
| 218 | writew(*((u16 *) addr), ®s->MARCAM[0]); |
| 219 | |
| 220 | BYTE_REG_BITS_ON(CAMCR_CAMWR, ®s->CAMCR); |
| 221 | |
| 222 | udelay(10); |
| 223 | |
| 224 | writeb(0, ®s->CAMADDR); |
| 225 | |
| 226 | /* Select mar */ |
| 227 | BYTE_REG_BITS_SET(CAMCR_PS_MAR, CAMCR_PS1 | CAMCR_PS0, ®s->CAMCR); |
| 228 | } |
| 229 | |
| 230 | |
| 231 | /** |
| 232 | * mac_wol_reset - reset WOL after exiting low power |
| 233 | * @regs: register block of this velocity |
| 234 | * |
| 235 | * Called after we drop out of wake on lan mode in order to |
| 236 | * reset the Wake on lan features. This function doesn't restore |
| 237 | * the rest of the logic from the result of sleep/wakeup |
| 238 | */ |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 239 | static void mac_wol_reset(struct mac_regs __iomem *regs) |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 240 | { |
| 241 | |
| 242 | /* Turn off SWPTAG right after leaving power mode */ |
| 243 | BYTE_REG_BITS_OFF(STICKHW_SWPTAG, ®s->STICKHW); |
| 244 | /* clear sticky bits */ |
| 245 | BYTE_REG_BITS_OFF((STICKHW_DS1 | STICKHW_DS0), ®s->STICKHW); |
| 246 | |
| 247 | BYTE_REG_BITS_OFF(CHIPGCR_FCGMII, ®s->CHIPGCR); |
| 248 | BYTE_REG_BITS_OFF(CHIPGCR_FCMODE, ®s->CHIPGCR); |
| 249 | /* disable force PME-enable */ |
| 250 | writeb(WOLCFG_PMEOVR, ®s->WOLCFGClr); |
| 251 | /* disable power-event config bit */ |
| 252 | writew(0xFFFF, ®s->WOLCRClr); |
| 253 | /* clear power status */ |
| 254 | writew(0xFFFF, ®s->WOLSRClr); |
| 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 257 | static const struct ethtool_ops velocity_ethtool_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
| 259 | /* |
| 260 | Define module options |
| 261 | */ |
| 262 | |
| 263 | MODULE_AUTHOR("VIA Networking Technologies, Inc."); |
| 264 | MODULE_LICENSE("GPL"); |
| 265 | MODULE_DESCRIPTION("VIA Networking Velocity Family Gigabit Ethernet Adapter Driver"); |
| 266 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 267 | #define VELOCITY_PARAM(N, D) \ |
| 268 | static int N[MAX_UNITS] = OPTION_DEFAULT;\ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | module_param_array(N, int, NULL, 0); \ |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 270 | MODULE_PARM_DESC(N, D); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | #define RX_DESC_MIN 64 |
| 273 | #define RX_DESC_MAX 255 |
| 274 | #define RX_DESC_DEF 64 |
| 275 | VELOCITY_PARAM(RxDescriptors, "Number of receive descriptors"); |
| 276 | |
| 277 | #define TX_DESC_MIN 16 |
| 278 | #define TX_DESC_MAX 256 |
| 279 | #define TX_DESC_DEF 64 |
| 280 | VELOCITY_PARAM(TxDescriptors, "Number of transmit descriptors"); |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | #define RX_THRESH_MIN 0 |
| 283 | #define RX_THRESH_MAX 3 |
| 284 | #define RX_THRESH_DEF 0 |
| 285 | /* rx_thresh[] is used for controlling the receive fifo threshold. |
| 286 | 0: indicate the rxfifo threshold is 128 bytes. |
| 287 | 1: indicate the rxfifo threshold is 512 bytes. |
| 288 | 2: indicate the rxfifo threshold is 1024 bytes. |
| 289 | 3: indicate the rxfifo threshold is store & forward. |
| 290 | */ |
| 291 | VELOCITY_PARAM(rx_thresh, "Receive fifo threshold"); |
| 292 | |
| 293 | #define DMA_LENGTH_MIN 0 |
| 294 | #define DMA_LENGTH_MAX 7 |
Simon Kagstrom | 2a5774f | 2009-11-25 22:10:34 +0000 | [diff] [blame] | 295 | #define DMA_LENGTH_DEF 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | /* DMA_length[] is used for controlling the DMA length |
| 298 | 0: 8 DWORDs |
| 299 | 1: 16 DWORDs |
| 300 | 2: 32 DWORDs |
| 301 | 3: 64 DWORDs |
| 302 | 4: 128 DWORDs |
| 303 | 5: 256 DWORDs |
| 304 | 6: SF(flush till emply) |
| 305 | 7: SF(flush till emply) |
| 306 | */ |
| 307 | VELOCITY_PARAM(DMA_length, "DMA length"); |
| 308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | #define IP_ALIG_DEF 0 |
| 310 | /* IP_byte_align[] is used for IP header DWORD byte aligned |
| 311 | 0: indicate the IP header won't be DWORD byte aligned.(Default) . |
| 312 | 1: indicate the IP header will be DWORD byte aligned. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 313 | In some environment, the IP header should be DWORD byte aligned, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | or the packet will be droped when we receive it. (eg: IPVS) |
| 315 | */ |
| 316 | VELOCITY_PARAM(IP_byte_align, "Enable IP header dword aligned"); |
| 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | #define FLOW_CNTL_DEF 1 |
| 319 | #define FLOW_CNTL_MIN 1 |
| 320 | #define FLOW_CNTL_MAX 5 |
| 321 | |
| 322 | /* flow_control[] is used for setting the flow control ability of NIC. |
| 323 | 1: hardware deafult - AUTO (default). Use Hardware default value in ANAR. |
| 324 | 2: enable TX flow control. |
| 325 | 3: enable RX flow control. |
| 326 | 4: enable RX/TX flow control. |
| 327 | 5: disable |
| 328 | */ |
| 329 | VELOCITY_PARAM(flow_control, "Enable flow control ability"); |
| 330 | |
| 331 | #define MED_LNK_DEF 0 |
| 332 | #define MED_LNK_MIN 0 |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 333 | #define MED_LNK_MAX 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* speed_duplex[] is used for setting the speed and duplex mode of NIC. |
| 335 | 0: indicate autonegotiation for both speed and duplex mode |
| 336 | 1: indicate 100Mbps half duplex mode |
| 337 | 2: indicate 100Mbps full duplex mode |
| 338 | 3: indicate 10Mbps half duplex mode |
| 339 | 4: indicate 10Mbps full duplex mode |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 340 | 5: indicate 1000Mbps full duplex mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | Note: |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 343 | if EEPROM have been set to the force mode, this option is ignored |
| 344 | by driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | */ |
| 346 | VELOCITY_PARAM(speed_duplex, "Setting the speed and duplex mode"); |
| 347 | |
| 348 | #define VAL_PKT_LEN_DEF 0 |
| 349 | /* ValPktLen[] is used for setting the checksum offload ability of NIC. |
| 350 | 0: Receive frame with invalid layer 2 length (Default) |
| 351 | 1: Drop frame with invalid layer 2 length |
| 352 | */ |
| 353 | VELOCITY_PARAM(ValPktLen, "Receiving or Drop invalid 802.3 frame"); |
| 354 | |
| 355 | #define WOL_OPT_DEF 0 |
| 356 | #define WOL_OPT_MIN 0 |
| 357 | #define WOL_OPT_MAX 7 |
| 358 | /* wol_opts[] is used for controlling wake on lan behavior. |
| 359 | 0: Wake up if recevied a magic packet. (Default) |
| 360 | 1: Wake up if link status is on/off. |
| 361 | 2: Wake up if recevied an arp packet. |
| 362 | 4: Wake up if recevied any unicast packet. |
| 363 | Those value can be sumed up to support more than one option. |
| 364 | */ |
| 365 | VELOCITY_PARAM(wol_opts, "Wake On Lan options"); |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | static int rx_copybreak = 200; |
| 368 | module_param(rx_copybreak, int, 0644); |
| 369 | MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames"); |
| 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* |
| 372 | * Internal board variants. At the moment we have only one |
| 373 | */ |
Andrew Morton | 4f14b92 | 2008-02-09 23:41:40 -0800 | [diff] [blame] | 374 | static struct velocity_info_tbl chip_info_table[] = { |
Jeff Garzik | cabb766 | 2006-06-27 09:25:28 -0400 | [diff] [blame] | 375 | {CHIP_TYPE_VT6110, "VIA Networking Velocity Family Gigabit Ethernet Adapter", 1, 0x00FFFFFFUL}, |
| 376 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | /* |
| 380 | * Describe the PCI device identifiers that we support in this |
| 381 | * device driver. Used for hotplug autoloading. |
| 382 | */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 383 | |
| 384 | static DEFINE_PCI_DEVICE_TABLE(velocity_pci_id_table) = { |
Jeff Garzik | e54f489 | 2006-06-27 09:20:08 -0400 | [diff] [blame] | 385 | { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_612X) }, |
| 386 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | }; |
| 388 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 389 | MODULE_DEVICE_TABLE(pci, velocity_pci_id_table); |
| 390 | |
| 391 | /** |
| 392 | * Describe the OF device identifiers that we support in this |
| 393 | * device driver. Used for devicetree nodes. |
| 394 | */ |
| 395 | static struct of_device_id velocity_of_ids[] = { |
| 396 | { .compatible = "via,velocity-vt6110", .data = &chip_info_table[0] }, |
| 397 | { /* Sentinel */ }, |
| 398 | }; |
| 399 | MODULE_DEVICE_TABLE(of, velocity_of_ids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | /** |
| 402 | * get_chip_name - identifier to name |
| 403 | * @id: chip identifier |
| 404 | * |
| 405 | * Given a chip identifier return a suitable description. Returns |
| 406 | * a pointer a static string valid while the driver is loaded. |
| 407 | */ |
Bill Pemberton | 27add00 | 2012-12-03 09:23:49 -0500 | [diff] [blame] | 408 | static const char *get_chip_name(enum chip_type chip_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | { |
| 410 | int i; |
| 411 | for (i = 0; chip_info_table[i].name != NULL; i++) |
| 412 | if (chip_info_table[i].chip_id == chip_id) |
| 413 | break; |
| 414 | return chip_info_table[i].name; |
| 415 | } |
| 416 | |
| 417 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | * velocity_set_int_opt - parser for integer options |
| 419 | * @opt: pointer to option value |
| 420 | * @val: value the user requested (or -1 for default) |
| 421 | * @min: lowest value allowed |
| 422 | * @max: highest value allowed |
| 423 | * @def: default value |
| 424 | * @name: property name |
| 425 | * @dev: device name |
| 426 | * |
| 427 | * Set an integer property in the module options. This function does |
| 428 | * all the verification and checking as well as reporting so that |
| 429 | * we don't duplicate code for each option. |
| 430 | */ |
Bill Pemberton | 27add00 | 2012-12-03 09:23:49 -0500 | [diff] [blame] | 431 | static void velocity_set_int_opt(int *opt, int val, int min, int max, int def, |
| 432 | char *name, const char *devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | { |
| 434 | if (val == -1) |
| 435 | *opt = def; |
| 436 | else if (val < min || val > max) { |
| 437 | VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (%d-%d)\n", |
| 438 | devname, name, min, max); |
| 439 | *opt = def; |
| 440 | } else { |
| 441 | VELOCITY_PRT(MSG_LEVEL_INFO, KERN_INFO "%s: set value of parameter %s to %d\n", |
| 442 | devname, name, val); |
| 443 | *opt = val; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * velocity_set_bool_opt - parser for boolean options |
| 449 | * @opt: pointer to option value |
| 450 | * @val: value the user requested (or -1 for default) |
| 451 | * @def: default value (yes/no) |
| 452 | * @flag: numeric value to set for true. |
| 453 | * @name: property name |
| 454 | * @dev: device name |
| 455 | * |
| 456 | * Set a boolean property in the module options. This function does |
| 457 | * all the verification and checking as well as reporting so that |
| 458 | * we don't duplicate code for each option. |
| 459 | */ |
Bill Pemberton | 27add00 | 2012-12-03 09:23:49 -0500 | [diff] [blame] | 460 | static void velocity_set_bool_opt(u32 *opt, int val, int def, u32 flag, |
| 461 | char *name, const char *devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
| 463 | (*opt) &= (~flag); |
| 464 | if (val == -1) |
| 465 | *opt |= (def ? flag : 0); |
| 466 | else if (val < 0 || val > 1) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 467 | printk(KERN_NOTICE "%s: the value of parameter %s is invalid, the valid range is (0-1)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | devname, name); |
| 469 | *opt |= (def ? flag : 0); |
| 470 | } else { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 471 | printk(KERN_INFO "%s: set parameter %s to %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | devname, name, val ? "TRUE" : "FALSE"); |
| 473 | *opt |= (val ? flag : 0); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * velocity_get_options - set options on device |
| 479 | * @opts: option structure for the device |
| 480 | * @index: index of option to use in module options array |
| 481 | * @devname: device name |
| 482 | * |
| 483 | * Turn the module and command options into a single structure |
| 484 | * for the current device |
| 485 | */ |
Bill Pemberton | 27add00 | 2012-12-03 09:23:49 -0500 | [diff] [blame] | 486 | static void velocity_get_options(struct velocity_opt *opts, int index, |
| 487 | const char *devname) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
| 489 | |
| 490 | velocity_set_int_opt(&opts->rx_thresh, rx_thresh[index], RX_THRESH_MIN, RX_THRESH_MAX, RX_THRESH_DEF, "rx_thresh", devname); |
| 491 | velocity_set_int_opt(&opts->DMA_length, DMA_length[index], DMA_LENGTH_MIN, DMA_LENGTH_MAX, DMA_LENGTH_DEF, "DMA_length", devname); |
| 492 | velocity_set_int_opt(&opts->numrx, RxDescriptors[index], RX_DESC_MIN, RX_DESC_MAX, RX_DESC_DEF, "RxDescriptors", devname); |
| 493 | velocity_set_int_opt(&opts->numtx, TxDescriptors[index], TX_DESC_MIN, TX_DESC_MAX, TX_DESC_DEF, "TxDescriptors", devname); |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | velocity_set_int_opt(&opts->flow_cntl, flow_control[index], FLOW_CNTL_MIN, FLOW_CNTL_MAX, FLOW_CNTL_DEF, "flow_control", devname); |
| 496 | velocity_set_bool_opt(&opts->flags, IP_byte_align[index], IP_ALIG_DEF, VELOCITY_FLAGS_IP_ALIGN, "IP_byte_align", devname); |
| 497 | velocity_set_bool_opt(&opts->flags, ValPktLen[index], VAL_PKT_LEN_DEF, VELOCITY_FLAGS_VAL_PKT_LEN, "ValPktLen", devname); |
| 498 | velocity_set_int_opt((int *) &opts->spd_dpx, speed_duplex[index], MED_LNK_MIN, MED_LNK_MAX, MED_LNK_DEF, "Media link mode", devname); |
Joe Perches | 6469933 | 2012-06-04 12:44:16 +0000 | [diff] [blame] | 499 | velocity_set_int_opt(&opts->wol_opts, wol_opts[index], WOL_OPT_MIN, WOL_OPT_MAX, WOL_OPT_DEF, "Wake On Lan options", devname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | opts->numrx = (opts->numrx & ~3); |
| 501 | } |
| 502 | |
| 503 | /** |
| 504 | * velocity_init_cam_filter - initialise CAM |
| 505 | * @vptr: velocity to program |
| 506 | * |
| 507 | * Initialize the content addressable memory used for filters. Load |
| 508 | * appropriately according to the presence of VLAN |
| 509 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | static void velocity_init_cam_filter(struct velocity_info *vptr) |
| 511 | { |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 512 | struct mac_regs __iomem *regs = vptr->mac_regs; |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 513 | unsigned int vid, i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* Turn on MCFG_PQEN, turn off MCFG_RTGOPT */ |
| 516 | WORD_REG_BITS_SET(MCFG_PQEN, MCFG_RTGOPT, ®s->MCFG); |
| 517 | WORD_REG_BITS_ON(MCFG_VIDFR, ®s->MCFG); |
| 518 | |
| 519 | /* Disable all CAMs */ |
| 520 | memset(vptr->vCAMmask, 0, sizeof(u8) * 8); |
| 521 | memset(vptr->mCAMmask, 0, sizeof(u8) * 8); |
Stephen Hemminger | 01faccb | 2007-08-24 14:40:45 -0700 | [diff] [blame] | 522 | mac_set_vlan_cam_mask(regs, vptr->vCAMmask); |
| 523 | mac_set_cam_mask(regs, vptr->mCAMmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Francois Romieu | d4f73c8 | 2008-04-24 23:32:33 +0200 | [diff] [blame] | 525 | /* Enable VCAMs */ |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 526 | for_each_set_bit(vid, vptr->active_vlans, VLAN_N_VID) { |
| 527 | mac_set_vlan_cam(regs, i, (u8 *) &vid); |
| 528 | vptr->vCAMmask[i / 8] |= 0x1 << (i % 8); |
| 529 | if (++i >= VCAM_SIZE) |
| 530 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 532 | mac_set_vlan_cam_mask(regs, vptr->vCAMmask); |
Francois Romieu | d4f73c8 | 2008-04-24 23:32:33 +0200 | [diff] [blame] | 533 | } |
| 534 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 535 | static int velocity_vlan_rx_add_vid(struct net_device *dev, |
| 536 | __be16 proto, u16 vid) |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 537 | { |
| 538 | struct velocity_info *vptr = netdev_priv(dev); |
| 539 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 540 | spin_lock_irq(&vptr->lock); |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 541 | set_bit(vid, vptr->active_vlans); |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 542 | velocity_init_cam_filter(vptr); |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 543 | spin_unlock_irq(&vptr->lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 544 | return 0; |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 545 | } |
| 546 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 547 | static int velocity_vlan_rx_kill_vid(struct net_device *dev, |
| 548 | __be16 proto, u16 vid) |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 549 | { |
| 550 | struct velocity_info *vptr = netdev_priv(dev); |
| 551 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 552 | spin_lock_irq(&vptr->lock); |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 553 | clear_bit(vid, vptr->active_vlans); |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 554 | velocity_init_cam_filter(vptr); |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 555 | spin_unlock_irq(&vptr->lock); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 556 | return 0; |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 557 | } |
| 558 | |
Francois Romieu | 3c4dc71 | 2008-07-31 22:51:18 +0200 | [diff] [blame] | 559 | static void velocity_init_rx_ring_indexes(struct velocity_info *vptr) |
| 560 | { |
| 561 | vptr->rx.dirty = vptr->rx.filled = vptr->rx.curr = 0; |
| 562 | } |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /** |
| 565 | * velocity_rx_reset - handle a receive reset |
| 566 | * @vptr: velocity we are resetting |
| 567 | * |
| 568 | * Reset the ownership and status for the receive ring side. |
| 569 | * Hand all the receive queue to the NIC. |
| 570 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | static void velocity_rx_reset(struct velocity_info *vptr) |
| 572 | { |
| 573 | |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 574 | struct mac_regs __iomem *regs = vptr->mac_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | int i; |
| 576 | |
Francois Romieu | 3c4dc71 | 2008-07-31 22:51:18 +0200 | [diff] [blame] | 577 | velocity_init_rx_ring_indexes(vptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | /* |
| 580 | * Init state, all RD entries belong to the NIC |
| 581 | */ |
| 582 | for (i = 0; i < vptr->options.numrx; ++i) |
Francois Romieu | 0fe9f15 | 2008-07-31 22:10:10 +0200 | [diff] [blame] | 583 | vptr->rx.ring[i].rdesc0.len |= OWNED_BY_NIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
| 585 | writew(vptr->options.numrx, ®s->RBRDU); |
Francois Romieu | 0fe9f15 | 2008-07-31 22:10:10 +0200 | [diff] [blame] | 586 | writel(vptr->rx.pool_dma, ®s->RDBaseLo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | writew(0, ®s->RDIdx); |
| 588 | writew(vptr->options.numrx - 1, ®s->RDCSize); |
| 589 | } |
| 590 | |
| 591 | /** |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 592 | * velocity_get_opt_media_mode - get media selection |
| 593 | * @vptr: velocity adapter |
| 594 | * |
| 595 | * Get the media mode stored in EEPROM or module options and load |
| 596 | * mii_status accordingly. The requested link state information |
| 597 | * is also returned. |
| 598 | */ |
| 599 | static u32 velocity_get_opt_media_mode(struct velocity_info *vptr) |
| 600 | { |
| 601 | u32 status = 0; |
| 602 | |
| 603 | switch (vptr->options.spd_dpx) { |
| 604 | case SPD_DPX_AUTO: |
| 605 | status = VELOCITY_AUTONEG_ENABLE; |
| 606 | break; |
| 607 | case SPD_DPX_100_FULL: |
| 608 | status = VELOCITY_SPEED_100 | VELOCITY_DUPLEX_FULL; |
| 609 | break; |
| 610 | case SPD_DPX_10_FULL: |
| 611 | status = VELOCITY_SPEED_10 | VELOCITY_DUPLEX_FULL; |
| 612 | break; |
| 613 | case SPD_DPX_100_HALF: |
| 614 | status = VELOCITY_SPEED_100; |
| 615 | break; |
| 616 | case SPD_DPX_10_HALF: |
| 617 | status = VELOCITY_SPEED_10; |
| 618 | break; |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 619 | case SPD_DPX_1000_FULL: |
| 620 | status = VELOCITY_SPEED_1000 | VELOCITY_DUPLEX_FULL; |
| 621 | break; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 622 | } |
| 623 | vptr->mii_status = status; |
| 624 | return status; |
| 625 | } |
| 626 | |
| 627 | /** |
| 628 | * safe_disable_mii_autopoll - autopoll off |
| 629 | * @regs: velocity registers |
| 630 | * |
| 631 | * Turn off the autopoll and wait for it to disable on the chip |
| 632 | */ |
| 633 | static void safe_disable_mii_autopoll(struct mac_regs __iomem *regs) |
| 634 | { |
| 635 | u16 ww; |
| 636 | |
| 637 | /* turn off MAUTO */ |
| 638 | writeb(0, ®s->MIICR); |
| 639 | for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { |
| 640 | udelay(1); |
| 641 | if (BYTE_REG_BITS_IS_ON(MIISR_MIDLE, ®s->MIISR)) |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | |
| 646 | /** |
| 647 | * enable_mii_autopoll - turn on autopolling |
| 648 | * @regs: velocity registers |
| 649 | * |
| 650 | * Enable the MII link status autopoll feature on the Velocity |
| 651 | * hardware. Wait for it to enable. |
| 652 | */ |
| 653 | static void enable_mii_autopoll(struct mac_regs __iomem *regs) |
| 654 | { |
| 655 | int ii; |
| 656 | |
| 657 | writeb(0, &(regs->MIICR)); |
| 658 | writeb(MIIADR_SWMPL, ®s->MIIADR); |
| 659 | |
| 660 | for (ii = 0; ii < W_MAX_TIMEOUT; ii++) { |
| 661 | udelay(1); |
| 662 | if (BYTE_REG_BITS_IS_ON(MIISR_MIDLE, ®s->MIISR)) |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | writeb(MIICR_MAUTO, ®s->MIICR); |
| 667 | |
| 668 | for (ii = 0; ii < W_MAX_TIMEOUT; ii++) { |
| 669 | udelay(1); |
| 670 | if (!BYTE_REG_BITS_IS_ON(MIISR_MIDLE, ®s->MIISR)) |
| 671 | break; |
| 672 | } |
| 673 | |
| 674 | } |
| 675 | |
| 676 | /** |
| 677 | * velocity_mii_read - read MII data |
| 678 | * @regs: velocity registers |
| 679 | * @index: MII register index |
| 680 | * @data: buffer for received data |
| 681 | * |
| 682 | * Perform a single read of an MII 16bit register. Returns zero |
| 683 | * on success or -ETIMEDOUT if the PHY did not respond. |
| 684 | */ |
| 685 | static int velocity_mii_read(struct mac_regs __iomem *regs, u8 index, u16 *data) |
| 686 | { |
| 687 | u16 ww; |
| 688 | |
| 689 | /* |
| 690 | * Disable MIICR_MAUTO, so that mii addr can be set normally |
| 691 | */ |
| 692 | safe_disable_mii_autopoll(regs); |
| 693 | |
| 694 | writeb(index, ®s->MIIADR); |
| 695 | |
| 696 | BYTE_REG_BITS_ON(MIICR_RCMD, ®s->MIICR); |
| 697 | |
| 698 | for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { |
| 699 | if (!(readb(®s->MIICR) & MIICR_RCMD)) |
| 700 | break; |
| 701 | } |
| 702 | |
| 703 | *data = readw(®s->MIIDATA); |
| 704 | |
| 705 | enable_mii_autopoll(regs); |
| 706 | if (ww == W_MAX_TIMEOUT) |
| 707 | return -ETIMEDOUT; |
| 708 | return 0; |
| 709 | } |
| 710 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 711 | /** |
| 712 | * mii_check_media_mode - check media state |
| 713 | * @regs: velocity registers |
| 714 | * |
| 715 | * Check the current MII status and determine the link status |
| 716 | * accordingly |
| 717 | */ |
| 718 | static u32 mii_check_media_mode(struct mac_regs __iomem *regs) |
| 719 | { |
| 720 | u32 status = 0; |
| 721 | u16 ANAR; |
| 722 | |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 723 | if (!MII_REG_BITS_IS_ON(BMSR_LSTATUS, MII_BMSR, regs)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 724 | status |= VELOCITY_LINK_FAIL; |
| 725 | |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 726 | if (MII_REG_BITS_IS_ON(ADVERTISE_1000FULL, MII_CTRL1000, regs)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 727 | status |= VELOCITY_SPEED_1000 | VELOCITY_DUPLEX_FULL; |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 728 | else if (MII_REG_BITS_IS_ON(ADVERTISE_1000HALF, MII_CTRL1000, regs)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 729 | status |= (VELOCITY_SPEED_1000); |
| 730 | else { |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 731 | velocity_mii_read(regs, MII_ADVERTISE, &ANAR); |
| 732 | if (ANAR & ADVERTISE_100FULL) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 733 | status |= (VELOCITY_SPEED_100 | VELOCITY_DUPLEX_FULL); |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 734 | else if (ANAR & ADVERTISE_100HALF) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 735 | status |= VELOCITY_SPEED_100; |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 736 | else if (ANAR & ADVERTISE_10FULL) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 737 | status |= (VELOCITY_SPEED_10 | VELOCITY_DUPLEX_FULL); |
| 738 | else |
| 739 | status |= (VELOCITY_SPEED_10); |
| 740 | } |
| 741 | |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 742 | if (MII_REG_BITS_IS_ON(BMCR_ANENABLE, MII_BMCR, regs)) { |
| 743 | velocity_mii_read(regs, MII_ADVERTISE, &ANAR); |
| 744 | if ((ANAR & (ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | ADVERTISE_10HALF)) |
| 745 | == (ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | ADVERTISE_10HALF)) { |
| 746 | if (MII_REG_BITS_IS_ON(ADVERTISE_1000HALF | ADVERTISE_1000FULL, MII_CTRL1000, regs)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 747 | status |= VELOCITY_AUTONEG_ENABLE; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | return status; |
| 752 | } |
| 753 | |
| 754 | /** |
| 755 | * velocity_mii_write - write MII data |
| 756 | * @regs: velocity registers |
| 757 | * @index: MII register index |
| 758 | * @data: 16bit data for the MII register |
| 759 | * |
| 760 | * Perform a single write to an MII 16bit register. Returns zero |
| 761 | * on success or -ETIMEDOUT if the PHY did not respond. |
| 762 | */ |
| 763 | static int velocity_mii_write(struct mac_regs __iomem *regs, u8 mii_addr, u16 data) |
| 764 | { |
| 765 | u16 ww; |
| 766 | |
| 767 | /* |
| 768 | * Disable MIICR_MAUTO, so that mii addr can be set normally |
| 769 | */ |
| 770 | safe_disable_mii_autopoll(regs); |
| 771 | |
| 772 | /* MII reg offset */ |
| 773 | writeb(mii_addr, ®s->MIIADR); |
| 774 | /* set MII data */ |
| 775 | writew(data, ®s->MIIDATA); |
| 776 | |
| 777 | /* turn on MIICR_WCMD */ |
| 778 | BYTE_REG_BITS_ON(MIICR_WCMD, ®s->MIICR); |
| 779 | |
| 780 | /* W_MAX_TIMEOUT is the timeout period */ |
| 781 | for (ww = 0; ww < W_MAX_TIMEOUT; ww++) { |
| 782 | udelay(5); |
| 783 | if (!(readb(®s->MIICR) & MIICR_WCMD)) |
| 784 | break; |
| 785 | } |
| 786 | enable_mii_autopoll(regs); |
| 787 | |
| 788 | if (ww == W_MAX_TIMEOUT) |
| 789 | return -ETIMEDOUT; |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | /** |
| 794 | * set_mii_flow_control - flow control setup |
| 795 | * @vptr: velocity interface |
| 796 | * |
| 797 | * Set up the flow control on this interface according to |
| 798 | * the supplied user/eeprom options. |
| 799 | */ |
| 800 | static void set_mii_flow_control(struct velocity_info *vptr) |
| 801 | { |
| 802 | /*Enable or Disable PAUSE in ANAR */ |
| 803 | switch (vptr->options.flow_cntl) { |
| 804 | case FLOW_CNTL_TX: |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 805 | MII_REG_BITS_OFF(ADVERTISE_PAUSE_CAP, MII_ADVERTISE, vptr->mac_regs); |
| 806 | MII_REG_BITS_ON(ADVERTISE_PAUSE_ASYM, MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 807 | break; |
| 808 | |
| 809 | case FLOW_CNTL_RX: |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 810 | MII_REG_BITS_ON(ADVERTISE_PAUSE_CAP, MII_ADVERTISE, vptr->mac_regs); |
| 811 | MII_REG_BITS_ON(ADVERTISE_PAUSE_ASYM, MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 812 | break; |
| 813 | |
| 814 | case FLOW_CNTL_TX_RX: |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 815 | MII_REG_BITS_ON(ADVERTISE_PAUSE_CAP, MII_ADVERTISE, vptr->mac_regs); |
David S. Miller | 4a35ecf | 2010-04-06 23:53:30 -0700 | [diff] [blame] | 816 | MII_REG_BITS_OFF(ADVERTISE_PAUSE_ASYM, MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 817 | break; |
| 818 | |
| 819 | case FLOW_CNTL_DISABLE: |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 820 | MII_REG_BITS_OFF(ADVERTISE_PAUSE_CAP, MII_ADVERTISE, vptr->mac_regs); |
| 821 | MII_REG_BITS_OFF(ADVERTISE_PAUSE_ASYM, MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 822 | break; |
| 823 | default: |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | /** |
| 829 | * mii_set_auto_on - autonegotiate on |
| 830 | * @vptr: velocity |
| 831 | * |
| 832 | * Enable autonegotation on this interface |
| 833 | */ |
| 834 | static void mii_set_auto_on(struct velocity_info *vptr) |
| 835 | { |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 836 | if (MII_REG_BITS_IS_ON(BMCR_ANENABLE, MII_BMCR, vptr->mac_regs)) |
| 837 | MII_REG_BITS_ON(BMCR_ANRESTART, MII_BMCR, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 838 | else |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 839 | MII_REG_BITS_ON(BMCR_ANENABLE, MII_BMCR, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | static u32 check_connection_type(struct mac_regs __iomem *regs) |
| 843 | { |
| 844 | u32 status = 0; |
| 845 | u8 PHYSR0; |
| 846 | u16 ANAR; |
| 847 | PHYSR0 = readb(®s->PHYSR0); |
| 848 | |
| 849 | /* |
| 850 | if (!(PHYSR0 & PHYSR0_LINKGD)) |
| 851 | status|=VELOCITY_LINK_FAIL; |
| 852 | */ |
| 853 | |
| 854 | if (PHYSR0 & PHYSR0_FDPX) |
| 855 | status |= VELOCITY_DUPLEX_FULL; |
| 856 | |
| 857 | if (PHYSR0 & PHYSR0_SPDG) |
| 858 | status |= VELOCITY_SPEED_1000; |
| 859 | else if (PHYSR0 & PHYSR0_SPD10) |
| 860 | status |= VELOCITY_SPEED_10; |
| 861 | else |
| 862 | status |= VELOCITY_SPEED_100; |
| 863 | |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 864 | if (MII_REG_BITS_IS_ON(BMCR_ANENABLE, MII_BMCR, regs)) { |
| 865 | velocity_mii_read(regs, MII_ADVERTISE, &ANAR); |
| 866 | if ((ANAR & (ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | ADVERTISE_10HALF)) |
| 867 | == (ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | ADVERTISE_10HALF)) { |
| 868 | if (MII_REG_BITS_IS_ON(ADVERTISE_1000HALF | ADVERTISE_1000FULL, MII_CTRL1000, regs)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 869 | status |= VELOCITY_AUTONEG_ENABLE; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | return status; |
| 874 | } |
| 875 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 876 | /** |
| 877 | * velocity_set_media_mode - set media mode |
| 878 | * @mii_status: old MII link state |
| 879 | * |
| 880 | * Check the media link state and configure the flow control |
| 881 | * PHY and also velocity hardware setup accordingly. In particular |
| 882 | * we need to set up CD polling and frame bursting. |
| 883 | */ |
| 884 | static int velocity_set_media_mode(struct velocity_info *vptr, u32 mii_status) |
| 885 | { |
| 886 | u32 curr_status; |
| 887 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 888 | |
| 889 | vptr->mii_status = mii_check_media_mode(vptr->mac_regs); |
| 890 | curr_status = vptr->mii_status & (~VELOCITY_LINK_FAIL); |
| 891 | |
| 892 | /* Set mii link status */ |
| 893 | set_mii_flow_control(vptr); |
| 894 | |
| 895 | /* |
Uwe Kleine-König | a34f0b3 | 2010-12-10 14:55:42 +0100 | [diff] [blame] | 896 | Check if new status is consistent with current status |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 897 | if (((mii_status & curr_status) & VELOCITY_AUTONEG_ENABLE) || |
| 898 | (mii_status==curr_status)) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 899 | vptr->mii_status=mii_check_media_mode(vptr->mac_regs); |
| 900 | vptr->mii_status=check_connection_type(vptr->mac_regs); |
| 901 | VELOCITY_PRT(MSG_LEVEL_INFO, "Velocity link no change\n"); |
| 902 | return 0; |
| 903 | } |
| 904 | */ |
| 905 | |
| 906 | if (PHYID_GET_PHY_ID(vptr->phy_id) == PHYID_CICADA_CS8201) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 907 | MII_REG_BITS_ON(AUXCR_MDPPS, MII_NCONFIG, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 908 | |
| 909 | /* |
| 910 | * If connection type is AUTO |
| 911 | */ |
| 912 | if (mii_status & VELOCITY_AUTONEG_ENABLE) { |
| 913 | VELOCITY_PRT(MSG_LEVEL_INFO, "Velocity is AUTO mode\n"); |
| 914 | /* clear force MAC mode bit */ |
| 915 | BYTE_REG_BITS_OFF(CHIPGCR_FCMODE, ®s->CHIPGCR); |
| 916 | /* set duplex mode of MAC according to duplex mode of MII */ |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 917 | MII_REG_BITS_ON(ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | ADVERTISE_10HALF, MII_ADVERTISE, vptr->mac_regs); |
| 918 | MII_REG_BITS_ON(ADVERTISE_1000FULL | ADVERTISE_1000HALF, MII_CTRL1000, vptr->mac_regs); |
| 919 | MII_REG_BITS_ON(BMCR_SPEED1000, MII_BMCR, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 920 | |
| 921 | /* enable AUTO-NEGO mode */ |
| 922 | mii_set_auto_on(vptr); |
| 923 | } else { |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 924 | u16 CTRL1000; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 925 | u16 ANAR; |
| 926 | u8 CHIPGCR; |
| 927 | |
| 928 | /* |
| 929 | * 1. if it's 3119, disable frame bursting in halfduplex mode |
| 930 | * and enable it in fullduplex mode |
| 931 | * 2. set correct MII/GMII and half/full duplex mode in CHIPGCR |
| 932 | * 3. only enable CD heart beat counter in 10HD mode |
| 933 | */ |
| 934 | |
| 935 | /* set force MAC mode bit */ |
| 936 | BYTE_REG_BITS_ON(CHIPGCR_FCMODE, ®s->CHIPGCR); |
| 937 | |
| 938 | CHIPGCR = readb(®s->CHIPGCR); |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 939 | |
| 940 | if (mii_status & VELOCITY_SPEED_1000) |
| 941 | CHIPGCR |= CHIPGCR_FCGMII; |
| 942 | else |
| 943 | CHIPGCR &= ~CHIPGCR_FCGMII; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 944 | |
| 945 | if (mii_status & VELOCITY_DUPLEX_FULL) { |
| 946 | CHIPGCR |= CHIPGCR_FCFDX; |
| 947 | writeb(CHIPGCR, ®s->CHIPGCR); |
| 948 | VELOCITY_PRT(MSG_LEVEL_INFO, "set Velocity to forced full mode\n"); |
| 949 | if (vptr->rev_id < REV_ID_VT3216_A0) |
| 950 | BYTE_REG_BITS_OFF(TCR_TB2BDIS, ®s->TCR); |
| 951 | } else { |
| 952 | CHIPGCR &= ~CHIPGCR_FCFDX; |
| 953 | VELOCITY_PRT(MSG_LEVEL_INFO, "set Velocity to forced half mode\n"); |
| 954 | writeb(CHIPGCR, ®s->CHIPGCR); |
| 955 | if (vptr->rev_id < REV_ID_VT3216_A0) |
| 956 | BYTE_REG_BITS_ON(TCR_TB2BDIS, ®s->TCR); |
| 957 | } |
| 958 | |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 959 | velocity_mii_read(vptr->mac_regs, MII_CTRL1000, &CTRL1000); |
| 960 | CTRL1000 &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 961 | if ((mii_status & VELOCITY_SPEED_1000) && |
| 962 | (mii_status & VELOCITY_DUPLEX_FULL)) { |
| 963 | CTRL1000 |= ADVERTISE_1000FULL; |
| 964 | } |
| 965 | velocity_mii_write(vptr->mac_regs, MII_CTRL1000, CTRL1000); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 966 | |
| 967 | if (!(mii_status & VELOCITY_DUPLEX_FULL) && (mii_status & VELOCITY_SPEED_10)) |
| 968 | BYTE_REG_BITS_OFF(TESTCFG_HBDIS, ®s->TESTCFG); |
| 969 | else |
| 970 | BYTE_REG_BITS_ON(TESTCFG_HBDIS, ®s->TESTCFG); |
| 971 | |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 972 | /* MII_REG_BITS_OFF(BMCR_SPEED1000, MII_BMCR, vptr->mac_regs); */ |
| 973 | velocity_mii_read(vptr->mac_regs, MII_ADVERTISE, &ANAR); |
| 974 | ANAR &= (~(ADVERTISE_100FULL | ADVERTISE_100HALF | ADVERTISE_10FULL | ADVERTISE_10HALF)); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 975 | if (mii_status & VELOCITY_SPEED_100) { |
| 976 | if (mii_status & VELOCITY_DUPLEX_FULL) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 977 | ANAR |= ADVERTISE_100FULL; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 978 | else |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 979 | ANAR |= ADVERTISE_100HALF; |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 980 | } else if (mii_status & VELOCITY_SPEED_10) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 981 | if (mii_status & VELOCITY_DUPLEX_FULL) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 982 | ANAR |= ADVERTISE_10FULL; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 983 | else |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 984 | ANAR |= ADVERTISE_10HALF; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 985 | } |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 986 | velocity_mii_write(vptr->mac_regs, MII_ADVERTISE, ANAR); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 987 | /* enable AUTO-NEGO mode */ |
| 988 | mii_set_auto_on(vptr); |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 989 | /* MII_REG_BITS_ON(BMCR_ANENABLE, MII_BMCR, vptr->mac_regs); */ |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 990 | } |
| 991 | /* vptr->mii_status=mii_check_media_mode(vptr->mac_regs); */ |
| 992 | /* vptr->mii_status=check_connection_type(vptr->mac_regs); */ |
| 993 | return VELOCITY_LINK_CHANGE; |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * velocity_print_link_status - link status reporting |
| 998 | * @vptr: velocity to report on |
| 999 | * |
| 1000 | * Turn the link status of the velocity card into a kernel log |
| 1001 | * description of the new link state, detailing speed and duplex |
| 1002 | * status |
| 1003 | */ |
| 1004 | static void velocity_print_link_status(struct velocity_info *vptr) |
| 1005 | { |
| 1006 | |
| 1007 | if (vptr->mii_status & VELOCITY_LINK_FAIL) { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1008 | VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: failed to detect cable link\n", vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1009 | } else if (vptr->options.spd_dpx == SPD_DPX_AUTO) { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1010 | VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: Link auto-negotiation", vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1011 | |
| 1012 | if (vptr->mii_status & VELOCITY_SPEED_1000) |
| 1013 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 1000M bps"); |
| 1014 | else if (vptr->mii_status & VELOCITY_SPEED_100) |
| 1015 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 100M bps"); |
| 1016 | else |
| 1017 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 10M bps"); |
| 1018 | |
| 1019 | if (vptr->mii_status & VELOCITY_DUPLEX_FULL) |
| 1020 | VELOCITY_PRT(MSG_LEVEL_INFO, " full duplex\n"); |
| 1021 | else |
| 1022 | VELOCITY_PRT(MSG_LEVEL_INFO, " half duplex\n"); |
| 1023 | } else { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1024 | VELOCITY_PRT(MSG_LEVEL_INFO, KERN_NOTICE "%s: Link forced", vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1025 | switch (vptr->options.spd_dpx) { |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 1026 | case SPD_DPX_1000_FULL: |
| 1027 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 1000M bps full duplex\n"); |
| 1028 | break; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1029 | case SPD_DPX_100_HALF: |
| 1030 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 100M bps half duplex\n"); |
| 1031 | break; |
| 1032 | case SPD_DPX_100_FULL: |
| 1033 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 100M bps full duplex\n"); |
| 1034 | break; |
| 1035 | case SPD_DPX_10_HALF: |
| 1036 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 10M bps half duplex\n"); |
| 1037 | break; |
| 1038 | case SPD_DPX_10_FULL: |
| 1039 | VELOCITY_PRT(MSG_LEVEL_INFO, " speed 10M bps full duplex\n"); |
| 1040 | break; |
| 1041 | default: |
| 1042 | break; |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * enable_flow_control_ability - flow control |
| 1049 | * @vptr: veloity to configure |
| 1050 | * |
| 1051 | * Set up flow control according to the flow control options |
| 1052 | * determined by the eeprom/configuration. |
| 1053 | */ |
| 1054 | static void enable_flow_control_ability(struct velocity_info *vptr) |
| 1055 | { |
| 1056 | |
| 1057 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 1058 | |
| 1059 | switch (vptr->options.flow_cntl) { |
| 1060 | |
| 1061 | case FLOW_CNTL_DEFAULT: |
| 1062 | if (BYTE_REG_BITS_IS_ON(PHYSR0_RXFLC, ®s->PHYSR0)) |
| 1063 | writel(CR0_FDXRFCEN, ®s->CR0Set); |
| 1064 | else |
| 1065 | writel(CR0_FDXRFCEN, ®s->CR0Clr); |
| 1066 | |
| 1067 | if (BYTE_REG_BITS_IS_ON(PHYSR0_TXFLC, ®s->PHYSR0)) |
| 1068 | writel(CR0_FDXTFCEN, ®s->CR0Set); |
| 1069 | else |
| 1070 | writel(CR0_FDXTFCEN, ®s->CR0Clr); |
| 1071 | break; |
| 1072 | |
| 1073 | case FLOW_CNTL_TX: |
| 1074 | writel(CR0_FDXTFCEN, ®s->CR0Set); |
| 1075 | writel(CR0_FDXRFCEN, ®s->CR0Clr); |
| 1076 | break; |
| 1077 | |
| 1078 | case FLOW_CNTL_RX: |
| 1079 | writel(CR0_FDXRFCEN, ®s->CR0Set); |
| 1080 | writel(CR0_FDXTFCEN, ®s->CR0Clr); |
| 1081 | break; |
| 1082 | |
| 1083 | case FLOW_CNTL_TX_RX: |
| 1084 | writel(CR0_FDXTFCEN, ®s->CR0Set); |
| 1085 | writel(CR0_FDXRFCEN, ®s->CR0Set); |
| 1086 | break; |
| 1087 | |
| 1088 | case FLOW_CNTL_DISABLE: |
| 1089 | writel(CR0_FDXRFCEN, ®s->CR0Clr); |
| 1090 | writel(CR0_FDXTFCEN, ®s->CR0Clr); |
| 1091 | break; |
| 1092 | |
| 1093 | default: |
| 1094 | break; |
| 1095 | } |
| 1096 | |
| 1097 | } |
| 1098 | |
| 1099 | /** |
| 1100 | * velocity_soft_reset - soft reset |
| 1101 | * @vptr: velocity to reset |
| 1102 | * |
| 1103 | * Kick off a soft reset of the velocity adapter and then poll |
| 1104 | * until the reset sequence has completed before returning. |
| 1105 | */ |
| 1106 | static int velocity_soft_reset(struct velocity_info *vptr) |
| 1107 | { |
| 1108 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 1109 | int i = 0; |
| 1110 | |
| 1111 | writel(CR0_SFRST, ®s->CR0Set); |
| 1112 | |
| 1113 | for (i = 0; i < W_MAX_TIMEOUT; i++) { |
| 1114 | udelay(5); |
| 1115 | if (!DWORD_REG_BITS_IS_ON(CR0_SFRST, ®s->CR0Set)) |
| 1116 | break; |
| 1117 | } |
| 1118 | |
| 1119 | if (i == W_MAX_TIMEOUT) { |
| 1120 | writel(CR0_FORSRST, ®s->CR0Set); |
| 1121 | /* FIXME: PCI POSTING */ |
| 1122 | /* delay 2ms */ |
| 1123 | mdelay(2); |
| 1124 | } |
| 1125 | return 0; |
| 1126 | } |
| 1127 | |
| 1128 | /** |
| 1129 | * velocity_set_multi - filter list change callback |
| 1130 | * @dev: network device |
| 1131 | * |
| 1132 | * Called by the network layer when the filter lists need to change |
| 1133 | * for a velocity adapter. Reload the CAMs with the new address |
| 1134 | * filter ruleset. |
| 1135 | */ |
| 1136 | static void velocity_set_multi(struct net_device *dev) |
| 1137 | { |
| 1138 | struct velocity_info *vptr = netdev_priv(dev); |
| 1139 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 1140 | u8 rx_mode; |
| 1141 | int i; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1142 | struct netdev_hw_addr *ha; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1143 | |
| 1144 | if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ |
| 1145 | writel(0xffffffff, ®s->MARCAM[0]); |
| 1146 | writel(0xffffffff, ®s->MARCAM[4]); |
| 1147 | rx_mode = (RCR_AM | RCR_AB | RCR_PROM); |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 1148 | } else if ((netdev_mc_count(dev) > vptr->multicast_limit) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1149 | (dev->flags & IFF_ALLMULTI)) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1150 | writel(0xffffffff, ®s->MARCAM[0]); |
| 1151 | writel(0xffffffff, ®s->MARCAM[4]); |
| 1152 | rx_mode = (RCR_AM | RCR_AB); |
| 1153 | } else { |
| 1154 | int offset = MCAM_SIZE - vptr->multicast_limit; |
| 1155 | mac_get_cam_mask(regs, vptr->mCAMmask); |
| 1156 | |
Jiri Pirko | 567ec87 | 2010-02-23 23:17:07 +0000 | [diff] [blame] | 1157 | i = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1158 | netdev_for_each_mc_addr(ha, dev) { |
| 1159 | mac_set_cam(regs, i + offset, ha->addr); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1160 | vptr->mCAMmask[(offset + i) / 8] |= 1 << ((offset + i) & 7); |
Jiri Pirko | 567ec87 | 2010-02-23 23:17:07 +0000 | [diff] [blame] | 1161 | i++; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | mac_set_cam_mask(regs, vptr->mCAMmask); |
| 1165 | rx_mode = RCR_AM | RCR_AB | RCR_AP; |
| 1166 | } |
| 1167 | if (dev->mtu > 1500) |
| 1168 | rx_mode |= RCR_AL; |
| 1169 | |
| 1170 | BYTE_REG_BITS_ON(rx_mode, ®s->RCR); |
| 1171 | |
| 1172 | } |
| 1173 | |
| 1174 | /* |
| 1175 | * MII access , media link mode setting functions |
| 1176 | */ |
| 1177 | |
| 1178 | /** |
| 1179 | * mii_init - set up MII |
| 1180 | * @vptr: velocity adapter |
| 1181 | * @mii_status: links tatus |
| 1182 | * |
| 1183 | * Set up the PHY for the current link state. |
| 1184 | */ |
| 1185 | static void mii_init(struct velocity_info *vptr, u32 mii_status) |
| 1186 | { |
| 1187 | u16 BMCR; |
| 1188 | |
| 1189 | switch (PHYID_GET_PHY_ID(vptr->phy_id)) { |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1190 | case PHYID_ICPLUS_IP101A: |
| 1191 | MII_REG_BITS_ON((ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP), |
| 1192 | MII_ADVERTISE, vptr->mac_regs); |
| 1193 | if (vptr->mii_status & VELOCITY_DUPLEX_FULL) |
| 1194 | MII_REG_BITS_ON(TCSR_ECHODIS, MII_SREVISION, |
| 1195 | vptr->mac_regs); |
| 1196 | else |
| 1197 | MII_REG_BITS_OFF(TCSR_ECHODIS, MII_SREVISION, |
| 1198 | vptr->mac_regs); |
| 1199 | MII_REG_BITS_ON(PLED_LALBE, MII_TPISTATUS, vptr->mac_regs); |
| 1200 | break; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1201 | case PHYID_CICADA_CS8201: |
| 1202 | /* |
| 1203 | * Reset to hardware default |
| 1204 | */ |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1205 | MII_REG_BITS_OFF((ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP), MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1206 | /* |
| 1207 | * Turn on ECHODIS bit in NWay-forced full mode and turn it |
| 1208 | * off it in NWay-forced half mode for NWay-forced v.s. |
| 1209 | * legacy-forced issue. |
| 1210 | */ |
| 1211 | if (vptr->mii_status & VELOCITY_DUPLEX_FULL) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1212 | MII_REG_BITS_ON(TCSR_ECHODIS, MII_SREVISION, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1213 | else |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1214 | MII_REG_BITS_OFF(TCSR_ECHODIS, MII_SREVISION, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1215 | /* |
| 1216 | * Turn on Link/Activity LED enable bit for CIS8201 |
| 1217 | */ |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1218 | MII_REG_BITS_ON(PLED_LALBE, MII_TPISTATUS, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1219 | break; |
| 1220 | case PHYID_VT3216_32BIT: |
| 1221 | case PHYID_VT3216_64BIT: |
| 1222 | /* |
| 1223 | * Reset to hardware default |
| 1224 | */ |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1225 | MII_REG_BITS_ON((ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP), MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1226 | /* |
| 1227 | * Turn on ECHODIS bit in NWay-forced full mode and turn it |
| 1228 | * off it in NWay-forced half mode for NWay-forced v.s. |
| 1229 | * legacy-forced issue |
| 1230 | */ |
| 1231 | if (vptr->mii_status & VELOCITY_DUPLEX_FULL) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1232 | MII_REG_BITS_ON(TCSR_ECHODIS, MII_SREVISION, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1233 | else |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1234 | MII_REG_BITS_OFF(TCSR_ECHODIS, MII_SREVISION, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1235 | break; |
| 1236 | |
| 1237 | case PHYID_MARVELL_1000: |
| 1238 | case PHYID_MARVELL_1000S: |
| 1239 | /* |
| 1240 | * Assert CRS on Transmit |
| 1241 | */ |
| 1242 | MII_REG_BITS_ON(PSCR_ACRSTX, MII_REG_PSCR, vptr->mac_regs); |
| 1243 | /* |
| 1244 | * Reset to hardware default |
| 1245 | */ |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1246 | MII_REG_BITS_ON((ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP), MII_ADVERTISE, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1247 | break; |
| 1248 | default: |
| 1249 | ; |
| 1250 | } |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 1251 | velocity_mii_read(vptr->mac_regs, MII_BMCR, &BMCR); |
| 1252 | if (BMCR & BMCR_ISOLATE) { |
| 1253 | BMCR &= ~BMCR_ISOLATE; |
| 1254 | velocity_mii_write(vptr->mac_regs, MII_BMCR, BMCR); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 1258 | /** |
| 1259 | * setup_queue_timers - Setup interrupt timers |
| 1260 | * |
| 1261 | * Setup interrupt frequency during suppression (timeout if the frame |
| 1262 | * count isn't filled). |
| 1263 | */ |
| 1264 | static void setup_queue_timers(struct velocity_info *vptr) |
| 1265 | { |
| 1266 | /* Only for newer revisions */ |
| 1267 | if (vptr->rev_id >= REV_ID_VT3216_A0) { |
| 1268 | u8 txqueue_timer = 0; |
| 1269 | u8 rxqueue_timer = 0; |
| 1270 | |
| 1271 | if (vptr->mii_status & (VELOCITY_SPEED_1000 | |
| 1272 | VELOCITY_SPEED_100)) { |
| 1273 | txqueue_timer = vptr->options.txqueue_timer; |
| 1274 | rxqueue_timer = vptr->options.rxqueue_timer; |
| 1275 | } |
| 1276 | |
| 1277 | writeb(txqueue_timer, &vptr->mac_regs->TQETMR); |
| 1278 | writeb(rxqueue_timer, &vptr->mac_regs->RQETMR); |
| 1279 | } |
| 1280 | } |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 1281 | |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 1282 | /** |
| 1283 | * setup_adaptive_interrupts - Setup interrupt suppression |
| 1284 | * |
| 1285 | * @vptr velocity adapter |
| 1286 | * |
| 1287 | * The velocity is able to suppress interrupt during high interrupt load. |
| 1288 | * This function turns on that feature. |
| 1289 | */ |
| 1290 | static void setup_adaptive_interrupts(struct velocity_info *vptr) |
| 1291 | { |
| 1292 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 1293 | u16 tx_intsup = vptr->options.tx_intsup; |
| 1294 | u16 rx_intsup = vptr->options.rx_intsup; |
| 1295 | |
| 1296 | /* Setup default interrupt mask (will be changed below) */ |
| 1297 | vptr->int_mask = INT_MASK_DEF; |
| 1298 | |
| 1299 | /* Set Tx Interrupt Suppression Threshold */ |
| 1300 | writeb(CAMCR_PS0, ®s->CAMCR); |
| 1301 | if (tx_intsup != 0) { |
| 1302 | vptr->int_mask &= ~(ISR_PTXI | ISR_PTX0I | ISR_PTX1I | |
| 1303 | ISR_PTX2I | ISR_PTX3I); |
| 1304 | writew(tx_intsup, ®s->ISRCTL); |
| 1305 | } else |
| 1306 | writew(ISRCTL_TSUPDIS, ®s->ISRCTL); |
| 1307 | |
| 1308 | /* Set Rx Interrupt Suppression Threshold */ |
| 1309 | writeb(CAMCR_PS1, ®s->CAMCR); |
| 1310 | if (rx_intsup != 0) { |
| 1311 | vptr->int_mask &= ~ISR_PRXI; |
| 1312 | writew(rx_intsup, ®s->ISRCTL); |
| 1313 | } else |
| 1314 | writew(ISRCTL_RSUPDIS, ®s->ISRCTL); |
| 1315 | |
| 1316 | /* Select page to interrupt hold timer */ |
| 1317 | writeb(0, ®s->CAMCR); |
| 1318 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1319 | |
| 1320 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | * velocity_init_registers - initialise MAC registers |
| 1322 | * @vptr: velocity to init |
| 1323 | * @type: type of initialisation (hot or cold) |
| 1324 | * |
| 1325 | * Initialise the MAC on a reset or on first set up on the |
| 1326 | * hardware. |
| 1327 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1328 | static void velocity_init_registers(struct velocity_info *vptr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | enum velocity_init_type type) |
| 1330 | { |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 1331 | struct mac_regs __iomem *regs = vptr->mac_regs; |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1332 | struct net_device *netdev = vptr->netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | int i, mii_status; |
| 1334 | |
| 1335 | mac_wol_reset(regs); |
| 1336 | |
| 1337 | switch (type) { |
| 1338 | case VELOCITY_INIT_RESET: |
| 1339 | case VELOCITY_INIT_WOL: |
| 1340 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1341 | netif_stop_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
| 1343 | /* |
| 1344 | * Reset RX to prevent RX pointer not on the 4X location |
| 1345 | */ |
| 1346 | velocity_rx_reset(vptr); |
| 1347 | mac_rx_queue_run(regs); |
| 1348 | mac_rx_queue_wake(regs); |
| 1349 | |
| 1350 | mii_status = velocity_get_opt_media_mode(vptr); |
| 1351 | if (velocity_set_media_mode(vptr, mii_status) != VELOCITY_LINK_CHANGE) { |
| 1352 | velocity_print_link_status(vptr); |
| 1353 | if (!(vptr->mii_status & VELOCITY_LINK_FAIL)) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1354 | netif_wake_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | enable_flow_control_ability(vptr); |
| 1358 | |
| 1359 | mac_clear_isr(regs); |
| 1360 | writel(CR0_STOP, ®s->CR0Clr); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1361 | writel((CR0_DPOLL | CR0_TXON | CR0_RXON | CR0_STRT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | ®s->CR0Set); |
| 1363 | |
| 1364 | break; |
| 1365 | |
| 1366 | case VELOCITY_INIT_COLD: |
| 1367 | default: |
| 1368 | /* |
| 1369 | * Do reset |
| 1370 | */ |
| 1371 | velocity_soft_reset(vptr); |
| 1372 | mdelay(5); |
| 1373 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1374 | if (!vptr->no_eeprom) { |
| 1375 | mac_eeprom_reload(regs); |
| 1376 | for (i = 0; i < 6; i++) |
| 1377 | writeb(netdev->dev_addr[i], regs->PAR + i); |
| 1378 | } |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 1379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | /* |
| 1381 | * clear Pre_ACPI bit. |
| 1382 | */ |
| 1383 | BYTE_REG_BITS_OFF(CFGA_PACPI, &(regs->CFGA)); |
| 1384 | mac_set_rx_thresh(regs, vptr->options.rx_thresh); |
| 1385 | mac_set_dma_length(regs, vptr->options.DMA_length); |
| 1386 | |
| 1387 | writeb(WOLCFG_SAM | WOLCFG_SAB, ®s->WOLCFGSet); |
| 1388 | /* |
| 1389 | * Back off algorithm use original IEEE standard |
| 1390 | */ |
| 1391 | BYTE_REG_BITS_SET(CFGB_OFSET, (CFGB_CRANDOM | CFGB_CAP | CFGB_MBA | CFGB_BAKOPT), ®s->CFGB); |
| 1392 | |
| 1393 | /* |
| 1394 | * Init CAM filter |
| 1395 | */ |
| 1396 | velocity_init_cam_filter(vptr); |
| 1397 | |
| 1398 | /* |
| 1399 | * Set packet filter: Receive directed and broadcast address |
| 1400 | */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1401 | velocity_set_multi(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
| 1403 | /* |
| 1404 | * Enable MII auto-polling |
| 1405 | */ |
| 1406 | enable_mii_autopoll(regs); |
| 1407 | |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 1408 | setup_adaptive_interrupts(vptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | |
Francois Romieu | 0fe9f15 | 2008-07-31 22:10:10 +0200 | [diff] [blame] | 1410 | writel(vptr->rx.pool_dma, ®s->RDBaseLo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | writew(vptr->options.numrx - 1, ®s->RDCSize); |
| 1412 | mac_rx_queue_run(regs); |
| 1413 | mac_rx_queue_wake(regs); |
| 1414 | |
| 1415 | writew(vptr->options.numtx - 1, ®s->TDCSize); |
| 1416 | |
Francois Romieu | 0fe9f15 | 2008-07-31 22:10:10 +0200 | [diff] [blame] | 1417 | for (i = 0; i < vptr->tx.numq; i++) { |
| 1418 | writel(vptr->tx.pool_dma[i], ®s->TDBaseLo[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | mac_tx_queue_run(regs, i); |
| 1420 | } |
| 1421 | |
| 1422 | init_flow_control_register(vptr); |
| 1423 | |
| 1424 | writel(CR0_STOP, ®s->CR0Clr); |
| 1425 | writel((CR0_DPOLL | CR0_TXON | CR0_RXON | CR0_STRT), ®s->CR0Set); |
| 1426 | |
| 1427 | mii_status = velocity_get_opt_media_mode(vptr); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1428 | netif_stop_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | |
| 1430 | mii_init(vptr, mii_status); |
| 1431 | |
| 1432 | if (velocity_set_media_mode(vptr, mii_status) != VELOCITY_LINK_CHANGE) { |
| 1433 | velocity_print_link_status(vptr); |
| 1434 | if (!(vptr->mii_status & VELOCITY_LINK_FAIL)) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 1435 | netif_wake_queue(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | enable_flow_control_ability(vptr); |
| 1439 | mac_hw_mibs_init(regs); |
| 1440 | mac_write_int_mask(vptr->int_mask, regs); |
| 1441 | mac_clear_isr(regs); |
| 1442 | |
| 1443 | } |
| 1444 | } |
| 1445 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1446 | static void velocity_give_many_rx_descs(struct velocity_info *vptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | { |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 1448 | struct mac_regs __iomem *regs = vptr->mac_regs; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1449 | int avail, dirty, unusable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1451 | /* |
| 1452 | * RD number must be equal to 4X per hardware spec |
| 1453 | * (programming guide rev 1.20, p.13) |
| 1454 | */ |
| 1455 | if (vptr->rx.filled < 4) |
| 1456 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1458 | wmb(); |
| 1459 | |
| 1460 | unusable = vptr->rx.filled & 0x0003; |
| 1461 | dirty = vptr->rx.dirty - unusable; |
| 1462 | for (avail = vptr->rx.filled & 0xfffc; avail; avail--) { |
| 1463 | dirty = (dirty > 0) ? dirty - 1 : vptr->options.numrx - 1; |
| 1464 | vptr->rx.ring[dirty].rdesc0.len |= OWNED_BY_NIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1467 | writew(vptr->rx.filled & 0xfffc, ®s->RBRDU); |
| 1468 | vptr->rx.filled = unusable; |
| 1469 | } |
| 1470 | |
| 1471 | /** |
| 1472 | * velocity_init_dma_rings - set up DMA rings |
| 1473 | * @vptr: Velocity to set up |
| 1474 | * |
| 1475 | * Allocate PCI mapped DMA rings for the receive and transmit layer |
| 1476 | * to use. |
| 1477 | */ |
| 1478 | static int velocity_init_dma_rings(struct velocity_info *vptr) |
| 1479 | { |
| 1480 | struct velocity_opt *opt = &vptr->options; |
| 1481 | const unsigned int rx_ring_size = opt->numrx * sizeof(struct rx_desc); |
| 1482 | const unsigned int tx_ring_size = opt->numtx * sizeof(struct tx_desc); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1483 | dma_addr_t pool_dma; |
| 1484 | void *pool; |
| 1485 | unsigned int i; |
| 1486 | |
| 1487 | /* |
| 1488 | * Allocate all RD/TD rings a single pool. |
| 1489 | * |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1490 | * dma_alloc_coherent() fulfills the requirement for 64 bytes |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1491 | * alignment |
| 1492 | */ |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1493 | pool = dma_alloc_coherent(vptr->dev, tx_ring_size * vptr->tx.numq + |
| 1494 | rx_ring_size, &pool_dma, GFP_ATOMIC); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1495 | if (!pool) { |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1496 | dev_err(vptr->dev, "%s : DMA memory allocation failed.\n", |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1497 | vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1498 | return -ENOMEM; |
| 1499 | } |
| 1500 | |
| 1501 | vptr->rx.ring = pool; |
| 1502 | vptr->rx.pool_dma = pool_dma; |
| 1503 | |
| 1504 | pool += rx_ring_size; |
| 1505 | pool_dma += rx_ring_size; |
| 1506 | |
| 1507 | for (i = 0; i < vptr->tx.numq; i++) { |
| 1508 | vptr->tx.rings[i] = pool; |
| 1509 | vptr->tx.pool_dma[i] = pool_dma; |
| 1510 | pool += tx_ring_size; |
| 1511 | pool_dma += tx_ring_size; |
| 1512 | } |
| 1513 | |
| 1514 | return 0; |
| 1515 | } |
| 1516 | |
| 1517 | static void velocity_set_rxbufsize(struct velocity_info *vptr, int mtu) |
| 1518 | { |
| 1519 | vptr->rx.buf_sz = (mtu <= ETH_DATA_LEN) ? PKT_BUF_SZ : mtu + 32; |
| 1520 | } |
| 1521 | |
| 1522 | /** |
| 1523 | * velocity_alloc_rx_buf - allocate aligned receive buffer |
| 1524 | * @vptr: velocity |
| 1525 | * @idx: ring index |
| 1526 | * |
| 1527 | * Allocate a new full sized buffer for the reception of a frame and |
| 1528 | * map it into PCI space for the hardware to use. The hardware |
| 1529 | * requires *64* byte alignment of the buffer which makes life |
| 1530 | * less fun than would be ideal. |
| 1531 | */ |
| 1532 | static int velocity_alloc_rx_buf(struct velocity_info *vptr, int idx) |
| 1533 | { |
| 1534 | struct rx_desc *rd = &(vptr->rx.ring[idx]); |
| 1535 | struct velocity_rd_info *rd_info = &(vptr->rx.info[idx]); |
| 1536 | |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1537 | rd_info->skb = netdev_alloc_skb(vptr->netdev, vptr->rx.buf_sz + 64); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1538 | if (rd_info->skb == NULL) |
| 1539 | return -ENOMEM; |
| 1540 | |
| 1541 | /* |
| 1542 | * Do the gymnastics to get the buffer head for data at |
| 1543 | * 64byte alignment. |
| 1544 | */ |
Simon Kagstrom | da95b2d | 2009-11-25 22:09:53 +0000 | [diff] [blame] | 1545 | skb_reserve(rd_info->skb, |
| 1546 | 64 - ((unsigned long) rd_info->skb->data & 63)); |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1547 | rd_info->skb_dma = dma_map_single(vptr->dev, rd_info->skb->data, |
| 1548 | vptr->rx.buf_sz, DMA_FROM_DEVICE); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1549 | |
| 1550 | /* |
| 1551 | * Fill in the descriptor to match |
| 1552 | */ |
| 1553 | |
| 1554 | *((u32 *) & (rd->rdesc0)) = 0; |
| 1555 | rd->size = cpu_to_le16(vptr->rx.buf_sz) | RX_INTEN; |
| 1556 | rd->pa_low = cpu_to_le32(rd_info->skb_dma); |
| 1557 | rd->pa_high = 0; |
| 1558 | return 0; |
| 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | static int velocity_rx_refill(struct velocity_info *vptr) |
| 1563 | { |
| 1564 | int dirty = vptr->rx.dirty, done = 0; |
| 1565 | |
| 1566 | do { |
| 1567 | struct rx_desc *rd = vptr->rx.ring + dirty; |
| 1568 | |
| 1569 | /* Fine for an all zero Rx desc at init time as well */ |
| 1570 | if (rd->rdesc0.len & OWNED_BY_NIC) |
| 1571 | break; |
| 1572 | |
| 1573 | if (!vptr->rx.info[dirty].skb) { |
| 1574 | if (velocity_alloc_rx_buf(vptr, dirty) < 0) |
| 1575 | break; |
| 1576 | } |
| 1577 | done++; |
| 1578 | dirty = (dirty < vptr->options.numrx - 1) ? dirty + 1 : 0; |
| 1579 | } while (dirty != vptr->rx.curr); |
| 1580 | |
| 1581 | if (done) { |
| 1582 | vptr->rx.dirty = dirty; |
| 1583 | vptr->rx.filled += done; |
| 1584 | } |
| 1585 | |
| 1586 | return done; |
| 1587 | } |
| 1588 | |
| 1589 | /** |
| 1590 | * velocity_free_rd_ring - free receive ring |
| 1591 | * @vptr: velocity to clean up |
| 1592 | * |
| 1593 | * Free the receive buffers for each ring slot and any |
| 1594 | * attached socket buffers that need to go away. |
| 1595 | */ |
| 1596 | static void velocity_free_rd_ring(struct velocity_info *vptr) |
| 1597 | { |
| 1598 | int i; |
| 1599 | |
| 1600 | if (vptr->rx.info == NULL) |
| 1601 | return; |
| 1602 | |
| 1603 | for (i = 0; i < vptr->options.numrx; i++) { |
| 1604 | struct velocity_rd_info *rd_info = &(vptr->rx.info[i]); |
| 1605 | struct rx_desc *rd = vptr->rx.ring + i; |
| 1606 | |
| 1607 | memset(rd, 0, sizeof(*rd)); |
| 1608 | |
| 1609 | if (!rd_info->skb) |
| 1610 | continue; |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1611 | dma_unmap_single(vptr->dev, rd_info->skb_dma, vptr->rx.buf_sz, |
| 1612 | DMA_FROM_DEVICE); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1613 | rd_info->skb_dma = 0; |
| 1614 | |
| 1615 | dev_kfree_skb(rd_info->skb); |
| 1616 | rd_info->skb = NULL; |
| 1617 | } |
| 1618 | |
| 1619 | kfree(vptr->rx.info); |
| 1620 | vptr->rx.info = NULL; |
| 1621 | } |
| 1622 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1623 | /** |
| 1624 | * velocity_init_rd_ring - set up receive ring |
| 1625 | * @vptr: velocity to configure |
| 1626 | * |
| 1627 | * Allocate and set up the receive buffers for each ring slot and |
| 1628 | * assign them to the network adapter. |
| 1629 | */ |
| 1630 | static int velocity_init_rd_ring(struct velocity_info *vptr) |
| 1631 | { |
| 1632 | int ret = -ENOMEM; |
| 1633 | |
| 1634 | vptr->rx.info = kcalloc(vptr->options.numrx, |
| 1635 | sizeof(struct velocity_rd_info), GFP_KERNEL); |
| 1636 | if (!vptr->rx.info) |
| 1637 | goto out; |
| 1638 | |
| 1639 | velocity_init_rx_ring_indexes(vptr); |
| 1640 | |
| 1641 | if (velocity_rx_refill(vptr) != vptr->options.numrx) { |
| 1642 | VELOCITY_PRT(MSG_LEVEL_ERR, KERN_ERR |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1643 | "%s: failed to allocate RX buffer.\n", vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1644 | velocity_free_rd_ring(vptr); |
| 1645 | goto out; |
| 1646 | } |
| 1647 | |
| 1648 | ret = 0; |
| 1649 | out: |
| 1650 | return ret; |
| 1651 | } |
| 1652 | |
| 1653 | /** |
| 1654 | * velocity_init_td_ring - set up transmit ring |
| 1655 | * @vptr: velocity |
| 1656 | * |
| 1657 | * Set up the transmit ring and chain the ring pointers together. |
| 1658 | * Returns zero on success or a negative posix errno code for |
| 1659 | * failure. |
| 1660 | */ |
| 1661 | static int velocity_init_td_ring(struct velocity_info *vptr) |
| 1662 | { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1663 | int j; |
| 1664 | |
| 1665 | /* Init the TD ring entries */ |
| 1666 | for (j = 0; j < vptr->tx.numq; j++) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1667 | |
| 1668 | vptr->tx.infos[j] = kcalloc(vptr->options.numtx, |
| 1669 | sizeof(struct velocity_td_info), |
| 1670 | GFP_KERNEL); |
| 1671 | if (!vptr->tx.infos[j]) { |
| 1672 | while (--j >= 0) |
| 1673 | kfree(vptr->tx.infos[j]); |
| 1674 | return -ENOMEM; |
| 1675 | } |
| 1676 | |
| 1677 | vptr->tx.tail[j] = vptr->tx.curr[j] = vptr->tx.used[j] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | } |
| 1679 | return 0; |
| 1680 | } |
| 1681 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1682 | /** |
| 1683 | * velocity_free_dma_rings - free PCI ring pointers |
| 1684 | * @vptr: Velocity to free from |
| 1685 | * |
| 1686 | * Clean up the PCI ring buffers allocated to this velocity. |
| 1687 | */ |
| 1688 | static void velocity_free_dma_rings(struct velocity_info *vptr) |
| 1689 | { |
| 1690 | const int size = vptr->options.numrx * sizeof(struct rx_desc) + |
| 1691 | vptr->options.numtx * sizeof(struct tx_desc) * vptr->tx.numq; |
| 1692 | |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1693 | dma_free_coherent(vptr->dev, size, vptr->rx.ring, vptr->rx.pool_dma); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1694 | } |
| 1695 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1696 | static int velocity_init_rings(struct velocity_info *vptr, int mtu) |
| 1697 | { |
| 1698 | int ret; |
| 1699 | |
| 1700 | velocity_set_rxbufsize(vptr, mtu); |
| 1701 | |
| 1702 | ret = velocity_init_dma_rings(vptr); |
| 1703 | if (ret < 0) |
| 1704 | goto out; |
| 1705 | |
| 1706 | ret = velocity_init_rd_ring(vptr); |
| 1707 | if (ret < 0) |
| 1708 | goto err_free_dma_rings_0; |
| 1709 | |
| 1710 | ret = velocity_init_td_ring(vptr); |
| 1711 | if (ret < 0) |
| 1712 | goto err_free_rd_ring_1; |
| 1713 | out: |
| 1714 | return ret; |
| 1715 | |
| 1716 | err_free_rd_ring_1: |
| 1717 | velocity_free_rd_ring(vptr); |
| 1718 | err_free_dma_rings_0: |
| 1719 | velocity_free_dma_rings(vptr); |
| 1720 | goto out; |
| 1721 | } |
| 1722 | |
| 1723 | /** |
| 1724 | * velocity_free_tx_buf - free transmit buffer |
| 1725 | * @vptr: velocity |
| 1726 | * @tdinfo: buffer |
| 1727 | * |
| 1728 | * Release an transmit buffer. If the buffer was preallocated then |
| 1729 | * recycle it, if not then unmap the buffer. |
| 1730 | */ |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 1731 | static void velocity_free_tx_buf(struct velocity_info *vptr, |
| 1732 | struct velocity_td_info *tdinfo, struct tx_desc *td) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1733 | { |
| 1734 | struct sk_buff *skb = tdinfo->skb; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1735 | |
| 1736 | /* |
| 1737 | * Don't unmap the pre-allocated tx_bufs |
| 1738 | */ |
| 1739 | if (tdinfo->skb_dma) { |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 1740 | int i; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1741 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1742 | for (i = 0; i < tdinfo->nskb_dma; i++) { |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 1743 | size_t pktlen = max_t(size_t, skb->len, ETH_ZLEN); |
| 1744 | |
| 1745 | /* For scatter-gather */ |
| 1746 | if (skb_shinfo(skb)->nr_frags > 0) |
| 1747 | pktlen = max_t(size_t, pktlen, |
| 1748 | td->td_buf[i].size & ~TD_QUEUE); |
| 1749 | |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1750 | dma_unmap_single(vptr->dev, tdinfo->skb_dma[i], |
| 1751 | le16_to_cpu(pktlen), DMA_TO_DEVICE); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1752 | } |
| 1753 | } |
| 1754 | dev_kfree_skb_irq(skb); |
| 1755 | tdinfo->skb = NULL; |
| 1756 | } |
| 1757 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1758 | /* |
| 1759 | * FIXME: could we merge this with velocity_free_tx_buf ? |
| 1760 | */ |
| 1761 | static void velocity_free_td_ring_entry(struct velocity_info *vptr, |
| 1762 | int q, int n) |
| 1763 | { |
| 1764 | struct velocity_td_info *td_info = &(vptr->tx.infos[q][n]); |
| 1765 | int i; |
| 1766 | |
| 1767 | if (td_info == NULL) |
| 1768 | return; |
| 1769 | |
| 1770 | if (td_info->skb) { |
| 1771 | for (i = 0; i < td_info->nskb_dma; i++) { |
| 1772 | if (td_info->skb_dma[i]) { |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 1773 | dma_unmap_single(vptr->dev, td_info->skb_dma[i], |
| 1774 | td_info->skb->len, DMA_TO_DEVICE); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1775 | td_info->skb_dma[i] = 0; |
| 1776 | } |
| 1777 | } |
| 1778 | dev_kfree_skb(td_info->skb); |
| 1779 | td_info->skb = NULL; |
| 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | /** |
| 1784 | * velocity_free_td_ring - free td ring |
| 1785 | * @vptr: velocity |
| 1786 | * |
| 1787 | * Free up the transmit ring for this particular velocity adapter. |
| 1788 | * We free the ring contents but not the ring itself. |
| 1789 | */ |
| 1790 | static void velocity_free_td_ring(struct velocity_info *vptr) |
| 1791 | { |
| 1792 | int i, j; |
| 1793 | |
| 1794 | for (j = 0; j < vptr->tx.numq; j++) { |
| 1795 | if (vptr->tx.infos[j] == NULL) |
| 1796 | continue; |
| 1797 | for (i = 0; i < vptr->options.numtx; i++) |
| 1798 | velocity_free_td_ring_entry(vptr, j, i); |
| 1799 | |
| 1800 | kfree(vptr->tx.infos[j]); |
| 1801 | vptr->tx.infos[j] = NULL; |
| 1802 | } |
| 1803 | } |
| 1804 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1805 | static void velocity_free_rings(struct velocity_info *vptr) |
| 1806 | { |
| 1807 | velocity_free_td_ring(vptr); |
| 1808 | velocity_free_rd_ring(vptr); |
| 1809 | velocity_free_dma_rings(vptr); |
| 1810 | } |
| 1811 | |
| 1812 | /** |
| 1813 | * velocity_error - handle error from controller |
| 1814 | * @vptr: velocity |
| 1815 | * @status: card status |
| 1816 | * |
| 1817 | * Process an error report from the hardware and attempt to recover |
| 1818 | * the card itself. At the moment we cannot recover from some |
| 1819 | * theoretically impossible errors but this could be fixed using |
| 1820 | * the pci_device_failed logic to bounce the hardware |
| 1821 | * |
| 1822 | */ |
| 1823 | static void velocity_error(struct velocity_info *vptr, int status) |
| 1824 | { |
| 1825 | |
| 1826 | if (status & ISR_TXSTLI) { |
| 1827 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 1828 | |
| 1829 | printk(KERN_ERR "TD structure error TDindex=%hx\n", readw(®s->TDIdx[0])); |
| 1830 | BYTE_REG_BITS_ON(TXESR_TDSTR, ®s->TXESR); |
| 1831 | writew(TRDCSR_RUN, ®s->TDCSRClr); |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1832 | netif_stop_queue(vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1833 | |
| 1834 | /* FIXME: port over the pci_device_failed code and use it |
| 1835 | here */ |
| 1836 | } |
| 1837 | |
| 1838 | if (status & ISR_SRCI) { |
| 1839 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 1840 | int linked; |
| 1841 | |
| 1842 | if (vptr->options.spd_dpx == SPD_DPX_AUTO) { |
| 1843 | vptr->mii_status = check_connection_type(regs); |
| 1844 | |
| 1845 | /* |
| 1846 | * If it is a 3119, disable frame bursting in |
| 1847 | * halfduplex mode and enable it in fullduplex |
| 1848 | * mode |
| 1849 | */ |
| 1850 | if (vptr->rev_id < REV_ID_VT3216_A0) { |
David S. Miller | 6cdee2f | 2009-09-02 00:32:56 -0700 | [diff] [blame] | 1851 | if (vptr->mii_status & VELOCITY_DUPLEX_FULL) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1852 | BYTE_REG_BITS_ON(TCR_TB2BDIS, ®s->TCR); |
| 1853 | else |
| 1854 | BYTE_REG_BITS_OFF(TCR_TB2BDIS, ®s->TCR); |
| 1855 | } |
| 1856 | /* |
| 1857 | * Only enable CD heart beat counter in 10HD mode |
| 1858 | */ |
| 1859 | if (!(vptr->mii_status & VELOCITY_DUPLEX_FULL) && (vptr->mii_status & VELOCITY_SPEED_10)) |
| 1860 | BYTE_REG_BITS_OFF(TESTCFG_HBDIS, ®s->TESTCFG); |
| 1861 | else |
| 1862 | BYTE_REG_BITS_ON(TESTCFG_HBDIS, ®s->TESTCFG); |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 1863 | |
| 1864 | setup_queue_timers(vptr); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1865 | } |
| 1866 | /* |
| 1867 | * Get link status from PHYSR0 |
| 1868 | */ |
| 1869 | linked = readb(®s->PHYSR0) & PHYSR0_LINKGD; |
| 1870 | |
| 1871 | if (linked) { |
| 1872 | vptr->mii_status &= ~VELOCITY_LINK_FAIL; |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1873 | netif_carrier_on(vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1874 | } else { |
| 1875 | vptr->mii_status |= VELOCITY_LINK_FAIL; |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1876 | netif_carrier_off(vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1877 | } |
| 1878 | |
| 1879 | velocity_print_link_status(vptr); |
| 1880 | enable_flow_control_ability(vptr); |
| 1881 | |
| 1882 | /* |
| 1883 | * Re-enable auto-polling because SRCI will disable |
| 1884 | * auto-polling |
| 1885 | */ |
| 1886 | |
| 1887 | enable_mii_autopoll(regs); |
| 1888 | |
| 1889 | if (vptr->mii_status & VELOCITY_LINK_FAIL) |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1890 | netif_stop_queue(vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1891 | else |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1892 | netif_wake_queue(vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1893 | |
Joe Perches | 6403eab | 2011-06-03 11:51:20 +0000 | [diff] [blame] | 1894 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1895 | if (status & ISR_MIBFI) |
| 1896 | velocity_update_hw_mibs(vptr); |
| 1897 | if (status & ISR_LSTEI) |
| 1898 | mac_rx_queue_wake(vptr->mac_regs); |
| 1899 | } |
| 1900 | |
| 1901 | /** |
| 1902 | * tx_srv - transmit interrupt service |
| 1903 | * @vptr; Velocity |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1904 | * |
| 1905 | * Scan the queues looking for transmitted packets that |
| 1906 | * we can complete and clean up. Update any statistics as |
| 1907 | * necessary/ |
| 1908 | */ |
Simon Kagstrom | d6cade0 | 2010-02-09 23:37:54 +0000 | [diff] [blame] | 1909 | static int velocity_tx_srv(struct velocity_info *vptr) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1910 | { |
| 1911 | struct tx_desc *td; |
| 1912 | int qnum; |
| 1913 | int full = 0; |
| 1914 | int idx; |
| 1915 | int works = 0; |
| 1916 | struct velocity_td_info *tdinfo; |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1917 | struct net_device_stats *stats = &vptr->netdev->stats; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1918 | |
| 1919 | for (qnum = 0; qnum < vptr->tx.numq; qnum++) { |
| 1920 | for (idx = vptr->tx.tail[qnum]; vptr->tx.used[qnum] > 0; |
| 1921 | idx = (idx + 1) % vptr->options.numtx) { |
| 1922 | |
| 1923 | /* |
| 1924 | * Get Tx Descriptor |
| 1925 | */ |
| 1926 | td = &(vptr->tx.rings[qnum][idx]); |
| 1927 | tdinfo = &(vptr->tx.infos[qnum][idx]); |
| 1928 | |
| 1929 | if (td->tdesc0.len & OWNED_BY_NIC) |
| 1930 | break; |
| 1931 | |
| 1932 | if ((works++ > 15)) |
| 1933 | break; |
| 1934 | |
| 1935 | if (td->tdesc0.TSR & TSR0_TERR) { |
| 1936 | stats->tx_errors++; |
| 1937 | stats->tx_dropped++; |
| 1938 | if (td->tdesc0.TSR & TSR0_CDH) |
| 1939 | stats->tx_heartbeat_errors++; |
| 1940 | if (td->tdesc0.TSR & TSR0_CRS) |
| 1941 | stats->tx_carrier_errors++; |
| 1942 | if (td->tdesc0.TSR & TSR0_ABT) |
| 1943 | stats->tx_aborted_errors++; |
| 1944 | if (td->tdesc0.TSR & TSR0_OWC) |
| 1945 | stats->tx_window_errors++; |
| 1946 | } else { |
| 1947 | stats->tx_packets++; |
| 1948 | stats->tx_bytes += tdinfo->skb->len; |
| 1949 | } |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 1950 | velocity_free_tx_buf(vptr, tdinfo, td); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1951 | vptr->tx.used[qnum]--; |
| 1952 | } |
| 1953 | vptr->tx.tail[qnum] = idx; |
| 1954 | |
| 1955 | if (AVAIL_TD(vptr, qnum) < 1) |
| 1956 | full = 1; |
| 1957 | } |
| 1958 | /* |
| 1959 | * Look to see if we should kick the transmit network |
| 1960 | * layer for more work. |
| 1961 | */ |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1962 | if (netif_queue_stopped(vptr->netdev) && (full == 0) && |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 1963 | (!(vptr->mii_status & VELOCITY_LINK_FAIL))) { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 1964 | netif_wake_queue(vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1965 | } |
| 1966 | return works; |
| 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * velocity_rx_csum - checksum process |
| 1971 | * @rd: receive packet descriptor |
| 1972 | * @skb: network layer packet buffer |
| 1973 | * |
| 1974 | * Process the status bits for the received packet and determine |
| 1975 | * if the checksum was computed and verified by the hardware |
| 1976 | */ |
| 1977 | static inline void velocity_rx_csum(struct rx_desc *rd, struct sk_buff *skb) |
| 1978 | { |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 1979 | skb_checksum_none_assert(skb); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 1980 | |
| 1981 | if (rd->rdesc1.CSM & CSM_IPKT) { |
| 1982 | if (rd->rdesc1.CSM & CSM_IPOK) { |
| 1983 | if ((rd->rdesc1.CSM & CSM_TCPKT) || |
| 1984 | (rd->rdesc1.CSM & CSM_UDPKT)) { |
| 1985 | if (!(rd->rdesc1.CSM & CSM_TUPOK)) |
| 1986 | return; |
| 1987 | } |
| 1988 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1989 | } |
| 1990 | } |
| 1991 | } |
| 1992 | |
| 1993 | /** |
| 1994 | * velocity_rx_copy - in place Rx copy for small packets |
| 1995 | * @rx_skb: network layer packet buffer candidate |
| 1996 | * @pkt_size: received data size |
| 1997 | * @rd: receive packet descriptor |
| 1998 | * @dev: network device |
| 1999 | * |
| 2000 | * Replace the current skb that is scheduled for Rx processing by a |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2001 | * shorter, immediately allocated skb, if the received packet is small |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2002 | * enough. This function returns a negative value if the received |
| 2003 | * packet is too big or if memory is exhausted. |
| 2004 | */ |
| 2005 | static int velocity_rx_copy(struct sk_buff **rx_skb, int pkt_size, |
| 2006 | struct velocity_info *vptr) |
| 2007 | { |
| 2008 | int ret = -1; |
| 2009 | if (pkt_size < rx_copybreak) { |
| 2010 | struct sk_buff *new_skb; |
| 2011 | |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2012 | new_skb = netdev_alloc_skb_ip_align(vptr->netdev, pkt_size); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2013 | if (new_skb) { |
| 2014 | new_skb->ip_summed = rx_skb[0]->ip_summed; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2015 | skb_copy_from_linear_data(*rx_skb, new_skb->data, pkt_size); |
| 2016 | *rx_skb = new_skb; |
| 2017 | ret = 0; |
| 2018 | } |
| 2019 | |
| 2020 | } |
| 2021 | return ret; |
| 2022 | } |
| 2023 | |
| 2024 | /** |
| 2025 | * velocity_iph_realign - IP header alignment |
| 2026 | * @vptr: velocity we are handling |
| 2027 | * @skb: network layer packet buffer |
| 2028 | * @pkt_size: received data size |
| 2029 | * |
| 2030 | * Align IP header on a 2 bytes boundary. This behavior can be |
| 2031 | * configured by the user. |
| 2032 | */ |
| 2033 | static inline void velocity_iph_realign(struct velocity_info *vptr, |
| 2034 | struct sk_buff *skb, int pkt_size) |
| 2035 | { |
| 2036 | if (vptr->flags & VELOCITY_FLAGS_IP_ALIGN) { |
| 2037 | memmove(skb->data + 2, skb->data, pkt_size); |
| 2038 | skb_reserve(skb, 2); |
| 2039 | } |
| 2040 | } |
| 2041 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2042 | /** |
| 2043 | * velocity_receive_frame - received packet processor |
| 2044 | * @vptr: velocity we are handling |
| 2045 | * @idx: ring index |
| 2046 | * |
| 2047 | * A packet has arrived. We process the packet and if appropriate |
| 2048 | * pass the frame up the network stack |
| 2049 | */ |
| 2050 | static int velocity_receive_frame(struct velocity_info *vptr, int idx) |
| 2051 | { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2052 | struct net_device_stats *stats = &vptr->netdev->stats; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2053 | struct velocity_rd_info *rd_info = &(vptr->rx.info[idx]); |
| 2054 | struct rx_desc *rd = &(vptr->rx.ring[idx]); |
| 2055 | int pkt_len = le16_to_cpu(rd->rdesc0.len) & 0x3fff; |
| 2056 | struct sk_buff *skb; |
| 2057 | |
| 2058 | if (rd->rdesc0.RSR & (RSR_STP | RSR_EDP)) { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2059 | VELOCITY_PRT(MSG_LEVEL_VERBOSE, KERN_ERR " %s : the received frame span multple RDs.\n", vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2060 | stats->rx_length_errors++; |
| 2061 | return -EINVAL; |
| 2062 | } |
| 2063 | |
| 2064 | if (rd->rdesc0.RSR & RSR_MAR) |
| 2065 | stats->multicast++; |
| 2066 | |
| 2067 | skb = rd_info->skb; |
| 2068 | |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 2069 | dma_sync_single_for_cpu(vptr->dev, rd_info->skb_dma, |
| 2070 | vptr->rx.buf_sz, DMA_FROM_DEVICE); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2071 | |
| 2072 | /* |
| 2073 | * Drop frame not meeting IEEE 802.3 |
| 2074 | */ |
| 2075 | |
| 2076 | if (vptr->flags & VELOCITY_FLAGS_VAL_PKT_LEN) { |
| 2077 | if (rd->rdesc0.RSR & RSR_RL) { |
| 2078 | stats->rx_length_errors++; |
| 2079 | return -EINVAL; |
| 2080 | } |
| 2081 | } |
| 2082 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2083 | velocity_rx_csum(rd, skb); |
| 2084 | |
| 2085 | if (velocity_rx_copy(&skb, pkt_len, vptr) < 0) { |
| 2086 | velocity_iph_realign(vptr, skb, pkt_len); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2087 | rd_info->skb = NULL; |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 2088 | dma_unmap_single(vptr->dev, rd_info->skb_dma, vptr->rx.buf_sz, |
| 2089 | DMA_FROM_DEVICE); |
| 2090 | } else { |
| 2091 | dma_sync_single_for_device(vptr->dev, rd_info->skb_dma, |
| 2092 | vptr->rx.buf_sz, DMA_FROM_DEVICE); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2095 | skb_put(skb, pkt_len - 4); |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2096 | skb->protocol = eth_type_trans(skb, vptr->netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2097 | |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 2098 | if (rd->rdesc0.RSR & RSR_DETAG) { |
| 2099 | u16 vid = swab16(le16_to_cpu(rd->rdesc1.PQTAG)); |
| 2100 | |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2101 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Jiri Pirko | 73b5468 | 2011-07-20 04:54:30 +0000 | [diff] [blame] | 2102 | } |
Julia Lawall | 2fdac01 | 2013-08-14 16:26:53 +0200 | [diff] [blame] | 2103 | netif_receive_skb(skb); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2104 | |
| 2105 | stats->rx_bytes += pkt_len; |
françois romieu | 3cb7a79 | 2011-08-04 02:37:55 +0000 | [diff] [blame] | 2106 | stats->rx_packets++; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2107 | |
| 2108 | return 0; |
| 2109 | } |
| 2110 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2111 | /** |
| 2112 | * velocity_rx_srv - service RX interrupt |
| 2113 | * @vptr: velocity |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2114 | * |
| 2115 | * Walk the receive ring of the velocity adapter and remove |
| 2116 | * any received packets from the receive queue. Hand the ring |
| 2117 | * slots back to the adapter for reuse. |
| 2118 | */ |
Simon Kagstrom | d6cade0 | 2010-02-09 23:37:54 +0000 | [diff] [blame] | 2119 | static int velocity_rx_srv(struct velocity_info *vptr, int budget_left) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2120 | { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2121 | struct net_device_stats *stats = &vptr->netdev->stats; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2122 | int rd_curr = vptr->rx.curr; |
| 2123 | int works = 0; |
| 2124 | |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2125 | while (works < budget_left) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2126 | struct rx_desc *rd = vptr->rx.ring + rd_curr; |
| 2127 | |
| 2128 | if (!vptr->rx.info[rd_curr].skb) |
| 2129 | break; |
| 2130 | |
| 2131 | if (rd->rdesc0.len & OWNED_BY_NIC) |
| 2132 | break; |
| 2133 | |
| 2134 | rmb(); |
| 2135 | |
| 2136 | /* |
| 2137 | * Don't drop CE or RL error frame although RXOK is off |
| 2138 | */ |
| 2139 | if (rd->rdesc0.RSR & (RSR_RXOK | RSR_CE | RSR_RL)) { |
| 2140 | if (velocity_receive_frame(vptr, rd_curr) < 0) |
| 2141 | stats->rx_dropped++; |
| 2142 | } else { |
| 2143 | if (rd->rdesc0.RSR & RSR_CRC) |
| 2144 | stats->rx_crc_errors++; |
| 2145 | if (rd->rdesc0.RSR & RSR_FAE) |
| 2146 | stats->rx_frame_errors++; |
| 2147 | |
| 2148 | stats->rx_dropped++; |
| 2149 | } |
| 2150 | |
| 2151 | rd->size |= RX_INTEN; |
| 2152 | |
| 2153 | rd_curr++; |
| 2154 | if (rd_curr >= vptr->options.numrx) |
| 2155 | rd_curr = 0; |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2156 | works++; |
| 2157 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2158 | |
| 2159 | vptr->rx.curr = rd_curr; |
| 2160 | |
| 2161 | if ((works > 0) && (velocity_rx_refill(vptr) > 0)) |
| 2162 | velocity_give_many_rx_descs(vptr); |
| 2163 | |
| 2164 | VAR_USED(stats); |
| 2165 | return works; |
| 2166 | } |
| 2167 | |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2168 | static int velocity_poll(struct napi_struct *napi, int budget) |
| 2169 | { |
| 2170 | struct velocity_info *vptr = container_of(napi, |
| 2171 | struct velocity_info, napi); |
| 2172 | unsigned int rx_done; |
Simon Kagstrom | 3f2e8d9 | 2010-02-09 23:38:25 +0000 | [diff] [blame] | 2173 | unsigned long flags; |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2174 | |
Simon Kagstrom | 3f2e8d9 | 2010-02-09 23:38:25 +0000 | [diff] [blame] | 2175 | spin_lock_irqsave(&vptr->lock, flags); |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2176 | /* |
| 2177 | * Do rx and tx twice for performance (taken from the VIA |
| 2178 | * out-of-tree driver). |
| 2179 | */ |
Simon Kagstrom | d6cade0 | 2010-02-09 23:37:54 +0000 | [diff] [blame] | 2180 | rx_done = velocity_rx_srv(vptr, budget / 2); |
| 2181 | velocity_tx_srv(vptr); |
| 2182 | rx_done += velocity_rx_srv(vptr, budget - rx_done); |
| 2183 | velocity_tx_srv(vptr); |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2184 | |
| 2185 | /* If budget not fully consumed, exit the polling mode */ |
| 2186 | if (rx_done < budget) { |
| 2187 | napi_complete(napi); |
| 2188 | mac_enable_int(vptr->mac_regs); |
| 2189 | } |
Simon Kagstrom | 3f2e8d9 | 2010-02-09 23:38:25 +0000 | [diff] [blame] | 2190 | spin_unlock_irqrestore(&vptr->lock, flags); |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2191 | |
| 2192 | return rx_done; |
| 2193 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2194 | |
| 2195 | /** |
| 2196 | * velocity_intr - interrupt callback |
| 2197 | * @irq: interrupt number |
| 2198 | * @dev_instance: interrupting device |
| 2199 | * |
| 2200 | * Called whenever an interrupt is generated by the velocity |
| 2201 | * adapter IRQ line. We may not be the source of the interrupt |
| 2202 | * and need to identify initially if we are, and if not exit as |
| 2203 | * efficiently as possible. |
| 2204 | */ |
| 2205 | static irqreturn_t velocity_intr(int irq, void *dev_instance) |
| 2206 | { |
| 2207 | struct net_device *dev = dev_instance; |
| 2208 | struct velocity_info *vptr = netdev_priv(dev); |
| 2209 | u32 isr_status; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2210 | |
| 2211 | spin_lock(&vptr->lock); |
| 2212 | isr_status = mac_read_isr(vptr->mac_regs); |
| 2213 | |
| 2214 | /* Not us ? */ |
| 2215 | if (isr_status == 0) { |
| 2216 | spin_unlock(&vptr->lock); |
| 2217 | return IRQ_NONE; |
| 2218 | } |
| 2219 | |
Simon Kagstrom | 3f2e8d9 | 2010-02-09 23:38:25 +0000 | [diff] [blame] | 2220 | /* Ack the interrupt */ |
| 2221 | mac_write_isr(vptr->mac_regs, isr_status); |
| 2222 | |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2223 | if (likely(napi_schedule_prep(&vptr->napi))) { |
| 2224 | mac_disable_int(vptr->mac_regs); |
| 2225 | __napi_schedule(&vptr->napi); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2226 | } |
Simon Kagstrom | 3f2e8d9 | 2010-02-09 23:38:25 +0000 | [diff] [blame] | 2227 | |
| 2228 | if (isr_status & (~(ISR_PRXI | ISR_PPRXI | ISR_PTXI | ISR_PPTXI))) |
| 2229 | velocity_error(vptr, isr_status); |
| 2230 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2231 | spin_unlock(&vptr->lock); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2232 | |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2233 | return IRQ_HANDLED; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | /** |
| 2237 | * velocity_open - interface activation callback |
| 2238 | * @dev: network layer device to open |
| 2239 | * |
| 2240 | * Called when the network layer brings the interface up. Returns |
| 2241 | * a negative posix error code on failure, or zero on success. |
| 2242 | * |
| 2243 | * All the ring allocation and set up is done on open for this |
| 2244 | * adapter to minimise memory usage when inactive |
| 2245 | */ |
| 2246 | static int velocity_open(struct net_device *dev) |
| 2247 | { |
| 2248 | struct velocity_info *vptr = netdev_priv(dev); |
| 2249 | int ret; |
| 2250 | |
| 2251 | ret = velocity_init_rings(vptr, dev->mtu); |
| 2252 | if (ret < 0) |
| 2253 | goto out; |
| 2254 | |
| 2255 | /* Ensure chip is running */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2256 | velocity_set_power_state(vptr, PCI_D0); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2257 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2258 | velocity_init_registers(vptr, VELOCITY_INIT_COLD); |
| 2259 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2260 | ret = request_irq(dev->irq, velocity_intr, IRQF_SHARED, |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2261 | dev->name, dev); |
| 2262 | if (ret < 0) { |
| 2263 | /* Power down the chip */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2264 | velocity_set_power_state(vptr, PCI_D3hot); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2265 | velocity_free_rings(vptr); |
| 2266 | goto out; |
| 2267 | } |
| 2268 | |
Ben Hutchings | 35bb5ca | 2009-12-14 16:05:09 +0000 | [diff] [blame] | 2269 | velocity_give_many_rx_descs(vptr); |
| 2270 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2271 | mac_enable_int(vptr->mac_regs); |
| 2272 | netif_start_queue(dev); |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2273 | napi_enable(&vptr->napi); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2274 | vptr->flags |= VELOCITY_FLAGS_OPENED; |
| 2275 | out: |
| 2276 | return ret; |
| 2277 | } |
| 2278 | |
| 2279 | /** |
| 2280 | * velocity_shutdown - shut down the chip |
| 2281 | * @vptr: velocity to deactivate |
| 2282 | * |
| 2283 | * Shuts down the internal operations of the velocity and |
| 2284 | * disables interrupts, autopolling, transmit and receive |
| 2285 | */ |
| 2286 | static void velocity_shutdown(struct velocity_info *vptr) |
| 2287 | { |
| 2288 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 2289 | mac_disable_int(regs); |
| 2290 | writel(CR0_STOP, ®s->CR0Set); |
| 2291 | writew(0xFFFF, ®s->TDCSRClr); |
| 2292 | writeb(0xFF, ®s->RDCSRClr); |
| 2293 | safe_disable_mii_autopoll(regs); |
| 2294 | mac_clear_isr(regs); |
| 2295 | } |
| 2296 | |
| 2297 | /** |
| 2298 | * velocity_change_mtu - MTU change callback |
| 2299 | * @dev: network device |
| 2300 | * @new_mtu: desired MTU |
| 2301 | * |
| 2302 | * Handle requests from the networking layer for MTU change on |
| 2303 | * this interface. It gets called on a change by the network layer. |
| 2304 | * Return zero for success or negative posix error code. |
| 2305 | */ |
| 2306 | static int velocity_change_mtu(struct net_device *dev, int new_mtu) |
| 2307 | { |
| 2308 | struct velocity_info *vptr = netdev_priv(dev); |
| 2309 | int ret = 0; |
| 2310 | |
| 2311 | if ((new_mtu < VELOCITY_MIN_MTU) || new_mtu > (VELOCITY_MAX_MTU)) { |
| 2312 | VELOCITY_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Invalid MTU.\n", |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2313 | vptr->netdev->name); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2314 | ret = -EINVAL; |
| 2315 | goto out_0; |
| 2316 | } |
| 2317 | |
| 2318 | if (!netif_running(dev)) { |
| 2319 | dev->mtu = new_mtu; |
| 2320 | goto out_0; |
| 2321 | } |
| 2322 | |
| 2323 | if (dev->mtu != new_mtu) { |
| 2324 | struct velocity_info *tmp_vptr; |
| 2325 | unsigned long flags; |
| 2326 | struct rx_info rx; |
| 2327 | struct tx_info tx; |
| 2328 | |
| 2329 | tmp_vptr = kzalloc(sizeof(*tmp_vptr), GFP_KERNEL); |
| 2330 | if (!tmp_vptr) { |
| 2331 | ret = -ENOMEM; |
| 2332 | goto out_0; |
| 2333 | } |
| 2334 | |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2335 | tmp_vptr->netdev = dev; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2336 | tmp_vptr->pdev = vptr->pdev; |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2337 | tmp_vptr->dev = vptr->dev; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2338 | tmp_vptr->options = vptr->options; |
| 2339 | tmp_vptr->tx.numq = vptr->tx.numq; |
| 2340 | |
| 2341 | ret = velocity_init_rings(tmp_vptr, new_mtu); |
| 2342 | if (ret < 0) |
| 2343 | goto out_free_tmp_vptr_1; |
| 2344 | |
| 2345 | spin_lock_irqsave(&vptr->lock, flags); |
| 2346 | |
| 2347 | netif_stop_queue(dev); |
| 2348 | velocity_shutdown(vptr); |
| 2349 | |
| 2350 | rx = vptr->rx; |
| 2351 | tx = vptr->tx; |
| 2352 | |
| 2353 | vptr->rx = tmp_vptr->rx; |
| 2354 | vptr->tx = tmp_vptr->tx; |
| 2355 | |
| 2356 | tmp_vptr->rx = rx; |
| 2357 | tmp_vptr->tx = tx; |
| 2358 | |
| 2359 | dev->mtu = new_mtu; |
| 2360 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2361 | velocity_init_registers(vptr, VELOCITY_INIT_COLD); |
| 2362 | |
Ben Hutchings | 35bb5ca | 2009-12-14 16:05:09 +0000 | [diff] [blame] | 2363 | velocity_give_many_rx_descs(vptr); |
| 2364 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2365 | mac_enable_int(vptr->mac_regs); |
| 2366 | netif_start_queue(dev); |
| 2367 | |
| 2368 | spin_unlock_irqrestore(&vptr->lock, flags); |
| 2369 | |
| 2370 | velocity_free_rings(tmp_vptr); |
| 2371 | |
| 2372 | out_free_tmp_vptr_1: |
| 2373 | kfree(tmp_vptr); |
| 2374 | } |
| 2375 | out_0: |
| 2376 | return ret; |
| 2377 | } |
| 2378 | |
Amit Uttamchandani | 0887a57 | 2013-07-18 17:45:22 -0700 | [diff] [blame] | 2379 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2380 | /** |
| 2381 | * velocity_poll_controller - Velocity Poll controller function |
| 2382 | * @dev: network device |
| 2383 | * |
| 2384 | * |
| 2385 | * Used by NETCONSOLE and other diagnostic tools to allow network I/P |
| 2386 | * with interrupts disabled. |
| 2387 | */ |
| 2388 | static void velocity_poll_controller(struct net_device *dev) |
| 2389 | { |
| 2390 | disable_irq(dev->irq); |
| 2391 | velocity_intr(dev->irq, dev); |
| 2392 | enable_irq(dev->irq); |
| 2393 | } |
| 2394 | #endif |
| 2395 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2396 | /** |
| 2397 | * velocity_mii_ioctl - MII ioctl handler |
| 2398 | * @dev: network device |
| 2399 | * @ifr: the ifreq block for the ioctl |
| 2400 | * @cmd: the command |
| 2401 | * |
| 2402 | * Process MII requests made via ioctl from the network layer. These |
| 2403 | * are used by tools like kudzu to interrogate the link state of the |
| 2404 | * hardware |
| 2405 | */ |
| 2406 | static int velocity_mii_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 2407 | { |
| 2408 | struct velocity_info *vptr = netdev_priv(dev); |
| 2409 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 2410 | unsigned long flags; |
| 2411 | struct mii_ioctl_data *miidata = if_mii(ifr); |
| 2412 | int err; |
| 2413 | |
| 2414 | switch (cmd) { |
| 2415 | case SIOCGMIIPHY: |
| 2416 | miidata->phy_id = readb(®s->MIIADR) & 0x1f; |
| 2417 | break; |
| 2418 | case SIOCGMIIREG: |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2419 | if (velocity_mii_read(vptr->mac_regs, miidata->reg_num & 0x1f, &(miidata->val_out)) < 0) |
| 2420 | return -ETIMEDOUT; |
| 2421 | break; |
| 2422 | case SIOCSMIIREG: |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2423 | spin_lock_irqsave(&vptr->lock, flags); |
| 2424 | err = velocity_mii_write(vptr->mac_regs, miidata->reg_num & 0x1f, miidata->val_in); |
| 2425 | spin_unlock_irqrestore(&vptr->lock, flags); |
| 2426 | check_connection_type(vptr->mac_regs); |
| 2427 | if (err) |
| 2428 | return err; |
| 2429 | break; |
| 2430 | default: |
| 2431 | return -EOPNOTSUPP; |
| 2432 | } |
| 2433 | return 0; |
| 2434 | } |
| 2435 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2436 | /** |
| 2437 | * velocity_ioctl - ioctl entry point |
| 2438 | * @dev: network device |
| 2439 | * @rq: interface request ioctl |
| 2440 | * @cmd: command code |
| 2441 | * |
| 2442 | * Called when the user issues an ioctl request to the network |
| 2443 | * device in question. The velocity interface supports MII. |
| 2444 | */ |
| 2445 | static int velocity_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2446 | { |
| 2447 | struct velocity_info *vptr = netdev_priv(dev); |
| 2448 | int ret; |
| 2449 | |
| 2450 | /* If we are asked for information and the device is power |
| 2451 | saving then we need to bring the device back up to talk to it */ |
| 2452 | |
| 2453 | if (!netif_running(dev)) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2454 | velocity_set_power_state(vptr, PCI_D0); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2455 | |
| 2456 | switch (cmd) { |
| 2457 | case SIOCGMIIPHY: /* Get address of MII PHY in use. */ |
| 2458 | case SIOCGMIIREG: /* Read MII PHY register. */ |
| 2459 | case SIOCSMIIREG: /* Write to MII PHY register. */ |
| 2460 | ret = velocity_mii_ioctl(dev, rq, cmd); |
| 2461 | break; |
| 2462 | |
| 2463 | default: |
| 2464 | ret = -EOPNOTSUPP; |
| 2465 | } |
| 2466 | if (!netif_running(dev)) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2467 | velocity_set_power_state(vptr, PCI_D3hot); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2468 | |
| 2469 | |
| 2470 | return ret; |
| 2471 | } |
| 2472 | |
| 2473 | /** |
| 2474 | * velocity_get_status - statistics callback |
| 2475 | * @dev: network device |
| 2476 | * |
| 2477 | * Callback from the network layer to allow driver statistics |
| 2478 | * to be resynchronized with hardware collected state. In the |
| 2479 | * case of the velocity we need to pull the MIB counters from |
| 2480 | * the hardware into the counters before letting the network |
| 2481 | * layer display them. |
| 2482 | */ |
| 2483 | static struct net_device_stats *velocity_get_stats(struct net_device *dev) |
| 2484 | { |
| 2485 | struct velocity_info *vptr = netdev_priv(dev); |
| 2486 | |
| 2487 | /* If the hardware is down, don't touch MII */ |
| 2488 | if (!netif_running(dev)) |
| 2489 | return &dev->stats; |
| 2490 | |
| 2491 | spin_lock_irq(&vptr->lock); |
| 2492 | velocity_update_hw_mibs(vptr); |
| 2493 | spin_unlock_irq(&vptr->lock); |
| 2494 | |
| 2495 | dev->stats.rx_packets = vptr->mib_counter[HW_MIB_ifRxAllPkts]; |
| 2496 | dev->stats.rx_errors = vptr->mib_counter[HW_MIB_ifRxErrorPkts]; |
| 2497 | dev->stats.rx_length_errors = vptr->mib_counter[HW_MIB_ifInRangeLengthErrors]; |
| 2498 | |
| 2499 | // unsigned long rx_dropped; /* no space in linux buffers */ |
| 2500 | dev->stats.collisions = vptr->mib_counter[HW_MIB_ifTxEtherCollisions]; |
| 2501 | /* detailed rx_errors: */ |
| 2502 | // unsigned long rx_length_errors; |
| 2503 | // unsigned long rx_over_errors; /* receiver ring buff overflow */ |
| 2504 | dev->stats.rx_crc_errors = vptr->mib_counter[HW_MIB_ifRxPktCRCE]; |
| 2505 | // unsigned long rx_frame_errors; /* recv'd frame alignment error */ |
| 2506 | // unsigned long rx_fifo_errors; /* recv'r fifo overrun */ |
| 2507 | // unsigned long rx_missed_errors; /* receiver missed packet */ |
| 2508 | |
| 2509 | /* detailed tx_errors */ |
| 2510 | // unsigned long tx_fifo_errors; |
| 2511 | |
| 2512 | return &dev->stats; |
| 2513 | } |
| 2514 | |
| 2515 | /** |
| 2516 | * velocity_close - close adapter callback |
| 2517 | * @dev: network device |
| 2518 | * |
| 2519 | * Callback from the network layer when the velocity is being |
| 2520 | * deactivated by the network layer |
| 2521 | */ |
| 2522 | static int velocity_close(struct net_device *dev) |
| 2523 | { |
| 2524 | struct velocity_info *vptr = netdev_priv(dev); |
| 2525 | |
Simon Kagstrom | dfff714 | 2009-11-25 22:10:26 +0000 | [diff] [blame] | 2526 | napi_disable(&vptr->napi); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2527 | netif_stop_queue(dev); |
| 2528 | velocity_shutdown(vptr); |
| 2529 | |
| 2530 | if (vptr->flags & VELOCITY_FLAGS_WOL_ENABLED) |
| 2531 | velocity_get_ip(vptr); |
Francois Romieu | dfda357 | 2012-03-09 15:24:37 +0100 | [diff] [blame] | 2532 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2533 | free_irq(dev->irq, dev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2534 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2535 | velocity_free_rings(vptr); |
| 2536 | |
| 2537 | vptr->flags &= (~VELOCITY_FLAGS_OPENED); |
| 2538 | return 0; |
| 2539 | } |
| 2540 | |
| 2541 | /** |
| 2542 | * velocity_xmit - transmit packet callback |
| 2543 | * @skb: buffer to transmit |
| 2544 | * @dev: network device |
| 2545 | * |
| 2546 | * Called by the networ layer to request a packet is queued to |
| 2547 | * the velocity. Returns zero on success. |
| 2548 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2549 | static netdev_tx_t velocity_xmit(struct sk_buff *skb, |
| 2550 | struct net_device *dev) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2551 | { |
| 2552 | struct velocity_info *vptr = netdev_priv(dev); |
| 2553 | int qnum = 0; |
| 2554 | struct tx_desc *td_ptr; |
| 2555 | struct velocity_td_info *tdinfo; |
| 2556 | unsigned long flags; |
| 2557 | int pktlen; |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2558 | int index, prev; |
| 2559 | int i = 0; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2560 | |
| 2561 | if (skb_padto(skb, ETH_ZLEN)) |
| 2562 | goto out; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2563 | |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2564 | /* The hardware can handle at most 7 memory segments, so merge |
| 2565 | * the skb if there are more */ |
| 2566 | if (skb_shinfo(skb)->nr_frags > 6 && __skb_linearize(skb)) { |
| 2567 | kfree_skb(skb); |
| 2568 | return NETDEV_TX_OK; |
| 2569 | } |
| 2570 | |
| 2571 | pktlen = skb_shinfo(skb)->nr_frags == 0 ? |
| 2572 | max_t(unsigned int, skb->len, ETH_ZLEN) : |
| 2573 | skb_headlen(skb); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2574 | |
| 2575 | spin_lock_irqsave(&vptr->lock, flags); |
| 2576 | |
| 2577 | index = vptr->tx.curr[qnum]; |
| 2578 | td_ptr = &(vptr->tx.rings[qnum][index]); |
| 2579 | tdinfo = &(vptr->tx.infos[qnum][index]); |
| 2580 | |
| 2581 | td_ptr->tdesc1.TCR = TCR0_TIC; |
| 2582 | td_ptr->td_buf[0].size &= ~TD_QUEUE; |
| 2583 | |
| 2584 | /* |
| 2585 | * Map the linear network buffer into PCI space and |
| 2586 | * add it to the transmit ring. |
| 2587 | */ |
| 2588 | tdinfo->skb = skb; |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 2589 | tdinfo->skb_dma[0] = dma_map_single(vptr->dev, skb->data, pktlen, |
| 2590 | DMA_TO_DEVICE); |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2591 | td_ptr->tdesc0.len = cpu_to_le16(pktlen); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2592 | td_ptr->td_buf[0].pa_low = cpu_to_le32(tdinfo->skb_dma[0]); |
| 2593 | td_ptr->td_buf[0].pa_high = 0; |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2594 | td_ptr->td_buf[0].size = cpu_to_le16(pktlen); |
| 2595 | |
| 2596 | /* Handle fragments */ |
| 2597 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2598 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2599 | |
Tony Prisk | e2c41f1 | 2013-05-18 09:39:06 +0000 | [diff] [blame] | 2600 | tdinfo->skb_dma[i + 1] = skb_frag_dma_map(vptr->dev, |
Ian Campbell | e4cb193 | 2011-09-21 21:53:26 +0000 | [diff] [blame] | 2601 | frag, 0, |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2602 | skb_frag_size(frag), |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 2603 | DMA_TO_DEVICE); |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2604 | |
| 2605 | td_ptr->td_buf[i + 1].pa_low = cpu_to_le32(tdinfo->skb_dma[i + 1]); |
| 2606 | td_ptr->td_buf[i + 1].pa_high = 0; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2607 | td_ptr->td_buf[i + 1].size = cpu_to_le16(skb_frag_size(frag)); |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2608 | } |
| 2609 | tdinfo->nskb_dma = i + 1; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2610 | |
| 2611 | td_ptr->tdesc1.cmd = TCPLS_NORMAL + (tdinfo->nskb_dma + 1) * 16; |
| 2612 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 2613 | if (vlan_tx_tag_present(skb)) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2614 | td_ptr->tdesc1.vlan = cpu_to_le16(vlan_tx_tag_get(skb)); |
| 2615 | td_ptr->tdesc1.TCR |= TCR0_VETAG; |
| 2616 | } |
| 2617 | |
| 2618 | /* |
| 2619 | * Handle hardware checksum |
| 2620 | */ |
Michał Mirosław | f593fe3 | 2011-04-10 03:13:21 +0000 | [diff] [blame] | 2621 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2622 | const struct iphdr *ip = ip_hdr(skb); |
| 2623 | if (ip->protocol == IPPROTO_TCP) |
| 2624 | td_ptr->tdesc1.TCR |= TCR0_TCPCK; |
| 2625 | else if (ip->protocol == IPPROTO_UDP) |
| 2626 | td_ptr->tdesc1.TCR |= (TCR0_UDPCK); |
| 2627 | td_ptr->tdesc1.TCR |= TCR0_IPCK; |
| 2628 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2629 | |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2630 | prev = index - 1; |
| 2631 | if (prev < 0) |
| 2632 | prev = vptr->options.numtx - 1; |
| 2633 | td_ptr->tdesc0.len |= OWNED_BY_NIC; |
| 2634 | vptr->tx.used[qnum]++; |
| 2635 | vptr->tx.curr[qnum] = (index + 1) % vptr->options.numtx; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2636 | |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2637 | if (AVAIL_TD(vptr, qnum) < 1) |
| 2638 | netif_stop_queue(dev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2639 | |
Simon Kagstrom | c79992f | 2009-11-25 22:10:43 +0000 | [diff] [blame] | 2640 | td_ptr = &(vptr->tx.rings[qnum][prev]); |
| 2641 | td_ptr->td_buf[0].size |= TD_QUEUE; |
| 2642 | mac_tx_queue_wake(vptr->mac_regs, qnum); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2643 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2644 | spin_unlock_irqrestore(&vptr->lock, flags); |
| 2645 | out: |
| 2646 | return NETDEV_TX_OK; |
| 2647 | } |
| 2648 | |
Stephen Hemminger | 39a11bd | 2008-11-19 22:19:33 -0800 | [diff] [blame] | 2649 | static const struct net_device_ops velocity_netdev_ops = { |
| 2650 | .ndo_open = velocity_open, |
| 2651 | .ndo_stop = velocity_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 2652 | .ndo_start_xmit = velocity_xmit, |
Stephen Hemminger | 39a11bd | 2008-11-19 22:19:33 -0800 | [diff] [blame] | 2653 | .ndo_get_stats = velocity_get_stats, |
| 2654 | .ndo_validate_addr = eth_validate_addr, |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 2655 | .ndo_set_mac_address = eth_mac_addr, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 2656 | .ndo_set_rx_mode = velocity_set_multi, |
Stephen Hemminger | 39a11bd | 2008-11-19 22:19:33 -0800 | [diff] [blame] | 2657 | .ndo_change_mtu = velocity_change_mtu, |
| 2658 | .ndo_do_ioctl = velocity_ioctl, |
| 2659 | .ndo_vlan_rx_add_vid = velocity_vlan_rx_add_vid, |
| 2660 | .ndo_vlan_rx_kill_vid = velocity_vlan_rx_kill_vid, |
Amit Uttamchandani | 0887a57 | 2013-07-18 17:45:22 -0700 | [diff] [blame] | 2661 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2662 | .ndo_poll_controller = velocity_poll_controller, |
| 2663 | #endif |
Stephen Hemminger | 39a11bd | 2008-11-19 22:19:33 -0800 | [diff] [blame] | 2664 | }; |
| 2665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | /** |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2667 | * velocity_init_info - init private data |
| 2668 | * @pdev: PCI device |
| 2669 | * @vptr: Velocity info |
| 2670 | * @info: Board type |
| 2671 | * |
| 2672 | * Set up the initial velocity_info struct for the device that has been |
| 2673 | * discovered. |
| 2674 | */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2675 | static void velocity_init_info(struct velocity_info *vptr, |
| 2676 | const struct velocity_info_tbl *info) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2677 | { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2678 | vptr->chip_id = info->chip_id; |
| 2679 | vptr->tx.numq = info->txqueue; |
| 2680 | vptr->multicast_limit = MCAM_SIZE; |
| 2681 | spin_lock_init(&vptr->lock); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | /** |
| 2685 | * velocity_get_pci_info - retrieve PCI info for device |
| 2686 | * @vptr: velocity device |
| 2687 | * @pdev: PCI device it matches |
| 2688 | * |
| 2689 | * Retrieve the PCI configuration space data that interests us from |
| 2690 | * the kernel PCI layer |
| 2691 | */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2692 | static int velocity_get_pci_info(struct velocity_info *vptr) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2693 | { |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2694 | struct pci_dev *pdev = vptr->pdev; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2695 | |
| 2696 | pci_set_master(pdev); |
| 2697 | |
| 2698 | vptr->ioaddr = pci_resource_start(pdev, 0); |
| 2699 | vptr->memaddr = pci_resource_start(pdev, 1); |
| 2700 | |
| 2701 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_IO)) { |
| 2702 | dev_err(&pdev->dev, |
| 2703 | "region #0 is not an I/O resource, aborting.\n"); |
| 2704 | return -EINVAL; |
| 2705 | } |
| 2706 | |
| 2707 | if ((pci_resource_flags(pdev, 1) & IORESOURCE_IO)) { |
| 2708 | dev_err(&pdev->dev, |
| 2709 | "region #1 is an I/O resource, aborting.\n"); |
| 2710 | return -EINVAL; |
| 2711 | } |
| 2712 | |
| 2713 | if (pci_resource_len(pdev, 1) < VELOCITY_IO_SIZE) { |
| 2714 | dev_err(&pdev->dev, "region #1 is too small.\n"); |
| 2715 | return -EINVAL; |
| 2716 | } |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2717 | |
| 2718 | return 0; |
| 2719 | } |
| 2720 | |
| 2721 | /** |
| 2722 | * velocity_get_platform_info - retrieve platform info for device |
| 2723 | * @vptr: velocity device |
| 2724 | * @pdev: platform device it matches |
| 2725 | * |
| 2726 | * Retrieve the Platform configuration data that interests us |
| 2727 | */ |
| 2728 | static int velocity_get_platform_info(struct velocity_info *vptr) |
| 2729 | { |
| 2730 | struct resource res; |
| 2731 | int ret; |
| 2732 | |
| 2733 | if (of_get_property(vptr->dev->of_node, "no-eeprom", NULL)) |
| 2734 | vptr->no_eeprom = 1; |
| 2735 | |
| 2736 | ret = of_address_to_resource(vptr->dev->of_node, 0, &res); |
| 2737 | if (ret) { |
| 2738 | dev_err(vptr->dev, "unable to find memory address\n"); |
| 2739 | return ret; |
| 2740 | } |
| 2741 | |
| 2742 | vptr->memaddr = res.start; |
| 2743 | |
| 2744 | if (resource_size(&res) < VELOCITY_IO_SIZE) { |
| 2745 | dev_err(vptr->dev, "memory region is too small.\n"); |
| 2746 | return -EINVAL; |
| 2747 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2748 | |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
| 2752 | /** |
| 2753 | * velocity_print_info - per driver data |
| 2754 | * @vptr: velocity |
| 2755 | * |
| 2756 | * Print per driver data as the kernel driver finds Velocity |
| 2757 | * hardware |
| 2758 | */ |
Bill Pemberton | 27add00 | 2012-12-03 09:23:49 -0500 | [diff] [blame] | 2759 | static void velocity_print_info(struct velocity_info *vptr) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2760 | { |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 2761 | struct net_device *dev = vptr->netdev; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2762 | |
| 2763 | printk(KERN_INFO "%s: %s\n", dev->name, get_chip_name(vptr->chip_id)); |
H Hartley Sweeten | aa7c68a | 2009-12-29 20:04:14 -0800 | [diff] [blame] | 2764 | printk(KERN_INFO "%s: Ethernet Address: %pM\n", |
| 2765 | dev->name, dev->dev_addr); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | static u32 velocity_get_link(struct net_device *dev) |
| 2769 | { |
| 2770 | struct velocity_info *vptr = netdev_priv(dev); |
| 2771 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 2772 | return BYTE_REG_BITS_IS_ON(PHYSR0_LINKGD, ®s->PHYSR0) ? 1 : 0; |
| 2773 | } |
| 2774 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2775 | /** |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2776 | * velocity_probe - set up discovered velocity device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | * @pdev: PCI device |
| 2778 | * @ent: PCI device table entry that matched |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2779 | * @bustype: bus that device is connected to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | * |
| 2781 | * Configure a discovered adapter from scratch. Return a negative |
| 2782 | * errno error code on failure paths. |
| 2783 | */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2784 | static int velocity_probe(struct device *dev, int irq, |
| 2785 | const struct velocity_info_tbl *info, |
| 2786 | enum velocity_bus_type bustype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | { |
| 2788 | static int first = 1; |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2789 | struct net_device *netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2790 | int i; |
Sven Hartge | 07b5f6a | 2008-10-23 13:03:44 +0000 | [diff] [blame] | 2791 | const char *drv_string; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2792 | struct velocity_info *vptr; |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 2793 | struct mac_regs __iomem *regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | int ret = -ENOMEM; |
| 2795 | |
Jeff Garzik | e54f489 | 2006-06-27 09:20:08 -0400 | [diff] [blame] | 2796 | /* FIXME: this driver, like almost all other ethernet drivers, |
| 2797 | * can support more than MAX_UNITS. |
| 2798 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | if (velocity_nics >= MAX_UNITS) { |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2800 | dev_notice(dev, "already found %d NICs.\n", velocity_nics); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | return -ENODEV; |
| 2802 | } |
| 2803 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2804 | netdev = alloc_etherdev(sizeof(struct velocity_info)); |
| 2805 | if (!netdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | goto out; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | /* Chain it all together */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2809 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2810 | SET_NETDEV_DEV(netdev, dev); |
| 2811 | vptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2813 | if (first) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2814 | printk(KERN_INFO "%s Ver. %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | VELOCITY_FULL_DRV_NAM, VELOCITY_VERSION); |
| 2816 | printk(KERN_INFO "Copyright (c) 2002, 2003 VIA Networking Technologies, Inc.\n"); |
| 2817 | printk(KERN_INFO "Copyright (c) 2004 Red Hat Inc.\n"); |
| 2818 | first = 0; |
| 2819 | } |
| 2820 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2821 | netdev->irq = irq; |
| 2822 | vptr->netdev = netdev; |
| 2823 | vptr->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2825 | velocity_init_info(vptr, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2827 | if (bustype == BUS_PCI) { |
| 2828 | vptr->pdev = to_pci_dev(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2830 | ret = velocity_get_pci_info(vptr); |
| 2831 | if (ret < 0) |
| 2832 | goto err_free_dev; |
| 2833 | } else { |
| 2834 | vptr->pdev = NULL; |
| 2835 | ret = velocity_get_platform_info(vptr); |
| 2836 | if (ret < 0) |
| 2837 | goto err_free_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | } |
| 2839 | |
Jeff Garzik | cabb766 | 2006-06-27 09:25:28 -0400 | [diff] [blame] | 2840 | regs = ioremap(vptr->memaddr, VELOCITY_IO_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | if (regs == NULL) { |
| 2842 | ret = -EIO; |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2843 | goto err_free_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | vptr->mac_regs = regs; |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2847 | vptr->rev_id = readb(®s->rev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
| 2849 | mac_wol_reset(regs); |
| 2850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | for (i = 0; i < 6; i++) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2852 | netdev->dev_addr[i] = readb(®s->PAR[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | |
| 2854 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2855 | drv_string = dev_driver_string(dev); |
Sven Hartge | 07b5f6a | 2008-10-23 13:03:44 +0000 | [diff] [blame] | 2856 | |
| 2857 | velocity_get_options(&vptr->options, velocity_nics, drv_string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2858 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2859 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2860 | * Mask out the options cannot be set to the chip |
| 2861 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2863 | vptr->options.flags &= info->flags; |
| 2864 | |
| 2865 | /* |
| 2866 | * Enable the chip specified capbilities |
| 2867 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | vptr->flags = vptr->options.flags | (info->flags & 0xFF000000UL); |
| 2870 | |
| 2871 | vptr->wol_opts = vptr->options.wol_opts; |
| 2872 | vptr->flags |= VELOCITY_FLAGS_WOL_ENABLED; |
| 2873 | |
| 2874 | vptr->phy_id = MII_GET_PHY_ID(vptr->mac_regs); |
| 2875 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2876 | netdev->netdev_ops = &velocity_netdev_ops; |
| 2877 | netdev->ethtool_ops = &velocity_ethtool_ops; |
| 2878 | netif_napi_add(netdev, &vptr->napi, velocity_poll, |
| 2879 | VELOCITY_NAPI_WEIGHT); |
Stephen Hemminger | 501e4d2 | 2007-08-24 13:56:49 -0700 | [diff] [blame] | 2880 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2881 | netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_SG | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2882 | NETIF_F_HW_VLAN_CTAG_TX; |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2883 | netdev->features |= NETIF_F_HW_VLAN_CTAG_TX | |
| 2884 | NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_CTAG_RX | |
| 2885 | NETIF_F_IP_CSUM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2886 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2887 | ret = register_netdev(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | if (ret < 0) |
| 2889 | goto err_iounmap; |
| 2890 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2891 | if (!velocity_get_link(netdev)) { |
| 2892 | netif_carrier_off(netdev); |
Séguier Régis | d3b238a | 2009-06-16 11:25:49 +0000 | [diff] [blame] | 2893 | vptr->mii_status |= VELOCITY_LINK_FAIL; |
| 2894 | } |
Francois Romieu | 8a22ddd | 2006-06-23 00:47:06 +0200 | [diff] [blame] | 2895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | velocity_print_info(vptr); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2897 | dev_set_drvdata(vptr->dev, netdev); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2899 | /* and leave the chip powered down */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 2900 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2901 | velocity_set_power_state(vptr, PCI_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | velocity_nics++; |
| 2903 | out: |
| 2904 | return ret; |
| 2905 | |
| 2906 | err_iounmap: |
Julia Lawall | 2fdac01 | 2013-08-14 16:26:53 +0200 | [diff] [blame] | 2907 | netif_napi_del(&vptr->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | iounmap(regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | err_free_dev: |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2910 | free_netdev(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2911 | goto out; |
| 2912 | } |
| 2913 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2914 | /** |
| 2915 | * velocity_remove - device unplug |
| 2916 | * @dev: device being removed |
| 2917 | * |
| 2918 | * Device unload callback. Called on an unplug or on module |
| 2919 | * unload for each active device that is present. Disconnects |
| 2920 | * the device from the network layer and frees all the resources |
| 2921 | */ |
| 2922 | static int velocity_remove(struct device *dev) |
| 2923 | { |
| 2924 | struct net_device *netdev = dev_get_drvdata(dev); |
| 2925 | struct velocity_info *vptr = netdev_priv(netdev); |
| 2926 | |
| 2927 | unregister_netdev(netdev); |
Julia Lawall | 2fdac01 | 2013-08-14 16:26:53 +0200 | [diff] [blame] | 2928 | netif_napi_del(&vptr->napi); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 2929 | iounmap(vptr->mac_regs); |
| 2930 | free_netdev(netdev); |
| 2931 | velocity_nics--; |
| 2932 | |
| 2933 | return 0; |
| 2934 | } |
| 2935 | |
| 2936 | static int velocity_pci_probe(struct pci_dev *pdev, |
| 2937 | const struct pci_device_id *ent) |
| 2938 | { |
| 2939 | const struct velocity_info_tbl *info = |
| 2940 | &chip_info_table[ent->driver_data]; |
| 2941 | int ret; |
| 2942 | |
| 2943 | ret = pci_enable_device(pdev); |
| 2944 | if (ret < 0) |
| 2945 | return ret; |
| 2946 | |
| 2947 | ret = pci_request_regions(pdev, VELOCITY_NAME); |
| 2948 | if (ret < 0) { |
| 2949 | dev_err(&pdev->dev, "No PCI resources.\n"); |
| 2950 | goto fail1; |
| 2951 | } |
| 2952 | |
| 2953 | ret = velocity_probe(&pdev->dev, pdev->irq, info, BUS_PCI); |
| 2954 | if (ret == 0) |
| 2955 | return 0; |
| 2956 | |
| 2957 | pci_release_regions(pdev); |
| 2958 | fail1: |
| 2959 | pci_disable_device(pdev); |
| 2960 | return ret; |
| 2961 | } |
| 2962 | |
| 2963 | static void velocity_pci_remove(struct pci_dev *pdev) |
| 2964 | { |
| 2965 | velocity_remove(&pdev->dev); |
| 2966 | |
| 2967 | pci_release_regions(pdev); |
| 2968 | pci_disable_device(pdev); |
| 2969 | } |
| 2970 | |
| 2971 | static int velocity_platform_probe(struct platform_device *pdev) |
| 2972 | { |
| 2973 | const struct of_device_id *of_id; |
| 2974 | const struct velocity_info_tbl *info; |
| 2975 | int irq; |
| 2976 | |
| 2977 | of_id = of_match_device(velocity_of_ids, &pdev->dev); |
| 2978 | if (!of_id) |
| 2979 | return -EINVAL; |
| 2980 | info = of_id->data; |
| 2981 | |
| 2982 | irq = irq_of_parse_and_map(pdev->dev.of_node, 0); |
| 2983 | if (!irq) |
| 2984 | return -EINVAL; |
| 2985 | |
| 2986 | return velocity_probe(&pdev->dev, irq, info, BUS_PLATFORM); |
| 2987 | } |
| 2988 | |
| 2989 | static int velocity_platform_remove(struct platform_device *pdev) |
| 2990 | { |
| 2991 | velocity_remove(&pdev->dev); |
| 2992 | |
| 2993 | return 0; |
| 2994 | } |
| 2995 | |
| 2996 | #ifdef CONFIG_PM_SLEEP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | /** |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 2998 | * wol_calc_crc - WOL CRC |
| 2999 | * @pattern: data pattern |
| 3000 | * @mask_pattern: mask |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | * |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3002 | * Compute the wake on lan crc hashes for the packet header |
| 3003 | * we are interested in. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | */ |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3005 | static u16 wol_calc_crc(int size, u8 *pattern, u8 *mask_pattern) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3006 | { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3007 | u16 crc = 0xFFFF; |
| 3008 | u8 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | int i, j; |
| 3010 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3011 | for (i = 0; i < size; i++) { |
| 3012 | mask = mask_pattern[i]; |
| 3013 | |
| 3014 | /* Skip this loop if the mask equals to zero */ |
| 3015 | if (mask == 0x00) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3018 | for (j = 0; j < 8; j++) { |
| 3019 | if ((mask & 0x01) == 0) { |
| 3020 | mask >>= 1; |
| 3021 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3023 | mask >>= 1; |
| 3024 | crc = crc_ccitt(crc, &(pattern[i * 8 + j]), 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | } |
| 3026 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3027 | /* Finally, invert the result once to get the correct data */ |
| 3028 | crc = ~crc; |
| 3029 | return bitrev32(crc) >> 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | /** |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3033 | * velocity_set_wol - set up for wake on lan |
| 3034 | * @vptr: velocity to set WOL status on |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | * |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3036 | * Set a card up for wake on lan either by unicast or by |
| 3037 | * ARP packet. |
| 3038 | * |
| 3039 | * FIXME: check static buffer is safe here |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | */ |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3041 | static int velocity_set_wol(struct velocity_info *vptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | { |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 3043 | struct mac_regs __iomem *regs = vptr->mac_regs; |
françois romieu | 2ffa007 | 2011-01-20 04:59:33 +0000 | [diff] [blame] | 3044 | enum speed_opt spd_dpx = vptr->options.spd_dpx; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3045 | static u8 buf[256]; |
| 3046 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3048 | static u32 mask_pattern[2][4] = { |
| 3049 | {0x00203000, 0x000003C0, 0x00000000, 0x0000000}, /* ARP */ |
| 3050 | {0xfffff000, 0xffffffff, 0xffffffff, 0x000ffff} /* Magic Packet */ |
| 3051 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3053 | writew(0xFFFF, ®s->WOLCRClr); |
| 3054 | writeb(WOLCFG_SAB | WOLCFG_SAM, ®s->WOLCFGSet); |
| 3055 | writew(WOLCR_MAGIC_EN, ®s->WOLCRSet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3056 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3057 | /* |
| 3058 | if (vptr->wol_opts & VELOCITY_WOL_PHY) |
| 3059 | writew((WOLCR_LINKON_EN|WOLCR_LINKOFF_EN), ®s->WOLCRSet); |
| 3060 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3061 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3062 | if (vptr->wol_opts & VELOCITY_WOL_UCAST) |
| 3063 | writew(WOLCR_UNICAST_EN, ®s->WOLCRSet); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3064 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3065 | if (vptr->wol_opts & VELOCITY_WOL_ARP) { |
| 3066 | struct arp_packet *arp = (struct arp_packet *) buf; |
| 3067 | u16 crc; |
| 3068 | memset(buf, 0, sizeof(struct arp_packet) + 7); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3069 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3070 | for (i = 0; i < 4; i++) |
| 3071 | writel(mask_pattern[0][i], ®s->ByteMask[0][i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3073 | arp->type = htons(ETH_P_ARP); |
| 3074 | arp->ar_op = htons(1); |
| 3075 | |
| 3076 | memcpy(arp->ar_tip, vptr->ip_addr, 4); |
| 3077 | |
| 3078 | crc = wol_calc_crc((sizeof(struct arp_packet) + 7) / 8, buf, |
| 3079 | (u8 *) & mask_pattern[0][0]); |
| 3080 | |
| 3081 | writew(crc, ®s->PatternCRC[0]); |
| 3082 | writew(WOLCR_ARP_EN, ®s->WOLCRSet); |
| 3083 | } |
| 3084 | |
| 3085 | BYTE_REG_BITS_ON(PWCFG_WOLTYPE, ®s->PWCFGSet); |
| 3086 | BYTE_REG_BITS_ON(PWCFG_LEGACY_WOLEN, ®s->PWCFGSet); |
| 3087 | |
| 3088 | writew(0x0FFF, ®s->WOLSRClr); |
| 3089 | |
françois romieu | 2ffa007 | 2011-01-20 04:59:33 +0000 | [diff] [blame] | 3090 | if (spd_dpx == SPD_DPX_1000_FULL) |
| 3091 | goto mac_done; |
| 3092 | |
| 3093 | if (spd_dpx != SPD_DPX_AUTO) |
| 3094 | goto advertise_done; |
| 3095 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3096 | if (vptr->mii_status & VELOCITY_AUTONEG_ENABLE) { |
| 3097 | if (PHYID_GET_PHY_ID(vptr->phy_id) == PHYID_CICADA_CS8201) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 3098 | MII_REG_BITS_ON(AUXCR_MDPPS, MII_NCONFIG, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3099 | |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 3100 | MII_REG_BITS_OFF(ADVERTISE_1000FULL | ADVERTISE_1000HALF, MII_CTRL1000, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | if (vptr->mii_status & VELOCITY_SPEED_1000) |
Francois Romieu | 3a7f868 | 2010-04-06 14:24:53 -0700 | [diff] [blame] | 3104 | MII_REG_BITS_ON(BMCR_ANRESTART, MII_BMCR, vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3105 | |
françois romieu | 2ffa007 | 2011-01-20 04:59:33 +0000 | [diff] [blame] | 3106 | advertise_done: |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3107 | BYTE_REG_BITS_ON(CHIPGCR_FCMODE, ®s->CHIPGCR); |
| 3108 | |
| 3109 | { |
| 3110 | u8 GCR; |
| 3111 | GCR = readb(®s->CHIPGCR); |
| 3112 | GCR = (GCR & ~CHIPGCR_FCGMII) | CHIPGCR_FCFDX; |
| 3113 | writeb(GCR, ®s->CHIPGCR); |
| 3114 | } |
| 3115 | |
françois romieu | 2ffa007 | 2011-01-20 04:59:33 +0000 | [diff] [blame] | 3116 | mac_done: |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3117 | BYTE_REG_BITS_OFF(ISR_PWEI, ®s->ISR); |
| 3118 | /* Turn on SWPTAG just before entering power mode */ |
| 3119 | BYTE_REG_BITS_ON(STICKHW_SWPTAG, ®s->STICKHW); |
| 3120 | /* Go to bed ..... */ |
| 3121 | BYTE_REG_BITS_ON((STICKHW_DS1 | STICKHW_DS0), ®s->STICKHW); |
| 3122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | return 0; |
| 3124 | } |
| 3125 | |
| 3126 | /** |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3127 | * velocity_save_context - save registers |
| 3128 | * @vptr: velocity |
| 3129 | * @context: buffer for stored context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | * |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3131 | * Retrieve the current configuration from the velocity hardware |
| 3132 | * and stash it in the context structure, for use by the context |
| 3133 | * restore functions. This allows us to save things we need across |
| 3134 | * power down states |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | */ |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3136 | static void velocity_save_context(struct velocity_info *vptr, struct velocity_context *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3138 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 3139 | u16 i; |
| 3140 | u8 __iomem *ptr = (u8 __iomem *)regs; |
| 3141 | |
| 3142 | for (i = MAC_REG_PAR; i < MAC_REG_CR0_CLR; i += 4) |
| 3143 | *((u32 *) (context->mac_reg + i)) = readl(ptr + i); |
| 3144 | |
| 3145 | for (i = MAC_REG_MAR; i < MAC_REG_TDCSR_CLR; i += 4) |
| 3146 | *((u32 *) (context->mac_reg + i)) = readl(ptr + i); |
| 3147 | |
| 3148 | for (i = MAC_REG_RDBASE_LO; i < MAC_REG_FIFO_TEST0; i += 4) |
| 3149 | *((u32 *) (context->mac_reg + i)) = readl(ptr + i); |
| 3150 | |
| 3151 | } |
| 3152 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3153 | static int velocity_suspend(struct device *dev) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3154 | { |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3155 | struct net_device *netdev = dev_get_drvdata(dev); |
| 3156 | struct velocity_info *vptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3157 | unsigned long flags; |
Francois Romieu | 580a690 | 2008-07-11 00:03:44 +0200 | [diff] [blame] | 3158 | |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 3159 | if (!netif_running(vptr->netdev)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3160 | return 0; |
Francois Romieu | 580a690 | 2008-07-11 00:03:44 +0200 | [diff] [blame] | 3161 | |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 3162 | netif_device_detach(vptr->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | |
| 3164 | spin_lock_irqsave(&vptr->lock, flags); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3165 | if (vptr->pdev) |
| 3166 | pci_save_state(vptr->pdev); |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3167 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3168 | if (vptr->flags & VELOCITY_FLAGS_WOL_ENABLED) { |
| 3169 | velocity_get_ip(vptr); |
| 3170 | velocity_save_context(vptr, &vptr->context); |
| 3171 | velocity_shutdown(vptr); |
| 3172 | velocity_set_wol(vptr); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3173 | if (vptr->pdev) |
| 3174 | pci_enable_wake(vptr->pdev, PCI_D3hot, 1); |
| 3175 | velocity_set_power_state(vptr, PCI_D3hot); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3176 | } else { |
| 3177 | velocity_save_context(vptr, &vptr->context); |
| 3178 | velocity_shutdown(vptr); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3179 | if (vptr->pdev) |
| 3180 | pci_disable_device(vptr->pdev); |
| 3181 | velocity_set_power_state(vptr, PCI_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | } |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3184 | spin_unlock_irqrestore(&vptr->lock, flags); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3185 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | /** |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3189 | * velocity_restore_context - restore registers |
| 3190 | * @vptr: velocity |
| 3191 | * @context: buffer for stored context |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | * |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3193 | * Reload the register configuration from the velocity context |
| 3194 | * created by velocity_save_context. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | */ |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3196 | static void velocity_restore_context(struct velocity_info *vptr, struct velocity_context *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3198 | struct mac_regs __iomem *regs = vptr->mac_regs; |
| 3199 | int i; |
| 3200 | u8 __iomem *ptr = (u8 __iomem *)regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3202 | for (i = MAC_REG_PAR; i < MAC_REG_CR0_SET; i += 4) |
| 3203 | writel(*((u32 *) (context->mac_reg + i)), ptr + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3205 | /* Just skip cr0 */ |
| 3206 | for (i = MAC_REG_CR1_SET; i < MAC_REG_CR0_CLR; i++) { |
| 3207 | /* Clear */ |
| 3208 | writeb(~(*((u8 *) (context->mac_reg + i))), ptr + i + 4); |
| 3209 | /* Set */ |
| 3210 | writeb(*((u8 *) (context->mac_reg + i)), ptr + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | } |
| 3212 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3213 | for (i = MAC_REG_MAR; i < MAC_REG_IMR; i += 4) |
| 3214 | writel(*((u32 *) (context->mac_reg + i)), ptr + i); |
| 3215 | |
| 3216 | for (i = MAC_REG_RDBASE_LO; i < MAC_REG_FIFO_TEST0; i += 4) |
| 3217 | writel(*((u32 *) (context->mac_reg + i)), ptr + i); |
| 3218 | |
| 3219 | for (i = MAC_REG_TDCSR_SET; i <= MAC_REG_RDCSR_SET; i++) |
| 3220 | writeb(*((u8 *) (context->mac_reg + i)), ptr + i); |
| 3221 | } |
| 3222 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3223 | static int velocity_resume(struct device *dev) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3224 | { |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3225 | struct net_device *netdev = dev_get_drvdata(dev); |
| 3226 | struct velocity_info *vptr = netdev_priv(netdev); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3227 | unsigned long flags; |
| 3228 | int i; |
| 3229 | |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 3230 | if (!netif_running(vptr->netdev)) |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3231 | return 0; |
| 3232 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3233 | velocity_set_power_state(vptr, PCI_D0); |
| 3234 | |
| 3235 | if (vptr->pdev) { |
Yijing Wang | 1ca0151 | 2013-06-27 20:53:42 +0800 | [diff] [blame] | 3236 | pci_enable_wake(vptr->pdev, PCI_D0, 0); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3237 | pci_restore_state(vptr->pdev); |
| 3238 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3239 | |
| 3240 | mac_wol_reset(vptr->mac_regs); |
| 3241 | |
| 3242 | spin_lock_irqsave(&vptr->lock, flags); |
| 3243 | velocity_restore_context(vptr, &vptr->context); |
| 3244 | velocity_init_registers(vptr, VELOCITY_INIT_WOL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | mac_disable_int(vptr->mac_regs); |
| 3246 | |
Simon Kagstrom | d6cade0 | 2010-02-09 23:37:54 +0000 | [diff] [blame] | 3247 | velocity_tx_srv(vptr); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3248 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3249 | for (i = 0; i < vptr->tx.numq; i++) { |
| 3250 | if (vptr->tx.used[i]) |
| 3251 | mac_tx_queue_wake(vptr->mac_regs, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3252 | } |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3254 | mac_enable_int(vptr->mac_regs); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3255 | spin_unlock_irqrestore(&vptr->lock, flags); |
Tony Prisk | a9683c9 | 2013-05-18 09:39:05 +0000 | [diff] [blame] | 3256 | netif_device_attach(vptr->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3258 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3260 | #endif /* CONFIG_PM_SLEEP */ |
| 3261 | |
| 3262 | static SIMPLE_DEV_PM_OPS(velocity_pm_ops, velocity_suspend, velocity_resume); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | |
| 3264 | /* |
| 3265 | * Definition for our device driver. The PCI layer interface |
| 3266 | * uses this to handle all our card discover and plugging |
| 3267 | */ |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3268 | static struct pci_driver velocity_pci_driver = { |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3269 | .name = VELOCITY_NAME, |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3270 | .id_table = velocity_pci_id_table, |
| 3271 | .probe = velocity_pci_probe, |
| 3272 | .remove = velocity_pci_remove, |
| 3273 | .driver = { |
| 3274 | .pm = &velocity_pm_ops, |
| 3275 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | }; |
| 3277 | |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3278 | static struct platform_driver velocity_platform_driver = { |
| 3279 | .probe = velocity_platform_probe, |
| 3280 | .remove = velocity_platform_remove, |
| 3281 | .driver = { |
| 3282 | .name = "via-velocity", |
| 3283 | .owner = THIS_MODULE, |
| 3284 | .of_match_table = velocity_of_ids, |
| 3285 | .pm = &velocity_pm_ops, |
| 3286 | }, |
| 3287 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | |
| 3289 | /** |
| 3290 | * velocity_ethtool_up - pre hook for ethtool |
| 3291 | * @dev: network device |
| 3292 | * |
| 3293 | * Called before an ethtool operation. We need to make sure the |
| 3294 | * chip is out of D3 state before we poke at it. |
| 3295 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | static int velocity_ethtool_up(struct net_device *dev) |
| 3297 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3298 | struct velocity_info *vptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | if (!netif_running(dev)) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3300 | velocity_set_power_state(vptr, PCI_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | return 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | |
| 3304 | /** |
| 3305 | * velocity_ethtool_down - post hook for ethtool |
| 3306 | * @dev: network device |
| 3307 | * |
| 3308 | * Called after an ethtool operation. Restore the chip back to D3 |
| 3309 | * state if it isn't running. |
| 3310 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3311 | static void velocity_ethtool_down(struct net_device *dev) |
| 3312 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3313 | struct velocity_info *vptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | if (!netif_running(dev)) |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3315 | velocity_set_power_state(vptr, PCI_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 3318 | static int velocity_get_settings(struct net_device *dev, |
| 3319 | struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3321 | struct velocity_info *vptr = netdev_priv(dev); |
Dave Jones | c406740 | 2009-07-20 17:35:21 +0000 | [diff] [blame] | 3322 | struct mac_regs __iomem *regs = vptr->mac_regs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | u32 status; |
| 3324 | status = check_connection_type(vptr->mac_regs); |
| 3325 | |
Jay Cliburn | 59b693f | 2006-07-20 23:23:57 +0200 | [diff] [blame] | 3326 | cmd->supported = SUPPORTED_TP | |
| 3327 | SUPPORTED_Autoneg | |
| 3328 | SUPPORTED_10baseT_Half | |
| 3329 | SUPPORTED_10baseT_Full | |
| 3330 | SUPPORTED_100baseT_Half | |
| 3331 | SUPPORTED_100baseT_Full | |
| 3332 | SUPPORTED_1000baseT_Half | |
| 3333 | SUPPORTED_1000baseT_Full; |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 3334 | |
| 3335 | cmd->advertising = ADVERTISED_TP | ADVERTISED_Autoneg; |
| 3336 | if (vptr->options.spd_dpx == SPD_DPX_AUTO) { |
| 3337 | cmd->advertising |= |
| 3338 | ADVERTISED_10baseT_Half | |
| 3339 | ADVERTISED_10baseT_Full | |
| 3340 | ADVERTISED_100baseT_Half | |
| 3341 | ADVERTISED_100baseT_Full | |
| 3342 | ADVERTISED_1000baseT_Half | |
| 3343 | ADVERTISED_1000baseT_Full; |
| 3344 | } else { |
| 3345 | switch (vptr->options.spd_dpx) { |
| 3346 | case SPD_DPX_1000_FULL: |
| 3347 | cmd->advertising |= ADVERTISED_1000baseT_Full; |
| 3348 | break; |
| 3349 | case SPD_DPX_100_HALF: |
| 3350 | cmd->advertising |= ADVERTISED_100baseT_Half; |
| 3351 | break; |
| 3352 | case SPD_DPX_100_FULL: |
| 3353 | cmd->advertising |= ADVERTISED_100baseT_Full; |
| 3354 | break; |
| 3355 | case SPD_DPX_10_HALF: |
| 3356 | cmd->advertising |= ADVERTISED_10baseT_Half; |
| 3357 | break; |
| 3358 | case SPD_DPX_10_FULL: |
| 3359 | cmd->advertising |= ADVERTISED_10baseT_Full; |
| 3360 | break; |
| 3361 | default: |
| 3362 | break; |
| 3363 | } |
| 3364 | } |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 3365 | |
Jay Cliburn | 59b693f | 2006-07-20 23:23:57 +0200 | [diff] [blame] | 3366 | if (status & VELOCITY_SPEED_1000) |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 3367 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Jay Cliburn | 59b693f | 2006-07-20 23:23:57 +0200 | [diff] [blame] | 3368 | else if (status & VELOCITY_SPEED_100) |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 3369 | ethtool_cmd_speed_set(cmd, SPEED_100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | else |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 3371 | ethtool_cmd_speed_set(cmd, SPEED_10); |
| 3372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | cmd->autoneg = (status & VELOCITY_AUTONEG_ENABLE) ? AUTONEG_ENABLE : AUTONEG_DISABLE; |
| 3374 | cmd->port = PORT_TP; |
| 3375 | cmd->transceiver = XCVR_INTERNAL; |
| 3376 | cmd->phy_address = readb(®s->MIIADR) & 0x1F; |
| 3377 | |
| 3378 | if (status & VELOCITY_DUPLEX_FULL) |
| 3379 | cmd->duplex = DUPLEX_FULL; |
| 3380 | else |
| 3381 | cmd->duplex = DUPLEX_HALF; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | return 0; |
| 3384 | } |
| 3385 | |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 3386 | static int velocity_set_settings(struct net_device *dev, |
| 3387 | struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3389 | struct velocity_info *vptr = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 3390 | u32 speed = ethtool_cmd_speed(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | u32 curr_status; |
| 3392 | u32 new_status = 0; |
| 3393 | int ret = 0; |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 3394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3395 | curr_status = check_connection_type(vptr->mac_regs); |
| 3396 | curr_status &= (~VELOCITY_LINK_FAIL); |
| 3397 | |
| 3398 | new_status |= ((cmd->autoneg) ? VELOCITY_AUTONEG_ENABLE : 0); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 3399 | new_status |= ((speed == SPEED_1000) ? VELOCITY_SPEED_1000 : 0); |
| 3400 | new_status |= ((speed == SPEED_100) ? VELOCITY_SPEED_100 : 0); |
| 3401 | new_status |= ((speed == SPEED_10) ? VELOCITY_SPEED_10 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3402 | new_status |= ((cmd->duplex == DUPLEX_FULL) ? VELOCITY_DUPLEX_FULL : 0); |
| 3403 | |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 3404 | if ((new_status & VELOCITY_AUTONEG_ENABLE) && |
| 3405 | (new_status != (curr_status | VELOCITY_AUTONEG_ENABLE))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3406 | ret = -EINVAL; |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 3407 | } else { |
| 3408 | enum speed_opt spd_dpx; |
| 3409 | |
| 3410 | if (new_status & VELOCITY_AUTONEG_ENABLE) |
| 3411 | spd_dpx = SPD_DPX_AUTO; |
| 3412 | else if ((new_status & VELOCITY_SPEED_1000) && |
| 3413 | (new_status & VELOCITY_DUPLEX_FULL)) { |
| 3414 | spd_dpx = SPD_DPX_1000_FULL; |
| 3415 | } else if (new_status & VELOCITY_SPEED_100) |
| 3416 | spd_dpx = (new_status & VELOCITY_DUPLEX_FULL) ? |
| 3417 | SPD_DPX_100_FULL : SPD_DPX_100_HALF; |
| 3418 | else if (new_status & VELOCITY_SPEED_10) |
| 3419 | spd_dpx = (new_status & VELOCITY_DUPLEX_FULL) ? |
| 3420 | SPD_DPX_10_FULL : SPD_DPX_10_HALF; |
| 3421 | else |
| 3422 | return -EOPNOTSUPP; |
| 3423 | |
| 3424 | vptr->options.spd_dpx = spd_dpx; |
| 3425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | velocity_set_media_mode(vptr, new_status); |
françois romieu | 1541922 | 2010-10-13 09:26:05 +0000 | [diff] [blame] | 3427 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | |
| 3429 | return ret; |
| 3430 | } |
| 3431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3432 | static void velocity_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 3433 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3434 | struct velocity_info *vptr = netdev_priv(dev); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3435 | |
Rick Jones | 23020ab | 2011-11-09 09:58:07 +0000 | [diff] [blame] | 3436 | strlcpy(info->driver, VELOCITY_NAME, sizeof(info->driver)); |
| 3437 | strlcpy(info->version, VELOCITY_VERSION, sizeof(info->version)); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3438 | if (vptr->pdev) |
| 3439 | strlcpy(info->bus_info, pci_name(vptr->pdev), |
| 3440 | sizeof(info->bus_info)); |
| 3441 | else |
| 3442 | strlcpy(info->bus_info, "platform", sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | static void velocity_ethtool_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 3446 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3447 | struct velocity_info *vptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | wol->supported = WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_ARP; |
| 3449 | wol->wolopts |= WAKE_MAGIC; |
| 3450 | /* |
| 3451 | if (vptr->wol_opts & VELOCITY_WOL_PHY) |
| 3452 | wol.wolopts|=WAKE_PHY; |
| 3453 | */ |
| 3454 | if (vptr->wol_opts & VELOCITY_WOL_UCAST) |
| 3455 | wol->wolopts |= WAKE_UCAST; |
| 3456 | if (vptr->wol_opts & VELOCITY_WOL_ARP) |
| 3457 | wol->wolopts |= WAKE_ARP; |
| 3458 | memcpy(&wol->sopass, vptr->wol_passwd, 6); |
| 3459 | } |
| 3460 | |
| 3461 | static int velocity_ethtool_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 3462 | { |
Jeff Garzik | 8ab6f3f | 2006-06-27 08:56:23 -0400 | [diff] [blame] | 3463 | struct velocity_info *vptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3464 | |
| 3465 | if (!(wol->wolopts & (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_ARP))) |
| 3466 | return -EFAULT; |
| 3467 | vptr->wol_opts = VELOCITY_WOL_MAGIC; |
| 3468 | |
| 3469 | /* |
| 3470 | if (wol.wolopts & WAKE_PHY) { |
| 3471 | vptr->wol_opts|=VELOCITY_WOL_PHY; |
| 3472 | vptr->flags |=VELOCITY_FLAGS_WOL_ENABLED; |
| 3473 | } |
| 3474 | */ |
| 3475 | |
| 3476 | if (wol->wolopts & WAKE_MAGIC) { |
| 3477 | vptr->wol_opts |= VELOCITY_WOL_MAGIC; |
| 3478 | vptr->flags |= VELOCITY_FLAGS_WOL_ENABLED; |
| 3479 | } |
| 3480 | if (wol->wolopts & WAKE_UCAST) { |
| 3481 | vptr->wol_opts |= VELOCITY_WOL_UCAST; |
| 3482 | vptr->flags |= VELOCITY_FLAGS_WOL_ENABLED; |
| 3483 | } |
| 3484 | if (wol->wolopts & WAKE_ARP) { |
| 3485 | vptr->wol_opts |= VELOCITY_WOL_ARP; |
| 3486 | vptr->flags |= VELOCITY_FLAGS_WOL_ENABLED; |
| 3487 | } |
| 3488 | memcpy(vptr->wol_passwd, wol->sopass, 6); |
| 3489 | return 0; |
| 3490 | } |
| 3491 | |
| 3492 | static u32 velocity_get_msglevel(struct net_device *dev) |
| 3493 | { |
| 3494 | return msglevel; |
| 3495 | } |
| 3496 | |
| 3497 | static void velocity_set_msglevel(struct net_device *dev, u32 value) |
| 3498 | { |
| 3499 | msglevel = value; |
| 3500 | } |
| 3501 | |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 3502 | static int get_pending_timer_val(int val) |
| 3503 | { |
| 3504 | int mult_bits = val >> 6; |
| 3505 | int mult = 1; |
| 3506 | |
| 3507 | switch (mult_bits) |
| 3508 | { |
| 3509 | case 1: |
| 3510 | mult = 4; break; |
| 3511 | case 2: |
| 3512 | mult = 16; break; |
| 3513 | case 3: |
| 3514 | mult = 64; break; |
| 3515 | case 0: |
| 3516 | default: |
| 3517 | break; |
| 3518 | } |
| 3519 | |
| 3520 | return (val & 0x3f) * mult; |
| 3521 | } |
| 3522 | |
| 3523 | static void set_pending_timer_val(int *val, u32 us) |
| 3524 | { |
| 3525 | u8 mult = 0; |
| 3526 | u8 shift = 0; |
| 3527 | |
| 3528 | if (us >= 0x3f) { |
| 3529 | mult = 1; /* mult with 4 */ |
| 3530 | shift = 2; |
| 3531 | } |
| 3532 | if (us >= 0x3f * 4) { |
| 3533 | mult = 2; /* mult with 16 */ |
| 3534 | shift = 4; |
| 3535 | } |
| 3536 | if (us >= 0x3f * 16) { |
| 3537 | mult = 3; /* mult with 64 */ |
| 3538 | shift = 6; |
| 3539 | } |
| 3540 | |
| 3541 | *val = (mult << 6) | ((us >> shift) & 0x3f); |
| 3542 | } |
| 3543 | |
| 3544 | |
| 3545 | static int velocity_get_coalesce(struct net_device *dev, |
| 3546 | struct ethtool_coalesce *ecmd) |
| 3547 | { |
| 3548 | struct velocity_info *vptr = netdev_priv(dev); |
| 3549 | |
| 3550 | ecmd->tx_max_coalesced_frames = vptr->options.tx_intsup; |
| 3551 | ecmd->rx_max_coalesced_frames = vptr->options.rx_intsup; |
| 3552 | |
| 3553 | ecmd->rx_coalesce_usecs = get_pending_timer_val(vptr->options.rxqueue_timer); |
| 3554 | ecmd->tx_coalesce_usecs = get_pending_timer_val(vptr->options.txqueue_timer); |
| 3555 | |
| 3556 | return 0; |
| 3557 | } |
| 3558 | |
| 3559 | static int velocity_set_coalesce(struct net_device *dev, |
| 3560 | struct ethtool_coalesce *ecmd) |
| 3561 | { |
| 3562 | struct velocity_info *vptr = netdev_priv(dev); |
| 3563 | int max_us = 0x3f * 64; |
Simon Kagstrom | 39c2ff4 | 2010-02-09 23:38:07 +0000 | [diff] [blame] | 3564 | unsigned long flags; |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 3565 | |
| 3566 | /* 6 bits of */ |
| 3567 | if (ecmd->tx_coalesce_usecs > max_us) |
| 3568 | return -EINVAL; |
| 3569 | if (ecmd->rx_coalesce_usecs > max_us) |
| 3570 | return -EINVAL; |
| 3571 | |
| 3572 | if (ecmd->tx_max_coalesced_frames > 0xff) |
| 3573 | return -EINVAL; |
| 3574 | if (ecmd->rx_max_coalesced_frames > 0xff) |
| 3575 | return -EINVAL; |
| 3576 | |
| 3577 | vptr->options.rx_intsup = ecmd->rx_max_coalesced_frames; |
| 3578 | vptr->options.tx_intsup = ecmd->tx_max_coalesced_frames; |
| 3579 | |
| 3580 | set_pending_timer_val(&vptr->options.rxqueue_timer, |
| 3581 | ecmd->rx_coalesce_usecs); |
| 3582 | set_pending_timer_val(&vptr->options.txqueue_timer, |
| 3583 | ecmd->tx_coalesce_usecs); |
| 3584 | |
| 3585 | /* Setup the interrupt suppression and queue timers */ |
Simon Kagstrom | 39c2ff4 | 2010-02-09 23:38:07 +0000 | [diff] [blame] | 3586 | spin_lock_irqsave(&vptr->lock, flags); |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 3587 | mac_disable_int(vptr->mac_regs); |
| 3588 | setup_adaptive_interrupts(vptr); |
| 3589 | setup_queue_timers(vptr); |
| 3590 | |
| 3591 | mac_write_int_mask(vptr->int_mask, vptr->mac_regs); |
| 3592 | mac_clear_isr(vptr->mac_regs); |
| 3593 | mac_enable_int(vptr->mac_regs); |
Simon Kagstrom | 39c2ff4 | 2010-02-09 23:38:07 +0000 | [diff] [blame] | 3594 | spin_unlock_irqrestore(&vptr->lock, flags); |
Simon Kagstrom | 6dfc4b9 | 2009-11-25 22:10:12 +0000 | [diff] [blame] | 3595 | |
| 3596 | return 0; |
| 3597 | } |
| 3598 | |
françois romieu | ad66fa7 | 2011-08-04 02:38:28 +0000 | [diff] [blame] | 3599 | static const char velocity_gstrings[][ETH_GSTRING_LEN] = { |
| 3600 | "rx_all", |
| 3601 | "rx_ok", |
| 3602 | "tx_ok", |
| 3603 | "rx_error", |
| 3604 | "rx_runt_ok", |
| 3605 | "rx_runt_err", |
| 3606 | "rx_64", |
| 3607 | "tx_64", |
| 3608 | "rx_65_to_127", |
| 3609 | "tx_65_to_127", |
| 3610 | "rx_128_to_255", |
| 3611 | "tx_128_to_255", |
| 3612 | "rx_256_to_511", |
| 3613 | "tx_256_to_511", |
| 3614 | "rx_512_to_1023", |
| 3615 | "tx_512_to_1023", |
| 3616 | "rx_1024_to_1518", |
| 3617 | "tx_1024_to_1518", |
| 3618 | "tx_ether_collisions", |
| 3619 | "rx_crc_errors", |
| 3620 | "rx_jumbo", |
| 3621 | "tx_jumbo", |
| 3622 | "rx_mac_control_frames", |
| 3623 | "tx_mac_control_frames", |
| 3624 | "rx_frame_alignement_errors", |
| 3625 | "rx_long_ok", |
| 3626 | "rx_long_err", |
| 3627 | "tx_sqe_errors", |
| 3628 | "rx_no_buf", |
| 3629 | "rx_symbol_errors", |
| 3630 | "in_range_length_errors", |
| 3631 | "late_collisions" |
| 3632 | }; |
| 3633 | |
| 3634 | static void velocity_get_strings(struct net_device *dev, u32 sset, u8 *data) |
| 3635 | { |
| 3636 | switch (sset) { |
| 3637 | case ETH_SS_STATS: |
| 3638 | memcpy(data, *velocity_gstrings, sizeof(velocity_gstrings)); |
| 3639 | break; |
| 3640 | } |
| 3641 | } |
| 3642 | |
| 3643 | static int velocity_get_sset_count(struct net_device *dev, int sset) |
| 3644 | { |
| 3645 | switch (sset) { |
| 3646 | case ETH_SS_STATS: |
| 3647 | return ARRAY_SIZE(velocity_gstrings); |
| 3648 | default: |
| 3649 | return -EOPNOTSUPP; |
| 3650 | } |
| 3651 | } |
| 3652 | |
| 3653 | static void velocity_get_ethtool_stats(struct net_device *dev, |
| 3654 | struct ethtool_stats *stats, u64 *data) |
| 3655 | { |
| 3656 | if (netif_running(dev)) { |
| 3657 | struct velocity_info *vptr = netdev_priv(dev); |
| 3658 | u32 *p = vptr->mib_counter; |
| 3659 | int i; |
| 3660 | |
| 3661 | spin_lock_irq(&vptr->lock); |
| 3662 | velocity_update_hw_mibs(vptr); |
| 3663 | spin_unlock_irq(&vptr->lock); |
| 3664 | |
| 3665 | for (i = 0; i < ARRAY_SIZE(velocity_gstrings); i++) |
| 3666 | *data++ = *p++; |
| 3667 | } |
| 3668 | } |
| 3669 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 3670 | static const struct ethtool_ops velocity_ethtool_ops = { |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3671 | .get_settings = velocity_get_settings, |
| 3672 | .set_settings = velocity_set_settings, |
| 3673 | .get_drvinfo = velocity_get_drvinfo, |
| 3674 | .get_wol = velocity_ethtool_get_wol, |
| 3675 | .set_wol = velocity_ethtool_set_wol, |
| 3676 | .get_msglevel = velocity_get_msglevel, |
| 3677 | .set_msglevel = velocity_set_msglevel, |
| 3678 | .get_link = velocity_get_link, |
françois romieu | ad66fa7 | 2011-08-04 02:38:28 +0000 | [diff] [blame] | 3679 | .get_strings = velocity_get_strings, |
| 3680 | .get_sset_count = velocity_get_sset_count, |
| 3681 | .get_ethtool_stats = velocity_get_ethtool_stats, |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3682 | .get_coalesce = velocity_get_coalesce, |
| 3683 | .set_coalesce = velocity_set_coalesce, |
| 3684 | .begin = velocity_ethtool_up, |
| 3685 | .complete = velocity_ethtool_down |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | }; |
| 3687 | |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3688 | #if defined(CONFIG_PM) && defined(CONFIG_INET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | static int velocity_netdev_event(struct notifier_block *nb, unsigned long notification, void *ptr) |
| 3690 | { |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3691 | struct in_ifaddr *ifa = ptr; |
Denis V. Lunev | a337499f | 2008-02-28 20:44:27 -0800 | [diff] [blame] | 3692 | struct net_device *dev = ifa->ifa_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | |
Ben Hutchings | 516b4df | 2009-10-28 04:01:46 -0700 | [diff] [blame] | 3694 | if (dev_net(dev) == &init_net && |
| 3695 | dev->netdev_ops == &velocity_netdev_ops) |
| 3696 | velocity_get_ip(netdev_priv(dev)); |
Denis V. Lunev | a337499f | 2008-02-28 20:44:27 -0800 | [diff] [blame] | 3697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3698 | return NOTIFY_DONE; |
| 3699 | } |
Randy Dunlap | ce9f7fe | 2006-12-18 21:21:10 -0800 | [diff] [blame] | 3700 | |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3701 | static struct notifier_block velocity_inetaddr_notifier = { |
françois romieu | 5ae297b | 2011-08-04 02:39:03 +0000 | [diff] [blame] | 3702 | .notifier_call = velocity_netdev_event, |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3703 | }; |
| 3704 | |
| 3705 | static void velocity_register_notifier(void) |
| 3706 | { |
| 3707 | register_inetaddr_notifier(&velocity_inetaddr_notifier); |
| 3708 | } |
| 3709 | |
| 3710 | static void velocity_unregister_notifier(void) |
| 3711 | { |
| 3712 | unregister_inetaddr_notifier(&velocity_inetaddr_notifier); |
| 3713 | } |
| 3714 | |
| 3715 | #else |
| 3716 | |
| 3717 | #define velocity_register_notifier() do {} while (0) |
| 3718 | #define velocity_unregister_notifier() do {} while (0) |
| 3719 | |
| 3720 | #endif /* defined(CONFIG_PM) && defined(CONFIG_INET) */ |
| 3721 | |
| 3722 | /** |
| 3723 | * velocity_init_module - load time function |
| 3724 | * |
| 3725 | * Called when the velocity module is loaded. The PCI driver |
| 3726 | * is registered with the PCI layer, and in turn will call |
| 3727 | * the probe functions for each velocity adapter installed |
| 3728 | * in the system. |
| 3729 | */ |
| 3730 | static int __init velocity_init_module(void) |
| 3731 | { |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3732 | int ret_pci, ret_platform; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3733 | |
| 3734 | velocity_register_notifier(); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3735 | |
| 3736 | ret_pci = pci_register_driver(&velocity_pci_driver); |
| 3737 | ret_platform = platform_driver_register(&velocity_platform_driver); |
| 3738 | |
| 3739 | /* if both_registers failed, remove the notifier */ |
| 3740 | if ((ret_pci < 0) && (ret_platform < 0)) { |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3741 | velocity_unregister_notifier(); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3742 | return ret_pci; |
| 3743 | } |
| 3744 | |
| 3745 | return 0; |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3746 | } |
| 3747 | |
| 3748 | /** |
| 3749 | * velocity_cleanup - module unload |
| 3750 | * |
| 3751 | * When the velocity hardware is unloaded this function is called. |
| 3752 | * It will clean up the notifiers and the unregister the PCI |
| 3753 | * driver interface for this hardware. This in turn cleans up |
| 3754 | * all discovered interfaces before returning from the function |
| 3755 | */ |
| 3756 | static void __exit velocity_cleanup_module(void) |
| 3757 | { |
| 3758 | velocity_unregister_notifier(); |
Tony Prisk | 6dffbe5 | 2013-05-18 09:39:07 +0000 | [diff] [blame] | 3759 | |
| 3760 | pci_unregister_driver(&velocity_pci_driver); |
| 3761 | platform_driver_unregister(&velocity_platform_driver); |
Dave Jones | 2cf71d2 | 2009-07-23 18:11:12 -0700 | [diff] [blame] | 3762 | } |
| 3763 | |
| 3764 | module_init(velocity_init_module); |
| 3765 | module_exit(velocity_cleanup_module); |