Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

orinoco: Annotate ezusb_read_ltv()

ezusb_read_ltv() is always invoked via the ->read_ltv() callback. This
callback is mostly invoked under orinoco_lock() which disables BH.

There are a few invocations during probe which occur in preemptible
context via:
ezusb_probe() -> orinoco_init() -> determine_fw_capabilities()

Extend `hermes_ops' with the ->read_ltv_pr callback which is implemented
with the same callback like ->read_ltv on `hermes_ops_local'.
On `ezusb_ops' ->read_ltv is used for callbacks under the lock which
need to poll.
The new ->read_ltv_pr() is used in the preemptible context in which it
is possible to wait for the completion. Provide HERMES_READ_RECORD_PR()
and hermes_read_wordrec_pr() which behave like their non _pr equivalents
and invoke ->read_ltv_pr().

This removes the last user of ezusb_req_ctx_wait() and can now be
removed.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20201113212252.2243570-11-bigeasy@linutronix.de

authored by

Sebastian Andrzej Siewior and committed by
Kalle Valo
a3d8a259 a9a2678a

+52 -45
+1
drivers/net/wireless/intersil/orinoco/hermes.c
··· 763 763 .init_cmd_wait = hermes_doicmd_wait, 764 764 .allocate = hermes_allocate, 765 765 .read_ltv = hermes_read_ltv, 766 + .read_ltv_pr = hermes_read_ltv, 766 767 .write_ltv = hermes_write_ltv, 767 768 .bap_pread = hermes_bap_pread, 768 769 .bap_pwrite = hermes_bap_pwrite,
+15
drivers/net/wireless/intersil/orinoco/hermes.h
··· 386 386 int (*allocate)(struct hermes *hw, u16 size, u16 *fid); 387 387 int (*read_ltv)(struct hermes *hw, int bap, u16 rid, unsigned buflen, 388 388 u16 *length, void *buf); 389 + int (*read_ltv_pr)(struct hermes *hw, int bap, u16 rid, 390 + unsigned buflen, u16 *length, void *buf); 389 391 int (*write_ltv)(struct hermes *hw, int bap, u16 rid, 390 392 u16 length, const void *value); 391 393 int (*bap_pread)(struct hermes *hw, int bap, void *buf, int len, ··· 496 494 497 495 #define HERMES_READ_RECORD(hw, bap, rid, buf) \ 498 496 (hw->ops->read_ltv((hw), (bap), (rid), sizeof(*buf), NULL, (buf))) 497 + #define HERMES_READ_RECORD_PR(hw, bap, rid, buf) \ 498 + (hw->ops->read_ltv_pr((hw), (bap), (rid), sizeof(*buf), NULL, (buf))) 499 499 #define HERMES_WRITE_RECORD(hw, bap, rid, buf) \ 500 500 (hw->ops->write_ltv((hw), (bap), (rid), \ 501 501 HERMES_BYTES_TO_RECLEN(sizeof(*buf)), (buf))) ··· 509 505 int err; 510 506 511 507 err = HERMES_READ_RECORD(hw, bap, rid, &rec); 508 + *word = le16_to_cpu(rec); 509 + return err; 510 + } 511 + 512 + static inline int hermes_read_wordrec_pr(struct hermes *hw, int bap, u16 rid, 513 + u16 *word) 514 + { 515 + __le16 rec; 516 + int err; 517 + 518 + err = HERMES_READ_RECORD_PR(hw, bap, rid, &rec); 512 519 *word = le16_to_cpu(rec); 513 520 return err; 514 521 }
+16 -16
drivers/net/wireless/intersil/orinoco/hw.c
··· 78 78 char tmp[SYMBOL_MAX_VER_LEN + 1] __attribute__((aligned(2))); 79 79 80 80 /* Get the hardware version */ 81 - err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id); 81 + err = HERMES_READ_RECORD_PR(hw, USER_BAP, HERMES_RID_NICID, &nic_id); 82 82 if (err) { 83 83 dev_err(dev, "Cannot read hardware identity: error %d\n", 84 84 err); ··· 101 101 priv->firmware_type = determine_firmware_type(&nic_id); 102 102 103 103 /* Get the firmware version */ 104 - err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id); 104 + err = HERMES_READ_RECORD_PR(hw, USER_BAP, HERMES_RID_STAID, &sta_id); 105 105 if (err) { 106 106 dev_err(dev, "Cannot read station identity: error %d\n", 107 107 err); ··· 177 177 /* 3Com MAC : 00:50:DA:* */ 178 178 memset(tmp, 0, sizeof(tmp)); 179 179 /* Get the Symbol firmware version */ 180 - err = hw->ops->read_ltv(hw, USER_BAP, 180 + err = hw->ops->read_ltv_pr(hw, USER_BAP, 181 181 HERMES_RID_SECONDARYVERSION_SYMBOL, 182 182 SYMBOL_MAX_VER_LEN, NULL, &tmp); 183 183 if (err) { ··· 286 286 u16 reclen; 287 287 288 288 /* Get the MAC address */ 289 - err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, 289 + err = hw->ops->read_ltv_pr(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR, 290 290 ETH_ALEN, NULL, dev_addr); 291 291 if (err) { 292 292 dev_warn(dev, "Failed to read MAC address!\n"); ··· 296 296 dev_dbg(dev, "MAC address %pM\n", dev_addr); 297 297 298 298 /* Get the station name */ 299 - err = hw->ops->read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME, 299 + err = hw->ops->read_ltv_pr(hw, USER_BAP, HERMES_RID_CNFOWNNAME, 300 300 sizeof(nickbuf), &reclen, &nickbuf); 301 301 if (err) { 302 302 dev_err(dev, "failed to read station name\n"); ··· 312 312 dev_dbg(dev, "Station name \"%s\"\n", priv->nick); 313 313 314 314 /* Get allowed channels */ 315 - err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST, 315 + err = hermes_read_wordrec_pr(hw, USER_BAP, HERMES_RID_CHANNELLIST, 316 316 &priv->channel_mask); 317 317 if (err) { 318 318 dev_err(dev, "Failed to read channel list!\n"); ··· 320 320 } 321 321 322 322 /* Get initial AP density */ 323 - err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE, 323 + err = hermes_read_wordrec_pr(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE, 324 324 &priv->ap_density); 325 325 if (err || priv->ap_density < 1 || priv->ap_density > 3) 326 326 priv->has_sensitivity = 0; 327 327 328 328 /* Get initial RTS threshold */ 329 - err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, 329 + err = hermes_read_wordrec_pr(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD, 330 330 &priv->rts_thresh); 331 331 if (err) { 332 332 dev_err(dev, "Failed to read RTS threshold!\n"); ··· 335 335 336 336 /* Get initial fragmentation settings */ 337 337 if (priv->has_mwo) 338 - err = hermes_read_wordrec(hw, USER_BAP, 338 + err = hermes_read_wordrec_pr(hw, USER_BAP, 339 339 HERMES_RID_CNFMWOROBUST_AGERE, 340 340 &priv->mwo_robust); 341 341 else 342 - err = hermes_read_wordrec(hw, USER_BAP, 342 + err = hermes_read_wordrec_pr(hw, USER_BAP, 343 343 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD, 344 344 &priv->frag_thresh); 345 345 if (err) { ··· 351 351 if (priv->has_pm) { 352 352 priv->pm_on = 0; 353 353 priv->pm_mcast = 1; 354 - err = hermes_read_wordrec(hw, USER_BAP, 354 + err = hermes_read_wordrec_pr(hw, USER_BAP, 355 355 HERMES_RID_CNFMAXSLEEPDURATION, 356 356 &priv->pm_period); 357 357 if (err) { ··· 359 359 "period!\n"); 360 360 goto out; 361 361 } 362 - err = hermes_read_wordrec(hw, USER_BAP, 362 + err = hermes_read_wordrec_pr(hw, USER_BAP, 363 363 HERMES_RID_CNFPMHOLDOVERDURATION, 364 364 &priv->pm_timeout); 365 365 if (err) { ··· 371 371 372 372 /* Preamble setup */ 373 373 if (priv->has_preamble) { 374 - err = hermes_read_wordrec(hw, USER_BAP, 374 + err = hermes_read_wordrec_pr(hw, USER_BAP, 375 375 HERMES_RID_CNFPREAMBLE_SYMBOL, 376 376 &priv->preamble); 377 377 if (err) { ··· 381 381 } 382 382 383 383 /* Retry settings */ 384 - err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT, 384 + err = hermes_read_wordrec_pr(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT, 385 385 &priv->short_retry_limit); 386 386 if (err) { 387 387 dev_err(dev, "Failed to read short retry limit\n"); 388 388 goto out; 389 389 } 390 390 391 - err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT, 391 + err = hermes_read_wordrec_pr(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT, 392 392 &priv->long_retry_limit); 393 393 if (err) { 394 394 dev_err(dev, "Failed to read long retry limit\n"); 395 395 goto out; 396 396 } 397 397 398 - err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME, 398 + err = hermes_read_wordrec_pr(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME, 399 399 &priv->retry_lifetime); 400 400 if (err) { 401 401 dev_err(dev, "Failed to read max retry lifetime\n");
+20 -29
drivers/net/wireless/intersil/orinoco/orinoco_usb.c
··· 667 667 668 668 typedef void (*ezusb_ctx_wait)(struct ezusb_priv *, struct request_context *); 669 669 670 - static void ezusb_req_ctx_wait(struct ezusb_priv *upriv, 671 - struct request_context *ctx) 672 - { 673 - switch (ctx->state) { 674 - case EZUSB_CTX_QUEUED: 675 - case EZUSB_CTX_REQ_SUBMITTED: 676 - case EZUSB_CTX_REQ_COMPLETE: 677 - case EZUSB_CTX_RESP_RECEIVED: 678 - if (in_softirq()) { 679 - /* If we get called from a timer, timeout timers don't 680 - * get the chance to run themselves. So we make sure 681 - * that we don't sleep for ever */ 682 - int msecs = DEF_TIMEOUT * (1000 / HZ); 683 - 684 - while (!try_wait_for_completion(&ctx->done) && msecs--) 685 - udelay(1000); 686 - } else { 687 - wait_for_completion(&ctx->done); 688 - } 689 - break; 690 - default: 691 - /* Done or failed - nothing to wait for */ 692 - break; 693 - } 694 - } 695 - 696 670 static void ezusb_req_ctx_wait_compl(struct ezusb_priv *upriv, 697 671 struct request_context *ctx) 698 672 { ··· 1006 1032 ezusb_req_ctx_wait_poll); 1007 1033 } 1008 1034 1009 - static int ezusb_read_ltv(struct hermes *hw, int bap, u16 rid, 1010 - unsigned bufsize, u16 *length, void *buf) 1035 + static int __ezusb_read_ltv(struct hermes *hw, int bap, u16 rid, 1036 + unsigned bufsize, u16 *length, void *buf, 1037 + ezusb_ctx_wait ezusb_ctx_wait_func) 1038 + 1011 1039 { 1012 1040 struct ezusb_priv *upriv = hw->priv; 1013 1041 struct request_context *ctx; ··· 1022 1046 return -ENOMEM; 1023 1047 1024 1048 return ezusb_access_ltv(upriv, ctx, 0, NULL, EZUSB_FRAME_CONTROL, 1025 - buf, bufsize, length, ezusb_req_ctx_wait); 1049 + buf, bufsize, length, ezusb_req_ctx_wait_poll); 1050 + } 1051 + 1052 + static int ezusb_read_ltv(struct hermes *hw, int bap, u16 rid, 1053 + unsigned bufsize, u16 *length, void *buf) 1054 + { 1055 + return __ezusb_read_ltv(hw, bap, rid, bufsize, length, buf, 1056 + ezusb_req_ctx_wait_poll); 1057 + } 1058 + 1059 + static int ezusb_read_ltv_preempt(struct hermes *hw, int bap, u16 rid, 1060 + unsigned bufsize, u16 *length, void *buf) 1061 + { 1062 + return __ezusb_read_ltv(hw, bap, rid, bufsize, length, buf, 1063 + ezusb_req_ctx_wait_compl); 1026 1064 } 1027 1065 1028 1066 static int ezusb_doicmd_wait(struct hermes *hw, u16 cmd, u16 parm0, u16 parm1, ··· 1576 1586 .init_cmd_wait = ezusb_doicmd_wait, 1577 1587 .allocate = ezusb_allocate, 1578 1588 .read_ltv = ezusb_read_ltv, 1589 + .read_ltv_pr = ezusb_read_ltv_preempt, 1579 1590 .write_ltv = ezusb_write_ltv, 1580 1591 .bap_pread = ezusb_bap_pread, 1581 1592 .read_pda = ezusb_read_pda,