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