1 /* Copyright (C) 2010 - 2013 UNISYS CORPORATION */
2 /* All rights reserved. */
3 #ifndef __IOCHANNEL_H__
4 #define __IOCHANNEL_H__
7 * Everything needed for IOPart-GuestPart communication is define in
8 * this file. Note: Everything is OS-independent because this file is
9 * used by Windows, Linux and possible EFI drivers. */
12 * Communication flow between the IOPart and GuestPart uses the channel headers
13 * channel state. The following states are currently being used:
14 * UNINIT(All Zeroes), CHANNEL_ATTACHING, CHANNEL_ATTACHED, CHANNEL_OPENED
16 * additional states will be used later. No locking is needed to switch between
17 * states due to the following rules:
19 * 1. IOPart is only the only partition allowed to change from UNIT
20 * 2. IOPart is only the only partition allowed to change from
22 * 3. GuestPart is only the only partition allowed to change from
25 * The state changes are the following: IOPart sees the channel is in UNINIT,
26 * UNINIT -> CHANNEL_ATTACHING (performed only by IOPart)
27 * CHANNEL_ATTACHING -> CHANNEL_ATTACHED (performed only by IOPart)
28 * CHANNEL_ATTACHED -> CHANNEL_OPENED (performed only by GuestPart)
31 #include <linux/uuid.h>
33 #include "vmcallinterface.h"
35 #define _ULTRA_CONTROLVM_CHANNEL_INLINE_
36 #include <linux/dma-direction.h>
37 #include "controlvmchannel.h"
38 #include "vbuschannel.h"
39 #undef _ULTRA_CONTROLVM_CHANNEL_INLINE_
41 #include "channel_guid.h"
43 #define ULTRA_VHBA_CHANNEL_PROTOCOL_SIGNATURE ULTRA_CHANNEL_PROTOCOL_SIGNATURE
44 #define ULTRA_VNIC_CHANNEL_PROTOCOL_SIGNATURE ULTRA_CHANNEL_PROTOCOL_SIGNATURE
45 #define ULTRA_VSWITCH_CHANNEL_PROTOCOL_SIGNATURE \
46 ULTRA_CHANNEL_PROTOCOL_SIGNATURE
48 /* Must increment these whenever you insert or delete fields within this channel
49 * struct. Also increment whenever you change the meaning of fields within this
50 * channel struct so as to break pre-existing software. Note that you can
51 * usually add fields to the END of the channel struct withOUT needing to
54 #define ULTRA_VHBA_CHANNEL_PROTOCOL_VERSIONID 2
55 #define ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID 2
56 #define ULTRA_VSWITCH_CHANNEL_PROTOCOL_VERSIONID 1
58 #define SPAR_VHBA_CHANNEL_OK_CLIENT(ch) \
59 (spar_check_channel_client(ch, spar_vhba_channel_protocol_uuid, \
60 "vhba", MIN_IO_CHANNEL_SIZE, \
61 ULTRA_VHBA_CHANNEL_PROTOCOL_VERSIONID, \
62 ULTRA_VHBA_CHANNEL_PROTOCOL_SIGNATURE))
64 #define SPAR_VNIC_CHANNEL_OK_CLIENT(ch) \
65 (spar_check_channel_client(ch, spar_vnic_channel_protocol_uuid, \
66 "vnic", MIN_IO_CHANNEL_SIZE, \
67 ULTRA_VNIC_CHANNEL_PROTOCOL_VERSIONID, \
68 ULTRA_VNIC_CHANNEL_PROTOCOL_SIGNATURE))
71 * Everything necessary to handle SCSI & NIC traffic between Guest Partition and
72 * IO Partition is defined below.
79 #define MINNUM(a, b) (((a) < (b)) ? (a) : (b))
80 #define MAXNUM(a, b) (((a) > (b)) ? (a) : (b))
82 /* these define the two queues per data channel between iopart and
85 #define IOCHAN_TO_IOPART 0 /* used by ioguestpart to 'insert' signals to
88 #define IOCHAN_FROM_IOPART 1 /* used by ioguestpart to 'remove' signals from
89 * iopart - same queue as previous queue */
91 /* size of cdb - i.e., scsi cmnd */
92 #define MAX_CMND_SIZE 16
94 #define MAX_SENSE_SIZE 64
96 #define MAX_PHYS_INFO 64
98 /* various types of network packets that can be sent in cmdrsp */
100 NET_RCV_POST = 0, /* submit buffer to hold receiving
102 /* virtnic -> uisnic */
103 NET_RCV, /* incoming packet received */
104 /* uisnic -> virtpci */
105 NET_XMIT, /* for outgoing net packets */
106 /* virtnic -> uisnic */
107 NET_XMIT_DONE, /* outgoing packet xmitted */
108 /* uisnic -> virtpci */
109 NET_RCV_ENBDIS, /* enable/disable packet reception */
110 /* virtnic -> uisnic */
111 NET_RCV_ENBDIS_ACK, /* acknowledge enable/disable packet
113 /* uisnic -> virtnic */
114 NET_RCV_PROMISC, /* enable/disable promiscuous mode */
115 /* virtnic -> uisnic */
116 NET_CONNECT_STATUS, /* indicate the loss or restoration of a network
118 /* uisnic -> virtnic */
119 NET_MACADDR, /* indicates the client has requested to update
121 NET_MACADDR_ACK, /* MAC address */
125 #define ETH_HEADER_SIZE 14 /* size of ethernet header */
127 #define ETH_MIN_DATA_SIZE 46 /* minimum eth data size */
128 #define ETH_MIN_PACKET_SIZE (ETH_HEADER_SIZE + ETH_MIN_DATA_SIZE)
130 #define ETH_MAX_MTU 16384 /* maximum data size */
132 #ifndef MAX_MACADDR_LEN
133 #define MAX_MACADDR_LEN 6 /* number of bytes in MAC address */
134 #endif /* MAX_MACADDR_LEN */
136 /* various types of scsi task mgmt commands */
137 enum task_mgmt_types {
138 TASK_MGMT_ABORT_TASK = 1,
141 TASK_MGMT_TARGET_RESET,
144 /* various types of vdisk mgmt commands */
145 enum vdisk_mgmt_types {
146 VDISK_MGMT_ACQUIRE = 1,
150 /* structs with pragma pack */
152 /* ///////////// BEGIN PRAGMA PACK PUSH 1 ///////////////////////// */
153 /* ///////////// ONLY STRUCT TYPE SHOULD BE BELOW */
155 #pragma pack(push, 1)
157 struct guest_phys_info {
162 #define GPI_ENTRIES_PER_PAGE (PAGE_SIZE / sizeof(struct guest_phys_info))
164 struct uisscsi_dest {
165 u32 channel; /* channel == bus number */
166 u32 id; /* id == target number */
167 u32 lun; /* lun == logical unit number */
175 /* WARNING: Values stired in this structure must contain maximum counts (not
176 * maximum values). */
177 struct vhba_config_max { /* 20 bytes */
178 u32 max_channel; /* maximum channel for devices attached to this
180 u32 max_id; /* maximum SCSI ID for devices attached to this
182 u32 max_lun; /* maximum SCSI LUN for devices attached to this
184 u32 cmd_per_lun; /* maximum number of outstanding commands per
185 * lun that are allowed at one time */
186 u32 max_io_size; /* maximum io size for devices attached to this
188 /* max io size is often determined by the resource of the hba. e.g */
189 /* max scatter gather list length * page size / sector size */
192 struct uiscmdrsp_scsi {
193 void *scsicmd; /* the handle to the cmd that was received -
194 * send it back as is in the rsp packet. */
195 u8 cmnd[MAX_CMND_SIZE]; /* the cdb for the command */
196 u32 bufflen; /* length of data to be transferred out or in */
197 u16 guest_phys_entries; /* Number of entries in scatter-gather (sg)
199 struct guest_phys_info gpi_list[MAX_PHYS_INFO]; /* physical address
200 * information for each
202 enum dma_data_direction data_dir; /* direction of the data, if any */
203 struct uisscsi_dest vdest; /* identifies the virtual hba, id,
204 * channel, lun to which cmd was sent */
206 /* the following fields are needed to queue the rsp back to cmd
208 int linuxstat; /* the original Linux status - for use by linux
210 u8 scsistat; /* the scsi status */
211 u8 addlstat; /* non-scsi status - covers cases like timeout
212 * needed by windows guests */
213 #define ADDL_SEL_TIMEOUT 4
215 /* the following fields are need to determine the result of command */
216 u8 sensebuf[MAX_SENSE_SIZE]; /* sense info in case cmd failed; */
217 /* it holds the sense_data struct; */
218 /* see that struct for details. */
219 void *vdisk; /* contains pointer to the vdisk so that we can clean up
220 * when the IO completes. */
222 /* used to return no disk inquiry result
223 * when no_disk_result is set to 1,
224 * scsi.scsistat is SAM_STAT_GOOD
226 * scsi.linuxstat is SAM_STAT_GOOD
227 * That is, there is NO error.
231 /* Defines to support sending correct inquiry result when no disk is
237 * If the target is not capable of supporting a device on this logical unit, the
238 * device server shall set this field to 7Fh (PERIPHERAL QUALIFIER set to 011b
239 * and PERIPHERAL DEVICE TYPE set to 1Fh).
241 *The device server is capable of supporting the specified peripheral device
242 *type on this logical unit. However, the physical device is not currently
243 *connected to this logical unit.
246 #define DEV_NOT_CAPABLE 0x7f /* peripheral qualifier of 0x3 */
247 /* peripheral type of 0x1f */
248 /* specifies no device but target present */
250 #define DEV_DISK_CAPABLE_NOT_PRESENT 0x20 /* peripheral qualifier of 0x1 */
251 /* peripheral type of 0 - disk */
252 /* specifies device capable, but not present */
254 #define DEV_HISUPPORT 0x10 /* HiSup = 1; shows support for report luns */
255 /* must be returned for lun 0. */
257 /* NOTE: Linux code assumes inquiry contains 36 bytes. Without checking length
258 * in buf[4] some linux code accesses bytes beyond 5 to retrieve vendor, product
259 * & revision. Yikes! So let us always send back 36 bytes, the minimum for
262 #define NO_DISK_INQUIRY_RESULT_LEN 36
264 #define MIN_INQUIRY_RESULT_LEN 5 /* we need at least 5 bytes minimum for inquiry
267 /* SCSI device version for no disk inquiry result */
268 #define SCSI_SPC2_VER 4 /* indicates SCSI SPC2 (SPC3 is 5) */
270 /* Windows and Linux want different things for a non-existent lun. So, we'll let
271 * caller pass in the peripheral qualifier and type.
272 * NOTE:[4] SCSI returns (n-4); so we return length-1-4 or length-5. */
274 #define SET_NO_DISK_INQUIRY_RESULT(buf, len, lun, lun0notpresent, notpresent) \
278 (unsigned int)NO_DISK_INQUIRY_RESULT_LEN)); \
279 buf[2] = (u8)SCSI_SPC2_VER; \
281 buf[0] = (u8)lun0notpresent; \
282 buf[3] = (u8)DEV_HISUPPORT; \
284 buf[0] = (u8)notpresent; \
287 (unsigned int)NO_DISK_INQUIRY_RESULT_LEN) - 5);\
288 if (len >= NO_DISK_INQUIRY_RESULT_LEN) { \
312 * Struct & Defines to support sense information.
315 /* The following struct is returned in sensebuf field in uiscmdrsp_scsi. It is
316 * initialized in exactly the manner that is recommended in Windows (hence the
318 * When set, these fields will have the following values:
319 * ErrorCode = 0x70 indicates current error
320 * Valid = 1 indicates sense info is valid
321 * SenseKey contains sense key as defined by SCSI specs.
322 * AdditionalSenseCode contains sense key as defined by SCSI specs.
323 * AdditionalSenseCodeQualifier contains qualifier to sense code as defined by
325 * AdditionalSenseLength contains will be sizeof(sense_data)-8=10.
333 u8 incorrect_length:1;
337 u8 additional_sense_length;
338 u8 command_specific_information[4];
339 u8 additional_sense_code;
340 u8 additional_sense_code_qualifier;
342 u8 sense_key_specific[3];
346 int len; /* full length of data in the packet */
347 int num_frags; /* number of fragments in frags containing data */
348 struct phys_info frags[MAX_PHYS_INFO]; /* physical page information for
350 char ethhdr[ETH_HEADER_SIZE]; /* the ethernet header */
352 /* these are needed for csum at uisnic end */
353 u8 valid; /* 1 = rest of this struct is valid - else
355 u8 hrawoffv; /* 1 = hwrafoff is valid */
356 u8 nhrawoffv; /* 1 = nhwrafoff is valid */
357 u16 protocol; /* specifies packet protocol */
358 u32 csum; /* value used to set skb->csum at IOPart */
359 u32 hrawoff; /* value used to set skb->h.raw at IOPart */
360 /* hrawoff points to the start of the TRANSPORT LAYER HEADER */
361 u32 nhrawoff; /* value used to set skb->nh.raw at IOPart */
362 /* nhrawoff points to the start of the NETWORK LAYER HEADER */
366 * The full packet is described in frags but the ethernet header is
367 * separately kept in ethhdr so that uisnic doesn't have "MAP" the
368 * guest memory to get to the header. uisnic needs ethhdr to
369 * determine how to route the packet.
373 struct net_pkt_xmtdone {
374 u32 xmt_done_result; /* result of NET_XMIT */
377 /* RCVPOST_BUF_SIZe must be at most page_size(4096) - cache_line_size (64) The
378 * reason is because dev_skb_alloc which is used to generate RCV_POST skbs in
379 * virtnic requires that there is "overhead" in the buffer, and pads 16 bytes. I
380 * prefer to use 1 full cache line size for "overhead" so that transfers are
381 * better. IOVM requires that a buffer be represented by 1 phys_info structure
382 * which can only cover page_size.
384 #define RCVPOST_BUF_SIZE 4032
385 #define MAX_NET_RCV_CHAIN \
386 ((ETH_MAX_MTU+ETH_HEADER_SIZE + RCVPOST_BUF_SIZE-1) / RCVPOST_BUF_SIZE)
388 struct net_pkt_rcvpost {
389 /* rcv buf size must be large enough to include ethernet data len +
390 * ethernet header len - we are choosing 2K because it is guaranteed
391 * to be describable */
392 struct phys_info frag; /* physical page information for the
393 * single fragment 2K rcv buf */
394 u64 unique_num; /* This is used to make sure that
395 * receive posts are returned to */
396 /* the Adapter which we sent them originally. */
400 /* the number of receive buffers that can be chained */
401 /* is based on max mtu and size of each rcv buf */
402 u32 rcv_done_len; /* length of received data */
403 u8 numrcvbufs; /* number of receive buffers that contain the */
404 /* incoming data; guest end MUST chain these together. */
405 void *rcvbuf[MAX_NET_RCV_CHAIN]; /* the list of receive buffers
406 * that must be chained; */
407 /* each entry is a receive buffer provided by NET_RCV_POST. */
408 /* NOTE: first rcvbuf in the chain will also be provided in net.buf. */
410 u32 rcvs_dropped_delta;
413 struct net_pkt_enbdis {
415 u16 enable; /* 1 = enable, 0 = disable */
418 struct net_pkt_macaddr {
420 u8 macaddr[MAX_MACADDR_LEN]; /* 6 bytes */
423 /* cmd rsp packet used for VNIC network traffic */
424 struct uiscmdrsp_net {
428 struct net_pkt_xmt xmt; /* used for NET_XMIT */
429 struct net_pkt_xmtdone xmtdone; /* used for NET_XMIT_DONE */
430 struct net_pkt_rcvpost rcvpost; /* used for NET_RCV_POST */
431 struct net_pkt_rcv rcv; /* used for NET_RCV */
432 struct net_pkt_enbdis enbdis; /* used for NET_RCV_ENBDIS, */
433 /* NET_RCV_ENBDIS_ACK, */
434 /* NET_RCV_PROMSIC, */
435 /* and NET_CONNECT_STATUS */
436 struct net_pkt_macaddr macaddr;
440 struct uiscmdrsp_scsitaskmgmt {
441 enum task_mgmt_types tasktype;
443 /* the type of task */
444 struct uisscsi_dest vdest;
446 /* the vdisk for which this task mgmt is generated */
449 /* This is some handle that the guest has saved off for its own use.
450 * Its value is preserved by iopart & returned as is in the task
455 /* For linux guests, this is a pointer to wait_queue_head that a
456 * thread is waiting on to see if the taskmgmt command has completed.
457 * For windows guests, this is a pointer to a location that a waiting
458 * thread is testing to see if the taskmgmt command has completed.
459 * When the rsp is received by guest, the thread receiving the
460 * response uses this to notify the thread waiting for taskmgmt
461 * command completion. Its value is preserved by iopart & returned
462 * as is in the task mgmt rsp.
466 /* this is a handle to location in guest where the result of the
467 * taskmgmt command (result field) is to saved off when the response
468 * is handled. Its value is preserved by iopart & returned as is in
473 /* result of taskmgmt command - set by IOPart - values are: */
474 #define TASK_MGMT_FAILED 0
477 /* The following is used by uissd to send disk add/remove notifications to
479 /* Note that the vHba pointer is not used by the Client/Guest side. */
480 struct uiscmdrsp_disknotify {
481 u8 add; /* 0-remove, 1-add */
482 void *v_hba; /* Pointer to vhba_info for channel info to
484 u32 channel, id, lun; /* SCSI Path of Disk to added or removed */
487 /* The following is used by virthba/vSCSI to send the Acquire/Release commands
489 struct uiscmdrsp_vdiskmgmt {
490 enum vdisk_mgmt_types vdisktype;
492 /* the type of task */
493 struct uisscsi_dest vdest;
495 /* the vdisk for which this task mgmt is generated */
498 /* This is some handle that the guest has saved off for its own use.
499 * Its value is preserved by iopart & returned as is in the task
504 /* For linux guests, this is a pointer to wait_queue_head that a
505 * thread is waiting on to see if the tskmgmt command has completed.
506 * For win32 guests, this is a pointer to a location that a waiting
507 * thread is testing to see if the taskmgmt command has completed.
508 * When the rsp is received by guest, the thread receiving the
509 * response uses this to notify the thread waiting for taskmgmt
510 * command completion. Its value is preserved by iopart & returned
511 * as is in the task mgmt rsp.
515 /* this is a handle to location in guest where the result of the
516 * taskmgmt command (result field) is to saved off when the response
517 * is handled. Its value is preserved by iopart & returned as is in
522 /* result of taskmgmt command - set by IOPart - values are: */
523 #define VDISK_MGMT_FAILED 0
526 /* keeping cmd & rsp info in one structure for now cmd rsp packet for scsi */
530 /* describes what type of information is in the struct */
531 #define CMD_SCSI_TYPE 1
532 #define CMD_NET_TYPE 2
533 #define CMD_SCSITASKMGMT_TYPE 3
534 #define CMD_NOTIFYGUEST_TYPE 4
535 #define CMD_VDISKMGMT_TYPE 5
537 struct uiscmdrsp_scsi scsi;
538 struct uiscmdrsp_net net;
539 struct uiscmdrsp_scsitaskmgmt scsitaskmgmt;
540 struct uiscmdrsp_disknotify disknotify;
541 struct uiscmdrsp_vdiskmgmt vdiskmgmt;
543 void *private_data; /* used to send the response when the cmd is
544 * done (scsi & scsittaskmgmt). */
545 struct uiscmdrsp *next; /* General Purpose Queue Link */
546 struct uiscmdrsp *activeQ_next; /* Used to track active commands */
547 struct uiscmdrsp *activeQ_prev; /* Used to track active commands */
550 /* This is just the header of the IO channel. It is assumed that directly after
551 * this header there is a large region of memory which contains the command and
552 * response queues as specified in cmd_q and rsp_q SIGNAL_QUEUE_HEADERS.
554 struct spar_io_channel_protocol {
555 struct channel_header channel_header;
556 struct signal_queue_header cmd_q;
557 struct signal_queue_header rsp_q;
560 struct vhba_wwnn wwnn; /* 8 bytes */
561 struct vhba_config_max max; /* 20 bytes */
562 } vhba; /* total = 28 bytes */
564 u8 macaddr[MAX_MACADDR_LEN]; /* 6 bytes */
565 u32 num_rcv_bufs; /* 4 bytes */
566 u32 mtu; /* 4 bytes */
567 uuid_le zone_uuid; /* 16 bytes */
568 } vnic; /* total = 30 bytes */
571 #define MAX_CLIENTSTRING_LEN 1024
572 u8 client_string[MAX_CLIENTSTRING_LEN];/* NULL terminated - so holds
577 /* ///////////// END PRAGMA PACK PUSH 1 /////////////////////////// */
580 * INLINE functions for initializing and accessing I/O data channels
583 #define SIZEOF_PROTOCOL (COVER(sizeof(struct spar_io_channel_protocol), 64))
584 #define SIZEOF_CMDRSP (COVER(sizeof(struct uiscmdrsp), 64))
586 #define MIN_IO_CHANNEL_SIZE COVER(SIZEOF_PROTOCOL + \
587 2 * MIN_NUMSIGNALS * SIZEOF_CMDRSP, 4096)
590 * INLINE function for expanding a guest's pfn-off-size into multiple 4K page
591 * pfn-off-size entires.
594 /* we deal with 4K page sizes when we it comes to passing page information
596 /* Guest and IOPartition. */
597 #define PI_PAGE_SIZE 0x1000
598 #define PI_PAGE_MASK 0x0FFF
600 /* returns next non-zero index on success or zero on failure (i.e. out of
604 add_physinfo_entries(u32 inp_pfn, /* input - specifies the pfn to be used
606 u16 inp_off, /* input - specifies the off to be used
608 u32 inp_len, /* input - specifies the len to be used
610 u16 index, /* input - index in array at which new
611 * entries are added */
612 u16 max_pi_arr_entries, /* input - specifies the maximum
613 * entries pi_arr can hold */
614 struct phys_info pi_arr[]) /* input & output - array to
615 * which entries are added */
620 firstlen = PI_PAGE_SIZE - inp_off;
621 if (inp_len <= firstlen) {
622 /* the input entry spans only one page - add as is */
623 if (index >= max_pi_arr_entries)
625 pi_arr[index].pi_pfn = inp_pfn;
626 pi_arr[index].pi_off = (u16)inp_off;
627 pi_arr[index].pi_len = (u16)inp_len;
631 /* this entry spans multiple pages */
632 for (len = inp_len, i = 0; len;
633 len -= pi_arr[index + i].pi_len, i++) {
634 if (index + i >= max_pi_arr_entries)
636 pi_arr[index + i].pi_pfn = inp_pfn + i;
638 pi_arr[index].pi_off = inp_off;
639 pi_arr[index].pi_len = firstlen;
643 pi_arr[index + i].pi_off = 0;
644 pi_arr[index + i].pi_len =
645 (u16)MINNUM(len, (u32)PI_PAGE_SIZE);
651 #endif /* __IOCHANNEL_H__ */