pio_copy.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
  2. /*
  3. * Copyright(c) 2015, 2016 Intel Corporation.
  4. */
  5. #include "hfi.h"
  6. /* additive distance between non-SOP and SOP space */
  7. #define SOP_DISTANCE (TXE_PIO_SIZE / 2)
  8. #define PIO_BLOCK_MASK (PIO_BLOCK_SIZE - 1)
  9. /* number of QUADWORDs in a block */
  10. #define PIO_BLOCK_QWS (PIO_BLOCK_SIZE / sizeof(u64))
  11. /**
  12. * pio_copy - copy data block to MMIO space
  13. * @dd: hfi1 dev data
  14. * @pbuf: a number of blocks allocated within a PIO send context
  15. * @pbc: PBC to send
  16. * @from: source, must be 8 byte aligned
  17. * @count: number of DWORD (32-bit) quantities to copy from source
  18. *
  19. * Copy data from source to PIO Send Buffer memory, 8 bytes at a time.
  20. * Must always write full BLOCK_SIZE bytes blocks. The first block must
  21. * be written to the corresponding SOP=1 address.
  22. *
  23. * Known:
  24. * o pbuf->start always starts on a block boundary
  25. * o pbuf can wrap only at a block boundary
  26. */
  27. void pio_copy(struct hfi1_devdata *dd, struct pio_buf *pbuf, u64 pbc,
  28. const void *from, size_t count)
  29. {
  30. void __iomem *dest = pbuf->start + SOP_DISTANCE;
  31. void __iomem *send = dest + PIO_BLOCK_SIZE;
  32. void __iomem *dend; /* 8-byte data end */
  33. /* write the PBC */
  34. writeq(pbc, dest);
  35. dest += sizeof(u64);
  36. /* calculate where the QWORD data ends - in SOP=1 space */
  37. dend = dest + ((count >> 1) * sizeof(u64));
  38. if (dend < send) {
  39. /*
  40. * all QWORD data is within the SOP block, does *not*
  41. * reach the end of the SOP block
  42. */
  43. while (dest < dend) {
  44. writeq(*(u64 *)from, dest);
  45. from += sizeof(u64);
  46. dest += sizeof(u64);
  47. }
  48. /*
  49. * No boundary checks are needed here:
  50. * 0. We're not on the SOP block boundary
  51. * 1. The possible DWORD dangle will still be within
  52. * the SOP block
  53. * 2. We cannot wrap except on a block boundary.
  54. */
  55. } else {
  56. /* QWORD data extends _to_ or beyond the SOP block */
  57. /* write 8-byte SOP chunk data */
  58. while (dest < send) {
  59. writeq(*(u64 *)from, dest);
  60. from += sizeof(u64);
  61. dest += sizeof(u64);
  62. }
  63. /* drop out of the SOP range */
  64. dest -= SOP_DISTANCE;
  65. dend -= SOP_DISTANCE;
  66. /*
  67. * If the wrap comes before or matches the data end,
  68. * copy until until the wrap, then wrap.
  69. *
  70. * If the data ends at the end of the SOP above and
  71. * the buffer wraps, then pbuf->end == dend == dest
  72. * and nothing will get written, but we will wrap in
  73. * case there is a dangling DWORD.
  74. */
  75. if (pbuf->end <= dend) {
  76. while (dest < pbuf->end) {
  77. writeq(*(u64 *)from, dest);
  78. from += sizeof(u64);
  79. dest += sizeof(u64);
  80. }
  81. dest -= pbuf->sc->size;
  82. dend -= pbuf->sc->size;
  83. }
  84. /* write 8-byte non-SOP, non-wrap chunk data */
  85. while (dest < dend) {
  86. writeq(*(u64 *)from, dest);
  87. from += sizeof(u64);
  88. dest += sizeof(u64);
  89. }
  90. }
  91. /* at this point we have wrapped if we are going to wrap */
  92. /* write dangling u32, if any */
  93. if (count & 1) {
  94. union mix val;
  95. val.val64 = 0;
  96. val.val32[0] = *(u32 *)from;
  97. writeq(val.val64, dest);
  98. dest += sizeof(u64);
  99. }
  100. /*
  101. * fill in rest of block, no need to check pbuf->end
  102. * as we only wrap on a block boundary
  103. */
  104. while (((unsigned long)dest & PIO_BLOCK_MASK) != 0) {
  105. writeq(0, dest);
  106. dest += sizeof(u64);
  107. }
  108. /* finished with this buffer */
  109. this_cpu_dec(*pbuf->sc->buffers_allocated);
  110. preempt_enable();
  111. }
  112. /*
  113. * Handle carry bytes using shifts and masks.
  114. *
  115. * NOTE: the value the unused portion of carry is expected to always be zero.
  116. */
  117. /*
  118. * "zero" shift - bit shift used to zero out upper bytes. Input is
  119. * the count of LSB bytes to preserve.
  120. */
  121. #define zshift(x) (8 * (8 - (x)))
  122. /*
  123. * "merge" shift - bit shift used to merge with carry bytes. Input is
  124. * the LSB byte count to move beyond.
  125. */
  126. #define mshift(x) (8 * (x))
  127. /*
  128. * Jump copy - no-loop copy for < 8 bytes.
  129. */
  130. static inline void jcopy(u8 *dest, const u8 *src, u32 n)
  131. {
  132. switch (n) {
  133. case 7:
  134. *dest++ = *src++;
  135. fallthrough;
  136. case 6:
  137. *dest++ = *src++;
  138. fallthrough;
  139. case 5:
  140. *dest++ = *src++;
  141. fallthrough;
  142. case 4:
  143. *dest++ = *src++;
  144. fallthrough;
  145. case 3:
  146. *dest++ = *src++;
  147. fallthrough;
  148. case 2:
  149. *dest++ = *src++;
  150. fallthrough;
  151. case 1:
  152. *dest++ = *src++;
  153. }
  154. }
  155. /*
  156. * Read nbytes from "from" and place them in the low bytes
  157. * of pbuf->carry. Other bytes are left as-is. Any previous
  158. * value in pbuf->carry is lost.
  159. *
  160. * NOTES:
  161. * o do not read from from if nbytes is zero
  162. * o from may _not_ be u64 aligned.
  163. */
  164. static inline void read_low_bytes(struct pio_buf *pbuf, const void *from,
  165. unsigned int nbytes)
  166. {
  167. pbuf->carry.val64 = 0;
  168. jcopy(&pbuf->carry.val8[0], from, nbytes);
  169. pbuf->carry_bytes = nbytes;
  170. }
  171. /*
  172. * Read nbytes bytes from "from" and put them at the end of pbuf->carry.
  173. * It is expected that the extra read does not overfill carry.
  174. *
  175. * NOTES:
  176. * o from may _not_ be u64 aligned
  177. * o nbytes may span a QW boundary
  178. */
  179. static inline void read_extra_bytes(struct pio_buf *pbuf,
  180. const void *from, unsigned int nbytes)
  181. {
  182. jcopy(&pbuf->carry.val8[pbuf->carry_bytes], from, nbytes);
  183. pbuf->carry_bytes += nbytes;
  184. }
  185. /*
  186. * Write a quad word using parts of pbuf->carry and the next 8 bytes of src.
  187. * Put the unused part of the next 8 bytes of src into the LSB bytes of
  188. * pbuf->carry with the upper bytes zeroed..
  189. *
  190. * NOTES:
  191. * o result must keep unused bytes zeroed
  192. * o src must be u64 aligned
  193. */
  194. static inline void merge_write8(
  195. struct pio_buf *pbuf,
  196. void __iomem *dest,
  197. const void *src)
  198. {
  199. u64 new, temp;
  200. new = *(u64 *)src;
  201. temp = pbuf->carry.val64 | (new << mshift(pbuf->carry_bytes));
  202. writeq(temp, dest);
  203. pbuf->carry.val64 = new >> zshift(pbuf->carry_bytes);
  204. }
  205. /*
  206. * Write a quad word using all bytes of carry.
  207. */
  208. static inline void carry8_write8(union mix carry, void __iomem *dest)
  209. {
  210. writeq(carry.val64, dest);
  211. }
  212. /*
  213. * Write a quad word using all the valid bytes of carry. If carry
  214. * has zero valid bytes, nothing is written.
  215. * Returns 0 on nothing written, non-zero on quad word written.
  216. */
  217. static inline int carry_write8(struct pio_buf *pbuf, void __iomem *dest)
  218. {
  219. if (pbuf->carry_bytes) {
  220. /* unused bytes are always kept zeroed, so just write */
  221. writeq(pbuf->carry.val64, dest);
  222. return 1;
  223. }
  224. return 0;
  225. }
  226. /*
  227. * Segmented PIO Copy - start
  228. *
  229. * Start a PIO copy.
  230. *
  231. * @pbuf: destination buffer
  232. * @pbc: the PBC for the PIO buffer
  233. * @from: data source, QWORD aligned
  234. * @nbytes: bytes to copy
  235. */
  236. void seg_pio_copy_start(struct pio_buf *pbuf, u64 pbc,
  237. const void *from, size_t nbytes)
  238. {
  239. void __iomem *dest = pbuf->start + SOP_DISTANCE;
  240. void __iomem *send = dest + PIO_BLOCK_SIZE;
  241. void __iomem *dend; /* 8-byte data end */
  242. writeq(pbc, dest);
  243. dest += sizeof(u64);
  244. /* calculate where the QWORD data ends - in SOP=1 space */
  245. dend = dest + ((nbytes >> 3) * sizeof(u64));
  246. if (dend < send) {
  247. /*
  248. * all QWORD data is within the SOP block, does *not*
  249. * reach the end of the SOP block
  250. */
  251. while (dest < dend) {
  252. writeq(*(u64 *)from, dest);
  253. from += sizeof(u64);
  254. dest += sizeof(u64);
  255. }
  256. /*
  257. * No boundary checks are needed here:
  258. * 0. We're not on the SOP block boundary
  259. * 1. The possible DWORD dangle will still be within
  260. * the SOP block
  261. * 2. We cannot wrap except on a block boundary.
  262. */
  263. } else {
  264. /* QWORD data extends _to_ or beyond the SOP block */
  265. /* write 8-byte SOP chunk data */
  266. while (dest < send) {
  267. writeq(*(u64 *)from, dest);
  268. from += sizeof(u64);
  269. dest += sizeof(u64);
  270. }
  271. /* drop out of the SOP range */
  272. dest -= SOP_DISTANCE;
  273. dend -= SOP_DISTANCE;
  274. /*
  275. * If the wrap comes before or matches the data end,
  276. * copy until until the wrap, then wrap.
  277. *
  278. * If the data ends at the end of the SOP above and
  279. * the buffer wraps, then pbuf->end == dend == dest
  280. * and nothing will get written, but we will wrap in
  281. * case there is a dangling DWORD.
  282. */
  283. if (pbuf->end <= dend) {
  284. while (dest < pbuf->end) {
  285. writeq(*(u64 *)from, dest);
  286. from += sizeof(u64);
  287. dest += sizeof(u64);
  288. }
  289. dest -= pbuf->sc->size;
  290. dend -= pbuf->sc->size;
  291. }
  292. /* write 8-byte non-SOP, non-wrap chunk data */
  293. while (dest < dend) {
  294. writeq(*(u64 *)from, dest);
  295. from += sizeof(u64);
  296. dest += sizeof(u64);
  297. }
  298. }
  299. /* at this point we have wrapped if we are going to wrap */
  300. /* ...but it doesn't matter as we're done writing */
  301. /* save dangling bytes, if any */
  302. read_low_bytes(pbuf, from, nbytes & 0x7);
  303. pbuf->qw_written = 1 /*PBC*/ + (nbytes >> 3);
  304. }
  305. /*
  306. * Mid copy helper, "mixed case" - source is 64-bit aligned but carry
  307. * bytes are non-zero.
  308. *
  309. * Whole u64s must be written to the chip, so bytes must be manually merged.
  310. *
  311. * @pbuf: destination buffer
  312. * @from: data source, is QWORD aligned.
  313. * @nbytes: bytes to copy
  314. *
  315. * Must handle nbytes < 8.
  316. */
  317. static void mid_copy_mix(struct pio_buf *pbuf, const void *from, size_t nbytes)
  318. {
  319. void __iomem *dest = pbuf->start + (pbuf->qw_written * sizeof(u64));
  320. void __iomem *dend; /* 8-byte data end */
  321. unsigned long qw_to_write = nbytes >> 3;
  322. unsigned long bytes_left = nbytes & 0x7;
  323. /* calculate 8-byte data end */
  324. dend = dest + (qw_to_write * sizeof(u64));
  325. if (pbuf->qw_written < PIO_BLOCK_QWS) {
  326. /*
  327. * Still within SOP block. We don't need to check for
  328. * wrap because we are still in the first block and
  329. * can only wrap on block boundaries.
  330. */
  331. void __iomem *send; /* SOP end */
  332. void __iomem *xend;
  333. /*
  334. * calculate the end of data or end of block, whichever
  335. * comes first
  336. */
  337. send = pbuf->start + PIO_BLOCK_SIZE;
  338. xend = min(send, dend);
  339. /* shift up to SOP=1 space */
  340. dest += SOP_DISTANCE;
  341. xend += SOP_DISTANCE;
  342. /* write 8-byte chunk data */
  343. while (dest < xend) {
  344. merge_write8(pbuf, dest, from);
  345. from += sizeof(u64);
  346. dest += sizeof(u64);
  347. }
  348. /* shift down to SOP=0 space */
  349. dest -= SOP_DISTANCE;
  350. }
  351. /*
  352. * At this point dest could be (either, both, or neither):
  353. * - at dend
  354. * - at the wrap
  355. */
  356. /*
  357. * If the wrap comes before or matches the data end,
  358. * copy until until the wrap, then wrap.
  359. *
  360. * If dest is at the wrap, we will fall into the if,
  361. * not do the loop, when wrap.
  362. *
  363. * If the data ends at the end of the SOP above and
  364. * the buffer wraps, then pbuf->end == dend == dest
  365. * and nothing will get written.
  366. */
  367. if (pbuf->end <= dend) {
  368. while (dest < pbuf->end) {
  369. merge_write8(pbuf, dest, from);
  370. from += sizeof(u64);
  371. dest += sizeof(u64);
  372. }
  373. dest -= pbuf->sc->size;
  374. dend -= pbuf->sc->size;
  375. }
  376. /* write 8-byte non-SOP, non-wrap chunk data */
  377. while (dest < dend) {
  378. merge_write8(pbuf, dest, from);
  379. from += sizeof(u64);
  380. dest += sizeof(u64);
  381. }
  382. pbuf->qw_written += qw_to_write;
  383. /* handle carry and left-over bytes */
  384. if (pbuf->carry_bytes + bytes_left >= 8) {
  385. unsigned long nread;
  386. /* there is enough to fill another qw - fill carry */
  387. nread = 8 - pbuf->carry_bytes;
  388. read_extra_bytes(pbuf, from, nread);
  389. /*
  390. * One more write - but need to make sure dest is correct.
  391. * Check for wrap and the possibility the write
  392. * should be in SOP space.
  393. *
  394. * The two checks immediately below cannot both be true, hence
  395. * the else. If we have wrapped, we cannot still be within the
  396. * first block. Conversely, if we are still in the first block,
  397. * we cannot have wrapped. We do the wrap check first as that
  398. * is more likely.
  399. */
  400. /* adjust if we have wrapped */
  401. if (dest >= pbuf->end)
  402. dest -= pbuf->sc->size;
  403. /* jump to the SOP range if within the first block */
  404. else if (pbuf->qw_written < PIO_BLOCK_QWS)
  405. dest += SOP_DISTANCE;
  406. /* flush out full carry */
  407. carry8_write8(pbuf->carry, dest);
  408. pbuf->qw_written++;
  409. /* now adjust and read the rest of the bytes into carry */
  410. bytes_left -= nread;
  411. from += nread; /* from is now not aligned */
  412. read_low_bytes(pbuf, from, bytes_left);
  413. } else {
  414. /* not enough to fill another qw, append the rest to carry */
  415. read_extra_bytes(pbuf, from, bytes_left);
  416. }
  417. }
  418. /*
  419. * Mid copy helper, "straight case" - source pointer is 64-bit aligned
  420. * with no carry bytes.
  421. *
  422. * @pbuf: destination buffer
  423. * @from: data source, is QWORD aligned
  424. * @nbytes: bytes to copy
  425. *
  426. * Must handle nbytes < 8.
  427. */
  428. static void mid_copy_straight(struct pio_buf *pbuf,
  429. const void *from, size_t nbytes)
  430. {
  431. void __iomem *dest = pbuf->start + (pbuf->qw_written * sizeof(u64));
  432. void __iomem *dend; /* 8-byte data end */
  433. /* calculate 8-byte data end */
  434. dend = dest + ((nbytes >> 3) * sizeof(u64));
  435. if (pbuf->qw_written < PIO_BLOCK_QWS) {
  436. /*
  437. * Still within SOP block. We don't need to check for
  438. * wrap because we are still in the first block and
  439. * can only wrap on block boundaries.
  440. */
  441. void __iomem *send; /* SOP end */
  442. void __iomem *xend;
  443. /*
  444. * calculate the end of data or end of block, whichever
  445. * comes first
  446. */
  447. send = pbuf->start + PIO_BLOCK_SIZE;
  448. xend = min(send, dend);
  449. /* shift up to SOP=1 space */
  450. dest += SOP_DISTANCE;
  451. xend += SOP_DISTANCE;
  452. /* write 8-byte chunk data */
  453. while (dest < xend) {
  454. writeq(*(u64 *)from, dest);
  455. from += sizeof(u64);
  456. dest += sizeof(u64);
  457. }
  458. /* shift down to SOP=0 space */
  459. dest -= SOP_DISTANCE;
  460. }
  461. /*
  462. * At this point dest could be (either, both, or neither):
  463. * - at dend
  464. * - at the wrap
  465. */
  466. /*
  467. * If the wrap comes before or matches the data end,
  468. * copy until until the wrap, then wrap.
  469. *
  470. * If dest is at the wrap, we will fall into the if,
  471. * not do the loop, when wrap.
  472. *
  473. * If the data ends at the end of the SOP above and
  474. * the buffer wraps, then pbuf->end == dend == dest
  475. * and nothing will get written.
  476. */
  477. if (pbuf->end <= dend) {
  478. while (dest < pbuf->end) {
  479. writeq(*(u64 *)from, dest);
  480. from += sizeof(u64);
  481. dest += sizeof(u64);
  482. }
  483. dest -= pbuf->sc->size;
  484. dend -= pbuf->sc->size;
  485. }
  486. /* write 8-byte non-SOP, non-wrap chunk data */
  487. while (dest < dend) {
  488. writeq(*(u64 *)from, dest);
  489. from += sizeof(u64);
  490. dest += sizeof(u64);
  491. }
  492. /* we know carry_bytes was zero on entry to this routine */
  493. read_low_bytes(pbuf, from, nbytes & 0x7);
  494. pbuf->qw_written += nbytes >> 3;
  495. }
  496. /*
  497. * Segmented PIO Copy - middle
  498. *
  499. * Must handle any aligned tail and any aligned source with any byte count.
  500. *
  501. * @pbuf: a number of blocks allocated within a PIO send context
  502. * @from: data source
  503. * @nbytes: number of bytes to copy
  504. */
  505. void seg_pio_copy_mid(struct pio_buf *pbuf, const void *from, size_t nbytes)
  506. {
  507. unsigned long from_align = (unsigned long)from & 0x7;
  508. if (pbuf->carry_bytes + nbytes < 8) {
  509. /* not enough bytes to fill a QW */
  510. read_extra_bytes(pbuf, from, nbytes);
  511. return;
  512. }
  513. if (from_align) {
  514. /* misaligned source pointer - align it */
  515. unsigned long to_align;
  516. /* bytes to read to align "from" */
  517. to_align = 8 - from_align;
  518. /*
  519. * In the advance-to-alignment logic below, we do not need
  520. * to check if we are using more than nbytes. This is because
  521. * if we are here, we already know that carry+nbytes will
  522. * fill at least one QW.
  523. */
  524. if (pbuf->carry_bytes + to_align < 8) {
  525. /* not enough align bytes to fill a QW */
  526. read_extra_bytes(pbuf, from, to_align);
  527. from += to_align;
  528. nbytes -= to_align;
  529. } else {
  530. /* bytes to fill carry */
  531. unsigned long to_fill = 8 - pbuf->carry_bytes;
  532. /* bytes left over to be read */
  533. unsigned long extra = to_align - to_fill;
  534. void __iomem *dest;
  535. /* fill carry... */
  536. read_extra_bytes(pbuf, from, to_fill);
  537. from += to_fill;
  538. nbytes -= to_fill;
  539. /* may not be enough valid bytes left to align */
  540. if (extra > nbytes)
  541. extra = nbytes;
  542. /* ...now write carry */
  543. dest = pbuf->start + (pbuf->qw_written * sizeof(u64));
  544. /*
  545. * The two checks immediately below cannot both be
  546. * true, hence the else. If we have wrapped, we
  547. * cannot still be within the first block.
  548. * Conversely, if we are still in the first block, we
  549. * cannot have wrapped. We do the wrap check first
  550. * as that is more likely.
  551. */
  552. /* adjust if we've wrapped */
  553. if (dest >= pbuf->end)
  554. dest -= pbuf->sc->size;
  555. /* jump to SOP range if within the first block */
  556. else if (pbuf->qw_written < PIO_BLOCK_QWS)
  557. dest += SOP_DISTANCE;
  558. carry8_write8(pbuf->carry, dest);
  559. pbuf->qw_written++;
  560. /* read any extra bytes to do final alignment */
  561. /* this will overwrite anything in pbuf->carry */
  562. read_low_bytes(pbuf, from, extra);
  563. from += extra;
  564. nbytes -= extra;
  565. /*
  566. * If no bytes are left, return early - we are done.
  567. * NOTE: This short-circuit is *required* because
  568. * "extra" may have been reduced in size and "from"
  569. * is not aligned, as required when leaving this
  570. * if block.
  571. */
  572. if (nbytes == 0)
  573. return;
  574. }
  575. /* at this point, from is QW aligned */
  576. }
  577. if (pbuf->carry_bytes)
  578. mid_copy_mix(pbuf, from, nbytes);
  579. else
  580. mid_copy_straight(pbuf, from, nbytes);
  581. }
  582. /*
  583. * Segmented PIO Copy - end
  584. *
  585. * Write any remainder (in pbuf->carry) and finish writing the whole block.
  586. *
  587. * @pbuf: a number of blocks allocated within a PIO send context
  588. */
  589. void seg_pio_copy_end(struct pio_buf *pbuf)
  590. {
  591. void __iomem *dest = pbuf->start + (pbuf->qw_written * sizeof(u64));
  592. /*
  593. * The two checks immediately below cannot both be true, hence the
  594. * else. If we have wrapped, we cannot still be within the first
  595. * block. Conversely, if we are still in the first block, we
  596. * cannot have wrapped. We do the wrap check first as that is
  597. * more likely.
  598. */
  599. /* adjust if we have wrapped */
  600. if (dest >= pbuf->end)
  601. dest -= pbuf->sc->size;
  602. /* jump to the SOP range if within the first block */
  603. else if (pbuf->qw_written < PIO_BLOCK_QWS)
  604. dest += SOP_DISTANCE;
  605. /* write final bytes, if any */
  606. if (carry_write8(pbuf, dest)) {
  607. dest += sizeof(u64);
  608. /*
  609. * NOTE: We do not need to recalculate whether dest needs
  610. * SOP_DISTANCE or not.
  611. *
  612. * If we are in the first block and the dangle write
  613. * keeps us in the same block, dest will need
  614. * to retain SOP_DISTANCE in the loop below.
  615. *
  616. * If we are in the first block and the dangle write pushes
  617. * us to the next block, then loop below will not run
  618. * and dest is not used. Hence we do not need to update
  619. * it.
  620. *
  621. * If we are past the first block, then SOP_DISTANCE
  622. * was never added, so there is nothing to do.
  623. */
  624. }
  625. /* fill in rest of block */
  626. while (((unsigned long)dest & PIO_BLOCK_MASK) != 0) {
  627. writeq(0, dest);
  628. dest += sizeof(u64);
  629. }
  630. /* finished with this buffer */
  631. this_cpu_dec(*pbuf->sc->buffers_allocated);
  632. preempt_enable();
  633. }