]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - drivers/s390/net/claw.c
[PATCH] changing CONFIG_LOCALVERSION rebuilds too much, for no good reason
[linux-2.6.git] / drivers / s390 / net / claw.c
1 /*
2  *  drivers/s390/net/claw.c
3  *    ESCON CLAW network driver
4  *
5  *    $Revision: 1.38 $ $Date: 2005/08/29 09:47:04 $
6  *
7  *  Linux for zSeries version
8  *    Copyright (C) 2002,2005 IBM Corporation
9  *  Author(s) Original code written by:
10  *              Kazuo Iimura (iimura@jp.ibm.com)
11  *            Rewritten by
12  *              Andy Richter (richtera@us.ibm.com)
13  *              Marc Price (mwprice@us.ibm.com)
14  *
15  *    sysfs parms:
16  *   group x.x.rrrr,x.x.wwww
17  *   read_buffer nnnnnnn
18  *   write_buffer nnnnnn
19  *   host_name  aaaaaaaa
20  *   adapter_name aaaaaaaa
21  *   api_type    aaaaaaaa
22  *
23  *  eg.
24  *   group  0.0.0200 0.0.0201
25  *   read_buffer 25
26  *   write_buffer 20
27  *   host_name LINUX390
28  *   adapter_name RS6K
29  *   api_type     TCPIP
30  *
31  *  where
32  *
33  *   The device id is decided by the order entries
34  *   are added to the group the first is claw0 the second claw1
35  *   up to CLAW_MAX_DEV
36  *
37  *   rrrr     - the first of 2 consecutive device addresses used for the
38  *              CLAW protocol.
39  *              The specified address is always used as the input (Read)
40  *              channel and the next address is used as the output channel.
41  *
42  *   wwww     - the second of 2 consecutive device addresses used for
43  *              the CLAW protocol.
44  *              The specified address is always used as the output
45  *              channel and the previous address is used as the input channel.
46  *
47  *   read_buffer        -       specifies number of input buffers to allocate.
48  *   write_buffer       -       specifies number of output buffers to allocate.
49  *   host_name          -       host name
50  *   adaptor_name       -       adaptor name
51  *   api_type           -       API type TCPIP or API will be sent and expected
52  *                              as ws_name
53  *
54  *   Note the following requirements:
55  *   1)  host_name must match the configured adapter_name on the remote side
56  *   2)  adaptor_name must match the configured host name on the remote side
57  *
58  *  Change History
59  *    1.00  Initial release shipped
60  *    1.10  Changes for Buffer allocation
61  *    1.15  Changed for 2.6 Kernel  No longer compiles on 2.4 or lower
62  *    1.25  Added Packing support
63  */
64 #include <asm/bitops.h>
65 #include <asm/ccwdev.h>
66 #include <asm/ccwgroup.h>
67 #include <asm/debug.h>
68 #include <asm/idals.h>
69 #include <asm/io.h>
70
71 #include <linux/ctype.h>
72 #include <linux/delay.h>
73 #include <linux/errno.h>
74 #include <linux/if_arp.h>
75 #include <linux/init.h>
76 #include <linux/interrupt.h>
77 #include <linux/ip.h>
78 #include <linux/kernel.h>
79 #include <linux/module.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/proc_fs.h>
83 #include <linux/sched.h>
84 #include <linux/signal.h>
85 #include <linux/skbuff.h>
86 #include <linux/slab.h>
87 #include <linux/string.h>
88 #include <linux/tcp.h>
89 #include <linux/timer.h>
90 #include <linux/types.h>
91
92 #include "cu3088.h"
93 #include "claw.h"
94
95 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
96 MODULE_DESCRIPTION("Linux for zSeries CLAW Driver\n" \
97                         "Copyright 2000,2005 IBM Corporation\n");
98 MODULE_LICENSE("GPL");
99
100 /* Debugging is based on DEBUGMSG, IOTRACE, or FUNCTRACE  options:
101    DEBUGMSG  - Enables output of various debug messages in the code
102    IOTRACE   - Enables output of CCW and other IO related traces
103    FUNCTRACE - Enables output of function entry/exit trace
104    Define any combination of above options to enable tracing
105
106    CLAW also uses the s390dbf file system  see claw_trace and claw_setup
107 */
108
109 /* following enables tracing */
110 //#define DEBUGMSG
111 //#define IOTRACE
112 //#define FUNCTRACE
113
114 #ifdef DEBUGMSG
115 #define DEBUG
116 #endif
117
118 #ifdef IOTRACE
119 #define DEBUG
120 #endif
121
122 #ifdef FUNCTRACE
123 #define DEBUG
124 #endif
125
126  char debug_buffer[255];
127 /**
128  * Debug Facility Stuff
129  */
130 static debug_info_t *claw_dbf_setup;
131 static debug_info_t *claw_dbf_trace;
132
133 /**
134  *  CLAW Debug Facility functions
135  */
136 static void
137 claw_unregister_debug_facility(void)
138 {
139         if (claw_dbf_setup)
140                 debug_unregister(claw_dbf_setup);
141         if (claw_dbf_trace)
142                 debug_unregister(claw_dbf_trace);
143 }
144
145 static int
146 claw_register_debug_facility(void)
147 {
148         claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
149         claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
150         if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
151                 printk(KERN_WARNING "Not enough memory for debug facility.\n");
152                 claw_unregister_debug_facility();
153                 return -ENOMEM;
154         }
155         debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
156         debug_set_level(claw_dbf_setup, 2);
157         debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
158         debug_set_level(claw_dbf_trace, 2);
159         return 0;
160 }
161
162 static inline void
163 claw_set_busy(struct net_device *dev)
164 {
165  ((struct claw_privbk *) dev->priv)->tbusy=1;
166  eieio();
167 }
168
169 static inline void
170 claw_clear_busy(struct net_device *dev)
171 {
172         clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
173         netif_wake_queue(dev);
174         eieio();
175 }
176
177 static inline int
178 claw_check_busy(struct net_device *dev)
179 {
180         eieio();
181         return ((struct claw_privbk *) dev->priv)->tbusy;
182 }
183
184 static inline void
185 claw_setbit_busy(int nr,struct net_device *dev)
186 {
187         netif_stop_queue(dev);
188         set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
189 }
190
191 static inline void
192 claw_clearbit_busy(int nr,struct net_device *dev)
193 {
194         clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
195         netif_wake_queue(dev);
196 }
197
198 static inline int
199 claw_test_and_setbit_busy(int nr,struct net_device *dev)
200 {
201         netif_stop_queue(dev);
202         return test_and_set_bit(nr,
203                 (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
204 }
205
206
207 /* Functions for the DEV methods */
208
209 static int claw_probe(struct ccwgroup_device *cgdev);
210 static void claw_remove_device(struct ccwgroup_device *cgdev);
211 static void claw_purge_skb_queue(struct sk_buff_head *q);
212 static int claw_new_device(struct ccwgroup_device *cgdev);
213 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
214 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
215 static int claw_change_mtu( struct net_device *dev, int new_mtu);
216 static int claw_open(struct net_device *dev);
217 static void claw_irq_handler(struct ccw_device *cdev,
218         unsigned long intparm, struct irb *irb);
219 static void claw_irq_tasklet ( unsigned long data );
220 static int claw_release(struct net_device *dev);
221 static void claw_write_retry ( struct chbk * p_ch );
222 static void claw_write_next ( struct chbk * p_ch );
223 static void claw_timer ( struct chbk * p_ch );
224
225 /* Functions */
226 static int add_claw_reads(struct net_device *dev,
227         struct ccwbk* p_first, struct ccwbk* p_last);
228 static void inline ccw_check_return_code (struct ccw_device *cdev,
229         int return_code);
230 static void inline ccw_check_unit_check (struct chbk * p_ch,
231         unsigned char sense );
232 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
233 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
234 static int init_ccw_bk(struct net_device *dev);
235 static void probe_error( struct ccwgroup_device *cgdev);
236 static struct net_device_stats *claw_stats(struct net_device *dev);
237 static int inline pages_to_order_of_mag(int num_of_pages);
238 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
239 #ifdef DEBUG
240 static void dumpit (char *buf, int len);
241 #endif
242 /* sysfs Functions */
243 static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
244 static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
245         const char *buf, size_t count);
246 static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
247 static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
248         const char *buf, size_t count);
249 static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
250 static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
251         const char *buf, size_t count);
252 static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
253 static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
254         const char *buf, size_t count);
255 static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
256 static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
257         const char *buf, size_t count);
258 static int claw_add_files(struct device *dev);
259 static void claw_remove_files(struct device *dev);
260
261 /*   Functions for System Validate  */
262 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
263 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
264        __u8 correlator, __u8 rc , char *local_name, char *remote_name);
265 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
266 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
267 static int claw_snd_sys_validate_rsp(struct net_device *dev,
268         struct clawctl * p_ctl, __u32 return_code);
269 static int claw_strt_conn_req(struct net_device *dev );
270 static void claw_strt_read ( struct net_device *dev, int lock );
271 static void claw_strt_out_IO( struct net_device *dev );
272 static void claw_free_wrt_buf( struct net_device *dev );
273
274 /* Functions for unpack reads   */
275 static void unpack_read (struct net_device *dev );
276
277 /* ccwgroup table  */
278
279 static struct ccwgroup_driver claw_group_driver = {
280         .owner       = THIS_MODULE,
281         .name        = "claw",
282         .max_slaves  = 2,
283         .driver_id   = 0xC3D3C1E6,
284         .probe       = claw_probe,
285         .remove      = claw_remove_device,
286         .set_online  = claw_new_device,
287         .set_offline = claw_shutdown_device,
288 };
289
290 /*
291 *
292 *       Key functions
293 */
294
295 /*----------------------------------------------------------------*
296  *   claw_probe                                                   *
297  *      this function is called for each CLAW device.             *
298  *----------------------------------------------------------------*/
299 static int
300 claw_probe(struct ccwgroup_device *cgdev)
301 {
302         int             rc;
303         struct claw_privbk *privptr=NULL;
304
305 #ifdef FUNCTRACE
306         printk(KERN_INFO "%s Enter\n",__FUNCTION__);
307 #endif
308         CLAW_DBF_TEXT(2,setup,"probe");
309         if (!get_device(&cgdev->dev))
310                 return -ENODEV;
311 #ifdef DEBUGMSG
312         printk(KERN_INFO "claw: variable cgdev =\n");
313         dumpit((char *)cgdev, sizeof(struct ccwgroup_device));
314 #endif
315         privptr = kmalloc(sizeof(struct claw_privbk), GFP_KERNEL);
316         if (privptr == NULL) {
317                 probe_error(cgdev);
318                 put_device(&cgdev->dev);
319                 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
320                         cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
321                 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
322                 return -ENOMEM;
323         }
324         memset(privptr,0x00,sizeof(struct claw_privbk));
325         privptr->p_mtc_envelope= kmalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
326         privptr->p_env = kmalloc(sizeof(struct claw_env), GFP_KERNEL);
327         if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
328                 probe_error(cgdev);
329                 put_device(&cgdev->dev);
330                 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
331                         cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
332                 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
333                 return -ENOMEM;
334         }
335         memset(privptr->p_mtc_envelope, 0x00, MAX_ENVELOPE_SIZE);
336         memset(privptr->p_env, 0x00, sizeof(struct claw_env));
337         memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
338         memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
339         memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
340         privptr->p_env->packing = 0;
341         privptr->p_env->write_buffers = 5;
342         privptr->p_env->read_buffers = 5;
343         privptr->p_env->read_size = CLAW_FRAME_SIZE;
344         privptr->p_env->write_size = CLAW_FRAME_SIZE;
345         rc = claw_add_files(&cgdev->dev);
346         if (rc) {
347                 probe_error(cgdev);
348                 put_device(&cgdev->dev);
349                 printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
350                         cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
351                 CLAW_DBF_TEXT_(2,setup,"probex%d",rc);
352                 return rc;
353         }
354         printk(KERN_INFO "claw: sysfs files added for %s\n",cgdev->cdev[0]->dev.bus_id);
355         privptr->p_env->p_priv = privptr;
356         cgdev->cdev[0]->handler = claw_irq_handler;
357         cgdev->cdev[1]->handler = claw_irq_handler;
358         cgdev->dev.driver_data = privptr;
359 #ifdef FUNCTRACE
360         printk(KERN_INFO "claw:%s exit on line %d, "
361                 "rc = 0\n",__FUNCTION__,__LINE__);
362 #endif
363         CLAW_DBF_TEXT(2,setup,"prbext 0");
364
365         return 0;
366 }  /*  end of claw_probe       */
367
368 /*-------------------------------------------------------------------*
369  *   claw_tx                                                         *
370  *-------------------------------------------------------------------*/
371
372 static int
373 claw_tx(struct sk_buff *skb, struct net_device *dev)
374 {
375         int             rc;
376         struct claw_privbk *privptr=dev->priv;
377         unsigned long saveflags;
378         struct chbk *p_ch;
379
380 #ifdef FUNCTRACE
381         printk(KERN_INFO "%s:%s enter\n",dev->name,__FUNCTION__);
382 #endif
383         CLAW_DBF_TEXT(4,trace,"claw_tx");
384         p_ch=&privptr->channel[WRITE];
385         if (skb == NULL) {
386                 printk(KERN_WARNING "%s: null pointer passed as sk_buffer\n",
387                         dev->name);
388                 privptr->stats.tx_dropped++;
389 #ifdef FUNCTRACE
390                 printk(KERN_INFO "%s: %s() exit on line %d, rc = EIO\n",
391                         dev->name,__FUNCTION__, __LINE__);
392 #endif
393                 CLAW_DBF_TEXT_(2,trace,"clawtx%d",-EIO);
394                 return -EIO;
395         }
396
397 #ifdef IOTRACE
398         printk(KERN_INFO "%s: variable sk_buff=\n",dev->name);
399         dumpit((char *) skb, sizeof(struct sk_buff));
400         printk(KERN_INFO "%s: variable dev=\n",dev->name);
401         dumpit((char *) dev, sizeof(struct net_device));
402 #endif
403         spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
404         rc=claw_hw_tx( skb, dev, 1 );
405         spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
406 #ifdef FUNCTRACE
407         printk(KERN_INFO "%s:%s exit on line %d, rc = %d\n",
408                 dev->name, __FUNCTION__, __LINE__, rc);
409 #endif
410         CLAW_DBF_TEXT_(4,trace,"clawtx%d",rc);
411         return rc;
412 }   /*  end of claw_tx */
413
414 /*------------------------------------------------------------------*
415  *  pack the collect queue into an skb and return it                *
416  *   If not packing just return the top skb from the queue          *
417  *------------------------------------------------------------------*/
418
419 static struct sk_buff *
420 claw_pack_skb(struct claw_privbk *privptr)
421 {
422         struct sk_buff *new_skb,*held_skb;
423         struct chbk *p_ch = &privptr->channel[WRITE];
424         struct claw_env  *p_env = privptr->p_env;
425         int     pkt_cnt,pk_ind,so_far;
426
427         new_skb = NULL;         /* assume no dice */
428         pkt_cnt = 0;
429         CLAW_DBF_TEXT(4,trace,"PackSKBe");
430         if (!skb_queue_empty(&p_ch->collect_queue)) {
431         /* some data */
432                 held_skb = skb_dequeue(&p_ch->collect_queue);
433                 if (held_skb)
434                         dev_kfree_skb_any(held_skb);
435                 else
436                         return NULL;
437                 if (p_env->packing != DO_PACKED)
438                         return held_skb;
439                 /* get a new SKB we will pack at least one */
440                 new_skb = dev_alloc_skb(p_env->write_size);
441                 if (new_skb == NULL) {
442                         atomic_inc(&held_skb->users);
443                         skb_queue_head(&p_ch->collect_queue,held_skb);
444                         return NULL;
445                 }
446                 /* we have packed packet and a place to put it  */
447                 pk_ind = 1;
448                 so_far = 0;
449                 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
450                 while ((pk_ind) && (held_skb != NULL)) {
451                         if (held_skb->len+so_far <= p_env->write_size-8) {
452                                 memcpy(skb_put(new_skb,held_skb->len),
453                                         held_skb->data,held_skb->len);
454                                 privptr->stats.tx_packets++;
455                                 so_far += held_skb->len;
456                                 pkt_cnt++;
457                                 dev_kfree_skb_any(held_skb);
458                                 held_skb = skb_dequeue(&p_ch->collect_queue);
459                                 if (held_skb)
460                                         atomic_dec(&held_skb->users);
461                         } else {
462                                 pk_ind = 0;
463                                 atomic_inc(&held_skb->users);
464                                 skb_queue_head(&p_ch->collect_queue,held_skb);
465                         }
466                 }
467 #ifdef IOTRACE
468                 printk(KERN_INFO "%s: %s() Packed %d len %d\n",
469                         p_env->ndev->name,
470                         __FUNCTION__,pkt_cnt,new_skb->len);
471 #endif
472         }
473         CLAW_DBF_TEXT(4,trace,"PackSKBx");
474         return new_skb;
475 }
476
477 /*-------------------------------------------------------------------*
478  *   claw_change_mtu                                                 *
479  *                                                                   *
480  *-------------------------------------------------------------------*/
481
482 static int
483 claw_change_mtu(struct net_device *dev, int new_mtu)
484 {
485         struct claw_privbk  *privptr=dev->priv;
486         int buff_size;
487 #ifdef FUNCTRACE
488         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
489 #endif
490 #ifdef DEBUGMSG
491         printk(KERN_INFO "variable dev =\n");
492         dumpit((char *) dev, sizeof(struct net_device));
493         printk(KERN_INFO "variable new_mtu = %d\n", new_mtu);
494 #endif
495         CLAW_DBF_TEXT(4,trace,"setmtu");
496         buff_size = privptr->p_env->write_size;
497         if ((new_mtu < 60) || (new_mtu > buff_size)) {
498 #ifdef FUNCTRACE
499                 printk(KERN_INFO "%s:%s Exit on line %d, rc=EINVAL\n",
500                 dev->name,
501                 __FUNCTION__, __LINE__);
502 #endif
503                 return -EINVAL;
504         }
505         dev->mtu = new_mtu;
506 #ifdef FUNCTRACE
507         printk(KERN_INFO "%s:%s Exit on line %d\n",dev->name,
508         __FUNCTION__, __LINE__);
509 #endif
510         return 0;
511 }  /*   end of claw_change_mtu */
512
513
514 /*-------------------------------------------------------------------*
515  *   claw_open                                                       *
516  *                                                                   *
517  *-------------------------------------------------------------------*/
518 static int
519 claw_open(struct net_device *dev)
520 {
521
522         int     rc;
523         int     i;
524         unsigned long       saveflags=0;
525         unsigned long       parm;
526         struct claw_privbk  *privptr;
527         DECLARE_WAITQUEUE(wait, current);
528         struct timer_list  timer;
529         struct ccwbk *p_buf;
530
531 #ifdef FUNCTRACE
532         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
533 #endif
534         CLAW_DBF_TEXT(4,trace,"open");
535         if (!dev | (dev->name[0] == 0x00)) {
536                 CLAW_DBF_TEXT(2,trace,"BadDev");
537                 printk(KERN_WARNING "claw: Bad device at open failing \n");
538                 return -ENODEV;
539         }
540         privptr = (struct claw_privbk *)dev->priv;
541         /*   allocate and initialize CCW blocks */
542         if (privptr->buffs_alloc == 0) {
543                 rc=init_ccw_bk(dev);
544                 if (rc) {
545                         printk(KERN_INFO "%s:%s Exit on line %d, rc=ENOMEM\n",
546                         dev->name,
547                         __FUNCTION__, __LINE__);
548                         CLAW_DBF_TEXT(2,trace,"openmem");
549                         return -ENOMEM;
550                 }
551         }
552         privptr->system_validate_comp=0;
553         privptr->release_pend=0;
554         if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
555                 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
556                 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
557                 privptr->p_env->packing=PACKING_ASK;
558         } else {
559                 privptr->p_env->packing=0;
560                 privptr->p_env->read_size=CLAW_FRAME_SIZE;
561                 privptr->p_env->write_size=CLAW_FRAME_SIZE;
562         }
563         claw_set_busy(dev);
564         tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
565                 (unsigned long) &privptr->channel[READ]);
566         for ( i = 0; i < 2;  i++) {
567                 CLAW_DBF_TEXT_(2,trace,"opn_ch%d",i);
568                 init_waitqueue_head(&privptr->channel[i].wait);
569                 /* skb_queue_head_init(&p_ch->io_queue); */
570                 if (i == WRITE)
571                         skb_queue_head_init(
572                                 &privptr->channel[WRITE].collect_queue);
573                 privptr->channel[i].flag_a = 0;
574                 privptr->channel[i].IO_active = 0;
575                 privptr->channel[i].flag  &= ~CLAW_TIMER;
576                 init_timer(&timer);
577                 timer.function = (void *)claw_timer;
578                 timer.data = (unsigned long)(&privptr->channel[i]);
579                 timer.expires = jiffies + 15*HZ;
580                 add_timer(&timer);
581                 spin_lock_irqsave(get_ccwdev_lock(
582                         privptr->channel[i].cdev), saveflags);
583                 parm = (unsigned long) &privptr->channel[i];
584                 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
585                 rc = 0;
586                 add_wait_queue(&privptr->channel[i].wait, &wait);
587                 rc = ccw_device_halt(
588                         (struct ccw_device *)privptr->channel[i].cdev,parm);
589                 set_current_state(TASK_INTERRUPTIBLE);
590                 spin_unlock_irqrestore(
591                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
592                 schedule();
593                 set_current_state(TASK_RUNNING);
594                 remove_wait_queue(&privptr->channel[i].wait, &wait);
595                 if(rc != 0)
596                         ccw_check_return_code(privptr->channel[i].cdev, rc);
597                 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
598                         del_timer(&timer);
599         }
600         if ((((privptr->channel[READ].last_dstat |
601                 privptr->channel[WRITE].last_dstat) &
602            ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
603            (((privptr->channel[READ].flag |
604                 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
605 #ifdef DEBUGMSG
606                 printk(KERN_INFO "%s: channel problems during open - read:"
607                         " %02x -  write: %02x\n",
608                         dev->name,
609                         privptr->channel[READ].last_dstat,
610                         privptr->channel[WRITE].last_dstat);
611 #endif
612                 printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
613                 CLAW_DBF_TEXT(2,trace,"notrdy");
614
615                 for ( i = 0; i < 2;  i++) {
616                         spin_lock_irqsave(
617                                 get_ccwdev_lock(privptr->channel[i].cdev),
618                                 saveflags);
619                         parm = (unsigned long) &privptr->channel[i];
620                         privptr->channel[i].claw_state = CLAW_STOP;
621                         rc = ccw_device_halt(
622                                 (struct ccw_device *)&privptr->channel[i].cdev,
623                                 parm);
624                         spin_unlock_irqrestore(
625                                 get_ccwdev_lock(privptr->channel[i].cdev),
626                                 saveflags);
627                         if (rc != 0) {
628                                 ccw_check_return_code(
629                                         privptr->channel[i].cdev, rc);
630                         }
631                 }
632                 free_pages((unsigned long)privptr->p_buff_ccw,
633                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
634                 if (privptr->p_env->read_size < PAGE_SIZE) {
635                         free_pages((unsigned long)privptr->p_buff_read,
636                                (int)pages_to_order_of_mag(
637                                         privptr->p_buff_read_num));
638                 }
639                 else {
640                         p_buf=privptr->p_read_active_first;
641                         while (p_buf!=NULL) {
642                                 free_pages((unsigned long)p_buf->p_buffer,
643                                       (int)pages_to_order_of_mag(
644                                         privptr->p_buff_pages_perread ));
645                                 p_buf=p_buf->next;
646                         }
647                 }
648                 if (privptr->p_env->write_size < PAGE_SIZE ) {
649                         free_pages((unsigned long)privptr->p_buff_write,
650                              (int)pages_to_order_of_mag(
651                                 privptr->p_buff_write_num));
652                 }
653                 else {
654                         p_buf=privptr->p_write_active_first;
655                         while (p_buf!=NULL) {
656                                 free_pages((unsigned long)p_buf->p_buffer,
657                                      (int)pages_to_order_of_mag(
658                                         privptr->p_buff_pages_perwrite ));
659                                 p_buf=p_buf->next;
660                         }
661                 }
662                 privptr->buffs_alloc = 0;
663                 privptr->channel[READ].flag= 0x00;
664                 privptr->channel[WRITE].flag = 0x00;
665                 privptr->p_buff_ccw=NULL;
666                 privptr->p_buff_read=NULL;
667                 privptr->p_buff_write=NULL;
668                 claw_clear_busy(dev);
669 #ifdef FUNCTRACE
670                 printk(KERN_INFO "%s:%s Exit on line %d, rc=EIO\n",
671                 dev->name,__FUNCTION__,__LINE__);
672 #endif
673                 CLAW_DBF_TEXT(2,trace,"open EIO");
674                 return -EIO;
675         }
676
677         /*   Send SystemValidate command */
678
679         claw_clear_busy(dev);
680
681 #ifdef FUNCTRACE
682         printk(KERN_INFO "%s:%s Exit on line %d, rc=0\n",
683                 dev->name,__FUNCTION__,__LINE__);
684 #endif
685         CLAW_DBF_TEXT(4,trace,"openok");
686         return 0;
687 }    /*     end of claw_open    */
688
689 /*-------------------------------------------------------------------*
690 *                                                                    *
691 *       claw_irq_handler                                             *
692 *                                                                    *
693 *--------------------------------------------------------------------*/
694 static void
695 claw_irq_handler(struct ccw_device *cdev,
696         unsigned long intparm, struct irb *irb)
697 {
698         struct chbk *p_ch = NULL;
699         struct claw_privbk *privptr = NULL;
700         struct net_device *dev = NULL;
701         struct claw_env  *p_env;
702         struct chbk *p_ch_r=NULL;
703
704
705 #ifdef FUNCTRACE
706         printk(KERN_INFO "%s enter  \n",__FUNCTION__);
707 #endif
708         CLAW_DBF_TEXT(4,trace,"clawirq");
709         /* Bypass all 'unsolicited interrupts' */
710         if (!cdev->dev.driver_data) {
711                 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
712                         "%s received c-%02x d-%02x\n",
713                         cdev->dev.bus_id,irb->scsw.cstat, irb->scsw.dstat);
714 #ifdef FUNCTRACE
715                 printk(KERN_INFO "claw: %s() "
716                         "exit on line %d\n",__FUNCTION__,__LINE__);
717 #endif
718                 CLAW_DBF_TEXT(2,trace,"badirq");
719                 return;
720         }
721         privptr = (struct claw_privbk *)cdev->dev.driver_data;
722
723         /* Try to extract channel from driver data. */
724         if (privptr->channel[READ].cdev == cdev)
725                 p_ch = &privptr->channel[READ];
726         else if (privptr->channel[WRITE].cdev == cdev)
727                 p_ch = &privptr->channel[WRITE];
728         else {
729                 printk(KERN_WARNING "claw: Can't determine channel for "
730                         "interrupt, device %s\n", cdev->dev.bus_id);
731                 CLAW_DBF_TEXT(2,trace,"badchan");
732                 return;
733         }
734         CLAW_DBF_TEXT_(4,trace,"IRQCH=%d",p_ch->flag);
735
736         dev = (struct net_device *) (p_ch->ndev);
737         p_env=privptr->p_env;
738
739 #ifdef IOTRACE
740         printk(KERN_INFO "%s: interrupt for device: %04x "
741                 "received c-%02x d-%02x state-%02x\n",
742                 dev->name, p_ch->devno, irb->scsw.cstat,
743                 irb->scsw.dstat, p_ch->claw_state);
744 #endif
745
746         /* Copy interruption response block. */
747         memcpy(p_ch->irb, irb, sizeof(struct irb));
748
749         /* Check for good subchannel return code, otherwise error message */
750         if (irb->scsw.cstat  &&  !(irb->scsw.cstat & SCHN_STAT_PCI)) {
751                 printk(KERN_INFO "%s: subchannel check for device: %04x -"
752                         " Sch Stat %02x  Dev Stat %02x CPA - %04x\n",
753                         dev->name, p_ch->devno,
754                         irb->scsw.cstat, irb->scsw.dstat,irb->scsw.cpa);
755 #ifdef IOTRACE
756                 dumpit((char *)irb,sizeof(struct irb));
757                 dumpit((char *)(unsigned long)irb->scsw.cpa,
758                         sizeof(struct ccw1));
759 #endif
760 #ifdef FUNCTRACE
761                 printk(KERN_INFO "%s:%s Exit on line %d\n",
762                 dev->name,__FUNCTION__,__LINE__);
763 #endif
764                 CLAW_DBF_TEXT(2,trace,"chanchk");
765                 /* return; */
766         }
767
768         /* Check the reason-code of a unit check */
769         if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
770                 ccw_check_unit_check(p_ch, irb->ecw[0]);
771         }
772
773         /* State machine to bring the connection up, down and to restart */
774         p_ch->last_dstat = irb->scsw.dstat;
775
776         switch (p_ch->claw_state) {
777                 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
778 #ifdef DEBUGMSG
779                         printk(KERN_INFO "%s: CLAW_STOP enter\n", dev->name);
780 #endif
781                         if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
782                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
783                         (p_ch->irb->scsw.stctl ==
784                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
785 #ifdef FUNCTRACE
786                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
787                                         dev->name,__FUNCTION__,__LINE__);
788 #endif
789                                 return;
790                         }
791                         wake_up(&p_ch->wait);   /* wake up claw_release */
792
793 #ifdef DEBUGMSG
794                         printk(KERN_INFO "%s: CLAW_STOP exit\n", dev->name);
795 #endif
796 #ifdef FUNCTRACE
797                         printk(KERN_INFO "%s:%s Exit on line %d\n",
798                                 dev->name,__FUNCTION__,__LINE__);
799 #endif
800                         CLAW_DBF_TEXT(4,trace,"stop");
801                         return;
802
803                 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open  */
804 #ifdef DEBUGMSG
805                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO\n",
806                                 dev->name);
807 #endif
808                         if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
809                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
810                         (p_ch->irb->scsw.stctl ==
811                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
812 #ifdef FUNCTRACE
813                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
814                                         dev->name,__FUNCTION__,__LINE__);
815 #endif
816                                 CLAW_DBF_TEXT(4,trace,"haltio");
817                                 return;
818                         }
819                         if (p_ch->flag == CLAW_READ) {
820                                 p_ch->claw_state = CLAW_START_READ;
821                                 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
822                         }
823                         else
824                            if (p_ch->flag == CLAW_WRITE) {
825                                 p_ch->claw_state = CLAW_START_WRITE;
826                                 /*      send SYSTEM_VALIDATE                    */
827                                 claw_strt_read(dev, LOCK_NO);
828                                 claw_send_control(dev,
829                                         SYSTEM_VALIDATE_REQUEST,
830                                         0, 0, 0,
831                                         p_env->host_name,
832                                         p_env->adapter_name );
833                         } else {
834                                 printk(KERN_WARNING "claw: unsolicited "
835                                         "interrupt for device:"
836                                         "%s received c-%02x d-%02x\n",
837                                         cdev->dev.bus_id,
838                                         irb->scsw.cstat,
839                                         irb->scsw.dstat);
840                                 return;
841                                 }
842 #ifdef DEBUGMSG
843                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO exit\n",
844                                 dev->name);
845 #endif
846 #ifdef FUNCTRACE
847                         printk(KERN_INFO "%s:%s Exit on line %d\n",
848                                 dev->name,__FUNCTION__,__LINE__);
849 #endif
850                         CLAW_DBF_TEXT(4,trace,"haltio");
851                         return;
852                 case CLAW_START_READ:
853                         CLAW_DBF_TEXT(4,trace,"ReadIRQ");
854                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
855                                 clear_bit(0, (void *)&p_ch->IO_active);
856                                 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
857                                     (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
858                                     (p_ch->irb->ecw[0])        == 0)
859                                 {
860                                         privptr->stats.rx_errors++;
861                                         printk(KERN_INFO "%s: Restart is "
862                                                 "required after remote "
863                                                 "side recovers \n",
864                                                 dev->name);
865                                 }
866 #ifdef FUNCTRACE
867                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
868                                         dev->name,__FUNCTION__,__LINE__);
869 #endif
870                                         CLAW_DBF_TEXT(4,trace,"notrdy");
871                                         return;
872                         }
873                         if ((p_ch->irb->scsw.cstat & SCHN_STAT_PCI) &&
874                             (p_ch->irb->scsw.dstat==0)) {
875                                 if (test_and_set_bit(CLAW_BH_ACTIVE,
876                                         (void *)&p_ch->flag_a) == 0) {
877                                         tasklet_schedule(&p_ch->tasklet);
878                                 }
879                                 else {
880                                         CLAW_DBF_TEXT(4,trace,"PCINoBH");
881                                 }
882 #ifdef FUNCTRACE
883                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
884                                         dev->name,__FUNCTION__,__LINE__);
885 #endif
886                                 CLAW_DBF_TEXT(4,trace,"PCI_read");
887                                 return;
888                         }
889                         if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
890                          (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
891                          (p_ch->irb->scsw.stctl ==
892                          (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
893 #ifdef FUNCTRACE
894                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
895                                         dev->name,__FUNCTION__,__LINE__);
896 #endif
897                                 CLAW_DBF_TEXT(4,trace,"SPend_rd");
898                                 return;
899                         }
900                         clear_bit(0, (void *)&p_ch->IO_active);
901                         claw_clearbit_busy(TB_RETRY,dev);
902                         if (test_and_set_bit(CLAW_BH_ACTIVE,
903                                 (void *)&p_ch->flag_a) == 0) {
904                                 tasklet_schedule(&p_ch->tasklet);
905                          }
906                         else {
907                                 CLAW_DBF_TEXT(4,trace,"RdBHAct");
908                         }
909
910 #ifdef DEBUGMSG
911                         printk(KERN_INFO "%s: process CLAW_START_READ exit\n",
912                                 dev->name);
913 #endif
914 #ifdef FUNCTRACE
915                         printk(KERN_INFO "%s:%s Exit on line %d\n",
916                                 dev->name,__FUNCTION__,__LINE__);
917 #endif
918                         CLAW_DBF_TEXT(4,trace,"RdIRQXit");
919                         return;
920                 case CLAW_START_WRITE:
921                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
922                                 printk(KERN_INFO "%s: Unit Check Occured in "
923                                         "write channel\n",dev->name);
924                                 clear_bit(0, (void *)&p_ch->IO_active);
925                                 if (p_ch->irb->ecw[0] & 0x80 ) {
926                                         printk(KERN_INFO "%s: Resetting Event "
927                                                 "occurred:\n",dev->name);
928                                         init_timer(&p_ch->timer);
929                                         p_ch->timer.function =
930                                                 (void *)claw_write_retry;
931                                         p_ch->timer.data = (unsigned long)p_ch;
932                                         p_ch->timer.expires = jiffies + 10*HZ;
933                                         add_timer(&p_ch->timer);
934                                         printk(KERN_INFO "%s: write connection "
935                                                 "restarting\n",dev->name);
936                                 }
937 #ifdef FUNCTRACE
938                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
939                                         dev->name,__FUNCTION__,__LINE__);
940 #endif
941                                 CLAW_DBF_TEXT(4,trace,"rstrtwrt");
942                                 return;
943                         }
944                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
945                                         clear_bit(0, (void *)&p_ch->IO_active);
946                                         printk(KERN_INFO "%s: Unit Exception "
947                                                 "Occured in write channel\n",
948                                                 dev->name);
949                         }
950                         if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
951                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
952                         (p_ch->irb->scsw.stctl ==
953                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
954 #ifdef FUNCTRACE
955                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
956                                         dev->name,__FUNCTION__,__LINE__);
957 #endif
958                                 CLAW_DBF_TEXT(4,trace,"writeUE");
959                                 return;
960                         }
961                         clear_bit(0, (void *)&p_ch->IO_active);
962                         if (claw_test_and_setbit_busy(TB_TX,dev)==0) {
963                                 claw_write_next(p_ch);
964                                 claw_clearbit_busy(TB_TX,dev);
965                                 claw_clear_busy(dev);
966                         }
967                         p_ch_r=(struct chbk *)&privptr->channel[READ];
968                         if (test_and_set_bit(CLAW_BH_ACTIVE,
969                                         (void *)&p_ch_r->flag_a) == 0) {
970                                 tasklet_schedule(&p_ch_r->tasklet);
971                         }
972
973 #ifdef DEBUGMSG
974                         printk(KERN_INFO "%s: process CLAW_START_WRITE exit\n",
975                                  dev->name);
976 #endif
977 #ifdef FUNCTRACE
978                         printk(KERN_INFO "%s:%s Exit on line %d\n",
979                                 dev->name,__FUNCTION__,__LINE__);
980 #endif
981                         CLAW_DBF_TEXT(4,trace,"StWtExit");
982                         return;
983                 default:
984                         printk(KERN_WARNING "%s: wrong selection code - irq "
985                                 "state=%d\n",dev->name,p_ch->claw_state);
986 #ifdef FUNCTRACE
987                         printk(KERN_INFO "%s:%s Exit on line %d\n",
988                                 dev->name,__FUNCTION__,__LINE__);
989 #endif
990                         CLAW_DBF_TEXT(2,trace,"badIRQ");
991                         return;
992         }
993
994 }       /*   end of claw_irq_handler    */
995
996
997 /*-------------------------------------------------------------------*
998 *       claw_irq_tasklet                                             *
999 *                                                                    *
1000 *--------------------------------------------------------------------*/
1001 static void
1002 claw_irq_tasklet ( unsigned long data )
1003 {
1004         struct chbk * p_ch;
1005         struct net_device  *dev;
1006         struct claw_privbk *       privptr;
1007
1008         p_ch = (struct chbk *) data;
1009         dev = (struct net_device *)p_ch->ndev;
1010 #ifdef FUNCTRACE
1011         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
1012 #endif
1013 #ifdef DEBUGMSG
1014         printk(KERN_INFO "%s: variable p_ch =\n",dev->name);
1015         dumpit((char *) p_ch, sizeof(struct chbk));
1016 #endif
1017         CLAW_DBF_TEXT(4,trace,"IRQtask");
1018
1019         privptr = (struct claw_privbk *) dev->priv;
1020
1021 #ifdef DEBUGMSG
1022         printk(KERN_INFO "%s: bh routine - state-%02x\n" ,
1023                 dev->name, p_ch->claw_state);
1024 #endif
1025
1026         unpack_read(dev);
1027         clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
1028         CLAW_DBF_TEXT(4,trace,"TskletXt");
1029 #ifdef FUNCTRACE
1030         printk(KERN_INFO "%s:%s Exit on line %d\n",
1031                 dev->name,__FUNCTION__,__LINE__);
1032 #endif
1033         return;
1034 }       /*    end of claw_irq_bh    */
1035
1036 /*-------------------------------------------------------------------*
1037 *       claw_release                                                 *
1038 *                                                                    *
1039 *--------------------------------------------------------------------*/
1040 static int
1041 claw_release(struct net_device *dev)
1042 {
1043         int                rc;
1044         int                i;
1045         unsigned long      saveflags;
1046         unsigned long      parm;
1047         struct claw_privbk *privptr;
1048         DECLARE_WAITQUEUE(wait, current);
1049         struct ccwbk*             p_this_ccw;
1050         struct ccwbk*             p_buf;
1051
1052         if (!dev)
1053                 return 0;
1054         privptr = (struct claw_privbk *) dev->priv;
1055         if (!privptr)
1056                 return 0;
1057 #ifdef FUNCTRACE
1058         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
1059 #endif
1060         CLAW_DBF_TEXT(4,trace,"release");
1061 #ifdef DEBUGMSG
1062         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1063         dumpit((char *) dev, sizeof(struct net_device));
1064         printk(KERN_INFO "Priv Buffalloc %d\n",privptr->buffs_alloc);
1065         printk(KERN_INFO "Priv p_buff_ccw = %p\n",&privptr->p_buff_ccw);
1066 #endif
1067         privptr->release_pend=1;
1068         claw_setbit_busy(TB_STOP,dev);
1069         for ( i = 1; i >=0 ;  i--) {
1070                 spin_lock_irqsave(
1071                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1072              /*   del_timer(&privptr->channel[READ].timer);  */
1073                 privptr->channel[i].claw_state = CLAW_STOP;
1074                 privptr->channel[i].IO_active = 0;
1075                 parm = (unsigned long) &privptr->channel[i];
1076                 if (i == WRITE)
1077                         claw_purge_skb_queue(
1078                                 &privptr->channel[WRITE].collect_queue);
1079                 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
1080                 if (privptr->system_validate_comp==0x00)  /* never opened? */
1081                    init_waitqueue_head(&privptr->channel[i].wait);
1082                 add_wait_queue(&privptr->channel[i].wait, &wait);
1083                 set_current_state(TASK_INTERRUPTIBLE);
1084                 spin_unlock_irqrestore(
1085                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1086                 schedule();
1087                 set_current_state(TASK_RUNNING);
1088                 remove_wait_queue(&privptr->channel[i].wait, &wait);
1089                 if (rc != 0) {
1090                         ccw_check_return_code(privptr->channel[i].cdev, rc);
1091                 }
1092         }
1093         if (privptr->pk_skb != NULL) {
1094                 dev_kfree_skb_any(privptr->pk_skb);
1095                 privptr->pk_skb = NULL;
1096         }
1097         if(privptr->buffs_alloc != 1) {
1098 #ifdef FUNCTRACE
1099         printk(KERN_INFO "%s:%s Exit on line %d\n",
1100                 dev->name,__FUNCTION__,__LINE__);
1101 #endif
1102                 CLAW_DBF_TEXT(4,trace,"none2fre");
1103                 return 0;
1104         }
1105         CLAW_DBF_TEXT(4,trace,"freebufs");
1106         if (privptr->p_buff_ccw != NULL) {
1107                 free_pages((unsigned long)privptr->p_buff_ccw,
1108                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
1109         }
1110         CLAW_DBF_TEXT(4,trace,"freeread");
1111         if (privptr->p_env->read_size < PAGE_SIZE) {
1112             if (privptr->p_buff_read != NULL) {
1113                 free_pages((unsigned long)privptr->p_buff_read,
1114                       (int)pages_to_order_of_mag(privptr->p_buff_read_num));
1115                 }
1116         }
1117         else {
1118                 p_buf=privptr->p_read_active_first;
1119                 while (p_buf!=NULL) {
1120                         free_pages((unsigned long)p_buf->p_buffer,
1121                              (int)pages_to_order_of_mag(
1122                                 privptr->p_buff_pages_perread ));
1123                         p_buf=p_buf->next;
1124                 }
1125         }
1126          CLAW_DBF_TEXT(4,trace,"freewrit");
1127         if (privptr->p_env->write_size < PAGE_SIZE ) {
1128                 free_pages((unsigned long)privptr->p_buff_write,
1129                       (int)pages_to_order_of_mag(privptr->p_buff_write_num));
1130         }
1131         else {
1132                 p_buf=privptr->p_write_active_first;
1133                 while (p_buf!=NULL) {
1134                         free_pages((unsigned long)p_buf->p_buffer,
1135                               (int)pages_to_order_of_mag(
1136                               privptr->p_buff_pages_perwrite ));
1137                         p_buf=p_buf->next;
1138                 }
1139         }
1140          CLAW_DBF_TEXT(4,trace,"clearptr");
1141         privptr->buffs_alloc = 0;
1142         privptr->p_buff_ccw=NULL;
1143         privptr->p_buff_read=NULL;
1144         privptr->p_buff_write=NULL;
1145         privptr->system_validate_comp=0;
1146         privptr->release_pend=0;
1147         /*      Remove any writes that were pending and reset all reads   */
1148         p_this_ccw=privptr->p_read_active_first;
1149         while (p_this_ccw!=NULL) {
1150                 p_this_ccw->header.length=0xffff;
1151                 p_this_ccw->header.opcode=0xff;
1152                 p_this_ccw->header.flag=0x00;
1153                 p_this_ccw=p_this_ccw->next;
1154         }
1155
1156         while (privptr->p_write_active_first!=NULL) {
1157                 p_this_ccw=privptr->p_write_active_first;
1158                 p_this_ccw->header.flag=CLAW_PENDING;
1159                 privptr->p_write_active_first=p_this_ccw->next;
1160                 p_this_ccw->next=privptr->p_write_free_chain;
1161                 privptr->p_write_free_chain=p_this_ccw;
1162                 ++privptr->write_free_count;
1163         }
1164         privptr->p_write_active_last=NULL;
1165         privptr->mtc_logical_link = -1;
1166         privptr->mtc_skipping = 1;
1167         privptr->mtc_offset=0;
1168
1169         if (((privptr->channel[READ].last_dstat |
1170                 privptr->channel[WRITE].last_dstat) &
1171                 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
1172                 printk(KERN_WARNING "%s: channel problems during close - "
1173                         "read: %02x -  write: %02x\n",
1174                 dev->name,
1175                 privptr->channel[READ].last_dstat,
1176                 privptr->channel[WRITE].last_dstat);
1177                  CLAW_DBF_TEXT(2,trace,"badclose");
1178         }
1179 #ifdef FUNCTRACE
1180         printk(KERN_INFO "%s:%s Exit on line %d\n",
1181                 dev->name,__FUNCTION__,__LINE__);
1182 #endif
1183         CLAW_DBF_TEXT(4,trace,"rlsexit");
1184         return 0;
1185 }      /* end of claw_release     */
1186
1187
1188
1189 /*-------------------------------------------------------------------*
1190 *       claw_write_retry                                             *
1191 *                                                                    *
1192 *--------------------------------------------------------------------*/
1193
1194 static void
1195 claw_write_retry ( struct chbk *p_ch )
1196 {
1197
1198         struct net_device  *dev=p_ch->ndev;
1199
1200
1201 #ifdef FUNCTRACE
1202         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
1203         printk(KERN_INFO "claw: variable p_ch =\n");
1204         dumpit((char *) p_ch, sizeof(struct chbk));
1205 #endif
1206         CLAW_DBF_TEXT(4,trace,"w_retry");
1207         if (p_ch->claw_state == CLAW_STOP) {
1208 #ifdef FUNCTRACE
1209                 printk(KERN_INFO "%s:%s Exit on line %d\n",
1210                         dev->name,__FUNCTION__,__LINE__);
1211 #endif
1212                 return;
1213         }
1214 #ifdef DEBUGMSG
1215         printk( KERN_INFO "%s:%s  state-%02x\n" ,
1216                 dev->name,
1217                 __FUNCTION__,
1218                 p_ch->claw_state);
1219 #endif
1220         claw_strt_out_IO( dev );
1221 #ifdef FUNCTRACE
1222         printk(KERN_INFO "%s:%s Exit on line %d\n",
1223                 dev->name,__FUNCTION__,__LINE__);
1224 #endif
1225         CLAW_DBF_TEXT(4,trace,"rtry_xit");
1226         return;
1227 }      /* end of claw_write_retry      */
1228
1229
1230 /*-------------------------------------------------------------------*
1231 *       claw_write_next                                              *
1232 *                                                                    *
1233 *--------------------------------------------------------------------*/
1234
1235 static void
1236 claw_write_next ( struct chbk * p_ch )
1237 {
1238
1239         struct net_device  *dev;
1240         struct claw_privbk *privptr=NULL;
1241         struct sk_buff *pk_skb;
1242         int     rc;
1243
1244 #ifdef FUNCTRACE
1245         printk(KERN_INFO "%s:%s Enter  \n",p_ch->ndev->name,__FUNCTION__);
1246         printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1247         dumpit((char *) p_ch, sizeof(struct chbk));
1248 #endif
1249         CLAW_DBF_TEXT(4,trace,"claw_wrt");
1250         if (p_ch->claw_state == CLAW_STOP)
1251                 return;
1252         dev = (struct net_device *) p_ch->ndev;
1253         privptr = (struct claw_privbk *) dev->priv;
1254         claw_free_wrt_buf( dev );
1255         if ((privptr->write_free_count > 0) &&
1256             !skb_queue_empty(&p_ch->collect_queue)) {
1257                 pk_skb = claw_pack_skb(privptr);
1258                 while (pk_skb != NULL) {
1259                         rc = claw_hw_tx( pk_skb, dev,1);
1260                         if (privptr->write_free_count > 0) {
1261                                 pk_skb = claw_pack_skb(privptr);
1262                         } else
1263                                 pk_skb = NULL;
1264                 }
1265         }
1266         if (privptr->p_write_active_first!=NULL) {
1267                 claw_strt_out_IO(dev);
1268         }
1269
1270 #ifdef FUNCTRACE
1271         printk(KERN_INFO "%s:%s Exit on line %d\n",
1272                 dev->name,__FUNCTION__,__LINE__);
1273 #endif
1274         return;
1275 }      /* end of claw_write_next      */
1276
1277 /*-------------------------------------------------------------------*
1278 *                                                                    *
1279 *       claw_timer                                                   *
1280 *--------------------------------------------------------------------*/
1281
1282 static void
1283 claw_timer ( struct chbk * p_ch )
1284 {
1285 #ifdef FUNCTRACE
1286         printk(KERN_INFO "%s:%s Entry\n",p_ch->ndev->name,__FUNCTION__);
1287         printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1288         dumpit((char *) p_ch, sizeof(struct chbk));
1289 #endif
1290         CLAW_DBF_TEXT(4,trace,"timer");
1291         p_ch->flag |= CLAW_TIMER;
1292         wake_up(&p_ch->wait);
1293 #ifdef FUNCTRACE
1294         printk(KERN_INFO "%s:%s Exit on line %d\n",
1295                 p_ch->ndev->name,__FUNCTION__,__LINE__);
1296 #endif
1297         return;
1298 }      /* end of claw_timer  */
1299
1300
1301 /*
1302 *
1303 *       functions
1304 */
1305
1306
1307 /*-------------------------------------------------------------------*
1308 *                                                                    *
1309 *     pages_to_order_of_mag                                          *
1310 *                                                                    *
1311 *    takes a number of pages from 1 to 512 and returns the           *
1312 *    log(num_pages)/log(2) get_free_pages() needs a base 2 order     *
1313 *    of magnitude get_free_pages() has an upper order of 9           *
1314 *--------------------------------------------------------------------*/
1315
1316 static int inline
1317 pages_to_order_of_mag(int num_of_pages)
1318 {
1319         int     order_of_mag=1;         /* assume 2 pages */
1320         int     nump=2;
1321 #ifdef FUNCTRACE
1322         printk(KERN_INFO "%s Enter pages = %d \n",__FUNCTION__,num_of_pages);
1323 #endif
1324         CLAW_DBF_TEXT_(5,trace,"pages%d",num_of_pages);
1325         if (num_of_pages == 1)   {return 0; }  /* magnitude of 0 = 1 page */
1326         /* 512 pages = 2Meg on 4k page systems */
1327         if (num_of_pages >= 512) {return 9; }
1328         /* we have two or more pages order is at least 1 */
1329         for (nump=2 ;nump <= 512;nump*=2) {
1330           if (num_of_pages <= nump)
1331                   break;
1332           order_of_mag +=1;
1333         }
1334         if (order_of_mag > 9) { order_of_mag = 9; }  /* I know it's paranoid */
1335 #ifdef FUNCTRACE
1336         printk(KERN_INFO "%s Exit on line %d, order = %d\n",
1337         __FUNCTION__,__LINE__, order_of_mag);
1338 #endif
1339         CLAW_DBF_TEXT_(5,trace,"mag%d",order_of_mag);
1340         return order_of_mag;
1341 }
1342
1343 /*-------------------------------------------------------------------*
1344 *                                                                    *
1345 *     add_claw_reads                                                 *
1346 *                                                                    *
1347 *--------------------------------------------------------------------*/
1348 static int
1349 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1350         struct ccwbk* p_last)
1351 {
1352         struct claw_privbk *privptr;
1353         struct ccw1  temp_ccw;
1354         struct endccw * p_end;
1355 #ifdef IOTRACE
1356         struct ccwbk*  p_buf;
1357 #endif
1358 #ifdef FUNCTRACE
1359         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
1360 #endif
1361 #ifdef DEBUGMSG
1362         printk(KERN_INFO "dev\n");
1363         dumpit((char *) dev, sizeof(struct net_device));
1364         printk(KERN_INFO "p_first\n");
1365         dumpit((char *) p_first, sizeof(struct ccwbk));
1366         printk(KERN_INFO "p_last\n");
1367         dumpit((char *) p_last, sizeof(struct ccwbk));
1368 #endif
1369         CLAW_DBF_TEXT(4,trace,"addreads");
1370         privptr = dev->priv;
1371         p_end = privptr->p_end_ccw;
1372
1373         /* first CCW and last CCW contains a new set of read channel programs
1374         *       to apend the running channel programs
1375         */
1376         if ( p_first==NULL) {
1377 #ifdef FUNCTRACE
1378                 printk(KERN_INFO "%s:%s Exit on line %d\n",
1379                         dev->name,__FUNCTION__,__LINE__);
1380 #endif
1381                 CLAW_DBF_TEXT(4,trace,"addexit");
1382                 return 0;
1383         }
1384
1385         /* set up ending CCW sequence for this segment */
1386         if (p_end->read1) {
1387                 p_end->read1=0x00;    /*  second ending CCW is now active */
1388                 /*      reset ending CCWs and setup TIC CCWs              */
1389                 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1390                 p_end->read2_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1391                 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1392                 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1393                 p_end->read2_nop2.cda=0;
1394                 p_end->read2_nop2.count=1;
1395         }
1396         else {
1397                 p_end->read1=0x01;  /* first ending CCW is now active */
1398                 /*      reset ending CCWs and setup TIC CCWs          */
1399                 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1400                 p_end->read1_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1401                 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1402                 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1403                 p_end->read1_nop2.cda=0;
1404                 p_end->read1_nop2.count=1;
1405         }
1406
1407         if ( privptr-> p_read_active_first ==NULL ) {
1408 #ifdef DEBUGMSG
1409                 printk(KERN_INFO "%s:%s p_read_active_frist == NULL \n",
1410                         dev->name,__FUNCTION__);
1411                 printk(KERN_INFO "%s:%s Read active first/last changed \n",
1412                         dev->name,__FUNCTION__);
1413 #endif
1414                 privptr-> p_read_active_first= p_first;  /*    set new first */
1415                 privptr-> p_read_active_last = p_last;   /*    set new last  */
1416         }
1417         else {
1418
1419 #ifdef DEBUGMSG
1420                 printk(KERN_INFO "%s:%s Read in progress \n",
1421                 dev->name,__FUNCTION__);
1422 #endif
1423                 /* set up TIC ccw  */
1424                 temp_ccw.cda= (__u32)__pa(&p_first->read);
1425                 temp_ccw.count=0;
1426                 temp_ccw.flags=0;
1427                 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1428
1429
1430                 if (p_end->read1) {
1431
1432                /* first set of CCW's is chained to the new read              */
1433                /* chain, so the second set is chained to the active chain.   */
1434                /* Therefore modify the second set to point to the new        */
1435                /* read chain set up TIC CCWs                                 */
1436                /* make sure we update the CCW so channel doesn't fetch it    */
1437                /* when it's only half done                                   */
1438                         memcpy( &p_end->read2_nop2, &temp_ccw ,
1439                                 sizeof(struct ccw1));
1440                         privptr->p_read_active_last->r_TIC_1.cda=
1441                                 (__u32)__pa(&p_first->read);
1442                         privptr->p_read_active_last->r_TIC_2.cda=
1443                                 (__u32)__pa(&p_first->read);
1444                 }
1445                 else {
1446                         /* make sure we update the CCW so channel doesn't   */
1447                         /* fetch it when it is only half done               */
1448                         memcpy( &p_end->read1_nop2, &temp_ccw ,
1449                                 sizeof(struct ccw1));
1450                         privptr->p_read_active_last->r_TIC_1.cda=
1451                                 (__u32)__pa(&p_first->read);
1452                         privptr->p_read_active_last->r_TIC_2.cda=
1453                                 (__u32)__pa(&p_first->read);
1454                 }
1455                 /*      chain in new set of blocks                              */
1456                 privptr->p_read_active_last->next = p_first;
1457                 privptr->p_read_active_last=p_last;
1458         } /* end of if ( privptr-> p_read_active_first ==NULL)  */
1459 #ifdef IOTRACE
1460         printk(KERN_INFO "%s:%s  dump p_last CCW BK \n",dev->name,__FUNCTION__);
1461         dumpit((char *)p_last, sizeof(struct ccwbk));
1462         printk(KERN_INFO "%s:%s  dump p_end CCW BK \n",dev->name,__FUNCTION__);
1463         dumpit((char *)p_end, sizeof(struct endccw));
1464
1465         printk(KERN_INFO "%s:%s dump p_first CCW BK \n",dev->name,__FUNCTION__);
1466         dumpit((char *)p_first, sizeof(struct ccwbk));
1467         printk(KERN_INFO "%s:%s Dump Active CCW chain \n",
1468                 dev->name,__FUNCTION__);
1469         p_buf=privptr->p_read_active_first;
1470         while (p_buf!=NULL) {
1471                 dumpit((char *)p_buf, sizeof(struct ccwbk));
1472                 p_buf=p_buf->next;
1473         }
1474 #endif
1475 #ifdef FUNCTRACE
1476         printk(KERN_INFO "%s:%s Exit on line %d\n",
1477                 dev->name,__FUNCTION__,__LINE__);
1478 #endif
1479         CLAW_DBF_TEXT(4,trace,"addexit");
1480         return 0;
1481 }    /*     end of add_claw_reads   */
1482
1483 /*-------------------------------------------------------------------*
1484  *   ccw_check_return_code                                           *
1485  *                                                                   *
1486  *-------------------------------------------------------------------*/
1487
1488 static void inline
1489 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1490 {
1491 #ifdef FUNCTRACE
1492         printk(KERN_INFO "%s: %s() > enter  \n",
1493                 cdev->dev.bus_id,__FUNCTION__);
1494 #endif
1495         CLAW_DBF_TEXT(4,trace,"ccwret");
1496 #ifdef DEBUGMSG
1497         printk(KERN_INFO "variable cdev =\n");
1498         dumpit((char *) cdev, sizeof(struct ccw_device));
1499         printk(KERN_INFO "variable return_code = %d\n",return_code);
1500 #endif
1501         if (return_code != 0) {
1502                 switch (return_code) {
1503                         case -EBUSY:
1504                                 printk(KERN_INFO "%s: Busy !\n",
1505                                         cdev->dev.bus_id);
1506                                 break;
1507                         case -ENODEV:
1508                                 printk(KERN_EMERG "%s: Missing device called "
1509                                         "for IO ENODEV\n", cdev->dev.bus_id);
1510                                 break;
1511                         case -EIO:
1512                                 printk(KERN_EMERG "%s: Status pending... EIO \n",
1513                                         cdev->dev.bus_id);
1514                                 break;
1515                         case -EINVAL:
1516                                 printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
1517                                         cdev->dev.bus_id);
1518                                 break;
1519                         default:
1520                                 printk(KERN_EMERG "%s: Unknown error in "
1521                                  "Do_IO %d\n",cdev->dev.bus_id, return_code);
1522                 }
1523         }
1524 #ifdef FUNCTRACE
1525         printk(KERN_INFO "%s: %s() > exit on line %d\n",
1526                 cdev->dev.bus_id,__FUNCTION__,__LINE__);
1527 #endif
1528         CLAW_DBF_TEXT(4,trace,"ccwret");
1529 }    /*    end of ccw_check_return_code   */
1530
1531 /*-------------------------------------------------------------------*
1532 *       ccw_check_unit_check                                         *
1533 *--------------------------------------------------------------------*/
1534
1535 static void inline
1536 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1537 {
1538         struct net_device *dev = p_ch->ndev;
1539
1540 #ifdef FUNCTRACE
1541         printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
1542 #endif
1543 #ifdef DEBUGMSG
1544         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1545         dumpit((char *)dev, sizeof(struct net_device));
1546         printk(KERN_INFO "%s: variable sense =\n",dev->name);
1547         dumpit((char *)&sense, 2);
1548 #endif
1549         CLAW_DBF_TEXT(4,trace,"unitchek");
1550
1551         printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
1552                 dev->name, sense);
1553
1554         if (sense & 0x40) {
1555                 if (sense & 0x01) {
1556                         printk(KERN_WARNING "%s: Interface disconnect or "
1557                                 "Selective reset "
1558                                 "occurred (remote side)\n", dev->name);
1559                 }
1560                 else {
1561                         printk(KERN_WARNING "%s: System reset occured"
1562                                 " (remote side)\n", dev->name);
1563                 }
1564         }
1565         else if (sense & 0x20) {
1566                 if (sense & 0x04) {
1567                         printk(KERN_WARNING "%s: Data-streaming "
1568                                 "timeout)\n", dev->name);
1569                 }
1570                 else  {
1571                         printk(KERN_WARNING "%s: Data-transfer parity"
1572                                 " error\n", dev->name);
1573                 }
1574         }
1575         else if (sense & 0x10) {
1576                 if (sense & 0x20) {
1577                         printk(KERN_WARNING "%s: Hardware malfunction "
1578                                 "(remote side)\n", dev->name);
1579                 }
1580                 else {
1581                         printk(KERN_WARNING "%s: read-data parity error "
1582                                 "(remote side)\n", dev->name);
1583                 }
1584         }
1585
1586 #ifdef FUNCTRACE
1587         printk(KERN_INFO "%s: %s() exit on line %d\n",
1588                 dev->name,__FUNCTION__,__LINE__);
1589 #endif
1590 }   /*    end of ccw_check_unit_check    */
1591
1592
1593
1594 /*-------------------------------------------------------------------*
1595 * Dump buffer format                                                 *
1596 *                                                                    *
1597 *--------------------------------------------------------------------*/
1598 #ifdef DEBUG
1599 static void
1600 dumpit(char* buf, int len)
1601 {
1602
1603         __u32      ct, sw, rm, dup;
1604         char       *ptr, *rptr;
1605         char       tbuf[82], tdup[82];
1606 #if (CONFIG_ARCH_S390X)
1607         char       addr[22];
1608 #else
1609         char       addr[12];
1610 #endif
1611         char       boff[12];
1612         char       bhex[82], duphex[82];
1613         char       basc[40];
1614
1615         sw  = 0;
1616         rptr =ptr=buf;
1617         rm  = 16;
1618         duphex[0]  = 0x00;
1619         dup = 0;
1620         for ( ct=0; ct < len; ct++, ptr++, rptr++ )  {
1621                 if (sw == 0) {
1622 #if (CONFIG_ARCH_S390X)
1623                         sprintf(addr, "%16.16lX",(unsigned long)rptr);
1624 #else
1625                         sprintf(addr, "%8.8X",(__u32)rptr);
1626 #endif
1627                         sprintf(boff, "%4.4X", (__u32)ct);
1628                         bhex[0] = '\0';
1629                         basc[0] = '\0';
1630                 }
1631                 if ((sw == 4) || (sw == 12)) {
1632                         strcat(bhex, " ");
1633                 }
1634                 if (sw == 8) {
1635                         strcat(bhex, "  ");
1636                 }
1637 #if (CONFIG_ARCH_S390X)
1638                 sprintf(tbuf,"%2.2lX", (unsigned long)*ptr);
1639 #else
1640                 sprintf(tbuf,"%2.2X", (__u32)*ptr);
1641 #endif
1642                 tbuf[2] = '\0';
1643                 strcat(bhex, tbuf);
1644                 if ((0!=isprint(*ptr)) && (*ptr >= 0x20)) {
1645                         basc[sw] = *ptr;
1646                 }
1647                 else {
1648                         basc[sw] = '.';
1649                 }
1650                 basc[sw+1] = '\0';
1651                 sw++;
1652                 rm--;
1653                 if (sw==16) {
1654                         if ((strcmp(duphex, bhex)) !=0) {
1655                                 if (dup !=0) {
1656                                         sprintf(tdup,"Duplicate as above to"
1657                                                 " %s", addr);
1658                                         printk( KERN_INFO "                 "
1659                                                 "   --- %s ---\n",tdup);
1660                                 }
1661                                 printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1662                                          addr, boff, bhex, basc);
1663                                 dup = 0;
1664                                 strcpy(duphex, bhex);
1665                         }
1666                         else {
1667                                 dup++;
1668                         }
1669                         sw = 0;
1670                         rm = 16;
1671                 }
1672         }  /* endfor */
1673
1674         if (sw != 0) {
1675                 for ( ; rm > 0; rm--, sw++ ) {
1676                         if ((sw==4) || (sw==12)) strcat(bhex, " ");
1677                         if (sw==8)               strcat(bhex, "  ");
1678                         strcat(bhex, "  ");
1679                         strcat(basc, " ");
1680                 }
1681                 if (dup !=0) {
1682                         sprintf(tdup,"Duplicate as above to %s", addr);
1683                         printk( KERN_INFO "                    --- %s ---\n",
1684                                 tdup);
1685                 }
1686                 printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1687                         addr, boff, bhex, basc);
1688         }
1689         else {
1690                 if (dup >=1) {
1691                         sprintf(tdup,"Duplicate as above to %s", addr);
1692                         printk( KERN_INFO "                    --- %s ---\n",
1693                                 tdup);
1694                 }
1695                 if (dup !=0) {
1696                         printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1697                                 addr, boff, bhex, basc);
1698                 }
1699         }
1700         return;
1701
1702 }   /*   end of dumpit  */
1703 #endif
1704
1705 /*-------------------------------------------------------------------*
1706 *               find_link                                            *
1707 *--------------------------------------------------------------------*/
1708 static int
1709 find_link(struct net_device *dev, char *host_name, char *ws_name )
1710 {
1711         struct claw_privbk *privptr;
1712         struct claw_env *p_env;
1713         int    rc=0;
1714
1715 #ifdef FUNCTRACE
1716         printk(KERN_INFO "%s:%s > enter  \n",dev->name,__FUNCTION__);
1717 #endif
1718         CLAW_DBF_TEXT(2,setup,"findlink");
1719 #ifdef DEBUGMSG
1720         printk(KERN_INFO "%s: variable dev = \n",dev->name);
1721         dumpit((char *) dev, sizeof(struct net_device));
1722         printk(KERN_INFO "%s: variable host_name = %s\n",dev->name, host_name);
1723         printk(KERN_INFO "%s: variable ws_name = %s\n",dev->name, ws_name);
1724 #endif
1725         privptr=dev->priv;
1726         p_env=privptr->p_env;
1727         switch (p_env->packing)
1728         {
1729                 case  PACKING_ASK:
1730                         if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1731                             (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1732                              rc = EINVAL;
1733                         break;
1734                 case  DO_PACKED:
1735                 case  PACK_SEND:
1736                         if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1737                             (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1738                                 rc = EINVAL;
1739                         break;
1740                 default:
1741                         if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1742                             (memcmp(p_env->api_type , ws_name, 8)!=0))
1743                                 rc = EINVAL;
1744                         break;
1745         }
1746
1747 #ifdef FUNCTRACE
1748         printk(KERN_INFO "%s:%s Exit on line %d\n",
1749                 dev->name,__FUNCTION__,__LINE__);
1750 #endif
1751         return 0;
1752 }    /*    end of find_link    */
1753
1754 /*-------------------------------------------------------------------*
1755  *   claw_hw_tx                                                      *
1756  *                                                                   *
1757  *                                                                   *
1758  *-------------------------------------------------------------------*/
1759
1760 static int
1761 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1762 {
1763         int                             rc=0;
1764         struct claw_privbk              *privptr;
1765         struct ccwbk           *p_this_ccw;
1766         struct ccwbk           *p_first_ccw;
1767         struct ccwbk           *p_last_ccw;
1768         __u32                           numBuffers;
1769         signed long                     len_of_data;
1770         unsigned long                   bytesInThisBuffer;
1771         unsigned char                   *pDataAddress;
1772         struct endccw                   *pEnd;
1773         struct ccw1                     tempCCW;
1774         struct chbk                     *p_ch;
1775         struct claw_env                 *p_env;
1776         int                             lock;
1777         struct clawph                   *pk_head;
1778         struct chbk                     *ch;
1779 #ifdef IOTRACE
1780         struct ccwbk                   *p_buf;
1781 #endif
1782 #ifdef FUNCTRACE
1783         printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
1784 #endif
1785         CLAW_DBF_TEXT(4,trace,"hw_tx");
1786 #ifdef DEBUGMSG
1787         printk(KERN_INFO "%s: variable dev skb =\n",dev->name);
1788         dumpit((char *) skb, sizeof(struct sk_buff));
1789         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1790         dumpit((char *) dev, sizeof(struct net_device));
1791         printk(KERN_INFO "%s: variable linkid = %ld\n",dev->name,linkid);
1792 #endif
1793         privptr = (struct claw_privbk *) (dev->priv);
1794         p_ch=(struct chbk *)&privptr->channel[WRITE];
1795         p_env =privptr->p_env;
1796 #ifdef IOTRACE
1797         printk(KERN_INFO "%s: %s() dump sk_buff  \n",dev->name,__FUNCTION__);
1798         dumpit((char *)skb ,sizeof(struct sk_buff));
1799 #endif
1800         claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1801         /*  scan the write queue to free any completed write packets   */
1802         p_first_ccw=NULL;
1803         p_last_ccw=NULL;
1804         if ((p_env->packing >= PACK_SEND) &&
1805             (skb->cb[1] != 'P')) {
1806                 skb_push(skb,sizeof(struct clawph));
1807                 pk_head=(struct clawph *)skb->data;
1808                 pk_head->len=skb->len-sizeof(struct clawph);
1809                 if (pk_head->len%4)  {
1810                         pk_head->len+= 4-(pk_head->len%4);
1811                         skb_pad(skb,4-(pk_head->len%4));
1812                         skb_put(skb,4-(pk_head->len%4));
1813                 }
1814                 if (p_env->packing == DO_PACKED)
1815                         pk_head->link_num = linkid;
1816                 else
1817                         pk_head->link_num = 0;
1818                 pk_head->flag = 0x00;
1819                 skb_pad(skb,4);
1820                 skb->cb[1] = 'P';
1821         }
1822         if (linkid == 0) {
1823                 if (claw_check_busy(dev)) {
1824                         if (privptr->write_free_count!=0) {
1825                                 claw_clear_busy(dev);
1826                         }
1827                         else {
1828                                 claw_strt_out_IO(dev );
1829                                 claw_free_wrt_buf( dev );
1830                                 if (privptr->write_free_count==0) {
1831 #ifdef IOTRACE
1832                                         printk(KERN_INFO "%s: "
1833                                            "(claw_check_busy) no free write "
1834                                            "buffers\n", dev->name);
1835 #endif
1836                                         ch = &privptr->channel[WRITE];
1837                                         atomic_inc(&skb->users);
1838                                         skb_queue_tail(&ch->collect_queue, skb);
1839                                         goto Done;
1840                                 }
1841                                 else {
1842                                         claw_clear_busy(dev);
1843                                 }
1844                         }
1845                 }
1846                 /*  tx lock  */
1847                 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1848 #ifdef DEBUGMSG
1849                         printk(KERN_INFO "%s:  busy  (claw_test_and_setbit_"
1850                                 "busy)\n", dev->name);
1851 #endif
1852                         ch = &privptr->channel[WRITE];
1853                         atomic_inc(&skb->users);
1854                         skb_queue_tail(&ch->collect_queue, skb);
1855                         claw_strt_out_IO(dev );
1856                         rc=-EBUSY;
1857                         goto Done2;
1858                 }
1859         }
1860         /*      See how many write buffers are required to hold this data */
1861         numBuffers= ( skb->len + privptr->p_env->write_size - 1) /
1862                         ( privptr->p_env->write_size);
1863
1864         /*      If that number of buffers isn't available, give up for now */
1865         if (privptr->write_free_count < numBuffers ||
1866             privptr->p_write_free_chain == NULL ) {
1867
1868                 claw_setbit_busy(TB_NOBUFFER,dev);
1869
1870 #ifdef DEBUGMSG
1871                 printk(KERN_INFO "%s:  busy  (claw_setbit_busy"
1872                         "(TB_NOBUFFER))\n", dev->name);
1873                 printk(KERN_INFO "       free_count: %d, numBuffers : %d\n",
1874                         (int)privptr->write_free_count,(int) numBuffers );
1875 #endif
1876                 ch = &privptr->channel[WRITE];
1877                 atomic_inc(&skb->users);
1878                 skb_queue_tail(&ch->collect_queue, skb);
1879                 CLAW_DBF_TEXT(2,trace,"clawbusy");
1880                 goto Done2;
1881         }
1882         pDataAddress=skb->data;
1883         len_of_data=skb->len;
1884
1885         while (len_of_data > 0) {
1886 #ifdef DEBUGMSG
1887                 printk(KERN_INFO "%s: %s() length-of-data is %ld \n",
1888                         dev->name ,__FUNCTION__,len_of_data);
1889                 dumpit((char *)pDataAddress ,64);
1890 #endif
1891                 p_this_ccw=privptr->p_write_free_chain;  /* get a block */
1892                 if (p_this_ccw == NULL) { /* lost the race */
1893                         ch = &privptr->channel[WRITE];
1894                         atomic_inc(&skb->users);
1895                         skb_queue_tail(&ch->collect_queue, skb);
1896                         goto Done2;
1897                 }
1898                 privptr->p_write_free_chain=p_this_ccw->next;
1899                 p_this_ccw->next=NULL;
1900                 --privptr->write_free_count; /* -1 */
1901                 bytesInThisBuffer=len_of_data;
1902                 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1903                 len_of_data-=bytesInThisBuffer;
1904                 pDataAddress+=(unsigned long)bytesInThisBuffer;
1905                 /*      setup write CCW         */
1906                 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1907                 if (len_of_data>0) {
1908                         p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1909                 }
1910                 p_this_ccw->write.count=bytesInThisBuffer;
1911                 /*      now add to end of this chain    */
1912                 if (p_first_ccw==NULL)    {
1913                         p_first_ccw=p_this_ccw;
1914                 }
1915                 if (p_last_ccw!=NULL) {
1916                         p_last_ccw->next=p_this_ccw;
1917                         /*      set up TIC ccws         */
1918                         p_last_ccw->w_TIC_1.cda=
1919                                 (__u32)__pa(&p_this_ccw->write);
1920                 }
1921                 p_last_ccw=p_this_ccw;      /* save new last block */
1922 #ifdef IOTRACE
1923                 printk(KERN_INFO "%s: %s() > CCW and Buffer %ld bytes long \n",
1924                         dev->name,__FUNCTION__,bytesInThisBuffer);
1925                 dumpit((char *)p_this_ccw, sizeof(struct ccwbk));
1926                 dumpit((char *)p_this_ccw->p_buffer, 64);
1927 #endif
1928         }
1929
1930         /*      FirstCCW and LastCCW now contain a new set of write channel
1931         *       programs to append to the running channel program
1932         */
1933
1934         if (p_first_ccw!=NULL) {
1935                 /*      setup ending ccw sequence for this segment              */
1936                 pEnd=privptr->p_end_ccw;
1937                 if (pEnd->write1) {
1938                         pEnd->write1=0x00;   /* second end ccw is now active */
1939                         /*      set up Tic CCWs         */
1940                         p_last_ccw->w_TIC_1.cda=
1941                                 (__u32)__pa(&pEnd->write2_nop1);
1942                         pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1943                         pEnd->write2_nop2.flags    =
1944                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1945                         pEnd->write2_nop2.cda=0;
1946                         pEnd->write2_nop2.count=1;
1947                 }
1948                 else {  /*  end of if (pEnd->write1)*/
1949                         pEnd->write1=0x01;   /* first end ccw is now active */
1950                         /*      set up Tic CCWs         */
1951                         p_last_ccw->w_TIC_1.cda=
1952                                 (__u32)__pa(&pEnd->write1_nop1);
1953                         pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1954                         pEnd->write1_nop2.flags    =
1955                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1956                         pEnd->write1_nop2.cda=0;
1957                         pEnd->write1_nop2.count=1;
1958                 }  /* end if if (pEnd->write1) */
1959
1960
1961                 if (privptr->p_write_active_first==NULL ) {
1962                         privptr->p_write_active_first=p_first_ccw;
1963                         privptr->p_write_active_last=p_last_ccw;
1964                 }
1965                 else {
1966
1967                         /*      set up Tic CCWs         */
1968
1969                         tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1970                         tempCCW.count=0;
1971                         tempCCW.flags=0;
1972                         tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1973
1974                         if (pEnd->write1) {
1975
1976                  /*
1977                  * first set of ending CCW's is chained to the new write
1978                  * chain, so the second set is chained to the active chain
1979                  * Therefore modify the second set to point the new write chain.
1980                  * make sure we update the CCW atomically
1981                  * so channel does not fetch it when it's only half done
1982                  */
1983                                 memcpy( &pEnd->write2_nop2, &tempCCW ,
1984                                         sizeof(struct ccw1));
1985                                 privptr->p_write_active_last->w_TIC_1.cda=
1986                                         (__u32)__pa(&p_first_ccw->write);
1987                         }
1988                         else {
1989
1990                         /*make sure we update the CCW atomically
1991                          *so channel does not fetch it when it's only half done
1992                          */
1993                                 memcpy(&pEnd->write1_nop2, &tempCCW ,
1994                                         sizeof(struct ccw1));
1995                                 privptr->p_write_active_last->w_TIC_1.cda=
1996                                         (__u32)__pa(&p_first_ccw->write);
1997
1998                         } /* end if if (pEnd->write1) */
1999
2000                         privptr->p_write_active_last->next=p_first_ccw;
2001                         privptr->p_write_active_last=p_last_ccw;
2002                 }
2003
2004         } /* endif (p_first_ccw!=NULL)  */
2005
2006
2007 #ifdef IOTRACE
2008         printk(KERN_INFO "%s: %s() >  Dump Active CCW chain \n",
2009                 dev->name,__FUNCTION__);
2010         p_buf=privptr->p_write_active_first;
2011         while (p_buf!=NULL) {
2012                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2013                 p_buf=p_buf->next;
2014         }
2015         p_buf=(struct ccwbk*)privptr->p_end_ccw;
2016         dumpit((char *)p_buf, sizeof(struct endccw));
2017 #endif
2018         dev_kfree_skb_any(skb);
2019         if (linkid==0) {
2020                 lock=LOCK_NO;
2021         }
2022         else  {
2023                 lock=LOCK_YES;
2024         }
2025         claw_strt_out_IO(dev );
2026         /*      if write free count is zero , set NOBUFFER       */
2027 #ifdef DEBUGMSG
2028         printk(KERN_INFO "%s: %s() > free_count is %d\n",
2029                 dev->name,__FUNCTION__,
2030                 (int) privptr->write_free_count );
2031 #endif
2032         if (privptr->write_free_count==0) {
2033                 claw_setbit_busy(TB_NOBUFFER,dev);
2034         }
2035 Done2:
2036         claw_clearbit_busy(TB_TX,dev);
2037 Done:
2038 #ifdef FUNCTRACE
2039         printk(KERN_INFO "%s: %s() > exit on line %d, rc = %d \n",
2040                 dev->name,__FUNCTION__,__LINE__, rc);
2041 #endif
2042         return(rc);
2043 }    /*    end of claw_hw_tx    */
2044
2045 /*-------------------------------------------------------------------*
2046 *                                                                    *
2047 *     init_ccw_bk                                                    *
2048 *                                                                    *
2049 *--------------------------------------------------------------------*/
2050
2051 static int
2052 init_ccw_bk(struct net_device *dev)
2053 {
2054
2055         __u32   ccw_blocks_required;
2056         __u32   ccw_blocks_perpage;
2057         __u32   ccw_pages_required;
2058         __u32   claw_reads_perpage=1;
2059         __u32   claw_read_pages;
2060         __u32   claw_writes_perpage=1;
2061         __u32   claw_write_pages;
2062         void    *p_buff=NULL;
2063         struct ccwbk*p_free_chain;
2064         struct ccwbk*p_buf;
2065         struct ccwbk*p_last_CCWB;
2066         struct ccwbk*p_first_CCWB;
2067         struct endccw *p_endccw=NULL;
2068         addr_t  real_address;
2069         struct claw_privbk *privptr=dev->priv;
2070         struct clawh *pClawH=NULL;
2071         addr_t   real_TIC_address;
2072         int i,j;
2073 #ifdef FUNCTRACE
2074         printk(KERN_INFO "%s: %s() enter  \n",dev->name,__FUNCTION__);
2075 #endif
2076         CLAW_DBF_TEXT(4,trace,"init_ccw");
2077 #ifdef DEBUGMSG
2078         printk(KERN_INFO "%s: variable dev =\n",dev->name);
2079         dumpit((char *) dev, sizeof(struct net_device));
2080 #endif
2081
2082         /*  initialize  statistics field */
2083         privptr->active_link_ID=0;
2084         /*  initialize  ccwbk pointers  */
2085         privptr->p_write_free_chain=NULL;   /* pointer to free ccw chain*/
2086         privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
2087         privptr->p_write_active_last=NULL;  /* pointer to the last write ccw*/
2088         privptr->p_read_active_first=NULL;  /* pointer to the first read ccw*/
2089         privptr->p_read_active_last=NULL;   /* pointer to the last read ccw */
2090         privptr->p_end_ccw=NULL;            /* pointer to ending ccw        */
2091         privptr->p_claw_signal_blk=NULL;    /* pointer to signal block      */
2092         privptr->buffs_alloc = 0;
2093         memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
2094         memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
2095         /*  initialize  free write ccwbk counter  */
2096         privptr->write_free_count=0;  /* number of free bufs on write chain */
2097         p_last_CCWB = NULL;
2098         p_first_CCWB= NULL;
2099         /*
2100         *  We need 1 CCW block for each read buffer, 1 for each
2101         *  write buffer, plus 1 for ClawSignalBlock
2102         */
2103         ccw_blocks_required =
2104                 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
2105 #ifdef DEBUGMSG
2106         printk(KERN_INFO "%s: %s() "
2107                 "ccw_blocks_required=%d\n",
2108                 dev->name,__FUNCTION__,
2109                 ccw_blocks_required);
2110         printk(KERN_INFO "%s: %s() "
2111                 "PAGE_SIZE=0x%x\n",
2112                 dev->name,__FUNCTION__,
2113                 (unsigned int)PAGE_SIZE);
2114         printk(KERN_INFO "%s: %s() > "
2115                 "PAGE_MASK=0x%x\n",
2116                 dev->name,__FUNCTION__,
2117                 (unsigned int)PAGE_MASK);
2118 #endif
2119         /*
2120         * compute number of CCW blocks that will fit in a page
2121         */
2122         ccw_blocks_perpage= PAGE_SIZE /  CCWBK_SIZE;
2123         ccw_pages_required=
2124                 (ccw_blocks_required+ccw_blocks_perpage -1) /
2125                          ccw_blocks_perpage;
2126
2127 #ifdef DEBUGMSG
2128         printk(KERN_INFO "%s: %s() > ccw_blocks_perpage=%d\n",
2129                 dev->name,__FUNCTION__,
2130                 ccw_blocks_perpage);
2131         printk(KERN_INFO "%s: %s() > ccw_pages_required=%d\n",
2132                 dev->name,__FUNCTION__,
2133                 ccw_pages_required);
2134 #endif
2135         /*
2136          *  read and write sizes are set by 2 constants in claw.h
2137          *  4k and 32k.  Unpacked values other than 4k are not going to
2138          * provide good performance. With packing buffers support 32k
2139          * buffers are used.
2140          */
2141         if (privptr->p_env->read_size < PAGE_SIZE) {
2142             claw_reads_perpage= PAGE_SIZE / privptr->p_env->read_size;
2143             claw_read_pages= (privptr->p_env->read_buffers +
2144                 claw_reads_perpage -1) / claw_reads_perpage;
2145          }
2146          else {       /* > or equal  */
2147             privptr->p_buff_pages_perread=
2148                 (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
2149             claw_read_pages=
2150                 privptr->p_env->read_buffers * privptr->p_buff_pages_perread;
2151          }
2152         if (privptr->p_env->write_size < PAGE_SIZE) {
2153             claw_writes_perpage=
2154                 PAGE_SIZE / privptr->p_env->write_size;
2155             claw_write_pages=
2156                 (privptr->p_env->write_buffers + claw_writes_perpage -1) /
2157                         claw_writes_perpage;
2158
2159         }
2160         else {      /* >  or equal  */
2161             privptr->p_buff_pages_perwrite=
2162                  (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
2163             claw_write_pages=
2164                 privptr->p_env->write_buffers * privptr->p_buff_pages_perwrite;
2165         }
2166 #ifdef DEBUGMSG
2167         if (privptr->p_env->read_size < PAGE_SIZE) {
2168             printk(KERN_INFO "%s: %s() reads_perpage=%d\n",
2169                 dev->name,__FUNCTION__,
2170                 claw_reads_perpage);
2171         }
2172         else {
2173             printk(KERN_INFO "%s: %s() pages_perread=%d\n",
2174                 dev->name,__FUNCTION__,
2175                 privptr->p_buff_pages_perread);
2176         }
2177         printk(KERN_INFO "%s: %s() read_pages=%d\n",
2178                 dev->name,__FUNCTION__,
2179                 claw_read_pages);
2180         if (privptr->p_env->write_size < PAGE_SIZE) {
2181             printk(KERN_INFO "%s: %s() writes_perpage=%d\n",
2182                 dev->name,__FUNCTION__,
2183                 claw_writes_perpage);
2184         }
2185         else {
2186             printk(KERN_INFO "%s: %s() pages_perwrite=%d\n",
2187                 dev->name,__FUNCTION__,
2188                 privptr->p_buff_pages_perwrite);
2189         }
2190         printk(KERN_INFO "%s: %s() write_pages=%d\n",
2191                 dev->name,__FUNCTION__,
2192                 claw_write_pages);
2193 #endif
2194
2195
2196         /*
2197         *               allocate ccw_pages_required
2198         */
2199         if (privptr->p_buff_ccw==NULL) {
2200                 privptr->p_buff_ccw=
2201                         (void *)__get_free_pages(__GFP_DMA,
2202                         (int)pages_to_order_of_mag(ccw_pages_required ));
2203                 if (privptr->p_buff_ccw==NULL) {
2204                         printk(KERN_INFO "%s: %s()  "
2205                                 "__get_free_pages for CCWs failed : "
2206                                 "pages is %d\n",
2207                                 dev->name,__FUNCTION__,
2208                                 ccw_pages_required );
2209 #ifdef FUNCTRACE
2210                         printk(KERN_INFO "%s: %s() > "
2211                                 "exit on line %d, rc = ENOMEM\n",
2212                                 dev->name,__FUNCTION__,
2213                                  __LINE__);
2214 #endif
2215                         return -ENOMEM;
2216                 }
2217                 privptr->p_buff_ccw_num=ccw_pages_required;
2218         }
2219         memset(privptr->p_buff_ccw, 0x00,
2220                 privptr->p_buff_ccw_num * PAGE_SIZE);
2221
2222         /*
2223         *               obtain ending ccw block address
2224         *
2225         */
2226         privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
2227         real_address  = (__u32)__pa(privptr->p_end_ccw);
2228         /*                              Initialize ending CCW block       */
2229 #ifdef DEBUGMSG
2230         printk(KERN_INFO "%s: %s() begin initialize ending CCW blocks\n",
2231                 dev->name,__FUNCTION__);
2232 #endif
2233
2234         p_endccw=privptr->p_end_ccw;
2235         p_endccw->real=real_address;
2236         p_endccw->write1=0x00;
2237         p_endccw->read1=0x00;
2238
2239         /*      write1_nop1                                     */
2240         p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2241         p_endccw->write1_nop1.flags       = CCW_FLAG_SLI | CCW_FLAG_CC;
2242         p_endccw->write1_nop1.count       = 1;
2243         p_endccw->write1_nop1.cda         = 0;
2244
2245         /*      write1_nop2                                     */
2246         p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2247         p_endccw->write1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2248         p_endccw->write1_nop2.count      = 1;
2249         p_endccw->write1_nop2.cda        = 0;
2250
2251         /*      write2_nop1                                     */
2252         p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2253         p_endccw->write2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2254         p_endccw->write2_nop1.count        = 1;
2255         p_endccw->write2_nop1.cda          = 0;
2256
2257         /*      write2_nop2                                     */
2258         p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2259         p_endccw->write2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2260         p_endccw->write2_nop2.count        = 1;
2261         p_endccw->write2_nop2.cda          = 0;
2262
2263         /*      read1_nop1                                      */
2264         p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2265         p_endccw->read1_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2266         p_endccw->read1_nop1.count        = 1;
2267         p_endccw->read1_nop1.cda          = 0;
2268
2269         /*      read1_nop2                                      */
2270         p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2271         p_endccw->read1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2272         p_endccw->read1_nop2.count        = 1;
2273         p_endccw->read1_nop2.cda          = 0;
2274
2275         /*      read2_nop1                                      */
2276         p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2277         p_endccw->read2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2278         p_endccw->read2_nop1.count        = 1;
2279         p_endccw->read2_nop1.cda          = 0;
2280
2281         /*      read2_nop2                                      */
2282         p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2283         p_endccw->read2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2284         p_endccw->read2_nop2.count        = 1;
2285         p_endccw->read2_nop2.cda          = 0;
2286
2287 #ifdef IOTRACE
2288         printk(KERN_INFO "%s: %s() dump claw ending CCW BK \n",
2289                 dev->name,__FUNCTION__);
2290         dumpit((char *)p_endccw, sizeof(struct endccw));
2291 #endif
2292
2293         /*
2294         *                               Build a chain of CCWs
2295         *
2296         */
2297
2298 #ifdef DEBUGMSG
2299         printk(KERN_INFO "%s: %s()  Begin build a chain of CCW buffer \n",
2300                 dev->name,__FUNCTION__);
2301 #endif
2302         p_buff=privptr->p_buff_ccw;
2303
2304         p_free_chain=NULL;
2305         for (i=0 ; i < ccw_pages_required; i++ ) {
2306                 real_address  = (__u32)__pa(p_buff);
2307                 p_buf=p_buff;
2308                 for (j=0 ; j < ccw_blocks_perpage ; j++) {
2309                         p_buf->next  = p_free_chain;
2310                         p_free_chain = p_buf;
2311                         p_buf->real=(__u32)__pa(p_buf);
2312                         ++p_buf;
2313                 }
2314                 p_buff+=PAGE_SIZE;
2315         }
2316 #ifdef DEBUGMSG
2317         printk(KERN_INFO "%s: %s() "
2318                 "End build a chain of CCW buffer \n",
2319                         dev->name,__FUNCTION__);
2320         p_buf=p_free_chain;
2321         while (p_buf!=NULL) {
2322                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2323                 p_buf=p_buf->next;
2324         }
2325 #endif
2326
2327         /*
2328         *                               Initialize ClawSignalBlock
2329         *
2330         */
2331 #ifdef DEBUGMSG
2332         printk(KERN_INFO "%s: %s() "
2333                 "Begin initialize ClawSignalBlock \n",
2334                 dev->name,__FUNCTION__);
2335 #endif
2336         if (privptr->p_claw_signal_blk==NULL) {
2337                 privptr->p_claw_signal_blk=p_free_chain;
2338                 p_free_chain=p_free_chain->next;
2339                 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
2340                 pClawH->length=0xffff;
2341                 pClawH->opcode=0xff;
2342                 pClawH->flag=CLAW_BUSY;
2343         }
2344 #ifdef DEBUGMSG
2345         printk(KERN_INFO "%s: %s() >  End initialize "
2346                 "ClawSignalBlock\n",
2347                 dev->name,__FUNCTION__);
2348         dumpit((char *)privptr->p_claw_signal_blk, sizeof(struct ccwbk));
2349 #endif
2350
2351         /*
2352         *               allocate write_pages_required and add to free chain
2353         */
2354         if (privptr->p_buff_write==NULL) {
2355             if (privptr->p_env->write_size < PAGE_SIZE) {
2356                 privptr->p_buff_write=
2357                         (void *)__get_free_pages(__GFP_DMA,
2358                         (int)pages_to_order_of_mag(claw_write_pages ));
2359                 if (privptr->p_buff_write==NULL) {
2360                         printk(KERN_INFO "%s: %s() __get_free_pages for write"
2361                                 " bufs failed : get is for %d pages\n",
2362                                 dev->name,__FUNCTION__,claw_write_pages );
2363                         free_pages((unsigned long)privptr->p_buff_ccw,
2364                            (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2365                         privptr->p_buff_ccw=NULL;
2366 #ifdef FUNCTRACE
2367                         printk(KERN_INFO "%s: %s() > exit on line %d,"
2368                                 "rc = ENOMEM\n",
2369                                 dev->name,__FUNCTION__,__LINE__);
2370 #endif
2371                         return -ENOMEM;
2372                 }
2373                 /*
2374                 *                               Build CLAW write free chain
2375                 *
2376                 */
2377
2378                 memset(privptr->p_buff_write, 0x00,
2379                         ccw_pages_required * PAGE_SIZE);
2380 #ifdef DEBUGMSG
2381                 printk(KERN_INFO "%s: %s() Begin build claw write free "
2382                         "chain \n",dev->name,__FUNCTION__);
2383 #endif
2384                 privptr->p_write_free_chain=NULL;
2385
2386                 p_buff=privptr->p_buff_write;
2387
2388                 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
2389                         p_buf        = p_free_chain;      /*  get a CCW */
2390                         p_free_chain = p_buf->next;
2391                         p_buf->next  =privptr->p_write_free_chain;
2392                         privptr->p_write_free_chain = p_buf;
2393                         p_buf-> p_buffer        = (struct clawbuf *)p_buff;
2394                         p_buf-> write.cda       = (__u32)__pa(p_buff);
2395                         p_buf-> write.flags     = CCW_FLAG_SLI | CCW_FLAG_CC;
2396                         p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2397                         p_buf-> w_read_FF.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
2398                         p_buf-> w_read_FF.count   = 1;
2399                         p_buf-> w_read_FF.cda     =
2400                                 (__u32)__pa(&p_buf-> header.flag);
2401                         p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2402                         p_buf-> w_TIC_1.flags      = 0;
2403                         p_buf-> w_TIC_1.count      = 0;
2404
2405                         if (((unsigned long)p_buff+privptr->p_env->write_size) >=
2406                            ((unsigned long)(p_buff+2*
2407                                 (privptr->p_env->write_size) -1) & PAGE_MASK)) {
2408                         p_buff= p_buff+privptr->p_env->write_size;
2409                         }
2410                 }
2411            }
2412            else      /*  Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
2413            {
2414                privptr->p_write_free_chain=NULL;
2415                for (i = 0; i< privptr->p_env->write_buffers ; i++) {
2416                    p_buff=(void *)__get_free_pages(__GFP_DMA,
2417                         (int)pages_to_order_of_mag(
2418                         privptr->p_buff_pages_perwrite) );
2419 #ifdef IOTRACE
2420                    printk(KERN_INFO "%s:%s __get_free_pages "
2421                     "for writes buf: get for %d pages\n",
2422                     dev->name,__FUNCTION__,
2423                     privptr->p_buff_pages_perwrite);
2424 #endif
2425                    if (p_buff==NULL) {
2426                         printk(KERN_INFO "%s:%s __get_free_pages"
2427                                 "for writes buf failed : get is for %d pages\n",
2428                                 dev->name,
2429                                 __FUNCTION__,
2430                                 privptr->p_buff_pages_perwrite );
2431                         free_pages((unsigned long)privptr->p_buff_ccw,
2432                               (int)pages_to_order_of_mag(
2433                                         privptr->p_buff_ccw_num));
2434                         privptr->p_buff_ccw=NULL;
2435                         p_buf=privptr->p_buff_write;
2436                         while (p_buf!=NULL) {
2437                                 free_pages((unsigned long)
2438                                         p_buf->p_buffer,
2439                                         (int)pages_to_order_of_mag(
2440                                         privptr->p_buff_pages_perwrite));
2441                                 p_buf=p_buf->next;
2442                         }
2443 #ifdef FUNCTRACE
2444                         printk(KERN_INFO "%s: %s exit on line %d, rc = ENOMEM\n",
2445                         dev->name,
2446                         __FUNCTION__,
2447                         __LINE__);
2448 #endif
2449                         return -ENOMEM;
2450                    }  /* Error on get_pages   */
2451                    memset(p_buff, 0x00, privptr->p_env->write_size );
2452                    p_buf         = p_free_chain;
2453                    p_free_chain  = p_buf->next;
2454                    p_buf->next   = privptr->p_write_free_chain;
2455                    privptr->p_write_free_chain = p_buf;
2456                    privptr->p_buff_write = p_buf;
2457                    p_buf->p_buffer=(struct clawbuf *)p_buff;
2458                    p_buf-> write.cda     = (__u32)__pa(p_buff);
2459                    p_buf-> write.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
2460                    p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2461                    p_buf-> w_read_FF.flags    = CCW_FLAG_SLI | CCW_FLAG_CC;
2462                    p_buf-> w_read_FF.count    = 1;
2463                    p_buf-> w_read_FF.cda      =
2464                         (__u32)__pa(&p_buf-> header.flag);
2465                    p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2466                    p_buf-> w_TIC_1.flags   = 0;
2467                    p_buf-> w_TIC_1.count   = 0;
2468                }  /* for all write_buffers   */
2469
2470            }    /* else buffers are PAGE_SIZE or bigger */
2471
2472         }
2473         privptr->p_buff_write_num=claw_write_pages;
2474         privptr->write_free_count=privptr->p_env->write_buffers;
2475
2476
2477 #ifdef DEBUGMSG
2478         printk(KERN_INFO "%s:%s  End build claw write free chain \n",
2479         dev->name,__FUNCTION__);
2480         p_buf=privptr->p_write_free_chain;
2481         while (p_buf!=NULL) {
2482                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2483                 p_buf=p_buf->next;
2484         }
2485 #endif
2486         /*
2487         *               allocate read_pages_required and chain to free chain
2488         */
2489         if (privptr->p_buff_read==NULL) {
2490             if (privptr->p_env->read_size < PAGE_SIZE)  {
2491                 privptr->p_buff_read=
2492                         (void *)__get_free_pages(__GFP_DMA,
2493                         (int)pages_to_order_of_mag(claw_read_pages) );
2494                 if (privptr->p_buff_read==NULL) {
2495                         printk(KERN_INFO "%s: %s() "
2496                                 "__get_free_pages for read buf failed : "
2497                                 "get is for %d pages\n",
2498                                 dev->name,__FUNCTION__,claw_read_pages );
2499                         free_pages((unsigned long)privptr->p_buff_ccw,
2500                                 (int)pages_to_order_of_mag(
2501                                         privptr->p_buff_ccw_num));
2502                         /* free the write pages size is < page size  */
2503                         free_pages((unsigned long)privptr->p_buff_write,
2504                                 (int)pages_to_order_of_mag(
2505                                 privptr->p_buff_write_num));
2506                         privptr->p_buff_ccw=NULL;
2507                         privptr->p_buff_write=NULL;
2508 #ifdef FUNCTRACE
2509                         printk(KERN_INFO "%s: %s() > exit on line %d, rc ="
2510                                 " ENOMEM\n",dev->name,__FUNCTION__,__LINE__);
2511 #endif
2512                         return -ENOMEM;
2513                 }
2514                 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
2515                 privptr->p_buff_read_num=claw_read_pages;
2516                 /*
2517                 *                               Build CLAW read free chain
2518                 *
2519                 */
2520 #ifdef DEBUGMSG
2521                 printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2522                         dev->name,__FUNCTION__);
2523 #endif
2524                 p_buff=privptr->p_buff_read;
2525                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2526                         p_buf        = p_free_chain;
2527                         p_free_chain = p_buf->next;
2528
2529                         if (p_last_CCWB==NULL) {
2530                                 p_buf->next=NULL;
2531                                 real_TIC_address=0;
2532                                 p_last_CCWB=p_buf;
2533                         }
2534                         else {
2535                                 p_buf->next=p_first_CCWB;
2536                                 real_TIC_address=
2537                                 (__u32)__pa(&p_first_CCWB -> read );
2538                         }
2539
2540                         p_first_CCWB=p_buf;
2541
2542                         p_buf->p_buffer=(struct clawbuf *)p_buff;
2543                         /*  initialize read command */
2544                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2545                         p_buf-> read.cda = (__u32)__pa(p_buff);
2546                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2547                         p_buf-> read.count       = privptr->p_env->read_size;
2548
2549                         /*  initialize read_h command */
2550                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2551                         p_buf-> read_h.cda =
2552                                 (__u32)__pa(&(p_buf->header));
2553                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2554                         p_buf-> read_h.count      = sizeof(struct clawh);
2555
2556                         /*  initialize Signal command */
2557                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2558                         p_buf-> signal.cda =
2559                                 (__u32)__pa(&(pClawH->flag));
2560                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2561                         p_buf-> signal.count     = 1;
2562
2563                         /*  initialize r_TIC_1 command */
2564                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2565                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2566                         p_buf-> r_TIC_1.flags = 0;
2567                         p_buf-> r_TIC_1.count      = 0;
2568
2569                         /*  initialize r_read_FF command */
2570                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2571                         p_buf-> r_read_FF.cda =
2572                                 (__u32)__pa(&(pClawH->flag));
2573                         p_buf-> r_read_FF.flags =
2574                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2575                         p_buf-> r_read_FF.count    = 1;
2576
2577                         /*    initialize r_TIC_2          */
2578                         memcpy(&p_buf->r_TIC_2,
2579                                 &p_buf->r_TIC_1, sizeof(struct ccw1));
2580
2581                         /*     initialize Header     */
2582                         p_buf->header.length=0xffff;
2583                         p_buf->header.opcode=0xff;
2584                         p_buf->header.flag=CLAW_PENDING;
2585
2586                         if (((unsigned long)p_buff+privptr->p_env->read_size) >=
2587                                 ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
2588                                  & PAGE_MASK) ) {
2589                                 p_buff= p_buff+privptr->p_env->read_size;
2590                         }
2591                         else {
2592                                 p_buff=
2593                                 (void *)((unsigned long)
2594                                         (p_buff+2*(privptr->p_env->read_size) -1)
2595                                          & PAGE_MASK) ;
2596                         }
2597                 }   /* for read_buffers   */
2598           }         /* read_size < PAGE_SIZE  */
2599           else {  /* read Size >= PAGE_SIZE  */
2600
2601 #ifdef DEBUGMSG
2602         printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2603                 dev->name,__FUNCTION__);
2604 #endif
2605                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2606                         p_buff = (void *)__get_free_pages(__GFP_DMA,
2607                                 (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
2608                         if (p_buff==NULL) {
2609                                 printk(KERN_INFO "%s: %s() __get_free_pages for read "
2610                                         "buf failed : get is for %d pages\n",
2611                                         dev->name,__FUNCTION__,
2612                                         privptr->p_buff_pages_perread );
2613                                 free_pages((unsigned long)privptr->p_buff_ccw,
2614                                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2615                                 /* free the write pages  */
2616                                 p_buf=privptr->p_buff_write;
2617                                 while (p_buf!=NULL) {
2618                                         free_pages((unsigned long)p_buf->p_buffer,
2619                                                 (int)pages_to_order_of_mag(
2620                                                 privptr->p_buff_pages_perwrite ));
2621                                         p_buf=p_buf->next;
2622                                 }
2623                                 /* free any read pages already alloc  */
2624                                 p_buf=privptr->p_buff_read;
2625                                 while (p_buf!=NULL) {
2626                                         free_pages((unsigned long)p_buf->p_buffer,
2627                                                 (int)pages_to_order_of_mag(
2628                                                 privptr->p_buff_pages_perread ));
2629                                         p_buf=p_buf->next;
2630                                 }
2631                                 privptr->p_buff_ccw=NULL;
2632                                 privptr->p_buff_write=NULL;
2633 #ifdef FUNCTRACE
2634                                 printk(KERN_INFO "%s: %s() exit on line %d, rc = ENOMEM\n",
2635                                         dev->name,__FUNCTION__,
2636                                         __LINE__);
2637 #endif
2638                                 return -ENOMEM;
2639                         }
2640                         memset(p_buff, 0x00, privptr->p_env->read_size);
2641                         p_buf        = p_free_chain;
2642                         privptr->p_buff_read = p_buf;
2643                         p_free_chain = p_buf->next;
2644
2645                         if (p_last_CCWB==NULL) {
2646                                 p_buf->next=NULL;
2647                                 real_TIC_address=0;
2648                                 p_last_CCWB=p_buf;
2649                         }
2650                         else {
2651                                 p_buf->next=p_first_CCWB;
2652                                 real_TIC_address=
2653                                         (addr_t)__pa(
2654                                                 &p_first_CCWB -> read );
2655                         }
2656
2657                         p_first_CCWB=p_buf;
2658                                 /* save buff address */
2659                         p_buf->p_buffer=(struct clawbuf *)p_buff;
2660                         /*  initialize read command */
2661                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2662                         p_buf-> read.cda = (__u32)__pa(p_buff);
2663                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2664                         p_buf-> read.count       = privptr->p_env->read_size;
2665
2666                         /*  initialize read_h command */
2667                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2668                         p_buf-> read_h.cda =
2669                                 (__u32)__pa(&(p_buf->header));
2670                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2671                         p_buf-> read_h.count      = sizeof(struct clawh);
2672
2673                         /*  initialize Signal command */
2674                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2675                         p_buf-> signal.cda =
2676                                 (__u32)__pa(&(pClawH->flag));
2677                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2678                         p_buf-> signal.count     = 1;
2679
2680                         /*  initialize r_TIC_1 command */
2681                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2682                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2683                         p_buf-> r_TIC_1.flags = 0;
2684                         p_buf-> r_TIC_1.count      = 0;
2685
2686                         /*  initialize r_read_FF command */
2687                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2688                         p_buf-> r_read_FF.cda =
2689                                 (__u32)__pa(&(pClawH->flag));
2690                         p_buf-> r_read_FF.flags =
2691                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2692                         p_buf-> r_read_FF.count    = 1;
2693
2694                         /*    initialize r_TIC_2          */
2695                         memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2696                                 sizeof(struct ccw1));
2697
2698                         /*     initialize Header     */
2699                         p_buf->header.length=0xffff;
2700                         p_buf->header.opcode=0xff;
2701                         p_buf->header.flag=CLAW_PENDING;
2702
2703                 }    /* For read_buffers   */
2704           }     /*  read_size >= PAGE_SIZE   */
2705         }       /*  pBuffread = NULL */
2706 #ifdef DEBUGMSG
2707         printk(KERN_INFO "%s: %s() >  End build claw read free chain \n",
2708                 dev->name,__FUNCTION__);
2709         p_buf=p_first_CCWB;
2710         while (p_buf!=NULL) {
2711                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2712                 p_buf=p_buf->next;
2713         }
2714
2715 #endif
2716         add_claw_reads( dev  ,p_first_CCWB , p_last_CCWB);
2717         privptr->buffs_alloc = 1;
2718 #ifdef FUNCTRACE
2719         printk(KERN_INFO "%s: %s() exit on line %d\n",
2720                 dev->name,__FUNCTION__,__LINE__);
2721 #endif
2722         return 0;
2723 }    /*    end of init_ccw_bk */
2724
2725 /*-------------------------------------------------------------------*
2726 *                                                                    *
2727 *       probe_error                                                  *
2728 *                                                                    *
2729 *--------------------------------------------------------------------*/
2730
2731 static void
2732 probe_error( struct ccwgroup_device *cgdev)
2733 {
2734   struct claw_privbk *privptr;
2735 #ifdef FUNCTRACE
2736         printk(KERN_INFO "%s enter  \n",__FUNCTION__);
2737 #endif
2738         CLAW_DBF_TEXT(4,trace,"proberr");
2739 #ifdef DEBUGMSG
2740         printk(KERN_INFO "%s variable cgdev =\n",__FUNCTION__);
2741         dumpit((char *) cgdev, sizeof(struct ccwgroup_device));
2742 #endif
2743         privptr=(struct claw_privbk *)cgdev->dev.driver_data;
2744         if (privptr!=NULL) {
2745                 kfree(privptr->p_env);
2746                 privptr->p_env=NULL;
2747                 kfree(privptr->p_mtc_envelope);
2748                 privptr->p_mtc_envelope=NULL;
2749                 kfree(privptr);
2750                 privptr=NULL;
2751         }
2752 #ifdef FUNCTRACE
2753         printk(KERN_INFO "%s > exit on line %d\n",
2754                  __FUNCTION__,__LINE__);
2755 #endif
2756
2757         return;
2758 }    /*    probe_error    */
2759
2760
2761
2762 /*-------------------------------------------------------------------*
2763 *    claw_process_control                                            *
2764 *                                                                    *
2765 *                                                                    *
2766 *--------------------------------------------------------------------*/
2767
2768 static int
2769 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2770 {
2771
2772         struct clawbuf *p_buf;
2773         struct clawctl  ctlbk;
2774         struct clawctl *p_ctlbk;
2775         char    temp_host_name[8];
2776         char    temp_ws_name[8];
2777         struct claw_privbk *privptr;
2778         struct claw_env *p_env;
2779         struct sysval *p_sysval;
2780         struct conncmd *p_connect=NULL;
2781         int rc;
2782         struct chbk *p_ch = NULL;
2783 #ifdef FUNCTRACE
2784         printk(KERN_INFO "%s: %s() > enter  \n",
2785                 dev->name,__FUNCTION__);
2786 #endif
2787         CLAW_DBF_TEXT(2,setup,"clw_cntl");
2788 #ifdef DEBUGMSG
2789         printk(KERN_INFO "%s: variable dev =\n",dev->name);
2790         dumpit((char *) dev, sizeof(struct net_device));
2791         printk(KERN_INFO "%s: variable p_ccw =\n",dev->name);
2792         dumpit((char *) p_ccw, sizeof(struct ccwbk *));
2793 #endif
2794         udelay(1000);  /* Wait a ms for the control packets to
2795                         *catch up to each other */
2796         privptr=dev->priv;
2797         p_env=privptr->p_env;
2798         memcpy( &temp_host_name, p_env->host_name, 8);
2799         memcpy( &temp_ws_name, p_env->adapter_name , 8);
2800         printk(KERN_INFO "%s: CLAW device %.8s: "
2801                 "Received Control Packet\n",
2802                 dev->name, temp_ws_name);
2803         if (privptr->release_pend==1) {
2804 #ifdef FUNCTRACE
2805                 printk(KERN_INFO "%s: %s() > "
2806                         "exit on line %d, rc=0\n",
2807                         dev->name,__FUNCTION__,__LINE__);
2808 #endif
2809                 return 0;
2810         }
2811         p_buf=p_ccw->p_buffer;
2812         p_ctlbk=&ctlbk;
2813         if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2814                 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2815         } else {
2816                 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2817         }
2818 #ifdef IOTRACE
2819         printk(KERN_INFO "%s: dump claw control data inbound\n",dev->name);
2820         dumpit((char *)p_ctlbk, sizeof(struct clawctl));
2821 #endif
2822         switch (p_ctlbk->command)
2823         {
2824                 case SYSTEM_VALIDATE_REQUEST:
2825                         if (p_ctlbk->version!=CLAW_VERSION_ID) {
2826                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2827                                         CLAW_RC_WRONG_VERSION );
2828                                 printk("%s: %d is wrong version id. "
2829                                         "Expected %d\n",
2830                                         dev->name, p_ctlbk->version,
2831                                         CLAW_VERSION_ID);
2832                         }
2833                         p_sysval=(struct sysval *)&(p_ctlbk->data);
2834                         printk( "%s: Recv Sys Validate Request: "
2835                                 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2836                                 "8s,Host name=%.8s\n",
2837                                 dev->name, p_ctlbk->version,
2838                                 p_ctlbk->linkid,
2839                                 p_ctlbk->correlator,
2840                                 p_sysval->WS_name,
2841                                 p_sysval->host_name);
2842                         if (0!=memcmp(temp_host_name,p_sysval->host_name,8)) {
2843                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2844                                         CLAW_RC_NAME_MISMATCH );
2845                                 CLAW_DBF_TEXT(2,setup,"HSTBAD");
2846                                 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->host_name);
2847                                 CLAW_DBF_TEXT_(2,setup,"%s",temp_host_name);
2848                                 printk(KERN_INFO "%s:  Host name mismatch\n",
2849                                         dev->name);
2850                                 printk(KERN_INFO "%s: Received :%s: "
2851                                         "expected :%s: \n",
2852                                         dev->name,
2853                                         p_sysval->host_name,
2854                                         temp_host_name);
2855                         }
2856                         if (0!=memcmp(temp_ws_name,p_sysval->WS_name,8)) {
2857                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2858                                         CLAW_RC_NAME_MISMATCH );
2859                                 CLAW_DBF_TEXT(2,setup,"WSNBAD");
2860                                 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->WS_name);
2861                                 CLAW_DBF_TEXT_(2,setup,"%s",temp_ws_name);
2862                                 printk(KERN_INFO "%s: WS name mismatch\n",
2863                                         dev->name);
2864                                  printk(KERN_INFO "%s: Received :%s: "
2865                                         "expected :%s: \n",
2866                                         dev->name,
2867                                         p_sysval->WS_name,
2868                                         temp_ws_name);
2869                         }
2870                         if (( p_sysval->write_frame_size < p_env->write_size) &&
2871                            ( p_env->packing == 0)) {
2872                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2873                                         CLAW_RC_HOST_RCV_TOO_SMALL );
2874                                 printk(KERN_INFO "%s: host write size is too "
2875                                         "small\n", dev->name);
2876                                 CLAW_DBF_TEXT(2,setup,"wrtszbad");
2877                         }
2878                         if (( p_sysval->read_frame_size < p_env->read_size) &&
2879                            ( p_env->packing == 0)) {
2880                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2881                                         CLAW_RC_HOST_RCV_TOO_SMALL );
2882                                 printk(KERN_INFO "%s: host read size is too "
2883                                         "small\n", dev->name);
2884                                 CLAW_DBF_TEXT(2,setup,"rdsizbad");
2885                         }
2886                         claw_snd_sys_validate_rsp(dev, p_ctlbk, 0 );
2887                         printk("%s: CLAW device %.8s: System validate"
2888                                 " completed.\n",dev->name, temp_ws_name);
2889                         printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev->name,
2890                                 p_sysval->read_frame_size,p_sysval->write_frame_size);
2891                         privptr->system_validate_comp=1;
2892                         if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
2893                                 p_env->packing = PACKING_ASK;
2894                         }
2895                         claw_strt_conn_req(dev);
2896                         break;
2897
2898                 case SYSTEM_VALIDATE_RESPONSE:
2899                         p_sysval=(struct sysval *)&(p_ctlbk->data);
2900                         printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2901                                 "WS name=%.8s,Host name=%.8s\n",
2902                                 dev->name,
2903                                 p_ctlbk->version,
2904                                 p_ctlbk->correlator,
2905                                 p_ctlbk->rc,
2906                                 p_sysval->WS_name,
2907                                 p_sysval->host_name);
2908                         switch (p_ctlbk->rc)
2909                         {
2910                                 case 0:
2911                                         printk(KERN_INFO "%s: CLAW device "
2912                                                 "%.8s: System validate "
2913                                                 "completed.\n",
2914                                                 dev->name, temp_ws_name);
2915                                         if (privptr->system_validate_comp == 0)
2916                                                 claw_strt_conn_req(dev);
2917                                         privptr->system_validate_comp=1;
2918                                         break;
2919                                 case CLAW_RC_NAME_MISMATCH:
2920                                         printk(KERN_INFO "%s: Sys Validate "
2921                                                 "Resp : Host, WS name is "
2922                                                 "mismatch\n",
2923                                                 dev->name);
2924                                         break;
2925                                 case CLAW_RC_WRONG_VERSION:
2926                                         printk(KERN_INFO "%s: Sys Validate "
2927                                                 "Resp : Wrong version\n",
2928                                                 dev->name);
2929                                         break;
2930                                 case CLAW_RC_HOST_RCV_TOO_SMALL:
2931                                         printk(KERN_INFO "%s: Sys Validate "
2932                                                 "Resp : bad frame size\n",
2933                                                 dev->name);
2934                                         break;
2935                                 default:
2936                                         printk(KERN_INFO "%s: Sys Validate "
2937                                                 "error code=%d \n",
2938                                                  dev->name, p_ctlbk->rc );
2939                                         break;
2940                         }
2941                         break;
2942
2943                 case CONNECTION_REQUEST:
2944                         p_connect=(struct conncmd *)&(p_ctlbk->data);
2945                         printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2946                                 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2947                                 dev->name,
2948                                 p_ctlbk->version,
2949                                 p_ctlbk->linkid,
2950                                 p_ctlbk->correlator,
2951                                 p_connect->host_name,
2952                                 p_connect->WS_name);
2953                         if (privptr->active_link_ID!=0 ) {
2954                                 claw_snd_disc(dev, p_ctlbk);
2955                                 printk(KERN_INFO "%s: Conn Req error : "
2956                                         "already logical link is active \n",
2957                                         dev->name);
2958                         }
2959                         if (p_ctlbk->linkid!=1 ) {
2960                                 claw_snd_disc(dev, p_ctlbk);
2961                                 printk(KERN_INFO "%s: Conn Req error : "
2962                                         "req logical link id is not 1\n",
2963                                         dev->name);
2964                         }
2965                         rc=find_link(dev,
2966                                 p_connect->host_name, p_connect->WS_name);
2967                         if (rc!=0) {
2968                                 claw_snd_disc(dev, p_ctlbk);
2969                                 printk(KERN_INFO "%s: Conn Req error : "
2970                                         "req appl name does not match\n",
2971                                          dev->name);
2972                         }
2973                         claw_send_control(dev,
2974                                 CONNECTION_CONFIRM, p_ctlbk->linkid,
2975                                 p_ctlbk->correlator,
2976                                 0, p_connect->host_name,
2977                                 p_connect->WS_name);
2978                         if (p_env->packing == PACKING_ASK) {
2979                                 printk("%s: Now Pack ask\n",dev->name);
2980                                 p_env->packing = PACK_SEND;
2981                                 claw_snd_conn_req(dev,0);
2982                         }
2983                         printk(KERN_INFO "%s: CLAW device %.8s: Connection "
2984                                 "completed link_id=%d.\n",
2985                                 dev->name, temp_ws_name,
2986                                 p_ctlbk->linkid);
2987                         privptr->active_link_ID=p_ctlbk->linkid;
2988                         p_ch=&privptr->channel[WRITE];
2989                         wake_up(&p_ch->wait);  /* wake up claw_open ( WRITE) */
2990                         break;
2991                 case CONNECTION_RESPONSE:
2992                         p_connect=(struct conncmd *)&(p_ctlbk->data);
2993                         printk(KERN_INFO "%s: Revc Conn Resp: Vers=%d,link_id=%d,"
2994                                 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2995                                 dev->name,
2996                                 p_ctlbk->version,
2997                                 p_ctlbk->linkid,
2998                                 p_ctlbk->correlator,
2999                                 p_ctlbk->rc,
3000                                 p_connect->host_name,
3001                                 p_connect->WS_name);
3002
3003                         if (p_ctlbk->rc !=0 ) {
3004                                 printk(KERN_INFO "%s: Conn Resp error: rc=%d \n",
3005                                         dev->name, p_ctlbk->rc);
3006                                 return 1;
3007                         }
3008                         rc=find_link(dev,
3009                                 p_connect->host_name, p_connect->WS_name);
3010                         if (rc!=0) {
3011                                 claw_snd_disc(dev, p_ctlbk);
3012                                 printk(KERN_INFO "%s: Conn Resp error: "
3013                                         "req appl name does not match\n",
3014                                          dev->name);
3015                         }
3016                         /* should be until CONNECTION_CONFIRM */
3017                         privptr->active_link_ID =  - (p_ctlbk->linkid);
3018                         break;
3019                 case CONNECTION_CONFIRM:
3020                         p_connect=(struct conncmd *)&(p_ctlbk->data);
3021                         printk(KERN_INFO "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
3022                                 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
3023                         dev->name,
3024                         p_ctlbk->version,
3025                         p_ctlbk->linkid,
3026                         p_ctlbk->correlator,
3027                         p_connect->host_name,
3028                         p_connect->WS_name);
3029                         if (p_ctlbk->linkid== -(privptr->active_link_ID)) {
3030                                 privptr->active_link_ID=p_ctlbk->linkid;
3031                                 if (p_env->packing > PACKING_ASK) {
3032                                         printk(KERN_INFO "%s: Confirmed Now packing\n",dev->name);
3033                                         p_env->packing = DO_PACKED;
3034                                         }
3035                                 p_ch=&privptr->channel[WRITE];
3036                                 wake_up(&p_ch->wait);
3037                         }
3038                         else {
3039                                 printk(KERN_INFO "%s: Conn confirm: "
3040                                         "unexpected linkid=%d \n",
3041                                         dev->name, p_ctlbk->linkid);
3042                                 claw_snd_disc(dev, p_ctlbk);
3043                         }
3044                         break;
3045                 case DISCONNECT:
3046                         printk(KERN_INFO "%s: Disconnect: "
3047                                 "Vers=%d,link_id=%d,Corr=%d\n",
3048                                 dev->name, p_ctlbk->version,
3049                                 p_ctlbk->linkid, p_ctlbk->correlator);
3050                         if ((p_ctlbk->linkid == 2) &&
3051                             (p_env->packing == PACK_SEND)) {
3052                                 privptr->active_link_ID = 1;
3053                                 p_env->packing = DO_PACKED;
3054                         }
3055                         else
3056                                 privptr->active_link_ID=0;
3057                         break;
3058                 case CLAW_ERROR:
3059                         printk(KERN_INFO "%s: CLAW ERROR detected\n",
3060                                 dev->name);
3061                         break;
3062                 default:
3063                         printk(KERN_INFO "%s:  Unexpected command code=%d \n",
3064                                 dev->name,  p_ctlbk->command);
3065                         break;
3066         }
3067
3068 #ifdef FUNCTRACE
3069         printk(KERN_INFO "%s: %s() exit on line %d, rc = 0\n",
3070                 dev->name,__FUNCTION__,__LINE__);
3071 #endif
3072
3073         return 0;
3074 }   /*    end of claw_process_control    */
3075
3076
3077 /*-------------------------------------------------------------------*
3078 *               claw_send_control                                    *
3079 *                                                                    *
3080 *--------------------------------------------------------------------*/
3081
3082 static int
3083 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
3084          __u8 correlator, __u8 rc, char *local_name, char *remote_name)
3085 {
3086         struct claw_privbk              *privptr;
3087         struct clawctl                  *p_ctl;
3088         struct sysval                   *p_sysval;
3089         struct conncmd                  *p_connect;
3090         struct sk_buff                  *skb;
3091
3092 #ifdef FUNCTRACE
3093         printk(KERN_INFO "%s:%s > enter  \n",dev->name,__FUNCTION__);
3094 #endif
3095         CLAW_DBF_TEXT(2,setup,"sndcntl");
3096 #ifdef DEBUGMSG
3097         printk(KERN_INFO "%s: Sending Control Packet \n",dev->name);
3098         printk(KERN_INFO "%s: variable type = 0x%X, link = "
3099                 "%d, correlator = %d, rc = %d\n",
3100                 dev->name,type, link, correlator, rc);
3101         printk(KERN_INFO "%s: variable local_name = %s, "
3102                 "remote_name = %s\n",dev->name, local_name, remote_name);
3103 #endif
3104         privptr=dev->priv;
3105         p_ctl=(struct clawctl *)&privptr->ctl_bk;
3106
3107         p_ctl->command=type;
3108         p_ctl->version=CLAW_VERSION_ID;
3109         p_ctl->linkid=link;
3110         p_ctl->correlator=correlator;
3111         p_ctl->rc=rc;
3112
3113         p_sysval=(struct sysval *)&p_ctl->data;
3114         p_connect=(struct conncmd *)&p_ctl->data;
3115
3116         switch (p_ctl->command) {
3117                 case SYSTEM_VALIDATE_REQUEST:
3118                 case SYSTEM_VALIDATE_RESPONSE:
3119                         memcpy(&p_sysval->host_name, local_name, 8);
3120                         memcpy(&p_sysval->WS_name, remote_name, 8);
3121                         if (privptr->p_env->packing > 0) {
3122                                 p_sysval->read_frame_size=DEF_PACK_BUFSIZE;
3123                                 p_sysval->write_frame_size=DEF_PACK_BUFSIZE;
3124                         } else {
3125                                 /* how big is the piggest group of packets */
3126                                 p_sysval->read_frame_size=privptr->p_env->read_size;
3127                                 p_sysval->write_frame_size=privptr->p_env->write_size;
3128                         }
3129                         memset(&p_sysval->reserved, 0x00, 4);
3130                         break;
3131                 case CONNECTION_REQUEST:
3132                 case CONNECTION_RESPONSE:
3133                 case CONNECTION_CONFIRM:
3134                 case DISCONNECT:
3135                         memcpy(&p_sysval->host_name, local_name, 8);
3136                         memcpy(&p_sysval->WS_name, remote_name, 8);
3137                         if (privptr->p_env->packing > 0) {
3138                         /* How big is the biggest packet */
3139                                 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
3140                                 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
3141                         } else {
3142                                 memset(&p_connect->reserved1, 0x00, 4);
3143                                 memset(&p_connect->reserved2, 0x00, 4);
3144                         }
3145                         break;
3146                 default:
3147                         break;
3148         }
3149
3150         /*      write Control Record to the device                   */
3151
3152
3153         skb = dev_alloc_skb(sizeof(struct clawctl));
3154         if (!skb) {
3155                 printk(  "%s:%s low on mem, returning...\n",
3156                         dev->name,__FUNCTION__);
3157 #ifdef DEBUG
3158                 printk(KERN_INFO "%s:%s Exit, rc = ENOMEM\n",
3159                         dev->name,__FUNCTION__);
3160 #endif
3161                 return -ENOMEM;
3162         }
3163         memcpy(skb_put(skb, sizeof(struct clawctl)),
3164                 p_ctl, sizeof(struct clawctl));
3165 #ifdef IOTRACE
3166          printk(KERN_INFO "%s: outbnd claw cntl data \n",dev->name);
3167         dumpit((char *)p_ctl,sizeof(struct clawctl));
3168 #endif
3169         if (privptr->p_env->packing >= PACK_SEND)
3170                 claw_hw_tx(skb, dev, 1);
3171         else
3172                 claw_hw_tx(skb, dev, 0);
3173 #ifdef FUNCTRACE
3174         printk(KERN_INFO "%s:%s Exit on line %d\n",
3175                 dev->name,__FUNCTION__,__LINE__);
3176 #endif
3177
3178         return 0;
3179 }  /*   end of claw_send_control  */
3180
3181 /*-------------------------------------------------------------------*
3182 *               claw_snd_conn_req                                    *
3183 *                                                                    *
3184 *--------------------------------------------------------------------*/
3185 static int
3186 claw_snd_conn_req(struct net_device *dev, __u8 link)
3187 {
3188         int                rc;
3189         struct claw_privbk *privptr=dev->priv;
3190         struct clawctl     *p_ctl;
3191
3192 #ifdef FUNCTRACE
3193         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
3194 #endif
3195         CLAW_DBF_TEXT(2,setup,"snd_conn");
3196 #ifdef  DEBUGMSG
3197         printk(KERN_INFO "%s: variable link = %X, dev =\n",dev->name, link);
3198         dumpit((char *) dev, sizeof(struct net_device));
3199 #endif
3200         rc = 1;
3201         p_ctl=(struct clawctl *)&privptr->ctl_bk;
3202         p_ctl->linkid = link;
3203         if ( privptr->system_validate_comp==0x00 ) {
3204 #ifdef FUNCTRACE
3205                 printk(KERN_INFO "%s:%s Exit on line %d, rc = 1\n",
3206                         dev->name,__FUNCTION__,__LINE__);
3207 #endif
3208                 return rc;
3209         }
3210         if (privptr->p_env->packing == PACKING_ASK )
3211                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3212                         WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
3213         if (privptr->p_env->packing == PACK_SEND)  {
3214                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3215                         WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
3216         }
3217         if (privptr->p_env->packing == 0)
3218                 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
3219                         HOST_APPL_NAME, privptr->p_env->api_type);
3220 #ifdef FUNCTRACE
3221         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3222                 dev->name,__FUNCTION__,__LINE__, rc);
3223 #endif
3224         return rc;
3225
3226 }  /*  end of claw_snd_conn_req */
3227
3228
3229 /*-------------------------------------------------------------------*
3230 *               claw_snd_disc                                        *
3231 *                                                                    *
3232 *--------------------------------------------------------------------*/
3233
3234 static int
3235 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
3236 {
3237         int rc;
3238         struct conncmd *  p_connect;
3239
3240 #ifdef FUNCTRACE
3241         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3242 #endif
3243         CLAW_DBF_TEXT(2,setup,"snd_dsc");
3244 #ifdef  DEBUGMSG
3245         printk(KERN_INFO "%s: variable dev =\n",dev->name);
3246         dumpit((char *) dev, sizeof(struct net_device));
3247         printk(KERN_INFO "%s: variable p_ctl",dev->name);
3248         dumpit((char *) p_ctl, sizeof(struct clawctl));
3249 #endif
3250         p_connect=(struct conncmd *)&p_ctl->data;
3251
3252         rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
3253                 p_ctl->correlator, 0,
3254                 p_connect->host_name, p_connect->WS_name);
3255 #ifdef FUNCTRACE
3256         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3257                 dev->name,__FUNCTION__, __LINE__, rc);
3258 #endif
3259         return rc;
3260 }     /*   end of claw_snd_disc    */
3261
3262
3263 /*-------------------------------------------------------------------*
3264 *               claw_snd_sys_validate_rsp                            *
3265 *                                                                    *
3266 *--------------------------------------------------------------------*/
3267
3268 static int
3269 claw_snd_sys_validate_rsp(struct net_device *dev,
3270         struct clawctl *p_ctl, __u32 return_code)
3271 {
3272         struct claw_env *  p_env;
3273         struct claw_privbk *privptr;
3274         int    rc;
3275
3276 #ifdef FUNCTRACE
3277         printk(KERN_INFO "%s:%s Enter\n",
3278                 dev->name,__FUNCTION__);
3279 #endif
3280         CLAW_DBF_TEXT(2,setup,"chkresp");
3281 #ifdef DEBUGMSG
3282         printk(KERN_INFO "%s: variable return_code = %d, dev =\n",
3283                 dev->name, return_code);
3284         dumpit((char *) dev, sizeof(struct net_device));
3285         printk(KERN_INFO "%s: variable p_ctl =\n",dev->name);
3286         dumpit((char *) p_ctl, sizeof(struct clawctl));
3287 #endif
3288         privptr = dev->priv;
3289         p_env=privptr->p_env;
3290         rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
3291                 p_ctl->linkid,
3292                 p_ctl->correlator,
3293                 return_code,
3294                 p_env->host_name,
3295                 p_env->adapter_name  );
3296 #ifdef FUNCTRACE
3297         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3298                 dev->name,__FUNCTION__,__LINE__, rc);
3299 #endif
3300         return rc;
3301 }     /*    end of claw_snd_sys_validate_rsp    */
3302
3303 /*-------------------------------------------------------------------*
3304 *               claw_strt_conn_req                                   *
3305 *                                                                    *
3306 *--------------------------------------------------------------------*/
3307
3308 static int
3309 claw_strt_conn_req(struct net_device *dev )
3310 {
3311         int rc;
3312
3313 #ifdef FUNCTRACE
3314         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3315 #endif
3316         CLAW_DBF_TEXT(2,setup,"conn_req");
3317 #ifdef DEBUGMSG
3318         printk(KERN_INFO "%s: variable dev =\n",dev->name);
3319         dumpit((char *) dev, sizeof(struct net_device));
3320 #endif
3321         rc=claw_snd_conn_req(dev, 1);
3322 #ifdef FUNCTRACE
3323         printk(KERN_INFO "%s:%s Exit on line %d, rc = %d\n",
3324                 dev->name,__FUNCTION__,__LINE__, rc);
3325 #endif
3326         return rc;
3327 }    /*   end of claw_strt_conn_req   */
3328
3329
3330
3331 /*-------------------------------------------------------------------*
3332  *   claw_stats                                                      *
3333  *-------------------------------------------------------------------*/
3334
3335 static struct
3336 net_device_stats *claw_stats(struct net_device *dev)
3337 {
3338         struct claw_privbk *privptr;
3339 #ifdef FUNCTRACE
3340         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3341 #endif
3342         CLAW_DBF_TEXT(4,trace,"stats");
3343         privptr = dev->priv;
3344 #ifdef FUNCTRACE
3345         printk(KERN_INFO "%s:%s Exit on line %d\n",
3346                 dev->name,__FUNCTION__,__LINE__);
3347 #endif
3348         return &privptr->stats;
3349 }     /*   end of claw_stats   */
3350
3351
3352 /*-------------------------------------------------------------------*
3353 *       unpack_read                                                  *
3354 *                                                                    *
3355 *--------------------------------------------------------------------*/
3356 static void
3357 unpack_read(struct net_device *dev )
3358 {
3359         struct sk_buff *skb;
3360         struct claw_privbk *privptr;
3361         struct claw_env    *p_env;
3362         struct ccwbk    *p_this_ccw;
3363         struct ccwbk    *p_first_ccw;
3364         struct ccwbk    *p_last_ccw;
3365         struct clawph   *p_packh;
3366         void            *p_packd;
3367         struct clawctl  *p_ctlrec=NULL;
3368
3369         __u32   len_of_data;
3370         __u32   pack_off;
3371         __u8    link_num;
3372         __u8    mtc_this_frm=0;
3373         __u32   bytes_to_mov;
3374         struct chbk *p_ch = NULL;
3375         int     i=0;
3376         int     p=0;
3377
3378 #ifdef FUNCTRACE
3379         printk(KERN_INFO "%s:%s enter  \n",dev->name,__FUNCTION__);
3380 #endif
3381         CLAW_DBF_TEXT(4,trace,"unpkread");
3382         p_first_ccw=NULL;
3383         p_last_ccw=NULL;
3384         p_packh=NULL;
3385         p_packd=NULL;
3386         privptr=dev->priv;
3387         p_env = privptr->p_env;
3388         p_this_ccw=privptr->p_read_active_first;
3389         i=0;
3390         while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
3391 #ifdef IOTRACE
3392                 printk(KERN_INFO "%s p_this_ccw \n",dev->name);
3393                 dumpit((char*)p_this_ccw, sizeof(struct ccwbk));
3394                 printk(KERN_INFO "%s Inbound p_this_ccw->p_buffer(64)"
3395                         " pk=%d \n",dev->name,p_env->packing);
3396                 dumpit((char *)p_this_ccw->p_buffer, 64 );
3397 #endif
3398                 pack_off = 0;
3399                 p = 0;
3400                 p_this_ccw->header.flag=CLAW_PENDING;
3401                 privptr->p_read_active_first=p_this_ccw->next;
3402                 p_this_ccw->next=NULL;
3403                 p_packh = (struct clawph *)p_this_ccw->p_buffer;
3404                 if ((p_env->packing == PACK_SEND) &&
3405                     (p_packh->len == 32)           &&
3406                     (p_packh->link_num == 0)) {   /* is it a packed ctl rec? */
3407                         p_packh++;  /* peek past pack header */
3408                         p_ctlrec = (struct clawctl *)p_packh;
3409                         p_packh--;  /* un peek */
3410                         if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
3411                             (p_ctlrec->command == CONNECTION_CONFIRM))
3412                                 p_env->packing = DO_PACKED;
3413                 }
3414                 if (p_env->packing == DO_PACKED)
3415                         link_num=p_packh->link_num;
3416                 else
3417                         link_num=p_this_ccw->header.opcode / 8;
3418                 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
3419 #ifdef DEBUGMSG
3420                         printk(KERN_INFO "%s: %s > More_to_come is ON\n",
3421                         dev->name,__FUNCTION__);
3422 #endif
3423                         mtc_this_frm=1;
3424                         if (p_this_ccw->header.length!=
3425                                 privptr->p_env->read_size ) {
3426                                 printk(KERN_INFO " %s: Invalid frame detected "
3427                                         "length is %02x\n" ,
3428                                         dev->name, p_this_ccw->header.length);
3429                         }
3430                 }
3431
3432                 if (privptr->mtc_skipping) {
3433                         /*
3434                         *   We're in the mode of skipping past a
3435                         *   multi-frame message
3436                         *   that we can't process for some reason or other.
3437                         *   The first frame without the More-To-Come flag is
3438                         *   the last frame of the skipped message.
3439                         */
3440                         /*  in case of More-To-Come not set in this frame */
3441                         if (mtc_this_frm==0) {
3442                                 privptr->mtc_skipping=0; /* Ok, the end */
3443                                 privptr->mtc_logical_link=-1;
3444                         }
3445 #ifdef DEBUGMSG
3446                         printk(KERN_INFO "%s:%s goto next "
3447                                 "frame from MoretoComeSkip \n",
3448                                 dev->name,__FUNCTION__);
3449 #endif
3450                         goto NextFrame;
3451                 }
3452
3453                 if (link_num==0) {
3454                         claw_process_control(dev, p_this_ccw);
3455 #ifdef DEBUGMSG
3456                         printk(KERN_INFO "%s:%s goto next "
3457                                 "frame from claw_process_control \n",
3458                                 dev->name,__FUNCTION__);
3459 #endif
3460                         CLAW_DBF_TEXT(4,trace,"UnpkCntl");
3461                         goto NextFrame;
3462                 }
3463 unpack_next:
3464                 if (p_env->packing == DO_PACKED) {
3465                         if (pack_off > p_env->read_size)
3466                                 goto NextFrame;
3467                         p_packd = p_this_ccw->p_buffer+pack_off;
3468                         p_packh = (struct clawph *) p_packd;
3469                         if ((p_packh->len == 0) || /* all done with this frame? */
3470                             (p_packh->flag != 0))
3471                                 goto NextFrame;
3472                         bytes_to_mov = p_packh->len;
3473                         pack_off += bytes_to_mov+sizeof(struct clawph);
3474                         p++;
3475                 } else {
3476                         bytes_to_mov=p_this_ccw->header.length;
3477                 }
3478                 if (privptr->mtc_logical_link<0) {
3479 #ifdef DEBUGMSG
3480                 printk(KERN_INFO "%s: %s mtc_logical_link < 0  \n",
3481                         dev->name,__FUNCTION__);
3482 #endif
3483
3484                 /*
3485                 *  if More-To-Come is set in this frame then we don't know
3486                 *  length of entire message, and hence have to allocate
3487                 *  large buffer   */
3488
3489                 /*      We are starting a new envelope  */
3490                 privptr->mtc_offset=0;
3491                         privptr->mtc_logical_link=link_num;
3492                 }
3493
3494                 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
3495                         /*      error     */
3496 #ifdef DEBUGMSG
3497                         printk(KERN_INFO "%s: %s > goto next "
3498                                 "frame from MoretoComeSkip \n",
3499                                 dev->name,
3500                                 __FUNCTION__);
3501                         printk(KERN_INFO "      bytes_to_mov %d > (MAX_ENVELOPE_"
3502                                 "SIZE-privptr->mtc_offset %d)\n",
3503                                 bytes_to_mov,(MAX_ENVELOPE_SIZE- privptr->mtc_offset));
3504 #endif
3505                         privptr->stats.rx_frame_errors++;
3506                         goto NextFrame;
3507                 }
3508                 if (p_env->packing == DO_PACKED) {
3509                         memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
3510                                 p_packd+sizeof(struct clawph), bytes_to_mov);
3511
3512                 } else  {
3513                         memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
3514                                 p_this_ccw->p_buffer, bytes_to_mov);
3515                 }
3516 #ifdef DEBUGMSG
3517                 printk(KERN_INFO "%s: %s() received data \n",
3518                         dev->name,__FUNCTION__);
3519                 if (p_env->packing == DO_PACKED)
3520                         dumpit((char *)p_packd+sizeof(struct clawph),32);
3521                 else
3522                         dumpit((char *)p_this_ccw->p_buffer, 32);
3523                 printk(KERN_INFO "%s: %s() bytelength %d \n",
3524                         dev->name,__FUNCTION__,bytes_to_mov);
3525 #endif
3526                 if (mtc_this_frm==0) {
3527                         len_of_data=privptr->mtc_offset+bytes_to_mov;
3528                         skb=dev_alloc_skb(len_of_data);
3529                         if (skb) {
3530                                 memcpy(skb_put(skb,len_of_data),
3531                                         privptr->p_mtc_envelope,
3532                                         len_of_data);
3533                                 skb->mac.raw=skb->data;
3534                                 skb->dev=dev;
3535                                 skb->protocol=htons(ETH_P_IP);
3536                                 skb->ip_summed=CHECKSUM_UNNECESSARY;
3537                                 privptr->stats.rx_packets++;
3538                                 privptr->stats.rx_bytes+=len_of_data;
3539                                 netif_rx(skb);
3540 #ifdef DEBUGMSG
3541                                 printk(KERN_INFO "%s: %s() netif_"
3542                                         "rx(skb) completed \n",
3543                                         dev->name,__FUNCTION__);
3544 #endif
3545                         }
3546                         else {
3547                                 privptr->stats.rx_dropped++;
3548                                 printk(KERN_WARNING "%s: %s() low on memory\n",
3549                                 dev->name,__FUNCTION__);
3550                         }
3551                         privptr->mtc_offset=0;
3552                         privptr->mtc_logical_link=-1;
3553                 }
3554                 else {
3555                         privptr->mtc_offset+=bytes_to_mov;
3556                 }
3557                 if (p_env->packing == DO_PACKED)
3558                         goto unpack_next;
3559 NextFrame:
3560                 /*
3561                 *   Remove ThisCCWblock from active read queue, and add it
3562                 *   to queue of free blocks to be reused.
3563                 */
3564                 i++;
3565                 p_this_ccw->header.length=0xffff;
3566                 p_this_ccw->header.opcode=0xff;
3567                 /*
3568                 *       add this one to the free queue for later reuse
3569                 */
3570                 if (p_first_ccw==NULL) {
3571                         p_first_ccw = p_this_ccw;
3572                 }
3573                 else {
3574                         p_last_ccw->next = p_this_ccw;
3575                 }
3576                 p_last_ccw = p_this_ccw;
3577                 /*
3578                 *       chain to next block on active read queue
3579                 */
3580                 p_this_ccw = privptr->p_read_active_first;
3581                 CLAW_DBF_TEXT_(4,trace,"rxpkt %d",p);
3582         } /* end of while */
3583
3584         /*      check validity                  */
3585
3586 #ifdef IOTRACE
3587         printk(KERN_INFO "%s:%s processed frame is %d \n",
3588                 dev->name,__FUNCTION__,i);
3589         printk(KERN_INFO "%s:%s  F:%lx L:%lx\n",
3590                 dev->name,
3591                 __FUNCTION__,
3592                 (unsigned long)p_first_ccw,
3593                 (unsigned long)p_last_ccw);
3594 #endif
3595         CLAW_DBF_TEXT_(4,trace,"rxfrm %d",i);
3596         add_claw_reads(dev, p_first_ccw, p_last_ccw);
3597         p_ch=&privptr->channel[READ];
3598         claw_strt_read(dev, LOCK_YES);
3599 #ifdef FUNCTRACE
3600         printk(KERN_INFO "%s: %s exit on line %d\n",
3601                 dev->name, __FUNCTION__, __LINE__);
3602 #endif
3603         return;
3604 }     /*  end of unpack_read   */
3605
3606 /*-------------------------------------------------------------------*
3607 *       claw_strt_read                                               *
3608 *                                                                    *
3609 *--------------------------------------------------------------------*/
3610 static void
3611 claw_strt_read (struct net_device *dev, int lock )
3612 {
3613         int        rc = 0;
3614         __u32      parm;
3615         unsigned long  saveflags = 0;
3616         struct claw_privbk *privptr=dev->priv;
3617         struct ccwbk*p_ccwbk;
3618         struct chbk *p_ch;
3619         struct clawh *p_clawh;
3620         p_ch=&privptr->channel[READ];
3621
3622 #ifdef FUNCTRACE
3623         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
3624         printk(KERN_INFO "%s: variable lock = %d, dev =\n",dev->name, lock);
3625         dumpit((char *) dev, sizeof(struct net_device));
3626 #endif
3627         CLAW_DBF_TEXT(4,trace,"StRdNter");
3628         p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
3629         p_clawh->flag=CLAW_IDLE;    /* 0x00 */
3630
3631         if ((privptr->p_write_active_first!=NULL &&
3632              privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
3633             (privptr->p_read_active_first!=NULL &&
3634              privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
3635                 p_clawh->flag=CLAW_BUSY;    /* 0xff */
3636         }
3637 #ifdef DEBUGMSG
3638         printk(KERN_INFO "%s:%s state-%02x\n" ,
3639                 dev->name,__FUNCTION__, p_ch->claw_state);
3640 #endif
3641         if (lock==LOCK_YES) {
3642                 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
3643         }
3644         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
3645 #ifdef DEBUGMSG
3646                 printk(KERN_INFO "%s: HOT READ started in %s\n" ,
3647                         dev->name,__FUNCTION__);
3648                 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
3649                 dumpit((char *)&p_clawh->flag , 1);
3650 #endif
3651                 CLAW_DBF_TEXT(4,trace,"HotRead");
3652                 p_ccwbk=privptr->p_read_active_first;
3653                 parm = (unsigned long) p_ch;
3654                 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
3655                                        0xff, 0);
3656                 if (rc != 0) {
3657                         ccw_check_return_code(p_ch->cdev, rc);
3658                 }
3659         }
3660         else {
3661 #ifdef DEBUGMSG
3662                 printk(KERN_INFO "%s: No READ started by %s() In progress\n" ,
3663                         dev->name,__FUNCTION__);
3664 #endif
3665                 CLAW_DBF_TEXT(2,trace,"ReadAct");
3666         }
3667
3668         if (lock==LOCK_YES) {
3669                 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
3670         }
3671 #ifdef FUNCTRACE
3672         printk(KERN_INFO "%s:%s Exit on line %d\n",
3673                 dev->name,__FUNCTION__,__LINE__);
3674 #endif
3675         CLAW_DBF_TEXT(4,trace,"StRdExit");
3676         return;
3677 }       /*    end of claw_strt_read    */
3678
3679 /*-------------------------------------------------------------------*
3680 *       claw_strt_out_IO                                             *
3681 *                                                                    *
3682 *--------------------------------------------------------------------*/
3683
3684 static void
3685 claw_strt_out_IO( struct net_device *dev )
3686 {
3687         int                     rc = 0;
3688         unsigned long           parm;
3689         struct claw_privbk      *privptr;
3690         struct chbk             *p_ch;
3691         struct ccwbk    *p_first_ccw;
3692
3693 #ifdef FUNCTRACE
3694         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3695 #endif
3696         if (!dev) {
3697                 return;
3698         }
3699         privptr=(struct claw_privbk *)dev->priv;
3700         p_ch=&privptr->channel[WRITE];
3701
3702 #ifdef DEBUGMSG
3703         printk(KERN_INFO "%s:%s state-%02x\n" ,
3704                 dev->name,__FUNCTION__,p_ch->claw_state);
3705 #endif
3706         CLAW_DBF_TEXT(4,trace,"strt_io");
3707         p_first_ccw=privptr->p_write_active_first;
3708
3709         if (p_ch->claw_state == CLAW_STOP)
3710                 return;
3711         if (p_first_ccw == NULL) {
3712 #ifdef FUNCTRACE
3713                 printk(KERN_INFO "%s:%s Exit on line %d\n",
3714                         dev->name,__FUNCTION__,__LINE__);
3715 #endif
3716                 return;
3717         }
3718         if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
3719                 parm = (unsigned long) p_ch;
3720 #ifdef DEBUGMSG
3721                 printk(KERN_INFO "%s:%s do_io \n" ,dev->name,__FUNCTION__);
3722                 dumpit((char *)p_first_ccw, sizeof(struct ccwbk));
3723 #endif
3724                 CLAW_DBF_TEXT(2,trace,"StWrtIO");
3725                 rc = ccw_device_start (p_ch->cdev,&p_first_ccw->write, parm,
3726                                        0xff, 0);
3727                 if (rc != 0) {
3728                         ccw_check_return_code(p_ch->cdev, rc);
3729                 }
3730         }
3731         dev->trans_start = jiffies;
3732 #ifdef FUNCTRACE
3733         printk(KERN_INFO "%s:%s Exit on line %d\n",
3734                 dev->name,__FUNCTION__,__LINE__);
3735 #endif
3736
3737         return;
3738 }       /*    end of claw_strt_out_IO    */
3739
3740 /*-------------------------------------------------------------------*
3741 *       Free write buffers                                           *
3742 *                                                                    *
3743 *--------------------------------------------------------------------*/
3744
3745 static void
3746 claw_free_wrt_buf( struct net_device *dev )
3747 {
3748
3749         struct claw_privbk *privptr=(struct claw_privbk *)dev->priv;
3750         struct ccwbk*p_first_ccw;
3751         struct ccwbk*p_last_ccw;
3752         struct ccwbk*p_this_ccw;
3753         struct ccwbk*p_next_ccw;
3754 #ifdef IOTRACE
3755         struct ccwbk*p_buf;
3756 #endif
3757 #ifdef FUNCTRACE
3758         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3759         printk(KERN_INFO "%s: free count = %d  variable dev =\n",
3760                 dev->name,privptr->write_free_count);
3761 #endif
3762         CLAW_DBF_TEXT(4,trace,"freewrtb");
3763         /*  scan the write queue to free any completed write packets   */
3764         p_first_ccw=NULL;
3765         p_last_ccw=NULL;
3766 #ifdef IOTRACE
3767         printk(KERN_INFO "%s:  Dump current CCW chain \n",dev->name  );
3768         p_buf=privptr->p_write_active_first;
3769         while (p_buf!=NULL) {
3770                 dumpit((char *)p_buf, sizeof(struct ccwbk));
3771                 p_buf=p_buf->next;
3772         }
3773         if (p_buf==NULL) {
3774                 printk(KERN_INFO "%s: privptr->p_write_"
3775                         "active_first==NULL\n",dev->name  );
3776         }
3777         p_buf=(struct ccwbk*)privptr->p_end_ccw;
3778         dumpit((char *)p_buf, sizeof(struct endccw));
3779 #endif
3780         p_this_ccw=privptr->p_write_active_first;
3781         while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
3782         {
3783                 p_next_ccw = p_this_ccw->next;
3784                 if (((p_next_ccw!=NULL) &&
3785                      (p_next_ccw->header.flag!=CLAW_PENDING)) ||
3786                     ((p_this_ccw == privptr->p_write_active_last) &&
3787                      (p_this_ccw->header.flag!=CLAW_PENDING))) {
3788                         /* The next CCW is OK or this is  */
3789                         /* the last CCW...free it   @A1A  */
3790                         privptr->p_write_active_first=p_this_ccw->next;
3791                         p_this_ccw->header.flag=CLAW_PENDING;
3792                         p_this_ccw->next=privptr->p_write_free_chain;
3793                         privptr->p_write_free_chain=p_this_ccw;
3794                         ++privptr->write_free_count;
3795                         privptr->stats.tx_bytes+= p_this_ccw->write.count;
3796                         p_this_ccw=privptr->p_write_active_first;
3797                         privptr->stats.tx_packets++;
3798                 }
3799                 else {
3800                         break;
3801                 }
3802         }
3803         if (privptr->write_free_count!=0) {
3804                 claw_clearbit_busy(TB_NOBUFFER,dev);
3805         }
3806         /*   whole chain removed?   */
3807         if (privptr->p_write_active_first==NULL) {
3808                 privptr->p_write_active_last=NULL;
3809 #ifdef DEBUGMSG
3810                 printk(KERN_INFO "%s:%s p_write_"
3811                         "active_first==NULL\n",dev->name,__FUNCTION__);
3812 #endif
3813         }
3814 #ifdef IOTRACE
3815         printk(KERN_INFO "%s: Dump arranged CCW chain \n",dev->name  );
3816         p_buf=privptr->p_write_active_first;
3817         while (p_buf!=NULL) {
3818                 dumpit((char *)p_buf, sizeof(struct ccwbk));
3819                 p_buf=p_buf->next;
3820         }
3821         if (p_buf==NULL) {
3822                 printk(KERN_INFO "%s: privptr->p_write_active_"
3823                         "first==NULL\n",dev->name  );
3824         }
3825         p_buf=(struct ccwbk*)privptr->p_end_ccw;
3826         dumpit((char *)p_buf, sizeof(struct endccw));
3827 #endif
3828
3829         CLAW_DBF_TEXT_(4,trace,"FWC=%d",privptr->write_free_count);
3830 #ifdef FUNCTRACE
3831         printk(KERN_INFO "%s:%s Exit on line %d free_count =%d\n",
3832                 dev->name,__FUNCTION__, __LINE__,privptr->write_free_count);
3833 #endif
3834         return;
3835 }
3836
3837 /*-------------------------------------------------------------------*
3838 *       claw free netdevice                                          *
3839 *                                                                    *
3840 *--------------------------------------------------------------------*/
3841 static void
3842 claw_free_netdevice(struct net_device * dev, int free_dev)
3843 {
3844         struct claw_privbk *privptr;
3845 #ifdef FUNCTRACE
3846         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3847 #endif
3848         CLAW_DBF_TEXT(2,setup,"free_dev");
3849
3850         if (!dev)
3851                 return;
3852         CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
3853         privptr = dev->priv;
3854         if (dev->flags & IFF_RUNNING)
3855                 claw_release(dev);
3856         if (privptr) {
3857                 privptr->channel[READ].ndev = NULL;  /* say it's free */
3858         }
3859         dev->priv=NULL;
3860 #ifdef MODULE
3861         if (free_dev) {
3862                 free_netdev(dev);
3863         }
3864 #endif
3865         CLAW_DBF_TEXT(2,setup,"feee_ok");
3866 #ifdef FUNCTRACE
3867         printk(KERN_INFO "%s:%s Exit\n",dev->name,__FUNCTION__);
3868 #endif
3869 }
3870
3871 /**
3872  * Claw init netdevice
3873  * Initialize everything of the net device except the name and the
3874  * channel structs.
3875  */
3876 static void
3877 claw_init_netdevice(struct net_device * dev)
3878 {
3879 #ifdef FUNCTRACE
3880         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
3881 #endif
3882         CLAW_DBF_TEXT(2,setup,"init_dev");
3883         CLAW_DBF_TEXT_(2,setup,"%s",dev->name);
3884         if (!dev) {
3885         printk(KERN_WARNING "claw:%s BAD Device exit line %d\n",
3886                 __FUNCTION__,__LINE__);
3887                 CLAW_DBF_TEXT(2,setup,"baddev");
3888                 return;
3889         }
3890         dev->mtu = CLAW_DEFAULT_MTU_SIZE;
3891         dev->hard_start_xmit = claw_tx;
3892         dev->open = claw_open;
3893         dev->stop = claw_release;
3894         dev->get_stats = claw_stats;
3895         dev->change_mtu = claw_change_mtu;
3896         dev->hard_header_len = 0;
3897         dev->addr_len = 0;
3898         dev->type = ARPHRD_SLIP;
3899         dev->tx_queue_len = 1300;
3900         dev->flags = IFF_POINTOPOINT | IFF_NOARP;
3901         SET_MODULE_OWNER(dev);
3902 #ifdef FUNCTRACE
3903         printk(KERN_INFO "%s:%s Exit\n",dev->name,__FUNCTION__);
3904 #endif
3905         CLAW_DBF_TEXT(2,setup,"initok");
3906         return;
3907 }
3908
3909 /**
3910  * Init a new channel in the privptr->channel[i].
3911  *
3912  * @param cdev  The ccw_device to be added.
3913  *
3914  * @return 0 on success, !0 on error.
3915  */
3916 static int
3917 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
3918 {
3919         struct chbk *p_ch;
3920
3921 #ifdef FUNCTRACE
3922         printk(KERN_INFO "%s:%s Enter\n",cdev->dev.bus_id,__FUNCTION__);
3923 #endif
3924         CLAW_DBF_TEXT_(2,setup,"%s",cdev->dev.bus_id);
3925         privptr->channel[i].flag  = i+1;   /* Read is 1 Write is 2 */
3926         p_ch = &privptr->channel[i];
3927         p_ch->cdev = cdev;
3928         snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", cdev->dev.bus_id);
3929         sscanf(cdev->dev.bus_id+4,"%x",&p_ch->devno);
3930         if ((p_ch->irb = kmalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
3931                 printk(KERN_WARNING "%s Out of memory in %s for irb\n",
3932                         p_ch->id,__FUNCTION__);
3933 #ifdef FUNCTRACE
3934                 printk(KERN_INFO "%s:%s Exit on line %d\n",
3935                         p_ch->id,__FUNCTION__,__LINE__);
3936 #endif
3937                 return -ENOMEM;
3938         }
3939         memset(p_ch->irb, 0, sizeof (struct irb));
3940 #ifdef FUNCTRACE
3941                 printk(KERN_INFO "%s:%s Exit on line %d\n",
3942                         cdev->dev.bus_id,__FUNCTION__,__LINE__);
3943 #endif
3944         return 0;
3945 }
3946
3947
3948 /**
3949  *
3950  * Setup an interface.
3951  *
3952  * @param cgdev  Device to be setup.
3953  *
3954  * @returns 0 on success, !0 on failure.
3955  */
3956 static int
3957 claw_new_device(struct ccwgroup_device *cgdev)
3958 {
3959         struct claw_privbk *privptr;
3960         struct claw_env *p_env;
3961         struct net_device *dev;
3962         int ret;
3963
3964         pr_debug("%s() called\n", __FUNCTION__);
3965         printk(KERN_INFO "claw: add for %s\n",cgdev->cdev[READ]->dev.bus_id);
3966         CLAW_DBF_TEXT(2,setup,"new_dev");
3967         privptr = cgdev->dev.driver_data;
3968         cgdev->cdev[READ]->dev.driver_data = privptr;
3969         cgdev->cdev[WRITE]->dev.driver_data = privptr;
3970         if (!privptr)
3971                 return -ENODEV;
3972         p_env = privptr->p_env;
3973         sscanf(cgdev->cdev[READ]->dev.bus_id+4,"%x",
3974                 &p_env->devno[READ]);
3975         sscanf(cgdev->cdev[WRITE]->dev.bus_id+4,"%x",
3976                 &p_env->devno[WRITE]);
3977         ret = add_channel(cgdev->cdev[0],0,privptr);
3978         if (ret == 0)
3979                 ret = add_channel(cgdev->cdev[1],1,privptr);
3980         if (ret != 0) {
3981                         printk(KERN_WARNING
3982                         "add channel failed "
3983                                 "with ret = %d\n", ret);
3984                         goto out;
3985         }
3986         ret = ccw_device_set_online(cgdev->cdev[READ]);
3987         if (ret != 0) {
3988                 printk(KERN_WARNING
3989                  "claw: ccw_device_set_online %s READ failed "
3990                         "with ret = %d\n",cgdev->cdev[READ]->dev.bus_id,ret);
3991                 goto out;
3992         }
3993         ret = ccw_device_set_online(cgdev->cdev[WRITE]);
3994         if (ret != 0) {
3995                 printk(KERN_WARNING
3996                  "claw: ccw_device_set_online %s WRITE failed "
3997                         "with ret = %d\n",cgdev->cdev[WRITE]->dev.bus_id, ret);
3998                 goto out;
3999         }
4000         dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
4001         if (!dev) {
4002                 printk(KERN_WARNING "%s:alloc_netdev failed\n",__FUNCTION__);
4003                 goto out;
4004         }
4005         dev->priv = privptr;
4006         cgdev->dev.driver_data = privptr;
4007         cgdev->cdev[READ]->dev.driver_data = privptr;
4008         cgdev->cdev[WRITE]->dev.driver_data = privptr;
4009         /* sysfs magic */
4010         SET_NETDEV_DEV(dev, &cgdev->dev);
4011         if (register_netdev(dev) != 0) {
4012                 claw_free_netdevice(dev, 1);
4013                 CLAW_DBF_TEXT(2,trace,"regfail");
4014                 goto out;
4015         }
4016         dev->flags &=~IFF_RUNNING;
4017         if (privptr->buffs_alloc == 0) {
4018                 ret=init_ccw_bk(dev);
4019                 if (ret !=0) {
4020                         printk(KERN_WARNING
4021                          "claw: init_ccw_bk failed with ret=%d\n", ret);
4022                         unregister_netdev(dev);
4023                         claw_free_netdevice(dev,1);
4024                         CLAW_DBF_TEXT(2,trace,"ccwmem");
4025                         goto out;
4026                 }
4027         }
4028         privptr->channel[READ].ndev = dev;
4029         privptr->channel[WRITE].ndev = dev;
4030         privptr->p_env->ndev = dev;
4031
4032         printk(KERN_INFO "%s:readsize=%d  writesize=%d "
4033                 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
4034                 dev->name, p_env->read_size,
4035                 p_env->write_size, p_env->read_buffers,
4036                 p_env->write_buffers, p_env->devno[READ],
4037                 p_env->devno[WRITE]);
4038         printk(KERN_INFO "%s:host_name:%.8s, adapter_name "
4039                 ":%.8s api_type: %.8s\n",
4040                 dev->name, p_env->host_name,
4041                 p_env->adapter_name , p_env->api_type);
4042         return 0;
4043 out:
4044         ccw_device_set_offline(cgdev->cdev[1]);
4045         ccw_device_set_offline(cgdev->cdev[0]);
4046
4047         return -ENODEV;
4048 }
4049
4050 static void
4051 claw_purge_skb_queue(struct sk_buff_head *q)
4052 {
4053         struct sk_buff *skb;
4054
4055         CLAW_DBF_TEXT(4,trace,"purgque");
4056
4057         while ((skb = skb_dequeue(q))) {
4058                 atomic_dec(&skb->users);
4059                 dev_kfree_skb_any(skb);
4060         }
4061 }
4062
4063 /**
4064  * Shutdown an interface.
4065  *
4066  * @param cgdev  Device to be shut down.
4067  *
4068  * @returns 0 on success, !0 on failure.
4069  */
4070 static int
4071 claw_shutdown_device(struct ccwgroup_device *cgdev)
4072 {
4073         struct claw_privbk *priv;
4074         struct net_device *ndev;
4075         int     ret;
4076
4077         pr_debug("%s() called\n", __FUNCTION__);
4078         CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
4079         priv = cgdev->dev.driver_data;
4080         if (!priv)
4081                 return -ENODEV;
4082         ndev = priv->channel[READ].ndev;
4083         if (ndev) {
4084                 /* Close the device */
4085                 printk(KERN_INFO
4086                         "%s: shuting down \n",ndev->name);
4087                 if (ndev->flags & IFF_RUNNING)
4088                         ret = claw_release(ndev);
4089                 ndev->flags &=~IFF_RUNNING;
4090                 unregister_netdev(ndev);
4091                 ndev->priv = NULL;  /* cgdev data, not ndev's to free */
4092                 claw_free_netdevice(ndev, 1);
4093                 priv->channel[READ].ndev = NULL;
4094                 priv->channel[WRITE].ndev = NULL;
4095                 priv->p_env->ndev = NULL;
4096         }
4097         ccw_device_set_offline(cgdev->cdev[1]);
4098         ccw_device_set_offline(cgdev->cdev[0]);
4099         return 0;
4100 }
4101
4102 static void
4103 claw_remove_device(struct ccwgroup_device *cgdev)
4104 {
4105         struct claw_privbk *priv;
4106
4107         pr_debug("%s() called\n", __FUNCTION__);
4108         CLAW_DBF_TEXT_(2,setup,"%s",cgdev->dev.bus_id);
4109         priv = cgdev->dev.driver_data;
4110         if (!priv) {
4111                 printk(KERN_WARNING "claw: %s() no Priv exiting\n",__FUNCTION__);
4112                 return;
4113         }
4114         printk(KERN_INFO "claw: %s() called %s will be removed.\n",
4115                         __FUNCTION__,cgdev->cdev[0]->dev.bus_id);
4116         if (cgdev->state == CCWGROUP_ONLINE)
4117                 claw_shutdown_device(cgdev);
4118         claw_remove_files(&cgdev->dev);
4119         kfree(priv->p_mtc_envelope);
4120         priv->p_mtc_envelope=NULL;
4121         kfree(priv->p_env);
4122         priv->p_env=NULL;
4123         kfree(priv->channel[0].irb);
4124         priv->channel[0].irb=NULL;
4125         kfree(priv->channel[1].irb);
4126         priv->channel[1].irb=NULL;
4127         kfree(priv);
4128         cgdev->dev.driver_data=NULL;
4129         cgdev->cdev[READ]->dev.driver_data = NULL;
4130         cgdev->cdev[WRITE]->dev.driver_data = NULL;
4131         put_device(&cgdev->dev);
4132 }
4133
4134
4135 /*
4136  * sysfs attributes
4137  */
4138 static ssize_t
4139 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
4140 {
4141         struct claw_privbk *priv;
4142         struct claw_env *  p_env;
4143
4144         priv = dev->driver_data;
4145         if (!priv)
4146                 return -ENODEV;
4147         p_env = priv->p_env;
4148         return sprintf(buf, "%s\n",p_env->host_name);
4149 }
4150
4151 static ssize_t
4152 claw_hname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4153 {
4154         struct claw_privbk *priv;
4155         struct claw_env *  p_env;
4156
4157         priv = dev->driver_data;
4158         if (!priv)
4159                 return -ENODEV;
4160         p_env = priv->p_env;
4161         if (count > MAX_NAME_LEN+1)
4162                 return -EINVAL;
4163         memset(p_env->host_name, 0x20, MAX_NAME_LEN);
4164         strncpy(p_env->host_name,buf, count);
4165         p_env->host_name[count-1] = 0x20;  /* clear extra 0x0a */
4166         p_env->host_name[MAX_NAME_LEN] = 0x00;
4167         CLAW_DBF_TEXT(2,setup,"HstnSet");
4168         CLAW_DBF_TEXT_(2,setup,"%s",p_env->host_name);
4169
4170         return count;
4171 }
4172
4173 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
4174
4175 static ssize_t
4176 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
4177 {
4178         struct claw_privbk *priv;
4179         struct claw_env *  p_env;
4180
4181         priv = dev->driver_data;
4182         if (!priv)
4183                 return -ENODEV;
4184         p_env = priv->p_env;
4185         return sprintf(buf, "%s\n",p_env->adapter_name);
4186 }
4187
4188 static ssize_t
4189 claw_adname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4190 {
4191         struct claw_privbk *priv;
4192         struct claw_env *  p_env;
4193
4194         priv = dev->driver_data;
4195         if (!priv)
4196                 return -ENODEV;
4197         p_env = priv->p_env;
4198         if (count > MAX_NAME_LEN+1)
4199                 return -EINVAL;
4200         memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
4201         strncpy(p_env->adapter_name,buf, count);
4202         p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
4203         p_env->adapter_name[MAX_NAME_LEN] = 0x00;
4204         CLAW_DBF_TEXT(2,setup,"AdnSet");
4205         CLAW_DBF_TEXT_(2,setup,"%s",p_env->adapter_name);
4206
4207         return count;
4208 }
4209
4210 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
4211
4212 static ssize_t
4213 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
4214 {
4215         struct claw_privbk *priv;
4216         struct claw_env *  p_env;
4217
4218         priv = dev->driver_data;
4219         if (!priv)
4220                 return -ENODEV;
4221         p_env = priv->p_env;
4222         return sprintf(buf, "%s\n",
4223                        p_env->api_type);
4224 }
4225
4226 static ssize_t
4227 claw_apname_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4228 {
4229         struct claw_privbk *priv;
4230         struct claw_env *  p_env;
4231
4232         priv = dev->driver_data;
4233         if (!priv)
4234                 return -ENODEV;
4235         p_env = priv->p_env;
4236         if (count > MAX_NAME_LEN+1)
4237                 return -EINVAL;
4238         memset(p_env->api_type, 0x20, MAX_NAME_LEN);
4239         strncpy(p_env->api_type,buf, count);
4240         p_env->api_type[count-1] = 0x20;  /* we get a loose 0x0a */
4241         p_env->api_type[MAX_NAME_LEN] = 0x00;
4242         if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
4243                 p_env->read_size=DEF_PACK_BUFSIZE;
4244                 p_env->write_size=DEF_PACK_BUFSIZE;
4245                 p_env->packing=PACKING_ASK;
4246                 CLAW_DBF_TEXT(2,setup,"PACKING");
4247         }
4248         else {
4249                 p_env->packing=0;
4250                 p_env->read_size=CLAW_FRAME_SIZE;
4251                 p_env->write_size=CLAW_FRAME_SIZE;
4252                 CLAW_DBF_TEXT(2,setup,"ApiSet");
4253         }
4254         CLAW_DBF_TEXT_(2,setup,"%s",p_env->api_type);
4255         return count;
4256 }
4257
4258 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
4259
4260 static ssize_t
4261 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
4262 {
4263         struct claw_privbk *priv;
4264         struct claw_env * p_env;
4265
4266         priv = dev->driver_data;
4267         if (!priv)
4268                 return -ENODEV;
4269         p_env = priv->p_env;
4270         return sprintf(buf, "%d\n", p_env->write_buffers);
4271 }
4272
4273 static ssize_t
4274 claw_wbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4275 {
4276         struct claw_privbk *priv;
4277         struct claw_env *  p_env;
4278         int nnn,max;
4279
4280         priv = dev->driver_data;
4281         if (!priv)
4282                 return -ENODEV;
4283         p_env = priv->p_env;
4284         sscanf(buf, "%i", &nnn);
4285         if (p_env->packing) {
4286                 max = 64;
4287         }
4288         else {
4289                 max = 512;
4290         }
4291         if ((nnn > max ) || (nnn < 2))
4292                 return -EINVAL;
4293         p_env->write_buffers = nnn;
4294         CLAW_DBF_TEXT(2,setup,"Wbufset");
4295         CLAW_DBF_TEXT_(2,setup,"WB=%d",p_env->write_buffers);
4296         return count;
4297 }
4298
4299 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
4300
4301 static ssize_t
4302 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
4303 {
4304         struct claw_privbk *priv;
4305         struct claw_env *  p_env;
4306
4307         priv = dev->driver_data;
4308         if (!priv)
4309                 return -ENODEV;
4310         p_env = priv->p_env;
4311         return sprintf(buf, "%d\n", p_env->read_buffers);
4312 }
4313
4314 static ssize_t
4315 claw_rbuff_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
4316 {
4317         struct claw_privbk *priv;
4318         struct claw_env *p_env;
4319         int nnn,max;
4320
4321         priv = dev->driver_data;
4322         if (!priv)
4323                 return -ENODEV;
4324         p_env = priv->p_env;
4325         sscanf(buf, "%i", &nnn);
4326         if (p_env->packing) {
4327                 max = 64;
4328         }
4329         else {
4330                 max = 512;
4331         }
4332         if ((nnn > max ) || (nnn < 2))
4333                 return -EINVAL;
4334         p_env->read_buffers = nnn;
4335         CLAW_DBF_TEXT(2,setup,"Rbufset");
4336         CLAW_DBF_TEXT_(2,setup,"RB=%d",p_env->read_buffers);
4337         return count;
4338 }
4339
4340 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
4341
4342 static struct attribute *claw_attr[] = {
4343         &dev_attr_read_buffer.attr,
4344         &dev_attr_write_buffer.attr,
4345         &dev_attr_adapter_name.attr,
4346         &dev_attr_api_type.attr,
4347         &dev_attr_host_name.attr,
4348         NULL,
4349 };
4350
4351 static struct attribute_group claw_attr_group = {
4352         .attrs = claw_attr,
4353 };
4354
4355 static int
4356 claw_add_files(struct device *dev)
4357 {
4358         pr_debug("%s() called\n", __FUNCTION__);
4359         CLAW_DBF_TEXT(2,setup,"add_file");
4360         return sysfs_create_group(&dev->kobj, &claw_attr_group);
4361 }
4362
4363 static void
4364 claw_remove_files(struct device *dev)
4365 {
4366         pr_debug("%s() called\n", __FUNCTION__);
4367         CLAW_DBF_TEXT(2,setup,"rem_file");
4368         sysfs_remove_group(&dev->kobj, &claw_attr_group);
4369 }
4370
4371 /*--------------------------------------------------------------------*
4372 *    claw_init  and cleanup                                           *
4373 *---------------------------------------------------------------------*/
4374
4375 static void __exit
4376 claw_cleanup(void)
4377 {
4378         unregister_cu3088_discipline(&claw_group_driver);
4379         claw_unregister_debug_facility();
4380         printk(KERN_INFO "claw: Driver unloaded\n");
4381
4382 }
4383
4384 /**
4385  * Initialize module.
4386  * This is called just after the module is loaded.
4387  *
4388  * @return 0 on success, !0 on error.
4389  */
4390 static int __init
4391 claw_init(void)
4392 {
4393         int ret = 0;
4394        printk(KERN_INFO "claw: starting driver "
4395 #ifdef MODULE
4396                 "module "
4397 #else
4398                 "compiled into kernel "
4399 #endif
4400                 " $Revision: 1.38 $ $Date: 2005/08/29 09:47:04 $ \n");
4401
4402
4403 #ifdef FUNCTRACE
4404         printk(KERN_INFO "claw: %s() enter \n",__FUNCTION__);
4405 #endif
4406         ret = claw_register_debug_facility();
4407         if (ret) {
4408                 printk(KERN_WARNING "claw: %s() debug_register failed %d\n",
4409                         __FUNCTION__,ret);
4410                 return ret;
4411         }
4412         CLAW_DBF_TEXT(2,setup,"init_mod");
4413         ret = register_cu3088_discipline(&claw_group_driver);
4414         if (ret) {
4415                 claw_unregister_debug_facility();
4416                 printk(KERN_WARNING "claw; %s() cu3088 register failed %d\n",
4417                         __FUNCTION__,ret);
4418         }
4419 #ifdef FUNCTRACE
4420         printk(KERN_INFO "claw: %s() exit \n",__FUNCTION__);
4421 #endif
4422         return ret;
4423 }
4424
4425 module_init(claw_init);
4426 module_exit(claw_cleanup);
4427
4428
4429
4430 /*--------------------------------------------------------------------*
4431 *    End of File                                                      *
4432 *---------------------------------------------------------------------*/
4433
4434