]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/s390/net/claw.c
ctcm: suspend has to wait for outstanding I/O
[mirror_ubuntu-zesty-kernel.git] / drivers / s390 / net / claw.c
CommitLineData
1da177e4
LT
1/*
2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
4 *
8e84c801 5 * Linux for zSeries version
88efc2c5 6 * Copyright IBM Corp. 2002, 2009
1da177e4 7 * Author(s) Original code written by:
88efc2c5 8 * Kazuo Iimura <iimura@jp.ibm.com>
1da177e4 9 * Rewritten by
88efc2c5
FB
10 * Andy Richter <richtera@us.ibm.com>
11 * Marc Price <mwprice@us.ibm.com>
1da177e4
LT
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
b805da74 61 * 1.5
1da177e4 62 */
4811fcb7
AR
63
64#define KMSG_COMPONENT "claw"
65
1da177e4
LT
66#include <asm/ccwdev.h>
67#include <asm/ccwgroup.h>
68#include <asm/debug.h>
69#include <asm/idals.h>
70#include <asm/io.h>
1977f032 71#include <linux/bitops.h>
1da177e4
LT
72#include <linux/ctype.h>
73#include <linux/delay.h>
74#include <linux/errno.h>
75#include <linux/if_arp.h>
76#include <linux/init.h>
77#include <linux/interrupt.h>
78#include <linux/ip.h>
79#include <linux/kernel.h>
80#include <linux/module.h>
81#include <linux/netdevice.h>
82#include <linux/etherdevice.h>
83#include <linux/proc_fs.h>
84#include <linux/sched.h>
85#include <linux/signal.h>
86#include <linux/skbuff.h>
87#include <linux/slab.h>
88#include <linux/string.h>
89#include <linux/tcp.h>
90#include <linux/timer.h>
91#include <linux/types.h>
1da177e4
LT
92
93#include "cu3088.h"
94#include "claw.h"
95
b805da74
AR
96/*
97 CLAW uses the s390dbf file system see claw_trace and claw_setup
1da177e4
LT
98*/
99
4811fcb7 100static char version[] __initdata = "CLAW driver";
2b67fc46 101static char debug_buffer[255];
1da177e4
LT
102/**
103 * Debug Facility Stuff
104 */
105static debug_info_t *claw_dbf_setup;
106static debug_info_t *claw_dbf_trace;
107
108/**
109 * CLAW Debug Facility functions
110 */
111static void
112claw_unregister_debug_facility(void)
113{
114 if (claw_dbf_setup)
115 debug_unregister(claw_dbf_setup);
116 if (claw_dbf_trace)
117 debug_unregister(claw_dbf_trace);
118}
119
120static int
121claw_register_debug_facility(void)
122{
66a464db
MH
123 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
124 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
1da177e4 125 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
1da177e4
LT
126 claw_unregister_debug_facility();
127 return -ENOMEM;
128 }
129 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
130 debug_set_level(claw_dbf_setup, 2);
131 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
132 debug_set_level(claw_dbf_trace, 2);
133 return 0;
134}
135
136static inline void
137claw_set_busy(struct net_device *dev)
138{
6951df34 139 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
1da177e4
LT
140 eieio();
141}
142
143static inline void
144claw_clear_busy(struct net_device *dev)
145{
6951df34 146 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
1da177e4
LT
147 netif_wake_queue(dev);
148 eieio();
149}
150
151static inline int
152claw_check_busy(struct net_device *dev)
153{
154 eieio();
6951df34 155 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
1da177e4
LT
156}
157
158static inline void
159claw_setbit_busy(int nr,struct net_device *dev)
160{
161 netif_stop_queue(dev);
6951df34 162 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
1da177e4
LT
163}
164
165static inline void
166claw_clearbit_busy(int nr,struct net_device *dev)
167{
6951df34 168 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
1da177e4
LT
169 netif_wake_queue(dev);
170}
171
172static inline int
173claw_test_and_setbit_busy(int nr,struct net_device *dev)
174{
175 netif_stop_queue(dev);
176 return test_and_set_bit(nr,
6951df34 177 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
1da177e4
LT
178}
179
180
181/* Functions for the DEV methods */
182
183static int claw_probe(struct ccwgroup_device *cgdev);
184static void claw_remove_device(struct ccwgroup_device *cgdev);
185static void claw_purge_skb_queue(struct sk_buff_head *q);
186static int claw_new_device(struct ccwgroup_device *cgdev);
187static int claw_shutdown_device(struct ccwgroup_device *cgdev);
188static int claw_tx(struct sk_buff *skb, struct net_device *dev);
189static int claw_change_mtu( struct net_device *dev, int new_mtu);
190static int claw_open(struct net_device *dev);
191static void claw_irq_handler(struct ccw_device *cdev,
192 unsigned long intparm, struct irb *irb);
193static void claw_irq_tasklet ( unsigned long data );
194static int claw_release(struct net_device *dev);
195static void claw_write_retry ( struct chbk * p_ch );
196static void claw_write_next ( struct chbk * p_ch );
197static void claw_timer ( struct chbk * p_ch );
198
199/* Functions */
200static int add_claw_reads(struct net_device *dev,
201 struct ccwbk* p_first, struct ccwbk* p_last);
4d284cac
HC
202static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
203static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
1da177e4
LT
204static int find_link(struct net_device *dev, char *host_name, char *ws_name );
205static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
206static int init_ccw_bk(struct net_device *dev);
207static void probe_error( struct ccwgroup_device *cgdev);
208static struct net_device_stats *claw_stats(struct net_device *dev);
4d284cac 209static int pages_to_order_of_mag(int num_of_pages);
1da177e4 210static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
1da177e4 211/* sysfs Functions */
4811fcb7
AR
212static ssize_t claw_hname_show(struct device *dev,
213 struct device_attribute *attr, char *buf);
214static ssize_t claw_hname_write(struct device *dev,
215 struct device_attribute *attr,
1da177e4 216 const char *buf, size_t count);
4811fcb7
AR
217static ssize_t claw_adname_show(struct device *dev,
218 struct device_attribute *attr, char *buf);
219static ssize_t claw_adname_write(struct device *dev,
220 struct device_attribute *attr,
1da177e4 221 const char *buf, size_t count);
4811fcb7
AR
222static ssize_t claw_apname_show(struct device *dev,
223 struct device_attribute *attr, char *buf);
224static ssize_t claw_apname_write(struct device *dev,
225 struct device_attribute *attr,
1da177e4 226 const char *buf, size_t count);
4811fcb7
AR
227static ssize_t claw_wbuff_show(struct device *dev,
228 struct device_attribute *attr, char *buf);
229static ssize_t claw_wbuff_write(struct device *dev,
230 struct device_attribute *attr,
1da177e4 231 const char *buf, size_t count);
4811fcb7
AR
232static ssize_t claw_rbuff_show(struct device *dev,
233 struct device_attribute *attr, char *buf);
234static ssize_t claw_rbuff_write(struct device *dev,
235 struct device_attribute *attr,
1da177e4
LT
236 const char *buf, size_t count);
237static int claw_add_files(struct device *dev);
238static void claw_remove_files(struct device *dev);
239
240/* Functions for System Validate */
241static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
242static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
243 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
244static int claw_snd_conn_req(struct net_device *dev, __u8 link);
245static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
246static int claw_snd_sys_validate_rsp(struct net_device *dev,
247 struct clawctl * p_ctl, __u32 return_code);
248static int claw_strt_conn_req(struct net_device *dev );
b805da74
AR
249static void claw_strt_read(struct net_device *dev, int lock);
250static void claw_strt_out_IO(struct net_device *dev);
251static void claw_free_wrt_buf(struct net_device *dev);
1da177e4
LT
252
253/* Functions for unpack reads */
b805da74 254static void unpack_read(struct net_device *dev);
1da177e4 255
88efc2c5
FB
256static int claw_pm_prepare(struct ccwgroup_device *gdev)
257{
258 return -EPERM;
259}
260
1da177e4
LT
261/* ccwgroup table */
262
263static struct ccwgroup_driver claw_group_driver = {
264 .owner = THIS_MODULE,
265 .name = "claw",
266 .max_slaves = 2,
267 .driver_id = 0xC3D3C1E6,
268 .probe = claw_probe,
269 .remove = claw_remove_device,
270 .set_online = claw_new_device,
271 .set_offline = claw_shutdown_device,
88efc2c5 272 .prepare = claw_pm_prepare,
1da177e4
LT
273};
274
275/*
1da177e4
LT
276* Key functions
277*/
278
279/*----------------------------------------------------------------*
280 * claw_probe *
281 * this function is called for each CLAW device. *
282 *----------------------------------------------------------------*/
283static int
284claw_probe(struct ccwgroup_device *cgdev)
285{
286 int rc;
287 struct claw_privbk *privptr=NULL;
288
b805da74 289 CLAW_DBF_TEXT(2, setup, "probe");
1da177e4
LT
290 if (!get_device(&cgdev->dev))
291 return -ENODEV;
88abaab4 292 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
dff59b64 293 dev_set_drvdata(&cgdev->dev, privptr);
1da177e4
LT
294 if (privptr == NULL) {
295 probe_error(cgdev);
296 put_device(&cgdev->dev);
b805da74 297 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
1da177e4
LT
298 return -ENOMEM;
299 }
dd00cc48
YP
300 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
301 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
1da177e4
LT
302 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
303 probe_error(cgdev);
304 put_device(&cgdev->dev);
b805da74 305 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
1da177e4
LT
306 return -ENOMEM;
307 }
1da177e4
LT
308 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
309 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
310 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
311 privptr->p_env->packing = 0;
312 privptr->p_env->write_buffers = 5;
313 privptr->p_env->read_buffers = 5;
314 privptr->p_env->read_size = CLAW_FRAME_SIZE;
315 privptr->p_env->write_size = CLAW_FRAME_SIZE;
316 rc = claw_add_files(&cgdev->dev);
317 if (rc) {
318 probe_error(cgdev);
319 put_device(&cgdev->dev);
4811fcb7
AR
320 dev_err(&cgdev->dev, "Creating the /proc files for a new"
321 " CLAW device failed\n");
b805da74 322 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
1da177e4
LT
323 return rc;
324 }
1da177e4
LT
325 privptr->p_env->p_priv = privptr;
326 cgdev->cdev[0]->handler = claw_irq_handler;
327 cgdev->cdev[1]->handler = claw_irq_handler;
b805da74 328 CLAW_DBF_TEXT(2, setup, "prbext 0");
1da177e4
LT
329
330 return 0;
331} /* end of claw_probe */
332
333/*-------------------------------------------------------------------*
334 * claw_tx *
335 *-------------------------------------------------------------------*/
336
337static int
338claw_tx(struct sk_buff *skb, struct net_device *dev)
339{
340 int rc;
6951df34 341 struct claw_privbk *privptr = dev->ml_priv;
1da177e4
LT
342 unsigned long saveflags;
343 struct chbk *p_ch;
344
b805da74 345 CLAW_DBF_TEXT(4, trace, "claw_tx");
1da177e4 346 p_ch=&privptr->channel[WRITE];
1da177e4
LT
347 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
348 rc=claw_hw_tx( skb, dev, 1 );
349 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
b805da74 350 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
8f0c40d4
UB
351 if (rc)
352 rc = NETDEV_TX_BUSY;
ec634fe3
PM
353 else
354 rc = NETDEV_TX_OK;
1da177e4
LT
355 return rc;
356} /* end of claw_tx */
357
358/*------------------------------------------------------------------*
359 * pack the collect queue into an skb and return it *
360 * If not packing just return the top skb from the queue *
361 *------------------------------------------------------------------*/
362
363static struct sk_buff *
364claw_pack_skb(struct claw_privbk *privptr)
365{
366 struct sk_buff *new_skb,*held_skb;
367 struct chbk *p_ch = &privptr->channel[WRITE];
368 struct claw_env *p_env = privptr->p_env;
369 int pkt_cnt,pk_ind,so_far;
370
371 new_skb = NULL; /* assume no dice */
372 pkt_cnt = 0;
b805da74 373 CLAW_DBF_TEXT(4, trace, "PackSKBe");
b03efcfb 374 if (!skb_queue_empty(&p_ch->collect_queue)) {
1da177e4
LT
375 /* some data */
376 held_skb = skb_dequeue(&p_ch->collect_queue);
1da177e4 377 if (held_skb)
8e84c801 378 dev_kfree_skb_any(held_skb);
1da177e4
LT
379 else
380 return NULL;
8e84c801
FP
381 if (p_env->packing != DO_PACKED)
382 return held_skb;
1da177e4
LT
383 /* get a new SKB we will pack at least one */
384 new_skb = dev_alloc_skb(p_env->write_size);
385 if (new_skb == NULL) {
386 atomic_inc(&held_skb->users);
387 skb_queue_head(&p_ch->collect_queue,held_skb);
388 return NULL;
389 }
390 /* we have packed packet and a place to put it */
391 pk_ind = 1;
392 so_far = 0;
393 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
394 while ((pk_ind) && (held_skb != NULL)) {
395 if (held_skb->len+so_far <= p_env->write_size-8) {
396 memcpy(skb_put(new_skb,held_skb->len),
397 held_skb->data,held_skb->len);
398 privptr->stats.tx_packets++;
399 so_far += held_skb->len;
400 pkt_cnt++;
8e84c801 401 dev_kfree_skb_any(held_skb);
1da177e4
LT
402 held_skb = skb_dequeue(&p_ch->collect_queue);
403 if (held_skb)
404 atomic_dec(&held_skb->users);
405 } else {
406 pk_ind = 0;
407 atomic_inc(&held_skb->users);
408 skb_queue_head(&p_ch->collect_queue,held_skb);
409 }
410 }
1da177e4 411 }
b805da74 412 CLAW_DBF_TEXT(4, trace, "PackSKBx");
1da177e4
LT
413 return new_skb;
414}
415
416/*-------------------------------------------------------------------*
417 * claw_change_mtu *
418 * *
419 *-------------------------------------------------------------------*/
420
421static int
422claw_change_mtu(struct net_device *dev, int new_mtu)
423{
6951df34 424 struct claw_privbk *privptr = dev->ml_priv;
1da177e4 425 int buff_size;
b805da74 426 CLAW_DBF_TEXT(4, trace, "setmtu");
1da177e4
LT
427 buff_size = privptr->p_env->write_size;
428 if ((new_mtu < 60) || (new_mtu > buff_size)) {
1da177e4
LT
429 return -EINVAL;
430 }
431 dev->mtu = new_mtu;
1da177e4
LT
432 return 0;
433} /* end of claw_change_mtu */
434
435
436/*-------------------------------------------------------------------*
437 * claw_open *
438 * *
439 *-------------------------------------------------------------------*/
440static int
441claw_open(struct net_device *dev)
442{
443
444 int rc;
445 int i;
446 unsigned long saveflags=0;
447 unsigned long parm;
448 struct claw_privbk *privptr;
449 DECLARE_WAITQUEUE(wait, current);
450 struct timer_list timer;
451 struct ccwbk *p_buf;
452
b805da74 453 CLAW_DBF_TEXT(4, trace, "open");
6951df34 454 privptr = (struct claw_privbk *)dev->ml_priv;
1da177e4
LT
455 /* allocate and initialize CCW blocks */
456 if (privptr->buffs_alloc == 0) {
457 rc=init_ccw_bk(dev);
458 if (rc) {
b805da74 459 CLAW_DBF_TEXT(2, trace, "openmem");
1da177e4
LT
460 return -ENOMEM;
461 }
462 }
463 privptr->system_validate_comp=0;
464 privptr->release_pend=0;
465 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
466 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
467 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
468 privptr->p_env->packing=PACKING_ASK;
469 } else {
470 privptr->p_env->packing=0;
471 privptr->p_env->read_size=CLAW_FRAME_SIZE;
472 privptr->p_env->write_size=CLAW_FRAME_SIZE;
473 }
474 claw_set_busy(dev);
475 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
476 (unsigned long) &privptr->channel[READ]);
477 for ( i = 0; i < 2; i++) {
b805da74 478 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
1da177e4
LT
479 init_waitqueue_head(&privptr->channel[i].wait);
480 /* skb_queue_head_init(&p_ch->io_queue); */
481 if (i == WRITE)
482 skb_queue_head_init(
483 &privptr->channel[WRITE].collect_queue);
484 privptr->channel[i].flag_a = 0;
485 privptr->channel[i].IO_active = 0;
486 privptr->channel[i].flag &= ~CLAW_TIMER;
487 init_timer(&timer);
488 timer.function = (void *)claw_timer;
489 timer.data = (unsigned long)(&privptr->channel[i]);
490 timer.expires = jiffies + 15*HZ;
491 add_timer(&timer);
492 spin_lock_irqsave(get_ccwdev_lock(
493 privptr->channel[i].cdev), saveflags);
494 parm = (unsigned long) &privptr->channel[i];
495 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
496 rc = 0;
497 add_wait_queue(&privptr->channel[i].wait, &wait);
498 rc = ccw_device_halt(
499 (struct ccw_device *)privptr->channel[i].cdev,parm);
500 set_current_state(TASK_INTERRUPTIBLE);
501 spin_unlock_irqrestore(
502 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
503 schedule();
504 set_current_state(TASK_RUNNING);
505 remove_wait_queue(&privptr->channel[i].wait, &wait);
506 if(rc != 0)
507 ccw_check_return_code(privptr->channel[i].cdev, rc);
508 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
509 del_timer(&timer);
510 }
511 if ((((privptr->channel[READ].last_dstat |
512 privptr->channel[WRITE].last_dstat) &
513 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
514 (((privptr->channel[READ].flag |
515 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
4811fcb7
AR
516 dev_info(&privptr->channel[READ].cdev->dev,
517 "%s: remote side is not ready\n", dev->name);
b805da74 518 CLAW_DBF_TEXT(2, trace, "notrdy");
1da177e4
LT
519
520 for ( i = 0; i < 2; i++) {
521 spin_lock_irqsave(
522 get_ccwdev_lock(privptr->channel[i].cdev),
523 saveflags);
524 parm = (unsigned long) &privptr->channel[i];
525 privptr->channel[i].claw_state = CLAW_STOP;
526 rc = ccw_device_halt(
527 (struct ccw_device *)&privptr->channel[i].cdev,
528 parm);
529 spin_unlock_irqrestore(
530 get_ccwdev_lock(privptr->channel[i].cdev),
531 saveflags);
532 if (rc != 0) {
533 ccw_check_return_code(
534 privptr->channel[i].cdev, rc);
535 }
536 }
537 free_pages((unsigned long)privptr->p_buff_ccw,
538 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
539 if (privptr->p_env->read_size < PAGE_SIZE) {
540 free_pages((unsigned long)privptr->p_buff_read,
541 (int)pages_to_order_of_mag(
542 privptr->p_buff_read_num));
543 }
544 else {
545 p_buf=privptr->p_read_active_first;
546 while (p_buf!=NULL) {
547 free_pages((unsigned long)p_buf->p_buffer,
548 (int)pages_to_order_of_mag(
549 privptr->p_buff_pages_perread ));
550 p_buf=p_buf->next;
551 }
552 }
553 if (privptr->p_env->write_size < PAGE_SIZE ) {
554 free_pages((unsigned long)privptr->p_buff_write,
555 (int)pages_to_order_of_mag(
556 privptr->p_buff_write_num));
557 }
558 else {
559 p_buf=privptr->p_write_active_first;
560 while (p_buf!=NULL) {
561 free_pages((unsigned long)p_buf->p_buffer,
562 (int)pages_to_order_of_mag(
563 privptr->p_buff_pages_perwrite ));
564 p_buf=p_buf->next;
565 }
566 }
567 privptr->buffs_alloc = 0;
568 privptr->channel[READ].flag= 0x00;
569 privptr->channel[WRITE].flag = 0x00;
570 privptr->p_buff_ccw=NULL;
571 privptr->p_buff_read=NULL;
572 privptr->p_buff_write=NULL;
573 claw_clear_busy(dev);
b805da74 574 CLAW_DBF_TEXT(2, trace, "open EIO");
1da177e4
LT
575 return -EIO;
576 }
577
578 /* Send SystemValidate command */
579
580 claw_clear_busy(dev);
b805da74 581 CLAW_DBF_TEXT(4, trace, "openok");
1da177e4
LT
582 return 0;
583} /* end of claw_open */
584
585/*-------------------------------------------------------------------*
586* *
587* claw_irq_handler *
588* *
589*--------------------------------------------------------------------*/
590static void
591claw_irq_handler(struct ccw_device *cdev,
592 unsigned long intparm, struct irb *irb)
593{
594 struct chbk *p_ch = NULL;
595 struct claw_privbk *privptr = NULL;
596 struct net_device *dev = NULL;
597 struct claw_env *p_env;
598 struct chbk *p_ch_r=NULL;
599
b805da74 600 CLAW_DBF_TEXT(4, trace, "clawirq");
1da177e4 601 /* Bypass all 'unsolicited interrupts' */
dff59b64
GKH
602 privptr = dev_get_drvdata(&cdev->dev);
603 if (!privptr) {
4811fcb7
AR
604 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
605 " IRQ, c-%02x d-%02x\n",
606 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
b805da74 607 CLAW_DBF_TEXT(2, trace, "badirq");
1da177e4
LT
608 return;
609 }
1da177e4
LT
610
611 /* Try to extract channel from driver data. */
612 if (privptr->channel[READ].cdev == cdev)
613 p_ch = &privptr->channel[READ];
614 else if (privptr->channel[WRITE].cdev == cdev)
615 p_ch = &privptr->channel[WRITE];
616 else {
4811fcb7 617 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
b805da74 618 CLAW_DBF_TEXT(2, trace, "badchan");
1da177e4
LT
619 return;
620 }
b805da74 621 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
1da177e4
LT
622
623 dev = (struct net_device *) (p_ch->ndev);
624 p_env=privptr->p_env;
625
1da177e4
LT
626 /* Copy interruption response block. */
627 memcpy(p_ch->irb, irb, sizeof(struct irb));
628
b805da74 629 /* Check for good subchannel return code, otherwise info message */
23d805b6 630 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
4811fcb7
AR
631 dev_info(&cdev->dev,
632 "%s: subchannel check for device: %04x -"
1da177e4
LT
633 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
634 dev->name, p_ch->devno,
23d805b6
PO
635 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
636 irb->scsw.cmd.cpa);
b805da74 637 CLAW_DBF_TEXT(2, trace, "chanchk");
1da177e4
LT
638 /* return; */
639 }
640
641 /* Check the reason-code of a unit check */
23d805b6 642 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
1da177e4 643 ccw_check_unit_check(p_ch, irb->ecw[0]);
1da177e4
LT
644
645 /* State machine to bring the connection up, down and to restart */
23d805b6 646 p_ch->last_dstat = irb->scsw.cmd.dstat;
1da177e4
LT
647
648 switch (p_ch->claw_state) {
b805da74
AR
649 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
650 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
651 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
652 (p_ch->irb->scsw.cmd.stctl ==
653 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
654 return;
655 wake_up(&p_ch->wait); /* wake up claw_release */
656 CLAW_DBF_TEXT(4, trace, "stop");
657 return;
658 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
659 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
660 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
661 (p_ch->irb->scsw.cmd.stctl ==
662 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
663 CLAW_DBF_TEXT(4, trace, "haltio");
664 return;
665 }
666 if (p_ch->flag == CLAW_READ) {
667 p_ch->claw_state = CLAW_START_READ;
668 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
669 } else if (p_ch->flag == CLAW_WRITE) {
670 p_ch->claw_state = CLAW_START_WRITE;
4811fcb7 671 /* send SYSTEM_VALIDATE */
b805da74
AR
672 claw_strt_read(dev, LOCK_NO);
673 claw_send_control(dev,
674 SYSTEM_VALIDATE_REQUEST,
675 0, 0, 0,
676 p_env->host_name,
677 p_env->adapter_name);
678 } else {
4811fcb7
AR
679 dev_warn(&cdev->dev, "The CLAW device received"
680 " an unexpected IRQ, "
681 "c-%02x d-%02x\n",
b805da74
AR
682 irb->scsw.cmd.cstat,
683 irb->scsw.cmd.dstat);
684 return;
685 }
686 CLAW_DBF_TEXT(4, trace, "haltio");
687 return;
688 case CLAW_START_READ:
689 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
690 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
691 clear_bit(0, (void *)&p_ch->IO_active);
692 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
693 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
694 (p_ch->irb->ecw[0]) == 0) {
695 privptr->stats.rx_errors++;
4811fcb7
AR
696 dev_info(&cdev->dev,
697 "%s: Restart is required after remote "
b805da74
AR
698 "side recovers \n",
699 dev->name);
700 }
701 CLAW_DBF_TEXT(4, trace, "notrdy");
702 return;
703 }
704 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
705 (p_ch->irb->scsw.cmd.dstat == 0)) {
706 if (test_and_set_bit(CLAW_BH_ACTIVE,
707 (void *)&p_ch->flag_a) == 0)
708 tasklet_schedule(&p_ch->tasklet);
1da177e4 709 else
b805da74
AR
710 CLAW_DBF_TEXT(4, trace, "PCINoBH");
711 CLAW_DBF_TEXT(4, trace, "PCI_read");
712 return;
713 }
714 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
715 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
716 (p_ch->irb->scsw.cmd.stctl ==
717 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
718 CLAW_DBF_TEXT(4, trace, "SPend_rd");
719 return;
720 }
721 clear_bit(0, (void *)&p_ch->IO_active);
722 claw_clearbit_busy(TB_RETRY, dev);
723 if (test_and_set_bit(CLAW_BH_ACTIVE,
724 (void *)&p_ch->flag_a) == 0)
725 tasklet_schedule(&p_ch->tasklet);
726 else
727 CLAW_DBF_TEXT(4, trace, "RdBHAct");
728 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
729 return;
730 case CLAW_START_WRITE:
731 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
4811fcb7
AR
732 dev_info(&cdev->dev,
733 "%s: Unit Check Occured in "
b805da74
AR
734 "write channel\n", dev->name);
735 clear_bit(0, (void *)&p_ch->IO_active);
736 if (p_ch->irb->ecw[0] & 0x80) {
4811fcb7
AR
737 dev_info(&cdev->dev,
738 "%s: Resetting Event "
b805da74
AR
739 "occurred:\n", dev->name);
740 init_timer(&p_ch->timer);
741 p_ch->timer.function =
742 (void *)claw_write_retry;
743 p_ch->timer.data = (unsigned long)p_ch;
744 p_ch->timer.expires = jiffies + 10*HZ;
745 add_timer(&p_ch->timer);
4811fcb7
AR
746 dev_info(&cdev->dev,
747 "%s: write connection "
b805da74
AR
748 "restarting\n", dev->name);
749 }
750 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
751 return;
752 }
753 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
754 clear_bit(0, (void *)&p_ch->IO_active);
4811fcb7
AR
755 dev_info(&cdev->dev,
756 "%s: Unit Exception "
757 "occurred in write channel\n",
758 dev->name);
b805da74
AR
759 }
760 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
761 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
762 (p_ch->irb->scsw.cmd.stctl ==
763 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
764 CLAW_DBF_TEXT(4, trace, "writeUE");
765 return;
766 }
767 clear_bit(0, (void *)&p_ch->IO_active);
768 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
769 claw_write_next(p_ch);
770 claw_clearbit_busy(TB_TX, dev);
771 claw_clear_busy(dev);
772 }
773 p_ch_r = (struct chbk *)&privptr->channel[READ];
774 if (test_and_set_bit(CLAW_BH_ACTIVE,
775 (void *)&p_ch_r->flag_a) == 0)
776 tasklet_schedule(&p_ch_r->tasklet);
777 CLAW_DBF_TEXT(4, trace, "StWtExit");
778 return;
779 default:
4811fcb7
AR
780 dev_warn(&cdev->dev,
781 "The CLAW device for %s received an unexpected IRQ\n",
782 dev->name);
b805da74
AR
783 CLAW_DBF_TEXT(2, trace, "badIRQ");
784 return;
1da177e4
LT
785 }
786
787} /* end of claw_irq_handler */
788
789
790/*-------------------------------------------------------------------*
791* claw_irq_tasklet *
792* *
793*--------------------------------------------------------------------*/
794static void
795claw_irq_tasklet ( unsigned long data )
796{
797 struct chbk * p_ch;
798 struct net_device *dev;
799 struct claw_privbk * privptr;
800
801 p_ch = (struct chbk *) data;
802 dev = (struct net_device *)p_ch->ndev;
b805da74 803 CLAW_DBF_TEXT(4, trace, "IRQtask");
6951df34 804 privptr = (struct claw_privbk *)dev->ml_priv;
1da177e4
LT
805 unpack_read(dev);
806 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
b805da74 807 CLAW_DBF_TEXT(4, trace, "TskletXt");
1da177e4
LT
808 return;
809} /* end of claw_irq_bh */
810
811/*-------------------------------------------------------------------*
812* claw_release *
813* *
814*--------------------------------------------------------------------*/
815static int
816claw_release(struct net_device *dev)
817{
818 int rc;
819 int i;
820 unsigned long saveflags;
821 unsigned long parm;
822 struct claw_privbk *privptr;
823 DECLARE_WAITQUEUE(wait, current);
824 struct ccwbk* p_this_ccw;
825 struct ccwbk* p_buf;
826
827 if (!dev)
828 return 0;
6951df34 829 privptr = (struct claw_privbk *)dev->ml_priv;
1da177e4
LT
830 if (!privptr)
831 return 0;
b805da74 832 CLAW_DBF_TEXT(4, trace, "release");
1da177e4
LT
833 privptr->release_pend=1;
834 claw_setbit_busy(TB_STOP,dev);
835 for ( i = 1; i >=0 ; i--) {
836 spin_lock_irqsave(
837 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
838 /* del_timer(&privptr->channel[READ].timer); */
839 privptr->channel[i].claw_state = CLAW_STOP;
840 privptr->channel[i].IO_active = 0;
841 parm = (unsigned long) &privptr->channel[i];
842 if (i == WRITE)
843 claw_purge_skb_queue(
844 &privptr->channel[WRITE].collect_queue);
845 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
846 if (privptr->system_validate_comp==0x00) /* never opened? */
847 init_waitqueue_head(&privptr->channel[i].wait);
848 add_wait_queue(&privptr->channel[i].wait, &wait);
849 set_current_state(TASK_INTERRUPTIBLE);
850 spin_unlock_irqrestore(
851 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
852 schedule();
853 set_current_state(TASK_RUNNING);
854 remove_wait_queue(&privptr->channel[i].wait, &wait);
855 if (rc != 0) {
856 ccw_check_return_code(privptr->channel[i].cdev, rc);
857 }
858 }
859 if (privptr->pk_skb != NULL) {
8e84c801 860 dev_kfree_skb_any(privptr->pk_skb);
1da177e4
LT
861 privptr->pk_skb = NULL;
862 }
863 if(privptr->buffs_alloc != 1) {
b805da74 864 CLAW_DBF_TEXT(4, trace, "none2fre");
1da177e4
LT
865 return 0;
866 }
b805da74 867 CLAW_DBF_TEXT(4, trace, "freebufs");
1da177e4
LT
868 if (privptr->p_buff_ccw != NULL) {
869 free_pages((unsigned long)privptr->p_buff_ccw,
870 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
871 }
b805da74 872 CLAW_DBF_TEXT(4, trace, "freeread");
1da177e4
LT
873 if (privptr->p_env->read_size < PAGE_SIZE) {
874 if (privptr->p_buff_read != NULL) {
875 free_pages((unsigned long)privptr->p_buff_read,
876 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
877 }
878 }
879 else {
880 p_buf=privptr->p_read_active_first;
881 while (p_buf!=NULL) {
882 free_pages((unsigned long)p_buf->p_buffer,
883 (int)pages_to_order_of_mag(
884 privptr->p_buff_pages_perread ));
885 p_buf=p_buf->next;
886 }
887 }
b805da74 888 CLAW_DBF_TEXT(4, trace, "freewrit");
1da177e4
LT
889 if (privptr->p_env->write_size < PAGE_SIZE ) {
890 free_pages((unsigned long)privptr->p_buff_write,
891 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
892 }
893 else {
894 p_buf=privptr->p_write_active_first;
895 while (p_buf!=NULL) {
896 free_pages((unsigned long)p_buf->p_buffer,
897 (int)pages_to_order_of_mag(
898 privptr->p_buff_pages_perwrite ));
899 p_buf=p_buf->next;
900 }
901 }
b805da74 902 CLAW_DBF_TEXT(4, trace, "clearptr");
1da177e4
LT
903 privptr->buffs_alloc = 0;
904 privptr->p_buff_ccw=NULL;
905 privptr->p_buff_read=NULL;
906 privptr->p_buff_write=NULL;
907 privptr->system_validate_comp=0;
908 privptr->release_pend=0;
909 /* Remove any writes that were pending and reset all reads */
910 p_this_ccw=privptr->p_read_active_first;
911 while (p_this_ccw!=NULL) {
912 p_this_ccw->header.length=0xffff;
913 p_this_ccw->header.opcode=0xff;
914 p_this_ccw->header.flag=0x00;
915 p_this_ccw=p_this_ccw->next;
916 }
917
918 while (privptr->p_write_active_first!=NULL) {
919 p_this_ccw=privptr->p_write_active_first;
920 p_this_ccw->header.flag=CLAW_PENDING;
921 privptr->p_write_active_first=p_this_ccw->next;
922 p_this_ccw->next=privptr->p_write_free_chain;
923 privptr->p_write_free_chain=p_this_ccw;
924 ++privptr->write_free_count;
925 }
926 privptr->p_write_active_last=NULL;
927 privptr->mtc_logical_link = -1;
928 privptr->mtc_skipping = 1;
929 privptr->mtc_offset=0;
930
931 if (((privptr->channel[READ].last_dstat |
932 privptr->channel[WRITE].last_dstat) &
933 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
4811fcb7
AR
934 dev_warn(&privptr->channel[READ].cdev->dev,
935 "Deactivating %s completed with incorrect"
936 " subchannel status "
937 "(read %02x, write %02x)\n",
1da177e4
LT
938 dev->name,
939 privptr->channel[READ].last_dstat,
940 privptr->channel[WRITE].last_dstat);
b805da74 941 CLAW_DBF_TEXT(2, trace, "badclose");
1da177e4 942 }
b805da74 943 CLAW_DBF_TEXT(4, trace, "rlsexit");
1da177e4
LT
944 return 0;
945} /* end of claw_release */
946
1da177e4
LT
947/*-------------------------------------------------------------------*
948* claw_write_retry *
949* *
950*--------------------------------------------------------------------*/
951
952static void
953claw_write_retry ( struct chbk *p_ch )
954{
955
956 struct net_device *dev=p_ch->ndev;
957
b805da74 958 CLAW_DBF_TEXT(4, trace, "w_retry");
1da177e4 959 if (p_ch->claw_state == CLAW_STOP) {
1da177e4
LT
960 return;
961 }
1da177e4 962 claw_strt_out_IO( dev );
b805da74 963 CLAW_DBF_TEXT(4, trace, "rtry_xit");
1da177e4
LT
964 return;
965} /* end of claw_write_retry */
966
967
968/*-------------------------------------------------------------------*
969* claw_write_next *
970* *
971*--------------------------------------------------------------------*/
972
973static void
974claw_write_next ( struct chbk * p_ch )
975{
976
977 struct net_device *dev;
978 struct claw_privbk *privptr=NULL;
979 struct sk_buff *pk_skb;
980 int rc;
981
b805da74 982 CLAW_DBF_TEXT(4, trace, "claw_wrt");
1da177e4
LT
983 if (p_ch->claw_state == CLAW_STOP)
984 return;
985 dev = (struct net_device *) p_ch->ndev;
6951df34 986 privptr = (struct claw_privbk *) dev->ml_priv;
1da177e4
LT
987 claw_free_wrt_buf( dev );
988 if ((privptr->write_free_count > 0) &&
b03efcfb 989 !skb_queue_empty(&p_ch->collect_queue)) {
1da177e4
LT
990 pk_skb = claw_pack_skb(privptr);
991 while (pk_skb != NULL) {
992 rc = claw_hw_tx( pk_skb, dev,1);
993 if (privptr->write_free_count > 0) {
994 pk_skb = claw_pack_skb(privptr);
995 } else
996 pk_skb = NULL;
997 }
998 }
999 if (privptr->p_write_active_first!=NULL) {
1000 claw_strt_out_IO(dev);
1001 }
1da177e4
LT
1002 return;
1003} /* end of claw_write_next */
1004
1005/*-------------------------------------------------------------------*
1006* *
1007* claw_timer *
1008*--------------------------------------------------------------------*/
1009
1010static void
1011claw_timer ( struct chbk * p_ch )
1012{
b805da74 1013 CLAW_DBF_TEXT(4, trace, "timer");
1da177e4
LT
1014 p_ch->flag |= CLAW_TIMER;
1015 wake_up(&p_ch->wait);
1da177e4
LT
1016 return;
1017} /* end of claw_timer */
1018
1da177e4
LT
1019/*
1020*
1021* functions
1022*/
1023
1024
1025/*-------------------------------------------------------------------*
1026* *
1027* pages_to_order_of_mag *
1028* *
1029* takes a number of pages from 1 to 512 and returns the *
1030* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1031* of magnitude get_free_pages() has an upper order of 9 *
1032*--------------------------------------------------------------------*/
1033
4d284cac 1034static int
1da177e4
LT
1035pages_to_order_of_mag(int num_of_pages)
1036{
1037 int order_of_mag=1; /* assume 2 pages */
b9d2fcee 1038 int nump;
b805da74
AR
1039
1040 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
1da177e4
LT
1041 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1042 /* 512 pages = 2Meg on 4k page systems */
1043 if (num_of_pages >= 512) {return 9; }
1044 /* we have two or more pages order is at least 1 */
1045 for (nump=2 ;nump <= 512;nump*=2) {
1046 if (num_of_pages <= nump)
1047 break;
1048 order_of_mag +=1;
1049 }
1050 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
b805da74 1051 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
1da177e4
LT
1052 return order_of_mag;
1053}
1054
1055/*-------------------------------------------------------------------*
1056* *
1057* add_claw_reads *
1058* *
1059*--------------------------------------------------------------------*/
1060static int
1061add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1062 struct ccwbk* p_last)
1063{
1064 struct claw_privbk *privptr;
1065 struct ccw1 temp_ccw;
1066 struct endccw * p_end;
b805da74 1067 CLAW_DBF_TEXT(4, trace, "addreads");
6951df34 1068 privptr = dev->ml_priv;
1da177e4
LT
1069 p_end = privptr->p_end_ccw;
1070
1071 /* first CCW and last CCW contains a new set of read channel programs
1072 * to apend the running channel programs
1073 */
1074 if ( p_first==NULL) {
b805da74 1075 CLAW_DBF_TEXT(4, trace, "addexit");
1da177e4
LT
1076 return 0;
1077 }
1078
1079 /* set up ending CCW sequence for this segment */
1080 if (p_end->read1) {
1081 p_end->read1=0x00; /* second ending CCW is now active */
1082 /* reset ending CCWs and setup TIC CCWs */
1083 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1084 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1085 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1086 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1087 p_end->read2_nop2.cda=0;
1088 p_end->read2_nop2.count=1;
1089 }
1090 else {
1091 p_end->read1=0x01; /* first ending CCW is now active */
1092 /* reset ending CCWs and setup TIC CCWs */
1093 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1094 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1095 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1096 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1097 p_end->read1_nop2.cda=0;
1098 p_end->read1_nop2.count=1;
1099 }
1100
1101 if ( privptr-> p_read_active_first ==NULL ) {
4811fcb7
AR
1102 privptr->p_read_active_first = p_first; /* set new first */
1103 privptr->p_read_active_last = p_last; /* set new last */
1da177e4
LT
1104 }
1105 else {
1106
1da177e4
LT
1107 /* set up TIC ccw */
1108 temp_ccw.cda= (__u32)__pa(&p_first->read);
1109 temp_ccw.count=0;
1110 temp_ccw.flags=0;
1111 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1112
1113
1114 if (p_end->read1) {
1115
1116 /* first set of CCW's is chained to the new read */
1117 /* chain, so the second set is chained to the active chain. */
1118 /* Therefore modify the second set to point to the new */
1119 /* read chain set up TIC CCWs */
1120 /* make sure we update the CCW so channel doesn't fetch it */
1121 /* when it's only half done */
1122 memcpy( &p_end->read2_nop2, &temp_ccw ,
1123 sizeof(struct ccw1));
1124 privptr->p_read_active_last->r_TIC_1.cda=
1125 (__u32)__pa(&p_first->read);
1126 privptr->p_read_active_last->r_TIC_2.cda=
1127 (__u32)__pa(&p_first->read);
1128 }
1129 else {
1130 /* make sure we update the CCW so channel doesn't */
1131 /* fetch it when it is only half done */
1132 memcpy( &p_end->read1_nop2, &temp_ccw ,
1133 sizeof(struct ccw1));
1134 privptr->p_read_active_last->r_TIC_1.cda=
1135 (__u32)__pa(&p_first->read);
1136 privptr->p_read_active_last->r_TIC_2.cda=
1137 (__u32)__pa(&p_first->read);
1138 }
4811fcb7 1139 /* chain in new set of blocks */
1da177e4
LT
1140 privptr->p_read_active_last->next = p_first;
1141 privptr->p_read_active_last=p_last;
1142 } /* end of if ( privptr-> p_read_active_first ==NULL) */
b805da74 1143 CLAW_DBF_TEXT(4, trace, "addexit");
1da177e4
LT
1144 return 0;
1145} /* end of add_claw_reads */
1146
1147/*-------------------------------------------------------------------*
1148 * ccw_check_return_code *
1149 * *
1150 *-------------------------------------------------------------------*/
1151
4d284cac 1152static void
1da177e4
LT
1153ccw_check_return_code(struct ccw_device *cdev, int return_code)
1154{
b805da74 1155 CLAW_DBF_TEXT(4, trace, "ccwret");
1da177e4
LT
1156 if (return_code != 0) {
1157 switch (return_code) {
b805da74
AR
1158 case -EBUSY: /* BUSY is a transient state no action needed */
1159 break;
1160 case -ENODEV:
4811fcb7
AR
1161 dev_err(&cdev->dev, "The remote channel adapter is not"
1162 " available\n");
b805da74
AR
1163 break;
1164 case -EINVAL:
4811fcb7
AR
1165 dev_err(&cdev->dev,
1166 "The status of the remote channel adapter"
1167 " is not valid\n");
b805da74
AR
1168 break;
1169 default:
4811fcb7
AR
1170 dev_err(&cdev->dev, "The common device layer"
1171 " returned error code %d\n",
1172 return_code);
b805da74
AR
1173 }
1174 }
1175 CLAW_DBF_TEXT(4, trace, "ccwret");
1da177e4
LT
1176} /* end of ccw_check_return_code */
1177
1178/*-------------------------------------------------------------------*
1179* ccw_check_unit_check *
1180*--------------------------------------------------------------------*/
1181
4d284cac 1182static void
1da177e4
LT
1183ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1184{
b805da74 1185 struct net_device *ndev = p_ch->ndev;
4811fcb7 1186 struct device *dev = &p_ch->cdev->dev;
1da177e4 1187
b805da74 1188 CLAW_DBF_TEXT(4, trace, "unitchek");
4811fcb7
AR
1189 dev_warn(dev, "The communication peer of %s disconnected\n",
1190 ndev->name);
1da177e4 1191
b9d2fcee
AR
1192 if (sense & 0x40) {
1193 if (sense & 0x01) {
4811fcb7
AR
1194 dev_warn(dev, "The remote channel adapter for"
1195 " %s has been reset\n",
1196 ndev->name);
b9d2fcee
AR
1197 }
1198 } else if (sense & 0x20) {
1199 if (sense & 0x04) {
4811fcb7
AR
1200 dev_warn(dev, "A data streaming timeout occurred"
1201 " for %s\n",
1202 ndev->name);
b9d2fcee 1203 } else if (sense & 0x10) {
4811fcb7
AR
1204 dev_warn(dev, "The remote channel adapter for %s"
1205 " is faulty\n",
1206 ndev->name);
b9d2fcee
AR
1207 } else {
1208 dev_warn(dev, "A data transfer parity error occurred"
4811fcb7
AR
1209 " for %s\n",
1210 ndev->name);
b9d2fcee
AR
1211 }
1212 } else if (sense & 0x10) {
1213 dev_warn(dev, "A read data parity error occurred"
1214 " for %s\n",
1215 ndev->name);
1216 }
1da177e4 1217
1da177e4
LT
1218} /* end of ccw_check_unit_check */
1219
1da177e4
LT
1220/*-------------------------------------------------------------------*
1221* find_link *
1222*--------------------------------------------------------------------*/
1223static int
1224find_link(struct net_device *dev, char *host_name, char *ws_name )
1225{
1226 struct claw_privbk *privptr;
1227 struct claw_env *p_env;
1228 int rc=0;
1229
b805da74 1230 CLAW_DBF_TEXT(2, setup, "findlink");
6951df34 1231 privptr = dev->ml_priv;
1da177e4
LT
1232 p_env=privptr->p_env;
1233 switch (p_env->packing)
1234 {
1235 case PACKING_ASK:
1236 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1237 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1238 rc = EINVAL;
1239 break;
1240 case DO_PACKED:
1241 case PACK_SEND:
1242 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1243 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1244 rc = EINVAL;
1245 break;
1246 default:
1247 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1248 (memcmp(p_env->api_type , ws_name, 8)!=0))
1249 rc = EINVAL;
1250 break;
1251 }
1252
b9d2fcee 1253 return rc;
1da177e4
LT
1254} /* end of find_link */
1255
1256/*-------------------------------------------------------------------*
1257 * claw_hw_tx *
1258 * *
1259 * *
1260 *-------------------------------------------------------------------*/
1261
1262static int
1263claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1264{
1265 int rc=0;
1266 struct claw_privbk *privptr;
1267 struct ccwbk *p_this_ccw;
1268 struct ccwbk *p_first_ccw;
1269 struct ccwbk *p_last_ccw;
1270 __u32 numBuffers;
1271 signed long len_of_data;
1272 unsigned long bytesInThisBuffer;
1273 unsigned char *pDataAddress;
1274 struct endccw *pEnd;
1275 struct ccw1 tempCCW;
1276 struct chbk *p_ch;
1277 struct claw_env *p_env;
1278 int lock;
1279 struct clawph *pk_head;
1280 struct chbk *ch;
b805da74
AR
1281
1282 CLAW_DBF_TEXT(4, trace, "hw_tx");
6951df34 1283 privptr = (struct claw_privbk *)(dev->ml_priv);
1da177e4
LT
1284 p_ch=(struct chbk *)&privptr->channel[WRITE];
1285 p_env =privptr->p_env;
1da177e4
LT
1286 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1287 /* scan the write queue to free any completed write packets */
1288 p_first_ccw=NULL;
1289 p_last_ccw=NULL;
1290 if ((p_env->packing >= PACK_SEND) &&
1291 (skb->cb[1] != 'P')) {
1292 skb_push(skb,sizeof(struct clawph));
1293 pk_head=(struct clawph *)skb->data;
1294 pk_head->len=skb->len-sizeof(struct clawph);
1295 if (pk_head->len%4) {
1296 pk_head->len+= 4-(pk_head->len%4);
1297 skb_pad(skb,4-(pk_head->len%4));
1298 skb_put(skb,4-(pk_head->len%4));
1299 }
1300 if (p_env->packing == DO_PACKED)
1301 pk_head->link_num = linkid;
1302 else
1303 pk_head->link_num = 0;
1304 pk_head->flag = 0x00;
1305 skb_pad(skb,4);
1306 skb->cb[1] = 'P';
1307 }
1308 if (linkid == 0) {
1309 if (claw_check_busy(dev)) {
1310 if (privptr->write_free_count!=0) {
1311 claw_clear_busy(dev);
1312 }
1313 else {
1314 claw_strt_out_IO(dev );
1315 claw_free_wrt_buf( dev );
1316 if (privptr->write_free_count==0) {
1da177e4
LT
1317 ch = &privptr->channel[WRITE];
1318 atomic_inc(&skb->users);
1319 skb_queue_tail(&ch->collect_queue, skb);
1320 goto Done;
1321 }
1322 else {
1323 claw_clear_busy(dev);
1324 }
1325 }
1326 }
1327 /* tx lock */
1328 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1da177e4
LT
1329 ch = &privptr->channel[WRITE];
1330 atomic_inc(&skb->users);
1331 skb_queue_tail(&ch->collect_queue, skb);
1332 claw_strt_out_IO(dev );
1333 rc=-EBUSY;
1334 goto Done2;
1335 }
1336 }
1337 /* See how many write buffers are required to hold this data */
f5154fbf 1338 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1da177e4
LT
1339
1340 /* If that number of buffers isn't available, give up for now */
1341 if (privptr->write_free_count < numBuffers ||
1342 privptr->p_write_free_chain == NULL ) {
1343
1344 claw_setbit_busy(TB_NOBUFFER,dev);
1da177e4
LT
1345 ch = &privptr->channel[WRITE];
1346 atomic_inc(&skb->users);
1347 skb_queue_tail(&ch->collect_queue, skb);
b805da74 1348 CLAW_DBF_TEXT(2, trace, "clawbusy");
1da177e4
LT
1349 goto Done2;
1350 }
1351 pDataAddress=skb->data;
1352 len_of_data=skb->len;
1353
1354 while (len_of_data > 0) {
1da177e4
LT
1355 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1356 if (p_this_ccw == NULL) { /* lost the race */
1357 ch = &privptr->channel[WRITE];
1358 atomic_inc(&skb->users);
1359 skb_queue_tail(&ch->collect_queue, skb);
1360 goto Done2;
1361 }
1362 privptr->p_write_free_chain=p_this_ccw->next;
1363 p_this_ccw->next=NULL;
1364 --privptr->write_free_count; /* -1 */
b9d2fcee
AR
1365 if (len_of_data >= privptr->p_env->write_size)
1366 bytesInThisBuffer = privptr->p_env->write_size;
1367 else
1368 bytesInThisBuffer = len_of_data;
1da177e4
LT
1369 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1370 len_of_data-=bytesInThisBuffer;
1371 pDataAddress+=(unsigned long)bytesInThisBuffer;
1372 /* setup write CCW */
1373 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1374 if (len_of_data>0) {
1375 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1376 }
1377 p_this_ccw->write.count=bytesInThisBuffer;
1378 /* now add to end of this chain */
1379 if (p_first_ccw==NULL) {
1380 p_first_ccw=p_this_ccw;
1381 }
1382 if (p_last_ccw!=NULL) {
1383 p_last_ccw->next=p_this_ccw;
1384 /* set up TIC ccws */
1385 p_last_ccw->w_TIC_1.cda=
1386 (__u32)__pa(&p_this_ccw->write);
1387 }
1388 p_last_ccw=p_this_ccw; /* save new last block */
1da177e4
LT
1389 }
1390
1391 /* FirstCCW and LastCCW now contain a new set of write channel
1392 * programs to append to the running channel program
1393 */
1394
1395 if (p_first_ccw!=NULL) {
4811fcb7 1396 /* setup ending ccw sequence for this segment */
1da177e4
LT
1397 pEnd=privptr->p_end_ccw;
1398 if (pEnd->write1) {
1399 pEnd->write1=0x00; /* second end ccw is now active */
1400 /* set up Tic CCWs */
1401 p_last_ccw->w_TIC_1.cda=
1402 (__u32)__pa(&pEnd->write2_nop1);
1403 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1404 pEnd->write2_nop2.flags =
1405 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1406 pEnd->write2_nop2.cda=0;
1407 pEnd->write2_nop2.count=1;
1408 }
1409 else { /* end of if (pEnd->write1)*/
1410 pEnd->write1=0x01; /* first end ccw is now active */
1411 /* set up Tic CCWs */
1412 p_last_ccw->w_TIC_1.cda=
1413 (__u32)__pa(&pEnd->write1_nop1);
1414 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1415 pEnd->write1_nop2.flags =
1416 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1417 pEnd->write1_nop2.cda=0;
1418 pEnd->write1_nop2.count=1;
1419 } /* end if if (pEnd->write1) */
1420
1da177e4
LT
1421 if (privptr->p_write_active_first==NULL ) {
1422 privptr->p_write_active_first=p_first_ccw;
1423 privptr->p_write_active_last=p_last_ccw;
1424 }
1425 else {
1da177e4
LT
1426 /* set up Tic CCWs */
1427
1428 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1429 tempCCW.count=0;
1430 tempCCW.flags=0;
1431 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1432
1433 if (pEnd->write1) {
1434
1435 /*
1436 * first set of ending CCW's is chained to the new write
1437 * chain, so the second set is chained to the active chain
1438 * Therefore modify the second set to point the new write chain.
1439 * make sure we update the CCW atomically
1440 * so channel does not fetch it when it's only half done
1441 */
1442 memcpy( &pEnd->write2_nop2, &tempCCW ,
1443 sizeof(struct ccw1));
1444 privptr->p_write_active_last->w_TIC_1.cda=
1445 (__u32)__pa(&p_first_ccw->write);
1446 }
1447 else {
1448
1449 /*make sure we update the CCW atomically
1450 *so channel does not fetch it when it's only half done
1451 */
1452 memcpy(&pEnd->write1_nop2, &tempCCW ,
1453 sizeof(struct ccw1));
1454 privptr->p_write_active_last->w_TIC_1.cda=
1455 (__u32)__pa(&p_first_ccw->write);
1456
1457 } /* end if if (pEnd->write1) */
1458
1459 privptr->p_write_active_last->next=p_first_ccw;
1460 privptr->p_write_active_last=p_last_ccw;
1461 }
1462
1463 } /* endif (p_first_ccw!=NULL) */
8e84c801 1464 dev_kfree_skb_any(skb);
1da177e4
LT
1465 if (linkid==0) {
1466 lock=LOCK_NO;
1467 }
1468 else {
1469 lock=LOCK_YES;
1470 }
1471 claw_strt_out_IO(dev );
1472 /* if write free count is zero , set NOBUFFER */
1da177e4
LT
1473 if (privptr->write_free_count==0) {
1474 claw_setbit_busy(TB_NOBUFFER,dev);
1475 }
1476Done2:
1477 claw_clearbit_busy(TB_TX,dev);
1478Done:
1da177e4
LT
1479 return(rc);
1480} /* end of claw_hw_tx */
1481
1482/*-------------------------------------------------------------------*
1483* *
1484* init_ccw_bk *
1485* *
1486*--------------------------------------------------------------------*/
1487
1488static int
1489init_ccw_bk(struct net_device *dev)
1490{
1491
1492 __u32 ccw_blocks_required;
1493 __u32 ccw_blocks_perpage;
1494 __u32 ccw_pages_required;
1495 __u32 claw_reads_perpage=1;
1496 __u32 claw_read_pages;
1497 __u32 claw_writes_perpage=1;
1498 __u32 claw_write_pages;
1499 void *p_buff=NULL;
1500 struct ccwbk*p_free_chain;
1501 struct ccwbk*p_buf;
1502 struct ccwbk*p_last_CCWB;
1503 struct ccwbk*p_first_CCWB;
1504 struct endccw *p_endccw=NULL;
6951df34
PT
1505 addr_t real_address;
1506 struct claw_privbk *privptr = dev->ml_priv;
1da177e4
LT
1507 struct clawh *pClawH=NULL;
1508 addr_t real_TIC_address;
1509 int i,j;
b805da74 1510 CLAW_DBF_TEXT(4, trace, "init_ccw");
1da177e4
LT
1511
1512 /* initialize statistics field */
1513 privptr->active_link_ID=0;
1514 /* initialize ccwbk pointers */
1515 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1516 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1517 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1518 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1519 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1520 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1521 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1522 privptr->buffs_alloc = 0;
1523 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1524 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1525 /* initialize free write ccwbk counter */
1526 privptr->write_free_count=0; /* number of free bufs on write chain */
1527 p_last_CCWB = NULL;
1528 p_first_CCWB= NULL;
1529 /*
1530 * We need 1 CCW block for each read buffer, 1 for each
1531 * write buffer, plus 1 for ClawSignalBlock
1532 */
1533 ccw_blocks_required =
1534 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
1da177e4
LT
1535 /*
1536 * compute number of CCW blocks that will fit in a page
1537 */
1538 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1539 ccw_pages_required=
f5154fbf 1540 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
1da177e4 1541
1da177e4
LT
1542 /*
1543 * read and write sizes are set by 2 constants in claw.h
1544 * 4k and 32k. Unpacked values other than 4k are not going to
1545 * provide good performance. With packing buffers support 32k
1546 * buffers are used.
1547 */
f5154fbf
JL
1548 if (privptr->p_env->read_size < PAGE_SIZE) {
1549 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1550 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1551 claw_reads_perpage);
1da177e4
LT
1552 }
1553 else { /* > or equal */
f5154fbf
JL
1554 privptr->p_buff_pages_perread =
1555 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1556 claw_read_pages = privptr->p_env->read_buffers *
1557 privptr->p_buff_pages_perread;
1da177e4
LT
1558 }
1559 if (privptr->p_env->write_size < PAGE_SIZE) {
f5154fbf
JL
1560 claw_writes_perpage =
1561 PAGE_SIZE / privptr->p_env->write_size;
1562 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1563 claw_writes_perpage);
1da177e4
LT
1564
1565 }
1566 else { /* > or equal */
f5154fbf
JL
1567 privptr->p_buff_pages_perwrite =
1568 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1569 claw_write_pages = privptr->p_env->write_buffers *
1570 privptr->p_buff_pages_perwrite;
1da177e4 1571 }
1da177e4
LT
1572 /*
1573 * allocate ccw_pages_required
1574 */
1575 if (privptr->p_buff_ccw==NULL) {
1576 privptr->p_buff_ccw=
1577 (void *)__get_free_pages(__GFP_DMA,
1578 (int)pages_to_order_of_mag(ccw_pages_required ));
1579 if (privptr->p_buff_ccw==NULL) {
1da177e4
LT
1580 return -ENOMEM;
1581 }
1582 privptr->p_buff_ccw_num=ccw_pages_required;
1583 }
1584 memset(privptr->p_buff_ccw, 0x00,
1585 privptr->p_buff_ccw_num * PAGE_SIZE);
1586
1587 /*
1588 * obtain ending ccw block address
1589 *
1590 */
1591 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1592 real_address = (__u32)__pa(privptr->p_end_ccw);
1593 /* Initialize ending CCW block */
1da177e4
LT
1594 p_endccw=privptr->p_end_ccw;
1595 p_endccw->real=real_address;
1596 p_endccw->write1=0x00;
1597 p_endccw->read1=0x00;
1598
1599 /* write1_nop1 */
1600 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1601 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1602 p_endccw->write1_nop1.count = 1;
1603 p_endccw->write1_nop1.cda = 0;
1604
1605 /* write1_nop2 */
1606 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1607 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1608 p_endccw->write1_nop2.count = 1;
1609 p_endccw->write1_nop2.cda = 0;
1610
1611 /* write2_nop1 */
1612 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1613 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1614 p_endccw->write2_nop1.count = 1;
1615 p_endccw->write2_nop1.cda = 0;
1616
1617 /* write2_nop2 */
1618 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1619 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1620 p_endccw->write2_nop2.count = 1;
1621 p_endccw->write2_nop2.cda = 0;
1622
1623 /* read1_nop1 */
1624 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1625 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1626 p_endccw->read1_nop1.count = 1;
1627 p_endccw->read1_nop1.cda = 0;
1628
1629 /* read1_nop2 */
1630 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1631 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1632 p_endccw->read1_nop2.count = 1;
1633 p_endccw->read1_nop2.cda = 0;
1634
1635 /* read2_nop1 */
1636 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1637 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1638 p_endccw->read2_nop1.count = 1;
1639 p_endccw->read2_nop1.cda = 0;
1640
1641 /* read2_nop2 */
1642 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1643 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1644 p_endccw->read2_nop2.count = 1;
1645 p_endccw->read2_nop2.cda = 0;
1646
1da177e4
LT
1647 /*
1648 * Build a chain of CCWs
1649 *
1650 */
1da177e4
LT
1651 p_buff=privptr->p_buff_ccw;
1652
1653 p_free_chain=NULL;
1654 for (i=0 ; i < ccw_pages_required; i++ ) {
1655 real_address = (__u32)__pa(p_buff);
1656 p_buf=p_buff;
1657 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1658 p_buf->next = p_free_chain;
1659 p_free_chain = p_buf;
1660 p_buf->real=(__u32)__pa(p_buf);
1661 ++p_buf;
1662 }
1663 p_buff+=PAGE_SIZE;
1664 }
1da177e4
LT
1665 /*
1666 * Initialize ClawSignalBlock
1667 *
1668 */
1da177e4
LT
1669 if (privptr->p_claw_signal_blk==NULL) {
1670 privptr->p_claw_signal_blk=p_free_chain;
1671 p_free_chain=p_free_chain->next;
1672 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1673 pClawH->length=0xffff;
1674 pClawH->opcode=0xff;
1675 pClawH->flag=CLAW_BUSY;
1676 }
1da177e4
LT
1677
1678 /*
1679 * allocate write_pages_required and add to free chain
1680 */
1681 if (privptr->p_buff_write==NULL) {
1682 if (privptr->p_env->write_size < PAGE_SIZE) {
1683 privptr->p_buff_write=
1684 (void *)__get_free_pages(__GFP_DMA,
1685 (int)pages_to_order_of_mag(claw_write_pages ));
1686 if (privptr->p_buff_write==NULL) {
1da177e4 1687 privptr->p_buff_ccw=NULL;
1da177e4
LT
1688 return -ENOMEM;
1689 }
1690 /*
1691 * Build CLAW write free chain
1692 *
1693 */
1694
1695 memset(privptr->p_buff_write, 0x00,
1696 ccw_pages_required * PAGE_SIZE);
1da177e4
LT
1697 privptr->p_write_free_chain=NULL;
1698
1699 p_buff=privptr->p_buff_write;
1700
1701 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1702 p_buf = p_free_chain; /* get a CCW */
1703 p_free_chain = p_buf->next;
1704 p_buf->next =privptr->p_write_free_chain;
1705 privptr->p_write_free_chain = p_buf;
1706 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1707 p_buf-> write.cda = (__u32)__pa(p_buff);
1708 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1709 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1710 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1711 p_buf-> w_read_FF.count = 1;
1712 p_buf-> w_read_FF.cda =
1713 (__u32)__pa(&p_buf-> header.flag);
1714 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1715 p_buf-> w_TIC_1.flags = 0;
1716 p_buf-> w_TIC_1.count = 0;
1717
4811fcb7
AR
1718 if (((unsigned long)p_buff +
1719 privptr->p_env->write_size) >=
1da177e4 1720 ((unsigned long)(p_buff+2*
4811fcb7
AR
1721 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1722 p_buff = p_buff+privptr->p_env->write_size;
1da177e4
LT
1723 }
1724 }
1725 }
1726 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1727 {
1728 privptr->p_write_free_chain=NULL;
1729 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1730 p_buff=(void *)__get_free_pages(__GFP_DMA,
1731 (int)pages_to_order_of_mag(
1732 privptr->p_buff_pages_perwrite) );
1da177e4 1733 if (p_buff==NULL) {
1da177e4
LT
1734 free_pages((unsigned long)privptr->p_buff_ccw,
1735 (int)pages_to_order_of_mag(
1736 privptr->p_buff_ccw_num));
1737 privptr->p_buff_ccw=NULL;
1738 p_buf=privptr->p_buff_write;
1739 while (p_buf!=NULL) {
1740 free_pages((unsigned long)
1741 p_buf->p_buffer,
1742 (int)pages_to_order_of_mag(
1743 privptr->p_buff_pages_perwrite));
1744 p_buf=p_buf->next;
1745 }
1da177e4
LT
1746 return -ENOMEM;
1747 } /* Error on get_pages */
1748 memset(p_buff, 0x00, privptr->p_env->write_size );
1749 p_buf = p_free_chain;
1750 p_free_chain = p_buf->next;
1751 p_buf->next = privptr->p_write_free_chain;
1752 privptr->p_write_free_chain = p_buf;
1753 privptr->p_buff_write = p_buf;
1754 p_buf->p_buffer=(struct clawbuf *)p_buff;
1755 p_buf-> write.cda = (__u32)__pa(p_buff);
1756 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1757 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1758 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1759 p_buf-> w_read_FF.count = 1;
1760 p_buf-> w_read_FF.cda =
1761 (__u32)__pa(&p_buf-> header.flag);
1762 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1763 p_buf-> w_TIC_1.flags = 0;
1764 p_buf-> w_TIC_1.count = 0;
1765 } /* for all write_buffers */
1766
1767 } /* else buffers are PAGE_SIZE or bigger */
1768
1769 }
1770 privptr->p_buff_write_num=claw_write_pages;
1771 privptr->write_free_count=privptr->p_env->write_buffers;
1772
1773
1da177e4
LT
1774 /*
1775 * allocate read_pages_required and chain to free chain
1776 */
1777 if (privptr->p_buff_read==NULL) {
1778 if (privptr->p_env->read_size < PAGE_SIZE) {
1779 privptr->p_buff_read=
1780 (void *)__get_free_pages(__GFP_DMA,
1781 (int)pages_to_order_of_mag(claw_read_pages) );
1782 if (privptr->p_buff_read==NULL) {
1da177e4
LT
1783 free_pages((unsigned long)privptr->p_buff_ccw,
1784 (int)pages_to_order_of_mag(
1785 privptr->p_buff_ccw_num));
1786 /* free the write pages size is < page size */
1787 free_pages((unsigned long)privptr->p_buff_write,
1788 (int)pages_to_order_of_mag(
1789 privptr->p_buff_write_num));
1790 privptr->p_buff_ccw=NULL;
1791 privptr->p_buff_write=NULL;
1da177e4
LT
1792 return -ENOMEM;
1793 }
1794 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1795 privptr->p_buff_read_num=claw_read_pages;
1796 /*
1797 * Build CLAW read free chain
1798 *
1799 */
1da177e4
LT
1800 p_buff=privptr->p_buff_read;
1801 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1802 p_buf = p_free_chain;
1803 p_free_chain = p_buf->next;
1804
1805 if (p_last_CCWB==NULL) {
1806 p_buf->next=NULL;
1807 real_TIC_address=0;
1808 p_last_CCWB=p_buf;
1809 }
1810 else {
1811 p_buf->next=p_first_CCWB;
1812 real_TIC_address=
1813 (__u32)__pa(&p_first_CCWB -> read );
1814 }
1815
1816 p_first_CCWB=p_buf;
1817
1818 p_buf->p_buffer=(struct clawbuf *)p_buff;
1819 /* initialize read command */
1820 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1821 p_buf-> read.cda = (__u32)__pa(p_buff);
1822 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1823 p_buf-> read.count = privptr->p_env->read_size;
1824
1825 /* initialize read_h command */
1826 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1827 p_buf-> read_h.cda =
1828 (__u32)__pa(&(p_buf->header));
1829 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1830 p_buf-> read_h.count = sizeof(struct clawh);
1831
1832 /* initialize Signal command */
1833 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1834 p_buf-> signal.cda =
1835 (__u32)__pa(&(pClawH->flag));
1836 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1837 p_buf-> signal.count = 1;
1838
1839 /* initialize r_TIC_1 command */
1840 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1841 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1842 p_buf-> r_TIC_1.flags = 0;
1843 p_buf-> r_TIC_1.count = 0;
1844
1845 /* initialize r_read_FF command */
1846 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1847 p_buf-> r_read_FF.cda =
1848 (__u32)__pa(&(pClawH->flag));
1849 p_buf-> r_read_FF.flags =
1850 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1851 p_buf-> r_read_FF.count = 1;
1852
1853 /* initialize r_TIC_2 */
1854 memcpy(&p_buf->r_TIC_2,
1855 &p_buf->r_TIC_1, sizeof(struct ccw1));
1856
1857 /* initialize Header */
1858 p_buf->header.length=0xffff;
1859 p_buf->header.opcode=0xff;
1860 p_buf->header.flag=CLAW_PENDING;
1861
4811fcb7
AR
1862 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1863 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1864 -1)
1865 & PAGE_MASK)) {
1da177e4
LT
1866 p_buff= p_buff+privptr->p_env->read_size;
1867 }
1868 else {
1869 p_buff=
1870 (void *)((unsigned long)
4811fcb7 1871 (p_buff+2*(privptr->p_env->read_size)-1)
1da177e4
LT
1872 & PAGE_MASK) ;
1873 }
1874 } /* for read_buffers */
1875 } /* read_size < PAGE_SIZE */
1876 else { /* read Size >= PAGE_SIZE */
1da177e4
LT
1877 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1878 p_buff = (void *)__get_free_pages(__GFP_DMA,
4811fcb7
AR
1879 (int)pages_to_order_of_mag(
1880 privptr->p_buff_pages_perread));
1da177e4 1881 if (p_buff==NULL) {
1da177e4 1882 free_pages((unsigned long)privptr->p_buff_ccw,
4811fcb7
AR
1883 (int)pages_to_order_of_mag(privptr->
1884 p_buff_ccw_num));
1da177e4
LT
1885 /* free the write pages */
1886 p_buf=privptr->p_buff_write;
1887 while (p_buf!=NULL) {
4811fcb7
AR
1888 free_pages(
1889 (unsigned long)p_buf->p_buffer,
1890 (int)pages_to_order_of_mag(
1891 privptr->p_buff_pages_perwrite));
1da177e4
LT
1892 p_buf=p_buf->next;
1893 }
1894 /* free any read pages already alloc */
1895 p_buf=privptr->p_buff_read;
1896 while (p_buf!=NULL) {
4811fcb7
AR
1897 free_pages(
1898 (unsigned long)p_buf->p_buffer,
1899 (int)pages_to_order_of_mag(
1900 privptr->p_buff_pages_perread));
1da177e4
LT
1901 p_buf=p_buf->next;
1902 }
1903 privptr->p_buff_ccw=NULL;
1904 privptr->p_buff_write=NULL;
1da177e4
LT
1905 return -ENOMEM;
1906 }
1907 memset(p_buff, 0x00, privptr->p_env->read_size);
1908 p_buf = p_free_chain;
1909 privptr->p_buff_read = p_buf;
1910 p_free_chain = p_buf->next;
1911
1912 if (p_last_CCWB==NULL) {
1913 p_buf->next=NULL;
1914 real_TIC_address=0;
1915 p_last_CCWB=p_buf;
1916 }
1917 else {
1918 p_buf->next=p_first_CCWB;
1919 real_TIC_address=
1920 (addr_t)__pa(
1921 &p_first_CCWB -> read );
1922 }
1923
1924 p_first_CCWB=p_buf;
1925 /* save buff address */
1926 p_buf->p_buffer=(struct clawbuf *)p_buff;
1927 /* initialize read command */
1928 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1929 p_buf-> read.cda = (__u32)__pa(p_buff);
1930 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1931 p_buf-> read.count = privptr->p_env->read_size;
1932
1933 /* initialize read_h command */
1934 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1935 p_buf-> read_h.cda =
1936 (__u32)__pa(&(p_buf->header));
1937 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1938 p_buf-> read_h.count = sizeof(struct clawh);
1939
1940 /* initialize Signal command */
1941 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1942 p_buf-> signal.cda =
1943 (__u32)__pa(&(pClawH->flag));
1944 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1945 p_buf-> signal.count = 1;
1946
1947 /* initialize r_TIC_1 command */
1948 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1949 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1950 p_buf-> r_TIC_1.flags = 0;
1951 p_buf-> r_TIC_1.count = 0;
1952
1953 /* initialize r_read_FF command */
1954 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1955 p_buf-> r_read_FF.cda =
1956 (__u32)__pa(&(pClawH->flag));
1957 p_buf-> r_read_FF.flags =
1958 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1959 p_buf-> r_read_FF.count = 1;
1960
1961 /* initialize r_TIC_2 */
1962 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1963 sizeof(struct ccw1));
1964
1965 /* initialize Header */
1966 p_buf->header.length=0xffff;
1967 p_buf->header.opcode=0xff;
1968 p_buf->header.flag=CLAW_PENDING;
1969
1970 } /* For read_buffers */
1971 } /* read_size >= PAGE_SIZE */
1972 } /* pBuffread = NULL */
1da177e4
LT
1973 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1974 privptr->buffs_alloc = 1;
b805da74 1975
1da177e4
LT
1976 return 0;
1977} /* end of init_ccw_bk */
1978
1979/*-------------------------------------------------------------------*
1980* *
1981* probe_error *
1982* *
1983*--------------------------------------------------------------------*/
1984
1985static void
1986probe_error( struct ccwgroup_device *cgdev)
1987{
2b356b46 1988 struct claw_privbk *privptr;
b805da74
AR
1989
1990 CLAW_DBF_TEXT(4, trace, "proberr");
dff59b64 1991 privptr = dev_get_drvdata(&cgdev->dev);
2b356b46 1992 if (privptr != NULL) {
dff59b64 1993 dev_set_drvdata(&cgdev->dev, NULL);
17fd682e 1994 kfree(privptr->p_env);
2b356b46
MS
1995 kfree(privptr->p_mtc_envelope);
1996 kfree(privptr);
1997 }
1da177e4
LT
1998} /* probe_error */
1999
1da177e4
LT
2000/*-------------------------------------------------------------------*
2001* claw_process_control *
2002* *
2003* *
2004*--------------------------------------------------------------------*/
2005
2006static int
2007claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2008{
2009
2010 struct clawbuf *p_buf;
2011 struct clawctl ctlbk;
2012 struct clawctl *p_ctlbk;
2013 char temp_host_name[8];
2014 char temp_ws_name[8];
2015 struct claw_privbk *privptr;
2016 struct claw_env *p_env;
2017 struct sysval *p_sysval;
2018 struct conncmd *p_connect=NULL;
2019 int rc;
2020 struct chbk *p_ch = NULL;
b805da74
AR
2021 struct device *tdev;
2022 CLAW_DBF_TEXT(2, setup, "clw_cntl");
1da177e4
LT
2023 udelay(1000); /* Wait a ms for the control packets to
2024 *catch up to each other */
6951df34 2025 privptr = dev->ml_priv;
1da177e4 2026 p_env=privptr->p_env;
b805da74 2027 tdev = &privptr->channel[READ].cdev->dev;
1da177e4
LT
2028 memcpy( &temp_host_name, p_env->host_name, 8);
2029 memcpy( &temp_ws_name, p_env->adapter_name , 8);
4811fcb7 2030 dev_info(tdev, "%s: CLAW device %.8s: "
1da177e4
LT
2031 "Received Control Packet\n",
2032 dev->name, temp_ws_name);
2033 if (privptr->release_pend==1) {
1da177e4
LT
2034 return 0;
2035 }
2036 p_buf=p_ccw->p_buffer;
2037 p_ctlbk=&ctlbk;
2038 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2039 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2040 } else {
2041 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2042 }
1da177e4
LT
2043 switch (p_ctlbk->command)
2044 {
b805da74
AR
2045 case SYSTEM_VALIDATE_REQUEST:
2046 if (p_ctlbk->version != CLAW_VERSION_ID) {
2047 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2048 CLAW_RC_WRONG_VERSION);
4811fcb7
AR
2049 dev_warn(tdev, "The communication peer of %s"
2050 " uses an incorrect API version %d\n",
2051 dev->name, p_ctlbk->version);
b805da74
AR
2052 }
2053 p_sysval = (struct sysval *)&(p_ctlbk->data);
4811fcb7
AR
2054 dev_info(tdev, "%s: Recv Sys Validate Request: "
2055 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2056 "Host name=%.8s\n",
2057 dev->name, p_ctlbk->version,
2058 p_ctlbk->linkid,
2059 p_ctlbk->correlator,
2060 p_sysval->WS_name,
2061 p_sysval->host_name);
b805da74
AR
2062 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2063 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2064 CLAW_RC_NAME_MISMATCH);
2065 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2066 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2067 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
4811fcb7
AR
2068 dev_warn(tdev,
2069 "Host name %s for %s does not match the"
2070 " remote adapter name %s\n",
b805da74 2071 p_sysval->host_name,
4811fcb7 2072 dev->name,
b805da74
AR
2073 temp_host_name);
2074 }
2075 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2076 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2077 CLAW_RC_NAME_MISMATCH);
2078 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2079 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2080 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
4811fcb7
AR
2081 dev_warn(tdev, "Adapter name %s for %s does not match"
2082 " the remote host name %s\n",
2083 p_sysval->WS_name,
2084 dev->name,
2085 temp_ws_name);
b805da74
AR
2086 }
2087 if ((p_sysval->write_frame_size < p_env->write_size) &&
2088 (p_env->packing == 0)) {
2089 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2090 CLAW_RC_HOST_RCV_TOO_SMALL);
4811fcb7
AR
2091 dev_warn(tdev,
2092 "The local write buffer is smaller than the"
2093 " remote read buffer\n");
b805da74
AR
2094 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2095 }
2096 if ((p_sysval->read_frame_size < p_env->read_size) &&
2097 (p_env->packing == 0)) {
2098 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2099 CLAW_RC_HOST_RCV_TOO_SMALL);
4811fcb7
AR
2100 dev_warn(tdev,
2101 "The local read buffer is smaller than the"
2102 " remote write buffer\n");
b805da74
AR
2103 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2104 }
2105 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
4811fcb7
AR
2106 dev_info(tdev,
2107 "CLAW device %.8s: System validate"
2108 " completed.\n", temp_ws_name);
2109 dev_info(tdev,
2110 "%s: sys Validate Rsize:%d Wsize:%d\n",
2111 dev->name, p_sysval->read_frame_size,
2112 p_sysval->write_frame_size);
b805da74
AR
2113 privptr->system_validate_comp = 1;
2114 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2115 p_env->packing = PACKING_ASK;
2116 claw_strt_conn_req(dev);
2117 break;
2118 case SYSTEM_VALIDATE_RESPONSE:
2119 p_sysval = (struct sysval *)&(p_ctlbk->data);
4811fcb7
AR
2120 dev_info(tdev,
2121 "Settings for %s validated (version=%d, "
2122 "remote device=%d, rc=%d, adapter name=%.8s, "
2123 "host name=%.8s)\n",
b805da74
AR
2124 dev->name,
2125 p_ctlbk->version,
2126 p_ctlbk->correlator,
2127 p_ctlbk->rc,
2128 p_sysval->WS_name,
2129 p_sysval->host_name);
2130 switch (p_ctlbk->rc) {
2131 case 0:
4811fcb7
AR
2132 dev_info(tdev, "%s: CLAW device "
2133 "%.8s: System validate completed.\n",
2134 dev->name, temp_ws_name);
b805da74
AR
2135 if (privptr->system_validate_comp == 0)
2136 claw_strt_conn_req(dev);
2137 privptr->system_validate_comp = 1;
2138 break;
2139 case CLAW_RC_NAME_MISMATCH:
4811fcb7
AR
2140 dev_warn(tdev, "Validating %s failed because of"
2141 " a host or adapter name mismatch\n",
2142 dev->name);
b805da74
AR
2143 break;
2144 case CLAW_RC_WRONG_VERSION:
4811fcb7
AR
2145 dev_warn(tdev, "Validating %s failed because of a"
2146 " version conflict\n",
b805da74
AR
2147 dev->name);
2148 break;
2149 case CLAW_RC_HOST_RCV_TOO_SMALL:
4811fcb7
AR
2150 dev_warn(tdev, "Validating %s failed because of a"
2151 " frame size conflict\n",
b805da74
AR
2152 dev->name);
2153 break;
2154 default:
4811fcb7
AR
2155 dev_warn(tdev, "The communication peer of %s rejected"
2156 " the connection\n",
2157 dev->name);
b805da74
AR
2158 break;
2159 }
2160 break;
1da177e4 2161
b805da74
AR
2162 case CONNECTION_REQUEST:
2163 p_connect = (struct conncmd *)&(p_ctlbk->data);
4811fcb7 2164 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
b805da74
AR
2165 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2166 dev->name,
2167 p_ctlbk->version,
2168 p_ctlbk->linkid,
2169 p_ctlbk->correlator,
2170 p_connect->host_name,
2171 p_connect->WS_name);
2172 if (privptr->active_link_ID != 0) {
2173 claw_snd_disc(dev, p_ctlbk);
4811fcb7
AR
2174 dev_info(tdev, "%s rejected a connection request"
2175 " because it is already active\n",
b805da74
AR
2176 dev->name);
2177 }
2178 if (p_ctlbk->linkid != 1) {
2179 claw_snd_disc(dev, p_ctlbk);
4811fcb7
AR
2180 dev_info(tdev, "%s rejected a request to open multiple"
2181 " connections\n",
b805da74
AR
2182 dev->name);
2183 }
2184 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2185 if (rc != 0) {
2186 claw_snd_disc(dev, p_ctlbk);
4811fcb7
AR
2187 dev_info(tdev, "%s rejected a connection request"
2188 " because of a type mismatch\n",
b805da74
AR
2189 dev->name);
2190 }
2191 claw_send_control(dev,
2192 CONNECTION_CONFIRM, p_ctlbk->linkid,
2193 p_ctlbk->correlator,
2194 0, p_connect->host_name,
2195 p_connect->WS_name);
2196 if (p_env->packing == PACKING_ASK) {
2197 p_env->packing = PACK_SEND;
2198 claw_snd_conn_req(dev, 0);
2199 }
4811fcb7 2200 dev_info(tdev, "%s: CLAW device %.8s: Connection "
b805da74
AR
2201 "completed link_id=%d.\n",
2202 dev->name, temp_ws_name,
2203 p_ctlbk->linkid);
2204 privptr->active_link_ID = p_ctlbk->linkid;
2205 p_ch = &privptr->channel[WRITE];
2206 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2207 break;
2208 case CONNECTION_RESPONSE:
2209 p_connect = (struct conncmd *)&(p_ctlbk->data);
4811fcb7 2210 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
b805da74
AR
2211 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2212 dev->name,
2213 p_ctlbk->version,
2214 p_ctlbk->linkid,
2215 p_ctlbk->correlator,
2216 p_ctlbk->rc,
2217 p_connect->host_name,
2218 p_connect->WS_name);
2219
2220 if (p_ctlbk->rc != 0) {
4811fcb7
AR
2221 dev_warn(tdev, "The communication peer of %s rejected"
2222 " a connection request\n",
2223 dev->name);
b805da74
AR
2224 return 1;
2225 }
2226 rc = find_link(dev,
2227 p_connect->host_name, p_connect->WS_name);
2228 if (rc != 0) {
2229 claw_snd_disc(dev, p_ctlbk);
4811fcb7
AR
2230 dev_warn(tdev, "The communication peer of %s"
2231 " rejected a connection "
2232 "request because of a type mismatch\n",
b805da74
AR
2233 dev->name);
2234 }
2235 /* should be until CONNECTION_CONFIRM */
2236 privptr->active_link_ID = -(p_ctlbk->linkid);
2237 break;
2238 case CONNECTION_CONFIRM:
2239 p_connect = (struct conncmd *)&(p_ctlbk->data);
4811fcb7
AR
2240 dev_info(tdev,
2241 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
b805da74
AR
2242 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2243 dev->name,
2244 p_ctlbk->version,
2245 p_ctlbk->linkid,
2246 p_ctlbk->correlator,
2247 p_connect->host_name,
2248 p_connect->WS_name);
2249 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2250 privptr->active_link_ID = p_ctlbk->linkid;
2251 if (p_env->packing > PACKING_ASK) {
4811fcb7
AR
2252 dev_info(tdev,
2253 "%s: Confirmed Now packing\n", dev->name);
1da177e4
LT
2254 p_env->packing = DO_PACKED;
2255 }
b805da74
AR
2256 p_ch = &privptr->channel[WRITE];
2257 wake_up(&p_ch->wait);
2258 } else {
4811fcb7
AR
2259 dev_warn(tdev, "Activating %s failed because of"
2260 " an incorrect link ID=%d\n",
b805da74
AR
2261 dev->name, p_ctlbk->linkid);
2262 claw_snd_disc(dev, p_ctlbk);
2263 }
2264 break;
2265 case DISCONNECT:
4811fcb7 2266 dev_info(tdev, "%s: Disconnect: "
b805da74
AR
2267 "Vers=%d,link_id=%d,Corr=%d\n",
2268 dev->name, p_ctlbk->version,
2269 p_ctlbk->linkid, p_ctlbk->correlator);
2270 if ((p_ctlbk->linkid == 2) &&
2271 (p_env->packing == PACK_SEND)) {
2272 privptr->active_link_ID = 1;
2273 p_env->packing = DO_PACKED;
2274 } else
2275 privptr->active_link_ID = 0;
2276 break;
2277 case CLAW_ERROR:
4811fcb7 2278 dev_warn(tdev, "The communication peer of %s failed\n",
b805da74
AR
2279 dev->name);
2280 break;
2281 default:
4811fcb7
AR
2282 dev_warn(tdev, "The communication peer of %s sent"
2283 " an unknown command code\n",
2284 dev->name);
b805da74 2285 break;
1da177e4
LT
2286 }
2287
1da177e4
LT
2288 return 0;
2289} /* end of claw_process_control */
2290
2291
2292/*-------------------------------------------------------------------*
2293* claw_send_control *
2294* *
2295*--------------------------------------------------------------------*/
2296
2297static int
2298claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2299 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2300{
2301 struct claw_privbk *privptr;
2302 struct clawctl *p_ctl;
2303 struct sysval *p_sysval;
2304 struct conncmd *p_connect;
2305 struct sk_buff *skb;
2306
b805da74 2307 CLAW_DBF_TEXT(2, setup, "sndcntl");
6951df34 2308 privptr = dev->ml_priv;
1da177e4
LT
2309 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2310
2311 p_ctl->command=type;
2312 p_ctl->version=CLAW_VERSION_ID;
2313 p_ctl->linkid=link;
2314 p_ctl->correlator=correlator;
2315 p_ctl->rc=rc;
2316
2317 p_sysval=(struct sysval *)&p_ctl->data;
2318 p_connect=(struct conncmd *)&p_ctl->data;
2319
2320 switch (p_ctl->command) {
2321 case SYSTEM_VALIDATE_REQUEST:
2322 case SYSTEM_VALIDATE_RESPONSE:
2323 memcpy(&p_sysval->host_name, local_name, 8);
2324 memcpy(&p_sysval->WS_name, remote_name, 8);
2325 if (privptr->p_env->packing > 0) {
4811fcb7
AR
2326 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2327 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
1da177e4 2328 } else {
b805da74 2329 /* how big is the biggest group of packets */
4811fcb7
AR
2330 p_sysval->read_frame_size =
2331 privptr->p_env->read_size;
2332 p_sysval->write_frame_size =
2333 privptr->p_env->write_size;
1da177e4
LT
2334 }
2335 memset(&p_sysval->reserved, 0x00, 4);
2336 break;
2337 case CONNECTION_REQUEST:
2338 case CONNECTION_RESPONSE:
2339 case CONNECTION_CONFIRM:
2340 case DISCONNECT:
2341 memcpy(&p_sysval->host_name, local_name, 8);
2342 memcpy(&p_sysval->WS_name, remote_name, 8);
2343 if (privptr->p_env->packing > 0) {
2344 /* How big is the biggest packet */
2345 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2346 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2347 } else {
2348 memset(&p_connect->reserved1, 0x00, 4);
2349 memset(&p_connect->reserved2, 0x00, 4);
2350 }
2351 break;
2352 default:
2353 break;
2354 }
2355
2356 /* write Control Record to the device */
2357
2358
2359 skb = dev_alloc_skb(sizeof(struct clawctl));
2360 if (!skb) {
1da177e4
LT
2361 return -ENOMEM;
2362 }
2363 memcpy(skb_put(skb, sizeof(struct clawctl)),
2364 p_ctl, sizeof(struct clawctl));
1da177e4
LT
2365 if (privptr->p_env->packing >= PACK_SEND)
2366 claw_hw_tx(skb, dev, 1);
2367 else
2368 claw_hw_tx(skb, dev, 0);
1da177e4
LT
2369 return 0;
2370} /* end of claw_send_control */
2371
2372/*-------------------------------------------------------------------*
2373* claw_snd_conn_req *
2374* *
2375*--------------------------------------------------------------------*/
2376static int
2377claw_snd_conn_req(struct net_device *dev, __u8 link)
2378{
2379 int rc;
6951df34 2380 struct claw_privbk *privptr = dev->ml_priv;
1da177e4
LT
2381 struct clawctl *p_ctl;
2382
b805da74 2383 CLAW_DBF_TEXT(2, setup, "snd_conn");
1da177e4
LT
2384 rc = 1;
2385 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2386 p_ctl->linkid = link;
2387 if ( privptr->system_validate_comp==0x00 ) {
1da177e4
LT
2388 return rc;
2389 }
2390 if (privptr->p_env->packing == PACKING_ASK )
2391 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2392 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2393 if (privptr->p_env->packing == PACK_SEND) {
2394 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2395 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2396 }
2397 if (privptr->p_env->packing == 0)
2398 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2399 HOST_APPL_NAME, privptr->p_env->api_type);
1da177e4
LT
2400 return rc;
2401
2402} /* end of claw_snd_conn_req */
2403
2404
2405/*-------------------------------------------------------------------*
2406* claw_snd_disc *
2407* *
2408*--------------------------------------------------------------------*/
2409
2410static int
2411claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2412{
2413 int rc;
2414 struct conncmd * p_connect;
2415
b805da74 2416 CLAW_DBF_TEXT(2, setup, "snd_dsc");
1da177e4
LT
2417 p_connect=(struct conncmd *)&p_ctl->data;
2418
2419 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2420 p_ctl->correlator, 0,
2421 p_connect->host_name, p_connect->WS_name);
1da177e4
LT
2422 return rc;
2423} /* end of claw_snd_disc */
2424
2425
2426/*-------------------------------------------------------------------*
2427* claw_snd_sys_validate_rsp *
2428* *
2429*--------------------------------------------------------------------*/
2430
2431static int
2432claw_snd_sys_validate_rsp(struct net_device *dev,
2433 struct clawctl *p_ctl, __u32 return_code)
2434{
2435 struct claw_env * p_env;
2436 struct claw_privbk *privptr;
2437 int rc;
2438
b805da74 2439 CLAW_DBF_TEXT(2, setup, "chkresp");
6951df34 2440 privptr = dev->ml_priv;
1da177e4
LT
2441 p_env=privptr->p_env;
2442 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2443 p_ctl->linkid,
2444 p_ctl->correlator,
2445 return_code,
2446 p_env->host_name,
2447 p_env->adapter_name );
1da177e4
LT
2448 return rc;
2449} /* end of claw_snd_sys_validate_rsp */
2450
2451/*-------------------------------------------------------------------*
2452* claw_strt_conn_req *
2453* *
2454*--------------------------------------------------------------------*/
2455
2456static int
2457claw_strt_conn_req(struct net_device *dev )
2458{
2459 int rc;
2460
b805da74 2461 CLAW_DBF_TEXT(2, setup, "conn_req");
1da177e4 2462 rc=claw_snd_conn_req(dev, 1);
1da177e4
LT
2463 return rc;
2464} /* end of claw_strt_conn_req */
2465
2466
2467
2468/*-------------------------------------------------------------------*
2469 * claw_stats *
2470 *-------------------------------------------------------------------*/
2471
2472static struct
2473net_device_stats *claw_stats(struct net_device *dev)
2474{
2475 struct claw_privbk *privptr;
b805da74
AR
2476
2477 CLAW_DBF_TEXT(4, trace, "stats");
6951df34 2478 privptr = dev->ml_priv;
1da177e4
LT
2479 return &privptr->stats;
2480} /* end of claw_stats */
2481
2482
2483/*-------------------------------------------------------------------*
2484* unpack_read *
2485* *
2486*--------------------------------------------------------------------*/
2487static void
2488unpack_read(struct net_device *dev )
2489{
2490 struct sk_buff *skb;
2491 struct claw_privbk *privptr;
2492 struct claw_env *p_env;
2493 struct ccwbk *p_this_ccw;
2494 struct ccwbk *p_first_ccw;
2495 struct ccwbk *p_last_ccw;
2496 struct clawph *p_packh;
2497 void *p_packd;
2498 struct clawctl *p_ctlrec=NULL;
b805da74 2499 struct device *p_dev;
1da177e4
LT
2500
2501 __u32 len_of_data;
2502 __u32 pack_off;
2503 __u8 link_num;
2504 __u8 mtc_this_frm=0;
2505 __u32 bytes_to_mov;
1da177e4
LT
2506 int i=0;
2507 int p=0;
2508
b805da74 2509 CLAW_DBF_TEXT(4, trace, "unpkread");
1da177e4
LT
2510 p_first_ccw=NULL;
2511 p_last_ccw=NULL;
2512 p_packh=NULL;
2513 p_packd=NULL;
6951df34 2514 privptr = dev->ml_priv;
b805da74
AR
2515
2516 p_dev = &privptr->channel[READ].cdev->dev;
1da177e4
LT
2517 p_env = privptr->p_env;
2518 p_this_ccw=privptr->p_read_active_first;
1da177e4 2519 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
1da177e4
LT
2520 pack_off = 0;
2521 p = 0;
2522 p_this_ccw->header.flag=CLAW_PENDING;
2523 privptr->p_read_active_first=p_this_ccw->next;
2524 p_this_ccw->next=NULL;
2525 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2526 if ((p_env->packing == PACK_SEND) &&
2527 (p_packh->len == 32) &&
2528 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2529 p_packh++; /* peek past pack header */
2530 p_ctlrec = (struct clawctl *)p_packh;
2531 p_packh--; /* un peek */
2532 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2533 (p_ctlrec->command == CONNECTION_CONFIRM))
2534 p_env->packing = DO_PACKED;
2535 }
2536 if (p_env->packing == DO_PACKED)
2537 link_num=p_packh->link_num;
2538 else
2539 link_num=p_this_ccw->header.opcode / 8;
2540 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
1da177e4
LT
2541 mtc_this_frm=1;
2542 if (p_this_ccw->header.length!=
2543 privptr->p_env->read_size ) {
4811fcb7
AR
2544 dev_warn(p_dev,
2545 "The communication peer of %s"
2546 " sent a faulty"
2547 " frame of length %02x\n",
1da177e4
LT
2548 dev->name, p_this_ccw->header.length);
2549 }
2550 }
2551
2552 if (privptr->mtc_skipping) {
2553 /*
2554 * We're in the mode of skipping past a
2555 * multi-frame message
2556 * that we can't process for some reason or other.
2557 * The first frame without the More-To-Come flag is
2558 * the last frame of the skipped message.
2559 */
2560 /* in case of More-To-Come not set in this frame */
2561 if (mtc_this_frm==0) {
2562 privptr->mtc_skipping=0; /* Ok, the end */
2563 privptr->mtc_logical_link=-1;
2564 }
1da177e4
LT
2565 goto NextFrame;
2566 }
2567
2568 if (link_num==0) {
2569 claw_process_control(dev, p_this_ccw);
b805da74 2570 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
1da177e4
LT
2571 goto NextFrame;
2572 }
2573unpack_next:
2574 if (p_env->packing == DO_PACKED) {
2575 if (pack_off > p_env->read_size)
2576 goto NextFrame;
2577 p_packd = p_this_ccw->p_buffer+pack_off;
2578 p_packh = (struct clawph *) p_packd;
4811fcb7 2579 if ((p_packh->len == 0) || /* done with this frame? */
1da177e4
LT
2580 (p_packh->flag != 0))
2581 goto NextFrame;
2582 bytes_to_mov = p_packh->len;
2583 pack_off += bytes_to_mov+sizeof(struct clawph);
2584 p++;
2585 } else {
2586 bytes_to_mov=p_this_ccw->header.length;
2587 }
2588 if (privptr->mtc_logical_link<0) {
1da177e4
LT
2589
2590 /*
2591 * if More-To-Come is set in this frame then we don't know
2592 * length of entire message, and hence have to allocate
2593 * large buffer */
2594
2595 /* We are starting a new envelope */
2596 privptr->mtc_offset=0;
2597 privptr->mtc_logical_link=link_num;
2598 }
2599
2600 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2601 /* error */
1da177e4
LT
2602 privptr->stats.rx_frame_errors++;
2603 goto NextFrame;
2604 }
2605 if (p_env->packing == DO_PACKED) {
2606 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2607 p_packd+sizeof(struct clawph), bytes_to_mov);
2608
2609 } else {
2610 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2611 p_this_ccw->p_buffer, bytes_to_mov);
2612 }
1da177e4
LT
2613 if (mtc_this_frm==0) {
2614 len_of_data=privptr->mtc_offset+bytes_to_mov;
2615 skb=dev_alloc_skb(len_of_data);
2616 if (skb) {
2617 memcpy(skb_put(skb,len_of_data),
2618 privptr->p_mtc_envelope,
2619 len_of_data);
1da177e4 2620 skb->dev=dev;
98e399f8 2621 skb_reset_mac_header(skb);
1da177e4
LT
2622 skb->protocol=htons(ETH_P_IP);
2623 skb->ip_summed=CHECKSUM_UNNECESSARY;
2624 privptr->stats.rx_packets++;
2625 privptr->stats.rx_bytes+=len_of_data;
2626 netif_rx(skb);
1da177e4
LT
2627 }
2628 else {
4811fcb7
AR
2629 dev_info(p_dev, "Allocating a buffer for"
2630 " incoming data failed\n");
1da177e4 2631 privptr->stats.rx_dropped++;
1da177e4
LT
2632 }
2633 privptr->mtc_offset=0;
2634 privptr->mtc_logical_link=-1;
2635 }
2636 else {
2637 privptr->mtc_offset+=bytes_to_mov;
2638 }
2639 if (p_env->packing == DO_PACKED)
2640 goto unpack_next;
2641NextFrame:
2642 /*
2643 * Remove ThisCCWblock from active read queue, and add it
2644 * to queue of free blocks to be reused.
2645 */
2646 i++;
2647 p_this_ccw->header.length=0xffff;
2648 p_this_ccw->header.opcode=0xff;
2649 /*
2650 * add this one to the free queue for later reuse
2651 */
2652 if (p_first_ccw==NULL) {
2653 p_first_ccw = p_this_ccw;
2654 }
2655 else {
2656 p_last_ccw->next = p_this_ccw;
2657 }
2658 p_last_ccw = p_this_ccw;
2659 /*
2660 * chain to next block on active read queue
2661 */
2662 p_this_ccw = privptr->p_read_active_first;
b805da74 2663 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
1da177e4
LT
2664 } /* end of while */
2665
2666 /* check validity */
2667
b805da74 2668 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
1da177e4 2669 add_claw_reads(dev, p_first_ccw, p_last_ccw);
1da177e4 2670 claw_strt_read(dev, LOCK_YES);
1da177e4
LT
2671 return;
2672} /* end of unpack_read */
2673
2674/*-------------------------------------------------------------------*
2675* claw_strt_read *
2676* *
2677*--------------------------------------------------------------------*/
2678static void
2679claw_strt_read (struct net_device *dev, int lock )
2680{
2681 int rc = 0;
2682 __u32 parm;
2683 unsigned long saveflags = 0;
6951df34 2684 struct claw_privbk *privptr = dev->ml_priv;
1da177e4
LT
2685 struct ccwbk*p_ccwbk;
2686 struct chbk *p_ch;
2687 struct clawh *p_clawh;
2688 p_ch=&privptr->channel[READ];
2689
b805da74 2690 CLAW_DBF_TEXT(4, trace, "StRdNter");
1da177e4
LT
2691 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2692 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2693
2694 if ((privptr->p_write_active_first!=NULL &&
2695 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2696 (privptr->p_read_active_first!=NULL &&
2697 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2698 p_clawh->flag=CLAW_BUSY; /* 0xff */
2699 }
1da177e4
LT
2700 if (lock==LOCK_YES) {
2701 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2702 }
2703 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
b805da74 2704 CLAW_DBF_TEXT(4, trace, "HotRead");
1da177e4
LT
2705 p_ccwbk=privptr->p_read_active_first;
2706 parm = (unsigned long) p_ch;
2707 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2708 0xff, 0);
2709 if (rc != 0) {
2710 ccw_check_return_code(p_ch->cdev, rc);
2711 }
2712 }
2713 else {
b805da74 2714 CLAW_DBF_TEXT(2, trace, "ReadAct");
1da177e4
LT
2715 }
2716
2717 if (lock==LOCK_YES) {
2718 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2719 }
b805da74 2720 CLAW_DBF_TEXT(4, trace, "StRdExit");
1da177e4
LT
2721 return;
2722} /* end of claw_strt_read */
2723
2724/*-------------------------------------------------------------------*
2725* claw_strt_out_IO *
2726* *
2727*--------------------------------------------------------------------*/
2728
2729static void
2730claw_strt_out_IO( struct net_device *dev )
2731{
2732 int rc = 0;
2733 unsigned long parm;
2734 struct claw_privbk *privptr;
2735 struct chbk *p_ch;
2736 struct ccwbk *p_first_ccw;
2737
1da177e4
LT
2738 if (!dev) {
2739 return;
2740 }
6951df34 2741 privptr = (struct claw_privbk *)dev->ml_priv;
1da177e4
LT
2742 p_ch=&privptr->channel[WRITE];
2743
b805da74 2744 CLAW_DBF_TEXT(4, trace, "strt_io");
1da177e4
LT
2745 p_first_ccw=privptr->p_write_active_first;
2746
2747 if (p_ch->claw_state == CLAW_STOP)
2748 return;
2749 if (p_first_ccw == NULL) {
1da177e4
LT
2750 return;
2751 }
2752 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2753 parm = (unsigned long) p_ch;
b805da74 2754 CLAW_DBF_TEXT(2, trace, "StWrtIO");
4811fcb7
AR
2755 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2756 0xff, 0);
1da177e4
LT
2757 if (rc != 0) {
2758 ccw_check_return_code(p_ch->cdev, rc);
2759 }
2760 }
2761 dev->trans_start = jiffies;
1da177e4
LT
2762 return;
2763} /* end of claw_strt_out_IO */
2764
2765/*-------------------------------------------------------------------*
2766* Free write buffers *
2767* *
2768*--------------------------------------------------------------------*/
2769
2770static void
2771claw_free_wrt_buf( struct net_device *dev )
2772{
2773
6951df34 2774 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
1da177e4
LT
2775 struct ccwbk*p_first_ccw;
2776 struct ccwbk*p_last_ccw;
2777 struct ccwbk*p_this_ccw;
2778 struct ccwbk*p_next_ccw;
b805da74
AR
2779
2780 CLAW_DBF_TEXT(4, trace, "freewrtb");
1da177e4
LT
2781 /* scan the write queue to free any completed write packets */
2782 p_first_ccw=NULL;
2783 p_last_ccw=NULL;
1da177e4
LT
2784 p_this_ccw=privptr->p_write_active_first;
2785 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2786 {
2787 p_next_ccw = p_this_ccw->next;
2788 if (((p_next_ccw!=NULL) &&
2789 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2790 ((p_this_ccw == privptr->p_write_active_last) &&
2791 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2792 /* The next CCW is OK or this is */
2793 /* the last CCW...free it @A1A */
2794 privptr->p_write_active_first=p_this_ccw->next;
2795 p_this_ccw->header.flag=CLAW_PENDING;
2796 p_this_ccw->next=privptr->p_write_free_chain;
2797 privptr->p_write_free_chain=p_this_ccw;
2798 ++privptr->write_free_count;
2799 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2800 p_this_ccw=privptr->p_write_active_first;
2801 privptr->stats.tx_packets++;
2802 }
2803 else {
2804 break;
2805 }
2806 }
2807 if (privptr->write_free_count!=0) {
2808 claw_clearbit_busy(TB_NOBUFFER,dev);
2809 }
2810 /* whole chain removed? */
2811 if (privptr->p_write_active_first==NULL) {
2812 privptr->p_write_active_last=NULL;
1da177e4 2813 }
b805da74 2814 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
1da177e4
LT
2815 return;
2816}
2817
2818/*-------------------------------------------------------------------*
2819* claw free netdevice *
2820* *
2821*--------------------------------------------------------------------*/
2822static void
2823claw_free_netdevice(struct net_device * dev, int free_dev)
2824{
2825 struct claw_privbk *privptr;
1da177e4 2826
b805da74 2827 CLAW_DBF_TEXT(2, setup, "free_dev");
1da177e4
LT
2828 if (!dev)
2829 return;
b805da74 2830 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
6951df34 2831 privptr = dev->ml_priv;
1da177e4
LT
2832 if (dev->flags & IFF_RUNNING)
2833 claw_release(dev);
2834 if (privptr) {
2835 privptr->channel[READ].ndev = NULL; /* say it's free */
2836 }
6951df34 2837 dev->ml_priv = NULL;
1da177e4
LT
2838#ifdef MODULE
2839 if (free_dev) {
2840 free_netdev(dev);
2841 }
2842#endif
b805da74 2843 CLAW_DBF_TEXT(2, setup, "free_ok");
1da177e4
LT
2844}
2845
2846/**
2847 * Claw init netdevice
2848 * Initialize everything of the net device except the name and the
2849 * channel structs.
2850 */
2171dc18
FB
2851static const struct net_device_ops claw_netdev_ops = {
2852 .ndo_open = claw_open,
2853 .ndo_stop = claw_release,
2854 .ndo_get_stats = claw_stats,
2855 .ndo_start_xmit = claw_tx,
2856 .ndo_change_mtu = claw_change_mtu,
2857};
2858
1da177e4
LT
2859static void
2860claw_init_netdevice(struct net_device * dev)
2861{
b805da74
AR
2862 CLAW_DBF_TEXT(2, setup, "init_dev");
2863 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
1da177e4 2864 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
1da177e4
LT
2865 dev->hard_header_len = 0;
2866 dev->addr_len = 0;
2867 dev->type = ARPHRD_SLIP;
2868 dev->tx_queue_len = 1300;
2869 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2171dc18 2870 dev->netdev_ops = &claw_netdev_ops;
b805da74 2871 CLAW_DBF_TEXT(2, setup, "initok");
1da177e4
LT
2872 return;
2873}
2874
2875/**
2876 * Init a new channel in the privptr->channel[i].
2877 *
2878 * @param cdev The ccw_device to be added.
2879 *
2880 * @return 0 on success, !0 on error.
2881 */
2882static int
2883add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2884{
2885 struct chbk *p_ch;
dc5bc0ca 2886 struct ccw_dev_id dev_id;
1da177e4 2887
2a0217d5 2888 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
1da177e4
LT
2889 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2890 p_ch = &privptr->channel[i];
2891 p_ch->cdev = cdev;
2a0217d5 2892 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
dc5bc0ca
CH
2893 ccw_device_get_id(cdev, &dev_id);
2894 p_ch->devno = dev_id.devno;
dd00cc48 2895 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
1da177e4
LT
2896 return -ENOMEM;
2897 }
1da177e4
LT
2898 return 0;
2899}
2900
2901
2902/**
2903 *
2904 * Setup an interface.
2905 *
2906 * @param cgdev Device to be setup.
2907 *
2908 * @returns 0 on success, !0 on failure.
2909 */
2910static int
2911claw_new_device(struct ccwgroup_device *cgdev)
2912{
2913 struct claw_privbk *privptr;
2914 struct claw_env *p_env;
2915 struct net_device *dev;
2916 int ret;
dc5bc0ca 2917 struct ccw_dev_id dev_id;
1da177e4 2918
4811fcb7
AR
2919 dev_info(&cgdev->dev, "add for %s\n",
2920 dev_name(&cgdev->cdev[READ]->dev));
b805da74 2921 CLAW_DBF_TEXT(2, setup, "new_dev");
dff59b64
GKH
2922 privptr = dev_get_drvdata(&cgdev->dev);
2923 dev_set_drvdata(&cgdev->cdev[READ]->dev, privptr);
2924 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, privptr);
1da177e4
LT
2925 if (!privptr)
2926 return -ENODEV;
2927 p_env = privptr->p_env;
dc5bc0ca
CH
2928 ccw_device_get_id(cgdev->cdev[READ], &dev_id);
2929 p_env->devno[READ] = dev_id.devno;
2930 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
2931 p_env->devno[WRITE] = dev_id.devno;
1da177e4
LT
2932 ret = add_channel(cgdev->cdev[0],0,privptr);
2933 if (ret == 0)
2934 ret = add_channel(cgdev->cdev[1],1,privptr);
2935 if (ret != 0) {
4811fcb7
AR
2936 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2937 " failed with error code %d\n", ret);
b805da74 2938 goto out;
1da177e4
LT
2939 }
2940 ret = ccw_device_set_online(cgdev->cdev[READ]);
2941 if (ret != 0) {
4811fcb7
AR
2942 dev_warn(&cgdev->dev,
2943 "Setting the read subchannel online"
2944 " failed with error code %d\n", ret);
1da177e4
LT
2945 goto out;
2946 }
2947 ret = ccw_device_set_online(cgdev->cdev[WRITE]);
2948 if (ret != 0) {
4811fcb7
AR
2949 dev_warn(&cgdev->dev,
2950 "Setting the write subchannel online "
2951 "failed with error code %d\n", ret);
1da177e4
LT
2952 goto out;
2953 }
2954 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2955 if (!dev) {
4811fcb7
AR
2956 dev_warn(&cgdev->dev,
2957 "Activating the CLAW device failed\n");
1da177e4
LT
2958 goto out;
2959 }
6951df34 2960 dev->ml_priv = privptr;
dff59b64
GKH
2961 dev_set_drvdata(&cgdev->dev, privptr);
2962 dev_set_drvdata(&cgdev->cdev[READ]->dev, privptr);
2963 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, privptr);
1da177e4
LT
2964 /* sysfs magic */
2965 SET_NETDEV_DEV(dev, &cgdev->dev);
2966 if (register_netdev(dev) != 0) {
2967 claw_free_netdevice(dev, 1);
b805da74 2968 CLAW_DBF_TEXT(2, trace, "regfail");
1da177e4
LT
2969 goto out;
2970 }
2971 dev->flags &=~IFF_RUNNING;
2972 if (privptr->buffs_alloc == 0) {
2973 ret=init_ccw_bk(dev);
2974 if (ret !=0) {
1da177e4
LT
2975 unregister_netdev(dev);
2976 claw_free_netdevice(dev,1);
b805da74 2977 CLAW_DBF_TEXT(2, trace, "ccwmem");
1da177e4
LT
2978 goto out;
2979 }
2980 }
2981 privptr->channel[READ].ndev = dev;
2982 privptr->channel[WRITE].ndev = dev;
2983 privptr->p_env->ndev = dev;
2984
4811fcb7 2985 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
1da177e4
LT
2986 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2987 dev->name, p_env->read_size,
2988 p_env->write_size, p_env->read_buffers,
2989 p_env->write_buffers, p_env->devno[READ],
2990 p_env->devno[WRITE]);
4811fcb7 2991 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
1da177e4
LT
2992 ":%.8s api_type: %.8s\n",
2993 dev->name, p_env->host_name,
2994 p_env->adapter_name , p_env->api_type);
2995 return 0;
2996out:
2997 ccw_device_set_offline(cgdev->cdev[1]);
2998 ccw_device_set_offline(cgdev->cdev[0]);
1da177e4
LT
2999 return -ENODEV;
3000}
3001
3002static void
3003claw_purge_skb_queue(struct sk_buff_head *q)
3004{
3005 struct sk_buff *skb;
3006
b805da74 3007 CLAW_DBF_TEXT(4, trace, "purgque");
1da177e4
LT
3008 while ((skb = skb_dequeue(q))) {
3009 atomic_dec(&skb->users);
8e84c801 3010 dev_kfree_skb_any(skb);
1da177e4
LT
3011 }
3012}
3013
3014/**
3015 * Shutdown an interface.
3016 *
3017 * @param cgdev Device to be shut down.
3018 *
3019 * @returns 0 on success, !0 on failure.
3020 */
3021static int
3022claw_shutdown_device(struct ccwgroup_device *cgdev)
3023{
3024 struct claw_privbk *priv;
3025 struct net_device *ndev;
3026 int ret;
3027
b9d3aed7 3028 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
dff59b64 3029 priv = dev_get_drvdata(&cgdev->dev);
1da177e4
LT
3030 if (!priv)
3031 return -ENODEV;
3032 ndev = priv->channel[READ].ndev;
3033 if (ndev) {
3034 /* Close the device */
4811fcb7
AR
3035 dev_info(&cgdev->dev, "%s: shutting down \n",
3036 ndev->name);
1da177e4
LT
3037 if (ndev->flags & IFF_RUNNING)
3038 ret = claw_release(ndev);
3039 ndev->flags &=~IFF_RUNNING;
3040 unregister_netdev(ndev);
6951df34 3041 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
1da177e4
LT
3042 claw_free_netdevice(ndev, 1);
3043 priv->channel[READ].ndev = NULL;
3044 priv->channel[WRITE].ndev = NULL;
3045 priv->p_env->ndev = NULL;
3046 }
3047 ccw_device_set_offline(cgdev->cdev[1]);
3048 ccw_device_set_offline(cgdev->cdev[0]);
3049 return 0;
3050}
3051
3052static void
3053claw_remove_device(struct ccwgroup_device *cgdev)
3054{
3055 struct claw_privbk *priv;
3056
b805da74 3057 BUG_ON(!cgdev);
b9d3aed7 3058 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
dff59b64 3059 priv = dev_get_drvdata(&cgdev->dev);
b805da74 3060 BUG_ON(!priv);
4811fcb7 3061 dev_info(&cgdev->dev, " will be removed.\n");
1da177e4
LT
3062 if (cgdev->state == CCWGROUP_ONLINE)
3063 claw_shutdown_device(cgdev);
3064 claw_remove_files(&cgdev->dev);
17fd682e
JJ
3065 kfree(priv->p_mtc_envelope);
3066 priv->p_mtc_envelope=NULL;
3067 kfree(priv->p_env);
3068 priv->p_env=NULL;
3069 kfree(priv->channel[0].irb);
3070 priv->channel[0].irb=NULL;
3071 kfree(priv->channel[1].irb);
3072 priv->channel[1].irb=NULL;
1da177e4 3073 kfree(priv);
dff59b64
GKH
3074 dev_set_drvdata(&cgdev->dev, NULL);
3075 dev_set_drvdata(&cgdev->cdev[READ]->dev, NULL);
3076 dev_set_drvdata(&cgdev->cdev[WRITE]->dev, NULL);
1da177e4 3077 put_device(&cgdev->dev);
b805da74
AR
3078
3079 return;
1da177e4
LT
3080}
3081
3082
3083/*
3084 * sysfs attributes
3085 */
3086static ssize_t
3fd3c0a5 3087claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
3088{
3089 struct claw_privbk *priv;
3090 struct claw_env * p_env;
3091
dff59b64 3092 priv = dev_get_drvdata(dev);
1da177e4
LT
3093 if (!priv)
3094 return -ENODEV;
3095 p_env = priv->p_env;
3096 return sprintf(buf, "%s\n",p_env->host_name);
3097}
3098
3099static ssize_t
4811fcb7
AR
3100claw_hname_write(struct device *dev, struct device_attribute *attr,
3101 const char *buf, size_t count)
1da177e4
LT
3102{
3103 struct claw_privbk *priv;
3104 struct claw_env * p_env;
3105
dff59b64 3106 priv = dev_get_drvdata(dev);
1da177e4
LT
3107 if (!priv)
3108 return -ENODEV;
3109 p_env = priv->p_env;
3110 if (count > MAX_NAME_LEN+1)
3111 return -EINVAL;
3112 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3113 strncpy(p_env->host_name,buf, count);
3114 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3115 p_env->host_name[MAX_NAME_LEN] = 0x00;
b805da74
AR
3116 CLAW_DBF_TEXT(2, setup, "HstnSet");
3117 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
1da177e4
LT
3118
3119 return count;
3120}
3121
3122static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3123
3124static ssize_t
3fd3c0a5 3125claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
3126{
3127 struct claw_privbk *priv;
3128 struct claw_env * p_env;
3129
dff59b64 3130 priv = dev_get_drvdata(dev);
1da177e4
LT
3131 if (!priv)
3132 return -ENODEV;
3133 p_env = priv->p_env;
b805da74 3134 return sprintf(buf, "%s\n", p_env->adapter_name);
1da177e4
LT
3135}
3136
3137static ssize_t
4811fcb7
AR
3138claw_adname_write(struct device *dev, struct device_attribute *attr,
3139 const char *buf, size_t count)
1da177e4
LT
3140{
3141 struct claw_privbk *priv;
3142 struct claw_env * p_env;
3143
dff59b64 3144 priv = dev_get_drvdata(dev);
1da177e4
LT
3145 if (!priv)
3146 return -ENODEV;
3147 p_env = priv->p_env;
3148 if (count > MAX_NAME_LEN+1)
3149 return -EINVAL;
3150 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3151 strncpy(p_env->adapter_name,buf, count);
3152 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3153 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
b805da74
AR
3154 CLAW_DBF_TEXT(2, setup, "AdnSet");
3155 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
1da177e4
LT
3156
3157 return count;
3158}
3159
3160static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3161
3162static ssize_t
3fd3c0a5 3163claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
3164{
3165 struct claw_privbk *priv;
3166 struct claw_env * p_env;
3167
dff59b64 3168 priv = dev_get_drvdata(dev);
1da177e4
LT
3169 if (!priv)
3170 return -ENODEV;
3171 p_env = priv->p_env;
3172 return sprintf(buf, "%s\n",
3173 p_env->api_type);
3174}
3175
3176static ssize_t
4811fcb7
AR
3177claw_apname_write(struct device *dev, struct device_attribute *attr,
3178 const char *buf, size_t count)
1da177e4
LT
3179{
3180 struct claw_privbk *priv;
3181 struct claw_env * p_env;
3182
dff59b64 3183 priv = dev_get_drvdata(dev);
1da177e4
LT
3184 if (!priv)
3185 return -ENODEV;
3186 p_env = priv->p_env;
3187 if (count > MAX_NAME_LEN+1)
3188 return -EINVAL;
3189 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3190 strncpy(p_env->api_type,buf, count);
3191 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3192 p_env->api_type[MAX_NAME_LEN] = 0x00;
3193 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3194 p_env->read_size=DEF_PACK_BUFSIZE;
3195 p_env->write_size=DEF_PACK_BUFSIZE;
3196 p_env->packing=PACKING_ASK;
b805da74 3197 CLAW_DBF_TEXT(2, setup, "PACKING");
1da177e4
LT
3198 }
3199 else {
3200 p_env->packing=0;
3201 p_env->read_size=CLAW_FRAME_SIZE;
3202 p_env->write_size=CLAW_FRAME_SIZE;
b805da74 3203 CLAW_DBF_TEXT(2, setup, "ApiSet");
1da177e4 3204 }
b805da74 3205 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
1da177e4
LT
3206 return count;
3207}
3208
3209static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3210
3211static ssize_t
3fd3c0a5 3212claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
3213{
3214 struct claw_privbk *priv;
3215 struct claw_env * p_env;
3216
dff59b64 3217 priv = dev_get_drvdata(dev);
1da177e4
LT
3218 if (!priv)
3219 return -ENODEV;
3220 p_env = priv->p_env;
3221 return sprintf(buf, "%d\n", p_env->write_buffers);
3222}
3223
3224static ssize_t
4811fcb7
AR
3225claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3226 const char *buf, size_t count)
1da177e4
LT
3227{
3228 struct claw_privbk *priv;
3229 struct claw_env * p_env;
3230 int nnn,max;
3231
dff59b64 3232 priv = dev_get_drvdata(dev);
1da177e4
LT
3233 if (!priv)
3234 return -ENODEV;
3235 p_env = priv->p_env;
3236 sscanf(buf, "%i", &nnn);
3237 if (p_env->packing) {
3238 max = 64;
3239 }
3240 else {
3241 max = 512;
3242 }
3243 if ((nnn > max ) || (nnn < 2))
3244 return -EINVAL;
3245 p_env->write_buffers = nnn;
b805da74
AR
3246 CLAW_DBF_TEXT(2, setup, "Wbufset");
3247 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
1da177e4
LT
3248 return count;
3249}
3250
3251static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3252
3253static ssize_t
3fd3c0a5 3254claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
1da177e4
LT
3255{
3256 struct claw_privbk *priv;
3257 struct claw_env * p_env;
3258
dff59b64 3259 priv = dev_get_drvdata(dev);
1da177e4
LT
3260 if (!priv)
3261 return -ENODEV;
3262 p_env = priv->p_env;
3263 return sprintf(buf, "%d\n", p_env->read_buffers);
3264}
3265
3266static ssize_t
4811fcb7
AR
3267claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3268 const char *buf, size_t count)
1da177e4
LT
3269{
3270 struct claw_privbk *priv;
3271 struct claw_env *p_env;
3272 int nnn,max;
3273
dff59b64 3274 priv = dev_get_drvdata(dev);
1da177e4
LT
3275 if (!priv)
3276 return -ENODEV;
3277 p_env = priv->p_env;
3278 sscanf(buf, "%i", &nnn);
3279 if (p_env->packing) {
3280 max = 64;
3281 }
3282 else {
3283 max = 512;
3284 }
3285 if ((nnn > max ) || (nnn < 2))
3286 return -EINVAL;
3287 p_env->read_buffers = nnn;
b805da74
AR
3288 CLAW_DBF_TEXT(2, setup, "Rbufset");
3289 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
1da177e4
LT
3290 return count;
3291}
3292
3293static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3294
3295static struct attribute *claw_attr[] = {
3296 &dev_attr_read_buffer.attr,
3297 &dev_attr_write_buffer.attr,
3298 &dev_attr_adapter_name.attr,
3299 &dev_attr_api_type.attr,
3300 &dev_attr_host_name.attr,
3301 NULL,
3302};
3303
3304static struct attribute_group claw_attr_group = {
3305 .attrs = claw_attr,
3306};
3307
3308static int
3309claw_add_files(struct device *dev)
3310{
b805da74 3311 CLAW_DBF_TEXT(2, setup, "add_file");
1da177e4
LT
3312 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3313}
3314
3315static void
3316claw_remove_files(struct device *dev)
3317{
b805da74 3318 CLAW_DBF_TEXT(2, setup, "rem_file");
1da177e4
LT
3319 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3320}
3321
3322/*--------------------------------------------------------------------*
3323* claw_init and cleanup *
3324*---------------------------------------------------------------------*/
3325
3326static void __exit
3327claw_cleanup(void)
3328{
3329 unregister_cu3088_discipline(&claw_group_driver);
3330 claw_unregister_debug_facility();
4811fcb7 3331 pr_info("Driver unloaded\n");
1da177e4
LT
3332
3333}
3334
3335/**
3336 * Initialize module.
3337 * This is called just after the module is loaded.
3338 *
3339 * @return 0 on success, !0 on error.
3340 */
3341static int __init
3342claw_init(void)
3343{
3344 int ret = 0;
1da177e4 3345
4811fcb7 3346 pr_info("Loading %s\n", version);
1da177e4
LT
3347 ret = claw_register_debug_facility();
3348 if (ret) {
4811fcb7
AR
3349 pr_err("Registering with the S/390 debug feature"
3350 " failed with error code %d\n", ret);
1da177e4
LT
3351 return ret;
3352 }
b805da74 3353 CLAW_DBF_TEXT(2, setup, "init_mod");
1da177e4
LT
3354 ret = register_cu3088_discipline(&claw_group_driver);
3355 if (ret) {
b805da74 3356 CLAW_DBF_TEXT(2, setup, "init_bad");
1da177e4 3357 claw_unregister_debug_facility();
4811fcb7
AR
3358 pr_err("Registering with the cu3088 device driver failed "
3359 "with error code %d\n", ret);
1da177e4 3360 }
1da177e4
LT
3361 return ret;
3362}
3363
3364module_init(claw_init);
3365module_exit(claw_cleanup);
3366
b805da74
AR
3367MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3368MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3369 "Copyright 2000,2008 IBM Corporation\n");
3370MODULE_LICENSE("GPL");