blob: 218801232ca2609671f12ce4a99ae1dfd04d315f [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 *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010028static void qeth_bridgeport_query_support(struct qeth_card *card);
29static void qeth_bridge_state_change(struct qeth_card *card,
30 struct qeth_ipa_cmd *cmd);
31static void qeth_bridge_host_event(struct qeth_card *card,
32 struct qeth_ipa_cmd *cmd);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +020033static void qeth_l2_vnicc_set_defaults(struct qeth_card *card);
Hans Wippela45b3fa2017-09-18 21:18:14 +020034static void qeth_l2_vnicc_init(struct qeth_card *card);
Hans Wippel349d13d2017-09-18 21:18:16 +020035static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
36 u32 *timeout);
Frank Blaschka4a71df52008-02-15 09:19:42 +010037
Julian Wiedmann742d4d42019-02-12 18:33:25 +010038static int qeth_l2_setdelmac_makerc(struct qeth_card *card, u16 retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010039{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010040 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010041
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010042 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010043 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010044 switch (retcode) {
45 case IPA_RC_SUCCESS:
46 rc = 0;
47 break;
48 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020049 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010050 break;
51 case IPA_RC_L2_ADDR_TABLE_FULL:
52 rc = -ENOSPC;
53 break;
54 case IPA_RC_L2_DUP_MAC:
55 case IPA_RC_L2_DUP_LAYER3_MAC:
56 rc = -EEXIST;
57 break;
58 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
59 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
60 rc = -EPERM;
61 break;
62 case IPA_RC_L2_MAC_NOT_FOUND:
63 rc = -ENOENT;
64 break;
65 default:
66 rc = -EIO;
67 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010068 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010069 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010070}
71
Julian Wiedmann742d4d42019-02-12 18:33:25 +010072static int qeth_l2_send_setdelmac_cb(struct qeth_card *card,
73 struct qeth_reply *reply,
74 unsigned long data)
75{
76 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
77
78 return qeth_l2_setdelmac_makerc(card, cmd->hdr.return_code);
79}
80
Julian Wiedmannac988d72017-01-12 15:48:41 +010081static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
82 enum qeth_ipa_cmds ipacmd)
83{
84 struct qeth_ipa_cmd *cmd;
85 struct qeth_cmd_buffer *iob;
86
87 QETH_CARD_TEXT(card, 2, "L2sdmac");
88 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
89 if (!iob)
90 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +010091 cmd = __ipa_cmd(iob);
Julian Wiedmann99f0b852017-12-20 20:11:01 +010092 cmd->data.setdelmac.mac_length = ETH_ALEN;
93 ether_addr_copy(cmd->data.setdelmac.mac, mac);
Julian Wiedmann742d4d42019-02-12 18:33:25 +010094 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelmac_cb, NULL);
Julian Wiedmannac988d72017-01-12 15:48:41 +010095}
96
97static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
98{
99 int rc;
100
101 QETH_CARD_TEXT(card, 2, "L2Setmac");
102 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
103 if (rc == 0) {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100104 dev_info(&card->gdev->dev,
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100105 "MAC address %pM successfully registered\n", mac);
Julian Wiedmannac988d72017-01-12 15:48:41 +0100106 } else {
Julian Wiedmannac988d72017-01-12 15:48:41 +0100107 switch (rc) {
108 case -EEXIST:
109 dev_warn(&card->gdev->dev,
110 "MAC address %pM already exists\n", mac);
111 break;
112 case -EPERM:
113 dev_warn(&card->gdev->dev,
114 "MAC address %pM is not authorized\n", mac);
115 break;
116 }
117 }
118 return rc;
119}
120
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100121static int qeth_l2_write_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100122{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200123 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100124 IPA_CMD_SETGMAC : IPA_CMD_SETVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100125 int rc;
126
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100127 QETH_CARD_TEXT(card, 2, "L2Wmac");
128 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100129 if (rc == -EEXIST)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100130 QETH_DBF_MESSAGE(2, "MAC already registered on device %x\n",
131 CARD_DEVID(card));
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100132 else if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100133 QETH_DBF_MESSAGE(2, "Failed to register MAC on device %x: %d\n",
134 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100135 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100136}
137
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100138static int qeth_l2_remove_mac(struct qeth_card *card, u8 *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100139{
Vasily Gorbik9d0a58f2018-06-29 19:45:52 +0200140 enum qeth_ipa_cmds cmd = is_multicast_ether_addr(mac) ?
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100141 IPA_CMD_DELGMAC : IPA_CMD_DELVMAC;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100142 int rc;
143
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100144 QETH_CARD_TEXT(card, 2, "L2Rmac");
145 rc = qeth_l2_send_setdelmac(card, mac, cmd);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100146 if (rc)
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100147 QETH_DBF_MESSAGE(2, "Failed to delete MAC on device %u: %d\n",
148 CARD_DEVID(card), rc);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100149 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100150}
151
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100152static void qeth_l2_drain_rx_mode_cache(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200153{
154 struct qeth_mac *mac;
155 struct hlist_node *tmp;
156 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100157
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200158 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200159 hash_del(&mac->hnode);
160 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100161 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100162}
163
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100164static void qeth_l2_fill_header(struct qeth_qdio_out_q *queue,
165 struct qeth_hdr *hdr, struct sk_buff *skb,
166 int ipv, int cast_type, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100167{
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200168 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100169
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200170 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200172 if (skb_is_gso(skb)) {
173 hdr->hdr.l2.id = QETH_HEADER_TYPE_L2_TSO;
174 } else {
175 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
176 if (skb->ip_summed == CHECKSUM_PARTIAL) {
177 qeth_tx_csum(skb, &hdr->hdr.l2.flags[1], ipv);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100178 QETH_TXQ_STAT_INC(queue, skbs_csum);
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200179 }
Julian Wiedmannfc696602018-09-17 17:35:55 +0200180 }
181
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182 /* set byte byte 3 to casting flags */
183 if (cast_type == RTN_MULTICAST)
184 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
185 else if (cast_type == RTN_BROADCAST)
186 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
187 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000188 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100189
Frank Blaschka4a71df52008-02-15 09:19:42 +0100190 /* VSWITCH relies on the VLAN
191 * information to be present in
192 * the QDIO header */
193 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
194 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
195 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
196 }
197}
198
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100199static int qeth_l2_setdelvlan_makerc(struct qeth_card *card, u16 retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200{
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200201 if (retcode)
202 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
203
204 switch (retcode) {
205 case IPA_RC_SUCCESS:
206 return 0;
207 case IPA_RC_L2_INVALID_VLAN_ID:
208 return -EINVAL;
209 case IPA_RC_L2_DUP_VLAN_ID:
210 return -EEXIST;
211 case IPA_RC_L2_VLAN_ID_NOT_FOUND:
212 return -ENOENT;
213 case IPA_RC_L2_VLAN_ID_NOT_ALLOWED:
214 return -EPERM;
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200215 default:
216 return -EIO;
217 }
218}
219
220static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
221 struct qeth_reply *reply,
222 unsigned long data)
223{
224 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100225
Carsten Otte847a50f2010-06-21 22:57:05 +0000226 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100227 if (cmd->hdr.return_code) {
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100228 QETH_DBF_MESSAGE(2, "Error in processing VLAN %u on device %x: %#x.\n",
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200229 cmd->data.setdelvlan.vlan_id,
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100230 CARD_DEVID(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000231 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100232 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100233 return qeth_l2_setdelvlan_makerc(card, cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100234}
235
236static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
Julian Wiedmann2aa48672017-09-18 21:18:20 +0200237 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100238{
239 struct qeth_ipa_cmd *cmd;
240 struct qeth_cmd_buffer *iob;
241
Carsten Otte847a50f2010-06-21 22:57:05 +0000242 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100243 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100244 if (!iob)
245 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100246 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100247 cmd->data.setdelvlan.vlan_id = i;
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100248 return qeth_send_ipa_cmd(card, iob, qeth_l2_send_setdelvlan_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100249}
250
Patrick McHardy80d5c362013-04-19 02:04:28 +0000251static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
252 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100253{
Heiko Carstens509e2562008-07-26 02:24:10 -0700254 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100255
Carsten Otte847a50f2010-06-21 22:57:05 +0000256 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000257 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500258 return 0;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100259
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100260 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100261}
262
Patrick McHardy80d5c362013-04-19 02:04:28 +0000263static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
264 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100265{
Heiko Carstens509e2562008-07-26 02:24:10 -0700266 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100267
Carsten Otte847a50f2010-06-21 22:57:05 +0000268 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100269 if (!vid)
270 return 0;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100271
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100272 return qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100273}
274
Julian Wiedmannd4560152019-02-28 18:59:39 +0100275static void qeth_l2_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200277 QETH_DBF_TEXT(SETUP , 2, "stopcard");
278 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279
280 qeth_set_allowed_threads(card, 0, 1);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +0100281
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100282 cancel_work_sync(&card->rx_mode_work);
283 qeth_l2_drain_rx_mode_cache(card);
284
Frank Blaschka4a71df52008-02-15 09:19:42 +0100285 if (card->state == CARD_STATE_SOFTSETUP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100286 qeth_clear_ipacmd_list(card);
287 card->state = CARD_STATE_HARDSETUP;
288 }
289 if (card->state == CARD_STATE_HARDSETUP) {
290 qeth_qdio_clear_card(card, 0);
Julian Wiedmann41c47da2019-04-17 18:17:28 +0200291 qeth_drain_output_queues(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100292 qeth_clear_working_pool_list(card);
293 card->state = CARD_STATE_DOWN;
294 }
295 if (card->state == CARD_STATE_DOWN) {
296 qeth_clear_cmd_buffers(&card->read);
297 qeth_clear_cmd_buffers(&card->write);
298 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +0100299
300 flush_workqueue(card->event_wq);
Julian Wiedmann7bd22752019-02-28 18:59:38 +0100301 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302}
303
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000304static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
305 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000307 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 struct sk_buff *skb;
309 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100310 unsigned int len;
311
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000312 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000313 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000314 while (budget) {
315 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000316 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000317 &card->rx.b_element, &card->rx.e_offset, &hdr);
318 if (!skb) {
319 *done = 1;
320 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100321 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322 switch (hdr->hdr.l2.id) {
323 case QETH_HEADER_TYPE_LAYER2:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100324 skb->protocol = eth_type_trans(skb, skb->dev);
Julian Wiedmann6195b932018-04-26 09:42:17 +0200325 qeth_rx_csum(card, skb, hdr->hdr.l2.flags[1]);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100326 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200327 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328 break;
329 case QETH_HEADER_TYPE_OSN:
Julian Wiedmann379ac992019-04-25 18:25:57 +0200330 if (IS_OSN(card)) {
Ursula Braun2d488c22008-10-24 11:16:55 +0200331 skb_push(skb, sizeof(struct qeth_hdr));
332 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100333 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200334 len = skb->len;
335 card->osn_info.data_cb(skb);
336 break;
337 }
338 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100339 default:
340 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000341 QETH_CARD_TEXT(card, 3, "inbunkno");
Julian Wiedmann0ac14872018-09-12 15:31:35 +0200342 QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 continue;
344 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000345 work_done++;
346 budget--;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100347 QETH_CARD_STAT_INC(card, rx_packets);
348 QETH_CARD_STAT_ADD(card, rx_bytes, len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100349 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000350 return work_done;
351}
352
Frank Blaschka4a71df52008-02-15 09:19:42 +0100353static int qeth_l2_request_initial_mac(struct qeth_card *card)
354{
355 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100356
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200357 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200358 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100359
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200360 if (MACHINE_IS_VM) {
361 rc = qeth_vm_request_mac(card);
362 if (!rc)
363 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100364 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %x: %#x\n",
365 CARD_DEVID(card), rc);
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200366 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
367 /* fall back to alternative mechanism: */
368 }
369
Julian Wiedmannb144b992018-11-08 15:06:15 +0100370 if (!IS_OSN(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100371 rc = qeth_setadpparms_change_macaddr(card);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100372 if (!rc)
Julian Wiedmann21b17022018-04-26 09:42:24 +0200373 goto out;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100374 QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
375 CARD_DEVID(card), rc);
Julian Wiedmann21b17022018-04-26 09:42:24 +0200376 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
377 /* fall back once more: */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378 }
Julian Wiedmann21b17022018-04-26 09:42:24 +0200379
380 /* some devices don't support a custom MAC address: */
Julian Wiedmann379ac992019-04-25 18:25:57 +0200381 if (IS_OSM(card) || IS_OSX(card))
Julian Wiedmann21b17022018-04-26 09:42:24 +0200382 return (rc) ? rc : -EADDRNOTAVAIL;
383 eth_hw_addr_random(card->dev);
384
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200385out:
386 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100387 return 0;
388}
389
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100390static void qeth_l2_register_dev_addr(struct qeth_card *card)
391{
392 if (!is_valid_ether_addr(card->dev->dev_addr))
393 qeth_l2_request_initial_mac(card);
394
395 if (!IS_OSN(card) && !qeth_l2_send_setmac(card, card->dev->dev_addr))
396 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
397}
398
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100399static int qeth_l2_validate_addr(struct net_device *dev)
400{
401 struct qeth_card *card = dev->ml_priv;
402
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100403 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100404 return eth_validate_addr(dev);
405
406 QETH_CARD_TEXT(card, 4, "nomacadr");
407 return -EPERM;
408}
409
Frank Blaschka4a71df52008-02-15 09:19:42 +0100410static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
411{
412 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700413 struct qeth_card *card = dev->ml_priv;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200414 u8 old_addr[ETH_ALEN];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100415 int rc = 0;
416
Carsten Otte847a50f2010-06-21 22:57:05 +0000417 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100419 if (IS_OSM(card) || IS_OSX(card)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000420 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100421 return -EOPNOTSUPP;
422 }
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100423 QETH_CARD_HEX(card, 3, addr->sa_data, ETH_ALEN);
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200424 if (!is_valid_ether_addr(addr->sa_data))
425 return -EADDRNOTAVAIL;
426
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200427 /* don't register the same address twice */
428 if (ether_addr_equal_64bits(dev->dev_addr, addr->sa_data) &&
429 (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100430 return 0;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200431
432 /* add the new address, switch over, drop the old */
433 rc = qeth_l2_send_setmac(card, addr->sa_data);
434 if (rc)
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100435 return rc;
Julian Wiedmannbcacfcb2018-04-19 12:52:09 +0200436 ether_addr_copy(old_addr, dev->dev_addr);
437 ether_addr_copy(dev->dev_addr, addr->sa_data);
438
439 if (card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED)
440 qeth_l2_remove_mac(card, old_addr);
441 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100442 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443}
444
Eugene Crosser0db587b2015-05-18 14:27:55 +0200445static void qeth_promisc_to_bridge(struct qeth_card *card)
446{
447 struct net_device *dev = card->dev;
448 enum qeth_ipa_promisc_modes promisc_mode;
449 int role;
450 int rc;
451
452 QETH_CARD_TEXT(card, 3, "pmisc2br");
453
454 if (!card->options.sbp.reflect_promisc)
455 return;
456 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
457 : SET_PROMISC_MODE_OFF;
458 if (promisc_mode == card->info.promisc_mode)
459 return;
460
461 if (promisc_mode == SET_PROMISC_MODE_ON) {
462 if (card->options.sbp.reflect_promisc_primary)
463 role = QETH_SBP_ROLE_PRIMARY;
464 else
465 role = QETH_SBP_ROLE_SECONDARY;
466 } else
467 role = QETH_SBP_ROLE_NONE;
468
469 rc = qeth_bridgeport_setrole(card, role);
470 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
471 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
472 if (!rc) {
473 card->options.sbp.role = role;
474 card->info.promisc_mode = promisc_mode;
475 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200476
477}
478/* New MAC address is added to the hash table and marked to be written on card
479 * only if there is not in the hash table storage already
480 *
481*/
Julian Wiedmann4641b022017-12-20 20:10:59 +0100482static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200483{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200484 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200485 struct qeth_mac *mac;
486
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200487 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100488 if (ether_addr_equal_64bits(ha->addr, mac->mac_addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200489 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200490 return;
491 }
492 }
493
494 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200495 if (!mac)
496 return;
497
Julian Wiedmann99f0b852017-12-20 20:11:01 +0100498 ether_addr_copy(mac->mac_addr, ha->addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200499 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200500
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200501 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200502}
503
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100504static void qeth_l2_rx_mode_work(struct work_struct *work)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505{
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100506 struct qeth_card *card = container_of(work, struct qeth_card,
507 rx_mode_work);
508 struct net_device *dev = card->dev;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000509 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200510 struct qeth_mac *mac;
511 struct hlist_node *tmp;
512 int i;
513 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100514
Carsten Otte847a50f2010-06-21 22:57:05 +0000515 QETH_CARD_TEXT(card, 3, "setmulti");
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200516
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100517 netif_addr_lock_bh(dev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000518 netdev_for_each_mc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100519 qeth_l2_add_mac(card, ha);
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800520 netdev_for_each_uc_addr(ha, dev)
Julian Wiedmann4641b022017-12-20 20:10:59 +0100521 qeth_l2_add_mac(card, ha);
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100522 netif_addr_unlock_bh(dev);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200523
524 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100525 switch (mac->disp_flag) {
526 case QETH_DISP_ADDR_DELETE:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100527 qeth_l2_remove_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200528 hash_del(&mac->hnode);
529 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100530 break;
531 case QETH_DISP_ADDR_ADD:
Julian Wiedmann8174aa82017-12-20 20:11:00 +0100532 rc = qeth_l2_write_mac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200533 if (rc) {
534 hash_del(&mac->hnode);
535 kfree(mac);
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100536 break;
537 }
538 /* fall through */
539 default:
540 /* for next call to set_rx_mode(): */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200541 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Julian Wiedmann00c163f2017-12-20 20:11:02 +0100542 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200543 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200544
Eugene Crosser0db587b2015-05-18 14:27:55 +0200545 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
546 qeth_setadp_promisc_mode(card);
547 else
548 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100549}
550
Julian Wiedmann72863842017-08-18 10:19:04 +0200551static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
552 struct qeth_qdio_out_q *queue)
553{
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200554 struct qeth_hdr *hdr = (struct qeth_hdr *)skb->data;
555 addr_t end = (addr_t)(skb->data + sizeof(*hdr));
556 addr_t start = (addr_t)skb->data;
557 unsigned int elements = 0;
558 unsigned int hd_len = 0;
559 int rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200560
561 if (skb->protocol == htons(ETH_P_IPV6))
562 return -EPROTONOSUPPORT;
563
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200564 if (qeth_get_elements_for_range(start, end) > 1) {
565 /* Misaligned HW header, move it to its own buffer element. */
566 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
567 if (!hdr)
568 return -ENOMEM;
569 hd_len = sizeof(*hdr);
570 skb_copy_from_linear_data(skb, (char *)hdr, hd_len);
571 elements++;
572 }
573
574 elements += qeth_count_elements(skb, hd_len);
Julian Wiedmann4e26c5f2019-04-25 18:25:59 +0200575 if (elements > queue->max_elements) {
Julian Wiedmann69d7ce82018-09-17 17:36:04 +0200576 rc = -E2BIG;
577 goto out;
578 }
579
580 rc = qeth_do_send_packet(card, queue, skb, hdr, hd_len, hd_len,
581 elements);
582out:
583 if (rc && hd_len)
584 kmem_cache_free(qeth_core_header_cache, hdr);
585 return rc;
Julian Wiedmann72863842017-08-18 10:19:04 +0200586}
587
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200588static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
589 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100590{
Heiko Carstens509e2562008-07-26 02:24:10 -0700591 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200592 u16 txq = skb_get_queue_mapping(skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200593 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100594 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200595 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100596
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200597 if (IS_IQD(card))
Julian Wiedmann54a50942019-04-17 18:17:35 +0200598 txq = qeth_iqd_translate_txq(dev, txq);
599 queue = card->qdio.out_qs[txq];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100600
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200601 if (IS_OSN(card))
Julian Wiedmann72863842017-08-18 10:19:04 +0200602 rc = qeth_l2_xmit_osn(card, skb, queue);
Julian Wiedmann5f89eca2018-07-19 12:43:58 +0200603 else
Julian Wiedmann73dc2da2019-04-17 18:17:33 +0200604 rc = qeth_xmit(card, skb, queue, qeth_get_ip_version(skb),
Julian Wiedmann58aa2492019-04-25 18:26:00 +0200605 qeth_get_ether_cast_type(skb),
606 qeth_l2_fill_header);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100607
Frank Blaschka4a71df52008-02-15 09:19:42 +0100608 if (!rc) {
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100609 QETH_TXQ_STAT_INC(queue, tx_packets);
610 QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes);
Julian Wiedmann72863842017-08-18 10:19:04 +0200611 return NETDEV_TX_OK;
Julian Wiedmann54a50942019-04-17 18:17:35 +0200612 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100613
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100614 QETH_TXQ_STAT_INC(queue, tx_dropped);
Julian Wiedmann104b4852019-03-18 16:40:56 +0100615 kfree_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100616 return NETDEV_TX_OK;
617}
618
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200619static u16 qeth_l2_select_queue(struct net_device *dev, struct sk_buff *skb,
620 struct net_device *sb_dev)
621{
Julian Wiedmann73dc2da2019-04-17 18:17:33 +0200622 struct qeth_card *card = dev->ml_priv;
623
624 if (IS_IQD(card))
625 return qeth_iqd_select_queue(dev, skb,
Julian Wiedmann58aa2492019-04-25 18:26:00 +0200626 qeth_get_ether_cast_type(skb),
Julian Wiedmann73dc2da2019-04-17 18:17:33 +0200627 sb_dev);
628 return qeth_get_priority_queue(card, skb);
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200629}
630
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200631static const struct device_type qeth_l2_devtype = {
632 .name = "qeth_layer2",
633 .groups = qeth_l2_attr_groups,
634};
635
Frank Blaschka4a71df52008-02-15 09:19:42 +0100636static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
637{
638 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200639 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640
Julian Wiedmann12b409d2019-03-18 16:40:54 +0100641 qeth_l2_vnicc_set_defaults(card);
642
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200643 if (gdev->dev.type == &qeth_generic_devtype) {
644 rc = qeth_l2_create_device_attributes(&gdev->dev);
645 if (rc)
646 return rc;
647 }
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100648
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200649 hash_init(card->mac_htable);
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100650 INIT_WORK(&card->rx_mode_work, qeth_l2_rx_mode_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651 return 0;
652}
653
654static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
655{
656 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
657
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200658 if (cgdev->dev.type == &qeth_generic_devtype)
659 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000660 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100661 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
662
Ursula Braun70919e22011-02-26 22:41:36 -0800663 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100664 qeth_l2_set_offline(cgdev);
Julian Wiedmannc2780c12019-02-04 17:40:08 +0100665
666 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +0100667 if (qeth_netdev_is_registered(card->dev))
668 unregister_netdev(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669}
670
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100671static void qeth_l2_set_rx_mode(struct net_device *dev)
672{
673 struct qeth_card *card = dev->ml_priv;
674
675 schedule_work(&card->rx_mode_work);
676}
677
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000678static const struct net_device_ops qeth_l2_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100679 .ndo_open = qeth_open,
680 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +0100681 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -0800682 .ndo_start_xmit = qeth_l2_hard_start_xmit,
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100683 .ndo_features_check = qeth_features_check,
Julian Wiedmann3a18d752019-04-17 18:17:32 +0200684 .ndo_select_queue = qeth_l2_select_queue,
Julian Wiedmanne22355e2019-01-25 15:44:18 +0100685 .ndo_validate_addr = qeth_l2_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200686 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200687 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800688 .ndo_set_mac_address = qeth_l2_set_mac_address,
Frank Blaschka8403b132009-01-08 10:50:55 -0800689 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
690 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
691 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200692 .ndo_fix_features = qeth_fix_features,
693 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800694};
695
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100696static const struct net_device_ops qeth_osn_netdev_ops = {
697 .ndo_open = qeth_open,
698 .ndo_stop = qeth_stop,
699 .ndo_get_stats64 = qeth_get_stats64,
700 .ndo_start_xmit = qeth_l2_hard_start_xmit,
701 .ndo_validate_addr = eth_validate_addr,
702 .ndo_tx_timeout = qeth_tx_timeout,
703};
704
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100705static int qeth_l2_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100706{
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200707 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100709 if (IS_OSN(card)) {
710 card->dev->netdev_ops = &qeth_osn_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200711 card->dev->flags |= IFF_NOARP;
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100712 goto add_napi;
713 }
714
715 card->dev->needed_headroom = sizeof(struct qeth_hdr);
716 card->dev->netdev_ops = &qeth_l2_netdev_ops;
717 card->dev->priv_flags |= IFF_UNICAST_FLT;
Julian Wiedmann9400c532017-10-18 17:40:20 +0200718
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100719 if (IS_OSM(card)) {
Julian Wiedmann9400c532017-10-18 17:40:20 +0200720 card->dev->features |= NETIF_F_VLAN_CHALLENGED;
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100721 } else {
722 if (!IS_VM_NIC(card))
723 card->dev->hw_features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann9400c532017-10-18 17:40:20 +0200724 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmann5fc692a2019-01-25 15:44:23 +0100725 }
Julian Wiedmann0f342942018-03-09 18:12:54 +0100726
Julian Wiedmann379ac992019-04-25 18:25:57 +0200727 if (IS_OSD(card) && !IS_VM_NIC(card)) {
Julian Wiedmann6d69b1f2017-12-01 10:14:50 +0100728 card->dev->features |= NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200729 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200730 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200731 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200732 card->dev->vlan_features |= NETIF_F_IP_CSUM;
733 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200734 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +0200735 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
736 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
737 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
738 }
Kittipon Meesompopd7e6ed92018-04-26 09:42:23 +0200739 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM) ||
740 qeth_is_supported6(card, IPA_INBOUND_CHECKSUM_V6)) {
741 card->dev->hw_features |= NETIF_F_RXCSUM;
742 card->dev->vlan_features |= NETIF_F_RXCSUM;
743 }
Julian Wiedmann0aef8392018-10-12 17:27:15 +0200744 if (qeth_is_supported(card, IPA_OUTBOUND_TSO)) {
745 card->dev->hw_features |= NETIF_F_TSO;
746 card->dev->vlan_features |= NETIF_F_TSO;
747 }
748 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
749 card->dev->hw_features |= NETIF_F_TSO6;
750 card->dev->vlan_features |= NETIF_F_TSO6;
751 }
752
753 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) {
754 card->dev->needed_headroom = sizeof(struct qeth_hdr_tso);
755 netif_set_gso_max_size(card->dev,
756 PAGE_SIZE * (QDIO_MAX_ELEMENTS_PER_BUFFER - 1));
757 }
Julian Wiedmann0d6f02d2017-08-18 10:19:10 +0200758
Julian Wiedmann8024cc92019-02-15 19:22:31 +0100759add_napi:
Julian Wiedmannd73ef322017-04-11 16:11:11 +0200760 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200761 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100762 if (!rc && carrier_ok)
763 netif_carrier_on(card->dev);
764
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200765 if (rc)
766 card->dev->netdev_ops = NULL;
767 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100768}
769
Thomas Richter4d7def22015-09-18 16:06:51 +0200770static int qeth_l2_start_ipassists(struct qeth_card *card)
771{
772 /* configure isolation level */
773 if (qeth_set_access_ctrl_online(card, 0))
774 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +0200775 return 0;
776}
777
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200778static void qeth_l2_trace_features(struct qeth_card *card)
779{
Hans Wippela45b3fa2017-09-18 21:18:14 +0200780 /* Set BridgePort features */
781 QETH_CARD_TEXT(card, 2, "featuSBP");
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200782 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
783 sizeof(card->options.sbp.supported_funcs));
Hans Wippela45b3fa2017-09-18 21:18:14 +0200784 /* VNIC Characteristics features */
785 QETH_CARD_TEXT(card, 2, "feaVNICC");
786 QETH_CARD_HEX(card, 2, &card->options.vnicc.sup_chars,
787 sizeof(card->options.vnicc.sup_chars));
Julian Wiedmann521c10e2017-06-06 14:33:45 +0200788}
789
Julian Wiedmannd4560152019-02-28 18:59:39 +0100790static int qeth_l2_set_online(struct ccwgroup_device *gdev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100791{
792 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100793 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100795 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100796
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000797 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000798 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200799 QETH_DBF_TEXT(SETUP, 2, "setonlin");
800 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100801
Julian Wiedmann9fae5c32018-11-02 19:04:11 +0100802 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100803 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100804 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000805 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100806 goto out_remove;
807 }
Julian Wiedmann654e3d42019-01-25 15:44:19 +0100808
Frank Blaschka1da74b12011-05-12 18:45:02 +0000809 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
810 if (card->info.hwtrap &&
811 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
812 card->info.hwtrap = 0;
813 } else
814 card->info.hwtrap = 0;
815
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +0100816 qeth_bridgeport_query_support(card);
817 if (card->options.sbp.supported_funcs)
818 dev_info(&card->gdev->dev,
819 "The device represents a Bridge Capable Port\n");
820
821 qeth_l2_register_dev_addr(card);
822
Hans Wippela45b3fa2017-09-18 21:18:14 +0200823 /* for the rx_bcast characteristic, init VNICC after setmac */
824 qeth_l2_vnicc_init(card);
825
826 qeth_trace_features(card);
827 qeth_l2_trace_features(card);
828
Eugene Crosserb4d72c02014-01-14 15:54:11 +0100829 qeth_l2_setup_bridgeport_attrs(card);
830
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831 card->state = CARD_STATE_HARDSETUP;
832 qeth_print_status_message(card);
833
834 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200835 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100836
Julian Wiedmann379ac992019-04-25 18:25:57 +0200837 if (IS_OSD(card) || IS_OSX(card)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200838 rc = qeth_l2_start_ipassists(card);
839 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +0000840 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +0000841 }
Ursula Braun5113fec2010-05-16 21:15:14 +0000842
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843 rc = qeth_init_qdio_queues(card);
844 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200845 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +0000846 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847 goto out_remove;
848 }
849 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850
851 qeth_set_allowed_threads(card, 0xffffffff, 0);
Julian Wiedmannd025da92018-06-29 19:45:54 +0200852
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100853 if (!qeth_netdev_is_registered(dev)) {
854 rc = qeth_l2_setup_netdev(card, carrier_ok);
855 if (rc)
856 goto out_remove;
857 } else {
858 rtnl_lock();
859 if (carrier_ok)
860 netif_carrier_on(dev);
861 else
862 netif_carrier_off(dev);
863
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100864 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100865 qeth_enable_hw_features(dev);
866
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100867 if (card->info.open_when_online) {
868 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +0100869 dev_open(dev, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870 }
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +0100871 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 }
873 /* let user_space know that device is online */
874 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000875 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000876 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +0000878
Frank Blaschka4a71df52008-02-15 09:19:42 +0100879out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +0100880 qeth_l2_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100881 ccw_device_set_offline(CARD_DDEV(card));
882 ccw_device_set_offline(CARD_WDEV(card));
883 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +0100884 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100885 card->state = CARD_STATE_DOWN;
886
Frank Blaschkac4949f02010-05-11 19:34:47 +0000887 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000888 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +0000889 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100890}
891
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
893 int recovery_mode)
894{
895 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
896 int rc = 0, rc2 = 0, rc3 = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100897
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000898 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000899 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200900 QETH_DBF_TEXT(SETUP, 3, "setoffl");
901 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902
Julian Wiedmannd7ef489f2019-02-28 18:59:37 +0100903 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
904 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
905 card->info.hwtrap = 1;
906 }
907
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100908 rtnl_lock();
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100909 card->info.open_when_online = card->dev->flags & IFF_UP;
Julian Wiedmannd4560152019-02-28 18:59:39 +0100910 dev_close(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100911 netif_device_detach(card->dev);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +0200912 netif_carrier_off(card->dev);
Julian Wiedmanne6e771b2019-01-25 15:44:22 +0100913 rtnl_unlock();
914
Julian Wiedmannd4560152019-02-28 18:59:39 +0100915 qeth_l2_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916 rc = ccw_device_set_offline(CARD_DDEV(card));
917 rc2 = ccw_device_set_offline(CARD_WDEV(card));
918 rc3 = ccw_device_set_offline(CARD_RDEV(card));
919 if (!rc)
920 rc = (rc2) ? rc2 : rc3;
921 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200922 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +0100923 qdio_free(CARD_DDEV(card));
Julian Wiedmannd7d543f2019-02-28 18:59:36 +0100924
Frank Blaschka4a71df52008-02-15 09:19:42 +0100925 /* let user_space know that device is offline */
926 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +0000927 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +0000928 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100929 return 0;
930}
931
932static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
933{
934 return __qeth_l2_set_offline(cgdev, 0);
935}
936
937static int qeth_l2_recover(void *ptr)
938{
939 struct qeth_card *card;
940 int rc = 0;
941
942 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +0000943 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
945 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +0000946 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100947 dev_warn(&card->gdev->dev,
948 "A recovery process has been started for the device\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100949 __qeth_l2_set_offline(card->gdev, 1);
Julian Wiedmannd4560152019-02-28 18:59:39 +0100950 rc = qeth_l2_set_online(card->gdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100952 dev_info(&card->gdev->dev,
953 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200954 else {
Julian Wiedmannbf42d402019-02-28 18:59:41 +0100955 ccwgroup_set_offline(card->gdev);
Stefan Raspl0f547612013-01-21 02:30:20 +0000956 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +0000957 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +0200958 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000959 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
960 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961 return 0;
962}
963
964static int __init qeth_l2_init(void)
965{
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100966 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100967 return 0;
968}
969
970static void __exit qeth_l2_exit(void)
971{
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100972 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973}
974
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +0200975static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
976{
977 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
978
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +0200979 qeth_set_allowed_threads(card, 0, 1);
980 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
981 if (gdev->state == CCWGROUP_OFFLINE)
982 return 0;
Julian Wiedmann62ca98d2019-02-28 18:59:43 +0100983
984 qeth_l2_set_offline(gdev);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +0200985 return 0;
986}
987
988static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
989{
990 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Julian Wiedmannd4560152019-02-28 18:59:39 +0100991 int rc;
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +0200992
Julian Wiedmannd4560152019-02-28 18:59:39 +0100993 rc = qeth_l2_set_online(gdev);
Julian Wiedmann6585ac42018-09-26 18:29:12 +0200994
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +0200995 qeth_set_allowed_threads(card, 0xffffffff, 0);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +0200996 if (rc)
997 dev_warn(&card->gdev->dev, "The qeth device driver "
998 "failed to recover an error on the device\n");
999 return rc;
1000}
1001
Eugene Crosserc044dc22014-01-29 09:23:48 +01001002/* Returns zero if the command is successfully "consumed" */
1003static int qeth_l2_control_event(struct qeth_card *card,
1004 struct qeth_ipa_cmd *cmd)
1005{
1006 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001007 case IPA_CMD_SETBRIDGEPORT_OSA:
1008 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001009 if (cmd->data.sbp.hdr.command_code ==
1010 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1011 qeth_bridge_state_change(card, cmd);
1012 return 0;
1013 } else
1014 return 1;
1015 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1016 qeth_bridge_host_event(card, cmd);
1017 return 0;
1018 default:
1019 return 1;
1020 }
1021}
1022
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001023struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001024 .devtype = &qeth_l2_devtype,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001025 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001026 .recover = qeth_l2_recover,
1027 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001028 .remove = qeth_l2_remove_device,
1029 .set_online = qeth_l2_set_online,
1030 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001031 .freeze = qeth_l2_pm_suspend,
1032 .thaw = qeth_l2_pm_resume,
1033 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001034 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001035 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001036};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001037EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038
1039static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1040 struct qeth_cmd_buffer *iob)
1041{
Julian Wiedmann750b1622018-08-09 14:47:59 +02001042 struct qeth_channel *channel = iob->channel;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 int rc = 0;
1044
Carsten Otte847a50f2010-06-21 22:57:05 +00001045 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001046
Julian Wiedmann782e4a72019-03-28 16:39:24 +01001047 wait_event(card->wait_q, qeth_trylock_channel(channel));
Julian Wiedmann48ce6f82019-03-28 16:39:27 +01001048 iob->finalize(card, iob, len);
1049 QETH_DBF_HEX(CTRL, 2, iob->data, min(len, QETH_DBF_CTRL_LEN));
Carsten Otte847a50f2010-06-21 22:57:05 +00001050 QETH_CARD_TEXT(card, 6, "osnoirqp");
Julian Wiedmanned471552018-09-17 17:36:08 +02001051 spin_lock_irq(get_ccwdev_lock(channel->ccwdev));
Julian Wiedmannf15cdaf2018-08-09 14:48:03 +02001052 rc = ccw_device_start_timeout(channel->ccwdev, channel->ccw,
Julian Wiedmann782e4a72019-03-28 16:39:24 +01001053 (addr_t) iob, 0, 0, iob->timeout);
Julian Wiedmanned471552018-09-17 17:36:08 +02001054 spin_unlock_irq(get_ccwdev_lock(channel->ccwdev));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001056 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001057 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001058 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Julian Wiedmann750b1622018-08-09 14:47:59 +02001059 qeth_release_buffer(channel, iob);
1060 atomic_set(&channel->irq_pending, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061 wake_up(&card->wait_q);
1062 }
1063 return rc;
1064}
1065
1066static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
Julian Wiedmannc2153272019-02-12 18:33:17 +01001067 struct qeth_cmd_buffer *iob)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001068{
Julian Wiedmannc2153272019-02-12 18:33:17 +01001069 u16 length;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001070
Carsten Otte847a50f2010-06-21 22:57:05 +00001071 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001072
Julian Wiedmannc2153272019-02-12 18:33:17 +01001073 memcpy(&length, QETH_IPA_PDU_LEN_TOTAL(iob->data), 2);
1074 return qeth_osn_send_control_data(card, length, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075}
1076
1077int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1078{
1079 struct qeth_cmd_buffer *iob;
1080 struct qeth_card *card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001081
Frank Blaschka4a71df52008-02-15 09:19:42 +01001082 if (!dev)
1083 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001084 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001085 if (!card)
1086 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001087 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001088 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001089 return -ENODEV;
1090 iob = qeth_wait_for_buffer(&card->write);
Julian Wiedmannc2153272019-02-12 18:33:17 +01001091 qeth_prepare_ipa_cmd(card, iob, (u16) data_len);
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001092 memcpy(__ipa_cmd(iob), data, data_len);
Julian Wiedmannc2153272019-02-12 18:33:17 +01001093 return qeth_osn_send_ipa_cmd(card, iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001094}
1095EXPORT_SYMBOL(qeth_osn_assist);
1096
1097int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1098 int (*assist_cb)(struct net_device *, void *),
1099 int (*data_cb)(struct sk_buff *))
1100{
1101 struct qeth_card *card;
Julian Wiedmannd7d18da2018-11-08 15:06:18 +01001102 char bus_id[16];
1103 u16 devno;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001104
Julian Wiedmannd7d18da2018-11-08 15:06:18 +01001105 memcpy(&devno, read_dev_no, 2);
1106 sprintf(bus_id, "0.0.%04x", devno);
1107 card = qeth_get_card_by_busid(bus_id);
1108 if (!card || !IS_OSN(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001109 return -ENODEV;
Julian Wiedmannd7d18da2018-11-08 15:06:18 +01001110 *dev = card->dev;
1111
Carsten Otte847a50f2010-06-21 22:57:05 +00001112 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113 if ((assist_cb == NULL) || (data_cb == NULL))
1114 return -EINVAL;
1115 card->osn_info.assist_cb = assist_cb;
1116 card->osn_info.data_cb = data_cb;
1117 return 0;
1118}
1119EXPORT_SYMBOL(qeth_osn_register);
1120
1121void qeth_osn_deregister(struct net_device *dev)
1122{
1123 struct qeth_card *card;
1124
Frank Blaschka4a71df52008-02-15 09:19:42 +01001125 if (!dev)
1126 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001127 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001128 if (!card)
1129 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001130 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001131 card->osn_info.assist_cb = NULL;
1132 card->osn_info.data_cb = NULL;
1133 return;
1134}
1135EXPORT_SYMBOL(qeth_osn_deregister);
1136
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001137/* SETBRIDGEPORT support, async notifications */
1138
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001139enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1140
1141/**
1142 * qeth_bridge_emit_host_event() - bridgeport address change notification
1143 * @card: qeth_card structure pointer, for udev events.
1144 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1145 * and reset token and addr_lnid are unused and may be NULL.
1146 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1147 * object, 0 - addition of an object.
1148 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1149 * @token: "network token" structure identifying physical address of the port.
1150 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1151 *
1152 * This function is called when registrations and deregistrations are
1153 * reported by the hardware, and also when notifications are enabled -
1154 * for all currently registered addresses.
1155 */
1156static void qeth_bridge_emit_host_event(struct qeth_card *card,
1157 enum qeth_an_event_type evtype,
1158 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1159{
1160 char str[7][32];
1161 char *env[8];
1162 int i = 0;
1163
1164 switch (evtype) {
1165 case anev_reg_unreg:
1166 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1167 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1168 ? "deregister" : "register");
1169 env[i] = str[i]; i++;
1170 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1171 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1172 addr_lnid->lnid);
1173 env[i] = str[i]; i++;
1174 }
1175 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001176 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001177 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001178 env[i] = str[i]; i++;
1179 }
1180 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1181 token->cssid, token->ssid, token->devnum);
1182 env[i] = str[i]; i++;
1183 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1184 env[i] = str[i]; i++;
1185 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1186 token->chpid);
1187 env[i] = str[i]; i++;
1188 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1189 env[i] = str[i]; i++;
1190 break;
1191 case anev_abort:
1192 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1193 env[i] = str[i]; i++;
1194 break;
1195 case anev_reset:
1196 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1197 env[i] = str[i]; i++;
1198 break;
1199 }
1200 env[i] = NULL;
1201 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1202}
1203
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001204struct qeth_bridge_state_data {
1205 struct work_struct worker;
1206 struct qeth_card *card;
1207 struct qeth_sbp_state_change qports;
1208};
1209
1210static void qeth_bridge_state_change_worker(struct work_struct *work)
1211{
1212 struct qeth_bridge_state_data *data =
1213 container_of(work, struct qeth_bridge_state_data, worker);
1214 /* We are only interested in the first entry - local port */
1215 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1216 char env_locrem[32];
1217 char env_role[32];
1218 char env_state[32];
1219 char *env[] = {
1220 env_locrem,
1221 env_role,
1222 env_state,
1223 NULL
1224 };
1225
1226 /* Role should not change by itself, but if it did, */
1227 /* information from the hardware is authoritative. */
1228 mutex_lock(&data->card->conf_mutex);
1229 data->card->options.sbp.role = entry->role;
1230 mutex_unlock(&data->card->conf_mutex);
1231
1232 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1233 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1234 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1235 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1236 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1237 "<INVALID>");
1238 snprintf(env_state, sizeof(env_state), "STATE=%s",
1239 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1240 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1241 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1242 "<INVALID>");
1243 kobject_uevent_env(&data->card->gdev->dev.kobj,
1244 KOBJ_CHANGE, env);
1245 kfree(data);
1246}
1247
Eugene Crosserc044dc22014-01-29 09:23:48 +01001248static void qeth_bridge_state_change(struct qeth_card *card,
1249 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001250{
1251 struct qeth_sbp_state_change *qports =
1252 &cmd->data.sbp.data.state_change;
1253 struct qeth_bridge_state_data *data;
1254 int extrasize;
1255
1256 QETH_CARD_TEXT(card, 2, "brstchng");
1257 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001258 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001259 return;
1260 }
1261 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1262 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1263 GFP_ATOMIC);
1264 if (!data) {
1265 QETH_CARD_TEXT(card, 2, "BPSalloc");
1266 return;
1267 }
1268 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1269 data->card = card;
1270 memcpy(&data->qports, qports,
1271 sizeof(struct qeth_sbp_state_change) + extrasize);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001272 queue_work(card->event_wq, &data->worker);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001273}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001274
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001275struct qeth_bridge_host_data {
1276 struct work_struct worker;
1277 struct qeth_card *card;
1278 struct qeth_ipacmd_addr_change hostevs;
1279};
1280
1281static void qeth_bridge_host_event_worker(struct work_struct *work)
1282{
1283 struct qeth_bridge_host_data *data =
1284 container_of(work, struct qeth_bridge_host_data, worker);
1285 int i;
1286
1287 if (data->hostevs.lost_event_mask) {
1288 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001289"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001290 data->card->dev->name,
1291 (data->hostevs.lost_event_mask == 0x01)
1292 ? "Overflow"
1293 : (data->hostevs.lost_event_mask == 0x02)
1294 ? "Bridge port state change"
1295 : "Unknown reason");
1296 mutex_lock(&data->card->conf_mutex);
1297 data->card->options.sbp.hostnotification = 0;
1298 mutex_unlock(&data->card->conf_mutex);
1299 qeth_bridge_emit_host_event(data->card, anev_abort,
1300 0, NULL, NULL);
1301 } else
1302 for (i = 0; i < data->hostevs.num_entries; i++) {
1303 struct qeth_ipacmd_addr_change_entry *entry =
1304 &data->hostevs.entry[i];
1305 qeth_bridge_emit_host_event(data->card,
1306 anev_reg_unreg,
1307 entry->change_code,
1308 &entry->token, &entry->addr_lnid);
1309 }
1310 kfree(data);
1311}
1312
Eugene Crosserc044dc22014-01-29 09:23:48 +01001313static void qeth_bridge_host_event(struct qeth_card *card,
1314 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001315{
1316 struct qeth_ipacmd_addr_change *hostevs =
1317 &cmd->data.addrchange;
1318 struct qeth_bridge_host_data *data;
1319 int extrasize;
1320
1321 QETH_CARD_TEXT(card, 2, "brhostev");
1322 if (cmd->hdr.return_code != 0x0000) {
1323 if (cmd->hdr.return_code == 0x0010) {
1324 if (hostevs->lost_event_mask == 0x00)
1325 hostevs->lost_event_mask = 0xff;
1326 } else {
1327 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1328 cmd->hdr.return_code);
1329 return;
1330 }
1331 }
1332 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1333 hostevs->num_entries;
1334 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1335 GFP_ATOMIC);
1336 if (!data) {
1337 QETH_CARD_TEXT(card, 2, "BPHalloc");
1338 return;
1339 }
1340 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1341 data->card = card;
1342 memcpy(&data->hostevs, hostevs,
1343 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001344 queue_work(card->event_wq, &data->worker);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001345}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001346
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001347/* SETBRIDGEPORT support; sending commands */
1348
1349struct _qeth_sbp_cbctl {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001350 union {
1351 u32 supported;
1352 struct {
1353 enum qeth_sbp_roles *role;
1354 enum qeth_sbp_states *state;
1355 } qports;
1356 } data;
1357};
1358
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001359static int qeth_bridgeport_makerc(struct qeth_card *card,
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001360 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001361{
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001362 struct qeth_ipacmd_setbridgeport *sbp = &cmd->data.sbp;
1363 enum qeth_ipa_sbp_cmd setcmd = sbp->hdr.command_code;
1364 u16 ipa_rc = cmd->hdr.return_code;
1365 u16 sbp_rc = sbp->hdr.return_code;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001366 int rc;
1367
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001368 if (ipa_rc == IPA_RC_SUCCESS && sbp_rc == IPA_RC_SUCCESS)
1369 return 0;
1370
1371 if ((IS_IQD(card) && ipa_rc == IPA_RC_SUCCESS) ||
1372 (!IS_IQD(card) && ipa_rc == sbp_rc)) {
1373 switch (sbp_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001374 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001375 rc = 0;
1376 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001377 case IPA_RC_L2_UNSUPPORTED_CMD:
1378 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001379 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001380 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001381 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1382 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001383 rc = -ENODEV; /* maybe not the best code here? */
1384 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001385 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001386 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001387 case IPA_RC_SBP_OSA_OS_MISMATCH:
1388 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001389 rc = -EPERM;
1390 dev_err(&card->gdev->dev,
1391 "A Bridge Port is already configured by a different operating system\n");
1392 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001393 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1394 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001395 switch (setcmd) {
1396 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1397 rc = -EEXIST;
1398 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001399 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001400 break;
1401 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1402 rc = -EBUSY;
1403 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001404 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001405 break;
1406 default:
1407 rc = -EIO;
1408 }
1409 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001410 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1411 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001412 rc = -EBUSY;
1413 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001414 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001415 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001416 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1417 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001418 rc = -EEXIST;
1419 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001420 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001421 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001422 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1423 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001424 rc = -EBUSY;
1425 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001426 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001427 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001428 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1429 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001430 rc = -EACCES;
1431 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001432 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001433 break;
1434 default:
1435 rc = -EIO;
1436 }
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001437 } else {
1438 switch (ipa_rc) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001439 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001440 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001441 break;
1442 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001443 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001444 break;
1445 default:
1446 rc = -EIO;
1447 }
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001448 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001449
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001450 if (rc) {
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001451 QETH_CARD_TEXT_(card, 2, "SBPi%04x", ipa_rc);
1452 QETH_CARD_TEXT_(card, 2, "SBPc%04x", sbp_rc);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001453 }
1454 return rc;
1455}
1456
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001457static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1458 enum qeth_ipa_sbp_cmd sbp_cmd,
1459 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001460{
Julian Wiedmann379ac992019-04-25 18:25:57 +02001461 enum qeth_ipa_cmds ipa_cmd = IS_IQD(card) ? IPA_CMD_SETBRIDGEPORT_IQD :
1462 IPA_CMD_SETBRIDGEPORT_OSA;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001463 struct qeth_cmd_buffer *iob;
1464 struct qeth_ipa_cmd *cmd;
1465
1466 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1467 if (!iob)
1468 return iob;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001469 cmd = __ipa_cmd(iob);
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001470 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1471 cmd_length;
1472 cmd->data.sbp.hdr.command_code = sbp_cmd;
1473 cmd->data.sbp.hdr.used_total = 1;
1474 cmd->data.sbp.hdr.seq_no = 1;
1475 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001476}
1477
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001478static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1479 struct qeth_reply *reply, unsigned long data)
1480{
1481 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1482 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001483 int rc;
1484
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001485 QETH_CARD_TEXT(card, 2, "brqsupcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001486 rc = qeth_bridgeport_makerc(card, cmd);
1487 if (rc)
1488 return rc;
1489
1490 cbctl->data.supported =
1491 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001492 return 0;
1493}
1494
1495/**
1496 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1497 * @card: qeth_card structure pointer.
1498 *
1499 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1500 * strucutre: card->options.sbp.supported_funcs.
1501 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001502static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001503{
1504 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001505 struct _qeth_sbp_cbctl cbctl;
1506
1507 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001508 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1509 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001510 if (!iob)
1511 return;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001512
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001513 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001514 &cbctl)) {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001515 card->options.sbp.role = QETH_SBP_ROLE_NONE;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001516 card->options.sbp.supported_funcs = 0;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001517 return;
1518 }
1519 card->options.sbp.supported_funcs = cbctl.data.supported;
1520}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001521
1522static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1523 struct qeth_reply *reply, unsigned long data)
1524{
1525 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1526 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1527 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001528 int rc;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001529
1530 QETH_CARD_TEXT(card, 2, "brqprtcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001531 rc = qeth_bridgeport_makerc(card, cmd);
1532 if (rc)
1533 return rc;
1534
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001535 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001536 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001537 return -EINVAL;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001538 }
1539 /* first entry contains the state of the local port */
1540 if (qports->num_entries > 0) {
1541 if (cbctl->data.qports.role)
1542 *cbctl->data.qports.role = qports->entry[0].role;
1543 if (cbctl->data.qports.state)
1544 *cbctl->data.qports.state = qports->entry[0].state;
1545 }
1546 return 0;
1547}
1548
1549/**
1550 * qeth_bridgeport_query_ports() - query local bridgeport status.
1551 * @card: qeth_card structure pointer.
1552 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1553 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1554 *
1555 * Returns negative errno-compatible error indication or 0 on success.
1556 *
1557 * 'role' and 'state' are not updated in case of hardware operation failure.
1558 */
1559int qeth_bridgeport_query_ports(struct qeth_card *card,
1560 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1561{
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001562 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001563 struct _qeth_sbp_cbctl cbctl = {
1564 .data = {
1565 .qports = {
1566 .role = role,
1567 .state = state,
1568 },
1569 },
1570 };
1571
1572 QETH_CARD_TEXT(card, 2, "brqports");
1573 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1574 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001575 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001576 if (!iob)
1577 return -ENOMEM;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001578
1579 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1580 &cbctl);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001581}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001582
1583static int qeth_bridgeport_set_cb(struct qeth_card *card,
1584 struct qeth_reply *reply, unsigned long data)
1585{
1586 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001587
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001588 QETH_CARD_TEXT(card, 2, "brsetrcb");
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001589 return qeth_bridgeport_makerc(card, cmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001590}
1591
1592/**
1593 * qeth_bridgeport_setrole() - Assign primary role to the port.
1594 * @card: qeth_card structure pointer.
1595 * @role: Role to assign.
1596 *
1597 * Returns negative errno-compatible error indication or 0 on success.
1598 */
1599int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1600{
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001601 int cmdlength;
1602 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001603 enum qeth_ipa_sbp_cmd setcmd;
1604
1605 QETH_CARD_TEXT(card, 2, "brsetrol");
1606 switch (role) {
1607 case QETH_SBP_ROLE_NONE:
1608 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001609 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001610 break;
1611 case QETH_SBP_ROLE_PRIMARY:
1612 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001613 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001614 break;
1615 case QETH_SBP_ROLE_SECONDARY:
1616 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001617 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001618 break;
1619 default:
1620 return -EINVAL;
1621 }
1622 if (!(card->options.sbp.supported_funcs & setcmd))
1623 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001624 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001625 if (!iob)
1626 return -ENOMEM;
Julian Wiedmann1709ff82019-02-12 18:33:24 +01001627
1628 return qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb, NULL);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001629}
1630
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001631/**
1632 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1633 * @card: qeth_card structure pointer, for debug messages.
1634 *
1635 * Returns negative errno-compatible error indication or 0 on success.
1636 */
1637static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1638{
1639 int rc;
1640
1641 if (pnso_rc == 0)
1642 switch (response) {
1643 case 0x0001:
1644 rc = 0;
1645 break;
1646 case 0x0004:
1647 case 0x0100:
1648 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001649 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001650 dev_err(&card->gdev->dev,
1651 "Setting address notification failed\n");
1652 break;
1653 case 0x0107:
1654 rc = -EAGAIN;
1655 break;
1656 default:
1657 rc = -EIO;
1658 }
1659 else
1660 rc = -EIO;
1661
1662 if (rc) {
1663 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1664 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1665 }
1666 return rc;
1667}
1668
1669static void qeth_bridgeport_an_set_cb(void *priv,
1670 enum qdio_brinfo_entry_type type, void *entry)
1671{
1672 struct qeth_card *card = (struct qeth_card *)priv;
1673 struct qdio_brinfo_entry_l2 *l2entry;
1674 u8 code;
1675
1676 if (type != l2_addr_lnid) {
1677 WARN_ON_ONCE(1);
1678 return;
1679 }
1680
1681 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1682 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1683 if (l2entry->addr_lnid.lnid)
1684 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1685 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1686 (struct net_if_token *)&l2entry->nit,
1687 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1688}
1689
1690/**
1691 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1692 * @card: qeth_card structure pointer.
1693 * @enable: 0 - disable, non-zero - enable notifications
1694 *
1695 * Returns negative errno-compatible error indication or 0 on success.
1696 *
1697 * On enable, emits a series of address notifications udev events for all
1698 * currently registered hosts.
1699 */
1700int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
1701{
1702 int rc;
1703 u16 response;
1704 struct ccw_device *ddev;
1705 struct subchannel_id schid;
1706
1707 if (!card)
1708 return -EINVAL;
1709 if (!card->options.sbp.supported_funcs)
1710 return -EOPNOTSUPP;
1711 ddev = CARD_DDEV(card);
1712 ccw_device_get_schid(ddev, &schid);
1713
1714 if (enable) {
1715 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
1716 rc = qdio_pnso_brinfo(schid, 1, &response,
1717 qeth_bridgeport_an_set_cb, card);
1718 } else
1719 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
1720 return qeth_anset_makerc(card, rc, response);
1721}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001722
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001723static bool qeth_bridgeport_is_in_use(struct qeth_card *card)
1724{
1725 return (card->options.sbp.role || card->options.sbp.reflect_promisc ||
1726 card->options.sbp.hostnotification);
1727}
1728
Hans Wippela45b3fa2017-09-18 21:18:14 +02001729/* VNIC Characteristics support */
1730
1731/* handle VNICC IPA command return codes; convert to error codes */
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001732static int qeth_l2_vnicc_makerc(struct qeth_card *card, u16 ipa_rc)
Hans Wippela45b3fa2017-09-18 21:18:14 +02001733{
1734 int rc;
1735
1736 switch (ipa_rc) {
1737 case IPA_RC_SUCCESS:
1738 return ipa_rc;
1739 case IPA_RC_L2_UNSUPPORTED_CMD:
1740 case IPA_RC_NOTSUPP:
1741 rc = -EOPNOTSUPP;
1742 break;
1743 case IPA_RC_VNICC_OOSEQ:
1744 rc = -EALREADY;
1745 break;
1746 case IPA_RC_VNICC_VNICBP:
1747 rc = -EBUSY;
1748 break;
1749 case IPA_RC_L2_ADDR_TABLE_FULL:
1750 rc = -ENOSPC;
1751 break;
1752 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
1753 rc = -EACCES;
1754 break;
1755 default:
1756 rc = -EIO;
1757 }
1758
1759 QETH_CARD_TEXT_(card, 2, "err%04x", ipa_rc);
1760 return rc;
1761}
1762
1763/* generic VNICC request call back control */
1764struct _qeth_l2_vnicc_request_cbctl {
1765 u32 sub_cmd;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001766 struct {
1767 u32 vnic_char;
Hans Wippel349d13d2017-09-18 21:18:16 +02001768 u32 timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001769 } param;
1770 struct {
Hans Wippel349d13d2017-09-18 21:18:16 +02001771 union{
1772 u32 *sup_cmds;
1773 u32 *timeout;
1774 };
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001775 } result;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001776};
1777
1778/* generic VNICC request call back */
1779static int qeth_l2_vnicc_request_cb(struct qeth_card *card,
1780 struct qeth_reply *reply,
1781 unsigned long data)
1782{
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001783 struct _qeth_l2_vnicc_request_cbctl *cbctl =
1784 (struct _qeth_l2_vnicc_request_cbctl *) reply->param;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001785 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1786 struct qeth_ipacmd_vnicc *rep = &cmd->data.vnicc;
1787
1788 QETH_CARD_TEXT(card, 2, "vniccrcb");
1789 if (cmd->hdr.return_code)
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001790 return qeth_l2_vnicc_makerc(card, cmd->hdr.return_code);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001791 /* return results to caller */
1792 card->options.vnicc.sup_chars = rep->hdr.sup;
1793 card->options.vnicc.cur_chars = rep->hdr.cur;
1794
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001795 if (cbctl->sub_cmd == IPA_VNICC_QUERY_CMDS)
1796 *cbctl->result.sup_cmds = rep->query_cmds.sup_cmds;
1797
Hans Wippel349d13d2017-09-18 21:18:16 +02001798 if (cbctl->sub_cmd == IPA_VNICC_GET_TIMEOUT)
1799 *cbctl->result.timeout = rep->getset_timeout.timeout;
1800
Hans Wippela45b3fa2017-09-18 21:18:14 +02001801 return 0;
1802}
1803
1804/* generic VNICC request */
1805static int qeth_l2_vnicc_request(struct qeth_card *card,
1806 struct _qeth_l2_vnicc_request_cbctl *cbctl)
1807{
1808 struct qeth_ipacmd_vnicc *req;
1809 struct qeth_cmd_buffer *iob;
1810 struct qeth_ipa_cmd *cmd;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001811
1812 QETH_CARD_TEXT(card, 2, "vniccreq");
1813
1814 /* get new buffer for request */
1815 iob = qeth_get_ipacmd_buffer(card, IPA_CMD_VNICC, 0);
1816 if (!iob)
1817 return -ENOMEM;
1818
1819 /* create header for request */
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001820 cmd = __ipa_cmd(iob);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001821 req = &cmd->data.vnicc;
1822
1823 /* create sub command header for request */
1824 req->sub_hdr.data_length = sizeof(req->sub_hdr);
1825 req->sub_hdr.sub_command = cbctl->sub_cmd;
1826
1827 /* create sub command specific request fields */
1828 switch (cbctl->sub_cmd) {
1829 case IPA_VNICC_QUERY_CHARS:
1830 break;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001831 case IPA_VNICC_QUERY_CMDS:
1832 req->sub_hdr.data_length += sizeof(req->query_cmds);
1833 req->query_cmds.vnic_char = cbctl->param.vnic_char;
1834 break;
1835 case IPA_VNICC_ENABLE:
1836 case IPA_VNICC_DISABLE:
1837 req->sub_hdr.data_length += sizeof(req->set_char);
1838 req->set_char.vnic_char = cbctl->param.vnic_char;
1839 break;
Hans Wippel349d13d2017-09-18 21:18:16 +02001840 case IPA_VNICC_SET_TIMEOUT:
1841 req->getset_timeout.timeout = cbctl->param.timeout;
1842 /* fallthrough */
1843 case IPA_VNICC_GET_TIMEOUT:
1844 req->sub_hdr.data_length += sizeof(req->getset_timeout);
1845 req->getset_timeout.vnic_char = cbctl->param.vnic_char;
1846 break;
Hans Wippela45b3fa2017-09-18 21:18:14 +02001847 default:
1848 qeth_release_buffer(iob->channel, iob);
1849 return -EOPNOTSUPP;
1850 }
1851
1852 /* send request */
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001853 return qeth_send_ipa_cmd(card, iob, qeth_l2_vnicc_request_cb, cbctl);
Hans Wippela45b3fa2017-09-18 21:18:14 +02001854}
1855
1856/* VNICC query VNIC characteristics request */
1857static int qeth_l2_vnicc_query_chars(struct qeth_card *card)
1858{
1859 struct _qeth_l2_vnicc_request_cbctl cbctl;
1860
1861 /* prepare callback control */
1862 cbctl.sub_cmd = IPA_VNICC_QUERY_CHARS;
1863
1864 QETH_CARD_TEXT(card, 2, "vniccqch");
1865 return qeth_l2_vnicc_request(card, &cbctl);
1866}
1867
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001868/* VNICC query sub commands request */
1869static int qeth_l2_vnicc_query_cmds(struct qeth_card *card, u32 vnic_char,
1870 u32 *sup_cmds)
1871{
1872 struct _qeth_l2_vnicc_request_cbctl cbctl;
1873
1874 /* prepare callback control */
1875 cbctl.sub_cmd = IPA_VNICC_QUERY_CMDS;
1876 cbctl.param.vnic_char = vnic_char;
1877 cbctl.result.sup_cmds = sup_cmds;
1878
1879 QETH_CARD_TEXT(card, 2, "vniccqcm");
1880 return qeth_l2_vnicc_request(card, &cbctl);
1881}
1882
1883/* VNICC enable/disable characteristic request */
1884static int qeth_l2_vnicc_set_char(struct qeth_card *card, u32 vnic_char,
1885 u32 cmd)
1886{
1887 struct _qeth_l2_vnicc_request_cbctl cbctl;
1888
1889 /* prepare callback control */
1890 cbctl.sub_cmd = cmd;
1891 cbctl.param.vnic_char = vnic_char;
1892
1893 QETH_CARD_TEXT(card, 2, "vniccedc");
1894 return qeth_l2_vnicc_request(card, &cbctl);
1895}
1896
Hans Wippel349d13d2017-09-18 21:18:16 +02001897/* VNICC get/set timeout for characteristic request */
1898static int qeth_l2_vnicc_getset_timeout(struct qeth_card *card, u32 vnicc,
1899 u32 cmd, u32 *timeout)
1900{
1901 struct _qeth_l2_vnicc_request_cbctl cbctl;
1902
1903 /* prepare callback control */
1904 cbctl.sub_cmd = cmd;
1905 cbctl.param.vnic_char = vnicc;
1906 if (cmd == IPA_VNICC_SET_TIMEOUT)
1907 cbctl.param.timeout = *timeout;
1908 if (cmd == IPA_VNICC_GET_TIMEOUT)
1909 cbctl.result.timeout = timeout;
1910
1911 QETH_CARD_TEXT(card, 2, "vniccgst");
1912 return qeth_l2_vnicc_request(card, &cbctl);
1913}
1914
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001915/* set current VNICC flag state; called from sysfs store function */
1916int qeth_l2_vnicc_set_state(struct qeth_card *card, u32 vnicc, bool state)
1917{
1918 int rc = 0;
1919 u32 cmd;
1920
1921 QETH_CARD_TEXT(card, 2, "vniccsch");
1922
1923 /* do not change anything if BridgePort is enabled */
1924 if (qeth_bridgeport_is_in_use(card))
1925 return -EBUSY;
1926
1927 /* check if characteristic and enable/disable are supported */
1928 if (!(card->options.vnicc.sup_chars & vnicc) ||
1929 !(card->options.vnicc.set_char_sup & vnicc))
1930 return -EOPNOTSUPP;
1931
1932 /* set enable/disable command and store wanted characteristic */
1933 if (state) {
1934 cmd = IPA_VNICC_ENABLE;
1935 card->options.vnicc.wanted_chars |= vnicc;
1936 } else {
1937 cmd = IPA_VNICC_DISABLE;
1938 card->options.vnicc.wanted_chars &= ~vnicc;
1939 }
1940
1941 /* do we need to do anything? */
1942 if (card->options.vnicc.cur_chars == card->options.vnicc.wanted_chars)
1943 return rc;
1944
1945 /* if card is not ready, simply stop here */
1946 if (!qeth_card_hw_is_reachable(card)) {
1947 if (state)
1948 card->options.vnicc.cur_chars |= vnicc;
1949 else
1950 card->options.vnicc.cur_chars &= ~vnicc;
1951 return rc;
1952 }
1953
1954 rc = qeth_l2_vnicc_set_char(card, vnicc, cmd);
1955 if (rc)
1956 card->options.vnicc.wanted_chars =
1957 card->options.vnicc.cur_chars;
Hans Wippel349d13d2017-09-18 21:18:16 +02001958 else {
1959 /* successful online VNICC change; handle special cases */
1960 if (state && vnicc == QETH_VNICC_RX_BCAST)
1961 card->options.vnicc.rx_bcast_enabled = true;
1962 if (!state && vnicc == QETH_VNICC_LEARNING)
1963 qeth_l2_vnicc_recover_timeout(card, vnicc,
1964 &card->options.vnicc.learning_timeout);
1965 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02001966
1967 return rc;
1968}
1969
1970/* get current VNICC flag state; called from sysfs show function */
1971int qeth_l2_vnicc_get_state(struct qeth_card *card, u32 vnicc, bool *state)
1972{
1973 int rc = 0;
1974
1975 QETH_CARD_TEXT(card, 2, "vniccgch");
1976
1977 /* do not get anything if BridgePort is enabled */
1978 if (qeth_bridgeport_is_in_use(card))
1979 return -EBUSY;
1980
1981 /* check if characteristic is supported */
1982 if (!(card->options.vnicc.sup_chars & vnicc))
1983 return -EOPNOTSUPP;
1984
1985 /* if card is ready, query current VNICC state */
1986 if (qeth_card_hw_is_reachable(card))
1987 rc = qeth_l2_vnicc_query_chars(card);
1988
1989 *state = (card->options.vnicc.cur_chars & vnicc) ? true : false;
1990 return rc;
1991}
1992
Hans Wippel349d13d2017-09-18 21:18:16 +02001993/* set VNICC timeout; called from sysfs store function. Currently, only learning
1994 * supports timeout
1995 */
1996int qeth_l2_vnicc_set_timeout(struct qeth_card *card, u32 timeout)
1997{
1998 int rc = 0;
1999
2000 QETH_CARD_TEXT(card, 2, "vniccsto");
2001
2002 /* do not change anything if BridgePort is enabled */
2003 if (qeth_bridgeport_is_in_use(card))
2004 return -EBUSY;
2005
2006 /* check if characteristic and set_timeout are supported */
2007 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2008 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2009 return -EOPNOTSUPP;
2010
2011 /* do we need to do anything? */
2012 if (card->options.vnicc.learning_timeout == timeout)
2013 return rc;
2014
2015 /* if card is not ready, simply store the value internally and return */
2016 if (!qeth_card_hw_is_reachable(card)) {
2017 card->options.vnicc.learning_timeout = timeout;
2018 return rc;
2019 }
2020
2021 /* send timeout value to card; if successful, store value internally */
2022 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2023 IPA_VNICC_SET_TIMEOUT, &timeout);
2024 if (!rc)
2025 card->options.vnicc.learning_timeout = timeout;
2026
2027 return rc;
2028}
2029
2030/* get current VNICC timeout; called from sysfs show function. Currently, only
2031 * learning supports timeout
2032 */
2033int qeth_l2_vnicc_get_timeout(struct qeth_card *card, u32 *timeout)
2034{
2035 int rc = 0;
2036
2037 QETH_CARD_TEXT(card, 2, "vniccgto");
2038
2039 /* do not get anything if BridgePort is enabled */
2040 if (qeth_bridgeport_is_in_use(card))
2041 return -EBUSY;
2042
2043 /* check if characteristic and get_timeout are supported */
2044 if (!(card->options.vnicc.sup_chars & QETH_VNICC_LEARNING) ||
2045 !(card->options.vnicc.getset_timeout_sup & QETH_VNICC_LEARNING))
2046 return -EOPNOTSUPP;
2047 /* if card is ready, get timeout. Otherwise, just return stored value */
2048 *timeout = card->options.vnicc.learning_timeout;
2049 if (qeth_card_hw_is_reachable(card))
2050 rc = qeth_l2_vnicc_getset_timeout(card, QETH_VNICC_LEARNING,
2051 IPA_VNICC_GET_TIMEOUT,
2052 timeout);
2053
2054 return rc;
2055}
2056
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002057/* check if VNICC is currently enabled */
2058bool qeth_l2_vnicc_is_in_use(struct qeth_card *card)
2059{
2060 /* if everything is turned off, VNICC is not active */
2061 if (!card->options.vnicc.cur_chars)
2062 return false;
2063 /* default values are only OK if rx_bcast was not enabled by user
2064 * or the card is offline.
2065 */
2066 if (card->options.vnicc.cur_chars == QETH_VNICC_DEFAULT) {
2067 if (!card->options.vnicc.rx_bcast_enabled ||
2068 !qeth_card_hw_is_reachable(card))
2069 return false;
2070 }
2071 return true;
2072}
2073
Hans Wippel349d13d2017-09-18 21:18:16 +02002074/* recover user timeout setting */
2075static bool qeth_l2_vnicc_recover_timeout(struct qeth_card *card, u32 vnicc,
2076 u32 *timeout)
2077{
2078 if (card->options.vnicc.sup_chars & vnicc &&
2079 card->options.vnicc.getset_timeout_sup & vnicc &&
2080 !qeth_l2_vnicc_getset_timeout(card, vnicc, IPA_VNICC_SET_TIMEOUT,
2081 timeout))
2082 return false;
2083 *timeout = QETH_VNICC_DEFAULT_TIMEOUT;
2084 return true;
2085}
2086
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002087/* recover user characteristic setting */
2088static bool qeth_l2_vnicc_recover_char(struct qeth_card *card, u32 vnicc,
2089 bool enable)
2090{
2091 u32 cmd = enable ? IPA_VNICC_ENABLE : IPA_VNICC_DISABLE;
2092
2093 if (card->options.vnicc.sup_chars & vnicc &&
2094 card->options.vnicc.set_char_sup & vnicc &&
2095 !qeth_l2_vnicc_set_char(card, vnicc, cmd))
2096 return false;
2097 card->options.vnicc.wanted_chars &= ~vnicc;
2098 card->options.vnicc.wanted_chars |= QETH_VNICC_DEFAULT & vnicc;
2099 return true;
2100}
2101
Hans Wippela45b3fa2017-09-18 21:18:14 +02002102/* (re-)initialize VNICC */
2103static void qeth_l2_vnicc_init(struct qeth_card *card)
2104{
Hans Wippel349d13d2017-09-18 21:18:16 +02002105 u32 *timeout = &card->options.vnicc.learning_timeout;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002106 unsigned int chars_len, i;
2107 unsigned long chars_tmp;
2108 u32 sup_cmds, vnicc;
2109 bool enable, error;
2110
Hans Wippela45b3fa2017-09-18 21:18:14 +02002111 QETH_CARD_TEXT(card, 2, "vniccini");
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002112 /* reset rx_bcast */
2113 card->options.vnicc.rx_bcast_enabled = 0;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002114 /* initial query and storage of VNIC characteristics */
2115 if (qeth_l2_vnicc_query_chars(card)) {
Hans Wippel349d13d2017-09-18 21:18:16 +02002116 if (card->options.vnicc.wanted_chars != QETH_VNICC_DEFAULT ||
2117 *timeout != QETH_VNICC_DEFAULT_TIMEOUT)
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002118 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2119 /* fail quietly if user didn't change the default config */
Hans Wippela45b3fa2017-09-18 21:18:14 +02002120 card->options.vnicc.sup_chars = 0;
2121 card->options.vnicc.cur_chars = 0;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002122 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
2123 return;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002124 }
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002125 /* get supported commands for each supported characteristic */
2126 chars_tmp = card->options.vnicc.sup_chars;
2127 chars_len = sizeof(card->options.vnicc.sup_chars) * BITS_PER_BYTE;
2128 for_each_set_bit(i, &chars_tmp, chars_len) {
2129 vnicc = BIT(i);
2130 qeth_l2_vnicc_query_cmds(card, vnicc, &sup_cmds);
Hans Wippel349d13d2017-09-18 21:18:16 +02002131 if (!(sup_cmds & IPA_VNICC_SET_TIMEOUT) ||
2132 !(sup_cmds & IPA_VNICC_GET_TIMEOUT))
2133 card->options.vnicc.getset_timeout_sup &= ~vnicc;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002134 if (!(sup_cmds & IPA_VNICC_ENABLE) ||
2135 !(sup_cmds & IPA_VNICC_DISABLE))
2136 card->options.vnicc.set_char_sup &= ~vnicc;
2137 }
2138 /* enforce assumed default values and recover settings, if changed */
Hans Wippel349d13d2017-09-18 21:18:16 +02002139 error = qeth_l2_vnicc_recover_timeout(card, QETH_VNICC_LEARNING,
2140 timeout);
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002141 chars_tmp = card->options.vnicc.wanted_chars ^ QETH_VNICC_DEFAULT;
2142 chars_tmp |= QETH_VNICC_BRIDGE_INVISIBLE;
2143 chars_len = sizeof(card->options.vnicc.wanted_chars) * BITS_PER_BYTE;
2144 for_each_set_bit(i, &chars_tmp, chars_len) {
2145 vnicc = BIT(i);
2146 enable = card->options.vnicc.wanted_chars & vnicc;
2147 error |= qeth_l2_vnicc_recover_char(card, vnicc, enable);
2148 }
2149 if (error)
2150 dev_err(&card->gdev->dev, "Configuring the VNIC characteristics failed\n");
2151}
2152
2153/* configure default values of VNIC characteristics */
2154static void qeth_l2_vnicc_set_defaults(struct qeth_card *card)
2155{
2156 /* characteristics values */
2157 card->options.vnicc.sup_chars = QETH_VNICC_ALL;
2158 card->options.vnicc.cur_chars = QETH_VNICC_DEFAULT;
Hans Wippel349d13d2017-09-18 21:18:16 +02002159 card->options.vnicc.learning_timeout = QETH_VNICC_DEFAULT_TIMEOUT;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002160 /* supported commands */
2161 card->options.vnicc.set_char_sup = QETH_VNICC_ALL;
Hans Wippel349d13d2017-09-18 21:18:16 +02002162 card->options.vnicc.getset_timeout_sup = QETH_VNICC_LEARNING;
Hans Wippelcaa1f0b2017-09-18 21:18:15 +02002163 /* settings wanted by users */
2164 card->options.vnicc.wanted_chars = QETH_VNICC_DEFAULT;
Hans Wippela45b3fa2017-09-18 21:18:14 +02002165}
2166
Frank Blaschka4a71df52008-02-15 09:19:42 +01002167module_init(qeth_l2_init);
2168module_exit(qeth_l2_exit);
2169MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2170MODULE_DESCRIPTION("qeth layer 2 discipline");
2171MODULE_LICENSE("GPL");