blob: b41fae37d3afde703e225ec6f42ea59c94edf848 [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 = {
Sebastian Ott3c190c52011-03-23 10:16:04 +0100266 .driver = {
267 .owner = THIS_MODULE,
268 .name = "claw",
269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 .max_slaves = 2,
271 .driver_id = 0xC3D3C1E6,
272 .probe = claw_probe,
273 .remove = claw_remove_device,
274 .set_online = claw_new_device,
275 .set_offline = claw_shutdown_device,
Frank Blaschka88efc2c2009-06-16 10:30:33 +0200276 .prepare = claw_pm_prepare,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277};
278
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000279static struct ccw_device_id claw_ids[] = {
280 {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw},
281 {},
282};
283MODULE_DEVICE_TABLE(ccw, claw_ids);
284
285static struct ccw_driver claw_ccw_driver = {
Sebastian Ott3bda0582011-03-23 10:16:02 +0100286 .driver = {
287 .owner = THIS_MODULE,
288 .name = "claw",
289 },
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000290 .ids = claw_ids,
291 .probe = ccwgroup_probe_ccwdev,
292 .remove = ccwgroup_remove_ccwdev,
Peter Oberparleiterde400d62011-10-30 15:16:04 +0100293 .int_class = IOINT_CLW,
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000294};
295
296static ssize_t
297claw_driver_group_store(struct device_driver *ddrv, const char *buf,
298 size_t count)
299{
300 int err;
301 err = ccwgroup_create_from_string(claw_root_dev,
302 claw_group_driver.driver_id,
Ursula Braune48d24a2010-07-22 23:15:07 +0000303 &claw_ccw_driver, 2, buf);
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000304 return err ? err : count;
305}
306
307static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store);
308
309static struct attribute *claw_group_attrs[] = {
310 &driver_attr_group.attr,
311 NULL,
312};
313
314static struct attribute_group claw_group_attr_group = {
315 .attrs = claw_group_attrs,
316};
317
Heiko Carstens302689a2009-11-17 06:47:02 -0800318static const struct attribute_group *claw_group_attr_groups[] = {
Ursula Braun0ca8cc62009-11-12 21:46:29 +0000319 &claw_group_attr_group,
320 NULL,
321};
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324* Key functions
325*/
326
327/*----------------------------------------------------------------*
328 * claw_probe *
329 * this function is called for each CLAW device. *
330 *----------------------------------------------------------------*/
331static int
332claw_probe(struct ccwgroup_device *cgdev)
333{
334 int rc;
335 struct claw_privbk *privptr=NULL;
336
Andy Richterb805da72008-07-18 15:24:56 +0200337 CLAW_DBF_TEXT(2, setup, "probe");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 if (!get_device(&cgdev->dev))
339 return -ENODEV;
Eric Sesterhenn88abaab2006-03-24 03:15:31 -0800340 privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700341 dev_set_drvdata(&cgdev->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 if (privptr == NULL) {
343 probe_error(cgdev);
344 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200345 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return -ENOMEM;
347 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700348 privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL);
349 privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) {
351 probe_error(cgdev);
352 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +0200353 CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return -ENOMEM;
355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 memcpy(privptr->p_env->adapter_name,WS_NAME_NOT_DEF,8);
357 memcpy(privptr->p_env->host_name,WS_NAME_NOT_DEF,8);
358 memcpy(privptr->p_env->api_type,WS_NAME_NOT_DEF,8);
359 privptr->p_env->packing = 0;
360 privptr->p_env->write_buffers = 5;
361 privptr->p_env->read_buffers = 5;
362 privptr->p_env->read_size = CLAW_FRAME_SIZE;
363 privptr->p_env->write_size = CLAW_FRAME_SIZE;
364 rc = claw_add_files(&cgdev->dev);
365 if (rc) {
366 probe_error(cgdev);
367 put_device(&cgdev->dev);
Andy Richter4811fcb2009-01-20 06:14:33 +0000368 dev_err(&cgdev->dev, "Creating the /proc files for a new"
369 " CLAW device failed\n");
Andy Richterb805da72008-07-18 15:24:56 +0200370 CLAW_DBF_TEXT_(2, setup, "probex%d", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 return rc;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 privptr->p_env->p_priv = privptr;
374 cgdev->cdev[0]->handler = claw_irq_handler;
375 cgdev->cdev[1]->handler = claw_irq_handler;
Andy Richterb805da72008-07-18 15:24:56 +0200376 CLAW_DBF_TEXT(2, setup, "prbext 0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 return 0;
379} /* end of claw_probe */
380
381/*-------------------------------------------------------------------*
382 * claw_tx *
383 *-------------------------------------------------------------------*/
384
385static int
386claw_tx(struct sk_buff *skb, struct net_device *dev)
387{
388 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200389 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 unsigned long saveflags;
391 struct chbk *p_ch;
392
Andy Richterb805da72008-07-18 15:24:56 +0200393 CLAW_DBF_TEXT(4, trace, "claw_tx");
Heiko Carstens319cb082010-08-12 01:58:27 +0000394 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
396 rc=claw_hw_tx( skb, dev, 1 );
397 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
Andy Richterb805da72008-07-18 15:24:56 +0200398 CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc);
Ursula Braun8f0c40d2009-03-24 03:27:46 +0000399 if (rc)
400 rc = NETDEV_TX_BUSY;
Patrick McHardyec634fe2009-07-05 19:23:38 -0700401 else
402 rc = NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 return rc;
404} /* end of claw_tx */
405
406/*------------------------------------------------------------------*
407 * pack the collect queue into an skb and return it *
408 * If not packing just return the top skb from the queue *
409 *------------------------------------------------------------------*/
410
411static struct sk_buff *
412claw_pack_skb(struct claw_privbk *privptr)
413{
414 struct sk_buff *new_skb,*held_skb;
Heiko Carstens319cb082010-08-12 01:58:27 +0000415 struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 struct claw_env *p_env = privptr->p_env;
417 int pkt_cnt,pk_ind,so_far;
418
419 new_skb = NULL; /* assume no dice */
420 pkt_cnt = 0;
Andy Richterb805da72008-07-18 15:24:56 +0200421 CLAW_DBF_TEXT(4, trace, "PackSKBe");
David S. Millerb03efcf2005-07-08 14:57:23 -0700422 if (!skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 /* some data */
424 held_skb = skb_dequeue(&p_ch->collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (held_skb)
Frank Pavlic8e84c802005-09-06 15:03:09 +0200426 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 else
428 return NULL;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200429 if (p_env->packing != DO_PACKED)
430 return held_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 /* get a new SKB we will pack at least one */
432 new_skb = dev_alloc_skb(p_env->write_size);
433 if (new_skb == NULL) {
434 atomic_inc(&held_skb->users);
435 skb_queue_head(&p_ch->collect_queue,held_skb);
436 return NULL;
437 }
438 /* we have packed packet and a place to put it */
439 pk_ind = 1;
440 so_far = 0;
441 new_skb->cb[1] = 'P'; /* every skb on queue has pack header */
442 while ((pk_ind) && (held_skb != NULL)) {
443 if (held_skb->len+so_far <= p_env->write_size-8) {
444 memcpy(skb_put(new_skb,held_skb->len),
445 held_skb->data,held_skb->len);
446 privptr->stats.tx_packets++;
447 so_far += held_skb->len;
448 pkt_cnt++;
Frank Pavlic8e84c802005-09-06 15:03:09 +0200449 dev_kfree_skb_any(held_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 held_skb = skb_dequeue(&p_ch->collect_queue);
451 if (held_skb)
452 atomic_dec(&held_skb->users);
453 } else {
454 pk_ind = 0;
455 atomic_inc(&held_skb->users);
456 skb_queue_head(&p_ch->collect_queue,held_skb);
457 }
458 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
Andy Richterb805da72008-07-18 15:24:56 +0200460 CLAW_DBF_TEXT(4, trace, "PackSKBx");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 return new_skb;
462}
463
464/*-------------------------------------------------------------------*
465 * claw_change_mtu *
466 * *
467 *-------------------------------------------------------------------*/
468
469static int
470claw_change_mtu(struct net_device *dev, int new_mtu)
471{
Peter Tiedemann6951df32008-08-21 17:10:23 +0200472 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 int buff_size;
Andy Richterb805da72008-07-18 15:24:56 +0200474 CLAW_DBF_TEXT(4, trace, "setmtu");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 buff_size = privptr->p_env->write_size;
476 if ((new_mtu < 60) || (new_mtu > buff_size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return -EINVAL;
478 }
479 dev->mtu = new_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 return 0;
481} /* end of claw_change_mtu */
482
483
484/*-------------------------------------------------------------------*
485 * claw_open *
486 * *
487 *-------------------------------------------------------------------*/
488static int
489claw_open(struct net_device *dev)
490{
491
492 int rc;
493 int i;
494 unsigned long saveflags=0;
495 unsigned long parm;
496 struct claw_privbk *privptr;
497 DECLARE_WAITQUEUE(wait, current);
498 struct timer_list timer;
499 struct ccwbk *p_buf;
500
Andy Richterb805da72008-07-18 15:24:56 +0200501 CLAW_DBF_TEXT(4, trace, "open");
Peter Tiedemann6951df32008-08-21 17:10:23 +0200502 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /* allocate and initialize CCW blocks */
504 if (privptr->buffs_alloc == 0) {
505 rc=init_ccw_bk(dev);
506 if (rc) {
Andy Richterb805da72008-07-18 15:24:56 +0200507 CLAW_DBF_TEXT(2, trace, "openmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return -ENOMEM;
509 }
510 }
511 privptr->system_validate_comp=0;
512 privptr->release_pend=0;
513 if(strncmp(privptr->p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
514 privptr->p_env->read_size=DEF_PACK_BUFSIZE;
515 privptr->p_env->write_size=DEF_PACK_BUFSIZE;
516 privptr->p_env->packing=PACKING_ASK;
517 } else {
518 privptr->p_env->packing=0;
519 privptr->p_env->read_size=CLAW_FRAME_SIZE;
520 privptr->p_env->write_size=CLAW_FRAME_SIZE;
521 }
522 claw_set_busy(dev);
Heiko Carstens319cb082010-08-12 01:58:27 +0000523 tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet,
524 (unsigned long) &privptr->channel[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 for ( i = 0; i < 2; i++) {
Andy Richterb805da72008-07-18 15:24:56 +0200526 CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 init_waitqueue_head(&privptr->channel[i].wait);
528 /* skb_queue_head_init(&p_ch->io_queue); */
Heiko Carstens319cb082010-08-12 01:58:27 +0000529 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 skb_queue_head_init(
Heiko Carstens319cb082010-08-12 01:58:27 +0000531 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 privptr->channel[i].flag_a = 0;
533 privptr->channel[i].IO_active = 0;
534 privptr->channel[i].flag &= ~CLAW_TIMER;
535 init_timer(&timer);
536 timer.function = (void *)claw_timer;
537 timer.data = (unsigned long)(&privptr->channel[i]);
538 timer.expires = jiffies + 15*HZ;
539 add_timer(&timer);
540 spin_lock_irqsave(get_ccwdev_lock(
541 privptr->channel[i].cdev), saveflags);
542 parm = (unsigned long) &privptr->channel[i];
543 privptr->channel[i].claw_state = CLAW_START_HALT_IO;
544 rc = 0;
545 add_wait_queue(&privptr->channel[i].wait, &wait);
546 rc = ccw_device_halt(
547 (struct ccw_device *)privptr->channel[i].cdev,parm);
548 set_current_state(TASK_INTERRUPTIBLE);
549 spin_unlock_irqrestore(
550 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
551 schedule();
552 set_current_state(TASK_RUNNING);
553 remove_wait_queue(&privptr->channel[i].wait, &wait);
554 if(rc != 0)
555 ccw_check_return_code(privptr->channel[i].cdev, rc);
556 if((privptr->channel[i].flag & CLAW_TIMER) == 0x00)
557 del_timer(&timer);
558 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000559 if ((((privptr->channel[READ_CHANNEL].last_dstat |
560 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) ||
Heiko Carstens319cb082010-08-12 01:58:27 +0000562 (((privptr->channel[READ_CHANNEL].flag |
563 privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) {
564 dev_info(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000565 "%s: remote side is not ready\n", dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200566 CLAW_DBF_TEXT(2, trace, "notrdy");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 for ( i = 0; i < 2; i++) {
569 spin_lock_irqsave(
570 get_ccwdev_lock(privptr->channel[i].cdev),
571 saveflags);
572 parm = (unsigned long) &privptr->channel[i];
573 privptr->channel[i].claw_state = CLAW_STOP;
574 rc = ccw_device_halt(
575 (struct ccw_device *)&privptr->channel[i].cdev,
576 parm);
577 spin_unlock_irqrestore(
578 get_ccwdev_lock(privptr->channel[i].cdev),
579 saveflags);
580 if (rc != 0) {
581 ccw_check_return_code(
582 privptr->channel[i].cdev, rc);
583 }
584 }
585 free_pages((unsigned long)privptr->p_buff_ccw,
586 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
587 if (privptr->p_env->read_size < PAGE_SIZE) {
588 free_pages((unsigned long)privptr->p_buff_read,
589 (int)pages_to_order_of_mag(
590 privptr->p_buff_read_num));
591 }
592 else {
593 p_buf=privptr->p_read_active_first;
594 while (p_buf!=NULL) {
595 free_pages((unsigned long)p_buf->p_buffer,
596 (int)pages_to_order_of_mag(
597 privptr->p_buff_pages_perread ));
598 p_buf=p_buf->next;
599 }
600 }
601 if (privptr->p_env->write_size < PAGE_SIZE ) {
602 free_pages((unsigned long)privptr->p_buff_write,
603 (int)pages_to_order_of_mag(
604 privptr->p_buff_write_num));
605 }
606 else {
607 p_buf=privptr->p_write_active_first;
608 while (p_buf!=NULL) {
609 free_pages((unsigned long)p_buf->p_buffer,
610 (int)pages_to_order_of_mag(
611 privptr->p_buff_pages_perwrite ));
612 p_buf=p_buf->next;
613 }
614 }
615 privptr->buffs_alloc = 0;
Heiko Carstens319cb082010-08-12 01:58:27 +0000616 privptr->channel[READ_CHANNEL].flag = 0x00;
617 privptr->channel[WRITE_CHANNEL].flag = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 privptr->p_buff_ccw=NULL;
619 privptr->p_buff_read=NULL;
620 privptr->p_buff_write=NULL;
621 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200622 CLAW_DBF_TEXT(2, trace, "open EIO");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 return -EIO;
624 }
625
626 /* Send SystemValidate command */
627
628 claw_clear_busy(dev);
Andy Richterb805da72008-07-18 15:24:56 +0200629 CLAW_DBF_TEXT(4, trace, "openok");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return 0;
631} /* end of claw_open */
632
633/*-------------------------------------------------------------------*
634* *
635* claw_irq_handler *
636* *
637*--------------------------------------------------------------------*/
638static void
639claw_irq_handler(struct ccw_device *cdev,
640 unsigned long intparm, struct irb *irb)
641{
642 struct chbk *p_ch = NULL;
643 struct claw_privbk *privptr = NULL;
644 struct net_device *dev = NULL;
645 struct claw_env *p_env;
646 struct chbk *p_ch_r=NULL;
647
Andy Richterb805da72008-07-18 15:24:56 +0200648 CLAW_DBF_TEXT(4, trace, "clawirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 /* Bypass all 'unsolicited interrupts' */
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -0700650 privptr = dev_get_drvdata(&cdev->dev);
651 if (!privptr) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000652 dev_warn(&cdev->dev, "An uninitialized CLAW device received an"
653 " IRQ, c-%02x d-%02x\n",
654 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200655 CLAW_DBF_TEXT(2, trace, "badirq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 return;
657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* Try to extract channel from driver data. */
Heiko Carstens319cb082010-08-12 01:58:27 +0000660 if (privptr->channel[READ_CHANNEL].cdev == cdev)
661 p_ch = &privptr->channel[READ_CHANNEL];
662 else if (privptr->channel[WRITE_CHANNEL].cdev == cdev)
663 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000665 dev_warn(&cdev->dev, "The device is not a CLAW device\n");
Andy Richterb805da72008-07-18 15:24:56 +0200666 CLAW_DBF_TEXT(2, trace, "badchan");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 return;
668 }
Andy Richterb805da72008-07-18 15:24:56 +0200669 CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 dev = (struct net_device *) (p_ch->ndev);
672 p_env=privptr->p_env;
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 /* Copy interruption response block. */
675 memcpy(p_ch->irb, irb, sizeof(struct irb));
676
Andy Richterb805da72008-07-18 15:24:56 +0200677 /* Check for good subchannel return code, otherwise info message */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200678 if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000679 dev_info(&cdev->dev,
680 "%s: subchannel check for device: %04x -"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 " Sch Stat %02x Dev Stat %02x CPA - %04x\n",
682 dev->name, p_ch->devno,
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200683 irb->scsw.cmd.cstat, irb->scsw.cmd.dstat,
684 irb->scsw.cmd.cpa);
Andy Richterb805da72008-07-18 15:24:56 +0200685 CLAW_DBF_TEXT(2, trace, "chanchk");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 /* return; */
687 }
688
689 /* Check the reason-code of a unit check */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200690 if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 ccw_check_unit_check(p_ch, irb->ecw[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 /* State machine to bring the connection up, down and to restart */
Peter Oberparleiter23d805b2008-07-14 09:58:50 +0200694 p_ch->last_dstat = irb->scsw.cmd.dstat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 switch (p_ch->claw_state) {
Andy Richterb805da72008-07-18 15:24:56 +0200697 case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */
698 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
699 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
700 (p_ch->irb->scsw.cmd.stctl ==
701 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND))))
702 return;
703 wake_up(&p_ch->wait); /* wake up claw_release */
704 CLAW_DBF_TEXT(4, trace, "stop");
705 return;
706 case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */
707 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
708 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
709 (p_ch->irb->scsw.cmd.stctl ==
710 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
711 CLAW_DBF_TEXT(4, trace, "haltio");
712 return;
713 }
714 if (p_ch->flag == CLAW_READ) {
715 p_ch->claw_state = CLAW_START_READ;
716 wake_up(&p_ch->wait); /* wake claw_open (READ)*/
717 } else if (p_ch->flag == CLAW_WRITE) {
718 p_ch->claw_state = CLAW_START_WRITE;
Andy Richter4811fcb2009-01-20 06:14:33 +0000719 /* send SYSTEM_VALIDATE */
Andy Richterb805da72008-07-18 15:24:56 +0200720 claw_strt_read(dev, LOCK_NO);
721 claw_send_control(dev,
722 SYSTEM_VALIDATE_REQUEST,
723 0, 0, 0,
724 p_env->host_name,
725 p_env->adapter_name);
726 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +0000727 dev_warn(&cdev->dev, "The CLAW device received"
728 " an unexpected IRQ, "
729 "c-%02x d-%02x\n",
Andy Richterb805da72008-07-18 15:24:56 +0200730 irb->scsw.cmd.cstat,
731 irb->scsw.cmd.dstat);
732 return;
733 }
734 CLAW_DBF_TEXT(4, trace, "haltio");
735 return;
736 case CLAW_START_READ:
737 CLAW_DBF_TEXT(4, trace, "ReadIRQ");
738 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
739 clear_bit(0, (void *)&p_ch->IO_active);
740 if ((p_ch->irb->ecw[0] & 0x41) == 0x41 ||
741 (p_ch->irb->ecw[0] & 0x40) == 0x40 ||
742 (p_ch->irb->ecw[0]) == 0) {
743 privptr->stats.rx_errors++;
Andy Richter4811fcb2009-01-20 06:14:33 +0000744 dev_info(&cdev->dev,
745 "%s: Restart is required after remote "
Andy Richterb805da72008-07-18 15:24:56 +0200746 "side recovers \n",
747 dev->name);
748 }
749 CLAW_DBF_TEXT(4, trace, "notrdy");
750 return;
751 }
752 if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) &&
753 (p_ch->irb->scsw.cmd.dstat == 0)) {
754 if (test_and_set_bit(CLAW_BH_ACTIVE,
755 (void *)&p_ch->flag_a) == 0)
756 tasklet_schedule(&p_ch->tasklet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 else
Andy Richterb805da72008-07-18 15:24:56 +0200758 CLAW_DBF_TEXT(4, trace, "PCINoBH");
759 CLAW_DBF_TEXT(4, trace, "PCI_read");
760 return;
761 }
762 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
763 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
764 (p_ch->irb->scsw.cmd.stctl ==
765 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
766 CLAW_DBF_TEXT(4, trace, "SPend_rd");
767 return;
768 }
769 clear_bit(0, (void *)&p_ch->IO_active);
770 claw_clearbit_busy(TB_RETRY, dev);
771 if (test_and_set_bit(CLAW_BH_ACTIVE,
772 (void *)&p_ch->flag_a) == 0)
773 tasklet_schedule(&p_ch->tasklet);
774 else
775 CLAW_DBF_TEXT(4, trace, "RdBHAct");
776 CLAW_DBF_TEXT(4, trace, "RdIRQXit");
777 return;
778 case CLAW_START_WRITE:
779 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000780 dev_info(&cdev->dev,
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300781 "%s: Unit Check Occurred in "
Andy Richterb805da72008-07-18 15:24:56 +0200782 "write channel\n", dev->name);
783 clear_bit(0, (void *)&p_ch->IO_active);
784 if (p_ch->irb->ecw[0] & 0x80) {
Andy Richter4811fcb2009-01-20 06:14:33 +0000785 dev_info(&cdev->dev,
786 "%s: Resetting Event "
Andy Richterb805da72008-07-18 15:24:56 +0200787 "occurred:\n", dev->name);
788 init_timer(&p_ch->timer);
789 p_ch->timer.function =
790 (void *)claw_write_retry;
791 p_ch->timer.data = (unsigned long)p_ch;
792 p_ch->timer.expires = jiffies + 10*HZ;
793 add_timer(&p_ch->timer);
Andy Richter4811fcb2009-01-20 06:14:33 +0000794 dev_info(&cdev->dev,
795 "%s: write connection "
Andy Richterb805da72008-07-18 15:24:56 +0200796 "restarting\n", dev->name);
797 }
798 CLAW_DBF_TEXT(4, trace, "rstrtwrt");
799 return;
800 }
801 if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) {
802 clear_bit(0, (void *)&p_ch->IO_active);
Andy Richter4811fcb2009-01-20 06:14:33 +0000803 dev_info(&cdev->dev,
804 "%s: Unit Exception "
805 "occurred in write channel\n",
806 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200807 }
808 if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) ||
809 (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) ||
810 (p_ch->irb->scsw.cmd.stctl ==
811 (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) {
812 CLAW_DBF_TEXT(4, trace, "writeUE");
813 return;
814 }
815 clear_bit(0, (void *)&p_ch->IO_active);
816 if (claw_test_and_setbit_busy(TB_TX, dev) == 0) {
817 claw_write_next(p_ch);
818 claw_clearbit_busy(TB_TX, dev);
819 claw_clear_busy(dev);
820 }
Heiko Carstens319cb082010-08-12 01:58:27 +0000821 p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +0200822 if (test_and_set_bit(CLAW_BH_ACTIVE,
823 (void *)&p_ch_r->flag_a) == 0)
824 tasklet_schedule(&p_ch_r->tasklet);
825 CLAW_DBF_TEXT(4, trace, "StWtExit");
826 return;
827 default:
Andy Richter4811fcb2009-01-20 06:14:33 +0000828 dev_warn(&cdev->dev,
829 "The CLAW device for %s received an unexpected IRQ\n",
830 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +0200831 CLAW_DBF_TEXT(2, trace, "badIRQ");
832 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 }
834
835} /* end of claw_irq_handler */
836
837
838/*-------------------------------------------------------------------*
839* claw_irq_tasklet *
840* *
841*--------------------------------------------------------------------*/
842static void
843claw_irq_tasklet ( unsigned long data )
844{
845 struct chbk * p_ch;
846 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 p_ch = (struct chbk *) data;
849 dev = (struct net_device *)p_ch->ndev;
Andy Richterb805da72008-07-18 15:24:56 +0200850 CLAW_DBF_TEXT(4, trace, "IRQtask");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 unpack_read(dev);
852 clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a);
Andy Richterb805da72008-07-18 15:24:56 +0200853 CLAW_DBF_TEXT(4, trace, "TskletXt");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 return;
855} /* end of claw_irq_bh */
856
857/*-------------------------------------------------------------------*
858* claw_release *
859* *
860*--------------------------------------------------------------------*/
861static int
862claw_release(struct net_device *dev)
863{
864 int rc;
865 int i;
866 unsigned long saveflags;
867 unsigned long parm;
868 struct claw_privbk *privptr;
869 DECLARE_WAITQUEUE(wait, current);
870 struct ccwbk* p_this_ccw;
871 struct ccwbk* p_buf;
872
873 if (!dev)
874 return 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +0200875 privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 if (!privptr)
877 return 0;
Andy Richterb805da72008-07-18 15:24:56 +0200878 CLAW_DBF_TEXT(4, trace, "release");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 privptr->release_pend=1;
880 claw_setbit_busy(TB_STOP,dev);
881 for ( i = 1; i >=0 ; i--) {
882 spin_lock_irqsave(
883 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
Heiko Carstens319cb082010-08-12 01:58:27 +0000884 /* del_timer(&privptr->channel[READ_CHANNEL].timer); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 privptr->channel[i].claw_state = CLAW_STOP;
886 privptr->channel[i].IO_active = 0;
887 parm = (unsigned long) &privptr->channel[i];
Heiko Carstens319cb082010-08-12 01:58:27 +0000888 if (i == WRITE_CHANNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 claw_purge_skb_queue(
Heiko Carstens319cb082010-08-12 01:58:27 +0000890 &privptr->channel[WRITE_CHANNEL].collect_queue);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 rc = ccw_device_halt (privptr->channel[i].cdev, parm);
892 if (privptr->system_validate_comp==0x00) /* never opened? */
893 init_waitqueue_head(&privptr->channel[i].wait);
894 add_wait_queue(&privptr->channel[i].wait, &wait);
895 set_current_state(TASK_INTERRUPTIBLE);
896 spin_unlock_irqrestore(
897 get_ccwdev_lock(privptr->channel[i].cdev), saveflags);
898 schedule();
899 set_current_state(TASK_RUNNING);
900 remove_wait_queue(&privptr->channel[i].wait, &wait);
901 if (rc != 0) {
902 ccw_check_return_code(privptr->channel[i].cdev, rc);
903 }
904 }
905 if (privptr->pk_skb != NULL) {
Frank Pavlic8e84c802005-09-06 15:03:09 +0200906 dev_kfree_skb_any(privptr->pk_skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 privptr->pk_skb = NULL;
908 }
909 if(privptr->buffs_alloc != 1) {
Andy Richterb805da72008-07-18 15:24:56 +0200910 CLAW_DBF_TEXT(4, trace, "none2fre");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 return 0;
912 }
Andy Richterb805da72008-07-18 15:24:56 +0200913 CLAW_DBF_TEXT(4, trace, "freebufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 if (privptr->p_buff_ccw != NULL) {
915 free_pages((unsigned long)privptr->p_buff_ccw,
916 (int)pages_to_order_of_mag(privptr->p_buff_ccw_num));
917 }
Andy Richterb805da72008-07-18 15:24:56 +0200918 CLAW_DBF_TEXT(4, trace, "freeread");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 if (privptr->p_env->read_size < PAGE_SIZE) {
920 if (privptr->p_buff_read != NULL) {
921 free_pages((unsigned long)privptr->p_buff_read,
922 (int)pages_to_order_of_mag(privptr->p_buff_read_num));
923 }
924 }
925 else {
926 p_buf=privptr->p_read_active_first;
927 while (p_buf!=NULL) {
928 free_pages((unsigned long)p_buf->p_buffer,
929 (int)pages_to_order_of_mag(
930 privptr->p_buff_pages_perread ));
931 p_buf=p_buf->next;
932 }
933 }
Andy Richterb805da72008-07-18 15:24:56 +0200934 CLAW_DBF_TEXT(4, trace, "freewrit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (privptr->p_env->write_size < PAGE_SIZE ) {
936 free_pages((unsigned long)privptr->p_buff_write,
937 (int)pages_to_order_of_mag(privptr->p_buff_write_num));
938 }
939 else {
940 p_buf=privptr->p_write_active_first;
941 while (p_buf!=NULL) {
942 free_pages((unsigned long)p_buf->p_buffer,
943 (int)pages_to_order_of_mag(
944 privptr->p_buff_pages_perwrite ));
945 p_buf=p_buf->next;
946 }
947 }
Andy Richterb805da72008-07-18 15:24:56 +0200948 CLAW_DBF_TEXT(4, trace, "clearptr");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 privptr->buffs_alloc = 0;
950 privptr->p_buff_ccw=NULL;
951 privptr->p_buff_read=NULL;
952 privptr->p_buff_write=NULL;
953 privptr->system_validate_comp=0;
954 privptr->release_pend=0;
955 /* Remove any writes that were pending and reset all reads */
956 p_this_ccw=privptr->p_read_active_first;
957 while (p_this_ccw!=NULL) {
958 p_this_ccw->header.length=0xffff;
959 p_this_ccw->header.opcode=0xff;
960 p_this_ccw->header.flag=0x00;
961 p_this_ccw=p_this_ccw->next;
962 }
963
964 while (privptr->p_write_active_first!=NULL) {
965 p_this_ccw=privptr->p_write_active_first;
966 p_this_ccw->header.flag=CLAW_PENDING;
967 privptr->p_write_active_first=p_this_ccw->next;
968 p_this_ccw->next=privptr->p_write_free_chain;
969 privptr->p_write_free_chain=p_this_ccw;
970 ++privptr->write_free_count;
971 }
972 privptr->p_write_active_last=NULL;
973 privptr->mtc_logical_link = -1;
974 privptr->mtc_skipping = 1;
975 privptr->mtc_offset=0;
976
Heiko Carstens319cb082010-08-12 01:58:27 +0000977 if (((privptr->channel[READ_CHANNEL].last_dstat |
978 privptr->channel[WRITE_CHANNEL].last_dstat) &
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) {
Heiko Carstens319cb082010-08-12 01:58:27 +0000980 dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev,
Andy Richter4811fcb2009-01-20 06:14:33 +0000981 "Deactivating %s completed with incorrect"
982 " subchannel status "
983 "(read %02x, write %02x)\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 dev->name,
Heiko Carstens319cb082010-08-12 01:58:27 +0000985 privptr->channel[READ_CHANNEL].last_dstat,
986 privptr->channel[WRITE_CHANNEL].last_dstat);
Andy Richterb805da72008-07-18 15:24:56 +0200987 CLAW_DBF_TEXT(2, trace, "badclose");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
Andy Richterb805da72008-07-18 15:24:56 +0200989 CLAW_DBF_TEXT(4, trace, "rlsexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 return 0;
991} /* end of claw_release */
992
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993/*-------------------------------------------------------------------*
994* claw_write_retry *
995* *
996*--------------------------------------------------------------------*/
997
998static void
999claw_write_retry ( struct chbk *p_ch )
1000{
1001
1002 struct net_device *dev=p_ch->ndev;
1003
Andy Richterb805da72008-07-18 15:24:56 +02001004 CLAW_DBF_TEXT(4, trace, "w_retry");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 if (p_ch->claw_state == CLAW_STOP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 return;
1007 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 claw_strt_out_IO( dev );
Andy Richterb805da72008-07-18 15:24:56 +02001009 CLAW_DBF_TEXT(4, trace, "rtry_xit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 return;
1011} /* end of claw_write_retry */
1012
1013
1014/*-------------------------------------------------------------------*
1015* claw_write_next *
1016* *
1017*--------------------------------------------------------------------*/
1018
1019static void
1020claw_write_next ( struct chbk * p_ch )
1021{
1022
1023 struct net_device *dev;
1024 struct claw_privbk *privptr=NULL;
1025 struct sk_buff *pk_skb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Andy Richterb805da72008-07-18 15:24:56 +02001027 CLAW_DBF_TEXT(4, trace, "claw_wrt");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 if (p_ch->claw_state == CLAW_STOP)
1029 return;
1030 dev = (struct net_device *) p_ch->ndev;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001031 privptr = (struct claw_privbk *) dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 claw_free_wrt_buf( dev );
1033 if ((privptr->write_free_count > 0) &&
David S. Millerb03efcf2005-07-08 14:57:23 -07001034 !skb_queue_empty(&p_ch->collect_queue)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 pk_skb = claw_pack_skb(privptr);
1036 while (pk_skb != NULL) {
Heiko Carstens38ed18f2011-05-12 18:45:04 +00001037 claw_hw_tx(pk_skb, dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 if (privptr->write_free_count > 0) {
1039 pk_skb = claw_pack_skb(privptr);
1040 } else
1041 pk_skb = NULL;
1042 }
1043 }
1044 if (privptr->p_write_active_first!=NULL) {
1045 claw_strt_out_IO(dev);
1046 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 return;
1048} /* end of claw_write_next */
1049
1050/*-------------------------------------------------------------------*
1051* *
1052* claw_timer *
1053*--------------------------------------------------------------------*/
1054
1055static void
1056claw_timer ( struct chbk * p_ch )
1057{
Andy Richterb805da72008-07-18 15:24:56 +02001058 CLAW_DBF_TEXT(4, trace, "timer");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 p_ch->flag |= CLAW_TIMER;
1060 wake_up(&p_ch->wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 return;
1062} /* end of claw_timer */
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064/*
1065*
1066* functions
1067*/
1068
1069
1070/*-------------------------------------------------------------------*
1071* *
1072* pages_to_order_of_mag *
1073* *
1074* takes a number of pages from 1 to 512 and returns the *
1075* log(num_pages)/log(2) get_free_pages() needs a base 2 order *
1076* of magnitude get_free_pages() has an upper order of 9 *
1077*--------------------------------------------------------------------*/
1078
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001079static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080pages_to_order_of_mag(int num_of_pages)
1081{
1082 int order_of_mag=1; /* assume 2 pages */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001083 int nump;
Andy Richterb805da72008-07-18 15:24:56 +02001084
1085 CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */
1087 /* 512 pages = 2Meg on 4k page systems */
1088 if (num_of_pages >= 512) {return 9; }
1089 /* we have two or more pages order is at least 1 */
1090 for (nump=2 ;nump <= 512;nump*=2) {
1091 if (num_of_pages <= nump)
1092 break;
1093 order_of_mag +=1;
1094 }
1095 if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */
Andy Richterb805da72008-07-18 15:24:56 +02001096 CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 return order_of_mag;
1098}
1099
1100/*-------------------------------------------------------------------*
1101* *
1102* add_claw_reads *
1103* *
1104*--------------------------------------------------------------------*/
1105static int
1106add_claw_reads(struct net_device *dev, struct ccwbk* p_first,
1107 struct ccwbk* p_last)
1108{
1109 struct claw_privbk *privptr;
1110 struct ccw1 temp_ccw;
1111 struct endccw * p_end;
Andy Richterb805da72008-07-18 15:24:56 +02001112 CLAW_DBF_TEXT(4, trace, "addreads");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001113 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 p_end = privptr->p_end_ccw;
1115
1116 /* first CCW and last CCW contains a new set of read channel programs
1117 * to apend the running channel programs
1118 */
1119 if ( p_first==NULL) {
Andy Richterb805da72008-07-18 15:24:56 +02001120 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 return 0;
1122 }
1123
1124 /* set up ending CCW sequence for this segment */
1125 if (p_end->read1) {
1126 p_end->read1=0x00; /* second ending CCW is now active */
1127 /* reset ending CCWs and setup TIC CCWs */
1128 p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1129 p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1130 p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1);
1131 p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1);
1132 p_end->read2_nop2.cda=0;
1133 p_end->read2_nop2.count=1;
1134 }
1135 else {
1136 p_end->read1=0x01; /* first ending CCW is now active */
1137 /* reset ending CCWs and setup TIC CCWs */
1138 p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1139 p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1140 p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1);
1141 p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1);
1142 p_end->read1_nop2.cda=0;
1143 p_end->read1_nop2.count=1;
1144 }
1145
1146 if ( privptr-> p_read_active_first ==NULL ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001147 privptr->p_read_active_first = p_first; /* set new first */
1148 privptr->p_read_active_last = p_last; /* set new last */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
1150 else {
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* set up TIC ccw */
1153 temp_ccw.cda= (__u32)__pa(&p_first->read);
1154 temp_ccw.count=0;
1155 temp_ccw.flags=0;
1156 temp_ccw.cmd_code = CCW_CLAW_CMD_TIC;
1157
1158
1159 if (p_end->read1) {
1160
1161 /* first set of CCW's is chained to the new read */
1162 /* chain, so the second set is chained to the active chain. */
1163 /* Therefore modify the second set to point to the new */
1164 /* read chain set up TIC CCWs */
1165 /* make sure we update the CCW so channel doesn't fetch it */
1166 /* when it's only half done */
1167 memcpy( &p_end->read2_nop2, &temp_ccw ,
1168 sizeof(struct ccw1));
1169 privptr->p_read_active_last->r_TIC_1.cda=
1170 (__u32)__pa(&p_first->read);
1171 privptr->p_read_active_last->r_TIC_2.cda=
1172 (__u32)__pa(&p_first->read);
1173 }
1174 else {
1175 /* make sure we update the CCW so channel doesn't */
1176 /* fetch it when it is only half done */
1177 memcpy( &p_end->read1_nop2, &temp_ccw ,
1178 sizeof(struct ccw1));
1179 privptr->p_read_active_last->r_TIC_1.cda=
1180 (__u32)__pa(&p_first->read);
1181 privptr->p_read_active_last->r_TIC_2.cda=
1182 (__u32)__pa(&p_first->read);
1183 }
Andy Richter4811fcb2009-01-20 06:14:33 +00001184 /* chain in new set of blocks */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 privptr->p_read_active_last->next = p_first;
1186 privptr->p_read_active_last=p_last;
1187 } /* end of if ( privptr-> p_read_active_first ==NULL) */
Andy Richterb805da72008-07-18 15:24:56 +02001188 CLAW_DBF_TEXT(4, trace, "addexit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 return 0;
1190} /* end of add_claw_reads */
1191
1192/*-------------------------------------------------------------------*
1193 * ccw_check_return_code *
1194 * *
1195 *-------------------------------------------------------------------*/
1196
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001197static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198ccw_check_return_code(struct ccw_device *cdev, int return_code)
1199{
Andy Richterb805da72008-07-18 15:24:56 +02001200 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 if (return_code != 0) {
1202 switch (return_code) {
Andy Richterb805da72008-07-18 15:24:56 +02001203 case -EBUSY: /* BUSY is a transient state no action needed */
1204 break;
1205 case -ENODEV:
Andy Richter4811fcb2009-01-20 06:14:33 +00001206 dev_err(&cdev->dev, "The remote channel adapter is not"
1207 " available\n");
Andy Richterb805da72008-07-18 15:24:56 +02001208 break;
1209 case -EINVAL:
Andy Richter4811fcb2009-01-20 06:14:33 +00001210 dev_err(&cdev->dev,
1211 "The status of the remote channel adapter"
1212 " is not valid\n");
Andy Richterb805da72008-07-18 15:24:56 +02001213 break;
1214 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00001215 dev_err(&cdev->dev, "The common device layer"
1216 " returned error code %d\n",
1217 return_code);
Andy Richterb805da72008-07-18 15:24:56 +02001218 }
1219 }
1220 CLAW_DBF_TEXT(4, trace, "ccwret");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221} /* end of ccw_check_return_code */
1222
1223/*-------------------------------------------------------------------*
1224* ccw_check_unit_check *
1225*--------------------------------------------------------------------*/
1226
Heiko Carstens4d284ca2007-02-05 21:18:53 +01001227static void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228ccw_check_unit_check(struct chbk * p_ch, unsigned char sense )
1229{
Andy Richterb805da72008-07-18 15:24:56 +02001230 struct net_device *ndev = p_ch->ndev;
Andy Richter4811fcb2009-01-20 06:14:33 +00001231 struct device *dev = &p_ch->cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
Andy Richterb805da72008-07-18 15:24:56 +02001233 CLAW_DBF_TEXT(4, trace, "unitchek");
Andy Richter4811fcb2009-01-20 06:14:33 +00001234 dev_warn(dev, "The communication peer of %s disconnected\n",
1235 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001237 if (sense & 0x40) {
1238 if (sense & 0x01) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001239 dev_warn(dev, "The remote channel adapter for"
1240 " %s has been reset\n",
1241 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001242 }
1243 } else if (sense & 0x20) {
1244 if (sense & 0x04) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001245 dev_warn(dev, "A data streaming timeout occurred"
1246 " for %s\n",
1247 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001248 } else if (sense & 0x10) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001249 dev_warn(dev, "The remote channel adapter for %s"
1250 " is faulty\n",
1251 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001252 } else {
1253 dev_warn(dev, "A data transfer parity error occurred"
Andy Richter4811fcb2009-01-20 06:14:33 +00001254 " for %s\n",
1255 ndev->name);
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001256 }
1257 } else if (sense & 0x10) {
1258 dev_warn(dev, "A read data parity error occurred"
1259 " for %s\n",
1260 ndev->name);
1261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263} /* end of ccw_check_unit_check */
1264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265/*-------------------------------------------------------------------*
1266* find_link *
1267*--------------------------------------------------------------------*/
1268static int
1269find_link(struct net_device *dev, char *host_name, char *ws_name )
1270{
1271 struct claw_privbk *privptr;
1272 struct claw_env *p_env;
1273 int rc=0;
1274
Andy Richterb805da72008-07-18 15:24:56 +02001275 CLAW_DBF_TEXT(2, setup, "findlink");
Peter Tiedemann6951df32008-08-21 17:10:23 +02001276 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 p_env=privptr->p_env;
1278 switch (p_env->packing)
1279 {
1280 case PACKING_ASK:
1281 if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) ||
1282 (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 ))
1283 rc = EINVAL;
1284 break;
1285 case DO_PACKED:
1286 case PACK_SEND:
1287 if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) ||
1288 (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 ))
1289 rc = EINVAL;
1290 break;
1291 default:
1292 if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) ||
1293 (memcmp(p_env->api_type , ws_name, 8)!=0))
1294 rc = EINVAL;
1295 break;
1296 }
1297
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001298 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299} /* end of find_link */
1300
1301/*-------------------------------------------------------------------*
1302 * claw_hw_tx *
1303 * *
1304 * *
1305 *-------------------------------------------------------------------*/
1306
1307static int
1308claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid)
1309{
1310 int rc=0;
1311 struct claw_privbk *privptr;
1312 struct ccwbk *p_this_ccw;
1313 struct ccwbk *p_first_ccw;
1314 struct ccwbk *p_last_ccw;
1315 __u32 numBuffers;
1316 signed long len_of_data;
1317 unsigned long bytesInThisBuffer;
1318 unsigned char *pDataAddress;
1319 struct endccw *pEnd;
1320 struct ccw1 tempCCW;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 struct claw_env *p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 p_env =privptr->p_env;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 claw_free_wrt_buf(dev); /* Clean up free chain if posible */
1329 /* scan the write queue to free any completed write packets */
1330 p_first_ccw=NULL;
1331 p_last_ccw=NULL;
1332 if ((p_env->packing >= PACK_SEND) &&
1333 (skb->cb[1] != 'P')) {
1334 skb_push(skb,sizeof(struct clawph));
1335 pk_head=(struct clawph *)skb->data;
1336 pk_head->len=skb->len-sizeof(struct clawph);
1337 if (pk_head->len%4) {
1338 pk_head->len+= 4-(pk_head->len%4);
1339 skb_pad(skb,4-(pk_head->len%4));
1340 skb_put(skb,4-(pk_head->len%4));
1341 }
1342 if (p_env->packing == DO_PACKED)
1343 pk_head->link_num = linkid;
1344 else
1345 pk_head->link_num = 0;
1346 pk_head->flag = 0x00;
1347 skb_pad(skb,4);
1348 skb->cb[1] = 'P';
1349 }
1350 if (linkid == 0) {
1351 if (claw_check_busy(dev)) {
1352 if (privptr->write_free_count!=0) {
1353 claw_clear_busy(dev);
1354 }
1355 else {
1356 claw_strt_out_IO(dev );
1357 claw_free_wrt_buf( dev );
1358 if (privptr->write_free_count==0) {
Heiko Carstens319cb082010-08-12 01:58:27 +00001359 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 atomic_inc(&skb->users);
1361 skb_queue_tail(&ch->collect_queue, skb);
1362 goto Done;
1363 }
1364 else {
1365 claw_clear_busy(dev);
1366 }
1367 }
1368 }
1369 /* tx lock */
1370 if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */
Heiko Carstens319cb082010-08-12 01:58:27 +00001371 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 atomic_inc(&skb->users);
1373 skb_queue_tail(&ch->collect_queue, skb);
1374 claw_strt_out_IO(dev );
1375 rc=-EBUSY;
1376 goto Done2;
1377 }
1378 }
1379 /* See how many write buffers are required to hold this data */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001380 numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 /* If that number of buffers isn't available, give up for now */
1383 if (privptr->write_free_count < numBuffers ||
1384 privptr->p_write_free_chain == NULL ) {
1385
1386 claw_setbit_busy(TB_NOBUFFER,dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00001387 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 atomic_inc(&skb->users);
1389 skb_queue_tail(&ch->collect_queue, skb);
Andy Richterb805da72008-07-18 15:24:56 +02001390 CLAW_DBF_TEXT(2, trace, "clawbusy");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 goto Done2;
1392 }
1393 pDataAddress=skb->data;
1394 len_of_data=skb->len;
1395
1396 while (len_of_data > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 p_this_ccw=privptr->p_write_free_chain; /* get a block */
1398 if (p_this_ccw == NULL) { /* lost the race */
Heiko Carstens319cb082010-08-12 01:58:27 +00001399 ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 atomic_inc(&skb->users);
1401 skb_queue_tail(&ch->collect_queue, skb);
1402 goto Done2;
1403 }
1404 privptr->p_write_free_chain=p_this_ccw->next;
1405 p_this_ccw->next=NULL;
1406 --privptr->write_free_count; /* -1 */
Andrew H. Richterb9d2fce2009-03-24 03:27:51 +00001407 if (len_of_data >= privptr->p_env->write_size)
1408 bytesInThisBuffer = privptr->p_env->write_size;
1409 else
1410 bytesInThisBuffer = len_of_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer);
1412 len_of_data-=bytesInThisBuffer;
1413 pDataAddress+=(unsigned long)bytesInThisBuffer;
1414 /* setup write CCW */
1415 p_this_ccw->write.cmd_code = (linkid * 8) +1;
1416 if (len_of_data>0) {
1417 p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG;
1418 }
1419 p_this_ccw->write.count=bytesInThisBuffer;
1420 /* now add to end of this chain */
1421 if (p_first_ccw==NULL) {
1422 p_first_ccw=p_this_ccw;
1423 }
1424 if (p_last_ccw!=NULL) {
1425 p_last_ccw->next=p_this_ccw;
1426 /* set up TIC ccws */
1427 p_last_ccw->w_TIC_1.cda=
1428 (__u32)__pa(&p_this_ccw->write);
1429 }
1430 p_last_ccw=p_this_ccw; /* save new last block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 }
1432
1433 /* FirstCCW and LastCCW now contain a new set of write channel
1434 * programs to append to the running channel program
1435 */
1436
1437 if (p_first_ccw!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001438 /* setup ending ccw sequence for this segment */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 pEnd=privptr->p_end_ccw;
1440 if (pEnd->write1) {
1441 pEnd->write1=0x00; /* second end ccw is now active */
1442 /* set up Tic CCWs */
1443 p_last_ccw->w_TIC_1.cda=
1444 (__u32)__pa(&pEnd->write2_nop1);
1445 pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1446 pEnd->write2_nop2.flags =
1447 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1448 pEnd->write2_nop2.cda=0;
1449 pEnd->write2_nop2.count=1;
1450 }
1451 else { /* end of if (pEnd->write1)*/
1452 pEnd->write1=0x01; /* first end ccw is now active */
1453 /* set up Tic CCWs */
1454 p_last_ccw->w_TIC_1.cda=
1455 (__u32)__pa(&pEnd->write1_nop1);
1456 pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1457 pEnd->write1_nop2.flags =
1458 CCW_FLAG_SLI | CCW_FLAG_SKIP;
1459 pEnd->write1_nop2.cda=0;
1460 pEnd->write1_nop2.count=1;
1461 } /* end if if (pEnd->write1) */
1462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 if (privptr->p_write_active_first==NULL ) {
1464 privptr->p_write_active_first=p_first_ccw;
1465 privptr->p_write_active_last=p_last_ccw;
1466 }
1467 else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 /* set up Tic CCWs */
1469
1470 tempCCW.cda=(__u32)__pa(&p_first_ccw->write);
1471 tempCCW.count=0;
1472 tempCCW.flags=0;
1473 tempCCW.cmd_code=CCW_CLAW_CMD_TIC;
1474
1475 if (pEnd->write1) {
1476
1477 /*
1478 * first set of ending CCW's is chained to the new write
1479 * chain, so the second set is chained to the active chain
1480 * Therefore modify the second set to point the new write chain.
1481 * make sure we update the CCW atomically
1482 * so channel does not fetch it when it's only half done
1483 */
1484 memcpy( &pEnd->write2_nop2, &tempCCW ,
1485 sizeof(struct ccw1));
1486 privptr->p_write_active_last->w_TIC_1.cda=
1487 (__u32)__pa(&p_first_ccw->write);
1488 }
1489 else {
1490
1491 /*make sure we update the CCW atomically
1492 *so channel does not fetch it when it's only half done
1493 */
1494 memcpy(&pEnd->write1_nop2, &tempCCW ,
1495 sizeof(struct ccw1));
1496 privptr->p_write_active_last->w_TIC_1.cda=
1497 (__u32)__pa(&p_first_ccw->write);
1498
1499 } /* end if if (pEnd->write1) */
1500
1501 privptr->p_write_active_last->next=p_first_ccw;
1502 privptr->p_write_active_last=p_last_ccw;
1503 }
1504
1505 } /* endif (p_first_ccw!=NULL) */
Frank Pavlic8e84c802005-09-06 15:03:09 +02001506 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 claw_strt_out_IO(dev );
1508 /* if write free count is zero , set NOBUFFER */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 if (privptr->write_free_count==0) {
1510 claw_setbit_busy(TB_NOBUFFER,dev);
1511 }
1512Done2:
1513 claw_clearbit_busy(TB_TX,dev);
1514Done:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 return(rc);
1516} /* end of claw_hw_tx */
1517
1518/*-------------------------------------------------------------------*
1519* *
1520* init_ccw_bk *
1521* *
1522*--------------------------------------------------------------------*/
1523
1524static int
1525init_ccw_bk(struct net_device *dev)
1526{
1527
1528 __u32 ccw_blocks_required;
1529 __u32 ccw_blocks_perpage;
1530 __u32 ccw_pages_required;
1531 __u32 claw_reads_perpage=1;
1532 __u32 claw_read_pages;
1533 __u32 claw_writes_perpage=1;
1534 __u32 claw_write_pages;
1535 void *p_buff=NULL;
1536 struct ccwbk*p_free_chain;
1537 struct ccwbk*p_buf;
1538 struct ccwbk*p_last_CCWB;
1539 struct ccwbk*p_first_CCWB;
1540 struct endccw *p_endccw=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02001541 addr_t real_address;
1542 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 struct clawh *pClawH=NULL;
1544 addr_t real_TIC_address;
1545 int i,j;
Andy Richterb805da72008-07-18 15:24:56 +02001546 CLAW_DBF_TEXT(4, trace, "init_ccw");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547
1548 /* initialize statistics field */
1549 privptr->active_link_ID=0;
1550 /* initialize ccwbk pointers */
1551 privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/
1552 privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/
1553 privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/
1554 privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/
1555 privptr->p_read_active_last=NULL; /* pointer to the last read ccw */
1556 privptr->p_end_ccw=NULL; /* pointer to ending ccw */
1557 privptr->p_claw_signal_blk=NULL; /* pointer to signal block */
1558 privptr->buffs_alloc = 0;
1559 memset(&privptr->end_ccw, 0x00, sizeof(struct endccw));
1560 memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl));
1561 /* initialize free write ccwbk counter */
1562 privptr->write_free_count=0; /* number of free bufs on write chain */
1563 p_last_CCWB = NULL;
1564 p_first_CCWB= NULL;
1565 /*
1566 * We need 1 CCW block for each read buffer, 1 for each
1567 * write buffer, plus 1 for ClawSignalBlock
1568 */
1569 ccw_blocks_required =
1570 privptr->p_env->read_buffers+privptr->p_env->write_buffers+1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 /*
1572 * compute number of CCW blocks that will fit in a page
1573 */
1574 ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE;
1575 ccw_pages_required=
Julia Lawallf5154fb2008-02-18 14:41:55 +01001576 DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 /*
1579 * read and write sizes are set by 2 constants in claw.h
1580 * 4k and 32k. Unpacked values other than 4k are not going to
1581 * provide good performance. With packing buffers support 32k
1582 * buffers are used.
1583 */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001584 if (privptr->p_env->read_size < PAGE_SIZE) {
1585 claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size;
1586 claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers,
1587 claw_reads_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 }
1589 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001590 privptr->p_buff_pages_perread =
1591 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1592 claw_read_pages = privptr->p_env->read_buffers *
1593 privptr->p_buff_pages_perread;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 }
1595 if (privptr->p_env->write_size < PAGE_SIZE) {
Julia Lawallf5154fb2008-02-18 14:41:55 +01001596 claw_writes_perpage =
1597 PAGE_SIZE / privptr->p_env->write_size;
1598 claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers,
1599 claw_writes_perpage);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600
1601 }
1602 else { /* > or equal */
Julia Lawallf5154fb2008-02-18 14:41:55 +01001603 privptr->p_buff_pages_perwrite =
1604 DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE);
1605 claw_write_pages = privptr->p_env->write_buffers *
1606 privptr->p_buff_pages_perwrite;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 /*
1609 * allocate ccw_pages_required
1610 */
1611 if (privptr->p_buff_ccw==NULL) {
1612 privptr->p_buff_ccw=
1613 (void *)__get_free_pages(__GFP_DMA,
1614 (int)pages_to_order_of_mag(ccw_pages_required ));
1615 if (privptr->p_buff_ccw==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 return -ENOMEM;
1617 }
1618 privptr->p_buff_ccw_num=ccw_pages_required;
1619 }
1620 memset(privptr->p_buff_ccw, 0x00,
1621 privptr->p_buff_ccw_num * PAGE_SIZE);
1622
1623 /*
1624 * obtain ending ccw block address
1625 *
1626 */
1627 privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw;
1628 real_address = (__u32)__pa(privptr->p_end_ccw);
1629 /* Initialize ending CCW block */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 p_endccw=privptr->p_end_ccw;
1631 p_endccw->real=real_address;
1632 p_endccw->write1=0x00;
1633 p_endccw->read1=0x00;
1634
1635 /* write1_nop1 */
1636 p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1637 p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1638 p_endccw->write1_nop1.count = 1;
1639 p_endccw->write1_nop1.cda = 0;
1640
1641 /* write1_nop2 */
1642 p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1643 p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1644 p_endccw->write1_nop2.count = 1;
1645 p_endccw->write1_nop2.cda = 0;
1646
1647 /* write2_nop1 */
1648 p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1649 p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1650 p_endccw->write2_nop1.count = 1;
1651 p_endccw->write2_nop1.cda = 0;
1652
1653 /* write2_nop2 */
1654 p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1655 p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1656 p_endccw->write2_nop2.count = 1;
1657 p_endccw->write2_nop2.cda = 0;
1658
1659 /* read1_nop1 */
1660 p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1661 p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1662 p_endccw->read1_nop1.count = 1;
1663 p_endccw->read1_nop1.cda = 0;
1664
1665 /* read1_nop2 */
1666 p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1667 p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1668 p_endccw->read1_nop2.count = 1;
1669 p_endccw->read1_nop2.cda = 0;
1670
1671 /* read2_nop1 */
1672 p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP;
1673 p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1674 p_endccw->read2_nop1.count = 1;
1675 p_endccw->read2_nop1.cda = 0;
1676
1677 /* read2_nop2 */
1678 p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF;
1679 p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP;
1680 p_endccw->read2_nop2.count = 1;
1681 p_endccw->read2_nop2.cda = 0;
1682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 /*
1684 * Build a chain of CCWs
1685 *
1686 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 p_buff=privptr->p_buff_ccw;
1688
1689 p_free_chain=NULL;
1690 for (i=0 ; i < ccw_pages_required; i++ ) {
1691 real_address = (__u32)__pa(p_buff);
1692 p_buf=p_buff;
1693 for (j=0 ; j < ccw_blocks_perpage ; j++) {
1694 p_buf->next = p_free_chain;
1695 p_free_chain = p_buf;
1696 p_buf->real=(__u32)__pa(p_buf);
1697 ++p_buf;
1698 }
1699 p_buff+=PAGE_SIZE;
1700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 /*
1702 * Initialize ClawSignalBlock
1703 *
1704 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 if (privptr->p_claw_signal_blk==NULL) {
1706 privptr->p_claw_signal_blk=p_free_chain;
1707 p_free_chain=p_free_chain->next;
1708 pClawH=(struct clawh *)privptr->p_claw_signal_blk;
1709 pClawH->length=0xffff;
1710 pClawH->opcode=0xff;
1711 pClawH->flag=CLAW_BUSY;
1712 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
1714 /*
1715 * allocate write_pages_required and add to free chain
1716 */
1717 if (privptr->p_buff_write==NULL) {
1718 if (privptr->p_env->write_size < PAGE_SIZE) {
1719 privptr->p_buff_write=
1720 (void *)__get_free_pages(__GFP_DMA,
1721 (int)pages_to_order_of_mag(claw_write_pages ));
1722 if (privptr->p_buff_write==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 privptr->p_buff_ccw=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 return -ENOMEM;
1725 }
1726 /*
1727 * Build CLAW write free chain
1728 *
1729 */
1730
1731 memset(privptr->p_buff_write, 0x00,
1732 ccw_pages_required * PAGE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 privptr->p_write_free_chain=NULL;
1734
1735 p_buff=privptr->p_buff_write;
1736
1737 for (i=0 ; i< privptr->p_env->write_buffers ; i++) {
1738 p_buf = p_free_chain; /* get a CCW */
1739 p_free_chain = p_buf->next;
1740 p_buf->next =privptr->p_write_free_chain;
1741 privptr->p_write_free_chain = p_buf;
1742 p_buf-> p_buffer = (struct clawbuf *)p_buff;
1743 p_buf-> write.cda = (__u32)__pa(p_buff);
1744 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1745 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1746 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1747 p_buf-> w_read_FF.count = 1;
1748 p_buf-> w_read_FF.cda =
1749 (__u32)__pa(&p_buf-> header.flag);
1750 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1751 p_buf-> w_TIC_1.flags = 0;
1752 p_buf-> w_TIC_1.count = 0;
1753
Andy Richter4811fcb2009-01-20 06:14:33 +00001754 if (((unsigned long)p_buff +
1755 privptr->p_env->write_size) >=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 ((unsigned long)(p_buff+2*
Andy Richter4811fcb2009-01-20 06:14:33 +00001757 (privptr->p_env->write_size) - 1) & PAGE_MASK)) {
1758 p_buff = p_buff+privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 }
1760 }
1761 }
1762 else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */
1763 {
1764 privptr->p_write_free_chain=NULL;
1765 for (i = 0; i< privptr->p_env->write_buffers ; i++) {
1766 p_buff=(void *)__get_free_pages(__GFP_DMA,
1767 (int)pages_to_order_of_mag(
1768 privptr->p_buff_pages_perwrite) );
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 free_pages((unsigned long)privptr->p_buff_ccw,
1771 (int)pages_to_order_of_mag(
1772 privptr->p_buff_ccw_num));
1773 privptr->p_buff_ccw=NULL;
1774 p_buf=privptr->p_buff_write;
1775 while (p_buf!=NULL) {
1776 free_pages((unsigned long)
1777 p_buf->p_buffer,
1778 (int)pages_to_order_of_mag(
1779 privptr->p_buff_pages_perwrite));
1780 p_buf=p_buf->next;
1781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return -ENOMEM;
1783 } /* Error on get_pages */
1784 memset(p_buff, 0x00, privptr->p_env->write_size );
1785 p_buf = p_free_chain;
1786 p_free_chain = p_buf->next;
1787 p_buf->next = privptr->p_write_free_chain;
1788 privptr->p_write_free_chain = p_buf;
1789 privptr->p_buff_write = p_buf;
1790 p_buf->p_buffer=(struct clawbuf *)p_buff;
1791 p_buf-> write.cda = (__u32)__pa(p_buff);
1792 p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1793 p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1794 p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1795 p_buf-> w_read_FF.count = 1;
1796 p_buf-> w_read_FF.cda =
1797 (__u32)__pa(&p_buf-> header.flag);
1798 p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1799 p_buf-> w_TIC_1.flags = 0;
1800 p_buf-> w_TIC_1.count = 0;
1801 } /* for all write_buffers */
1802
1803 } /* else buffers are PAGE_SIZE or bigger */
1804
1805 }
1806 privptr->p_buff_write_num=claw_write_pages;
1807 privptr->write_free_count=privptr->p_env->write_buffers;
1808
1809
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 /*
1811 * allocate read_pages_required and chain to free chain
1812 */
1813 if (privptr->p_buff_read==NULL) {
1814 if (privptr->p_env->read_size < PAGE_SIZE) {
1815 privptr->p_buff_read=
1816 (void *)__get_free_pages(__GFP_DMA,
1817 (int)pages_to_order_of_mag(claw_read_pages) );
1818 if (privptr->p_buff_read==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 free_pages((unsigned long)privptr->p_buff_ccw,
1820 (int)pages_to_order_of_mag(
1821 privptr->p_buff_ccw_num));
1822 /* free the write pages size is < page size */
1823 free_pages((unsigned long)privptr->p_buff_write,
1824 (int)pages_to_order_of_mag(
1825 privptr->p_buff_write_num));
1826 privptr->p_buff_ccw=NULL;
1827 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 return -ENOMEM;
1829 }
1830 memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE);
1831 privptr->p_buff_read_num=claw_read_pages;
1832 /*
1833 * Build CLAW read free chain
1834 *
1835 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 p_buff=privptr->p_buff_read;
1837 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1838 p_buf = p_free_chain;
1839 p_free_chain = p_buf->next;
1840
1841 if (p_last_CCWB==NULL) {
1842 p_buf->next=NULL;
1843 real_TIC_address=0;
1844 p_last_CCWB=p_buf;
1845 }
1846 else {
1847 p_buf->next=p_first_CCWB;
1848 real_TIC_address=
1849 (__u32)__pa(&p_first_CCWB -> read );
1850 }
1851
1852 p_first_CCWB=p_buf;
1853
1854 p_buf->p_buffer=(struct clawbuf *)p_buff;
1855 /* initialize read command */
1856 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1857 p_buf-> read.cda = (__u32)__pa(p_buff);
1858 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1859 p_buf-> read.count = privptr->p_env->read_size;
1860
1861 /* initialize read_h command */
1862 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1863 p_buf-> read_h.cda =
1864 (__u32)__pa(&(p_buf->header));
1865 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1866 p_buf-> read_h.count = sizeof(struct clawh);
1867
1868 /* initialize Signal command */
1869 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1870 p_buf-> signal.cda =
1871 (__u32)__pa(&(pClawH->flag));
1872 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1873 p_buf-> signal.count = 1;
1874
1875 /* initialize r_TIC_1 command */
1876 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1877 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1878 p_buf-> r_TIC_1.flags = 0;
1879 p_buf-> r_TIC_1.count = 0;
1880
1881 /* initialize r_read_FF command */
1882 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1883 p_buf-> r_read_FF.cda =
1884 (__u32)__pa(&(pClawH->flag));
1885 p_buf-> r_read_FF.flags =
1886 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1887 p_buf-> r_read_FF.count = 1;
1888
1889 /* initialize r_TIC_2 */
1890 memcpy(&p_buf->r_TIC_2,
1891 &p_buf->r_TIC_1, sizeof(struct ccw1));
1892
1893 /* initialize Header */
1894 p_buf->header.length=0xffff;
1895 p_buf->header.opcode=0xff;
1896 p_buf->header.flag=CLAW_PENDING;
1897
Andy Richter4811fcb2009-01-20 06:14:33 +00001898 if (((unsigned long)p_buff+privptr->p_env->read_size) >=
1899 ((unsigned long)(p_buff+2*(privptr->p_env->read_size)
1900 -1)
1901 & PAGE_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 p_buff= p_buff+privptr->p_env->read_size;
1903 }
1904 else {
1905 p_buff=
1906 (void *)((unsigned long)
Andy Richter4811fcb2009-01-20 06:14:33 +00001907 (p_buff+2*(privptr->p_env->read_size)-1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 & PAGE_MASK) ;
1909 }
1910 } /* for read_buffers */
1911 } /* read_size < PAGE_SIZE */
1912 else { /* read Size >= PAGE_SIZE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 for (i=0 ; i< privptr->p_env->read_buffers ; i++) {
1914 p_buff = (void *)__get_free_pages(__GFP_DMA,
Andy Richter4811fcb2009-01-20 06:14:33 +00001915 (int)pages_to_order_of_mag(
1916 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 if (p_buff==NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 free_pages((unsigned long)privptr->p_buff_ccw,
Andy Richter4811fcb2009-01-20 06:14:33 +00001919 (int)pages_to_order_of_mag(privptr->
1920 p_buff_ccw_num));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 /* free the write pages */
1922 p_buf=privptr->p_buff_write;
1923 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001924 free_pages(
1925 (unsigned long)p_buf->p_buffer,
1926 (int)pages_to_order_of_mag(
1927 privptr->p_buff_pages_perwrite));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 p_buf=p_buf->next;
1929 }
1930 /* free any read pages already alloc */
1931 p_buf=privptr->p_buff_read;
1932 while (p_buf!=NULL) {
Andy Richter4811fcb2009-01-20 06:14:33 +00001933 free_pages(
1934 (unsigned long)p_buf->p_buffer,
1935 (int)pages_to_order_of_mag(
1936 privptr->p_buff_pages_perread));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 p_buf=p_buf->next;
1938 }
1939 privptr->p_buff_ccw=NULL;
1940 privptr->p_buff_write=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 return -ENOMEM;
1942 }
1943 memset(p_buff, 0x00, privptr->p_env->read_size);
1944 p_buf = p_free_chain;
1945 privptr->p_buff_read = p_buf;
1946 p_free_chain = p_buf->next;
1947
1948 if (p_last_CCWB==NULL) {
1949 p_buf->next=NULL;
1950 real_TIC_address=0;
1951 p_last_CCWB=p_buf;
1952 }
1953 else {
1954 p_buf->next=p_first_CCWB;
1955 real_TIC_address=
1956 (addr_t)__pa(
1957 &p_first_CCWB -> read );
1958 }
1959
1960 p_first_CCWB=p_buf;
1961 /* save buff address */
1962 p_buf->p_buffer=(struct clawbuf *)p_buff;
1963 /* initialize read command */
1964 p_buf-> read.cmd_code = CCW_CLAW_CMD_READ;
1965 p_buf-> read.cda = (__u32)__pa(p_buff);
1966 p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1967 p_buf-> read.count = privptr->p_env->read_size;
1968
1969 /* initialize read_h command */
1970 p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER;
1971 p_buf-> read_h.cda =
1972 (__u32)__pa(&(p_buf->header));
1973 p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1974 p_buf-> read_h.count = sizeof(struct clawh);
1975
1976 /* initialize Signal command */
1977 p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD;
1978 p_buf-> signal.cda =
1979 (__u32)__pa(&(pClawH->flag));
1980 p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC;
1981 p_buf-> signal.count = 1;
1982
1983 /* initialize r_TIC_1 command */
1984 p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC;
1985 p_buf-> r_TIC_1.cda = (__u32)real_TIC_address;
1986 p_buf-> r_TIC_1.flags = 0;
1987 p_buf-> r_TIC_1.count = 0;
1988
1989 /* initialize r_read_FF command */
1990 p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF;
1991 p_buf-> r_read_FF.cda =
1992 (__u32)__pa(&(pClawH->flag));
1993 p_buf-> r_read_FF.flags =
1994 CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI;
1995 p_buf-> r_read_FF.count = 1;
1996
1997 /* initialize r_TIC_2 */
1998 memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1,
1999 sizeof(struct ccw1));
2000
2001 /* initialize Header */
2002 p_buf->header.length=0xffff;
2003 p_buf->header.opcode=0xff;
2004 p_buf->header.flag=CLAW_PENDING;
2005
2006 } /* For read_buffers */
2007 } /* read_size >= PAGE_SIZE */
2008 } /* pBuffread = NULL */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 add_claw_reads( dev ,p_first_CCWB , p_last_CCWB);
2010 privptr->buffs_alloc = 1;
Andy Richterb805da72008-07-18 15:24:56 +02002011
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 return 0;
2013} /* end of init_ccw_bk */
2014
2015/*-------------------------------------------------------------------*
2016* *
2017* probe_error *
2018* *
2019*--------------------------------------------------------------------*/
2020
2021static void
2022probe_error( struct ccwgroup_device *cgdev)
2023{
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002024 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002025
2026 CLAW_DBF_TEXT(4, trace, "proberr");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002027 privptr = dev_get_drvdata(&cgdev->dev);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002028 if (privptr != NULL) {
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002029 dev_set_drvdata(&cgdev->dev, NULL);
Jesper Juhl17fd6822005-11-07 01:01:30 -08002030 kfree(privptr->p_env);
Martin Schwidefsky2b356b42008-08-21 17:10:22 +02002031 kfree(privptr->p_mtc_envelope);
2032 kfree(privptr);
2033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034} /* probe_error */
2035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036/*-------------------------------------------------------------------*
2037* claw_process_control *
2038* *
2039* *
2040*--------------------------------------------------------------------*/
2041
2042static int
2043claw_process_control( struct net_device *dev, struct ccwbk * p_ccw)
2044{
2045
2046 struct clawbuf *p_buf;
2047 struct clawctl ctlbk;
2048 struct clawctl *p_ctlbk;
2049 char temp_host_name[8];
2050 char temp_ws_name[8];
2051 struct claw_privbk *privptr;
2052 struct claw_env *p_env;
2053 struct sysval *p_sysval;
2054 struct conncmd *p_connect=NULL;
2055 int rc;
2056 struct chbk *p_ch = NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002057 struct device *tdev;
2058 CLAW_DBF_TEXT(2, setup, "clw_cntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 udelay(1000); /* Wait a ms for the control packets to
2060 *catch up to each other */
Peter Tiedemann6951df32008-08-21 17:10:23 +02002061 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 p_env=privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002063 tdev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 memcpy( &temp_host_name, p_env->host_name, 8);
2065 memcpy( &temp_ws_name, p_env->adapter_name , 8);
Andy Richter4811fcb2009-01-20 06:14:33 +00002066 dev_info(tdev, "%s: CLAW device %.8s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 "Received Control Packet\n",
2068 dev->name, temp_ws_name);
2069 if (privptr->release_pend==1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 return 0;
2071 }
2072 p_buf=p_ccw->p_buffer;
2073 p_ctlbk=&ctlbk;
2074 if (p_env->packing == DO_PACKED) { /* packing in progress?*/
2075 memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl));
2076 } else {
2077 memcpy(p_ctlbk, p_buf, sizeof(struct clawctl));
2078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 switch (p_ctlbk->command)
2080 {
Andy Richterb805da72008-07-18 15:24:56 +02002081 case SYSTEM_VALIDATE_REQUEST:
2082 if (p_ctlbk->version != CLAW_VERSION_ID) {
2083 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2084 CLAW_RC_WRONG_VERSION);
Andy Richter4811fcb2009-01-20 06:14:33 +00002085 dev_warn(tdev, "The communication peer of %s"
2086 " uses an incorrect API version %d\n",
2087 dev->name, p_ctlbk->version);
Andy Richterb805da72008-07-18 15:24:56 +02002088 }
2089 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002090 dev_info(tdev, "%s: Recv Sys Validate Request: "
2091 "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s,"
2092 "Host name=%.8s\n",
2093 dev->name, p_ctlbk->version,
2094 p_ctlbk->linkid,
2095 p_ctlbk->correlator,
2096 p_sysval->WS_name,
2097 p_sysval->host_name);
Andy Richterb805da72008-07-18 15:24:56 +02002098 if (memcmp(temp_host_name, p_sysval->host_name, 8)) {
2099 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2100 CLAW_RC_NAME_MISMATCH);
2101 CLAW_DBF_TEXT(2, setup, "HSTBAD");
2102 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name);
2103 CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002104 dev_warn(tdev,
2105 "Host name %s for %s does not match the"
2106 " remote adapter name %s\n",
Andy Richterb805da72008-07-18 15:24:56 +02002107 p_sysval->host_name,
Andy Richter4811fcb2009-01-20 06:14:33 +00002108 dev->name,
Andy Richterb805da72008-07-18 15:24:56 +02002109 temp_host_name);
2110 }
2111 if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) {
2112 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2113 CLAW_RC_NAME_MISMATCH);
2114 CLAW_DBF_TEXT(2, setup, "WSNBAD");
2115 CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name);
2116 CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name);
Andy Richter4811fcb2009-01-20 06:14:33 +00002117 dev_warn(tdev, "Adapter name %s for %s does not match"
2118 " the remote host name %s\n",
2119 p_sysval->WS_name,
2120 dev->name,
2121 temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002122 }
2123 if ((p_sysval->write_frame_size < p_env->write_size) &&
2124 (p_env->packing == 0)) {
2125 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2126 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002127 dev_warn(tdev,
2128 "The local write buffer is smaller than the"
2129 " remote read buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002130 CLAW_DBF_TEXT(2, setup, "wrtszbad");
2131 }
2132 if ((p_sysval->read_frame_size < p_env->read_size) &&
2133 (p_env->packing == 0)) {
2134 claw_snd_sys_validate_rsp(dev, p_ctlbk,
2135 CLAW_RC_HOST_RCV_TOO_SMALL);
Andy Richter4811fcb2009-01-20 06:14:33 +00002136 dev_warn(tdev,
2137 "The local read buffer is smaller than the"
2138 " remote write buffer\n");
Andy Richterb805da72008-07-18 15:24:56 +02002139 CLAW_DBF_TEXT(2, setup, "rdsizbad");
2140 }
2141 claw_snd_sys_validate_rsp(dev, p_ctlbk, 0);
Andy Richter4811fcb2009-01-20 06:14:33 +00002142 dev_info(tdev,
2143 "CLAW device %.8s: System validate"
2144 " completed.\n", temp_ws_name);
2145 dev_info(tdev,
2146 "%s: sys Validate Rsize:%d Wsize:%d\n",
2147 dev->name, p_sysval->read_frame_size,
2148 p_sysval->write_frame_size);
Andy Richterb805da72008-07-18 15:24:56 +02002149 privptr->system_validate_comp = 1;
2150 if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0)
2151 p_env->packing = PACKING_ASK;
2152 claw_strt_conn_req(dev);
2153 break;
2154 case SYSTEM_VALIDATE_RESPONSE:
2155 p_sysval = (struct sysval *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002156 dev_info(tdev,
2157 "Settings for %s validated (version=%d, "
2158 "remote device=%d, rc=%d, adapter name=%.8s, "
2159 "host name=%.8s)\n",
Andy Richterb805da72008-07-18 15:24:56 +02002160 dev->name,
2161 p_ctlbk->version,
2162 p_ctlbk->correlator,
2163 p_ctlbk->rc,
2164 p_sysval->WS_name,
2165 p_sysval->host_name);
2166 switch (p_ctlbk->rc) {
2167 case 0:
Andy Richter4811fcb2009-01-20 06:14:33 +00002168 dev_info(tdev, "%s: CLAW device "
2169 "%.8s: System validate completed.\n",
2170 dev->name, temp_ws_name);
Andy Richterb805da72008-07-18 15:24:56 +02002171 if (privptr->system_validate_comp == 0)
2172 claw_strt_conn_req(dev);
2173 privptr->system_validate_comp = 1;
2174 break;
2175 case CLAW_RC_NAME_MISMATCH:
Andy Richter4811fcb2009-01-20 06:14:33 +00002176 dev_warn(tdev, "Validating %s failed because of"
2177 " a host or adapter name mismatch\n",
2178 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002179 break;
2180 case CLAW_RC_WRONG_VERSION:
Andy Richter4811fcb2009-01-20 06:14:33 +00002181 dev_warn(tdev, "Validating %s failed because of a"
2182 " version conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002183 dev->name);
2184 break;
2185 case CLAW_RC_HOST_RCV_TOO_SMALL:
Andy Richter4811fcb2009-01-20 06:14:33 +00002186 dev_warn(tdev, "Validating %s failed because of a"
2187 " frame size conflict\n",
Andy Richterb805da72008-07-18 15:24:56 +02002188 dev->name);
2189 break;
2190 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002191 dev_warn(tdev, "The communication peer of %s rejected"
2192 " the connection\n",
2193 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002194 break;
2195 }
2196 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Andy Richterb805da72008-07-18 15:24:56 +02002198 case CONNECTION_REQUEST:
2199 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002200 dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002201 "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n",
2202 dev->name,
2203 p_ctlbk->version,
2204 p_ctlbk->linkid,
2205 p_ctlbk->correlator,
2206 p_connect->host_name,
2207 p_connect->WS_name);
2208 if (privptr->active_link_ID != 0) {
2209 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002210 dev_info(tdev, "%s rejected a connection request"
2211 " because it is already active\n",
Andy Richterb805da72008-07-18 15:24:56 +02002212 dev->name);
2213 }
2214 if (p_ctlbk->linkid != 1) {
2215 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002216 dev_info(tdev, "%s rejected a request to open multiple"
2217 " connections\n",
Andy Richterb805da72008-07-18 15:24:56 +02002218 dev->name);
2219 }
2220 rc = find_link(dev, p_connect->host_name, p_connect->WS_name);
2221 if (rc != 0) {
2222 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002223 dev_info(tdev, "%s rejected a connection request"
2224 " because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002225 dev->name);
2226 }
2227 claw_send_control(dev,
2228 CONNECTION_CONFIRM, p_ctlbk->linkid,
2229 p_ctlbk->correlator,
2230 0, p_connect->host_name,
2231 p_connect->WS_name);
2232 if (p_env->packing == PACKING_ASK) {
2233 p_env->packing = PACK_SEND;
2234 claw_snd_conn_req(dev, 0);
2235 }
Andy Richter4811fcb2009-01-20 06:14:33 +00002236 dev_info(tdev, "%s: CLAW device %.8s: Connection "
Andy Richterb805da72008-07-18 15:24:56 +02002237 "completed link_id=%d.\n",
2238 dev->name, temp_ws_name,
2239 p_ctlbk->linkid);
2240 privptr->active_link_ID = p_ctlbk->linkid;
Heiko Carstens319cb082010-08-12 01:58:27 +00002241 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002242 wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */
2243 break;
2244 case CONNECTION_RESPONSE:
2245 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002246 dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002247 "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n",
2248 dev->name,
2249 p_ctlbk->version,
2250 p_ctlbk->linkid,
2251 p_ctlbk->correlator,
2252 p_ctlbk->rc,
2253 p_connect->host_name,
2254 p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Andy Richterb805da72008-07-18 15:24:56 +02002256 if (p_ctlbk->rc != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002257 dev_warn(tdev, "The communication peer of %s rejected"
2258 " a connection request\n",
2259 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002260 return 1;
2261 }
2262 rc = find_link(dev,
2263 p_connect->host_name, p_connect->WS_name);
2264 if (rc != 0) {
2265 claw_snd_disc(dev, p_ctlbk);
Andy Richter4811fcb2009-01-20 06:14:33 +00002266 dev_warn(tdev, "The communication peer of %s"
2267 " rejected a connection "
2268 "request because of a type mismatch\n",
Andy Richterb805da72008-07-18 15:24:56 +02002269 dev->name);
2270 }
2271 /* should be until CONNECTION_CONFIRM */
2272 privptr->active_link_ID = -(p_ctlbk->linkid);
2273 break;
2274 case CONNECTION_CONFIRM:
2275 p_connect = (struct conncmd *)&(p_ctlbk->data);
Andy Richter4811fcb2009-01-20 06:14:33 +00002276 dev_info(tdev,
2277 "%s: Recv Conn Confirm:Vers=%d,link_id=%d,"
Andy Richterb805da72008-07-18 15:24:56 +02002278 "Corr=%d,Host appl=%.8s,WS appl=%.8s\n",
2279 dev->name,
2280 p_ctlbk->version,
2281 p_ctlbk->linkid,
2282 p_ctlbk->correlator,
2283 p_connect->host_name,
2284 p_connect->WS_name);
2285 if (p_ctlbk->linkid == -(privptr->active_link_ID)) {
2286 privptr->active_link_ID = p_ctlbk->linkid;
2287 if (p_env->packing > PACKING_ASK) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002288 dev_info(tdev,
2289 "%s: Confirmed Now packing\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 p_env->packing = DO_PACKED;
2291 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002292 p_ch = &privptr->channel[WRITE_CHANNEL];
Andy Richterb805da72008-07-18 15:24:56 +02002293 wake_up(&p_ch->wait);
2294 } else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002295 dev_warn(tdev, "Activating %s failed because of"
2296 " an incorrect link ID=%d\n",
Andy Richterb805da72008-07-18 15:24:56 +02002297 dev->name, p_ctlbk->linkid);
2298 claw_snd_disc(dev, p_ctlbk);
2299 }
2300 break;
2301 case DISCONNECT:
Andy Richter4811fcb2009-01-20 06:14:33 +00002302 dev_info(tdev, "%s: Disconnect: "
Andy Richterb805da72008-07-18 15:24:56 +02002303 "Vers=%d,link_id=%d,Corr=%d\n",
2304 dev->name, p_ctlbk->version,
2305 p_ctlbk->linkid, p_ctlbk->correlator);
2306 if ((p_ctlbk->linkid == 2) &&
2307 (p_env->packing == PACK_SEND)) {
2308 privptr->active_link_ID = 1;
2309 p_env->packing = DO_PACKED;
2310 } else
2311 privptr->active_link_ID = 0;
2312 break;
2313 case CLAW_ERROR:
Andy Richter4811fcb2009-01-20 06:14:33 +00002314 dev_warn(tdev, "The communication peer of %s failed\n",
Andy Richterb805da72008-07-18 15:24:56 +02002315 dev->name);
2316 break;
2317 default:
Andy Richter4811fcb2009-01-20 06:14:33 +00002318 dev_warn(tdev, "The communication peer of %s sent"
2319 " an unknown command code\n",
2320 dev->name);
Andy Richterb805da72008-07-18 15:24:56 +02002321 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 }
2323
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 return 0;
2325} /* end of claw_process_control */
2326
2327
2328/*-------------------------------------------------------------------*
2329* claw_send_control *
2330* *
2331*--------------------------------------------------------------------*/
2332
2333static int
2334claw_send_control(struct net_device *dev, __u8 type, __u8 link,
2335 __u8 correlator, __u8 rc, char *local_name, char *remote_name)
2336{
2337 struct claw_privbk *privptr;
2338 struct clawctl *p_ctl;
2339 struct sysval *p_sysval;
2340 struct conncmd *p_connect;
2341 struct sk_buff *skb;
2342
Andy Richterb805da72008-07-18 15:24:56 +02002343 CLAW_DBF_TEXT(2, setup, "sndcntl");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002344 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2346
2347 p_ctl->command=type;
2348 p_ctl->version=CLAW_VERSION_ID;
2349 p_ctl->linkid=link;
2350 p_ctl->correlator=correlator;
2351 p_ctl->rc=rc;
2352
2353 p_sysval=(struct sysval *)&p_ctl->data;
2354 p_connect=(struct conncmd *)&p_ctl->data;
2355
2356 switch (p_ctl->command) {
2357 case SYSTEM_VALIDATE_REQUEST:
2358 case SYSTEM_VALIDATE_RESPONSE:
2359 memcpy(&p_sysval->host_name, local_name, 8);
2360 memcpy(&p_sysval->WS_name, remote_name, 8);
2361 if (privptr->p_env->packing > 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002362 p_sysval->read_frame_size = DEF_PACK_BUFSIZE;
2363 p_sysval->write_frame_size = DEF_PACK_BUFSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 } else {
Andy Richterb805da72008-07-18 15:24:56 +02002365 /* how big is the biggest group of packets */
Andy Richter4811fcb2009-01-20 06:14:33 +00002366 p_sysval->read_frame_size =
2367 privptr->p_env->read_size;
2368 p_sysval->write_frame_size =
2369 privptr->p_env->write_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 }
2371 memset(&p_sysval->reserved, 0x00, 4);
2372 break;
2373 case CONNECTION_REQUEST:
2374 case CONNECTION_RESPONSE:
2375 case CONNECTION_CONFIRM:
2376 case DISCONNECT:
2377 memcpy(&p_sysval->host_name, local_name, 8);
2378 memcpy(&p_sysval->WS_name, remote_name, 8);
2379 if (privptr->p_env->packing > 0) {
2380 /* How big is the biggest packet */
2381 p_connect->reserved1[0]=CLAW_FRAME_SIZE;
2382 p_connect->reserved1[1]=CLAW_FRAME_SIZE;
2383 } else {
2384 memset(&p_connect->reserved1, 0x00, 4);
2385 memset(&p_connect->reserved2, 0x00, 4);
2386 }
2387 break;
2388 default:
2389 break;
2390 }
2391
2392 /* write Control Record to the device */
2393
2394
2395 skb = dev_alloc_skb(sizeof(struct clawctl));
2396 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 return -ENOMEM;
2398 }
2399 memcpy(skb_put(skb, sizeof(struct clawctl)),
2400 p_ctl, sizeof(struct clawctl));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 if (privptr->p_env->packing >= PACK_SEND)
2402 claw_hw_tx(skb, dev, 1);
2403 else
2404 claw_hw_tx(skb, dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 return 0;
2406} /* end of claw_send_control */
2407
2408/*-------------------------------------------------------------------*
2409* claw_snd_conn_req *
2410* *
2411*--------------------------------------------------------------------*/
2412static int
2413claw_snd_conn_req(struct net_device *dev, __u8 link)
2414{
2415 int rc;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002416 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 struct clawctl *p_ctl;
2418
Andy Richterb805da72008-07-18 15:24:56 +02002419 CLAW_DBF_TEXT(2, setup, "snd_conn");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 rc = 1;
2421 p_ctl=(struct clawctl *)&privptr->ctl_bk;
2422 p_ctl->linkid = link;
2423 if ( privptr->system_validate_comp==0x00 ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 return rc;
2425 }
2426 if (privptr->p_env->packing == PACKING_ASK )
2427 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2428 WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED);
2429 if (privptr->p_env->packing == PACK_SEND) {
2430 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2431 WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME);
2432 }
2433 if (privptr->p_env->packing == 0)
2434 rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0,
2435 HOST_APPL_NAME, privptr->p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 return rc;
2437
2438} /* end of claw_snd_conn_req */
2439
2440
2441/*-------------------------------------------------------------------*
2442* claw_snd_disc *
2443* *
2444*--------------------------------------------------------------------*/
2445
2446static int
2447claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl)
2448{
2449 int rc;
2450 struct conncmd * p_connect;
2451
Andy Richterb805da72008-07-18 15:24:56 +02002452 CLAW_DBF_TEXT(2, setup, "snd_dsc");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 p_connect=(struct conncmd *)&p_ctl->data;
2454
2455 rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid,
2456 p_ctl->correlator, 0,
2457 p_connect->host_name, p_connect->WS_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 return rc;
2459} /* end of claw_snd_disc */
2460
2461
2462/*-------------------------------------------------------------------*
2463* claw_snd_sys_validate_rsp *
2464* *
2465*--------------------------------------------------------------------*/
2466
2467static int
2468claw_snd_sys_validate_rsp(struct net_device *dev,
2469 struct clawctl *p_ctl, __u32 return_code)
2470{
2471 struct claw_env * p_env;
2472 struct claw_privbk *privptr;
2473 int rc;
2474
Andy Richterb805da72008-07-18 15:24:56 +02002475 CLAW_DBF_TEXT(2, setup, "chkresp");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002476 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 p_env=privptr->p_env;
2478 rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE,
2479 p_ctl->linkid,
2480 p_ctl->correlator,
2481 return_code,
2482 p_env->host_name,
2483 p_env->adapter_name );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 return rc;
2485} /* end of claw_snd_sys_validate_rsp */
2486
2487/*-------------------------------------------------------------------*
2488* claw_strt_conn_req *
2489* *
2490*--------------------------------------------------------------------*/
2491
2492static int
2493claw_strt_conn_req(struct net_device *dev )
2494{
2495 int rc;
2496
Andy Richterb805da72008-07-18 15:24:56 +02002497 CLAW_DBF_TEXT(2, setup, "conn_req");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 rc=claw_snd_conn_req(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 return rc;
2500} /* end of claw_strt_conn_req */
2501
2502
2503
2504/*-------------------------------------------------------------------*
2505 * claw_stats *
2506 *-------------------------------------------------------------------*/
2507
2508static struct
2509net_device_stats *claw_stats(struct net_device *dev)
2510{
2511 struct claw_privbk *privptr;
Andy Richterb805da72008-07-18 15:24:56 +02002512
2513 CLAW_DBF_TEXT(4, trace, "stats");
Peter Tiedemann6951df32008-08-21 17:10:23 +02002514 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 return &privptr->stats;
2516} /* end of claw_stats */
2517
2518
2519/*-------------------------------------------------------------------*
2520* unpack_read *
2521* *
2522*--------------------------------------------------------------------*/
2523static void
2524unpack_read(struct net_device *dev )
2525{
2526 struct sk_buff *skb;
2527 struct claw_privbk *privptr;
2528 struct claw_env *p_env;
2529 struct ccwbk *p_this_ccw;
2530 struct ccwbk *p_first_ccw;
2531 struct ccwbk *p_last_ccw;
2532 struct clawph *p_packh;
2533 void *p_packd;
2534 struct clawctl *p_ctlrec=NULL;
Andy Richterb805da72008-07-18 15:24:56 +02002535 struct device *p_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 __u32 len_of_data;
2538 __u32 pack_off;
2539 __u8 link_num;
2540 __u8 mtc_this_frm=0;
2541 __u32 bytes_to_mov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 int i=0;
2543 int p=0;
2544
Andy Richterb805da72008-07-18 15:24:56 +02002545 CLAW_DBF_TEXT(4, trace, "unpkread");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 p_first_ccw=NULL;
2547 p_last_ccw=NULL;
2548 p_packh=NULL;
2549 p_packd=NULL;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002550 privptr = dev->ml_priv;
Andy Richterb805da72008-07-18 15:24:56 +02002551
Heiko Carstens319cb082010-08-12 01:58:27 +00002552 p_dev = &privptr->channel[READ_CHANNEL].cdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 p_env = privptr->p_env;
2554 p_this_ccw=privptr->p_read_active_first;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 pack_off = 0;
2557 p = 0;
2558 p_this_ccw->header.flag=CLAW_PENDING;
2559 privptr->p_read_active_first=p_this_ccw->next;
2560 p_this_ccw->next=NULL;
2561 p_packh = (struct clawph *)p_this_ccw->p_buffer;
2562 if ((p_env->packing == PACK_SEND) &&
2563 (p_packh->len == 32) &&
2564 (p_packh->link_num == 0)) { /* is it a packed ctl rec? */
2565 p_packh++; /* peek past pack header */
2566 p_ctlrec = (struct clawctl *)p_packh;
2567 p_packh--; /* un peek */
2568 if ((p_ctlrec->command == CONNECTION_RESPONSE) ||
2569 (p_ctlrec->command == CONNECTION_CONFIRM))
2570 p_env->packing = DO_PACKED;
2571 }
2572 if (p_env->packing == DO_PACKED)
2573 link_num=p_packh->link_num;
2574 else
2575 link_num=p_this_ccw->header.opcode / 8;
2576 if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 mtc_this_frm=1;
2578 if (p_this_ccw->header.length!=
2579 privptr->p_env->read_size ) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002580 dev_warn(p_dev,
2581 "The communication peer of %s"
2582 " sent a faulty"
2583 " frame of length %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 dev->name, p_this_ccw->header.length);
2585 }
2586 }
2587
2588 if (privptr->mtc_skipping) {
2589 /*
2590 * We're in the mode of skipping past a
2591 * multi-frame message
2592 * that we can't process for some reason or other.
2593 * The first frame without the More-To-Come flag is
2594 * the last frame of the skipped message.
2595 */
2596 /* in case of More-To-Come not set in this frame */
2597 if (mtc_this_frm==0) {
2598 privptr->mtc_skipping=0; /* Ok, the end */
2599 privptr->mtc_logical_link=-1;
2600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 goto NextFrame;
2602 }
2603
2604 if (link_num==0) {
2605 claw_process_control(dev, p_this_ccw);
Andy Richterb805da72008-07-18 15:24:56 +02002606 CLAW_DBF_TEXT(4, trace, "UnpkCntl");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 goto NextFrame;
2608 }
2609unpack_next:
2610 if (p_env->packing == DO_PACKED) {
2611 if (pack_off > p_env->read_size)
2612 goto NextFrame;
2613 p_packd = p_this_ccw->p_buffer+pack_off;
2614 p_packh = (struct clawph *) p_packd;
Andy Richter4811fcb2009-01-20 06:14:33 +00002615 if ((p_packh->len == 0) || /* done with this frame? */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 (p_packh->flag != 0))
2617 goto NextFrame;
2618 bytes_to_mov = p_packh->len;
2619 pack_off += bytes_to_mov+sizeof(struct clawph);
2620 p++;
2621 } else {
2622 bytes_to_mov=p_this_ccw->header.length;
2623 }
2624 if (privptr->mtc_logical_link<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625
2626 /*
2627 * if More-To-Come is set in this frame then we don't know
2628 * length of entire message, and hence have to allocate
2629 * large buffer */
2630
2631 /* We are starting a new envelope */
2632 privptr->mtc_offset=0;
2633 privptr->mtc_logical_link=link_num;
2634 }
2635
2636 if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) {
2637 /* error */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 privptr->stats.rx_frame_errors++;
2639 goto NextFrame;
2640 }
2641 if (p_env->packing == DO_PACKED) {
2642 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2643 p_packd+sizeof(struct clawph), bytes_to_mov);
2644
2645 } else {
2646 memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset,
2647 p_this_ccw->p_buffer, bytes_to_mov);
2648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 if (mtc_this_frm==0) {
2650 len_of_data=privptr->mtc_offset+bytes_to_mov;
2651 skb=dev_alloc_skb(len_of_data);
2652 if (skb) {
2653 memcpy(skb_put(skb,len_of_data),
2654 privptr->p_mtc_envelope,
2655 len_of_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 skb->dev=dev;
Arnaldo Carvalho de Melo98e399f2007-03-19 15:33:04 -07002657 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 skb->protocol=htons(ETH_P_IP);
2659 skb->ip_summed=CHECKSUM_UNNECESSARY;
2660 privptr->stats.rx_packets++;
2661 privptr->stats.rx_bytes+=len_of_data;
2662 netif_rx(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 }
2664 else {
Andy Richter4811fcb2009-01-20 06:14:33 +00002665 dev_info(p_dev, "Allocating a buffer for"
2666 " incoming data failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 privptr->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 }
2669 privptr->mtc_offset=0;
2670 privptr->mtc_logical_link=-1;
2671 }
2672 else {
2673 privptr->mtc_offset+=bytes_to_mov;
2674 }
2675 if (p_env->packing == DO_PACKED)
2676 goto unpack_next;
2677NextFrame:
2678 /*
2679 * Remove ThisCCWblock from active read queue, and add it
2680 * to queue of free blocks to be reused.
2681 */
2682 i++;
2683 p_this_ccw->header.length=0xffff;
2684 p_this_ccw->header.opcode=0xff;
2685 /*
2686 * add this one to the free queue for later reuse
2687 */
2688 if (p_first_ccw==NULL) {
2689 p_first_ccw = p_this_ccw;
2690 }
2691 else {
2692 p_last_ccw->next = p_this_ccw;
2693 }
2694 p_last_ccw = p_this_ccw;
2695 /*
2696 * chain to next block on active read queue
2697 */
2698 p_this_ccw = privptr->p_read_active_first;
Andy Richterb805da72008-07-18 15:24:56 +02002699 CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 } /* end of while */
2701
2702 /* check validity */
2703
Andy Richterb805da72008-07-18 15:24:56 +02002704 CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 add_claw_reads(dev, p_first_ccw, p_last_ccw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 claw_strt_read(dev, LOCK_YES);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 return;
2708} /* end of unpack_read */
2709
2710/*-------------------------------------------------------------------*
2711* claw_strt_read *
2712* *
2713*--------------------------------------------------------------------*/
2714static void
2715claw_strt_read (struct net_device *dev, int lock )
2716{
2717 int rc = 0;
2718 __u32 parm;
2719 unsigned long saveflags = 0;
Peter Tiedemann6951df32008-08-21 17:10:23 +02002720 struct claw_privbk *privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 struct ccwbk*p_ccwbk;
2722 struct chbk *p_ch;
2723 struct clawh *p_clawh;
Heiko Carstens319cb082010-08-12 01:58:27 +00002724 p_ch = &privptr->channel[READ_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725
Andy Richterb805da72008-07-18 15:24:56 +02002726 CLAW_DBF_TEXT(4, trace, "StRdNter");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 p_clawh=(struct clawh *)privptr->p_claw_signal_blk;
2728 p_clawh->flag=CLAW_IDLE; /* 0x00 */
2729
2730 if ((privptr->p_write_active_first!=NULL &&
2731 privptr->p_write_active_first->header.flag!=CLAW_PENDING) ||
2732 (privptr->p_read_active_first!=NULL &&
2733 privptr->p_read_active_first->header.flag!=CLAW_PENDING )) {
2734 p_clawh->flag=CLAW_BUSY; /* 0xff */
2735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 if (lock==LOCK_YES) {
2737 spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags);
2738 }
2739 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
Andy Richterb805da72008-07-18 15:24:56 +02002740 CLAW_DBF_TEXT(4, trace, "HotRead");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 p_ccwbk=privptr->p_read_active_first;
2742 parm = (unsigned long) p_ch;
2743 rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm,
2744 0xff, 0);
2745 if (rc != 0) {
2746 ccw_check_return_code(p_ch->cdev, rc);
2747 }
2748 }
2749 else {
Andy Richterb805da72008-07-18 15:24:56 +02002750 CLAW_DBF_TEXT(2, trace, "ReadAct");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 }
2752
2753 if (lock==LOCK_YES) {
2754 spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags);
2755 }
Andy Richterb805da72008-07-18 15:24:56 +02002756 CLAW_DBF_TEXT(4, trace, "StRdExit");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 return;
2758} /* end of claw_strt_read */
2759
2760/*-------------------------------------------------------------------*
2761* claw_strt_out_IO *
2762* *
2763*--------------------------------------------------------------------*/
2764
2765static void
2766claw_strt_out_IO( struct net_device *dev )
2767{
2768 int rc = 0;
2769 unsigned long parm;
2770 struct claw_privbk *privptr;
2771 struct chbk *p_ch;
2772 struct ccwbk *p_first_ccw;
2773
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 if (!dev) {
2775 return;
2776 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002777 privptr = (struct claw_privbk *)dev->ml_priv;
Heiko Carstens319cb082010-08-12 01:58:27 +00002778 p_ch = &privptr->channel[WRITE_CHANNEL];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779
Andy Richterb805da72008-07-18 15:24:56 +02002780 CLAW_DBF_TEXT(4, trace, "strt_io");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 p_first_ccw=privptr->p_write_active_first;
2782
2783 if (p_ch->claw_state == CLAW_STOP)
2784 return;
2785 if (p_first_ccw == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 return;
2787 }
2788 if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) {
2789 parm = (unsigned long) p_ch;
Andy Richterb805da72008-07-18 15:24:56 +02002790 CLAW_DBF_TEXT(2, trace, "StWrtIO");
Andy Richter4811fcb2009-01-20 06:14:33 +00002791 rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm,
2792 0xff, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 if (rc != 0) {
2794 ccw_check_return_code(p_ch->cdev, rc);
2795 }
2796 }
2797 dev->trans_start = jiffies;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 return;
2799} /* end of claw_strt_out_IO */
2800
2801/*-------------------------------------------------------------------*
2802* Free write buffers *
2803* *
2804*--------------------------------------------------------------------*/
2805
2806static void
2807claw_free_wrt_buf( struct net_device *dev )
2808{
2809
Peter Tiedemann6951df32008-08-21 17:10:23 +02002810 struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 struct ccwbk*p_this_ccw;
2812 struct ccwbk*p_next_ccw;
Andy Richterb805da72008-07-18 15:24:56 +02002813
2814 CLAW_DBF_TEXT(4, trace, "freewrtb");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 /* scan the write queue to free any completed write packets */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 p_this_ccw=privptr->p_write_active_first;
2817 while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING))
2818 {
2819 p_next_ccw = p_this_ccw->next;
2820 if (((p_next_ccw!=NULL) &&
2821 (p_next_ccw->header.flag!=CLAW_PENDING)) ||
2822 ((p_this_ccw == privptr->p_write_active_last) &&
2823 (p_this_ccw->header.flag!=CLAW_PENDING))) {
2824 /* The next CCW is OK or this is */
2825 /* the last CCW...free it @A1A */
2826 privptr->p_write_active_first=p_this_ccw->next;
2827 p_this_ccw->header.flag=CLAW_PENDING;
2828 p_this_ccw->next=privptr->p_write_free_chain;
2829 privptr->p_write_free_chain=p_this_ccw;
2830 ++privptr->write_free_count;
2831 privptr->stats.tx_bytes+= p_this_ccw->write.count;
2832 p_this_ccw=privptr->p_write_active_first;
2833 privptr->stats.tx_packets++;
2834 }
2835 else {
2836 break;
2837 }
2838 }
2839 if (privptr->write_free_count!=0) {
2840 claw_clearbit_busy(TB_NOBUFFER,dev);
2841 }
2842 /* whole chain removed? */
2843 if (privptr->p_write_active_first==NULL) {
2844 privptr->p_write_active_last=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 }
Andy Richterb805da72008-07-18 15:24:56 +02002846 CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 return;
2848}
2849
2850/*-------------------------------------------------------------------*
2851* claw free netdevice *
2852* *
2853*--------------------------------------------------------------------*/
2854static void
2855claw_free_netdevice(struct net_device * dev, int free_dev)
2856{
2857 struct claw_privbk *privptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858
Andy Richterb805da72008-07-18 15:24:56 +02002859 CLAW_DBF_TEXT(2, setup, "free_dev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 if (!dev)
2861 return;
Andy Richterb805da72008-07-18 15:24:56 +02002862 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Peter Tiedemann6951df32008-08-21 17:10:23 +02002863 privptr = dev->ml_priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 if (dev->flags & IFF_RUNNING)
2865 claw_release(dev);
2866 if (privptr) {
Heiko Carstens319cb082010-08-12 01:58:27 +00002867 privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002869 dev->ml_priv = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870#ifdef MODULE
2871 if (free_dev) {
2872 free_netdev(dev);
2873 }
2874#endif
Andy Richterb805da72008-07-18 15:24:56 +02002875 CLAW_DBF_TEXT(2, setup, "free_ok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876}
2877
2878/**
2879 * Claw init netdevice
2880 * Initialize everything of the net device except the name and the
2881 * channel structs.
2882 */
Frank Blaschka2171dc12009-01-09 03:43:59 +00002883static const struct net_device_ops claw_netdev_ops = {
2884 .ndo_open = claw_open,
2885 .ndo_stop = claw_release,
2886 .ndo_get_stats = claw_stats,
2887 .ndo_start_xmit = claw_tx,
2888 .ndo_change_mtu = claw_change_mtu,
2889};
2890
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891static void
2892claw_init_netdevice(struct net_device * dev)
2893{
Andy Richterb805da72008-07-18 15:24:56 +02002894 CLAW_DBF_TEXT(2, setup, "init_dev");
2895 CLAW_DBF_TEXT_(2, setup, "%s", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 dev->mtu = CLAW_DEFAULT_MTU_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 dev->hard_header_len = 0;
2898 dev->addr_len = 0;
2899 dev->type = ARPHRD_SLIP;
2900 dev->tx_queue_len = 1300;
2901 dev->flags = IFF_POINTOPOINT | IFF_NOARP;
Frank Blaschka2171dc12009-01-09 03:43:59 +00002902 dev->netdev_ops = &claw_netdev_ops;
Andy Richterb805da72008-07-18 15:24:56 +02002903 CLAW_DBF_TEXT(2, setup, "initok");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 return;
2905}
2906
2907/**
2908 * Init a new channel in the privptr->channel[i].
2909 *
2910 * @param cdev The ccw_device to be added.
2911 *
2912 * @return 0 on success, !0 on error.
2913 */
2914static int
2915add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr)
2916{
2917 struct chbk *p_ch;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002918 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919
Kay Sievers2a0217d2008-10-10 21:33:09 +02002920 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002921 privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */
2922 p_ch = &privptr->channel[i];
2923 p_ch->cdev = cdev;
Kay Sievers2a0217d2008-10-10 21:33:09 +02002924 snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev));
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002925 ccw_device_get_id(cdev, &dev_id);
2926 p_ch->devno = dev_id.devno;
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07002927 if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 return -ENOMEM;
2929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 return 0;
2931}
2932
2933
2934/**
2935 *
2936 * Setup an interface.
2937 *
2938 * @param cgdev Device to be setup.
2939 *
2940 * @returns 0 on success, !0 on failure.
2941 */
2942static int
2943claw_new_device(struct ccwgroup_device *cgdev)
2944{
2945 struct claw_privbk *privptr;
2946 struct claw_env *p_env;
2947 struct net_device *dev;
2948 int ret;
Cornelia Huckdc5bc0c2007-06-20 13:00:20 +02002949 struct ccw_dev_id dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
Andy Richter4811fcb2009-01-20 06:14:33 +00002951 dev_info(&cgdev->dev, "add for %s\n",
Heiko Carstens319cb082010-08-12 01:58:27 +00002952 dev_name(&cgdev->cdev[READ_CHANNEL]->dev));
Andy Richterb805da72008-07-18 15:24:56 +02002953 CLAW_DBF_TEXT(2, setup, "new_dev");
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002954 privptr = dev_get_drvdata(&cgdev->dev);
Heiko Carstens319cb082010-08-12 01:58:27 +00002955 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2956 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 if (!privptr)
2958 return -ENODEV;
2959 p_env = privptr->p_env;
Heiko Carstens319cb082010-08-12 01:58:27 +00002960 ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id);
2961 p_env->devno[READ_CHANNEL] = dev_id.devno;
2962 ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id);
2963 p_env->devno[WRITE_CHANNEL] = dev_id.devno;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 ret = add_channel(cgdev->cdev[0],0,privptr);
2965 if (ret == 0)
2966 ret = add_channel(cgdev->cdev[1],1,privptr);
2967 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002968 dev_warn(&cgdev->dev, "Creating a CLAW group device"
2969 " failed with error code %d\n", ret);
Andy Richterb805da72008-07-18 15:24:56 +02002970 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002972 ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002974 dev_warn(&cgdev->dev,
2975 "Setting the read subchannel online"
2976 " failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 goto out;
2978 }
Heiko Carstens319cb082010-08-12 01:58:27 +00002979 ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 if (ret != 0) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002981 dev_warn(&cgdev->dev,
2982 "Setting the write subchannel online "
2983 "failed with error code %d\n", ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 goto out;
2985 }
2986 dev = alloc_netdev(0,"claw%d",claw_init_netdevice);
2987 if (!dev) {
Andy Richter4811fcb2009-01-20 06:14:33 +00002988 dev_warn(&cgdev->dev,
2989 "Activating the CLAW device failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 goto out;
2991 }
Peter Tiedemann6951df32008-08-21 17:10:23 +02002992 dev->ml_priv = privptr;
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07002993 dev_set_drvdata(&cgdev->dev, privptr);
Heiko Carstens319cb082010-08-12 01:58:27 +00002994 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr);
2995 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 /* sysfs magic */
2997 SET_NETDEV_DEV(dev, &cgdev->dev);
2998 if (register_netdev(dev) != 0) {
2999 claw_free_netdevice(dev, 1);
Andy Richterb805da72008-07-18 15:24:56 +02003000 CLAW_DBF_TEXT(2, trace, "regfail");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 goto out;
3002 }
3003 dev->flags &=~IFF_RUNNING;
3004 if (privptr->buffs_alloc == 0) {
3005 ret=init_ccw_bk(dev);
3006 if (ret !=0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 unregister_netdev(dev);
3008 claw_free_netdevice(dev,1);
Andy Richterb805da72008-07-18 15:24:56 +02003009 CLAW_DBF_TEXT(2, trace, "ccwmem");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 goto out;
3011 }
3012 }
Heiko Carstens319cb082010-08-12 01:58:27 +00003013 privptr->channel[READ_CHANNEL].ndev = dev;
3014 privptr->channel[WRITE_CHANNEL].ndev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 privptr->p_env->ndev = dev;
3016
Andy Richter4811fcb2009-01-20 06:14:33 +00003017 dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n",
3019 dev->name, p_env->read_size,
3020 p_env->write_size, p_env->read_buffers,
Heiko Carstens319cb082010-08-12 01:58:27 +00003021 p_env->write_buffers, p_env->devno[READ_CHANNEL],
3022 p_env->devno[WRITE_CHANNEL]);
Andy Richter4811fcb2009-01-20 06:14:33 +00003023 dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name "
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 ":%.8s api_type: %.8s\n",
3025 dev->name, p_env->host_name,
3026 p_env->adapter_name , p_env->api_type);
3027 return 0;
3028out:
3029 ccw_device_set_offline(cgdev->cdev[1]);
3030 ccw_device_set_offline(cgdev->cdev[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 return -ENODEV;
3032}
3033
3034static void
3035claw_purge_skb_queue(struct sk_buff_head *q)
3036{
3037 struct sk_buff *skb;
3038
Andy Richterb805da72008-07-18 15:24:56 +02003039 CLAW_DBF_TEXT(4, trace, "purgque");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 while ((skb = skb_dequeue(q))) {
3041 atomic_dec(&skb->users);
Frank Pavlic8e84c802005-09-06 15:03:09 +02003042 dev_kfree_skb_any(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 }
3044}
3045
3046/**
3047 * Shutdown an interface.
3048 *
3049 * @param cgdev Device to be shut down.
3050 *
3051 * @returns 0 on success, !0 on failure.
3052 */
3053static int
3054claw_shutdown_device(struct ccwgroup_device *cgdev)
3055{
3056 struct claw_privbk *priv;
3057 struct net_device *ndev;
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003058 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003060 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003061 priv = dev_get_drvdata(&cgdev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 if (!priv)
3063 return -ENODEV;
Heiko Carstens319cb082010-08-12 01:58:27 +00003064 ndev = priv->channel[READ_CHANNEL].ndev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 if (ndev) {
3066 /* Close the device */
Heiko Carstens319cb082010-08-12 01:58:27 +00003067 dev_info(&cgdev->dev, "%s: shutting down\n",
Andy Richter4811fcb2009-01-20 06:14:33 +00003068 ndev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 if (ndev->flags & IFF_RUNNING)
3070 ret = claw_release(ndev);
3071 ndev->flags &=~IFF_RUNNING;
3072 unregister_netdev(ndev);
Peter Tiedemann6951df32008-08-21 17:10:23 +02003073 ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 claw_free_netdevice(ndev, 1);
Heiko Carstens319cb082010-08-12 01:58:27 +00003075 priv->channel[READ_CHANNEL].ndev = NULL;
3076 priv->channel[WRITE_CHANNEL].ndev = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 priv->p_env->ndev = NULL;
3078 }
3079 ccw_device_set_offline(cgdev->cdev[1]);
3080 ccw_device_set_offline(cgdev->cdev[0]);
Heiko Carstens38ed18f2011-05-12 18:45:04 +00003081 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082}
3083
3084static void
3085claw_remove_device(struct ccwgroup_device *cgdev)
3086{
3087 struct claw_privbk *priv;
3088
Andy Richterb805da72008-07-18 15:24:56 +02003089 BUG_ON(!cgdev);
Cornelia Huckb9d3aed2008-10-10 21:33:11 +02003090 CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev));
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003091 priv = dev_get_drvdata(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003092 BUG_ON(!priv);
Andy Richter4811fcb2009-01-20 06:14:33 +00003093 dev_info(&cgdev->dev, " will be removed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 if (cgdev->state == CCWGROUP_ONLINE)
3095 claw_shutdown_device(cgdev);
3096 claw_remove_files(&cgdev->dev);
Jesper Juhl17fd6822005-11-07 01:01:30 -08003097 kfree(priv->p_mtc_envelope);
3098 priv->p_mtc_envelope=NULL;
3099 kfree(priv->p_env);
3100 priv->p_env=NULL;
3101 kfree(priv->channel[0].irb);
3102 priv->channel[0].irb=NULL;
3103 kfree(priv->channel[1].irb);
3104 priv->channel[1].irb=NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 kfree(priv);
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003106 dev_set_drvdata(&cgdev->dev, NULL);
Heiko Carstens319cb082010-08-12 01:58:27 +00003107 dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL);
3108 dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 put_device(&cgdev->dev);
Andy Richterb805da72008-07-18 15:24:56 +02003110
3111 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112}
3113
3114
3115/*
3116 * sysfs attributes
3117 */
3118static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003119claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120{
3121 struct claw_privbk *priv;
3122 struct claw_env * p_env;
3123
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003124 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 if (!priv)
3126 return -ENODEV;
3127 p_env = priv->p_env;
3128 return sprintf(buf, "%s\n",p_env->host_name);
3129}
3130
3131static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003132claw_hname_write(struct device *dev, struct device_attribute *attr,
3133 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134{
3135 struct claw_privbk *priv;
3136 struct claw_env * p_env;
3137
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003138 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 if (!priv)
3140 return -ENODEV;
3141 p_env = priv->p_env;
3142 if (count > MAX_NAME_LEN+1)
3143 return -EINVAL;
3144 memset(p_env->host_name, 0x20, MAX_NAME_LEN);
3145 strncpy(p_env->host_name,buf, count);
3146 p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */
3147 p_env->host_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003148 CLAW_DBF_TEXT(2, setup, "HstnSet");
3149 CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
3151 return count;
3152}
3153
3154static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write);
3155
3156static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003157claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158{
3159 struct claw_privbk *priv;
3160 struct claw_env * p_env;
3161
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003162 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 if (!priv)
3164 return -ENODEV;
3165 p_env = priv->p_env;
Andy Richterb805da72008-07-18 15:24:56 +02003166 return sprintf(buf, "%s\n", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167}
3168
3169static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003170claw_adname_write(struct device *dev, struct device_attribute *attr,
3171 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172{
3173 struct claw_privbk *priv;
3174 struct claw_env * p_env;
3175
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003176 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 if (!priv)
3178 return -ENODEV;
3179 p_env = priv->p_env;
3180 if (count > MAX_NAME_LEN+1)
3181 return -EINVAL;
3182 memset(p_env->adapter_name, 0x20, MAX_NAME_LEN);
3183 strncpy(p_env->adapter_name,buf, count);
3184 p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */
3185 p_env->adapter_name[MAX_NAME_LEN] = 0x00;
Andy Richterb805da72008-07-18 15:24:56 +02003186 CLAW_DBF_TEXT(2, setup, "AdnSet");
3187 CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 return count;
3190}
3191
3192static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write);
3193
3194static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003195claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196{
3197 struct claw_privbk *priv;
3198 struct claw_env * p_env;
3199
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003200 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 if (!priv)
3202 return -ENODEV;
3203 p_env = priv->p_env;
3204 return sprintf(buf, "%s\n",
3205 p_env->api_type);
3206}
3207
3208static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003209claw_apname_write(struct device *dev, struct device_attribute *attr,
3210 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211{
3212 struct claw_privbk *priv;
3213 struct claw_env * p_env;
3214
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003215 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 if (!priv)
3217 return -ENODEV;
3218 p_env = priv->p_env;
3219 if (count > MAX_NAME_LEN+1)
3220 return -EINVAL;
3221 memset(p_env->api_type, 0x20, MAX_NAME_LEN);
3222 strncpy(p_env->api_type,buf, count);
3223 p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */
3224 p_env->api_type[MAX_NAME_LEN] = 0x00;
3225 if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) {
3226 p_env->read_size=DEF_PACK_BUFSIZE;
3227 p_env->write_size=DEF_PACK_BUFSIZE;
3228 p_env->packing=PACKING_ASK;
Andy Richterb805da72008-07-18 15:24:56 +02003229 CLAW_DBF_TEXT(2, setup, "PACKING");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230 }
3231 else {
3232 p_env->packing=0;
3233 p_env->read_size=CLAW_FRAME_SIZE;
3234 p_env->write_size=CLAW_FRAME_SIZE;
Andy Richterb805da72008-07-18 15:24:56 +02003235 CLAW_DBF_TEXT(2, setup, "ApiSet");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 }
Andy Richterb805da72008-07-18 15:24:56 +02003237 CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 return count;
3239}
3240
3241static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write);
3242
3243static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003244claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245{
3246 struct claw_privbk *priv;
3247 struct claw_env * p_env;
3248
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003249 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 if (!priv)
3251 return -ENODEV;
3252 p_env = priv->p_env;
3253 return sprintf(buf, "%d\n", p_env->write_buffers);
3254}
3255
3256static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003257claw_wbuff_write(struct device *dev, struct device_attribute *attr,
3258 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259{
3260 struct claw_privbk *priv;
3261 struct claw_env * p_env;
3262 int nnn,max;
3263
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003264 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 if (!priv)
3266 return -ENODEV;
3267 p_env = priv->p_env;
3268 sscanf(buf, "%i", &nnn);
3269 if (p_env->packing) {
3270 max = 64;
3271 }
3272 else {
3273 max = 512;
3274 }
3275 if ((nnn > max ) || (nnn < 2))
3276 return -EINVAL;
3277 p_env->write_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003278 CLAW_DBF_TEXT(2, setup, "Wbufset");
3279 CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 return count;
3281}
3282
3283static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write);
3284
3285static ssize_t
Yani Ioannou3fd3c0a2005-05-17 06:43:27 -04003286claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287{
3288 struct claw_privbk *priv;
3289 struct claw_env * p_env;
3290
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003291 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 if (!priv)
3293 return -ENODEV;
3294 p_env = priv->p_env;
3295 return sprintf(buf, "%d\n", p_env->read_buffers);
3296}
3297
3298static ssize_t
Andy Richter4811fcb2009-01-20 06:14:33 +00003299claw_rbuff_write(struct device *dev, struct device_attribute *attr,
3300 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301{
3302 struct claw_privbk *priv;
3303 struct claw_env *p_env;
3304 int nnn,max;
3305
Greg Kroah-Hartmandff59b62009-05-04 12:40:54 -07003306 priv = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 if (!priv)
3308 return -ENODEV;
3309 p_env = priv->p_env;
3310 sscanf(buf, "%i", &nnn);
3311 if (p_env->packing) {
3312 max = 64;
3313 }
3314 else {
3315 max = 512;
3316 }
3317 if ((nnn > max ) || (nnn < 2))
3318 return -EINVAL;
3319 p_env->read_buffers = nnn;
Andy Richterb805da72008-07-18 15:24:56 +02003320 CLAW_DBF_TEXT(2, setup, "Rbufset");
3321 CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 return count;
3323}
3324
3325static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write);
3326
3327static struct attribute *claw_attr[] = {
3328 &dev_attr_read_buffer.attr,
3329 &dev_attr_write_buffer.attr,
3330 &dev_attr_adapter_name.attr,
3331 &dev_attr_api_type.attr,
3332 &dev_attr_host_name.attr,
3333 NULL,
3334};
3335
3336static struct attribute_group claw_attr_group = {
3337 .attrs = claw_attr,
3338};
3339
3340static int
3341claw_add_files(struct device *dev)
3342{
Andy Richterb805da72008-07-18 15:24:56 +02003343 CLAW_DBF_TEXT(2, setup, "add_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 return sysfs_create_group(&dev->kobj, &claw_attr_group);
3345}
3346
3347static void
3348claw_remove_files(struct device *dev)
3349{
Andy Richterb805da72008-07-18 15:24:56 +02003350 CLAW_DBF_TEXT(2, setup, "rem_file");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 sysfs_remove_group(&dev->kobj, &claw_attr_group);
3352}
3353
3354/*--------------------------------------------------------------------*
3355* claw_init and cleanup *
3356*---------------------------------------------------------------------*/
3357
3358static void __exit
3359claw_cleanup(void)
3360{
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003361 driver_remove_file(&claw_group_driver.driver,
3362 &driver_attr_group);
3363 ccwgroup_driver_unregister(&claw_group_driver);
3364 ccw_driver_unregister(&claw_ccw_driver);
3365 root_device_unregister(claw_root_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 claw_unregister_debug_facility();
Andy Richter4811fcb2009-01-20 06:14:33 +00003367 pr_info("Driver unloaded\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368
3369}
3370
3371/**
3372 * Initialize module.
3373 * This is called just after the module is loaded.
3374 *
3375 * @return 0 on success, !0 on error.
3376 */
3377static int __init
3378claw_init(void)
3379{
3380 int ret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
Andy Richter4811fcb2009-01-20 06:14:33 +00003382 pr_info("Loading %s\n", version);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 ret = claw_register_debug_facility();
3384 if (ret) {
Andy Richter4811fcb2009-01-20 06:14:33 +00003385 pr_err("Registering with the S/390 debug feature"
3386 " failed with error code %d\n", ret);
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003387 goto out_err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 }
Andy Richterb805da72008-07-18 15:24:56 +02003389 CLAW_DBF_TEXT(2, setup, "init_mod");
Ursula Braund950d172010-01-04 03:14:45 +00003390 claw_root_dev = root_device_register("claw");
Ursula Braun0ca8cc62009-11-12 21:46:29 +00003391 ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0;
3392 if (ret)
3393 goto register_err;
3394 ret = ccw_driver_register(&claw_ccw_driver);
3395 if (ret)
3396 goto ccw_err;
3397 claw_group_driver.driver.groups = claw_group_attr_groups;
3398 ret = ccwgroup_driver_register(&claw_group_driver);
3399 if (ret)
3400 goto ccwgroup_err;
3401 return 0;
3402
3403ccwgroup_err:
3404 ccw_driver_unregister(&claw_ccw_driver);
3405ccw_err:
3406 root_device_unregister(claw_root_dev);
3407register_err:
3408 CLAW_DBF_TEXT(2, setup, "init_bad");
3409 claw_unregister_debug_facility();
3410out_err:
3411 pr_err("Initializing the claw device driver failed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 return ret;
3413}
3414
3415module_init(claw_init);
3416module_exit(claw_cleanup);
3417
Andy Richterb805da72008-07-18 15:24:56 +02003418MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>");
3419MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \
3420 "Copyright 2000,2008 IBM Corporation\n");
3421MODULE_LICENSE("GPL");