blob: 2f4a837f0d6adcb066d6deb952859d6a711026e4 [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
Jeff Kirsher0ab75ae2013-12-06 06:28:43 -080016 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Olof Johanssonf5cd7872007-01-31 21:43:54 -060017 */
18
Olof Johanssonf5cd7872007-01-31 21:43:54 -060019#include <linux/module.h>
20#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/slab.h>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060022#include <linux/interrupt.h>
23#include <linux/dmaengine.h>
24#include <linux/delay.h>
25#include <linux/netdevice.h>
Grant Likely1dd2d062009-04-25 12:53:17 +000026#include <linux/of_mdio.h>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060027#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>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060033#include <net/checksum.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040034#include <linux/prefetch.h>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060035
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 * - Multiqueue RX/TX
Olof Johanssonf5cd7872007-01-31 21:43:54 -060054 */
55
Olof Johanssonef1ea0b2008-01-23 13:56:47 -060056#define PE_MIN_MTU 64
Olof Johansson8d636d82008-03-05 16:34:16 -060057#define PE_MAX_MTU 9000
Olof Johanssonef1ea0b2008-01-23 13:56:47 -060058#define PE_DEF_MTU ETH_DATA_LEN
59
Olof Johanssonceb51362007-05-08 00:47:49 -050060#define DEFAULT_MSG_ENABLE \
61 (NETIF_MSG_DRV | \
62 NETIF_MSG_PROBE | \
63 NETIF_MSG_LINK | \
64 NETIF_MSG_TIMER | \
65 NETIF_MSG_IFDOWN | \
66 NETIF_MSG_IFUP | \
67 NETIF_MSG_RX_ERR | \
68 NETIF_MSG_TX_ERR)
69
Olof Johanssonceb51362007-05-08 00:47:49 -050070MODULE_LICENSE("GPL");
71MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
72MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
73
74static int debug = -1; /* -1 == use DEFAULT_MSG_ENABLE as value */
75module_param(debug, int, 0);
76MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
Olof Johanssonf5cd7872007-01-31 21:43:54 -060077
Olof Johanssone37c7722008-02-20 20:57:59 -060078extern const struct ethtool_ops pasemi_mac_ethtool_ops;
79
Olof Johanssonaf289e82007-10-03 13:03:54 -050080static int translation_enabled(void)
81{
82#if defined(CONFIG_PPC_PASEMI_IOMMU_DMA_FORCE)
83 return 1;
84#else
85 return firmware_has_feature(FW_FEATURE_LPAR);
86#endif
87}
88
Olof Johansson34c20622007-11-28 20:56:32 -060089static void write_iob_reg(unsigned int reg, unsigned int val)
Olof Johanssona85b9422007-09-15 13:40:59 -070090{
Olof Johansson34c20622007-11-28 20:56:32 -060091 pasemi_write_iob_reg(reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -070092}
93
Olof Johansson5c153322007-11-28 20:56:41 -060094static unsigned int read_mac_reg(const struct pasemi_mac *mac, unsigned int reg)
Olof Johanssona85b9422007-09-15 13:40:59 -070095{
Olof Johansson34c20622007-11-28 20:56:32 -060096 return pasemi_read_mac_reg(mac->dma_if, reg);
Olof Johanssona85b9422007-09-15 13:40:59 -070097}
98
Olof Johansson5c153322007-11-28 20:56:41 -060099static void write_mac_reg(const struct pasemi_mac *mac, unsigned int reg,
Olof Johanssona85b9422007-09-15 13:40:59 -0700100 unsigned int val)
101{
Olof Johansson34c20622007-11-28 20:56:32 -0600102 pasemi_write_mac_reg(mac->dma_if, reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700103}
104
Olof Johansson34c20622007-11-28 20:56:32 -0600105static unsigned int read_dma_reg(unsigned int reg)
Olof Johanssona85b9422007-09-15 13:40:59 -0700106{
Olof Johansson34c20622007-11-28 20:56:32 -0600107 return pasemi_read_dma_reg(reg);
Olof Johanssona85b9422007-09-15 13:40:59 -0700108}
109
Olof Johansson34c20622007-11-28 20:56:32 -0600110static void write_dma_reg(unsigned int reg, unsigned int val)
Olof Johanssona85b9422007-09-15 13:40:59 -0700111{
Olof Johansson34c20622007-11-28 20:56:32 -0600112 pasemi_write_dma_reg(reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700113}
114
Olof Johansson5c153322007-11-28 20:56:41 -0600115static struct pasemi_mac_rxring *rx_ring(const struct pasemi_mac *mac)
Olof Johansson72b05b92007-11-28 20:54:28 -0600116{
117 return mac->rx;
118}
119
Olof Johansson5c153322007-11-28 20:56:41 -0600120static struct pasemi_mac_txring *tx_ring(const struct pasemi_mac *mac)
Olof Johansson72b05b92007-11-28 20:54:28 -0600121{
122 return mac->tx;
123}
124
Olof Johansson5c153322007-11-28 20:56:41 -0600125static inline void prefetch_skb(const struct sk_buff *skb)
126{
127 const void *d = skb;
128
129 prefetch(d);
130 prefetch(d+64);
131 prefetch(d+128);
132 prefetch(d+192);
133}
134
Olof Johansson34c20622007-11-28 20:56:32 -0600135static int mac_to_intf(struct pasemi_mac *mac)
136{
137 struct pci_dev *pdev = mac->pdev;
138 u32 tmp;
139 int nintf, off, i, j;
140 int devfn = pdev->devfn;
141
142 tmp = read_dma_reg(PAS_DMA_CAP_IFI);
143 nintf = (tmp & PAS_DMA_CAP_IFI_NIN_M) >> PAS_DMA_CAP_IFI_NIN_S;
144 off = (tmp & PAS_DMA_CAP_IFI_IOFF_M) >> PAS_DMA_CAP_IFI_IOFF_S;
145
146 /* IOFF contains the offset to the registers containing the
147 * DMA interface-to-MAC-pci-id mappings, and NIN contains number
148 * of total interfaces. Each register contains 4 devfns.
149 * Just do a linear search until we find the devfn of the MAC
150 * we're trying to look up.
151 */
152
153 for (i = 0; i < (nintf+3)/4; i++) {
154 tmp = read_dma_reg(off+4*i);
155 for (j = 0; j < 4; j++) {
156 if (((tmp >> (8*j)) & 0xff) == devfn)
157 return i*4 + j;
158 }
159 }
160 return -1;
161}
162
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600163static void pasemi_mac_intf_disable(struct pasemi_mac *mac)
164{
165 unsigned int flags;
166
167 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
168 flags &= ~PAS_MAC_CFG_PCFG_PE;
169 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
170}
171
172static void pasemi_mac_intf_enable(struct pasemi_mac *mac)
173{
174 unsigned int flags;
175
176 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
177 flags |= PAS_MAC_CFG_PCFG_PE;
178 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
179}
180
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600181static int pasemi_get_mac_addr(struct pasemi_mac *mac)
182{
183 struct pci_dev *pdev = mac->pdev;
184 struct device_node *dn = pci_device_to_OF_node(pdev);
olof@lixom.net1af7f052007-05-12 14:57:46 -0500185 int len;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600186 const u8 *maddr;
Joe Perches1409a932013-08-01 16:17:49 -0700187 u8 addr[ETH_ALEN];
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600188
189 if (!dn) {
190 dev_dbg(&pdev->dev,
191 "No device node for mac, not configuring\n");
192 return -ENOENT;
193 }
194
olof@lixom.net1af7f052007-05-12 14:57:46 -0500195 maddr = of_get_property(dn, "local-mac-address", &len);
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500196
Joe Perches1409a932013-08-01 16:17:49 -0700197 if (maddr && len == ETH_ALEN) {
198 memcpy(mac->mac_addr, maddr, ETH_ALEN);
olof@lixom.net1af7f052007-05-12 14:57:46 -0500199 return 0;
200 }
201
202 /* Some old versions of firmware mistakenly uses mac-address
203 * (and as a string) instead of a byte array in local-mac-address.
204 */
205
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500206 if (maddr == NULL)
Linus Torvalds90287802007-05-08 11:57:17 -0700207 maddr = of_get_property(dn, "mac-address", NULL);
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500208
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600209 if (maddr == NULL) {
210 dev_warn(&pdev->dev,
211 "no mac address in device tree, not configuring\n");
212 return -ENOENT;
213 }
214
Joe Perches1409a932013-08-01 16:17:49 -0700215 if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
216 &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5])
217 != ETH_ALEN) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600218 dev_warn(&pdev->dev,
219 "can't parse mac address, not configuring\n");
220 return -EINVAL;
221 }
222
Joe Perches1409a932013-08-01 16:17:49 -0700223 memcpy(mac->mac_addr, addr, ETH_ALEN);
olof@lixom.net1af7f052007-05-12 14:57:46 -0500224
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600225 return 0;
226}
227
Olof Johansson5cea73b2008-01-23 13:56:19 -0600228static int pasemi_mac_set_mac_addr(struct net_device *dev, void *p)
229{
230 struct pasemi_mac *mac = netdev_priv(dev);
231 struct sockaddr *addr = p;
232 unsigned int adr0, adr1;
233
234 if (!is_valid_ether_addr(addr->sa_data))
Danny Kukawka504f9b52012-02-21 02:07:49 +0000235 return -EADDRNOTAVAIL;
Olof Johansson5cea73b2008-01-23 13:56:19 -0600236
237 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
238
239 adr0 = dev->dev_addr[2] << 24 |
240 dev->dev_addr[3] << 16 |
241 dev->dev_addr[4] << 8 |
242 dev->dev_addr[5];
243 adr1 = read_mac_reg(mac, PAS_MAC_CFG_ADR1);
244 adr1 &= ~0xffff;
245 adr1 |= dev->dev_addr[0] << 8 | dev->dev_addr[1];
246
247 pasemi_mac_intf_disable(mac);
248 write_mac_reg(mac, PAS_MAC_CFG_ADR0, adr0);
249 write_mac_reg(mac, PAS_MAC_CFG_ADR1, adr1);
250 pasemi_mac_intf_enable(mac);
251
252 return 0;
253}
254
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500255static int pasemi_mac_unmap_tx_skb(struct pasemi_mac *mac,
Olof Johansson7e9916e2007-11-28 20:57:45 -0600256 const int nfrags,
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500257 struct sk_buff *skb,
Olof Johansson5c153322007-11-28 20:56:41 -0600258 const dma_addr_t *dmas)
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500259{
260 int f;
Olof Johansson5c153322007-11-28 20:56:41 -0600261 struct pci_dev *pdev = mac->dma_pdev;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500262
Olof Johansson5c153322007-11-28 20:56:41 -0600263 pci_unmap_single(pdev, dmas[0], skb_headlen(skb), PCI_DMA_TODEVICE);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500264
265 for (f = 0; f < nfrags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +0000266 const skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500267
Eric Dumazet9e903e02011-10-18 21:00:24 +0000268 pci_unmap_page(pdev, dmas[f+1], skb_frag_size(frag), PCI_DMA_TODEVICE);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500269 }
270 dev_kfree_skb_irq(skb);
271
272 /* Freed descriptor slot + main SKB ptr + nfrags additional ptrs,
273 * aligned up to a power of 2
274 */
275 return (nfrags + 3) & ~1;
276}
277
Olof Johansson8d636d82008-03-05 16:34:16 -0600278static struct pasemi_mac_csring *pasemi_mac_setup_csring(struct pasemi_mac *mac)
279{
280 struct pasemi_mac_csring *ring;
281 u32 val;
282 unsigned int cfg;
283 int chno;
284
285 ring = pasemi_dma_alloc_chan(TXCHAN, sizeof(struct pasemi_mac_csring),
286 offsetof(struct pasemi_mac_csring, chan));
287
288 if (!ring) {
289 dev_err(&mac->pdev->dev, "Can't allocate checksum channel\n");
290 goto out_chan;
291 }
292
293 chno = ring->chan.chno;
294
295 ring->size = CS_RING_SIZE;
296 ring->next_to_fill = 0;
297
298 /* Allocate descriptors */
299 if (pasemi_dma_alloc_ring(&ring->chan, CS_RING_SIZE))
300 goto out_ring_desc;
301
302 write_dma_reg(PAS_DMA_TXCHAN_BASEL(chno),
303 PAS_DMA_TXCHAN_BASEL_BRBL(ring->chan.ring_dma));
304 val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->chan.ring_dma >> 32);
305 val |= PAS_DMA_TXCHAN_BASEU_SIZ(CS_RING_SIZE >> 3);
306
307 write_dma_reg(PAS_DMA_TXCHAN_BASEU(chno), val);
308
309 ring->events[0] = pasemi_dma_alloc_flag();
310 ring->events[1] = pasemi_dma_alloc_flag();
311 if (ring->events[0] < 0 || ring->events[1] < 0)
312 goto out_flags;
313
314 pasemi_dma_clear_flag(ring->events[0]);
315 pasemi_dma_clear_flag(ring->events[1]);
316
317 ring->fun = pasemi_dma_alloc_fun();
318 if (ring->fun < 0)
319 goto out_fun;
320
321 cfg = PAS_DMA_TXCHAN_CFG_TY_FUNC | PAS_DMA_TXCHAN_CFG_UP |
322 PAS_DMA_TXCHAN_CFG_TATTR(ring->fun) |
323 PAS_DMA_TXCHAN_CFG_LPSQ | PAS_DMA_TXCHAN_CFG_LPDQ;
324
325 if (translation_enabled())
326 cfg |= PAS_DMA_TXCHAN_CFG_TRD | PAS_DMA_TXCHAN_CFG_TRR;
327
328 write_dma_reg(PAS_DMA_TXCHAN_CFG(chno), cfg);
329
330 /* enable channel */
331 pasemi_dma_start_chan(&ring->chan, PAS_DMA_TXCHAN_TCMDSTA_SZ |
332 PAS_DMA_TXCHAN_TCMDSTA_DB |
333 PAS_DMA_TXCHAN_TCMDSTA_DE |
334 PAS_DMA_TXCHAN_TCMDSTA_DA);
335
336 return ring;
337
338out_fun:
339out_flags:
340 if (ring->events[0] >= 0)
341 pasemi_dma_free_flag(ring->events[0]);
342 if (ring->events[1] >= 0)
343 pasemi_dma_free_flag(ring->events[1]);
344 pasemi_dma_free_ring(&ring->chan);
345out_ring_desc:
346 pasemi_dma_free_chan(&ring->chan);
347out_chan:
348
349 return NULL;
350}
351
352static void pasemi_mac_setup_csrings(struct pasemi_mac *mac)
353{
354 int i;
355 mac->cs[0] = pasemi_mac_setup_csring(mac);
356 if (mac->type == MAC_TYPE_XAUI)
357 mac->cs[1] = pasemi_mac_setup_csring(mac);
358 else
359 mac->cs[1] = 0;
360
361 for (i = 0; i < MAX_CS; i++)
362 if (mac->cs[i])
363 mac->num_cs++;
364}
365
366static void pasemi_mac_free_csring(struct pasemi_mac_csring *csring)
367{
368 pasemi_dma_stop_chan(&csring->chan);
369 pasemi_dma_free_flag(csring->events[0]);
370 pasemi_dma_free_flag(csring->events[1]);
371 pasemi_dma_free_ring(&csring->chan);
372 pasemi_dma_free_chan(&csring->chan);
Olof Johansson1724ac22008-03-25 09:58:40 -0500373 pasemi_dma_free_fun(csring->fun);
Olof Johansson8d636d82008-03-05 16:34:16 -0600374}
375
Olof Johansson5c153322007-11-28 20:56:41 -0600376static int pasemi_mac_setup_rx_resources(const struct net_device *dev)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600377{
378 struct pasemi_mac_rxring *ring;
379 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson34c20622007-11-28 20:56:32 -0600380 int chno;
Olof Johanssonaf289e82007-10-03 13:03:54 -0500381 unsigned int cfg;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600382
Olof Johansson34c20622007-11-28 20:56:32 -0600383 ring = pasemi_dma_alloc_chan(RXCHAN, sizeof(struct pasemi_mac_rxring),
384 offsetof(struct pasemi_mac_rxring, chan));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600385
Olof Johansson34c20622007-11-28 20:56:32 -0600386 if (!ring) {
387 dev_err(&mac->pdev->dev, "Can't allocate RX channel\n");
388 goto out_chan;
389 }
390 chno = ring->chan.chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600391
392 spin_lock_init(&ring->lock);
393
Olof Johansson021fa222007-08-22 09:13:11 -0500394 ring->size = RX_RING_SIZE;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500395 ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600396 RX_RING_SIZE, GFP_KERNEL);
397
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500398 if (!ring->ring_info)
399 goto out_ring_info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600400
401 /* Allocate descriptors */
Olof Johansson34c20622007-11-28 20:56:32 -0600402 if (pasemi_dma_alloc_ring(&ring->chan, RX_RING_SIZE))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500403 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600404
Joe Perchesede23fa2013-08-26 22:45:23 -0700405 ring->buffers = dma_zalloc_coherent(&mac->dma_pdev->dev,
406 RX_RING_SIZE * sizeof(u64),
407 &ring->buf_dma, GFP_KERNEL);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600408 if (!ring->buffers)
Olof Johansson34c20622007-11-28 20:56:32 -0600409 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600410
Olof Johansson34c20622007-11-28 20:56:32 -0600411 write_dma_reg(PAS_DMA_RXCHAN_BASEL(chno),
412 PAS_DMA_RXCHAN_BASEL_BRBL(ring->chan.ring_dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600413
Olof Johansson34c20622007-11-28 20:56:32 -0600414 write_dma_reg(PAS_DMA_RXCHAN_BASEU(chno),
415 PAS_DMA_RXCHAN_BASEU_BRBH(ring->chan.ring_dma >> 32) |
416 PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 3));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600417
Olof Johansson5c153322007-11-28 20:56:41 -0600418 cfg = PAS_DMA_RXCHAN_CFG_HBU(2);
Olof Johanssonaf289e82007-10-03 13:03:54 -0500419
420 if (translation_enabled())
421 cfg |= PAS_DMA_RXCHAN_CFG_CTR;
422
Olof Johansson34c20622007-11-28 20:56:32 -0600423 write_dma_reg(PAS_DMA_RXCHAN_CFG(chno), cfg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600424
Olof Johansson34c20622007-11-28 20:56:32 -0600425 write_dma_reg(PAS_DMA_RXINT_BASEL(mac->dma_if),
426 PAS_DMA_RXINT_BASEL_BRBL(ring->buf_dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600427
Olof Johansson34c20622007-11-28 20:56:32 -0600428 write_dma_reg(PAS_DMA_RXINT_BASEU(mac->dma_if),
429 PAS_DMA_RXINT_BASEU_BRBH(ring->buf_dma >> 32) |
430 PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600431
Olof Johansson5c153322007-11-28 20:56:41 -0600432 cfg = PAS_DMA_RXINT_CFG_DHL(2) | PAS_DMA_RXINT_CFG_L2 |
Olof Johanssonaf289e82007-10-03 13:03:54 -0500433 PAS_DMA_RXINT_CFG_LW | PAS_DMA_RXINT_CFG_RBP |
434 PAS_DMA_RXINT_CFG_HEN;
435
436 if (translation_enabled())
437 cfg |= PAS_DMA_RXINT_CFG_ITRR | PAS_DMA_RXINT_CFG_ITR;
438
Olof Johansson34c20622007-11-28 20:56:32 -0600439 write_dma_reg(PAS_DMA_RXINT_CFG(mac->dma_if), cfg);
Olof Johanssonc0efd522007-08-22 09:12:52 -0500440
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600441 ring->next_to_fill = 0;
442 ring->next_to_clean = 0;
Olof Johansson72b05b92007-11-28 20:54:28 -0600443 ring->mac = mac;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600444 mac->rx = ring;
445
446 return 0;
447
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500448out_ring_desc:
449 kfree(ring->ring_info);
450out_ring_info:
Olof Johansson34c20622007-11-28 20:56:32 -0600451 pasemi_dma_free_chan(&ring->chan);
452out_chan:
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600453 return -ENOMEM;
454}
455
Olof Johansson72b05b92007-11-28 20:54:28 -0600456static struct pasemi_mac_txring *
Olof Johansson5c153322007-11-28 20:56:41 -0600457pasemi_mac_setup_tx_resources(const struct net_device *dev)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600458{
459 struct pasemi_mac *mac = netdev_priv(dev);
460 u32 val;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600461 struct pasemi_mac_txring *ring;
Olof Johanssonaf289e82007-10-03 13:03:54 -0500462 unsigned int cfg;
Olof Johansson34c20622007-11-28 20:56:32 -0600463 int chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600464
Olof Johansson34c20622007-11-28 20:56:32 -0600465 ring = pasemi_dma_alloc_chan(TXCHAN, sizeof(struct pasemi_mac_txring),
466 offsetof(struct pasemi_mac_txring, chan));
467
468 if (!ring) {
469 dev_err(&mac->pdev->dev, "Can't allocate TX channel\n");
470 goto out_chan;
471 }
472
473 chno = ring->chan.chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600474
475 spin_lock_init(&ring->lock);
476
Olof Johansson021fa222007-08-22 09:13:11 -0500477 ring->size = TX_RING_SIZE;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500478 ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600479 TX_RING_SIZE, GFP_KERNEL);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500480 if (!ring->ring_info)
481 goto out_ring_info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600482
483 /* Allocate descriptors */
Olof Johansson34c20622007-11-28 20:56:32 -0600484 if (pasemi_dma_alloc_ring(&ring->chan, TX_RING_SIZE))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500485 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600486
Olof Johansson34c20622007-11-28 20:56:32 -0600487 write_dma_reg(PAS_DMA_TXCHAN_BASEL(chno),
488 PAS_DMA_TXCHAN_BASEL_BRBL(ring->chan.ring_dma));
489 val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->chan.ring_dma >> 32);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500490 val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 3);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600491
Olof Johansson34c20622007-11-28 20:56:32 -0600492 write_dma_reg(PAS_DMA_TXCHAN_BASEU(chno), val);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600493
Olof Johanssonaf289e82007-10-03 13:03:54 -0500494 cfg = PAS_DMA_TXCHAN_CFG_TY_IFACE |
495 PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) |
496 PAS_DMA_TXCHAN_CFG_UP |
Olof Johansson8d636d82008-03-05 16:34:16 -0600497 PAS_DMA_TXCHAN_CFG_WT(4);
Olof Johanssonaf289e82007-10-03 13:03:54 -0500498
499 if (translation_enabled())
500 cfg |= PAS_DMA_TXCHAN_CFG_TRD | PAS_DMA_TXCHAN_CFG_TRR;
501
Olof Johansson34c20622007-11-28 20:56:32 -0600502 write_dma_reg(PAS_DMA_TXCHAN_CFG(chno), cfg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600503
Olof Johansson021fa222007-08-22 09:13:11 -0500504 ring->next_to_fill = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600505 ring->next_to_clean = 0;
Olof Johansson72b05b92007-11-28 20:54:28 -0600506 ring->mac = mac;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600507
Olof Johansson72b05b92007-11-28 20:54:28 -0600508 return ring;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600509
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500510out_ring_desc:
511 kfree(ring->ring_info);
512out_ring_info:
Olof Johansson34c20622007-11-28 20:56:32 -0600513 pasemi_dma_free_chan(&ring->chan);
514out_chan:
Olof Johansson72b05b92007-11-28 20:54:28 -0600515 return NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600516}
517
Olof Johansson72b05b92007-11-28 20:54:28 -0600518static void pasemi_mac_free_tx_resources(struct pasemi_mac *mac)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600519{
Olof Johansson72b05b92007-11-28 20:54:28 -0600520 struct pasemi_mac_txring *txring = tx_ring(mac);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500521 unsigned int i, j;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600522 struct pasemi_mac_buffer *info;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500523 dma_addr_t dmas[MAX_SKB_FRAGS+1];
Olof Johansson7e9916e2007-11-28 20:57:45 -0600524 int freed, nfrags;
Olof Johanssonad5da102007-10-02 16:27:15 -0500525 int start, limit;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600526
Olof Johansson72b05b92007-11-28 20:54:28 -0600527 start = txring->next_to_clean;
528 limit = txring->next_to_fill;
Olof Johanssonad5da102007-10-02 16:27:15 -0500529
530 /* Compensate for when fill has wrapped and clean has not */
531 if (start > limit)
532 limit += TX_RING_SIZE;
533
534 for (i = start; i < limit; i += freed) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600535 info = &txring->ring_info[(i+1) & (TX_RING_SIZE-1)];
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500536 if (info->dma && info->skb) {
Olof Johansson7e9916e2007-11-28 20:57:45 -0600537 nfrags = skb_shinfo(info->skb)->nr_frags;
538 for (j = 0; j <= nfrags; j++)
Olof Johansson72b05b92007-11-28 20:54:28 -0600539 dmas[j] = txring->ring_info[(i+1+j) &
540 (TX_RING_SIZE-1)].dma;
Olof Johansson7e9916e2007-11-28 20:57:45 -0600541 freed = pasemi_mac_unmap_tx_skb(mac, nfrags,
542 info->skb, dmas);
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000543 } else {
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500544 freed = 2;
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000545 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600546 }
547
Olof Johansson72b05b92007-11-28 20:54:28 -0600548 kfree(txring->ring_info);
Olof Johansson34c20622007-11-28 20:56:32 -0600549 pasemi_dma_free_chan(&txring->chan);
550
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600551}
552
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600553static void pasemi_mac_free_rx_buffers(struct pasemi_mac *mac)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600554{
Olof Johansson72b05b92007-11-28 20:54:28 -0600555 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600556 unsigned int i;
557 struct pasemi_mac_buffer *info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600558
559 for (i = 0; i < RX_RING_SIZE; i++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600560 info = &RX_DESC_INFO(rx, i);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500561 if (info->skb && info->dma) {
562 pci_unmap_single(mac->dma_pdev,
563 info->dma,
564 info->skb->len,
565 PCI_DMA_FROMDEVICE);
566 dev_kfree_skb_any(info->skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600567 }
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500568 info->dma = 0;
569 info->skb = NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600570 }
571
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500572 for (i = 0; i < RX_RING_SIZE; i++)
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600573 RX_BUFF(rx, i) = 0;
574}
575
576static void pasemi_mac_free_rx_resources(struct pasemi_mac *mac)
577{
578 pasemi_mac_free_rx_buffers(mac);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500579
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600580 dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
Olof Johansson72b05b92007-11-28 20:54:28 -0600581 rx_ring(mac)->buffers, rx_ring(mac)->buf_dma);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600582
Olof Johansson72b05b92007-11-28 20:54:28 -0600583 kfree(rx_ring(mac)->ring_info);
Olof Johansson34c20622007-11-28 20:56:32 -0600584 pasemi_dma_free_chan(&rx_ring(mac)->chan);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600585 mac->rx = NULL;
586}
587
Stephen Rothwell5c6239c2012-05-03 10:51:46 +1000588static void pasemi_mac_replenish_rx_ring(struct net_device *dev,
Olof Johansson5c153322007-11-28 20:56:41 -0600589 const int limit)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600590{
Olof Johansson5c153322007-11-28 20:56:41 -0600591 const struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -0600592 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500593 int fill, count;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600594
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500595 if (limit <= 0)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600596 return;
597
Olof Johansson72b05b92007-11-28 20:54:28 -0600598 fill = rx_ring(mac)->next_to_fill;
Olof Johansson928773c2007-09-26 16:25:06 -0500599 for (count = 0; count < limit; count++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600600 struct pasemi_mac_buffer *info = &RX_DESC_INFO(rx, fill);
601 u64 *buff = &RX_BUFF(rx, fill);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600602 struct sk_buff *skb;
603 dma_addr_t dma;
604
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500605 /* Entry in use? */
606 WARN_ON(*buff);
607
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +0000608 skb = netdev_alloc_skb(dev, mac->bufsz);
Olof Johansson5d894942007-11-28 20:57:56 -0600609 skb_reserve(skb, LOCAL_SKB_ALIGN);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600610
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500611 if (unlikely(!skb))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600612 break;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600613
Olof Johansson8dc121a2007-10-02 16:26:53 -0500614 dma = pci_map_single(mac->dma_pdev, skb->data,
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600615 mac->bufsz - LOCAL_SKB_ALIGN,
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600616 PCI_DMA_FROMDEVICE);
617
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700618 if (unlikely(pci_dma_mapping_error(mac->dma_pdev, dma))) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600619 dev_kfree_skb_irq(info->skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600620 break;
621 }
622
623 info->skb = skb;
624 info->dma = dma;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600625 *buff = XCT_RXB_LEN(mac->bufsz) | XCT_RXB_ADDR(dma);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500626 fill++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600627 }
628
629 wmb();
630
Olof Johansson34c20622007-11-28 20:56:32 -0600631 write_dma_reg(PAS_DMA_RXINT_INCR(mac->dma_if), count);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600632
Olof Johansson72b05b92007-11-28 20:54:28 -0600633 rx_ring(mac)->next_to_fill = (rx_ring(mac)->next_to_fill + count) &
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500634 (RX_RING_SIZE - 1);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600635}
636
Olof Johansson5c153322007-11-28 20:56:41 -0600637static void pasemi_mac_restart_rx_intr(const struct pasemi_mac *mac)
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500638{
Olof Johansson906674a2007-11-28 20:57:09 -0600639 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johansson52a94352007-05-12 18:01:09 -0500640 unsigned int reg, pcnt;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500641 /* Re-enable packet count interrupts: finally
642 * ack the packet count interrupt we got in rx_intr.
643 */
644
Olof Johansson906674a2007-11-28 20:57:09 -0600645 pcnt = *rx->chan.status & PAS_STATUS_PCNT_M;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500646
Olof Johansson52a94352007-05-12 18:01:09 -0500647 reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500648
Olof Johansson906674a2007-11-28 20:57:09 -0600649 if (*rx->chan.status & PAS_STATUS_TIMER)
650 reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
651
Olof Johansson34c20622007-11-28 20:56:32 -0600652 write_iob_reg(PAS_IOB_DMA_RXCH_RESET(mac->rx->chan.chno), reg);
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500653}
654
Olof Johansson5c153322007-11-28 20:56:41 -0600655static void pasemi_mac_restart_tx_intr(const struct pasemi_mac *mac)
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500656{
Olof Johansson52a94352007-05-12 18:01:09 -0500657 unsigned int reg, pcnt;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500658
659 /* Re-enable packet count interrupts */
Olof Johansson34c20622007-11-28 20:56:32 -0600660 pcnt = *tx_ring(mac)->chan.status & PAS_STATUS_PCNT_M;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500661
Olof Johansson52a94352007-05-12 18:01:09 -0500662 reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500663
Olof Johansson34c20622007-11-28 20:56:32 -0600664 write_iob_reg(PAS_IOB_DMA_TXCH_RESET(tx_ring(mac)->chan.chno), reg);
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500665}
666
667
Olof Johansson5c153322007-11-28 20:56:41 -0600668static inline void pasemi_mac_rx_error(const struct pasemi_mac *mac,
669 const u64 macrx)
Olof Johansson69c29d82007-10-02 16:24:51 -0500670{
671 unsigned int rcmdsta, ccmdsta;
Olof Johansson34c20622007-11-28 20:56:32 -0600672 struct pasemi_dmachan *chan = &rx_ring(mac)->chan;
Olof Johansson69c29d82007-10-02 16:24:51 -0500673
674 if (!netif_msg_rx_err(mac))
675 return;
676
Olof Johansson34c20622007-11-28 20:56:32 -0600677 rcmdsta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
678 ccmdsta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(chan->chno));
Olof Johansson69c29d82007-10-02 16:24:51 -0500679
Ingo Molnarfe333322009-01-06 14:26:03 +0000680 printk(KERN_ERR "pasemi_mac: rx error. macrx %016llx, rx status %llx\n",
Olof Johansson34c20622007-11-28 20:56:32 -0600681 macrx, *chan->status);
Olof Johansson69c29d82007-10-02 16:24:51 -0500682
683 printk(KERN_ERR "pasemi_mac: rcmdsta %08x ccmdsta %08x\n",
684 rcmdsta, ccmdsta);
685}
686
Olof Johansson5c153322007-11-28 20:56:41 -0600687static inline void pasemi_mac_tx_error(const struct pasemi_mac *mac,
688 const u64 mactx)
Olof Johansson69c29d82007-10-02 16:24:51 -0500689{
690 unsigned int cmdsta;
Olof Johansson34c20622007-11-28 20:56:32 -0600691 struct pasemi_dmachan *chan = &tx_ring(mac)->chan;
Olof Johansson69c29d82007-10-02 16:24:51 -0500692
693 if (!netif_msg_tx_err(mac))
694 return;
695
Olof Johansson34c20622007-11-28 20:56:32 -0600696 cmdsta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(chan->chno));
Olof Johansson69c29d82007-10-02 16:24:51 -0500697
Ingo Molnarfe333322009-01-06 14:26:03 +0000698 printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016llx, "\
699 "tx status 0x%016llx\n", mactx, *chan->status);
Olof Johansson69c29d82007-10-02 16:24:51 -0500700
701 printk(KERN_ERR "pasemi_mac: tcmdsta 0x%08x\n", cmdsta);
702}
703
Olof Johansson5c153322007-11-28 20:56:41 -0600704static int pasemi_mac_clean_rx(struct pasemi_mac_rxring *rx,
705 const int limit)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600706{
Olof Johansson5c153322007-11-28 20:56:41 -0600707 const struct pasemi_dmachan *chan = &rx->chan;
Olof Johansson72b05b92007-11-28 20:54:28 -0600708 struct pasemi_mac *mac = rx->mac;
Olof Johansson5c153322007-11-28 20:56:41 -0600709 struct pci_dev *pdev = mac->dma_pdev;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500710 unsigned int n;
Olof Johansson5c153322007-11-28 20:56:41 -0600711 int count, buf_index, tot_bytes, packets;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500712 struct pasemi_mac_buffer *info;
713 struct sk_buff *skb;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500714 unsigned int len;
Olof Johansson5c153322007-11-28 20:56:41 -0600715 u64 macrx, eval;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500716 dma_addr_t dma;
Olof Johansson5c153322007-11-28 20:56:41 -0600717
718 tot_bytes = 0;
719 packets = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600720
Olof Johansson72b05b92007-11-28 20:54:28 -0600721 spin_lock(&rx->lock);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600722
Olof Johansson72b05b92007-11-28 20:54:28 -0600723 n = rx->next_to_clean;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600724
Olof Johansson72b05b92007-11-28 20:54:28 -0600725 prefetch(&RX_DESC(rx, n));
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500726
727 for (count = 0; count < limit; count++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600728 macrx = RX_DESC(rx, n);
Olof Johansson5c153322007-11-28 20:56:41 -0600729 prefetch(&RX_DESC(rx, n+4));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600730
Olof Johansson69c29d82007-10-02 16:24:51 -0500731 if ((macrx & XCT_MACRX_E) ||
Olof Johansson34c20622007-11-28 20:56:32 -0600732 (*chan->status & PAS_STATUS_ERROR))
Olof Johansson69c29d82007-10-02 16:24:51 -0500733 pasemi_mac_rx_error(mac, macrx);
734
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500735 if (!(macrx & XCT_MACRX_O))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600736 break;
737
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600738 info = NULL;
739
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500740 BUG_ON(!(macrx & XCT_MACRX_RR_8BRES));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600741
Olof Johansson72b05b92007-11-28 20:54:28 -0600742 eval = (RX_DESC(rx, n+1) & XCT_RXRES_8B_EVAL_M) >>
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500743 XCT_RXRES_8B_EVAL_S;
744 buf_index = eval-1;
745
Olof Johansson72b05b92007-11-28 20:54:28 -0600746 dma = (RX_DESC(rx, n+2) & XCT_PTR_ADDR_M);
747 info = &RX_DESC_INFO(rx, buf_index);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500748
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500749 skb = info->skb;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600750
Olof Johansson5c153322007-11-28 20:56:41 -0600751 prefetch_skb(skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600752
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500753 len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600754
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600755 pci_unmap_single(pdev, dma, mac->bufsz - LOCAL_SKB_ALIGN,
Olof Johansson5c153322007-11-28 20:56:41 -0600756 PCI_DMA_FROMDEVICE);
Olof Johansson32bee772007-11-06 22:21:38 -0600757
758 if (macrx & XCT_MACRX_CRC) {
759 /* CRC error flagged */
760 mac->netdev->stats.rx_errors++;
761 mac->netdev->stats.rx_crc_errors++;
Olof Johansson4352d822007-12-03 21:34:14 -0600762 /* No need to free skb, it'll be reused */
Olof Johansson32bee772007-11-06 22:21:38 -0600763 goto next;
764 }
765
Olof Johansson5d894942007-11-28 20:57:56 -0600766 info->skb = NULL;
Olof Johanssonad5da102007-10-02 16:27:15 -0500767 info->dma = 0;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500768
Olof Johansson26fcfa92007-08-22 09:12:59 -0500769 if (likely((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK)) {
Olof Johansson38bf3182007-08-22 09:13:24 -0500770 skb->ip_summed = CHECKSUM_UNNECESSARY;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500771 skb->csum = (macrx & XCT_MACRX_CSUM_M) >>
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600772 XCT_MACRX_CSUM_S;
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000773 } else {
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700774 skb_checksum_none_assert(skb);
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000775 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600776
Olof Johansson5c153322007-11-28 20:56:41 -0600777 packets++;
778 tot_bytes += len;
779
780 /* Don't include CRC */
781 skb_put(skb, len-4);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600782
Olof Johansson26fcfa92007-08-22 09:12:59 -0500783 skb->protocol = eth_type_trans(skb, mac->netdev);
Ben Hutchingsa4f9cdb2016-02-15 21:25:11 +0000784 napi_gro_receive(&mac->napi, skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600785
Olof Johansson32bee772007-11-06 22:21:38 -0600786next:
Olof Johansson72b05b92007-11-28 20:54:28 -0600787 RX_DESC(rx, n) = 0;
788 RX_DESC(rx, n+1) = 0;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500789
Olof Johanssonad5da102007-10-02 16:27:15 -0500790 /* Need to zero it out since hardware doesn't, since the
791 * replenish loop uses it to tell when it's done.
792 */
Olof Johansson72b05b92007-11-28 20:54:28 -0600793 RX_BUFF(rx, buf_index) = 0;
Olof Johanssonad5da102007-10-02 16:27:15 -0500794
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500795 n += 4;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600796 }
797
Olof Johansson9a50beb2007-10-02 16:26:30 -0500798 if (n > RX_RING_SIZE) {
799 /* Errata 5971 workaround: L2 target of headers */
Olof Johansson34c20622007-11-28 20:56:32 -0600800 write_iob_reg(PAS_IOB_COM_PKTHDRCNT, 0);
Olof Johansson9a50beb2007-10-02 16:26:30 -0500801 n &= (RX_RING_SIZE-1);
802 }
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500803
Olof Johansson72b05b92007-11-28 20:54:28 -0600804 rx_ring(mac)->next_to_clean = n;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500805
806 /* Increase is in number of 16-byte entries, and since each descriptor
807 * with an 8BRES takes up 3x8 bytes (padded to 4x8), increase with
808 * count*2.
809 */
Olof Johansson34c20622007-11-28 20:56:32 -0600810 write_dma_reg(PAS_DMA_RXCHAN_INCR(mac->rx->chan.chno), count << 1);
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500811
812 pasemi_mac_replenish_rx_ring(mac->netdev, count);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600813
Olof Johansson5c153322007-11-28 20:56:41 -0600814 mac->netdev->stats.rx_bytes += tot_bytes;
815 mac->netdev->stats.rx_packets += packets;
816
Olof Johansson72b05b92007-11-28 20:54:28 -0600817 spin_unlock(&rx_ring(mac)->lock);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600818
819 return count;
820}
821
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500822/* Can't make this too large or we blow the kernel stack limits */
823#define TX_CLEAN_BATCHSIZE (128/MAX_SKB_FRAGS)
824
Olof Johansson72b05b92007-11-28 20:54:28 -0600825static int pasemi_mac_clean_tx(struct pasemi_mac_txring *txring)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600826{
Olof Johansson34c20622007-11-28 20:56:32 -0600827 struct pasemi_dmachan *chan = &txring->chan;
Olof Johansson72b05b92007-11-28 20:54:28 -0600828 struct pasemi_mac *mac = txring->mac;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500829 int i, j;
Olof Johanssonad5da102007-10-02 16:27:15 -0500830 unsigned int start, descr_count, buf_count, batch_limit;
831 unsigned int ring_limit;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500832 unsigned int total_count;
Olof Johanssonca7e2352007-09-26 16:23:59 -0500833 unsigned long flags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500834 struct sk_buff *skbs[TX_CLEAN_BATCHSIZE];
835 dma_addr_t dmas[TX_CLEAN_BATCHSIZE][MAX_SKB_FRAGS+1];
Olof Johansson7e9916e2007-11-28 20:57:45 -0600836 int nf[TX_CLEAN_BATCHSIZE];
837 int nr_frags;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600838
Olof Johansson02df6cf2007-08-22 09:13:03 -0500839 total_count = 0;
Olof Johanssonad5da102007-10-02 16:27:15 -0500840 batch_limit = TX_CLEAN_BATCHSIZE;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500841restart:
Olof Johansson72b05b92007-11-28 20:54:28 -0600842 spin_lock_irqsave(&txring->lock, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600843
Olof Johansson72b05b92007-11-28 20:54:28 -0600844 start = txring->next_to_clean;
845 ring_limit = txring->next_to_fill;
Olof Johanssonad5da102007-10-02 16:27:15 -0500846
Olof Johansson7e9916e2007-11-28 20:57:45 -0600847 prefetch(&TX_DESC_INFO(txring, start+1).skb);
848
Olof Johanssonad5da102007-10-02 16:27:15 -0500849 /* Compensate for when fill has wrapped but clean has not */
850 if (start > ring_limit)
851 ring_limit += TX_RING_SIZE;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500852
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500853 buf_count = 0;
854 descr_count = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600855
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500856 for (i = start;
Olof Johanssonad5da102007-10-02 16:27:15 -0500857 descr_count < batch_limit && i < ring_limit;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500858 i += buf_count) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600859 u64 mactx = TX_DESC(txring, i);
Olof Johanssonad5da102007-10-02 16:27:15 -0500860 struct sk_buff *skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500861
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500862 if ((mactx & XCT_MACTX_E) ||
Olof Johansson34c20622007-11-28 20:56:32 -0600863 (*chan->status & PAS_STATUS_ERROR))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500864 pasemi_mac_tx_error(mac, mactx);
Olof Johansson69c29d82007-10-02 16:24:51 -0500865
Olof Johansson8d636d82008-03-05 16:34:16 -0600866 /* Skip over control descriptors */
867 if (!(mactx & XCT_MACTX_LLEN_M)) {
868 TX_DESC(txring, i) = 0;
869 TX_DESC(txring, i+1) = 0;
870 buf_count = 2;
871 continue;
872 }
873
874 skb = TX_DESC_INFO(txring, i+1).skb;
875 nr_frags = TX_DESC_INFO(txring, i).dma;
876
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500877 if (unlikely(mactx & XCT_MACTX_O))
Olof Johansson02df6cf2007-08-22 09:13:03 -0500878 /* Not yet transmitted */
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600879 break;
880
Olof Johansson7e9916e2007-11-28 20:57:45 -0600881 buf_count = 2 + nr_frags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500882 /* Since we always fill with an even number of entries, make
883 * sure we skip any unused one at the end as well.
884 */
885 if (buf_count & 1)
886 buf_count++;
Olof Johansson7e9916e2007-11-28 20:57:45 -0600887
888 for (j = 0; j <= nr_frags; j++)
889 dmas[descr_count][j] = TX_DESC_INFO(txring, i+1+j).dma;
890
891 skbs[descr_count] = skb;
892 nf[descr_count] = nr_frags;
893
894 TX_DESC(txring, i) = 0;
895 TX_DESC(txring, i+1) = 0;
896
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500897 descr_count++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600898 }
Olof Johansson72b05b92007-11-28 20:54:28 -0600899 txring->next_to_clean = i & (TX_RING_SIZE-1);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500900
Olof Johansson72b05b92007-11-28 20:54:28 -0600901 spin_unlock_irqrestore(&txring->lock, flags);
Olof Johansson0ce68c72007-04-28 15:36:40 -0500902 netif_wake_queue(mac->netdev);
903
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500904 for (i = 0; i < descr_count; i++)
Olof Johansson7e9916e2007-11-28 20:57:45 -0600905 pasemi_mac_unmap_tx_skb(mac, nf[i], skbs[i], dmas[i]);
Olof Johansson02df6cf2007-08-22 09:13:03 -0500906
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500907 total_count += descr_count;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500908
909 /* If the batch was full, try to clean more */
Olof Johanssonad5da102007-10-02 16:27:15 -0500910 if (descr_count == batch_limit)
Olof Johansson02df6cf2007-08-22 09:13:03 -0500911 goto restart;
912
913 return total_count;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600914}
915
916
917static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
918{
Olof Johansson5c153322007-11-28 20:56:41 -0600919 const struct pasemi_mac_rxring *rxring = data;
Olof Johansson34c20622007-11-28 20:56:32 -0600920 struct pasemi_mac *mac = rxring->mac;
Olof Johansson5c153322007-11-28 20:56:41 -0600921 const struct pasemi_dmachan *chan = &rxring->chan;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600922 unsigned int reg;
923
Olof Johansson34c20622007-11-28 20:56:32 -0600924 if (!(*chan->status & PAS_STATUS_CAUSE_M))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600925 return IRQ_NONE;
926
Olof Johansson6dfa7522007-05-08 00:47:32 -0500927 /* Don't reset packet count so it won't fire again but clear
928 * all others.
929 */
930
Olof Johansson6dfa7522007-05-08 00:47:32 -0500931 reg = 0;
Olof Johansson34c20622007-11-28 20:56:32 -0600932 if (*chan->status & PAS_STATUS_SOFT)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500933 reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
Olof Johansson34c20622007-11-28 20:56:32 -0600934 if (*chan->status & PAS_STATUS_ERROR)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500935 reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600936
Ben Hutchings288379f2009-01-19 16:43:59 -0800937 napi_schedule(&mac->napi);
Olof Johansson6dfa7522007-05-08 00:47:32 -0500938
Olof Johansson34c20622007-11-28 20:56:32 -0600939 write_iob_reg(PAS_IOB_DMA_RXCH_RESET(chan->chno), reg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600940
941 return IRQ_HANDLED;
942}
943
Olof Johansson61cec3b2007-11-28 20:56:54 -0600944#define TX_CLEAN_INTERVAL HZ
945
946static void pasemi_mac_tx_timer(unsigned long data)
947{
948 struct pasemi_mac_txring *txring = (struct pasemi_mac_txring *)data;
949 struct pasemi_mac *mac = txring->mac;
950
951 pasemi_mac_clean_tx(txring);
952
953 mod_timer(&txring->clean_timer, jiffies + TX_CLEAN_INTERVAL);
954
955 pasemi_mac_restart_tx_intr(mac);
956}
957
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600958static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
959{
Olof Johansson72b05b92007-11-28 20:54:28 -0600960 struct pasemi_mac_txring *txring = data;
Olof Johansson5c153322007-11-28 20:56:41 -0600961 const struct pasemi_dmachan *chan = &txring->chan;
Olof Johansson61cec3b2007-11-28 20:56:54 -0600962 struct pasemi_mac *mac = txring->mac;
963 unsigned int reg;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600964
Olof Johansson34c20622007-11-28 20:56:32 -0600965 if (!(*chan->status & PAS_STATUS_CAUSE_M))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600966 return IRQ_NONE;
967
Olof Johansson61cec3b2007-11-28 20:56:54 -0600968 reg = 0;
Olof Johansson6dfa7522007-05-08 00:47:32 -0500969
Olof Johansson34c20622007-11-28 20:56:32 -0600970 if (*chan->status & PAS_STATUS_SOFT)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500971 reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
Olof Johansson34c20622007-11-28 20:56:32 -0600972 if (*chan->status & PAS_STATUS_ERROR)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500973 reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600974
Olof Johansson61cec3b2007-11-28 20:56:54 -0600975 mod_timer(&txring->clean_timer, jiffies + (TX_CLEAN_INTERVAL)*2);
976
Ben Hutchings288379f2009-01-19 16:43:59 -0800977 napi_schedule(&mac->napi);
Olof Johansson61cec3b2007-11-28 20:56:54 -0600978
979 if (reg)
980 write_iob_reg(PAS_IOB_DMA_TXCH_RESET(chan->chno), reg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600981
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600982 return IRQ_HANDLED;
983}
984
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500985static void pasemi_adjust_link(struct net_device *dev)
986{
987 struct pasemi_mac *mac = netdev_priv(dev);
988 int msg;
989 unsigned int flags;
990 unsigned int new_flags;
991
Philippe Reynes80721e72016-07-14 23:44:52 +0200992 if (!dev->phydev->link) {
Olof Johanssonbb6e9592007-05-08 00:47:54 -0500993 /* If no link, MAC speed settings don't matter. Just report
994 * link down and return.
995 */
996 if (mac->link && netif_msg_link(mac))
997 printk(KERN_INFO "%s: Link is down.\n", dev->name);
998
999 netif_carrier_off(dev);
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001000 pasemi_mac_intf_disable(mac);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001001 mac->link = 0;
1002
1003 return;
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001004 } else {
1005 pasemi_mac_intf_enable(mac);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001006 netif_carrier_on(dev);
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001007 }
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001008
Olof Johanssona85b9422007-09-15 13:40:59 -07001009 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001010 new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M |
1011 PAS_MAC_CFG_PCFG_TSR_M);
1012
Philippe Reynes80721e72016-07-14 23:44:52 +02001013 if (!dev->phydev->duplex)
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001014 new_flags |= PAS_MAC_CFG_PCFG_HD;
1015
Philippe Reynes80721e72016-07-14 23:44:52 +02001016 switch (dev->phydev->speed) {
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001017 case 1000:
1018 new_flags |= PAS_MAC_CFG_PCFG_SPD_1G |
1019 PAS_MAC_CFG_PCFG_TSR_1G;
1020 break;
1021 case 100:
1022 new_flags |= PAS_MAC_CFG_PCFG_SPD_100M |
1023 PAS_MAC_CFG_PCFG_TSR_100M;
1024 break;
1025 case 10:
1026 new_flags |= PAS_MAC_CFG_PCFG_SPD_10M |
1027 PAS_MAC_CFG_PCFG_TSR_10M;
1028 break;
1029 default:
Philippe Reynes80721e72016-07-14 23:44:52 +02001030 printk("Unsupported speed %d\n", dev->phydev->speed);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001031 }
1032
1033 /* Print on link or speed/duplex change */
Philippe Reynes80721e72016-07-14 23:44:52 +02001034 msg = mac->link != dev->phydev->link || flags != new_flags;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001035
Philippe Reynes80721e72016-07-14 23:44:52 +02001036 mac->duplex = dev->phydev->duplex;
1037 mac->speed = dev->phydev->speed;
1038 mac->link = dev->phydev->link;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001039
1040 if (new_flags != flags)
Olof Johanssona85b9422007-09-15 13:40:59 -07001041 write_mac_reg(mac, PAS_MAC_CFG_PCFG, new_flags);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001042
1043 if (msg && netif_msg_link(mac))
1044 printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n",
1045 dev->name, mac->speed, mac->duplex ? "full" : "half");
1046}
1047
1048static int pasemi_mac_phy_init(struct net_device *dev)
1049{
1050 struct pasemi_mac *mac = netdev_priv(dev);
1051 struct device_node *dn, *phy_dn;
1052 struct phy_device *phydev;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001053
1054 dn = pci_device_to_OF_node(mac->pdev);
Grant Likely1dd2d062009-04-25 12:53:17 +00001055 phy_dn = of_parse_phandle(dn, "phy-handle", 0);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001056 of_node_put(phy_dn);
1057
1058 mac->link = 0;
1059 mac->speed = 0;
1060 mac->duplex = -1;
1061
Grant Likely1dd2d062009-04-25 12:53:17 +00001062 phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
1063 PHY_INTERFACE_MODE_SGMII);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001064
Wei Yongjunbeb5ac22012-09-26 19:51:58 +00001065 if (!phydev) {
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001066 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
Wei Yongjunbeb5ac22012-09-26 19:51:58 +00001067 return -ENODEV;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001068 }
1069
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001070 return 0;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001071}
1072
1073
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001074static int pasemi_mac_open(struct net_device *dev)
1075{
1076 struct pasemi_mac *mac = netdev_priv(dev);
1077 unsigned int flags;
Olof Johanssone37c7722008-02-20 20:57:59 -06001078 int i, ret;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001079
1080 flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
1081 PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
1082 PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12);
1083
Olof Johanssona85b9422007-09-15 13:40:59 -07001084 write_mac_reg(mac, PAS_MAC_CFG_TXP, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001085
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001086 ret = pasemi_mac_setup_rx_resources(dev);
1087 if (ret)
1088 goto out_rx_resources;
1089
Olof Johansson34c20622007-11-28 20:56:32 -06001090 mac->tx = pasemi_mac_setup_tx_resources(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -06001091
1092 if (!mac->tx)
1093 goto out_tx_ring;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001094
Olof Johansson1724ac22008-03-25 09:58:40 -05001095 /* We might already have allocated rings in case mtu was changed
1096 * before interface was brought up.
1097 */
1098 if (dev->mtu > 1500 && !mac->num_cs) {
Olof Johansson8d636d82008-03-05 16:34:16 -06001099 pasemi_mac_setup_csrings(mac);
1100 if (!mac->num_cs)
1101 goto out_tx_ring;
1102 }
1103
Olof Johanssone37c7722008-02-20 20:57:59 -06001104 /* Zero out rmon counters */
1105 for (i = 0; i < 32; i++)
1106 write_mac_reg(mac, PAS_MAC_RMON(i), 0);
1107
Olof Johansson906674a2007-11-28 20:57:09 -06001108 /* 0x3ff with 33MHz clock is about 31us */
1109 write_iob_reg(PAS_IOB_DMA_COM_TIMEOUTCFG,
1110 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0x3ff));
1111
Olof Johansson34c20622007-11-28 20:56:32 -06001112 write_iob_reg(PAS_IOB_DMA_RXCH_CFG(mac->rx->chan.chno),
Olof Johansson28ae79f2007-11-28 20:57:27 -06001113 PAS_IOB_DMA_RXCH_CFG_CNTTH(256));
Olof Johansson34c20622007-11-28 20:56:32 -06001114
1115 write_iob_reg(PAS_IOB_DMA_TXCH_CFG(mac->tx->chan.chno),
Olof Johansson61cec3b2007-11-28 20:56:54 -06001116 PAS_IOB_DMA_TXCH_CFG_CNTTH(32));
Olof Johansson34c20622007-11-28 20:56:32 -06001117
Olof Johanssona85b9422007-09-15 13:40:59 -07001118 write_mac_reg(mac, PAS_MAC_IPC_CHNL,
Olof Johansson34c20622007-11-28 20:56:32 -06001119 PAS_MAC_IPC_CHNL_DCHNO(mac->rx->chan.chno) |
1120 PAS_MAC_IPC_CHNL_BCH(mac->rx->chan.chno));
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001121
1122 /* enable rx if */
Olof Johansson34c20622007-11-28 20:56:32 -06001123 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1124 PAS_DMA_RXINT_RCMDSTA_EN |
1125 PAS_DMA_RXINT_RCMDSTA_DROPS_M |
1126 PAS_DMA_RXINT_RCMDSTA_BP |
1127 PAS_DMA_RXINT_RCMDSTA_OO |
1128 PAS_DMA_RXINT_RCMDSTA_BT);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001129
1130 /* enable rx channel */
Olof Johansson34c20622007-11-28 20:56:32 -06001131 pasemi_dma_start_chan(&rx_ring(mac)->chan, PAS_DMA_RXCHAN_CCMDSTA_DU |
1132 PAS_DMA_RXCHAN_CCMDSTA_OD |
1133 PAS_DMA_RXCHAN_CCMDSTA_FD |
1134 PAS_DMA_RXCHAN_CCMDSTA_DT);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001135
1136 /* enable tx channel */
Olof Johansson34c20622007-11-28 20:56:32 -06001137 pasemi_dma_start_chan(&tx_ring(mac)->chan, PAS_DMA_TXCHAN_TCMDSTA_SZ |
1138 PAS_DMA_TXCHAN_TCMDSTA_DB |
1139 PAS_DMA_TXCHAN_TCMDSTA_DE |
1140 PAS_DMA_TXCHAN_TCMDSTA_DA);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001141
Olof Johansson928773c2007-09-26 16:25:06 -05001142 pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001143
Olof Johansson34c20622007-11-28 20:56:32 -06001144 write_dma_reg(PAS_DMA_RXCHAN_INCR(rx_ring(mac)->chan.chno),
1145 RX_RING_SIZE>>1);
Olof Johanssonb5254ee2007-10-02 16:27:57 -05001146
Olof Johansson72b05b92007-11-28 20:54:28 -06001147 /* Clear out any residual packet count state from firmware */
1148 pasemi_mac_restart_rx_intr(mac);
1149 pasemi_mac_restart_tx_intr(mac);
1150
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001151 flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE;
Olof Johansson36033762007-09-26 16:24:42 -05001152
1153 if (mac->type == MAC_TYPE_GMAC)
1154 flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
1155 else
1156 flags |= PAS_MAC_CFG_PCFG_TSR_10G | PAS_MAC_CFG_PCFG_SPD_10G;
1157
1158 /* Enable interface in MAC */
1159 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
1160
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001161 ret = pasemi_mac_phy_init(dev);
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001162 if (ret) {
1163 /* Since we won't get link notification, just enable RX */
1164 pasemi_mac_intf_enable(mac);
1165 if (mac->type == MAC_TYPE_GMAC) {
1166 /* Warn for missing PHY on SGMII (1Gig) ports */
1167 dev_warn(&mac->pdev->dev,
1168 "PHY init failed: %d.\n", ret);
1169 dev_warn(&mac->pdev->dev,
1170 "Defaulting to 1Gbit full duplex\n");
1171 }
Olof Johansson8304b632007-11-28 20:58:06 -06001172 }
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001173
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001174 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001175 napi_enable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001176
Olof Johansson72b05b92007-11-28 20:54:28 -06001177 snprintf(mac->tx_irq_name, sizeof(mac->tx_irq_name), "%s tx",
1178 dev->name);
Olof Johansson771f7402007-05-08 00:47:21 -05001179
Michael Opdenacker78874272013-09-13 06:21:24 +02001180 ret = request_irq(mac->tx->chan.irq, pasemi_mac_tx_intr, 0,
Olof Johansson72b05b92007-11-28 20:54:28 -06001181 mac->tx_irq_name, mac->tx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001182 if (ret) {
1183 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
Olof Johansson34c20622007-11-28 20:56:32 -06001184 mac->tx->chan.irq, ret);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001185 goto out_tx_int;
1186 }
1187
Olof Johansson72b05b92007-11-28 20:54:28 -06001188 snprintf(mac->rx_irq_name, sizeof(mac->rx_irq_name), "%s rx",
1189 dev->name);
1190
Michael Opdenacker78874272013-09-13 06:21:24 +02001191 ret = request_irq(mac->rx->chan.irq, pasemi_mac_rx_intr, 0,
Olof Johansson34c20622007-11-28 20:56:32 -06001192 mac->rx_irq_name, mac->rx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001193 if (ret) {
1194 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
Olof Johansson34c20622007-11-28 20:56:32 -06001195 mac->rx->chan.irq, ret);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001196 goto out_rx_int;
1197 }
1198
Philippe Reynes80721e72016-07-14 23:44:52 +02001199 if (dev->phydev)
1200 phy_start(dev->phydev);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001201
Vaishali Thakkar187d6782015-02-28 00:20:59 +05301202 setup_timer(&mac->tx->clean_timer, pasemi_mac_tx_timer,
1203 (unsigned long)mac->tx);
1204 mod_timer(&mac->tx->clean_timer, jiffies + HZ);
Olof Johansson61cec3b2007-11-28 20:56:54 -06001205
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001206 return 0;
1207
1208out_rx_int:
Olof Johansson34c20622007-11-28 20:56:32 -06001209 free_irq(mac->tx->chan.irq, mac->tx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001210out_tx_int:
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001211 napi_disable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001212 netif_stop_queue(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -06001213out_tx_ring:
1214 if (mac->tx)
1215 pasemi_mac_free_tx_resources(mac);
1216 pasemi_mac_free_rx_resources(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001217out_rx_resources:
1218
1219 return ret;
1220}
1221
1222#define MAX_RETRIES 5000
1223
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001224static void pasemi_mac_pause_txchan(struct pasemi_mac *mac)
1225{
1226 unsigned int sta, retries;
1227 int txch = tx_ring(mac)->chan.chno;
1228
1229 write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch),
1230 PAS_DMA_TXCHAN_TCMDSTA_ST);
1231
1232 for (retries = 0; retries < MAX_RETRIES; retries++) {
1233 sta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch));
1234 if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT))
1235 break;
1236 cond_resched();
1237 }
1238
1239 if (sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)
1240 dev_err(&mac->dma_pdev->dev,
1241 "Failed to stop tx channel, tcmdsta %08x\n", sta);
1242
1243 write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch), 0);
1244}
1245
1246static void pasemi_mac_pause_rxchan(struct pasemi_mac *mac)
1247{
1248 unsigned int sta, retries;
1249 int rxch = rx_ring(mac)->chan.chno;
1250
1251 write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch),
1252 PAS_DMA_RXCHAN_CCMDSTA_ST);
1253 for (retries = 0; retries < MAX_RETRIES; retries++) {
1254 sta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch));
1255 if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT))
1256 break;
1257 cond_resched();
1258 }
1259
1260 if (sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)
1261 dev_err(&mac->dma_pdev->dev,
1262 "Failed to stop rx channel, ccmdsta 08%x\n", sta);
1263 write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch), 0);
1264}
1265
1266static void pasemi_mac_pause_rxint(struct pasemi_mac *mac)
1267{
1268 unsigned int sta, retries;
1269
1270 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1271 PAS_DMA_RXINT_RCMDSTA_ST);
1272 for (retries = 0; retries < MAX_RETRIES; retries++) {
1273 sta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
1274 if (!(sta & PAS_DMA_RXINT_RCMDSTA_ACT))
1275 break;
1276 cond_resched();
1277 }
1278
1279 if (sta & PAS_DMA_RXINT_RCMDSTA_ACT)
1280 dev_err(&mac->dma_pdev->dev,
1281 "Failed to stop rx interface, rcmdsta %08x\n", sta);
1282 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
1283}
1284
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001285static int pasemi_mac_close(struct net_device *dev)
1286{
1287 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson9e81d332007-10-02 16:27:39 -05001288 unsigned int sta;
Olof Johansson8d636d82008-03-05 16:34:16 -06001289 int rxch, txch, i;
Olof Johansson34c20622007-11-28 20:56:32 -06001290
1291 rxch = rx_ring(mac)->chan.chno;
1292 txch = tx_ring(mac)->chan.chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001293
Philippe Reynes80721e72016-07-14 23:44:52 +02001294 if (dev->phydev) {
1295 phy_stop(dev->phydev);
1296 phy_disconnect(dev->phydev);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001297 }
1298
Olof Johansson61cec3b2007-11-28 20:56:54 -06001299 del_timer_sync(&mac->tx->clean_timer);
1300
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001301 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001302 napi_disable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001303
Olof Johansson34c20622007-11-28 20:56:32 -06001304 sta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
Olof Johansson9e81d332007-10-02 16:27:39 -05001305 if (sta & (PAS_DMA_RXINT_RCMDSTA_BP |
1306 PAS_DMA_RXINT_RCMDSTA_OO |
1307 PAS_DMA_RXINT_RCMDSTA_BT))
1308 printk(KERN_DEBUG "pasemi_mac: rcmdsta error: 0x%08x\n", sta);
1309
Olof Johansson34c20622007-11-28 20:56:32 -06001310 sta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch));
Olof Johansson9e81d332007-10-02 16:27:39 -05001311 if (sta & (PAS_DMA_RXCHAN_CCMDSTA_DU |
1312 PAS_DMA_RXCHAN_CCMDSTA_OD |
1313 PAS_DMA_RXCHAN_CCMDSTA_FD |
1314 PAS_DMA_RXCHAN_CCMDSTA_DT))
1315 printk(KERN_DEBUG "pasemi_mac: ccmdsta error: 0x%08x\n", sta);
1316
Olof Johansson34c20622007-11-28 20:56:32 -06001317 sta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch));
Olof Johansson72b05b92007-11-28 20:54:28 -06001318 if (sta & (PAS_DMA_TXCHAN_TCMDSTA_SZ | PAS_DMA_TXCHAN_TCMDSTA_DB |
1319 PAS_DMA_TXCHAN_TCMDSTA_DE | PAS_DMA_TXCHAN_TCMDSTA_DA))
Olof Johansson9e81d332007-10-02 16:27:39 -05001320 printk(KERN_DEBUG "pasemi_mac: tcmdsta error: 0x%08x\n", sta);
1321
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001322 /* Clean out any pending buffers */
Olof Johansson72b05b92007-11-28 20:54:28 -06001323 pasemi_mac_clean_tx(tx_ring(mac));
1324 pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001325
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001326 pasemi_mac_pause_txchan(mac);
1327 pasemi_mac_pause_rxint(mac);
1328 pasemi_mac_pause_rxchan(mac);
Olof Johansson1145d952008-01-23 13:57:19 -06001329 pasemi_mac_intf_disable(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001330
Olof Johansson34c20622007-11-28 20:56:32 -06001331 free_irq(mac->tx->chan.irq, mac->tx);
1332 free_irq(mac->rx->chan.irq, mac->rx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001333
Olof Johansson1724ac22008-03-25 09:58:40 -05001334 for (i = 0; i < mac->num_cs; i++) {
Olof Johansson8d636d82008-03-05 16:34:16 -06001335 pasemi_mac_free_csring(mac->cs[i]);
Olof Johansson1724ac22008-03-25 09:58:40 -05001336 mac->cs[i] = NULL;
1337 }
1338
1339 mac->num_cs = 0;
Olof Johansson8d636d82008-03-05 16:34:16 -06001340
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001341 /* Free resources */
Olof Johansson72b05b92007-11-28 20:54:28 -06001342 pasemi_mac_free_rx_resources(mac);
1343 pasemi_mac_free_tx_resources(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001344
1345 return 0;
1346}
1347
Olof Johansson8d636d82008-03-05 16:34:16 -06001348static void pasemi_mac_queue_csdesc(const struct sk_buff *skb,
1349 const dma_addr_t *map,
1350 const unsigned int *map_size,
1351 struct pasemi_mac_txring *txring,
1352 struct pasemi_mac_csring *csring)
1353{
1354 u64 fund;
1355 dma_addr_t cs_dest;
1356 const int nh_off = skb_network_offset(skb);
1357 const int nh_len = skb_network_header_len(skb);
1358 const int nfrags = skb_shinfo(skb)->nr_frags;
1359 int cs_size, i, fill, hdr, cpyhdr, evt;
1360 dma_addr_t csdma;
1361
1362 fund = XCT_FUN_ST | XCT_FUN_RR_8BRES |
1363 XCT_FUN_O | XCT_FUN_FUN(csring->fun) |
1364 XCT_FUN_CRM_SIG | XCT_FUN_LLEN(skb->len - nh_off) |
1365 XCT_FUN_SHL(nh_len >> 2) | XCT_FUN_SE;
1366
1367 switch (ip_hdr(skb)->protocol) {
1368 case IPPROTO_TCP:
1369 fund |= XCT_FUN_SIG_TCP4;
1370 /* TCP checksum is 16 bytes into the header */
1371 cs_dest = map[0] + skb_transport_offset(skb) + 16;
1372 break;
1373 case IPPROTO_UDP:
1374 fund |= XCT_FUN_SIG_UDP4;
1375 /* UDP checksum is 6 bytes into the header */
1376 cs_dest = map[0] + skb_transport_offset(skb) + 6;
1377 break;
1378 default:
1379 BUG();
1380 }
1381
1382 /* Do the checksum offloaded */
1383 fill = csring->next_to_fill;
1384 hdr = fill;
1385
1386 CS_DESC(csring, fill++) = fund;
1387 /* Room for 8BRES. Checksum result is really 2 bytes into it */
1388 csdma = csring->chan.ring_dma + (fill & (CS_RING_SIZE-1)) * 8 + 2;
1389 CS_DESC(csring, fill++) = 0;
1390
1391 CS_DESC(csring, fill) = XCT_PTR_LEN(map_size[0]-nh_off) | XCT_PTR_ADDR(map[0]+nh_off);
1392 for (i = 1; i <= nfrags; i++)
1393 CS_DESC(csring, fill+i) = XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]);
1394
1395 fill += i;
1396 if (fill & 1)
1397 fill++;
1398
1399 /* Copy the result into the TCP packet */
1400 cpyhdr = fill;
1401 CS_DESC(csring, fill++) = XCT_FUN_O | XCT_FUN_FUN(csring->fun) |
1402 XCT_FUN_LLEN(2) | XCT_FUN_SE;
1403 CS_DESC(csring, fill++) = XCT_PTR_LEN(2) | XCT_PTR_ADDR(cs_dest) | XCT_PTR_T;
1404 CS_DESC(csring, fill++) = XCT_PTR_LEN(2) | XCT_PTR_ADDR(csdma);
1405 fill++;
1406
1407 evt = !csring->last_event;
1408 csring->last_event = evt;
1409
1410 /* Event handshaking with MAC TX */
1411 CS_DESC(csring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1412 CTRL_CMD_ETYPE_SET | CTRL_CMD_REG(csring->events[evt]);
1413 CS_DESC(csring, fill++) = 0;
1414 CS_DESC(csring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1415 CTRL_CMD_ETYPE_WCLR | CTRL_CMD_REG(csring->events[!evt]);
1416 CS_DESC(csring, fill++) = 0;
1417 csring->next_to_fill = fill & (CS_RING_SIZE-1);
1418
1419 cs_size = fill - hdr;
1420 write_dma_reg(PAS_DMA_TXCHAN_INCR(csring->chan.chno), (cs_size) >> 1);
1421
1422 /* TX-side event handshaking */
1423 fill = txring->next_to_fill;
1424 TX_DESC(txring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1425 CTRL_CMD_ETYPE_WSET | CTRL_CMD_REG(csring->events[evt]);
1426 TX_DESC(txring, fill++) = 0;
1427 TX_DESC(txring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1428 CTRL_CMD_ETYPE_CLR | CTRL_CMD_REG(csring->events[!evt]);
1429 TX_DESC(txring, fill++) = 0;
1430 txring->next_to_fill = fill;
1431
1432 write_dma_reg(PAS_DMA_TXCHAN_INCR(txring->chan.chno), 2);
Olof Johansson8d636d82008-03-05 16:34:16 -06001433}
1434
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001435static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
1436{
Olof Johansson8d636d82008-03-05 16:34:16 -06001437 struct pasemi_mac * const mac = netdev_priv(dev);
1438 struct pasemi_mac_txring * const txring = tx_ring(mac);
1439 struct pasemi_mac_csring *csring;
1440 u64 dflags = 0;
1441 u64 mactx;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001442 dma_addr_t map[MAX_SKB_FRAGS+1];
1443 unsigned int map_size[MAX_SKB_FRAGS+1];
Olof Johanssonca7e2352007-09-26 16:23:59 -05001444 unsigned long flags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001445 int i, nfrags;
Olof Johansson5c153322007-11-28 20:56:41 -06001446 int fill;
Olof Johansson8d636d82008-03-05 16:34:16 -06001447 const int nh_off = skb_network_offset(skb);
1448 const int nh_len = skb_network_header_len(skb);
1449
1450 prefetch(&txring->ring_info);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001451
Olof Johanssondbd62af2007-11-06 22:20:39 -06001452 dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_CRC_PAD;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001453
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001454 nfrags = skb_shinfo(skb)->nr_frags;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001455
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001456 map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb),
1457 PCI_DMA_TODEVICE);
1458 map_size[0] = skb_headlen(skb);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001459 if (pci_dma_mapping_error(mac->dma_pdev, map[0]))
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001460 goto out_err_nolock;
1461
1462 for (i = 0; i < nfrags; i++) {
1463 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1464
Ian Campbell4bb97ca2011-08-31 00:47:01 +00001465 map[i + 1] = skb_frag_dma_map(&mac->dma_pdev->dev, frag, 0,
Eric Dumazet9e903e02011-10-18 21:00:24 +00001466 skb_frag_size(frag), DMA_TO_DEVICE);
1467 map_size[i+1] = skb_frag_size(frag);
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01001468 if (dma_mapping_error(&mac->dma_pdev->dev, map[i + 1])) {
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001469 nfrags = i;
1470 goto out_err_nolock;
1471 }
1472 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001473
Olof Johansson8d636d82008-03-05 16:34:16 -06001474 if (skb->ip_summed == CHECKSUM_PARTIAL && skb->len <= 1540) {
1475 switch (ip_hdr(skb)->protocol) {
1476 case IPPROTO_TCP:
1477 dflags |= XCT_MACTX_CSUM_TCP;
1478 dflags |= XCT_MACTX_IPH(nh_len >> 2);
1479 dflags |= XCT_MACTX_IPO(nh_off);
1480 break;
1481 case IPPROTO_UDP:
1482 dflags |= XCT_MACTX_CSUM_UDP;
1483 dflags |= XCT_MACTX_IPH(nh_len >> 2);
1484 dflags |= XCT_MACTX_IPO(nh_off);
1485 break;
1486 default:
1487 WARN_ON(1);
1488 }
1489 }
1490
Olof Johansson26fcfa92007-08-22 09:12:59 -05001491 mactx = dflags | XCT_MACTX_LLEN(skb->len);
Olof Johansson26fcfa92007-08-22 09:12:59 -05001492
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001493 spin_lock_irqsave(&txring->lock, flags);
1494
Olof Johanssonad5da102007-10-02 16:27:15 -05001495 /* Avoid stepping on the same cache line that the DMA controller
1496 * is currently about to send, so leave at least 8 words available.
1497 * Total free space needed is mactx + fragments + 8
1498 */
Olof Johansson8d636d82008-03-05 16:34:16 -06001499 if (RING_AVAIL(txring) < nfrags + 14) {
Olof Johanssonad5da102007-10-02 16:27:15 -05001500 /* no room -- stop the queue and wait for tx intr */
1501 netif_stop_queue(dev);
1502 goto out_err;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001503 }
1504
Olof Johansson8d636d82008-03-05 16:34:16 -06001505 /* Queue up checksum + event descriptors, if needed */
1506 if (mac->num_cs && skb->ip_summed == CHECKSUM_PARTIAL && skb->len > 1540) {
1507 csring = mac->cs[mac->last_cs];
1508 mac->last_cs = (mac->last_cs + 1) % mac->num_cs;
1509
1510 pasemi_mac_queue_csdesc(skb, map, map_size, txring, csring);
1511 }
1512
1513 fill = txring->next_to_fill;
Olof Johansson5c153322007-11-28 20:56:41 -06001514 TX_DESC(txring, fill) = mactx;
Olof Johansson7e9916e2007-11-28 20:57:45 -06001515 TX_DESC_INFO(txring, fill).dma = nfrags;
Olof Johansson5c153322007-11-28 20:56:41 -06001516 fill++;
1517 TX_DESC_INFO(txring, fill).skb = skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001518 for (i = 0; i <= nfrags; i++) {
Olof Johansson5c153322007-11-28 20:56:41 -06001519 TX_DESC(txring, fill+i) =
Olof Johansson72b05b92007-11-28 20:54:28 -06001520 XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]);
Olof Johansson5c153322007-11-28 20:56:41 -06001521 TX_DESC_INFO(txring, fill+i).dma = map[i];
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001522 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001523
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001524 /* We have to add an even number of 8-byte entries to the ring
1525 * even if the last one is unused. That means always an odd number
1526 * of pointers + one mactx descriptor.
1527 */
1528 if (nfrags & 1)
1529 nfrags++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001530
Olof Johansson5c153322007-11-28 20:56:41 -06001531 txring->next_to_fill = (fill + nfrags + 1) & (TX_RING_SIZE-1);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -05001532
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001533 dev->stats.tx_packets++;
1534 dev->stats.tx_bytes += skb->len;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001535
1536 spin_unlock_irqrestore(&txring->lock, flags);
1537
Olof Johansson34c20622007-11-28 20:56:32 -06001538 write_dma_reg(PAS_DMA_TXCHAN_INCR(txring->chan.chno), (nfrags+2) >> 1);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001539
1540 return NETDEV_TX_OK;
1541
1542out_err:
1543 spin_unlock_irqrestore(&txring->lock, flags);
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001544out_err_nolock:
1545 while (nfrags--)
1546 pci_unmap_single(mac->dma_pdev, map[nfrags], map_size[nfrags],
1547 PCI_DMA_TODEVICE);
1548
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001549 return NETDEV_TX_BUSY;
1550}
1551
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001552static void pasemi_mac_set_rx_mode(struct net_device *dev)
1553{
Olof Johansson5c153322007-11-28 20:56:41 -06001554 const struct pasemi_mac *mac = netdev_priv(dev);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001555 unsigned int flags;
1556
Olof Johanssona85b9422007-09-15 13:40:59 -07001557 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001558
1559 /* Set promiscuous */
1560 if (dev->flags & IFF_PROMISC)
1561 flags |= PAS_MAC_CFG_PCFG_PR;
1562 else
1563 flags &= ~PAS_MAC_CFG_PCFG_PR;
1564
Olof Johanssona85b9422007-09-15 13:40:59 -07001565 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001566}
1567
1568
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001569static int pasemi_mac_poll(struct napi_struct *napi, int budget)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001570{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001571 struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001572 int pkts;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001573
Olof Johansson72b05b92007-11-28 20:54:28 -06001574 pasemi_mac_clean_tx(tx_ring(mac));
1575 pkts = pasemi_mac_clean_rx(rx_ring(mac), budget);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001576 if (pkts < budget) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001577 /* all done, no more packets present */
Ben Hutchings288379f2009-01-19 16:43:59 -08001578 napi_complete(napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001579
Olof Johansson1b0335ea2007-05-08 00:47:26 -05001580 pasemi_mac_restart_rx_intr(mac);
Olof Johansson61cec3b2007-11-28 20:56:54 -06001581 pasemi_mac_restart_tx_intr(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001582 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001583 return pkts;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001584}
1585
Nate Case6e620402008-03-21 17:02:42 -05001586#ifdef CONFIG_NET_POLL_CONTROLLER
1587/*
1588 * Polling 'interrupt' - used by things like netconsole to send skbs
1589 * without having to re-enable interrupts. It's not called while
1590 * the interrupt routine is executing.
1591 */
1592static void pasemi_mac_netpoll(struct net_device *dev)
1593{
1594 const struct pasemi_mac *mac = netdev_priv(dev);
1595
1596 disable_irq(mac->tx->chan.irq);
1597 pasemi_mac_tx_intr(mac->tx->chan.irq, mac->tx);
1598 enable_irq(mac->tx->chan.irq);
1599
1600 disable_irq(mac->rx->chan.irq);
1601 pasemi_mac_rx_intr(mac->rx->chan.irq, mac->rx);
1602 enable_irq(mac->rx->chan.irq);
1603}
1604#endif
1605
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001606static int pasemi_mac_change_mtu(struct net_device *dev, int new_mtu)
1607{
1608 struct pasemi_mac *mac = netdev_priv(dev);
1609 unsigned int reg;
Olof Johansson8d636d82008-03-05 16:34:16 -06001610 unsigned int rcmdsta = 0;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001611 int running;
Olof Johansson8d636d82008-03-05 16:34:16 -06001612 int ret = 0;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001613
1614 if (new_mtu < PE_MIN_MTU || new_mtu > PE_MAX_MTU)
1615 return -EINVAL;
1616
1617 running = netif_running(dev);
1618
1619 if (running) {
1620 /* Need to stop the interface, clean out all already
1621 * received buffers, free all unused buffers on the RX
1622 * interface ring, then finally re-fill the rx ring with
1623 * the new-size buffers and restart.
1624 */
1625
1626 napi_disable(&mac->napi);
1627 netif_tx_disable(dev);
1628 pasemi_mac_intf_disable(mac);
1629
1630 rcmdsta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
1631 pasemi_mac_pause_rxint(mac);
1632 pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
1633 pasemi_mac_free_rx_buffers(mac);
Olof Johansson8d636d82008-03-05 16:34:16 -06001634
1635 }
1636
1637 /* Setup checksum channels if large MTU and none already allocated */
1638 if (new_mtu > 1500 && !mac->num_cs) {
1639 pasemi_mac_setup_csrings(mac);
1640 if (!mac->num_cs) {
1641 ret = -ENOMEM;
1642 goto out;
1643 }
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001644 }
1645
1646 /* Change maxf, i.e. what size frames are accepted.
1647 * Need room for ethernet header and CRC word
1648 */
1649 reg = read_mac_reg(mac, PAS_MAC_CFG_MACCFG);
1650 reg &= ~PAS_MAC_CFG_MACCFG_MAXF_M;
1651 reg |= PAS_MAC_CFG_MACCFG_MAXF(new_mtu + ETH_HLEN + 4);
1652 write_mac_reg(mac, PAS_MAC_CFG_MACCFG, reg);
1653
1654 dev->mtu = new_mtu;
1655 /* MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
1656 mac->bufsz = new_mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
1657
Olof Johansson8d636d82008-03-05 16:34:16 -06001658out:
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001659 if (running) {
1660 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1661 rcmdsta | PAS_DMA_RXINT_RCMDSTA_EN);
1662
1663 rx_ring(mac)->next_to_fill = 0;
1664 pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE-1);
1665
1666 napi_enable(&mac->napi);
1667 netif_start_queue(dev);
1668 pasemi_mac_intf_enable(mac);
1669 }
1670
Olof Johansson8d636d82008-03-05 16:34:16 -06001671 return ret;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001672}
1673
Alexander Beregalov9e0ac842009-04-15 12:52:54 +00001674static const struct net_device_ops pasemi_netdev_ops = {
1675 .ndo_open = pasemi_mac_open,
1676 .ndo_stop = pasemi_mac_close,
1677 .ndo_start_xmit = pasemi_mac_start_tx,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001678 .ndo_set_rx_mode = pasemi_mac_set_rx_mode,
Alexander Beregalov9e0ac842009-04-15 12:52:54 +00001679 .ndo_set_mac_address = pasemi_mac_set_mac_addr,
1680 .ndo_change_mtu = pasemi_mac_change_mtu,
1681 .ndo_validate_addr = eth_validate_addr,
1682#ifdef CONFIG_NET_POLL_CONTROLLER
1683 .ndo_poll_controller = pasemi_mac_netpoll,
1684#endif
1685};
1686
Bill Pemberton03c4d832012-12-03 09:24:00 -05001687static int
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001688pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1689{
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001690 struct net_device *dev;
1691 struct pasemi_mac *mac;
roel kluin15b8e192009-04-23 08:53:20 +00001692 int err, ret;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001693
1694 err = pci_enable_device(pdev);
1695 if (err)
1696 return err;
1697
1698 dev = alloc_etherdev(sizeof(struct pasemi_mac));
1699 if (dev == NULL) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001700 err = -ENOMEM;
1701 goto out_disable_device;
1702 }
1703
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001704 pci_set_drvdata(pdev, dev);
1705 SET_NETDEV_DEV(dev, &pdev->dev);
1706
1707 mac = netdev_priv(dev);
1708
1709 mac->pdev = pdev;
1710 mac->netdev = dev;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001711
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001712 netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64);
1713
Olof Johansson5c153322007-11-28 20:56:41 -06001714 dev->features = NETIF_F_IP_CSUM | NETIF_F_LLTX | NETIF_F_SG |
Olof Johansson25156782008-02-20 20:57:58 -06001715 NETIF_F_HIGHDMA | NETIF_F_GSO;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001716
Olof Johansson34c20622007-11-28 20:56:32 -06001717 mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
1718 if (!mac->dma_pdev) {
1719 dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
1720 err = -ENODEV;
1721 goto out;
1722 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001723
Olof Johansson34c20622007-11-28 20:56:32 -06001724 mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
1725 if (!mac->iob_pdev) {
1726 dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
1727 err = -ENODEV;
1728 goto out;
1729 }
1730
1731 /* get mac addr from device tree */
1732 if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) {
1733 err = -ENODEV;
1734 goto out;
1735 }
1736 memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
1737
roel kluin15b8e192009-04-23 08:53:20 +00001738 ret = mac_to_intf(mac);
1739 if (ret < 0) {
Olof Johansson34c20622007-11-28 20:56:32 -06001740 dev_err(&mac->pdev->dev, "Can't map DMA interface\n");
1741 err = -ENODEV;
1742 goto out;
1743 }
roel kluin15b8e192009-04-23 08:53:20 +00001744 mac->dma_if = ret;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001745
1746 switch (pdev->device) {
1747 case 0xa005:
1748 mac->type = MAC_TYPE_GMAC;
1749 break;
1750 case 0xa006:
1751 mac->type = MAC_TYPE_XAUI;
1752 break;
1753 default:
1754 err = -ENODEV;
1755 goto out;
1756 }
1757
Alexander Beregalov9e0ac842009-04-15 12:52:54 +00001758 dev->netdev_ops = &pasemi_netdev_ops;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001759 dev->mtu = PE_DEF_MTU;
1760 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
1761 mac->bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
1762
Olof Johanssone37c7722008-02-20 20:57:59 -06001763 dev->ethtool_ops = &pasemi_mac_ethtool_ops;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001764
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001765 if (err)
1766 goto out;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001767
Olof Johanssonceb51362007-05-08 00:47:49 -05001768 mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
1769
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001770 /* Enable most messages by default */
1771 mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
1772
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001773 err = register_netdev(dev);
1774
1775 if (err) {
1776 dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n",
1777 err);
1778 goto out;
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +00001779 } else if (netif_msg_probe(mac)) {
Johannes Berge1749612008-10-27 15:59:26 -07001780 printk(KERN_INFO "%s: PA Semi %s: intf %d, hw addr %pM\n",
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001781 dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
Johannes Berge1749612008-10-27 15:59:26 -07001782 mac->dma_if, dev->dev_addr);
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +00001783 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001784
1785 return err;
1786
1787out:
Markus Elfring6db16712014-11-29 18:55:40 +01001788 pci_dev_put(mac->iob_pdev);
1789 pci_dev_put(mac->dma_pdev);
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001790
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001791 free_netdev(dev);
1792out_disable_device:
1793 pci_disable_device(pdev);
1794 return err;
1795
1796}
1797
Bill Pemberton03c4d832012-12-03 09:24:00 -05001798static void pasemi_mac_remove(struct pci_dev *pdev)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001799{
1800 struct net_device *netdev = pci_get_drvdata(pdev);
1801 struct pasemi_mac *mac;
1802
1803 if (!netdev)
1804 return;
1805
1806 mac = netdev_priv(netdev);
1807
1808 unregister_netdev(netdev);
1809
1810 pci_disable_device(pdev);
1811 pci_dev_put(mac->dma_pdev);
1812 pci_dev_put(mac->iob_pdev);
1813
Olof Johansson34c20622007-11-28 20:56:32 -06001814 pasemi_dma_free_chan(&mac->tx->chan);
1815 pasemi_dma_free_chan(&mac->rx->chan);
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001816
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001817 free_netdev(netdev);
1818}
1819
Benoit Taine9baa3c32014-08-08 15:56:03 +02001820static const struct pci_device_id pasemi_mac_pci_tbl[] = {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001821 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
1822 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
olof@lixom.netfd178252007-05-12 14:57:36 -05001823 { },
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001824};
1825
1826MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
1827
1828static struct pci_driver pasemi_mac_driver = {
1829 .name = "pasemi_mac",
1830 .id_table = pasemi_mac_pci_tbl,
1831 .probe = pasemi_mac_probe,
Bill Pemberton03c4d832012-12-03 09:24:00 -05001832 .remove = pasemi_mac_remove,
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001833};
1834
1835static void __exit pasemi_mac_cleanup_module(void)
1836{
1837 pci_unregister_driver(&pasemi_mac_driver);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001838}
1839
1840int pasemi_mac_init_module(void)
1841{
Olof Johansson34c20622007-11-28 20:56:32 -06001842 int err;
1843
1844 err = pasemi_dma_init();
1845 if (err)
1846 return err;
1847
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001848 return pci_register_driver(&pasemi_mac_driver);
1849}
1850
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001851module_init(pasemi_mac_init_module);
1852module_exit(pasemi_mac_cleanup_module);