forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/s390/net/qeth_l3_sys.c
....@@ -60,9 +60,6 @@
6060 {
6161 struct qeth_card *card = dev_get_drvdata(dev);
6262
63
- if (!card)
64
- return -EINVAL;
65
-
6663 return qeth_l3_dev_route_show(card, &card->options.route4, buf);
6764 }
6865
....@@ -109,9 +106,6 @@
109106 {
110107 struct qeth_card *card = dev_get_drvdata(dev);
111108
112
- if (!card)
113
- return -EINVAL;
114
-
115109 return qeth_l3_dev_route_store(card, &card->options.route4,
116110 QETH_PROT_IPV4, buf, count);
117111 }
....@@ -124,9 +118,6 @@
124118 {
125119 struct qeth_card *card = dev_get_drvdata(dev);
126120
127
- if (!card)
128
- return -EINVAL;
129
-
130121 return qeth_l3_dev_route_show(card, &card->options.route6, buf);
131122 }
132123
....@@ -135,9 +126,6 @@
135126 {
136127 struct qeth_card *card = dev_get_drvdata(dev);
137128
138
- if (!card)
139
- return -EINVAL;
140
-
141129 return qeth_l3_dev_route_store(card, &card->options.route6,
142130 QETH_PROT_IPV6, buf, count);
143131 }
....@@ -145,54 +133,10 @@
145133 static DEVICE_ATTR(route6, 0644, qeth_l3_dev_route6_show,
146134 qeth_l3_dev_route6_store);
147135
148
-static ssize_t qeth_l3_dev_fake_broadcast_show(struct device *dev,
149
- struct device_attribute *attr, char *buf)
150
-{
151
- struct qeth_card *card = dev_get_drvdata(dev);
152
-
153
- if (!card)
154
- return -EINVAL;
155
-
156
- return sprintf(buf, "%i\n", card->options.fake_broadcast? 1:0);
157
-}
158
-
159
-static ssize_t qeth_l3_dev_fake_broadcast_store(struct device *dev,
160
- struct device_attribute *attr, const char *buf, size_t count)
161
-{
162
- struct qeth_card *card = dev_get_drvdata(dev);
163
- char *tmp;
164
- int i, rc = 0;
165
-
166
- if (!card)
167
- return -EINVAL;
168
-
169
- mutex_lock(&card->conf_mutex);
170
- if ((card->state != CARD_STATE_DOWN) &&
171
- (card->state != CARD_STATE_RECOVER)) {
172
- rc = -EPERM;
173
- goto out;
174
- }
175
-
176
- i = simple_strtoul(buf, &tmp, 16);
177
- if ((i == 0) || (i == 1))
178
- card->options.fake_broadcast = i;
179
- else
180
- rc = -EINVAL;
181
-out:
182
- mutex_unlock(&card->conf_mutex);
183
- return rc ? rc : count;
184
-}
185
-
186
-static DEVICE_ATTR(fake_broadcast, 0644, qeth_l3_dev_fake_broadcast_show,
187
- qeth_l3_dev_fake_broadcast_store);
188
-
189136 static ssize_t qeth_l3_dev_sniffer_show(struct device *dev,
190137 struct device_attribute *attr, char *buf)
191138 {
192139 struct qeth_card *card = dev_get_drvdata(dev);
193
-
194
- if (!card)
195
- return -EINVAL;
196140
197141 return sprintf(buf, "%i\n", card->options.sniffer ? 1 : 0);
198142 }
....@@ -204,17 +148,13 @@
204148 int rc = 0;
205149 unsigned long i;
206150
207
- if (!card)
208
- return -EINVAL;
209
-
210
- if (card->info.type != QETH_CARD_TYPE_IQD)
151
+ if (!IS_IQD(card))
211152 return -EPERM;
212153 if (card->options.cq == QETH_CQ_ENABLED)
213154 return -EPERM;
214155
215156 mutex_lock(&card->conf_mutex);
216
- if ((card->state != CARD_STATE_DOWN) &&
217
- (card->state != CARD_STATE_RECOVER)) {
157
+ if (card->state != CARD_STATE_DOWN) {
218158 rc = -EPERM;
219159 goto out;
220160 }
....@@ -230,14 +170,13 @@
230170 break;
231171 case 1:
232172 qdio_get_ssqd_desc(CARD_DDEV(card), &card->ssqd);
233
- if (card->ssqd.qdioac2 & QETH_SNIFF_AVAIL) {
173
+ if (card->ssqd.qdioac2 & CHSC_AC2_SNIFFER_AVAILABLE) {
234174 card->options.sniffer = i;
235
- if (card->qdio.init_pool.buf_count !=
236
- QETH_IN_BUF_COUNT_MAX)
237
- qeth_realloc_buffer_pool(card,
238
- QETH_IN_BUF_COUNT_MAX);
239
- } else
175
+ qeth_resize_buffer_pool(card, QETH_IN_BUF_COUNT_MAX);
176
+ } else {
240177 rc = -EPERM;
178
+ }
179
+
241180 break;
242181 default:
243182 rc = -EINVAL;
....@@ -250,17 +189,13 @@
250189 static DEVICE_ATTR(sniffer, 0644, qeth_l3_dev_sniffer_show,
251190 qeth_l3_dev_sniffer_store);
252191
253
-
254192 static ssize_t qeth_l3_dev_hsuid_show(struct device *dev,
255193 struct device_attribute *attr, char *buf)
256194 {
257195 struct qeth_card *card = dev_get_drvdata(dev);
258196 char tmp_hsuid[9];
259197
260
- if (!card)
261
- return -EINVAL;
262
-
263
- if (card->info.type != QETH_CARD_TYPE_IQD)
198
+ if (!IS_IQD(card))
264199 return -EPERM;
265200
266201 memcpy(tmp_hsuid, card->options.hsuid, sizeof(tmp_hsuid));
....@@ -272,25 +207,33 @@
272207 struct device_attribute *attr, const char *buf, size_t count)
273208 {
274209 struct qeth_card *card = dev_get_drvdata(dev);
210
+ int rc = 0;
275211 char *tmp;
276
- int rc;
277212
278
- if (!card)
279
- return -EINVAL;
213
+ if (!IS_IQD(card))
214
+ return -EPERM;
280215
281
- if (card->info.type != QETH_CARD_TYPE_IQD)
282
- return -EPERM;
283
- if (card->state != CARD_STATE_DOWN &&
284
- card->state != CARD_STATE_RECOVER)
285
- return -EPERM;
286
- if (card->options.sniffer)
287
- return -EPERM;
288
- if (card->options.cq == QETH_CQ_NOTAVAILABLE)
289
- return -EPERM;
216
+ mutex_lock(&card->conf_mutex);
217
+ if (card->state != CARD_STATE_DOWN) {
218
+ rc = -EPERM;
219
+ goto out;
220
+ }
221
+
222
+ if (card->options.sniffer) {
223
+ rc = -EPERM;
224
+ goto out;
225
+ }
226
+
227
+ if (card->options.cq == QETH_CQ_NOTAVAILABLE) {
228
+ rc = -EPERM;
229
+ goto out;
230
+ }
290231
291232 tmp = strsep((char **)&buf, "\n");
292
- if (strlen(tmp) > 8)
293
- return -EINVAL;
233
+ if (strlen(tmp) > 8) {
234
+ rc = -EINVAL;
235
+ goto out;
236
+ }
294237
295238 if (card->options.hsuid[0])
296239 /* delete old ip address */
....@@ -301,11 +244,13 @@
301244 card->options.hsuid[0] = '\0';
302245 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
303246 qeth_configure_cq(card, QETH_CQ_DISABLED);
304
- return count;
247
+ goto out;
305248 }
306249
307
- if (qeth_configure_cq(card, QETH_CQ_ENABLED))
308
- return -EPERM;
250
+ if (qeth_configure_cq(card, QETH_CQ_ENABLED)) {
251
+ rc = -EPERM;
252
+ goto out;
253
+ }
309254
310255 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
311256 "%-8s", tmp);
....@@ -314,6 +259,8 @@
314259
315260 rc = qeth_l3_modify_hsuid(card, true);
316261
262
+out:
263
+ mutex_unlock(&card->conf_mutex);
317264 return rc ? rc : count;
318265 }
319266
....@@ -324,7 +271,6 @@
324271 static struct attribute *qeth_l3_device_attrs[] = {
325272 &dev_attr_route4.attr,
326273 &dev_attr_route6.attr,
327
- &dev_attr_fake_broadcast.attr,
328274 &dev_attr_sniffer.attr,
329275 &dev_attr_hsuid.attr,
330276 NULL,
....@@ -339,10 +285,7 @@
339285 {
340286 struct qeth_card *card = dev_get_drvdata(dev);
341287
342
- if (!card)
343
- return -EINVAL;
344
-
345
- return sprintf(buf, "%i\n", card->ipato.enabled? 1:0);
288
+ return sprintf(buf, "%u\n", card->ipato.enabled ? 1 : 0);
346289 }
347290
348291 static ssize_t qeth_l3_dev_ipato_enable_store(struct device *dev,
....@@ -352,29 +295,27 @@
352295 bool enable;
353296 int rc = 0;
354297
355
- if (!card)
356
- return -EINVAL;
357
-
358298 mutex_lock(&card->conf_mutex);
359
- if ((card->state != CARD_STATE_DOWN) &&
360
- (card->state != CARD_STATE_RECOVER)) {
299
+ if (card->state != CARD_STATE_DOWN) {
361300 rc = -EPERM;
362301 goto out;
363302 }
364303
304
+ mutex_lock(&card->ip_lock);
365305 if (sysfs_streq(buf, "toggle")) {
366306 enable = !card->ipato.enabled;
367307 } else if (kstrtobool(buf, &enable)) {
368308 rc = -EINVAL;
369
- goto out;
309
+ goto unlock_ip;
370310 }
371311
372312 if (card->ipato.enabled != enable) {
373313 card->ipato.enabled = enable;
374
- spin_lock_bh(&card->ip_lock);
375314 qeth_l3_update_ipato(card);
376
- spin_unlock_bh(&card->ip_lock);
377315 }
316
+
317
+unlock_ip:
318
+ mutex_unlock(&card->ip_lock);
378319 out:
379320 mutex_unlock(&card->conf_mutex);
380321 return rc ? rc : count;
....@@ -389,10 +330,7 @@
389330 {
390331 struct qeth_card *card = dev_get_drvdata(dev);
391332
392
- if (!card)
393
- return -EINVAL;
394
-
395
- return sprintf(buf, "%i\n", card->ipato.invert4? 1:0);
333
+ return sprintf(buf, "%u\n", card->ipato.invert4 ? 1 : 0);
396334 }
397335
398336 static ssize_t qeth_l3_dev_ipato_invert4_store(struct device *dev,
....@@ -403,10 +341,7 @@
403341 bool invert;
404342 int rc = 0;
405343
406
- if (!card)
407
- return -EINVAL;
408
-
409
- mutex_lock(&card->conf_mutex);
344
+ mutex_lock(&card->ip_lock);
410345 if (sysfs_streq(buf, "toggle")) {
411346 invert = !card->ipato.invert4;
412347 } else if (kstrtobool(buf, &invert)) {
....@@ -416,12 +351,11 @@
416351
417352 if (card->ipato.invert4 != invert) {
418353 card->ipato.invert4 = invert;
419
- spin_lock_bh(&card->ip_lock);
420354 qeth_l3_update_ipato(card);
421
- spin_unlock_bh(&card->ip_lock);
422355 }
356
+
423357 out:
424
- mutex_unlock(&card->conf_mutex);
358
+ mutex_unlock(&card->ip_lock);
425359 return rc ? rc : count;
426360 }
427361
....@@ -433,30 +367,35 @@
433367 enum qeth_prot_versions proto)
434368 {
435369 struct qeth_ipato_entry *ipatoe;
436
- char addr_str[40];
437
- int entry_len; /* length of 1 entry string, differs between v4 and v6 */
438
- int i = 0;
370
+ int str_len = 0;
439371
440
- entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
441
- /* add strlen for "/<mask>\n" */
442
- entry_len += (proto == QETH_PROT_IPV4)? 5 : 6;
443
- spin_lock_bh(&card->ip_lock);
372
+ mutex_lock(&card->ip_lock);
444373 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
374
+ char addr_str[40];
375
+ int entry_len;
376
+
445377 if (ipatoe->proto != proto)
446378 continue;
447
- /* String must not be longer than PAGE_SIZE. So we check if
448
- * string length gets near PAGE_SIZE. Then we can savely display
449
- * the next IPv6 address (worst case, compared to IPv4) */
450
- if ((PAGE_SIZE - i) <= entry_len)
451
- break;
452
- qeth_l3_ipaddr_to_string(proto, ipatoe->addr, addr_str);
453
- i += snprintf(buf + i, PAGE_SIZE - i,
454
- "%s/%i\n", addr_str, ipatoe->mask_bits);
455
- }
456
- spin_unlock_bh(&card->ip_lock);
457
- i += snprintf(buf + i, PAGE_SIZE - i, "\n");
458379
459
- return i;
380
+ entry_len = qeth_l3_ipaddr_to_string(proto, ipatoe->addr,
381
+ addr_str);
382
+ if (entry_len < 0)
383
+ continue;
384
+
385
+ /* Append /%mask to the entry: */
386
+ entry_len += 1 + ((proto == QETH_PROT_IPV4) ? 2 : 3);
387
+ /* Enough room to format %entry\n into null terminated page? */
388
+ if (entry_len + 1 > PAGE_SIZE - str_len - 1)
389
+ break;
390
+
391
+ entry_len = scnprintf(buf, PAGE_SIZE - str_len,
392
+ "%s/%i\n", addr_str, ipatoe->mask_bits);
393
+ str_len += entry_len;
394
+ buf += entry_len;
395
+ }
396
+ mutex_unlock(&card->ip_lock);
397
+
398
+ return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
460399 }
461400
462401 static ssize_t qeth_l3_dev_ipato_add4_show(struct device *dev,
....@@ -464,36 +403,33 @@
464403 {
465404 struct qeth_card *card = dev_get_drvdata(dev);
466405
467
- if (!card)
468
- return -EINVAL;
469
-
470406 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV4);
471407 }
472408
473409 static int qeth_l3_parse_ipatoe(const char *buf, enum qeth_prot_versions proto,
474
- u8 *addr, int *mask_bits)
410
+ u8 *addr, unsigned int *mask_bits)
475411 {
476
- const char *start, *end;
477
- char *tmp;
478
- char buffer[40] = {0, };
412
+ char *sep;
413
+ int rc;
479414
480
- start = buf;
481
- /* get address string */
482
- end = strchr(start, '/');
483
- if (!end || (end - start >= 40)) {
415
+ /* Expected input pattern: %addr/%mask */
416
+ sep = strnchr(buf, 40, '/');
417
+ if (!sep)
484418 return -EINVAL;
485
- }
486
- strncpy(buffer, start, end - start);
487
- if (qeth_l3_string_to_ipaddr(buffer, proto, addr)) {
419
+
420
+ /* Terminate the %addr sub-string, and parse it: */
421
+ *sep = '\0';
422
+ rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
423
+ if (rc)
424
+ return rc;
425
+
426
+ rc = kstrtouint(sep + 1, 10, mask_bits);
427
+ if (rc)
428
+ return rc;
429
+
430
+ if (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))
488431 return -EINVAL;
489
- }
490
- start = end + 1;
491
- *mask_bits = simple_strtoul(start, &tmp, 10);
492
- if (!strlen(start) ||
493
- (tmp == start) ||
494
- (*mask_bits > ((proto == QETH_PROT_IPV4) ? 32 : 128))) {
495
- return -EINVAL;
496
- }
432
+
497433 return 0;
498434 }
499435
....@@ -501,29 +437,26 @@
501437 struct qeth_card *card, enum qeth_prot_versions proto)
502438 {
503439 struct qeth_ipato_entry *ipatoe;
440
+ unsigned int mask_bits;
504441 u8 addr[16];
505
- int mask_bits;
506442 int rc = 0;
507443
508
- mutex_lock(&card->conf_mutex);
509444 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
510445 if (rc)
511
- goto out;
446
+ return rc;
512447
513448 ipatoe = kzalloc(sizeof(struct qeth_ipato_entry), GFP_KERNEL);
514
- if (!ipatoe) {
515
- rc = -ENOMEM;
516
- goto out;
517
- }
449
+ if (!ipatoe)
450
+ return -ENOMEM;
451
+
518452 ipatoe->proto = proto;
519
- memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4)? 4:16);
453
+ memcpy(ipatoe->addr, addr, (proto == QETH_PROT_IPV4) ? 4 : 16);
520454 ipatoe->mask_bits = mask_bits;
521455
522456 rc = qeth_l3_add_ipato_entry(card, ipatoe);
523457 if (rc)
524458 kfree(ipatoe);
525
-out:
526
- mutex_unlock(&card->conf_mutex);
459
+
527460 return rc ? rc : count;
528461 }
529462
....@@ -531,9 +464,6 @@
531464 struct device_attribute *attr, const char *buf, size_t count)
532465 {
533466 struct qeth_card *card = dev_get_drvdata(dev);
534
-
535
- if (!card)
536
- return -EINVAL;
537467
538468 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV4);
539469 }
....@@ -545,15 +475,13 @@
545475 static ssize_t qeth_l3_dev_ipato_del_store(const char *buf, size_t count,
546476 struct qeth_card *card, enum qeth_prot_versions proto)
547477 {
478
+ unsigned int mask_bits;
548479 u8 addr[16];
549
- int mask_bits;
550480 int rc = 0;
551481
552
- mutex_lock(&card->conf_mutex);
553482 rc = qeth_l3_parse_ipatoe(buf, proto, addr, &mask_bits);
554483 if (!rc)
555484 rc = qeth_l3_del_ipato_entry(card, proto, addr, mask_bits);
556
- mutex_unlock(&card->conf_mutex);
557485 return rc ? rc : count;
558486 }
559487
....@@ -561,9 +489,6 @@
561489 struct device_attribute *attr, const char *buf, size_t count)
562490 {
563491 struct qeth_card *card = dev_get_drvdata(dev);
564
-
565
- if (!card)
566
- return -EINVAL;
567492
568493 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV4);
569494 }
....@@ -576,10 +501,7 @@
576501 {
577502 struct qeth_card *card = dev_get_drvdata(dev);
578503
579
- if (!card)
580
- return -EINVAL;
581
-
582
- return sprintf(buf, "%i\n", card->ipato.invert6? 1:0);
504
+ return sprintf(buf, "%u\n", card->ipato.invert6 ? 1 : 0);
583505 }
584506
585507 static ssize_t qeth_l3_dev_ipato_invert6_store(struct device *dev,
....@@ -589,10 +511,7 @@
589511 bool invert;
590512 int rc = 0;
591513
592
- if (!card)
593
- return -EINVAL;
594
-
595
- mutex_lock(&card->conf_mutex);
514
+ mutex_lock(&card->ip_lock);
596515 if (sysfs_streq(buf, "toggle")) {
597516 invert = !card->ipato.invert6;
598517 } else if (kstrtobool(buf, &invert)) {
....@@ -602,12 +521,11 @@
602521
603522 if (card->ipato.invert6 != invert) {
604523 card->ipato.invert6 = invert;
605
- spin_lock_bh(&card->ip_lock);
606524 qeth_l3_update_ipato(card);
607
- spin_unlock_bh(&card->ip_lock);
608525 }
526
+
609527 out:
610
- mutex_unlock(&card->conf_mutex);
528
+ mutex_unlock(&card->ip_lock);
611529 return rc ? rc : count;
612530 }
613531
....@@ -621,9 +539,6 @@
621539 {
622540 struct qeth_card *card = dev_get_drvdata(dev);
623541
624
- if (!card)
625
- return -EINVAL;
626
-
627542 return qeth_l3_dev_ipato_add_show(buf, card, QETH_PROT_IPV6);
628543 }
629544
....@@ -631,9 +546,6 @@
631546 struct device_attribute *attr, const char *buf, size_t count)
632547 {
633548 struct qeth_card *card = dev_get_drvdata(dev);
634
-
635
- if (!card)
636
- return -EINVAL;
637549
638550 return qeth_l3_dev_ipato_add_store(buf, count, card, QETH_PROT_IPV6);
639551 }
....@@ -646,9 +558,6 @@
646558 struct device_attribute *attr, const char *buf, size_t count)
647559 {
648560 struct qeth_card *card = dev_get_drvdata(dev);
649
-
650
- if (!card)
651
- return -EINVAL;
652561
653562 return qeth_l3_dev_ipato_del_store(buf, count, card, QETH_PROT_IPV6);
654563 }
....@@ -678,34 +587,34 @@
678587 {
679588 struct qeth_card *card = dev_get_drvdata(dev);
680589 struct qeth_ipaddr *ipaddr;
681
- char addr_str[40];
682590 int str_len = 0;
683
- int entry_len; /* length of 1 entry string, differs between v4 and v6 */
684591 int i;
685592
686
- if (!card)
687
- return -EINVAL;
688
-
689
- entry_len = (proto == QETH_PROT_IPV4)? 12 : 40;
690
- entry_len += 2; /* \n + terminator */
691
- spin_lock_bh(&card->ip_lock);
593
+ mutex_lock(&card->ip_lock);
692594 hash_for_each(card->ip_htable, i, ipaddr, hnode) {
595
+ char addr_str[40];
596
+ int entry_len;
597
+
693598 if (ipaddr->proto != proto || ipaddr->type != type)
694599 continue;
695
- /* String must not be longer than PAGE_SIZE. So we check if
696
- * string length gets near PAGE_SIZE. Then we can savely display
697
- * the next IPv6 address (worst case, compared to IPv4) */
698
- if ((PAGE_SIZE - str_len) <= entry_len)
699
- break;
700
- qeth_l3_ipaddr_to_string(proto, (const u8 *)&ipaddr->u,
701
- addr_str);
702
- str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "%s\n",
703
- addr_str);
704
- }
705
- spin_unlock_bh(&card->ip_lock);
706
- str_len += snprintf(buf + str_len, PAGE_SIZE - str_len, "\n");
707600
708
- return str_len;
601
+ entry_len = qeth_l3_ipaddr_to_string(proto, (u8 *)&ipaddr->u,
602
+ addr_str);
603
+ if (entry_len < 0)
604
+ continue;
605
+
606
+ /* Enough room to format %addr\n into null terminated page? */
607
+ if (entry_len + 1 > PAGE_SIZE - str_len - 1)
608
+ break;
609
+
610
+ entry_len = scnprintf(buf, PAGE_SIZE - str_len, "%s\n",
611
+ addr_str);
612
+ str_len += entry_len;
613
+ buf += entry_len;
614
+ }
615
+ mutex_unlock(&card->ip_lock);
616
+
617
+ return str_len ? str_len : scnprintf(buf, PAGE_SIZE, "\n");
709618 }
710619
711620 static ssize_t qeth_l3_dev_vipa_add4_show(struct device *dev,
....@@ -716,69 +625,34 @@
716625 QETH_IP_TYPE_VIPA);
717626 }
718627
719
-static int qeth_l3_parse_vipae(const char *buf, enum qeth_prot_versions proto,
720
- u8 *addr)
628
+static ssize_t qeth_l3_vipa_store(struct device *dev, const char *buf, bool add,
629
+ size_t count, enum qeth_prot_versions proto)
721630 {
722
- if (qeth_l3_string_to_ipaddr(buf, proto, addr)) {
723
- return -EINVAL;
724
- }
725
- return 0;
726
-}
727
-
728
-static ssize_t qeth_l3_dev_vipa_add_store(const char *buf, size_t count,
729
- struct qeth_card *card, enum qeth_prot_versions proto)
730
-{
631
+ struct qeth_card *card = dev_get_drvdata(dev);
731632 u8 addr[16] = {0, };
732633 int rc;
733634
734
- mutex_lock(&card->conf_mutex);
735
- rc = qeth_l3_parse_vipae(buf, proto, addr);
635
+ rc = qeth_l3_string_to_ipaddr(buf, proto, addr);
736636 if (!rc)
737
- rc = qeth_l3_modify_rxip_vipa(card, true, addr,
637
+ rc = qeth_l3_modify_rxip_vipa(card, add, addr,
738638 QETH_IP_TYPE_VIPA, proto);
739
- mutex_unlock(&card->conf_mutex);
740639 return rc ? rc : count;
741640 }
742641
743642 static ssize_t qeth_l3_dev_vipa_add4_store(struct device *dev,
744643 struct device_attribute *attr, const char *buf, size_t count)
745644 {
746
- struct qeth_card *card = dev_get_drvdata(dev);
747
-
748
- if (!card)
749
- return -EINVAL;
750
-
751
- return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV4);
645
+ return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV4);
752646 }
753647
754648 static QETH_DEVICE_ATTR(vipa_add4, add4, 0644,
755649 qeth_l3_dev_vipa_add4_show,
756650 qeth_l3_dev_vipa_add4_store);
757651
758
-static ssize_t qeth_l3_dev_vipa_del_store(const char *buf, size_t count,
759
- struct qeth_card *card, enum qeth_prot_versions proto)
760
-{
761
- u8 addr[16];
762
- int rc;
763
-
764
- mutex_lock(&card->conf_mutex);
765
- rc = qeth_l3_parse_vipae(buf, proto, addr);
766
- if (!rc)
767
- rc = qeth_l3_modify_rxip_vipa(card, false, addr,
768
- QETH_IP_TYPE_VIPA, proto);
769
- mutex_unlock(&card->conf_mutex);
770
- return rc ? rc : count;
771
-}
772
-
773652 static ssize_t qeth_l3_dev_vipa_del4_store(struct device *dev,
774653 struct device_attribute *attr, const char *buf, size_t count)
775654 {
776
- struct qeth_card *card = dev_get_drvdata(dev);
777
-
778
- if (!card)
779
- return -EINVAL;
780
-
781
- return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV4);
655
+ return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV4);
782656 }
783657
784658 static QETH_DEVICE_ATTR(vipa_del4, del4, 0200, NULL,
....@@ -795,12 +669,7 @@
795669 static ssize_t qeth_l3_dev_vipa_add6_store(struct device *dev,
796670 struct device_attribute *attr, const char *buf, size_t count)
797671 {
798
- struct qeth_card *card = dev_get_drvdata(dev);
799
-
800
- if (!card)
801
- return -EINVAL;
802
-
803
- return qeth_l3_dev_vipa_add_store(buf, count, card, QETH_PROT_IPV6);
672
+ return qeth_l3_vipa_store(dev, buf, true, count, QETH_PROT_IPV6);
804673 }
805674
806675 static QETH_DEVICE_ATTR(vipa_add6, add6, 0644,
....@@ -810,12 +679,7 @@
810679 static ssize_t qeth_l3_dev_vipa_del6_store(struct device *dev,
811680 struct device_attribute *attr, const char *buf, size_t count)
812681 {
813
- struct qeth_card *card = dev_get_drvdata(dev);
814
-
815
- if (!card)
816
- return -EINVAL;
817
-
818
- return qeth_l3_dev_vipa_del_store(buf, count, card, QETH_PROT_IPV6);
682
+ return qeth_l3_vipa_store(dev, buf, false, count, QETH_PROT_IPV6);
819683 }
820684
821685 static QETH_DEVICE_ATTR(vipa_del6, del6, 0200, NULL,
....@@ -868,60 +732,34 @@
868732 return 0;
869733 }
870734
871
-static ssize_t qeth_l3_dev_rxip_add_store(const char *buf, size_t count,
872
- struct qeth_card *card, enum qeth_prot_versions proto)
735
+static ssize_t qeth_l3_rxip_store(struct device *dev, const char *buf, bool add,
736
+ size_t count, enum qeth_prot_versions proto)
873737 {
738
+ struct qeth_card *card = dev_get_drvdata(dev);
874739 u8 addr[16] = {0, };
875740 int rc;
876741
877
- mutex_lock(&card->conf_mutex);
878742 rc = qeth_l3_parse_rxipe(buf, proto, addr);
879743 if (!rc)
880
- rc = qeth_l3_modify_rxip_vipa(card, true, addr,
744
+ rc = qeth_l3_modify_rxip_vipa(card, add, addr,
881745 QETH_IP_TYPE_RXIP, proto);
882
- mutex_unlock(&card->conf_mutex);
883746 return rc ? rc : count;
884747 }
885748
886749 static ssize_t qeth_l3_dev_rxip_add4_store(struct device *dev,
887750 struct device_attribute *attr, const char *buf, size_t count)
888751 {
889
- struct qeth_card *card = dev_get_drvdata(dev);
890
-
891
- if (!card)
892
- return -EINVAL;
893
-
894
- return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV4);
752
+ return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV4);
895753 }
896754
897755 static QETH_DEVICE_ATTR(rxip_add4, add4, 0644,
898756 qeth_l3_dev_rxip_add4_show,
899757 qeth_l3_dev_rxip_add4_store);
900758
901
-static ssize_t qeth_l3_dev_rxip_del_store(const char *buf, size_t count,
902
- struct qeth_card *card, enum qeth_prot_versions proto)
903
-{
904
- u8 addr[16];
905
- int rc;
906
-
907
- mutex_lock(&card->conf_mutex);
908
- rc = qeth_l3_parse_rxipe(buf, proto, addr);
909
- if (!rc)
910
- rc = qeth_l3_modify_rxip_vipa(card, false, addr,
911
- QETH_IP_TYPE_RXIP, proto);
912
- mutex_unlock(&card->conf_mutex);
913
- return rc ? rc : count;
914
-}
915
-
916759 static ssize_t qeth_l3_dev_rxip_del4_store(struct device *dev,
917760 struct device_attribute *attr, const char *buf, size_t count)
918761 {
919
- struct qeth_card *card = dev_get_drvdata(dev);
920
-
921
- if (!card)
922
- return -EINVAL;
923
-
924
- return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV4);
762
+ return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV4);
925763 }
926764
927765 static QETH_DEVICE_ATTR(rxip_del4, del4, 0200, NULL,
....@@ -938,12 +776,7 @@
938776 static ssize_t qeth_l3_dev_rxip_add6_store(struct device *dev,
939777 struct device_attribute *attr, const char *buf, size_t count)
940778 {
941
- struct qeth_card *card = dev_get_drvdata(dev);
942
-
943
- if (!card)
944
- return -EINVAL;
945
-
946
- return qeth_l3_dev_rxip_add_store(buf, count, card, QETH_PROT_IPV6);
779
+ return qeth_l3_rxip_store(dev, buf, true, count, QETH_PROT_IPV6);
947780 }
948781
949782 static QETH_DEVICE_ATTR(rxip_add6, add6, 0644,
....@@ -953,12 +786,7 @@
953786 static ssize_t qeth_l3_dev_rxip_del6_store(struct device *dev,
954787 struct device_attribute *attr, const char *buf, size_t count)
955788 {
956
- struct qeth_card *card = dev_get_drvdata(dev);
957
-
958
- if (!card)
959
- return -EINVAL;
960
-
961
- return qeth_l3_dev_rxip_del_store(buf, count, card, QETH_PROT_IPV6);
789
+ return qeth_l3_rxip_store(dev, buf, false, count, QETH_PROT_IPV6);
962790 }
963791
964792 static QETH_DEVICE_ATTR(rxip_del6, del6, 0200, NULL,