blob: 7b6f46ddf3c304146b5b7e0afd34233f34b01b42 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/net/claw.c
3 * ESCON CLAW network driver
4 *
Frank Pavlic8e84c802005-09-06 15:03:09 +02005 * Linux for zSeries version
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright (C) 2002,2005 IBM Corporation
7 * Author(s) Original code written by:
8 * Kazuo Iimura (iimura@jp.ibm.com)
9 * Rewritten by
10 * Andy Richter (richtera@us.ibm.com)
11 * Marc Price (mwprice@us.ibm.com)
12 *
13 * sysfs parms:
14 * group x.x.rrrr,x.x.wwww
15 * read_buffer nnnnnnn
16 * write_buffer nnnnnn
17 * host_name aaaaaaaa
18 * adapter_name aaaaaaaa
19 * api_type aaaaaaaa
20 *
21 * eg.
22 * group 0.0.0200 0.0.0201
23 * read_buffer 25
24 * write_buffer 20
25 * host_name LINUX390
26 * adapter_name RS6K
27 * api_type TCPIP
28 *
29 * where
30 *
31 * The device id is decided by the order entries
32 * are added to the group the first is claw0 the second claw1
33 * up to CLAW_MAX_DEV
34 *
35 * rrrr - the first of 2 consecutive device addresses used for the
36 * CLAW protocol.
37 * The specified address is always used as the input (Read)
38 * channel and the next address is used as the output channel.
39 *
40 * wwww - the second of 2 consecutive device addresses used for
41 * the CLAW protocol.
42 * The specified address is always used as the output
43 * channel and the previous address is used as the input channel.
44 *
45 * read_buffer - specifies number of input buffers to allocate.
46 * write_buffer - specifies number of output buffers to allocate.
47 * host_name - host name
48 * adaptor_name - adaptor name
49 * api_type - API type TCPIP or API will be sent and expected
50 * as ws_name
51 *
52 * Note the following requirements:
53 * 1) host_name must match the configured adapter_name on the remote side
54 * 2) adaptor_name must match the configured host name on the remote side
55 *
56 * Change History
57 * 1.00 Initial release shipped
58 * 1.10 Changes for Buffer allocation
59 * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower
60 * 1.25 Added Packing support
Andy Richterb805da72008-07-18 15:24:56 +020061 * 1.5
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 */
Andy Richter4811fcb2009-01-20 06:14:33 +000063
64#define KMSG_COMPONENT "claw"
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066#include <asm/ccwdev.h>
67#include <asm/ccwgroup.h>
68#include <asm/debug.h>
69#include <asm/idals.h>
70#include <asm/io.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070071#include <linux/bitops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include <linux/ctype.h>
73#include <linux/delay.h>
74#include <linux/errno.h>
75#include <linux/if_arp.h>
76#include <linux/init.h>
77#include <linux/interrupt.h>
78#include <linux/ip.h>
79#include <linux/kernel.h>
80#include <linux/module.h>
81#include <linux/netdevice.h>
82#include <linux/etherdevice.h>
83#include <linux/proc_fs.h>
84#include <linux/sched.h>
85#include <linux/signal.h>
86#include <linux/skbuff.h>
87#include <linux/slab.h>
88#include <linux/string.h>
89#include <linux/tcp.h>
90#include <linux/timer.h>
91#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#include "cu3088.h"
94#include "claw.h"
95
Andy Richterb805da72008-07-18 15:24:56 +020096/*
97 CLAW uses the s390dbf file system see claw_trace and claw_setup
Linus Torvalds1da177e2005-04-16 15:20:36 -070098*/
99
Andy Richter4811fcb2009-01-20 06:14:33 +0000100static char version[] __initdata = "CLAW driver";
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100101static char debug_buffer[255];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/**
103 * Debug Facility Stuff
104 */
105static debug_info_t *claw_dbf_setup;
106static debug_info_t *claw_dbf_trace;
107
108/**
109 * CLAW Debug Facility functions
110 */
111static void
112claw_unregister_debug_facility(void)
113{
114 if (claw_dbf_setup)
115 debug_unregister(claw_dbf_setup);
116 if (claw_dbf_trace)
117 debug_unregister(claw_dbf_trace);
118}
119
120static int
121claw_register_debug_facility(void)
122{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700123 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
124 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 claw_unregister_debug_facility();
127 return -ENOMEM;
128 }
129 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
130 debug_set_level(claw_dbf_setup, 2);
131 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
132 debug_set_level(claw_dbf_trace, 2);
133 return 0;
134}
135
136static inline void
137claw_set_busy(struct net_device *dev)
138{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200139 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 eieio();
141}
142
143static inline void
144claw_clear_busy(struct net_device *dev)
145{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200146 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 netif_wake_queue(dev);
148 eieio();
149}
150
151static inline int
152claw_check_busy(struct net_device *dev)
153{
154 eieio();
Peter Tiedemann6951df32008-08-21 17:10:23 +0200155 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
158static inline void
159claw_setbit_busy(int nr,struct net_device *dev)
160{
161 netif_stop_queue(dev);
Peter Tiedemann6951df32008-08-21 17:10:23 +0200162 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline void
166claw_clearbit_busy(int nr,struct net_device *dev)
167{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200168 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 netif_wake_queue(dev);
170}
171
172static inline int
173claw_test_and_setbit_busy(int nr,struct net_device *dev)
174{
175 netif_stop_queue(dev);
176 return test_and_set_bit(nr,
Peter Tiedemann6951df32008-08-21 17:10:23 +0200177 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
180
181/* Functions for the DEV methods */
182
183static int claw_probe(struct ccwgroup_device *cgdev);
184static void claw_remove_device(struct ccwgroup_device *cgdev);
185static void claw_purge_skb_queue(struct sk_buff_head *q);
186static int claw_new_device(struct ccwgroup_device *cgdev);
187static int claw_shutdown_device(struct ccwgroup_device *cgdev);
188static int claw_tx(struct sk_buff *skb, struct net_device *dev);
189static int claw_change_mtu( struct net_device *dev, int new_mtu);
190static int claw_open(struct net_device *dev);
191static void claw_irq_handler(struct ccw_device *cdev,
192 unsigned long intparm, struct irb *irb);
193static void claw_irq_tasklet ( unsigned long data );
194static int claw_release(struct net_device *dev);
195static void claw_write_retry ( struct chbk * p_ch );
196static void claw_write_next ( struct chbk * p_ch );
197static void claw_timer ( struct chbk * p_ch );
198
199/* Functions */
200static int add_claw_reads(struct net_device *dev,
201 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100202static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
203static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static int find_link(struct net_device *dev, char *host_name, char *ws_name );
205static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
206static int init_ccw_bk(struct net_device *dev);
207static void probe_error( struct ccwgroup_device *cgdev);
208static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100209static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/* sysfs Functions */
Andy Richter4811fcb2009-01-20 06:14:33 +0000212static ssize_t claw_hname_show(struct device *dev,
213 struct device_attribute *attr, char *buf);
214static ssize_t claw_hname_write(struct device *dev,
215 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000217static ssize_t claw_adname_show(struct device *dev,
218 struct device_attribute *attr, char *buf);
219static ssize_t claw_adname_write(struct device *dev,
220 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000222static ssize_t claw_apname_show(struct device *dev,
223 struct device_attribute *attr, char *buf);
224static ssize_t claw_apname_write(struct device *dev,
225 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000227static ssize_t claw_wbuff_show(struct device *dev,
228 struct device_attribute *attr, char *buf);
229static ssize_t claw_wbuff_write(struct device *dev,
230 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000232static ssize_t claw_rbuff_show(struct device *dev,
233 struct device_attribute *attr, char *buf);
234static ssize_t claw_rbuff_write(struct device *dev,
235 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 const char *buf, size_t count);
237static int claw_add_files(struct device *dev);
238static void claw_remove_files(struct device *dev);
239
240/* Functions for System Validate */
241static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
242static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
243 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
244static int claw_snd_conn_req(struct net_device *dev, __u8 link);
245static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
246static int claw_snd_sys_validate_rsp(struct net_device *dev,
247 struct clawctl * p_ctl, __u32 return_code);
248static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200249static void claw_strt_read(struct net_device *dev, int lock);
250static void claw_strt_out_IO(struct net_device *dev);
251static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200254static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256/* ccwgroup table */
257
258static struct ccwgroup_driver claw_group_driver = {
259 .owner = THIS_MODULE,
260 .name = "claw",
261 .max_slaves = 2,
262 .driver_id = 0xC3D3C1E6,
263 .probe = claw_probe,
264 .remove = claw_remove_device,
265 .set_online = claw_new_device,
266 .set_offline = claw_shutdown_device,
267};
268
269/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270* Key functions
271*/
272
273/*----------------------------------------------------------------*
274 * claw_probe *
275 * this function is called for each CLAW device. *
276 *----------------------------------------------------------------*/
277static int
278claw_probe(struct ccwgroup_device *cgdev)
279{
280 int rc;
281 struct claw_privbk *privptr=NULL;
282
Andy Richterb805da72008-07-18 15:24:56 +0200283 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 if (!get_device(&cgdev->dev))
285 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800286 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +0200287 cgdev->dev.driver_data = privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 if (privptr == NULL) {
289 probe_error(cgdev);
290 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200291 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 return -ENOMEM;
293 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700294 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
295 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
297 probe_error(cgdev);
298 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200299 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return -ENOMEM;
301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 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);
311 if (rc) {
312 probe_error(cgdev);
313 put_device(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +0000314 dev_err(&cgdev->dev, "Creating the /proc files for a new"
315 " CLAW device failed\n");
Andy Richterb805da72008-07-18 15:24:56 +0200316 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return rc;
318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 privptr->p_env->p_priv = privptr;
320 cgdev->cdev[0]->handler = claw_irq_handler;
321 cgdev->cdev[1]->handler = claw_irq_handler;
Andy Richterb805da72008-07-18 15:24:56 +0200322 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 return 0;
325} /* end of claw_probe */
326
327/*-------------------------------------------------------------------*
328 * claw_tx *
329 *-------------------------------------------------------------------*/
330
331static int
332claw_tx(struct sk_buff *skb, struct net_device *dev)
333{
334 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200335 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 unsigned long saveflags;
337 struct chbk *p_ch;
338
Andy Richterb805da72008-07-18 15:24:56 +0200339 CLAW_DBF_TEXT(4, trace, "claw_tx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 p_ch=&privptr->channel[WRITE];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 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);
Andy Richterb805da72008-07-18 15:24:56 +0200344 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000345 if (rc)
346 rc = NETDEV_TX_BUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return rc;
348} /* end of claw_tx */
349
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 *------------------------------------------------------------------*/
354
355static struct sk_buff *
356claw_pack_skb(struct claw_privbk *privptr)
357{
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;
362
363 new_skb = NULL; /* assume no dice */
364 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200365 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700366 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* some data */
368 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200370 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 else
372 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200373 if (p_env->packing != DO_PACKED)
374 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 /* 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);
380 return NULL;
381 }
382 /* we have packed packet and a place to put it */
383 pk_ind = 1;
384 so_far = 0;
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;
392 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200393 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 held_skb = skb_dequeue(&p_ch->collect_queue);
395 if (held_skb)
396 atomic_dec(&held_skb->users);
397 } else {
398 pk_ind = 0;
399 atomic_inc(&held_skb->users);
400 skb_queue_head(&p_ch->collect_queue,held_skb);
401 }
402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
Andy Richterb805da72008-07-18 15:24:56 +0200404 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return new_skb;
406}
407
408/*-------------------------------------------------------------------*
409 * claw_change_mtu *
410 * *
411 *-------------------------------------------------------------------*/
412
413static int
414claw_change_mtu(struct net_device *dev, int new_mtu)
415{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200416 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200418 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 buff_size = privptr->p_env->write_size;
420 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return -EINVAL;
422 }
423 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 return 0;
425} /* end of claw_change_mtu */
426
427
428/*-------------------------------------------------------------------*
429 * claw_open *
430 * *
431 *-------------------------------------------------------------------*/
432static int
433claw_open(struct net_device *dev)
434{
435
436 int rc;
437 int i;
438 unsigned long saveflags=0;
439 unsigned long parm;
440 struct claw_privbk *privptr;
441 DECLARE_WAITQUEUE(wait, current);
442 struct timer_list timer;
443 struct ccwbk *p_buf;
444
Andy Richterb805da72008-07-18 15:24:56 +0200445 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200446 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 /* allocate and initialize CCW blocks */
448 if (privptr->buffs_alloc == 0) {
449 rc=init_ccw_bk(dev);
450 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200451 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return -ENOMEM;
453 }
454 }
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;
461 } else {
462 privptr->p_env->packing=0;
463 privptr->p_env->read_size=CLAW_FRAME_SIZE;
464 privptr->p_env->write_size=CLAW_FRAME_SIZE;
465 }
466 claw_set_busy(dev);
467 tasklet_init(&privptr->channel[READ].tasklet, claw_irq_tasklet,
468 (unsigned long) &privptr->channel[READ]);
469 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200470 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 init_waitqueue_head(&privptr->channel[i].wait);
472 /* skb_queue_head_init(&p_ch->io_queue); */
473 if (i == WRITE)
474 skb_queue_head_init(
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;
479 init_timer(&timer);
480 timer.function = (void *)claw_timer;
481 timer.data = (unsigned long)(&privptr->channel[i]);
482 timer.expires = jiffies + 15*HZ;
483 add_timer(&timer);
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;
488 rc = 0;
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);
495 schedule();
496 set_current_state(TASK_RUNNING);
497 remove_wait_queue(&privptr->channel[i].wait, &wait);
498 if(rc != 0)
499 ccw_check_return_code(privptr->channel[i].cdev, rc);
500 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
501 del_timer(&timer);
502 }
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)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000508 dev_info(&privptr->channel[READ].cdev->dev,
509 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200510 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 for ( i = 0; i < 2; i++) {
513 spin_lock_irqsave(
514 get_ccwdev_lock(privptr->channel[i].cdev),
515 saveflags);
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,
520 parm);
521 spin_unlock_irqrestore(
522 get_ccwdev_lock(privptr->channel[i].cdev),
523 saveflags);
524 if (rc != 0) {
525 ccw_check_return_code(
526 privptr->channel[i].cdev, rc);
527 }
528 }
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));
535 }
536 else {
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 ));
542 p_buf=p_buf->next;
543 }
544 }
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));
549 }
550 else {
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 ));
556 p_buf=p_buf->next;
557 }
558 }
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);
Andy Richterb805da72008-07-18 15:24:56 +0200566 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return -EIO;
568 }
569
570 /* Send SystemValidate command */
571
572 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200573 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return 0;
575} /* end of claw_open */
576
577/*-------------------------------------------------------------------*
578* *
579* claw_irq_handler *
580* *
581*--------------------------------------------------------------------*/
582static void
583claw_irq_handler(struct ccw_device *cdev,
584 unsigned long intparm, struct irb *irb)
585{
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;
591
Andy Richterb805da72008-07-18 15:24:56 +0200592 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 /* Bypass all 'unsolicited interrupts' */
594 if (!cdev->dev.driver_data) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000595 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);
Andy Richterb805da72008-07-18 15:24:56 +0200598 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return;
600 }
601 privptr = (struct claw_privbk *)cdev->dev.driver_data;
602
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];
608 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000609 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200610 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 return;
612 }
Andy Richterb805da72008-07-18 15:24:56 +0200613 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 dev = (struct net_device *) (p_ch->ndev);
616 p_env=privptr->p_env;
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 /* Copy interruption response block. */
619 memcpy(p_ch->irb, irb, sizeof(struct irb));
620
Andy Richterb805da72008-07-18 15:24:56 +0200621 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200622 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000623 dev_info(&cdev->dev,
624 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
626 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200627 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
628 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200629 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 /* return; */
631 }
632
633 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200634 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200638 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200641 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))))
646 return;
647 wake_up(&p_ch->wait); /* wake up claw_release */
648 CLAW_DBF_TEXT(4, trace, "stop");
649 return;
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");
656 return;
657 }
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;
Andy Richter4811fcb2009-01-20 06:14:33 +0000663 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200664 claw_strt_read(dev, LOCK_NO);
665 claw_send_control(dev,
666 SYSTEM_VALIDATE_REQUEST,
667 0, 0, 0,
668 p_env->host_name,
669 p_env->adapter_name);
670 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000671 dev_warn(&cdev->dev, "The CLAW device received"
672 " an unexpected IRQ, "
673 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200674 irb->scsw.cmd.cstat,
675 irb->scsw.cmd.dstat);
676 return;
677 }
678 CLAW_DBF_TEXT(4, trace, "haltio");
679 return;
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++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000688 dev_info(&cdev->dev,
689 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200690 "side recovers \n",
691 dev->name);
692 }
693 CLAW_DBF_TEXT(4, trace, "notrdy");
694 return;
695 }
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 else
Andy Richterb805da72008-07-18 15:24:56 +0200702 CLAW_DBF_TEXT(4, trace, "PCINoBH");
703 CLAW_DBF_TEXT(4, trace, "PCI_read");
704 return;
705 }
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");
711 return;
712 }
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);
718 else
719 CLAW_DBF_TEXT(4, trace, "RdBHAct");
720 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
721 return;
722 case CLAW_START_WRITE:
723 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000724 dev_info(&cdev->dev,
725 "%s: Unit Check Occured in "
Andy Richterb805da72008-07-18 15:24:56 +0200726 "write channel\n", dev->name);
727 clear_bit(0, (void *)&p_ch->IO_active);
728 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000729 dev_info(&cdev->dev,
730 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200731 "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);
Andy Richter4811fcb2009-01-20 06:14:33 +0000738 dev_info(&cdev->dev,
739 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200740 "restarting\n", dev->name);
741 }
742 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
743 return;
744 }
745 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
746 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000747 dev_info(&cdev->dev,
748 "%s: Unit Exception "
749 "occurred in write channel\n",
750 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200751 }
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");
757 return;
758 }
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);
764 }
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");
770 return;
771 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000772 dev_warn(&cdev->dev,
773 "The CLAW device for %s received an unexpected IRQ\n",
774 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200775 CLAW_DBF_TEXT(2, trace, "badIRQ");
776 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 }
778
779} /* end of claw_irq_handler */
780
781
782/*-------------------------------------------------------------------*
783* claw_irq_tasklet *
784* *
785*--------------------------------------------------------------------*/
786static void
787claw_irq_tasklet ( unsigned long data )
788{
789 struct chbk * p_ch;
790 struct net_device *dev;
791 struct claw_privbk * privptr;
792
793 p_ch = (struct chbk *) data;
794 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200795 CLAW_DBF_TEXT(4, trace, "IRQtask");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200796 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 unpack_read(dev);
798 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200799 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return;
801} /* end of claw_irq_bh */
802
803/*-------------------------------------------------------------------*
804* claw_release *
805* *
806*--------------------------------------------------------------------*/
807static int
808claw_release(struct net_device *dev)
809{
810 int rc;
811 int i;
812 unsigned long saveflags;
813 unsigned long parm;
814 struct claw_privbk *privptr;
815 DECLARE_WAITQUEUE(wait, current);
816 struct ccwbk* p_this_ccw;
817 struct ccwbk* p_buf;
818
819 if (!dev)
820 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200821 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (!privptr)
823 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200824 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 privptr->release_pend=1;
826 claw_setbit_busy(TB_STOP,dev);
827 for ( i = 1; i >=0 ; i--) {
828 spin_lock_irqsave(
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];
834 if (i == WRITE)
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);
844 schedule();
845 set_current_state(TASK_RUNNING);
846 remove_wait_queue(&privptr->channel[i].wait, &wait);
847 if (rc != 0) {
848 ccw_check_return_code(privptr->channel[i].cdev, rc);
849 }
850 }
851 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200852 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 privptr->pk_skb = NULL;
854 }
855 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200856 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 return 0;
858 }
Andy Richterb805da72008-07-18 15:24:56 +0200859 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 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));
863 }
Andy Richterb805da72008-07-18 15:24:56 +0200864 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 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));
869 }
870 }
871 else {
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 ));
877 p_buf=p_buf->next;
878 }
879 }
Andy Richterb805da72008-07-18 15:24:56 +0200880 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 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));
884 }
885 else {
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 ));
891 p_buf=p_buf->next;
892 }
893 }
Andy Richterb805da72008-07-18 15:24:56 +0200894 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 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;
908 }
909
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;
917 }
918 privptr->p_write_active_last=NULL;
919 privptr->mtc_logical_link = -1;
920 privptr->mtc_skipping = 1;
921 privptr->mtc_offset=0;
922
923 if (((privptr->channel[READ].last_dstat |
924 privptr->channel[WRITE].last_dstat) &
925 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000926 dev_warn(&privptr->channel[READ].cdev->dev,
927 "Deactivating %s completed with incorrect"
928 " subchannel status "
929 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 dev->name,
931 privptr->channel[READ].last_dstat,
932 privptr->channel[WRITE].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200933 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 }
Andy Richterb805da72008-07-18 15:24:56 +0200935 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 return 0;
937} /* end of claw_release */
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939/*-------------------------------------------------------------------*
940* claw_write_retry *
941* *
942*--------------------------------------------------------------------*/
943
944static void
945claw_write_retry ( struct chbk *p_ch )
946{
947
948 struct net_device *dev=p_ch->ndev;
949
Andy Richterb805da72008-07-18 15:24:56 +0200950 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 return;
953 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +0200955 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 return;
957} /* end of claw_write_retry */
958
959
960/*-------------------------------------------------------------------*
961* claw_write_next *
962* *
963*--------------------------------------------------------------------*/
964
965static void
966claw_write_next ( struct chbk * p_ch )
967{
968
969 struct net_device *dev;
970 struct claw_privbk *privptr=NULL;
971 struct sk_buff *pk_skb;
972 int rc;
973
Andy Richterb805da72008-07-18 15:24:56 +0200974 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if (p_ch->claw_state == CLAW_STOP)
976 return;
977 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200978 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 claw_free_wrt_buf( dev );
980 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -0700981 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 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);
987 } else
988 pk_skb = NULL;
989 }
990 }
991 if (privptr->p_write_active_first!=NULL) {
992 claw_strt_out_IO(dev);
993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 return;
995} /* end of claw_write_next */
996
997/*-------------------------------------------------------------------*
998* *
999* claw_timer *
1000*--------------------------------------------------------------------*/
1001
1002static void
1003claw_timer ( struct chbk * p_ch )
1004{
Andy Richterb805da72008-07-18 15:24:56 +02001005 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 p_ch->flag |= CLAW_TIMER;
1007 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 return;
1009} /* end of claw_timer */
1010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011/*
1012*
1013* functions
1014*/
1015
1016
1017/*-------------------------------------------------------------------*
1018* *
1019* pages_to_order_of_mag *
1020* *
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*--------------------------------------------------------------------*/
1025
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001026static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027pages_to_order_of_mag(int num_of_pages)
1028{
1029 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001030 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001031
1032 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 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)
1039 break;
1040 order_of_mag +=1;
1041 }
1042 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001043 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return order_of_mag;
1045}
1046
1047/*-------------------------------------------------------------------*
1048* *
1049* add_claw_reads *
1050* *
1051*--------------------------------------------------------------------*/
1052static int
1053add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1054 struct ccwbk* p_last)
1055{
1056 struct claw_privbk *privptr;
1057 struct ccw1 temp_ccw;
1058 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001059 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001060 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 p_end = privptr->p_end_ccw;
1062
1063 /* first CCW and last CCW contains a new set of read channel programs
1064 * to apend the running channel programs
1065 */
1066 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001067 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 return 0;
1069 }
1070
1071 /* set up ending CCW sequence for this segment */
1072 if (p_end->read1) {
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;
1081 }
1082 else {
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;
1091 }
1092
1093 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001094 privptr->p_read_active_first = p_first; /* set new first */
1095 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
1097 else {
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 /* set up TIC ccw */
1100 temp_ccw.cda= (__u32)__pa(&p_first->read);
1101 temp_ccw.count=0;
1102 temp_ccw.flags=0;
1103 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1104
1105
1106 if (p_end->read1) {
1107
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);
1120 }
1121 else {
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);
1130 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001131 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 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) */
Andy Richterb805da72008-07-18 15:24:56 +02001135 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 return 0;
1137} /* end of add_claw_reads */
1138
1139/*-------------------------------------------------------------------*
1140 * ccw_check_return_code *
1141 * *
1142 *-------------------------------------------------------------------*/
1143
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001144static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145ccw_check_return_code(struct ccw_device *cdev, int return_code)
1146{
Andy Richterb805da72008-07-18 15:24:56 +02001147 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 if (return_code != 0) {
1149 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001150 case -EBUSY: /* BUSY is a transient state no action needed */
1151 break;
1152 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001153 dev_err(&cdev->dev, "The remote channel adapter is not"
1154 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001155 break;
1156 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001157 dev_err(&cdev->dev,
1158 "The status of the remote channel adapter"
1159 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001160 break;
1161 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001162 dev_err(&cdev->dev, "The common device layer"
1163 " returned error code %d\n",
1164 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001165 }
1166 }
1167 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168} /* end of ccw_check_return_code */
1169
1170/*-------------------------------------------------------------------*
1171* ccw_check_unit_check *
1172*--------------------------------------------------------------------*/
1173
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001174static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1176{
Andy Richterb805da72008-07-18 15:24:56 +02001177 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001178 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Andy Richterb805da72008-07-18 15:24:56 +02001180 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001181 dev_warn(dev, "The communication peer of %s disconnected\n",
1182 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001184 if (sense & 0x40) {
1185 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001186 dev_warn(dev, "The remote channel adapter for"
1187 " %s has been reset\n",
1188 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001189 }
1190 } else if (sense & 0x20) {
1191 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001192 dev_warn(dev, "A data streaming timeout occurred"
1193 " for %s\n",
1194 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001195 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001196 dev_warn(dev, "The remote channel adapter for %s"
1197 " is faulty\n",
1198 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001199 } else {
1200 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001201 " for %s\n",
1202 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001203 }
1204 } else if (sense & 0x10) {
1205 dev_warn(dev, "A read data parity error occurred"
1206 " for %s\n",
1207 ndev->name);
1208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210} /* end of ccw_check_unit_check */
1211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212/*-------------------------------------------------------------------*
1213* find_link *
1214*--------------------------------------------------------------------*/
1215static int
1216find_link(struct net_device *dev, char *host_name, char *ws_name )
1217{
1218 struct claw_privbk *privptr;
1219 struct claw_env *p_env;
1220 int rc=0;
1221
Andy Richterb805da72008-07-18 15:24:56 +02001222 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001223 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 p_env=privptr->p_env;
1225 switch (p_env->packing)
1226 {
1227 case PACKING_ASK:
1228 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1229 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1230 rc = EINVAL;
1231 break;
1232 case DO_PACKED:
1233 case PACK_SEND:
1234 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1235 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1236 rc = EINVAL;
1237 break;
1238 default:
1239 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1240 (memcmp(p_env->api_type , ws_name, 8)!=0))
1241 rc = EINVAL;
1242 break;
1243 }
1244
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001245 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246} /* end of find_link */
1247
1248/*-------------------------------------------------------------------*
1249 * claw_hw_tx *
1250 * *
1251 * *
1252 *-------------------------------------------------------------------*/
1253
1254static int
1255claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1256{
1257 int rc=0;
1258 struct claw_privbk *privptr;
1259 struct ccwbk *p_this_ccw;
1260 struct ccwbk *p_first_ccw;
1261 struct ccwbk *p_last_ccw;
1262 __u32 numBuffers;
1263 signed long len_of_data;
1264 unsigned long bytesInThisBuffer;
1265 unsigned char *pDataAddress;
1266 struct endccw *pEnd;
1267 struct ccw1 tempCCW;
1268 struct chbk *p_ch;
1269 struct claw_env *p_env;
1270 int lock;
1271 struct clawph *pk_head;
1272 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001273
1274 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001275 privptr = (struct claw_privbk *)(dev->ml_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 p_ch=(struct chbk *)&privptr->channel[WRITE];
1277 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1279 /* scan the write queue to free any completed write packets */
1280 p_first_ccw=NULL;
1281 p_last_ccw=NULL;
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));
1291 }
1292 if (p_env->packing == DO_PACKED)
1293 pk_head->link_num = linkid;
1294 else
1295 pk_head->link_num = 0;
1296 pk_head->flag = 0x00;
1297 skb_pad(skb,4);
1298 skb->cb[1] = 'P';
1299 }
1300 if (linkid == 0) {
1301 if (claw_check_busy(dev)) {
1302 if (privptr->write_free_count!=0) {
1303 claw_clear_busy(dev);
1304 }
1305 else {
1306 claw_strt_out_IO(dev );
1307 claw_free_wrt_buf( dev );
1308 if (privptr->write_free_count==0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 ch = &privptr->channel[WRITE];
1310 atomic_inc(&skb->users);
1311 skb_queue_tail(&ch->collect_queue, skb);
1312 goto Done;
1313 }
1314 else {
1315 claw_clear_busy(dev);
1316 }
1317 }
1318 }
1319 /* tx lock */
1320 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 ch = &privptr->channel[WRITE];
1322 atomic_inc(&skb->users);
1323 skb_queue_tail(&ch->collect_queue, skb);
1324 claw_strt_out_IO(dev );
1325 rc=-EBUSY;
1326 goto Done2;
1327 }
1328 }
1329 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001330 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
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 ) {
1335
1336 claw_setbit_busy(TB_NOBUFFER,dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 ch = &privptr->channel[WRITE];
1338 atomic_inc(&skb->users);
1339 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001340 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 goto Done2;
1342 }
1343 pDataAddress=skb->data;
1344 len_of_data=skb->len;
1345
1346 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 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);
1352 goto Done2;
1353 }
1354 privptr->p_write_free_chain=p_this_ccw->next;
1355 p_this_ccw->next=NULL;
1356 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001357 if (len_of_data >= privptr->p_env->write_size)
1358 bytesInThisBuffer = privptr->p_env->write_size;
1359 else
1360 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 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;
1368 }
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;
1373 }
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);
1379 }
1380 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382
1383 /* FirstCCW and LastCCW now contain a new set of write channel
1384 * programs to append to the running channel program
1385 */
1386
1387 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001388 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 pEnd=privptr->p_end_ccw;
1390 if (pEnd->write1) {
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;
1400 }
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) */
1412
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 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;
1416 }
1417 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 /* set up Tic CCWs */
1419
1420 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1421 tempCCW.count=0;
1422 tempCCW.flags=0;
1423 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1424
1425 if (pEnd->write1) {
1426
1427 /*
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
1433 */
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);
1438 }
1439 else {
1440
1441 /*make sure we update the CCW atomically
1442 *so channel does not fetch it when it's only half done
1443 */
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);
1448
1449 } /* end if if (pEnd->write1) */
1450
1451 privptr->p_write_active_last->next=p_first_ccw;
1452 privptr->p_write_active_last=p_last_ccw;
1453 }
1454
1455 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001456 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 if (linkid==0) {
1458 lock=LOCK_NO;
1459 }
1460 else {
1461 lock=LOCK_YES;
1462 }
1463 claw_strt_out_IO(dev );
1464 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 if (privptr->write_free_count==0) {
1466 claw_setbit_busy(TB_NOBUFFER,dev);
1467 }
1468Done2:
1469 claw_clearbit_busy(TB_TX,dev);
1470Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 return(rc);
1472} /* end of claw_hw_tx */
1473
1474/*-------------------------------------------------------------------*
1475* *
1476* init_ccw_bk *
1477* *
1478*--------------------------------------------------------------------*/
1479
1480static int
1481init_ccw_bk(struct net_device *dev)
1482{
1483
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;
1491 void *p_buff=NULL;
1492 struct ccwbk*p_free_chain;
1493 struct ccwbk*p_buf;
1494 struct ccwbk*p_last_CCWB;
1495 struct ccwbk*p_first_CCWB;
1496 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001497 addr_t real_address;
1498 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 struct clawh *pClawH=NULL;
1500 addr_t real_TIC_address;
1501 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001502 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503
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 */
1519 p_last_CCWB = NULL;
1520 p_first_CCWB= NULL;
1521 /*
1522 * We need 1 CCW block for each read buffer, 1 for each
1523 * write buffer, plus 1 for ClawSignalBlock
1524 */
1525 ccw_blocks_required =
1526 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 /*
1528 * compute number of CCW blocks that will fit in a page
1529 */
1530 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1531 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001532 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 /*
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
1538 * buffers are used.
1539 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001540 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 }
1545 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001546 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 }
1551 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001552 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557 }
1558 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001559 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 /*
1565 * allocate ccw_pages_required
1566 */
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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 return -ENOMEM;
1573 }
1574 privptr->p_buff_ccw_num=ccw_pages_required;
1575 }
1576 memset(privptr->p_buff_ccw, 0x00,
1577 privptr->p_buff_ccw_num * PAGE_SIZE);
1578
1579 /*
1580 * obtain ending ccw block address
1581 *
1582 */
1583 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1584 real_address = (__u32)__pa(privptr->p_end_ccw);
1585 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 p_endccw=privptr->p_end_ccw;
1587 p_endccw->real=real_address;
1588 p_endccw->write1=0x00;
1589 p_endccw->read1=0x00;
1590
1591 /* write1_nop1 */
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;
1596
1597 /* write1_nop2 */
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;
1602
1603 /* write2_nop1 */
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;
1608
1609 /* write2_nop2 */
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;
1614
1615 /* read1_nop1 */
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;
1620
1621 /* read1_nop2 */
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;
1626
1627 /* read2_nop1 */
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;
1632
1633 /* read2_nop2 */
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;
1638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /*
1640 * Build a chain of CCWs
1641 *
1642 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 p_buff=privptr->p_buff_ccw;
1644
1645 p_free_chain=NULL;
1646 for (i=0 ; i < ccw_pages_required; i++ ) {
1647 real_address = (__u32)__pa(p_buff);
1648 p_buf=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);
1653 ++p_buf;
1654 }
1655 p_buff+=PAGE_SIZE;
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 /*
1658 * Initialize ClawSignalBlock
1659 *
1660 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 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;
1668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
1670 /*
1671 * allocate write_pages_required and add to free chain
1672 */
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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 return -ENOMEM;
1681 }
1682 /*
1683 * Build CLAW write free chain
1684 *
1685 */
1686
1687 memset(privptr->p_buff_write, 0x00,
1688 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 privptr->p_write_free_chain=NULL;
1690
1691 p_buff=privptr->p_buff_write;
1692
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;
1709
Andy Richter4811fcb2009-01-20 06:14:33 +00001710 if (((unsigned long)p_buff +
1711 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001713 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1714 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 }
1716 }
1717 }
1718 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1719 {
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) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 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)
1733 p_buf->p_buffer,
1734 (int)pages_to_order_of_mag(
1735 privptr->p_buff_pages_perwrite));
1736 p_buf=p_buf->next;
1737 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 return -ENOMEM;
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 */
1758
1759 } /* else buffers are PAGE_SIZE or bigger */
1760
1761 }
1762 privptr->p_buff_write_num=claw_write_pages;
1763 privptr->write_free_count=privptr->p_env->write_buffers;
1764
1765
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 /*
1767 * allocate read_pages_required and chain to free chain
1768 */
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) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 return -ENOMEM;
1785 }
1786 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1787 privptr->p_buff_read_num=claw_read_pages;
1788 /*
1789 * Build CLAW read free chain
1790 *
1791 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 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;
1796
1797 if (p_last_CCWB==NULL) {
1798 p_buf->next=NULL;
1799 real_TIC_address=0;
1800 p_last_CCWB=p_buf;
1801 }
1802 else {
1803 p_buf->next=p_first_CCWB;
1804 real_TIC_address=
1805 (__u32)__pa(&p_first_CCWB -> read );
1806 }
1807
1808 p_first_CCWB=p_buf;
1809
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;
1816
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);
1823
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;
1830
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;
1836
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;
1844
1845 /* initialize r_TIC_2 */
1846 memcpy(&p_buf->r_TIC_2,
1847 &p_buf->r_TIC_1, sizeof(struct ccw1));
1848
1849 /* initialize Header */
1850 p_buf->header.length=0xffff;
1851 p_buf->header.opcode=0xff;
1852 p_buf->header.flag=CLAW_PENDING;
1853
Andy Richter4811fcb2009-01-20 06:14:33 +00001854 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1855 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1856 -1)
1857 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 p_buff= p_buff+privptr->p_env->read_size;
1859 }
1860 else {
1861 p_buff=
1862 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001863 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 & PAGE_MASK) ;
1865 }
1866 } /* for read_buffers */
1867 } /* read_size < PAGE_SIZE */
1868 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1870 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001871 (int)pages_to_order_of_mag(
1872 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001875 (int)pages_to_order_of_mag(privptr->
1876 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877 /* free the write pages */
1878 p_buf=privptr->p_buff_write;
1879 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001880 free_pages(
1881 (unsigned long)p_buf->p_buffer,
1882 (int)pages_to_order_of_mag(
1883 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 p_buf=p_buf->next;
1885 }
1886 /* free any read pages already alloc */
1887 p_buf=privptr->p_buff_read;
1888 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001889 free_pages(
1890 (unsigned long)p_buf->p_buffer,
1891 (int)pages_to_order_of_mag(
1892 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 p_buf=p_buf->next;
1894 }
1895 privptr->p_buff_ccw=NULL;
1896 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 return -ENOMEM;
1898 }
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;
1903
1904 if (p_last_CCWB==NULL) {
1905 p_buf->next=NULL;
1906 real_TIC_address=0;
1907 p_last_CCWB=p_buf;
1908 }
1909 else {
1910 p_buf->next=p_first_CCWB;
1911 real_TIC_address=
1912 (addr_t)__pa(
1913 &p_first_CCWB -> read );
1914 }
1915
1916 p_first_CCWB=p_buf;
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;
1924
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);
1931
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;
1938
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;
1944
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;
1952
1953 /* initialize r_TIC_2 */
1954 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1955 sizeof(struct ccw1));
1956
1957 /* initialize Header */
1958 p_buf->header.length=0xffff;
1959 p_buf->header.opcode=0xff;
1960 p_buf->header.flag=CLAW_PENDING;
1961
1962 } /* For read_buffers */
1963 } /* read_size >= PAGE_SIZE */
1964 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1966 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02001967
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 return 0;
1969} /* end of init_ccw_bk */
1970
1971/*-------------------------------------------------------------------*
1972* *
1973* probe_error *
1974* *
1975*--------------------------------------------------------------------*/
1976
1977static void
1978probe_error( struct ccwgroup_device *cgdev)
1979{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001980 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02001981
1982 CLAW_DBF_TEXT(4, trace, "proberr");
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001983 privptr = (struct claw_privbk *) cgdev->dev.driver_data;
1984 if (privptr != NULL) {
1985 cgdev->dev.driver_data = NULL;
Jesper Juhl17fd6822005-11-07 01:01:30 -08001986 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001987 kfree(privptr->p_mtc_envelope);
1988 kfree(privptr);
1989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990} /* probe_error */
1991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992/*-------------------------------------------------------------------*
1993* claw_process_control *
1994* *
1995* *
1996*--------------------------------------------------------------------*/
1997
1998static int
1999claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2000{
2001
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;
2011 int rc;
2012 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002013 struct device *tdev;
2014 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 udelay(1000); /* Wait a ms for the control packets to
2016 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02002017 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 p_env=privptr->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02002019 tdev = &privptr->channel[READ].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 memcpy( &temp_host_name, p_env->host_name, 8);
2021 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002022 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 "Received Control Packet\n",
2024 dev->name, temp_ws_name);
2025 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 return 0;
2027 }
2028 p_buf=p_ccw->p_buffer;
2029 p_ctlbk=&ctlbk;
2030 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2031 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2032 } else {
2033 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 switch (p_ctlbk->command)
2036 {
Andy Richterb805da72008-07-18 15:24:56 +02002037 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);
Andy Richter4811fcb2009-01-20 06:14:33 +00002041 dev_warn(tdev, "The communication peer of %s"
2042 " uses an incorrect API version %d\n",
2043 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002044 }
2045 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002046 dev_info(tdev, "%s: Recv Sys Validate Request: "
2047 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2048 "Host name=%.8s\n",
2049 dev->name, p_ctlbk->version,
2050 p_ctlbk->linkid,
2051 p_ctlbk->correlator,
2052 p_sysval->WS_name,
2053 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002054 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);
Andy Richter4811fcb2009-01-20 06:14:33 +00002060 dev_warn(tdev,
2061 "Host name %s for %s does not match the"
2062 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002063 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002064 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002065 temp_host_name);
2066 }
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);
Andy Richter4811fcb2009-01-20 06:14:33 +00002073 dev_warn(tdev, "Adapter name %s for %s does not match"
2074 " the remote host name %s\n",
2075 p_sysval->WS_name,
2076 dev->name,
2077 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002078 }
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);
Andy Richter4811fcb2009-01-20 06:14:33 +00002083 dev_warn(tdev,
2084 "The local write buffer is smaller than the"
2085 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002086 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2087 }
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);
Andy Richter4811fcb2009-01-20 06:14:33 +00002092 dev_warn(tdev,
2093 "The local read buffer is smaller than the"
2094 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002095 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2096 }
2097 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002098 dev_info(tdev,
2099 "CLAW device %.8s: System validate"
2100 " completed.\n", temp_ws_name);
2101 dev_info(tdev,
2102 "%s: sys Validate Rsize:%d Wsize:%d\n",
2103 dev->name, p_sysval->read_frame_size,
2104 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002105 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);
2109 break;
2110 case SYSTEM_VALIDATE_RESPONSE:
2111 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002112 dev_info(tdev,
2113 "Settings for %s validated (version=%d, "
2114 "remote device=%d, rc=%d, adapter name=%.8s, "
2115 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002116 dev->name,
2117 p_ctlbk->version,
2118 p_ctlbk->correlator,
2119 p_ctlbk->rc,
2120 p_sysval->WS_name,
2121 p_sysval->host_name);
2122 switch (p_ctlbk->rc) {
2123 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002124 dev_info(tdev, "%s: CLAW device "
2125 "%.8s: System validate completed.\n",
2126 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002127 if (privptr->system_validate_comp == 0)
2128 claw_strt_conn_req(dev);
2129 privptr->system_validate_comp = 1;
2130 break;
2131 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002132 dev_warn(tdev, "Validating %s failed because of"
2133 " a host or adapter name mismatch\n",
2134 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002135 break;
2136 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002137 dev_warn(tdev, "Validating %s failed because of a"
2138 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002139 dev->name);
2140 break;
2141 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002142 dev_warn(tdev, "Validating %s failed because of a"
2143 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002144 dev->name);
2145 break;
2146 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002147 dev_warn(tdev, "The communication peer of %s rejected"
2148 " the connection\n",
2149 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002150 break;
2151 }
2152 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Andy Richterb805da72008-07-18 15:24:56 +02002154 case CONNECTION_REQUEST:
2155 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002156 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002157 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2158 dev->name,
2159 p_ctlbk->version,
2160 p_ctlbk->linkid,
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);
Andy Richter4811fcb2009-01-20 06:14:33 +00002166 dev_info(tdev, "%s rejected a connection request"
2167 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002168 dev->name);
2169 }
2170 if (p_ctlbk->linkid != 1) {
2171 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002172 dev_info(tdev, "%s rejected a request to open multiple"
2173 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002174 dev->name);
2175 }
2176 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2177 if (rc != 0) {
2178 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002179 dev_info(tdev, "%s rejected a connection request"
2180 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002181 dev->name);
2182 }
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);
2191 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002192 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002193 "completed link_id=%d.\n",
2194 dev->name, temp_ws_name,
2195 p_ctlbk->linkid);
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) */
2199 break;
2200 case CONNECTION_RESPONSE:
2201 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002202 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002203 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2204 dev->name,
2205 p_ctlbk->version,
2206 p_ctlbk->linkid,
2207 p_ctlbk->correlator,
2208 p_ctlbk->rc,
2209 p_connect->host_name,
2210 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
Andy Richterb805da72008-07-18 15:24:56 +02002212 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002213 dev_warn(tdev, "The communication peer of %s rejected"
2214 " a connection request\n",
2215 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002216 return 1;
2217 }
2218 rc = find_link(dev,
2219 p_connect->host_name, p_connect->WS_name);
2220 if (rc != 0) {
2221 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002222 dev_warn(tdev, "The communication peer of %s"
2223 " rejected a connection "
2224 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002225 dev->name);
2226 }
2227 /* should be until CONNECTION_CONFIRM */
2228 privptr->active_link_ID = -(p_ctlbk->linkid);
2229 break;
2230 case CONNECTION_CONFIRM:
2231 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002232 dev_info(tdev,
2233 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002234 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2235 dev->name,
2236 p_ctlbk->version,
2237 p_ctlbk->linkid,
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) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002244 dev_info(tdev,
2245 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 p_env->packing = DO_PACKED;
2247 }
Andy Richterb805da72008-07-18 15:24:56 +02002248 p_ch = &privptr->channel[WRITE];
2249 wake_up(&p_ch->wait);
2250 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002251 dev_warn(tdev, "Activating %s failed because of"
2252 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002253 dev->name, p_ctlbk->linkid);
2254 claw_snd_disc(dev, p_ctlbk);
2255 }
2256 break;
2257 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002258 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002259 "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;
2266 } else
2267 privptr->active_link_ID = 0;
2268 break;
2269 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002270 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002271 dev->name);
2272 break;
2273 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002274 dev_warn(tdev, "The communication peer of %s sent"
2275 " an unknown command code\n",
2276 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002277 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 }
2279
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 return 0;
2281} /* end of claw_process_control */
2282
2283
2284/*-------------------------------------------------------------------*
2285* claw_send_control *
2286* *
2287*--------------------------------------------------------------------*/
2288
2289static int
2290claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2291 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2292{
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;
2298
Andy Richterb805da72008-07-18 15:24:56 +02002299 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002300 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2302
2303 p_ctl->command=type;
2304 p_ctl->version=CLAW_VERSION_ID;
2305 p_ctl->linkid=link;
2306 p_ctl->correlator=correlator;
2307 p_ctl->rc=rc;
2308
2309 p_sysval=(struct sysval *)&p_ctl->data;
2310 p_connect=(struct conncmd *)&p_ctl->data;
2311
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) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002318 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2319 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002321 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002322 p_sysval->read_frame_size =
2323 privptr->p_env->read_size;
2324 p_sysval->write_frame_size =
2325 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
2327 memset(&p_sysval->reserved, 0x00, 4);
2328 break;
2329 case CONNECTION_REQUEST:
2330 case CONNECTION_RESPONSE:
2331 case CONNECTION_CONFIRM:
2332 case DISCONNECT:
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;
2339 } else {
2340 memset(&p_connect->reserved1, 0x00, 4);
2341 memset(&p_connect->reserved2, 0x00, 4);
2342 }
2343 break;
2344 default:
2345 break;
2346 }
2347
2348 /* write Control Record to the device */
2349
2350
2351 skb = dev_alloc_skb(sizeof(struct clawctl));
2352 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 return -ENOMEM;
2354 }
2355 memcpy(skb_put(skb, sizeof(struct clawctl)),
2356 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 if (privptr->p_env->packing >= PACK_SEND)
2358 claw_hw_tx(skb, dev, 1);
2359 else
2360 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 return 0;
2362} /* end of claw_send_control */
2363
2364/*-------------------------------------------------------------------*
2365* claw_snd_conn_req *
2366* *
2367*--------------------------------------------------------------------*/
2368static int
2369claw_snd_conn_req(struct net_device *dev, __u8 link)
2370{
2371 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002372 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 struct clawctl *p_ctl;
2374
Andy Richterb805da72008-07-18 15:24:56 +02002375 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 rc = 1;
2377 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2378 p_ctl->linkid = link;
2379 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 return rc;
2381 }
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);
2388 }
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 return rc;
2393
2394} /* end of claw_snd_conn_req */
2395
2396
2397/*-------------------------------------------------------------------*
2398* claw_snd_disc *
2399* *
2400*--------------------------------------------------------------------*/
2401
2402static int
2403claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2404{
2405 int rc;
2406 struct conncmd * p_connect;
2407
Andy Richterb805da72008-07-18 15:24:56 +02002408 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 p_connect=(struct conncmd *)&p_ctl->data;
2410
2411 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2412 p_ctl->correlator, 0,
2413 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 return rc;
2415} /* end of claw_snd_disc */
2416
2417
2418/*-------------------------------------------------------------------*
2419* claw_snd_sys_validate_rsp *
2420* *
2421*--------------------------------------------------------------------*/
2422
2423static int
2424claw_snd_sys_validate_rsp(struct net_device *dev,
2425 struct clawctl *p_ctl, __u32 return_code)
2426{
2427 struct claw_env * p_env;
2428 struct claw_privbk *privptr;
2429 int rc;
2430
Andy Richterb805da72008-07-18 15:24:56 +02002431 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002432 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 p_env=privptr->p_env;
2434 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2435 p_ctl->linkid,
2436 p_ctl->correlator,
2437 return_code,
2438 p_env->host_name,
2439 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 return rc;
2441} /* end of claw_snd_sys_validate_rsp */
2442
2443/*-------------------------------------------------------------------*
2444* claw_strt_conn_req *
2445* *
2446*--------------------------------------------------------------------*/
2447
2448static int
2449claw_strt_conn_req(struct net_device *dev )
2450{
2451 int rc;
2452
Andy Richterb805da72008-07-18 15:24:56 +02002453 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 return rc;
2456} /* end of claw_strt_conn_req */
2457
2458
2459
2460/*-------------------------------------------------------------------*
2461 * claw_stats *
2462 *-------------------------------------------------------------------*/
2463
2464static struct
2465net_device_stats *claw_stats(struct net_device *dev)
2466{
2467 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002468
2469 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002470 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return &privptr->stats;
2472} /* end of claw_stats */
2473
2474
2475/*-------------------------------------------------------------------*
2476* unpack_read *
2477* *
2478*--------------------------------------------------------------------*/
2479static void
2480unpack_read(struct net_device *dev )
2481{
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;
2489 void *p_packd;
2490 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002491 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
2493 __u32 len_of_data;
2494 __u32 pack_off;
2495 __u8 link_num;
2496 __u8 mtc_this_frm=0;
2497 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 int i=0;
2499 int p=0;
2500
Andy Richterb805da72008-07-18 15:24:56 +02002501 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 p_first_ccw=NULL;
2503 p_last_ccw=NULL;
2504 p_packh=NULL;
2505 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002506 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002507
2508 p_dev = &privptr->channel[READ].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 p_env = privptr->p_env;
2510 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 pack_off = 0;
2513 p = 0;
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;
2527 }
2528 if (p_env->packing == DO_PACKED)
2529 link_num=p_packh->link_num;
2530 else
2531 link_num=p_this_ccw->header.opcode / 8;
2532 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 mtc_this_frm=1;
2534 if (p_this_ccw->header.length!=
2535 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002536 dev_warn(p_dev,
2537 "The communication peer of %s"
2538 " sent a faulty"
2539 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 dev->name, p_this_ccw->header.length);
2541 }
2542 }
2543
2544 if (privptr->mtc_skipping) {
2545 /*
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.
2551 */
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;
2556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 goto NextFrame;
2558 }
2559
2560 if (link_num==0) {
2561 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002562 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 goto NextFrame;
2564 }
2565unpack_next:
2566 if (p_env->packing == DO_PACKED) {
2567 if (pack_off > p_env->read_size)
2568 goto NextFrame;
2569 p_packd = p_this_ccw->p_buffer+pack_off;
2570 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002571 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 (p_packh->flag != 0))
2573 goto NextFrame;
2574 bytes_to_mov = p_packh->len;
2575 pack_off += bytes_to_mov+sizeof(struct clawph);
2576 p++;
2577 } else {
2578 bytes_to_mov=p_this_ccw->header.length;
2579 }
2580 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
2582 /*
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
2585 * large buffer */
2586
2587 /* We are starting a new envelope */
2588 privptr->mtc_offset=0;
2589 privptr->mtc_logical_link=link_num;
2590 }
2591
2592 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2593 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 privptr->stats.rx_frame_errors++;
2595 goto NextFrame;
2596 }
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);
2600
2601 } else {
2602 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2603 p_this_ccw->p_buffer, bytes_to_mov);
2604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 if (mtc_this_frm==0) {
2606 len_of_data=privptr->mtc_offset+bytes_to_mov;
2607 skb=dev_alloc_skb(len_of_data);
2608 if (skb) {
2609 memcpy(skb_put(skb,len_of_data),
2610 privptr->p_mtc_envelope,
2611 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002613 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 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;
2618 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 }
2620 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002621 dev_info(p_dev, "Allocating a buffer for"
2622 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 }
2625 privptr->mtc_offset=0;
2626 privptr->mtc_logical_link=-1;
2627 }
2628 else {
2629 privptr->mtc_offset+=bytes_to_mov;
2630 }
2631 if (p_env->packing == DO_PACKED)
2632 goto unpack_next;
2633NextFrame:
2634 /*
2635 * Remove ThisCCWblock from active read queue, and add it
2636 * to queue of free blocks to be reused.
2637 */
2638 i++;
2639 p_this_ccw->header.length=0xffff;
2640 p_this_ccw->header.opcode=0xff;
2641 /*
2642 * add this one to the free queue for later reuse
2643 */
2644 if (p_first_ccw==NULL) {
2645 p_first_ccw = p_this_ccw;
2646 }
2647 else {
2648 p_last_ccw->next = p_this_ccw;
2649 }
2650 p_last_ccw = p_this_ccw;
2651 /*
2652 * chain to next block on active read queue
2653 */
2654 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002655 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 } /* end of while */
2657
2658 /* check validity */
2659
Andy Richterb805da72008-07-18 15:24:56 +02002660 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 return;
2664} /* end of unpack_read */
2665
2666/*-------------------------------------------------------------------*
2667* claw_strt_read *
2668* *
2669*--------------------------------------------------------------------*/
2670static void
2671claw_strt_read (struct net_device *dev, int lock )
2672{
2673 int rc = 0;
2674 __u32 parm;
2675 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002676 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 struct ccwbk*p_ccwbk;
2678 struct chbk *p_ch;
2679 struct clawh *p_clawh;
2680 p_ch=&privptr->channel[READ];
2681
Andy Richterb805da72008-07-18 15:24:56 +02002682 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2684 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2685
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 */
2691 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 if (lock==LOCK_YES) {
2693 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2694 }
2695 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002696 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 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,
2700 0xff, 0);
2701 if (rc != 0) {
2702 ccw_check_return_code(p_ch->cdev, rc);
2703 }
2704 }
2705 else {
Andy Richterb805da72008-07-18 15:24:56 +02002706 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 }
2708
2709 if (lock==LOCK_YES) {
2710 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2711 }
Andy Richterb805da72008-07-18 15:24:56 +02002712 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 return;
2714} /* end of claw_strt_read */
2715
2716/*-------------------------------------------------------------------*
2717* claw_strt_out_IO *
2718* *
2719*--------------------------------------------------------------------*/
2720
2721static void
2722claw_strt_out_IO( struct net_device *dev )
2723{
2724 int rc = 0;
2725 unsigned long parm;
2726 struct claw_privbk *privptr;
2727 struct chbk *p_ch;
2728 struct ccwbk *p_first_ccw;
2729
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 if (!dev) {
2731 return;
2732 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002733 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 p_ch=&privptr->channel[WRITE];
2735
Andy Richterb805da72008-07-18 15:24:56 +02002736 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 p_first_ccw=privptr->p_write_active_first;
2738
2739 if (p_ch->claw_state == CLAW_STOP)
2740 return;
2741 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 return;
2743 }
2744 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2745 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002746 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002747 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2748 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 if (rc != 0) {
2750 ccw_check_return_code(p_ch->cdev, rc);
2751 }
2752 }
2753 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return;
2755} /* end of claw_strt_out_IO */
2756
2757/*-------------------------------------------------------------------*
2758* Free write buffers *
2759* *
2760*--------------------------------------------------------------------*/
2761
2762static void
2763claw_free_wrt_buf( struct net_device *dev )
2764{
2765
Peter Tiedemann6951df32008-08-21 17:10:23 +02002766 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 struct ccwbk*p_first_ccw;
2768 struct ccwbk*p_last_ccw;
2769 struct ccwbk*p_this_ccw;
2770 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002771
2772 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 /* scan the write queue to free any completed write packets */
2774 p_first_ccw=NULL;
2775 p_last_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 p_this_ccw=privptr->p_write_active_first;
2777 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2778 {
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++;
2794 }
2795 else {
2796 break;
2797 }
2798 }
2799 if (privptr->write_free_count!=0) {
2800 claw_clearbit_busy(TB_NOBUFFER,dev);
2801 }
2802 /* whole chain removed? */
2803 if (privptr->p_write_active_first==NULL) {
2804 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 }
Andy Richterb805da72008-07-18 15:24:56 +02002806 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 return;
2808}
2809
2810/*-------------------------------------------------------------------*
2811* claw free netdevice *
2812* *
2813*--------------------------------------------------------------------*/
2814static void
2815claw_free_netdevice(struct net_device * dev, int free_dev)
2816{
2817 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
Andy Richterb805da72008-07-18 15:24:56 +02002819 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 if (!dev)
2821 return;
Andy Richterb805da72008-07-18 15:24:56 +02002822 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002823 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 if (dev->flags & IFF_RUNNING)
2825 claw_release(dev);
2826 if (privptr) {
2827 privptr->channel[READ].ndev = NULL; /* say it's free */
2828 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002829 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830#ifdef MODULE
2831 if (free_dev) {
2832 free_netdev(dev);
2833 }
2834#endif
Andy Richterb805da72008-07-18 15:24:56 +02002835 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836}
2837
2838/**
2839 * Claw init netdevice
2840 * Initialize everything of the net device except the name and the
2841 * channel structs.
2842 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002843static 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,
2849};
2850
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851static void
2852claw_init_netdevice(struct net_device * dev)
2853{
Andy Richterb805da72008-07-18 15:24:56 +02002854 CLAW_DBF_TEXT(2, setup, "init_dev");
2855 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 dev->hard_header_len = 0;
2858 dev->addr_len = 0;
2859 dev->type = ARPHRD_SLIP;
2860 dev->tx_queue_len = 1300;
2861 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002862 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002863 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 return;
2865}
2866
2867/**
2868 * Init a new channel in the privptr->channel[i].
2869 *
2870 * @param cdev The ccw_device to be added.
2871 *
2872 * @return 0 on success, !0 on error.
2873 */
2874static int
2875add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2876{
2877 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002878 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
Kay Sievers2a0217d2008-10-10 21:33:09 +02002880 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2882 p_ch = &privptr->channel[i];
2883 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002884 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002885 ccw_device_get_id(cdev, &dev_id);
2886 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002887 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 return -ENOMEM;
2889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 return 0;
2891}
2892
2893
2894/**
2895 *
2896 * Setup an interface.
2897 *
2898 * @param cgdev Device to be setup.
2899 *
2900 * @returns 0 on success, !0 on failure.
2901 */
2902static int
2903claw_new_device(struct ccwgroup_device *cgdev)
2904{
2905 struct claw_privbk *privptr;
2906 struct claw_env *p_env;
2907 struct net_device *dev;
2908 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002909 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
Andy Richter4811fcb2009-01-20 06:14:33 +00002911 dev_info(&cgdev->dev, "add for %s\n",
2912 dev_name(&cgdev->cdev[READ]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002913 CLAW_DBF_TEXT(2, setup, "new_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 privptr = cgdev->dev.driver_data;
2915 cgdev->cdev[READ]->dev.driver_data = privptr;
2916 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2917 if (!privptr)
2918 return -ENODEV;
2919 p_env = privptr->p_env;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002920 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 ret = add_channel(cgdev->cdev[0],0,privptr);
2925 if (ret == 0)
2926 ret = add_channel(cgdev->cdev[1],1,privptr);
2927 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002928 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2929 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002930 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 }
2932 ret = ccw_device_set_online(cgdev->cdev[READ]);
2933 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002934 dev_warn(&cgdev->dev,
2935 "Setting the read subchannel online"
2936 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 goto out;
2938 }
2939 ret = ccw_device_set_online(cgdev->cdev[WRITE]);
2940 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002941 dev_warn(&cgdev->dev,
2942 "Setting the write subchannel online "
2943 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 goto out;
2945 }
2946 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2947 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002948 dev_warn(&cgdev->dev,
2949 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 goto out;
2951 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002952 dev->ml_priv = privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 cgdev->dev.driver_data = privptr;
2954 cgdev->cdev[READ]->dev.driver_data = privptr;
2955 cgdev->cdev[WRITE]->dev.driver_data = privptr;
2956 /* sysfs magic */
2957 SET_NETDEV_DEV(dev, &cgdev->dev);
2958 if (register_netdev(dev) != 0) {
2959 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02002960 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 goto out;
2962 }
2963 dev->flags &=~IFF_RUNNING;
2964 if (privptr->buffs_alloc == 0) {
2965 ret=init_ccw_bk(dev);
2966 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 unregister_netdev(dev);
2968 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02002969 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 goto out;
2971 }
2972 }
2973 privptr->channel[READ].ndev = dev;
2974 privptr->channel[WRITE].ndev = dev;
2975 privptr->p_env->ndev = dev;
2976
Andy Richter4811fcb2009-01-20 06:14:33 +00002977 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 "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]);
Andy Richter4811fcb2009-01-20 06:14:33 +00002983 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 ":%.8s api_type: %.8s\n",
2985 dev->name, p_env->host_name,
2986 p_env->adapter_name , p_env->api_type);
2987 return 0;
2988out:
2989 ccw_device_set_offline(cgdev->cdev[1]);
2990 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 return -ENODEV;
2992}
2993
2994static void
2995claw_purge_skb_queue(struct sk_buff_head *q)
2996{
2997 struct sk_buff *skb;
2998
Andy Richterb805da72008-07-18 15:24:56 +02002999 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 while ((skb = skb_dequeue(q))) {
3001 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02003002 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 }
3004}
3005
3006/**
3007 * Shutdown an interface.
3008 *
3009 * @param cgdev Device to be shut down.
3010 *
3011 * @returns 0 on success, !0 on failure.
3012 */
3013static int
3014claw_shutdown_device(struct ccwgroup_device *cgdev)
3015{
3016 struct claw_privbk *priv;
3017 struct net_device *ndev;
3018 int ret;
3019
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003020 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 priv = cgdev->dev.driver_data;
3022 if (!priv)
3023 return -ENODEV;
3024 ndev = priv->channel[READ].ndev;
3025 if (ndev) {
3026 /* Close the device */
Andy Richter4811fcb2009-01-20 06:14:33 +00003027 dev_info(&cgdev->dev, "%s: shutting down \n",
3028 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 if (ndev->flags & IFF_RUNNING)
3030 ret = claw_release(ndev);
3031 ndev->flags &=~IFF_RUNNING;
3032 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003033 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 claw_free_netdevice(ndev, 1);
3035 priv->channel[READ].ndev = NULL;
3036 priv->channel[WRITE].ndev = NULL;
3037 priv->p_env->ndev = NULL;
3038 }
3039 ccw_device_set_offline(cgdev->cdev[1]);
3040 ccw_device_set_offline(cgdev->cdev[0]);
3041 return 0;
3042}
3043
3044static void
3045claw_remove_device(struct ccwgroup_device *cgdev)
3046{
3047 struct claw_privbk *priv;
3048
Andy Richterb805da72008-07-18 15:24:56 +02003049 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003050 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 priv = cgdev->dev.driver_data;
Andy Richterb805da72008-07-18 15:24:56 +02003052 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003053 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 if (cgdev->state == CCWGROUP_ONLINE)
3055 claw_shutdown_device(cgdev);
3056 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003057 kfree(priv->p_mtc_envelope);
3058 priv->p_mtc_envelope=NULL;
3059 kfree(priv->p_env);
3060 priv->p_env=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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 kfree(priv);
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);
Andy Richterb805da72008-07-18 15:24:56 +02003070
3071 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072}
3073
3074
3075/*
3076 * sysfs attributes
3077 */
3078static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003079claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080{
3081 struct claw_privbk *priv;
3082 struct claw_env * p_env;
3083
3084 priv = dev->driver_data;
3085 if (!priv)
3086 return -ENODEV;
3087 p_env = priv->p_env;
3088 return sprintf(buf, "%s\n",p_env->host_name);
3089}
3090
3091static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003092claw_hname_write(struct device *dev, struct device_attribute *attr,
3093 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094{
3095 struct claw_privbk *priv;
3096 struct claw_env * p_env;
3097
3098 priv = dev->driver_data;
3099 if (!priv)
3100 return -ENODEV;
3101 p_env = priv->p_env;
3102 if (count > MAX_NAME_LEN+1)
3103 return -EINVAL;
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;
Andy Richterb805da72008-07-18 15:24:56 +02003108 CLAW_DBF_TEXT(2, setup, "HstnSet");
3109 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110
3111 return count;
3112}
3113
3114static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3115
3116static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003117claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118{
3119 struct claw_privbk *priv;
3120 struct claw_env * p_env;
3121
3122 priv = dev->driver_data;
3123 if (!priv)
3124 return -ENODEV;
3125 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003126 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127}
3128
3129static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003130claw_adname_write(struct device *dev, struct device_attribute *attr,
3131 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132{
3133 struct claw_privbk *priv;
3134 struct claw_env * p_env;
3135
3136 priv = dev->driver_data;
3137 if (!priv)
3138 return -ENODEV;
3139 p_env = priv->p_env;
3140 if (count > MAX_NAME_LEN+1)
3141 return -EINVAL;
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;
Andy Richterb805da72008-07-18 15:24:56 +02003146 CLAW_DBF_TEXT(2, setup, "AdnSet");
3147 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 return count;
3150}
3151
3152static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3153
3154static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003155claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156{
3157 struct claw_privbk *priv;
3158 struct claw_env * p_env;
3159
3160 priv = dev->driver_data;
3161 if (!priv)
3162 return -ENODEV;
3163 p_env = priv->p_env;
3164 return sprintf(buf, "%s\n",
3165 p_env->api_type);
3166}
3167
3168static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003169claw_apname_write(struct device *dev, struct device_attribute *attr,
3170 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171{
3172 struct claw_privbk *priv;
3173 struct claw_env * p_env;
3174
3175 priv = dev->driver_data;
3176 if (!priv)
3177 return -ENODEV;
3178 p_env = priv->p_env;
3179 if (count > MAX_NAME_LEN+1)
3180 return -EINVAL;
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;
Andy Richterb805da72008-07-18 15:24:56 +02003189 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 }
3191 else {
3192 p_env->packing=0;
3193 p_env->read_size=CLAW_FRAME_SIZE;
3194 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003195 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196 }
Andy Richterb805da72008-07-18 15:24:56 +02003197 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 return count;
3199}
3200
3201static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3202
3203static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003204claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205{
3206 struct claw_privbk *priv;
3207 struct claw_env * p_env;
3208
3209 priv = dev->driver_data;
3210 if (!priv)
3211 return -ENODEV;
3212 p_env = priv->p_env;
3213 return sprintf(buf, "%d\n", p_env->write_buffers);
3214}
3215
3216static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003217claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3218 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219{
3220 struct claw_privbk *priv;
3221 struct claw_env * p_env;
3222 int nnn,max;
3223
3224 priv = dev->driver_data;
3225 if (!priv)
3226 return -ENODEV;
3227 p_env = priv->p_env;
3228 sscanf(buf, "%i", &nnn);
3229 if (p_env->packing) {
3230 max = 64;
3231 }
3232 else {
3233 max = 512;
3234 }
3235 if ((nnn > max ) || (nnn < 2))
3236 return -EINVAL;
3237 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003238 CLAW_DBF_TEXT(2, setup, "Wbufset");
3239 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 return count;
3241}
3242
3243static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3244
3245static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003246claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247{
3248 struct claw_privbk *priv;
3249 struct claw_env * p_env;
3250
3251 priv = dev->driver_data;
3252 if (!priv)
3253 return -ENODEV;
3254 p_env = priv->p_env;
3255 return sprintf(buf, "%d\n", p_env->read_buffers);
3256}
3257
3258static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003259claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3260 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261{
3262 struct claw_privbk *priv;
3263 struct claw_env *p_env;
3264 int nnn,max;
3265
3266 priv = dev->driver_data;
3267 if (!priv)
3268 return -ENODEV;
3269 p_env = priv->p_env;
3270 sscanf(buf, "%i", &nnn);
3271 if (p_env->packing) {
3272 max = 64;
3273 }
3274 else {
3275 max = 512;
3276 }
3277 if ((nnn > max ) || (nnn < 2))
3278 return -EINVAL;
3279 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003280 CLAW_DBF_TEXT(2, setup, "Rbufset");
3281 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 return count;
3283}
3284
3285static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3286
3287static 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,
3293 NULL,
3294};
3295
3296static struct attribute_group claw_attr_group = {
3297 .attrs = claw_attr,
3298};
3299
3300static int
3301claw_add_files(struct device *dev)
3302{
Andy Richterb805da72008-07-18 15:24:56 +02003303 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3305}
3306
3307static void
3308claw_remove_files(struct device *dev)
3309{
Andy Richterb805da72008-07-18 15:24:56 +02003310 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3312}
3313
3314/*--------------------------------------------------------------------*
3315* claw_init and cleanup *
3316*---------------------------------------------------------------------*/
3317
3318static void __exit
3319claw_cleanup(void)
3320{
3321 unregister_cu3088_discipline(&claw_group_driver);
3322 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003323 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
3325}
3326
3327/**
3328 * Initialize module.
3329 * This is called just after the module is loaded.
3330 *
3331 * @return 0 on success, !0 on error.
3332 */
3333static int __init
3334claw_init(void)
3335{
3336 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
Andy Richter4811fcb2009-01-20 06:14:33 +00003338 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 ret = claw_register_debug_facility();
3340 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003341 pr_err("Registering with the S/390 debug feature"
3342 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 return ret;
3344 }
Andy Richterb805da72008-07-18 15:24:56 +02003345 CLAW_DBF_TEXT(2, setup, "init_mod");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 ret = register_cu3088_discipline(&claw_group_driver);
3347 if (ret) {
Andy Richterb805da72008-07-18 15:24:56 +02003348 CLAW_DBF_TEXT(2, setup, "init_bad");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003350 pr_err("Registering with the cu3088 device driver failed "
3351 "with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 return ret;
3354}
3355
3356module_init(claw_init);
3357module_exit(claw_cleanup);
3358
Andy Richterb805da72008-07-18 15:24:56 +02003359MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3360MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3361 "Copyright 2000,2008 IBM Corporation\n");
3362MODULE_LICENSE("GPL");