1/*
2 *  include/asm-s390/chandev.h
3 *
4 *    Copyright (C) 2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 *    Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 *
7 *  Generic channel device initialisation support.
8 */
9#ifndef __S390_CHANDEV_H
10#define __S390_CHANDEV_H
11#include <linux/version.h>
12#include <asm/types.h>
13#include <linux/netdevice.h>
14
15
16/* Setting this flag to true causes a device name to be built based on the read_devno of the device */
17/* this is exported so external code can look at this flags setting */
18extern int chandev_use_devno_names;
19
20
21/* chandev_type is a bitmask for registering & describing device types. */
22typedef enum
23{
24	chandev_type_none=0x0,
25	chandev_type_ctc=0x1,
26	chandev_type_escon=0x2,
27	chandev_type_lcs=0x4,
28	chandev_type_osad=0x8,
29	chandev_type_qeth=0x10,
30	chandev_type_claw=0x20,
31} chandev_type;
32
33typedef enum
34{
35	chandev_category_none,
36	chandev_category_network_device,
37	chandev_category_serial_device,
38} chandev_category;
39
40
41
42typedef struct
43{
44	int     irq;
45	u16     devno;
46	u16     cu_type;      /* control unit type */
47	u8      cu_model;     /* control unit model */
48	u16     dev_type;     /* device type */
49	u8      dev_model;    /* device model */
50	u8      pim;          /* path installed mask */
51	u8      chpid[8];     /* CHPID 0-7 (if available) */
52} chandev_subchannel_info;
53
54#define CLAW_NAMELEN 9
55/* CLAW specific parameters other drivers should ignore these fields */
56typedef struct
57{
58
59	char	 host_name[CLAW_NAMELEN];    /* local host name */
60	char	 adapter_name[CLAW_NAMELEN]; /* workstation adapter name */
61	char	 api_type[CLAW_NAMELEN];     /* API type either TCPIP or API */
62} chandev_claw_info;
63
64/*
65 * The chandev_probeinfo structure is passed to the device driver with configuration
66 * info for which irq's & ports to use when attempting to probe the device.
67 */
68typedef struct
69{
70	chandev_subchannel_info read;
71	chandev_subchannel_info write;
72	chandev_subchannel_info data;
73	/* memory_usage_in_k is the suggested memory the driver should attempt to use for io */
74	/* buffers -1 means use the driver default the driver should set this field to the */
75	/* amount of memory it actually uses when returning this probeinfo to the channel */
76	/* device layer with chandev_initdevice */
77	s32     memory_usage_in_k;
78	chandev_claw_info       claw;
79	u8      data_exists; /* whether this device has a data channel */
80	u8      cu_dev_info_inconsistent; /* either ctc or we possibly had a bad sense_id */
81	u8      chpid_info_inconsistent;  /* either ctc or schib info bad */
82        s16     port_protocol_no; /* 0 by default, set specifically when forcing */
83	u8      hint_port_no;   /* lcs specific */
84	u8      max_port_no;    /* lcs/qeth specific */
85	chandev_type chan_type;
86	u8      checksum_received_ip_pkts;
87	u8      use_hw_stats; /* where available e.g. lcs */
88	u8      device_forced; /* indicates the device hasn't been autodetected */
89	char    *parmstr;       /* driver specific parameters added by add_parms keyword */
90	/* newdevice used internally by chandev.c */
91	struct  chandev_activelist *newdevice;
92	s32     devif_num;
93/* devif_num=-1 implies don't care,0 implies tr0, info used by chandev_initnetdevice */
94} chandev_probeinfo;
95
96/*
97 * This is a wrapper to the machine check handler & should be used
98 * instead of reqest_irq or s390_request_irq_special for anything
99 * using the channel device layer.
100 */
101int chandev_request_irq(unsigned int   irq,
102                      void           (*handler)(int, void *, struct pt_regs *),
103                      unsigned long  irqflags,
104                      const char    *devname,
105                      void          *dev_id);
106/*
107 * I originally believed this function wouldn't be necessary
108 * I subsequently found that reprobing failed in certain cases :-(,
109 * It is just a wrapper for free irq.
110 */
111void chandev_free_irq(unsigned int irq, void *dev_id);
112
113typedef enum
114{
115	chandev_status_good,
116	chandev_status_not_oper,
117	chandev_status_first_msck=chandev_status_not_oper,
118	chandev_status_no_path,
119	chandev_status_revalidate,
120	chandev_status_gone,
121	chandev_status_last_msck,
122	chandev_status_all_chans_good /* pseudo machine check to indicate all channels are healthy */
123} chandev_msck_status;
124
125typedef int (*chandev_probefunc)(chandev_probeinfo *probeinfo);
126typedef int (*chandev_shutdownfunc)(void *device);
127typedef void (*chandev_unregfunc)(void *device);
128typedef void (*chandev_msck_notification_func)(void *device,int msck_irq,
129chandev_msck_status prevstatus,chandev_msck_status newstatus);
130
131
132
133/* A driver should call chandev_register_and_probe when ready to be probed,
134 * after registeration the drivers probefunction will be called asynchronously
135 * when more devices become available at normal task time.
136 * The shutdownfunc parameter is used so that the channel layer
137 * can request a driver to close unregister itself & release its interrupts.
138 * repoper func is used when a device becomes operational again after being temporarily
139 * not operational the previous status is sent in the prevstatus variable.
140 * This can be used in cases when the default handling isn't quite adequete
141 * e.g. if a ssch is needed to reinitialize long running channel programs.
142 *
143 * This returns the number of devices found or -ENOMEM if the code didn't
144 * have enough memory to allocate the chandev control block
145 * or -EPERM if a duplicate entry is found.
146 */
147int chandev_register_and_probe(chandev_probefunc probefunc,
148			       chandev_shutdownfunc shutdownfunc,
149			       chandev_msck_notification_func msck_notfunc,
150			       chandev_type chan_type);
151
152/* The chandev_unregister function is typically called when a module is being removed
153 * from the system. The shutdown parameter if TRUE calls shutdownfunc for each
154 * device instance so the driver writer doesn't have to.
155 */
156void chandev_unregister(chandev_probefunc probefunc,int call_shutdown);
157
158/* chandev_initdevice should be called immeadiately before returning after */
159/* a successful probe. */
160int chandev_initdevice(chandev_probeinfo *probeinfo,void *dev_ptr,u8 port_no,char *devname,
161chandev_category category,chandev_unregfunc unreg_dev);
162
163/* This function builds a device name & copies it into destnamebuff suitable for calling
164   init_trdev or whatever & it honours the use_devno_names flag, it is used by chandev_initnetdevice
165   setting the buildfullname flag to TRUE will cause it to always build a full unique name based
166   on basename either honouring the chandev_use_devno_names flag if set or starting at index
167   0 & checking the namespace of the channel device layer itself for a free index, this
168   may be useful when one doesn't have control of the name an upper layer may choose.
169   It returns NULL on error.
170*/
171char *chandev_build_device_name(chandev_probeinfo *probeinfo,char *destnamebuff,char *basename,int buildfullname);
172
173
174
175
176/* chandev_init_netdev registers with the normal network device layer */
177/* it doesn't update any of the chandev internal structures. */
178/* i.e. it is optional */
179/* it was part of chandev_initnetdevice but I separated it as */
180/* chandev_initnetdevice may make too many assumptions for some users */
181/* chandev_initnetdevice = chandev_initdevice followed by chandev_init_netdev */
182#if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
183struct net_device *chandev_init_netdev(chandev_probeinfo *probeinfo,char *basename,
184struct net_device *dev, int sizeof_priv,struct net_device *(*init_netdevfunc)(struct net_device *dev, int sizeof_priv));
185#else
186struct device *chandev_init_netdev(chandev_probeinfo *probeinfo,char *basename,
187struct device *dev, int sizeof_priv,struct device *(*init_netdevfunc)(struct device *dev, int sizeof_priv));
188#endif
189
190/* chandev_initnetdevice registers a network device with the channel layer.
191 * It returns the device structure if successful,if dev=NULL it kmallocs it,
192 * On device initialisation failure it will kfree it under ALL curcumstances
193 * i.e. if dev is not NULL on entering this routine it MUST be malloced with kmalloc.
194 * The base name is tr ( e.g. tr0 without the 0 ), for token ring eth for ethernet,
195 *  ctc or escon for ctc device drivers.
196 * If valid function pointers are given they will be called to setup,
197 * register & unregister the device.
198 * An example of setup is eth_setup in drivers/net/net_init.c.
199 * An example of init_dev is init_trdev(struct net_device *dev)
200 * & an example of unregister is unregister_trdev,
201 * unregister_netdev should be used for escon & ctc
202 * as there is no network unregister_ctcdev in the kernel.
203*/
204
205#if LINUX_VERSION_CODE>=KERNEL_VERSION(2,3,0)
206struct net_device *chandev_initnetdevice(chandev_probeinfo *probeinfo,u8 port_no,
207					 struct net_device *dev,int sizeof_priv,
208					 char *basename,
209					 struct net_device *(*init_netdevfunc)
210					 (struct net_device *dev, int sizeof_priv),
211					 void (*unreg_netdevfunc)(struct net_device *dev));
212#else
213struct device *chandev_initnetdevice(chandev_probeinfo *probeinfo,u8 port_no,
214				     struct device *dev,int sizeof_priv,
215				     char *basename,
216				     struct device *(*init_netdevfunc)
217				     (struct device *dev, int sizeof_priv),
218				     void (*unreg_netdevfunc)(struct device *dev));
219#endif
220
221/* chandev_add & delete model shouldn't normally be needed by drivers except if */
222/* someone is developing a driver which the channel device layer doesn't know about */
223void chandev_add_model(chandev_type chan_type,s32 cu_type,s16 cu_model,
224		       s32 dev_type,s16 dev_model,u8 max_port_no,int auto_msck_recovery,
225		        u8 default_checksum_received_ip_pkts,u8 default_use_hw_stats);
226void chandev_del_model(s32 cu_type,s16 cu_model,s32 dev_type,s16 dev_model);
227
228/* modules should use chandev_persist to see if they should stay loaded */
229/* this is useful for debugging purposes where you may wish to examine */
230/* /proc/s390dbf/ entries */
231int chandev_persist(chandev_type chan_type);
232#endif /* __S390_CHANDEV_H */
233
234
235
236
237
238