drivers/s390/char/hmcdrv_ftp.c

Source file repositories/reference/linux-study-clean/drivers/s390/char/hmcdrv_ftp.c

File Facts

System
Linux kernel
Corpus path
drivers/s390/char/hmcdrv_ftp.c
Extension
.c
Size
8176 bytes
Lines
346
Domain
Driver Families
Bucket
drivers/s390
Inferred role
Driver Families: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct hmcdrv_ftp_ops {
	int (*startup)(void);
	void (*shutdown)(void);
	ssize_t (*transfer)(const struct hmcdrv_ftp_cmdspec *ftp,
			    size_t *fsize);
};

static enum hmcdrv_ftp_cmdid hmcdrv_ftp_cmd_getid(const char *cmd, int len);
static int hmcdrv_ftp_parse(char *cmd, struct hmcdrv_ftp_cmdspec *ftp);

static const struct hmcdrv_ftp_ops *hmcdrv_ftp_funcs; /* current operations */
static DEFINE_MUTEX(hmcdrv_ftp_mutex); /* mutex for hmcdrv_ftp_funcs */
static unsigned hmcdrv_ftp_refcnt; /* start/shutdown reference counter */

/**
 * hmcdrv_ftp_cmd_getid() - determine FTP command ID from a command string
 * @cmd: FTP command string (NOT zero-terminated)
 * @len: length of FTP command string in @cmd
 */
static enum hmcdrv_ftp_cmdid hmcdrv_ftp_cmd_getid(const char *cmd, int len)
{
	/* HMC FTP command descriptor */
	struct hmcdrv_ftp_cmd_desc {
		const char *str;	   /* command string */
		enum hmcdrv_ftp_cmdid cmd; /* associated command as enum */
	};

	/* Description of all HMC drive FTP commands
	 *
	 * Notes:
	 * 1. Array size should be a prime number.
	 * 2. Do not change the order of commands in table (because the
	 *    index is determined by CRC % ARRAY_SIZE).
	 * 3. Original command 'nlist' was renamed, else the CRC would
	 *    collide with 'append' (see point 2).
	 */
	static const struct hmcdrv_ftp_cmd_desc ftpcmds[7] = {

		{.str = "get", /* [0] get (CRC = 0x68eb) */
		 .cmd = HMCDRV_FTP_GET},
		{.str = "dir", /* [1] dir (CRC = 0x6a9e) */
		 .cmd = HMCDRV_FTP_DIR},
		{.str = "delete", /* [2] delete (CRC = 0x53ae) */
		 .cmd = HMCDRV_FTP_DELETE},
		{.str = "nls", /* [3] nls (CRC = 0xf87c) */
		 .cmd = HMCDRV_FTP_NLIST},
		{.str = "put", /* [4] put (CRC = 0xac56) */
		 .cmd = HMCDRV_FTP_PUT},
		{.str = "append", /* [5] append (CRC = 0xf56e) */
		 .cmd = HMCDRV_FTP_APPEND},
		{.str = NULL} /* [6] unused */
	};

	const struct hmcdrv_ftp_cmd_desc *pdesc;

	u16 crc = 0xffffU;

	if (len == 0)
		return HMCDRV_FTP_NOOP; /* error indiactor */

	crc = crc16(crc, cmd, len);
	pdesc = ftpcmds + (crc % ARRAY_SIZE(ftpcmds));
	pr_debug("FTP command '%s' has CRC 0x%04x, at table pos. %lu\n",
		 cmd, crc, (crc % ARRAY_SIZE(ftpcmds)));

	if (!pdesc->str || strncmp(pdesc->str, cmd, len))
		return HMCDRV_FTP_NOOP;

	pr_debug("FTP command '%s' found, with ID %d\n",
		 pdesc->str, pdesc->cmd);

	return pdesc->cmd;
}

/**
 * hmcdrv_ftp_parse() - HMC drive FTP command parser
 * @cmd: FTP command string "<cmd> <filename>"
 * @ftp: Pointer to FTP command specification buffer (output)
 *
 * Return: 0 on success, else a (negative) error code
 */
static int hmcdrv_ftp_parse(char *cmd, struct hmcdrv_ftp_cmdspec *ftp)
{
	char *start;
	int argc = 0;

	ftp->id = HMCDRV_FTP_NOOP;
	ftp->fname = NULL;

	while (*cmd != '\0') {

Annotation

Implementation Notes