blob: b1cfbb75ff1e09146b1c5ee6fc71562596b6e09f [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060024#include <linux/interrupt.h>
25#include <linux/dmaengine.h>
26#include <linux/delay.h>
27#include <linux/netdevice.h>
Grant Likely1dd2d062009-04-25 12:53:17 +000028#include <linux/of_mdio.h>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060029#include <linux/etherdevice.h>
30#include <asm/dma-mapping.h>
31#include <linux/in.h>
32#include <linux/skbuff.h>
33
34#include <linux/ip.h>
35#include <linux/tcp.h>
36#include <net/checksum.h>
Olof Johansson28ae79f2007-11-28 20:57:27 -060037#include <linux/inet_lro.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040038#include <linux/prefetch.h>
Olof Johanssonf5cd7872007-01-31 21:43:54 -060039
Olof Johansson771f7402007-05-08 00:47:21 -050040#include <asm/irq.h>
Olof Johanssonaf289e82007-10-03 13:03:54 -050041#include <asm/firmware.h>
Olof Johansson40afa532007-11-28 20:56:04 -060042#include <asm/pasemi_dma.h>
Olof Johansson771f7402007-05-08 00:47:21 -050043
Olof Johanssonf5cd7872007-01-31 21:43:54 -060044#include "pasemi_mac.h"
45
Olof Johansson8dc121a2007-10-02 16:26:53 -050046/* We have our own align, since ppc64 in general has it at 0 because
47 * of design flaws in some of the server bridge chips. However, for
48 * PWRficient doing the unaligned copies is more expensive than doing
49 * unaligned DMA, so make sure the data is aligned instead.
50 */
51#define LOCAL_SKB_ALIGN 2
Olof Johanssonf5cd7872007-01-31 21:43:54 -060052
53/* TODO list
54 *
Olof Johanssonf5cd7872007-01-31 21:43:54 -060055 * - Multicast support
56 * - Large MTU support
Olof Johansson7ddeae22007-10-02 16:27:28 -050057 * - SW LRO
58 * - Multiqueue RX/TX
Olof Johanssonf5cd7872007-01-31 21:43:54 -060059 */
60
Olof Johansson28ae79f2007-11-28 20:57:27 -060061#define LRO_MAX_AGGR 64
62
Olof Johanssonef1ea0b2008-01-23 13:56:47 -060063#define PE_MIN_MTU 64
Olof Johansson8d636d82008-03-05 16:34:16 -060064#define PE_MAX_MTU 9000
Olof Johanssonef1ea0b2008-01-23 13:56:47 -060065#define PE_DEF_MTU ETH_DATA_LEN
66
Olof Johanssonceb51362007-05-08 00:47:49 -050067#define DEFAULT_MSG_ENABLE \
68 (NETIF_MSG_DRV | \
69 NETIF_MSG_PROBE | \
70 NETIF_MSG_LINK | \
71 NETIF_MSG_TIMER | \
72 NETIF_MSG_IFDOWN | \
73 NETIF_MSG_IFUP | \
74 NETIF_MSG_RX_ERR | \
75 NETIF_MSG_TX_ERR)
76
Olof Johanssonceb51362007-05-08 00:47:49 -050077MODULE_LICENSE("GPL");
78MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
79MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
80
81static int debug = -1; /* -1 == use DEFAULT_MSG_ENABLE as value */
82module_param(debug, int, 0);
83MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
Olof Johanssonf5cd7872007-01-31 21:43:54 -060084
Olof Johanssone37c7722008-02-20 20:57:59 -060085extern const struct ethtool_ops pasemi_mac_ethtool_ops;
86
Olof Johanssonaf289e82007-10-03 13:03:54 -050087static int translation_enabled(void)
88{
89#if defined(CONFIG_PPC_PASEMI_IOMMU_DMA_FORCE)
90 return 1;
91#else
92 return firmware_has_feature(FW_FEATURE_LPAR);
93#endif
94}
95
Olof Johansson34c20622007-11-28 20:56:32 -060096static void write_iob_reg(unsigned int reg, unsigned int val)
Olof Johanssona85b9422007-09-15 13:40:59 -070097{
Olof Johansson34c20622007-11-28 20:56:32 -060098 pasemi_write_iob_reg(reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -070099}
100
Olof Johansson5c153322007-11-28 20:56:41 -0600101static unsigned int read_mac_reg(const struct pasemi_mac *mac, unsigned int reg)
Olof Johanssona85b9422007-09-15 13:40:59 -0700102{
Olof Johansson34c20622007-11-28 20:56:32 -0600103 return pasemi_read_mac_reg(mac->dma_if, reg);
Olof Johanssona85b9422007-09-15 13:40:59 -0700104}
105
Olof Johansson5c153322007-11-28 20:56:41 -0600106static void write_mac_reg(const struct pasemi_mac *mac, unsigned int reg,
Olof Johanssona85b9422007-09-15 13:40:59 -0700107 unsigned int val)
108{
Olof Johansson34c20622007-11-28 20:56:32 -0600109 pasemi_write_mac_reg(mac->dma_if, reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700110}
111
Olof Johansson34c20622007-11-28 20:56:32 -0600112static unsigned int read_dma_reg(unsigned int reg)
Olof Johanssona85b9422007-09-15 13:40:59 -0700113{
Olof Johansson34c20622007-11-28 20:56:32 -0600114 return pasemi_read_dma_reg(reg);
Olof Johanssona85b9422007-09-15 13:40:59 -0700115}
116
Olof Johansson34c20622007-11-28 20:56:32 -0600117static void write_dma_reg(unsigned int reg, unsigned int val)
Olof Johanssona85b9422007-09-15 13:40:59 -0700118{
Olof Johansson34c20622007-11-28 20:56:32 -0600119 pasemi_write_dma_reg(reg, val);
Olof Johanssona85b9422007-09-15 13:40:59 -0700120}
121
Olof Johansson5c153322007-11-28 20:56:41 -0600122static struct pasemi_mac_rxring *rx_ring(const struct pasemi_mac *mac)
Olof Johansson72b05b92007-11-28 20:54:28 -0600123{
124 return mac->rx;
125}
126
Olof Johansson5c153322007-11-28 20:56:41 -0600127static struct pasemi_mac_txring *tx_ring(const struct pasemi_mac *mac)
Olof Johansson72b05b92007-11-28 20:54:28 -0600128{
129 return mac->tx;
130}
131
Olof Johansson5c153322007-11-28 20:56:41 -0600132static inline void prefetch_skb(const struct sk_buff *skb)
133{
134 const void *d = skb;
135
136 prefetch(d);
137 prefetch(d+64);
138 prefetch(d+128);
139 prefetch(d+192);
140}
141
Olof Johansson34c20622007-11-28 20:56:32 -0600142static int mac_to_intf(struct pasemi_mac *mac)
143{
144 struct pci_dev *pdev = mac->pdev;
145 u32 tmp;
146 int nintf, off, i, j;
147 int devfn = pdev->devfn;
148
149 tmp = read_dma_reg(PAS_DMA_CAP_IFI);
150 nintf = (tmp & PAS_DMA_CAP_IFI_NIN_M) >> PAS_DMA_CAP_IFI_NIN_S;
151 off = (tmp & PAS_DMA_CAP_IFI_IOFF_M) >> PAS_DMA_CAP_IFI_IOFF_S;
152
153 /* IOFF contains the offset to the registers containing the
154 * DMA interface-to-MAC-pci-id mappings, and NIN contains number
155 * of total interfaces. Each register contains 4 devfns.
156 * Just do a linear search until we find the devfn of the MAC
157 * we're trying to look up.
158 */
159
160 for (i = 0; i < (nintf+3)/4; i++) {
161 tmp = read_dma_reg(off+4*i);
162 for (j = 0; j < 4; j++) {
163 if (((tmp >> (8*j)) & 0xff) == devfn)
164 return i*4 + j;
165 }
166 }
167 return -1;
168}
169
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600170static void pasemi_mac_intf_disable(struct pasemi_mac *mac)
171{
172 unsigned int flags;
173
174 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
175 flags &= ~PAS_MAC_CFG_PCFG_PE;
176 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
177}
178
179static void pasemi_mac_intf_enable(struct pasemi_mac *mac)
180{
181 unsigned int flags;
182
183 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
184 flags |= PAS_MAC_CFG_PCFG_PE;
185 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
186}
187
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600188static int pasemi_get_mac_addr(struct pasemi_mac *mac)
189{
190 struct pci_dev *pdev = mac->pdev;
191 struct device_node *dn = pci_device_to_OF_node(pdev);
olof@lixom.net1af7f052007-05-12 14:57:46 -0500192 int len;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600193 const u8 *maddr;
194 u8 addr[6];
195
196 if (!dn) {
197 dev_dbg(&pdev->dev,
198 "No device node for mac, not configuring\n");
199 return -ENOENT;
200 }
201
olof@lixom.net1af7f052007-05-12 14:57:46 -0500202 maddr = of_get_property(dn, "local-mac-address", &len);
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500203
olof@lixom.net1af7f052007-05-12 14:57:46 -0500204 if (maddr && len == 6) {
205 memcpy(mac->mac_addr, maddr, 6);
206 return 0;
207 }
208
209 /* Some old versions of firmware mistakenly uses mac-address
210 * (and as a string) instead of a byte array in local-mac-address.
211 */
212
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500213 if (maddr == NULL)
Linus Torvalds90287802007-05-08 11:57:17 -0700214 maddr = of_get_property(dn, "mac-address", NULL);
Olof Johanssona5fd22e2007-05-08 00:48:02 -0500215
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600216 if (maddr == NULL) {
217 dev_warn(&pdev->dev,
218 "no mac address in device tree, not configuring\n");
219 return -ENOENT;
220 }
221
222 if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
223 &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
224 dev_warn(&pdev->dev,
225 "can't parse mac address, not configuring\n");
226 return -EINVAL;
227 }
228
olof@lixom.net1af7f052007-05-12 14:57:46 -0500229 memcpy(mac->mac_addr, addr, 6);
230
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600231 return 0;
232}
233
Olof Johansson5cea73b2008-01-23 13:56:19 -0600234static int pasemi_mac_set_mac_addr(struct net_device *dev, void *p)
235{
236 struct pasemi_mac *mac = netdev_priv(dev);
237 struct sockaddr *addr = p;
238 unsigned int adr0, adr1;
239
240 if (!is_valid_ether_addr(addr->sa_data))
Danny Kukawka504f9b52012-02-21 02:07:49 +0000241 return -EADDRNOTAVAIL;
Olof Johansson5cea73b2008-01-23 13:56:19 -0600242
243 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
244
245 adr0 = dev->dev_addr[2] << 24 |
246 dev->dev_addr[3] << 16 |
247 dev->dev_addr[4] << 8 |
248 dev->dev_addr[5];
249 adr1 = read_mac_reg(mac, PAS_MAC_CFG_ADR1);
250 adr1 &= ~0xffff;
251 adr1 |= dev->dev_addr[0] << 8 | dev->dev_addr[1];
252
253 pasemi_mac_intf_disable(mac);
254 write_mac_reg(mac, PAS_MAC_CFG_ADR0, adr0);
255 write_mac_reg(mac, PAS_MAC_CFG_ADR1, adr1);
256 pasemi_mac_intf_enable(mac);
257
258 return 0;
259}
260
Olof Johansson28ae79f2007-11-28 20:57:27 -0600261static int get_skb_hdr(struct sk_buff *skb, void **iphdr,
262 void **tcph, u64 *hdr_flags, void *data)
263{
264 u64 macrx = (u64) data;
265 unsigned int ip_len;
266 struct iphdr *iph;
267
268 /* IPv4 header checksum failed */
269 if ((macrx & XCT_MACRX_HTY_M) != XCT_MACRX_HTY_IPV4_OK)
270 return -1;
271
272 /* non tcp packet */
273 skb_reset_network_header(skb);
274 iph = ip_hdr(skb);
275 if (iph->protocol != IPPROTO_TCP)
276 return -1;
277
278 ip_len = ip_hdrlen(skb);
279 skb_set_transport_header(skb, ip_len);
280 *tcph = tcp_hdr(skb);
281
282 /* check if ip header and tcp header are complete */
Roland Dreier77321232008-07-01 10:22:45 -0700283 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
Olof Johansson28ae79f2007-11-28 20:57:27 -0600284 return -1;
285
286 *hdr_flags = LRO_IPV4 | LRO_TCP;
287 *iphdr = iph;
288
289 return 0;
290}
291
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500292static int pasemi_mac_unmap_tx_skb(struct pasemi_mac *mac,
Olof Johansson7e9916e2007-11-28 20:57:45 -0600293 const int nfrags,
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500294 struct sk_buff *skb,
Olof Johansson5c153322007-11-28 20:56:41 -0600295 const dma_addr_t *dmas)
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500296{
297 int f;
Olof Johansson5c153322007-11-28 20:56:41 -0600298 struct pci_dev *pdev = mac->dma_pdev;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500299
Olof Johansson5c153322007-11-28 20:56:41 -0600300 pci_unmap_single(pdev, dmas[0], skb_headlen(skb), PCI_DMA_TODEVICE);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500301
302 for (f = 0; f < nfrags; f++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +0000303 const skb_frag_t *frag = &skb_shinfo(skb)->frags[f];
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500304
Eric Dumazet9e903e02011-10-18 21:00:24 +0000305 pci_unmap_page(pdev, dmas[f+1], skb_frag_size(frag), PCI_DMA_TODEVICE);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500306 }
307 dev_kfree_skb_irq(skb);
308
309 /* Freed descriptor slot + main SKB ptr + nfrags additional ptrs,
310 * aligned up to a power of 2
311 */
312 return (nfrags + 3) & ~1;
313}
314
Olof Johansson8d636d82008-03-05 16:34:16 -0600315static struct pasemi_mac_csring *pasemi_mac_setup_csring(struct pasemi_mac *mac)
316{
317 struct pasemi_mac_csring *ring;
318 u32 val;
319 unsigned int cfg;
320 int chno;
321
322 ring = pasemi_dma_alloc_chan(TXCHAN, sizeof(struct pasemi_mac_csring),
323 offsetof(struct pasemi_mac_csring, chan));
324
325 if (!ring) {
326 dev_err(&mac->pdev->dev, "Can't allocate checksum channel\n");
327 goto out_chan;
328 }
329
330 chno = ring->chan.chno;
331
332 ring->size = CS_RING_SIZE;
333 ring->next_to_fill = 0;
334
335 /* Allocate descriptors */
336 if (pasemi_dma_alloc_ring(&ring->chan, CS_RING_SIZE))
337 goto out_ring_desc;
338
339 write_dma_reg(PAS_DMA_TXCHAN_BASEL(chno),
340 PAS_DMA_TXCHAN_BASEL_BRBL(ring->chan.ring_dma));
341 val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->chan.ring_dma >> 32);
342 val |= PAS_DMA_TXCHAN_BASEU_SIZ(CS_RING_SIZE >> 3);
343
344 write_dma_reg(PAS_DMA_TXCHAN_BASEU(chno), val);
345
346 ring->events[0] = pasemi_dma_alloc_flag();
347 ring->events[1] = pasemi_dma_alloc_flag();
348 if (ring->events[0] < 0 || ring->events[1] < 0)
349 goto out_flags;
350
351 pasemi_dma_clear_flag(ring->events[0]);
352 pasemi_dma_clear_flag(ring->events[1]);
353
354 ring->fun = pasemi_dma_alloc_fun();
355 if (ring->fun < 0)
356 goto out_fun;
357
358 cfg = PAS_DMA_TXCHAN_CFG_TY_FUNC | PAS_DMA_TXCHAN_CFG_UP |
359 PAS_DMA_TXCHAN_CFG_TATTR(ring->fun) |
360 PAS_DMA_TXCHAN_CFG_LPSQ | PAS_DMA_TXCHAN_CFG_LPDQ;
361
362 if (translation_enabled())
363 cfg |= PAS_DMA_TXCHAN_CFG_TRD | PAS_DMA_TXCHAN_CFG_TRR;
364
365 write_dma_reg(PAS_DMA_TXCHAN_CFG(chno), cfg);
366
367 /* enable channel */
368 pasemi_dma_start_chan(&ring->chan, PAS_DMA_TXCHAN_TCMDSTA_SZ |
369 PAS_DMA_TXCHAN_TCMDSTA_DB |
370 PAS_DMA_TXCHAN_TCMDSTA_DE |
371 PAS_DMA_TXCHAN_TCMDSTA_DA);
372
373 return ring;
374
375out_fun:
376out_flags:
377 if (ring->events[0] >= 0)
378 pasemi_dma_free_flag(ring->events[0]);
379 if (ring->events[1] >= 0)
380 pasemi_dma_free_flag(ring->events[1]);
381 pasemi_dma_free_ring(&ring->chan);
382out_ring_desc:
383 pasemi_dma_free_chan(&ring->chan);
384out_chan:
385
386 return NULL;
387}
388
389static void pasemi_mac_setup_csrings(struct pasemi_mac *mac)
390{
391 int i;
392 mac->cs[0] = pasemi_mac_setup_csring(mac);
393 if (mac->type == MAC_TYPE_XAUI)
394 mac->cs[1] = pasemi_mac_setup_csring(mac);
395 else
396 mac->cs[1] = 0;
397
398 for (i = 0; i < MAX_CS; i++)
399 if (mac->cs[i])
400 mac->num_cs++;
401}
402
403static void pasemi_mac_free_csring(struct pasemi_mac_csring *csring)
404{
405 pasemi_dma_stop_chan(&csring->chan);
406 pasemi_dma_free_flag(csring->events[0]);
407 pasemi_dma_free_flag(csring->events[1]);
408 pasemi_dma_free_ring(&csring->chan);
409 pasemi_dma_free_chan(&csring->chan);
Olof Johansson1724ac22008-03-25 09:58:40 -0500410 pasemi_dma_free_fun(csring->fun);
Olof Johansson8d636d82008-03-05 16:34:16 -0600411}
412
Olof Johansson5c153322007-11-28 20:56:41 -0600413static int pasemi_mac_setup_rx_resources(const struct net_device *dev)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600414{
415 struct pasemi_mac_rxring *ring;
416 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson34c20622007-11-28 20:56:32 -0600417 int chno;
Olof Johanssonaf289e82007-10-03 13:03:54 -0500418 unsigned int cfg;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600419
Olof Johansson34c20622007-11-28 20:56:32 -0600420 ring = pasemi_dma_alloc_chan(RXCHAN, sizeof(struct pasemi_mac_rxring),
421 offsetof(struct pasemi_mac_rxring, chan));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600422
Olof Johansson34c20622007-11-28 20:56:32 -0600423 if (!ring) {
424 dev_err(&mac->pdev->dev, "Can't allocate RX channel\n");
425 goto out_chan;
426 }
427 chno = ring->chan.chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600428
429 spin_lock_init(&ring->lock);
430
Olof Johansson021fa222007-08-22 09:13:11 -0500431 ring->size = RX_RING_SIZE;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500432 ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600433 RX_RING_SIZE, GFP_KERNEL);
434
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500435 if (!ring->ring_info)
436 goto out_ring_info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600437
438 /* Allocate descriptors */
Olof Johansson34c20622007-11-28 20:56:32 -0600439 if (pasemi_dma_alloc_ring(&ring->chan, RX_RING_SIZE))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500440 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600441
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600442 ring->buffers = dma_alloc_coherent(&mac->dma_pdev->dev,
443 RX_RING_SIZE * sizeof(u64),
444 &ring->buf_dma, GFP_KERNEL);
445 if (!ring->buffers)
Olof Johansson34c20622007-11-28 20:56:32 -0600446 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600447
448 memset(ring->buffers, 0, RX_RING_SIZE * sizeof(u64));
449
Olof Johansson34c20622007-11-28 20:56:32 -0600450 write_dma_reg(PAS_DMA_RXCHAN_BASEL(chno),
451 PAS_DMA_RXCHAN_BASEL_BRBL(ring->chan.ring_dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600452
Olof Johansson34c20622007-11-28 20:56:32 -0600453 write_dma_reg(PAS_DMA_RXCHAN_BASEU(chno),
454 PAS_DMA_RXCHAN_BASEU_BRBH(ring->chan.ring_dma >> 32) |
455 PAS_DMA_RXCHAN_BASEU_SIZ(RX_RING_SIZE >> 3));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600456
Olof Johansson5c153322007-11-28 20:56:41 -0600457 cfg = PAS_DMA_RXCHAN_CFG_HBU(2);
Olof Johanssonaf289e82007-10-03 13:03:54 -0500458
459 if (translation_enabled())
460 cfg |= PAS_DMA_RXCHAN_CFG_CTR;
461
Olof Johansson34c20622007-11-28 20:56:32 -0600462 write_dma_reg(PAS_DMA_RXCHAN_CFG(chno), cfg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600463
Olof Johansson34c20622007-11-28 20:56:32 -0600464 write_dma_reg(PAS_DMA_RXINT_BASEL(mac->dma_if),
465 PAS_DMA_RXINT_BASEL_BRBL(ring->buf_dma));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600466
Olof Johansson34c20622007-11-28 20:56:32 -0600467 write_dma_reg(PAS_DMA_RXINT_BASEU(mac->dma_if),
468 PAS_DMA_RXINT_BASEU_BRBH(ring->buf_dma >> 32) |
469 PAS_DMA_RXINT_BASEU_SIZ(RX_RING_SIZE >> 3));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600470
Olof Johansson5c153322007-11-28 20:56:41 -0600471 cfg = PAS_DMA_RXINT_CFG_DHL(2) | PAS_DMA_RXINT_CFG_L2 |
Olof Johanssonaf289e82007-10-03 13:03:54 -0500472 PAS_DMA_RXINT_CFG_LW | PAS_DMA_RXINT_CFG_RBP |
473 PAS_DMA_RXINT_CFG_HEN;
474
475 if (translation_enabled())
476 cfg |= PAS_DMA_RXINT_CFG_ITRR | PAS_DMA_RXINT_CFG_ITR;
477
Olof Johansson34c20622007-11-28 20:56:32 -0600478 write_dma_reg(PAS_DMA_RXINT_CFG(mac->dma_if), cfg);
Olof Johanssonc0efd522007-08-22 09:12:52 -0500479
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600480 ring->next_to_fill = 0;
481 ring->next_to_clean = 0;
Olof Johansson72b05b92007-11-28 20:54:28 -0600482 ring->mac = mac;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600483 mac->rx = ring;
484
485 return 0;
486
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500487out_ring_desc:
488 kfree(ring->ring_info);
489out_ring_info:
Olof Johansson34c20622007-11-28 20:56:32 -0600490 pasemi_dma_free_chan(&ring->chan);
491out_chan:
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600492 return -ENOMEM;
493}
494
Olof Johansson72b05b92007-11-28 20:54:28 -0600495static struct pasemi_mac_txring *
Olof Johansson5c153322007-11-28 20:56:41 -0600496pasemi_mac_setup_tx_resources(const struct net_device *dev)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600497{
498 struct pasemi_mac *mac = netdev_priv(dev);
499 u32 val;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600500 struct pasemi_mac_txring *ring;
Olof Johanssonaf289e82007-10-03 13:03:54 -0500501 unsigned int cfg;
Olof Johansson34c20622007-11-28 20:56:32 -0600502 int chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600503
Olof Johansson34c20622007-11-28 20:56:32 -0600504 ring = pasemi_dma_alloc_chan(TXCHAN, sizeof(struct pasemi_mac_txring),
505 offsetof(struct pasemi_mac_txring, chan));
506
507 if (!ring) {
508 dev_err(&mac->pdev->dev, "Can't allocate TX channel\n");
509 goto out_chan;
510 }
511
512 chno = ring->chan.chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600513
514 spin_lock_init(&ring->lock);
515
Olof Johansson021fa222007-08-22 09:13:11 -0500516 ring->size = TX_RING_SIZE;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500517 ring->ring_info = kzalloc(sizeof(struct pasemi_mac_buffer) *
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600518 TX_RING_SIZE, GFP_KERNEL);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500519 if (!ring->ring_info)
520 goto out_ring_info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600521
522 /* Allocate descriptors */
Olof Johansson34c20622007-11-28 20:56:32 -0600523 if (pasemi_dma_alloc_ring(&ring->chan, TX_RING_SIZE))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500524 goto out_ring_desc;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600525
Olof Johansson34c20622007-11-28 20:56:32 -0600526 write_dma_reg(PAS_DMA_TXCHAN_BASEL(chno),
527 PAS_DMA_TXCHAN_BASEL_BRBL(ring->chan.ring_dma));
528 val = PAS_DMA_TXCHAN_BASEU_BRBH(ring->chan.ring_dma >> 32);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500529 val |= PAS_DMA_TXCHAN_BASEU_SIZ(TX_RING_SIZE >> 3);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600530
Olof Johansson34c20622007-11-28 20:56:32 -0600531 write_dma_reg(PAS_DMA_TXCHAN_BASEU(chno), val);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600532
Olof Johanssonaf289e82007-10-03 13:03:54 -0500533 cfg = PAS_DMA_TXCHAN_CFG_TY_IFACE |
534 PAS_DMA_TXCHAN_CFG_TATTR(mac->dma_if) |
535 PAS_DMA_TXCHAN_CFG_UP |
Olof Johansson8d636d82008-03-05 16:34:16 -0600536 PAS_DMA_TXCHAN_CFG_WT(4);
Olof Johanssonaf289e82007-10-03 13:03:54 -0500537
538 if (translation_enabled())
539 cfg |= PAS_DMA_TXCHAN_CFG_TRD | PAS_DMA_TXCHAN_CFG_TRR;
540
Olof Johansson34c20622007-11-28 20:56:32 -0600541 write_dma_reg(PAS_DMA_TXCHAN_CFG(chno), cfg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600542
Olof Johansson021fa222007-08-22 09:13:11 -0500543 ring->next_to_fill = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600544 ring->next_to_clean = 0;
Olof Johansson72b05b92007-11-28 20:54:28 -0600545 ring->mac = mac;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600546
Olof Johansson72b05b92007-11-28 20:54:28 -0600547 return ring;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600548
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500549out_ring_desc:
550 kfree(ring->ring_info);
551out_ring_info:
Olof Johansson34c20622007-11-28 20:56:32 -0600552 pasemi_dma_free_chan(&ring->chan);
553out_chan:
Olof Johansson72b05b92007-11-28 20:54:28 -0600554 return NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600555}
556
Olof Johansson72b05b92007-11-28 20:54:28 -0600557static void pasemi_mac_free_tx_resources(struct pasemi_mac *mac)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600558{
Olof Johansson72b05b92007-11-28 20:54:28 -0600559 struct pasemi_mac_txring *txring = tx_ring(mac);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500560 unsigned int i, j;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600561 struct pasemi_mac_buffer *info;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500562 dma_addr_t dmas[MAX_SKB_FRAGS+1];
Olof Johansson7e9916e2007-11-28 20:57:45 -0600563 int freed, nfrags;
Olof Johanssonad5da102007-10-02 16:27:15 -0500564 int start, limit;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600565
Olof Johansson72b05b92007-11-28 20:54:28 -0600566 start = txring->next_to_clean;
567 limit = txring->next_to_fill;
Olof Johanssonad5da102007-10-02 16:27:15 -0500568
569 /* Compensate for when fill has wrapped and clean has not */
570 if (start > limit)
571 limit += TX_RING_SIZE;
572
573 for (i = start; i < limit; i += freed) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600574 info = &txring->ring_info[(i+1) & (TX_RING_SIZE-1)];
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500575 if (info->dma && info->skb) {
Olof Johansson7e9916e2007-11-28 20:57:45 -0600576 nfrags = skb_shinfo(info->skb)->nr_frags;
577 for (j = 0; j <= nfrags; j++)
Olof Johansson72b05b92007-11-28 20:54:28 -0600578 dmas[j] = txring->ring_info[(i+1+j) &
579 (TX_RING_SIZE-1)].dma;
Olof Johansson7e9916e2007-11-28 20:57:45 -0600580 freed = pasemi_mac_unmap_tx_skb(mac, nfrags,
581 info->skb, dmas);
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000582 } else {
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500583 freed = 2;
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000584 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600585 }
586
Olof Johansson72b05b92007-11-28 20:54:28 -0600587 kfree(txring->ring_info);
Olof Johansson34c20622007-11-28 20:56:32 -0600588 pasemi_dma_free_chan(&txring->chan);
589
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600590}
591
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600592static void pasemi_mac_free_rx_buffers(struct pasemi_mac *mac)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600593{
Olof Johansson72b05b92007-11-28 20:54:28 -0600594 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600595 unsigned int i;
596 struct pasemi_mac_buffer *info;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600597
598 for (i = 0; i < RX_RING_SIZE; i++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600599 info = &RX_DESC_INFO(rx, i);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500600 if (info->skb && info->dma) {
601 pci_unmap_single(mac->dma_pdev,
602 info->dma,
603 info->skb->len,
604 PCI_DMA_FROMDEVICE);
605 dev_kfree_skb_any(info->skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600606 }
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500607 info->dma = 0;
608 info->skb = NULL;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600609 }
610
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500611 for (i = 0; i < RX_RING_SIZE; i++)
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600612 RX_BUFF(rx, i) = 0;
613}
614
615static void pasemi_mac_free_rx_resources(struct pasemi_mac *mac)
616{
617 pasemi_mac_free_rx_buffers(mac);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500618
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600619 dma_free_coherent(&mac->dma_pdev->dev, RX_RING_SIZE * sizeof(u64),
Olof Johansson72b05b92007-11-28 20:54:28 -0600620 rx_ring(mac)->buffers, rx_ring(mac)->buf_dma);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600621
Olof Johansson72b05b92007-11-28 20:54:28 -0600622 kfree(rx_ring(mac)->ring_info);
Olof Johansson34c20622007-11-28 20:56:32 -0600623 pasemi_dma_free_chan(&rx_ring(mac)->chan);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600624 mac->rx = NULL;
625}
626
Stephen Rothwell5c6239c2012-05-03 10:51:46 +1000627static void pasemi_mac_replenish_rx_ring(struct net_device *dev,
Olof Johansson5c153322007-11-28 20:56:41 -0600628 const int limit)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600629{
Olof Johansson5c153322007-11-28 20:56:41 -0600630 const struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -0600631 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500632 int fill, count;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600633
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500634 if (limit <= 0)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600635 return;
636
Olof Johansson72b05b92007-11-28 20:54:28 -0600637 fill = rx_ring(mac)->next_to_fill;
Olof Johansson928773c2007-09-26 16:25:06 -0500638 for (count = 0; count < limit; count++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600639 struct pasemi_mac_buffer *info = &RX_DESC_INFO(rx, fill);
640 u64 *buff = &RX_BUFF(rx, fill);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600641 struct sk_buff *skb;
642 dma_addr_t dma;
643
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500644 /* Entry in use? */
645 WARN_ON(*buff);
646
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +0000647 skb = netdev_alloc_skb(dev, mac->bufsz);
Olof Johansson5d894942007-11-28 20:57:56 -0600648 skb_reserve(skb, LOCAL_SKB_ALIGN);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600649
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500650 if (unlikely(!skb))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600651 break;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600652
Olof Johansson8dc121a2007-10-02 16:26:53 -0500653 dma = pci_map_single(mac->dma_pdev, skb->data,
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600654 mac->bufsz - LOCAL_SKB_ALIGN,
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600655 PCI_DMA_FROMDEVICE);
656
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -0700657 if (unlikely(pci_dma_mapping_error(mac->dma_pdev, dma))) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600658 dev_kfree_skb_irq(info->skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600659 break;
660 }
661
662 info->skb = skb;
663 info->dma = dma;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600664 *buff = XCT_RXB_LEN(mac->bufsz) | XCT_RXB_ADDR(dma);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500665 fill++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600666 }
667
668 wmb();
669
Olof Johansson34c20622007-11-28 20:56:32 -0600670 write_dma_reg(PAS_DMA_RXINT_INCR(mac->dma_if), count);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600671
Olof Johansson72b05b92007-11-28 20:54:28 -0600672 rx_ring(mac)->next_to_fill = (rx_ring(mac)->next_to_fill + count) &
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500673 (RX_RING_SIZE - 1);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600674}
675
Olof Johansson5c153322007-11-28 20:56:41 -0600676static void pasemi_mac_restart_rx_intr(const struct pasemi_mac *mac)
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500677{
Olof Johansson906674a2007-11-28 20:57:09 -0600678 struct pasemi_mac_rxring *rx = rx_ring(mac);
Olof Johansson52a94352007-05-12 18:01:09 -0500679 unsigned int reg, pcnt;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500680 /* Re-enable packet count interrupts: finally
681 * ack the packet count interrupt we got in rx_intr.
682 */
683
Olof Johansson906674a2007-11-28 20:57:09 -0600684 pcnt = *rx->chan.status & PAS_STATUS_PCNT_M;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500685
Olof Johansson52a94352007-05-12 18:01:09 -0500686 reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500687
Olof Johansson906674a2007-11-28 20:57:09 -0600688 if (*rx->chan.status & PAS_STATUS_TIMER)
689 reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
690
Olof Johansson34c20622007-11-28 20:56:32 -0600691 write_iob_reg(PAS_IOB_DMA_RXCH_RESET(mac->rx->chan.chno), reg);
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500692}
693
Olof Johansson5c153322007-11-28 20:56:41 -0600694static void pasemi_mac_restart_tx_intr(const struct pasemi_mac *mac)
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500695{
Olof Johansson52a94352007-05-12 18:01:09 -0500696 unsigned int reg, pcnt;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500697
698 /* Re-enable packet count interrupts */
Olof Johansson34c20622007-11-28 20:56:32 -0600699 pcnt = *tx_ring(mac)->chan.status & PAS_STATUS_PCNT_M;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500700
Olof Johansson52a94352007-05-12 18:01:09 -0500701 reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500702
Olof Johansson34c20622007-11-28 20:56:32 -0600703 write_iob_reg(PAS_IOB_DMA_TXCH_RESET(tx_ring(mac)->chan.chno), reg);
Olof Johansson1b0335ea2007-05-08 00:47:26 -0500704}
705
706
Olof Johansson5c153322007-11-28 20:56:41 -0600707static inline void pasemi_mac_rx_error(const struct pasemi_mac *mac,
708 const u64 macrx)
Olof Johansson69c29d82007-10-02 16:24:51 -0500709{
710 unsigned int rcmdsta, ccmdsta;
Olof Johansson34c20622007-11-28 20:56:32 -0600711 struct pasemi_dmachan *chan = &rx_ring(mac)->chan;
Olof Johansson69c29d82007-10-02 16:24:51 -0500712
713 if (!netif_msg_rx_err(mac))
714 return;
715
Olof Johansson34c20622007-11-28 20:56:32 -0600716 rcmdsta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
717 ccmdsta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(chan->chno));
Olof Johansson69c29d82007-10-02 16:24:51 -0500718
Ingo Molnarfe333322009-01-06 14:26:03 +0000719 printk(KERN_ERR "pasemi_mac: rx error. macrx %016llx, rx status %llx\n",
Olof Johansson34c20622007-11-28 20:56:32 -0600720 macrx, *chan->status);
Olof Johansson69c29d82007-10-02 16:24:51 -0500721
722 printk(KERN_ERR "pasemi_mac: rcmdsta %08x ccmdsta %08x\n",
723 rcmdsta, ccmdsta);
724}
725
Olof Johansson5c153322007-11-28 20:56:41 -0600726static inline void pasemi_mac_tx_error(const struct pasemi_mac *mac,
727 const u64 mactx)
Olof Johansson69c29d82007-10-02 16:24:51 -0500728{
729 unsigned int cmdsta;
Olof Johansson34c20622007-11-28 20:56:32 -0600730 struct pasemi_dmachan *chan = &tx_ring(mac)->chan;
Olof Johansson69c29d82007-10-02 16:24:51 -0500731
732 if (!netif_msg_tx_err(mac))
733 return;
734
Olof Johansson34c20622007-11-28 20:56:32 -0600735 cmdsta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(chan->chno));
Olof Johansson69c29d82007-10-02 16:24:51 -0500736
Ingo Molnarfe333322009-01-06 14:26:03 +0000737 printk(KERN_ERR "pasemi_mac: tx error. mactx 0x%016llx, "\
738 "tx status 0x%016llx\n", mactx, *chan->status);
Olof Johansson69c29d82007-10-02 16:24:51 -0500739
740 printk(KERN_ERR "pasemi_mac: tcmdsta 0x%08x\n", cmdsta);
741}
742
Olof Johansson5c153322007-11-28 20:56:41 -0600743static int pasemi_mac_clean_rx(struct pasemi_mac_rxring *rx,
744 const int limit)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600745{
Olof Johansson5c153322007-11-28 20:56:41 -0600746 const struct pasemi_dmachan *chan = &rx->chan;
Olof Johansson72b05b92007-11-28 20:54:28 -0600747 struct pasemi_mac *mac = rx->mac;
Olof Johansson5c153322007-11-28 20:56:41 -0600748 struct pci_dev *pdev = mac->dma_pdev;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500749 unsigned int n;
Olof Johansson5c153322007-11-28 20:56:41 -0600750 int count, buf_index, tot_bytes, packets;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500751 struct pasemi_mac_buffer *info;
752 struct sk_buff *skb;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500753 unsigned int len;
Olof Johansson5c153322007-11-28 20:56:41 -0600754 u64 macrx, eval;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500755 dma_addr_t dma;
Olof Johansson5c153322007-11-28 20:56:41 -0600756
757 tot_bytes = 0;
758 packets = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600759
Olof Johansson72b05b92007-11-28 20:54:28 -0600760 spin_lock(&rx->lock);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600761
Olof Johansson72b05b92007-11-28 20:54:28 -0600762 n = rx->next_to_clean;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600763
Olof Johansson72b05b92007-11-28 20:54:28 -0600764 prefetch(&RX_DESC(rx, n));
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500765
766 for (count = 0; count < limit; count++) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600767 macrx = RX_DESC(rx, n);
Olof Johansson5c153322007-11-28 20:56:41 -0600768 prefetch(&RX_DESC(rx, n+4));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600769
Olof Johansson69c29d82007-10-02 16:24:51 -0500770 if ((macrx & XCT_MACRX_E) ||
Olof Johansson34c20622007-11-28 20:56:32 -0600771 (*chan->status & PAS_STATUS_ERROR))
Olof Johansson69c29d82007-10-02 16:24:51 -0500772 pasemi_mac_rx_error(mac, macrx);
773
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500774 if (!(macrx & XCT_MACRX_O))
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600775 break;
776
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600777 info = NULL;
778
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500779 BUG_ON(!(macrx & XCT_MACRX_RR_8BRES));
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600780
Olof Johansson72b05b92007-11-28 20:54:28 -0600781 eval = (RX_DESC(rx, n+1) & XCT_RXRES_8B_EVAL_M) >>
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500782 XCT_RXRES_8B_EVAL_S;
783 buf_index = eval-1;
784
Olof Johansson72b05b92007-11-28 20:54:28 -0600785 dma = (RX_DESC(rx, n+2) & XCT_PTR_ADDR_M);
786 info = &RX_DESC_INFO(rx, buf_index);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500787
Olof Johansson9f05cfe2007-05-08 00:47:37 -0500788 skb = info->skb;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600789
Olof Johansson5c153322007-11-28 20:56:41 -0600790 prefetch_skb(skb);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600791
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500792 len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600793
Olof Johanssonef1ea0b2008-01-23 13:56:47 -0600794 pci_unmap_single(pdev, dma, mac->bufsz - LOCAL_SKB_ALIGN,
Olof Johansson5c153322007-11-28 20:56:41 -0600795 PCI_DMA_FROMDEVICE);
Olof Johansson32bee772007-11-06 22:21:38 -0600796
797 if (macrx & XCT_MACRX_CRC) {
798 /* CRC error flagged */
799 mac->netdev->stats.rx_errors++;
800 mac->netdev->stats.rx_crc_errors++;
Olof Johansson4352d822007-12-03 21:34:14 -0600801 /* No need to free skb, it'll be reused */
Olof Johansson32bee772007-11-06 22:21:38 -0600802 goto next;
803 }
804
Olof Johansson5d894942007-11-28 20:57:56 -0600805 info->skb = NULL;
Olof Johanssonad5da102007-10-02 16:27:15 -0500806 info->dma = 0;
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500807
Olof Johansson26fcfa92007-08-22 09:12:59 -0500808 if (likely((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK)) {
Olof Johansson38bf3182007-08-22 09:13:24 -0500809 skb->ip_summed = CHECKSUM_UNNECESSARY;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500810 skb->csum = (macrx & XCT_MACRX_CSUM_M) >>
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600811 XCT_MACRX_CSUM_S;
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000812 } else {
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700813 skb_checksum_none_assert(skb);
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +0000814 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600815
Olof Johansson5c153322007-11-28 20:56:41 -0600816 packets++;
817 tot_bytes += len;
818
819 /* Don't include CRC */
820 skb_put(skb, len-4);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600821
Olof Johansson26fcfa92007-08-22 09:12:59 -0500822 skb->protocol = eth_type_trans(skb, mac->netdev);
Olof Johansson28ae79f2007-11-28 20:57:27 -0600823 lro_receive_skb(&mac->lro_mgr, skb, (void *)macrx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600824
Olof Johansson32bee772007-11-06 22:21:38 -0600825next:
Olof Johansson72b05b92007-11-28 20:54:28 -0600826 RX_DESC(rx, n) = 0;
827 RX_DESC(rx, n+1) = 0;
Olof Johanssoncd4ceb22007-05-08 00:47:45 -0500828
Olof Johanssonad5da102007-10-02 16:27:15 -0500829 /* Need to zero it out since hardware doesn't, since the
830 * replenish loop uses it to tell when it's done.
831 */
Olof Johansson72b05b92007-11-28 20:54:28 -0600832 RX_BUFF(rx, buf_index) = 0;
Olof Johanssonad5da102007-10-02 16:27:15 -0500833
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500834 n += 4;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600835 }
836
Olof Johansson9a50beb2007-10-02 16:26:30 -0500837 if (n > RX_RING_SIZE) {
838 /* Errata 5971 workaround: L2 target of headers */
Olof Johansson34c20622007-11-28 20:56:32 -0600839 write_iob_reg(PAS_IOB_COM_PKTHDRCNT, 0);
Olof Johansson9a50beb2007-10-02 16:26:30 -0500840 n &= (RX_RING_SIZE-1);
841 }
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500842
Olof Johansson72b05b92007-11-28 20:54:28 -0600843 rx_ring(mac)->next_to_clean = n;
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500844
Olof Johansson28ae79f2007-11-28 20:57:27 -0600845 lro_flush_all(&mac->lro_mgr);
846
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500847 /* Increase is in number of 16-byte entries, and since each descriptor
848 * with an 8BRES takes up 3x8 bytes (padded to 4x8), increase with
849 * count*2.
850 */
Olof Johansson34c20622007-11-28 20:56:32 -0600851 write_dma_reg(PAS_DMA_RXCHAN_INCR(mac->rx->chan.chno), count << 1);
Olof Johanssonb5254ee2007-10-02 16:27:57 -0500852
853 pasemi_mac_replenish_rx_ring(mac->netdev, count);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600854
Olof Johansson5c153322007-11-28 20:56:41 -0600855 mac->netdev->stats.rx_bytes += tot_bytes;
856 mac->netdev->stats.rx_packets += packets;
857
Olof Johansson72b05b92007-11-28 20:54:28 -0600858 spin_unlock(&rx_ring(mac)->lock);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600859
860 return count;
861}
862
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500863/* Can't make this too large or we blow the kernel stack limits */
864#define TX_CLEAN_BATCHSIZE (128/MAX_SKB_FRAGS)
865
Olof Johansson72b05b92007-11-28 20:54:28 -0600866static int pasemi_mac_clean_tx(struct pasemi_mac_txring *txring)
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600867{
Olof Johansson34c20622007-11-28 20:56:32 -0600868 struct pasemi_dmachan *chan = &txring->chan;
Olof Johansson72b05b92007-11-28 20:54:28 -0600869 struct pasemi_mac *mac = txring->mac;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500870 int i, j;
Olof Johanssonad5da102007-10-02 16:27:15 -0500871 unsigned int start, descr_count, buf_count, batch_limit;
872 unsigned int ring_limit;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500873 unsigned int total_count;
Olof Johanssonca7e2352007-09-26 16:23:59 -0500874 unsigned long flags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500875 struct sk_buff *skbs[TX_CLEAN_BATCHSIZE];
876 dma_addr_t dmas[TX_CLEAN_BATCHSIZE][MAX_SKB_FRAGS+1];
Olof Johansson7e9916e2007-11-28 20:57:45 -0600877 int nf[TX_CLEAN_BATCHSIZE];
878 int nr_frags;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600879
Olof Johansson02df6cf2007-08-22 09:13:03 -0500880 total_count = 0;
Olof Johanssonad5da102007-10-02 16:27:15 -0500881 batch_limit = TX_CLEAN_BATCHSIZE;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500882restart:
Olof Johansson72b05b92007-11-28 20:54:28 -0600883 spin_lock_irqsave(&txring->lock, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600884
Olof Johansson72b05b92007-11-28 20:54:28 -0600885 start = txring->next_to_clean;
886 ring_limit = txring->next_to_fill;
Olof Johanssonad5da102007-10-02 16:27:15 -0500887
Olof Johansson7e9916e2007-11-28 20:57:45 -0600888 prefetch(&TX_DESC_INFO(txring, start+1).skb);
889
Olof Johanssonad5da102007-10-02 16:27:15 -0500890 /* Compensate for when fill has wrapped but clean has not */
891 if (start > ring_limit)
892 ring_limit += TX_RING_SIZE;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500893
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500894 buf_count = 0;
895 descr_count = 0;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600896
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500897 for (i = start;
Olof Johanssonad5da102007-10-02 16:27:15 -0500898 descr_count < batch_limit && i < ring_limit;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500899 i += buf_count) {
Olof Johansson72b05b92007-11-28 20:54:28 -0600900 u64 mactx = TX_DESC(txring, i);
Olof Johanssonad5da102007-10-02 16:27:15 -0500901 struct sk_buff *skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500902
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500903 if ((mactx & XCT_MACTX_E) ||
Olof Johansson34c20622007-11-28 20:56:32 -0600904 (*chan->status & PAS_STATUS_ERROR))
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500905 pasemi_mac_tx_error(mac, mactx);
Olof Johansson69c29d82007-10-02 16:24:51 -0500906
Olof Johansson8d636d82008-03-05 16:34:16 -0600907 /* Skip over control descriptors */
908 if (!(mactx & XCT_MACTX_LLEN_M)) {
909 TX_DESC(txring, i) = 0;
910 TX_DESC(txring, i+1) = 0;
911 buf_count = 2;
912 continue;
913 }
914
915 skb = TX_DESC_INFO(txring, i+1).skb;
916 nr_frags = TX_DESC_INFO(txring, i).dma;
917
Olof Johanssonfc9e4d22007-10-02 16:25:53 -0500918 if (unlikely(mactx & XCT_MACTX_O))
Olof Johansson02df6cf2007-08-22 09:13:03 -0500919 /* Not yet transmitted */
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600920 break;
921
Olof Johansson7e9916e2007-11-28 20:57:45 -0600922 buf_count = 2 + nr_frags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500923 /* Since we always fill with an even number of entries, make
924 * sure we skip any unused one at the end as well.
925 */
926 if (buf_count & 1)
927 buf_count++;
Olof Johansson7e9916e2007-11-28 20:57:45 -0600928
929 for (j = 0; j <= nr_frags; j++)
930 dmas[descr_count][j] = TX_DESC_INFO(txring, i+1+j).dma;
931
932 skbs[descr_count] = skb;
933 nf[descr_count] = nr_frags;
934
935 TX_DESC(txring, i) = 0;
936 TX_DESC(txring, i+1) = 0;
937
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500938 descr_count++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600939 }
Olof Johansson72b05b92007-11-28 20:54:28 -0600940 txring->next_to_clean = i & (TX_RING_SIZE-1);
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500941
Olof Johansson72b05b92007-11-28 20:54:28 -0600942 spin_unlock_irqrestore(&txring->lock, flags);
Olof Johansson0ce68c72007-04-28 15:36:40 -0500943 netif_wake_queue(mac->netdev);
944
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500945 for (i = 0; i < descr_count; i++)
Olof Johansson7e9916e2007-11-28 20:57:45 -0600946 pasemi_mac_unmap_tx_skb(mac, nf[i], skbs[i], dmas[i]);
Olof Johansson02df6cf2007-08-22 09:13:03 -0500947
Olof Johanssonad3c20d2007-10-02 16:26:13 -0500948 total_count += descr_count;
Olof Johansson02df6cf2007-08-22 09:13:03 -0500949
950 /* If the batch was full, try to clean more */
Olof Johanssonad5da102007-10-02 16:27:15 -0500951 if (descr_count == batch_limit)
Olof Johansson02df6cf2007-08-22 09:13:03 -0500952 goto restart;
953
954 return total_count;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600955}
956
957
958static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
959{
Olof Johansson5c153322007-11-28 20:56:41 -0600960 const struct pasemi_mac_rxring *rxring = data;
Olof Johansson34c20622007-11-28 20:56:32 -0600961 struct pasemi_mac *mac = rxring->mac;
Olof Johansson5c153322007-11-28 20:56:41 -0600962 const struct pasemi_dmachan *chan = &rxring->chan;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600963 unsigned int reg;
964
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 Johansson6dfa7522007-05-08 00:47:32 -0500968 /* Don't reset packet count so it won't fire again but clear
969 * all others.
970 */
971
Olof Johansson6dfa7522007-05-08 00:47:32 -0500972 reg = 0;
Olof Johansson34c20622007-11-28 20:56:32 -0600973 if (*chan->status & PAS_STATUS_SOFT)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500974 reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
Olof Johansson34c20622007-11-28 20:56:32 -0600975 if (*chan->status & PAS_STATUS_ERROR)
Olof Johansson6dfa7522007-05-08 00:47:32 -0500976 reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600977
Ben Hutchings288379f2009-01-19 16:43:59 -0800978 napi_schedule(&mac->napi);
Olof Johansson6dfa7522007-05-08 00:47:32 -0500979
Olof Johansson34c20622007-11-28 20:56:32 -0600980 write_iob_reg(PAS_IOB_DMA_RXCH_RESET(chan->chno), reg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600981
982 return IRQ_HANDLED;
983}
984
Olof Johansson61cec3b2007-11-28 20:56:54 -0600985#define TX_CLEAN_INTERVAL HZ
986
987static void pasemi_mac_tx_timer(unsigned long data)
988{
989 struct pasemi_mac_txring *txring = (struct pasemi_mac_txring *)data;
990 struct pasemi_mac *mac = txring->mac;
991
992 pasemi_mac_clean_tx(txring);
993
994 mod_timer(&txring->clean_timer, jiffies + TX_CLEAN_INTERVAL);
995
996 pasemi_mac_restart_tx_intr(mac);
997}
998
Olof Johanssonf5cd7872007-01-31 21:43:54 -0600999static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
1000{
Olof Johansson72b05b92007-11-28 20:54:28 -06001001 struct pasemi_mac_txring *txring = data;
Olof Johansson5c153322007-11-28 20:56:41 -06001002 const struct pasemi_dmachan *chan = &txring->chan;
Olof Johansson61cec3b2007-11-28 20:56:54 -06001003 struct pasemi_mac *mac = txring->mac;
1004 unsigned int reg;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001005
Olof Johansson34c20622007-11-28 20:56:32 -06001006 if (!(*chan->status & PAS_STATUS_CAUSE_M))
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001007 return IRQ_NONE;
1008
Olof Johansson61cec3b2007-11-28 20:56:54 -06001009 reg = 0;
Olof Johansson6dfa7522007-05-08 00:47:32 -05001010
Olof Johansson34c20622007-11-28 20:56:32 -06001011 if (*chan->status & PAS_STATUS_SOFT)
Olof Johansson6dfa7522007-05-08 00:47:32 -05001012 reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
Olof Johansson34c20622007-11-28 20:56:32 -06001013 if (*chan->status & PAS_STATUS_ERROR)
Olof Johansson6dfa7522007-05-08 00:47:32 -05001014 reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001015
Olof Johansson61cec3b2007-11-28 20:56:54 -06001016 mod_timer(&txring->clean_timer, jiffies + (TX_CLEAN_INTERVAL)*2);
1017
Ben Hutchings288379f2009-01-19 16:43:59 -08001018 napi_schedule(&mac->napi);
Olof Johansson61cec3b2007-11-28 20:56:54 -06001019
1020 if (reg)
1021 write_iob_reg(PAS_IOB_DMA_TXCH_RESET(chan->chno), reg);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001022
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001023 return IRQ_HANDLED;
1024}
1025
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001026static void pasemi_adjust_link(struct net_device *dev)
1027{
1028 struct pasemi_mac *mac = netdev_priv(dev);
1029 int msg;
1030 unsigned int flags;
1031 unsigned int new_flags;
1032
1033 if (!mac->phydev->link) {
1034 /* If no link, MAC speed settings don't matter. Just report
1035 * link down and return.
1036 */
1037 if (mac->link && netif_msg_link(mac))
1038 printk(KERN_INFO "%s: Link is down.\n", dev->name);
1039
1040 netif_carrier_off(dev);
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001041 pasemi_mac_intf_disable(mac);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001042 mac->link = 0;
1043
1044 return;
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001045 } else {
1046 pasemi_mac_intf_enable(mac);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001047 netif_carrier_on(dev);
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001048 }
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001049
Olof Johanssona85b9422007-09-15 13:40:59 -07001050 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001051 new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M |
1052 PAS_MAC_CFG_PCFG_TSR_M);
1053
1054 if (!mac->phydev->duplex)
1055 new_flags |= PAS_MAC_CFG_PCFG_HD;
1056
1057 switch (mac->phydev->speed) {
1058 case 1000:
1059 new_flags |= PAS_MAC_CFG_PCFG_SPD_1G |
1060 PAS_MAC_CFG_PCFG_TSR_1G;
1061 break;
1062 case 100:
1063 new_flags |= PAS_MAC_CFG_PCFG_SPD_100M |
1064 PAS_MAC_CFG_PCFG_TSR_100M;
1065 break;
1066 case 10:
1067 new_flags |= PAS_MAC_CFG_PCFG_SPD_10M |
1068 PAS_MAC_CFG_PCFG_TSR_10M;
1069 break;
1070 default:
1071 printk("Unsupported speed %d\n", mac->phydev->speed);
1072 }
1073
1074 /* Print on link or speed/duplex change */
1075 msg = mac->link != mac->phydev->link || flags != new_flags;
1076
1077 mac->duplex = mac->phydev->duplex;
1078 mac->speed = mac->phydev->speed;
1079 mac->link = mac->phydev->link;
1080
1081 if (new_flags != flags)
Olof Johanssona85b9422007-09-15 13:40:59 -07001082 write_mac_reg(mac, PAS_MAC_CFG_PCFG, new_flags);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001083
1084 if (msg && netif_msg_link(mac))
1085 printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n",
1086 dev->name, mac->speed, mac->duplex ? "full" : "half");
1087}
1088
1089static int pasemi_mac_phy_init(struct net_device *dev)
1090{
1091 struct pasemi_mac *mac = netdev_priv(dev);
1092 struct device_node *dn, *phy_dn;
1093 struct phy_device *phydev;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001094
1095 dn = pci_device_to_OF_node(mac->pdev);
Grant Likely1dd2d062009-04-25 12:53:17 +00001096 phy_dn = of_parse_phandle(dn, "phy-handle", 0);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001097 of_node_put(phy_dn);
1098
1099 mac->link = 0;
1100 mac->speed = 0;
1101 mac->duplex = -1;
1102
Grant Likely1dd2d062009-04-25 12:53:17 +00001103 phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
1104 PHY_INTERFACE_MODE_SGMII);
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001105
Wei Yongjunbeb5ac22012-09-26 19:51:58 +00001106 if (!phydev) {
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001107 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
Wei Yongjunbeb5ac22012-09-26 19:51:58 +00001108 return -ENODEV;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001109 }
1110
1111 mac->phydev = phydev;
1112
1113 return 0;
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001114}
1115
1116
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001117static int pasemi_mac_open(struct net_device *dev)
1118{
1119 struct pasemi_mac *mac = netdev_priv(dev);
1120 unsigned int flags;
Olof Johanssone37c7722008-02-20 20:57:59 -06001121 int i, ret;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001122
1123 flags = PAS_MAC_CFG_TXP_FCE | PAS_MAC_CFG_TXP_FPC(3) |
1124 PAS_MAC_CFG_TXP_SL(3) | PAS_MAC_CFG_TXP_COB(0xf) |
1125 PAS_MAC_CFG_TXP_TIFT(8) | PAS_MAC_CFG_TXP_TIFG(12);
1126
Olof Johanssona85b9422007-09-15 13:40:59 -07001127 write_mac_reg(mac, PAS_MAC_CFG_TXP, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001128
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001129 ret = pasemi_mac_setup_rx_resources(dev);
1130 if (ret)
1131 goto out_rx_resources;
1132
Olof Johansson34c20622007-11-28 20:56:32 -06001133 mac->tx = pasemi_mac_setup_tx_resources(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -06001134
1135 if (!mac->tx)
1136 goto out_tx_ring;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001137
Olof Johansson1724ac22008-03-25 09:58:40 -05001138 /* We might already have allocated rings in case mtu was changed
1139 * before interface was brought up.
1140 */
1141 if (dev->mtu > 1500 && !mac->num_cs) {
Olof Johansson8d636d82008-03-05 16:34:16 -06001142 pasemi_mac_setup_csrings(mac);
1143 if (!mac->num_cs)
1144 goto out_tx_ring;
1145 }
1146
Olof Johanssone37c7722008-02-20 20:57:59 -06001147 /* Zero out rmon counters */
1148 for (i = 0; i < 32; i++)
1149 write_mac_reg(mac, PAS_MAC_RMON(i), 0);
1150
Olof Johansson906674a2007-11-28 20:57:09 -06001151 /* 0x3ff with 33MHz clock is about 31us */
1152 write_iob_reg(PAS_IOB_DMA_COM_TIMEOUTCFG,
1153 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0x3ff));
1154
Olof Johansson34c20622007-11-28 20:56:32 -06001155 write_iob_reg(PAS_IOB_DMA_RXCH_CFG(mac->rx->chan.chno),
Olof Johansson28ae79f2007-11-28 20:57:27 -06001156 PAS_IOB_DMA_RXCH_CFG_CNTTH(256));
Olof Johansson34c20622007-11-28 20:56:32 -06001157
1158 write_iob_reg(PAS_IOB_DMA_TXCH_CFG(mac->tx->chan.chno),
Olof Johansson61cec3b2007-11-28 20:56:54 -06001159 PAS_IOB_DMA_TXCH_CFG_CNTTH(32));
Olof Johansson34c20622007-11-28 20:56:32 -06001160
Olof Johanssona85b9422007-09-15 13:40:59 -07001161 write_mac_reg(mac, PAS_MAC_IPC_CHNL,
Olof Johansson34c20622007-11-28 20:56:32 -06001162 PAS_MAC_IPC_CHNL_DCHNO(mac->rx->chan.chno) |
1163 PAS_MAC_IPC_CHNL_BCH(mac->rx->chan.chno));
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001164
1165 /* enable rx if */
Olof Johansson34c20622007-11-28 20:56:32 -06001166 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1167 PAS_DMA_RXINT_RCMDSTA_EN |
1168 PAS_DMA_RXINT_RCMDSTA_DROPS_M |
1169 PAS_DMA_RXINT_RCMDSTA_BP |
1170 PAS_DMA_RXINT_RCMDSTA_OO |
1171 PAS_DMA_RXINT_RCMDSTA_BT);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001172
1173 /* enable rx channel */
Olof Johansson34c20622007-11-28 20:56:32 -06001174 pasemi_dma_start_chan(&rx_ring(mac)->chan, PAS_DMA_RXCHAN_CCMDSTA_DU |
1175 PAS_DMA_RXCHAN_CCMDSTA_OD |
1176 PAS_DMA_RXCHAN_CCMDSTA_FD |
1177 PAS_DMA_RXCHAN_CCMDSTA_DT);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001178
1179 /* enable tx channel */
Olof Johansson34c20622007-11-28 20:56:32 -06001180 pasemi_dma_start_chan(&tx_ring(mac)->chan, PAS_DMA_TXCHAN_TCMDSTA_SZ |
1181 PAS_DMA_TXCHAN_TCMDSTA_DB |
1182 PAS_DMA_TXCHAN_TCMDSTA_DE |
1183 PAS_DMA_TXCHAN_TCMDSTA_DA);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001184
Olof Johansson928773c2007-09-26 16:25:06 -05001185 pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001186
Olof Johansson34c20622007-11-28 20:56:32 -06001187 write_dma_reg(PAS_DMA_RXCHAN_INCR(rx_ring(mac)->chan.chno),
1188 RX_RING_SIZE>>1);
Olof Johanssonb5254ee2007-10-02 16:27:57 -05001189
Olof Johansson72b05b92007-11-28 20:54:28 -06001190 /* Clear out any residual packet count state from firmware */
1191 pasemi_mac_restart_rx_intr(mac);
1192 pasemi_mac_restart_tx_intr(mac);
1193
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001194 flags = PAS_MAC_CFG_PCFG_S1 | PAS_MAC_CFG_PCFG_PR | PAS_MAC_CFG_PCFG_CE;
Olof Johansson36033762007-09-26 16:24:42 -05001195
1196 if (mac->type == MAC_TYPE_GMAC)
1197 flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
1198 else
1199 flags |= PAS_MAC_CFG_PCFG_TSR_10G | PAS_MAC_CFG_PCFG_SPD_10G;
1200
1201 /* Enable interface in MAC */
1202 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
1203
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001204 ret = pasemi_mac_phy_init(dev);
Olof Johanssonb0cd2f92007-11-28 20:58:25 -06001205 if (ret) {
1206 /* Since we won't get link notification, just enable RX */
1207 pasemi_mac_intf_enable(mac);
1208 if (mac->type == MAC_TYPE_GMAC) {
1209 /* Warn for missing PHY on SGMII (1Gig) ports */
1210 dev_warn(&mac->pdev->dev,
1211 "PHY init failed: %d.\n", ret);
1212 dev_warn(&mac->pdev->dev,
1213 "Defaulting to 1Gbit full duplex\n");
1214 }
Olof Johansson8304b632007-11-28 20:58:06 -06001215 }
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001216
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001217 netif_start_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001218 napi_enable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001219
Olof Johansson72b05b92007-11-28 20:54:28 -06001220 snprintf(mac->tx_irq_name, sizeof(mac->tx_irq_name), "%s tx",
1221 dev->name);
Olof Johansson771f7402007-05-08 00:47:21 -05001222
Joe Perchesa0607fd2009-11-18 23:29:17 -08001223 ret = request_irq(mac->tx->chan.irq, pasemi_mac_tx_intr, IRQF_DISABLED,
Olof Johansson72b05b92007-11-28 20:54:28 -06001224 mac->tx_irq_name, mac->tx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001225 if (ret) {
1226 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
Olof Johansson34c20622007-11-28 20:56:32 -06001227 mac->tx->chan.irq, ret);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001228 goto out_tx_int;
1229 }
1230
Olof Johansson72b05b92007-11-28 20:54:28 -06001231 snprintf(mac->rx_irq_name, sizeof(mac->rx_irq_name), "%s rx",
1232 dev->name);
1233
Joe Perchesa0607fd2009-11-18 23:29:17 -08001234 ret = request_irq(mac->rx->chan.irq, pasemi_mac_rx_intr, IRQF_DISABLED,
Olof Johansson34c20622007-11-28 20:56:32 -06001235 mac->rx_irq_name, mac->rx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001236 if (ret) {
1237 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
Olof Johansson34c20622007-11-28 20:56:32 -06001238 mac->rx->chan.irq, ret);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001239 goto out_rx_int;
1240 }
1241
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001242 if (mac->phydev)
1243 phy_start(mac->phydev);
1244
Olof Johansson61cec3b2007-11-28 20:56:54 -06001245 init_timer(&mac->tx->clean_timer);
1246 mac->tx->clean_timer.function = pasemi_mac_tx_timer;
1247 mac->tx->clean_timer.data = (unsigned long)mac->tx;
1248 mac->tx->clean_timer.expires = jiffies+HZ;
1249 add_timer(&mac->tx->clean_timer);
1250
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001251 return 0;
1252
1253out_rx_int:
Olof Johansson34c20622007-11-28 20:56:32 -06001254 free_irq(mac->tx->chan.irq, mac->tx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001255out_tx_int:
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001256 napi_disable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001257 netif_stop_queue(dev);
Olof Johansson72b05b92007-11-28 20:54:28 -06001258out_tx_ring:
1259 if (mac->tx)
1260 pasemi_mac_free_tx_resources(mac);
1261 pasemi_mac_free_rx_resources(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001262out_rx_resources:
1263
1264 return ret;
1265}
1266
1267#define MAX_RETRIES 5000
1268
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001269static void pasemi_mac_pause_txchan(struct pasemi_mac *mac)
1270{
1271 unsigned int sta, retries;
1272 int txch = tx_ring(mac)->chan.chno;
1273
1274 write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch),
1275 PAS_DMA_TXCHAN_TCMDSTA_ST);
1276
1277 for (retries = 0; retries < MAX_RETRIES; retries++) {
1278 sta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch));
1279 if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT))
1280 break;
1281 cond_resched();
1282 }
1283
1284 if (sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)
1285 dev_err(&mac->dma_pdev->dev,
1286 "Failed to stop tx channel, tcmdsta %08x\n", sta);
1287
1288 write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch), 0);
1289}
1290
1291static void pasemi_mac_pause_rxchan(struct pasemi_mac *mac)
1292{
1293 unsigned int sta, retries;
1294 int rxch = rx_ring(mac)->chan.chno;
1295
1296 write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch),
1297 PAS_DMA_RXCHAN_CCMDSTA_ST);
1298 for (retries = 0; retries < MAX_RETRIES; retries++) {
1299 sta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch));
1300 if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT))
1301 break;
1302 cond_resched();
1303 }
1304
1305 if (sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)
1306 dev_err(&mac->dma_pdev->dev,
1307 "Failed to stop rx channel, ccmdsta 08%x\n", sta);
1308 write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch), 0);
1309}
1310
1311static void pasemi_mac_pause_rxint(struct pasemi_mac *mac)
1312{
1313 unsigned int sta, retries;
1314
1315 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1316 PAS_DMA_RXINT_RCMDSTA_ST);
1317 for (retries = 0; retries < MAX_RETRIES; retries++) {
1318 sta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
1319 if (!(sta & PAS_DMA_RXINT_RCMDSTA_ACT))
1320 break;
1321 cond_resched();
1322 }
1323
1324 if (sta & PAS_DMA_RXINT_RCMDSTA_ACT)
1325 dev_err(&mac->dma_pdev->dev,
1326 "Failed to stop rx interface, rcmdsta %08x\n", sta);
1327 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
1328}
1329
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001330static int pasemi_mac_close(struct net_device *dev)
1331{
1332 struct pasemi_mac *mac = netdev_priv(dev);
Olof Johansson9e81d332007-10-02 16:27:39 -05001333 unsigned int sta;
Olof Johansson8d636d82008-03-05 16:34:16 -06001334 int rxch, txch, i;
Olof Johansson34c20622007-11-28 20:56:32 -06001335
1336 rxch = rx_ring(mac)->chan.chno;
1337 txch = tx_ring(mac)->chan.chno;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001338
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001339 if (mac->phydev) {
1340 phy_stop(mac->phydev);
1341 phy_disconnect(mac->phydev);
1342 }
1343
Olof Johansson61cec3b2007-11-28 20:56:54 -06001344 del_timer_sync(&mac->tx->clean_timer);
1345
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001346 netif_stop_queue(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001347 napi_disable(&mac->napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001348
Olof Johansson34c20622007-11-28 20:56:32 -06001349 sta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
Olof Johansson9e81d332007-10-02 16:27:39 -05001350 if (sta & (PAS_DMA_RXINT_RCMDSTA_BP |
1351 PAS_DMA_RXINT_RCMDSTA_OO |
1352 PAS_DMA_RXINT_RCMDSTA_BT))
1353 printk(KERN_DEBUG "pasemi_mac: rcmdsta error: 0x%08x\n", sta);
1354
Olof Johansson34c20622007-11-28 20:56:32 -06001355 sta = read_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(rxch));
Olof Johansson9e81d332007-10-02 16:27:39 -05001356 if (sta & (PAS_DMA_RXCHAN_CCMDSTA_DU |
1357 PAS_DMA_RXCHAN_CCMDSTA_OD |
1358 PAS_DMA_RXCHAN_CCMDSTA_FD |
1359 PAS_DMA_RXCHAN_CCMDSTA_DT))
1360 printk(KERN_DEBUG "pasemi_mac: ccmdsta error: 0x%08x\n", sta);
1361
Olof Johansson34c20622007-11-28 20:56:32 -06001362 sta = read_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(txch));
Olof Johansson72b05b92007-11-28 20:54:28 -06001363 if (sta & (PAS_DMA_TXCHAN_TCMDSTA_SZ | PAS_DMA_TXCHAN_TCMDSTA_DB |
1364 PAS_DMA_TXCHAN_TCMDSTA_DE | PAS_DMA_TXCHAN_TCMDSTA_DA))
Olof Johansson9e81d332007-10-02 16:27:39 -05001365 printk(KERN_DEBUG "pasemi_mac: tcmdsta error: 0x%08x\n", sta);
1366
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001367 /* Clean out any pending buffers */
Olof Johansson72b05b92007-11-28 20:54:28 -06001368 pasemi_mac_clean_tx(tx_ring(mac));
1369 pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001370
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001371 pasemi_mac_pause_txchan(mac);
1372 pasemi_mac_pause_rxint(mac);
1373 pasemi_mac_pause_rxchan(mac);
Olof Johansson1145d952008-01-23 13:57:19 -06001374 pasemi_mac_intf_disable(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001375
Olof Johansson34c20622007-11-28 20:56:32 -06001376 free_irq(mac->tx->chan.irq, mac->tx);
1377 free_irq(mac->rx->chan.irq, mac->rx);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001378
Olof Johansson1724ac22008-03-25 09:58:40 -05001379 for (i = 0; i < mac->num_cs; i++) {
Olof Johansson8d636d82008-03-05 16:34:16 -06001380 pasemi_mac_free_csring(mac->cs[i]);
Olof Johansson1724ac22008-03-25 09:58:40 -05001381 mac->cs[i] = NULL;
1382 }
1383
1384 mac->num_cs = 0;
Olof Johansson8d636d82008-03-05 16:34:16 -06001385
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001386 /* Free resources */
Olof Johansson72b05b92007-11-28 20:54:28 -06001387 pasemi_mac_free_rx_resources(mac);
1388 pasemi_mac_free_tx_resources(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001389
1390 return 0;
1391}
1392
Olof Johansson8d636d82008-03-05 16:34:16 -06001393static void pasemi_mac_queue_csdesc(const struct sk_buff *skb,
1394 const dma_addr_t *map,
1395 const unsigned int *map_size,
1396 struct pasemi_mac_txring *txring,
1397 struct pasemi_mac_csring *csring)
1398{
1399 u64 fund;
1400 dma_addr_t cs_dest;
1401 const int nh_off = skb_network_offset(skb);
1402 const int nh_len = skb_network_header_len(skb);
1403 const int nfrags = skb_shinfo(skb)->nr_frags;
1404 int cs_size, i, fill, hdr, cpyhdr, evt;
1405 dma_addr_t csdma;
1406
1407 fund = XCT_FUN_ST | XCT_FUN_RR_8BRES |
1408 XCT_FUN_O | XCT_FUN_FUN(csring->fun) |
1409 XCT_FUN_CRM_SIG | XCT_FUN_LLEN(skb->len - nh_off) |
1410 XCT_FUN_SHL(nh_len >> 2) | XCT_FUN_SE;
1411
1412 switch (ip_hdr(skb)->protocol) {
1413 case IPPROTO_TCP:
1414 fund |= XCT_FUN_SIG_TCP4;
1415 /* TCP checksum is 16 bytes into the header */
1416 cs_dest = map[0] + skb_transport_offset(skb) + 16;
1417 break;
1418 case IPPROTO_UDP:
1419 fund |= XCT_FUN_SIG_UDP4;
1420 /* UDP checksum is 6 bytes into the header */
1421 cs_dest = map[0] + skb_transport_offset(skb) + 6;
1422 break;
1423 default:
1424 BUG();
1425 }
1426
1427 /* Do the checksum offloaded */
1428 fill = csring->next_to_fill;
1429 hdr = fill;
1430
1431 CS_DESC(csring, fill++) = fund;
1432 /* Room for 8BRES. Checksum result is really 2 bytes into it */
1433 csdma = csring->chan.ring_dma + (fill & (CS_RING_SIZE-1)) * 8 + 2;
1434 CS_DESC(csring, fill++) = 0;
1435
1436 CS_DESC(csring, fill) = XCT_PTR_LEN(map_size[0]-nh_off) | XCT_PTR_ADDR(map[0]+nh_off);
1437 for (i = 1; i <= nfrags; i++)
1438 CS_DESC(csring, fill+i) = XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]);
1439
1440 fill += i;
1441 if (fill & 1)
1442 fill++;
1443
1444 /* Copy the result into the TCP packet */
1445 cpyhdr = fill;
1446 CS_DESC(csring, fill++) = XCT_FUN_O | XCT_FUN_FUN(csring->fun) |
1447 XCT_FUN_LLEN(2) | XCT_FUN_SE;
1448 CS_DESC(csring, fill++) = XCT_PTR_LEN(2) | XCT_PTR_ADDR(cs_dest) | XCT_PTR_T;
1449 CS_DESC(csring, fill++) = XCT_PTR_LEN(2) | XCT_PTR_ADDR(csdma);
1450 fill++;
1451
1452 evt = !csring->last_event;
1453 csring->last_event = evt;
1454
1455 /* Event handshaking with MAC TX */
1456 CS_DESC(csring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1457 CTRL_CMD_ETYPE_SET | CTRL_CMD_REG(csring->events[evt]);
1458 CS_DESC(csring, fill++) = 0;
1459 CS_DESC(csring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1460 CTRL_CMD_ETYPE_WCLR | CTRL_CMD_REG(csring->events[!evt]);
1461 CS_DESC(csring, fill++) = 0;
1462 csring->next_to_fill = fill & (CS_RING_SIZE-1);
1463
1464 cs_size = fill - hdr;
1465 write_dma_reg(PAS_DMA_TXCHAN_INCR(csring->chan.chno), (cs_size) >> 1);
1466
1467 /* TX-side event handshaking */
1468 fill = txring->next_to_fill;
1469 TX_DESC(txring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1470 CTRL_CMD_ETYPE_WSET | CTRL_CMD_REG(csring->events[evt]);
1471 TX_DESC(txring, fill++) = 0;
1472 TX_DESC(txring, fill++) = CTRL_CMD_T | CTRL_CMD_META_EVT | CTRL_CMD_O |
1473 CTRL_CMD_ETYPE_CLR | CTRL_CMD_REG(csring->events[!evt]);
1474 TX_DESC(txring, fill++) = 0;
1475 txring->next_to_fill = fill;
1476
1477 write_dma_reg(PAS_DMA_TXCHAN_INCR(txring->chan.chno), 2);
Olof Johansson8d636d82008-03-05 16:34:16 -06001478}
1479
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001480static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
1481{
Olof Johansson8d636d82008-03-05 16:34:16 -06001482 struct pasemi_mac * const mac = netdev_priv(dev);
1483 struct pasemi_mac_txring * const txring = tx_ring(mac);
1484 struct pasemi_mac_csring *csring;
1485 u64 dflags = 0;
1486 u64 mactx;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001487 dma_addr_t map[MAX_SKB_FRAGS+1];
1488 unsigned int map_size[MAX_SKB_FRAGS+1];
Olof Johanssonca7e2352007-09-26 16:23:59 -05001489 unsigned long flags;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001490 int i, nfrags;
Olof Johansson5c153322007-11-28 20:56:41 -06001491 int fill;
Olof Johansson8d636d82008-03-05 16:34:16 -06001492 const int nh_off = skb_network_offset(skb);
1493 const int nh_len = skb_network_header_len(skb);
1494
1495 prefetch(&txring->ring_info);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001496
Olof Johanssondbd62af2007-11-06 22:20:39 -06001497 dflags = XCT_MACTX_O | XCT_MACTX_ST | XCT_MACTX_CRC_PAD;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001498
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001499 nfrags = skb_shinfo(skb)->nr_frags;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001500
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001501 map[0] = pci_map_single(mac->dma_pdev, skb->data, skb_headlen(skb),
1502 PCI_DMA_TODEVICE);
1503 map_size[0] = skb_headlen(skb);
FUJITA Tomonori8d8bb392008-07-25 19:44:49 -07001504 if (pci_dma_mapping_error(mac->dma_pdev, map[0]))
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001505 goto out_err_nolock;
1506
1507 for (i = 0; i < nfrags; i++) {
1508 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1509
Ian Campbell4bb97ca2011-08-31 00:47:01 +00001510 map[i + 1] = skb_frag_dma_map(&mac->dma_pdev->dev, frag, 0,
Eric Dumazet9e903e02011-10-18 21:00:24 +00001511 skb_frag_size(frag), DMA_TO_DEVICE);
1512 map_size[i+1] = skb_frag_size(frag);
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01001513 if (dma_mapping_error(&mac->dma_pdev->dev, map[i + 1])) {
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001514 nfrags = i;
1515 goto out_err_nolock;
1516 }
1517 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001518
Olof Johansson8d636d82008-03-05 16:34:16 -06001519 if (skb->ip_summed == CHECKSUM_PARTIAL && skb->len <= 1540) {
1520 switch (ip_hdr(skb)->protocol) {
1521 case IPPROTO_TCP:
1522 dflags |= XCT_MACTX_CSUM_TCP;
1523 dflags |= XCT_MACTX_IPH(nh_len >> 2);
1524 dflags |= XCT_MACTX_IPO(nh_off);
1525 break;
1526 case IPPROTO_UDP:
1527 dflags |= XCT_MACTX_CSUM_UDP;
1528 dflags |= XCT_MACTX_IPH(nh_len >> 2);
1529 dflags |= XCT_MACTX_IPO(nh_off);
1530 break;
1531 default:
1532 WARN_ON(1);
1533 }
1534 }
1535
Olof Johansson26fcfa92007-08-22 09:12:59 -05001536 mactx = dflags | XCT_MACTX_LLEN(skb->len);
Olof Johansson26fcfa92007-08-22 09:12:59 -05001537
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001538 spin_lock_irqsave(&txring->lock, flags);
1539
Olof Johanssonad5da102007-10-02 16:27:15 -05001540 /* Avoid stepping on the same cache line that the DMA controller
1541 * is currently about to send, so leave at least 8 words available.
1542 * Total free space needed is mactx + fragments + 8
1543 */
Olof Johansson8d636d82008-03-05 16:34:16 -06001544 if (RING_AVAIL(txring) < nfrags + 14) {
Olof Johanssonad5da102007-10-02 16:27:15 -05001545 /* no room -- stop the queue and wait for tx intr */
1546 netif_stop_queue(dev);
1547 goto out_err;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001548 }
1549
Olof Johansson8d636d82008-03-05 16:34:16 -06001550 /* Queue up checksum + event descriptors, if needed */
1551 if (mac->num_cs && skb->ip_summed == CHECKSUM_PARTIAL && skb->len > 1540) {
1552 csring = mac->cs[mac->last_cs];
1553 mac->last_cs = (mac->last_cs + 1) % mac->num_cs;
1554
1555 pasemi_mac_queue_csdesc(skb, map, map_size, txring, csring);
1556 }
1557
1558 fill = txring->next_to_fill;
Olof Johansson5c153322007-11-28 20:56:41 -06001559 TX_DESC(txring, fill) = mactx;
Olof Johansson7e9916e2007-11-28 20:57:45 -06001560 TX_DESC_INFO(txring, fill).dma = nfrags;
Olof Johansson5c153322007-11-28 20:56:41 -06001561 fill++;
1562 TX_DESC_INFO(txring, fill).skb = skb;
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001563 for (i = 0; i <= nfrags; i++) {
Olof Johansson5c153322007-11-28 20:56:41 -06001564 TX_DESC(txring, fill+i) =
Olof Johansson72b05b92007-11-28 20:54:28 -06001565 XCT_PTR_LEN(map_size[i]) | XCT_PTR_ADDR(map[i]);
Olof Johansson5c153322007-11-28 20:56:41 -06001566 TX_DESC_INFO(txring, fill+i).dma = map[i];
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001567 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001568
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001569 /* We have to add an even number of 8-byte entries to the ring
1570 * even if the last one is unused. That means always an odd number
1571 * of pointers + one mactx descriptor.
1572 */
1573 if (nfrags & 1)
1574 nfrags++;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001575
Olof Johansson5c153322007-11-28 20:56:41 -06001576 txring->next_to_fill = (fill + nfrags + 1) & (TX_RING_SIZE-1);
Olof Johanssonfc9e4d22007-10-02 16:25:53 -05001577
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001578 dev->stats.tx_packets++;
1579 dev->stats.tx_bytes += skb->len;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001580
1581 spin_unlock_irqrestore(&txring->lock, flags);
1582
Olof Johansson34c20622007-11-28 20:56:32 -06001583 write_dma_reg(PAS_DMA_TXCHAN_INCR(txring->chan.chno), (nfrags+2) >> 1);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001584
1585 return NETDEV_TX_OK;
1586
1587out_err:
1588 spin_unlock_irqrestore(&txring->lock, flags);
Olof Johanssonad3c20d2007-10-02 16:26:13 -05001589out_err_nolock:
1590 while (nfrags--)
1591 pci_unmap_single(mac->dma_pdev, map[nfrags], map_size[nfrags],
1592 PCI_DMA_TODEVICE);
1593
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001594 return NETDEV_TX_BUSY;
1595}
1596
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001597static void pasemi_mac_set_rx_mode(struct net_device *dev)
1598{
Olof Johansson5c153322007-11-28 20:56:41 -06001599 const struct pasemi_mac *mac = netdev_priv(dev);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001600 unsigned int flags;
1601
Olof Johanssona85b9422007-09-15 13:40:59 -07001602 flags = read_mac_reg(mac, PAS_MAC_CFG_PCFG);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001603
1604 /* Set promiscuous */
1605 if (dev->flags & IFF_PROMISC)
1606 flags |= PAS_MAC_CFG_PCFG_PR;
1607 else
1608 flags &= ~PAS_MAC_CFG_PCFG_PR;
1609
Olof Johanssona85b9422007-09-15 13:40:59 -07001610 write_mac_reg(mac, PAS_MAC_CFG_PCFG, flags);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001611}
1612
1613
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001614static int pasemi_mac_poll(struct napi_struct *napi, int budget)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001615{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001616 struct pasemi_mac *mac = container_of(napi, struct pasemi_mac, napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001617 int pkts;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001618
Olof Johansson72b05b92007-11-28 20:54:28 -06001619 pasemi_mac_clean_tx(tx_ring(mac));
1620 pkts = pasemi_mac_clean_rx(rx_ring(mac), budget);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001621 if (pkts < budget) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001622 /* all done, no more packets present */
Ben Hutchings288379f2009-01-19 16:43:59 -08001623 napi_complete(napi);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001624
Olof Johansson1b0335ea2007-05-08 00:47:26 -05001625 pasemi_mac_restart_rx_intr(mac);
Olof Johansson61cec3b2007-11-28 20:56:54 -06001626 pasemi_mac_restart_tx_intr(mac);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001627 }
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001628 return pkts;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001629}
1630
Nate Case6e620402008-03-21 17:02:42 -05001631#ifdef CONFIG_NET_POLL_CONTROLLER
1632/*
1633 * Polling 'interrupt' - used by things like netconsole to send skbs
1634 * without having to re-enable interrupts. It's not called while
1635 * the interrupt routine is executing.
1636 */
1637static void pasemi_mac_netpoll(struct net_device *dev)
1638{
1639 const struct pasemi_mac *mac = netdev_priv(dev);
1640
1641 disable_irq(mac->tx->chan.irq);
1642 pasemi_mac_tx_intr(mac->tx->chan.irq, mac->tx);
1643 enable_irq(mac->tx->chan.irq);
1644
1645 disable_irq(mac->rx->chan.irq);
1646 pasemi_mac_rx_intr(mac->rx->chan.irq, mac->rx);
1647 enable_irq(mac->rx->chan.irq);
1648}
1649#endif
1650
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001651static int pasemi_mac_change_mtu(struct net_device *dev, int new_mtu)
1652{
1653 struct pasemi_mac *mac = netdev_priv(dev);
1654 unsigned int reg;
Olof Johansson8d636d82008-03-05 16:34:16 -06001655 unsigned int rcmdsta = 0;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001656 int running;
Olof Johansson8d636d82008-03-05 16:34:16 -06001657 int ret = 0;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001658
1659 if (new_mtu < PE_MIN_MTU || new_mtu > PE_MAX_MTU)
1660 return -EINVAL;
1661
1662 running = netif_running(dev);
1663
1664 if (running) {
1665 /* Need to stop the interface, clean out all already
1666 * received buffers, free all unused buffers on the RX
1667 * interface ring, then finally re-fill the rx ring with
1668 * the new-size buffers and restart.
1669 */
1670
1671 napi_disable(&mac->napi);
1672 netif_tx_disable(dev);
1673 pasemi_mac_intf_disable(mac);
1674
1675 rcmdsta = read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if));
1676 pasemi_mac_pause_rxint(mac);
1677 pasemi_mac_clean_rx(rx_ring(mac), RX_RING_SIZE);
1678 pasemi_mac_free_rx_buffers(mac);
Olof Johansson8d636d82008-03-05 16:34:16 -06001679
1680 }
1681
1682 /* Setup checksum channels if large MTU and none already allocated */
1683 if (new_mtu > 1500 && !mac->num_cs) {
1684 pasemi_mac_setup_csrings(mac);
1685 if (!mac->num_cs) {
1686 ret = -ENOMEM;
1687 goto out;
1688 }
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001689 }
1690
1691 /* Change maxf, i.e. what size frames are accepted.
1692 * Need room for ethernet header and CRC word
1693 */
1694 reg = read_mac_reg(mac, PAS_MAC_CFG_MACCFG);
1695 reg &= ~PAS_MAC_CFG_MACCFG_MAXF_M;
1696 reg |= PAS_MAC_CFG_MACCFG_MAXF(new_mtu + ETH_HLEN + 4);
1697 write_mac_reg(mac, PAS_MAC_CFG_MACCFG, reg);
1698
1699 dev->mtu = new_mtu;
1700 /* MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
1701 mac->bufsz = new_mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
1702
Olof Johansson8d636d82008-03-05 16:34:16 -06001703out:
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001704 if (running) {
1705 write_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
1706 rcmdsta | PAS_DMA_RXINT_RCMDSTA_EN);
1707
1708 rx_ring(mac)->next_to_fill = 0;
1709 pasemi_mac_replenish_rx_ring(dev, RX_RING_SIZE-1);
1710
1711 napi_enable(&mac->napi);
1712 netif_start_queue(dev);
1713 pasemi_mac_intf_enable(mac);
1714 }
1715
Olof Johansson8d636d82008-03-05 16:34:16 -06001716 return ret;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001717}
1718
Alexander Beregalov9e0ac842009-04-15 12:52:54 +00001719static const struct net_device_ops pasemi_netdev_ops = {
1720 .ndo_open = pasemi_mac_open,
1721 .ndo_stop = pasemi_mac_close,
1722 .ndo_start_xmit = pasemi_mac_start_tx,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00001723 .ndo_set_rx_mode = pasemi_mac_set_rx_mode,
Alexander Beregalov9e0ac842009-04-15 12:52:54 +00001724 .ndo_set_mac_address = pasemi_mac_set_mac_addr,
1725 .ndo_change_mtu = pasemi_mac_change_mtu,
1726 .ndo_validate_addr = eth_validate_addr,
1727#ifdef CONFIG_NET_POLL_CONTROLLER
1728 .ndo_poll_controller = pasemi_mac_netpoll,
1729#endif
1730};
1731
Bill Pemberton03c4d832012-12-03 09:24:00 -05001732static int
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001733pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1734{
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001735 struct net_device *dev;
1736 struct pasemi_mac *mac;
roel kluin15b8e192009-04-23 08:53:20 +00001737 int err, ret;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001738
1739 err = pci_enable_device(pdev);
1740 if (err)
1741 return err;
1742
1743 dev = alloc_etherdev(sizeof(struct pasemi_mac));
1744 if (dev == NULL) {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001745 err = -ENOMEM;
1746 goto out_disable_device;
1747 }
1748
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001749 pci_set_drvdata(pdev, dev);
1750 SET_NETDEV_DEV(dev, &pdev->dev);
1751
1752 mac = netdev_priv(dev);
1753
1754 mac->pdev = pdev;
1755 mac->netdev = dev;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001756
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001757 netif_napi_add(dev, &mac->napi, pasemi_mac_poll, 64);
1758
Olof Johansson5c153322007-11-28 20:56:41 -06001759 dev->features = NETIF_F_IP_CSUM | NETIF_F_LLTX | NETIF_F_SG |
Olof Johansson25156782008-02-20 20:57:58 -06001760 NETIF_F_HIGHDMA | NETIF_F_GSO;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001761
Olof Johansson28ae79f2007-11-28 20:57:27 -06001762 mac->lro_mgr.max_aggr = LRO_MAX_AGGR;
1763 mac->lro_mgr.max_desc = MAX_LRO_DESCRIPTORS;
1764 mac->lro_mgr.lro_arr = mac->lro_desc;
1765 mac->lro_mgr.get_skb_header = get_skb_hdr;
1766 mac->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
1767 mac->lro_mgr.dev = mac->netdev;
1768 mac->lro_mgr.ip_summed = CHECKSUM_UNNECESSARY;
1769 mac->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
1770
1771
Olof Johansson34c20622007-11-28 20:56:32 -06001772 mac->dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
1773 if (!mac->dma_pdev) {
1774 dev_err(&mac->pdev->dev, "Can't find DMA Controller\n");
1775 err = -ENODEV;
1776 goto out;
1777 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001778
Olof Johansson34c20622007-11-28 20:56:32 -06001779 mac->iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
1780 if (!mac->iob_pdev) {
1781 dev_err(&mac->pdev->dev, "Can't find I/O Bridge\n");
1782 err = -ENODEV;
1783 goto out;
1784 }
1785
1786 /* get mac addr from device tree */
1787 if (pasemi_get_mac_addr(mac) || !is_valid_ether_addr(mac->mac_addr)) {
1788 err = -ENODEV;
1789 goto out;
1790 }
1791 memcpy(dev->dev_addr, mac->mac_addr, sizeof(mac->mac_addr));
1792
roel kluin15b8e192009-04-23 08:53:20 +00001793 ret = mac_to_intf(mac);
1794 if (ret < 0) {
Olof Johansson34c20622007-11-28 20:56:32 -06001795 dev_err(&mac->pdev->dev, "Can't map DMA interface\n");
1796 err = -ENODEV;
1797 goto out;
1798 }
roel kluin15b8e192009-04-23 08:53:20 +00001799 mac->dma_if = ret;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001800
1801 switch (pdev->device) {
1802 case 0xa005:
1803 mac->type = MAC_TYPE_GMAC;
1804 break;
1805 case 0xa006:
1806 mac->type = MAC_TYPE_XAUI;
1807 break;
1808 default:
1809 err = -ENODEV;
1810 goto out;
1811 }
1812
Alexander Beregalov9e0ac842009-04-15 12:52:54 +00001813 dev->netdev_ops = &pasemi_netdev_ops;
Olof Johanssonef1ea0b2008-01-23 13:56:47 -06001814 dev->mtu = PE_DEF_MTU;
1815 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
1816 mac->bufsz = dev->mtu + ETH_HLEN + ETH_FCS_LEN + LOCAL_SKB_ALIGN + 128;
1817
Olof Johanssone37c7722008-02-20 20:57:59 -06001818 dev->ethtool_ops = &pasemi_mac_ethtool_ops;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001819
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001820 if (err)
1821 goto out;
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001822
Olof Johanssonceb51362007-05-08 00:47:49 -05001823 mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
1824
Olof Johanssonbb6e9592007-05-08 00:47:54 -05001825 /* Enable most messages by default */
1826 mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
1827
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001828 err = register_netdev(dev);
1829
1830 if (err) {
1831 dev_err(&mac->pdev->dev, "register_netdev failed with error %d\n",
1832 err);
1833 goto out;
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +00001834 } else if (netif_msg_probe(mac)) {
Johannes Berge1749612008-10-27 15:59:26 -07001835 printk(KERN_INFO "%s: PA Semi %s: intf %d, hw addr %pM\n",
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001836 dev->name, mac->type == MAC_TYPE_GMAC ? "GMAC" : "XAUI",
Johannes Berge1749612008-10-27 15:59:26 -07001837 mac->dma_if, dev->dev_addr);
Syam Sidhardhanea5cdcc2013-02-24 13:01:19 +00001838 }
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001839
1840 return err;
1841
1842out:
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001843 if (mac->iob_pdev)
1844 pci_dev_put(mac->iob_pdev);
1845 if (mac->dma_pdev)
1846 pci_dev_put(mac->dma_pdev);
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001847
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001848 free_netdev(dev);
1849out_disable_device:
1850 pci_disable_device(pdev);
1851 return err;
1852
1853}
1854
Bill Pemberton03c4d832012-12-03 09:24:00 -05001855static void pasemi_mac_remove(struct pci_dev *pdev)
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001856{
1857 struct net_device *netdev = pci_get_drvdata(pdev);
1858 struct pasemi_mac *mac;
1859
1860 if (!netdev)
1861 return;
1862
1863 mac = netdev_priv(netdev);
1864
1865 unregister_netdev(netdev);
1866
1867 pci_disable_device(pdev);
1868 pci_dev_put(mac->dma_pdev);
1869 pci_dev_put(mac->iob_pdev);
1870
Olof Johansson34c20622007-11-28 20:56:32 -06001871 pasemi_dma_free_chan(&mac->tx->chan);
1872 pasemi_dma_free_chan(&mac->rx->chan);
Olof Johanssonb6e05a12007-09-15 13:44:07 -07001873
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001874 pci_set_drvdata(pdev, NULL);
1875 free_netdev(netdev);
1876}
1877
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00001878static DEFINE_PCI_DEVICE_TABLE(pasemi_mac_pci_tbl) = {
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001879 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
1880 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
olof@lixom.netfd178252007-05-12 14:57:36 -05001881 { },
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001882};
1883
1884MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
1885
1886static struct pci_driver pasemi_mac_driver = {
1887 .name = "pasemi_mac",
1888 .id_table = pasemi_mac_pci_tbl,
1889 .probe = pasemi_mac_probe,
Bill Pemberton03c4d832012-12-03 09:24:00 -05001890 .remove = pasemi_mac_remove,
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001891};
1892
1893static void __exit pasemi_mac_cleanup_module(void)
1894{
1895 pci_unregister_driver(&pasemi_mac_driver);
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001896}
1897
1898int pasemi_mac_init_module(void)
1899{
Olof Johansson34c20622007-11-28 20:56:32 -06001900 int err;
1901
1902 err = pasemi_dma_init();
1903 if (err)
1904 return err;
1905
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001906 return pci_register_driver(&pasemi_mac_driver);
1907}
1908
Olof Johanssonf5cd7872007-01-31 21:43:54 -06001909module_init(pasemi_mac_init_module);
1910module_exit(pasemi_mac_cleanup_module);