38 #define KMSG_COMPONENT "netiucv"
39 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
43 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/slab.h>
47 #include <linux/errno.h>
48 #include <linux/types.h>
51 #include <linux/bitops.h>
53 #include <linux/signal.h>
54 #include <linux/string.h>
55 #include <linux/device.h>
58 #include <linux/if_arp.h>
59 #include <linux/tcp.h>
61 #include <linux/ctype.h>
65 #include <asm/uaccess.h>
78 #define IUCV_DBF_SETUP_NAME "iucv_setup"
79 #define IUCV_DBF_SETUP_LEN 64
80 #define IUCV_DBF_SETUP_PAGES 2
81 #define IUCV_DBF_SETUP_NR_AREAS 1
82 #define IUCV_DBF_SETUP_LEVEL 3
84 #define IUCV_DBF_DATA_NAME "iucv_data"
85 #define IUCV_DBF_DATA_LEN 128
86 #define IUCV_DBF_DATA_PAGES 2
87 #define IUCV_DBF_DATA_NR_AREAS 1
88 #define IUCV_DBF_DATA_LEVEL 2
90 #define IUCV_DBF_TRACE_NAME "iucv_trace"
91 #define IUCV_DBF_TRACE_LEN 16
92 #define IUCV_DBF_TRACE_PAGES 4
93 #define IUCV_DBF_TRACE_NR_AREAS 1
94 #define IUCV_DBF_TRACE_LEVEL 3
96 #define IUCV_DBF_TEXT(name,level,text) \
98 debug_text_event(iucv_dbf_##name,level,text); \
101 #define IUCV_DBF_HEX(name,level,addr,len) \
103 debug_event(iucv_dbf_##name,level,(void*)(addr),len); \
111 return (level <= dbf_grp->level);
114 #define IUCV_DBF_TEXT_(name, level, text...) \
116 if (iucv_dbf_passes(iucv_dbf_##name, level)) { \
117 char* __buf = get_cpu_var(iucv_dbf_txt_buf); \
118 sprintf(__buf, text); \
119 debug_text_event(iucv_dbf_##name, level, __buf); \
120 put_cpu_var(iucv_dbf_txt_buf); \
124 #define IUCV_DBF_SPRINTF(name,level,text...) \
126 debug_sprintf_event(iucv_dbf_trace, level, ##text ); \
127 debug_sprintf_event(iucv_dbf_trace, level, text ); \
133 #define IUCV_HEXDUMP16(importance,header,ptr) \
134 PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
135 "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
136 *(((char*)ptr)),*(((char*)ptr)+1),*(((char*)ptr)+2), \
137 *(((char*)ptr)+3),*(((char*)ptr)+4),*(((char*)ptr)+5), \
138 *(((char*)ptr)+6),*(((char*)ptr)+7),*(((char*)ptr)+8), \
139 *(((char*)ptr)+9),*(((char*)ptr)+10),*(((char*)ptr)+11), \
140 *(((char*)ptr)+12),*(((char*)ptr)+13), \
141 *(((char*)ptr)+14),*(((char*)ptr)+15)); \
142 PRINT_##importance(header "%02x %02x %02x %02x %02x %02x %02x %02x " \
143 "%02x %02x %02x %02x %02x %02x %02x %02x\n", \
144 *(((char*)ptr)+16),*(((char*)ptr)+17), \
145 *(((char*)ptr)+18),*(((char*)ptr)+19), \
146 *(((char*)ptr)+20),*(((char*)ptr)+21), \
147 *(((char*)ptr)+22),*(((char*)ptr)+23), \
148 *(((char*)ptr)+24),*(((char*)ptr)+25), \
149 *(((char*)ptr)+26),*(((char*)ptr)+27), \
150 *(((char*)ptr)+28),*(((char*)ptr)+29), \
151 *(((char*)ptr)+30),*(((char*)ptr)+31));
153 #define PRINTK_HEADER " iucv: "
156 static struct device *netiucv_dev;
158 static int netiucv_pm_prepare(
struct device *);
159 static void netiucv_pm_complete(
struct device *);
160 static int netiucv_pm_freeze(
struct device *);
161 static int netiucv_pm_restore_thaw(
struct device *);
163 static const struct dev_pm_ops netiucv_pm_ops = {
164 .prepare = netiucv_pm_prepare,
165 .complete = netiucv_pm_complete,
166 .freeze = netiucv_pm_freeze,
167 .thaw = netiucv_pm_restore_thaw,
168 .restore = netiucv_pm_restore_thaw,
175 .pm = &netiucv_pm_ops,
178 static int netiucv_callback_connreq(
struct iucv_path *,
188 .path_pending = netiucv_callback_connreq,
189 .path_complete = netiucv_callback_connack,
190 .path_severed = netiucv_callback_connrej,
191 .path_quiesced = netiucv_callback_connsusp,
192 .path_resumed = netiucv_callback_connres,
193 .message_pending = netiucv_callback_rx,
194 .message_complete = netiucv_callback_txdone
267 #define NETIUCV_HDRLEN (sizeof(struct ll_header))
268 #define NETIUCV_BUFSIZE_MAX 65537
269 #define NETIUCV_BUFSIZE_DEFAULT NETIUCV_BUFSIZE_MAX
270 #define NETIUCV_MTU_MAX (NETIUCV_BUFSIZE_MAX - NETIUCV_HDRLEN)
271 #define NETIUCV_MTU_DEFAULT 9216
272 #define NETIUCV_QUEUELEN_DEFAULT 50
273 #define NETIUCV_TIMEOUT_5SEC 5000
279 static inline void netiucv_clear_busy(
struct net_device *
dev)
283 netif_wake_queue(dev);
286 static inline int netiucv_test_and_set_busy(
struct net_device *
dev)
289 netif_stop_queue(dev);
293 static u8 iucvMagic_ascii[16] = {
294 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
295 0x30, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
298 static u8 iucvMagic_ebcdic[16] = {
299 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
300 0xF0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40
311 static char *netiucv_printname(
char *
name,
int len)
317 while (*p && ((p - tmp) < len) && (!
isspace(*p)))
325 static char tmp_uid[9];
326 static char tmp_udat[17];
327 static char buf[100];
333 memcpy(tmp_uid, netiucv_printname(tmp_uid, 8), 8);
336 memcpy(tmp_udat, netiucv_printname(tmp_udat, 16), 16);
337 sprintf(buf,
"%s.%s", tmp_uid, tmp_udat);
340 return netiucv_printname(conn->
userid, 8);
423 static const char *conn_event_names[] = {
424 "Remote connection request",
425 "Remote connection acknowledge",
426 "Remote connection reject",
427 "Connection suspended",
428 "Connection resumed",
492 static const char *conn_state_names[] = {
500 "Registration error",
514 static void iucv_unregister_dbf_views(
void)
523 static int iucv_register_dbf_views(
void)
538 if ((iucv_dbf_setup ==
NULL) || (iucv_dbf_data ==
NULL) ||
539 (iucv_dbf_trace ==
NULL)) {
540 iucv_unregister_dbf_views();
593 static char tmp_user[9];
594 static char tmp_udat[17];
598 memcpy(tmp_user, netiucv_printname(ipvmid, 8), 8);
599 memcpy(tmp_udat, ipuser, 16);
614 tmp_user, netiucv_printname(tmp_udat, 16));
619 static void netiucv_callback_connrej(
struct iucv_path *path,
u8 ipuser[16])
626 static void netiucv_callback_connsusp(
struct iucv_path *path,
u8 ipuser[16])
633 static void netiucv_callback_connres(
struct iucv_path *path,
u8 ipuser[16])
680 offset += header->
next;
682 if (skb_tailroom(pskb) < header->
next) {
684 header->
next, skb_tailroom(pskb));
688 skb_reset_mac_header(pskb);
689 skb = dev_alloc_skb(pskb->
len);
692 "Out of memory in netiucv_unpack_skb\n");
693 privptr->
stats.rx_dropped++;
696 skb_copy_from_linear_data(pskb,
skb_put(skb, pskb->
len),
698 skb_reset_mac_header(skb);
702 privptr->
stats.rx_packets++;
703 privptr->
stats.rx_bytes += skb->
len;
727 "Received data for unlinked connection\n");
732 privptr->
stats.rx_dropped++;
738 skb_reset_tail_pointer(conn->
rx_buff);
742 if (rc || msg->
length < 5) {
743 privptr->
stats.rx_errors++;
747 netiucv_unpack_skb(conn, conn->
rx_buff);
750 static void conn_action_txdone(
fsm_instance *fi,
int event,
void *arg)
757 u32 single_flag = msg->
tag;
762 unsigned long saveflags;
769 privptr = netdev_priv(conn->
netdev);
770 conn->
prof.tx_pending--;
775 privptr->
stats.tx_packets++;
776 privptr->
stats.tx_bytes +=
784 skb_reset_tail_pointer(conn->
tx_buff);
791 skb_copy_from_linear_data(skb,
816 conn->
prof.doios_multi++;
818 conn->
prof.tx_pending++;
819 if (conn->
prof.tx_pending > conn->
prof.tx_max_pending)
820 conn->
prof.tx_max_pending = conn->
prof.tx_pending;
822 conn->
prof.tx_pending--;
825 privptr->
stats.tx_errors += txpackets;
829 privptr->
stats.tx_packets += txpackets;
830 privptr->
stats.tx_bytes += txbytes;
832 if (stat_maxcq > conn->
prof.maxcqueue)
833 conn->
prof.maxcqueue = stat_maxcq;
837 static void conn_action_connaccept(
fsm_instance *fi,
int event,
void *arg)
851 rc = iucv_path_accept(path, &netiucv_handler, conn->
userdata , conn);
861 static void conn_action_connreject(
fsm_instance *fi,
int event,
void *arg)
870 static void conn_action_connack(
fsm_instance *fi,
int event,
void *arg)
883 static void conn_action_conntimsev(
fsm_instance *fi,
int event,
void *arg)
893 static void conn_action_connsever(
fsm_instance *fi,
int event,
void *arg)
903 dev_info(privptr->
dev,
"The peer z/VM guest %s has closed the "
904 "connection\n", netiucv_printuser(conn));
906 "conn_action_connsever: Remote dropped connection\n");
911 static void conn_action_start(
fsm_instance *fi,
int event,
void *arg)
931 netdev->
name, netiucv_printuser(conn));
933 rc = iucv_path_connect(conn->
path, &netiucv_handler, conn->
userid,
943 "The IUCV device failed to connect to z/VM guest %s\n",
944 netiucv_printname(conn->
userid, 8));
949 "The IUCV device failed to connect to the peer on z/VM"
950 " guest %s\n", netiucv_printname(conn->
userid, 8));
955 "Connecting the IUCV device would exceed the maximum"
956 " number of IUCV connections\n");
961 "z/VM guest %s has too many IUCV connections"
962 " to connect with the IUCV device\n",
963 netiucv_printname(conn->
userid, 8));
968 "The IUCV device cannot connect to a z/VM guest with no"
969 " IUCV authorization\n");
974 "Connecting the IUCV device failed with error %d\n",
994 static void conn_action_stop(
fsm_instance *fi,
int event,
void *arg)
1016 static void conn_action_inval(
fsm_instance *fi,
int event,
void *arg)
1025 static const fsm_node conn_fsm[] = {
1057 static const int CONN_FSM_LEN =
sizeof(conn_fsm) /
sizeof(
fsm_node);
1072 static void dev_action_start(
fsm_instance *fi,
int event,
void *arg)
1091 dev_action_stop(
fsm_instance *fi,
int event,
void *arg)
1114 dev_action_connup(
fsm_instance *fi,
int event,
void *arg)
1121 switch (fsm_getstate(fi)) {
1125 "The IUCV device has been connected"
1126 " successfully to %s\n",
1127 netiucv_printuser(privptr->
conn));
1129 "connection is up and running\n");
1133 "dev_action_connup: in DEV_STATE_STOPWAIT\n");
1147 dev_action_conndown(
fsm_instance *fi,
int event,
void *arg)
1151 switch (fsm_getstate(fi)) {
1193 unsigned long saveflags;
1205 "EBUSY from netiucv_transmit_skb\n");
1212 spin_unlock_irqrestore(&conn->
collect_lock, saveflags);
1219 unsigned long hi = ((
unsigned long)(skb_tail_pointer(skb) +
1222 if (hi || (skb_tailroom(skb) < 2)) {
1251 conn->
prof.doios_single++;
1253 conn->
prof.tx_pending++;
1254 if (conn->
prof.tx_pending > conn->
prof.tx_max_pending)
1255 conn->
prof.tx_max_pending = conn->
prof.tx_pending;
1259 conn->
prof.tx_pending--;
1260 privptr = netdev_priv(conn->
netdev);
1262 privptr->
stats.tx_errors++;
1264 dev_kfree_skb(nskb);
1297 static int netiucv_open(
struct net_device *dev)
1313 static int netiucv_close(
struct net_device *dev)
1321 static int netiucv_pm_prepare(
struct device *dev)
1327 static void netiucv_pm_complete(
struct device *dev)
1339 static int netiucv_pm_freeze(
struct device *dev)
1346 if (priv && priv->
conn)
1347 ndev = priv->
conn->netdev;
1352 rc = netiucv_close(ndev);
1363 static int netiucv_pm_restore_thaw(
struct device *dev)
1370 if (priv && priv->
conn)
1371 ndev = priv->
conn->netdev;
1377 rc = netiucv_open(ndev);
1409 privptr->
stats.tx_dropped++;
1414 "netiucv_tx: skb_headroom < NETIUCV_HDRLEN\n");
1416 privptr->
stats.tx_dropped++;
1426 privptr->
stats.tx_dropped++;
1427 privptr->
stats.tx_errors++;
1428 privptr->
stats.tx_carrier_errors++;
1432 if (netiucv_test_and_set_busy(dev)) {
1437 rc = netiucv_transmit_skb(privptr->
conn, skb);
1438 netiucv_clear_busy(dev);
1455 return &priv->
stats;
1468 static int netiucv_change_mtu(
struct net_device * dev,
int new_mtu)
1489 return sprintf(buf,
"%s\n", netiucv_printuser(priv->
conn));
1492 static int netiucv_check_user(
const char *buf,
size_t count,
char *username,
1499 if ((p && ((count > 26) ||
1501 (buf + count - p > 18))) ||
1502 (!p && (count > 9))) {
1507 for (i = 0, p = buf; i < 8 && *p && *p !=
'.'; i++, p++) {
1508 if (
isalnum(*p) || *p ==
'$') {
1516 "conn_write: invalid character %02x\n", *p);
1520 username[i++] =
' ';
1525 for (i = 0; i < 16 && *
p; i++, p++) {
1530 while (i > 0 && i < 16)
1531 userdata[i++] =
' ';
1533 memcpy(userdata, iucvMagic_ascii, 16);
1534 userdata[16] =
'\0';
1541 const char *buf,
size_t count)
1551 rc = netiucv_check_user(buf, count, username, userdata);
1555 if (
memcmp(username, priv->
conn->userid, 9) &&
1567 "already exists\n", netiucv_printuser(cp));
1585 return sprintf(buf,
"%d\n", priv->
conn->max_buffsize);
1589 const char *buf,
size_t count)
1609 "buffer_write: buffer size %d too large\n",
1616 "buffer_write: buffer size %d too small\n",
1622 "buffer_write: buffer size %d too small\n",
1627 priv->
conn->max_buffsize = bs1;
1665 return sprintf(buf,
"%ld\n", priv->
conn->prof.maxmulti);
1670 const char *buf,
size_t count)
1675 priv->
conn->prof.maxmulti = 0;
1679 static DEVICE_ATTR(max_tx_buffer_used, 0644, maxmulti_show, maxmulti_write);
1687 return sprintf(buf,
"%ld\n", priv->
conn->prof.maxcqueue);
1691 const char *buf,
size_t count)
1696 priv->
conn->prof.maxcqueue = 0;
1700 static DEVICE_ATTR(max_chained_skbs, 0644, maxcq_show, maxcq_write);
1708 return sprintf(buf,
"%ld\n", priv->
conn->prof.doios_single);
1712 const char *buf,
size_t count)
1717 priv->
conn->prof.doios_single = 0;
1721 static DEVICE_ATTR(tx_single_write_ops, 0644, sdoio_show, sdoio_write);
1729 return sprintf(buf,
"%ld\n", priv->
conn->prof.doios_multi);
1733 const char *buf,
size_t count)
1738 priv->
conn->prof.doios_multi = 0;
1742 static DEVICE_ATTR(tx_multi_write_ops, 0644, mdoio_show, mdoio_write);
1750 return sprintf(buf,
"%ld\n", priv->
conn->prof.txlen);
1754 const char *buf,
size_t count)
1759 priv->
conn->prof.txlen = 0;
1763 static DEVICE_ATTR(netto_bytes, 0644, txlen_show, txlen_write);
1771 return sprintf(buf,
"%ld\n", priv->
conn->prof.tx_time);
1775 const char *buf,
size_t count)
1780 priv->
conn->prof.tx_time = 0;
1784 static DEVICE_ATTR(max_tx_io_time, 0644, txtime_show, txtime_write);
1792 return sprintf(buf,
"%ld\n", priv->
conn->prof.tx_pending);
1796 const char *buf,
size_t count)
1801 priv->
conn->prof.tx_pending = 0;
1813 return sprintf(buf,
"%ld\n", priv->
conn->prof.tx_max_pending);
1817 const char *buf,
size_t count)
1822 priv->
conn->prof.tx_max_pending = 0;
1826 static DEVICE_ATTR(tx_max_pending, 0644, txmpnd_show, txmpnd_write);
1828 static struct attribute *netiucv_attrs[] = {
1829 &dev_attr_buffer.attr,
1830 &dev_attr_user.attr,
1835 .attrs = netiucv_attrs,
1838 static struct attribute *netiucv_stat_attrs[] = {
1839 &dev_attr_device_fsm_state.attr,
1840 &dev_attr_connection_fsm_state.attr,
1841 &dev_attr_max_tx_buffer_used.attr,
1842 &dev_attr_max_chained_skbs.attr,
1843 &dev_attr_tx_single_write_ops.attr,
1844 &dev_attr_tx_multi_write_ops.attr,
1845 &dev_attr_netto_bytes.attr,
1846 &dev_attr_max_tx_io_time.attr,
1847 &dev_attr_tx_pending.attr,
1848 &dev_attr_tx_max_pending.attr,
1854 .attrs = netiucv_stat_attrs,
1858 &netiucv_stat_attr_group,
1859 &netiucv_attr_group,
1863 static int netiucv_register_device(
struct net_device *ndev)
1875 dev->
groups = netiucv_attr_groups;
1884 dev->
driver = &netiucv_driver;
1898 static void netiucv_unregister_device(
struct device *dev)
1929 conn->
fsm =
init_fsm(
"netiucvconn", conn_state_names,
1970 list_del_init(&conn->
list);
1988 static void netiucv_free_netdevice(
struct net_device *dev)
1999 netiucv_remove_connection(privptr->
conn);
2012 .ndo_open = netiucv_open,
2013 .ndo_stop = netiucv_close,
2014 .ndo_get_stats = netiucv_stats,
2015 .ndo_start_xmit = netiucv_tx,
2016 .ndo_change_mtu = netiucv_change_mtu,
2019 static void netiucv_setup_netdevice(
struct net_device *dev)
2034 static struct net_device *netiucv_init_netdevice(
char *username,
char *userdata)
2040 netiucv_setup_netdevice);
2046 privptr = netdev_priv(dev);
2047 privptr->
fsm =
init_fsm(
"netiucvdev", dev_state_names,
2053 privptr->
conn = netiucv_new_connection(dev, username, userdata);
2054 if (!privptr->
conn) {
2069 const char *buf,
size_t count)
2079 rc = netiucv_check_user(buf, count, username, userdata);
2089 "already exists\n", netiucv_printuser(cp));
2095 dev = netiucv_init_netdevice(username, userdata);
2101 rc = netiucv_register_device(dev);
2104 "ret %d from netiucv_register_device\n", rc);
2109 priv = netdev_priv(dev);
2116 dev_info(priv->
dev,
"The IUCV interface to %s has been established "
2118 netiucv_printuser(priv->
conn));
2123 netiucv_unregister_device(priv->
dev);
2125 netiucv_free_netdevice(dev);
2132 const char *buf,
size_t count)
2147 for (i = 0, p = buf; i < count && *
p; i++, p++) {
2148 if (*p ==
'\n' || *p ==
' ')
2158 priv = netdev_priv(ndev);
2164 dev_warn(dev,
"The IUCV device is connected"
2165 " to %s and cannot be removed\n",
2166 priv->
conn->userid);
2171 netiucv_unregister_device(dev);
2181 static struct attribute * netiucv_drv_attrs[] = {
2182 &driver_attr_connection.attr,
2183 &driver_attr_remove.attr,
2188 .attrs = netiucv_drv_attrs,
2192 &netiucv_drv_attr_group,
2196 static void netiucv_banner(
void)
2198 pr_info(
"driver initialized\n");
2201 static void __exit netiucv_exit(
void)
2209 while (!list_empty(&iucv_connection_list)) {
2213 priv = netdev_priv(ndev);
2217 netiucv_unregister_device(dev);
2223 iucv_unregister_dbf_views();
2229 static int __init netiucv_init(
void)
2233 rc = iucv_register_dbf_views();
2240 netiucv_driver.
groups = netiucv_drv_attr_groups;
2256 netiucv_dev->
driver = &netiucv_driver;
2270 iucv_unregister_dbf_views();