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 struct 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 struct 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(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(struct device
), 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
);
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 ((struct spar_io_channel_protocol __iomem *) \
359 chanptr)->vnic.macaddr, \
362 readl(&((struct spar_io_channel_protocol __iomem *)\
363 chanptr)->vnic.num_rcv_bufs); \
364 net.mtu = readl(&((struct spar_io_channel_protocol __iomem *) \
365 chanptr)->vnic.mtu); \
366 memcpy_fromio(&net.zone_uuid, \
367 &((struct spar_io_channel_protocol __iomem *)\
368 chanptr)->vnic.zone_uuid, \
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 ((struct spar_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
.zone_uuid
);
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(enum virtpci_dev_type devtype
,
618 struct del_vbus_guestpart
*delparams
)
621 unsigned char busid
[BUS_ID_SIZE
];
624 GET_BUS_DEV(delparams
->bus_no
);
626 if ((devtype
!= VIRTHBA_TYPE
) && (devtype
!= VIRTNIC_TYPE
)) {
627 LOGERR("**** FAILED to delete all devices; devtype:%d not vhba:%d or vnic:%d\n",
628 devtype
, VIRTHBA_TYPE
, VIRTNIC_TYPE
);
632 LOGINF("Deleting all %s in vbus %s\n",
633 devtype
== VIRTHBA_TYPE
? "vhbas" : "vnics", busid
);
634 /* delete all vhbas/vnics */
635 i
= virtpci_device_del(vbus
, devtype
, NULL
, NULL
);
637 LOGINF("Deleted %d %s\n", i
,
638 devtype
== VIRTHBA_TYPE
? "vhbas" : "vnics");
642 static int virtpci_ctrlchan_func(struct guest_msgs
*msg
)
644 switch (msg
->msgtype
) {
646 return add_vbus(&msg
->add_vbus
);
648 return add_vhba(&msg
->add_vhba
);
650 return add_vnic(&msg
->add_vnic
);
652 return delete_vbus(&msg
->del_vbus
);
654 return delete_vhba(&msg
->del_vhba
);
656 return delete_vnic(&msg
->del_vhba
);
657 case GUEST_DEL_ALL_VHBAS
:
658 return delete_all_virt(VIRTHBA_TYPE
, &msg
->del_all_vhbas
);
659 case GUEST_DEL_ALL_VNICS
:
660 return delete_all_virt(VIRTNIC_TYPE
, &msg
->del_all_vnics
);
661 case GUEST_DEL_ALL_VBUSES
:
664 case GUEST_PAUSE_VHBA
:
665 return pause_vhba(&msg
->pause_vhba
);
666 case GUEST_PAUSE_VNIC
:
667 return pause_vnic(&msg
->pause_vnic
);
668 case GUEST_RESUME_VHBA
:
669 return resume_vhba(&msg
->resume_vhba
);
670 case GUEST_RESUME_VNIC
:
671 return resume_vnic(&msg
->resume_vnic
);
673 LOGERR("invalid message type %d.\n", msg
->msgtype
);
678 /* same as driver_helper in bus.c linux */
679 static int match_busid(struct device
*dev
, void *data
)
681 const char *name
= data
;
683 if (strcmp(name
, BUS_ID(dev
)) == 0)
688 /*****************************************************/
690 /*****************************************************/
692 static const struct pci_device_id
*
693 virtpci_match_device(const struct pci_device_id
*ids
,
694 const struct virtpci_dev
*dev
)
696 while (ids
->vendor
|| ids
->subvendor
|| ids
->class_mask
) {
697 DBGINF("ids->vendor:%x dev->vendor:%x ids->device:%x dev->device:%x\n",
698 ids
->vendor
, dev
->vendor
, ids
->device
, dev
->device
);
700 if ((ids
->vendor
== dev
->vendor
)
701 && (ids
->device
== dev
->device
))
709 /* NOTE: !!!!!! This function is called when a new device is added
710 * for this bus. Or, it is called for existing devices when a new
711 * driver is added for this bus. It returns nonzero if a given device
712 * can be handled by the given driver.
714 static int virtpci_bus_match(struct device
*dev
, struct device_driver
*drv
)
716 struct virtpci_dev
*virtpcidev
= device_to_virtpci_dev(dev
);
717 struct virtpci_driver
*virtpcidrv
= driver_to_virtpci_driver(drv
);
720 DBGINF("In virtpci_bus_match dev->bus_id:%s drv->name:%s\n",
721 dev
->bus_id
, drv
->name
);
723 /* check ids list for a match */
724 if (virtpci_match_device(virtpcidrv
->id_table
, virtpcidev
))
727 DBGINF("returning match:%d\n", match
);
728 return match
; /* 0 - no match; 1 - yes it matches */
731 static int virtpci_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
733 DBGINF("In virtpci_hotplug\n");
734 /* add variables to the environment prior to the generation of
735 * hotplug events to user space
737 if (add_uevent_var(env
, "VIRTPCI_VERSION=%s", VIRTPCI_VERSION
))
742 static int virtpci_device_suspend(struct device
*dev
, pm_message_t state
)
744 DBGINF("In virtpci_device_suspend -NYI ****\n");
748 static int virtpci_device_resume(struct device
*dev
)
750 DBGINF("In virtpci_device_resume -NYI ****\n");
754 /* For a child device just created on a client bus, fill in
755 * information about the driver that is controlling this device into
756 * the appropriate slot within the vbus channel of the bus
759 static void fix_vbus_devInfo(struct device
*dev
, int devNo
, int devType
,
760 struct virtpci_driver
*virtpcidrv
)
764 struct ultra_vbus_deviceinfo devInfo
;
768 LOGERR("%s dev is NULL", __func__
);
772 LOGERR("%s driver is NULL", __func__
);
777 LOGERR("%s dev has no parent bus", __func__
);
780 pChan
= vbus
->platform_data
;
782 LOGERR("%s dev bus has no channel", __func__
);
786 case PCI_DEVICE_ID_VIRTHBA
:
789 case PCI_DEVICE_ID_VIRTNIC
:
796 bus_device_info_init(&devInfo
, stype
,
800 write_vbus_devInfo(pChan
, &devInfo
, devNo
);
802 /* Re-write bus+chipset info, because it is possible that this
803 * was previously written by our good counterpart, visorbus.
805 write_vbus_chpInfo(pChan
, &Chipset_DriverInfo
);
806 write_vbus_busInfo(pChan
, &Bus_DriverInfo
);
809 /* This function is called to query the existence of a specific device
810 * and whether this driver can work with it. It should return -ENODEV
811 * in case of failure.
813 static int virtpci_device_probe(struct device
*dev
)
815 struct virtpci_dev
*virtpcidev
= device_to_virtpci_dev(dev
);
816 struct virtpci_driver
*virtpcidrv
=
817 driver_to_virtpci_driver(dev
->driver
);
818 const struct pci_device_id
*id
;
821 LOGINF("In virtpci_device_probe dev:%p virtpcidev:%p virtpcidrv:%p\n",
822 dev
, virtpcidev
, virtpcidrv
); /* VERBOSE/DEBUG ? */
823 POSTCODE_LINUX_2(VPCI_PROBE_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
824 /* static match and static probe vs dynamic match & dynamic
825 * probe - do we care?.
827 if (!virtpcidrv
->id_table
)
830 id
= virtpci_match_device(virtpcidrv
->id_table
, virtpcidev
);
834 /* increment reference count */
837 /* if virtpcidev is not already claimed & probe function is
840 if (!virtpcidev
->mydriver
&& virtpcidrv
->probe
) {
841 /* call the probe function - virthba or virtnic probe
842 * is what it should be
844 error
= virtpcidrv
->probe(virtpcidev
, id
);
846 fix_vbus_devInfo(dev
, virtpcidev
->device_no
,
847 virtpcidev
->device
, virtpcidrv
);
848 virtpcidev
->mydriver
= virtpcidrv
;
849 POSTCODE_LINUX_2(VPCI_PROBE_EXIT_PC
,
850 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(struct virtpci_dev
), 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)
1506 if (!unisys_spar_platform
)
1509 POSTCODE_LINUX_2(VPCI_CREATE_ENTRY_PC
, POSTCODE_SEVERITY_INFO
);
1511 ret
= bus_register(&virtpci_bus_type
);
1512 /* creates /sys/bus/uisvirtpci which contains devices &
1516 LOGERR("bus_register ****FAILED:%d\n", ret
);
1517 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC
, ret
,
1518 POSTCODE_SEVERITY_ERR
);
1521 DBGINF("bus_register successful\n");
1522 bus_device_info_init(&Bus_DriverInfo
, "clientbus", "virtpci",
1525 /* create a root bus used to parent all the virtpci buses. */
1526 ret
= device_register(&virtpci_rootbus_device
);
1528 LOGERR("device_register FAILED:%d\n", ret
);
1529 bus_unregister(&virtpci_bus_type
);
1530 POSTCODE_LINUX_3(VPCI_CREATE_FAILURE_PC
, ret
,
1531 POSTCODE_SEVERITY_ERR
);
1534 DBGINF("device_register successful ret:%x\n", ret
);
1536 if (!uisctrl_register_req_handler(2, (void *) &virtpci_ctrlchan_func
,
1537 &Chipset_DriverInfo
)) {
1538 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1539 POSTCODE_LINUX_2(VPCI_CREATE_FAILURE_PC
, POSTCODE_SEVERITY_ERR
);
1540 device_unregister(&virtpci_rootbus_device
);
1541 bus_unregister(&virtpci_bus_type
);
1545 LOGINF("successfully registered virtpci_ctrlchan_func (0x%p) as callback.\n",
1546 (void *) &virtpci_ctrlchan_func
);
1547 /* create debugfs directory and info file inside. */
1548 virtpci_debugfs_dir
= debugfs_create_dir("virtpci", NULL
);
1549 debugfs_create_file("info", S_IRUSR
, virtpci_debugfs_dir
,
1550 NULL
, &debugfs_info_fops
);
1551 LOGINF("Leaving\n");
1552 POSTCODE_LINUX_2(VPCI_CREATE_EXIT_PC
, POSTCODE_SEVERITY_INFO
);
1556 static void __exit
virtpci_mod_exit(void)
1558 LOGINF("virtpci_mod_exit...\n");
1560 /* unregister the callback function */
1561 if (!uisctrl_register_req_handler(2, NULL
, NULL
))
1562 LOGERR("uisctrl_register_req_handler ****FAILED.\n");
1564 device_unregister(&virtpci_rootbus_device
);
1565 bus_unregister(&virtpci_bus_type
);
1566 debugfs_remove_recursive(virtpci_debugfs_dir
);
1567 LOGINF("Leaving\n");
1571 module_init(virtpci_mod_init
);
1572 module_exit(virtpci_mod_exit
);
1573 MODULE_LICENSE("GPL");
1574 MODULE_AUTHOR("Usha Srinivasan");
1575 MODULE_ALIAS("uisvirtpci");