blob: 70b633f951ead40700fd67dd01f392927c0155ab [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>
Frank Blaschka4a71df52008-02-15 09:19:42 +010024#include "qeth_core.h"
Eugene Crosserb4d72c02014-01-14 15:54:11 +010025#include "qeth_l2.h"
Frank Blaschka4a71df52008-02-15 09:19:42 +010026
Frank Blaschka4a71df52008-02-15 09:19:42 +010027static int qeth_l2_set_offline(struct ccwgroup_device *);
28static int qeth_l2_stop(struct net_device *);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020029static void qeth_l2_set_rx_mode(struct net_device *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010030static void qeth_bridgeport_query_support(struct qeth_card *card);
31static void qeth_bridge_state_change(struct qeth_card *card,
32 struct qeth_ipa_cmd *cmd);
33static void qeth_bridge_host_event(struct qeth_card *card,
34 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010035
Frank Blaschka4a71df52008-02-15 09:19:42 +010036static int qeth_l2_verify_dev(struct net_device *dev)
37{
38 struct qeth_card *card;
39 unsigned long flags;
40 int rc = 0;
41
42 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
43 list_for_each_entry(card, &qeth_core_card_list.list, list) {
44 if (card->dev == dev) {
45 rc = QETH_REAL_CARD;
46 break;
47 }
48 }
49 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
50
51 return rc;
52}
53
54static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
55{
56 struct qeth_card *card;
57 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020058 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +010059 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +020060 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +010061
62 ndev = NULL;
63 memcpy(&temp_dev_no, read_dev_no, 2);
64 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
65 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +020066 ccw_device_get_id(CARD_RDEV(card), &read_devid);
67 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +010068 ndev = card->dev;
69 break;
70 }
71 }
72 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
73 return ndev;
74}
75
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010076static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +010077{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010078 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +010079
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010080 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +010081 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010082 switch (retcode) {
83 case IPA_RC_SUCCESS:
84 rc = 0;
85 break;
86 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +020087 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010088 break;
89 case IPA_RC_L2_ADDR_TABLE_FULL:
90 rc = -ENOSPC;
91 break;
92 case IPA_RC_L2_DUP_MAC:
93 case IPA_RC_L2_DUP_LAYER3_MAC:
94 rc = -EEXIST;
95 break;
96 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
97 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
98 rc = -EPERM;
99 break;
100 case IPA_RC_L2_MAC_NOT_FOUND:
101 rc = -ENOENT;
102 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100103 case -ENOMEM:
104 rc = -ENOMEM;
105 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100106 default:
107 rc = -EIO;
108 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100109 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100110 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100111}
112
Julian Wiedmannac988d72017-01-12 15:48:41 +0100113static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
114 enum qeth_ipa_cmds ipacmd)
115{
116 struct qeth_ipa_cmd *cmd;
117 struct qeth_cmd_buffer *iob;
118
119 QETH_CARD_TEXT(card, 2, "L2sdmac");
120 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
121 if (!iob)
122 return -ENOMEM;
123 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
124 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
125 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
126 return qeth_setdel_makerc(card, qeth_send_ipa_cmd(card, iob,
127 NULL, NULL));
128}
129
130static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
131{
132 int rc;
133
134 QETH_CARD_TEXT(card, 2, "L2Setmac");
135 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC);
136 if (rc == 0) {
137 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
138 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
139 dev_info(&card->gdev->dev,
140 "MAC address %pM successfully registered on device %s\n",
141 card->dev->dev_addr, card->dev->name);
142 } else {
143 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
144 switch (rc) {
145 case -EEXIST:
146 dev_warn(&card->gdev->dev,
147 "MAC address %pM already exists\n", mac);
148 break;
149 case -EPERM:
150 dev_warn(&card->gdev->dev,
151 "MAC address %pM is not authorized\n", mac);
152 break;
153 }
154 }
155 return rc;
156}
157
158static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
159{
160 int rc;
161
162 QETH_CARD_TEXT(card, 2, "L2Delmac");
163 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
164 return 0;
165 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC);
166 if (rc == 0)
167 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
168 return rc;
169}
170
Frank Blaschka4a71df52008-02-15 09:19:42 +0100171static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
172{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100173 int rc;
174
Carsten Otte847a50f2010-06-21 22:57:05 +0000175 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100176 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100177 if (rc == -EEXIST)
178 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
179 mac, QETH_CARD_IFNAME(card));
180 else if (rc)
181 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
182 mac, QETH_CARD_IFNAME(card), rc);
183 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100184}
185
186static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
187{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100188 int rc;
189
Carsten Otte847a50f2010-06-21 22:57:05 +0000190 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100191 rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100192 if (rc)
193 QETH_DBF_MESSAGE(2,
194 "Could not delete group MAC %pM on %s: %d\n",
195 mac, QETH_CARD_IFNAME(card), rc);
196 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100197}
198
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200199static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100200{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200201 if (mac->is_uc) {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100202 return qeth_l2_send_setdelmac(card, mac->mac_addr,
Julian Wiedmann754e0b82017-01-12 15:48:39 +0100203 IPA_CMD_SETVMAC);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200204 } else {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100205 return qeth_l2_send_setgroupmac(card, mac->mac_addr);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200206 }
Julian Wiedmann979d7922017-01-12 15:48:40 +0100207}
208
209static int qeth_l2_remove_mac(struct qeth_card *card, struct qeth_mac *mac)
210{
211 if (mac->is_uc) {
212 return qeth_l2_send_setdelmac(card, mac->mac_addr,
213 IPA_CMD_DELVMAC);
214 } else {
215 return qeth_l2_send_delgroupmac(card, mac->mac_addr);
216 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200217}
218
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100219static void qeth_l2_del_all_macs(struct qeth_card *card)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200220{
221 struct qeth_mac *mac;
222 struct hlist_node *tmp;
223 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100224
225 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200226 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200227 hash_del(&mac->hnode);
228 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100229 }
230 spin_unlock_bh(&card->mclock);
231}
232
Julian Wiedmannac988d72017-01-12 15:48:41 +0100233static inline u32 qeth_l2_mac_hash(const u8 *addr)
234{
235 return get_unaligned((u32 *)(&addr[2]));
236}
237
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000238static inline int qeth_l2_get_cast_type(struct qeth_card *card,
239 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100240{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000241 if (card->info.type == QETH_CARD_TYPE_OSN)
242 return RTN_UNSPEC;
243 if (is_broadcast_ether_addr(skb->data))
244 return RTN_BROADCAST;
245 if (is_multicast_ether_addr(skb->data))
246 return RTN_MULTICAST;
247 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100248}
249
Thomas Richter4d7def22015-09-18 16:06:51 +0200250static inline void qeth_l2_hdr_csum(struct qeth_card *card,
251 struct qeth_hdr *hdr, struct sk_buff *skb)
252{
253 struct iphdr *iph = ip_hdr(skb);
254
255 /* tcph->check contains already the pseudo hdr checksum
256 * so just set the header flags
257 */
258 if (iph->protocol == IPPROTO_UDP)
259 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
260 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
261 QETH_HDR_EXT_CSUM_HDR_REQ;
262 iph->check = 0;
263 if (card->options.performance_stats)
264 card->perf_stats.tx_csum++;
265}
266
Frank Blaschka4a71df52008-02-15 09:19:42 +0100267static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Stefan Raspl43934072014-03-19 07:58:01 +0100268 struct sk_buff *skb, int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269{
Frank Blaschka683d7182008-08-01 16:39:13 +0200270 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271
272 memset(hdr, 0, sizeof(struct qeth_hdr));
273 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
274
275 /* set byte byte 3 to casting flags */
276 if (cast_type == RTN_MULTICAST)
277 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
278 else if (cast_type == RTN_BROADCAST)
279 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
280 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000281 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100282
Julian Wiedmann2aedd562017-04-11 16:11:15 +0200283 hdr->hdr.l2.pkt_length = skb->len - sizeof(struct qeth_hdr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284 /* VSWITCH relies on the VLAN
285 * information to be present in
286 * the QDIO header */
287 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
288 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
289 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
290 }
291}
292
293static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
294 struct qeth_reply *reply, unsigned long data)
295{
296 struct qeth_ipa_cmd *cmd;
297
Carsten Otte847a50f2010-06-21 22:57:05 +0000298 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100299 cmd = (struct qeth_ipa_cmd *) data;
300 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200301 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100302 "Continuing\n", cmd->data.setdelvlan.vlan_id,
303 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000304 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
305 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100306 }
307 return 0;
308}
309
310static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
311 enum qeth_ipa_cmds ipacmd)
312{
313 struct qeth_ipa_cmd *cmd;
314 struct qeth_cmd_buffer *iob;
315
Carsten Otte847a50f2010-06-21 22:57:05 +0000316 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100317 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100318 if (!iob)
319 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100320 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
321 cmd->data.setdelvlan.vlan_id = i;
322 return qeth_send_ipa_cmd(card, iob,
323 qeth_l2_send_setdelvlan_cb, NULL);
324}
325
Ursula Braun70919e22011-02-26 22:41:36 -0800326static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100327{
328 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000329 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100330 spin_lock_bh(&card->vlanlock);
331 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800332 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100333 }
334 spin_unlock_bh(&card->vlanlock);
335}
336
Patrick McHardy80d5c362013-04-19 02:04:28 +0000337static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
338 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100339{
Heiko Carstens509e2562008-07-26 02:24:10 -0700340 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100341 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100342 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343
Carsten Otte847a50f2010-06-21 22:57:05 +0000344 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000345 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500346 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000347 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000348 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500349 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000350 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000351 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000352 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500353 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000354 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100355 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
356 if (id) {
357 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100358 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
359 if (rc) {
360 kfree(id);
361 return rc;
362 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100363 spin_lock_bh(&card->vlanlock);
364 list_add_tail(&id->list, &card->vid_list);
365 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500366 } else {
367 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100368 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500369 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100370}
371
Patrick McHardy80d5c362013-04-19 02:04:28 +0000372static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
373 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100374{
375 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700376 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100377 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100378
Carsten Otte847a50f2010-06-21 22:57:05 +0000379 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000380 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000381 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500382 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000383 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000384 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000385 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500386 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000387 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100388 spin_lock_bh(&card->vlanlock);
389 list_for_each_entry(id, &card->vid_list, list) {
390 if (id->vid == vid) {
391 list_del(&id->list);
392 tmpid = id;
393 break;
394 }
395 }
396 spin_unlock_bh(&card->vlanlock);
397 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100398 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100399 kfree(tmpid);
400 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200401 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100402 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100403}
404
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200405static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100406{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200407 QETH_DBF_TEXT(SETUP , 2, "stopcard");
408 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100409
410 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100411 if (card->read.state == CH_STATE_UP &&
412 card->write.state == CH_STATE_UP &&
413 (card->state == CARD_STATE_UP)) {
414 if (recovery_mode &&
415 card->info.type != QETH_CARD_TYPE_OSN) {
416 qeth_l2_stop(card->dev);
417 } else {
418 rtnl_lock();
419 dev_close(card->dev);
420 rtnl_unlock();
421 }
Ursula Braun70919e22011-02-26 22:41:36 -0800422 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100423 card->state = CARD_STATE_SOFTSETUP;
424 }
425 if (card->state == CARD_STATE_SOFTSETUP) {
Julian Wiedmannc07cbf22017-01-12 15:48:37 +0100426 qeth_l2_del_all_macs(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100427 qeth_clear_ipacmd_list(card);
428 card->state = CARD_STATE_HARDSETUP;
429 }
430 if (card->state == CARD_STATE_HARDSETUP) {
431 qeth_qdio_clear_card(card, 0);
432 qeth_clear_qdio_buffers(card);
433 qeth_clear_working_pool_list(card);
434 card->state = CARD_STATE_DOWN;
435 }
436 if (card->state == CARD_STATE_DOWN) {
437 qeth_clear_cmd_buffers(&card->read);
438 qeth_clear_cmd_buffers(&card->write);
439 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440}
441
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000442static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
443 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100444{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000445 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 struct sk_buff *skb;
447 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100448 unsigned int len;
449
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000450 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000451 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000452 while (budget) {
453 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000454 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000455 &card->rx.b_element, &card->rx.e_offset, &hdr);
456 if (!skb) {
457 *done = 1;
458 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100459 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000460 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 switch (hdr->hdr.l2.id) {
462 case QETH_HEADER_TYPE_LAYER2:
463 skb->pkt_type = PACKET_HOST;
464 skb->protocol = eth_type_trans(skb, skb->dev);
Thomas Richter4d7def22015-09-18 16:06:51 +0200465 if ((card->dev->features & NETIF_F_RXCSUM)
466 && ((hdr->hdr.l2.flags[1] &
467 (QETH_HDR_EXT_CSUM_HDR_REQ |
468 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
469 (QETH_HDR_EXT_CSUM_HDR_REQ |
470 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
471 skb->ip_summed = CHECKSUM_UNNECESSARY;
472 else
473 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200474 if (skb->protocol == htons(ETH_P_802_2))
475 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100476 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200477 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478 break;
479 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200480 if (card->info.type == QETH_CARD_TYPE_OSN) {
481 skb_push(skb, sizeof(struct qeth_hdr));
482 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100483 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200484 len = skb->len;
485 card->osn_info.data_cb(skb);
486 break;
487 }
488 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100489 default:
490 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000491 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200492 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 continue;
494 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000495 work_done++;
496 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100497 card->stats.rx_packets++;
498 card->stats.rx_bytes += len;
499 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000500 return work_done;
501}
502
Frank Blaschka4a71df52008-02-15 09:19:42 +0100503static int qeth_l2_request_initial_mac(struct qeth_card *card)
504{
505 int rc = 0;
506 char vendor_pre[] = {0x02, 0x00, 0x00};
507
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200508 QETH_DBF_TEXT(SETUP, 2, "doL2init");
509 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100510
Stefan Raspla1348842012-11-12 23:05:16 +0000511 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
512 rc = qeth_query_setadapterparms(card);
513 if (rc) {
514 QETH_DBF_MESSAGE(2, "could not query adapter "
515 "parameters on device %s: x%x\n",
516 CARD_BUS_ID(card), rc);
517 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100518 }
519
Ursula Braun5113fec2010-05-16 21:15:14 +0000520 if (card->info.type == QETH_CARD_TYPE_IQD ||
521 card->info.type == QETH_CARD_TYPE_OSM ||
522 card->info.type == QETH_CARD_TYPE_OSX ||
523 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100524 rc = qeth_setadpparms_change_macaddr(card);
525 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200526 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
527 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100528 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100529 return rc;
530 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200531 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100532 } else {
Joe Perches18336112012-07-12 22:33:10 -0700533 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100534 memcpy(card->dev->dev_addr, vendor_pre, 3);
535 }
536 return 0;
537}
538
539static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
540{
541 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700542 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100543 int rc = 0;
544
Carsten Otte847a50f2010-06-21 22:57:05 +0000545 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100546
547 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000548 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100549 return -EOPNOTSUPP;
550 }
551
Ursula Braun5113fec2010-05-16 21:15:14 +0000552 if (card->info.type == QETH_CARD_TYPE_OSN ||
553 card->info.type == QETH_CARD_TYPE_OSM ||
554 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000555 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100556 return -EOPNOTSUPP;
557 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000558 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000559 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000560 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000561 return -ERESTARTSYS;
562 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100563 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100564 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100565 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000566 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100567}
568
Eugene Crosser0db587b2015-05-18 14:27:55 +0200569static void qeth_promisc_to_bridge(struct qeth_card *card)
570{
571 struct net_device *dev = card->dev;
572 enum qeth_ipa_promisc_modes promisc_mode;
573 int role;
574 int rc;
575
576 QETH_CARD_TEXT(card, 3, "pmisc2br");
577
578 if (!card->options.sbp.reflect_promisc)
579 return;
580 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
581 : SET_PROMISC_MODE_OFF;
582 if (promisc_mode == card->info.promisc_mode)
583 return;
584
585 if (promisc_mode == SET_PROMISC_MODE_ON) {
586 if (card->options.sbp.reflect_promisc_primary)
587 role = QETH_SBP_ROLE_PRIMARY;
588 else
589 role = QETH_SBP_ROLE_SECONDARY;
590 } else
591 role = QETH_SBP_ROLE_NONE;
592
593 rc = qeth_bridgeport_setrole(card, role);
594 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
595 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
596 if (!rc) {
597 card->options.sbp.role = role;
598 card->info.promisc_mode = promisc_mode;
599 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200600
601}
602/* New MAC address is added to the hash table and marked to be written on card
603 * only if there is not in the hash table storage already
604 *
605*/
606static void
607qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha, u8 is_uc)
608{
609 struct qeth_mac *mac;
610
611 hash_for_each_possible(card->mac_htable, mac, hnode,
612 qeth_l2_mac_hash(ha->addr)) {
613 if (is_uc == mac->is_uc &&
614 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200615 mac->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200616 return;
617 }
618 }
619
620 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
621
622 if (!mac)
623 return;
624
625 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
626 mac->is_uc = is_uc;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200627 mac->disp_flag = QETH_DISP_ADDR_ADD;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200628
629 hash_add(card->mac_htable, &mac->hnode,
630 qeth_l2_mac_hash(mac->mac_addr));
631
Eugene Crosser0db587b2015-05-18 14:27:55 +0200632}
633
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200634static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100635{
Heiko Carstens509e2562008-07-26 02:24:10 -0700636 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000637 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200638 struct qeth_mac *mac;
639 struct hlist_node *tmp;
640 int i;
641 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100642
643 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200644 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645
Carsten Otte847a50f2010-06-21 22:57:05 +0000646 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000647 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
648 (card->state != CARD_STATE_UP))
649 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200650
Frank Blaschka4a71df52008-02-15 09:19:42 +0100651 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200652
Jiri Pirko22bedad32010-04-01 21:22:57 +0000653 netdev_for_each_mc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200654 qeth_l2_add_mac(card, ha, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200655
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800656 netdev_for_each_uc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200657 qeth_l2_add_mac(card, ha, 1);
658
659 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200660 if (mac->disp_flag == QETH_DISP_ADDR_DELETE) {
Julian Wiedmann979d7922017-01-12 15:48:40 +0100661 qeth_l2_remove_mac(card, mac);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200662 hash_del(&mac->hnode);
663 kfree(mac);
664
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200665 } else if (mac->disp_flag == QETH_DISP_ADDR_ADD) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200666 rc = qeth_l2_write_mac(card, mac);
667 if (rc) {
668 hash_del(&mac->hnode);
669 kfree(mac);
670 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200671 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200672 } else
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200673 mac->disp_flag = QETH_DISP_ADDR_DELETE;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200674 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200675
Frank Blaschka4a71df52008-02-15 09:19:42 +0100676 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200677
Eugene Crosser0db587b2015-05-18 14:27:55 +0200678 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
679 qeth_setadp_promisc_mode(card);
680 else
681 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100682}
683
Julian Wiedmanne38db6b2017-04-11 16:11:14 +0200684static netdev_tx_t qeth_l2_hard_start_xmit(struct sk_buff *skb,
685 struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686{
687 int rc;
688 struct qeth_hdr *hdr = NULL;
689 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700690 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100691 struct sk_buff *new_skb = skb;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000692 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200693 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100694 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200695 int data_offset = -1;
696 int elements_needed = 0;
697 int hd_len = 0;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200698 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100699
Stefan Raspl290b8342014-04-28 10:05:08 +0200700 if (card->qdio.do_prio_queueing || (cast_type &&
701 card->info.is_multicast_different))
702 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
703 qeth_get_ip_version(skb), cast_type)];
704 else
705 queue = card->qdio.out_qs[card->qdio.default_out_queue];
706
Frank Blaschka4a71df52008-02-15 09:19:42 +0100707 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
708 card->stats.tx_carrier_errors++;
709 goto tx_drop;
710 }
711
712 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
713 (skb->protocol == htons(ETH_P_IPV6)))
714 goto tx_drop;
715
716 if (card->options.performance_stats) {
717 card->perf_stats.outbound_cnt++;
718 card->perf_stats.outbound_start_time = qeth_get_micros();
719 }
720 netif_stop_queue(dev);
721
Eugene Crosserd52aec92016-06-16 16:18:55 +0200722 /* fix hardware limitation: as long as we do not have sbal
723 * chaining we can not send long frag lists
724 */
725 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
Julian Wiedmann7d969d22017-03-23 14:55:08 +0100726 !qeth_get_elements_no(card, new_skb, 0, 0)) {
Eugene Crosser6059c902016-06-16 16:18:57 +0200727 int lin_rc = skb_linearize(new_skb);
728
729 if (card->options.performance_stats) {
730 if (lin_rc)
731 card->perf_stats.tx_linfail++;
732 else
733 card->perf_stats.tx_lin++;
734 }
735 if (lin_rc)
Eugene Crosserd52aec92016-06-16 16:18:55 +0200736 goto tx_drop;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200737 }
738
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739 if (card->info.type == QETH_CARD_TYPE_OSN)
740 hdr = (struct qeth_hdr *)skb->data;
741 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000742 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200743 new_skb = skb;
744 data_offset = ETH_HLEN;
745 hd_len = ETH_HLEN;
746 hdr = kmem_cache_alloc(qeth_core_header_cache,
747 GFP_ATOMIC);
748 if (!hdr)
749 goto tx_drop;
750 elements_needed++;
751 skb_reset_mac_header(new_skb);
Stefan Raspl43934072014-03-19 07:58:01 +0100752 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200753 hdr->hdr.l2.pkt_length = new_skb->len;
754 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
755 skb_mac_header(new_skb), ETH_HLEN);
756 } else {
757 /* create a clone with writeable headroom */
758 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200759 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200760 if (!new_skb)
761 goto tx_drop;
762 hdr = (struct qeth_hdr *)skb_push(new_skb,
763 sizeof(struct qeth_hdr));
764 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
Stefan Raspl43934072014-03-19 07:58:01 +0100765 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Thomas Richter4d7def22015-09-18 16:06:51 +0200766 if (new_skb->ip_summed == CHECKSUM_PARTIAL)
767 qeth_l2_hdr_csum(card, hdr, new_skb);
Frank Blaschka683d7182008-08-01 16:39:13 +0200768 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769 }
770
Julian Wiedmann7d969d22017-03-23 14:55:08 +0100771 elements = qeth_get_elements_no(card, new_skb, elements_needed,
772 (data_offset > 0) ? data_offset : 0);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000773 if (!elements) {
774 if (data_offset >= 0)
775 kmem_cache_free(qeth_core_header_cache, hdr);
776 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000777 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100778
Frank Blaschka51aa1652010-06-21 22:57:10 +0000779 if (card->info.type != QETH_CARD_TYPE_IQD) {
Stefan Raspld4ae1f52013-04-22 01:12:29 +0000780 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
Frank Blaschka51aa1652010-06-21 22:57:10 +0000781 sizeof(struct qeth_hdr_layer2)))
782 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100783 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000784 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000785 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100786 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Julian Wiedmann4e8d7e62017-04-11 16:11:13 +0200787 data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100788 if (!rc) {
789 card->stats.tx_packets++;
790 card->stats.tx_bytes += tx_bytes;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200791 if (card->options.performance_stats) {
792 nr_frags = skb_shinfo(new_skb)->nr_frags;
793 if (nr_frags) {
794 card->perf_stats.sg_skbs_sent++;
795 /* nr_frags + skb->data */
796 card->perf_stats.sg_frags_sent += nr_frags + 1;
797 }
798 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100799 if (new_skb != skb)
800 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700801 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100802 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200803 if (data_offset >= 0)
804 kmem_cache_free(qeth_core_header_cache, hdr);
805
Frank Blaschka4a71df52008-02-15 09:19:42 +0100806 if (rc == -EBUSY) {
807 if (new_skb != skb)
808 dev_kfree_skb_any(new_skb);
809 return NETDEV_TX_BUSY;
810 } else
811 goto tx_drop;
812 }
813
814 netif_wake_queue(dev);
815 if (card->options.performance_stats)
816 card->perf_stats.outbound_time += qeth_get_micros() -
817 card->perf_stats.outbound_start_time;
818 return rc;
819
820tx_drop:
821 card->stats.tx_dropped++;
822 card->stats.tx_errors++;
823 if ((new_skb != skb) && new_skb)
824 dev_kfree_skb_any(new_skb);
825 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200826 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100827 return NETDEV_TX_OK;
828}
829
Ursula Braun39423442011-01-12 20:42:24 +0000830static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100831{
Heiko Carstens509e2562008-07-26 02:24:10 -0700832 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000833 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100834
Carsten Otte847a50f2010-06-21 22:57:05 +0000835 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +0000836 if (card->state == CARD_STATE_UP)
837 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100838 if (card->state != CARD_STATE_SOFTSETUP)
839 return -ENODEV;
840
841 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
842 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000843 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100844 return -EPERM;
845 }
846 card->data.state = CH_STATE_UP;
847 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100848 netif_start_queue(dev);
849
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000850 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
851 napi_enable(&card->napi);
852 napi_schedule(&card->napi);
853 } else
854 rc = -EIO;
855 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100856}
857
Ursula Braun39423442011-01-12 20:42:24 +0000858static int qeth_l2_open(struct net_device *dev)
859{
860 struct qeth_card *card = dev->ml_priv;
861
862 QETH_CARD_TEXT(card, 5, "qethope_");
863 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
864 QETH_CARD_TEXT(card, 3, "openREC");
865 return -ERESTARTSYS;
866 }
867 return __qeth_l2_open(dev);
868}
869
Frank Blaschka4a71df52008-02-15 09:19:42 +0100870static int qeth_l2_stop(struct net_device *dev)
871{
Heiko Carstens509e2562008-07-26 02:24:10 -0700872 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873
Carsten Otte847a50f2010-06-21 22:57:05 +0000874 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100875 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000876 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100877 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000878 napi_disable(&card->napi);
879 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880 return 0;
881}
882
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200883static const struct device_type qeth_l2_devtype = {
884 .name = "qeth_layer2",
885 .groups = qeth_l2_attr_groups,
886};
887
Frank Blaschka4a71df52008-02-15 09:19:42 +0100888static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
889{
890 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +0200891 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100892
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200893 if (gdev->dev.type == &qeth_generic_devtype) {
894 rc = qeth_l2_create_device_attributes(&gdev->dev);
895 if (rc)
896 return rc;
897 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100898 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200899 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100900 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +0000901 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100902 return 0;
903}
904
905static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
906{
907 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
908
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +0200909 if (cgdev->dev.type == &qeth_generic_devtype)
910 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +0000911 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100912 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
913
Ursula Braun70919e22011-02-26 22:41:36 -0800914 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100915 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100916
917 if (card->dev) {
Ursula Braun7831b4f2016-07-04 14:07:16 +0200918 netif_napi_del(&card->napi);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100919 unregister_netdev(card->dev);
920 card->dev = NULL;
921 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100922 return;
923}
924
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700925static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100926 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 .get_strings = qeth_core_get_strings,
928 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000929 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100930 .get_drvinfo = qeth_core_get_drvinfo,
Julian Wiedmann993e19c2017-04-11 16:11:17 +0200931 .get_link_ksettings = qeth_core_ethtool_get_link_ksettings,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100932};
933
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700934static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100935 .get_strings = qeth_core_get_strings,
936 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +0000937 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100938 .get_drvinfo = qeth_core_get_drvinfo,
939};
940
Frank Blaschka3d58cef2009-01-09 03:44:00 +0000941static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -0800942 .ndo_open = qeth_l2_open,
943 .ndo_stop = qeth_l2_stop,
944 .ndo_get_stats = qeth_get_stats,
945 .ndo_start_xmit = qeth_l2_hard_start_xmit,
946 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200947 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +0200948 .ndo_do_ioctl = qeth_do_ioctl,
Frank Blaschka8403b132009-01-08 10:50:55 -0800949 .ndo_set_mac_address = qeth_l2_set_mac_address,
950 .ndo_change_mtu = qeth_change_mtu,
951 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
952 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
953 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter8f43fb02016-06-16 16:18:59 +0200954 .ndo_fix_features = qeth_fix_features,
955 .ndo_set_features = qeth_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -0800956};
957
Frank Blaschka4a71df52008-02-15 09:19:42 +0100958static int qeth_l2_setup_netdev(struct qeth_card *card)
959{
960 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +0200962 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
963 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100964 break;
965 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +0200966 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
967 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100968 break;
969 default:
970 card->dev = alloc_etherdev(0);
971 }
972
973 if (!card->dev)
974 return -ENODEV;
975
Heiko Carstens509e2562008-07-26 02:24:10 -0700976 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100977 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100978 card->dev->mtu = card->info.initial_mtu;
Jarod Wilson46b3ef42016-10-20 13:55:23 -0400979 card->dev->min_mtu = 64;
980 card->dev->max_mtu = ETH_MAX_MTU;
Frank Blaschka8403b132009-01-08 10:50:55 -0800981 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Julian Wiedmann25e2c342017-05-10 19:07:53 +0200982 if (card->info.type == QETH_CARD_TYPE_OSN) {
983 card->dev->ethtool_ops = &qeth_l2_osn_ops;
984 card->dev->flags |= IFF_NOARP;
985 } else {
986 card->dev->ethtool_ops = &qeth_l2_ethtool_ops;
987 }
Patrick McHardyf6469682013-04-19 02:04:27 +0000988 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Thomas Richter4d7def22015-09-18 16:06:51 +0200989 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200990 card->dev->hw_features = NETIF_F_SG;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200991 card->dev->vlan_features = NETIF_F_SG;
Thomas Richter8f43fb02016-06-16 16:18:59 +0200992 /* OSA 3S and earlier has no RX/TX support */
Hans Wippel9bdc4412016-06-16 16:19:00 +0200993 if (qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200994 card->dev->hw_features |= NETIF_F_IP_CSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200995 card->dev->vlan_features |= NETIF_F_IP_CSUM;
996 }
997 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +0200998 card->dev->hw_features |= NETIF_F_RXCSUM;
Hans Wippel9bdc4412016-06-16 16:19:00 +0200999 card->dev->vlan_features |= NETIF_F_RXCSUM;
1000 }
Thomas Richter4d7def22015-09-18 16:06:51 +02001001 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001002 card->info.broadcast_capable = 1;
1003 qeth_l2_request_initial_mac(card);
Eugene Crosserd52aec92016-06-16 16:18:55 +02001004 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
1005 PAGE_SIZE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001006 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001007 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01001008 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001009 return register_netdev(card->dev);
1010}
1011
Thomas Richter4d7def22015-09-18 16:06:51 +02001012static int qeth_l2_start_ipassists(struct qeth_card *card)
1013{
1014 /* configure isolation level */
1015 if (qeth_set_access_ctrl_online(card, 0))
1016 return -ENODEV;
Thomas Richter4d7def22015-09-18 16:06:51 +02001017 return 0;
1018}
1019
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001020static void qeth_l2_trace_features(struct qeth_card *card)
1021{
1022 QETH_CARD_TEXT(card, 2, "l2featur");
1023 QETH_CARD_HEX(card, 2, &card->options.sbp.supported_funcs,
1024 sizeof(card->options.sbp.supported_funcs));
1025}
1026
Frank Blaschka4a71df52008-02-15 09:19:42 +01001027static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1028{
1029 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1030 int rc = 0;
1031 enum qeth_card_states recover_flag;
1032
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001033 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001034 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001035 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1036 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001037
Frank Blaschka4a71df52008-02-15 09:19:42 +01001038 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001039 rc = qeth_core_hardsetup_card(card);
1040 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001041 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001042 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043 goto out_remove;
1044 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001045 qeth_bridgeport_query_support(card);
1046 if (card->options.sbp.supported_funcs)
1047 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001048 "The device represents a Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001049 qeth_trace_features(card);
Julian Wiedmann521c10e2017-06-06 14:33:45 +02001050 qeth_l2_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001051
Ursula Braunaa909222009-11-12 00:11:43 +00001052 if (!card->dev && qeth_l2_setup_netdev(card)) {
1053 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001054 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001055 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001056
1057 if (card->info.type != QETH_CARD_TYPE_OSN)
1058 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1059
Frank Blaschka1da74b12011-05-12 18:45:02 +00001060 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1061 if (card->info.hwtrap &&
1062 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1063 card->info.hwtrap = 0;
1064 } else
1065 card->info.hwtrap = 0;
1066
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001067 qeth_l2_setup_bridgeport_attrs(card);
1068
Frank Blaschka4a71df52008-02-15 09:19:42 +01001069 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001070 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001071 qeth_print_status_message(card);
1072
1073 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001074 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075
Ursula Braun5113fec2010-05-16 21:15:14 +00001076 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001077 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter8f43fb02016-06-16 16:18:59 +02001078 rc = qeth_l2_start_ipassists(card);
1079 if (rc)
Stefan Raspl0f547612013-01-21 02:30:20 +00001080 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001081 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001082
1083 if (card->info.type != QETH_CARD_TYPE_OSN &&
1084 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001085 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001086
1087 netif_tx_disable(card->dev);
1088
1089 rc = qeth_init_qdio_queues(card);
1090 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001091 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001092 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001093 goto out_remove;
1094 }
1095 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001096 if (card->lan_online)
1097 netif_carrier_on(card->dev);
1098 else
1099 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001100
1101 qeth_set_allowed_threads(card, 0xffffffff, 0);
1102 if (recover_flag == CARD_STATE_RECOVER) {
1103 if (recovery_mode &&
1104 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001105 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001106 } else {
1107 rtnl_lock();
1108 dev_open(card->dev);
1109 rtnl_unlock();
1110 }
1111 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001112 qeth_l2_set_rx_mode(card->dev);
Hans Wippele830baa2016-09-15 14:39:21 +02001113 rtnl_lock();
1114 qeth_recover_features(card->dev);
1115 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001116 }
1117 /* let user_space know that device is online */
1118 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001119 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001120 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001121 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001122
Frank Blaschka4a71df52008-02-15 09:19:42 +01001123out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001124 qeth_l2_stop_card(card, 0);
1125 ccw_device_set_offline(CARD_DDEV(card));
1126 ccw_device_set_offline(CARD_WDEV(card));
1127 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001128 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001129 if (recover_flag == CARD_STATE_RECOVER)
1130 card->state = CARD_STATE_RECOVER;
1131 else
1132 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001133 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001134 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001135 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001136}
1137
1138static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1139{
1140 return __qeth_l2_set_online(gdev, 0);
1141}
1142
1143static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1144 int recovery_mode)
1145{
1146 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1147 int rc = 0, rc2 = 0, rc3 = 0;
1148 enum qeth_card_states recover_flag;
1149
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001150 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001151 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001152 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1153 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154
1155 if (card->dev && netif_carrier_ok(card->dev))
1156 netif_carrier_off(card->dev);
1157 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001158 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1159 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1160 card->info.hwtrap = 1;
1161 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001162 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001163 rc = ccw_device_set_offline(CARD_DDEV(card));
1164 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1165 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1166 if (!rc)
1167 rc = (rc2) ? rc2 : rc3;
1168 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001169 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001170 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001171 if (recover_flag == CARD_STATE_UP)
1172 card->state = CARD_STATE_RECOVER;
1173 /* let user_space know that device is offline */
1174 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001175 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001176 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001177 return 0;
1178}
1179
1180static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1181{
1182 return __qeth_l2_set_offline(cgdev, 0);
1183}
1184
1185static int qeth_l2_recover(void *ptr)
1186{
1187 struct qeth_card *card;
1188 int rc = 0;
1189
1190 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001191 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001192 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1193 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001194 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001195 dev_warn(&card->gdev->dev,
1196 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001197 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001198 __qeth_l2_set_offline(card->gdev, 1);
1199 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001201 dev_info(&card->gdev->dev,
1202 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001203 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001204 qeth_close_dev(card);
1205 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001206 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001207 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001208 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001209 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1210 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001211 return 0;
1212}
1213
1214static int __init qeth_l2_init(void)
1215{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001216 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217 return 0;
1218}
1219
1220static void __exit qeth_l2_exit(void)
1221{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001222 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001223}
1224
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001225static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1226{
1227 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1228
1229 if (card->dev)
1230 netif_device_detach(card->dev);
1231 qeth_set_allowed_threads(card, 0, 1);
1232 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1233 if (gdev->state == CCWGROUP_OFFLINE)
1234 return 0;
1235 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001236 if (card->info.hwtrap)
1237 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001238 __qeth_l2_set_offline(card->gdev, 1);
1239 } else
1240 __qeth_l2_set_offline(card->gdev, 0);
1241 return 0;
1242}
1243
1244static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1245{
1246 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1247 int rc = 0;
1248
1249 if (gdev->state == CCWGROUP_OFFLINE)
1250 goto out;
1251
1252 if (card->state == CARD_STATE_RECOVER) {
1253 rc = __qeth_l2_set_online(card->gdev, 1);
1254 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001255 rtnl_lock();
1256 dev_close(card->dev);
1257 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001258 }
1259 } else
1260 rc = __qeth_l2_set_online(card->gdev, 0);
1261out:
1262 qeth_set_allowed_threads(card, 0xffffffff, 0);
1263 if (card->dev)
1264 netif_device_attach(card->dev);
1265 if (rc)
1266 dev_warn(&card->gdev->dev, "The qeth device driver "
1267 "failed to recover an error on the device\n");
1268 return rc;
1269}
1270
Eugene Crosserc044dc22014-01-29 09:23:48 +01001271/* Returns zero if the command is successfully "consumed" */
1272static int qeth_l2_control_event(struct qeth_card *card,
1273 struct qeth_ipa_cmd *cmd)
1274{
1275 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001276 case IPA_CMD_SETBRIDGEPORT_OSA:
1277 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001278 if (cmd->data.sbp.hdr.command_code ==
1279 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1280 qeth_bridge_state_change(card, cmd);
1281 return 0;
1282 } else
1283 return 1;
1284 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1285 qeth_bridge_host_event(card, cmd);
1286 return 0;
1287 default:
1288 return 1;
1289 }
1290}
1291
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001292struct qeth_discipline qeth_l2_discipline = {
Julian Wiedmann2d2ebb32017-05-10 19:07:52 +02001293 .devtype = &qeth_l2_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001294 .start_poll = qeth_qdio_start_poll,
1295 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1296 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001297 .process_rx_buffer = qeth_l2_process_inbound_buffer,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001298 .recover = qeth_l2_recover,
1299 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001300 .remove = qeth_l2_remove_device,
1301 .set_online = qeth_l2_set_online,
1302 .set_offline = qeth_l2_set_offline,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001303 .freeze = qeth_l2_pm_suspend,
1304 .thaw = qeth_l2_pm_resume,
1305 .restore = qeth_l2_pm_resume,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001306 .do_ioctl = NULL,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001307 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001308};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001309EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001310
1311static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1312 struct qeth_cmd_buffer *iob)
1313{
1314 unsigned long flags;
1315 int rc = 0;
1316
Carsten Otte847a50f2010-06-21 22:57:05 +00001317 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318
1319 wait_event(card->wait_q,
1320 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1321 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001322 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1324 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1325 (addr_t) iob, 0, 0);
1326 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1327 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001328 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001329 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001330 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001331 qeth_release_buffer(iob->channel, iob);
1332 atomic_set(&card->write.irq_pending, 0);
1333 wake_up(&card->wait_q);
1334 }
1335 return rc;
1336}
1337
1338static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1339 struct qeth_cmd_buffer *iob, int data_len)
1340{
1341 u16 s1, s2;
1342
Carsten Otte847a50f2010-06-21 22:57:05 +00001343 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001344
1345 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1346 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1347 s2 = (u16)data_len;
1348 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1349 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1350 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1351 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1352 return qeth_osn_send_control_data(card, s1, iob);
1353}
1354
1355int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1356{
1357 struct qeth_cmd_buffer *iob;
1358 struct qeth_card *card;
1359 int rc;
1360
Frank Blaschka4a71df52008-02-15 09:19:42 +01001361 if (!dev)
1362 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001363 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001364 if (!card)
1365 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001366 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001367 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001368 return -ENODEV;
1369 iob = qeth_wait_for_buffer(&card->write);
1370 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1371 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1372 return rc;
1373}
1374EXPORT_SYMBOL(qeth_osn_assist);
1375
1376int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1377 int (*assist_cb)(struct net_device *, void *),
1378 int (*data_cb)(struct sk_buff *))
1379{
1380 struct qeth_card *card;
1381
Frank Blaschka4a71df52008-02-15 09:19:42 +01001382 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1383 if (*dev == NULL)
1384 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001385 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001386 if (!card)
1387 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001388 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001389 if ((assist_cb == NULL) || (data_cb == NULL))
1390 return -EINVAL;
1391 card->osn_info.assist_cb = assist_cb;
1392 card->osn_info.data_cb = data_cb;
1393 return 0;
1394}
1395EXPORT_SYMBOL(qeth_osn_register);
1396
1397void qeth_osn_deregister(struct net_device *dev)
1398{
1399 struct qeth_card *card;
1400
Frank Blaschka4a71df52008-02-15 09:19:42 +01001401 if (!dev)
1402 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001403 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001404 if (!card)
1405 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001406 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001407 card->osn_info.assist_cb = NULL;
1408 card->osn_info.data_cb = NULL;
1409 return;
1410}
1411EXPORT_SYMBOL(qeth_osn_deregister);
1412
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001413/* SETBRIDGEPORT support, async notifications */
1414
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001415enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1416
1417/**
1418 * qeth_bridge_emit_host_event() - bridgeport address change notification
1419 * @card: qeth_card structure pointer, for udev events.
1420 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1421 * and reset token and addr_lnid are unused and may be NULL.
1422 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1423 * object, 0 - addition of an object.
1424 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1425 * @token: "network token" structure identifying physical address of the port.
1426 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1427 *
1428 * This function is called when registrations and deregistrations are
1429 * reported by the hardware, and also when notifications are enabled -
1430 * for all currently registered addresses.
1431 */
1432static void qeth_bridge_emit_host_event(struct qeth_card *card,
1433 enum qeth_an_event_type evtype,
1434 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1435{
1436 char str[7][32];
1437 char *env[8];
1438 int i = 0;
1439
1440 switch (evtype) {
1441 case anev_reg_unreg:
1442 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1443 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1444 ? "deregister" : "register");
1445 env[i] = str[i]; i++;
1446 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1447 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1448 addr_lnid->lnid);
1449 env[i] = str[i]; i++;
1450 }
1451 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001452 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001453 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001454 env[i] = str[i]; i++;
1455 }
1456 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1457 token->cssid, token->ssid, token->devnum);
1458 env[i] = str[i]; i++;
1459 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1460 env[i] = str[i]; i++;
1461 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1462 token->chpid);
1463 env[i] = str[i]; i++;
1464 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1465 env[i] = str[i]; i++;
1466 break;
1467 case anev_abort:
1468 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1469 env[i] = str[i]; i++;
1470 break;
1471 case anev_reset:
1472 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1473 env[i] = str[i]; i++;
1474 break;
1475 }
1476 env[i] = NULL;
1477 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1478}
1479
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001480struct qeth_bridge_state_data {
1481 struct work_struct worker;
1482 struct qeth_card *card;
1483 struct qeth_sbp_state_change qports;
1484};
1485
1486static void qeth_bridge_state_change_worker(struct work_struct *work)
1487{
1488 struct qeth_bridge_state_data *data =
1489 container_of(work, struct qeth_bridge_state_data, worker);
1490 /* We are only interested in the first entry - local port */
1491 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1492 char env_locrem[32];
1493 char env_role[32];
1494 char env_state[32];
1495 char *env[] = {
1496 env_locrem,
1497 env_role,
1498 env_state,
1499 NULL
1500 };
1501
1502 /* Role should not change by itself, but if it did, */
1503 /* information from the hardware is authoritative. */
1504 mutex_lock(&data->card->conf_mutex);
1505 data->card->options.sbp.role = entry->role;
1506 mutex_unlock(&data->card->conf_mutex);
1507
1508 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1509 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1510 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1511 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1512 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1513 "<INVALID>");
1514 snprintf(env_state, sizeof(env_state), "STATE=%s",
1515 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1516 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1517 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1518 "<INVALID>");
1519 kobject_uevent_env(&data->card->gdev->dev.kobj,
1520 KOBJ_CHANGE, env);
1521 kfree(data);
1522}
1523
Eugene Crosserc044dc22014-01-29 09:23:48 +01001524static void qeth_bridge_state_change(struct qeth_card *card,
1525 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001526{
1527 struct qeth_sbp_state_change *qports =
1528 &cmd->data.sbp.data.state_change;
1529 struct qeth_bridge_state_data *data;
1530 int extrasize;
1531
1532 QETH_CARD_TEXT(card, 2, "brstchng");
1533 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001534 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001535 return;
1536 }
1537 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1538 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1539 GFP_ATOMIC);
1540 if (!data) {
1541 QETH_CARD_TEXT(card, 2, "BPSalloc");
1542 return;
1543 }
1544 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1545 data->card = card;
1546 memcpy(&data->qports, qports,
1547 sizeof(struct qeth_sbp_state_change) + extrasize);
1548 queue_work(qeth_wq, &data->worker);
1549}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001550
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001551struct qeth_bridge_host_data {
1552 struct work_struct worker;
1553 struct qeth_card *card;
1554 struct qeth_ipacmd_addr_change hostevs;
1555};
1556
1557static void qeth_bridge_host_event_worker(struct work_struct *work)
1558{
1559 struct qeth_bridge_host_data *data =
1560 container_of(work, struct qeth_bridge_host_data, worker);
1561 int i;
1562
1563 if (data->hostevs.lost_event_mask) {
1564 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001565"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001566 data->card->dev->name,
1567 (data->hostevs.lost_event_mask == 0x01)
1568 ? "Overflow"
1569 : (data->hostevs.lost_event_mask == 0x02)
1570 ? "Bridge port state change"
1571 : "Unknown reason");
1572 mutex_lock(&data->card->conf_mutex);
1573 data->card->options.sbp.hostnotification = 0;
1574 mutex_unlock(&data->card->conf_mutex);
1575 qeth_bridge_emit_host_event(data->card, anev_abort,
1576 0, NULL, NULL);
1577 } else
1578 for (i = 0; i < data->hostevs.num_entries; i++) {
1579 struct qeth_ipacmd_addr_change_entry *entry =
1580 &data->hostevs.entry[i];
1581 qeth_bridge_emit_host_event(data->card,
1582 anev_reg_unreg,
1583 entry->change_code,
1584 &entry->token, &entry->addr_lnid);
1585 }
1586 kfree(data);
1587}
1588
Eugene Crosserc044dc22014-01-29 09:23:48 +01001589static void qeth_bridge_host_event(struct qeth_card *card,
1590 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001591{
1592 struct qeth_ipacmd_addr_change *hostevs =
1593 &cmd->data.addrchange;
1594 struct qeth_bridge_host_data *data;
1595 int extrasize;
1596
1597 QETH_CARD_TEXT(card, 2, "brhostev");
1598 if (cmd->hdr.return_code != 0x0000) {
1599 if (cmd->hdr.return_code == 0x0010) {
1600 if (hostevs->lost_event_mask == 0x00)
1601 hostevs->lost_event_mask = 0xff;
1602 } else {
1603 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1604 cmd->hdr.return_code);
1605 return;
1606 }
1607 }
1608 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1609 hostevs->num_entries;
1610 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1611 GFP_ATOMIC);
1612 if (!data) {
1613 QETH_CARD_TEXT(card, 2, "BPHalloc");
1614 return;
1615 }
1616 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1617 data->card = card;
1618 memcpy(&data->hostevs, hostevs,
1619 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1620 queue_work(qeth_wq, &data->worker);
1621}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001622
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001623/* SETBRIDGEPORT support; sending commands */
1624
1625struct _qeth_sbp_cbctl {
1626 u16 ipa_rc;
1627 u16 cmd_rc;
1628 union {
1629 u32 supported;
1630 struct {
1631 enum qeth_sbp_roles *role;
1632 enum qeth_sbp_states *state;
1633 } qports;
1634 } data;
1635};
1636
1637/**
1638 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1639 * @card: qeth_card structure pointer, for debug messages.
1640 * @cbctl: state structure with hardware return codes.
1641 * @setcmd: IPA command code
1642 *
1643 * Returns negative errno-compatible error indication or 0 on success.
1644 */
1645static int qeth_bridgeport_makerc(struct qeth_card *card,
1646 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1647{
1648 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001649 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001650
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001651 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1652 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001653 switch (cbctl->cmd_rc) {
1654 case 0x0000:
1655 rc = 0;
1656 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001657 case 0x2B04:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001658 case 0x0004:
Eugene Crosserffb95252015-05-18 14:27:58 +02001659 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001660 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001661 case 0x2B0C:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001662 case 0x000C: /* Not configured as bridge Port */
1663 rc = -ENODEV; /* maybe not the best code here? */
1664 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001665 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001666 break;
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001667 case 0x2B10:
1668 case 0x0010: /* OS mismatch */
1669 rc = -EPERM;
1670 dev_err(&card->gdev->dev,
1671 "A Bridge Port is already configured by a different operating system\n");
1672 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001673 case 0x2B14:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001674 case 0x0014: /* Another device is Primary */
1675 switch (setcmd) {
1676 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1677 rc = -EEXIST;
1678 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001679 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001680 break;
1681 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1682 rc = -EBUSY;
1683 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001684 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001685 break;
1686 default:
1687 rc = -EIO;
1688 }
1689 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001690 case 0x2B18:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001691 case 0x0018: /* This device is currently Secondary */
1692 rc = -EBUSY;
1693 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001694 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001695 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001696 case 0x2B1C:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001697 case 0x001C: /* Limit for Secondary devices reached */
1698 rc = -EEXIST;
1699 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001700 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001701 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001702 case 0x2B24:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001703 case 0x0024: /* This device is currently Primary */
1704 rc = -EBUSY;
1705 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001706 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001707 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001708 case 0x2B20:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001709 case 0x0020: /* Not authorized by zManager */
1710 rc = -EACCES;
1711 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001712 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001713 break;
1714 default:
1715 rc = -EIO;
1716 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001717 else
1718 switch (cbctl->ipa_rc) {
1719 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001720 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001721 break;
1722 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001723 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001724 break;
1725 default:
1726 rc = -EIO;
1727 }
1728
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001729 if (rc) {
1730 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1731 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1732 }
1733 return rc;
1734}
1735
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001736static inline int ipa_cmd_sbp(struct qeth_card *card)
1737{
1738 return (card->info.type == QETH_CARD_TYPE_IQD) ?
1739 IPA_CMD_SETBRIDGEPORT_IQD :
1740 IPA_CMD_SETBRIDGEPORT_OSA;
1741}
1742
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001743static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1744 struct qeth_reply *reply, unsigned long data)
1745{
1746 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1747 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1748 QETH_CARD_TEXT(card, 2, "brqsupcb");
1749 cbctl->ipa_rc = cmd->hdr.return_code;
1750 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1751 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1752 cbctl->data.supported =
1753 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1754 } else {
1755 cbctl->data.supported = 0;
1756 }
1757 return 0;
1758}
1759
1760/**
1761 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1762 * @card: qeth_card structure pointer.
1763 *
1764 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1765 * strucutre: card->options.sbp.supported_funcs.
1766 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001767static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001768{
1769 struct qeth_cmd_buffer *iob;
1770 struct qeth_ipa_cmd *cmd;
1771 struct _qeth_sbp_cbctl cbctl;
1772
1773 QETH_CARD_TEXT(card, 2, "brqsuppo");
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001774 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001775 if (!iob)
1776 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001777 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1778 cmd->data.sbp.hdr.cmdlength =
1779 sizeof(struct qeth_ipacmd_sbp_hdr) +
1780 sizeof(struct qeth_sbp_query_cmds_supp);
1781 cmd->data.sbp.hdr.command_code =
1782 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1783 cmd->data.sbp.hdr.used_total = 1;
1784 cmd->data.sbp.hdr.seq_no = 1;
1785 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1786 (void *)&cbctl) ||
1787 qeth_bridgeport_makerc(card, &cbctl,
1788 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1789 /* non-zero makerc signifies failure, and produce messages */
1790 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1791 return;
1792 }
1793 card->options.sbp.supported_funcs = cbctl.data.supported;
1794}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001795
1796static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1797 struct qeth_reply *reply, unsigned long data)
1798{
1799 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1800 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1801 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1802
1803 QETH_CARD_TEXT(card, 2, "brqprtcb");
1804 cbctl->ipa_rc = cmd->hdr.return_code;
1805 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1806 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1807 return 0;
1808 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1809 cbctl->cmd_rc = 0xffff;
1810 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1811 return 0;
1812 }
1813 /* first entry contains the state of the local port */
1814 if (qports->num_entries > 0) {
1815 if (cbctl->data.qports.role)
1816 *cbctl->data.qports.role = qports->entry[0].role;
1817 if (cbctl->data.qports.state)
1818 *cbctl->data.qports.state = qports->entry[0].state;
1819 }
1820 return 0;
1821}
1822
1823/**
1824 * qeth_bridgeport_query_ports() - query local bridgeport status.
1825 * @card: qeth_card structure pointer.
1826 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1827 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1828 *
1829 * Returns negative errno-compatible error indication or 0 on success.
1830 *
1831 * 'role' and 'state' are not updated in case of hardware operation failure.
1832 */
1833int qeth_bridgeport_query_ports(struct qeth_card *card,
1834 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
1835{
1836 int rc = 0;
1837 struct qeth_cmd_buffer *iob;
1838 struct qeth_ipa_cmd *cmd;
1839 struct _qeth_sbp_cbctl cbctl = {
1840 .data = {
1841 .qports = {
1842 .role = role,
1843 .state = state,
1844 },
1845 },
1846 };
1847
1848 QETH_CARD_TEXT(card, 2, "brqports");
1849 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
1850 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001851 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001852 if (!iob)
1853 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001854 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1855 cmd->data.sbp.hdr.cmdlength =
1856 sizeof(struct qeth_ipacmd_sbp_hdr);
1857 cmd->data.sbp.hdr.command_code =
1858 IPA_SBP_QUERY_BRIDGE_PORTS;
1859 cmd->data.sbp.hdr.used_total = 1;
1860 cmd->data.sbp.hdr.seq_no = 1;
1861 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
1862 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001863 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001864 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001865 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001866}
1867EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
1868
1869static int qeth_bridgeport_set_cb(struct qeth_card *card,
1870 struct qeth_reply *reply, unsigned long data)
1871{
1872 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
1873 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1874 QETH_CARD_TEXT(card, 2, "brsetrcb");
1875 cbctl->ipa_rc = cmd->hdr.return_code;
1876 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1877 return 0;
1878}
1879
1880/**
1881 * qeth_bridgeport_setrole() - Assign primary role to the port.
1882 * @card: qeth_card structure pointer.
1883 * @role: Role to assign.
1884 *
1885 * Returns negative errno-compatible error indication or 0 on success.
1886 */
1887int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
1888{
1889 int rc = 0;
1890 int cmdlength;
1891 struct qeth_cmd_buffer *iob;
1892 struct qeth_ipa_cmd *cmd;
1893 struct _qeth_sbp_cbctl cbctl;
1894 enum qeth_ipa_sbp_cmd setcmd;
1895
1896 QETH_CARD_TEXT(card, 2, "brsetrol");
1897 switch (role) {
1898 case QETH_SBP_ROLE_NONE:
1899 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
1900 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1901 sizeof(struct qeth_sbp_reset_role);
1902 break;
1903 case QETH_SBP_ROLE_PRIMARY:
1904 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
1905 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1906 sizeof(struct qeth_sbp_set_primary);
1907 break;
1908 case QETH_SBP_ROLE_SECONDARY:
1909 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
1910 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
1911 sizeof(struct qeth_sbp_set_secondary);
1912 break;
1913 default:
1914 return -EINVAL;
1915 }
1916 if (!(card->options.sbp.supported_funcs & setcmd))
1917 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001918 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001919 if (!iob)
1920 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001921 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1922 cmd->data.sbp.hdr.cmdlength = cmdlength;
1923 cmd->data.sbp.hdr.command_code = setcmd;
1924 cmd->data.sbp.hdr.used_total = 1;
1925 cmd->data.sbp.hdr.seq_no = 1;
1926 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
1927 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02001928 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001929 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02001930 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001931}
1932
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001933/**
1934 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
1935 * @card: qeth_card structure pointer, for debug messages.
1936 *
1937 * Returns negative errno-compatible error indication or 0 on success.
1938 */
1939static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
1940{
1941 int rc;
1942
1943 if (pnso_rc == 0)
1944 switch (response) {
1945 case 0x0001:
1946 rc = 0;
1947 break;
1948 case 0x0004:
1949 case 0x0100:
1950 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02001951 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001952 dev_err(&card->gdev->dev,
1953 "Setting address notification failed\n");
1954 break;
1955 case 0x0107:
1956 rc = -EAGAIN;
1957 break;
1958 default:
1959 rc = -EIO;
1960 }
1961 else
1962 rc = -EIO;
1963
1964 if (rc) {
1965 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
1966 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
1967 }
1968 return rc;
1969}
1970
1971static void qeth_bridgeport_an_set_cb(void *priv,
1972 enum qdio_brinfo_entry_type type, void *entry)
1973{
1974 struct qeth_card *card = (struct qeth_card *)priv;
1975 struct qdio_brinfo_entry_l2 *l2entry;
1976 u8 code;
1977
1978 if (type != l2_addr_lnid) {
1979 WARN_ON_ONCE(1);
1980 return;
1981 }
1982
1983 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
1984 code = IPA_ADDR_CHANGE_CODE_MACADDR;
1985 if (l2entry->addr_lnid.lnid)
1986 code |= IPA_ADDR_CHANGE_CODE_VLANID;
1987 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
1988 (struct net_if_token *)&l2entry->nit,
1989 (struct mac_addr_lnid *)&l2entry->addr_lnid);
1990}
1991
1992/**
1993 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
1994 * @card: qeth_card structure pointer.
1995 * @enable: 0 - disable, non-zero - enable notifications
1996 *
1997 * Returns negative errno-compatible error indication or 0 on success.
1998 *
1999 * On enable, emits a series of address notifications udev events for all
2000 * currently registered hosts.
2001 */
2002int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2003{
2004 int rc;
2005 u16 response;
2006 struct ccw_device *ddev;
2007 struct subchannel_id schid;
2008
2009 if (!card)
2010 return -EINVAL;
2011 if (!card->options.sbp.supported_funcs)
2012 return -EOPNOTSUPP;
2013 ddev = CARD_DDEV(card);
2014 ccw_device_get_schid(ddev, &schid);
2015
2016 if (enable) {
2017 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2018 rc = qdio_pnso_brinfo(schid, 1, &response,
2019 qeth_bridgeport_an_set_cb, card);
2020 } else
2021 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2022 return qeth_anset_makerc(card, rc, response);
2023}
2024EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2025
Frank Blaschka4a71df52008-02-15 09:19:42 +01002026module_init(qeth_l2_init);
2027module_exit(qeth_l2_exit);
2028MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2029MODULE_DESCRIPTION("qeth layer 2 discipline");
2030MODULE_LICENSE("GPL");