30f32f95149a370f4c6e12fce2d0a2fdf67d32a9
[openwrt/staging/wigyori.git] / target / linux / brcm47xx / patches-3.8 / 750-bgmac.patch
1 From dd4544f05469aaaeee891d7dc54d66430344321e Mon Sep 17 00:00:00 2001
2 From: =?utf8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Tue, 8 Jan 2013 20:06:23 +0000
4 Subject: [PATCH] bgmac: driver for GBit MAC core on BCMA bus
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=utf8
7 Content-Transfer-Encoding: 8bit
8
9 BCMA is a Broadcom specific bus with devices AKA cores. All recent BCMA
10 based SoCs have gigabit ethernet provided by the GBit MAC core. This
11 patch adds driver for such a cores registering itself as a netdev. It
12 has been tested on a BCM4706 and BCM4718 chipsets.
13
14 In the kernel tree there is already b44 driver which has some common
15 things with bgmac, however there are many differences that has led to
16 the decision or writing a new driver:
17 1) GBit MAC cores appear on BCMA bus (not SSB as in case of b44)
18 2) There is 64bit DMA engine which differs from 32bit one
19 3) There is no CAM (Content Addressable Memory) in GBit MAC
20 4) We have 4 TX queues on GBit MAC devices (instead of 1)
21 5) Many registers have different addresses/values
22 6) RX header flags are also different
23
24 The driver in it's state is functional how, however there is of course
25 place for improvements:
26 1) Supporting more net_device_ops
27 2) SUpporting more ethtool_ops
28 3) Unaligned addressing in DMA
29 4) Writing separated PHY driver
30
31 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
32 Signed-off-by: David S. Miller <davem@davemloft.net>
33 ---
34 drivers/bcma/driver_chipcommon_pmu.c | 3 +-
35 drivers/net/ethernet/broadcom/Kconfig | 9 +
36 drivers/net/ethernet/broadcom/Makefile | 1 +
37 drivers/net/ethernet/broadcom/bgmac.c | 1422 +++++++++++++++++++++++++++
38 drivers/net/ethernet/broadcom/bgmac.h | 456 +++++++++
39 include/linux/bcma/bcma_driver_chipcommon.h | 2 +
40 6 files changed, 1892 insertions(+), 1 deletions(-)
41 create mode 100644 drivers/net/ethernet/broadcom/bgmac.c
42 create mode 100644 drivers/net/ethernet/broadcom/bgmac.h
43
44 --- a/drivers/net/ethernet/broadcom/Kconfig
45 +++ b/drivers/net/ethernet/broadcom/Kconfig
46 @@ -121,4 +121,13 @@ config BNX2X
47 To compile this driver as a module, choose M here: the module
48 will be called bnx2x. This is recommended.
49
50 +config BGMAC
51 + tristate "BCMA bus GBit core support"
52 + depends on BCMA_HOST_SOC && HAS_DMA
53 + ---help---
54 + This driver supports GBit MAC and BCM4706 GBit MAC cores on BCMA bus.
55 + They can be found on BCM47xx SoCs and provide gigabit ethernet.
56 + In case of using this driver on BCM4706 it's also requires to enable
57 + BCMA_DRIVER_GMAC_CMN to make it work.
58 +
59 endif # NET_VENDOR_BROADCOM
60 --- a/drivers/net/ethernet/broadcom/Makefile
61 +++ b/drivers/net/ethernet/broadcom/Makefile
62 @@ -9,3 +9,4 @@ obj-$(CONFIG_CNIC) += cnic.o
63 obj-$(CONFIG_BNX2X) += bnx2x/
64 obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o
65 obj-$(CONFIG_TIGON3) += tg3.o
66 +obj-$(CONFIG_BGMAC) += bgmac.o
67 --- /dev/null
68 +++ b/drivers/net/ethernet/broadcom/bgmac.c
69 @@ -0,0 +1,1422 @@
70 +/*
71 + * Driver for (BCM4706)? GBit MAC core on BCMA bus.
72 + *
73 + * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com>
74 + *
75 + * Licensed under the GNU/GPL. See COPYING for details.
76 + */
77 +
78 +#include "bgmac.h"
79 +
80 +#include <linux/kernel.h>
81 +#include <linux/module.h>
82 +#include <linux/delay.h>
83 +#include <linux/etherdevice.h>
84 +#include <linux/mii.h>
85 +#include <linux/interrupt.h>
86 +#include <linux/dma-mapping.h>
87 +#include <bcm47xx_nvram.h>
88 +
89 +static const struct bcma_device_id bgmac_bcma_tbl[] = {
90 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
91 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
92 + BCMA_CORETABLE_END
93 +};
94 +MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl);
95 +
96 +static bool bgmac_wait_value(struct bcma_device *core, u16 reg, u32 mask,
97 + u32 value, int timeout)
98 +{
99 + u32 val;
100 + int i;
101 +
102 + for (i = 0; i < timeout / 10; i++) {
103 + val = bcma_read32(core, reg);
104 + if ((val & mask) == value)
105 + return true;
106 + udelay(10);
107 + }
108 + pr_err("Timeout waiting for reg 0x%X\n", reg);
109 + return false;
110 +}
111 +
112 +/**************************************************
113 + * DMA
114 + **************************************************/
115 +
116 +static void bgmac_dma_tx_reset(struct bgmac *bgmac, struct bgmac_dma_ring *ring)
117 +{
118 + u32 val;
119 + int i;
120 +
121 + if (!ring->mmio_base)
122 + return;
123 +
124 + /* Suspend DMA TX ring first.
125 + * bgmac_wait_value doesn't support waiting for any of few values, so
126 + * implement whole loop here.
127 + */
128 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL,
129 + BGMAC_DMA_TX_SUSPEND);
130 + for (i = 0; i < 10000 / 10; i++) {
131 + val = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_TX_STATUS);
132 + val &= BGMAC_DMA_TX_STAT;
133 + if (val == BGMAC_DMA_TX_STAT_DISABLED ||
134 + val == BGMAC_DMA_TX_STAT_IDLEWAIT ||
135 + val == BGMAC_DMA_TX_STAT_STOPPED) {
136 + i = 0;
137 + break;
138 + }
139 + udelay(10);
140 + }
141 + if (i)
142 + bgmac_err(bgmac, "Timeout suspending DMA TX ring 0x%X (BGMAC_DMA_TX_STAT: 0x%08X)\n",
143 + ring->mmio_base, val);
144 +
145 + /* Remove SUSPEND bit */
146 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL, 0);
147 + if (!bgmac_wait_value(bgmac->core,
148 + ring->mmio_base + BGMAC_DMA_TX_STATUS,
149 + BGMAC_DMA_TX_STAT, BGMAC_DMA_TX_STAT_DISABLED,
150 + 10000)) {
151 + bgmac_warn(bgmac, "DMA TX ring 0x%X wasn't disabled on time, waiting additional 300us\n",
152 + ring->mmio_base);
153 + udelay(300);
154 + val = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_TX_STATUS);
155 + if ((val & BGMAC_DMA_TX_STAT) != BGMAC_DMA_TX_STAT_DISABLED)
156 + bgmac_err(bgmac, "Reset of DMA TX ring 0x%X failed\n",
157 + ring->mmio_base);
158 + }
159 +}
160 +
161 +static void bgmac_dma_tx_enable(struct bgmac *bgmac,
162 + struct bgmac_dma_ring *ring)
163 +{
164 + u32 ctl;
165 +
166 + ctl = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL);
167 + ctl |= BGMAC_DMA_TX_ENABLE;
168 + ctl |= BGMAC_DMA_TX_PARITY_DISABLE;
169 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL, ctl);
170 +}
171 +
172 +static netdev_tx_t bgmac_dma_tx_add(struct bgmac *bgmac,
173 + struct bgmac_dma_ring *ring,
174 + struct sk_buff *skb)
175 +{
176 + struct device *dma_dev = bgmac->core->dma_dev;
177 + struct net_device *net_dev = bgmac->net_dev;
178 + struct bgmac_dma_desc *dma_desc;
179 + struct bgmac_slot_info *slot;
180 + u32 ctl0, ctl1;
181 + int free_slots;
182 +
183 + if (skb->len > BGMAC_DESC_CTL1_LEN) {
184 + bgmac_err(bgmac, "Too long skb (%d)\n", skb->len);
185 + goto err_stop_drop;
186 + }
187 +
188 + if (ring->start <= ring->end)
189 + free_slots = ring->start - ring->end + BGMAC_TX_RING_SLOTS;
190 + else
191 + free_slots = ring->start - ring->end;
192 + if (free_slots == 1) {
193 + bgmac_err(bgmac, "TX ring is full, queue should be stopped!\n");
194 + netif_stop_queue(net_dev);
195 + return NETDEV_TX_BUSY;
196 + }
197 +
198 + slot = &ring->slots[ring->end];
199 + slot->skb = skb;
200 + slot->dma_addr = dma_map_single(dma_dev, skb->data, skb->len,
201 + DMA_TO_DEVICE);
202 + if (dma_mapping_error(dma_dev, slot->dma_addr)) {
203 + bgmac_err(bgmac, "Mapping error of skb on ring 0x%X\n",
204 + ring->mmio_base);
205 + goto err_stop_drop;
206 + }
207 +
208 + ctl0 = BGMAC_DESC_CTL0_IOC | BGMAC_DESC_CTL0_SOF | BGMAC_DESC_CTL0_EOF;
209 + if (ring->end == ring->num_slots - 1)
210 + ctl0 |= BGMAC_DESC_CTL0_EOT;
211 + ctl1 = skb->len & BGMAC_DESC_CTL1_LEN;
212 +
213 + dma_desc = ring->cpu_base;
214 + dma_desc += ring->end;
215 + dma_desc->addr_low = cpu_to_le32(lower_32_bits(slot->dma_addr));
216 + dma_desc->addr_high = cpu_to_le32(upper_32_bits(slot->dma_addr));
217 + dma_desc->ctl0 = cpu_to_le32(ctl0);
218 + dma_desc->ctl1 = cpu_to_le32(ctl1);
219 +
220 + wmb();
221 +
222 + /* Increase ring->end to point empty slot. We tell hardware the first
223 + * slot it should *not* read.
224 + */
225 + if (++ring->end >= BGMAC_TX_RING_SLOTS)
226 + ring->end = 0;
227 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_INDEX,
228 + ring->end * sizeof(struct bgmac_dma_desc));
229 +
230 + /* Always keep one slot free to allow detecting bugged calls. */
231 + if (--free_slots == 1)
232 + netif_stop_queue(net_dev);
233 +
234 + return NETDEV_TX_OK;
235 +
236 +err_stop_drop:
237 + netif_stop_queue(net_dev);
238 + dev_kfree_skb(skb);
239 + return NETDEV_TX_OK;
240 +}
241 +
242 +/* Free transmitted packets */
243 +static void bgmac_dma_tx_free(struct bgmac *bgmac, struct bgmac_dma_ring *ring)
244 +{
245 + struct device *dma_dev = bgmac->core->dma_dev;
246 + int empty_slot;
247 + bool freed = false;
248 +
249 + /* The last slot that hardware didn't consume yet */
250 + empty_slot = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_TX_STATUS);
251 + empty_slot &= BGMAC_DMA_TX_STATDPTR;
252 + empty_slot /= sizeof(struct bgmac_dma_desc);
253 +
254 + while (ring->start != empty_slot) {
255 + struct bgmac_slot_info *slot = &ring->slots[ring->start];
256 +
257 + if (slot->skb) {
258 + /* Unmap no longer used buffer */
259 + dma_unmap_single(dma_dev, slot->dma_addr,
260 + slot->skb->len, DMA_TO_DEVICE);
261 + slot->dma_addr = 0;
262 +
263 + /* Free memory! :) */
264 + dev_kfree_skb(slot->skb);
265 + slot->skb = NULL;
266 + } else {
267 + bgmac_err(bgmac, "Hardware reported transmission for empty TX ring slot %d! End of ring: %d\n",
268 + ring->start, ring->end);
269 + }
270 +
271 + if (++ring->start >= BGMAC_TX_RING_SLOTS)
272 + ring->start = 0;
273 + freed = true;
274 + }
275 +
276 + if (freed && netif_queue_stopped(bgmac->net_dev))
277 + netif_wake_queue(bgmac->net_dev);
278 +}
279 +
280 +static void bgmac_dma_rx_reset(struct bgmac *bgmac, struct bgmac_dma_ring *ring)
281 +{
282 + if (!ring->mmio_base)
283 + return;
284 +
285 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL, 0);
286 + if (!bgmac_wait_value(bgmac->core,
287 + ring->mmio_base + BGMAC_DMA_RX_STATUS,
288 + BGMAC_DMA_RX_STAT, BGMAC_DMA_RX_STAT_DISABLED,
289 + 10000))
290 + bgmac_err(bgmac, "Reset of ring 0x%X RX failed\n",
291 + ring->mmio_base);
292 +}
293 +
294 +static void bgmac_dma_rx_enable(struct bgmac *bgmac,
295 + struct bgmac_dma_ring *ring)
296 +{
297 + u32 ctl;
298 +
299 + ctl = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL);
300 + ctl &= BGMAC_DMA_RX_ADDREXT_MASK;
301 + ctl |= BGMAC_DMA_RX_ENABLE;
302 + ctl |= BGMAC_DMA_RX_PARITY_DISABLE;
303 + ctl |= BGMAC_DMA_RX_OVERFLOW_CONT;
304 + ctl |= BGMAC_RX_FRAME_OFFSET << BGMAC_DMA_RX_FRAME_OFFSET_SHIFT;
305 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL, ctl);
306 +}
307 +
308 +static int bgmac_dma_rx_skb_for_slot(struct bgmac *bgmac,
309 + struct bgmac_slot_info *slot)
310 +{
311 + struct device *dma_dev = bgmac->core->dma_dev;
312 + struct bgmac_rx_header *rx;
313 +
314 + /* Alloc skb */
315 + slot->skb = netdev_alloc_skb(bgmac->net_dev, BGMAC_RX_BUF_SIZE);
316 + if (!slot->skb) {
317 + bgmac_err(bgmac, "Allocation of skb failed!\n");
318 + return -ENOMEM;
319 + }
320 +
321 + /* Poison - if everything goes fine, hardware will overwrite it */
322 + rx = (struct bgmac_rx_header *)slot->skb->data;
323 + rx->len = cpu_to_le16(0xdead);
324 + rx->flags = cpu_to_le16(0xbeef);
325 +
326 + /* Map skb for the DMA */
327 + slot->dma_addr = dma_map_single(dma_dev, slot->skb->data,
328 + BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
329 + if (dma_mapping_error(dma_dev, slot->dma_addr)) {
330 + bgmac_err(bgmac, "DMA mapping error\n");
331 + return -ENOMEM;
332 + }
333 + if (slot->dma_addr & 0xC0000000)
334 + bgmac_warn(bgmac, "DMA address using 0xC0000000 bit(s), it may need translation trick\n");
335 +
336 + return 0;
337 +}
338 +
339 +static int bgmac_dma_rx_read(struct bgmac *bgmac, struct bgmac_dma_ring *ring,
340 + int weight)
341 +{
342 + u32 end_slot;
343 + int handled = 0;
344 +
345 + end_slot = bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_STATUS);
346 + end_slot &= BGMAC_DMA_RX_STATDPTR;
347 + end_slot /= sizeof(struct bgmac_dma_desc);
348 +
349 + ring->end = end_slot;
350 +
351 + while (ring->start != ring->end) {
352 + struct device *dma_dev = bgmac->core->dma_dev;
353 + struct bgmac_slot_info *slot = &ring->slots[ring->start];
354 + struct sk_buff *skb = slot->skb;
355 + struct sk_buff *new_skb;
356 + struct bgmac_rx_header *rx;
357 + u16 len, flags;
358 +
359 + /* Unmap buffer to make it accessible to the CPU */
360 + dma_sync_single_for_cpu(dma_dev, slot->dma_addr,
361 + BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
362 +
363 + /* Get info from the header */
364 + rx = (struct bgmac_rx_header *)skb->data;
365 + len = le16_to_cpu(rx->len);
366 + flags = le16_to_cpu(rx->flags);
367 +
368 + /* Check for poison and drop or pass the packet */
369 + if (len == 0xdead && flags == 0xbeef) {
370 + bgmac_err(bgmac, "Found poisoned packet at slot %d, DMA issue!\n",
371 + ring->start);
372 + } else {
373 + new_skb = netdev_alloc_skb(bgmac->net_dev, len);
374 + if (new_skb) {
375 + skb_put(new_skb, len);
376 + skb_copy_from_linear_data_offset(skb, BGMAC_RX_FRAME_OFFSET,
377 + new_skb->data,
378 + len);
379 + new_skb->protocol =
380 + eth_type_trans(new_skb, bgmac->net_dev);
381 + netif_receive_skb(new_skb);
382 + handled++;
383 + } else {
384 + bgmac->net_dev->stats.rx_dropped++;
385 + bgmac_err(bgmac, "Allocation of skb for copying packet failed!\n");
386 + }
387 +
388 + /* Poison the old skb */
389 + rx->len = cpu_to_le16(0xdead);
390 + rx->flags = cpu_to_le16(0xbeef);
391 + }
392 +
393 + /* Make it back accessible to the hardware */
394 + dma_sync_single_for_device(dma_dev, slot->dma_addr,
395 + BGMAC_RX_BUF_SIZE, DMA_FROM_DEVICE);
396 +
397 + if (++ring->start >= BGMAC_RX_RING_SLOTS)
398 + ring->start = 0;
399 +
400 + if (handled >= weight) /* Should never be greater */
401 + break;
402 + }
403 +
404 + return handled;
405 +}
406 +
407 +/* Does ring support unaligned addressing? */
408 +static bool bgmac_dma_unaligned(struct bgmac *bgmac,
409 + struct bgmac_dma_ring *ring,
410 + enum bgmac_dma_ring_type ring_type)
411 +{
412 + switch (ring_type) {
413 + case BGMAC_DMA_RING_TX:
414 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_RINGLO,
415 + 0xff0);
416 + if (bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_TX_RINGLO))
417 + return true;
418 + break;
419 + case BGMAC_DMA_RING_RX:
420 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_RINGLO,
421 + 0xff0);
422 + if (bgmac_read(bgmac, ring->mmio_base + BGMAC_DMA_RX_RINGLO))
423 + return true;
424 + break;
425 + }
426 + return false;
427 +}
428 +
429 +static void bgmac_dma_ring_free(struct bgmac *bgmac,
430 + struct bgmac_dma_ring *ring)
431 +{
432 + struct device *dma_dev = bgmac->core->dma_dev;
433 + struct bgmac_slot_info *slot;
434 + int size;
435 + int i;
436 +
437 + for (i = 0; i < ring->num_slots; i++) {
438 + slot = &ring->slots[i];
439 + if (slot->skb) {
440 + if (slot->dma_addr)
441 + dma_unmap_single(dma_dev, slot->dma_addr,
442 + slot->skb->len, DMA_TO_DEVICE);
443 + dev_kfree_skb(slot->skb);
444 + }
445 + }
446 +
447 + if (ring->cpu_base) {
448 + /* Free ring of descriptors */
449 + size = ring->num_slots * sizeof(struct bgmac_dma_desc);
450 + dma_free_coherent(dma_dev, size, ring->cpu_base,
451 + ring->dma_base);
452 + }
453 +}
454 +
455 +static void bgmac_dma_free(struct bgmac *bgmac)
456 +{
457 + int i;
458 +
459 + for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
460 + bgmac_dma_ring_free(bgmac, &bgmac->tx_ring[i]);
461 + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
462 + bgmac_dma_ring_free(bgmac, &bgmac->rx_ring[i]);
463 +}
464 +
465 +static int bgmac_dma_alloc(struct bgmac *bgmac)
466 +{
467 + struct device *dma_dev = bgmac->core->dma_dev;
468 + struct bgmac_dma_ring *ring;
469 + static const u16 ring_base[] = { BGMAC_DMA_BASE0, BGMAC_DMA_BASE1,
470 + BGMAC_DMA_BASE2, BGMAC_DMA_BASE3, };
471 + int size; /* ring size: different for Tx and Rx */
472 + int err;
473 + int i;
474 +
475 + BUILD_BUG_ON(BGMAC_MAX_TX_RINGS > ARRAY_SIZE(ring_base));
476 + BUILD_BUG_ON(BGMAC_MAX_RX_RINGS > ARRAY_SIZE(ring_base));
477 +
478 + if (!(bcma_aread32(bgmac->core, BCMA_IOST) & BCMA_IOST_DMA64)) {
479 + bgmac_err(bgmac, "Core does not report 64-bit DMA\n");
480 + return -ENOTSUPP;
481 + }
482 +
483 + for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
484 + ring = &bgmac->tx_ring[i];
485 + ring->num_slots = BGMAC_TX_RING_SLOTS;
486 + ring->mmio_base = ring_base[i];
487 + if (bgmac_dma_unaligned(bgmac, ring, BGMAC_DMA_RING_TX))
488 + bgmac_warn(bgmac, "TX on ring 0x%X supports unaligned addressing but this feature is not implemented\n",
489 + ring->mmio_base);
490 +
491 + /* Alloc ring of descriptors */
492 + size = ring->num_slots * sizeof(struct bgmac_dma_desc);
493 + ring->cpu_base = dma_zalloc_coherent(dma_dev, size,
494 + &ring->dma_base,
495 + GFP_KERNEL);
496 + if (!ring->cpu_base) {
497 + bgmac_err(bgmac, "Allocation of TX ring 0x%X failed\n",
498 + ring->mmio_base);
499 + goto err_dma_free;
500 + }
501 + if (ring->dma_base & 0xC0000000)
502 + bgmac_warn(bgmac, "DMA address using 0xC0000000 bit(s), it may need translation trick\n");
503 +
504 + /* No need to alloc TX slots yet */
505 + }
506 +
507 + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
508 + ring = &bgmac->rx_ring[i];
509 + ring->num_slots = BGMAC_RX_RING_SLOTS;
510 + ring->mmio_base = ring_base[i];
511 + if (bgmac_dma_unaligned(bgmac, ring, BGMAC_DMA_RING_RX))
512 + bgmac_warn(bgmac, "RX on ring 0x%X supports unaligned addressing but this feature is not implemented\n",
513 + ring->mmio_base);
514 +
515 + /* Alloc ring of descriptors */
516 + size = ring->num_slots * sizeof(struct bgmac_dma_desc);
517 + ring->cpu_base = dma_zalloc_coherent(dma_dev, size,
518 + &ring->dma_base,
519 + GFP_KERNEL);
520 + if (!ring->cpu_base) {
521 + bgmac_err(bgmac, "Allocation of RX ring 0x%X failed\n",
522 + ring->mmio_base);
523 + err = -ENOMEM;
524 + goto err_dma_free;
525 + }
526 + if (ring->dma_base & 0xC0000000)
527 + bgmac_warn(bgmac, "DMA address using 0xC0000000 bit(s), it may need translation trick\n");
528 +
529 + /* Alloc RX slots */
530 + for (i = 0; i < ring->num_slots; i++) {
531 + err = bgmac_dma_rx_skb_for_slot(bgmac, &ring->slots[i]);
532 + if (err) {
533 + bgmac_err(bgmac, "Can't allocate skb for slot in RX ring\n");
534 + goto err_dma_free;
535 + }
536 + }
537 + }
538 +
539 + return 0;
540 +
541 +err_dma_free:
542 + bgmac_dma_free(bgmac);
543 + return -ENOMEM;
544 +}
545 +
546 +static void bgmac_dma_init(struct bgmac *bgmac)
547 +{
548 + struct bgmac_dma_ring *ring;
549 + struct bgmac_dma_desc *dma_desc;
550 + u32 ctl0, ctl1;
551 + int i;
552 +
553 + for (i = 0; i < BGMAC_MAX_TX_RINGS; i++) {
554 + ring = &bgmac->tx_ring[i];
555 +
556 + /* We don't implement unaligned addressing, so enable first */
557 + bgmac_dma_tx_enable(bgmac, ring);
558 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_RINGLO,
559 + lower_32_bits(ring->dma_base));
560 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_RINGHI,
561 + upper_32_bits(ring->dma_base));
562 +
563 + ring->start = 0;
564 + ring->end = 0; /* Points the slot that should *not* be read */
565 + }
566 +
567 + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
568 + ring = &bgmac->rx_ring[i];
569 +
570 + /* We don't implement unaligned addressing, so enable first */
571 + bgmac_dma_rx_enable(bgmac, ring);
572 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_RINGLO,
573 + lower_32_bits(ring->dma_base));
574 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_RINGHI,
575 + upper_32_bits(ring->dma_base));
576 +
577 + for (i = 0, dma_desc = ring->cpu_base; i < ring->num_slots;
578 + i++, dma_desc++) {
579 + ctl0 = ctl1 = 0;
580 +
581 + if (i == ring->num_slots - 1)
582 + ctl0 |= BGMAC_DESC_CTL0_EOT;
583 + ctl1 |= BGMAC_RX_BUF_SIZE & BGMAC_DESC_CTL1_LEN;
584 + /* Is there any BGMAC device that requires extension? */
585 + /* ctl1 |= (addrext << B43_DMA64_DCTL1_ADDREXT_SHIFT) &
586 + * B43_DMA64_DCTL1_ADDREXT_MASK;
587 + */
588 +
589 + dma_desc->addr_low = cpu_to_le32(lower_32_bits(ring->slots[i].dma_addr));
590 + dma_desc->addr_high = cpu_to_le32(upper_32_bits(ring->slots[i].dma_addr));
591 + dma_desc->ctl0 = cpu_to_le32(ctl0);
592 + dma_desc->ctl1 = cpu_to_le32(ctl1);
593 + }
594 +
595 + bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_INDEX,
596 + ring->num_slots * sizeof(struct bgmac_dma_desc));
597 +
598 + ring->start = 0;
599 + ring->end = 0;
600 + }
601 +}
602 +
603 +/**************************************************
604 + * PHY ops
605 + **************************************************/
606 +
607 +u16 bgmac_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg)
608 +{
609 + struct bcma_device *core;
610 + u16 phy_access_addr;
611 + u16 phy_ctl_addr;
612 + u32 tmp;
613 +
614 + BUILD_BUG_ON(BGMAC_PA_DATA_MASK != BCMA_GMAC_CMN_PA_DATA_MASK);
615 + BUILD_BUG_ON(BGMAC_PA_ADDR_MASK != BCMA_GMAC_CMN_PA_ADDR_MASK);
616 + BUILD_BUG_ON(BGMAC_PA_ADDR_SHIFT != BCMA_GMAC_CMN_PA_ADDR_SHIFT);
617 + BUILD_BUG_ON(BGMAC_PA_REG_MASK != BCMA_GMAC_CMN_PA_REG_MASK);
618 + BUILD_BUG_ON(BGMAC_PA_REG_SHIFT != BCMA_GMAC_CMN_PA_REG_SHIFT);
619 + BUILD_BUG_ON(BGMAC_PA_WRITE != BCMA_GMAC_CMN_PA_WRITE);
620 + BUILD_BUG_ON(BGMAC_PA_START != BCMA_GMAC_CMN_PA_START);
621 + BUILD_BUG_ON(BGMAC_PC_EPA_MASK != BCMA_GMAC_CMN_PC_EPA_MASK);
622 + BUILD_BUG_ON(BGMAC_PC_MCT_MASK != BCMA_GMAC_CMN_PC_MCT_MASK);
623 + BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT);
624 + BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE);
625 +
626 + if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
627 + core = bgmac->core->bus->drv_gmac_cmn.core;
628 + phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
629 + phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
630 + } else {
631 + core = bgmac->core;
632 + phy_access_addr = BGMAC_PHY_ACCESS;
633 + phy_ctl_addr = BGMAC_PHY_CNTL;
634 + }
635 +
636 + tmp = bcma_read32(core, phy_ctl_addr);
637 + tmp &= ~BGMAC_PC_EPA_MASK;
638 + tmp |= phyaddr;
639 + bcma_write32(core, phy_ctl_addr, tmp);
640 +
641 + tmp = BGMAC_PA_START;
642 + tmp |= phyaddr << BGMAC_PA_ADDR_SHIFT;
643 + tmp |= reg << BGMAC_PA_REG_SHIFT;
644 + bcma_write32(core, phy_access_addr, tmp);
645 +
646 + if (!bgmac_wait_value(core, phy_access_addr, BGMAC_PA_START, 0, 1000)) {
647 + bgmac_err(bgmac, "Reading PHY %d register 0x%X failed\n",
648 + phyaddr, reg);
649 + return 0xffff;
650 + }
651 +
652 + return bcma_read32(core, phy_access_addr) & BGMAC_PA_DATA_MASK;
653 +}
654 +
655 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */
656 +void bgmac_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, u16 value)
657 +{
658 + struct bcma_device *core;
659 + u16 phy_access_addr;
660 + u16 phy_ctl_addr;
661 + u32 tmp;
662 +
663 + if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT) {
664 + core = bgmac->core->bus->drv_gmac_cmn.core;
665 + phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS;
666 + phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL;
667 + } else {
668 + core = bgmac->core;
669 + phy_access_addr = BGMAC_PHY_ACCESS;
670 + phy_ctl_addr = BGMAC_PHY_CNTL;
671 + }
672 +
673 + tmp = bcma_read32(core, phy_ctl_addr);
674 + tmp &= ~BGMAC_PC_EPA_MASK;
675 + tmp |= phyaddr;
676 + bcma_write32(core, phy_ctl_addr, tmp);
677 +
678 + bgmac_write(bgmac, BGMAC_INT_STATUS, BGMAC_IS_MDIO);
679 + if (bgmac_read(bgmac, BGMAC_INT_STATUS) & BGMAC_IS_MDIO)
680 + bgmac_warn(bgmac, "Error setting MDIO int\n");
681 +
682 + tmp = BGMAC_PA_START;
683 + tmp |= BGMAC_PA_WRITE;
684 + tmp |= phyaddr << BGMAC_PA_ADDR_SHIFT;
685 + tmp |= reg << BGMAC_PA_REG_SHIFT;
686 + tmp |= value;
687 + bcma_write32(core, phy_access_addr, tmp);
688 +
689 + if (!bgmac_wait_value(core, phy_access_addr, BGMAC_PA_START, 0, 1000))
690 + bgmac_err(bgmac, "Writing to PHY %d register 0x%X failed\n",
691 + phyaddr, reg);
692 +}
693 +
694 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyforce */
695 +static void bgmac_phy_force(struct bgmac *bgmac)
696 +{
697 + u16 ctl;
698 + u16 mask = ~(BGMAC_PHY_CTL_SPEED | BGMAC_PHY_CTL_SPEED_MSB |
699 + BGMAC_PHY_CTL_ANENAB | BGMAC_PHY_CTL_DUPLEX);
700 +
701 + if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
702 + return;
703 +
704 + if (bgmac->autoneg)
705 + return;
706 +
707 + ctl = bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL);
708 + ctl &= mask;
709 + if (bgmac->full_duplex)
710 + ctl |= BGMAC_PHY_CTL_DUPLEX;
711 + if (bgmac->speed == BGMAC_SPEED_100)
712 + ctl |= BGMAC_PHY_CTL_SPEED_100;
713 + else if (bgmac->speed == BGMAC_SPEED_1000)
714 + ctl |= BGMAC_PHY_CTL_SPEED_1000;
715 + bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL, ctl);
716 +}
717 +
718 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyadvertise */
719 +static void bgmac_phy_advertise(struct bgmac *bgmac)
720 +{
721 + u16 adv;
722 +
723 + if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
724 + return;
725 +
726 + if (!bgmac->autoneg)
727 + return;
728 +
729 + /* Adv selected 10/100 speeds */
730 + adv = bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV);
731 + adv &= ~(BGMAC_PHY_ADV_10HALF | BGMAC_PHY_ADV_10FULL |
732 + BGMAC_PHY_ADV_100HALF | BGMAC_PHY_ADV_100FULL);
733 + if (!bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_10)
734 + adv |= BGMAC_PHY_ADV_10HALF;
735 + if (!bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_100)
736 + adv |= BGMAC_PHY_ADV_100HALF;
737 + if (bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_10)
738 + adv |= BGMAC_PHY_ADV_10FULL;
739 + if (bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_100)
740 + adv |= BGMAC_PHY_ADV_100FULL;
741 + bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV, adv);
742 +
743 + /* Adv selected 1000 speeds */
744 + adv = bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV2);
745 + adv &= ~(BGMAC_PHY_ADV2_1000HALF | BGMAC_PHY_ADV2_1000FULL);
746 + if (!bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_1000)
747 + adv |= BGMAC_PHY_ADV2_1000HALF;
748 + if (bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_1000)
749 + adv |= BGMAC_PHY_ADV2_1000FULL;
750 + bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV2, adv);
751 +
752 + /* Restart */
753 + bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
754 + bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) |
755 + BGMAC_PHY_CTL_RESTART);
756 +}
757 +
758 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
759 +static void bgmac_phy_init(struct bgmac *bgmac)
760 +{
761 + struct bcma_chipinfo *ci = &bgmac->core->bus->chipinfo;
762 + struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc;
763 + u8 i;
764 +
765 + if (ci->id == BCMA_CHIP_ID_BCM5356) {
766 + for (i = 0; i < 5; i++) {
767 + bgmac_phy_write(bgmac, i, 0x1f, 0x008b);
768 + bgmac_phy_write(bgmac, i, 0x15, 0x0100);
769 + bgmac_phy_write(bgmac, i, 0x1f, 0x000f);
770 + bgmac_phy_write(bgmac, i, 0x12, 0x2aaa);
771 + bgmac_phy_write(bgmac, i, 0x1f, 0x000b);
772 + }
773 + }
774 + if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) ||
775 + (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) ||
776 + (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) {
777 + bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0);
778 + bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0);
779 + for (i = 0; i < 5; i++) {
780 + bgmac_phy_write(bgmac, i, 0x1f, 0x000f);
781 + bgmac_phy_write(bgmac, i, 0x16, 0x5284);
782 + bgmac_phy_write(bgmac, i, 0x1f, 0x000b);
783 + bgmac_phy_write(bgmac, i, 0x17, 0x0010);
784 + bgmac_phy_write(bgmac, i, 0x1f, 0x000f);
785 + bgmac_phy_write(bgmac, i, 0x16, 0x5296);
786 + bgmac_phy_write(bgmac, i, 0x17, 0x1073);
787 + bgmac_phy_write(bgmac, i, 0x17, 0x9073);
788 + bgmac_phy_write(bgmac, i, 0x16, 0x52b6);
789 + bgmac_phy_write(bgmac, i, 0x17, 0x9273);
790 + bgmac_phy_write(bgmac, i, 0x1f, 0x000b);
791 + }
792 + }
793 +}
794 +
795 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */
796 +static void bgmac_phy_reset(struct bgmac *bgmac)
797 +{
798 + if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
799 + return;
800 +
801 + bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
802 + BGMAC_PHY_CTL_RESET);
803 + udelay(100);
804 + if (bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) &
805 + BGMAC_PHY_CTL_RESET)
806 + bgmac_err(bgmac, "PHY reset failed\n");
807 + bgmac_phy_init(bgmac);
808 +}
809 +
810 +/**************************************************
811 + * Chip ops
812 + **************************************************/
813 +
814 +/* TODO: can we just drop @force? Can we don't reset MAC at all if there is
815 + * nothing to change? Try if after stabilizng driver.
816 + */
817 +static void bgmac_cmdcfg_maskset(struct bgmac *bgmac, u32 mask, u32 set,
818 + bool force)
819 +{
820 + u32 cmdcfg = bgmac_read(bgmac, BGMAC_CMDCFG);
821 + u32 new_val = (cmdcfg & mask) | set;
822 +
823 + bgmac_set(bgmac, BGMAC_CMDCFG, BGMAC_CMDCFG_SR);
824 + udelay(2);
825 +
826 + if (new_val != cmdcfg || force)
827 + bgmac_write(bgmac, BGMAC_CMDCFG, new_val);
828 +
829 + bgmac_mask(bgmac, BGMAC_CMDCFG, ~BGMAC_CMDCFG_SR);
830 + udelay(2);
831 +}
832 +
833 +#if 0 /* We don't use that regs yet */
834 +static void bgmac_chip_stats_update(struct bgmac *bgmac)
835 +{
836 + int i;
837 +
838 + if (bgmac->core->id.id != BCMA_CORE_4706_MAC_GBIT) {
839 + for (i = 0; i < BGMAC_NUM_MIB_TX_REGS; i++)
840 + bgmac->mib_tx_regs[i] =
841 + bgmac_read(bgmac,
842 + BGMAC_TX_GOOD_OCTETS + (i * 4));
843 + for (i = 0; i < BGMAC_NUM_MIB_RX_REGS; i++)
844 + bgmac->mib_rx_regs[i] =
845 + bgmac_read(bgmac,
846 + BGMAC_RX_GOOD_OCTETS + (i * 4));
847 + }
848 +
849 + /* TODO: what else? how to handle BCM4706? Specs are needed */
850 +}
851 +#endif
852 +
853 +static void bgmac_clear_mib(struct bgmac *bgmac)
854 +{
855 + int i;
856 +
857 + if (bgmac->core->id.id == BCMA_CORE_4706_MAC_GBIT)
858 + return;
859 +
860 + bgmac_set(bgmac, BGMAC_DEV_CTL, BGMAC_DC_MROR);
861 + for (i = 0; i < BGMAC_NUM_MIB_TX_REGS; i++)
862 + bgmac_read(bgmac, BGMAC_TX_GOOD_OCTETS + (i * 4));
863 + for (i = 0; i < BGMAC_NUM_MIB_RX_REGS; i++)
864 + bgmac_read(bgmac, BGMAC_RX_GOOD_OCTETS + (i * 4));
865 +}
866 +
867 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_speed */
868 +static void bgmac_speed(struct bgmac *bgmac, int speed)
869 +{
870 + u32 mask = ~(BGMAC_CMDCFG_ES_MASK | BGMAC_CMDCFG_HD);
871 + u32 set = 0;
872 +
873 + if (speed & BGMAC_SPEED_10)
874 + set |= BGMAC_CMDCFG_ES_10;
875 + if (speed & BGMAC_SPEED_100)
876 + set |= BGMAC_CMDCFG_ES_100;
877 + if (speed & BGMAC_SPEED_1000)
878 + set |= BGMAC_CMDCFG_ES_1000;
879 + if (!bgmac->full_duplex)
880 + set |= BGMAC_CMDCFG_HD;
881 + bgmac_cmdcfg_maskset(bgmac, mask, set, true);
882 +}
883 +
884 +static void bgmac_miiconfig(struct bgmac *bgmac)
885 +{
886 + u8 imode = (bgmac_read(bgmac, BGMAC_DEV_STATUS) & BGMAC_DS_MM_MASK) >>
887 + BGMAC_DS_MM_SHIFT;
888 + if (imode == 0 || imode == 1) {
889 + if (bgmac->autoneg)
890 + bgmac_speed(bgmac, BGMAC_SPEED_100);
891 + else
892 + bgmac_speed(bgmac, bgmac->speed);
893 + }
894 +}
895 +
896 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipreset */
897 +static void bgmac_chip_reset(struct bgmac *bgmac)
898 +{
899 + struct bcma_device *core = bgmac->core;
900 + struct bcma_bus *bus = core->bus;
901 + struct bcma_chipinfo *ci = &bus->chipinfo;
902 + u32 flags = 0;
903 + u32 iost;
904 + int i;
905 +
906 + if (bcma_core_is_enabled(core)) {
907 + if (!bgmac->stats_grabbed) {
908 + /* bgmac_chip_stats_update(bgmac); */
909 + bgmac->stats_grabbed = true;
910 + }
911 +
912 + for (i = 0; i < BGMAC_MAX_TX_RINGS; i++)
913 + bgmac_dma_tx_reset(bgmac, &bgmac->tx_ring[i]);
914 +
915 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, false);
916 + udelay(1);
917 +
918 + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++)
919 + bgmac_dma_rx_reset(bgmac, &bgmac->rx_ring[i]);
920 +
921 + /* TODO: Clear software multicast filter list */
922 + }
923 +
924 + iost = bcma_aread32(core, BCMA_IOST);
925 + if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 10) ||
926 + (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg == 10) ||
927 + (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == 9))
928 + iost &= ~BGMAC_BCMA_IOST_ATTACHED;
929 +
930 + if (iost & BGMAC_BCMA_IOST_ATTACHED) {
931 + flags = BGMAC_BCMA_IOCTL_SW_CLKEN;
932 + if (!bgmac->has_robosw)
933 + flags |= BGMAC_BCMA_IOCTL_SW_RESET;
934 + }
935 +
936 + bcma_core_enable(core, flags);
937 +
938 + if (core->id.rev > 2) {
939 + bgmac_set(bgmac, BCMA_CLKCTLST, 1 << 8);
940 + bgmac_wait_value(bgmac->core, BCMA_CLKCTLST, 1 << 24, 1 << 24,
941 + 1000);
942 + }
943 +
944 + if (ci->id == BCMA_CHIP_ID_BCM5357 || ci->id == BCMA_CHIP_ID_BCM4749 ||
945 + ci->id == BCMA_CHIP_ID_BCM53572) {
946 + struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc;
947 + u8 et_swtype = 0;
948 + u8 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHY |
949 + BGMAC_CHIPCTL_1_IF_TYPE_RMII;
950 + char buf[2];
951 +
952 + if (bcm47xx_nvram_getenv("et_swtype", buf, 1) > 0) {
953 + if (kstrtou8(buf, 0, &et_swtype))
954 + bgmac_err(bgmac, "Failed to parse et_swtype (%s)\n",
955 + buf);
956 + et_swtype &= 0x0f;
957 + et_swtype <<= 4;
958 + sw_type = et_swtype;
959 + } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 9) {
960 + sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII;
961 + } else if (0) {
962 + /* TODO */
963 + }
964 + bcma_chipco_chipctl_maskset(cc, 1,
965 + ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK |
966 + BGMAC_CHIPCTL_1_SW_TYPE_MASK),
967 + sw_type);
968 + }
969 +
970 + if (iost & BGMAC_BCMA_IOST_ATTACHED && !bgmac->has_robosw)
971 + bcma_awrite32(core, BCMA_IOCTL,
972 + bcma_aread32(core, BCMA_IOCTL) &
973 + ~BGMAC_BCMA_IOCTL_SW_RESET);
974 +
975 + /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_reset
976 + * Specs don't say about using BGMAC_CMDCFG_SR, but in this routine
977 + * BGMAC_CMDCFG is read _after_ putting chip in a reset. So it has to
978 + * be keps until taking MAC out of the reset.
979 + */
980 + bgmac_cmdcfg_maskset(bgmac,
981 + ~(BGMAC_CMDCFG_TE |
982 + BGMAC_CMDCFG_RE |
983 + BGMAC_CMDCFG_RPI |
984 + BGMAC_CMDCFG_TAI |
985 + BGMAC_CMDCFG_HD |
986 + BGMAC_CMDCFG_ML |
987 + BGMAC_CMDCFG_CFE |
988 + BGMAC_CMDCFG_RL |
989 + BGMAC_CMDCFG_RED |
990 + BGMAC_CMDCFG_PE |
991 + BGMAC_CMDCFG_TPI |
992 + BGMAC_CMDCFG_PAD_EN |
993 + BGMAC_CMDCFG_PF),
994 + BGMAC_CMDCFG_PROM |
995 + BGMAC_CMDCFG_NLC |
996 + BGMAC_CMDCFG_CFE |
997 + BGMAC_CMDCFG_SR,
998 + false);
999 +
1000 + bgmac_clear_mib(bgmac);
1001 + if (core->id.id == BCMA_CORE_4706_MAC_GBIT)
1002 + bcma_maskset32(bgmac->cmn, BCMA_GMAC_CMN_PHY_CTL, ~0,
1003 + BCMA_GMAC_CMN_PC_MTE);
1004 + else
1005 + bgmac_set(bgmac, BGMAC_PHY_CNTL, BGMAC_PC_MTE);
1006 + bgmac_miiconfig(bgmac);
1007 + bgmac_phy_init(bgmac);
1008 +
1009 + bgmac->int_status = 0;
1010 +}
1011 +
1012 +static void bgmac_chip_intrs_on(struct bgmac *bgmac)
1013 +{
1014 + bgmac_write(bgmac, BGMAC_INT_MASK, bgmac->int_mask);
1015 +}
1016 +
1017 +static void bgmac_chip_intrs_off(struct bgmac *bgmac)
1018 +{
1019 + bgmac_write(bgmac, BGMAC_INT_MASK, 0);
1020 +}
1021 +
1022 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_enable */
1023 +static void bgmac_enable(struct bgmac *bgmac)
1024 +{
1025 + struct bcma_chipinfo *ci = &bgmac->core->bus->chipinfo;
1026 + u32 cmdcfg;
1027 + u32 mode;
1028 + u32 rxq_ctl;
1029 + u32 fl_ctl;
1030 + u16 bp_clk;
1031 + u8 mdp;
1032 +
1033 + cmdcfg = bgmac_read(bgmac, BGMAC_CMDCFG);
1034 + bgmac_cmdcfg_maskset(bgmac, ~(BGMAC_CMDCFG_TE | BGMAC_CMDCFG_RE),
1035 + BGMAC_CMDCFG_SR, true);
1036 + udelay(2);
1037 + cmdcfg |= BGMAC_CMDCFG_TE | BGMAC_CMDCFG_RE;
1038 + bgmac_write(bgmac, BGMAC_CMDCFG, cmdcfg);
1039 +
1040 + mode = (bgmac_read(bgmac, BGMAC_DEV_STATUS) & BGMAC_DS_MM_MASK) >>
1041 + BGMAC_DS_MM_SHIFT;
1042 + if (ci->id != BCMA_CHIP_ID_BCM47162 || mode != 0)
1043 + bgmac_set(bgmac, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT);
1044 + if (ci->id == BCMA_CHIP_ID_BCM47162 && mode == 2)
1045 + bcma_chipco_chipctl_maskset(&bgmac->core->bus->drv_cc, 1, ~0,
1046 + BGMAC_CHIPCTL_1_RXC_DLL_BYPASS);
1047 +
1048 + switch (ci->id) {
1049 + case BCMA_CHIP_ID_BCM5357:
1050 + case BCMA_CHIP_ID_BCM4749:
1051 + case BCMA_CHIP_ID_BCM53572:
1052 + case BCMA_CHIP_ID_BCM4716:
1053 + case BCMA_CHIP_ID_BCM47162:
1054 + fl_ctl = 0x03cb04cb;
1055 + if (ci->id == BCMA_CHIP_ID_BCM5357 ||
1056 + ci->id == BCMA_CHIP_ID_BCM4749 ||
1057 + ci->id == BCMA_CHIP_ID_BCM53572)
1058 + fl_ctl = 0x2300e1;
1059 + bgmac_write(bgmac, BGMAC_FLOW_CTL_THRESH, fl_ctl);
1060 + bgmac_write(bgmac, BGMAC_PAUSE_CTL, 0x27fff);
1061 + break;
1062 + }
1063 +
1064 + rxq_ctl = bgmac_read(bgmac, BGMAC_RXQ_CTL);
1065 + rxq_ctl &= ~BGMAC_RXQ_CTL_MDP_MASK;
1066 + bp_clk = bcma_pmu_get_bus_clock(&bgmac->core->bus->drv_cc) / 1000000;
1067 + mdp = (bp_clk * 128 / 1000) - 3;
1068 + rxq_ctl |= (mdp << BGMAC_RXQ_CTL_MDP_SHIFT);
1069 + bgmac_write(bgmac, BGMAC_RXQ_CTL, rxq_ctl);
1070 +}
1071 +
1072 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipinit */
1073 +static void bgmac_chip_init(struct bgmac *bgmac, bool full_init)
1074 +{
1075 + struct bgmac_dma_ring *ring;
1076 + u8 *mac = bgmac->net_dev->dev_addr;
1077 + u32 tmp;
1078 + int i;
1079 +
1080 + /* 1 interrupt per received frame */
1081 + bgmac_write(bgmac, BGMAC_INT_RECV_LAZY, 1 << BGMAC_IRL_FC_SHIFT);
1082 +
1083 + /* Enable 802.3x tx flow control (honor received PAUSE frames) */
1084 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_RPI, 0, true);
1085 +
1086 + if (bgmac->net_dev->flags & IFF_PROMISC)
1087 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_PROM, false);
1088 + else
1089 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_PROM, 0, false);
1090 +
1091 + /* Set MAC addr */
1092 + tmp = (mac[0] << 24) | (mac[1] << 16) | (mac[2] << 8) | mac[3];
1093 + bgmac_write(bgmac, BGMAC_MACADDR_HIGH, tmp);
1094 + tmp = (mac[4] << 8) | mac[5];
1095 + bgmac_write(bgmac, BGMAC_MACADDR_LOW, tmp);
1096 +
1097 + if (bgmac->loopback)
1098 + bgmac_cmdcfg_maskset(bgmac, ~0, BGMAC_CMDCFG_ML, true);
1099 + else
1100 + bgmac_cmdcfg_maskset(bgmac, ~BGMAC_CMDCFG_ML, 0, true);
1101 +
1102 + bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
1103 +
1104 + if (!bgmac->autoneg) {
1105 + bgmac_speed(bgmac, bgmac->speed);
1106 + bgmac_phy_force(bgmac);
1107 + } else if (bgmac->speed) { /* if there is anything to adv */
1108 + bgmac_phy_advertise(bgmac);
1109 + }
1110 +
1111 + if (full_init) {
1112 + bgmac_dma_init(bgmac);
1113 + if (1) /* FIXME: is there any case we don't want IRQs? */
1114 + bgmac_chip_intrs_on(bgmac);
1115 + } else {
1116 + for (i = 0; i < BGMAC_MAX_RX_RINGS; i++) {
1117 + ring = &bgmac->rx_ring[i];
1118 + bgmac_dma_rx_enable(bgmac, ring);
1119 + }
1120 + }
1121 +
1122 + bgmac_enable(bgmac);
1123 +}
1124 +
1125 +static irqreturn_t bgmac_interrupt(int irq, void *dev_id)
1126 +{
1127 + struct bgmac *bgmac = netdev_priv(dev_id);
1128 +
1129 + u32 int_status = bgmac_read(bgmac, BGMAC_INT_STATUS);
1130 + int_status &= bgmac->int_mask;
1131 +
1132 + if (!int_status)
1133 + return IRQ_NONE;
1134 +
1135 + /* Ack */
1136 + bgmac_write(bgmac, BGMAC_INT_STATUS, int_status);
1137 +
1138 + /* Disable new interrupts until handling existing ones */
1139 + bgmac_chip_intrs_off(bgmac);
1140 +
1141 + bgmac->int_status = int_status;
1142 +
1143 + napi_schedule(&bgmac->napi);
1144 +
1145 + return IRQ_HANDLED;
1146 +}
1147 +
1148 +static int bgmac_poll(struct napi_struct *napi, int weight)
1149 +{
1150 + struct bgmac *bgmac = container_of(napi, struct bgmac, napi);
1151 + struct bgmac_dma_ring *ring;
1152 + int handled = 0;
1153 +
1154 + if (bgmac->int_status & BGMAC_IS_TX0) {
1155 + ring = &bgmac->tx_ring[0];
1156 + bgmac_dma_tx_free(bgmac, ring);
1157 + bgmac->int_status &= ~BGMAC_IS_TX0;
1158 + }
1159 +
1160 + if (bgmac->int_status & BGMAC_IS_RX) {
1161 + ring = &bgmac->rx_ring[0];
1162 + handled += bgmac_dma_rx_read(bgmac, ring, weight);
1163 + bgmac->int_status &= ~BGMAC_IS_RX;
1164 + }
1165 +
1166 + if (bgmac->int_status) {
1167 + bgmac_err(bgmac, "Unknown IRQs: 0x%08X\n", bgmac->int_status);
1168 + bgmac->int_status = 0;
1169 + }
1170 +
1171 + if (handled < weight)
1172 + napi_complete(napi);
1173 +
1174 + bgmac_chip_intrs_on(bgmac);
1175 +
1176 + return handled;
1177 +}
1178 +
1179 +/**************************************************
1180 + * net_device_ops
1181 + **************************************************/
1182 +
1183 +static int bgmac_open(struct net_device *net_dev)
1184 +{
1185 + struct bgmac *bgmac = netdev_priv(net_dev);
1186 + int err = 0;
1187 +
1188 + bgmac_chip_reset(bgmac);
1189 + /* Specs say about reclaiming rings here, but we do that in DMA init */
1190 + bgmac_chip_init(bgmac, true);
1191 +
1192 + err = request_irq(bgmac->core->irq, bgmac_interrupt, IRQF_SHARED,
1193 + KBUILD_MODNAME, net_dev);
1194 + if (err < 0) {
1195 + bgmac_err(bgmac, "IRQ request error: %d!\n", err);
1196 + goto err_out;
1197 + }
1198 + napi_enable(&bgmac->napi);
1199 +
1200 + netif_carrier_on(net_dev);
1201 +
1202 +err_out:
1203 + return err;
1204 +}
1205 +
1206 +static int bgmac_stop(struct net_device *net_dev)
1207 +{
1208 + struct bgmac *bgmac = netdev_priv(net_dev);
1209 +
1210 + netif_carrier_off(net_dev);
1211 +
1212 + napi_disable(&bgmac->napi);
1213 + bgmac_chip_intrs_off(bgmac);
1214 + free_irq(bgmac->core->irq, net_dev);
1215 +
1216 + bgmac_chip_reset(bgmac);
1217 +
1218 + return 0;
1219 +}
1220 +
1221 +static netdev_tx_t bgmac_start_xmit(struct sk_buff *skb,
1222 + struct net_device *net_dev)
1223 +{
1224 + struct bgmac *bgmac = netdev_priv(net_dev);
1225 + struct bgmac_dma_ring *ring;
1226 +
1227 + /* No QOS support yet */
1228 + ring = &bgmac->tx_ring[0];
1229 + return bgmac_dma_tx_add(bgmac, ring, skb);
1230 +}
1231 +
1232 +static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
1233 +{
1234 + struct bgmac *bgmac = netdev_priv(net_dev);
1235 + struct mii_ioctl_data *data = if_mii(ifr);
1236 +
1237 + switch (cmd) {
1238 + case SIOCGMIIPHY:
1239 + data->phy_id = bgmac->phyaddr;
1240 + /* fallthru */
1241 + case SIOCGMIIREG:
1242 + if (!netif_running(net_dev))
1243 + return -EAGAIN;
1244 + data->val_out = bgmac_phy_read(bgmac, data->phy_id,
1245 + data->reg_num & 0x1f);
1246 + return 0;
1247 + case SIOCSMIIREG:
1248 + if (!netif_running(net_dev))
1249 + return -EAGAIN;
1250 + bgmac_phy_write(bgmac, data->phy_id, data->reg_num & 0x1f,
1251 + data->val_in);
1252 + return 0;
1253 + default:
1254 + return -EOPNOTSUPP;
1255 + }
1256 +}
1257 +
1258 +static const struct net_device_ops bgmac_netdev_ops = {
1259 + .ndo_open = bgmac_open,
1260 + .ndo_stop = bgmac_stop,
1261 + .ndo_start_xmit = bgmac_start_xmit,
1262 + .ndo_set_mac_address = eth_mac_addr, /* generic, sets dev_addr */
1263 + .ndo_do_ioctl = bgmac_ioctl,
1264 +};
1265 +
1266 +/**************************************************
1267 + * ethtool_ops
1268 + **************************************************/
1269 +
1270 +static int bgmac_get_settings(struct net_device *net_dev,
1271 + struct ethtool_cmd *cmd)
1272 +{
1273 + struct bgmac *bgmac = netdev_priv(net_dev);
1274 +
1275 + cmd->supported = SUPPORTED_10baseT_Half |
1276 + SUPPORTED_10baseT_Full |
1277 + SUPPORTED_100baseT_Half |
1278 + SUPPORTED_100baseT_Full |
1279 + SUPPORTED_1000baseT_Half |
1280 + SUPPORTED_1000baseT_Full |
1281 + SUPPORTED_Autoneg;
1282 +
1283 + if (bgmac->autoneg) {
1284 + WARN_ON(cmd->advertising);
1285 + if (bgmac->full_duplex) {
1286 + if (bgmac->speed & BGMAC_SPEED_10)
1287 + cmd->advertising |= ADVERTISED_10baseT_Full;
1288 + if (bgmac->speed & BGMAC_SPEED_100)
1289 + cmd->advertising |= ADVERTISED_100baseT_Full;
1290 + if (bgmac->speed & BGMAC_SPEED_1000)
1291 + cmd->advertising |= ADVERTISED_1000baseT_Full;
1292 + } else {
1293 + if (bgmac->speed & BGMAC_SPEED_10)
1294 + cmd->advertising |= ADVERTISED_10baseT_Half;
1295 + if (bgmac->speed & BGMAC_SPEED_100)
1296 + cmd->advertising |= ADVERTISED_100baseT_Half;
1297 + if (bgmac->speed & BGMAC_SPEED_1000)
1298 + cmd->advertising |= ADVERTISED_1000baseT_Half;
1299 + }
1300 + } else {
1301 + switch (bgmac->speed) {
1302 + case BGMAC_SPEED_10:
1303 + ethtool_cmd_speed_set(cmd, SPEED_10);
1304 + break;
1305 + case BGMAC_SPEED_100:
1306 + ethtool_cmd_speed_set(cmd, SPEED_100);
1307 + break;
1308 + case BGMAC_SPEED_1000:
1309 + ethtool_cmd_speed_set(cmd, SPEED_1000);
1310 + break;
1311 + }
1312 + }
1313 +
1314 + cmd->duplex = bgmac->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
1315 +
1316 + cmd->autoneg = bgmac->autoneg;
1317 +
1318 + return 0;
1319 +}
1320 +
1321 +#if 0
1322 +static int bgmac_set_settings(struct net_device *net_dev,
1323 + struct ethtool_cmd *cmd)
1324 +{
1325 + struct bgmac *bgmac = netdev_priv(net_dev);
1326 +
1327 + return -1;
1328 +}
1329 +#endif
1330 +
1331 +static void bgmac_get_drvinfo(struct net_device *net_dev,
1332 + struct ethtool_drvinfo *info)
1333 +{
1334 + strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
1335 + strlcpy(info->bus_info, "BCMA", sizeof(info->bus_info));
1336 +}
1337 +
1338 +static const struct ethtool_ops bgmac_ethtool_ops = {
1339 + .get_settings = bgmac_get_settings,
1340 + .get_drvinfo = bgmac_get_drvinfo,
1341 +};
1342 +
1343 +/**************************************************
1344 + * BCMA bus ops
1345 + **************************************************/
1346 +
1347 +/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */
1348 +static int bgmac_probe(struct bcma_device *core)
1349 +{
1350 + struct net_device *net_dev;
1351 + struct bgmac *bgmac;
1352 + struct ssb_sprom *sprom = &core->bus->sprom;
1353 + u8 *mac = core->core_unit ? sprom->et1mac : sprom->et0mac;
1354 + int err;
1355 +
1356 + /* We don't support 2nd, 3rd, ... units, SPROM has to be adjusted */
1357 + if (core->core_unit > 1) {
1358 + pr_err("Unsupported core_unit %d\n", core->core_unit);
1359 + return -ENOTSUPP;
1360 + }
1361 +
1362 + /* Allocation and references */
1363 + net_dev = alloc_etherdev(sizeof(*bgmac));
1364 + if (!net_dev)
1365 + return -ENOMEM;
1366 + net_dev->netdev_ops = &bgmac_netdev_ops;
1367 + net_dev->irq = core->irq;
1368 + SET_ETHTOOL_OPS(net_dev, &bgmac_ethtool_ops);
1369 + bgmac = netdev_priv(net_dev);
1370 + bgmac->net_dev = net_dev;
1371 + bgmac->core = core;
1372 + bcma_set_drvdata(core, bgmac);
1373 +
1374 + /* Defaults */
1375 + bgmac->autoneg = true;
1376 + bgmac->full_duplex = true;
1377 + bgmac->speed = BGMAC_SPEED_10 | BGMAC_SPEED_100 | BGMAC_SPEED_1000;
1378 + memcpy(bgmac->net_dev->dev_addr, mac, ETH_ALEN);
1379 +
1380 + /* On BCM4706 we need common core to access PHY */
1381 + if (core->id.id == BCMA_CORE_4706_MAC_GBIT &&
1382 + !core->bus->drv_gmac_cmn.core) {
1383 + bgmac_err(bgmac, "GMAC CMN core not found (required for BCM4706)\n");
1384 + err = -ENODEV;
1385 + goto err_netdev_free;
1386 + }
1387 + bgmac->cmn = core->bus->drv_gmac_cmn.core;
1388 +
1389 + bgmac->phyaddr = core->core_unit ? sprom->et1phyaddr :
1390 + sprom->et0phyaddr;
1391 + bgmac->phyaddr &= BGMAC_PHY_MASK;
1392 + if (bgmac->phyaddr == BGMAC_PHY_MASK) {
1393 + bgmac_err(bgmac, "No PHY found\n");
1394 + err = -ENODEV;
1395 + goto err_netdev_free;
1396 + }
1397 + bgmac_info(bgmac, "Found PHY addr: %d%s\n", bgmac->phyaddr,
1398 + bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : "");
1399 +
1400 + if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) {
1401 + bgmac_err(bgmac, "PCI setup not implemented\n");
1402 + err = -ENOTSUPP;
1403 + goto err_netdev_free;
1404 + }
1405 +
1406 + bgmac_chip_reset(bgmac);
1407 +
1408 + err = bgmac_dma_alloc(bgmac);
1409 + if (err) {
1410 + bgmac_err(bgmac, "Unable to alloc memory for DMA\n");
1411 + goto err_netdev_free;
1412 + }
1413 +
1414 + bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK;
1415 + if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0)
1416 + bgmac->int_mask &= ~BGMAC_IS_TX_MASK;
1417 +
1418 + /* TODO: reset the external phy. Specs are needed */
1419 + bgmac_phy_reset(bgmac);
1420 +
1421 + bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo &
1422 + BGMAC_BFL_ENETROBO);
1423 + if (bgmac->has_robosw)
1424 + bgmac_warn(bgmac, "Support for Roboswitch not implemented\n");
1425 +
1426 + if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM)
1427 + bgmac_warn(bgmac, "Support for ADMtek ethernet switch not implemented\n");
1428 +
1429 + err = register_netdev(bgmac->net_dev);
1430 + if (err) {
1431 + bgmac_err(bgmac, "Cannot register net device\n");
1432 + err = -ENOTSUPP;
1433 + goto err_dma_free;
1434 + }
1435 +
1436 + netif_carrier_off(net_dev);
1437 +
1438 + netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT);
1439 +
1440 + return 0;
1441 +
1442 +err_dma_free:
1443 + bgmac_dma_free(bgmac);
1444 +
1445 +err_netdev_free:
1446 + bcma_set_drvdata(core, NULL);
1447 + free_netdev(net_dev);
1448 +
1449 + return err;
1450 +}
1451 +
1452 +static void bgmac_remove(struct bcma_device *core)
1453 +{
1454 + struct bgmac *bgmac = bcma_get_drvdata(core);
1455 +
1456 + netif_napi_del(&bgmac->napi);
1457 + unregister_netdev(bgmac->net_dev);
1458 + bgmac_dma_free(bgmac);
1459 + bcma_set_drvdata(core, NULL);
1460 + free_netdev(bgmac->net_dev);
1461 +}
1462 +
1463 +static struct bcma_driver bgmac_bcma_driver = {
1464 + .name = KBUILD_MODNAME,
1465 + .id_table = bgmac_bcma_tbl,
1466 + .probe = bgmac_probe,
1467 + .remove = bgmac_remove,
1468 +};
1469 +
1470 +static int __init bgmac_init(void)
1471 +{
1472 + int err;
1473 +
1474 + err = bcma_driver_register(&bgmac_bcma_driver);
1475 + if (err)
1476 + return err;
1477 + pr_info("Broadcom 47xx GBit MAC driver loaded\n");
1478 +
1479 + return 0;
1480 +}
1481 +
1482 +static void __exit bgmac_exit(void)
1483 +{
1484 + bcma_driver_unregister(&bgmac_bcma_driver);
1485 +}
1486 +
1487 +module_init(bgmac_init)
1488 +module_exit(bgmac_exit)
1489 +
1490 +MODULE_AUTHOR("Rafał Miłecki");
1491 +MODULE_LICENSE("GPL");
1492 --- /dev/null
1493 +++ b/drivers/net/ethernet/broadcom/bgmac.h
1494 @@ -0,0 +1,456 @@
1495 +#ifndef _BGMAC_H
1496 +#define _BGMAC_H
1497 +
1498 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1499 +
1500 +#define bgmac_err(bgmac, fmt, ...) \
1501 + dev_err(&(bgmac)->core->dev, fmt, ##__VA_ARGS__)
1502 +#define bgmac_warn(bgmac, fmt, ...) \
1503 + dev_warn(&(bgmac)->core->dev, fmt, ##__VA_ARGS__)
1504 +#define bgmac_info(bgmac, fmt, ...) \
1505 + dev_info(&(bgmac)->core->dev, fmt, ##__VA_ARGS__)
1506 +#define bgmac_dbg(bgmac, fmt, ...) \
1507 + dev_dbg(&(bgmac)->core->dev, fmt, ##__VA_ARGS__)
1508 +
1509 +#include <linux/bcma/bcma.h>
1510 +#include <linux/netdevice.h>
1511 +
1512 +#define BGMAC_DEV_CTL 0x000
1513 +#define BGMAC_DC_TSM 0x00000002
1514 +#define BGMAC_DC_CFCO 0x00000004
1515 +#define BGMAC_DC_RLSS 0x00000008
1516 +#define BGMAC_DC_MROR 0x00000010
1517 +#define BGMAC_DC_FCM_MASK 0x00000060
1518 +#define BGMAC_DC_FCM_SHIFT 5
1519 +#define BGMAC_DC_NAE 0x00000080
1520 +#define BGMAC_DC_TF 0x00000100
1521 +#define BGMAC_DC_RDS_MASK 0x00030000
1522 +#define BGMAC_DC_RDS_SHIFT 16
1523 +#define BGMAC_DC_TDS_MASK 0x000c0000
1524 +#define BGMAC_DC_TDS_SHIFT 18
1525 +#define BGMAC_DEV_STATUS 0x004 /* Configuration of the interface */
1526 +#define BGMAC_DS_RBF 0x00000001
1527 +#define BGMAC_DS_RDF 0x00000002
1528 +#define BGMAC_DS_RIF 0x00000004
1529 +#define BGMAC_DS_TBF 0x00000008
1530 +#define BGMAC_DS_TDF 0x00000010
1531 +#define BGMAC_DS_TIF 0x00000020
1532 +#define BGMAC_DS_PO 0x00000040
1533 +#define BGMAC_DS_MM_MASK 0x00000300 /* Mode of the interface */
1534 +#define BGMAC_DS_MM_SHIFT 8
1535 +#define BGMAC_BIST_STATUS 0x00c
1536 +#define BGMAC_INT_STATUS 0x020 /* Interrupt status */
1537 +#define BGMAC_IS_MRO 0x00000001
1538 +#define BGMAC_IS_MTO 0x00000002
1539 +#define BGMAC_IS_TFD 0x00000004
1540 +#define BGMAC_IS_LS 0x00000008
1541 +#define BGMAC_IS_MDIO 0x00000010
1542 +#define BGMAC_IS_MR 0x00000020
1543 +#define BGMAC_IS_MT 0x00000040
1544 +#define BGMAC_IS_TO 0x00000080
1545 +#define BGMAC_IS_DESC_ERR 0x00000400 /* Descriptor error */
1546 +#define BGMAC_IS_DATA_ERR 0x00000800 /* Data error */
1547 +#define BGMAC_IS_DESC_PROT_ERR 0x00001000 /* Descriptor protocol error */
1548 +#define BGMAC_IS_RX_DESC_UNDERF 0x00002000 /* Receive descriptor underflow */
1549 +#define BGMAC_IS_RX_F_OVERF 0x00004000 /* Receive FIFO overflow */
1550 +#define BGMAC_IS_TX_F_UNDERF 0x00008000 /* Transmit FIFO underflow */
1551 +#define BGMAC_IS_RX 0x00010000 /* Interrupt for RX queue 0 */
1552 +#define BGMAC_IS_TX0 0x01000000 /* Interrupt for TX queue 0 */
1553 +#define BGMAC_IS_TX1 0x02000000 /* Interrupt for TX queue 1 */
1554 +#define BGMAC_IS_TX2 0x04000000 /* Interrupt for TX queue 2 */
1555 +#define BGMAC_IS_TX3 0x08000000 /* Interrupt for TX queue 3 */
1556 +#define BGMAC_IS_TX_MASK 0x0f000000
1557 +#define BGMAC_IS_INTMASK 0x0f01fcff
1558 +#define BGMAC_IS_ERRMASK 0x0000fc00
1559 +#define BGMAC_INT_MASK 0x024 /* Interrupt mask */
1560 +#define BGMAC_GP_TIMER 0x028
1561 +#define BGMAC_INT_RECV_LAZY 0x100
1562 +#define BGMAC_IRL_TO_MASK 0x00ffffff
1563 +#define BGMAC_IRL_FC_MASK 0xff000000
1564 +#define BGMAC_IRL_FC_SHIFT 24 /* Shift the number of interrupts triggered per received frame */
1565 +#define BGMAC_FLOW_CTL_THRESH 0x104 /* Flow control thresholds */
1566 +#define BGMAC_WRRTHRESH 0x108
1567 +#define BGMAC_GMAC_IDLE_CNT_THRESH 0x10c
1568 +#define BGMAC_PHY_ACCESS 0x180 /* PHY access address */
1569 +#define BGMAC_PA_DATA_MASK 0x0000ffff
1570 +#define BGMAC_PA_ADDR_MASK 0x001f0000
1571 +#define BGMAC_PA_ADDR_SHIFT 16
1572 +#define BGMAC_PA_REG_MASK 0x1f000000
1573 +#define BGMAC_PA_REG_SHIFT 24
1574 +#define BGMAC_PA_WRITE 0x20000000
1575 +#define BGMAC_PA_START 0x40000000
1576 +#define BGMAC_PHY_CNTL 0x188 /* PHY control address */
1577 +#define BGMAC_PC_EPA_MASK 0x0000001f
1578 +#define BGMAC_PC_MCT_MASK 0x007f0000
1579 +#define BGMAC_PC_MCT_SHIFT 16
1580 +#define BGMAC_PC_MTE 0x00800000
1581 +#define BGMAC_TXQ_CTL 0x18c
1582 +#define BGMAC_TXQ_CTL_DBT_MASK 0x00000fff
1583 +#define BGMAC_TXQ_CTL_DBT_SHIFT 0
1584 +#define BGMAC_RXQ_CTL 0x190
1585 +#define BGMAC_RXQ_CTL_DBT_MASK 0x00000fff
1586 +#define BGMAC_RXQ_CTL_DBT_SHIFT 0
1587 +#define BGMAC_RXQ_CTL_PTE 0x00001000
1588 +#define BGMAC_RXQ_CTL_MDP_MASK 0x3f000000
1589 +#define BGMAC_RXQ_CTL_MDP_SHIFT 24
1590 +#define BGMAC_GPIO_SELECT 0x194
1591 +#define BGMAC_GPIO_OUTPUT_EN 0x198
1592 +/* For 0x1e0 see BCMA_CLKCTLST */
1593 +#define BGMAC_HW_WAR 0x1e4
1594 +#define BGMAC_PWR_CTL 0x1e8
1595 +#define BGMAC_DMA_BASE0 0x200 /* Tx and Rx controller */
1596 +#define BGMAC_DMA_BASE1 0x240 /* Tx controller only */
1597 +#define BGMAC_DMA_BASE2 0x280 /* Tx controller only */
1598 +#define BGMAC_DMA_BASE3 0x2C0 /* Tx controller only */
1599 +#define BGMAC_TX_GOOD_OCTETS 0x300
1600 +#define BGMAC_TX_GOOD_OCTETS_HIGH 0x304
1601 +#define BGMAC_TX_GOOD_PKTS 0x308
1602 +#define BGMAC_TX_OCTETS 0x30c
1603 +#define BGMAC_TX_OCTETS_HIGH 0x310
1604 +#define BGMAC_TX_PKTS 0x314
1605 +#define BGMAC_TX_BROADCAST_PKTS 0x318
1606 +#define BGMAC_TX_MULTICAST_PKTS 0x31c
1607 +#define BGMAC_TX_LEN_64 0x320
1608 +#define BGMAC_TX_LEN_65_TO_127 0x324
1609 +#define BGMAC_TX_LEN_128_TO_255 0x328
1610 +#define BGMAC_TX_LEN_256_TO_511 0x32c
1611 +#define BGMAC_TX_LEN_512_TO_1023 0x330
1612 +#define BGMAC_TX_LEN_1024_TO_1522 0x334
1613 +#define BGMAC_TX_LEN_1523_TO_2047 0x338
1614 +#define BGMAC_TX_LEN_2048_TO_4095 0x33c
1615 +#define BGMAC_TX_LEN_4095_TO_8191 0x340
1616 +#define BGMAC_TX_LEN_8192_TO_MAX 0x344
1617 +#define BGMAC_TX_JABBER_PKTS 0x348 /* Error */
1618 +#define BGMAC_TX_OVERSIZE_PKTS 0x34c /* Error */
1619 +#define BGMAC_TX_FRAGMENT_PKTS 0x350
1620 +#define BGMAC_TX_UNDERRUNS 0x354 /* Error */
1621 +#define BGMAC_TX_TOTAL_COLS 0x358
1622 +#define BGMAC_TX_SINGLE_COLS 0x35c
1623 +#define BGMAC_TX_MULTIPLE_COLS 0x360
1624 +#define BGMAC_TX_EXCESSIVE_COLS 0x364 /* Error */
1625 +#define BGMAC_TX_LATE_COLS 0x368 /* Error */
1626 +#define BGMAC_TX_DEFERED 0x36c
1627 +#define BGMAC_TX_CARRIER_LOST 0x370
1628 +#define BGMAC_TX_PAUSE_PKTS 0x374
1629 +#define BGMAC_TX_UNI_PKTS 0x378
1630 +#define BGMAC_TX_Q0_PKTS 0x37c
1631 +#define BGMAC_TX_Q0_OCTETS 0x380
1632 +#define BGMAC_TX_Q0_OCTETS_HIGH 0x384
1633 +#define BGMAC_TX_Q1_PKTS 0x388
1634 +#define BGMAC_TX_Q1_OCTETS 0x38c
1635 +#define BGMAC_TX_Q1_OCTETS_HIGH 0x390
1636 +#define BGMAC_TX_Q2_PKTS 0x394
1637 +#define BGMAC_TX_Q2_OCTETS 0x398
1638 +#define BGMAC_TX_Q2_OCTETS_HIGH 0x39c
1639 +#define BGMAC_TX_Q3_PKTS 0x3a0
1640 +#define BGMAC_TX_Q3_OCTETS 0x3a4
1641 +#define BGMAC_TX_Q3_OCTETS_HIGH 0x3a8
1642 +#define BGMAC_RX_GOOD_OCTETS 0x3b0
1643 +#define BGMAC_RX_GOOD_OCTETS_HIGH 0x3b4
1644 +#define BGMAC_RX_GOOD_PKTS 0x3b8
1645 +#define BGMAC_RX_OCTETS 0x3bc
1646 +#define BGMAC_RX_OCTETS_HIGH 0x3c0
1647 +#define BGMAC_RX_PKTS 0x3c4
1648 +#define BGMAC_RX_BROADCAST_PKTS 0x3c8
1649 +#define BGMAC_RX_MULTICAST_PKTS 0x3cc
1650 +#define BGMAC_RX_LEN_64 0x3d0
1651 +#define BGMAC_RX_LEN_65_TO_127 0x3d4
1652 +#define BGMAC_RX_LEN_128_TO_255 0x3d8
1653 +#define BGMAC_RX_LEN_256_TO_511 0x3dc
1654 +#define BGMAC_RX_LEN_512_TO_1023 0x3e0
1655 +#define BGMAC_RX_LEN_1024_TO_1522 0x3e4
1656 +#define BGMAC_RX_LEN_1523_TO_2047 0x3e8
1657 +#define BGMAC_RX_LEN_2048_TO_4095 0x3ec
1658 +#define BGMAC_RX_LEN_4095_TO_8191 0x3f0
1659 +#define BGMAC_RX_LEN_8192_TO_MAX 0x3f4
1660 +#define BGMAC_RX_JABBER_PKTS 0x3f8 /* Error */
1661 +#define BGMAC_RX_OVERSIZE_PKTS 0x3fc /* Error */
1662 +#define BGMAC_RX_FRAGMENT_PKTS 0x400
1663 +#define BGMAC_RX_MISSED_PKTS 0x404 /* Error */
1664 +#define BGMAC_RX_CRC_ALIGN_ERRS 0x408 /* Error */
1665 +#define BGMAC_RX_UNDERSIZE 0x40c /* Error */
1666 +#define BGMAC_RX_CRC_ERRS 0x410 /* Error */
1667 +#define BGMAC_RX_ALIGN_ERRS 0x414 /* Error */
1668 +#define BGMAC_RX_SYMBOL_ERRS 0x418 /* Error */
1669 +#define BGMAC_RX_PAUSE_PKTS 0x41c
1670 +#define BGMAC_RX_NONPAUSE_PKTS 0x420
1671 +#define BGMAC_RX_SACHANGES 0x424
1672 +#define BGMAC_RX_UNI_PKTS 0x428
1673 +#define BGMAC_UNIMAC_VERSION 0x800
1674 +#define BGMAC_HDBKP_CTL 0x804
1675 +#define BGMAC_CMDCFG 0x808 /* Configuration */
1676 +#define BGMAC_CMDCFG_TE 0x00000001 /* Set to activate TX */
1677 +#define BGMAC_CMDCFG_RE 0x00000002 /* Set to activate RX */
1678 +#define BGMAC_CMDCFG_ES_MASK 0x0000000c /* Ethernet speed see gmac_speed */
1679 +#define BGMAC_CMDCFG_ES_10 0x00000000
1680 +#define BGMAC_CMDCFG_ES_100 0x00000004
1681 +#define BGMAC_CMDCFG_ES_1000 0x00000008
1682 +#define BGMAC_CMDCFG_PROM 0x00000010 /* Set to activate promiscuous mode */
1683 +#define BGMAC_CMDCFG_PAD_EN 0x00000020
1684 +#define BGMAC_CMDCFG_CF 0x00000040
1685 +#define BGMAC_CMDCFG_PF 0x00000080
1686 +#define BGMAC_CMDCFG_RPI 0x00000100 /* Unset to enable 802.3x tx flow control */
1687 +#define BGMAC_CMDCFG_TAI 0x00000200
1688 +#define BGMAC_CMDCFG_HD 0x00000400 /* Set if in half duplex mode */
1689 +#define BGMAC_CMDCFG_HD_SHIFT 10
1690 +#define BGMAC_CMDCFG_SR 0x00000800 /* Set to reset mode */
1691 +#define BGMAC_CMDCFG_ML 0x00008000 /* Set to activate mac loopback mode */
1692 +#define BGMAC_CMDCFG_AE 0x00400000
1693 +#define BGMAC_CMDCFG_CFE 0x00800000
1694 +#define BGMAC_CMDCFG_NLC 0x01000000
1695 +#define BGMAC_CMDCFG_RL 0x02000000
1696 +#define BGMAC_CMDCFG_RED 0x04000000
1697 +#define BGMAC_CMDCFG_PE 0x08000000
1698 +#define BGMAC_CMDCFG_TPI 0x10000000
1699 +#define BGMAC_CMDCFG_AT 0x20000000
1700 +#define BGMAC_MACADDR_HIGH 0x80c /* High 4 octets of own mac address */
1701 +#define BGMAC_MACADDR_LOW 0x810 /* Low 2 octets of own mac address */
1702 +#define BGMAC_RXMAX_LENGTH 0x814 /* Max receive frame length with vlan tag */
1703 +#define BGMAC_PAUSEQUANTA 0x818
1704 +#define BGMAC_MAC_MODE 0x844
1705 +#define BGMAC_OUTERTAG 0x848
1706 +#define BGMAC_INNERTAG 0x84c
1707 +#define BGMAC_TXIPG 0x85c
1708 +#define BGMAC_PAUSE_CTL 0xb30
1709 +#define BGMAC_TX_FLUSH 0xb34
1710 +#define BGMAC_RX_STATUS 0xb38
1711 +#define BGMAC_TX_STATUS 0xb3c
1712 +
1713 +#define BGMAC_PHY_CTL 0x00
1714 +#define BGMAC_PHY_CTL_SPEED_MSB 0x0040
1715 +#define BGMAC_PHY_CTL_DUPLEX 0x0100 /* duplex mode */
1716 +#define BGMAC_PHY_CTL_RESTART 0x0200 /* restart autonegotiation */
1717 +#define BGMAC_PHY_CTL_ANENAB 0x1000 /* enable autonegotiation */
1718 +#define BGMAC_PHY_CTL_SPEED 0x2000
1719 +#define BGMAC_PHY_CTL_LOOP 0x4000 /* loopback */
1720 +#define BGMAC_PHY_CTL_RESET 0x8000 /* reset */
1721 +/* Helpers */
1722 +#define BGMAC_PHY_CTL_SPEED_10 0
1723 +#define BGMAC_PHY_CTL_SPEED_100 BGMAC_PHY_CTL_SPEED
1724 +#define BGMAC_PHY_CTL_SPEED_1000 BGMAC_PHY_CTL_SPEED_MSB
1725 +#define BGMAC_PHY_ADV 0x04
1726 +#define BGMAC_PHY_ADV_10HALF 0x0020 /* advertise 10MBits/s half duplex */
1727 +#define BGMAC_PHY_ADV_10FULL 0x0040 /* advertise 10MBits/s full duplex */
1728 +#define BGMAC_PHY_ADV_100HALF 0x0080 /* advertise 100MBits/s half duplex */
1729 +#define BGMAC_PHY_ADV_100FULL 0x0100 /* advertise 100MBits/s full duplex */
1730 +#define BGMAC_PHY_ADV2 0x09
1731 +#define BGMAC_PHY_ADV2_1000HALF 0x0100 /* advertise 1000MBits/s half duplex */
1732 +#define BGMAC_PHY_ADV2_1000FULL 0x0200 /* advertise 1000MBits/s full duplex */
1733 +
1734 +/* BCMA GMAC core specific IO Control (BCMA_IOCTL) flags */
1735 +#define BGMAC_BCMA_IOCTL_SW_CLKEN 0x00000004 /* PHY Clock Enable */
1736 +#define BGMAC_BCMA_IOCTL_SW_RESET 0x00000008 /* PHY Reset */
1737 +
1738 +/* BCMA GMAC core specific IO status (BCMA_IOST) flags */
1739 +#define BGMAC_BCMA_IOST_ATTACHED 0x00000800
1740 +
1741 +#define BGMAC_NUM_MIB_TX_REGS \
1742 + (((BGMAC_TX_Q3_OCTETS_HIGH - BGMAC_TX_GOOD_OCTETS) / 4) + 1)
1743 +#define BGMAC_NUM_MIB_RX_REGS \
1744 + (((BGMAC_RX_UNI_PKTS - BGMAC_RX_GOOD_OCTETS) / 4) + 1)
1745 +
1746 +#define BGMAC_DMA_TX_CTL 0x00
1747 +#define BGMAC_DMA_TX_ENABLE 0x00000001
1748 +#define BGMAC_DMA_TX_SUSPEND 0x00000002
1749 +#define BGMAC_DMA_TX_LOOPBACK 0x00000004
1750 +#define BGMAC_DMA_TX_FLUSH 0x00000010
1751 +#define BGMAC_DMA_TX_PARITY_DISABLE 0x00000800
1752 +#define BGMAC_DMA_TX_ADDREXT_MASK 0x00030000
1753 +#define BGMAC_DMA_TX_ADDREXT_SHIFT 16
1754 +#define BGMAC_DMA_TX_INDEX 0x04
1755 +#define BGMAC_DMA_TX_RINGLO 0x08
1756 +#define BGMAC_DMA_TX_RINGHI 0x0C
1757 +#define BGMAC_DMA_TX_STATUS 0x10
1758 +#define BGMAC_DMA_TX_STATDPTR 0x00001FFF
1759 +#define BGMAC_DMA_TX_STAT 0xF0000000
1760 +#define BGMAC_DMA_TX_STAT_DISABLED 0x00000000
1761 +#define BGMAC_DMA_TX_STAT_ACTIVE 0x10000000
1762 +#define BGMAC_DMA_TX_STAT_IDLEWAIT 0x20000000
1763 +#define BGMAC_DMA_TX_STAT_STOPPED 0x30000000
1764 +#define BGMAC_DMA_TX_STAT_SUSP 0x40000000
1765 +#define BGMAC_DMA_TX_ERROR 0x14
1766 +#define BGMAC_DMA_TX_ERRDPTR 0x0001FFFF
1767 +#define BGMAC_DMA_TX_ERR 0xF0000000
1768 +#define BGMAC_DMA_TX_ERR_NOERR 0x00000000
1769 +#define BGMAC_DMA_TX_ERR_PROT 0x10000000
1770 +#define BGMAC_DMA_TX_ERR_UNDERRUN 0x20000000
1771 +#define BGMAC_DMA_TX_ERR_TRANSFER 0x30000000
1772 +#define BGMAC_DMA_TX_ERR_DESCREAD 0x40000000
1773 +#define BGMAC_DMA_TX_ERR_CORE 0x50000000
1774 +#define BGMAC_DMA_RX_CTL 0x20
1775 +#define BGMAC_DMA_RX_ENABLE 0x00000001
1776 +#define BGMAC_DMA_RX_FRAME_OFFSET_MASK 0x000000FE
1777 +#define BGMAC_DMA_RX_FRAME_OFFSET_SHIFT 1
1778 +#define BGMAC_DMA_RX_DIRECT_FIFO 0x00000100
1779 +#define BGMAC_DMA_RX_OVERFLOW_CONT 0x00000400
1780 +#define BGMAC_DMA_RX_PARITY_DISABLE 0x00000800
1781 +#define BGMAC_DMA_RX_ADDREXT_MASK 0x00030000
1782 +#define BGMAC_DMA_RX_ADDREXT_SHIFT 16
1783 +#define BGMAC_DMA_RX_INDEX 0x24
1784 +#define BGMAC_DMA_RX_RINGLO 0x28
1785 +#define BGMAC_DMA_RX_RINGHI 0x2C
1786 +#define BGMAC_DMA_RX_STATUS 0x30
1787 +#define BGMAC_DMA_RX_STATDPTR 0x00001FFF
1788 +#define BGMAC_DMA_RX_STAT 0xF0000000
1789 +#define BGMAC_DMA_RX_STAT_DISABLED 0x00000000
1790 +#define BGMAC_DMA_RX_STAT_ACTIVE 0x10000000
1791 +#define BGMAC_DMA_RX_STAT_IDLEWAIT 0x20000000
1792 +#define BGMAC_DMA_RX_STAT_STOPPED 0x30000000
1793 +#define BGMAC_DMA_RX_STAT_SUSP 0x40000000
1794 +#define BGMAC_DMA_RX_ERROR 0x34
1795 +#define BGMAC_DMA_RX_ERRDPTR 0x0001FFFF
1796 +#define BGMAC_DMA_RX_ERR 0xF0000000
1797 +#define BGMAC_DMA_RX_ERR_NOERR 0x00000000
1798 +#define BGMAC_DMA_RX_ERR_PROT 0x10000000
1799 +#define BGMAC_DMA_RX_ERR_UNDERRUN 0x20000000
1800 +#define BGMAC_DMA_RX_ERR_TRANSFER 0x30000000
1801 +#define BGMAC_DMA_RX_ERR_DESCREAD 0x40000000
1802 +#define BGMAC_DMA_RX_ERR_CORE 0x50000000
1803 +
1804 +#define BGMAC_DESC_CTL0_EOT 0x10000000 /* End of ring */
1805 +#define BGMAC_DESC_CTL0_IOC 0x20000000 /* IRQ on complete */
1806 +#define BGMAC_DESC_CTL0_SOF 0x40000000 /* Start of frame */
1807 +#define BGMAC_DESC_CTL0_EOF 0x80000000 /* End of frame */
1808 +#define BGMAC_DESC_CTL1_LEN 0x00001FFF
1809 +
1810 +#define BGMAC_PHY_NOREGS 0x1E
1811 +#define BGMAC_PHY_MASK 0x1F
1812 +
1813 +#define BGMAC_MAX_TX_RINGS 4
1814 +#define BGMAC_MAX_RX_RINGS 1
1815 +
1816 +#define BGMAC_TX_RING_SLOTS 128
1817 +#define BGMAC_RX_RING_SLOTS 512 - 1 /* Why -1? Well, Broadcom does that... */
1818 +
1819 +#define BGMAC_RX_HEADER_LEN 28 /* Last 24 bytes are unused. Well... */
1820 +#define BGMAC_RX_FRAME_OFFSET 30 /* There are 2 unused bytes between header and real data */
1821 +#define BGMAC_RX_MAX_FRAME_SIZE 1536 /* Copied from b44/tg3 */
1822 +#define BGMAC_RX_BUF_SIZE (BGMAC_RX_FRAME_OFFSET + BGMAC_RX_MAX_FRAME_SIZE)
1823 +
1824 +#define BGMAC_BFL_ENETROBO 0x0010 /* has ephy roboswitch spi */
1825 +#define BGMAC_BFL_ENETADM 0x0080 /* has ADMtek switch */
1826 +#define BGMAC_BFL_ENETVLAN 0x0100 /* can do vlan */
1827 +
1828 +#define BGMAC_CHIPCTL_1_IF_TYPE_MASK 0x00000030
1829 +#define BGMAC_CHIPCTL_1_IF_TYPE_RMII 0x00000000
1830 +#define BGMAC_CHIPCTL_1_IF_TYPE_MI 0x00000010
1831 +#define BGMAC_CHIPCTL_1_IF_TYPE_RGMII 0x00000020
1832 +#define BGMAC_CHIPCTL_1_SW_TYPE_MASK 0x000000C0
1833 +#define BGMAC_CHIPCTL_1_SW_TYPE_EPHY 0x00000000
1834 +#define BGMAC_CHIPCTL_1_SW_TYPE_EPHYMII 0x00000040
1835 +#define BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII 0x00000080
1836 +#define BGMAC_CHIPCTL_1_SW_TYPE_RGMI 0x000000C0
1837 +#define BGMAC_CHIPCTL_1_RXC_DLL_BYPASS 0x00010000
1838 +
1839 +#define BGMAC_SPEED_10 0x0001
1840 +#define BGMAC_SPEED_100 0x0002
1841 +#define BGMAC_SPEED_1000 0x0004
1842 +
1843 +#define BGMAC_WEIGHT 64
1844 +
1845 +#define ETHER_MAX_LEN 1518
1846 +
1847 +struct bgmac_slot_info {
1848 + struct sk_buff *skb;
1849 + dma_addr_t dma_addr;
1850 +};
1851 +
1852 +struct bgmac_dma_desc {
1853 + __le32 ctl0;
1854 + __le32 ctl1;
1855 + __le32 addr_low;
1856 + __le32 addr_high;
1857 +} __packed;
1858 +
1859 +enum bgmac_dma_ring_type {
1860 + BGMAC_DMA_RING_TX,
1861 + BGMAC_DMA_RING_RX,
1862 +};
1863 +
1864 +/**
1865 + * bgmac_dma_ring - contains info about DMA ring (either TX or RX one)
1866 + * @start: index of the first slot containing data
1867 + * @end: index of a slot that can *not* be read (yet)
1868 + *
1869 + * Be really aware of the specific @end meaning. It's an index of a slot *after*
1870 + * the one containing data that can be read. If @start equals @end the ring is
1871 + * empty.
1872 + */
1873 +struct bgmac_dma_ring {
1874 + u16 num_slots;
1875 + u16 start;
1876 + u16 end;
1877 +
1878 + u16 mmio_base;
1879 + struct bgmac_dma_desc *cpu_base;
1880 + dma_addr_t dma_base;
1881 +
1882 + struct bgmac_slot_info slots[BGMAC_RX_RING_SLOTS];
1883 +};
1884 +
1885 +struct bgmac_rx_header {
1886 + __le16 len;
1887 + __le16 flags;
1888 + __le16 pad[12];
1889 +};
1890 +
1891 +struct bgmac {
1892 + struct bcma_device *core;
1893 + struct bcma_device *cmn; /* Reference to CMN core for BCM4706 */
1894 + struct net_device *net_dev;
1895 + struct napi_struct napi;
1896 +
1897 + /* DMA */
1898 + struct bgmac_dma_ring tx_ring[BGMAC_MAX_TX_RINGS];
1899 + struct bgmac_dma_ring rx_ring[BGMAC_MAX_RX_RINGS];
1900 +
1901 + /* Stats */
1902 + bool stats_grabbed;
1903 + u32 mib_tx_regs[BGMAC_NUM_MIB_TX_REGS];
1904 + u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS];
1905 +
1906 + /* Int */
1907 + u32 int_mask;
1908 + u32 int_status;
1909 +
1910 + /* Speed-related */
1911 + int speed;
1912 + bool autoneg;
1913 + bool full_duplex;
1914 +
1915 + u8 phyaddr;
1916 + bool has_robosw;
1917 +
1918 + bool loopback;
1919 +};
1920 +
1921 +static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset)
1922 +{
1923 + return bcma_read32(bgmac->core, offset);
1924 +}
1925 +
1926 +static inline void bgmac_write(struct bgmac *bgmac, u16 offset, u32 value)
1927 +{
1928 + bcma_write32(bgmac->core, offset, value);
1929 +}
1930 +
1931 +static inline void bgmac_maskset(struct bgmac *bgmac, u16 offset, u32 mask,
1932 + u32 set)
1933 +{
1934 + bgmac_write(bgmac, offset, (bgmac_read(bgmac, offset) & mask) | set);
1935 +}
1936 +
1937 +static inline void bgmac_mask(struct bgmac *bgmac, u16 offset, u32 mask)
1938 +{
1939 + bgmac_maskset(bgmac, offset, mask, 0);
1940 +}
1941 +
1942 +static inline void bgmac_set(struct bgmac *bgmac, u16 offset, u32 set)
1943 +{
1944 + bgmac_maskset(bgmac, offset, ~0, set);
1945 +}
1946 +
1947 +u16 bgmac_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg);
1948 +void bgmac_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, u16 value);
1949 +
1950 +#endif /* _BGMAC_H */