3 * Copyright (C) 2010 - 2013 UNISYS CORPORATION
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14 * NON INFRINGEMENT. See the GNU General Public License for more
20 #include <linux/kernel.h>
21 #ifdef CONFIG_MODVERSIONS
22 #include <config/modversions.h>
25 #include "diagnostics/appos_subsystems.h"
27 #include "vbuschannel.h"
28 #include "vbushelper.h"
29 #include <linux/types.h>
31 #include <linux/uuid.h>
32 #include <linux/module.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/device.h>
36 #include <linux/list.h>
37 #include <linux/slab.h>
38 #include <linux/mod_devicetable.h>
39 #include <linux/if_ether.h>
40 #include <linux/version.h>
41 #include <linux/debugfs.h>
43 #include "guestlinuxdebug.h"
46 struct driver_private {
48 struct klist klist_devices;
49 struct klist_node knode_bus;
50 struct module_kobject *mkobj;
51 struct device_driver *driver;
53 #define to_driver(obj) container_of(obj, struct driver_private, kobj)
55 /* bus_id went away in 2.6.30 - the size was 20 bytes, so we'll define
56 * it ourselves, and a macro to make getting the field a bit simpler.
59 #define BUS_ID_SIZE 20
62 #define BUS_ID(x) dev_name(x)
64 /* MAX_BUF = 4 busses x ( 32 devices/bus + 1 busline) x 80 characters
65 * = 10,560 bytes ~ 2^14 = 16,384 bytes
71 /* this is shorter than using __FILE__ (full path name) in
72 * debug/info/error messages
74 #define CURRENT_FILE_PC VIRT_PCI_PC_virtpci_c
75 #define __MYFILE__ "virtpci.c"
77 #define VIRTPCI_VERSION "01.00"
79 /*****************************************************/
80 /* Forward declarations */
81 /*****************************************************/
83 static int delete_vbus_device(struct device *vbus, void *data);
84 static int match_busid(struct device *dev, void *data);
85 static void virtpci_bus_release(struct device *dev);
86 static void virtpci_device_release(struct device *dev);
87 static int virtpci_device_add(struct device *parentbus, int devtype,
88 struct add_virt_guestpart *addparams,
89 struct scsi_adap_info *scsi,
90 struct net_adap_info *net);
91 static int virtpci_device_del(struct device *parentbus, int devtype,
92 struct vhba_wwnn *wwnn, unsigned char macaddr[]);
93 static int virtpci_device_serverdown(struct device *parentbus, int devtype,
94 struct vhba_wwnn *wwnn,
95 unsigned char macaddr[]);
96 static int virtpci_device_serverup(struct device *parentbus, int devtype,
97 struct vhba_wwnn *wwnn,
98 unsigned char macaddr[]);
99 static ssize_t virtpci_driver_attr_show(struct kobject *kobj,
100 struct attribute *attr, char *buf);
101 static ssize_t virtpci_driver_attr_store(struct kobject *kobj,
102 struct attribute *attr,
103 const char *buf, size_t count);
104 static int virtpci_bus_match(struct device *dev, struct device_driver *drv);
105 static int virtpci_uevent(struct device *dev, struct kobj_uevent_env *env);
106 static int virtpci_device_suspend(struct device *dev, pm_message_t state);
107 static int virtpci_device_resume(struct device *dev);
108 static int virtpci_device_probe(struct device *dev);
109 static int virtpci_device_remove(struct device *dev);
111 static ssize_t info_debugfs_read(struct file *file, char __user *buf,
112 size_t len, loff_t *offset);
114 static const struct file_operations debugfs_info_fops = {
115 .read = info_debugfs_read,
118 /*****************************************************/
120 /*****************************************************/
122 /* methods in bus_type struct allow the bus code to serve as an
123 * intermediary between the device core and individual device core and
126 static struct bus_type virtpci_bus_type = {
127 .name = "uisvirtpci",
128 .match = virtpci_bus_match,
129 .uevent = virtpci_uevent,
130 .suspend = virtpci_device_suspend,
131 .resume = virtpci_device_resume,
134 static struct device virtpci_rootbus_device = {
135 .init_name = "vbusroot", /* root bus */
136 .release = virtpci_bus_release
139 /* filled in with info about parent chipset driver when we register with it */
140 static ULTRA_VBUS_DEVICEINFO Chipset_DriverInfo;
142 static const struct sysfs_ops virtpci_driver_sysfs_ops = {
143 .show = virtpci_driver_attr_show,
144 .store = virtpci_driver_attr_store,
147 static struct kobj_type virtpci_driver_kobj_type = {
148 .sysfs_ops = &virtpci_driver_sysfs_ops,
151 static struct virtpci_dev *VpcidevListHead;
152 static DEFINE_RWLOCK(VpcidevListLock);
154 /* filled in with info about this driver, wrt it servicing client busses */
155 static ULTRA_VBUS_DEVICEINFO Bus_DriverInfo;
157 /*****************************************************/
158 /* debugfs entries */
159 /*****************************************************/
160 /* dentry is used to create the debugfs entry directory
163 static struct dentry *virtpci_debugfs_dir;
165 struct virtpci_busdev {
166 struct device virtpci_bus_device;
169 /*****************************************************/
170 /* Local functions */
171 /*****************************************************/
174 int WAIT_FOR_IO_CHANNEL(ULTRA_IO_CHANNEL_PROTOCOL __iomem *chanptr)
180 if (ULTRA_CHANNEL_SERVER_READY(&chanptr->ChannelHeader))
182 UIS_THREAD_WAIT_SEC(1);
188 /* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.ChpInfo. */
189 static int write_vbus_chpInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
190 ULTRA_VBUS_DEVICEINFO *info)
195 LOGERR("vbus channel not present");
198 off = sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.chpInfoByteOffset;
199 if (chan->HdrInfo.chpInfoByteOffset == 0) {
200 LOGERR("vbus channel not used, because chpInfoByteOffset == 0");
203 memcpy(((u8 *) (chan)) + off, info, sizeof(*info));
207 /* Write the contents of <info> to the ULTRA_VBUS_CHANNEL_PROTOCOL.BusInfo. */
208 static int write_vbus_busInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
209 ULTRA_VBUS_DEVICEINFO *info)
214 LOGERR("vbus channel not present");
217 off = sizeof(ULTRA_CHANNEL_PROTOCOL) + chan->HdrInfo.busInfoByteOffset;
218 if (chan->HdrInfo.busInfoByteOffset == 0) {
219 LOGERR("vbus channel not used, because busInfoByteOffset == 0");
222 memcpy(((u8 *) (chan)) + off, info, sizeof(*info));
226 /* Write the contents of <info> to the
227 * ULTRA_VBUS_CHANNEL_PROTOCOL.DevInfo[<devix>].
230 write_vbus_devInfo(ULTRA_VBUS_CHANNEL_PROTOCOL *chan,
231 ULTRA_VBUS_DEVICEINFO *info, int devix)
236 LOGERR("vbus channel not present");
240 (sizeof(ULTRA_CHANNEL_PROTOCOL) +
241 chan->HdrInfo.devInfoByteOffset) +
242 (chan->HdrInfo.deviceInfoStructBytes * devix);
243 if (chan->HdrInfo.devInfoByteOffset == 0) {
244 LOGERR("vbus channel not used, because devInfoByteOffset == 0");
247 memcpy(((u8 *) (chan)) + off, info, sizeof(*info));
252 * returns 0 failure, 1 success,
254 static int add_vbus(struct add_vbus_guestpart *addparams)
259 vbus = kzalloc(sizeof(struct device), GFP_ATOMIC);
261 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
265 dev_set_name(vbus, "vbus%d", addparams->busNo);
266 vbus->release = virtpci_bus_release;
267 vbus->parent = &virtpci_rootbus_device; /* root bus is parent */
268 vbus->bus = &virtpci_bus_type; /* bus type */
269 vbus->platform_data = (__force void *)addparams->chanptr;
271 /* register a virt bus device -
272 * this bus shows up under /sys/devices with .name value
273 * "virtpci%d" any devices added to this bus then show up under
274 * /sys/devices/virtpci0
276 ret = device_register(vbus);
278 LOGERR("device_register FAILED:%d\n", ret);
279 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
282 write_vbus_chpInfo(vbus->platform_data /* chanptr */ ,
283 &Chipset_DriverInfo);
284 write_vbus_busInfo(vbus->platform_data /* chanptr */ , &Bus_DriverInfo);
285 LOGINF("Added vbus %d; device %s created successfully\n",
286 addparams->busNo, BUS_ID(vbus));
287 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
291 /* for CHANSOCK wwwnn/max are AUTO-GENERATED; for normal channels,
292 * wwnn/max are in the channel header.
294 #define GET_SCSIADAPINFO_FROM_CHANPTR(chanptr) { \
295 memcpy_fromio(&scsi.wwnn, \
296 &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \
297 chanptr)->vhba.wwnn, \
298 sizeof(struct vhba_wwnn)); \
299 memcpy_fromio(&scsi.max, \
300 &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \
301 chanptr)->vhba.max, \
302 sizeof(struct vhba_config_max)); \
305 /* find bus device with the busid that matches - match_busid matches bus_id */
306 #define GET_BUS_DEV(busno) { \
307 sprintf(busid, "vbus%d", busno); \
308 vbus = bus_find_device(&virtpci_bus_type, NULL, \
309 (void *)busid, match_busid); \
311 LOGERR("**** FAILED to find vbus %s\n", busid); \
317 * returns 0 failure, 1 success,
319 static int add_vhba(struct add_virt_guestpart *addparams)
322 struct scsi_adap_info scsi;
324 unsigned char busid[BUS_ID_SIZE];
326 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
327 if (!WAIT_FOR_IO_CHANNEL
328 ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) addparams->chanptr)) {
329 LOGERR("Timed out. Channel not ready\n");
330 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
334 GET_SCSIADAPINFO_FROM_CHANPTR(addparams->chanptr);
336 GET_BUS_DEV(addparams->bus_no);
338 LOGINF("Adding vhba wwnn:%x:%x config:%d-%d-%d-%d chanptr:%p\n",
339 scsi.wwnn.wwnn1, scsi.wwnn.wwnn2,
340 scsi.max.max_channel, scsi.max.max_id, scsi.max.max_lun,
341 scsi.max.cmd_per_lun, addparams->chanptr);
342 i = virtpci_device_add(vbus, VIRTHBA_TYPE, addparams, &scsi, NULL);
344 LOGINF("Added vhba wwnn:%x:%x chanptr:%p\n", scsi.wwnn.wwnn1,
345 scsi.wwnn.wwnn2, addparams->chanptr);
346 POSTCODE_LINUX_3(VPCI_CREATE_EXIT_PC, i,
347 POSTCODE_SEVERITY_INFO);
353 /* for CHANSOCK macaddr is AUTO-GENERATED; for normal channels,
354 * macaddr is in the channel header.
356 #define GET_NETADAPINFO_FROM_CHANPTR(chanptr) { \
357 memcpy_fromio(net.mac_addr, \
358 ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \
359 chanptr)->vnic.macaddr, \
362 readl(&((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \
363 chanptr)->vnic.num_rcv_bufs); \
364 net.mtu = readl(&((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \
365 chanptr)->vnic.mtu); \
366 memcpy_fromio(&net.zoneGuid, \
367 &((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) \
368 chanptr)->vnic.zoneGuid, \
373 * returns 0 failure, 1 success,
376 add_vnic(struct add_virt_guestpart *addparams)
379 struct net_adap_info net;
381 unsigned char busid[BUS_ID_SIZE];
383 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
384 if (!WAIT_FOR_IO_CHANNEL
385 ((ULTRA_IO_CHANNEL_PROTOCOL __iomem *) addparams->chanptr)) {
386 LOGERR("Timed out, channel not ready\n");
387 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
391 GET_NETADAPINFO_FROM_CHANPTR(addparams->chanptr);
393 GET_BUS_DEV(addparams->bus_no);
395 LOGINF("Adding vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x rcvbufs:%d mtu:%d chanptr:%p%pUL\n",
396 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2], net.mac_addr[3],
397 net.mac_addr[4], net.mac_addr[5], net.num_rcv_bufs, net.mtu,
398 addparams->chanptr, &net.zoneGuid);
399 i = virtpci_device_add(vbus, VIRTNIC_TYPE, addparams, NULL, &net);
401 LOGINF("Added vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
402 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
403 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
404 POSTCODE_LINUX_3(VPCI_CREATE_EXIT_PC, i,
405 POSTCODE_SEVERITY_INFO);
412 * returns 0 failure, 1 success,
415 delete_vbus(struct del_vbus_guestpart *delparams)
418 unsigned char busid[BUS_ID_SIZE];
420 GET_BUS_DEV(delparams->bus_no);
421 /* ensure that bus has no devices? -- TBD */
422 LOGINF("Deleting %s\n", BUS_ID(vbus));
423 if (delete_vbus_device(vbus, NULL))
424 return 0; /* failure */
425 LOGINF("Deleted vbus %d\n", delparams->bus_no);
430 delete_vbus_device(struct device *vbus, void *data)
432 int checkforroot = (data != NULL);
433 struct device *pDev = &virtpci_rootbus_device;
435 if ((checkforroot) && match_busid(vbus, (void *) BUS_ID(pDev))) {
436 /* skip it - don't delete root bus */
437 LOGINF("skipping root bus\n");
438 return 0; /* pretend no error */
440 LOGINF("Calling unregister for %s\n", BUS_ID(vbus));
441 device_unregister(vbus);
443 LOGINF("VBus unregister and freed\n");
444 return 0; /* no error */
448 * returns 0 failure, 1 success,
450 static int pause_vhba(struct pause_virt_guestpart *pauseparams)
453 struct scsi_adap_info scsi;
455 GET_SCSIADAPINFO_FROM_CHANPTR(pauseparams->chanptr);
457 LOGINF("Pausing vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2);
458 i = virtpci_device_serverdown(NULL /*no parent bus */ , VIRTHBA_TYPE,
461 LOGINF("Paused vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1,
467 * returns 0 failure, 1 success,
469 static int pause_vnic(struct pause_virt_guestpart *pauseparams)
472 struct net_adap_info net;
474 GET_NETADAPINFO_FROM_CHANPTR(pauseparams->chanptr);
476 LOGINF("Pausing vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
477 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
478 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
479 i = virtpci_device_serverdown(NULL /*no parent bus */ , VIRTNIC_TYPE,
482 LOGINF(" Paused vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
483 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
484 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
490 * returns 0 failure, 1 success,
492 static int resume_vhba(struct resume_virt_guestpart *resumeparams)
495 struct scsi_adap_info scsi;
497 GET_SCSIADAPINFO_FROM_CHANPTR(resumeparams->chanptr);
499 LOGINF("Resuming vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2);
500 i = virtpci_device_serverup(NULL /*no parent bus */ , VIRTHBA_TYPE,
503 LOGINF("Resumed vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1,
509 * returns 0 failure, 1 success,
512 resume_vnic(struct resume_virt_guestpart *resumeparams)
515 struct net_adap_info net;
517 GET_NETADAPINFO_FROM_CHANPTR(resumeparams->chanptr);
519 LOGINF("Resuming vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
520 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
521 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
522 i = virtpci_device_serverup(NULL /*no parent bus */ , VIRTNIC_TYPE,
525 LOGINF(" Resumed vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
526 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
527 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
533 * returns 0 failure, 1 success,
535 static int delete_vhba(struct del_virt_guestpart *delparams)
538 struct scsi_adap_info scsi;
540 GET_SCSIADAPINFO_FROM_CHANPTR(delparams->chanptr);
542 LOGINF("Deleting vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1, scsi.wwnn.wwnn2);
543 i = virtpci_device_del(NULL /*no parent bus */ , VIRTHBA_TYPE,
546 LOGINF("Deleted vhba wwnn:%x:%x\n", scsi.wwnn.wwnn1,
554 * returns 0 failure, 1 success,
556 static int delete_vnic(struct del_virt_guestpart *delparams)
559 struct net_adap_info net;
561 GET_NETADAPINFO_FROM_CHANPTR(delparams->chanptr);
563 LOGINF("Deleting vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
564 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
565 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
566 i = virtpci_device_del(NULL /*no parent bus */ , VIRTNIC_TYPE, NULL,
569 LOGINF("Deleted vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
570 net.mac_addr[0], net.mac_addr[1], net.mac_addr[2],
571 net.mac_addr[3], net.mac_addr[4], net.mac_addr[5]);
576 #define DELETE_ONE_VPCIDEV(vpcidev) { \
577 LOGINF("calling device_unregister:%p\n", &vpcidev->generic_dev); \
578 device_unregister(&vpcidev->generic_dev); \
579 LOGINF("Deleted %p\n", vpcidev); \
583 /* deletes all vhbas and vnics
584 * returns 0 failure, 1 success,
586 static void delete_all(void)
590 struct virtpci_dev *tmpvpcidev, *nextvpcidev;
592 /* delete the entire vhba/vnic list in one shot */
593 write_lock_irqsave(&VpcidevListLock, flags);
594 tmpvpcidev = VpcidevListHead;
595 VpcidevListHead = NULL;
596 write_unlock_irqrestore(&VpcidevListLock, flags);
598 /* delete one vhba/vnic at a time */
600 nextvpcidev = tmpvpcidev->next;
601 /* delete the vhba/vnic at tmpvpcidev */
602 DELETE_ONE_VPCIDEV(tmpvpcidev);
603 tmpvpcidev = nextvpcidev;
606 LOGINF("Deleted %d vhbas/vnics.\n", count);
608 /* now delete each vbus */
610 (&virtpci_bus_type, NULL, (void *) 1, delete_vbus_device))
611 LOGERR("delete of all vbus failed\n");
614 /* deletes all vnics or vhbas
615 * returns 0 failure, 1 success,
617 static int delete_all_virt(VIRTPCI_DEV_TYPE devtype, struct del_vbus_guestpart *delparams)
620 unsigned char busid[BUS_ID_SIZE];
623 GET_BUS_DEV(delparams->bus_no);
625 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
626 LOGERR("**** FAILED to delete all devices; devtype:%d not vhba:%d or vnic:%d\n",
627 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
631 LOGINF("Deleting all %s in vbus %s\n",
632 devtype == VIRTHBA_TYPE ? "vhbas" : "vnics", busid);
633 /* delete all vhbas/vnics */
634 i = virtpci_device_del(vbus, devtype, NULL, NULL);
636 LOGINF("Deleted %d %s\n", i,
637 devtype == VIRTHBA_TYPE ? "vhbas" : "vnics");
641 static int virtpci_ctrlchan_func(struct guest_msgs *msg)
643 switch (msg->msgtype) {
645 return add_vbus(&msg->add_vbus);
647 return add_vhba(&msg->add_vhba);
649 return add_vnic(&msg->add_vnic);
651 return delete_vbus(&msg->del_vbus);
653 return delete_vhba(&msg->del_vhba);
655 return delete_vnic(&msg->del_vhba);
656 case GUEST_DEL_ALL_VHBAS:
657 return delete_all_virt(VIRTHBA_TYPE, &msg->del_all_vhbas);
658 case GUEST_DEL_ALL_VNICS:
659 return delete_all_virt(VIRTNIC_TYPE, &msg->del_all_vnics);
660 case GUEST_DEL_ALL_VBUSES:
663 case GUEST_PAUSE_VHBA:
664 return pause_vhba(&msg->pause_vhba);
665 case GUEST_PAUSE_VNIC:
666 return pause_vnic(&msg->pause_vnic);
667 case GUEST_RESUME_VHBA:
668 return resume_vhba(&msg->resume_vhba);
669 case GUEST_RESUME_VNIC:
670 return resume_vnic(&msg->resume_vnic);
672 LOGERR("invalid message type %d.\n", msg->msgtype);
677 /* same as driver_helper in bus.c linux */
678 static int match_busid(struct device *dev, void *data)
680 const char *name = data;
682 if (strcmp(name, BUS_ID(dev)) == 0)
687 /*****************************************************/
689 /*****************************************************/
691 static const struct pci_device_id *
692 virtpci_match_device(const struct pci_device_id *ids,
693 const struct virtpci_dev *dev)
695 while (ids->vendor || ids->subvendor || ids->class_mask) {
696 DBGINF("ids->vendor:%x dev->vendor:%x ids->device:%x dev->device:%x\n",
697 ids->vendor, dev->vendor, ids->device, dev->device);
699 if ((ids->vendor == dev->vendor)
700 && (ids->device == dev->device))
708 /* NOTE: !!!!!! This function is called when a new device is added
709 * for this bus. Or, it is called for existing devices when a new
710 * driver is added for this bus. It returns nonzero if a given device
711 * can be handled by the given driver.
713 static int virtpci_bus_match(struct device *dev, struct device_driver *drv)
715 struct virtpci_dev *virtpcidev = device_to_virtpci_dev(dev);
716 struct virtpci_driver *virtpcidrv = driver_to_virtpci_driver(drv);
719 DBGINF("In virtpci_bus_match dev->bus_id:%s drv->name:%s\n",
720 dev->bus_id, drv->name);
722 /* check ids list for a match */
723 if (virtpci_match_device(virtpcidrv->id_table, virtpcidev))
726 DBGINF("returning match:%d\n", match);
727 return match; /* 0 - no match; 1 - yes it matches */
730 static int virtpci_uevent(struct device *dev, struct kobj_uevent_env *env)
732 DBGINF("In virtpci_hotplug\n");
733 /* add variables to the environment prior to the generation of
734 * hotplug events to user space
736 if (add_uevent_var(env, "VIRTPCI_VERSION=%s", VIRTPCI_VERSION))
741 static int virtpci_device_suspend(struct device *dev, pm_message_t state)
743 DBGINF("In virtpci_device_suspend -NYI ****\n");
747 static int virtpci_device_resume(struct device *dev)
749 DBGINF("In virtpci_device_resume -NYI ****\n");
753 /* For a child device just created on a client bus, fill in
754 * information about the driver that is controlling this device into
755 * the the appropriate slot within the vbus channel of the bus
758 static void fix_vbus_devInfo(struct device *dev, int devNo, int devType,
759 struct virtpci_driver *virtpcidrv)
763 ULTRA_VBUS_DEVICEINFO devInfo;
767 LOGERR("%s dev is NULL", __func__);
771 LOGERR("%s driver is NULL", __func__);
776 LOGERR("%s dev has no parent bus", __func__);
779 pChan = vbus->platform_data;
781 LOGERR("%s dev bus has no channel", __func__);
785 case PCI_DEVICE_ID_VIRTHBA:
788 case PCI_DEVICE_ID_VIRTNIC:
795 BusDeviceInfo_Init(&devInfo, stype,
799 write_vbus_devInfo(pChan, &devInfo, devNo);
801 /* Re-write bus+chipset info, because it is possible that this
802 * was previously written by our good counterpart, visorbus.
804 write_vbus_chpInfo(pChan, &Chipset_DriverInfo);
805 write_vbus_busInfo(pChan, &Bus_DriverInfo);
808 /* This function is called to query the existence of a specific device
809 * and whether this driver can work with it. It should return -ENODEV
810 * in case of failure.
812 static int virtpci_device_probe(struct device *dev)
814 struct virtpci_dev *virtpcidev = device_to_virtpci_dev(dev);
815 struct virtpci_driver *virtpcidrv =
816 driver_to_virtpci_driver(dev->driver);
817 const struct pci_device_id *id;
820 LOGINF("In virtpci_device_probe dev:%p virtpcidev:%p virtpcidrv:%p\n",
821 dev, virtpcidev, virtpcidrv); /* VERBOSE/DEBUG ? */
822 POSTCODE_LINUX_2(VPCI_PROBE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
823 /* static match and static probe vs dynamic match & dynamic
824 * probe - do we care?.
826 if (!virtpcidrv->id_table)
829 id = virtpci_match_device(virtpcidrv->id_table, virtpcidev);
833 /* increment reference count */
836 /* if virtpcidev is not already claimed & probe function is
839 if (!virtpcidev->mydriver && virtpcidrv->probe) {
840 /* call the probe function - virthba or virtnic probe
841 * is what it should be
843 error = virtpcidrv->probe(virtpcidev, id);
845 fix_vbus_devInfo(dev, virtpcidev->deviceNo,
846 virtpcidev->device, virtpcidrv);
847 virtpcidev->mydriver = virtpcidrv;
848 POSTCODE_LINUX_2(VPCI_PROBE_EXIT_PC,
849 POSTCODE_SEVERITY_INFO);
853 POSTCODE_LINUX_2(VPCI_PROBE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
854 return error; /* -ENODEV for probe failure */
857 static int virtpci_device_remove(struct device *dev_)
859 /* dev_ passed in is the HBA device which we called
860 * generic_dev in our virtpcidev struct
862 struct virtpci_dev *virtpcidev = device_to_virtpci_dev(dev_);
863 struct virtpci_driver *virtpcidrv = virtpcidev->mydriver;
865 LOGINF("In virtpci_device_remove bus_id:%s dev_:%p virtpcidev:%p dev->driver:%p drivername:%s\n",
866 BUS_ID(dev_), dev_, virtpcidev, dev_->driver,
867 dev_->driver->name); /* VERBOSE/DEBUG */
869 /* TEMP: assuming we have only one such driver for now */
870 if (virtpcidrv->remove)
871 virtpcidrv->remove(virtpcidev);
872 virtpcidev->mydriver = NULL;
875 DBGINF("calling putdevice\n");
882 /*****************************************************/
884 /*****************************************************/
886 static void virtpci_bus_release(struct device *dev)
888 /* this function is called when the last reference to the
891 DBGINF("In virtpci_bus_release\n");
892 /* what else is supposed to happen here? */
895 /*****************************************************/
896 /* Adapter functions */
897 /*****************************************************/
899 static int virtpci_device_add(struct device *parentbus, int devtype,
900 struct add_virt_guestpart *addparams,
901 struct scsi_adap_info *scsi, /* NULL for VNIC add */
902 struct net_adap_info *net /* NULL for VHBA add */)
904 struct virtpci_dev *virtpcidev = NULL;
905 struct virtpci_dev *tmpvpcidev = NULL, *prev;
908 ULTRA_IO_CHANNEL_PROTOCOL __iomem *pIoChan = NULL;
911 LOGINF("virtpci_device_add parentbus:%p chanptr:%p\n", parentbus,
914 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
916 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
917 LOGERR("**** FAILED to add device; devtype:%d not vhba:%d or vnic:%d\n",
918 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
919 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, devtype,
920 POSTCODE_SEVERITY_ERR);
924 /* add a Virtual Device */
925 virtpcidev = kzalloc(sizeof(struct virtpci_dev), GFP_ATOMIC);
926 if (virtpcidev == NULL) {
927 LOGERR("can't add device - malloc FALLED\n");
928 POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
932 /* initialize stuff unique to virtpci_dev struct */
933 virtpcidev->devtype = devtype;
934 if (devtype == VIRTHBA_TYPE) {
935 virtpcidev->device = PCI_DEVICE_ID_VIRTHBA;
936 virtpcidev->scsi = *scsi;
938 virtpcidev->device = PCI_DEVICE_ID_VIRTNIC;
939 virtpcidev->net = *net;
941 virtpcidev->vendor = PCI_VENDOR_ID_UNISYS;
942 virtpcidev->busNo = addparams->bus_no;
943 virtpcidev->deviceNo = addparams->device_no;
945 virtpcidev->queueinfo.chan = addparams->chanptr;
946 virtpcidev->queueinfo.send_int_if_needed = NULL;
948 /* Set up safe queue... */
949 pIoChan = (ULTRA_IO_CHANNEL_PROTOCOL __iomem *)
950 virtpcidev->queueinfo.chan;
952 virtpcidev->intr = addparams->intr;
954 /* initialize stuff in the device portion of the struct */
955 virtpcidev->generic_dev.bus = &virtpci_bus_type;
956 virtpcidev->generic_dev.parent = parentbus;
957 virtpcidev->generic_dev.release = virtpci_device_release;
959 dev_set_name(&virtpcidev->generic_dev, "%x:%x",
960 addparams->bus_no, addparams->device_no);
962 /* add the vhba/vnic to virtpci device list - but check for
963 * duplicate wwnn/macaddr first
965 write_lock_irqsave(&VpcidevListLock, flags);
966 for (tmpvpcidev = VpcidevListHead; tmpvpcidev;
967 tmpvpcidev = tmpvpcidev->next) {
968 if (devtype == VIRTHBA_TYPE) {
969 if ((tmpvpcidev->scsi.wwnn.wwnn1 == scsi->wwnn.wwnn1) &&
970 (tmpvpcidev->scsi.wwnn.wwnn2 == scsi->wwnn.wwnn2)) {
971 /* duplicate - already have vpcidev
977 (tmpvpcidev->net.mac_addr, net->mac_addr,
978 MAX_MACADDR_LEN) == 0) {
979 /* duplicate - already have vnic with this wwnn */
984 /* found a vhba/vnic already in the list with same
985 * wwnn or macaddr - reject add
987 write_unlock_irqrestore(&VpcidevListLock, flags);
989 LOGERR("**** FAILED vhba/vnic already exists in the list\n");
990 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
994 /* add it at the head */
995 if (!VpcidevListHead)
996 VpcidevListHead = virtpcidev;
998 /* insert virtpcidev at the head of our linked list of
1001 virtpcidev->next = VpcidevListHead;
1002 VpcidevListHead = virtpcidev;
1005 write_unlock_irqrestore(&VpcidevListLock, flags);
1007 /* Must transition channel to ATTACHED state BEFORE
1008 * registering the device, because polling of the channel
1009 * queues can begin at any time after device_register().
1011 pDev = &virtpcidev->generic_dev;
1012 ULTRA_CHANNEL_CLIENT_TRANSITION(addparams->chanptr,
1014 CHANNELCLI_ATTACHED, NULL);
1016 /* don't register until device has been added to
1017 * list. Otherwise, a device_unregister from this function can
1018 * cause a "scheduling while atomic".
1020 DBGINF("registering device:%p with bus_id:%s\n",
1021 &virtpcidev->generic_dev, virtpcidev->generic_dev.bus_id);
1022 ret = device_register(&virtpcidev->generic_dev);
1023 /* NOTE: THIS IS CALLING HOTPLUG virtpci_hotplug!!!
1024 * This call to device_register results in virtpci_bus_match
1025 * being called !!!!! And, if match returns success, then
1026 * virtpcidev->generic_dev.driver is setup to core_driver,
1027 * i.e., virtpci and the probe function
1028 * virtpcidev->generic_dev.driver->probe is called which
1029 * results in virtpci_device_probe being called. And if
1030 * virtpci_device_probe is successful
1033 LOGERR("device_register returned %d\n", ret);
1034 pDev = &virtpcidev->generic_dev;
1035 ULTRA_CHANNEL_CLIENT_TRANSITION(addparams->chanptr,
1037 CHANNELCLI_DETACHED, NULL);
1038 /* remove virtpcidev, the one we just added, from the list */
1039 write_lock_irqsave(&VpcidevListLock, flags);
1040 for (tmpvpcidev = VpcidevListHead, prev = NULL;
1042 prev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) {
1043 if (tmpvpcidev == virtpcidev) {
1045 prev->next = tmpvpcidev->next;
1047 VpcidevListHead = tmpvpcidev->next;
1051 write_unlock_irqrestore(&VpcidevListLock, flags);
1056 LOGINF("Added %s:%d:%d &virtpcidev->generic_dev:%p\n",
1057 (devtype == VIRTHBA_TYPE) ? "virthba" : "virtnic",
1058 addparams->bus_no, addparams->device_no,
1059 &virtpcidev->generic_dev);
1060 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
1064 static int virtpci_device_serverdown(struct device *parentbus,
1066 struct vhba_wwnn *wwnn,
1067 unsigned char macaddr[])
1069 int pausethisone = 0;
1071 struct virtpci_dev *tmpvpcidev, *prevvpcidev;
1072 struct virtpci_driver *vpcidriver;
1073 unsigned long flags;
1076 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
1077 LOGERR("**** FAILED to pause device; devtype:%d not vhba:%d or vnic:%d\n",
1078 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
1082 /* find the vhba or vnic in virtpci device list */
1083 write_lock_irqsave(&VpcidevListLock, flags);
1085 for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL;
1086 (tmpvpcidev && !found);
1087 prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) {
1088 if (tmpvpcidev->devtype != devtype)
1091 if (devtype == VIRTHBA_TYPE) {
1093 ((tmpvpcidev->scsi.wwnn.wwnn1 == wwnn->wwnn1) &&
1094 (tmpvpcidev->scsi.wwnn.wwnn2 == wwnn->wwnn2));
1095 /* devtype is vhba, we're pausing vhba whose
1096 * wwnn matches the current device's wwnn
1098 } else { /* VIRTNIC_TYPE */
1100 memcmp(tmpvpcidev->net.mac_addr, macaddr,
1101 MAX_MACADDR_LEN) == 0;
1102 /* devtype is vnic, we're pausing vnic whose
1103 * macaddr matches the current device's macaddr */
1110 vpcidriver = tmpvpcidev->mydriver;
1111 rc = vpcidriver->suspend(tmpvpcidev, 0);
1113 write_unlock_irqrestore(&VpcidevListLock, flags);
1116 LOGERR("**** FAILED to find vhba/vnic in the list\n");
1123 static int virtpci_device_serverup(struct device *parentbus,
1125 struct vhba_wwnn *wwnn,
1126 unsigned char macaddr[])
1128 int resumethisone = 0;
1130 struct virtpci_dev *tmpvpcidev, *prevvpcidev;
1131 struct virtpci_driver *vpcidriver;
1132 unsigned long flags;
1135 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
1136 LOGERR("**** FAILED to resume device; devtype:%d not vhba:%d or vnic:%d\n",
1137 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
1141 /* find the vhba or vnic in virtpci device list */
1142 write_lock_irqsave(&VpcidevListLock, flags);
1144 for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL;
1145 (tmpvpcidev && !found);
1146 prevvpcidev = tmpvpcidev, tmpvpcidev = tmpvpcidev->next) {
1147 if (tmpvpcidev->devtype != devtype)
1150 if (devtype == VIRTHBA_TYPE) {
1152 ((tmpvpcidev->scsi.wwnn.wwnn1 == wwnn->wwnn1) &&
1153 (tmpvpcidev->scsi.wwnn.wwnn2 == wwnn->wwnn2));
1154 /* devtype is vhba, we're resuming vhba whose
1155 * wwnn matches the current device's wwnn */
1156 } else { /* VIRTNIC_TYPE */
1158 memcmp(tmpvpcidev->net.mac_addr, macaddr,
1159 MAX_MACADDR_LEN) == 0;
1160 /* devtype is vnic, we're resuming vnic whose
1161 * macaddr matches the current device's macaddr */
1168 vpcidriver = tmpvpcidev->mydriver;
1169 /* This should be done at BUS resume time, but an
1170 * existing problem prevents us from ever getting a bus
1171 * resume... This hack would fail to work should we
1172 * ever have a bus that contains NO devices, since we
1173 * would never even get here in that case.
1175 fix_vbus_devInfo(&tmpvpcidev->generic_dev, tmpvpcidev->deviceNo,
1176 tmpvpcidev->device, vpcidriver);
1177 rc = vpcidriver->resume(tmpvpcidev);
1180 write_unlock_irqrestore(&VpcidevListLock, flags);
1183 LOGERR("**** FAILED to find vhba/vnic in the list\n");
1190 static int virtpci_device_del(struct device *parentbus,
1191 int devtype, struct vhba_wwnn *wwnn,
1192 unsigned char macaddr[])
1194 int count = 0, all = 0, delthisone;
1195 struct virtpci_dev *tmpvpcidev, *prevvpcidev, *dellist = NULL;
1196 unsigned long flags;
1198 #define DEL_CONTINUE { \
1199 prevvpcidev = tmpvpcidev;\
1200 tmpvpcidev = tmpvpcidev->next;\
1204 if ((devtype != VIRTHBA_TYPE) && (devtype != VIRTNIC_TYPE)) {
1205 LOGERR("**** FAILED to delete device; devtype:%d not vhba:%d or vnic:%d\n",
1206 devtype, VIRTHBA_TYPE, VIRTNIC_TYPE);
1210 /* see if we are to delete all - NOTE: all implies we have a
1213 all = ((devtype == VIRTHBA_TYPE) && (wwnn == NULL)) ||
1214 ((devtype == VIRTNIC_TYPE) && (macaddr == NULL));
1216 /* find all the vhba or vnic or both in virtpci device list
1217 * keep list of ones we are deleting so we can call
1218 * device_unregister after we release the lock; otherwise we
1219 * encounter "schedule while atomic"
1221 write_lock_irqsave(&VpcidevListLock, flags);
1222 for (tmpvpcidev = VpcidevListHead, prevvpcidev = NULL; tmpvpcidev;) {
1223 if (tmpvpcidev->devtype != devtype)
1228 (tmpvpcidev->generic_dev.parent == parentbus);
1229 /* we're deleting all vhbas or vnics on the
1230 * specified parent bus
1232 } else if (devtype == VIRTHBA_TYPE) {
1234 ((tmpvpcidev->scsi.wwnn.wwnn1 == wwnn->wwnn1) &&
1235 (tmpvpcidev->scsi.wwnn.wwnn2 == wwnn->wwnn2));
1236 /* devtype is vhba, we're deleting vhba whose
1237 * wwnn matches the current device's wwnn
1239 } else { /* VIRTNIC_TYPE */
1241 memcmp(tmpvpcidev->net.mac_addr, macaddr,
1242 MAX_MACADDR_LEN) == 0;
1243 /* devtype is vnic, we're deleting vnic whose
1244 * macaddr matches the current device's macaddr
1251 /* take vhba/vnic out of the list */
1254 prevvpcidev->next = tmpvpcidev->next;
1256 VpcidevListHead = tmpvpcidev->next;
1258 /* add it to our deletelist */
1259 tmpvpcidev->next = dellist;
1260 dellist = tmpvpcidev;
1265 /* going to top of loop again - set tmpvpcidev to next
1266 * one we're to process
1269 tmpvpcidev = prevvpcidev->next;
1271 tmpvpcidev = VpcidevListHead;
1273 write_unlock_irqrestore(&VpcidevListLock, flags);
1275 if (!all && (count == 0)) {
1276 LOGERR("**** FAILED to find vhba/vnic in the list\n");
1280 /* now delete each one from delete list */
1283 tmpvpcidev = dellist->next;
1284 /* delete the vhba/vnic at dellist */
1285 DELETE_ONE_VPCIDEV(dellist);
1287 dellist = tmpvpcidev;
1293 static void virtpci_device_release(struct device *dev_)
1295 /* this function is called when the last reference to the
1298 LOGINF("In virtpci_device_release:%p - NOT YET IMPLEMENTED\n", dev_);
1301 /*****************************************************/
1302 /* Driver functions */
1303 /*****************************************************/
1305 #define kobj_to_device_driver(obj) container_of(obj, struct device_driver, kobj)
1306 #define attribute_to_driver_attribute(obj) \
1307 container_of(obj, struct driver_attribute, attr)
1309 static ssize_t virtpci_driver_attr_show(struct kobject *kobj,
1310 struct attribute *attr,
1313 struct driver_attribute *dattr = attribute_to_driver_attribute(attr);
1316 struct driver_private *dprivate = to_driver(kobj);
1317 struct device_driver *driver;
1319 if (dprivate != NULL)
1320 driver = dprivate->driver;
1324 DBGINF("In virtpci_driver_attr_show driver->name:%s\n", driver->name);
1327 ret = dattr->show(driver, buf);
1332 static ssize_t virtpci_driver_attr_store(struct kobject *kobj,
1333 struct attribute *attr,
1334 const char *buf, size_t count)
1336 struct driver_attribute *dattr = attribute_to_driver_attribute(attr);
1339 struct driver_private *dprivate = to_driver(kobj);
1340 struct device_driver *driver;
1342 if (dprivate != NULL)
1343 driver = dprivate->driver;
1347 DBGINF("In virtpci_driver_attr_store driver->name:%s\n", driver->name);
1351 ret = dattr->store(driver, buf, count);
1356 /* register a new virtpci driver */
1357 int virtpci_register_driver(struct virtpci_driver *drv)
1361 DBGINF("In virtpci_register_driver\n");
1363 if (drv->id_table == NULL) {
1364 LOGERR("id_table missing\n");
1367 /* initialize core driver fields needed to call driver_register */
1368 drv->core_driver.name = drv->name; /* name of driver in sysfs */
1369 drv->core_driver.bus = &virtpci_bus_type; /* type of bus this
1370 * driver works with */
1371 drv->core_driver.probe = virtpci_device_probe; /* called to query the
1373 * specific device and
1374 * whether this driver
1375 *can work with it */
1376 drv->core_driver.remove = virtpci_device_remove; /* called when the
1378 * from the system */
1379 /* register with core */
1380 result = driver_register(&drv->core_driver);
1381 /* calls bus_add_driver which calls driver_attach and
1385 return result; /* failed */
1387 drv->core_driver.p->kobj.ktype = &virtpci_driver_kobj_type;
1391 EXPORT_SYMBOL_GPL(virtpci_register_driver);
1393 void virtpci_unregister_driver(struct virtpci_driver *drv)
1395 DBGINF("In virtpci_unregister_driver drv:%p\n", drv);
1396 driver_unregister(&drv->core_driver);
1397 /* driver_unregister calls bus_remove_driver
1398 * bus_remove_driver calls device_detach
1399 * device_detach calls device_release_driver for each of the
1401 * device_release driver calls drv->remove which is
1402 * virtpci_device_remove
1403 * virtpci_device_remove calls virthba_remove
1405 DBGINF("Leaving\n");
1407 EXPORT_SYMBOL_GPL(virtpci_unregister_driver);
1409 /*****************************************************/
1410 /* debugfs filesystem functions */
1411 /*****************************************************/
1412 struct print_vbus_info {
1418 static int print_vbus(struct device *vbus, void *data)
1420 struct print_vbus_info *p = (struct print_vbus_info *)data;
1422 *p->str_pos += scnprintf(p->buf + *p->str_pos, *p->len - *p->str_pos,
1423 "bus_id:%s\n", dev_name(vbus));
1427 static ssize_t info_debugfs_read(struct file *file, char __user *buf,
1428 size_t len, loff_t *offset)
1430 ssize_t bytes_read = 0;
1432 struct virtpci_dev *tmpvpcidev;
1433 unsigned long flags;
1434 struct print_vbus_info printparam;
1439 vbuf = kzalloc(len, GFP_KERNEL);
1443 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1444 " Virtual PCI Bus devices\n");
1445 printparam.str_pos = &str_pos;
1446 printparam.buf = vbuf;
1447 printparam.len = &len;
1448 if (bus_for_each_dev(&virtpci_bus_type, NULL,
1449 (void *) &printparam, print_vbus))
1450 LOGERR("Failed to find bus\n");
1452 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1453 "\n Virtual PCI devices\n");
1454 read_lock_irqsave(&VpcidevListLock, flags);
1455 tmpvpcidev = VpcidevListHead;
1456 while (tmpvpcidev) {
1457 if (tmpvpcidev->devtype == VIRTHBA_TYPE) {
1458 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1459 "[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
1460 tmpvpcidev->busNo, tmpvpcidev->deviceNo,
1461 tmpvpcidev->scsi.wwnn.wwnn1,
1462 tmpvpcidev->scsi.wwnn.wwnn2,
1463 tmpvpcidev->scsi.max.max_channel,
1464 tmpvpcidev->scsi.max.max_id,
1465 tmpvpcidev->scsi.max.max_lun,
1466 tmpvpcidev->scsi.max.cmd_per_lun);
1468 str_pos += scnprintf(vbuf + str_pos, len - str_pos,
1469 "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
1470 tmpvpcidev->busNo, tmpvpcidev->deviceNo,
1471 tmpvpcidev->net.mac_addr[0],
1472 tmpvpcidev->net.mac_addr[1],
1473 tmpvpcidev->net.mac_addr[2],
1474 tmpvpcidev->net.mac_addr[3],
1475 tmpvpcidev->net.mac_addr[4],
1476 tmpvpcidev->net.mac_addr[5],
1477 tmpvpcidev->net.num_rcv_bufs,
1478 tmpvpcidev->net.mtu);
1480 str_pos += scnprintf(vbuf + str_pos,
1481 len - str_pos, " chanptr:%p\n",
1482 tmpvpcidev->queueinfo.chan);
1483 tmpvpcidev = tmpvpcidev->next;
1485 read_unlock_irqrestore(&VpcidevListLock, flags);
1487 str_pos += scnprintf(vbuf + str_pos, len - str_pos, "\n");
1488 bytes_read = simple_read_from_buffer(buf, len, offset, vbuf, str_pos);
1493 /*****************************************************/
1494 /* Module Init & Exit functions */
1495 /*****************************************************/
1497 static int __init virtpci_mod_init(void)
1502 if (!unisys_spar_platform)
1505 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
1507 ret = bus_register(&virtpci_bus_type);
1508 /* creates /sys/bus/uisvirtpci which contains devices &
1512 LOGERR("bus_register ****FAILED:%d\n", ret);
1513 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, ret,
1514 POSTCODE_SEVERITY_ERR);
1517 DBGINF("bus_register successful\n");
1518 BusDeviceInfo_Init(&Bus_DriverInfo, "clientbus", "virtpci",
1521 /* create a root bus used to parent all the virtpci buses. */
1522 ret = device_register(&virtpci_rootbus_device);
1524 LOGERR("device_register FAILED:%d\n", ret);
1525 bus_unregister(&virtpci_bus_type);
1526 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC, ret,
1527 POSTCODE_SEVERITY_ERR);
1530 DBGINF("device_register successful ret:%x\n", ret);
1532 if (!uisctrl_register_req_handler(2, (void *) &virtpci_ctrlchan_func,
1533 &Chipset_DriverInfo)) {
1534 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1535 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC, POSTCODE_SEVERITY_ERR);
1536 device_unregister(&virtpci_rootbus_device);
1537 bus_unregister(&virtpci_bus_type);
1541 LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
1542 (void *) &virtpci_ctrlchan_func);
1543 /* create debugfs directory and info file inside. */
1544 virtpci_debugfs_dir = debugfs_create_dir("virtpci", NULL);
1545 debugfs_create_file("info", S_IRUSR, virtpci_debugfs_dir,
1546 NULL, &debugfs_info_fops);
1547 LOGINF("Leaving\n");
1548 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC, POSTCODE_SEVERITY_INFO);
1552 static void __exit virtpci_mod_exit(void)
1554 LOGINF("virtpci_mod_exit...\n");
1556 /* unregister the callback function */
1557 if (!uisctrl_register_req_handler(2, NULL, NULL))
1558 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1560 device_unregister(&virtpci_rootbus_device);
1561 bus_unregister(&virtpci_bus_type);
1562 debugfs_remove_recursive(virtpci_debugfs_dir);
1563 LOGINF("Leaving\n");
1567 module_init(virtpci_mod_init);
1568 module_exit(virtpci_mod_exit);
1569 MODULE_LICENSE("GPL");
1570 MODULE_AUTHOR("Usha Srinivasan");
1571 MODULE_ALIAS("uisvirtpci");