18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *    Copyright IBM Corp. 2007, 2012
48c2ecf20Sopenharmony_ci *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef _ASM_S390_CHPID_H
78c2ecf20Sopenharmony_ci#define _ASM_S390_CHPID_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <uapi/asm/chpid.h>
108c2ecf20Sopenharmony_ci#include <asm/cio.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cistruct channel_path_desc_fmt0 {
138c2ecf20Sopenharmony_ci	u8 flags;
148c2ecf20Sopenharmony_ci	u8 lsn;
158c2ecf20Sopenharmony_ci	u8 desc;
168c2ecf20Sopenharmony_ci	u8 chpid;
178c2ecf20Sopenharmony_ci	u8 swla;
188c2ecf20Sopenharmony_ci	u8 zeroes;
198c2ecf20Sopenharmony_ci	u8 chla;
208c2ecf20Sopenharmony_ci	u8 chpp;
218c2ecf20Sopenharmony_ci} __packed;
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic inline void chp_id_init(struct chp_id *chpid)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	memset(chpid, 0, sizeof(struct chp_id));
268c2ecf20Sopenharmony_ci}
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_cistatic inline int chp_id_is_equal(struct chp_id *a, struct chp_id *b)
298c2ecf20Sopenharmony_ci{
308c2ecf20Sopenharmony_ci	return (a->id == b->id) && (a->cssid == b->cssid);
318c2ecf20Sopenharmony_ci}
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cistatic inline void chp_id_next(struct chp_id *chpid)
348c2ecf20Sopenharmony_ci{
358c2ecf20Sopenharmony_ci	if (chpid->id < __MAX_CHPID)
368c2ecf20Sopenharmony_ci		chpid->id++;
378c2ecf20Sopenharmony_ci	else {
388c2ecf20Sopenharmony_ci		chpid->id = 0;
398c2ecf20Sopenharmony_ci		chpid->cssid++;
408c2ecf20Sopenharmony_ci	}
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic inline int chp_id_is_valid(struct chp_id *chpid)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	return (chpid->cssid <= __MAX_CSSID);
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define chp_id_for_each(c) \
508c2ecf20Sopenharmony_ci	for (chp_id_init(c); chp_id_is_valid(c); chp_id_next(c))
518c2ecf20Sopenharmony_ci#endif /* _ASM_S390_CHPID_H */
52