Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sunbmac: Convert to pure OF driver.

Signed-off-by: David S. Miller <davem@davemloft.net>

+70 -88
+68 -86
drivers/net/sunbmac.c
··· 1 - /* $Id: sunbmac.c,v 1.30 2002/01/15 06:48:55 davem Exp $ 2 - * sunbmac.c: Driver for Sparc BigMAC 100baseT ethernet adapters. 1 + /* sunbmac.c: Driver for Sparc BigMAC 100baseT ethernet adapters. 3 2 * 4 - * Copyright (C) 1997, 1998, 1999, 2003 David S. Miller (davem@redhat.com) 3 + * Copyright (C) 1997, 1998, 1999, 2003, 2008 David S. Miller (davem@davemloft.net) 5 4 */ 6 5 7 6 #include <linux/module.h> ··· 23 24 #include <linux/skbuff.h> 24 25 #include <linux/bitops.h> 25 26 #include <linux/dma-mapping.h> 27 + #include <linux/of.h> 28 + #include <linux/of_device.h> 26 29 27 30 #include <asm/auxio.h> 28 31 #include <asm/byteorder.h> ··· 34 33 #include <asm/openprom.h> 35 34 #include <asm/oplib.h> 36 35 #include <asm/pgtable.h> 37 - #include <asm/sbus.h> 38 36 #include <asm/system.h> 39 37 40 38 #include "sunbmac.h" 41 39 42 40 #define DRV_NAME "sunbmac" 43 - #define DRV_VERSION "2.0" 44 - #define DRV_RELDATE "11/24/03" 45 - #define DRV_AUTHOR "David S. Miller (davem@redhat.com)" 41 + #define DRV_VERSION "2.1" 42 + #define DRV_RELDATE "August 26, 2008" 43 + #define DRV_AUTHOR "David S. Miller (davem@davemloft.net)" 46 44 47 45 static char version[] = 48 46 DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " " DRV_AUTHOR "\n"; ··· 97 97 98 98 static void qec_init(struct bigmac *bp) 99 99 { 100 + struct of_device *qec_op = bp->qec_op; 100 101 void __iomem *gregs = bp->gregs; 101 - struct sbus_dev *qec_sdev = bp->qec_sdev; 102 102 u8 bsizes = bp->bigmac_bursts; 103 103 u32 regval; 104 104 ··· 113 113 sbus_writel(GLOB_PSIZE_2048, gregs + GLOB_PSIZE); 114 114 115 115 /* All of memsize is given to bigmac. */ 116 - sbus_writel(qec_sdev->reg_addrs[1].reg_size, 116 + sbus_writel(resource_size(&qec_op->resource[1]), 117 117 gregs + GLOB_MSIZE); 118 118 119 119 /* Half to the transmitter, half to the receiver. */ 120 - sbus_writel(qec_sdev->reg_addrs[1].reg_size >> 1, 120 + sbus_writel(resource_size(&qec_op->resource[1]) >> 1, 121 121 gregs + GLOB_TSIZE); 122 - sbus_writel(qec_sdev->reg_addrs[1].reg_size >> 1, 122 + sbus_writel(resource_size(&qec_op->resource[1]) >> 1, 123 123 gregs + GLOB_RSIZE); 124 124 } 125 125 ··· 240 240 skb_reserve(skb, 34); 241 241 242 242 bb->be_rxd[i].rx_addr = 243 - dma_map_single(&bp->bigmac_sdev->ofdev.dev, 243 + dma_map_single(&bp->bigmac_op->dev, 244 244 skb->data, 245 245 RX_BUF_ALLOC_SIZE - 34, 246 246 DMA_FROM_DEVICE); ··· 778 778 skb = bp->tx_skbs[elem]; 779 779 bp->enet_stats.tx_packets++; 780 780 bp->enet_stats.tx_bytes += skb->len; 781 - dma_unmap_single(&bp->bigmac_sdev->ofdev.dev, 781 + dma_unmap_single(&bp->bigmac_op->dev, 782 782 this->tx_addr, skb->len, 783 783 DMA_TO_DEVICE); 784 784 ··· 833 833 drops++; 834 834 goto drop_it; 835 835 } 836 - dma_unmap_single(&bp->bigmac_sdev->ofdev.dev, 836 + dma_unmap_single(&bp->bigmac_op->dev, 837 837 this->rx_addr, 838 838 RX_BUF_ALLOC_SIZE - 34, 839 839 DMA_FROM_DEVICE); ··· 842 842 skb_put(new_skb, ETH_FRAME_LEN); 843 843 skb_reserve(new_skb, 34); 844 844 this->rx_addr = 845 - dma_map_single(&bp->bigmac_sdev->ofdev.dev, 845 + dma_map_single(&bp->bigmac_op->dev, 846 846 new_skb->data, 847 847 RX_BUF_ALLOC_SIZE - 34, 848 848 DMA_FROM_DEVICE); ··· 860 860 } 861 861 skb_reserve(copy_skb, 2); 862 862 skb_put(copy_skb, len); 863 - dma_sync_single_for_cpu(&bp->bigmac_sdev->ofdev.dev, 863 + dma_sync_single_for_cpu(&bp->bigmac_op->dev, 864 864 this->rx_addr, len, 865 865 DMA_FROM_DEVICE); 866 866 skb_copy_to_linear_data(copy_skb, (unsigned char *)skb->data, len); 867 - dma_sync_single_for_device(&bp->bigmac_sdev->ofdev.dev, 867 + dma_sync_single_for_device(&bp->bigmac_op->dev, 868 868 this->rx_addr, len, 869 869 DMA_FROM_DEVICE); 870 870 ··· 962 962 u32 mapping; 963 963 964 964 len = skb->len; 965 - mapping = dma_map_single(&bp->bigmac_sdev->ofdev.dev, skb->data, 965 + mapping = dma_map_single(&bp->bigmac_op->dev, skb->data, 966 966 len, DMA_TO_DEVICE); 967 967 968 968 /* Avoid a race... */ ··· 1055 1055 /* Ethtool support... */ 1056 1056 static void bigmac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) 1057 1057 { 1058 - struct bigmac *bp = dev->priv; 1059 - 1060 1058 strcpy(info->driver, "sunbmac"); 1061 1059 strcpy(info->version, "2.0"); 1062 - sprintf(info->bus_info, "SBUS:%d", 1063 - bp->qec_sdev->slot); 1064 1060 } 1065 1061 1066 1062 static u32 bigmac_get_link(struct net_device *dev) ··· 1075 1079 .get_link = bigmac_get_link, 1076 1080 }; 1077 1081 1078 - static int __devinit bigmac_ether_init(struct sbus_dev *qec_sdev) 1082 + static int __devinit bigmac_ether_init(struct of_device *op, 1083 + struct of_device *qec_op) 1079 1084 { 1080 - struct net_device *dev; 1081 1085 static int version_printed; 1082 - struct bigmac *bp; 1086 + struct net_device *dev; 1083 1087 u8 bsizes, bsizes_more; 1084 - int i; 1085 1088 DECLARE_MAC_BUF(mac); 1089 + struct bigmac *bp; 1090 + int i; 1086 1091 1087 1092 /* Get a new device struct for this interface. */ 1088 1093 dev = alloc_etherdev(sizeof(struct bigmac)); ··· 1093 1096 if (version_printed++ == 0) 1094 1097 printk(KERN_INFO "%s", version); 1095 1098 1096 - dev->base_addr = (long) qec_sdev; 1097 1099 for (i = 0; i < 6; i++) 1098 1100 dev->dev_addr[i] = idprom->id_ethaddr[i]; 1099 1101 1100 1102 /* Setup softc, with backpointers to QEC and BigMAC SBUS device structs. */ 1101 - bp = dev->priv; 1102 - bp->qec_sdev = qec_sdev; 1103 - bp->bigmac_sdev = qec_sdev->child; 1103 + bp = netdev_priv(dev); 1104 + bp->qec_op = qec_op; 1105 + bp->bigmac_op = op; 1104 1106 1105 - SET_NETDEV_DEV(dev, &bp->bigmac_sdev->ofdev.dev); 1107 + SET_NETDEV_DEV(dev, &op->dev); 1106 1108 1107 1109 spin_lock_init(&bp->lock); 1108 1110 1109 - /* Verify the registers we expect, are actually there. */ 1110 - if ((bp->bigmac_sdev->num_registers != 3) || 1111 - (bp->qec_sdev->num_registers != 2)) { 1112 - printk(KERN_ERR "BIGMAC: Device does not have 2 and 3 regs, it has %d and %d.\n", 1113 - bp->qec_sdev->num_registers, 1114 - bp->bigmac_sdev->num_registers); 1115 - printk(KERN_ERR "BIGMAC: Would you like that for here or to go?\n"); 1116 - goto fail_and_cleanup; 1117 - } 1118 - 1119 1111 /* Map in QEC global control registers. */ 1120 - bp->gregs = sbus_ioremap(&bp->qec_sdev->resource[0], 0, 1121 - GLOB_REG_SIZE, "BigMAC QEC GLobal Regs"); 1112 + bp->gregs = of_ioremap(&qec_op->resource[0], 0, 1113 + GLOB_REG_SIZE, "BigMAC QEC GLobal Regs"); 1122 1114 if (!bp->gregs) { 1123 1115 printk(KERN_ERR "BIGMAC: Cannot map QEC global registers.\n"); 1124 1116 goto fail_and_cleanup; ··· 1124 1138 goto fail_and_cleanup; 1125 1139 1126 1140 /* Get supported SBUS burst sizes. */ 1127 - bsizes = prom_getintdefault(bp->qec_sdev->prom_node, 1128 - "burst-sizes", 1129 - 0xff); 1130 - 1131 - bsizes_more = prom_getintdefault(bp->qec_sdev->bus->prom_node, 1132 - "burst-sizes", 1133 - 0xff); 1141 + bsizes = of_getintprop_default(qec_op->node, "burst-sizes", 0xff); 1142 + bsizes_more = of_getintprop_default(qec_op->node, "burst-sizes", 0xff); 1134 1143 1135 1144 bsizes &= 0xff; 1136 1145 if (bsizes_more != 0xff) ··· 1139 1158 qec_init(bp); 1140 1159 1141 1160 /* Map in the BigMAC channel registers. */ 1142 - bp->creg = sbus_ioremap(&bp->bigmac_sdev->resource[0], 0, 1143 - CREG_REG_SIZE, "BigMAC QEC Channel Regs"); 1161 + bp->creg = of_ioremap(&op->resource[0], 0, 1162 + CREG_REG_SIZE, "BigMAC QEC Channel Regs"); 1144 1163 if (!bp->creg) { 1145 1164 printk(KERN_ERR "BIGMAC: Cannot map QEC channel registers.\n"); 1146 1165 goto fail_and_cleanup; 1147 1166 } 1148 1167 1149 1168 /* Map in the BigMAC control registers. */ 1150 - bp->bregs = sbus_ioremap(&bp->bigmac_sdev->resource[1], 0, 1151 - BMAC_REG_SIZE, "BigMAC Primary Regs"); 1169 + bp->bregs = of_ioremap(&op->resource[1], 0, 1170 + BMAC_REG_SIZE, "BigMAC Primary Regs"); 1152 1171 if (!bp->bregs) { 1153 1172 printk(KERN_ERR "BIGMAC: Cannot map BigMAC primary registers.\n"); 1154 1173 goto fail_and_cleanup; ··· 1157 1176 /* Map in the BigMAC transceiver registers, this is how you poke at 1158 1177 * the BigMAC's PHY. 1159 1178 */ 1160 - bp->tregs = sbus_ioremap(&bp->bigmac_sdev->resource[2], 0, 1161 - TCVR_REG_SIZE, "BigMAC Transceiver Regs"); 1179 + bp->tregs = of_ioremap(&op->resource[2], 0, 1180 + TCVR_REG_SIZE, "BigMAC Transceiver Regs"); 1162 1181 if (!bp->tregs) { 1163 1182 printk(KERN_ERR "BIGMAC: Cannot map BigMAC transceiver registers.\n"); 1164 1183 goto fail_and_cleanup; ··· 1168 1187 bigmac_stop(bp); 1169 1188 1170 1189 /* Allocate transmit/receive descriptor DVMA block. */ 1171 - bp->bmac_block = dma_alloc_coherent(&bp->bigmac_sdev->ofdev.dev, 1190 + bp->bmac_block = dma_alloc_coherent(&bp->bigmac_op->dev, 1172 1191 PAGE_SIZE, 1173 1192 &bp->bblock_dvma, GFP_ATOMIC); 1174 1193 if (bp->bmac_block == NULL || bp->bblock_dvma == 0) { ··· 1177 1196 } 1178 1197 1179 1198 /* Get the board revision of this BigMAC. */ 1180 - bp->board_rev = prom_getintdefault(bp->bigmac_sdev->prom_node, 1181 - "board-version", 1); 1199 + bp->board_rev = of_getintprop_default(bp->bigmac_op->node, 1200 + "board-version", 1); 1182 1201 1183 1202 /* Init auto-negotiation timer state. */ 1184 1203 init_timer(&bp->bigmac_timer); ··· 1202 1221 dev->watchdog_timeo = 5*HZ; 1203 1222 1204 1223 /* Finish net device registration. */ 1205 - dev->irq = bp->bigmac_sdev->irqs[0]; 1224 + dev->irq = bp->bigmac_op->irqs[0]; 1206 1225 dev->dma = 0; 1207 1226 1208 1227 if (register_netdev(dev)) { ··· 1210 1229 goto fail_and_cleanup; 1211 1230 } 1212 1231 1213 - dev_set_drvdata(&bp->bigmac_sdev->ofdev.dev, bp); 1232 + dev_set_drvdata(&bp->bigmac_op->dev, bp); 1214 1233 1215 1234 printk(KERN_INFO "%s: BigMAC 100baseT Ethernet %s\n", 1216 1235 dev->name, print_mac(mac, dev->dev_addr)); ··· 1221 1240 /* Something went wrong, undo whatever we did so far. */ 1222 1241 /* Free register mappings if any. */ 1223 1242 if (bp->gregs) 1224 - sbus_iounmap(bp->gregs, GLOB_REG_SIZE); 1243 + of_iounmap(&qec_op->resource[0], bp->gregs, GLOB_REG_SIZE); 1225 1244 if (bp->creg) 1226 - sbus_iounmap(bp->creg, CREG_REG_SIZE); 1245 + of_iounmap(&op->resource[0], bp->creg, CREG_REG_SIZE); 1227 1246 if (bp->bregs) 1228 - sbus_iounmap(bp->bregs, BMAC_REG_SIZE); 1247 + of_iounmap(&op->resource[1], bp->bregs, BMAC_REG_SIZE); 1229 1248 if (bp->tregs) 1230 - sbus_iounmap(bp->tregs, TCVR_REG_SIZE); 1249 + of_iounmap(&op->resource[2], bp->tregs, TCVR_REG_SIZE); 1231 1250 1232 1251 if (bp->bmac_block) 1233 - dma_free_coherent(&bp->bigmac_sdev->ofdev.dev, 1252 + dma_free_coherent(&bp->bigmac_op->dev, 1234 1253 PAGE_SIZE, 1235 1254 bp->bmac_block, 1236 1255 bp->bblock_dvma); ··· 1240 1259 return -ENODEV; 1241 1260 } 1242 1261 1243 - /* QEC can be the parent of either QuadEthernet or 1244 - * a BigMAC. We want the latter. 1262 + /* QEC can be the parent of either QuadEthernet or a BigMAC. We want 1263 + * the latter. 1245 1264 */ 1246 - static int __devinit bigmac_sbus_probe(struct of_device *dev, const struct of_device_id *match) 1265 + static int __devinit bigmac_sbus_probe(struct of_device *op, 1266 + const struct of_device_id *match) 1247 1267 { 1248 - struct sbus_dev *sdev = to_sbus_device(&dev->dev); 1249 - struct device_node *dp = dev->node; 1268 + struct device *parent = op->dev.parent; 1269 + struct of_device *qec_op; 1250 1270 1251 - if (!strcmp(dp->name, "be")) 1252 - sdev = sdev->parent; 1271 + qec_op = to_of_device(parent); 1253 1272 1254 - return bigmac_ether_init(sdev); 1273 + return bigmac_ether_init(op, qec_op); 1255 1274 } 1256 1275 1257 - static int __devexit bigmac_sbus_remove(struct of_device *dev) 1276 + static int __devexit bigmac_sbus_remove(struct of_device *op) 1258 1277 { 1259 - struct bigmac *bp = dev_get_drvdata(&dev->dev); 1278 + struct bigmac *bp = dev_get_drvdata(&op->dev); 1279 + struct device *parent = op->dev.parent; 1260 1280 struct net_device *net_dev = bp->dev; 1281 + struct of_device *qec_op; 1282 + 1283 + qec_op = to_of_device(parent); 1261 1284 1262 1285 unregister_netdevice(net_dev); 1263 1286 1264 - sbus_iounmap(bp->gregs, GLOB_REG_SIZE); 1265 - sbus_iounmap(bp->creg, CREG_REG_SIZE); 1266 - sbus_iounmap(bp->bregs, BMAC_REG_SIZE); 1267 - sbus_iounmap(bp->tregs, TCVR_REG_SIZE); 1268 - dma_free_coherent(&bp->bigmac_sdev->ofdev.dev, 1287 + of_iounmap(&qec_op->resource[0], bp->gregs, GLOB_REG_SIZE); 1288 + of_iounmap(&op->resource[0], bp->creg, CREG_REG_SIZE); 1289 + of_iounmap(&op->resource[1], bp->bregs, BMAC_REG_SIZE); 1290 + of_iounmap(&op->resource[2], bp->tregs, TCVR_REG_SIZE); 1291 + dma_free_coherent(&op->dev, 1269 1292 PAGE_SIZE, 1270 1293 bp->bmac_block, 1271 1294 bp->bblock_dvma); 1272 1295 1273 1296 free_netdev(net_dev); 1274 1297 1275 - dev_set_drvdata(&dev->dev, NULL); 1298 + dev_set_drvdata(&op->dev, NULL); 1276 1299 1277 1300 return 0; 1278 1301 } 1279 1302 1280 1303 static struct of_device_id bigmac_sbus_match[] = { 1281 - { 1282 - .name = "qec", 1283 - }, 1284 1304 { 1285 1305 .name = "be", 1286 1306 }, ··· 1299 1317 1300 1318 static int __init bigmac_init(void) 1301 1319 { 1302 - return of_register_driver(&bigmac_sbus_driver, &sbus_bus_type); 1320 + return of_register_driver(&bigmac_sbus_driver, &of_bus_type); 1303 1321 } 1304 1322 1305 1323 static void __exit bigmac_exit(void)
+2 -2
drivers/net/sunbmac.h
··· 329 329 unsigned int timer_ticks; 330 330 331 331 struct net_device_stats enet_stats; 332 - struct sbus_dev *qec_sdev; 333 - struct sbus_dev *bigmac_sdev; 332 + struct of_device *qec_op; 333 + struct of_device *bigmac_op; 334 334 struct net_device *dev; 335 335 }; 336 336