blob: 6aa2dc32727ec6c53cddc682b48e23bbb4304f33 [file] [log] [blame]
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001/*
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.
Jay Cliburn53ffb422007-07-15 11:03:27 -050041 * Add more ethtool functions.
Jay Cliburnf3cc28c2007-02-08 10:42:37 -050042 * 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>
Al Virod3676752007-07-17 08:49:35 +010078#include <linux/interrupt.h>
Jay Cliburnf3cc28c2007-02-08 10:42:37 -050079#include <net/checksum.h>
80
81#include <asm/atomic.h>
82#include <asm/byteorder.h>
83
84#include "atl1.h"
85
Jay Cliburn9cc6d142007-02-14 20:18:05 -060086#define DRIVER_VERSION "2.0.7"
Jay Cliburnf3cc28c2007-02-08 10:42:37 -050087
88char atl1_driver_name[] = "atl1";
89static const char atl1_driver_string[] = "Attansic L1 Ethernet Network Driver";
90static const char atl1_copyright[] = "Copyright(c) 2005-2006 Attansic Corporation.";
91char atl1_driver_version[] = DRIVER_VERSION;
92
93MODULE_AUTHOR
94 ("Attansic Corporation <xiong_huang@attansic.com>, Chris Snook <csnook@redhat.com>, Jay Cliburn <jcliburn@gmail.com>");
95MODULE_DESCRIPTION("Attansic 1000M Ethernet Network Driver");
96MODULE_LICENSE("GPL");
97MODULE_VERSION(DRIVER_VERSION);
98
99/*
100 * atl1_pci_tbl - PCI Device ID Table
101 */
102static const struct pci_device_id atl1_pci_tbl[] = {
Chris Snooke81e5572007-02-14 20:17:01 -0600103 {PCI_DEVICE(PCI_VENDOR_ID_ATTANSIC, PCI_DEVICE_ID_ATTANSIC_L1)},
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500104 /* required last entry */
105 {0,}
106};
107
108MODULE_DEVICE_TABLE(pci, atl1_pci_tbl);
109
110/*
111 * atl1_sw_init - Initialize general software structures (struct atl1_adapter)
112 * @adapter: board private structure to initialize
113 *
114 * atl1_sw_init initializes the Adapter private data structure.
115 * Fields are initialized based on PCI device information and
116 * OS network device settings (MTU size).
117 */
118static int __devinit atl1_sw_init(struct atl1_adapter *adapter)
119{
120 struct atl1_hw *hw = &adapter->hw;
121 struct net_device *netdev = adapter->netdev;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500122
123 hw->max_frame_size = netdev->mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
124 hw->min_frame_size = MINIMUM_ETHERNET_FRAME_SIZE;
125
126 adapter->wol = 0;
127 adapter->rx_buffer_len = (hw->max_frame_size + 7) & ~7;
128 adapter->ict = 50000; /* 100ms */
129 adapter->link_speed = SPEED_0; /* hardware init */
130 adapter->link_duplex = FULL_DUPLEX;
131
132 hw->phy_configured = false;
133 hw->preamble_len = 7;
134 hw->ipgt = 0x60;
135 hw->min_ifg = 0x50;
136 hw->ipgr1 = 0x40;
137 hw->ipgr2 = 0x60;
138 hw->max_retry = 0xf;
139 hw->lcol = 0x37;
140 hw->jam_ipg = 7;
141 hw->rfd_burst = 8;
142 hw->rrd_burst = 8;
143 hw->rfd_fetch_gap = 1;
144 hw->rx_jumbo_th = adapter->rx_buffer_len / 8;
145 hw->rx_jumbo_lkah = 1;
146 hw->rrd_ret_timer = 16;
147 hw->tpd_burst = 4;
148 hw->tpd_fetch_th = 16;
149 hw->txf_burst = 0x100;
150 hw->tx_jumbo_task_th = (hw->max_frame_size + 7) >> 3;
151 hw->tpd_fetch_gap = 1;
152 hw->rcb_value = atl1_rcb_64;
153 hw->dma_ord = atl1_dma_ord_enh;
154 hw->dmar_block = atl1_dma_req_256;
155 hw->dmaw_block = atl1_dma_req_256;
156 hw->cmb_rrd = 4;
157 hw->cmb_tpd = 4;
158 hw->cmb_rx_timer = 1; /* about 2us */
159 hw->cmb_tx_timer = 1; /* about 2us */
160 hw->smb_timer = 100000; /* about 200ms */
161
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500162 spin_lock_init(&adapter->lock);
163 spin_lock_init(&adapter->mb_lock);
164
165 return 0;
166}
167
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500168static int mdio_read(struct net_device *netdev, int phy_id, int reg_num)
169{
170 struct atl1_adapter *adapter = netdev_priv(netdev);
171 u16 result;
172
173 atl1_read_phy_reg(&adapter->hw, reg_num & 0x1f, &result);
174
175 return result;
176}
177
178static void mdio_write(struct net_device *netdev, int phy_id, int reg_num,
179 int val)
180{
181 struct atl1_adapter *adapter = netdev_priv(netdev);
182
183 atl1_write_phy_reg(&adapter->hw, reg_num, val);
184}
185
186/*
187 * atl1_mii_ioctl -
188 * @netdev:
189 * @ifreq:
190 * @cmd:
191 */
192static int atl1_mii_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
193{
194 struct atl1_adapter *adapter = netdev_priv(netdev);
195 unsigned long flags;
196 int retval;
197
198 if (!netif_running(netdev))
199 return -EINVAL;
200
201 spin_lock_irqsave(&adapter->lock, flags);
202 retval = generic_mii_ioctl(&adapter->mii, if_mii(ifr), cmd, NULL);
203 spin_unlock_irqrestore(&adapter->lock, flags);
204
205 return retval;
206}
207
208/*
209 * atl1_ioctl -
210 * @netdev:
211 * @ifreq:
212 * @cmd:
213 */
214static int atl1_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
215{
216 switch (cmd) {
217 case SIOCGMIIPHY:
218 case SIOCGMIIREG:
219 case SIOCSMIIREG:
220 return atl1_mii_ioctl(netdev, ifr, cmd);
221 default:
222 return -EOPNOTSUPP;
223 }
224}
225
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500226/*
227 * atl1_setup_mem_resources - allocate Tx / RX descriptor resources
228 * @adapter: board private structure
229 *
230 * Return 0 on success, negative on failure
231 */
232s32 atl1_setup_ring_resources(struct atl1_adapter *adapter)
233{
234 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
235 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
236 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
237 struct atl1_ring_header *ring_header = &adapter->ring_header;
238 struct pci_dev *pdev = adapter->pdev;
239 int size;
240 u8 offset = 0;
241
242 size = sizeof(struct atl1_buffer) * (tpd_ring->count + rfd_ring->count);
243 tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL);
244 if (unlikely(!tpd_ring->buffer_info)) {
Jay Cliburn1e006362007-04-29 21:42:10 -0500245 dev_err(&pdev->dev, "kzalloc failed , size = D%d\n", size);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500246 goto err_nomem;
247 }
248 rfd_ring->buffer_info =
Jay Cliburn53ffb422007-07-15 11:03:27 -0500249 (struct atl1_buffer *)(tpd_ring->buffer_info + tpd_ring->count);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500250
Jay Cliburn53ffb422007-07-15 11:03:27 -0500251 /* real ring DMA buffer
252 * each ring/block may need up to 8 bytes for alignment, hence the
253 * additional 40 bytes tacked onto the end.
254 */
255 ring_header->size = size =
256 sizeof(struct tx_packet_desc) * tpd_ring->count
257 + sizeof(struct rx_free_desc) * rfd_ring->count
258 + sizeof(struct rx_return_desc) * rrd_ring->count
259 + sizeof(struct coals_msg_block)
260 + sizeof(struct stats_msg_block)
261 + 40;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500262
263 ring_header->desc = pci_alloc_consistent(pdev, ring_header->size,
Jay Cliburn53ffb422007-07-15 11:03:27 -0500264 &ring_header->dma);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500265 if (unlikely(!ring_header->desc)) {
Jay Cliburn1e006362007-04-29 21:42:10 -0500266 dev_err(&pdev->dev, "pci_alloc_consistent failed\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500267 goto err_nomem;
268 }
269
270 memset(ring_header->desc, 0, ring_header->size);
271
272 /* init TPD ring */
273 tpd_ring->dma = ring_header->dma;
274 offset = (tpd_ring->dma & 0x7) ? (8 - (ring_header->dma & 0x7)) : 0;
275 tpd_ring->dma += offset;
276 tpd_ring->desc = (u8 *) ring_header->desc + offset;
277 tpd_ring->size = sizeof(struct tx_packet_desc) * tpd_ring->count;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500278
279 /* init RFD ring */
280 rfd_ring->dma = tpd_ring->dma + tpd_ring->size;
281 offset = (rfd_ring->dma & 0x7) ? (8 - (rfd_ring->dma & 0x7)) : 0;
282 rfd_ring->dma += offset;
283 rfd_ring->desc = (u8 *) tpd_ring->desc + (tpd_ring->size + offset);
284 rfd_ring->size = sizeof(struct rx_free_desc) * rfd_ring->count;
Jay Cliburn2ca13da2007-07-15 11:03:28 -0500285
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500286
287 /* init RRD ring */
288 rrd_ring->dma = rfd_ring->dma + rfd_ring->size;
289 offset = (rrd_ring->dma & 0x7) ? (8 - (rrd_ring->dma & 0x7)) : 0;
290 rrd_ring->dma += offset;
291 rrd_ring->desc = (u8 *) rfd_ring->desc + (rfd_ring->size + offset);
292 rrd_ring->size = sizeof(struct rx_return_desc) * rrd_ring->count;
Jay Cliburn2ca13da2007-07-15 11:03:28 -0500293
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500294
295 /* init CMB */
296 adapter->cmb.dma = rrd_ring->dma + rrd_ring->size;
297 offset = (adapter->cmb.dma & 0x7) ? (8 - (adapter->cmb.dma & 0x7)) : 0;
298 adapter->cmb.dma += offset;
Jay Cliburn53ffb422007-07-15 11:03:27 -0500299 adapter->cmb.cmb = (struct coals_msg_block *)
300 ((u8 *) rrd_ring->desc + (rrd_ring->size + offset));
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500301
302 /* init SMB */
303 adapter->smb.dma = adapter->cmb.dma + sizeof(struct coals_msg_block);
304 offset = (adapter->smb.dma & 0x7) ? (8 - (adapter->smb.dma & 0x7)) : 0;
305 adapter->smb.dma += offset;
306 adapter->smb.smb = (struct stats_msg_block *)
Jay Cliburn53ffb422007-07-15 11:03:27 -0500307 ((u8 *) adapter->cmb.cmb +
308 (sizeof(struct coals_msg_block) + offset));
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500309
310 return ATL1_SUCCESS;
311
312err_nomem:
313 kfree(tpd_ring->buffer_info);
314 return -ENOMEM;
315}
316
Jay Cliburn2ca13da2007-07-15 11:03:28 -0500317void atl1_init_ring_ptrs(struct atl1_adapter *adapter)
318{
319 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
320 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
321 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
322
323 atomic_set(&tpd_ring->next_to_use, 0);
324 atomic_set(&tpd_ring->next_to_clean, 0);
325
326 rfd_ring->next_to_clean = 0;
327 atomic_set(&rfd_ring->next_to_use, 0);
328
329 rrd_ring->next_to_use = 0;
330 atomic_set(&rrd_ring->next_to_clean, 0);
331}
332
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500333/*
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500334 * atl1_clean_rx_ring - Free RFD Buffers
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500335 * @adapter: board private structure
336 */
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500337static void atl1_clean_rx_ring(struct atl1_adapter *adapter)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500338{
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500339 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
340 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
341 struct atl1_buffer *buffer_info;
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500342 struct pci_dev *pdev = adapter->pdev;
343 unsigned long size;
344 unsigned int i;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500345
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500346 /* Free all the Rx ring sk_buffs */
347 for (i = 0; i < rfd_ring->count; i++) {
348 buffer_info = &rfd_ring->buffer_info[i];
349 if (buffer_info->dma) {
350 pci_unmap_page(pdev, buffer_info->dma,
351 buffer_info->length, PCI_DMA_FROMDEVICE);
352 buffer_info->dma = 0;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500353 }
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500354 if (buffer_info->skb) {
355 dev_kfree_skb(buffer_info->skb);
356 buffer_info->skb = NULL;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500357 }
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500358 }
359
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500360 size = sizeof(struct atl1_buffer) * rfd_ring->count;
361 memset(rfd_ring->buffer_info, 0, size);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500362
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500363 /* Zero out the descriptor ring */
364 memset(rfd_ring->desc, 0, rfd_ring->size);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500365
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500366 rfd_ring->next_to_clean = 0;
367 atomic_set(&rfd_ring->next_to_use, 0);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500368
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500369 rrd_ring->next_to_use = 0;
370 atomic_set(&rrd_ring->next_to_clean, 0);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500371}
372
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500373/*
374 * atl1_clean_tx_ring - Free Tx Buffers
375 * @adapter: board private structure
376 */
377static void atl1_clean_tx_ring(struct atl1_adapter *adapter)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500378{
379 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
380 struct atl1_buffer *buffer_info;
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500381 struct pci_dev *pdev = adapter->pdev;
382 unsigned long size;
383 unsigned int i;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500384
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500385 /* Free all the Tx ring sk_buffs */
386 for (i = 0; i < tpd_ring->count; i++) {
387 buffer_info = &tpd_ring->buffer_info[i];
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500388 if (buffer_info->dma) {
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500389 pci_unmap_page(pdev, buffer_info->dma,
390 buffer_info->length, PCI_DMA_TODEVICE);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500391 buffer_info->dma = 0;
392 }
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500393 }
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500394
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500395 for (i = 0; i < tpd_ring->count; i++) {
396 buffer_info = &tpd_ring->buffer_info[i];
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500397 if (buffer_info->skb) {
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500398 dev_kfree_skb_any(buffer_info->skb);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500399 buffer_info->skb = NULL;
400 }
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500401 }
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500402
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500403 size = sizeof(struct atl1_buffer) * tpd_ring->count;
404 memset(tpd_ring->buffer_info, 0, size);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500405
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500406 /* Zero out the descriptor ring */
407 memset(tpd_ring->desc, 0, tpd_ring->size);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500408
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500409 atomic_set(&tpd_ring->next_to_use, 0);
410 atomic_set(&tpd_ring->next_to_clean, 0);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500411}
412
413/*
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500414 * atl1_free_ring_resources - Free Tx / RX descriptor Resources
415 * @adapter: board private structure
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500416 *
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500417 * Free all transmit software resources
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500418 */
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500419void atl1_free_ring_resources(struct atl1_adapter *adapter)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500420{
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500421 struct pci_dev *pdev = adapter->pdev;
422 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
423 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
424 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
425 struct atl1_ring_header *ring_header = &adapter->ring_header;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500426
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500427 atl1_clean_tx_ring(adapter);
428 atl1_clean_rx_ring(adapter);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500429
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500430 kfree(tpd_ring->buffer_info);
431 pci_free_consistent(pdev, ring_header->size, ring_header->desc,
432 ring_header->dma);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500433
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500434 tpd_ring->buffer_info = NULL;
435 tpd_ring->desc = NULL;
436 tpd_ring->dma = 0;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500437
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500438 rfd_ring->buffer_info = NULL;
439 rfd_ring->desc = NULL;
440 rfd_ring->dma = 0;
441
442 rrd_ring->desc = NULL;
443 rrd_ring->dma = 0;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500444}
445
446static void atl1_setup_mac_ctrl(struct atl1_adapter *adapter)
447{
448 u32 value;
449 struct atl1_hw *hw = &adapter->hw;
450 struct net_device *netdev = adapter->netdev;
451 /* Config MAC CTRL Register */
452 value = MAC_CTRL_TX_EN | MAC_CTRL_RX_EN;
453 /* duplex */
454 if (FULL_DUPLEX == adapter->link_duplex)
455 value |= MAC_CTRL_DUPLX;
456 /* speed */
457 value |= ((u32) ((SPEED_1000 == adapter->link_speed) ?
458 MAC_CTRL_SPEED_1000 : MAC_CTRL_SPEED_10_100) <<
459 MAC_CTRL_SPEED_SHIFT);
460 /* flow control */
461 value |= (MAC_CTRL_TX_FLOW | MAC_CTRL_RX_FLOW);
462 /* PAD & CRC */
463 value |= (MAC_CTRL_ADD_CRC | MAC_CTRL_PAD);
464 /* preamble length */
465 value |= (((u32) adapter->hw.preamble_len
466 & MAC_CTRL_PRMLEN_MASK) << MAC_CTRL_PRMLEN_SHIFT);
467 /* vlan */
468 if (adapter->vlgrp)
469 value |= MAC_CTRL_RMV_VLAN;
470 /* rx checksum
471 if (adapter->rx_csum)
472 value |= MAC_CTRL_RX_CHKSUM_EN;
473 */
474 /* filter mode */
475 value |= MAC_CTRL_BC_EN;
476 if (netdev->flags & IFF_PROMISC)
477 value |= MAC_CTRL_PROMIS_EN;
478 else if (netdev->flags & IFF_ALLMULTI)
479 value |= MAC_CTRL_MC_ALL_EN;
480 /* value |= MAC_CTRL_LOOPBACK; */
481 iowrite32(value, hw->hw_addr + REG_MAC_CTRL);
482}
483
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500484/*
485 * atl1_set_mac - Change the Ethernet Address of the NIC
486 * @netdev: network interface device structure
487 * @p: pointer to an address structure
488 *
489 * Returns 0 on success, negative on failure
490 */
491static int atl1_set_mac(struct net_device *netdev, void *p)
492{
493 struct atl1_adapter *adapter = netdev_priv(netdev);
494 struct sockaddr *addr = p;
495
496 if (netif_running(netdev))
497 return -EBUSY;
498
499 if (!is_valid_ether_addr(addr->sa_data))
500 return -EADDRNOTAVAIL;
501
502 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
503 memcpy(adapter->hw.mac_addr, addr->sa_data, netdev->addr_len);
504
505 atl1_set_mac_addr(&adapter->hw);
506 return 0;
507}
508
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500509static u32 atl1_check_link(struct atl1_adapter *adapter)
510{
511 struct atl1_hw *hw = &adapter->hw;
512 struct net_device *netdev = adapter->netdev;
513 u32 ret_val;
514 u16 speed, duplex, phy_data;
515 int reconfig = 0;
516
517 /* MII_BMSR must read twice */
518 atl1_read_phy_reg(hw, MII_BMSR, &phy_data);
519 atl1_read_phy_reg(hw, MII_BMSR, &phy_data);
520 if (!(phy_data & BMSR_LSTATUS)) { /* link down */
521 if (netif_carrier_ok(netdev)) { /* old link state: Up */
Jay Cliburn1e006362007-04-29 21:42:10 -0500522 dev_info(&adapter->pdev->dev, "link is down\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500523 adapter->link_speed = SPEED_0;
524 netif_carrier_off(netdev);
525 netif_stop_queue(netdev);
526 }
527 return ATL1_SUCCESS;
528 }
529
530 /* Link Up */
531 ret_val = atl1_get_speed_and_duplex(hw, &speed, &duplex);
532 if (ret_val)
533 return ret_val;
534
535 switch (hw->media_type) {
536 case MEDIA_TYPE_1000M_FULL:
537 if (speed != SPEED_1000 || duplex != FULL_DUPLEX)
538 reconfig = 1;
539 break;
540 case MEDIA_TYPE_100M_FULL:
541 if (speed != SPEED_100 || duplex != FULL_DUPLEX)
542 reconfig = 1;
543 break;
544 case MEDIA_TYPE_100M_HALF:
545 if (speed != SPEED_100 || duplex != HALF_DUPLEX)
546 reconfig = 1;
547 break;
548 case MEDIA_TYPE_10M_FULL:
549 if (speed != SPEED_10 || duplex != FULL_DUPLEX)
550 reconfig = 1;
551 break;
552 case MEDIA_TYPE_10M_HALF:
553 if (speed != SPEED_10 || duplex != HALF_DUPLEX)
554 reconfig = 1;
555 break;
556 }
557
558 /* link result is our setting */
559 if (!reconfig) {
560 if (adapter->link_speed != speed
561 || adapter->link_duplex != duplex) {
562 adapter->link_speed = speed;
563 adapter->link_duplex = duplex;
564 atl1_setup_mac_ctrl(adapter);
Jay Cliburn1e006362007-04-29 21:42:10 -0500565 dev_info(&adapter->pdev->dev,
566 "%s link is up %d Mbps %s\n",
567 netdev->name, adapter->link_speed,
568 adapter->link_duplex == FULL_DUPLEX ?
569 "full duplex" : "half duplex");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500570 }
571 if (!netif_carrier_ok(netdev)) { /* Link down -> Up */
572 netif_carrier_on(netdev);
573 netif_wake_queue(netdev);
574 }
575 return ATL1_SUCCESS;
576 }
577
578 /* change orignal link status */
579 if (netif_carrier_ok(netdev)) {
580 adapter->link_speed = SPEED_0;
581 netif_carrier_off(netdev);
582 netif_stop_queue(netdev);
583 }
584
585 if (hw->media_type != MEDIA_TYPE_AUTO_SENSOR &&
586 hw->media_type != MEDIA_TYPE_1000M_FULL) {
587 switch (hw->media_type) {
588 case MEDIA_TYPE_100M_FULL:
589 phy_data = MII_CR_FULL_DUPLEX | MII_CR_SPEED_100 |
590 MII_CR_RESET;
591 break;
592 case MEDIA_TYPE_100M_HALF:
593 phy_data = MII_CR_SPEED_100 | MII_CR_RESET;
594 break;
595 case MEDIA_TYPE_10M_FULL:
596 phy_data =
597 MII_CR_FULL_DUPLEX | MII_CR_SPEED_10 | MII_CR_RESET;
598 break;
599 default: /* MEDIA_TYPE_10M_HALF: */
600 phy_data = MII_CR_SPEED_10 | MII_CR_RESET;
601 break;
602 }
603 atl1_write_phy_reg(hw, MII_BMCR, phy_data);
604 return ATL1_SUCCESS;
605 }
606
607 /* auto-neg, insert timer to re-config phy */
608 if (!adapter->phy_timer_pending) {
609 adapter->phy_timer_pending = true;
610 mod_timer(&adapter->phy_config_timer, jiffies + 3 * HZ);
611 }
612
613 return ATL1_SUCCESS;
614}
615
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500616static void atl1_check_for_link(struct atl1_adapter *adapter)
617{
618 struct net_device *netdev = adapter->netdev;
619 u16 phy_data = 0;
620
621 spin_lock(&adapter->lock);
622 adapter->phy_timer_pending = false;
623 atl1_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
624 atl1_read_phy_reg(&adapter->hw, MII_BMSR, &phy_data);
625 spin_unlock(&adapter->lock);
626
627 /* notify upper layer link down ASAP */
628 if (!(phy_data & BMSR_LSTATUS)) { /* Link Down */
629 if (netif_carrier_ok(netdev)) { /* old link state: Up */
630 dev_info(&adapter->pdev->dev, "%s link is down\n",
631 netdev->name);
632 adapter->link_speed = SPEED_0;
633 netif_carrier_off(netdev);
634 netif_stop_queue(netdev);
635 }
636 }
637 schedule_work(&adapter->link_chg_task);
638}
639
640/*
641 * atl1_set_multi - Multicast and Promiscuous mode set
642 * @netdev: network interface device structure
643 *
644 * The set_multi entry point is called whenever the multicast address
645 * list or the network interface flags are updated. This routine is
646 * responsible for configuring the hardware for proper multicast,
647 * promiscuous mode, and all-multi behavior.
648 */
649static void atl1_set_multi(struct net_device *netdev)
650{
651 struct atl1_adapter *adapter = netdev_priv(netdev);
652 struct atl1_hw *hw = &adapter->hw;
653 struct dev_mc_list *mc_ptr;
654 u32 rctl;
655 u32 hash_value;
656
657 /* Check for Promiscuous and All Multicast modes */
658 rctl = ioread32(hw->hw_addr + REG_MAC_CTRL);
659 if (netdev->flags & IFF_PROMISC)
660 rctl |= MAC_CTRL_PROMIS_EN;
661 else if (netdev->flags & IFF_ALLMULTI) {
662 rctl |= MAC_CTRL_MC_ALL_EN;
663 rctl &= ~MAC_CTRL_PROMIS_EN;
664 } else
665 rctl &= ~(MAC_CTRL_PROMIS_EN | MAC_CTRL_MC_ALL_EN);
666
667 iowrite32(rctl, hw->hw_addr + REG_MAC_CTRL);
668
669 /* clear the old settings from the multicast hash table */
670 iowrite32(0, hw->hw_addr + REG_RX_HASH_TABLE);
671 iowrite32(0, (hw->hw_addr + REG_RX_HASH_TABLE) + (1 << 2));
672
673 /* compute mc addresses' hash value ,and put it into hash table */
674 for (mc_ptr = netdev->mc_list; mc_ptr; mc_ptr = mc_ptr->next) {
675 hash_value = atl1_hash_mc_addr(hw, mc_ptr->dmi_addr);
676 atl1_hash_set(hw, hash_value);
677 }
678}
679
680/*
681 * atl1_change_mtu - Change the Maximum Transfer Unit
682 * @netdev: network interface device structure
683 * @new_mtu: new value for maximum frame size
684 *
685 * Returns 0 on success, negative on failure
686 */
687static int atl1_change_mtu(struct net_device *netdev, int new_mtu)
688{
689 struct atl1_adapter *adapter = netdev_priv(netdev);
690 int old_mtu = netdev->mtu;
691 int max_frame = new_mtu + ENET_HEADER_SIZE + ETHERNET_FCS_SIZE;
692
693 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
694 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
695 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
696 return -EINVAL;
697 }
698
699 adapter->hw.max_frame_size = max_frame;
700 adapter->hw.tx_jumbo_task_th = (max_frame + 7) >> 3;
701 adapter->rx_buffer_len = (max_frame + 7) & ~7;
702 adapter->hw.rx_jumbo_th = adapter->rx_buffer_len / 8;
703
704 netdev->mtu = new_mtu;
705 if ((old_mtu != new_mtu) && netif_running(netdev)) {
706 atl1_down(adapter);
707 atl1_up(adapter);
708 }
709
710 return 0;
711}
712
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500713static void set_flow_ctrl_old(struct atl1_adapter *adapter)
714{
715 u32 hi, lo, value;
716
717 /* RFD Flow Control */
718 value = adapter->rfd_ring.count;
719 hi = value / 16;
720 if (hi < 2)
721 hi = 2;
722 lo = value * 7 / 8;
723
724 value = ((hi & RXQ_RXF_PAUSE_TH_HI_MASK) << RXQ_RXF_PAUSE_TH_HI_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500725 ((lo & RXQ_RXF_PAUSE_TH_LO_MASK) << RXQ_RXF_PAUSE_TH_LO_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500726 iowrite32(value, adapter->hw.hw_addr + REG_RXQ_RXF_PAUSE_THRESH);
727
728 /* RRD Flow Control */
729 value = adapter->rrd_ring.count;
730 lo = value / 16;
731 hi = value * 7 / 8;
732 if (lo < 2)
733 lo = 2;
734 value = ((hi & RXQ_RRD_PAUSE_TH_HI_MASK) << RXQ_RRD_PAUSE_TH_HI_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500735 ((lo & RXQ_RRD_PAUSE_TH_LO_MASK) << RXQ_RRD_PAUSE_TH_LO_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500736 iowrite32(value, adapter->hw.hw_addr + REG_RXQ_RRD_PAUSE_THRESH);
737}
738
739static void set_flow_ctrl_new(struct atl1_hw *hw)
740{
741 u32 hi, lo, value;
742
743 /* RXF Flow Control */
744 value = ioread32(hw->hw_addr + REG_SRAM_RXF_LEN);
745 lo = value / 16;
746 if (lo < 192)
747 lo = 192;
748 hi = value * 7 / 8;
749 if (hi < lo)
750 hi = lo + 16;
751 value = ((hi & RXQ_RXF_PAUSE_TH_HI_MASK) << RXQ_RXF_PAUSE_TH_HI_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500752 ((lo & RXQ_RXF_PAUSE_TH_LO_MASK) << RXQ_RXF_PAUSE_TH_LO_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500753 iowrite32(value, hw->hw_addr + REG_RXQ_RXF_PAUSE_THRESH);
754
755 /* RRD Flow Control */
756 value = ioread32(hw->hw_addr + REG_SRAM_RRD_LEN);
757 lo = value / 8;
758 hi = value * 7 / 8;
759 if (lo < 2)
760 lo = 2;
761 if (hi < lo)
762 hi = lo + 3;
763 value = ((hi & RXQ_RRD_PAUSE_TH_HI_MASK) << RXQ_RRD_PAUSE_TH_HI_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500764 ((lo & RXQ_RRD_PAUSE_TH_LO_MASK) << RXQ_RRD_PAUSE_TH_LO_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500765 iowrite32(value, hw->hw_addr + REG_RXQ_RRD_PAUSE_THRESH);
766}
767
768/*
769 * atl1_configure - Configure Transmit&Receive Unit after Reset
770 * @adapter: board private structure
771 *
772 * Configure the Tx /Rx unit of the MAC after a reset.
773 */
774static u32 atl1_configure(struct atl1_adapter *adapter)
775{
776 struct atl1_hw *hw = &adapter->hw;
777 u32 value;
778
779 /* clear interrupt status */
780 iowrite32(0xffffffff, adapter->hw.hw_addr + REG_ISR);
781
782 /* set MAC Address */
783 value = (((u32) hw->mac_addr[2]) << 24) |
784 (((u32) hw->mac_addr[3]) << 16) |
785 (((u32) hw->mac_addr[4]) << 8) |
786 (((u32) hw->mac_addr[5]));
787 iowrite32(value, hw->hw_addr + REG_MAC_STA_ADDR);
788 value = (((u32) hw->mac_addr[0]) << 8) | (((u32) hw->mac_addr[1]));
789 iowrite32(value, hw->hw_addr + (REG_MAC_STA_ADDR + 4));
790
791 /* tx / rx ring */
792
793 /* HI base address */
794 iowrite32((u32) ((adapter->tpd_ring.dma & 0xffffffff00000000ULL) >> 32),
795 hw->hw_addr + REG_DESC_BASE_ADDR_HI);
796 /* LO base address */
797 iowrite32((u32) (adapter->rfd_ring.dma & 0x00000000ffffffffULL),
798 hw->hw_addr + REG_DESC_RFD_ADDR_LO);
799 iowrite32((u32) (adapter->rrd_ring.dma & 0x00000000ffffffffULL),
800 hw->hw_addr + REG_DESC_RRD_ADDR_LO);
801 iowrite32((u32) (adapter->tpd_ring.dma & 0x00000000ffffffffULL),
802 hw->hw_addr + REG_DESC_TPD_ADDR_LO);
803 iowrite32((u32) (adapter->cmb.dma & 0x00000000ffffffffULL),
804 hw->hw_addr + REG_DESC_CMB_ADDR_LO);
805 iowrite32((u32) (adapter->smb.dma & 0x00000000ffffffffULL),
806 hw->hw_addr + REG_DESC_SMB_ADDR_LO);
807
808 /* element count */
809 value = adapter->rrd_ring.count;
810 value <<= 16;
811 value += adapter->rfd_ring.count;
812 iowrite32(value, hw->hw_addr + REG_DESC_RFD_RRD_RING_SIZE);
Jay Cliburn2ca13da2007-07-15 11:03:28 -0500813 iowrite32(adapter->tpd_ring.count, hw->hw_addr +
814 REG_DESC_TPD_RING_SIZE);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500815
816 /* Load Ptr */
817 iowrite32(1, hw->hw_addr + REG_LOAD_PTR);
818
819 /* config Mailbox */
820 value = ((atomic_read(&adapter->tpd_ring.next_to_use)
821 & MB_TPD_PROD_INDX_MASK) << MB_TPD_PROD_INDX_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500822 ((atomic_read(&adapter->rrd_ring.next_to_clean)
823 & MB_RRD_CONS_INDX_MASK) << MB_RRD_CONS_INDX_SHIFT) |
824 ((atomic_read(&adapter->rfd_ring.next_to_use)
825 & MB_RFD_PROD_INDX_MASK) << MB_RFD_PROD_INDX_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500826 iowrite32(value, hw->hw_addr + REG_MAILBOX);
827
828 /* config IPG/IFG */
829 value = (((u32) hw->ipgt & MAC_IPG_IFG_IPGT_MASK)
830 << MAC_IPG_IFG_IPGT_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500831 (((u32) hw->min_ifg & MAC_IPG_IFG_MIFG_MASK)
832 << MAC_IPG_IFG_MIFG_SHIFT) |
833 (((u32) hw->ipgr1 & MAC_IPG_IFG_IPGR1_MASK)
834 << MAC_IPG_IFG_IPGR1_SHIFT) |
835 (((u32) hw->ipgr2 & MAC_IPG_IFG_IPGR2_MASK)
836 << MAC_IPG_IFG_IPGR2_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500837 iowrite32(value, hw->hw_addr + REG_MAC_IPG_IFG);
838
839 /* config Half-Duplex Control */
840 value = ((u32) hw->lcol & MAC_HALF_DUPLX_CTRL_LCOL_MASK) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500841 (((u32) hw->max_retry & MAC_HALF_DUPLX_CTRL_RETRY_MASK)
842 << MAC_HALF_DUPLX_CTRL_RETRY_SHIFT) |
843 MAC_HALF_DUPLX_CTRL_EXC_DEF_EN |
844 (0xa << MAC_HALF_DUPLX_CTRL_ABEBT_SHIFT) |
845 (((u32) hw->jam_ipg & MAC_HALF_DUPLX_CTRL_JAMIPG_MASK)
846 << MAC_HALF_DUPLX_CTRL_JAMIPG_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500847 iowrite32(value, hw->hw_addr + REG_MAC_HALF_DUPLX_CTRL);
848
849 /* set Interrupt Moderator Timer */
850 iowrite16(adapter->imt, hw->hw_addr + REG_IRQ_MODU_TIMER_INIT);
851 iowrite32(MASTER_CTRL_ITIMER_EN, hw->hw_addr + REG_MASTER_CTRL);
852
853 /* set Interrupt Clear Timer */
854 iowrite16(adapter->ict, hw->hw_addr + REG_CMBDISDMA_TIMER);
855
856 /* set MTU, 4 : VLAN */
857 iowrite32(hw->max_frame_size + 4, hw->hw_addr + REG_MTU);
858
859 /* jumbo size & rrd retirement timer */
860 value = (((u32) hw->rx_jumbo_th & RXQ_JMBOSZ_TH_MASK)
861 << RXQ_JMBOSZ_TH_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500862 (((u32) hw->rx_jumbo_lkah & RXQ_JMBO_LKAH_MASK)
863 << RXQ_JMBO_LKAH_SHIFT) |
864 (((u32) hw->rrd_ret_timer & RXQ_RRD_TIMER_MASK)
865 << RXQ_RRD_TIMER_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500866 iowrite32(value, hw->hw_addr + REG_RXQ_JMBOSZ_RRDTIM);
867
868 /* Flow Control */
869 switch (hw->dev_rev) {
870 case 0x8001:
871 case 0x9001:
872 case 0x9002:
873 case 0x9003:
874 set_flow_ctrl_old(adapter);
875 break;
876 default:
877 set_flow_ctrl_new(hw);
878 break;
879 }
880
881 /* config TXQ */
882 value = (((u32) hw->tpd_burst & TXQ_CTRL_TPD_BURST_NUM_MASK)
883 << TXQ_CTRL_TPD_BURST_NUM_SHIFT) |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500884 (((u32) hw->txf_burst & TXQ_CTRL_TXF_BURST_NUM_MASK)
885 << TXQ_CTRL_TXF_BURST_NUM_SHIFT) |
886 (((u32) hw->tpd_fetch_th & TXQ_CTRL_TPD_FETCH_TH_MASK)
887 << TXQ_CTRL_TPD_FETCH_TH_SHIFT) | TXQ_CTRL_ENH_MODE |
888 TXQ_CTRL_EN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500889 iowrite32(value, hw->hw_addr + REG_TXQ_CTRL);
890
891 /* min tpd fetch gap & tx jumbo packet size threshold for taskoffload */
892 value = (((u32) hw->tx_jumbo_task_th & TX_JUMBO_TASK_TH_MASK)
Jay Cliburn53ffb422007-07-15 11:03:27 -0500893 << TX_JUMBO_TASK_TH_SHIFT) |
894 (((u32) hw->tpd_fetch_gap & TX_TPD_MIN_IPG_MASK)
895 << TX_TPD_MIN_IPG_SHIFT);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500896 iowrite32(value, hw->hw_addr + REG_TX_JUMBO_TASK_TH_TPD_IPG);
897
898 /* config RXQ */
899 value = (((u32) hw->rfd_burst & RXQ_CTRL_RFD_BURST_NUM_MASK)
Jay Cliburn53ffb422007-07-15 11:03:27 -0500900 << RXQ_CTRL_RFD_BURST_NUM_SHIFT) |
901 (((u32) hw->rrd_burst & RXQ_CTRL_RRD_BURST_THRESH_MASK)
902 << RXQ_CTRL_RRD_BURST_THRESH_SHIFT) |
903 (((u32) hw->rfd_fetch_gap & RXQ_CTRL_RFD_PREF_MIN_IPG_MASK)
904 << RXQ_CTRL_RFD_PREF_MIN_IPG_SHIFT) | RXQ_CTRL_CUT_THRU_EN |
905 RXQ_CTRL_EN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500906 iowrite32(value, hw->hw_addr + REG_RXQ_CTRL);
907
908 /* config DMA Engine */
909 value = ((((u32) hw->dmar_block) & DMA_CTRL_DMAR_BURST_LEN_MASK)
Jay Cliburn53ffb422007-07-15 11:03:27 -0500910 << DMA_CTRL_DMAR_BURST_LEN_SHIFT) |
Jay Cliburn3f516c02007-07-19 18:45:11 -0500911 ((((u32) hw->dmaw_block) & DMA_CTRL_DMAW_BURST_LEN_MASK)
912 << DMA_CTRL_DMAW_BURST_LEN_SHIFT) | DMA_CTRL_DMAR_EN |
Jay Cliburn53ffb422007-07-15 11:03:27 -0500913 DMA_CTRL_DMAW_EN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500914 value |= (u32) hw->dma_ord;
915 if (atl1_rcb_128 == hw->rcb_value)
916 value |= DMA_CTRL_RCB_VALUE;
917 iowrite32(value, hw->hw_addr + REG_DMA_CTRL);
918
919 /* config CMB / SMB */
Jay Cliburn91a500a2007-07-19 18:45:12 -0500920 value = (hw->cmb_tpd > adapter->tpd_ring.count) ?
921 hw->cmb_tpd : adapter->tpd_ring.count;
922 value <<= 16;
923 value |= hw->cmb_rrd;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500924 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TH);
925 value = hw->cmb_rx_timer | ((u32) hw->cmb_tx_timer << 16);
926 iowrite32(value, hw->hw_addr + REG_CMB_WRITE_TIMER);
927 iowrite32(hw->smb_timer, hw->hw_addr + REG_SMB_TIMER);
928
929 /* --- enable CMB / SMB */
930 value = CSMB_CTRL_CMB_EN | CSMB_CTRL_SMB_EN;
931 iowrite32(value, hw->hw_addr + REG_CSMB_CTRL);
932
933 value = ioread32(adapter->hw.hw_addr + REG_ISR);
934 if (unlikely((value & ISR_PHY_LINKDOWN) != 0))
935 value = 1; /* config failed */
936 else
937 value = 0;
938
939 /* clear all interrupt status */
940 iowrite32(0x3fffffff, adapter->hw.hw_addr + REG_ISR);
941 iowrite32(0, adapter->hw.hw_addr + REG_ISR);
942 return value;
943}
944
945/*
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500946 * atl1_pcie_patch - Patch for PCIE module
947 */
948static void atl1_pcie_patch(struct atl1_adapter *adapter)
949{
950 u32 value;
951
952 /* much vendor magic here */
953 value = 0x6500;
954 iowrite32(value, adapter->hw.hw_addr + 0x12FC);
955 /* pcie flow control mode change */
956 value = ioread32(adapter->hw.hw_addr + 0x1008);
957 value |= 0x8000;
958 iowrite32(value, adapter->hw.hw_addr + 0x1008);
959}
960
961/*
962 * When ACPI resume on some VIA MotherBoard, the Interrupt Disable bit/0x400
963 * on PCI Command register is disable.
964 * The function enable this bit.
965 * Brackett, 2006/03/15
966 */
967static void atl1_via_workaround(struct atl1_adapter *adapter)
968{
969 unsigned long value;
970
971 value = ioread16(adapter->hw.hw_addr + PCI_COMMAND);
972 if (value & PCI_COMMAND_INTX_DISABLE)
973 value &= ~PCI_COMMAND_INTX_DISABLE;
974 iowrite32(value, adapter->hw.hw_addr + PCI_COMMAND);
975}
976
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500977/*
978 * atl1_irq_enable - Enable default interrupt generation settings
979 * @adapter: board private structure
980 */
981static void atl1_irq_enable(struct atl1_adapter *adapter)
982{
Jay Cliburn05ffdd72007-07-15 11:03:29 -0500983 iowrite32(IMR_NORMAL_MASK, adapter->hw.hw_addr + REG_IMR);
984 ioread32(adapter->hw.hw_addr + REG_IMR);
985}
986
987/*
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500988 * atl1_irq_disable - Mask off interrupt generation on the NIC
989 * @adapter: board private structure
990 */
991static void atl1_irq_disable(struct atl1_adapter *adapter)
992{
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500993 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
994 ioread32(adapter->hw.hw_addr + REG_IMR);
995 synchronize_irq(adapter->pdev->irq);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -0500996}
997
998static void atl1_clear_phy_int(struct atl1_adapter *adapter)
999{
1000 u16 phy_data;
1001 unsigned long flags;
1002
1003 spin_lock_irqsave(&adapter->lock, flags);
1004 atl1_read_phy_reg(&adapter->hw, 19, &phy_data);
1005 spin_unlock_irqrestore(&adapter->lock, flags);
1006}
1007
1008static void atl1_inc_smb(struct atl1_adapter *adapter)
1009{
1010 struct stats_msg_block *smb = adapter->smb.smb;
1011
1012 /* Fill out the OS statistics structure */
1013 adapter->soft_stats.rx_packets += smb->rx_ok;
1014 adapter->soft_stats.tx_packets += smb->tx_ok;
1015 adapter->soft_stats.rx_bytes += smb->rx_byte_cnt;
1016 adapter->soft_stats.tx_bytes += smb->tx_byte_cnt;
1017 adapter->soft_stats.multicast += smb->rx_mcast;
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001018 adapter->soft_stats.collisions += (smb->tx_1_col + smb->tx_2_col * 2 +
1019 smb->tx_late_col + smb->tx_abort_col * adapter->hw.max_retry);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001020
1021 /* Rx Errors */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001022 adapter->soft_stats.rx_errors += (smb->rx_frag + smb->rx_fcs_err +
1023 smb->rx_len_err + smb->rx_sz_ov + smb->rx_rxf_ov +
1024 smb->rx_rrd_ov + smb->rx_align_err);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001025 adapter->soft_stats.rx_fifo_errors += smb->rx_rxf_ov;
1026 adapter->soft_stats.rx_length_errors += smb->rx_len_err;
1027 adapter->soft_stats.rx_crc_errors += smb->rx_fcs_err;
1028 adapter->soft_stats.rx_frame_errors += smb->rx_align_err;
1029 adapter->soft_stats.rx_missed_errors += (smb->rx_rrd_ov +
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001030 smb->rx_rxf_ov);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001031
1032 adapter->soft_stats.rx_pause += smb->rx_pause;
1033 adapter->soft_stats.rx_rrd_ov += smb->rx_rrd_ov;
1034 adapter->soft_stats.rx_trunc += smb->rx_sz_ov;
1035
1036 /* Tx Errors */
1037 adapter->soft_stats.tx_errors += (smb->tx_late_col +
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001038 smb->tx_abort_col + smb->tx_underrun + smb->tx_trunc);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001039 adapter->soft_stats.tx_fifo_errors += smb->tx_underrun;
1040 adapter->soft_stats.tx_aborted_errors += smb->tx_abort_col;
1041 adapter->soft_stats.tx_window_errors += smb->tx_late_col;
1042
1043 adapter->soft_stats.excecol += smb->tx_abort_col;
1044 adapter->soft_stats.deffer += smb->tx_defer;
1045 adapter->soft_stats.scc += smb->tx_1_col;
1046 adapter->soft_stats.mcc += smb->tx_2_col;
1047 adapter->soft_stats.latecol += smb->tx_late_col;
1048 adapter->soft_stats.tx_underun += smb->tx_underrun;
1049 adapter->soft_stats.tx_trunc += smb->tx_trunc;
1050 adapter->soft_stats.tx_pause += smb->tx_pause;
1051
1052 adapter->net_stats.rx_packets = adapter->soft_stats.rx_packets;
1053 adapter->net_stats.tx_packets = adapter->soft_stats.tx_packets;
1054 adapter->net_stats.rx_bytes = adapter->soft_stats.rx_bytes;
1055 adapter->net_stats.tx_bytes = adapter->soft_stats.tx_bytes;
1056 adapter->net_stats.multicast = adapter->soft_stats.multicast;
1057 adapter->net_stats.collisions = adapter->soft_stats.collisions;
1058 adapter->net_stats.rx_errors = adapter->soft_stats.rx_errors;
1059 adapter->net_stats.rx_over_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001060 adapter->soft_stats.rx_missed_errors;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001061 adapter->net_stats.rx_length_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001062 adapter->soft_stats.rx_length_errors;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001063 adapter->net_stats.rx_crc_errors = adapter->soft_stats.rx_crc_errors;
1064 adapter->net_stats.rx_frame_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001065 adapter->soft_stats.rx_frame_errors;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001066 adapter->net_stats.rx_fifo_errors = adapter->soft_stats.rx_fifo_errors;
1067 adapter->net_stats.rx_missed_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001068 adapter->soft_stats.rx_missed_errors;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001069 adapter->net_stats.tx_errors = adapter->soft_stats.tx_errors;
1070 adapter->net_stats.tx_fifo_errors = adapter->soft_stats.tx_fifo_errors;
1071 adapter->net_stats.tx_aborted_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001072 adapter->soft_stats.tx_aborted_errors;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001073 adapter->net_stats.tx_window_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001074 adapter->soft_stats.tx_window_errors;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001075 adapter->net_stats.tx_carrier_errors =
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001076 adapter->soft_stats.tx_carrier_errors;
1077}
1078
1079/*
1080 * atl1_get_stats - Get System Network Statistics
1081 * @netdev: network interface device structure
1082 *
1083 * Returns the address of the device statistics structure.
1084 * The statistics are actually updated from the timer callback.
1085 */
1086static struct net_device_stats *atl1_get_stats(struct net_device *netdev)
1087{
1088 struct atl1_adapter *adapter = netdev_priv(netdev);
1089 return &adapter->net_stats;
1090}
1091
1092static void atl1_update_mailbox(struct atl1_adapter *adapter)
1093{
1094 unsigned long flags;
1095 u32 tpd_next_to_use;
1096 u32 rfd_next_to_use;
1097 u32 rrd_next_to_clean;
1098 u32 value;
1099
1100 spin_lock_irqsave(&adapter->mb_lock, flags);
1101
1102 tpd_next_to_use = atomic_read(&adapter->tpd_ring.next_to_use);
1103 rfd_next_to_use = atomic_read(&adapter->rfd_ring.next_to_use);
1104 rrd_next_to_clean = atomic_read(&adapter->rrd_ring.next_to_clean);
1105
1106 value = ((rfd_next_to_use & MB_RFD_PROD_INDX_MASK) <<
1107 MB_RFD_PROD_INDX_SHIFT) |
1108 ((rrd_next_to_clean & MB_RRD_CONS_INDX_MASK) <<
1109 MB_RRD_CONS_INDX_SHIFT) |
1110 ((tpd_next_to_use & MB_TPD_PROD_INDX_MASK) <<
1111 MB_TPD_PROD_INDX_SHIFT);
1112 iowrite32(value, adapter->hw.hw_addr + REG_MAILBOX);
1113
1114 spin_unlock_irqrestore(&adapter->mb_lock, flags);
1115}
1116
1117static void atl1_clean_alloc_flag(struct atl1_adapter *adapter,
1118 struct rx_return_desc *rrd, u16 offset)
1119{
1120 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1121
1122 while (rfd_ring->next_to_clean != (rrd->buf_indx + offset)) {
1123 rfd_ring->buffer_info[rfd_ring->next_to_clean].alloced = 0;
1124 if (++rfd_ring->next_to_clean == rfd_ring->count) {
1125 rfd_ring->next_to_clean = 0;
1126 }
1127 }
1128}
1129
1130static void atl1_update_rfd_index(struct atl1_adapter *adapter,
1131 struct rx_return_desc *rrd)
1132{
1133 u16 num_buf;
1134
1135 num_buf = (rrd->xsz.xsum_sz.pkt_size + adapter->rx_buffer_len - 1) /
1136 adapter->rx_buffer_len;
1137 if (rrd->num_buf == num_buf)
1138 /* clean alloc flag for bad rrd */
1139 atl1_clean_alloc_flag(adapter, rrd, num_buf);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001140}
1141
1142static void atl1_rx_checksum(struct atl1_adapter *adapter,
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001143 struct rx_return_desc *rrd, struct sk_buff *skb)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001144{
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001145 struct pci_dev *pdev = adapter->pdev;
1146
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001147 skb->ip_summed = CHECKSUM_NONE;
1148
1149 if (unlikely(rrd->pkt_flg & PACKET_FLAG_ERR)) {
1150 if (rrd->err_flg & (ERR_FLAG_CRC | ERR_FLAG_TRUNC |
1151 ERR_FLAG_CODE | ERR_FLAG_OV)) {
1152 adapter->hw_csum_err++;
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001153 dev_printk(KERN_DEBUG, &pdev->dev,
1154 "rx checksum error\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001155 return;
1156 }
1157 }
1158
1159 /* not IPv4 */
1160 if (!(rrd->pkt_flg & PACKET_FLAG_IPV4))
1161 /* checksum is invalid, but it's not an IPv4 pkt, so ok */
1162 return;
1163
1164 /* IPv4 packet */
1165 if (likely(!(rrd->err_flg &
1166 (ERR_FLAG_IP_CHKSUM | ERR_FLAG_L4_CHKSUM)))) {
1167 skb->ip_summed = CHECKSUM_UNNECESSARY;
1168 adapter->hw_csum_good++;
1169 return;
1170 }
1171
1172 /* IPv4, but hardware thinks its checksum is wrong */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001173 dev_printk(KERN_DEBUG, &pdev->dev,
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001174 "hw csum wrong, pkt_flag:%x, err_flag:%x\n",
1175 rrd->pkt_flg, rrd->err_flg);
1176 skb->ip_summed = CHECKSUM_COMPLETE;
1177 skb->csum = htons(rrd->xsz.xsum_sz.rx_chksum);
1178 adapter->hw_csum_err++;
1179 return;
1180}
1181
1182/*
1183 * atl1_alloc_rx_buffers - Replace used receive buffers
1184 * @adapter: address of board private structure
1185 */
1186static u16 atl1_alloc_rx_buffers(struct atl1_adapter *adapter)
1187{
1188 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1189 struct pci_dev *pdev = adapter->pdev;
1190 struct page *page;
1191 unsigned long offset;
1192 struct atl1_buffer *buffer_info, *next_info;
1193 struct sk_buff *skb;
1194 u16 num_alloc = 0;
1195 u16 rfd_next_to_use, next_next;
1196 struct rx_free_desc *rfd_desc;
1197
1198 next_next = rfd_next_to_use = atomic_read(&rfd_ring->next_to_use);
1199 if (++next_next == rfd_ring->count)
1200 next_next = 0;
1201 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1202 next_info = &rfd_ring->buffer_info[next_next];
1203
1204 while (!buffer_info->alloced && !next_info->alloced) {
1205 if (buffer_info->skb) {
1206 buffer_info->alloced = 1;
1207 goto next;
1208 }
1209
1210 rfd_desc = ATL1_RFD_DESC(rfd_ring, rfd_next_to_use);
1211
1212 skb = dev_alloc_skb(adapter->rx_buffer_len + NET_IP_ALIGN);
1213 if (unlikely(!skb)) { /* Better luck next round */
1214 adapter->net_stats.rx_dropped++;
1215 break;
1216 }
1217
1218 /*
1219 * Make buffer alignment 2 beyond a 16 byte boundary
1220 * this will result in a 16 byte aligned IP header after
1221 * the 14 byte MAC header is removed
1222 */
1223 skb_reserve(skb, NET_IP_ALIGN);
1224
1225 buffer_info->alloced = 1;
1226 buffer_info->skb = skb;
1227 buffer_info->length = (u16) adapter->rx_buffer_len;
1228 page = virt_to_page(skb->data);
1229 offset = (unsigned long)skb->data & ~PAGE_MASK;
1230 buffer_info->dma = pci_map_page(pdev, page, offset,
1231 adapter->rx_buffer_len,
1232 PCI_DMA_FROMDEVICE);
1233 rfd_desc->buffer_addr = cpu_to_le64(buffer_info->dma);
1234 rfd_desc->buf_len = cpu_to_le16(adapter->rx_buffer_len);
1235 rfd_desc->coalese = 0;
1236
1237next:
1238 rfd_next_to_use = next_next;
1239 if (unlikely(++next_next == rfd_ring->count))
1240 next_next = 0;
1241
1242 buffer_info = &rfd_ring->buffer_info[rfd_next_to_use];
1243 next_info = &rfd_ring->buffer_info[next_next];
1244 num_alloc++;
1245 }
1246
1247 if (num_alloc) {
1248 /*
1249 * Force memory writes to complete before letting h/w
1250 * know there are new descriptors to fetch. (Only
1251 * applicable for weak-ordered memory model archs,
1252 * such as IA-64).
1253 */
1254 wmb();
1255 atomic_set(&rfd_ring->next_to_use, (int)rfd_next_to_use);
1256 }
1257 return num_alloc;
1258}
1259
1260static void atl1_intr_rx(struct atl1_adapter *adapter)
1261{
1262 int i, count;
1263 u16 length;
1264 u16 rrd_next_to_clean;
1265 u32 value;
1266 struct atl1_rfd_ring *rfd_ring = &adapter->rfd_ring;
1267 struct atl1_rrd_ring *rrd_ring = &adapter->rrd_ring;
1268 struct atl1_buffer *buffer_info;
1269 struct rx_return_desc *rrd;
1270 struct sk_buff *skb;
1271
1272 count = 0;
1273
1274 rrd_next_to_clean = atomic_read(&rrd_ring->next_to_clean);
1275
1276 while (1) {
1277 rrd = ATL1_RRD_DESC(rrd_ring, rrd_next_to_clean);
1278 i = 1;
1279 if (likely(rrd->xsz.valid)) { /* packet valid */
1280chk_rrd:
1281 /* check rrd status */
1282 if (likely(rrd->num_buf == 1))
1283 goto rrd_ok;
1284
1285 /* rrd seems to be bad */
1286 if (unlikely(i-- > 0)) {
1287 /* rrd may not be DMAed completely */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001288 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001289 "incomplete RRD DMA transfer\n");
1290 udelay(1);
1291 goto chk_rrd;
1292 }
1293 /* bad rrd */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001294 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1295 "bad RRD\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001296 /* see if update RFD index */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001297 if (rrd->num_buf > 1)
1298 atl1_update_rfd_index(adapter, rrd);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001299
1300 /* update rrd */
1301 rrd->xsz.valid = 0;
1302 if (++rrd_next_to_clean == rrd_ring->count)
1303 rrd_next_to_clean = 0;
1304 count++;
1305 continue;
1306 } else { /* current rrd still not be updated */
1307
1308 break;
1309 }
1310rrd_ok:
1311 /* clean alloc flag for bad rrd */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001312 atl1_clean_alloc_flag(adapter, rrd, 0);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001313
1314 buffer_info = &rfd_ring->buffer_info[rrd->buf_indx];
1315 if (++rfd_ring->next_to_clean == rfd_ring->count)
1316 rfd_ring->next_to_clean = 0;
1317
1318 /* update rrd next to clean */
1319 if (++rrd_next_to_clean == rrd_ring->count)
1320 rrd_next_to_clean = 0;
1321 count++;
1322
1323 if (unlikely(rrd->pkt_flg & PACKET_FLAG_ERR)) {
1324 if (!(rrd->err_flg &
1325 (ERR_FLAG_IP_CHKSUM | ERR_FLAG_L4_CHKSUM
1326 | ERR_FLAG_LEN))) {
1327 /* packet error, don't need upstream */
1328 buffer_info->alloced = 0;
1329 rrd->xsz.valid = 0;
1330 continue;
1331 }
1332 }
1333
1334 /* Good Receive */
1335 pci_unmap_page(adapter->pdev, buffer_info->dma,
1336 buffer_info->length, PCI_DMA_FROMDEVICE);
1337 skb = buffer_info->skb;
1338 length = le16_to_cpu(rrd->xsz.xsum_sz.pkt_size);
1339
1340 skb_put(skb, length - ETHERNET_FCS_SIZE);
1341
1342 /* Receive Checksum Offload */
1343 atl1_rx_checksum(adapter, rrd, skb);
1344 skb->protocol = eth_type_trans(skb, adapter->netdev);
1345
1346 if (adapter->vlgrp && (rrd->pkt_flg & PACKET_FLAG_VLAN_INS)) {
1347 u16 vlan_tag = (rrd->vlan_tag >> 4) |
1348 ((rrd->vlan_tag & 7) << 13) |
1349 ((rrd->vlan_tag & 8) << 9);
1350 vlan_hwaccel_rx(skb, adapter->vlgrp, vlan_tag);
1351 } else
1352 netif_rx(skb);
1353
1354 /* let protocol layer free skb */
1355 buffer_info->skb = NULL;
1356 buffer_info->alloced = 0;
1357 rrd->xsz.valid = 0;
1358
1359 adapter->netdev->last_rx = jiffies;
1360 }
1361
1362 atomic_set(&rrd_ring->next_to_clean, rrd_next_to_clean);
1363
1364 atl1_alloc_rx_buffers(adapter);
1365
1366 /* update mailbox ? */
1367 if (count) {
1368 u32 tpd_next_to_use;
1369 u32 rfd_next_to_use;
1370 u32 rrd_next_to_clean;
1371
1372 spin_lock(&adapter->mb_lock);
1373
1374 tpd_next_to_use = atomic_read(&adapter->tpd_ring.next_to_use);
1375 rfd_next_to_use =
1376 atomic_read(&adapter->rfd_ring.next_to_use);
1377 rrd_next_to_clean =
1378 atomic_read(&adapter->rrd_ring.next_to_clean);
1379 value = ((rfd_next_to_use & MB_RFD_PROD_INDX_MASK) <<
1380 MB_RFD_PROD_INDX_SHIFT) |
1381 ((rrd_next_to_clean & MB_RRD_CONS_INDX_MASK) <<
1382 MB_RRD_CONS_INDX_SHIFT) |
1383 ((tpd_next_to_use & MB_TPD_PROD_INDX_MASK) <<
1384 MB_TPD_PROD_INDX_SHIFT);
1385 iowrite32(value, adapter->hw.hw_addr + REG_MAILBOX);
1386 spin_unlock(&adapter->mb_lock);
1387 }
1388}
1389
1390static void atl1_intr_tx(struct atl1_adapter *adapter)
1391{
1392 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1393 struct atl1_buffer *buffer_info;
1394 u16 sw_tpd_next_to_clean;
1395 u16 cmb_tpd_next_to_clean;
1396
1397 sw_tpd_next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1398 cmb_tpd_next_to_clean = le16_to_cpu(adapter->cmb.cmb->tpd_cons_idx);
1399
1400 while (cmb_tpd_next_to_clean != sw_tpd_next_to_clean) {
1401 struct tx_packet_desc *tpd;
1402
1403 tpd = ATL1_TPD_DESC(tpd_ring, sw_tpd_next_to_clean);
1404 buffer_info = &tpd_ring->buffer_info[sw_tpd_next_to_clean];
1405 if (buffer_info->dma) {
1406 pci_unmap_page(adapter->pdev, buffer_info->dma,
1407 buffer_info->length, PCI_DMA_TODEVICE);
1408 buffer_info->dma = 0;
1409 }
1410
1411 if (buffer_info->skb) {
1412 dev_kfree_skb_irq(buffer_info->skb);
1413 buffer_info->skb = NULL;
1414 }
1415 tpd->buffer_addr = 0;
1416 tpd->desc.data = 0;
1417
1418 if (++sw_tpd_next_to_clean == tpd_ring->count)
1419 sw_tpd_next_to_clean = 0;
1420 }
1421 atomic_set(&tpd_ring->next_to_clean, sw_tpd_next_to_clean);
1422
1423 if (netif_queue_stopped(adapter->netdev)
1424 && netif_carrier_ok(adapter->netdev))
1425 netif_wake_queue(adapter->netdev);
1426}
1427
Jay Cliburne6a7ff42007-07-19 18:45:10 -05001428static u16 atl1_tpd_avail(struct atl1_tpd_ring *tpd_ring)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001429{
1430 u16 next_to_clean = atomic_read(&tpd_ring->next_to_clean);
1431 u16 next_to_use = atomic_read(&tpd_ring->next_to_use);
Jay Cliburn53ffb422007-07-15 11:03:27 -05001432 return ((next_to_clean > next_to_use) ?
1433 next_to_clean - next_to_use - 1 :
1434 tpd_ring->count + next_to_clean - next_to_use - 1);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001435}
1436
1437static int atl1_tso(struct atl1_adapter *adapter, struct sk_buff *skb,
1438 struct tso_param *tso)
1439{
1440 /* We enter this function holding a spinlock. */
1441 u8 ipofst;
1442 int err;
1443
1444 if (skb_shinfo(skb)->gso_size) {
1445 if (skb_header_cloned(skb)) {
1446 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
1447 if (unlikely(err))
1448 return err;
1449 }
1450
1451 if (skb->protocol == ntohs(ETH_P_IP)) {
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001452 struct iphdr *iph = ip_hdr(skb);
1453
1454 iph->tot_len = 0;
1455 iph->check = 0;
Arnaldo Carvalho de Meloaa8223c2007-04-10 21:04:22 -07001456 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Jay Cliburn2ca13da2007-07-15 11:03:28 -05001457 iph->daddr, 0, IPPROTO_TCP, 0);
Arnaldo Carvalho de Melobbe735e2007-03-10 22:16:10 -03001458 ipofst = skb_network_offset(skb);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001459 if (ipofst != ENET_HEADER_SIZE) /* 802.3 frame */
1460 tso->tsopl |= 1 << TSO_PARAM_ETHTYPE_SHIFT;
1461
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001462 tso->tsopl |= (iph->ihl &
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001463 CSUM_PARAM_IPHL_MASK) << CSUM_PARAM_IPHL_SHIFT;
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001464 tso->tsopl |= (tcp_hdrlen(skb) &
Jay Cliburn53ffb422007-07-15 11:03:27 -05001465 TSO_PARAM_TCPHDRLEN_MASK) <<
1466 TSO_PARAM_TCPHDRLEN_SHIFT;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001467 tso->tsopl |= (skb_shinfo(skb)->gso_size &
1468 TSO_PARAM_MSS_MASK) << TSO_PARAM_MSS_SHIFT;
1469 tso->tsopl |= 1 << TSO_PARAM_IPCKSUM_SHIFT;
1470 tso->tsopl |= 1 << TSO_PARAM_TCPCKSUM_SHIFT;
1471 tso->tsopl |= 1 << TSO_PARAM_SEGMENT_SHIFT;
1472 return true;
1473 }
1474 }
1475 return false;
1476}
1477
1478static int atl1_tx_csum(struct atl1_adapter *adapter, struct sk_buff *skb,
Jay Cliburn53ffb422007-07-15 11:03:27 -05001479 struct csum_param *csum)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001480{
1481 u8 css, cso;
1482
1483 if (likely(skb->ip_summed == CHECKSUM_PARTIAL)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07001484 cso = skb_transport_offset(skb);
Herbert Xu628592c2007-04-23 17:06:40 -07001485 css = cso + skb->csum_offset;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001486 if (unlikely(cso & 0x1)) {
Jay Cliburn53ffb422007-07-15 11:03:27 -05001487 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
Jay Cliburn1e006362007-04-29 21:42:10 -05001488 "payload offset not an even number\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001489 return -1;
1490 }
1491 csum->csumpl |= (cso & CSUM_PARAM_PLOADOFFSET_MASK) <<
1492 CSUM_PARAM_PLOADOFFSET_SHIFT;
1493 csum->csumpl |= (css & CSUM_PARAM_XSUMOFFSET_MASK) <<
1494 CSUM_PARAM_XSUMOFFSET_SHIFT;
1495 csum->csumpl |= 1 << CSUM_PARAM_CUSTOMCKSUM_SHIFT;
1496 return true;
1497 }
1498
1499 return true;
1500}
1501
Jay Cliburn53ffb422007-07-15 11:03:27 -05001502static void atl1_tx_map(struct atl1_adapter *adapter, struct sk_buff *skb,
1503 bool tcp_seg)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001504{
1505 /* We enter this function holding a spinlock. */
1506 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1507 struct atl1_buffer *buffer_info;
1508 struct page *page;
1509 int first_buf_len = skb->len;
1510 unsigned long offset;
1511 unsigned int nr_frags;
1512 unsigned int f;
1513 u16 tpd_next_to_use;
1514 u16 proto_hdr_len;
1515 u16 i, m, len12;
1516
1517 first_buf_len -= skb->data_len;
1518 nr_frags = skb_shinfo(skb)->nr_frags;
1519 tpd_next_to_use = atomic_read(&tpd_ring->next_to_use);
1520 buffer_info = &tpd_ring->buffer_info[tpd_next_to_use];
1521 if (unlikely(buffer_info->skb))
1522 BUG();
1523 buffer_info->skb = NULL; /* put skb in last TPD */
1524
1525 if (tcp_seg) {
1526 /* TSO/GSO */
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001527 proto_hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001528 buffer_info->length = proto_hdr_len;
1529 page = virt_to_page(skb->data);
1530 offset = (unsigned long)skb->data & ~PAGE_MASK;
1531 buffer_info->dma = pci_map_page(adapter->pdev, page,
1532 offset, proto_hdr_len,
1533 PCI_DMA_TODEVICE);
1534
1535 if (++tpd_next_to_use == tpd_ring->count)
1536 tpd_next_to_use = 0;
1537
1538 if (first_buf_len > proto_hdr_len) {
1539 len12 = first_buf_len - proto_hdr_len;
Jay Cliburn53ffb422007-07-15 11:03:27 -05001540 m = (len12 + ATL1_MAX_TX_BUF_LEN - 1) /
1541 ATL1_MAX_TX_BUF_LEN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001542 for (i = 0; i < m; i++) {
1543 buffer_info =
1544 &tpd_ring->buffer_info[tpd_next_to_use];
1545 buffer_info->skb = NULL;
1546 buffer_info->length =
Jay Cliburn2b116142007-07-15 11:03:26 -05001547 (ATL1_MAX_TX_BUF_LEN >=
1548 len12) ? ATL1_MAX_TX_BUF_LEN : len12;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001549 len12 -= buffer_info->length;
1550 page = virt_to_page(skb->data +
Jay Cliburn53ffb422007-07-15 11:03:27 -05001551 (proto_hdr_len +
1552 i * ATL1_MAX_TX_BUF_LEN));
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001553 offset = (unsigned long)(skb->data +
Jay Cliburn53ffb422007-07-15 11:03:27 -05001554 (proto_hdr_len +
1555 i * ATL1_MAX_TX_BUF_LEN)) & ~PAGE_MASK;
1556 buffer_info->dma = pci_map_page(adapter->pdev,
1557 page, offset, buffer_info->length,
1558 PCI_DMA_TODEVICE);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001559 if (++tpd_next_to_use == tpd_ring->count)
1560 tpd_next_to_use = 0;
1561 }
1562 }
1563 } else {
1564 /* not TSO/GSO */
1565 buffer_info->length = first_buf_len;
1566 page = virt_to_page(skb->data);
1567 offset = (unsigned long)skb->data & ~PAGE_MASK;
1568 buffer_info->dma = pci_map_page(adapter->pdev, page,
Jay Cliburn53ffb422007-07-15 11:03:27 -05001569 offset, first_buf_len, PCI_DMA_TODEVICE);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001570 if (++tpd_next_to_use == tpd_ring->count)
1571 tpd_next_to_use = 0;
1572 }
1573
1574 for (f = 0; f < nr_frags; f++) {
1575 struct skb_frag_struct *frag;
1576 u16 lenf, i, m;
1577
1578 frag = &skb_shinfo(skb)->frags[f];
1579 lenf = frag->size;
1580
Jay Cliburn2b116142007-07-15 11:03:26 -05001581 m = (lenf + ATL1_MAX_TX_BUF_LEN - 1) / ATL1_MAX_TX_BUF_LEN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001582 for (i = 0; i < m; i++) {
1583 buffer_info = &tpd_ring->buffer_info[tpd_next_to_use];
1584 if (unlikely(buffer_info->skb))
1585 BUG();
1586 buffer_info->skb = NULL;
Jay Cliburn53ffb422007-07-15 11:03:27 -05001587 buffer_info->length = (lenf > ATL1_MAX_TX_BUF_LEN) ?
1588 ATL1_MAX_TX_BUF_LEN : lenf;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001589 lenf -= buffer_info->length;
Jay Cliburn53ffb422007-07-15 11:03:27 -05001590 buffer_info->dma = pci_map_page(adapter->pdev,
1591 frag->page,
1592 frag->page_offset + (i * ATL1_MAX_TX_BUF_LEN),
1593 buffer_info->length, PCI_DMA_TODEVICE);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001594
1595 if (++tpd_next_to_use == tpd_ring->count)
1596 tpd_next_to_use = 0;
1597 }
1598 }
1599
1600 /* last tpd's buffer-info */
1601 buffer_info->skb = skb;
1602}
1603
1604static void atl1_tx_queue(struct atl1_adapter *adapter, int count,
Jay Cliburn53ffb422007-07-15 11:03:27 -05001605 union tpd_descr *descr)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001606{
1607 /* We enter this function holding a spinlock. */
1608 struct atl1_tpd_ring *tpd_ring = &adapter->tpd_ring;
1609 int j;
1610 u32 val;
1611 struct atl1_buffer *buffer_info;
1612 struct tx_packet_desc *tpd;
1613 u16 tpd_next_to_use = atomic_read(&tpd_ring->next_to_use);
1614
1615 for (j = 0; j < count; j++) {
1616 buffer_info = &tpd_ring->buffer_info[tpd_next_to_use];
1617 tpd = ATL1_TPD_DESC(&adapter->tpd_ring, tpd_next_to_use);
1618 tpd->desc.csum.csumpu = descr->csum.csumpu;
1619 tpd->desc.csum.csumpl = descr->csum.csumpl;
1620 tpd->desc.tso.tsopu = descr->tso.tsopu;
1621 tpd->desc.tso.tsopl = descr->tso.tsopl;
1622 tpd->buffer_addr = cpu_to_le64(buffer_info->dma);
1623 tpd->desc.data = descr->data;
1624 tpd->desc.csum.csumpu |= (cpu_to_le16(buffer_info->length) &
1625 CSUM_PARAM_BUFLEN_MASK) << CSUM_PARAM_BUFLEN_SHIFT;
1626
1627 val = (descr->tso.tsopl >> TSO_PARAM_SEGMENT_SHIFT) &
1628 TSO_PARAM_SEGMENT_MASK;
1629 if (val && !j)
1630 tpd->desc.tso.tsopl |= 1 << TSO_PARAM_HDRFLAG_SHIFT;
1631
1632 if (j == (count - 1))
1633 tpd->desc.csum.csumpl |= 1 << CSUM_PARAM_EOP_SHIFT;
1634
1635 if (++tpd_next_to_use == tpd_ring->count)
1636 tpd_next_to_use = 0;
1637 }
1638 /*
1639 * Force memory writes to complete before letting h/w
1640 * know there are new descriptors to fetch. (Only
1641 * applicable for weak-ordered memory model archs,
1642 * such as IA-64).
1643 */
1644 wmb();
1645
1646 atomic_set(&tpd_ring->next_to_use, (int)tpd_next_to_use);
1647}
1648
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001649static int atl1_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1650{
1651 struct atl1_adapter *adapter = netdev_priv(netdev);
1652 int len = skb->len;
1653 int tso;
1654 int count = 1;
1655 int ret_val;
1656 u32 val;
1657 union tpd_descr param;
1658 u16 frag_size;
1659 u16 vlan_tag;
1660 unsigned long flags;
1661 unsigned int nr_frags = 0;
1662 unsigned int mss = 0;
1663 unsigned int f;
1664 unsigned int proto_hdr_len;
1665
1666 len -= skb->data_len;
1667
1668 if (unlikely(skb->len == 0)) {
1669 dev_kfree_skb_any(skb);
1670 return NETDEV_TX_OK;
1671 }
1672
1673 param.data = 0;
1674 param.tso.tsopu = 0;
1675 param.tso.tsopl = 0;
1676 param.csum.csumpu = 0;
1677 param.csum.csumpl = 0;
1678
1679 /* nr_frags will be nonzero if we're doing scatter/gather (SG) */
1680 nr_frags = skb_shinfo(skb)->nr_frags;
1681 for (f = 0; f < nr_frags; f++) {
1682 frag_size = skb_shinfo(skb)->frags[f].size;
1683 if (frag_size)
Jay Cliburn53ffb422007-07-15 11:03:27 -05001684 count += (frag_size + ATL1_MAX_TX_BUF_LEN - 1) /
1685 ATL1_MAX_TX_BUF_LEN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001686 }
1687
1688 /* mss will be nonzero if we're doing segment offload (TSO/GSO) */
1689 mss = skb_shinfo(skb)->gso_size;
1690 if (mss) {
Al Viro7ccec1b2007-03-14 09:20:10 +00001691 if (skb->protocol == htons(ETH_P_IP)) {
Arnaldo Carvalho de Meloea2ae172007-04-25 17:55:53 -07001692 proto_hdr_len = (skb_transport_offset(skb) +
Arnaldo Carvalho de Meloab6a5bb2007-03-18 17:43:48 -07001693 tcp_hdrlen(skb));
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001694 if (unlikely(proto_hdr_len > len)) {
1695 dev_kfree_skb_any(skb);
1696 return NETDEV_TX_OK;
1697 }
1698 /* need additional TPD ? */
1699 if (proto_hdr_len != len)
1700 count += (len - proto_hdr_len +
Jay Cliburn53ffb422007-07-15 11:03:27 -05001701 ATL1_MAX_TX_BUF_LEN - 1) /
1702 ATL1_MAX_TX_BUF_LEN;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001703 }
1704 }
1705
1706 local_irq_save(flags);
1707 if (!spin_trylock(&adapter->lock)) {
1708 /* Can't get lock - tell upper layer to requeue */
1709 local_irq_restore(flags);
Jay Cliburn53ffb422007-07-15 11:03:27 -05001710 dev_printk(KERN_DEBUG, &adapter->pdev->dev, "tx locked\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001711 return NETDEV_TX_LOCKED;
1712 }
1713
Jay Cliburne6a7ff42007-07-19 18:45:10 -05001714 if (atl1_tpd_avail(&adapter->tpd_ring) < count) {
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001715 /* not enough descriptors */
1716 netif_stop_queue(netdev);
1717 spin_unlock_irqrestore(&adapter->lock, flags);
Jay Cliburn53ffb422007-07-15 11:03:27 -05001718 dev_printk(KERN_DEBUG, &adapter->pdev->dev, "tx busy\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001719 return NETDEV_TX_BUSY;
1720 }
1721
1722 param.data = 0;
1723
1724 if (adapter->vlgrp && vlan_tx_tag_present(skb)) {
1725 vlan_tag = vlan_tx_tag_get(skb);
1726 vlan_tag = (vlan_tag << 4) | (vlan_tag >> 13) |
1727 ((vlan_tag >> 9) & 0x8);
1728 param.csum.csumpl |= 1 << CSUM_PARAM_INSVLAG_SHIFT;
1729 param.csum.csumpu |= (vlan_tag & CSUM_PARAM_VALANTAG_MASK) <<
1730 CSUM_PARAM_VALAN_SHIFT;
1731 }
1732
1733 tso = atl1_tso(adapter, skb, &param.tso);
1734 if (tso < 0) {
1735 spin_unlock_irqrestore(&adapter->lock, flags);
1736 dev_kfree_skb_any(skb);
1737 return NETDEV_TX_OK;
1738 }
1739
1740 if (!tso) {
1741 ret_val = atl1_tx_csum(adapter, skb, &param.csum);
1742 if (ret_val < 0) {
1743 spin_unlock_irqrestore(&adapter->lock, flags);
1744 dev_kfree_skb_any(skb);
1745 return NETDEV_TX_OK;
1746 }
1747 }
1748
1749 val = (param.csum.csumpl >> CSUM_PARAM_SEGMENT_SHIFT) &
1750 CSUM_PARAM_SEGMENT_MASK;
1751 atl1_tx_map(adapter, skb, 1 == val);
1752 atl1_tx_queue(adapter, count, &param);
1753 netdev->trans_start = jiffies;
1754 spin_unlock_irqrestore(&adapter->lock, flags);
1755 atl1_update_mailbox(adapter);
1756 return NETDEV_TX_OK;
1757}
1758
1759/*
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001760 * atl1_intr - Interrupt Handler
1761 * @irq: interrupt number
1762 * @data: pointer to a network interface device structure
1763 * @pt_regs: CPU registers structure
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001764 */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001765static irqreturn_t atl1_intr(int irq, void *data)
1766{
1767 struct atl1_adapter *adapter = netdev_priv(data);
1768 u32 status;
1769 u8 update_rx;
1770 int max_ints = 10;
1771
1772 status = adapter->cmb.cmb->int_stats;
1773 if (!status)
1774 return IRQ_NONE;
1775
1776 update_rx = 0;
1777
1778 do {
1779 /* clear CMB interrupt status at once */
1780 adapter->cmb.cmb->int_stats = 0;
1781
1782 if (status & ISR_GPHY) /* clear phy status */
1783 atl1_clear_phy_int(adapter);
1784
1785 /* clear ISR status, and Enable CMB DMA/Disable Interrupt */
1786 iowrite32(status | ISR_DIS_INT, adapter->hw.hw_addr + REG_ISR);
1787
1788 /* check if SMB intr */
1789 if (status & ISR_SMB)
1790 atl1_inc_smb(adapter);
1791
1792 /* check if PCIE PHY Link down */
1793 if (status & ISR_PHY_LINKDOWN) {
1794 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1795 "pcie phy link down %x\n", status);
1796 if (netif_running(adapter->netdev)) { /* reset MAC */
1797 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
1798 schedule_work(&adapter->pcie_dma_to_rst_task);
1799 return IRQ_HANDLED;
1800 }
1801 }
1802
1803 /* check if DMA read/write error ? */
1804 if (status & (ISR_DMAR_TO_RST | ISR_DMAW_TO_RST)) {
1805 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1806 "pcie DMA r/w error (status = 0x%x)\n",
1807 status);
1808 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
1809 schedule_work(&adapter->pcie_dma_to_rst_task);
1810 return IRQ_HANDLED;
1811 }
1812
1813 /* link event */
1814 if (status & ISR_GPHY) {
1815 adapter->soft_stats.tx_carrier_errors++;
1816 atl1_check_for_link(adapter);
1817 }
1818
1819 /* transmit event */
1820 if (status & ISR_CMB_TX)
1821 atl1_intr_tx(adapter);
1822
1823 /* rx exception */
1824 if (unlikely(status & (ISR_RXF_OV | ISR_RFD_UNRUN |
1825 ISR_RRD_OV | ISR_HOST_RFD_UNRUN |
1826 ISR_HOST_RRD_OV | ISR_CMB_RX))) {
1827 if (status & (ISR_RXF_OV | ISR_RFD_UNRUN |
1828 ISR_RRD_OV | ISR_HOST_RFD_UNRUN |
1829 ISR_HOST_RRD_OV))
1830 dev_printk(KERN_DEBUG, &adapter->pdev->dev,
1831 "rx exception, ISR = 0x%x\n", status);
1832 atl1_intr_rx(adapter);
1833 }
1834
1835 if (--max_ints < 0)
1836 break;
1837
1838 } while ((status = adapter->cmb.cmb->int_stats));
1839
1840 /* re-enable Interrupt */
1841 iowrite32(ISR_DIS_SMB | ISR_DIS_DMA, adapter->hw.hw_addr + REG_ISR);
1842 return IRQ_HANDLED;
1843}
1844
1845/*
1846 * atl1_watchdog - Timer Call-back
1847 * @data: pointer to netdev cast into an unsigned long
1848 */
1849static void atl1_watchdog(unsigned long data)
1850{
1851 struct atl1_adapter *adapter = (struct atl1_adapter *)data;
1852
1853 /* Reset the timer */
1854 mod_timer(&adapter->watchdog_timer, jiffies + 2 * HZ);
1855}
1856
1857/*
1858 * atl1_phy_config - Timer Call-back
1859 * @data: pointer to netdev cast into an unsigned long
1860 */
1861static void atl1_phy_config(unsigned long data)
1862{
1863 struct atl1_adapter *adapter = (struct atl1_adapter *)data;
1864 struct atl1_hw *hw = &adapter->hw;
1865 unsigned long flags;
1866
1867 spin_lock_irqsave(&adapter->lock, flags);
1868 adapter->phy_timer_pending = false;
1869 atl1_write_phy_reg(hw, MII_ADVERTISE, hw->mii_autoneg_adv_reg);
1870 atl1_write_phy_reg(hw, MII_AT001_CR, hw->mii_1000t_ctrl_reg);
1871 atl1_write_phy_reg(hw, MII_BMCR, MII_CR_RESET | MII_CR_AUTO_NEG_EN);
1872 spin_unlock_irqrestore(&adapter->lock, flags);
1873}
1874
1875/*
1876 * atl1_tx_timeout - Respond to a Tx Hang
1877 * @netdev: network interface device structure
1878 */
1879static void atl1_tx_timeout(struct net_device *netdev)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001880{
1881 struct atl1_adapter *adapter = netdev_priv(netdev);
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001882 /* Do the reset outside of interrupt context */
1883 schedule_work(&adapter->tx_timeout_task);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001884}
1885
1886/*
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001887 * Orphaned vendor comment left intact here:
1888 * <vendor comment>
1889 * If TPD Buffer size equal to 0, PCIE DMAR_TO_INT
1890 * will assert. We do soft reset <0x1400=1> according
1891 * with the SPEC. BUT, it seemes that PCIE or DMA
1892 * state-machine will not be reset. DMAR_TO_INT will
1893 * assert again and again.
1894 * </vendor comment>
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001895 */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001896static void atl1_tx_timeout_task(struct work_struct *work)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001897{
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001898 struct atl1_adapter *adapter =
1899 container_of(work, struct atl1_adapter, tx_timeout_task);
1900 struct net_device *netdev = adapter->netdev;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001901
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001902 netif_device_detach(netdev);
1903 atl1_down(adapter);
1904 atl1_up(adapter);
1905 netif_device_attach(netdev);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001906}
1907
1908/*
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001909 * atl1_link_chg_task - deal with link change event Out of interrupt context
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001910 */
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001911static void atl1_link_chg_task(struct work_struct *work)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001912{
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001913 struct atl1_adapter *adapter =
1914 container_of(work, struct atl1_adapter, link_chg_task);
1915 unsigned long flags;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001916
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001917 spin_lock_irqsave(&adapter->lock, flags);
1918 atl1_check_link(adapter);
1919 spin_unlock_irqrestore(&adapter->lock, flags);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001920}
1921
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001922static void atl1_vlan_rx_register(struct net_device *netdev,
1923 struct vlan_group *grp)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001924{
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001925 struct atl1_adapter *adapter = netdev_priv(netdev);
1926 unsigned long flags;
1927 u32 ctrl;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001928
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001929 spin_lock_irqsave(&adapter->lock, flags);
1930 /* atl1_irq_disable(adapter); */
1931 adapter->vlgrp = grp;
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001932
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001933 if (grp) {
1934 /* enable VLAN tag insert/strip */
1935 ctrl = ioread32(adapter->hw.hw_addr + REG_MAC_CTRL);
1936 ctrl |= MAC_CTRL_RMV_VLAN;
1937 iowrite32(ctrl, adapter->hw.hw_addr + REG_MAC_CTRL);
1938 } else {
1939 /* disable VLAN tag insert/strip */
1940 ctrl = ioread32(adapter->hw.hw_addr + REG_MAC_CTRL);
1941 ctrl &= ~MAC_CTRL_RMV_VLAN;
1942 iowrite32(ctrl, adapter->hw.hw_addr + REG_MAC_CTRL);
1943 }
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001944
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001945 /* atl1_irq_enable(adapter); */
1946 spin_unlock_irqrestore(&adapter->lock, flags);
1947}
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001948
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001949static void atl1_restore_vlan(struct atl1_adapter *adapter)
1950{
1951 atl1_vlan_rx_register(adapter->netdev, adapter->vlgrp);
1952}
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001953
Jay Cliburn05ffdd72007-07-15 11:03:29 -05001954int atl1_reset(struct atl1_adapter *adapter)
1955{
1956 int ret;
1957
1958 ret = atl1_reset_hw(&adapter->hw);
1959 if (ret != ATL1_SUCCESS)
1960 return ret;
1961 return atl1_init_hw(&adapter->hw);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001962}
1963
1964s32 atl1_up(struct atl1_adapter *adapter)
1965{
1966 struct net_device *netdev = adapter->netdev;
1967 int err;
1968 int irq_flags = IRQF_SAMPLE_RANDOM;
1969
1970 /* hardware has been reset, we need to reload some things */
1971 atl1_set_multi(netdev);
Jay Cliburn2ca13da2007-07-15 11:03:28 -05001972 atl1_init_ring_ptrs(adapter);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05001973 atl1_restore_vlan(adapter);
1974 err = atl1_alloc_rx_buffers(adapter);
1975 if (unlikely(!err)) /* no RX BUFFER allocated */
1976 return -ENOMEM;
1977
1978 if (unlikely(atl1_configure(adapter))) {
1979 err = -EIO;
1980 goto err_up;
1981 }
1982
1983 err = pci_enable_msi(adapter->pdev);
1984 if (err) {
1985 dev_info(&adapter->pdev->dev,
1986 "Unable to enable MSI: %d\n", err);
1987 irq_flags |= IRQF_SHARED;
1988 }
1989
1990 err = request_irq(adapter->pdev->irq, &atl1_intr, irq_flags,
1991 netdev->name, netdev);
1992 if (unlikely(err))
1993 goto err_up;
1994
1995 mod_timer(&adapter->watchdog_timer, jiffies);
1996 atl1_irq_enable(adapter);
1997 atl1_check_link(adapter);
1998 return 0;
1999
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002000err_up:
2001 pci_disable_msi(adapter->pdev);
2002 /* free rx_buffers */
2003 atl1_clean_rx_ring(adapter);
2004 return err;
2005}
2006
2007void atl1_down(struct atl1_adapter *adapter)
2008{
2009 struct net_device *netdev = adapter->netdev;
2010
2011 del_timer_sync(&adapter->watchdog_timer);
2012 del_timer_sync(&adapter->phy_config_timer);
2013 adapter->phy_timer_pending = false;
2014
2015 atl1_irq_disable(adapter);
2016 free_irq(adapter->pdev->irq, netdev);
2017 pci_disable_msi(adapter->pdev);
2018 atl1_reset_hw(&adapter->hw);
2019 adapter->cmb.cmb->int_stats = 0;
2020
2021 adapter->link_speed = SPEED_0;
2022 adapter->link_duplex = -1;
2023 netif_carrier_off(netdev);
2024 netif_stop_queue(netdev);
2025
2026 atl1_clean_tx_ring(adapter);
2027 atl1_clean_rx_ring(adapter);
2028}
2029
2030/*
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002031 * atl1_open - Called when a network interface is made active
2032 * @netdev: network interface device structure
2033 *
2034 * Returns 0 on success, negative value on failure
2035 *
2036 * The open entry point is called when a network interface is made
2037 * active by the system (IFF_UP). At this point all resources needed
2038 * for transmit and receive operations are allocated, the interrupt
2039 * handler is registered with the OS, the watchdog timer is started,
2040 * and the stack is notified that the interface is ready.
2041 */
2042static int atl1_open(struct net_device *netdev)
2043{
2044 struct atl1_adapter *adapter = netdev_priv(netdev);
2045 int err;
2046
2047 /* allocate transmit descriptors */
2048 err = atl1_setup_ring_resources(adapter);
2049 if (err)
2050 return err;
2051
2052 err = atl1_up(adapter);
2053 if (err)
2054 goto err_up;
2055
2056 return 0;
2057
2058err_up:
2059 atl1_reset(adapter);
2060 return err;
2061}
2062
2063/*
2064 * atl1_close - Disables a network interface
2065 * @netdev: network interface device structure
2066 *
2067 * Returns 0, this is not allowed to fail
2068 *
2069 * The close entry point is called when an interface is de-activated
2070 * by the OS. The hardware is still under the drivers control, but
2071 * needs to be disabled. A global MAC reset is issued to stop the
2072 * hardware, and all transmit and receive resources are freed.
2073 */
2074static int atl1_close(struct net_device *netdev)
2075{
2076 struct atl1_adapter *adapter = netdev_priv(netdev);
2077 atl1_down(adapter);
2078 atl1_free_ring_resources(adapter);
2079 return 0;
2080}
2081
Jay Cliburn05ffdd72007-07-15 11:03:29 -05002082#ifdef CONFIG_PM
2083static int atl1_suspend(struct pci_dev *pdev, pm_message_t state)
2084{
2085 struct net_device *netdev = pci_get_drvdata(pdev);
2086 struct atl1_adapter *adapter = netdev_priv(netdev);
2087 struct atl1_hw *hw = &adapter->hw;
2088 u32 ctrl = 0;
2089 u32 wufc = adapter->wol;
2090
2091 netif_device_detach(netdev);
2092 if (netif_running(netdev))
2093 atl1_down(adapter);
2094
2095 atl1_read_phy_reg(hw, MII_BMSR, (u16 *) & ctrl);
2096 atl1_read_phy_reg(hw, MII_BMSR, (u16 *) & ctrl);
2097 if (ctrl & BMSR_LSTATUS)
2098 wufc &= ~ATL1_WUFC_LNKC;
2099
2100 /* reduce speed to 10/100M */
2101 if (wufc) {
2102 atl1_phy_enter_power_saving(hw);
2103 /* if resume, let driver to re- setup link */
2104 hw->phy_configured = false;
2105 atl1_set_mac_addr(hw);
2106 atl1_set_multi(netdev);
2107
2108 ctrl = 0;
2109 /* turn on magic packet wol */
2110 if (wufc & ATL1_WUFC_MAG)
2111 ctrl = WOL_MAGIC_EN | WOL_MAGIC_PME_EN;
2112
2113 /* turn on Link change WOL */
2114 if (wufc & ATL1_WUFC_LNKC)
2115 ctrl |= (WOL_LINK_CHG_EN | WOL_LINK_CHG_PME_EN);
2116 iowrite32(ctrl, hw->hw_addr + REG_WOL_CTRL);
2117
2118 /* turn on all-multi mode if wake on multicast is enabled */
2119 ctrl = ioread32(hw->hw_addr + REG_MAC_CTRL);
2120 ctrl &= ~MAC_CTRL_DBG;
2121 ctrl &= ~MAC_CTRL_PROMIS_EN;
2122 if (wufc & ATL1_WUFC_MC)
2123 ctrl |= MAC_CTRL_MC_ALL_EN;
2124 else
2125 ctrl &= ~MAC_CTRL_MC_ALL_EN;
2126
2127 /* turn on broadcast mode if wake on-BC is enabled */
2128 if (wufc & ATL1_WUFC_BC)
2129 ctrl |= MAC_CTRL_BC_EN;
2130 else
2131 ctrl &= ~MAC_CTRL_BC_EN;
2132
2133 /* enable RX */
2134 ctrl |= MAC_CTRL_RX_EN;
2135 iowrite32(ctrl, hw->hw_addr + REG_MAC_CTRL);
2136 pci_enable_wake(pdev, PCI_D3hot, 1);
2137 pci_enable_wake(pdev, PCI_D3cold, 1);
2138 } else {
2139 iowrite32(0, hw->hw_addr + REG_WOL_CTRL);
2140 pci_enable_wake(pdev, PCI_D3hot, 0);
2141 pci_enable_wake(pdev, PCI_D3cold, 0);
2142 }
2143
2144 pci_save_state(pdev);
2145 pci_disable_device(pdev);
2146
2147 pci_set_power_state(pdev, PCI_D3hot);
2148
2149 return 0;
2150}
2151
2152static int atl1_resume(struct pci_dev *pdev)
2153{
2154 struct net_device *netdev = pci_get_drvdata(pdev);
2155 struct atl1_adapter *adapter = netdev_priv(netdev);
2156 u32 ret_val;
2157
2158 pci_set_power_state(pdev, 0);
2159 pci_restore_state(pdev);
2160
2161 ret_val = pci_enable_device(pdev);
2162 pci_enable_wake(pdev, PCI_D3hot, 0);
2163 pci_enable_wake(pdev, PCI_D3cold, 0);
2164
2165 iowrite32(0, adapter->hw.hw_addr + REG_WOL_CTRL);
2166 atl1_reset(adapter);
2167
2168 if (netif_running(netdev))
2169 atl1_up(adapter);
2170 netif_device_attach(netdev);
2171
2172 atl1_via_workaround(adapter);
2173
2174 return 0;
2175}
2176#else
2177#define atl1_suspend NULL
2178#define atl1_resume NULL
2179#endif
2180
Alexey Dobriyan497f0502007-05-09 18:52:35 +04002181#ifdef CONFIG_NET_POLL_CONTROLLER
2182static void atl1_poll_controller(struct net_device *netdev)
2183{
2184 disable_irq(netdev->irq);
2185 atl1_intr(netdev->irq, netdev);
2186 enable_irq(netdev->irq);
2187}
2188#endif
2189
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002190/*
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002191 * atl1_probe - Device Initialization Routine
2192 * @pdev: PCI device information struct
2193 * @ent: entry in atl1_pci_tbl
2194 *
2195 * Returns 0 on success, negative on failure
2196 *
2197 * atl1_probe initializes an adapter identified by a pci_dev structure.
2198 * The OS initialization, configuring of the adapter private structure,
2199 * and a hardware reset occur.
2200 */
2201static int __devinit atl1_probe(struct pci_dev *pdev,
Jay Cliburn53ffb422007-07-15 11:03:27 -05002202 const struct pci_device_id *ent)
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002203{
2204 struct net_device *netdev;
2205 struct atl1_adapter *adapter;
2206 static int cards_found = 0;
2207 bool pci_using_64 = true;
2208 int err;
2209
2210 err = pci_enable_device(pdev);
2211 if (err)
2212 return err;
2213
2214 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
2215 if (err) {
2216 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2217 if (err) {
Jay Cliburn1e006362007-04-29 21:42:10 -05002218 dev_err(&pdev->dev, "no usable DMA configuration\n");
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002219 goto err_dma;
2220 }
2221 pci_using_64 = false;
2222 }
2223 /* Mark all PCI regions associated with PCI device
2224 * pdev as being reserved by owner atl1_driver_name
2225 */
2226 err = pci_request_regions(pdev, atl1_driver_name);
2227 if (err)
2228 goto err_request_regions;
2229
2230 /* Enables bus-mastering on the device and calls
2231 * pcibios_set_master to do the needed arch specific settings
2232 */
2233 pci_set_master(pdev);
2234
2235 netdev = alloc_etherdev(sizeof(struct atl1_adapter));
2236 if (!netdev) {
2237 err = -ENOMEM;
2238 goto err_alloc_etherdev;
2239 }
2240 SET_MODULE_OWNER(netdev);
2241 SET_NETDEV_DEV(netdev, &pdev->dev);
2242
2243 pci_set_drvdata(pdev, netdev);
2244 adapter = netdev_priv(netdev);
2245 adapter->netdev = netdev;
2246 adapter->pdev = pdev;
2247 adapter->hw.back = adapter;
2248
2249 adapter->hw.hw_addr = pci_iomap(pdev, 0, 0);
2250 if (!adapter->hw.hw_addr) {
2251 err = -EIO;
2252 goto err_pci_iomap;
2253 }
2254 /* get device revision number */
Jay Cliburn1e006362007-04-29 21:42:10 -05002255 adapter->hw.dev_rev = ioread16(adapter->hw.hw_addr +
Jay Cliburn53ffb422007-07-15 11:03:27 -05002256 (REG_MASTER_CTRL + 2));
Jay Cliburn1e006362007-04-29 21:42:10 -05002257 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002258
2259 /* set default ring resource counts */
2260 adapter->rfd_ring.count = adapter->rrd_ring.count = ATL1_DEFAULT_RFD;
2261 adapter->tpd_ring.count = ATL1_DEFAULT_TPD;
2262
2263 adapter->mii.dev = netdev;
2264 adapter->mii.mdio_read = mdio_read;
2265 adapter->mii.mdio_write = mdio_write;
2266 adapter->mii.phy_id_mask = 0x1f;
2267 adapter->mii.reg_num_mask = 0x1f;
2268
2269 netdev->open = &atl1_open;
2270 netdev->stop = &atl1_close;
2271 netdev->hard_start_xmit = &atl1_xmit_frame;
2272 netdev->get_stats = &atl1_get_stats;
2273 netdev->set_multicast_list = &atl1_set_multi;
2274 netdev->set_mac_address = &atl1_set_mac;
2275 netdev->change_mtu = &atl1_change_mtu;
2276 netdev->do_ioctl = &atl1_ioctl;
2277 netdev->tx_timeout = &atl1_tx_timeout;
2278 netdev->watchdog_timeo = 5 * HZ;
Alexey Dobriyan497f0502007-05-09 18:52:35 +04002279#ifdef CONFIG_NET_POLL_CONTROLLER
2280 netdev->poll_controller = atl1_poll_controller;
2281#endif
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002282 netdev->vlan_rx_register = atl1_vlan_rx_register;
Stephen Hemmingercb434e32007-06-01 09:44:00 -07002283
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002284 netdev->ethtool_ops = &atl1_ethtool_ops;
2285 adapter->bd_number = cards_found;
2286 adapter->pci_using_64 = pci_using_64;
2287
2288 /* setup the private structure */
2289 err = atl1_sw_init(adapter);
2290 if (err)
2291 goto err_common;
2292
2293 netdev->features = NETIF_F_HW_CSUM;
2294 netdev->features |= NETIF_F_SG;
2295 netdev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
2296
2297 /*
2298 * FIXME - Until tso performance gets fixed, disable the feature.
2299 * Enable it with ethtool -K if desired.
2300 */
2301 /* netdev->features |= NETIF_F_TSO; */
2302
2303 if (pci_using_64)
2304 netdev->features |= NETIF_F_HIGHDMA;
2305
2306 netdev->features |= NETIF_F_LLTX;
2307
2308 /*
2309 * patch for some L1 of old version,
2310 * the final version of L1 may not need these
2311 * patches
2312 */
2313 /* atl1_pcie_patch(adapter); */
2314
2315 /* really reset GPHY core */
2316 iowrite16(0, adapter->hw.hw_addr + REG_GPHY_ENABLE);
2317
2318 /*
2319 * reset the controller to
2320 * put the device in a known good starting state
2321 */
2322 if (atl1_reset_hw(&adapter->hw)) {
2323 err = -EIO;
2324 goto err_common;
2325 }
2326
2327 /* copy the MAC address out of the EEPROM */
2328 atl1_read_mac_addr(&adapter->hw);
2329 memcpy(netdev->dev_addr, adapter->hw.mac_addr, netdev->addr_len);
2330
2331 if (!is_valid_ether_addr(netdev->dev_addr)) {
2332 err = -EIO;
2333 goto err_common;
2334 }
2335
2336 atl1_check_options(adapter);
2337
2338 /* pre-init the MAC, and setup link */
2339 err = atl1_init_hw(&adapter->hw);
2340 if (err) {
2341 err = -EIO;
2342 goto err_common;
2343 }
2344
2345 atl1_pcie_patch(adapter);
2346 /* assume we have no link for now */
2347 netif_carrier_off(netdev);
2348 netif_stop_queue(netdev);
2349
2350 init_timer(&adapter->watchdog_timer);
2351 adapter->watchdog_timer.function = &atl1_watchdog;
2352 adapter->watchdog_timer.data = (unsigned long)adapter;
2353
2354 init_timer(&adapter->phy_config_timer);
2355 adapter->phy_config_timer.function = &atl1_phy_config;
2356 adapter->phy_config_timer.data = (unsigned long)adapter;
2357 adapter->phy_timer_pending = false;
2358
2359 INIT_WORK(&adapter->tx_timeout_task, atl1_tx_timeout_task);
2360
2361 INIT_WORK(&adapter->link_chg_task, atl1_link_chg_task);
2362
2363 INIT_WORK(&adapter->pcie_dma_to_rst_task, atl1_tx_timeout_task);
2364
2365 err = register_netdev(netdev);
2366 if (err)
2367 goto err_common;
2368
2369 cards_found++;
2370 atl1_via_workaround(adapter);
2371 return 0;
2372
2373err_common:
2374 pci_iounmap(pdev, adapter->hw.hw_addr);
2375err_pci_iomap:
2376 free_netdev(netdev);
2377err_alloc_etherdev:
2378 pci_release_regions(pdev);
2379err_dma:
2380err_request_regions:
2381 pci_disable_device(pdev);
2382 return err;
2383}
2384
2385/*
2386 * atl1_remove - Device Removal Routine
2387 * @pdev: PCI device information struct
2388 *
2389 * atl1_remove is called by the PCI subsystem to alert the driver
2390 * that it should release a PCI device. The could be caused by a
2391 * Hot-Plug event, or because the driver is going to be removed from
2392 * memory.
2393 */
2394static void __devexit atl1_remove(struct pci_dev *pdev)
2395{
2396 struct net_device *netdev = pci_get_drvdata(pdev);
2397 struct atl1_adapter *adapter;
2398 /* Device not available. Return. */
2399 if (!netdev)
2400 return;
2401
2402 adapter = netdev_priv(netdev);
Chris Snook8c754a02007-03-28 20:51:51 -04002403
2404 /* Some atl1 boards lack persistent storage for their MAC, and get it
2405 * from the BIOS during POST. If we've been messing with the MAC
2406 * address, we need to save the permanent one.
2407 */
2408 if (memcmp(adapter->hw.mac_addr, adapter->hw.perm_mac_addr, ETH_ALEN)) {
Jay Cliburn53ffb422007-07-15 11:03:27 -05002409 memcpy(adapter->hw.mac_addr, adapter->hw.perm_mac_addr,
2410 ETH_ALEN);
Chris Snook8c754a02007-03-28 20:51:51 -04002411 atl1_set_mac_addr(&adapter->hw);
2412 }
2413
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002414 iowrite16(0, adapter->hw.hw_addr + REG_GPHY_ENABLE);
2415 unregister_netdev(netdev);
2416 pci_iounmap(pdev, adapter->hw.hw_addr);
2417 pci_release_regions(pdev);
2418 free_netdev(netdev);
2419 pci_disable_device(pdev);
2420}
2421
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002422static struct pci_driver atl1_driver = {
2423 .name = atl1_driver_name,
2424 .id_table = atl1_pci_tbl,
2425 .probe = atl1_probe,
2426 .remove = __devexit_p(atl1_remove),
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002427 .suspend = atl1_suspend,
2428 .resume = atl1_resume
2429};
2430
2431/*
2432 * atl1_exit_module - Driver Exit Cleanup Routine
2433 *
2434 * atl1_exit_module is called just before the driver is removed
2435 * from memory.
2436 */
2437static void __exit atl1_exit_module(void)
2438{
2439 pci_unregister_driver(&atl1_driver);
2440}
2441
2442/*
2443 * atl1_init_module - Driver Registration Routine
2444 *
2445 * atl1_init_module is the first routine called when the driver is
2446 * loaded. All it does is register with the PCI subsystem.
2447 */
2448static int __init atl1_init_module(void)
2449{
Jay Cliburnf3cc28c2007-02-08 10:42:37 -05002450 return pci_register_driver(&atl1_driver);
2451}
2452
2453module_init(atl1_init_module);
2454module_exit(atl1_exit_module);