2 * Copyright (C) 2010 - 2016 UNISYS CORPORATION
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for more
17 #ifndef __IOCHANNEL_H__
18 #define __IOCHANNEL_H__
21 * Everything needed for IOPart-GuestPart communication is define in
22 * this file. Note: Everything is OS-independent because this file is
23 * used by Windows, Linux and possible EFI drivers.
25 * Communication flow between the IOPart and GuestPart uses the channel headers
26 * channel state. The following states are currently being used:
27 * UNINIT(All Zeroes), CHANNEL_ATTACHING, CHANNEL_ATTACHED, CHANNEL_OPENED
29 * Additional states will be used later. No locking is needed to switch between
30 * states due to the following rules:
32 * 1. IOPart is only the only partition allowed to change from UNIT
33 * 2. IOPart is only the only partition allowed to change from
35 * 3. GuestPart is only the only partition allowed to change from
38 * The state changes are the following: IOPart sees the channel is in UNINIT,
39 * UNINIT -> CHANNEL_ATTACHING (performed only by IOPart)
40 * CHANNEL_ATTACHING -> CHANNEL_ATTACHED (performed only by IOPart)
41 * CHANNEL_ATTACHED -> CHANNEL_OPENED (performed only by GuestPart)
44 #include <linux/uuid.h>
45 #include <linux/skbuff.h>
50 * Must increment these whenever you insert or delete fields within this channel
51 * struct. Also increment whenever you change the meaning of fields within this
52 * channel struct so as to break pre-existing software. Note that you can
53 * usually add fields to the END of the channel struct without needing to
56 #define VISOR_VHBA_CHANNEL_VERSIONID 2
57 #define VISOR_VNIC_CHANNEL_VERSIONID 2
60 * Everything necessary to handle SCSI & NIC traffic between Guest Partition and
61 * IO Partition is defined below.
65 * Define the two queues per data channel between iopart and ioguestparts.
66 * IOCHAN_TO_IOPART -- used by guest to 'insert' signals to iopart.
67 * IOCHAN_FROM_IOPART -- used by guest to 'remove' signals from IO part.
69 #define IOCHAN_TO_IOPART 0
70 #define IOCHAN_FROM_IOPART 1
72 /* Size of cdb - i.e., SCSI cmnd */
73 #define MAX_CMND_SIZE 16
75 /* Unisys-specific DMA direction values */
76 enum uis_dma_data_direction {
77 UIS_DMA_BIDIRECTIONAL = 0,
78 UIS_DMA_TO_DEVICE = 1,
79 UIS_DMA_FROM_DEVICE = 2,
83 #define MAX_SENSE_SIZE 64
84 #define MAX_PHYS_INFO 64
87 * enum net_types - Various types of network packets that can be sent in cmdrsp.
88 * @NET_RCV_POST: Submit buffer to hold receiving incoming packet.
89 * @NET_RCV: visornic -> uisnic. Incoming packet received.
90 * @NET_XMIT: uisnic -> visornic. For outgoing packet.
91 * @NET_XMIT_DONE: visornic -> uisnic. Outgoing packet xmitted.
92 * @NET_RCV_ENBDIS: uisnic -> visornic. Enable/Disable packet reception.
93 * @NET_RCV_ENBDIS_ACK: visornic -> uisnic. Acknowledge enable/disable packet.
94 * @NET_RCV_PROMISC: uisnic -> visornic. Enable/Disable promiscuous mode.
95 * @NET_CONNECT_STATUS: visornic -> uisnic. Indicate the loss or restoration of
96 * a network connection.
97 * @NET_MACADDR: uisnic -> visornic. Indicates the client has requested
98 * to update it's MAC address.
99 * @NET_MACADDR_ACK: MAC address acknowledge.
115 /* Minimum eth data size */
116 #define ETH_MIN_DATA_SIZE 46
117 #define ETH_MIN_PACKET_SIZE (ETH_HLEN + ETH_MIN_DATA_SIZE)
119 /* Maximum data size */
120 #define VISOR_ETH_MAX_MTU 16384
122 #ifndef MAX_MACADDR_LEN
123 /* Number of bytes in MAC address */
124 #define MAX_MACADDR_LEN 6
127 /* Various types of scsi task mgmt commands. */
128 enum task_mgmt_types {
129 TASK_MGMT_ABORT_TASK = 1,
132 TASK_MGMT_TARGET_RESET,
135 /* Various types of vdisk mgmt commands. */
136 enum vdisk_mgmt_types {
137 VDISK_MGMT_ACQUIRE = 1,
147 #define MIN_NUMSIGNALS 64
149 /* Structs with pragma pack. */
151 struct guest_phys_info {
157 * struct uisscsi_dest
158 * @channel: Bus number.
159 * @id: Target number.
160 * @lun: Logical unit number.
162 struct uisscsi_dest {
174 * struct vhba_config_max
175 * @max_channel: Maximum channel for devices attached to this bus.
176 * @max_id: Maximum SCSI ID for devices attached to bus.
177 * @max_lun: Maximum SCSI LUN for devices attached to bus.
178 * @cmd_per_lun: Maximum number of outstanding commands per LUN.
179 * @max_io_size: Maximum io size for devices attached to this bus. Max io size
180 * is often determined by the resource of the hba.
181 * e.g Max scatter gather list length * page size / sector size.
183 * WARNING: Values stored in this structure must contain maximum counts (not
188 struct vhba_config_max {
197 * struct uiscmdrsp_scsi
199 * @handle: The handle to the cmd that was received. Send it back as
200 * is in the rsp packet.
201 * @cmnd: The cdb for the command.
202 * @bufflen: Length of data to be transferred out or in.
203 * @guest_phys_entries: Number of entries in scatter-gather list.
204 * @struct gpi_list: Physical address information for each fragment.
205 * @data_dir: Direction of the data, if any.
206 * @struct vdest: Identifies the virtual hba, id, channel, lun to which
208 * @linuxstat: Original Linux status used by Linux vdisk.
209 * @scsistat: The scsi status.
210 * @addlstat: Non-scsi status.
211 * @sensebuf: Sense info in case cmd failed. sensebuf holds the
212 * sense_data struct. See sense_data struct for more
214 * @*vdisk: Pointer to the vdisk to clean up when IO completes.
215 * @no_disk_result: Used to return no disk inquiry result when
216 * no_disk_result is set to 1
217 * scsi.scsistat is SAM_STAT_GOOD
219 * scsi.linuxstat is SAM_STAT_GOOD
220 * That is, there is NO error.
222 struct uiscmdrsp_scsi {
224 u8 cmnd[MAX_CMND_SIZE];
226 u16 guest_phys_entries;
227 struct guest_phys_info gpi_list[MAX_PHYS_INFO];
229 struct uisscsi_dest vdest;
230 /* Needed to queue the rsp back to cmd originator. */
234 #define ADDL_SEL_TIMEOUT 4
235 /* The following fields are need to determine the result of command. */
236 u8 sensebuf[MAX_SENSE_SIZE];
242 * Defines to support sending correct inquiry result when no disk is
247 * If the target is not capable of supporting a device on this logical unit, the
248 * device server shall set this field to 7Fh (PERIPHERAL QUALIFIER set to 011b
249 * and PERIPHERAL DEVICE TYPE set to 1Fh).
251 * The device server is capable of supporting the specified peripheral device
252 * type on this logical unit. However, the physical device is not currently
253 * connected to this logical unit.
257 * Peripheral qualifier of 0x3
258 * Peripheral type of 0x1f
259 * Specifies no device but target present
261 #define DEV_NOT_CAPABLE 0x7f
263 * Peripheral qualifier of 0x1
264 * Peripheral type of 0 - disk
265 * Specifies device capable, but not present
267 #define DEV_DISK_CAPABLE_NOT_PRESENT 0x20
268 /* HiSup = 1; shows support for report luns must be returned for lun 0. */
269 #define DEV_HISUPPORT 0x10
272 * Peripheral qualifier of 0x3
273 * Peripheral type of 0x1f
274 * Specifies no device but target present
276 #define DEV_NOT_CAPABLE 0x7f
278 * Peripheral qualifier of 0x1
279 * Peripheral type of 0 - disk
280 * Specifies device capable, but not present
282 #define DEV_DISK_CAPABLE_NOT_PRESENT 0x20
283 /* HiSup = 1; shows support for report luns must be returned for lun 0. */
284 #define DEV_HISUPPORT 0x10
287 * NOTE: Linux code assumes inquiry contains 36 bytes. Without checking length
288 * in buf[4] some Linux code accesses bytes beyond 5 to retrieve vendor, product
289 * and revision. Yikes! So let us always send back 36 bytes, the minimum for
292 #define NO_DISK_INQUIRY_RESULT_LEN 36
293 /* 5 bytes minimum for inquiry result */
294 #define MIN_INQUIRY_RESULT_LEN 5
296 /* SCSI device version for no disk inquiry result */
297 /* indicates SCSI SPC2 (SPC3 is 5) */
298 #define SCSI_SPC2_VER 4
300 /* Struct and Defines to support sense information. */
303 * The following struct is returned in sensebuf field in uiscmdrsp_scsi. It is
304 * initialized in exactly the manner that is recommended in Windows (hence the
306 * When set, these fields will have the following values:
307 * ErrorCode = 0x70 indicates current error
308 * Valid = 1 indicates sense info is valid
309 * SenseKey contains sense key as defined by SCSI specs.
310 * AdditionalSenseCode contains sense key as defined by SCSI specs.
311 * AdditionalSenseCodeQualifier contains qualifier to sense code as defined by
313 * AdditionalSenseLength contains will be sizeof(sense_data)-8=10.
321 u8 incorrect_length:1;
325 u8 additional_sense_length;
326 u8 command_specific_information[4];
327 u8 additional_sense_code;
328 u8 additional_sense_code_qualifier;
330 u8 sense_key_specific[3];
335 * @len: Full length of data in the packet.
336 * @num_frags: Number of fragments in frags containing data.
337 * @struct phys_info frags: Physical page information.
338 * @ethhdr: The ethernet header.
339 * @struct lincsum: These are needed for csum at uisnic end.
340 * @valid: 1 = struct is valid - else ignore.
341 * @hrawoffv: 1 = hwrafoff is valid.
342 * @nhrawoffv: 1 = nhwrafoff is valid.
343 * @protocol: Specifies packet protocol.
344 * @csum: Value used to set skb->csum at IOPart.
345 * @hrawoff: Value used to set skb->h.raw at IOPart. hrawoff points to
346 * the start of the TRANSPORT LAYER HEADER.
347 * @nhrawoff: Value used to set skb->nh.raw at IOPart. nhrawoff points to
348 * the start of the NETWORK LAYER HEADER.
351 * The full packet is described in frags but the ethernet header is
352 * separately kept in ethhdr so that uisnic doesn't have "MAP" the
353 * guest memory to get to the header. uisnic needs ethhdr to
354 * determine how to route the packet.
359 struct phys_info frags[MAX_PHYS_INFO];
360 char ethhdr[ETH_HLEN];
372 struct net_pkt_xmtdone {
373 /* Result of NET_XMIT */
378 * RCVPOST_BUF_SIZE must be at most page_size(4096) - cache_line_size (64) The
379 * reason is because dev_skb_alloc which is used to generate RCV_POST skbs in
380 * visornic requires that there is "overhead" in the buffer, and pads 16 bytes.
381 * Use 1 full cache line size for "overhead" so that transfers are optimized.
382 * IOVM requires that a buffer be represented by 1 phys_info structure
383 * which can only cover page_size.
385 #define RCVPOST_BUF_SIZE 4032
386 #define MAX_NET_RCV_CHAIN \
387 ((VISOR_ETH_MAX_MTU + ETH_HLEN + RCVPOST_BUF_SIZE - 1) \
390 /* rcv buf size must be large enough to include ethernet data len + ethernet
391 * header len - we are choosing 2K because it is guaranteed to be describable.
393 struct net_pkt_rcvpost {
394 /* Physical page information for the single fragment 2K rcv buf */
395 struct phys_info frag;
397 * Ensures that receive posts are returned to the adapter which we sent
398 * them from originally.
406 * @rcv_done_len: Length of the received data.
407 * @numrcvbufs: Contains the incoming data. Guest side MUST chain these
409 * @*rcvbuf: List of chained rcvbufa. Each entry is a receive buffer
410 * provided by NET_RCV_POST. NOTE: First rcvbuf in the
411 * chain will also be provided in net.buf.
413 * @rcvs_dropped_delta:
415 * The number of rcvbuf that can be chained is based on max mtu and size of each
421 void *rcvbuf[MAX_NET_RCV_CHAIN];
423 u32 rcvs_dropped_delta;
426 struct net_pkt_enbdis {
428 /* 1 = enable, 0 = disable */
432 struct net_pkt_macaddr {
435 u8 macaddr[MAX_MACADDR_LEN];
439 * struct uiscmdrsp_net - cmd rsp packet used for VNIC network traffic.
443 * @struct xmt: Used for NET_XMIT.
444 * @struct xmtdone: Used for NET_XMIT_DONE.
445 * @struct rcvpost: Used for NET_RCV_POST.
446 * @struct rcv: Used for NET_RCV.
447 * @struct enbdis: Used for NET_RCV_ENBDIS, NET_RCV_ENBDIS_ACK,
448 * NET_RCV_PROMSIC, and NET_CONNECT_STATUS.
451 struct uiscmdrsp_net {
455 struct net_pkt_xmt xmt;
456 struct net_pkt_xmtdone xmtdone;
457 struct net_pkt_rcvpost rcvpost;
458 struct net_pkt_rcv rcv;
459 struct net_pkt_enbdis enbdis;
460 struct net_pkt_macaddr macaddr;
465 * struct uiscmdrsp_scsitaskmgmt
466 * @enum tasktype: The type of task.
467 * @struct vdest: The vdisk for which this task mgmt is generated.
468 * @handle: This is a handle that the guest has saved off for its
469 * own use. The handle value is preserved by iopart and
470 * returned as in task mgmt rsp.
471 * @notify_handle: For Linux guests, this is a pointer to wait_queue_head
472 * that a thread is waiting on to see if the taskmgmt
473 * command has completed. When the rsp is received by
474 * guest, the thread receiving the response uses this to
475 * notify the thread waiting for taskmgmt command
476 * completion. It's value is preserved by iopart and
477 * returned as in the task mgmt rsp.
478 * @notifyresult_handle: This is a handle to the location in the guest where
479 * the result of the taskmgmt command (result field) is
480 * saved to when the response is handled. It's value is
481 * preserved by iopart and returned as is in the task mgmt
483 * @result: Result of taskmgmt command - set by IOPart.
485 struct uiscmdrsp_scsitaskmgmt {
486 enum task_mgmt_types tasktype;
487 struct uisscsi_dest vdest;
490 u64 notifyresult_handle;
493 #define TASK_MGMT_FAILED 0
497 * struct uiscmdrsp_disknotify - Used by uissd to send disk add/remove
498 * notifications to Guest.
499 * @add: 0-remove, 1-add.
500 * @*v_hba: Channel info to route msg.
501 * @channel: SCSI Path of Disk to added or removed.
502 * @id: SCSI Path of Disk to added or removed.
503 * @lun: SCSI Path of Disk to added or removed.
505 * Note that the vHba pointer is not used by the Client/Guest side.
507 struct uiscmdrsp_disknotify {
510 u32 channel, id, lun;
513 /* Keeping cmd and rsp info in one structure for now cmd rsp packet for SCSI */
516 /* Describes what type of information is in the struct */
517 #define CMD_SCSI_TYPE 1
518 #define CMD_NET_TYPE 2
519 #define CMD_SCSITASKMGMT_TYPE 3
520 #define CMD_NOTIFYGUEST_TYPE 4
522 struct uiscmdrsp_scsi scsi;
523 struct uiscmdrsp_net net;
524 struct uiscmdrsp_scsitaskmgmt scsitaskmgmt;
525 struct uiscmdrsp_disknotify disknotify;
527 /* Send the response when the cmd is done (scsi and scsittaskmgmt). */
529 /* General Purpose Queue Link */
530 struct uiscmdrsp *next;
531 /* Pointer to the nextactive commands */
532 struct uiscmdrsp *activeQ_next;
533 /* Pointer to the prevactive commands */
534 struct uiscmdrsp *activeQ_prev;
537 /* total = 28 bytes */
538 struct iochannel_vhba {
540 struct vhba_wwnn wwnn;
542 struct vhba_config_max max;
545 struct iochannel_vnic {
557 * This is just the header of the IO channel. It is assumed that directly after
558 * this header there is a large region of memory which contains the command and
559 * response queues as specified in cmd_q and rsp_q SIGNAL_QUEUE_HEADERS.
561 struct visor_io_channel {
562 struct channel_header channel_header;
563 struct signal_queue_header cmd_q;
564 struct signal_queue_header rsp_q;
566 struct iochannel_vhba vhba;
567 struct iochannel_vnic vnic;
570 #define MAX_CLIENTSTRING_LEN 1024
571 /* client_string is NULL termimated so holds max-1 bytes */
572 u8 client_string[MAX_CLIENTSTRING_LEN];
575 /* INLINE functions for initializing and accessing I/O data channels. */
576 #define SIZEOF_CMDRSP (64 * DIV_ROUND_UP(sizeof(struct uiscmdrsp), 64))
578 /* Use 4K page sizes when passing page info between Guest and IOPartition. */
579 #define PI_PAGE_SIZE 0x1000
580 #define PI_PAGE_MASK 0x0FFF
582 /* __IOCHANNEL_H__ */