2 * DIAGNOSE X'2C4' instruction based HMC FTP services, useable on z/VM
4 * Copyright IBM Corp. 2013
5 * Author(s): Ralf Hoppe (rhoppe@de.ibm.com)
9 #define KMSG_COMPONENT "hmcdrv"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/kernel.h>
14 #include <linux/irq.h>
15 #include <linux/wait.h>
16 #include <linux/string.h>
17 #include <asm/ctl_reg.h>
19 #include "hmcdrv_ftp.h"
22 /* DIAGNOSE X'2C4' return codes in Ry */
23 #define DIAG_FTP_RET_OK 0 /* HMC FTP started successfully */
24 #define DIAG_FTP_RET_EBUSY 4 /* HMC FTP service currently busy */
25 #define DIAG_FTP_RET_EIO 8 /* HMC FTP service I/O error */
26 /* and an artificial extension */
27 #define DIAG_FTP_RET_EPERM 2 /* HMC FTP service privilege error */
29 /* FTP service status codes (after INTR at guest real location 133) */
30 #define DIAG_FTP_STAT_OK 0U /* request completed successfully */
31 #define DIAG_FTP_STAT_PGCC 4U /* program check condition */
32 #define DIAG_FTP_STAT_PGIOE 8U /* paging I/O error */
33 #define DIAG_FTP_STAT_TIMEOUT 12U /* timeout */
34 #define DIAG_FTP_STAT_EBASE 16U /* base of error codes from SCLP */
35 #define DIAG_FTP_STAT_LDFAIL (DIAG_FTP_STAT_EBASE + 1U) /* failed */
36 #define DIAG_FTP_STAT_LDNPERM (DIAG_FTP_STAT_EBASE + 2U) /* not allowed */
37 #define DIAG_FTP_STAT_LDRUNS (DIAG_FTP_STAT_EBASE + 3U) /* runs */
38 #define DIAG_FTP_STAT_LDNRUNS (DIAG_FTP_STAT_EBASE + 4U) /* not runs */
41 * struct diag_ftp_ldfpl - load file FTP parameter list (LDFPL)
42 * @bufaddr: real buffer address (at 4k boundary)
43 * @buflen: length of buffer
44 * @offset: dir/file offset
45 * @intparm: interruption parameter (unused)
46 * @transferred: bytes transferred
47 * @fsize: file size, filled on GET
48 * @failaddr: failing address
50 * @fident: file name - ASCII
52 struct diag_ftp_ldfpl
{
61 u8 fident
[HMCDRV_FTP_FIDENT_MAX
];
64 static DECLARE_COMPLETION(diag_ftp_rx_complete
);
65 static int diag_ftp_subcode
;
68 * diag_ftp_handler() - FTP services IRQ handler
69 * @extirq: external interrupt (sub-) code
70 * @param32: 32-bit interruption parameter from &struct diag_ftp_ldfpl
71 * @param64: unused (for 64-bit interrupt parameters)
73 static void diag_ftp_handler(struct ext_code extirq
,
75 unsigned long param64
)
77 if ((extirq
.subcode
>> 8) != 8)
78 return; /* not a FTP services sub-code */
80 inc_irq_stat(IRQEXT_FTP
);
81 diag_ftp_subcode
= extirq
.subcode
& 0xffU
;
82 complete(&diag_ftp_rx_complete
);
86 * diag_ftp_2c4() - DIAGNOSE X'2C4' service call
87 * @fpl: pointer to prepared LDFPL
88 * @cmd: FTP command to be executed
90 * Performs a DIAGNOSE X'2C4' call with (input/output) FTP parameter list
91 * @fpl and FTP function code @cmd. In case of an error the function does
92 * nothing and returns an (negative) error code.
95 * 1. This function only initiates a transfer, so the caller must wait
96 * for completion (asynchronous execution).
97 * 2. The FTP parameter list @fpl must be aligned to a double-word boundary.
98 * 3. fpl->bufaddr must be a real address, 4k aligned
100 static int diag_ftp_2c4(struct diag_ftp_ldfpl
*fpl
,
101 enum hmcdrv_ftp_cmdid cmd
)
106 " diag %[addr],%[cmd],0x2c4\n"
108 "1: la %[rc],%[err]\n"
111 : [rc
] "=d" (rc
), "+m" (*fpl
)
112 : [cmd
] "0" (cmd
), [addr
] "d" (virt_to_phys(fpl
)),
113 [err
] "i" (DIAG_FTP_RET_EPERM
)
117 case DIAG_FTP_RET_OK
:
119 case DIAG_FTP_RET_EBUSY
:
121 case DIAG_FTP_RET_EPERM
:
123 case DIAG_FTP_RET_EIO
:
130 * diag_ftp_cmd() - executes a DIAG X'2C4' FTP command, targeting a HMC
131 * @ftp: pointer to FTP command specification
132 * @fsize: return of file size (or NULL if undesirable)
134 * Attention: Notice that this function is not reentrant - so the caller
135 * must ensure locking.
137 * Return: number of bytes read/written or a (negative) error code
139 ssize_t
diag_ftp_cmd(const struct hmcdrv_ftp_cmdspec
*ftp
, size_t *fsize
)
141 struct diag_ftp_ldfpl
*ldfpl
;
144 unsigned long start_jiffies
;
146 pr_debug("starting DIAG X'2C4' on '%s', requesting %zd bytes\n",
147 ftp
->fname
, ftp
->len
);
148 start_jiffies
= jiffies
;
150 init_completion(&diag_ftp_rx_complete
);
152 ldfpl
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
158 len
= strlcpy(ldfpl
->fident
, ftp
->fname
, sizeof(ldfpl
->fident
));
159 if (len
>= HMCDRV_FTP_FIDENT_MAX
) {
164 ldfpl
->transferred
= 0;
166 ldfpl
->offset
= ftp
->ofs
;
167 ldfpl
->buflen
= ftp
->len
;
168 ldfpl
->bufaddr
= virt_to_phys(ftp
->buf
);
170 len
= diag_ftp_2c4(ldfpl
, ftp
->id
);
175 * There is no way to cancel the running diag X'2C4', the code
176 * needs to wait unconditionally until the transfer is complete.
178 wait_for_completion(&diag_ftp_rx_complete
);
181 pr_debug("completed DIAG X'2C4' after %lu ms\n",
182 (jiffies
- start_jiffies
) * 1000 / HZ
);
183 pr_debug("status of DIAG X'2C4' is %u, with %lld/%lld bytes\n",
184 diag_ftp_subcode
, ldfpl
->transferred
, ldfpl
->fsize
);
187 switch (diag_ftp_subcode
) {
188 case DIAG_FTP_STAT_OK
: /* success */
189 len
= ldfpl
->transferred
;
191 *fsize
= ldfpl
->fsize
;
193 case DIAG_FTP_STAT_LDNPERM
:
196 case DIAG_FTP_STAT_LDRUNS
:
199 case DIAG_FTP_STAT_LDFAIL
:
200 len
= -ENOENT
; /* no such file or media */
208 free_page((unsigned long) ldfpl
);
214 * diag_ftp_startup() - startup of FTP services, when running on z/VM
216 * Return: 0 on success, else an (negative) error code
218 int diag_ftp_startup(void)
222 rc
= register_external_irq(EXT_IRQ_CP_SERVICE
, diag_ftp_handler
);
226 irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL
);
231 * diag_ftp_shutdown() - shutdown of FTP services, when running on z/VM
233 void diag_ftp_shutdown(void)
235 irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL
);
236 unregister_external_irq(EXT_IRQ_CP_SERVICE
, diag_ftp_handler
);