Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved. |
| 3 | * Copyright(c) 2006 Chris Snook <csnook@redhat.com> |
| 4 | * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com> |
| 5 | * |
| 6 | * Derived from Intel e1000 driver |
| 7 | * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the Free |
| 11 | * Software Foundation; either version 2 of the License, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along with |
| 20 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 21 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | * |
| 23 | * The full GNU General Public License is included in this distribution in the |
| 24 | * file called COPYING. |
| 25 | * |
| 26 | * Contact Information: |
| 27 | * Xiong Huang <xiong_huang@attansic.com> |
| 28 | * Attansic Technology Corp. 3F 147, Xianzheng 9th Road, Zhubei, |
| 29 | * Xinzhu 302, TAIWAN, REPUBLIC OF CHINA |
| 30 | * |
| 31 | * Chris Snook <csnook@redhat.com> |
| 32 | * Jay Cliburn <jcliburn@gmail.com> |
| 33 | * |
| 34 | * This version is adapted from the Attansic reference driver for |
| 35 | * inclusion in the Linux kernel. It is currently under heavy development. |
| 36 | * A very incomplete list of things that need to be dealt with: |
| 37 | * |
| 38 | * TODO: |
| 39 | * Fix TSO; tx performance is horrible with TSO enabled. |
| 40 | * Wake on LAN. |
| 41 | * Add more ethtool functions, including set ring parameters. |
| 42 | * Fix abstruse irq enable/disable condition described here: |
| 43 | * http://marc.theaimsgroup.com/?l=linux-netdev&m=116398508500553&w=2 |
| 44 | * |
| 45 | * NEEDS TESTING: |
| 46 | * VLAN |
| 47 | * multicast |
| 48 | * promiscuous mode |
| 49 | * interrupt coalescing |
| 50 | * SMP torture testing |
| 51 | */ |
| 52 | |
| 53 | #include <linux/types.h> |
| 54 | #include <linux/netdevice.h> |
| 55 | #include <linux/pci.h> |
| 56 | #include <linux/spinlock.h> |
| 57 | #include <linux/slab.h> |
| 58 | #include <linux/string.h> |
| 59 | #include <linux/skbuff.h> |
| 60 | #include <linux/etherdevice.h> |
| 61 | #include <linux/if_vlan.h> |
| 62 | #include <linux/irqreturn.h> |
| 63 | #include <linux/workqueue.h> |
| 64 | #include <linux/timer.h> |
| 65 | #include <linux/jiffies.h> |
| 66 | #include <linux/hardirq.h> |
| 67 | #include <linux/interrupt.h> |
| 68 | #include <linux/irqflags.h> |
| 69 | #include <linux/dma-mapping.h> |
| 70 | #include <linux/net.h> |
| 71 | #include <linux/pm.h> |
| 72 | #include <linux/in.h> |
| 73 | #include <linux/ip.h> |
| 74 | #include <linux/tcp.h> |
| 75 | #include <linux/compiler.h> |
| 76 | #include <linux/delay.h> |
| 77 | #include <linux/mii.h> |
| 78 | #include <net/checksum.h> |
| 79 | |
| 80 | #include <asm/atomic.h> |
| 81 | #include <asm/byteorder.h> |
| 82 | |
| 83 | #include "atl1.h" |
| 84 | |
Jay Cliburn | 9cc6d14 | 2007-02-14 20:18:05 -0600 | [diff] [blame] | 85 | #define DRIVER_VERSION "2.0.7" |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 86 | |
| 87 | char atl1_driver_name[] = "atl1"; |
| 88 | static const char atl1_driver_string[] = "Attansic L1 Ethernet Network Driver"; |
| 89 | static const char atl1_copyright[] = "Copyright(c) 2005-2006 Attansic Corporation."; |
| 90 | char atl1_driver_version[] = DRIVER_VERSION; |
| 91 | |
| 92 | MODULE_AUTHOR |
| 93 | ("Attansic Corporation <xiong_huang@attansic.com>, Chris Snook <csnook@redhat.com>, Jay Cliburn <jcliburn@gmail.com>"); |
| 94 | MODULE_DESCRIPTION("Attansic 1000M Ethernet Network Driver"); |
| 95 | MODULE_LICENSE("GPL"); |
| 96 | MODULE_VERSION(DRIVER_VERSION); |
| 97 | |
| 98 | /* |
| 99 | * atl1_pci_tbl - PCI Device ID Table |
| 100 | */ |
| 101 | static const struct pci_device_id atl1_pci_tbl[] = { |
Chris Snook | e81e557 | 2007-02-14 20:17:01 -0600 | [diff] [blame] | 102 | {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1)}, |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 103 | /* required last entry */ |
| 104 | {0,} |
| 105 | }; |
| 106 | |
| 107 | MODULE_DEVICE_TABLE(pci, atl1_pci_tbl); |
| 108 | |
| 109 | /* |
| 110 | * atl1_sw_init - Initialize general software structures (struct atl1_adapter) |
| 111 | * @adapter: board private structure to initialize |
| 112 | * |
| 113 | * atl1_sw_init initializes the Adapter private data structure. |
| 114 | * Fields are initialized based on PCI device information and |
| 115 | * OS network device settings (MTU size). |
| 116 | */ |
| 117 | static int __devinit atl1_sw_init(struct atl1_adapter *adapter) |
| 118 | { |
| 119 | struct atl1_hw *hw = &adapter->hw; |
| 120 | struct net_device *netdev = adapter->netdev; |
| 121 | struct pci_dev *pdev = adapter->pdev; |
| 122 | |
| 123 | /* PCI config space info */ |
| 124 | pci_read_config_byte(pdev, PCI_REVISION_ID, &hw->revision_id); |
| 125 | |
| 126 | hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 127 | hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE; |
| 128 | |
| 129 | adapter->wol = 0; |
| 130 | adapter->rx_buffer_len = (hw->max_frame_size + 7) & ~7; |
| 131 | adapter->ict = 50000; /* 100ms */ |
| 132 | adapter->link_speed = SPEED_0; /* hardware init */ |
| 133 | adapter->link_duplex = FULL_DUPLEX; |
| 134 | |
| 135 | hw->phy_configured = false; |
| 136 | hw->preamble_len = 7; |
| 137 | hw->ipgt = 0x60; |
| 138 | hw->min_ifg = 0x50; |
| 139 | hw->ipgr1 = 0x40; |
| 140 | hw->ipgr2 = 0x60; |
| 141 | hw->max_retry = 0xf; |
| 142 | hw->lcol = 0x37; |
| 143 | hw->jam_ipg = 7; |
| 144 | hw->rfd_burst = 8; |
| 145 | hw->rrd_burst = 8; |
| 146 | hw->rfd_fetch_gap = 1; |
| 147 | hw->rx_jumbo_th = adapter->rx_buffer_len / 8; |
| 148 | hw->rx_jumbo_lkah = 1; |
| 149 | hw->rrd_ret_timer = 16; |
| 150 | hw->tpd_burst = 4; |
| 151 | hw->tpd_fetch_th = 16; |
| 152 | hw->txf_burst = 0x100; |
| 153 | hw->tx_jumbo_task_th = (hw->max_frame_size + 7) >> 3; |
| 154 | hw->tpd_fetch_gap = 1; |
| 155 | hw->rcb_value = atl1_rcb_64; |
| 156 | hw->dma_ord = atl1_dma_ord_enh; |
| 157 | hw->dmar_block = atl1_dma_req_256; |
| 158 | hw->dmaw_block = atl1_dma_req_256; |
| 159 | hw->cmb_rrd = 4; |
| 160 | hw->cmb_tpd = 4; |
| 161 | hw->cmb_rx_timer = 1; /* about 2us */ |
| 162 | hw->cmb_tx_timer = 1; /* about 2us */ |
| 163 | hw->smb_timer = 100000; /* about 200ms */ |
| 164 | |
| 165 | atomic_set(&adapter->irq_sem, 0); |
| 166 | spin_lock_init(&adapter->lock); |
| 167 | spin_lock_init(&adapter->mb_lock); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | * atl1_setup_mem_resources - allocate Tx / RX descriptor resources |
| 174 | * @adapter: board private structure |
| 175 | * |
| 176 | * Return 0 on success, negative on failure |
| 177 | */ |
| 178 | s32 atl1_setup_ring_resources(struct atl1_adapter *adapter) |
| 179 | { |
| 180 | struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; |
| 181 | struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 182 | struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring; |
| 183 | struct atl1_ring_header *ring_header = &adapter->ring_header; |
| 184 | struct pci_dev *pdev = adapter->pdev; |
| 185 | int size; |
| 186 | u8 offset = 0; |
| 187 | |
| 188 | size = sizeof(struct atl1_buffer) * (tpd_ring->count + rfd_ring->count); |
| 189 | tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL); |
| 190 | if (unlikely(!tpd_ring->buffer_info)) { |
| 191 | printk(KERN_WARNING "%s: kzalloc failed , size = D%d\n", |
| 192 | atl1_driver_name, size); |
| 193 | goto err_nomem; |
| 194 | } |
| 195 | rfd_ring->buffer_info = |
| 196 | (struct atl1_buffer *)(tpd_ring->buffer_info + tpd_ring->count); |
| 197 | |
| 198 | /* real ring DMA buffer */ |
| 199 | ring_header->size = size = sizeof(struct tx_packet_desc) * |
| 200 | tpd_ring->count |
| 201 | + sizeof(struct rx_free_desc) * rfd_ring->count |
| 202 | + sizeof(struct rx_return_desc) * rrd_ring->count |
| 203 | + sizeof(struct coals_msg_block) |
| 204 | + sizeof(struct stats_msg_block) |
| 205 | + 40; /* "40: for 8 bytes align" huh? -- CHS */ |
| 206 | |
| 207 | ring_header->desc = pci_alloc_consistent(pdev, ring_header->size, |
| 208 | &ring_header->dma); |
| 209 | if (unlikely(!ring_header->desc)) { |
| 210 | printk(KERN_WARNING |
| 211 | "%s: pci_alloc_consistent failed, size = D%d\n", |
| 212 | atl1_driver_name, size); |
| 213 | goto err_nomem; |
| 214 | } |
| 215 | |
| 216 | memset(ring_header->desc, 0, ring_header->size); |
| 217 | |
| 218 | /* init TPD ring */ |
| 219 | tpd_ring->dma = ring_header->dma; |
| 220 | offset = (tpd_ring->dma & 0x7) ? (8 - (ring_header->dma & 0x7)) : 0; |
| 221 | tpd_ring->dma += offset; |
| 222 | tpd_ring->desc = (u8 *) ring_header->desc + offset; |
| 223 | tpd_ring->size = sizeof(struct tx_packet_desc) * tpd_ring->count; |
| 224 | atomic_set(&tpd_ring->next_to_use, 0); |
| 225 | atomic_set(&tpd_ring->next_to_clean, 0); |
| 226 | |
| 227 | /* init RFD ring */ |
| 228 | rfd_ring->dma = tpd_ring->dma + tpd_ring->size; |
| 229 | offset = (rfd_ring->dma & 0x7) ? (8 - (rfd_ring->dma & 0x7)) : 0; |
| 230 | rfd_ring->dma += offset; |
| 231 | rfd_ring->desc = (u8 *) tpd_ring->desc + (tpd_ring->size + offset); |
| 232 | rfd_ring->size = sizeof(struct rx_free_desc) * rfd_ring->count; |
| 233 | rfd_ring->next_to_clean = 0; |
| 234 | /* rfd_ring->next_to_use = rfd_ring->count - 1; */ |
| 235 | atomic_set(&rfd_ring->next_to_use, 0); |
| 236 | |
| 237 | /* init RRD ring */ |
| 238 | rrd_ring->dma = rfd_ring->dma + rfd_ring->size; |
| 239 | offset = (rrd_ring->dma & 0x7) ? (8 - (rrd_ring->dma & 0x7)) : 0; |
| 240 | rrd_ring->dma += offset; |
| 241 | rrd_ring->desc = (u8 *) rfd_ring->desc + (rfd_ring->size + offset); |
| 242 | rrd_ring->size = sizeof(struct rx_return_desc) * rrd_ring->count; |
| 243 | rrd_ring->next_to_use = 0; |
| 244 | atomic_set(&rrd_ring->next_to_clean, 0); |
| 245 | |
| 246 | /* init CMB */ |
| 247 | adapter->cmb.dma = rrd_ring->dma + rrd_ring->size; |
| 248 | offset = (adapter->cmb.dma & 0x7) ? (8 - (adapter->cmb.dma & 0x7)) : 0; |
| 249 | adapter->cmb.dma += offset; |
| 250 | adapter->cmb.cmb = |
| 251 | (struct coals_msg_block *) ((u8 *) rrd_ring->desc + |
| 252 | (rrd_ring->size + offset)); |
| 253 | |
| 254 | /* init SMB */ |
| 255 | adapter->smb.dma = adapter->cmb.dma + sizeof(struct coals_msg_block); |
| 256 | offset = (adapter->smb.dma & 0x7) ? (8 - (adapter->smb.dma & 0x7)) : 0; |
| 257 | adapter->smb.dma += offset; |
| 258 | adapter->smb.smb = (struct stats_msg_block *) |
| 259 | ((u8 *) adapter->cmb.cmb + (sizeof(struct coals_msg_block) + offset)); |
| 260 | |
| 261 | return ATL1_SUCCESS; |
| 262 | |
| 263 | err_nomem: |
| 264 | kfree(tpd_ring->buffer_info); |
| 265 | return -ENOMEM; |
| 266 | } |
| 267 | |
| 268 | /* |
| 269 | * atl1_irq_enable - Enable default interrupt generation settings |
| 270 | * @adapter: board private structure |
| 271 | */ |
| 272 | static void atl1_irq_enable(struct atl1_adapter *adapter) |
| 273 | { |
| 274 | if (likely(!atomic_dec_and_test(&adapter->irq_sem))) |
| 275 | iowrite32(IMR_NORMAL_MASK, adapter->hw.hw_addr + REG_IMR); |
| 276 | } |
| 277 | |
| 278 | static void atl1_clear_phy_int(struct atl1_adapter *adapter) |
| 279 | { |
| 280 | u16 phy_data; |
| 281 | unsigned long flags; |
| 282 | |
| 283 | spin_lock_irqsave(&adapter->lock, flags); |
| 284 | atl1_read_phy_reg(&adapter->hw, 19, &phy_data); |
| 285 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 286 | } |
| 287 | |
| 288 | static void atl1_inc_smb(struct atl1_adapter *adapter) |
| 289 | { |
| 290 | struct stats_msg_block *smb = adapter->smb.smb; |
| 291 | |
| 292 | /* Fill out the OS statistics structure */ |
| 293 | adapter->soft_stats.rx_packets += smb->rx_ok; |
| 294 | adapter->soft_stats.tx_packets += smb->tx_ok; |
| 295 | adapter->soft_stats.rx_bytes += smb->rx_byte_cnt; |
| 296 | adapter->soft_stats.tx_bytes += smb->tx_byte_cnt; |
| 297 | adapter->soft_stats.multicast += smb->rx_mcast; |
| 298 | adapter->soft_stats.collisions += (smb->tx_1_col + |
| 299 | smb->tx_2_col * 2 + |
| 300 | smb->tx_late_col + |
| 301 | smb->tx_abort_col * |
| 302 | adapter->hw.max_retry); |
| 303 | |
| 304 | /* Rx Errors */ |
| 305 | adapter->soft_stats.rx_errors += (smb->rx_frag + |
| 306 | smb->rx_fcs_err + |
| 307 | smb->rx_len_err + |
| 308 | smb->rx_sz_ov + |
| 309 | smb->rx_rxf_ov + |
| 310 | smb->rx_rrd_ov + smb->rx_align_err); |
| 311 | adapter->soft_stats.rx_fifo_errors += smb->rx_rxf_ov; |
| 312 | adapter->soft_stats.rx_length_errors += smb->rx_len_err; |
| 313 | adapter->soft_stats.rx_crc_errors += smb->rx_fcs_err; |
| 314 | adapter->soft_stats.rx_frame_errors += smb->rx_align_err; |
| 315 | adapter->soft_stats.rx_missed_errors += (smb->rx_rrd_ov + |
| 316 | smb->rx_rxf_ov); |
| 317 | |
| 318 | adapter->soft_stats.rx_pause += smb->rx_pause; |
| 319 | adapter->soft_stats.rx_rrd_ov += smb->rx_rrd_ov; |
| 320 | adapter->soft_stats.rx_trunc += smb->rx_sz_ov; |
| 321 | |
| 322 | /* Tx Errors */ |
| 323 | adapter->soft_stats.tx_errors += (smb->tx_late_col + |
| 324 | smb->tx_abort_col + |
| 325 | smb->tx_underrun + smb->tx_trunc); |
| 326 | adapter->soft_stats.tx_fifo_errors += smb->tx_underrun; |
| 327 | adapter->soft_stats.tx_aborted_errors += smb->tx_abort_col; |
| 328 | adapter->soft_stats.tx_window_errors += smb->tx_late_col; |
| 329 | |
| 330 | adapter->soft_stats.excecol += smb->tx_abort_col; |
| 331 | adapter->soft_stats.deffer += smb->tx_defer; |
| 332 | adapter->soft_stats.scc += smb->tx_1_col; |
| 333 | adapter->soft_stats.mcc += smb->tx_2_col; |
| 334 | adapter->soft_stats.latecol += smb->tx_late_col; |
| 335 | adapter->soft_stats.tx_underun += smb->tx_underrun; |
| 336 | adapter->soft_stats.tx_trunc += smb->tx_trunc; |
| 337 | adapter->soft_stats.tx_pause += smb->tx_pause; |
| 338 | |
| 339 | adapter->net_stats.rx_packets = adapter->soft_stats.rx_packets; |
| 340 | adapter->net_stats.tx_packets = adapter->soft_stats.tx_packets; |
| 341 | adapter->net_stats.rx_bytes = adapter->soft_stats.rx_bytes; |
| 342 | adapter->net_stats.tx_bytes = adapter->soft_stats.tx_bytes; |
| 343 | adapter->net_stats.multicast = adapter->soft_stats.multicast; |
| 344 | adapter->net_stats.collisions = adapter->soft_stats.collisions; |
| 345 | adapter->net_stats.rx_errors = adapter->soft_stats.rx_errors; |
| 346 | adapter->net_stats.rx_over_errors = |
| 347 | adapter->soft_stats.rx_missed_errors; |
| 348 | adapter->net_stats.rx_length_errors = |
| 349 | adapter->soft_stats.rx_length_errors; |
| 350 | adapter->net_stats.rx_crc_errors = adapter->soft_stats.rx_crc_errors; |
| 351 | adapter->net_stats.rx_frame_errors = |
| 352 | adapter->soft_stats.rx_frame_errors; |
| 353 | adapter->net_stats.rx_fifo_errors = adapter->soft_stats.rx_fifo_errors; |
| 354 | adapter->net_stats.rx_missed_errors = |
| 355 | adapter->soft_stats.rx_missed_errors; |
| 356 | adapter->net_stats.tx_errors = adapter->soft_stats.tx_errors; |
| 357 | adapter->net_stats.tx_fifo_errors = adapter->soft_stats.tx_fifo_errors; |
| 358 | adapter->net_stats.tx_aborted_errors = |
| 359 | adapter->soft_stats.tx_aborted_errors; |
| 360 | adapter->net_stats.tx_window_errors = |
| 361 | adapter->soft_stats.tx_window_errors; |
| 362 | adapter->net_stats.tx_carrier_errors = |
| 363 | adapter->soft_stats.tx_carrier_errors; |
| 364 | } |
| 365 | |
| 366 | static void atl1_rx_checksum(struct atl1_adapter *adapter, |
| 367 | struct rx_return_desc *rrd, |
| 368 | struct sk_buff *skb) |
| 369 | { |
| 370 | skb->ip_summed = CHECKSUM_NONE; |
| 371 | |
| 372 | if (unlikely(rrd->pkt_flg & PACKET_FLAG_ERR)) { |
| 373 | if (rrd->err_flg & (ERR_FLAG_CRC | ERR_FLAG_TRUNC | |
| 374 | ERR_FLAG_CODE | ERR_FLAG_OV)) { |
| 375 | adapter->hw_csum_err++; |
| 376 | printk(KERN_DEBUG "%s: rx checksum error\n", |
| 377 | atl1_driver_name); |
| 378 | return; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /* not IPv4 */ |
| 383 | if (!(rrd->pkt_flg & PACKET_FLAG_IPV4)) |
| 384 | /* checksum is invalid, but it's not an IPv4 pkt, so ok */ |
| 385 | return; |
| 386 | |
| 387 | /* IPv4 packet */ |
| 388 | if (likely(!(rrd->err_flg & |
| 389 | (ERR_FLAG_IP_CHKSUM | ERR_FLAG_L4_CHKSUM)))) { |
| 390 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 391 | adapter->hw_csum_good++; |
| 392 | return; |
| 393 | } |
| 394 | |
| 395 | /* IPv4, but hardware thinks its checksum is wrong */ |
| 396 | printk(KERN_DEBUG "%s: hw csum wrong pkt_flag:%x, err_flag:%x\n", |
| 397 | atl1_driver_name, rrd->pkt_flg, rrd->err_flg); |
| 398 | skb->ip_summed = CHECKSUM_COMPLETE; |
| 399 | skb->csum = htons(rrd->xsz.xsum_sz.rx_chksum); |
| 400 | adapter->hw_csum_err++; |
| 401 | return; |
| 402 | } |
| 403 | |
| 404 | /* |
| 405 | * atl1_alloc_rx_buffers - Replace used receive buffers |
| 406 | * @adapter: address of board private structure |
| 407 | */ |
| 408 | static u16 atl1_alloc_rx_buffers(struct atl1_adapter *adapter) |
| 409 | { |
| 410 | struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring; |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 411 | struct pci_dev *pdev = adapter->pdev; |
| 412 | struct page *page; |
| 413 | unsigned long offset; |
| 414 | struct atl1_buffer *buffer_info, *next_info; |
| 415 | struct sk_buff *skb; |
| 416 | u16 num_alloc = 0; |
| 417 | u16 rfd_next_to_use, next_next; |
| 418 | struct rx_free_desc *rfd_desc; |
| 419 | |
| 420 | next_next = rfd_next_to_use = atomic_read(&rfd_ring->next_to_use); |
| 421 | if (++next_next == rfd_ring->count) |
| 422 | next_next = 0; |
| 423 | buffer_info = &rfd_ring->buffer_info[rfd_next_to_use]; |
| 424 | next_info = &rfd_ring->buffer_info[next_next]; |
| 425 | |
| 426 | while (!buffer_info->alloced && !next_info->alloced) { |
| 427 | if (buffer_info->skb) { |
| 428 | buffer_info->alloced = 1; |
| 429 | goto next; |
| 430 | } |
| 431 | |
| 432 | rfd_desc = ATL1_RFD_DESC(rfd_ring, rfd_next_to_use); |
| 433 | |
| 434 | skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN); |
| 435 | if (unlikely(!skb)) { /* Better luck next round */ |
| 436 | adapter->net_stats.rx_dropped++; |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | /* |
| 441 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 442 | * this will result in a 16 byte aligned IP header after |
| 443 | * the 14 byte MAC header is removed |
| 444 | */ |
| 445 | skb_reserve(skb, NET_IP_ALIGN); |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 446 | |
| 447 | buffer_info->alloced = 1; |
| 448 | buffer_info->skb = skb; |
| 449 | buffer_info->length = (u16) adapter->rx_buffer_len; |
| 450 | page = virt_to_page(skb->data); |
| 451 | offset = (unsigned long)skb->data & ~PAGE_MASK; |
| 452 | buffer_info->dma = pci_map_page(pdev, page, offset, |
| 453 | adapter->rx_buffer_len, |
| 454 | PCI_DMA_FROMDEVICE); |
| 455 | rfd_desc->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 456 | rfd_desc->buf_len = cpu_to_le16(adapter->rx_buffer_len); |
| 457 | rfd_desc->coalese = 0; |
| 458 | |
| 459 | next: |
| 460 | rfd_next_to_use = next_next; |
| 461 | if (unlikely(++next_next == rfd_ring->count)) |
| 462 | next_next = 0; |
| 463 | |
| 464 | buffer_info = &rfd_ring->buffer_info[rfd_next_to_use]; |
| 465 | next_info = &rfd_ring->buffer_info[next_next]; |
| 466 | num_alloc++; |
| 467 | } |
| 468 | |
| 469 | if (num_alloc) { |
| 470 | /* |
| 471 | * Force memory writes to complete before letting h/w |
| 472 | * know there are new descriptors to fetch. (Only |
| 473 | * applicable for weak-ordered memory model archs, |
| 474 | * such as IA-64). |
| 475 | */ |
| 476 | wmb(); |
| 477 | atomic_set(&rfd_ring->next_to_use, (int)rfd_next_to_use); |
| 478 | } |
| 479 | return num_alloc; |
| 480 | } |
| 481 | |
| 482 | static void atl1_intr_rx(struct atl1_adapter *adapter) |
| 483 | { |
| 484 | int i, count; |
| 485 | u16 length; |
| 486 | u16 rrd_next_to_clean; |
| 487 | u32 value; |
| 488 | struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 489 | struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring; |
| 490 | struct atl1_buffer *buffer_info; |
| 491 | struct rx_return_desc *rrd; |
| 492 | struct sk_buff *skb; |
| 493 | |
| 494 | count = 0; |
| 495 | |
| 496 | rrd_next_to_clean = atomic_read(&rrd_ring->next_to_clean); |
| 497 | |
| 498 | while (1) { |
| 499 | rrd = ATL1_RRD_DESC(rrd_ring, rrd_next_to_clean); |
| 500 | i = 1; |
| 501 | if (likely(rrd->xsz.valid)) { /* packet valid */ |
| 502 | chk_rrd: |
| 503 | /* check rrd status */ |
| 504 | if (likely(rrd->num_buf == 1)) |
| 505 | goto rrd_ok; |
| 506 | |
| 507 | /* rrd seems to be bad */ |
| 508 | if (unlikely(i-- > 0)) { |
| 509 | /* rrd may not be DMAed completely */ |
| 510 | printk(KERN_DEBUG |
| 511 | "%s: RRD may not be DMAed completely\n", |
| 512 | atl1_driver_name); |
| 513 | udelay(1); |
| 514 | goto chk_rrd; |
| 515 | } |
| 516 | /* bad rrd */ |
| 517 | printk(KERN_DEBUG "%s: bad RRD\n", atl1_driver_name); |
| 518 | /* see if update RFD index */ |
| 519 | if (rrd->num_buf > 1) { |
| 520 | u16 num_buf; |
| 521 | num_buf = |
| 522 | (rrd->xsz.xsum_sz.pkt_size + |
| 523 | adapter->rx_buffer_len - |
| 524 | 1) / adapter->rx_buffer_len; |
| 525 | if (rrd->num_buf == num_buf) { |
| 526 | /* clean alloc flag for bad rrd */ |
| 527 | while (rfd_ring->next_to_clean != |
| 528 | (rrd->buf_indx + num_buf)) { |
| 529 | rfd_ring->buffer_info[rfd_ring-> |
| 530 | next_to_clean].alloced = 0; |
| 531 | if (++rfd_ring->next_to_clean == |
| 532 | rfd_ring->count) { |
| 533 | rfd_ring-> |
| 534 | next_to_clean = 0; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | } |
| 539 | |
| 540 | /* update rrd */ |
| 541 | rrd->xsz.valid = 0; |
| 542 | if (++rrd_next_to_clean == rrd_ring->count) |
| 543 | rrd_next_to_clean = 0; |
| 544 | count++; |
| 545 | continue; |
| 546 | } else { /* current rrd still not be updated */ |
| 547 | |
| 548 | break; |
| 549 | } |
| 550 | rrd_ok: |
| 551 | /* clean alloc flag for bad rrd */ |
| 552 | while (rfd_ring->next_to_clean != rrd->buf_indx) { |
| 553 | rfd_ring->buffer_info[rfd_ring->next_to_clean].alloced = |
| 554 | 0; |
| 555 | if (++rfd_ring->next_to_clean == rfd_ring->count) |
| 556 | rfd_ring->next_to_clean = 0; |
| 557 | } |
| 558 | |
| 559 | buffer_info = &rfd_ring->buffer_info[rrd->buf_indx]; |
| 560 | if (++rfd_ring->next_to_clean == rfd_ring->count) |
| 561 | rfd_ring->next_to_clean = 0; |
| 562 | |
| 563 | /* update rrd next to clean */ |
| 564 | if (++rrd_next_to_clean == rrd_ring->count) |
| 565 | rrd_next_to_clean = 0; |
| 566 | count++; |
| 567 | |
| 568 | if (unlikely(rrd->pkt_flg & PACKET_FLAG_ERR)) { |
| 569 | if (!(rrd->err_flg & |
| 570 | (ERR_FLAG_IP_CHKSUM | ERR_FLAG_L4_CHKSUM |
| 571 | | ERR_FLAG_LEN))) { |
| 572 | /* packet error, don't need upstream */ |
| 573 | buffer_info->alloced = 0; |
| 574 | rrd->xsz.valid = 0; |
| 575 | continue; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /* Good Receive */ |
| 580 | pci_unmap_page(adapter->pdev, buffer_info->dma, |
| 581 | buffer_info->length, PCI_DMA_FROMDEVICE); |
| 582 | skb = buffer_info->skb; |
| 583 | length = le16_to_cpu(rrd->xsz.xsum_sz.pkt_size); |
| 584 | |
| 585 | skb_put(skb, length - ETHERNET_FCS_SIZE); |
| 586 | |
| 587 | /* Receive Checksum Offload */ |
| 588 | atl1_rx_checksum(adapter, rrd, skb); |
| 589 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
| 590 | |
| 591 | if (adapter->vlgrp && (rrd->pkt_flg & PACKET_FLAG_VLAN_INS)) { |
| 592 | u16 vlan_tag = (rrd->vlan_tag >> 4) | |
| 593 | ((rrd->vlan_tag & 7) << 13) | |
| 594 | ((rrd->vlan_tag & 8) << 9); |
| 595 | vlan_hwaccel_rx(skb, adapter->vlgrp, vlan_tag); |
| 596 | } else |
| 597 | netif_rx(skb); |
| 598 | |
| 599 | /* let protocol layer free skb */ |
| 600 | buffer_info->skb = NULL; |
| 601 | buffer_info->alloced = 0; |
| 602 | rrd->xsz.valid = 0; |
| 603 | |
| 604 | adapter->netdev->last_rx = jiffies; |
| 605 | } |
| 606 | |
| 607 | atomic_set(&rrd_ring->next_to_clean, rrd_next_to_clean); |
| 608 | |
| 609 | atl1_alloc_rx_buffers(adapter); |
| 610 | |
| 611 | /* update mailbox ? */ |
| 612 | if (count) { |
| 613 | u32 tpd_next_to_use; |
| 614 | u32 rfd_next_to_use; |
| 615 | u32 rrd_next_to_clean; |
| 616 | |
| 617 | spin_lock(&adapter->mb_lock); |
| 618 | |
| 619 | tpd_next_to_use = atomic_read(&adapter->tpd_ring.next_to_use); |
| 620 | rfd_next_to_use = |
| 621 | atomic_read(&adapter->rfd_ring.next_to_use); |
| 622 | rrd_next_to_clean = |
| 623 | atomic_read(&adapter->rrd_ring.next_to_clean); |
| 624 | value = ((rfd_next_to_use & MB_RFD_PROD_INDX_MASK) << |
| 625 | MB_RFD_PROD_INDX_SHIFT) | |
| 626 | ((rrd_next_to_clean & MB_RRD_CONS_INDX_MASK) << |
| 627 | MB_RRD_CONS_INDX_SHIFT) | |
| 628 | ((tpd_next_to_use & MB_TPD_PROD_INDX_MASK) << |
| 629 | MB_TPD_PROD_INDX_SHIFT); |
| 630 | iowrite32(value, adapter->hw.hw_addr + REG_MAILBOX); |
| 631 | spin_unlock(&adapter->mb_lock); |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | static void atl1_intr_tx(struct atl1_adapter *adapter) |
| 636 | { |
| 637 | struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; |
| 638 | struct atl1_buffer *buffer_info; |
| 639 | u16 sw_tpd_next_to_clean; |
| 640 | u16 cmb_tpd_next_to_clean; |
| 641 | u8 update = 0; |
| 642 | |
| 643 | sw_tpd_next_to_clean = atomic_read(&tpd_ring->next_to_clean); |
| 644 | cmb_tpd_next_to_clean = le16_to_cpu(adapter->cmb.cmb->tpd_cons_idx); |
| 645 | |
| 646 | while (cmb_tpd_next_to_clean != sw_tpd_next_to_clean) { |
| 647 | struct tx_packet_desc *tpd; |
| 648 | update = 1; |
| 649 | tpd = ATL1_TPD_DESC(tpd_ring, sw_tpd_next_to_clean); |
| 650 | buffer_info = &tpd_ring->buffer_info[sw_tpd_next_to_clean]; |
| 651 | if (buffer_info->dma) { |
| 652 | pci_unmap_page(adapter->pdev, buffer_info->dma, |
| 653 | buffer_info->length, PCI_DMA_TODEVICE); |
| 654 | buffer_info->dma = 0; |
| 655 | } |
| 656 | |
| 657 | if (buffer_info->skb) { |
| 658 | dev_kfree_skb_irq(buffer_info->skb); |
| 659 | buffer_info->skb = NULL; |
| 660 | } |
| 661 | tpd->buffer_addr = 0; |
| 662 | tpd->desc.data = 0; |
| 663 | |
| 664 | if (++sw_tpd_next_to_clean == tpd_ring->count) |
| 665 | sw_tpd_next_to_clean = 0; |
| 666 | } |
| 667 | atomic_set(&tpd_ring->next_to_clean, sw_tpd_next_to_clean); |
| 668 | |
| 669 | if (netif_queue_stopped(adapter->netdev) |
| 670 | && netif_carrier_ok(adapter->netdev)) |
| 671 | netif_wake_queue(adapter->netdev); |
| 672 | } |
| 673 | |
| 674 | static void atl1_check_for_link(struct atl1_adapter *adapter) |
| 675 | { |
| 676 | struct net_device *netdev = adapter->netdev; |
| 677 | u16 phy_data = 0; |
| 678 | |
| 679 | spin_lock(&adapter->lock); |
| 680 | adapter->phy_timer_pending = false; |
| 681 | atl1_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data); |
| 682 | atl1_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data); |
| 683 | spin_unlock(&adapter->lock); |
| 684 | |
| 685 | /* notify upper layer link down ASAP */ |
| 686 | if (!(phy_data & BMSR_LSTATUS)) { /* Link Down */ |
| 687 | if (netif_carrier_ok(netdev)) { /* old link state: Up */ |
| 688 | printk(KERN_INFO "%s: %s link is down\n", |
| 689 | atl1_driver_name, netdev->name); |
| 690 | adapter->link_speed = SPEED_0; |
| 691 | netif_carrier_off(netdev); |
| 692 | netif_stop_queue(netdev); |
| 693 | } |
| 694 | } |
| 695 | schedule_work(&adapter->link_chg_task); |
| 696 | } |
| 697 | |
| 698 | /* |
| 699 | * atl1_intr - Interrupt Handler |
| 700 | * @irq: interrupt number |
| 701 | * @data: pointer to a network interface device structure |
| 702 | * @pt_regs: CPU registers structure |
| 703 | */ |
| 704 | static irqreturn_t atl1_intr(int irq, void *data) |
| 705 | { |
| 706 | /*struct atl1_adapter *adapter = ((struct net_device *)data)->priv;*/ |
| 707 | struct atl1_adapter *adapter = netdev_priv(data); |
| 708 | u32 status; |
| 709 | u8 update_rx; |
| 710 | int max_ints = 10; |
| 711 | |
| 712 | status = adapter->cmb.cmb->int_stats; |
| 713 | if (!status) |
| 714 | return IRQ_NONE; |
| 715 | |
| 716 | update_rx = 0; |
| 717 | |
| 718 | do { |
| 719 | /* clear CMB interrupt status at once */ |
| 720 | adapter->cmb.cmb->int_stats = 0; |
| 721 | |
| 722 | if (status & ISR_GPHY) /* clear phy status */ |
| 723 | atl1_clear_phy_int(adapter); |
| 724 | |
| 725 | /* clear ISR status, and Enable CMB DMA/Disable Interrupt */ |
| 726 | iowrite32(status | ISR_DIS_INT, adapter->hw.hw_addr + REG_ISR); |
| 727 | |
| 728 | /* check if SMB intr */ |
| 729 | if (status & ISR_SMB) |
| 730 | atl1_inc_smb(adapter); |
| 731 | |
| 732 | /* check if PCIE PHY Link down */ |
| 733 | if (status & ISR_PHY_LINKDOWN) { |
| 734 | printk(KERN_DEBUG "%s: pcie phy link down %x\n", |
| 735 | atl1_driver_name, status); |
| 736 | if (netif_running(adapter->netdev)) { /* reset MAC */ |
| 737 | iowrite32(0, adapter->hw.hw_addr + REG_IMR); |
| 738 | schedule_work(&adapter->pcie_dma_to_rst_task); |
| 739 | return IRQ_HANDLED; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /* check if DMA read/write error ? */ |
| 744 | if (status & (ISR_DMAR_TO_RST | ISR_DMAW_TO_RST)) { |
| 745 | printk(KERN_DEBUG |
| 746 | "%s: pcie DMA r/w error (status = 0x%x)\n", |
| 747 | atl1_driver_name, status); |
| 748 | iowrite32(0, adapter->hw.hw_addr + REG_IMR); |
| 749 | schedule_work(&adapter->pcie_dma_to_rst_task); |
| 750 | return IRQ_HANDLED; |
| 751 | } |
| 752 | |
| 753 | /* link event */ |
| 754 | if (status & ISR_GPHY) { |
| 755 | adapter->soft_stats.tx_carrier_errors++; |
| 756 | atl1_check_for_link(adapter); |
| 757 | } |
| 758 | |
| 759 | /* transmit event */ |
| 760 | if (status & ISR_CMB_TX) |
| 761 | atl1_intr_tx(adapter); |
| 762 | |
| 763 | /* rx exception */ |
| 764 | if (unlikely(status & (ISR_RXF_OV | ISR_RFD_UNRUN | |
| 765 | ISR_RRD_OV | ISR_HOST_RFD_UNRUN | |
| 766 | ISR_HOST_RRD_OV | ISR_CMB_RX))) { |
| 767 | if (status & |
| 768 | (ISR_RXF_OV | ISR_RFD_UNRUN | ISR_RRD_OV | |
| 769 | ISR_HOST_RFD_UNRUN | ISR_HOST_RRD_OV)) |
| 770 | printk(KERN_INFO |
| 771 | "%s: rx exception: status = 0x%x\n", |
| 772 | atl1_driver_name, status); |
| 773 | atl1_intr_rx(adapter); |
| 774 | } |
| 775 | |
| 776 | if (--max_ints < 0) |
| 777 | break; |
| 778 | |
| 779 | } while ((status = adapter->cmb.cmb->int_stats)); |
| 780 | |
| 781 | /* re-enable Interrupt */ |
| 782 | iowrite32(ISR_DIS_SMB | ISR_DIS_DMA, adapter->hw.hw_addr + REG_ISR); |
| 783 | return IRQ_HANDLED; |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | * atl1_set_multi - Multicast and Promiscuous mode set |
| 788 | * @netdev: network interface device structure |
| 789 | * |
| 790 | * The set_multi entry point is called whenever the multicast address |
| 791 | * list or the network interface flags are updated. This routine is |
| 792 | * responsible for configuring the hardware for proper multicast, |
| 793 | * promiscuous mode, and all-multi behavior. |
| 794 | */ |
| 795 | static void atl1_set_multi(struct net_device *netdev) |
| 796 | { |
| 797 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 798 | struct atl1_hw *hw = &adapter->hw; |
| 799 | struct dev_mc_list *mc_ptr; |
| 800 | u32 rctl; |
| 801 | u32 hash_value; |
| 802 | |
| 803 | /* Check for Promiscuous and All Multicast modes */ |
| 804 | rctl = ioread32(hw->hw_addr + REG_MAC_CTRL); |
| 805 | if (netdev->flags & IFF_PROMISC) |
| 806 | rctl |= MAC_CTRL_PROMIS_EN; |
| 807 | else if (netdev->flags & IFF_ALLMULTI) { |
| 808 | rctl |= MAC_CTRL_MC_ALL_EN; |
| 809 | rctl &= ~MAC_CTRL_PROMIS_EN; |
| 810 | } else |
| 811 | rctl &= ~(MAC_CTRL_PROMIS_EN | MAC_CTRL_MC_ALL_EN); |
| 812 | |
| 813 | iowrite32(rctl, hw->hw_addr + REG_MAC_CTRL); |
| 814 | |
| 815 | /* clear the old settings from the multicast hash table */ |
| 816 | iowrite32(0, hw->hw_addr + REG_RX_HASH_TABLE); |
| 817 | iowrite32(0, (hw->hw_addr + REG_RX_HASH_TABLE) + (1 << 2)); |
| 818 | |
| 819 | /* compute mc addresses' hash value ,and put it into hash table */ |
| 820 | for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) { |
| 821 | hash_value = atl1_hash_mc_addr(hw, mc_ptr->dmi_addr); |
| 822 | atl1_hash_set(hw, hash_value); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | static void atl1_setup_mac_ctrl(struct atl1_adapter *adapter) |
| 827 | { |
| 828 | u32 value; |
| 829 | struct atl1_hw *hw = &adapter->hw; |
| 830 | struct net_device *netdev = adapter->netdev; |
| 831 | /* Config MAC CTRL Register */ |
| 832 | value = MAC_CTRL_TX_EN | MAC_CTRL_RX_EN; |
| 833 | /* duplex */ |
| 834 | if (FULL_DUPLEX == adapter->link_duplex) |
| 835 | value |= MAC_CTRL_DUPLX; |
| 836 | /* speed */ |
| 837 | value |= ((u32) ((SPEED_1000 == adapter->link_speed) ? |
| 838 | MAC_CTRL_SPEED_1000 : MAC_CTRL_SPEED_10_100) << |
| 839 | MAC_CTRL_SPEED_SHIFT); |
| 840 | /* flow control */ |
| 841 | value |= (MAC_CTRL_TX_FLOW | MAC_CTRL_RX_FLOW); |
| 842 | /* PAD & CRC */ |
| 843 | value |= (MAC_CTRL_ADD_CRC | MAC_CTRL_PAD); |
| 844 | /* preamble length */ |
| 845 | value |= (((u32) adapter->hw.preamble_len |
| 846 | & MAC_CTRL_PRMLEN_MASK) << MAC_CTRL_PRMLEN_SHIFT); |
| 847 | /* vlan */ |
| 848 | if (adapter->vlgrp) |
| 849 | value |= MAC_CTRL_RMV_VLAN; |
| 850 | /* rx checksum |
| 851 | if (adapter->rx_csum) |
| 852 | value |= MAC_CTRL_RX_CHKSUM_EN; |
| 853 | */ |
| 854 | /* filter mode */ |
| 855 | value |= MAC_CTRL_BC_EN; |
| 856 | if (netdev->flags & IFF_PROMISC) |
| 857 | value |= MAC_CTRL_PROMIS_EN; |
| 858 | else if (netdev->flags & IFF_ALLMULTI) |
| 859 | value |= MAC_CTRL_MC_ALL_EN; |
| 860 | /* value |= MAC_CTRL_LOOPBACK; */ |
| 861 | iowrite32(value, hw->hw_addr + REG_MAC_CTRL); |
| 862 | } |
| 863 | |
| 864 | static u32 atl1_check_link(struct atl1_adapter *adapter) |
| 865 | { |
| 866 | struct atl1_hw *hw = &adapter->hw; |
| 867 | struct net_device *netdev = adapter->netdev; |
| 868 | u32 ret_val; |
| 869 | u16 speed, duplex, phy_data; |
| 870 | int reconfig = 0; |
| 871 | |
| 872 | /* MII_BMSR must read twice */ |
| 873 | atl1_read_phy_reg(hw, MII_BMSR, &phy_data); |
| 874 | atl1_read_phy_reg(hw, MII_BMSR, &phy_data); |
| 875 | if (!(phy_data & BMSR_LSTATUS)) { /* link down */ |
| 876 | if (netif_carrier_ok(netdev)) { /* old link state: Up */ |
| 877 | printk(KERN_INFO "%s: link is down\n", |
| 878 | atl1_driver_name); |
| 879 | adapter->link_speed = SPEED_0; |
| 880 | netif_carrier_off(netdev); |
| 881 | netif_stop_queue(netdev); |
| 882 | } |
| 883 | return ATL1_SUCCESS; |
| 884 | } |
| 885 | |
| 886 | /* Link Up */ |
| 887 | ret_val = atl1_get_speed_and_duplex(hw, &speed, &duplex); |
| 888 | if (ret_val) |
| 889 | return ret_val; |
| 890 | |
| 891 | switch (hw->media_type) { |
| 892 | case MEDIA_TYPE_1000M_FULL: |
| 893 | if (speed != SPEED_1000 || duplex != FULL_DUPLEX) |
| 894 | reconfig = 1; |
| 895 | break; |
| 896 | case MEDIA_TYPE_100M_FULL: |
| 897 | if (speed != SPEED_100 || duplex != FULL_DUPLEX) |
| 898 | reconfig = 1; |
| 899 | break; |
| 900 | case MEDIA_TYPE_100M_HALF: |
| 901 | if (speed != SPEED_100 || duplex != HALF_DUPLEX) |
| 902 | reconfig = 1; |
| 903 | break; |
| 904 | case MEDIA_TYPE_10M_FULL: |
| 905 | if (speed != SPEED_10 || duplex != FULL_DUPLEX) |
| 906 | reconfig = 1; |
| 907 | break; |
| 908 | case MEDIA_TYPE_10M_HALF: |
| 909 | if (speed != SPEED_10 || duplex != HALF_DUPLEX) |
| 910 | reconfig = 1; |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | /* link result is our setting */ |
| 915 | if (!reconfig) { |
| 916 | if (adapter->link_speed != speed |
| 917 | || adapter->link_duplex != duplex) { |
| 918 | adapter->link_speed = speed; |
| 919 | adapter->link_duplex = duplex; |
| 920 | atl1_setup_mac_ctrl(adapter); |
| 921 | printk(KERN_INFO "%s: %s link is up %d Mbps %s\n", |
| 922 | atl1_driver_name, netdev->name, |
| 923 | adapter->link_speed, |
| 924 | adapter->link_duplex == |
| 925 | FULL_DUPLEX ? "full duplex" : "half duplex"); |
| 926 | } |
| 927 | if (!netif_carrier_ok(netdev)) { /* Link down -> Up */ |
| 928 | netif_carrier_on(netdev); |
| 929 | netif_wake_queue(netdev); |
| 930 | } |
| 931 | return ATL1_SUCCESS; |
| 932 | } |
| 933 | |
| 934 | /* change orignal link status */ |
| 935 | if (netif_carrier_ok(netdev)) { |
| 936 | adapter->link_speed = SPEED_0; |
| 937 | netif_carrier_off(netdev); |
| 938 | netif_stop_queue(netdev); |
| 939 | } |
| 940 | |
| 941 | if (hw->media_type != MEDIA_TYPE_AUTO_SENSOR && |
| 942 | hw->media_type != MEDIA_TYPE_1000M_FULL) { |
| 943 | switch (hw->media_type) { |
| 944 | case MEDIA_TYPE_100M_FULL: |
| 945 | phy_data = MII_CR_FULL_DUPLEX | MII_CR_SPEED_100 | |
| 946 | MII_CR_RESET; |
| 947 | break; |
| 948 | case MEDIA_TYPE_100M_HALF: |
| 949 | phy_data = MII_CR_SPEED_100 | MII_CR_RESET; |
| 950 | break; |
| 951 | case MEDIA_TYPE_10M_FULL: |
| 952 | phy_data = |
| 953 | MII_CR_FULL_DUPLEX | MII_CR_SPEED_10 | MII_CR_RESET; |
| 954 | break; |
| 955 | default: /* MEDIA_TYPE_10M_HALF: */ |
| 956 | phy_data = MII_CR_SPEED_10 | MII_CR_RESET; |
| 957 | break; |
| 958 | } |
| 959 | atl1_write_phy_reg(hw, MII_BMCR, phy_data); |
| 960 | return ATL1_SUCCESS; |
| 961 | } |
| 962 | |
| 963 | /* auto-neg, insert timer to re-config phy */ |
| 964 | if (!adapter->phy_timer_pending) { |
| 965 | adapter->phy_timer_pending = true; |
| 966 | mod_timer(&adapter->phy_config_timer, jiffies + 3 * HZ); |
| 967 | } |
| 968 | |
| 969 | return ATL1_SUCCESS; |
| 970 | } |
| 971 | |
| 972 | static void set_flow_ctrl_old(struct atl1_adapter *adapter) |
| 973 | { |
| 974 | u32 hi, lo, value; |
| 975 | |
| 976 | /* RFD Flow Control */ |
| 977 | value = adapter->rfd_ring.count; |
| 978 | hi = value / 16; |
| 979 | if (hi < 2) |
| 980 | hi = 2; |
| 981 | lo = value * 7 / 8; |
| 982 | |
| 983 | value = ((hi & RXQ_RXF_PAUSE_TH_HI_MASK) << RXQ_RXF_PAUSE_TH_HI_SHIFT) | |
| 984 | ((lo & RXQ_RXF_PAUSE_TH_LO_MASK) << RXQ_RXF_PAUSE_TH_LO_SHIFT); |
| 985 | iowrite32(value, adapter->hw.hw_addr + REG_RXQ_RXF_PAUSE_THRESH); |
| 986 | |
| 987 | /* RRD Flow Control */ |
| 988 | value = adapter->rrd_ring.count; |
| 989 | lo = value / 16; |
| 990 | hi = value * 7 / 8; |
| 991 | if (lo < 2) |
| 992 | lo = 2; |
| 993 | value = ((hi & RXQ_RRD_PAUSE_TH_HI_MASK) << RXQ_RRD_PAUSE_TH_HI_SHIFT) | |
| 994 | ((lo & RXQ_RRD_PAUSE_TH_LO_MASK) << RXQ_RRD_PAUSE_TH_LO_SHIFT); |
| 995 | iowrite32(value, adapter->hw.hw_addr + REG_RXQ_RRD_PAUSE_THRESH); |
| 996 | } |
| 997 | |
| 998 | static void set_flow_ctrl_new(struct atl1_hw *hw) |
| 999 | { |
| 1000 | u32 hi, lo, value; |
| 1001 | |
| 1002 | /* RXF Flow Control */ |
| 1003 | value = ioread32(hw->hw_addr + REG_SRAM_RXF_LEN); |
| 1004 | lo = value / 16; |
| 1005 | if (lo < 192) |
| 1006 | lo = 192; |
| 1007 | hi = value * 7 / 8; |
| 1008 | if (hi < lo) |
| 1009 | hi = lo + 16; |
| 1010 | value = ((hi & RXQ_RXF_PAUSE_TH_HI_MASK) << RXQ_RXF_PAUSE_TH_HI_SHIFT) | |
| 1011 | ((lo & RXQ_RXF_PAUSE_TH_LO_MASK) << RXQ_RXF_PAUSE_TH_LO_SHIFT); |
| 1012 | iowrite32(value, hw->hw_addr + REG_RXQ_RXF_PAUSE_THRESH); |
| 1013 | |
| 1014 | /* RRD Flow Control */ |
| 1015 | value = ioread32(hw->hw_addr + REG_SRAM_RRD_LEN); |
| 1016 | lo = value / 8; |
| 1017 | hi = value * 7 / 8; |
| 1018 | if (lo < 2) |
| 1019 | lo = 2; |
| 1020 | if (hi < lo) |
| 1021 | hi = lo + 3; |
| 1022 | value = ((hi & RXQ_RRD_PAUSE_TH_HI_MASK) << RXQ_RRD_PAUSE_TH_HI_SHIFT) | |
| 1023 | ((lo & RXQ_RRD_PAUSE_TH_LO_MASK) << RXQ_RRD_PAUSE_TH_LO_SHIFT); |
| 1024 | iowrite32(value, hw->hw_addr + REG_RXQ_RRD_PAUSE_THRESH); |
| 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | * atl1_configure - Configure Transmit&Receive Unit after Reset |
| 1029 | * @adapter: board private structure |
| 1030 | * |
| 1031 | * Configure the Tx /Rx unit of the MAC after a reset. |
| 1032 | */ |
| 1033 | static u32 atl1_configure(struct atl1_adapter *adapter) |
| 1034 | { |
| 1035 | struct atl1_hw *hw = &adapter->hw; |
| 1036 | u32 value; |
| 1037 | |
| 1038 | /* clear interrupt status */ |
| 1039 | iowrite32(0xffffffff, adapter->hw.hw_addr + REG_ISR); |
| 1040 | |
| 1041 | /* set MAC Address */ |
| 1042 | value = (((u32) hw->mac_addr[2]) << 24) | |
| 1043 | (((u32) hw->mac_addr[3]) << 16) | |
| 1044 | (((u32) hw->mac_addr[4]) << 8) | |
| 1045 | (((u32) hw->mac_addr[5])); |
| 1046 | iowrite32(value, hw->hw_addr + REG_MAC_STA_ADDR); |
| 1047 | value = (((u32) hw->mac_addr[0]) << 8) | (((u32) hw->mac_addr[1])); |
| 1048 | iowrite32(value, hw->hw_addr + (REG_MAC_STA_ADDR + 4)); |
| 1049 | |
| 1050 | /* tx / rx ring */ |
| 1051 | |
| 1052 | /* HI base address */ |
| 1053 | iowrite32((u32) ((adapter->tpd_ring.dma & 0xffffffff00000000ULL) >> 32), |
| 1054 | hw->hw_addr + REG_DESC_BASE_ADDR_HI); |
| 1055 | /* LO base address */ |
| 1056 | iowrite32((u32) (adapter->rfd_ring.dma & 0x00000000ffffffffULL), |
| 1057 | hw->hw_addr + REG_DESC_RFD_ADDR_LO); |
| 1058 | iowrite32((u32) (adapter->rrd_ring.dma & 0x00000000ffffffffULL), |
| 1059 | hw->hw_addr + REG_DESC_RRD_ADDR_LO); |
| 1060 | iowrite32((u32) (adapter->tpd_ring.dma & 0x00000000ffffffffULL), |
| 1061 | hw->hw_addr + REG_DESC_TPD_ADDR_LO); |
| 1062 | iowrite32((u32) (adapter->cmb.dma & 0x00000000ffffffffULL), |
| 1063 | hw->hw_addr + REG_DESC_CMB_ADDR_LO); |
| 1064 | iowrite32((u32) (adapter->smb.dma & 0x00000000ffffffffULL), |
| 1065 | hw->hw_addr + REG_DESC_SMB_ADDR_LO); |
| 1066 | |
| 1067 | /* element count */ |
| 1068 | value = adapter->rrd_ring.count; |
| 1069 | value <<= 16; |
| 1070 | value += adapter->rfd_ring.count; |
| 1071 | iowrite32(value, hw->hw_addr + REG_DESC_RFD_RRD_RING_SIZE); |
| 1072 | iowrite32(adapter->tpd_ring.count, hw->hw_addr + REG_DESC_TPD_RING_SIZE); |
| 1073 | |
| 1074 | /* Load Ptr */ |
| 1075 | iowrite32(1, hw->hw_addr + REG_LOAD_PTR); |
| 1076 | |
| 1077 | /* config Mailbox */ |
| 1078 | value = ((atomic_read(&adapter->tpd_ring.next_to_use) |
| 1079 | & MB_TPD_PROD_INDX_MASK) << MB_TPD_PROD_INDX_SHIFT) | |
| 1080 | ((atomic_read(&adapter->rrd_ring.next_to_clean) |
| 1081 | & MB_RRD_CONS_INDX_MASK) << MB_RRD_CONS_INDX_SHIFT) | |
| 1082 | ((atomic_read(&adapter->rfd_ring.next_to_use) |
| 1083 | & MB_RFD_PROD_INDX_MASK) << MB_RFD_PROD_INDX_SHIFT); |
| 1084 | iowrite32(value, hw->hw_addr + REG_MAILBOX); |
| 1085 | |
| 1086 | /* config IPG/IFG */ |
| 1087 | value = (((u32) hw->ipgt & MAC_IPG_IFG_IPGT_MASK) |
| 1088 | << MAC_IPG_IFG_IPGT_SHIFT) | |
| 1089 | (((u32) hw->min_ifg & MAC_IPG_IFG_MIFG_MASK) |
| 1090 | << MAC_IPG_IFG_MIFG_SHIFT) | |
| 1091 | (((u32) hw->ipgr1 & MAC_IPG_IFG_IPGR1_MASK) |
| 1092 | << MAC_IPG_IFG_IPGR1_SHIFT) | |
| 1093 | (((u32) hw->ipgr2 & MAC_IPG_IFG_IPGR2_MASK) |
| 1094 | << MAC_IPG_IFG_IPGR2_SHIFT); |
| 1095 | iowrite32(value, hw->hw_addr + REG_MAC_IPG_IFG); |
| 1096 | |
| 1097 | /* config Half-Duplex Control */ |
| 1098 | value = ((u32) hw->lcol & MAC_HALF_DUPLX_CTRL_LCOL_MASK) | |
| 1099 | (((u32) hw->max_retry & MAC_HALF_DUPLX_CTRL_RETRY_MASK) |
| 1100 | << MAC_HALF_DUPLX_CTRL_RETRY_SHIFT) | |
| 1101 | MAC_HALF_DUPLX_CTRL_EXC_DEF_EN | |
| 1102 | (0xa << MAC_HALF_DUPLX_CTRL_ABEBT_SHIFT) | |
| 1103 | (((u32) hw->jam_ipg & MAC_HALF_DUPLX_CTRL_JAMIPG_MASK) |
| 1104 | << MAC_HALF_DUPLX_CTRL_JAMIPG_SHIFT); |
| 1105 | iowrite32(value, hw->hw_addr + REG_MAC_HALF_DUPLX_CTRL); |
| 1106 | |
| 1107 | /* set Interrupt Moderator Timer */ |
| 1108 | iowrite16(adapter->imt, hw->hw_addr + REG_IRQ_MODU_TIMER_INIT); |
| 1109 | iowrite32(MASTER_CTRL_ITIMER_EN, hw->hw_addr + REG_MASTER_CTRL); |
| 1110 | |
| 1111 | /* set Interrupt Clear Timer */ |
| 1112 | iowrite16(adapter->ict, hw->hw_addr + REG_CMBDISDMA_TIMER); |
| 1113 | |
| 1114 | /* set MTU, 4 : VLAN */ |
| 1115 | iowrite32(hw->max_frame_size + 4, hw->hw_addr + REG_MTU); |
| 1116 | |
| 1117 | /* jumbo size & rrd retirement timer */ |
| 1118 | value = (((u32) hw->rx_jumbo_th & RXQ_JMBOSZ_TH_MASK) |
| 1119 | << RXQ_JMBOSZ_TH_SHIFT) | |
| 1120 | (((u32) hw->rx_jumbo_lkah & RXQ_JMBO_LKAH_MASK) |
| 1121 | << RXQ_JMBO_LKAH_SHIFT) | |
| 1122 | (((u32) hw->rrd_ret_timer & RXQ_RRD_TIMER_MASK) |
| 1123 | << RXQ_RRD_TIMER_SHIFT); |
| 1124 | iowrite32(value, hw->hw_addr + REG_RXQ_JMBOSZ_RRDTIM); |
| 1125 | |
| 1126 | /* Flow Control */ |
| 1127 | switch (hw->dev_rev) { |
| 1128 | case 0x8001: |
| 1129 | case 0x9001: |
| 1130 | case 0x9002: |
| 1131 | case 0x9003: |
| 1132 | set_flow_ctrl_old(adapter); |
| 1133 | break; |
| 1134 | default: |
| 1135 | set_flow_ctrl_new(hw); |
| 1136 | break; |
| 1137 | } |
| 1138 | |
| 1139 | /* config TXQ */ |
| 1140 | value = (((u32) hw->tpd_burst & TXQ_CTRL_TPD_BURST_NUM_MASK) |
| 1141 | << TXQ_CTRL_TPD_BURST_NUM_SHIFT) | |
| 1142 | (((u32) hw->txf_burst & TXQ_CTRL_TXF_BURST_NUM_MASK) |
| 1143 | << TXQ_CTRL_TXF_BURST_NUM_SHIFT) | |
| 1144 | (((u32) hw->tpd_fetch_th & TXQ_CTRL_TPD_FETCH_TH_MASK) |
| 1145 | << TXQ_CTRL_TPD_FETCH_TH_SHIFT) | TXQ_CTRL_ENH_MODE | TXQ_CTRL_EN; |
| 1146 | iowrite32(value, hw->hw_addr + REG_TXQ_CTRL); |
| 1147 | |
| 1148 | /* min tpd fetch gap & tx jumbo packet size threshold for taskoffload */ |
| 1149 | value = (((u32) hw->tx_jumbo_task_th & TX_JUMBO_TASK_TH_MASK) |
| 1150 | << TX_JUMBO_TASK_TH_SHIFT) | |
| 1151 | (((u32) hw->tpd_fetch_gap & TX_TPD_MIN_IPG_MASK) |
| 1152 | << TX_TPD_MIN_IPG_SHIFT); |
| 1153 | iowrite32(value, hw->hw_addr + REG_TX_JUMBO_TASK_TH_TPD_IPG); |
| 1154 | |
| 1155 | /* config RXQ */ |
| 1156 | value = (((u32) hw->rfd_burst & RXQ_CTRL_RFD_BURST_NUM_MASK) |
| 1157 | << RXQ_CTRL_RFD_BURST_NUM_SHIFT) | |
| 1158 | (((u32) hw->rrd_burst & RXQ_CTRL_RRD_BURST_THRESH_MASK) |
| 1159 | << RXQ_CTRL_RRD_BURST_THRESH_SHIFT) | |
| 1160 | (((u32) hw->rfd_fetch_gap & RXQ_CTRL_RFD_PREF_MIN_IPG_MASK) |
| 1161 | << RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT) | |
| 1162 | RXQ_CTRL_CUT_THRU_EN | RXQ_CTRL_EN; |
| 1163 | iowrite32(value, hw->hw_addr + REG_RXQ_CTRL); |
| 1164 | |
| 1165 | /* config DMA Engine */ |
| 1166 | value = ((((u32) hw->dmar_block) & DMA_CTRL_DMAR_BURST_LEN_MASK) |
| 1167 | << DMA_CTRL_DMAR_BURST_LEN_SHIFT) | |
| 1168 | ((((u32) hw->dmaw_block) & DMA_CTRL_DMAR_BURST_LEN_MASK) |
| 1169 | << DMA_CTRL_DMAR_BURST_LEN_SHIFT) | |
| 1170 | DMA_CTRL_DMAR_EN | DMA_CTRL_DMAW_EN; |
| 1171 | value |= (u32) hw->dma_ord; |
| 1172 | if (atl1_rcb_128 == hw->rcb_value) |
| 1173 | value |= DMA_CTRL_RCB_VALUE; |
| 1174 | iowrite32(value, hw->hw_addr + REG_DMA_CTRL); |
| 1175 | |
| 1176 | /* config CMB / SMB */ |
| 1177 | value = hw->cmb_rrd | ((u32) hw->cmb_tpd << 16); |
| 1178 | iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TH); |
| 1179 | value = hw->cmb_rx_timer | ((u32) hw->cmb_tx_timer << 16); |
| 1180 | iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TIMER); |
| 1181 | iowrite32(hw->smb_timer, hw->hw_addr + REG_SMB_TIMER); |
| 1182 | |
| 1183 | /* --- enable CMB / SMB */ |
| 1184 | value = CSMB_CTRL_CMB_EN | CSMB_CTRL_SMB_EN; |
| 1185 | iowrite32(value, hw->hw_addr + REG_CSMB_CTRL); |
| 1186 | |
| 1187 | value = ioread32(adapter->hw.hw_addr + REG_ISR); |
| 1188 | if (unlikely((value & ISR_PHY_LINKDOWN) != 0)) |
| 1189 | value = 1; /* config failed */ |
| 1190 | else |
| 1191 | value = 0; |
| 1192 | |
| 1193 | /* clear all interrupt status */ |
| 1194 | iowrite32(0x3fffffff, adapter->hw.hw_addr + REG_ISR); |
| 1195 | iowrite32(0, adapter->hw.hw_addr + REG_ISR); |
| 1196 | return value; |
| 1197 | } |
| 1198 | |
| 1199 | /* |
| 1200 | * atl1_irq_disable - Mask off interrupt generation on the NIC |
| 1201 | * @adapter: board private structure |
| 1202 | */ |
| 1203 | static void atl1_irq_disable(struct atl1_adapter *adapter) |
| 1204 | { |
| 1205 | atomic_inc(&adapter->irq_sem); |
| 1206 | iowrite32(0, adapter->hw.hw_addr + REG_IMR); |
| 1207 | ioread32(adapter->hw.hw_addr + REG_IMR); |
| 1208 | synchronize_irq(adapter->pdev->irq); |
| 1209 | } |
| 1210 | |
| 1211 | static void atl1_vlan_rx_register(struct net_device *netdev, |
| 1212 | struct vlan_group *grp) |
| 1213 | { |
| 1214 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1215 | unsigned long flags; |
| 1216 | u32 ctrl; |
| 1217 | |
| 1218 | spin_lock_irqsave(&adapter->lock, flags); |
| 1219 | /* atl1_irq_disable(adapter); */ |
| 1220 | adapter->vlgrp = grp; |
| 1221 | |
| 1222 | if (grp) { |
| 1223 | /* enable VLAN tag insert/strip */ |
| 1224 | ctrl = ioread32(adapter->hw.hw_addr + REG_MAC_CTRL); |
| 1225 | ctrl |= MAC_CTRL_RMV_VLAN; |
| 1226 | iowrite32(ctrl, adapter->hw.hw_addr + REG_MAC_CTRL); |
| 1227 | } else { |
| 1228 | /* disable VLAN tag insert/strip */ |
| 1229 | ctrl = ioread32(adapter->hw.hw_addr + REG_MAC_CTRL); |
| 1230 | ctrl &= ~MAC_CTRL_RMV_VLAN; |
| 1231 | iowrite32(ctrl, adapter->hw.hw_addr + REG_MAC_CTRL); |
| 1232 | } |
| 1233 | |
| 1234 | /* atl1_irq_enable(adapter); */ |
| 1235 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1236 | } |
| 1237 | |
| 1238 | /* FIXME: justify or remove -- CHS */ |
| 1239 | static void atl1_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 1240 | { |
| 1241 | /* We don't do Vlan filtering */ |
| 1242 | return; |
| 1243 | } |
| 1244 | |
| 1245 | /* FIXME: this looks wrong too -- CHS */ |
| 1246 | static void atl1_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 1247 | { |
| 1248 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1249 | unsigned long flags; |
| 1250 | |
| 1251 | spin_lock_irqsave(&adapter->lock, flags); |
| 1252 | /* atl1_irq_disable(adapter); */ |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1253 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1254 | /* atl1_irq_enable(adapter); */ |
| 1255 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1256 | /* We don't do Vlan filtering */ |
| 1257 | return; |
| 1258 | } |
| 1259 | |
| 1260 | static void atl1_restore_vlan(struct atl1_adapter *adapter) |
| 1261 | { |
| 1262 | atl1_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 1263 | if (adapter->vlgrp) { |
| 1264 | u16 vid; |
| 1265 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 1266 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1267 | continue; |
| 1268 | atl1_vlan_rx_add_vid(adapter->netdev, vid); |
| 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | |
| 1273 | static u16 tpd_avail(struct atl1_tpd_ring *tpd_ring) |
| 1274 | { |
| 1275 | u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean); |
| 1276 | u16 next_to_use = atomic_read(&tpd_ring->next_to_use); |
| 1277 | return ((next_to_clean > |
| 1278 | next_to_use) ? next_to_clean - next_to_use - |
| 1279 | 1 : tpd_ring->count + next_to_clean - next_to_use - 1); |
| 1280 | } |
| 1281 | |
| 1282 | static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb, |
| 1283 | struct tso_param *tso) |
| 1284 | { |
| 1285 | /* We enter this function holding a spinlock. */ |
| 1286 | u8 ipofst; |
| 1287 | int err; |
| 1288 | |
| 1289 | if (skb_shinfo(skb)->gso_size) { |
| 1290 | if (skb_header_cloned(skb)) { |
| 1291 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 1292 | if (unlikely(err)) |
| 1293 | return err; |
| 1294 | } |
| 1295 | |
| 1296 | if (skb->protocol == ntohs(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1297 | struct iphdr *iph = ip_hdr(skb); |
| 1298 | |
| 1299 | iph->tot_len = 0; |
| 1300 | iph->check = 0; |
| 1301 | skb->h.th->check = ~csum_tcpudp_magic(iph->saddr, |
| 1302 | iph->daddr, 0, |
| 1303 | IPPROTO_TCP, 0); |
Arnaldo Carvalho de Melo | bbe735e | 2007-03-10 22:16:10 -0300 | [diff] [blame] | 1304 | ipofst = skb_network_offset(skb); |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1305 | if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */ |
| 1306 | tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT; |
| 1307 | |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 1308 | tso->tsopl |= (iph->ihl & |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1309 | CSUM_PARAM_IPHL_MASK) << CSUM_PARAM_IPHL_SHIFT; |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame^] | 1310 | tso->tsopl |= (tcp_hdrlen(skb) & |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1311 | TSO_PARAM_TCPHDRLEN_MASK) << TSO_PARAM_TCPHDRLEN_SHIFT; |
| 1312 | tso->tsopl |= (skb_shinfo(skb)->gso_size & |
| 1313 | TSO_PARAM_MSS_MASK) << TSO_PARAM_MSS_SHIFT; |
| 1314 | tso->tsopl |= 1 << TSO_PARAM_IPCKSUM_SHIFT; |
| 1315 | tso->tsopl |= 1 << TSO_PARAM_TCPCKSUM_SHIFT; |
| 1316 | tso->tsopl |= 1 << TSO_PARAM_SEGMENT_SHIFT; |
| 1317 | return true; |
| 1318 | } |
| 1319 | } |
| 1320 | return false; |
| 1321 | } |
| 1322 | |
| 1323 | static int atl1_tx_csum(struct atl1_adapter *adapter, struct sk_buff *skb, |
| 1324 | struct csum_param *csum) |
| 1325 | { |
| 1326 | u8 css, cso; |
| 1327 | |
| 1328 | if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) { |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 1329 | cso = skb_transport_offset(skb); |
| 1330 | css = cso + skb->csum; |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1331 | if (unlikely(cso & 0x1)) { |
| 1332 | printk(KERN_DEBUG "%s: payload offset != even number\n", |
| 1333 | atl1_driver_name); |
| 1334 | return -1; |
| 1335 | } |
| 1336 | csum->csumpl |= (cso & CSUM_PARAM_PLOADOFFSET_MASK) << |
| 1337 | CSUM_PARAM_PLOADOFFSET_SHIFT; |
| 1338 | csum->csumpl |= (css & CSUM_PARAM_XSUMOFFSET_MASK) << |
| 1339 | CSUM_PARAM_XSUMOFFSET_SHIFT; |
| 1340 | csum->csumpl |= 1 << CSUM_PARAM_CUSTOMCKSUM_SHIFT; |
| 1341 | return true; |
| 1342 | } |
| 1343 | |
| 1344 | return true; |
| 1345 | } |
| 1346 | |
| 1347 | static void atl1_tx_map(struct atl1_adapter *adapter, |
| 1348 | struct sk_buff *skb, bool tcp_seg) |
| 1349 | { |
| 1350 | /* We enter this function holding a spinlock. */ |
| 1351 | struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; |
| 1352 | struct atl1_buffer *buffer_info; |
| 1353 | struct page *page; |
| 1354 | int first_buf_len = skb->len; |
| 1355 | unsigned long offset; |
| 1356 | unsigned int nr_frags; |
| 1357 | unsigned int f; |
| 1358 | u16 tpd_next_to_use; |
| 1359 | u16 proto_hdr_len; |
| 1360 | u16 i, m, len12; |
| 1361 | |
| 1362 | first_buf_len -= skb->data_len; |
| 1363 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 1364 | tpd_next_to_use = atomic_read(&tpd_ring->next_to_use); |
| 1365 | buffer_info = &tpd_ring->buffer_info[tpd_next_to_use]; |
| 1366 | if (unlikely(buffer_info->skb)) |
| 1367 | BUG(); |
| 1368 | buffer_info->skb = NULL; /* put skb in last TPD */ |
| 1369 | |
| 1370 | if (tcp_seg) { |
| 1371 | /* TSO/GSO */ |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame^] | 1372 | proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb); |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1373 | buffer_info->length = proto_hdr_len; |
| 1374 | page = virt_to_page(skb->data); |
| 1375 | offset = (unsigned long)skb->data & ~PAGE_MASK; |
| 1376 | buffer_info->dma = pci_map_page(adapter->pdev, page, |
| 1377 | offset, proto_hdr_len, |
| 1378 | PCI_DMA_TODEVICE); |
| 1379 | |
| 1380 | if (++tpd_next_to_use == tpd_ring->count) |
| 1381 | tpd_next_to_use = 0; |
| 1382 | |
| 1383 | if (first_buf_len > proto_hdr_len) { |
| 1384 | len12 = first_buf_len - proto_hdr_len; |
| 1385 | m = (len12 + MAX_TX_BUF_LEN - 1) / MAX_TX_BUF_LEN; |
| 1386 | for (i = 0; i < m; i++) { |
| 1387 | buffer_info = |
| 1388 | &tpd_ring->buffer_info[tpd_next_to_use]; |
| 1389 | buffer_info->skb = NULL; |
| 1390 | buffer_info->length = |
| 1391 | (MAX_TX_BUF_LEN >= |
| 1392 | len12) ? MAX_TX_BUF_LEN : len12; |
| 1393 | len12 -= buffer_info->length; |
| 1394 | page = virt_to_page(skb->data + |
| 1395 | (proto_hdr_len + |
| 1396 | i * MAX_TX_BUF_LEN)); |
| 1397 | offset = (unsigned long)(skb->data + |
| 1398 | (proto_hdr_len + |
| 1399 | i * MAX_TX_BUF_LEN)) & |
| 1400 | ~PAGE_MASK; |
| 1401 | buffer_info->dma = |
| 1402 | pci_map_page(adapter->pdev, page, offset, |
| 1403 | buffer_info->length, |
| 1404 | PCI_DMA_TODEVICE); |
| 1405 | if (++tpd_next_to_use == tpd_ring->count) |
| 1406 | tpd_next_to_use = 0; |
| 1407 | } |
| 1408 | } |
| 1409 | } else { |
| 1410 | /* not TSO/GSO */ |
| 1411 | buffer_info->length = first_buf_len; |
| 1412 | page = virt_to_page(skb->data); |
| 1413 | offset = (unsigned long)skb->data & ~PAGE_MASK; |
| 1414 | buffer_info->dma = pci_map_page(adapter->pdev, page, |
| 1415 | offset, first_buf_len, |
| 1416 | PCI_DMA_TODEVICE); |
| 1417 | if (++tpd_next_to_use == tpd_ring->count) |
| 1418 | tpd_next_to_use = 0; |
| 1419 | } |
| 1420 | |
| 1421 | for (f = 0; f < nr_frags; f++) { |
| 1422 | struct skb_frag_struct *frag; |
| 1423 | u16 lenf, i, m; |
| 1424 | |
| 1425 | frag = &skb_shinfo(skb)->frags[f]; |
| 1426 | lenf = frag->size; |
| 1427 | |
| 1428 | m = (lenf + MAX_TX_BUF_LEN - 1) / MAX_TX_BUF_LEN; |
| 1429 | for (i = 0; i < m; i++) { |
| 1430 | buffer_info = &tpd_ring->buffer_info[tpd_next_to_use]; |
| 1431 | if (unlikely(buffer_info->skb)) |
| 1432 | BUG(); |
| 1433 | buffer_info->skb = NULL; |
| 1434 | buffer_info->length = |
| 1435 | (lenf > MAX_TX_BUF_LEN) ? MAX_TX_BUF_LEN : lenf; |
| 1436 | lenf -= buffer_info->length; |
| 1437 | buffer_info->dma = |
| 1438 | pci_map_page(adapter->pdev, frag->page, |
| 1439 | frag->page_offset + i * MAX_TX_BUF_LEN, |
| 1440 | buffer_info->length, PCI_DMA_TODEVICE); |
| 1441 | |
| 1442 | if (++tpd_next_to_use == tpd_ring->count) |
| 1443 | tpd_next_to_use = 0; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | /* last tpd's buffer-info */ |
| 1448 | buffer_info->skb = skb; |
| 1449 | } |
| 1450 | |
| 1451 | static void atl1_tx_queue(struct atl1_adapter *adapter, int count, |
| 1452 | union tpd_descr *descr) |
| 1453 | { |
| 1454 | /* We enter this function holding a spinlock. */ |
| 1455 | struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; |
| 1456 | int j; |
| 1457 | u32 val; |
| 1458 | struct atl1_buffer *buffer_info; |
| 1459 | struct tx_packet_desc *tpd; |
| 1460 | u16 tpd_next_to_use = atomic_read(&tpd_ring->next_to_use); |
| 1461 | |
| 1462 | for (j = 0; j < count; j++) { |
| 1463 | buffer_info = &tpd_ring->buffer_info[tpd_next_to_use]; |
| 1464 | tpd = ATL1_TPD_DESC(&adapter->tpd_ring, tpd_next_to_use); |
| 1465 | tpd->desc.csum.csumpu = descr->csum.csumpu; |
| 1466 | tpd->desc.csum.csumpl = descr->csum.csumpl; |
| 1467 | tpd->desc.tso.tsopu = descr->tso.tsopu; |
| 1468 | tpd->desc.tso.tsopl = descr->tso.tsopl; |
| 1469 | tpd->buffer_addr = cpu_to_le64(buffer_info->dma); |
| 1470 | tpd->desc.data = descr->data; |
| 1471 | tpd->desc.csum.csumpu |= (cpu_to_le16(buffer_info->length) & |
| 1472 | CSUM_PARAM_BUFLEN_MASK) << CSUM_PARAM_BUFLEN_SHIFT; |
| 1473 | |
| 1474 | val = (descr->tso.tsopl >> TSO_PARAM_SEGMENT_SHIFT) & |
| 1475 | TSO_PARAM_SEGMENT_MASK; |
| 1476 | if (val && !j) |
| 1477 | tpd->desc.tso.tsopl |= 1 << TSO_PARAM_HDRFLAG_SHIFT; |
| 1478 | |
| 1479 | if (j == (count - 1)) |
| 1480 | tpd->desc.csum.csumpl |= 1 << CSUM_PARAM_EOP_SHIFT; |
| 1481 | |
| 1482 | if (++tpd_next_to_use == tpd_ring->count) |
| 1483 | tpd_next_to_use = 0; |
| 1484 | } |
| 1485 | /* |
| 1486 | * Force memory writes to complete before letting h/w |
| 1487 | * know there are new descriptors to fetch. (Only |
| 1488 | * applicable for weak-ordered memory model archs, |
| 1489 | * such as IA-64). |
| 1490 | */ |
| 1491 | wmb(); |
| 1492 | |
| 1493 | atomic_set(&tpd_ring->next_to_use, (int)tpd_next_to_use); |
| 1494 | } |
| 1495 | |
| 1496 | static void atl1_update_mailbox(struct atl1_adapter *adapter) |
| 1497 | { |
| 1498 | unsigned long flags; |
| 1499 | u32 tpd_next_to_use; |
| 1500 | u32 rfd_next_to_use; |
| 1501 | u32 rrd_next_to_clean; |
| 1502 | u32 value; |
| 1503 | |
| 1504 | spin_lock_irqsave(&adapter->mb_lock, flags); |
| 1505 | |
| 1506 | tpd_next_to_use = atomic_read(&adapter->tpd_ring.next_to_use); |
| 1507 | rfd_next_to_use = atomic_read(&adapter->rfd_ring.next_to_use); |
| 1508 | rrd_next_to_clean = atomic_read(&adapter->rrd_ring.next_to_clean); |
| 1509 | |
| 1510 | value = ((rfd_next_to_use & MB_RFD_PROD_INDX_MASK) << |
| 1511 | MB_RFD_PROD_INDX_SHIFT) | |
| 1512 | ((rrd_next_to_clean & MB_RRD_CONS_INDX_MASK) << |
| 1513 | MB_RRD_CONS_INDX_SHIFT) | |
| 1514 | ((tpd_next_to_use & MB_TPD_PROD_INDX_MASK) << |
| 1515 | MB_TPD_PROD_INDX_SHIFT); |
| 1516 | iowrite32(value, adapter->hw.hw_addr + REG_MAILBOX); |
| 1517 | |
| 1518 | spin_unlock_irqrestore(&adapter->mb_lock, flags); |
| 1519 | } |
| 1520 | |
| 1521 | static int atl1_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 1522 | { |
| 1523 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1524 | int len = skb->len; |
| 1525 | int tso; |
| 1526 | int count = 1; |
| 1527 | int ret_val; |
| 1528 | u32 val; |
| 1529 | union tpd_descr param; |
| 1530 | u16 frag_size; |
| 1531 | u16 vlan_tag; |
| 1532 | unsigned long flags; |
| 1533 | unsigned int nr_frags = 0; |
| 1534 | unsigned int mss = 0; |
| 1535 | unsigned int f; |
| 1536 | unsigned int proto_hdr_len; |
| 1537 | |
| 1538 | len -= skb->data_len; |
| 1539 | |
| 1540 | if (unlikely(skb->len == 0)) { |
| 1541 | dev_kfree_skb_any(skb); |
| 1542 | return NETDEV_TX_OK; |
| 1543 | } |
| 1544 | |
| 1545 | param.data = 0; |
| 1546 | param.tso.tsopu = 0; |
| 1547 | param.tso.tsopl = 0; |
| 1548 | param.csum.csumpu = 0; |
| 1549 | param.csum.csumpl = 0; |
| 1550 | |
| 1551 | /* nr_frags will be nonzero if we're doing scatter/gather (SG) */ |
| 1552 | nr_frags = skb_shinfo(skb)->nr_frags; |
| 1553 | for (f = 0; f < nr_frags; f++) { |
| 1554 | frag_size = skb_shinfo(skb)->frags[f].size; |
| 1555 | if (frag_size) |
| 1556 | count += |
| 1557 | (frag_size + MAX_TX_BUF_LEN - 1) / MAX_TX_BUF_LEN; |
| 1558 | } |
| 1559 | |
| 1560 | /* mss will be nonzero if we're doing segment offload (TSO/GSO) */ |
| 1561 | mss = skb_shinfo(skb)->gso_size; |
| 1562 | if (mss) { |
Al Viro | 7ccec1b | 2007-03-14 09:20:10 +0000 | [diff] [blame] | 1563 | if (skb->protocol == htons(ETH_P_IP)) { |
Arnaldo Carvalho de Melo | ea2ae17 | 2007-04-25 17:55:53 -0700 | [diff] [blame] | 1564 | proto_hdr_len = (skb_transport_offset(skb) + |
Arnaldo Carvalho de Melo | ab6a5bb | 2007-03-18 17:43:48 -0700 | [diff] [blame^] | 1565 | tcp_hdrlen(skb)); |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 1566 | if (unlikely(proto_hdr_len > len)) { |
| 1567 | dev_kfree_skb_any(skb); |
| 1568 | return NETDEV_TX_OK; |
| 1569 | } |
| 1570 | /* need additional TPD ? */ |
| 1571 | if (proto_hdr_len != len) |
| 1572 | count += (len - proto_hdr_len + |
| 1573 | MAX_TX_BUF_LEN - 1) / MAX_TX_BUF_LEN; |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | local_irq_save(flags); |
| 1578 | if (!spin_trylock(&adapter->lock)) { |
| 1579 | /* Can't get lock - tell upper layer to requeue */ |
| 1580 | local_irq_restore(flags); |
| 1581 | printk(KERN_DEBUG "%s: TX locked\n", atl1_driver_name); |
| 1582 | return NETDEV_TX_LOCKED; |
| 1583 | } |
| 1584 | |
| 1585 | if (tpd_avail(&adapter->tpd_ring) < count) { |
| 1586 | /* not enough descriptors */ |
| 1587 | netif_stop_queue(netdev); |
| 1588 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1589 | printk(KERN_DEBUG "%s: TX busy\n", atl1_driver_name); |
| 1590 | return NETDEV_TX_BUSY; |
| 1591 | } |
| 1592 | |
| 1593 | param.data = 0; |
| 1594 | |
| 1595 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 1596 | vlan_tag = vlan_tx_tag_get(skb); |
| 1597 | vlan_tag = (vlan_tag << 4) | (vlan_tag >> 13) | |
| 1598 | ((vlan_tag >> 9) & 0x8); |
| 1599 | param.csum.csumpl |= 1 << CSUM_PARAM_INSVLAG_SHIFT; |
| 1600 | param.csum.csumpu |= (vlan_tag & CSUM_PARAM_VALANTAG_MASK) << |
| 1601 | CSUM_PARAM_VALAN_SHIFT; |
| 1602 | } |
| 1603 | |
| 1604 | tso = atl1_tso(adapter, skb, ¶m.tso); |
| 1605 | if (tso < 0) { |
| 1606 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1607 | dev_kfree_skb_any(skb); |
| 1608 | return NETDEV_TX_OK; |
| 1609 | } |
| 1610 | |
| 1611 | if (!tso) { |
| 1612 | ret_val = atl1_tx_csum(adapter, skb, ¶m.csum); |
| 1613 | if (ret_val < 0) { |
| 1614 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1615 | dev_kfree_skb_any(skb); |
| 1616 | return NETDEV_TX_OK; |
| 1617 | } |
| 1618 | } |
| 1619 | |
| 1620 | val = (param.csum.csumpl >> CSUM_PARAM_SEGMENT_SHIFT) & |
| 1621 | CSUM_PARAM_SEGMENT_MASK; |
| 1622 | atl1_tx_map(adapter, skb, 1 == val); |
| 1623 | atl1_tx_queue(adapter, count, ¶m); |
| 1624 | netdev->trans_start = jiffies; |
| 1625 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1626 | atl1_update_mailbox(adapter); |
| 1627 | return NETDEV_TX_OK; |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | * atl1_get_stats - Get System Network Statistics |
| 1632 | * @netdev: network interface device structure |
| 1633 | * |
| 1634 | * Returns the address of the device statistics structure. |
| 1635 | * The statistics are actually updated from the timer callback. |
| 1636 | */ |
| 1637 | static struct net_device_stats *atl1_get_stats(struct net_device *netdev) |
| 1638 | { |
| 1639 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1640 | return &adapter->net_stats; |
| 1641 | } |
| 1642 | |
| 1643 | /* |
| 1644 | * atl1_clean_rx_ring - Free RFD Buffers |
| 1645 | * @adapter: board private structure |
| 1646 | */ |
| 1647 | static void atl1_clean_rx_ring(struct atl1_adapter *adapter) |
| 1648 | { |
| 1649 | struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 1650 | struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring; |
| 1651 | struct atl1_buffer *buffer_info; |
| 1652 | struct pci_dev *pdev = adapter->pdev; |
| 1653 | unsigned long size; |
| 1654 | unsigned int i; |
| 1655 | |
| 1656 | /* Free all the Rx ring sk_buffs */ |
| 1657 | for (i = 0; i < rfd_ring->count; i++) { |
| 1658 | buffer_info = &rfd_ring->buffer_info[i]; |
| 1659 | if (buffer_info->dma) { |
| 1660 | pci_unmap_page(pdev, |
| 1661 | buffer_info->dma, |
| 1662 | buffer_info->length, |
| 1663 | PCI_DMA_FROMDEVICE); |
| 1664 | buffer_info->dma = 0; |
| 1665 | } |
| 1666 | if (buffer_info->skb) { |
| 1667 | dev_kfree_skb(buffer_info->skb); |
| 1668 | buffer_info->skb = NULL; |
| 1669 | } |
| 1670 | } |
| 1671 | |
| 1672 | size = sizeof(struct atl1_buffer) * rfd_ring->count; |
| 1673 | memset(rfd_ring->buffer_info, 0, size); |
| 1674 | |
| 1675 | /* Zero out the descriptor ring */ |
| 1676 | memset(rfd_ring->desc, 0, rfd_ring->size); |
| 1677 | |
| 1678 | rfd_ring->next_to_clean = 0; |
| 1679 | atomic_set(&rfd_ring->next_to_use, 0); |
| 1680 | |
| 1681 | rrd_ring->next_to_use = 0; |
| 1682 | atomic_set(&rrd_ring->next_to_clean, 0); |
| 1683 | } |
| 1684 | |
| 1685 | /* |
| 1686 | * atl1_clean_tx_ring - Free Tx Buffers |
| 1687 | * @adapter: board private structure |
| 1688 | */ |
| 1689 | static void atl1_clean_tx_ring(struct atl1_adapter *adapter) |
| 1690 | { |
| 1691 | struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; |
| 1692 | struct atl1_buffer *buffer_info; |
| 1693 | struct pci_dev *pdev = adapter->pdev; |
| 1694 | unsigned long size; |
| 1695 | unsigned int i; |
| 1696 | |
| 1697 | /* Free all the Tx ring sk_buffs */ |
| 1698 | for (i = 0; i < tpd_ring->count; i++) { |
| 1699 | buffer_info = &tpd_ring->buffer_info[i]; |
| 1700 | if (buffer_info->dma) { |
| 1701 | pci_unmap_page(pdev, buffer_info->dma, |
| 1702 | buffer_info->length, PCI_DMA_TODEVICE); |
| 1703 | buffer_info->dma = 0; |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | for (i = 0; i < tpd_ring->count; i++) { |
| 1708 | buffer_info = &tpd_ring->buffer_info[i]; |
| 1709 | if (buffer_info->skb) { |
| 1710 | dev_kfree_skb_any(buffer_info->skb); |
| 1711 | buffer_info->skb = NULL; |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | size = sizeof(struct atl1_buffer) * tpd_ring->count; |
| 1716 | memset(tpd_ring->buffer_info, 0, size); |
| 1717 | |
| 1718 | /* Zero out the descriptor ring */ |
| 1719 | memset(tpd_ring->desc, 0, tpd_ring->size); |
| 1720 | |
| 1721 | atomic_set(&tpd_ring->next_to_use, 0); |
| 1722 | atomic_set(&tpd_ring->next_to_clean, 0); |
| 1723 | } |
| 1724 | |
| 1725 | /* |
| 1726 | * atl1_free_ring_resources - Free Tx / RX descriptor Resources |
| 1727 | * @adapter: board private structure |
| 1728 | * |
| 1729 | * Free all transmit software resources |
| 1730 | */ |
| 1731 | void atl1_free_ring_resources(struct atl1_adapter *adapter) |
| 1732 | { |
| 1733 | struct pci_dev *pdev = adapter->pdev; |
| 1734 | struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring; |
| 1735 | struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring; |
| 1736 | struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring; |
| 1737 | struct atl1_ring_header *ring_header = &adapter->ring_header; |
| 1738 | |
| 1739 | atl1_clean_tx_ring(adapter); |
| 1740 | atl1_clean_rx_ring(adapter); |
| 1741 | |
| 1742 | kfree(tpd_ring->buffer_info); |
| 1743 | pci_free_consistent(pdev, ring_header->size, ring_header->desc, |
| 1744 | ring_header->dma); |
| 1745 | |
| 1746 | tpd_ring->buffer_info = NULL; |
| 1747 | tpd_ring->desc = NULL; |
| 1748 | tpd_ring->dma = 0; |
| 1749 | |
| 1750 | rfd_ring->buffer_info = NULL; |
| 1751 | rfd_ring->desc = NULL; |
| 1752 | rfd_ring->dma = 0; |
| 1753 | |
| 1754 | rrd_ring->desc = NULL; |
| 1755 | rrd_ring->dma = 0; |
| 1756 | } |
| 1757 | |
| 1758 | s32 atl1_up(struct atl1_adapter *adapter) |
| 1759 | { |
| 1760 | struct net_device *netdev = adapter->netdev; |
| 1761 | int err; |
| 1762 | int irq_flags = IRQF_SAMPLE_RANDOM; |
| 1763 | |
| 1764 | /* hardware has been reset, we need to reload some things */ |
| 1765 | atl1_set_multi(netdev); |
| 1766 | atl1_restore_vlan(adapter); |
| 1767 | err = atl1_alloc_rx_buffers(adapter); |
| 1768 | if (unlikely(!err)) /* no RX BUFFER allocated */ |
| 1769 | return -ENOMEM; |
| 1770 | |
| 1771 | if (unlikely(atl1_configure(adapter))) { |
| 1772 | err = -EIO; |
| 1773 | goto err_up; |
| 1774 | } |
| 1775 | |
| 1776 | err = pci_enable_msi(adapter->pdev); |
| 1777 | if (err) { |
| 1778 | dev_info(&adapter->pdev->dev, |
| 1779 | "Unable to enable MSI: %d\n", err); |
| 1780 | irq_flags |= IRQF_SHARED; |
| 1781 | } |
| 1782 | |
| 1783 | err = request_irq(adapter->pdev->irq, &atl1_intr, irq_flags, |
| 1784 | netdev->name, netdev); |
| 1785 | if (unlikely(err)) |
| 1786 | goto err_up; |
| 1787 | |
| 1788 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 1789 | atl1_irq_enable(adapter); |
| 1790 | atl1_check_link(adapter); |
| 1791 | return 0; |
| 1792 | |
| 1793 | /* FIXME: unreachable code! -- CHS */ |
| 1794 | /* free irq disable any interrupt */ |
| 1795 | iowrite32(0, adapter->hw.hw_addr + REG_IMR); |
| 1796 | free_irq(adapter->pdev->irq, netdev); |
| 1797 | |
| 1798 | err_up: |
| 1799 | pci_disable_msi(adapter->pdev); |
| 1800 | /* free rx_buffers */ |
| 1801 | atl1_clean_rx_ring(adapter); |
| 1802 | return err; |
| 1803 | } |
| 1804 | |
| 1805 | void atl1_down(struct atl1_adapter *adapter) |
| 1806 | { |
| 1807 | struct net_device *netdev = adapter->netdev; |
| 1808 | |
| 1809 | del_timer_sync(&adapter->watchdog_timer); |
| 1810 | del_timer_sync(&adapter->phy_config_timer); |
| 1811 | adapter->phy_timer_pending = false; |
| 1812 | |
| 1813 | atl1_irq_disable(adapter); |
| 1814 | free_irq(adapter->pdev->irq, netdev); |
| 1815 | pci_disable_msi(adapter->pdev); |
| 1816 | atl1_reset_hw(&adapter->hw); |
| 1817 | adapter->cmb.cmb->int_stats = 0; |
| 1818 | |
| 1819 | adapter->link_speed = SPEED_0; |
| 1820 | adapter->link_duplex = -1; |
| 1821 | netif_carrier_off(netdev); |
| 1822 | netif_stop_queue(netdev); |
| 1823 | |
| 1824 | atl1_clean_tx_ring(adapter); |
| 1825 | atl1_clean_rx_ring(adapter); |
| 1826 | } |
| 1827 | |
| 1828 | /* |
| 1829 | * atl1_change_mtu - Change the Maximum Transfer Unit |
| 1830 | * @netdev: network interface device structure |
| 1831 | * @new_mtu: new value for maximum frame size |
| 1832 | * |
| 1833 | * Returns 0 on success, negative on failure |
| 1834 | */ |
| 1835 | static int atl1_change_mtu(struct net_device *netdev, int new_mtu) |
| 1836 | { |
| 1837 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1838 | int old_mtu = netdev->mtu; |
| 1839 | int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE; |
| 1840 | |
| 1841 | if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || |
| 1842 | (max_frame > MAX_JUMBO_FRAME_SIZE)) { |
| 1843 | printk(KERN_WARNING "%s: invalid MTU setting\n", |
| 1844 | atl1_driver_name); |
| 1845 | return -EINVAL; |
| 1846 | } |
| 1847 | |
| 1848 | adapter->hw.max_frame_size = max_frame; |
| 1849 | adapter->hw.tx_jumbo_task_th = (max_frame + 7) >> 3; |
| 1850 | adapter->rx_buffer_len = (max_frame + 7) & ~7; |
| 1851 | adapter->hw.rx_jumbo_th = adapter->rx_buffer_len / 8; |
| 1852 | |
| 1853 | netdev->mtu = new_mtu; |
| 1854 | if ((old_mtu != new_mtu) && netif_running(netdev)) { |
| 1855 | atl1_down(adapter); |
| 1856 | atl1_up(adapter); |
| 1857 | } |
| 1858 | |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | /* |
| 1863 | * atl1_set_mac - Change the Ethernet Address of the NIC |
| 1864 | * @netdev: network interface device structure |
| 1865 | * @p: pointer to an address structure |
| 1866 | * |
| 1867 | * Returns 0 on success, negative on failure |
| 1868 | */ |
| 1869 | static int atl1_set_mac(struct net_device *netdev, void *p) |
| 1870 | { |
| 1871 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1872 | struct sockaddr *addr = p; |
| 1873 | |
| 1874 | if (netif_running(netdev)) |
| 1875 | return -EBUSY; |
| 1876 | |
| 1877 | if (!is_valid_ether_addr(addr->sa_data)) |
| 1878 | return -EADDRNOTAVAIL; |
| 1879 | |
| 1880 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 1881 | memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len); |
| 1882 | |
| 1883 | atl1_set_mac_addr(&adapter->hw); |
| 1884 | return 0; |
| 1885 | } |
| 1886 | |
| 1887 | /* |
| 1888 | * atl1_watchdog - Timer Call-back |
| 1889 | * @data: pointer to netdev cast into an unsigned long |
| 1890 | */ |
| 1891 | static void atl1_watchdog(unsigned long data) |
| 1892 | { |
| 1893 | struct atl1_adapter *adapter = (struct atl1_adapter *)data; |
| 1894 | |
| 1895 | /* Reset the timer */ |
| 1896 | mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ); |
| 1897 | } |
| 1898 | |
| 1899 | static int mdio_read(struct net_device *netdev, int phy_id, int reg_num) |
| 1900 | { |
| 1901 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1902 | u16 result; |
| 1903 | |
| 1904 | atl1_read_phy_reg(&adapter->hw, reg_num & 0x1f, &result); |
| 1905 | |
| 1906 | return result; |
| 1907 | } |
| 1908 | |
| 1909 | static void mdio_write(struct net_device *netdev, int phy_id, int reg_num, int val) |
| 1910 | { |
| 1911 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1912 | |
| 1913 | atl1_write_phy_reg(&adapter->hw, reg_num, val); |
| 1914 | } |
| 1915 | |
| 1916 | /* |
| 1917 | * atl1_mii_ioctl - |
| 1918 | * @netdev: |
| 1919 | * @ifreq: |
| 1920 | * @cmd: |
| 1921 | */ |
| 1922 | static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 1923 | { |
| 1924 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1925 | unsigned long flags; |
| 1926 | int retval; |
| 1927 | |
| 1928 | if (!netif_running(netdev)) |
| 1929 | return -EINVAL; |
| 1930 | |
| 1931 | spin_lock_irqsave(&adapter->lock, flags); |
| 1932 | retval = generic_mii_ioctl(&adapter->mii, if_mii(ifr), cmd, NULL); |
| 1933 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1934 | |
| 1935 | return retval; |
| 1936 | } |
| 1937 | |
| 1938 | /* |
| 1939 | * atl1_ioctl - |
| 1940 | * @netdev: |
| 1941 | * @ifreq: |
| 1942 | * @cmd: |
| 1943 | */ |
| 1944 | static int atl1_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 1945 | { |
| 1946 | switch (cmd) { |
| 1947 | case SIOCGMIIPHY: |
| 1948 | case SIOCGMIIREG: |
| 1949 | case SIOCSMIIREG: |
| 1950 | return atl1_mii_ioctl(netdev, ifr, cmd); |
| 1951 | default: |
| 1952 | return -EOPNOTSUPP; |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | /* |
| 1957 | * atl1_tx_timeout - Respond to a Tx Hang |
| 1958 | * @netdev: network interface device structure |
| 1959 | */ |
| 1960 | static void atl1_tx_timeout(struct net_device *netdev) |
| 1961 | { |
| 1962 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 1963 | /* Do the reset outside of interrupt context */ |
| 1964 | schedule_work(&adapter->tx_timeout_task); |
| 1965 | } |
| 1966 | |
| 1967 | /* |
| 1968 | * atl1_phy_config - Timer Call-back |
| 1969 | * @data: pointer to netdev cast into an unsigned long |
| 1970 | */ |
| 1971 | static void atl1_phy_config(unsigned long data) |
| 1972 | { |
| 1973 | struct atl1_adapter *adapter = (struct atl1_adapter *)data; |
| 1974 | struct atl1_hw *hw = &adapter->hw; |
| 1975 | unsigned long flags; |
| 1976 | |
| 1977 | spin_lock_irqsave(&adapter->lock, flags); |
| 1978 | adapter->phy_timer_pending = false; |
| 1979 | atl1_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg); |
| 1980 | atl1_write_phy_reg(hw, MII_AT001_CR, hw->mii_1000t_ctrl_reg); |
| 1981 | atl1_write_phy_reg(hw, MII_BMCR, MII_CR_RESET | MII_CR_AUTO_NEG_EN); |
| 1982 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 1983 | } |
| 1984 | |
| 1985 | int atl1_reset(struct atl1_adapter *adapter) |
| 1986 | { |
| 1987 | int ret; |
| 1988 | |
| 1989 | ret = atl1_reset_hw(&adapter->hw); |
| 1990 | if (ret != ATL1_SUCCESS) |
| 1991 | return ret; |
| 1992 | return atl1_init_hw(&adapter->hw); |
| 1993 | } |
| 1994 | |
| 1995 | /* |
| 1996 | * atl1_open - Called when a network interface is made active |
| 1997 | * @netdev: network interface device structure |
| 1998 | * |
| 1999 | * Returns 0 on success, negative value on failure |
| 2000 | * |
| 2001 | * The open entry point is called when a network interface is made |
| 2002 | * active by the system (IFF_UP). At this point all resources needed |
| 2003 | * for transmit and receive operations are allocated, the interrupt |
| 2004 | * handler is registered with the OS, the watchdog timer is started, |
| 2005 | * and the stack is notified that the interface is ready. |
| 2006 | */ |
| 2007 | static int atl1_open(struct net_device *netdev) |
| 2008 | { |
| 2009 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 2010 | int err; |
| 2011 | |
| 2012 | /* allocate transmit descriptors */ |
| 2013 | err = atl1_setup_ring_resources(adapter); |
| 2014 | if (err) |
| 2015 | return err; |
| 2016 | |
| 2017 | err = atl1_up(adapter); |
| 2018 | if (err) |
| 2019 | goto err_up; |
| 2020 | |
| 2021 | return 0; |
| 2022 | |
| 2023 | err_up: |
| 2024 | atl1_reset(adapter); |
| 2025 | return err; |
| 2026 | } |
| 2027 | |
| 2028 | /* |
| 2029 | * atl1_close - Disables a network interface |
| 2030 | * @netdev: network interface device structure |
| 2031 | * |
| 2032 | * Returns 0, this is not allowed to fail |
| 2033 | * |
| 2034 | * The close entry point is called when an interface is de-activated |
| 2035 | * by the OS. The hardware is still under the drivers control, but |
| 2036 | * needs to be disabled. A global MAC reset is issued to stop the |
| 2037 | * hardware, and all transmit and receive resources are freed. |
| 2038 | */ |
| 2039 | static int atl1_close(struct net_device *netdev) |
| 2040 | { |
| 2041 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 2042 | atl1_down(adapter); |
| 2043 | atl1_free_ring_resources(adapter); |
| 2044 | return 0; |
| 2045 | } |
| 2046 | |
| 2047 | /* |
| 2048 | * If TPD Buffer size equal to 0, PCIE DMAR_TO_INT |
| 2049 | * will assert. We do soft reset <0x1400=1> according |
| 2050 | * with the SPEC. BUT, it seemes that PCIE or DMA |
| 2051 | * state-machine will not be reset. DMAR_TO_INT will |
| 2052 | * assert again and again. |
| 2053 | */ |
| 2054 | static void atl1_tx_timeout_task(struct work_struct *work) |
| 2055 | { |
| 2056 | struct atl1_adapter *adapter = |
| 2057 | container_of(work, struct atl1_adapter, tx_timeout_task); |
| 2058 | struct net_device *netdev = adapter->netdev; |
| 2059 | |
| 2060 | netif_device_detach(netdev); |
| 2061 | atl1_down(adapter); |
| 2062 | atl1_up(adapter); |
| 2063 | netif_device_attach(netdev); |
| 2064 | } |
| 2065 | |
| 2066 | /* |
| 2067 | * atl1_link_chg_task - deal with link change event Out of interrupt context |
| 2068 | */ |
| 2069 | static void atl1_link_chg_task(struct work_struct *work) |
| 2070 | { |
| 2071 | struct atl1_adapter *adapter = |
| 2072 | container_of(work, struct atl1_adapter, link_chg_task); |
| 2073 | unsigned long flags; |
| 2074 | |
| 2075 | spin_lock_irqsave(&adapter->lock, flags); |
| 2076 | atl1_check_link(adapter); |
| 2077 | spin_unlock_irqrestore(&adapter->lock, flags); |
| 2078 | } |
| 2079 | |
| 2080 | /* |
| 2081 | * atl1_pcie_patch - Patch for PCIE module |
| 2082 | */ |
| 2083 | static void atl1_pcie_patch(struct atl1_adapter *adapter) |
| 2084 | { |
| 2085 | u32 value; |
| 2086 | value = 0x6500; |
| 2087 | iowrite32(value, adapter->hw.hw_addr + 0x12FC); |
| 2088 | /* pcie flow control mode change */ |
| 2089 | value = ioread32(adapter->hw.hw_addr + 0x1008); |
| 2090 | value |= 0x8000; |
| 2091 | iowrite32(value, adapter->hw.hw_addr + 0x1008); |
| 2092 | } |
| 2093 | |
| 2094 | /* |
| 2095 | * When ACPI resume on some VIA MotherBoard, the Interrupt Disable bit/0x400 |
| 2096 | * on PCI Command register is disable. |
| 2097 | * The function enable this bit. |
| 2098 | * Brackett, 2006/03/15 |
| 2099 | */ |
| 2100 | static void atl1_via_workaround(struct atl1_adapter *adapter) |
| 2101 | { |
| 2102 | unsigned long value; |
| 2103 | |
| 2104 | value = ioread16(adapter->hw.hw_addr + PCI_COMMAND); |
| 2105 | if (value & PCI_COMMAND_INTX_DISABLE) |
| 2106 | value &= ~PCI_COMMAND_INTX_DISABLE; |
| 2107 | iowrite32(value, adapter->hw.hw_addr + PCI_COMMAND); |
| 2108 | } |
| 2109 | |
| 2110 | /* |
| 2111 | * atl1_probe - Device Initialization Routine |
| 2112 | * @pdev: PCI device information struct |
| 2113 | * @ent: entry in atl1_pci_tbl |
| 2114 | * |
| 2115 | * Returns 0 on success, negative on failure |
| 2116 | * |
| 2117 | * atl1_probe initializes an adapter identified by a pci_dev structure. |
| 2118 | * The OS initialization, configuring of the adapter private structure, |
| 2119 | * and a hardware reset occur. |
| 2120 | */ |
| 2121 | static int __devinit atl1_probe(struct pci_dev *pdev, |
| 2122 | const struct pci_device_id *ent) |
| 2123 | { |
| 2124 | struct net_device *netdev; |
| 2125 | struct atl1_adapter *adapter; |
| 2126 | static int cards_found = 0; |
| 2127 | bool pci_using_64 = true; |
| 2128 | int err; |
| 2129 | |
| 2130 | err = pci_enable_device(pdev); |
| 2131 | if (err) |
| 2132 | return err; |
| 2133 | |
| 2134 | err = pci_set_dma_mask(pdev, DMA_64BIT_MASK); |
| 2135 | if (err) { |
| 2136 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 2137 | if (err) { |
| 2138 | printk(KERN_DEBUG |
| 2139 | "%s: no usable DMA configuration, aborting\n", |
| 2140 | atl1_driver_name); |
| 2141 | goto err_dma; |
| 2142 | } |
| 2143 | pci_using_64 = false; |
| 2144 | } |
| 2145 | /* Mark all PCI regions associated with PCI device |
| 2146 | * pdev as being reserved by owner atl1_driver_name |
| 2147 | */ |
| 2148 | err = pci_request_regions(pdev, atl1_driver_name); |
| 2149 | if (err) |
| 2150 | goto err_request_regions; |
| 2151 | |
| 2152 | /* Enables bus-mastering on the device and calls |
| 2153 | * pcibios_set_master to do the needed arch specific settings |
| 2154 | */ |
| 2155 | pci_set_master(pdev); |
| 2156 | |
| 2157 | netdev = alloc_etherdev(sizeof(struct atl1_adapter)); |
| 2158 | if (!netdev) { |
| 2159 | err = -ENOMEM; |
| 2160 | goto err_alloc_etherdev; |
| 2161 | } |
| 2162 | SET_MODULE_OWNER(netdev); |
| 2163 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 2164 | |
| 2165 | pci_set_drvdata(pdev, netdev); |
| 2166 | adapter = netdev_priv(netdev); |
| 2167 | adapter->netdev = netdev; |
| 2168 | adapter->pdev = pdev; |
| 2169 | adapter->hw.back = adapter; |
| 2170 | |
| 2171 | adapter->hw.hw_addr = pci_iomap(pdev, 0, 0); |
| 2172 | if (!adapter->hw.hw_addr) { |
| 2173 | err = -EIO; |
| 2174 | goto err_pci_iomap; |
| 2175 | } |
| 2176 | /* get device revision number */ |
| 2177 | adapter->hw.dev_rev = ioread16(adapter->hw.hw_addr + (REG_MASTER_CTRL + 2)); |
| 2178 | |
| 2179 | /* set default ring resource counts */ |
| 2180 | adapter->rfd_ring.count = adapter->rrd_ring.count = ATL1_DEFAULT_RFD; |
| 2181 | adapter->tpd_ring.count = ATL1_DEFAULT_TPD; |
| 2182 | |
| 2183 | adapter->mii.dev = netdev; |
| 2184 | adapter->mii.mdio_read = mdio_read; |
| 2185 | adapter->mii.mdio_write = mdio_write; |
| 2186 | adapter->mii.phy_id_mask = 0x1f; |
| 2187 | adapter->mii.reg_num_mask = 0x1f; |
| 2188 | |
| 2189 | netdev->open = &atl1_open; |
| 2190 | netdev->stop = &atl1_close; |
| 2191 | netdev->hard_start_xmit = &atl1_xmit_frame; |
| 2192 | netdev->get_stats = &atl1_get_stats; |
| 2193 | netdev->set_multicast_list = &atl1_set_multi; |
| 2194 | netdev->set_mac_address = &atl1_set_mac; |
| 2195 | netdev->change_mtu = &atl1_change_mtu; |
| 2196 | netdev->do_ioctl = &atl1_ioctl; |
| 2197 | netdev->tx_timeout = &atl1_tx_timeout; |
| 2198 | netdev->watchdog_timeo = 5 * HZ; |
| 2199 | netdev->vlan_rx_register = atl1_vlan_rx_register; |
| 2200 | netdev->vlan_rx_add_vid = atl1_vlan_rx_add_vid; |
| 2201 | netdev->vlan_rx_kill_vid = atl1_vlan_rx_kill_vid; |
| 2202 | netdev->ethtool_ops = &atl1_ethtool_ops; |
| 2203 | adapter->bd_number = cards_found; |
| 2204 | adapter->pci_using_64 = pci_using_64; |
| 2205 | |
| 2206 | /* setup the private structure */ |
| 2207 | err = atl1_sw_init(adapter); |
| 2208 | if (err) |
| 2209 | goto err_common; |
| 2210 | |
| 2211 | netdev->features = NETIF_F_HW_CSUM; |
| 2212 | netdev->features |= NETIF_F_SG; |
| 2213 | netdev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX); |
| 2214 | |
| 2215 | /* |
| 2216 | * FIXME - Until tso performance gets fixed, disable the feature. |
| 2217 | * Enable it with ethtool -K if desired. |
| 2218 | */ |
| 2219 | /* netdev->features |= NETIF_F_TSO; */ |
| 2220 | |
| 2221 | if (pci_using_64) |
| 2222 | netdev->features |= NETIF_F_HIGHDMA; |
| 2223 | |
| 2224 | netdev->features |= NETIF_F_LLTX; |
| 2225 | |
| 2226 | /* |
| 2227 | * patch for some L1 of old version, |
| 2228 | * the final version of L1 may not need these |
| 2229 | * patches |
| 2230 | */ |
| 2231 | /* atl1_pcie_patch(adapter); */ |
| 2232 | |
| 2233 | /* really reset GPHY core */ |
| 2234 | iowrite16(0, adapter->hw.hw_addr + REG_GPHY_ENABLE); |
| 2235 | |
| 2236 | /* |
| 2237 | * reset the controller to |
| 2238 | * put the device in a known good starting state |
| 2239 | */ |
| 2240 | if (atl1_reset_hw(&adapter->hw)) { |
| 2241 | err = -EIO; |
| 2242 | goto err_common; |
| 2243 | } |
| 2244 | |
| 2245 | /* copy the MAC address out of the EEPROM */ |
| 2246 | atl1_read_mac_addr(&adapter->hw); |
| 2247 | memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len); |
| 2248 | |
| 2249 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
| 2250 | err = -EIO; |
| 2251 | goto err_common; |
| 2252 | } |
| 2253 | |
| 2254 | atl1_check_options(adapter); |
| 2255 | |
| 2256 | /* pre-init the MAC, and setup link */ |
| 2257 | err = atl1_init_hw(&adapter->hw); |
| 2258 | if (err) { |
| 2259 | err = -EIO; |
| 2260 | goto err_common; |
| 2261 | } |
| 2262 | |
| 2263 | atl1_pcie_patch(adapter); |
| 2264 | /* assume we have no link for now */ |
| 2265 | netif_carrier_off(netdev); |
| 2266 | netif_stop_queue(netdev); |
| 2267 | |
| 2268 | init_timer(&adapter->watchdog_timer); |
| 2269 | adapter->watchdog_timer.function = &atl1_watchdog; |
| 2270 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 2271 | |
| 2272 | init_timer(&adapter->phy_config_timer); |
| 2273 | adapter->phy_config_timer.function = &atl1_phy_config; |
| 2274 | adapter->phy_config_timer.data = (unsigned long)adapter; |
| 2275 | adapter->phy_timer_pending = false; |
| 2276 | |
| 2277 | INIT_WORK(&adapter->tx_timeout_task, atl1_tx_timeout_task); |
| 2278 | |
| 2279 | INIT_WORK(&adapter->link_chg_task, atl1_link_chg_task); |
| 2280 | |
| 2281 | INIT_WORK(&adapter->pcie_dma_to_rst_task, atl1_tx_timeout_task); |
| 2282 | |
| 2283 | err = register_netdev(netdev); |
| 2284 | if (err) |
| 2285 | goto err_common; |
| 2286 | |
| 2287 | cards_found++; |
| 2288 | atl1_via_workaround(adapter); |
| 2289 | return 0; |
| 2290 | |
| 2291 | err_common: |
| 2292 | pci_iounmap(pdev, adapter->hw.hw_addr); |
| 2293 | err_pci_iomap: |
| 2294 | free_netdev(netdev); |
| 2295 | err_alloc_etherdev: |
| 2296 | pci_release_regions(pdev); |
| 2297 | err_dma: |
| 2298 | err_request_regions: |
| 2299 | pci_disable_device(pdev); |
| 2300 | return err; |
| 2301 | } |
| 2302 | |
| 2303 | /* |
| 2304 | * atl1_remove - Device Removal Routine |
| 2305 | * @pdev: PCI device information struct |
| 2306 | * |
| 2307 | * atl1_remove is called by the PCI subsystem to alert the driver |
| 2308 | * that it should release a PCI device. The could be caused by a |
| 2309 | * Hot-Plug event, or because the driver is going to be removed from |
| 2310 | * memory. |
| 2311 | */ |
| 2312 | static void __devexit atl1_remove(struct pci_dev *pdev) |
| 2313 | { |
| 2314 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2315 | struct atl1_adapter *adapter; |
| 2316 | /* Device not available. Return. */ |
| 2317 | if (!netdev) |
| 2318 | return; |
| 2319 | |
| 2320 | adapter = netdev_priv(netdev); |
Chris Snook | 8c754a0 | 2007-03-28 20:51:51 -0400 | [diff] [blame] | 2321 | |
| 2322 | /* Some atl1 boards lack persistent storage for their MAC, and get it |
| 2323 | * from the BIOS during POST. If we've been messing with the MAC |
| 2324 | * address, we need to save the permanent one. |
| 2325 | */ |
| 2326 | if (memcmp(adapter->hw.mac_addr, adapter->hw.perm_mac_addr, ETH_ALEN)) { |
| 2327 | memcpy(adapter->hw.mac_addr, adapter->hw.perm_mac_addr, ETH_ALEN); |
| 2328 | atl1_set_mac_addr(&adapter->hw); |
| 2329 | } |
| 2330 | |
Jay Cliburn | f3cc28c | 2007-02-08 10:42:37 -0500 | [diff] [blame] | 2331 | iowrite16(0, adapter->hw.hw_addr + REG_GPHY_ENABLE); |
| 2332 | unregister_netdev(netdev); |
| 2333 | pci_iounmap(pdev, adapter->hw.hw_addr); |
| 2334 | pci_release_regions(pdev); |
| 2335 | free_netdev(netdev); |
| 2336 | pci_disable_device(pdev); |
| 2337 | } |
| 2338 | |
| 2339 | #ifdef CONFIG_PM |
| 2340 | static int atl1_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2341 | { |
| 2342 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2343 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 2344 | struct atl1_hw *hw = &adapter->hw; |
| 2345 | u32 ctrl = 0; |
| 2346 | u32 wufc = adapter->wol; |
| 2347 | |
| 2348 | netif_device_detach(netdev); |
| 2349 | if (netif_running(netdev)) |
| 2350 | atl1_down(adapter); |
| 2351 | |
| 2352 | atl1_read_phy_reg(hw, MII_BMSR, (u16 *) & ctrl); |
| 2353 | atl1_read_phy_reg(hw, MII_BMSR, (u16 *) & ctrl); |
| 2354 | if (ctrl & BMSR_LSTATUS) |
| 2355 | wufc &= ~ATL1_WUFC_LNKC; |
| 2356 | |
| 2357 | /* reduce speed to 10/100M */ |
| 2358 | if (wufc) { |
| 2359 | atl1_phy_enter_power_saving(hw); |
| 2360 | /* if resume, let driver to re- setup link */ |
| 2361 | hw->phy_configured = false; |
| 2362 | atl1_set_mac_addr(hw); |
| 2363 | atl1_set_multi(netdev); |
| 2364 | |
| 2365 | ctrl = 0; |
| 2366 | /* turn on magic packet wol */ |
| 2367 | if (wufc & ATL1_WUFC_MAG) |
| 2368 | ctrl = WOL_MAGIC_EN | WOL_MAGIC_PME_EN; |
| 2369 | |
| 2370 | /* turn on Link change WOL */ |
| 2371 | if (wufc & ATL1_WUFC_LNKC) |
| 2372 | ctrl |= (WOL_LINK_CHG_EN | WOL_LINK_CHG_PME_EN); |
| 2373 | iowrite32(ctrl, hw->hw_addr + REG_WOL_CTRL); |
| 2374 | |
| 2375 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 2376 | ctrl = ioread32(hw->hw_addr + REG_MAC_CTRL); |
| 2377 | ctrl &= ~MAC_CTRL_DBG; |
| 2378 | ctrl &= ~MAC_CTRL_PROMIS_EN; |
| 2379 | if (wufc & ATL1_WUFC_MC) |
| 2380 | ctrl |= MAC_CTRL_MC_ALL_EN; |
| 2381 | else |
| 2382 | ctrl &= ~MAC_CTRL_MC_ALL_EN; |
| 2383 | |
| 2384 | /* turn on broadcast mode if wake on-BC is enabled */ |
| 2385 | if (wufc & ATL1_WUFC_BC) |
| 2386 | ctrl |= MAC_CTRL_BC_EN; |
| 2387 | else |
| 2388 | ctrl &= ~MAC_CTRL_BC_EN; |
| 2389 | |
| 2390 | /* enable RX */ |
| 2391 | ctrl |= MAC_CTRL_RX_EN; |
| 2392 | iowrite32(ctrl, hw->hw_addr + REG_MAC_CTRL); |
| 2393 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 2394 | pci_enable_wake(pdev, PCI_D3cold, 1); /* 4 == D3 cold */ |
| 2395 | } else { |
| 2396 | iowrite32(0, hw->hw_addr + REG_WOL_CTRL); |
| 2397 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 2398 | pci_enable_wake(pdev, PCI_D3cold, 0); /* 4 == D3 cold */ |
| 2399 | } |
| 2400 | |
| 2401 | pci_save_state(pdev); |
| 2402 | pci_disable_device(pdev); |
| 2403 | |
| 2404 | pci_set_power_state(pdev, PCI_D3hot); |
| 2405 | |
| 2406 | return 0; |
| 2407 | } |
| 2408 | |
| 2409 | static int atl1_resume(struct pci_dev *pdev) |
| 2410 | { |
| 2411 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2412 | struct atl1_adapter *adapter = netdev_priv(netdev); |
| 2413 | u32 ret_val; |
| 2414 | |
| 2415 | pci_set_power_state(pdev, 0); |
| 2416 | pci_restore_state(pdev); |
| 2417 | |
| 2418 | ret_val = pci_enable_device(pdev); |
| 2419 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 2420 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 2421 | |
| 2422 | iowrite32(0, adapter->hw.hw_addr + REG_WOL_CTRL); |
| 2423 | atl1_reset(adapter); |
| 2424 | |
| 2425 | if (netif_running(netdev)) |
| 2426 | atl1_up(adapter); |
| 2427 | netif_device_attach(netdev); |
| 2428 | |
| 2429 | atl1_via_workaround(adapter); |
| 2430 | |
| 2431 | return 0; |
| 2432 | } |
| 2433 | #else |
| 2434 | #define atl1_suspend NULL |
| 2435 | #define atl1_resume NULL |
| 2436 | #endif |
| 2437 | |
| 2438 | static struct pci_driver atl1_driver = { |
| 2439 | .name = atl1_driver_name, |
| 2440 | .id_table = atl1_pci_tbl, |
| 2441 | .probe = atl1_probe, |
| 2442 | .remove = __devexit_p(atl1_remove), |
| 2443 | /* Power Managment Hooks */ |
| 2444 | /* probably broken right now -- CHS */ |
| 2445 | .suspend = atl1_suspend, |
| 2446 | .resume = atl1_resume |
| 2447 | }; |
| 2448 | |
| 2449 | /* |
| 2450 | * atl1_exit_module - Driver Exit Cleanup Routine |
| 2451 | * |
| 2452 | * atl1_exit_module is called just before the driver is removed |
| 2453 | * from memory. |
| 2454 | */ |
| 2455 | static void __exit atl1_exit_module(void) |
| 2456 | { |
| 2457 | pci_unregister_driver(&atl1_driver); |
| 2458 | } |
| 2459 | |
| 2460 | /* |
| 2461 | * atl1_init_module - Driver Registration Routine |
| 2462 | * |
| 2463 | * atl1_init_module is the first routine called when the driver is |
| 2464 | * loaded. All it does is register with the PCI subsystem. |
| 2465 | */ |
| 2466 | static int __init atl1_init_module(void) |
| 2467 | { |
| 2468 | printk(KERN_INFO "%s - version %s\n", atl1_driver_string, DRIVER_VERSION); |
| 2469 | printk(KERN_INFO "%s\n", atl1_copyright); |
| 2470 | return pci_register_driver(&atl1_driver); |
| 2471 | } |
| 2472 | |
| 2473 | module_init(atl1_init_module); |
| 2474 | module_exit(atl1_exit_module); |