blob: 8319bc18bfa27deaeb27bf5c4a1fffe0f7d485fc [file] [log] [blame]
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001/*
2 * Copyright (C) 2006-2007 PA Semi, Inc
3 *
4 * Driver for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/interrupt.h>
24#include <linux/dmaengine.h>
25#include <linux/delay.h>
26#include <linux/netdevice.h>
27#include <linux/etherdevice.h>
28#include <asm/dma-mapping.h>
29#include <linux/in.h>
30#include <linux/skbuff.h>
31
32#include <linux/ip.h>
33#include <linux/tcp.h>
34#include <net/checksum.h>
35
Olof Johansson771f7402007-05-08 00:47:21 -050036#include <asm/irq.h>
Olof Johanssonaf289e82007-10-03 13:03:54 -050037#include <asm/firmware.h>
Olof Johansson40afa532007-11-28 20:56:04 -060038#include <asm/pasemi_dma.h>
Olof Johansson771f7402007-05-08 00:47:21 -050039
Olof Johanssonf5cd7872007-01-31 21:43:54 -060040#include "pasemi_mac.h"
41
Olof Johansson8dc121a2007-10-02 16:26:53 -050042/* We have our own align, since ppc64 in general has it at 0 because
43 * of design flaws in some of the server bridge chips. However, for
44 * PWRficient doing the unaligned copies is more expensive than doing
45 * unaligned DMA, so make sure the data is aligned instead.
46 */
47#define LOCAL_SKB_ALIGN 2
Olof Johanssonf5cd7872007-01-31 21:43:54 -060048
49/* TODO list
50 *
Olof Johanssonf5cd7872007-01-31 21:43:54 -060051 * - Multicast support
52 * - Large MTU support
Olof Johansson7ddeae22007-10-02 16:27:28 -050053 * - SW LRO
54 * - Multiqueue RX/TX
Olof Johanssonf5cd7872007-01-31 21:43:54 -060055 */
56
57
58/* Must be a power of two */
Olof Johanssonad5da102007-10-02 16:27:15 -050059#define RX_RING_SIZE 4096
60#define TX_RING_SIZE 4096
Olof Johanssonf5cd7872007-01-31 21:43:54 -060061
Olof Johanssonceb51362007-05-08 00:47:49 -050062#define DEFAULT_MSG_ENABLE \
63 (NETIF_MSG_DRV | \
64 NETIF_MSG_PROBE | \
65 NETIF_MSG_LINK | \
66 NETIF_MSG_TIMER | \
67 NETIF_MSG_IFDOWN | \
68 NETIF_MSG_IFUP | \
69 NETIF_MSG_RX_ERR | \
70 NETIF_MSG_TX_ERR)
71
Olof Johansson72b05b92007-11-28 20:54:28 -060072#define TX_DESC(tx, num) ((tx)->ring[(num) & (TX_RING_SIZE-1)])
73#define TX_DESC_INFO(tx, num) ((tx)->ring_info[(num) & (TX_RING_SIZE-1)])
74#define RX_DESC(rx, num) ((rx)->ring[(num) & (RX_RING_SIZE-1)])
75#define RX_DESC_INFO(rx, num) ((rx)->ring_info[(num) & (RX_RING_SIZE-1)])
76#define RX_BUFF(rx, num) ((rx)->buffers[(num) & (RX_RING_SIZE-1)])
Olof Johanssonf5cd7872007-01-31 21:43:54 -060077
Olof Johansson021fa222007-08-22 09:13:11 -050078#define RING_USED(ring) (((ring)->next_to_fill - (ring)->next_to_clean) \
79 & ((ring)->size - 1))
80#define RING_AVAIL(ring) ((ring->size) - RING_USED(ring))
81
Olof Johanssonf5cd7872007-01-31 21:43:54 -060082#define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
83
Olof Johanssonceb51362007-05-08 00:47:49 -050084MODULE_LICENSE("GPL");
85MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
86MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
87
88static int debug = -1; /* -1 == use DEFAULT_MSG_ENABLE as value */
89module_param(debug, int, 0);
90MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
Olof Johanssonf5cd7872007-01-31 21:43:54 -060091
92static struct pasdma_status *dma_status;
93
Olof Johanssonaf289e82007-10-03 13:03:54 -050094static int translation_enabled(void)
95{
96#if defined(CONFIG_PPC_PASEMI_IOMMU_DMA_FORCE)
97 return 1;
98#else
99 return firmware_has_feature(FW_FEATURE_LPAR);
100#endif
101}
102
Olof Johanssona85b9422007-09-15 13:40:59 -0700103static void write_iob_reg(struct pasemi_mac *mac, unsigned int reg,
104 unsigned int val)
105{
Olof Johanssonb6e05a12007-09-15 13:44:07 -0700106 out_le32(mac->iob_regs+reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700107}
108
109static unsigned int read_mac_reg(struct pasemi_mac *mac, unsigned int reg)
110{
Olof Johanssonb6e05a12007-09-15 13:44:07 -0700111 return in_le32(mac->regs+reg);
Olof Johanssona85b9422007-09-15 13:40:59 -0700112}
113
114static void write_mac_reg(struct pasemi_mac *mac, unsigned int reg,
115 unsigned int val)
116{
Olof Johanssonb6e05a12007-09-15 13:44:07 -0700117 out_le32(mac->regs+reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700118}
119
120static unsigned int read_dma_reg(struct pasemi_mac *mac, unsigned int reg)
121{
Olof Johanssonb6e05a12007-09-15 13:44:07 -0700122 return in_le32(mac->dma_regs+reg);
Olof Johanssona85b9422007-09-15 13:40:59 -0700123}
124
125static void write_dma_reg(struct pasemi_mac *mac, unsigned int reg,
126 unsigned int val)
127{
Olof Johanssonb6e05a12007-09-15 13:44:07 -0700128 out_le32(mac->dma_regs+reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700129}
130
Olof Johansson72b05b92007-11-28 20:54:28 -0600131static struct pasemi_mac_rxring *rx_ring(struct pasemi_mac *mac)
132{
133 return mac->rx;
134}
135
136static struct pasemi_mac_txring *tx_ring(struct pasemi_mac *mac)
137{
138 return mac->tx;
139}
140
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600141static int pasemi_get_mac_addr(struct pasemi_mac *mac)
142{
143 struct pci_dev *pdev = mac->pdev;
144 struct device_node *dn = pci_device_to_OF_node(pdev);
olof@lixom.net1af7f052007-05-12 14:57:46 -0500145 int len;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600146 const u8 *maddr;
147 u8 addr[6];
148
149 if (!dn) {
150 dev_dbg(&pdev->dev,
151 "No device node for mac, not configuring\n");
152 return -ENOENT;
153 }
154
olof@lixom.net1af7f052007-05-12 14:57:46 -0500155 maddr = of_get_property(dn, "local-mac-address", &len);
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500156
olof@lixom.net1af7f052007-05-12 14:57:46 -0500157 if (maddr && len == 6) {
158 memcpy(mac->mac_addr, maddr, 6);
159 return 0;
160 }
161
162 /* Some old versions of firmware mistakenly uses mac-address
163 * (and as a string) instead of a byte array in local-mac-address.
164 */
165
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500166 if (maddr == NULL)
Linus Torvalds90287802007-05-08 11:57:17 -0700167 maddr = of_get_property(dn, "mac-address", NULL);
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500168
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600169 if (maddr == NULL) {
170 dev_warn(&pdev->dev,
171 "no mac address in device tree, not configuring\n");
172 return -ENOENT;
173 }
174
olof@lixom.net1af7f052007-05-12 14:57:46 -0500175
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600176 if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
177 &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
178 dev_warn(&pdev->dev,
179 "can't parse mac address, not configuring\n");
180 return -EINVAL;
181 }
182
olof@lixom.net1af7f052007-05-12 14:57:46 -0500183 memcpy(mac->mac_addr, addr, 6);
184
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600185 return 0;
186}
187
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500188static int pasemi_mac_unmap_tx_skb(struct pasemi_mac *mac,
189 struct sk_buff *skb,
190 dma_addr_t *dmas)
191{
192 int f;
193 int nfrags = skb_shinfo(skb)->nr_frags;
194
195 pci_unmap_single(mac->dma_pdev, dmas[0], skb_headlen(skb),
196 PCI_DMA_TODEVICE);
197
198 for (f = 0; f < nfrags; f++) {
199 skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
200
201 pci_unmap_page(mac->dma_pdev, dmas[f+1], frag->size,
202 PCI_DMA_TODEVICE);
203 }
204 dev_kfree_skb_irq(skb);
205
206 /* Freed descriptor slot + main SKB ptr + nfrags additional ptrs,
207 * aligned up to a power of 2
208 */
209 return (nfrags + 3) & ~1;
210}
211
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600212static int pasemi_mac_setup_rx_resources(struct net_device *dev)
213{
214 struct pasemi_mac_rxring *ring;
215 struct pasemi_mac *mac = netdev_priv(dev);
216 int chan_id = mac->dma_rxch;
Olof Johanssonaf289e82007-10-03 13:03:54 -0500217 unsigned int cfg;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600218
219 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
220
221 if (!ring)
222 goto out_ring;
223
224 spin_lock_init(&ring->lock);
225
Olof Johansson021fa222007-08-22 09:13:11 -0500226 ring->size = RX_RING_SIZE;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500227 ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600228 RX_RING_SIZE, GFP_KERNEL);
229
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500230 if (!ring->ring_info)
231 goto out_ring_info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600232
233 /* Allocate descriptors */
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500234 ring->ring = dma_alloc_coherent(&mac->dma_pdev->dev,
235 RX_RING_SIZE * sizeof(u64),
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600236 &ring->dma, GFP_KERNEL);
237
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500238 if (!ring->ring)
239 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600240
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500241 memset(ring->ring, 0, RX_RING_SIZE * sizeof(u64));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600242
243 ring->buffers = dma_alloc_coherent(&mac->dma_pdev->dev,
244 RX_RING_SIZE * sizeof(u64),
245 &ring->buf_dma, GFP_KERNEL);
246 if (!ring->buffers)
247 goto out_buffers;
248
249 memset(ring->buffers, 0, RX_RING_SIZE * sizeof(u64));
250
Olof Johanssona85b9422007-09-15 13:40:59 -0700251 write_dma_reg(mac, PAS_DMA_RXCHAN_BASEL(chan_id), PAS_DMA_RXCHAN_BASEL_BRBL(ring->dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600252
Olof Johanssona85b9422007-09-15 13:40:59 -0700253 write_dma_reg(mac, PAS_DMA_RXCHAN_BASEU(chan_id),
254 PAS_DMA_RXCHAN_BASEU_BRBH(ring->dma >> 32) |
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500255 PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 3));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600256
Olof Johanssonaf289e82007-10-03 13:03:54 -0500257 cfg = PAS_DMA_RXCHAN_CFG_HBU(2);
258
259 if (translation_enabled())
260 cfg |= PAS_DMA_RXCHAN_CFG_CTR;
261
262 write_dma_reg(mac, PAS_DMA_RXCHAN_CFG(chan_id), cfg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600263
Olof Johanssona85b9422007-09-15 13:40:59 -0700264 write_dma_reg(mac, PAS_DMA_RXINT_BASEL(mac->dma_if),
Olof Johanssonaf289e82007-10-03 13:03:54 -0500265 PAS_DMA_RXINT_BASEL_BRBL(ring->buf_dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600266
Olof Johanssona85b9422007-09-15 13:40:59 -0700267 write_dma_reg(mac, PAS_DMA_RXINT_BASEU(mac->dma_if),
Olof Johanssonaf289e82007-10-03 13:03:54 -0500268 PAS_DMA_RXINT_BASEU_BRBH(ring->buf_dma >> 32) |
Olof Johanssona85b9422007-09-15 13:40:59 -0700269 PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600270
Olof Johanssonaf289e82007-10-03 13:03:54 -0500271 cfg = PAS_DMA_RXINT_CFG_DHL(3) | PAS_DMA_RXINT_CFG_L2 |
272 PAS_DMA_RXINT_CFG_LW | PAS_DMA_RXINT_CFG_RBP |
273 PAS_DMA_RXINT_CFG_HEN;
274
275 if (translation_enabled())
276 cfg |= PAS_DMA_RXINT_CFG_ITRR | PAS_DMA_RXINT_CFG_ITR;
277
278 write_dma_reg(mac, PAS_DMA_RXINT_CFG(mac->dma_if), cfg);
Olof Johanssonc0efd522007-08-22 09:12:52 -0500279
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600280 ring->next_to_fill = 0;
281 ring->next_to_clean = 0;
282
Olof Johansson72b05b92007-11-28 20:54:28 -0600283 ring->status = &dma_status->rx_sta[mac->dma_rxch];
284 ring->mac = mac;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600285 mac->rx = ring;
286
287 return 0;
288
289out_buffers:
290 dma_free_coherent(&mac->dma_pdev->dev,
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500291 RX_RING_SIZE * sizeof(u64),
Olof Johansson72b05b92007-11-28 20:54:28 -0600292 rx_ring(mac)->ring, rx_ring(mac)->dma);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500293out_ring_desc:
294 kfree(ring->ring_info);
295out_ring_info:
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600296 kfree(ring);
297out_ring:
298 return -ENOMEM;
299}
300
Olof Johansson72b05b92007-11-28 20:54:28 -0600301static struct pasemi_mac_txring *
302pasemi_mac_setup_tx_resources(struct net_device *dev, int txch)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600303{
304 struct pasemi_mac *mac = netdev_priv(dev);
305 u32 val;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600306 struct pasemi_mac_txring *ring;
Olof Johanssonaf289e82007-10-03 13:03:54 -0500307 unsigned int cfg;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600308
309 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
310 if (!ring)
311 goto out_ring;
312
313 spin_lock_init(&ring->lock);
314
Olof Johansson021fa222007-08-22 09:13:11 -0500315 ring->size = TX_RING_SIZE;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500316 ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600317 TX_RING_SIZE, GFP_KERNEL);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500318 if (!ring->ring_info)
319 goto out_ring_info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600320
321 /* Allocate descriptors */
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500322 ring->ring = dma_alloc_coherent(&mac->dma_pdev->dev,
323 TX_RING_SIZE * sizeof(u64),
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600324 &ring->dma, GFP_KERNEL);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500325 if (!ring->ring)
326 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600327
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500328 memset(ring->ring, 0, TX_RING_SIZE * sizeof(u64));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600329
Olof Johansson72b05b92007-11-28 20:54:28 -0600330 write_dma_reg(mac, PAS_DMA_TXCHAN_BASEL(txch),
Olof Johanssona85b9422007-09-15 13:40:59 -0700331 PAS_DMA_TXCHAN_BASEL_BRBL(ring->dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600332 val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->dma >> 32);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500333 val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 3);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600334
Olof Johansson72b05b92007-11-28 20:54:28 -0600335 write_dma_reg(mac, PAS_DMA_TXCHAN_BASEU(txch), val);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600336
Olof Johanssonaf289e82007-10-03 13:03:54 -0500337 cfg = PAS_DMA_TXCHAN_CFG_TY_IFACE |
338 PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) |
339 PAS_DMA_TXCHAN_CFG_UP |
340 PAS_DMA_TXCHAN_CFG_WT(2);
341
342 if (translation_enabled())
343 cfg |= PAS_DMA_TXCHAN_CFG_TRD | PAS_DMA_TXCHAN_CFG_TRR;
344
Olof Johansson72b05b92007-11-28 20:54:28 -0600345 write_dma_reg(mac, PAS_DMA_TXCHAN_CFG(txch), cfg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600346
Olof Johansson021fa222007-08-22 09:13:11 -0500347 ring->next_to_fill = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600348 ring->next_to_clean = 0;
Olof Johansson72b05b92007-11-28 20:54:28 -0600349 ring->status = &dma_status->tx_sta[txch];
350 ring->chan = txch;
351 ring->mac = mac;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600352
Olof Johansson72b05b92007-11-28 20:54:28 -0600353 return ring;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600354
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500355out_ring_desc:
356 kfree(ring->ring_info);
357out_ring_info:
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600358 kfree(ring);
359out_ring:
Olof Johansson72b05b92007-11-28 20:54:28 -0600360 return NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600361}
362
Olof Johansson72b05b92007-11-28 20:54:28 -0600363static void pasemi_mac_free_tx_resources(struct pasemi_mac *mac)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600364{
Olof Johansson72b05b92007-11-28 20:54:28 -0600365 struct pasemi_mac_txring *txring = tx_ring(mac);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500366 unsigned int i, j;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600367 struct pasemi_mac_buffer *info;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500368 dma_addr_t dmas[MAX_SKB_FRAGS+1];
369 int freed;
Olof Johanssonad5da102007-10-02 16:27:15 -0500370 int start, limit;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600371
Olof Johansson72b05b92007-11-28 20:54:28 -0600372 start = txring->next_to_clean;
373 limit = txring->next_to_fill;
Olof Johanssonad5da102007-10-02 16:27:15 -0500374
375 /* Compensate for when fill has wrapped and clean has not */
376 if (start > limit)
377 limit += TX_RING_SIZE;
378
379 for (i = start; i < limit; i += freed) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600380 info = &txring->ring_info[(i+1) & (TX_RING_SIZE-1)];
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500381 if (info->dma && info->skb) {
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500382 for (j = 0; j <= skb_shinfo(info->skb)->nr_frags; j++)
Olof Johansson72b05b92007-11-28 20:54:28 -0600383 dmas[j] = txring->ring_info[(i+1+j) &
384 (TX_RING_SIZE-1)].dma;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500385 freed = pasemi_mac_unmap_tx_skb(mac, info->skb, dmas);
386 } else
387 freed = 2;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600388 }
389
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500390 for (i = 0; i < TX_RING_SIZE; i++)
Olof Johansson72b05b92007-11-28 20:54:28 -0600391 txring->ring[i] = 0;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500392
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600393 dma_free_coherent(&mac->dma_pdev->dev,
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500394 TX_RING_SIZE * sizeof(u64),
Olof Johansson72b05b92007-11-28 20:54:28 -0600395 txring->ring, txring->dma);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600396
Olof Johansson72b05b92007-11-28 20:54:28 -0600397 kfree(txring->ring_info);
398 kfree(txring);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600399}
400
Olof Johansson72b05b92007-11-28 20:54:28 -0600401static void pasemi_mac_free_rx_resources(struct pasemi_mac *mac)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600402{
Olof Johansson72b05b92007-11-28 20:54:28 -0600403 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600404 unsigned int i;
405 struct pasemi_mac_buffer *info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600406
407 for (i = 0; i < RX_RING_SIZE; i++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600408 info = &RX_DESC_INFO(rx, i);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500409 if (info->skb && info->dma) {
410 pci_unmap_single(mac->dma_pdev,
411 info->dma,
412 info->skb->len,
413 PCI_DMA_FROMDEVICE);
414 dev_kfree_skb_any(info->skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600415 }
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500416 info->dma = 0;
417 info->skb = NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600418 }
419
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500420 for (i = 0; i < RX_RING_SIZE; i++)
Olof Johansson72b05b92007-11-28 20:54:28 -0600421 RX_DESC(rx, i) = 0;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500422
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600423 dma_free_coherent(&mac->dma_pdev->dev,
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500424 RX_RING_SIZE * sizeof(u64),
Olof Johansson72b05b92007-11-28 20:54:28 -0600425 rx_ring(mac)->ring, rx_ring(mac)->dma);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600426
427 dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
Olof Johansson72b05b92007-11-28 20:54:28 -0600428 rx_ring(mac)->buffers, rx_ring(mac)->buf_dma);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600429
Olof Johansson72b05b92007-11-28 20:54:28 -0600430 kfree(rx_ring(mac)->ring_info);
431 kfree(rx_ring(mac));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600432 mac->rx = NULL;
433}
434
Olof Johansson928773c2007-09-26 16:25:06 -0500435static void pasemi_mac_replenish_rx_ring(struct net_device *dev, int limit)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600436{
437 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -0600438 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500439 int fill, count;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600440
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500441 if (limit <= 0)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600442 return;
443
Olof Johansson72b05b92007-11-28 20:54:28 -0600444 fill = rx_ring(mac)->next_to_fill;
Olof Johansson928773c2007-09-26 16:25:06 -0500445 for (count = 0; count < limit; count++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600446 struct pasemi_mac_buffer *info = &RX_DESC_INFO(rx, fill);
447 u64 *buff = &RX_BUFF(rx, fill);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600448 struct sk_buff *skb;
449 dma_addr_t dma;
450
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500451 /* Entry in use? */
452 WARN_ON(*buff);
453
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500454 /* skb might still be in there for recycle on short receives */
455 if (info->skb)
456 skb = info->skb;
Olof Johansson8dc121a2007-10-02 16:26:53 -0500457 else {
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500458 skb = dev_alloc_skb(BUF_SIZE);
Olof Johansson8dc121a2007-10-02 16:26:53 -0500459 skb_reserve(skb, LOCAL_SKB_ALIGN);
460 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600461
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500462 if (unlikely(!skb))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600463 break;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600464
Olof Johansson8dc121a2007-10-02 16:26:53 -0500465 dma = pci_map_single(mac->dma_pdev, skb->data,
466 BUF_SIZE - LOCAL_SKB_ALIGN,
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600467 PCI_DMA_FROMDEVICE);
468
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500469 if (unlikely(dma_mapping_error(dma))) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600470 dev_kfree_skb_irq(info->skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600471 break;
472 }
473
474 info->skb = skb;
475 info->dma = dma;
476 *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500477 fill++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600478 }
479
480 wmb();
481
Olof Johansson928773c2007-09-26 16:25:06 -0500482 write_dma_reg(mac, PAS_DMA_RXINT_INCR(mac->dma_if), count);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600483
Olof Johansson72b05b92007-11-28 20:54:28 -0600484 rx_ring(mac)->next_to_fill = (rx_ring(mac)->next_to_fill + count) &
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500485 (RX_RING_SIZE - 1);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600486}
487
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500488static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac)
489{
Olof Johansson52a94352007-05-12 18:01:09 -0500490 unsigned int reg, pcnt;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500491 /* Re-enable packet count interrupts: finally
492 * ack the packet count interrupt we got in rx_intr.
493 */
494
Olof Johansson72b05b92007-11-28 20:54:28 -0600495 pcnt = *rx_ring(mac)->status & PAS_STATUS_PCNT_M;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500496
Olof Johansson52a94352007-05-12 18:01:09 -0500497 reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500498
Olof Johanssona85b9422007-09-15 13:40:59 -0700499 write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500500}
501
502static void pasemi_mac_restart_tx_intr(struct pasemi_mac *mac)
503{
Olof Johansson52a94352007-05-12 18:01:09 -0500504 unsigned int reg, pcnt;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500505
506 /* Re-enable packet count interrupts */
Olof Johansson72b05b92007-11-28 20:54:28 -0600507 pcnt = *tx_ring(mac)->status & PAS_STATUS_PCNT_M;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500508
Olof Johansson52a94352007-05-12 18:01:09 -0500509 reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500510
Olof Johansson72b05b92007-11-28 20:54:28 -0600511 write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(tx_ring(mac)->chan), reg);
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500512}
513
514
Olof Johansson69c29d82007-10-02 16:24:51 -0500515static inline void pasemi_mac_rx_error(struct pasemi_mac *mac, u64 macrx)
516{
517 unsigned int rcmdsta, ccmdsta;
518
519 if (!netif_msg_rx_err(mac))
520 return;
521
522 rcmdsta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
523 ccmdsta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
524
525 printk(KERN_ERR "pasemi_mac: rx error. macrx %016lx, rx status %lx\n",
Olof Johansson72b05b92007-11-28 20:54:28 -0600526 macrx, *rx_ring(mac)->status);
Olof Johansson69c29d82007-10-02 16:24:51 -0500527
528 printk(KERN_ERR "pasemi_mac: rcmdsta %08x ccmdsta %08x\n",
529 rcmdsta, ccmdsta);
530}
531
532static inline void pasemi_mac_tx_error(struct pasemi_mac *mac, u64 mactx)
533{
534 unsigned int cmdsta;
535
536 if (!netif_msg_tx_err(mac))
537 return;
538
539 cmdsta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
540
541 printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016lx, "\
Olof Johansson72b05b92007-11-28 20:54:28 -0600542 "tx status 0x%016lx\n", mactx, *tx_ring(mac)->status);
Olof Johansson69c29d82007-10-02 16:24:51 -0500543
544 printk(KERN_ERR "pasemi_mac: tcmdsta 0x%08x\n", cmdsta);
545}
546
Olof Johansson72b05b92007-11-28 20:54:28 -0600547static int pasemi_mac_clean_rx(struct pasemi_mac_rxring *rx, int limit)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600548{
Olof Johansson72b05b92007-11-28 20:54:28 -0600549 struct pasemi_mac *mac = rx->mac;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500550 unsigned int n;
551 int count;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500552 struct pasemi_mac_buffer *info;
553 struct sk_buff *skb;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500554 unsigned int len;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500555 u64 macrx;
556 dma_addr_t dma;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500557 int buf_index;
558 u64 eval;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600559
Olof Johansson72b05b92007-11-28 20:54:28 -0600560 spin_lock(&rx->lock);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600561
Olof Johansson72b05b92007-11-28 20:54:28 -0600562 n = rx->next_to_clean;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600563
Olof Johansson72b05b92007-11-28 20:54:28 -0600564 prefetch(&RX_DESC(rx, n));
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500565
566 for (count = 0; count < limit; count++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600567 macrx = RX_DESC(rx, n);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600568
Olof Johansson69c29d82007-10-02 16:24:51 -0500569 if ((macrx & XCT_MACRX_E) ||
Olof Johansson72b05b92007-11-28 20:54:28 -0600570 (*rx_ring(mac)->status & PAS_STATUS_ERROR))
Olof Johansson69c29d82007-10-02 16:24:51 -0500571 pasemi_mac_rx_error(mac, macrx);
572
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500573 if (!(macrx & XCT_MACRX_O))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600574 break;
575
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600576 info = NULL;
577
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500578 BUG_ON(!(macrx & XCT_MACRX_RR_8BRES));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600579
Olof Johansson72b05b92007-11-28 20:54:28 -0600580 eval = (RX_DESC(rx, n+1) & XCT_RXRES_8B_EVAL_M) >>
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500581 XCT_RXRES_8B_EVAL_S;
582 buf_index = eval-1;
583
Olof Johansson72b05b92007-11-28 20:54:28 -0600584 dma = (RX_DESC(rx, n+2) & XCT_PTR_ADDR_M);
585 info = &RX_DESC_INFO(rx, buf_index);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500586
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500587 skb = info->skb;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600588
Olof Johanssonad5da102007-10-02 16:27:15 -0500589 prefetch(skb);
590 prefetch(&skb->data_len);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600591
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500592 len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600593
Olof Johansson32bee772007-11-06 22:21:38 -0600594 pci_unmap_single(mac->dma_pdev, dma, len, PCI_DMA_FROMDEVICE);
595
596 if (macrx & XCT_MACRX_CRC) {
597 /* CRC error flagged */
598 mac->netdev->stats.rx_errors++;
599 mac->netdev->stats.rx_crc_errors++;
Olof Johansson4352d822007-12-03 21:34:14 -0600600 /* No need to free skb, it'll be reused */
Olof Johansson32bee772007-11-06 22:21:38 -0600601 goto next;
602 }
603
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500604 if (len < 256) {
Olof Johansson8dc121a2007-10-02 16:26:53 -0500605 struct sk_buff *new_skb;
606
607 new_skb = netdev_alloc_skb(mac->netdev,
608 len + LOCAL_SKB_ALIGN);
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500609 if (new_skb) {
Olof Johansson8dc121a2007-10-02 16:26:53 -0500610 skb_reserve(new_skb, LOCAL_SKB_ALIGN);
Olof Johansson73344862007-08-22 09:12:55 -0500611 memcpy(new_skb->data, skb->data, len);
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500612 /* save the skb in buffer_info as good */
613 skb = new_skb;
614 }
615 /* else just continue with the old one */
616 } else
617 info->skb = NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600618
Olof Johanssonad5da102007-10-02 16:27:15 -0500619 info->dma = 0;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500620
Olof Johansson32bee772007-11-06 22:21:38 -0600621 /* Don't include CRC */
622 skb_put(skb, len-4);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600623
Olof Johansson26fcfa92007-08-22 09:12:59 -0500624 if (likely((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK)) {
Olof Johansson38bf3182007-08-22 09:13:24 -0500625 skb->ip_summed = CHECKSUM_UNNECESSARY;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500626 skb->csum = (macrx & XCT_MACRX_CSUM_M) >>
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600627 XCT_MACRX_CSUM_S;
628 } else
629 skb->ip_summed = CHECKSUM_NONE;
630
Jeff Garzik09f75cd2007-10-03 17:41:50 -0700631 mac->netdev->stats.rx_bytes += len;
632 mac->netdev->stats.rx_packets++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600633
Olof Johansson26fcfa92007-08-22 09:12:59 -0500634 skb->protocol = eth_type_trans(skb, mac->netdev);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600635 netif_receive_skb(skb);
636
Olof Johansson32bee772007-11-06 22:21:38 -0600637next:
Olof Johansson72b05b92007-11-28 20:54:28 -0600638 RX_DESC(rx, n) = 0;
639 RX_DESC(rx, n+1) = 0;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500640
Olof Johanssonad5da102007-10-02 16:27:15 -0500641 /* Need to zero it out since hardware doesn't, since the
642 * replenish loop uses it to tell when it's done.
643 */
Olof Johansson72b05b92007-11-28 20:54:28 -0600644 RX_BUFF(rx, buf_index) = 0;
Olof Johanssonad5da102007-10-02 16:27:15 -0500645
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500646 n += 4;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600647 }
648
Olof Johansson9a50beb2007-10-02 16:26:30 -0500649 if (n > RX_RING_SIZE) {
650 /* Errata 5971 workaround: L2 target of headers */
651 write_iob_reg(mac, PAS_IOB_COM_PKTHDRCNT, 0);
652 n &= (RX_RING_SIZE-1);
653 }
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500654
Olof Johansson72b05b92007-11-28 20:54:28 -0600655 rx_ring(mac)->next_to_clean = n;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500656
657 /* Increase is in number of 16-byte entries, and since each descriptor
658 * with an 8BRES takes up 3x8 bytes (padded to 4x8), increase with
659 * count*2.
660 */
661 write_dma_reg(mac, PAS_DMA_RXCHAN_INCR(mac->dma_rxch), count << 1);
662
663 pasemi_mac_replenish_rx_ring(mac->netdev, count);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600664
Olof Johansson72b05b92007-11-28 20:54:28 -0600665 spin_unlock(&rx_ring(mac)->lock);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600666
667 return count;
668}
669
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500670/* Can't make this too large or we blow the kernel stack limits */
671#define TX_CLEAN_BATCHSIZE (128/MAX_SKB_FRAGS)
672
Olof Johansson72b05b92007-11-28 20:54:28 -0600673static int pasemi_mac_clean_tx(struct pasemi_mac_txring *txring)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600674{
Olof Johansson72b05b92007-11-28 20:54:28 -0600675 struct pasemi_mac *mac = txring->mac;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500676 int i, j;
Olof Johanssonad5da102007-10-02 16:27:15 -0500677 unsigned int start, descr_count, buf_count, batch_limit;
678 unsigned int ring_limit;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500679 unsigned int total_count;
Olof Johanssonca7e2352007-09-26 16:23:59 -0500680 unsigned long flags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500681 struct sk_buff *skbs[TX_CLEAN_BATCHSIZE];
682 dma_addr_t dmas[TX_CLEAN_BATCHSIZE][MAX_SKB_FRAGS+1];
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600683
Olof Johansson02df6cf2007-08-22 09:13:03 -0500684 total_count = 0;
Olof Johanssonad5da102007-10-02 16:27:15 -0500685 batch_limit = TX_CLEAN_BATCHSIZE;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500686restart:
Olof Johansson72b05b92007-11-28 20:54:28 -0600687 spin_lock_irqsave(&txring->lock, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600688
Olof Johansson72b05b92007-11-28 20:54:28 -0600689 start = txring->next_to_clean;
690 ring_limit = txring->next_to_fill;
Olof Johanssonad5da102007-10-02 16:27:15 -0500691
692 /* Compensate for when fill has wrapped but clean has not */
693 if (start > ring_limit)
694 ring_limit += TX_RING_SIZE;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500695
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500696 buf_count = 0;
697 descr_count = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600698
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500699 for (i = start;
Olof Johanssonad5da102007-10-02 16:27:15 -0500700 descr_count < batch_limit && i < ring_limit;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500701 i += buf_count) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600702 u64 mactx = TX_DESC(txring, i);
Olof Johanssonad5da102007-10-02 16:27:15 -0500703 struct sk_buff *skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500704
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500705 if ((mactx & XCT_MACTX_E) ||
Olof Johansson72b05b92007-11-28 20:54:28 -0600706 (*tx_ring(mac)->status & PAS_STATUS_ERROR))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500707 pasemi_mac_tx_error(mac, mactx);
Olof Johansson69c29d82007-10-02 16:24:51 -0500708
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500709 if (unlikely(mactx & XCT_MACTX_O))
Olof Johansson02df6cf2007-08-22 09:13:03 -0500710 /* Not yet transmitted */
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600711 break;
712
Olof Johansson72b05b92007-11-28 20:54:28 -0600713 skb = TX_DESC_INFO(txring, i+1).skb;
Olof Johanssonad5da102007-10-02 16:27:15 -0500714 skbs[descr_count] = skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500715
Olof Johanssonad5da102007-10-02 16:27:15 -0500716 buf_count = 2 + skb_shinfo(skb)->nr_frags;
717 for (j = 0; j <= skb_shinfo(skb)->nr_frags; j++)
Olof Johansson72b05b92007-11-28 20:54:28 -0600718 dmas[descr_count][j] = TX_DESC_INFO(txring, i+1+j).dma;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500719
Olof Johansson72b05b92007-11-28 20:54:28 -0600720 TX_DESC(txring, i) = 0;
721 TX_DESC(txring, i+1) = 0;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500722
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500723 /* Since we always fill with an even number of entries, make
724 * sure we skip any unused one at the end as well.
725 */
726 if (buf_count & 1)
727 buf_count++;
728 descr_count++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600729 }
Olof Johansson72b05b92007-11-28 20:54:28 -0600730 txring->next_to_clean = i & (TX_RING_SIZE-1);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500731
Olof Johansson72b05b92007-11-28 20:54:28 -0600732 spin_unlock_irqrestore(&txring->lock, flags);
Olof Johansson0ce68c72007-04-28 15:36:40 -0500733 netif_wake_queue(mac->netdev);
734
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500735 for (i = 0; i < descr_count; i++)
736 pasemi_mac_unmap_tx_skb(mac, skbs[i], dmas[i]);
Olof Johansson02df6cf2007-08-22 09:13:03 -0500737
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500738 total_count += descr_count;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500739
740 /* If the batch was full, try to clean more */
Olof Johanssonad5da102007-10-02 16:27:15 -0500741 if (descr_count == batch_limit)
Olof Johansson02df6cf2007-08-22 09:13:03 -0500742 goto restart;
743
744 return total_count;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600745}
746
747
748static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
749{
750 struct net_device *dev = data;
751 struct pasemi_mac *mac = netdev_priv(dev);
752 unsigned int reg;
753
Olof Johansson72b05b92007-11-28 20:54:28 -0600754 if (!(*rx_ring(mac)->status & PAS_STATUS_CAUSE_M))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600755 return IRQ_NONE;
756
Olof Johansson6dfa7522007-05-08 00:47:32 -0500757 /* Don't reset packet count so it won't fire again but clear
758 * all others.
759 */
760
Olof Johansson6dfa7522007-05-08 00:47:32 -0500761 reg = 0;
Olof Johansson72b05b92007-11-28 20:54:28 -0600762 if (*rx_ring(mac)->status & PAS_STATUS_SOFT)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500763 reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
Olof Johansson72b05b92007-11-28 20:54:28 -0600764 if (*rx_ring(mac)->status & PAS_STATUS_ERROR)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500765 reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
Olof Johansson72b05b92007-11-28 20:54:28 -0600766 if (*rx_ring(mac)->status & PAS_STATUS_TIMER)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600767 reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
768
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700769 netif_rx_schedule(dev, &mac->napi);
Olof Johansson6dfa7522007-05-08 00:47:32 -0500770
Olof Johanssona85b9422007-09-15 13:40:59 -0700771 write_iob_reg(mac, PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600772
773 return IRQ_HANDLED;
774}
775
776static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
777{
Olof Johansson72b05b92007-11-28 20:54:28 -0600778 struct pasemi_mac_txring *txring = data;
779 struct pasemi_mac *mac = txring->mac;
Olof Johansson52a94352007-05-12 18:01:09 -0500780 unsigned int reg, pcnt;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600781
Olof Johansson72b05b92007-11-28 20:54:28 -0600782 if (!(*txring->status & PAS_STATUS_CAUSE_M))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600783 return IRQ_NONE;
784
Olof Johansson72b05b92007-11-28 20:54:28 -0600785 pasemi_mac_clean_tx(txring);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600786
Olof Johansson72b05b92007-11-28 20:54:28 -0600787 pcnt = *txring->status & PAS_STATUS_PCNT_M;
Olof Johansson52a94352007-05-12 18:01:09 -0500788
789 reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
Olof Johansson6dfa7522007-05-08 00:47:32 -0500790
Olof Johansson72b05b92007-11-28 20:54:28 -0600791 if (*txring->status & PAS_STATUS_SOFT)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500792 reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
Olof Johansson72b05b92007-11-28 20:54:28 -0600793 if (*txring->status & PAS_STATUS_ERROR)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500794 reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600795
Olof Johansson72b05b92007-11-28 20:54:28 -0600796 write_iob_reg(mac, PAS_IOB_DMA_TXCH_RESET(txring->chan), reg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600797
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600798 return IRQ_HANDLED;
799}
800
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500801static void pasemi_adjust_link(struct net_device *dev)
802{
803 struct pasemi_mac *mac = netdev_priv(dev);
804 int msg;
805 unsigned int flags;
806 unsigned int new_flags;
807
808 if (!mac->phydev->link) {
809 /* If no link, MAC speed settings don't matter. Just report
810 * link down and return.
811 */
812 if (mac->link && netif_msg_link(mac))
813 printk(KERN_INFO "%s: Link is down.\n", dev->name);
814
815 netif_carrier_off(dev);
816 mac->link = 0;
817
818 return;
819 } else
820 netif_carrier_on(dev);
821
Olof Johanssona85b9422007-09-15 13:40:59 -0700822 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500823 new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M |
824 PAS_MAC_CFG_PCFG_TSR_M);
825
826 if (!mac->phydev->duplex)
827 new_flags |= PAS_MAC_CFG_PCFG_HD;
828
829 switch (mac->phydev->speed) {
830 case 1000:
831 new_flags |= PAS_MAC_CFG_PCFG_SPD_1G |
832 PAS_MAC_CFG_PCFG_TSR_1G;
833 break;
834 case 100:
835 new_flags |= PAS_MAC_CFG_PCFG_SPD_100M |
836 PAS_MAC_CFG_PCFG_TSR_100M;
837 break;
838 case 10:
839 new_flags |= PAS_MAC_CFG_PCFG_SPD_10M |
840 PAS_MAC_CFG_PCFG_TSR_10M;
841 break;
842 default:
843 printk("Unsupported speed %d\n", mac->phydev->speed);
844 }
845
846 /* Print on link or speed/duplex change */
847 msg = mac->link != mac->phydev->link || flags != new_flags;
848
849 mac->duplex = mac->phydev->duplex;
850 mac->speed = mac->phydev->speed;
851 mac->link = mac->phydev->link;
852
853 if (new_flags != flags)
Olof Johanssona85b9422007-09-15 13:40:59 -0700854 write_mac_reg(mac, PAS_MAC_CFG_PCFG, new_flags);
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500855
856 if (msg && netif_msg_link(mac))
857 printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n",
858 dev->name, mac->speed, mac->duplex ? "full" : "half");
859}
860
861static int pasemi_mac_phy_init(struct net_device *dev)
862{
863 struct pasemi_mac *mac = netdev_priv(dev);
864 struct device_node *dn, *phy_dn;
865 struct phy_device *phydev;
866 unsigned int phy_id;
867 const phandle *ph;
868 const unsigned int *prop;
869 struct resource r;
870 int ret;
871
872 dn = pci_device_to_OF_node(mac->pdev);
Linus Torvalds90287802007-05-08 11:57:17 -0700873 ph = of_get_property(dn, "phy-handle", NULL);
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500874 if (!ph)
875 return -ENODEV;
876 phy_dn = of_find_node_by_phandle(*ph);
877
Linus Torvalds90287802007-05-08 11:57:17 -0700878 prop = of_get_property(phy_dn, "reg", NULL);
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500879 ret = of_address_to_resource(phy_dn->parent, 0, &r);
880 if (ret)
881 goto err;
882
883 phy_id = *prop;
884 snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id);
885
886 of_node_put(phy_dn);
887
888 mac->link = 0;
889 mac->speed = 0;
890 mac->duplex = -1;
891
892 phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
893
894 if (IS_ERR(phydev)) {
895 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
896 return PTR_ERR(phydev);
897 }
898
899 mac->phydev = phydev;
900
901 return 0;
902
903err:
904 of_node_put(phy_dn);
905 return -ENODEV;
906}
907
908
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600909static int pasemi_mac_open(struct net_device *dev)
910{
911 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson771f7402007-05-08 00:47:21 -0500912 int base_irq;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600913 unsigned int flags;
914 int ret;
915
916 /* enable rx section */
Olof Johanssona85b9422007-09-15 13:40:59 -0700917 write_dma_reg(mac, PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600918
919 /* enable tx section */
Olof Johanssona85b9422007-09-15 13:40:59 -0700920 write_dma_reg(mac, PAS_DMA_COM_TXCMD, PAS_DMA_COM_TXCMD_EN);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600921
922 flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
923 PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
924 PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12);
925
Olof Johanssona85b9422007-09-15 13:40:59 -0700926 write_mac_reg(mac, PAS_MAC_CFG_TXP, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600927
Olof Johanssona85b9422007-09-15 13:40:59 -0700928 write_iob_reg(mac, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch),
929 PAS_IOB_DMA_RXCH_CFG_CNTTH(0));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600930
Olof Johanssona85b9422007-09-15 13:40:59 -0700931 write_iob_reg(mac, PAS_IOB_DMA_TXCH_CFG(mac->dma_txch),
Olof Johansson02df6cf2007-08-22 09:13:03 -0500932 PAS_IOB_DMA_TXCH_CFG_CNTTH(128));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600933
Olof Johansson6dfa7522007-05-08 00:47:32 -0500934 /* 0xffffff is max value, about 16ms */
Olof Johanssona85b9422007-09-15 13:40:59 -0700935 write_iob_reg(mac, PAS_IOB_DMA_COM_TIMEOUTCFG,
936 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0xffffff));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600937
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600938 ret = pasemi_mac_setup_rx_resources(dev);
939 if (ret)
940 goto out_rx_resources;
941
Olof Johansson72b05b92007-11-28 20:54:28 -0600942 mac->tx = pasemi_mac_setup_tx_resources(dev, mac->dma_txch);
943
944 if (!mac->tx)
945 goto out_tx_ring;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600946
Olof Johanssona85b9422007-09-15 13:40:59 -0700947 write_mac_reg(mac, PAS_MAC_IPC_CHNL,
948 PAS_MAC_IPC_CHNL_DCHNO(mac->dma_rxch) |
949 PAS_MAC_IPC_CHNL_BCH(mac->dma_rxch));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600950
951 /* enable rx if */
Olof Johanssona85b9422007-09-15 13:40:59 -0700952 write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
Olof Johansson9e81d332007-10-02 16:27:39 -0500953 PAS_DMA_RXINT_RCMDSTA_EN |
954 PAS_DMA_RXINT_RCMDSTA_DROPS_M |
955 PAS_DMA_RXINT_RCMDSTA_BP |
956 PAS_DMA_RXINT_RCMDSTA_OO |
957 PAS_DMA_RXINT_RCMDSTA_BT);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600958
959 /* enable rx channel */
Olof Johanssona85b9422007-09-15 13:40:59 -0700960 write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
961 PAS_DMA_RXCHAN_CCMDSTA_EN |
Olof Johansson9e81d332007-10-02 16:27:39 -0500962 PAS_DMA_RXCHAN_CCMDSTA_DU |
963 PAS_DMA_RXCHAN_CCMDSTA_OD |
964 PAS_DMA_RXCHAN_CCMDSTA_FD |
965 PAS_DMA_RXCHAN_CCMDSTA_DT);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600966
967 /* enable tx channel */
Olof Johanssona85b9422007-09-15 13:40:59 -0700968 write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
Olof Johansson9e81d332007-10-02 16:27:39 -0500969 PAS_DMA_TXCHAN_TCMDSTA_EN |
970 PAS_DMA_TXCHAN_TCMDSTA_SZ |
971 PAS_DMA_TXCHAN_TCMDSTA_DB |
972 PAS_DMA_TXCHAN_TCMDSTA_DE |
973 PAS_DMA_TXCHAN_TCMDSTA_DA);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600974
Olof Johansson928773c2007-09-26 16:25:06 -0500975 pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600976
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500977 write_dma_reg(mac, PAS_DMA_RXCHAN_INCR(mac->dma_rxch), RX_RING_SIZE>>1);
978
Olof Johansson72b05b92007-11-28 20:54:28 -0600979 /* Clear out any residual packet count state from firmware */
980 pasemi_mac_restart_rx_intr(mac);
981 pasemi_mac_restart_tx_intr(mac);
982
Olof Johansson36033762007-09-26 16:24:42 -0500983 flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PE |
984 PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE;
985
986 if (mac->type == MAC_TYPE_GMAC)
987 flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
988 else
989 flags |= PAS_MAC_CFG_PCFG_TSR_10G | PAS_MAC_CFG_PCFG_SPD_10G;
990
991 /* Enable interface in MAC */
992 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
993
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500994 ret = pasemi_mac_phy_init(dev);
995 /* Some configs don't have PHYs (XAUI etc), so don't complain about
996 * failed init due to -ENODEV.
997 */
998 if (ret && ret != -ENODEV)
999 dev_warn(&mac->pdev->dev, "phy init failed: %d\n", ret);
1000
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001001 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001002 napi_enable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001003
Olof Johansson771f7402007-05-08 00:47:21 -05001004 /* Interrupts are a bit different for our DMA controller: While
1005 * it's got one a regular PCI device header, the interrupt there
1006 * is really the base of the range it's using. Each tx and rx
1007 * channel has it's own interrupt source.
1008 */
1009
1010 base_irq = virq_to_hw(mac->dma_pdev->irq);
1011
1012 mac->tx_irq = irq_create_mapping(NULL, base_irq + mac->dma_txch);
Olof Johansson72b05b92007-11-28 20:54:28 -06001013
1014 snprintf(mac->tx_irq_name, sizeof(mac->tx_irq_name), "%s tx",
1015 dev->name);
Olof Johansson771f7402007-05-08 00:47:21 -05001016
1017 ret = request_irq(mac->tx_irq, &pasemi_mac_tx_intr, IRQF_DISABLED,
Olof Johansson72b05b92007-11-28 20:54:28 -06001018 mac->tx_irq_name, mac->tx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001019 if (ret) {
1020 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
Olof Johansson771f7402007-05-08 00:47:21 -05001021 base_irq + mac->dma_txch, ret);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001022 goto out_tx_int;
1023 }
1024
Olof Johansson72b05b92007-11-28 20:54:28 -06001025 mac->rx_irq = irq_create_mapping(NULL, base_irq + 20 + mac->dma_rxch);
1026
1027 snprintf(mac->rx_irq_name, sizeof(mac->rx_irq_name), "%s rx",
1028 dev->name);
1029
Olof Johansson771f7402007-05-08 00:47:21 -05001030 ret = request_irq(mac->rx_irq, &pasemi_mac_rx_intr, IRQF_DISABLED,
Olof Johansson72b05b92007-11-28 20:54:28 -06001031 mac->rx_irq_name, dev);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001032 if (ret) {
1033 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
Olof Johansson771f7402007-05-08 00:47:21 -05001034 base_irq + 20 + mac->dma_rxch, ret);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001035 goto out_rx_int;
1036 }
1037
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001038 if (mac->phydev)
1039 phy_start(mac->phydev);
1040
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001041 return 0;
1042
1043out_rx_int:
Olof Johansson72b05b92007-11-28 20:54:28 -06001044 free_irq(mac->tx_irq, mac->tx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001045out_tx_int:
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001046 napi_disable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001047 netif_stop_queue(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -06001048out_tx_ring:
1049 if (mac->tx)
1050 pasemi_mac_free_tx_resources(mac);
1051 pasemi_mac_free_rx_resources(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001052out_rx_resources:
1053
1054 return ret;
1055}
1056
1057#define MAX_RETRIES 5000
1058
1059static int pasemi_mac_close(struct net_device *dev)
1060{
1061 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson9e81d332007-10-02 16:27:39 -05001062 unsigned int sta;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001063 int retries;
1064
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001065 if (mac->phydev) {
1066 phy_stop(mac->phydev);
1067 phy_disconnect(mac->phydev);
1068 }
1069
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001070 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001071 napi_disable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001072
Olof Johansson9e81d332007-10-02 16:27:39 -05001073 sta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
1074 if (sta & (PAS_DMA_RXINT_RCMDSTA_BP |
1075 PAS_DMA_RXINT_RCMDSTA_OO |
1076 PAS_DMA_RXINT_RCMDSTA_BT))
1077 printk(KERN_DEBUG "pasemi_mac: rcmdsta error: 0x%08x\n", sta);
1078
1079 sta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
1080 if (sta & (PAS_DMA_RXCHAN_CCMDSTA_DU |
1081 PAS_DMA_RXCHAN_CCMDSTA_OD |
1082 PAS_DMA_RXCHAN_CCMDSTA_FD |
1083 PAS_DMA_RXCHAN_CCMDSTA_DT))
1084 printk(KERN_DEBUG "pasemi_mac: ccmdsta error: 0x%08x\n", sta);
1085
1086 sta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
Olof Johansson72b05b92007-11-28 20:54:28 -06001087 if (sta & (PAS_DMA_TXCHAN_TCMDSTA_SZ | PAS_DMA_TXCHAN_TCMDSTA_DB |
1088 PAS_DMA_TXCHAN_TCMDSTA_DE | PAS_DMA_TXCHAN_TCMDSTA_DA))
Olof Johansson9e81d332007-10-02 16:27:39 -05001089 printk(KERN_DEBUG "pasemi_mac: tcmdsta error: 0x%08x\n", sta);
1090
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001091 /* Clean out any pending buffers */
Olof Johansson72b05b92007-11-28 20:54:28 -06001092 pasemi_mac_clean_tx(tx_ring(mac));
1093 pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001094
1095 /* Disable interface */
Olof Johansson72b05b92007-11-28 20:54:28 -06001096 write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
1097 PAS_DMA_TXCHAN_TCMDSTA_ST);
1098 write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1099 PAS_DMA_RXINT_RCMDSTA_ST);
1100 write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
1101 PAS_DMA_RXCHAN_CCMDSTA_ST);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001102
1103 for (retries = 0; retries < MAX_RETRIES; retries++) {
Olof Johansson9e81d332007-10-02 16:27:39 -05001104 sta = read_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch));
1105 if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT))
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001106 break;
1107 cond_resched();
1108 }
1109
Olof Johansson9e81d332007-10-02 16:27:39 -05001110 if (sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)
Olof Johansson72b05b92007-11-28 20:54:28 -06001111 dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel %d\n",
1112 mac->dma_txch);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001113
1114 for (retries = 0; retries < MAX_RETRIES; retries++) {
Olof Johansson9e81d332007-10-02 16:27:39 -05001115 sta = read_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch));
1116 if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT))
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001117 break;
1118 cond_resched();
1119 }
1120
Olof Johansson9e81d332007-10-02 16:27:39 -05001121 if (sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001122 dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n");
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001123
1124 for (retries = 0; retries < MAX_RETRIES; retries++) {
Olof Johansson9e81d332007-10-02 16:27:39 -05001125 sta = read_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
1126 if (!(sta & PAS_DMA_RXINT_RCMDSTA_ACT))
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001127 break;
1128 cond_resched();
1129 }
1130
Olof Johansson9e81d332007-10-02 16:27:39 -05001131 if (sta & PAS_DMA_RXINT_RCMDSTA_ACT)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001132 dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n");
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001133
1134 /* Then, disable the channel. This must be done separately from
1135 * stopping, since you can't disable when active.
1136 */
1137
Olof Johanssona85b9422007-09-15 13:40:59 -07001138 write_dma_reg(mac, PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), 0);
1139 write_dma_reg(mac, PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), 0);
1140 write_dma_reg(mac, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001141
Olof Johansson72b05b92007-11-28 20:54:28 -06001142 free_irq(mac->tx_irq, mac->tx);
1143 free_irq(mac->rx_irq, mac->rx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001144
1145 /* Free resources */
Olof Johansson72b05b92007-11-28 20:54:28 -06001146 pasemi_mac_free_rx_resources(mac);
1147 pasemi_mac_free_tx_resources(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001148
1149 return 0;
1150}
1151
1152static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
1153{
1154 struct pasemi_mac *mac = netdev_priv(dev);
1155 struct pasemi_mac_txring *txring;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001156 u64 dflags, mactx;
1157 dma_addr_t map[MAX_SKB_FRAGS+1];
1158 unsigned int map_size[MAX_SKB_FRAGS+1];
Olof Johanssonca7e2352007-09-26 16:23:59 -05001159 unsigned long flags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001160 int i, nfrags;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001161
Olof Johanssondbd62af2007-11-06 22:20:39 -06001162 dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_CRC_PAD;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001163
1164 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -07001165 const unsigned char *nh = skb_network_header(skb);
1166
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -07001167 switch (ip_hdr(skb)->protocol) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001168 case IPPROTO_TCP:
1169 dflags |= XCT_MACTX_CSUM_TCP;
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -03001170 dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2);
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -07001171 dflags |= XCT_MACTX_IPO(nh - skb->data);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001172 break;
1173 case IPPROTO_UDP:
1174 dflags |= XCT_MACTX_CSUM_UDP;
Arnaldo Carvalho de Melocfe1fc72007-03-16 17:26:39 -03001175 dflags |= XCT_MACTX_IPH(skb_network_header_len(skb) >> 2);
Arnaldo Carvalho de Melod56f90a2007-04-10 20:50:43 -07001176 dflags |= XCT_MACTX_IPO(nh - skb->data);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001177 break;
1178 }
1179 }
1180
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001181 nfrags = skb_shinfo(skb)->nr_frags;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001182
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001183 map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb),
1184 PCI_DMA_TODEVICE);
1185 map_size[0] = skb_headlen(skb);
1186 if (dma_mapping_error(map[0]))
1187 goto out_err_nolock;
1188
1189 for (i = 0; i < nfrags; i++) {
1190 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1191
1192 map[i+1] = pci_map_page(mac->dma_pdev, frag->page,
1193 frag->page_offset, frag->size,
1194 PCI_DMA_TODEVICE);
1195 map_size[i+1] = frag->size;
1196 if (dma_mapping_error(map[i+1])) {
1197 nfrags = i;
1198 goto out_err_nolock;
1199 }
1200 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001201
Olof Johansson26fcfa92007-08-22 09:12:59 -05001202 mactx = dflags | XCT_MACTX_LLEN(skb->len);
Olof Johansson26fcfa92007-08-22 09:12:59 -05001203
Olof Johansson72b05b92007-11-28 20:54:28 -06001204 txring = tx_ring(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001205
1206 spin_lock_irqsave(&txring->lock, flags);
1207
Olof Johanssonad5da102007-10-02 16:27:15 -05001208 /* Avoid stepping on the same cache line that the DMA controller
1209 * is currently about to send, so leave at least 8 words available.
1210 * Total free space needed is mactx + fragments + 8
1211 */
1212 if (RING_AVAIL(txring) < nfrags + 10) {
1213 /* no room -- stop the queue and wait for tx intr */
1214 netif_stop_queue(dev);
1215 goto out_err;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001216 }
1217
Olof Johansson72b05b92007-11-28 20:54:28 -06001218 TX_DESC(txring, txring->next_to_fill) = mactx;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001219 txring->next_to_fill++;
Olof Johansson72b05b92007-11-28 20:54:28 -06001220 TX_DESC_INFO(txring, txring->next_to_fill).skb = skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001221 for (i = 0; i <= nfrags; i++) {
Olof Johansson72b05b92007-11-28 20:54:28 -06001222 TX_DESC(txring, txring->next_to_fill+i) =
1223 XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]);
1224 TX_DESC_INFO(txring, txring->next_to_fill+i).dma = map[i];
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001225 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001226
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001227 /* We have to add an even number of 8-byte entries to the ring
1228 * even if the last one is unused. That means always an odd number
1229 * of pointers + one mactx descriptor.
1230 */
1231 if (nfrags & 1)
1232 nfrags++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001233
Olof Johanssonad5da102007-10-02 16:27:15 -05001234 txring->next_to_fill = (txring->next_to_fill + nfrags + 1) &
1235 (TX_RING_SIZE-1);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -05001236
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001237 dev->stats.tx_packets++;
1238 dev->stats.tx_bytes += skb->len;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001239
1240 spin_unlock_irqrestore(&txring->lock, flags);
1241
Olof Johansson72b05b92007-11-28 20:54:28 -06001242 write_dma_reg(mac, PAS_DMA_TXCHAN_INCR(txring->chan), (nfrags+2) >> 1);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001243
1244 return NETDEV_TX_OK;
1245
1246out_err:
1247 spin_unlock_irqrestore(&txring->lock, flags);
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001248out_err_nolock:
1249 while (nfrags--)
1250 pci_unmap_single(mac->dma_pdev, map[nfrags], map_size[nfrags],
1251 PCI_DMA_TODEVICE);
1252
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001253 return NETDEV_TX_BUSY;
1254}
1255
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001256static void pasemi_mac_set_rx_mode(struct net_device *dev)
1257{
1258 struct pasemi_mac *mac = netdev_priv(dev);
1259 unsigned int flags;
1260
Olof Johanssona85b9422007-09-15 13:40:59 -07001261 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001262
1263 /* Set promiscuous */
1264 if (dev->flags & IFF_PROMISC)
1265 flags |= PAS_MAC_CFG_PCFG_PR;
1266 else
1267 flags &= ~PAS_MAC_CFG_PCFG_PR;
1268
Olof Johanssona85b9422007-09-15 13:40:59 -07001269 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001270}
1271
1272
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001273static int pasemi_mac_poll(struct napi_struct *napi, int budget)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001274{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001275 struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi);
1276 struct net_device *dev = mac->netdev;
1277 int pkts;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001278
Olof Johansson72b05b92007-11-28 20:54:28 -06001279 pasemi_mac_clean_tx(tx_ring(mac));
1280 pkts = pasemi_mac_clean_rx(rx_ring(mac), budget);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001281 if (pkts < budget) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001282 /* all done, no more packets present */
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001283 netif_rx_complete(dev, napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001284
Olof Johansson1b0335ea2007-05-08 00:47:26 -05001285 pasemi_mac_restart_rx_intr(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001286 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001287 return pkts;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001288}
1289
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001290static void __iomem * __devinit map_onedev(struct pci_dev *p, int index)
1291{
1292 struct device_node *dn;
1293 void __iomem *ret;
1294
1295 dn = pci_device_to_OF_node(p);
1296 if (!dn)
1297 goto fallback;
1298
1299 ret = of_iomap(dn, index);
1300 if (!ret)
1301 goto fallback;
1302
1303 return ret;
1304fallback:
1305 /* This is hardcoded and ugly, but we have some firmware versions
1306 * that don't provide the register space in the device tree. Luckily
1307 * they are at well-known locations so we can just do the math here.
1308 */
1309 return ioremap(0xe0000000 + (p->devfn << 12), 0x2000);
1310}
1311
1312static int __devinit pasemi_mac_map_regs(struct pasemi_mac *mac)
1313{
1314 struct resource res;
1315 struct device_node *dn;
1316 int err;
1317
1318 mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
1319 if (!mac->dma_pdev) {
1320 dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
1321 return -ENODEV;
1322 }
1323
1324 mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
1325 if (!mac->iob_pdev) {
1326 dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
1327 return -ENODEV;
1328 }
1329
1330 mac->regs = map_onedev(mac->pdev, 0);
1331 mac->dma_regs = map_onedev(mac->dma_pdev, 0);
1332 mac->iob_regs = map_onedev(mac->iob_pdev, 0);
1333
1334 if (!mac->regs || !mac->dma_regs || !mac->iob_regs) {
1335 dev_err(&mac->pdev->dev, "Can't map registers\n");
1336 return -ENODEV;
1337 }
1338
1339 /* The dma status structure is located in the I/O bridge, and
1340 * is cache coherent.
1341 */
1342 if (!dma_status) {
1343 dn = pci_device_to_OF_node(mac->iob_pdev);
1344 if (dn)
1345 err = of_address_to_resource(dn, 1, &res);
1346 if (!dn || err) {
1347 /* Fallback for old firmware */
1348 res.start = 0xfd800000;
1349 res.end = res.start + 0x1000;
1350 }
1351 dma_status = __ioremap(res.start, res.end-res.start, 0);
1352 }
1353
1354 return 0;
1355}
1356
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001357static int __devinit
1358pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1359{
1360 static int index = 0;
1361 struct net_device *dev;
1362 struct pasemi_mac *mac;
1363 int err;
Joe Perches0795af52007-10-03 17:59:30 -07001364 DECLARE_MAC_BUF(mac_buf);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001365
1366 err = pci_enable_device(pdev);
1367 if (err)
1368 return err;
1369
1370 dev = alloc_etherdev(sizeof(struct pasemi_mac));
1371 if (dev == NULL) {
1372 dev_err(&pdev->dev,
1373 "pasemi_mac: Could not allocate ethernet device.\n");
1374 err = -ENOMEM;
1375 goto out_disable_device;
1376 }
1377
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001378 pci_set_drvdata(pdev, dev);
1379 SET_NETDEV_DEV(dev, &pdev->dev);
1380
1381 mac = netdev_priv(dev);
1382
1383 mac->pdev = pdev;
1384 mac->netdev = dev;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001385
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001386 netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64);
1387
David Woodhouse0581d3f2007-12-03 04:34:32 +00001388 dev->features = NETIF_F_IP_CSUM | NETIF_F_LLTX | NETIF_F_SG;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001389
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001390 /* These should come out of the device tree eventually */
1391 mac->dma_txch = index;
1392 mac->dma_rxch = index;
1393
1394 /* We probe GMAC before XAUI, but the DMA interfaces are
1395 * in XAUI, GMAC order.
1396 */
1397 if (index < 4)
1398 mac->dma_if = index + 2;
1399 else
1400 mac->dma_if = index - 4;
1401 index++;
1402
1403 switch (pdev->device) {
1404 case 0xa005:
1405 mac->type = MAC_TYPE_GMAC;
1406 break;
1407 case 0xa006:
1408 mac->type = MAC_TYPE_XAUI;
1409 break;
1410 default:
1411 err = -ENODEV;
1412 goto out;
1413 }
1414
1415 /* get mac addr from device tree */
1416 if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) {
1417 err = -ENODEV;
1418 goto out;
1419 }
1420 memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
1421
1422 dev->open = pasemi_mac_open;
1423 dev->stop = pasemi_mac_close;
1424 dev->hard_start_xmit = pasemi_mac_start_tx;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001425 dev->set_multicast_list = pasemi_mac_set_rx_mode;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001426
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001427 err = pasemi_mac_map_regs(mac);
1428 if (err)
1429 goto out;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001430
Olof Johanssonceb51362007-05-08 00:47:49 -05001431 mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
1432
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001433 /* Enable most messages by default */
1434 mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
1435
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001436 err = register_netdev(dev);
1437
1438 if (err) {
1439 dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n",
1440 err);
1441 goto out;
Olof Johansson69c29d82007-10-02 16:24:51 -05001442 } else if netif_msg_probe(mac)
Olof Johansson72b05b92007-11-28 20:54:28 -06001443 printk(KERN_INFO "%s: PA Semi %s: intf %d, hw addr %s\n",
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001444 dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
Olof Johansson72b05b92007-11-28 20:54:28 -06001445 mac->dma_if, print_mac(mac_buf, dev->dev_addr));
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001446
1447 return err;
1448
1449out:
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001450 if (mac->iob_pdev)
1451 pci_dev_put(mac->iob_pdev);
1452 if (mac->dma_pdev)
1453 pci_dev_put(mac->dma_pdev);
1454 if (mac->dma_regs)
1455 iounmap(mac->dma_regs);
1456 if (mac->iob_regs)
1457 iounmap(mac->iob_regs);
1458 if (mac->regs)
1459 iounmap(mac->regs);
1460
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001461 free_netdev(dev);
1462out_disable_device:
1463 pci_disable_device(pdev);
1464 return err;
1465
1466}
1467
1468static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
1469{
1470 struct net_device *netdev = pci_get_drvdata(pdev);
1471 struct pasemi_mac *mac;
1472
1473 if (!netdev)
1474 return;
1475
1476 mac = netdev_priv(netdev);
1477
1478 unregister_netdev(netdev);
1479
1480 pci_disable_device(pdev);
1481 pci_dev_put(mac->dma_pdev);
1482 pci_dev_put(mac->iob_pdev);
1483
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001484 iounmap(mac->regs);
1485 iounmap(mac->dma_regs);
1486 iounmap(mac->iob_regs);
1487
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001488 pci_set_drvdata(pdev, NULL);
1489 free_netdev(netdev);
1490}
1491
1492static struct pci_device_id pasemi_mac_pci_tbl[] = {
1493 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
1494 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
olof@lixom.netfd178252007-05-12 14:57:36 -05001495 { },
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001496};
1497
1498MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
1499
1500static struct pci_driver pasemi_mac_driver = {
1501 .name = "pasemi_mac",
1502 .id_table = pasemi_mac_pci_tbl,
1503 .probe = pasemi_mac_probe,
1504 .remove = __devexit_p(pasemi_mac_remove),
1505};
1506
1507static void __exit pasemi_mac_cleanup_module(void)
1508{
1509 pci_unregister_driver(&pasemi_mac_driver);
1510 __iounmap(dma_status);
1511 dma_status = NULL;
1512}
1513
1514int pasemi_mac_init_module(void)
1515{
1516 return pci_register_driver(&pasemi_mac_driver);
1517}
1518
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001519module_init(pasemi_mac_init_module);
1520module_exit(pasemi_mac_cleanup_module);