aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/sunhme.c
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2008-10-13 12:13:56 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2008-10-13 12:13:56 -0400
commite758936e02700ff88a0b08b722a3847b95283ef2 (patch)
tree50c919bef1b459a778b85159d5929de95b6c4a01 /drivers/net/sunhme.c
parent239cfbde1f5843c4a24199f117d5f67f637d72d5 (diff)
parent4480f15b3306f43bbb0310d461142b4e897ca45b (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts: include/asm-x86/statfs.h
Diffstat (limited to 'drivers/net/sunhme.c')
-rw-r--r--drivers/net/sunhme.c322
1 files changed, 128 insertions, 194 deletions
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index b79d5f018f79..f1ebeb5f65b2 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -3,7 +3,7 @@
3 * "Happy Meal Ethernet" found on SunSwift SBUS cards. 3 * "Happy Meal Ethernet" found on SunSwift SBUS cards.
4 * 4 *
5 * Copyright (C) 1996, 1998, 1999, 2002, 2003, 5 * Copyright (C) 1996, 1998, 1999, 2002, 2003,
6 2006 David S. Miller (davem@davemloft.net) 6 * 2006, 2008 David S. Miller (davem@davemloft.net)
7 * 7 *
8 * Changes : 8 * Changes :
9 * 2000/11/11 Willy Tarreau <willy AT meta-x.org> 9 * 2000/11/11 Willy Tarreau <willy AT meta-x.org>
@@ -34,6 +34,7 @@
34#include <linux/skbuff.h> 34#include <linux/skbuff.h>
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include <linux/bitops.h> 36#include <linux/bitops.h>
37#include <linux/dma-mapping.h>
37 38
38#include <asm/system.h> 39#include <asm/system.h>
39#include <asm/io.h> 40#include <asm/io.h>
@@ -41,8 +42,9 @@
41#include <asm/byteorder.h> 42#include <asm/byteorder.h>
42 43
43#ifdef CONFIG_SPARC 44#ifdef CONFIG_SPARC
45#include <linux/of.h>
46#include <linux/of_device.h>
44#include <asm/idprom.h> 47#include <asm/idprom.h>
45#include <asm/sbus.h>
46#include <asm/openprom.h> 48#include <asm/openprom.h>
47#include <asm/oplib.h> 49#include <asm/oplib.h>
48#include <asm/prom.h> 50#include <asm/prom.h>
@@ -60,8 +62,8 @@
60#include "sunhme.h" 62#include "sunhme.h"
61 63
62#define DRV_NAME "sunhme" 64#define DRV_NAME "sunhme"
63#define DRV_VERSION "3.00" 65#define DRV_VERSION "3.10"
64#define DRV_RELDATE "June 23, 2006" 66#define DRV_RELDATE "August 26, 2008"
65#define DRV_AUTHOR "David S. Miller (davem@davemloft.net)" 67#define DRV_AUTHOR "David S. Miller (davem@davemloft.net)"
66 68
67static char version[] = 69static char version[] =
@@ -251,13 +253,13 @@ static u32 pci_hme_read_desc32(hme32 *p)
251#define hme_read_desc32(__hp, __p) \ 253#define hme_read_desc32(__hp, __p) \
252 ((__hp)->read_desc32(__p)) 254 ((__hp)->read_desc32(__p))
253#define hme_dma_map(__hp, __ptr, __size, __dir) \ 255#define hme_dma_map(__hp, __ptr, __size, __dir) \
254 ((__hp)->dma_map((__hp)->happy_dev, (__ptr), (__size), (__dir))) 256 ((__hp)->dma_map((__hp)->dma_dev, (__ptr), (__size), (__dir)))
255#define hme_dma_unmap(__hp, __addr, __size, __dir) \ 257#define hme_dma_unmap(__hp, __addr, __size, __dir) \
256 ((__hp)->dma_unmap((__hp)->happy_dev, (__addr), (__size), (__dir))) 258 ((__hp)->dma_unmap((__hp)->dma_dev, (__addr), (__size), (__dir)))
257#define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \ 259#define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
258 ((__hp)->dma_sync_for_cpu((__hp)->happy_dev, (__addr), (__size), (__dir))) 260 ((__hp)->dma_sync_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir)))
259#define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \ 261#define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
260 ((__hp)->dma_sync_for_device((__hp)->happy_dev, (__addr), (__size), (__dir))) 262 ((__hp)->dma_sync_for_device((__hp)->dma_dev, (__addr), (__size), (__dir)))
261#else 263#else
262#ifdef CONFIG_SBUS 264#ifdef CONFIG_SBUS
263/* SBUS only compilation */ 265/* SBUS only compilation */
@@ -277,13 +279,13 @@ do { (__txd)->tx_addr = (__force hme32)(u32)(__addr); \
277} while(0) 279} while(0)
278#define hme_read_desc32(__hp, __p) ((__force u32)(hme32)*(__p)) 280#define hme_read_desc32(__hp, __p) ((__force u32)(hme32)*(__p))
279#define hme_dma_map(__hp, __ptr, __size, __dir) \ 281#define hme_dma_map(__hp, __ptr, __size, __dir) \
280 sbus_map_single((__hp)->happy_dev, (__ptr), (__size), (__dir)) 282 dma_map_single((__hp)->dma_dev, (__ptr), (__size), (__dir))
281#define hme_dma_unmap(__hp, __addr, __size, __dir) \ 283#define hme_dma_unmap(__hp, __addr, __size, __dir) \
282 sbus_unmap_single((__hp)->happy_dev, (__addr), (__size), (__dir)) 284 dma_unmap_single((__hp)->dma_dev, (__addr), (__size), (__dir))
283#define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \ 285#define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
284 sbus_dma_sync_single_for_cpu((__hp)->happy_dev, (__addr), (__size), (__dir)) 286 dma_dma_sync_single_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir))
285#define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \ 287#define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
286 sbus_dma_sync_single_for_device((__hp)->happy_dev, (__addr), (__size), (__dir)) 288 dma_dma_sync_single_for_device((__hp)->dma_dev, (__addr), (__size), (__dir))
287#else 289#else
288/* PCI only compilation */ 290/* PCI only compilation */
289#define hme_write32(__hp, __reg, __val) \ 291#define hme_write32(__hp, __reg, __val) \
@@ -305,36 +307,17 @@ static inline u32 hme_read_desc32(struct happy_meal *hp, hme32 *p)
305 return le32_to_cpup((__le32 *)p); 307 return le32_to_cpup((__le32 *)p);
306} 308}
307#define hme_dma_map(__hp, __ptr, __size, __dir) \ 309#define hme_dma_map(__hp, __ptr, __size, __dir) \
308 pci_map_single((__hp)->happy_dev, (__ptr), (__size), (__dir)) 310 pci_map_single((__hp)->dma_dev, (__ptr), (__size), (__dir))
309#define hme_dma_unmap(__hp, __addr, __size, __dir) \ 311#define hme_dma_unmap(__hp, __addr, __size, __dir) \
310 pci_unmap_single((__hp)->happy_dev, (__addr), (__size), (__dir)) 312 pci_unmap_single((__hp)->dma_dev, (__addr), (__size), (__dir))
311#define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \ 313#define hme_dma_sync_for_cpu(__hp, __addr, __size, __dir) \
312 pci_dma_sync_single_for_cpu((__hp)->happy_dev, (__addr), (__size), (__dir)) 314 pci_dma_sync_single_for_cpu((__hp)->dma_dev, (__addr), (__size), (__dir))
313#define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \ 315#define hme_dma_sync_for_device(__hp, __addr, __size, __dir) \
314 pci_dma_sync_single_for_device((__hp)->happy_dev, (__addr), (__size), (__dir)) 316 pci_dma_sync_single_for_device((__hp)->dma_dev, (__addr), (__size), (__dir))
315#endif 317#endif
316#endif 318#endif
317 319
318 320
319#ifdef SBUS_DMA_BIDIRECTIONAL
320# define DMA_BIDIRECTIONAL SBUS_DMA_BIDIRECTIONAL
321#else
322# define DMA_BIDIRECTIONAL 0
323#endif
324
325#ifdef SBUS_DMA_FROMDEVICE
326# define DMA_FROMDEVICE SBUS_DMA_FROMDEVICE
327#else
328# define DMA_TODEVICE 1
329#endif
330
331#ifdef SBUS_DMA_TODEVICE
332# define DMA_TODEVICE SBUS_DMA_TODEVICE
333#else
334# define DMA_FROMDEVICE 2
335#endif
336
337
338/* Oh yes, the MIF BitBang is mighty fun to program. BitBucket is more like it. */ 321/* Oh yes, the MIF BitBang is mighty fun to program. BitBucket is more like it. */
339static void BB_PUT_BIT(struct happy_meal *hp, void __iomem *tregs, int bit) 322static void BB_PUT_BIT(struct happy_meal *hp, void __iomem *tregs, int bit)
340{ 323{
@@ -1224,7 +1207,8 @@ static void happy_meal_clean_rings(struct happy_meal *hp)
1224 1207
1225 rxd = &hp->happy_block->happy_meal_rxd[i]; 1208 rxd = &hp->happy_block->happy_meal_rxd[i];
1226 dma_addr = hme_read_desc32(hp, &rxd->rx_addr); 1209 dma_addr = hme_read_desc32(hp, &rxd->rx_addr);
1227 hme_dma_unmap(hp, dma_addr, RX_BUF_ALLOC_SIZE, DMA_FROMDEVICE); 1210 dma_unmap_single(hp->dma_dev, dma_addr,
1211 RX_BUF_ALLOC_SIZE, DMA_FROM_DEVICE);
1228 dev_kfree_skb_any(skb); 1212 dev_kfree_skb_any(skb);
1229 hp->rx_skbs[i] = NULL; 1213 hp->rx_skbs[i] = NULL;
1230 } 1214 }
@@ -1242,10 +1226,10 @@ static void happy_meal_clean_rings(struct happy_meal *hp)
1242 for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) { 1226 for (frag = 0; frag <= skb_shinfo(skb)->nr_frags; frag++) {
1243 txd = &hp->happy_block->happy_meal_txd[i]; 1227 txd = &hp->happy_block->happy_meal_txd[i];
1244 dma_addr = hme_read_desc32(hp, &txd->tx_addr); 1228 dma_addr = hme_read_desc32(hp, &txd->tx_addr);
1245 hme_dma_unmap(hp, dma_addr, 1229 dma_unmap_single(hp->dma_dev, dma_addr,
1246 (hme_read_desc32(hp, &txd->tx_flags) 1230 (hme_read_desc32(hp, &txd->tx_flags)
1247 & TXFLAG_SIZE), 1231 & TXFLAG_SIZE),
1248 DMA_TODEVICE); 1232 DMA_TO_DEVICE);
1249 1233
1250 if (frag != skb_shinfo(skb)->nr_frags) 1234 if (frag != skb_shinfo(skb)->nr_frags)
1251 i++; 1235 i++;
@@ -1287,7 +1271,8 @@ static void happy_meal_init_rings(struct happy_meal *hp)
1287 skb_put(skb, (ETH_FRAME_LEN + RX_OFFSET + 4)); 1271 skb_put(skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
1288 hme_write_rxd(hp, &hb->happy_meal_rxd[i], 1272 hme_write_rxd(hp, &hb->happy_meal_rxd[i],
1289 (RXFLAG_OWN | ((RX_BUF_ALLOC_SIZE - RX_OFFSET) << 16)), 1273 (RXFLAG_OWN | ((RX_BUF_ALLOC_SIZE - RX_OFFSET) << 16)),
1290 hme_dma_map(hp, skb->data, RX_BUF_ALLOC_SIZE, DMA_FROMDEVICE)); 1274 dma_map_single(hp->dma_dev, skb->data, RX_BUF_ALLOC_SIZE,
1275 DMA_FROM_DEVICE));
1291 skb_reserve(skb, RX_OFFSET); 1276 skb_reserve(skb, RX_OFFSET);
1292 } 1277 }
1293 1278
@@ -1593,7 +1578,7 @@ static int happy_meal_init(struct happy_meal *hp)
1593 if ((hp->happy_bursts & DMA_BURST64) && 1578 if ((hp->happy_bursts & DMA_BURST64) &&
1594 ((hp->happy_flags & HFLAG_PCI) != 0 1579 ((hp->happy_flags & HFLAG_PCI) != 0
1595#ifdef CONFIG_SBUS 1580#ifdef CONFIG_SBUS
1596 || sbus_can_burst64(hp->happy_dev) 1581 || sbus_can_burst64()
1597#endif 1582#endif
1598 || 0)) { 1583 || 0)) {
1599 u32 gcfg = GREG_CFG_BURST64; 1584 u32 gcfg = GREG_CFG_BURST64;
@@ -1603,11 +1588,13 @@ static int happy_meal_init(struct happy_meal *hp)
1603 * do not. -DaveM 1588 * do not. -DaveM
1604 */ 1589 */
1605#ifdef CONFIG_SBUS 1590#ifdef CONFIG_SBUS
1606 if ((hp->happy_flags & HFLAG_PCI) == 0 && 1591 if ((hp->happy_flags & HFLAG_PCI) == 0) {
1607 sbus_can_dma_64bit(hp->happy_dev)) { 1592 struct of_device *op = hp->happy_dev;
1608 sbus_set_sbus64(hp->happy_dev, 1593 if (sbus_can_dma_64bit()) {
1609 hp->happy_bursts); 1594 sbus_set_sbus64(&op->dev,
1610 gcfg |= GREG_CFG_64BIT; 1595 hp->happy_bursts);
1596 gcfg |= GREG_CFG_64BIT;
1597 }
1611 } 1598 }
1612#endif 1599#endif
1613 1600
@@ -1966,7 +1953,7 @@ static void happy_meal_tx(struct happy_meal *hp)
1966 dma_len = hme_read_desc32(hp, &this->tx_flags); 1953 dma_len = hme_read_desc32(hp, &this->tx_flags);
1967 1954
1968 dma_len &= TXFLAG_SIZE; 1955 dma_len &= TXFLAG_SIZE;
1969 hme_dma_unmap(hp, dma_addr, dma_len, DMA_TODEVICE); 1956 dma_unmap_single(hp->dma_dev, dma_addr, dma_len, DMA_TO_DEVICE);
1970 1957
1971 elem = NEXT_TX(elem); 1958 elem = NEXT_TX(elem);
1972 this = &txbase[elem]; 1959 this = &txbase[elem];
@@ -2044,13 +2031,14 @@ static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
2044 drops++; 2031 drops++;
2045 goto drop_it; 2032 goto drop_it;
2046 } 2033 }
2047 hme_dma_unmap(hp, dma_addr, RX_BUF_ALLOC_SIZE, DMA_FROMDEVICE); 2034 dma_unmap_single(hp->dma_dev, dma_addr, RX_BUF_ALLOC_SIZE, DMA_FROM_DEVICE);
2048 hp->rx_skbs[elem] = new_skb; 2035 hp->rx_skbs[elem] = new_skb;
2049 new_skb->dev = dev; 2036 new_skb->dev = dev;
2050 skb_put(new_skb, (ETH_FRAME_LEN + RX_OFFSET + 4)); 2037 skb_put(new_skb, (ETH_FRAME_LEN + RX_OFFSET + 4));
2051 hme_write_rxd(hp, this, 2038 hme_write_rxd(hp, this,
2052 (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)), 2039 (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
2053 hme_dma_map(hp, new_skb->data, RX_BUF_ALLOC_SIZE, DMA_FROMDEVICE)); 2040 dma_map_single(hp->dma_dev, new_skb->data, RX_BUF_ALLOC_SIZE,
2041 DMA_FROM_DEVICE));
2054 skb_reserve(new_skb, RX_OFFSET); 2042 skb_reserve(new_skb, RX_OFFSET);
2055 2043
2056 /* Trim the original skb for the netif. */ 2044 /* Trim the original skb for the netif. */
@@ -2065,10 +2053,9 @@ static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
2065 2053
2066 skb_reserve(copy_skb, 2); 2054 skb_reserve(copy_skb, 2);
2067 skb_put(copy_skb, len); 2055 skb_put(copy_skb, len);
2068 hme_dma_sync_for_cpu(hp, dma_addr, len, DMA_FROMDEVICE); 2056 dma_sync_single_for_cpu(hp->dma_dev, dma_addr, len, DMA_FROM_DEVICE);
2069 skb_copy_from_linear_data(skb, copy_skb->data, len); 2057 skb_copy_from_linear_data(skb, copy_skb->data, len);
2070 hme_dma_sync_for_device(hp, dma_addr, len, DMA_FROMDEVICE); 2058 dma_sync_single_for_device(hp->dma_dev, dma_addr, len, DMA_FROM_DEVICE);
2071
2072 /* Reuse original ring buffer. */ 2059 /* Reuse original ring buffer. */
2073 hme_write_rxd(hp, this, 2060 hme_write_rxd(hp, this,
2074 (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)), 2061 (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
@@ -2300,7 +2287,7 @@ static int happy_meal_start_xmit(struct sk_buff *skb, struct net_device *dev)
2300 u32 mapping, len; 2287 u32 mapping, len;
2301 2288
2302 len = skb->len; 2289 len = skb->len;
2303 mapping = hme_dma_map(hp, skb->data, len, DMA_TODEVICE); 2290 mapping = dma_map_single(hp->dma_dev, skb->data, len, DMA_TO_DEVICE);
2304 tx_flags |= (TXFLAG_SOP | TXFLAG_EOP); 2291 tx_flags |= (TXFLAG_SOP | TXFLAG_EOP);
2305 hme_write_txd(hp, &hp->happy_block->happy_meal_txd[entry], 2292 hme_write_txd(hp, &hp->happy_block->happy_meal_txd[entry],
2306 (tx_flags | (len & TXFLAG_SIZE)), 2293 (tx_flags | (len & TXFLAG_SIZE)),
@@ -2314,7 +2301,8 @@ static int happy_meal_start_xmit(struct sk_buff *skb, struct net_device *dev)
2314 * Otherwise we could race with the device. 2301 * Otherwise we could race with the device.
2315 */ 2302 */
2316 first_len = skb_headlen(skb); 2303 first_len = skb_headlen(skb);
2317 first_mapping = hme_dma_map(hp, skb->data, first_len, DMA_TODEVICE); 2304 first_mapping = dma_map_single(hp->dma_dev, skb->data, first_len,
2305 DMA_TO_DEVICE);
2318 entry = NEXT_TX(entry); 2306 entry = NEXT_TX(entry);
2319 2307
2320 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) { 2308 for (frag = 0; frag < skb_shinfo(skb)->nr_frags; frag++) {
@@ -2322,10 +2310,9 @@ static int happy_meal_start_xmit(struct sk_buff *skb, struct net_device *dev)
2322 u32 len, mapping, this_txflags; 2310 u32 len, mapping, this_txflags;
2323 2311
2324 len = this_frag->size; 2312 len = this_frag->size;
2325 mapping = hme_dma_map(hp, 2313 mapping = dma_map_page(hp->dma_dev, this_frag->page,
2326 ((void *) page_address(this_frag->page) + 2314 this_frag->page_offset, len,
2327 this_frag->page_offset), 2315 DMA_TO_DEVICE);
2328 len, DMA_TODEVICE);
2329 this_txflags = tx_flags; 2316 this_txflags = tx_flags;
2330 if (frag == skb_shinfo(skb)->nr_frags - 1) 2317 if (frag == skb_shinfo(skb)->nr_frags - 1)
2331 this_txflags |= TXFLAG_EOP; 2318 this_txflags |= TXFLAG_EOP;
@@ -2493,9 +2480,12 @@ static void hme_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
2493 } 2480 }
2494#ifdef CONFIG_SBUS 2481#ifdef CONFIG_SBUS
2495 else { 2482 else {
2496 struct sbus_dev *sdev = hp->happy_dev; 2483 const struct linux_prom_registers *regs;
2497 sprintf(info->bus_info, "SBUS:%d", 2484 struct of_device *op = hp->happy_dev;
2498 sdev->slot); 2485 regs = of_get_property(op->node, "regs", NULL);
2486 if (regs)
2487 sprintf(info->bus_info, "SBUS:%d",
2488 regs->which_io);
2499 } 2489 }
2500#endif 2490#endif
2501} 2491}
@@ -2521,63 +2511,21 @@ static const struct ethtool_ops hme_ethtool_ops = {
2521static int hme_version_printed; 2511static int hme_version_printed;
2522 2512
2523#ifdef CONFIG_SBUS 2513#ifdef CONFIG_SBUS
2524void __devinit quattro_get_ranges(struct quattro *qp)
2525{
2526 struct sbus_dev *sdev = qp->quattro_dev;
2527 int err;
2528
2529 err = prom_getproperty(sdev->prom_node,
2530 "ranges",
2531 (char *)&qp->ranges[0],
2532 sizeof(qp->ranges));
2533 if (err == 0 || err == -1) {
2534 qp->nranges = 0;
2535 return;
2536 }
2537 qp->nranges = (err / sizeof(struct linux_prom_ranges));
2538}
2539
2540static void __devinit quattro_apply_ranges(struct quattro *qp, struct happy_meal *hp)
2541{
2542 struct sbus_dev *sdev = hp->happy_dev;
2543 int rng;
2544
2545 for (rng = 0; rng < qp->nranges; rng++) {
2546 struct linux_prom_ranges *rngp = &qp->ranges[rng];
2547 int reg;
2548
2549 for (reg = 0; reg < 5; reg++) {
2550 if (sdev->reg_addrs[reg].which_io ==
2551 rngp->ot_child_space)
2552 break;
2553 }
2554 if (reg == 5)
2555 continue;
2556
2557 sdev->reg_addrs[reg].which_io = rngp->ot_parent_space;
2558 sdev->reg_addrs[reg].phys_addr += rngp->ot_parent_base;
2559 }
2560}
2561
2562/* Given a happy meal sbus device, find it's quattro parent. 2514/* Given a happy meal sbus device, find it's quattro parent.
2563 * If none exist, allocate and return a new one. 2515 * If none exist, allocate and return a new one.
2564 * 2516 *
2565 * Return NULL on failure. 2517 * Return NULL on failure.
2566 */ 2518 */
2567static struct quattro * __devinit quattro_sbus_find(struct sbus_dev *goal_sdev) 2519static struct quattro * __devinit quattro_sbus_find(struct of_device *child)
2568{ 2520{
2569 struct sbus_dev *sdev; 2521 struct device *parent = child->dev.parent;
2522 struct of_device *op;
2570 struct quattro *qp; 2523 struct quattro *qp;
2571 int i;
2572 2524
2573 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2525 op = to_of_device(parent);
2574 for (i = 0, sdev = qp->quattro_dev; 2526 qp = dev_get_drvdata(&op->dev);
2575 (sdev != NULL) && (i < 4); 2527 if (qp)
2576 sdev = sdev->next, i++) { 2528 return qp;
2577 if (sdev == goal_sdev)
2578 return qp;
2579 }
2580 }
2581 2529
2582 qp = kmalloc(sizeof(struct quattro), GFP_KERNEL); 2530 qp = kmalloc(sizeof(struct quattro), GFP_KERNEL);
2583 if (qp != NULL) { 2531 if (qp != NULL) {
@@ -2586,10 +2534,11 @@ static struct quattro * __devinit quattro_sbus_find(struct sbus_dev *goal_sdev)
2586 for (i = 0; i < 4; i++) 2534 for (i = 0; i < 4; i++)
2587 qp->happy_meals[i] = NULL; 2535 qp->happy_meals[i] = NULL;
2588 2536
2589 qp->quattro_dev = goal_sdev; 2537 qp->quattro_dev = child;
2590 qp->next = qfe_sbus_list; 2538 qp->next = qfe_sbus_list;
2591 qfe_sbus_list = qp; 2539 qfe_sbus_list = qp;
2592 quattro_get_ranges(qp); 2540
2541 dev_set_drvdata(&op->dev, qp);
2593 } 2542 }
2594 return qp; 2543 return qp;
2595} 2544}
@@ -2602,10 +2551,10 @@ static void __init quattro_sbus_register_irqs(void)
2602 struct quattro *qp; 2551 struct quattro *qp;
2603 2552
2604 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2553 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2605 struct sbus_dev *sdev = qp->quattro_dev; 2554 struct of_device *op = qp->quattro_dev;
2606 int err; 2555 int err;
2607 2556
2608 err = request_irq(sdev->irqs[0], 2557 err = request_irq(op->irqs[0],
2609 quattro_sbus_interrupt, 2558 quattro_sbus_interrupt,
2610 IRQF_SHARED, "Quattro", 2559 IRQF_SHARED, "Quattro",
2611 qp); 2560 qp);
@@ -2621,9 +2570,9 @@ static void quattro_sbus_free_irqs(void)
2621 struct quattro *qp; 2570 struct quattro *qp;
2622 2571
2623 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) { 2572 for (qp = qfe_sbus_list; qp != NULL; qp = qp->next) {
2624 struct sbus_dev *sdev = qp->quattro_dev; 2573 struct of_device *op = qp->quattro_dev;
2625 2574
2626 free_irq(sdev->irqs[0], qp); 2575 free_irq(op->irqs[0], qp);
2627 } 2576 }
2628} 2577}
2629#endif /* CONFIG_SBUS */ 2578#endif /* CONFIG_SBUS */
@@ -2660,9 +2609,9 @@ static struct quattro * __devinit quattro_pci_find(struct pci_dev *pdev)
2660#endif /* CONFIG_PCI */ 2609#endif /* CONFIG_PCI */
2661 2610
2662#ifdef CONFIG_SBUS 2611#ifdef CONFIG_SBUS
2663static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe) 2612static int __devinit happy_meal_sbus_probe_one(struct of_device *op, int is_qfe)
2664{ 2613{
2665 struct device_node *dp = sdev->ofdev.node; 2614 struct device_node *dp = op->node, *sbus_dp;
2666 struct quattro *qp = NULL; 2615 struct quattro *qp = NULL;
2667 struct happy_meal *hp; 2616 struct happy_meal *hp;
2668 struct net_device *dev; 2617 struct net_device *dev;
@@ -2671,7 +2620,7 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2671 DECLARE_MAC_BUF(mac); 2620 DECLARE_MAC_BUF(mac);
2672 2621
2673 if (is_qfe) { 2622 if (is_qfe) {
2674 qp = quattro_sbus_find(sdev); 2623 qp = quattro_sbus_find(op);
2675 if (qp == NULL) 2624 if (qp == NULL)
2676 goto err_out; 2625 goto err_out;
2677 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++) 2626 for (qfe_slot = 0; qfe_slot < 4; qfe_slot++)
@@ -2685,7 +2634,7 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2685 dev = alloc_etherdev(sizeof(struct happy_meal)); 2634 dev = alloc_etherdev(sizeof(struct happy_meal));
2686 if (!dev) 2635 if (!dev)
2687 goto err_out; 2636 goto err_out;
2688 SET_NETDEV_DEV(dev, &sdev->ofdev.dev); 2637 SET_NETDEV_DEV(dev, &op->dev);
2689 2638
2690 if (hme_version_printed++ == 0) 2639 if (hme_version_printed++ == 0)
2691 printk(KERN_INFO "%s", version); 2640 printk(KERN_INFO "%s", version);
@@ -2713,56 +2662,50 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2713 memcpy(dev->dev_addr, idprom->id_ethaddr, 6); 2662 memcpy(dev->dev_addr, idprom->id_ethaddr, 6);
2714 } 2663 }
2715 2664
2716 hp = dev->priv; 2665 hp = netdev_priv(dev);
2717 2666
2718 hp->happy_dev = sdev; 2667 hp->happy_dev = op;
2668 hp->dma_dev = &op->dev;
2719 2669
2720 spin_lock_init(&hp->happy_lock); 2670 spin_lock_init(&hp->happy_lock);
2721 2671
2722 err = -ENODEV; 2672 err = -ENODEV;
2723 if (sdev->num_registers != 5) {
2724 printk(KERN_ERR "happymeal: Device needs 5 regs, has %d.\n",
2725 sdev->num_registers);
2726 goto err_out_free_netdev;
2727 }
2728
2729 if (qp != NULL) { 2673 if (qp != NULL) {
2730 hp->qfe_parent = qp; 2674 hp->qfe_parent = qp;
2731 hp->qfe_ent = qfe_slot; 2675 hp->qfe_ent = qfe_slot;
2732 qp->happy_meals[qfe_slot] = dev; 2676 qp->happy_meals[qfe_slot] = dev;
2733 quattro_apply_ranges(qp, hp);
2734 } 2677 }
2735 2678
2736 hp->gregs = sbus_ioremap(&sdev->resource[0], 0, 2679 hp->gregs = of_ioremap(&op->resource[0], 0,
2737 GREG_REG_SIZE, "HME Global Regs"); 2680 GREG_REG_SIZE, "HME Global Regs");
2738 if (!hp->gregs) { 2681 if (!hp->gregs) {
2739 printk(KERN_ERR "happymeal: Cannot map global registers.\n"); 2682 printk(KERN_ERR "happymeal: Cannot map global registers.\n");
2740 goto err_out_free_netdev; 2683 goto err_out_free_netdev;
2741 } 2684 }
2742 2685
2743 hp->etxregs = sbus_ioremap(&sdev->resource[1], 0, 2686 hp->etxregs = of_ioremap(&op->resource[1], 0,
2744 ETX_REG_SIZE, "HME TX Regs"); 2687 ETX_REG_SIZE, "HME TX Regs");
2745 if (!hp->etxregs) { 2688 if (!hp->etxregs) {
2746 printk(KERN_ERR "happymeal: Cannot map MAC TX registers.\n"); 2689 printk(KERN_ERR "happymeal: Cannot map MAC TX registers.\n");
2747 goto err_out_iounmap; 2690 goto err_out_iounmap;
2748 } 2691 }
2749 2692
2750 hp->erxregs = sbus_ioremap(&sdev->resource[2], 0, 2693 hp->erxregs = of_ioremap(&op->resource[2], 0,
2751 ERX_REG_SIZE, "HME RX Regs"); 2694 ERX_REG_SIZE, "HME RX Regs");
2752 if (!hp->erxregs) { 2695 if (!hp->erxregs) {
2753 printk(KERN_ERR "happymeal: Cannot map MAC RX registers.\n"); 2696 printk(KERN_ERR "happymeal: Cannot map MAC RX registers.\n");
2754 goto err_out_iounmap; 2697 goto err_out_iounmap;
2755 } 2698 }
2756 2699
2757 hp->bigmacregs = sbus_ioremap(&sdev->resource[3], 0, 2700 hp->bigmacregs = of_ioremap(&op->resource[3], 0,
2758 BMAC_REG_SIZE, "HME BIGMAC Regs"); 2701 BMAC_REG_SIZE, "HME BIGMAC Regs");
2759 if (!hp->bigmacregs) { 2702 if (!hp->bigmacregs) {
2760 printk(KERN_ERR "happymeal: Cannot map BIGMAC registers.\n"); 2703 printk(KERN_ERR "happymeal: Cannot map BIGMAC registers.\n");
2761 goto err_out_iounmap; 2704 goto err_out_iounmap;
2762 } 2705 }
2763 2706
2764 hp->tcvregs = sbus_ioremap(&sdev->resource[4], 0, 2707 hp->tcvregs = of_ioremap(&op->resource[4], 0,
2765 TCVR_REG_SIZE, "HME Tranceiver Regs"); 2708 TCVR_REG_SIZE, "HME Tranceiver Regs");
2766 if (!hp->tcvregs) { 2709 if (!hp->tcvregs) {
2767 printk(KERN_ERR "happymeal: Cannot map TCVR registers.\n"); 2710 printk(KERN_ERR "happymeal: Cannot map TCVR registers.\n");
2768 goto err_out_iounmap; 2711 goto err_out_iounmap;
@@ -2781,13 +2724,18 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2781 if (qp != NULL) 2724 if (qp != NULL)
2782 hp->happy_flags |= HFLAG_QUATTRO; 2725 hp->happy_flags |= HFLAG_QUATTRO;
2783 2726
2727 sbus_dp = to_of_device(op->dev.parent)->node;
2728 if (is_qfe)
2729 sbus_dp = to_of_device(op->dev.parent->parent)->node;
2730
2784 /* Get the supported DVMA burst sizes from our Happy SBUS. */ 2731 /* Get the supported DVMA burst sizes from our Happy SBUS. */
2785 hp->happy_bursts = of_getintprop_default(sdev->bus->ofdev.node, 2732 hp->happy_bursts = of_getintprop_default(sbus_dp,
2786 "burst-sizes", 0x00); 2733 "burst-sizes", 0x00);
2787 2734
2788 hp->happy_block = sbus_alloc_consistent(hp->happy_dev, 2735 hp->happy_block = dma_alloc_coherent(hp->dma_dev,
2789 PAGE_SIZE, 2736 PAGE_SIZE,
2790 &hp->hblock_dvma); 2737 &hp->hblock_dvma,
2738 GFP_ATOMIC);
2791 err = -ENOMEM; 2739 err = -ENOMEM;
2792 if (!hp->happy_block) { 2740 if (!hp->happy_block) {
2793 printk(KERN_ERR "happymeal: Cannot allocate descriptors.\n"); 2741 printk(KERN_ERR "happymeal: Cannot allocate descriptors.\n");
@@ -2816,19 +2764,13 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2816 /* Happy Meal can do it all... */ 2764 /* Happy Meal can do it all... */
2817 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; 2765 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
2818 2766
2819 dev->irq = sdev->irqs[0]; 2767 dev->irq = op->irqs[0];
2820 2768
2821#if defined(CONFIG_SBUS) && defined(CONFIG_PCI) 2769#if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
2822 /* Hook up PCI register/dma accessors. */ 2770 /* Hook up SBUS register/descriptor accessors. */
2823 hp->read_desc32 = sbus_hme_read_desc32; 2771 hp->read_desc32 = sbus_hme_read_desc32;
2824 hp->write_txd = sbus_hme_write_txd; 2772 hp->write_txd = sbus_hme_write_txd;
2825 hp->write_rxd = sbus_hme_write_rxd; 2773 hp->write_rxd = sbus_hme_write_rxd;
2826 hp->dma_map = (u32 (*)(void *, void *, long, int))sbus_map_single;
2827 hp->dma_unmap = (void (*)(void *, u32, long, int))sbus_unmap_single;
2828 hp->dma_sync_for_cpu = (void (*)(void *, u32, long, int))
2829 sbus_dma_sync_single_for_cpu;
2830 hp->dma_sync_for_device = (void (*)(void *, u32, long, int))
2831 sbus_dma_sync_single_for_device;
2832 hp->read32 = sbus_hme_read32; 2774 hp->read32 = sbus_hme_read32;
2833 hp->write32 = sbus_hme_write32; 2775 hp->write32 = sbus_hme_write32;
2834#endif 2776#endif
@@ -2843,10 +2785,10 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2843 if (register_netdev(hp->dev)) { 2785 if (register_netdev(hp->dev)) {
2844 printk(KERN_ERR "happymeal: Cannot register net device, " 2786 printk(KERN_ERR "happymeal: Cannot register net device, "
2845 "aborting.\n"); 2787 "aborting.\n");
2846 goto err_out_free_consistent; 2788 goto err_out_free_coherent;
2847 } 2789 }
2848 2790
2849 dev_set_drvdata(&sdev->ofdev.dev, hp); 2791 dev_set_drvdata(&op->dev, hp);
2850 2792
2851 if (qfe_slot != -1) 2793 if (qfe_slot != -1)
2852 printk(KERN_INFO "%s: Quattro HME slot %d (SBUS) 10/100baseT Ethernet ", 2794 printk(KERN_INFO "%s: Quattro HME slot %d (SBUS) 10/100baseT Ethernet ",
@@ -2859,23 +2801,23 @@ static int __devinit happy_meal_sbus_probe_one(struct sbus_dev *sdev, int is_qfe
2859 2801
2860 return 0; 2802 return 0;
2861 2803
2862err_out_free_consistent: 2804err_out_free_coherent:
2863 sbus_free_consistent(hp->happy_dev, 2805 dma_free_coherent(hp->dma_dev,
2864 PAGE_SIZE, 2806 PAGE_SIZE,
2865 hp->happy_block, 2807 hp->happy_block,
2866 hp->hblock_dvma); 2808 hp->hblock_dvma);
2867 2809
2868err_out_iounmap: 2810err_out_iounmap:
2869 if (hp->gregs) 2811 if (hp->gregs)
2870 sbus_iounmap(hp->gregs, GREG_REG_SIZE); 2812 of_iounmap(&op->resource[0], hp->gregs, GREG_REG_SIZE);
2871 if (hp->etxregs) 2813 if (hp->etxregs)
2872 sbus_iounmap(hp->etxregs, ETX_REG_SIZE); 2814 of_iounmap(&op->resource[1], hp->etxregs, ETX_REG_SIZE);
2873 if (hp->erxregs) 2815 if (hp->erxregs)
2874 sbus_iounmap(hp->erxregs, ERX_REG_SIZE); 2816 of_iounmap(&op->resource[2], hp->erxregs, ERX_REG_SIZE);
2875 if (hp->bigmacregs) 2817 if (hp->bigmacregs)
2876 sbus_iounmap(hp->bigmacregs, BMAC_REG_SIZE); 2818 of_iounmap(&op->resource[3], hp->bigmacregs, BMAC_REG_SIZE);
2877 if (hp->tcvregs) 2819 if (hp->tcvregs)
2878 sbus_iounmap(hp->tcvregs, TCVR_REG_SIZE); 2820 of_iounmap(&op->resource[4], hp->tcvregs, TCVR_REG_SIZE);
2879 2821
2880err_out_free_netdev: 2822err_out_free_netdev:
2881 free_netdev(dev); 2823 free_netdev(dev);
@@ -3035,6 +2977,7 @@ static int __devinit happy_meal_pci_probe(struct pci_dev *pdev,
3035 memset(hp, 0, sizeof(*hp)); 2977 memset(hp, 0, sizeof(*hp));
3036 2978
3037 hp->happy_dev = pdev; 2979 hp->happy_dev = pdev;
2980 hp->dma_dev = &pdev->dev;
3038 2981
3039 spin_lock_init(&hp->happy_lock); 2982 spin_lock_init(&hp->happy_lock);
3040 2983
@@ -3121,7 +3064,7 @@ static int __devinit happy_meal_pci_probe(struct pci_dev *pdev,
3121#endif 3064#endif
3122 3065
3123 hp->happy_block = (struct hmeal_init_block *) 3066 hp->happy_block = (struct hmeal_init_block *)
3124 pci_alloc_consistent(pdev, PAGE_SIZE, &hp->hblock_dvma); 3067 dma_alloc_coherent(&pdev->dev, PAGE_SIZE, &hp->hblock_dvma, GFP_KERNEL);
3125 3068
3126 err = -ENODEV; 3069 err = -ENODEV;
3127 if (!hp->happy_block) { 3070 if (!hp->happy_block) {
@@ -3151,16 +3094,10 @@ static int __devinit happy_meal_pci_probe(struct pci_dev *pdev,
3151 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; 3094 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
3152 3095
3153#if defined(CONFIG_SBUS) && defined(CONFIG_PCI) 3096#if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
3154 /* Hook up PCI register/dma accessors. */ 3097 /* Hook up PCI register/descriptor accessors. */
3155 hp->read_desc32 = pci_hme_read_desc32; 3098 hp->read_desc32 = pci_hme_read_desc32;
3156 hp->write_txd = pci_hme_write_txd; 3099 hp->write_txd = pci_hme_write_txd;
3157 hp->write_rxd = pci_hme_write_rxd; 3100 hp->write_rxd = pci_hme_write_rxd;
3158 hp->dma_map = (u32 (*)(void *, void *, long, int))pci_map_single;
3159 hp->dma_unmap = (void (*)(void *, u32, long, int))pci_unmap_single;
3160 hp->dma_sync_for_cpu = (void (*)(void *, u32, long, int))
3161 pci_dma_sync_single_for_cpu;
3162 hp->dma_sync_for_device = (void (*)(void *, u32, long, int))
3163 pci_dma_sync_single_for_device;
3164 hp->read32 = pci_hme_read32; 3101 hp->read32 = pci_hme_read32;
3165 hp->write32 = pci_hme_write32; 3102 hp->write32 = pci_hme_write32;
3166#endif 3103#endif
@@ -3231,10 +3168,8 @@ static void __devexit happy_meal_pci_remove(struct pci_dev *pdev)
3231 3168
3232 unregister_netdev(net_dev); 3169 unregister_netdev(net_dev);
3233 3170
3234 pci_free_consistent(hp->happy_dev, 3171 dma_free_coherent(hp->dma_dev, PAGE_SIZE,
3235 PAGE_SIZE, 3172 hp->happy_block, hp->hblock_dvma);
3236 hp->happy_block,
3237 hp->hblock_dvma);
3238 iounmap(hp->gregs); 3173 iounmap(hp->gregs);
3239 pci_release_regions(hp->happy_dev); 3174 pci_release_regions(hp->happy_dev);
3240 3175
@@ -3279,46 +3214,45 @@ static void happy_meal_pci_exit(void)
3279#endif 3214#endif
3280 3215
3281#ifdef CONFIG_SBUS 3216#ifdef CONFIG_SBUS
3282static int __devinit hme_sbus_probe(struct of_device *dev, const struct of_device_id *match) 3217static int __devinit hme_sbus_probe(struct of_device *op, const struct of_device_id *match)
3283{ 3218{
3284 struct sbus_dev *sdev = to_sbus_device(&dev->dev); 3219 struct device_node *dp = op->node;
3285 struct device_node *dp = dev->node;
3286 const char *model = of_get_property(dp, "model", NULL); 3220 const char *model = of_get_property(dp, "model", NULL);
3287 int is_qfe = (match->data != NULL); 3221 int is_qfe = (match->data != NULL);
3288 3222
3289 if (!is_qfe && model && !strcmp(model, "SUNW,sbus-qfe")) 3223 if (!is_qfe && model && !strcmp(model, "SUNW,sbus-qfe"))
3290 is_qfe = 1; 3224 is_qfe = 1;
3291 3225
3292 return happy_meal_sbus_probe_one(sdev, is_qfe); 3226 return happy_meal_sbus_probe_one(op, is_qfe);
3293} 3227}
3294 3228
3295static int __devexit hme_sbus_remove(struct of_device *dev) 3229static int __devexit hme_sbus_remove(struct of_device *op)
3296{ 3230{
3297 struct happy_meal *hp = dev_get_drvdata(&dev->dev); 3231 struct happy_meal *hp = dev_get_drvdata(&op->dev);
3298 struct net_device *net_dev = hp->dev; 3232 struct net_device *net_dev = hp->dev;
3299 3233
3300 unregister_netdev(net_dev); 3234 unregister_netdev(net_dev);
3301 3235
3302 /* XXX qfe parent interrupt... */ 3236 /* XXX qfe parent interrupt... */
3303 3237
3304 sbus_iounmap(hp->gregs, GREG_REG_SIZE); 3238 of_iounmap(&op->resource[0], hp->gregs, GREG_REG_SIZE);
3305 sbus_iounmap(hp->etxregs, ETX_REG_SIZE); 3239 of_iounmap(&op->resource[1], hp->etxregs, ETX_REG_SIZE);
3306 sbus_iounmap(hp->erxregs, ERX_REG_SIZE); 3240 of_iounmap(&op->resource[2], hp->erxregs, ERX_REG_SIZE);
3307 sbus_iounmap(hp->bigmacregs, BMAC_REG_SIZE); 3241 of_iounmap(&op->resource[3], hp->bigmacregs, BMAC_REG_SIZE);
3308 sbus_iounmap(hp->tcvregs, TCVR_REG_SIZE); 3242 of_iounmap(&op->resource[4], hp->tcvregs, TCVR_REG_SIZE);
3309 sbus_free_consistent(hp->happy_dev, 3243 dma_free_coherent(hp->dma_dev,
3310 PAGE_SIZE, 3244 PAGE_SIZE,
3311 hp->happy_block, 3245 hp->happy_block,
3312 hp->hblock_dvma); 3246 hp->hblock_dvma);
3313 3247
3314 free_netdev(net_dev); 3248 free_netdev(net_dev);
3315 3249
3316 dev_set_drvdata(&dev->dev, NULL); 3250 dev_set_drvdata(&op->dev, NULL);
3317 3251
3318 return 0; 3252 return 0;
3319} 3253}
3320 3254
3321static struct of_device_id hme_sbus_match[] = { 3255static const struct of_device_id hme_sbus_match[] = {
3322 { 3256 {
3323 .name = "SUNW,hme", 3257 .name = "SUNW,hme",
3324 }, 3258 },
@@ -3346,7 +3280,7 @@ static int __init happy_meal_sbus_init(void)
3346{ 3280{
3347 int err; 3281 int err;
3348 3282
3349 err = of_register_driver(&hme_sbus_driver, &sbus_bus_type); 3283 err = of_register_driver(&hme_sbus_driver, &of_bus_type);
3350 if (!err) 3284 if (!err)
3351 quattro_sbus_register_irqs(); 3285 quattro_sbus_register_irqs();
3352 3286