Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 | /* virtpci.c * * Copyright © 2010 - 2013 UNISYS CORPORATION * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or * NON INFRINGEMENT. See the GNU General Public License for more * details. */ #define EXPORT_SYMTAB #include <linux/kernel.h> #ifdef CONFIG_MODVERSIONS #include <config/modversions.h> #endif #include "uniklog.h" #include "diagnostics/appos_subsystems.h" #include "uisutils.h" #include "commontypes.h" #include "vbuschannel.h" #include "vbushelper.h" #include <linux/module.h> #include <linux/init.h> #include <linux/pci.h> #include <linux/device.h> #include <linux/list.h> #include <linux/slab.h> #include <linux/mod_devicetable.h> #include <linux/proc_fs.h> #include <linux/if_ether.h> #include <linux/version.h> #include "version.h" #include "guestlinuxdebug.h" struct driver_private { struct kobject kobj; struct klist klist_devices; struct klist_node knode_bus; struct module_kobject *mkobj; struct device_driver *driver; }; #define to_driver(obj) container_of(obj, struct driver_private, kobj) /* bus_id went away in 2.6.30 - the size was 20 bytes, so we'll define * it ourselves, and a macro to make getting the field a bit simpler. */ #ifndef BUS_ID_SIZE #define BUS_ID_SIZE 20 #endif #define BUS_ID(x) dev_name(x) #include "virtpci.h" /* this is shorter than using __FILE__ (full path name) in * debug/info/error messages */ #define CURRENT_FILE_PC VIRT_PCI_PC_virtpci_c #define __MYFILE__ "virtpci.c" #define VIRTPCI_VERSION "01.00" /*****************************************************/ /* Forward declarations */ /*****************************************************/ static int delete_vbus_device(struct device *vbus, void *data); static int match_busid(struct device *dev, void *data); static void virtpci_bus_release(struct device *dev); static void virtpci_device_release(struct device *dev); static int virtpci_device_add(struct device *parentbus, int devtype, struct add_virt_guestpart *addparams, struct scsi_adap_info *scsi, struct net_adap_info *net); static int virtpci_device_del(struct device *parentbus, int devtype, struct vhba_wwnn *wwnn, unsigned char macaddr[]); static int virtpci_device_serverdown(struct device *parentbus, int devtype, struct vhba_wwnn *wwnn, unsigned char macaddr[]); static int virtpci_device_serverup(struct device *parentbus, int devtype, struct vhba_wwnn *wwnn, unsigned char macaddr[]); static ssize_t virtpci_driver_attr_show(struct kobject *kobj, struct attribute *attr, char *buf); static ssize_t virtpci_driver_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count); static int virtpci_bus_match(struct device *dev, struct device_driver *drv); static int virtpci_uevent(struct device *dev, struct kobj_uevent_env *env); static int virtpci_device_suspend(struct device *dev, pm_message_t state); static int virtpci_device_resume(struct device *dev); static int virtpci_device_probe(struct device *dev); static int virtpci_device_remove(struct device *dev); static ssize_t virt_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos); static ssize_t info_proc_read(struct file *file, char __user *buf, size_t len, loff_t *offset); static const struct file_operations proc_virt_fops = { .write = virt_proc_write, }; static const struct file_operations proc_info_fops = { .read = info_proc_read, }; /*****************************************************/ /* Globals */ /*****************************************************/ /* methods in bus_type struct allow the bus code to serve as an * intermediary between the device core and individual device core and * individual drivers */ static struct bus_type virtpci_bus_type = { .name = "uisvirtpci", .match = virtpci_bus_match, .uevent = virtpci_uevent, .suspend = virtpci_device_suspend, .resume = virtpci_device_resume, }; static struct device virtpci_rootbus_device = { .init_name = "vbusroot", /* root bus */ .release = virtpci_bus_release }; /* filled in with info about parent chipset driver when we register with it */ static ULTRA_VBUS_DEVICEINFO Chipset_DriverInfo; static const struct sysfs_ops virtpci_driver_sysfs_ops = { .show = virtpci_driver_attr_show, .store = virtpci_driver_attr_store, }; static struct kobj_type virtpci_driver_kobj_type = { .sysfs_ops = &virtpci_driver_sysfs_ops, }; static struct virtpci_dev *VpcidevListHead; static DEFINE_RWLOCK(VpcidevListLock); /* filled in with info about this driver, wrt it servicing client busses */ static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo; /* virtpci_proc_dir_entry is used to create the proc entry directory * for virtpci */ static struct proc_dir_entry *virtpci_proc_dir; /* virt_proc_entry is used to tell virtpci to add/delete vhbas/vnics/vbuses */ static struct proc_dir_entry *virt_proc_entry; /* info_proc_entry is used to tell virtpci to display current info * kept in the driver */ static struct proc_dir_entry *info_proc_entry; #define VIRT_PROC_ENTRY_FN "virt" #define INFO_PROC_ENTRY_FN "info" #define DIR_PROC_ENTRY "virtpci" struct virtpci_busdev { struct device virtpci_bus_device; }; /*****************************************************/ /* Local functions */ /*****************************************************/ static inline int WAIT_FOR_IO_CHANNEL(ULTRA_IO_CHANNEL_PROTOCOL __iomem *chanptr) { int count = 120; while (count > 0) { if (ULTRA_CHANNEL_SERVER_READY(&chanptr->ChannelHeader)) return 1; UIS_THREAD_WAIT_SEC(1); count--; } return 0; } /* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.ChpInfo. */ static int write_vbus_chpInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan, ULTRA_VBUS_DEVICEINFO *info) { int off; if (!chan) { LOGERR("vbus channel not present"); return -1; } off = sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.chpInfoByteOffset; if (chan->HdrInfo.chpInfoByteOffset == 0) { LOGERR("vbus channel not used, because chpInfoByteOffset == 0"); return -1; } memcpy(((U8 *) (chan)) + off, info, sizeof(*info)); return 0; } /* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.BusInfo. */ static int write_vbus_busInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan, ULTRA_VBUS_DEVICEINFO *info) { int off; if (!chan) { LOGERR("vbus channel not present"); return -1; } off = sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.busInfoByteOffset; if (chan->HdrInfo.busInfoByteOffset == 0) { LOGERR("vbus channel not used, because busInfoByteOffset == 0"); return -1; } memcpy(((U8 *) (chan)) + off, info, sizeof(*info)); return 0; } /* Write the contents of <info> to the * ULTRA_VBUS_CHANNEL_PROTOCOL.DevInfo[<devix>]. */ static int write_vbus_devInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan, ULTRA_VBUS_DEVICEINFO *info, int devix) { int off; if (!chan) { LOGERR("vbus channel not present"); return -1; } off = (sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.devInfoByteOffset) + (chan->HdrInfo.deviceInfoStructBytes * devix); if (chan->HdrInfo.devInfoByteOffset == 0) { LOGERR("vbus channel not used, because devInfoByteOffset == 0"); return -1; } memcpy(((U8 *) (chan)) + off, info, sizeof(*info)); return 0; } /* adds a vbus * returns 0 failure, 1 success, */ static int add_vbus(struct add_vbus_guestpart *addparams) { int ret; struct device *vbus; vbus = kzalloc(sizeof(struct device), GFP_ATOMIC); POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); if (!vbus) return 0; dev_set_name(vbus, "vbus%d", addparams->busNo); vbus->release = virtpci_bus_release; vbus->parent = &virtpci_rootbus_device; /* root bus is parent */ vbus->bus = &virtpci_bus_type; /* bus type */ vbus->platform_data = (__force void *)addparams->chanptr; /* register a virt bus device - * this bus shows up under /sys/devices with .name value * "virtpci%d" any devices added to this bus then show up under * /sys/devices/virtpci0 */ ret = device_register(vbus); if (ret) { LOGERR("device_register FAILED:%d\n", ret); POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); return 0; } write_vbus_chpInfo(vbus->platform_data /* chanptr */ , &Chipset_DriverInfo); write_vbus_busInfo(vbus->platform_data /* chanptr */ , &Bus_DriverInfo); LOGINF("Added vbus %d; device %s created successfully\n", addparams->busNo, BUS_ID(vbus)); POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO); return 1; } /* for CHANSOCK wwwnn/max are AUTO-GENERATED; for normal channels, * wwnn/max are in the channel header. */ #define GET_SCSIADAPINFO_FROM_CHANPTR(chanptr) { \ memcpy_fromio(&scsi.wwnn, \ &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ chanptr)->vhba.wwnn, \ sizeof(struct vhba_wwnn)); \ memcpy_fromio(&scsi.max, \ &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ chanptr)->vhba.max, \ sizeof(struct vhba_config_max)); \ } /* find bus device with the busid that matches - match_busid matches bus_id */ #define GET_BUS_DEV(busno) { \ sprintf(busid, "vbus%d", busno); \ vbus = bus_find_device(&virtpci_bus_type, NULL, \ (void *)busid, match_busid); \ if (!vbus) { \ LOGERR("**** FAILED to find vbus %s\n", busid); \ return 0; \ } \ } /* adds a vhba * returns 0 failure, 1 success, */ static int add_vhba(struct add_virt_guestpart *addparams) { int i; struct scsi_adap_info scsi; struct device *vbus; unsigned char busid[BUS_ID_SIZE]; POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); if (!WAIT_FOR_IO_CHANNEL ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) addparams->chanptr)) { LOGERR("Timed out. Channel not ready\n"); POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); return 0; } GET_SCSIADAPINFO_FROM_CHANPTR(addparams->chanptr); GET_BUS_DEV(addparams->busNo); LOGINF("Adding vhba wwnn:%x:%x config:%d-%d-%d-%d chanptr:%p\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2, scsi.max.max_channel, scsi.max.max_id, scsi.max.max_lun, scsi.max.cmd_per_lun, addparams->chanptr); i = virtpci_device_add(vbus, VIRTHBA_TYPE, addparams, &scsi, NULL); if (i) { LOGINF("Added vhba wwnn:%x:%x chanptr:%p\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2, addparams->chanptr); POSTCODE_LINUX_3(VPCI_CREATE_EXIT_PC, i, POSTCODE_SEVERITY_INFO); } return i; } /* for CHANSOCK macaddr is AUTO-GENERATED; for normal channels, * macaddr is in the channel header. */ #define GET_NETADAPINFO_FROM_CHANPTR(chanptr) { \ memcpy_fromio(net.mac_addr, \ ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ chanptr)->vnic.macaddr, \ MAX_MACADDR_LEN); \ net.num_rcv_bufs = \ readl(&((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ chanptr)->vnic.num_rcv_bufs); \ net.mtu = readl(&((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ chanptr)->vnic.mtu); \ memcpy_fromio(&net.zoneGuid, \ &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \ chanptr)->vnic.zoneGuid, \ sizeof(GUID)); \ } /* adds a vnic * returns 0 failure, 1 success, */ static int add_vnic(struct add_virt_guestpart *addparams) { int i; struct net_adap_info net; struct device *vbus; unsigned char busid[BUS_ID_SIZE]; POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); if (!WAIT_FOR_IO_CHANNEL ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) addparams->chanptr)) { LOGERR("Timed out, channel not ready\n"); POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); return 0; } GET_NETADAPINFO_FROM_CHANPTR(addparams->chanptr); GET_BUS_DEV(addparams->busNo); LOGINF("Adding vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x rcvbufs:%d mtu:%d chanptr:%p{%-8.8lx-%-4.4x-%-4.4x-%-2.2x%-2.2x%-2.2x%-2.2x%-2.2x%-2.2x%-2.2x%-2.2x}\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5], net.num_rcv_bufs, net.mtu, addparams->chanptr, (ulong) net.zoneGuid.data1, net.zoneGuid.data2, net.zoneGuid.data3, net.zoneGuid.data4[0], net.zoneGuid.data4[1], net.zoneGuid.data4[2], net.zoneGuid.data4[3], net.zoneGuid.data4[4], net.zoneGuid.data4[5], net.zoneGuid.data4[6], net.zoneGuid.data4[7]); i = virtpci_device_add(vbus, VIRTNIC_TYPE, addparams, NULL, &net); if (i) { LOGINF("Added vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); POSTCODE_LINUX_3(VPCI_CREATE_EXIT_PC, i, POSTCODE_SEVERITY_INFO); return 1; } return 0; } /* delete vbus * returns 0 failure, 1 success, */ static int delete_vbus(struct del_vbus_guestpart *delparams) { struct device *vbus; unsigned char busid[BUS_ID_SIZE]; GET_BUS_DEV(delparams->busNo); /* ensure that bus has no devices? -- TBD */ LOGINF("Deleting %s\n", BUS_ID(vbus)); if (delete_vbus_device(vbus, NULL)) return 0; /* failure */ LOGINF("Deleted vbus %d\n", delparams->busNo); return 1; } static int delete_vbus_device(struct device *vbus, void *data) { int checkforroot = (data != NULL); struct device *pDev = &virtpci_rootbus_device; if ((checkforroot) && match_busid(vbus, (void *) BUS_ID(pDev))) { /* skip it - don't delete root bus */ LOGINF("skipping root bus\n"); return 0; /* pretend no error */ } LOGINF("Calling unregister for %s\n", BUS_ID(vbus)); device_unregister(vbus); kfree(vbus); LOGINF("VBus unregister and freed\n"); return 0; /* no error */ } /* pause vhba * returns 0 failure, 1 success, */ static int pause_vhba(struct pause_virt_guestpart *pauseparams) { int i; struct scsi_adap_info scsi; GET_SCSIADAPINFO_FROM_CHANPTR(pauseparams->chanptr); LOGINF("Pausing vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2); i = virtpci_device_serverdown(NULL /*no parent bus */ , VIRTHBA_TYPE, &scsi.wwnn, NULL); if (i) LOGINF("Paused vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2); return i; } /* pause vnic * returns 0 failure, 1 success, */ static int pause_vnic(struct pause_virt_guestpart *pauseparams) { int i; struct net_adap_info net; GET_NETADAPINFO_FROM_CHANPTR(pauseparams->chanptr); LOGINF("Pausing vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); i = virtpci_device_serverdown(NULL /*no parent bus */ , VIRTNIC_TYPE, NULL, net.mac_addr); if (i) { LOGINF(" Paused vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); } return i; } /* resume vhba * returns 0 failure, 1 success, */ static int resume_vhba(struct resume_virt_guestpart *resumeparams) { int i; struct scsi_adap_info scsi; GET_SCSIADAPINFO_FROM_CHANPTR(resumeparams->chanptr); LOGINF("Resuming vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2); i = virtpci_device_serverup(NULL /*no parent bus */ , VIRTHBA_TYPE, &scsi.wwnn, NULL); if (i) LOGINF("Resumed vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2); return i; } /* resume vnic * returns 0 failure, 1 success, */ static int resume_vnic(struct resume_virt_guestpart *resumeparams) { int i; struct net_adap_info net; GET_NETADAPINFO_FROM_CHANPTR(resumeparams->chanptr); LOGINF("Resuming vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); i = virtpci_device_serverup(NULL /*no parent bus */ , VIRTNIC_TYPE, NULL, net.mac_addr); if (i) { LOGINF(" Resumed vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); } return i; } /* delete vhba * returns 0 failure, 1 success, */ static int delete_vhba(struct del_virt_guestpart *delparams) { int i; struct scsi_adap_info scsi; GET_SCSIADAPINFO_FROM_CHANPTR(delparams->chanptr); LOGINF("Deleting vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2); i = virtpci_device_del(NULL /*no parent bus */ , VIRTHBA_TYPE, &scsi.wwnn, NULL); if (i) { LOGINF("Deleted vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2); return 1; } return 0; } /* deletes a vnic * returns 0 failure, 1 success, */ static int delete_vnic(struct del_virt_guestpart *delparams) { int i; struct net_adap_info net; GET_NETADAPINFO_FROM_CHANPTR(delparams->chanptr); LOGINF("Deleting vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); i = virtpci_device_del(NULL /*no parent bus */ , VIRTNIC_TYPE, NULL, net.mac_addr); if (i) { LOGINF("Deleted vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n", net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]); } return i; } #define DELETE_ONE_VPCIDEV(vpcidev) { \ LOGINF("calling device_unregister:%p\n", &vpcidev->generic_dev); \ device_unregister(&vpcidev->generic_dev); \ LOGINF("Deleted %p\n", vpcidev); \ kfree(vpcidev); \ } /* deletes all vhbas and vnics * returns 0 failure, 1 success, */ static void delete_all(void) { int count = 0; unsigned long flags; struct virtpci_dev *tmpvpcidev, *nextvpcidev; /* delete the entire vhba/vnic list in one shot */ write_lock_irqsave(&VpcidevListLock, flags); tmpvpcidev = VpcidevListHead; VpcidevListHead = NULL; write_unlock_irqrestore(&VpcidevListLock, flags); /* delete one vhba/vnic at a time */ while (tmpvpcidev) { nextvpcidev = tmpvpcidev->next; /* delete the vhba/vnic at tmpvpcidev */ DELETE_ONE_VPCIDEV(tmpvpcidev); tmpvpcidev = nextvpcidev; count++; } LOGINF("Deleted %d vhbas/vnics.\n", count); /* now delete each vbus */ if (bus_for_each_dev (&virtpci_bus_type, NULL, (void *) 1, delete_vbus_device)) LOGERR("delete of all vbus failed\n"); } /* deletes all vnics or vhbas * returns 0 failure, 1 success, */ static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams) { int i; unsigned char busid[BUS_ID_SIZE]; struct device *vbus; GET_BUS_DEV(delparams->busNo); if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { LOGERR("**** FAILED to delete all devices; devtype:%d not vhba:%d or vnic:%d\n", devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); return 0; } LOGINF("Deleting all %s in vbus %s\n", devtype == VIRTHBA_TYPE ? "vhbas" : "vnics", busid); /* delete all vhbas/vnics */ i = virtpci_device_del(vbus, devtype, NULL, NULL); if (i > 0) LOGINF("Deleted %d %s\n", i, devtype == VIRTHBA_TYPE ? "vhbas" : "vnics"); return 1; } static int virtpci_ctrlchan_func(struct guest_msgs *msg) { switch (msg->msgtype) { case GUEST_ADD_VBUS: return add_vbus(&msg->add_vbus); case GUEST_ADD_VHBA: return add_vhba(&msg->add_vhba); case GUEST_ADD_VNIC: return add_vnic(&msg->add_vnic); case GUEST_DEL_VBUS: return delete_vbus(&msg->del_vbus); case GUEST_DEL_VHBA: return delete_vhba(&msg->del_vhba); case GUEST_DEL_VNIC: return delete_vnic(&msg->del_vhba); case GUEST_DEL_ALL_VHBAS: return delete_all_virt(VIRTHBA_TYPE, &msg->del_all_vhbas); case GUEST_DEL_ALL_VNICS: return delete_all_virt(VIRTNIC_TYPE, &msg->del_all_vnics); case GUEST_DEL_ALL_VBUSES: delete_all(); return 1; case GUEST_PAUSE_VHBA: return pause_vhba(&msg->pause_vhba); case GUEST_PAUSE_VNIC: return pause_vnic(&msg->pause_vnic); case GUEST_RESUME_VHBA: return resume_vhba(&msg->resume_vhba); case GUEST_RESUME_VNIC: return resume_vnic(&msg->resume_vnic); default: LOGERR("invalid message type %d.\n", msg->msgtype); return 0; } } /* same as driver_helper in bus.c linux */ static int match_busid(struct device *dev, void *data) { const char *name = data; if (strcmp(name, BUS_ID(dev)) == 0) return 1; return 0; } /*****************************************************/ /* Bus functions */ /*****************************************************/ static const struct pci_device_id * virtpci_match_device(const struct pci_device_id *ids, const struct virtpci_dev *dev) { while (ids->vendor || ids->subvendor || ids->class_mask) { DBGINF("ids->vendor:%x dev->vendor:%x ids->device:%x dev->device:%x\n", ids->vendor, dev->vendor, ids->device, dev->device); if ((ids->vendor == dev->vendor) && (ids->device == dev->device)) return ids; ids++; } return NULL; } /* NOTE: !!!!!! This function is called when a new device is added * for this bus. Or, it is called for existing devices when a new * driver is added for this bus. It returns nonzero if a given device * can be handled by the given driver. */ static int virtpci_bus_match(struct device *dev, struct device_driver *drv) { struct virtpci_dev *virtpcidev = device_to_virtpci_dev(dev); struct virtpci_driver *virtpcidrv = driver_to_virtpci_driver(drv); int match = 0; DBGINF("In virtpci_bus_match dev->bus_id:%s drv->name:%s\n", dev->bus_id, drv->name); /* check ids list for a match */ if (virtpci_match_device(virtpcidrv->id_table, virtpcidev)) match = 1; DBGINF("returning match:%d\n", match); return match; /* 0 - no match; 1 - yes it matches */ } static int virtpci_uevent(struct device *dev, struct kobj_uevent_env *env) { DBGINF("In virtpci_hotplug\n"); /* add variables to the environment prior to the generation of * hotplug events to user space */ if (add_uevent_var(env, "VIRTPCI_VERSION=%s", VIRTPCI_VERSION)) return -ENOMEM; return 0; } static int virtpci_device_suspend(struct device *dev, pm_message_t state) { DBGINF("In virtpci_device_suspend -NYI ****\n"); return 0; } static int virtpci_device_resume(struct device *dev) { DBGINF("In virtpci_device_resume -NYI ****\n"); return 0; } /* For a child device just created on a client bus, fill in * information about the driver that is controlling this device into * the the appropriate slot within the vbus channel of the bus * instance. */ static void fix_vbus_devInfo(struct device *dev, int devNo, int devType, struct virtpci_driver *virtpcidrv) { struct device *vbus; void *pChan; ULTRA_VBUS_DEVICEINFO devInfo; const char *stype; if (!dev) { LOGERR("%s dev is NULL", __func__); return; } if (!virtpcidrv) { LOGERR("%s driver is NULL", __func__); return; } vbus = dev->parent; if (!vbus) { LOGERR("%s dev has no parent bus", __func__); return; } pChan = vbus->platform_data; if (!pChan) { LOGERR("%s dev bus has no channel", __func__); return; } switch (devType) { case PCI_DEVICE_ID_VIRTHBA: stype = "vHBA"; break; case PCI_DEVICE_ID_VIRTNIC: stype = "vNIC"; break; default: stype = "unknown"; break; } BusDeviceInfo_Init(&devInfo, stype, virtpcidrv->name, virtpcidrv->version, virtpcidrv->vertag, virtpcidrv->build_date, virtpcidrv->build_time); write_vbus_devInfo(pChan, &devInfo, devNo); /* Re-write bus+chipset info, because it is possible that this * was previously written by our good counterpart, visorbus. */ write_vbus_chpInfo(pChan, &Chipset_DriverInfo); write_vbus_busInfo(pChan, &Bus_DriverInfo); } /* This function is called to query the existence of a specific device * and whether this driver can work with it. It should return -ENODEV * in case of failure. */ static int virtpci_device_probe(struct device *dev) { struct virtpci_dev *virtpcidev = device_to_virtpci_dev(dev); struct virtpci_driver *virtpcidrv = driver_to_virtpci_driver(dev->driver); const struct pci_device_id *id; int error = 0; LOGINF("In virtpci_device_probe dev:%p virtpcidev:%p virtpcidrv:%p\n", dev, virtpcidev, virtpcidrv); /* VERBOSE/DEBUG ? */ POSTCODE_LINUX_2(VPCI_PROBE_ENTRY_PC, POSTCODE_SEVERITY_INFO); /* static match and static probe vs dynamic match & dynamic * probe - do we care?. */ if (!virtpcidrv->id_table) return -ENODEV; id = virtpci_match_device(virtpcidrv->id_table, virtpcidev); if (!id) return -ENODEV; /* increment reference count */ get_device(dev); /* if virtpcidev is not already claimed & probe function is * valid, probe it */ if (!virtpcidev->mydriver && virtpcidrv->probe) { /* call the probe function - virthba or virtnic probe * is what it should be */ error = virtpcidrv->probe(virtpcidev, id); if (!error) { fix_vbus_devInfo(dev, virtpcidev->deviceNo, virtpcidev->device, virtpcidrv); virtpcidev->mydriver = virtpcidrv; POSTCODE_LINUX_2(VPCI_PROBE_EXIT_PC, POSTCODE_SEVERITY_INFO); } else put_device(dev); } POSTCODE_LINUX_2(VPCI_PROBE_FAILURE_PC, POSTCODE_SEVERITY_ERR); return error; /* -ENODEV for probe failure */ } static int virtpci_device_remove(struct device *dev_) { /* dev_ passed in is the HBA device which we called * generic_dev in our virtpcidev struct */ struct virtpci_dev *virtpcidev = device_to_virtpci_dev(dev_); struct virtpci_driver *virtpcidrv = virtpcidev->mydriver; LOGINF("In virtpci_device_remove bus_id:%s dev_:%p virtpcidev:%p dev->driver:%p drivername:%s\n", BUS_ID(dev_), dev_, virtpcidev, dev_->driver, dev_->driver->name); /* VERBOSE/DEBUG */ if (virtpcidrv) { /* TEMP: assuming we have only one such driver for now */ if (virtpcidrv->remove) virtpcidrv->remove(virtpcidev); virtpcidev->mydriver = NULL; } DBGINF("calling putdevice\n"); put_device(dev_); DBGINF("Leaving\n"); return 0; } /*****************************************************/ /* Bus functions */ /*****************************************************/ static void virtpci_bus_release(struct device *dev) { /* this function is called when the last reference to the * device is removed */ DBGINF("In virtpci_bus_release\n"); /* what else is supposed to happen here? */ } /*****************************************************/ /* Adapter functions */ /*****************************************************/ static int virtpci_device_add(struct device *parentbus, int devtype, struct add_virt_guestpart *addparams, struct scsi_adap_info *scsi, /* NULL for VNIC add */ struct net_adap_info *net /* NULL for VHBA add */) { struct virtpci_dev *virtpcidev = NULL; struct virtpci_dev *tmpvpcidev = NULL, *prev; unsigned long flags; int ret; ULTRA_IO_CHANNEL_PROTOCOL __iomem *pIoChan = NULL; struct device *pDev; LOGINF("virtpci_device_add parentbus:%p chanptr:%p\n", parentbus, addparams->chanptr); POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { LOGERR("**** FAILED to add device; devtype:%d not vhba:%d or vnic:%d\n", devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, devtype, POSTCODE_SEVERITY_ERR); return 0; } /* add a Virtual Device */ virtpcidev = kzalloc(sizeof(struct virtpci_dev), GFP_ATOMIC); if (virtpcidev == NULL) { LOGERR("can't add device - malloc FALLED\n"); POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR); return 0; } /* initialize stuff unique to virtpci_dev struct */ virtpcidev->devtype = devtype; if (devtype == VIRTHBA_TYPE) { virtpcidev->device = PCI_DEVICE_ID_VIRTHBA; virtpcidev->scsi = *scsi; } else { virtpcidev->device = PCI_DEVICE_ID_VIRTNIC; virtpcidev->net = *net; } virtpcidev->vendor = PCI_VENDOR_ID_UNISYS; virtpcidev->busNo = addparams->busNo; virtpcidev->deviceNo = addparams->deviceNo; virtpcidev->queueinfo.chan = addparams->chanptr; virtpcidev->queueinfo.send_int_if_needed = NULL; /* Set up safe queue... */ pIoChan = (ULTRA_IO_CHANNEL_PROTOCOL __iomem *) virtpcidev->queueinfo.chan; virtpcidev->intr = addparams->intr; /* initialize stuff in the device portion of the struct */ virtpcidev->generic_dev.bus = &virtpci_bus_type; virtpcidev->generic_dev.parent = parentbus; virtpcidev->generic_dev.release = virtpci_device_release; dev_set_name(&virtpcidev->generic_dev, "%x:%x", addparams->busNo, addparams->deviceNo); /* add the vhba/vnic to virtpci device list - but check for * duplicate wwnn/macaddr first */ write_lock_irqsave(&VpcidevListLock, flags); for (tmpvpcidev = VpcidevListHead; tmpvpcidev; tmpvpcidev = tmpvpcidev->next) { if (devtype == VIRTHBA_TYPE) { if ((tmpvpcidev->scsi.wwnn.wwnn1 == scsi->wwnn.wwnn1) && (tmpvpcidev->scsi.wwnn.wwnn2 == scsi->wwnn.wwnn2)) { /* duplicate - already have vpcidev with this wwnn */ break; } } else if (memcmp (tmpvpcidev->net.mac_addr, net->mac_addr, MAX_MACADDR_LEN) == 0) { /* duplicate - already have vnic with this wwnn */ break; } } if (tmpvpcidev) { /* found a vhba/vnic already in the list with same * wwnn or macaddr - reject add */ write_unlock_irqrestore(&VpcidevListLock, flags); kfree(virtpcidev); LOGERR("**** FAILED vhba/vnic already exists in the list\n"); POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); return 0; } /* add it at the head */ if (!VpcidevListHead) VpcidevListHead = virtpcidev; else { /* insert virtpcidev at the head of our linked list of * vpcidevs */ virtpcidev->next = VpcidevListHead; VpcidevListHead = virtpcidev; } write_unlock_irqrestore(&VpcidevListLock, flags); /* Must transition channel to ATTACHED state BEFORE * registering the device, because polling of the channel * queues can begin at any time after device_register(). */ pDev = &virtpcidev->generic_dev; ULTRA_CHANNEL_CLIENT_TRANSITION(addparams->chanptr, BUS_ID(pDev), CHANNELCLI_ATTACHED, NULL); /* don't register until device has been added to * list. Otherwise, a device_unregister from this function can * cause a "scheduling while atomic". */ DBGINF("registering device:%p with bus_id:%s\n", &virtpcidev->generic_dev, virtpcidev->generic_dev.bus_id); ret = device_register(&virtpcidev->generic_dev); /* NOTE: THIS IS CALLING HOTPLUG virtpci_hotplug!!! * This call to device_register results in virtpci_bus_match * being called !!!!! And, if match returns success, then * virtpcidev->generic_dev.driver is setup to core_driver, * i.e., virtpci and the probe function * virtpcidev->generic_dev.driver->probe is called which * results in virtpci_device_probe being called. And if * virtpci_device_probe is successful */ if (ret) { LOGERR("device_register returned %d\n", ret); pDev = &virtpcidev->generic_dev; ULTRA_CHANNEL_CLIENT_TRANSITION(addparams->chanptr, BUS_ID(pDev), CHANNELCLI_DETACHED, NULL); /* remove virtpcidev, the one we just added, from the list */ write_lock_irqsave(&VpcidevListLock, flags); for (tmpvpcidev = VpcidevListHead, prev = NULL; tmpvpcidev; prev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) { if (tmpvpcidev == virtpcidev) { if (prev) prev->next = tmpvpcidev->next; else VpcidevListHead = tmpvpcidev->next; break; } } write_unlock_irqrestore(&VpcidevListLock, flags); kfree(virtpcidev); return 0; } LOGINF("Added %s:%d:%d &virtpcidev->generic_dev:%p\n", (devtype == VIRTHBA_TYPE) ? "virthba" : "virtnic", addparams->busNo, addparams->deviceNo, &virtpcidev->generic_dev); POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO); return 1; } static int virtpci_device_serverdown(struct device *parentbus, int devtype, struct vhba_wwnn *wwnn, unsigned char macaddr[]) { int pausethisone = 0; bool found = false; struct virtpci_dev *tmpvpcidev, *prevvpcidev; struct virtpci_driver *vpcidriver; unsigned long flags; int rc = 0; if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { LOGERR("**** FAILED to pause device; devtype:%d not vhba:%d or vnic:%d\n", devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); return 0; } /* find the vhba or vnic in virtpci device list */ write_lock_irqsave(&VpcidevListLock, flags); for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; (tmpvpcidev && !found); prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) { if (tmpvpcidev->devtype != devtype) continue; if (devtype == VIRTHBA_TYPE) { pausethisone = ((tmpvpcidev->scsi.wwnn.wwnn1 == wwnn->wwnn1) && (tmpvpcidev->scsi.wwnn.wwnn2 == wwnn->wwnn2)); /* devtype is vhba, we're pausing vhba whose * wwnn matches the current device's wwnn */ } else { /* VIRTNIC_TYPE */ pausethisone = memcmp(tmpvpcidev->net.mac_addr, macaddr, MAX_MACADDR_LEN) == 0; /* devtype is vnic, we're pausing vnic whose * macaddr matches the current device's macaddr */ } if (!pausethisone) continue; found = true; vpcidriver = tmpvpcidev->mydriver; rc = vpcidriver->suspend(tmpvpcidev, 0); } write_unlock_irqrestore(&VpcidevListLock, flags); if (!found) { LOGERR("**** FAILED to find vhba/vnic in the list\n"); return 0; } return rc; } static int virtpci_device_serverup(struct device *parentbus, int devtype, struct vhba_wwnn *wwnn, unsigned char macaddr[]) { int resumethisone = 0; bool found = false; struct virtpci_dev *tmpvpcidev, *prevvpcidev; struct virtpci_driver *vpcidriver; unsigned long flags; int rc = 0; if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { LOGERR("**** FAILED to resume device; devtype:%d not vhba:%d or vnic:%d\n", devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); return 0; } /* find the vhba or vnic in virtpci device list */ write_lock_irqsave(&VpcidevListLock, flags); for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; (tmpvpcidev && !found); prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) { if (tmpvpcidev->devtype != devtype) continue; if (devtype == VIRTHBA_TYPE) { resumethisone = ((tmpvpcidev->scsi.wwnn.wwnn1 == wwnn->wwnn1) && (tmpvpcidev->scsi.wwnn.wwnn2 == wwnn->wwnn2)); /* devtype is vhba, we're resuming vhba whose * wwnn matches the current device's wwnn */ } else { /* VIRTNIC_TYPE */ resumethisone = memcmp(tmpvpcidev->net.mac_addr, macaddr, MAX_MACADDR_LEN) == 0; /* devtype is vnic, we're resuming vnic whose * macaddr matches the current device's macaddr */ } if (!resumethisone) continue; found = true; vpcidriver = tmpvpcidev->mydriver; /* This should be done at BUS resume time, but an * existing problem prevents us from ever getting a bus * resume... This hack would fail to work should we * ever have a bus that contains NO devices, since we * would never even get here in that case. */ fix_vbus_devInfo(&tmpvpcidev->generic_dev, tmpvpcidev->deviceNo, tmpvpcidev->device, vpcidriver); rc = vpcidriver->resume(tmpvpcidev); } write_unlock_irqrestore(&VpcidevListLock, flags); if (!found) { LOGERR("**** FAILED to find vhba/vnic in the list\n"); return 0; } return rc; } static int virtpci_device_del(struct device *parentbus, int devtype, struct vhba_wwnn *wwnn, unsigned char macaddr[]) { int count = 0, all = 0, delthisone; struct virtpci_dev *tmpvpcidev, *prevvpcidev, *dellist = NULL; unsigned long flags; #define DEL_CONTINUE { \ prevvpcidev = tmpvpcidev;\ tmpvpcidev = tmpvpcidev->next;\ continue; \ } if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) { LOGERR("**** FAILED to delete device; devtype:%d not vhba:%d or vnic:%d\n", devtype, VIRTHBA_TYPE, VIRTNIC_TYPE); return 0; } /* see if we are to delete all - NOTE: all implies we have a * valid parentbus */ all = ((devtype == VIRTHBA_TYPE) && (wwnn == NULL)) || ((devtype == VIRTNIC_TYPE) && (macaddr == NULL)); /* find all the vhba or vnic or both in virtpci device list * keep list of ones we are deleting so we can call * device_unregister after we release the lock; otherwise we * encounter "schedule while atomic" */ write_lock_irqsave(&VpcidevListLock, flags); for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; tmpvpcidev;) { if (tmpvpcidev->devtype != devtype) DEL_CONTINUE; if (all) { delthisone = (tmpvpcidev->generic_dev.parent == parentbus); /* we're deleting all vhbas or vnics on the * specified parent bus */ } else if (devtype == VIRTHBA_TYPE) { delthisone = ((tmpvpcidev->scsi.wwnn.wwnn1 == wwnn->wwnn1) && (tmpvpcidev->scsi.wwnn.wwnn2 == wwnn->wwnn2)); /* devtype is vhba, we're deleting vhba whose * wwnn matches the current device's wwnn */ } else { /* VIRTNIC_TYPE */ delthisone = memcmp(tmpvpcidev->net.mac_addr, macaddr, MAX_MACADDR_LEN) == 0; /* devtype is vnic, we're deleting vnic whose * macaddr matches the current device's macaddr */ } if (!delthisone) DEL_CONTINUE; /* take vhba/vnic out of the list */ if (prevvpcidev) /* not at head */ prevvpcidev->next = tmpvpcidev->next; else VpcidevListHead = tmpvpcidev->next; /* add it to our deletelist */ tmpvpcidev->next = dellist; dellist = tmpvpcidev; count++; if (!all) break; /* done */ /* going to top of loop again - set tmpvpcidev to next * one we're to process */ if (prevvpcidev) tmpvpcidev = prevvpcidev->next; else tmpvpcidev = VpcidevListHead; } write_unlock_irqrestore(&VpcidevListLock, flags); if (!all && (count == 0)) { LOGERR("**** FAILED to find vhba/vnic in the list\n"); return 0; } /* now delete each one from delete list */ while (dellist) { /* save next */ tmpvpcidev = dellist->next; /* delete the vhba/vnic at dellist */ DELETE_ONE_VPCIDEV(dellist); /* do next */ dellist = tmpvpcidev; } return count; } static void virtpci_device_release(struct device *dev_) { /* this function is called when the last reference to the * device is removed */ LOGINF("In virtpci_device_release:%p - NOT YET IMPLEMENTED\n", dev_); } /*****************************************************/ /* Driver functions */ /*****************************************************/ #define kobj_to_device_driver(obj) container_of(obj, struct device_driver, kobj) #define attribute_to_driver_attribute(obj) \ container_of(obj, struct driver_attribute, attr) static ssize_t virtpci_driver_attr_show(struct kobject *kobj, struct attribute *attr, char *buf) { struct driver_attribute *dattr = attribute_to_driver_attribute(attr); ssize_t ret = 0; struct driver_private *dprivate = to_driver(kobj); struct device_driver *driver; if (dprivate != NULL) driver = dprivate->driver; else driver = NULL; DBGINF("In virtpci_driver_attr_show driver->name:%s\n", driver->name); if (driver) { if (dattr->show) ret = dattr->show(driver, buf); } return ret; } static ssize_t virtpci_driver_attr_store(struct kobject *kobj, struct attribute *attr, const char *buf, size_t count) { struct driver_attribute *dattr = attribute_to_driver_attribute(attr); ssize_t ret = 0; struct driver_private *dprivate = to_driver(kobj); struct device_driver *driver; if (dprivate != NULL) driver = dprivate->driver; else driver = NULL; DBGINF("In virtpci_driver_attr_store driver->name:%s\n", driver->name); if (driver) { if (dattr->store) ret = dattr->store(driver, buf, count); } return ret; } /* register a new virtpci driver */ int virtpci_register_driver(struct virtpci_driver *drv) { int result = 0; DBGINF("In virtpci_register_driver\n"); if (drv->id_table == NULL) { LOGERR("id_table missing\n"); return 1; } /* initialize core driver fields needed to call driver_register */ drv->core_driver.name = drv->name; /* name of driver in sysfs */ drv->core_driver.bus = &virtpci_bus_type; /* type of bus this * driver works with */ drv->core_driver.probe = virtpci_device_probe; /* called to query the * existence of a * specific device and * whether this driver *can work with it */ drv->core_driver.remove = virtpci_device_remove; /* called when the * device is removed * from the system */ /* register with core */ result = driver_register(&drv->core_driver); /* calls bus_add_driver which calls driver_attach and * module_add_driver */ if (result) return result; /* failed */ drv->core_driver.p->kobj.ktype = &virtpci_driver_kobj_type; return 0; } EXPORT_SYMBOL_GPL(virtpci_register_driver); void virtpci_unregister_driver(struct virtpci_driver *drv) { DBGINF("In virtpci_unregister_driver drv:%p\n", drv); driver_unregister(&drv->core_driver); /* driver_unregister calls bus_remove_driver * bus_remove_driver calls device_detach * device_detach calls device_release_driver for each of the * driver's devices * device_release driver calls drv->remove which is * virtpci_device_remove * virtpci_device_remove calls virthba_remove */ DBGINF("Leaving\n"); } EXPORT_SYMBOL_GPL(virtpci_unregister_driver); /*****************************************************/ /* proc filesystem functions */ /*****************************************************/ struct print_vbus_info { int *length; char *buf; }; static int print_vbus(struct device *vbus, void *data) { struct print_vbus_info *p = (struct print_vbus_info *) data; int l = *(p->length); *(p->length) = l + sprintf(p->buf + l, "bus_id:%s\n", dev_name(vbus)); return 0; /* no error */ } static ssize_t info_proc_read(struct file *file, char __user *buf, size_t len, loff_t *offset) { int length = 0; struct virtpci_dev *tmpvpcidev; unsigned long flags; struct print_vbus_info printparam; char *vbuf; loff_t pos = *offset; if (pos < 0) return -EINVAL; if (pos > 0 || !len) return 0; vbuf = kzalloc(len, GFP_KERNEL); if (!vbuf) return -ENOMEM; length += sprintf(vbuf + length, "CHANSOCK is not defined.\n"); length += sprintf(vbuf + length, "\n Virtual PCI Bus devices\n"); printparam.length = &length; printparam.buf = vbuf; if (bus_for_each_dev(&virtpci_bus_type, NULL, (void *) &printparam, print_vbus)) LOGERR("delete of all vbus failed\n"); length += sprintf(vbuf + length, "\n Virtual PCI devices\n"); read_lock_irqsave(&VpcidevListLock, flags); tmpvpcidev = VpcidevListHead; while (tmpvpcidev) { if (tmpvpcidev->devtype == VIRTHBA_TYPE) { length += sprintf(vbuf + length, "[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d", tmpvpcidev->busNo, tmpvpcidev->deviceNo, tmpvpcidev->scsi.wwnn.wwnn1, tmpvpcidev->scsi.wwnn.wwnn2, tmpvpcidev->scsi.max.max_channel, tmpvpcidev->scsi.max.max_id, tmpvpcidev->scsi.max.max_lun, tmpvpcidev->scsi.max.cmd_per_lun); } else { length += sprintf(vbuf + length, "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d", tmpvpcidev->busNo, tmpvpcidev->deviceNo, tmpvpcidev->net.mac_addr[0], tmpvpcidev->net.mac_addr[1], tmpvpcidev->net.mac_addr[2], tmpvpcidev->net.mac_addr[3], tmpvpcidev->net.mac_addr[4], tmpvpcidev->net.mac_addr[5], tmpvpcidev->net.num_rcv_bufs, tmpvpcidev->net.mtu); } length += sprintf(vbuf + length, " chanptr:%p\n", tmpvpcidev->queueinfo.chan); tmpvpcidev = tmpvpcidev->next; } read_unlock_irqrestore(&VpcidevListLock, flags); length += sprintf(vbuf + length, "\nModule build: Date:%s Time:%s\n", __DATE__, __TIME__); length += sprintf(vbuf + length, "\n"); if (copy_to_user(buf, vbuf, length)) { kfree(vbuf); return -EFAULT; } kfree(vbuf); *offset += length; return length; } static ssize_t virt_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos) { char buf[16]; int type, i, action = 0xffff; unsigned int busno, deviceno; void __iomem *chanptr; struct add_vbus_guestpart busaddparams; struct add_virt_guestpart addparams; struct del_vbus_guestpart busdelparams; struct del_virt_guestpart delparams; GUID dummyGuid = GUID0; #ifdef STORAGE_CHANNEL U64 storagechannel; #endif #define PRINT_USAGE_RETURN {\ LOGERR("usage: 0-0-<chanptr> ==> delete vhba\n"); \ LOGERR("usage: 0-1-<chanptr>-<busNo>-<deviceNo> ==> add vhba\n"); \ LOGERR("usage: 0-f-<busNo> ==> delete all vhbas\n"); \ LOGERR("\n"); \ LOGERR("usage: 1-0-<chanptr> ==> delete vnic\n"); \ LOGERR("usage: 1-1-<chanptr>-<busNo>-<deviceNo> ==> add vnic\n"); \ LOGERR("usage: 1-f-<busNo> ==> delete all vnics\n"); \ LOGERR("\n"); \ LOGERR("usage: 6-0-<busNo> ==> delete vbus\n"); \ LOGERR("usage: 6-1-<busNo> ==> add vbus\n"); \ LOGERR("usage: 6-f ==> delete all vbuses\n"); \ LOGERR("usage: 98-<busNo>-<deviceNo> ==> INJECT Client delete vnic\n"); \ LOGERR("usage: 99-<chanptr>-<busNo>-<deviceNo> ==> INJECT Client add vnic\n"); \ return -EINVAL; \ } if (count >= ARRAY_SIZE(buf)) return -EINVAL; if (copy_from_user(buf, buffer, count)) { LOGERR("copy_from_user failed.\n"); return -EFAULT; } i = sscanf(buf, "%x-%x", &type, &action); if (i < 2) PRINT_USAGE_RETURN; if (type == 0x98) { /* client inject delete vnic */ i = sscanf(buf, "%x-%d-%d", &type, &busno, &deviceno); if (i != 3) PRINT_USAGE_RETURN; uislib_client_inject_del_vnic(busno, deviceno); return count; /* success */ } else if (type == 0x99) { /* client inject add vnic */ i = sscanf(buf, "%x-%p-%d-%d", &type, &chanptr, &busno, &deviceno); if (i != 4) PRINT_USAGE_RETURN; if (!uislib_client_inject_add_vnic(busno, deviceno, __pa(chanptr), MIN_IO_CHANNEL_SIZE, 1, /* test msg */ dummyGuid, /* inst guid */ NULL)) { /*interrupt info */ LOGERR("FAILED to inject add vnic\n"); return -EFAULT; } return count; /* success */ } if ((type != VIRTHBA_TYPE) && (type != VIRTNIC_TYPE) && (type != VIRTBUS_TYPE)) PRINT_USAGE_RETURN; if (type == VIRTBUS_TYPE) { i = sscanf(buf, "%x-%x-%d", &type, &action, &busno); switch (action) { case 0: /* delete vbus */ if (i != 3) break; busdelparams.busNo = busno; if (delete_vbus(&busdelparams)) return count; /* success */ return -EFAULT; case 1: /* add vbus */ if (i != 3) break; busaddparams.chanptr = NULL; /* NOT YET USED */ busaddparams.busNo = busno; if (add_vbus(&busaddparams)) return count; /* success */ return -EFAULT; case 0xf: /* delete all vbuses and all vhbas/vnics on the buses */ if (i != 2) break; delete_all(); return count; /* success */ default: break; } PRINT_USAGE_RETURN; } /* if (type == VIRTNIC_TYPE) or if (type == VIRTHBA_TYPE) */ switch (action) { case 0: /* delete vhba/vnic */ i = sscanf(buf, "%x-%x-%p", &type, &action, &chanptr); if (i != 3) break; delparams.chanptr = chanptr; if (type == VIRTHBA_TYPE) { if (delete_vhba(&delparams)) return count; /* success */ } else { if (delete_vnic(&delparams)) return count; /* success */ } return -EFAULT; case 1: /* add vhba/vnic */ i = sscanf(buf, "%x-%x-%p-%d-%d", &type, &action, &chanptr, &busno, &deviceno); if (i != 5) break; addparams.chanptr = chanptr; addparams.busNo = busno; addparams.deviceNo = deviceno; if (type == VIRTHBA_TYPE) { if (add_vhba(&addparams)) return count; /* success */ } else { if (add_vnic(&addparams)) return count; /* success */ } return -EFAULT; #ifdef STORAGE_CHANNEL case 2: /* add vhba */ i = sscanf(buf, "%x-%x-%d-%d", &type, &action, &busno, &deviceno); if (i != 4) break; storagechannel = uislib_storage_channel(0); /* Get my storage channel */ /* ioremap_cache it now */ addparams.chanptr = (void *) ioremap_cache(storagechannel, IO_CHANNEL_SIZE); if (addparams.chanptr == NULL) { LOGERR("Failure to get remap storage channel.\n"); return -EFAULT; } addparams.busNo = busno; addparams.deviceNo = deviceno; if (type == VIRTHBA_TYPE) { if (add_vhba(&addparams)) return count; /* success */ } return -EFAULT; #endif case 0xf: /* delete all vhbas/vnics */ i = sscanf(buf, "%x-%x-%d", &type, &action, &busno); if (i != 3) break; busdelparams.busNo = busno; delete_all_virt(type, &busdelparams); return count; /* success */ default: break; } PRINT_USAGE_RETURN; } /*****************************************************/ /* Module Init & Exit functions */ /*****************************************************/ static int __init virtpci_mod_init(void) { int ret; LOGINF("Module build: Date:%s Time:%s...\n", __DATE__, __TIME__); POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO); ret = bus_register(&virtpci_bus_type); /* creates /sys/bus/uisvirtpci which contains devices & * drivers directory */ if (ret) { LOGERR("bus_register ****FAILED:%d\n", ret); POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, ret, POSTCODE_SEVERITY_ERR); return ret; } DBGINF("bus_register successful\n"); BusDeviceInfo_Init(&Bus_DriverInfo, "clientbus", "virtpci", VERSION, NULL, __DATE__, __TIME__); /* create a root bus used to parent all the virtpci buses. */ ret = device_register(&virtpci_rootbus_device); if (ret) { LOGERR("device_register FAILED:%d\n", ret); bus_unregister(&virtpci_bus_type); POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, ret, POSTCODE_SEVERITY_ERR); return ret; } DBGINF("device_register successful ret:%x\n", ret); if (!uisctrl_register_req_handler(2, (void *) &virtpci_ctrlchan_func, &Chipset_DriverInfo)) { LOGERR("uisctrl_register_req_handler ****FAILED.\n"); POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR); device_unregister(&virtpci_rootbus_device); bus_unregister(&virtpci_bus_type); return -1; } LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n", (void *) &virtpci_ctrlchan_func); /* create the proc directories */ virtpci_proc_dir = proc_mkdir(DIR_PROC_ENTRY, NULL); virt_proc_entry = proc_create(VIRT_PROC_ENTRY_FN, 0, virtpci_proc_dir, &proc_virt_fops); info_proc_entry = proc_create(INFO_PROC_ENTRY_FN, 0, virtpci_proc_dir, &proc_info_fops); LOGINF("Leaving\n"); POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO); return 0; } static void __exit virtpci_mod_exit(void) { LOGINF("virtpci_mod_exit...\n"); /* unregister the callback function */ if (!uisctrl_register_req_handler(2, NULL, NULL)) LOGERR("uisctrl_register_req_handler ****FAILED.\n"); device_unregister(&virtpci_rootbus_device); bus_unregister(&virtpci_bus_type); if (virt_proc_entry) remove_proc_entry(VIRT_PROC_ENTRY_FN, virtpci_proc_dir); if (info_proc_entry) remove_proc_entry(INFO_PROC_ENTRY_FN, virtpci_proc_dir); if (virtpci_proc_dir) remove_proc_entry(DIR_PROC_ENTRY, NULL); LOGINF("Leaving\n"); } module_init(virtpci_mod_init); module_exit(virtpci_mod_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Usha Srinivasan"); MODULE_ALIAS("uisvirtpci"); |