Fix "frist", "fisrt", typos
[linux-2.6.git] / drivers / s390 / net / claw.c
1 /*
2  *  drivers/s390/net/claw.c
3  *    ESCON CLAW network driver
4  *
5  *  Linux for zSeries version
6  *    Copyright (C) 2002,2005 IBM Corporation
7  *  Author(s) Original code written by:
8  *              Kazuo Iimura (iimura@jp.ibm.com)
9  *            Rewritten by
10  *              Andy Richter (richtera@us.ibm.com)
11  *              Marc Price (mwprice@us.ibm.com)
12  *
13  *    sysfs parms:
14  *   group x.x.rrrr,x.x.wwww
15  *   read_buffer nnnnnnn
16  *   write_buffer nnnnnn
17  *   host_name  aaaaaaaa
18  *   adapter_name aaaaaaaa
19  *   api_type    aaaaaaaa
20  *
21  *  eg.
22  *   group  0.0.0200 0.0.0201
23  *   read_buffer 25
24  *   write_buffer 20
25  *   host_name LINUX390
26  *   adapter_name RS6K
27  *   api_type     TCPIP
28  *
29  *  where
30  *
31  *   The device id is decided by the order entries
32  *   are added to the group the first is claw0 the second claw1
33  *   up to CLAW_MAX_DEV
34  *
35  *   rrrr     - the first of 2 consecutive device addresses used for the
36  *              CLAW protocol.
37  *              The specified address is always used as the input (Read)
38  *              channel and the next address is used as the output channel.
39  *
40  *   wwww     - the second of 2 consecutive device addresses used for
41  *              the CLAW protocol.
42  *              The specified address is always used as the output
43  *              channel and the previous address is used as the input channel.
44  *
45  *   read_buffer        -       specifies number of input buffers to allocate.
46  *   write_buffer       -       specifies number of output buffers to allocate.
47  *   host_name          -       host name
48  *   adaptor_name       -       adaptor name
49  *   api_type           -       API type TCPIP or API will be sent and expected
50  *                              as ws_name
51  *
52  *   Note the following requirements:
53  *   1)  host_name must match the configured adapter_name on the remote side
54  *   2)  adaptor_name must match the configured host name on the remote side
55  *
56  *  Change History
57  *    1.00  Initial release shipped
58  *    1.10  Changes for Buffer allocation
59  *    1.15  Changed for 2.6 Kernel  No longer compiles on 2.4 or lower
60  *    1.25  Added Packing support
61  */
62 #include <asm/bitops.h>
63 #include <asm/ccwdev.h>
64 #include <asm/ccwgroup.h>
65 #include <asm/debug.h>
66 #include <asm/idals.h>
67 #include <asm/io.h>
68
69 #include <linux/ctype.h>
70 #include <linux/delay.h>
71 #include <linux/errno.h>
72 #include <linux/if_arp.h>
73 #include <linux/init.h>
74 #include <linux/interrupt.h>
75 #include <linux/ip.h>
76 #include <linux/kernel.h>
77 #include <linux/module.h>
78 #include <linux/netdevice.h>
79 #include <linux/etherdevice.h>
80 #include <linux/proc_fs.h>
81 #include <linux/sched.h>
82 #include <linux/signal.h>
83 #include <linux/skbuff.h>
84 #include <linux/slab.h>
85 #include <linux/string.h>
86 #include <linux/tcp.h>
87 #include <linux/timer.h>
88 #include <linux/types.h>
89
90 #include "cu3088.h"
91 #include "claw.h"
92
93 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
94 MODULE_DESCRIPTION("Linux for zSeries CLAW Driver\n" \
95                         "Copyright 2000,2005 IBM Corporation\n");
96 MODULE_LICENSE("GPL");
97
98 /* Debugging is based on DEBUGMSG, IOTRACE, or FUNCTRACE  options:
99    DEBUGMSG  - Enables output of various debug messages in the code
100    IOTRACE   - Enables output of CCW and other IO related traces
101    FUNCTRACE - Enables output of function entry/exit trace
102    Define any combination of above options to enable tracing
103
104    CLAW also uses the s390dbf file system  see claw_trace and claw_setup
105 */
106
107 /* following enables tracing */
108 //#define DEBUGMSG
109 //#define IOTRACE
110 //#define FUNCTRACE
111
112 #ifdef DEBUGMSG
113 #define DEBUG
114 #endif
115
116 #ifdef IOTRACE
117 #define DEBUG
118 #endif
119
120 #ifdef FUNCTRACE
121 #define DEBUG
122 #endif
123
124  char debug_buffer[255];
125 /**
126  * Debug Facility Stuff
127  */
128 static debug_info_t *claw_dbf_setup;
129 static debug_info_t *claw_dbf_trace;
130
131 /**
132  *  CLAW Debug Facility functions
133  */
134 static void
135 claw_unregister_debug_facility(void)
136 {
137         if (claw_dbf_setup)
138                 debug_unregister(claw_dbf_setup);
139         if (claw_dbf_trace)
140                 debug_unregister(claw_dbf_trace);
141 }
142
143 static int
144 claw_register_debug_facility(void)
145 {
146         claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
147         claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
148         if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
149                 printk(KERN_WARNING "Not enough memory for debug facility.\n");
150                 claw_unregister_debug_facility();
151                 return -ENOMEM;
152         }
153         debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
154         debug_set_level(claw_dbf_setup, 2);
155         debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
156         debug_set_level(claw_dbf_trace, 2);
157         return 0;
158 }
159
160 static inline void
161 claw_set_busy(struct net_device *dev)
162 {
163  ((struct claw_privbk *) dev->priv)->tbusy=1;
164  eieio();
165 }
166
167 static inline void
168 claw_clear_busy(struct net_device *dev)
169 {
170         clear_bit(0, &(((struct claw_privbk *) dev->priv)->tbusy));
171         netif_wake_queue(dev);
172         eieio();
173 }
174
175 static inline int
176 claw_check_busy(struct net_device *dev)
177 {
178         eieio();
179         return ((struct claw_privbk *) dev->priv)->tbusy;
180 }
181
182 static inline void
183 claw_setbit_busy(int nr,struct net_device *dev)
184 {
185         netif_stop_queue(dev);
186         set_bit(nr, (void *)&(((struct claw_privbk *)dev->priv)->tbusy));
187 }
188
189 static inline void
190 claw_clearbit_busy(int nr,struct net_device *dev)
191 {
192         clear_bit(nr,(void *)&(((struct claw_privbk *)dev->priv)->tbusy));
193         netif_wake_queue(dev);
194 }
195
196 static inline int
197 claw_test_and_setbit_busy(int nr,struct net_device *dev)
198 {
199         netif_stop_queue(dev);
200         return test_and_set_bit(nr,
201                 (void *)&(((struct claw_privbk *) dev->priv)->tbusy));
202 }
203
204
205 /* Functions for the DEV methods */
206
207 static int claw_probe(struct ccwgroup_device *cgdev);
208 static void claw_remove_device(struct ccwgroup_device *cgdev);
209 static void claw_purge_skb_queue(struct sk_buff_head *q);
210 static int claw_new_device(struct ccwgroup_device *cgdev);
211 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
212 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
213 static int claw_change_mtu( struct net_device *dev, int new_mtu);
214 static int claw_open(struct net_device *dev);
215 static void claw_irq_handler(struct ccw_device *cdev,
216         unsigned long intparm, struct irb *irb);
217 static void claw_irq_tasklet ( unsigned long data );
218 static int claw_release(struct net_device *dev);
219 static void claw_write_retry ( struct chbk * p_ch );
220 static void claw_write_next ( struct chbk * p_ch );
221 static void claw_timer ( struct chbk * p_ch );
222
223 /* Functions */
224 static int add_claw_reads(struct net_device *dev,
225         struct ccwbk* p_first, struct ccwbk* p_last);
226 static void inline ccw_check_return_code (struct ccw_device *cdev,
227         int return_code);
228 static void inline ccw_check_unit_check (struct chbk * p_ch,
229         unsigned char sense );
230 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
231 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
232 static int init_ccw_bk(struct net_device *dev);
233 static void probe_error( struct ccwgroup_device *cgdev);
234 static struct net_device_stats *claw_stats(struct net_device *dev);
235 static int inline pages_to_order_of_mag(int num_of_pages);
236 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
237 #ifdef DEBUG
238 static void dumpit (char *buf, int len);
239 #endif
240 /* sysfs Functions */
241 static ssize_t claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf);
242 static ssize_t claw_hname_write(struct device *dev, struct device_attribute *attr,
243         const char *buf, size_t count);
244 static ssize_t claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf);
245 static ssize_t claw_adname_write(struct device *dev, struct device_attribute *attr,
246         const char *buf, size_t count);
247 static ssize_t claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf);
248 static ssize_t claw_apname_write(struct device *dev, struct device_attribute *attr,
249         const char *buf, size_t count);
250 static ssize_t claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
251 static ssize_t claw_wbuff_write(struct device *dev, struct device_attribute *attr,
252         const char *buf, size_t count);
253 static ssize_t claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf);
254 static ssize_t claw_rbuff_write(struct device *dev, struct device_attribute *attr,
255         const char *buf, size_t count);
256 static int claw_add_files(struct device *dev);
257 static void claw_remove_files(struct device *dev);
258
259 /*   Functions for System Validate  */
260 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
261 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
262        __u8 correlator, __u8 rc , char *local_name, char *remote_name);
263 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
264 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
265 static int claw_snd_sys_validate_rsp(struct net_device *dev,
266         struct clawctl * p_ctl, __u32 return_code);
267 static int claw_strt_conn_req(struct net_device *dev );
268 static void claw_strt_read ( struct net_device *dev, int lock );
269 static void claw_strt_out_IO( struct net_device *dev );
270 static void claw_free_wrt_buf( struct net_device *dev );
271
272 /* Functions for unpack reads   */
273 static void unpack_read (struct net_device *dev );
274
275 /* ccwgroup table  */
276
277 static struct ccwgroup_driver claw_group_driver = {
278         .owner       = THIS_MODULE,
279         .name        = "claw",
280         .max_slaves  = 2,
281         .driver_id   = 0xC3D3C1E6,
282         .probe       = claw_probe,
283         .remove      = claw_remove_device,
284         .set_online  = claw_new_device,
285         .set_offline = claw_shutdown_device,
286 };
287
288 /*
289 *
290 *       Key functions
291 */
292
293 /*----------------------------------------------------------------*
294  *   claw_probe                                                   *
295  *      this function is called for each CLAW device.             *
296  *----------------------------------------------------------------*/
297 static int
298 claw_probe(struct ccwgroup_device *cgdev)
299 {
300         int             rc;
301         struct claw_privbk *privptr=NULL;
302
303 #ifdef FUNCTRACE
304         printk(KERN_INFO "%s Enter\n",__FUNCTION__);
305 #endif
306         CLAW_DBF_TEXT(2,setup,"probe");
307         if (!get_device(&cgdev->dev))
308                 return -ENODEV;
309 #ifdef DEBUGMSG
310         printk(KERN_INFO "claw: variable cgdev =\n");
311         dumpit((char *)cgdev, sizeof(struct ccwgroup_device));
312 #endif
313         privptr = kmalloc(sizeof(struct claw_privbk), GFP_KERNEL);
314         if (privptr == NULL) {
315                 probe_error(cgdev);
316                 put_device(&cgdev->dev);
317                 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
318                         cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
319                 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
320                 return -ENOMEM;
321         }
322         memset(privptr,0x00,sizeof(struct claw_privbk));
323         privptr->p_mtc_envelope= kmalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
324         privptr->p_env = kmalloc(sizeof(struct claw_env), GFP_KERNEL);
325         if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
326                 probe_error(cgdev);
327                 put_device(&cgdev->dev);
328                 printk(KERN_WARNING "Out of memory %s %s Exit Line %d \n",
329                         cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
330                 CLAW_DBF_TEXT_(2,setup,"probex%d",-ENOMEM);
331                 return -ENOMEM;
332         }
333         memset(privptr->p_mtc_envelope, 0x00, MAX_ENVELOPE_SIZE);
334         memset(privptr->p_env, 0x00, sizeof(struct claw_env));
335         memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
336         memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
337         memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
338         privptr->p_env->packing = 0;
339         privptr->p_env->write_buffers = 5;
340         privptr->p_env->read_buffers = 5;
341         privptr->p_env->read_size = CLAW_FRAME_SIZE;
342         privptr->p_env->write_size = CLAW_FRAME_SIZE;
343         rc = claw_add_files(&cgdev->dev);
344         if (rc) {
345                 probe_error(cgdev);
346                 put_device(&cgdev->dev);
347                 printk(KERN_WARNING "add_files failed %s %s Exit Line %d \n",
348                         cgdev->cdev[0]->dev.bus_id,__FUNCTION__,__LINE__);
349                 CLAW_DBF_TEXT_(2,setup,"probex%d",rc);
350                 return rc;
351         }
352         printk(KERN_INFO "claw: sysfs files added for %s\n",cgdev->cdev[0]->dev.bus_id);
353         privptr->p_env->p_priv = privptr;
354         cgdev->cdev[0]->handler = claw_irq_handler;
355         cgdev->cdev[1]->handler = claw_irq_handler;
356         cgdev->dev.driver_data = privptr;
357 #ifdef FUNCTRACE
358         printk(KERN_INFO "claw:%s exit on line %d, "
359                 "rc = 0\n",__FUNCTION__,__LINE__);
360 #endif
361         CLAW_DBF_TEXT(2,setup,"prbext 0");
362
363         return 0;
364 }  /*  end of claw_probe       */
365
366 /*-------------------------------------------------------------------*
367  *   claw_tx                                                         *
368  *-------------------------------------------------------------------*/
369
370 static int
371 claw_tx(struct sk_buff *skb, struct net_device *dev)
372 {
373         int             rc;
374         struct claw_privbk *privptr=dev->priv;
375         unsigned long saveflags;
376         struct chbk *p_ch;
377
378 #ifdef FUNCTRACE
379         printk(KERN_INFO "%s:%s enter\n",dev->name,__FUNCTION__);
380 #endif
381         CLAW_DBF_TEXT(4,trace,"claw_tx");
382         p_ch=&privptr->channel[WRITE];
383         if (skb == NULL) {
384                 printk(KERN_WARNING "%s: null pointer passed as sk_buffer\n",
385                         dev->name);
386                 privptr->stats.tx_dropped++;
387 #ifdef FUNCTRACE
388                 printk(KERN_INFO "%s: %s() exit on line %d, rc = EIO\n",
389                         dev->name,__FUNCTION__, __LINE__);
390 #endif
391                 CLAW_DBF_TEXT_(2,trace,"clawtx%d",-EIO);
392                 return -EIO;
393         }
394
395 #ifdef IOTRACE
396         printk(KERN_INFO "%s: variable sk_buff=\n",dev->name);
397         dumpit((char *) skb, sizeof(struct sk_buff));
398         printk(KERN_INFO "%s: variable dev=\n",dev->name);
399         dumpit((char *) dev, sizeof(struct net_device));
400 #endif
401         spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
402         rc=claw_hw_tx( skb, dev, 1 );
403         spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
404 #ifdef FUNCTRACE
405         printk(KERN_INFO "%s:%s exit on line %d, rc = %d\n",
406                 dev->name, __FUNCTION__, __LINE__, rc);
407 #endif
408         CLAW_DBF_TEXT_(4,trace,"clawtx%d",rc);
409         return rc;
410 }   /*  end of claw_tx */
411
412 /*------------------------------------------------------------------*
413  *  pack the collect queue into an skb and return it                *
414  *   If not packing just return the top skb from the queue          *
415  *------------------------------------------------------------------*/
416
417 static struct sk_buff *
418 claw_pack_skb(struct claw_privbk *privptr)
419 {
420         struct sk_buff *new_skb,*held_skb;
421         struct chbk *p_ch = &privptr->channel[WRITE];
422         struct claw_env  *p_env = privptr->p_env;
423         int     pkt_cnt,pk_ind,so_far;
424
425         new_skb = NULL;         /* assume no dice */
426         pkt_cnt = 0;
427         CLAW_DBF_TEXT(4,trace,"PackSKBe");
428         if (!skb_queue_empty(&p_ch->collect_queue)) {
429         /* some data */
430                 held_skb = skb_dequeue(&p_ch->collect_queue);
431                 if (held_skb)
432                         dev_kfree_skb_any(held_skb);
433                 else
434                         return NULL;
435                 if (p_env->packing != DO_PACKED)
436                         return held_skb;
437                 /* get a new SKB we will pack at least one */
438                 new_skb = dev_alloc_skb(p_env->write_size);
439                 if (new_skb == NULL) {
440                         atomic_inc(&held_skb->users);
441                         skb_queue_head(&p_ch->collect_queue,held_skb);
442                         return NULL;
443                 }
444                 /* we have packed packet and a place to put it  */
445                 pk_ind = 1;
446                 so_far = 0;
447                 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
448                 while ((pk_ind) && (held_skb != NULL)) {
449                         if (held_skb->len+so_far <= p_env->write_size-8) {
450                                 memcpy(skb_put(new_skb,held_skb->len),
451                                         held_skb->data,held_skb->len);
452                                 privptr->stats.tx_packets++;
453                                 so_far += held_skb->len;
454                                 pkt_cnt++;
455                                 dev_kfree_skb_any(held_skb);
456                                 held_skb = skb_dequeue(&p_ch->collect_queue);
457                                 if (held_skb)
458                                         atomic_dec(&held_skb->users);
459                         } else {
460                                 pk_ind = 0;
461                                 atomic_inc(&held_skb->users);
462                                 skb_queue_head(&p_ch->collect_queue,held_skb);
463                         }
464                 }
465 #ifdef IOTRACE
466                 printk(KERN_INFO "%s: %s() Packed %d len %d\n",
467                         p_env->ndev->name,
468                         __FUNCTION__,pkt_cnt,new_skb->len);
469 #endif
470         }
471         CLAW_DBF_TEXT(4,trace,"PackSKBx");
472         return new_skb;
473 }
474
475 /*-------------------------------------------------------------------*
476  *   claw_change_mtu                                                 *
477  *                                                                   *
478  *-------------------------------------------------------------------*/
479
480 static int
481 claw_change_mtu(struct net_device *dev, int new_mtu)
482 {
483         struct claw_privbk  *privptr=dev->priv;
484         int buff_size;
485 #ifdef FUNCTRACE
486         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
487 #endif
488 #ifdef DEBUGMSG
489         printk(KERN_INFO "variable dev =\n");
490         dumpit((char *) dev, sizeof(struct net_device));
491         printk(KERN_INFO "variable new_mtu = %d\n", new_mtu);
492 #endif
493         CLAW_DBF_TEXT(4,trace,"setmtu");
494         buff_size = privptr->p_env->write_size;
495         if ((new_mtu < 60) || (new_mtu > buff_size)) {
496 #ifdef FUNCTRACE
497                 printk(KERN_INFO "%s:%s Exit on line %d, rc=EINVAL\n",
498                 dev->name,
499                 __FUNCTION__, __LINE__);
500 #endif
501                 return -EINVAL;
502         }
503         dev->mtu = new_mtu;
504 #ifdef FUNCTRACE
505         printk(KERN_INFO "%s:%s Exit on line %d\n",dev->name,
506         __FUNCTION__, __LINE__);
507 #endif
508         return 0;
509 }  /*   end of claw_change_mtu */
510
511
512 /*-------------------------------------------------------------------*
513  *   claw_open                                                       *
514  *                                                                   *
515  *-------------------------------------------------------------------*/
516 static int
517 claw_open(struct net_device *dev)
518 {
519
520         int     rc;
521         int     i;
522         unsigned long       saveflags=0;
523         unsigned long       parm;
524         struct claw_privbk  *privptr;
525         DECLARE_WAITQUEUE(wait, current);
526         struct timer_list  timer;
527         struct ccwbk *p_buf;
528
529 #ifdef FUNCTRACE
530         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
531 #endif
532         CLAW_DBF_TEXT(4,trace,"open");
533         if (!dev | (dev->name[0] == 0x00)) {
534                 CLAW_DBF_TEXT(2,trace,"BadDev");
535                 printk(KERN_WARNING "claw: Bad device at open failing \n");
536                 return -ENODEV;
537         }
538         privptr = (struct claw_privbk *)dev->priv;
539         /*   allocate and initialize CCW blocks */
540         if (privptr->buffs_alloc == 0) {
541                 rc=init_ccw_bk(dev);
542                 if (rc) {
543                         printk(KERN_INFO "%s:%s Exit on line %d, rc=ENOMEM\n",
544                         dev->name,
545                         __FUNCTION__, __LINE__);
546                         CLAW_DBF_TEXT(2,trace,"openmem");
547                         return -ENOMEM;
548                 }
549         }
550         privptr->system_validate_comp=0;
551         privptr->release_pend=0;
552         if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
553                 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
554                 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
555                 privptr->p_env->packing=PACKING_ASK;
556         } else {
557                 privptr->p_env->packing=0;
558                 privptr->p_env->read_size=CLAW_FRAME_SIZE;
559                 privptr->p_env->write_size=CLAW_FRAME_SIZE;
560         }
561         claw_set_busy(dev);
562         tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
563                 (unsigned long) &privptr->channel[READ]);
564         for ( i = 0; i < 2;  i++) {
565                 CLAW_DBF_TEXT_(2,trace,"opn_ch%d",i);
566                 init_waitqueue_head(&privptr->channel[i].wait);
567                 /* skb_queue_head_init(&p_ch->io_queue); */
568                 if (i == WRITE)
569                         skb_queue_head_init(
570                                 &privptr->channel[WRITE].collect_queue);
571                 privptr->channel[i].flag_a = 0;
572                 privptr->channel[i].IO_active = 0;
573                 privptr->channel[i].flag  &= ~CLAW_TIMER;
574                 init_timer(&timer);
575                 timer.function = (void *)claw_timer;
576                 timer.data = (unsigned long)(&privptr->channel[i]);
577                 timer.expires = jiffies + 15*HZ;
578                 add_timer(&timer);
579                 spin_lock_irqsave(get_ccwdev_lock(
580                         privptr->channel[i].cdev), saveflags);
581                 parm = (unsigned long) &privptr->channel[i];
582                 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
583                 rc = 0;
584                 add_wait_queue(&privptr->channel[i].wait, &wait);
585                 rc = ccw_device_halt(
586                         (struct ccw_device *)privptr->channel[i].cdev,parm);
587                 set_current_state(TASK_INTERRUPTIBLE);
588                 spin_unlock_irqrestore(
589                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
590                 schedule();
591                 set_current_state(TASK_RUNNING);
592                 remove_wait_queue(&privptr->channel[i].wait, &wait);
593                 if(rc != 0)
594                         ccw_check_return_code(privptr->channel[i].cdev, rc);
595                 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
596                         del_timer(&timer);
597         }
598         if ((((privptr->channel[READ].last_dstat |
599                 privptr->channel[WRITE].last_dstat) &
600            ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
601            (((privptr->channel[READ].flag |
602                 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
603 #ifdef DEBUGMSG
604                 printk(KERN_INFO "%s: channel problems during open - read:"
605                         " %02x -  write: %02x\n",
606                         dev->name,
607                         privptr->channel[READ].last_dstat,
608                         privptr->channel[WRITE].last_dstat);
609 #endif
610                 printk(KERN_INFO "%s: remote side is not ready\n", dev->name);
611                 CLAW_DBF_TEXT(2,trace,"notrdy");
612
613                 for ( i = 0; i < 2;  i++) {
614                         spin_lock_irqsave(
615                                 get_ccwdev_lock(privptr->channel[i].cdev),
616                                 saveflags);
617                         parm = (unsigned long) &privptr->channel[i];
618                         privptr->channel[i].claw_state = CLAW_STOP;
619                         rc = ccw_device_halt(
620                                 (struct ccw_device *)&privptr->channel[i].cdev,
621                                 parm);
622                         spin_unlock_irqrestore(
623                                 get_ccwdev_lock(privptr->channel[i].cdev),
624                                 saveflags);
625                         if (rc != 0) {
626                                 ccw_check_return_code(
627                                         privptr->channel[i].cdev, rc);
628                         }
629                 }
630                 free_pages((unsigned long)privptr->p_buff_ccw,
631                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
632                 if (privptr->p_env->read_size < PAGE_SIZE) {
633                         free_pages((unsigned long)privptr->p_buff_read,
634                                (int)pages_to_order_of_mag(
635                                         privptr->p_buff_read_num));
636                 }
637                 else {
638                         p_buf=privptr->p_read_active_first;
639                         while (p_buf!=NULL) {
640                                 free_pages((unsigned long)p_buf->p_buffer,
641                                       (int)pages_to_order_of_mag(
642                                         privptr->p_buff_pages_perread ));
643                                 p_buf=p_buf->next;
644                         }
645                 }
646                 if (privptr->p_env->write_size < PAGE_SIZE ) {
647                         free_pages((unsigned long)privptr->p_buff_write,
648                              (int)pages_to_order_of_mag(
649                                 privptr->p_buff_write_num));
650                 }
651                 else {
652                         p_buf=privptr->p_write_active_first;
653                         while (p_buf!=NULL) {
654                                 free_pages((unsigned long)p_buf->p_buffer,
655                                      (int)pages_to_order_of_mag(
656                                         privptr->p_buff_pages_perwrite ));
657                                 p_buf=p_buf->next;
658                         }
659                 }
660                 privptr->buffs_alloc = 0;
661                 privptr->channel[READ].flag= 0x00;
662                 privptr->channel[WRITE].flag = 0x00;
663                 privptr->p_buff_ccw=NULL;
664                 privptr->p_buff_read=NULL;
665                 privptr->p_buff_write=NULL;
666                 claw_clear_busy(dev);
667 #ifdef FUNCTRACE
668                 printk(KERN_INFO "%s:%s Exit on line %d, rc=EIO\n",
669                 dev->name,__FUNCTION__,__LINE__);
670 #endif
671                 CLAW_DBF_TEXT(2,trace,"open EIO");
672                 return -EIO;
673         }
674
675         /*   Send SystemValidate command */
676
677         claw_clear_busy(dev);
678
679 #ifdef FUNCTRACE
680         printk(KERN_INFO "%s:%s Exit on line %d, rc=0\n",
681                 dev->name,__FUNCTION__,__LINE__);
682 #endif
683         CLAW_DBF_TEXT(4,trace,"openok");
684         return 0;
685 }    /*     end of claw_open    */
686
687 /*-------------------------------------------------------------------*
688 *                                                                    *
689 *       claw_irq_handler                                             *
690 *                                                                    *
691 *--------------------------------------------------------------------*/
692 static void
693 claw_irq_handler(struct ccw_device *cdev,
694         unsigned long intparm, struct irb *irb)
695 {
696         struct chbk *p_ch = NULL;
697         struct claw_privbk *privptr = NULL;
698         struct net_device *dev = NULL;
699         struct claw_env  *p_env;
700         struct chbk *p_ch_r=NULL;
701
702
703 #ifdef FUNCTRACE
704         printk(KERN_INFO "%s enter  \n",__FUNCTION__);
705 #endif
706         CLAW_DBF_TEXT(4,trace,"clawirq");
707         /* Bypass all 'unsolicited interrupts' */
708         if (!cdev->dev.driver_data) {
709                 printk(KERN_WARNING "claw: unsolicited interrupt for device:"
710                         "%s received c-%02x d-%02x\n",
711                         cdev->dev.bus_id,irb->scsw.cstat, irb->scsw.dstat);
712 #ifdef FUNCTRACE
713                 printk(KERN_INFO "claw: %s() "
714                         "exit on line %d\n",__FUNCTION__,__LINE__);
715 #endif
716                 CLAW_DBF_TEXT(2,trace,"badirq");
717                 return;
718         }
719         privptr = (struct claw_privbk *)cdev->dev.driver_data;
720
721         /* Try to extract channel from driver data. */
722         if (privptr->channel[READ].cdev == cdev)
723                 p_ch = &privptr->channel[READ];
724         else if (privptr->channel[WRITE].cdev == cdev)
725                 p_ch = &privptr->channel[WRITE];
726         else {
727                 printk(KERN_WARNING "claw: Can't determine channel for "
728                         "interrupt, device %s\n", cdev->dev.bus_id);
729                 CLAW_DBF_TEXT(2,trace,"badchan");
730                 return;
731         }
732         CLAW_DBF_TEXT_(4,trace,"IRQCH=%d",p_ch->flag);
733
734         dev = (struct net_device *) (p_ch->ndev);
735         p_env=privptr->p_env;
736
737 #ifdef IOTRACE
738         printk(KERN_INFO "%s: interrupt for device: %04x "
739                 "received c-%02x d-%02x state-%02x\n",
740                 dev->name, p_ch->devno, irb->scsw.cstat,
741                 irb->scsw.dstat, p_ch->claw_state);
742 #endif
743
744         /* Copy interruption response block. */
745         memcpy(p_ch->irb, irb, sizeof(struct irb));
746
747         /* Check for good subchannel return code, otherwise error message */
748         if (irb->scsw.cstat  &&  !(irb->scsw.cstat & SCHN_STAT_PCI)) {
749                 printk(KERN_INFO "%s: subchannel check for device: %04x -"
750                         " Sch Stat %02x  Dev Stat %02x CPA - %04x\n",
751                         dev->name, p_ch->devno,
752                         irb->scsw.cstat, irb->scsw.dstat,irb->scsw.cpa);
753 #ifdef IOTRACE
754                 dumpit((char *)irb,sizeof(struct irb));
755                 dumpit((char *)(unsigned long)irb->scsw.cpa,
756                         sizeof(struct ccw1));
757 #endif
758 #ifdef FUNCTRACE
759                 printk(KERN_INFO "%s:%s Exit on line %d\n",
760                 dev->name,__FUNCTION__,__LINE__);
761 #endif
762                 CLAW_DBF_TEXT(2,trace,"chanchk");
763                 /* return; */
764         }
765
766         /* Check the reason-code of a unit check */
767         if (irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
768                 ccw_check_unit_check(p_ch, irb->ecw[0]);
769         }
770
771         /* State machine to bring the connection up, down and to restart */
772         p_ch->last_dstat = irb->scsw.dstat;
773
774         switch (p_ch->claw_state) {
775                 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
776 #ifdef DEBUGMSG
777                         printk(KERN_INFO "%s: CLAW_STOP enter\n", dev->name);
778 #endif
779                         if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
780                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
781                         (p_ch->irb->scsw.stctl ==
782                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
783 #ifdef FUNCTRACE
784                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
785                                         dev->name,__FUNCTION__,__LINE__);
786 #endif
787                                 return;
788                         }
789                         wake_up(&p_ch->wait);   /* wake up claw_release */
790
791 #ifdef DEBUGMSG
792                         printk(KERN_INFO "%s: CLAW_STOP exit\n", dev->name);
793 #endif
794 #ifdef FUNCTRACE
795                         printk(KERN_INFO "%s:%s Exit on line %d\n",
796                                 dev->name,__FUNCTION__,__LINE__);
797 #endif
798                         CLAW_DBF_TEXT(4,trace,"stop");
799                         return;
800
801                 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open  */
802 #ifdef DEBUGMSG
803                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO\n",
804                                 dev->name);
805 #endif
806                         if (!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
807                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
808                         (p_ch->irb->scsw.stctl ==
809                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
810 #ifdef FUNCTRACE
811                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
812                                         dev->name,__FUNCTION__,__LINE__);
813 #endif
814                                 CLAW_DBF_TEXT(4,trace,"haltio");
815                                 return;
816                         }
817                         if (p_ch->flag == CLAW_READ) {
818                                 p_ch->claw_state = CLAW_START_READ;
819                                 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
820                         }
821                         else
822                            if (p_ch->flag == CLAW_WRITE) {
823                                 p_ch->claw_state = CLAW_START_WRITE;
824                                 /*      send SYSTEM_VALIDATE                    */
825                                 claw_strt_read(dev, LOCK_NO);
826                                 claw_send_control(dev,
827                                         SYSTEM_VALIDATE_REQUEST,
828                                         0, 0, 0,
829                                         p_env->host_name,
830                                         p_env->adapter_name );
831                         } else {
832                                 printk(KERN_WARNING "claw: unsolicited "
833                                         "interrupt for device:"
834                                         "%s received c-%02x d-%02x\n",
835                                         cdev->dev.bus_id,
836                                         irb->scsw.cstat,
837                                         irb->scsw.dstat);
838                                 return;
839                                 }
840 #ifdef DEBUGMSG
841                         printk(KERN_INFO "%s: process CLAW_STAT_HALT_IO exit\n",
842                                 dev->name);
843 #endif
844 #ifdef FUNCTRACE
845                         printk(KERN_INFO "%s:%s Exit on line %d\n",
846                                 dev->name,__FUNCTION__,__LINE__);
847 #endif
848                         CLAW_DBF_TEXT(4,trace,"haltio");
849                         return;
850                 case CLAW_START_READ:
851                         CLAW_DBF_TEXT(4,trace,"ReadIRQ");
852                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
853                                 clear_bit(0, (void *)&p_ch->IO_active);
854                                 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
855                                     (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
856                                     (p_ch->irb->ecw[0])        == 0)
857                                 {
858                                         privptr->stats.rx_errors++;
859                                         printk(KERN_INFO "%s: Restart is "
860                                                 "required after remote "
861                                                 "side recovers \n",
862                                                 dev->name);
863                                 }
864 #ifdef FUNCTRACE
865                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
866                                         dev->name,__FUNCTION__,__LINE__);
867 #endif
868                                         CLAW_DBF_TEXT(4,trace,"notrdy");
869                                         return;
870                         }
871                         if ((p_ch->irb->scsw.cstat & SCHN_STAT_PCI) &&
872                             (p_ch->irb->scsw.dstat==0)) {
873                                 if (test_and_set_bit(CLAW_BH_ACTIVE,
874                                         (void *)&p_ch->flag_a) == 0) {
875                                         tasklet_schedule(&p_ch->tasklet);
876                                 }
877                                 else {
878                                         CLAW_DBF_TEXT(4,trace,"PCINoBH");
879                                 }
880 #ifdef FUNCTRACE
881                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
882                                         dev->name,__FUNCTION__,__LINE__);
883 #endif
884                                 CLAW_DBF_TEXT(4,trace,"PCI_read");
885                                 return;
886                         }
887                         if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
888                          (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
889                          (p_ch->irb->scsw.stctl ==
890                          (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
891 #ifdef FUNCTRACE
892                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
893                                         dev->name,__FUNCTION__,__LINE__);
894 #endif
895                                 CLAW_DBF_TEXT(4,trace,"SPend_rd");
896                                 return;
897                         }
898                         clear_bit(0, (void *)&p_ch->IO_active);
899                         claw_clearbit_busy(TB_RETRY,dev);
900                         if (test_and_set_bit(CLAW_BH_ACTIVE,
901                                 (void *)&p_ch->flag_a) == 0) {
902                                 tasklet_schedule(&p_ch->tasklet);
903                          }
904                         else {
905                                 CLAW_DBF_TEXT(4,trace,"RdBHAct");
906                         }
907
908 #ifdef DEBUGMSG
909                         printk(KERN_INFO "%s: process CLAW_START_READ exit\n",
910                                 dev->name);
911 #endif
912 #ifdef FUNCTRACE
913                         printk(KERN_INFO "%s:%s Exit on line %d\n",
914                                 dev->name,__FUNCTION__,__LINE__);
915 #endif
916                         CLAW_DBF_TEXT(4,trace,"RdIRQXit");
917                         return;
918                 case CLAW_START_WRITE:
919                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_CHECK) {
920                                 printk(KERN_INFO "%s: Unit Check Occured in "
921                                         "write channel\n",dev->name);
922                                 clear_bit(0, (void *)&p_ch->IO_active);
923                                 if (p_ch->irb->ecw[0] & 0x80 ) {
924                                         printk(KERN_INFO "%s: Resetting Event "
925                                                 "occurred:\n",dev->name);
926                                         init_timer(&p_ch->timer);
927                                         p_ch->timer.function =
928                                                 (void *)claw_write_retry;
929                                         p_ch->timer.data = (unsigned long)p_ch;
930                                         p_ch->timer.expires = jiffies + 10*HZ;
931                                         add_timer(&p_ch->timer);
932                                         printk(KERN_INFO "%s: write connection "
933                                                 "restarting\n",dev->name);
934                                 }
935 #ifdef FUNCTRACE
936                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
937                                         dev->name,__FUNCTION__,__LINE__);
938 #endif
939                                 CLAW_DBF_TEXT(4,trace,"rstrtwrt");
940                                 return;
941                         }
942                         if (p_ch->irb->scsw.dstat & DEV_STAT_UNIT_EXCEP) {
943                                         clear_bit(0, (void *)&p_ch->IO_active);
944                                         printk(KERN_INFO "%s: Unit Exception "
945                                                 "Occured in write channel\n",
946                                                 dev->name);
947                         }
948                         if(!((p_ch->irb->scsw.stctl & SCSW_STCTL_SEC_STATUS) ||
949                         (p_ch->irb->scsw.stctl == SCSW_STCTL_STATUS_PEND) ||
950                         (p_ch->irb->scsw.stctl ==
951                         (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
952 #ifdef FUNCTRACE
953                                 printk(KERN_INFO "%s:%s Exit on line %d\n",
954                                         dev->name,__FUNCTION__,__LINE__);
955 #endif
956                                 CLAW_DBF_TEXT(4,trace,"writeUE");
957                                 return;
958                         }
959                         clear_bit(0, (void *)&p_ch->IO_active);
960                         if (claw_test_and_setbit_busy(TB_TX,dev)==0) {
961                                 claw_write_next(p_ch);
962                                 claw_clearbit_busy(TB_TX,dev);
963                                 claw_clear_busy(dev);
964                         }
965                         p_ch_r=(struct chbk *)&privptr->channel[READ];
966                         if (test_and_set_bit(CLAW_BH_ACTIVE,
967                                         (void *)&p_ch_r->flag_a) == 0) {
968                                 tasklet_schedule(&p_ch_r->tasklet);
969                         }
970
971 #ifdef DEBUGMSG
972                         printk(KERN_INFO "%s: process CLAW_START_WRITE exit\n",
973                                  dev->name);
974 #endif
975 #ifdef FUNCTRACE
976                         printk(KERN_INFO "%s:%s Exit on line %d\n",
977                                 dev->name,__FUNCTION__,__LINE__);
978 #endif
979                         CLAW_DBF_TEXT(4,trace,"StWtExit");
980                         return;
981                 default:
982                         printk(KERN_WARNING "%s: wrong selection code - irq "
983                                 "state=%d\n",dev->name,p_ch->claw_state);
984 #ifdef FUNCTRACE
985                         printk(KERN_INFO "%s:%s Exit on line %d\n",
986                                 dev->name,__FUNCTION__,__LINE__);
987 #endif
988                         CLAW_DBF_TEXT(2,trace,"badIRQ");
989                         return;
990         }
991
992 }       /*   end of claw_irq_handler    */
993
994
995 /*-------------------------------------------------------------------*
996 *       claw_irq_tasklet                                             *
997 *                                                                    *
998 *--------------------------------------------------------------------*/
999 static void
1000 claw_irq_tasklet ( unsigned long data )
1001 {
1002         struct chbk * p_ch;
1003         struct net_device  *dev;
1004         struct claw_privbk *       privptr;
1005
1006         p_ch = (struct chbk *) data;
1007         dev = (struct net_device *)p_ch->ndev;
1008 #ifdef FUNCTRACE
1009         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
1010 #endif
1011 #ifdef DEBUGMSG
1012         printk(KERN_INFO "%s: variable p_ch =\n",dev->name);
1013         dumpit((char *) p_ch, sizeof(struct chbk));
1014 #endif
1015         CLAW_DBF_TEXT(4,trace,"IRQtask");
1016
1017         privptr = (struct claw_privbk *) dev->priv;
1018
1019 #ifdef DEBUGMSG
1020         printk(KERN_INFO "%s: bh routine - state-%02x\n" ,
1021                 dev->name, p_ch->claw_state);
1022 #endif
1023
1024         unpack_read(dev);
1025         clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
1026         CLAW_DBF_TEXT(4,trace,"TskletXt");
1027 #ifdef FUNCTRACE
1028         printk(KERN_INFO "%s:%s Exit on line %d\n",
1029                 dev->name,__FUNCTION__,__LINE__);
1030 #endif
1031         return;
1032 }       /*    end of claw_irq_bh    */
1033
1034 /*-------------------------------------------------------------------*
1035 *       claw_release                                                 *
1036 *                                                                    *
1037 *--------------------------------------------------------------------*/
1038 static int
1039 claw_release(struct net_device *dev)
1040 {
1041         int                rc;
1042         int                i;
1043         unsigned long      saveflags;
1044         unsigned long      parm;
1045         struct claw_privbk *privptr;
1046         DECLARE_WAITQUEUE(wait, current);
1047         struct ccwbk*             p_this_ccw;
1048         struct ccwbk*             p_buf;
1049
1050         if (!dev)
1051                 return 0;
1052         privptr = (struct claw_privbk *) dev->priv;
1053         if (!privptr)
1054                 return 0;
1055 #ifdef FUNCTRACE
1056         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
1057 #endif
1058         CLAW_DBF_TEXT(4,trace,"release");
1059 #ifdef DEBUGMSG
1060         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1061         dumpit((char *) dev, sizeof(struct net_device));
1062         printk(KERN_INFO "Priv Buffalloc %d\n",privptr->buffs_alloc);
1063         printk(KERN_INFO "Priv p_buff_ccw = %p\n",&privptr->p_buff_ccw);
1064 #endif
1065         privptr->release_pend=1;
1066         claw_setbit_busy(TB_STOP,dev);
1067         for ( i = 1; i >=0 ;  i--) {
1068                 spin_lock_irqsave(
1069                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1070              /*   del_timer(&privptr->channel[READ].timer);  */
1071                 privptr->channel[i].claw_state = CLAW_STOP;
1072                 privptr->channel[i].IO_active = 0;
1073                 parm = (unsigned long) &privptr->channel[i];
1074                 if (i == WRITE)
1075                         claw_purge_skb_queue(
1076                                 &privptr->channel[WRITE].collect_queue);
1077                 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
1078                 if (privptr->system_validate_comp==0x00)  /* never opened? */
1079                    init_waitqueue_head(&privptr->channel[i].wait);
1080                 add_wait_queue(&privptr->channel[i].wait, &wait);
1081                 set_current_state(TASK_INTERRUPTIBLE);
1082                 spin_unlock_irqrestore(
1083                         get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
1084                 schedule();
1085                 set_current_state(TASK_RUNNING);
1086                 remove_wait_queue(&privptr->channel[i].wait, &wait);
1087                 if (rc != 0) {
1088                         ccw_check_return_code(privptr->channel[i].cdev, rc);
1089                 }
1090         }
1091         if (privptr->pk_skb != NULL) {
1092                 dev_kfree_skb_any(privptr->pk_skb);
1093                 privptr->pk_skb = NULL;
1094         }
1095         if(privptr->buffs_alloc != 1) {
1096 #ifdef FUNCTRACE
1097         printk(KERN_INFO "%s:%s Exit on line %d\n",
1098                 dev->name,__FUNCTION__,__LINE__);
1099 #endif
1100                 CLAW_DBF_TEXT(4,trace,"none2fre");
1101                 return 0;
1102         }
1103         CLAW_DBF_TEXT(4,trace,"freebufs");
1104         if (privptr->p_buff_ccw != NULL) {
1105                 free_pages((unsigned long)privptr->p_buff_ccw,
1106                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
1107         }
1108         CLAW_DBF_TEXT(4,trace,"freeread");
1109         if (privptr->p_env->read_size < PAGE_SIZE) {
1110             if (privptr->p_buff_read != NULL) {
1111                 free_pages((unsigned long)privptr->p_buff_read,
1112                       (int)pages_to_order_of_mag(privptr->p_buff_read_num));
1113                 }
1114         }
1115         else {
1116                 p_buf=privptr->p_read_active_first;
1117                 while (p_buf!=NULL) {
1118                         free_pages((unsigned long)p_buf->p_buffer,
1119                              (int)pages_to_order_of_mag(
1120                                 privptr->p_buff_pages_perread ));
1121                         p_buf=p_buf->next;
1122                 }
1123         }
1124          CLAW_DBF_TEXT(4,trace,"freewrit");
1125         if (privptr->p_env->write_size < PAGE_SIZE ) {
1126                 free_pages((unsigned long)privptr->p_buff_write,
1127                       (int)pages_to_order_of_mag(privptr->p_buff_write_num));
1128         }
1129         else {
1130                 p_buf=privptr->p_write_active_first;
1131                 while (p_buf!=NULL) {
1132                         free_pages((unsigned long)p_buf->p_buffer,
1133                               (int)pages_to_order_of_mag(
1134                               privptr->p_buff_pages_perwrite ));
1135                         p_buf=p_buf->next;
1136                 }
1137         }
1138          CLAW_DBF_TEXT(4,trace,"clearptr");
1139         privptr->buffs_alloc = 0;
1140         privptr->p_buff_ccw=NULL;
1141         privptr->p_buff_read=NULL;
1142         privptr->p_buff_write=NULL;
1143         privptr->system_validate_comp=0;
1144         privptr->release_pend=0;
1145         /*      Remove any writes that were pending and reset all reads   */
1146         p_this_ccw=privptr->p_read_active_first;
1147         while (p_this_ccw!=NULL) {
1148                 p_this_ccw->header.length=0xffff;
1149                 p_this_ccw->header.opcode=0xff;
1150                 p_this_ccw->header.flag=0x00;
1151                 p_this_ccw=p_this_ccw->next;
1152         }
1153
1154         while (privptr->p_write_active_first!=NULL) {
1155                 p_this_ccw=privptr->p_write_active_first;
1156                 p_this_ccw->header.flag=CLAW_PENDING;
1157                 privptr->p_write_active_first=p_this_ccw->next;
1158                 p_this_ccw->next=privptr->p_write_free_chain;
1159                 privptr->p_write_free_chain=p_this_ccw;
1160                 ++privptr->write_free_count;
1161         }
1162         privptr->p_write_active_last=NULL;
1163         privptr->mtc_logical_link = -1;
1164         privptr->mtc_skipping = 1;
1165         privptr->mtc_offset=0;
1166
1167         if (((privptr->channel[READ].last_dstat |
1168                 privptr->channel[WRITE].last_dstat) &
1169                 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
1170                 printk(KERN_WARNING "%s: channel problems during close - "
1171                         "read: %02x -  write: %02x\n",
1172                 dev->name,
1173                 privptr->channel[READ].last_dstat,
1174                 privptr->channel[WRITE].last_dstat);
1175                  CLAW_DBF_TEXT(2,trace,"badclose");
1176         }
1177 #ifdef FUNCTRACE
1178         printk(KERN_INFO "%s:%s Exit on line %d\n",
1179                 dev->name,__FUNCTION__,__LINE__);
1180 #endif
1181         CLAW_DBF_TEXT(4,trace,"rlsexit");
1182         return 0;
1183 }      /* end of claw_release     */
1184
1185
1186
1187 /*-------------------------------------------------------------------*
1188 *       claw_write_retry                                             *
1189 *                                                                    *
1190 *--------------------------------------------------------------------*/
1191
1192 static void
1193 claw_write_retry ( struct chbk *p_ch )
1194 {
1195
1196         struct net_device  *dev=p_ch->ndev;
1197
1198
1199 #ifdef FUNCTRACE
1200         printk(KERN_INFO "%s:%s Enter\n",dev->name,__FUNCTION__);
1201         printk(KERN_INFO "claw: variable p_ch =\n");
1202         dumpit((char *) p_ch, sizeof(struct chbk));
1203 #endif
1204         CLAW_DBF_TEXT(4,trace,"w_retry");
1205         if (p_ch->claw_state == CLAW_STOP) {
1206 #ifdef FUNCTRACE
1207                 printk(KERN_INFO "%s:%s Exit on line %d\n",
1208                         dev->name,__FUNCTION__,__LINE__);
1209 #endif
1210                 return;
1211         }
1212 #ifdef DEBUGMSG
1213         printk( KERN_INFO "%s:%s  state-%02x\n" ,
1214                 dev->name,
1215                 __FUNCTION__,
1216                 p_ch->claw_state);
1217 #endif
1218         claw_strt_out_IO( dev );
1219 #ifdef FUNCTRACE
1220         printk(KERN_INFO "%s:%s Exit on line %d\n",
1221                 dev->name,__FUNCTION__,__LINE__);
1222 #endif
1223         CLAW_DBF_TEXT(4,trace,"rtry_xit");
1224         return;
1225 }      /* end of claw_write_retry      */
1226
1227
1228 /*-------------------------------------------------------------------*
1229 *       claw_write_next                                              *
1230 *                                                                    *
1231 *--------------------------------------------------------------------*/
1232
1233 static void
1234 claw_write_next ( struct chbk * p_ch )
1235 {
1236
1237         struct net_device  *dev;
1238         struct claw_privbk *privptr=NULL;
1239         struct sk_buff *pk_skb;
1240         int     rc;
1241
1242 #ifdef FUNCTRACE
1243         printk(KERN_INFO "%s:%s Enter  \n",p_ch->ndev->name,__FUNCTION__);
1244         printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1245         dumpit((char *) p_ch, sizeof(struct chbk));
1246 #endif
1247         CLAW_DBF_TEXT(4,trace,"claw_wrt");
1248         if (p_ch->claw_state == CLAW_STOP)
1249                 return;
1250         dev = (struct net_device *) p_ch->ndev;
1251         privptr = (struct claw_privbk *) dev->priv;
1252         claw_free_wrt_buf( dev );
1253         if ((privptr->write_free_count > 0) &&
1254             !skb_queue_empty(&p_ch->collect_queue)) {
1255                 pk_skb = claw_pack_skb(privptr);
1256                 while (pk_skb != NULL) {
1257                         rc = claw_hw_tx( pk_skb, dev,1);
1258                         if (privptr->write_free_count > 0) {
1259                                 pk_skb = claw_pack_skb(privptr);
1260                         } else
1261                                 pk_skb = NULL;
1262                 }
1263         }
1264         if (privptr->p_write_active_first!=NULL) {
1265                 claw_strt_out_IO(dev);
1266         }
1267
1268 #ifdef FUNCTRACE
1269         printk(KERN_INFO "%s:%s Exit on line %d\n",
1270                 dev->name,__FUNCTION__,__LINE__);
1271 #endif
1272         return;
1273 }      /* end of claw_write_next      */
1274
1275 /*-------------------------------------------------------------------*
1276 *                                                                    *
1277 *       claw_timer                                                   *
1278 *--------------------------------------------------------------------*/
1279
1280 static void
1281 claw_timer ( struct chbk * p_ch )
1282 {
1283 #ifdef FUNCTRACE
1284         printk(KERN_INFO "%s:%s Entry\n",p_ch->ndev->name,__FUNCTION__);
1285         printk(KERN_INFO "%s: variable p_ch =\n",p_ch->ndev->name);
1286         dumpit((char *) p_ch, sizeof(struct chbk));
1287 #endif
1288         CLAW_DBF_TEXT(4,trace,"timer");
1289         p_ch->flag |= CLAW_TIMER;
1290         wake_up(&p_ch->wait);
1291 #ifdef FUNCTRACE
1292         printk(KERN_INFO "%s:%s Exit on line %d\n",
1293                 p_ch->ndev->name,__FUNCTION__,__LINE__);
1294 #endif
1295         return;
1296 }      /* end of claw_timer  */
1297
1298
1299 /*
1300 *
1301 *       functions
1302 */
1303
1304
1305 /*-------------------------------------------------------------------*
1306 *                                                                    *
1307 *     pages_to_order_of_mag                                          *
1308 *                                                                    *
1309 *    takes a number of pages from 1 to 512 and returns the           *
1310 *    log(num_pages)/log(2) get_free_pages() needs a base 2 order     *
1311 *    of magnitude get_free_pages() has an upper order of 9           *
1312 *--------------------------------------------------------------------*/
1313
1314 static int inline
1315 pages_to_order_of_mag(int num_of_pages)
1316 {
1317         int     order_of_mag=1;         /* assume 2 pages */
1318         int     nump=2;
1319 #ifdef FUNCTRACE
1320         printk(KERN_INFO "%s Enter pages = %d \n",__FUNCTION__,num_of_pages);
1321 #endif
1322         CLAW_DBF_TEXT_(5,trace,"pages%d",num_of_pages);
1323         if (num_of_pages == 1)   {return 0; }  /* magnitude of 0 = 1 page */
1324         /* 512 pages = 2Meg on 4k page systems */
1325         if (num_of_pages >= 512) {return 9; }
1326         /* we have two or more pages order is at least 1 */
1327         for (nump=2 ;nump <= 512;nump*=2) {
1328           if (num_of_pages <= nump)
1329                   break;
1330           order_of_mag +=1;
1331         }
1332         if (order_of_mag > 9) { order_of_mag = 9; }  /* I know it's paranoid */
1333 #ifdef FUNCTRACE
1334         printk(KERN_INFO "%s Exit on line %d, order = %d\n",
1335         __FUNCTION__,__LINE__, order_of_mag);
1336 #endif
1337         CLAW_DBF_TEXT_(5,trace,"mag%d",order_of_mag);
1338         return order_of_mag;
1339 }
1340
1341 /*-------------------------------------------------------------------*
1342 *                                                                    *
1343 *     add_claw_reads                                                 *
1344 *                                                                    *
1345 *--------------------------------------------------------------------*/
1346 static int
1347 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1348         struct ccwbk* p_last)
1349 {
1350         struct claw_privbk *privptr;
1351         struct ccw1  temp_ccw;
1352         struct endccw * p_end;
1353 #ifdef IOTRACE
1354         struct ccwbk*  p_buf;
1355 #endif
1356 #ifdef FUNCTRACE
1357         printk(KERN_INFO "%s:%s Enter  \n",dev->name,__FUNCTION__);
1358 #endif
1359 #ifdef DEBUGMSG
1360         printk(KERN_INFO "dev\n");
1361         dumpit((char *) dev, sizeof(struct net_device));
1362         printk(KERN_INFO "p_first\n");
1363         dumpit((char *) p_first, sizeof(struct ccwbk));
1364         printk(KERN_INFO "p_last\n");
1365         dumpit((char *) p_last, sizeof(struct ccwbk));
1366 #endif
1367         CLAW_DBF_TEXT(4,trace,"addreads");
1368         privptr = dev->priv;
1369         p_end = privptr->p_end_ccw;
1370
1371         /* first CCW and last CCW contains a new set of read channel programs
1372         *       to apend the running channel programs
1373         */
1374         if ( p_first==NULL) {
1375 #ifdef FUNCTRACE
1376                 printk(KERN_INFO "%s:%s Exit on line %d\n",
1377                         dev->name,__FUNCTION__,__LINE__);
1378 #endif
1379                 CLAW_DBF_TEXT(4,trace,"addexit");
1380                 return 0;
1381         }
1382
1383         /* set up ending CCW sequence for this segment */
1384         if (p_end->read1) {
1385                 p_end->read1=0x00;    /*  second ending CCW is now active */
1386                 /*      reset ending CCWs and setup TIC CCWs              */
1387                 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1388                 p_end->read2_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1389                 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1390                 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1391                 p_end->read2_nop2.cda=0;
1392                 p_end->read2_nop2.count=1;
1393         }
1394         else {
1395                 p_end->read1=0x01;  /* first ending CCW is now active */
1396                 /*      reset ending CCWs and setup TIC CCWs          */
1397                 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1398                 p_end->read1_nop2.flags  = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1399                 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1400                 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1401                 p_end->read1_nop2.cda=0;
1402                 p_end->read1_nop2.count=1;
1403         }
1404
1405         if ( privptr-> p_read_active_first ==NULL ) {
1406 #ifdef DEBUGMSG
1407                 printk(KERN_INFO "%s:%s p_read_active_first == NULL \n",
1408                         dev->name,__FUNCTION__);
1409                 printk(KERN_INFO "%s:%s Read active first/last changed \n",
1410                         dev->name,__FUNCTION__);
1411 #endif
1412                 privptr-> p_read_active_first= p_first;  /*    set new first */
1413                 privptr-> p_read_active_last = p_last;   /*    set new last  */
1414         }
1415         else {
1416
1417 #ifdef DEBUGMSG
1418                 printk(KERN_INFO "%s:%s Read in progress \n",
1419                 dev->name,__FUNCTION__);
1420 #endif
1421                 /* set up TIC ccw  */
1422                 temp_ccw.cda= (__u32)__pa(&p_first->read);
1423                 temp_ccw.count=0;
1424                 temp_ccw.flags=0;
1425                 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1426
1427
1428                 if (p_end->read1) {
1429
1430                /* first set of CCW's is chained to the new read              */
1431                /* chain, so the second set is chained to the active chain.   */
1432                /* Therefore modify the second set to point to the new        */
1433                /* read chain set up TIC CCWs                                 */
1434                /* make sure we update the CCW so channel doesn't fetch it    */
1435                /* when it's only half done                                   */
1436                         memcpy( &p_end->read2_nop2, &temp_ccw ,
1437                                 sizeof(struct ccw1));
1438                         privptr->p_read_active_last->r_TIC_1.cda=
1439                                 (__u32)__pa(&p_first->read);
1440                         privptr->p_read_active_last->r_TIC_2.cda=
1441                                 (__u32)__pa(&p_first->read);
1442                 }
1443                 else {
1444                         /* make sure we update the CCW so channel doesn't   */
1445                         /* fetch it when it is only half done               */
1446                         memcpy( &p_end->read1_nop2, &temp_ccw ,
1447                                 sizeof(struct ccw1));
1448                         privptr->p_read_active_last->r_TIC_1.cda=
1449                                 (__u32)__pa(&p_first->read);
1450                         privptr->p_read_active_last->r_TIC_2.cda=
1451                                 (__u32)__pa(&p_first->read);
1452                 }
1453                 /*      chain in new set of blocks                              */
1454                 privptr->p_read_active_last->next = p_first;
1455                 privptr->p_read_active_last=p_last;
1456         } /* end of if ( privptr-> p_read_active_first ==NULL)  */
1457 #ifdef IOTRACE
1458         printk(KERN_INFO "%s:%s  dump p_last CCW BK \n",dev->name,__FUNCTION__);
1459         dumpit((char *)p_last, sizeof(struct ccwbk));
1460         printk(KERN_INFO "%s:%s  dump p_end CCW BK \n",dev->name,__FUNCTION__);
1461         dumpit((char *)p_end, sizeof(struct endccw));
1462
1463         printk(KERN_INFO "%s:%s dump p_first CCW BK \n",dev->name,__FUNCTION__);
1464         dumpit((char *)p_first, sizeof(struct ccwbk));
1465         printk(KERN_INFO "%s:%s Dump Active CCW chain \n",
1466                 dev->name,__FUNCTION__);
1467         p_buf=privptr->p_read_active_first;
1468         while (p_buf!=NULL) {
1469                 dumpit((char *)p_buf, sizeof(struct ccwbk));
1470                 p_buf=p_buf->next;
1471         }
1472 #endif
1473 #ifdef FUNCTRACE
1474         printk(KERN_INFO "%s:%s Exit on line %d\n",
1475                 dev->name,__FUNCTION__,__LINE__);
1476 #endif
1477         CLAW_DBF_TEXT(4,trace,"addexit");
1478         return 0;
1479 }    /*     end of add_claw_reads   */
1480
1481 /*-------------------------------------------------------------------*
1482  *   ccw_check_return_code                                           *
1483  *                                                                   *
1484  *-------------------------------------------------------------------*/
1485
1486 static void inline
1487 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1488 {
1489 #ifdef FUNCTRACE
1490         printk(KERN_INFO "%s: %s() > enter  \n",
1491                 cdev->dev.bus_id,__FUNCTION__);
1492 #endif
1493         CLAW_DBF_TEXT(4,trace,"ccwret");
1494 #ifdef DEBUGMSG
1495         printk(KERN_INFO "variable cdev =\n");
1496         dumpit((char *) cdev, sizeof(struct ccw_device));
1497         printk(KERN_INFO "variable return_code = %d\n",return_code);
1498 #endif
1499         if (return_code != 0) {
1500                 switch (return_code) {
1501                         case -EBUSY:
1502                                 printk(KERN_INFO "%s: Busy !\n",
1503                                         cdev->dev.bus_id);
1504                                 break;
1505                         case -ENODEV:
1506                                 printk(KERN_EMERG "%s: Missing device called "
1507                                         "for IO ENODEV\n", cdev->dev.bus_id);
1508                                 break;
1509                         case -EIO:
1510                                 printk(KERN_EMERG "%s: Status pending... EIO \n",
1511                                         cdev->dev.bus_id);
1512                                 break;
1513                         case -EINVAL:
1514                                 printk(KERN_EMERG "%s: Invalid Dev State EINVAL \n",
1515                                         cdev->dev.bus_id);
1516                                 break;
1517                         default:
1518                                 printk(KERN_EMERG "%s: Unknown error in "
1519                                  "Do_IO %d\n",cdev->dev.bus_id, return_code);
1520                 }
1521         }
1522 #ifdef FUNCTRACE
1523         printk(KERN_INFO "%s: %s() > exit on line %d\n",
1524                 cdev->dev.bus_id,__FUNCTION__,__LINE__);
1525 #endif
1526         CLAW_DBF_TEXT(4,trace,"ccwret");
1527 }    /*    end of ccw_check_return_code   */
1528
1529 /*-------------------------------------------------------------------*
1530 *       ccw_check_unit_check                                         *
1531 *--------------------------------------------------------------------*/
1532
1533 static void inline
1534 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1535 {
1536         struct net_device *dev = p_ch->ndev;
1537
1538 #ifdef FUNCTRACE
1539         printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
1540 #endif
1541 #ifdef DEBUGMSG
1542         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1543         dumpit((char *)dev, sizeof(struct net_device));
1544         printk(KERN_INFO "%s: variable sense =\n",dev->name);
1545         dumpit((char *)&sense, 2);
1546 #endif
1547         CLAW_DBF_TEXT(4,trace,"unitchek");
1548
1549         printk(KERN_INFO "%s: Unit Check with sense byte:0x%04x\n",
1550                 dev->name, sense);
1551
1552         if (sense & 0x40) {
1553                 if (sense & 0x01) {
1554                         printk(KERN_WARNING "%s: Interface disconnect or "
1555                                 "Selective reset "
1556                                 "occurred (remote side)\n", dev->name);
1557                 }
1558                 else {
1559                         printk(KERN_WARNING "%s: System reset occured"
1560                                 " (remote side)\n", dev->name);
1561                 }
1562         }
1563         else if (sense & 0x20) {
1564                 if (sense & 0x04) {
1565                         printk(KERN_WARNING "%s: Data-streaming "
1566                                 "timeout)\n", dev->name);
1567                 }
1568                 else  {
1569                         printk(KERN_WARNING "%s: Data-transfer parity"
1570                                 " error\n", dev->name);
1571                 }
1572         }
1573         else if (sense & 0x10) {
1574                 if (sense & 0x20) {
1575                         printk(KERN_WARNING "%s: Hardware malfunction "
1576                                 "(remote side)\n", dev->name);
1577                 }
1578                 else {
1579                         printk(KERN_WARNING "%s: read-data parity error "
1580                                 "(remote side)\n", dev->name);
1581                 }
1582         }
1583
1584 #ifdef FUNCTRACE
1585         printk(KERN_INFO "%s: %s() exit on line %d\n",
1586                 dev->name,__FUNCTION__,__LINE__);
1587 #endif
1588 }   /*    end of ccw_check_unit_check    */
1589
1590
1591
1592 /*-------------------------------------------------------------------*
1593 * Dump buffer format                                                 *
1594 *                                                                    *
1595 *--------------------------------------------------------------------*/
1596 #ifdef DEBUG
1597 static void
1598 dumpit(char* buf, int len)
1599 {
1600
1601         __u32      ct, sw, rm, dup;
1602         char       *ptr, *rptr;
1603         char       tbuf[82], tdup[82];
1604 #if (CONFIG_64BIT)
1605         char       addr[22];
1606 #else
1607         char       addr[12];
1608 #endif
1609         char       boff[12];
1610         char       bhex[82], duphex[82];
1611         char       basc[40];
1612
1613         sw  = 0;
1614         rptr =ptr=buf;
1615         rm  = 16;
1616         duphex[0]  = 0x00;
1617         dup = 0;
1618         for ( ct=0; ct < len; ct++, ptr++, rptr++ )  {
1619                 if (sw == 0) {
1620 #if (CONFIG_64BIT)
1621                         sprintf(addr, "%16.16lX",(unsigned long)rptr);
1622 #else
1623                         sprintf(addr, "%8.8X",(__u32)rptr);
1624 #endif
1625                         sprintf(boff, "%4.4X", (__u32)ct);
1626                         bhex[0] = '\0';
1627                         basc[0] = '\0';
1628                 }
1629                 if ((sw == 4) || (sw == 12)) {
1630                         strcat(bhex, " ");
1631                 }
1632                 if (sw == 8) {
1633                         strcat(bhex, "  ");
1634                 }
1635 #if (CONFIG_64BIT)
1636                 sprintf(tbuf,"%2.2lX", (unsigned long)*ptr);
1637 #else
1638                 sprintf(tbuf,"%2.2X", (__u32)*ptr);
1639 #endif
1640                 tbuf[2] = '\0';
1641                 strcat(bhex, tbuf);
1642                 if ((0!=isprint(*ptr)) && (*ptr >= 0x20)) {
1643                         basc[sw] = *ptr;
1644                 }
1645                 else {
1646                         basc[sw] = '.';
1647                 }
1648                 basc[sw+1] = '\0';
1649                 sw++;
1650                 rm--;
1651                 if (sw==16) {
1652                         if ((strcmp(duphex, bhex)) !=0) {
1653                                 if (dup !=0) {
1654                                         sprintf(tdup,"Duplicate as above to"
1655                                                 " %s", addr);
1656                                         printk( KERN_INFO "                 "
1657                                                 "   --- %s ---\n",tdup);
1658                                 }
1659                                 printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1660                                          addr, boff, bhex, basc);
1661                                 dup = 0;
1662                                 strcpy(duphex, bhex);
1663                         }
1664                         else {
1665                                 dup++;
1666                         }
1667                         sw = 0;
1668                         rm = 16;
1669                 }
1670         }  /* endfor */
1671
1672         if (sw != 0) {
1673                 for ( ; rm > 0; rm--, sw++ ) {
1674                         if ((sw==4) || (sw==12)) strcat(bhex, " ");
1675                         if (sw==8)               strcat(bhex, "  ");
1676                         strcat(bhex, "  ");
1677                         strcat(basc, " ");
1678                 }
1679                 if (dup !=0) {
1680                         sprintf(tdup,"Duplicate as above to %s", addr);
1681                         printk( KERN_INFO "                    --- %s ---\n",
1682                                 tdup);
1683                 }
1684                 printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1685                         addr, boff, bhex, basc);
1686         }
1687         else {
1688                 if (dup >=1) {
1689                         sprintf(tdup,"Duplicate as above to %s", addr);
1690                         printk( KERN_INFO "                    --- %s ---\n",
1691                                 tdup);
1692                 }
1693                 if (dup !=0) {
1694                         printk( KERN_INFO "   %s (+%s) : %s  [%s]\n",
1695                                 addr, boff, bhex, basc);
1696                 }
1697         }
1698         return;
1699
1700 }   /*   end of dumpit  */
1701 #endif
1702
1703 /*-------------------------------------------------------------------*
1704 *               find_link                                            *
1705 *--------------------------------------------------------------------*/
1706 static int
1707 find_link(struct net_device *dev, char *host_name, char *ws_name )
1708 {
1709         struct claw_privbk *privptr;
1710         struct claw_env *p_env;
1711         int    rc=0;
1712
1713 #ifdef FUNCTRACE
1714         printk(KERN_INFO "%s:%s > enter  \n",dev->name,__FUNCTION__);
1715 #endif
1716         CLAW_DBF_TEXT(2,setup,"findlink");
1717 #ifdef DEBUGMSG
1718         printk(KERN_INFO "%s: variable dev = \n",dev->name);
1719         dumpit((char *) dev, sizeof(struct net_device));
1720         printk(KERN_INFO "%s: variable host_name = %s\n",dev->name, host_name);
1721         printk(KERN_INFO "%s: variable ws_name = %s\n",dev->name, ws_name);
1722 #endif
1723         privptr=dev->priv;
1724         p_env=privptr->p_env;
1725         switch (p_env->packing)
1726         {
1727                 case  PACKING_ASK:
1728                         if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1729                             (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1730                              rc = EINVAL;
1731                         break;
1732                 case  DO_PACKED:
1733                 case  PACK_SEND:
1734                         if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1735                             (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1736                                 rc = EINVAL;
1737                         break;
1738                 default:
1739                         if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1740                             (memcmp(p_env->api_type , ws_name, 8)!=0))
1741                                 rc = EINVAL;
1742                         break;
1743         }
1744
1745 #ifdef FUNCTRACE
1746         printk(KERN_INFO "%s:%s Exit on line %d\n",
1747                 dev->name,__FUNCTION__,__LINE__);
1748 #endif
1749         return 0;
1750 }    /*    end of find_link    */
1751
1752 /*-------------------------------------------------------------------*
1753  *   claw_hw_tx                                                      *
1754  *                                                                   *
1755  *                                                                   *
1756  *-------------------------------------------------------------------*/
1757
1758 static int
1759 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1760 {
1761         int                             rc=0;
1762         struct claw_privbk              *privptr;
1763         struct ccwbk           *p_this_ccw;
1764         struct ccwbk           *p_first_ccw;
1765         struct ccwbk           *p_last_ccw;
1766         __u32                           numBuffers;
1767         signed long                     len_of_data;
1768         unsigned long                   bytesInThisBuffer;
1769         unsigned char                   *pDataAddress;
1770         struct endccw                   *pEnd;
1771         struct ccw1                     tempCCW;
1772         struct chbk                     *p_ch;
1773         struct claw_env                 *p_env;
1774         int                             lock;
1775         struct clawph                   *pk_head;
1776         struct chbk                     *ch;
1777 #ifdef IOTRACE
1778         struct ccwbk                   *p_buf;
1779 #endif
1780 #ifdef FUNCTRACE
1781         printk(KERN_INFO "%s: %s() > enter\n",dev->name,__FUNCTION__);
1782 #endif
1783         CLAW_DBF_TEXT(4,trace,"hw_tx");
1784 #ifdef DEBUGMSG
1785         printk(KERN_INFO "%s: variable dev skb =\n",dev->name);
1786         dumpit((char *) skb, sizeof(struct sk_buff));
1787         printk(KERN_INFO "%s: variable dev =\n",dev->name);
1788         dumpit((char *) dev, sizeof(struct net_device));
1789         printk(KERN_INFO "%s: variable linkid = %ld\n",dev->name,linkid);
1790 #endif
1791         privptr = (struct claw_privbk *) (dev->priv);
1792         p_ch=(struct chbk *)&privptr->channel[WRITE];
1793         p_env =privptr->p_env;
1794 #ifdef IOTRACE
1795         printk(KERN_INFO "%s: %s() dump sk_buff  \n",dev->name,__FUNCTION__);
1796         dumpit((char *)skb ,sizeof(struct sk_buff));
1797 #endif
1798         claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1799         /*  scan the write queue to free any completed write packets   */
1800         p_first_ccw=NULL;
1801         p_last_ccw=NULL;
1802         if ((p_env->packing >= PACK_SEND) &&
1803             (skb->cb[1] != 'P')) {
1804                 skb_push(skb,sizeof(struct clawph));
1805                 pk_head=(struct clawph *)skb->data;
1806                 pk_head->len=skb->len-sizeof(struct clawph);
1807                 if (pk_head->len%4)  {
1808                         pk_head->len+= 4-(pk_head->len%4);
1809                         skb_pad(skb,4-(pk_head->len%4));
1810                         skb_put(skb,4-(pk_head->len%4));
1811                 }
1812                 if (p_env->packing == DO_PACKED)
1813                         pk_head->link_num = linkid;
1814                 else
1815                         pk_head->link_num = 0;
1816                 pk_head->flag = 0x00;
1817                 skb_pad(skb,4);
1818                 skb->cb[1] = 'P';
1819         }
1820         if (linkid == 0) {
1821                 if (claw_check_busy(dev)) {
1822                         if (privptr->write_free_count!=0) {
1823                                 claw_clear_busy(dev);
1824                         }
1825                         else {
1826                                 claw_strt_out_IO(dev );
1827                                 claw_free_wrt_buf( dev );
1828                                 if (privptr->write_free_count==0) {
1829 #ifdef IOTRACE
1830                                         printk(KERN_INFO "%s: "
1831                                            "(claw_check_busy) no free write "
1832                                            "buffers\n", dev->name);
1833 #endif
1834                                         ch = &privptr->channel[WRITE];
1835                                         atomic_inc(&skb->users);
1836                                         skb_queue_tail(&ch->collect_queue, skb);
1837                                         goto Done;
1838                                 }
1839                                 else {
1840                                         claw_clear_busy(dev);
1841                                 }
1842                         }
1843                 }
1844                 /*  tx lock  */
1845                 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1846 #ifdef DEBUGMSG
1847                         printk(KERN_INFO "%s:  busy  (claw_test_and_setbit_"
1848                                 "busy)\n", dev->name);
1849 #endif
1850                         ch = &privptr->channel[WRITE];
1851                         atomic_inc(&skb->users);
1852                         skb_queue_tail(&ch->collect_queue, skb);
1853                         claw_strt_out_IO(dev );
1854                         rc=-EBUSY;
1855                         goto Done2;
1856                 }
1857         }
1858         /*      See how many write buffers are required to hold this data */
1859         numBuffers= ( skb->len + privptr->p_env->write_size - 1) /
1860                         ( privptr->p_env->write_size);
1861
1862         /*      If that number of buffers isn't available, give up for now */
1863         if (privptr->write_free_count < numBuffers ||
1864             privptr->p_write_free_chain == NULL ) {
1865
1866                 claw_setbit_busy(TB_NOBUFFER,dev);
1867
1868 #ifdef DEBUGMSG
1869                 printk(KERN_INFO "%s:  busy  (claw_setbit_busy"
1870                         "(TB_NOBUFFER))\n", dev->name);
1871                 printk(KERN_INFO "       free_count: %d, numBuffers : %d\n",
1872                         (int)privptr->write_free_count,(int) numBuffers );
1873 #endif
1874                 ch = &privptr->channel[WRITE];
1875                 atomic_inc(&skb->users);
1876                 skb_queue_tail(&ch->collect_queue, skb);
1877                 CLAW_DBF_TEXT(2,trace,"clawbusy");
1878                 goto Done2;
1879         }
1880         pDataAddress=skb->data;
1881         len_of_data=skb->len;
1882
1883         while (len_of_data > 0) {
1884 #ifdef DEBUGMSG
1885                 printk(KERN_INFO "%s: %s() length-of-data is %ld \n",
1886                         dev->name ,__FUNCTION__,len_of_data);
1887                 dumpit((char *)pDataAddress ,64);
1888 #endif
1889                 p_this_ccw=privptr->p_write_free_chain;  /* get a block */
1890                 if (p_this_ccw == NULL) { /* lost the race */
1891                         ch = &privptr->channel[WRITE];
1892                         atomic_inc(&skb->users);
1893                         skb_queue_tail(&ch->collect_queue, skb);
1894                         goto Done2;
1895                 }
1896                 privptr->p_write_free_chain=p_this_ccw->next;
1897                 p_this_ccw->next=NULL;
1898                 --privptr->write_free_count; /* -1 */
1899                 bytesInThisBuffer=len_of_data;
1900                 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1901                 len_of_data-=bytesInThisBuffer;
1902                 pDataAddress+=(unsigned long)bytesInThisBuffer;
1903                 /*      setup write CCW         */
1904                 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1905                 if (len_of_data>0) {
1906                         p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1907                 }
1908                 p_this_ccw->write.count=bytesInThisBuffer;
1909                 /*      now add to end of this chain    */
1910                 if (p_first_ccw==NULL)    {
1911                         p_first_ccw=p_this_ccw;
1912                 }
1913                 if (p_last_ccw!=NULL) {
1914                         p_last_ccw->next=p_this_ccw;
1915                         /*      set up TIC ccws         */
1916                         p_last_ccw->w_TIC_1.cda=
1917                                 (__u32)__pa(&p_this_ccw->write);
1918                 }
1919                 p_last_ccw=p_this_ccw;      /* save new last block */
1920 #ifdef IOTRACE
1921                 printk(KERN_INFO "%s: %s() > CCW and Buffer %ld bytes long \n",
1922                         dev->name,__FUNCTION__,bytesInThisBuffer);
1923                 dumpit((char *)p_this_ccw, sizeof(struct ccwbk));
1924                 dumpit((char *)p_this_ccw->p_buffer, 64);
1925 #endif
1926         }
1927
1928         /*      FirstCCW and LastCCW now contain a new set of write channel
1929         *       programs to append to the running channel program
1930         */
1931
1932         if (p_first_ccw!=NULL) {
1933                 /*      setup ending ccw sequence for this segment              */
1934                 pEnd=privptr->p_end_ccw;
1935                 if (pEnd->write1) {
1936                         pEnd->write1=0x00;   /* second end ccw is now active */
1937                         /*      set up Tic CCWs         */
1938                         p_last_ccw->w_TIC_1.cda=
1939                                 (__u32)__pa(&pEnd->write2_nop1);
1940                         pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1941                         pEnd->write2_nop2.flags    =
1942                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1943                         pEnd->write2_nop2.cda=0;
1944                         pEnd->write2_nop2.count=1;
1945                 }
1946                 else {  /*  end of if (pEnd->write1)*/
1947                         pEnd->write1=0x01;   /* first end ccw is now active */
1948                         /*      set up Tic CCWs         */
1949                         p_last_ccw->w_TIC_1.cda=
1950                                 (__u32)__pa(&pEnd->write1_nop1);
1951                         pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1952                         pEnd->write1_nop2.flags    =
1953                                 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1954                         pEnd->write1_nop2.cda=0;
1955                         pEnd->write1_nop2.count=1;
1956                 }  /* end if if (pEnd->write1) */
1957
1958
1959                 if (privptr->p_write_active_first==NULL ) {
1960                         privptr->p_write_active_first=p_first_ccw;
1961                         privptr->p_write_active_last=p_last_ccw;
1962                 }
1963                 else {
1964
1965                         /*      set up Tic CCWs         */
1966
1967                         tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1968                         tempCCW.count=0;
1969                         tempCCW.flags=0;
1970                         tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1971
1972                         if (pEnd->write1) {
1973
1974                  /*
1975                  * first set of ending CCW's is chained to the new write
1976                  * chain, so the second set is chained to the active chain
1977                  * Therefore modify the second set to point the new write chain.
1978                  * make sure we update the CCW atomically
1979                  * so channel does not fetch it when it's only half done
1980                  */
1981                                 memcpy( &pEnd->write2_nop2, &tempCCW ,
1982                                         sizeof(struct ccw1));
1983                                 privptr->p_write_active_last->w_TIC_1.cda=
1984                                         (__u32)__pa(&p_first_ccw->write);
1985                         }
1986                         else {
1987
1988                         /*make sure we update the CCW atomically
1989                          *so channel does not fetch it when it's only half done
1990                          */
1991                                 memcpy(&pEnd->write1_nop2, &tempCCW ,
1992                                         sizeof(struct ccw1));
1993                                 privptr->p_write_active_last->w_TIC_1.cda=
1994                                         (__u32)__pa(&p_first_ccw->write);
1995
1996                         } /* end if if (pEnd->write1) */
1997
1998                         privptr->p_write_active_last->next=p_first_ccw;
1999                         privptr->p_write_active_last=p_last_ccw;
2000                 }
2001
2002         } /* endif (p_first_ccw!=NULL)  */
2003
2004
2005 #ifdef IOTRACE
2006         printk(KERN_INFO "%s: %s() >  Dump Active CCW chain \n",
2007                 dev->name,__FUNCTION__);
2008         p_buf=privptr->p_write_active_first;
2009         while (p_buf!=NULL) {
2010                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2011                 p_buf=p_buf->next;
2012         }
2013         p_buf=(struct ccwbk*)privptr->p_end_ccw;
2014         dumpit((char *)p_buf, sizeof(struct endccw));
2015 #endif
2016         dev_kfree_skb_any(skb);
2017         if (linkid==0) {
2018                 lock=LOCK_NO;
2019         }
2020         else  {
2021                 lock=LOCK_YES;
2022         }
2023         claw_strt_out_IO(dev );
2024         /*      if write free count is zero , set NOBUFFER       */
2025 #ifdef DEBUGMSG
2026         printk(KERN_INFO "%s: %s() > free_count is %d\n",
2027                 dev->name,__FUNCTION__,
2028                 (int) privptr->write_free_count );
2029 #endif
2030         if (privptr->write_free_count==0) {
2031                 claw_setbit_busy(TB_NOBUFFER,dev);
2032         }
2033 Done2:
2034         claw_clearbit_busy(TB_TX,dev);
2035 Done:
2036 #ifdef FUNCTRACE
2037         printk(KERN_INFO "%s: %s() > exit on line %d, rc = %d \n",
2038                 dev->name,__FUNCTION__,__LINE__, rc);
2039 #endif
2040         return(rc);
2041 }    /*    end of claw_hw_tx    */
2042
2043 /*-------------------------------------------------------------------*
2044 *                                                                    *
2045 *     init_ccw_bk                                                    *
2046 *                                                                    *
2047 *--------------------------------------------------------------------*/
2048
2049 static int
2050 init_ccw_bk(struct net_device *dev)
2051 {
2052
2053         __u32   ccw_blocks_required;
2054         __u32   ccw_blocks_perpage;
2055         __u32   ccw_pages_required;
2056         __u32   claw_reads_perpage=1;
2057         __u32   claw_read_pages;
2058         __u32   claw_writes_perpage=1;
2059         __u32   claw_write_pages;
2060         void    *p_buff=NULL;
2061         struct ccwbk*p_free_chain;
2062         struct ccwbk*p_buf;
2063         struct ccwbk*p_last_CCWB;
2064         struct ccwbk*p_first_CCWB;
2065         struct endccw *p_endccw=NULL;
2066         addr_t  real_address;
2067         struct claw_privbk *privptr=dev->priv;
2068         struct clawh *pClawH=NULL;
2069         addr_t   real_TIC_address;
2070         int i,j;
2071 #ifdef FUNCTRACE
2072         printk(KERN_INFO "%s: %s() enter  \n",dev->name,__FUNCTION__);
2073 #endif
2074         CLAW_DBF_TEXT(4,trace,"init_ccw");
2075 #ifdef DEBUGMSG
2076         printk(KERN_INFO "%s: variable dev =\n",dev->name);
2077         dumpit((char *) dev, sizeof(struct net_device));
2078 #endif
2079
2080         /*  initialize  statistics field */
2081         privptr->active_link_ID=0;
2082         /*  initialize  ccwbk pointers  */
2083         privptr->p_write_free_chain=NULL;   /* pointer to free ccw chain*/
2084         privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
2085         privptr->p_write_active_last=NULL;  /* pointer to the last write ccw*/
2086         privptr->p_read_active_first=NULL;  /* pointer to the first read ccw*/
2087         privptr->p_read_active_last=NULL;   /* pointer to the last read ccw */
2088         privptr->p_end_ccw=NULL;            /* pointer to ending ccw        */
2089         privptr->p_claw_signal_blk=NULL;    /* pointer to signal block      */
2090         privptr->buffs_alloc = 0;
2091         memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
2092         memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
2093         /*  initialize  free write ccwbk counter  */
2094         privptr->write_free_count=0;  /* number of free bufs on write chain */
2095         p_last_CCWB = NULL;
2096         p_first_CCWB= NULL;
2097         /*
2098         *  We need 1 CCW block for each read buffer, 1 for each
2099         *  write buffer, plus 1 for ClawSignalBlock
2100         */
2101         ccw_blocks_required =
2102                 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
2103 #ifdef DEBUGMSG
2104         printk(KERN_INFO "%s: %s() "
2105                 "ccw_blocks_required=%d\n",
2106                 dev->name,__FUNCTION__,
2107                 ccw_blocks_required);
2108         printk(KERN_INFO "%s: %s() "
2109                 "PAGE_SIZE=0x%x\n",
2110                 dev->name,__FUNCTION__,
2111                 (unsigned int)PAGE_SIZE);
2112         printk(KERN_INFO "%s: %s() > "
2113                 "PAGE_MASK=0x%x\n",
2114                 dev->name,__FUNCTION__,
2115                 (unsigned int)PAGE_MASK);
2116 #endif
2117         /*
2118         * compute number of CCW blocks that will fit in a page
2119         */
2120         ccw_blocks_perpage= PAGE_SIZE /  CCWBK_SIZE;
2121         ccw_pages_required=
2122                 (ccw_blocks_required+ccw_blocks_perpage -1) /
2123                          ccw_blocks_perpage;
2124
2125 #ifdef DEBUGMSG
2126         printk(KERN_INFO "%s: %s() > ccw_blocks_perpage=%d\n",
2127                 dev->name,__FUNCTION__,
2128                 ccw_blocks_perpage);
2129         printk(KERN_INFO "%s: %s() > ccw_pages_required=%d\n",
2130                 dev->name,__FUNCTION__,
2131                 ccw_pages_required);
2132 #endif
2133         /*
2134          *  read and write sizes are set by 2 constants in claw.h
2135          *  4k and 32k.  Unpacked values other than 4k are not going to
2136          * provide good performance. With packing buffers support 32k
2137          * buffers are used.
2138          */
2139         if (privptr->p_env->read_size < PAGE_SIZE) {
2140             claw_reads_perpage= PAGE_SIZE / privptr->p_env->read_size;
2141             claw_read_pages= (privptr->p_env->read_buffers +
2142                 claw_reads_perpage -1) / claw_reads_perpage;
2143          }
2144          else {       /* > or equal  */
2145             privptr->p_buff_pages_perread=
2146                 (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
2147             claw_read_pages=
2148                 privptr->p_env->read_buffers * privptr->p_buff_pages_perread;
2149          }
2150         if (privptr->p_env->write_size < PAGE_SIZE) {
2151             claw_writes_perpage=
2152                 PAGE_SIZE / privptr->p_env->write_size;
2153             claw_write_pages=
2154                 (privptr->p_env->write_buffers + claw_writes_perpage -1) /
2155                         claw_writes_perpage;
2156
2157         }
2158         else {      /* >  or equal  */
2159             privptr->p_buff_pages_perwrite=
2160                  (privptr->p_env->read_size + PAGE_SIZE - 1) / PAGE_SIZE;
2161             claw_write_pages=
2162                 privptr->p_env->write_buffers * privptr->p_buff_pages_perwrite;
2163         }
2164 #ifdef DEBUGMSG
2165         if (privptr->p_env->read_size < PAGE_SIZE) {
2166             printk(KERN_INFO "%s: %s() reads_perpage=%d\n",
2167                 dev->name,__FUNCTION__,
2168                 claw_reads_perpage);
2169         }
2170         else {
2171             printk(KERN_INFO "%s: %s() pages_perread=%d\n",
2172                 dev->name,__FUNCTION__,
2173                 privptr->p_buff_pages_perread);
2174         }
2175         printk(KERN_INFO "%s: %s() read_pages=%d\n",
2176                 dev->name,__FUNCTION__,
2177                 claw_read_pages);
2178         if (privptr->p_env->write_size < PAGE_SIZE) {
2179             printk(KERN_INFO "%s: %s() writes_perpage=%d\n",
2180                 dev->name,__FUNCTION__,
2181                 claw_writes_perpage);
2182         }
2183         else {
2184             printk(KERN_INFO "%s: %s() pages_perwrite=%d\n",
2185                 dev->name,__FUNCTION__,
2186                 privptr->p_buff_pages_perwrite);
2187         }
2188         printk(KERN_INFO "%s: %s() write_pages=%d\n",
2189                 dev->name,__FUNCTION__,
2190                 claw_write_pages);
2191 #endif
2192
2193
2194         /*
2195         *               allocate ccw_pages_required
2196         */
2197         if (privptr->p_buff_ccw==NULL) {
2198                 privptr->p_buff_ccw=
2199                         (void *)__get_free_pages(__GFP_DMA,
2200                         (int)pages_to_order_of_mag(ccw_pages_required ));
2201                 if (privptr->p_buff_ccw==NULL) {
2202                         printk(KERN_INFO "%s: %s()  "
2203                                 "__get_free_pages for CCWs failed : "
2204                                 "pages is %d\n",
2205                                 dev->name,__FUNCTION__,
2206                                 ccw_pages_required );
2207 #ifdef FUNCTRACE
2208                         printk(KERN_INFO "%s: %s() > "
2209                                 "exit on line %d, rc = ENOMEM\n",
2210                                 dev->name,__FUNCTION__,
2211                                  __LINE__);
2212 #endif
2213                         return -ENOMEM;
2214                 }
2215                 privptr->p_buff_ccw_num=ccw_pages_required;
2216         }
2217         memset(privptr->p_buff_ccw, 0x00,
2218                 privptr->p_buff_ccw_num * PAGE_SIZE);
2219
2220         /*
2221         *               obtain ending ccw block address
2222         *
2223         */
2224         privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
2225         real_address  = (__u32)__pa(privptr->p_end_ccw);
2226         /*                              Initialize ending CCW block       */
2227 #ifdef DEBUGMSG
2228         printk(KERN_INFO "%s: %s() begin initialize ending CCW blocks\n",
2229                 dev->name,__FUNCTION__);
2230 #endif
2231
2232         p_endccw=privptr->p_end_ccw;
2233         p_endccw->real=real_address;
2234         p_endccw->write1=0x00;
2235         p_endccw->read1=0x00;
2236
2237         /*      write1_nop1                                     */
2238         p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2239         p_endccw->write1_nop1.flags       = CCW_FLAG_SLI | CCW_FLAG_CC;
2240         p_endccw->write1_nop1.count       = 1;
2241         p_endccw->write1_nop1.cda         = 0;
2242
2243         /*      write1_nop2                                     */
2244         p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2245         p_endccw->write1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2246         p_endccw->write1_nop2.count      = 1;
2247         p_endccw->write1_nop2.cda        = 0;
2248
2249         /*      write2_nop1                                     */
2250         p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2251         p_endccw->write2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2252         p_endccw->write2_nop1.count        = 1;
2253         p_endccw->write2_nop1.cda          = 0;
2254
2255         /*      write2_nop2                                     */
2256         p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2257         p_endccw->write2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2258         p_endccw->write2_nop2.count        = 1;
2259         p_endccw->write2_nop2.cda          = 0;
2260
2261         /*      read1_nop1                                      */
2262         p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2263         p_endccw->read1_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2264         p_endccw->read1_nop1.count        = 1;
2265         p_endccw->read1_nop1.cda          = 0;
2266
2267         /*      read1_nop2                                      */
2268         p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2269         p_endccw->read1_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2270         p_endccw->read1_nop2.count        = 1;
2271         p_endccw->read1_nop2.cda          = 0;
2272
2273         /*      read2_nop1                                      */
2274         p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
2275         p_endccw->read2_nop1.flags        = CCW_FLAG_SLI | CCW_FLAG_CC;
2276         p_endccw->read2_nop1.count        = 1;
2277         p_endccw->read2_nop1.cda          = 0;
2278
2279         /*      read2_nop2                                      */
2280         p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
2281         p_endccw->read2_nop2.flags        = CCW_FLAG_SLI | CCW_FLAG_SKIP;
2282         p_endccw->read2_nop2.count        = 1;
2283         p_endccw->read2_nop2.cda          = 0;
2284
2285 #ifdef IOTRACE
2286         printk(KERN_INFO "%s: %s() dump claw ending CCW BK \n",
2287                 dev->name,__FUNCTION__);
2288         dumpit((char *)p_endccw, sizeof(struct endccw));
2289 #endif
2290
2291         /*
2292         *                               Build a chain of CCWs
2293         *
2294         */
2295
2296 #ifdef DEBUGMSG
2297         printk(KERN_INFO "%s: %s()  Begin build a chain of CCW buffer \n",
2298                 dev->name,__FUNCTION__);
2299 #endif
2300         p_buff=privptr->p_buff_ccw;
2301
2302         p_free_chain=NULL;
2303         for (i=0 ; i < ccw_pages_required; i++ ) {
2304                 real_address  = (__u32)__pa(p_buff);
2305                 p_buf=p_buff;
2306                 for (j=0 ; j < ccw_blocks_perpage ; j++) {
2307                         p_buf->next  = p_free_chain;
2308                         p_free_chain = p_buf;
2309                         p_buf->real=(__u32)__pa(p_buf);
2310                         ++p_buf;
2311                 }
2312                 p_buff+=PAGE_SIZE;
2313         }
2314 #ifdef DEBUGMSG
2315         printk(KERN_INFO "%s: %s() "
2316                 "End build a chain of CCW buffer \n",
2317                         dev->name,__FUNCTION__);
2318         p_buf=p_free_chain;
2319         while (p_buf!=NULL) {
2320                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2321                 p_buf=p_buf->next;
2322         }
2323 #endif
2324
2325         /*
2326         *                               Initialize ClawSignalBlock
2327         *
2328         */
2329 #ifdef DEBUGMSG
2330         printk(KERN_INFO "%s: %s() "
2331                 "Begin initialize ClawSignalBlock \n",
2332                 dev->name,__FUNCTION__);
2333 #endif
2334         if (privptr->p_claw_signal_blk==NULL) {
2335                 privptr->p_claw_signal_blk=p_free_chain;
2336                 p_free_chain=p_free_chain->next;
2337                 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
2338                 pClawH->length=0xffff;
2339                 pClawH->opcode=0xff;
2340                 pClawH->flag=CLAW_BUSY;
2341         }
2342 #ifdef DEBUGMSG
2343         printk(KERN_INFO "%s: %s() >  End initialize "
2344                 "ClawSignalBlock\n",
2345                 dev->name,__FUNCTION__);
2346         dumpit((char *)privptr->p_claw_signal_blk, sizeof(struct ccwbk));
2347 #endif
2348
2349         /*
2350         *               allocate write_pages_required and add to free chain
2351         */
2352         if (privptr->p_buff_write==NULL) {
2353             if (privptr->p_env->write_size < PAGE_SIZE) {
2354                 privptr->p_buff_write=
2355                         (void *)__get_free_pages(__GFP_DMA,
2356                         (int)pages_to_order_of_mag(claw_write_pages ));
2357                 if (privptr->p_buff_write==NULL) {
2358                         printk(KERN_INFO "%s: %s() __get_free_pages for write"
2359                                 " bufs failed : get is for %d pages\n",
2360                                 dev->name,__FUNCTION__,claw_write_pages );
2361                         free_pages((unsigned long)privptr->p_buff_ccw,
2362                            (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2363                         privptr->p_buff_ccw=NULL;
2364 #ifdef FUNCTRACE
2365                         printk(KERN_INFO "%s: %s() > exit on line %d,"
2366                                 "rc = ENOMEM\n",
2367                                 dev->name,__FUNCTION__,__LINE__);
2368 #endif
2369                         return -ENOMEM;
2370                 }
2371                 /*
2372                 *                               Build CLAW write free chain
2373                 *
2374                 */
2375
2376                 memset(privptr->p_buff_write, 0x00,
2377                         ccw_pages_required * PAGE_SIZE);
2378 #ifdef DEBUGMSG
2379                 printk(KERN_INFO "%s: %s() Begin build claw write free "
2380                         "chain \n",dev->name,__FUNCTION__);
2381 #endif
2382                 privptr->p_write_free_chain=NULL;
2383
2384                 p_buff=privptr->p_buff_write;
2385
2386                 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
2387                         p_buf        = p_free_chain;      /*  get a CCW */
2388                         p_free_chain = p_buf->next;
2389                         p_buf->next  =privptr->p_write_free_chain;
2390                         privptr->p_write_free_chain = p_buf;
2391                         p_buf-> p_buffer        = (struct clawbuf *)p_buff;
2392                         p_buf-> write.cda       = (__u32)__pa(p_buff);
2393                         p_buf-> write.flags     = CCW_FLAG_SLI | CCW_FLAG_CC;
2394                         p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2395                         p_buf-> w_read_FF.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
2396                         p_buf-> w_read_FF.count   = 1;
2397                         p_buf-> w_read_FF.cda     =
2398                                 (__u32)__pa(&p_buf-> header.flag);
2399                         p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2400                         p_buf-> w_TIC_1.flags      = 0;
2401                         p_buf-> w_TIC_1.count      = 0;
2402
2403                         if (((unsigned long)p_buff+privptr->p_env->write_size) >=
2404                            ((unsigned long)(p_buff+2*
2405                                 (privptr->p_env->write_size) -1) & PAGE_MASK)) {
2406                         p_buff= p_buff+privptr->p_env->write_size;
2407                         }
2408                 }
2409            }
2410            else      /*  Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
2411            {
2412                privptr->p_write_free_chain=NULL;
2413                for (i = 0; i< privptr->p_env->write_buffers ; i++) {
2414                    p_buff=(void *)__get_free_pages(__GFP_DMA,
2415                         (int)pages_to_order_of_mag(
2416                         privptr->p_buff_pages_perwrite) );
2417 #ifdef IOTRACE
2418                    printk(KERN_INFO "%s:%s __get_free_pages "
2419                     "for writes buf: get for %d pages\n",
2420                     dev->name,__FUNCTION__,
2421                     privptr->p_buff_pages_perwrite);
2422 #endif
2423                    if (p_buff==NULL) {
2424                         printk(KERN_INFO "%s:%s __get_free_pages"
2425                                 "for writes buf failed : get is for %d pages\n",
2426                                 dev->name,
2427                                 __FUNCTION__,
2428                                 privptr->p_buff_pages_perwrite );
2429                         free_pages((unsigned long)privptr->p_buff_ccw,
2430                               (int)pages_to_order_of_mag(
2431                                         privptr->p_buff_ccw_num));
2432                         privptr->p_buff_ccw=NULL;
2433                         p_buf=privptr->p_buff_write;
2434                         while (p_buf!=NULL) {
2435                                 free_pages((unsigned long)
2436                                         p_buf->p_buffer,
2437                                         (int)pages_to_order_of_mag(
2438                                         privptr->p_buff_pages_perwrite));
2439                                 p_buf=p_buf->next;
2440                         }
2441 #ifdef FUNCTRACE
2442                         printk(KERN_INFO "%s: %s exit on line %d, rc = ENOMEM\n",
2443                         dev->name,
2444                         __FUNCTION__,
2445                         __LINE__);
2446 #endif
2447                         return -ENOMEM;
2448                    }  /* Error on get_pages   */
2449                    memset(p_buff, 0x00, privptr->p_env->write_size );
2450                    p_buf         = p_free_chain;
2451                    p_free_chain  = p_buf->next;
2452                    p_buf->next   = privptr->p_write_free_chain;
2453                    privptr->p_write_free_chain = p_buf;
2454                    privptr->p_buff_write = p_buf;
2455                    p_buf->p_buffer=(struct clawbuf *)p_buff;
2456                    p_buf-> write.cda     = (__u32)__pa(p_buff);
2457                    p_buf-> write.flags   = CCW_FLAG_SLI | CCW_FLAG_CC;
2458                    p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2459                    p_buf-> w_read_FF.flags    = CCW_FLAG_SLI | CCW_FLAG_CC;
2460                    p_buf-> w_read_FF.count    = 1;
2461                    p_buf-> w_read_FF.cda      =
2462                         (__u32)__pa(&p_buf-> header.flag);
2463                    p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2464                    p_buf-> w_TIC_1.flags   = 0;
2465                    p_buf-> w_TIC_1.count   = 0;
2466                }  /* for all write_buffers   */
2467
2468            }    /* else buffers are PAGE_SIZE or bigger */
2469
2470         }
2471         privptr->p_buff_write_num=claw_write_pages;
2472         privptr->write_free_count=privptr->p_env->write_buffers;
2473
2474
2475 #ifdef DEBUGMSG
2476         printk(KERN_INFO "%s:%s  End build claw write free chain \n",
2477         dev->name,__FUNCTION__);
2478         p_buf=privptr->p_write_free_chain;
2479         while (p_buf!=NULL) {
2480                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2481                 p_buf=p_buf->next;
2482         }
2483 #endif
2484         /*
2485         *               allocate read_pages_required and chain to free chain
2486         */
2487         if (privptr->p_buff_read==NULL) {
2488             if (privptr->p_env->read_size < PAGE_SIZE)  {
2489                 privptr->p_buff_read=
2490                         (void *)__get_free_pages(__GFP_DMA,
2491                         (int)pages_to_order_of_mag(claw_read_pages) );
2492                 if (privptr->p_buff_read==NULL) {
2493                         printk(KERN_INFO "%s: %s() "
2494                                 "__get_free_pages for read buf failed : "
2495                                 "get is for %d pages\n",
2496                                 dev->name,__FUNCTION__,claw_read_pages );
2497                         free_pages((unsigned long)privptr->p_buff_ccw,
2498                                 (int)pages_to_order_of_mag(
2499                                         privptr->p_buff_ccw_num));
2500                         /* free the write pages size is < page size  */
2501                         free_pages((unsigned long)privptr->p_buff_write,
2502                                 (int)pages_to_order_of_mag(
2503                                 privptr->p_buff_write_num));
2504                         privptr->p_buff_ccw=NULL;
2505                         privptr->p_buff_write=NULL;
2506 #ifdef FUNCTRACE
2507                         printk(KERN_INFO "%s: %s() > exit on line %d, rc ="
2508                                 " ENOMEM\n",dev->name,__FUNCTION__,__LINE__);
2509 #endif
2510                         return -ENOMEM;
2511                 }
2512                 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
2513                 privptr->p_buff_read_num=claw_read_pages;
2514                 /*
2515                 *                               Build CLAW read free chain
2516                 *
2517                 */
2518 #ifdef DEBUGMSG
2519                 printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2520                         dev->name,__FUNCTION__);
2521 #endif
2522                 p_buff=privptr->p_buff_read;
2523                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2524                         p_buf        = p_free_chain;
2525                         p_free_chain = p_buf->next;
2526
2527                         if (p_last_CCWB==NULL) {
2528                                 p_buf->next=NULL;
2529                                 real_TIC_address=0;
2530                                 p_last_CCWB=p_buf;
2531                         }
2532                         else {
2533                                 p_buf->next=p_first_CCWB;
2534                                 real_TIC_address=
2535                                 (__u32)__pa(&p_first_CCWB -> read );
2536                         }
2537
2538                         p_first_CCWB=p_buf;
2539
2540                         p_buf->p_buffer=(struct clawbuf *)p_buff;
2541                         /*  initialize read command */
2542                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2543                         p_buf-> read.cda = (__u32)__pa(p_buff);
2544                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2545                         p_buf-> read.count       = privptr->p_env->read_size;
2546
2547                         /*  initialize read_h command */
2548                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2549                         p_buf-> read_h.cda =
2550                                 (__u32)__pa(&(p_buf->header));
2551                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2552                         p_buf-> read_h.count      = sizeof(struct clawh);
2553
2554                         /*  initialize Signal command */
2555                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2556                         p_buf-> signal.cda =
2557                                 (__u32)__pa(&(pClawH->flag));
2558                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2559                         p_buf-> signal.count     = 1;
2560
2561                         /*  initialize r_TIC_1 command */
2562                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2563                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2564                         p_buf-> r_TIC_1.flags = 0;
2565                         p_buf-> r_TIC_1.count      = 0;
2566
2567                         /*  initialize r_read_FF command */
2568                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2569                         p_buf-> r_read_FF.cda =
2570                                 (__u32)__pa(&(pClawH->flag));
2571                         p_buf-> r_read_FF.flags =
2572                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2573                         p_buf-> r_read_FF.count    = 1;
2574
2575                         /*    initialize r_TIC_2          */
2576                         memcpy(&p_buf->r_TIC_2,
2577                                 &p_buf->r_TIC_1, sizeof(struct ccw1));
2578
2579                         /*     initialize Header     */
2580                         p_buf->header.length=0xffff;
2581                         p_buf->header.opcode=0xff;
2582                         p_buf->header.flag=CLAW_PENDING;
2583
2584                         if (((unsigned long)p_buff+privptr->p_env->read_size) >=
2585                                 ((unsigned long)(p_buff+2*(privptr->p_env->read_size) -1)
2586                                  & PAGE_MASK) ) {
2587                                 p_buff= p_buff+privptr->p_env->read_size;
2588                         }
2589                         else {
2590                                 p_buff=
2591                                 (void *)((unsigned long)
2592                                         (p_buff+2*(privptr->p_env->read_size) -1)
2593                                          & PAGE_MASK) ;
2594                         }
2595                 }   /* for read_buffers   */
2596           }         /* read_size < PAGE_SIZE  */
2597           else {  /* read Size >= PAGE_SIZE  */
2598
2599 #ifdef DEBUGMSG
2600         printk(KERN_INFO "%s: %s() Begin build claw read free chain \n",
2601                 dev->name,__FUNCTION__);
2602 #endif
2603                 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
2604                         p_buff = (void *)__get_free_pages(__GFP_DMA,
2605                                 (int)pages_to_order_of_mag(privptr->p_buff_pages_perread) );
2606                         if (p_buff==NULL) {
2607                                 printk(KERN_INFO "%s: %s() __get_free_pages for read "
2608                                         "buf failed : get is for %d pages\n",
2609                                         dev->name,__FUNCTION__,
2610                                         privptr->p_buff_pages_perread );
2611                                 free_pages((unsigned long)privptr->p_buff_ccw,
2612                                         (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
2613                                 /* free the write pages  */
2614                                 p_buf=privptr->p_buff_write;
2615                                 while (p_buf!=NULL) {
2616                                         free_pages((unsigned long)p_buf->p_buffer,
2617                                                 (int)pages_to_order_of_mag(
2618                                                 privptr->p_buff_pages_perwrite ));
2619                                         p_buf=p_buf->next;
2620                                 }
2621                                 /* free any read pages already alloc  */
2622                                 p_buf=privptr->p_buff_read;
2623                                 while (p_buf!=NULL) {
2624                                         free_pages((unsigned long)p_buf->p_buffer,
2625                                                 (int)pages_to_order_of_mag(
2626                                                 privptr->p_buff_pages_perread ));
2627                                         p_buf=p_buf->next;
2628                                 }
2629                                 privptr->p_buff_ccw=NULL;
2630                                 privptr->p_buff_write=NULL;
2631 #ifdef FUNCTRACE
2632                                 printk(KERN_INFO "%s: %s() exit on line %d, rc = ENOMEM\n",
2633                                         dev->name,__FUNCTION__,
2634                                         __LINE__);
2635 #endif
2636                                 return -ENOMEM;
2637                         }
2638                         memset(p_buff, 0x00, privptr->p_env->read_size);
2639                         p_buf        = p_free_chain;
2640                         privptr->p_buff_read = p_buf;
2641                         p_free_chain = p_buf->next;
2642
2643                         if (p_last_CCWB==NULL) {
2644                                 p_buf->next=NULL;
2645                                 real_TIC_address=0;
2646                                 p_last_CCWB=p_buf;
2647                         }
2648                         else {
2649                                 p_buf->next=p_first_CCWB;
2650                                 real_TIC_address=
2651                                         (addr_t)__pa(
2652                                                 &p_first_CCWB -> read );
2653                         }
2654
2655                         p_first_CCWB=p_buf;
2656                                 /* save buff address */
2657                         p_buf->p_buffer=(struct clawbuf *)p_buff;
2658                         /*  initialize read command */
2659                         p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
2660                         p_buf-> read.cda = (__u32)__pa(p_buff);
2661                         p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2662                         p_buf-> read.count       = privptr->p_env->read_size;
2663
2664                         /*  initialize read_h command */
2665                         p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
2666                         p_buf-> read_h.cda =
2667                                 (__u32)__pa(&(p_buf->header));
2668                         p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2669                         p_buf-> read_h.count      = sizeof(struct clawh);
2670
2671                         /*  initialize Signal command */
2672                         p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
2673                         p_buf-> signal.cda =
2674                                 (__u32)__pa(&(pClawH->flag));
2675                         p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
2676                         p_buf-> signal.count     = 1;
2677
2678                         /*  initialize r_TIC_1 command */
2679                         p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
2680                         p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
2681                         p_buf-> r_TIC_1.flags = 0;
2682                         p_buf-> r_TIC_1.count      = 0;
2683
2684                         /*  initialize r_read_FF command */
2685                         p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
2686                         p_buf-> r_read_FF.cda =
2687                                 (__u32)__pa(&(pClawH->flag));
2688                         p_buf-> r_read_FF.flags =
2689                                 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2690                         p_buf-> r_read_FF.count    = 1;
2691
2692                         /*    initialize r_TIC_2          */
2693                         memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2694                                 sizeof(struct ccw1));
2695
2696                         /*     initialize Header     */
2697                         p_buf->header.length=0xffff;
2698                         p_buf->header.opcode=0xff;
2699                         p_buf->header.flag=CLAW_PENDING;
2700
2701                 }    /* For read_buffers   */
2702           }     /*  read_size >= PAGE_SIZE   */
2703         }       /*  pBuffread = NULL */
2704 #ifdef DEBUGMSG
2705         printk(KERN_INFO "%s: %s() >  End build claw read free chain \n",
2706                 dev->name,__FUNCTION__);
2707         p_buf=p_first_CCWB;
2708         while (p_buf!=NULL) {
2709                 dumpit((char *)p_buf, sizeof(struct ccwbk));
2710                 p_buf=p_buf->next;
2711         }
2712
2713 #endif
2714         add_claw_reads( dev  ,p_first_CCWB , p_last_CCWB);
2715         privptr->buffs_alloc = 1;
2716 #ifdef FUNCTRACE
2717         printk(KERN_INFO "%s: %s() exit on line %d\n",
2718                 dev->name,__FUNCTION__,__LINE__);
2719 #endif
2720         return 0;
2721 }    /*    end of init_ccw_bk */
2722
2723 /*-------------------------------------------------------------------*
2724 *                                                                    *
2725 *       probe_error                                                  *
2726 *                                                                    *
2727 *--------------------------------------------------------------------*/
2728
2729 static void
2730 probe_error( struct ccwgroup_device *cgdev)
2731 {
2732   struct claw_privbk *privptr;
2733 #ifdef FUNCTRACE
2734         printk(KERN_INFO "%s enter  \n",__FUNCTION__);
2735 #endif
2736         CLAW_DBF_TEXT(4,trace,"proberr");
2737 #ifdef DEBUGMSG
2738         printk(KERN_INFO "%s variable cgdev =\n",__FUNCTION__);
2739         dumpit((char *) cgdev, sizeof(struct ccwgroup_device));
2740 #endif
2741         privptr=(struct claw_privbk *)cgdev->dev.driver_data;
2742         if (privptr!=NULL) {
2743                 kfree(privptr->p_env);
2744                 privptr->p_env=NULL;
2745                 kfree(privptr->p_mtc_envelope);
2746                 privptr->p_mtc_envelope=NULL;
2747                 kfree(privptr);
2748                 privptr=NULL;
2749         }
2750 #ifdef FUNCTRACE
2751         printk(KERN_INFO "%s > exit on line %d\n",
2752                  __FUNCTION__,__LINE__);
2753 #endif
2754
2755         return;
2756 }    /*    probe_error    */
2757
2758
2759
2760 /*-------------------------------------------------------------------*
2761 *    claw_process_control                                            *
2762 *                                                                    *
2763 *                                                                    *
2764 *--------------------------------------------------------------------*/
2765
2766 static int
2767 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2768 {
2769
2770         struct clawbuf *p_buf;
2771         struct clawctl  ctlbk;
2772         struct clawctl *p_ctlbk;
2773         char    temp_host_name[8];
2774         char    temp_ws_name[8];
2775         struct claw_privbk *privptr;
2776         struct claw_env *p_env;
2777         struct sysval *p_sysval;
2778         struct conncmd *p_connect=NULL;
2779         int rc;
2780         struct chbk *p_ch = NULL;
2781 #ifdef FUNCTRACE
2782         printk(KERN_INFO "%s: %s() > enter  \n",
2783                 dev->name,__FUNCTION__);
2784 #endif
2785         CLAW_DBF_TEXT(2,setup,"clw_cntl");
2786 #ifdef DEBUGMSG
2787         printk(KERN_INFO "%s: variable dev =\n",dev->name);
2788         dumpit((char *) dev, sizeof(struct net_device));
2789         printk(KERN_INFO "%s: variable p_ccw =\n",dev->name);
2790         dumpit((char *) p_ccw, sizeof(struct ccwbk *));
2791 #endif
2792         udelay(1000);  /* Wait a ms for the control packets to
2793                         *catch up to each other */
2794         privptr=dev->priv;
2795         p_env=privptr->p_env;
2796         memcpy( &temp_host_name, p_env->host_name, 8);
2797         memcpy( &temp_ws_name, p_env->adapter_name , 8);
2798         printk(KERN_INFO "%s: CLAW device %.8s: "
2799                 "Received Control Packet\n",
2800                 dev->name, temp_ws_name);
2801         if (privptr->release_pend==1) {
2802 #ifdef FUNCTRACE
2803                 printk(KERN_INFO "%s: %s() > "
2804                         "exit on line %d, rc=0\n",
2805                         dev->name,__FUNCTION__,__LINE__);
2806 #endif
2807                 return 0;
2808         }
2809         p_buf=p_ccw->p_buffer;
2810         p_ctlbk=&ctlbk;
2811         if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2812                 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2813         } else {
2814                 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2815         }
2816 #ifdef IOTRACE
2817         printk(KERN_INFO "%s: dump claw control data inbound\n",dev->name);
2818         dumpit((char *)p_ctlbk, sizeof(struct clawctl));
2819 #endif
2820         switch (p_ctlbk->command)
2821         {
2822                 case SYSTEM_VALIDATE_REQUEST:
2823                         if (p_ctlbk->version!=CLAW_VERSION_ID) {
2824                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2825                                         CLAW_RC_WRONG_VERSION );
2826                                 printk("%s: %d is wrong version id. "
2827                                         "Expected %d\n",
2828                                         dev->name, p_ctlbk->version,
2829                                         CLAW_VERSION_ID);
2830                         }
2831                         p_sysval=(struct sysval *)&(p_ctlbk->data);
2832                         printk( "%s: Recv Sys Validate Request: "
2833                                 "Vers=%d,link_id=%d,Corr=%d,WS name=%."
2834                                 "8s,Host name=%.8s\n",
2835                                 dev->name, p_ctlbk->version,
2836                                 p_ctlbk->linkid,
2837                                 p_ctlbk->correlator,
2838                                 p_sysval->WS_name,
2839                                 p_sysval->host_name);
2840                         if (0!=memcmp(temp_host_name,p_sysval->host_name,8)) {
2841                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2842                                         CLAW_RC_NAME_MISMATCH );
2843                                 CLAW_DBF_TEXT(2,setup,"HSTBAD");
2844                                 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->host_name);
2845                                 CLAW_DBF_TEXT_(2,setup,"%s",temp_host_name);
2846                                 printk(KERN_INFO "%s:  Host name mismatch\n",
2847                                         dev->name);
2848                                 printk(KERN_INFO "%s: Received :%s: "
2849                                         "expected :%s: \n",
2850                                         dev->name,
2851                                         p_sysval->host_name,
2852                                         temp_host_name);
2853                         }
2854                         if (0!=memcmp(temp_ws_name,p_sysval->WS_name,8)) {
2855                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2856                                         CLAW_RC_NAME_MISMATCH );
2857                                 CLAW_DBF_TEXT(2,setup,"WSNBAD");
2858                                 CLAW_DBF_TEXT_(2,setup,"%s",p_sysval->WS_name);
2859                                 CLAW_DBF_TEXT_(2,setup,"%s",temp_ws_name);
2860                                 printk(KERN_INFO "%s: WS name mismatch\n",
2861                                         dev->name);
2862                                  printk(KERN_INFO "%s: Received :%s: "
2863                                         "expected :%s: \n",
2864                                         dev->name,
2865                                         p_sysval->WS_name,
2866                                         temp_ws_name);
2867                         }
2868                         if (( p_sysval->write_frame_size < p_env->write_size) &&
2869                            ( p_env->packing == 0)) {
2870                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2871                                         CLAW_RC_HOST_RCV_TOO_SMALL );
2872                                 printk(KERN_INFO "%s: host write size is too "
2873                                         "small\n", dev->name);
2874                                 CLAW_DBF_TEXT(2,setup,"wrtszbad");
2875                         }
2876                         if (( p_sysval->read_frame_size < p_env->read_size) &&
2877                            ( p_env->packing == 0)) {
2878                                 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2879                                         CLAW_RC_HOST_RCV_TOO_SMALL );
2880                                 printk(KERN_INFO "%s: host read size is too "
2881                                         "small\n", dev->name);
2882                                 CLAW_DBF_TEXT(2,setup,"rdsizbad");
2883                         }
2884                         claw_snd_sys_validate_rsp(dev, p_ctlbk, 0 );
2885                         printk("%s: CLAW device %.8s: System validate"
2886                                 " completed.\n",dev->name, temp_ws_name);
2887                         printk("%s: sys Validate Rsize:%d Wsize:%d\n",dev->name,
2888                                 p_sysval->read_frame_size,p_sysval->write_frame_size);
2889                         privptr->system_validate_comp=1;
2890                         if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
2891                                 p_env->packing = PACKING_ASK;
2892                         }
2893                         claw_strt_conn_req(dev);
2894                         break;
2895
2896                 case SYSTEM_VALIDATE_RESPONSE:
2897                         p_sysval=(struct sysval *)&(p_ctlbk->data);
2898                         printk("%s: Recv Sys Validate Resp: Vers=%d,Corr=%d,RC=%d,"
2899                                 "WS name=%.8s,Host name=%.8s\n",
2900                                 dev->name,
2901                                 p_ctlbk->version,
2902                                 p_ctlbk->correlator,
2903                                 p_ctlbk->rc,
2904                                 p_sysval->WS_name,
2905                                 p_sysval->host_name);
2906                         switch (p_ctlbk->rc)
2907                         {
2908                                 case 0:
2909                                         printk(KERN_INFO "%s: CLAW device "
2910                                                 "%.8s: System validate "
2911                                                 "completed.\n",
2912                                                 dev->name, temp_ws_name);
2913                                         if (privptr->system_validate_comp == 0)
2914                                                 claw_strt_conn_req(dev);
2915                                         privptr->system_validate_comp=1;
2916                                         break;
2917                                 case CLAW_RC_NAME_MISMATCH:
2918                                         printk(KERN_INFO "%s: Sys Validate "
2919                                                 "Resp : Host, WS name is "
2920                                                 "mismatch\n",
2921                                                 dev->name);
2922                                         break;
2923                                 case CLAW_RC_WRONG_VERSION:
2924                                         printk(KERN_INFO "%s: Sys Validate "
2925                                                 "Resp : Wrong version\n",
2926                                                 dev->name);
2927                                         break;
2928                                 case CLAW_RC_HOST_RCV_TOO_SMALL:
2929                                         printk(KERN_INFO "%s: Sys Validate "
2930                                                 "Resp : bad frame size\n",
2931                                                 dev->name);
2932                                         break;
2933                                 default:
2934                                         printk(KERN_INFO "%s: Sys Validate "
2935                                                 "error code=%d \n",
2936                                                  dev->name, p_ctlbk->rc );
2937                                         break;
2938                         }
2939                         break;
2940
2941                 case CONNECTION_REQUEST:
2942                         p_connect=(struct conncmd *)&(p_ctlbk->data);
2943                         printk(KERN_INFO "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2944                                 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2945                                 dev->name,
2946                                 p_ctlbk->version,
2947                                 p_ctlbk->linkid,
2948                                 p_ctlbk->correlator,
2949                                 p_connect->host_name,
2950                                 p_connect->WS_name);
2951                         if (privptr->active_link_ID!=0 ) {
2952                                 claw_snd_disc(dev, p_ctlbk);
2953                                 printk(KERN_INFO "%s: Conn Req error : "
2954                                         "already logical link is active \n",
2955                                         dev->name);
2956                         }
2957                         if (p_ctlbk->linkid!=1 ) {
2958                                 claw_snd_disc(dev, p_ctlbk);
2959                                 printk(KERN_INFO "%s: Conn Req error : "
2960                                         "req logical link id is not 1\n",
2961                                         dev->name);
2962                         }
2963                         rc=find_link(dev,
2964                                 p_connect->host_name, p_connect->WS_name);
2965                         if (rc!=0) {
2966                                 claw_snd_disc(dev, p_ctlbk);
2967                                 printk(KERN_INFO "%s: Conn Req error : "
2968                                         "req appl name does not match\n",
2969                                          dev->name);
2970                         }
2971                         claw_send_control(dev,
2972                                 CONNECTION_CONFIRM, p_ctlbk->linkid,
2973                                 p_ctlbk->correlator,
2974                                 0, p_connect->host_name,
2975                                 p_connect->WS_name);
2976                         if (p_env->packing == PACKING_ASK) {
2977                                 printk("%s: Now Pack ask\n",dev->name);
2978                                 p_env->packing = PACK_SEND;
2979                                 claw_snd_conn_req(dev,0);
2980                         }
2981                       &nbs