1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (C) 2010 - 2016 UNISYS CORPORATION
7 #ifndef __IOCHANNEL_H__
8 #define __IOCHANNEL_H__
11 * Everything needed for IOPart-GuestPart communication is define in
12 * this file. Note: Everything is OS-independent because this file is
13 * used by Windows, Linux and possible EFI drivers.
15 * Communication flow between the IOPart and GuestPart uses the channel headers
16 * channel state. The following states are currently being used:
17 * UNINIT(All Zeroes), CHANNEL_ATTACHING, CHANNEL_ATTACHED, CHANNEL_OPENED
19 * Additional states will be used later. No locking is needed to switch between
20 * states due to the following rules:
22 * 1. IOPart is only the only partition allowed to change from UNIT
23 * 2. IOPart is only the only partition allowed to change from
25 * 3. GuestPart is only the only partition allowed to change from
28 * The state changes are the following: IOPart sees the channel is in UNINIT,
29 * UNINIT -> CHANNEL_ATTACHING (performed only by IOPart)
30 * CHANNEL_ATTACHING -> CHANNEL_ATTACHED (performed only by IOPart)
31 * CHANNEL_ATTACHED -> CHANNEL_OPENED (performed only by GuestPart)
34 #include <linux/uuid.h>
35 #include <linux/skbuff.h>
36 #include <linux/visorbus.h>
39 * Must increment these whenever you insert or delete fields within this channel
40 * struct. Also increment whenever you change the meaning of fields within this
41 * channel struct so as to break pre-existing software. Note that you can
42 * usually add fields to the END of the channel struct without needing to
45 #define VISOR_VHBA_CHANNEL_VERSIONID 2
46 #define VISOR_VNIC_CHANNEL_VERSIONID 2
49 * Everything necessary to handle SCSI & NIC traffic between Guest Partition and
50 * IO Partition is defined below.
54 * Define the two queues per data channel between iopart and ioguestparts.
55 * IOCHAN_TO_IOPART -- used by guest to 'insert' signals to iopart.
56 * IOCHAN_FROM_IOPART -- used by guest to 'remove' signals from IO part.
58 #define IOCHAN_TO_IOPART 0
59 #define IOCHAN_FROM_IOPART 1
61 /* Size of cdb - i.e., SCSI cmnd */
62 #define MAX_CMND_SIZE 16
64 /* Unisys-specific DMA direction values */
65 enum uis_dma_data_direction {
66 UIS_DMA_BIDIRECTIONAL = 0,
67 UIS_DMA_TO_DEVICE = 1,
68 UIS_DMA_FROM_DEVICE = 2,
72 #define MAX_SENSE_SIZE 64
73 #define MAX_PHYS_INFO 64
76 * enum net_types - Various types of network packets that can be sent in cmdrsp.
77 * @NET_RCV_POST: Submit buffer to hold receiving incoming packet.
78 * @NET_RCV: visornic -> uisnic. Incoming packet received.
79 * @NET_XMIT: uisnic -> visornic. For outgoing packet.
80 * @NET_XMIT_DONE: visornic -> uisnic. Outgoing packet xmitted.
81 * @NET_RCV_ENBDIS: uisnic -> visornic. Enable/Disable packet reception.
82 * @NET_RCV_ENBDIS_ACK: visornic -> uisnic. Acknowledge enable/disable packet.
83 * @NET_RCV_PROMISC: uisnic -> visornic. Enable/Disable promiscuous mode.
84 * @NET_CONNECT_STATUS: visornic -> uisnic. Indicate the loss or restoration of
85 * a network connection.
86 * @NET_MACADDR: uisnic -> visornic. Indicates the client has requested
87 * to update it's MAC address.
88 * @NET_MACADDR_ACK: MAC address acknowledge.
104 /* Minimum eth data size */
105 #define ETH_MIN_DATA_SIZE 46
106 #define ETH_MIN_PACKET_SIZE (ETH_HLEN + ETH_MIN_DATA_SIZE)
108 /* Maximum data size */
109 #define VISOR_ETH_MAX_MTU 16384
111 #ifndef MAX_MACADDR_LEN
112 /* Number of bytes in MAC address */
113 #define MAX_MACADDR_LEN 6
116 /* Various types of scsi task mgmt commands. */
117 enum task_mgmt_types {
118 TASK_MGMT_ABORT_TASK = 1,
121 TASK_MGMT_TARGET_RESET,
124 /* Various types of vdisk mgmt commands. */
125 enum vdisk_mgmt_types {
126 VDISK_MGMT_ACQUIRE = 1,
136 #define MIN_NUMSIGNALS 64
138 /* Structs with pragma pack. */
140 struct guest_phys_info {
146 * struct uisscsi_dest
147 * @channel: Bus number.
148 * @id: Target number.
149 * @lun: Logical unit number.
151 struct uisscsi_dest {
163 * struct vhba_config_max
164 * @max_channel: Maximum channel for devices attached to this bus.
165 * @max_id: Maximum SCSI ID for devices attached to bus.
166 * @max_lun: Maximum SCSI LUN for devices attached to bus.
167 * @cmd_per_lun: Maximum number of outstanding commands per LUN.
168 * @max_io_size: Maximum io size for devices attached to this bus. Max io size
169 * is often determined by the resource of the hba.
170 * e.g Max scatter gather list length * page size / sector size.
172 * WARNING: Values stored in this structure must contain maximum counts (not
177 struct vhba_config_max {
186 * struct uiscmdrsp_scsi
188 * @handle: The handle to the cmd that was received. Send it back as
189 * is in the rsp packet.
190 * @cmnd: The cdb for the command.
191 * @bufflen: Length of data to be transferred out or in.
192 * @guest_phys_entries: Number of entries in scatter-gather list.
193 * @struct gpi_list: Physical address information for each fragment.
194 * @data_dir: Direction of the data, if any.
195 * @struct vdest: Identifies the virtual hba, id, channel, lun to which
197 * @linuxstat: Original Linux status used by Linux vdisk.
198 * @scsistat: The scsi status.
199 * @addlstat: Non-scsi status.
200 * @sensebuf: Sense info in case cmd failed. sensebuf holds the
201 * sense_data struct. See sense_data struct for more
203 * @*vdisk: Pointer to the vdisk to clean up when IO completes.
204 * @no_disk_result: Used to return no disk inquiry result when
205 * no_disk_result is set to 1
206 * scsi.scsistat is SAM_STAT_GOOD
208 * scsi.linuxstat is SAM_STAT_GOOD
209 * That is, there is NO error.
211 struct uiscmdrsp_scsi {
213 u8 cmnd[MAX_CMND_SIZE];
215 u16 guest_phys_entries;
216 struct guest_phys_info gpi_list[MAX_PHYS_INFO];
218 struct uisscsi_dest vdest;
219 /* Needed to queue the rsp back to cmd originator. */
223 #define ADDL_SEL_TIMEOUT 4
224 /* The following fields are need to determine the result of command. */
225 u8 sensebuf[MAX_SENSE_SIZE];
231 * Defines to support sending correct inquiry result when no disk is
236 * If the target is not capable of supporting a device on this logical unit, the
237 * device server shall set this field to 7Fh (PERIPHERAL QUALIFIER set to 011b
238 * and PERIPHERAL DEVICE TYPE set to 1Fh).
240 * The device server is capable of supporting the specified peripheral device
241 * type on this logical unit. However, the physical device is not currently
242 * connected to this logical unit.
246 * Peripheral qualifier of 0x3
247 * Peripheral type of 0x1f
248 * Specifies no device but target present
250 #define DEV_NOT_CAPABLE 0x7f
252 * Peripheral qualifier of 0x1
253 * Peripheral type of 0 - disk
254 * Specifies device capable, but not present
256 #define DEV_DISK_CAPABLE_NOT_PRESENT 0x20
257 /* HiSup = 1; shows support for report luns must be returned for lun 0. */
258 #define DEV_HISUPPORT 0x10
261 * Peripheral qualifier of 0x3
262 * Peripheral type of 0x1f
263 * Specifies no device but target present
265 #define DEV_NOT_CAPABLE 0x7f
267 * Peripheral qualifier of 0x1
268 * Peripheral type of 0 - disk
269 * Specifies device capable, but not present
271 #define DEV_DISK_CAPABLE_NOT_PRESENT 0x20
272 /* HiSup = 1; shows support for report luns must be returned for lun 0. */
273 #define DEV_HISUPPORT 0x10
276 * NOTE: Linux code assumes inquiry contains 36 bytes. Without checking length
277 * in buf[4] some Linux code accesses bytes beyond 5 to retrieve vendor, product
278 * and revision. Yikes! So let us always send back 36 bytes, the minimum for
281 #define NO_DISK_INQUIRY_RESULT_LEN 36
282 /* 5 bytes minimum for inquiry result */
283 #define MIN_INQUIRY_RESULT_LEN 5
285 /* SCSI device version for no disk inquiry result */
286 /* indicates SCSI SPC2 (SPC3 is 5) */
287 #define SCSI_SPC2_VER 4
289 /* Struct and Defines to support sense information. */
292 * The following struct is returned in sensebuf field in uiscmdrsp_scsi. It is
293 * initialized in exactly the manner that is recommended in Windows (hence the
295 * When set, these fields will have the following values:
296 * ErrorCode = 0x70 indicates current error
297 * Valid = 1 indicates sense info is valid
298 * SenseKey contains sense key as defined by SCSI specs.
299 * AdditionalSenseCode contains sense key as defined by SCSI specs.
300 * AdditionalSenseCodeQualifier contains qualifier to sense code as defined by
302 * AdditionalSenseLength contains will be sizeof(sense_data)-8=10.
310 u8 incorrect_length:1;
314 u8 additional_sense_length;
315 u8 command_specific_information[4];
316 u8 additional_sense_code;
317 u8 additional_sense_code_qualifier;
319 u8 sense_key_specific[3];
324 * @len: Full length of data in the packet.
325 * @num_frags: Number of fragments in frags containing data.
326 * @struct phys_info frags: Physical page information.
327 * @ethhdr: The ethernet header.
328 * @struct lincsum: These are needed for csum at uisnic end.
329 * @valid: 1 = struct is valid - else ignore.
330 * @hrawoffv: 1 = hwrafoff is valid.
331 * @nhrawoffv: 1 = nhwrafoff is valid.
332 * @protocol: Specifies packet protocol.
333 * @csum: Value used to set skb->csum at IOPart.
334 * @hrawoff: Value used to set skb->h.raw at IOPart. hrawoff points to
335 * the start of the TRANSPORT LAYER HEADER.
336 * @nhrawoff: Value used to set skb->nh.raw at IOPart. nhrawoff points to
337 * the start of the NETWORK LAYER HEADER.
340 * The full packet is described in frags but the ethernet header is separately
341 * kept in ethhdr so that uisnic doesn't have "MAP" the guest memory to get to
342 * the header. uisnic needs ethhdr to determine how to route the packet.
347 struct phys_info frags[MAX_PHYS_INFO];
348 char ethhdr[ETH_HLEN];
360 struct net_pkt_xmtdone {
361 /* Result of NET_XMIT */
366 * RCVPOST_BUF_SIZE must be at most page_size(4096) - cache_line_size (64) The
367 * reason is because dev_skb_alloc which is used to generate RCV_POST skbs in
368 * visornic requires that there is "overhead" in the buffer, and pads 16 bytes.
369 * Use 1 full cache line size for "overhead" so that transfers are optimized.
370 * IOVM requires that a buffer be represented by 1 phys_info structure
371 * which can only cover page_size.
373 #define RCVPOST_BUF_SIZE 4032
374 #define MAX_NET_RCV_CHAIN \
375 ((VISOR_ETH_MAX_MTU + ETH_HLEN + RCVPOST_BUF_SIZE - 1) \
378 /* rcv buf size must be large enough to include ethernet data len + ethernet
379 * header len - we are choosing 2K because it is guaranteed to be describable.
381 struct net_pkt_rcvpost {
382 /* Physical page information for the single fragment 2K rcv buf */
383 struct phys_info frag;
385 * Ensures that receive posts are returned to the adapter which we sent
386 * them from originally.
394 * @rcv_done_len: Length of the received data.
395 * @numrcvbufs: Contains the incoming data. Guest side MUST chain these
397 * @*rcvbuf: List of chained rcvbufa. Each entry is a receive buffer
398 * provided by NET_RCV_POST. NOTE: First rcvbuf in the
399 * chain will also be provided in net.buf.
401 * @rcvs_dropped_delta:
403 * The number of rcvbuf that can be chained is based on max mtu and size of each
409 void *rcvbuf[MAX_NET_RCV_CHAIN];
411 u32 rcvs_dropped_delta;
414 struct net_pkt_enbdis {
416 /* 1 = enable, 0 = disable */
420 struct net_pkt_macaddr {
423 u8 macaddr[MAX_MACADDR_LEN];
427 * struct uiscmdrsp_net - cmd rsp packet used for VNIC network traffic.
431 * @struct xmt: Used for NET_XMIT.
432 * @struct xmtdone: Used for NET_XMIT_DONE.
433 * @struct rcvpost: Used for NET_RCV_POST.
434 * @struct rcv: Used for NET_RCV.
435 * @struct enbdis: Used for NET_RCV_ENBDIS, NET_RCV_ENBDIS_ACK,
436 * NET_RCV_PROMSIC, and NET_CONNECT_STATUS.
439 struct uiscmdrsp_net {
443 struct net_pkt_xmt xmt;
444 struct net_pkt_xmtdone xmtdone;
445 struct net_pkt_rcvpost rcvpost;
446 struct net_pkt_rcv rcv;
447 struct net_pkt_enbdis enbdis;
448 struct net_pkt_macaddr macaddr;
453 * struct uiscmdrsp_scsitaskmgmt
454 * @enum tasktype: The type of task.
455 * @struct vdest: The vdisk for which this task mgmt is generated.
456 * @handle: This is a handle that the guest has saved off for its
457 * own use. The handle value is preserved by iopart and
458 * returned as in task mgmt rsp.
459 * @notify_handle: For Linux guests, this is a pointer to wait_queue_head
460 * that a thread is waiting on to see if the taskmgmt
461 * command has completed. When the rsp is received by
462 * guest, the thread receiving the response uses this to
463 * notify the thread waiting for taskmgmt command
464 * completion. It's value is preserved by iopart and
465 * returned as in the task mgmt rsp.
466 * @notifyresult_handle: This is a handle to the location in the guest where
467 * the result of the taskmgmt command (result field) is
468 * saved to when the response is handled. It's value is
469 * preserved by iopart and returned as is in the task mgmt
471 * @result: Result of taskmgmt command - set by IOPart.
473 struct uiscmdrsp_scsitaskmgmt {
474 enum task_mgmt_types tasktype;
475 struct uisscsi_dest vdest;
478 u64 notifyresult_handle;
481 #define TASK_MGMT_FAILED 0
485 * struct uiscmdrsp_disknotify - Used by uissd to send disk add/remove
486 * notifications to Guest.
487 * @add: 0-remove, 1-add.
488 * @*v_hba: Channel info to route msg.
489 * @channel: SCSI Path of Disk to added or removed.
490 * @id: SCSI Path of Disk to added or removed.
491 * @lun: SCSI Path of Disk to added or removed.
493 * Note that the vHba pointer is not used by the Client/Guest side.
495 struct uiscmdrsp_disknotify {
498 u32 channel, id, lun;
501 /* Keeping cmd and rsp info in one structure for now cmd rsp packet for SCSI */
504 /* Describes what type of information is in the struct */
505 #define CMD_SCSI_TYPE 1
506 #define CMD_NET_TYPE 2
507 #define CMD_SCSITASKMGMT_TYPE 3
508 #define CMD_NOTIFYGUEST_TYPE 4
510 struct uiscmdrsp_scsi scsi;
511 struct uiscmdrsp_net net;
512 struct uiscmdrsp_scsitaskmgmt scsitaskmgmt;
513 struct uiscmdrsp_disknotify disknotify;
515 /* Send the response when the cmd is done (scsi and scsittaskmgmt). */
517 /* General Purpose Queue Link */
518 struct uiscmdrsp *next;
519 /* Pointer to the nextactive commands */
520 struct uiscmdrsp *activeQ_next;
521 /* Pointer to the prevactive commands */
522 struct uiscmdrsp *activeQ_prev;
525 /* total = 28 bytes */
526 struct iochannel_vhba {
528 struct vhba_wwnn wwnn;
530 struct vhba_config_max max;
533 struct iochannel_vnic {
545 * This is just the header of the IO channel. It is assumed that directly after
546 * this header there is a large region of memory which contains the command and
547 * response queues as specified in cmd_q and rsp_q SIGNAL_QUEUE_HEADERS.
549 struct visor_io_channel {
550 struct channel_header channel_header;
551 struct signal_queue_header cmd_q;
552 struct signal_queue_header rsp_q;
554 struct iochannel_vhba vhba;
555 struct iochannel_vnic vnic;
558 #define MAX_CLIENTSTRING_LEN 1024
559 /* client_string is NULL termimated so holds max-1 bytes */
560 u8 client_string[MAX_CLIENTSTRING_LEN];
563 /* INLINE functions for initializing and accessing I/O data channels. */
564 #define SIZEOF_CMDRSP (64 * DIV_ROUND_UP(sizeof(struct uiscmdrsp), 64))
566 /* Use 4K page sizes when passing page info between Guest and IOPartition. */
567 #define PI_PAGE_SIZE 0x1000
568 #define PI_PAGE_MASK 0x0FFF
570 /* __IOCHANNEL_H__ */