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>
20 #include "hmcdrv_ftp.h"
23 /* DIAGNOSE X'2C4' return codes in Ry */
24 #define DIAG_FTP_RET_OK 0 /* HMC FTP started successfully */
25 #define DIAG_FTP_RET_EBUSY 4 /* HMC FTP service currently busy */
26 #define DIAG_FTP_RET_EIO 8 /* HMC FTP service I/O error */
27 /* and an artificial extension */
28 #define DIAG_FTP_RET_EPERM 2 /* HMC FTP service privilege error */
30 /* FTP service status codes (after INTR at guest real location 133) */
31 #define DIAG_FTP_STAT_OK 0U /* request completed successfully */
32 #define DIAG_FTP_STAT_PGCC 4U /* program check condition */
33 #define DIAG_FTP_STAT_PGIOE 8U /* paging I/O error */
34 #define DIAG_FTP_STAT_TIMEOUT 12U /* timeout */
35 #define DIAG_FTP_STAT_EBASE 16U /* base of error codes from SCLP */
36 #define DIAG_FTP_STAT_LDFAIL (DIAG_FTP_STAT_EBASE + 1U) /* failed */
37 #define DIAG_FTP_STAT_LDNPERM (DIAG_FTP_STAT_EBASE + 2U) /* not allowed */
38 #define DIAG_FTP_STAT_LDRUNS (DIAG_FTP_STAT_EBASE + 3U) /* runs */
39 #define DIAG_FTP_STAT_LDNRUNS (DIAG_FTP_STAT_EBASE + 4U) /* not runs */
42 * struct diag_ftp_ldfpl - load file FTP parameter list (LDFPL)
43 * @bufaddr: real buffer address (at 4k boundary)
44 * @buflen: length of buffer
45 * @offset: dir/file offset
46 * @intparm: interruption parameter (unused)
47 * @transferred: bytes transferred
48 * @fsize: file size, filled on GET
49 * @failaddr: failing address
51 * @fident: file name - ASCII
53 struct diag_ftp_ldfpl
{
62 u8 fident
[HMCDRV_FTP_FIDENT_MAX
];
65 static DECLARE_COMPLETION(diag_ftp_rx_complete
);
66 static int diag_ftp_subcode
;
69 * diag_ftp_handler() - FTP services IRQ handler
70 * @extirq: external interrupt (sub-) code
71 * @param32: 32-bit interruption parameter from &struct diag_ftp_ldfpl
72 * @param64: unused (for 64-bit interrupt parameters)
74 static void diag_ftp_handler(struct ext_code extirq
,
76 unsigned long param64
)
78 if ((extirq
.subcode
>> 8) != 8)
79 return; /* not a FTP services sub-code */
81 inc_irq_stat(IRQEXT_FTP
);
82 diag_ftp_subcode
= extirq
.subcode
& 0xffU
;
83 complete(&diag_ftp_rx_complete
);
87 * diag_ftp_2c4() - DIAGNOSE X'2C4' service call
88 * @fpl: pointer to prepared LDFPL
89 * @cmd: FTP command to be executed
91 * Performs a DIAGNOSE X'2C4' call with (input/output) FTP parameter list
92 * @fpl and FTP function code @cmd. In case of an error the function does
93 * nothing and returns an (negative) error code.
96 * 1. This function only initiates a transfer, so the caller must wait
97 * for completion (asynchronous execution).
98 * 2. The FTP parameter list @fpl must be aligned to a double-word boundary.
99 * 3. fpl->bufaddr must be a real address, 4k aligned
101 static int diag_ftp_2c4(struct diag_ftp_ldfpl
*fpl
,
102 enum hmcdrv_ftp_cmdid cmd
)
106 diag_stat_inc(DIAG_STAT_X2C4
);
108 " diag %[addr],%[cmd],0x2c4\n"
110 "1: la %[rc],%[err]\n"
113 : [rc
] "=d" (rc
), "+m" (*fpl
)
114 : [cmd
] "0" (cmd
), [addr
] "d" (virt_to_phys(fpl
)),
115 [err
] "i" (DIAG_FTP_RET_EPERM
)
119 case DIAG_FTP_RET_OK
:
121 case DIAG_FTP_RET_EBUSY
:
123 case DIAG_FTP_RET_EPERM
:
125 case DIAG_FTP_RET_EIO
:
132 * diag_ftp_cmd() - executes a DIAG X'2C4' FTP command, targeting a HMC
133 * @ftp: pointer to FTP command specification
134 * @fsize: return of file size (or NULL if undesirable)
136 * Attention: Notice that this function is not reentrant - so the caller
137 * must ensure locking.
139 * Return: number of bytes read/written or a (negative) error code
141 ssize_t
diag_ftp_cmd(const struct hmcdrv_ftp_cmdspec
*ftp
, size_t *fsize
)
143 struct diag_ftp_ldfpl
*ldfpl
;
146 unsigned long start_jiffies
;
148 pr_debug("starting DIAG X'2C4' on '%s', requesting %zd bytes\n",
149 ftp
->fname
, ftp
->len
);
150 start_jiffies
= jiffies
;
152 init_completion(&diag_ftp_rx_complete
);
154 ldfpl
= (void *) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
160 len
= strlcpy(ldfpl
->fident
, ftp
->fname
, sizeof(ldfpl
->fident
));
161 if (len
>= HMCDRV_FTP_FIDENT_MAX
) {
166 ldfpl
->transferred
= 0;
168 ldfpl
->offset
= ftp
->ofs
;
169 ldfpl
->buflen
= ftp
->len
;
170 ldfpl
->bufaddr
= virt_to_phys(ftp
->buf
);
172 len
= diag_ftp_2c4(ldfpl
, ftp
->id
);
177 * There is no way to cancel the running diag X'2C4', the code
178 * needs to wait unconditionally until the transfer is complete.
180 wait_for_completion(&diag_ftp_rx_complete
);
183 pr_debug("completed DIAG X'2C4' after %lu ms\n",
184 (jiffies
- start_jiffies
) * 1000 / HZ
);
185 pr_debug("status of DIAG X'2C4' is %u, with %lld/%lld bytes\n",
186 diag_ftp_subcode
, ldfpl
->transferred
, ldfpl
->fsize
);
189 switch (diag_ftp_subcode
) {
190 case DIAG_FTP_STAT_OK
: /* success */
191 len
= ldfpl
->transferred
;
193 *fsize
= ldfpl
->fsize
;
195 case DIAG_FTP_STAT_LDNPERM
:
198 case DIAG_FTP_STAT_LDRUNS
:
201 case DIAG_FTP_STAT_LDFAIL
:
202 len
= -ENOENT
; /* no such file or media */
210 free_page((unsigned long) ldfpl
);
216 * diag_ftp_startup() - startup of FTP services, when running on z/VM
218 * Return: 0 on success, else an (negative) error code
220 int diag_ftp_startup(void)
224 rc
= register_external_irq(EXT_IRQ_CP_SERVICE
, diag_ftp_handler
);
228 irq_subclass_register(IRQ_SUBCLASS_SERVICE_SIGNAL
);
233 * diag_ftp_shutdown() - shutdown of FTP services, when running on z/VM
235 void diag_ftp_shutdown(void)
237 irq_subclass_unregister(IRQ_SUBCLASS_SERVICE_SIGNAL
);
238 unregister_external_irq(EXT_IRQ_CP_SERVICE
, diag_ftp_handler
);