Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/net/claw.c |
| 3 | * ESCON CLAW network driver |
| 4 | * |
Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 5 | * Linux for zSeries version |
Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 6 | * Copyright IBM Corp. 2002, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Author(s) Original code written by: |
Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 8 | * Kazuo Iimura <iimura@jp.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Rewritten by |
Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 10 | * Andy Richter <richtera@us.ibm.com> |
| 11 | * Marc Price <mwprice@us.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * |
| 13 | * sysfs parms: |
| 14 | * group x.x.rrrr,x.x.wwww |
| 15 | * read_buffer nnnnnnn |
| 16 | * write_buffer nnnnnn |
| 17 | * host_name aaaaaaaa |
| 18 | * adapter_name aaaaaaaa |
| 19 | * api_type aaaaaaaa |
| 20 | * |
| 21 | * eg. |
| 22 | * group 0.0.0200 0.0.0201 |
| 23 | * read_buffer 25 |
| 24 | * write_buffer 20 |
| 25 | * host_name LINUX390 |
| 26 | * adapter_name RS6K |
| 27 | * api_type TCPIP |
| 28 | * |
| 29 | * where |
| 30 | * |
| 31 | * The device id is decided by the order entries |
| 32 | * are added to the group the first is claw0 the second claw1 |
| 33 | * up to CLAW_MAX_DEV |
| 34 | * |
| 35 | * rrrr - the first of 2 consecutive device addresses used for the |
| 36 | * CLAW protocol. |
| 37 | * The specified address is always used as the input (Read) |
| 38 | * channel and the next address is used as the output channel. |
| 39 | * |
| 40 | * wwww - the second of 2 consecutive device addresses used for |
| 41 | * the CLAW protocol. |
| 42 | * The specified address is always used as the output |
| 43 | * channel and the previous address is used as the input channel. |
| 44 | * |
| 45 | * read_buffer - specifies number of input buffers to allocate. |
| 46 | * write_buffer - specifies number of output buffers to allocate. |
| 47 | * host_name - host name |
| 48 | * adaptor_name - adaptor name |
| 49 | * api_type - API type TCPIP or API will be sent and expected |
| 50 | * as ws_name |
| 51 | * |
| 52 | * Note the following requirements: |
| 53 | * 1) host_name must match the configured adapter_name on the remote side |
| 54 | * 2) adaptor_name must match the configured host name on the remote side |
| 55 | * |
| 56 | * Change History |
| 57 | * 1.00 Initial release shipped |
| 58 | * 1.10 Changes for Buffer allocation |
| 59 | * 1.15 Changed for 2.6 Kernel No longer compiles on 2.4 or lower |
| 60 | * 1.25 Added Packing support |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 61 | * 1.5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | */ |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 63 | |
| 64 | #define KMSG_COMPONENT "claw" |
| 65 | |
Heiko Carstens | 355eb40 | 2011-01-05 12:47:36 +0100 | [diff] [blame] | 66 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | #include <asm/ccwdev.h> |
| 68 | #include <asm/ccwgroup.h> |
| 69 | #include <asm/debug.h> |
| 70 | #include <asm/idals.h> |
| 71 | #include <asm/io.h> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 72 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #include <linux/ctype.h> |
| 74 | #include <linux/delay.h> |
| 75 | #include <linux/errno.h> |
| 76 | #include <linux/if_arp.h> |
| 77 | #include <linux/init.h> |
| 78 | #include <linux/interrupt.h> |
| 79 | #include <linux/ip.h> |
| 80 | #include <linux/kernel.h> |
| 81 | #include <linux/module.h> |
| 82 | #include <linux/netdevice.h> |
| 83 | #include <linux/etherdevice.h> |
| 84 | #include <linux/proc_fs.h> |
| 85 | #include <linux/sched.h> |
| 86 | #include <linux/signal.h> |
| 87 | #include <linux/skbuff.h> |
| 88 | #include <linux/slab.h> |
| 89 | #include <linux/string.h> |
| 90 | #include <linux/tcp.h> |
| 91 | #include <linux/timer.h> |
| 92 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #include "claw.h" |
| 95 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 96 | /* |
| 97 | CLAW uses the s390dbf file system see claw_trace and claw_setup |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | */ |
| 99 | |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 100 | static char version[] __initdata = "CLAW driver"; |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 101 | static char debug_buffer[255]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | /** |
| 103 | * Debug Facility Stuff |
| 104 | */ |
| 105 | static debug_info_t *claw_dbf_setup; |
| 106 | static debug_info_t *claw_dbf_trace; |
| 107 | |
| 108 | /** |
| 109 | * CLAW Debug Facility functions |
| 110 | */ |
| 111 | static void |
| 112 | claw_unregister_debug_facility(void) |
| 113 | { |
| 114 | if (claw_dbf_setup) |
| 115 | debug_unregister(claw_dbf_setup); |
| 116 | if (claw_dbf_trace) |
| 117 | debug_unregister(claw_dbf_trace); |
| 118 | } |
| 119 | |
| 120 | static int |
| 121 | claw_register_debug_facility(void) |
| 122 | { |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 123 | claw_dbf_setup = debug_register("claw_setup", 2, 1, 8); |
| 124 | claw_dbf_trace = debug_register("claw_trace", 2, 2, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | if (claw_dbf_setup == NULL || claw_dbf_trace == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | claw_unregister_debug_facility(); |
| 127 | return -ENOMEM; |
| 128 | } |
| 129 | debug_register_view(claw_dbf_setup, &debug_hex_ascii_view); |
| 130 | debug_set_level(claw_dbf_setup, 2); |
| 131 | debug_register_view(claw_dbf_trace, &debug_hex_ascii_view); |
| 132 | debug_set_level(claw_dbf_trace, 2); |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | static inline void |
| 137 | claw_set_busy(struct net_device *dev) |
| 138 | { |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 139 | ((struct claw_privbk *)dev->ml_priv)->tbusy = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | eieio(); |
| 141 | } |
| 142 | |
| 143 | static inline void |
| 144 | claw_clear_busy(struct net_device *dev) |
| 145 | { |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 146 | clear_bit(0, &(((struct claw_privbk *) dev->ml_priv)->tbusy)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | netif_wake_queue(dev); |
| 148 | eieio(); |
| 149 | } |
| 150 | |
| 151 | static inline int |
| 152 | claw_check_busy(struct net_device *dev) |
| 153 | { |
| 154 | eieio(); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 155 | return ((struct claw_privbk *) dev->ml_priv)->tbusy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | static inline void |
| 159 | claw_setbit_busy(int nr,struct net_device *dev) |
| 160 | { |
| 161 | netif_stop_queue(dev); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 162 | set_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | static inline void |
| 166 | claw_clearbit_busy(int nr,struct net_device *dev) |
| 167 | { |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 168 | clear_bit(nr, (void *)&(((struct claw_privbk *)dev->ml_priv)->tbusy)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | netif_wake_queue(dev); |
| 170 | } |
| 171 | |
| 172 | static inline int |
| 173 | claw_test_and_setbit_busy(int nr,struct net_device *dev) |
| 174 | { |
| 175 | netif_stop_queue(dev); |
| 176 | return test_and_set_bit(nr, |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 177 | (void *)&(((struct claw_privbk *) dev->ml_priv)->tbusy)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
| 180 | |
| 181 | /* Functions for the DEV methods */ |
| 182 | |
| 183 | static int claw_probe(struct ccwgroup_device *cgdev); |
| 184 | static void claw_remove_device(struct ccwgroup_device *cgdev); |
| 185 | static void claw_purge_skb_queue(struct sk_buff_head *q); |
| 186 | static int claw_new_device(struct ccwgroup_device *cgdev); |
| 187 | static int claw_shutdown_device(struct ccwgroup_device *cgdev); |
| 188 | static int claw_tx(struct sk_buff *skb, struct net_device *dev); |
| 189 | static int claw_change_mtu( struct net_device *dev, int new_mtu); |
| 190 | static int claw_open(struct net_device *dev); |
| 191 | static void claw_irq_handler(struct ccw_device *cdev, |
| 192 | unsigned long intparm, struct irb *irb); |
| 193 | static void claw_irq_tasklet ( unsigned long data ); |
| 194 | static int claw_release(struct net_device *dev); |
| 195 | static void claw_write_retry ( struct chbk * p_ch ); |
| 196 | static void claw_write_next ( struct chbk * p_ch ); |
| 197 | static void claw_timer ( struct chbk * p_ch ); |
| 198 | |
| 199 | /* Functions */ |
| 200 | static int add_claw_reads(struct net_device *dev, |
| 201 | struct ccwbk* p_first, struct ccwbk* p_last); |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 202 | static void ccw_check_return_code (struct ccw_device *cdev, int return_code); |
| 203 | static void ccw_check_unit_check (struct chbk * p_ch, unsigned char sense ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | static int find_link(struct net_device *dev, char *host_name, char *ws_name ); |
| 205 | static int claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid); |
| 206 | static int init_ccw_bk(struct net_device *dev); |
| 207 | static void probe_error( struct ccwgroup_device *cgdev); |
| 208 | static struct net_device_stats *claw_stats(struct net_device *dev); |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 209 | static int pages_to_order_of_mag(int num_of_pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | static struct sk_buff *claw_pack_skb(struct claw_privbk *privptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | /* sysfs Functions */ |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 212 | static ssize_t claw_hname_show(struct device *dev, |
| 213 | struct device_attribute *attr, char *buf); |
| 214 | static ssize_t claw_hname_write(struct device *dev, |
| 215 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | const char *buf, size_t count); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 217 | static ssize_t claw_adname_show(struct device *dev, |
| 218 | struct device_attribute *attr, char *buf); |
| 219 | static ssize_t claw_adname_write(struct device *dev, |
| 220 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | const char *buf, size_t count); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 222 | static ssize_t claw_apname_show(struct device *dev, |
| 223 | struct device_attribute *attr, char *buf); |
| 224 | static ssize_t claw_apname_write(struct device *dev, |
| 225 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | const char *buf, size_t count); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 227 | static ssize_t claw_wbuff_show(struct device *dev, |
| 228 | struct device_attribute *attr, char *buf); |
| 229 | static ssize_t claw_wbuff_write(struct device *dev, |
| 230 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | const char *buf, size_t count); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 232 | static ssize_t claw_rbuff_show(struct device *dev, |
| 233 | struct device_attribute *attr, char *buf); |
| 234 | static ssize_t claw_rbuff_write(struct device *dev, |
| 235 | struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | const char *buf, size_t count); |
| 237 | static int claw_add_files(struct device *dev); |
| 238 | static void claw_remove_files(struct device *dev); |
| 239 | |
| 240 | /* Functions for System Validate */ |
| 241 | static int claw_process_control( struct net_device *dev, struct ccwbk * p_ccw); |
| 242 | static int claw_send_control(struct net_device *dev, __u8 type, __u8 link, |
| 243 | __u8 correlator, __u8 rc , char *local_name, char *remote_name); |
| 244 | static int claw_snd_conn_req(struct net_device *dev, __u8 link); |
| 245 | static int claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl); |
| 246 | static int claw_snd_sys_validate_rsp(struct net_device *dev, |
| 247 | struct clawctl * p_ctl, __u32 return_code); |
| 248 | static int claw_strt_conn_req(struct net_device *dev ); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 249 | static void claw_strt_read(struct net_device *dev, int lock); |
| 250 | static void claw_strt_out_IO(struct net_device *dev); |
| 251 | static void claw_free_wrt_buf(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | /* Functions for unpack reads */ |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 254 | static void unpack_read(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 256 | static int claw_pm_prepare(struct ccwgroup_device *gdev) |
| 257 | { |
| 258 | return -EPERM; |
| 259 | } |
| 260 | |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 261 | /* the root device for claw group devices */ |
| 262 | static struct device *claw_root_dev; |
| 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /* ccwgroup table */ |
| 265 | |
| 266 | static struct ccwgroup_driver claw_group_driver = { |
Sebastian Ott | 3c190c5 | 2011-03-23 10:16:04 +0100 | [diff] [blame] | 267 | .driver = { |
| 268 | .owner = THIS_MODULE, |
| 269 | .name = "claw", |
| 270 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | .max_slaves = 2, |
| 272 | .driver_id = 0xC3D3C1E6, |
| 273 | .probe = claw_probe, |
| 274 | .remove = claw_remove_device, |
| 275 | .set_online = claw_new_device, |
| 276 | .set_offline = claw_shutdown_device, |
Frank Blaschka | 88efc2c | 2009-06-16 10:30:33 +0200 | [diff] [blame] | 277 | .prepare = claw_pm_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | }; |
| 279 | |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 280 | static struct ccw_device_id claw_ids[] = { |
| 281 | {CCW_DEVICE(0x3088, 0x61), .driver_info = claw_channel_type_claw}, |
| 282 | {}, |
| 283 | }; |
| 284 | MODULE_DEVICE_TABLE(ccw, claw_ids); |
| 285 | |
| 286 | static struct ccw_driver claw_ccw_driver = { |
Sebastian Ott | 3bda058 | 2011-03-23 10:16:02 +0100 | [diff] [blame] | 287 | .driver = { |
| 288 | .owner = THIS_MODULE, |
| 289 | .name = "claw", |
| 290 | }, |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 291 | .ids = claw_ids, |
| 292 | .probe = ccwgroup_probe_ccwdev, |
| 293 | .remove = ccwgroup_remove_ccwdev, |
| 294 | }; |
| 295 | |
| 296 | static ssize_t |
| 297 | claw_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 Braun | e48d24a | 2010-07-22 23:15:07 +0000 | [diff] [blame] | 303 | &claw_ccw_driver, 2, buf); |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 304 | return err ? err : count; |
| 305 | } |
| 306 | |
| 307 | static DRIVER_ATTR(group, 0200, NULL, claw_driver_group_store); |
| 308 | |
| 309 | static struct attribute *claw_group_attrs[] = { |
| 310 | &driver_attr_group.attr, |
| 311 | NULL, |
| 312 | }; |
| 313 | |
| 314 | static struct attribute_group claw_group_attr_group = { |
| 315 | .attrs = claw_group_attrs, |
| 316 | }; |
| 317 | |
Heiko Carstens | 302689a | 2009-11-17 06:47:02 -0800 | [diff] [blame] | 318 | static const struct attribute_group *claw_group_attr_groups[] = { |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 319 | &claw_group_attr_group, |
| 320 | NULL, |
| 321 | }; |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | * Key functions |
| 325 | */ |
| 326 | |
| 327 | /*----------------------------------------------------------------* |
| 328 | * claw_probe * |
| 329 | * this function is called for each CLAW device. * |
| 330 | *----------------------------------------------------------------*/ |
| 331 | static int |
| 332 | claw_probe(struct ccwgroup_device *cgdev) |
| 333 | { |
| 334 | int rc; |
| 335 | struct claw_privbk *privptr=NULL; |
| 336 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 337 | CLAW_DBF_TEXT(2, setup, "probe"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (!get_device(&cgdev->dev)) |
| 339 | return -ENODEV; |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 340 | privptr = kzalloc(sizeof(struct claw_privbk), GFP_KERNEL); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 341 | dev_set_drvdata(&cgdev->dev, privptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | if (privptr == NULL) { |
| 343 | probe_error(cgdev); |
| 344 | put_device(&cgdev->dev); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 345 | CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return -ENOMEM; |
| 347 | } |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 348 | privptr->p_mtc_envelope= kzalloc( MAX_ENVELOPE_SIZE, GFP_KERNEL); |
| 349 | privptr->p_env = kzalloc(sizeof(struct claw_env), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if ((privptr->p_mtc_envelope==NULL) || (privptr->p_env==NULL)) { |
| 351 | probe_error(cgdev); |
| 352 | put_device(&cgdev->dev); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 353 | CLAW_DBF_TEXT_(2, setup, "probex%d", -ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return -ENOMEM; |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | 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 Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 368 | dev_err(&cgdev->dev, "Creating the /proc files for a new" |
| 369 | " CLAW device failed\n"); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 370 | CLAW_DBF_TEXT_(2, setup, "probex%d", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | return rc; |
| 372 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | privptr->p_env->p_priv = privptr; |
| 374 | cgdev->cdev[0]->handler = claw_irq_handler; |
| 375 | cgdev->cdev[1]->handler = claw_irq_handler; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 376 | CLAW_DBF_TEXT(2, setup, "prbext 0"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
| 378 | return 0; |
| 379 | } /* end of claw_probe */ |
| 380 | |
| 381 | /*-------------------------------------------------------------------* |
| 382 | * claw_tx * |
| 383 | *-------------------------------------------------------------------*/ |
| 384 | |
| 385 | static int |
| 386 | claw_tx(struct sk_buff *skb, struct net_device *dev) |
| 387 | { |
| 388 | int rc; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 389 | struct claw_privbk *privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | unsigned long saveflags; |
| 391 | struct chbk *p_ch; |
| 392 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 393 | CLAW_DBF_TEXT(4, trace, "claw_tx"); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 394 | p_ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | 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 Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 398 | CLAW_DBF_TEXT_(4, trace, "clawtx%d", rc); |
Ursula Braun | 8f0c40d | 2009-03-24 03:27:46 +0000 | [diff] [blame] | 399 | if (rc) |
| 400 | rc = NETDEV_TX_BUSY; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 401 | else |
| 402 | rc = NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 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 | |
| 411 | static struct sk_buff * |
| 412 | claw_pack_skb(struct claw_privbk *privptr) |
| 413 | { |
| 414 | struct sk_buff *new_skb,*held_skb; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 415 | struct chbk *p_ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | 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 Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 421 | CLAW_DBF_TEXT(4, trace, "PackSKBe"); |
David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 422 | if (!skb_queue_empty(&p_ch->collect_queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | /* some data */ |
| 424 | held_skb = skb_dequeue(&p_ch->collect_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | if (held_skb) |
Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 426 | dev_kfree_skb_any(held_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | else |
| 428 | return NULL; |
Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 429 | if (p_env->packing != DO_PACKED) |
| 430 | return held_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* 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 Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 449 | dev_kfree_skb_any(held_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 460 | CLAW_DBF_TEXT(4, trace, "PackSKBx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | return new_skb; |
| 462 | } |
| 463 | |
| 464 | /*-------------------------------------------------------------------* |
| 465 | * claw_change_mtu * |
| 466 | * * |
| 467 | *-------------------------------------------------------------------*/ |
| 468 | |
| 469 | static int |
| 470 | claw_change_mtu(struct net_device *dev, int new_mtu) |
| 471 | { |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 472 | struct claw_privbk *privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | int buff_size; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 474 | CLAW_DBF_TEXT(4, trace, "setmtu"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | buff_size = privptr->p_env->write_size; |
| 476 | if ((new_mtu < 60) || (new_mtu > buff_size)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | return -EINVAL; |
| 478 | } |
| 479 | dev->mtu = new_mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return 0; |
| 481 | } /* end of claw_change_mtu */ |
| 482 | |
| 483 | |
| 484 | /*-------------------------------------------------------------------* |
| 485 | * claw_open * |
| 486 | * * |
| 487 | *-------------------------------------------------------------------*/ |
| 488 | static int |
| 489 | claw_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 Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 501 | CLAW_DBF_TEXT(4, trace, "open"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 502 | privptr = (struct claw_privbk *)dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | /* allocate and initialize CCW blocks */ |
| 504 | if (privptr->buffs_alloc == 0) { |
| 505 | rc=init_ccw_bk(dev); |
| 506 | if (rc) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 507 | CLAW_DBF_TEXT(2, trace, "openmem"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | 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 Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 523 | tasklet_init(&privptr->channel[READ_CHANNEL].tasklet, claw_irq_tasklet, |
| 524 | (unsigned long) &privptr->channel[READ_CHANNEL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | for ( i = 0; i < 2; i++) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 526 | CLAW_DBF_TEXT_(2, trace, "opn_ch%d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | init_waitqueue_head(&privptr->channel[i].wait); |
| 528 | /* skb_queue_head_init(&p_ch->io_queue); */ |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 529 | if (i == WRITE_CHANNEL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | skb_queue_head_init( |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 531 | &privptr->channel[WRITE_CHANNEL].collect_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | 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 Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 559 | if ((((privptr->channel[READ_CHANNEL].last_dstat | |
| 560 | privptr->channel[WRITE_CHANNEL].last_dstat) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) || |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 562 | (((privptr->channel[READ_CHANNEL].flag | |
| 563 | privptr->channel[WRITE_CHANNEL].flag) & CLAW_TIMER) != 0x00)) { |
| 564 | dev_info(&privptr->channel[READ_CHANNEL].cdev->dev, |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 565 | "%s: remote side is not ready\n", dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 566 | CLAW_DBF_TEXT(2, trace, "notrdy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 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 Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 616 | privptr->channel[READ_CHANNEL].flag = 0x00; |
| 617 | privptr->channel[WRITE_CHANNEL].flag = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | privptr->p_buff_ccw=NULL; |
| 619 | privptr->p_buff_read=NULL; |
| 620 | privptr->p_buff_write=NULL; |
| 621 | claw_clear_busy(dev); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 622 | CLAW_DBF_TEXT(2, trace, "open EIO"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | return -EIO; |
| 624 | } |
| 625 | |
| 626 | /* Send SystemValidate command */ |
| 627 | |
| 628 | claw_clear_busy(dev); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 629 | CLAW_DBF_TEXT(4, trace, "openok"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | return 0; |
| 631 | } /* end of claw_open */ |
| 632 | |
| 633 | /*-------------------------------------------------------------------* |
| 634 | * * |
| 635 | * claw_irq_handler * |
| 636 | * * |
| 637 | *--------------------------------------------------------------------*/ |
| 638 | static void |
| 639 | claw_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 | |
Heiko Carstens | 355eb40 | 2011-01-05 12:47:36 +0100 | [diff] [blame] | 648 | kstat_cpu(smp_processor_id()).irqs[IOINT_CLW]++; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 649 | CLAW_DBF_TEXT(4, trace, "clawirq"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | /* Bypass all 'unsolicited interrupts' */ |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 651 | privptr = dev_get_drvdata(&cdev->dev); |
| 652 | if (!privptr) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 653 | dev_warn(&cdev->dev, "An uninitialized CLAW device received an" |
| 654 | " IRQ, c-%02x d-%02x\n", |
| 655 | irb->scsw.cmd.cstat, irb->scsw.cmd.dstat); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 656 | CLAW_DBF_TEXT(2, trace, "badirq"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | return; |
| 658 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | /* Try to extract channel from driver data. */ |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 661 | if (privptr->channel[READ_CHANNEL].cdev == cdev) |
| 662 | p_ch = &privptr->channel[READ_CHANNEL]; |
| 663 | else if (privptr->channel[WRITE_CHANNEL].cdev == cdev) |
| 664 | p_ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | else { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 666 | dev_warn(&cdev->dev, "The device is not a CLAW device\n"); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 667 | CLAW_DBF_TEXT(2, trace, "badchan"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return; |
| 669 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 670 | CLAW_DBF_TEXT_(4, trace, "IRQCH=%d", p_ch->flag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
| 672 | dev = (struct net_device *) (p_ch->ndev); |
| 673 | p_env=privptr->p_env; |
| 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* Copy interruption response block. */ |
| 676 | memcpy(p_ch->irb, irb, sizeof(struct irb)); |
| 677 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 678 | /* Check for good subchannel return code, otherwise info message */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 679 | if (irb->scsw.cmd.cstat && !(irb->scsw.cmd.cstat & SCHN_STAT_PCI)) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 680 | dev_info(&cdev->dev, |
| 681 | "%s: subchannel check for device: %04x -" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | " Sch Stat %02x Dev Stat %02x CPA - %04x\n", |
| 683 | dev->name, p_ch->devno, |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 684 | irb->scsw.cmd.cstat, irb->scsw.cmd.dstat, |
| 685 | irb->scsw.cmd.cpa); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 686 | CLAW_DBF_TEXT(2, trace, "chanchk"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /* return; */ |
| 688 | } |
| 689 | |
| 690 | /* Check the reason-code of a unit check */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 691 | if (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | ccw_check_unit_check(p_ch, irb->ecw[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
| 694 | /* State machine to bring the connection up, down and to restart */ |
Peter Oberparleiter | 23d805b | 2008-07-14 09:58:50 +0200 | [diff] [blame] | 695 | p_ch->last_dstat = irb->scsw.cmd.dstat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
| 697 | switch (p_ch->claw_state) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 698 | case CLAW_STOP:/* HALT_IO by claw_release (halt sequence) */ |
| 699 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || |
| 700 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || |
| 701 | (p_ch->irb->scsw.cmd.stctl == |
| 702 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) |
| 703 | return; |
| 704 | wake_up(&p_ch->wait); /* wake up claw_release */ |
| 705 | CLAW_DBF_TEXT(4, trace, "stop"); |
| 706 | return; |
| 707 | case CLAW_START_HALT_IO: /* HALT_IO issued by claw_open */ |
| 708 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || |
| 709 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || |
| 710 | (p_ch->irb->scsw.cmd.stctl == |
| 711 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { |
| 712 | CLAW_DBF_TEXT(4, trace, "haltio"); |
| 713 | return; |
| 714 | } |
| 715 | if (p_ch->flag == CLAW_READ) { |
| 716 | p_ch->claw_state = CLAW_START_READ; |
| 717 | wake_up(&p_ch->wait); /* wake claw_open (READ)*/ |
| 718 | } else if (p_ch->flag == CLAW_WRITE) { |
| 719 | p_ch->claw_state = CLAW_START_WRITE; |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 720 | /* send SYSTEM_VALIDATE */ |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 721 | claw_strt_read(dev, LOCK_NO); |
| 722 | claw_send_control(dev, |
| 723 | SYSTEM_VALIDATE_REQUEST, |
| 724 | 0, 0, 0, |
| 725 | p_env->host_name, |
| 726 | p_env->adapter_name); |
| 727 | } else { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 728 | dev_warn(&cdev->dev, "The CLAW device received" |
| 729 | " an unexpected IRQ, " |
| 730 | "c-%02x d-%02x\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 731 | irb->scsw.cmd.cstat, |
| 732 | irb->scsw.cmd.dstat); |
| 733 | return; |
| 734 | } |
| 735 | CLAW_DBF_TEXT(4, trace, "haltio"); |
| 736 | return; |
| 737 | case CLAW_START_READ: |
| 738 | CLAW_DBF_TEXT(4, trace, "ReadIRQ"); |
| 739 | if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { |
| 740 | clear_bit(0, (void *)&p_ch->IO_active); |
| 741 | if ((p_ch->irb->ecw[0] & 0x41) == 0x41 || |
| 742 | (p_ch->irb->ecw[0] & 0x40) == 0x40 || |
| 743 | (p_ch->irb->ecw[0]) == 0) { |
| 744 | privptr->stats.rx_errors++; |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 745 | dev_info(&cdev->dev, |
| 746 | "%s: Restart is required after remote " |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 747 | "side recovers \n", |
| 748 | dev->name); |
| 749 | } |
| 750 | CLAW_DBF_TEXT(4, trace, "notrdy"); |
| 751 | return; |
| 752 | } |
| 753 | if ((p_ch->irb->scsw.cmd.cstat & SCHN_STAT_PCI) && |
| 754 | (p_ch->irb->scsw.cmd.dstat == 0)) { |
| 755 | if (test_and_set_bit(CLAW_BH_ACTIVE, |
| 756 | (void *)&p_ch->flag_a) == 0) |
| 757 | tasklet_schedule(&p_ch->tasklet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | else |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 759 | CLAW_DBF_TEXT(4, trace, "PCINoBH"); |
| 760 | CLAW_DBF_TEXT(4, trace, "PCI_read"); |
| 761 | return; |
| 762 | } |
| 763 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || |
| 764 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || |
| 765 | (p_ch->irb->scsw.cmd.stctl == |
| 766 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { |
| 767 | CLAW_DBF_TEXT(4, trace, "SPend_rd"); |
| 768 | return; |
| 769 | } |
| 770 | clear_bit(0, (void *)&p_ch->IO_active); |
| 771 | claw_clearbit_busy(TB_RETRY, dev); |
| 772 | if (test_and_set_bit(CLAW_BH_ACTIVE, |
| 773 | (void *)&p_ch->flag_a) == 0) |
| 774 | tasklet_schedule(&p_ch->tasklet); |
| 775 | else |
| 776 | CLAW_DBF_TEXT(4, trace, "RdBHAct"); |
| 777 | CLAW_DBF_TEXT(4, trace, "RdIRQXit"); |
| 778 | return; |
| 779 | case CLAW_START_WRITE: |
| 780 | if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 781 | dev_info(&cdev->dev, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 782 | "%s: Unit Check Occurred in " |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 783 | "write channel\n", dev->name); |
| 784 | clear_bit(0, (void *)&p_ch->IO_active); |
| 785 | if (p_ch->irb->ecw[0] & 0x80) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 786 | dev_info(&cdev->dev, |
| 787 | "%s: Resetting Event " |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 788 | "occurred:\n", dev->name); |
| 789 | init_timer(&p_ch->timer); |
| 790 | p_ch->timer.function = |
| 791 | (void *)claw_write_retry; |
| 792 | p_ch->timer.data = (unsigned long)p_ch; |
| 793 | p_ch->timer.expires = jiffies + 10*HZ; |
| 794 | add_timer(&p_ch->timer); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 795 | dev_info(&cdev->dev, |
| 796 | "%s: write connection " |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 797 | "restarting\n", dev->name); |
| 798 | } |
| 799 | CLAW_DBF_TEXT(4, trace, "rstrtwrt"); |
| 800 | return; |
| 801 | } |
| 802 | if (p_ch->irb->scsw.cmd.dstat & DEV_STAT_UNIT_EXCEP) { |
| 803 | clear_bit(0, (void *)&p_ch->IO_active); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 804 | dev_info(&cdev->dev, |
| 805 | "%s: Unit Exception " |
| 806 | "occurred in write channel\n", |
| 807 | dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 808 | } |
| 809 | if (!((p_ch->irb->scsw.cmd.stctl & SCSW_STCTL_SEC_STATUS) || |
| 810 | (p_ch->irb->scsw.cmd.stctl == SCSW_STCTL_STATUS_PEND) || |
| 811 | (p_ch->irb->scsw.cmd.stctl == |
| 812 | (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)))) { |
| 813 | CLAW_DBF_TEXT(4, trace, "writeUE"); |
| 814 | return; |
| 815 | } |
| 816 | clear_bit(0, (void *)&p_ch->IO_active); |
| 817 | if (claw_test_and_setbit_busy(TB_TX, dev) == 0) { |
| 818 | claw_write_next(p_ch); |
| 819 | claw_clearbit_busy(TB_TX, dev); |
| 820 | claw_clear_busy(dev); |
| 821 | } |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 822 | p_ch_r = (struct chbk *)&privptr->channel[READ_CHANNEL]; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 823 | if (test_and_set_bit(CLAW_BH_ACTIVE, |
| 824 | (void *)&p_ch_r->flag_a) == 0) |
| 825 | tasklet_schedule(&p_ch_r->tasklet); |
| 826 | CLAW_DBF_TEXT(4, trace, "StWtExit"); |
| 827 | return; |
| 828 | default: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 829 | dev_warn(&cdev->dev, |
| 830 | "The CLAW device for %s received an unexpected IRQ\n", |
| 831 | dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 832 | CLAW_DBF_TEXT(2, trace, "badIRQ"); |
| 833 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | } /* end of claw_irq_handler */ |
| 837 | |
| 838 | |
| 839 | /*-------------------------------------------------------------------* |
| 840 | * claw_irq_tasklet * |
| 841 | * * |
| 842 | *--------------------------------------------------------------------*/ |
| 843 | static void |
| 844 | claw_irq_tasklet ( unsigned long data ) |
| 845 | { |
| 846 | struct chbk * p_ch; |
| 847 | struct net_device *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
| 849 | p_ch = (struct chbk *) data; |
| 850 | dev = (struct net_device *)p_ch->ndev; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 851 | CLAW_DBF_TEXT(4, trace, "IRQtask"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | unpack_read(dev); |
| 853 | clear_bit(CLAW_BH_ACTIVE, (void *)&p_ch->flag_a); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 854 | CLAW_DBF_TEXT(4, trace, "TskletXt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | return; |
| 856 | } /* end of claw_irq_bh */ |
| 857 | |
| 858 | /*-------------------------------------------------------------------* |
| 859 | * claw_release * |
| 860 | * * |
| 861 | *--------------------------------------------------------------------*/ |
| 862 | static int |
| 863 | claw_release(struct net_device *dev) |
| 864 | { |
| 865 | int rc; |
| 866 | int i; |
| 867 | unsigned long saveflags; |
| 868 | unsigned long parm; |
| 869 | struct claw_privbk *privptr; |
| 870 | DECLARE_WAITQUEUE(wait, current); |
| 871 | struct ccwbk* p_this_ccw; |
| 872 | struct ccwbk* p_buf; |
| 873 | |
| 874 | if (!dev) |
| 875 | return 0; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 876 | privptr = (struct claw_privbk *)dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | if (!privptr) |
| 878 | return 0; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 879 | CLAW_DBF_TEXT(4, trace, "release"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | privptr->release_pend=1; |
| 881 | claw_setbit_busy(TB_STOP,dev); |
| 882 | for ( i = 1; i >=0 ; i--) { |
| 883 | spin_lock_irqsave( |
| 884 | get_ccwdev_lock(privptr->channel[i].cdev), saveflags); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 885 | /* del_timer(&privptr->channel[READ_CHANNEL].timer); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | privptr->channel[i].claw_state = CLAW_STOP; |
| 887 | privptr->channel[i].IO_active = 0; |
| 888 | parm = (unsigned long) &privptr->channel[i]; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 889 | if (i == WRITE_CHANNEL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | claw_purge_skb_queue( |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 891 | &privptr->channel[WRITE_CHANNEL].collect_queue); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | rc = ccw_device_halt (privptr->channel[i].cdev, parm); |
| 893 | if (privptr->system_validate_comp==0x00) /* never opened? */ |
| 894 | init_waitqueue_head(&privptr->channel[i].wait); |
| 895 | add_wait_queue(&privptr->channel[i].wait, &wait); |
| 896 | set_current_state(TASK_INTERRUPTIBLE); |
| 897 | spin_unlock_irqrestore( |
| 898 | get_ccwdev_lock(privptr->channel[i].cdev), saveflags); |
| 899 | schedule(); |
| 900 | set_current_state(TASK_RUNNING); |
| 901 | remove_wait_queue(&privptr->channel[i].wait, &wait); |
| 902 | if (rc != 0) { |
| 903 | ccw_check_return_code(privptr->channel[i].cdev, rc); |
| 904 | } |
| 905 | } |
| 906 | if (privptr->pk_skb != NULL) { |
Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 907 | dev_kfree_skb_any(privptr->pk_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | privptr->pk_skb = NULL; |
| 909 | } |
| 910 | if(privptr->buffs_alloc != 1) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 911 | CLAW_DBF_TEXT(4, trace, "none2fre"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | return 0; |
| 913 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 914 | CLAW_DBF_TEXT(4, trace, "freebufs"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | if (privptr->p_buff_ccw != NULL) { |
| 916 | free_pages((unsigned long)privptr->p_buff_ccw, |
| 917 | (int)pages_to_order_of_mag(privptr->p_buff_ccw_num)); |
| 918 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 919 | CLAW_DBF_TEXT(4, trace, "freeread"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | if (privptr->p_env->read_size < PAGE_SIZE) { |
| 921 | if (privptr->p_buff_read != NULL) { |
| 922 | free_pages((unsigned long)privptr->p_buff_read, |
| 923 | (int)pages_to_order_of_mag(privptr->p_buff_read_num)); |
| 924 | } |
| 925 | } |
| 926 | else { |
| 927 | p_buf=privptr->p_read_active_first; |
| 928 | while (p_buf!=NULL) { |
| 929 | free_pages((unsigned long)p_buf->p_buffer, |
| 930 | (int)pages_to_order_of_mag( |
| 931 | privptr->p_buff_pages_perread )); |
| 932 | p_buf=p_buf->next; |
| 933 | } |
| 934 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 935 | CLAW_DBF_TEXT(4, trace, "freewrit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | if (privptr->p_env->write_size < PAGE_SIZE ) { |
| 937 | free_pages((unsigned long)privptr->p_buff_write, |
| 938 | (int)pages_to_order_of_mag(privptr->p_buff_write_num)); |
| 939 | } |
| 940 | else { |
| 941 | p_buf=privptr->p_write_active_first; |
| 942 | while (p_buf!=NULL) { |
| 943 | free_pages((unsigned long)p_buf->p_buffer, |
| 944 | (int)pages_to_order_of_mag( |
| 945 | privptr->p_buff_pages_perwrite )); |
| 946 | p_buf=p_buf->next; |
| 947 | } |
| 948 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 949 | CLAW_DBF_TEXT(4, trace, "clearptr"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | privptr->buffs_alloc = 0; |
| 951 | privptr->p_buff_ccw=NULL; |
| 952 | privptr->p_buff_read=NULL; |
| 953 | privptr->p_buff_write=NULL; |
| 954 | privptr->system_validate_comp=0; |
| 955 | privptr->release_pend=0; |
| 956 | /* Remove any writes that were pending and reset all reads */ |
| 957 | p_this_ccw=privptr->p_read_active_first; |
| 958 | while (p_this_ccw!=NULL) { |
| 959 | p_this_ccw->header.length=0xffff; |
| 960 | p_this_ccw->header.opcode=0xff; |
| 961 | p_this_ccw->header.flag=0x00; |
| 962 | p_this_ccw=p_this_ccw->next; |
| 963 | } |
| 964 | |
| 965 | while (privptr->p_write_active_first!=NULL) { |
| 966 | p_this_ccw=privptr->p_write_active_first; |
| 967 | p_this_ccw->header.flag=CLAW_PENDING; |
| 968 | privptr->p_write_active_first=p_this_ccw->next; |
| 969 | p_this_ccw->next=privptr->p_write_free_chain; |
| 970 | privptr->p_write_free_chain=p_this_ccw; |
| 971 | ++privptr->write_free_count; |
| 972 | } |
| 973 | privptr->p_write_active_last=NULL; |
| 974 | privptr->mtc_logical_link = -1; |
| 975 | privptr->mtc_skipping = 1; |
| 976 | privptr->mtc_offset=0; |
| 977 | |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 978 | if (((privptr->channel[READ_CHANNEL].last_dstat | |
| 979 | privptr->channel[WRITE_CHANNEL].last_dstat) & |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END)) != 0x00) { |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 981 | dev_warn(&privptr->channel[READ_CHANNEL].cdev->dev, |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 982 | "Deactivating %s completed with incorrect" |
| 983 | " subchannel status " |
| 984 | "(read %02x, write %02x)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | dev->name, |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 986 | privptr->channel[READ_CHANNEL].last_dstat, |
| 987 | privptr->channel[WRITE_CHANNEL].last_dstat); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 988 | CLAW_DBF_TEXT(2, trace, "badclose"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 990 | CLAW_DBF_TEXT(4, trace, "rlsexit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | return 0; |
| 992 | } /* end of claw_release */ |
| 993 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | /*-------------------------------------------------------------------* |
| 995 | * claw_write_retry * |
| 996 | * * |
| 997 | *--------------------------------------------------------------------*/ |
| 998 | |
| 999 | static void |
| 1000 | claw_write_retry ( struct chbk *p_ch ) |
| 1001 | { |
| 1002 | |
| 1003 | struct net_device *dev=p_ch->ndev; |
| 1004 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1005 | CLAW_DBF_TEXT(4, trace, "w_retry"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | if (p_ch->claw_state == CLAW_STOP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | return; |
| 1008 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | claw_strt_out_IO( dev ); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1010 | CLAW_DBF_TEXT(4, trace, "rtry_xit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | return; |
| 1012 | } /* end of claw_write_retry */ |
| 1013 | |
| 1014 | |
| 1015 | /*-------------------------------------------------------------------* |
| 1016 | * claw_write_next * |
| 1017 | * * |
| 1018 | *--------------------------------------------------------------------*/ |
| 1019 | |
| 1020 | static void |
| 1021 | claw_write_next ( struct chbk * p_ch ) |
| 1022 | { |
| 1023 | |
| 1024 | struct net_device *dev; |
| 1025 | struct claw_privbk *privptr=NULL; |
| 1026 | struct sk_buff *pk_skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1028 | CLAW_DBF_TEXT(4, trace, "claw_wrt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | if (p_ch->claw_state == CLAW_STOP) |
| 1030 | return; |
| 1031 | dev = (struct net_device *) p_ch->ndev; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1032 | privptr = (struct claw_privbk *) dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | claw_free_wrt_buf( dev ); |
| 1034 | if ((privptr->write_free_count > 0) && |
David S. Miller | b03efcf | 2005-07-08 14:57:23 -0700 | [diff] [blame] | 1035 | !skb_queue_empty(&p_ch->collect_queue)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | pk_skb = claw_pack_skb(privptr); |
| 1037 | while (pk_skb != NULL) { |
Heiko Carstens | 38ed18f | 2011-05-12 18:45:04 +0000 | [diff] [blame] | 1038 | claw_hw_tx(pk_skb, dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | if (privptr->write_free_count > 0) { |
| 1040 | pk_skb = claw_pack_skb(privptr); |
| 1041 | } else |
| 1042 | pk_skb = NULL; |
| 1043 | } |
| 1044 | } |
| 1045 | if (privptr->p_write_active_first!=NULL) { |
| 1046 | claw_strt_out_IO(dev); |
| 1047 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | return; |
| 1049 | } /* end of claw_write_next */ |
| 1050 | |
| 1051 | /*-------------------------------------------------------------------* |
| 1052 | * * |
| 1053 | * claw_timer * |
| 1054 | *--------------------------------------------------------------------*/ |
| 1055 | |
| 1056 | static void |
| 1057 | claw_timer ( struct chbk * p_ch ) |
| 1058 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1059 | CLAW_DBF_TEXT(4, trace, "timer"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | p_ch->flag |= CLAW_TIMER; |
| 1061 | wake_up(&p_ch->wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | return; |
| 1063 | } /* end of claw_timer */ |
| 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | /* |
| 1066 | * |
| 1067 | * functions |
| 1068 | */ |
| 1069 | |
| 1070 | |
| 1071 | /*-------------------------------------------------------------------* |
| 1072 | * * |
| 1073 | * pages_to_order_of_mag * |
| 1074 | * * |
| 1075 | * takes a number of pages from 1 to 512 and returns the * |
| 1076 | * log(num_pages)/log(2) get_free_pages() needs a base 2 order * |
| 1077 | * of magnitude get_free_pages() has an upper order of 9 * |
| 1078 | *--------------------------------------------------------------------*/ |
| 1079 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1080 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | pages_to_order_of_mag(int num_of_pages) |
| 1082 | { |
| 1083 | int order_of_mag=1; /* assume 2 pages */ |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1084 | int nump; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1085 | |
| 1086 | CLAW_DBF_TEXT_(5, trace, "pages%d", num_of_pages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | if (num_of_pages == 1) {return 0; } /* magnitude of 0 = 1 page */ |
| 1088 | /* 512 pages = 2Meg on 4k page systems */ |
| 1089 | if (num_of_pages >= 512) {return 9; } |
| 1090 | /* we have two or more pages order is at least 1 */ |
| 1091 | for (nump=2 ;nump <= 512;nump*=2) { |
| 1092 | if (num_of_pages <= nump) |
| 1093 | break; |
| 1094 | order_of_mag +=1; |
| 1095 | } |
| 1096 | if (order_of_mag > 9) { order_of_mag = 9; } /* I know it's paranoid */ |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1097 | CLAW_DBF_TEXT_(5, trace, "mag%d", order_of_mag); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | return order_of_mag; |
| 1099 | } |
| 1100 | |
| 1101 | /*-------------------------------------------------------------------* |
| 1102 | * * |
| 1103 | * add_claw_reads * |
| 1104 | * * |
| 1105 | *--------------------------------------------------------------------*/ |
| 1106 | static int |
| 1107 | add_claw_reads(struct net_device *dev, struct ccwbk* p_first, |
| 1108 | struct ccwbk* p_last) |
| 1109 | { |
| 1110 | struct claw_privbk *privptr; |
| 1111 | struct ccw1 temp_ccw; |
| 1112 | struct endccw * p_end; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1113 | CLAW_DBF_TEXT(4, trace, "addreads"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1114 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | p_end = privptr->p_end_ccw; |
| 1116 | |
| 1117 | /* first CCW and last CCW contains a new set of read channel programs |
| 1118 | * to apend the running channel programs |
| 1119 | */ |
| 1120 | if ( p_first==NULL) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1121 | CLAW_DBF_TEXT(4, trace, "addexit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | return 0; |
| 1123 | } |
| 1124 | |
| 1125 | /* set up ending CCW sequence for this segment */ |
| 1126 | if (p_end->read1) { |
| 1127 | p_end->read1=0x00; /* second ending CCW is now active */ |
| 1128 | /* reset ending CCWs and setup TIC CCWs */ |
| 1129 | p_end->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1130 | p_end->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1131 | p_last->r_TIC_1.cda =(__u32)__pa(&p_end->read2_nop1); |
| 1132 | p_last->r_TIC_2.cda =(__u32)__pa(&p_end->read2_nop1); |
| 1133 | p_end->read2_nop2.cda=0; |
| 1134 | p_end->read2_nop2.count=1; |
| 1135 | } |
| 1136 | else { |
| 1137 | p_end->read1=0x01; /* first ending CCW is now active */ |
| 1138 | /* reset ending CCWs and setup TIC CCWs */ |
| 1139 | p_end->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1140 | p_end->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1141 | p_last->r_TIC_1.cda = (__u32)__pa(&p_end->read1_nop1); |
| 1142 | p_last->r_TIC_2.cda = (__u32)__pa(&p_end->read1_nop1); |
| 1143 | p_end->read1_nop2.cda=0; |
| 1144 | p_end->read1_nop2.count=1; |
| 1145 | } |
| 1146 | |
| 1147 | if ( privptr-> p_read_active_first ==NULL ) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1148 | privptr->p_read_active_first = p_first; /* set new first */ |
| 1149 | privptr->p_read_active_last = p_last; /* set new last */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | else { |
| 1152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | /* set up TIC ccw */ |
| 1154 | temp_ccw.cda= (__u32)__pa(&p_first->read); |
| 1155 | temp_ccw.count=0; |
| 1156 | temp_ccw.flags=0; |
| 1157 | temp_ccw.cmd_code = CCW_CLAW_CMD_TIC; |
| 1158 | |
| 1159 | |
| 1160 | if (p_end->read1) { |
| 1161 | |
| 1162 | /* first set of CCW's is chained to the new read */ |
| 1163 | /* chain, so the second set is chained to the active chain. */ |
| 1164 | /* Therefore modify the second set to point to the new */ |
| 1165 | /* read chain set up TIC CCWs */ |
| 1166 | /* make sure we update the CCW so channel doesn't fetch it */ |
| 1167 | /* when it's only half done */ |
| 1168 | memcpy( &p_end->read2_nop2, &temp_ccw , |
| 1169 | sizeof(struct ccw1)); |
| 1170 | privptr->p_read_active_last->r_TIC_1.cda= |
| 1171 | (__u32)__pa(&p_first->read); |
| 1172 | privptr->p_read_active_last->r_TIC_2.cda= |
| 1173 | (__u32)__pa(&p_first->read); |
| 1174 | } |
| 1175 | else { |
| 1176 | /* make sure we update the CCW so channel doesn't */ |
| 1177 | /* fetch it when it is only half done */ |
| 1178 | memcpy( &p_end->read1_nop2, &temp_ccw , |
| 1179 | sizeof(struct ccw1)); |
| 1180 | privptr->p_read_active_last->r_TIC_1.cda= |
| 1181 | (__u32)__pa(&p_first->read); |
| 1182 | privptr->p_read_active_last->r_TIC_2.cda= |
| 1183 | (__u32)__pa(&p_first->read); |
| 1184 | } |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1185 | /* chain in new set of blocks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | privptr->p_read_active_last->next = p_first; |
| 1187 | privptr->p_read_active_last=p_last; |
| 1188 | } /* end of if ( privptr-> p_read_active_first ==NULL) */ |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1189 | CLAW_DBF_TEXT(4, trace, "addexit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | return 0; |
| 1191 | } /* end of add_claw_reads */ |
| 1192 | |
| 1193 | /*-------------------------------------------------------------------* |
| 1194 | * ccw_check_return_code * |
| 1195 | * * |
| 1196 | *-------------------------------------------------------------------*/ |
| 1197 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1198 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | ccw_check_return_code(struct ccw_device *cdev, int return_code) |
| 1200 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1201 | CLAW_DBF_TEXT(4, trace, "ccwret"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | if (return_code != 0) { |
| 1203 | switch (return_code) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1204 | case -EBUSY: /* BUSY is a transient state no action needed */ |
| 1205 | break; |
| 1206 | case -ENODEV: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1207 | dev_err(&cdev->dev, "The remote channel adapter is not" |
| 1208 | " available\n"); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1209 | break; |
| 1210 | case -EINVAL: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1211 | dev_err(&cdev->dev, |
| 1212 | "The status of the remote channel adapter" |
| 1213 | " is not valid\n"); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1214 | break; |
| 1215 | default: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1216 | dev_err(&cdev->dev, "The common device layer" |
| 1217 | " returned error code %d\n", |
| 1218 | return_code); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | CLAW_DBF_TEXT(4, trace, "ccwret"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } /* end of ccw_check_return_code */ |
| 1223 | |
| 1224 | /*-------------------------------------------------------------------* |
| 1225 | * ccw_check_unit_check * |
| 1226 | *--------------------------------------------------------------------*/ |
| 1227 | |
Heiko Carstens | 4d284ca | 2007-02-05 21:18:53 +0100 | [diff] [blame] | 1228 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | ccw_check_unit_check(struct chbk * p_ch, unsigned char sense ) |
| 1230 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1231 | struct net_device *ndev = p_ch->ndev; |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1232 | struct device *dev = &p_ch->cdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1234 | CLAW_DBF_TEXT(4, trace, "unitchek"); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1235 | dev_warn(dev, "The communication peer of %s disconnected\n", |
| 1236 | ndev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1238 | if (sense & 0x40) { |
| 1239 | if (sense & 0x01) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1240 | dev_warn(dev, "The remote channel adapter for" |
| 1241 | " %s has been reset\n", |
| 1242 | ndev->name); |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1243 | } |
| 1244 | } else if (sense & 0x20) { |
| 1245 | if (sense & 0x04) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1246 | dev_warn(dev, "A data streaming timeout occurred" |
| 1247 | " for %s\n", |
| 1248 | ndev->name); |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1249 | } else if (sense & 0x10) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1250 | dev_warn(dev, "The remote channel adapter for %s" |
| 1251 | " is faulty\n", |
| 1252 | ndev->name); |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1253 | } else { |
| 1254 | dev_warn(dev, "A data transfer parity error occurred" |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1255 | " for %s\n", |
| 1256 | ndev->name); |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1257 | } |
| 1258 | } else if (sense & 0x10) { |
| 1259 | dev_warn(dev, "A read data parity error occurred" |
| 1260 | " for %s\n", |
| 1261 | ndev->name); |
| 1262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | } /* end of ccw_check_unit_check */ |
| 1265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | /*-------------------------------------------------------------------* |
| 1267 | * find_link * |
| 1268 | *--------------------------------------------------------------------*/ |
| 1269 | static int |
| 1270 | find_link(struct net_device *dev, char *host_name, char *ws_name ) |
| 1271 | { |
| 1272 | struct claw_privbk *privptr; |
| 1273 | struct claw_env *p_env; |
| 1274 | int rc=0; |
| 1275 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1276 | CLAW_DBF_TEXT(2, setup, "findlink"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1277 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | p_env=privptr->p_env; |
| 1279 | switch (p_env->packing) |
| 1280 | { |
| 1281 | case PACKING_ASK: |
| 1282 | if ((memcmp(WS_APPL_NAME_PACKED, host_name, 8)!=0) || |
| 1283 | (memcmp(WS_APPL_NAME_PACKED, ws_name, 8)!=0 )) |
| 1284 | rc = EINVAL; |
| 1285 | break; |
| 1286 | case DO_PACKED: |
| 1287 | case PACK_SEND: |
| 1288 | if ((memcmp(WS_APPL_NAME_IP_NAME, host_name, 8)!=0) || |
| 1289 | (memcmp(WS_APPL_NAME_IP_NAME, ws_name, 8)!=0 )) |
| 1290 | rc = EINVAL; |
| 1291 | break; |
| 1292 | default: |
| 1293 | if ((memcmp(HOST_APPL_NAME, host_name, 8)!=0) || |
| 1294 | (memcmp(p_env->api_type , ws_name, 8)!=0)) |
| 1295 | rc = EINVAL; |
| 1296 | break; |
| 1297 | } |
| 1298 | |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1299 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | } /* end of find_link */ |
| 1301 | |
| 1302 | /*-------------------------------------------------------------------* |
| 1303 | * claw_hw_tx * |
| 1304 | * * |
| 1305 | * * |
| 1306 | *-------------------------------------------------------------------*/ |
| 1307 | |
| 1308 | static int |
| 1309 | claw_hw_tx(struct sk_buff *skb, struct net_device *dev, long linkid) |
| 1310 | { |
| 1311 | int rc=0; |
| 1312 | struct claw_privbk *privptr; |
| 1313 | struct ccwbk *p_this_ccw; |
| 1314 | struct ccwbk *p_first_ccw; |
| 1315 | struct ccwbk *p_last_ccw; |
| 1316 | __u32 numBuffers; |
| 1317 | signed long len_of_data; |
| 1318 | unsigned long bytesInThisBuffer; |
| 1319 | unsigned char *pDataAddress; |
| 1320 | struct endccw *pEnd; |
| 1321 | struct ccw1 tempCCW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | struct claw_env *p_env; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | struct clawph *pk_head; |
| 1324 | struct chbk *ch; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1325 | |
| 1326 | CLAW_DBF_TEXT(4, trace, "hw_tx"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1327 | privptr = (struct claw_privbk *)(dev->ml_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | p_env =privptr->p_env; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | claw_free_wrt_buf(dev); /* Clean up free chain if posible */ |
| 1330 | /* scan the write queue to free any completed write packets */ |
| 1331 | p_first_ccw=NULL; |
| 1332 | p_last_ccw=NULL; |
| 1333 | if ((p_env->packing >= PACK_SEND) && |
| 1334 | (skb->cb[1] != 'P')) { |
| 1335 | skb_push(skb,sizeof(struct clawph)); |
| 1336 | pk_head=(struct clawph *)skb->data; |
| 1337 | pk_head->len=skb->len-sizeof(struct clawph); |
| 1338 | if (pk_head->len%4) { |
| 1339 | pk_head->len+= 4-(pk_head->len%4); |
| 1340 | skb_pad(skb,4-(pk_head->len%4)); |
| 1341 | skb_put(skb,4-(pk_head->len%4)); |
| 1342 | } |
| 1343 | if (p_env->packing == DO_PACKED) |
| 1344 | pk_head->link_num = linkid; |
| 1345 | else |
| 1346 | pk_head->link_num = 0; |
| 1347 | pk_head->flag = 0x00; |
| 1348 | skb_pad(skb,4); |
| 1349 | skb->cb[1] = 'P'; |
| 1350 | } |
| 1351 | if (linkid == 0) { |
| 1352 | if (claw_check_busy(dev)) { |
| 1353 | if (privptr->write_free_count!=0) { |
| 1354 | claw_clear_busy(dev); |
| 1355 | } |
| 1356 | else { |
| 1357 | claw_strt_out_IO(dev ); |
| 1358 | claw_free_wrt_buf( dev ); |
| 1359 | if (privptr->write_free_count==0) { |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1360 | ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | atomic_inc(&skb->users); |
| 1362 | skb_queue_tail(&ch->collect_queue, skb); |
| 1363 | goto Done; |
| 1364 | } |
| 1365 | else { |
| 1366 | claw_clear_busy(dev); |
| 1367 | } |
| 1368 | } |
| 1369 | } |
| 1370 | /* tx lock */ |
| 1371 | if (claw_test_and_setbit_busy(TB_TX,dev)) { /* set to busy */ |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1372 | ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | atomic_inc(&skb->users); |
| 1374 | skb_queue_tail(&ch->collect_queue, skb); |
| 1375 | claw_strt_out_IO(dev ); |
| 1376 | rc=-EBUSY; |
| 1377 | goto Done2; |
| 1378 | } |
| 1379 | } |
| 1380 | /* See how many write buffers are required to hold this data */ |
Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1381 | numBuffers = DIV_ROUND_UP(skb->len, privptr->p_env->write_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | |
| 1383 | /* If that number of buffers isn't available, give up for now */ |
| 1384 | if (privptr->write_free_count < numBuffers || |
| 1385 | privptr->p_write_free_chain == NULL ) { |
| 1386 | |
| 1387 | claw_setbit_busy(TB_NOBUFFER,dev); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1388 | ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1389 | atomic_inc(&skb->users); |
| 1390 | skb_queue_tail(&ch->collect_queue, skb); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1391 | CLAW_DBF_TEXT(2, trace, "clawbusy"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | goto Done2; |
| 1393 | } |
| 1394 | pDataAddress=skb->data; |
| 1395 | len_of_data=skb->len; |
| 1396 | |
| 1397 | while (len_of_data > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | p_this_ccw=privptr->p_write_free_chain; /* get a block */ |
| 1399 | if (p_this_ccw == NULL) { /* lost the race */ |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 1400 | ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | atomic_inc(&skb->users); |
| 1402 | skb_queue_tail(&ch->collect_queue, skb); |
| 1403 | goto Done2; |
| 1404 | } |
| 1405 | privptr->p_write_free_chain=p_this_ccw->next; |
| 1406 | p_this_ccw->next=NULL; |
| 1407 | --privptr->write_free_count; /* -1 */ |
Andrew H. Richter | b9d2fce | 2009-03-24 03:27:51 +0000 | [diff] [blame] | 1408 | if (len_of_data >= privptr->p_env->write_size) |
| 1409 | bytesInThisBuffer = privptr->p_env->write_size; |
| 1410 | else |
| 1411 | bytesInThisBuffer = len_of_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | memcpy( p_this_ccw->p_buffer,pDataAddress, bytesInThisBuffer); |
| 1413 | len_of_data-=bytesInThisBuffer; |
| 1414 | pDataAddress+=(unsigned long)bytesInThisBuffer; |
| 1415 | /* setup write CCW */ |
| 1416 | p_this_ccw->write.cmd_code = (linkid * 8) +1; |
| 1417 | if (len_of_data>0) { |
| 1418 | p_this_ccw->write.cmd_code+=MORE_to_COME_FLAG; |
| 1419 | } |
| 1420 | p_this_ccw->write.count=bytesInThisBuffer; |
| 1421 | /* now add to end of this chain */ |
| 1422 | if (p_first_ccw==NULL) { |
| 1423 | p_first_ccw=p_this_ccw; |
| 1424 | } |
| 1425 | if (p_last_ccw!=NULL) { |
| 1426 | p_last_ccw->next=p_this_ccw; |
| 1427 | /* set up TIC ccws */ |
| 1428 | p_last_ccw->w_TIC_1.cda= |
| 1429 | (__u32)__pa(&p_this_ccw->write); |
| 1430 | } |
| 1431 | p_last_ccw=p_this_ccw; /* save new last block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | /* FirstCCW and LastCCW now contain a new set of write channel |
| 1435 | * programs to append to the running channel program |
| 1436 | */ |
| 1437 | |
| 1438 | if (p_first_ccw!=NULL) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1439 | /* setup ending ccw sequence for this segment */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | pEnd=privptr->p_end_ccw; |
| 1441 | if (pEnd->write1) { |
| 1442 | pEnd->write1=0x00; /* second end ccw is now active */ |
| 1443 | /* set up Tic CCWs */ |
| 1444 | p_last_ccw->w_TIC_1.cda= |
| 1445 | (__u32)__pa(&pEnd->write2_nop1); |
| 1446 | pEnd->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1447 | pEnd->write2_nop2.flags = |
| 1448 | CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1449 | pEnd->write2_nop2.cda=0; |
| 1450 | pEnd->write2_nop2.count=1; |
| 1451 | } |
| 1452 | else { /* end of if (pEnd->write1)*/ |
| 1453 | pEnd->write1=0x01; /* first end ccw is now active */ |
| 1454 | /* set up Tic CCWs */ |
| 1455 | p_last_ccw->w_TIC_1.cda= |
| 1456 | (__u32)__pa(&pEnd->write1_nop1); |
| 1457 | pEnd->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1458 | pEnd->write1_nop2.flags = |
| 1459 | CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1460 | pEnd->write1_nop2.cda=0; |
| 1461 | pEnd->write1_nop2.count=1; |
| 1462 | } /* end if if (pEnd->write1) */ |
| 1463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | if (privptr->p_write_active_first==NULL ) { |
| 1465 | privptr->p_write_active_first=p_first_ccw; |
| 1466 | privptr->p_write_active_last=p_last_ccw; |
| 1467 | } |
| 1468 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | /* set up Tic CCWs */ |
| 1470 | |
| 1471 | tempCCW.cda=(__u32)__pa(&p_first_ccw->write); |
| 1472 | tempCCW.count=0; |
| 1473 | tempCCW.flags=0; |
| 1474 | tempCCW.cmd_code=CCW_CLAW_CMD_TIC; |
| 1475 | |
| 1476 | if (pEnd->write1) { |
| 1477 | |
| 1478 | /* |
| 1479 | * first set of ending CCW's is chained to the new write |
| 1480 | * chain, so the second set is chained to the active chain |
| 1481 | * Therefore modify the second set to point the new write chain. |
| 1482 | * make sure we update the CCW atomically |
| 1483 | * so channel does not fetch it when it's only half done |
| 1484 | */ |
| 1485 | memcpy( &pEnd->write2_nop2, &tempCCW , |
| 1486 | sizeof(struct ccw1)); |
| 1487 | privptr->p_write_active_last->w_TIC_1.cda= |
| 1488 | (__u32)__pa(&p_first_ccw->write); |
| 1489 | } |
| 1490 | else { |
| 1491 | |
| 1492 | /*make sure we update the CCW atomically |
| 1493 | *so channel does not fetch it when it's only half done |
| 1494 | */ |
| 1495 | memcpy(&pEnd->write1_nop2, &tempCCW , |
| 1496 | sizeof(struct ccw1)); |
| 1497 | privptr->p_write_active_last->w_TIC_1.cda= |
| 1498 | (__u32)__pa(&p_first_ccw->write); |
| 1499 | |
| 1500 | } /* end if if (pEnd->write1) */ |
| 1501 | |
| 1502 | privptr->p_write_active_last->next=p_first_ccw; |
| 1503 | privptr->p_write_active_last=p_last_ccw; |
| 1504 | } |
| 1505 | |
| 1506 | } /* endif (p_first_ccw!=NULL) */ |
Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 1507 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | claw_strt_out_IO(dev ); |
| 1509 | /* if write free count is zero , set NOBUFFER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | if (privptr->write_free_count==0) { |
| 1511 | claw_setbit_busy(TB_NOBUFFER,dev); |
| 1512 | } |
| 1513 | Done2: |
| 1514 | claw_clearbit_busy(TB_TX,dev); |
| 1515 | Done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | return(rc); |
| 1517 | } /* end of claw_hw_tx */ |
| 1518 | |
| 1519 | /*-------------------------------------------------------------------* |
| 1520 | * * |
| 1521 | * init_ccw_bk * |
| 1522 | * * |
| 1523 | *--------------------------------------------------------------------*/ |
| 1524 | |
| 1525 | static int |
| 1526 | init_ccw_bk(struct net_device *dev) |
| 1527 | { |
| 1528 | |
| 1529 | __u32 ccw_blocks_required; |
| 1530 | __u32 ccw_blocks_perpage; |
| 1531 | __u32 ccw_pages_required; |
| 1532 | __u32 claw_reads_perpage=1; |
| 1533 | __u32 claw_read_pages; |
| 1534 | __u32 claw_writes_perpage=1; |
| 1535 | __u32 claw_write_pages; |
| 1536 | void *p_buff=NULL; |
| 1537 | struct ccwbk*p_free_chain; |
| 1538 | struct ccwbk*p_buf; |
| 1539 | struct ccwbk*p_last_CCWB; |
| 1540 | struct ccwbk*p_first_CCWB; |
| 1541 | struct endccw *p_endccw=NULL; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 1542 | addr_t real_address; |
| 1543 | struct claw_privbk *privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | struct clawh *pClawH=NULL; |
| 1545 | addr_t real_TIC_address; |
| 1546 | int i,j; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 1547 | CLAW_DBF_TEXT(4, trace, "init_ccw"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | |
| 1549 | /* initialize statistics field */ |
| 1550 | privptr->active_link_ID=0; |
| 1551 | /* initialize ccwbk pointers */ |
| 1552 | privptr->p_write_free_chain=NULL; /* pointer to free ccw chain*/ |
| 1553 | privptr->p_write_active_first=NULL; /* pointer to the first write ccw*/ |
| 1554 | privptr->p_write_active_last=NULL; /* pointer to the last write ccw*/ |
| 1555 | privptr->p_read_active_first=NULL; /* pointer to the first read ccw*/ |
| 1556 | privptr->p_read_active_last=NULL; /* pointer to the last read ccw */ |
| 1557 | privptr->p_end_ccw=NULL; /* pointer to ending ccw */ |
| 1558 | privptr->p_claw_signal_blk=NULL; /* pointer to signal block */ |
| 1559 | privptr->buffs_alloc = 0; |
| 1560 | memset(&privptr->end_ccw, 0x00, sizeof(struct endccw)); |
| 1561 | memset(&privptr->ctl_bk, 0x00, sizeof(struct clawctl)); |
| 1562 | /* initialize free write ccwbk counter */ |
| 1563 | privptr->write_free_count=0; /* number of free bufs on write chain */ |
| 1564 | p_last_CCWB = NULL; |
| 1565 | p_first_CCWB= NULL; |
| 1566 | /* |
| 1567 | * We need 1 CCW block for each read buffer, 1 for each |
| 1568 | * write buffer, plus 1 for ClawSignalBlock |
| 1569 | */ |
| 1570 | ccw_blocks_required = |
| 1571 | privptr->p_env->read_buffers+privptr->p_env->write_buffers+1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | /* |
| 1573 | * compute number of CCW blocks that will fit in a page |
| 1574 | */ |
| 1575 | ccw_blocks_perpage= PAGE_SIZE / CCWBK_SIZE; |
| 1576 | ccw_pages_required= |
Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1577 | DIV_ROUND_UP(ccw_blocks_required, ccw_blocks_perpage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | /* |
| 1580 | * read and write sizes are set by 2 constants in claw.h |
| 1581 | * 4k and 32k. Unpacked values other than 4k are not going to |
| 1582 | * provide good performance. With packing buffers support 32k |
| 1583 | * buffers are used. |
| 1584 | */ |
Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1585 | if (privptr->p_env->read_size < PAGE_SIZE) { |
| 1586 | claw_reads_perpage = PAGE_SIZE / privptr->p_env->read_size; |
| 1587 | claw_read_pages = DIV_ROUND_UP(privptr->p_env->read_buffers, |
| 1588 | claw_reads_perpage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | } |
| 1590 | else { /* > or equal */ |
Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1591 | privptr->p_buff_pages_perread = |
| 1592 | DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); |
| 1593 | claw_read_pages = privptr->p_env->read_buffers * |
| 1594 | privptr->p_buff_pages_perread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | } |
| 1596 | if (privptr->p_env->write_size < PAGE_SIZE) { |
Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1597 | claw_writes_perpage = |
| 1598 | PAGE_SIZE / privptr->p_env->write_size; |
| 1599 | claw_write_pages = DIV_ROUND_UP(privptr->p_env->write_buffers, |
| 1600 | claw_writes_perpage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | |
| 1602 | } |
| 1603 | else { /* > or equal */ |
Julia Lawall | f5154fb | 2008-02-18 14:41:55 +0100 | [diff] [blame] | 1604 | privptr->p_buff_pages_perwrite = |
| 1605 | DIV_ROUND_UP(privptr->p_env->read_size, PAGE_SIZE); |
| 1606 | claw_write_pages = privptr->p_env->write_buffers * |
| 1607 | privptr->p_buff_pages_perwrite; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | /* |
| 1610 | * allocate ccw_pages_required |
| 1611 | */ |
| 1612 | if (privptr->p_buff_ccw==NULL) { |
| 1613 | privptr->p_buff_ccw= |
| 1614 | (void *)__get_free_pages(__GFP_DMA, |
| 1615 | (int)pages_to_order_of_mag(ccw_pages_required )); |
| 1616 | if (privptr->p_buff_ccw==NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | return -ENOMEM; |
| 1618 | } |
| 1619 | privptr->p_buff_ccw_num=ccw_pages_required; |
| 1620 | } |
| 1621 | memset(privptr->p_buff_ccw, 0x00, |
| 1622 | privptr->p_buff_ccw_num * PAGE_SIZE); |
| 1623 | |
| 1624 | /* |
| 1625 | * obtain ending ccw block address |
| 1626 | * |
| 1627 | */ |
| 1628 | privptr->p_end_ccw = (struct endccw *)&privptr->end_ccw; |
| 1629 | real_address = (__u32)__pa(privptr->p_end_ccw); |
| 1630 | /* Initialize ending CCW block */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | p_endccw=privptr->p_end_ccw; |
| 1632 | p_endccw->real=real_address; |
| 1633 | p_endccw->write1=0x00; |
| 1634 | p_endccw->read1=0x00; |
| 1635 | |
| 1636 | /* write1_nop1 */ |
| 1637 | p_endccw->write1_nop1.cmd_code = CCW_CLAW_CMD_NOP; |
| 1638 | p_endccw->write1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1639 | p_endccw->write1_nop1.count = 1; |
| 1640 | p_endccw->write1_nop1.cda = 0; |
| 1641 | |
| 1642 | /* write1_nop2 */ |
| 1643 | p_endccw->write1_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1644 | p_endccw->write1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1645 | p_endccw->write1_nop2.count = 1; |
| 1646 | p_endccw->write1_nop2.cda = 0; |
| 1647 | |
| 1648 | /* write2_nop1 */ |
| 1649 | p_endccw->write2_nop1.cmd_code = CCW_CLAW_CMD_NOP; |
| 1650 | p_endccw->write2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1651 | p_endccw->write2_nop1.count = 1; |
| 1652 | p_endccw->write2_nop1.cda = 0; |
| 1653 | |
| 1654 | /* write2_nop2 */ |
| 1655 | p_endccw->write2_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1656 | p_endccw->write2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1657 | p_endccw->write2_nop2.count = 1; |
| 1658 | p_endccw->write2_nop2.cda = 0; |
| 1659 | |
| 1660 | /* read1_nop1 */ |
| 1661 | p_endccw->read1_nop1.cmd_code = CCW_CLAW_CMD_NOP; |
| 1662 | p_endccw->read1_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1663 | p_endccw->read1_nop1.count = 1; |
| 1664 | p_endccw->read1_nop1.cda = 0; |
| 1665 | |
| 1666 | /* read1_nop2 */ |
| 1667 | p_endccw->read1_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1668 | p_endccw->read1_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1669 | p_endccw->read1_nop2.count = 1; |
| 1670 | p_endccw->read1_nop2.cda = 0; |
| 1671 | |
| 1672 | /* read2_nop1 */ |
| 1673 | p_endccw->read2_nop1.cmd_code = CCW_CLAW_CMD_NOP; |
| 1674 | p_endccw->read2_nop1.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1675 | p_endccw->read2_nop1.count = 1; |
| 1676 | p_endccw->read2_nop1.cda = 0; |
| 1677 | |
| 1678 | /* read2_nop2 */ |
| 1679 | p_endccw->read2_nop2.cmd_code = CCW_CLAW_CMD_READFF; |
| 1680 | p_endccw->read2_nop2.flags = CCW_FLAG_SLI | CCW_FLAG_SKIP; |
| 1681 | p_endccw->read2_nop2.count = 1; |
| 1682 | p_endccw->read2_nop2.cda = 0; |
| 1683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | /* |
| 1685 | * Build a chain of CCWs |
| 1686 | * |
| 1687 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | p_buff=privptr->p_buff_ccw; |
| 1689 | |
| 1690 | p_free_chain=NULL; |
| 1691 | for (i=0 ; i < ccw_pages_required; i++ ) { |
| 1692 | real_address = (__u32)__pa(p_buff); |
| 1693 | p_buf=p_buff; |
| 1694 | for (j=0 ; j < ccw_blocks_perpage ; j++) { |
| 1695 | p_buf->next = p_free_chain; |
| 1696 | p_free_chain = p_buf; |
| 1697 | p_buf->real=(__u32)__pa(p_buf); |
| 1698 | ++p_buf; |
| 1699 | } |
| 1700 | p_buff+=PAGE_SIZE; |
| 1701 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | /* |
| 1703 | * Initialize ClawSignalBlock |
| 1704 | * |
| 1705 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | if (privptr->p_claw_signal_blk==NULL) { |
| 1707 | privptr->p_claw_signal_blk=p_free_chain; |
| 1708 | p_free_chain=p_free_chain->next; |
| 1709 | pClawH=(struct clawh *)privptr->p_claw_signal_blk; |
| 1710 | pClawH->length=0xffff; |
| 1711 | pClawH->opcode=0xff; |
| 1712 | pClawH->flag=CLAW_BUSY; |
| 1713 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1714 | |
| 1715 | /* |
| 1716 | * allocate write_pages_required and add to free chain |
| 1717 | */ |
| 1718 | if (privptr->p_buff_write==NULL) { |
| 1719 | if (privptr->p_env->write_size < PAGE_SIZE) { |
| 1720 | privptr->p_buff_write= |
| 1721 | (void *)__get_free_pages(__GFP_DMA, |
| 1722 | (int)pages_to_order_of_mag(claw_write_pages )); |
| 1723 | if (privptr->p_buff_write==NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | privptr->p_buff_ccw=NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | return -ENOMEM; |
| 1726 | } |
| 1727 | /* |
| 1728 | * Build CLAW write free chain |
| 1729 | * |
| 1730 | */ |
| 1731 | |
| 1732 | memset(privptr->p_buff_write, 0x00, |
| 1733 | ccw_pages_required * PAGE_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | privptr->p_write_free_chain=NULL; |
| 1735 | |
| 1736 | p_buff=privptr->p_buff_write; |
| 1737 | |
| 1738 | for (i=0 ; i< privptr->p_env->write_buffers ; i++) { |
| 1739 | p_buf = p_free_chain; /* get a CCW */ |
| 1740 | p_free_chain = p_buf->next; |
| 1741 | p_buf->next =privptr->p_write_free_chain; |
| 1742 | privptr->p_write_free_chain = p_buf; |
| 1743 | p_buf-> p_buffer = (struct clawbuf *)p_buff; |
| 1744 | p_buf-> write.cda = (__u32)__pa(p_buff); |
| 1745 | p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1746 | p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; |
| 1747 | p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1748 | p_buf-> w_read_FF.count = 1; |
| 1749 | p_buf-> w_read_FF.cda = |
| 1750 | (__u32)__pa(&p_buf-> header.flag); |
| 1751 | p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; |
| 1752 | p_buf-> w_TIC_1.flags = 0; |
| 1753 | p_buf-> w_TIC_1.count = 0; |
| 1754 | |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1755 | if (((unsigned long)p_buff + |
| 1756 | privptr->p_env->write_size) >= |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | ((unsigned long)(p_buff+2* |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1758 | (privptr->p_env->write_size) - 1) & PAGE_MASK)) { |
| 1759 | p_buff = p_buff+privptr->p_env->write_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | } |
| 1763 | else /* Buffers are => PAGE_SIZE. 1 buff per get_free_pages */ |
| 1764 | { |
| 1765 | privptr->p_write_free_chain=NULL; |
| 1766 | for (i = 0; i< privptr->p_env->write_buffers ; i++) { |
| 1767 | p_buff=(void *)__get_free_pages(__GFP_DMA, |
| 1768 | (int)pages_to_order_of_mag( |
| 1769 | privptr->p_buff_pages_perwrite) ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | if (p_buff==NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | free_pages((unsigned long)privptr->p_buff_ccw, |
| 1772 | (int)pages_to_order_of_mag( |
| 1773 | privptr->p_buff_ccw_num)); |
| 1774 | privptr->p_buff_ccw=NULL; |
| 1775 | p_buf=privptr->p_buff_write; |
| 1776 | while (p_buf!=NULL) { |
| 1777 | free_pages((unsigned long) |
| 1778 | p_buf->p_buffer, |
| 1779 | (int)pages_to_order_of_mag( |
| 1780 | privptr->p_buff_pages_perwrite)); |
| 1781 | p_buf=p_buf->next; |
| 1782 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | return -ENOMEM; |
| 1784 | } /* Error on get_pages */ |
| 1785 | memset(p_buff, 0x00, privptr->p_env->write_size ); |
| 1786 | p_buf = p_free_chain; |
| 1787 | p_free_chain = p_buf->next; |
| 1788 | p_buf->next = privptr->p_write_free_chain; |
| 1789 | privptr->p_write_free_chain = p_buf; |
| 1790 | privptr->p_buff_write = p_buf; |
| 1791 | p_buf->p_buffer=(struct clawbuf *)p_buff; |
| 1792 | p_buf-> write.cda = (__u32)__pa(p_buff); |
| 1793 | p_buf-> write.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1794 | p_buf-> w_read_FF.cmd_code = CCW_CLAW_CMD_READFF; |
| 1795 | p_buf-> w_read_FF.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1796 | p_buf-> w_read_FF.count = 1; |
| 1797 | p_buf-> w_read_FF.cda = |
| 1798 | (__u32)__pa(&p_buf-> header.flag); |
| 1799 | p_buf-> w_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; |
| 1800 | p_buf-> w_TIC_1.flags = 0; |
| 1801 | p_buf-> w_TIC_1.count = 0; |
| 1802 | } /* for all write_buffers */ |
| 1803 | |
| 1804 | } /* else buffers are PAGE_SIZE or bigger */ |
| 1805 | |
| 1806 | } |
| 1807 | privptr->p_buff_write_num=claw_write_pages; |
| 1808 | privptr->write_free_count=privptr->p_env->write_buffers; |
| 1809 | |
| 1810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | /* |
| 1812 | * allocate read_pages_required and chain to free chain |
| 1813 | */ |
| 1814 | if (privptr->p_buff_read==NULL) { |
| 1815 | if (privptr->p_env->read_size < PAGE_SIZE) { |
| 1816 | privptr->p_buff_read= |
| 1817 | (void *)__get_free_pages(__GFP_DMA, |
| 1818 | (int)pages_to_order_of_mag(claw_read_pages) ); |
| 1819 | if (privptr->p_buff_read==NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | free_pages((unsigned long)privptr->p_buff_ccw, |
| 1821 | (int)pages_to_order_of_mag( |
| 1822 | privptr->p_buff_ccw_num)); |
| 1823 | /* free the write pages size is < page size */ |
| 1824 | free_pages((unsigned long)privptr->p_buff_write, |
| 1825 | (int)pages_to_order_of_mag( |
| 1826 | privptr->p_buff_write_num)); |
| 1827 | privptr->p_buff_ccw=NULL; |
| 1828 | privptr->p_buff_write=NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | return -ENOMEM; |
| 1830 | } |
| 1831 | memset(privptr->p_buff_read, 0x00, claw_read_pages * PAGE_SIZE); |
| 1832 | privptr->p_buff_read_num=claw_read_pages; |
| 1833 | /* |
| 1834 | * Build CLAW read free chain |
| 1835 | * |
| 1836 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | p_buff=privptr->p_buff_read; |
| 1838 | for (i=0 ; i< privptr->p_env->read_buffers ; i++) { |
| 1839 | p_buf = p_free_chain; |
| 1840 | p_free_chain = p_buf->next; |
| 1841 | |
| 1842 | if (p_last_CCWB==NULL) { |
| 1843 | p_buf->next=NULL; |
| 1844 | real_TIC_address=0; |
| 1845 | p_last_CCWB=p_buf; |
| 1846 | } |
| 1847 | else { |
| 1848 | p_buf->next=p_first_CCWB; |
| 1849 | real_TIC_address= |
| 1850 | (__u32)__pa(&p_first_CCWB -> read ); |
| 1851 | } |
| 1852 | |
| 1853 | p_first_CCWB=p_buf; |
| 1854 | |
| 1855 | p_buf->p_buffer=(struct clawbuf *)p_buff; |
| 1856 | /* initialize read command */ |
| 1857 | p_buf-> read.cmd_code = CCW_CLAW_CMD_READ; |
| 1858 | p_buf-> read.cda = (__u32)__pa(p_buff); |
| 1859 | p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1860 | p_buf-> read.count = privptr->p_env->read_size; |
| 1861 | |
| 1862 | /* initialize read_h command */ |
| 1863 | p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER; |
| 1864 | p_buf-> read_h.cda = |
| 1865 | (__u32)__pa(&(p_buf->header)); |
| 1866 | p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1867 | p_buf-> read_h.count = sizeof(struct clawh); |
| 1868 | |
| 1869 | /* initialize Signal command */ |
| 1870 | p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD; |
| 1871 | p_buf-> signal.cda = |
| 1872 | (__u32)__pa(&(pClawH->flag)); |
| 1873 | p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1874 | p_buf-> signal.count = 1; |
| 1875 | |
| 1876 | /* initialize r_TIC_1 command */ |
| 1877 | p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; |
| 1878 | p_buf-> r_TIC_1.cda = (__u32)real_TIC_address; |
| 1879 | p_buf-> r_TIC_1.flags = 0; |
| 1880 | p_buf-> r_TIC_1.count = 0; |
| 1881 | |
| 1882 | /* initialize r_read_FF command */ |
| 1883 | p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF; |
| 1884 | p_buf-> r_read_FF.cda = |
| 1885 | (__u32)__pa(&(pClawH->flag)); |
| 1886 | p_buf-> r_read_FF.flags = |
| 1887 | CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI; |
| 1888 | p_buf-> r_read_FF.count = 1; |
| 1889 | |
| 1890 | /* initialize r_TIC_2 */ |
| 1891 | memcpy(&p_buf->r_TIC_2, |
| 1892 | &p_buf->r_TIC_1, sizeof(struct ccw1)); |
| 1893 | |
| 1894 | /* initialize Header */ |
| 1895 | p_buf->header.length=0xffff; |
| 1896 | p_buf->header.opcode=0xff; |
| 1897 | p_buf->header.flag=CLAW_PENDING; |
| 1898 | |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1899 | if (((unsigned long)p_buff+privptr->p_env->read_size) >= |
| 1900 | ((unsigned long)(p_buff+2*(privptr->p_env->read_size) |
| 1901 | -1) |
| 1902 | & PAGE_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | p_buff= p_buff+privptr->p_env->read_size; |
| 1904 | } |
| 1905 | else { |
| 1906 | p_buff= |
| 1907 | (void *)((unsigned long) |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1908 | (p_buff+2*(privptr->p_env->read_size)-1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | & PAGE_MASK) ; |
| 1910 | } |
| 1911 | } /* for read_buffers */ |
| 1912 | } /* read_size < PAGE_SIZE */ |
| 1913 | else { /* read Size >= PAGE_SIZE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | for (i=0 ; i< privptr->p_env->read_buffers ; i++) { |
| 1915 | p_buff = (void *)__get_free_pages(__GFP_DMA, |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1916 | (int)pages_to_order_of_mag( |
| 1917 | privptr->p_buff_pages_perread)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | if (p_buff==NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | free_pages((unsigned long)privptr->p_buff_ccw, |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1920 | (int)pages_to_order_of_mag(privptr-> |
| 1921 | p_buff_ccw_num)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | /* free the write pages */ |
| 1923 | p_buf=privptr->p_buff_write; |
| 1924 | while (p_buf!=NULL) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1925 | free_pages( |
| 1926 | (unsigned long)p_buf->p_buffer, |
| 1927 | (int)pages_to_order_of_mag( |
| 1928 | privptr->p_buff_pages_perwrite)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | p_buf=p_buf->next; |
| 1930 | } |
| 1931 | /* free any read pages already alloc */ |
| 1932 | p_buf=privptr->p_buff_read; |
| 1933 | while (p_buf!=NULL) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 1934 | free_pages( |
| 1935 | (unsigned long)p_buf->p_buffer, |
| 1936 | (int)pages_to_order_of_mag( |
| 1937 | privptr->p_buff_pages_perread)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | p_buf=p_buf->next; |
| 1939 | } |
| 1940 | privptr->p_buff_ccw=NULL; |
| 1941 | privptr->p_buff_write=NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | return -ENOMEM; |
| 1943 | } |
| 1944 | memset(p_buff, 0x00, privptr->p_env->read_size); |
| 1945 | p_buf = p_free_chain; |
| 1946 | privptr->p_buff_read = p_buf; |
| 1947 | p_free_chain = p_buf->next; |
| 1948 | |
| 1949 | if (p_last_CCWB==NULL) { |
| 1950 | p_buf->next=NULL; |
| 1951 | real_TIC_address=0; |
| 1952 | p_last_CCWB=p_buf; |
| 1953 | } |
| 1954 | else { |
| 1955 | p_buf->next=p_first_CCWB; |
| 1956 | real_TIC_address= |
| 1957 | (addr_t)__pa( |
| 1958 | &p_first_CCWB -> read ); |
| 1959 | } |
| 1960 | |
| 1961 | p_first_CCWB=p_buf; |
| 1962 | /* save buff address */ |
| 1963 | p_buf->p_buffer=(struct clawbuf *)p_buff; |
| 1964 | /* initialize read command */ |
| 1965 | p_buf-> read.cmd_code = CCW_CLAW_CMD_READ; |
| 1966 | p_buf-> read.cda = (__u32)__pa(p_buff); |
| 1967 | p_buf-> read.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1968 | p_buf-> read.count = privptr->p_env->read_size; |
| 1969 | |
| 1970 | /* initialize read_h command */ |
| 1971 | p_buf-> read_h.cmd_code = CCW_CLAW_CMD_READHEADER; |
| 1972 | p_buf-> read_h.cda = |
| 1973 | (__u32)__pa(&(p_buf->header)); |
| 1974 | p_buf-> read_h.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1975 | p_buf-> read_h.count = sizeof(struct clawh); |
| 1976 | |
| 1977 | /* initialize Signal command */ |
| 1978 | p_buf-> signal.cmd_code = CCW_CLAW_CMD_SIGNAL_SMOD; |
| 1979 | p_buf-> signal.cda = |
| 1980 | (__u32)__pa(&(pClawH->flag)); |
| 1981 | p_buf-> signal.flags = CCW_FLAG_SLI | CCW_FLAG_CC; |
| 1982 | p_buf-> signal.count = 1; |
| 1983 | |
| 1984 | /* initialize r_TIC_1 command */ |
| 1985 | p_buf-> r_TIC_1.cmd_code = CCW_CLAW_CMD_TIC; |
| 1986 | p_buf-> r_TIC_1.cda = (__u32)real_TIC_address; |
| 1987 | p_buf-> r_TIC_1.flags = 0; |
| 1988 | p_buf-> r_TIC_1.count = 0; |
| 1989 | |
| 1990 | /* initialize r_read_FF command */ |
| 1991 | p_buf-> r_read_FF.cmd_code = CCW_CLAW_CMD_READFF; |
| 1992 | p_buf-> r_read_FF.cda = |
| 1993 | (__u32)__pa(&(pClawH->flag)); |
| 1994 | p_buf-> r_read_FF.flags = |
| 1995 | CCW_FLAG_SLI | CCW_FLAG_CC | CCW_FLAG_PCI; |
| 1996 | p_buf-> r_read_FF.count = 1; |
| 1997 | |
| 1998 | /* initialize r_TIC_2 */ |
| 1999 | memcpy(&p_buf->r_TIC_2, &p_buf->r_TIC_1, |
| 2000 | sizeof(struct ccw1)); |
| 2001 | |
| 2002 | /* initialize Header */ |
| 2003 | p_buf->header.length=0xffff; |
| 2004 | p_buf->header.opcode=0xff; |
| 2005 | p_buf->header.flag=CLAW_PENDING; |
| 2006 | |
| 2007 | } /* For read_buffers */ |
| 2008 | } /* read_size >= PAGE_SIZE */ |
| 2009 | } /* pBuffread = NULL */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | add_claw_reads( dev ,p_first_CCWB , p_last_CCWB); |
| 2011 | privptr->buffs_alloc = 1; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | return 0; |
| 2014 | } /* end of init_ccw_bk */ |
| 2015 | |
| 2016 | /*-------------------------------------------------------------------* |
| 2017 | * * |
| 2018 | * probe_error * |
| 2019 | * * |
| 2020 | *--------------------------------------------------------------------*/ |
| 2021 | |
| 2022 | static void |
| 2023 | probe_error( struct ccwgroup_device *cgdev) |
| 2024 | { |
Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 2025 | struct claw_privbk *privptr; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2026 | |
| 2027 | CLAW_DBF_TEXT(4, trace, "proberr"); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2028 | privptr = dev_get_drvdata(&cgdev->dev); |
Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 2029 | if (privptr != NULL) { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2030 | dev_set_drvdata(&cgdev->dev, NULL); |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 2031 | kfree(privptr->p_env); |
Martin Schwidefsky | 2b356b4 | 2008-08-21 17:10:22 +0200 | [diff] [blame] | 2032 | kfree(privptr->p_mtc_envelope); |
| 2033 | kfree(privptr); |
| 2034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | } /* probe_error */ |
| 2036 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | /*-------------------------------------------------------------------* |
| 2038 | * claw_process_control * |
| 2039 | * * |
| 2040 | * * |
| 2041 | *--------------------------------------------------------------------*/ |
| 2042 | |
| 2043 | static int |
| 2044 | claw_process_control( struct net_device *dev, struct ccwbk * p_ccw) |
| 2045 | { |
| 2046 | |
| 2047 | struct clawbuf *p_buf; |
| 2048 | struct clawctl ctlbk; |
| 2049 | struct clawctl *p_ctlbk; |
| 2050 | char temp_host_name[8]; |
| 2051 | char temp_ws_name[8]; |
| 2052 | struct claw_privbk *privptr; |
| 2053 | struct claw_env *p_env; |
| 2054 | struct sysval *p_sysval; |
| 2055 | struct conncmd *p_connect=NULL; |
| 2056 | int rc; |
| 2057 | struct chbk *p_ch = NULL; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2058 | struct device *tdev; |
| 2059 | CLAW_DBF_TEXT(2, setup, "clw_cntl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | udelay(1000); /* Wait a ms for the control packets to |
| 2061 | *catch up to each other */ |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2062 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | p_env=privptr->p_env; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2064 | tdev = &privptr->channel[READ_CHANNEL].cdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | memcpy( &temp_host_name, p_env->host_name, 8); |
| 2066 | memcpy( &temp_ws_name, p_env->adapter_name , 8); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2067 | dev_info(tdev, "%s: CLAW device %.8s: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2068 | "Received Control Packet\n", |
| 2069 | dev->name, temp_ws_name); |
| 2070 | if (privptr->release_pend==1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | return 0; |
| 2072 | } |
| 2073 | p_buf=p_ccw->p_buffer; |
| 2074 | p_ctlbk=&ctlbk; |
| 2075 | if (p_env->packing == DO_PACKED) { /* packing in progress?*/ |
| 2076 | memcpy(p_ctlbk, &p_buf->buffer[4], sizeof(struct clawctl)); |
| 2077 | } else { |
| 2078 | memcpy(p_ctlbk, p_buf, sizeof(struct clawctl)); |
| 2079 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | switch (p_ctlbk->command) |
| 2081 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2082 | case SYSTEM_VALIDATE_REQUEST: |
| 2083 | if (p_ctlbk->version != CLAW_VERSION_ID) { |
| 2084 | claw_snd_sys_validate_rsp(dev, p_ctlbk, |
| 2085 | CLAW_RC_WRONG_VERSION); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2086 | dev_warn(tdev, "The communication peer of %s" |
| 2087 | " uses an incorrect API version %d\n", |
| 2088 | dev->name, p_ctlbk->version); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2089 | } |
| 2090 | p_sysval = (struct sysval *)&(p_ctlbk->data); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2091 | dev_info(tdev, "%s: Recv Sys Validate Request: " |
| 2092 | "Vers=%d,link_id=%d,Corr=%d,WS name=%.8s," |
| 2093 | "Host name=%.8s\n", |
| 2094 | dev->name, p_ctlbk->version, |
| 2095 | p_ctlbk->linkid, |
| 2096 | p_ctlbk->correlator, |
| 2097 | p_sysval->WS_name, |
| 2098 | p_sysval->host_name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2099 | if (memcmp(temp_host_name, p_sysval->host_name, 8)) { |
| 2100 | claw_snd_sys_validate_rsp(dev, p_ctlbk, |
| 2101 | CLAW_RC_NAME_MISMATCH); |
| 2102 | CLAW_DBF_TEXT(2, setup, "HSTBAD"); |
| 2103 | CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->host_name); |
| 2104 | CLAW_DBF_TEXT_(2, setup, "%s", temp_host_name); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2105 | dev_warn(tdev, |
| 2106 | "Host name %s for %s does not match the" |
| 2107 | " remote adapter name %s\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2108 | p_sysval->host_name, |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2109 | dev->name, |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2110 | temp_host_name); |
| 2111 | } |
| 2112 | if (memcmp(temp_ws_name, p_sysval->WS_name, 8)) { |
| 2113 | claw_snd_sys_validate_rsp(dev, p_ctlbk, |
| 2114 | CLAW_RC_NAME_MISMATCH); |
| 2115 | CLAW_DBF_TEXT(2, setup, "WSNBAD"); |
| 2116 | CLAW_DBF_TEXT_(2, setup, "%s", p_sysval->WS_name); |
| 2117 | CLAW_DBF_TEXT_(2, setup, "%s", temp_ws_name); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2118 | dev_warn(tdev, "Adapter name %s for %s does not match" |
| 2119 | " the remote host name %s\n", |
| 2120 | p_sysval->WS_name, |
| 2121 | dev->name, |
| 2122 | temp_ws_name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2123 | } |
| 2124 | if ((p_sysval->write_frame_size < p_env->write_size) && |
| 2125 | (p_env->packing == 0)) { |
| 2126 | claw_snd_sys_validate_rsp(dev, p_ctlbk, |
| 2127 | CLAW_RC_HOST_RCV_TOO_SMALL); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2128 | dev_warn(tdev, |
| 2129 | "The local write buffer is smaller than the" |
| 2130 | " remote read buffer\n"); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2131 | CLAW_DBF_TEXT(2, setup, "wrtszbad"); |
| 2132 | } |
| 2133 | if ((p_sysval->read_frame_size < p_env->read_size) && |
| 2134 | (p_env->packing == 0)) { |
| 2135 | claw_snd_sys_validate_rsp(dev, p_ctlbk, |
| 2136 | CLAW_RC_HOST_RCV_TOO_SMALL); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2137 | dev_warn(tdev, |
| 2138 | "The local read buffer is smaller than the" |
| 2139 | " remote write buffer\n"); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2140 | CLAW_DBF_TEXT(2, setup, "rdsizbad"); |
| 2141 | } |
| 2142 | claw_snd_sys_validate_rsp(dev, p_ctlbk, 0); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2143 | dev_info(tdev, |
| 2144 | "CLAW device %.8s: System validate" |
| 2145 | " completed.\n", temp_ws_name); |
| 2146 | dev_info(tdev, |
| 2147 | "%s: sys Validate Rsize:%d Wsize:%d\n", |
| 2148 | dev->name, p_sysval->read_frame_size, |
| 2149 | p_sysval->write_frame_size); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2150 | privptr->system_validate_comp = 1; |
| 2151 | if (strncmp(p_env->api_type, WS_APPL_NAME_PACKED, 6) == 0) |
| 2152 | p_env->packing = PACKING_ASK; |
| 2153 | claw_strt_conn_req(dev); |
| 2154 | break; |
| 2155 | case SYSTEM_VALIDATE_RESPONSE: |
| 2156 | p_sysval = (struct sysval *)&(p_ctlbk->data); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2157 | dev_info(tdev, |
| 2158 | "Settings for %s validated (version=%d, " |
| 2159 | "remote device=%d, rc=%d, adapter name=%.8s, " |
| 2160 | "host name=%.8s)\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2161 | dev->name, |
| 2162 | p_ctlbk->version, |
| 2163 | p_ctlbk->correlator, |
| 2164 | p_ctlbk->rc, |
| 2165 | p_sysval->WS_name, |
| 2166 | p_sysval->host_name); |
| 2167 | switch (p_ctlbk->rc) { |
| 2168 | case 0: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2169 | dev_info(tdev, "%s: CLAW device " |
| 2170 | "%.8s: System validate completed.\n", |
| 2171 | dev->name, temp_ws_name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2172 | if (privptr->system_validate_comp == 0) |
| 2173 | claw_strt_conn_req(dev); |
| 2174 | privptr->system_validate_comp = 1; |
| 2175 | break; |
| 2176 | case CLAW_RC_NAME_MISMATCH: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2177 | dev_warn(tdev, "Validating %s failed because of" |
| 2178 | " a host or adapter name mismatch\n", |
| 2179 | dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2180 | break; |
| 2181 | case CLAW_RC_WRONG_VERSION: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2182 | dev_warn(tdev, "Validating %s failed because of a" |
| 2183 | " version conflict\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2184 | dev->name); |
| 2185 | break; |
| 2186 | case CLAW_RC_HOST_RCV_TOO_SMALL: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2187 | dev_warn(tdev, "Validating %s failed because of a" |
| 2188 | " frame size conflict\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2189 | dev->name); |
| 2190 | break; |
| 2191 | default: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2192 | dev_warn(tdev, "The communication peer of %s rejected" |
| 2193 | " the connection\n", |
| 2194 | dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2195 | break; |
| 2196 | } |
| 2197 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2199 | case CONNECTION_REQUEST: |
| 2200 | p_connect = (struct conncmd *)&(p_ctlbk->data); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2201 | dev_info(tdev, "%s: Recv Conn Req: Vers=%d,link_id=%d," |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2202 | "Corr=%d,HOST appl=%.8s,WS appl=%.8s\n", |
| 2203 | dev->name, |
| 2204 | p_ctlbk->version, |
| 2205 | p_ctlbk->linkid, |
| 2206 | p_ctlbk->correlator, |
| 2207 | p_connect->host_name, |
| 2208 | p_connect->WS_name); |
| 2209 | if (privptr->active_link_ID != 0) { |
| 2210 | claw_snd_disc(dev, p_ctlbk); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2211 | dev_info(tdev, "%s rejected a connection request" |
| 2212 | " because it is already active\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2213 | dev->name); |
| 2214 | } |
| 2215 | if (p_ctlbk->linkid != 1) { |
| 2216 | claw_snd_disc(dev, p_ctlbk); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2217 | dev_info(tdev, "%s rejected a request to open multiple" |
| 2218 | " connections\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2219 | dev->name); |
| 2220 | } |
| 2221 | rc = find_link(dev, p_connect->host_name, p_connect->WS_name); |
| 2222 | if (rc != 0) { |
| 2223 | claw_snd_disc(dev, p_ctlbk); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2224 | dev_info(tdev, "%s rejected a connection request" |
| 2225 | " because of a type mismatch\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2226 | dev->name); |
| 2227 | } |
| 2228 | claw_send_control(dev, |
| 2229 | CONNECTION_CONFIRM, p_ctlbk->linkid, |
| 2230 | p_ctlbk->correlator, |
| 2231 | 0, p_connect->host_name, |
| 2232 | p_connect->WS_name); |
| 2233 | if (p_env->packing == PACKING_ASK) { |
| 2234 | p_env->packing = PACK_SEND; |
| 2235 | claw_snd_conn_req(dev, 0); |
| 2236 | } |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2237 | dev_info(tdev, "%s: CLAW device %.8s: Connection " |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2238 | "completed link_id=%d.\n", |
| 2239 | dev->name, temp_ws_name, |
| 2240 | p_ctlbk->linkid); |
| 2241 | privptr->active_link_ID = p_ctlbk->linkid; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2242 | p_ch = &privptr->channel[WRITE_CHANNEL]; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2243 | wake_up(&p_ch->wait); /* wake up claw_open ( WRITE) */ |
| 2244 | break; |
| 2245 | case CONNECTION_RESPONSE: |
| 2246 | p_connect = (struct conncmd *)&(p_ctlbk->data); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2247 | dev_info(tdev, "%s: Recv Conn Resp: Vers=%d,link_id=%d," |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2248 | "Corr=%d,RC=%d,Host appl=%.8s, WS appl=%.8s\n", |
| 2249 | dev->name, |
| 2250 | p_ctlbk->version, |
| 2251 | p_ctlbk->linkid, |
| 2252 | p_ctlbk->correlator, |
| 2253 | p_ctlbk->rc, |
| 2254 | p_connect->host_name, |
| 2255 | p_connect->WS_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2257 | if (p_ctlbk->rc != 0) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2258 | dev_warn(tdev, "The communication peer of %s rejected" |
| 2259 | " a connection request\n", |
| 2260 | dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2261 | return 1; |
| 2262 | } |
| 2263 | rc = find_link(dev, |
| 2264 | p_connect->host_name, p_connect->WS_name); |
| 2265 | if (rc != 0) { |
| 2266 | claw_snd_disc(dev, p_ctlbk); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2267 | dev_warn(tdev, "The communication peer of %s" |
| 2268 | " rejected a connection " |
| 2269 | "request because of a type mismatch\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2270 | dev->name); |
| 2271 | } |
| 2272 | /* should be until CONNECTION_CONFIRM */ |
| 2273 | privptr->active_link_ID = -(p_ctlbk->linkid); |
| 2274 | break; |
| 2275 | case CONNECTION_CONFIRM: |
| 2276 | p_connect = (struct conncmd *)&(p_ctlbk->data); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2277 | dev_info(tdev, |
| 2278 | "%s: Recv Conn Confirm:Vers=%d,link_id=%d," |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2279 | "Corr=%d,Host appl=%.8s,WS appl=%.8s\n", |
| 2280 | dev->name, |
| 2281 | p_ctlbk->version, |
| 2282 | p_ctlbk->linkid, |
| 2283 | p_ctlbk->correlator, |
| 2284 | p_connect->host_name, |
| 2285 | p_connect->WS_name); |
| 2286 | if (p_ctlbk->linkid == -(privptr->active_link_ID)) { |
| 2287 | privptr->active_link_ID = p_ctlbk->linkid; |
| 2288 | if (p_env->packing > PACKING_ASK) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2289 | dev_info(tdev, |
| 2290 | "%s: Confirmed Now packing\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | p_env->packing = DO_PACKED; |
| 2292 | } |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2293 | p_ch = &privptr->channel[WRITE_CHANNEL]; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2294 | wake_up(&p_ch->wait); |
| 2295 | } else { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2296 | dev_warn(tdev, "Activating %s failed because of" |
| 2297 | " an incorrect link ID=%d\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2298 | dev->name, p_ctlbk->linkid); |
| 2299 | claw_snd_disc(dev, p_ctlbk); |
| 2300 | } |
| 2301 | break; |
| 2302 | case DISCONNECT: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2303 | dev_info(tdev, "%s: Disconnect: " |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2304 | "Vers=%d,link_id=%d,Corr=%d\n", |
| 2305 | dev->name, p_ctlbk->version, |
| 2306 | p_ctlbk->linkid, p_ctlbk->correlator); |
| 2307 | if ((p_ctlbk->linkid == 2) && |
| 2308 | (p_env->packing == PACK_SEND)) { |
| 2309 | privptr->active_link_ID = 1; |
| 2310 | p_env->packing = DO_PACKED; |
| 2311 | } else |
| 2312 | privptr->active_link_ID = 0; |
| 2313 | break; |
| 2314 | case CLAW_ERROR: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2315 | dev_warn(tdev, "The communication peer of %s failed\n", |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2316 | dev->name); |
| 2317 | break; |
| 2318 | default: |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2319 | dev_warn(tdev, "The communication peer of %s sent" |
| 2320 | " an unknown command code\n", |
| 2321 | dev->name); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2322 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | return 0; |
| 2326 | } /* end of claw_process_control */ |
| 2327 | |
| 2328 | |
| 2329 | /*-------------------------------------------------------------------* |
| 2330 | * claw_send_control * |
| 2331 | * * |
| 2332 | *--------------------------------------------------------------------*/ |
| 2333 | |
| 2334 | static int |
| 2335 | claw_send_control(struct net_device *dev, __u8 type, __u8 link, |
| 2336 | __u8 correlator, __u8 rc, char *local_name, char *remote_name) |
| 2337 | { |
| 2338 | struct claw_privbk *privptr; |
| 2339 | struct clawctl *p_ctl; |
| 2340 | struct sysval *p_sysval; |
| 2341 | struct conncmd *p_connect; |
| 2342 | struct sk_buff *skb; |
| 2343 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2344 | CLAW_DBF_TEXT(2, setup, "sndcntl"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2345 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | p_ctl=(struct clawctl *)&privptr->ctl_bk; |
| 2347 | |
| 2348 | p_ctl->command=type; |
| 2349 | p_ctl->version=CLAW_VERSION_ID; |
| 2350 | p_ctl->linkid=link; |
| 2351 | p_ctl->correlator=correlator; |
| 2352 | p_ctl->rc=rc; |
| 2353 | |
| 2354 | p_sysval=(struct sysval *)&p_ctl->data; |
| 2355 | p_connect=(struct conncmd *)&p_ctl->data; |
| 2356 | |
| 2357 | switch (p_ctl->command) { |
| 2358 | case SYSTEM_VALIDATE_REQUEST: |
| 2359 | case SYSTEM_VALIDATE_RESPONSE: |
| 2360 | memcpy(&p_sysval->host_name, local_name, 8); |
| 2361 | memcpy(&p_sysval->WS_name, remote_name, 8); |
| 2362 | if (privptr->p_env->packing > 0) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2363 | p_sysval->read_frame_size = DEF_PACK_BUFSIZE; |
| 2364 | p_sysval->write_frame_size = DEF_PACK_BUFSIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | } else { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2366 | /* how big is the biggest group of packets */ |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2367 | p_sysval->read_frame_size = |
| 2368 | privptr->p_env->read_size; |
| 2369 | p_sysval->write_frame_size = |
| 2370 | privptr->p_env->write_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2371 | } |
| 2372 | memset(&p_sysval->reserved, 0x00, 4); |
| 2373 | break; |
| 2374 | case CONNECTION_REQUEST: |
| 2375 | case CONNECTION_RESPONSE: |
| 2376 | case CONNECTION_CONFIRM: |
| 2377 | case DISCONNECT: |
| 2378 | memcpy(&p_sysval->host_name, local_name, 8); |
| 2379 | memcpy(&p_sysval->WS_name, remote_name, 8); |
| 2380 | if (privptr->p_env->packing > 0) { |
| 2381 | /* How big is the biggest packet */ |
| 2382 | p_connect->reserved1[0]=CLAW_FRAME_SIZE; |
| 2383 | p_connect->reserved1[1]=CLAW_FRAME_SIZE; |
| 2384 | } else { |
| 2385 | memset(&p_connect->reserved1, 0x00, 4); |
| 2386 | memset(&p_connect->reserved2, 0x00, 4); |
| 2387 | } |
| 2388 | break; |
| 2389 | default: |
| 2390 | break; |
| 2391 | } |
| 2392 | |
| 2393 | /* write Control Record to the device */ |
| 2394 | |
| 2395 | |
| 2396 | skb = dev_alloc_skb(sizeof(struct clawctl)); |
| 2397 | if (!skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | return -ENOMEM; |
| 2399 | } |
| 2400 | memcpy(skb_put(skb, sizeof(struct clawctl)), |
| 2401 | p_ctl, sizeof(struct clawctl)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | if (privptr->p_env->packing >= PACK_SEND) |
| 2403 | claw_hw_tx(skb, dev, 1); |
| 2404 | else |
| 2405 | claw_hw_tx(skb, dev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | return 0; |
| 2407 | } /* end of claw_send_control */ |
| 2408 | |
| 2409 | /*-------------------------------------------------------------------* |
| 2410 | * claw_snd_conn_req * |
| 2411 | * * |
| 2412 | *--------------------------------------------------------------------*/ |
| 2413 | static int |
| 2414 | claw_snd_conn_req(struct net_device *dev, __u8 link) |
| 2415 | { |
| 2416 | int rc; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2417 | struct claw_privbk *privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | struct clawctl *p_ctl; |
| 2419 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2420 | CLAW_DBF_TEXT(2, setup, "snd_conn"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | rc = 1; |
| 2422 | p_ctl=(struct clawctl *)&privptr->ctl_bk; |
| 2423 | p_ctl->linkid = link; |
| 2424 | if ( privptr->system_validate_comp==0x00 ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | return rc; |
| 2426 | } |
| 2427 | if (privptr->p_env->packing == PACKING_ASK ) |
| 2428 | rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, |
| 2429 | WS_APPL_NAME_PACKED, WS_APPL_NAME_PACKED); |
| 2430 | if (privptr->p_env->packing == PACK_SEND) { |
| 2431 | rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, |
| 2432 | WS_APPL_NAME_IP_NAME, WS_APPL_NAME_IP_NAME); |
| 2433 | } |
| 2434 | if (privptr->p_env->packing == 0) |
| 2435 | rc=claw_send_control(dev, CONNECTION_REQUEST,0,0,0, |
| 2436 | HOST_APPL_NAME, privptr->p_env->api_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | return rc; |
| 2438 | |
| 2439 | } /* end of claw_snd_conn_req */ |
| 2440 | |
| 2441 | |
| 2442 | /*-------------------------------------------------------------------* |
| 2443 | * claw_snd_disc * |
| 2444 | * * |
| 2445 | *--------------------------------------------------------------------*/ |
| 2446 | |
| 2447 | static int |
| 2448 | claw_snd_disc(struct net_device *dev, struct clawctl * p_ctl) |
| 2449 | { |
| 2450 | int rc; |
| 2451 | struct conncmd * p_connect; |
| 2452 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2453 | CLAW_DBF_TEXT(2, setup, "snd_dsc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | p_connect=(struct conncmd *)&p_ctl->data; |
| 2455 | |
| 2456 | rc=claw_send_control(dev, DISCONNECT, p_ctl->linkid, |
| 2457 | p_ctl->correlator, 0, |
| 2458 | p_connect->host_name, p_connect->WS_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | return rc; |
| 2460 | } /* end of claw_snd_disc */ |
| 2461 | |
| 2462 | |
| 2463 | /*-------------------------------------------------------------------* |
| 2464 | * claw_snd_sys_validate_rsp * |
| 2465 | * * |
| 2466 | *--------------------------------------------------------------------*/ |
| 2467 | |
| 2468 | static int |
| 2469 | claw_snd_sys_validate_rsp(struct net_device *dev, |
| 2470 | struct clawctl *p_ctl, __u32 return_code) |
| 2471 | { |
| 2472 | struct claw_env * p_env; |
| 2473 | struct claw_privbk *privptr; |
| 2474 | int rc; |
| 2475 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2476 | CLAW_DBF_TEXT(2, setup, "chkresp"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2477 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | p_env=privptr->p_env; |
| 2479 | rc=claw_send_control(dev, SYSTEM_VALIDATE_RESPONSE, |
| 2480 | p_ctl->linkid, |
| 2481 | p_ctl->correlator, |
| 2482 | return_code, |
| 2483 | p_env->host_name, |
| 2484 | p_env->adapter_name ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | return rc; |
| 2486 | } /* end of claw_snd_sys_validate_rsp */ |
| 2487 | |
| 2488 | /*-------------------------------------------------------------------* |
| 2489 | * claw_strt_conn_req * |
| 2490 | * * |
| 2491 | *--------------------------------------------------------------------*/ |
| 2492 | |
| 2493 | static int |
| 2494 | claw_strt_conn_req(struct net_device *dev ) |
| 2495 | { |
| 2496 | int rc; |
| 2497 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2498 | CLAW_DBF_TEXT(2, setup, "conn_req"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2499 | rc=claw_snd_conn_req(dev, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | return rc; |
| 2501 | } /* end of claw_strt_conn_req */ |
| 2502 | |
| 2503 | |
| 2504 | |
| 2505 | /*-------------------------------------------------------------------* |
| 2506 | * claw_stats * |
| 2507 | *-------------------------------------------------------------------*/ |
| 2508 | |
| 2509 | static struct |
| 2510 | net_device_stats *claw_stats(struct net_device *dev) |
| 2511 | { |
| 2512 | struct claw_privbk *privptr; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2513 | |
| 2514 | CLAW_DBF_TEXT(4, trace, "stats"); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2515 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | return &privptr->stats; |
| 2517 | } /* end of claw_stats */ |
| 2518 | |
| 2519 | |
| 2520 | /*-------------------------------------------------------------------* |
| 2521 | * unpack_read * |
| 2522 | * * |
| 2523 | *--------------------------------------------------------------------*/ |
| 2524 | static void |
| 2525 | unpack_read(struct net_device *dev ) |
| 2526 | { |
| 2527 | struct sk_buff *skb; |
| 2528 | struct claw_privbk *privptr; |
| 2529 | struct claw_env *p_env; |
| 2530 | struct ccwbk *p_this_ccw; |
| 2531 | struct ccwbk *p_first_ccw; |
| 2532 | struct ccwbk *p_last_ccw; |
| 2533 | struct clawph *p_packh; |
| 2534 | void *p_packd; |
| 2535 | struct clawctl *p_ctlrec=NULL; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2536 | struct device *p_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | |
| 2538 | __u32 len_of_data; |
| 2539 | __u32 pack_off; |
| 2540 | __u8 link_num; |
| 2541 | __u8 mtc_this_frm=0; |
| 2542 | __u32 bytes_to_mov; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | int i=0; |
| 2544 | int p=0; |
| 2545 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2546 | CLAW_DBF_TEXT(4, trace, "unpkread"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2547 | p_first_ccw=NULL; |
| 2548 | p_last_ccw=NULL; |
| 2549 | p_packh=NULL; |
| 2550 | p_packd=NULL; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2551 | privptr = dev->ml_priv; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2552 | |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2553 | p_dev = &privptr->channel[READ_CHANNEL].cdev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | p_env = privptr->p_env; |
| 2555 | p_this_ccw=privptr->p_read_active_first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2556 | while (p_this_ccw!=NULL && p_this_ccw->header.flag!=CLAW_PENDING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | pack_off = 0; |
| 2558 | p = 0; |
| 2559 | p_this_ccw->header.flag=CLAW_PENDING; |
| 2560 | privptr->p_read_active_first=p_this_ccw->next; |
| 2561 | p_this_ccw->next=NULL; |
| 2562 | p_packh = (struct clawph *)p_this_ccw->p_buffer; |
| 2563 | if ((p_env->packing == PACK_SEND) && |
| 2564 | (p_packh->len == 32) && |
| 2565 | (p_packh->link_num == 0)) { /* is it a packed ctl rec? */ |
| 2566 | p_packh++; /* peek past pack header */ |
| 2567 | p_ctlrec = (struct clawctl *)p_packh; |
| 2568 | p_packh--; /* un peek */ |
| 2569 | if ((p_ctlrec->command == CONNECTION_RESPONSE) || |
| 2570 | (p_ctlrec->command == CONNECTION_CONFIRM)) |
| 2571 | p_env->packing = DO_PACKED; |
| 2572 | } |
| 2573 | if (p_env->packing == DO_PACKED) |
| 2574 | link_num=p_packh->link_num; |
| 2575 | else |
| 2576 | link_num=p_this_ccw->header.opcode / 8; |
| 2577 | if ((p_this_ccw->header.opcode & MORE_to_COME_FLAG)!=0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | mtc_this_frm=1; |
| 2579 | if (p_this_ccw->header.length!= |
| 2580 | privptr->p_env->read_size ) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2581 | dev_warn(p_dev, |
| 2582 | "The communication peer of %s" |
| 2583 | " sent a faulty" |
| 2584 | " frame of length %02x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2585 | dev->name, p_this_ccw->header.length); |
| 2586 | } |
| 2587 | } |
| 2588 | |
| 2589 | if (privptr->mtc_skipping) { |
| 2590 | /* |
| 2591 | * We're in the mode of skipping past a |
| 2592 | * multi-frame message |
| 2593 | * that we can't process for some reason or other. |
| 2594 | * The first frame without the More-To-Come flag is |
| 2595 | * the last frame of the skipped message. |
| 2596 | */ |
| 2597 | /* in case of More-To-Come not set in this frame */ |
| 2598 | if (mtc_this_frm==0) { |
| 2599 | privptr->mtc_skipping=0; /* Ok, the end */ |
| 2600 | privptr->mtc_logical_link=-1; |
| 2601 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | goto NextFrame; |
| 2603 | } |
| 2604 | |
| 2605 | if (link_num==0) { |
| 2606 | claw_process_control(dev, p_this_ccw); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2607 | CLAW_DBF_TEXT(4, trace, "UnpkCntl"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | goto NextFrame; |
| 2609 | } |
| 2610 | unpack_next: |
| 2611 | if (p_env->packing == DO_PACKED) { |
| 2612 | if (pack_off > p_env->read_size) |
| 2613 | goto NextFrame; |
| 2614 | p_packd = p_this_ccw->p_buffer+pack_off; |
| 2615 | p_packh = (struct clawph *) p_packd; |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2616 | if ((p_packh->len == 0) || /* done with this frame? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | (p_packh->flag != 0)) |
| 2618 | goto NextFrame; |
| 2619 | bytes_to_mov = p_packh->len; |
| 2620 | pack_off += bytes_to_mov+sizeof(struct clawph); |
| 2621 | p++; |
| 2622 | } else { |
| 2623 | bytes_to_mov=p_this_ccw->header.length; |
| 2624 | } |
| 2625 | if (privptr->mtc_logical_link<0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | |
| 2627 | /* |
| 2628 | * if More-To-Come is set in this frame then we don't know |
| 2629 | * length of entire message, and hence have to allocate |
| 2630 | * large buffer */ |
| 2631 | |
| 2632 | /* We are starting a new envelope */ |
| 2633 | privptr->mtc_offset=0; |
| 2634 | privptr->mtc_logical_link=link_num; |
| 2635 | } |
| 2636 | |
| 2637 | if (bytes_to_mov > (MAX_ENVELOPE_SIZE- privptr->mtc_offset) ) { |
| 2638 | /* error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | privptr->stats.rx_frame_errors++; |
| 2640 | goto NextFrame; |
| 2641 | } |
| 2642 | if (p_env->packing == DO_PACKED) { |
| 2643 | memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset, |
| 2644 | p_packd+sizeof(struct clawph), bytes_to_mov); |
| 2645 | |
| 2646 | } else { |
| 2647 | memcpy( privptr->p_mtc_envelope+ privptr->mtc_offset, |
| 2648 | p_this_ccw->p_buffer, bytes_to_mov); |
| 2649 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | if (mtc_this_frm==0) { |
| 2651 | len_of_data=privptr->mtc_offset+bytes_to_mov; |
| 2652 | skb=dev_alloc_skb(len_of_data); |
| 2653 | if (skb) { |
| 2654 | memcpy(skb_put(skb,len_of_data), |
| 2655 | privptr->p_mtc_envelope, |
| 2656 | len_of_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | skb->dev=dev; |
Arnaldo Carvalho de Melo | 98e399f | 2007-03-19 15:33:04 -0700 | [diff] [blame] | 2658 | skb_reset_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2659 | skb->protocol=htons(ETH_P_IP); |
| 2660 | skb->ip_summed=CHECKSUM_UNNECESSARY; |
| 2661 | privptr->stats.rx_packets++; |
| 2662 | privptr->stats.rx_bytes+=len_of_data; |
| 2663 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | } |
| 2665 | else { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2666 | dev_info(p_dev, "Allocating a buffer for" |
| 2667 | " incoming data failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | privptr->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2669 | } |
| 2670 | privptr->mtc_offset=0; |
| 2671 | privptr->mtc_logical_link=-1; |
| 2672 | } |
| 2673 | else { |
| 2674 | privptr->mtc_offset+=bytes_to_mov; |
| 2675 | } |
| 2676 | if (p_env->packing == DO_PACKED) |
| 2677 | goto unpack_next; |
| 2678 | NextFrame: |
| 2679 | /* |
| 2680 | * Remove ThisCCWblock from active read queue, and add it |
| 2681 | * to queue of free blocks to be reused. |
| 2682 | */ |
| 2683 | i++; |
| 2684 | p_this_ccw->header.length=0xffff; |
| 2685 | p_this_ccw->header.opcode=0xff; |
| 2686 | /* |
| 2687 | * add this one to the free queue for later reuse |
| 2688 | */ |
| 2689 | if (p_first_ccw==NULL) { |
| 2690 | p_first_ccw = p_this_ccw; |
| 2691 | } |
| 2692 | else { |
| 2693 | p_last_ccw->next = p_this_ccw; |
| 2694 | } |
| 2695 | p_last_ccw = p_this_ccw; |
| 2696 | /* |
| 2697 | * chain to next block on active read queue |
| 2698 | */ |
| 2699 | p_this_ccw = privptr->p_read_active_first; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2700 | CLAW_DBF_TEXT_(4, trace, "rxpkt %d", p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | } /* end of while */ |
| 2702 | |
| 2703 | /* check validity */ |
| 2704 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2705 | CLAW_DBF_TEXT_(4, trace, "rxfrm %d", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | add_claw_reads(dev, p_first_ccw, p_last_ccw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | claw_strt_read(dev, LOCK_YES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | return; |
| 2709 | } /* end of unpack_read */ |
| 2710 | |
| 2711 | /*-------------------------------------------------------------------* |
| 2712 | * claw_strt_read * |
| 2713 | * * |
| 2714 | *--------------------------------------------------------------------*/ |
| 2715 | static void |
| 2716 | claw_strt_read (struct net_device *dev, int lock ) |
| 2717 | { |
| 2718 | int rc = 0; |
| 2719 | __u32 parm; |
| 2720 | unsigned long saveflags = 0; |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2721 | struct claw_privbk *privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | struct ccwbk*p_ccwbk; |
| 2723 | struct chbk *p_ch; |
| 2724 | struct clawh *p_clawh; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2725 | p_ch = &privptr->channel[READ_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2726 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2727 | CLAW_DBF_TEXT(4, trace, "StRdNter"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | p_clawh=(struct clawh *)privptr->p_claw_signal_blk; |
| 2729 | p_clawh->flag=CLAW_IDLE; /* 0x00 */ |
| 2730 | |
| 2731 | if ((privptr->p_write_active_first!=NULL && |
| 2732 | privptr->p_write_active_first->header.flag!=CLAW_PENDING) || |
| 2733 | (privptr->p_read_active_first!=NULL && |
| 2734 | privptr->p_read_active_first->header.flag!=CLAW_PENDING )) { |
| 2735 | p_clawh->flag=CLAW_BUSY; /* 0xff */ |
| 2736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | if (lock==LOCK_YES) { |
| 2738 | spin_lock_irqsave(get_ccwdev_lock(p_ch->cdev), saveflags); |
| 2739 | } |
| 2740 | if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2741 | CLAW_DBF_TEXT(4, trace, "HotRead"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | p_ccwbk=privptr->p_read_active_first; |
| 2743 | parm = (unsigned long) p_ch; |
| 2744 | rc = ccw_device_start (p_ch->cdev, &p_ccwbk->read, parm, |
| 2745 | 0xff, 0); |
| 2746 | if (rc != 0) { |
| 2747 | ccw_check_return_code(p_ch->cdev, rc); |
| 2748 | } |
| 2749 | } |
| 2750 | else { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2751 | CLAW_DBF_TEXT(2, trace, "ReadAct"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | if (lock==LOCK_YES) { |
| 2755 | spin_unlock_irqrestore(get_ccwdev_lock(p_ch->cdev), saveflags); |
| 2756 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2757 | CLAW_DBF_TEXT(4, trace, "StRdExit"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | return; |
| 2759 | } /* end of claw_strt_read */ |
| 2760 | |
| 2761 | /*-------------------------------------------------------------------* |
| 2762 | * claw_strt_out_IO * |
| 2763 | * * |
| 2764 | *--------------------------------------------------------------------*/ |
| 2765 | |
| 2766 | static void |
| 2767 | claw_strt_out_IO( struct net_device *dev ) |
| 2768 | { |
| 2769 | int rc = 0; |
| 2770 | unsigned long parm; |
| 2771 | struct claw_privbk *privptr; |
| 2772 | struct chbk *p_ch; |
| 2773 | struct ccwbk *p_first_ccw; |
| 2774 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | if (!dev) { |
| 2776 | return; |
| 2777 | } |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2778 | privptr = (struct claw_privbk *)dev->ml_priv; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2779 | p_ch = &privptr->channel[WRITE_CHANNEL]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2780 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2781 | CLAW_DBF_TEXT(4, trace, "strt_io"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | p_first_ccw=privptr->p_write_active_first; |
| 2783 | |
| 2784 | if (p_ch->claw_state == CLAW_STOP) |
| 2785 | return; |
| 2786 | if (p_first_ccw == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | return; |
| 2788 | } |
| 2789 | if (test_and_set_bit(0, (void *)&p_ch->IO_active) == 0) { |
| 2790 | parm = (unsigned long) p_ch; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2791 | CLAW_DBF_TEXT(2, trace, "StWrtIO"); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2792 | rc = ccw_device_start(p_ch->cdev, &p_first_ccw->write, parm, |
| 2793 | 0xff, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | if (rc != 0) { |
| 2795 | ccw_check_return_code(p_ch->cdev, rc); |
| 2796 | } |
| 2797 | } |
| 2798 | dev->trans_start = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | return; |
| 2800 | } /* end of claw_strt_out_IO */ |
| 2801 | |
| 2802 | /*-------------------------------------------------------------------* |
| 2803 | * Free write buffers * |
| 2804 | * * |
| 2805 | *--------------------------------------------------------------------*/ |
| 2806 | |
| 2807 | static void |
| 2808 | claw_free_wrt_buf( struct net_device *dev ) |
| 2809 | { |
| 2810 | |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2811 | struct claw_privbk *privptr = (struct claw_privbk *)dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | struct ccwbk*p_this_ccw; |
| 2813 | struct ccwbk*p_next_ccw; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2814 | |
| 2815 | CLAW_DBF_TEXT(4, trace, "freewrtb"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | /* scan the write queue to free any completed write packets */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2817 | p_this_ccw=privptr->p_write_active_first; |
| 2818 | while ( (p_this_ccw!=NULL) && (p_this_ccw->header.flag!=CLAW_PENDING)) |
| 2819 | { |
| 2820 | p_next_ccw = p_this_ccw->next; |
| 2821 | if (((p_next_ccw!=NULL) && |
| 2822 | (p_next_ccw->header.flag!=CLAW_PENDING)) || |
| 2823 | ((p_this_ccw == privptr->p_write_active_last) && |
| 2824 | (p_this_ccw->header.flag!=CLAW_PENDING))) { |
| 2825 | /* The next CCW is OK or this is */ |
| 2826 | /* the last CCW...free it @A1A */ |
| 2827 | privptr->p_write_active_first=p_this_ccw->next; |
| 2828 | p_this_ccw->header.flag=CLAW_PENDING; |
| 2829 | p_this_ccw->next=privptr->p_write_free_chain; |
| 2830 | privptr->p_write_free_chain=p_this_ccw; |
| 2831 | ++privptr->write_free_count; |
| 2832 | privptr->stats.tx_bytes+= p_this_ccw->write.count; |
| 2833 | p_this_ccw=privptr->p_write_active_first; |
| 2834 | privptr->stats.tx_packets++; |
| 2835 | } |
| 2836 | else { |
| 2837 | break; |
| 2838 | } |
| 2839 | } |
| 2840 | if (privptr->write_free_count!=0) { |
| 2841 | claw_clearbit_busy(TB_NOBUFFER,dev); |
| 2842 | } |
| 2843 | /* whole chain removed? */ |
| 2844 | if (privptr->p_write_active_first==NULL) { |
| 2845 | privptr->p_write_active_last=NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2847 | CLAW_DBF_TEXT_(4, trace, "FWC=%d", privptr->write_free_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | return; |
| 2849 | } |
| 2850 | |
| 2851 | /*-------------------------------------------------------------------* |
| 2852 | * claw free netdevice * |
| 2853 | * * |
| 2854 | *--------------------------------------------------------------------*/ |
| 2855 | static void |
| 2856 | claw_free_netdevice(struct net_device * dev, int free_dev) |
| 2857 | { |
| 2858 | struct claw_privbk *privptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2860 | CLAW_DBF_TEXT(2, setup, "free_dev"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2861 | if (!dev) |
| 2862 | return; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2863 | CLAW_DBF_TEXT_(2, setup, "%s", dev->name); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2864 | privptr = dev->ml_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | if (dev->flags & IFF_RUNNING) |
| 2866 | claw_release(dev); |
| 2867 | if (privptr) { |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2868 | privptr->channel[READ_CHANNEL].ndev = NULL; /* say it's free */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | } |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2870 | dev->ml_priv = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2871 | #ifdef MODULE |
| 2872 | if (free_dev) { |
| 2873 | free_netdev(dev); |
| 2874 | } |
| 2875 | #endif |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2876 | CLAW_DBF_TEXT(2, setup, "free_ok"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | /** |
| 2880 | * Claw init netdevice |
| 2881 | * Initialize everything of the net device except the name and the |
| 2882 | * channel structs. |
| 2883 | */ |
Frank Blaschka | 2171dc1 | 2009-01-09 03:43:59 +0000 | [diff] [blame] | 2884 | static const struct net_device_ops claw_netdev_ops = { |
| 2885 | .ndo_open = claw_open, |
| 2886 | .ndo_stop = claw_release, |
| 2887 | .ndo_get_stats = claw_stats, |
| 2888 | .ndo_start_xmit = claw_tx, |
| 2889 | .ndo_change_mtu = claw_change_mtu, |
| 2890 | }; |
| 2891 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | static void |
| 2893 | claw_init_netdevice(struct net_device * dev) |
| 2894 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2895 | CLAW_DBF_TEXT(2, setup, "init_dev"); |
| 2896 | CLAW_DBF_TEXT_(2, setup, "%s", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | dev->mtu = CLAW_DEFAULT_MTU_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | dev->hard_header_len = 0; |
| 2899 | dev->addr_len = 0; |
| 2900 | dev->type = ARPHRD_SLIP; |
| 2901 | dev->tx_queue_len = 1300; |
| 2902 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
Frank Blaschka | 2171dc1 | 2009-01-09 03:43:59 +0000 | [diff] [blame] | 2903 | dev->netdev_ops = &claw_netdev_ops; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2904 | CLAW_DBF_TEXT(2, setup, "initok"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | return; |
| 2906 | } |
| 2907 | |
| 2908 | /** |
| 2909 | * Init a new channel in the privptr->channel[i]. |
| 2910 | * |
| 2911 | * @param cdev The ccw_device to be added. |
| 2912 | * |
| 2913 | * @return 0 on success, !0 on error. |
| 2914 | */ |
| 2915 | static int |
| 2916 | add_channel(struct ccw_device *cdev,int i,struct claw_privbk *privptr) |
| 2917 | { |
| 2918 | struct chbk *p_ch; |
Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2919 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2920 | |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2921 | CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cdev->dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2922 | privptr->channel[i].flag = i+1; /* Read is 1 Write is 2 */ |
| 2923 | p_ch = &privptr->channel[i]; |
| 2924 | p_ch->cdev = cdev; |
Kay Sievers | 2a0217d | 2008-10-10 21:33:09 +0200 | [diff] [blame] | 2925 | snprintf(p_ch->id, CLAW_ID_SIZE, "cl-%s", dev_name(&cdev->dev)); |
Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2926 | ccw_device_get_id(cdev, &dev_id); |
| 2927 | p_ch->devno = dev_id.devno; |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2928 | if ((p_ch->irb = kzalloc(sizeof (struct irb),GFP_KERNEL)) == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | return -ENOMEM; |
| 2930 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | return 0; |
| 2932 | } |
| 2933 | |
| 2934 | |
| 2935 | /** |
| 2936 | * |
| 2937 | * Setup an interface. |
| 2938 | * |
| 2939 | * @param cgdev Device to be setup. |
| 2940 | * |
| 2941 | * @returns 0 on success, !0 on failure. |
| 2942 | */ |
| 2943 | static int |
| 2944 | claw_new_device(struct ccwgroup_device *cgdev) |
| 2945 | { |
| 2946 | struct claw_privbk *privptr; |
| 2947 | struct claw_env *p_env; |
| 2948 | struct net_device *dev; |
| 2949 | int ret; |
Cornelia Huck | dc5bc0c | 2007-06-20 13:00:20 +0200 | [diff] [blame] | 2950 | struct ccw_dev_id dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2952 | dev_info(&cgdev->dev, "add for %s\n", |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2953 | dev_name(&cgdev->cdev[READ_CHANNEL]->dev)); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2954 | CLAW_DBF_TEXT(2, setup, "new_dev"); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2955 | privptr = dev_get_drvdata(&cgdev->dev); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2956 | dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr); |
| 2957 | dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2958 | if (!privptr) |
| 2959 | return -ENODEV; |
| 2960 | p_env = privptr->p_env; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2961 | ccw_device_get_id(cgdev->cdev[READ_CHANNEL], &dev_id); |
| 2962 | p_env->devno[READ_CHANNEL] = dev_id.devno; |
| 2963 | ccw_device_get_id(cgdev->cdev[WRITE_CHANNEL], &dev_id); |
| 2964 | p_env->devno[WRITE_CHANNEL] = dev_id.devno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | ret = add_channel(cgdev->cdev[0],0,privptr); |
| 2966 | if (ret == 0) |
| 2967 | ret = add_channel(cgdev->cdev[1],1,privptr); |
| 2968 | if (ret != 0) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2969 | dev_warn(&cgdev->dev, "Creating a CLAW group device" |
| 2970 | " failed with error code %d\n", ret); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 2971 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | } |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2973 | ret = ccw_device_set_online(cgdev->cdev[READ_CHANNEL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2974 | if (ret != 0) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2975 | dev_warn(&cgdev->dev, |
| 2976 | "Setting the read subchannel online" |
| 2977 | " failed with error code %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | goto out; |
| 2979 | } |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2980 | ret = ccw_device_set_online(cgdev->cdev[WRITE_CHANNEL]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | if (ret != 0) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2982 | dev_warn(&cgdev->dev, |
| 2983 | "Setting the write subchannel online " |
| 2984 | "failed with error code %d\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | goto out; |
| 2986 | } |
| 2987 | dev = alloc_netdev(0,"claw%d",claw_init_netdevice); |
| 2988 | if (!dev) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 2989 | dev_warn(&cgdev->dev, |
| 2990 | "Activating the CLAW device failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | goto out; |
| 2992 | } |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 2993 | dev->ml_priv = privptr; |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2994 | dev_set_drvdata(&cgdev->dev, privptr); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 2995 | dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, privptr); |
| 2996 | dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, privptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2997 | /* sysfs magic */ |
| 2998 | SET_NETDEV_DEV(dev, &cgdev->dev); |
| 2999 | if (register_netdev(dev) != 0) { |
| 3000 | claw_free_netdevice(dev, 1); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3001 | CLAW_DBF_TEXT(2, trace, "regfail"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3002 | goto out; |
| 3003 | } |
| 3004 | dev->flags &=~IFF_RUNNING; |
| 3005 | if (privptr->buffs_alloc == 0) { |
| 3006 | ret=init_ccw_bk(dev); |
| 3007 | if (ret !=0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | unregister_netdev(dev); |
| 3009 | claw_free_netdevice(dev,1); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3010 | CLAW_DBF_TEXT(2, trace, "ccwmem"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | goto out; |
| 3012 | } |
| 3013 | } |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3014 | privptr->channel[READ_CHANNEL].ndev = dev; |
| 3015 | privptr->channel[WRITE_CHANNEL].ndev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | privptr->p_env->ndev = dev; |
| 3017 | |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3018 | dev_info(&cgdev->dev, "%s:readsize=%d writesize=%d " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | "readbuffer=%d writebuffer=%d read=0x%04x write=0x%04x\n", |
| 3020 | dev->name, p_env->read_size, |
| 3021 | p_env->write_size, p_env->read_buffers, |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3022 | p_env->write_buffers, p_env->devno[READ_CHANNEL], |
| 3023 | p_env->devno[WRITE_CHANNEL]); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3024 | dev_info(&cgdev->dev, "%s:host_name:%.8s, adapter_name " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | ":%.8s api_type: %.8s\n", |
| 3026 | dev->name, p_env->host_name, |
| 3027 | p_env->adapter_name , p_env->api_type); |
| 3028 | return 0; |
| 3029 | out: |
| 3030 | ccw_device_set_offline(cgdev->cdev[1]); |
| 3031 | ccw_device_set_offline(cgdev->cdev[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | return -ENODEV; |
| 3033 | } |
| 3034 | |
| 3035 | static void |
| 3036 | claw_purge_skb_queue(struct sk_buff_head *q) |
| 3037 | { |
| 3038 | struct sk_buff *skb; |
| 3039 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3040 | CLAW_DBF_TEXT(4, trace, "purgque"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | while ((skb = skb_dequeue(q))) { |
| 3042 | atomic_dec(&skb->users); |
Frank Pavlic | 8e84c80 | 2005-09-06 15:03:09 +0200 | [diff] [blame] | 3043 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | /** |
| 3048 | * Shutdown an interface. |
| 3049 | * |
| 3050 | * @param cgdev Device to be shut down. |
| 3051 | * |
| 3052 | * @returns 0 on success, !0 on failure. |
| 3053 | */ |
| 3054 | static int |
| 3055 | claw_shutdown_device(struct ccwgroup_device *cgdev) |
| 3056 | { |
| 3057 | struct claw_privbk *priv; |
| 3058 | struct net_device *ndev; |
Heiko Carstens | 38ed18f | 2011-05-12 18:45:04 +0000 | [diff] [blame] | 3059 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 3061 | CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev)); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3062 | priv = dev_get_drvdata(&cgdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3063 | if (!priv) |
| 3064 | return -ENODEV; |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3065 | ndev = priv->channel[READ_CHANNEL].ndev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | if (ndev) { |
| 3067 | /* Close the device */ |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3068 | dev_info(&cgdev->dev, "%s: shutting down\n", |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3069 | ndev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | if (ndev->flags & IFF_RUNNING) |
| 3071 | ret = claw_release(ndev); |
| 3072 | ndev->flags &=~IFF_RUNNING; |
| 3073 | unregister_netdev(ndev); |
Peter Tiedemann | 6951df3 | 2008-08-21 17:10:23 +0200 | [diff] [blame] | 3074 | ndev->ml_priv = NULL; /* cgdev data, not ndev's to free */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | claw_free_netdevice(ndev, 1); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3076 | priv->channel[READ_CHANNEL].ndev = NULL; |
| 3077 | priv->channel[WRITE_CHANNEL].ndev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | priv->p_env->ndev = NULL; |
| 3079 | } |
| 3080 | ccw_device_set_offline(cgdev->cdev[1]); |
| 3081 | ccw_device_set_offline(cgdev->cdev[0]); |
Heiko Carstens | 38ed18f | 2011-05-12 18:45:04 +0000 | [diff] [blame] | 3082 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | static void |
| 3086 | claw_remove_device(struct ccwgroup_device *cgdev) |
| 3087 | { |
| 3088 | struct claw_privbk *priv; |
| 3089 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3090 | BUG_ON(!cgdev); |
Cornelia Huck | b9d3aed | 2008-10-10 21:33:11 +0200 | [diff] [blame] | 3091 | CLAW_DBF_TEXT_(2, setup, "%s", dev_name(&cgdev->dev)); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3092 | priv = dev_get_drvdata(&cgdev->dev); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3093 | BUG_ON(!priv); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3094 | dev_info(&cgdev->dev, " will be removed.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | if (cgdev->state == CCWGROUP_ONLINE) |
| 3096 | claw_shutdown_device(cgdev); |
| 3097 | claw_remove_files(&cgdev->dev); |
Jesper Juhl | 17fd682 | 2005-11-07 01:01:30 -0800 | [diff] [blame] | 3098 | kfree(priv->p_mtc_envelope); |
| 3099 | priv->p_mtc_envelope=NULL; |
| 3100 | kfree(priv->p_env); |
| 3101 | priv->p_env=NULL; |
| 3102 | kfree(priv->channel[0].irb); |
| 3103 | priv->channel[0].irb=NULL; |
| 3104 | kfree(priv->channel[1].irb); |
| 3105 | priv->channel[1].irb=NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | kfree(priv); |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3107 | dev_set_drvdata(&cgdev->dev, NULL); |
Heiko Carstens | 319cb08 | 2010-08-12 01:58:27 +0000 | [diff] [blame] | 3108 | dev_set_drvdata(&cgdev->cdev[READ_CHANNEL]->dev, NULL); |
| 3109 | dev_set_drvdata(&cgdev->cdev[WRITE_CHANNEL]->dev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3110 | put_device(&cgdev->dev); |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3111 | |
| 3112 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | } |
| 3114 | |
| 3115 | |
| 3116 | /* |
| 3117 | * sysfs attributes |
| 3118 | */ |
| 3119 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3120 | claw_hname_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | { |
| 3122 | struct claw_privbk *priv; |
| 3123 | struct claw_env * p_env; |
| 3124 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3125 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | if (!priv) |
| 3127 | return -ENODEV; |
| 3128 | p_env = priv->p_env; |
| 3129 | return sprintf(buf, "%s\n",p_env->host_name); |
| 3130 | } |
| 3131 | |
| 3132 | static ssize_t |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3133 | claw_hname_write(struct device *dev, struct device_attribute *attr, |
| 3134 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3135 | { |
| 3136 | struct claw_privbk *priv; |
| 3137 | struct claw_env * p_env; |
| 3138 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3139 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | if (!priv) |
| 3141 | return -ENODEV; |
| 3142 | p_env = priv->p_env; |
| 3143 | if (count > MAX_NAME_LEN+1) |
| 3144 | return -EINVAL; |
| 3145 | memset(p_env->host_name, 0x20, MAX_NAME_LEN); |
| 3146 | strncpy(p_env->host_name,buf, count); |
| 3147 | p_env->host_name[count-1] = 0x20; /* clear extra 0x0a */ |
| 3148 | p_env->host_name[MAX_NAME_LEN] = 0x00; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3149 | CLAW_DBF_TEXT(2, setup, "HstnSet"); |
| 3150 | CLAW_DBF_TEXT_(2, setup, "%s", p_env->host_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | |
| 3152 | return count; |
| 3153 | } |
| 3154 | |
| 3155 | static DEVICE_ATTR(host_name, 0644, claw_hname_show, claw_hname_write); |
| 3156 | |
| 3157 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3158 | claw_adname_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | { |
| 3160 | struct claw_privbk *priv; |
| 3161 | struct claw_env * p_env; |
| 3162 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3163 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3164 | if (!priv) |
| 3165 | return -ENODEV; |
| 3166 | p_env = priv->p_env; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3167 | return sprintf(buf, "%s\n", p_env->adapter_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | static ssize_t |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3171 | claw_adname_write(struct device *dev, struct device_attribute *attr, |
| 3172 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | { |
| 3174 | struct claw_privbk *priv; |
| 3175 | struct claw_env * p_env; |
| 3176 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3177 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | if (!priv) |
| 3179 | return -ENODEV; |
| 3180 | p_env = priv->p_env; |
| 3181 | if (count > MAX_NAME_LEN+1) |
| 3182 | return -EINVAL; |
| 3183 | memset(p_env->adapter_name, 0x20, MAX_NAME_LEN); |
| 3184 | strncpy(p_env->adapter_name,buf, count); |
| 3185 | p_env->adapter_name[count-1] = 0x20; /* clear extra 0x0a */ |
| 3186 | p_env->adapter_name[MAX_NAME_LEN] = 0x00; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3187 | CLAW_DBF_TEXT(2, setup, "AdnSet"); |
| 3188 | CLAW_DBF_TEXT_(2, setup, "%s", p_env->adapter_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3189 | |
| 3190 | return count; |
| 3191 | } |
| 3192 | |
| 3193 | static DEVICE_ATTR(adapter_name, 0644, claw_adname_show, claw_adname_write); |
| 3194 | |
| 3195 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3196 | claw_apname_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3197 | { |
| 3198 | struct claw_privbk *priv; |
| 3199 | struct claw_env * p_env; |
| 3200 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3201 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | if (!priv) |
| 3203 | return -ENODEV; |
| 3204 | p_env = priv->p_env; |
| 3205 | return sprintf(buf, "%s\n", |
| 3206 | p_env->api_type); |
| 3207 | } |
| 3208 | |
| 3209 | static ssize_t |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3210 | claw_apname_write(struct device *dev, struct device_attribute *attr, |
| 3211 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | { |
| 3213 | struct claw_privbk *priv; |
| 3214 | struct claw_env * p_env; |
| 3215 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3216 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | if (!priv) |
| 3218 | return -ENODEV; |
| 3219 | p_env = priv->p_env; |
| 3220 | if (count > MAX_NAME_LEN+1) |
| 3221 | return -EINVAL; |
| 3222 | memset(p_env->api_type, 0x20, MAX_NAME_LEN); |
| 3223 | strncpy(p_env->api_type,buf, count); |
| 3224 | p_env->api_type[count-1] = 0x20; /* we get a loose 0x0a */ |
| 3225 | p_env->api_type[MAX_NAME_LEN] = 0x00; |
| 3226 | if(strncmp(p_env->api_type,WS_APPL_NAME_PACKED,6) == 0) { |
| 3227 | p_env->read_size=DEF_PACK_BUFSIZE; |
| 3228 | p_env->write_size=DEF_PACK_BUFSIZE; |
| 3229 | p_env->packing=PACKING_ASK; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3230 | CLAW_DBF_TEXT(2, setup, "PACKING"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3231 | } |
| 3232 | else { |
| 3233 | p_env->packing=0; |
| 3234 | p_env->read_size=CLAW_FRAME_SIZE; |
| 3235 | p_env->write_size=CLAW_FRAME_SIZE; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3236 | CLAW_DBF_TEXT(2, setup, "ApiSet"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3238 | CLAW_DBF_TEXT_(2, setup, "%s", p_env->api_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | return count; |
| 3240 | } |
| 3241 | |
| 3242 | static DEVICE_ATTR(api_type, 0644, claw_apname_show, claw_apname_write); |
| 3243 | |
| 3244 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3245 | claw_wbuff_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | { |
| 3247 | struct claw_privbk *priv; |
| 3248 | struct claw_env * p_env; |
| 3249 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3250 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | if (!priv) |
| 3252 | return -ENODEV; |
| 3253 | p_env = priv->p_env; |
| 3254 | return sprintf(buf, "%d\n", p_env->write_buffers); |
| 3255 | } |
| 3256 | |
| 3257 | static ssize_t |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3258 | claw_wbuff_write(struct device *dev, struct device_attribute *attr, |
| 3259 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | { |
| 3261 | struct claw_privbk *priv; |
| 3262 | struct claw_env * p_env; |
| 3263 | int nnn,max; |
| 3264 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3265 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | if (!priv) |
| 3267 | return -ENODEV; |
| 3268 | p_env = priv->p_env; |
| 3269 | sscanf(buf, "%i", &nnn); |
| 3270 | if (p_env->packing) { |
| 3271 | max = 64; |
| 3272 | } |
| 3273 | else { |
| 3274 | max = 512; |
| 3275 | } |
| 3276 | if ((nnn > max ) || (nnn < 2)) |
| 3277 | return -EINVAL; |
| 3278 | p_env->write_buffers = nnn; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3279 | CLAW_DBF_TEXT(2, setup, "Wbufset"); |
| 3280 | CLAW_DBF_TEXT_(2, setup, "WB=%d", p_env->write_buffers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | return count; |
| 3282 | } |
| 3283 | |
| 3284 | static DEVICE_ATTR(write_buffer, 0644, claw_wbuff_show, claw_wbuff_write); |
| 3285 | |
| 3286 | static ssize_t |
Yani Ioannou | 3fd3c0a | 2005-05-17 06:43:27 -0400 | [diff] [blame] | 3287 | claw_rbuff_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | { |
| 3289 | struct claw_privbk *priv; |
| 3290 | struct claw_env * p_env; |
| 3291 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3292 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | if (!priv) |
| 3294 | return -ENODEV; |
| 3295 | p_env = priv->p_env; |
| 3296 | return sprintf(buf, "%d\n", p_env->read_buffers); |
| 3297 | } |
| 3298 | |
| 3299 | static ssize_t |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3300 | claw_rbuff_write(struct device *dev, struct device_attribute *attr, |
| 3301 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | { |
| 3303 | struct claw_privbk *priv; |
| 3304 | struct claw_env *p_env; |
| 3305 | int nnn,max; |
| 3306 | |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 3307 | priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3308 | if (!priv) |
| 3309 | return -ENODEV; |
| 3310 | p_env = priv->p_env; |
| 3311 | sscanf(buf, "%i", &nnn); |
| 3312 | if (p_env->packing) { |
| 3313 | max = 64; |
| 3314 | } |
| 3315 | else { |
| 3316 | max = 512; |
| 3317 | } |
| 3318 | if ((nnn > max ) || (nnn < 2)) |
| 3319 | return -EINVAL; |
| 3320 | p_env->read_buffers = nnn; |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3321 | CLAW_DBF_TEXT(2, setup, "Rbufset"); |
| 3322 | CLAW_DBF_TEXT_(2, setup, "RB=%d", p_env->read_buffers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | return count; |
| 3324 | } |
| 3325 | |
| 3326 | static DEVICE_ATTR(read_buffer, 0644, claw_rbuff_show, claw_rbuff_write); |
| 3327 | |
| 3328 | static struct attribute *claw_attr[] = { |
| 3329 | &dev_attr_read_buffer.attr, |
| 3330 | &dev_attr_write_buffer.attr, |
| 3331 | &dev_attr_adapter_name.attr, |
| 3332 | &dev_attr_api_type.attr, |
| 3333 | &dev_attr_host_name.attr, |
| 3334 | NULL, |
| 3335 | }; |
| 3336 | |
| 3337 | static struct attribute_group claw_attr_group = { |
| 3338 | .attrs = claw_attr, |
| 3339 | }; |
| 3340 | |
| 3341 | static int |
| 3342 | claw_add_files(struct device *dev) |
| 3343 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3344 | CLAW_DBF_TEXT(2, setup, "add_file"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | return sysfs_create_group(&dev->kobj, &claw_attr_group); |
| 3346 | } |
| 3347 | |
| 3348 | static void |
| 3349 | claw_remove_files(struct device *dev) |
| 3350 | { |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3351 | CLAW_DBF_TEXT(2, setup, "rem_file"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3352 | sysfs_remove_group(&dev->kobj, &claw_attr_group); |
| 3353 | } |
| 3354 | |
| 3355 | /*--------------------------------------------------------------------* |
| 3356 | * claw_init and cleanup * |
| 3357 | *---------------------------------------------------------------------*/ |
| 3358 | |
| 3359 | static void __exit |
| 3360 | claw_cleanup(void) |
| 3361 | { |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3362 | driver_remove_file(&claw_group_driver.driver, |
| 3363 | &driver_attr_group); |
| 3364 | ccwgroup_driver_unregister(&claw_group_driver); |
| 3365 | ccw_driver_unregister(&claw_ccw_driver); |
| 3366 | root_device_unregister(claw_root_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | claw_unregister_debug_facility(); |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3368 | pr_info("Driver unloaded\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | |
| 3370 | } |
| 3371 | |
| 3372 | /** |
| 3373 | * Initialize module. |
| 3374 | * This is called just after the module is loaded. |
| 3375 | * |
| 3376 | * @return 0 on success, !0 on error. |
| 3377 | */ |
| 3378 | static int __init |
| 3379 | claw_init(void) |
| 3380 | { |
| 3381 | int ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3383 | pr_info("Loading %s\n", version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | ret = claw_register_debug_facility(); |
| 3385 | if (ret) { |
Andy Richter | 4811fcb | 2009-01-20 06:14:33 +0000 | [diff] [blame] | 3386 | pr_err("Registering with the S/390 debug feature" |
| 3387 | " failed with error code %d\n", ret); |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3388 | goto out_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3389 | } |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3390 | CLAW_DBF_TEXT(2, setup, "init_mod"); |
Ursula Braun | d950d17 | 2010-01-04 03:14:45 +0000 | [diff] [blame] | 3391 | claw_root_dev = root_device_register("claw"); |
Ursula Braun | 0ca8cc6 | 2009-11-12 21:46:29 +0000 | [diff] [blame] | 3392 | ret = IS_ERR(claw_root_dev) ? PTR_ERR(claw_root_dev) : 0; |
| 3393 | if (ret) |
| 3394 | goto register_err; |
| 3395 | ret = ccw_driver_register(&claw_ccw_driver); |
| 3396 | if (ret) |
| 3397 | goto ccw_err; |
| 3398 | claw_group_driver.driver.groups = claw_group_attr_groups; |
| 3399 | ret = ccwgroup_driver_register(&claw_group_driver); |
| 3400 | if (ret) |
| 3401 | goto ccwgroup_err; |
| 3402 | return 0; |
| 3403 | |
| 3404 | ccwgroup_err: |
| 3405 | ccw_driver_unregister(&claw_ccw_driver); |
| 3406 | ccw_err: |
| 3407 | root_device_unregister(claw_root_dev); |
| 3408 | register_err: |
| 3409 | CLAW_DBF_TEXT(2, setup, "init_bad"); |
| 3410 | claw_unregister_debug_facility(); |
| 3411 | out_err: |
| 3412 | pr_err("Initializing the claw device driver failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | return ret; |
| 3414 | } |
| 3415 | |
| 3416 | module_init(claw_init); |
| 3417 | module_exit(claw_cleanup); |
| 3418 | |
Andy Richter | b805da7 | 2008-07-18 15:24:56 +0200 | [diff] [blame] | 3419 | MODULE_AUTHOR("Andy Richter <richtera@us.ibm.com>"); |
| 3420 | MODULE_DESCRIPTION("Linux for System z CLAW Driver\n" \ |
| 3421 | "Copyright 2000,2008 IBM Corporation\n"); |
| 3422 | MODULE_LICENSE("GPL"); |