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
;
54 #define to_driver(obj) container_of(obj, struct driver_private, kobj)
56 /* bus_id went away in 2.6.30 - the size was 20 bytes, so we'll define
57 * it ourselves, and a macro to make getting the field a bit simpler.
60 #define BUS_ID_SIZE 20
63 #define BUS_ID(x) dev_name(x)
65 /* MAX_BUF = 4 busses x ( 32 devices/bus + 1 busline) x 80 characters
66 * = 10,560 bytes ~ 2^14 = 16,384 bytes
72 /* this is shorter than using __FILE__ (full path name) in
73 * debug/info/error messages
75 #define CURRENT_FILE_PC VIRT_PCI_PC_virtpci_c
76 #define __MYFILE__ "virtpci.c"
78 #define VIRTPCI_VERSION "01.00"
80 /*****************************************************/
81 /* Forward declarations */
82 /*****************************************************/
84 static int delete_vbus_device(struct device
*vbus
, void *data
);
85 static int match_busid(struct device
*dev
, void *data
);
86 static void virtpci_bus_release(struct device
*dev
);
87 static void virtpci_device_release(struct device
*dev
);
88 static int virtpci_device_add(struct device
*parentbus
, int devtype
,
89 struct add_virt_guestpart
*addparams
,
90 struct scsi_adap_info
*scsi
,
91 struct net_adap_info
*net
);
92 static int virtpci_device_del(struct device
*parentbus
, int devtype
,
93 struct vhba_wwnn
*wwnn
, unsigned char macaddr
[]);
94 static int virtpci_device_serverdown(struct device
*parentbus
, int devtype
,
95 struct vhba_wwnn
*wwnn
,
96 unsigned char macaddr
[]);
97 static int virtpci_device_serverup(struct device
*parentbus
, int devtype
,
98 struct vhba_wwnn
*wwnn
,
99 unsigned char macaddr
[]);
100 static ssize_t
virtpci_driver_attr_show(struct kobject
*kobj
,
101 struct attribute
*attr
, char *buf
);
102 static ssize_t
virtpci_driver_attr_store(struct kobject
*kobj
,
103 struct attribute
*attr
,
104 const char *buf
, size_t count
);
105 static int virtpci_bus_match(struct device
*dev
, struct device_driver
*drv
);
106 static int virtpci_uevent(struct device
*dev
, struct kobj_uevent_env
*env
);
107 static int virtpci_device_suspend(struct device
*dev
, pm_message_t state
);
108 static int virtpci_device_resume(struct device
*dev
);
109 static int virtpci_device_probe(struct device
*dev
);
110 static int virtpci_device_remove(struct device
*dev
);
112 static ssize_t
info_debugfs_read(struct file
*file
, char __user
*buf
,
113 size_t len
, loff_t
*offset
);
115 static const struct file_operations debugfs_info_fops
= {
116 .read
= info_debugfs_read
,
119 /*****************************************************/
121 /*****************************************************/
123 /* methods in bus_type struct allow the bus code to serve as an
124 * intermediary between the device core and individual device core and
127 static struct bus_type virtpci_bus_type
= {
128 .name
= "uisvirtpci",
129 .match
= virtpci_bus_match
,
130 .uevent
= virtpci_uevent
,
131 .suspend
= virtpci_device_suspend
,
132 .resume
= virtpci_device_resume
,
135 static struct device virtpci_rootbus_device
= {
136 .init_name
= "vbusroot", /* root bus */
137 .release
= virtpci_bus_release
140 /* filled in with info about parent chipset driver when we register with it */
141 static struct ultra_vbus_deviceinfo Chipset_DriverInfo
;
143 static const struct sysfs_ops virtpci_driver_sysfs_ops
= {
144 .show
= virtpci_driver_attr_show
,
145 .store
= virtpci_driver_attr_store
,
148 static struct kobj_type virtpci_driver_kobj_type
= {
149 .sysfs_ops
= &virtpci_driver_sysfs_ops
,
152 static struct virtpci_dev
*VpcidevListHead
;
153 static DEFINE_RWLOCK(VpcidevListLock
);
155 /* filled in with info about this driver, wrt it servicing client busses */
156 static struct ultra_vbus_deviceinfo Bus_DriverInfo
;
158 /*****************************************************/
159 /* debugfs entries */
160 /*****************************************************/
161 /* dentry is used to create the debugfs entry directory
164 static struct dentry
*virtpci_debugfs_dir
;
166 struct virtpci_busdev
{
167 struct device virtpci_bus_device
;
170 /*****************************************************/
171 /* Local functions */
172 /*****************************************************/
175 int WAIT_FOR_IO_CHANNEL(struct spar_io_channel_protocol __iomem
*chanptr
)
180 if (SPAR_CHANNEL_SERVER_READY(&chanptr
->channel_header
))
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(struct spar_vbus_channel_protocol
*chan
,
190 struct ultra_vbus_deviceinfo
*info
)
195 LOGERR("vbus channel not present");
198 off
= sizeof(struct channel_header
) + chan
->hdr_info
.chp_info_offset
;
199 if (chan
->hdr_info
.chp_info_offset
== 0) {
200 LOGERR("vbus channel not used, because chp_info_offset == 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(struct spar_vbus_channel_protocol
*chan
,
209 struct ultra_vbus_deviceinfo
*info
)
214 LOGERR("vbus channel not present");
217 off
= sizeof(struct channel_header
) + chan
->hdr_info
.bus_info_offset
;
218 if (chan
->hdr_info
.bus_info_offset
== 0) {
219 LOGERR("vbus channel not used, because bus_info_offset == 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(struct spar_vbus_channel_protocol
*chan
,
231 struct ultra_vbus_deviceinfo
*info
, int devix
)
236 LOGERR("vbus channel not present");
240 (sizeof(struct channel_header
) +
241 chan
->hdr_info
.dev_info_offset
) +
242 (chan
->hdr_info
.device_info_struct_bytes
* devix
);
243 if (chan
->hdr_info
.dev_info_offset
== 0) {
244 LOGERR("vbus channel not used, because dev_info_offset == 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(*vbus
), GFP_ATOMIC
);
261 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
265 dev_set_name(vbus
, "vbus%d", addparams
->bus_no
);
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
->bus_no
, 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 &((struct spar_io_channel_protocol __iomem *) \
297 chanptr)->vhba.wwnn, \
298 sizeof(struct vhba_wwnn)); \
299 memcpy_fromio(&scsi.max, \
300 &((struct spar_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 ((struct spar_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
);
352 /* for CHANSOCK macaddr is AUTO-GENERATED; for normal channels,
353 * macaddr is in the channel header.
355 #define GET_NETADAPINFO_FROM_CHANPTR(chanptr) { \
356 memcpy_fromio(net.mac_addr, \
357 ((struct spar_io_channel_protocol __iomem *) \
358 chanptr)->vnic.macaddr, \
361 readl(&((struct spar_io_channel_protocol __iomem *)\
362 chanptr)->vnic.num_rcv_bufs); \
363 net.mtu = readl(&((struct spar_io_channel_protocol __iomem *) \
364 chanptr)->vnic.mtu); \
365 memcpy_fromio(&net.zone_uuid, \
366 &((struct spar_io_channel_protocol __iomem *)\
367 chanptr)->vnic.zone_uuid, \
372 * returns 0 failure, 1 success,
375 add_vnic(struct add_virt_guestpart
*addparams
)
378 struct net_adap_info net
;
380 unsigned char busid
[BUS_ID_SIZE
];
382 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
383 if (!WAIT_FOR_IO_CHANNEL
384 ((struct spar_io_channel_protocol __iomem
*)addparams
->chanptr
)) {
385 LOGERR("Timed out, channel not ready\n");
386 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC
, POSTCODE_SEVERITY_ERR
);
390 GET_NETADAPINFO_FROM_CHANPTR(addparams
->chanptr
);
392 GET_BUS_DEV(addparams
->bus_no
);
394 LOGINF("Adding vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x rcvbufs:%d mtu:%d chanptr:%p%pUL\n",
395 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
396 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5],
397 net
.num_rcv_bufs
, net
.mtu
, addparams
->chanptr
, &net
.zone_uuid
);
398 i
= virtpci_device_add(vbus
, VIRTNIC_TYPE
, addparams
, NULL
, &net
);
400 LOGINF("Added vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
401 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
402 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
403 POSTCODE_LINUX_3(VPCI_CREATE_EXIT_PC
, i
,
404 POSTCODE_SEVERITY_INFO
);
411 * returns 0 failure, 1 success,
414 delete_vbus(struct del_vbus_guestpart
*delparams
)
417 unsigned char busid
[BUS_ID_SIZE
];
419 GET_BUS_DEV(delparams
->bus_no
);
420 /* ensure that bus has no devices? -- TBD */
421 LOGINF("Deleting %s\n", BUS_ID(vbus
));
422 if (delete_vbus_device(vbus
, NULL
))
423 return 0; /* failure */
424 LOGINF("Deleted vbus %d\n", delparams
->bus_no
);
429 delete_vbus_device(struct device
*vbus
, void *data
)
431 int checkforroot
= (data
!= NULL
);
432 struct device
*pDev
= &virtpci_rootbus_device
;
434 if ((checkforroot
) && match_busid(vbus
, (void *)BUS_ID(pDev
))) {
435 /* skip it - don't delete root bus */
436 LOGINF("skipping root bus\n");
437 return 0; /* pretend no error */
439 LOGINF("Calling unregister for %s\n", BUS_ID(vbus
));
440 device_unregister(vbus
);
442 LOGINF("VBus unregister and freed\n");
443 return 0; /* no error */
447 * returns 0 failure, 1 success,
449 static int pause_vhba(struct pause_virt_guestpart
*pauseparams
)
452 struct scsi_adap_info scsi
;
454 GET_SCSIADAPINFO_FROM_CHANPTR(pauseparams
->chanptr
);
456 LOGINF("Pausing vhba wwnn:%x:%x\n", scsi
.wwnn
.wwnn1
, scsi
.wwnn
.wwnn2
);
457 i
= virtpci_device_serverdown(NULL
/*no parent bus */ , VIRTHBA_TYPE
,
460 LOGINF("Paused vhba wwnn:%x:%x\n", scsi
.wwnn
.wwnn1
,
466 * returns 0 failure, 1 success,
468 static int pause_vnic(struct pause_virt_guestpart
*pauseparams
)
471 struct net_adap_info net
;
473 GET_NETADAPINFO_FROM_CHANPTR(pauseparams
->chanptr
);
475 LOGINF("Pausing vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
476 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
477 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
478 i
= virtpci_device_serverdown(NULL
/*no parent bus */ , VIRTNIC_TYPE
,
481 LOGINF(" Paused vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
482 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
483 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
489 * returns 0 failure, 1 success,
491 static int resume_vhba(struct resume_virt_guestpart
*resumeparams
)
494 struct scsi_adap_info scsi
;
496 GET_SCSIADAPINFO_FROM_CHANPTR(resumeparams
->chanptr
);
498 LOGINF("Resuming vhba wwnn:%x:%x\n", scsi
.wwnn
.wwnn1
, scsi
.wwnn
.wwnn2
);
499 i
= virtpci_device_serverup(NULL
/*no parent bus */ , VIRTHBA_TYPE
,
502 LOGINF("Resumed vhba wwnn:%x:%x\n", scsi
.wwnn
.wwnn1
,
508 * returns 0 failure, 1 success,
511 resume_vnic(struct resume_virt_guestpart
*resumeparams
)
514 struct net_adap_info net
;
516 GET_NETADAPINFO_FROM_CHANPTR(resumeparams
->chanptr
);
518 LOGINF("Resuming vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
519 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
520 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
521 i
= virtpci_device_serverup(NULL
/*no parent bus */ , VIRTNIC_TYPE
,
524 LOGINF(" Resumed vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
525 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
526 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
532 * returns 0 failure, 1 success,
534 static int delete_vhba(struct del_virt_guestpart
*delparams
)
537 struct scsi_adap_info scsi
;
539 GET_SCSIADAPINFO_FROM_CHANPTR(delparams
->chanptr
);
541 LOGINF("Deleting vhba wwnn:%x:%x\n", scsi
.wwnn
.wwnn1
, scsi
.wwnn
.wwnn2
);
542 i
= virtpci_device_del(NULL
/*no parent bus */ , VIRTHBA_TYPE
,
545 LOGINF("Deleted vhba wwnn:%x:%x\n", scsi
.wwnn
.wwnn1
,
553 * returns 0 failure, 1 success,
555 static int delete_vnic(struct del_virt_guestpart
*delparams
)
558 struct net_adap_info net
;
560 GET_NETADAPINFO_FROM_CHANPTR(delparams
->chanptr
);
562 LOGINF("Deleting vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
563 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
564 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
565 i
= virtpci_device_del(NULL
/*no parent bus */ , VIRTNIC_TYPE
, NULL
,
568 LOGINF("Deleted vnic macaddr:%02x:%02x:%02x:%02x:%02x:%02x\n",
569 net
.mac_addr
[0], net
.mac_addr
[1], net
.mac_addr
[2],
570 net
.mac_addr
[3], net
.mac_addr
[4], net
.mac_addr
[5]);
575 #define DELETE_ONE_VPCIDEV(vpcidev) { \
576 LOGINF("calling device_unregister:%p\n", &vpcidev->generic_dev); \
577 device_unregister(&vpcidev->generic_dev); \
578 LOGINF("Deleted %p\n", vpcidev); \
582 /* deletes all vhbas and vnics
583 * returns 0 failure, 1 success,
585 static void delete_all(void)
589 struct virtpci_dev
*tmpvpcidev
, *nextvpcidev
;
591 /* delete the entire vhba/vnic list in one shot */
592 write_lock_irqsave(&VpcidevListLock
, flags
);
593 tmpvpcidev
= VpcidevListHead
;
594 VpcidevListHead
= NULL
;
595 write_unlock_irqrestore(&VpcidevListLock
, flags
);
597 /* delete one vhba/vnic at a time */
599 nextvpcidev
= tmpvpcidev
->next
;
600 /* delete the vhba/vnic at tmpvpcidev */
601 DELETE_ONE_VPCIDEV(tmpvpcidev
);
602 tmpvpcidev
= nextvpcidev
;
605 LOGINF("Deleted %d vhbas/vnics.\n", count
);
607 /* now delete each vbus */
609 (&virtpci_bus_type
, NULL
, (void *)1, delete_vbus_device
))
610 LOGERR("delete of all vbus failed\n");
613 /* deletes all vnics or vhbas
614 * returns 0 failure, 1 success,
616 static int delete_all_virt(enum virtpci_dev_type devtype
,
617 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 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 struct 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 bus_device_info_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
->device_no
,
846 virtpcidev
->device
, virtpcidrv
);
847 virtpcidev
->mydriver
= virtpcidrv
;
848 POSTCODE_LINUX_2(VPCI_PROBE_EXIT_PC
,
849 POSTCODE_SEVERITY_INFO
);
854 POSTCODE_LINUX_2(VPCI_PROBE_FAILURE_PC
, POSTCODE_SEVERITY_ERR
);
855 return error
; /* -ENODEV for probe failure */
858 static int virtpci_device_remove(struct device
*dev_
)
860 /* dev_ passed in is the HBA device which we called
861 * generic_dev in our virtpcidev struct
863 struct virtpci_dev
*virtpcidev
= device_to_virtpci_dev(dev_
);
864 struct virtpci_driver
*virtpcidrv
= virtpcidev
->mydriver
;
866 LOGINF("In virtpci_device_remove bus_id:%s dev_:%p virtpcidev:%p dev->driver:%p drivername:%s\n",
867 BUS_ID(dev_
), dev_
, virtpcidev
, dev_
->driver
,
868 dev_
->driver
->name
); /* VERBOSE/DEBUG */
870 /* TEMP: assuming we have only one such driver for now */
871 if (virtpcidrv
->remove
)
872 virtpcidrv
->remove(virtpcidev
);
873 virtpcidev
->mydriver
= NULL
;
876 DBGINF("calling putdevice\n");
883 /*****************************************************/
885 /*****************************************************/
887 static void virtpci_bus_release(struct device
*dev
)
889 /* this function is called when the last reference to the
892 DBGINF("In virtpci_bus_release\n");
893 /* what else is supposed to happen here? */
896 /*****************************************************/
897 /* Adapter functions */
898 /*****************************************************/
900 static int virtpci_device_add(struct device
*parentbus
, int devtype
,
901 struct add_virt_guestpart
*addparams
,
902 struct scsi_adap_info
*scsi
, /* NULL for VNIC add */
903 struct net_adap_info
*net
/* NULL for VHBA add */)
905 struct virtpci_dev
*virtpcidev
= NULL
;
906 struct virtpci_dev
*tmpvpcidev
= NULL
, *prev
;
909 struct spar_io_channel_protocol __iomem
*pIoChan
= NULL
;
912 LOGINF("virtpci_device_add parentbus:%p chanptr:%p\n", parentbus
,
915 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
917 if ((devtype
!= VIRTHBA_TYPE
) && (devtype
!= VIRTNIC_TYPE
)) {
918 LOGERR("**** FAILED to add device; devtype:%d not vhba:%d or vnic:%d\n",
919 devtype
, VIRTHBA_TYPE
, VIRTNIC_TYPE
);
920 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC
, devtype
,
921 POSTCODE_SEVERITY_ERR
);
925 /* add a Virtual Device */
926 virtpcidev
= kzalloc(sizeof(*virtpcidev
), GFP_ATOMIC
);
927 if (virtpcidev
== NULL
) {
928 LOGERR("can't add device - malloc FALLED\n");
929 POSTCODE_LINUX_2(MALLOC_FAILURE_PC
, POSTCODE_SEVERITY_ERR
);
933 /* initialize stuff unique to virtpci_dev struct */
934 virtpcidev
->devtype
= devtype
;
935 if (devtype
== VIRTHBA_TYPE
) {
936 virtpcidev
->device
= PCI_DEVICE_ID_VIRTHBA
;
937 virtpcidev
->scsi
= *scsi
;
939 virtpcidev
->device
= PCI_DEVICE_ID_VIRTNIC
;
940 virtpcidev
->net
= *net
;
942 virtpcidev
->vendor
= PCI_VENDOR_ID_UNISYS
;
943 virtpcidev
->bus_no
= addparams
->bus_no
;
944 virtpcidev
->device_no
= addparams
->device_no
;
946 virtpcidev
->queueinfo
.chan
= addparams
->chanptr
;
947 virtpcidev
->queueinfo
.send_int_if_needed
= NULL
;
949 /* Set up safe queue... */
950 pIoChan
= (struct spar_io_channel_protocol __iomem
*)
951 virtpcidev
->queueinfo
.chan
;
953 virtpcidev
->intr
= addparams
->intr
;
955 /* initialize stuff in the device portion of the struct */
956 virtpcidev
->generic_dev
.bus
= &virtpci_bus_type
;
957 virtpcidev
->generic_dev
.parent
= parentbus
;
958 virtpcidev
->generic_dev
.release
= virtpci_device_release
;
960 dev_set_name(&virtpcidev
->generic_dev
, "%x:%x",
961 addparams
->bus_no
, addparams
->device_no
);
963 /* add the vhba/vnic to virtpci device list - but check for
964 * duplicate wwnn/macaddr first
966 write_lock_irqsave(&VpcidevListLock
, flags
);
967 for (tmpvpcidev
= VpcidevListHead
; tmpvpcidev
;
968 tmpvpcidev
= tmpvpcidev
->next
) {
969 if (devtype
== VIRTHBA_TYPE
) {
970 if ((tmpvpcidev
->scsi
.wwnn
.wwnn1
== scsi
->wwnn
.wwnn1
) &&
971 (tmpvpcidev
->scsi
.wwnn
.wwnn2
== scsi
->wwnn
.wwnn2
)) {
972 /* duplicate - already have vpcidev
978 (tmpvpcidev
->net
.mac_addr
, net
->mac_addr
,
979 MAX_MACADDR_LEN
) == 0) {
980 /* duplicate - already have vnic with this wwnn */
985 /* found a vhba/vnic already in the list with same
986 * wwnn or macaddr - reject add
988 write_unlock_irqrestore(&VpcidevListLock
, flags
);
990 LOGERR("**** FAILED vhba/vnic already exists in the list\n");
991 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC
, POSTCODE_SEVERITY_ERR
);
995 /* add it at the head */
996 if (!VpcidevListHead
) {
997 VpcidevListHead
= virtpcidev
;
999 /* insert virtpcidev at the head of our linked list of
1002 virtpcidev
->next
= VpcidevListHead
;
1003 VpcidevListHead
= virtpcidev
;
1006 write_unlock_irqrestore(&VpcidevListLock
, flags
);
1008 /* Must transition channel to ATTACHED state BEFORE
1009 * registering the device, because polling of the channel
1010 * queues can begin at any time after device_register().
1012 pDev
= &virtpcidev
->generic_dev
;
1013 SPAR_CHANNEL_CLIENT_TRANSITION(addparams
->chanptr
,
1015 CHANNELCLI_ATTACHED
, NULL
);
1017 /* don't register until device has been added to
1018 * list. Otherwise, a device_unregister from this function can
1019 * cause a "scheduling while atomic".
1021 DBGINF("registering device:%p with bus_id:%s\n",
1022 &virtpcidev
->generic_dev
, virtpcidev
->generic_dev
.bus_id
);
1023 ret
= device_register(&virtpcidev
->generic_dev
);
1024 /* NOTE: THIS IS CALLING HOTPLUG virtpci_hotplug!!!
1025 * This call to device_register results in virtpci_bus_match
1026 * being called !!!!! And, if match returns success, then
1027 * virtpcidev->generic_dev.driver is setup to core_driver,
1028 * i.e., virtpci and the probe function
1029 * virtpcidev->generic_dev.driver->probe is called which
1030 * results in virtpci_device_probe being called. And if
1031 * virtpci_device_probe is successful
1034 LOGERR("device_register returned %d\n", ret
);
1035 pDev
= &virtpcidev
->generic_dev
;
1036 SPAR_CHANNEL_CLIENT_TRANSITION(addparams
->chanptr
,
1038 CHANNELCLI_DETACHED
, NULL
);
1039 /* remove virtpcidev, the one we just added, from the list */
1040 write_lock_irqsave(&VpcidevListLock
, flags
);
1041 for (tmpvpcidev
= VpcidevListHead
, prev
= NULL
;
1043 prev
= tmpvpcidev
, tmpvpcidev
= tmpvpcidev
->next
) {
1044 if (tmpvpcidev
== virtpcidev
) {
1046 prev
->next
= tmpvpcidev
->next
;
1048 VpcidevListHead
= tmpvpcidev
->next
;
1052 write_unlock_irqrestore(&VpcidevListLock
, flags
);
1057 LOGINF("Added %s:%d:%d &virtpcidev->generic_dev:%p\n",
1058 (devtype
== VIRTHBA_TYPE
) ? "virthba" : "virtnic",
1059 addparams
->bus_no
, addparams
->device_no
,
1060 &virtpcidev
->generic_dev
);
1061 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
1065 static int virtpci_device_serverdown(struct device
*parentbus
,
1067 struct vhba_wwnn
*wwnn
,
1068 unsigned char macaddr
[])
1070 int pausethisone
= 0;
1072 struct virtpci_dev
*tmpvpcidev
, *prevvpcidev
;
1073 struct virtpci_driver
*vpcidriver
;
1074 unsigned long flags
;
1077 if ((devtype
!= VIRTHBA_TYPE
) && (devtype
!= VIRTNIC_TYPE
)) {
1078 LOGERR("**** FAILED to pause device; devtype:%d not vhba:%d or vnic:%d\n",
1079 devtype
, VIRTHBA_TYPE
, VIRTNIC_TYPE
);
1083 /* find the vhba or vnic in virtpci device list */
1084 write_lock_irqsave(&VpcidevListLock
, flags
);
1086 for (tmpvpcidev
= VpcidevListHead
, prevvpcidev
= NULL
;
1087 (tmpvpcidev
&& !found
);
1088 prevvpcidev
= tmpvpcidev
, tmpvpcidev
= tmpvpcidev
->next
) {
1089 if (tmpvpcidev
->devtype
!= devtype
)
1092 if (devtype
== VIRTHBA_TYPE
) {
1094 ((tmpvpcidev
->scsi
.wwnn
.wwnn1
== wwnn
->wwnn1
) &&
1095 (tmpvpcidev
->scsi
.wwnn
.wwnn2
== wwnn
->wwnn2
));
1096 /* devtype is vhba, we're pausing vhba whose
1097 * wwnn matches the current device's wwnn
1099 } else { /* VIRTNIC_TYPE */
1101 memcmp(tmpvpcidev
->net
.mac_addr
, macaddr
,
1102 MAX_MACADDR_LEN
) == 0;
1103 /* devtype is vnic, we're pausing vnic whose
1104 * macaddr matches the current device's macaddr */
1111 vpcidriver
= tmpvpcidev
->mydriver
;
1112 rc
= vpcidriver
->suspend(tmpvpcidev
, 0);
1114 write_unlock_irqrestore(&VpcidevListLock
, flags
);
1117 LOGERR("**** FAILED to find vhba/vnic in the list\n");
1124 static int virtpci_device_serverup(struct device
*parentbus
,
1126 struct vhba_wwnn
*wwnn
,
1127 unsigned char macaddr
[])
1129 int resumethisone
= 0;
1131 struct virtpci_dev
*tmpvpcidev
, *prevvpcidev
;
1132 struct virtpci_driver
*vpcidriver
;
1133 unsigned long flags
;
1136 if ((devtype
!= VIRTHBA_TYPE
) && (devtype
!= VIRTNIC_TYPE
)) {
1137 LOGERR("**** FAILED to resume device; devtype:%d not vhba:%d or vnic:%d\n",
1138 devtype
, VIRTHBA_TYPE
, VIRTNIC_TYPE
);
1142 /* find the vhba or vnic in virtpci device list */
1143 write_lock_irqsave(&VpcidevListLock
, flags
);
1145 for (tmpvpcidev
= VpcidevListHead
, prevvpcidev
= NULL
;
1146 (tmpvpcidev
&& !found
);
1147 prevvpcidev
= tmpvpcidev
, tmpvpcidev
= tmpvpcidev
->next
) {
1148 if (tmpvpcidev
->devtype
!= devtype
)
1151 if (devtype
== VIRTHBA_TYPE
) {
1153 ((tmpvpcidev
->scsi
.wwnn
.wwnn1
== wwnn
->wwnn1
) &&
1154 (tmpvpcidev
->scsi
.wwnn
.wwnn2
== wwnn
->wwnn2
));
1155 /* devtype is vhba, we're resuming vhba whose
1156 * wwnn matches the current device's wwnn */
1157 } else { /* VIRTNIC_TYPE */
1159 memcmp(tmpvpcidev
->net
.mac_addr
, macaddr
,
1160 MAX_MACADDR_LEN
) == 0;
1161 /* devtype is vnic, we're resuming vnic whose
1162 * macaddr matches the current device's macaddr */
1169 vpcidriver
= tmpvpcidev
->mydriver
;
1170 /* This should be done at BUS resume time, but an
1171 * existing problem prevents us from ever getting a bus
1172 * resume... This hack would fail to work should we
1173 * ever have a bus that contains NO devices, since we
1174 * would never even get here in that case.
1176 fix_vbus_devInfo(&tmpvpcidev
->generic_dev
,
1177 tmpvpcidev
->device_no
,
1178 tmpvpcidev
->device
, vpcidriver
);
1179 rc
= vpcidriver
->resume(tmpvpcidev
);
1182 write_unlock_irqrestore(&VpcidevListLock
, flags
);
1185 LOGERR("**** FAILED to find vhba/vnic in the list\n");
1192 static int virtpci_device_del(struct device
*parentbus
,
1193 int devtype
, struct vhba_wwnn
*wwnn
,
1194 unsigned char macaddr
[])
1196 int count
= 0, all
= 0, delthisone
;
1197 struct virtpci_dev
*tmpvpcidev
, *prevvpcidev
, *dellist
= NULL
;
1198 unsigned long flags
;
1200 #define DEL_CONTINUE { \
1201 prevvpcidev = tmpvpcidev;\
1202 tmpvpcidev = tmpvpcidev->next;\
1206 if ((devtype
!= VIRTHBA_TYPE
) && (devtype
!= VIRTNIC_TYPE
)) {
1207 LOGERR("**** FAILED to delete device; devtype:%d not vhba:%d or vnic:%d\n",
1208 devtype
, VIRTHBA_TYPE
, VIRTNIC_TYPE
);
1212 /* see if we are to delete all - NOTE: all implies we have a
1215 all
= ((devtype
== VIRTHBA_TYPE
) && (wwnn
== NULL
)) ||
1216 ((devtype
== VIRTNIC_TYPE
) && (macaddr
== NULL
));
1218 /* find all the vhba or vnic or both in virtpci device list
1219 * keep list of ones we are deleting so we can call
1220 * device_unregister after we release the lock; otherwise we
1221 * encounter "schedule while atomic"
1223 write_lock_irqsave(&VpcidevListLock
, flags
);
1224 for (tmpvpcidev
= VpcidevListHead
, prevvpcidev
= NULL
; tmpvpcidev
;) {
1225 if (tmpvpcidev
->devtype
!= devtype
)
1230 (tmpvpcidev
->generic_dev
.parent
== parentbus
);
1231 /* we're deleting all vhbas or vnics on the
1232 * specified parent bus
1234 } else if (devtype
== VIRTHBA_TYPE
) {
1236 ((tmpvpcidev
->scsi
.wwnn
.wwnn1
== wwnn
->wwnn1
) &&
1237 (tmpvpcidev
->scsi
.wwnn
.wwnn2
== wwnn
->wwnn2
));
1238 /* devtype is vhba, we're deleting vhba whose
1239 * wwnn matches the current device's wwnn
1241 } else { /* VIRTNIC_TYPE */
1243 memcmp(tmpvpcidev
->net
.mac_addr
, macaddr
,
1244 MAX_MACADDR_LEN
) == 0;
1245 /* devtype is vnic, we're deleting vnic whose
1246 * macaddr matches the current device's macaddr
1253 /* take vhba/vnic out of the list */
1256 prevvpcidev
->next
= tmpvpcidev
->next
;
1258 VpcidevListHead
= tmpvpcidev
->next
;
1260 /* add it to our deletelist */
1261 tmpvpcidev
->next
= dellist
;
1262 dellist
= tmpvpcidev
;
1267 /* going to top of loop again - set tmpvpcidev to next
1268 * one we're to process
1271 tmpvpcidev
= prevvpcidev
->next
;
1273 tmpvpcidev
= VpcidevListHead
;
1275 write_unlock_irqrestore(&VpcidevListLock
, flags
);
1277 if (!all
&& (count
== 0)) {
1278 LOGERR("**** FAILED to find vhba/vnic in the list\n");
1282 /* now delete each one from delete list */
1285 tmpvpcidev
= dellist
->next
;
1286 /* delete the vhba/vnic at dellist */
1287 DELETE_ONE_VPCIDEV(dellist
);
1289 dellist
= tmpvpcidev
;
1295 static void virtpci_device_release(struct device
*dev_
)
1297 /* this function is called when the last reference to the
1300 LOGINF("In virtpci_device_release:%p - NOT YET IMPLEMENTED\n", dev_
);
1303 /*****************************************************/
1304 /* Driver functions */
1305 /*****************************************************/
1307 #define kobj_to_device_driver(obj) container_of(obj, struct device_driver, kobj)
1308 #define attribute_to_driver_attribute(obj) \
1309 container_of(obj, struct driver_attribute, attr)
1311 static ssize_t
virtpci_driver_attr_show(struct kobject
*kobj
,
1312 struct attribute
*attr
,
1315 struct driver_attribute
*dattr
= attribute_to_driver_attribute(attr
);
1318 struct driver_private
*dprivate
= to_driver(kobj
);
1319 struct device_driver
*driver
;
1321 if (dprivate
!= NULL
)
1322 driver
= dprivate
->driver
;
1326 DBGINF("In virtpci_driver_attr_show driver->name:%s\n", driver
->name
);
1329 ret
= dattr
->show(driver
, buf
);
1334 static ssize_t
virtpci_driver_attr_store(struct kobject
*kobj
,
1335 struct attribute
*attr
,
1336 const char *buf
, size_t count
)
1338 struct driver_attribute
*dattr
= attribute_to_driver_attribute(attr
);
1341 struct driver_private
*dprivate
= to_driver(kobj
);
1342 struct device_driver
*driver
;
1344 if (dprivate
!= NULL
)
1345 driver
= dprivate
->driver
;
1349 DBGINF("In virtpci_driver_attr_store driver->name:%s\n", driver
->name
);
1353 ret
= dattr
->store(driver
, buf
, count
);
1358 /* register a new virtpci driver */
1359 int virtpci_register_driver(struct virtpci_driver
*drv
)
1363 DBGINF("In virtpci_register_driver\n");
1365 if (drv
->id_table
== NULL
) {
1366 LOGERR("id_table missing\n");
1369 /* initialize core driver fields needed to call driver_register */
1370 drv
->core_driver
.name
= drv
->name
; /* name of driver in sysfs */
1371 drv
->core_driver
.bus
= &virtpci_bus_type
; /* type of bus this
1372 * driver works with */
1373 drv
->core_driver
.probe
= virtpci_device_probe
; /* called to query the
1375 * specific device and
1376 * whether this driver
1377 *can work with it */
1378 drv
->core_driver
.remove
= virtpci_device_remove
; /* called when the
1380 * from the system */
1381 /* register with core */
1382 result
= driver_register(&drv
->core_driver
);
1383 /* calls bus_add_driver which calls driver_attach and
1387 return result
; /* failed */
1389 drv
->core_driver
.p
->kobj
.ktype
= &virtpci_driver_kobj_type
;
1393 EXPORT_SYMBOL_GPL(virtpci_register_driver
);
1395 void virtpci_unregister_driver(struct virtpci_driver
*drv
)
1397 DBGINF("In virtpci_unregister_driver drv:%p\n", drv
);
1398 driver_unregister(&drv
->core_driver
);
1399 /* driver_unregister calls bus_remove_driver
1400 * bus_remove_driver calls device_detach
1401 * device_detach calls device_release_driver for each of the
1403 * device_release driver calls drv->remove which is
1404 * virtpci_device_remove
1405 * virtpci_device_remove calls virthba_remove
1407 DBGINF("Leaving\n");
1409 EXPORT_SYMBOL_GPL(virtpci_unregister_driver
);
1411 /*****************************************************/
1412 /* debugfs filesystem functions */
1413 /*****************************************************/
1414 struct print_vbus_info
{
1420 static int print_vbus(struct device
*vbus
, void *data
)
1422 struct print_vbus_info
*p
= (struct print_vbus_info
*)data
;
1424 *p
->str_pos
+= scnprintf(p
->buf
+ *p
->str_pos
, *p
->len
- *p
->str_pos
,
1425 "bus_id:%s\n", dev_name(vbus
));
1429 static ssize_t
info_debugfs_read(struct file
*file
, char __user
*buf
,
1430 size_t len
, loff_t
*offset
)
1432 ssize_t bytes_read
= 0;
1434 struct virtpci_dev
*tmpvpcidev
;
1435 unsigned long flags
;
1436 struct print_vbus_info printparam
;
1441 vbuf
= kzalloc(len
, GFP_KERNEL
);
1445 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1446 " Virtual PCI Bus devices\n");
1447 printparam
.str_pos
= &str_pos
;
1448 printparam
.buf
= vbuf
;
1449 printparam
.len
= &len
;
1450 if (bus_for_each_dev(&virtpci_bus_type
, NULL
,
1451 (void *)&printparam
, print_vbus
))
1452 LOGERR("Failed to find bus\n");
1454 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1455 "\n Virtual PCI devices\n");
1456 read_lock_irqsave(&VpcidevListLock
, flags
);
1457 tmpvpcidev
= VpcidevListHead
;
1458 while (tmpvpcidev
) {
1459 if (tmpvpcidev
->devtype
== VIRTHBA_TYPE
) {
1460 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1461 "[%d:%d] VHba:%08x:%08x max-config:%d-%d-%d-%d",
1463 tmpvpcidev
->device_no
,
1464 tmpvpcidev
->scsi
.wwnn
.wwnn1
,
1465 tmpvpcidev
->scsi
.wwnn
.wwnn2
,
1466 tmpvpcidev
->scsi
.max
.max_channel
,
1467 tmpvpcidev
->scsi
.max
.max_id
,
1468 tmpvpcidev
->scsi
.max
.max_lun
,
1469 tmpvpcidev
->scsi
.max
.cmd_per_lun
);
1471 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
,
1472 "[%d:%d] VNic:%02x:%02x:%02x:%02x:%02x:%02x num_rcv_bufs:%d mtu:%d",
1474 tmpvpcidev
->device_no
,
1475 tmpvpcidev
->net
.mac_addr
[0],
1476 tmpvpcidev
->net
.mac_addr
[1],
1477 tmpvpcidev
->net
.mac_addr
[2],
1478 tmpvpcidev
->net
.mac_addr
[3],
1479 tmpvpcidev
->net
.mac_addr
[4],
1480 tmpvpcidev
->net
.mac_addr
[5],
1481 tmpvpcidev
->net
.num_rcv_bufs
,
1482 tmpvpcidev
->net
.mtu
);
1484 str_pos
+= scnprintf(vbuf
+ str_pos
,
1485 len
- str_pos
, " chanptr:%p\n",
1486 tmpvpcidev
->queueinfo
.chan
);
1487 tmpvpcidev
= tmpvpcidev
->next
;
1489 read_unlock_irqrestore(&VpcidevListLock
, flags
);
1491 str_pos
+= scnprintf(vbuf
+ str_pos
, len
- str_pos
, "\n");
1492 bytes_read
= simple_read_from_buffer(buf
, len
, offset
, vbuf
, str_pos
);
1497 /*****************************************************/
1498 /* Module Init & Exit functions */
1499 /*****************************************************/
1501 static int __init
virtpci_mod_init(void)
1505 if (!unisys_spar_platform
)
1508 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
1510 ret
= bus_register(&virtpci_bus_type
);
1511 /* creates /sys/bus/uisvirtpci which contains devices &
1515 LOGERR("bus_register ****FAILED:%d\n", ret
);
1516 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC
, ret
,
1517 POSTCODE_SEVERITY_ERR
);
1520 DBGINF("bus_register successful\n");
1521 bus_device_info_init(&Bus_DriverInfo
, "clientbus", "virtpci",
1524 /* create a root bus used to parent all the virtpci buses. */
1525 ret
= device_register(&virtpci_rootbus_device
);
1527 LOGERR("device_register FAILED:%d\n", ret
);
1528 bus_unregister(&virtpci_bus_type
);
1529 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC
, ret
,
1530 POSTCODE_SEVERITY_ERR
);
1533 DBGINF("device_register successful ret:%x\n", ret
);
1535 if (!uisctrl_register_req_handler(2, (void *)&virtpci_ctrlchan_func
,
1536 &Chipset_DriverInfo
)) {
1537 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1538 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC
, POSTCODE_SEVERITY_ERR
);
1539 device_unregister(&virtpci_rootbus_device
);
1540 bus_unregister(&virtpci_bus_type
);
1544 LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
1545 (void *)&virtpci_ctrlchan_func
);
1546 /* create debugfs directory and info file inside. */
1547 virtpci_debugfs_dir
= debugfs_create_dir("virtpci", NULL
);
1548 debugfs_create_file("info", S_IRUSR
, virtpci_debugfs_dir
,
1549 NULL
, &debugfs_info_fops
);
1550 LOGINF("Leaving\n");
1551 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
1555 static void __exit
virtpci_mod_exit(void)
1557 LOGINF("virtpci_mod_exit...\n");
1559 /* unregister the callback function */
1560 if (!uisctrl_register_req_handler(2, NULL
, NULL
))
1561 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1563 device_unregister(&virtpci_rootbus_device
);
1564 bus_unregister(&virtpci_bus_type
);
1565 debugfs_remove_recursive(virtpci_debugfs_dir
);
1566 LOGINF("Leaving\n");
1569 module_init(virtpci_mod_init
);
1570 module_exit(virtpci_mod_exit
);
1571 MODULE_LICENSE("GPL");
1572 MODULE_AUTHOR("Usha Srinivasan");
1573 MODULE_ALIAS("uisvirtpci");