blob: 08b5fa969d4a40df802dfb2b6854545faf039707 [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>
19#include <linux/mii.h>
20#include <linux/ip.h>
Jiri Pirkoccffad252009-05-22 23:22:17 +000021#include <linux/list.h>
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020022#include <linux/hash.h>
23#include <linux/hashtable.h>
24#include <linux/string.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 *);
30static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
31static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +010032 enum qeth_ipa_cmds);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +020033static void qeth_l2_set_rx_mode(struct net_device *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010034static int qeth_l2_recover(void *);
Eugene Crosserc044dc22014-01-29 09:23:48 +010035static void qeth_bridgeport_query_support(struct qeth_card *card);
36static void qeth_bridge_state_change(struct qeth_card *card,
37 struct qeth_ipa_cmd *cmd);
38static void qeth_bridge_host_event(struct qeth_card *card,
39 struct qeth_ipa_cmd *cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +010040
41static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
42{
Heiko Carstens509e2562008-07-26 02:24:10 -070043 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +010044 struct mii_ioctl_data *mii_data;
45 int rc = 0;
46
47 if (!card)
48 return -ENODEV;
49
Eugene Crosserc3521252015-01-16 14:05:47 +010050 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +010051 return -ENODEV;
52
53 if (card->info.type == QETH_CARD_TYPE_OSN)
54 return -EPERM;
55
56 switch (cmd) {
57 case SIOC_QETH_ADP_SET_SNMP_CONTROL:
58 rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
59 break;
60 case SIOC_QETH_GET_CARD_TYPE:
Ursula Braun5113fec2010-05-16 21:15:14 +000061 if ((card->info.type == QETH_CARD_TYPE_OSD ||
62 card->info.type == QETH_CARD_TYPE_OSM ||
63 card->info.type == QETH_CARD_TYPE_OSX) &&
Frank Blaschka4a71df52008-02-15 09:19:42 +010064 !card->info.guestlan)
65 return 1;
66 return 0;
67 break;
68 case SIOCGMIIPHY:
69 mii_data = if_mii(rq);
70 mii_data->phy_id = 0;
71 break;
72 case SIOCGMIIREG:
73 mii_data = if_mii(rq);
74 if (mii_data->phy_id != 0)
75 rc = -EINVAL;
76 else
77 mii_data->val_out = qeth_mdio_read(dev,
78 mii_data->phy_id, mii_data->reg_num);
79 break;
Frank Blaschkac3ab96f2012-02-08 00:19:49 +000080 case SIOC_QETH_QUERY_OAT:
81 rc = qeth_query_oat_command(card, rq->ifr_ifru.ifru_data);
82 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +010083 default:
84 rc = -EOPNOTSUPP;
85 }
86 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +000087 QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +010088 return rc;
89}
90
91static int qeth_l2_verify_dev(struct net_device *dev)
92{
93 struct qeth_card *card;
94 unsigned long flags;
95 int rc = 0;
96
97 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
98 list_for_each_entry(card, &qeth_core_card_list.list, list) {
99 if (card->dev == dev) {
100 rc = QETH_REAL_CARD;
101 break;
102 }
103 }
104 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
105
106 return rc;
107}
108
109static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
110{
111 struct qeth_card *card;
112 struct net_device *ndev;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200113 __u16 temp_dev_no;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100114 unsigned long flags;
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200115 struct ccw_dev_id read_devid;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100116
117 ndev = NULL;
118 memcpy(&temp_dev_no, read_dev_no, 2);
119 read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
120 list_for_each_entry(card, &qeth_core_card_list.list, list) {
Cornelia Huckf06f6f32008-06-06 12:37:45 +0200121 ccw_device_get_id(CARD_RDEV(card), &read_devid);
122 if (read_devid.devno == temp_dev_no) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100123 ndev = card->dev;
124 break;
125 }
126 }
127 read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags);
128 return ndev;
129}
130
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100131static int qeth_setdel_makerc(struct qeth_card *card, int retcode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100132{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100133 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100134
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100135 if (retcode)
Thomas Richter1aec42b2015-01-21 13:39:10 +0100136 QETH_CARD_TEXT_(card, 2, "err%04x", retcode);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100137 switch (retcode) {
138 case IPA_RC_SUCCESS:
139 rc = 0;
140 break;
141 case IPA_RC_L2_UNSUPPORTED_CMD:
Eugene Crosserffb95252015-05-18 14:27:58 +0200142 rc = -EOPNOTSUPP;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100143 break;
144 case IPA_RC_L2_ADDR_TABLE_FULL:
145 rc = -ENOSPC;
146 break;
147 case IPA_RC_L2_DUP_MAC:
148 case IPA_RC_L2_DUP_LAYER3_MAC:
149 rc = -EEXIST;
150 break;
151 case IPA_RC_L2_MAC_NOT_AUTH_BY_HYP:
152 case IPA_RC_L2_MAC_NOT_AUTH_BY_ADP:
153 rc = -EPERM;
154 break;
155 case IPA_RC_L2_MAC_NOT_FOUND:
156 rc = -ENOENT;
157 break;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100158 case -ENOMEM:
159 rc = -ENOMEM;
160 break;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100161 default:
162 rc = -EIO;
163 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100165 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100166}
167
168static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
169{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100170 int rc;
171
Carsten Otte847a50f2010-06-21 22:57:05 +0000172 QETH_CARD_TEXT(card, 2, "L2Sgmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100173 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
174 IPA_CMD_SETGMAC));
175 if (rc == -EEXIST)
176 QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s\n",
177 mac, QETH_CARD_IFNAME(card));
178 else if (rc)
179 QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %d\n",
180 mac, QETH_CARD_IFNAME(card), rc);
181 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100182}
183
184static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
185{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100186 int rc;
187
Carsten Otte847a50f2010-06-21 22:57:05 +0000188 QETH_CARD_TEXT(card, 2, "L2Dgmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100189 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
190 IPA_CMD_DELGMAC));
191 if (rc)
192 QETH_DBF_MESSAGE(2,
193 "Could not delete group MAC %pM on %s: %d\n",
194 mac, QETH_CARD_IFNAME(card), rc);
195 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100196}
197
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200198static inline u32 qeth_l2_mac_hash(const u8 *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100199{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200200 return get_unaligned((u32 *)(&addr[2]));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100201}
202
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200203static int qeth_l2_write_mac(struct qeth_card *card, struct qeth_mac *mac)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100204{
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200205
206 int rc;
207
208 if (mac->is_uc) {
209 rc = qeth_setdel_makerc(card,
210 qeth_l2_send_setdelmac(card, mac->mac_addr,
211 IPA_CMD_SETVMAC));
212 } else {
213 rc = qeth_setdel_makerc(card,
214 qeth_l2_send_setgroupmac(card, mac->mac_addr));
215 }
216 return rc;
217}
218
219static void qeth_l2_del_all_macs(struct qeth_card *card, int del)
220{
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) {
Ursula Braun70919e22011-02-26 22:41:36 -0800227 if (del) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200228 if (mac->is_uc)
229 qeth_l2_send_setdelmac(card, mac->mac_addr,
230 IPA_CMD_DELVMAC);
Ursula Braun70919e22011-02-26 22:41:36 -0800231 else
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200232 qeth_l2_send_delgroupmac(card, mac->mac_addr);
Ursula Braun70919e22011-02-26 22:41:36 -0800233 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200234 hash_del(&mac->hnode);
235 kfree(mac);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100236 }
237 spin_unlock_bh(&card->mclock);
238}
239
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000240static inline int qeth_l2_get_cast_type(struct qeth_card *card,
241 struct sk_buff *skb)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100242{
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000243 if (card->info.type == QETH_CARD_TYPE_OSN)
244 return RTN_UNSPEC;
245 if (is_broadcast_ether_addr(skb->data))
246 return RTN_BROADCAST;
247 if (is_multicast_ether_addr(skb->data))
248 return RTN_MULTICAST;
249 return RTN_UNSPEC;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100250}
251
Thomas Richter4d7def22015-09-18 16:06:51 +0200252static inline void qeth_l2_hdr_csum(struct qeth_card *card,
253 struct qeth_hdr *hdr, struct sk_buff *skb)
254{
255 struct iphdr *iph = ip_hdr(skb);
256
257 /* tcph->check contains already the pseudo hdr checksum
258 * so just set the header flags
259 */
260 if (iph->protocol == IPPROTO_UDP)
261 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_UDP;
262 hdr->hdr.l2.flags[1] |= QETH_HDR_EXT_CSUM_TRANSP_REQ |
263 QETH_HDR_EXT_CSUM_HDR_REQ;
264 iph->check = 0;
265 if (card->options.performance_stats)
266 card->perf_stats.tx_csum++;
267}
268
Frank Blaschka4a71df52008-02-15 09:19:42 +0100269static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
Stefan Raspl43934072014-03-19 07:58:01 +0100270 struct sk_buff *skb, int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271{
Frank Blaschka683d7182008-08-01 16:39:13 +0200272 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100273
274 memset(hdr, 0, sizeof(struct qeth_hdr));
275 hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
276
277 /* set byte byte 3 to casting flags */
278 if (cast_type == RTN_MULTICAST)
279 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
280 else if (cast_type == RTN_BROADCAST)
281 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
282 else
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000283 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100284
285 hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
286 /* VSWITCH relies on the VLAN
287 * information to be present in
288 * the QDIO header */
289 if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
290 hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
291 hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
292 }
293}
294
295static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
296 struct qeth_reply *reply, unsigned long data)
297{
298 struct qeth_ipa_cmd *cmd;
299
Carsten Otte847a50f2010-06-21 22:57:05 +0000300 QETH_CARD_TEXT(card, 2, "L2sdvcb");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100301 cmd = (struct qeth_ipa_cmd *) data;
302 if (cmd->hdr.return_code) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200303 QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
Frank Blaschka4a71df52008-02-15 09:19:42 +0100304 "Continuing\n", cmd->data.setdelvlan.vlan_id,
305 QETH_CARD_IFNAME(card), cmd->hdr.return_code);
Carsten Otte847a50f2010-06-21 22:57:05 +0000306 QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
307 QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100308 }
309 return 0;
310}
311
312static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
313 enum qeth_ipa_cmds ipacmd)
314{
315 struct qeth_ipa_cmd *cmd;
316 struct qeth_cmd_buffer *iob;
317
Carsten Otte847a50f2010-06-21 22:57:05 +0000318 QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100319 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100320 if (!iob)
321 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100322 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
323 cmd->data.setdelvlan.vlan_id = i;
324 return qeth_send_ipa_cmd(card, iob,
325 qeth_l2_send_setdelvlan_cb, NULL);
326}
327
Ursula Braun70919e22011-02-26 22:41:36 -0800328static void qeth_l2_process_vlans(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100329{
330 struct qeth_vlan_vid *id;
Carsten Otte847a50f2010-06-21 22:57:05 +0000331 QETH_CARD_TEXT(card, 3, "L2prcvln");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100332 spin_lock_bh(&card->vlanlock);
333 list_for_each_entry(id, &card->vid_list, list) {
Ursula Braun70919e22011-02-26 22:41:36 -0800334 qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100335 }
336 spin_unlock_bh(&card->vlanlock);
337}
338
Patrick McHardy80d5c362013-04-19 02:04:28 +0000339static int qeth_l2_vlan_rx_add_vid(struct net_device *dev,
340 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100341{
Heiko Carstens509e2562008-07-26 02:24:10 -0700342 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100343 struct qeth_vlan_vid *id;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100344 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100345
Carsten Otte847a50f2010-06-21 22:57:05 +0000346 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Ursula Braun10651db2010-10-01 02:51:13 +0000347 if (!vid)
Jiri Pirko8e586132011-12-08 19:52:37 -0500348 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000349 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000350 QETH_CARD_TEXT(card, 3, "aidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500351 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000352 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000353 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000354 QETH_CARD_TEXT(card, 3, "aidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500355 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000356 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100357 id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
358 if (id) {
359 id->vid = vid;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100360 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
361 if (rc) {
362 kfree(id);
363 return rc;
364 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100365 spin_lock_bh(&card->vlanlock);
366 list_add_tail(&id->list, &card->vid_list);
367 spin_unlock_bh(&card->vlanlock);
Jiri Pirko8e586132011-12-08 19:52:37 -0500368 } else {
369 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100370 }
Jiri Pirko8e586132011-12-08 19:52:37 -0500371 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100372}
373
Patrick McHardy80d5c362013-04-19 02:04:28 +0000374static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev,
375 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100376{
377 struct qeth_vlan_vid *id, *tmpid = NULL;
Heiko Carstens509e2562008-07-26 02:24:10 -0700378 struct qeth_card *card = dev->ml_priv;
Thomas Richter1aec42b2015-01-21 13:39:10 +0100379 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100380
Carsten Otte847a50f2010-06-21 22:57:05 +0000381 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Ursula Braun5113fec2010-05-16 21:15:14 +0000382 if (card->info.type == QETH_CARD_TYPE_OSM) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000383 QETH_CARD_TEXT(card, 3, "kidOSM");
Jiri Pirko8e586132011-12-08 19:52:37 -0500384 return 0;
Ursula Braun5113fec2010-05-16 21:15:14 +0000385 }
Ursula Braun8e98ac42009-03-24 20:57:18 +0000386 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000387 QETH_CARD_TEXT(card, 3, "kidREC");
Jiri Pirko8e586132011-12-08 19:52:37 -0500388 return 0;
Ursula Braun8e98ac42009-03-24 20:57:18 +0000389 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100390 spin_lock_bh(&card->vlanlock);
391 list_for_each_entry(id, &card->vid_list, list) {
392 if (id->vid == vid) {
393 list_del(&id->list);
394 tmpid = id;
395 break;
396 }
397 }
398 spin_unlock_bh(&card->vlanlock);
399 if (tmpid) {
Thomas Richter1aec42b2015-01-21 13:39:10 +0100400 rc = qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100401 kfree(tmpid);
402 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200403 qeth_l2_set_rx_mode(card->dev);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100404 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100405}
406
Thomas Richter4d7def22015-09-18 16:06:51 +0200407static netdev_features_t qeth_l2_fix_features(struct net_device *dev,
408 netdev_features_t features)
409{
410 struct qeth_card *card = dev->ml_priv;
411
412 QETH_DBF_TEXT(SETUP, 2, "fixfeat");
413 if (!qeth_is_supported(card, IPA_OUTBOUND_CHECKSUM))
414 features &= ~NETIF_F_IP_CSUM;
415 if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
416 features &= ~NETIF_F_RXCSUM;
417 QETH_DBF_HEX(SETUP, 2, &features, sizeof(features));
418 return features;
419}
420
421static int qeth_l2_set_features(struct net_device *dev,
422 netdev_features_t features)
423{
424 struct qeth_card *card = dev->ml_priv;
425 netdev_features_t changed = dev->features ^ features;
426
427 QETH_DBF_TEXT(SETUP, 2, "setfeat");
428 QETH_DBF_HEX(SETUP, 2, &features, sizeof(features));
429
430 if (card->state == CARD_STATE_DOWN ||
431 card->state == CARD_STATE_RECOVER)
432 return 0;
433
434 if (!(changed & NETIF_F_RXCSUM))
435 return 0;
436 return qeth_set_rx_csum(card, features & NETIF_F_RXCSUM ? 1 : 0);
437}
438
Peter Senna Tschudinb2f4de82015-08-04 17:11:47 +0200439static void qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100440{
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200441 QETH_DBF_TEXT(SETUP , 2, "stopcard");
442 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100443
444 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100445 if (card->read.state == CH_STATE_UP &&
446 card->write.state == CH_STATE_UP &&
447 (card->state == CARD_STATE_UP)) {
448 if (recovery_mode &&
449 card->info.type != QETH_CARD_TYPE_OSN) {
450 qeth_l2_stop(card->dev);
451 } else {
452 rtnl_lock();
453 dev_close(card->dev);
454 rtnl_unlock();
455 }
Ursula Braun70919e22011-02-26 22:41:36 -0800456 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100457 card->state = CARD_STATE_SOFTSETUP;
458 }
459 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200460 qeth_l2_del_all_macs(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100461 qeth_clear_ipacmd_list(card);
462 card->state = CARD_STATE_HARDSETUP;
463 }
464 if (card->state == CARD_STATE_HARDSETUP) {
465 qeth_qdio_clear_card(card, 0);
466 qeth_clear_qdio_buffers(card);
467 qeth_clear_working_pool_list(card);
468 card->state = CARD_STATE_DOWN;
469 }
470 if (card->state == CARD_STATE_DOWN) {
471 qeth_clear_cmd_buffers(&card->read);
472 qeth_clear_cmd_buffers(&card->write);
473 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100474}
475
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000476static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
477 int budget, int *done)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100478{
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000479 int work_done = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 struct sk_buff *skb;
481 struct qeth_hdr *hdr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100482 unsigned int len;
483
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000484 *done = 0;
Stefan Raspl18af5c12012-11-19 02:46:50 +0000485 WARN_ON_ONCE(!budget);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000486 while (budget) {
487 skb = qeth_core_get_next_skb(card,
Frank Blaschkab3332932011-08-08 01:33:59 +0000488 &card->qdio.in_q->bufs[card->rx.b_index],
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000489 &card->rx.b_element, &card->rx.e_offset, &hdr);
490 if (!skb) {
491 *done = 1;
492 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100493 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000494 skb->dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100495 switch (hdr->hdr.l2.id) {
496 case QETH_HEADER_TYPE_LAYER2:
497 skb->pkt_type = PACKET_HOST;
498 skb->protocol = eth_type_trans(skb, skb->dev);
Thomas Richter4d7def22015-09-18 16:06:51 +0200499 if ((card->dev->features & NETIF_F_RXCSUM)
500 && ((hdr->hdr.l2.flags[1] &
501 (QETH_HDR_EXT_CSUM_HDR_REQ |
502 QETH_HDR_EXT_CSUM_TRANSP_REQ)) ==
503 (QETH_HDR_EXT_CSUM_HDR_REQ |
504 QETH_HDR_EXT_CSUM_TRANSP_REQ)))
505 skb->ip_summed = CHECKSUM_UNNECESSARY;
506 else
507 skb->ip_summed = CHECKSUM_NONE;
Ursula Braun12883722008-04-01 10:26:56 +0200508 if (skb->protocol == htons(ETH_P_802_2))
509 *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100510 len = skb->len;
Thomas Richter9abfa8c2015-10-06 15:12:27 +0200511 napi_gro_receive(&card->napi, skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100512 break;
513 case QETH_HEADER_TYPE_OSN:
Ursula Braun2d488c22008-10-24 11:16:55 +0200514 if (card->info.type == QETH_CARD_TYPE_OSN) {
515 skb_push(skb, sizeof(struct qeth_hdr));
516 skb_copy_to_linear_data(skb, hdr,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517 sizeof(struct qeth_hdr));
Ursula Braun2d488c22008-10-24 11:16:55 +0200518 len = skb->len;
519 card->osn_info.data_cb(skb);
520 break;
521 }
522 /* else unknown */
Frank Blaschka4a71df52008-02-15 09:19:42 +0100523 default:
524 dev_kfree_skb_any(skb);
Carsten Otte847a50f2010-06-21 22:57:05 +0000525 QETH_CARD_TEXT(card, 3, "inbunkno");
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200526 QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100527 continue;
528 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000529 work_done++;
530 budget--;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100531 card->stats.rx_packets++;
532 card->stats.rx_bytes += len;
533 }
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +0000534 return work_done;
535}
536
537static int qeth_l2_poll(struct napi_struct *napi, int budget)
538{
539 struct qeth_card *card = container_of(napi, struct qeth_card, napi);
540 int work_done = 0;
541 struct qeth_qdio_buffer *buffer;
542 int done;
543 int new_budget = budget;
544
545 if (card->options.performance_stats) {
546 card->perf_stats.inbound_cnt++;
547 card->perf_stats.inbound_start_time = qeth_get_micros();
548 }
549
550 while (1) {
551 if (!card->rx.b_count) {
552 card->rx.qdio_err = 0;
553 card->rx.b_count = qdio_get_next_buffers(
554 card->data.ccwdev, 0, &card->rx.b_index,
555 &card->rx.qdio_err);
556 if (card->rx.b_count <= 0) {
557 card->rx.b_count = 0;
558 break;
559 }
560 card->rx.b_element =
561 &card->qdio.in_q->bufs[card->rx.b_index]
562 .buffer->element[0];
563 card->rx.e_offset = 0;
564 }
565
566 while (card->rx.b_count) {
567 buffer = &card->qdio.in_q->bufs[card->rx.b_index];
568 if (!(card->rx.qdio_err &&
569 qeth_check_qdio_errors(card, buffer->buffer,
570 card->rx.qdio_err, "qinerr")))
571 work_done += qeth_l2_process_inbound_buffer(
572 card, new_budget, &done);
573 else
574 done = 1;
575
576 if (done) {
577 if (card->options.performance_stats)
578 card->perf_stats.bufs_rec++;
579 qeth_put_buffer_pool_entry(card,
580 buffer->pool_entry);
581 qeth_queue_input_buffer(card, card->rx.b_index);
582 card->rx.b_count--;
583 if (card->rx.b_count) {
584 card->rx.b_index =
585 (card->rx.b_index + 1) %
586 QDIO_MAX_BUFFERS_PER_Q;
587 card->rx.b_element =
588 &card->qdio.in_q
589 ->bufs[card->rx.b_index]
590 .buffer->element[0];
591 card->rx.e_offset = 0;
592 }
593 }
594
595 if (work_done >= budget)
596 goto out;
597 else
598 new_budget = budget - work_done;
599 }
600 }
601
602 napi_complete(napi);
603 if (qdio_start_irq(card->data.ccwdev, 0))
604 napi_schedule(&card->napi);
605out:
606 if (card->options.performance_stats)
607 card->perf_stats.inbound_time += qeth_get_micros() -
608 card->perf_stats.inbound_start_time;
609 return work_done;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100610}
611
612static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100613 enum qeth_ipa_cmds ipacmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100614{
615 struct qeth_ipa_cmd *cmd;
616 struct qeth_cmd_buffer *iob;
617
Carsten Otte847a50f2010-06-21 22:57:05 +0000618 QETH_CARD_TEXT(card, 2, "L2sdmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100619 iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100620 if (!iob)
621 return -ENOMEM;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100622 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
623 cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
624 memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100625 return qeth_send_ipa_cmd(card, iob, NULL, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100626}
627
628static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
629{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100630 int rc;
631
Carsten Otte847a50f2010-06-21 22:57:05 +0000632 QETH_CARD_TEXT(card, 2, "L2Setmac");
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100633 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
634 IPA_CMD_SETVMAC));
635 if (rc == 0) {
636 card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
637 memcpy(card->dev->dev_addr, mac, OSA_ADDR_LEN);
638 dev_info(&card->gdev->dev,
639 "MAC address %pM successfully registered on device %s\n",
640 card->dev->dev_addr, card->dev->name);
641 } else {
642 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
643 switch (rc) {
644 case -EEXIST:
645 dev_warn(&card->gdev->dev,
646 "MAC address %pM already exists\n", mac);
647 break;
648 case -EPERM:
649 dev_warn(&card->gdev->dev,
650 "MAC address %pM is not authorized\n", mac);
651 break;
652 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100653 }
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100654 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100655}
656
657static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
658{
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100659 int rc;
660
Carsten Otte847a50f2010-06-21 22:57:05 +0000661 QETH_CARD_TEXT(card, 2, "L2Delmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662 if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
663 return 0;
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100664 rc = qeth_setdel_makerc(card, qeth_l2_send_setdelmac(card, mac,
665 IPA_CMD_DELVMAC));
666 if (rc == 0)
667 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
668 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100669}
670
671static int qeth_l2_request_initial_mac(struct qeth_card *card)
672{
673 int rc = 0;
674 char vendor_pre[] = {0x02, 0x00, 0x00};
675
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200676 QETH_DBF_TEXT(SETUP, 2, "doL2init");
677 QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100678
Stefan Raspla1348842012-11-12 23:05:16 +0000679 if (qeth_is_supported(card, IPA_SETADAPTERPARMS)) {
680 rc = qeth_query_setadapterparms(card);
681 if (rc) {
682 QETH_DBF_MESSAGE(2, "could not query adapter "
683 "parameters on device %s: x%x\n",
684 CARD_BUS_ID(card), rc);
685 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100686 }
687
Ursula Braun5113fec2010-05-16 21:15:14 +0000688 if (card->info.type == QETH_CARD_TYPE_IQD ||
689 card->info.type == QETH_CARD_TYPE_OSM ||
690 card->info.type == QETH_CARD_TYPE_OSX ||
691 card->info.guestlan) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100692 rc = qeth_setadpparms_change_macaddr(card);
693 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +0200694 QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
695 "device %s: x%x\n", CARD_BUS_ID(card), rc);
Thomas Richter1aec42b2015-01-21 13:39:10 +0100696 QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100697 return rc;
698 }
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +0200699 QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700 } else {
Joe Perches18336112012-07-12 22:33:10 -0700701 eth_random_addr(card->dev->dev_addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100702 memcpy(card->dev->dev_addr, vendor_pre, 3);
703 }
704 return 0;
705}
706
707static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
708{
709 struct sockaddr *addr = p;
Heiko Carstens509e2562008-07-26 02:24:10 -0700710 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100711 int rc = 0;
712
Carsten Otte847a50f2010-06-21 22:57:05 +0000713 QETH_CARD_TEXT(card, 3, "setmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100714
715 if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000716 QETH_CARD_TEXT(card, 3, "setmcINV");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100717 return -EOPNOTSUPP;
718 }
719
Ursula Braun5113fec2010-05-16 21:15:14 +0000720 if (card->info.type == QETH_CARD_TYPE_OSN ||
721 card->info.type == QETH_CARD_TYPE_OSM ||
722 card->info.type == QETH_CARD_TYPE_OSX) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000723 QETH_CARD_TEXT(card, 3, "setmcTYP");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100724 return -EOPNOTSUPP;
725 }
Carsten Otte847a50f2010-06-21 22:57:05 +0000726 QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
Ursula Braun8e98ac42009-03-24 20:57:18 +0000727 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000728 QETH_CARD_TEXT(card, 3, "setmcREC");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000729 return -ERESTARTSYS;
730 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100731 rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
Eugene Crosserefbbc1d2015-01-21 13:39:09 +0100732 if (!rc || (rc == -ENOENT))
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733 rc = qeth_l2_send_setmac(card, addr->sa_data);
Ursula Braune0a81142012-03-07 02:06:28 +0000734 return rc ? -EINVAL : 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100735}
736
Eugene Crosser0db587b2015-05-18 14:27:55 +0200737static void qeth_promisc_to_bridge(struct qeth_card *card)
738{
739 struct net_device *dev = card->dev;
740 enum qeth_ipa_promisc_modes promisc_mode;
741 int role;
742 int rc;
743
744 QETH_CARD_TEXT(card, 3, "pmisc2br");
745
746 if (!card->options.sbp.reflect_promisc)
747 return;
748 promisc_mode = (dev->flags & IFF_PROMISC) ? SET_PROMISC_MODE_ON
749 : SET_PROMISC_MODE_OFF;
750 if (promisc_mode == card->info.promisc_mode)
751 return;
752
753 if (promisc_mode == SET_PROMISC_MODE_ON) {
754 if (card->options.sbp.reflect_promisc_primary)
755 role = QETH_SBP_ROLE_PRIMARY;
756 else
757 role = QETH_SBP_ROLE_SECONDARY;
758 } else
759 role = QETH_SBP_ROLE_NONE;
760
761 rc = qeth_bridgeport_setrole(card, role);
762 QETH_DBF_TEXT_(SETUP, 2, "bpm%c%04x",
763 (promisc_mode == SET_PROMISC_MODE_ON) ? '+' : '-', rc);
764 if (!rc) {
765 card->options.sbp.role = role;
766 card->info.promisc_mode = promisc_mode;
767 }
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200768
769}
770/* New MAC address is added to the hash table and marked to be written on card
771 * only if there is not in the hash table storage already
772 *
773*/
774static void
775qeth_l2_add_mac(struct qeth_card *card, struct netdev_hw_addr *ha, u8 is_uc)
776{
777 struct qeth_mac *mac;
778
779 hash_for_each_possible(card->mac_htable, mac, hnode,
780 qeth_l2_mac_hash(ha->addr)) {
781 if (is_uc == mac->is_uc &&
782 !memcmp(ha->addr, mac->mac_addr, OSA_ADDR_LEN)) {
783 mac->disp_flag = QETH_DISP_MAC_DO_NOTHING;
784 return;
785 }
786 }
787
788 mac = kzalloc(sizeof(struct qeth_mac), GFP_ATOMIC);
789
790 if (!mac)
791 return;
792
793 memcpy(mac->mac_addr, ha->addr, OSA_ADDR_LEN);
794 mac->is_uc = is_uc;
795 mac->disp_flag = QETH_DISP_MAC_ADD;
796
797 hash_add(card->mac_htable, &mac->hnode,
798 qeth_l2_mac_hash(mac->mac_addr));
799
Eugene Crosser0db587b2015-05-18 14:27:55 +0200800}
801
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200802static void qeth_l2_set_rx_mode(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100803{
Heiko Carstens509e2562008-07-26 02:24:10 -0700804 struct qeth_card *card = dev->ml_priv;
Jiri Pirkoccffad252009-05-22 23:22:17 +0000805 struct netdev_hw_addr *ha;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200806 struct qeth_mac *mac;
807 struct hlist_node *tmp;
808 int i;
809 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100810
811 if (card->info.type == QETH_CARD_TYPE_OSN)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200812 return;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100813
Carsten Otte847a50f2010-06-21 22:57:05 +0000814 QETH_CARD_TEXT(card, 3, "setmulti");
Ursula Braun8e98ac42009-03-24 20:57:18 +0000815 if (qeth_threads_running(card, QETH_RECOVER_THREAD) &&
816 (card->state != CARD_STATE_UP))
817 return;
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200818
Frank Blaschka4a71df52008-02-15 09:19:42 +0100819 spin_lock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200820
Jiri Pirko22bedad32010-04-01 21:22:57 +0000821 netdev_for_each_mc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200822 qeth_l2_add_mac(card, ha, 0);
Frank Blaschka7db22662008-08-15 08:02:59 +0200823
Jiri Pirko32e7bfc2010-01-25 13:36:10 -0800824 netdev_for_each_uc_addr(ha, dev)
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200825 qeth_l2_add_mac(card, ha, 1);
826
827 hash_for_each_safe(card->mac_htable, i, tmp, mac, hnode) {
828 if (mac->disp_flag == QETH_DISP_MAC_DELETE) {
829 if (!mac->is_uc)
830 rc = qeth_l2_send_delgroupmac(card,
831 mac->mac_addr);
832 else {
833 rc = qeth_l2_send_setdelmac(card, mac->mac_addr,
834 IPA_CMD_DELVMAC);
835 }
836
837 hash_del(&mac->hnode);
838 kfree(mac);
839
840 } else if (mac->disp_flag == QETH_DISP_MAC_ADD) {
841 rc = qeth_l2_write_mac(card, mac);
842 if (rc) {
843 hash_del(&mac->hnode);
844 kfree(mac);
845 } else
846 mac->disp_flag = QETH_DISP_MAC_DELETE;
847 } else
848 mac->disp_flag = QETH_DISP_MAC_DELETE;
849 }
Frank Blaschka7db22662008-08-15 08:02:59 +0200850
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851 spin_unlock_bh(&card->mclock);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +0200852
Eugene Crosser0db587b2015-05-18 14:27:55 +0200853 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
854 qeth_setadp_promisc_mode(card);
855 else
856 qeth_promisc_to_bridge(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100857}
858
859static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
860{
861 int rc;
862 struct qeth_hdr *hdr = NULL;
863 int elements = 0;
Heiko Carstens509e2562008-07-26 02:24:10 -0700864 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100865 struct sk_buff *new_skb = skb;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +0000866 int cast_type = qeth_l2_get_cast_type(card, skb);
Stefan Raspl290b8342014-04-28 10:05:08 +0200867 struct qeth_qdio_out_q *queue;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100868 int tx_bytes = skb->len;
Frank Blaschka683d7182008-08-01 16:39:13 +0200869 int data_offset = -1;
870 int elements_needed = 0;
871 int hd_len = 0;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200872 int nr_frags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100873
Stefan Raspl290b8342014-04-28 10:05:08 +0200874 if (card->qdio.do_prio_queueing || (cast_type &&
875 card->info.is_multicast_different))
876 queue = card->qdio.out_qs[qeth_get_priority_queue(card, skb,
877 qeth_get_ip_version(skb), cast_type)];
878 else
879 queue = card->qdio.out_qs[card->qdio.default_out_queue];
880
Frank Blaschka4a71df52008-02-15 09:19:42 +0100881 if ((card->state != CARD_STATE_UP) || !card->lan_online) {
882 card->stats.tx_carrier_errors++;
883 goto tx_drop;
884 }
885
886 if ((card->info.type == QETH_CARD_TYPE_OSN) &&
887 (skb->protocol == htons(ETH_P_IPV6)))
888 goto tx_drop;
889
890 if (card->options.performance_stats) {
891 card->perf_stats.outbound_cnt++;
892 card->perf_stats.outbound_start_time = qeth_get_micros();
893 }
894 netif_stop_queue(dev);
895
Eugene Crosserd52aec92016-06-16 16:18:55 +0200896 /* fix hardware limitation: as long as we do not have sbal
897 * chaining we can not send long frag lists
898 */
899 if ((card->info.type != QETH_CARD_TYPE_IQD) &&
900 !qeth_get_elements_no(card, new_skb, 0)) {
Eugene Crosser6059c902016-06-16 16:18:57 +0200901 int lin_rc = skb_linearize(new_skb);
902
903 if (card->options.performance_stats) {
904 if (lin_rc)
905 card->perf_stats.tx_linfail++;
906 else
907 card->perf_stats.tx_lin++;
908 }
909 if (lin_rc)
Eugene Crosserd52aec92016-06-16 16:18:55 +0200910 goto tx_drop;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200911 }
912
Frank Blaschka4a71df52008-02-15 09:19:42 +0100913 if (card->info.type == QETH_CARD_TYPE_OSN)
914 hdr = (struct qeth_hdr *)skb->data;
915 else {
Frank Blaschka64ef8952009-03-24 20:57:16 +0000916 if (card->info.type == QETH_CARD_TYPE_IQD) {
Frank Blaschka683d7182008-08-01 16:39:13 +0200917 new_skb = skb;
918 data_offset = ETH_HLEN;
919 hd_len = ETH_HLEN;
920 hdr = kmem_cache_alloc(qeth_core_header_cache,
921 GFP_ATOMIC);
922 if (!hdr)
923 goto tx_drop;
924 elements_needed++;
925 skb_reset_mac_header(new_skb);
Stefan Raspl43934072014-03-19 07:58:01 +0100926 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Frank Blaschka683d7182008-08-01 16:39:13 +0200927 hdr->hdr.l2.pkt_length = new_skb->len;
928 memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
929 skb_mac_header(new_skb), ETH_HLEN);
930 } else {
931 /* create a clone with writeable headroom */
932 new_skb = skb_realloc_headroom(skb,
Frank Blaschkaf90b7442008-04-24 10:15:24 +0200933 sizeof(struct qeth_hdr));
Frank Blaschka683d7182008-08-01 16:39:13 +0200934 if (!new_skb)
935 goto tx_drop;
936 hdr = (struct qeth_hdr *)skb_push(new_skb,
937 sizeof(struct qeth_hdr));
938 skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
Stefan Raspl43934072014-03-19 07:58:01 +0100939 qeth_l2_fill_header(card, hdr, new_skb, cast_type);
Thomas Richter4d7def22015-09-18 16:06:51 +0200940 if (new_skb->ip_summed == CHECKSUM_PARTIAL)
941 qeth_l2_hdr_csum(card, hdr, new_skb);
Frank Blaschka683d7182008-08-01 16:39:13 +0200942 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100943 }
944
Stefan Raspl065cc782013-04-22 01:12:28 +0000945 elements = qeth_get_elements_no(card, new_skb, elements_needed);
Frank Blaschka64ef8952009-03-24 20:57:16 +0000946 if (!elements) {
947 if (data_offset >= 0)
948 kmem_cache_free(qeth_core_header_cache, hdr);
949 goto tx_drop;
Frank Blaschkaf61a0d02009-03-24 20:57:15 +0000950 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100951
Frank Blaschka51aa1652010-06-21 22:57:10 +0000952 if (card->info.type != QETH_CARD_TYPE_IQD) {
Stefan Raspld4ae1f52013-04-22 01:12:29 +0000953 if (qeth_hdr_chk_and_bounce(new_skb, &hdr,
Frank Blaschka51aa1652010-06-21 22:57:10 +0000954 sizeof(struct qeth_hdr_layer2)))
955 goto tx_drop;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100956 rc = qeth_do_send_packet(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000957 elements);
Frank Blaschka51aa1652010-06-21 22:57:10 +0000958 } else
Frank Blaschka4a71df52008-02-15 09:19:42 +0100959 rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
Frank Blaschka64ef8952009-03-24 20:57:16 +0000960 elements, data_offset, hd_len);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100961 if (!rc) {
962 card->stats.tx_packets++;
963 card->stats.tx_bytes += tx_bytes;
Eugene Crosserd52aec92016-06-16 16:18:55 +0200964 if (card->options.performance_stats) {
965 nr_frags = skb_shinfo(new_skb)->nr_frags;
966 if (nr_frags) {
967 card->perf_stats.sg_skbs_sent++;
968 /* nr_frags + skb->data */
969 card->perf_stats.sg_frags_sent += nr_frags + 1;
970 }
971 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100972 if (new_skb != skb)
973 dev_kfree_skb_any(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700974 rc = NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100975 } else {
Frank Blaschka683d7182008-08-01 16:39:13 +0200976 if (data_offset >= 0)
977 kmem_cache_free(qeth_core_header_cache, hdr);
978
Frank Blaschka4a71df52008-02-15 09:19:42 +0100979 if (rc == -EBUSY) {
980 if (new_skb != skb)
981 dev_kfree_skb_any(new_skb);
982 return NETDEV_TX_BUSY;
983 } else
984 goto tx_drop;
985 }
986
987 netif_wake_queue(dev);
988 if (card->options.performance_stats)
989 card->perf_stats.outbound_time += qeth_get_micros() -
990 card->perf_stats.outbound_start_time;
991 return rc;
992
993tx_drop:
994 card->stats.tx_dropped++;
995 card->stats.tx_errors++;
996 if ((new_skb != skb) && new_skb)
997 dev_kfree_skb_any(new_skb);
998 dev_kfree_skb_any(skb);
Frank Blaschkad0ec0f52008-06-06 12:37:48 +0200999 netif_wake_queue(dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001000 return NETDEV_TX_OK;
1001}
1002
Ursula Braun39423442011-01-12 20:42:24 +00001003static int __qeth_l2_open(struct net_device *dev)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001004{
Heiko Carstens509e2562008-07-26 02:24:10 -07001005 struct qeth_card *card = dev->ml_priv;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001006 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001007
Carsten Otte847a50f2010-06-21 22:57:05 +00001008 QETH_CARD_TEXT(card, 4, "qethopen");
Ursula Braun39423442011-01-12 20:42:24 +00001009 if (card->state == CARD_STATE_UP)
1010 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001011 if (card->state != CARD_STATE_SOFTSETUP)
1012 return -ENODEV;
1013
1014 if ((card->info.type != QETH_CARD_TYPE_OSN) &&
1015 (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001016 QETH_CARD_TEXT(card, 4, "nomacadr");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001017 return -EPERM;
1018 }
1019 card->data.state = CH_STATE_UP;
1020 card->state = CARD_STATE_UP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001021 netif_start_queue(dev);
1022
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001023 if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
1024 napi_enable(&card->napi);
1025 napi_schedule(&card->napi);
1026 } else
1027 rc = -EIO;
1028 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001029}
1030
Ursula Braun39423442011-01-12 20:42:24 +00001031static int qeth_l2_open(struct net_device *dev)
1032{
1033 struct qeth_card *card = dev->ml_priv;
1034
1035 QETH_CARD_TEXT(card, 5, "qethope_");
1036 if (qeth_wait_for_threads(card, QETH_RECOVER_THREAD)) {
1037 QETH_CARD_TEXT(card, 3, "openREC");
1038 return -ERESTARTSYS;
1039 }
1040 return __qeth_l2_open(dev);
1041}
1042
Frank Blaschka4a71df52008-02-15 09:19:42 +01001043static int qeth_l2_stop(struct net_device *dev)
1044{
Heiko Carstens509e2562008-07-26 02:24:10 -07001045 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001046
Carsten Otte847a50f2010-06-21 22:57:05 +00001047 QETH_CARD_TEXT(card, 4, "qethstop");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001048 netif_tx_disable(dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001049 if (card->state == CARD_STATE_UP) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001050 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001051 napi_disable(&card->napi);
1052 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001053 return 0;
1054}
1055
1056static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
1057{
1058 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1059
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001060 qeth_l2_create_device_attributes(&gdev->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001061 INIT_LIST_HEAD(&card->vid_list);
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001062 hash_init(card->mac_htable);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001063 card->options.layer2 = 1;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001064 card->info.hwtrap = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001065 return 0;
1066}
1067
1068static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
1069{
1070 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1071
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001072 qeth_l2_remove_device_attributes(&cgdev->dev);
Ursula Braunf2148562009-05-19 21:38:37 +00001073 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001074 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1075
Ursula Braun70919e22011-02-26 22:41:36 -08001076 if (cgdev->state == CCWGROUP_ONLINE)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001077 qeth_l2_set_offline(cgdev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001078
1079 if (card->dev) {
1080 unregister_netdev(card->dev);
1081 card->dev = NULL;
1082 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001083 return;
1084}
1085
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001086static const struct ethtool_ops qeth_l2_ethtool_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001087 .get_link = ethtool_op_get_link,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001088 .get_strings = qeth_core_get_strings,
1089 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00001090 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001091 .get_drvinfo = qeth_core_get_drvinfo,
Frank Blaschka3f9975a2008-04-24 10:15:23 +02001092 .get_settings = qeth_core_ethtool_get_settings,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001093};
1094
Stephen Hemminger0fc0b732009-09-02 01:03:33 -07001095static const struct ethtool_ops qeth_l2_osn_ops = {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001096 .get_strings = qeth_core_get_strings,
1097 .get_ethtool_stats = qeth_core_get_ethtool_stats,
Ben Hutchingsdf8b4ec2009-10-01 11:24:32 +00001098 .get_sset_count = qeth_core_get_sset_count,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001099 .get_drvinfo = qeth_core_get_drvinfo,
1100};
1101
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001102static const struct net_device_ops qeth_l2_netdev_ops = {
Frank Blaschka8403b132009-01-08 10:50:55 -08001103 .ndo_open = qeth_l2_open,
1104 .ndo_stop = qeth_l2_stop,
1105 .ndo_get_stats = qeth_get_stats,
1106 .ndo_start_xmit = qeth_l2_hard_start_xmit,
1107 .ndo_validate_addr = eth_validate_addr,
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001108 .ndo_set_rx_mode = qeth_l2_set_rx_mode,
Frank Blaschka8403b132009-01-08 10:50:55 -08001109 .ndo_do_ioctl = qeth_l2_do_ioctl,
1110 .ndo_set_mac_address = qeth_l2_set_mac_address,
1111 .ndo_change_mtu = qeth_change_mtu,
1112 .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
1113 .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
1114 .ndo_tx_timeout = qeth_tx_timeout,
Thomas Richter4d7def22015-09-18 16:06:51 +02001115 .ndo_fix_features = qeth_l2_fix_features,
1116 .ndo_set_features = qeth_l2_set_features
Frank Blaschka8403b132009-01-08 10:50:55 -08001117};
1118
Frank Blaschka4a71df52008-02-15 09:19:42 +01001119static int qeth_l2_setup_netdev(struct qeth_card *card)
1120{
1121 switch (card->info.type) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001122 case QETH_CARD_TYPE_IQD:
Tom Gundersenc835a672014-07-14 16:37:24 +02001123 card->dev = alloc_netdev(0, "hsi%d", NET_NAME_UNKNOWN,
1124 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001125 break;
1126 case QETH_CARD_TYPE_OSN:
Tom Gundersenc835a672014-07-14 16:37:24 +02001127 card->dev = alloc_netdev(0, "osn%d", NET_NAME_UNKNOWN,
1128 ether_setup);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001129 card->dev->flags |= IFF_NOARP;
1130 break;
1131 default:
1132 card->dev = alloc_etherdev(0);
1133 }
1134
1135 if (!card->dev)
1136 return -ENODEV;
1137
Heiko Carstens509e2562008-07-26 02:24:10 -07001138 card->dev->ml_priv = card;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001139 card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001140 card->dev->mtu = card->info.initial_mtu;
Frank Blaschka8403b132009-01-08 10:50:55 -08001141 card->dev->netdev_ops = &qeth_l2_netdev_ops;
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +00001142 card->dev->ethtool_ops =
1143 (card->info.type != QETH_CARD_TYPE_OSN) ?
1144 &qeth_l2_ethtool_ops : &qeth_l2_osn_ops;
Patrick McHardyf6469682013-04-19 02:04:27 +00001145 card->dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
Thomas Richter4d7def22015-09-18 16:06:51 +02001146 if (card->info.type == QETH_CARD_TYPE_OSD && !card->info.guestlan) {
Eugene Crosserd52aec92016-06-16 16:18:55 +02001147 card->dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
1148 NETIF_F_SG;
Eugene Crosser2601e4e2016-06-16 16:18:56 +02001149 /* Turn on RX offloading and SG per default */
1150 card->dev->features |= NETIF_F_RXCSUM | NETIF_F_SG;
Thomas Richter4d7def22015-09-18 16:06:51 +02001151 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001152 card->info.broadcast_capable = 1;
1153 qeth_l2_request_initial_mac(card);
Eugene Crosserd52aec92016-06-16 16:18:55 +02001154 card->dev->gso_max_size = (QETH_MAX_BUFFER_ELEMENTS(card) - 1) *
1155 PAGE_SIZE;
1156 card->dev->gso_max_segs = (QETH_MAX_BUFFER_ELEMENTS(card) - 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001157 SET_NETDEV_DEV(card->dev, &card->gdev->dev);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001158 netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
Ursula Braune5ebe632015-12-11 12:27:55 +01001159 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160 return register_netdev(card->dev);
1161}
1162
Thomas Richter4d7def22015-09-18 16:06:51 +02001163static int qeth_l2_start_ipassists(struct qeth_card *card)
1164{
1165 /* configure isolation level */
1166 if (qeth_set_access_ctrl_online(card, 0))
1167 return -ENODEV;
1168 if (qeth_is_supported(card, IPA_INBOUND_CHECKSUM))
1169 qeth_set_rx_csum(card, 1);
1170 qeth_start_ipa_tx_checksum(card);
1171 return 0;
1172}
1173
Frank Blaschka4a71df52008-02-15 09:19:42 +01001174static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
1175{
1176 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1177 int rc = 0;
1178 enum qeth_card_states recover_flag;
1179
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001180 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001181 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001182 QETH_DBF_TEXT(SETUP, 2, "setonlin");
1183 QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001184
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 recover_flag = card->state;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001186 rc = qeth_core_hardsetup_card(card);
1187 if (rc) {
Thomas Richter1aec42b2015-01-21 13:39:10 +01001188 QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001189 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001190 goto out_remove;
1191 }
Eugene Crosserc044dc22014-01-29 09:23:48 +01001192 qeth_bridgeport_query_support(card);
1193 if (card->options.sbp.supported_funcs)
1194 dev_info(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001195 "The device represents a Bridge Capable Port\n");
Stefan Raspl395672e02012-11-19 02:46:49 +00001196 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001197
Ursula Braunaa909222009-11-12 00:11:43 +00001198 if (!card->dev && qeth_l2_setup_netdev(card)) {
1199 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001200 goto out_remove;
Ursula Braunaa909222009-11-12 00:11:43 +00001201 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001202
1203 if (card->info.type != QETH_CARD_TYPE_OSN)
1204 qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
1205
Frank Blaschka1da74b12011-05-12 18:45:02 +00001206 if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
1207 if (card->info.hwtrap &&
1208 qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM))
1209 card->info.hwtrap = 0;
1210 } else
1211 card->info.hwtrap = 0;
1212
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001213 qeth_l2_setup_bridgeport_attrs(card);
1214
Frank Blaschka4a71df52008-02-15 09:19:42 +01001215 card->state = CARD_STATE_HARDSETUP;
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001216 memset(&card->rx, 0, sizeof(struct qeth_rx));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217 qeth_print_status_message(card);
1218
1219 /* softsetup */
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001220 QETH_DBF_TEXT(SETUP, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001221
1222 rc = qeth_send_startlan(card);
1223 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001224 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001225 if (rc == 0xe080) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001226 dev_warn(&card->gdev->dev,
1227 "The LAN is offline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001228 card->lan_online = 0;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001229 goto contin;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001230 }
Ursula Braunaa909222009-11-12 00:11:43 +00001231 rc = -ENODEV;
Ursula Braunf2148562009-05-19 21:38:37 +00001232 goto out_remove;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001233 } else
1234 card->lan_online = 1;
1235
Ursula Braun2b6203b2010-11-26 02:41:19 +00001236contin:
Ursula Braun5113fec2010-05-16 21:15:14 +00001237 if ((card->info.type == QETH_CARD_TYPE_OSD) ||
Stefan Raspl0f547612013-01-21 02:30:20 +00001238 (card->info.type == QETH_CARD_TYPE_OSX)) {
Thomas Richter4d7def22015-09-18 16:06:51 +02001239 if (qeth_l2_start_ipassists(card))
Stefan Raspl0f547612013-01-21 02:30:20 +00001240 goto out_remove;
Stefan Raspl0f547612013-01-21 02:30:20 +00001241 }
Ursula Braun5113fec2010-05-16 21:15:14 +00001242
1243 if (card->info.type != QETH_CARD_TYPE_OSN &&
1244 card->info.type != QETH_CARD_TYPE_OSM)
Ursula Braun70919e22011-02-26 22:41:36 -08001245 qeth_l2_process_vlans(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001246
1247 netif_tx_disable(card->dev);
1248
1249 rc = qeth_init_qdio_queues(card);
1250 if (rc) {
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001251 QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00001252 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001253 goto out_remove;
1254 }
1255 card->state = CARD_STATE_SOFTSETUP;
Ursula Braun2b6203b2010-11-26 02:41:19 +00001256 if (card->lan_online)
1257 netif_carrier_on(card->dev);
1258 else
1259 netif_carrier_off(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001260
1261 qeth_set_allowed_threads(card, 0xffffffff, 0);
1262 if (recover_flag == CARD_STATE_RECOVER) {
1263 if (recovery_mode &&
1264 card->info.type != QETH_CARD_TYPE_OSN) {
Ursula Braun39423442011-01-12 20:42:24 +00001265 __qeth_l2_open(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001266 } else {
1267 rtnl_lock();
1268 dev_open(card->dev);
1269 rtnl_unlock();
1270 }
1271 /* this also sets saved unicast addresses */
Lakhvich Dmitriyfe5c8022015-10-06 15:12:28 +02001272 qeth_l2_set_rx_mode(card->dev);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273 }
1274 /* let user_space know that device is online */
1275 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001276 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001277 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001278 return 0;
Ursula Braunaa909222009-11-12 00:11:43 +00001279
Frank Blaschka4a71df52008-02-15 09:19:42 +01001280out_remove:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001281 qeth_l2_stop_card(card, 0);
1282 ccw_device_set_offline(CARD_DDEV(card));
1283 ccw_device_set_offline(CARD_WDEV(card));
1284 ccw_device_set_offline(CARD_RDEV(card));
Ursula Braun22ae2792014-02-24 13:12:06 +01001285 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001286 if (recover_flag == CARD_STATE_RECOVER)
1287 card->state = CARD_STATE_RECOVER;
1288 else
1289 card->state = CARD_STATE_DOWN;
Frank Blaschkac4949f02010-05-11 19:34:47 +00001290 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001291 mutex_unlock(&card->discipline_mutex);
Ursula Braunaa909222009-11-12 00:11:43 +00001292 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001293}
1294
1295static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1296{
1297 return __qeth_l2_set_online(gdev, 0);
1298}
1299
1300static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1301 int recovery_mode)
1302{
1303 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1304 int rc = 0, rc2 = 0, rc3 = 0;
1305 enum qeth_card_states recover_flag;
1306
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001307 mutex_lock(&card->discipline_mutex);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001308 mutex_lock(&card->conf_mutex);
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001309 QETH_DBF_TEXT(SETUP, 3, "setoffl");
1310 QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001311
1312 if (card->dev && netif_carrier_ok(card->dev))
1313 netif_carrier_off(card->dev);
1314 recover_flag = card->state;
Frank Blaschka1da74b12011-05-12 18:45:02 +00001315 if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1316 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
1317 card->info.hwtrap = 1;
1318 }
Ursula Braun0f5623c2008-10-24 11:16:52 +02001319 qeth_l2_stop_card(card, recovery_mode);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001320 rc = ccw_device_set_offline(CARD_DDEV(card));
1321 rc2 = ccw_device_set_offline(CARD_WDEV(card));
1322 rc3 = ccw_device_set_offline(CARD_RDEV(card));
1323 if (!rc)
1324 rc = (rc2) ? rc2 : rc3;
1325 if (rc)
Peter Tiedemannd11ba0c2008-04-01 10:26:58 +02001326 QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
Ursula Braun22ae2792014-02-24 13:12:06 +01001327 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001328 if (recover_flag == CARD_STATE_UP)
1329 card->state = CARD_STATE_RECOVER;
1330 /* let user_space know that device is offline */
1331 kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
Frank Blaschkac4949f02010-05-11 19:34:47 +00001332 mutex_unlock(&card->conf_mutex);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00001333 mutex_unlock(&card->discipline_mutex);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001334 return 0;
1335}
1336
1337static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1338{
1339 return __qeth_l2_set_offline(cgdev, 0);
1340}
1341
1342static int qeth_l2_recover(void *ptr)
1343{
1344 struct qeth_card *card;
1345 int rc = 0;
1346
1347 card = (struct qeth_card *) ptr;
Carsten Otte847a50f2010-06-21 22:57:05 +00001348 QETH_CARD_TEXT(card, 2, "recover1");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001349 if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD))
1350 return 0;
Carsten Otte847a50f2010-06-21 22:57:05 +00001351 QETH_CARD_TEXT(card, 2, "recover2");
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001352 dev_warn(&card->gdev->dev,
1353 "A recovery process has been started for the device\n");
Stefan Raspl65d80132013-04-07 22:19:27 +00001354 qeth_set_recovery_task(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001355 __qeth_l2_set_offline(card->gdev, 1);
1356 rc = __qeth_l2_set_online(card->gdev, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001357 if (!rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001358 dev_info(&card->gdev->dev,
1359 "Device successfully recovered!\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001360 else {
Stefan Raspl0f547612013-01-21 02:30:20 +00001361 qeth_close_dev(card);
1362 dev_warn(&card->gdev->dev, "The qeth device driver "
Stefan Raspl2efaf5f2012-10-15 19:21:18 +00001363 "failed to recover an error on the device\n");
Ursula Braun28a7e4c2008-09-19 12:56:03 +02001364 }
Stefan Raspl65d80132013-04-07 22:19:27 +00001365 qeth_clear_recovery_task(card);
Frank Blaschkaa1c3ed42010-09-07 21:14:42 +00001366 qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD);
1367 qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001368 return 0;
1369}
1370
1371static int __init qeth_l2_init(void)
1372{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001373 pr_info("register layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001374 return 0;
1375}
1376
1377static void __exit qeth_l2_exit(void)
1378{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01001379 pr_info("unregister layer 2 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001380}
1381
1382static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1383{
1384 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braunf78ac2b2011-12-19 22:56:33 +00001385 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka1da74b12011-05-12 18:45:02 +00001386 if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1387 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001388 qeth_qdio_clear_card(card, 0);
1389 qeth_clear_qdio_buffers(card);
Ursula Braun22ae2792014-02-24 13:12:06 +01001390 qdio_free(CARD_DDEV(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391}
1392
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001393static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1394{
1395 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1396
1397 if (card->dev)
1398 netif_device_detach(card->dev);
1399 qeth_set_allowed_threads(card, 0, 1);
1400 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1401 if (gdev->state == CCWGROUP_OFFLINE)
1402 return 0;
1403 if (card->state == CARD_STATE_UP) {
Frank Blaschka1da74b12011-05-12 18:45:02 +00001404 if (card->info.hwtrap)
1405 qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM);
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001406 __qeth_l2_set_offline(card->gdev, 1);
1407 } else
1408 __qeth_l2_set_offline(card->gdev, 0);
1409 return 0;
1410}
1411
1412static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1413{
1414 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1415 int rc = 0;
1416
1417 if (gdev->state == CCWGROUP_OFFLINE)
1418 goto out;
1419
1420 if (card->state == CARD_STATE_RECOVER) {
1421 rc = __qeth_l2_set_online(card->gdev, 1);
1422 if (rc) {
Ursula Braun869da902010-03-08 20:36:56 +00001423 rtnl_lock();
1424 dev_close(card->dev);
1425 rtnl_unlock();
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001426 }
1427 } else
1428 rc = __qeth_l2_set_online(card->gdev, 0);
1429out:
1430 qeth_set_allowed_threads(card, 0xffffffff, 0);
1431 if (card->dev)
1432 netif_device_attach(card->dev);
1433 if (rc)
1434 dev_warn(&card->gdev->dev, "The qeth device driver "
1435 "failed to recover an error on the device\n");
1436 return rc;
1437}
1438
Eugene Crosserc044dc22014-01-29 09:23:48 +01001439/* Returns zero if the command is successfully "consumed" */
1440static int qeth_l2_control_event(struct qeth_card *card,
1441 struct qeth_ipa_cmd *cmd)
1442{
1443 switch (cmd->hdr.command) {
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001444 case IPA_CMD_SETBRIDGEPORT_OSA:
1445 case IPA_CMD_SETBRIDGEPORT_IQD:
Eugene Crosserc044dc22014-01-29 09:23:48 +01001446 if (cmd->data.sbp.hdr.command_code ==
1447 IPA_SBP_BRIDGE_PORT_STATE_CHANGE) {
1448 qeth_bridge_state_change(card, cmd);
1449 return 0;
1450 } else
1451 return 1;
1452 case IPA_CMD_ADDRESS_CHANGE_NOTIF:
1453 qeth_bridge_host_event(card, cmd);
1454 return 0;
1455 default:
1456 return 1;
1457 }
1458}
1459
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001460struct qeth_discipline qeth_l2_discipline = {
1461 .start_poll = qeth_qdio_start_poll,
1462 .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1463 .output_handler = (qdio_handler_t *) qeth_qdio_output_handler,
1464 .recover = qeth_l2_recover,
1465 .setup = qeth_l2_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001466 .remove = qeth_l2_remove_device,
1467 .set_online = qeth_l2_set_online,
1468 .set_offline = qeth_l2_set_offline,
1469 .shutdown = qeth_l2_shutdown,
Frank Blaschkabbcfcdc2009-06-16 10:30:31 +02001470 .freeze = qeth_l2_pm_suspend,
1471 .thaw = qeth_l2_pm_resume,
1472 .restore = qeth_l2_pm_resume,
Eugene Crosserc044dc22014-01-29 09:23:48 +01001473 .control_event_handler = qeth_l2_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01001474};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02001475EXPORT_SYMBOL_GPL(qeth_l2_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001476
1477static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1478 struct qeth_cmd_buffer *iob)
1479{
1480 unsigned long flags;
1481 int rc = 0;
1482
Carsten Otte847a50f2010-06-21 22:57:05 +00001483 QETH_CARD_TEXT(card, 5, "osndctrd");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001484
1485 wait_event(card->wait_q,
1486 atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1487 qeth_prepare_control_data(card, len, iob);
Carsten Otte847a50f2010-06-21 22:57:05 +00001488 QETH_CARD_TEXT(card, 6, "osnoirqp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001489 spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1490 rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1491 (addr_t) iob, 0, 0);
1492 spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1493 if (rc) {
Frank Blaschka14cc21b2008-06-06 12:37:46 +02001494 QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
Frank Blaschka4a71df52008-02-15 09:19:42 +01001495 "ccw_device_start rc = %i\n", rc);
Carsten Otte847a50f2010-06-21 22:57:05 +00001496 QETH_CARD_TEXT_(card, 2, " err%d", rc);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001497 qeth_release_buffer(iob->channel, iob);
1498 atomic_set(&card->write.irq_pending, 0);
1499 wake_up(&card->wait_q);
1500 }
1501 return rc;
1502}
1503
1504static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1505 struct qeth_cmd_buffer *iob, int data_len)
1506{
1507 u16 s1, s2;
1508
Carsten Otte847a50f2010-06-21 22:57:05 +00001509 QETH_CARD_TEXT(card, 4, "osndipa");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001510
1511 qeth_prepare_ipa_cmd(card, iob, QETH_PROT_OSN2);
1512 s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1513 s2 = (u16)data_len;
1514 memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1515 memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1516 memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1517 memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1518 return qeth_osn_send_control_data(card, s1, iob);
1519}
1520
1521int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1522{
1523 struct qeth_cmd_buffer *iob;
1524 struct qeth_card *card;
1525 int rc;
1526
Frank Blaschka4a71df52008-02-15 09:19:42 +01001527 if (!dev)
1528 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001529 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001530 if (!card)
1531 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001532 QETH_CARD_TEXT(card, 2, "osnsdmc");
Eugene Crosserc3521252015-01-16 14:05:47 +01001533 if (!qeth_card_hw_is_reachable(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001534 return -ENODEV;
1535 iob = qeth_wait_for_buffer(&card->write);
1536 memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1537 rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1538 return rc;
1539}
1540EXPORT_SYMBOL(qeth_osn_assist);
1541
1542int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1543 int (*assist_cb)(struct net_device *, void *),
1544 int (*data_cb)(struct sk_buff *))
1545{
1546 struct qeth_card *card;
1547
Frank Blaschka4a71df52008-02-15 09:19:42 +01001548 *dev = qeth_l2_netdev_by_devno(read_dev_no);
1549 if (*dev == NULL)
1550 return -ENODEV;
Heiko Carstens509e2562008-07-26 02:24:10 -07001551 card = (*dev)->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001552 if (!card)
1553 return -ENODEV;
Carsten Otte847a50f2010-06-21 22:57:05 +00001554 QETH_CARD_TEXT(card, 2, "osnreg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001555 if ((assist_cb == NULL) || (data_cb == NULL))
1556 return -EINVAL;
1557 card->osn_info.assist_cb = assist_cb;
1558 card->osn_info.data_cb = data_cb;
1559 return 0;
1560}
1561EXPORT_SYMBOL(qeth_osn_register);
1562
1563void qeth_osn_deregister(struct net_device *dev)
1564{
1565 struct qeth_card *card;
1566
Frank Blaschka4a71df52008-02-15 09:19:42 +01001567 if (!dev)
1568 return;
Heiko Carstens509e2562008-07-26 02:24:10 -07001569 card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001570 if (!card)
1571 return;
Carsten Otte847a50f2010-06-21 22:57:05 +00001572 QETH_CARD_TEXT(card, 2, "osndereg");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001573 card->osn_info.assist_cb = NULL;
1574 card->osn_info.data_cb = NULL;
1575 return;
1576}
1577EXPORT_SYMBOL(qeth_osn_deregister);
1578
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001579/* SETBRIDGEPORT support, async notifications */
1580
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001581enum qeth_an_event_type {anev_reg_unreg, anev_abort, anev_reset};
1582
1583/**
1584 * qeth_bridge_emit_host_event() - bridgeport address change notification
1585 * @card: qeth_card structure pointer, for udev events.
1586 * @evtype: "normal" register/unregister, or abort, or reset. For abort
1587 * and reset token and addr_lnid are unused and may be NULL.
1588 * @code: event bitmask: high order bit 0x80 value 1 means removal of an
1589 * object, 0 - addition of an object.
1590 * 0x01 - VLAN, 0x02 - MAC, 0x03 - VLAN and MAC.
1591 * @token: "network token" structure identifying physical address of the port.
1592 * @addr_lnid: pointer to structure with MAC address and VLAN ID.
1593 *
1594 * This function is called when registrations and deregistrations are
1595 * reported by the hardware, and also when notifications are enabled -
1596 * for all currently registered addresses.
1597 */
1598static void qeth_bridge_emit_host_event(struct qeth_card *card,
1599 enum qeth_an_event_type evtype,
1600 u8 code, struct net_if_token *token, struct mac_addr_lnid *addr_lnid)
1601{
1602 char str[7][32];
1603 char *env[8];
1604 int i = 0;
1605
1606 switch (evtype) {
1607 case anev_reg_unreg:
1608 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=%s",
1609 (code & IPA_ADDR_CHANGE_CODE_REMOVAL)
1610 ? "deregister" : "register");
1611 env[i] = str[i]; i++;
1612 if (code & IPA_ADDR_CHANGE_CODE_VLANID) {
1613 snprintf(str[i], sizeof(str[i]), "VLAN=%d",
1614 addr_lnid->lnid);
1615 env[i] = str[i]; i++;
1616 }
1617 if (code & IPA_ADDR_CHANGE_CODE_MACADDR) {
Eugene Crosser9846e702015-09-18 16:06:48 +02001618 snprintf(str[i], sizeof(str[i]), "MAC=%pM",
Thomas Richter4d7def22015-09-18 16:06:51 +02001619 addr_lnid->mac);
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001620 env[i] = str[i]; i++;
1621 }
1622 snprintf(str[i], sizeof(str[i]), "NTOK_BUSID=%x.%x.%04x",
1623 token->cssid, token->ssid, token->devnum);
1624 env[i] = str[i]; i++;
1625 snprintf(str[i], sizeof(str[i]), "NTOK_IID=%02x", token->iid);
1626 env[i] = str[i]; i++;
1627 snprintf(str[i], sizeof(str[i]), "NTOK_CHPID=%02x",
1628 token->chpid);
1629 env[i] = str[i]; i++;
1630 snprintf(str[i], sizeof(str[i]), "NTOK_CHID=%04x", token->chid);
1631 env[i] = str[i]; i++;
1632 break;
1633 case anev_abort:
1634 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=abort");
1635 env[i] = str[i]; i++;
1636 break;
1637 case anev_reset:
1638 snprintf(str[i], sizeof(str[i]), "BRIDGEDHOST=reset");
1639 env[i] = str[i]; i++;
1640 break;
1641 }
1642 env[i] = NULL;
1643 kobject_uevent_env(&card->gdev->dev.kobj, KOBJ_CHANGE, env);
1644}
1645
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001646struct qeth_bridge_state_data {
1647 struct work_struct worker;
1648 struct qeth_card *card;
1649 struct qeth_sbp_state_change qports;
1650};
1651
1652static void qeth_bridge_state_change_worker(struct work_struct *work)
1653{
1654 struct qeth_bridge_state_data *data =
1655 container_of(work, struct qeth_bridge_state_data, worker);
1656 /* We are only interested in the first entry - local port */
1657 struct qeth_sbp_port_entry *entry = &data->qports.entry[0];
1658 char env_locrem[32];
1659 char env_role[32];
1660 char env_state[32];
1661 char *env[] = {
1662 env_locrem,
1663 env_role,
1664 env_state,
1665 NULL
1666 };
1667
1668 /* Role should not change by itself, but if it did, */
1669 /* information from the hardware is authoritative. */
1670 mutex_lock(&data->card->conf_mutex);
1671 data->card->options.sbp.role = entry->role;
1672 mutex_unlock(&data->card->conf_mutex);
1673
1674 snprintf(env_locrem, sizeof(env_locrem), "BRIDGEPORT=statechange");
1675 snprintf(env_role, sizeof(env_role), "ROLE=%s",
1676 (entry->role == QETH_SBP_ROLE_NONE) ? "none" :
1677 (entry->role == QETH_SBP_ROLE_PRIMARY) ? "primary" :
1678 (entry->role == QETH_SBP_ROLE_SECONDARY) ? "secondary" :
1679 "<INVALID>");
1680 snprintf(env_state, sizeof(env_state), "STATE=%s",
1681 (entry->state == QETH_SBP_STATE_INACTIVE) ? "inactive" :
1682 (entry->state == QETH_SBP_STATE_STANDBY) ? "standby" :
1683 (entry->state == QETH_SBP_STATE_ACTIVE) ? "active" :
1684 "<INVALID>");
1685 kobject_uevent_env(&data->card->gdev->dev.kobj,
1686 KOBJ_CHANGE, env);
1687 kfree(data);
1688}
1689
Eugene Crosserc044dc22014-01-29 09:23:48 +01001690static void qeth_bridge_state_change(struct qeth_card *card,
1691 struct qeth_ipa_cmd *cmd)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001692{
1693 struct qeth_sbp_state_change *qports =
1694 &cmd->data.sbp.data.state_change;
1695 struct qeth_bridge_state_data *data;
1696 int extrasize;
1697
1698 QETH_CARD_TEXT(card, 2, "brstchng");
1699 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
Thomas Richter8a593142014-10-22 12:18:03 +02001700 QETH_CARD_TEXT_(card, 2, "BPsz%04x", qports->entry_length);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001701 return;
1702 }
1703 extrasize = sizeof(struct qeth_sbp_port_entry) * qports->num_entries;
1704 data = kzalloc(sizeof(struct qeth_bridge_state_data) + extrasize,
1705 GFP_ATOMIC);
1706 if (!data) {
1707 QETH_CARD_TEXT(card, 2, "BPSalloc");
1708 return;
1709 }
1710 INIT_WORK(&data->worker, qeth_bridge_state_change_worker);
1711 data->card = card;
1712 memcpy(&data->qports, qports,
1713 sizeof(struct qeth_sbp_state_change) + extrasize);
1714 queue_work(qeth_wq, &data->worker);
1715}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001716
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001717struct qeth_bridge_host_data {
1718 struct work_struct worker;
1719 struct qeth_card *card;
1720 struct qeth_ipacmd_addr_change hostevs;
1721};
1722
1723static void qeth_bridge_host_event_worker(struct work_struct *work)
1724{
1725 struct qeth_bridge_host_data *data =
1726 container_of(work, struct qeth_bridge_host_data, worker);
1727 int i;
1728
1729 if (data->hostevs.lost_event_mask) {
1730 dev_info(&data->card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001731"Address notification from the Bridge Port stopped %s (%s)\n",
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001732 data->card->dev->name,
1733 (data->hostevs.lost_event_mask == 0x01)
1734 ? "Overflow"
1735 : (data->hostevs.lost_event_mask == 0x02)
1736 ? "Bridge port state change"
1737 : "Unknown reason");
1738 mutex_lock(&data->card->conf_mutex);
1739 data->card->options.sbp.hostnotification = 0;
1740 mutex_unlock(&data->card->conf_mutex);
1741 qeth_bridge_emit_host_event(data->card, anev_abort,
1742 0, NULL, NULL);
1743 } else
1744 for (i = 0; i < data->hostevs.num_entries; i++) {
1745 struct qeth_ipacmd_addr_change_entry *entry =
1746 &data->hostevs.entry[i];
1747 qeth_bridge_emit_host_event(data->card,
1748 anev_reg_unreg,
1749 entry->change_code,
1750 &entry->token, &entry->addr_lnid);
1751 }
1752 kfree(data);
1753}
1754
Eugene Crosserc044dc22014-01-29 09:23:48 +01001755static void qeth_bridge_host_event(struct qeth_card *card,
1756 struct qeth_ipa_cmd *cmd)
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001757{
1758 struct qeth_ipacmd_addr_change *hostevs =
1759 &cmd->data.addrchange;
1760 struct qeth_bridge_host_data *data;
1761 int extrasize;
1762
1763 QETH_CARD_TEXT(card, 2, "brhostev");
1764 if (cmd->hdr.return_code != 0x0000) {
1765 if (cmd->hdr.return_code == 0x0010) {
1766 if (hostevs->lost_event_mask == 0x00)
1767 hostevs->lost_event_mask = 0xff;
1768 } else {
1769 QETH_CARD_TEXT_(card, 2, "BPHe%04x",
1770 cmd->hdr.return_code);
1771 return;
1772 }
1773 }
1774 extrasize = sizeof(struct qeth_ipacmd_addr_change_entry) *
1775 hostevs->num_entries;
1776 data = kzalloc(sizeof(struct qeth_bridge_host_data) + extrasize,
1777 GFP_ATOMIC);
1778 if (!data) {
1779 QETH_CARD_TEXT(card, 2, "BPHalloc");
1780 return;
1781 }
1782 INIT_WORK(&data->worker, qeth_bridge_host_event_worker);
1783 data->card = card;
1784 memcpy(&data->hostevs, hostevs,
1785 sizeof(struct qeth_ipacmd_addr_change) + extrasize);
1786 queue_work(qeth_wq, &data->worker);
1787}
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01001788
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001789/* SETBRIDGEPORT support; sending commands */
1790
1791struct _qeth_sbp_cbctl {
1792 u16 ipa_rc;
1793 u16 cmd_rc;
1794 union {
1795 u32 supported;
1796 struct {
1797 enum qeth_sbp_roles *role;
1798 enum qeth_sbp_states *state;
1799 } qports;
1800 } data;
1801};
1802
1803/**
1804 * qeth_bridgeport_makerc() - derive "traditional" error from hardware codes.
1805 * @card: qeth_card structure pointer, for debug messages.
1806 * @cbctl: state structure with hardware return codes.
1807 * @setcmd: IPA command code
1808 *
1809 * Returns negative errno-compatible error indication or 0 on success.
1810 */
1811static int qeth_bridgeport_makerc(struct qeth_card *card,
1812 struct _qeth_sbp_cbctl *cbctl, enum qeth_ipa_sbp_cmd setcmd)
1813{
1814 int rc;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001815 int is_iqd = (card->info.type == QETH_CARD_TYPE_IQD);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001816
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001817 if ((is_iqd && (cbctl->ipa_rc == IPA_RC_SUCCESS)) ||
1818 (!is_iqd && (cbctl->ipa_rc == cbctl->cmd_rc)))
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001819 switch (cbctl->cmd_rc) {
1820 case 0x0000:
1821 rc = 0;
1822 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001823 case 0x2B04:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001824 case 0x0004:
Eugene Crosserffb95252015-05-18 14:27:58 +02001825 rc = -EOPNOTSUPP;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001826 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001827 case 0x2B0C:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001828 case 0x000C: /* Not configured as bridge Port */
1829 rc = -ENODEV; /* maybe not the best code here? */
1830 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001831 "The device is not configured as a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001832 break;
Eugene Crosser1b05cf62016-06-16 16:18:51 +02001833 case 0x2B10:
1834 case 0x0010: /* OS mismatch */
1835 rc = -EPERM;
1836 dev_err(&card->gdev->dev,
1837 "A Bridge Port is already configured by a different operating system\n");
1838 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001839 case 0x2B14:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001840 case 0x0014: /* Another device is Primary */
1841 switch (setcmd) {
1842 case IPA_SBP_SET_PRIMARY_BRIDGE_PORT:
1843 rc = -EEXIST;
1844 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001845 "The LAN already has a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001846 break;
1847 case IPA_SBP_SET_SECONDARY_BRIDGE_PORT:
1848 rc = -EBUSY;
1849 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001850 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001851 break;
1852 default:
1853 rc = -EIO;
1854 }
1855 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001856 case 0x2B18:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001857 case 0x0018: /* This device is currently Secondary */
1858 rc = -EBUSY;
1859 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001860 "The device is already a secondary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001861 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001862 case 0x2B1C:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001863 case 0x001C: /* Limit for Secondary devices reached */
1864 rc = -EEXIST;
1865 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001866 "The LAN cannot have more secondary Bridge Ports\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001867 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001868 case 0x2B24:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001869 case 0x0024: /* This device is currently Primary */
1870 rc = -EBUSY;
1871 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001872 "The device is already a primary Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001873 break;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001874 case 0x2B20:
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001875 case 0x0020: /* Not authorized by zManager */
1876 rc = -EACCES;
1877 dev_err(&card->gdev->dev,
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001878 "The device is not authorized to be a Bridge Port\n");
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001879 break;
1880 default:
1881 rc = -EIO;
1882 }
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001883 else
1884 switch (cbctl->ipa_rc) {
1885 case IPA_RC_NOTSUPP:
Eugene Crosserffb95252015-05-18 14:27:58 +02001886 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001887 break;
1888 case IPA_RC_UNSUPPORTED_COMMAND:
Eugene Crosserffb95252015-05-18 14:27:58 +02001889 rc = -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001890 break;
1891 default:
1892 rc = -EIO;
1893 }
1894
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001895 if (rc) {
1896 QETH_CARD_TEXT_(card, 2, "SBPi%04x", cbctl->ipa_rc);
1897 QETH_CARD_TEXT_(card, 2, "SBPc%04x", cbctl->cmd_rc);
1898 }
1899 return rc;
1900}
1901
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001902static inline int ipa_cmd_sbp(struct qeth_card *card)
1903{
1904 return (card->info.type == QETH_CARD_TYPE_IQD) ?
1905 IPA_CMD_SETBRIDGEPORT_IQD :
1906 IPA_CMD_SETBRIDGEPORT_OSA;
1907}
1908
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001909static int qeth_bridgeport_query_support_cb(struct qeth_card *card,
1910 struct qeth_reply *reply, unsigned long data)
1911{
1912 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1913 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1914 QETH_CARD_TEXT(card, 2, "brqsupcb");
1915 cbctl->ipa_rc = cmd->hdr.return_code;
1916 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1917 if ((cbctl->ipa_rc == 0) && (cbctl->cmd_rc == 0)) {
1918 cbctl->data.supported =
1919 cmd->data.sbp.data.query_cmds_supp.supported_cmds;
1920 } else {
1921 cbctl->data.supported = 0;
1922 }
1923 return 0;
1924}
1925
1926/**
1927 * qeth_bridgeport_query_support() - store bitmask of supported subfunctions.
1928 * @card: qeth_card structure pointer.
1929 *
1930 * Sets bitmask of supported setbridgeport subfunctions in the qeth_card
1931 * strucutre: card->options.sbp.supported_funcs.
1932 */
Eugene Crosserc044dc22014-01-29 09:23:48 +01001933static void qeth_bridgeport_query_support(struct qeth_card *card)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001934{
1935 struct qeth_cmd_buffer *iob;
1936 struct qeth_ipa_cmd *cmd;
1937 struct _qeth_sbp_cbctl cbctl;
1938
1939 QETH_CARD_TEXT(card, 2, "brqsuppo");
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02001940 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001941 if (!iob)
1942 return;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001943 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
1944 cmd->data.sbp.hdr.cmdlength =
1945 sizeof(struct qeth_ipacmd_sbp_hdr) +
1946 sizeof(struct qeth_sbp_query_cmds_supp);
1947 cmd->data.sbp.hdr.command_code =
1948 IPA_SBP_QUERY_COMMANDS_SUPPORTED;
1949 cmd->data.sbp.hdr.used_total = 1;
1950 cmd->data.sbp.hdr.seq_no = 1;
1951 if (qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_support_cb,
1952 (void *)&cbctl) ||
1953 qeth_bridgeport_makerc(card, &cbctl,
1954 IPA_SBP_QUERY_COMMANDS_SUPPORTED)) {
1955 /* non-zero makerc signifies failure, and produce messages */
1956 card->options.sbp.role = QETH_SBP_ROLE_NONE;
1957 return;
1958 }
1959 card->options.sbp.supported_funcs = cbctl.data.supported;
1960}
Eugene Crosserb4d72c02014-01-14 15:54:11 +01001961
1962static int qeth_bridgeport_query_ports_cb(struct qeth_card *card,
1963 struct qeth_reply *reply, unsigned long data)
1964{
1965 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1966 struct qeth_sbp_query_ports *qports = &cmd->data.sbp.data.query_ports;
1967 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
1968
1969 QETH_CARD_TEXT(card, 2, "brqprtcb");
1970 cbctl->ipa_rc = cmd->hdr.return_code;
1971 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
1972 if ((cbctl->ipa_rc != 0) || (cbctl->cmd_rc != 0))
1973 return 0;
1974 if (qports->entry_length != sizeof(struct qeth_sbp_port_entry)) {
1975 cbctl->cmd_rc = 0xffff;
1976 QETH_CARD_TEXT_(card, 2, "SBPs%04x", qports->entry_length);
1977 return 0;
1978 }
1979 /* first entry contains the state of the local port */
1980 if (qports->num_entries > 0) {
1981 if (cbctl->data.qports.role)
1982 *cbctl->data.qports.role = qports->entry[0].role;
1983 if (cbctl->data.qports.state)
1984 *cbctl->data.qports.state = qports->entry[0].state;
1985 }
1986 return 0;
1987}
1988
1989/**
1990 * qeth_bridgeport_query_ports() - query local bridgeport status.
1991 * @card: qeth_card structure pointer.
1992 * @role: Role of the port: 0-none, 1-primary, 2-secondary.
1993 * @state: State of the port: 0-inactive, 1-standby, 2-active.
1994 *
1995 * Returns negative errno-compatible error indication or 0 on success.
1996 *
1997 * 'role' and 'state' are not updated in case of hardware operation failure.
1998 */
1999int qeth_bridgeport_query_ports(struct qeth_card *card,
2000 enum qeth_sbp_roles *role, enum qeth_sbp_states *state)
2001{
2002 int rc = 0;
2003 struct qeth_cmd_buffer *iob;
2004 struct qeth_ipa_cmd *cmd;
2005 struct _qeth_sbp_cbctl cbctl = {
2006 .data = {
2007 .qports = {
2008 .role = role,
2009 .state = state,
2010 },
2011 },
2012 };
2013
2014 QETH_CARD_TEXT(card, 2, "brqports");
2015 if (!(card->options.sbp.supported_funcs & IPA_SBP_QUERY_BRIDGE_PORTS))
2016 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02002017 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002018 if (!iob)
2019 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002020 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2021 cmd->data.sbp.hdr.cmdlength =
2022 sizeof(struct qeth_ipacmd_sbp_hdr);
2023 cmd->data.sbp.hdr.command_code =
2024 IPA_SBP_QUERY_BRIDGE_PORTS;
2025 cmd->data.sbp.hdr.used_total = 1;
2026 cmd->data.sbp.hdr.seq_no = 1;
2027 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_query_ports_cb,
2028 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02002029 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002030 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02002031 return qeth_bridgeport_makerc(card, &cbctl, IPA_SBP_QUERY_BRIDGE_PORTS);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002032}
2033EXPORT_SYMBOL_GPL(qeth_bridgeport_query_ports);
2034
2035static int qeth_bridgeport_set_cb(struct qeth_card *card,
2036 struct qeth_reply *reply, unsigned long data)
2037{
2038 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
2039 struct _qeth_sbp_cbctl *cbctl = (struct _qeth_sbp_cbctl *)reply->param;
2040 QETH_CARD_TEXT(card, 2, "brsetrcb");
2041 cbctl->ipa_rc = cmd->hdr.return_code;
2042 cbctl->cmd_rc = cmd->data.sbp.hdr.return_code;
2043 return 0;
2044}
2045
2046/**
2047 * qeth_bridgeport_setrole() - Assign primary role to the port.
2048 * @card: qeth_card structure pointer.
2049 * @role: Role to assign.
2050 *
2051 * Returns negative errno-compatible error indication or 0 on success.
2052 */
2053int qeth_bridgeport_setrole(struct qeth_card *card, enum qeth_sbp_roles role)
2054{
2055 int rc = 0;
2056 int cmdlength;
2057 struct qeth_cmd_buffer *iob;
2058 struct qeth_ipa_cmd *cmd;
2059 struct _qeth_sbp_cbctl cbctl;
2060 enum qeth_ipa_sbp_cmd setcmd;
2061
2062 QETH_CARD_TEXT(card, 2, "brsetrol");
2063 switch (role) {
2064 case QETH_SBP_ROLE_NONE:
2065 setcmd = IPA_SBP_RESET_BRIDGE_PORT_ROLE;
2066 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2067 sizeof(struct qeth_sbp_reset_role);
2068 break;
2069 case QETH_SBP_ROLE_PRIMARY:
2070 setcmd = IPA_SBP_SET_PRIMARY_BRIDGE_PORT;
2071 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2072 sizeof(struct qeth_sbp_set_primary);
2073 break;
2074 case QETH_SBP_ROLE_SECONDARY:
2075 setcmd = IPA_SBP_SET_SECONDARY_BRIDGE_PORT;
2076 cmdlength = sizeof(struct qeth_ipacmd_sbp_hdr) +
2077 sizeof(struct qeth_sbp_set_secondary);
2078 break;
2079 default:
2080 return -EINVAL;
2081 }
2082 if (!(card->options.sbp.supported_funcs & setcmd))
2083 return -EOPNOTSUPP;
Eugene Crosser9c23f4da2015-05-18 14:27:56 +02002084 iob = qeth_get_ipacmd_buffer(card, ipa_cmd_sbp(card), 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01002085 if (!iob)
2086 return -ENOMEM;
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002087 cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
2088 cmd->data.sbp.hdr.cmdlength = cmdlength;
2089 cmd->data.sbp.hdr.command_code = setcmd;
2090 cmd->data.sbp.hdr.used_total = 1;
2091 cmd->data.sbp.hdr.seq_no = 1;
2092 rc = qeth_send_ipa_cmd(card, iob, qeth_bridgeport_set_cb,
2093 (void *)&cbctl);
Eugene Crosserc88394e2015-05-18 14:27:53 +02002094 if (rc < 0)
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002095 return rc;
Eugene Crosserc88394e2015-05-18 14:27:53 +02002096 return qeth_bridgeport_makerc(card, &cbctl, setcmd);
Eugene Crosserb4d72c02014-01-14 15:54:11 +01002097}
2098
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01002099/**
2100 * qeth_anset_makerc() - derive "traditional" error from hardware codes.
2101 * @card: qeth_card structure pointer, for debug messages.
2102 *
2103 * Returns negative errno-compatible error indication or 0 on success.
2104 */
2105static int qeth_anset_makerc(struct qeth_card *card, int pnso_rc, u16 response)
2106{
2107 int rc;
2108
2109 if (pnso_rc == 0)
2110 switch (response) {
2111 case 0x0001:
2112 rc = 0;
2113 break;
2114 case 0x0004:
2115 case 0x0100:
2116 case 0x0106:
Eugene Crosserffb95252015-05-18 14:27:58 +02002117 rc = -EOPNOTSUPP;
Eugene Crosser9f48b9d2014-01-14 15:54:13 +01002118 dev_err(&card->gdev->dev,
2119 "Setting address notification failed\n");
2120 break;
2121 case 0x0107:
2122 rc = -EAGAIN;
2123 break;
2124 default:
2125 rc = -EIO;
2126 }
2127 else
2128 rc = -EIO;
2129
2130 if (rc) {
2131 QETH_CARD_TEXT_(card, 2, "SBPp%04x", pnso_rc);
2132 QETH_CARD_TEXT_(card, 2, "SBPr%04x", response);
2133 }
2134 return rc;
2135}
2136
2137static void qeth_bridgeport_an_set_cb(void *priv,
2138 enum qdio_brinfo_entry_type type, void *entry)
2139{
2140 struct qeth_card *card = (struct qeth_card *)priv;
2141 struct qdio_brinfo_entry_l2 *l2entry;
2142 u8 code;
2143
2144 if (type != l2_addr_lnid) {
2145 WARN_ON_ONCE(1);
2146 return;
2147 }
2148
2149 l2entry = (struct qdio_brinfo_entry_l2 *)entry;
2150 code = IPA_ADDR_CHANGE_CODE_MACADDR;
2151 if (l2entry->addr_lnid.lnid)
2152 code |= IPA_ADDR_CHANGE_CODE_VLANID;
2153 qeth_bridge_emit_host_event(card, anev_reg_unreg, code,
2154 (struct net_if_token *)&l2entry->nit,
2155 (struct mac_addr_lnid *)&l2entry->addr_lnid);
2156}
2157
2158/**
2159 * qeth_bridgeport_an_set() - Enable or disable bridgeport address notification
2160 * @card: qeth_card structure pointer.
2161 * @enable: 0 - disable, non-zero - enable notifications
2162 *
2163 * Returns negative errno-compatible error indication or 0 on success.
2164 *
2165 * On enable, emits a series of address notifications udev events for all
2166 * currently registered hosts.
2167 */
2168int qeth_bridgeport_an_set(struct qeth_card *card, int enable)
2169{
2170 int rc;
2171 u16 response;
2172 struct ccw_device *ddev;
2173 struct subchannel_id schid;
2174
2175 if (!card)
2176 return -EINVAL;
2177 if (!card->options.sbp.supported_funcs)
2178 return -EOPNOTSUPP;
2179 ddev = CARD_DDEV(card);
2180 ccw_device_get_schid(ddev, &schid);
2181
2182 if (enable) {
2183 qeth_bridge_emit_host_event(card, anev_reset, 0, NULL, NULL);
2184 rc = qdio_pnso_brinfo(schid, 1, &response,
2185 qeth_bridgeport_an_set_cb, card);
2186 } else
2187 rc = qdio_pnso_brinfo(schid, 0, &response, NULL, NULL);
2188 return qeth_anset_makerc(card, rc, response);
2189}
2190EXPORT_SYMBOL_GPL(qeth_bridgeport_an_set);
2191
Frank Blaschka4a71df52008-02-15 09:19:42 +01002192module_init(qeth_l2_init);
2193module_exit(qeth_l2_exit);
2194MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2195MODULE_DESCRIPTION("qeth layer 2 discipline");
2196MODULE_LICENSE("GPL");