blob: 2914a1a69f8300a36c1bf0580094532cb9ccecd4 [file] [log] [blame]
Greg Kroah-Hartmanab9953f2017-11-14 18:38:04 +01001// SPDX-License-Identifier: GPL-2.0
Frank Blaschka4a71df52008-02-15 09:19:42 +01002/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02003 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01004 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
5 * Frank Pavlic <fpavlic@de.ibm.com>,
6 * Thomas Spatzier <tspat@de.ibm.com>,
7 * Frank Blaschka <frank.blaschka@de.ibm.com>
8 */
9
Frank Blaschka74eacdb2008-12-25 13:39:49 +010010#define KMSG_COMPONENT "qeth"
11#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
Frank Blaschka4a71df52008-02-15 09:19:42 +010013#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/string.h>
16#include <linux/errno.h>
17#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010019#include <linux/etherdevice.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000020#include <linux/list.h>
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020021#include <linux/hash.h>
22#include <linux/hashtable.h>
Julian Wiedmannec61bd22017-06-20 16:00:34 +020023#include <asm/setup.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010024#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010025#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
Frank Blaschka4a71df52008-02-15 09:19:42 +010027static int qeth_l2_set_offline(struct ccwgroup_device *);
28static int qeth_l2_stop(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010029static void qeth_bridgeport_query_support(struct qeth_card *card);
30static void qeth_bridge_state_change(struct qeth_card *card,
31 struct qeth_ipa_cmd *cmd);
32static void qeth_bridge_host_event(struct qeth_card *card,
33 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020034static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020035static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020036static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
37 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010038
Frank Blaschka4a71df52008-02-15 09:19:42 +010039static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
40{
41 struct qeth_card *card;
42 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020043 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010044 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020045 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010046
47 ndev = NULL;
48 memcpy(&temp_dev_no, read_dev_no, 2);
49 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
50 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020051 ccw_device_get_id(CARD_RDEV(card), &read_devid);
52 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010053 ndev = card->dev;
54 break;
55 }
56 }
57 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
58 return ndev;
59}
60
Julian Wiedmann2aa48672017-09-18 21:18:20 +020061static int qeth_setdelmac_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010062{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010063 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010064
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010065 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010066 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010067 switch (retcode) {
68 case IPA_RC_SUCCESS:
69 rc = 0;
70 break;
71 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020072 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010073 break;
74 case IPA_RC_L2_ADDR_TABLE_FULL:
75 rc = -ENOSPC;
76 break;
77 case IPA_RC_L2_DUP_MAC:
78 case IPA_RC_L2_DUP_LAYER3_MAC:
79 rc = -EEXIST;
80 break;
81 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
82 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
83 rc = -EPERM;
84 break;
85 case IPA_RC_L2_MAC_NOT_FOUND:
86 rc = -ENOENT;
87 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +010088 case -ENOMEM:
89 rc = -ENOMEM;
90 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010091 default:
92 rc = -EIO;
93 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010094 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010095 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010096}
97
Julian Wiedmannac988d72017-01-12 15:48:41 +010098static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
99 enum qeth_ipa_cmds ipacmd)
100{
101 struct qeth_ipa_cmd *cmd;
102 struct qeth_cmd_buffer *iob;
103
104 QETH_CARD_TEXT(card, 2, "L2sdmac");
105 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
106 if (!iob)
107 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100108 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100109 cmd->data.setdelmac.mac_length = ETH_ALEN;
110 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200111 return qeth_setdelmac_makerc(card, qeth_send_ipa_cmd(card, iob,
112 NULL, NULL));
Julian Wiedmannac988d72017-01-12 15:48:41 +0100113}
114
115static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
116{
117 int rc;
118
119 QETH_CARD_TEXT(card, 2, "L2Setmac");
120 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
121 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100122 dev_info(&card->gdev->dev,
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200123 "MAC address %pM successfully registered on device %s\n",
124 mac, card->dev->name);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100125 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100126 switch (rc) {
127 case -EEXIST:
128 dev_warn(&card->gdev->dev,
129 "MAC address %pM already exists\n", mac);
130 break;
131 case -EPERM:
132 dev_warn(&card->gdev->dev,
133 "MAC address %pM is not authorized\n", mac);
134 break;
135 }
136 }
137 return rc;
138}
139
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100140static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100141{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200142 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100143 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100144 int rc;
145
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100146 QETH_CARD_TEXT(card, 2, "L2Wmac");
147 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100148 if (rc == -EEXIST)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100149 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
150 CARD_DEVID(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100151 else if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100152 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
153 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100154 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100155}
156
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100157static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100158{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200159 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100160 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100161 int rc;
162
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100163 QETH_CARD_TEXT(card, 2, "L2Rmac");
164 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100165 if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100166 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
167 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100168 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169}
170
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100171static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200172{
173 struct qeth_mac *mac;
174 struct hlist_node *tmp;
175 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100176
177 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200178 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200179 hash_del(&mac->hnode);
180 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100181 }
182 spin_unlock_bh(&card->mclock);
183}
184
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200185static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100186{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000187 if (card->info.type == QETH_CARD_TYPE_OSN)
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200188 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000189 if (is_broadcast_ether_addr(skb->data))
190 return RTN_BROADCAST;
191 if (is_multicast_ether_addr(skb->data))
192 return RTN_MULTICAST;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200193 return RTN_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100194}
195
Julian Wiedmannfc696602018-09-17 17:35:55 +0200196static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
197 struct sk_buff *skb, int ipv, int cast_type,
198 unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100199{
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200200 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200202 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100203
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200204 if (skb_is_gso(skb)) {
205 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
206 } else {
207 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
208 if (skb->ip_summed == CHECKSUM_PARTIAL) {
209 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
210 if (card->options.performance_stats)
211 card->perf_stats.tx_csum++;
212 }
Julian Wiedmannfc696602018-09-17 17:35:55 +0200213 }
214
Frank Blaschka4a71df52008-02-15 09:19:42 +0100215 /* set byte byte 3 to casting flags */
216 if (cast_type == RTN_MULTICAST)
217 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
218 else if (cast_type == RTN_BROADCAST)
219 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
220 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000221 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100222
Frank Blaschka4a71df52008-02-15 09:19:42 +0100223 /* VSWITCH relies on the VLAN
224 * information to be present in
225 * the QDIO header */
226 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
227 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
228 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
229 }
230}
231
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200232static int qeth_setdelvlan_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100233{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200234 if (retcode)
235 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
236
237 switch (retcode) {
238 case IPA_RC_SUCCESS:
239 return 0;
240 case IPA_RC_L2_INVALID_VLAN_ID:
241 return -EINVAL;
242 case IPA_RC_L2_DUP_VLAN_ID:
243 return -EEXIST;
244 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
245 return -ENOENT;
246 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
247 return -EPERM;
248 case -ENOMEM:
249 return -ENOMEM;
250 default:
251 return -EIO;
252 }
253}
254
255static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
256 struct qeth_reply *reply,
257 unsigned long data)
258{
259 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100260
Carsten Otte847a50f2010-06-21 22:57:05 +0000261 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100262 if (cmd->hdr.return_code) {
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100263 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200264 cmd->data.setdelvlan.vlan_id,
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100265 CARD_DEVID(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000266 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
267 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100268 }
269 return 0;
270}
271
272static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200273 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274{
275 struct qeth_ipa_cmd *cmd;
276 struct qeth_cmd_buffer *iob;
277
Carsten Otte847a50f2010-06-21 22:57:05 +0000278 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100280 if (!iob)
281 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100282 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100283 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200284 return qeth_setdelvlan_makerc(card, qeth_send_ipa_cmd(card, iob,
285 qeth_l2_send_setdelvlan_cb, NULL));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286}
287
Ursula Braun70919e22011-02-26 22:41:36 -0800288static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100289{
290 struct qeth_vlan_vid *id;
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200291
Carsten Otte847a50f2010-06-21 22:57:05 +0000292 QETH_CARD_TEXT(card, 3, "L2prcvln");
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200293 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800295 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100296 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200297 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100298}
299
Patrick McHardy80d5c362013-04-19 02:04:28 +0000300static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
301 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302{
Heiko Carstens509e2562008-07-26 02:24:10 -0700303 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100305 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306
Carsten Otte847a50f2010-06-21 22:57:05 +0000307 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000308 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500309 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000310 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000311 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500312 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000313 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200314 id = kmalloc(sizeof(*id), GFP_KERNEL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315 if (id) {
316 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100317 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
318 if (rc) {
319 kfree(id);
320 return rc;
321 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200322 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323 list_add_tail(&id->list, &card->vid_list);
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200324 mutex_unlock(&card->vid_list_mutex);
Jiri Pirko8e586132011-12-08 19:52:37 -0500325 } else {
326 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500328 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329}
330
Patrick McHardy80d5c362013-04-19 02:04:28 +0000331static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
332 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100333{
334 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700335 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100336 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100337
Carsten Otte847a50f2010-06-21 22:57:05 +0000338 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000339 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000340 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500341 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000342 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200343 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100344 list_for_each_entry(id, &card->vid_list, list) {
345 if (id->vid == vid) {
346 list_del(&id->list);
347 tmpid = id;
348 break;
349 }
350 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200351 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100353 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100354 kfree(tmpid);
355 }
Thomas Richter1aec42b2015-01-21 13:39:10 +0100356 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357}
358
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200359static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100360{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200361 QETH_DBF_TEXT(SETUP , 2, "stopcard");
362 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363
364 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365 if (card->read.state == CH_STATE_UP &&
366 card->write.state == CH_STATE_UP &&
367 (card->state == CARD_STATE_UP)) {
368 if (recovery_mode &&
369 card->info.type != QETH_CARD_TYPE_OSN) {
370 qeth_l2_stop(card->dev);
371 } else {
372 rtnl_lock();
373 dev_close(card->dev);
374 rtnl_unlock();
375 }
Ursula Braun70919e22011-02-26 22:41:36 -0800376 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100377 card->state = CARD_STATE_SOFTSETUP;
378 }
379 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100380 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100381 qeth_clear_ipacmd_list(card);
382 card->state = CARD_STATE_HARDSETUP;
383 }
384 if (card->state == CARD_STATE_HARDSETUP) {
385 qeth_qdio_clear_card(card, 0);
386 qeth_clear_qdio_buffers(card);
387 qeth_clear_working_pool_list(card);
388 card->state = CARD_STATE_DOWN;
389 }
390 if (card->state == CARD_STATE_DOWN) {
391 qeth_clear_cmd_buffers(&card->read);
392 qeth_clear_cmd_buffers(&card->write);
393 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394}
395
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000396static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
397 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100398{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000399 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100400 struct sk_buff *skb;
401 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100402 unsigned int len;
403
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000404 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000405 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000406 while (budget) {
407 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000408 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000409 &card->rx.b_element, &card->rx.e_offset, &hdr);
410 if (!skb) {
411 *done = 1;
412 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100413 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414 switch (hdr->hdr.l2.id) {
415 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100416 skb->protocol = eth_type_trans(skb, skb->dev);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200417 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
Ursula Braun12883722008-04-01 10:26:56 +0200418 if (skb->protocol == htons(ETH_P_802_2))
419 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100420 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200421 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422 break;
423 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200424 if (card->info.type == QETH_CARD_TYPE_OSN) {
425 skb_push(skb, sizeof(struct qeth_hdr));
426 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200428 len = skb->len;
429 card->osn_info.data_cb(skb);
430 break;
431 }
432 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433 default:
434 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000435 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +0200436 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 continue;
438 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000439 work_done++;
440 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 card->stats.rx_packets++;
442 card->stats.rx_bytes += len;
443 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000444 return work_done;
445}
446
Frank Blaschka4a71df52008-02-15 09:19:42 +0100447static int qeth_l2_request_initial_mac(struct qeth_card *card)
448{
449 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100450
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200451 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200452 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100453
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200454 if (MACHINE_IS_VM) {
455 rc = qeth_vm_request_mac(card);
456 if (!rc)
457 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100458 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
459 CARD_DEVID(card), rc);
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200460 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
461 /* fall back to alternative mechanism: */
462 }
463
Ursula Braun5113fec2010-05-16 21:15:14 +0000464 if (card->info.type == QETH_CARD_TYPE_IQD ||
465 card->info.type == QETH_CARD_TYPE_OSM ||
466 card->info.type == QETH_CARD_TYPE_OSX ||
467 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100468 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200469 if (!rc)
470 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100471 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
472 CARD_DEVID(card), rc);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200473 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
474 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100475 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200476
477 /* some devices don't support a custom MAC address: */
478 if (card->info.type == QETH_CARD_TYPE_OSM ||
479 card->info.type == QETH_CARD_TYPE_OSX)
480 return (rc) ? rc : -EADDRNOTAVAIL;
481 eth_hw_addr_random(card->dev);
482
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200483out:
484 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100485 return 0;
486}
487
488static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
489{
490 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700491 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200492 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 int rc = 0;
494
Carsten Otte847a50f2010-06-21 22:57:05 +0000495 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100496
Ursula Braun5113fec2010-05-16 21:15:14 +0000497 if (card->info.type == QETH_CARD_TYPE_OSN ||
498 card->info.type == QETH_CARD_TYPE_OSM ||
499 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000500 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100501 return -EOPNOTSUPP;
502 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100503 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200504 if (!is_valid_ether_addr(addr->sa_data))
505 return -EADDRNOTAVAIL;
506
Ursula Braun8e98ac42009-03-24 20:57:18 +0000507 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000508 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000509 return -ERESTARTSYS;
510 }
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200511
Julian Wiedmann4789a212018-06-29 19:45:51 +0200512 /* avoid racing against concurrent state change: */
513 if (!mutex_trylock(&card->conf_mutex))
514 return -EAGAIN;
515
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200516 if (!qeth_card_hw_is_reachable(card)) {
517 ether_addr_copy(dev->dev_addr, addr->sa_data);
Julian Wiedmann4789a212018-06-29 19:45:51 +0200518 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200519 }
520
521 /* don't register the same address twice */
522 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
523 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Julian Wiedmann4789a212018-06-29 19:45:51 +0200524 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200525
526 /* add the new address, switch over, drop the old */
527 rc = qeth_l2_send_setmac(card, addr->sa_data);
528 if (rc)
Julian Wiedmann4789a212018-06-29 19:45:51 +0200529 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200530 ether_addr_copy(old_addr, dev->dev_addr);
531 ether_addr_copy(dev->dev_addr, addr->sa_data);
532
533 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
534 qeth_l2_remove_mac(card, old_addr);
535 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmann4789a212018-06-29 19:45:51 +0200536
537out_unlock:
538 mutex_unlock(&card->conf_mutex);
539 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100540}
541
Eugene Crosser0db587b2015-05-18 14:27:55 +0200542static void qeth_promisc_to_bridge(struct qeth_card *card)
543{
544 struct net_device *dev = card->dev;
545 enum qeth_ipa_promisc_modes promisc_mode;
546 int role;
547 int rc;
548
549 QETH_CARD_TEXT(card, 3, "pmisc2br");
550
551 if (!card->options.sbp.reflect_promisc)
552 return;
553 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
554 : SET_PROMISC_MODE_OFF;
555 if (promisc_mode == card->info.promisc_mode)
556 return;
557
558 if (promisc_mode == SET_PROMISC_MODE_ON) {
559 if (card->options.sbp.reflect_promisc_primary)
560 role = QETH_SBP_ROLE_PRIMARY;
561 else
562 role = QETH_SBP_ROLE_SECONDARY;
563 } else
564 role = QETH_SBP_ROLE_NONE;
565
566 rc = qeth_bridgeport_setrole(card, role);
567 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
568 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
569 if (!rc) {
570 card->options.sbp.role = role;
571 card->info.promisc_mode = promisc_mode;
572 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200573
574}
575/* New MAC address is added to the hash table and marked to be written on card
576 * only if there is not in the hash table storage already
577 *
578*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100579static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200580{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200581 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200582 struct qeth_mac *mac;
583
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200584 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100585 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200586 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200587 return;
588 }
589 }
590
591 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200592 if (!mac)
593 return;
594
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100595 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200596 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200597
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200598 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200599}
600
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200601static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100602{
Heiko Carstens509e2562008-07-26 02:24:10 -0700603 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000604 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200605 struct qeth_mac *mac;
606 struct hlist_node *tmp;
607 int i;
608 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100609
610 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200611 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100612
Carsten Otte847a50f2010-06-21 22:57:05 +0000613 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000614 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
615 (card->state != CARD_STATE_UP))
616 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200617
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200619
Jiri Pirko22bedad32010-04-01 21:22:57 +0000620 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100621 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800622 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100623 qeth_l2_add_mac(card, ha);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200624
625 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100626 switch (mac->disp_flag) {
627 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100628 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200629 hash_del(&mac->hnode);
630 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100631 break;
632 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100633 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200634 if (rc) {
635 hash_del(&mac->hnode);
636 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100637 break;
638 }
639 /* fall through */
640 default:
641 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200642 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100643 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200644 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200645
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200647
Eugene Crosser0db587b2015-05-18 14:27:55 +0200648 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
649 qeth_setadp_promisc_mode(card);
650 else
651 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100652}
653
Julian Wiedmann72863842017-08-18 10:19:04 +0200654static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
655 struct qeth_qdio_out_q *queue)
656{
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200657 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
658 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
659 addr_t start = (addr_t)skb->data;
660 unsigned int elements = 0;
661 unsigned int hd_len = 0;
662 int rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200663
664 if (skb->protocol == htons(ETH_P_IPV6))
665 return -EPROTONOSUPPORT;
666
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200667 if (qeth_get_elements_for_range(start, end) > 1) {
668 /* Misaligned HW header, move it to its own buffer element. */
669 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
670 if (!hdr)
671 return -ENOMEM;
672 hd_len = sizeof(*hdr);
673 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
674 elements++;
675 }
676
677 elements += qeth_count_elements(skb, hd_len);
678 if (elements > QETH_MAX_BUFFER_ELEMENTS(card)) {
679 rc = -E2BIG;
680 goto out;
681 }
682
683 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
684 elements);
685out:
686 if (rc && hd_len)
687 kmem_cache_free(qeth_core_header_cache, hdr);
688 return rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200689}
690
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200691static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
692 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100693{
Heiko Carstens509e2562008-07-26 02:24:10 -0700694 struct qeth_card *card = dev->ml_priv;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000695 int cast_type = qeth_l2_get_cast_type(card, skb);
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200696 int ipv = qeth_get_ip_version(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200697 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100698 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200699 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700
Julian Wiedmann91cc98f2018-09-26 18:29:16 +0200701 if (card->state != CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 card->stats.tx_carrier_errors++;
703 goto tx_drop;
704 }
705
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +0200706 queue = qeth_get_tx_queue(card, skb, ipv, cast_type);
707
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 if (card->options.performance_stats) {
709 card->perf_stats.outbound_cnt++;
710 card->perf_stats.outbound_start_time = qeth_get_micros();
711 }
712 netif_stop_queue(dev);
713
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200714 if (IS_OSN(card))
Julian Wiedmann72863842017-08-18 10:19:04 +0200715 rc = qeth_l2_xmit_osn(card, skb, queue);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200716 else
Julian Wiedmannfc696602018-09-17 17:35:55 +0200717 rc = qeth_xmit(card, skb, queue, ipv, cast_type,
718 qeth_l2_fill_header);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100719
Frank Blaschka4a71df52008-02-15 09:19:42 +0100720 if (!rc) {
721 card->stats.tx_packets++;
722 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann72863842017-08-18 10:19:04 +0200723 if (card->options.performance_stats)
724 card->perf_stats.outbound_time += qeth_get_micros() -
725 card->perf_stats.outbound_start_time;
726 netif_wake_queue(dev);
727 return NETDEV_TX_OK;
728 } else if (rc == -EBUSY) {
729 return NETDEV_TX_BUSY;
730 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731
732tx_drop:
733 card->stats.tx_dropped++;
734 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200736 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100737 return NETDEV_TX_OK;
738}
739
Ursula Braun39423442011-01-12 20:42:24 +0000740static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100741{
Heiko Carstens509e2562008-07-26 02:24:10 -0700742 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000743 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100744
Carsten Otte847a50f2010-06-21 22:57:05 +0000745 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000746 if (card->state == CARD_STATE_UP)
747 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748 if (card->state != CARD_STATE_SOFTSETUP)
749 return -ENODEV;
750
751 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
752 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000753 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100754 return -EPERM;
755 }
756 card->data.state = CH_STATE_UP;
757 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100758 netif_start_queue(dev);
759
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000760 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
761 napi_enable(&card->napi);
Julian Wiedmann4d19db72018-09-17 17:36:06 +0200762 local_bh_disable();
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000763 napi_schedule(&card->napi);
Julian Wiedmann4d19db72018-09-17 17:36:06 +0200764 /* kick-start the NAPI softirq: */
765 local_bh_enable();
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000766 } else
767 rc = -EIO;
768 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769}
770
Ursula Braun39423442011-01-12 20:42:24 +0000771static int qeth_l2_open(struct net_device *dev)
772{
773 struct qeth_card *card = dev->ml_priv;
774
775 QETH_CARD_TEXT(card, 5, "qethope_");
776 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
777 QETH_CARD_TEXT(card, 3, "openREC");
778 return -ERESTARTSYS;
779 }
780 return __qeth_l2_open(dev);
781}
782
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783static int qeth_l2_stop(struct net_device *dev)
784{
Heiko Carstens509e2562008-07-26 02:24:10 -0700785 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786
Carsten Otte847a50f2010-06-21 22:57:05 +0000787 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000789 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000791 napi_disable(&card->napi);
792 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100793 return 0;
794}
795
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200796static const struct device_type qeth_l2_devtype = {
797 .name = "qeth_layer2",
798 .groups = qeth_l2_attr_groups,
799};
800
Frank Blaschka4a71df52008-02-15 09:19:42 +0100801static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
802{
803 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200804 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200806 if (gdev->dev.type == &qeth_generic_devtype) {
807 rc = qeth_l2_create_device_attributes(&gdev->dev);
808 if (rc)
809 return rc;
810 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200812 hash_init(card->mac_htable);
Frank Blaschka1da74b12011-05-12 18:45:02 +0000813 card->info.hwtrap = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +0200814 qeth_l2_vnicc_set_defaults(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100815 return 0;
816}
817
818static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
819{
820 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
821
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200822 if (cgdev->dev.type == &qeth_generic_devtype)
823 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000824 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
826
Ursula Braun70919e22011-02-26 22:41:36 -0800827 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100828 qeth_l2_set_offline(cgdev);
Julian Wiedmann30356d02018-11-02 19:04:10 +0100829 if (qeth_netdev_is_registered(card->dev))
830 unregister_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831}
832
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700833static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100834 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100835 .get_strings = qeth_core_get_strings,
836 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000837 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200839 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840};
841
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700842static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 .get_strings = qeth_core_get_strings,
844 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000845 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100846 .get_drvinfo = qeth_core_get_drvinfo,
847};
848
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000849static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800850 .ndo_open = qeth_l2_open,
851 .ndo_stop = qeth_l2_stop,
852 .ndo_get_stats = qeth_get_stats,
853 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100854 .ndo_features_check = qeth_features_check,
Frank Blaschka8403b132009-01-08 10:50:55 -0800855 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200856 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200857 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800858 .ndo_set_mac_address = qeth_l2_set_mac_address,
Frank Blaschka8403b132009-01-08 10:50:55 -0800859 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
860 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
861 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200862 .ndo_fix_features = qeth_fix_features,
863 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800864};
865
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100866static int qeth_l2_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867{
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200868 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869
Julian Wiedmann30356d02018-11-02 19:04:10 +0100870 if (qeth_netdev_is_registered(card->dev))
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200871 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872
Julian Wiedmannd3aacac2018-03-09 18:12:55 +0100873 card->dev->priv_flags |= IFF_UNICAST_FLT;
Frank Blaschka8403b132009-01-08 10:50:55 -0800874 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200875 if (card->info.type == QETH_CARD_TYPE_OSN) {
876 card->dev->ethtool_ops = &qeth_l2_osn_ops;
877 card->dev->flags |= IFF_NOARP;
878 } else {
879 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200880 card->dev->needed_headroom = sizeof(struct qeth_hdr);
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200881 }
Julian Wiedmann9400c532017-10-18 17:40:20 +0200882
883 if (card->info.type == QETH_CARD_TYPE_OSM)
884 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
885 else
886 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann0f342942018-03-09 18:12:54 +0100887
Thomas Richter4d7def22015-09-18 16:06:51 +0200888 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100889 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200890 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200891 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200892 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200893 card->dev->vlan_features |= NETIF_F_IP_CSUM;
894 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200895 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200896 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
897 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
898 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
899 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +0200900 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
901 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
902 card->dev->hw_features |= NETIF_F_RXCSUM;
903 card->dev->vlan_features |= NETIF_F_RXCSUM;
904 }
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200905 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
906 card->dev->hw_features |= NETIF_F_TSO;
907 card->dev->vlan_features |= NETIF_F_TSO;
908 }
909 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
910 card->dev->hw_features |= NETIF_F_TSO6;
911 card->dev->vlan_features |= NETIF_F_TSO6;
912 }
913
914 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
915 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
916 netif_set_gso_max_size(card->dev,
917 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
918 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200919
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 qeth_l2_request_initial_mac(card);
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200921 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200922 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100923 if (!rc && carrier_ok)
924 netif_carrier_on(card->dev);
925
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200926 if (rc)
927 card->dev->netdev_ops = NULL;
928 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929}
930
Thomas Richter4d7def22015-09-18 16:06:51 +0200931static int qeth_l2_start_ipassists(struct qeth_card *card)
932{
933 /* configure isolation level */
934 if (qeth_set_access_ctrl_online(card, 0))
935 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +0200936 return 0;
937}
938
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200939static void qeth_l2_trace_features(struct qeth_card *card)
940{
Hans Wippela45b3fa2017-09-18 21:18:14 +0200941 /* Set BridgePort features */
942 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200943 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
944 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +0200945 /* VNIC Characteristics features */
946 QETH_CARD_TEXT(card, 2, "feaVNICC");
947 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
948 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200949}
950
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
952{
953 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
954 int rc = 0;
955 enum qeth_card_states recover_flag;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100956 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000958 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000959 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200960 QETH_DBF_TEXT(SETUP, 2, "setonlin");
961 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100962
Frank Blaschka4a71df52008-02-15 09:19:42 +0100963 recover_flag = card->state;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100964 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100965 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100966 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000967 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 goto out_remove;
969 }
Eugene Crosserc044dc22014-01-29 09:23:48 +0100970 qeth_bridgeport_query_support(card);
971 if (card->options.sbp.supported_funcs)
972 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +0200973 "The device represents a Bridge Capable Port\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100974
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100975 rc = qeth_l2_setup_netdev(card, carrier_ok);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200976 if (rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 goto out_remove;
978
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200979 if (card->info.type != QETH_CARD_TYPE_OSN &&
980 !qeth_l2_send_setmac(card, card->dev->dev_addr))
981 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100982
Frank Blaschka1da74b12011-05-12 18:45:02 +0000983 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
984 if (card->info.hwtrap &&
985 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
986 card->info.hwtrap = 0;
987 } else
988 card->info.hwtrap = 0;
989
Hans Wippela45b3fa2017-09-18 21:18:14 +0200990 /* for the rx_bcast characteristic, init VNICC after setmac */
991 qeth_l2_vnicc_init(card);
992
993 qeth_trace_features(card);
994 qeth_l2_trace_features(card);
995
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100996 qeth_l2_setup_bridgeport_attrs(card);
997
Frank Blaschka4a71df52008-02-15 09:19:42 +0100998 card->state = CARD_STATE_HARDSETUP;
999 qeth_print_status_message(card);
1000
1001 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001002 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001003
Ursula Braun5113fec2010-05-16 21:15:14 +00001004 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001005 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001006 rc = qeth_l2_start_ipassists(card);
1007 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001008 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001009 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001010
Julian Wiedmann9400c532017-10-18 17:40:20 +02001011 if (card->info.type != QETH_CARD_TYPE_OSN)
Ursula Braun70919e22011-02-26 22:41:36 -08001012 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001013
1014 netif_tx_disable(card->dev);
1015
1016 rc = qeth_init_qdio_queues(card);
1017 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001018 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001019 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001020 goto out_remove;
1021 }
1022 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001023
1024 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd025da92018-06-29 19:45:54 +02001025
1026 qeth_enable_hw_features(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001027 if (recover_flag == CARD_STATE_RECOVER) {
1028 if (recovery_mode &&
1029 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001030 __qeth_l2_open(card->dev);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02001031 qeth_l2_set_rx_mode(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001032 } else {
1033 rtnl_lock();
1034 dev_open(card->dev);
1035 rtnl_unlock();
1036 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037 }
1038 /* let user_space know that device is online */
1039 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001040 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001041 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001042 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001043
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001045 qeth_l2_stop_card(card, 0);
1046 ccw_device_set_offline(CARD_DDEV(card));
1047 ccw_device_set_offline(CARD_WDEV(card));
1048 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001049 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001050 if (recover_flag == CARD_STATE_RECOVER)
1051 card->state = CARD_STATE_RECOVER;
1052 else
1053 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001054 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001055 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001056 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001057}
1058
1059static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1060{
1061 return __qeth_l2_set_online(gdev, 0);
1062}
1063
1064static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1065 int recovery_mode)
1066{
1067 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1068 int rc = 0, rc2 = 0, rc3 = 0;
1069 enum qeth_card_states recover_flag;
1070
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001071 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001072 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001073 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1074 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001076 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001077 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001078 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1079 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1080 card->info.hwtrap = 1;
1081 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001082 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001083 rc = ccw_device_set_offline(CARD_DDEV(card));
1084 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1085 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1086 if (!rc)
1087 rc = (rc2) ? rc2 : rc3;
1088 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001089 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001090 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091 if (recover_flag == CARD_STATE_UP)
1092 card->state = CARD_STATE_RECOVER;
1093 /* let user_space know that device is offline */
1094 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001095 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001096 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001097 return 0;
1098}
1099
1100static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1101{
1102 return __qeth_l2_set_offline(cgdev, 0);
1103}
1104
1105static int qeth_l2_recover(void *ptr)
1106{
1107 struct qeth_card *card;
1108 int rc = 0;
1109
1110 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001111 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001112 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1113 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001114 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001115 dev_warn(&card->gdev->dev,
1116 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001117 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 __qeth_l2_set_offline(card->gdev, 1);
1119 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001121 dev_info(&card->gdev->dev,
1122 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001123 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001124 qeth_close_dev(card);
1125 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001126 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001127 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001128 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001129 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1130 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001131 return 0;
1132}
1133
1134static int __init qeth_l2_init(void)
1135{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001136 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001137 return 0;
1138}
1139
1140static void __exit qeth_l2_exit(void)
1141{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001142 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143}
1144
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001145static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1146{
1147 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1148
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001149 netif_device_detach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001150 qeth_set_allowed_threads(card, 0, 1);
1151 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1152 if (gdev->state == CCWGROUP_OFFLINE)
1153 return 0;
1154 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001155 if (card->info.hwtrap)
1156 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001157 __qeth_l2_set_offline(card->gdev, 1);
1158 } else
1159 __qeth_l2_set_offline(card->gdev, 0);
1160 return 0;
1161}
1162
1163static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1164{
1165 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1166 int rc = 0;
1167
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001168 if (card->state == CARD_STATE_RECOVER) {
1169 rc = __qeth_l2_set_online(card->gdev, 1);
1170 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001171 rtnl_lock();
1172 dev_close(card->dev);
1173 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001174 }
1175 } else
1176 rc = __qeth_l2_set_online(card->gdev, 0);
Julian Wiedmann6585ac42018-09-26 18:29:12 +02001177
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001178 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001179 netif_device_attach(card->dev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001180 if (rc)
1181 dev_warn(&card->gdev->dev, "The qeth device driver "
1182 "failed to recover an error on the device\n");
1183 return rc;
1184}
1185
Eugene Crosserc044dc22014-01-29 09:23:48 +01001186/* Returns zero if the command is successfully "consumed" */
1187static int qeth_l2_control_event(struct qeth_card *card,
1188 struct qeth_ipa_cmd *cmd)
1189{
1190 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001191 case IPA_CMD_SETBRIDGEPORT_OSA:
1192 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001193 if (cmd->data.sbp.hdr.command_code ==
1194 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1195 qeth_bridge_state_change(card, cmd);
1196 return 0;
1197 } else
1198 return 1;
1199 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1200 qeth_bridge_host_event(card, cmd);
1201 return 0;
1202 default:
1203 return 1;
1204 }
1205}
1206
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001207struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001208 .devtype = &qeth_l2_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001209 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001210 .recover = qeth_l2_recover,
1211 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001212 .remove = qeth_l2_remove_device,
1213 .set_online = qeth_l2_set_online,
1214 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001215 .freeze = qeth_l2_pm_suspend,
1216 .thaw = qeth_l2_pm_resume,
1217 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001218 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001219 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001221EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001222
1223static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1224 struct qeth_cmd_buffer *iob)
1225{
Julian Wiedmann750b1622018-08-09 14:47:59 +02001226 struct qeth_channel *channel = iob->channel;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001227 int rc = 0;
1228
Carsten Otte847a50f2010-06-21 22:57:05 +00001229 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230
1231 wait_event(card->wait_q,
Julian Wiedmann750b1622018-08-09 14:47:59 +02001232 atomic_cmpxchg(&channel->irq_pending, 0, 1) == 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001233 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001234 QETH_CARD_TEXT(card, 6, "osnoirqp");
Julian Wiedmanned471552018-09-17 17:36:08 +02001235 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
Julian Wiedmannf15cdaf2018-08-09 14:48:03 +02001236 rc = ccw_device_start_timeout(channel->ccwdev, channel->ccw,
Julian Wiedmanndb71bbb2018-04-19 12:52:10 +02001237 (addr_t) iob, 0, 0, QETH_IPA_TIMEOUT);
Julian Wiedmanned471552018-09-17 17:36:08 +02001238 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001239 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001240 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001241 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001242 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Julian Wiedmann750b1622018-08-09 14:47:59 +02001243 qeth_release_buffer(channel, iob);
1244 atomic_set(&channel->irq_pending, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001245 wake_up(&card->wait_q);
1246 }
1247 return rc;
1248}
1249
1250static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1251 struct qeth_cmd_buffer *iob, int data_len)
1252{
1253 u16 s1, s2;
1254
Carsten Otte847a50f2010-06-21 22:57:05 +00001255 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001256
Julian Wiedmann73657a32018-08-09 14:47:58 +02001257 qeth_prepare_ipa_cmd(card, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001258 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1259 s2 = (u16)data_len;
1260 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1261 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1262 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1263 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1264 return qeth_osn_send_control_data(card, s1, iob);
1265}
1266
1267int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1268{
1269 struct qeth_cmd_buffer *iob;
1270 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001271
Frank Blaschka4a71df52008-02-15 09:19:42 +01001272 if (!dev)
1273 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001274 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275 if (!card)
1276 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001277 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001278 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001279 return -ENODEV;
1280 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001281 memcpy(__ipa_cmd(iob), data, data_len);
1282 return qeth_osn_send_ipa_cmd(card, iob, data_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001283}
1284EXPORT_SYMBOL(qeth_osn_assist);
1285
1286int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1287 int (*assist_cb)(struct net_device *, void *),
1288 int (*data_cb)(struct sk_buff *))
1289{
1290 struct qeth_card *card;
1291
Frank Blaschka4a71df52008-02-15 09:19:42 +01001292 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1293 if (*dev == NULL)
1294 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001295 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001296 if (!card)
1297 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001298 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001299 if ((assist_cb == NULL) || (data_cb == NULL))
1300 return -EINVAL;
1301 card->osn_info.assist_cb = assist_cb;
1302 card->osn_info.data_cb = data_cb;
1303 return 0;
1304}
1305EXPORT_SYMBOL(qeth_osn_register);
1306
1307void qeth_osn_deregister(struct net_device *dev)
1308{
1309 struct qeth_card *card;
1310
Frank Blaschka4a71df52008-02-15 09:19:42 +01001311 if (!dev)
1312 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001313 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001314 if (!card)
1315 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001316 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001317 card->osn_info.assist_cb = NULL;
1318 card->osn_info.data_cb = NULL;
1319 return;
1320}
1321EXPORT_SYMBOL(qeth_osn_deregister);
1322
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001323/* SETBRIDGEPORT support, async notifications */
1324
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001325enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1326
1327/**
1328 * qeth_bridge_emit_host_event() - bridgeport address change notification
1329 * @card: qeth_card structure pointer, for udev events.
1330 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1331 * and reset token and addr_lnid are unused and may be NULL.
1332 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1333 * object, 0 - addition of an object.
1334 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1335 * @token: "network token" structure identifying physical address of the port.
1336 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1337 *
1338 * This function is called when registrations and deregistrations are
1339 * reported by the hardware, and also when notifications are enabled -
1340 * for all currently registered addresses.
1341 */
1342static void qeth_bridge_emit_host_event(struct qeth_card *card,
1343 enum qeth_an_event_type evtype,
1344 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1345{
1346 char str[7][32];
1347 char *env[8];
1348 int i = 0;
1349
1350 switch (evtype) {
1351 case anev_reg_unreg:
1352 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1353 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1354 ? "deregister" : "register");
1355 env[i] = str[i]; i++;
1356 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1357 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1358 addr_lnid->lnid);
1359 env[i] = str[i]; i++;
1360 }
1361 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001362 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001363 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001364 env[i] = str[i]; i++;
1365 }
1366 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1367 token->cssid, token->ssid, token->devnum);
1368 env[i] = str[i]; i++;
1369 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1370 env[i] = str[i]; i++;
1371 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1372 token->chpid);
1373 env[i] = str[i]; i++;
1374 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1375 env[i] = str[i]; i++;
1376 break;
1377 case anev_abort:
1378 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1379 env[i] = str[i]; i++;
1380 break;
1381 case anev_reset:
1382 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1383 env[i] = str[i]; i++;
1384 break;
1385 }
1386 env[i] = NULL;
1387 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1388}
1389
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001390struct qeth_bridge_state_data {
1391 struct work_struct worker;
1392 struct qeth_card *card;
1393 struct qeth_sbp_state_change qports;
1394};
1395
1396static void qeth_bridge_state_change_worker(struct work_struct *work)
1397{
1398 struct qeth_bridge_state_data *data =
1399 container_of(work, struct qeth_bridge_state_data, worker);
1400 /* We are only interested in the first entry - local port */
1401 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1402 char env_locrem[32];
1403 char env_role[32];
1404 char env_state[32];
1405 char *env[] = {
1406 env_locrem,
1407 env_role,
1408 env_state,
1409 NULL
1410 };
1411
1412 /* Role should not change by itself, but if it did, */
1413 /* information from the hardware is authoritative. */
1414 mutex_lock(&data->card->conf_mutex);
1415 data->card->options.sbp.role = entry->role;
1416 mutex_unlock(&data->card->conf_mutex);
1417
1418 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1419 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1420 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1421 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1422 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1423 "<INVALID>");
1424 snprintf(env_state, sizeof(env_state), "STATE=%s",
1425 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1426 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1427 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1428 "<INVALID>");
1429 kobject_uevent_env(&data->card->gdev->dev.kobj,
1430 KOBJ_CHANGE, env);
1431 kfree(data);
1432}
1433
Eugene Crosserc044dc22014-01-29 09:23:48 +01001434static void qeth_bridge_state_change(struct qeth_card *card,
1435 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001436{
1437 struct qeth_sbp_state_change *qports =
1438 &cmd->data.sbp.data.state_change;
1439 struct qeth_bridge_state_data *data;
1440 int extrasize;
1441
1442 QETH_CARD_TEXT(card, 2, "brstchng");
1443 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001444 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001445 return;
1446 }
1447 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1448 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1449 GFP_ATOMIC);
1450 if (!data) {
1451 QETH_CARD_TEXT(card, 2, "BPSalloc");
1452 return;
1453 }
1454 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1455 data->card = card;
1456 memcpy(&data->qports, qports,
1457 sizeof(struct qeth_sbp_state_change) + extrasize);
1458 queue_work(qeth_wq, &data->worker);
1459}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001460
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001461struct qeth_bridge_host_data {
1462 struct work_struct worker;
1463 struct qeth_card *card;
1464 struct qeth_ipacmd_addr_change hostevs;
1465};
1466
1467static void qeth_bridge_host_event_worker(struct work_struct *work)
1468{
1469 struct qeth_bridge_host_data *data =
1470 container_of(work, struct qeth_bridge_host_data, worker);
1471 int i;
1472
1473 if (data->hostevs.lost_event_mask) {
1474 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001475"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001476 data->card->dev->name,
1477 (data->hostevs.lost_event_mask == 0x01)
1478 ? "Overflow"
1479 : (data->hostevs.lost_event_mask == 0x02)
1480 ? "Bridge port state change"
1481 : "Unknown reason");
1482 mutex_lock(&data->card->conf_mutex);
1483 data->card->options.sbp.hostnotification = 0;
1484 mutex_unlock(&data->card->conf_mutex);
1485 qeth_bridge_emit_host_event(data->card, anev_abort,
1486 0, NULL, NULL);
1487 } else
1488 for (i = 0; i < data->hostevs.num_entries; i++) {
1489 struct qeth_ipacmd_addr_change_entry *entry =
1490 &data->hostevs.entry[i];
1491 qeth_bridge_emit_host_event(data->card,
1492 anev_reg_unreg,
1493 entry->change_code,
1494 &entry->token, &entry->addr_lnid);
1495 }
1496 kfree(data);
1497}
1498
Eugene Crosserc044dc22014-01-29 09:23:48 +01001499static void qeth_bridge_host_event(struct qeth_card *card,
1500 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001501{
1502 struct qeth_ipacmd_addr_change *hostevs =
1503 &cmd->data.addrchange;
1504 struct qeth_bridge_host_data *data;
1505 int extrasize;
1506
1507 QETH_CARD_TEXT(card, 2, "brhostev");
1508 if (cmd->hdr.return_code != 0x0000) {
1509 if (cmd->hdr.return_code == 0x0010) {
1510 if (hostevs->lost_event_mask == 0x00)
1511 hostevs->lost_event_mask = 0xff;
1512 } else {
1513 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1514 cmd->hdr.return_code);
1515 return;
1516 }
1517 }
1518 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1519 hostevs->num_entries;
1520 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1521 GFP_ATOMIC);
1522 if (!data) {
1523 QETH_CARD_TEXT(card, 2, "BPHalloc");
1524 return;
1525 }
1526 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1527 data->card = card;
1528 memcpy(&data->hostevs, hostevs,
1529 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1530 queue_work(qeth_wq, &data->worker);
1531}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001532
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001533/* SETBRIDGEPORT support; sending commands */
1534
1535struct _qeth_sbp_cbctl {
1536 u16 ipa_rc;
1537 u16 cmd_rc;
1538 union {
1539 u32 supported;
1540 struct {
1541 enum qeth_sbp_roles *role;
1542 enum qeth_sbp_states *state;
1543 } qports;
1544 } data;
1545};
1546
1547/**
1548 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1549 * @card: qeth_card structure pointer, for debug messages.
1550 * @cbctl: state structure with hardware return codes.
1551 * @setcmd: IPA command code
1552 *
1553 * Returns negative errno-compatible error indication or 0 on success.
1554 */
1555static int qeth_bridgeport_makerc(struct qeth_card *card,
1556 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1557{
1558 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001559 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001560
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001561 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1562 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001563 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001564 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001565 rc = 0;
1566 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001567 case IPA_RC_L2_UNSUPPORTED_CMD:
1568 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001569 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001570 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001571 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1572 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001573 rc = -ENODEV; /* maybe not the best code here? */
1574 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001575 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001576 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001577 case IPA_RC_SBP_OSA_OS_MISMATCH:
1578 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001579 rc = -EPERM;
1580 dev_err(&card->gdev->dev,
1581 "A Bridge Port is already configured by a different operating system\n");
1582 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001583 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1584 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001585 switch (setcmd) {
1586 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1587 rc = -EEXIST;
1588 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001589 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001590 break;
1591 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1592 rc = -EBUSY;
1593 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001594 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001595 break;
1596 default:
1597 rc = -EIO;
1598 }
1599 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001600 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1601 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001602 rc = -EBUSY;
1603 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001604 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001605 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001606 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1607 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001608 rc = -EEXIST;
1609 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001610 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001611 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001612 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1613 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001614 rc = -EBUSY;
1615 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001616 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001617 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001618 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1619 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001620 rc = -EACCES;
1621 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001622 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001623 break;
1624 default:
1625 rc = -EIO;
1626 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001627 else
1628 switch (cbctl->ipa_rc) {
1629 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001630 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001631 break;
1632 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001633 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001634 break;
1635 default:
1636 rc = -EIO;
1637 }
1638
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001639 if (rc) {
1640 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1641 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1642 }
1643 return rc;
1644}
1645
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001646static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1647 enum qeth_ipa_sbp_cmd sbp_cmd,
1648 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001649{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001650 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1651 IPA_CMD_SETBRIDGEPORT_IQD :
1652 IPA_CMD_SETBRIDGEPORT_OSA;
1653 struct qeth_cmd_buffer *iob;
1654 struct qeth_ipa_cmd *cmd;
1655
1656 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1657 if (!iob)
1658 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001659 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001660 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1661 cmd_length;
1662 cmd->data.sbp.hdr.command_code = sbp_cmd;
1663 cmd->data.sbp.hdr.used_total = 1;
1664 cmd->data.sbp.hdr.seq_no = 1;
1665 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001666}
1667
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001668static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1669 struct qeth_reply *reply, unsigned long data)
1670{
1671 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1672 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1673 QETH_CARD_TEXT(card, 2, "brqsupcb");
1674 cbctl->ipa_rc = cmd->hdr.return_code;
1675 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1676 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1677 cbctl->data.supported =
1678 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1679 } else {
1680 cbctl->data.supported = 0;
1681 }
1682 return 0;
1683}
1684
1685/**
1686 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1687 * @card: qeth_card structure pointer.
1688 *
1689 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1690 * strucutre: card->options.sbp.supported_funcs.
1691 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001692static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001693{
1694 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001695 struct _qeth_sbp_cbctl cbctl;
1696
1697 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001698 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1699 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001700 if (!iob)
1701 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001702 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1703 (void *)&cbctl) ||
1704 qeth_bridgeport_makerc(card, &cbctl,
1705 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1706 /* non-zero makerc signifies failure, and produce messages */
1707 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1708 return;
1709 }
1710 card->options.sbp.supported_funcs = cbctl.data.supported;
1711}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001712
1713static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1714 struct qeth_reply *reply, unsigned long data)
1715{
1716 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1717 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1718 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1719
1720 QETH_CARD_TEXT(card, 2, "brqprtcb");
1721 cbctl->ipa_rc = cmd->hdr.return_code;
1722 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1723 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1724 return 0;
1725 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1726 cbctl->cmd_rc = 0xffff;
1727 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1728 return 0;
1729 }
1730 /* first entry contains the state of the local port */
1731 if (qports->num_entries > 0) {
1732 if (cbctl->data.qports.role)
1733 *cbctl->data.qports.role = qports->entry[0].role;
1734 if (cbctl->data.qports.state)
1735 *cbctl->data.qports.state = qports->entry[0].state;
1736 }
1737 return 0;
1738}
1739
1740/**
1741 * qeth_bridgeport_query_ports() - query local bridgeport status.
1742 * @card: qeth_card structure pointer.
1743 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1744 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1745 *
1746 * Returns negative errno-compatible error indication or 0 on success.
1747 *
1748 * 'role' and 'state' are not updated in case of hardware operation failure.
1749 */
1750int qeth_bridgeport_query_ports(struct qeth_card *card,
1751 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1752{
1753 int rc = 0;
1754 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001755 struct _qeth_sbp_cbctl cbctl = {
1756 .data = {
1757 .qports = {
1758 .role = role,
1759 .state = state,
1760 },
1761 },
1762 };
1763
1764 QETH_CARD_TEXT(card, 2, "brqports");
1765 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1766 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001767 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001768 if (!iob)
1769 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001770 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1771 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001772 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001773 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001774 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001775}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001776
1777static int qeth_bridgeport_set_cb(struct qeth_card *card,
1778 struct qeth_reply *reply, unsigned long data)
1779{
1780 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1781 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1782 QETH_CARD_TEXT(card, 2, "brsetrcb");
1783 cbctl->ipa_rc = cmd->hdr.return_code;
1784 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1785 return 0;
1786}
1787
1788/**
1789 * qeth_bridgeport_setrole() - Assign primary role to the port.
1790 * @card: qeth_card structure pointer.
1791 * @role: Role to assign.
1792 *
1793 * Returns negative errno-compatible error indication or 0 on success.
1794 */
1795int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1796{
1797 int rc = 0;
1798 int cmdlength;
1799 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001800 struct _qeth_sbp_cbctl cbctl;
1801 enum qeth_ipa_sbp_cmd setcmd;
1802
1803 QETH_CARD_TEXT(card, 2, "brsetrol");
1804 switch (role) {
1805 case QETH_SBP_ROLE_NONE:
1806 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001807 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001808 break;
1809 case QETH_SBP_ROLE_PRIMARY:
1810 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001811 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001812 break;
1813 case QETH_SBP_ROLE_SECONDARY:
1814 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001815 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001816 break;
1817 default:
1818 return -EINVAL;
1819 }
1820 if (!(card->options.sbp.supported_funcs & setcmd))
1821 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001822 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001823 if (!iob)
1824 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001825 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1826 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001827 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001828 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001829 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001830}
1831
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001832/**
1833 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1834 * @card: qeth_card structure pointer, for debug messages.
1835 *
1836 * Returns negative errno-compatible error indication or 0 on success.
1837 */
1838static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1839{
1840 int rc;
1841
1842 if (pnso_rc == 0)
1843 switch (response) {
1844 case 0x0001:
1845 rc = 0;
1846 break;
1847 case 0x0004:
1848 case 0x0100:
1849 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001850 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001851 dev_err(&card->gdev->dev,
1852 "Setting address notification failed\n");
1853 break;
1854 case 0x0107:
1855 rc = -EAGAIN;
1856 break;
1857 default:
1858 rc = -EIO;
1859 }
1860 else
1861 rc = -EIO;
1862
1863 if (rc) {
1864 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1865 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1866 }
1867 return rc;
1868}
1869
1870static void qeth_bridgeport_an_set_cb(void *priv,
1871 enum qdio_brinfo_entry_type type, void *entry)
1872{
1873 struct qeth_card *card = (struct qeth_card *)priv;
1874 struct qdio_brinfo_entry_l2 *l2entry;
1875 u8 code;
1876
1877 if (type != l2_addr_lnid) {
1878 WARN_ON_ONCE(1);
1879 return;
1880 }
1881
1882 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1883 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1884 if (l2entry->addr_lnid.lnid)
1885 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1886 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1887 (struct net_if_token *)&l2entry->nit,
1888 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1889}
1890
1891/**
1892 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1893 * @card: qeth_card structure pointer.
1894 * @enable: 0 - disable, non-zero - enable notifications
1895 *
1896 * Returns negative errno-compatible error indication or 0 on success.
1897 *
1898 * On enable, emits a series of address notifications udev events for all
1899 * currently registered hosts.
1900 */
1901int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1902{
1903 int rc;
1904 u16 response;
1905 struct ccw_device *ddev;
1906 struct subchannel_id schid;
1907
1908 if (!card)
1909 return -EINVAL;
1910 if (!card->options.sbp.supported_funcs)
1911 return -EOPNOTSUPP;
1912 ddev = CARD_DDEV(card);
1913 ccw_device_get_schid(ddev, &schid);
1914
1915 if (enable) {
1916 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1917 rc = qdio_pnso_brinfo(schid, 1, &response,
1918 qeth_bridgeport_an_set_cb, card);
1919 } else
1920 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1921 return qeth_anset_makerc(card, rc, response);
1922}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001923
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001924static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1925{
1926 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1927 card->options.sbp.hostnotification);
1928}
1929
Hans Wippela45b3fa2017-09-18 21:18:14 +02001930/* VNIC Characteristics support */
1931
1932/* handle VNICC IPA command return codes; convert to error codes */
1933static int qeth_l2_vnicc_makerc(struct qeth_card *card, int ipa_rc)
1934{
1935 int rc;
1936
1937 switch (ipa_rc) {
1938 case IPA_RC_SUCCESS:
1939 return ipa_rc;
1940 case IPA_RC_L2_UNSUPPORTED_CMD:
1941 case IPA_RC_NOTSUPP:
1942 rc = -EOPNOTSUPP;
1943 break;
1944 case IPA_RC_VNICC_OOSEQ:
1945 rc = -EALREADY;
1946 break;
1947 case IPA_RC_VNICC_VNICBP:
1948 rc = -EBUSY;
1949 break;
1950 case IPA_RC_L2_ADDR_TABLE_FULL:
1951 rc = -ENOSPC;
1952 break;
1953 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1954 rc = -EACCES;
1955 break;
1956 default:
1957 rc = -EIO;
1958 }
1959
1960 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1961 return rc;
1962}
1963
1964/* generic VNICC request call back control */
1965struct _qeth_l2_vnicc_request_cbctl {
1966 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001967 struct {
1968 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02001969 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001970 } param;
1971 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02001972 union{
1973 u32 *sup_cmds;
1974 u32 *timeout;
1975 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001976 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001977};
1978
1979/* generic VNICC request call back */
1980static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1981 struct qeth_reply *reply,
1982 unsigned long data)
1983{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001984 struct _qeth_l2_vnicc_request_cbctl *cbctl =
1985 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001986 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1987 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1988
1989 QETH_CARD_TEXT(card, 2, "vniccrcb");
1990 if (cmd->hdr.return_code)
1991 return 0;
1992 /* return results to caller */
1993 card->options.vnicc.sup_chars = rep->hdr.sup;
1994 card->options.vnicc.cur_chars = rep->hdr.cur;
1995
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001996 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
1997 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
1998
Hans Wippel349d13d2017-09-18 21:18:16 +02001999 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
2000 *cbctl->result.timeout = rep->getset_timeout.timeout;
2001
Hans Wippela45b3fa2017-09-18 21:18:14 +02002002 return 0;
2003}
2004
2005/* generic VNICC request */
2006static int qeth_l2_vnicc_request(struct qeth_card *card,
2007 struct _qeth_l2_vnicc_request_cbctl *cbctl)
2008{
2009 struct qeth_ipacmd_vnicc *req;
2010 struct qeth_cmd_buffer *iob;
2011 struct qeth_ipa_cmd *cmd;
2012 int rc;
2013
2014 QETH_CARD_TEXT(card, 2, "vniccreq");
2015
2016 /* get new buffer for request */
2017 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
2018 if (!iob)
2019 return -ENOMEM;
2020
2021 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01002022 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02002023 req = &cmd->data.vnicc;
2024
2025 /* create sub command header for request */
2026 req->sub_hdr.data_length = sizeof(req->sub_hdr);
2027 req->sub_hdr.sub_command = cbctl->sub_cmd;
2028
2029 /* create sub command specific request fields */
2030 switch (cbctl->sub_cmd) {
2031 case IPA_VNICC_QUERY_CHARS:
2032 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002033 case IPA_VNICC_QUERY_CMDS:
2034 req->sub_hdr.data_length += sizeof(req->query_cmds);
2035 req->query_cmds.vnic_char = cbctl->param.vnic_char;
2036 break;
2037 case IPA_VNICC_ENABLE:
2038 case IPA_VNICC_DISABLE:
2039 req->sub_hdr.data_length += sizeof(req->set_char);
2040 req->set_char.vnic_char = cbctl->param.vnic_char;
2041 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02002042 case IPA_VNICC_SET_TIMEOUT:
2043 req->getset_timeout.timeout = cbctl->param.timeout;
2044 /* fallthrough */
2045 case IPA_VNICC_GET_TIMEOUT:
2046 req->sub_hdr.data_length += sizeof(req->getset_timeout);
2047 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
2048 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002049 default:
2050 qeth_release_buffer(iob->channel, iob);
2051 return -EOPNOTSUPP;
2052 }
2053
2054 /* send request */
2055 rc = qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb,
2056 (void *) cbctl);
2057
2058 return qeth_l2_vnicc_makerc(card, rc);
2059}
2060
2061/* VNICC query VNIC characteristics request */
2062static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
2063{
2064 struct _qeth_l2_vnicc_request_cbctl cbctl;
2065
2066 /* prepare callback control */
2067 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
2068
2069 QETH_CARD_TEXT(card, 2, "vniccqch");
2070 return qeth_l2_vnicc_request(card, &cbctl);
2071}
2072
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002073/* VNICC query sub commands request */
2074static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
2075 u32 *sup_cmds)
2076{
2077 struct _qeth_l2_vnicc_request_cbctl cbctl;
2078
2079 /* prepare callback control */
2080 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
2081 cbctl.param.vnic_char = vnic_char;
2082 cbctl.result.sup_cmds = sup_cmds;
2083
2084 QETH_CARD_TEXT(card, 2, "vniccqcm");
2085 return qeth_l2_vnicc_request(card, &cbctl);
2086}
2087
2088/* VNICC enable/disable characteristic request */
2089static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
2090 u32 cmd)
2091{
2092 struct _qeth_l2_vnicc_request_cbctl cbctl;
2093
2094 /* prepare callback control */
2095 cbctl.sub_cmd = cmd;
2096 cbctl.param.vnic_char = vnic_char;
2097
2098 QETH_CARD_TEXT(card, 2, "vniccedc");
2099 return qeth_l2_vnicc_request(card, &cbctl);
2100}
2101
Hans Wippel349d13d2017-09-18 21:18:16 +02002102/* VNICC get/set timeout for characteristic request */
2103static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
2104 u32 cmd, u32 *timeout)
2105{
2106 struct _qeth_l2_vnicc_request_cbctl cbctl;
2107
2108 /* prepare callback control */
2109 cbctl.sub_cmd = cmd;
2110 cbctl.param.vnic_char = vnicc;
2111 if (cmd == IPA_VNICC_SET_TIMEOUT)
2112 cbctl.param.timeout = *timeout;
2113 if (cmd == IPA_VNICC_GET_TIMEOUT)
2114 cbctl.result.timeout = timeout;
2115
2116 QETH_CARD_TEXT(card, 2, "vniccgst");
2117 return qeth_l2_vnicc_request(card, &cbctl);
2118}
2119
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002120/* set current VNICC flag state; called from sysfs store function */
2121int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
2122{
2123 int rc = 0;
2124 u32 cmd;
2125
2126 QETH_CARD_TEXT(card, 2, "vniccsch");
2127
2128 /* do not change anything if BridgePort is enabled */
2129 if (qeth_bridgeport_is_in_use(card))
2130 return -EBUSY;
2131
2132 /* check if characteristic and enable/disable are supported */
2133 if (!(card->options.vnicc.sup_chars & vnicc) ||
2134 !(card->options.vnicc.set_char_sup & vnicc))
2135 return -EOPNOTSUPP;
2136
2137 /* set enable/disable command and store wanted characteristic */
2138 if (state) {
2139 cmd = IPA_VNICC_ENABLE;
2140 card->options.vnicc.wanted_chars |= vnicc;
2141 } else {
2142 cmd = IPA_VNICC_DISABLE;
2143 card->options.vnicc.wanted_chars &= ~vnicc;
2144 }
2145
2146 /* do we need to do anything? */
2147 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
2148 return rc;
2149
2150 /* if card is not ready, simply stop here */
2151 if (!qeth_card_hw_is_reachable(card)) {
2152 if (state)
2153 card->options.vnicc.cur_chars |= vnicc;
2154 else
2155 card->options.vnicc.cur_chars &= ~vnicc;
2156 return rc;
2157 }
2158
2159 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
2160 if (rc)
2161 card->options.vnicc.wanted_chars =
2162 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02002163 else {
2164 /* successful online VNICC change; handle special cases */
2165 if (state && vnicc == QETH_VNICC_RX_BCAST)
2166 card->options.vnicc.rx_bcast_enabled = true;
2167 if (!state && vnicc == QETH_VNICC_LEARNING)
2168 qeth_l2_vnicc_recover_timeout(card, vnicc,
2169 &card->options.vnicc.learning_timeout);
2170 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002171
2172 return rc;
2173}
2174
2175/* get current VNICC flag state; called from sysfs show function */
2176int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
2177{
2178 int rc = 0;
2179
2180 QETH_CARD_TEXT(card, 2, "vniccgch");
2181
2182 /* do not get anything if BridgePort is enabled */
2183 if (qeth_bridgeport_is_in_use(card))
2184 return -EBUSY;
2185
2186 /* check if characteristic is supported */
2187 if (!(card->options.vnicc.sup_chars & vnicc))
2188 return -EOPNOTSUPP;
2189
2190 /* if card is ready, query current VNICC state */
2191 if (qeth_card_hw_is_reachable(card))
2192 rc = qeth_l2_vnicc_query_chars(card);
2193
2194 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
2195 return rc;
2196}
2197
Hans Wippel349d13d2017-09-18 21:18:16 +02002198/* set VNICC timeout; called from sysfs store function. Currently, only learning
2199 * supports timeout
2200 */
2201int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
2202{
2203 int rc = 0;
2204
2205 QETH_CARD_TEXT(card, 2, "vniccsto");
2206
2207 /* do not change anything if BridgePort is enabled */
2208 if (qeth_bridgeport_is_in_use(card))
2209 return -EBUSY;
2210
2211 /* check if characteristic and set_timeout are supported */
2212 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2213 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2214 return -EOPNOTSUPP;
2215
2216 /* do we need to do anything? */
2217 if (card->options.vnicc.learning_timeout == timeout)
2218 return rc;
2219
2220 /* if card is not ready, simply store the value internally and return */
2221 if (!qeth_card_hw_is_reachable(card)) {
2222 card->options.vnicc.learning_timeout = timeout;
2223 return rc;
2224 }
2225
2226 /* send timeout value to card; if successful, store value internally */
2227 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2228 IPA_VNICC_SET_TIMEOUT, &timeout);
2229 if (!rc)
2230 card->options.vnicc.learning_timeout = timeout;
2231
2232 return rc;
2233}
2234
2235/* get current VNICC timeout; called from sysfs show function. Currently, only
2236 * learning supports timeout
2237 */
2238int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2239{
2240 int rc = 0;
2241
2242 QETH_CARD_TEXT(card, 2, "vniccgto");
2243
2244 /* do not get anything if BridgePort is enabled */
2245 if (qeth_bridgeport_is_in_use(card))
2246 return -EBUSY;
2247
2248 /* check if characteristic and get_timeout are supported */
2249 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2250 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2251 return -EOPNOTSUPP;
2252 /* if card is ready, get timeout. Otherwise, just return stored value */
2253 *timeout = card->options.vnicc.learning_timeout;
2254 if (qeth_card_hw_is_reachable(card))
2255 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2256 IPA_VNICC_GET_TIMEOUT,
2257 timeout);
2258
2259 return rc;
2260}
2261
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002262/* check if VNICC is currently enabled */
2263bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2264{
2265 /* if everything is turned off, VNICC is not active */
2266 if (!card->options.vnicc.cur_chars)
2267 return false;
2268 /* default values are only OK if rx_bcast was not enabled by user
2269 * or the card is offline.
2270 */
2271 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2272 if (!card->options.vnicc.rx_bcast_enabled ||
2273 !qeth_card_hw_is_reachable(card))
2274 return false;
2275 }
2276 return true;
2277}
2278
Hans Wippel349d13d2017-09-18 21:18:16 +02002279/* recover user timeout setting */
2280static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2281 u32 *timeout)
2282{
2283 if (card->options.vnicc.sup_chars & vnicc &&
2284 card->options.vnicc.getset_timeout_sup & vnicc &&
2285 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2286 timeout))
2287 return false;
2288 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2289 return true;
2290}
2291
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002292/* recover user characteristic setting */
2293static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2294 bool enable)
2295{
2296 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2297
2298 if (card->options.vnicc.sup_chars & vnicc &&
2299 card->options.vnicc.set_char_sup & vnicc &&
2300 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2301 return false;
2302 card->options.vnicc.wanted_chars &= ~vnicc;
2303 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2304 return true;
2305}
2306
Hans Wippela45b3fa2017-09-18 21:18:14 +02002307/* (re-)initialize VNICC */
2308static void qeth_l2_vnicc_init(struct qeth_card *card)
2309{
Hans Wippel349d13d2017-09-18 21:18:16 +02002310 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002311 unsigned int chars_len, i;
2312 unsigned long chars_tmp;
2313 u32 sup_cmds, vnicc;
2314 bool enable, error;
2315
Hans Wippela45b3fa2017-09-18 21:18:14 +02002316 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002317 /* reset rx_bcast */
2318 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002319 /* initial query and storage of VNIC characteristics */
2320 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002321 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2322 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002323 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2324 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002325 card->options.vnicc.sup_chars = 0;
2326 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002327 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2328 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002329 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002330 /* get supported commands for each supported characteristic */
2331 chars_tmp = card->options.vnicc.sup_chars;
2332 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2333 for_each_set_bit(i, &chars_tmp, chars_len) {
2334 vnicc = BIT(i);
2335 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002336 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2337 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2338 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002339 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2340 !(sup_cmds & IPA_VNICC_DISABLE))
2341 card->options.vnicc.set_char_sup &= ~vnicc;
2342 }
2343 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002344 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2345 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002346 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2347 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2348 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2349 for_each_set_bit(i, &chars_tmp, chars_len) {
2350 vnicc = BIT(i);
2351 enable = card->options.vnicc.wanted_chars & vnicc;
2352 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2353 }
2354 if (error)
2355 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2356}
2357
2358/* configure default values of VNIC characteristics */
2359static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2360{
2361 /* characteristics values */
2362 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2363 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002364 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002365 /* supported commands */
2366 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002367 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002368 /* settings wanted by users */
2369 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002370}
2371
Frank Blaschka4a71df52008-02-15 09:19:42 +01002372module_init(qeth_l2_init);
2373module_exit(qeth_l2_exit);
2374MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2375MODULE_DESCRIPTION("qeth layer 2 discipline");
2376MODULE_LICENSE("GPL");