1 // SPDX-License-Identifier: GPL-2.0
3 * DIAGNOSE X'2C4' instruction based HMC FTP services, useable on z/VM
5 * Copyright IBM Corp. 2013
6 * Author(s): Ralf Hoppe (rhoppe@de.ibm.com)
10 #define KMSG_COMPONENT "hmcdrv"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/kernel.h>
15 #include <linux/irq.h>
16 #include <linux/wait.h>
17 #include <linux/string.h>
18 #include <asm/ctl_reg.h>
21 #include "hmcdrv_ftp.h"
24 /* DIAGNOSE X'2C4' return codes in Ry */
25 #define DIAG_FTP_RET_OK 0 /* HMC FTP started successfully */
26 #define DIAG_FTP_RET_EBUSY 4 /* HMC FTP service currently busy */
27 #define DIAG_FTP_RET_EIO 8 /* HMC FTP service I/O error */
28 /* and an artificial extension */
29 #define DIAG_FTP_RET_EPERM 2 /* HMC FTP service privilege error */
31 /* FTP service status codes (after INTR at guest real location 133) */
32 #define DIAG_FTP_STAT_OK 0U /* request completed successfully */
33 #define DIAG_FTP_STAT_PGCC 4U /* program check condition */
34 #define DIAG_FTP_STAT_PGIOE 8U /* paging I/O error */
35 #define DIAG_FTP_STAT_TIMEOUT 12U /* timeout */
36 #define DIAG_FTP_STAT_EBASE 16U /* base of error codes from SCLP */
37 #define DIAG_FTP_STAT_LDFAIL (DIAG_FTP_STAT_EBASE + 1U) /* failed */
38 #define DIAG_FTP_STAT_LDNPERM (DIAG_FTP_STAT_EBASE + 2U) /* not allowed */
39 #define DIAG_FTP_STAT_LDRUNS (DIAG_FTP_STAT_EBASE + 3U) /* runs */
40 #define DIAG_FTP_STAT_LDNRUNS (DIAG_FTP_STAT_EBASE + 4U) /* not runs */
43 * struct diag_ftp_ldfpl - load file FTP parameter list (LDFPL)
44 * @bufaddr: real buffer address (at 4k boundary)
45 * @buflen: length of buffer
46 * @offset: dir/file offset
47 * @intparm: interruption parameter (unused)
48 * @transferred: bytes transferred
49 * @fsize: file size, filled on GET
50 * @failaddr: failing address
52 * @fident: file name - ASCII
54 struct diag_ftp_ldfpl
{
63 u8 fident
[HMCDRV_FTP_FIDENT_MAX
];
66 static DECLARE_COMPLETION(diag_ftp_rx_complete
);
67 static int diag_ftp_subcode
;
70 * diag_ftp_handler() - FTP services IRQ handler
71 * @extirq: external interrupt (sub-) code
72 * @param32: 32-bit interruption parameter from &struct diag_ftp_ldfpl
73 * @param64: unused (for 64-bit interrupt parameters)
75 static void diag_ftp_handler(struct ext_code extirq
,
77 unsigned long param64
)
79 if ((extirq
.subcode
>> 8) != 8)
80 return; /* not a FTP services sub-code */
82 inc_irq_stat(IRQEXT_FTP
);
83 diag_ftp_subcode
= extirq
.subcode
& 0xffU
;
84 complete(&diag_ftp_rx_complete
);
88 * diag_ftp_2c4() - DIAGNOSE X'2C4' service call
89 * @fpl: pointer to prepared LDFPL
90 * @cmd: FTP command to be executed
92 * Performs a DIAGNOSE X'2C4' call with (input/output) FTP parameter list
93 * @fpl and FTP function code @cmd. In case of an error the function does
94 * nothing and returns an (negative) error code.
97 * 1. This function only initiates a transfer, so the caller must wait
98 * for completion (asynchronous execution).
99 * 2. The FTP parameter list @fpl must be aligned to a double-word boundary.
100 * 3. fpl->bufaddr must be a real address, 4k aligned
102 static int diag_ftp_2c4(struct diag_ftp_ldfpl
*fpl
,
103 enum hmcdrv_ftp_cmdid cmd
)
107 diag_stat_inc(DIAG_STAT_X2C4
);
109 " diag %[addr],%[cmd],0x2c4\n"
111 "1: la %[rc],%[err]\n"
114 : [rc
] "=d" (rc
), "+m" (*fpl
)
115 : [cmd
] "0" (cmd
), [addr
] "d" (virt_to_phys(fpl
)),
116 [err
] "i" (DIAG_FTP_RET_EPERM
)
120 case DIAG_FTP_RET_OK
:
122 case DIAG_FTP_RET_EBUSY
:
124 case DIAG_FTP_RET_EPERM
:
126 case DIAG_FTP_RET_EIO
:
133 * diag_ftp_cmd() - executes a DIAG X'2C4' FTP command, targeting a HMC
134 * @ftp: pointer to FTP command specification
135 * @fsize: return of file size (or NULL if undesirable)
137 * Attention: Notice that this function is not reentrant - so the caller
138 * must ensure locking.
140 * Return: number of bytes read/written or a (negative) error code
142 ssize_t
diag_ftp_cmd(const struct hmcdrv_ftp_cmdspec
*ftp
, size_t *fsize
)
144 struct diag_ftp_ldfpl
*ldfpl
;
147 unsigned long start_jiffies
;
149 pr_debug("starting DIAG X'2C4' on '%s', requesting %zd bytes\n",
150 ftp
->fname
, ftp
->len
);
151 start_jiffies
= jiffies
;
153 init_completion(&diag_ftp_rx_complete
);
155 ldfpl
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
161 len
= strlcpy(ldfpl
->fident
, ftp
->fname
, sizeof(ldfpl
->fident
));
162 if (len
>= HMCDRV_FTP_FIDENT_MAX
) {
167 ldfpl
->transferred
= 0;
169 ldfpl
->offset
= ftp
->ofs
;
170 ldfpl
->buflen
= ftp
->len
;
171 ldfpl
->bufaddr
= virt_to_phys(ftp
->buf
);
173 len
= diag_ftp_2c4(ldfpl
, ftp
->id
);
178 * There is no way to cancel the running diag X'2C4', the code
179 * needs to wait unconditionally until the transfer is complete.
181 wait_for_completion(&diag_ftp_rx_complete
);
184 pr_debug("completed DIAG X'2C4' after %lu ms\n",
185 (jiffies
- start_jiffies
) * 1000 / HZ
);
186 pr_debug("status of DIAG X'2C4' is %u, with %lld/%lld bytes\n",
187 diag_ftp_subcode
, ldfpl
->transferred
, ldfpl
->fsize
);
190 switch (diag_ftp_subcode
) {
191 case DIAG_FTP_STAT_OK
: /* success */
192 len
= ldfpl
->transferred
;
194 *fsize
= ldfpl
->fsize
;
196 case DIAG_FTP_STAT_LDNPERM
:
199 case DIAG_FTP_STAT_LDRUNS
:
202 case DIAG_FTP_STAT_LDFAIL
:
203 len
= -ENOENT
; /* no such file or media */
211 free_page((unsigned long) ldfpl
);
217 * diag_ftp_startup() - startup of FTP services, when running on z/VM
219 * Return: 0 on success, else an (negative) error code
221 int diag_ftp_startup(void)
225 rc
= register_external_irq(EXT_IRQ_CP_SERVICE
, diag_ftp_handler
);
229 irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL
);
234 * diag_ftp_shutdown() - shutdown of FTP services, when running on z/VM
236 void diag_ftp_shutdown(void)
238 irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL
);
239 unregister_external_irq(EXT_IRQ_CP_SERVICE
, diag_ftp_handler
);