blob: 5464515b71f1efd79063fd774835a7cd71b879f8 [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 *);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020029static void qeth_l2_set_rx_mode(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010030static void qeth_bridgeport_query_support(struct qeth_card *card);
31static void qeth_bridge_state_change(struct qeth_card *card,
32 struct qeth_ipa_cmd *cmd);
33static void qeth_bridge_host_event(struct qeth_card *card,
34 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020035static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020036static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020037static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
38 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010039
Frank Blaschka4a71df52008-02-15 09:19:42 +010040static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
41{
42 struct qeth_card *card;
43 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020044 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010045 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020046 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010047
48 ndev = NULL;
49 memcpy(&temp_dev_no, read_dev_no, 2);
50 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
51 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020052 ccw_device_get_id(CARD_RDEV(card), &read_devid);
53 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010054 ndev = card->dev;
55 break;
56 }
57 }
58 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
59 return ndev;
60}
61
Julian Wiedmann2aa48672017-09-18 21:18:20 +020062static int qeth_setdelmac_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010063{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010064 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010065
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010066 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010067 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010068 switch (retcode) {
69 case IPA_RC_SUCCESS:
70 rc = 0;
71 break;
72 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020073 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010074 break;
75 case IPA_RC_L2_ADDR_TABLE_FULL:
76 rc = -ENOSPC;
77 break;
78 case IPA_RC_L2_DUP_MAC:
79 case IPA_RC_L2_DUP_LAYER3_MAC:
80 rc = -EEXIST;
81 break;
82 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
83 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
84 rc = -EPERM;
85 break;
86 case IPA_RC_L2_MAC_NOT_FOUND:
87 rc = -ENOENT;
88 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +010089 case -ENOMEM:
90 rc = -ENOMEM;
91 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010092 default:
93 rc = -EIO;
94 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010095 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010096 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010097}
98
Julian Wiedmannac988d72017-01-12 15:48:41 +010099static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
100 enum qeth_ipa_cmds ipacmd)
101{
102 struct qeth_ipa_cmd *cmd;
103 struct qeth_cmd_buffer *iob;
104
105 QETH_CARD_TEXT(card, 2, "L2sdmac");
106 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
107 if (!iob)
108 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100109 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100110 cmd->data.setdelmac.mac_length = ETH_ALEN;
111 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200112 return qeth_setdelmac_makerc(card, qeth_send_ipa_cmd(card, iob,
113 NULL, NULL));
Julian Wiedmannac988d72017-01-12 15:48:41 +0100114}
115
116static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
117{
118 int rc;
119
120 QETH_CARD_TEXT(card, 2, "L2Setmac");
121 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
122 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100123 dev_info(&card->gdev->dev,
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200124 "MAC address %pM successfully registered on device %s\n",
125 mac, card->dev->name);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100126 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100127 switch (rc) {
128 case -EEXIST:
129 dev_warn(&card->gdev->dev,
130 "MAC address %pM already exists\n", mac);
131 break;
132 case -EPERM:
133 dev_warn(&card->gdev->dev,
134 "MAC address %pM is not authorized\n", mac);
135 break;
136 }
137 }
138 return rc;
139}
140
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100141static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100142{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200143 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100144 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100145 int rc;
146
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100147 QETH_CARD_TEXT(card, 2, "L2Wmac");
148 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100149 if (rc == -EEXIST)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100150 QETH_DBF_MESSAGE(2, "MAC %pM already registered on %s\n",
151 mac, QETH_CARD_IFNAME(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100152 else if (rc)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100153 QETH_DBF_MESSAGE(2, "Failed to register MAC %pM on %s: %d\n",
154 mac, QETH_CARD_IFNAME(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100155 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100156}
157
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100158static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100159{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200160 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100161 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100162 int rc;
163
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100164 QETH_CARD_TEXT(card, 2, "L2Rmac");
165 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100166 if (rc)
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100167 QETH_DBF_MESSAGE(2, "Failed to delete MAC %pM on %s: %d\n",
168 mac, QETH_CARD_IFNAME(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100169 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100170}
171
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100172static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200173{
174 struct qeth_mac *mac;
175 struct hlist_node *tmp;
176 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100177
178 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200179 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200180 hash_del(&mac->hnode);
181 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182 }
183 spin_unlock_bh(&card->mclock);
184}
185
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200186static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100187{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000188 if (card->info.type == QETH_CARD_TYPE_OSN)
189 return RTN_UNSPEC;
190 if (is_broadcast_ether_addr(skb->data))
191 return RTN_BROADCAST;
192 if (is_multicast_ether_addr(skb->data))
193 return RTN_MULTICAST;
194 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100195}
196
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200197static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb,
198 int cast_type, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100199{
Frank Blaschka683d7182008-08-01 16:39:13 +0200200 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201
202 memset(hdr, 0, sizeof(struct qeth_hdr));
203 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200204 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100205
206 /* set byte byte 3 to casting flags */
207 if (cast_type == RTN_MULTICAST)
208 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
209 else if (cast_type == RTN_BROADCAST)
210 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
211 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000212 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100213
Frank Blaschka4a71df52008-02-15 09:19:42 +0100214 /* VSWITCH relies on the VLAN
215 * information to be present in
216 * the QDIO header */
217 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
218 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
219 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
220 }
221}
222
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200223static int qeth_setdelvlan_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100224{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200225 if (retcode)
226 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
227
228 switch (retcode) {
229 case IPA_RC_SUCCESS:
230 return 0;
231 case IPA_RC_L2_INVALID_VLAN_ID:
232 return -EINVAL;
233 case IPA_RC_L2_DUP_VLAN_ID:
234 return -EEXIST;
235 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
236 return -ENOENT;
237 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
238 return -EPERM;
239 case -ENOMEM:
240 return -ENOMEM;
241 default:
242 return -EIO;
243 }
244}
245
246static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
247 struct qeth_reply *reply,
248 unsigned long data)
249{
250 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100251
Carsten Otte847a50f2010-06-21 22:57:05 +0000252 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100253 if (cmd->hdr.return_code) {
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200254 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x.\n",
255 cmd->data.setdelvlan.vlan_id,
256 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000257 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
258 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100259 }
260 return 0;
261}
262
263static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200264 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100265{
266 struct qeth_ipa_cmd *cmd;
267 struct qeth_cmd_buffer *iob;
268
Carsten Otte847a50f2010-06-21 22:57:05 +0000269 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100271 if (!iob)
272 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100273 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100274 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200275 return qeth_setdelvlan_makerc(card, qeth_send_ipa_cmd(card, iob,
276 qeth_l2_send_setdelvlan_cb, NULL));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100277}
278
Ursula Braun70919e22011-02-26 22:41:36 -0800279static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280{
281 struct qeth_vlan_vid *id;
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200282
Carsten Otte847a50f2010-06-21 22:57:05 +0000283 QETH_CARD_TEXT(card, 3, "L2prcvln");
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200284 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100285 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800286 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100287 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200288 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100289}
290
Patrick McHardy80d5c362013-04-19 02:04:28 +0000291static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
292 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100293{
Heiko Carstens509e2562008-07-26 02:24:10 -0700294 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100296 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297
Carsten Otte847a50f2010-06-21 22:57:05 +0000298 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000299 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500300 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000301 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000302 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500303 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000304 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200305 id = kmalloc(sizeof(*id), GFP_KERNEL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306 if (id) {
307 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100308 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
309 if (rc) {
310 kfree(id);
311 return rc;
312 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200313 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100314 list_add_tail(&id->list, &card->vid_list);
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200315 mutex_unlock(&card->vid_list_mutex);
Jiri Pirko8e586132011-12-08 19:52:37 -0500316 } else {
317 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100318 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500319 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100320}
321
Patrick McHardy80d5c362013-04-19 02:04:28 +0000322static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
323 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100324{
325 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700326 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100327 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328
Carsten Otte847a50f2010-06-21 22:57:05 +0000329 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000330 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000331 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500332 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000333 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200334 mutex_lock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100335 list_for_each_entry(id, &card->vid_list, list) {
336 if (id->vid == vid) {
337 list_del(&id->list);
338 tmpid = id;
339 break;
340 }
341 }
Julian Wiedmannd4ac0242018-04-26 09:42:13 +0200342 mutex_unlock(&card->vid_list_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100344 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100345 kfree(tmpid);
346 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200347 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100348 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100349}
350
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200351static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100352{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200353 QETH_DBF_TEXT(SETUP , 2, "stopcard");
354 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355
356 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357 if (card->read.state == CH_STATE_UP &&
358 card->write.state == CH_STATE_UP &&
359 (card->state == CARD_STATE_UP)) {
360 if (recovery_mode &&
361 card->info.type != QETH_CARD_TYPE_OSN) {
362 qeth_l2_stop(card->dev);
363 } else {
364 rtnl_lock();
365 dev_close(card->dev);
366 rtnl_unlock();
367 }
Ursula Braun70919e22011-02-26 22:41:36 -0800368 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100369 card->state = CARD_STATE_SOFTSETUP;
370 }
371 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100372 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373 qeth_clear_ipacmd_list(card);
374 card->state = CARD_STATE_HARDSETUP;
375 }
376 if (card->state == CARD_STATE_HARDSETUP) {
377 qeth_qdio_clear_card(card, 0);
378 qeth_clear_qdio_buffers(card);
379 qeth_clear_working_pool_list(card);
380 card->state = CARD_STATE_DOWN;
381 }
382 if (card->state == CARD_STATE_DOWN) {
383 qeth_clear_cmd_buffers(&card->read);
384 qeth_clear_cmd_buffers(&card->write);
385 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100386}
387
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000388static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
389 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000391 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100392 struct sk_buff *skb;
393 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394 unsigned int len;
395
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000396 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000397 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000398 while (budget) {
399 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000400 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000401 &card->rx.b_element, &card->rx.e_offset, &hdr);
402 if (!skb) {
403 *done = 1;
404 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100405 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406 switch (hdr->hdr.l2.id) {
407 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100408 skb->protocol = eth_type_trans(skb, skb->dev);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200409 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
Ursula Braun12883722008-04-01 10:26:56 +0200410 if (skb->protocol == htons(ETH_P_802_2))
411 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100412 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200413 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100414 break;
415 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200416 if (card->info.type == QETH_CARD_TYPE_OSN) {
417 skb_push(skb, sizeof(struct qeth_hdr));
418 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100419 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200420 len = skb->len;
421 card->osn_info.data_cb(skb);
422 break;
423 }
424 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100425 default:
426 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000427 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200428 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100429 continue;
430 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000431 work_done++;
432 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100433 card->stats.rx_packets++;
434 card->stats.rx_bytes += len;
435 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000436 return work_done;
437}
438
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439static int qeth_l2_request_initial_mac(struct qeth_card *card)
440{
441 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100442
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200443 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200444 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100445
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200446 if (MACHINE_IS_VM) {
447 rc = qeth_vm_request_mac(card);
448 if (!rc)
449 goto out;
450 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
451 CARD_BUS_ID(card), rc);
452 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
453 /* fall back to alternative mechanism: */
454 }
455
Ursula Braun5113fec2010-05-16 21:15:14 +0000456 if (card->info.type == QETH_CARD_TYPE_IQD ||
457 card->info.type == QETH_CARD_TYPE_OSM ||
458 card->info.type == QETH_CARD_TYPE_OSX ||
459 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100460 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200461 if (!rc)
462 goto out;
463 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %s: x%x\n",
464 CARD_BUS_ID(card), rc);
465 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
466 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100467 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200468
469 /* some devices don't support a custom MAC address: */
470 if (card->info.type == QETH_CARD_TYPE_OSM ||
471 card->info.type == QETH_CARD_TYPE_OSX)
472 return (rc) ? rc : -EADDRNOTAVAIL;
473 eth_hw_addr_random(card->dev);
474
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200475out:
476 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100477 return 0;
478}
479
480static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
481{
482 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700483 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200484 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100485 int rc = 0;
486
Carsten Otte847a50f2010-06-21 22:57:05 +0000487 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100488
Ursula Braun5113fec2010-05-16 21:15:14 +0000489 if (card->info.type == QETH_CARD_TYPE_OSN ||
490 card->info.type == QETH_CARD_TYPE_OSM ||
491 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000492 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 return -EOPNOTSUPP;
494 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100495 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200496 if (!is_valid_ether_addr(addr->sa_data))
497 return -EADDRNOTAVAIL;
498
Ursula Braun8e98ac42009-03-24 20:57:18 +0000499 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000500 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000501 return -ERESTARTSYS;
502 }
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200503
Julian Wiedmann4789a212018-06-29 19:45:51 +0200504 /* avoid racing against concurrent state change: */
505 if (!mutex_trylock(&card->conf_mutex))
506 return -EAGAIN;
507
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200508 if (!qeth_card_hw_is_reachable(card)) {
509 ether_addr_copy(dev->dev_addr, addr->sa_data);
Julian Wiedmann4789a212018-06-29 19:45:51 +0200510 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200511 }
512
513 /* don't register the same address twice */
514 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
515 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Julian Wiedmann4789a212018-06-29 19:45:51 +0200516 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200517
518 /* add the new address, switch over, drop the old */
519 rc = qeth_l2_send_setmac(card, addr->sa_data);
520 if (rc)
Julian Wiedmann4789a212018-06-29 19:45:51 +0200521 goto out_unlock;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200522 ether_addr_copy(old_addr, dev->dev_addr);
523 ether_addr_copy(dev->dev_addr, addr->sa_data);
524
525 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
526 qeth_l2_remove_mac(card, old_addr);
527 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmann4789a212018-06-29 19:45:51 +0200528
529out_unlock:
530 mutex_unlock(&card->conf_mutex);
531 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100532}
533
Eugene Crosser0db587b2015-05-18 14:27:55 +0200534static void qeth_promisc_to_bridge(struct qeth_card *card)
535{
536 struct net_device *dev = card->dev;
537 enum qeth_ipa_promisc_modes promisc_mode;
538 int role;
539 int rc;
540
541 QETH_CARD_TEXT(card, 3, "pmisc2br");
542
543 if (!card->options.sbp.reflect_promisc)
544 return;
545 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
546 : SET_PROMISC_MODE_OFF;
547 if (promisc_mode == card->info.promisc_mode)
548 return;
549
550 if (promisc_mode == SET_PROMISC_MODE_ON) {
551 if (card->options.sbp.reflect_promisc_primary)
552 role = QETH_SBP_ROLE_PRIMARY;
553 else
554 role = QETH_SBP_ROLE_SECONDARY;
555 } else
556 role = QETH_SBP_ROLE_NONE;
557
558 rc = qeth_bridgeport_setrole(card, role);
559 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
560 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
561 if (!rc) {
562 card->options.sbp.role = role;
563 card->info.promisc_mode = promisc_mode;
564 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200565
566}
567/* New MAC address is added to the hash table and marked to be written on card
568 * only if there is not in the hash table storage already
569 *
570*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100571static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200572{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200573 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200574 struct qeth_mac *mac;
575
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200576 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100577 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200578 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200579 return;
580 }
581 }
582
583 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200584 if (!mac)
585 return;
586
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100587 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200588 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200589
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200590 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200591}
592
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200593static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100594{
Heiko Carstens509e2562008-07-26 02:24:10 -0700595 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000596 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200597 struct qeth_mac *mac;
598 struct hlist_node *tmp;
599 int i;
600 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100601
602 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200603 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100604
Carsten Otte847a50f2010-06-21 22:57:05 +0000605 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000606 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
607 (card->state != CARD_STATE_UP))
608 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200609
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200611
Jiri Pirko22bedad32010-04-01 21:22:57 +0000612 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100613 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800614 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100615 qeth_l2_add_mac(card, ha);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200616
617 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100618 switch (mac->disp_flag) {
619 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100620 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200621 hash_del(&mac->hnode);
622 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100623 break;
624 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100625 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200626 if (rc) {
627 hash_del(&mac->hnode);
628 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100629 break;
630 }
631 /* fall through */
632 default:
633 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200634 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100635 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200636 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200637
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200639
Eugene Crosser0db587b2015-05-18 14:27:55 +0200640 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
641 qeth_setadp_promisc_mode(card);
642 else
643 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100644}
645
Julian Wiedmann72863842017-08-18 10:19:04 +0200646static int qeth_l2_xmit_iqd(struct qeth_card *card, struct sk_buff *skb,
647 struct qeth_qdio_out_q *queue, int cast_type)
648{
649 unsigned int data_offset = ETH_HLEN;
650 struct qeth_hdr *hdr;
651 int rc;
652
653 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
654 if (!hdr)
655 return -ENOMEM;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200656 qeth_l2_fill_header(hdr, skb, cast_type, skb->len);
Julian Wiedmann72863842017-08-18 10:19:04 +0200657 skb_copy_from_linear_data(skb, ((char *)hdr) + sizeof(*hdr),
658 data_offset);
659
660 if (!qeth_get_elements_no(card, skb, 1, data_offset)) {
661 rc = -E2BIG;
662 goto out;
663 }
Julian Wiedmann7c2e9ba2017-09-18 21:18:18 +0200664 rc = qeth_do_send_packet_fast(queue, skb, hdr, data_offset,
Julian Wiedmannf1588172017-08-18 10:19:08 +0200665 sizeof(*hdr) + data_offset);
Julian Wiedmann72863842017-08-18 10:19:04 +0200666out:
667 if (rc)
668 kmem_cache_free(qeth_core_header_cache, hdr);
669 return rc;
670}
671
672static int qeth_l2_xmit_osa(struct qeth_card *card, struct sk_buff *skb,
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200673 struct qeth_qdio_out_q *queue, int cast_type,
674 int ipv)
Julian Wiedmann72863842017-08-18 10:19:04 +0200675{
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200676 int push_len = sizeof(struct qeth_hdr);
Julian Wiedmann72863842017-08-18 10:19:04 +0200677 unsigned int elements, nr_frags;
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200678 unsigned int hdr_elements = 0;
679 struct qeth_hdr *hdr = NULL;
680 unsigned int hd_len = 0;
Julian Wiedmann72863842017-08-18 10:19:04 +0200681 int rc;
682
683 /* fix hardware limitation: as long as we do not have sbal
684 * chaining we can not send long frag lists
685 */
686 if (!qeth_get_elements_no(card, skb, 0, 0)) {
687 rc = skb_linearize(skb);
688
689 if (card->options.performance_stats) {
690 if (rc)
691 card->perf_stats.tx_linfail++;
692 else
693 card->perf_stats.tx_lin++;
694 }
695 if (rc)
696 return rc;
697 }
698 nr_frags = skb_shinfo(skb)->nr_frags;
699
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200700 rc = skb_cow_head(skb, push_len);
701 if (rc)
702 return rc;
703 push_len = qeth_push_hdr(skb, &hdr, push_len);
704 if (push_len < 0)
705 return push_len;
706 if (!push_len) {
707 /* hdr was allocated from cache */
708 hd_len = sizeof(*hdr);
709 hdr_elements = 1;
710 }
711 qeth_l2_fill_header(hdr, skb, cast_type, skb->len - push_len);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200712 if (skb->ip_summed == CHECKSUM_PARTIAL) {
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200713 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200714 if (card->options.performance_stats)
715 card->perf_stats.tx_csum++;
716 }
Julian Wiedmann72863842017-08-18 10:19:04 +0200717
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200718 elements = qeth_get_elements_no(card, skb, hdr_elements, 0);
Julian Wiedmann72863842017-08-18 10:19:04 +0200719 if (!elements) {
720 rc = -E2BIG;
721 goto out;
722 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200723 elements += hdr_elements;
724
725 /* TODO: remove the skb_orphan() once TX completion is fast enough */
726 skb_orphan(skb);
727 rc = qeth_do_send_packet(card, queue, skb, hdr, 0, hd_len, elements);
Julian Wiedmann72863842017-08-18 10:19:04 +0200728out:
729 if (!rc) {
Julian Wiedmann72863842017-08-18 10:19:04 +0200730 if (card->options.performance_stats && nr_frags) {
731 card->perf_stats.sg_skbs_sent++;
732 /* nr_frags + skb->data */
733 card->perf_stats.sg_frags_sent += nr_frags + 1;
734 }
735 } else {
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200736 if (hd_len)
737 kmem_cache_free(qeth_core_header_cache, hdr);
738 if (rc == -EBUSY)
739 /* roll back to ETH header */
740 skb_pull(skb, push_len);
Julian Wiedmann72863842017-08-18 10:19:04 +0200741 }
742 return rc;
743}
744
745static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
746 struct qeth_qdio_out_q *queue)
747{
748 unsigned int elements;
749 struct qeth_hdr *hdr;
750
751 if (skb->protocol == htons(ETH_P_IPV6))
752 return -EPROTONOSUPPORT;
753
754 hdr = (struct qeth_hdr *)skb->data;
755 elements = qeth_get_elements_no(card, skb, 0, 0);
756 if (!elements)
757 return -E2BIG;
758 if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr)))
759 return -EINVAL;
Julian Wiedmann9c3bfda2017-08-18 10:19:07 +0200760 return qeth_do_send_packet(card, queue, skb, hdr, 0, 0, elements);
Julian Wiedmann72863842017-08-18 10:19:04 +0200761}
762
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200763static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
764 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100765{
Heiko Carstens509e2562008-07-26 02:24:10 -0700766 struct qeth_card *card = dev->ml_priv;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000767 int cast_type = qeth_l2_get_cast_type(card, skb);
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200768 int ipv = qeth_get_ip_version(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200769 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100770 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200771 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100772
Stefan Raspl290b8342014-04-28 10:05:08 +0200773 if (card->qdio.do_prio_queueing || (cast_type &&
774 card->info.is_multicast_different))
775 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200776 ipv, cast_type)];
Stefan Raspl290b8342014-04-28 10:05:08 +0200777 else
778 queue = card->qdio.out_qs[card->qdio.default_out_queue];
779
Frank Blaschka4a71df52008-02-15 09:19:42 +0100780 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
781 card->stats.tx_carrier_errors++;
782 goto tx_drop;
783 }
784
Frank Blaschka4a71df52008-02-15 09:19:42 +0100785 if (card->options.performance_stats) {
786 card->perf_stats.outbound_cnt++;
787 card->perf_stats.outbound_start_time = qeth_get_micros();
788 }
789 netif_stop_queue(dev);
790
Julian Wiedmann72863842017-08-18 10:19:04 +0200791 switch (card->info.type) {
792 case QETH_CARD_TYPE_OSN:
793 rc = qeth_l2_xmit_osn(card, skb, queue);
794 break;
795 case QETH_CARD_TYPE_IQD:
796 rc = qeth_l2_xmit_iqd(card, skb, queue, cast_type);
797 break;
798 default:
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200799 rc = qeth_l2_xmit_osa(card, skb, queue, cast_type, ipv);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 }
801
Frank Blaschka4a71df52008-02-15 09:19:42 +0100802 if (!rc) {
803 card->stats.tx_packets++;
804 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann72863842017-08-18 10:19:04 +0200805 if (card->options.performance_stats)
806 card->perf_stats.outbound_time += qeth_get_micros() -
807 card->perf_stats.outbound_start_time;
808 netif_wake_queue(dev);
809 return NETDEV_TX_OK;
810 } else if (rc == -EBUSY) {
811 return NETDEV_TX_BUSY;
812 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813
814tx_drop:
815 card->stats.tx_dropped++;
816 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200818 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 return NETDEV_TX_OK;
820}
821
Ursula Braun39423442011-01-12 20:42:24 +0000822static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100823{
Heiko Carstens509e2562008-07-26 02:24:10 -0700824 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000825 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100826
Carsten Otte847a50f2010-06-21 22:57:05 +0000827 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000828 if (card->state == CARD_STATE_UP)
829 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100830 if (card->state != CARD_STATE_SOFTSETUP)
831 return -ENODEV;
832
833 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
834 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000835 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836 return -EPERM;
837 }
838 card->data.state = CH_STATE_UP;
839 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100840 netif_start_queue(dev);
841
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000842 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
843 napi_enable(&card->napi);
844 napi_schedule(&card->napi);
845 } else
846 rc = -EIO;
847 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848}
849
Ursula Braun39423442011-01-12 20:42:24 +0000850static int qeth_l2_open(struct net_device *dev)
851{
852 struct qeth_card *card = dev->ml_priv;
853
854 QETH_CARD_TEXT(card, 5, "qethope_");
855 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
856 QETH_CARD_TEXT(card, 3, "openREC");
857 return -ERESTARTSYS;
858 }
859 return __qeth_l2_open(dev);
860}
861
Frank Blaschka4a71df52008-02-15 09:19:42 +0100862static int qeth_l2_stop(struct net_device *dev)
863{
Heiko Carstens509e2562008-07-26 02:24:10 -0700864 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865
Carsten Otte847a50f2010-06-21 22:57:05 +0000866 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000868 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100869 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000870 napi_disable(&card->napi);
871 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 return 0;
873}
874
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200875static const struct device_type qeth_l2_devtype = {
876 .name = "qeth_layer2",
877 .groups = qeth_l2_attr_groups,
878};
879
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
881{
882 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200883 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100884
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200885 if (gdev->dev.type == &qeth_generic_devtype) {
886 rc = qeth_l2_create_device_attributes(&gdev->dev);
887 if (rc)
888 return rc;
889 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100890 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200891 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000893 card->info.hwtrap = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +0200894 qeth_l2_vnicc_set_defaults(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100895 return 0;
896}
897
898static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
899{
900 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
901
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200902 if (cgdev->dev.type == &qeth_generic_devtype)
903 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000904 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100905 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
906
Ursula Braun70919e22011-02-26 22:41:36 -0800907 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909
910 if (card->dev) {
911 unregister_netdev(card->dev);
Julian Wiedmann6be68732018-03-20 07:59:12 +0100912 free_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 card->dev = NULL;
914 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100915 return;
916}
917
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700918static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100920 .get_strings = qeth_core_get_strings,
921 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000922 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100923 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200924 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100925};
926
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700927static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928 .get_strings = qeth_core_get_strings,
929 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000930 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100931 .get_drvinfo = qeth_core_get_drvinfo,
932};
933
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000934static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800935 .ndo_open = qeth_l2_open,
936 .ndo_stop = qeth_l2_stop,
937 .ndo_get_stats = qeth_get_stats,
938 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100939 .ndo_features_check = qeth_features_check,
Frank Blaschka8403b132009-01-08 10:50:55 -0800940 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200941 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200942 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800943 .ndo_set_mac_address = qeth_l2_set_mac_address,
944 .ndo_change_mtu = qeth_change_mtu,
945 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
946 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
947 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200948 .ndo_fix_features = qeth_fix_features,
949 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800950};
951
Frank Blaschka4a71df52008-02-15 09:19:42 +0100952static int qeth_l2_setup_netdev(struct qeth_card *card)
953{
954 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200956 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
957 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958 break;
959 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200960 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
961 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100962 break;
963 default:
964 card->dev = alloc_etherdev(0);
965 }
966
967 if (!card->dev)
968 return -ENODEV;
969
Heiko Carstens509e2562008-07-26 02:24:10 -0700970 card->dev->ml_priv = card;
Julian Wiedmannd3aacac2018-03-09 18:12:55 +0100971 card->dev->priv_flags |= IFF_UNICAST_FLT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -0400974 card->dev->min_mtu = 64;
975 card->dev->max_mtu = ETH_MAX_MTU;
Ursula Braun71c46892018-04-26 09:42:15 +0200976 card->dev->dev_port = card->info.portno;
Frank Blaschka8403b132009-01-08 10:50:55 -0800977 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200978 if (card->info.type == QETH_CARD_TYPE_OSN) {
979 card->dev->ethtool_ops = &qeth_l2_osn_ops;
980 card->dev->flags |= IFF_NOARP;
981 } else {
982 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
983 }
Julian Wiedmann9400c532017-10-18 17:40:20 +0200984
985 if (card->info.type == QETH_CARD_TYPE_OSM)
986 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
987 else
988 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann0f342942018-03-09 18:12:54 +0100989
990 if (card->info.type != QETH_CARD_TYPE_OSN &&
991 card->info.type != QETH_CARD_TYPE_IQD) {
992 card->dev->priv_flags &= ~IFF_TX_SKB_SHARING;
993 card->dev->needed_headroom = sizeof(struct qeth_hdr);
994 card->dev->hw_features |= NETIF_F_SG;
995 card->dev->vlan_features |= NETIF_F_SG;
996 }
997
Thomas Richter4d7def22015-09-18 16:06:51 +0200998 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100999 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +02001000 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +02001001 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001002 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001003 card->dev->vlan_features |= NETIF_F_IP_CSUM;
1004 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001005 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02001006 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
1007 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
1008 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
1009 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +02001010 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
1011 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
1012 card->dev->hw_features |= NETIF_F_RXCSUM;
1013 card->dev->vlan_features |= NETIF_F_RXCSUM;
1014 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +02001015
Frank Blaschka4a71df52008-02-15 09:19:42 +01001016 card->info.broadcast_capable = 1;
1017 qeth_l2_request_initial_mac(card);
1018 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001019 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01001020 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 return register_netdev(card->dev);
1022}
1023
Thomas Richter4d7def22015-09-18 16:06:51 +02001024static int qeth_l2_start_ipassists(struct qeth_card *card)
1025{
1026 /* configure isolation level */
1027 if (qeth_set_access_ctrl_online(card, 0))
1028 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +02001029 return 0;
1030}
1031
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001032static void qeth_l2_trace_features(struct qeth_card *card)
1033{
Hans Wippela45b3fa2017-09-18 21:18:14 +02001034 /* Set BridgePort features */
1035 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001036 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
1037 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +02001038 /* VNIC Characteristics features */
1039 QETH_CARD_TEXT(card, 2, "feaVNICC");
1040 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
1041 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001042}
1043
Frank Blaschka4a71df52008-02-15 09:19:42 +01001044static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1045{
1046 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1047 int rc = 0;
1048 enum qeth_card_states recover_flag;
1049
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001050 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001051 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001052 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1053 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001054
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001056 rc = qeth_core_hardsetup_card(card);
1057 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001058 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001059 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001060 goto out_remove;
1061 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001062 qeth_bridgeport_query_support(card);
1063 if (card->options.sbp.supported_funcs)
1064 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001065 "The device represents a Bridge Capable Port\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066
Ursula Braunaa909222009-11-12 00:11:43 +00001067 if (!card->dev && qeth_l2_setup_netdev(card)) {
1068 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001069 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001070 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001071
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +02001072 if (card->info.type != QETH_CARD_TYPE_OSN &&
1073 !qeth_l2_send_setmac(card, card->dev->dev_addr))
1074 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075
Frank Blaschka1da74b12011-05-12 18:45:02 +00001076 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1077 if (card->info.hwtrap &&
1078 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1079 card->info.hwtrap = 0;
1080 } else
1081 card->info.hwtrap = 0;
1082
Hans Wippela45b3fa2017-09-18 21:18:14 +02001083 /* for the rx_bcast characteristic, init VNICC after setmac */
1084 qeth_l2_vnicc_init(card);
1085
1086 qeth_trace_features(card);
1087 qeth_l2_trace_features(card);
1088
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001089 qeth_l2_setup_bridgeport_attrs(card);
1090
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091 card->state = CARD_STATE_HARDSETUP;
1092 qeth_print_status_message(card);
1093
1094 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001095 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001096
Ursula Braun5113fec2010-05-16 21:15:14 +00001097 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001098 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001099 rc = qeth_l2_start_ipassists(card);
1100 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001101 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001102 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001103
Julian Wiedmann9400c532017-10-18 17:40:20 +02001104 if (card->info.type != QETH_CARD_TYPE_OSN)
Ursula Braun70919e22011-02-26 22:41:36 -08001105 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001106
1107 netif_tx_disable(card->dev);
1108
1109 rc = qeth_init_qdio_queues(card);
1110 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001111 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001112 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113 goto out_remove;
1114 }
1115 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001116 if (card->lan_online)
1117 netif_carrier_on(card->dev);
1118 else
1119 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001120
1121 qeth_set_allowed_threads(card, 0xffffffff, 0);
1122 if (recover_flag == CARD_STATE_RECOVER) {
1123 if (recovery_mode &&
1124 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001125 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001126 } else {
1127 rtnl_lock();
1128 dev_open(card->dev);
1129 rtnl_unlock();
1130 }
1131 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001132 qeth_l2_set_rx_mode(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02001133 rtnl_lock();
1134 qeth_recover_features(card->dev);
1135 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001136 }
1137 /* let user_space know that device is online */
1138 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001139 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001140 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001142
Frank Blaschka4a71df52008-02-15 09:19:42 +01001143out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001144 qeth_l2_stop_card(card, 0);
1145 ccw_device_set_offline(CARD_DDEV(card));
1146 ccw_device_set_offline(CARD_WDEV(card));
1147 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001148 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001149 if (recover_flag == CARD_STATE_RECOVER)
1150 card->state = CARD_STATE_RECOVER;
1151 else
1152 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001153 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001154 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001155 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001156}
1157
1158static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1159{
1160 return __qeth_l2_set_online(gdev, 0);
1161}
1162
1163static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1164 int recovery_mode)
1165{
1166 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1167 int rc = 0, rc2 = 0, rc3 = 0;
1168 enum qeth_card_states recover_flag;
1169
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001170 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001171 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001172 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1173 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174
1175 if (card->dev && netif_carrier_ok(card->dev))
1176 netif_carrier_off(card->dev);
1177 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001178 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1179 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1180 card->info.hwtrap = 1;
1181 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001182 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001183 rc = ccw_device_set_offline(CARD_DDEV(card));
1184 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1185 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1186 if (!rc)
1187 rc = (rc2) ? rc2 : rc3;
1188 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001189 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001190 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001191 if (recover_flag == CARD_STATE_UP)
1192 card->state = CARD_STATE_RECOVER;
1193 /* let user_space know that device is offline */
1194 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001195 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001196 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001197 return 0;
1198}
1199
1200static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1201{
1202 return __qeth_l2_set_offline(cgdev, 0);
1203}
1204
1205static int qeth_l2_recover(void *ptr)
1206{
1207 struct qeth_card *card;
1208 int rc = 0;
1209
1210 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001211 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001212 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1213 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001214 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001215 dev_warn(&card->gdev->dev,
1216 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001217 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001218 __qeth_l2_set_offline(card->gdev, 1);
1219 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001220 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001221 dev_info(&card->gdev->dev,
1222 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001223 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001224 qeth_close_dev(card);
1225 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001226 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001227 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001228 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001229 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1230 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001231 return 0;
1232}
1233
1234static int __init qeth_l2_init(void)
1235{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001236 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001237 return 0;
1238}
1239
1240static void __exit qeth_l2_exit(void)
1241{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001242 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001243}
1244
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001245static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1246{
1247 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1248
1249 if (card->dev)
1250 netif_device_detach(card->dev);
1251 qeth_set_allowed_threads(card, 0, 1);
1252 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1253 if (gdev->state == CCWGROUP_OFFLINE)
1254 return 0;
1255 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001256 if (card->info.hwtrap)
1257 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001258 __qeth_l2_set_offline(card->gdev, 1);
1259 } else
1260 __qeth_l2_set_offline(card->gdev, 0);
1261 return 0;
1262}
1263
1264static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1265{
1266 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1267 int rc = 0;
1268
1269 if (gdev->state == CCWGROUP_OFFLINE)
1270 goto out;
1271
1272 if (card->state == CARD_STATE_RECOVER) {
1273 rc = __qeth_l2_set_online(card->gdev, 1);
1274 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001275 rtnl_lock();
1276 dev_close(card->dev);
1277 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001278 }
1279 } else
1280 rc = __qeth_l2_set_online(card->gdev, 0);
1281out:
1282 qeth_set_allowed_threads(card, 0xffffffff, 0);
1283 if (card->dev)
1284 netif_device_attach(card->dev);
1285 if (rc)
1286 dev_warn(&card->gdev->dev, "The qeth device driver "
1287 "failed to recover an error on the device\n");
1288 return rc;
1289}
1290
Eugene Crosserc044dc22014-01-29 09:23:48 +01001291/* Returns zero if the command is successfully "consumed" */
1292static int qeth_l2_control_event(struct qeth_card *card,
1293 struct qeth_ipa_cmd *cmd)
1294{
1295 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001296 case IPA_CMD_SETBRIDGEPORT_OSA:
1297 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001298 if (cmd->data.sbp.hdr.command_code ==
1299 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1300 qeth_bridge_state_change(card, cmd);
1301 return 0;
1302 } else
1303 return 1;
1304 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1305 qeth_bridge_host_event(card, cmd);
1306 return 0;
1307 default:
1308 return 1;
1309 }
1310}
1311
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001312struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001313 .devtype = &qeth_l2_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001314 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001315 .recover = qeth_l2_recover,
1316 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001317 .remove = qeth_l2_remove_device,
1318 .set_online = qeth_l2_set_online,
1319 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001320 .freeze = qeth_l2_pm_suspend,
1321 .thaw = qeth_l2_pm_resume,
1322 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001323 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001324 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001325};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001326EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001327
1328static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1329 struct qeth_cmd_buffer *iob)
1330{
1331 unsigned long flags;
1332 int rc = 0;
1333
Carsten Otte847a50f2010-06-21 22:57:05 +00001334 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335
1336 wait_event(card->wait_q,
1337 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1338 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001339 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001340 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
Julian Wiedmanndb71bbb2018-04-19 12:52:10 +02001341 rc = ccw_device_start_timeout(CARD_WDEV(card), &card->write.ccw,
1342 (addr_t) iob, 0, 0, QETH_IPA_TIMEOUT);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1344 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001345 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001346 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001347 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001348 qeth_release_buffer(iob->channel, iob);
1349 atomic_set(&card->write.irq_pending, 0);
1350 wake_up(&card->wait_q);
1351 }
1352 return rc;
1353}
1354
1355static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1356 struct qeth_cmd_buffer *iob, int data_len)
1357{
1358 u16 s1, s2;
1359
Carsten Otte847a50f2010-06-21 22:57:05 +00001360 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001361
1362 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1363 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1364 s2 = (u16)data_len;
1365 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1366 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1367 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1368 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1369 return qeth_osn_send_control_data(card, s1, iob);
1370}
1371
1372int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1373{
1374 struct qeth_cmd_buffer *iob;
1375 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001376
Frank Blaschka4a71df52008-02-15 09:19:42 +01001377 if (!dev)
1378 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001379 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 if (!card)
1381 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001382 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001383 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001384 return -ENODEV;
1385 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001386 memcpy(__ipa_cmd(iob), data, data_len);
1387 return qeth_osn_send_ipa_cmd(card, iob, data_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001388}
1389EXPORT_SYMBOL(qeth_osn_assist);
1390
1391int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1392 int (*assist_cb)(struct net_device *, void *),
1393 int (*data_cb)(struct sk_buff *))
1394{
1395 struct qeth_card *card;
1396
Frank Blaschka4a71df52008-02-15 09:19:42 +01001397 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1398 if (*dev == NULL)
1399 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001400 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401 if (!card)
1402 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001403 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404 if ((assist_cb == NULL) || (data_cb == NULL))
1405 return -EINVAL;
1406 card->osn_info.assist_cb = assist_cb;
1407 card->osn_info.data_cb = data_cb;
1408 return 0;
1409}
1410EXPORT_SYMBOL(qeth_osn_register);
1411
1412void qeth_osn_deregister(struct net_device *dev)
1413{
1414 struct qeth_card *card;
1415
Frank Blaschka4a71df52008-02-15 09:19:42 +01001416 if (!dev)
1417 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001418 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001419 if (!card)
1420 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001421 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001422 card->osn_info.assist_cb = NULL;
1423 card->osn_info.data_cb = NULL;
1424 return;
1425}
1426EXPORT_SYMBOL(qeth_osn_deregister);
1427
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001428/* SETBRIDGEPORT support, async notifications */
1429
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001430enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1431
1432/**
1433 * qeth_bridge_emit_host_event() - bridgeport address change notification
1434 * @card: qeth_card structure pointer, for udev events.
1435 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1436 * and reset token and addr_lnid are unused and may be NULL.
1437 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1438 * object, 0 - addition of an object.
1439 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1440 * @token: "network token" structure identifying physical address of the port.
1441 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1442 *
1443 * This function is called when registrations and deregistrations are
1444 * reported by the hardware, and also when notifications are enabled -
1445 * for all currently registered addresses.
1446 */
1447static void qeth_bridge_emit_host_event(struct qeth_card *card,
1448 enum qeth_an_event_type evtype,
1449 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1450{
1451 char str[7][32];
1452 char *env[8];
1453 int i = 0;
1454
1455 switch (evtype) {
1456 case anev_reg_unreg:
1457 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1458 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1459 ? "deregister" : "register");
1460 env[i] = str[i]; i++;
1461 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1462 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1463 addr_lnid->lnid);
1464 env[i] = str[i]; i++;
1465 }
1466 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001467 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001468 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001469 env[i] = str[i]; i++;
1470 }
1471 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1472 token->cssid, token->ssid, token->devnum);
1473 env[i] = str[i]; i++;
1474 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1475 env[i] = str[i]; i++;
1476 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1477 token->chpid);
1478 env[i] = str[i]; i++;
1479 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1480 env[i] = str[i]; i++;
1481 break;
1482 case anev_abort:
1483 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1484 env[i] = str[i]; i++;
1485 break;
1486 case anev_reset:
1487 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1488 env[i] = str[i]; i++;
1489 break;
1490 }
1491 env[i] = NULL;
1492 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1493}
1494
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001495struct qeth_bridge_state_data {
1496 struct work_struct worker;
1497 struct qeth_card *card;
1498 struct qeth_sbp_state_change qports;
1499};
1500
1501static void qeth_bridge_state_change_worker(struct work_struct *work)
1502{
1503 struct qeth_bridge_state_data *data =
1504 container_of(work, struct qeth_bridge_state_data, worker);
1505 /* We are only interested in the first entry - local port */
1506 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1507 char env_locrem[32];
1508 char env_role[32];
1509 char env_state[32];
1510 char *env[] = {
1511 env_locrem,
1512 env_role,
1513 env_state,
1514 NULL
1515 };
1516
1517 /* Role should not change by itself, but if it did, */
1518 /* information from the hardware is authoritative. */
1519 mutex_lock(&data->card->conf_mutex);
1520 data->card->options.sbp.role = entry->role;
1521 mutex_unlock(&data->card->conf_mutex);
1522
1523 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1524 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1525 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1526 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1527 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1528 "<INVALID>");
1529 snprintf(env_state, sizeof(env_state), "STATE=%s",
1530 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1531 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1532 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1533 "<INVALID>");
1534 kobject_uevent_env(&data->card->gdev->dev.kobj,
1535 KOBJ_CHANGE, env);
1536 kfree(data);
1537}
1538
Eugene Crosserc044dc22014-01-29 09:23:48 +01001539static void qeth_bridge_state_change(struct qeth_card *card,
1540 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001541{
1542 struct qeth_sbp_state_change *qports =
1543 &cmd->data.sbp.data.state_change;
1544 struct qeth_bridge_state_data *data;
1545 int extrasize;
1546
1547 QETH_CARD_TEXT(card, 2, "brstchng");
1548 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001549 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001550 return;
1551 }
1552 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1553 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1554 GFP_ATOMIC);
1555 if (!data) {
1556 QETH_CARD_TEXT(card, 2, "BPSalloc");
1557 return;
1558 }
1559 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1560 data->card = card;
1561 memcpy(&data->qports, qports,
1562 sizeof(struct qeth_sbp_state_change) + extrasize);
1563 queue_work(qeth_wq, &data->worker);
1564}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001565
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001566struct qeth_bridge_host_data {
1567 struct work_struct worker;
1568 struct qeth_card *card;
1569 struct qeth_ipacmd_addr_change hostevs;
1570};
1571
1572static void qeth_bridge_host_event_worker(struct work_struct *work)
1573{
1574 struct qeth_bridge_host_data *data =
1575 container_of(work, struct qeth_bridge_host_data, worker);
1576 int i;
1577
1578 if (data->hostevs.lost_event_mask) {
1579 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001580"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001581 data->card->dev->name,
1582 (data->hostevs.lost_event_mask == 0x01)
1583 ? "Overflow"
1584 : (data->hostevs.lost_event_mask == 0x02)
1585 ? "Bridge port state change"
1586 : "Unknown reason");
1587 mutex_lock(&data->card->conf_mutex);
1588 data->card->options.sbp.hostnotification = 0;
1589 mutex_unlock(&data->card->conf_mutex);
1590 qeth_bridge_emit_host_event(data->card, anev_abort,
1591 0, NULL, NULL);
1592 } else
1593 for (i = 0; i < data->hostevs.num_entries; i++) {
1594 struct qeth_ipacmd_addr_change_entry *entry =
1595 &data->hostevs.entry[i];
1596 qeth_bridge_emit_host_event(data->card,
1597 anev_reg_unreg,
1598 entry->change_code,
1599 &entry->token, &entry->addr_lnid);
1600 }
1601 kfree(data);
1602}
1603
Eugene Crosserc044dc22014-01-29 09:23:48 +01001604static void qeth_bridge_host_event(struct qeth_card *card,
1605 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001606{
1607 struct qeth_ipacmd_addr_change *hostevs =
1608 &cmd->data.addrchange;
1609 struct qeth_bridge_host_data *data;
1610 int extrasize;
1611
1612 QETH_CARD_TEXT(card, 2, "brhostev");
1613 if (cmd->hdr.return_code != 0x0000) {
1614 if (cmd->hdr.return_code == 0x0010) {
1615 if (hostevs->lost_event_mask == 0x00)
1616 hostevs->lost_event_mask = 0xff;
1617 } else {
1618 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1619 cmd->hdr.return_code);
1620 return;
1621 }
1622 }
1623 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1624 hostevs->num_entries;
1625 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1626 GFP_ATOMIC);
1627 if (!data) {
1628 QETH_CARD_TEXT(card, 2, "BPHalloc");
1629 return;
1630 }
1631 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1632 data->card = card;
1633 memcpy(&data->hostevs, hostevs,
1634 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1635 queue_work(qeth_wq, &data->worker);
1636}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001637
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001638/* SETBRIDGEPORT support; sending commands */
1639
1640struct _qeth_sbp_cbctl {
1641 u16 ipa_rc;
1642 u16 cmd_rc;
1643 union {
1644 u32 supported;
1645 struct {
1646 enum qeth_sbp_roles *role;
1647 enum qeth_sbp_states *state;
1648 } qports;
1649 } data;
1650};
1651
1652/**
1653 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1654 * @card: qeth_card structure pointer, for debug messages.
1655 * @cbctl: state structure with hardware return codes.
1656 * @setcmd: IPA command code
1657 *
1658 * Returns negative errno-compatible error indication or 0 on success.
1659 */
1660static int qeth_bridgeport_makerc(struct qeth_card *card,
1661 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1662{
1663 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001664 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001665
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001666 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1667 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001668 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001669 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001670 rc = 0;
1671 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001672 case IPA_RC_L2_UNSUPPORTED_CMD:
1673 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001674 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001675 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001676 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1677 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001678 rc = -ENODEV; /* maybe not the best code here? */
1679 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001680 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001681 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001682 case IPA_RC_SBP_OSA_OS_MISMATCH:
1683 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001684 rc = -EPERM;
1685 dev_err(&card->gdev->dev,
1686 "A Bridge Port is already configured by a different operating system\n");
1687 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001688 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1689 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001690 switch (setcmd) {
1691 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1692 rc = -EEXIST;
1693 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001694 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001695 break;
1696 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1697 rc = -EBUSY;
1698 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001699 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001700 break;
1701 default:
1702 rc = -EIO;
1703 }
1704 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001705 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1706 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001707 rc = -EBUSY;
1708 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001709 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001710 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001711 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1712 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001713 rc = -EEXIST;
1714 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001715 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001716 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001717 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1718 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001719 rc = -EBUSY;
1720 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001721 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001722 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001723 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1724 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001725 rc = -EACCES;
1726 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001727 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001728 break;
1729 default:
1730 rc = -EIO;
1731 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001732 else
1733 switch (cbctl->ipa_rc) {
1734 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001735 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001736 break;
1737 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001738 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001739 break;
1740 default:
1741 rc = -EIO;
1742 }
1743
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001744 if (rc) {
1745 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1746 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1747 }
1748 return rc;
1749}
1750
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001751static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1752 enum qeth_ipa_sbp_cmd sbp_cmd,
1753 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001754{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001755 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1756 IPA_CMD_SETBRIDGEPORT_IQD :
1757 IPA_CMD_SETBRIDGEPORT_OSA;
1758 struct qeth_cmd_buffer *iob;
1759 struct qeth_ipa_cmd *cmd;
1760
1761 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1762 if (!iob)
1763 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001764 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001765 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1766 cmd_length;
1767 cmd->data.sbp.hdr.command_code = sbp_cmd;
1768 cmd->data.sbp.hdr.used_total = 1;
1769 cmd->data.sbp.hdr.seq_no = 1;
1770 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001771}
1772
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001773static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1774 struct qeth_reply *reply, unsigned long data)
1775{
1776 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1777 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1778 QETH_CARD_TEXT(card, 2, "brqsupcb");
1779 cbctl->ipa_rc = cmd->hdr.return_code;
1780 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1781 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1782 cbctl->data.supported =
1783 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1784 } else {
1785 cbctl->data.supported = 0;
1786 }
1787 return 0;
1788}
1789
1790/**
1791 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1792 * @card: qeth_card structure pointer.
1793 *
1794 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1795 * strucutre: card->options.sbp.supported_funcs.
1796 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001797static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001798{
1799 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001800 struct _qeth_sbp_cbctl cbctl;
1801
1802 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001803 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1804 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001805 if (!iob)
1806 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001807 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1808 (void *)&cbctl) ||
1809 qeth_bridgeport_makerc(card, &cbctl,
1810 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1811 /* non-zero makerc signifies failure, and produce messages */
1812 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1813 return;
1814 }
1815 card->options.sbp.supported_funcs = cbctl.data.supported;
1816}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001817
1818static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1819 struct qeth_reply *reply, unsigned long data)
1820{
1821 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1822 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1823 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1824
1825 QETH_CARD_TEXT(card, 2, "brqprtcb");
1826 cbctl->ipa_rc = cmd->hdr.return_code;
1827 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1828 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1829 return 0;
1830 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1831 cbctl->cmd_rc = 0xffff;
1832 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1833 return 0;
1834 }
1835 /* first entry contains the state of the local port */
1836 if (qports->num_entries > 0) {
1837 if (cbctl->data.qports.role)
1838 *cbctl->data.qports.role = qports->entry[0].role;
1839 if (cbctl->data.qports.state)
1840 *cbctl->data.qports.state = qports->entry[0].state;
1841 }
1842 return 0;
1843}
1844
1845/**
1846 * qeth_bridgeport_query_ports() - query local bridgeport status.
1847 * @card: qeth_card structure pointer.
1848 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1849 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1850 *
1851 * Returns negative errno-compatible error indication or 0 on success.
1852 *
1853 * 'role' and 'state' are not updated in case of hardware operation failure.
1854 */
1855int qeth_bridgeport_query_ports(struct qeth_card *card,
1856 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1857{
1858 int rc = 0;
1859 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001860 struct _qeth_sbp_cbctl cbctl = {
1861 .data = {
1862 .qports = {
1863 .role = role,
1864 .state = state,
1865 },
1866 },
1867 };
1868
1869 QETH_CARD_TEXT(card, 2, "brqports");
1870 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1871 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001872 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001873 if (!iob)
1874 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001875 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1876 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001877 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001878 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001879 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001880}
1881EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1882
1883static int qeth_bridgeport_set_cb(struct qeth_card *card,
1884 struct qeth_reply *reply, unsigned long data)
1885{
1886 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1887 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1888 QETH_CARD_TEXT(card, 2, "brsetrcb");
1889 cbctl->ipa_rc = cmd->hdr.return_code;
1890 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1891 return 0;
1892}
1893
1894/**
1895 * qeth_bridgeport_setrole() - Assign primary role to the port.
1896 * @card: qeth_card structure pointer.
1897 * @role: Role to assign.
1898 *
1899 * Returns negative errno-compatible error indication or 0 on success.
1900 */
1901int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1902{
1903 int rc = 0;
1904 int cmdlength;
1905 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001906 struct _qeth_sbp_cbctl cbctl;
1907 enum qeth_ipa_sbp_cmd setcmd;
1908
1909 QETH_CARD_TEXT(card, 2, "brsetrol");
1910 switch (role) {
1911 case QETH_SBP_ROLE_NONE:
1912 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001913 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001914 break;
1915 case QETH_SBP_ROLE_PRIMARY:
1916 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001917 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001918 break;
1919 case QETH_SBP_ROLE_SECONDARY:
1920 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001921 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001922 break;
1923 default:
1924 return -EINVAL;
1925 }
1926 if (!(card->options.sbp.supported_funcs & setcmd))
1927 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001928 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001929 if (!iob)
1930 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001931 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1932 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001933 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001934 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001935 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001936}
1937
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001938/**
1939 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1940 * @card: qeth_card structure pointer, for debug messages.
1941 *
1942 * Returns negative errno-compatible error indication or 0 on success.
1943 */
1944static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1945{
1946 int rc;
1947
1948 if (pnso_rc == 0)
1949 switch (response) {
1950 case 0x0001:
1951 rc = 0;
1952 break;
1953 case 0x0004:
1954 case 0x0100:
1955 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001956 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001957 dev_err(&card->gdev->dev,
1958 "Setting address notification failed\n");
1959 break;
1960 case 0x0107:
1961 rc = -EAGAIN;
1962 break;
1963 default:
1964 rc = -EIO;
1965 }
1966 else
1967 rc = -EIO;
1968
1969 if (rc) {
1970 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1971 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1972 }
1973 return rc;
1974}
1975
1976static void qeth_bridgeport_an_set_cb(void *priv,
1977 enum qdio_brinfo_entry_type type, void *entry)
1978{
1979 struct qeth_card *card = (struct qeth_card *)priv;
1980 struct qdio_brinfo_entry_l2 *l2entry;
1981 u8 code;
1982
1983 if (type != l2_addr_lnid) {
1984 WARN_ON_ONCE(1);
1985 return;
1986 }
1987
1988 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1989 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1990 if (l2entry->addr_lnid.lnid)
1991 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1992 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1993 (struct net_if_token *)&l2entry->nit,
1994 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1995}
1996
1997/**
1998 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1999 * @card: qeth_card structure pointer.
2000 * @enable: 0 - disable, non-zero - enable notifications
2001 *
2002 * Returns negative errno-compatible error indication or 0 on success.
2003 *
2004 * On enable, emits a series of address notifications udev events for all
2005 * currently registered hosts.
2006 */
2007int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2008{
2009 int rc;
2010 u16 response;
2011 struct ccw_device *ddev;
2012 struct subchannel_id schid;
2013
2014 if (!card)
2015 return -EINVAL;
2016 if (!card->options.sbp.supported_funcs)
2017 return -EOPNOTSUPP;
2018 ddev = CARD_DDEV(card);
2019 ccw_device_get_schid(ddev, &schid);
2020
2021 if (enable) {
2022 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2023 rc = qdio_pnso_brinfo(schid, 1, &response,
2024 qeth_bridgeport_an_set_cb, card);
2025 } else
2026 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2027 return qeth_anset_makerc(card, rc, response);
2028}
2029EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2030
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002031static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
2032{
2033 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
2034 card->options.sbp.hostnotification);
2035}
2036
Hans Wippela45b3fa2017-09-18 21:18:14 +02002037/* VNIC Characteristics support */
2038
2039/* handle VNICC IPA command return codes; convert to error codes */
2040static int qeth_l2_vnicc_makerc(struct qeth_card *card, int ipa_rc)
2041{
2042 int rc;
2043
2044 switch (ipa_rc) {
2045 case IPA_RC_SUCCESS:
2046 return ipa_rc;
2047 case IPA_RC_L2_UNSUPPORTED_CMD:
2048 case IPA_RC_NOTSUPP:
2049 rc = -EOPNOTSUPP;
2050 break;
2051 case IPA_RC_VNICC_OOSEQ:
2052 rc = -EALREADY;
2053 break;
2054 case IPA_RC_VNICC_VNICBP:
2055 rc = -EBUSY;
2056 break;
2057 case IPA_RC_L2_ADDR_TABLE_FULL:
2058 rc = -ENOSPC;
2059 break;
2060 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
2061 rc = -EACCES;
2062 break;
2063 default:
2064 rc = -EIO;
2065 }
2066
2067 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
2068 return rc;
2069}
2070
2071/* generic VNICC request call back control */
2072struct _qeth_l2_vnicc_request_cbctl {
2073 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002074 struct {
2075 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02002076 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002077 } param;
2078 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02002079 union{
2080 u32 *sup_cmds;
2081 u32 *timeout;
2082 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002083 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002084};
2085
2086/* generic VNICC request call back */
2087static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
2088 struct qeth_reply *reply,
2089 unsigned long data)
2090{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002091 struct _qeth_l2_vnicc_request_cbctl *cbctl =
2092 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002093 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
2094 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
2095
2096 QETH_CARD_TEXT(card, 2, "vniccrcb");
2097 if (cmd->hdr.return_code)
2098 return 0;
2099 /* return results to caller */
2100 card->options.vnicc.sup_chars = rep->hdr.sup;
2101 card->options.vnicc.cur_chars = rep->hdr.cur;
2102
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002103 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
2104 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
2105
Hans Wippel349d13d2017-09-18 21:18:16 +02002106 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
2107 *cbctl->result.timeout = rep->getset_timeout.timeout;
2108
Hans Wippela45b3fa2017-09-18 21:18:14 +02002109 return 0;
2110}
2111
2112/* generic VNICC request */
2113static int qeth_l2_vnicc_request(struct qeth_card *card,
2114 struct _qeth_l2_vnicc_request_cbctl *cbctl)
2115{
2116 struct qeth_ipacmd_vnicc *req;
2117 struct qeth_cmd_buffer *iob;
2118 struct qeth_ipa_cmd *cmd;
2119 int rc;
2120
2121 QETH_CARD_TEXT(card, 2, "vniccreq");
2122
2123 /* get new buffer for request */
2124 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
2125 if (!iob)
2126 return -ENOMEM;
2127
2128 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01002129 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02002130 req = &cmd->data.vnicc;
2131
2132 /* create sub command header for request */
2133 req->sub_hdr.data_length = sizeof(req->sub_hdr);
2134 req->sub_hdr.sub_command = cbctl->sub_cmd;
2135
2136 /* create sub command specific request fields */
2137 switch (cbctl->sub_cmd) {
2138 case IPA_VNICC_QUERY_CHARS:
2139 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002140 case IPA_VNICC_QUERY_CMDS:
2141 req->sub_hdr.data_length += sizeof(req->query_cmds);
2142 req->query_cmds.vnic_char = cbctl->param.vnic_char;
2143 break;
2144 case IPA_VNICC_ENABLE:
2145 case IPA_VNICC_DISABLE:
2146 req->sub_hdr.data_length += sizeof(req->set_char);
2147 req->set_char.vnic_char = cbctl->param.vnic_char;
2148 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02002149 case IPA_VNICC_SET_TIMEOUT:
2150 req->getset_timeout.timeout = cbctl->param.timeout;
2151 /* fallthrough */
2152 case IPA_VNICC_GET_TIMEOUT:
2153 req->sub_hdr.data_length += sizeof(req->getset_timeout);
2154 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
2155 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002156 default:
2157 qeth_release_buffer(iob->channel, iob);
2158 return -EOPNOTSUPP;
2159 }
2160
2161 /* send request */
2162 rc = qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb,
2163 (void *) cbctl);
2164
2165 return qeth_l2_vnicc_makerc(card, rc);
2166}
2167
2168/* VNICC query VNIC characteristics request */
2169static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
2170{
2171 struct _qeth_l2_vnicc_request_cbctl cbctl;
2172
2173 /* prepare callback control */
2174 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
2175
2176 QETH_CARD_TEXT(card, 2, "vniccqch");
2177 return qeth_l2_vnicc_request(card, &cbctl);
2178}
2179
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002180/* VNICC query sub commands request */
2181static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
2182 u32 *sup_cmds)
2183{
2184 struct _qeth_l2_vnicc_request_cbctl cbctl;
2185
2186 /* prepare callback control */
2187 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
2188 cbctl.param.vnic_char = vnic_char;
2189 cbctl.result.sup_cmds = sup_cmds;
2190
2191 QETH_CARD_TEXT(card, 2, "vniccqcm");
2192 return qeth_l2_vnicc_request(card, &cbctl);
2193}
2194
2195/* VNICC enable/disable characteristic request */
2196static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
2197 u32 cmd)
2198{
2199 struct _qeth_l2_vnicc_request_cbctl cbctl;
2200
2201 /* prepare callback control */
2202 cbctl.sub_cmd = cmd;
2203 cbctl.param.vnic_char = vnic_char;
2204
2205 QETH_CARD_TEXT(card, 2, "vniccedc");
2206 return qeth_l2_vnicc_request(card, &cbctl);
2207}
2208
Hans Wippel349d13d2017-09-18 21:18:16 +02002209/* VNICC get/set timeout for characteristic request */
2210static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
2211 u32 cmd, u32 *timeout)
2212{
2213 struct _qeth_l2_vnicc_request_cbctl cbctl;
2214
2215 /* prepare callback control */
2216 cbctl.sub_cmd = cmd;
2217 cbctl.param.vnic_char = vnicc;
2218 if (cmd == IPA_VNICC_SET_TIMEOUT)
2219 cbctl.param.timeout = *timeout;
2220 if (cmd == IPA_VNICC_GET_TIMEOUT)
2221 cbctl.result.timeout = timeout;
2222
2223 QETH_CARD_TEXT(card, 2, "vniccgst");
2224 return qeth_l2_vnicc_request(card, &cbctl);
2225}
2226
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002227/* set current VNICC flag state; called from sysfs store function */
2228int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
2229{
2230 int rc = 0;
2231 u32 cmd;
2232
2233 QETH_CARD_TEXT(card, 2, "vniccsch");
2234
2235 /* do not change anything if BridgePort is enabled */
2236 if (qeth_bridgeport_is_in_use(card))
2237 return -EBUSY;
2238
2239 /* check if characteristic and enable/disable are supported */
2240 if (!(card->options.vnicc.sup_chars & vnicc) ||
2241 !(card->options.vnicc.set_char_sup & vnicc))
2242 return -EOPNOTSUPP;
2243
2244 /* set enable/disable command and store wanted characteristic */
2245 if (state) {
2246 cmd = IPA_VNICC_ENABLE;
2247 card->options.vnicc.wanted_chars |= vnicc;
2248 } else {
2249 cmd = IPA_VNICC_DISABLE;
2250 card->options.vnicc.wanted_chars &= ~vnicc;
2251 }
2252
2253 /* do we need to do anything? */
2254 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
2255 return rc;
2256
2257 /* if card is not ready, simply stop here */
2258 if (!qeth_card_hw_is_reachable(card)) {
2259 if (state)
2260 card->options.vnicc.cur_chars |= vnicc;
2261 else
2262 card->options.vnicc.cur_chars &= ~vnicc;
2263 return rc;
2264 }
2265
2266 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
2267 if (rc)
2268 card->options.vnicc.wanted_chars =
2269 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02002270 else {
2271 /* successful online VNICC change; handle special cases */
2272 if (state && vnicc == QETH_VNICC_RX_BCAST)
2273 card->options.vnicc.rx_bcast_enabled = true;
2274 if (!state && vnicc == QETH_VNICC_LEARNING)
2275 qeth_l2_vnicc_recover_timeout(card, vnicc,
2276 &card->options.vnicc.learning_timeout);
2277 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002278
2279 return rc;
2280}
2281
2282/* get current VNICC flag state; called from sysfs show function */
2283int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
2284{
2285 int rc = 0;
2286
2287 QETH_CARD_TEXT(card, 2, "vniccgch");
2288
2289 /* do not get anything if BridgePort is enabled */
2290 if (qeth_bridgeport_is_in_use(card))
2291 return -EBUSY;
2292
2293 /* check if characteristic is supported */
2294 if (!(card->options.vnicc.sup_chars & vnicc))
2295 return -EOPNOTSUPP;
2296
2297 /* if card is ready, query current VNICC state */
2298 if (qeth_card_hw_is_reachable(card))
2299 rc = qeth_l2_vnicc_query_chars(card);
2300
2301 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
2302 return rc;
2303}
2304
Hans Wippel349d13d2017-09-18 21:18:16 +02002305/* set VNICC timeout; called from sysfs store function. Currently, only learning
2306 * supports timeout
2307 */
2308int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
2309{
2310 int rc = 0;
2311
2312 QETH_CARD_TEXT(card, 2, "vniccsto");
2313
2314 /* do not change anything if BridgePort is enabled */
2315 if (qeth_bridgeport_is_in_use(card))
2316 return -EBUSY;
2317
2318 /* check if characteristic and set_timeout are supported */
2319 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2320 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2321 return -EOPNOTSUPP;
2322
2323 /* do we need to do anything? */
2324 if (card->options.vnicc.learning_timeout == timeout)
2325 return rc;
2326
2327 /* if card is not ready, simply store the value internally and return */
2328 if (!qeth_card_hw_is_reachable(card)) {
2329 card->options.vnicc.learning_timeout = timeout;
2330 return rc;
2331 }
2332
2333 /* send timeout value to card; if successful, store value internally */
2334 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2335 IPA_VNICC_SET_TIMEOUT, &timeout);
2336 if (!rc)
2337 card->options.vnicc.learning_timeout = timeout;
2338
2339 return rc;
2340}
2341
2342/* get current VNICC timeout; called from sysfs show function. Currently, only
2343 * learning supports timeout
2344 */
2345int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2346{
2347 int rc = 0;
2348
2349 QETH_CARD_TEXT(card, 2, "vniccgto");
2350
2351 /* do not get anything if BridgePort is enabled */
2352 if (qeth_bridgeport_is_in_use(card))
2353 return -EBUSY;
2354
2355 /* check if characteristic and get_timeout are supported */
2356 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2357 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2358 return -EOPNOTSUPP;
2359 /* if card is ready, get timeout. Otherwise, just return stored value */
2360 *timeout = card->options.vnicc.learning_timeout;
2361 if (qeth_card_hw_is_reachable(card))
2362 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2363 IPA_VNICC_GET_TIMEOUT,
2364 timeout);
2365
2366 return rc;
2367}
2368
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002369/* check if VNICC is currently enabled */
2370bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2371{
2372 /* if everything is turned off, VNICC is not active */
2373 if (!card->options.vnicc.cur_chars)
2374 return false;
2375 /* default values are only OK if rx_bcast was not enabled by user
2376 * or the card is offline.
2377 */
2378 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2379 if (!card->options.vnicc.rx_bcast_enabled ||
2380 !qeth_card_hw_is_reachable(card))
2381 return false;
2382 }
2383 return true;
2384}
2385
Hans Wippel349d13d2017-09-18 21:18:16 +02002386/* recover user timeout setting */
2387static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2388 u32 *timeout)
2389{
2390 if (card->options.vnicc.sup_chars & vnicc &&
2391 card->options.vnicc.getset_timeout_sup & vnicc &&
2392 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2393 timeout))
2394 return false;
2395 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2396 return true;
2397}
2398
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002399/* recover user characteristic setting */
2400static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2401 bool enable)
2402{
2403 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2404
2405 if (card->options.vnicc.sup_chars & vnicc &&
2406 card->options.vnicc.set_char_sup & vnicc &&
2407 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2408 return false;
2409 card->options.vnicc.wanted_chars &= ~vnicc;
2410 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2411 return true;
2412}
2413
Hans Wippela45b3fa2017-09-18 21:18:14 +02002414/* (re-)initialize VNICC */
2415static void qeth_l2_vnicc_init(struct qeth_card *card)
2416{
Hans Wippel349d13d2017-09-18 21:18:16 +02002417 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002418 unsigned int chars_len, i;
2419 unsigned long chars_tmp;
2420 u32 sup_cmds, vnicc;
2421 bool enable, error;
2422
Hans Wippela45b3fa2017-09-18 21:18:14 +02002423 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002424 /* reset rx_bcast */
2425 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002426 /* initial query and storage of VNIC characteristics */
2427 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002428 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2429 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002430 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2431 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002432 card->options.vnicc.sup_chars = 0;
2433 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002434 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2435 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002436 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002437 /* get supported commands for each supported characteristic */
2438 chars_tmp = card->options.vnicc.sup_chars;
2439 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2440 for_each_set_bit(i, &chars_tmp, chars_len) {
2441 vnicc = BIT(i);
2442 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002443 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2444 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2445 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002446 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2447 !(sup_cmds & IPA_VNICC_DISABLE))
2448 card->options.vnicc.set_char_sup &= ~vnicc;
2449 }
2450 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002451 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2452 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002453 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2454 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2455 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2456 for_each_set_bit(i, &chars_tmp, chars_len) {
2457 vnicc = BIT(i);
2458 enable = card->options.vnicc.wanted_chars & vnicc;
2459 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2460 }
2461 if (error)
2462 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2463}
2464
2465/* configure default values of VNIC characteristics */
2466static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2467{
2468 /* characteristics values */
2469 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2470 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002471 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002472 /* supported commands */
2473 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002474 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002475 /* settings wanted by users */
2476 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002477}
2478
Frank Blaschka4a71df52008-02-15 09:19:42 +01002479module_init(qeth_l2_init);
2480module_exit(qeth_l2_exit);
2481MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2482MODULE_DESCRIPTION("qeth layer 2 discipline");
2483MODULE_LICENSE("GPL");