Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qeth_l2_main.c
Go to the documentation of this file.
1 /*
2  * Copyright IBM Corp. 2007, 2009
3  * Author(s): Utz Bacher <[email protected]>,
4  * Frank Pavlic <[email protected]>,
5  * Thomas Spatzier <[email protected]>,
6  * Frank Blaschka <[email protected]>
7  */
8 
9 #define KMSG_COMPONENT "qeth"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 
12 #include <linux/module.h>
13 #include <linux/moduleparam.h>
14 #include <linux/string.h>
15 #include <linux/errno.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
18 #include <linux/etherdevice.h>
19 #include <linux/mii.h>
20 #include <linux/ip.h>
21 #include <linux/list.h>
22 
23 #include "qeth_core.h"
24 
25 static int qeth_l2_set_offline(struct ccwgroup_device *);
26 static int qeth_l2_stop(struct net_device *);
27 static int qeth_l2_send_delmac(struct qeth_card *, __u8 *);
28 static int qeth_l2_send_setdelmac(struct qeth_card *, __u8 *,
29  enum qeth_ipa_cmds,
30  int (*reply_cb) (struct qeth_card *,
31  struct qeth_reply*,
32  unsigned long));
33 static void qeth_l2_set_multicast_list(struct net_device *);
34 static int qeth_l2_recover(void *);
35 
36 static int qeth_l2_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37 {
38  struct qeth_card *card = dev->ml_priv;
39  struct mii_ioctl_data *mii_data;
40  int rc = 0;
41 
42  if (!card)
43  return -ENODEV;
44 
45  if ((card->state != CARD_STATE_UP) &&
46  (card->state != CARD_STATE_SOFTSETUP))
47  return -ENODEV;
48 
49  if (card->info.type == QETH_CARD_TYPE_OSN)
50  return -EPERM;
51 
52  switch (cmd) {
54  rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data);
55  break;
57  if ((card->info.type == QETH_CARD_TYPE_OSD ||
58  card->info.type == QETH_CARD_TYPE_OSM ||
59  card->info.type == QETH_CARD_TYPE_OSX) &&
60  !card->info.guestlan)
61  return 1;
62  return 0;
63  break;
64  case SIOCGMIIPHY:
65  mii_data = if_mii(rq);
66  mii_data->phy_id = 0;
67  break;
68  case SIOCGMIIREG:
69  mii_data = if_mii(rq);
70  if (mii_data->phy_id != 0)
71  rc = -EINVAL;
72  else
73  mii_data->val_out = qeth_mdio_read(dev,
74  mii_data->phy_id, mii_data->reg_num);
75  break;
78  break;
79  default:
80  rc = -EOPNOTSUPP;
81  }
82  if (rc)
83  QETH_CARD_TEXT_(card, 2, "ioce%d", rc);
84  return rc;
85 }
86 
87 static int qeth_l2_verify_dev(struct net_device *dev)
88 {
89  struct qeth_card *card;
90  unsigned long flags;
91  int rc = 0;
92 
93  read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
95  if (card->dev == dev) {
96  rc = QETH_REAL_CARD;
97  break;
98  }
99  }
101 
102  return rc;
103 }
104 
105 static struct net_device *qeth_l2_netdev_by_devno(unsigned char *read_dev_no)
106 {
107  struct qeth_card *card;
108  struct net_device *ndev;
109  __u16 temp_dev_no;
110  unsigned long flags;
111  struct ccw_dev_id read_devid;
112 
113  ndev = NULL;
114  memcpy(&temp_dev_no, read_dev_no, 2);
115  read_lock_irqsave(&qeth_core_card_list.rwlock, flags);
117  ccw_device_get_id(CARD_RDEV(card), &read_devid);
118  if (read_devid.devno == temp_dev_no) {
119  ndev = card->dev;
120  break;
121  }
122  }
124  return ndev;
125 }
126 
127 static int qeth_l2_send_setgroupmac_cb(struct qeth_card *card,
128  struct qeth_reply *reply,
129  unsigned long data)
130 {
131  struct qeth_ipa_cmd *cmd;
132  __u8 *mac;
133 
134  QETH_CARD_TEXT(card, 2, "L2Sgmacb");
135  cmd = (struct qeth_ipa_cmd *) data;
136  mac = &cmd->data.setdelmac.mac[0];
137  /* MAC already registered, needed in couple/uncouple case */
138  if (cmd->hdr.return_code == IPA_RC_L2_DUP_MAC) {
139  QETH_DBF_MESSAGE(2, "Group MAC %pM already existing on %s \n",
140  mac, QETH_CARD_IFNAME(card));
141  cmd->hdr.return_code = 0;
142  }
143  if (cmd->hdr.return_code)
144  QETH_DBF_MESSAGE(2, "Could not set group MAC %pM on %s: %x\n",
145  mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
146  return 0;
147 }
148 
149 static int qeth_l2_send_setgroupmac(struct qeth_card *card, __u8 *mac)
150 {
151  QETH_CARD_TEXT(card, 2, "L2Sgmac");
152  return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETGMAC,
153  qeth_l2_send_setgroupmac_cb);
154 }
155 
156 static int qeth_l2_send_delgroupmac_cb(struct qeth_card *card,
157  struct qeth_reply *reply,
158  unsigned long data)
159 {
160  struct qeth_ipa_cmd *cmd;
161  __u8 *mac;
162 
163  QETH_CARD_TEXT(card, 2, "L2Dgmacb");
164  cmd = (struct qeth_ipa_cmd *) data;
165  mac = &cmd->data.setdelmac.mac[0];
166  if (cmd->hdr.return_code)
167  QETH_DBF_MESSAGE(2, "Could not delete group MAC %pM on %s: %x\n",
168  mac, QETH_CARD_IFNAME(card), cmd->hdr.return_code);
169  return 0;
170 }
171 
172 static int qeth_l2_send_delgroupmac(struct qeth_card *card, __u8 *mac)
173 {
174  QETH_CARD_TEXT(card, 2, "L2Dgmac");
175  return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELGMAC,
176  qeth_l2_send_delgroupmac_cb);
177 }
178 
179 static void qeth_l2_add_mc(struct qeth_card *card, __u8 *mac, int vmac)
180 {
181  struct qeth_mc_mac *mc;
182  int rc;
183 
184  mc = kmalloc(sizeof(struct qeth_mc_mac), GFP_ATOMIC);
185 
186  if (!mc)
187  return;
188 
189  memcpy(mc->mc_addr, mac, OSA_ADDR_LEN);
190  mc->mc_addrlen = OSA_ADDR_LEN;
191  mc->is_vmac = vmac;
192 
193  if (vmac) {
194  rc = qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
195  NULL);
196  } else {
197  rc = qeth_l2_send_setgroupmac(card, mac);
198  }
199 
200  if (!rc)
201  list_add_tail(&mc->list, &card->mc_list);
202  else
203  kfree(mc);
204 }
205 
206 static void qeth_l2_del_all_mc(struct qeth_card *card, int del)
207 {
208  struct qeth_mc_mac *mc, *tmp;
209 
210  spin_lock_bh(&card->mclock);
211  list_for_each_entry_safe(mc, tmp, &card->mc_list, list) {
212  if (del) {
213  if (mc->is_vmac)
214  qeth_l2_send_setdelmac(card, mc->mc_addr,
216  else
217  qeth_l2_send_delgroupmac(card, mc->mc_addr);
218  }
219  list_del(&mc->list);
220  kfree(mc);
221  }
222  spin_unlock_bh(&card->mclock);
223 }
224 
225 static inline int qeth_l2_get_cast_type(struct qeth_card *card,
226  struct sk_buff *skb)
227 {
228  if (card->info.type == QETH_CARD_TYPE_OSN)
229  return RTN_UNSPEC;
230  if (is_broadcast_ether_addr(skb->data))
231  return RTN_BROADCAST;
232  if (is_multicast_ether_addr(skb->data))
233  return RTN_MULTICAST;
234  return RTN_UNSPEC;
235 }
236 
237 static void qeth_l2_fill_header(struct qeth_card *card, struct qeth_hdr *hdr,
238  struct sk_buff *skb, int ipv, int cast_type)
239 {
240  struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb_mac_header(skb);
241 
242  memset(hdr, 0, sizeof(struct qeth_hdr));
243  hdr->hdr.l2.id = QETH_HEADER_TYPE_LAYER2;
244 
245  /* set byte byte 3 to casting flags */
246  if (cast_type == RTN_MULTICAST)
247  hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_MULTICAST;
248  else if (cast_type == RTN_BROADCAST)
249  hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_BROADCAST;
250  else
251  hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_UNICAST;
252 
253  hdr->hdr.l2.pkt_length = skb->len-QETH_HEADER_SIZE;
254  /* VSWITCH relies on the VLAN
255  * information to be present in
256  * the QDIO header */
257  if (veth->h_vlan_proto == __constant_htons(ETH_P_8021Q)) {
258  hdr->hdr.l2.flags[2] |= QETH_LAYER2_FLAG_VLAN;
259  hdr->hdr.l2.vlan_id = ntohs(veth->h_vlan_TCI);
260  }
261 }
262 
263 static int qeth_l2_send_setdelvlan_cb(struct qeth_card *card,
264  struct qeth_reply *reply, unsigned long data)
265 {
266  struct qeth_ipa_cmd *cmd;
267 
268  QETH_CARD_TEXT(card, 2, "L2sdvcb");
269  cmd = (struct qeth_ipa_cmd *) data;
270  if (cmd->hdr.return_code) {
271  QETH_DBF_MESSAGE(2, "Error in processing VLAN %i on %s: 0x%x. "
272  "Continuing\n", cmd->data.setdelvlan.vlan_id,
273  QETH_CARD_IFNAME(card), cmd->hdr.return_code);
274  QETH_CARD_TEXT_(card, 2, "L2VL%4x", cmd->hdr.command);
275  QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
276  }
277  return 0;
278 }
279 
280 static int qeth_l2_send_setdelvlan(struct qeth_card *card, __u16 i,
281  enum qeth_ipa_cmds ipacmd)
282 {
283  struct qeth_ipa_cmd *cmd;
284  struct qeth_cmd_buffer *iob;
285 
286  QETH_CARD_TEXT_(card, 4, "L2sdv%x", ipacmd);
287  iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
288  cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
289  cmd->data.setdelvlan.vlan_id = i;
290  return qeth_send_ipa_cmd(card, iob,
291  qeth_l2_send_setdelvlan_cb, NULL);
292 }
293 
294 static void qeth_l2_process_vlans(struct qeth_card *card)
295 {
296  struct qeth_vlan_vid *id;
297  QETH_CARD_TEXT(card, 3, "L2prcvln");
298  spin_lock_bh(&card->vlanlock);
299  list_for_each_entry(id, &card->vid_list, list) {
300  qeth_l2_send_setdelvlan(card, id->vid, IPA_CMD_SETVLAN);
301  }
302  spin_unlock_bh(&card->vlanlock);
303 }
304 
305 static int qeth_l2_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
306 {
307  struct qeth_card *card = dev->ml_priv;
308  struct qeth_vlan_vid *id;
309 
310  QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
311  if (!vid)
312  return 0;
313  if (card->info.type == QETH_CARD_TYPE_OSM) {
314  QETH_CARD_TEXT(card, 3, "aidOSM");
315  return 0;
316  }
318  QETH_CARD_TEXT(card, 3, "aidREC");
319  return 0;
320  }
321  id = kmalloc(sizeof(struct qeth_vlan_vid), GFP_ATOMIC);
322  if (id) {
323  id->vid = vid;
324  qeth_l2_send_setdelvlan(card, vid, IPA_CMD_SETVLAN);
325  spin_lock_bh(&card->vlanlock);
326  list_add_tail(&id->list, &card->vid_list);
327  spin_unlock_bh(&card->vlanlock);
328  } else {
329  return -ENOMEM;
330  }
331  return 0;
332 }
333 
334 static int qeth_l2_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
335 {
336  struct qeth_vlan_vid *id, *tmpid = NULL;
337  struct qeth_card *card = dev->ml_priv;
338 
339  QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
340  if (card->info.type == QETH_CARD_TYPE_OSM) {
341  QETH_CARD_TEXT(card, 3, "kidOSM");
342  return 0;
343  }
345  QETH_CARD_TEXT(card, 3, "kidREC");
346  return 0;
347  }
348  spin_lock_bh(&card->vlanlock);
349  list_for_each_entry(id, &card->vid_list, list) {
350  if (id->vid == vid) {
351  list_del(&id->list);
352  tmpid = id;
353  break;
354  }
355  }
356  spin_unlock_bh(&card->vlanlock);
357  if (tmpid) {
358  qeth_l2_send_setdelvlan(card, vid, IPA_CMD_DELVLAN);
359  kfree(tmpid);
360  }
361  qeth_l2_set_multicast_list(card->dev);
362  return 0;
363 }
364 
365 static int qeth_l2_stop_card(struct qeth_card *card, int recovery_mode)
366 {
367  int rc = 0;
368 
369  QETH_DBF_TEXT(SETUP , 2, "stopcard");
370  QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
371 
372  qeth_set_allowed_threads(card, 0, 1);
373  if (card->read.state == CH_STATE_UP &&
374  card->write.state == CH_STATE_UP &&
375  (card->state == CARD_STATE_UP)) {
376  if (recovery_mode &&
377  card->info.type != QETH_CARD_TYPE_OSN) {
378  qeth_l2_stop(card->dev);
379  } else {
380  rtnl_lock();
381  dev_close(card->dev);
382  rtnl_unlock();
383  }
384  card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
385  card->state = CARD_STATE_SOFTSETUP;
386  }
387  if (card->state == CARD_STATE_SOFTSETUP) {
388  qeth_l2_del_all_mc(card, 0);
390  card->state = CARD_STATE_HARDSETUP;
391  }
392  if (card->state == CARD_STATE_HARDSETUP) {
393  qeth_qdio_clear_card(card, 0);
396  card->state = CARD_STATE_DOWN;
397  }
398  if (card->state == CARD_STATE_DOWN) {
401  }
402  return rc;
403 }
404 
405 static int qeth_l2_process_inbound_buffer(struct qeth_card *card,
406  int budget, int *done)
407 {
408  int work_done = 0;
409  struct sk_buff *skb;
410  struct qeth_hdr *hdr;
411  unsigned int len;
412 
413  *done = 0;
414  BUG_ON(!budget);
415  while (budget) {
416  skb = qeth_core_get_next_skb(card,
417  &card->qdio.in_q->bufs[card->rx.b_index],
418  &card->rx.b_element, &card->rx.e_offset, &hdr);
419  if (!skb) {
420  *done = 1;
421  break;
422  }
423  skb->dev = card->dev;
424  switch (hdr->hdr.l2.id) {
426  skb->pkt_type = PACKET_HOST;
427  skb->protocol = eth_type_trans(skb, skb->dev);
428  skb->ip_summed = CHECKSUM_NONE;
429  if (skb->protocol == htons(ETH_P_802_2))
430  *((__u32 *)skb->cb) = ++card->seqno.pkt_seqno;
431  len = skb->len;
432  netif_receive_skb(skb);
433  break;
435  if (card->info.type == QETH_CARD_TYPE_OSN) {
436  skb_push(skb, sizeof(struct qeth_hdr));
437  skb_copy_to_linear_data(skb, hdr,
438  sizeof(struct qeth_hdr));
439  len = skb->len;
440  card->osn_info.data_cb(skb);
441  break;
442  }
443  /* else unknown */
444  default:
445  dev_kfree_skb_any(skb);
446  QETH_CARD_TEXT(card, 3, "inbunkno");
448  continue;
449  }
450  work_done++;
451  budget--;
452  card->stats.rx_packets++;
453  card->stats.rx_bytes += len;
454  }
455  return work_done;
456 }
457 
458 static int qeth_l2_poll(struct napi_struct *napi, int budget)
459 {
460  struct qeth_card *card = container_of(napi, struct qeth_card, napi);
461  int work_done = 0;
462  struct qeth_qdio_buffer *buffer;
463  int done;
464  int new_budget = budget;
465 
466  if (card->options.performance_stats) {
467  card->perf_stats.inbound_cnt++;
468  card->perf_stats.inbound_start_time = qeth_get_micros();
469  }
470 
471  while (1) {
472  if (!card->rx.b_count) {
473  card->rx.qdio_err = 0;
474  card->rx.b_count = qdio_get_next_buffers(
475  card->data.ccwdev, 0, &card->rx.b_index,
476  &card->rx.qdio_err);
477  if (card->rx.b_count <= 0) {
478  card->rx.b_count = 0;
479  break;
480  }
481  card->rx.b_element =
482  &card->qdio.in_q->bufs[card->rx.b_index]
483  .buffer->element[0];
484  card->rx.e_offset = 0;
485  }
486 
487  while (card->rx.b_count) {
488  buffer = &card->qdio.in_q->bufs[card->rx.b_index];
489  if (!(card->rx.qdio_err &&
490  qeth_check_qdio_errors(card, buffer->buffer,
491  card->rx.qdio_err, "qinerr")))
492  work_done += qeth_l2_process_inbound_buffer(
493  card, new_budget, &done);
494  else
495  done = 1;
496 
497  if (done) {
498  if (card->options.performance_stats)
499  card->perf_stats.bufs_rec++;
500  qeth_put_buffer_pool_entry(card,
501  buffer->pool_entry);
502  qeth_queue_input_buffer(card, card->rx.b_index);
503  card->rx.b_count--;
504  if (card->rx.b_count) {
505  card->rx.b_index =
506  (card->rx.b_index + 1) %
508  card->rx.b_element =
509  &card->qdio.in_q
510  ->bufs[card->rx.b_index]
511  .buffer->element[0];
512  card->rx.e_offset = 0;
513  }
514  }
515 
516  if (work_done >= budget)
517  goto out;
518  else
519  new_budget = budget - work_done;
520  }
521  }
522 
523  napi_complete(napi);
524  if (qdio_start_irq(card->data.ccwdev, 0))
525  napi_schedule(&card->napi);
526 out:
527  if (card->options.performance_stats)
528  card->perf_stats.inbound_time += qeth_get_micros() -
529  card->perf_stats.inbound_start_time;
530  return work_done;
531 }
532 
533 static int qeth_l2_send_setdelmac(struct qeth_card *card, __u8 *mac,
534  enum qeth_ipa_cmds ipacmd,
535  int (*reply_cb) (struct qeth_card *,
536  struct qeth_reply*,
537  unsigned long))
538 {
539  struct qeth_ipa_cmd *cmd;
540  struct qeth_cmd_buffer *iob;
541 
542  QETH_CARD_TEXT(card, 2, "L2sdmac");
543  iob = qeth_get_ipacmd_buffer(card, ipacmd, QETH_PROT_IPV4);
544  cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE);
545  cmd->data.setdelmac.mac_length = OSA_ADDR_LEN;
546  memcpy(&cmd->data.setdelmac.mac, mac, OSA_ADDR_LEN);
547  return qeth_send_ipa_cmd(card, iob, reply_cb, NULL);
548 }
549 
550 static int qeth_l2_send_setmac_cb(struct qeth_card *card,
551  struct qeth_reply *reply,
552  unsigned long data)
553 {
554  struct qeth_ipa_cmd *cmd;
555 
556  QETH_CARD_TEXT(card, 2, "L2Smaccb");
557  cmd = (struct qeth_ipa_cmd *) data;
558  if (cmd->hdr.return_code) {
559  QETH_CARD_TEXT_(card, 2, "L2er%x", cmd->hdr.return_code);
560  card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
561  switch (cmd->hdr.return_code) {
562  case IPA_RC_L2_DUP_MAC:
564  dev_warn(&card->gdev->dev,
565  "MAC address %pM already exists\n",
566  cmd->data.setdelmac.mac);
567  break;
570  dev_warn(&card->gdev->dev,
571  "MAC address %pM is not authorized\n",
572  cmd->data.setdelmac.mac);
573  break;
574  default:
575  break;
576  }
577  } else {
578  card->info.mac_bits |= QETH_LAYER2_MAC_REGISTERED;
579  memcpy(card->dev->dev_addr, cmd->data.setdelmac.mac,
580  OSA_ADDR_LEN);
581  dev_info(&card->gdev->dev,
582  "MAC address %pM successfully registered on device %s\n",
583  card->dev->dev_addr, card->dev->name);
584  }
585  return 0;
586 }
587 
588 static int qeth_l2_send_setmac(struct qeth_card *card, __u8 *mac)
589 {
590  QETH_CARD_TEXT(card, 2, "L2Setmac");
591  return qeth_l2_send_setdelmac(card, mac, IPA_CMD_SETVMAC,
592  qeth_l2_send_setmac_cb);
593 }
594 
595 static int qeth_l2_send_delmac_cb(struct qeth_card *card,
596  struct qeth_reply *reply,
597  unsigned long data)
598 {
599  struct qeth_ipa_cmd *cmd;
600 
601  QETH_CARD_TEXT(card, 2, "L2Dmaccb");
602  cmd = (struct qeth_ipa_cmd *) data;
603  if (cmd->hdr.return_code) {
604  QETH_CARD_TEXT_(card, 2, "err%d", cmd->hdr.return_code);
605  return 0;
606  }
607  card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
608 
609  return 0;
610 }
611 
612 static int qeth_l2_send_delmac(struct qeth_card *card, __u8 *mac)
613 {
614  QETH_CARD_TEXT(card, 2, "L2Delmac");
615  if (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))
616  return 0;
617  return qeth_l2_send_setdelmac(card, mac, IPA_CMD_DELVMAC,
618  qeth_l2_send_delmac_cb);
619 }
620 
621 static int qeth_l2_request_initial_mac(struct qeth_card *card)
622 {
623  int rc = 0;
624  char vendor_pre[] = {0x02, 0x00, 0x00};
625 
626  QETH_DBF_TEXT(SETUP, 2, "doL2init");
627  QETH_DBF_TEXT_(SETUP, 2, "doL2%s", CARD_BUS_ID(card));
628 
630  rc = qeth_query_setadapterparms(card);
631  if (rc) {
632  QETH_DBF_MESSAGE(2, "could not query adapter "
633  "parameters on device %s: x%x\n",
634  CARD_BUS_ID(card), rc);
635  }
636  }
637 
638  if (card->info.type == QETH_CARD_TYPE_IQD ||
639  card->info.type == QETH_CARD_TYPE_OSM ||
640  card->info.type == QETH_CARD_TYPE_OSX ||
641  card->info.guestlan) {
643  if (rc) {
644  QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
645  "device %s: x%x\n", CARD_BUS_ID(card), rc);
646  QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
647  return rc;
648  }
649  QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, OSA_ADDR_LEN);
650  } else {
651  eth_random_addr(card->dev->dev_addr);
652  memcpy(card->dev->dev_addr, vendor_pre, 3);
653  }
654  return 0;
655 }
656 
657 static int qeth_l2_set_mac_address(struct net_device *dev, void *p)
658 {
659  struct sockaddr *addr = p;
660  struct qeth_card *card = dev->ml_priv;
661  int rc = 0;
662 
663  QETH_CARD_TEXT(card, 3, "setmac");
664 
665  if (qeth_l2_verify_dev(dev) != QETH_REAL_CARD) {
666  QETH_CARD_TEXT(card, 3, "setmcINV");
667  return -EOPNOTSUPP;
668  }
669 
670  if (card->info.type == QETH_CARD_TYPE_OSN ||
671  card->info.type == QETH_CARD_TYPE_OSM ||
672  card->info.type == QETH_CARD_TYPE_OSX) {
673  QETH_CARD_TEXT(card, 3, "setmcTYP");
674  return -EOPNOTSUPP;
675  }
676  QETH_CARD_HEX(card, 3, addr->sa_data, OSA_ADDR_LEN);
678  QETH_CARD_TEXT(card, 3, "setmcREC");
679  return -ERESTARTSYS;
680  }
681  rc = qeth_l2_send_delmac(card, &card->dev->dev_addr[0]);
682  if (!rc || (rc == IPA_RC_L2_MAC_NOT_FOUND))
683  rc = qeth_l2_send_setmac(card, addr->sa_data);
684  return rc ? -EINVAL : 0;
685 }
686 
687 static void qeth_l2_set_multicast_list(struct net_device *dev)
688 {
689  struct qeth_card *card = dev->ml_priv;
690  struct netdev_hw_addr *ha;
691 
692  if (card->info.type == QETH_CARD_TYPE_OSN)
693  return ;
694 
695  QETH_CARD_TEXT(card, 3, "setmulti");
697  (card->state != CARD_STATE_UP))
698  return;
699  qeth_l2_del_all_mc(card, 1);
700  spin_lock_bh(&card->mclock);
701  netdev_for_each_mc_addr(ha, dev)
702  qeth_l2_add_mc(card, ha->addr, 0);
703 
704  netdev_for_each_uc_addr(ha, dev)
705  qeth_l2_add_mc(card, ha->addr, 1);
706 
707  spin_unlock_bh(&card->mclock);
709  return;
711 }
712 
713 static int qeth_l2_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
714 {
715  int rc;
716  struct qeth_hdr *hdr = NULL;
717  int elements = 0;
718  struct qeth_card *card = dev->ml_priv;
719  struct sk_buff *new_skb = skb;
720  int ipv = qeth_get_ip_version(skb);
721  int cast_type = qeth_l2_get_cast_type(card, skb);
722  struct qeth_qdio_out_q *queue = card->qdio.out_qs
723  [qeth_get_priority_queue(card, skb, ipv, cast_type)];
724  int tx_bytes = skb->len;
725  int data_offset = -1;
726  int elements_needed = 0;
727  int hd_len = 0;
728 
729  if ((card->state != CARD_STATE_UP) || !card->lan_online) {
730  card->stats.tx_carrier_errors++;
731  goto tx_drop;
732  }
733 
734  if ((card->info.type == QETH_CARD_TYPE_OSN) &&
735  (skb->protocol == htons(ETH_P_IPV6)))
736  goto tx_drop;
737 
738  if (card->options.performance_stats) {
739  card->perf_stats.outbound_cnt++;
740  card->perf_stats.outbound_start_time = qeth_get_micros();
741  }
742  netif_stop_queue(dev);
743 
744  if (card->info.type == QETH_CARD_TYPE_OSN)
745  hdr = (struct qeth_hdr *)skb->data;
746  else {
747  if (card->info.type == QETH_CARD_TYPE_IQD) {
748  new_skb = skb;
749  data_offset = ETH_HLEN;
750  hd_len = ETH_HLEN;
752  GFP_ATOMIC);
753  if (!hdr)
754  goto tx_drop;
755  elements_needed++;
756  skb_reset_mac_header(new_skb);
757  qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
758  hdr->hdr.l2.pkt_length = new_skb->len;
759  memcpy(((char *)hdr) + sizeof(struct qeth_hdr),
760  skb_mac_header(new_skb), ETH_HLEN);
761  } else {
762  /* create a clone with writeable headroom */
763  new_skb = skb_realloc_headroom(skb,
764  sizeof(struct qeth_hdr));
765  if (!new_skb)
766  goto tx_drop;
767  hdr = (struct qeth_hdr *)skb_push(new_skb,
768  sizeof(struct qeth_hdr));
769  skb_set_mac_header(new_skb, sizeof(struct qeth_hdr));
770  qeth_l2_fill_header(card, hdr, new_skb, ipv, cast_type);
771  }
772  }
773 
774  elements = qeth_get_elements_no(card, (void *)hdr, new_skb,
775  elements_needed);
776  if (!elements) {
777  if (data_offset >= 0)
779  goto tx_drop;
780  }
781 
782  if (card->info.type != QETH_CARD_TYPE_IQD) {
783  if (qeth_hdr_chk_and_bounce(new_skb,
784  sizeof(struct qeth_hdr_layer2)))
785  goto tx_drop;
786  rc = qeth_do_send_packet(card, queue, new_skb, hdr,
787  elements);
788  } else
789  rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr,
790  elements, data_offset, hd_len);
791  if (!rc) {
792  card->stats.tx_packets++;
793  card->stats.tx_bytes += tx_bytes;
794  if (new_skb != skb)
795  dev_kfree_skb_any(skb);
796  rc = NETDEV_TX_OK;
797  } else {
798  if (data_offset >= 0)
800 
801  if (rc == -EBUSY) {
802  if (new_skb != skb)
803  dev_kfree_skb_any(new_skb);
804  return NETDEV_TX_BUSY;
805  } else
806  goto tx_drop;
807  }
808 
809  netif_wake_queue(dev);
810  if (card->options.performance_stats)
811  card->perf_stats.outbound_time += qeth_get_micros() -
812  card->perf_stats.outbound_start_time;
813  return rc;
814 
815 tx_drop:
816  card->stats.tx_dropped++;
817  card->stats.tx_errors++;
818  if ((new_skb != skb) && new_skb)
819  dev_kfree_skb_any(new_skb);
820  dev_kfree_skb_any(skb);
821  netif_wake_queue(dev);
822  return NETDEV_TX_OK;
823 }
824 
825 static int __qeth_l2_open(struct net_device *dev)
826 {
827  struct qeth_card *card = dev->ml_priv;
828  int rc = 0;
829 
830  QETH_CARD_TEXT(card, 4, "qethopen");
831  if (card->state == CARD_STATE_UP)
832  return rc;
833  if (card->state != CARD_STATE_SOFTSETUP)
834  return -ENODEV;
835 
836  if ((card->info.type != QETH_CARD_TYPE_OSN) &&
837  (!(card->info.mac_bits & QETH_LAYER2_MAC_REGISTERED))) {
838  QETH_CARD_TEXT(card, 4, "nomacadr");
839  return -EPERM;
840  }
841  card->data.state = CH_STATE_UP;
842  card->state = CARD_STATE_UP;
843  netif_start_queue(dev);
844 
845  if (qdio_stop_irq(card->data.ccwdev, 0) >= 0) {
846  napi_enable(&card->napi);
847  napi_schedule(&card->napi);
848  } else
849  rc = -EIO;
850  return rc;
851 }
852 
853 static int qeth_l2_open(struct net_device *dev)
854 {
855  struct qeth_card *card = dev->ml_priv;
856 
857  QETH_CARD_TEXT(card, 5, "qethope_");
859  QETH_CARD_TEXT(card, 3, "openREC");
860  return -ERESTARTSYS;
861  }
862  return __qeth_l2_open(dev);
863 }
864 
865 static int qeth_l2_stop(struct net_device *dev)
866 {
867  struct qeth_card *card = dev->ml_priv;
868 
869  QETH_CARD_TEXT(card, 4, "qethstop");
870  netif_tx_disable(dev);
871  if (card->state == CARD_STATE_UP) {
872  card->state = CARD_STATE_SOFTSETUP;
873  napi_disable(&card->napi);
874  }
875  return 0;
876 }
877 
878 static int qeth_l2_probe_device(struct ccwgroup_device *gdev)
879 {
880  struct qeth_card *card = dev_get_drvdata(&gdev->dev);
881 
882  INIT_LIST_HEAD(&card->vid_list);
883  INIT_LIST_HEAD(&card->mc_list);
884  card->options.layer2 = 1;
885  card->info.hwtrap = 0;
886  return 0;
887 }
888 
889 static void qeth_l2_remove_device(struct ccwgroup_device *cgdev)
890 {
891  struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
892 
893  qeth_set_allowed_threads(card, 0, 1);
894  wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
895 
896  if (cgdev->state == CCWGROUP_ONLINE)
897  qeth_l2_set_offline(cgdev);
898 
899  if (card->dev) {
900  unregister_netdev(card->dev);
901  card->dev = NULL;
902  }
903  return;
904 }
905 
906 static const struct ethtool_ops qeth_l2_ethtool_ops = {
907  .get_link = ethtool_op_get_link,
908  .get_strings = qeth_core_get_strings,
909  .get_ethtool_stats = qeth_core_get_ethtool_stats,
910  .get_sset_count = qeth_core_get_sset_count,
911  .get_drvinfo = qeth_core_get_drvinfo,
912  .get_settings = qeth_core_ethtool_get_settings,
913 };
914 
915 static const struct ethtool_ops qeth_l2_osn_ops = {
916  .get_strings = qeth_core_get_strings,
917  .get_ethtool_stats = qeth_core_get_ethtool_stats,
918  .get_sset_count = qeth_core_get_sset_count,
919  .get_drvinfo = qeth_core_get_drvinfo,
920 };
921 
922 static const struct net_device_ops qeth_l2_netdev_ops = {
923  .ndo_open = qeth_l2_open,
924  .ndo_stop = qeth_l2_stop,
925  .ndo_get_stats = qeth_get_stats,
926  .ndo_start_xmit = qeth_l2_hard_start_xmit,
927  .ndo_validate_addr = eth_validate_addr,
928  .ndo_set_rx_mode = qeth_l2_set_multicast_list,
929  .ndo_do_ioctl = qeth_l2_do_ioctl,
930  .ndo_set_mac_address = qeth_l2_set_mac_address,
931  .ndo_change_mtu = qeth_change_mtu,
932  .ndo_vlan_rx_add_vid = qeth_l2_vlan_rx_add_vid,
933  .ndo_vlan_rx_kill_vid = qeth_l2_vlan_rx_kill_vid,
934  .ndo_tx_timeout = qeth_tx_timeout,
935 };
936 
937 static int qeth_l2_setup_netdev(struct qeth_card *card)
938 {
939  switch (card->info.type) {
940  case QETH_CARD_TYPE_IQD:
941  card->dev = alloc_netdev(0, "hsi%d", ether_setup);
942  break;
943  case QETH_CARD_TYPE_OSN:
944  card->dev = alloc_netdev(0, "osn%d", ether_setup);
945  card->dev->flags |= IFF_NOARP;
946  break;
947  default:
948  card->dev = alloc_etherdev(0);
949  }
950 
951  if (!card->dev)
952  return -ENODEV;
953 
954  card->dev->ml_priv = card;
955  card->dev->watchdog_timeo = QETH_TX_TIMEOUT;
956  card->dev->mtu = card->info.initial_mtu;
957  card->dev->netdev_ops = &qeth_l2_netdev_ops;
958  if (card->info.type != QETH_CARD_TYPE_OSN)
959  SET_ETHTOOL_OPS(card->dev, &qeth_l2_ethtool_ops);
960  else
961  SET_ETHTOOL_OPS(card->dev, &qeth_l2_osn_ops);
962  card->dev->features |= NETIF_F_HW_VLAN_FILTER;
963  card->info.broadcast_capable = 1;
964  qeth_l2_request_initial_mac(card);
965  SET_NETDEV_DEV(card->dev, &card->gdev->dev);
966  netif_napi_add(card->dev, &card->napi, qeth_l2_poll, QETH_NAPI_WEIGHT);
967  return register_netdev(card->dev);
968 }
969 
970 static int __qeth_l2_set_online(struct ccwgroup_device *gdev, int recovery_mode)
971 {
972  struct qeth_card *card = dev_get_drvdata(&gdev->dev);
973  int rc = 0;
974  enum qeth_card_states recover_flag;
975 
976  BUG_ON(!card);
978  mutex_lock(&card->conf_mutex);
979  QETH_DBF_TEXT(SETUP, 2, "setonlin");
980  QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *));
981 
982  recover_flag = card->state;
983  rc = qeth_core_hardsetup_card(card);
984  if (rc) {
985  QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc);
986  rc = -ENODEV;
987  goto out_remove;
988  }
989 
990  if (!card->dev && qeth_l2_setup_netdev(card)) {
991  rc = -ENODEV;
992  goto out_remove;
993  }
994 
995  if (card->info.type != QETH_CARD_TYPE_OSN)
996  qeth_l2_send_setmac(card, &card->dev->dev_addr[0]);
997 
998  if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) {
999  if (card->info.hwtrap &&
1001  card->info.hwtrap = 0;
1002  } else
1003  card->info.hwtrap = 0;
1004 
1005  card->state = CARD_STATE_HARDSETUP;
1006  memset(&card->rx, 0, sizeof(struct qeth_rx));
1008 
1009  /* softsetup */
1010  QETH_DBF_TEXT(SETUP, 2, "softsetp");
1011 
1012  rc = qeth_send_startlan(card);
1013  if (rc) {
1014  QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1015  if (rc == 0xe080) {
1016  dev_warn(&card->gdev->dev,
1017  "The LAN is offline\n");
1018  card->lan_online = 0;
1019  goto contin;
1020  }
1021  rc = -ENODEV;
1022  goto out_remove;
1023  } else
1024  card->lan_online = 1;
1025 
1026 contin:
1027  if ((card->info.type == QETH_CARD_TYPE_OSD) ||
1028  (card->info.type == QETH_CARD_TYPE_OSX))
1029  /* configure isolation level */
1031 
1032  if (card->info.type != QETH_CARD_TYPE_OSN &&
1033  card->info.type != QETH_CARD_TYPE_OSM)
1034  qeth_l2_process_vlans(card);
1035 
1036  netif_tx_disable(card->dev);
1037 
1038  rc = qeth_init_qdio_queues(card);
1039  if (rc) {
1040  QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc);
1041  rc = -ENODEV;
1042  goto out_remove;
1043  }
1044  card->state = CARD_STATE_SOFTSETUP;
1045  if (card->lan_online)
1046  netif_carrier_on(card->dev);
1047  else
1048  netif_carrier_off(card->dev);
1049 
1050  qeth_set_allowed_threads(card, 0xffffffff, 0);
1051  if (recover_flag == CARD_STATE_RECOVER) {
1052  if (recovery_mode &&
1053  card->info.type != QETH_CARD_TYPE_OSN) {
1054  __qeth_l2_open(card->dev);
1055  } else {
1056  rtnl_lock();
1057  dev_open(card->dev);
1058  rtnl_unlock();
1059  }
1060  /* this also sets saved unicast addresses */
1061  qeth_l2_set_multicast_list(card->dev);
1062  }
1063  /* let user_space know that device is online */
1064  kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
1065  mutex_unlock(&card->conf_mutex);
1067  return 0;
1068 
1069 out_remove:
1070  qeth_l2_stop_card(card, 0);
1074  if (recover_flag == CARD_STATE_RECOVER)
1075  card->state = CARD_STATE_RECOVER;
1076  else
1077  card->state = CARD_STATE_DOWN;
1078  mutex_unlock(&card->conf_mutex);
1080  return rc;
1081 }
1082 
1083 static int qeth_l2_set_online(struct ccwgroup_device *gdev)
1084 {
1085  return __qeth_l2_set_online(gdev, 0);
1086 }
1087 
1088 static int __qeth_l2_set_offline(struct ccwgroup_device *cgdev,
1089  int recovery_mode)
1090 {
1091  struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
1092  int rc = 0, rc2 = 0, rc3 = 0;
1093  enum qeth_card_states recover_flag;
1094 
1095  mutex_lock(&card->discipline_mutex);
1096  mutex_lock(&card->conf_mutex);
1097  QETH_DBF_TEXT(SETUP, 3, "setoffl");
1098  QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *));
1099 
1100  if (card->dev && netif_carrier_ok(card->dev))
1101  netif_carrier_off(card->dev);
1102  recover_flag = card->state;
1103  if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) {
1105  card->info.hwtrap = 1;
1106  }
1107  qeth_l2_stop_card(card, recovery_mode);
1108  rc = ccw_device_set_offline(CARD_DDEV(card));
1109  rc2 = ccw_device_set_offline(CARD_WDEV(card));
1110  rc3 = ccw_device_set_offline(CARD_RDEV(card));
1111  if (!rc)
1112  rc = (rc2) ? rc2 : rc3;
1113  if (rc)
1114  QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc);
1115  if (recover_flag == CARD_STATE_UP)
1116  card->state = CARD_STATE_RECOVER;
1117  /* let user_space know that device is offline */
1118  kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE);
1119  mutex_unlock(&card->conf_mutex);
1121  return 0;
1122 }
1123 
1124 static int qeth_l2_set_offline(struct ccwgroup_device *cgdev)
1125 {
1126  return __qeth_l2_set_offline(cgdev, 0);
1127 }
1128 
1129 static int qeth_l2_recover(void *ptr)
1130 {
1131  struct qeth_card *card;
1132  int rc = 0;
1133 
1134  card = (struct qeth_card *) ptr;
1135  QETH_CARD_TEXT(card, 2, "recover1");
1137  return 0;
1138  QETH_CARD_TEXT(card, 2, "recover2");
1139  dev_warn(&card->gdev->dev,
1140  "A recovery process has been started for the device\n");
1141  __qeth_l2_set_offline(card->gdev, 1);
1142  rc = __qeth_l2_set_online(card->gdev, 1);
1143  if (!rc)
1144  dev_info(&card->gdev->dev,
1145  "Device successfully recovered!\n");
1146  else {
1147  if (rtnl_trylock()) {
1148  dev_close(card->dev);
1149  rtnl_unlock();
1150  dev_warn(&card->gdev->dev, "The qeth device driver "
1151  "failed to recover an error on the device\n");
1152  }
1153  }
1156  return 0;
1157 }
1158 
1159 static int __init qeth_l2_init(void)
1160 {
1161  pr_info("register layer 2 discipline\n");
1162  return 0;
1163 }
1164 
1165 static void __exit qeth_l2_exit(void)
1166 {
1167  pr_info("unregister layer 2 discipline\n");
1168 }
1169 
1170 static void qeth_l2_shutdown(struct ccwgroup_device *gdev)
1171 {
1172  struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1173  qeth_set_allowed_threads(card, 0, 1);
1174  if ((gdev->state == CCWGROUP_ONLINE) && card->info.hwtrap)
1176  qeth_qdio_clear_card(card, 0);
1178 }
1179 
1180 static int qeth_l2_pm_suspend(struct ccwgroup_device *gdev)
1181 {
1182  struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1183 
1184  if (card->dev)
1185  netif_device_detach(card->dev);
1186  qeth_set_allowed_threads(card, 0, 1);
1187  wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
1188  if (gdev->state == CCWGROUP_OFFLINE)
1189  return 0;
1190  if (card->state == CARD_STATE_UP) {
1191  if (card->info.hwtrap)
1193  __qeth_l2_set_offline(card->gdev, 1);
1194  } else
1195  __qeth_l2_set_offline(card->gdev, 0);
1196  return 0;
1197 }
1198 
1199 static int qeth_l2_pm_resume(struct ccwgroup_device *gdev)
1200 {
1201  struct qeth_card *card = dev_get_drvdata(&gdev->dev);
1202  int rc = 0;
1203 
1204  if (gdev->state == CCWGROUP_OFFLINE)
1205  goto out;
1206 
1207  if (card->state == CARD_STATE_RECOVER) {
1208  rc = __qeth_l2_set_online(card->gdev, 1);
1209  if (rc) {
1210  rtnl_lock();
1211  dev_close(card->dev);
1212  rtnl_unlock();
1213  }
1214  } else
1215  rc = __qeth_l2_set_online(card->gdev, 0);
1216 out:
1217  qeth_set_allowed_threads(card, 0xffffffff, 0);
1218  if (card->dev)
1219  netif_device_attach(card->dev);
1220  if (rc)
1221  dev_warn(&card->gdev->dev, "The qeth device driver "
1222  "failed to recover an error on the device\n");
1223  return rc;
1224 }
1225 
1227  .start_poll = qeth_qdio_start_poll,
1228  .input_handler = (qdio_handler_t *) qeth_qdio_input_handler,
1230  .recover = qeth_l2_recover,
1231  .setup = qeth_l2_probe_device,
1232  .remove = qeth_l2_remove_device,
1233  .set_online = qeth_l2_set_online,
1234  .set_offline = qeth_l2_set_offline,
1235  .shutdown = qeth_l2_shutdown,
1236  .freeze = qeth_l2_pm_suspend,
1237  .thaw = qeth_l2_pm_resume,
1238  .restore = qeth_l2_pm_resume,
1239 };
1240 EXPORT_SYMBOL_GPL(qeth_l2_discipline);
1241 
1242 static int qeth_osn_send_control_data(struct qeth_card *card, int len,
1243  struct qeth_cmd_buffer *iob)
1244 {
1245  unsigned long flags;
1246  int rc = 0;
1247 
1248  QETH_CARD_TEXT(card, 5, "osndctrd");
1249 
1250  wait_event(card->wait_q,
1251  atomic_cmpxchg(&card->write.irq_pending, 0, 1) == 0);
1252  qeth_prepare_control_data(card, len, iob);
1253  QETH_CARD_TEXT(card, 6, "osnoirqp");
1254  spin_lock_irqsave(get_ccwdev_lock(card->write.ccwdev), flags);
1255  rc = ccw_device_start(card->write.ccwdev, &card->write.ccw,
1256  (addr_t) iob, 0, 0);
1257  spin_unlock_irqrestore(get_ccwdev_lock(card->write.ccwdev), flags);
1258  if (rc) {
1259  QETH_DBF_MESSAGE(2, "qeth_osn_send_control_data: "
1260  "ccw_device_start rc = %i\n", rc);
1261  QETH_CARD_TEXT_(card, 2, " err%d", rc);
1262  qeth_release_buffer(iob->channel, iob);
1263  atomic_set(&card->write.irq_pending, 0);
1264  wake_up(&card->wait_q);
1265  }
1266  return rc;
1267 }
1268 
1269 static int qeth_osn_send_ipa_cmd(struct qeth_card *card,
1270  struct qeth_cmd_buffer *iob, int data_len)
1271 {
1272  u16 s1, s2;
1273 
1274  QETH_CARD_TEXT(card, 4, "osndipa");
1275 
1277  s1 = (u16)(IPA_PDU_HEADER_SIZE + data_len);
1278  s2 = (u16)data_len;
1279  memcpy(QETH_IPA_PDU_LEN_TOTAL(iob->data), &s1, 2);
1280  memcpy(QETH_IPA_PDU_LEN_PDU1(iob->data), &s2, 2);
1281  memcpy(QETH_IPA_PDU_LEN_PDU2(iob->data), &s2, 2);
1282  memcpy(QETH_IPA_PDU_LEN_PDU3(iob->data), &s2, 2);
1283  return qeth_osn_send_control_data(card, s1, iob);
1284 }
1285 
1286 int qeth_osn_assist(struct net_device *dev, void *data, int data_len)
1287 {
1288  struct qeth_cmd_buffer *iob;
1289  struct qeth_card *card;
1290  int rc;
1291 
1292  if (!dev)
1293  return -ENODEV;
1294  card = dev->ml_priv;
1295  if (!card)
1296  return -ENODEV;
1297  QETH_CARD_TEXT(card, 2, "osnsdmc");
1298  if ((card->state != CARD_STATE_UP) &&
1299  (card->state != CARD_STATE_SOFTSETUP))
1300  return -ENODEV;
1301  iob = qeth_wait_for_buffer(&card->write);
1302  memcpy(iob->data+IPA_PDU_HEADER_SIZE, data, data_len);
1303  rc = qeth_osn_send_ipa_cmd(card, iob, data_len);
1304  return rc;
1305 }
1307 
1308 int qeth_osn_register(unsigned char *read_dev_no, struct net_device **dev,
1309  int (*assist_cb)(struct net_device *, void *),
1310  int (*data_cb)(struct sk_buff *))
1311 {
1312  struct qeth_card *card;
1313 
1314  *dev = qeth_l2_netdev_by_devno(read_dev_no);
1315  if (*dev == NULL)
1316  return -ENODEV;
1317  card = (*dev)->ml_priv;
1318  if (!card)
1319  return -ENODEV;
1320  QETH_CARD_TEXT(card, 2, "osnreg");
1321  if ((assist_cb == NULL) || (data_cb == NULL))
1322  return -EINVAL;
1323  card->osn_info.assist_cb = assist_cb;
1324  card->osn_info.data_cb = data_cb;
1325  return 0;
1326 }
1328 
1330 {
1331  struct qeth_card *card;
1332 
1333  if (!dev)
1334  return;
1335  card = dev->ml_priv;
1336  if (!card)
1337  return;
1338  QETH_CARD_TEXT(card, 2, "osndereg");
1339  card->osn_info.assist_cb = NULL;
1340  card->osn_info.data_cb = NULL;
1341  return;
1342 }
1344 
1345 module_init(qeth_l2_init);
1346 module_exit(qeth_l2_exit);
1347 MODULE_AUTHOR("Frank Blaschka <[email protected]>");
1348 MODULE_DESCRIPTION("qeth layer 2 discipline");
1349 MODULE_LICENSE("GPL");