2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
5 * Linux for zSeries version
6 * Copyright (C) 2002,2005 IBM Corporation
7 * Author(s) Original code written by:
8 * Kazuo Iimura (iimura@jp.ibm.com)
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
14 * group x.x.rrrr,x.x.wwww
18 * adapter_name aaaaaaaa
22 * group 0.0.0200 0.0.0201
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
35 * rrrr - the first of 2 consecutive device addresses used for the
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
40 * wwww - the second of 2 consecutive device addresses used for
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
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
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
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
64 #define KMSG_COMPONENT "claw"
66 #include <asm/ccwdev.h>
67 #include <asm/ccwgroup.h>
68 #include <asm/debug.h>
69 #include <asm/idals.h>
71 #include <linux/bitops.h>
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>
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>
97 CLAW uses the s390dbf file system see claw_trace and claw_setup
100 static char version[] __initdata = "CLAW driver";
101 static char debug_buffer[255];
103 * Debug Facility Stuff
105 static debug_info_t *claw_dbf_setup;
106 static debug_info_t *claw_dbf_trace;
109 * CLAW Debug Facility functions
112 claw_unregister_debug_facility(void)
115 debug_unregister(claw_dbf_setup);
117 debug_unregister(claw_dbf_trace);
121 claw_register_debug_facility(void)
123 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
124 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
125 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
126 claw_unregister_debug_facility();
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);
137 claw_set_busy(struct net_device *dev)
139 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
144 claw_clear_busy(struct net_device *dev)
146 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
147 netif_wake_queue(dev);
152 claw_check_busy(struct net_device *dev)
155 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
159 claw_setbit_busy(int nr,struct net_device *dev)
161 netif_stop_queue(dev);
162 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
166 claw_clearbit_busy(int nr,struct net_device *dev)
168 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
169 netif_wake_queue(dev);
173 claw_test_and_setbit_busy(int nr,struct net_device *dev)
175 netif_stop_queue(dev);
176 return test_and_set_bit(nr,
177 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
181 /* Functions for the DEV methods */
183 static int claw_probe(struct ccwgroup_device *cgdev);
184 static void claw_remove_device(struct ccwgroup_device *cgdev);
185 static void claw_purge_skb_queue(struct sk_buff_head *q);
186 static int claw_new_device(struct ccwgroup_device *cgdev);
187 static int claw_shutdown_device(struct ccwgroup_device *cgdev);
188 static int claw_tx(struct sk_buff *skb, struct net_device *dev);
189 static int claw_change_mtu( struct net_device *dev, int new_mtu);
190 static int claw_open(struct net_device *dev);
191 static void claw_irq_handler(struct ccw_device *cdev,
192 unsigned long intparm, struct irb *irb);
193 static void claw_irq_tasklet ( unsigned long data );
194 static int claw_release(struct net_device *dev);
195 static void claw_write_retry ( struct chbk * p_ch );
196 static void claw_write_next ( struct chbk * p_ch );
197 static void claw_timer ( struct chbk * p_ch );
200 static int add_claw_reads(struct net_device *dev,
201 struct ccwbk* p_first, struct ccwbk* p_last);
202 static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
203 static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
204 static int find_link(struct net_device *dev, char *host_name, char *ws_name );
205 static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
206 static int init_ccw_bk(struct net_device *dev);
207 static void probe_error( struct ccwgroup_device *cgdev);
208 static struct net_device_stats *claw_stats(struct net_device *dev);
209 static int pages_to_order_of_mag(int num_of_pages);
210 static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
211 /* sysfs Functions */
212 static ssize_t claw_hname_show(struct device *dev,
213 struct device_attribute *attr, char *buf);
214 static ssize_t claw_hname_write(struct device *dev,
215 struct device_attribute *attr,
216 const char *buf, size_t count);
217 static ssize_t claw_adname_show(struct device *dev,
218 struct device_attribute *attr, char *buf);
219 static ssize_t claw_adname_write(struct device *dev,
220 struct device_attribute *attr,
221 const char *buf, size_t count);
222 static ssize_t claw_apname_show(struct device *dev,
223 struct device_attribute *attr, char *buf);
224 static ssize_t claw_apname_write(struct device *dev,
225 struct device_attribute *attr,
226 const char *buf, size_t count);
227 static ssize_t claw_wbuff_show(struct device *dev,
228 struct device_attribute *attr, char *buf);
229 static ssize_t claw_wbuff_write(struct device *dev,
230 struct device_attribute *attr,
231 const char *buf, size_t count);
232 static ssize_t claw_rbuff_show(struct device *dev,
233 struct device_attribute *attr, char *buf);
234 static ssize_t claw_rbuff_write(struct device *dev,
235 struct device_attribute *attr,
236 const char *buf, size_t count);
237 static int claw_add_files(struct device *dev);
238 static void claw_remove_files(struct device *dev);
240 /* Functions for System Validate */
241 static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
242 static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
243 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
244 static int claw_snd_conn_req(struct net_device *dev, __u8 link);
245 static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
246 static int claw_snd_sys_validate_rsp(struct net_device *dev,
247 struct clawctl * p_ctl, __u32 return_code);
248 static int claw_strt_conn_req(struct net_device *dev );
249 static void claw_strt_read(struct net_device *dev, int lock);
250 static void claw_strt_out_IO(struct net_device *dev);
251 static void claw_free_wrt_buf(struct net_device *dev);
253 /* Functions for unpack reads */
254 static void unpack_read(struct net_device *dev);
258 static struct ccwgroup_driver claw_group_driver = {
259 .owner = THIS_MODULE,
262 .driver_id = 0xC3D3C1E6,
264 .remove = claw_remove_device,
265 .set_online = claw_new_device,
266 .set_offline = claw_shutdown_device,
273 /*----------------------------------------------------------------*
275 * this function is called for each CLAW device. *
276 *----------------------------------------------------------------*/
278 claw_probe(struct ccwgroup_device *cgdev)
281 struct claw_privbk *privptr=NULL;
283 CLAW_DBF_TEXT(2, setup, "probe");
284 if (!get_device(&cgdev->dev))
286 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
287 cgdev->dev.driver_data = privptr;
288 if (privptr == NULL) {
290 put_device(&cgdev->dev);
291 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
294 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
295 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
296 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
298 put_device(&cgdev->dev);
299 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
302 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
303 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
304 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
305 privptr->p_env->packing = 0;
306 privptr->p_env->write_buffers = 5;
307 privptr->p_env->read_buffers = 5;
308 privptr->p_env->read_size = CLAW_FRAME_SIZE;
309 privptr->p_env->write_size = CLAW_FRAME_SIZE;
310 rc = claw_add_files(&cgdev->dev);
313 put_device(&cgdev->dev);
314 dev_err(&cgdev->dev, "Creating the /proc files for a new"
315 " CLAW device failed\n");
316 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
319 privptr->p_env->p_priv = privptr;
320 cgdev->cdev[0]->handler = claw_irq_handler;
321 cgdev->cdev[1]->handler = claw_irq_handler;
322 CLAW_DBF_TEXT(2, setup, "prbext 0");
325 } /* end of claw_probe */
327 /*-------------------------------------------------------------------*
329 *-------------------------------------------------------------------*/
332 claw_tx(struct sk_buff *skb, struct net_device *dev)
335 struct claw_privbk *privptr = dev->ml_priv;
336 unsigned long saveflags;
339 CLAW_DBF_TEXT(4, trace, "claw_tx");
340 p_ch=&privptr->channel[WRITE];
342 privptr->stats.tx_dropped++;
343 privptr->stats.tx_errors++;
344 CLAW_DBF_TEXT_(2, trace, "clawtx%d", -EIO);
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);
350 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
354 } /* end of claw_tx */
356 /*------------------------------------------------------------------*
357 * pack the collect queue into an skb and return it *
358 * If not packing just return the top skb from the queue *
359 *------------------------------------------------------------------*/
361 static struct sk_buff *
362 claw_pack_skb(struct claw_privbk *privptr)
364 struct sk_buff *new_skb,*held_skb;
365 struct chbk *p_ch = &privptr->channel[WRITE];
366 struct claw_env *p_env = privptr->p_env;
367 int pkt_cnt,pk_ind,so_far;
369 new_skb = NULL; /* assume no dice */
371 CLAW_DBF_TEXT(4, trace, "PackSKBe");
372 if (!skb_queue_empty(&p_ch->collect_queue)) {
374 held_skb = skb_dequeue(&p_ch->collect_queue);
376 dev_kfree_skb_any(held_skb);
379 if (p_env->packing != DO_PACKED)
381 /* get a new SKB we will pack at least one */
382 new_skb = dev_alloc_skb(p_env->write_size);
383 if (new_skb == NULL) {
384 atomic_inc(&held_skb->users);
385 skb_queue_head(&p_ch->collect_queue,held_skb);
388 /* we have packed packet and a place to put it */
391 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
392 while ((pk_ind) && (held_skb != NULL)) {
393 if (held_skb->len+so_far <= p_env->write_size-8) {
394 memcpy(skb_put(new_skb,held_skb->len),
395 held_skb->data,held_skb->len);
396 privptr->stats.tx_packets++;
397 so_far += held_skb->len;
399 dev_kfree_skb_any(held_skb);
400 held_skb = skb_dequeue(&p_ch->collect_queue);
402 atomic_dec(&held_skb->users);
405 atomic_inc(&held_skb->users);
406 skb_queue_head(&p_ch->collect_queue,held_skb);
410 CLAW_DBF_TEXT(4, trace, "PackSKBx");
414 /*-------------------------------------------------------------------*
417 *-------------------------------------------------------------------*/
420 claw_change_mtu(struct net_device *dev, int new_mtu)
422 struct claw_privbk *privptr = dev->ml_priv;
424 CLAW_DBF_TEXT(4, trace, "setmtu");
425 buff_size = privptr->p_env->write_size;
426 if ((new_mtu < 60) || (new_mtu > buff_size)) {
431 } /* end of claw_change_mtu */
434 /*-------------------------------------------------------------------*
437 *-------------------------------------------------------------------*/
439 claw_open(struct net_device *dev)
444 unsigned long saveflags=0;
446 struct claw_privbk *privptr;
447 DECLARE_WAITQUEUE(wait, current);
448 struct timer_list timer;
451 CLAW_DBF_TEXT(4, trace, "open");
452 privptr = (struct claw_privbk *)dev->ml_priv;
453 /* allocate and initialize CCW blocks */
454 if (privptr->buffs_alloc == 0) {
457 CLAW_DBF_TEXT(2, trace, "openmem");
461 privptr->system_validate_comp=0;
462 privptr->release_pend=0;
463 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
464 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
465 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
466 privptr->p_env->packing=PACKING_ASK;
468 privptr->p_env->packing=0;
469 privptr->p_env->read_size=CLAW_FRAME_SIZE;
470 privptr->p_env->write_size=CLAW_FRAME_SIZE;
473 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
474 (unsigned long) &privptr->channel[READ]);
475 for ( i = 0; i < 2; i++) {
476 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
477 init_waitqueue_head(&privptr->channel[i].wait);
478 /* skb_queue_head_init(&p_ch->io_queue); */
481 &privptr->channel[WRITE].collect_queue);
482 privptr->channel[i].flag_a = 0;
483 privptr->channel[i].IO_active = 0;
484 privptr->channel[i].flag &= ~CLAW_TIMER;
486 timer.function = (void *)claw_timer;
487 timer.data = (unsigned long)(&privptr->channel[i]);
488 timer.expires = jiffies + 15*HZ;
490 spin_lock_irqsave(get_ccwdev_lock(
491 privptr->channel[i].cdev), saveflags);
492 parm = (unsigned long) &privptr->channel[i];
493 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
495 add_wait_queue(&privptr->channel[i].wait, &wait);
496 rc = ccw_device_halt(
497 (struct ccw_device *)privptr->channel[i].cdev,parm);
498 set_current_state(TASK_INTERRUPTIBLE);
499 spin_unlock_irqrestore(
500 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
502 set_current_state(TASK_RUNNING);
503 remove_wait_queue(&privptr->channel[i].wait, &wait);
505 ccw_check_return_code(privptr->channel[i].cdev, rc);
506 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
509 if ((((privptr->channel[READ].last_dstat |
510 privptr->channel[WRITE].last_dstat) &
511 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
512 (((privptr->channel[READ].flag |
513 privptr->channel[WRITE].flag) & CLAW_TIMER) != 0x00)) {
514 dev_info(&privptr->channel[READ].cdev->dev,
515 "%s: remote side is not ready\n", dev->name);
516 CLAW_DBF_TEXT(2, trace, "notrdy");
518 for ( i = 0; i < 2; i++) {
520 get_ccwdev_lock(privptr->channel[i].cdev),
522 parm = (unsigned long) &privptr->channel[i];
523 privptr->channel[i].claw_state = CLAW_STOP;
524 rc = ccw_device_halt(
525 (struct ccw_device *)&privptr->channel[i].cdev,
527 spin_unlock_irqrestore(
528 get_ccwdev_lock(privptr->channel[i].cdev),
531 ccw_check_return_code(
532 privptr->channel[i].cdev, rc);
535 free_pages((unsigned long)privptr->p_buff_ccw,
536 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
537 if (privptr->p_env->read_size < PAGE_SIZE) {
538 free_pages((unsigned long)privptr->p_buff_read,
539 (int)pages_to_order_of_mag(
540 privptr->p_buff_read_num));
543 p_buf=privptr->p_read_active_first;
544 while (p_buf!=NULL) {
545 free_pages((unsigned long)p_buf->p_buffer,
546 (int)pages_to_order_of_mag(
547 privptr->p_buff_pages_perread ));
551 if (privptr->p_env->write_size < PAGE_SIZE ) {
552 free_pages((unsigned long)privptr->p_buff_write,
553 (int)pages_to_order_of_mag(
554 privptr->p_buff_write_num));
557 p_buf=privptr->p_write_active_first;
558 while (p_buf!=NULL) {
559 free_pages((unsigned long)p_buf->p_buffer,
560 (int)pages_to_order_of_mag(
561 privptr->p_buff_pages_perwrite ));
565 privptr->buffs_alloc = 0;
566 privptr->channel[READ].flag= 0x00;
567 privptr->channel[WRITE].flag = 0x00;
568 privptr->p_buff_ccw=NULL;
569 privptr->p_buff_read=NULL;
570 privptr->p_buff_write=NULL;
571 claw_clear_busy(dev);
572 CLAW_DBF_TEXT(2, trace, "open EIO");
576 /* Send SystemValidate command */
578 claw_clear_busy(dev);
579 CLAW_DBF_TEXT(4, trace, "openok");
581 } /* end of claw_open */
583 /*-------------------------------------------------------------------*
587 *--------------------------------------------------------------------*/
589 claw_irq_handler(struct ccw_device *cdev,
590 unsigned long intparm, struct irb *irb)
592 struct chbk *p_ch = NULL;
593 struct claw_privbk *privptr = NULL;
594 struct net_device *dev = NULL;
595 struct claw_env *p_env;
596 struct chbk *p_ch_r=NULL;
598 CLAW_DBF_TEXT(4, trace, "clawirq");
599 /* Bypass all 'unsolicited interrupts' */
600 if (!cdev->dev.driver_data) {
601 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
602 " IRQ, c-%02x d-%02x\n",
603 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
604 CLAW_DBF_TEXT(2, trace, "badirq");
607 privptr = (struct claw_privbk *)cdev->dev.driver_data;
609 /* Try to extract channel from driver data. */
610 if (privptr->channel[READ].cdev == cdev)
611 p_ch = &privptr->channel[READ];
612 else if (privptr->channel[WRITE].cdev == cdev)
613 p_ch = &privptr->channel[WRITE];
615 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
616 CLAW_DBF_TEXT(2, trace, "badchan");
619 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
621 dev = (struct net_device *) (p_ch->ndev);
622 p_env=privptr->p_env;
624 /* Copy interruption response block. */
625 memcpy(p_ch->irb, irb, sizeof(struct irb));
627 /* Check for good subchannel return code, otherwise info message */
628 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
630 "%s: subchannel check for device: %04x -"
631 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
632 dev->name, p_ch->devno,
633 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
635 CLAW_DBF_TEXT(2, trace, "chanchk");
639 /* Check the reason-code of a unit check */
640 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
641 ccw_check_unit_check(p_ch, irb->ecw[0]);
643 /* State machine to bring the connection up, down and to restart */
644 p_ch->last_dstat = irb->scsw.cmd.dstat;
646 switch (p_ch->claw_state) {
647 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
648 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
649 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
650 (p_ch->irb->scsw.cmd.stctl ==
651 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
653 wake_up(&p_ch->wait); /* wake up claw_release */
654 CLAW_DBF_TEXT(4, trace, "stop");
656 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
657 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
658 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
659 (p_ch->irb->scsw.cmd.stctl ==
660 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
661 CLAW_DBF_TEXT(4, trace, "haltio");
664 if (p_ch->flag == CLAW_READ) {
665 p_ch->claw_state = CLAW_START_READ;
666 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
667 } else if (p_ch->flag == CLAW_WRITE) {
668 p_ch->claw_state = CLAW_START_WRITE;
669 /* send SYSTEM_VALIDATE */
670 claw_strt_read(dev, LOCK_NO);
671 claw_send_control(dev,
672 SYSTEM_VALIDATE_REQUEST,
675 p_env->adapter_name);
677 dev_warn(&cdev->dev, "The CLAW device received"
678 " an unexpected IRQ, "
681 irb->scsw.cmd.dstat);
684 CLAW_DBF_TEXT(4, trace, "haltio");
686 case CLAW_START_READ:
687 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
688 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
689 clear_bit(0, (void *)&p_ch->IO_active);
690 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
691 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
692 (p_ch->irb->ecw[0]) == 0) {
693 privptr->stats.rx_errors++;
695 "%s: Restart is required after remote "
699 CLAW_DBF_TEXT(4, trace, "notrdy");
702 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
703 (p_ch->irb->scsw.cmd.dstat == 0)) {
704 if (test_and_set_bit(CLAW_BH_ACTIVE,
705 (void *)&p_ch->flag_a) == 0)
706 tasklet_schedule(&p_ch->tasklet);
708 CLAW_DBF_TEXT(4, trace, "PCINoBH");
709 CLAW_DBF_TEXT(4, trace, "PCI_read");
712 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
713 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
714 (p_ch->irb->scsw.cmd.stctl ==
715 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
716 CLAW_DBF_TEXT(4, trace, "SPend_rd");
719 clear_bit(0, (void *)&p_ch->IO_active);
720 claw_clearbit_busy(TB_RETRY, dev);
721 if (test_and_set_bit(CLAW_BH_ACTIVE,
722 (void *)&p_ch->flag_a) == 0)
723 tasklet_schedule(&p_ch->tasklet);
725 CLAW_DBF_TEXT(4, trace, "RdBHAct");
726 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
728 case CLAW_START_WRITE:
729 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
731 "%s: Unit Check Occured in "
732 "write channel\n", dev->name);
733 clear_bit(0, (void *)&p_ch->IO_active);
734 if (p_ch->irb->ecw[0] & 0x80) {
736 "%s: Resetting Event "
737 "occurred:\n", dev->name);
738 init_timer(&p_ch->timer);
739 p_ch->timer.function =
740 (void *)claw_write_retry;
741 p_ch->timer.data = (unsigned long)p_ch;
742 p_ch->timer.expires = jiffies + 10*HZ;
743 add_timer(&p_ch->timer);
745 "%s: write connection "
746 "restarting\n", dev->name);
748 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
751 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
752 clear_bit(0, (void *)&p_ch->IO_active);
754 "%s: Unit Exception "
755 "occurred in write channel\n",
758 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
759 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
760 (p_ch->irb->scsw.cmd.stctl ==
761 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
762 CLAW_DBF_TEXT(4, trace, "writeUE");
765 clear_bit(0, (void *)&p_ch->IO_active);
766 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
767 claw_write_next(p_ch);
768 claw_clearbit_busy(TB_TX, dev);
769 claw_clear_busy(dev);
771 p_ch_r = (struct chbk *)&privptr->channel[READ];
772 if (test_and_set_bit(CLAW_BH_ACTIVE,
773 (void *)&p_ch_r->flag_a) == 0)
774 tasklet_schedule(&p_ch_r->tasklet);
775 CLAW_DBF_TEXT(4, trace, "StWtExit");
779 "The CLAW device for %s received an unexpected IRQ\n",
781 CLAW_DBF_TEXT(2, trace, "badIRQ");
785 } /* end of claw_irq_handler */
788 /*-------------------------------------------------------------------*
791 *--------------------------------------------------------------------*/
793 claw_irq_tasklet ( unsigned long data )
796 struct net_device *dev;
797 struct claw_privbk * privptr;
799 p_ch = (struct chbk *) data;
800 dev = (struct net_device *)p_ch->ndev;
801 CLAW_DBF_TEXT(4, trace, "IRQtask");
802 privptr = (struct claw_privbk *)dev->ml_priv;
804 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
805 CLAW_DBF_TEXT(4, trace, "TskletXt");
807 } /* end of claw_irq_bh */
809 /*-------------------------------------------------------------------*
812 *--------------------------------------------------------------------*/
814 claw_release(struct net_device *dev)
818 unsigned long saveflags;
820 struct claw_privbk *privptr;
821 DECLARE_WAITQUEUE(wait, current);
822 struct ccwbk* p_this_ccw;
827 privptr = (struct claw_privbk *)dev->ml_priv;
830 CLAW_DBF_TEXT(4, trace, "release");
831 privptr->release_pend=1;
832 claw_setbit_busy(TB_STOP,dev);
833 for ( i = 1; i >=0 ; i--) {
835 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
836 /* del_timer(&privptr->channel[READ].timer); */
837 privptr->channel[i].claw_state = CLAW_STOP;
838 privptr->channel[i].IO_active = 0;
839 parm = (unsigned long) &privptr->channel[i];
841 claw_purge_skb_queue(
842 &privptr->channel[WRITE].collect_queue);
843 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
844 if (privptr->system_validate_comp==0x00) /* never opened? */
845 init_waitqueue_head(&privptr->channel[i].wait);
846 add_wait_queue(&privptr->channel[i].wait, &wait);
847 set_current_state(TASK_INTERRUPTIBLE);
848 spin_unlock_irqrestore(
849 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
851 set_current_state(TASK_RUNNING);
852 remove_wait_queue(&privptr->channel[i].wait, &wait);
854 ccw_check_return_code(privptr->channel[i].cdev, rc);
857 if (privptr->pk_skb != NULL) {
858 dev_kfree_skb_any(privptr->pk_skb);
859 privptr->pk_skb = NULL;
861 if(privptr->buffs_alloc != 1) {
862 CLAW_DBF_TEXT(4, trace, "none2fre");
865 CLAW_DBF_TEXT(4, trace, "freebufs");
866 if (privptr->p_buff_ccw != NULL) {
867 free_pages((unsigned long)privptr->p_buff_ccw,
868 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
870 CLAW_DBF_TEXT(4, trace, "freeread");
871 if (privptr->p_env->read_size < PAGE_SIZE) {
872 if (privptr->p_buff_read != NULL) {
873 free_pages((unsigned long)privptr->p_buff_read,
874 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
878 p_buf=privptr->p_read_active_first;
879 while (p_buf!=NULL) {
880 free_pages((unsigned long)p_buf->p_buffer,
881 (int)pages_to_order_of_mag(
882 privptr->p_buff_pages_perread ));
886 CLAW_DBF_TEXT(4, trace, "freewrit");
887 if (privptr->p_env->write_size < PAGE_SIZE ) {
888 free_pages((unsigned long)privptr->p_buff_write,
889 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
892 p_buf=privptr->p_write_active_first;
893 while (p_buf!=NULL) {
894 free_pages((unsigned long)p_buf->p_buffer,
895 (int)pages_to_order_of_mag(
896 privptr->p_buff_pages_perwrite ));
900 CLAW_DBF_TEXT(4, trace, "clearptr");
901 privptr->buffs_alloc = 0;
902 privptr->p_buff_ccw=NULL;
903 privptr->p_buff_read=NULL;
904 privptr->p_buff_write=NULL;
905 privptr->system_validate_comp=0;
906 privptr->release_pend=0;
907 /* Remove any writes that were pending and reset all reads */
908 p_this_ccw=privptr->p_read_active_first;
909 while (p_this_ccw!=NULL) {
910 p_this_ccw->header.length=0xffff;
911 p_this_ccw->header.opcode=0xff;
912 p_this_ccw->header.flag=0x00;
913 p_this_ccw=p_this_ccw->next;
916 while (privptr->p_write_active_first!=NULL) {
917 p_this_ccw=privptr->p_write_active_first;
918 p_this_ccw->header.flag=CLAW_PENDING;
919 privptr->p_write_active_first=p_this_ccw->next;
920 p_this_ccw->next=privptr->p_write_free_chain;
921 privptr->p_write_free_chain=p_this_ccw;
922 ++privptr->write_free_count;
924 privptr->p_write_active_last=NULL;
925 privptr->mtc_logical_link = -1;
926 privptr->mtc_skipping = 1;
927 privptr->mtc_offset=0;
929 if (((privptr->channel[READ].last_dstat |
930 privptr->channel[WRITE].last_dstat) &
931 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
932 dev_warn(&privptr->channel[READ].cdev->dev,
933 "Deactivating %s completed with incorrect"
934 " subchannel status "
935 "(read %02x, write %02x)\n",
937 privptr->channel[READ].last_dstat,
938 privptr->channel[WRITE].last_dstat);
939 CLAW_DBF_TEXT(2, trace, "badclose");
941 CLAW_DBF_TEXT(4, trace, "rlsexit");
943 } /* end of claw_release */
945 /*-------------------------------------------------------------------*
948 *--------------------------------------------------------------------*/
951 claw_write_retry ( struct chbk *p_ch )
954 struct net_device *dev=p_ch->ndev;
956 CLAW_DBF_TEXT(4, trace, "w_retry");
957 if (p_ch->claw_state == CLAW_STOP) {
960 claw_strt_out_IO( dev );
961 CLAW_DBF_TEXT(4, trace, "rtry_xit");
963 } /* end of claw_write_retry */
966 /*-------------------------------------------------------------------*
969 *--------------------------------------------------------------------*/
972 claw_write_next ( struct chbk * p_ch )
975 struct net_device *dev;
976 struct claw_privbk *privptr=NULL;
977 struct sk_buff *pk_skb;
980 CLAW_DBF_TEXT(4, trace, "claw_wrt");
981 if (p_ch->claw_state == CLAW_STOP)
983 dev = (struct net_device *) p_ch->ndev;
984 privptr = (struct claw_privbk *) dev->ml_priv;
985 claw_free_wrt_buf( dev );
986 if ((privptr->write_free_count > 0) &&
987 !skb_queue_empty(&p_ch->collect_queue)) {
988 pk_skb = claw_pack_skb(privptr);
989 while (pk_skb != NULL) {
990 rc = claw_hw_tx( pk_skb, dev,1);
991 if (privptr->write_free_count > 0) {
992 pk_skb = claw_pack_skb(privptr);
997 if (privptr->p_write_active_first!=NULL) {
998 claw_strt_out_IO(dev);
1001 } /* end of claw_write_next */
1003 /*-------------------------------------------------------------------*
1006 *--------------------------------------------------------------------*/
1009 claw_timer ( struct chbk * p_ch )
1011 CLAW_DBF_TEXT(4, trace, "timer");
1012 p_ch->flag |= CLAW_TIMER;
1013 wake_up(&p_ch->wait);
1015 } /* end of claw_timer */
1023 /*-------------------------------------------------------------------*
1025 * pages_to_order_of_mag *
1027 * takes a number of pages from 1 to 512 and returns the *
1028 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1029 * of magnitude get_free_pages() has an upper order of 9 *
1030 *--------------------------------------------------------------------*/
1033 pages_to_order_of_mag(int num_of_pages)
1035 int order_of_mag=1; /* assume 2 pages */
1038 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
1039 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1040 /* 512 pages = 2Meg on 4k page systems */
1041 if (num_of_pages >= 512) {return 9; }
1042 /* we have two or more pages order is at least 1 */
1043 for (nump=2 ;nump <= 512;nump*=2) {
1044 if (num_of_pages <= nump)
1048 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
1049 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
1050 return order_of_mag;
1053 /*-------------------------------------------------------------------*
1057 *--------------------------------------------------------------------*/
1059 add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1060 struct ccwbk* p_last)
1062 struct claw_privbk *privptr;
1063 struct ccw1 temp_ccw;
1064 struct endccw * p_end;
1065 CLAW_DBF_TEXT(4, trace, "addreads");
1066 privptr = dev->ml_priv;
1067 p_end = privptr->p_end_ccw;
1069 /* first CCW and last CCW contains a new set of read channel programs
1070 * to apend the running channel programs
1072 if ( p_first==NULL) {
1073 CLAW_DBF_TEXT(4, trace, "addexit");
1077 /* set up ending CCW sequence for this segment */
1079 p_end->read1=0x00; /* second ending CCW is now active */
1080 /* reset ending CCWs and setup TIC CCWs */
1081 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1082 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1083 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1084 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1085 p_end->read2_nop2.cda=0;
1086 p_end->read2_nop2.count=1;
1089 p_end->read1=0x01; /* first ending CCW is now active */
1090 /* reset ending CCWs and setup TIC CCWs */
1091 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1092 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1093 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1094 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1095 p_end->read1_nop2.cda=0;
1096 p_end->read1_nop2.count=1;
1099 if ( privptr-> p_read_active_first ==NULL ) {
1100 privptr->p_read_active_first = p_first; /* set new first */
1101 privptr->p_read_active_last = p_last; /* set new last */
1105 /* set up TIC ccw */
1106 temp_ccw.cda= (__u32)__pa(&p_first->read);
1109 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1114 /* first set of CCW's is chained to the new read */
1115 /* chain, so the second set is chained to the active chain. */
1116 /* Therefore modify the second set to point to the new */
1117 /* read chain set up TIC CCWs */
1118 /* make sure we update the CCW so channel doesn't fetch it */
1119 /* when it's only half done */
1120 memcpy( &p_end->read2_nop2, &temp_ccw ,
1121 sizeof(struct ccw1));
1122 privptr->p_read_active_last->r_TIC_1.cda=
1123 (__u32)__pa(&p_first->read);
1124 privptr->p_read_active_last->r_TIC_2.cda=
1125 (__u32)__pa(&p_first->read);
1128 /* make sure we update the CCW so channel doesn't */
1129 /* fetch it when it is only half done */
1130 memcpy( &p_end->read1_nop2, &temp_ccw ,
1131 sizeof(struct ccw1));
1132 privptr->p_read_active_last->r_TIC_1.cda=
1133 (__u32)__pa(&p_first->read);
1134 privptr->p_read_active_last->r_TIC_2.cda=
1135 (__u32)__pa(&p_first->read);
1137 /* chain in new set of blocks */
1138 privptr->p_read_active_last->next = p_first;
1139 privptr->p_read_active_last=p_last;
1140 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1141 CLAW_DBF_TEXT(4, trace, "addexit");
1143 } /* end of add_claw_reads */
1145 /*-------------------------------------------------------------------*
1146 * ccw_check_return_code *
1148 *-------------------------------------------------------------------*/
1151 ccw_check_return_code(struct ccw_device *cdev, int return_code)
1153 CLAW_DBF_TEXT(4, trace, "ccwret");
1154 if (return_code != 0) {
1155 switch (return_code) {
1156 case -EBUSY: /* BUSY is a transient state no action needed */
1159 dev_err(&cdev->dev, "The remote channel adapter is not"
1164 "The status of the remote channel adapter"
1168 dev_err(&cdev->dev, "The common device layer"
1169 " returned error code %d\n",
1173 CLAW_DBF_TEXT(4, trace, "ccwret");
1174 } /* end of ccw_check_return_code */
1176 /*-------------------------------------------------------------------*
1177 * ccw_check_unit_check *
1178 *--------------------------------------------------------------------*/
1181 ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1183 struct net_device *ndev = p_ch->ndev;
1184 struct device *dev = &p_ch->cdev->dev;
1186 CLAW_DBF_TEXT(4, trace, "unitchek");
1187 dev_warn(dev, "The communication peer of %s disconnected\n",
1192 dev_warn(dev, "The remote channel adapter for"
1193 " %s has been reset\n",
1197 else if (sense & 0x20) {
1199 dev_warn(dev, "A data streaming timeout occurred"
1204 dev_warn(dev, "A data transfer parity error occurred"
1209 else if (sense & 0x10) {
1211 dev_warn(dev, "The remote channel adapter for %s"
1216 dev_warn(dev, "A read data parity error occurred"
1222 } /* end of ccw_check_unit_check */
1224 /*-------------------------------------------------------------------*
1226 *--------------------------------------------------------------------*/
1228 find_link(struct net_device *dev, char *host_name, char *ws_name )
1230 struct claw_privbk *privptr;
1231 struct claw_env *p_env;
1234 CLAW_DBF_TEXT(2, setup, "findlink");
1235 privptr = dev->ml_priv;
1236 p_env=privptr->p_env;
1237 switch (p_env->packing)
1240 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1241 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1246 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1247 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1251 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1252 (memcmp(p_env->api_type , ws_name, 8)!=0))
1258 } /* end of find_link */
1260 /*-------------------------------------------------------------------*
1264 *-------------------------------------------------------------------*/
1267 claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1270 struct claw_privbk *privptr;
1271 struct ccwbk *p_this_ccw;
1272 struct ccwbk *p_first_ccw;
1273 struct ccwbk *p_last_ccw;
1275 signed long len_of_data;
1276 unsigned long bytesInThisBuffer;
1277 unsigned char *pDataAddress;
1278 struct endccw *pEnd;
1279 struct ccw1 tempCCW;
1281 struct claw_env *p_env;
1283 struct clawph *pk_head;
1286 CLAW_DBF_TEXT(4, trace, "hw_tx");
1287 privptr = (struct claw_privbk *)(dev->ml_priv);
1288 p_ch=(struct chbk *)&privptr->channel[WRITE];
1289 p_env =privptr->p_env;
1290 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1291 /* scan the write queue to free any completed write packets */
1294 if ((p_env->packing >= PACK_SEND) &&
1295 (skb->cb[1] != 'P')) {
1296 skb_push(skb,sizeof(struct clawph));
1297 pk_head=(struct clawph *)skb->data;
1298 pk_head->len=skb->len-sizeof(struct clawph);
1299 if (pk_head->len%4) {
1300 pk_head->len+= 4-(pk_head->len%4);
1301 skb_pad(skb,4-(pk_head->len%4));
1302 skb_put(skb,4-(pk_head->len%4));
1304 if (p_env->packing == DO_PACKED)
1305 pk_head->link_num = linkid;
1307 pk_head->link_num = 0;
1308 pk_head->flag = 0x00;
1313 if (claw_check_busy(dev)) {
1314 if (privptr->write_free_count!=0) {
1315 claw_clear_busy(dev);
1318 claw_strt_out_IO(dev );
1319 claw_free_wrt_buf( dev );
1320 if (privptr->write_free_count==0) {
1321 ch = &privptr->channel[WRITE];
1322 atomic_inc(&skb->users);
1323 skb_queue_tail(&ch->collect_queue, skb);
1327 claw_clear_busy(dev);
1332 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
1333 ch = &privptr->channel[WRITE];
1334 atomic_inc(&skb->users);
1335 skb_queue_tail(&ch->collect_queue, skb);
1336 claw_strt_out_IO(dev );
1341 /* See how many write buffers are required to hold this data */
1342 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
1344 /* If that number of buffers isn't available, give up for now */
1345 if (privptr->write_free_count < numBuffers ||
1346 privptr->p_write_free_chain == NULL ) {
1348 claw_setbit_busy(TB_NOBUFFER,dev);
1349 ch = &privptr->channel[WRITE];
1350 atomic_inc(&skb->users);
1351 skb_queue_tail(&ch->collect_queue, skb);
1352 CLAW_DBF_TEXT(2, trace, "clawbusy");
1355 pDataAddress=skb->data;
1356 len_of_data=skb->len;
1358 while (len_of_data > 0) {
1359 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1360 if (p_this_ccw == NULL) { /* lost the race */
1361 ch = &privptr->channel[WRITE];
1362 atomic_inc(&skb->users);
1363 skb_queue_tail(&ch->collect_queue, skb);
1366 privptr->p_write_free_chain=p_this_ccw->next;
1367 p_this_ccw->next=NULL;
1368 --privptr->write_free_count; /* -1 */
1369 bytesInThisBuffer=len_of_data;
1370 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1371 len_of_data-=bytesInThisBuffer;
1372 pDataAddress+=(unsigned long)bytesInThisBuffer;
1373 /* setup write CCW */
1374 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1375 if (len_of_data>0) {
1376 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1378 p_this_ccw->write.count=bytesInThisBuffer;
1379 /* now add to end of this chain */
1380 if (p_first_ccw==NULL) {
1381 p_first_ccw=p_this_ccw;
1383 if (p_last_ccw!=NULL) {
1384 p_last_ccw->next=p_this_ccw;
1385 /* set up TIC ccws */
1386 p_last_ccw->w_TIC_1.cda=
1387 (__u32)__pa(&p_this_ccw->write);
1389 p_last_ccw=p_this_ccw; /* save new last block */
1392 /* FirstCCW and LastCCW now contain a new set of write channel
1393 * programs to append to the running channel program
1396 if (p_first_ccw!=NULL) {
1397 /* setup ending ccw sequence for this segment */
1398 pEnd=privptr->p_end_ccw;
1400 pEnd->write1=0x00; /* second end ccw is now active */
1401 /* set up Tic CCWs */
1402 p_last_ccw->w_TIC_1.cda=
1403 (__u32)__pa(&pEnd->write2_nop1);
1404 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1405 pEnd->write2_nop2.flags =
1406 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1407 pEnd->write2_nop2.cda=0;
1408 pEnd->write2_nop2.count=1;
1410 else { /* end of if (pEnd->write1)*/
1411 pEnd->write1=0x01; /* first end ccw is now active */
1412 /* set up Tic CCWs */
1413 p_last_ccw->w_TIC_1.cda=
1414 (__u32)__pa(&pEnd->write1_nop1);
1415 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1416 pEnd->write1_nop2.flags =
1417 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1418 pEnd->write1_nop2.cda=0;
1419 pEnd->write1_nop2.count=1;
1420 } /* end if if (pEnd->write1) */
1422 if (privptr->p_write_active_first==NULL ) {
1423 privptr->p_write_active_first=p_first_ccw;
1424 privptr->p_write_active_last=p_last_ccw;
1427 /* set up Tic CCWs */
1429 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1432 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1437 * first set of ending CCW's is chained to the new write
1438 * chain, so the second set is chained to the active chain
1439 * Therefore modify the second set to point the new write chain.
1440 * make sure we update the CCW atomically
1441 * so channel does not fetch it when it's only half done
1443 memcpy( &pEnd->write2_nop2, &tempCCW ,
1444 sizeof(struct ccw1));
1445 privptr->p_write_active_last->w_TIC_1.cda=
1446 (__u32)__pa(&p_first_ccw->write);
1450 /*make sure we update the CCW atomically
1451 *so channel does not fetch it when it's only half done
1453 memcpy(&pEnd->write1_nop2, &tempCCW ,
1454 sizeof(struct ccw1));
1455 privptr->p_write_active_last->w_TIC_1.cda=
1456 (__u32)__pa(&p_first_ccw->write);
1458 } /* end if if (pEnd->write1) */
1460 privptr->p_write_active_last->next=p_first_ccw;
1461 privptr->p_write_active_last=p_last_ccw;
1464 } /* endif (p_first_ccw!=NULL) */
1465 dev_kfree_skb_any(skb);
1472 claw_strt_out_IO(dev );
1473 /* if write free count is zero , set NOBUFFER */
1474 if (privptr->write_free_count==0) {
1475 claw_setbit_busy(TB_NOBUFFER,dev);
1478 claw_clearbit_busy(TB_TX,dev);
1481 } /* end of claw_hw_tx */
1483 /*-------------------------------------------------------------------*
1487 *--------------------------------------------------------------------*/
1490 init_ccw_bk(struct net_device *dev)
1493 __u32 ccw_blocks_required;
1494 __u32 ccw_blocks_perpage;
1495 __u32 ccw_pages_required;
1496 __u32 claw_reads_perpage=1;
1497 __u32 claw_read_pages;
1498 __u32 claw_writes_perpage=1;
1499 __u32 claw_write_pages;
1501 struct ccwbk*p_free_chain;
1503 struct ccwbk*p_last_CCWB;
1504 struct ccwbk*p_first_CCWB;
1505 struct endccw *p_endccw=NULL;
1506 addr_t real_address;
1507 struct claw_privbk *privptr = dev->ml_priv;
1508 struct clawh *pClawH=NULL;
1509 addr_t real_TIC_address;
1511 CLAW_DBF_TEXT(4, trace, "init_ccw");
1513 /* initialize statistics field */
1514 privptr->active_link_ID=0;
1515 /* initialize ccwbk pointers */
1516 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1517 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1518 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1519 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1520 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1521 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1522 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1523 privptr->buffs_alloc = 0;
1524 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1525 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1526 /* initialize free write ccwbk counter */
1527 privptr->write_free_count=0; /* number of free bufs on write chain */
1531 * We need 1 CCW block for each read buffer, 1 for each
1532 * write buffer, plus 1 for ClawSignalBlock
1534 ccw_blocks_required =
1535 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
1537 * compute number of CCW blocks that will fit in a page
1539 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1541 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
1544 * read and write sizes are set by 2 constants in claw.h
1545 * 4k and 32k. Unpacked values other than 4k are not going to
1546 * provide good performance. With packing buffers support 32k
1549 if (privptr->p_env->read_size < PAGE_SIZE) {
1550 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1551 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1552 claw_reads_perpage);
1554 else { /* > or equal */
1555 privptr->p_buff_pages_perread =
1556 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1557 claw_read_pages = privptr->p_env->read_buffers *
1558 privptr->p_buff_pages_perread;
1560 if (privptr->p_env->write_size < PAGE_SIZE) {
1561 claw_writes_perpage =
1562 PAGE_SIZE / privptr->p_env->write_size;
1563 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1564 claw_writes_perpage);
1567 else { /* > or equal */
1568 privptr->p_buff_pages_perwrite =
1569 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1570 claw_write_pages = privptr->p_env->write_buffers *
1571 privptr->p_buff_pages_perwrite;
1574 * allocate ccw_pages_required
1576 if (privptr->p_buff_ccw==NULL) {
1577 privptr->p_buff_ccw=
1578 (void *)__get_free_pages(__GFP_DMA,
1579 (int)pages_to_order_of_mag(ccw_pages_required ));
1580 if (privptr->p_buff_ccw==NULL) {
1583 privptr->p_buff_ccw_num=ccw_pages_required;
1585 memset(privptr->p_buff_ccw, 0x00,
1586 privptr->p_buff_ccw_num * PAGE_SIZE);
1589 * obtain ending ccw block address
1592 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1593 real_address = (__u32)__pa(privptr->p_end_ccw);
1594 /* Initialize ending CCW block */
1595 p_endccw=privptr->p_end_ccw;
1596 p_endccw->real=real_address;
1597 p_endccw->write1=0x00;
1598 p_endccw->read1=0x00;
1601 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1602 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1603 p_endccw->write1_nop1.count = 1;
1604 p_endccw->write1_nop1.cda = 0;
1607 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1608 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1609 p_endccw->write1_nop2.count = 1;
1610 p_endccw->write1_nop2.cda = 0;
1613 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1614 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1615 p_endccw->write2_nop1.count = 1;
1616 p_endccw->write2_nop1.cda = 0;
1619 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1620 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1621 p_endccw->write2_nop2.count = 1;
1622 p_endccw->write2_nop2.cda = 0;
1625 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1626 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1627 p_endccw->read1_nop1.count = 1;
1628 p_endccw->read1_nop1.cda = 0;
1631 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1632 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1633 p_endccw->read1_nop2.count = 1;
1634 p_endccw->read1_nop2.cda = 0;
1637 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1638 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1639 p_endccw->read2_nop1.count = 1;
1640 p_endccw->read2_nop1.cda = 0;
1643 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1644 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1645 p_endccw->read2_nop2.count = 1;
1646 p_endccw->read2_nop2.cda = 0;
1649 * Build a chain of CCWs
1652 p_buff=privptr->p_buff_ccw;
1655 for (i=0 ; i < ccw_pages_required; i++ ) {
1656 real_address = (__u32)__pa(p_buff);
1658 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1659 p_buf->next = p_free_chain;
1660 p_free_chain = p_buf;
1661 p_buf->real=(__u32)__pa(p_buf);
1667 * Initialize ClawSignalBlock
1670 if (privptr->p_claw_signal_blk==NULL) {
1671 privptr->p_claw_signal_blk=p_free_chain;
1672 p_free_chain=p_free_chain->next;
1673 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1674 pClawH->length=0xffff;
1675 pClawH->opcode=0xff;
1676 pClawH->flag=CLAW_BUSY;
1680 * allocate write_pages_required and add to free chain
1682 if (privptr->p_buff_write==NULL) {
1683 if (privptr->p_env->write_size < PAGE_SIZE) {
1684 privptr->p_buff_write=
1685 (void *)__get_free_pages(__GFP_DMA,
1686 (int)pages_to_order_of_mag(claw_write_pages ));
1687 if (privptr->p_buff_write==NULL) {
1688 privptr->p_buff_ccw=NULL;
1692 * Build CLAW write free chain
1696 memset(privptr->p_buff_write, 0x00,
1697 ccw_pages_required * PAGE_SIZE);
1698 privptr->p_write_free_chain=NULL;
1700 p_buff=privptr->p_buff_write;
1702 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1703 p_buf = p_free_chain; /* get a CCW */
1704 p_free_chain = p_buf->next;
1705 p_buf->next =privptr->p_write_free_chain;
1706 privptr->p_write_free_chain = p_buf;
1707 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1708 p_buf-> write.cda = (__u32)__pa(p_buff);
1709 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1710 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1711 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1712 p_buf-> w_read_FF.count = 1;
1713 p_buf-> w_read_FF.cda =
1714 (__u32)__pa(&p_buf-> header.flag);
1715 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1716 p_buf-> w_TIC_1.flags = 0;
1717 p_buf-> w_TIC_1.count = 0;
1719 if (((unsigned long)p_buff +
1720 privptr->p_env->write_size) >=
1721 ((unsigned long)(p_buff+2*
1722 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1723 p_buff = p_buff+privptr->p_env->write_size;
1727 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1729 privptr->p_write_free_chain=NULL;
1730 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1731 p_buff=(void *)__get_free_pages(__GFP_DMA,
1732 (int)pages_to_order_of_mag(
1733 privptr->p_buff_pages_perwrite) );
1735 free_pages((unsigned long)privptr->p_buff_ccw,
1736 (int)pages_to_order_of_mag(
1737 privptr->p_buff_ccw_num));
1738 privptr->p_buff_ccw=NULL;
1739 p_buf=privptr->p_buff_write;
1740 while (p_buf!=NULL) {
1741 free_pages((unsigned long)
1743 (int)pages_to_order_of_mag(
1744 privptr->p_buff_pages_perwrite));
1748 } /* Error on get_pages */
1749 memset(p_buff, 0x00, privptr->p_env->write_size );
1750 p_buf = p_free_chain;
1751 p_free_chain = p_buf->next;
1752 p_buf->next = privptr->p_write_free_chain;
1753 privptr->p_write_free_chain = p_buf;
1754 privptr->p_buff_write = p_buf;
1755 p_buf->p_buffer=(struct clawbuf *)p_buff;
1756 p_buf-> write.cda = (__u32)__pa(p_buff);
1757 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1758 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1759 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1760 p_buf-> w_read_FF.count = 1;
1761 p_buf-> w_read_FF.cda =
1762 (__u32)__pa(&p_buf-> header.flag);
1763 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1764 p_buf-> w_TIC_1.flags = 0;
1765 p_buf-> w_TIC_1.count = 0;
1766 } /* for all write_buffers */
1768 } /* else buffers are PAGE_SIZE or bigger */
1771 privptr->p_buff_write_num=claw_write_pages;
1772 privptr->write_free_count=privptr->p_env->write_buffers;
1776 * allocate read_pages_required and chain to free chain
1778 if (privptr->p_buff_read==NULL) {
1779 if (privptr->p_env->read_size < PAGE_SIZE) {
1780 privptr->p_buff_read=
1781 (void *)__get_free_pages(__GFP_DMA,
1782 (int)pages_to_order_of_mag(claw_read_pages) );
1783 if (privptr->p_buff_read==NULL) {
1784 free_pages((unsigned long)privptr->p_buff_ccw,
1785 (int)pages_to_order_of_mag(
1786 privptr->p_buff_ccw_num));
1787 /* free the write pages size is < page size */
1788 free_pages((unsigned long)privptr->p_buff_write,
1789 (int)pages_to_order_of_mag(
1790 privptr->p_buff_write_num));
1791 privptr->p_buff_ccw=NULL;
1792 privptr->p_buff_write=NULL;
1795 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1796 privptr->p_buff_read_num=claw_read_pages;
1798 * Build CLAW read free chain
1801 p_buff=privptr->p_buff_read;
1802 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1803 p_buf = p_free_chain;
1804 p_free_chain = p_buf->next;
1806 if (p_last_CCWB==NULL) {
1812 p_buf->next=p_first_CCWB;
1814 (__u32)__pa(&p_first_CCWB -> read );
1819 p_buf->p_buffer=(struct clawbuf *)p_buff;
1820 /* initialize read command */
1821 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1822 p_buf-> read.cda = (__u32)__pa(p_buff);
1823 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1824 p_buf-> read.count = privptr->p_env->read_size;
1826 /* initialize read_h command */
1827 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1828 p_buf-> read_h.cda =
1829 (__u32)__pa(&(p_buf->header));
1830 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1831 p_buf-> read_h.count = sizeof(struct clawh);
1833 /* initialize Signal command */
1834 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1835 p_buf-> signal.cda =
1836 (__u32)__pa(&(pClawH->flag));
1837 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1838 p_buf-> signal.count = 1;
1840 /* initialize r_TIC_1 command */
1841 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1842 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1843 p_buf-> r_TIC_1.flags = 0;
1844 p_buf-> r_TIC_1.count = 0;
1846 /* initialize r_read_FF command */
1847 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1848 p_buf-> r_read_FF.cda =
1849 (__u32)__pa(&(pClawH->flag));
1850 p_buf-> r_read_FF.flags =
1851 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1852 p_buf-> r_read_FF.count = 1;
1854 /* initialize r_TIC_2 */
1855 memcpy(&p_buf->r_TIC_2,
1856 &p_buf->r_TIC_1, sizeof(struct ccw1));
1858 /* initialize Header */
1859 p_buf->header.length=0xffff;
1860 p_buf->header.opcode=0xff;
1861 p_buf->header.flag=CLAW_PENDING;
1863 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1864 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1867 p_buff= p_buff+privptr->p_env->read_size;
1871 (void *)((unsigned long)
1872 (p_buff+2*(privptr->p_env->read_size)-1)
1875 } /* for read_buffers */
1876 } /* read_size < PAGE_SIZE */
1877 else { /* read Size >= PAGE_SIZE */
1878 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1879 p_buff = (void *)__get_free_pages(__GFP_DMA,
1880 (int)pages_to_order_of_mag(
1881 privptr->p_buff_pages_perread));
1883 free_pages((unsigned long)privptr->p_buff_ccw,
1884 (int)pages_to_order_of_mag(privptr->
1886 /* free the write pages */
1887 p_buf=privptr->p_buff_write;
1888 while (p_buf!=NULL) {
1890 (unsigned long)p_buf->p_buffer,
1891 (int)pages_to_order_of_mag(
1892 privptr->p_buff_pages_perwrite));
1895 /* free any read pages already alloc */
1896 p_buf=privptr->p_buff_read;
1897 while (p_buf!=NULL) {
1899 (unsigned long)p_buf->p_buffer,
1900 (int)pages_to_order_of_mag(
1901 privptr->p_buff_pages_perread));
1904 privptr->p_buff_ccw=NULL;
1905 privptr->p_buff_write=NULL;
1908 memset(p_buff, 0x00, privptr->p_env->read_size);
1909 p_buf = p_free_chain;
1910 privptr->p_buff_read = p_buf;
1911 p_free_chain = p_buf->next;
1913 if (p_last_CCWB==NULL) {
1919 p_buf->next=p_first_CCWB;
1922 &p_first_CCWB -> read );
1926 /* save buff address */
1927 p_buf->p_buffer=(struct clawbuf *)p_buff;
1928 /* initialize read command */
1929 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1930 p_buf-> read.cda = (__u32)__pa(p_buff);
1931 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1932 p_buf-> read.count = privptr->p_env->read_size;
1934 /* initialize read_h command */
1935 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1936 p_buf-> read_h.cda =
1937 (__u32)__pa(&(p_buf->header));
1938 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1939 p_buf-> read_h.count = sizeof(struct clawh);
1941 /* initialize Signal command */
1942 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1943 p_buf-> signal.cda =
1944 (__u32)__pa(&(pClawH->flag));
1945 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1946 p_buf-> signal.count = 1;
1948 /* initialize r_TIC_1 command */
1949 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1950 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1951 p_buf-> r_TIC_1.flags = 0;
1952 p_buf-> r_TIC_1.count = 0;
1954 /* initialize r_read_FF command */
1955 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1956 p_buf-> r_read_FF.cda =
1957 (__u32)__pa(&(pClawH->flag));
1958 p_buf-> r_read_FF.flags =
1959 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1960 p_buf-> r_read_FF.count = 1;
1962 /* initialize r_TIC_2 */
1963 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1964 sizeof(struct ccw1));
1966 /* initialize Header */
1967 p_buf->header.length=0xffff;
1968 p_buf->header.opcode=0xff;
1969 p_buf->header.flag=CLAW_PENDING;
1971 } /* For read_buffers */
1972 } /* read_size >= PAGE_SIZE */
1973 } /* pBuffread = NULL */
1974 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1975 privptr->buffs_alloc = 1;
1978 } /* end of init_ccw_bk */
1980 /*-------------------------------------------------------------------*
1984 *--------------------------------------------------------------------*/
1987 probe_error( struct ccwgroup_device *cgdev)
1989 struct claw_privbk *privptr;
1991 CLAW_DBF_TEXT(4, trace, "proberr");
1992 privptr = (struct claw_privbk *) cgdev->dev.driver_data;
1993 if (privptr != NULL) {
1994 cgdev->dev.driver_data = NULL;
1995 kfree(privptr->p_env);
1996 kfree(privptr->p_mtc_envelope);
2001 /*-------------------------------------------------------------------*
2002 * claw_process_control *
2005 *--------------------------------------------------------------------*/
2008 claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2011 struct clawbuf *p_buf;
2012 struct clawctl ctlbk;
2013 struct clawctl *p_ctlbk;
2014 char temp_host_name[8];
2015 char temp_ws_name[8];
2016 struct claw_privbk *privptr;
2017 struct claw_env *p_env;
2018 struct sysval *p_sysval;
2019 struct conncmd *p_connect=NULL;
2021 struct chbk *p_ch = NULL;
2022 struct device *tdev;
2023 CLAW_DBF_TEXT(2, setup, "clw_cntl");
2024 udelay(1000); /* Wait a ms for the control packets to
2025 *catch up to each other */
2026 privptr = dev->ml_priv;
2027 p_env=privptr->p_env;
2028 tdev = &privptr->channel[READ].cdev->dev;
2029 memcpy( &temp_host_name, p_env->host_name, 8);
2030 memcpy( &temp_ws_name, p_env->adapter_name , 8);
2031 dev_info(tdev, "%s: CLAW device %.8s: "
2032 "Received Control Packet\n",
2033 dev->name, temp_ws_name);
2034 if (privptr->release_pend==1) {
2037 p_buf=p_ccw->p_buffer;
2039 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2040 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2042 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2044 switch (p_ctlbk->command)
2046 case SYSTEM_VALIDATE_REQUEST:
2047 if (p_ctlbk->version != CLAW_VERSION_ID) {
2048 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2049 CLAW_RC_WRONG_VERSION);
2050 dev_warn(tdev, "The communication peer of %s"
2051 " uses an incorrect API version %d\n",
2052 dev->name, p_ctlbk->version);
2054 p_sysval = (struct sysval *)&(p_ctlbk->data);
2055 dev_info(tdev, "%s: Recv Sys Validate Request: "
2056 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2058 dev->name, p_ctlbk->version,
2060 p_ctlbk->correlator,
2062 p_sysval->host_name);
2063 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2064 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2065 CLAW_RC_NAME_MISMATCH);
2066 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2067 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2068 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
2070 "Host name %s for %s does not match the"
2071 " remote adapter name %s\n",
2072 p_sysval->host_name,
2076 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2077 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2078 CLAW_RC_NAME_MISMATCH);
2079 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2080 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2081 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
2082 dev_warn(tdev, "Adapter name %s for %s does not match"
2083 " the remote host name %s\n",
2088 if ((p_sysval->write_frame_size < p_env->write_size) &&
2089 (p_env->packing == 0)) {
2090 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2091 CLAW_RC_HOST_RCV_TOO_SMALL);
2093 "The local write buffer is smaller than the"
2094 " remote read buffer\n");
2095 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2097 if ((p_sysval->read_frame_size < p_env->read_size) &&
2098 (p_env->packing == 0)) {
2099 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2100 CLAW_RC_HOST_RCV_TOO_SMALL);
2102 "The local read buffer is smaller than the"
2103 " remote write buffer\n");
2104 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2106 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
2108 "CLAW device %.8s: System validate"
2109 " completed.\n", temp_ws_name);
2111 "%s: sys Validate Rsize:%d Wsize:%d\n",
2112 dev->name, p_sysval->read_frame_size,
2113 p_sysval->write_frame_size);
2114 privptr->system_validate_comp = 1;
2115 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2116 p_env->packing = PACKING_ASK;
2117 claw_strt_conn_req(dev);
2119 case SYSTEM_VALIDATE_RESPONSE:
2120 p_sysval = (struct sysval *)&(p_ctlbk->data);
2122 "Settings for %s validated (version=%d, "
2123 "remote device=%d, rc=%d, adapter name=%.8s, "
2124 "host name=%.8s)\n",
2127 p_ctlbk->correlator,
2130 p_sysval->host_name);
2131 switch (p_ctlbk->rc) {
2133 dev_info(tdev, "%s: CLAW device "
2134 "%.8s: System validate completed.\n",
2135 dev->name, temp_ws_name);
2136 if (privptr->system_validate_comp == 0)
2137 claw_strt_conn_req(dev);
2138 privptr->system_validate_comp = 1;
2140 case CLAW_RC_NAME_MISMATCH:
2141 dev_warn(tdev, "Validating %s failed because of"
2142 " a host or adapter name mismatch\n",
2145 case CLAW_RC_WRONG_VERSION:
2146 dev_warn(tdev, "Validating %s failed because of a"
2147 " version conflict\n",
2150 case CLAW_RC_HOST_RCV_TOO_SMALL:
2151 dev_warn(tdev, "Validating %s failed because of a"
2152 " frame size conflict\n",
2156 dev_warn(tdev, "The communication peer of %s rejected"
2157 " the connection\n",
2163 case CONNECTION_REQUEST:
2164 p_connect = (struct conncmd *)&(p_ctlbk->data);
2165 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2166 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2170 p_ctlbk->correlator,
2171 p_connect->host_name,
2172 p_connect->WS_name);
2173 if (privptr->active_link_ID != 0) {
2174 claw_snd_disc(dev, p_ctlbk);
2175 dev_info(tdev, "%s rejected a connection request"
2176 " because it is already active\n",
2179 if (p_ctlbk->linkid != 1) {
2180 claw_snd_disc(dev, p_ctlbk);
2181 dev_info(tdev, "%s rejected a request to open multiple"
2185 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2187 claw_snd_disc(dev, p_ctlbk);
2188 dev_info(tdev, "%s rejected a connection request"
2189 " because of a type mismatch\n",
2192 claw_send_control(dev,
2193 CONNECTION_CONFIRM, p_ctlbk->linkid,
2194 p_ctlbk->correlator,
2195 0, p_connect->host_name,
2196 p_connect->WS_name);
2197 if (p_env->packing == PACKING_ASK) {
2198 p_env->packing = PACK_SEND;
2199 claw_snd_conn_req(dev, 0);
2201 dev_info(tdev, "%s: CLAW device %.8s: Connection "
2202 "completed link_id=%d.\n",
2203 dev->name, temp_ws_name,
2205 privptr->active_link_ID = p_ctlbk->linkid;
2206 p_ch = &privptr->channel[WRITE];
2207 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2209 case CONNECTION_RESPONSE:
2210 p_connect = (struct conncmd *)&(p_ctlbk->data);
2211 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2212 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2216 p_ctlbk->correlator,
2218 p_connect->host_name,
2219 p_connect->WS_name);
2221 if (p_ctlbk->rc != 0) {
2222 dev_warn(tdev, "The communication peer of %s rejected"
2223 " a connection request\n",
2228 p_connect->host_name, p_connect->WS_name);
2230 claw_snd_disc(dev, p_ctlbk);
2231 dev_warn(tdev, "The communication peer of %s"
2232 " rejected a connection "
2233 "request because of a type mismatch\n",
2236 /* should be until CONNECTION_CONFIRM */
2237 privptr->active_link_ID = -(p_ctlbk->linkid);
2239 case CONNECTION_CONFIRM:
2240 p_connect = (struct conncmd *)&(p_ctlbk->data);
2242 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2243 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2247 p_ctlbk->correlator,
2248 p_connect->host_name,
2249 p_connect->WS_name);
2250 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2251 privptr->active_link_ID = p_ctlbk->linkid;
2252 if (p_env->packing > PACKING_ASK) {
2254 "%s: Confirmed Now packing\n", dev->name);
2255 p_env->packing = DO_PACKED;
2257 p_ch = &privptr->channel[WRITE];
2258 wake_up(&p_ch->wait);
2260 dev_warn(tdev, "Activating %s failed because of"
2261 " an incorrect link ID=%d\n",
2262 dev->name, p_ctlbk->linkid);
2263 claw_snd_disc(dev, p_ctlbk);
2267 dev_info(tdev, "%s: Disconnect: "
2268 "Vers=%d,link_id=%d,Corr=%d\n",
2269 dev->name, p_ctlbk->version,
2270 p_ctlbk->linkid, p_ctlbk->correlator);
2271 if ((p_ctlbk->linkid == 2) &&
2272 (p_env->packing == PACK_SEND)) {
2273 privptr->active_link_ID = 1;
2274 p_env->packing = DO_PACKED;
2276 privptr->active_link_ID = 0;
2279 dev_warn(tdev, "The communication peer of %s failed\n",
2283 dev_warn(tdev, "The communication peer of %s sent"
2284 " an unknown command code\n",
2290 } /* end of claw_process_control */
2293 /*-------------------------------------------------------------------*
2294 * claw_send_control *
2296 *--------------------------------------------------------------------*/
2299 claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2300 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2302 struct claw_privbk *privptr;
2303 struct clawctl *p_ctl;
2304 struct sysval *p_sysval;
2305 struct conncmd *p_connect;
2306 struct sk_buff *skb;
2308 CLAW_DBF_TEXT(2, setup, "sndcntl");
2309 privptr = dev->ml_priv;
2310 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2312 p_ctl->command=type;
2313 p_ctl->version=CLAW_VERSION_ID;
2315 p_ctl->correlator=correlator;
2318 p_sysval=(struct sysval *)&p_ctl->data;
2319 p_connect=(struct conncmd *)&p_ctl->data;
2321 switch (p_ctl->command) {
2322 case SYSTEM_VALIDATE_REQUEST:
2323 case SYSTEM_VALIDATE_RESPONSE:
2324 memcpy(&p_sysval->host_name, local_name, 8);
2325 memcpy(&p_sysval->WS_name, remote_name, 8);
2326 if (privptr->p_env->packing > 0) {
2327 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2328 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
2330 /* how big is the biggest group of packets */
2331 p_sysval->read_frame_size =
2332 privptr->p_env->read_size;
2333 p_sysval->write_frame_size =
2334 privptr->p_env->write_size;
2336 memset(&p_sysval->reserved, 0x00, 4);
2338 case CONNECTION_REQUEST:
2339 case CONNECTION_RESPONSE:
2340 case CONNECTION_CONFIRM:
2342 memcpy(&p_sysval->host_name, local_name, 8);
2343 memcpy(&p_sysval->WS_name, remote_name, 8);
2344 if (privptr->p_env->packing > 0) {
2345 /* How big is the biggest packet */
2346 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2347 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2349 memset(&p_connect->reserved1, 0x00, 4);
2350 memset(&p_connect->reserved2, 0x00, 4);
2357 /* write Control Record to the device */
2360 skb = dev_alloc_skb(sizeof(struct clawctl));
2364 memcpy(skb_put(skb, sizeof(struct clawctl)),
2365 p_ctl, sizeof(struct clawctl));
2366 if (privptr->p_env->packing >= PACK_SEND)
2367 claw_hw_tx(skb, dev, 1);
2369 claw_hw_tx(skb, dev, 0);
2371 } /* end of claw_send_control */
2373 /*-------------------------------------------------------------------*
2374 * claw_snd_conn_req *
2376 *--------------------------------------------------------------------*/
2378 claw_snd_conn_req(struct net_device *dev, __u8 link)
2381 struct claw_privbk *privptr = dev->ml_priv;
2382 struct clawctl *p_ctl;
2384 CLAW_DBF_TEXT(2, setup, "snd_conn");
2386 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2387 p_ctl->linkid = link;
2388 if ( privptr->system_validate_comp==0x00 ) {
2391 if (privptr->p_env->packing == PACKING_ASK )
2392 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2393 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2394 if (privptr->p_env->packing == PACK_SEND) {
2395 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2396 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2398 if (privptr->p_env->packing == 0)
2399 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2400 HOST_APPL_NAME, privptr->p_env->api_type);
2403 } /* end of claw_snd_conn_req */
2406 /*-------------------------------------------------------------------*
2409 *--------------------------------------------------------------------*/
2412 claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2415 struct conncmd * p_connect;
2417 CLAW_DBF_TEXT(2, setup, "snd_dsc");
2418 p_connect=(struct conncmd *)&p_ctl->data;
2420 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2421 p_ctl->correlator, 0,
2422 p_connect->host_name, p_connect->WS_name);
2424 } /* end of claw_snd_disc */
2427 /*-------------------------------------------------------------------*
2428 * claw_snd_sys_validate_rsp *
2430 *--------------------------------------------------------------------*/
2433 claw_snd_sys_validate_rsp(struct net_device *dev,
2434 struct clawctl *p_ctl, __u32 return_code)
2436 struct claw_env * p_env;
2437 struct claw_privbk *privptr;
2440 CLAW_DBF_TEXT(2, setup, "chkresp");
2441 privptr = dev->ml_priv;
2442 p_env=privptr->p_env;
2443 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2448 p_env->adapter_name );
2450 } /* end of claw_snd_sys_validate_rsp */
2452 /*-------------------------------------------------------------------*
2453 * claw_strt_conn_req *
2455 *--------------------------------------------------------------------*/
2458 claw_strt_conn_req(struct net_device *dev )
2462 CLAW_DBF_TEXT(2, setup, "conn_req");
2463 rc=claw_snd_conn_req(dev, 1);
2465 } /* end of claw_strt_conn_req */
2469 /*-------------------------------------------------------------------*
2471 *-------------------------------------------------------------------*/
2474 net_device_stats *claw_stats(struct net_device *dev)
2476 struct claw_privbk *privptr;
2478 CLAW_DBF_TEXT(4, trace, "stats");
2479 privptr = dev->ml_priv;
2480 return &privptr->stats;
2481 } /* end of claw_stats */
2484 /*-------------------------------------------------------------------*
2487 *--------------------------------------------------------------------*/
2489 unpack_read(struct net_device *dev )
2491 struct sk_buff *skb;
2492 struct claw_privbk *privptr;
2493 struct claw_env *p_env;
2494 struct ccwbk *p_this_ccw;
2495 struct ccwbk *p_first_ccw;
2496 struct ccwbk *p_last_ccw;
2497 struct clawph *p_packh;
2499 struct clawctl *p_ctlrec=NULL;
2500 struct device *p_dev;
2505 __u8 mtc_this_frm=0;
2510 CLAW_DBF_TEXT(4, trace, "unpkread");
2515 privptr = dev->ml_priv;
2517 p_dev = &privptr->channel[READ].cdev->dev;
2518 p_env = privptr->p_env;
2519 p_this_ccw=privptr->p_read_active_first;
2521 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
2524 p_this_ccw->header.flag=CLAW_PENDING;
2525 privptr->p_read_active_first=p_this_ccw->next;
2526 p_this_ccw->next=NULL;
2527 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2528 if ((p_env->packing == PACK_SEND) &&
2529 (p_packh->len == 32) &&
2530 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2531 p_packh++; /* peek past pack header */
2532 p_ctlrec = (struct clawctl *)p_packh;
2533 p_packh--; /* un peek */
2534 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2535 (p_ctlrec->command == CONNECTION_CONFIRM))
2536 p_env->packing = DO_PACKED;
2538 if (p_env->packing == DO_PACKED)
2539 link_num=p_packh->link_num;
2541 link_num=p_this_ccw->header.opcode / 8;
2542 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
2544 if (p_this_ccw->header.length!=
2545 privptr->p_env->read_size ) {
2547 "The communication peer of %s"
2549 " frame of length %02x\n",
2550 dev->name, p_this_ccw->header.length);
2554 if (privptr->mtc_skipping) {
2556 * We're in the mode of skipping past a
2557 * multi-frame message
2558 * that we can't process for some reason or other.
2559 * The first frame without the More-To-Come flag is
2560 * the last frame of the skipped message.
2562 /* in case of More-To-Come not set in this frame */
2563 if (mtc_this_frm==0) {
2564 privptr->mtc_skipping=0; /* Ok, the end */
2565 privptr->mtc_logical_link=-1;
2571 claw_process_control(dev, p_this_ccw);
2572 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
2576 if (p_env->packing == DO_PACKED) {
2577 if (pack_off > p_env->read_size)
2579 p_packd = p_this_ccw->p_buffer+pack_off;
2580 p_packh = (struct clawph *) p_packd;
2581 if ((p_packh->len == 0) || /* done with this frame? */
2582 (p_packh->flag != 0))
2584 bytes_to_mov = p_packh->len;
2585 pack_off += bytes_to_mov+sizeof(struct clawph);
2588 bytes_to_mov=p_this_ccw->header.length;
2590 if (privptr->mtc_logical_link<0) {
2593 * if More-To-Come is set in this frame then we don't know
2594 * length of entire message, and hence have to allocate
2597 /* We are starting a new envelope */
2598 privptr->mtc_offset=0;
2599 privptr->mtc_logical_link=link_num;
2602 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2604 privptr->stats.rx_frame_errors++;
2607 if (p_env->packing == DO_PACKED) {
2608 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2609 p_packd+sizeof(struct clawph), bytes_to_mov);
2612 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2613 p_this_ccw->p_buffer, bytes_to_mov);
2615 if (mtc_this_frm==0) {
2616 len_of_data=privptr->mtc_offset+bytes_to_mov;
2617 skb=dev_alloc_skb(len_of_data);
2619 memcpy(skb_put(skb,len_of_data),
2620 privptr->p_mtc_envelope,
2623 skb_reset_mac_header(skb);
2624 skb->protocol=htons(ETH_P_IP);
2625 skb->ip_summed=CHECKSUM_UNNECESSARY;
2626 privptr->stats.rx_packets++;
2627 privptr->stats.rx_bytes+=len_of_data;
2631 dev_info(p_dev, "Allocating a buffer for"
2632 " incoming data failed\n");
2633 privptr->stats.rx_dropped++;
2635 privptr->mtc_offset=0;
2636 privptr->mtc_logical_link=-1;
2639 privptr->mtc_offset+=bytes_to_mov;
2641 if (p_env->packing == DO_PACKED)
2645 * Remove ThisCCWblock from active read queue, and add it
2646 * to queue of free blocks to be reused.
2649 p_this_ccw->header.length=0xffff;
2650 p_this_ccw->header.opcode=0xff;
2652 * add this one to the free queue for later reuse
2654 if (p_first_ccw==NULL) {
2655 p_first_ccw = p_this_ccw;
2658 p_last_ccw->next = p_this_ccw;
2660 p_last_ccw = p_this_ccw;
2662 * chain to next block on active read queue
2664 p_this_ccw = privptr->p_read_active_first;
2665 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
2666 } /* end of while */
2668 /* check validity */
2670 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
2671 add_claw_reads(dev, p_first_ccw, p_last_ccw);
2672 claw_strt_read(dev, LOCK_YES);
2674 } /* end of unpack_read */
2676 /*-------------------------------------------------------------------*
2679 *--------------------------------------------------------------------*/
2681 claw_strt_read (struct net_device *dev, int lock )
2685 unsigned long saveflags = 0;
2686 struct claw_privbk *privptr = dev->ml_priv;
2687 struct ccwbk*p_ccwbk;
2689 struct clawh *p_clawh;
2690 p_ch=&privptr->channel[READ];
2692 CLAW_DBF_TEXT(4, trace, "StRdNter");
2693 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2694 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2696 if ((privptr->p_write_active_first!=NULL &&
2697 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2698 (privptr->p_read_active_first!=NULL &&
2699 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2700 p_clawh->flag=CLAW_BUSY; /* 0xff */
2702 if (lock==LOCK_YES) {
2703 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2705 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2706 CLAW_DBF_TEXT(4, trace, "HotRead");
2707 p_ccwbk=privptr->p_read_active_first;
2708 parm = (unsigned long) p_ch;
2709 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2712 ccw_check_return_code(p_ch->cdev, rc);
2716 CLAW_DBF_TEXT(2, trace, "ReadAct");
2719 if (lock==LOCK_YES) {
2720 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2722 CLAW_DBF_TEXT(4, trace, "StRdExit");
2724 } /* end of claw_strt_read */
2726 /*-------------------------------------------------------------------*
2727 * claw_strt_out_IO *
2729 *--------------------------------------------------------------------*/
2732 claw_strt_out_IO( struct net_device *dev )
2736 struct claw_privbk *privptr;
2738 struct ccwbk *p_first_ccw;
2743 privptr = (struct claw_privbk *)dev->ml_priv;
2744 p_ch=&privptr->channel[WRITE];
2746 CLAW_DBF_TEXT(4, trace, "strt_io");
2747 p_first_ccw=privptr->p_write_active_first;
2749 if (p_ch->claw_state == CLAW_STOP)
2751 if (p_first_ccw == NULL) {
2754 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2755 parm = (unsigned long) p_ch;
2756 CLAW_DBF_TEXT(2, trace, "StWrtIO");
2757 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2760 ccw_check_return_code(p_ch->cdev, rc);
2763 dev->trans_start = jiffies;
2765 } /* end of claw_strt_out_IO */
2767 /*-------------------------------------------------------------------*
2768 * Free write buffers *
2770 *--------------------------------------------------------------------*/
2773 claw_free_wrt_buf( struct net_device *dev )
2776 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
2777 struct ccwbk*p_first_ccw;
2778 struct ccwbk*p_last_ccw;
2779 struct ccwbk*p_this_ccw;
2780 struct ccwbk*p_next_ccw;
2782 CLAW_DBF_TEXT(4, trace, "freewrtb");
2783 /* scan the write queue to free any completed write packets */
2786 p_this_ccw=privptr->p_write_active_first;
2787 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2789 p_next_ccw = p_this_ccw->next;
2790 if (((p_next_ccw!=NULL) &&
2791 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2792 ((p_this_ccw == privptr->p_write_active_last) &&
2793 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2794 /* The next CCW is OK or this is */
2795 /* the last CCW...free it @A1A */
2796 privptr->p_write_active_first=p_this_ccw->next;
2797 p_this_ccw->header.flag=CLAW_PENDING;
2798 p_this_ccw->next=privptr->p_write_free_chain;
2799 privptr->p_write_free_chain=p_this_ccw;
2800 ++privptr->write_free_count;
2801 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2802 p_this_ccw=privptr->p_write_active_first;
2803 privptr->stats.tx_packets++;
2809 if (privptr->write_free_count!=0) {
2810 claw_clearbit_busy(TB_NOBUFFER,dev);
2812 /* whole chain removed? */
2813 if (privptr->p_write_active_first==NULL) {
2814 privptr->p_write_active_last=NULL;
2816 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
2820 /*-------------------------------------------------------------------*
2821 * claw free netdevice *
2823 *--------------------------------------------------------------------*/
2825 claw_free_netdevice(struct net_device * dev, int free_dev)
2827 struct claw_privbk *privptr;
2829 CLAW_DBF_TEXT(2, setup, "free_dev");
2832 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2833 privptr = dev->ml_priv;
2834 if (dev->flags & IFF_RUNNING)
2837 privptr->channel[READ].ndev = NULL; /* say it's free */
2839 dev->ml_priv = NULL;
2845 CLAW_DBF_TEXT(2, setup, "free_ok");
2849 * Claw init netdevice
2850 * Initialize everything of the net device except the name and the
2853 static const struct net_device_ops claw_netdev_ops = {
2854 .ndo_open = claw_open,
2855 .ndo_stop = claw_release,
2856 .ndo_get_stats = claw_stats,
2857 .ndo_start_xmit = claw_tx,
2858 .ndo_change_mtu = claw_change_mtu,
2862 claw_init_netdevice(struct net_device * dev)
2864 CLAW_DBF_TEXT(2, setup, "init_dev");
2865 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
2866 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
2867 dev->hard_header_len = 0;
2869 dev->type = ARPHRD_SLIP;
2870 dev->tx_queue_len = 1300;
2871 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
2872 dev->netdev_ops = &claw_netdev_ops;
2873 CLAW_DBF_TEXT(2, setup, "initok");
2878 * Init a new channel in the privptr->channel[i].
2880 * @param cdev The ccw_device to be added.
2882 * @return 0 on success, !0 on error.
2885 add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2888 struct ccw_dev_id dev_id;
2890 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
2891 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2892 p_ch = &privptr->channel[i];
2894 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
2895 ccw_device_get_id(cdev, &dev_id);
2896 p_ch->devno = dev_id.devno;
2897 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
2906 * Setup an interface.
2908 * @param cgdev Device to be setup.
2910 * @returns 0 on success, !0 on failure.
2913 claw_new_device(struct ccwgroup_device *cgdev)
2915 struct claw_privbk *privptr;
2916 struct claw_env *p_env;
2917 struct net_device *dev;
2919 struct ccw_dev_id dev_id;
2921 dev_info(&cgdev->dev, "add for %s\n",
2922 dev_name(&cgdev->cdev[READ]->dev));
2923 CLAW_DBF_TEXT(2, setup, "new_dev");
2924 privptr = cgdev->dev.driver_data;
2925 cgdev->cdev[READ]->dev.driver_data = privptr;
2926 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2929 p_env = privptr->p_env;
2930 ccw_device_get_id(cgdev->cdev[READ], &dev_id);
2931 p_env->devno[READ] = dev_id.devno;
2932 ccw_device_get_id(cgdev->cdev[WRITE], &dev_id);
2933 p_env->devno[WRITE] = dev_id.devno;
2934 ret = add_channel(cgdev->cdev[0],0,privptr);
2936 ret = add_channel(cgdev->cdev[1],1,privptr);
2938 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2939 " failed with error code %d\n", ret);
2942 ret = ccw_device_set_online(cgdev->cdev[READ]);
2944 dev_warn(&cgdev->dev,
2945 "Setting the read subchannel online"
2946 " failed with error code %d\n", ret);
2949 ret = ccw_device_set_online(cgdev->cdev[WRITE]);
2951 dev_warn(&cgdev->dev,
2952 "Setting the write subchannel online "
2953 "failed with error code %d\n", ret);
2956 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2958 dev_warn(&cgdev->dev,
2959 "Activating the CLAW device failed\n");
2962 dev->ml_priv = privptr;
2963 cgdev->dev.driver_data = privptr;
2964 cgdev->cdev[READ]->dev.driver_data = privptr;
2965 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2967 SET_NETDEV_DEV(dev, &cgdev->dev);
2968 if (register_netdev(dev) != 0) {
2969 claw_free_netdevice(dev, 1);
2970 CLAW_DBF_TEXT(2, trace, "regfail");
2973 dev->flags &=~IFF_RUNNING;
2974 if (privptr->buffs_alloc == 0) {
2975 ret=init_ccw_bk(dev);
2977 unregister_netdev(dev);
2978 claw_free_netdevice(dev,1);
2979 CLAW_DBF_TEXT(2, trace, "ccwmem");
2983 privptr->channel[READ].ndev = dev;
2984 privptr->channel[WRITE].ndev = dev;
2985 privptr->p_env->ndev = dev;
2987 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
2988 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2989 dev->name, p_env->read_size,
2990 p_env->write_size, p_env->read_buffers,
2991 p_env->write_buffers, p_env->devno[READ],
2992 p_env->devno[WRITE]);
2993 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
2994 ":%.8s api_type: %.8s\n",
2995 dev->name, p_env->host_name,
2996 p_env->adapter_name , p_env->api_type);
2999 ccw_device_set_offline(cgdev->cdev[1]);
3000 ccw_device_set_offline(cgdev->cdev[0]);
3005 claw_purge_skb_queue(struct sk_buff_head *q)
3007 struct sk_buff *skb;
3009 CLAW_DBF_TEXT(4, trace, "purgque");
3010 while ((skb = skb_dequeue(q))) {
3011 atomic_dec(&skb->users);
3012 dev_kfree_skb_any(skb);
3017 * Shutdown an interface.
3019 * @param cgdev Device to be shut down.
3021 * @returns 0 on success, !0 on failure.
3024 claw_shutdown_device(struct ccwgroup_device *cgdev)
3026 struct claw_privbk *priv;
3027 struct net_device *ndev;
3030 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
3031 priv = cgdev->dev.driver_data;
3034 ndev = priv->channel[READ].ndev;
3036 /* Close the device */
3037 dev_info(&cgdev->dev, "%s: shutting down \n",
3039 if (ndev->flags & IFF_RUNNING)
3040 ret = claw_release(ndev);
3041 ndev->flags &=~IFF_RUNNING;
3042 unregister_netdev(ndev);
3043 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
3044 claw_free_netdevice(ndev, 1);
3045 priv->channel[READ].ndev = NULL;
3046 priv->channel[WRITE].ndev = NULL;
3047 priv->p_env->ndev = NULL;
3049 ccw_device_set_offline(cgdev->cdev[1]);
3050 ccw_device_set_offline(cgdev->cdev[0]);
3055 claw_remove_device(struct ccwgroup_device *cgdev)
3057 struct claw_privbk *priv;
3060 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
3061 priv = cgdev->dev.driver_data;
3063 dev_info(&cgdev->dev, " will be removed.\n");
3064 if (cgdev->state == CCWGROUP_ONLINE)
3065 claw_shutdown_device(cgdev);
3066 claw_remove_files(&cgdev->dev);
3067 kfree(priv->p_mtc_envelope);
3068 priv->p_mtc_envelope=NULL;
3071 kfree(priv->channel[0].irb);
3072 priv->channel[0].irb=NULL;
3073 kfree(priv->channel[1].irb);
3074 priv->channel[1].irb=NULL;
3076 cgdev->dev.driver_data=NULL;
3077 cgdev->cdev[READ]->dev.driver_data = NULL;
3078 cgdev->cdev[WRITE]->dev.driver_data = NULL;
3079 put_device(&cgdev->dev);
3089 claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
3091 struct claw_privbk *priv;
3092 struct claw_env * p_env;
3094 priv = dev->driver_data;
3097 p_env = priv->p_env;
3098 return sprintf(buf, "%s\n",p_env->host_name);
3102 claw_hname_write(struct device *dev, struct device_attribute *attr,
3103 const char *buf, size_t count)
3105 struct claw_privbk *priv;
3106 struct claw_env * p_env;
3108 priv = dev->driver_data;
3111 p_env = priv->p_env;
3112 if (count > MAX_NAME_LEN+1)
3114 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3115 strncpy(p_env->host_name,buf, count);
3116 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3117 p_env->host_name[MAX_NAME_LEN] = 0x00;
3118 CLAW_DBF_TEXT(2, setup, "HstnSet");
3119 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
3124 static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3127 claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
3129 struct claw_privbk *priv;
3130 struct claw_env * p_env;
3132 priv = dev->driver_data;
3135 p_env = priv->p_env;
3136 return sprintf(buf, "%s\n", p_env->adapter_name);
3140 claw_adname_write(struct device *dev, struct device_attribute *attr,
3141 const char *buf, size_t count)
3143 struct claw_privbk *priv;
3144 struct claw_env * p_env;
3146 priv = dev->driver_data;
3149 p_env = priv->p_env;
3150 if (count > MAX_NAME_LEN+1)
3152 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3153 strncpy(p_env->adapter_name,buf, count);
3154 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3155 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
3156 CLAW_DBF_TEXT(2, setup, "AdnSet");
3157 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
3162 static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3165 claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
3167 struct claw_privbk *priv;
3168 struct claw_env * p_env;
3170 priv = dev->driver_data;
3173 p_env = priv->p_env;
3174 return sprintf(buf, "%s\n",
3179 claw_apname_write(struct device *dev, struct device_attribute *attr,
3180 const char *buf, size_t count)
3182 struct claw_privbk *priv;
3183 struct claw_env * p_env;
3185 priv = dev->driver_data;
3188 p_env = priv->p_env;
3189 if (count > MAX_NAME_LEN+1)
3191 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3192 strncpy(p_env->api_type,buf, count);
3193 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3194 p_env->api_type[MAX_NAME_LEN] = 0x00;
3195 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3196 p_env->read_size=DEF_PACK_BUFSIZE;
3197 p_env->write_size=DEF_PACK_BUFSIZE;
3198 p_env->packing=PACKING_ASK;
3199 CLAW_DBF_TEXT(2, setup, "PACKING");
3203 p_env->read_size=CLAW_FRAME_SIZE;
3204 p_env->write_size=CLAW_FRAME_SIZE;
3205 CLAW_DBF_TEXT(2, setup, "ApiSet");
3207 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
3211 static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3214 claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3216 struct claw_privbk *priv;
3217 struct claw_env * p_env;
3219 priv = dev->driver_data;
3222 p_env = priv->p_env;
3223 return sprintf(buf, "%d\n", p_env->write_buffers);
3227 claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3228 const char *buf, size_t count)
3230 struct claw_privbk *priv;
3231 struct claw_env * p_env;
3234 priv = dev->driver_data;
3237 p_env = priv->p_env;
3238 sscanf(buf, "%i", &nnn);
3239 if (p_env->packing) {
3245 if ((nnn > max ) || (nnn < 2))
3247 p_env->write_buffers = nnn;
3248 CLAW_DBF_TEXT(2, setup, "Wbufset");
3249 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
3253 static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3256 claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
3258 struct claw_privbk *priv;
3259 struct claw_env * p_env;
3261 priv = dev->driver_data;
3264 p_env = priv->p_env;
3265 return sprintf(buf, "%d\n", p_env->read_buffers);
3269 claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3270 const char *buf, size_t count)
3272 struct claw_privbk *priv;
3273 struct claw_env *p_env;
3276 priv = dev->driver_data;
3279 p_env = priv->p_env;
3280 sscanf(buf, "%i", &nnn);
3281 if (p_env->packing) {
3287 if ((nnn > max ) || (nnn < 2))
3289 p_env->read_buffers = nnn;
3290 CLAW_DBF_TEXT(2, setup, "Rbufset");
3291 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
3295 static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3297 static struct attribute *claw_attr[] = {
3298 &dev_attr_read_buffer.attr,
3299 &dev_attr_write_buffer.attr,
3300 &dev_attr_adapter_name.attr,
3301 &dev_attr_api_type.attr,
3302 &dev_attr_host_name.attr,
3306 static struct attribute_group claw_attr_group = {
3311 claw_add_files(struct device *dev)
3313 CLAW_DBF_TEXT(2, setup, "add_file");
3314 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3318 claw_remove_files(struct device *dev)
3320 CLAW_DBF_TEXT(2, setup, "rem_file");
3321 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3324 /*--------------------------------------------------------------------*
3325 * claw_init and cleanup *
3326 *---------------------------------------------------------------------*/
3331 unregister_cu3088_discipline(&claw_group_driver);
3332 claw_unregister_debug_facility();
3333 pr_info("Driver unloaded\n");
3338 * Initialize module.
3339 * This is called just after the module is loaded.
3341 * @return 0 on success, !0 on error.
3348 pr_info("Loading %s\n", version);
3349 ret = claw_register_debug_facility();
3351 pr_err("Registering with the S/390 debug feature"
3352 " failed with error code %d\n", ret);
3355 CLAW_DBF_TEXT(2, setup, "init_mod");
3356 ret = register_cu3088_discipline(&claw_group_driver);
3358 CLAW_DBF_TEXT(2, setup, "init_bad");
3359 claw_unregister_debug_facility();
3360 pr_err("Registering with the cu3088 device driver failed "
3361 "with error code %d\n", ret);
3366 module_init(claw_init);
3367 module_exit(claw_cleanup);
3369 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3370 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3371 "Copyright 2000,2008 IBM Corporation\n");
3372 MODULE_LICENSE("GPL");