blob: 3f5b852408d3ce3aedda542c90ef2060559fb682 [file] [log] [blame]
Frank Blaschka4a71df52008-02-15 09:19:42 +01001/*
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02002 * Copyright IBM Corp. 2007, 2009
Frank Blaschka4a71df52008-02-15 09:19:42 +01003 * Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
4 * Frank Pavlic <fpavlic@de.ibm.com>,
5 * Thomas Spatzier <tspat@de.ibm.com>,
6 * Frank Blaschka <frank.blaschka@de.ibm.com>
7 */
8
Frank Blaschka74eacdb2008-12-25 13:39:49 +01009#define KMSG_COMPONENT "qeth"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Frank Blaschka4a71df52008-02-15 09:19:42 +010012#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/string.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090017#include <linux/slab.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010018#include <linux/etherdevice.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010019#include <linux/ip.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>
23#include <linux/string.h>
Julian Wiedmannec61bd22017-06-20 16:00:34 +020024#include <asm/setup.h>
Frank Blaschka4a71df52008-02-15 09:19:42 +010025#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010026#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010027
Frank Blaschka4a71df52008-02-15 09:19:42 +010028static int qeth_l2_set_offline(struct ccwgroup_device *);
29static int qeth_l2_stop(struct net_device *);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020030static void qeth_l2_set_rx_mode(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010031static void qeth_bridgeport_query_support(struct qeth_card *card);
32static void qeth_bridge_state_change(struct qeth_card *card,
33 struct qeth_ipa_cmd *cmd);
34static void qeth_bridge_host_event(struct qeth_card *card,
35 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010036
Frank Blaschka4a71df52008-02-15 09:19:42 +010037static int qeth_l2_verify_dev(struct net_device *dev)
38{
39 struct qeth_card *card;
40 unsigned long flags;
41 int rc = 0;
42
43 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
44 list_for_each_entry(card, &qeth_core_card_list.list, list) {
45 if (card->dev == dev) {
46 rc = QETH_REAL_CARD;
47 break;
48 }
49 }
50 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
51
52 return rc;
53}
54
55static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
56{
57 struct qeth_card *card;
58 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020059 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010060 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020061 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010062
63 ndev = NULL;
64 memcpy(&temp_dev_no, read_dev_no, 2);
65 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
66 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020067 ccw_device_get_id(CARD_RDEV(card), &read_devid);
68 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010069 ndev = card->dev;
70 break;
71 }
72 }
73 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
74 return ndev;
75}
76
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010077static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010078{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010079 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010080
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010081 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010082 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010083 switch (retcode) {
84 case IPA_RC_SUCCESS:
85 rc = 0;
86 break;
87 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020088 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010089 break;
90 case IPA_RC_L2_ADDR_TABLE_FULL:
91 rc = -ENOSPC;
92 break;
93 case IPA_RC_L2_DUP_MAC:
94 case IPA_RC_L2_DUP_LAYER3_MAC:
95 rc = -EEXIST;
96 break;
97 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
98 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
99 rc = -EPERM;
100 break;
101 case IPA_RC_L2_MAC_NOT_FOUND:
102 rc = -ENOENT;
103 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100104 case -ENOMEM:
105 rc = -ENOMEM;
106 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100107 default:
108 rc = -EIO;
109 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100110 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100111 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100112}
113
Julian Wiedmannac988d72017-01-12 15:48:41 +0100114static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
115 enum qeth_ipa_cmds ipacmd)
116{
117 struct qeth_ipa_cmd *cmd;
118 struct qeth_cmd_buffer *iob;
119
120 QETH_CARD_TEXT(card, 2, "L2sdmac");
121 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
122 if (!iob)
123 return -ENOMEM;
124 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
125 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
126 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
127 return qeth_setdel_makerc(card, qeth_send_ipa_cmd(card, iob,
128 NULL, NULL));
129}
130
131static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
132{
133 int rc;
134
135 QETH_CARD_TEXT(card, 2, "L2Setmac");
136 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
137 if (rc == 0) {
138 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
139 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
140 dev_info(&card->gdev->dev,
141 "MAC address %pM successfully registered on device %s\n",
142 card->dev->dev_addr, card->dev->name);
143 } else {
144 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
145 switch (rc) {
146 case -EEXIST:
147 dev_warn(&card->gdev->dev,
148 "MAC address %pM already exists\n", mac);
149 break;
150 case -EPERM:
151 dev_warn(&card->gdev->dev,
152 "MAC address %pM is not authorized\n", mac);
153 break;
154 }
155 }
156 return rc;
157}
158
159static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
160{
161 int rc;
162
163 QETH_CARD_TEXT(card, 2, "L2Delmac");
164 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
165 return 0;
166 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC);
167 if (rc == 0)
168 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
169 return rc;
170}
171
Frank Blaschka4a71df52008-02-15 09:19:42 +0100172static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
173{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100174 int rc;
175
Carsten Otte847a50f2010-06-21 22:57:05 +0000176 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100177 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100178 if (rc == -EEXIST)
179 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
180 mac, QETH_CARD_IFNAME(card));
181 else if (rc)
182 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
183 mac, QETH_CARD_IFNAME(card), rc);
184 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100185}
186
187static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
188{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100189 int rc;
190
Carsten Otte847a50f2010-06-21 22:57:05 +0000191 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100192 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100193 if (rc)
194 QETH_DBF_MESSAGE(2,
195 "Could not delete group MAC %pM on %s: %d\n",
196 mac, QETH_CARD_IFNAME(card), rc);
197 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100198}
199
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200200static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200202 if (mac->is_uc) {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100203 return qeth_l2_send_setdelmac(card, mac->mac_addr,
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100204 IPA_CMD_SETVMAC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200205 } else {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100206 return qeth_l2_send_setgroupmac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200207 }
Julian Wiedmann979d7922017-01-12 15:48:40 +0100208}
209
210static int qeth_l2_remove_mac(struct qeth_card *card, struct qeth_mac *mac)
211{
212 if (mac->is_uc) {
213 return qeth_l2_send_setdelmac(card, mac->mac_addr,
214 IPA_CMD_DELVMAC);
215 } else {
216 return qeth_l2_send_delgroupmac(card, mac->mac_addr);
217 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200218}
219
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100220static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200221{
222 struct qeth_mac *mac;
223 struct hlist_node *tmp;
224 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100225
226 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200227 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200228 hash_del(&mac->hnode);
229 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100230 }
231 spin_unlock_bh(&card->mclock);
232}
233
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200234static int qeth_l2_get_cast_type(struct qeth_card *card, struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100235{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000236 if (card->info.type == QETH_CARD_TYPE_OSN)
237 return RTN_UNSPEC;
238 if (is_broadcast_ether_addr(skb->data))
239 return RTN_BROADCAST;
240 if (is_multicast_ether_addr(skb->data))
241 return RTN_MULTICAST;
242 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100243}
244
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200245static void qeth_l2_hdr_csum(struct qeth_card *card, struct qeth_hdr *hdr,
246 struct sk_buff *skb)
Thomas Richter4d7def22015-09-18 16:06:51 +0200247{
248 struct iphdr *iph = ip_hdr(skb);
249
250 /* tcph->check contains already the pseudo hdr checksum
251 * so just set the header flags
252 */
253 if (iph->protocol == IPPROTO_UDP)
254 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
255 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
256 QETH_HDR_EXT_CSUM_HDR_REQ;
257 iph->check = 0;
258 if (card->options.performance_stats)
259 card->perf_stats.tx_csum++;
260}
261
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200262static void qeth_l2_fill_header(struct qeth_hdr *hdr, struct sk_buff *skb,
263 int cast_type, unsigned int data_len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100264{
Frank Blaschka683d7182008-08-01 16:39:13 +0200265 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100266
267 memset(hdr, 0, sizeof(struct qeth_hdr));
268 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200269 hdr->hdr.l2.pkt_length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100270
271 /* set byte byte 3 to casting flags */
272 if (cast_type == RTN_MULTICAST)
273 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
274 else if (cast_type == RTN_BROADCAST)
275 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
276 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000277 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278
Frank Blaschka4a71df52008-02-15 09:19:42 +0100279 /* VSWITCH relies on the VLAN
280 * information to be present in
281 * the QDIO header */
282 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
283 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
284 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
285 }
286}
287
288static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
289 struct qeth_reply *reply, unsigned long data)
290{
291 struct qeth_ipa_cmd *cmd;
292
Carsten Otte847a50f2010-06-21 22:57:05 +0000293 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100294 cmd = (struct qeth_ipa_cmd *) data;
295 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200296 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100297 "Continuing\n", cmd->data.setdelvlan.vlan_id,
298 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000299 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
300 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 }
302 return 0;
303}
304
305static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
306 enum qeth_ipa_cmds ipacmd)
307{
308 struct qeth_ipa_cmd *cmd;
309 struct qeth_cmd_buffer *iob;
310
Carsten Otte847a50f2010-06-21 22:57:05 +0000311 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100312 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100313 if (!iob)
314 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100315 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
316 cmd->data.setdelvlan.vlan_id = i;
317 return qeth_send_ipa_cmd(card, iob,
318 qeth_l2_send_setdelvlan_cb, NULL);
319}
320
Ursula Braun70919e22011-02-26 22:41:36 -0800321static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322{
323 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000324 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100325 spin_lock_bh(&card->vlanlock);
326 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800327 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100328 }
329 spin_unlock_bh(&card->vlanlock);
330}
331
Patrick McHardy80d5c362013-04-19 02:04:28 +0000332static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
333 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100334{
Heiko Carstens509e2562008-07-26 02:24:10 -0700335 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100337 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338
Carsten Otte847a50f2010-06-21 22:57:05 +0000339 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000340 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500341 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000342 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000343 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500344 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000345 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000346 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000347 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500348 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000349 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
351 if (id) {
352 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100353 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
354 if (rc) {
355 kfree(id);
356 return rc;
357 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100358 spin_lock_bh(&card->vlanlock);
359 list_add_tail(&id->list, &card->vid_list);
360 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500361 } else {
362 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500364 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365}
366
Patrick McHardy80d5c362013-04-19 02:04:28 +0000367static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
368 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100369{
370 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700371 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100372 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373
Carsten Otte847a50f2010-06-21 22:57:05 +0000374 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000375 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000376 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500377 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000378 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000379 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000380 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500381 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000382 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100383 spin_lock_bh(&card->vlanlock);
384 list_for_each_entry(id, &card->vid_list, list) {
385 if (id->vid == vid) {
386 list_del(&id->list);
387 tmpid = id;
388 break;
389 }
390 }
391 spin_unlock_bh(&card->vlanlock);
392 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100393 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100394 kfree(tmpid);
395 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200396 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100397 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100398}
399
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200400static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200402 QETH_DBF_TEXT(SETUP , 2, "stopcard");
403 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100404
405 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406 if (card->read.state == CH_STATE_UP &&
407 card->write.state == CH_STATE_UP &&
408 (card->state == CARD_STATE_UP)) {
409 if (recovery_mode &&
410 card->info.type != QETH_CARD_TYPE_OSN) {
411 qeth_l2_stop(card->dev);
412 } else {
413 rtnl_lock();
414 dev_close(card->dev);
415 rtnl_unlock();
416 }
Ursula Braun70919e22011-02-26 22:41:36 -0800417 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100418 card->state = CARD_STATE_SOFTSETUP;
419 }
420 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100421 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422 qeth_clear_ipacmd_list(card);
423 card->state = CARD_STATE_HARDSETUP;
424 }
425 if (card->state == CARD_STATE_HARDSETUP) {
426 qeth_qdio_clear_card(card, 0);
427 qeth_clear_qdio_buffers(card);
428 qeth_clear_working_pool_list(card);
429 card->state = CARD_STATE_DOWN;
430 }
431 if (card->state == CARD_STATE_DOWN) {
432 qeth_clear_cmd_buffers(&card->read);
433 qeth_clear_cmd_buffers(&card->write);
434 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100435}
436
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000437static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
438 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100439{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000440 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 struct sk_buff *skb;
442 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443 unsigned int len;
444
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000445 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000446 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000447 while (budget) {
448 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000449 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000450 &card->rx.b_element, &card->rx.e_offset, &hdr);
451 if (!skb) {
452 *done = 1;
453 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100454 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000455 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100456 switch (hdr->hdr.l2.id) {
457 case QETH_HEADER_TYPE_LAYER2:
458 skb->pkt_type = PACKET_HOST;
459 skb->protocol = eth_type_trans(skb, skb->dev);
Thomas Richter4d7def22015-09-18 16:06:51 +0200460 if ((card->dev->features & NETIF_F_RXCSUM)
461 && ((hdr->hdr.l2.flags[1] &
462 (QETH_HDR_EXT_CSUM_HDR_REQ |
463 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
464 (QETH_HDR_EXT_CSUM_HDR_REQ |
465 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
466 skb->ip_summed = CHECKSUM_UNNECESSARY;
467 else
468 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200469 if (skb->protocol == htons(ETH_P_802_2))
470 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100471 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200472 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100473 break;
474 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200475 if (card->info.type == QETH_CARD_TYPE_OSN) {
476 skb_push(skb, sizeof(struct qeth_hdr));
477 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200479 len = skb->len;
480 card->osn_info.data_cb(skb);
481 break;
482 }
483 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100484 default:
485 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000486 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200487 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100488 continue;
489 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000490 work_done++;
491 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100492 card->stats.rx_packets++;
493 card->stats.rx_bytes += len;
494 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000495 return work_done;
496}
497
Frank Blaschka4a71df52008-02-15 09:19:42 +0100498static int qeth_l2_request_initial_mac(struct qeth_card *card)
499{
500 int rc = 0;
501 char vendor_pre[] = {0x02, 0x00, 0x00};
502
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200503 QETH_DBF_TEXT(SETUP, 2, "l2reqmac");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200504 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100505
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200506 if (MACHINE_IS_VM) {
507 rc = qeth_vm_request_mac(card);
508 if (!rc)
509 goto out;
510 QETH_DBF_MESSAGE(2, "z/VM MAC Service failed on device %s: x%x\n",
511 CARD_BUS_ID(card), rc);
512 QETH_DBF_TEXT_(SETUP, 2, "err%04x", rc);
513 /* fall back to alternative mechanism: */
514 }
515
Ursula Braun5113fec2010-05-16 21:15:14 +0000516 if (card->info.type == QETH_CARD_TYPE_IQD ||
517 card->info.type == QETH_CARD_TYPE_OSM ||
518 card->info.type == QETH_CARD_TYPE_OSX ||
519 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100520 rc = qeth_setadpparms_change_macaddr(card);
521 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200522 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
523 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100524 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100525 return rc;
526 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100527 } else {
Joe Perches18336112012-07-12 22:33:10 -0700528 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100529 memcpy(card->dev->dev_addr, vendor_pre, 3);
530 }
Julian Wiedmannec61bd22017-06-20 16:00:34 +0200531out:
532 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100533 return 0;
534}
535
536static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
537{
538 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700539 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100540 int rc = 0;
541
Carsten Otte847a50f2010-06-21 22:57:05 +0000542 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100543
544 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000545 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546 return -EOPNOTSUPP;
547 }
548
Ursula Braun5113fec2010-05-16 21:15:14 +0000549 if (card->info.type == QETH_CARD_TYPE_OSN ||
550 card->info.type == QETH_CARD_TYPE_OSM ||
551 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000552 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100553 return -EOPNOTSUPP;
554 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000555 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000556 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000557 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000558 return -ERESTARTSYS;
559 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100560 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100561 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100562 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000563 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100564}
565
Eugene Crosser0db587b2015-05-18 14:27:55 +0200566static void qeth_promisc_to_bridge(struct qeth_card *card)
567{
568 struct net_device *dev = card->dev;
569 enum qeth_ipa_promisc_modes promisc_mode;
570 int role;
571 int rc;
572
573 QETH_CARD_TEXT(card, 3, "pmisc2br");
574
575 if (!card->options.sbp.reflect_promisc)
576 return;
577 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
578 : SET_PROMISC_MODE_OFF;
579 if (promisc_mode == card->info.promisc_mode)
580 return;
581
582 if (promisc_mode == SET_PROMISC_MODE_ON) {
583 if (card->options.sbp.reflect_promisc_primary)
584 role = QETH_SBP_ROLE_PRIMARY;
585 else
586 role = QETH_SBP_ROLE_SECONDARY;
587 } else
588 role = QETH_SBP_ROLE_NONE;
589
590 rc = qeth_bridgeport_setrole(card, role);
591 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
592 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
593 if (!rc) {
594 card->options.sbp.role = role;
595 card->info.promisc_mode = promisc_mode;
596 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200597
598}
599/* New MAC address is added to the hash table and marked to be written on card
600 * only if there is not in the hash table storage already
601 *
602*/
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200603static void qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha,
604 u8 is_uc)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200605{
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200606 u32 mac_hash = get_unaligned((u32 *)(&ha->addr[2]));
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200607 struct qeth_mac *mac;
608
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200609 hash_for_each_possible(card->mac_htable, mac, hnode, mac_hash) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200610 if (is_uc == mac->is_uc &&
611 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200612 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200613 return;
614 }
615 }
616
617 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
618
619 if (!mac)
620 return;
621
622 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
623 mac->is_uc = is_uc;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200624 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200625
Julian Wiedmanncef6ff222017-08-15 17:02:46 +0200626 hash_add(card->mac_htable, &mac->hnode, mac_hash);
Eugene Crosser0db587b2015-05-18 14:27:55 +0200627}
628
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200629static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100630{
Heiko Carstens509e2562008-07-26 02:24:10 -0700631 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000632 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200633 struct qeth_mac *mac;
634 struct hlist_node *tmp;
635 int i;
636 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100637
638 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200639 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100640
Carsten Otte847a50f2010-06-21 22:57:05 +0000641 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000642 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
643 (card->state != CARD_STATE_UP))
644 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200645
Frank Blaschka4a71df52008-02-15 09:19:42 +0100646 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200647
Jiri Pirko22bedad32010-04-01 21:22:57 +0000648 netdev_for_each_mc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200649 qeth_l2_add_mac(card, ha, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200650
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800651 netdev_for_each_uc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200652 qeth_l2_add_mac(card, ha, 1);
653
654 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200655 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100656 qeth_l2_remove_mac(card, mac);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200657 hash_del(&mac->hnode);
658 kfree(mac);
659
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200660 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200661 rc = qeth_l2_write_mac(card, mac);
662 if (rc) {
663 hash_del(&mac->hnode);
664 kfree(mac);
665 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200666 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200667 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200668 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200669 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200670
Frank Blaschka4a71df52008-02-15 09:19:42 +0100671 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200672
Eugene Crosser0db587b2015-05-18 14:27:55 +0200673 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
674 qeth_setadp_promisc_mode(card);
675 else
676 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100677}
678
Julian Wiedmann72863842017-08-18 10:19:04 +0200679static int qeth_l2_xmit_iqd(struct qeth_card *card, struct sk_buff *skb,
680 struct qeth_qdio_out_q *queue, int cast_type)
681{
682 unsigned int data_offset = ETH_HLEN;
683 struct qeth_hdr *hdr;
684 int rc;
685
686 hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC);
687 if (!hdr)
688 return -ENOMEM;
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200689 qeth_l2_fill_header(hdr, skb, cast_type, skb->len);
Julian Wiedmann72863842017-08-18 10:19:04 +0200690 skb_copy_from_linear_data(skb, ((char *)hdr) + sizeof(*hdr),
691 data_offset);
692
693 if (!qeth_get_elements_no(card, skb, 1, data_offset)) {
694 rc = -E2BIG;
695 goto out;
696 }
697 rc = qeth_do_send_packet_fast(card, queue, skb, hdr, data_offset,
698 data_offset);
699out:
700 if (rc)
701 kmem_cache_free(qeth_core_header_cache, hdr);
702 return rc;
703}
704
705static int qeth_l2_xmit_osa(struct qeth_card *card, struct sk_buff *skb,
706 struct qeth_qdio_out_q *queue, int cast_type)
707{
708 unsigned int elements, nr_frags;
709 struct sk_buff *skb_copy;
710 struct qeth_hdr *hdr;
711 int rc;
712
713 /* fix hardware limitation: as long as we do not have sbal
714 * chaining we can not send long frag lists
715 */
716 if (!qeth_get_elements_no(card, skb, 0, 0)) {
717 rc = skb_linearize(skb);
718
719 if (card->options.performance_stats) {
720 if (rc)
721 card->perf_stats.tx_linfail++;
722 else
723 card->perf_stats.tx_lin++;
724 }
725 if (rc)
726 return rc;
727 }
728 nr_frags = skb_shinfo(skb)->nr_frags;
729
730 /* create a copy with writeable headroom */
731 skb_copy = skb_realloc_headroom(skb, sizeof(struct qeth_hdr));
732 if (!skb_copy)
733 return -ENOMEM;
734 hdr = skb_push(skb_copy, sizeof(struct qeth_hdr));
Julian Wiedmannae79fe02017-08-18 10:19:05 +0200735 qeth_l2_fill_header(hdr, skb_copy, cast_type,
736 skb_copy->len - sizeof(*hdr));
Julian Wiedmann72863842017-08-18 10:19:04 +0200737 if (skb_copy->ip_summed == CHECKSUM_PARTIAL)
738 qeth_l2_hdr_csum(card, hdr, skb_copy);
739
740 elements = qeth_get_elements_no(card, skb_copy, 0, 0);
741 if (!elements) {
742 rc = -E2BIG;
743 goto out;
744 }
745 if (qeth_hdr_chk_and_bounce(skb_copy, &hdr, sizeof(*hdr))) {
746 rc = -EINVAL;
747 goto out;
748 }
749 rc = qeth_do_send_packet(card, queue, skb_copy, hdr, elements);
750out:
751 if (!rc) {
752 /* tx success, free dangling original */
753 dev_kfree_skb_any(skb);
754 if (card->options.performance_stats && nr_frags) {
755 card->perf_stats.sg_skbs_sent++;
756 /* nr_frags + skb->data */
757 card->perf_stats.sg_frags_sent += nr_frags + 1;
758 }
759 } else {
760 /* tx fail, free copy */
761 dev_kfree_skb_any(skb_copy);
762 }
763 return rc;
764}
765
766static int qeth_l2_xmit_osn(struct qeth_card *card, struct sk_buff *skb,
767 struct qeth_qdio_out_q *queue)
768{
769 unsigned int elements;
770 struct qeth_hdr *hdr;
771
772 if (skb->protocol == htons(ETH_P_IPV6))
773 return -EPROTONOSUPPORT;
774
775 hdr = (struct qeth_hdr *)skb->data;
776 elements = qeth_get_elements_no(card, skb, 0, 0);
777 if (!elements)
778 return -E2BIG;
779 if (qeth_hdr_chk_and_bounce(skb, &hdr, sizeof(*hdr)))
780 return -EINVAL;
781 return qeth_do_send_packet(card, queue, skb, hdr, elements);
782}
783
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200784static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
785 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786{
Heiko Carstens509e2562008-07-26 02:24:10 -0700787 struct qeth_card *card = dev->ml_priv;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000788 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200789 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100790 int tx_bytes = skb->len;
Julian Wiedmann72863842017-08-18 10:19:04 +0200791 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100792
Stefan Raspl290b8342014-04-28 10:05:08 +0200793 if (card->qdio.do_prio_queueing || (cast_type &&
794 card->info.is_multicast_different))
795 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
796 qeth_get_ip_version(skb), cast_type)];
797 else
798 queue = card->qdio.out_qs[card->qdio.default_out_queue];
799
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
801 card->stats.tx_carrier_errors++;
802 goto tx_drop;
803 }
804
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805 if (card->options.performance_stats) {
806 card->perf_stats.outbound_cnt++;
807 card->perf_stats.outbound_start_time = qeth_get_micros();
808 }
809 netif_stop_queue(dev);
810
Julian Wiedmann72863842017-08-18 10:19:04 +0200811 switch (card->info.type) {
812 case QETH_CARD_TYPE_OSN:
813 rc = qeth_l2_xmit_osn(card, skb, queue);
814 break;
815 case QETH_CARD_TYPE_IQD:
816 rc = qeth_l2_xmit_iqd(card, skb, queue, cast_type);
817 break;
818 default:
819 rc = qeth_l2_xmit_osa(card, skb, queue, cast_type);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100820 }
821
Frank Blaschka4a71df52008-02-15 09:19:42 +0100822 if (!rc) {
823 card->stats.tx_packets++;
824 card->stats.tx_bytes += tx_bytes;
Julian Wiedmann72863842017-08-18 10:19:04 +0200825 if (card->options.performance_stats)
826 card->perf_stats.outbound_time += qeth_get_micros() -
827 card->perf_stats.outbound_start_time;
828 netif_wake_queue(dev);
829 return NETDEV_TX_OK;
830 } else if (rc == -EBUSY) {
831 return NETDEV_TX_BUSY;
832 } /* else fall through */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833
834tx_drop:
835 card->stats.tx_dropped++;
836 card->stats.tx_errors++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200838 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100839 return NETDEV_TX_OK;
840}
841
Ursula Braun39423442011-01-12 20:42:24 +0000842static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843{
Heiko Carstens509e2562008-07-26 02:24:10 -0700844 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000845 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100846
Carsten Otte847a50f2010-06-21 22:57:05 +0000847 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000848 if (card->state == CARD_STATE_UP)
849 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100850 if (card->state != CARD_STATE_SOFTSETUP)
851 return -ENODEV;
852
853 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
854 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000855 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856 return -EPERM;
857 }
858 card->data.state = CH_STATE_UP;
859 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100860 netif_start_queue(dev);
861
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000862 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
863 napi_enable(&card->napi);
864 napi_schedule(&card->napi);
865 } else
866 rc = -EIO;
867 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868}
869
Ursula Braun39423442011-01-12 20:42:24 +0000870static int qeth_l2_open(struct net_device *dev)
871{
872 struct qeth_card *card = dev->ml_priv;
873
874 QETH_CARD_TEXT(card, 5, "qethope_");
875 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
876 QETH_CARD_TEXT(card, 3, "openREC");
877 return -ERESTARTSYS;
878 }
879 return __qeth_l2_open(dev);
880}
881
Frank Blaschka4a71df52008-02-15 09:19:42 +0100882static int qeth_l2_stop(struct net_device *dev)
883{
Heiko Carstens509e2562008-07-26 02:24:10 -0700884 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100885
Carsten Otte847a50f2010-06-21 22:57:05 +0000886 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100887 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000888 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100889 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000890 napi_disable(&card->napi);
891 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892 return 0;
893}
894
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200895static const struct device_type qeth_l2_devtype = {
896 .name = "qeth_layer2",
897 .groups = qeth_l2_attr_groups,
898};
899
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
901{
902 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200903 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200905 if (gdev->dev.type == &qeth_generic_devtype) {
906 rc = qeth_l2_create_device_attributes(&gdev->dev);
907 if (rc)
908 return rc;
909 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100910 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200911 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000913 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914 return 0;
915}
916
917static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
918{
919 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
920
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200921 if (cgdev->dev.type == &qeth_generic_devtype)
922 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000923 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100924 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
925
Ursula Braun70919e22011-02-26 22:41:36 -0800926 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100928
929 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +0200930 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100931 unregister_netdev(card->dev);
932 card->dev = NULL;
933 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100934 return;
935}
936
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700937static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100939 .get_strings = qeth_core_get_strings,
940 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000941 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100942 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200943 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100944};
945
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700946static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100947 .get_strings = qeth_core_get_strings,
948 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000949 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100950 .get_drvinfo = qeth_core_get_drvinfo,
951};
952
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000953static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800954 .ndo_open = qeth_l2_open,
955 .ndo_stop = qeth_l2_stop,
956 .ndo_get_stats = qeth_get_stats,
957 .ndo_start_xmit = qeth_l2_hard_start_xmit,
958 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200959 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200960 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800961 .ndo_set_mac_address = qeth_l2_set_mac_address,
962 .ndo_change_mtu = qeth_change_mtu,
963 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
964 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
965 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200966 .ndo_fix_features = qeth_fix_features,
967 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800968};
969
Frank Blaschka4a71df52008-02-15 09:19:42 +0100970static int qeth_l2_setup_netdev(struct qeth_card *card)
971{
972 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100973 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200974 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
975 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100976 break;
977 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200978 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
979 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100980 break;
981 default:
982 card->dev = alloc_etherdev(0);
983 }
984
985 if (!card->dev)
986 return -ENODEV;
987
Heiko Carstens509e2562008-07-26 02:24:10 -0700988 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100989 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100990 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -0400991 card->dev->min_mtu = 64;
992 card->dev->max_mtu = ETH_MAX_MTU;
Frank Blaschka8403b132009-01-08 10:50:55 -0800993 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200994 if (card->info.type == QETH_CARD_TYPE_OSN) {
995 card->dev->ethtool_ops = &qeth_l2_osn_ops;
996 card->dev->flags |= IFF_NOARP;
997 } else {
998 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
999 }
Patrick McHardyf6469682013-04-19 02:04:27 +00001000 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Thomas Richter4d7def22015-09-18 16:06:51 +02001001 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001002 card->dev->hw_features = NETIF_F_SG;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001003 card->dev->vlan_features = NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +02001004 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +02001005 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001006 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001007 card->dev->vlan_features |= NETIF_F_IP_CSUM;
1008 }
1009 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001010 card->dev->hw_features |= NETIF_F_RXCSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +02001011 card->dev->vlan_features |= NETIF_F_RXCSUM;
1012 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001013 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001014 card->info.broadcast_capable = 1;
1015 qeth_l2_request_initial_mac(card);
Eugene Crosserd52aec92016-06-16 16:18:55 +02001016 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
1017 PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001018 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001019 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01001020 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 return register_netdev(card->dev);
1022}
1023
Thomas Richter4d7def22015-09-18 16:06:51 +02001024static int qeth_l2_start_ipassists(struct qeth_card *card)
1025{
1026 /* configure isolation level */
1027 if (qeth_set_access_ctrl_online(card, 0))
1028 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +02001029 return 0;
1030}
1031
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001032static void qeth_l2_trace_features(struct qeth_card *card)
1033{
1034 QETH_CARD_TEXT(card, 2, "l2featur");
1035 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
1036 sizeof(card->options.sbp.supported_funcs));
1037}
1038
Frank Blaschka4a71df52008-02-15 09:19:42 +01001039static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1040{
1041 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1042 int rc = 0;
1043 enum qeth_card_states recover_flag;
1044
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001045 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001046 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001047 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1048 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001049
Frank Blaschka4a71df52008-02-15 09:19:42 +01001050 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051 rc = qeth_core_hardsetup_card(card);
1052 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001053 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001054 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001055 goto out_remove;
1056 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001057 qeth_bridgeport_query_support(card);
1058 if (card->options.sbp.supported_funcs)
1059 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001060 "The device represents a Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001061 qeth_trace_features(card);
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001062 qeth_l2_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063
Ursula Braunaa909222009-11-12 00:11:43 +00001064 if (!card->dev && qeth_l2_setup_netdev(card)) {
1065 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001066 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001067 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001068
1069 if (card->info.type != QETH_CARD_TYPE_OSN)
1070 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1071
Frank Blaschka1da74b12011-05-12 18:45:02 +00001072 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1073 if (card->info.hwtrap &&
1074 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1075 card->info.hwtrap = 0;
1076 } else
1077 card->info.hwtrap = 0;
1078
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001079 qeth_l2_setup_bridgeport_attrs(card);
1080
Frank Blaschka4a71df52008-02-15 09:19:42 +01001081 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001082 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001083 qeth_print_status_message(card);
1084
1085 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001086 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001087
Ursula Braun5113fec2010-05-16 21:15:14 +00001088 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001089 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001090 rc = qeth_l2_start_ipassists(card);
1091 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001092 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001093 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001094
1095 if (card->info.type != QETH_CARD_TYPE_OSN &&
1096 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001097 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001098
1099 netif_tx_disable(card->dev);
1100
1101 rc = qeth_init_qdio_queues(card);
1102 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001103 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001104 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001105 goto out_remove;
1106 }
1107 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001108 if (card->lan_online)
1109 netif_carrier_on(card->dev);
1110 else
1111 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001112
1113 qeth_set_allowed_threads(card, 0xffffffff, 0);
1114 if (recover_flag == CARD_STATE_RECOVER) {
1115 if (recovery_mode &&
1116 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001117 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001118 } else {
1119 rtnl_lock();
1120 dev_open(card->dev);
1121 rtnl_unlock();
1122 }
1123 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001124 qeth_l2_set_rx_mode(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02001125 rtnl_lock();
1126 qeth_recover_features(card->dev);
1127 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001128 }
1129 /* let user_space know that device is online */
1130 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001131 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001132 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001133 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001134
Frank Blaschka4a71df52008-02-15 09:19:42 +01001135out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001136 qeth_l2_stop_card(card, 0);
1137 ccw_device_set_offline(CARD_DDEV(card));
1138 ccw_device_set_offline(CARD_WDEV(card));
1139 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001140 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001141 if (recover_flag == CARD_STATE_RECOVER)
1142 card->state = CARD_STATE_RECOVER;
1143 else
1144 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001145 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001146 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001147 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001148}
1149
1150static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1151{
1152 return __qeth_l2_set_online(gdev, 0);
1153}
1154
1155static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1156 int recovery_mode)
1157{
1158 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1159 int rc = 0, rc2 = 0, rc3 = 0;
1160 enum qeth_card_states recover_flag;
1161
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001162 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001163 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001164 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1165 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001166
1167 if (card->dev && netif_carrier_ok(card->dev))
1168 netif_carrier_off(card->dev);
1169 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001170 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1171 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1172 card->info.hwtrap = 1;
1173 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001174 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001175 rc = ccw_device_set_offline(CARD_DDEV(card));
1176 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1177 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1178 if (!rc)
1179 rc = (rc2) ? rc2 : rc3;
1180 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001181 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001182 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001183 if (recover_flag == CARD_STATE_UP)
1184 card->state = CARD_STATE_RECOVER;
1185 /* let user_space know that device is offline */
1186 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001187 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001188 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001189 return 0;
1190}
1191
1192static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1193{
1194 return __qeth_l2_set_offline(cgdev, 0);
1195}
1196
1197static int qeth_l2_recover(void *ptr)
1198{
1199 struct qeth_card *card;
1200 int rc = 0;
1201
1202 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001203 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001204 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1205 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001206 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001207 dev_warn(&card->gdev->dev,
1208 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001209 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001210 __qeth_l2_set_offline(card->gdev, 1);
1211 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001212 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001213 dev_info(&card->gdev->dev,
1214 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001215 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001216 qeth_close_dev(card);
1217 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001218 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001219 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001220 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001221 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1222 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001223 return 0;
1224}
1225
1226static int __init qeth_l2_init(void)
1227{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001228 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001229 return 0;
1230}
1231
1232static void __exit qeth_l2_exit(void)
1233{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001234 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001235}
1236
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001237static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1238{
1239 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1240
1241 if (card->dev)
1242 netif_device_detach(card->dev);
1243 qeth_set_allowed_threads(card, 0, 1);
1244 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1245 if (gdev->state == CCWGROUP_OFFLINE)
1246 return 0;
1247 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001248 if (card->info.hwtrap)
1249 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001250 __qeth_l2_set_offline(card->gdev, 1);
1251 } else
1252 __qeth_l2_set_offline(card->gdev, 0);
1253 return 0;
1254}
1255
1256static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1257{
1258 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1259 int rc = 0;
1260
1261 if (gdev->state == CCWGROUP_OFFLINE)
1262 goto out;
1263
1264 if (card->state == CARD_STATE_RECOVER) {
1265 rc = __qeth_l2_set_online(card->gdev, 1);
1266 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001267 rtnl_lock();
1268 dev_close(card->dev);
1269 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001270 }
1271 } else
1272 rc = __qeth_l2_set_online(card->gdev, 0);
1273out:
1274 qeth_set_allowed_threads(card, 0xffffffff, 0);
1275 if (card->dev)
1276 netif_device_attach(card->dev);
1277 if (rc)
1278 dev_warn(&card->gdev->dev, "The qeth device driver "
1279 "failed to recover an error on the device\n");
1280 return rc;
1281}
1282
Eugene Crosserc044dc22014-01-29 09:23:48 +01001283/* Returns zero if the command is successfully "consumed" */
1284static int qeth_l2_control_event(struct qeth_card *card,
1285 struct qeth_ipa_cmd *cmd)
1286{
1287 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001288 case IPA_CMD_SETBRIDGEPORT_OSA:
1289 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001290 if (cmd->data.sbp.hdr.command_code ==
1291 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1292 qeth_bridge_state_change(card, cmd);
1293 return 0;
1294 } else
1295 return 1;
1296 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1297 qeth_bridge_host_event(card, cmd);
1298 return 0;
1299 default:
1300 return 1;
1301 }
1302}
1303
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001304struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001305 .devtype = &qeth_l2_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001306 .start_poll = qeth_qdio_start_poll,
1307 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1308 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001309 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001310 .recover = qeth_l2_recover,
1311 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001312 .remove = qeth_l2_remove_device,
1313 .set_online = qeth_l2_set_online,
1314 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001315 .freeze = qeth_l2_pm_suspend,
1316 .thaw = qeth_l2_pm_resume,
1317 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001318 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001319 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001320};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001321EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001322
1323static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1324 struct qeth_cmd_buffer *iob)
1325{
1326 unsigned long flags;
1327 int rc = 0;
1328
Carsten Otte847a50f2010-06-21 22:57:05 +00001329 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001330
1331 wait_event(card->wait_q,
1332 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1333 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001334 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001335 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1336 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1337 (addr_t) iob, 0, 0);
1338 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1339 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001340 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001341 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001342 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001343 qeth_release_buffer(iob->channel, iob);
1344 atomic_set(&card->write.irq_pending, 0);
1345 wake_up(&card->wait_q);
1346 }
1347 return rc;
1348}
1349
1350static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1351 struct qeth_cmd_buffer *iob, int data_len)
1352{
1353 u16 s1, s2;
1354
Carsten Otte847a50f2010-06-21 22:57:05 +00001355 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001356
1357 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1358 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1359 s2 = (u16)data_len;
1360 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1361 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1362 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1363 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1364 return qeth_osn_send_control_data(card, s1, iob);
1365}
1366
1367int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1368{
1369 struct qeth_cmd_buffer *iob;
1370 struct qeth_card *card;
1371 int rc;
1372
Frank Blaschka4a71df52008-02-15 09:19:42 +01001373 if (!dev)
1374 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001375 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001376 if (!card)
1377 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001378 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001379 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380 return -ENODEV;
1381 iob = qeth_wait_for_buffer(&card->write);
1382 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1383 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1384 return rc;
1385}
1386EXPORT_SYMBOL(qeth_osn_assist);
1387
1388int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1389 int (*assist_cb)(struct net_device *, void *),
1390 int (*data_cb)(struct sk_buff *))
1391{
1392 struct qeth_card *card;
1393
Frank Blaschka4a71df52008-02-15 09:19:42 +01001394 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1395 if (*dev == NULL)
1396 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001397 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001398 if (!card)
1399 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001400 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401 if ((assist_cb == NULL) || (data_cb == NULL))
1402 return -EINVAL;
1403 card->osn_info.assist_cb = assist_cb;
1404 card->osn_info.data_cb = data_cb;
1405 return 0;
1406}
1407EXPORT_SYMBOL(qeth_osn_register);
1408
1409void qeth_osn_deregister(struct net_device *dev)
1410{
1411 struct qeth_card *card;
1412
Frank Blaschka4a71df52008-02-15 09:19:42 +01001413 if (!dev)
1414 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001415 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001416 if (!card)
1417 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001418 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001419 card->osn_info.assist_cb = NULL;
1420 card->osn_info.data_cb = NULL;
1421 return;
1422}
1423EXPORT_SYMBOL(qeth_osn_deregister);
1424
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001425/* SETBRIDGEPORT support, async notifications */
1426
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001427enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1428
1429/**
1430 * qeth_bridge_emit_host_event() - bridgeport address change notification
1431 * @card: qeth_card structure pointer, for udev events.
1432 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1433 * and reset token and addr_lnid are unused and may be NULL.
1434 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1435 * object, 0 - addition of an object.
1436 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1437 * @token: "network token" structure identifying physical address of the port.
1438 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1439 *
1440 * This function is called when registrations and deregistrations are
1441 * reported by the hardware, and also when notifications are enabled -
1442 * for all currently registered addresses.
1443 */
1444static void qeth_bridge_emit_host_event(struct qeth_card *card,
1445 enum qeth_an_event_type evtype,
1446 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1447{
1448 char str[7][32];
1449 char *env[8];
1450 int i = 0;
1451
1452 switch (evtype) {
1453 case anev_reg_unreg:
1454 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1455 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1456 ? "deregister" : "register");
1457 env[i] = str[i]; i++;
1458 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1459 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1460 addr_lnid->lnid);
1461 env[i] = str[i]; i++;
1462 }
1463 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001464 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001465 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001466 env[i] = str[i]; i++;
1467 }
1468 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1469 token->cssid, token->ssid, token->devnum);
1470 env[i] = str[i]; i++;
1471 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1472 env[i] = str[i]; i++;
1473 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1474 token->chpid);
1475 env[i] = str[i]; i++;
1476 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1477 env[i] = str[i]; i++;
1478 break;
1479 case anev_abort:
1480 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1481 env[i] = str[i]; i++;
1482 break;
1483 case anev_reset:
1484 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1485 env[i] = str[i]; i++;
1486 break;
1487 }
1488 env[i] = NULL;
1489 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1490}
1491
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001492struct qeth_bridge_state_data {
1493 struct work_struct worker;
1494 struct qeth_card *card;
1495 struct qeth_sbp_state_change qports;
1496};
1497
1498static void qeth_bridge_state_change_worker(struct work_struct *work)
1499{
1500 struct qeth_bridge_state_data *data =
1501 container_of(work, struct qeth_bridge_state_data, worker);
1502 /* We are only interested in the first entry - local port */
1503 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1504 char env_locrem[32];
1505 char env_role[32];
1506 char env_state[32];
1507 char *env[] = {
1508 env_locrem,
1509 env_role,
1510 env_state,
1511 NULL
1512 };
1513
1514 /* Role should not change by itself, but if it did, */
1515 /* information from the hardware is authoritative. */
1516 mutex_lock(&data->card->conf_mutex);
1517 data->card->options.sbp.role = entry->role;
1518 mutex_unlock(&data->card->conf_mutex);
1519
1520 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1521 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1522 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1523 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1524 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1525 "<INVALID>");
1526 snprintf(env_state, sizeof(env_state), "STATE=%s",
1527 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1528 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1529 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1530 "<INVALID>");
1531 kobject_uevent_env(&data->card->gdev->dev.kobj,
1532 KOBJ_CHANGE, env);
1533 kfree(data);
1534}
1535
Eugene Crosserc044dc22014-01-29 09:23:48 +01001536static void qeth_bridge_state_change(struct qeth_card *card,
1537 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001538{
1539 struct qeth_sbp_state_change *qports =
1540 &cmd->data.sbp.data.state_change;
1541 struct qeth_bridge_state_data *data;
1542 int extrasize;
1543
1544 QETH_CARD_TEXT(card, 2, "brstchng");
1545 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001546 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001547 return;
1548 }
1549 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1550 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1551 GFP_ATOMIC);
1552 if (!data) {
1553 QETH_CARD_TEXT(card, 2, "BPSalloc");
1554 return;
1555 }
1556 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1557 data->card = card;
1558 memcpy(&data->qports, qports,
1559 sizeof(struct qeth_sbp_state_change) + extrasize);
1560 queue_work(qeth_wq, &data->worker);
1561}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001562
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001563struct qeth_bridge_host_data {
1564 struct work_struct worker;
1565 struct qeth_card *card;
1566 struct qeth_ipacmd_addr_change hostevs;
1567};
1568
1569static void qeth_bridge_host_event_worker(struct work_struct *work)
1570{
1571 struct qeth_bridge_host_data *data =
1572 container_of(work, struct qeth_bridge_host_data, worker);
1573 int i;
1574
1575 if (data->hostevs.lost_event_mask) {
1576 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001577"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001578 data->card->dev->name,
1579 (data->hostevs.lost_event_mask == 0x01)
1580 ? "Overflow"
1581 : (data->hostevs.lost_event_mask == 0x02)
1582 ? "Bridge port state change"
1583 : "Unknown reason");
1584 mutex_lock(&data->card->conf_mutex);
1585 data->card->options.sbp.hostnotification = 0;
1586 mutex_unlock(&data->card->conf_mutex);
1587 qeth_bridge_emit_host_event(data->card, anev_abort,
1588 0, NULL, NULL);
1589 } else
1590 for (i = 0; i < data->hostevs.num_entries; i++) {
1591 struct qeth_ipacmd_addr_change_entry *entry =
1592 &data->hostevs.entry[i];
1593 qeth_bridge_emit_host_event(data->card,
1594 anev_reg_unreg,
1595 entry->change_code,
1596 &entry->token, &entry->addr_lnid);
1597 }
1598 kfree(data);
1599}
1600
Eugene Crosserc044dc22014-01-29 09:23:48 +01001601static void qeth_bridge_host_event(struct qeth_card *card,
1602 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001603{
1604 struct qeth_ipacmd_addr_change *hostevs =
1605 &cmd->data.addrchange;
1606 struct qeth_bridge_host_data *data;
1607 int extrasize;
1608
1609 QETH_CARD_TEXT(card, 2, "brhostev");
1610 if (cmd->hdr.return_code != 0x0000) {
1611 if (cmd->hdr.return_code == 0x0010) {
1612 if (hostevs->lost_event_mask == 0x00)
1613 hostevs->lost_event_mask = 0xff;
1614 } else {
1615 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1616 cmd->hdr.return_code);
1617 return;
1618 }
1619 }
1620 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1621 hostevs->num_entries;
1622 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1623 GFP_ATOMIC);
1624 if (!data) {
1625 QETH_CARD_TEXT(card, 2, "BPHalloc");
1626 return;
1627 }
1628 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1629 data->card = card;
1630 memcpy(&data->hostevs, hostevs,
1631 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1632 queue_work(qeth_wq, &data->worker);
1633}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001634
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001635/* SETBRIDGEPORT support; sending commands */
1636
1637struct _qeth_sbp_cbctl {
1638 u16 ipa_rc;
1639 u16 cmd_rc;
1640 union {
1641 u32 supported;
1642 struct {
1643 enum qeth_sbp_roles *role;
1644 enum qeth_sbp_states *state;
1645 } qports;
1646 } data;
1647};
1648
1649/**
1650 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1651 * @card: qeth_card structure pointer, for debug messages.
1652 * @cbctl: state structure with hardware return codes.
1653 * @setcmd: IPA command code
1654 *
1655 * Returns negative errno-compatible error indication or 0 on success.
1656 */
1657static int qeth_bridgeport_makerc(struct qeth_card *card,
1658 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1659{
1660 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001661 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001662
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001663 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1664 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001665 switch (cbctl->cmd_rc) {
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001666 case IPA_RC_SUCCESS:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001667 rc = 0;
1668 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001669 case IPA_RC_L2_UNSUPPORTED_CMD:
1670 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001671 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001672 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001673 case IPA_RC_SBP_OSA_NOT_CONFIGURED:
1674 case IPA_RC_SBP_IQD_NOT_CONFIGURED:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001675 rc = -ENODEV; /* maybe not the best code here? */
1676 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001677 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001678 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001679 case IPA_RC_SBP_OSA_OS_MISMATCH:
1680 case IPA_RC_SBP_IQD_OS_MISMATCH:
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001681 rc = -EPERM;
1682 dev_err(&card->gdev->dev,
1683 "A Bridge Port is already configured by a different operating system\n");
1684 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001685 case IPA_RC_SBP_OSA_ANO_DEV_PRIMARY:
1686 case IPA_RC_SBP_IQD_ANO_DEV_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001687 switch (setcmd) {
1688 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1689 rc = -EEXIST;
1690 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001691 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001692 break;
1693 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1694 rc = -EBUSY;
1695 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001696 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001697 break;
1698 default:
1699 rc = -EIO;
1700 }
1701 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001702 case IPA_RC_SBP_OSA_CURRENT_SECOND:
1703 case IPA_RC_SBP_IQD_CURRENT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001704 rc = -EBUSY;
1705 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001706 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001707 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001708 case IPA_RC_SBP_OSA_LIMIT_SECOND:
1709 case IPA_RC_SBP_IQD_LIMIT_SECOND:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001710 rc = -EEXIST;
1711 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001712 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001713 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001714 case IPA_RC_SBP_OSA_CURRENT_PRIMARY:
1715 case IPA_RC_SBP_IQD_CURRENT_PRIMARY:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001716 rc = -EBUSY;
1717 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001718 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001719 break;
Kittipon Meesompop2063a5f2017-06-20 16:00:31 +02001720 case IPA_RC_SBP_OSA_NOT_AUTHD_BY_ZMAN:
1721 case IPA_RC_SBP_IQD_NOT_AUTHD_BY_ZMAN:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001722 rc = -EACCES;
1723 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001724 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001725 break;
1726 default:
1727 rc = -EIO;
1728 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001729 else
1730 switch (cbctl->ipa_rc) {
1731 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001732 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001733 break;
1734 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001735 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001736 break;
1737 default:
1738 rc = -EIO;
1739 }
1740
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001741 if (rc) {
1742 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1743 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1744 }
1745 return rc;
1746}
1747
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001748static struct qeth_cmd_buffer *qeth_sbp_build_cmd(struct qeth_card *card,
1749 enum qeth_ipa_sbp_cmd sbp_cmd,
1750 unsigned int cmd_length)
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001751{
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001752 enum qeth_ipa_cmds ipa_cmd = (card->info.type == QETH_CARD_TYPE_IQD) ?
1753 IPA_CMD_SETBRIDGEPORT_IQD :
1754 IPA_CMD_SETBRIDGEPORT_OSA;
1755 struct qeth_cmd_buffer *iob;
1756 struct qeth_ipa_cmd *cmd;
1757
1758 iob = qeth_get_ipacmd_buffer(card, ipa_cmd, 0);
1759 if (!iob)
1760 return iob;
1761 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1762 cmd->data.sbp.hdr.cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1763 cmd_length;
1764 cmd->data.sbp.hdr.command_code = sbp_cmd;
1765 cmd->data.sbp.hdr.used_total = 1;
1766 cmd->data.sbp.hdr.seq_no = 1;
1767 return iob;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001768}
1769
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001770static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1771 struct qeth_reply *reply, unsigned long data)
1772{
1773 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1774 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1775 QETH_CARD_TEXT(card, 2, "brqsupcb");
1776 cbctl->ipa_rc = cmd->hdr.return_code;
1777 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1778 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1779 cbctl->data.supported =
1780 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1781 } else {
1782 cbctl->data.supported = 0;
1783 }
1784 return 0;
1785}
1786
1787/**
1788 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1789 * @card: qeth_card structure pointer.
1790 *
1791 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1792 * strucutre: card->options.sbp.supported_funcs.
1793 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001794static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001795{
1796 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001797 struct _qeth_sbp_cbctl cbctl;
1798
1799 QETH_CARD_TEXT(card, 2, "brqsuppo");
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001800 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_COMMANDS_SUPPORTED,
1801 sizeof(struct qeth_sbp_query_cmds_supp));
Thomas Richter1aec42b2015-01-21 13:39:10 +01001802 if (!iob)
1803 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001804 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1805 (void *)&cbctl) ||
1806 qeth_bridgeport_makerc(card, &cbctl,
1807 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1808 /* non-zero makerc signifies failure, and produce messages */
1809 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1810 return;
1811 }
1812 card->options.sbp.supported_funcs = cbctl.data.supported;
1813}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001814
1815static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1816 struct qeth_reply *reply, unsigned long data)
1817{
1818 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1819 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1820 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1821
1822 QETH_CARD_TEXT(card, 2, "brqprtcb");
1823 cbctl->ipa_rc = cmd->hdr.return_code;
1824 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1825 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1826 return 0;
1827 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1828 cbctl->cmd_rc = 0xffff;
1829 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1830 return 0;
1831 }
1832 /* first entry contains the state of the local port */
1833 if (qports->num_entries > 0) {
1834 if (cbctl->data.qports.role)
1835 *cbctl->data.qports.role = qports->entry[0].role;
1836 if (cbctl->data.qports.state)
1837 *cbctl->data.qports.state = qports->entry[0].state;
1838 }
1839 return 0;
1840}
1841
1842/**
1843 * qeth_bridgeport_query_ports() - query local bridgeport status.
1844 * @card: qeth_card structure pointer.
1845 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1846 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1847 *
1848 * Returns negative errno-compatible error indication or 0 on success.
1849 *
1850 * 'role' and 'state' are not updated in case of hardware operation failure.
1851 */
1852int qeth_bridgeport_query_ports(struct qeth_card *card,
1853 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1854{
1855 int rc = 0;
1856 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001857 struct _qeth_sbp_cbctl cbctl = {
1858 .data = {
1859 .qports = {
1860 .role = role,
1861 .state = state,
1862 },
1863 },
1864 };
1865
1866 QETH_CARD_TEXT(card, 2, "brqports");
1867 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1868 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001869 iob = qeth_sbp_build_cmd(card, IPA_SBP_QUERY_BRIDGE_PORTS, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001870 if (!iob)
1871 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001872 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1873 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001874 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001875 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001876 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001877}
1878EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1879
1880static int qeth_bridgeport_set_cb(struct qeth_card *card,
1881 struct qeth_reply *reply, unsigned long data)
1882{
1883 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1884 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1885 QETH_CARD_TEXT(card, 2, "brsetrcb");
1886 cbctl->ipa_rc = cmd->hdr.return_code;
1887 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1888 return 0;
1889}
1890
1891/**
1892 * qeth_bridgeport_setrole() - Assign primary role to the port.
1893 * @card: qeth_card structure pointer.
1894 * @role: Role to assign.
1895 *
1896 * Returns negative errno-compatible error indication or 0 on success.
1897 */
1898int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1899{
1900 int rc = 0;
1901 int cmdlength;
1902 struct qeth_cmd_buffer *iob;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001903 struct _qeth_sbp_cbctl cbctl;
1904 enum qeth_ipa_sbp_cmd setcmd;
1905
1906 QETH_CARD_TEXT(card, 2, "brsetrol");
1907 switch (role) {
1908 case QETH_SBP_ROLE_NONE:
1909 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001910 cmdlength = sizeof(struct qeth_sbp_reset_role);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001911 break;
1912 case QETH_SBP_ROLE_PRIMARY:
1913 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001914 cmdlength = sizeof(struct qeth_sbp_set_primary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001915 break;
1916 case QETH_SBP_ROLE_SECONDARY:
1917 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001918 cmdlength = sizeof(struct qeth_sbp_set_secondary);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001919 break;
1920 default:
1921 return -EINVAL;
1922 }
1923 if (!(card->options.sbp.supported_funcs & setcmd))
1924 return -EOPNOTSUPP;
Julian Wiedmannd65626a2017-08-15 17:02:47 +02001925 iob = qeth_sbp_build_cmd(card, setcmd, cmdlength);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001926 if (!iob)
1927 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001928 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1929 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001930 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001931 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001932 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001933}
1934
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001935/**
1936 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1937 * @card: qeth_card structure pointer, for debug messages.
1938 *
1939 * Returns negative errno-compatible error indication or 0 on success.
1940 */
1941static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1942{
1943 int rc;
1944
1945 if (pnso_rc == 0)
1946 switch (response) {
1947 case 0x0001:
1948 rc = 0;
1949 break;
1950 case 0x0004:
1951 case 0x0100:
1952 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001953 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001954 dev_err(&card->gdev->dev,
1955 "Setting address notification failed\n");
1956 break;
1957 case 0x0107:
1958 rc = -EAGAIN;
1959 break;
1960 default:
1961 rc = -EIO;
1962 }
1963 else
1964 rc = -EIO;
1965
1966 if (rc) {
1967 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1968 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1969 }
1970 return rc;
1971}
1972
1973static void qeth_bridgeport_an_set_cb(void *priv,
1974 enum qdio_brinfo_entry_type type, void *entry)
1975{
1976 struct qeth_card *card = (struct qeth_card *)priv;
1977 struct qdio_brinfo_entry_l2 *l2entry;
1978 u8 code;
1979
1980 if (type != l2_addr_lnid) {
1981 WARN_ON_ONCE(1);
1982 return;
1983 }
1984
1985 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1986 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1987 if (l2entry->addr_lnid.lnid)
1988 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1989 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1990 (struct net_if_token *)&l2entry->nit,
1991 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1992}
1993
1994/**
1995 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1996 * @card: qeth_card structure pointer.
1997 * @enable: 0 - disable, non-zero - enable notifications
1998 *
1999 * Returns negative errno-compatible error indication or 0 on success.
2000 *
2001 * On enable, emits a series of address notifications udev events for all
2002 * currently registered hosts.
2003 */
2004int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2005{
2006 int rc;
2007 u16 response;
2008 struct ccw_device *ddev;
2009 struct subchannel_id schid;
2010
2011 if (!card)
2012 return -EINVAL;
2013 if (!card->options.sbp.supported_funcs)
2014 return -EOPNOTSUPP;
2015 ddev = CARD_DDEV(card);
2016 ccw_device_get_schid(ddev, &schid);
2017
2018 if (enable) {
2019 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2020 rc = qdio_pnso_brinfo(schid, 1, &response,
2021 qeth_bridgeport_an_set_cb, card);
2022 } else
2023 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2024 return qeth_anset_makerc(card, rc, response);
2025}
2026EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2027
Frank Blaschka4a71df52008-02-15 09:19:42 +01002028module_init(qeth_l2_init);
2029module_exit(qeth_l2_exit);
2030MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2031MODULE_DESCRIPTION("qeth layer 2 discipline");
2032MODULE_LICENSE("GPL");