blob: 8e4153d740f3bf00d4a465bf5a1526ee66ad518e [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 eieio();
140}
141
142static inline void
143claw_clear_busy(struct net_device *dev)
144{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200145 clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 netif_wake_queue(dev);
147 eieio();
148}
149
150static inline int
151claw_check_busy(struct net_device *dev)
152{
153 eieio();
Peter Tiedemann6951df32008-08-21 17:10:23 +0200154 return ((struct claw_privbk *) dev->ml_priv)->tbusy;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
157static inline void
158claw_setbit_busy(int nr,struct net_device *dev)
159{
160 netif_stop_queue(dev);
Peter Tiedemann6951df32008-08-21 17:10:23 +0200161 set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164static inline void
165claw_clearbit_busy(int nr,struct net_device *dev)
166{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200167 clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 netif_wake_queue(dev);
169}
170
171static inline int
172claw_test_and_setbit_busy(int nr,struct net_device *dev)
173{
174 netif_stop_queue(dev);
175 return test_and_set_bit(nr,
Peter Tiedemann6951df32008-08-21 17:10:23 +0200176 (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
179
180/* Functions for the DEV methods */
181
182static int claw_probe(struct ccwgroup_device *cgdev);
183static void claw_remove_device(struct ccwgroup_device *cgdev);
184static void claw_purge_skb_queue(struct sk_buff_head *q);
185static int claw_new_device(struct ccwgroup_device *cgdev);
186static int claw_shutdown_device(struct ccwgroup_device *cgdev);
187static int claw_tx(struct sk_buff *skb, struct net_device *dev);
188static int claw_change_mtu( struct net_device *dev, int new_mtu);
189static int claw_open(struct net_device *dev);
190static void claw_irq_handler(struct ccw_device *cdev,
191 unsigned long intparm, struct irb *irb);
192static void claw_irq_tasklet ( unsigned long data );
193static int claw_release(struct net_device *dev);
194static void claw_write_retry ( struct chbk * p_ch );
195static void claw_write_next ( struct chbk * p_ch );
196static void claw_timer ( struct chbk * p_ch );
197
198/* Functions */
199static int add_claw_reads(struct net_device *dev,
200 struct ccwbk* p_first, struct ccwbk* p_last);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100201static void ccw_check_return_code (struct ccw_device *cdev, int return_code);
202static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static int find_link(struct net_device *dev, char *host_name, char *ws_name );
204static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid);
205static int init_ccw_bk(struct net_device *dev);
206static void probe_error( struct ccwgroup_device *cgdev);
207static struct net_device_stats *claw_stats(struct net_device *dev);
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100208static int pages_to_order_of_mag(int num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/* sysfs Functions */
Andy Richter4811fcb2009-01-20 06:14:33 +0000211static ssize_t claw_hname_show(struct device *dev,
212 struct device_attribute *attr, char *buf);
213static ssize_t claw_hname_write(struct device *dev,
214 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000216static ssize_t claw_adname_show(struct device *dev,
217 struct device_attribute *attr, char *buf);
218static ssize_t claw_adname_write(struct device *dev,
219 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000221static ssize_t claw_apname_show(struct device *dev,
222 struct device_attribute *attr, char *buf);
223static ssize_t claw_apname_write(struct device *dev,
224 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000226static ssize_t claw_wbuff_show(struct device *dev,
227 struct device_attribute *attr, char *buf);
228static ssize_t claw_wbuff_write(struct device *dev,
229 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 const char *buf, size_t count);
Andy Richter4811fcb2009-01-20 06:14:33 +0000231static ssize_t claw_rbuff_show(struct device *dev,
232 struct device_attribute *attr, char *buf);
233static ssize_t claw_rbuff_write(struct device *dev,
234 struct device_attribute *attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 const char *buf, size_t count);
236static int claw_add_files(struct device *dev);
237static void claw_remove_files(struct device *dev);
238
239/* Functions for System Validate */
240static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw);
241static int claw_send_control(struct net_device *dev, __u8 type, __u8 link,
242 __u8 correlator, __u8 rc , char *local_name, char *remote_name);
243static int claw_snd_conn_req(struct net_device *dev, __u8 link);
244static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl);
245static int claw_snd_sys_validate_rsp(struct net_device *dev,
246 struct clawctl * p_ctl, __u32 return_code);
247static int claw_strt_conn_req(struct net_device *dev );
Andy Richterb805da72008-07-18 15:24:56 +0200248static void claw_strt_read(struct net_device *dev, int lock);
249static void claw_strt_out_IO(struct net_device *dev);
250static void claw_free_wrt_buf(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252/* Functions for unpack reads */
Andy Richterb805da72008-07-18 15:24:56 +0200253static void unpack_read(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200255static int claw_pm_prepare(struct ccwgroup_device *gdev)
256{
257 return -EPERM;
258}
259
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000260/* the root device for claw group devices */
261static struct device *claw_root_dev;
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263/* ccwgroup table */
264
265static struct ccwgroup_driver claw_group_driver = {
266 .owner = THIS_MODULE,
267 .name = "claw",
268 .max_slaves = 2,
269 .driver_id = 0xC3D3C1E6,
270 .probe = claw_probe,
271 .remove = claw_remove_device,
272 .set_online = claw_new_device,
273 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200274 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275};
276
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000277static struct ccw_device_id claw_ids[] = {
278 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
279 {},
280};
281MODULE_DEVICE_TABLE(ccw, claw_ids);
282
283static struct ccw_driver claw_ccw_driver = {
284 .owner = THIS_MODULE,
285 .name = "claw",
286 .ids = claw_ids,
287 .probe = ccwgroup_probe_ccwdev,
288 .remove = ccwgroup_remove_ccwdev,
289};
290
291static ssize_t
292claw_driver_group_store(struct device_driver *ddrv, const char *buf,
293 size_t count)
294{
295 int err;
296 err = ccwgroup_create_from_string(claw_root_dev,
297 claw_group_driver.driver_id,
Ursula Braune48d24a2010-07-22 23:15:07 +0000298 &claw_ccw_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000299 return err ? err : count;
300}
301
302static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
303
304static struct attribute *claw_group_attrs[] = {
305 &driver_attr_group.attr,
306 NULL,
307};
308
309static struct attribute_group claw_group_attr_group = {
310 .attrs = claw_group_attrs,
311};
312
Heiko Carstens302689a2009-11-17 06:47:02 -0800313static const struct attribute_group *claw_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000314 &claw_group_attr_group,
315 NULL,
316};
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319* Key functions
320*/
321
322/*----------------------------------------------------------------*
323 * claw_probe *
324 * this function is called for each CLAW device. *
325 *----------------------------------------------------------------*/
326static int
327claw_probe(struct ccwgroup_device *cgdev)
328{
329 int rc;
330 struct claw_privbk *privptr=NULL;
331
Andy Richterb805da72008-07-18 15:24:56 +0200332 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 if (!get_device(&cgdev->dev))
334 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800335 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700336 dev_set_drvdata(&cgdev->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 if (privptr == NULL) {
338 probe_error(cgdev);
339 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200340 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 return -ENOMEM;
342 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700343 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
344 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
346 probe_error(cgdev);
347 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200348 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 return -ENOMEM;
350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
352 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
353 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
354 privptr->p_env->packing = 0;
355 privptr->p_env->write_buffers = 5;
356 privptr->p_env->read_buffers = 5;
357 privptr->p_env->read_size = CLAW_FRAME_SIZE;
358 privptr->p_env->write_size = CLAW_FRAME_SIZE;
359 rc = claw_add_files(&cgdev->dev);
360 if (rc) {
361 probe_error(cgdev);
362 put_device(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +0000363 dev_err(&cgdev->dev, "Creating the /proc files for a new"
364 " CLAW device failed\n");
Andy Richterb805da72008-07-18 15:24:56 +0200365 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 return rc;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 privptr->p_env->p_priv = privptr;
369 cgdev->cdev[0]->handler = claw_irq_handler;
370 cgdev->cdev[1]->handler = claw_irq_handler;
Andy Richterb805da72008-07-18 15:24:56 +0200371 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 return 0;
374} /* end of claw_probe */
375
376/*-------------------------------------------------------------------*
377 * claw_tx *
378 *-------------------------------------------------------------------*/
379
380static int
381claw_tx(struct sk_buff *skb, struct net_device *dev)
382{
383 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200384 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 unsigned long saveflags;
386 struct chbk *p_ch;
387
Andy Richterb805da72008-07-18 15:24:56 +0200388 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb082010-08-12 01:58:27 +0000389 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
391 rc=claw_hw_tx( skb, dev, 1 );
392 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200393 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000394 if (rc)
395 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700396 else
397 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 return rc;
399} /* end of claw_tx */
400
401/*------------------------------------------------------------------*
402 * pack the collect queue into an skb and return it *
403 * If not packing just return the top skb from the queue *
404 *------------------------------------------------------------------*/
405
406static struct sk_buff *
407claw_pack_skb(struct claw_privbk *privptr)
408{
409 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb082010-08-12 01:58:27 +0000410 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 struct claw_env *p_env = privptr->p_env;
412 int pkt_cnt,pk_ind,so_far;
413
414 new_skb = NULL; /* assume no dice */
415 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200416 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700417 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* some data */
419 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200421 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 else
423 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200424 if (p_env->packing != DO_PACKED)
425 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* get a new SKB we will pack at least one */
427 new_skb = dev_alloc_skb(p_env->write_size);
428 if (new_skb == NULL) {
429 atomic_inc(&held_skb->users);
430 skb_queue_head(&p_ch->collect_queue,held_skb);
431 return NULL;
432 }
433 /* we have packed packet and a place to put it */
434 pk_ind = 1;
435 so_far = 0;
436 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
437 while ((pk_ind) && (held_skb != NULL)) {
438 if (held_skb->len+so_far <= p_env->write_size-8) {
439 memcpy(skb_put(new_skb,held_skb->len),
440 held_skb->data,held_skb->len);
441 privptr->stats.tx_packets++;
442 so_far += held_skb->len;
443 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200444 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 held_skb = skb_dequeue(&p_ch->collect_queue);
446 if (held_skb)
447 atomic_dec(&held_skb->users);
448 } else {
449 pk_ind = 0;
450 atomic_inc(&held_skb->users);
451 skb_queue_head(&p_ch->collect_queue,held_skb);
452 }
453 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
Andy Richterb805da72008-07-18 15:24:56 +0200455 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 return new_skb;
457}
458
459/*-------------------------------------------------------------------*
460 * claw_change_mtu *
461 * *
462 *-------------------------------------------------------------------*/
463
464static int
465claw_change_mtu(struct net_device *dev, int new_mtu)
466{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200467 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200469 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 buff_size = privptr->p_env->write_size;
471 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return -EINVAL;
473 }
474 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return 0;
476} /* end of claw_change_mtu */
477
478
479/*-------------------------------------------------------------------*
480 * claw_open *
481 * *
482 *-------------------------------------------------------------------*/
483static int
484claw_open(struct net_device *dev)
485{
486
487 int rc;
488 int i;
489 unsigned long saveflags=0;
490 unsigned long parm;
491 struct claw_privbk *privptr;
492 DECLARE_WAITQUEUE(wait, current);
493 struct timer_list timer;
494 struct ccwbk *p_buf;
495
Andy Richterb805da72008-07-18 15:24:56 +0200496 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200497 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* allocate and initialize CCW blocks */
499 if (privptr->buffs_alloc == 0) {
500 rc=init_ccw_bk(dev);
501 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200502 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 return -ENOMEM;
504 }
505 }
506 privptr->system_validate_comp=0;
507 privptr->release_pend=0;
508 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
509 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
510 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
511 privptr->p_env->packing=PACKING_ASK;
512 } else {
513 privptr->p_env->packing=0;
514 privptr->p_env->read_size=CLAW_FRAME_SIZE;
515 privptr->p_env->write_size=CLAW_FRAME_SIZE;
516 }
517 claw_set_busy(dev);
Heiko Carstens319cb082010-08-12 01:58:27 +0000518 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
519 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200521 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 init_waitqueue_head(&privptr->channel[i].wait);
523 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb082010-08-12 01:58:27 +0000524 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 skb_queue_head_init(
Heiko Carstens319cb082010-08-12 01:58:27 +0000526 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 privptr->channel[i].flag_a = 0;
528 privptr->channel[i].IO_active = 0;
529 privptr->channel[i].flag &= ~CLAW_TIMER;
530 init_timer(&timer);
531 timer.function = (void *)claw_timer;
532 timer.data = (unsigned long)(&privptr->channel[i]);
533 timer.expires = jiffies + 15*HZ;
534 add_timer(&timer);
535 spin_lock_irqsave(get_ccwdev_lock(
536 privptr->channel[i].cdev), saveflags);
537 parm = (unsigned long) &privptr->channel[i];
538 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
539 rc = 0;
540 add_wait_queue(&privptr->channel[i].wait, &wait);
541 rc = ccw_device_halt(
542 (struct ccw_device *)privptr->channel[i].cdev,parm);
543 set_current_state(TASK_INTERRUPTIBLE);
544 spin_unlock_irqrestore(
545 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
546 schedule();
547 set_current_state(TASK_RUNNING);
548 remove_wait_queue(&privptr->channel[i].wait, &wait);
549 if(rc != 0)
550 ccw_check_return_code(privptr->channel[i].cdev, rc);
551 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
552 del_timer(&timer);
553 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000554 if ((((privptr->channel[READ_CHANNEL].last_dstat |
555 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb082010-08-12 01:58:27 +0000557 (((privptr->channel[READ_CHANNEL].flag |
558 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
559 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000560 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200561 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 for ( i = 0; i < 2; i++) {
564 spin_lock_irqsave(
565 get_ccwdev_lock(privptr->channel[i].cdev),
566 saveflags);
567 parm = (unsigned long) &privptr->channel[i];
568 privptr->channel[i].claw_state = CLAW_STOP;
569 rc = ccw_device_halt(
570 (struct ccw_device *)&privptr->channel[i].cdev,
571 parm);
572 spin_unlock_irqrestore(
573 get_ccwdev_lock(privptr->channel[i].cdev),
574 saveflags);
575 if (rc != 0) {
576 ccw_check_return_code(
577 privptr->channel[i].cdev, rc);
578 }
579 }
580 free_pages((unsigned long)privptr->p_buff_ccw,
581 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
582 if (privptr->p_env->read_size < PAGE_SIZE) {
583 free_pages((unsigned long)privptr->p_buff_read,
584 (int)pages_to_order_of_mag(
585 privptr->p_buff_read_num));
586 }
587 else {
588 p_buf=privptr->p_read_active_first;
589 while (p_buf!=NULL) {
590 free_pages((unsigned long)p_buf->p_buffer,
591 (int)pages_to_order_of_mag(
592 privptr->p_buff_pages_perread ));
593 p_buf=p_buf->next;
594 }
595 }
596 if (privptr->p_env->write_size < PAGE_SIZE ) {
597 free_pages((unsigned long)privptr->p_buff_write,
598 (int)pages_to_order_of_mag(
599 privptr->p_buff_write_num));
600 }
601 else {
602 p_buf=privptr->p_write_active_first;
603 while (p_buf!=NULL) {
604 free_pages((unsigned long)p_buf->p_buffer,
605 (int)pages_to_order_of_mag(
606 privptr->p_buff_pages_perwrite ));
607 p_buf=p_buf->next;
608 }
609 }
610 privptr->buffs_alloc = 0;
Heiko Carstens319cb082010-08-12 01:58:27 +0000611 privptr->channel[READ_CHANNEL].flag = 0x00;
612 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 privptr->p_buff_ccw=NULL;
614 privptr->p_buff_read=NULL;
615 privptr->p_buff_write=NULL;
616 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200617 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 return -EIO;
619 }
620
621 /* Send SystemValidate command */
622
623 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200624 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 return 0;
626} /* end of claw_open */
627
628/*-------------------------------------------------------------------*
629* *
630* claw_irq_handler *
631* *
632*--------------------------------------------------------------------*/
633static void
634claw_irq_handler(struct ccw_device *cdev,
635 unsigned long intparm, struct irb *irb)
636{
637 struct chbk *p_ch = NULL;
638 struct claw_privbk *privptr = NULL;
639 struct net_device *dev = NULL;
640 struct claw_env *p_env;
641 struct chbk *p_ch_r=NULL;
642
Andy Richterb805da72008-07-18 15:24:56 +0200643 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700645 privptr = dev_get_drvdata(&cdev->dev);
646 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000647 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
648 " IRQ, c-%02x d-%02x\n",
649 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200650 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 return;
652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654 /* Try to extract channel from driver data. */
Heiko Carstens319cb082010-08-12 01:58:27 +0000655 if (privptr->channel[READ_CHANNEL].cdev == cdev)
656 p_ch = &privptr->channel[READ_CHANNEL];
657 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
658 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000660 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200661 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662 return;
663 }
Andy Richterb805da72008-07-18 15:24:56 +0200664 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 dev = (struct net_device *) (p_ch->ndev);
667 p_env=privptr->p_env;
668
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 /* Copy interruption response block. */
670 memcpy(p_ch->irb, irb, sizeof(struct irb));
671
Andy Richterb805da72008-07-18 15:24:56 +0200672 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200673 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000674 dev_info(&cdev->dev,
675 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
677 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200678 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
679 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200680 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 /* return; */
682 }
683
684 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200685 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200689 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
691 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200692 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
693 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
694 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
695 (p_ch->irb->scsw.cmd.stctl ==
696 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
697 return;
698 wake_up(&p_ch->wait); /* wake up claw_release */
699 CLAW_DBF_TEXT(4, trace, "stop");
700 return;
701 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
702 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
703 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
704 (p_ch->irb->scsw.cmd.stctl ==
705 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
706 CLAW_DBF_TEXT(4, trace, "haltio");
707 return;
708 }
709 if (p_ch->flag == CLAW_READ) {
710 p_ch->claw_state = CLAW_START_READ;
711 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
712 } else if (p_ch->flag == CLAW_WRITE) {
713 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000714 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200715 claw_strt_read(dev, LOCK_NO);
716 claw_send_control(dev,
717 SYSTEM_VALIDATE_REQUEST,
718 0, 0, 0,
719 p_env->host_name,
720 p_env->adapter_name);
721 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000722 dev_warn(&cdev->dev, "The CLAW device received"
723 " an unexpected IRQ, "
724 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200725 irb->scsw.cmd.cstat,
726 irb->scsw.cmd.dstat);
727 return;
728 }
729 CLAW_DBF_TEXT(4, trace, "haltio");
730 return;
731 case CLAW_START_READ:
732 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
733 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
734 clear_bit(0, (void *)&p_ch->IO_active);
735 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
736 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
737 (p_ch->irb->ecw[0]) == 0) {
738 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000739 dev_info(&cdev->dev,
740 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200741 "side recovers \n",
742 dev->name);
743 }
744 CLAW_DBF_TEXT(4, trace, "notrdy");
745 return;
746 }
747 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
748 (p_ch->irb->scsw.cmd.dstat == 0)) {
749 if (test_and_set_bit(CLAW_BH_ACTIVE,
750 (void *)&p_ch->flag_a) == 0)
751 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 else
Andy Richterb805da72008-07-18 15:24:56 +0200753 CLAW_DBF_TEXT(4, trace, "PCINoBH");
754 CLAW_DBF_TEXT(4, trace, "PCI_read");
755 return;
756 }
757 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
758 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
759 (p_ch->irb->scsw.cmd.stctl ==
760 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
761 CLAW_DBF_TEXT(4, trace, "SPend_rd");
762 return;
763 }
764 clear_bit(0, (void *)&p_ch->IO_active);
765 claw_clearbit_busy(TB_RETRY, dev);
766 if (test_and_set_bit(CLAW_BH_ACTIVE,
767 (void *)&p_ch->flag_a) == 0)
768 tasklet_schedule(&p_ch->tasklet);
769 else
770 CLAW_DBF_TEXT(4, trace, "RdBHAct");
771 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
772 return;
773 case CLAW_START_WRITE:
774 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000775 dev_info(&cdev->dev,
776 "%s: Unit Check Occured in "
Andy Richterb805da72008-07-18 15:24:56 +0200777 "write channel\n", dev->name);
778 clear_bit(0, (void *)&p_ch->IO_active);
779 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000780 dev_info(&cdev->dev,
781 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200782 "occurred:\n", dev->name);
783 init_timer(&p_ch->timer);
784 p_ch->timer.function =
785 (void *)claw_write_retry;
786 p_ch->timer.data = (unsigned long)p_ch;
787 p_ch->timer.expires = jiffies + 10*HZ;
788 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000789 dev_info(&cdev->dev,
790 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200791 "restarting\n", dev->name);
792 }
793 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
794 return;
795 }
796 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
797 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000798 dev_info(&cdev->dev,
799 "%s: Unit Exception "
800 "occurred in write channel\n",
801 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200802 }
803 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
804 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
805 (p_ch->irb->scsw.cmd.stctl ==
806 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
807 CLAW_DBF_TEXT(4, trace, "writeUE");
808 return;
809 }
810 clear_bit(0, (void *)&p_ch->IO_active);
811 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
812 claw_write_next(p_ch);
813 claw_clearbit_busy(TB_TX, dev);
814 claw_clear_busy(dev);
815 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000816 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200817 if (test_and_set_bit(CLAW_BH_ACTIVE,
818 (void *)&p_ch_r->flag_a) == 0)
819 tasklet_schedule(&p_ch_r->tasklet);
820 CLAW_DBF_TEXT(4, trace, "StWtExit");
821 return;
822 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000823 dev_warn(&cdev->dev,
824 "The CLAW device for %s received an unexpected IRQ\n",
825 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200826 CLAW_DBF_TEXT(2, trace, "badIRQ");
827 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 }
829
830} /* end of claw_irq_handler */
831
832
833/*-------------------------------------------------------------------*
834* claw_irq_tasklet *
835* *
836*--------------------------------------------------------------------*/
837static void
838claw_irq_tasklet ( unsigned long data )
839{
840 struct chbk * p_ch;
841 struct net_device *dev;
842 struct claw_privbk * privptr;
843
844 p_ch = (struct chbk *) data;
845 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200846 CLAW_DBF_TEXT(4, trace, "IRQtask");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200847 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 unpack_read(dev);
849 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200850 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 return;
852} /* end of claw_irq_bh */
853
854/*-------------------------------------------------------------------*
855* claw_release *
856* *
857*--------------------------------------------------------------------*/
858static int
859claw_release(struct net_device *dev)
860{
861 int rc;
862 int i;
863 unsigned long saveflags;
864 unsigned long parm;
865 struct claw_privbk *privptr;
866 DECLARE_WAITQUEUE(wait, current);
867 struct ccwbk* p_this_ccw;
868 struct ccwbk* p_buf;
869
870 if (!dev)
871 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200872 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 if (!privptr)
874 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200875 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 privptr->release_pend=1;
877 claw_setbit_busy(TB_STOP,dev);
878 for ( i = 1; i >=0 ; i--) {
879 spin_lock_irqsave(
880 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb082010-08-12 01:58:27 +0000881 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 privptr->channel[i].claw_state = CLAW_STOP;
883 privptr->channel[i].IO_active = 0;
884 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb082010-08-12 01:58:27 +0000885 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 claw_purge_skb_queue(
Heiko Carstens319cb082010-08-12 01:58:27 +0000887 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
889 if (privptr->system_validate_comp==0x00) /* never opened? */
890 init_waitqueue_head(&privptr->channel[i].wait);
891 add_wait_queue(&privptr->channel[i].wait, &wait);
892 set_current_state(TASK_INTERRUPTIBLE);
893 spin_unlock_irqrestore(
894 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
895 schedule();
896 set_current_state(TASK_RUNNING);
897 remove_wait_queue(&privptr->channel[i].wait, &wait);
898 if (rc != 0) {
899 ccw_check_return_code(privptr->channel[i].cdev, rc);
900 }
901 }
902 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200903 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 privptr->pk_skb = NULL;
905 }
906 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200907 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 return 0;
909 }
Andy Richterb805da72008-07-18 15:24:56 +0200910 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 if (privptr->p_buff_ccw != NULL) {
912 free_pages((unsigned long)privptr->p_buff_ccw,
913 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
914 }
Andy Richterb805da72008-07-18 15:24:56 +0200915 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (privptr->p_env->read_size < PAGE_SIZE) {
917 if (privptr->p_buff_read != NULL) {
918 free_pages((unsigned long)privptr->p_buff_read,
919 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
920 }
921 }
922 else {
923 p_buf=privptr->p_read_active_first;
924 while (p_buf!=NULL) {
925 free_pages((unsigned long)p_buf->p_buffer,
926 (int)pages_to_order_of_mag(
927 privptr->p_buff_pages_perread ));
928 p_buf=p_buf->next;
929 }
930 }
Andy Richterb805da72008-07-18 15:24:56 +0200931 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (privptr->p_env->write_size < PAGE_SIZE ) {
933 free_pages((unsigned long)privptr->p_buff_write,
934 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
935 }
936 else {
937 p_buf=privptr->p_write_active_first;
938 while (p_buf!=NULL) {
939 free_pages((unsigned long)p_buf->p_buffer,
940 (int)pages_to_order_of_mag(
941 privptr->p_buff_pages_perwrite ));
942 p_buf=p_buf->next;
943 }
944 }
Andy Richterb805da72008-07-18 15:24:56 +0200945 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 privptr->buffs_alloc = 0;
947 privptr->p_buff_ccw=NULL;
948 privptr->p_buff_read=NULL;
949 privptr->p_buff_write=NULL;
950 privptr->system_validate_comp=0;
951 privptr->release_pend=0;
952 /* Remove any writes that were pending and reset all reads */
953 p_this_ccw=privptr->p_read_active_first;
954 while (p_this_ccw!=NULL) {
955 p_this_ccw->header.length=0xffff;
956 p_this_ccw->header.opcode=0xff;
957 p_this_ccw->header.flag=0x00;
958 p_this_ccw=p_this_ccw->next;
959 }
960
961 while (privptr->p_write_active_first!=NULL) {
962 p_this_ccw=privptr->p_write_active_first;
963 p_this_ccw->header.flag=CLAW_PENDING;
964 privptr->p_write_active_first=p_this_ccw->next;
965 p_this_ccw->next=privptr->p_write_free_chain;
966 privptr->p_write_free_chain=p_this_ccw;
967 ++privptr->write_free_count;
968 }
969 privptr->p_write_active_last=NULL;
970 privptr->mtc_logical_link = -1;
971 privptr->mtc_skipping = 1;
972 privptr->mtc_offset=0;
973
Heiko Carstens319cb082010-08-12 01:58:27 +0000974 if (((privptr->channel[READ_CHANNEL].last_dstat |
975 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb082010-08-12 01:58:27 +0000977 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000978 "Deactivating %s completed with incorrect"
979 " subchannel status "
980 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 dev->name,
Heiko Carstens319cb082010-08-12 01:58:27 +0000982 privptr->channel[READ_CHANNEL].last_dstat,
983 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200984 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 }
Andy Richterb805da72008-07-18 15:24:56 +0200986 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 return 0;
988} /* end of claw_release */
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990/*-------------------------------------------------------------------*
991* claw_write_retry *
992* *
993*--------------------------------------------------------------------*/
994
995static void
996claw_write_retry ( struct chbk *p_ch )
997{
998
999 struct net_device *dev=p_ch->ndev;
1000
Andy Richterb805da72008-07-18 15:24:56 +02001001 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 return;
1004 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +02001006 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 return;
1008} /* end of claw_write_retry */
1009
1010
1011/*-------------------------------------------------------------------*
1012* claw_write_next *
1013* *
1014*--------------------------------------------------------------------*/
1015
1016static void
1017claw_write_next ( struct chbk * p_ch )
1018{
1019
1020 struct net_device *dev;
1021 struct claw_privbk *privptr=NULL;
1022 struct sk_buff *pk_skb;
1023 int rc;
1024
Andy Richterb805da72008-07-18 15:24:56 +02001025 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if (p_ch->claw_state == CLAW_STOP)
1027 return;
1028 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001029 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 claw_free_wrt_buf( dev );
1031 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -07001032 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 pk_skb = claw_pack_skb(privptr);
1034 while (pk_skb != NULL) {
1035 rc = claw_hw_tx( pk_skb, dev,1);
1036 if (privptr->write_free_count > 0) {
1037 pk_skb = claw_pack_skb(privptr);
1038 } else
1039 pk_skb = NULL;
1040 }
1041 }
1042 if (privptr->p_write_active_first!=NULL) {
1043 claw_strt_out_IO(dev);
1044 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 return;
1046} /* end of claw_write_next */
1047
1048/*-------------------------------------------------------------------*
1049* *
1050* claw_timer *
1051*--------------------------------------------------------------------*/
1052
1053static void
1054claw_timer ( struct chbk * p_ch )
1055{
Andy Richterb805da72008-07-18 15:24:56 +02001056 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 p_ch->flag |= CLAW_TIMER;
1058 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 return;
1060} /* end of claw_timer */
1061
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062/*
1063*
1064* functions
1065*/
1066
1067
1068/*-------------------------------------------------------------------*
1069* *
1070* pages_to_order_of_mag *
1071* *
1072* takes a number of pages from 1 to 512 and returns the *
1073* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1074* of magnitude get_free_pages() has an upper order of 9 *
1075*--------------------------------------------------------------------*/
1076
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001077static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078pages_to_order_of_mag(int num_of_pages)
1079{
1080 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001081 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001082
1083 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1085 /* 512 pages = 2Meg on 4k page systems */
1086 if (num_of_pages >= 512) {return 9; }
1087 /* we have two or more pages order is at least 1 */
1088 for (nump=2 ;nump <= 512;nump*=2) {
1089 if (num_of_pages <= nump)
1090 break;
1091 order_of_mag +=1;
1092 }
1093 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001094 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 return order_of_mag;
1096}
1097
1098/*-------------------------------------------------------------------*
1099* *
1100* add_claw_reads *
1101* *
1102*--------------------------------------------------------------------*/
1103static int
1104add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1105 struct ccwbk* p_last)
1106{
1107 struct claw_privbk *privptr;
1108 struct ccw1 temp_ccw;
1109 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001110 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001111 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 p_end = privptr->p_end_ccw;
1113
1114 /* first CCW and last CCW contains a new set of read channel programs
1115 * to apend the running channel programs
1116 */
1117 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001118 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 return 0;
1120 }
1121
1122 /* set up ending CCW sequence for this segment */
1123 if (p_end->read1) {
1124 p_end->read1=0x00; /* second ending CCW is now active */
1125 /* reset ending CCWs and setup TIC CCWs */
1126 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1127 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1128 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1129 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1130 p_end->read2_nop2.cda=0;
1131 p_end->read2_nop2.count=1;
1132 }
1133 else {
1134 p_end->read1=0x01; /* first ending CCW is now active */
1135 /* reset ending CCWs and setup TIC CCWs */
1136 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1137 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1138 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1139 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1140 p_end->read1_nop2.cda=0;
1141 p_end->read1_nop2.count=1;
1142 }
1143
1144 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001145 privptr->p_read_active_first = p_first; /* set new first */
1146 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 }
1148 else {
1149
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 /* set up TIC ccw */
1151 temp_ccw.cda= (__u32)__pa(&p_first->read);
1152 temp_ccw.count=0;
1153 temp_ccw.flags=0;
1154 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1155
1156
1157 if (p_end->read1) {
1158
1159 /* first set of CCW's is chained to the new read */
1160 /* chain, so the second set is chained to the active chain. */
1161 /* Therefore modify the second set to point to the new */
1162 /* read chain set up TIC CCWs */
1163 /* make sure we update the CCW so channel doesn't fetch it */
1164 /* when it's only half done */
1165 memcpy( &p_end->read2_nop2, &temp_ccw ,
1166 sizeof(struct ccw1));
1167 privptr->p_read_active_last->r_TIC_1.cda=
1168 (__u32)__pa(&p_first->read);
1169 privptr->p_read_active_last->r_TIC_2.cda=
1170 (__u32)__pa(&p_first->read);
1171 }
1172 else {
1173 /* make sure we update the CCW so channel doesn't */
1174 /* fetch it when it is only half done */
1175 memcpy( &p_end->read1_nop2, &temp_ccw ,
1176 sizeof(struct ccw1));
1177 privptr->p_read_active_last->r_TIC_1.cda=
1178 (__u32)__pa(&p_first->read);
1179 privptr->p_read_active_last->r_TIC_2.cda=
1180 (__u32)__pa(&p_first->read);
1181 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001182 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 privptr->p_read_active_last->next = p_first;
1184 privptr->p_read_active_last=p_last;
1185 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001186 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 return 0;
1188} /* end of add_claw_reads */
1189
1190/*-------------------------------------------------------------------*
1191 * ccw_check_return_code *
1192 * *
1193 *-------------------------------------------------------------------*/
1194
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001195static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196ccw_check_return_code(struct ccw_device *cdev, int return_code)
1197{
Andy Richterb805da72008-07-18 15:24:56 +02001198 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 if (return_code != 0) {
1200 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001201 case -EBUSY: /* BUSY is a transient state no action needed */
1202 break;
1203 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001204 dev_err(&cdev->dev, "The remote channel adapter is not"
1205 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001206 break;
1207 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001208 dev_err(&cdev->dev,
1209 "The status of the remote channel adapter"
1210 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001211 break;
1212 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001213 dev_err(&cdev->dev, "The common device layer"
1214 " returned error code %d\n",
1215 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001216 }
1217 }
1218 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219} /* end of ccw_check_return_code */
1220
1221/*-------------------------------------------------------------------*
1222* ccw_check_unit_check *
1223*--------------------------------------------------------------------*/
1224
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001225static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1227{
Andy Richterb805da72008-07-18 15:24:56 +02001228 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001229 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Andy Richterb805da72008-07-18 15:24:56 +02001231 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001232 dev_warn(dev, "The communication peer of %s disconnected\n",
1233 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001235 if (sense & 0x40) {
1236 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001237 dev_warn(dev, "The remote channel adapter for"
1238 " %s has been reset\n",
1239 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001240 }
1241 } else if (sense & 0x20) {
1242 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001243 dev_warn(dev, "A data streaming timeout occurred"
1244 " for %s\n",
1245 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001246 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001247 dev_warn(dev, "The remote channel adapter for %s"
1248 " is faulty\n",
1249 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001250 } else {
1251 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001252 " for %s\n",
1253 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001254 }
1255 } else if (sense & 0x10) {
1256 dev_warn(dev, "A read data parity error occurred"
1257 " for %s\n",
1258 ndev->name);
1259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261} /* end of ccw_check_unit_check */
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263/*-------------------------------------------------------------------*
1264* find_link *
1265*--------------------------------------------------------------------*/
1266static int
1267find_link(struct net_device *dev, char *host_name, char *ws_name )
1268{
1269 struct claw_privbk *privptr;
1270 struct claw_env *p_env;
1271 int rc=0;
1272
Andy Richterb805da72008-07-18 15:24:56 +02001273 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001274 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 p_env=privptr->p_env;
1276 switch (p_env->packing)
1277 {
1278 case PACKING_ASK:
1279 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1280 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1281 rc = EINVAL;
1282 break;
1283 case DO_PACKED:
1284 case PACK_SEND:
1285 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1286 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1287 rc = EINVAL;
1288 break;
1289 default:
1290 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1291 (memcmp(p_env->api_type , ws_name, 8)!=0))
1292 rc = EINVAL;
1293 break;
1294 }
1295
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001296 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297} /* end of find_link */
1298
1299/*-------------------------------------------------------------------*
1300 * claw_hw_tx *
1301 * *
1302 * *
1303 *-------------------------------------------------------------------*/
1304
1305static int
1306claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1307{
1308 int rc=0;
1309 struct claw_privbk *privptr;
1310 struct ccwbk *p_this_ccw;
1311 struct ccwbk *p_first_ccw;
1312 struct ccwbk *p_last_ccw;
1313 __u32 numBuffers;
1314 signed long len_of_data;
1315 unsigned long bytesInThisBuffer;
1316 unsigned char *pDataAddress;
1317 struct endccw *pEnd;
1318 struct ccw1 tempCCW;
1319 struct chbk *p_ch;
1320 struct claw_env *p_env;
1321 int lock;
1322 struct clawph *pk_head;
1323 struct chbk *ch;
Andy Richterb805da72008-07-18 15:24:56 +02001324
1325 CLAW_DBF_TEXT(4, trace, "hw_tx");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001326 privptr = (struct claw_privbk *)(dev->ml_priv);
Heiko Carstens319cb082010-08-12 01:58:27 +00001327 p_ch = (struct chbk *)&privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1330 /* scan the write queue to free any completed write packets */
1331 p_first_ccw=NULL;
1332 p_last_ccw=NULL;
1333 if ((p_env->packing >= PACK_SEND) &&
1334 (skb->cb[1] != 'P')) {
1335 skb_push(skb,sizeof(struct clawph));
1336 pk_head=(struct clawph *)skb->data;
1337 pk_head->len=skb->len-sizeof(struct clawph);
1338 if (pk_head->len%4) {
1339 pk_head->len+= 4-(pk_head->len%4);
1340 skb_pad(skb,4-(pk_head->len%4));
1341 skb_put(skb,4-(pk_head->len%4));
1342 }
1343 if (p_env->packing == DO_PACKED)
1344 pk_head->link_num = linkid;
1345 else
1346 pk_head->link_num = 0;
1347 pk_head->flag = 0x00;
1348 skb_pad(skb,4);
1349 skb->cb[1] = 'P';
1350 }
1351 if (linkid == 0) {
1352 if (claw_check_busy(dev)) {
1353 if (privptr->write_free_count!=0) {
1354 claw_clear_busy(dev);
1355 }
1356 else {
1357 claw_strt_out_IO(dev );
1358 claw_free_wrt_buf( dev );
1359 if (privptr->write_free_count==0) {
Heiko Carstens319cb082010-08-12 01:58:27 +00001360 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 atomic_inc(&skb->users);
1362 skb_queue_tail(&ch->collect_queue, skb);
1363 goto Done;
1364 }
1365 else {
1366 claw_clear_busy(dev);
1367 }
1368 }
1369 }
1370 /* tx lock */
1371 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb082010-08-12 01:58:27 +00001372 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 atomic_inc(&skb->users);
1374 skb_queue_tail(&ch->collect_queue, skb);
1375 claw_strt_out_IO(dev );
1376 rc=-EBUSY;
1377 goto Done2;
1378 }
1379 }
1380 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001381 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 /* If that number of buffers isn't available, give up for now */
1384 if (privptr->write_free_count < numBuffers ||
1385 privptr->p_write_free_chain == NULL ) {
1386
1387 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00001388 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 atomic_inc(&skb->users);
1390 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001391 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 goto Done2;
1393 }
1394 pDataAddress=skb->data;
1395 len_of_data=skb->len;
1396
1397 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1399 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb082010-08-12 01:58:27 +00001400 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 atomic_inc(&skb->users);
1402 skb_queue_tail(&ch->collect_queue, skb);
1403 goto Done2;
1404 }
1405 privptr->p_write_free_chain=p_this_ccw->next;
1406 p_this_ccw->next=NULL;
1407 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001408 if (len_of_data >= privptr->p_env->write_size)
1409 bytesInThisBuffer = privptr->p_env->write_size;
1410 else
1411 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1413 len_of_data-=bytesInThisBuffer;
1414 pDataAddress+=(unsigned long)bytesInThisBuffer;
1415 /* setup write CCW */
1416 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1417 if (len_of_data>0) {
1418 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1419 }
1420 p_this_ccw->write.count=bytesInThisBuffer;
1421 /* now add to end of this chain */
1422 if (p_first_ccw==NULL) {
1423 p_first_ccw=p_this_ccw;
1424 }
1425 if (p_last_ccw!=NULL) {
1426 p_last_ccw->next=p_this_ccw;
1427 /* set up TIC ccws */
1428 p_last_ccw->w_TIC_1.cda=
1429 (__u32)__pa(&p_this_ccw->write);
1430 }
1431 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 }
1433
1434 /* FirstCCW and LastCCW now contain a new set of write channel
1435 * programs to append to the running channel program
1436 */
1437
1438 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001439 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 pEnd=privptr->p_end_ccw;
1441 if (pEnd->write1) {
1442 pEnd->write1=0x00; /* second end ccw is now active */
1443 /* set up Tic CCWs */
1444 p_last_ccw->w_TIC_1.cda=
1445 (__u32)__pa(&pEnd->write2_nop1);
1446 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1447 pEnd->write2_nop2.flags =
1448 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1449 pEnd->write2_nop2.cda=0;
1450 pEnd->write2_nop2.count=1;
1451 }
1452 else { /* end of if (pEnd->write1)*/
1453 pEnd->write1=0x01; /* first end ccw is now active */
1454 /* set up Tic CCWs */
1455 p_last_ccw->w_TIC_1.cda=
1456 (__u32)__pa(&pEnd->write1_nop1);
1457 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1458 pEnd->write1_nop2.flags =
1459 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1460 pEnd->write1_nop2.cda=0;
1461 pEnd->write1_nop2.count=1;
1462 } /* end if if (pEnd->write1) */
1463
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 if (privptr->p_write_active_first==NULL ) {
1465 privptr->p_write_active_first=p_first_ccw;
1466 privptr->p_write_active_last=p_last_ccw;
1467 }
1468 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 /* set up Tic CCWs */
1470
1471 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1472 tempCCW.count=0;
1473 tempCCW.flags=0;
1474 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1475
1476 if (pEnd->write1) {
1477
1478 /*
1479 * first set of ending CCW's is chained to the new write
1480 * chain, so the second set is chained to the active chain
1481 * Therefore modify the second set to point the new write chain.
1482 * make sure we update the CCW atomically
1483 * so channel does not fetch it when it's only half done
1484 */
1485 memcpy( &pEnd->write2_nop2, &tempCCW ,
1486 sizeof(struct ccw1));
1487 privptr->p_write_active_last->w_TIC_1.cda=
1488 (__u32)__pa(&p_first_ccw->write);
1489 }
1490 else {
1491
1492 /*make sure we update the CCW atomically
1493 *so channel does not fetch it when it's only half done
1494 */
1495 memcpy(&pEnd->write1_nop2, &tempCCW ,
1496 sizeof(struct ccw1));
1497 privptr->p_write_active_last->w_TIC_1.cda=
1498 (__u32)__pa(&p_first_ccw->write);
1499
1500 } /* end if if (pEnd->write1) */
1501
1502 privptr->p_write_active_last->next=p_first_ccw;
1503 privptr->p_write_active_last=p_last_ccw;
1504 }
1505
1506 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001507 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 if (linkid==0) {
1509 lock=LOCK_NO;
1510 }
1511 else {
1512 lock=LOCK_YES;
1513 }
1514 claw_strt_out_IO(dev );
1515 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 if (privptr->write_free_count==0) {
1517 claw_setbit_busy(TB_NOBUFFER,dev);
1518 }
1519Done2:
1520 claw_clearbit_busy(TB_TX,dev);
1521Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 return(rc);
1523} /* end of claw_hw_tx */
1524
1525/*-------------------------------------------------------------------*
1526* *
1527* init_ccw_bk *
1528* *
1529*--------------------------------------------------------------------*/
1530
1531static int
1532init_ccw_bk(struct net_device *dev)
1533{
1534
1535 __u32 ccw_blocks_required;
1536 __u32 ccw_blocks_perpage;
1537 __u32 ccw_pages_required;
1538 __u32 claw_reads_perpage=1;
1539 __u32 claw_read_pages;
1540 __u32 claw_writes_perpage=1;
1541 __u32 claw_write_pages;
1542 void *p_buff=NULL;
1543 struct ccwbk*p_free_chain;
1544 struct ccwbk*p_buf;
1545 struct ccwbk*p_last_CCWB;
1546 struct ccwbk*p_first_CCWB;
1547 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001548 addr_t real_address;
1549 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 struct clawh *pClawH=NULL;
1551 addr_t real_TIC_address;
1552 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001553 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 /* initialize statistics field */
1556 privptr->active_link_ID=0;
1557 /* initialize ccwbk pointers */
1558 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1559 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1560 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1561 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1562 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1563 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1564 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1565 privptr->buffs_alloc = 0;
1566 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1567 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1568 /* initialize free write ccwbk counter */
1569 privptr->write_free_count=0; /* number of free bufs on write chain */
1570 p_last_CCWB = NULL;
1571 p_first_CCWB= NULL;
1572 /*
1573 * We need 1 CCW block for each read buffer, 1 for each
1574 * write buffer, plus 1 for ClawSignalBlock
1575 */
1576 ccw_blocks_required =
1577 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 /*
1579 * compute number of CCW blocks that will fit in a page
1580 */
1581 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1582 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001583 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 /*
1586 * read and write sizes are set by 2 constants in claw.h
1587 * 4k and 32k. Unpacked values other than 4k are not going to
1588 * provide good performance. With packing buffers support 32k
1589 * buffers are used.
1590 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001591 if (privptr->p_env->read_size < PAGE_SIZE) {
1592 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1593 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1594 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 }
1596 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001597 privptr->p_buff_pages_perread =
1598 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1599 claw_read_pages = privptr->p_env->read_buffers *
1600 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 }
1602 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001603 claw_writes_perpage =
1604 PAGE_SIZE / privptr->p_env->write_size;
1605 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1606 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
1608 }
1609 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001610 privptr->p_buff_pages_perwrite =
1611 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1612 claw_write_pages = privptr->p_env->write_buffers *
1613 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 /*
1616 * allocate ccw_pages_required
1617 */
1618 if (privptr->p_buff_ccw==NULL) {
1619 privptr->p_buff_ccw=
1620 (void *)__get_free_pages(__GFP_DMA,
1621 (int)pages_to_order_of_mag(ccw_pages_required ));
1622 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 return -ENOMEM;
1624 }
1625 privptr->p_buff_ccw_num=ccw_pages_required;
1626 }
1627 memset(privptr->p_buff_ccw, 0x00,
1628 privptr->p_buff_ccw_num * PAGE_SIZE);
1629
1630 /*
1631 * obtain ending ccw block address
1632 *
1633 */
1634 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1635 real_address = (__u32)__pa(privptr->p_end_ccw);
1636 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 p_endccw=privptr->p_end_ccw;
1638 p_endccw->real=real_address;
1639 p_endccw->write1=0x00;
1640 p_endccw->read1=0x00;
1641
1642 /* write1_nop1 */
1643 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1644 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1645 p_endccw->write1_nop1.count = 1;
1646 p_endccw->write1_nop1.cda = 0;
1647
1648 /* write1_nop2 */
1649 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1650 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1651 p_endccw->write1_nop2.count = 1;
1652 p_endccw->write1_nop2.cda = 0;
1653
1654 /* write2_nop1 */
1655 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1656 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1657 p_endccw->write2_nop1.count = 1;
1658 p_endccw->write2_nop1.cda = 0;
1659
1660 /* write2_nop2 */
1661 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1662 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1663 p_endccw->write2_nop2.count = 1;
1664 p_endccw->write2_nop2.cda = 0;
1665
1666 /* read1_nop1 */
1667 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1668 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1669 p_endccw->read1_nop1.count = 1;
1670 p_endccw->read1_nop1.cda = 0;
1671
1672 /* read1_nop2 */
1673 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1674 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1675 p_endccw->read1_nop2.count = 1;
1676 p_endccw->read1_nop2.cda = 0;
1677
1678 /* read2_nop1 */
1679 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1680 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1681 p_endccw->read2_nop1.count = 1;
1682 p_endccw->read2_nop1.cda = 0;
1683
1684 /* read2_nop2 */
1685 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1686 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1687 p_endccw->read2_nop2.count = 1;
1688 p_endccw->read2_nop2.cda = 0;
1689
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 /*
1691 * Build a chain of CCWs
1692 *
1693 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 p_buff=privptr->p_buff_ccw;
1695
1696 p_free_chain=NULL;
1697 for (i=0 ; i < ccw_pages_required; i++ ) {
1698 real_address = (__u32)__pa(p_buff);
1699 p_buf=p_buff;
1700 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1701 p_buf->next = p_free_chain;
1702 p_free_chain = p_buf;
1703 p_buf->real=(__u32)__pa(p_buf);
1704 ++p_buf;
1705 }
1706 p_buff+=PAGE_SIZE;
1707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 /*
1709 * Initialize ClawSignalBlock
1710 *
1711 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 if (privptr->p_claw_signal_blk==NULL) {
1713 privptr->p_claw_signal_blk=p_free_chain;
1714 p_free_chain=p_free_chain->next;
1715 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1716 pClawH->length=0xffff;
1717 pClawH->opcode=0xff;
1718 pClawH->flag=CLAW_BUSY;
1719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720
1721 /*
1722 * allocate write_pages_required and add to free chain
1723 */
1724 if (privptr->p_buff_write==NULL) {
1725 if (privptr->p_env->write_size < PAGE_SIZE) {
1726 privptr->p_buff_write=
1727 (void *)__get_free_pages(__GFP_DMA,
1728 (int)pages_to_order_of_mag(claw_write_pages ));
1729 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 return -ENOMEM;
1732 }
1733 /*
1734 * Build CLAW write free chain
1735 *
1736 */
1737
1738 memset(privptr->p_buff_write, 0x00,
1739 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 privptr->p_write_free_chain=NULL;
1741
1742 p_buff=privptr->p_buff_write;
1743
1744 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1745 p_buf = p_free_chain; /* get a CCW */
1746 p_free_chain = p_buf->next;
1747 p_buf->next =privptr->p_write_free_chain;
1748 privptr->p_write_free_chain = p_buf;
1749 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1750 p_buf-> write.cda = (__u32)__pa(p_buff);
1751 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1752 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1753 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1754 p_buf-> w_read_FF.count = 1;
1755 p_buf-> w_read_FF.cda =
1756 (__u32)__pa(&p_buf-> header.flag);
1757 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1758 p_buf-> w_TIC_1.flags = 0;
1759 p_buf-> w_TIC_1.count = 0;
1760
Andy Richter4811fcb2009-01-20 06:14:33 +00001761 if (((unsigned long)p_buff +
1762 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001764 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1765 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 }
1767 }
1768 }
1769 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1770 {
1771 privptr->p_write_free_chain=NULL;
1772 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1773 p_buff=(void *)__get_free_pages(__GFP_DMA,
1774 (int)pages_to_order_of_mag(
1775 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 free_pages((unsigned long)privptr->p_buff_ccw,
1778 (int)pages_to_order_of_mag(
1779 privptr->p_buff_ccw_num));
1780 privptr->p_buff_ccw=NULL;
1781 p_buf=privptr->p_buff_write;
1782 while (p_buf!=NULL) {
1783 free_pages((unsigned long)
1784 p_buf->p_buffer,
1785 (int)pages_to_order_of_mag(
1786 privptr->p_buff_pages_perwrite));
1787 p_buf=p_buf->next;
1788 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 return -ENOMEM;
1790 } /* Error on get_pages */
1791 memset(p_buff, 0x00, privptr->p_env->write_size );
1792 p_buf = p_free_chain;
1793 p_free_chain = p_buf->next;
1794 p_buf->next = privptr->p_write_free_chain;
1795 privptr->p_write_free_chain = p_buf;
1796 privptr->p_buff_write = p_buf;
1797 p_buf->p_buffer=(struct clawbuf *)p_buff;
1798 p_buf-> write.cda = (__u32)__pa(p_buff);
1799 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1800 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1801 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1802 p_buf-> w_read_FF.count = 1;
1803 p_buf-> w_read_FF.cda =
1804 (__u32)__pa(&p_buf-> header.flag);
1805 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1806 p_buf-> w_TIC_1.flags = 0;
1807 p_buf-> w_TIC_1.count = 0;
1808 } /* for all write_buffers */
1809
1810 } /* else buffers are PAGE_SIZE or bigger */
1811
1812 }
1813 privptr->p_buff_write_num=claw_write_pages;
1814 privptr->write_free_count=privptr->p_env->write_buffers;
1815
1816
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 /*
1818 * allocate read_pages_required and chain to free chain
1819 */
1820 if (privptr->p_buff_read==NULL) {
1821 if (privptr->p_env->read_size < PAGE_SIZE) {
1822 privptr->p_buff_read=
1823 (void *)__get_free_pages(__GFP_DMA,
1824 (int)pages_to_order_of_mag(claw_read_pages) );
1825 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 free_pages((unsigned long)privptr->p_buff_ccw,
1827 (int)pages_to_order_of_mag(
1828 privptr->p_buff_ccw_num));
1829 /* free the write pages size is < page size */
1830 free_pages((unsigned long)privptr->p_buff_write,
1831 (int)pages_to_order_of_mag(
1832 privptr->p_buff_write_num));
1833 privptr->p_buff_ccw=NULL;
1834 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 return -ENOMEM;
1836 }
1837 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1838 privptr->p_buff_read_num=claw_read_pages;
1839 /*
1840 * Build CLAW read free chain
1841 *
1842 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 p_buff=privptr->p_buff_read;
1844 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1845 p_buf = p_free_chain;
1846 p_free_chain = p_buf->next;
1847
1848 if (p_last_CCWB==NULL) {
1849 p_buf->next=NULL;
1850 real_TIC_address=0;
1851 p_last_CCWB=p_buf;
1852 }
1853 else {
1854 p_buf->next=p_first_CCWB;
1855 real_TIC_address=
1856 (__u32)__pa(&p_first_CCWB -> read );
1857 }
1858
1859 p_first_CCWB=p_buf;
1860
1861 p_buf->p_buffer=(struct clawbuf *)p_buff;
1862 /* initialize read command */
1863 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1864 p_buf-> read.cda = (__u32)__pa(p_buff);
1865 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1866 p_buf-> read.count = privptr->p_env->read_size;
1867
1868 /* initialize read_h command */
1869 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1870 p_buf-> read_h.cda =
1871 (__u32)__pa(&(p_buf->header));
1872 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1873 p_buf-> read_h.count = sizeof(struct clawh);
1874
1875 /* initialize Signal command */
1876 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1877 p_buf-> signal.cda =
1878 (__u32)__pa(&(pClawH->flag));
1879 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1880 p_buf-> signal.count = 1;
1881
1882 /* initialize r_TIC_1 command */
1883 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1884 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1885 p_buf-> r_TIC_1.flags = 0;
1886 p_buf-> r_TIC_1.count = 0;
1887
1888 /* initialize r_read_FF command */
1889 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1890 p_buf-> r_read_FF.cda =
1891 (__u32)__pa(&(pClawH->flag));
1892 p_buf-> r_read_FF.flags =
1893 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1894 p_buf-> r_read_FF.count = 1;
1895
1896 /* initialize r_TIC_2 */
1897 memcpy(&p_buf->r_TIC_2,
1898 &p_buf->r_TIC_1, sizeof(struct ccw1));
1899
1900 /* initialize Header */
1901 p_buf->header.length=0xffff;
1902 p_buf->header.opcode=0xff;
1903 p_buf->header.flag=CLAW_PENDING;
1904
Andy Richter4811fcb2009-01-20 06:14:33 +00001905 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1906 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1907 -1)
1908 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 p_buff= p_buff+privptr->p_env->read_size;
1910 }
1911 else {
1912 p_buff=
1913 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001914 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 & PAGE_MASK) ;
1916 }
1917 } /* for read_buffers */
1918 } /* read_size < PAGE_SIZE */
1919 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1921 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001922 (int)pages_to_order_of_mag(
1923 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001926 (int)pages_to_order_of_mag(privptr->
1927 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 /* free the write pages */
1929 p_buf=privptr->p_buff_write;
1930 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001931 free_pages(
1932 (unsigned long)p_buf->p_buffer,
1933 (int)pages_to_order_of_mag(
1934 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 p_buf=p_buf->next;
1936 }
1937 /* free any read pages already alloc */
1938 p_buf=privptr->p_buff_read;
1939 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001940 free_pages(
1941 (unsigned long)p_buf->p_buffer,
1942 (int)pages_to_order_of_mag(
1943 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 p_buf=p_buf->next;
1945 }
1946 privptr->p_buff_ccw=NULL;
1947 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 return -ENOMEM;
1949 }
1950 memset(p_buff, 0x00, privptr->p_env->read_size);
1951 p_buf = p_free_chain;
1952 privptr->p_buff_read = p_buf;
1953 p_free_chain = p_buf->next;
1954
1955 if (p_last_CCWB==NULL) {
1956 p_buf->next=NULL;
1957 real_TIC_address=0;
1958 p_last_CCWB=p_buf;
1959 }
1960 else {
1961 p_buf->next=p_first_CCWB;
1962 real_TIC_address=
1963 (addr_t)__pa(
1964 &p_first_CCWB -> read );
1965 }
1966
1967 p_first_CCWB=p_buf;
1968 /* save buff address */
1969 p_buf->p_buffer=(struct clawbuf *)p_buff;
1970 /* initialize read command */
1971 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1972 p_buf-> read.cda = (__u32)__pa(p_buff);
1973 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1974 p_buf-> read.count = privptr->p_env->read_size;
1975
1976 /* initialize read_h command */
1977 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1978 p_buf-> read_h.cda =
1979 (__u32)__pa(&(p_buf->header));
1980 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1981 p_buf-> read_h.count = sizeof(struct clawh);
1982
1983 /* initialize Signal command */
1984 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1985 p_buf-> signal.cda =
1986 (__u32)__pa(&(pClawH->flag));
1987 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1988 p_buf-> signal.count = 1;
1989
1990 /* initialize r_TIC_1 command */
1991 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1992 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1993 p_buf-> r_TIC_1.flags = 0;
1994 p_buf-> r_TIC_1.count = 0;
1995
1996 /* initialize r_read_FF command */
1997 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1998 p_buf-> r_read_FF.cda =
1999 (__u32)__pa(&(pClawH->flag));
2000 p_buf-> r_read_FF.flags =
2001 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
2002 p_buf-> r_read_FF.count = 1;
2003
2004 /* initialize r_TIC_2 */
2005 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
2006 sizeof(struct ccw1));
2007
2008 /* initialize Header */
2009 p_buf->header.length=0xffff;
2010 p_buf->header.opcode=0xff;
2011 p_buf->header.flag=CLAW_PENDING;
2012
2013 } /* For read_buffers */
2014 } /* read_size >= PAGE_SIZE */
2015 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
2017 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02002018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 return 0;
2020} /* end of init_ccw_bk */
2021
2022/*-------------------------------------------------------------------*
2023* *
2024* probe_error *
2025* *
2026*--------------------------------------------------------------------*/
2027
2028static void
2029probe_error( struct ccwgroup_device *cgdev)
2030{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002031 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002032
2033 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002034 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002035 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002036 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08002037 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002038 kfree(privptr->p_mtc_envelope);
2039 kfree(privptr);
2040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041} /* probe_error */
2042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043/*-------------------------------------------------------------------*
2044* claw_process_control *
2045* *
2046* *
2047*--------------------------------------------------------------------*/
2048
2049static int
2050claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2051{
2052
2053 struct clawbuf *p_buf;
2054 struct clawctl ctlbk;
2055 struct clawctl *p_ctlbk;
2056 char temp_host_name[8];
2057 char temp_ws_name[8];
2058 struct claw_privbk *privptr;
2059 struct claw_env *p_env;
2060 struct sysval *p_sysval;
2061 struct conncmd *p_connect=NULL;
2062 int rc;
2063 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002064 struct device *tdev;
2065 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 udelay(1000); /* Wait a ms for the control packets to
2067 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02002068 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 p_env=privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002070 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 memcpy( &temp_host_name, p_env->host_name, 8);
2072 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002073 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 "Received Control Packet\n",
2075 dev->name, temp_ws_name);
2076 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 return 0;
2078 }
2079 p_buf=p_ccw->p_buffer;
2080 p_ctlbk=&ctlbk;
2081 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2082 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2083 } else {
2084 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 switch (p_ctlbk->command)
2087 {
Andy Richterb805da72008-07-18 15:24:56 +02002088 case SYSTEM_VALIDATE_REQUEST:
2089 if (p_ctlbk->version != CLAW_VERSION_ID) {
2090 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2091 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002092 dev_warn(tdev, "The communication peer of %s"
2093 " uses an incorrect API version %d\n",
2094 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002095 }
2096 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002097 dev_info(tdev, "%s: Recv Sys Validate Request: "
2098 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2099 "Host name=%.8s\n",
2100 dev->name, p_ctlbk->version,
2101 p_ctlbk->linkid,
2102 p_ctlbk->correlator,
2103 p_sysval->WS_name,
2104 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002105 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2106 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2107 CLAW_RC_NAME_MISMATCH);
2108 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2109 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2110 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002111 dev_warn(tdev,
2112 "Host name %s for %s does not match the"
2113 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002114 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002115 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002116 temp_host_name);
2117 }
2118 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2119 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2120 CLAW_RC_NAME_MISMATCH);
2121 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2122 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2123 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002124 dev_warn(tdev, "Adapter name %s for %s does not match"
2125 " the remote host name %s\n",
2126 p_sysval->WS_name,
2127 dev->name,
2128 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002129 }
2130 if ((p_sysval->write_frame_size < p_env->write_size) &&
2131 (p_env->packing == 0)) {
2132 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2133 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002134 dev_warn(tdev,
2135 "The local write buffer is smaller than the"
2136 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002137 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2138 }
2139 if ((p_sysval->read_frame_size < p_env->read_size) &&
2140 (p_env->packing == 0)) {
2141 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2142 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002143 dev_warn(tdev,
2144 "The local read buffer is smaller than the"
2145 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002146 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2147 }
2148 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002149 dev_info(tdev,
2150 "CLAW device %.8s: System validate"
2151 " completed.\n", temp_ws_name);
2152 dev_info(tdev,
2153 "%s: sys Validate Rsize:%d Wsize:%d\n",
2154 dev->name, p_sysval->read_frame_size,
2155 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002156 privptr->system_validate_comp = 1;
2157 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2158 p_env->packing = PACKING_ASK;
2159 claw_strt_conn_req(dev);
2160 break;
2161 case SYSTEM_VALIDATE_RESPONSE:
2162 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002163 dev_info(tdev,
2164 "Settings for %s validated (version=%d, "
2165 "remote device=%d, rc=%d, adapter name=%.8s, "
2166 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002167 dev->name,
2168 p_ctlbk->version,
2169 p_ctlbk->correlator,
2170 p_ctlbk->rc,
2171 p_sysval->WS_name,
2172 p_sysval->host_name);
2173 switch (p_ctlbk->rc) {
2174 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002175 dev_info(tdev, "%s: CLAW device "
2176 "%.8s: System validate completed.\n",
2177 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002178 if (privptr->system_validate_comp == 0)
2179 claw_strt_conn_req(dev);
2180 privptr->system_validate_comp = 1;
2181 break;
2182 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002183 dev_warn(tdev, "Validating %s failed because of"
2184 " a host or adapter name mismatch\n",
2185 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002186 break;
2187 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002188 dev_warn(tdev, "Validating %s failed because of a"
2189 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002190 dev->name);
2191 break;
2192 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002193 dev_warn(tdev, "Validating %s failed because of a"
2194 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002195 dev->name);
2196 break;
2197 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002198 dev_warn(tdev, "The communication peer of %s rejected"
2199 " the connection\n",
2200 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002201 break;
2202 }
2203 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Andy Richterb805da72008-07-18 15:24:56 +02002205 case CONNECTION_REQUEST:
2206 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002207 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002208 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2209 dev->name,
2210 p_ctlbk->version,
2211 p_ctlbk->linkid,
2212 p_ctlbk->correlator,
2213 p_connect->host_name,
2214 p_connect->WS_name);
2215 if (privptr->active_link_ID != 0) {
2216 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002217 dev_info(tdev, "%s rejected a connection request"
2218 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002219 dev->name);
2220 }
2221 if (p_ctlbk->linkid != 1) {
2222 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002223 dev_info(tdev, "%s rejected a request to open multiple"
2224 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002225 dev->name);
2226 }
2227 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2228 if (rc != 0) {
2229 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002230 dev_info(tdev, "%s rejected a connection request"
2231 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002232 dev->name);
2233 }
2234 claw_send_control(dev,
2235 CONNECTION_CONFIRM, p_ctlbk->linkid,
2236 p_ctlbk->correlator,
2237 0, p_connect->host_name,
2238 p_connect->WS_name);
2239 if (p_env->packing == PACKING_ASK) {
2240 p_env->packing = PACK_SEND;
2241 claw_snd_conn_req(dev, 0);
2242 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002243 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002244 "completed link_id=%d.\n",
2245 dev->name, temp_ws_name,
2246 p_ctlbk->linkid);
2247 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb082010-08-12 01:58:27 +00002248 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002249 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2250 break;
2251 case CONNECTION_RESPONSE:
2252 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002253 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002254 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2255 dev->name,
2256 p_ctlbk->version,
2257 p_ctlbk->linkid,
2258 p_ctlbk->correlator,
2259 p_ctlbk->rc,
2260 p_connect->host_name,
2261 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
Andy Richterb805da72008-07-18 15:24:56 +02002263 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002264 dev_warn(tdev, "The communication peer of %s rejected"
2265 " a connection request\n",
2266 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002267 return 1;
2268 }
2269 rc = find_link(dev,
2270 p_connect->host_name, p_connect->WS_name);
2271 if (rc != 0) {
2272 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002273 dev_warn(tdev, "The communication peer of %s"
2274 " rejected a connection "
2275 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002276 dev->name);
2277 }
2278 /* should be until CONNECTION_CONFIRM */
2279 privptr->active_link_ID = -(p_ctlbk->linkid);
2280 break;
2281 case CONNECTION_CONFIRM:
2282 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002283 dev_info(tdev,
2284 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002285 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2286 dev->name,
2287 p_ctlbk->version,
2288 p_ctlbk->linkid,
2289 p_ctlbk->correlator,
2290 p_connect->host_name,
2291 p_connect->WS_name);
2292 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2293 privptr->active_link_ID = p_ctlbk->linkid;
2294 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002295 dev_info(tdev,
2296 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 p_env->packing = DO_PACKED;
2298 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002299 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002300 wake_up(&p_ch->wait);
2301 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002302 dev_warn(tdev, "Activating %s failed because of"
2303 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002304 dev->name, p_ctlbk->linkid);
2305 claw_snd_disc(dev, p_ctlbk);
2306 }
2307 break;
2308 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002309 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002310 "Vers=%d,link_id=%d,Corr=%d\n",
2311 dev->name, p_ctlbk->version,
2312 p_ctlbk->linkid, p_ctlbk->correlator);
2313 if ((p_ctlbk->linkid == 2) &&
2314 (p_env->packing == PACK_SEND)) {
2315 privptr->active_link_ID = 1;
2316 p_env->packing = DO_PACKED;
2317 } else
2318 privptr->active_link_ID = 0;
2319 break;
2320 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002321 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002322 dev->name);
2323 break;
2324 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002325 dev_warn(tdev, "The communication peer of %s sent"
2326 " an unknown command code\n",
2327 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002328 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 }
2330
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 return 0;
2332} /* end of claw_process_control */
2333
2334
2335/*-------------------------------------------------------------------*
2336* claw_send_control *
2337* *
2338*--------------------------------------------------------------------*/
2339
2340static int
2341claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2342 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2343{
2344 struct claw_privbk *privptr;
2345 struct clawctl *p_ctl;
2346 struct sysval *p_sysval;
2347 struct conncmd *p_connect;
2348 struct sk_buff *skb;
2349
Andy Richterb805da72008-07-18 15:24:56 +02002350 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002351 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2353
2354 p_ctl->command=type;
2355 p_ctl->version=CLAW_VERSION_ID;
2356 p_ctl->linkid=link;
2357 p_ctl->correlator=correlator;
2358 p_ctl->rc=rc;
2359
2360 p_sysval=(struct sysval *)&p_ctl->data;
2361 p_connect=(struct conncmd *)&p_ctl->data;
2362
2363 switch (p_ctl->command) {
2364 case SYSTEM_VALIDATE_REQUEST:
2365 case SYSTEM_VALIDATE_RESPONSE:
2366 memcpy(&p_sysval->host_name, local_name, 8);
2367 memcpy(&p_sysval->WS_name, remote_name, 8);
2368 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002369 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2370 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002372 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002373 p_sysval->read_frame_size =
2374 privptr->p_env->read_size;
2375 p_sysval->write_frame_size =
2376 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 }
2378 memset(&p_sysval->reserved, 0x00, 4);
2379 break;
2380 case CONNECTION_REQUEST:
2381 case CONNECTION_RESPONSE:
2382 case CONNECTION_CONFIRM:
2383 case DISCONNECT:
2384 memcpy(&p_sysval->host_name, local_name, 8);
2385 memcpy(&p_sysval->WS_name, remote_name, 8);
2386 if (privptr->p_env->packing > 0) {
2387 /* How big is the biggest packet */
2388 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2389 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2390 } else {
2391 memset(&p_connect->reserved1, 0x00, 4);
2392 memset(&p_connect->reserved2, 0x00, 4);
2393 }
2394 break;
2395 default:
2396 break;
2397 }
2398
2399 /* write Control Record to the device */
2400
2401
2402 skb = dev_alloc_skb(sizeof(struct clawctl));
2403 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 return -ENOMEM;
2405 }
2406 memcpy(skb_put(skb, sizeof(struct clawctl)),
2407 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 if (privptr->p_env->packing >= PACK_SEND)
2409 claw_hw_tx(skb, dev, 1);
2410 else
2411 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 return 0;
2413} /* end of claw_send_control */
2414
2415/*-------------------------------------------------------------------*
2416* claw_snd_conn_req *
2417* *
2418*--------------------------------------------------------------------*/
2419static int
2420claw_snd_conn_req(struct net_device *dev, __u8 link)
2421{
2422 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002423 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 struct clawctl *p_ctl;
2425
Andy Richterb805da72008-07-18 15:24:56 +02002426 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 rc = 1;
2428 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2429 p_ctl->linkid = link;
2430 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 return rc;
2432 }
2433 if (privptr->p_env->packing == PACKING_ASK )
2434 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2435 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2436 if (privptr->p_env->packing == PACK_SEND) {
2437 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2438 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2439 }
2440 if (privptr->p_env->packing == 0)
2441 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2442 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 return rc;
2444
2445} /* end of claw_snd_conn_req */
2446
2447
2448/*-------------------------------------------------------------------*
2449* claw_snd_disc *
2450* *
2451*--------------------------------------------------------------------*/
2452
2453static int
2454claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2455{
2456 int rc;
2457 struct conncmd * p_connect;
2458
Andy Richterb805da72008-07-18 15:24:56 +02002459 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 p_connect=(struct conncmd *)&p_ctl->data;
2461
2462 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2463 p_ctl->correlator, 0,
2464 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 return rc;
2466} /* end of claw_snd_disc */
2467
2468
2469/*-------------------------------------------------------------------*
2470* claw_snd_sys_validate_rsp *
2471* *
2472*--------------------------------------------------------------------*/
2473
2474static int
2475claw_snd_sys_validate_rsp(struct net_device *dev,
2476 struct clawctl *p_ctl, __u32 return_code)
2477{
2478 struct claw_env * p_env;
2479 struct claw_privbk *privptr;
2480 int rc;
2481
Andy Richterb805da72008-07-18 15:24:56 +02002482 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002483 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 p_env=privptr->p_env;
2485 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2486 p_ctl->linkid,
2487 p_ctl->correlator,
2488 return_code,
2489 p_env->host_name,
2490 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 return rc;
2492} /* end of claw_snd_sys_validate_rsp */
2493
2494/*-------------------------------------------------------------------*
2495* claw_strt_conn_req *
2496* *
2497*--------------------------------------------------------------------*/
2498
2499static int
2500claw_strt_conn_req(struct net_device *dev )
2501{
2502 int rc;
2503
Andy Richterb805da72008-07-18 15:24:56 +02002504 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 return rc;
2507} /* end of claw_strt_conn_req */
2508
2509
2510
2511/*-------------------------------------------------------------------*
2512 * claw_stats *
2513 *-------------------------------------------------------------------*/
2514
2515static struct
2516net_device_stats *claw_stats(struct net_device *dev)
2517{
2518 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002519
2520 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002521 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 return &privptr->stats;
2523} /* end of claw_stats */
2524
2525
2526/*-------------------------------------------------------------------*
2527* unpack_read *
2528* *
2529*--------------------------------------------------------------------*/
2530static void
2531unpack_read(struct net_device *dev )
2532{
2533 struct sk_buff *skb;
2534 struct claw_privbk *privptr;
2535 struct claw_env *p_env;
2536 struct ccwbk *p_this_ccw;
2537 struct ccwbk *p_first_ccw;
2538 struct ccwbk *p_last_ccw;
2539 struct clawph *p_packh;
2540 void *p_packd;
2541 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002542 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543
2544 __u32 len_of_data;
2545 __u32 pack_off;
2546 __u8 link_num;
2547 __u8 mtc_this_frm=0;
2548 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 int i=0;
2550 int p=0;
2551
Andy Richterb805da72008-07-18 15:24:56 +02002552 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 p_first_ccw=NULL;
2554 p_last_ccw=NULL;
2555 p_packh=NULL;
2556 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002557 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002558
Heiko Carstens319cb082010-08-12 01:58:27 +00002559 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 p_env = privptr->p_env;
2561 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 pack_off = 0;
2564 p = 0;
2565 p_this_ccw->header.flag=CLAW_PENDING;
2566 privptr->p_read_active_first=p_this_ccw->next;
2567 p_this_ccw->next=NULL;
2568 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2569 if ((p_env->packing == PACK_SEND) &&
2570 (p_packh->len == 32) &&
2571 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2572 p_packh++; /* peek past pack header */
2573 p_ctlrec = (struct clawctl *)p_packh;
2574 p_packh--; /* un peek */
2575 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2576 (p_ctlrec->command == CONNECTION_CONFIRM))
2577 p_env->packing = DO_PACKED;
2578 }
2579 if (p_env->packing == DO_PACKED)
2580 link_num=p_packh->link_num;
2581 else
2582 link_num=p_this_ccw->header.opcode / 8;
2583 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 mtc_this_frm=1;
2585 if (p_this_ccw->header.length!=
2586 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002587 dev_warn(p_dev,
2588 "The communication peer of %s"
2589 " sent a faulty"
2590 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 dev->name, p_this_ccw->header.length);
2592 }
2593 }
2594
2595 if (privptr->mtc_skipping) {
2596 /*
2597 * We're in the mode of skipping past a
2598 * multi-frame message
2599 * that we can't process for some reason or other.
2600 * The first frame without the More-To-Come flag is
2601 * the last frame of the skipped message.
2602 */
2603 /* in case of More-To-Come not set in this frame */
2604 if (mtc_this_frm==0) {
2605 privptr->mtc_skipping=0; /* Ok, the end */
2606 privptr->mtc_logical_link=-1;
2607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 goto NextFrame;
2609 }
2610
2611 if (link_num==0) {
2612 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002613 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 goto NextFrame;
2615 }
2616unpack_next:
2617 if (p_env->packing == DO_PACKED) {
2618 if (pack_off > p_env->read_size)
2619 goto NextFrame;
2620 p_packd = p_this_ccw->p_buffer+pack_off;
2621 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002622 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 (p_packh->flag != 0))
2624 goto NextFrame;
2625 bytes_to_mov = p_packh->len;
2626 pack_off += bytes_to_mov+sizeof(struct clawph);
2627 p++;
2628 } else {
2629 bytes_to_mov=p_this_ccw->header.length;
2630 }
2631 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
2633 /*
2634 * if More-To-Come is set in this frame then we don't know
2635 * length of entire message, and hence have to allocate
2636 * large buffer */
2637
2638 /* We are starting a new envelope */
2639 privptr->mtc_offset=0;
2640 privptr->mtc_logical_link=link_num;
2641 }
2642
2643 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2644 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 privptr->stats.rx_frame_errors++;
2646 goto NextFrame;
2647 }
2648 if (p_env->packing == DO_PACKED) {
2649 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2650 p_packd+sizeof(struct clawph), bytes_to_mov);
2651
2652 } else {
2653 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2654 p_this_ccw->p_buffer, bytes_to_mov);
2655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 if (mtc_this_frm==0) {
2657 len_of_data=privptr->mtc_offset+bytes_to_mov;
2658 skb=dev_alloc_skb(len_of_data);
2659 if (skb) {
2660 memcpy(skb_put(skb,len_of_data),
2661 privptr->p_mtc_envelope,
2662 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002664 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 skb->protocol=htons(ETH_P_IP);
2666 skb->ip_summed=CHECKSUM_UNNECESSARY;
2667 privptr->stats.rx_packets++;
2668 privptr->stats.rx_bytes+=len_of_data;
2669 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 }
2671 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002672 dev_info(p_dev, "Allocating a buffer for"
2673 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 }
2676 privptr->mtc_offset=0;
2677 privptr->mtc_logical_link=-1;
2678 }
2679 else {
2680 privptr->mtc_offset+=bytes_to_mov;
2681 }
2682 if (p_env->packing == DO_PACKED)
2683 goto unpack_next;
2684NextFrame:
2685 /*
2686 * Remove ThisCCWblock from active read queue, and add it
2687 * to queue of free blocks to be reused.
2688 */
2689 i++;
2690 p_this_ccw->header.length=0xffff;
2691 p_this_ccw->header.opcode=0xff;
2692 /*
2693 * add this one to the free queue for later reuse
2694 */
2695 if (p_first_ccw==NULL) {
2696 p_first_ccw = p_this_ccw;
2697 }
2698 else {
2699 p_last_ccw->next = p_this_ccw;
2700 }
2701 p_last_ccw = p_this_ccw;
2702 /*
2703 * chain to next block on active read queue
2704 */
2705 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002706 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 } /* end of while */
2708
2709 /* check validity */
2710
Andy Richterb805da72008-07-18 15:24:56 +02002711 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 return;
2715} /* end of unpack_read */
2716
2717/*-------------------------------------------------------------------*
2718* claw_strt_read *
2719* *
2720*--------------------------------------------------------------------*/
2721static void
2722claw_strt_read (struct net_device *dev, int lock )
2723{
2724 int rc = 0;
2725 __u32 parm;
2726 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002727 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 struct ccwbk*p_ccwbk;
2729 struct chbk *p_ch;
2730 struct clawh *p_clawh;
Heiko Carstens319cb082010-08-12 01:58:27 +00002731 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
Andy Richterb805da72008-07-18 15:24:56 +02002733 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2735 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2736
2737 if ((privptr->p_write_active_first!=NULL &&
2738 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2739 (privptr->p_read_active_first!=NULL &&
2740 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2741 p_clawh->flag=CLAW_BUSY; /* 0xff */
2742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 if (lock==LOCK_YES) {
2744 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2745 }
2746 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002747 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 p_ccwbk=privptr->p_read_active_first;
2749 parm = (unsigned long) p_ch;
2750 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2751 0xff, 0);
2752 if (rc != 0) {
2753 ccw_check_return_code(p_ch->cdev, rc);
2754 }
2755 }
2756 else {
Andy Richterb805da72008-07-18 15:24:56 +02002757 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 }
2759
2760 if (lock==LOCK_YES) {
2761 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2762 }
Andy Richterb805da72008-07-18 15:24:56 +02002763 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 return;
2765} /* end of claw_strt_read */
2766
2767/*-------------------------------------------------------------------*
2768* claw_strt_out_IO *
2769* *
2770*--------------------------------------------------------------------*/
2771
2772static void
2773claw_strt_out_IO( struct net_device *dev )
2774{
2775 int rc = 0;
2776 unsigned long parm;
2777 struct claw_privbk *privptr;
2778 struct chbk *p_ch;
2779 struct ccwbk *p_first_ccw;
2780
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 if (!dev) {
2782 return;
2783 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002784 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb082010-08-12 01:58:27 +00002785 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
Andy Richterb805da72008-07-18 15:24:56 +02002787 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 p_first_ccw=privptr->p_write_active_first;
2789
2790 if (p_ch->claw_state == CLAW_STOP)
2791 return;
2792 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 return;
2794 }
2795 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2796 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002797 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002798 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2799 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 if (rc != 0) {
2801 ccw_check_return_code(p_ch->cdev, rc);
2802 }
2803 }
2804 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 return;
2806} /* end of claw_strt_out_IO */
2807
2808/*-------------------------------------------------------------------*
2809* Free write buffers *
2810* *
2811*--------------------------------------------------------------------*/
2812
2813static void
2814claw_free_wrt_buf( struct net_device *dev )
2815{
2816
Peter Tiedemann6951df32008-08-21 17:10:23 +02002817 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 struct ccwbk*p_first_ccw;
2819 struct ccwbk*p_last_ccw;
2820 struct ccwbk*p_this_ccw;
2821 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002822
2823 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 /* scan the write queue to free any completed write packets */
2825 p_first_ccw=NULL;
2826 p_last_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 p_this_ccw=privptr->p_write_active_first;
2828 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2829 {
2830 p_next_ccw = p_this_ccw->next;
2831 if (((p_next_ccw!=NULL) &&
2832 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2833 ((p_this_ccw == privptr->p_write_active_last) &&
2834 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2835 /* The next CCW is OK or this is */
2836 /* the last CCW...free it @A1A */
2837 privptr->p_write_active_first=p_this_ccw->next;
2838 p_this_ccw->header.flag=CLAW_PENDING;
2839 p_this_ccw->next=privptr->p_write_free_chain;
2840 privptr->p_write_free_chain=p_this_ccw;
2841 ++privptr->write_free_count;
2842 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2843 p_this_ccw=privptr->p_write_active_first;
2844 privptr->stats.tx_packets++;
2845 }
2846 else {
2847 break;
2848 }
2849 }
2850 if (privptr->write_free_count!=0) {
2851 claw_clearbit_busy(TB_NOBUFFER,dev);
2852 }
2853 /* whole chain removed? */
2854 if (privptr->p_write_active_first==NULL) {
2855 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 }
Andy Richterb805da72008-07-18 15:24:56 +02002857 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 return;
2859}
2860
2861/*-------------------------------------------------------------------*
2862* claw free netdevice *
2863* *
2864*--------------------------------------------------------------------*/
2865static void
2866claw_free_netdevice(struct net_device * dev, int free_dev)
2867{
2868 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869
Andy Richterb805da72008-07-18 15:24:56 +02002870 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 if (!dev)
2872 return;
Andy Richterb805da72008-07-18 15:24:56 +02002873 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002874 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 if (dev->flags & IFF_RUNNING)
2876 claw_release(dev);
2877 if (privptr) {
Heiko Carstens319cb082010-08-12 01:58:27 +00002878 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002880 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881#ifdef MODULE
2882 if (free_dev) {
2883 free_netdev(dev);
2884 }
2885#endif
Andy Richterb805da72008-07-18 15:24:56 +02002886 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887}
2888
2889/**
2890 * Claw init netdevice
2891 * Initialize everything of the net device except the name and the
2892 * channel structs.
2893 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002894static const struct net_device_ops claw_netdev_ops = {
2895 .ndo_open = claw_open,
2896 .ndo_stop = claw_release,
2897 .ndo_get_stats = claw_stats,
2898 .ndo_start_xmit = claw_tx,
2899 .ndo_change_mtu = claw_change_mtu,
2900};
2901
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902static void
2903claw_init_netdevice(struct net_device * dev)
2904{
Andy Richterb805da72008-07-18 15:24:56 +02002905 CLAW_DBF_TEXT(2, setup, "init_dev");
2906 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 dev->hard_header_len = 0;
2909 dev->addr_len = 0;
2910 dev->type = ARPHRD_SLIP;
2911 dev->tx_queue_len = 1300;
2912 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002913 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002914 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 return;
2916}
2917
2918/**
2919 * Init a new channel in the privptr->channel[i].
2920 *
2921 * @param cdev The ccw_device to be added.
2922 *
2923 * @return 0 on success, !0 on error.
2924 */
2925static int
2926add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2927{
2928 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002929 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930
Kay Sievers2a0217d2008-10-10 21:33:09 +02002931 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2933 p_ch = &privptr->channel[i];
2934 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002935 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002936 ccw_device_get_id(cdev, &dev_id);
2937 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002938 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 return -ENOMEM;
2940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 return 0;
2942}
2943
2944
2945/**
2946 *
2947 * Setup an interface.
2948 *
2949 * @param cgdev Device to be setup.
2950 *
2951 * @returns 0 on success, !0 on failure.
2952 */
2953static int
2954claw_new_device(struct ccwgroup_device *cgdev)
2955{
2956 struct claw_privbk *privptr;
2957 struct claw_env *p_env;
2958 struct net_device *dev;
2959 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002960 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
Andy Richter4811fcb2009-01-20 06:14:33 +00002962 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb082010-08-12 01:58:27 +00002963 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002964 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002965 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00002966 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2967 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 if (!privptr)
2969 return -ENODEV;
2970 p_env = privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002971 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2972 p_env->devno[READ_CHANNEL] = dev_id.devno;
2973 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2974 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 ret = add_channel(cgdev->cdev[0],0,privptr);
2976 if (ret == 0)
2977 ret = add_channel(cgdev->cdev[1],1,privptr);
2978 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002979 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2980 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002981 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002983 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002985 dev_warn(&cgdev->dev,
2986 "Setting the read subchannel online"
2987 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 goto out;
2989 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002990 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002992 dev_warn(&cgdev->dev,
2993 "Setting the write subchannel online "
2994 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 goto out;
2996 }
2997 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2998 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002999 dev_warn(&cgdev->dev,
3000 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 goto out;
3002 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02003003 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003004 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb082010-08-12 01:58:27 +00003005 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
3006 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 /* sysfs magic */
3008 SET_NETDEV_DEV(dev, &cgdev->dev);
3009 if (register_netdev(dev) != 0) {
3010 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02003011 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 goto out;
3013 }
3014 dev->flags &=~IFF_RUNNING;
3015 if (privptr->buffs_alloc == 0) {
3016 ret=init_ccw_bk(dev);
3017 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 unregister_netdev(dev);
3019 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02003020 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 goto out;
3022 }
3023 }
Heiko Carstens319cb082010-08-12 01:58:27 +00003024 privptr->channel[READ_CHANNEL].ndev = dev;
3025 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 privptr->p_env->ndev = dev;
3027
Andy Richter4811fcb2009-01-20 06:14:33 +00003028 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3030 dev->name, p_env->read_size,
3031 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb082010-08-12 01:58:27 +00003032 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3033 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00003034 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 ":%.8s api_type: %.8s\n",
3036 dev->name, p_env->host_name,
3037 p_env->adapter_name , p_env->api_type);
3038 return 0;
3039out:
3040 ccw_device_set_offline(cgdev->cdev[1]);
3041 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 return -ENODEV;
3043}
3044
3045static void
3046claw_purge_skb_queue(struct sk_buff_head *q)
3047{
3048 struct sk_buff *skb;
3049
Andy Richterb805da72008-07-18 15:24:56 +02003050 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 while ((skb = skb_dequeue(q))) {
3052 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02003053 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 }
3055}
3056
3057/**
3058 * Shutdown an interface.
3059 *
3060 * @param cgdev Device to be shut down.
3061 *
3062 * @returns 0 on success, !0 on failure.
3063 */
3064static int
3065claw_shutdown_device(struct ccwgroup_device *cgdev)
3066{
3067 struct claw_privbk *priv;
3068 struct net_device *ndev;
3069 int ret;
3070
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003071 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003072 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 if (!priv)
3074 return -ENODEV;
Heiko Carstens319cb082010-08-12 01:58:27 +00003075 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 if (ndev) {
3077 /* Close the device */
Heiko Carstens319cb082010-08-12 01:58:27 +00003078 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003079 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 if (ndev->flags & IFF_RUNNING)
3081 ret = claw_release(ndev);
3082 ndev->flags &=~IFF_RUNNING;
3083 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003084 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb082010-08-12 01:58:27 +00003086 priv->channel[READ_CHANNEL].ndev = NULL;
3087 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 priv->p_env->ndev = NULL;
3089 }
3090 ccw_device_set_offline(cgdev->cdev[1]);
3091 ccw_device_set_offline(cgdev->cdev[0]);
3092 return 0;
3093}
3094
3095static void
3096claw_remove_device(struct ccwgroup_device *cgdev)
3097{
3098 struct claw_privbk *priv;
3099
Andy Richterb805da72008-07-18 15:24:56 +02003100 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003101 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003102 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003103 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003104 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 if (cgdev->state == CCWGROUP_ONLINE)
3106 claw_shutdown_device(cgdev);
3107 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003108 kfree(priv->p_mtc_envelope);
3109 priv->p_mtc_envelope=NULL;
3110 kfree(priv->p_env);
3111 priv->p_env=NULL;
3112 kfree(priv->channel[0].irb);
3113 priv->channel[0].irb=NULL;
3114 kfree(priv->channel[1].irb);
3115 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003117 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb082010-08-12 01:58:27 +00003118 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3119 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003121
3122 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123}
3124
3125
3126/*
3127 * sysfs attributes
3128 */
3129static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003130claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131{
3132 struct claw_privbk *priv;
3133 struct claw_env * p_env;
3134
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003135 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 if (!priv)
3137 return -ENODEV;
3138 p_env = priv->p_env;
3139 return sprintf(buf, "%s\n",p_env->host_name);
3140}
3141
3142static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003143claw_hname_write(struct device *dev, struct device_attribute *attr,
3144 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003145{
3146 struct claw_privbk *priv;
3147 struct claw_env * p_env;
3148
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003149 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150 if (!priv)
3151 return -ENODEV;
3152 p_env = priv->p_env;
3153 if (count > MAX_NAME_LEN+1)
3154 return -EINVAL;
3155 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3156 strncpy(p_env->host_name,buf, count);
3157 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3158 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003159 CLAW_DBF_TEXT(2, setup, "HstnSet");
3160 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161
3162 return count;
3163}
3164
3165static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3166
3167static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003168claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169{
3170 struct claw_privbk *priv;
3171 struct claw_env * p_env;
3172
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003173 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 if (!priv)
3175 return -ENODEV;
3176 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003177 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178}
3179
3180static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003181claw_adname_write(struct device *dev, struct device_attribute *attr,
3182 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183{
3184 struct claw_privbk *priv;
3185 struct claw_env * p_env;
3186
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003187 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188 if (!priv)
3189 return -ENODEV;
3190 p_env = priv->p_env;
3191 if (count > MAX_NAME_LEN+1)
3192 return -EINVAL;
3193 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3194 strncpy(p_env->adapter_name,buf, count);
3195 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3196 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003197 CLAW_DBF_TEXT(2, setup, "AdnSet");
3198 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199
3200 return count;
3201}
3202
3203static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3204
3205static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003206claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207{
3208 struct claw_privbk *priv;
3209 struct claw_env * p_env;
3210
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003211 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 if (!priv)
3213 return -ENODEV;
3214 p_env = priv->p_env;
3215 return sprintf(buf, "%s\n",
3216 p_env->api_type);
3217}
3218
3219static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003220claw_apname_write(struct device *dev, struct device_attribute *attr,
3221 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222{
3223 struct claw_privbk *priv;
3224 struct claw_env * p_env;
3225
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003226 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 if (!priv)
3228 return -ENODEV;
3229 p_env = priv->p_env;
3230 if (count > MAX_NAME_LEN+1)
3231 return -EINVAL;
3232 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3233 strncpy(p_env->api_type,buf, count);
3234 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3235 p_env->api_type[MAX_NAME_LEN] = 0x00;
3236 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3237 p_env->read_size=DEF_PACK_BUFSIZE;
3238 p_env->write_size=DEF_PACK_BUFSIZE;
3239 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003240 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 }
3242 else {
3243 p_env->packing=0;
3244 p_env->read_size=CLAW_FRAME_SIZE;
3245 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003246 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 }
Andy Richterb805da72008-07-18 15:24:56 +02003248 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 return count;
3250}
3251
3252static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3253
3254static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003255claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256{
3257 struct claw_privbk *priv;
3258 struct claw_env * p_env;
3259
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003260 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 if (!priv)
3262 return -ENODEV;
3263 p_env = priv->p_env;
3264 return sprintf(buf, "%d\n", p_env->write_buffers);
3265}
3266
3267static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003268claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3269 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270{
3271 struct claw_privbk *priv;
3272 struct claw_env * p_env;
3273 int nnn,max;
3274
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003275 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 if (!priv)
3277 return -ENODEV;
3278 p_env = priv->p_env;
3279 sscanf(buf, "%i", &nnn);
3280 if (p_env->packing) {
3281 max = 64;
3282 }
3283 else {
3284 max = 512;
3285 }
3286 if ((nnn > max ) || (nnn < 2))
3287 return -EINVAL;
3288 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003289 CLAW_DBF_TEXT(2, setup, "Wbufset");
3290 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 return count;
3292}
3293
3294static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3295
3296static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003297claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298{
3299 struct claw_privbk *priv;
3300 struct claw_env * p_env;
3301
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003302 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 if (!priv)
3304 return -ENODEV;
3305 p_env = priv->p_env;
3306 return sprintf(buf, "%d\n", p_env->read_buffers);
3307}
3308
3309static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003310claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3311 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312{
3313 struct claw_privbk *priv;
3314 struct claw_env *p_env;
3315 int nnn,max;
3316
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003317 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 if (!priv)
3319 return -ENODEV;
3320 p_env = priv->p_env;
3321 sscanf(buf, "%i", &nnn);
3322 if (p_env->packing) {
3323 max = 64;
3324 }
3325 else {
3326 max = 512;
3327 }
3328 if ((nnn > max ) || (nnn < 2))
3329 return -EINVAL;
3330 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003331 CLAW_DBF_TEXT(2, setup, "Rbufset");
3332 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 return count;
3334}
3335
3336static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3337
3338static struct attribute *claw_attr[] = {
3339 &dev_attr_read_buffer.attr,
3340 &dev_attr_write_buffer.attr,
3341 &dev_attr_adapter_name.attr,
3342 &dev_attr_api_type.attr,
3343 &dev_attr_host_name.attr,
3344 NULL,
3345};
3346
3347static struct attribute_group claw_attr_group = {
3348 .attrs = claw_attr,
3349};
3350
3351static int
3352claw_add_files(struct device *dev)
3353{
Andy Richterb805da72008-07-18 15:24:56 +02003354 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3356}
3357
3358static void
3359claw_remove_files(struct device *dev)
3360{
Andy Richterb805da72008-07-18 15:24:56 +02003361 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3363}
3364
3365/*--------------------------------------------------------------------*
3366* claw_init and cleanup *
3367*---------------------------------------------------------------------*/
3368
3369static void __exit
3370claw_cleanup(void)
3371{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003372 driver_remove_file(&claw_group_driver.driver,
3373 &driver_attr_group);
3374 ccwgroup_driver_unregister(&claw_group_driver);
3375 ccw_driver_unregister(&claw_ccw_driver);
3376 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003378 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
3380}
3381
3382/**
3383 * Initialize module.
3384 * This is called just after the module is loaded.
3385 *
3386 * @return 0 on success, !0 on error.
3387 */
3388static int __init
3389claw_init(void)
3390{
3391 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392
Andy Richter4811fcb2009-01-20 06:14:33 +00003393 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 ret = claw_register_debug_facility();
3395 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003396 pr_err("Registering with the S/390 debug feature"
3397 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003398 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 }
Andy Richterb805da72008-07-18 15:24:56 +02003400 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003401 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003402 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3403 if (ret)
3404 goto register_err;
3405 ret = ccw_driver_register(&claw_ccw_driver);
3406 if (ret)
3407 goto ccw_err;
3408 claw_group_driver.driver.groups = claw_group_attr_groups;
3409 ret = ccwgroup_driver_register(&claw_group_driver);
3410 if (ret)
3411 goto ccwgroup_err;
3412 return 0;
3413
3414ccwgroup_err:
3415 ccw_driver_unregister(&claw_ccw_driver);
3416ccw_err:
3417 root_device_unregister(claw_root_dev);
3418register_err:
3419 CLAW_DBF_TEXT(2, setup, "init_bad");
3420 claw_unregister_debug_facility();
3421out_err:
3422 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 return ret;
3424}
3425
3426module_init(claw_init);
3427module_exit(claw_cleanup);
3428
Andy Richterb805da72008-07-18 15:24:56 +02003429MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3430MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3431 "Copyright 2000,2008 IBM Corporation\n");
3432MODULE_LICENSE("GPL");