Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * IUCV network driver |
| 3 | * |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 4 | * Copyright IBM Corp. 2001, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 6 | * Author(s): |
| 7 | * Original netiucv driver: |
| 8 | * Fritz Elfert (elfert@de.ibm.com, felfert@millenux.com) |
| 9 | * Sysfs integration and all bugs therein: |
| 10 | * Cornelia Huck (cornelia.huck@de.ibm.com) |
| 11 | * PM functions: |
| 12 | * Ursula Braun (ursula.braun@de.ibm.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * Documentation used: |
| 15 | * the source of the original IUCV driver by: |
| 16 | * Stefan Hegewald <hegewald@de.ibm.com> |
| 17 | * Hartmut Penner <hpenner@de.ibm.com> |
| 18 | * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
| 19 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 20 | * Alan Altmark (Alan_Altmark@us.ibm.com) Sept. 2000 |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2, or (at your option) |
| 25 | * any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 37 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 38 | #define KMSG_COMPONENT "netiucv" |
| 39 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #undef DEBUG |
| 42 | |
| 43 | #include <linux/module.h> |
| 44 | #include <linux/init.h> |
| 45 | #include <linux/kernel.h> |
| 46 | #include <linux/slab.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/interrupt.h> |
| 50 | #include <linux/timer.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/bitops.h> |
| 52 | |
| 53 | #include <linux/signal.h> |
| 54 | #include <linux/string.h> |
| 55 | #include <linux/device.h> |
| 56 | |
| 57 | #include <linux/ip.h> |
| 58 | #include <linux/if_arp.h> |
| 59 | #include <linux/tcp.h> |
| 60 | #include <linux/skbuff.h> |
| 61 | #include <linux/ctype.h> |
| 62 | #include <net/dst.h> |
| 63 | |
| 64 | #include <asm/io.h> |
| 65 | #include <asm/uaccess.h> |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 66 | #include <asm/ebcdic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 68 | #include <net/iucv/iucv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #include "fsm.h" |
| 70 | |
| 71 | MODULE_AUTHOR |
| 72 | ("(C) 2001 IBM Corporation by Fritz Elfert (felfert@millenux.com)"); |
| 73 | MODULE_DESCRIPTION ("Linux for S/390 IUCV network driver"); |
| 74 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 75 | /** |
| 76 | * Debug Facility stuff |
| 77 | */ |
| 78 | #define IUCV_DBF_SETUP_NAME "iucv_setup" |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 79 | #define IUCV_DBF_SETUP_LEN 64 |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 80 | #define IUCV_DBF_SETUP_PAGES 2 |
| 81 | #define IUCV_DBF_SETUP_NR_AREAS 1 |
| 82 | #define IUCV_DBF_SETUP_LEVEL 3 |
| 83 | |
| 84 | #define IUCV_DBF_DATA_NAME "iucv_data" |
| 85 | #define IUCV_DBF_DATA_LEN 128 |
| 86 | #define IUCV_DBF_DATA_PAGES 2 |
| 87 | #define IUCV_DBF_DATA_NR_AREAS 1 |
| 88 | #define IUCV_DBF_DATA_LEVEL 2 |
| 89 | |
| 90 | #define IUCV_DBF_TRACE_NAME "iucv_trace" |
| 91 | #define IUCV_DBF_TRACE_LEN 16 |
| 92 | #define IUCV_DBF_TRACE_PAGES 4 |
| 93 | #define IUCV_DBF_TRACE_NR_AREAS 1 |
| 94 | #define IUCV_DBF_TRACE_LEVEL 3 |
| 95 | |
| 96 | #define IUCV_DBF_TEXT(name,level,text) \ |
| 97 | do { \ |
| 98 | debug_text_event(iucv_dbf_##name,level,text); \ |
| 99 | } while (0) |
| 100 | |
| 101 | #define IUCV_DBF_HEX(name,level,addr,len) \ |
| 102 | do { \ |
| 103 | debug_event(iucv_dbf_##name,level,(void*)(addr),len); \ |
| 104 | } while (0) |
| 105 | |
| 106 | DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf); |
| 107 | |
Peter Tiedemann | f33780d | 2008-02-08 13:09:05 +0100 | [diff] [blame] | 108 | /* Allow to sort out low debug levels early to avoid wasted sprints */ |
| 109 | static inline int iucv_dbf_passes(debug_info_t *dbf_grp, int level) |
| 110 | { |
| 111 | return (level <= dbf_grp->level); |
| 112 | } |
| 113 | |
| 114 | #define IUCV_DBF_TEXT_(name, level, text...) \ |
| 115 | do { \ |
| 116 | if (iucv_dbf_passes(iucv_dbf_##name, level)) { \ |
Tejun Heo | 390dfd9 | 2009-10-29 22:34:14 +0900 | [diff] [blame] | 117 | char* __buf = get_cpu_var(iucv_dbf_txt_buf); \ |
| 118 | sprintf(__buf, text); \ |
| 119 | debug_text_event(iucv_dbf_##name, level, __buf); \ |
Peter Tiedemann | f33780d | 2008-02-08 13:09:05 +0100 | [diff] [blame] | 120 | put_cpu_var(iucv_dbf_txt_buf); \ |
| 121 | } \ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 122 | } while (0) |
| 123 | |
| 124 | #define IUCV_DBF_SPRINTF(name,level,text...) \ |
| 125 | do { \ |
| 126 | debug_sprintf_event(iucv_dbf_trace, level, ##text ); \ |
| 127 | debug_sprintf_event(iucv_dbf_trace, level, text ); \ |
| 128 | } while (0) |
| 129 | |
| 130 | /** |
| 131 | * some more debug stuff |
| 132 | */ |
| 133 | #define IUCV_HEXDUMP16(importance,header,ptr) \ |
| 134 | PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \ |
| 135 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", \ |
| 136 | *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \ |
| 137 | *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \ |
| 138 | *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \ |
| 139 | *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \ |
| 140 | *(((char*)ptr)+12),*(((char*)ptr)+13), \ |
| 141 | *(((char*)ptr)+14),*(((char*)ptr)+15)); \ |
| 142 | PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \ |
| 143 | "%02x %02x %02x %02x %02x %02x %02x %02x\n", \ |
| 144 | *(((char*)ptr)+16),*(((char*)ptr)+17), \ |
| 145 | *(((char*)ptr)+18),*(((char*)ptr)+19), \ |
| 146 | *(((char*)ptr)+20),*(((char*)ptr)+21), \ |
| 147 | *(((char*)ptr)+22),*(((char*)ptr)+23), \ |
| 148 | *(((char*)ptr)+24),*(((char*)ptr)+25), \ |
| 149 | *(((char*)ptr)+26),*(((char*)ptr)+27), \ |
| 150 | *(((char*)ptr)+28),*(((char*)ptr)+29), \ |
| 151 | *(((char*)ptr)+30),*(((char*)ptr)+31)); |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #define PRINTK_HEADER " iucv: " /* for debugging */ |
| 154 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 155 | /* dummy device to make sure netiucv_pm functions are called */ |
| 156 | static struct device *netiucv_dev; |
| 157 | |
| 158 | static int netiucv_pm_prepare(struct device *); |
| 159 | static void netiucv_pm_complete(struct device *); |
| 160 | static int netiucv_pm_freeze(struct device *); |
| 161 | static int netiucv_pm_restore_thaw(struct device *); |
| 162 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 163 | static const struct dev_pm_ops netiucv_pm_ops = { |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 164 | .prepare = netiucv_pm_prepare, |
| 165 | .complete = netiucv_pm_complete, |
| 166 | .freeze = netiucv_pm_freeze, |
| 167 | .thaw = netiucv_pm_restore_thaw, |
| 168 | .restore = netiucv_pm_restore_thaw, |
| 169 | }; |
| 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | static struct device_driver netiucv_driver = { |
Cornelia Huck | 2219510 | 2008-02-08 13:09:02 +0100 | [diff] [blame] | 172 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | .name = "netiucv", |
| 174 | .bus = &iucv_bus, |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 175 | .pm = &netiucv_pm_ops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | }; |
| 177 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 178 | static int netiucv_callback_connreq(struct iucv_path *, |
| 179 | u8 ipvmid[8], u8 ipuser[16]); |
| 180 | static void netiucv_callback_connack(struct iucv_path *, u8 ipuser[16]); |
| 181 | static void netiucv_callback_connrej(struct iucv_path *, u8 ipuser[16]); |
| 182 | static void netiucv_callback_connsusp(struct iucv_path *, u8 ipuser[16]); |
| 183 | static void netiucv_callback_connres(struct iucv_path *, u8 ipuser[16]); |
| 184 | static void netiucv_callback_rx(struct iucv_path *, struct iucv_message *); |
| 185 | static void netiucv_callback_txdone(struct iucv_path *, struct iucv_message *); |
| 186 | |
| 187 | static struct iucv_handler netiucv_handler = { |
| 188 | .path_pending = netiucv_callback_connreq, |
| 189 | .path_complete = netiucv_callback_connack, |
| 190 | .path_severed = netiucv_callback_connrej, |
| 191 | .path_quiesced = netiucv_callback_connsusp, |
| 192 | .path_resumed = netiucv_callback_connres, |
| 193 | .message_pending = netiucv_callback_rx, |
| 194 | .message_complete = netiucv_callback_txdone |
| 195 | }; |
| 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | /** |
| 198 | * Per connection profiling data |
| 199 | */ |
| 200 | struct connection_profile { |
| 201 | unsigned long maxmulti; |
| 202 | unsigned long maxcqueue; |
| 203 | unsigned long doios_single; |
| 204 | unsigned long doios_multi; |
| 205 | unsigned long txlen; |
| 206 | unsigned long tx_time; |
| 207 | struct timespec send_stamp; |
| 208 | unsigned long tx_pending; |
| 209 | unsigned long tx_max_pending; |
| 210 | }; |
| 211 | |
| 212 | /** |
| 213 | * Representation of one iucv connection |
| 214 | */ |
| 215 | struct iucv_connection { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 216 | struct list_head list; |
| 217 | struct iucv_path *path; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | struct sk_buff *rx_buff; |
| 219 | struct sk_buff *tx_buff; |
| 220 | struct sk_buff_head collect_queue; |
| 221 | struct sk_buff_head commit_queue; |
| 222 | spinlock_t collect_lock; |
| 223 | int collect_len; |
| 224 | int max_buffsize; |
| 225 | fsm_timer timer; |
| 226 | fsm_instance *fsm; |
| 227 | struct net_device *netdev; |
| 228 | struct connection_profile prof; |
| 229 | char userid[9]; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 230 | char userdata[17]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | /** |
| 234 | * Linked list of all connection structs. |
| 235 | */ |
Denis Cheng | c11ca97 | 2008-01-26 14:11:13 +0100 | [diff] [blame] | 236 | static LIST_HEAD(iucv_connection_list); |
Thomas Gleixner | bfac0d0 | 2007-06-20 13:02:55 +0200 | [diff] [blame] | 237 | static DEFINE_RWLOCK(iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
| 239 | /** |
| 240 | * Representation of event-data for the |
| 241 | * connection state machine. |
| 242 | */ |
| 243 | struct iucv_event { |
| 244 | struct iucv_connection *conn; |
| 245 | void *data; |
| 246 | }; |
| 247 | |
| 248 | /** |
| 249 | * Private part of the network device structure |
| 250 | */ |
| 251 | struct netiucv_priv { |
| 252 | struct net_device_stats stats; |
| 253 | unsigned long tbusy; |
| 254 | fsm_instance *fsm; |
| 255 | struct iucv_connection *conn; |
| 256 | struct device *dev; |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 257 | int pm_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | /** |
| 261 | * Link level header for a packet. |
| 262 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 263 | struct ll_header { |
| 264 | u16 next; |
| 265 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 267 | #define NETIUCV_HDRLEN (sizeof(struct ll_header)) |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 268 | #define NETIUCV_BUFSIZE_MAX 65537 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX |
| 270 | #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN) |
| 271 | #define NETIUCV_MTU_DEFAULT 9216 |
| 272 | #define NETIUCV_QUEUELEN_DEFAULT 50 |
| 273 | #define NETIUCV_TIMEOUT_5SEC 5000 |
| 274 | |
| 275 | /** |
| 276 | * Compatibility macros for busy handling |
| 277 | * of network devices. |
| 278 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 279 | static inline void netiucv_clear_busy(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 281 | struct netiucv_priv *priv = netdev_priv(dev); |
| 282 | clear_bit(0, &priv->tbusy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | netif_wake_queue(dev); |
| 284 | } |
| 285 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 286 | static inline int netiucv_test_and_set_busy(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 288 | struct netiucv_priv *priv = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | netif_stop_queue(dev); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 290 | return test_and_set_bit(0, &priv->tbusy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 293 | static u8 iucvMagic_ascii[16] = { |
| 294 | 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 295 | 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 |
| 296 | }; |
| 297 | |
| 298 | static u8 iucvMagic_ebcdic[16] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, |
| 300 | 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40 |
| 301 | }; |
| 302 | |
| 303 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | * Convert an iucv userId to its printable |
| 305 | * form (strip whitespace at end). |
| 306 | * |
| 307 | * @param An iucv userId |
| 308 | * |
| 309 | * @returns The printable string (static data!!) |
| 310 | */ |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 311 | static char *netiucv_printname(char *name, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 313 | static char tmp[17]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | char *p = tmp; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 315 | memcpy(tmp, name, len); |
| 316 | tmp[len] = '\0'; |
| 317 | while (*p && ((p - tmp) < len) && (!isspace(*p))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | p++; |
| 319 | *p = '\0'; |
| 320 | return tmp; |
| 321 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 322 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 323 | static char *netiucv_printuser(struct iucv_connection *conn) |
| 324 | { |
| 325 | static char tmp_uid[9]; |
| 326 | static char tmp_udat[17]; |
| 327 | static char buf[100]; |
| 328 | |
| 329 | if (memcmp(conn->userdata, iucvMagic_ebcdic, 16)) { |
| 330 | tmp_uid[8] = '\0'; |
| 331 | tmp_udat[16] = '\0'; |
| 332 | memcpy(tmp_uid, conn->userid, 8); |
| 333 | memcpy(tmp_uid, netiucv_printname(tmp_uid, 8), 8); |
| 334 | memcpy(tmp_udat, conn->userdata, 16); |
| 335 | EBCASC(tmp_udat, 16); |
| 336 | memcpy(tmp_udat, netiucv_printname(tmp_udat, 16), 16); |
| 337 | sprintf(buf, "%s.%s", tmp_uid, tmp_udat); |
| 338 | return buf; |
| 339 | } else |
| 340 | return netiucv_printname(conn->userid, 8); |
| 341 | } |
| 342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /** |
| 344 | * States of the interface statemachine. |
| 345 | */ |
| 346 | enum dev_states { |
| 347 | DEV_STATE_STOPPED, |
| 348 | DEV_STATE_STARTWAIT, |
| 349 | DEV_STATE_STOPWAIT, |
| 350 | DEV_STATE_RUNNING, |
| 351 | /** |
| 352 | * MUST be always the last element!! |
| 353 | */ |
| 354 | NR_DEV_STATES |
| 355 | }; |
| 356 | |
| 357 | static const char *dev_state_names[] = { |
| 358 | "Stopped", |
| 359 | "StartWait", |
| 360 | "StopWait", |
| 361 | "Running", |
| 362 | }; |
| 363 | |
| 364 | /** |
| 365 | * Events of the interface statemachine. |
| 366 | */ |
| 367 | enum dev_events { |
| 368 | DEV_EVENT_START, |
| 369 | DEV_EVENT_STOP, |
| 370 | DEV_EVENT_CONUP, |
| 371 | DEV_EVENT_CONDOWN, |
| 372 | /** |
| 373 | * MUST be always the last element!! |
| 374 | */ |
| 375 | NR_DEV_EVENTS |
| 376 | }; |
| 377 | |
| 378 | static const char *dev_event_names[] = { |
| 379 | "Start", |
| 380 | "Stop", |
| 381 | "Connection up", |
| 382 | "Connection down", |
| 383 | }; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /** |
| 386 | * Events of the connection statemachine |
| 387 | */ |
| 388 | enum conn_events { |
| 389 | /** |
| 390 | * Events, representing callbacks from |
| 391 | * lowlevel iucv layer) |
| 392 | */ |
| 393 | CONN_EVENT_CONN_REQ, |
| 394 | CONN_EVENT_CONN_ACK, |
| 395 | CONN_EVENT_CONN_REJ, |
| 396 | CONN_EVENT_CONN_SUS, |
| 397 | CONN_EVENT_CONN_RES, |
| 398 | CONN_EVENT_RX, |
| 399 | CONN_EVENT_TXDONE, |
| 400 | |
| 401 | /** |
| 402 | * Events, representing errors return codes from |
| 403 | * calls to lowlevel iucv layer |
| 404 | */ |
| 405 | |
| 406 | /** |
| 407 | * Event, representing timer expiry. |
| 408 | */ |
| 409 | CONN_EVENT_TIMER, |
| 410 | |
| 411 | /** |
| 412 | * Events, representing commands from upper levels. |
| 413 | */ |
| 414 | CONN_EVENT_START, |
| 415 | CONN_EVENT_STOP, |
| 416 | |
| 417 | /** |
| 418 | * MUST be always the last element!! |
| 419 | */ |
| 420 | NR_CONN_EVENTS, |
| 421 | }; |
| 422 | |
| 423 | static const char *conn_event_names[] = { |
| 424 | "Remote connection request", |
| 425 | "Remote connection acknowledge", |
| 426 | "Remote connection reject", |
| 427 | "Connection suspended", |
| 428 | "Connection resumed", |
| 429 | "Data received", |
| 430 | "Data sent", |
| 431 | |
| 432 | "Timer", |
| 433 | |
| 434 | "Start", |
| 435 | "Stop", |
| 436 | }; |
| 437 | |
| 438 | /** |
| 439 | * States of the connection statemachine. |
| 440 | */ |
| 441 | enum conn_states { |
| 442 | /** |
| 443 | * Connection not assigned to any device, |
| 444 | * initial state, invalid |
| 445 | */ |
| 446 | CONN_STATE_INVALID, |
| 447 | |
| 448 | /** |
| 449 | * Userid assigned but not operating |
| 450 | */ |
| 451 | CONN_STATE_STOPPED, |
| 452 | |
| 453 | /** |
| 454 | * Connection registered, |
| 455 | * no connection request sent yet, |
| 456 | * no connection request received |
| 457 | */ |
| 458 | CONN_STATE_STARTWAIT, |
| 459 | |
| 460 | /** |
| 461 | * Connection registered and connection request sent, |
| 462 | * no acknowledge and no connection request received yet. |
| 463 | */ |
| 464 | CONN_STATE_SETUPWAIT, |
| 465 | |
| 466 | /** |
| 467 | * Connection up and running idle |
| 468 | */ |
| 469 | CONN_STATE_IDLE, |
| 470 | |
| 471 | /** |
| 472 | * Data sent, awaiting CONN_EVENT_TXDONE |
| 473 | */ |
| 474 | CONN_STATE_TX, |
| 475 | |
| 476 | /** |
| 477 | * Error during registration. |
| 478 | */ |
| 479 | CONN_STATE_REGERR, |
| 480 | |
| 481 | /** |
| 482 | * Error during registration. |
| 483 | */ |
| 484 | CONN_STATE_CONNERR, |
| 485 | |
| 486 | /** |
| 487 | * MUST be always the last element!! |
| 488 | */ |
| 489 | NR_CONN_STATES, |
| 490 | }; |
| 491 | |
| 492 | static const char *conn_state_names[] = { |
| 493 | "Invalid", |
| 494 | "Stopped", |
| 495 | "StartWait", |
| 496 | "SetupWait", |
| 497 | "Idle", |
| 498 | "TX", |
| 499 | "Terminating", |
| 500 | "Registration error", |
| 501 | "Connect error", |
| 502 | }; |
| 503 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /** |
| 506 | * Debug Facility Stuff |
| 507 | */ |
| 508 | static debug_info_t *iucv_dbf_setup = NULL; |
| 509 | static debug_info_t *iucv_dbf_data = NULL; |
| 510 | static debug_info_t *iucv_dbf_trace = NULL; |
| 511 | |
| 512 | DEFINE_PER_CPU(char[256], iucv_dbf_txt_buf); |
| 513 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 514 | static void iucv_unregister_dbf_views(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
| 516 | if (iucv_dbf_setup) |
| 517 | debug_unregister(iucv_dbf_setup); |
| 518 | if (iucv_dbf_data) |
| 519 | debug_unregister(iucv_dbf_data); |
| 520 | if (iucv_dbf_trace) |
| 521 | debug_unregister(iucv_dbf_trace); |
| 522 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 523 | static int iucv_register_dbf_views(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | { |
| 525 | iucv_dbf_setup = debug_register(IUCV_DBF_SETUP_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 526 | IUCV_DBF_SETUP_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | IUCV_DBF_SETUP_NR_AREAS, |
| 528 | IUCV_DBF_SETUP_LEN); |
| 529 | iucv_dbf_data = debug_register(IUCV_DBF_DATA_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 530 | IUCV_DBF_DATA_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | IUCV_DBF_DATA_NR_AREAS, |
| 532 | IUCV_DBF_DATA_LEN); |
| 533 | iucv_dbf_trace = debug_register(IUCV_DBF_TRACE_NAME, |
Michael Holzheu | 66a464d | 2005-06-25 14:55:33 -0700 | [diff] [blame] | 534 | IUCV_DBF_TRACE_PAGES, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | IUCV_DBF_TRACE_NR_AREAS, |
| 536 | IUCV_DBF_TRACE_LEN); |
| 537 | |
| 538 | if ((iucv_dbf_setup == NULL) || (iucv_dbf_data == NULL) || |
| 539 | (iucv_dbf_trace == NULL)) { |
| 540 | iucv_unregister_dbf_views(); |
| 541 | return -ENOMEM; |
| 542 | } |
| 543 | debug_register_view(iucv_dbf_setup, &debug_hex_ascii_view); |
| 544 | debug_set_level(iucv_dbf_setup, IUCV_DBF_SETUP_LEVEL); |
| 545 | |
| 546 | debug_register_view(iucv_dbf_data, &debug_hex_ascii_view); |
| 547 | debug_set_level(iucv_dbf_data, IUCV_DBF_DATA_LEVEL); |
| 548 | |
| 549 | debug_register_view(iucv_dbf_trace, &debug_hex_ascii_view); |
| 550 | debug_set_level(iucv_dbf_trace, IUCV_DBF_TRACE_LEVEL); |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 555 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | * Callback-wrappers, called from lowlevel iucv layer. |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 557 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 559 | static void netiucv_callback_rx(struct iucv_path *path, |
| 560 | struct iucv_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 562 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | struct iucv_event ev; |
| 564 | |
| 565 | ev.conn = conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 566 | ev.data = msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | fsm_event(conn->fsm, CONN_EVENT_RX, &ev); |
| 568 | } |
| 569 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 570 | static void netiucv_callback_txdone(struct iucv_path *path, |
| 571 | struct iucv_message *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 573 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | struct iucv_event ev; |
| 575 | |
| 576 | ev.conn = conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 577 | ev.data = msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | fsm_event(conn->fsm, CONN_EVENT_TXDONE, &ev); |
| 579 | } |
| 580 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 581 | static void netiucv_callback_connack(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 583 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 585 | fsm_event(conn->fsm, CONN_EVENT_CONN_ACK, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 588 | static int netiucv_callback_connreq(struct iucv_path *path, |
| 589 | u8 ipvmid[8], u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 591 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | struct iucv_event ev; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 593 | static char tmp_user[9]; |
| 594 | static char tmp_udat[17]; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 595 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 597 | rc = -EINVAL; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 598 | memcpy(tmp_user, netiucv_printname(ipvmid, 8), 8); |
| 599 | memcpy(tmp_udat, ipuser, 16); |
| 600 | EBCASC(tmp_udat, 16); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 601 | read_lock_bh(&iucv_connection_rwlock); |
| 602 | list_for_each_entry(conn, &iucv_connection_list, list) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 603 | if (strncmp(ipvmid, conn->userid, 8) || |
| 604 | strncmp(ipuser, conn->userdata, 16)) |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 605 | continue; |
| 606 | /* Found a matching connection for this path. */ |
| 607 | conn->path = path; |
| 608 | ev.conn = conn; |
| 609 | ev.data = path; |
| 610 | fsm_event(conn->fsm, CONN_EVENT_CONN_REQ, &ev); |
| 611 | rc = 0; |
| 612 | } |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 613 | IUCV_DBF_TEXT_(setup, 2, "Connection requested for %s.%s\n", |
| 614 | tmp_user, netiucv_printname(tmp_udat, 16)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 615 | read_unlock_bh(&iucv_connection_rwlock); |
| 616 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 619 | static void netiucv_callback_connrej(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 621 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 623 | fsm_event(conn->fsm, CONN_EVENT_CONN_REJ, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
| 625 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 626 | static void netiucv_callback_connsusp(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 628 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 630 | fsm_event(conn->fsm, CONN_EVENT_CONN_SUS, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 633 | static void netiucv_callback_connres(struct iucv_path *path, u8 ipuser[16]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 635 | struct iucv_connection *conn = path->private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 637 | fsm_event(conn->fsm, CONN_EVENT_CONN_RES, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | /** |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 641 | * NOP action for statemachines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | */ |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 643 | static void netiucv_action_nop(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | { |
| 645 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 646 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 647 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | * Actions of the connection statemachine |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 649 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
| 651 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 652 | * netiucv_unpack_skb |
| 653 | * @conn: The connection where this skb has been received. |
| 654 | * @pskb: The received skb. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 656 | * Unpack a just received skb and hand it over to upper layers. |
| 657 | * Helper function for conn_action_rx. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 659 | static void netiucv_unpack_skb(struct iucv_connection *conn, |
| 660 | struct sk_buff *pskb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
| 662 | struct net_device *dev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 663 | struct netiucv_priv *privptr = netdev_priv(dev); |
| 664 | u16 offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | skb_put(pskb, NETIUCV_HDRLEN); |
| 667 | pskb->dev = dev; |
| 668 | pskb->ip_summed = CHECKSUM_NONE; |
| 669 | pskb->protocol = ntohs(ETH_P_IP); |
| 670 | |
| 671 | while (1) { |
| 672 | struct sk_buff *skb; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 673 | struct ll_header *header = (struct ll_header *) pskb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | if (!header->next) |
| 676 | break; |
| 677 | |
| 678 | skb_pull(pskb, NETIUCV_HDRLEN); |
| 679 | header->next -= offset; |
| 680 | offset += header->next; |
| 681 | header->next -= NETIUCV_HDRLEN; |
| 682 | if (skb_tailroom(pskb) < header->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | IUCV_DBF_TEXT_(data, 2, "Illegal next field: %d > %d\n", |
| 684 | header->next, skb_tailroom(pskb)); |
| 685 | return; |
| 686 | } |
| 687 | skb_put(pskb, header->next); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 688 | skb_reset_mac_header(pskb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | skb = dev_alloc_skb(pskb->len); |
| 690 | if (!skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | IUCV_DBF_TEXT(data, 2, |
| 692 | "Out of memory in netiucv_unpack_skb\n"); |
| 693 | privptr->stats.rx_dropped++; |
| 694 | return; |
| 695 | } |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 696 | skb_copy_from_linear_data(pskb, skb_put(skb, pskb->len), |
| 697 | pskb->len); |
Arnaldo Carvalho de Melo | 459a98e | 2007-03-19 15:30:44 -0700 | [diff] [blame] | 698 | skb_reset_mac_header(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | skb->dev = pskb->dev; |
| 700 | skb->protocol = pskb->protocol; |
| 701 | pskb->ip_summed = CHECKSUM_UNNECESSARY; |
Julia Lawall | 9b3efc0 | 2007-12-10 17:17:37 -0800 | [diff] [blame] | 702 | privptr->stats.rx_packets++; |
| 703 | privptr->stats.rx_bytes += skb->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | /* |
| 705 | * Since receiving is always initiated from a tasklet (in iucv.c), |
| 706 | * we must use netif_rx_ni() instead of netif_rx() |
| 707 | */ |
| 708 | netif_rx_ni(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | skb_pull(pskb, header->next); |
| 710 | skb_put(pskb, NETIUCV_HDRLEN); |
| 711 | } |
| 712 | } |
| 713 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 714 | static void conn_action_rx(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 716 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 718 | struct iucv_message *msg = ev->data; |
| 719 | struct netiucv_priv *privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | int rc; |
| 721 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 722 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | |
| 724 | if (!conn->netdev) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 725 | iucv_message_reject(conn->path, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 727 | "Received data for unlinked connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | return; |
| 729 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 730 | if (msg->length > conn->max_buffsize) { |
| 731 | iucv_message_reject(conn->path, msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | privptr->stats.rx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | IUCV_DBF_TEXT_(data, 2, "msglen %d > max_buffsize %d\n", |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 734 | msg->length, conn->max_buffsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return; |
| 736 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 737 | conn->rx_buff->data = conn->rx_buff->head; |
| 738 | skb_reset_tail_pointer(conn->rx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | conn->rx_buff->len = 0; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 740 | rc = iucv_message_receive(conn->path, msg, 0, conn->rx_buff->data, |
| 741 | msg->length, NULL); |
| 742 | if (rc || msg->length < 5) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | privptr->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_receive\n", rc); |
| 745 | return; |
| 746 | } |
| 747 | netiucv_unpack_skb(conn, conn->rx_buff); |
| 748 | } |
| 749 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 750 | static void conn_action_txdone(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 752 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 754 | struct iucv_message *msg = ev->data; |
| 755 | struct iucv_message txmsg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | struct netiucv_priv *privptr = NULL; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 757 | u32 single_flag = msg->tag; |
| 758 | u32 txbytes = 0; |
| 759 | u32 txpackets = 0; |
| 760 | u32 stat_maxcq = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | struct sk_buff *skb; |
| 762 | unsigned long saveflags; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 763 | struct ll_header header; |
| 764 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 766 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 768 | if (conn && conn->netdev) |
| 769 | privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | conn->prof.tx_pending--; |
| 771 | if (single_flag) { |
| 772 | if ((skb = skb_dequeue(&conn->commit_queue))) { |
| 773 | atomic_dec(&skb->users); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | if (privptr) { |
| 775 | privptr->stats.tx_packets++; |
| 776 | privptr->stats.tx_bytes += |
| 777 | (skb->len - NETIUCV_HDRLEN |
Ursula Braun | 998221c | 2009-11-12 21:46:30 +0000 | [diff] [blame] | 778 | - NETIUCV_HDRLEN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
Ursula Braun | 998221c | 2009-11-12 21:46:30 +0000 | [diff] [blame] | 780 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 783 | conn->tx_buff->data = conn->tx_buff->head; |
| 784 | skb_reset_tail_pointer(conn->tx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | conn->tx_buff->len = 0; |
| 786 | spin_lock_irqsave(&conn->collect_lock, saveflags); |
| 787 | while ((skb = skb_dequeue(&conn->collect_queue))) { |
| 788 | header.next = conn->tx_buff->len + skb->len + NETIUCV_HDRLEN; |
| 789 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, |
| 790 | NETIUCV_HDRLEN); |
Arnaldo Carvalho de Melo | d626f62 | 2007-03-27 18:55:52 -0300 | [diff] [blame] | 791 | skb_copy_from_linear_data(skb, |
| 792 | skb_put(conn->tx_buff, skb->len), |
| 793 | skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | txbytes += skb->len; |
| 795 | txpackets++; |
| 796 | stat_maxcq++; |
| 797 | atomic_dec(&skb->users); |
| 798 | dev_kfree_skb_any(skb); |
| 799 | } |
| 800 | if (conn->collect_len > conn->prof.maxmulti) |
| 801 | conn->prof.maxmulti = conn->collect_len; |
| 802 | conn->collect_len = 0; |
| 803 | spin_unlock_irqrestore(&conn->collect_lock, saveflags); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 804 | if (conn->tx_buff->len == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 806 | return; |
| 807 | } |
| 808 | |
| 809 | header.next = 0; |
| 810 | memcpy(skb_put(conn->tx_buff, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
john stultz | 2c6b47d | 2007-07-24 17:47:43 -0700 | [diff] [blame] | 811 | conn->prof.send_stamp = current_kernel_time(); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 812 | txmsg.class = 0; |
| 813 | txmsg.tag = 0; |
| 814 | rc = iucv_message_send(conn->path, &txmsg, 0, 0, |
| 815 | conn->tx_buff->data, conn->tx_buff->len); |
| 816 | conn->prof.doios_multi++; |
| 817 | conn->prof.txlen += conn->tx_buff->len; |
| 818 | conn->prof.tx_pending++; |
| 819 | if (conn->prof.tx_pending > conn->prof.tx_max_pending) |
| 820 | conn->prof.tx_max_pending = conn->prof.tx_pending; |
| 821 | if (rc) { |
| 822 | conn->prof.tx_pending--; |
| 823 | fsm_newstate(fi, CONN_STATE_IDLE); |
| 824 | if (privptr) |
| 825 | privptr->stats.tx_errors += txpackets; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 826 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc); |
| 827 | } else { |
| 828 | if (privptr) { |
| 829 | privptr->stats.tx_packets += txpackets; |
| 830 | privptr->stats.tx_bytes += txbytes; |
| 831 | } |
| 832 | if (stat_maxcq > conn->prof.maxcqueue) |
| 833 | conn->prof.maxcqueue = stat_maxcq; |
| 834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 837 | static void conn_action_connaccept(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 839 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | struct iucv_connection *conn = ev->conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 841 | struct iucv_path *path = ev->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 843 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 846 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 848 | conn->path = path; |
| 849 | path->msglim = NETIUCV_QUEUELEN_DEFAULT; |
| 850 | path->flags = 0; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 851 | rc = iucv_path_accept(path, &netiucv_handler, conn->userdata , conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | IUCV_DBF_TEXT_(setup, 2, "rc %d from iucv_accept", rc); |
| 854 | return; |
| 855 | } |
| 856 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 857 | netdev->tx_queue_len = conn->path->msglim; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev); |
| 859 | } |
| 860 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 861 | static void conn_action_connreject(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 863 | struct iucv_event *ev = arg; |
| 864 | struct iucv_path *path = ev->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 866 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 867 | iucv_path_sever(path, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 870 | static void conn_action_connack(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 872 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 874 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 876 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | fsm_deltimer(&conn->timer); |
| 878 | fsm_newstate(fi, CONN_STATE_IDLE); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 879 | netdev->tx_queue_len = conn->path->msglim; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | fsm_event(privptr->fsm, DEV_EVENT_CONUP, netdev); |
| 881 | } |
| 882 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 883 | static void conn_action_conntimsev(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 885 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 887 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | fsm_deltimer(&conn->timer); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 889 | iucv_path_sever(conn->path, conn->userdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 891 | } |
| 892 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 893 | static void conn_action_connsever(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 895 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 897 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 899 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | fsm_deltimer(&conn->timer); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 902 | iucv_path_sever(conn->path, conn->userdata); |
| 903 | dev_info(privptr->dev, "The peer z/VM guest %s has closed the " |
| 904 | "connection\n", netiucv_printuser(conn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 906 | "conn_action_connsever: Remote dropped connection\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 908 | fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev); |
| 909 | } |
| 910 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 911 | static void conn_action_start(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 913 | struct iucv_connection *conn = arg; |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 914 | struct net_device *netdev = conn->netdev; |
| 915 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | int rc; |
| 917 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 918 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 920 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 922 | /* |
| 923 | * We must set the state before calling iucv_connect because the |
| 924 | * callback handler could be called at any point after the connection |
| 925 | * request is sent |
| 926 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | fsm_newstate(fi, CONN_STATE_SETUPWAIT); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 929 | conn->path = iucv_path_alloc(NETIUCV_QUEUELEN_DEFAULT, 0, GFP_KERNEL); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 930 | IUCV_DBF_TEXT_(setup, 2, "%s: connecting to %s ...\n", |
| 931 | netdev->name, netiucv_printuser(conn)); |
| 932 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 933 | rc = iucv_path_connect(conn->path, &netiucv_handler, conn->userid, |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 934 | NULL, conn->userdata, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | switch (rc) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 936 | case 0: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 937 | netdev->tx_queue_len = conn->path->msglim; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 938 | fsm_addtimer(&conn->timer, NETIUCV_TIMEOUT_5SEC, |
| 939 | CONN_EVENT_TIMER, conn); |
| 940 | return; |
| 941 | case 11: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 942 | dev_warn(privptr->dev, |
| 943 | "The IUCV device failed to connect to z/VM guest %s\n", |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 944 | netiucv_printname(conn->userid, 8)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 945 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 946 | break; |
| 947 | case 12: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 948 | dev_warn(privptr->dev, |
| 949 | "The IUCV device failed to connect to the peer on z/VM" |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 950 | " guest %s\n", netiucv_printname(conn->userid, 8)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 951 | fsm_newstate(fi, CONN_STATE_STARTWAIT); |
| 952 | break; |
| 953 | case 13: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 954 | dev_err(privptr->dev, |
| 955 | "Connecting the IUCV device would exceed the maximum" |
| 956 | " number of IUCV connections\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 957 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 958 | break; |
| 959 | case 14: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 960 | dev_err(privptr->dev, |
| 961 | "z/VM guest %s has too many IUCV connections" |
| 962 | " to connect with the IUCV device\n", |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 963 | netiucv_printname(conn->userid, 8)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 964 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 965 | break; |
| 966 | case 15: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 967 | dev_err(privptr->dev, |
| 968 | "The IUCV device cannot connect to a z/VM guest with no" |
| 969 | " IUCV authorization\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 970 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 971 | break; |
| 972 | default: |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 973 | dev_err(privptr->dev, |
| 974 | "Connecting the IUCV device failed with error %d\n", |
| 975 | rc); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 976 | fsm_newstate(fi, CONN_STATE_CONNERR); |
| 977 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | IUCV_DBF_TEXT_(setup, 5, "iucv_connect rc is %d\n", rc); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 980 | kfree(conn->path); |
| 981 | conn->path = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 984 | static void netiucv_purge_skb_queue(struct sk_buff_head *q) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
| 986 | struct sk_buff *skb; |
| 987 | |
| 988 | while ((skb = skb_dequeue(q))) { |
| 989 | atomic_dec(&skb->users); |
| 990 | dev_kfree_skb_any(skb); |
| 991 | } |
| 992 | } |
| 993 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 994 | static void conn_action_stop(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 996 | struct iucv_event *ev = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | struct iucv_connection *conn = ev->conn; |
| 998 | struct net_device *netdev = conn->netdev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 999 | struct netiucv_priv *privptr = netdev_priv(netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1001 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | fsm_deltimer(&conn->timer); |
| 1004 | fsm_newstate(fi, CONN_STATE_STOPPED); |
| 1005 | netiucv_purge_skb_queue(&conn->collect_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1006 | if (conn->path) { |
| 1007 | IUCV_DBF_TEXT(trace, 5, "calling iucv_path_sever\n"); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1008 | iucv_path_sever(conn->path, conn->userdata); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1009 | kfree(conn->path); |
| 1010 | conn->path = NULL; |
| 1011 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | netiucv_purge_skb_queue(&conn->commit_queue); |
| 1013 | fsm_event(privptr->fsm, DEV_EVENT_CONDOWN, netdev); |
| 1014 | } |
| 1015 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1016 | static void conn_action_inval(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1018 | struct iucv_connection *conn = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | struct net_device *netdev = conn->netdev; |
| 1020 | |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 1021 | IUCV_DBF_TEXT_(data, 2, "%s('%s'): conn_action_inval called\n", |
| 1022 | netdev->name, conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | static const fsm_node conn_fsm[] = { |
| 1026 | { CONN_STATE_INVALID, CONN_EVENT_START, conn_action_inval }, |
| 1027 | { CONN_STATE_STOPPED, CONN_EVENT_START, conn_action_start }, |
| 1028 | |
| 1029 | { CONN_STATE_STOPPED, CONN_EVENT_STOP, conn_action_stop }, |
| 1030 | { CONN_STATE_STARTWAIT, CONN_EVENT_STOP, conn_action_stop }, |
| 1031 | { CONN_STATE_SETUPWAIT, CONN_EVENT_STOP, conn_action_stop }, |
| 1032 | { CONN_STATE_IDLE, CONN_EVENT_STOP, conn_action_stop }, |
| 1033 | { CONN_STATE_TX, CONN_EVENT_STOP, conn_action_stop }, |
| 1034 | { CONN_STATE_REGERR, CONN_EVENT_STOP, conn_action_stop }, |
| 1035 | { CONN_STATE_CONNERR, CONN_EVENT_STOP, conn_action_stop }, |
| 1036 | |
| 1037 | { CONN_STATE_STOPPED, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1038 | { CONN_STATE_STARTWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept }, |
| 1039 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REQ, conn_action_connaccept }, |
| 1040 | { CONN_STATE_IDLE, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1041 | { CONN_STATE_TX, CONN_EVENT_CONN_REQ, conn_action_connreject }, |
| 1042 | |
| 1043 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_ACK, conn_action_connack }, |
| 1044 | { CONN_STATE_SETUPWAIT, CONN_EVENT_TIMER, conn_action_conntimsev }, |
| 1045 | |
| 1046 | { CONN_STATE_SETUPWAIT, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1047 | { CONN_STATE_IDLE, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1048 | { CONN_STATE_TX, CONN_EVENT_CONN_REJ, conn_action_connsever }, |
| 1049 | |
| 1050 | { CONN_STATE_IDLE, CONN_EVENT_RX, conn_action_rx }, |
| 1051 | { CONN_STATE_TX, CONN_EVENT_RX, conn_action_rx }, |
| 1052 | |
| 1053 | { CONN_STATE_TX, CONN_EVENT_TXDONE, conn_action_txdone }, |
| 1054 | { CONN_STATE_IDLE, CONN_EVENT_TXDONE, conn_action_txdone }, |
| 1055 | }; |
| 1056 | |
| 1057 | static const int CONN_FSM_LEN = sizeof(conn_fsm) / sizeof(fsm_node); |
| 1058 | |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1059 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1060 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | * Actions for interface - statemachine. |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1062 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | |
| 1064 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1065 | * dev_action_start |
| 1066 | * @fi: An instance of an interface statemachine. |
| 1067 | * @event: The event, just happened. |
| 1068 | * @arg: Generic pointer, casted from struct net_device * upon call. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1070 | * Startup connection by sending CONN_EVENT_START to it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1072 | static void dev_action_start(fsm_instance *fi, int event, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1074 | struct net_device *dev = arg; |
| 1075 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1077 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1079 | fsm_newstate(fi, DEV_STATE_STARTWAIT); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1080 | fsm_event(privptr->conn->fsm, CONN_EVENT_START, privptr->conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | /** |
| 1084 | * Shutdown connection by sending CONN_EVENT_STOP to it. |
| 1085 | * |
| 1086 | * @param fi An instance of an interface statemachine. |
| 1087 | * @param event The event, just happened. |
| 1088 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1089 | */ |
| 1090 | static void |
| 1091 | dev_action_stop(fsm_instance *fi, int event, void *arg) |
| 1092 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1093 | struct net_device *dev = arg; |
| 1094 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | struct iucv_event ev; |
| 1096 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1097 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
| 1099 | ev.conn = privptr->conn; |
| 1100 | |
| 1101 | fsm_newstate(fi, DEV_STATE_STOPWAIT); |
| 1102 | fsm_event(privptr->conn->fsm, CONN_EVENT_STOP, &ev); |
| 1103 | } |
| 1104 | |
| 1105 | /** |
| 1106 | * Called from connection statemachine |
| 1107 | * when a connection is up and running. |
| 1108 | * |
| 1109 | * @param fi An instance of an interface statemachine. |
| 1110 | * @param event The event, just happened. |
| 1111 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1112 | */ |
| 1113 | static void |
| 1114 | dev_action_connup(fsm_instance *fi, int event, void *arg) |
| 1115 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1116 | struct net_device *dev = arg; |
| 1117 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1119 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
| 1121 | switch (fsm_getstate(fi)) { |
| 1122 | case DEV_STATE_STARTWAIT: |
| 1123 | fsm_newstate(fi, DEV_STATE_RUNNING); |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 1124 | dev_info(privptr->dev, |
| 1125 | "The IUCV device has been connected" |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1126 | " successfully to %s\n", |
| 1127 | netiucv_printuser(privptr->conn)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | IUCV_DBF_TEXT(setup, 3, |
| 1129 | "connection is up and running\n"); |
| 1130 | break; |
| 1131 | case DEV_STATE_STOPWAIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | IUCV_DBF_TEXT(data, 2, |
| 1133 | "dev_action_connup: in DEV_STATE_STOPWAIT\n"); |
| 1134 | break; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * Called from connection statemachine |
| 1140 | * when a connection has been shutdown. |
| 1141 | * |
| 1142 | * @param fi An instance of an interface statemachine. |
| 1143 | * @param event The event, just happened. |
| 1144 | * @param arg Generic pointer, casted from struct net_device * upon call. |
| 1145 | */ |
| 1146 | static void |
| 1147 | dev_action_conndown(fsm_instance *fi, int event, void *arg) |
| 1148 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1149 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | |
| 1151 | switch (fsm_getstate(fi)) { |
| 1152 | case DEV_STATE_RUNNING: |
| 1153 | fsm_newstate(fi, DEV_STATE_STARTWAIT); |
| 1154 | break; |
| 1155 | case DEV_STATE_STOPWAIT: |
| 1156 | fsm_newstate(fi, DEV_STATE_STOPPED); |
| 1157 | IUCV_DBF_TEXT(setup, 3, "connection is down\n"); |
| 1158 | break; |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | static const fsm_node dev_fsm[] = { |
| 1163 | { DEV_STATE_STOPPED, DEV_EVENT_START, dev_action_start }, |
| 1164 | |
| 1165 | { DEV_STATE_STOPWAIT, DEV_EVENT_START, dev_action_start }, |
| 1166 | { DEV_STATE_STOPWAIT, DEV_EVENT_CONDOWN, dev_action_conndown }, |
| 1167 | |
| 1168 | { DEV_STATE_STARTWAIT, DEV_EVENT_STOP, dev_action_stop }, |
| 1169 | { DEV_STATE_STARTWAIT, DEV_EVENT_CONUP, dev_action_connup }, |
| 1170 | |
| 1171 | { DEV_STATE_RUNNING, DEV_EVENT_STOP, dev_action_stop }, |
| 1172 | { DEV_STATE_RUNNING, DEV_EVENT_CONDOWN, dev_action_conndown }, |
Ursula Braun | 21b26f2f | 2008-02-08 13:09:03 +0100 | [diff] [blame] | 1173 | { DEV_STATE_RUNNING, DEV_EVENT_CONUP, netiucv_action_nop }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | }; |
| 1175 | |
| 1176 | static const int DEV_FSM_LEN = sizeof(dev_fsm) / sizeof(fsm_node); |
| 1177 | |
| 1178 | /** |
| 1179 | * Transmit a packet. |
| 1180 | * This is a helper function for netiucv_tx(). |
| 1181 | * |
| 1182 | * @param conn Connection to be used for sending. |
| 1183 | * @param skb Pointer to struct sk_buff of packet to send. |
| 1184 | * The linklevel header has already been set up |
| 1185 | * by netiucv_tx(). |
| 1186 | * |
| 1187 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1188 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1189 | static int netiucv_transmit_skb(struct iucv_connection *conn, |
| 1190 | struct sk_buff *skb) |
| 1191 | { |
| 1192 | struct iucv_message msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | unsigned long saveflags; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1194 | struct ll_header header; |
| 1195 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
| 1197 | if (fsm_getstate(conn->fsm) != CONN_STATE_IDLE) { |
| 1198 | int l = skb->len + NETIUCV_HDRLEN; |
| 1199 | |
| 1200 | spin_lock_irqsave(&conn->collect_lock, saveflags); |
| 1201 | if (conn->collect_len + l > |
| 1202 | (conn->max_buffsize - NETIUCV_HDRLEN)) { |
| 1203 | rc = -EBUSY; |
| 1204 | IUCV_DBF_TEXT(data, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1205 | "EBUSY from netiucv_transmit_skb\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } else { |
| 1207 | atomic_inc(&skb->users); |
| 1208 | skb_queue_tail(&conn->collect_queue, skb); |
| 1209 | conn->collect_len += l; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1210 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | } |
| 1212 | spin_unlock_irqrestore(&conn->collect_lock, saveflags); |
| 1213 | } else { |
| 1214 | struct sk_buff *nskb = skb; |
| 1215 | /** |
| 1216 | * Copy the skb to a new allocated skb in lowmem only if the |
| 1217 | * data is located above 2G in memory or tailroom is < 2. |
| 1218 | */ |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 1219 | unsigned long hi = ((unsigned long)(skb_tail_pointer(skb) + |
| 1220 | NETIUCV_HDRLEN)) >> 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | int copied = 0; |
| 1222 | if (hi || (skb_tailroom(skb) < 2)) { |
| 1223 | nskb = alloc_skb(skb->len + NETIUCV_HDRLEN + |
| 1224 | NETIUCV_HDRLEN, GFP_ATOMIC | GFP_DMA); |
| 1225 | if (!nskb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | IUCV_DBF_TEXT(data, 2, "alloc_skb failed\n"); |
| 1227 | rc = -ENOMEM; |
| 1228 | return rc; |
| 1229 | } else { |
| 1230 | skb_reserve(nskb, NETIUCV_HDRLEN); |
| 1231 | memcpy(skb_put(nskb, skb->len), |
| 1232 | skb->data, skb->len); |
| 1233 | } |
| 1234 | copied = 1; |
| 1235 | } |
| 1236 | /** |
| 1237 | * skb now is below 2G and has enough room. Add headers. |
| 1238 | */ |
| 1239 | header.next = nskb->len + NETIUCV_HDRLEN; |
| 1240 | memcpy(skb_push(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
| 1241 | header.next = 0; |
| 1242 | memcpy(skb_put(nskb, NETIUCV_HDRLEN), &header, NETIUCV_HDRLEN); |
| 1243 | |
| 1244 | fsm_newstate(conn->fsm, CONN_STATE_TX); |
john stultz | 2c6b47d | 2007-07-24 17:47:43 -0700 | [diff] [blame] | 1245 | conn->prof.send_stamp = current_kernel_time(); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1246 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1247 | msg.tag = 1; |
| 1248 | msg.class = 0; |
| 1249 | rc = iucv_message_send(conn->path, &msg, 0, 0, |
| 1250 | nskb->data, nskb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | conn->prof.doios_single++; |
| 1252 | conn->prof.txlen += skb->len; |
| 1253 | conn->prof.tx_pending++; |
| 1254 | if (conn->prof.tx_pending > conn->prof.tx_max_pending) |
| 1255 | conn->prof.tx_max_pending = conn->prof.tx_pending; |
| 1256 | if (rc) { |
| 1257 | struct netiucv_priv *privptr; |
| 1258 | fsm_newstate(conn->fsm, CONN_STATE_IDLE); |
| 1259 | conn->prof.tx_pending--; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1260 | privptr = netdev_priv(conn->netdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | if (privptr) |
| 1262 | privptr->stats.tx_errors++; |
| 1263 | if (copied) |
| 1264 | dev_kfree_skb(nskb); |
| 1265 | else { |
| 1266 | /** |
| 1267 | * Remove our headers. They get added |
| 1268 | * again on retransmit. |
| 1269 | */ |
| 1270 | skb_pull(skb, NETIUCV_HDRLEN); |
| 1271 | skb_trim(skb, skb->len - NETIUCV_HDRLEN); |
| 1272 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | IUCV_DBF_TEXT_(data, 2, "rc %d from iucv_send\n", rc); |
| 1274 | } else { |
| 1275 | if (copied) |
| 1276 | dev_kfree_skb(skb); |
| 1277 | atomic_inc(&nskb->users); |
| 1278 | skb_queue_tail(&conn->commit_queue, nskb); |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | return rc; |
| 1283 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1284 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1285 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | * Interface API for upper network layers |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1287 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | |
| 1289 | /** |
| 1290 | * Open an interface. |
| 1291 | * Called from generic network layer when ifconfig up is run. |
| 1292 | * |
| 1293 | * @param dev Pointer to interface struct. |
| 1294 | * |
| 1295 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1296 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1297 | static int netiucv_open(struct net_device *dev) |
| 1298 | { |
| 1299 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1300 | |
| 1301 | fsm_event(priv->fsm, DEV_EVENT_START, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | /** |
| 1306 | * Close an interface. |
| 1307 | * Called from generic network layer when ifconfig down is run. |
| 1308 | * |
| 1309 | * @param dev Pointer to interface struct. |
| 1310 | * |
| 1311 | * @return 0 on success, -ERRNO on failure. (Never fails.) |
| 1312 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1313 | static int netiucv_close(struct net_device *dev) |
| 1314 | { |
| 1315 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1316 | |
| 1317 | fsm_event(priv->fsm, DEV_EVENT_STOP, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | return 0; |
| 1319 | } |
| 1320 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1321 | static int netiucv_pm_prepare(struct device *dev) |
| 1322 | { |
| 1323 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1324 | return 0; |
| 1325 | } |
| 1326 | |
| 1327 | static void netiucv_pm_complete(struct device *dev) |
| 1328 | { |
| 1329 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1330 | return; |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * netiucv_pm_freeze() - Freeze PM callback |
| 1335 | * @dev: netiucv device |
| 1336 | * |
| 1337 | * close open netiucv interfaces |
| 1338 | */ |
| 1339 | static int netiucv_pm_freeze(struct device *dev) |
| 1340 | { |
Martin Schwidefsky | 4f0076f | 2009-06-22 12:08:19 +0200 | [diff] [blame] | 1341 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1342 | struct net_device *ndev = NULL; |
| 1343 | int rc = 0; |
| 1344 | |
| 1345 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1346 | if (priv && priv->conn) |
| 1347 | ndev = priv->conn->netdev; |
| 1348 | if (!ndev) |
| 1349 | goto out; |
| 1350 | netif_device_detach(ndev); |
| 1351 | priv->pm_state = fsm_getstate(priv->fsm); |
| 1352 | rc = netiucv_close(ndev); |
| 1353 | out: |
| 1354 | return rc; |
| 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * netiucv_pm_restore_thaw() - Thaw and restore PM callback |
| 1359 | * @dev: netiucv device |
| 1360 | * |
| 1361 | * re-open netiucv interfaces closed during freeze |
| 1362 | */ |
| 1363 | static int netiucv_pm_restore_thaw(struct device *dev) |
| 1364 | { |
Martin Schwidefsky | 4f0076f | 2009-06-22 12:08:19 +0200 | [diff] [blame] | 1365 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 1366 | struct net_device *ndev = NULL; |
| 1367 | int rc = 0; |
| 1368 | |
| 1369 | IUCV_DBF_TEXT(trace, 3, __func__); |
| 1370 | if (priv && priv->conn) |
| 1371 | ndev = priv->conn->netdev; |
| 1372 | if (!ndev) |
| 1373 | goto out; |
| 1374 | switch (priv->pm_state) { |
| 1375 | case DEV_STATE_RUNNING: |
| 1376 | case DEV_STATE_STARTWAIT: |
| 1377 | rc = netiucv_open(ndev); |
| 1378 | break; |
| 1379 | default: |
| 1380 | break; |
| 1381 | } |
| 1382 | netif_device_attach(ndev); |
| 1383 | out: |
| 1384 | return rc; |
| 1385 | } |
| 1386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | /** |
| 1388 | * Start transmission of a packet. |
| 1389 | * Called from generic network device layer. |
| 1390 | * |
| 1391 | * @param skb Pointer to buffer containing the packet. |
| 1392 | * @param dev Pointer to interface struct. |
| 1393 | * |
| 1394 | * @return 0 if packet consumed, !0 if packet rejected. |
| 1395 | * Note: If we return !0, then the packet is free'd by |
| 1396 | * the generic network layer. |
| 1397 | */ |
| 1398 | static int netiucv_tx(struct sk_buff *skb, struct net_device *dev) |
| 1399 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1400 | struct netiucv_priv *privptr = netdev_priv(dev); |
| 1401 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1402 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1403 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | /** |
| 1405 | * Some sanity checks ... |
| 1406 | */ |
| 1407 | if (skb == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | IUCV_DBF_TEXT(data, 2, "netiucv_tx: skb is NULL\n"); |
| 1409 | privptr->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1410 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | } |
| 1412 | if (skb_headroom(skb) < NETIUCV_HDRLEN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | IUCV_DBF_TEXT(data, 2, |
| 1414 | "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n"); |
| 1415 | dev_kfree_skb(skb); |
| 1416 | privptr->stats.tx_dropped++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1417 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | /** |
| 1421 | * If connection is not running, try to restart it |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1422 | * and throw away packet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | */ |
| 1424 | if (fsm_getstate(privptr->fsm) != DEV_STATE_RUNNING) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | dev_kfree_skb(skb); |
| 1426 | privptr->stats.tx_dropped++; |
| 1427 | privptr->stats.tx_errors++; |
| 1428 | privptr->stats.tx_carrier_errors++; |
Patrick McHardy | ec634fe | 2009-07-05 19:23:38 -0700 | [diff] [blame] | 1429 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | if (netiucv_test_and_set_busy(dev)) { |
| 1433 | IUCV_DBF_TEXT(data, 2, "EBUSY from netiucv_tx\n"); |
Ursula Braun | 4e584d6 | 2009-03-24 03:27:45 +0000 | [diff] [blame] | 1434 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | } |
| 1436 | dev->trans_start = jiffies; |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1437 | rc = netiucv_transmit_skb(privptr->conn, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | netiucv_clear_busy(dev); |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 1439 | return rc ? NETDEV_TX_BUSY : NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1443 | * netiucv_stats |
| 1444 | * @dev: Pointer to interface struct. |
| 1445 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | * Returns interface statistics of a device. |
| 1447 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1448 | * Returns pointer to stats struct of this interface. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1450 | static struct net_device_stats *netiucv_stats (struct net_device * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1452 | struct netiucv_priv *priv = netdev_priv(dev); |
| 1453 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1454 | IUCV_DBF_TEXT(trace, 5, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1455 | return &priv->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /** |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1459 | * netiucv_change_mtu |
| 1460 | * @dev: Pointer to interface struct. |
| 1461 | * @new_mtu: The new MTU to use for this interface. |
| 1462 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | * Sets MTU of an interface. |
| 1464 | * |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1465 | * Returns 0 on success, -EINVAL if MTU is out of valid range. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | * (valid range is 576 .. NETIUCV_MTU_MAX). |
| 1467 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1468 | static int netiucv_change_mtu(struct net_device * dev, int new_mtu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1470 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1471 | if (new_mtu < 576 || new_mtu > NETIUCV_MTU_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | IUCV_DBF_TEXT(setup, 2, "given MTU out of valid range\n"); |
| 1473 | return -EINVAL; |
| 1474 | } |
| 1475 | dev->mtu = new_mtu; |
| 1476 | return 0; |
| 1477 | } |
| 1478 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1479 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | * attributes in sysfs |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1481 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1483 | static ssize_t user_show(struct device *dev, struct device_attribute *attr, |
| 1484 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1486 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1488 | IUCV_DBF_TEXT(trace, 5, __func__); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1489 | return sprintf(buf, "%s\n", netiucv_printuser(priv->conn)); |
| 1490 | } |
| 1491 | |
| 1492 | static int netiucv_check_user(const char *buf, size_t count, char *username, |
| 1493 | char *userdata) |
| 1494 | { |
| 1495 | const char *p; |
| 1496 | int i; |
| 1497 | |
| 1498 | p = strchr(buf, '.'); |
| 1499 | if ((p && ((count > 26) || |
| 1500 | ((p - buf) > 8) || |
| 1501 | (buf + count - p > 18))) || |
| 1502 | (!p && (count > 9))) { |
| 1503 | IUCV_DBF_TEXT(setup, 2, "conn_write: too long\n"); |
| 1504 | return -EINVAL; |
| 1505 | } |
| 1506 | |
| 1507 | for (i = 0, p = buf; i < 8 && *p && *p != '.'; i++, p++) { |
| 1508 | if (isalnum(*p) || *p == '$') { |
| 1509 | username[i] = toupper(*p); |
| 1510 | continue; |
| 1511 | } |
| 1512 | if (*p == '\n') |
| 1513 | /* trailing lf, grr */ |
| 1514 | break; |
| 1515 | IUCV_DBF_TEXT_(setup, 2, |
| 1516 | "conn_write: invalid character %02x\n", *p); |
| 1517 | return -EINVAL; |
| 1518 | } |
| 1519 | while (i < 8) |
| 1520 | username[i++] = ' '; |
| 1521 | username[8] = '\0'; |
| 1522 | |
| 1523 | if (*p == '.') { |
| 1524 | p++; |
| 1525 | for (i = 0; i < 16 && *p; i++, p++) { |
| 1526 | if (*p == '\n') |
| 1527 | break; |
| 1528 | userdata[i] = toupper(*p); |
| 1529 | } |
| 1530 | while (i > 0 && i < 16) |
| 1531 | userdata[i++] = ' '; |
| 1532 | } else |
| 1533 | memcpy(userdata, iucvMagic_ascii, 16); |
| 1534 | userdata[16] = '\0'; |
| 1535 | ASCEBC(userdata, 16); |
| 1536 | |
| 1537 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1540 | static ssize_t user_write(struct device *dev, struct device_attribute *attr, |
| 1541 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1543 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | struct net_device *ndev = priv->conn->netdev; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1545 | char username[9]; |
| 1546 | char userdata[17]; |
| 1547 | int rc; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1548 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1549 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1550 | IUCV_DBF_TEXT(trace, 3, __func__); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1551 | rc = netiucv_check_user(buf, count, username, userdata); |
| 1552 | if (rc) |
| 1553 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1555 | if (memcmp(username, priv->conn->userid, 9) && |
| 1556 | (ndev->flags & (IFF_UP | IFF_RUNNING))) { |
| 1557 | /* username changed while the interface is active. */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1558 | IUCV_DBF_TEXT(setup, 2, "user_write: device active\n"); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 1559 | return -EPERM; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1560 | } |
| 1561 | read_lock_bh(&iucv_connection_rwlock); |
| 1562 | list_for_each_entry(cp, &iucv_connection_list, list) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1563 | if (!strncmp(username, cp->userid, 9) && |
| 1564 | !strncmp(userdata, cp->userdata, 17) && cp->netdev != ndev) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1565 | read_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1566 | IUCV_DBF_TEXT_(setup, 2, "user_write: Connection to %s " |
| 1567 | "already exists\n", netiucv_printuser(cp)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1568 | return -EEXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | } |
| 1570 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1571 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | memcpy(priv->conn->userid, username, 9); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1573 | memcpy(priv->conn->userdata, userdata, 17); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | static DEVICE_ATTR(user, 0644, user_show, user_write); |
| 1578 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1579 | static ssize_t buffer_show (struct device *dev, struct device_attribute *attr, |
| 1580 | char *buf) |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1581 | { |
| 1582 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1584 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | return sprintf(buf, "%d\n", priv->conn->max_buffsize); |
| 1586 | } |
| 1587 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1588 | static ssize_t buffer_write (struct device *dev, struct device_attribute *attr, |
| 1589 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1591 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | struct net_device *ndev = priv->conn->netdev; |
| 1593 | char *e; |
| 1594 | int bs1; |
| 1595 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1596 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | if (count >= 39) |
| 1598 | return -EINVAL; |
| 1599 | |
| 1600 | bs1 = simple_strtoul(buf, &e, 0); |
| 1601 | |
| 1602 | if (e && (!isspace(*e))) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1603 | IUCV_DBF_TEXT_(setup, 2, "buffer_write: invalid char %02x\n", |
| 1604 | *e); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | return -EINVAL; |
| 1606 | } |
| 1607 | if (bs1 > NETIUCV_BUFSIZE_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | IUCV_DBF_TEXT_(setup, 2, |
| 1609 | "buffer_write: buffer size %d too large\n", |
| 1610 | bs1); |
| 1611 | return -EINVAL; |
| 1612 | } |
| 1613 | if ((ndev->flags & IFF_RUNNING) && |
| 1614 | (bs1 < (ndev->mtu + NETIUCV_HDRLEN + 2))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | IUCV_DBF_TEXT_(setup, 2, |
| 1616 | "buffer_write: buffer size %d too small\n", |
| 1617 | bs1); |
| 1618 | return -EINVAL; |
| 1619 | } |
| 1620 | if (bs1 < (576 + NETIUCV_HDRLEN + NETIUCV_HDRLEN)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | IUCV_DBF_TEXT_(setup, 2, |
| 1622 | "buffer_write: buffer size %d too small\n", |
| 1623 | bs1); |
| 1624 | return -EINVAL; |
| 1625 | } |
| 1626 | |
| 1627 | priv->conn->max_buffsize = bs1; |
| 1628 | if (!(ndev->flags & IFF_RUNNING)) |
| 1629 | ndev->mtu = bs1 - NETIUCV_HDRLEN - NETIUCV_HDRLEN; |
| 1630 | |
| 1631 | return count; |
| 1632 | |
| 1633 | } |
| 1634 | |
| 1635 | static DEVICE_ATTR(buffer, 0644, buffer_show, buffer_write); |
| 1636 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1637 | static ssize_t dev_fsm_show (struct device *dev, struct device_attribute *attr, |
| 1638 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1640 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1642 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | return sprintf(buf, "%s\n", fsm_getstate_str(priv->fsm)); |
| 1644 | } |
| 1645 | |
| 1646 | static DEVICE_ATTR(device_fsm_state, 0444, dev_fsm_show, NULL); |
| 1647 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1648 | static ssize_t conn_fsm_show (struct device *dev, |
| 1649 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1650 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1651 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1653 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | return sprintf(buf, "%s\n", fsm_getstate_str(priv->conn->fsm)); |
| 1655 | } |
| 1656 | |
| 1657 | static DEVICE_ATTR(connection_fsm_state, 0444, conn_fsm_show, NULL); |
| 1658 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1659 | static ssize_t maxmulti_show (struct device *dev, |
| 1660 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1662 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1664 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | return sprintf(buf, "%ld\n", priv->conn->prof.maxmulti); |
| 1666 | } |
| 1667 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1668 | static ssize_t maxmulti_write (struct device *dev, |
| 1669 | struct device_attribute *attr, |
| 1670 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1672 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1674 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | priv->conn->prof.maxmulti = 0; |
| 1676 | return count; |
| 1677 | } |
| 1678 | |
| 1679 | static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write); |
| 1680 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1681 | static ssize_t maxcq_show (struct device *dev, struct device_attribute *attr, |
| 1682 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1684 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1686 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | return sprintf(buf, "%ld\n", priv->conn->prof.maxcqueue); |
| 1688 | } |
| 1689 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1690 | static ssize_t maxcq_write (struct device *dev, struct device_attribute *attr, |
| 1691 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1693 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1694 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1695 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | priv->conn->prof.maxcqueue = 0; |
| 1697 | return count; |
| 1698 | } |
| 1699 | |
| 1700 | static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write); |
| 1701 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1702 | static ssize_t sdoio_show (struct device *dev, struct device_attribute *attr, |
| 1703 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1705 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1707 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | return sprintf(buf, "%ld\n", priv->conn->prof.doios_single); |
| 1709 | } |
| 1710 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1711 | static ssize_t sdoio_write (struct device *dev, struct device_attribute *attr, |
| 1712 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1714 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1715 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1716 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | priv->conn->prof.doios_single = 0; |
| 1718 | return count; |
| 1719 | } |
| 1720 | |
| 1721 | static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write); |
| 1722 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1723 | static ssize_t mdoio_show (struct device *dev, struct device_attribute *attr, |
| 1724 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1725 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1726 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1728 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | return sprintf(buf, "%ld\n", priv->conn->prof.doios_multi); |
| 1730 | } |
| 1731 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1732 | static ssize_t mdoio_write (struct device *dev, struct device_attribute *attr, |
| 1733 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1735 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1736 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1737 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | priv->conn->prof.doios_multi = 0; |
| 1739 | return count; |
| 1740 | } |
| 1741 | |
| 1742 | static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write); |
| 1743 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1744 | static ssize_t txlen_show (struct device *dev, struct device_attribute *attr, |
| 1745 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1747 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1749 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | return sprintf(buf, "%ld\n", priv->conn->prof.txlen); |
| 1751 | } |
| 1752 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1753 | static ssize_t txlen_write (struct device *dev, struct device_attribute *attr, |
| 1754 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1756 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1757 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1758 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1759 | priv->conn->prof.txlen = 0; |
| 1760 | return count; |
| 1761 | } |
| 1762 | |
| 1763 | static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write); |
| 1764 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1765 | static ssize_t txtime_show (struct device *dev, struct device_attribute *attr, |
| 1766 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1768 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1770 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_time); |
| 1772 | } |
| 1773 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1774 | static ssize_t txtime_write (struct device *dev, struct device_attribute *attr, |
| 1775 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1777 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 1778 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1779 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | priv->conn->prof.tx_time = 0; |
| 1781 | return count; |
| 1782 | } |
| 1783 | |
| 1784 | static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write); |
| 1785 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1786 | static ssize_t txpend_show (struct device *dev, struct device_attribute *attr, |
| 1787 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1789 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1791 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_pending); |
| 1793 | } |
| 1794 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1795 | static ssize_t txpend_write (struct device *dev, struct device_attribute *attr, |
| 1796 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1797 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1798 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1800 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | priv->conn->prof.tx_pending = 0; |
| 1802 | return count; |
| 1803 | } |
| 1804 | |
| 1805 | static DEVICE_ATTR(tx_pending, 0644, txpend_show, txpend_write); |
| 1806 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1807 | static ssize_t txmpnd_show (struct device *dev, struct device_attribute *attr, |
| 1808 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1810 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1812 | IUCV_DBF_TEXT(trace, 5, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | return sprintf(buf, "%ld\n", priv->conn->prof.tx_max_pending); |
| 1814 | } |
| 1815 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1816 | static ssize_t txmpnd_write (struct device *dev, struct device_attribute *attr, |
| 1817 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | { |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1819 | struct netiucv_priv *priv = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1821 | IUCV_DBF_TEXT(trace, 4, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | priv->conn->prof.tx_max_pending = 0; |
| 1823 | return count; |
| 1824 | } |
| 1825 | |
| 1826 | static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write); |
| 1827 | |
| 1828 | static struct attribute *netiucv_attrs[] = { |
| 1829 | &dev_attr_buffer.attr, |
| 1830 | &dev_attr_user.attr, |
| 1831 | NULL, |
| 1832 | }; |
| 1833 | |
| 1834 | static struct attribute_group netiucv_attr_group = { |
| 1835 | .attrs = netiucv_attrs, |
| 1836 | }; |
| 1837 | |
| 1838 | static struct attribute *netiucv_stat_attrs[] = { |
| 1839 | &dev_attr_device_fsm_state.attr, |
| 1840 | &dev_attr_connection_fsm_state.attr, |
| 1841 | &dev_attr_max_tx_buffer_used.attr, |
| 1842 | &dev_attr_max_chained_skbs.attr, |
| 1843 | &dev_attr_tx_single_write_ops.attr, |
| 1844 | &dev_attr_tx_multi_write_ops.attr, |
| 1845 | &dev_attr_netto_bytes.attr, |
| 1846 | &dev_attr_max_tx_io_time.attr, |
| 1847 | &dev_attr_tx_pending.attr, |
| 1848 | &dev_attr_tx_max_pending.attr, |
| 1849 | NULL, |
| 1850 | }; |
| 1851 | |
| 1852 | static struct attribute_group netiucv_stat_attr_group = { |
| 1853 | .name = "stats", |
| 1854 | .attrs = netiucv_stat_attrs, |
| 1855 | }; |
| 1856 | |
Martin Schwidefsky | d461462 | 2007-06-20 13:03:57 +0200 | [diff] [blame] | 1857 | static int netiucv_add_files(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | { |
| 1859 | int ret; |
| 1860 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1861 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | ret = sysfs_create_group(&dev->kobj, &netiucv_attr_group); |
| 1863 | if (ret) |
| 1864 | return ret; |
| 1865 | ret = sysfs_create_group(&dev->kobj, &netiucv_stat_attr_group); |
| 1866 | if (ret) |
| 1867 | sysfs_remove_group(&dev->kobj, &netiucv_attr_group); |
| 1868 | return ret; |
| 1869 | } |
| 1870 | |
Martin Schwidefsky | d461462 | 2007-06-20 13:03:57 +0200 | [diff] [blame] | 1871 | static void netiucv_remove_files(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1873 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | sysfs_remove_group(&dev->kobj, &netiucv_stat_attr_group); |
| 1875 | sysfs_remove_group(&dev->kobj, &netiucv_attr_group); |
| 1876 | } |
| 1877 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1878 | static int netiucv_register_device(struct net_device *ndev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1880 | struct netiucv_priv *priv = netdev_priv(ndev); |
Eric Sesterhenn | 88abaab | 2006-03-24 03:15:31 -0800 | [diff] [blame] | 1881 | struct device *dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | int ret; |
| 1883 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1884 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | |
| 1886 | if (dev) { |
Cornelia Huck | 1bf5b28 | 2008-10-10 21:33:10 +0200 | [diff] [blame] | 1887 | dev_set_name(dev, "net%s", ndev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | dev->bus = &iucv_bus; |
| 1889 | dev->parent = iucv_root; |
| 1890 | /* |
| 1891 | * The release function could be called after the |
| 1892 | * module has been unloaded. It's _only_ task is to |
| 1893 | * free the struct. Therefore, we specify kfree() |
| 1894 | * directly here. (Probably a little bit obfuscating |
| 1895 | * but legitime ...). |
| 1896 | */ |
| 1897 | dev->release = (void (*)(struct device *))kfree; |
| 1898 | dev->driver = &netiucv_driver; |
| 1899 | } else |
| 1900 | return -ENOMEM; |
| 1901 | |
| 1902 | ret = device_register(dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1903 | if (ret) { |
| 1904 | put_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | return ret; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 1906 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | ret = netiucv_add_files(dev); |
| 1908 | if (ret) |
| 1909 | goto out_unreg; |
| 1910 | priv->dev = dev; |
Greg Kroah-Hartman | dff59b6 | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 1911 | dev_set_drvdata(dev, priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | return 0; |
| 1913 | |
| 1914 | out_unreg: |
| 1915 | device_unregister(dev); |
| 1916 | return ret; |
| 1917 | } |
| 1918 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1919 | static void netiucv_unregister_device(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | { |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1921 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | netiucv_remove_files(dev); |
| 1923 | device_unregister(dev); |
| 1924 | } |
| 1925 | |
| 1926 | /** |
| 1927 | * Allocate and initialize a new connection structure. |
| 1928 | * Add it to the list of netiucv connections; |
| 1929 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1930 | static struct iucv_connection *netiucv_new_connection(struct net_device *dev, |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1931 | char *username, |
| 1932 | char *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1934 | struct iucv_connection *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1935 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1936 | conn = kzalloc(sizeof(*conn), GFP_KERNEL); |
| 1937 | if (!conn) |
| 1938 | goto out; |
| 1939 | skb_queue_head_init(&conn->collect_queue); |
| 1940 | skb_queue_head_init(&conn->commit_queue); |
| 1941 | spin_lock_init(&conn->collect_lock); |
| 1942 | conn->max_buffsize = NETIUCV_BUFSIZE_DEFAULT; |
| 1943 | conn->netdev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1945 | conn->rx_buff = alloc_skb(conn->max_buffsize, GFP_KERNEL | GFP_DMA); |
| 1946 | if (!conn->rx_buff) |
| 1947 | goto out_conn; |
| 1948 | conn->tx_buff = alloc_skb(conn->max_buffsize, GFP_KERNEL | GFP_DMA); |
| 1949 | if (!conn->tx_buff) |
| 1950 | goto out_rx; |
| 1951 | conn->fsm = init_fsm("netiucvconn", conn_state_names, |
| 1952 | conn_event_names, NR_CONN_STATES, |
| 1953 | NR_CONN_EVENTS, conn_fsm, CONN_FSM_LEN, |
| 1954 | GFP_KERNEL); |
| 1955 | if (!conn->fsm) |
| 1956 | goto out_tx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1958 | fsm_settimer(conn->fsm, &conn->timer); |
| 1959 | fsm_newstate(conn->fsm, CONN_STATE_INVALID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1960 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1961 | if (userdata) |
| 1962 | memcpy(conn->userdata, userdata, 17); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1963 | if (username) { |
| 1964 | memcpy(conn->userid, username, 9); |
| 1965 | fsm_newstate(conn->fsm, CONN_STATE_STOPPED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1966 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1967 | |
| 1968 | write_lock_bh(&iucv_connection_rwlock); |
| 1969 | list_add_tail(&conn->list, &iucv_connection_list); |
| 1970 | write_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | return conn; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1972 | |
| 1973 | out_tx: |
| 1974 | kfree_skb(conn->tx_buff); |
| 1975 | out_rx: |
| 1976 | kfree_skb(conn->rx_buff); |
| 1977 | out_conn: |
| 1978 | kfree(conn); |
| 1979 | out: |
| 1980 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | /** |
| 1984 | * Release a connection structure and remove it from the |
| 1985 | * list of netiucv connections. |
| 1986 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1987 | static void netiucv_remove_connection(struct iucv_connection *conn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1989 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 1990 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1991 | write_lock_bh(&iucv_connection_rwlock); |
| 1992 | list_del_init(&conn->list); |
| 1993 | write_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 0be4ace | 2007-05-02 15:18:44 +0200 | [diff] [blame] | 1994 | fsm_deltimer(&conn->timer); |
| 1995 | netiucv_purge_skb_queue(&conn->collect_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1996 | if (conn->path) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 1997 | iucv_path_sever(conn->path, conn->userdata); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 1998 | kfree(conn->path); |
| 1999 | conn->path = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | } |
Ursula Braun | 0be4ace | 2007-05-02 15:18:44 +0200 | [diff] [blame] | 2001 | netiucv_purge_skb_queue(&conn->commit_queue); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2002 | kfree_fsm(conn->fsm); |
| 2003 | kfree_skb(conn->rx_buff); |
| 2004 | kfree_skb(conn->tx_buff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | /** |
| 2008 | * Release everything of a net device. |
| 2009 | */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2010 | static void netiucv_free_netdevice(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2012 | struct netiucv_priv *privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2014 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | |
| 2016 | if (!dev) |
| 2017 | return; |
| 2018 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | if (privptr) { |
| 2020 | if (privptr->conn) |
| 2021 | netiucv_remove_connection(privptr->conn); |
| 2022 | if (privptr->fsm) |
| 2023 | kfree_fsm(privptr->fsm); |
| 2024 | privptr->conn = NULL; privptr->fsm = NULL; |
| 2025 | /* privptr gets freed by free_netdev() */ |
| 2026 | } |
| 2027 | free_netdev(dev); |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * Initialize a net device. (Called from kernel in alloc_netdev()) |
| 2032 | */ |
Frank Blaschka | 4edd73b | 2009-01-09 03:43:58 +0000 | [diff] [blame] | 2033 | static const struct net_device_ops netiucv_netdev_ops = { |
| 2034 | .ndo_open = netiucv_open, |
| 2035 | .ndo_stop = netiucv_close, |
| 2036 | .ndo_get_stats = netiucv_stats, |
| 2037 | .ndo_start_xmit = netiucv_tx, |
| 2038 | .ndo_change_mtu = netiucv_change_mtu, |
| 2039 | }; |
| 2040 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2041 | static void netiucv_setup_netdevice(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | dev->mtu = NETIUCV_MTU_DEFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | dev->destructor = netiucv_free_netdevice; |
| 2045 | dev->hard_header_len = NETIUCV_HDRLEN; |
| 2046 | dev->addr_len = 0; |
| 2047 | dev->type = ARPHRD_SLIP; |
| 2048 | dev->tx_queue_len = NETIUCV_QUEUELEN_DEFAULT; |
| 2049 | dev->flags = IFF_POINTOPOINT | IFF_NOARP; |
Frank Blaschka | 4edd73b | 2009-01-09 03:43:58 +0000 | [diff] [blame] | 2050 | dev->netdev_ops = &netiucv_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | /** |
| 2054 | * Allocate and initialize everything of a net device. |
| 2055 | */ |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2056 | static struct net_device *netiucv_init_netdevice(char *username, char *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | { |
| 2058 | struct netiucv_priv *privptr; |
| 2059 | struct net_device *dev; |
| 2060 | |
| 2061 | dev = alloc_netdev(sizeof(struct netiucv_priv), "iucv%d", |
| 2062 | netiucv_setup_netdevice); |
| 2063 | if (!dev) |
| 2064 | return NULL; |
Ursula Braun | 1d50356 | 2011-11-15 02:31:14 +0000 | [diff] [blame] | 2065 | if (dev_alloc_name(dev, dev->name) < 0) |
| 2066 | goto out_netdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2068 | privptr = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2069 | privptr->fsm = init_fsm("netiucvdev", dev_state_names, |
| 2070 | dev_event_names, NR_DEV_STATES, NR_DEV_EVENTS, |
| 2071 | dev_fsm, DEV_FSM_LEN, GFP_KERNEL); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2072 | if (!privptr->fsm) |
| 2073 | goto out_netdev; |
| 2074 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2075 | privptr->conn = netiucv_new_connection(dev, username, userdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | if (!privptr->conn) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_new_connection\n"); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2078 | goto out_fsm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | } |
| 2080 | fsm_newstate(privptr->fsm, DEV_STATE_STOPPED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | return dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2082 | |
| 2083 | out_fsm: |
| 2084 | kfree_fsm(privptr->fsm); |
| 2085 | out_netdev: |
| 2086 | free_netdev(dev); |
| 2087 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | } |
| 2089 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2090 | static ssize_t conn_write(struct device_driver *drv, |
| 2091 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | { |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2093 | char username[9]; |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2094 | char userdata[17]; |
| 2095 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | struct net_device *dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2097 | struct netiucv_priv *priv; |
| 2098 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2100 | IUCV_DBF_TEXT(trace, 3, __func__); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2101 | rc = netiucv_check_user(buf, count, username, userdata); |
| 2102 | if (rc) |
| 2103 | return rc; |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2104 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2105 | read_lock_bh(&iucv_connection_rwlock); |
| 2106 | list_for_each_entry(cp, &iucv_connection_list, list) { |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2107 | if (!strncmp(username, cp->userid, 9) && |
| 2108 | !strncmp(userdata, cp->userdata, 17)) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2109 | read_unlock_bh(&iucv_connection_rwlock); |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2110 | IUCV_DBF_TEXT_(setup, 2, "conn_write: Connection to %s " |
| 2111 | "already exists\n", netiucv_printuser(cp)); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2112 | return -EEXIST; |
| 2113 | } |
Frank Pavlic | 16a83b3 | 2006-09-15 16:25:19 +0200 | [diff] [blame] | 2114 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2115 | read_unlock_bh(&iucv_connection_rwlock); |
| 2116 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2117 | dev = netiucv_init_netdevice(username, userdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | if (!dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2119 | IUCV_DBF_TEXT(setup, 2, "NULL from netiucv_init_netdevice\n"); |
| 2120 | return -ENODEV; |
| 2121 | } |
| 2122 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2123 | rc = netiucv_register_device(dev); |
| 2124 | if (rc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | IUCV_DBF_TEXT_(setup, 2, |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2126 | "ret %d from netiucv_register_device\n", rc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2127 | goto out_free_ndev; |
| 2128 | } |
| 2129 | |
| 2130 | /* sysfs magic */ |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2131 | priv = netdev_priv(dev); |
| 2132 | SET_NETDEV_DEV(dev, priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2133 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2134 | rc = register_netdev(dev); |
| 2135 | if (rc) |
| 2136 | goto out_unreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | |
Ursula Braun | 08e3356 | 2011-12-19 22:56:34 +0000 | [diff] [blame] | 2138 | dev_info(priv->dev, "The IUCV interface to %s has been established " |
| 2139 | "successfully\n", |
| 2140 | netiucv_printuser(priv->conn)); |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | return count; |
| 2143 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2144 | out_unreg: |
| 2145 | netiucv_unregister_device(priv->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2146 | out_free_ndev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | netiucv_free_netdevice(dev); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2148 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2151 | static DRIVER_ATTR(connection, 0200, NULL, conn_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2152 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2153 | static ssize_t remove_write (struct device_driver *drv, |
| 2154 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2156 | struct iucv_connection *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2157 | struct net_device *ndev; |
| 2158 | struct netiucv_priv *priv; |
| 2159 | struct device *dev; |
| 2160 | char name[IFNAMSIZ]; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2161 | const char *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2162 | int i; |
| 2163 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2164 | IUCV_DBF_TEXT(trace, 3, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2165 | |
| 2166 | if (count >= IFNAMSIZ) |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 2167 | count = IFNAMSIZ - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2168 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2169 | for (i = 0, p = buf; i < count && *p; i++, p++) { |
| 2170 | if (*p == '\n' || *p == ' ') |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | /* trailing lf, grr */ |
| 2172 | break; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2173 | name[i] = *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | } |
| 2175 | name[i] = '\0'; |
| 2176 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2177 | read_lock_bh(&iucv_connection_rwlock); |
| 2178 | list_for_each_entry(cp, &iucv_connection_list, list) { |
| 2179 | ndev = cp->netdev; |
| 2180 | priv = netdev_priv(ndev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2181 | dev = priv->dev; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2182 | if (strncmp(name, ndev->name, count)) |
| 2183 | continue; |
| 2184 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | if (ndev->flags & (IFF_UP | IFF_RUNNING)) { |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2186 | dev_warn(dev, "The IUCV device is connected" |
| 2187 | " to %s and cannot be removed\n", |
| 2188 | priv->conn->userid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | IUCV_DBF_TEXT(data, 2, "remove_write: still active\n"); |
Ursula Braun | f082bca | 2008-07-14 09:59:30 +0200 | [diff] [blame] | 2190 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | } |
| 2192 | unregister_netdev(ndev); |
| 2193 | netiucv_unregister_device(dev); |
| 2194 | return count; |
| 2195 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2196 | read_unlock_bh(&iucv_connection_rwlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | IUCV_DBF_TEXT(data, 2, "remove_write: unknown device\n"); |
| 2198 | return -EINVAL; |
| 2199 | } |
| 2200 | |
Heiko Carstens | 2b67fc4 | 2007-02-05 21:16:47 +0100 | [diff] [blame] | 2201 | static DRIVER_ATTR(remove, 0200, NULL, remove_write); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2203 | static struct attribute * netiucv_drv_attrs[] = { |
| 2204 | &driver_attr_connection.attr, |
| 2205 | &driver_attr_remove.attr, |
| 2206 | NULL, |
| 2207 | }; |
| 2208 | |
| 2209 | static struct attribute_group netiucv_drv_attr_group = { |
| 2210 | .attrs = netiucv_drv_attrs, |
| 2211 | }; |
| 2212 | |
David Brownell | a4dbd67 | 2009-06-24 10:06:31 -0700 | [diff] [blame] | 2213 | static const struct attribute_group *netiucv_drv_attr_groups[] = { |
Cornelia Huck | 5b88feb | 2007-12-05 12:50:28 +0100 | [diff] [blame] | 2214 | &netiucv_drv_attr_group, |
| 2215 | NULL, |
| 2216 | }; |
| 2217 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2218 | static void netiucv_banner(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2219 | { |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2220 | pr_info("driver initialized\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2223 | static void __exit netiucv_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2225 | struct iucv_connection *cp; |
| 2226 | struct net_device *ndev; |
| 2227 | struct netiucv_priv *priv; |
| 2228 | struct device *dev; |
| 2229 | |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2230 | IUCV_DBF_TEXT(trace, 3, __func__); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2231 | while (!list_empty(&iucv_connection_list)) { |
| 2232 | cp = list_entry(iucv_connection_list.next, |
| 2233 | struct iucv_connection, list); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2234 | ndev = cp->netdev; |
| 2235 | priv = netdev_priv(ndev); |
| 2236 | dev = priv->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | |
| 2238 | unregister_netdev(ndev); |
| 2239 | netiucv_unregister_device(dev); |
| 2240 | } |
| 2241 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2242 | device_unregister(netiucv_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | driver_unregister(&netiucv_driver); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2244 | iucv_unregister(&netiucv_handler, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | iucv_unregister_dbf_views(); |
| 2246 | |
Ursula Braun | 8f7c502 | 2008-12-25 13:39:47 +0100 | [diff] [blame] | 2247 | pr_info("driver unloaded\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | return; |
| 2249 | } |
| 2250 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2251 | static int __init netiucv_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2252 | { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2253 | int rc; |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2254 | |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2255 | rc = iucv_register_dbf_views(); |
| 2256 | if (rc) |
| 2257 | goto out; |
| 2258 | rc = iucv_register(&netiucv_handler, 1); |
| 2259 | if (rc) |
| 2260 | goto out_dbf; |
Harvey Harrison | 2a2cf6b | 2008-04-17 07:46:21 +0200 | [diff] [blame] | 2261 | IUCV_DBF_TEXT(trace, 3, __func__); |
Cornelia Huck | 0a0a831 | 2008-04-24 10:15:28 +0200 | [diff] [blame] | 2262 | netiucv_driver.groups = netiucv_drv_attr_groups; |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2263 | rc = driver_register(&netiucv_driver); |
| 2264 | if (rc) { |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2265 | IUCV_DBF_TEXT_(setup, 2, "ret %d from driver_register\n", rc); |
| 2266 | goto out_iucv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2267 | } |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2268 | /* establish dummy device */ |
| 2269 | netiucv_dev = kzalloc(sizeof(struct device), GFP_KERNEL); |
| 2270 | if (!netiucv_dev) { |
| 2271 | rc = -ENOMEM; |
| 2272 | goto out_driver; |
| 2273 | } |
| 2274 | dev_set_name(netiucv_dev, "netiucv"); |
| 2275 | netiucv_dev->bus = &iucv_bus; |
| 2276 | netiucv_dev->parent = iucv_root; |
| 2277 | netiucv_dev->release = (void (*)(struct device *))kfree; |
| 2278 | netiucv_dev->driver = &netiucv_driver; |
| 2279 | rc = device_register(netiucv_dev); |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 2280 | if (rc) { |
| 2281 | put_device(netiucv_dev); |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2282 | goto out_driver; |
Sebastian Ott | c630493 | 2009-09-11 10:28:38 +0200 | [diff] [blame] | 2283 | } |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2284 | netiucv_banner(); |
| 2285 | return rc; |
| 2286 | |
Ursula Braun | 1175b25 | 2009-06-16 10:30:43 +0200 | [diff] [blame] | 2287 | out_driver: |
| 2288 | driver_unregister(&netiucv_driver); |
Martin Schwidefsky | eebce38 | 2007-02-08 13:50:33 -0800 | [diff] [blame] | 2289 | out_iucv: |
| 2290 | iucv_unregister(&netiucv_handler, 1); |
| 2291 | out_dbf: |
| 2292 | iucv_unregister_dbf_views(); |
| 2293 | out: |
| 2294 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | } |
Jeff Garzik | e82b0f2 | 2006-05-26 21:58:38 -0400 | [diff] [blame] | 2296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2297 | module_init(netiucv_init); |
| 2298 | module_exit(netiucv_exit); |
| 2299 | MODULE_LICENSE("GPL"); |