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
];
341 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
342 rc
=claw_hw_tx( skb
, dev
, 1 );
343 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
344 CLAW_DBF_TEXT_(4, trace
, "clawtx%d", rc
);
348 } /* end of claw_tx */
350 /*------------------------------------------------------------------*
351 * pack the collect queue into an skb and return it *
352 * If not packing just return the top skb from the queue *
353 *------------------------------------------------------------------*/
355 static struct sk_buff
*
356 claw_pack_skb(struct claw_privbk
*privptr
)
358 struct sk_buff
*new_skb
,*held_skb
;
359 struct chbk
*p_ch
= &privptr
->channel
[WRITE
];
360 struct claw_env
*p_env
= privptr
->p_env
;
361 int pkt_cnt
,pk_ind
,so_far
;
363 new_skb
= NULL
; /* assume no dice */
365 CLAW_DBF_TEXT(4, trace
, "PackSKBe");
366 if (!skb_queue_empty(&p_ch
->collect_queue
)) {
368 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
370 dev_kfree_skb_any(held_skb
);
373 if (p_env
->packing
!= DO_PACKED
)
375 /* get a new SKB we will pack at least one */
376 new_skb
= dev_alloc_skb(p_env
->write_size
);
377 if (new_skb
== NULL
) {
378 atomic_inc(&held_skb
->users
);
379 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
382 /* we have packed packet and a place to put it */
385 new_skb
->cb
[1] = 'P'; /* every skb on queue has pack header */
386 while ((pk_ind
) && (held_skb
!= NULL
)) {
387 if (held_skb
->len
+so_far
<= p_env
->write_size
-8) {
388 memcpy(skb_put(new_skb
,held_skb
->len
),
389 held_skb
->data
,held_skb
->len
);
390 privptr
->stats
.tx_packets
++;
391 so_far
+= held_skb
->len
;
393 dev_kfree_skb_any(held_skb
);
394 held_skb
= skb_dequeue(&p_ch
->collect_queue
);
396 atomic_dec(&held_skb
->users
);
399 atomic_inc(&held_skb
->users
);
400 skb_queue_head(&p_ch
->collect_queue
,held_skb
);
404 CLAW_DBF_TEXT(4, trace
, "PackSKBx");
408 /*-------------------------------------------------------------------*
411 *-------------------------------------------------------------------*/
414 claw_change_mtu(struct net_device
*dev
, int new_mtu
)
416 struct claw_privbk
*privptr
= dev
->ml_priv
;
418 CLAW_DBF_TEXT(4, trace
, "setmtu");
419 buff_size
= privptr
->p_env
->write_size
;
420 if ((new_mtu
< 60) || (new_mtu
> buff_size
)) {
425 } /* end of claw_change_mtu */
428 /*-------------------------------------------------------------------*
431 *-------------------------------------------------------------------*/
433 claw_open(struct net_device
*dev
)
438 unsigned long saveflags
=0;
440 struct claw_privbk
*privptr
;
441 DECLARE_WAITQUEUE(wait
, current
);
442 struct timer_list timer
;
445 CLAW_DBF_TEXT(4, trace
, "open");
446 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
447 /* allocate and initialize CCW blocks */
448 if (privptr
->buffs_alloc
== 0) {
451 CLAW_DBF_TEXT(2, trace
, "openmem");
455 privptr
->system_validate_comp
=0;
456 privptr
->release_pend
=0;
457 if(strncmp(privptr
->p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
458 privptr
->p_env
->read_size
=DEF_PACK_BUFSIZE
;
459 privptr
->p_env
->write_size
=DEF_PACK_BUFSIZE
;
460 privptr
->p_env
->packing
=PACKING_ASK
;
462 privptr
->p_env
->packing
=0;
463 privptr
->p_env
->read_size
=CLAW_FRAME_SIZE
;
464 privptr
->p_env
->write_size
=CLAW_FRAME_SIZE
;
467 tasklet_init(&privptr
->channel
[READ
].tasklet
, claw_irq_tasklet
,
468 (unsigned long) &privptr
->channel
[READ
]);
469 for ( i
= 0; i
< 2; i
++) {
470 CLAW_DBF_TEXT_(2, trace
, "opn_ch%d", i
);
471 init_waitqueue_head(&privptr
->channel
[i
].wait
);
472 /* skb_queue_head_init(&p_ch->io_queue); */
475 &privptr
->channel
[WRITE
].collect_queue
);
476 privptr
->channel
[i
].flag_a
= 0;
477 privptr
->channel
[i
].IO_active
= 0;
478 privptr
->channel
[i
].flag
&= ~CLAW_TIMER
;
480 timer
.function
= (void *)claw_timer
;
481 timer
.data
= (unsigned long)(&privptr
->channel
[i
]);
482 timer
.expires
= jiffies
+ 15*HZ
;
484 spin_lock_irqsave(get_ccwdev_lock(
485 privptr
->channel
[i
].cdev
), saveflags
);
486 parm
= (unsigned long) &privptr
->channel
[i
];
487 privptr
->channel
[i
].claw_state
= CLAW_START_HALT_IO
;
489 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
490 rc
= ccw_device_halt(
491 (struct ccw_device
*)privptr
->channel
[i
].cdev
,parm
);
492 set_current_state(TASK_INTERRUPTIBLE
);
493 spin_unlock_irqrestore(
494 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
496 set_current_state(TASK_RUNNING
);
497 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
499 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
500 if((privptr
->channel
[i
].flag
& CLAW_TIMER
) == 0x00)
503 if ((((privptr
->channel
[READ
].last_dstat
|
504 privptr
->channel
[WRITE
].last_dstat
) &
505 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) ||
506 (((privptr
->channel
[READ
].flag
|
507 privptr
->channel
[WRITE
].flag
) & CLAW_TIMER
) != 0x00)) {
508 dev_info(&privptr
->channel
[READ
].cdev
->dev
,
509 "%s: remote side is not ready\n", dev
->name
);
510 CLAW_DBF_TEXT(2, trace
, "notrdy");
512 for ( i
= 0; i
< 2; i
++) {
514 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
516 parm
= (unsigned long) &privptr
->channel
[i
];
517 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
518 rc
= ccw_device_halt(
519 (struct ccw_device
*)&privptr
->channel
[i
].cdev
,
521 spin_unlock_irqrestore(
522 get_ccwdev_lock(privptr
->channel
[i
].cdev
),
525 ccw_check_return_code(
526 privptr
->channel
[i
].cdev
, rc
);
529 free_pages((unsigned long)privptr
->p_buff_ccw
,
530 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
531 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
532 free_pages((unsigned long)privptr
->p_buff_read
,
533 (int)pages_to_order_of_mag(
534 privptr
->p_buff_read_num
));
537 p_buf
=privptr
->p_read_active_first
;
538 while (p_buf
!=NULL
) {
539 free_pages((unsigned long)p_buf
->p_buffer
,
540 (int)pages_to_order_of_mag(
541 privptr
->p_buff_pages_perread
));
545 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
546 free_pages((unsigned long)privptr
->p_buff_write
,
547 (int)pages_to_order_of_mag(
548 privptr
->p_buff_write_num
));
551 p_buf
=privptr
->p_write_active_first
;
552 while (p_buf
!=NULL
) {
553 free_pages((unsigned long)p_buf
->p_buffer
,
554 (int)pages_to_order_of_mag(
555 privptr
->p_buff_pages_perwrite
));
559 privptr
->buffs_alloc
= 0;
560 privptr
->channel
[READ
].flag
= 0x00;
561 privptr
->channel
[WRITE
].flag
= 0x00;
562 privptr
->p_buff_ccw
=NULL
;
563 privptr
->p_buff_read
=NULL
;
564 privptr
->p_buff_write
=NULL
;
565 claw_clear_busy(dev
);
566 CLAW_DBF_TEXT(2, trace
, "open EIO");
570 /* Send SystemValidate command */
572 claw_clear_busy(dev
);
573 CLAW_DBF_TEXT(4, trace
, "openok");
575 } /* end of claw_open */
577 /*-------------------------------------------------------------------*
581 *--------------------------------------------------------------------*/
583 claw_irq_handler(struct ccw_device
*cdev
,
584 unsigned long intparm
, struct irb
*irb
)
586 struct chbk
*p_ch
= NULL
;
587 struct claw_privbk
*privptr
= NULL
;
588 struct net_device
*dev
= NULL
;
589 struct claw_env
*p_env
;
590 struct chbk
*p_ch_r
=NULL
;
592 CLAW_DBF_TEXT(4, trace
, "clawirq");
593 /* Bypass all 'unsolicited interrupts' */
594 if (!cdev
->dev
.driver_data
) {
595 dev_warn(&cdev
->dev
, "An uninitialized CLAW device received an"
596 " IRQ, c-%02x d-%02x\n",
597 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
);
598 CLAW_DBF_TEXT(2, trace
, "badirq");
601 privptr
= (struct claw_privbk
*)cdev
->dev
.driver_data
;
603 /* Try to extract channel from driver data. */
604 if (privptr
->channel
[READ
].cdev
== cdev
)
605 p_ch
= &privptr
->channel
[READ
];
606 else if (privptr
->channel
[WRITE
].cdev
== cdev
)
607 p_ch
= &privptr
->channel
[WRITE
];
609 dev_warn(&cdev
->dev
, "The device is not a CLAW device\n");
610 CLAW_DBF_TEXT(2, trace
, "badchan");
613 CLAW_DBF_TEXT_(4, trace
, "IRQCH=%d", p_ch
->flag
);
615 dev
= (struct net_device
*) (p_ch
->ndev
);
616 p_env
=privptr
->p_env
;
618 /* Copy interruption response block. */
619 memcpy(p_ch
->irb
, irb
, sizeof(struct irb
));
621 /* Check for good subchannel return code, otherwise info message */
622 if (irb
->scsw
.cmd
.cstat
&& !(irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
)) {
624 "%s: subchannel check for device: %04x -"
625 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
626 dev
->name
, p_ch
->devno
,
627 irb
->scsw
.cmd
.cstat
, irb
->scsw
.cmd
.dstat
,
629 CLAW_DBF_TEXT(2, trace
, "chanchk");
633 /* Check the reason-code of a unit check */
634 if (irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
)
635 ccw_check_unit_check(p_ch
, irb
->ecw
[0]);
637 /* State machine to bring the connection up, down and to restart */
638 p_ch
->last_dstat
= irb
->scsw
.cmd
.dstat
;
640 switch (p_ch
->claw_state
) {
641 case CLAW_STOP
:/* HALT_IO by claw_release (halt sequence) */
642 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
643 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
644 (p_ch
->irb
->scsw
.cmd
.stctl
==
645 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
))))
647 wake_up(&p_ch
->wait
); /* wake up claw_release */
648 CLAW_DBF_TEXT(4, trace
, "stop");
650 case CLAW_START_HALT_IO
: /* HALT_IO issued by claw_open */
651 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
652 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
653 (p_ch
->irb
->scsw
.cmd
.stctl
==
654 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
655 CLAW_DBF_TEXT(4, trace
, "haltio");
658 if (p_ch
->flag
== CLAW_READ
) {
659 p_ch
->claw_state
= CLAW_START_READ
;
660 wake_up(&p_ch
->wait
); /* wake claw_open (READ)*/
661 } else if (p_ch
->flag
== CLAW_WRITE
) {
662 p_ch
->claw_state
= CLAW_START_WRITE
;
663 /* send SYSTEM_VALIDATE */
664 claw_strt_read(dev
, LOCK_NO
);
665 claw_send_control(dev
,
666 SYSTEM_VALIDATE_REQUEST
,
669 p_env
->adapter_name
);
671 dev_warn(&cdev
->dev
, "The CLAW device received"
672 " an unexpected IRQ, "
675 irb
->scsw
.cmd
.dstat
);
678 CLAW_DBF_TEXT(4, trace
, "haltio");
680 case CLAW_START_READ
:
681 CLAW_DBF_TEXT(4, trace
, "ReadIRQ");
682 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
683 clear_bit(0, (void *)&p_ch
->IO_active
);
684 if ((p_ch
->irb
->ecw
[0] & 0x41) == 0x41 ||
685 (p_ch
->irb
->ecw
[0] & 0x40) == 0x40 ||
686 (p_ch
->irb
->ecw
[0]) == 0) {
687 privptr
->stats
.rx_errors
++;
689 "%s: Restart is required after remote "
693 CLAW_DBF_TEXT(4, trace
, "notrdy");
696 if ((p_ch
->irb
->scsw
.cmd
.cstat
& SCHN_STAT_PCI
) &&
697 (p_ch
->irb
->scsw
.cmd
.dstat
== 0)) {
698 if (test_and_set_bit(CLAW_BH_ACTIVE
,
699 (void *)&p_ch
->flag_a
) == 0)
700 tasklet_schedule(&p_ch
->tasklet
);
702 CLAW_DBF_TEXT(4, trace
, "PCINoBH");
703 CLAW_DBF_TEXT(4, trace
, "PCI_read");
706 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
707 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
708 (p_ch
->irb
->scsw
.cmd
.stctl
==
709 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
710 CLAW_DBF_TEXT(4, trace
, "SPend_rd");
713 clear_bit(0, (void *)&p_ch
->IO_active
);
714 claw_clearbit_busy(TB_RETRY
, dev
);
715 if (test_and_set_bit(CLAW_BH_ACTIVE
,
716 (void *)&p_ch
->flag_a
) == 0)
717 tasklet_schedule(&p_ch
->tasklet
);
719 CLAW_DBF_TEXT(4, trace
, "RdBHAct");
720 CLAW_DBF_TEXT(4, trace
, "RdIRQXit");
722 case CLAW_START_WRITE
:
723 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_CHECK
) {
725 "%s: Unit Check Occured in "
726 "write channel\n", dev
->name
);
727 clear_bit(0, (void *)&p_ch
->IO_active
);
728 if (p_ch
->irb
->ecw
[0] & 0x80) {
730 "%s: Resetting Event "
731 "occurred:\n", dev
->name
);
732 init_timer(&p_ch
->timer
);
733 p_ch
->timer
.function
=
734 (void *)claw_write_retry
;
735 p_ch
->timer
.data
= (unsigned long)p_ch
;
736 p_ch
->timer
.expires
= jiffies
+ 10*HZ
;
737 add_timer(&p_ch
->timer
);
739 "%s: write connection "
740 "restarting\n", dev
->name
);
742 CLAW_DBF_TEXT(4, trace
, "rstrtwrt");
745 if (p_ch
->irb
->scsw
.cmd
.dstat
& DEV_STAT_UNIT_EXCEP
) {
746 clear_bit(0, (void *)&p_ch
->IO_active
);
748 "%s: Unit Exception "
749 "occurred in write channel\n",
752 if (!((p_ch
->irb
->scsw
.cmd
.stctl
& SCSW_STCTL_SEC_STATUS
) ||
753 (p_ch
->irb
->scsw
.cmd
.stctl
== SCSW_STCTL_STATUS_PEND
) ||
754 (p_ch
->irb
->scsw
.cmd
.stctl
==
755 (SCSW_STCTL_ALERT_STATUS
| SCSW_STCTL_STATUS_PEND
)))) {
756 CLAW_DBF_TEXT(4, trace
, "writeUE");
759 clear_bit(0, (void *)&p_ch
->IO_active
);
760 if (claw_test_and_setbit_busy(TB_TX
, dev
) == 0) {
761 claw_write_next(p_ch
);
762 claw_clearbit_busy(TB_TX
, dev
);
763 claw_clear_busy(dev
);
765 p_ch_r
= (struct chbk
*)&privptr
->channel
[READ
];
766 if (test_and_set_bit(CLAW_BH_ACTIVE
,
767 (void *)&p_ch_r
->flag_a
) == 0)
768 tasklet_schedule(&p_ch_r
->tasklet
);
769 CLAW_DBF_TEXT(4, trace
, "StWtExit");
773 "The CLAW device for %s received an unexpected IRQ\n",
775 CLAW_DBF_TEXT(2, trace
, "badIRQ");
779 } /* end of claw_irq_handler */
782 /*-------------------------------------------------------------------*
785 *--------------------------------------------------------------------*/
787 claw_irq_tasklet ( unsigned long data
)
790 struct net_device
*dev
;
791 struct claw_privbk
* privptr
;
793 p_ch
= (struct chbk
*) data
;
794 dev
= (struct net_device
*)p_ch
->ndev
;
795 CLAW_DBF_TEXT(4, trace
, "IRQtask");
796 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
798 clear_bit(CLAW_BH_ACTIVE
, (void *)&p_ch
->flag_a
);
799 CLAW_DBF_TEXT(4, trace
, "TskletXt");
801 } /* end of claw_irq_bh */
803 /*-------------------------------------------------------------------*
806 *--------------------------------------------------------------------*/
808 claw_release(struct net_device
*dev
)
812 unsigned long saveflags
;
814 struct claw_privbk
*privptr
;
815 DECLARE_WAITQUEUE(wait
, current
);
816 struct ccwbk
* p_this_ccw
;
821 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
824 CLAW_DBF_TEXT(4, trace
, "release");
825 privptr
->release_pend
=1;
826 claw_setbit_busy(TB_STOP
,dev
);
827 for ( i
= 1; i
>=0 ; i
--) {
829 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
830 /* del_timer(&privptr->channel[READ].timer); */
831 privptr
->channel
[i
].claw_state
= CLAW_STOP
;
832 privptr
->channel
[i
].IO_active
= 0;
833 parm
= (unsigned long) &privptr
->channel
[i
];
835 claw_purge_skb_queue(
836 &privptr
->channel
[WRITE
].collect_queue
);
837 rc
= ccw_device_halt (privptr
->channel
[i
].cdev
, parm
);
838 if (privptr
->system_validate_comp
==0x00) /* never opened? */
839 init_waitqueue_head(&privptr
->channel
[i
].wait
);
840 add_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
841 set_current_state(TASK_INTERRUPTIBLE
);
842 spin_unlock_irqrestore(
843 get_ccwdev_lock(privptr
->channel
[i
].cdev
), saveflags
);
845 set_current_state(TASK_RUNNING
);
846 remove_wait_queue(&privptr
->channel
[i
].wait
, &wait
);
848 ccw_check_return_code(privptr
->channel
[i
].cdev
, rc
);
851 if (privptr
->pk_skb
!= NULL
) {
852 dev_kfree_skb_any(privptr
->pk_skb
);
853 privptr
->pk_skb
= NULL
;
855 if(privptr
->buffs_alloc
!= 1) {
856 CLAW_DBF_TEXT(4, trace
, "none2fre");
859 CLAW_DBF_TEXT(4, trace
, "freebufs");
860 if (privptr
->p_buff_ccw
!= NULL
) {
861 free_pages((unsigned long)privptr
->p_buff_ccw
,
862 (int)pages_to_order_of_mag(privptr
->p_buff_ccw_num
));
864 CLAW_DBF_TEXT(4, trace
, "freeread");
865 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
866 if (privptr
->p_buff_read
!= NULL
) {
867 free_pages((unsigned long)privptr
->p_buff_read
,
868 (int)pages_to_order_of_mag(privptr
->p_buff_read_num
));
872 p_buf
=privptr
->p_read_active_first
;
873 while (p_buf
!=NULL
) {
874 free_pages((unsigned long)p_buf
->p_buffer
,
875 (int)pages_to_order_of_mag(
876 privptr
->p_buff_pages_perread
));
880 CLAW_DBF_TEXT(4, trace
, "freewrit");
881 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
882 free_pages((unsigned long)privptr
->p_buff_write
,
883 (int)pages_to_order_of_mag(privptr
->p_buff_write_num
));
886 p_buf
=privptr
->p_write_active_first
;
887 while (p_buf
!=NULL
) {
888 free_pages((unsigned long)p_buf
->p_buffer
,
889 (int)pages_to_order_of_mag(
890 privptr
->p_buff_pages_perwrite
));
894 CLAW_DBF_TEXT(4, trace
, "clearptr");
895 privptr
->buffs_alloc
= 0;
896 privptr
->p_buff_ccw
=NULL
;
897 privptr
->p_buff_read
=NULL
;
898 privptr
->p_buff_write
=NULL
;
899 privptr
->system_validate_comp
=0;
900 privptr
->release_pend
=0;
901 /* Remove any writes that were pending and reset all reads */
902 p_this_ccw
=privptr
->p_read_active_first
;
903 while (p_this_ccw
!=NULL
) {
904 p_this_ccw
->header
.length
=0xffff;
905 p_this_ccw
->header
.opcode
=0xff;
906 p_this_ccw
->header
.flag
=0x00;
907 p_this_ccw
=p_this_ccw
->next
;
910 while (privptr
->p_write_active_first
!=NULL
) {
911 p_this_ccw
=privptr
->p_write_active_first
;
912 p_this_ccw
->header
.flag
=CLAW_PENDING
;
913 privptr
->p_write_active_first
=p_this_ccw
->next
;
914 p_this_ccw
->next
=privptr
->p_write_free_chain
;
915 privptr
->p_write_free_chain
=p_this_ccw
;
916 ++privptr
->write_free_count
;
918 privptr
->p_write_active_last
=NULL
;
919 privptr
->mtc_logical_link
= -1;
920 privptr
->mtc_skipping
= 1;
921 privptr
->mtc_offset
=0;
923 if (((privptr
->channel
[READ
].last_dstat
|
924 privptr
->channel
[WRITE
].last_dstat
) &
925 ~(DEV_STAT_CHN_END
| DEV_STAT_DEV_END
)) != 0x00) {
926 dev_warn(&privptr
->channel
[READ
].cdev
->dev
,
927 "Deactivating %s completed with incorrect"
928 " subchannel status "
929 "(read %02x, write %02x)\n",
931 privptr
->channel
[READ
].last_dstat
,
932 privptr
->channel
[WRITE
].last_dstat
);
933 CLAW_DBF_TEXT(2, trace
, "badclose");
935 CLAW_DBF_TEXT(4, trace
, "rlsexit");
937 } /* end of claw_release */
939 /*-------------------------------------------------------------------*
942 *--------------------------------------------------------------------*/
945 claw_write_retry ( struct chbk
*p_ch
)
948 struct net_device
*dev
=p_ch
->ndev
;
950 CLAW_DBF_TEXT(4, trace
, "w_retry");
951 if (p_ch
->claw_state
== CLAW_STOP
) {
954 claw_strt_out_IO( dev
);
955 CLAW_DBF_TEXT(4, trace
, "rtry_xit");
957 } /* end of claw_write_retry */
960 /*-------------------------------------------------------------------*
963 *--------------------------------------------------------------------*/
966 claw_write_next ( struct chbk
* p_ch
)
969 struct net_device
*dev
;
970 struct claw_privbk
*privptr
=NULL
;
971 struct sk_buff
*pk_skb
;
974 CLAW_DBF_TEXT(4, trace
, "claw_wrt");
975 if (p_ch
->claw_state
== CLAW_STOP
)
977 dev
= (struct net_device
*) p_ch
->ndev
;
978 privptr
= (struct claw_privbk
*) dev
->ml_priv
;
979 claw_free_wrt_buf( dev
);
980 if ((privptr
->write_free_count
> 0) &&
981 !skb_queue_empty(&p_ch
->collect_queue
)) {
982 pk_skb
= claw_pack_skb(privptr
);
983 while (pk_skb
!= NULL
) {
984 rc
= claw_hw_tx( pk_skb
, dev
,1);
985 if (privptr
->write_free_count
> 0) {
986 pk_skb
= claw_pack_skb(privptr
);
991 if (privptr
->p_write_active_first
!=NULL
) {
992 claw_strt_out_IO(dev
);
995 } /* end of claw_write_next */
997 /*-------------------------------------------------------------------*
1000 *--------------------------------------------------------------------*/
1003 claw_timer ( struct chbk
* p_ch
)
1005 CLAW_DBF_TEXT(4, trace
, "timer");
1006 p_ch
->flag
|= CLAW_TIMER
;
1007 wake_up(&p_ch
->wait
);
1009 } /* end of claw_timer */
1017 /*-------------------------------------------------------------------*
1019 * pages_to_order_of_mag *
1021 * takes a number of pages from 1 to 512 and returns the *
1022 * log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1023 * of magnitude get_free_pages() has an upper order of 9 *
1024 *--------------------------------------------------------------------*/
1027 pages_to_order_of_mag(int num_of_pages
)
1029 int order_of_mag
=1; /* assume 2 pages */
1032 CLAW_DBF_TEXT_(5, trace
, "pages%d", num_of_pages
);
1033 if (num_of_pages
== 1) {return 0; } /* magnitude of 0 = 1 page */
1034 /* 512 pages = 2Meg on 4k page systems */
1035 if (num_of_pages
>= 512) {return 9; }
1036 /* we have two or more pages order is at least 1 */
1037 for (nump
=2 ;nump
<= 512;nump
*=2) {
1038 if (num_of_pages
<= nump
)
1042 if (order_of_mag
> 9) { order_of_mag
= 9; } /* I know it's paranoid */
1043 CLAW_DBF_TEXT_(5, trace
, "mag%d", order_of_mag
);
1044 return order_of_mag
;
1047 /*-------------------------------------------------------------------*
1051 *--------------------------------------------------------------------*/
1053 add_claw_reads(struct net_device
*dev
, struct ccwbk
* p_first
,
1054 struct ccwbk
* p_last
)
1056 struct claw_privbk
*privptr
;
1057 struct ccw1 temp_ccw
;
1058 struct endccw
* p_end
;
1059 CLAW_DBF_TEXT(4, trace
, "addreads");
1060 privptr
= dev
->ml_priv
;
1061 p_end
= privptr
->p_end_ccw
;
1063 /* first CCW and last CCW contains a new set of read channel programs
1064 * to apend the running channel programs
1066 if ( p_first
==NULL
) {
1067 CLAW_DBF_TEXT(4, trace
, "addexit");
1071 /* set up ending CCW sequence for this segment */
1073 p_end
->read1
=0x00; /* second ending CCW is now active */
1074 /* reset ending CCWs and setup TIC CCWs */
1075 p_end
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1076 p_end
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1077 p_last
->r_TIC_1
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1078 p_last
->r_TIC_2
.cda
=(__u32
)__pa(&p_end
->read2_nop1
);
1079 p_end
->read2_nop2
.cda
=0;
1080 p_end
->read2_nop2
.count
=1;
1083 p_end
->read1
=0x01; /* first ending CCW is now active */
1084 /* reset ending CCWs and setup TIC CCWs */
1085 p_end
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1086 p_end
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1087 p_last
->r_TIC_1
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1088 p_last
->r_TIC_2
.cda
= (__u32
)__pa(&p_end
->read1_nop1
);
1089 p_end
->read1_nop2
.cda
=0;
1090 p_end
->read1_nop2
.count
=1;
1093 if ( privptr
-> p_read_active_first
==NULL
) {
1094 privptr
->p_read_active_first
= p_first
; /* set new first */
1095 privptr
->p_read_active_last
= p_last
; /* set new last */
1099 /* set up TIC ccw */
1100 temp_ccw
.cda
= (__u32
)__pa(&p_first
->read
);
1103 temp_ccw
.cmd_code
= CCW_CLAW_CMD_TIC
;
1108 /* first set of CCW's is chained to the new read */
1109 /* chain, so the second set is chained to the active chain. */
1110 /* Therefore modify the second set to point to the new */
1111 /* read chain set up TIC CCWs */
1112 /* make sure we update the CCW so channel doesn't fetch it */
1113 /* when it's only half done */
1114 memcpy( &p_end
->read2_nop2
, &temp_ccw
,
1115 sizeof(struct ccw1
));
1116 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1117 (__u32
)__pa(&p_first
->read
);
1118 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1119 (__u32
)__pa(&p_first
->read
);
1122 /* make sure we update the CCW so channel doesn't */
1123 /* fetch it when it is only half done */
1124 memcpy( &p_end
->read1_nop2
, &temp_ccw
,
1125 sizeof(struct ccw1
));
1126 privptr
->p_read_active_last
->r_TIC_1
.cda
=
1127 (__u32
)__pa(&p_first
->read
);
1128 privptr
->p_read_active_last
->r_TIC_2
.cda
=
1129 (__u32
)__pa(&p_first
->read
);
1131 /* chain in new set of blocks */
1132 privptr
->p_read_active_last
->next
= p_first
;
1133 privptr
->p_read_active_last
=p_last
;
1134 } /* end of if ( privptr-> p_read_active_first ==NULL) */
1135 CLAW_DBF_TEXT(4, trace
, "addexit");
1137 } /* end of add_claw_reads */
1139 /*-------------------------------------------------------------------*
1140 * ccw_check_return_code *
1142 *-------------------------------------------------------------------*/
1145 ccw_check_return_code(struct ccw_device
*cdev
, int return_code
)
1147 CLAW_DBF_TEXT(4, trace
, "ccwret");
1148 if (return_code
!= 0) {
1149 switch (return_code
) {
1150 case -EBUSY
: /* BUSY is a transient state no action needed */
1153 dev_err(&cdev
->dev
, "The remote channel adapter is not"
1158 "The status of the remote channel adapter"
1162 dev_err(&cdev
->dev
, "The common device layer"
1163 " returned error code %d\n",
1167 CLAW_DBF_TEXT(4, trace
, "ccwret");
1168 } /* end of ccw_check_return_code */
1170 /*-------------------------------------------------------------------*
1171 * ccw_check_unit_check *
1172 *--------------------------------------------------------------------*/
1175 ccw_check_unit_check(struct chbk
* p_ch
, unsigned char sense
)
1177 struct net_device
*ndev
= p_ch
->ndev
;
1178 struct device
*dev
= &p_ch
->cdev
->dev
;
1180 CLAW_DBF_TEXT(4, trace
, "unitchek");
1181 dev_warn(dev
, "The communication peer of %s disconnected\n",
1186 dev_warn(dev
, "The remote channel adapter for"
1187 " %s has been reset\n",
1190 } else if (sense
& 0x20) {
1192 dev_warn(dev
, "A data streaming timeout occurred"
1195 } else if (sense
& 0x10) {
1196 dev_warn(dev
, "The remote channel adapter for %s"
1200 dev_warn(dev
, "A data transfer parity error occurred"
1204 } else if (sense
& 0x10) {
1205 dev_warn(dev
, "A read data parity error occurred"
1210 } /* end of ccw_check_unit_check */
1212 /*-------------------------------------------------------------------*
1214 *--------------------------------------------------------------------*/
1216 find_link(struct net_device
*dev
, char *host_name
, char *ws_name
)
1218 struct claw_privbk
*privptr
;
1219 struct claw_env
*p_env
;
1222 CLAW_DBF_TEXT(2, setup
, "findlink");
1223 privptr
= dev
->ml_priv
;
1224 p_env
=privptr
->p_env
;
1225 switch (p_env
->packing
)
1228 if ((memcmp(WS_APPL_NAME_PACKED
, host_name
, 8)!=0) ||
1229 (memcmp(WS_APPL_NAME_PACKED
, ws_name
, 8)!=0 ))
1234 if ((memcmp(WS_APPL_NAME_IP_NAME
, host_name
, 8)!=0) ||
1235 (memcmp(WS_APPL_NAME_IP_NAME
, ws_name
, 8)!=0 ))
1239 if ((memcmp(HOST_APPL_NAME
, host_name
, 8)!=0) ||
1240 (memcmp(p_env
->api_type
, ws_name
, 8)!=0))
1246 } /* end of find_link */
1248 /*-------------------------------------------------------------------*
1252 *-------------------------------------------------------------------*/
1255 claw_hw_tx(struct sk_buff
*skb
, struct net_device
*dev
, long linkid
)
1258 struct claw_privbk
*privptr
;
1259 struct ccwbk
*p_this_ccw
;
1260 struct ccwbk
*p_first_ccw
;
1261 struct ccwbk
*p_last_ccw
;
1263 signed long len_of_data
;
1264 unsigned long bytesInThisBuffer
;
1265 unsigned char *pDataAddress
;
1266 struct endccw
*pEnd
;
1267 struct ccw1 tempCCW
;
1269 struct claw_env
*p_env
;
1271 struct clawph
*pk_head
;
1274 CLAW_DBF_TEXT(4, trace
, "hw_tx");
1275 privptr
= (struct claw_privbk
*)(dev
->ml_priv
);
1276 p_ch
=(struct chbk
*)&privptr
->channel
[WRITE
];
1277 p_env
=privptr
->p_env
;
1278 claw_free_wrt_buf(dev
); /* Clean up free chain if posible */
1279 /* scan the write queue to free any completed write packets */
1282 if ((p_env
->packing
>= PACK_SEND
) &&
1283 (skb
->cb
[1] != 'P')) {
1284 skb_push(skb
,sizeof(struct clawph
));
1285 pk_head
=(struct clawph
*)skb
->data
;
1286 pk_head
->len
=skb
->len
-sizeof(struct clawph
);
1287 if (pk_head
->len
%4) {
1288 pk_head
->len
+= 4-(pk_head
->len
%4);
1289 skb_pad(skb
,4-(pk_head
->len
%4));
1290 skb_put(skb
,4-(pk_head
->len
%4));
1292 if (p_env
->packing
== DO_PACKED
)
1293 pk_head
->link_num
= linkid
;
1295 pk_head
->link_num
= 0;
1296 pk_head
->flag
= 0x00;
1301 if (claw_check_busy(dev
)) {
1302 if (privptr
->write_free_count
!=0) {
1303 claw_clear_busy(dev
);
1306 claw_strt_out_IO(dev
);
1307 claw_free_wrt_buf( dev
);
1308 if (privptr
->write_free_count
==0) {
1309 ch
= &privptr
->channel
[WRITE
];
1310 atomic_inc(&skb
->users
);
1311 skb_queue_tail(&ch
->collect_queue
, skb
);
1315 claw_clear_busy(dev
);
1320 if (claw_test_and_setbit_busy(TB_TX
,dev
)) { /* set to busy */
1321 ch
= &privptr
->channel
[WRITE
];
1322 atomic_inc(&skb
->users
);
1323 skb_queue_tail(&ch
->collect_queue
, skb
);
1324 claw_strt_out_IO(dev
);
1329 /* See how many write buffers are required to hold this data */
1330 numBuffers
= DIV_ROUND_UP(skb
->len
, privptr
->p_env
->write_size
);
1332 /* If that number of buffers isn't available, give up for now */
1333 if (privptr
->write_free_count
< numBuffers
||
1334 privptr
->p_write_free_chain
== NULL
) {
1336 claw_setbit_busy(TB_NOBUFFER
,dev
);
1337 ch
= &privptr
->channel
[WRITE
];
1338 atomic_inc(&skb
->users
);
1339 skb_queue_tail(&ch
->collect_queue
, skb
);
1340 CLAW_DBF_TEXT(2, trace
, "clawbusy");
1343 pDataAddress
=skb
->data
;
1344 len_of_data
=skb
->len
;
1346 while (len_of_data
> 0) {
1347 p_this_ccw
=privptr
->p_write_free_chain
; /* get a block */
1348 if (p_this_ccw
== NULL
) { /* lost the race */
1349 ch
= &privptr
->channel
[WRITE
];
1350 atomic_inc(&skb
->users
);
1351 skb_queue_tail(&ch
->collect_queue
, skb
);
1354 privptr
->p_write_free_chain
=p_this_ccw
->next
;
1355 p_this_ccw
->next
=NULL
;
1356 --privptr
->write_free_count
; /* -1 */
1357 if (len_of_data
>= privptr
->p_env
->write_size
)
1358 bytesInThisBuffer
= privptr
->p_env
->write_size
;
1360 bytesInThisBuffer
= len_of_data
;
1361 memcpy( p_this_ccw
->p_buffer
,pDataAddress
, bytesInThisBuffer
);
1362 len_of_data
-=bytesInThisBuffer
;
1363 pDataAddress
+=(unsigned long)bytesInThisBuffer
;
1364 /* setup write CCW */
1365 p_this_ccw
->write
.cmd_code
= (linkid
* 8) +1;
1366 if (len_of_data
>0) {
1367 p_this_ccw
->write
.cmd_code
+=MORE_to_COME_FLAG
;
1369 p_this_ccw
->write
.count
=bytesInThisBuffer
;
1370 /* now add to end of this chain */
1371 if (p_first_ccw
==NULL
) {
1372 p_first_ccw
=p_this_ccw
;
1374 if (p_last_ccw
!=NULL
) {
1375 p_last_ccw
->next
=p_this_ccw
;
1376 /* set up TIC ccws */
1377 p_last_ccw
->w_TIC_1
.cda
=
1378 (__u32
)__pa(&p_this_ccw
->write
);
1380 p_last_ccw
=p_this_ccw
; /* save new last block */
1383 /* FirstCCW and LastCCW now contain a new set of write channel
1384 * programs to append to the running channel program
1387 if (p_first_ccw
!=NULL
) {
1388 /* setup ending ccw sequence for this segment */
1389 pEnd
=privptr
->p_end_ccw
;
1391 pEnd
->write1
=0x00; /* second end ccw is now active */
1392 /* set up Tic CCWs */
1393 p_last_ccw
->w_TIC_1
.cda
=
1394 (__u32
)__pa(&pEnd
->write2_nop1
);
1395 pEnd
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1396 pEnd
->write2_nop2
.flags
=
1397 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1398 pEnd
->write2_nop2
.cda
=0;
1399 pEnd
->write2_nop2
.count
=1;
1401 else { /* end of if (pEnd->write1)*/
1402 pEnd
->write1
=0x01; /* first end ccw is now active */
1403 /* set up Tic CCWs */
1404 p_last_ccw
->w_TIC_1
.cda
=
1405 (__u32
)__pa(&pEnd
->write1_nop1
);
1406 pEnd
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1407 pEnd
->write1_nop2
.flags
=
1408 CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1409 pEnd
->write1_nop2
.cda
=0;
1410 pEnd
->write1_nop2
.count
=1;
1411 } /* end if if (pEnd->write1) */
1413 if (privptr
->p_write_active_first
==NULL
) {
1414 privptr
->p_write_active_first
=p_first_ccw
;
1415 privptr
->p_write_active_last
=p_last_ccw
;
1418 /* set up Tic CCWs */
1420 tempCCW
.cda
=(__u32
)__pa(&p_first_ccw
->write
);
1423 tempCCW
.cmd_code
=CCW_CLAW_CMD_TIC
;
1428 * first set of ending CCW's is chained to the new write
1429 * chain, so the second set is chained to the active chain
1430 * Therefore modify the second set to point the new write chain.
1431 * make sure we update the CCW atomically
1432 * so channel does not fetch it when it's only half done
1434 memcpy( &pEnd
->write2_nop2
, &tempCCW
,
1435 sizeof(struct ccw1
));
1436 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1437 (__u32
)__pa(&p_first_ccw
->write
);
1441 /*make sure we update the CCW atomically
1442 *so channel does not fetch it when it's only half done
1444 memcpy(&pEnd
->write1_nop2
, &tempCCW
,
1445 sizeof(struct ccw1
));
1446 privptr
->p_write_active_last
->w_TIC_1
.cda
=
1447 (__u32
)__pa(&p_first_ccw
->write
);
1449 } /* end if if (pEnd->write1) */
1451 privptr
->p_write_active_last
->next
=p_first_ccw
;
1452 privptr
->p_write_active_last
=p_last_ccw
;
1455 } /* endif (p_first_ccw!=NULL) */
1456 dev_kfree_skb_any(skb
);
1463 claw_strt_out_IO(dev
);
1464 /* if write free count is zero , set NOBUFFER */
1465 if (privptr
->write_free_count
==0) {
1466 claw_setbit_busy(TB_NOBUFFER
,dev
);
1469 claw_clearbit_busy(TB_TX
,dev
);
1472 } /* end of claw_hw_tx */
1474 /*-------------------------------------------------------------------*
1478 *--------------------------------------------------------------------*/
1481 init_ccw_bk(struct net_device
*dev
)
1484 __u32 ccw_blocks_required
;
1485 __u32 ccw_blocks_perpage
;
1486 __u32 ccw_pages_required
;
1487 __u32 claw_reads_perpage
=1;
1488 __u32 claw_read_pages
;
1489 __u32 claw_writes_perpage
=1;
1490 __u32 claw_write_pages
;
1492 struct ccwbk
*p_free_chain
;
1494 struct ccwbk
*p_last_CCWB
;
1495 struct ccwbk
*p_first_CCWB
;
1496 struct endccw
*p_endccw
=NULL
;
1497 addr_t real_address
;
1498 struct claw_privbk
*privptr
= dev
->ml_priv
;
1499 struct clawh
*pClawH
=NULL
;
1500 addr_t real_TIC_address
;
1502 CLAW_DBF_TEXT(4, trace
, "init_ccw");
1504 /* initialize statistics field */
1505 privptr
->active_link_ID
=0;
1506 /* initialize ccwbk pointers */
1507 privptr
->p_write_free_chain
=NULL
; /* pointer to free ccw chain*/
1508 privptr
->p_write_active_first
=NULL
; /* pointer to the first write ccw*/
1509 privptr
->p_write_active_last
=NULL
; /* pointer to the last write ccw*/
1510 privptr
->p_read_active_first
=NULL
; /* pointer to the first read ccw*/
1511 privptr
->p_read_active_last
=NULL
; /* pointer to the last read ccw */
1512 privptr
->p_end_ccw
=NULL
; /* pointer to ending ccw */
1513 privptr
->p_claw_signal_blk
=NULL
; /* pointer to signal block */
1514 privptr
->buffs_alloc
= 0;
1515 memset(&privptr
->end_ccw
, 0x00, sizeof(struct endccw
));
1516 memset(&privptr
->ctl_bk
, 0x00, sizeof(struct clawctl
));
1517 /* initialize free write ccwbk counter */
1518 privptr
->write_free_count
=0; /* number of free bufs on write chain */
1522 * We need 1 CCW block for each read buffer, 1 for each
1523 * write buffer, plus 1 for ClawSignalBlock
1525 ccw_blocks_required
=
1526 privptr
->p_env
->read_buffers
+privptr
->p_env
->write_buffers
+1;
1528 * compute number of CCW blocks that will fit in a page
1530 ccw_blocks_perpage
= PAGE_SIZE
/ CCWBK_SIZE
;
1532 DIV_ROUND_UP(ccw_blocks_required
, ccw_blocks_perpage
);
1535 * read and write sizes are set by 2 constants in claw.h
1536 * 4k and 32k. Unpacked values other than 4k are not going to
1537 * provide good performance. With packing buffers support 32k
1540 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1541 claw_reads_perpage
= PAGE_SIZE
/ privptr
->p_env
->read_size
;
1542 claw_read_pages
= DIV_ROUND_UP(privptr
->p_env
->read_buffers
,
1543 claw_reads_perpage
);
1545 else { /* > or equal */
1546 privptr
->p_buff_pages_perread
=
1547 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1548 claw_read_pages
= privptr
->p_env
->read_buffers
*
1549 privptr
->p_buff_pages_perread
;
1551 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1552 claw_writes_perpage
=
1553 PAGE_SIZE
/ privptr
->p_env
->write_size
;
1554 claw_write_pages
= DIV_ROUND_UP(privptr
->p_env
->write_buffers
,
1555 claw_writes_perpage
);
1558 else { /* > or equal */
1559 privptr
->p_buff_pages_perwrite
=
1560 DIV_ROUND_UP(privptr
->p_env
->read_size
, PAGE_SIZE
);
1561 claw_write_pages
= privptr
->p_env
->write_buffers
*
1562 privptr
->p_buff_pages_perwrite
;
1565 * allocate ccw_pages_required
1567 if (privptr
->p_buff_ccw
==NULL
) {
1568 privptr
->p_buff_ccw
=
1569 (void *)__get_free_pages(__GFP_DMA
,
1570 (int)pages_to_order_of_mag(ccw_pages_required
));
1571 if (privptr
->p_buff_ccw
==NULL
) {
1574 privptr
->p_buff_ccw_num
=ccw_pages_required
;
1576 memset(privptr
->p_buff_ccw
, 0x00,
1577 privptr
->p_buff_ccw_num
* PAGE_SIZE
);
1580 * obtain ending ccw block address
1583 privptr
->p_end_ccw
= (struct endccw
*)&privptr
->end_ccw
;
1584 real_address
= (__u32
)__pa(privptr
->p_end_ccw
);
1585 /* Initialize ending CCW block */
1586 p_endccw
=privptr
->p_end_ccw
;
1587 p_endccw
->real
=real_address
;
1588 p_endccw
->write1
=0x00;
1589 p_endccw
->read1
=0x00;
1592 p_endccw
->write1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1593 p_endccw
->write1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1594 p_endccw
->write1_nop1
.count
= 1;
1595 p_endccw
->write1_nop1
.cda
= 0;
1598 p_endccw
->write1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1599 p_endccw
->write1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1600 p_endccw
->write1_nop2
.count
= 1;
1601 p_endccw
->write1_nop2
.cda
= 0;
1604 p_endccw
->write2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1605 p_endccw
->write2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1606 p_endccw
->write2_nop1
.count
= 1;
1607 p_endccw
->write2_nop1
.cda
= 0;
1610 p_endccw
->write2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1611 p_endccw
->write2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1612 p_endccw
->write2_nop2
.count
= 1;
1613 p_endccw
->write2_nop2
.cda
= 0;
1616 p_endccw
->read1_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1617 p_endccw
->read1_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1618 p_endccw
->read1_nop1
.count
= 1;
1619 p_endccw
->read1_nop1
.cda
= 0;
1622 p_endccw
->read1_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1623 p_endccw
->read1_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1624 p_endccw
->read1_nop2
.count
= 1;
1625 p_endccw
->read1_nop2
.cda
= 0;
1628 p_endccw
->read2_nop1
.cmd_code
= CCW_CLAW_CMD_NOP
;
1629 p_endccw
->read2_nop1
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1630 p_endccw
->read2_nop1
.count
= 1;
1631 p_endccw
->read2_nop1
.cda
= 0;
1634 p_endccw
->read2_nop2
.cmd_code
= CCW_CLAW_CMD_READFF
;
1635 p_endccw
->read2_nop2
.flags
= CCW_FLAG_SLI
| CCW_FLAG_SKIP
;
1636 p_endccw
->read2_nop2
.count
= 1;
1637 p_endccw
->read2_nop2
.cda
= 0;
1640 * Build a chain of CCWs
1643 p_buff
=privptr
->p_buff_ccw
;
1646 for (i
=0 ; i
< ccw_pages_required
; i
++ ) {
1647 real_address
= (__u32
)__pa(p_buff
);
1649 for (j
=0 ; j
< ccw_blocks_perpage
; j
++) {
1650 p_buf
->next
= p_free_chain
;
1651 p_free_chain
= p_buf
;
1652 p_buf
->real
=(__u32
)__pa(p_buf
);
1658 * Initialize ClawSignalBlock
1661 if (privptr
->p_claw_signal_blk
==NULL
) {
1662 privptr
->p_claw_signal_blk
=p_free_chain
;
1663 p_free_chain
=p_free_chain
->next
;
1664 pClawH
=(struct clawh
*)privptr
->p_claw_signal_blk
;
1665 pClawH
->length
=0xffff;
1666 pClawH
->opcode
=0xff;
1667 pClawH
->flag
=CLAW_BUSY
;
1671 * allocate write_pages_required and add to free chain
1673 if (privptr
->p_buff_write
==NULL
) {
1674 if (privptr
->p_env
->write_size
< PAGE_SIZE
) {
1675 privptr
->p_buff_write
=
1676 (void *)__get_free_pages(__GFP_DMA
,
1677 (int)pages_to_order_of_mag(claw_write_pages
));
1678 if (privptr
->p_buff_write
==NULL
) {
1679 privptr
->p_buff_ccw
=NULL
;
1683 * Build CLAW write free chain
1687 memset(privptr
->p_buff_write
, 0x00,
1688 ccw_pages_required
* PAGE_SIZE
);
1689 privptr
->p_write_free_chain
=NULL
;
1691 p_buff
=privptr
->p_buff_write
;
1693 for (i
=0 ; i
< privptr
->p_env
->write_buffers
; i
++) {
1694 p_buf
= p_free_chain
; /* get a CCW */
1695 p_free_chain
= p_buf
->next
;
1696 p_buf
->next
=privptr
->p_write_free_chain
;
1697 privptr
->p_write_free_chain
= p_buf
;
1698 p_buf
-> p_buffer
= (struct clawbuf
*)p_buff
;
1699 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1700 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1701 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1702 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1703 p_buf
-> w_read_FF
.count
= 1;
1704 p_buf
-> w_read_FF
.cda
=
1705 (__u32
)__pa(&p_buf
-> header
.flag
);
1706 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1707 p_buf
-> w_TIC_1
.flags
= 0;
1708 p_buf
-> w_TIC_1
.count
= 0;
1710 if (((unsigned long)p_buff
+
1711 privptr
->p_env
->write_size
) >=
1712 ((unsigned long)(p_buff
+2*
1713 (privptr
->p_env
->write_size
) - 1) & PAGE_MASK
)) {
1714 p_buff
= p_buff
+privptr
->p_env
->write_size
;
1718 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1720 privptr
->p_write_free_chain
=NULL
;
1721 for (i
= 0; i
< privptr
->p_env
->write_buffers
; i
++) {
1722 p_buff
=(void *)__get_free_pages(__GFP_DMA
,
1723 (int)pages_to_order_of_mag(
1724 privptr
->p_buff_pages_perwrite
) );
1726 free_pages((unsigned long)privptr
->p_buff_ccw
,
1727 (int)pages_to_order_of_mag(
1728 privptr
->p_buff_ccw_num
));
1729 privptr
->p_buff_ccw
=NULL
;
1730 p_buf
=privptr
->p_buff_write
;
1731 while (p_buf
!=NULL
) {
1732 free_pages((unsigned long)
1734 (int)pages_to_order_of_mag(
1735 privptr
->p_buff_pages_perwrite
));
1739 } /* Error on get_pages */
1740 memset(p_buff
, 0x00, privptr
->p_env
->write_size
);
1741 p_buf
= p_free_chain
;
1742 p_free_chain
= p_buf
->next
;
1743 p_buf
->next
= privptr
->p_write_free_chain
;
1744 privptr
->p_write_free_chain
= p_buf
;
1745 privptr
->p_buff_write
= p_buf
;
1746 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1747 p_buf
-> write
.cda
= (__u32
)__pa(p_buff
);
1748 p_buf
-> write
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1749 p_buf
-> w_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1750 p_buf
-> w_read_FF
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1751 p_buf
-> w_read_FF
.count
= 1;
1752 p_buf
-> w_read_FF
.cda
=
1753 (__u32
)__pa(&p_buf
-> header
.flag
);
1754 p_buf
-> w_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1755 p_buf
-> w_TIC_1
.flags
= 0;
1756 p_buf
-> w_TIC_1
.count
= 0;
1757 } /* for all write_buffers */
1759 } /* else buffers are PAGE_SIZE or bigger */
1762 privptr
->p_buff_write_num
=claw_write_pages
;
1763 privptr
->write_free_count
=privptr
->p_env
->write_buffers
;
1767 * allocate read_pages_required and chain to free chain
1769 if (privptr
->p_buff_read
==NULL
) {
1770 if (privptr
->p_env
->read_size
< PAGE_SIZE
) {
1771 privptr
->p_buff_read
=
1772 (void *)__get_free_pages(__GFP_DMA
,
1773 (int)pages_to_order_of_mag(claw_read_pages
) );
1774 if (privptr
->p_buff_read
==NULL
) {
1775 free_pages((unsigned long)privptr
->p_buff_ccw
,
1776 (int)pages_to_order_of_mag(
1777 privptr
->p_buff_ccw_num
));
1778 /* free the write pages size is < page size */
1779 free_pages((unsigned long)privptr
->p_buff_write
,
1780 (int)pages_to_order_of_mag(
1781 privptr
->p_buff_write_num
));
1782 privptr
->p_buff_ccw
=NULL
;
1783 privptr
->p_buff_write
=NULL
;
1786 memset(privptr
->p_buff_read
, 0x00, claw_read_pages
* PAGE_SIZE
);
1787 privptr
->p_buff_read_num
=claw_read_pages
;
1789 * Build CLAW read free chain
1792 p_buff
=privptr
->p_buff_read
;
1793 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1794 p_buf
= p_free_chain
;
1795 p_free_chain
= p_buf
->next
;
1797 if (p_last_CCWB
==NULL
) {
1803 p_buf
->next
=p_first_CCWB
;
1805 (__u32
)__pa(&p_first_CCWB
-> read
);
1810 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1811 /* initialize read command */
1812 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1813 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1814 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1815 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1817 /* initialize read_h command */
1818 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1819 p_buf
-> read_h
.cda
=
1820 (__u32
)__pa(&(p_buf
->header
));
1821 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1822 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1824 /* initialize Signal command */
1825 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1826 p_buf
-> signal
.cda
=
1827 (__u32
)__pa(&(pClawH
->flag
));
1828 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1829 p_buf
-> signal
.count
= 1;
1831 /* initialize r_TIC_1 command */
1832 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1833 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1834 p_buf
-> r_TIC_1
.flags
= 0;
1835 p_buf
-> r_TIC_1
.count
= 0;
1837 /* initialize r_read_FF command */
1838 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1839 p_buf
-> r_read_FF
.cda
=
1840 (__u32
)__pa(&(pClawH
->flag
));
1841 p_buf
-> r_read_FF
.flags
=
1842 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
1843 p_buf
-> r_read_FF
.count
= 1;
1845 /* initialize r_TIC_2 */
1846 memcpy(&p_buf
->r_TIC_2
,
1847 &p_buf
->r_TIC_1
, sizeof(struct ccw1
));
1849 /* initialize Header */
1850 p_buf
->header
.length
=0xffff;
1851 p_buf
->header
.opcode
=0xff;
1852 p_buf
->header
.flag
=CLAW_PENDING
;
1854 if (((unsigned long)p_buff
+privptr
->p_env
->read_size
) >=
1855 ((unsigned long)(p_buff
+2*(privptr
->p_env
->read_size
)
1858 p_buff
= p_buff
+privptr
->p_env
->read_size
;
1862 (void *)((unsigned long)
1863 (p_buff
+2*(privptr
->p_env
->read_size
)-1)
1866 } /* for read_buffers */
1867 } /* read_size < PAGE_SIZE */
1868 else { /* read Size >= PAGE_SIZE */
1869 for (i
=0 ; i
< privptr
->p_env
->read_buffers
; i
++) {
1870 p_buff
= (void *)__get_free_pages(__GFP_DMA
,
1871 (int)pages_to_order_of_mag(
1872 privptr
->p_buff_pages_perread
));
1874 free_pages((unsigned long)privptr
->p_buff_ccw
,
1875 (int)pages_to_order_of_mag(privptr
->
1877 /* free the write pages */
1878 p_buf
=privptr
->p_buff_write
;
1879 while (p_buf
!=NULL
) {
1881 (unsigned long)p_buf
->p_buffer
,
1882 (int)pages_to_order_of_mag(
1883 privptr
->p_buff_pages_perwrite
));
1886 /* free any read pages already alloc */
1887 p_buf
=privptr
->p_buff_read
;
1888 while (p_buf
!=NULL
) {
1890 (unsigned long)p_buf
->p_buffer
,
1891 (int)pages_to_order_of_mag(
1892 privptr
->p_buff_pages_perread
));
1895 privptr
->p_buff_ccw
=NULL
;
1896 privptr
->p_buff_write
=NULL
;
1899 memset(p_buff
, 0x00, privptr
->p_env
->read_size
);
1900 p_buf
= p_free_chain
;
1901 privptr
->p_buff_read
= p_buf
;
1902 p_free_chain
= p_buf
->next
;
1904 if (p_last_CCWB
==NULL
) {
1910 p_buf
->next
=p_first_CCWB
;
1913 &p_first_CCWB
-> read
);
1917 /* save buff address */
1918 p_buf
->p_buffer
=(struct clawbuf
*)p_buff
;
1919 /* initialize read command */
1920 p_buf
-> read
.cmd_code
= CCW_CLAW_CMD_READ
;
1921 p_buf
-> read
.cda
= (__u32
)__pa(p_buff
);
1922 p_buf
-> read
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1923 p_buf
-> read
.count
= privptr
->p_env
->read_size
;
1925 /* initialize read_h command */
1926 p_buf
-> read_h
.cmd_code
= CCW_CLAW_CMD_READHEADER
;
1927 p_buf
-> read_h
.cda
=
1928 (__u32
)__pa(&(p_buf
->header
));
1929 p_buf
-> read_h
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1930 p_buf
-> read_h
.count
= sizeof(struct clawh
);
1932 /* initialize Signal command */
1933 p_buf
-> signal
.cmd_code
= CCW_CLAW_CMD_SIGNAL_SMOD
;
1934 p_buf
-> signal
.cda
=
1935 (__u32
)__pa(&(pClawH
->flag
));
1936 p_buf
-> signal
.flags
= CCW_FLAG_SLI
| CCW_FLAG_CC
;
1937 p_buf
-> signal
.count
= 1;
1939 /* initialize r_TIC_1 command */
1940 p_buf
-> r_TIC_1
.cmd_code
= CCW_CLAW_CMD_TIC
;
1941 p_buf
-> r_TIC_1
.cda
= (__u32
)real_TIC_address
;
1942 p_buf
-> r_TIC_1
.flags
= 0;
1943 p_buf
-> r_TIC_1
.count
= 0;
1945 /* initialize r_read_FF command */
1946 p_buf
-> r_read_FF
.cmd_code
= CCW_CLAW_CMD_READFF
;
1947 p_buf
-> r_read_FF
.cda
=
1948 (__u32
)__pa(&(pClawH
->flag
));
1949 p_buf
-> r_read_FF
.flags
=
1950 CCW_FLAG_SLI
| CCW_FLAG_CC
| CCW_FLAG_PCI
;
1951 p_buf
-> r_read_FF
.count
= 1;
1953 /* initialize r_TIC_2 */
1954 memcpy(&p_buf
->r_TIC_2
, &p_buf
->r_TIC_1
,
1955 sizeof(struct ccw1
));
1957 /* initialize Header */
1958 p_buf
->header
.length
=0xffff;
1959 p_buf
->header
.opcode
=0xff;
1960 p_buf
->header
.flag
=CLAW_PENDING
;
1962 } /* For read_buffers */
1963 } /* read_size >= PAGE_SIZE */
1964 } /* pBuffread = NULL */
1965 add_claw_reads( dev
,p_first_CCWB
, p_last_CCWB
);
1966 privptr
->buffs_alloc
= 1;
1969 } /* end of init_ccw_bk */
1971 /*-------------------------------------------------------------------*
1975 *--------------------------------------------------------------------*/
1978 probe_error( struct ccwgroup_device
*cgdev
)
1980 struct claw_privbk
*privptr
;
1982 CLAW_DBF_TEXT(4, trace
, "proberr");
1983 privptr
= (struct claw_privbk
*) cgdev
->dev
.driver_data
;
1984 if (privptr
!= NULL
) {
1985 cgdev
->dev
.driver_data
= NULL
;
1986 kfree(privptr
->p_env
);
1987 kfree(privptr
->p_mtc_envelope
);
1992 /*-------------------------------------------------------------------*
1993 * claw_process_control *
1996 *--------------------------------------------------------------------*/
1999 claw_process_control( struct net_device
*dev
, struct ccwbk
* p_ccw
)
2002 struct clawbuf
*p_buf
;
2003 struct clawctl ctlbk
;
2004 struct clawctl
*p_ctlbk
;
2005 char temp_host_name
[8];
2006 char temp_ws_name
[8];
2007 struct claw_privbk
*privptr
;
2008 struct claw_env
*p_env
;
2009 struct sysval
*p_sysval
;
2010 struct conncmd
*p_connect
=NULL
;
2012 struct chbk
*p_ch
= NULL
;
2013 struct device
*tdev
;
2014 CLAW_DBF_TEXT(2, setup
, "clw_cntl");
2015 udelay(1000); /* Wait a ms for the control packets to
2016 *catch up to each other */
2017 privptr
= dev
->ml_priv
;
2018 p_env
=privptr
->p_env
;
2019 tdev
= &privptr
->channel
[READ
].cdev
->dev
;
2020 memcpy( &temp_host_name
, p_env
->host_name
, 8);
2021 memcpy( &temp_ws_name
, p_env
->adapter_name
, 8);
2022 dev_info(tdev
, "%s: CLAW device %.8s: "
2023 "Received Control Packet\n",
2024 dev
->name
, temp_ws_name
);
2025 if (privptr
->release_pend
==1) {
2028 p_buf
=p_ccw
->p_buffer
;
2030 if (p_env
->packing
== DO_PACKED
) { /* packing in progress?*/
2031 memcpy(p_ctlbk
, &p_buf
->buffer
[4], sizeof(struct clawctl
));
2033 memcpy(p_ctlbk
, p_buf
, sizeof(struct clawctl
));
2035 switch (p_ctlbk
->command
)
2037 case SYSTEM_VALIDATE_REQUEST
:
2038 if (p_ctlbk
->version
!= CLAW_VERSION_ID
) {
2039 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2040 CLAW_RC_WRONG_VERSION
);
2041 dev_warn(tdev
, "The communication peer of %s"
2042 " uses an incorrect API version %d\n",
2043 dev
->name
, p_ctlbk
->version
);
2045 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2046 dev_info(tdev
, "%s: Recv Sys Validate Request: "
2047 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2049 dev
->name
, p_ctlbk
->version
,
2051 p_ctlbk
->correlator
,
2053 p_sysval
->host_name
);
2054 if (memcmp(temp_host_name
, p_sysval
->host_name
, 8)) {
2055 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2056 CLAW_RC_NAME_MISMATCH
);
2057 CLAW_DBF_TEXT(2, setup
, "HSTBAD");
2058 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->host_name
);
2059 CLAW_DBF_TEXT_(2, setup
, "%s", temp_host_name
);
2061 "Host name %s for %s does not match the"
2062 " remote adapter name %s\n",
2063 p_sysval
->host_name
,
2067 if (memcmp(temp_ws_name
, p_sysval
->WS_name
, 8)) {
2068 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2069 CLAW_RC_NAME_MISMATCH
);
2070 CLAW_DBF_TEXT(2, setup
, "WSNBAD");
2071 CLAW_DBF_TEXT_(2, setup
, "%s", p_sysval
->WS_name
);
2072 CLAW_DBF_TEXT_(2, setup
, "%s", temp_ws_name
);
2073 dev_warn(tdev
, "Adapter name %s for %s does not match"
2074 " the remote host name %s\n",
2079 if ((p_sysval
->write_frame_size
< p_env
->write_size
) &&
2080 (p_env
->packing
== 0)) {
2081 claw_snd_sys_validate_rsp(dev
, p_ctlbk
,
2082 CLAW_RC_HOST_RCV_TOO_SMALL
);
2084 "The local write buffer is smaller than the"
2085 " remote read buffer\n");
2086 CLAW_DBF_TEXT(2, setup
, "wrtszbad");
2088 if ((p_sysval
->read_frame_size
< p_env
->read_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 read buffer is smaller than the"
2094 " remote write buffer\n");
2095 CLAW_DBF_TEXT(2, setup
, "rdsizbad");
2097 claw_snd_sys_validate_rsp(dev
, p_ctlbk
, 0);
2099 "CLAW device %.8s: System validate"
2100 " completed.\n", temp_ws_name
);
2102 "%s: sys Validate Rsize:%d Wsize:%d\n",
2103 dev
->name
, p_sysval
->read_frame_size
,
2104 p_sysval
->write_frame_size
);
2105 privptr
->system_validate_comp
= 1;
2106 if (strncmp(p_env
->api_type
, WS_APPL_NAME_PACKED
, 6) == 0)
2107 p_env
->packing
= PACKING_ASK
;
2108 claw_strt_conn_req(dev
);
2110 case SYSTEM_VALIDATE_RESPONSE
:
2111 p_sysval
= (struct sysval
*)&(p_ctlbk
->data
);
2113 "Settings for %s validated (version=%d, "
2114 "remote device=%d, rc=%d, adapter name=%.8s, "
2115 "host name=%.8s)\n",
2118 p_ctlbk
->correlator
,
2121 p_sysval
->host_name
);
2122 switch (p_ctlbk
->rc
) {
2124 dev_info(tdev
, "%s: CLAW device "
2125 "%.8s: System validate completed.\n",
2126 dev
->name
, temp_ws_name
);
2127 if (privptr
->system_validate_comp
== 0)
2128 claw_strt_conn_req(dev
);
2129 privptr
->system_validate_comp
= 1;
2131 case CLAW_RC_NAME_MISMATCH
:
2132 dev_warn(tdev
, "Validating %s failed because of"
2133 " a host or adapter name mismatch\n",
2136 case CLAW_RC_WRONG_VERSION
:
2137 dev_warn(tdev
, "Validating %s failed because of a"
2138 " version conflict\n",
2141 case CLAW_RC_HOST_RCV_TOO_SMALL
:
2142 dev_warn(tdev
, "Validating %s failed because of a"
2143 " frame size conflict\n",
2147 dev_warn(tdev
, "The communication peer of %s rejected"
2148 " the connection\n",
2154 case CONNECTION_REQUEST
:
2155 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2156 dev_info(tdev
, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
2157 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2161 p_ctlbk
->correlator
,
2162 p_connect
->host_name
,
2163 p_connect
->WS_name
);
2164 if (privptr
->active_link_ID
!= 0) {
2165 claw_snd_disc(dev
, p_ctlbk
);
2166 dev_info(tdev
, "%s rejected a connection request"
2167 " because it is already active\n",
2170 if (p_ctlbk
->linkid
!= 1) {
2171 claw_snd_disc(dev
, p_ctlbk
);
2172 dev_info(tdev
, "%s rejected a request to open multiple"
2176 rc
= find_link(dev
, p_connect
->host_name
, p_connect
->WS_name
);
2178 claw_snd_disc(dev
, p_ctlbk
);
2179 dev_info(tdev
, "%s rejected a connection request"
2180 " because of a type mismatch\n",
2183 claw_send_control(dev
,
2184 CONNECTION_CONFIRM
, p_ctlbk
->linkid
,
2185 p_ctlbk
->correlator
,
2186 0, p_connect
->host_name
,
2187 p_connect
->WS_name
);
2188 if (p_env
->packing
== PACKING_ASK
) {
2189 p_env
->packing
= PACK_SEND
;
2190 claw_snd_conn_req(dev
, 0);
2192 dev_info(tdev
, "%s: CLAW device %.8s: Connection "
2193 "completed link_id=%d.\n",
2194 dev
->name
, temp_ws_name
,
2196 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2197 p_ch
= &privptr
->channel
[WRITE
];
2198 wake_up(&p_ch
->wait
); /* wake up claw_open ( WRITE) */
2200 case CONNECTION_RESPONSE
:
2201 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2202 dev_info(tdev
, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
2203 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2207 p_ctlbk
->correlator
,
2209 p_connect
->host_name
,
2210 p_connect
->WS_name
);
2212 if (p_ctlbk
->rc
!= 0) {
2213 dev_warn(tdev
, "The communication peer of %s rejected"
2214 " a connection request\n",
2219 p_connect
->host_name
, p_connect
->WS_name
);
2221 claw_snd_disc(dev
, p_ctlbk
);
2222 dev_warn(tdev
, "The communication peer of %s"
2223 " rejected a connection "
2224 "request because of a type mismatch\n",
2227 /* should be until CONNECTION_CONFIRM */
2228 privptr
->active_link_ID
= -(p_ctlbk
->linkid
);
2230 case CONNECTION_CONFIRM
:
2231 p_connect
= (struct conncmd
*)&(p_ctlbk
->data
);
2233 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
2234 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2238 p_ctlbk
->correlator
,
2239 p_connect
->host_name
,
2240 p_connect
->WS_name
);
2241 if (p_ctlbk
->linkid
== -(privptr
->active_link_ID
)) {
2242 privptr
->active_link_ID
= p_ctlbk
->linkid
;
2243 if (p_env
->packing
> PACKING_ASK
) {
2245 "%s: Confirmed Now packing\n", dev
->name
);
2246 p_env
->packing
= DO_PACKED
;
2248 p_ch
= &privptr
->channel
[WRITE
];
2249 wake_up(&p_ch
->wait
);
2251 dev_warn(tdev
, "Activating %s failed because of"
2252 " an incorrect link ID=%d\n",
2253 dev
->name
, p_ctlbk
->linkid
);
2254 claw_snd_disc(dev
, p_ctlbk
);
2258 dev_info(tdev
, "%s: Disconnect: "
2259 "Vers=%d,link_id=%d,Corr=%d\n",
2260 dev
->name
, p_ctlbk
->version
,
2261 p_ctlbk
->linkid
, p_ctlbk
->correlator
);
2262 if ((p_ctlbk
->linkid
== 2) &&
2263 (p_env
->packing
== PACK_SEND
)) {
2264 privptr
->active_link_ID
= 1;
2265 p_env
->packing
= DO_PACKED
;
2267 privptr
->active_link_ID
= 0;
2270 dev_warn(tdev
, "The communication peer of %s failed\n",
2274 dev_warn(tdev
, "The communication peer of %s sent"
2275 " an unknown command code\n",
2281 } /* end of claw_process_control */
2284 /*-------------------------------------------------------------------*
2285 * claw_send_control *
2287 *--------------------------------------------------------------------*/
2290 claw_send_control(struct net_device
*dev
, __u8 type
, __u8 link
,
2291 __u8 correlator
, __u8 rc
, char *local_name
, char *remote_name
)
2293 struct claw_privbk
*privptr
;
2294 struct clawctl
*p_ctl
;
2295 struct sysval
*p_sysval
;
2296 struct conncmd
*p_connect
;
2297 struct sk_buff
*skb
;
2299 CLAW_DBF_TEXT(2, setup
, "sndcntl");
2300 privptr
= dev
->ml_priv
;
2301 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2303 p_ctl
->command
=type
;
2304 p_ctl
->version
=CLAW_VERSION_ID
;
2306 p_ctl
->correlator
=correlator
;
2309 p_sysval
=(struct sysval
*)&p_ctl
->data
;
2310 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2312 switch (p_ctl
->command
) {
2313 case SYSTEM_VALIDATE_REQUEST
:
2314 case SYSTEM_VALIDATE_RESPONSE
:
2315 memcpy(&p_sysval
->host_name
, local_name
, 8);
2316 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2317 if (privptr
->p_env
->packing
> 0) {
2318 p_sysval
->read_frame_size
= DEF_PACK_BUFSIZE
;
2319 p_sysval
->write_frame_size
= DEF_PACK_BUFSIZE
;
2321 /* how big is the biggest group of packets */
2322 p_sysval
->read_frame_size
=
2323 privptr
->p_env
->read_size
;
2324 p_sysval
->write_frame_size
=
2325 privptr
->p_env
->write_size
;
2327 memset(&p_sysval
->reserved
, 0x00, 4);
2329 case CONNECTION_REQUEST
:
2330 case CONNECTION_RESPONSE
:
2331 case CONNECTION_CONFIRM
:
2333 memcpy(&p_sysval
->host_name
, local_name
, 8);
2334 memcpy(&p_sysval
->WS_name
, remote_name
, 8);
2335 if (privptr
->p_env
->packing
> 0) {
2336 /* How big is the biggest packet */
2337 p_connect
->reserved1
[0]=CLAW_FRAME_SIZE
;
2338 p_connect
->reserved1
[1]=CLAW_FRAME_SIZE
;
2340 memset(&p_connect
->reserved1
, 0x00, 4);
2341 memset(&p_connect
->reserved2
, 0x00, 4);
2348 /* write Control Record to the device */
2351 skb
= dev_alloc_skb(sizeof(struct clawctl
));
2355 memcpy(skb_put(skb
, sizeof(struct clawctl
)),
2356 p_ctl
, sizeof(struct clawctl
));
2357 if (privptr
->p_env
->packing
>= PACK_SEND
)
2358 claw_hw_tx(skb
, dev
, 1);
2360 claw_hw_tx(skb
, dev
, 0);
2362 } /* end of claw_send_control */
2364 /*-------------------------------------------------------------------*
2365 * claw_snd_conn_req *
2367 *--------------------------------------------------------------------*/
2369 claw_snd_conn_req(struct net_device
*dev
, __u8 link
)
2372 struct claw_privbk
*privptr
= dev
->ml_priv
;
2373 struct clawctl
*p_ctl
;
2375 CLAW_DBF_TEXT(2, setup
, "snd_conn");
2377 p_ctl
=(struct clawctl
*)&privptr
->ctl_bk
;
2378 p_ctl
->linkid
= link
;
2379 if ( privptr
->system_validate_comp
==0x00 ) {
2382 if (privptr
->p_env
->packing
== PACKING_ASK
)
2383 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2384 WS_APPL_NAME_PACKED
, WS_APPL_NAME_PACKED
);
2385 if (privptr
->p_env
->packing
== PACK_SEND
) {
2386 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2387 WS_APPL_NAME_IP_NAME
, WS_APPL_NAME_IP_NAME
);
2389 if (privptr
->p_env
->packing
== 0)
2390 rc
=claw_send_control(dev
, CONNECTION_REQUEST
,0,0,0,
2391 HOST_APPL_NAME
, privptr
->p_env
->api_type
);
2394 } /* end of claw_snd_conn_req */
2397 /*-------------------------------------------------------------------*
2400 *--------------------------------------------------------------------*/
2403 claw_snd_disc(struct net_device
*dev
, struct clawctl
* p_ctl
)
2406 struct conncmd
* p_connect
;
2408 CLAW_DBF_TEXT(2, setup
, "snd_dsc");
2409 p_connect
=(struct conncmd
*)&p_ctl
->data
;
2411 rc
=claw_send_control(dev
, DISCONNECT
, p_ctl
->linkid
,
2412 p_ctl
->correlator
, 0,
2413 p_connect
->host_name
, p_connect
->WS_name
);
2415 } /* end of claw_snd_disc */
2418 /*-------------------------------------------------------------------*
2419 * claw_snd_sys_validate_rsp *
2421 *--------------------------------------------------------------------*/
2424 claw_snd_sys_validate_rsp(struct net_device
*dev
,
2425 struct clawctl
*p_ctl
, __u32 return_code
)
2427 struct claw_env
* p_env
;
2428 struct claw_privbk
*privptr
;
2431 CLAW_DBF_TEXT(2, setup
, "chkresp");
2432 privptr
= dev
->ml_priv
;
2433 p_env
=privptr
->p_env
;
2434 rc
=claw_send_control(dev
, SYSTEM_VALIDATE_RESPONSE
,
2439 p_env
->adapter_name
);
2441 } /* end of claw_snd_sys_validate_rsp */
2443 /*-------------------------------------------------------------------*
2444 * claw_strt_conn_req *
2446 *--------------------------------------------------------------------*/
2449 claw_strt_conn_req(struct net_device
*dev
)
2453 CLAW_DBF_TEXT(2, setup
, "conn_req");
2454 rc
=claw_snd_conn_req(dev
, 1);
2456 } /* end of claw_strt_conn_req */
2460 /*-------------------------------------------------------------------*
2462 *-------------------------------------------------------------------*/
2465 net_device_stats
*claw_stats(struct net_device
*dev
)
2467 struct claw_privbk
*privptr
;
2469 CLAW_DBF_TEXT(4, trace
, "stats");
2470 privptr
= dev
->ml_priv
;
2471 return &privptr
->stats
;
2472 } /* end of claw_stats */
2475 /*-------------------------------------------------------------------*
2478 *--------------------------------------------------------------------*/
2480 unpack_read(struct net_device
*dev
)
2482 struct sk_buff
*skb
;
2483 struct claw_privbk
*privptr
;
2484 struct claw_env
*p_env
;
2485 struct ccwbk
*p_this_ccw
;
2486 struct ccwbk
*p_first_ccw
;
2487 struct ccwbk
*p_last_ccw
;
2488 struct clawph
*p_packh
;
2490 struct clawctl
*p_ctlrec
=NULL
;
2491 struct device
*p_dev
;
2496 __u8 mtc_this_frm
=0;
2501 CLAW_DBF_TEXT(4, trace
, "unpkread");
2506 privptr
= dev
->ml_priv
;
2508 p_dev
= &privptr
->channel
[READ
].cdev
->dev
;
2509 p_env
= privptr
->p_env
;
2510 p_this_ccw
=privptr
->p_read_active_first
;
2511 while (p_this_ccw
!=NULL
&& p_this_ccw
->header
.flag
!=CLAW_PENDING
) {
2514 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2515 privptr
->p_read_active_first
=p_this_ccw
->next
;
2516 p_this_ccw
->next
=NULL
;
2517 p_packh
= (struct clawph
*)p_this_ccw
->p_buffer
;
2518 if ((p_env
->packing
== PACK_SEND
) &&
2519 (p_packh
->len
== 32) &&
2520 (p_packh
->link_num
== 0)) { /* is it a packed ctl rec? */
2521 p_packh
++; /* peek past pack header */
2522 p_ctlrec
= (struct clawctl
*)p_packh
;
2523 p_packh
--; /* un peek */
2524 if ((p_ctlrec
->command
== CONNECTION_RESPONSE
) ||
2525 (p_ctlrec
->command
== CONNECTION_CONFIRM
))
2526 p_env
->packing
= DO_PACKED
;
2528 if (p_env
->packing
== DO_PACKED
)
2529 link_num
=p_packh
->link_num
;
2531 link_num
=p_this_ccw
->header
.opcode
/ 8;
2532 if ((p_this_ccw
->header
.opcode
& MORE_to_COME_FLAG
)!=0) {
2534 if (p_this_ccw
->header
.length
!=
2535 privptr
->p_env
->read_size
) {
2537 "The communication peer of %s"
2539 " frame of length %02x\n",
2540 dev
->name
, p_this_ccw
->header
.length
);
2544 if (privptr
->mtc_skipping
) {
2546 * We're in the mode of skipping past a
2547 * multi-frame message
2548 * that we can't process for some reason or other.
2549 * The first frame without the More-To-Come flag is
2550 * the last frame of the skipped message.
2552 /* in case of More-To-Come not set in this frame */
2553 if (mtc_this_frm
==0) {
2554 privptr
->mtc_skipping
=0; /* Ok, the end */
2555 privptr
->mtc_logical_link
=-1;
2561 claw_process_control(dev
, p_this_ccw
);
2562 CLAW_DBF_TEXT(4, trace
, "UnpkCntl");
2566 if (p_env
->packing
== DO_PACKED
) {
2567 if (pack_off
> p_env
->read_size
)
2569 p_packd
= p_this_ccw
->p_buffer
+pack_off
;
2570 p_packh
= (struct clawph
*) p_packd
;
2571 if ((p_packh
->len
== 0) || /* done with this frame? */
2572 (p_packh
->flag
!= 0))
2574 bytes_to_mov
= p_packh
->len
;
2575 pack_off
+= bytes_to_mov
+sizeof(struct clawph
);
2578 bytes_to_mov
=p_this_ccw
->header
.length
;
2580 if (privptr
->mtc_logical_link
<0) {
2583 * if More-To-Come is set in this frame then we don't know
2584 * length of entire message, and hence have to allocate
2587 /* We are starting a new envelope */
2588 privptr
->mtc_offset
=0;
2589 privptr
->mtc_logical_link
=link_num
;
2592 if (bytes_to_mov
> (MAX_ENVELOPE_SIZE
- privptr
->mtc_offset
) ) {
2594 privptr
->stats
.rx_frame_errors
++;
2597 if (p_env
->packing
== DO_PACKED
) {
2598 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2599 p_packd
+sizeof(struct clawph
), bytes_to_mov
);
2602 memcpy( privptr
->p_mtc_envelope
+ privptr
->mtc_offset
,
2603 p_this_ccw
->p_buffer
, bytes_to_mov
);
2605 if (mtc_this_frm
==0) {
2606 len_of_data
=privptr
->mtc_offset
+bytes_to_mov
;
2607 skb
=dev_alloc_skb(len_of_data
);
2609 memcpy(skb_put(skb
,len_of_data
),
2610 privptr
->p_mtc_envelope
,
2613 skb_reset_mac_header(skb
);
2614 skb
->protocol
=htons(ETH_P_IP
);
2615 skb
->ip_summed
=CHECKSUM_UNNECESSARY
;
2616 privptr
->stats
.rx_packets
++;
2617 privptr
->stats
.rx_bytes
+=len_of_data
;
2621 dev_info(p_dev
, "Allocating a buffer for"
2622 " incoming data failed\n");
2623 privptr
->stats
.rx_dropped
++;
2625 privptr
->mtc_offset
=0;
2626 privptr
->mtc_logical_link
=-1;
2629 privptr
->mtc_offset
+=bytes_to_mov
;
2631 if (p_env
->packing
== DO_PACKED
)
2635 * Remove ThisCCWblock from active read queue, and add it
2636 * to queue of free blocks to be reused.
2639 p_this_ccw
->header
.length
=0xffff;
2640 p_this_ccw
->header
.opcode
=0xff;
2642 * add this one to the free queue for later reuse
2644 if (p_first_ccw
==NULL
) {
2645 p_first_ccw
= p_this_ccw
;
2648 p_last_ccw
->next
= p_this_ccw
;
2650 p_last_ccw
= p_this_ccw
;
2652 * chain to next block on active read queue
2654 p_this_ccw
= privptr
->p_read_active_first
;
2655 CLAW_DBF_TEXT_(4, trace
, "rxpkt %d", p
);
2656 } /* end of while */
2658 /* check validity */
2660 CLAW_DBF_TEXT_(4, trace
, "rxfrm %d", i
);
2661 add_claw_reads(dev
, p_first_ccw
, p_last_ccw
);
2662 claw_strt_read(dev
, LOCK_YES
);
2664 } /* end of unpack_read */
2666 /*-------------------------------------------------------------------*
2669 *--------------------------------------------------------------------*/
2671 claw_strt_read (struct net_device
*dev
, int lock
)
2675 unsigned long saveflags
= 0;
2676 struct claw_privbk
*privptr
= dev
->ml_priv
;
2677 struct ccwbk
*p_ccwbk
;
2679 struct clawh
*p_clawh
;
2680 p_ch
=&privptr
->channel
[READ
];
2682 CLAW_DBF_TEXT(4, trace
, "StRdNter");
2683 p_clawh
=(struct clawh
*)privptr
->p_claw_signal_blk
;
2684 p_clawh
->flag
=CLAW_IDLE
; /* 0x00 */
2686 if ((privptr
->p_write_active_first
!=NULL
&&
2687 privptr
->p_write_active_first
->header
.flag
!=CLAW_PENDING
) ||
2688 (privptr
->p_read_active_first
!=NULL
&&
2689 privptr
->p_read_active_first
->header
.flag
!=CLAW_PENDING
)) {
2690 p_clawh
->flag
=CLAW_BUSY
; /* 0xff */
2692 if (lock
==LOCK_YES
) {
2693 spin_lock_irqsave(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2695 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2696 CLAW_DBF_TEXT(4, trace
, "HotRead");
2697 p_ccwbk
=privptr
->p_read_active_first
;
2698 parm
= (unsigned long) p_ch
;
2699 rc
= ccw_device_start (p_ch
->cdev
, &p_ccwbk
->read
, parm
,
2702 ccw_check_return_code(p_ch
->cdev
, rc
);
2706 CLAW_DBF_TEXT(2, trace
, "ReadAct");
2709 if (lock
==LOCK_YES
) {
2710 spin_unlock_irqrestore(get_ccwdev_lock(p_ch
->cdev
), saveflags
);
2712 CLAW_DBF_TEXT(4, trace
, "StRdExit");
2714 } /* end of claw_strt_read */
2716 /*-------------------------------------------------------------------*
2717 * claw_strt_out_IO *
2719 *--------------------------------------------------------------------*/
2722 claw_strt_out_IO( struct net_device
*dev
)
2726 struct claw_privbk
*privptr
;
2728 struct ccwbk
*p_first_ccw
;
2733 privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2734 p_ch
=&privptr
->channel
[WRITE
];
2736 CLAW_DBF_TEXT(4, trace
, "strt_io");
2737 p_first_ccw
=privptr
->p_write_active_first
;
2739 if (p_ch
->claw_state
== CLAW_STOP
)
2741 if (p_first_ccw
== NULL
) {
2744 if (test_and_set_bit(0, (void *)&p_ch
->IO_active
) == 0) {
2745 parm
= (unsigned long) p_ch
;
2746 CLAW_DBF_TEXT(2, trace
, "StWrtIO");
2747 rc
= ccw_device_start(p_ch
->cdev
, &p_first_ccw
->write
, parm
,
2750 ccw_check_return_code(p_ch
->cdev
, rc
);
2753 dev
->trans_start
= jiffies
;
2755 } /* end of claw_strt_out_IO */
2757 /*-------------------------------------------------------------------*
2758 * Free write buffers *
2760 *--------------------------------------------------------------------*/
2763 claw_free_wrt_buf( struct net_device
*dev
)
2766 struct claw_privbk
*privptr
= (struct claw_privbk
*)dev
->ml_priv
;
2767 struct ccwbk
*p_first_ccw
;
2768 struct ccwbk
*p_last_ccw
;
2769 struct ccwbk
*p_this_ccw
;
2770 struct ccwbk
*p_next_ccw
;
2772 CLAW_DBF_TEXT(4, trace
, "freewrtb");
2773 /* scan the write queue to free any completed write packets */
2776 p_this_ccw
=privptr
->p_write_active_first
;
2777 while ( (p_this_ccw
!=NULL
) && (p_this_ccw
->header
.flag
!=CLAW_PENDING
))
2779 p_next_ccw
= p_this_ccw
->next
;
2780 if (((p_next_ccw
!=NULL
) &&
2781 (p_next_ccw
->header
.flag
!=CLAW_PENDING
)) ||
2782 ((p_this_ccw
== privptr
->p_write_active_last
) &&
2783 (p_this_ccw
->header
.flag
!=CLAW_PENDING
))) {
2784 /* The next CCW is OK or this is */
2785 /* the last CCW...free it @A1A */
2786 privptr
->p_write_active_first
=p_this_ccw
->next
;
2787 p_this_ccw
->header
.flag
=CLAW_PENDING
;
2788 p_this_ccw
->next
=privptr
->p_write_free_chain
;
2789 privptr
->p_write_free_chain
=p_this_ccw
;
2790 ++privptr
->write_free_count
;
2791 privptr
->stats
.tx_bytes
+= p_this_ccw
->write
.count
;
2792 p_this_ccw
=privptr
->p_write_active_first
;
2793 privptr
->stats
.tx_packets
++;
2799 if (privptr
->write_free_count
!=0) {
2800 claw_clearbit_busy(TB_NOBUFFER
,dev
);
2802 /* whole chain removed? */
2803 if (privptr
->p_write_active_first
==NULL
) {
2804 privptr
->p_write_active_last
=NULL
;
2806 CLAW_DBF_TEXT_(4, trace
, "FWC=%d", privptr
->write_free_count
);
2810 /*-------------------------------------------------------------------*
2811 * claw free netdevice *
2813 *--------------------------------------------------------------------*/
2815 claw_free_netdevice(struct net_device
* dev
, int free_dev
)
2817 struct claw_privbk
*privptr
;
2819 CLAW_DBF_TEXT(2, setup
, "free_dev");
2822 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2823 privptr
= dev
->ml_priv
;
2824 if (dev
->flags
& IFF_RUNNING
)
2827 privptr
->channel
[READ
].ndev
= NULL
; /* say it's free */
2829 dev
->ml_priv
= NULL
;
2835 CLAW_DBF_TEXT(2, setup
, "free_ok");
2839 * Claw init netdevice
2840 * Initialize everything of the net device except the name and the
2843 static const struct net_device_ops claw_netdev_ops
= {
2844 .ndo_open
= claw_open
,
2845 .ndo_stop
= claw_release
,
2846 .ndo_get_stats
= claw_stats
,
2847 .ndo_start_xmit
= claw_tx
,
2848 .ndo_change_mtu
= claw_change_mtu
,
2852 claw_init_netdevice(struct net_device
* dev
)
2854 CLAW_DBF_TEXT(2, setup
, "init_dev");
2855 CLAW_DBF_TEXT_(2, setup
, "%s", dev
->name
);
2856 dev
->mtu
= CLAW_DEFAULT_MTU_SIZE
;
2857 dev
->hard_header_len
= 0;
2859 dev
->type
= ARPHRD_SLIP
;
2860 dev
->tx_queue_len
= 1300;
2861 dev
->flags
= IFF_POINTOPOINT
| IFF_NOARP
;
2862 dev
->netdev_ops
= &claw_netdev_ops
;
2863 CLAW_DBF_TEXT(2, setup
, "initok");
2868 * Init a new channel in the privptr->channel[i].
2870 * @param cdev The ccw_device to be added.
2872 * @return 0 on success, !0 on error.
2875 add_channel(struct ccw_device
*cdev
,int i
,struct claw_privbk
*privptr
)
2878 struct ccw_dev_id dev_id
;
2880 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cdev
->dev
));
2881 privptr
->channel
[i
].flag
= i
+1; /* Read is 1 Write is 2 */
2882 p_ch
= &privptr
->channel
[i
];
2884 snprintf(p_ch
->id
, CLAW_ID_SIZE
, "cl-%s", dev_name(&cdev
->dev
));
2885 ccw_device_get_id(cdev
, &dev_id
);
2886 p_ch
->devno
= dev_id
.devno
;
2887 if ((p_ch
->irb
= kzalloc(sizeof (struct irb
),GFP_KERNEL
)) == NULL
) {
2896 * Setup an interface.
2898 * @param cgdev Device to be setup.
2900 * @returns 0 on success, !0 on failure.
2903 claw_new_device(struct ccwgroup_device
*cgdev
)
2905 struct claw_privbk
*privptr
;
2906 struct claw_env
*p_env
;
2907 struct net_device
*dev
;
2909 struct ccw_dev_id dev_id
;
2911 dev_info(&cgdev
->dev
, "add for %s\n",
2912 dev_name(&cgdev
->cdev
[READ
]->dev
));
2913 CLAW_DBF_TEXT(2, setup
, "new_dev");
2914 privptr
= cgdev
->dev
.driver_data
;
2915 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
2916 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
2919 p_env
= privptr
->p_env
;
2920 ccw_device_get_id(cgdev
->cdev
[READ
], &dev_id
);
2921 p_env
->devno
[READ
] = dev_id
.devno
;
2922 ccw_device_get_id(cgdev
->cdev
[WRITE
], &dev_id
);
2923 p_env
->devno
[WRITE
] = dev_id
.devno
;
2924 ret
= add_channel(cgdev
->cdev
[0],0,privptr
);
2926 ret
= add_channel(cgdev
->cdev
[1],1,privptr
);
2928 dev_warn(&cgdev
->dev
, "Creating a CLAW group device"
2929 " failed with error code %d\n", ret
);
2932 ret
= ccw_device_set_online(cgdev
->cdev
[READ
]);
2934 dev_warn(&cgdev
->dev
,
2935 "Setting the read subchannel online"
2936 " failed with error code %d\n", ret
);
2939 ret
= ccw_device_set_online(cgdev
->cdev
[WRITE
]);
2941 dev_warn(&cgdev
->dev
,
2942 "Setting the write subchannel online "
2943 "failed with error code %d\n", ret
);
2946 dev
= alloc_netdev(0,"claw%d",claw_init_netdevice
);
2948 dev_warn(&cgdev
->dev
,
2949 "Activating the CLAW device failed\n");
2952 dev
->ml_priv
= privptr
;
2953 cgdev
->dev
.driver_data
= privptr
;
2954 cgdev
->cdev
[READ
]->dev
.driver_data
= privptr
;
2955 cgdev
->cdev
[WRITE
]->dev
.driver_data
= privptr
;
2957 SET_NETDEV_DEV(dev
, &cgdev
->dev
);
2958 if (register_netdev(dev
) != 0) {
2959 claw_free_netdevice(dev
, 1);
2960 CLAW_DBF_TEXT(2, trace
, "regfail");
2963 dev
->flags
&=~IFF_RUNNING
;
2964 if (privptr
->buffs_alloc
== 0) {
2965 ret
=init_ccw_bk(dev
);
2967 unregister_netdev(dev
);
2968 claw_free_netdevice(dev
,1);
2969 CLAW_DBF_TEXT(2, trace
, "ccwmem");
2973 privptr
->channel
[READ
].ndev
= dev
;
2974 privptr
->channel
[WRITE
].ndev
= dev
;
2975 privptr
->p_env
->ndev
= dev
;
2977 dev_info(&cgdev
->dev
, "%s:readsize=%d writesize=%d "
2978 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2979 dev
->name
, p_env
->read_size
,
2980 p_env
->write_size
, p_env
->read_buffers
,
2981 p_env
->write_buffers
, p_env
->devno
[READ
],
2982 p_env
->devno
[WRITE
]);
2983 dev_info(&cgdev
->dev
, "%s:host_name:%.8s, adapter_name "
2984 ":%.8s api_type: %.8s\n",
2985 dev
->name
, p_env
->host_name
,
2986 p_env
->adapter_name
, p_env
->api_type
);
2989 ccw_device_set_offline(cgdev
->cdev
[1]);
2990 ccw_device_set_offline(cgdev
->cdev
[0]);
2995 claw_purge_skb_queue(struct sk_buff_head
*q
)
2997 struct sk_buff
*skb
;
2999 CLAW_DBF_TEXT(4, trace
, "purgque");
3000 while ((skb
= skb_dequeue(q
))) {
3001 atomic_dec(&skb
->users
);
3002 dev_kfree_skb_any(skb
);
3007 * Shutdown an interface.
3009 * @param cgdev Device to be shut down.
3011 * @returns 0 on success, !0 on failure.
3014 claw_shutdown_device(struct ccwgroup_device
*cgdev
)
3016 struct claw_privbk
*priv
;
3017 struct net_device
*ndev
;
3020 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3021 priv
= cgdev
->dev
.driver_data
;
3024 ndev
= priv
->channel
[READ
].ndev
;
3026 /* Close the device */
3027 dev_info(&cgdev
->dev
, "%s: shutting down \n",
3029 if (ndev
->flags
& IFF_RUNNING
)
3030 ret
= claw_release(ndev
);
3031 ndev
->flags
&=~IFF_RUNNING
;
3032 unregister_netdev(ndev
);
3033 ndev
->ml_priv
= NULL
; /* cgdev data, not ndev's to free */
3034 claw_free_netdevice(ndev
, 1);
3035 priv
->channel
[READ
].ndev
= NULL
;
3036 priv
->channel
[WRITE
].ndev
= NULL
;
3037 priv
->p_env
->ndev
= NULL
;
3039 ccw_device_set_offline(cgdev
->cdev
[1]);
3040 ccw_device_set_offline(cgdev
->cdev
[0]);
3045 claw_remove_device(struct ccwgroup_device
*cgdev
)
3047 struct claw_privbk
*priv
;
3050 CLAW_DBF_TEXT_(2, setup
, "%s", dev_name(&cgdev
->dev
));
3051 priv
= cgdev
->dev
.driver_data
;
3053 dev_info(&cgdev
->dev
, " will be removed.\n");
3054 if (cgdev
->state
== CCWGROUP_ONLINE
)
3055 claw_shutdown_device(cgdev
);
3056 claw_remove_files(&cgdev
->dev
);
3057 kfree(priv
->p_mtc_envelope
);
3058 priv
->p_mtc_envelope
=NULL
;
3061 kfree(priv
->channel
[0].irb
);
3062 priv
->channel
[0].irb
=NULL
;
3063 kfree(priv
->channel
[1].irb
);
3064 priv
->channel
[1].irb
=NULL
;
3066 cgdev
->dev
.driver_data
=NULL
;
3067 cgdev
->cdev
[READ
]->dev
.driver_data
= NULL
;
3068 cgdev
->cdev
[WRITE
]->dev
.driver_data
= NULL
;
3069 put_device(&cgdev
->dev
);
3079 claw_hname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3081 struct claw_privbk
*priv
;
3082 struct claw_env
* p_env
;
3084 priv
= dev
->driver_data
;
3087 p_env
= priv
->p_env
;
3088 return sprintf(buf
, "%s\n",p_env
->host_name
);
3092 claw_hname_write(struct device
*dev
, struct device_attribute
*attr
,
3093 const char *buf
, size_t count
)
3095 struct claw_privbk
*priv
;
3096 struct claw_env
* p_env
;
3098 priv
= dev
->driver_data
;
3101 p_env
= priv
->p_env
;
3102 if (count
> MAX_NAME_LEN
+1)
3104 memset(p_env
->host_name
, 0x20, MAX_NAME_LEN
);
3105 strncpy(p_env
->host_name
,buf
, count
);
3106 p_env
->host_name
[count
-1] = 0x20; /* clear extra 0x0a */
3107 p_env
->host_name
[MAX_NAME_LEN
] = 0x00;
3108 CLAW_DBF_TEXT(2, setup
, "HstnSet");
3109 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->host_name
);
3114 static DEVICE_ATTR(host_name
, 0644, claw_hname_show
, claw_hname_write
);
3117 claw_adname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3119 struct claw_privbk
*priv
;
3120 struct claw_env
* p_env
;
3122 priv
= dev
->driver_data
;
3125 p_env
= priv
->p_env
;
3126 return sprintf(buf
, "%s\n", p_env
->adapter_name
);
3130 claw_adname_write(struct device
*dev
, struct device_attribute
*attr
,
3131 const char *buf
, size_t count
)
3133 struct claw_privbk
*priv
;
3134 struct claw_env
* p_env
;
3136 priv
= dev
->driver_data
;
3139 p_env
= priv
->p_env
;
3140 if (count
> MAX_NAME_LEN
+1)
3142 memset(p_env
->adapter_name
, 0x20, MAX_NAME_LEN
);
3143 strncpy(p_env
->adapter_name
,buf
, count
);
3144 p_env
->adapter_name
[count
-1] = 0x20; /* clear extra 0x0a */
3145 p_env
->adapter_name
[MAX_NAME_LEN
] = 0x00;
3146 CLAW_DBF_TEXT(2, setup
, "AdnSet");
3147 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->adapter_name
);
3152 static DEVICE_ATTR(adapter_name
, 0644, claw_adname_show
, claw_adname_write
);
3155 claw_apname_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3157 struct claw_privbk
*priv
;
3158 struct claw_env
* p_env
;
3160 priv
= dev
->driver_data
;
3163 p_env
= priv
->p_env
;
3164 return sprintf(buf
, "%s\n",
3169 claw_apname_write(struct device
*dev
, struct device_attribute
*attr
,
3170 const char *buf
, size_t count
)
3172 struct claw_privbk
*priv
;
3173 struct claw_env
* p_env
;
3175 priv
= dev
->driver_data
;
3178 p_env
= priv
->p_env
;
3179 if (count
> MAX_NAME_LEN
+1)
3181 memset(p_env
->api_type
, 0x20, MAX_NAME_LEN
);
3182 strncpy(p_env
->api_type
,buf
, count
);
3183 p_env
->api_type
[count
-1] = 0x20; /* we get a loose 0x0a */
3184 p_env
->api_type
[MAX_NAME_LEN
] = 0x00;
3185 if(strncmp(p_env
->api_type
,WS_APPL_NAME_PACKED
,6) == 0) {
3186 p_env
->read_size
=DEF_PACK_BUFSIZE
;
3187 p_env
->write_size
=DEF_PACK_BUFSIZE
;
3188 p_env
->packing
=PACKING_ASK
;
3189 CLAW_DBF_TEXT(2, setup
, "PACKING");
3193 p_env
->read_size
=CLAW_FRAME_SIZE
;
3194 p_env
->write_size
=CLAW_FRAME_SIZE
;
3195 CLAW_DBF_TEXT(2, setup
, "ApiSet");
3197 CLAW_DBF_TEXT_(2, setup
, "%s", p_env
->api_type
);
3201 static DEVICE_ATTR(api_type
, 0644, claw_apname_show
, claw_apname_write
);
3204 claw_wbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3206 struct claw_privbk
*priv
;
3207 struct claw_env
* p_env
;
3209 priv
= dev
->driver_data
;
3212 p_env
= priv
->p_env
;
3213 return sprintf(buf
, "%d\n", p_env
->write_buffers
);
3217 claw_wbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3218 const char *buf
, size_t count
)
3220 struct claw_privbk
*priv
;
3221 struct claw_env
* p_env
;
3224 priv
= dev
->driver_data
;
3227 p_env
= priv
->p_env
;
3228 sscanf(buf
, "%i", &nnn
);
3229 if (p_env
->packing
) {
3235 if ((nnn
> max
) || (nnn
< 2))
3237 p_env
->write_buffers
= nnn
;
3238 CLAW_DBF_TEXT(2, setup
, "Wbufset");
3239 CLAW_DBF_TEXT_(2, setup
, "WB=%d", p_env
->write_buffers
);
3243 static DEVICE_ATTR(write_buffer
, 0644, claw_wbuff_show
, claw_wbuff_write
);
3246 claw_rbuff_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3248 struct claw_privbk
*priv
;
3249 struct claw_env
* p_env
;
3251 priv
= dev
->driver_data
;
3254 p_env
= priv
->p_env
;
3255 return sprintf(buf
, "%d\n", p_env
->read_buffers
);
3259 claw_rbuff_write(struct device
*dev
, struct device_attribute
*attr
,
3260 const char *buf
, size_t count
)
3262 struct claw_privbk
*priv
;
3263 struct claw_env
*p_env
;
3266 priv
= dev
->driver_data
;
3269 p_env
= priv
->p_env
;
3270 sscanf(buf
, "%i", &nnn
);
3271 if (p_env
->packing
) {
3277 if ((nnn
> max
) || (nnn
< 2))
3279 p_env
->read_buffers
= nnn
;
3280 CLAW_DBF_TEXT(2, setup
, "Rbufset");
3281 CLAW_DBF_TEXT_(2, setup
, "RB=%d", p_env
->read_buffers
);
3285 static DEVICE_ATTR(read_buffer
, 0644, claw_rbuff_show
, claw_rbuff_write
);
3287 static struct attribute
*claw_attr
[] = {
3288 &dev_attr_read_buffer
.attr
,
3289 &dev_attr_write_buffer
.attr
,
3290 &dev_attr_adapter_name
.attr
,
3291 &dev_attr_api_type
.attr
,
3292 &dev_attr_host_name
.attr
,
3296 static struct attribute_group claw_attr_group
= {
3301 claw_add_files(struct device
*dev
)
3303 CLAW_DBF_TEXT(2, setup
, "add_file");
3304 return sysfs_create_group(&dev
->kobj
, &claw_attr_group
);
3308 claw_remove_files(struct device
*dev
)
3310 CLAW_DBF_TEXT(2, setup
, "rem_file");
3311 sysfs_remove_group(&dev
->kobj
, &claw_attr_group
);
3314 /*--------------------------------------------------------------------*
3315 * claw_init and cleanup *
3316 *---------------------------------------------------------------------*/
3321 unregister_cu3088_discipline(&claw_group_driver
);
3322 claw_unregister_debug_facility();
3323 pr_info("Driver unloaded\n");
3328 * Initialize module.
3329 * This is called just after the module is loaded.
3331 * @return 0 on success, !0 on error.
3338 pr_info("Loading %s\n", version
);
3339 ret
= claw_register_debug_facility();
3341 pr_err("Registering with the S/390 debug feature"
3342 " failed with error code %d\n", ret
);
3345 CLAW_DBF_TEXT(2, setup
, "init_mod");
3346 ret
= register_cu3088_discipline(&claw_group_driver
);
3348 CLAW_DBF_TEXT(2, setup
, "init_bad");
3349 claw_unregister_debug_facility();
3350 pr_err("Registering with the cu3088 device driver failed "
3351 "with error code %d\n", ret
);
3356 module_init(claw_init
);
3357 module_exit(claw_cleanup
);
3359 MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3360 MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3361 "Copyright 2000,2008 IBM Corporation\n");
3362 MODULE_LICENSE("GPL");