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