blob: f7e7dcd74817eb7e5cdb28a0d306d8979358055e [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
Frank Blaschka88efc2c2009-06-16 10:30:33 +02006 * Copyright IBM Corp. 2002, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Author(s) Original code written by:
Frank Blaschka88efc2c2009-06-16 10:30:33 +02008 * Kazuo Iimura <iimura@jp.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Rewritten by
Frank Blaschka88efc2c2009-06-16 10:30:33 +020010 * Andy Richter <richtera@us.ibm.com>
11 * Marc Price <mwprice@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include "claw.h"
94
Andy Richterb805da72008-07-18 15:24:56 +020095/*
96 CLAW uses the s390dbf file system see claw_trace and claw_setup
Linus Torvalds1da177e2005-04-16 15:20:36 -070097*/
98
Andy Richter4811fcb2009-01-20 06:14:33 +000099static char version[] __initdata = "CLAW driver";
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100100static char debug_buffer[255];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/**
102 * Debug Facility Stuff
103 */
104static debug_info_t *claw_dbf_setup;
105static debug_info_t *claw_dbf_trace;
106
107/**
108 * CLAW Debug Facility functions
109 */
110static void
111claw_unregister_debug_facility(void)
112{
113 if (claw_dbf_setup)
114 debug_unregister(claw_dbf_setup);
115 if (claw_dbf_trace)
116 debug_unregister(claw_dbf_trace);
117}
118
119static int
120claw_register_debug_facility(void)
121{
Michael Holzheu66a464d2005-06-25 14:55:33 -0700122 claw_dbf_setup = debug_register("claw_setup", 2, 1, 8);
123 claw_dbf_trace = debug_register("claw_trace", 2, 2, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 claw_unregister_debug_facility();
126 return -ENOMEM;
127 }
128 debug_register_view(claw_dbf_setup, &debug_hex_ascii_view);
129 debug_set_level(claw_dbf_setup, 2);
130 debug_register_view(claw_dbf_trace, &debug_hex_ascii_view);
131 debug_set_level(claw_dbf_trace, 2);
132 return 0;
133}
134
135static inline void
136claw_set_busy(struct net_device *dev)
137{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200138 ((struct claw_privbk *)dev->ml_priv)->tbusy = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
141static inline void
142claw_clear_busy(struct net_device *dev)
143{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200144 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146}
147
148static inline int
149claw_check_busy(struct net_device *dev)
150{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200151 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152}
153
154static inline void
155claw_setbit_busy(int nr,struct net_device *dev)
156{
157 netif_stop_queue(dev);
Peter Tiedemann6951df32008-08-21 17:10:23 +0200158 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161static inline void
162claw_clearbit_busy(int nr,struct net_device *dev)
163{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200164 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 netif_wake_queue(dev);
166}
167
168static inline int
169claw_test_and_setbit_busy(int nr,struct net_device *dev)
170{
171 netif_stop_queue(dev);
172 return test_and_set_bit(nr,
Peter Tiedemann6951df32008-08-21 17:10:23 +0200173 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174}
175
176
177/* Functions for the DEV methods */
178
179static int claw_probe(struct ccwgroup_device *cgdev);
180static void claw_remove_device(struct ccwgroup_device *cgdev);
181static void claw_purge_skb_queue(struct sk_buff_head *q);
182static int claw_new_device(struct ccwgroup_device *cgdev);
183static int claw_shutdown_device(struct ccwgroup_device *cgdev);
184static int claw_tx(struct sk_buff *skb, struct net_device *dev);
185static int claw_change_mtu( struct net_device *dev, int new_mtu);
186static int claw_open(struct net_device *dev);
187static void claw_irq_handler(struct ccw_device *cdev,
188 unsigned long intparm, struct irb *irb);
189static void claw_irq_tasklet ( unsigned long data );
190static int claw_release(struct net_device *dev);
191static void claw_write_retry ( struct chbk * p_ch );
192static void claw_write_next ( struct chbk * p_ch );
193static void claw_timer ( struct chbk * p_ch );
194
195/* Functions */
196static int add_claw_reads(struct net_device *dev,
197 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100198static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
199static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200static int find_link(struct net_device *dev, char *host_name, char *ws_name );
201static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
202static int init_ccw_bk(struct net_device *dev);
203static void probe_error( struct ccwgroup_device *cgdev);
204static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100205static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/* sysfs Functions */
Andy Richter4811fcb2009-01-20 06:14:33 +0000208static ssize_t claw_hname_show(struct device *dev,
209 struct device_attribute *attr, char *buf);
210static ssize_t claw_hname_write(struct device *dev,
211 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000213static ssize_t claw_adname_show(struct device *dev,
214 struct device_attribute *attr, char *buf);
215static ssize_t claw_adname_write(struct device *dev,
216 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000218static ssize_t claw_apname_show(struct device *dev,
219 struct device_attribute *attr, char *buf);
220static ssize_t claw_apname_write(struct device *dev,
221 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000223static ssize_t claw_wbuff_show(struct device *dev,
224 struct device_attribute *attr, char *buf);
225static ssize_t claw_wbuff_write(struct device *dev,
226 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000228static ssize_t claw_rbuff_show(struct device *dev,
229 struct device_attribute *attr, char *buf);
230static ssize_t claw_rbuff_write(struct device *dev,
231 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 const char *buf, size_t count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234/* Functions for System Validate */
235static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
236static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
237 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
238static int claw_snd_conn_req(struct net_device *dev, __u8 link);
239static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
240static int claw_snd_sys_validate_rsp(struct net_device *dev,
241 struct clawctl * p_ctl, __u32 return_code);
242static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200243static void claw_strt_read(struct net_device *dev, int lock);
244static void claw_strt_out_IO(struct net_device *dev);
245static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200248static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200250static int claw_pm_prepare(struct ccwgroup_device *gdev)
251{
252 return -EPERM;
253}
254
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000255/* the root device for claw group devices */
256static struct device *claw_root_dev;
257
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258/* ccwgroup table */
259
260static struct ccwgroup_driver claw_group_driver = {
Sebastian Ott3c190c52011-03-23 10:16:04 +0100261 .driver = {
262 .owner = THIS_MODULE,
263 .name = "claw",
264 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 .max_slaves = 2,
266 .driver_id = 0xC3D3C1E6,
Sebastian Ott2ced5512012-05-15 18:00:49 +0200267 .setup = claw_probe,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 .remove = claw_remove_device,
269 .set_online = claw_new_device,
270 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200271 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272};
273
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000274static struct ccw_device_id claw_ids[] = {
275 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
276 {},
277};
278MODULE_DEVICE_TABLE(ccw, claw_ids);
279
280static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100281 .driver = {
282 .owner = THIS_MODULE,
283 .name = "claw",
284 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000285 .ids = claw_ids,
286 .probe = ccwgroup_probe_ccwdev,
287 .remove = ccwgroup_remove_ccwdev,
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100288 .int_class = IOINT_CLW,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000289};
290
Sebastian Ott2ced5512012-05-15 18:00:49 +0200291static ssize_t claw_driver_group_store(struct device_driver *ddrv,
292 const char *buf, size_t count)
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000293{
294 int err;
Sebastian Ott2ced5512012-05-15 18:00:49 +0200295 err = ccwgroup_create_dev(claw_root_dev, claw_group_driver.driver_id,
296 &claw_group_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000297 return err ? err : count;
298}
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000299static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
300
301static struct attribute *claw_group_attrs[] = {
302 &driver_attr_group.attr,
303 NULL,
304};
305
306static struct attribute_group claw_group_attr_group = {
307 .attrs = claw_group_attrs,
308};
309
Heiko Carstens302689a2009-11-17 06:47:02 -0800310static const struct attribute_group *claw_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000311 &claw_group_attr_group,
312 NULL,
313};
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316* Key functions
317*/
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319/*-------------------------------------------------------------------*
320 * claw_tx *
321 *-------------------------------------------------------------------*/
322
323static int
324claw_tx(struct sk_buff *skb, struct net_device *dev)
325{
326 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200327 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 unsigned long saveflags;
329 struct chbk *p_ch;
330
Andy Richterb805da72008-07-18 15:24:56 +0200331 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb0832010-08-12 01:58:27 +0000332 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
334 rc=claw_hw_tx( skb, dev, 1 );
335 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200336 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000337 if (rc)
338 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700339 else
340 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return rc;
342} /* end of claw_tx */
343
344/*------------------------------------------------------------------*
345 * pack the collect queue into an skb and return it *
346 * If not packing just return the top skb from the queue *
347 *------------------------------------------------------------------*/
348
349static struct sk_buff *
350claw_pack_skb(struct claw_privbk *privptr)
351{
352 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000353 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 struct claw_env *p_env = privptr->p_env;
355 int pkt_cnt,pk_ind,so_far;
356
357 new_skb = NULL; /* assume no dice */
358 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200359 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700360 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 /* some data */
362 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200364 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 else
366 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200367 if (p_env->packing != DO_PACKED)
368 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /* get a new SKB we will pack at least one */
370 new_skb = dev_alloc_skb(p_env->write_size);
371 if (new_skb == NULL) {
372 atomic_inc(&held_skb->users);
373 skb_queue_head(&p_ch->collect_queue,held_skb);
374 return NULL;
375 }
376 /* we have packed packet and a place to put it */
377 pk_ind = 1;
378 so_far = 0;
379 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
380 while ((pk_ind) && (held_skb != NULL)) {
381 if (held_skb->len+so_far <= p_env->write_size-8) {
382 memcpy(skb_put(new_skb,held_skb->len),
383 held_skb->data,held_skb->len);
384 privptr->stats.tx_packets++;
385 so_far += held_skb->len;
386 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200387 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 held_skb = skb_dequeue(&p_ch->collect_queue);
389 if (held_skb)
390 atomic_dec(&held_skb->users);
391 } else {
392 pk_ind = 0;
393 atomic_inc(&held_skb->users);
394 skb_queue_head(&p_ch->collect_queue,held_skb);
395 }
396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 }
Andy Richterb805da72008-07-18 15:24:56 +0200398 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 return new_skb;
400}
401
402/*-------------------------------------------------------------------*
403 * claw_change_mtu *
404 * *
405 *-------------------------------------------------------------------*/
406
407static int
408claw_change_mtu(struct net_device *dev, int new_mtu)
409{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200410 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200412 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 buff_size = privptr->p_env->write_size;
414 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 return -EINVAL;
416 }
417 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return 0;
419} /* end of claw_change_mtu */
420
421
422/*-------------------------------------------------------------------*
423 * claw_open *
424 * *
425 *-------------------------------------------------------------------*/
426static int
427claw_open(struct net_device *dev)
428{
429
430 int rc;
431 int i;
432 unsigned long saveflags=0;
433 unsigned long parm;
434 struct claw_privbk *privptr;
435 DECLARE_WAITQUEUE(wait, current);
436 struct timer_list timer;
437 struct ccwbk *p_buf;
438
Andy Richterb805da72008-07-18 15:24:56 +0200439 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200440 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 /* allocate and initialize CCW blocks */
442 if (privptr->buffs_alloc == 0) {
443 rc=init_ccw_bk(dev);
444 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200445 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return -ENOMEM;
447 }
448 }
449 privptr->system_validate_comp=0;
450 privptr->release_pend=0;
451 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
452 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
453 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
454 privptr->p_env->packing=PACKING_ASK;
455 } else {
456 privptr->p_env->packing=0;
457 privptr->p_env->read_size=CLAW_FRAME_SIZE;
458 privptr->p_env->write_size=CLAW_FRAME_SIZE;
459 }
460 claw_set_busy(dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000461 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
462 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200464 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 init_waitqueue_head(&privptr->channel[i].wait);
466 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000467 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 skb_queue_head_init(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000469 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 privptr->channel[i].flag_a = 0;
471 privptr->channel[i].IO_active = 0;
472 privptr->channel[i].flag &= ~CLAW_TIMER;
473 init_timer(&timer);
474 timer.function = (void *)claw_timer;
475 timer.data = (unsigned long)(&privptr->channel[i]);
476 timer.expires = jiffies + 15*HZ;
477 add_timer(&timer);
478 spin_lock_irqsave(get_ccwdev_lock(
479 privptr->channel[i].cdev), saveflags);
480 parm = (unsigned long) &privptr->channel[i];
481 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
482 rc = 0;
483 add_wait_queue(&privptr->channel[i].wait, &wait);
484 rc = ccw_device_halt(
485 (struct ccw_device *)privptr->channel[i].cdev,parm);
486 set_current_state(TASK_INTERRUPTIBLE);
487 spin_unlock_irqrestore(
488 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
489 schedule();
490 set_current_state(TASK_RUNNING);
491 remove_wait_queue(&privptr->channel[i].wait, &wait);
492 if(rc != 0)
493 ccw_check_return_code(privptr->channel[i].cdev, rc);
494 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
495 del_timer(&timer);
496 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000497 if ((((privptr->channel[READ_CHANNEL].last_dstat |
498 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb0832010-08-12 01:58:27 +0000500 (((privptr->channel[READ_CHANNEL].flag |
501 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
502 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000503 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200504 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 for ( i = 0; i < 2; i++) {
507 spin_lock_irqsave(
508 get_ccwdev_lock(privptr->channel[i].cdev),
509 saveflags);
510 parm = (unsigned long) &privptr->channel[i];
511 privptr->channel[i].claw_state = CLAW_STOP;
512 rc = ccw_device_halt(
513 (struct ccw_device *)&privptr->channel[i].cdev,
514 parm);
515 spin_unlock_irqrestore(
516 get_ccwdev_lock(privptr->channel[i].cdev),
517 saveflags);
518 if (rc != 0) {
519 ccw_check_return_code(
520 privptr->channel[i].cdev, rc);
521 }
522 }
523 free_pages((unsigned long)privptr->p_buff_ccw,
524 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
525 if (privptr->p_env->read_size < PAGE_SIZE) {
526 free_pages((unsigned long)privptr->p_buff_read,
527 (int)pages_to_order_of_mag(
528 privptr->p_buff_read_num));
529 }
530 else {
531 p_buf=privptr->p_read_active_first;
532 while (p_buf!=NULL) {
533 free_pages((unsigned long)p_buf->p_buffer,
534 (int)pages_to_order_of_mag(
535 privptr->p_buff_pages_perread ));
536 p_buf=p_buf->next;
537 }
538 }
539 if (privptr->p_env->write_size < PAGE_SIZE ) {
540 free_pages((unsigned long)privptr->p_buff_write,
541 (int)pages_to_order_of_mag(
542 privptr->p_buff_write_num));
543 }
544 else {
545 p_buf=privptr->p_write_active_first;
546 while (p_buf!=NULL) {
547 free_pages((unsigned long)p_buf->p_buffer,
548 (int)pages_to_order_of_mag(
549 privptr->p_buff_pages_perwrite ));
550 p_buf=p_buf->next;
551 }
552 }
553 privptr->buffs_alloc = 0;
Heiko Carstens319cb0832010-08-12 01:58:27 +0000554 privptr->channel[READ_CHANNEL].flag = 0x00;
555 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 privptr->p_buff_ccw=NULL;
557 privptr->p_buff_read=NULL;
558 privptr->p_buff_write=NULL;
559 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200560 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 return -EIO;
562 }
563
564 /* Send SystemValidate command */
565
566 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200567 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return 0;
569} /* end of claw_open */
570
571/*-------------------------------------------------------------------*
572* *
573* claw_irq_handler *
574* *
575*--------------------------------------------------------------------*/
576static void
577claw_irq_handler(struct ccw_device *cdev,
578 unsigned long intparm, struct irb *irb)
579{
580 struct chbk *p_ch = NULL;
581 struct claw_privbk *privptr = NULL;
582 struct net_device *dev = NULL;
583 struct claw_env *p_env;
584 struct chbk *p_ch_r=NULL;
585
Andy Richterb805da72008-07-18 15:24:56 +0200586 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700588 privptr = dev_get_drvdata(&cdev->dev);
589 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000590 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
591 " IRQ, c-%02x d-%02x\n",
592 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200593 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 return;
595 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 /* Try to extract channel from driver data. */
Heiko Carstens319cb0832010-08-12 01:58:27 +0000598 if (privptr->channel[READ_CHANNEL].cdev == cdev)
599 p_ch = &privptr->channel[READ_CHANNEL];
600 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
601 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000603 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200604 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 return;
606 }
Andy Richterb805da72008-07-18 15:24:56 +0200607 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 dev = (struct net_device *) (p_ch->ndev);
610 p_env=privptr->p_env;
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 /* Copy interruption response block. */
613 memcpy(p_ch->irb, irb, sizeof(struct irb));
614
Andy Richterb805da72008-07-18 15:24:56 +0200615 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200616 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000617 dev_info(&cdev->dev,
618 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
620 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200621 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
622 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200623 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 /* return; */
625 }
626
627 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200628 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200632 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200635 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
636 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
637 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
638 (p_ch->irb->scsw.cmd.stctl ==
639 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
640 return;
641 wake_up(&p_ch->wait); /* wake up claw_release */
642 CLAW_DBF_TEXT(4, trace, "stop");
643 return;
644 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
645 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
646 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
647 (p_ch->irb->scsw.cmd.stctl ==
648 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
649 CLAW_DBF_TEXT(4, trace, "haltio");
650 return;
651 }
652 if (p_ch->flag == CLAW_READ) {
653 p_ch->claw_state = CLAW_START_READ;
654 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
655 } else if (p_ch->flag == CLAW_WRITE) {
656 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000657 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200658 claw_strt_read(dev, LOCK_NO);
659 claw_send_control(dev,
660 SYSTEM_VALIDATE_REQUEST,
661 0, 0, 0,
662 p_env->host_name,
663 p_env->adapter_name);
664 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000665 dev_warn(&cdev->dev, "The CLAW device received"
666 " an unexpected IRQ, "
667 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200668 irb->scsw.cmd.cstat,
669 irb->scsw.cmd.dstat);
670 return;
671 }
672 CLAW_DBF_TEXT(4, trace, "haltio");
673 return;
674 case CLAW_START_READ:
675 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
676 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
677 clear_bit(0, (void *)&p_ch->IO_active);
678 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
679 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
680 (p_ch->irb->ecw[0]) == 0) {
681 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000682 dev_info(&cdev->dev,
683 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200684 "side recovers \n",
685 dev->name);
686 }
687 CLAW_DBF_TEXT(4, trace, "notrdy");
688 return;
689 }
690 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
691 (p_ch->irb->scsw.cmd.dstat == 0)) {
692 if (test_and_set_bit(CLAW_BH_ACTIVE,
693 (void *)&p_ch->flag_a) == 0)
694 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 else
Andy Richterb805da72008-07-18 15:24:56 +0200696 CLAW_DBF_TEXT(4, trace, "PCINoBH");
697 CLAW_DBF_TEXT(4, trace, "PCI_read");
698 return;
699 }
700 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
701 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
702 (p_ch->irb->scsw.cmd.stctl ==
703 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
704 CLAW_DBF_TEXT(4, trace, "SPend_rd");
705 return;
706 }
707 clear_bit(0, (void *)&p_ch->IO_active);
708 claw_clearbit_busy(TB_RETRY, dev);
709 if (test_and_set_bit(CLAW_BH_ACTIVE,
710 (void *)&p_ch->flag_a) == 0)
711 tasklet_schedule(&p_ch->tasklet);
712 else
713 CLAW_DBF_TEXT(4, trace, "RdBHAct");
714 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
715 return;
716 case CLAW_START_WRITE:
717 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000718 dev_info(&cdev->dev,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300719 "%s: Unit Check Occurred in "
Andy Richterb805da72008-07-18 15:24:56 +0200720 "write channel\n", dev->name);
721 clear_bit(0, (void *)&p_ch->IO_active);
722 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000723 dev_info(&cdev->dev,
724 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200725 "occurred:\n", dev->name);
726 init_timer(&p_ch->timer);
727 p_ch->timer.function =
728 (void *)claw_write_retry;
729 p_ch->timer.data = (unsigned long)p_ch;
730 p_ch->timer.expires = jiffies + 10*HZ;
731 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000732 dev_info(&cdev->dev,
733 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200734 "restarting\n", dev->name);
735 }
736 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
737 return;
738 }
739 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
740 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000741 dev_info(&cdev->dev,
742 "%s: Unit Exception "
743 "occurred in write channel\n",
744 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200745 }
746 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
747 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
748 (p_ch->irb->scsw.cmd.stctl ==
749 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
750 CLAW_DBF_TEXT(4, trace, "writeUE");
751 return;
752 }
753 clear_bit(0, (void *)&p_ch->IO_active);
754 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
755 claw_write_next(p_ch);
756 claw_clearbit_busy(TB_TX, dev);
757 claw_clear_busy(dev);
758 }
Heiko Carstens319cb0832010-08-12 01:58:27 +0000759 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200760 if (test_and_set_bit(CLAW_BH_ACTIVE,
761 (void *)&p_ch_r->flag_a) == 0)
762 tasklet_schedule(&p_ch_r->tasklet);
763 CLAW_DBF_TEXT(4, trace, "StWtExit");
764 return;
765 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000766 dev_warn(&cdev->dev,
767 "The CLAW device for %s received an unexpected IRQ\n",
768 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200769 CLAW_DBF_TEXT(2, trace, "badIRQ");
770 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 }
772
773} /* end of claw_irq_handler */
774
775
776/*-------------------------------------------------------------------*
777* claw_irq_tasklet *
778* *
779*--------------------------------------------------------------------*/
780static void
781claw_irq_tasklet ( unsigned long data )
782{
783 struct chbk * p_ch;
784 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786 p_ch = (struct chbk *) data;
787 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200788 CLAW_DBF_TEXT(4, trace, "IRQtask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 unpack_read(dev);
790 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200791 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 return;
793} /* end of claw_irq_bh */
794
795/*-------------------------------------------------------------------*
796* claw_release *
797* *
798*--------------------------------------------------------------------*/
799static int
800claw_release(struct net_device *dev)
801{
802 int rc;
803 int i;
804 unsigned long saveflags;
805 unsigned long parm;
806 struct claw_privbk *privptr;
807 DECLARE_WAITQUEUE(wait, current);
808 struct ccwbk* p_this_ccw;
809 struct ccwbk* p_buf;
810
811 if (!dev)
812 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200813 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 if (!privptr)
815 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200816 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 privptr->release_pend=1;
818 claw_setbit_busy(TB_STOP,dev);
819 for ( i = 1; i >=0 ; i--) {
820 spin_lock_irqsave(
821 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb0832010-08-12 01:58:27 +0000822 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 privptr->channel[i].claw_state = CLAW_STOP;
824 privptr->channel[i].IO_active = 0;
825 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb0832010-08-12 01:58:27 +0000826 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 claw_purge_skb_queue(
Heiko Carstens319cb0832010-08-12 01:58:27 +0000828 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
830 if (privptr->system_validate_comp==0x00) /* never opened? */
831 init_waitqueue_head(&privptr->channel[i].wait);
832 add_wait_queue(&privptr->channel[i].wait, &wait);
833 set_current_state(TASK_INTERRUPTIBLE);
834 spin_unlock_irqrestore(
835 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
836 schedule();
837 set_current_state(TASK_RUNNING);
838 remove_wait_queue(&privptr->channel[i].wait, &wait);
839 if (rc != 0) {
840 ccw_check_return_code(privptr->channel[i].cdev, rc);
841 }
842 }
843 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200844 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 privptr->pk_skb = NULL;
846 }
847 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200848 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 return 0;
850 }
Andy Richterb805da72008-07-18 15:24:56 +0200851 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 if (privptr->p_buff_ccw != NULL) {
853 free_pages((unsigned long)privptr->p_buff_ccw,
854 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
855 }
Andy Richterb805da72008-07-18 15:24:56 +0200856 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (privptr->p_env->read_size < PAGE_SIZE) {
858 if (privptr->p_buff_read != NULL) {
859 free_pages((unsigned long)privptr->p_buff_read,
860 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
861 }
862 }
863 else {
864 p_buf=privptr->p_read_active_first;
865 while (p_buf!=NULL) {
866 free_pages((unsigned long)p_buf->p_buffer,
867 (int)pages_to_order_of_mag(
868 privptr->p_buff_pages_perread ));
869 p_buf=p_buf->next;
870 }
871 }
Andy Richterb805da72008-07-18 15:24:56 +0200872 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 if (privptr->p_env->write_size < PAGE_SIZE ) {
874 free_pages((unsigned long)privptr->p_buff_write,
875 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
876 }
877 else {
878 p_buf=privptr->p_write_active_first;
879 while (p_buf!=NULL) {
880 free_pages((unsigned long)p_buf->p_buffer,
881 (int)pages_to_order_of_mag(
882 privptr->p_buff_pages_perwrite ));
883 p_buf=p_buf->next;
884 }
885 }
Andy Richterb805da72008-07-18 15:24:56 +0200886 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 privptr->buffs_alloc = 0;
888 privptr->p_buff_ccw=NULL;
889 privptr->p_buff_read=NULL;
890 privptr->p_buff_write=NULL;
891 privptr->system_validate_comp=0;
892 privptr->release_pend=0;
893 /* Remove any writes that were pending and reset all reads */
894 p_this_ccw=privptr->p_read_active_first;
895 while (p_this_ccw!=NULL) {
896 p_this_ccw->header.length=0xffff;
897 p_this_ccw->header.opcode=0xff;
898 p_this_ccw->header.flag=0x00;
899 p_this_ccw=p_this_ccw->next;
900 }
901
902 while (privptr->p_write_active_first!=NULL) {
903 p_this_ccw=privptr->p_write_active_first;
904 p_this_ccw->header.flag=CLAW_PENDING;
905 privptr->p_write_active_first=p_this_ccw->next;
906 p_this_ccw->next=privptr->p_write_free_chain;
907 privptr->p_write_free_chain=p_this_ccw;
908 ++privptr->write_free_count;
909 }
910 privptr->p_write_active_last=NULL;
911 privptr->mtc_logical_link = -1;
912 privptr->mtc_skipping = 1;
913 privptr->mtc_offset=0;
914
Heiko Carstens319cb0832010-08-12 01:58:27 +0000915 if (((privptr->channel[READ_CHANNEL].last_dstat |
916 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb0832010-08-12 01:58:27 +0000918 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000919 "Deactivating %s completed with incorrect"
920 " subchannel status "
921 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 dev->name,
Heiko Carstens319cb0832010-08-12 01:58:27 +0000923 privptr->channel[READ_CHANNEL].last_dstat,
924 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200925 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 }
Andy Richterb805da72008-07-18 15:24:56 +0200927 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 return 0;
929} /* end of claw_release */
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931/*-------------------------------------------------------------------*
932* claw_write_retry *
933* *
934*--------------------------------------------------------------------*/
935
936static void
937claw_write_retry ( struct chbk *p_ch )
938{
939
940 struct net_device *dev=p_ch->ndev;
941
Andy Richterb805da72008-07-18 15:24:56 +0200942 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 return;
945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +0200947 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 return;
949} /* end of claw_write_retry */
950
951
952/*-------------------------------------------------------------------*
953* claw_write_next *
954* *
955*--------------------------------------------------------------------*/
956
957static void
958claw_write_next ( struct chbk * p_ch )
959{
960
961 struct net_device *dev;
962 struct claw_privbk *privptr=NULL;
963 struct sk_buff *pk_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
Andy Richterb805da72008-07-18 15:24:56 +0200965 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 if (p_ch->claw_state == CLAW_STOP)
967 return;
968 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200969 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 claw_free_wrt_buf( dev );
971 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -0700972 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 pk_skb = claw_pack_skb(privptr);
974 while (pk_skb != NULL) {
Heiko Carstens38ed18f2011-05-12 18:45:04 +0000975 claw_hw_tx(pk_skb, dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 if (privptr->write_free_count > 0) {
977 pk_skb = claw_pack_skb(privptr);
978 } else
979 pk_skb = NULL;
980 }
981 }
982 if (privptr->p_write_active_first!=NULL) {
983 claw_strt_out_IO(dev);
984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 return;
986} /* end of claw_write_next */
987
988/*-------------------------------------------------------------------*
989* *
990* claw_timer *
991*--------------------------------------------------------------------*/
992
993static void
994claw_timer ( struct chbk * p_ch )
995{
Andy Richterb805da72008-07-18 15:24:56 +0200996 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 p_ch->flag |= CLAW_TIMER;
998 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 return;
1000} /* end of claw_timer */
1001
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002/*
1003*
1004* functions
1005*/
1006
1007
1008/*-------------------------------------------------------------------*
1009* *
1010* pages_to_order_of_mag *
1011* *
1012* takes a number of pages from 1 to 512 and returns the *
1013* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1014* of magnitude get_free_pages() has an upper order of 9 *
1015*--------------------------------------------------------------------*/
1016
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001017static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018pages_to_order_of_mag(int num_of_pages)
1019{
1020 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001021 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001022
1023 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1025 /* 512 pages = 2Meg on 4k page systems */
1026 if (num_of_pages >= 512) {return 9; }
1027 /* we have two or more pages order is at least 1 */
1028 for (nump=2 ;nump <= 512;nump*=2) {
1029 if (num_of_pages <= nump)
1030 break;
1031 order_of_mag +=1;
1032 }
1033 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001034 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 return order_of_mag;
1036}
1037
1038/*-------------------------------------------------------------------*
1039* *
1040* add_claw_reads *
1041* *
1042*--------------------------------------------------------------------*/
1043static int
1044add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1045 struct ccwbk* p_last)
1046{
1047 struct claw_privbk *privptr;
1048 struct ccw1 temp_ccw;
1049 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001050 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001051 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 p_end = privptr->p_end_ccw;
1053
1054 /* first CCW and last CCW contains a new set of read channel programs
1055 * to apend the running channel programs
1056 */
1057 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001058 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 return 0;
1060 }
1061
1062 /* set up ending CCW sequence for this segment */
1063 if (p_end->read1) {
1064 p_end->read1=0x00; /* second ending CCW is now active */
1065 /* reset ending CCWs and setup TIC CCWs */
1066 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1067 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1068 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1069 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1070 p_end->read2_nop2.cda=0;
1071 p_end->read2_nop2.count=1;
1072 }
1073 else {
1074 p_end->read1=0x01; /* first ending CCW is now active */
1075 /* reset ending CCWs and setup TIC CCWs */
1076 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1077 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1078 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1079 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1080 p_end->read1_nop2.cda=0;
1081 p_end->read1_nop2.count=1;
1082 }
1083
1084 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001085 privptr->p_read_active_first = p_first; /* set new first */
1086 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 }
1088 else {
1089
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 /* set up TIC ccw */
1091 temp_ccw.cda= (__u32)__pa(&p_first->read);
1092 temp_ccw.count=0;
1093 temp_ccw.flags=0;
1094 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1095
1096
1097 if (p_end->read1) {
1098
1099 /* first set of CCW's is chained to the new read */
1100 /* chain, so the second set is chained to the active chain. */
1101 /* Therefore modify the second set to point to the new */
1102 /* read chain set up TIC CCWs */
1103 /* make sure we update the CCW so channel doesn't fetch it */
1104 /* when it's only half done */
1105 memcpy( &p_end->read2_nop2, &temp_ccw ,
1106 sizeof(struct ccw1));
1107 privptr->p_read_active_last->r_TIC_1.cda=
1108 (__u32)__pa(&p_first->read);
1109 privptr->p_read_active_last->r_TIC_2.cda=
1110 (__u32)__pa(&p_first->read);
1111 }
1112 else {
1113 /* make sure we update the CCW so channel doesn't */
1114 /* fetch it when it is only half done */
1115 memcpy( &p_end->read1_nop2, &temp_ccw ,
1116 sizeof(struct ccw1));
1117 privptr->p_read_active_last->r_TIC_1.cda=
1118 (__u32)__pa(&p_first->read);
1119 privptr->p_read_active_last->r_TIC_2.cda=
1120 (__u32)__pa(&p_first->read);
1121 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001122 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 privptr->p_read_active_last->next = p_first;
1124 privptr->p_read_active_last=p_last;
1125 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001126 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 return 0;
1128} /* end of add_claw_reads */
1129
1130/*-------------------------------------------------------------------*
1131 * ccw_check_return_code *
1132 * *
1133 *-------------------------------------------------------------------*/
1134
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001135static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136ccw_check_return_code(struct ccw_device *cdev, int return_code)
1137{
Andy Richterb805da72008-07-18 15:24:56 +02001138 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 if (return_code != 0) {
1140 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001141 case -EBUSY: /* BUSY is a transient state no action needed */
1142 break;
1143 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001144 dev_err(&cdev->dev, "The remote channel adapter is not"
1145 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001146 break;
1147 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001148 dev_err(&cdev->dev,
1149 "The status of the remote channel adapter"
1150 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001151 break;
1152 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001153 dev_err(&cdev->dev, "The common device layer"
1154 " returned error code %d\n",
1155 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001156 }
1157 }
1158 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159} /* end of ccw_check_return_code */
1160
1161/*-------------------------------------------------------------------*
1162* ccw_check_unit_check *
1163*--------------------------------------------------------------------*/
1164
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001165static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1167{
Andy Richterb805da72008-07-18 15:24:56 +02001168 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001169 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Andy Richterb805da72008-07-18 15:24:56 +02001171 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001172 dev_warn(dev, "The communication peer of %s disconnected\n",
1173 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001175 if (sense & 0x40) {
1176 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001177 dev_warn(dev, "The remote channel adapter for"
1178 " %s has been reset\n",
1179 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001180 }
1181 } else if (sense & 0x20) {
1182 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001183 dev_warn(dev, "A data streaming timeout occurred"
1184 " for %s\n",
1185 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001186 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001187 dev_warn(dev, "The remote channel adapter for %s"
1188 " is faulty\n",
1189 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001190 } else {
1191 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001192 " for %s\n",
1193 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001194 }
1195 } else if (sense & 0x10) {
1196 dev_warn(dev, "A read data parity error occurred"
1197 " for %s\n",
1198 ndev->name);
1199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201} /* end of ccw_check_unit_check */
1202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203/*-------------------------------------------------------------------*
1204* find_link *
1205*--------------------------------------------------------------------*/
1206static int
1207find_link(struct net_device *dev, char *host_name, char *ws_name )
1208{
1209 struct claw_privbk *privptr;
1210 struct claw_env *p_env;
1211 int rc=0;
1212
Andy Richterb805da72008-07-18 15:24:56 +02001213 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001214 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 p_env=privptr->p_env;
1216 switch (p_env->packing)
1217 {
1218 case PACKING_ASK:
1219 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1220 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1221 rc = EINVAL;
1222 break;
1223 case DO_PACKED:
1224 case PACK_SEND:
1225 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1226 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1227 rc = EINVAL;
1228 break;
1229 default:
1230 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1231 (memcmp(p_env->api_type , ws_name, 8)!=0))
1232 rc = EINVAL;
1233 break;
1234 }
1235
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001236 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237} /* end of find_link */
1238
1239/*-------------------------------------------------------------------*
1240 * claw_hw_tx *
1241 * *
1242 * *
1243 *-------------------------------------------------------------------*/
1244
1245static int
1246claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1247{
1248 int rc=0;
1249 struct claw_privbk *privptr;
1250 struct ccwbk *p_this_ccw;
1251 struct ccwbk *p_first_ccw;
1252 struct ccwbk *p_last_ccw;
1253 __u32 numBuffers;
1254 signed long len_of_data;
1255 unsigned long bytesInThisBuffer;
1256 unsigned char *pDataAddress;
1257 struct endccw *pEnd;
1258 struct ccw1 tempCCW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 struct claw_env *p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 struct clawph *pk_head;
1261 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001262
1263 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001264 privptr = (struct claw_privbk *)(dev->ml_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1267 /* scan the write queue to free any completed write packets */
1268 p_first_ccw=NULL;
1269 p_last_ccw=NULL;
1270 if ((p_env->packing >= PACK_SEND) &&
1271 (skb->cb[1] != 'P')) {
1272 skb_push(skb,sizeof(struct clawph));
1273 pk_head=(struct clawph *)skb->data;
1274 pk_head->len=skb->len-sizeof(struct clawph);
1275 if (pk_head->len%4) {
1276 pk_head->len+= 4-(pk_head->len%4);
1277 skb_pad(skb,4-(pk_head->len%4));
1278 skb_put(skb,4-(pk_head->len%4));
1279 }
1280 if (p_env->packing == DO_PACKED)
1281 pk_head->link_num = linkid;
1282 else
1283 pk_head->link_num = 0;
1284 pk_head->flag = 0x00;
1285 skb_pad(skb,4);
1286 skb->cb[1] = 'P';
1287 }
1288 if (linkid == 0) {
1289 if (claw_check_busy(dev)) {
1290 if (privptr->write_free_count!=0) {
1291 claw_clear_busy(dev);
1292 }
1293 else {
1294 claw_strt_out_IO(dev );
1295 claw_free_wrt_buf( dev );
1296 if (privptr->write_free_count==0) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00001297 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 atomic_inc(&skb->users);
1299 skb_queue_tail(&ch->collect_queue, skb);
1300 goto Done;
1301 }
1302 else {
1303 claw_clear_busy(dev);
1304 }
1305 }
1306 }
1307 /* tx lock */
1308 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001309 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 atomic_inc(&skb->users);
1311 skb_queue_tail(&ch->collect_queue, skb);
1312 claw_strt_out_IO(dev );
1313 rc=-EBUSY;
1314 goto Done2;
1315 }
1316 }
1317 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001318 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 /* If that number of buffers isn't available, give up for now */
1321 if (privptr->write_free_count < numBuffers ||
1322 privptr->p_write_free_chain == NULL ) {
1323
1324 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00001325 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 atomic_inc(&skb->users);
1327 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001328 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 goto Done2;
1330 }
1331 pDataAddress=skb->data;
1332 len_of_data=skb->len;
1333
1334 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1336 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb0832010-08-12 01:58:27 +00001337 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 atomic_inc(&skb->users);
1339 skb_queue_tail(&ch->collect_queue, skb);
1340 goto Done2;
1341 }
1342 privptr->p_write_free_chain=p_this_ccw->next;
1343 p_this_ccw->next=NULL;
1344 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001345 if (len_of_data >= privptr->p_env->write_size)
1346 bytesInThisBuffer = privptr->p_env->write_size;
1347 else
1348 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1350 len_of_data-=bytesInThisBuffer;
1351 pDataAddress+=(unsigned long)bytesInThisBuffer;
1352 /* setup write CCW */
1353 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1354 if (len_of_data>0) {
1355 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1356 }
1357 p_this_ccw->write.count=bytesInThisBuffer;
1358 /* now add to end of this chain */
1359 if (p_first_ccw==NULL) {
1360 p_first_ccw=p_this_ccw;
1361 }
1362 if (p_last_ccw!=NULL) {
1363 p_last_ccw->next=p_this_ccw;
1364 /* set up TIC ccws */
1365 p_last_ccw->w_TIC_1.cda=
1366 (__u32)__pa(&p_this_ccw->write);
1367 }
1368 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 }
1370
1371 /* FirstCCW and LastCCW now contain a new set of write channel
1372 * programs to append to the running channel program
1373 */
1374
1375 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001376 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 pEnd=privptr->p_end_ccw;
1378 if (pEnd->write1) {
1379 pEnd->write1=0x00; /* second end ccw is now active */
1380 /* set up Tic CCWs */
1381 p_last_ccw->w_TIC_1.cda=
1382 (__u32)__pa(&pEnd->write2_nop1);
1383 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1384 pEnd->write2_nop2.flags =
1385 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1386 pEnd->write2_nop2.cda=0;
1387 pEnd->write2_nop2.count=1;
1388 }
1389 else { /* end of if (pEnd->write1)*/
1390 pEnd->write1=0x01; /* first end ccw is now active */
1391 /* set up Tic CCWs */
1392 p_last_ccw->w_TIC_1.cda=
1393 (__u32)__pa(&pEnd->write1_nop1);
1394 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1395 pEnd->write1_nop2.flags =
1396 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1397 pEnd->write1_nop2.cda=0;
1398 pEnd->write1_nop2.count=1;
1399 } /* end if if (pEnd->write1) */
1400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 if (privptr->p_write_active_first==NULL ) {
1402 privptr->p_write_active_first=p_first_ccw;
1403 privptr->p_write_active_last=p_last_ccw;
1404 }
1405 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 /* set up Tic CCWs */
1407
1408 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1409 tempCCW.count=0;
1410 tempCCW.flags=0;
1411 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1412
1413 if (pEnd->write1) {
1414
1415 /*
1416 * first set of ending CCW's is chained to the new write
1417 * chain, so the second set is chained to the active chain
1418 * Therefore modify the second set to point the new write chain.
1419 * make sure we update the CCW atomically
1420 * so channel does not fetch it when it's only half done
1421 */
1422 memcpy( &pEnd->write2_nop2, &tempCCW ,
1423 sizeof(struct ccw1));
1424 privptr->p_write_active_last->w_TIC_1.cda=
1425 (__u32)__pa(&p_first_ccw->write);
1426 }
1427 else {
1428
1429 /*make sure we update the CCW atomically
1430 *so channel does not fetch it when it's only half done
1431 */
1432 memcpy(&pEnd->write1_nop2, &tempCCW ,
1433 sizeof(struct ccw1));
1434 privptr->p_write_active_last->w_TIC_1.cda=
1435 (__u32)__pa(&p_first_ccw->write);
1436
1437 } /* end if if (pEnd->write1) */
1438
1439 privptr->p_write_active_last->next=p_first_ccw;
1440 privptr->p_write_active_last=p_last_ccw;
1441 }
1442
1443 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001444 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 claw_strt_out_IO(dev );
1446 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 if (privptr->write_free_count==0) {
1448 claw_setbit_busy(TB_NOBUFFER,dev);
1449 }
1450Done2:
1451 claw_clearbit_busy(TB_TX,dev);
1452Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 return(rc);
1454} /* end of claw_hw_tx */
1455
1456/*-------------------------------------------------------------------*
1457* *
1458* init_ccw_bk *
1459* *
1460*--------------------------------------------------------------------*/
1461
1462static int
1463init_ccw_bk(struct net_device *dev)
1464{
1465
1466 __u32 ccw_blocks_required;
1467 __u32 ccw_blocks_perpage;
1468 __u32 ccw_pages_required;
1469 __u32 claw_reads_perpage=1;
1470 __u32 claw_read_pages;
1471 __u32 claw_writes_perpage=1;
1472 __u32 claw_write_pages;
1473 void *p_buff=NULL;
1474 struct ccwbk*p_free_chain;
1475 struct ccwbk*p_buf;
1476 struct ccwbk*p_last_CCWB;
1477 struct ccwbk*p_first_CCWB;
1478 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001479 addr_t real_address;
1480 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 struct clawh *pClawH=NULL;
1482 addr_t real_TIC_address;
1483 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001484 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
1486 /* initialize statistics field */
1487 privptr->active_link_ID=0;
1488 /* initialize ccwbk pointers */
1489 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1490 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1491 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1492 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1493 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1494 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1495 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1496 privptr->buffs_alloc = 0;
1497 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1498 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1499 /* initialize free write ccwbk counter */
1500 privptr->write_free_count=0; /* number of free bufs on write chain */
1501 p_last_CCWB = NULL;
1502 p_first_CCWB= NULL;
1503 /*
1504 * We need 1 CCW block for each read buffer, 1 for each
1505 * write buffer, plus 1 for ClawSignalBlock
1506 */
1507 ccw_blocks_required =
1508 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 /*
1510 * compute number of CCW blocks that will fit in a page
1511 */
1512 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1513 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001514 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /*
1517 * read and write sizes are set by 2 constants in claw.h
1518 * 4k and 32k. Unpacked values other than 4k are not going to
1519 * provide good performance. With packing buffers support 32k
1520 * buffers are used.
1521 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001522 if (privptr->p_env->read_size < PAGE_SIZE) {
1523 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1524 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1525 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 }
1527 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001528 privptr->p_buff_pages_perread =
1529 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1530 claw_read_pages = privptr->p_env->read_buffers *
1531 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 }
1533 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001534 claw_writes_perpage =
1535 PAGE_SIZE / privptr->p_env->write_size;
1536 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1537 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538
1539 }
1540 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001541 privptr->p_buff_pages_perwrite =
1542 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1543 claw_write_pages = privptr->p_env->write_buffers *
1544 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 /*
1547 * allocate ccw_pages_required
1548 */
1549 if (privptr->p_buff_ccw==NULL) {
1550 privptr->p_buff_ccw=
1551 (void *)__get_free_pages(__GFP_DMA,
1552 (int)pages_to_order_of_mag(ccw_pages_required ));
1553 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 return -ENOMEM;
1555 }
1556 privptr->p_buff_ccw_num=ccw_pages_required;
1557 }
1558 memset(privptr->p_buff_ccw, 0x00,
1559 privptr->p_buff_ccw_num * PAGE_SIZE);
1560
1561 /*
1562 * obtain ending ccw block address
1563 *
1564 */
1565 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1566 real_address = (__u32)__pa(privptr->p_end_ccw);
1567 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 p_endccw=privptr->p_end_ccw;
1569 p_endccw->real=real_address;
1570 p_endccw->write1=0x00;
1571 p_endccw->read1=0x00;
1572
1573 /* write1_nop1 */
1574 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1575 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1576 p_endccw->write1_nop1.count = 1;
1577 p_endccw->write1_nop1.cda = 0;
1578
1579 /* write1_nop2 */
1580 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1581 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1582 p_endccw->write1_nop2.count = 1;
1583 p_endccw->write1_nop2.cda = 0;
1584
1585 /* write2_nop1 */
1586 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1587 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1588 p_endccw->write2_nop1.count = 1;
1589 p_endccw->write2_nop1.cda = 0;
1590
1591 /* write2_nop2 */
1592 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1593 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1594 p_endccw->write2_nop2.count = 1;
1595 p_endccw->write2_nop2.cda = 0;
1596
1597 /* read1_nop1 */
1598 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1599 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1600 p_endccw->read1_nop1.count = 1;
1601 p_endccw->read1_nop1.cda = 0;
1602
1603 /* read1_nop2 */
1604 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1605 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1606 p_endccw->read1_nop2.count = 1;
1607 p_endccw->read1_nop2.cda = 0;
1608
1609 /* read2_nop1 */
1610 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1611 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1612 p_endccw->read2_nop1.count = 1;
1613 p_endccw->read2_nop1.cda = 0;
1614
1615 /* read2_nop2 */
1616 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1617 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1618 p_endccw->read2_nop2.count = 1;
1619 p_endccw->read2_nop2.cda = 0;
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 /*
1622 * Build a chain of CCWs
1623 *
1624 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 p_buff=privptr->p_buff_ccw;
1626
1627 p_free_chain=NULL;
1628 for (i=0 ; i < ccw_pages_required; i++ ) {
1629 real_address = (__u32)__pa(p_buff);
1630 p_buf=p_buff;
1631 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1632 p_buf->next = p_free_chain;
1633 p_free_chain = p_buf;
1634 p_buf->real=(__u32)__pa(p_buf);
1635 ++p_buf;
1636 }
1637 p_buff+=PAGE_SIZE;
1638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /*
1640 * Initialize ClawSignalBlock
1641 *
1642 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 if (privptr->p_claw_signal_blk==NULL) {
1644 privptr->p_claw_signal_blk=p_free_chain;
1645 p_free_chain=p_free_chain->next;
1646 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1647 pClawH->length=0xffff;
1648 pClawH->opcode=0xff;
1649 pClawH->flag=CLAW_BUSY;
1650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651
1652 /*
1653 * allocate write_pages_required and add to free chain
1654 */
1655 if (privptr->p_buff_write==NULL) {
1656 if (privptr->p_env->write_size < PAGE_SIZE) {
1657 privptr->p_buff_write=
1658 (void *)__get_free_pages(__GFP_DMA,
1659 (int)pages_to_order_of_mag(claw_write_pages ));
1660 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 return -ENOMEM;
1663 }
1664 /*
1665 * Build CLAW write free chain
1666 *
1667 */
1668
1669 memset(privptr->p_buff_write, 0x00,
1670 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 privptr->p_write_free_chain=NULL;
1672
1673 p_buff=privptr->p_buff_write;
1674
1675 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1676 p_buf = p_free_chain; /* get a CCW */
1677 p_free_chain = p_buf->next;
1678 p_buf->next =privptr->p_write_free_chain;
1679 privptr->p_write_free_chain = p_buf;
1680 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1681 p_buf-> write.cda = (__u32)__pa(p_buff);
1682 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1683 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1684 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1685 p_buf-> w_read_FF.count = 1;
1686 p_buf-> w_read_FF.cda =
1687 (__u32)__pa(&p_buf-> header.flag);
1688 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1689 p_buf-> w_TIC_1.flags = 0;
1690 p_buf-> w_TIC_1.count = 0;
1691
Andy Richter4811fcb2009-01-20 06:14:33 +00001692 if (((unsigned long)p_buff +
1693 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001695 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1696 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 }
1698 }
1699 }
1700 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1701 {
1702 privptr->p_write_free_chain=NULL;
1703 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1704 p_buff=(void *)__get_free_pages(__GFP_DMA,
1705 (int)pages_to_order_of_mag(
1706 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 free_pages((unsigned long)privptr->p_buff_ccw,
1709 (int)pages_to_order_of_mag(
1710 privptr->p_buff_ccw_num));
1711 privptr->p_buff_ccw=NULL;
1712 p_buf=privptr->p_buff_write;
1713 while (p_buf!=NULL) {
1714 free_pages((unsigned long)
1715 p_buf->p_buffer,
1716 (int)pages_to_order_of_mag(
1717 privptr->p_buff_pages_perwrite));
1718 p_buf=p_buf->next;
1719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 return -ENOMEM;
1721 } /* Error on get_pages */
1722 memset(p_buff, 0x00, privptr->p_env->write_size );
1723 p_buf = p_free_chain;
1724 p_free_chain = p_buf->next;
1725 p_buf->next = privptr->p_write_free_chain;
1726 privptr->p_write_free_chain = p_buf;
1727 privptr->p_buff_write = p_buf;
1728 p_buf->p_buffer=(struct clawbuf *)p_buff;
1729 p_buf-> write.cda = (__u32)__pa(p_buff);
1730 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1731 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1732 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1733 p_buf-> w_read_FF.count = 1;
1734 p_buf-> w_read_FF.cda =
1735 (__u32)__pa(&p_buf-> header.flag);
1736 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1737 p_buf-> w_TIC_1.flags = 0;
1738 p_buf-> w_TIC_1.count = 0;
1739 } /* for all write_buffers */
1740
1741 } /* else buffers are PAGE_SIZE or bigger */
1742
1743 }
1744 privptr->p_buff_write_num=claw_write_pages;
1745 privptr->write_free_count=privptr->p_env->write_buffers;
1746
1747
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 /*
1749 * allocate read_pages_required and chain to free chain
1750 */
1751 if (privptr->p_buff_read==NULL) {
1752 if (privptr->p_env->read_size < PAGE_SIZE) {
1753 privptr->p_buff_read=
1754 (void *)__get_free_pages(__GFP_DMA,
1755 (int)pages_to_order_of_mag(claw_read_pages) );
1756 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 free_pages((unsigned long)privptr->p_buff_ccw,
1758 (int)pages_to_order_of_mag(
1759 privptr->p_buff_ccw_num));
1760 /* free the write pages size is < page size */
1761 free_pages((unsigned long)privptr->p_buff_write,
1762 (int)pages_to_order_of_mag(
1763 privptr->p_buff_write_num));
1764 privptr->p_buff_ccw=NULL;
1765 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 return -ENOMEM;
1767 }
1768 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1769 privptr->p_buff_read_num=claw_read_pages;
1770 /*
1771 * Build CLAW read free chain
1772 *
1773 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 p_buff=privptr->p_buff_read;
1775 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1776 p_buf = p_free_chain;
1777 p_free_chain = p_buf->next;
1778
1779 if (p_last_CCWB==NULL) {
1780 p_buf->next=NULL;
1781 real_TIC_address=0;
1782 p_last_CCWB=p_buf;
1783 }
1784 else {
1785 p_buf->next=p_first_CCWB;
1786 real_TIC_address=
1787 (__u32)__pa(&p_first_CCWB -> read );
1788 }
1789
1790 p_first_CCWB=p_buf;
1791
1792 p_buf->p_buffer=(struct clawbuf *)p_buff;
1793 /* initialize read command */
1794 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1795 p_buf-> read.cda = (__u32)__pa(p_buff);
1796 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1797 p_buf-> read.count = privptr->p_env->read_size;
1798
1799 /* initialize read_h command */
1800 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1801 p_buf-> read_h.cda =
1802 (__u32)__pa(&(p_buf->header));
1803 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1804 p_buf-> read_h.count = sizeof(struct clawh);
1805
1806 /* initialize Signal command */
1807 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1808 p_buf-> signal.cda =
1809 (__u32)__pa(&(pClawH->flag));
1810 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1811 p_buf-> signal.count = 1;
1812
1813 /* initialize r_TIC_1 command */
1814 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1815 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1816 p_buf-> r_TIC_1.flags = 0;
1817 p_buf-> r_TIC_1.count = 0;
1818
1819 /* initialize r_read_FF command */
1820 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1821 p_buf-> r_read_FF.cda =
1822 (__u32)__pa(&(pClawH->flag));
1823 p_buf-> r_read_FF.flags =
1824 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1825 p_buf-> r_read_FF.count = 1;
1826
1827 /* initialize r_TIC_2 */
1828 memcpy(&p_buf->r_TIC_2,
1829 &p_buf->r_TIC_1, sizeof(struct ccw1));
1830
1831 /* initialize Header */
1832 p_buf->header.length=0xffff;
1833 p_buf->header.opcode=0xff;
1834 p_buf->header.flag=CLAW_PENDING;
1835
Andy Richter4811fcb2009-01-20 06:14:33 +00001836 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1837 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1838 -1)
1839 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 p_buff= p_buff+privptr->p_env->read_size;
1841 }
1842 else {
1843 p_buff=
1844 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001845 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 & PAGE_MASK) ;
1847 }
1848 } /* for read_buffers */
1849 } /* read_size < PAGE_SIZE */
1850 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1852 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001853 (int)pages_to_order_of_mag(
1854 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001857 (int)pages_to_order_of_mag(privptr->
1858 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 /* free the write pages */
1860 p_buf=privptr->p_buff_write;
1861 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001862 free_pages(
1863 (unsigned long)p_buf->p_buffer,
1864 (int)pages_to_order_of_mag(
1865 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 p_buf=p_buf->next;
1867 }
1868 /* free any read pages already alloc */
1869 p_buf=privptr->p_buff_read;
1870 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001871 free_pages(
1872 (unsigned long)p_buf->p_buffer,
1873 (int)pages_to_order_of_mag(
1874 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 p_buf=p_buf->next;
1876 }
1877 privptr->p_buff_ccw=NULL;
1878 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 return -ENOMEM;
1880 }
1881 memset(p_buff, 0x00, privptr->p_env->read_size);
1882 p_buf = p_free_chain;
1883 privptr->p_buff_read = p_buf;
1884 p_free_chain = p_buf->next;
1885
1886 if (p_last_CCWB==NULL) {
1887 p_buf->next=NULL;
1888 real_TIC_address=0;
1889 p_last_CCWB=p_buf;
1890 }
1891 else {
1892 p_buf->next=p_first_CCWB;
1893 real_TIC_address=
1894 (addr_t)__pa(
1895 &p_first_CCWB -> read );
1896 }
1897
1898 p_first_CCWB=p_buf;
1899 /* save buff address */
1900 p_buf->p_buffer=(struct clawbuf *)p_buff;
1901 /* initialize read command */
1902 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1903 p_buf-> read.cda = (__u32)__pa(p_buff);
1904 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1905 p_buf-> read.count = privptr->p_env->read_size;
1906
1907 /* initialize read_h command */
1908 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1909 p_buf-> read_h.cda =
1910 (__u32)__pa(&(p_buf->header));
1911 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1912 p_buf-> read_h.count = sizeof(struct clawh);
1913
1914 /* initialize Signal command */
1915 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1916 p_buf-> signal.cda =
1917 (__u32)__pa(&(pClawH->flag));
1918 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1919 p_buf-> signal.count = 1;
1920
1921 /* initialize r_TIC_1 command */
1922 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1923 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1924 p_buf-> r_TIC_1.flags = 0;
1925 p_buf-> r_TIC_1.count = 0;
1926
1927 /* initialize r_read_FF command */
1928 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1929 p_buf-> r_read_FF.cda =
1930 (__u32)__pa(&(pClawH->flag));
1931 p_buf-> r_read_FF.flags =
1932 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1933 p_buf-> r_read_FF.count = 1;
1934
1935 /* initialize r_TIC_2 */
1936 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1937 sizeof(struct ccw1));
1938
1939 /* initialize Header */
1940 p_buf->header.length=0xffff;
1941 p_buf->header.opcode=0xff;
1942 p_buf->header.flag=CLAW_PENDING;
1943
1944 } /* For read_buffers */
1945 } /* read_size >= PAGE_SIZE */
1946 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
1948 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02001949
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 return 0;
1951} /* end of init_ccw_bk */
1952
1953/*-------------------------------------------------------------------*
1954* *
1955* probe_error *
1956* *
1957*--------------------------------------------------------------------*/
1958
1959static void
1960probe_error( struct ccwgroup_device *cgdev)
1961{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001962 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02001963
1964 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001965 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001966 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07001967 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08001968 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02001969 kfree(privptr->p_mtc_envelope);
1970 kfree(privptr);
1971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972} /* probe_error */
1973
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974/*-------------------------------------------------------------------*
1975* claw_process_control *
1976* *
1977* *
1978*--------------------------------------------------------------------*/
1979
1980static int
1981claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
1982{
1983
1984 struct clawbuf *p_buf;
1985 struct clawctl ctlbk;
1986 struct clawctl *p_ctlbk;
1987 char temp_host_name[8];
1988 char temp_ws_name[8];
1989 struct claw_privbk *privptr;
1990 struct claw_env *p_env;
1991 struct sysval *p_sysval;
1992 struct conncmd *p_connect=NULL;
1993 int rc;
1994 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02001995 struct device *tdev;
1996 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 udelay(1000); /* Wait a ms for the control packets to
1998 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02001999 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 p_env=privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002001 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 memcpy( &temp_host_name, p_env->host_name, 8);
2003 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002004 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 "Received Control Packet\n",
2006 dev->name, temp_ws_name);
2007 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 return 0;
2009 }
2010 p_buf=p_ccw->p_buffer;
2011 p_ctlbk=&ctlbk;
2012 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2013 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2014 } else {
2015 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 switch (p_ctlbk->command)
2018 {
Andy Richterb805da72008-07-18 15:24:56 +02002019 case SYSTEM_VALIDATE_REQUEST:
2020 if (p_ctlbk->version != CLAW_VERSION_ID) {
2021 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2022 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002023 dev_warn(tdev, "The communication peer of %s"
2024 " uses an incorrect API version %d\n",
2025 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002026 }
2027 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002028 dev_info(tdev, "%s: Recv Sys Validate Request: "
2029 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2030 "Host name=%.8s\n",
2031 dev->name, p_ctlbk->version,
2032 p_ctlbk->linkid,
2033 p_ctlbk->correlator,
2034 p_sysval->WS_name,
2035 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002036 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2037 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2038 CLAW_RC_NAME_MISMATCH);
2039 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2040 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2041 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002042 dev_warn(tdev,
2043 "Host name %s for %s does not match the"
2044 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002045 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002046 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002047 temp_host_name);
2048 }
2049 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2050 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2051 CLAW_RC_NAME_MISMATCH);
2052 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2053 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2054 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002055 dev_warn(tdev, "Adapter name %s for %s does not match"
2056 " the remote host name %s\n",
2057 p_sysval->WS_name,
2058 dev->name,
2059 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002060 }
2061 if ((p_sysval->write_frame_size < p_env->write_size) &&
2062 (p_env->packing == 0)) {
2063 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2064 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002065 dev_warn(tdev,
2066 "The local write buffer is smaller than the"
2067 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002068 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2069 }
2070 if ((p_sysval->read_frame_size < p_env->read_size) &&
2071 (p_env->packing == 0)) {
2072 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2073 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002074 dev_warn(tdev,
2075 "The local read buffer is smaller than the"
2076 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002077 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2078 }
2079 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002080 dev_info(tdev,
2081 "CLAW device %.8s: System validate"
2082 " completed.\n", temp_ws_name);
2083 dev_info(tdev,
2084 "%s: sys Validate Rsize:%d Wsize:%d\n",
2085 dev->name, p_sysval->read_frame_size,
2086 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002087 privptr->system_validate_comp = 1;
2088 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2089 p_env->packing = PACKING_ASK;
2090 claw_strt_conn_req(dev);
2091 break;
2092 case SYSTEM_VALIDATE_RESPONSE:
2093 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002094 dev_info(tdev,
2095 "Settings for %s validated (version=%d, "
2096 "remote device=%d, rc=%d, adapter name=%.8s, "
2097 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002098 dev->name,
2099 p_ctlbk->version,
2100 p_ctlbk->correlator,
2101 p_ctlbk->rc,
2102 p_sysval->WS_name,
2103 p_sysval->host_name);
2104 switch (p_ctlbk->rc) {
2105 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002106 dev_info(tdev, "%s: CLAW device "
2107 "%.8s: System validate completed.\n",
2108 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002109 if (privptr->system_validate_comp == 0)
2110 claw_strt_conn_req(dev);
2111 privptr->system_validate_comp = 1;
2112 break;
2113 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002114 dev_warn(tdev, "Validating %s failed because of"
2115 " a host or adapter name mismatch\n",
2116 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002117 break;
2118 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002119 dev_warn(tdev, "Validating %s failed because of a"
2120 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002121 dev->name);
2122 break;
2123 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002124 dev_warn(tdev, "Validating %s failed because of a"
2125 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002126 dev->name);
2127 break;
2128 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002129 dev_warn(tdev, "The communication peer of %s rejected"
2130 " the connection\n",
2131 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002132 break;
2133 }
2134 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
Andy Richterb805da72008-07-18 15:24:56 +02002136 case CONNECTION_REQUEST:
2137 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002138 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002139 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2140 dev->name,
2141 p_ctlbk->version,
2142 p_ctlbk->linkid,
2143 p_ctlbk->correlator,
2144 p_connect->host_name,
2145 p_connect->WS_name);
2146 if (privptr->active_link_ID != 0) {
2147 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002148 dev_info(tdev, "%s rejected a connection request"
2149 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002150 dev->name);
2151 }
2152 if (p_ctlbk->linkid != 1) {
2153 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002154 dev_info(tdev, "%s rejected a request to open multiple"
2155 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002156 dev->name);
2157 }
2158 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2159 if (rc != 0) {
2160 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002161 dev_info(tdev, "%s rejected a connection request"
2162 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002163 dev->name);
2164 }
2165 claw_send_control(dev,
2166 CONNECTION_CONFIRM, p_ctlbk->linkid,
2167 p_ctlbk->correlator,
2168 0, p_connect->host_name,
2169 p_connect->WS_name);
2170 if (p_env->packing == PACKING_ASK) {
2171 p_env->packing = PACK_SEND;
2172 claw_snd_conn_req(dev, 0);
2173 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002174 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002175 "completed link_id=%d.\n",
2176 dev->name, temp_ws_name,
2177 p_ctlbk->linkid);
2178 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002179 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002180 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2181 break;
2182 case CONNECTION_RESPONSE:
2183 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002184 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002185 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2186 dev->name,
2187 p_ctlbk->version,
2188 p_ctlbk->linkid,
2189 p_ctlbk->correlator,
2190 p_ctlbk->rc,
2191 p_connect->host_name,
2192 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193
Andy Richterb805da72008-07-18 15:24:56 +02002194 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002195 dev_warn(tdev, "The communication peer of %s rejected"
2196 " a connection request\n",
2197 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002198 return 1;
2199 }
2200 rc = find_link(dev,
2201 p_connect->host_name, p_connect->WS_name);
2202 if (rc != 0) {
2203 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002204 dev_warn(tdev, "The communication peer of %s"
2205 " rejected a connection "
2206 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002207 dev->name);
2208 }
2209 /* should be until CONNECTION_CONFIRM */
2210 privptr->active_link_ID = -(p_ctlbk->linkid);
2211 break;
2212 case CONNECTION_CONFIRM:
2213 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002214 dev_info(tdev,
2215 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002216 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2217 dev->name,
2218 p_ctlbk->version,
2219 p_ctlbk->linkid,
2220 p_ctlbk->correlator,
2221 p_connect->host_name,
2222 p_connect->WS_name);
2223 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2224 privptr->active_link_ID = p_ctlbk->linkid;
2225 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002226 dev_info(tdev,
2227 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 p_env->packing = DO_PACKED;
2229 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002230 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002231 wake_up(&p_ch->wait);
2232 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002233 dev_warn(tdev, "Activating %s failed because of"
2234 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002235 dev->name, p_ctlbk->linkid);
2236 claw_snd_disc(dev, p_ctlbk);
2237 }
2238 break;
2239 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002240 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002241 "Vers=%d,link_id=%d,Corr=%d\n",
2242 dev->name, p_ctlbk->version,
2243 p_ctlbk->linkid, p_ctlbk->correlator);
2244 if ((p_ctlbk->linkid == 2) &&
2245 (p_env->packing == PACK_SEND)) {
2246 privptr->active_link_ID = 1;
2247 p_env->packing = DO_PACKED;
2248 } else
2249 privptr->active_link_ID = 0;
2250 break;
2251 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002252 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002253 dev->name);
2254 break;
2255 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002256 dev_warn(tdev, "The communication peer of %s sent"
2257 " an unknown command code\n",
2258 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002259 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 }
2261
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 return 0;
2263} /* end of claw_process_control */
2264
2265
2266/*-------------------------------------------------------------------*
2267* claw_send_control *
2268* *
2269*--------------------------------------------------------------------*/
2270
2271static int
2272claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2273 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2274{
2275 struct claw_privbk *privptr;
2276 struct clawctl *p_ctl;
2277 struct sysval *p_sysval;
2278 struct conncmd *p_connect;
2279 struct sk_buff *skb;
2280
Andy Richterb805da72008-07-18 15:24:56 +02002281 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002282 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2284
2285 p_ctl->command=type;
2286 p_ctl->version=CLAW_VERSION_ID;
2287 p_ctl->linkid=link;
2288 p_ctl->correlator=correlator;
2289 p_ctl->rc=rc;
2290
2291 p_sysval=(struct sysval *)&p_ctl->data;
2292 p_connect=(struct conncmd *)&p_ctl->data;
2293
2294 switch (p_ctl->command) {
2295 case SYSTEM_VALIDATE_REQUEST:
2296 case SYSTEM_VALIDATE_RESPONSE:
2297 memcpy(&p_sysval->host_name, local_name, 8);
2298 memcpy(&p_sysval->WS_name, remote_name, 8);
2299 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002300 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2301 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002303 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002304 p_sysval->read_frame_size =
2305 privptr->p_env->read_size;
2306 p_sysval->write_frame_size =
2307 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 }
2309 memset(&p_sysval->reserved, 0x00, 4);
2310 break;
2311 case CONNECTION_REQUEST:
2312 case CONNECTION_RESPONSE:
2313 case CONNECTION_CONFIRM:
2314 case DISCONNECT:
2315 memcpy(&p_sysval->host_name, local_name, 8);
2316 memcpy(&p_sysval->WS_name, remote_name, 8);
2317 if (privptr->p_env->packing > 0) {
2318 /* How big is the biggest packet */
2319 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2320 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2321 } else {
2322 memset(&p_connect->reserved1, 0x00, 4);
2323 memset(&p_connect->reserved2, 0x00, 4);
2324 }
2325 break;
2326 default:
2327 break;
2328 }
2329
2330 /* write Control Record to the device */
2331
2332
2333 skb = dev_alloc_skb(sizeof(struct clawctl));
2334 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 return -ENOMEM;
2336 }
2337 memcpy(skb_put(skb, sizeof(struct clawctl)),
2338 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (privptr->p_env->packing >= PACK_SEND)
2340 claw_hw_tx(skb, dev, 1);
2341 else
2342 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 return 0;
2344} /* end of claw_send_control */
2345
2346/*-------------------------------------------------------------------*
2347* claw_snd_conn_req *
2348* *
2349*--------------------------------------------------------------------*/
2350static int
2351claw_snd_conn_req(struct net_device *dev, __u8 link)
2352{
2353 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002354 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 struct clawctl *p_ctl;
2356
Andy Richterb805da72008-07-18 15:24:56 +02002357 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 rc = 1;
2359 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2360 p_ctl->linkid = link;
2361 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 return rc;
2363 }
2364 if (privptr->p_env->packing == PACKING_ASK )
2365 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2366 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2367 if (privptr->p_env->packing == PACK_SEND) {
2368 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2369 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2370 }
2371 if (privptr->p_env->packing == 0)
2372 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2373 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 return rc;
2375
2376} /* end of claw_snd_conn_req */
2377
2378
2379/*-------------------------------------------------------------------*
2380* claw_snd_disc *
2381* *
2382*--------------------------------------------------------------------*/
2383
2384static int
2385claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2386{
2387 int rc;
2388 struct conncmd * p_connect;
2389
Andy Richterb805da72008-07-18 15:24:56 +02002390 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 p_connect=(struct conncmd *)&p_ctl->data;
2392
2393 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2394 p_ctl->correlator, 0,
2395 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 return rc;
2397} /* end of claw_snd_disc */
2398
2399
2400/*-------------------------------------------------------------------*
2401* claw_snd_sys_validate_rsp *
2402* *
2403*--------------------------------------------------------------------*/
2404
2405static int
2406claw_snd_sys_validate_rsp(struct net_device *dev,
2407 struct clawctl *p_ctl, __u32 return_code)
2408{
2409 struct claw_env * p_env;
2410 struct claw_privbk *privptr;
2411 int rc;
2412
Andy Richterb805da72008-07-18 15:24:56 +02002413 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002414 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 p_env=privptr->p_env;
2416 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2417 p_ctl->linkid,
2418 p_ctl->correlator,
2419 return_code,
2420 p_env->host_name,
2421 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 return rc;
2423} /* end of claw_snd_sys_validate_rsp */
2424
2425/*-------------------------------------------------------------------*
2426* claw_strt_conn_req *
2427* *
2428*--------------------------------------------------------------------*/
2429
2430static int
2431claw_strt_conn_req(struct net_device *dev )
2432{
2433 int rc;
2434
Andy Richterb805da72008-07-18 15:24:56 +02002435 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 return rc;
2438} /* end of claw_strt_conn_req */
2439
2440
2441
2442/*-------------------------------------------------------------------*
2443 * claw_stats *
2444 *-------------------------------------------------------------------*/
2445
2446static struct
2447net_device_stats *claw_stats(struct net_device *dev)
2448{
2449 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002450
2451 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002452 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 return &privptr->stats;
2454} /* end of claw_stats */
2455
2456
2457/*-------------------------------------------------------------------*
2458* unpack_read *
2459* *
2460*--------------------------------------------------------------------*/
2461static void
2462unpack_read(struct net_device *dev )
2463{
2464 struct sk_buff *skb;
2465 struct claw_privbk *privptr;
2466 struct claw_env *p_env;
2467 struct ccwbk *p_this_ccw;
2468 struct ccwbk *p_first_ccw;
2469 struct ccwbk *p_last_ccw;
2470 struct clawph *p_packh;
2471 void *p_packd;
2472 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002473 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 __u32 len_of_data;
2476 __u32 pack_off;
2477 __u8 link_num;
2478 __u8 mtc_this_frm=0;
2479 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 int i=0;
2481 int p=0;
2482
Andy Richterb805da72008-07-18 15:24:56 +02002483 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 p_first_ccw=NULL;
2485 p_last_ccw=NULL;
2486 p_packh=NULL;
2487 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002488 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002489
Heiko Carstens319cb0832010-08-12 01:58:27 +00002490 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 p_env = privptr->p_env;
2492 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 pack_off = 0;
2495 p = 0;
2496 p_this_ccw->header.flag=CLAW_PENDING;
2497 privptr->p_read_active_first=p_this_ccw->next;
2498 p_this_ccw->next=NULL;
2499 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2500 if ((p_env->packing == PACK_SEND) &&
2501 (p_packh->len == 32) &&
2502 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2503 p_packh++; /* peek past pack header */
2504 p_ctlrec = (struct clawctl *)p_packh;
2505 p_packh--; /* un peek */
2506 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2507 (p_ctlrec->command == CONNECTION_CONFIRM))
2508 p_env->packing = DO_PACKED;
2509 }
2510 if (p_env->packing == DO_PACKED)
2511 link_num=p_packh->link_num;
2512 else
2513 link_num=p_this_ccw->header.opcode / 8;
2514 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 mtc_this_frm=1;
2516 if (p_this_ccw->header.length!=
2517 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002518 dev_warn(p_dev,
2519 "The communication peer of %s"
2520 " sent a faulty"
2521 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 dev->name, p_this_ccw->header.length);
2523 }
2524 }
2525
2526 if (privptr->mtc_skipping) {
2527 /*
2528 * We're in the mode of skipping past a
2529 * multi-frame message
2530 * that we can't process for some reason or other.
2531 * The first frame without the More-To-Come flag is
2532 * the last frame of the skipped message.
2533 */
2534 /* in case of More-To-Come not set in this frame */
2535 if (mtc_this_frm==0) {
2536 privptr->mtc_skipping=0; /* Ok, the end */
2537 privptr->mtc_logical_link=-1;
2538 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 goto NextFrame;
2540 }
2541
2542 if (link_num==0) {
2543 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002544 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 goto NextFrame;
2546 }
2547unpack_next:
2548 if (p_env->packing == DO_PACKED) {
2549 if (pack_off > p_env->read_size)
2550 goto NextFrame;
2551 p_packd = p_this_ccw->p_buffer+pack_off;
2552 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002553 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 (p_packh->flag != 0))
2555 goto NextFrame;
2556 bytes_to_mov = p_packh->len;
2557 pack_off += bytes_to_mov+sizeof(struct clawph);
2558 p++;
2559 } else {
2560 bytes_to_mov=p_this_ccw->header.length;
2561 }
2562 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564 /*
2565 * if More-To-Come is set in this frame then we don't know
2566 * length of entire message, and hence have to allocate
2567 * large buffer */
2568
2569 /* We are starting a new envelope */
2570 privptr->mtc_offset=0;
2571 privptr->mtc_logical_link=link_num;
2572 }
2573
2574 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2575 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 privptr->stats.rx_frame_errors++;
2577 goto NextFrame;
2578 }
2579 if (p_env->packing == DO_PACKED) {
2580 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2581 p_packd+sizeof(struct clawph), bytes_to_mov);
2582
2583 } else {
2584 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2585 p_this_ccw->p_buffer, bytes_to_mov);
2586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587 if (mtc_this_frm==0) {
2588 len_of_data=privptr->mtc_offset+bytes_to_mov;
2589 skb=dev_alloc_skb(len_of_data);
2590 if (skb) {
2591 memcpy(skb_put(skb,len_of_data),
2592 privptr->p_mtc_envelope,
2593 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002595 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 skb->protocol=htons(ETH_P_IP);
2597 skb->ip_summed=CHECKSUM_UNNECESSARY;
2598 privptr->stats.rx_packets++;
2599 privptr->stats.rx_bytes+=len_of_data;
2600 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002603 dev_info(p_dev, "Allocating a buffer for"
2604 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 }
2607 privptr->mtc_offset=0;
2608 privptr->mtc_logical_link=-1;
2609 }
2610 else {
2611 privptr->mtc_offset+=bytes_to_mov;
2612 }
2613 if (p_env->packing == DO_PACKED)
2614 goto unpack_next;
2615NextFrame:
2616 /*
2617 * Remove ThisCCWblock from active read queue, and add it
2618 * to queue of free blocks to be reused.
2619 */
2620 i++;
2621 p_this_ccw->header.length=0xffff;
2622 p_this_ccw->header.opcode=0xff;
2623 /*
2624 * add this one to the free queue for later reuse
2625 */
2626 if (p_first_ccw==NULL) {
2627 p_first_ccw = p_this_ccw;
2628 }
2629 else {
2630 p_last_ccw->next = p_this_ccw;
2631 }
2632 p_last_ccw = p_this_ccw;
2633 /*
2634 * chain to next block on active read queue
2635 */
2636 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002637 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 } /* end of while */
2639
2640 /* check validity */
2641
Andy Richterb805da72008-07-18 15:24:56 +02002642 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 return;
2646} /* end of unpack_read */
2647
2648/*-------------------------------------------------------------------*
2649* claw_strt_read *
2650* *
2651*--------------------------------------------------------------------*/
2652static void
2653claw_strt_read (struct net_device *dev, int lock )
2654{
2655 int rc = 0;
2656 __u32 parm;
2657 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002658 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 struct ccwbk*p_ccwbk;
2660 struct chbk *p_ch;
2661 struct clawh *p_clawh;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002662 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Andy Richterb805da72008-07-18 15:24:56 +02002664 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2666 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2667
2668 if ((privptr->p_write_active_first!=NULL &&
2669 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2670 (privptr->p_read_active_first!=NULL &&
2671 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2672 p_clawh->flag=CLAW_BUSY; /* 0xff */
2673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 if (lock==LOCK_YES) {
2675 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2676 }
2677 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002678 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 p_ccwbk=privptr->p_read_active_first;
2680 parm = (unsigned long) p_ch;
2681 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2682 0xff, 0);
2683 if (rc != 0) {
2684 ccw_check_return_code(p_ch->cdev, rc);
2685 }
2686 }
2687 else {
Andy Richterb805da72008-07-18 15:24:56 +02002688 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 }
2690
2691 if (lock==LOCK_YES) {
2692 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2693 }
Andy Richterb805da72008-07-18 15:24:56 +02002694 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 return;
2696} /* end of claw_strt_read */
2697
2698/*-------------------------------------------------------------------*
2699* claw_strt_out_IO *
2700* *
2701*--------------------------------------------------------------------*/
2702
2703static void
2704claw_strt_out_IO( struct net_device *dev )
2705{
2706 int rc = 0;
2707 unsigned long parm;
2708 struct claw_privbk *privptr;
2709 struct chbk *p_ch;
2710 struct ccwbk *p_first_ccw;
2711
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 if (!dev) {
2713 return;
2714 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002715 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002716 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
Andy Richterb805da72008-07-18 15:24:56 +02002718 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 p_first_ccw=privptr->p_write_active_first;
2720
2721 if (p_ch->claw_state == CLAW_STOP)
2722 return;
2723 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 return;
2725 }
2726 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2727 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002728 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002729 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2730 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 if (rc != 0) {
2732 ccw_check_return_code(p_ch->cdev, rc);
2733 }
2734 }
2735 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 return;
2737} /* end of claw_strt_out_IO */
2738
2739/*-------------------------------------------------------------------*
2740* Free write buffers *
2741* *
2742*--------------------------------------------------------------------*/
2743
2744static void
2745claw_free_wrt_buf( struct net_device *dev )
2746{
2747
Peter Tiedemann6951df32008-08-21 17:10:23 +02002748 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 struct ccwbk*p_this_ccw;
2750 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002751
2752 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 /* scan the write queue to free any completed write packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 p_this_ccw=privptr->p_write_active_first;
2755 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2756 {
2757 p_next_ccw = p_this_ccw->next;
2758 if (((p_next_ccw!=NULL) &&
2759 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2760 ((p_this_ccw == privptr->p_write_active_last) &&
2761 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2762 /* The next CCW is OK or this is */
2763 /* the last CCW...free it @A1A */
2764 privptr->p_write_active_first=p_this_ccw->next;
2765 p_this_ccw->header.flag=CLAW_PENDING;
2766 p_this_ccw->next=privptr->p_write_free_chain;
2767 privptr->p_write_free_chain=p_this_ccw;
2768 ++privptr->write_free_count;
2769 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2770 p_this_ccw=privptr->p_write_active_first;
2771 privptr->stats.tx_packets++;
2772 }
2773 else {
2774 break;
2775 }
2776 }
2777 if (privptr->write_free_count!=0) {
2778 claw_clearbit_busy(TB_NOBUFFER,dev);
2779 }
2780 /* whole chain removed? */
2781 if (privptr->p_write_active_first==NULL) {
2782 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 }
Andy Richterb805da72008-07-18 15:24:56 +02002784 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 return;
2786}
2787
2788/*-------------------------------------------------------------------*
2789* claw free netdevice *
2790* *
2791*--------------------------------------------------------------------*/
2792static void
2793claw_free_netdevice(struct net_device * dev, int free_dev)
2794{
2795 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
Andy Richterb805da72008-07-18 15:24:56 +02002797 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 if (!dev)
2799 return;
Andy Richterb805da72008-07-18 15:24:56 +02002800 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002801 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 if (dev->flags & IFF_RUNNING)
2803 claw_release(dev);
2804 if (privptr) {
Heiko Carstens319cb0832010-08-12 01:58:27 +00002805 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002807 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808#ifdef MODULE
2809 if (free_dev) {
2810 free_netdev(dev);
2811 }
2812#endif
Andy Richterb805da72008-07-18 15:24:56 +02002813 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814}
2815
2816/**
2817 * Claw init netdevice
2818 * Initialize everything of the net device except the name and the
2819 * channel structs.
2820 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002821static const struct net_device_ops claw_netdev_ops = {
2822 .ndo_open = claw_open,
2823 .ndo_stop = claw_release,
2824 .ndo_get_stats = claw_stats,
2825 .ndo_start_xmit = claw_tx,
2826 .ndo_change_mtu = claw_change_mtu,
2827};
2828
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829static void
2830claw_init_netdevice(struct net_device * dev)
2831{
Andy Richterb805da72008-07-18 15:24:56 +02002832 CLAW_DBF_TEXT(2, setup, "init_dev");
2833 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 dev->hard_header_len = 0;
2836 dev->addr_len = 0;
2837 dev->type = ARPHRD_SLIP;
2838 dev->tx_queue_len = 1300;
2839 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002840 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002841 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 return;
2843}
2844
2845/**
2846 * Init a new channel in the privptr->channel[i].
2847 *
2848 * @param cdev The ccw_device to be added.
2849 *
2850 * @return 0 on success, !0 on error.
2851 */
2852static int
2853add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2854{
2855 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002856 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857
Kay Sievers2a0217d2008-10-10 21:33:09 +02002858 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2860 p_ch = &privptr->channel[i];
2861 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002862 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002863 ccw_device_get_id(cdev, &dev_id);
2864 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002865 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 return -ENOMEM;
2867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 return 0;
2869}
2870
2871
2872/**
2873 *
2874 * Setup an interface.
2875 *
2876 * @param cgdev Device to be setup.
2877 *
2878 * @returns 0 on success, !0 on failure.
2879 */
2880static int
2881claw_new_device(struct ccwgroup_device *cgdev)
2882{
2883 struct claw_privbk *privptr;
2884 struct claw_env *p_env;
2885 struct net_device *dev;
2886 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002887 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
Andy Richter4811fcb2009-01-20 06:14:33 +00002889 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb0832010-08-12 01:58:27 +00002890 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002891 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002892 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002893 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2894 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 if (!privptr)
2896 return -ENODEV;
2897 p_env = privptr->p_env;
Heiko Carstens319cb0832010-08-12 01:58:27 +00002898 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2899 p_env->devno[READ_CHANNEL] = dev_id.devno;
2900 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2901 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 ret = add_channel(cgdev->cdev[0],0,privptr);
2903 if (ret == 0)
2904 ret = add_channel(cgdev->cdev[1],1,privptr);
2905 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002906 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2907 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002908 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002910 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002912 dev_warn(&cgdev->dev,
2913 "Setting the read subchannel online"
2914 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 goto out;
2916 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002917 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002919 dev_warn(&cgdev->dev,
2920 "Setting the write subchannel online "
2921 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 goto out;
2923 }
2924 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2925 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002926 dev_warn(&cgdev->dev,
2927 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 goto out;
2929 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002930 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002931 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb0832010-08-12 01:58:27 +00002932 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2933 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 /* sysfs magic */
2935 SET_NETDEV_DEV(dev, &cgdev->dev);
2936 if (register_netdev(dev) != 0) {
2937 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02002938 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 goto out;
2940 }
2941 dev->flags &=~IFF_RUNNING;
2942 if (privptr->buffs_alloc == 0) {
2943 ret=init_ccw_bk(dev);
2944 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 unregister_netdev(dev);
2946 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02002947 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 goto out;
2949 }
2950 }
Heiko Carstens319cb0832010-08-12 01:58:27 +00002951 privptr->channel[READ_CHANNEL].ndev = dev;
2952 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 privptr->p_env->ndev = dev;
2954
Andy Richter4811fcb2009-01-20 06:14:33 +00002955 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
2957 dev->name, p_env->read_size,
2958 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb0832010-08-12 01:58:27 +00002959 p_env->write_buffers, p_env->devno[READ_CHANNEL],
2960 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00002961 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 ":%.8s api_type: %.8s\n",
2963 dev->name, p_env->host_name,
2964 p_env->adapter_name , p_env->api_type);
2965 return 0;
2966out:
2967 ccw_device_set_offline(cgdev->cdev[1]);
2968 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 return -ENODEV;
2970}
2971
2972static void
2973claw_purge_skb_queue(struct sk_buff_head *q)
2974{
2975 struct sk_buff *skb;
2976
Andy Richterb805da72008-07-18 15:24:56 +02002977 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 while ((skb = skb_dequeue(q))) {
2979 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02002980 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 }
2982}
2983
2984/**
2985 * Shutdown an interface.
2986 *
2987 * @param cgdev Device to be shut down.
2988 *
2989 * @returns 0 on success, !0 on failure.
2990 */
2991static int
2992claw_shutdown_device(struct ccwgroup_device *cgdev)
2993{
2994 struct claw_privbk *priv;
2995 struct net_device *ndev;
Heiko Carstens38ed18f2011-05-12 18:45:04 +00002996 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02002998 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002999 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 if (!priv)
3001 return -ENODEV;
Heiko Carstens319cb0832010-08-12 01:58:27 +00003002 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 if (ndev) {
3004 /* Close the device */
Heiko Carstens319cb0832010-08-12 01:58:27 +00003005 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003006 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 if (ndev->flags & IFF_RUNNING)
3008 ret = claw_release(ndev);
3009 ndev->flags &=~IFF_RUNNING;
3010 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003011 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003013 priv->channel[READ_CHANNEL].ndev = NULL;
3014 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 priv->p_env->ndev = NULL;
3016 }
3017 ccw_device_set_offline(cgdev->cdev[1]);
3018 ccw_device_set_offline(cgdev->cdev[0]);
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003019 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020}
3021
3022static void
3023claw_remove_device(struct ccwgroup_device *cgdev)
3024{
3025 struct claw_privbk *priv;
3026
Andy Richterb805da72008-07-18 15:24:56 +02003027 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003028 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003029 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003030 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003031 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 if (cgdev->state == CCWGROUP_ONLINE)
3033 claw_shutdown_device(cgdev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003034 kfree(priv->p_mtc_envelope);
3035 priv->p_mtc_envelope=NULL;
3036 kfree(priv->p_env);
3037 priv->p_env=NULL;
3038 kfree(priv->channel[0].irb);
3039 priv->channel[0].irb=NULL;
3040 kfree(priv->channel[1].irb);
3041 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003043 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb0832010-08-12 01:58:27 +00003044 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3045 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003047
3048 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049}
3050
3051
3052/*
3053 * sysfs attributes
3054 */
3055static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003056claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057{
3058 struct claw_privbk *priv;
3059 struct claw_env * p_env;
3060
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003061 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 if (!priv)
3063 return -ENODEV;
3064 p_env = priv->p_env;
3065 return sprintf(buf, "%s\n",p_env->host_name);
3066}
3067
3068static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003069claw_hname_write(struct device *dev, struct device_attribute *attr,
3070 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071{
3072 struct claw_privbk *priv;
3073 struct claw_env * p_env;
3074
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003075 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 if (!priv)
3077 return -ENODEV;
3078 p_env = priv->p_env;
3079 if (count > MAX_NAME_LEN+1)
3080 return -EINVAL;
3081 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3082 strncpy(p_env->host_name,buf, count);
3083 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3084 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003085 CLAW_DBF_TEXT(2, setup, "HstnSet");
3086 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087
3088 return count;
3089}
3090
3091static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3092
3093static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003094claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003095{
3096 struct claw_privbk *priv;
3097 struct claw_env * p_env;
3098
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003099 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003100 if (!priv)
3101 return -ENODEV;
3102 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003103 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104}
3105
3106static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003107claw_adname_write(struct device *dev, struct device_attribute *attr,
3108 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109{
3110 struct claw_privbk *priv;
3111 struct claw_env * p_env;
3112
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003113 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 if (!priv)
3115 return -ENODEV;
3116 p_env = priv->p_env;
3117 if (count > MAX_NAME_LEN+1)
3118 return -EINVAL;
3119 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3120 strncpy(p_env->adapter_name,buf, count);
3121 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3122 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003123 CLAW_DBF_TEXT(2, setup, "AdnSet");
3124 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125
3126 return count;
3127}
3128
3129static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3130
3131static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003132claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133{
3134 struct claw_privbk *priv;
3135 struct claw_env * p_env;
3136
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003137 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 if (!priv)
3139 return -ENODEV;
3140 p_env = priv->p_env;
3141 return sprintf(buf, "%s\n",
3142 p_env->api_type);
3143}
3144
3145static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003146claw_apname_write(struct device *dev, struct device_attribute *attr,
3147 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148{
3149 struct claw_privbk *priv;
3150 struct claw_env * p_env;
3151
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003152 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 if (!priv)
3154 return -ENODEV;
3155 p_env = priv->p_env;
3156 if (count > MAX_NAME_LEN+1)
3157 return -EINVAL;
3158 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3159 strncpy(p_env->api_type,buf, count);
3160 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3161 p_env->api_type[MAX_NAME_LEN] = 0x00;
3162 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3163 p_env->read_size=DEF_PACK_BUFSIZE;
3164 p_env->write_size=DEF_PACK_BUFSIZE;
3165 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003166 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 }
3168 else {
3169 p_env->packing=0;
3170 p_env->read_size=CLAW_FRAME_SIZE;
3171 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003172 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 }
Andy Richterb805da72008-07-18 15:24:56 +02003174 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 return count;
3176}
3177
3178static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3179
3180static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003181claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182{
3183 struct claw_privbk *priv;
3184 struct claw_env * p_env;
3185
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003186 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 if (!priv)
3188 return -ENODEV;
3189 p_env = priv->p_env;
3190 return sprintf(buf, "%d\n", p_env->write_buffers);
3191}
3192
3193static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003194claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3195 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196{
3197 struct claw_privbk *priv;
3198 struct claw_env * p_env;
3199 int nnn,max;
3200
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003201 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 if (!priv)
3203 return -ENODEV;
3204 p_env = priv->p_env;
3205 sscanf(buf, "%i", &nnn);
3206 if (p_env->packing) {
3207 max = 64;
3208 }
3209 else {
3210 max = 512;
3211 }
3212 if ((nnn > max ) || (nnn < 2))
3213 return -EINVAL;
3214 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003215 CLAW_DBF_TEXT(2, setup, "Wbufset");
3216 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 return count;
3218}
3219
3220static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3221
3222static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003223claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224{
3225 struct claw_privbk *priv;
3226 struct claw_env * p_env;
3227
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003228 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 if (!priv)
3230 return -ENODEV;
3231 p_env = priv->p_env;
3232 return sprintf(buf, "%d\n", p_env->read_buffers);
3233}
3234
3235static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003236claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3237 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238{
3239 struct claw_privbk *priv;
3240 struct claw_env *p_env;
3241 int nnn,max;
3242
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003243 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 if (!priv)
3245 return -ENODEV;
3246 p_env = priv->p_env;
3247 sscanf(buf, "%i", &nnn);
3248 if (p_env->packing) {
3249 max = 64;
3250 }
3251 else {
3252 max = 512;
3253 }
3254 if ((nnn > max ) || (nnn < 2))
3255 return -EINVAL;
3256 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003257 CLAW_DBF_TEXT(2, setup, "Rbufset");
3258 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 return count;
3260}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3262
3263static struct attribute *claw_attr[] = {
3264 &dev_attr_read_buffer.attr,
3265 &dev_attr_write_buffer.attr,
3266 &dev_attr_adapter_name.attr,
3267 &dev_attr_api_type.attr,
3268 &dev_attr_host_name.attr,
3269 NULL,
3270};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271static struct attribute_group claw_attr_group = {
3272 .attrs = claw_attr,
3273};
Sebastian Ott2ced5512012-05-15 18:00:49 +02003274static const struct attribute_group *claw_attr_groups[] = {
3275 &claw_attr_group,
3276 NULL,
3277};
3278static const struct device_type claw_devtype = {
3279 .name = "claw",
3280 .groups = claw_attr_groups,
3281};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282
Sebastian Ott2ced5512012-05-15 18:00:49 +02003283/*----------------------------------------------------------------*
3284 * claw_probe *
3285 * this function is called for each CLAW device. *
3286 *----------------------------------------------------------------*/
3287static int claw_probe(struct ccwgroup_device *cgdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288{
Sebastian Ott2ced5512012-05-15 18:00:49 +02003289 struct claw_privbk *privptr = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290
Sebastian Ott2ced5512012-05-15 18:00:49 +02003291 CLAW_DBF_TEXT(2, setup, "probe");
3292 if (!get_device(&cgdev->dev))
3293 return -ENODEV;
3294 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
3295 dev_set_drvdata(&cgdev->dev, privptr);
3296 if (privptr == NULL) {
3297 probe_error(cgdev);
3298 put_device(&cgdev->dev);
3299 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3300 return -ENOMEM;
3301 }
3302 privptr->p_mtc_envelope = kzalloc(MAX_ENVELOPE_SIZE, GFP_KERNEL);
3303 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
3304 if ((privptr->p_mtc_envelope == NULL) || (privptr->p_env == NULL)) {
3305 probe_error(cgdev);
3306 put_device(&cgdev->dev);
3307 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
3308 return -ENOMEM;
3309 }
3310 memcpy(privptr->p_env->adapter_name, WS_NAME_NOT_DEF, 8);
3311 memcpy(privptr->p_env->host_name, WS_NAME_NOT_DEF, 8);
3312 memcpy(privptr->p_env->api_type, WS_NAME_NOT_DEF, 8);
3313 privptr->p_env->packing = 0;
3314 privptr->p_env->write_buffers = 5;
3315 privptr->p_env->read_buffers = 5;
3316 privptr->p_env->read_size = CLAW_FRAME_SIZE;
3317 privptr->p_env->write_size = CLAW_FRAME_SIZE;
3318 privptr->p_env->p_priv = privptr;
3319 cgdev->cdev[0]->handler = claw_irq_handler;
3320 cgdev->cdev[1]->handler = claw_irq_handler;
3321 cgdev->dev.type = &claw_devtype;
3322 CLAW_DBF_TEXT(2, setup, "prbext 0");
3323
3324 return 0;
3325} /* end of claw_probe */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
3327/*--------------------------------------------------------------------*
3328* claw_init and cleanup *
3329*---------------------------------------------------------------------*/
3330
3331static void __exit
3332claw_cleanup(void)
3333{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003334 driver_remove_file(&claw_group_driver.driver,
3335 &driver_attr_group);
3336 ccwgroup_driver_unregister(&claw_group_driver);
3337 ccw_driver_unregister(&claw_ccw_driver);
3338 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003340 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341
3342}
3343
3344/**
3345 * Initialize module.
3346 * This is called just after the module is loaded.
3347 *
3348 * @return 0 on success, !0 on error.
3349 */
3350static int __init
3351claw_init(void)
3352{
3353 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354
Andy Richter4811fcb2009-01-20 06:14:33 +00003355 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 ret = claw_register_debug_facility();
3357 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003358 pr_err("Registering with the S/390 debug feature"
3359 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003360 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 }
Andy Richterb805da72008-07-18 15:24:56 +02003362 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003363 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003364 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3365 if (ret)
3366 goto register_err;
3367 ret = ccw_driver_register(&claw_ccw_driver);
3368 if (ret)
3369 goto ccw_err;
3370 claw_group_driver.driver.groups = claw_group_attr_groups;
3371 ret = ccwgroup_driver_register(&claw_group_driver);
3372 if (ret)
3373 goto ccwgroup_err;
3374 return 0;
3375
3376ccwgroup_err:
3377 ccw_driver_unregister(&claw_ccw_driver);
3378ccw_err:
3379 root_device_unregister(claw_root_dev);
3380register_err:
3381 CLAW_DBF_TEXT(2, setup, "init_bad");
3382 claw_unregister_debug_facility();
3383out_err:
3384 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 return ret;
3386}
3387
3388module_init(claw_init);
3389module_exit(claw_cleanup);
3390
Andy Richterb805da72008-07-18 15:24:56 +02003391MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3392MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3393 "Copyright 2000,2008 IBM Corporation\n");
3394MODULE_LICENSE("GPL");