x86/nmi: Fix use of unallocated cpumask_var_t
[cascardo/linux.git] / drivers / net / wireless / b43 / phy_common.c
1 /*
2
3   Broadcom B43 wireless driver
4   Common PHY routines
5
6   Copyright (c) 2005 Martin Langer <martin-langer@gmx.de>,
7   Copyright (c) 2005-2007 Stefano Brivio <stefano.brivio@polimi.it>
8   Copyright (c) 2005-2008 Michael Buesch <m@bues.ch>
9   Copyright (c) 2005, 2006 Danny van Dyk <kugelfang@gentoo.org>
10   Copyright (c) 2005, 2006 Andreas Jaggi <andreas.jaggi@waterwave.ch>
11
12   This program is free software; you can redistribute it and/or modify
13   it under the terms of the GNU General Public License as published by
14   the Free Software Foundation; either version 2 of the License, or
15   (at your option) any later version.
16
17   This program is distributed in the hope that it will be useful,
18   but WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20   GNU General Public License for more details.
21
22   You should have received a copy of the GNU General Public License
23   along with this program; see the file COPYING.  If not, write to
24   the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
25   Boston, MA 02110-1301, USA.
26
27 */
28
29 #include "phy_common.h"
30 #include "phy_g.h"
31 #include "phy_a.h"
32 #include "phy_n.h"
33 #include "phy_lp.h"
34 #include "phy_ht.h"
35 #include "phy_lcn.h"
36 #include "b43.h"
37 #include "main.h"
38
39
40 int b43_phy_allocate(struct b43_wldev *dev)
41 {
42         struct b43_phy *phy = &(dev->phy);
43         int err;
44
45         phy->ops = NULL;
46
47         switch (phy->type) {
48         case B43_PHYTYPE_G:
49 #ifdef CONFIG_B43_PHY_G
50                 phy->ops = &b43_phyops_g;
51 #endif
52                 break;
53         case B43_PHYTYPE_N:
54 #ifdef CONFIG_B43_PHY_N
55                 phy->ops = &b43_phyops_n;
56 #endif
57                 break;
58         case B43_PHYTYPE_LP:
59 #ifdef CONFIG_B43_PHY_LP
60                 phy->ops = &b43_phyops_lp;
61 #endif
62                 break;
63         case B43_PHYTYPE_HT:
64 #ifdef CONFIG_B43_PHY_HT
65                 phy->ops = &b43_phyops_ht;
66 #endif
67                 break;
68         case B43_PHYTYPE_LCN:
69 #ifdef CONFIG_B43_PHY_LCN
70                 phy->ops = &b43_phyops_lcn;
71 #endif
72                 break;
73         }
74         if (B43_WARN_ON(!phy->ops))
75                 return -ENODEV;
76
77         err = phy->ops->allocate(dev);
78         if (err)
79                 phy->ops = NULL;
80
81         return err;
82 }
83
84 void b43_phy_free(struct b43_wldev *dev)
85 {
86         dev->phy.ops->free(dev);
87         dev->phy.ops = NULL;
88 }
89
90 int b43_phy_init(struct b43_wldev *dev)
91 {
92         struct b43_phy *phy = &dev->phy;
93         const struct b43_phy_operations *ops = phy->ops;
94         int err;
95
96         /* During PHY init we need to use some channel. On the first init this
97          * function is called *before* b43_op_config, so our pointer is NULL.
98          */
99         if (!phy->chandef) {
100                 phy->chandef = &dev->wl->hw->conf.chandef;
101                 phy->channel = phy->chandef->chan->hw_value;
102         }
103
104         phy->ops->switch_analog(dev, true);
105         b43_software_rfkill(dev, false);
106
107         err = ops->init(dev);
108         if (err) {
109                 b43err(dev->wl, "PHY init failed\n");
110                 goto err_block_rf;
111         }
112         phy->do_full_init = false;
113
114         err = b43_switch_channel(dev, phy->channel);
115         if (err) {
116                 b43err(dev->wl, "PHY init: Channel switch to default failed\n");
117                 goto err_phy_exit;
118         }
119
120         return 0;
121
122 err_phy_exit:
123         phy->do_full_init = true;
124         if (ops->exit)
125                 ops->exit(dev);
126 err_block_rf:
127         b43_software_rfkill(dev, true);
128
129         return err;
130 }
131
132 void b43_phy_exit(struct b43_wldev *dev)
133 {
134         const struct b43_phy_operations *ops = dev->phy.ops;
135
136         b43_software_rfkill(dev, true);
137         dev->phy.do_full_init = true;
138         if (ops->exit)
139                 ops->exit(dev);
140 }
141
142 bool b43_has_hardware_pctl(struct b43_wldev *dev)
143 {
144         if (!dev->phy.hardware_power_control)
145                 return false;
146         if (!dev->phy.ops->supports_hwpctl)
147                 return false;
148         return dev->phy.ops->supports_hwpctl(dev);
149 }
150
151 void b43_radio_lock(struct b43_wldev *dev)
152 {
153         u32 macctl;
154
155 #if B43_DEBUG
156         B43_WARN_ON(dev->phy.radio_locked);
157         dev->phy.radio_locked = true;
158 #endif
159
160         macctl = b43_read32(dev, B43_MMIO_MACCTL);
161         macctl |= B43_MACCTL_RADIOLOCK;
162         b43_write32(dev, B43_MMIO_MACCTL, macctl);
163         /* Commit the write and wait for the firmware
164          * to finish any radio register access. */
165         b43_read32(dev, B43_MMIO_MACCTL);
166         udelay(10);
167 }
168
169 void b43_radio_unlock(struct b43_wldev *dev)
170 {
171         u32 macctl;
172
173 #if B43_DEBUG
174         B43_WARN_ON(!dev->phy.radio_locked);
175         dev->phy.radio_locked = false;
176 #endif
177
178         /* Commit any write */
179         b43_read16(dev, B43_MMIO_PHY_VER);
180         /* unlock */
181         macctl = b43_read32(dev, B43_MMIO_MACCTL);
182         macctl &= ~B43_MACCTL_RADIOLOCK;
183         b43_write32(dev, B43_MMIO_MACCTL, macctl);
184 }
185
186 void b43_phy_lock(struct b43_wldev *dev)
187 {
188 #if B43_DEBUG
189         B43_WARN_ON(dev->phy.phy_locked);
190         dev->phy.phy_locked = true;
191 #endif
192         B43_WARN_ON(dev->dev->core_rev < 3);
193
194         if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP))
195                 b43_power_saving_ctl_bits(dev, B43_PS_AWAKE);
196 }
197
198 void b43_phy_unlock(struct b43_wldev *dev)
199 {
200 #if B43_DEBUG
201         B43_WARN_ON(!dev->phy.phy_locked);
202         dev->phy.phy_locked = false;
203 #endif
204         B43_WARN_ON(dev->dev->core_rev < 3);
205
206         if (!b43_is_mode(dev->wl, NL80211_IFTYPE_AP))
207                 b43_power_saving_ctl_bits(dev, 0);
208 }
209
210 static inline void assert_mac_suspended(struct b43_wldev *dev)
211 {
212         if (!B43_DEBUG)
213                 return;
214         if ((b43_status(dev) >= B43_STAT_INITIALIZED) &&
215             (dev->mac_suspended <= 0)) {
216                 b43dbg(dev->wl, "PHY/RADIO register access with "
217                        "enabled MAC.\n");
218                 dump_stack();
219         }
220 }
221
222 u16 b43_radio_read(struct b43_wldev *dev, u16 reg)
223 {
224         assert_mac_suspended(dev);
225         dev->phy.writes_counter = 0;
226         return dev->phy.ops->radio_read(dev, reg);
227 }
228
229 void b43_radio_write(struct b43_wldev *dev, u16 reg, u16 value)
230 {
231         assert_mac_suspended(dev);
232         if (b43_bus_host_is_pci(dev->dev) &&
233             ++dev->phy.writes_counter > B43_MAX_WRITES_IN_ROW) {
234                 b43_read32(dev, B43_MMIO_MACCTL);
235                 dev->phy.writes_counter = 1;
236         }
237         dev->phy.ops->radio_write(dev, reg, value);
238 }
239
240 void b43_radio_mask(struct b43_wldev *dev, u16 offset, u16 mask)
241 {
242         b43_radio_write16(dev, offset,
243                           b43_radio_read16(dev, offset) & mask);
244 }
245
246 void b43_radio_set(struct b43_wldev *dev, u16 offset, u16 set)
247 {
248         b43_radio_write16(dev, offset,
249                           b43_radio_read16(dev, offset) | set);
250 }
251
252 void b43_radio_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
253 {
254         b43_radio_write16(dev, offset,
255                           (b43_radio_read16(dev, offset) & mask) | set);
256 }
257
258 bool b43_radio_wait_value(struct b43_wldev *dev, u16 offset, u16 mask,
259                           u16 value, int delay, int timeout)
260 {
261         u16 val;
262         int i;
263
264         for (i = 0; i < timeout; i += delay) {
265                 val = b43_radio_read(dev, offset);
266                 if ((val & mask) == value)
267                         return true;
268                 udelay(delay);
269         }
270         return false;
271 }
272
273 u16 b43_phy_read(struct b43_wldev *dev, u16 reg)
274 {
275         assert_mac_suspended(dev);
276         dev->phy.writes_counter = 0;
277
278         if (dev->phy.ops->phy_read)
279                 return dev->phy.ops->phy_read(dev, reg);
280
281         b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
282         return b43_read16(dev, B43_MMIO_PHY_DATA);
283 }
284
285 void b43_phy_write(struct b43_wldev *dev, u16 reg, u16 value)
286 {
287         assert_mac_suspended(dev);
288         if (b43_bus_host_is_pci(dev->dev) &&
289             ++dev->phy.writes_counter > B43_MAX_WRITES_IN_ROW) {
290                 b43_read16(dev, B43_MMIO_PHY_VER);
291                 dev->phy.writes_counter = 1;
292         }
293
294         if (dev->phy.ops->phy_write)
295                 return dev->phy.ops->phy_write(dev, reg, value);
296
297         b43_write16f(dev, B43_MMIO_PHY_CONTROL, reg);
298         b43_write16(dev, B43_MMIO_PHY_DATA, value);
299 }
300
301 void b43_phy_copy(struct b43_wldev *dev, u16 destreg, u16 srcreg)
302 {
303         assert_mac_suspended(dev);
304         dev->phy.ops->phy_write(dev, destreg,
305                 dev->phy.ops->phy_read(dev, srcreg));
306 }
307
308 void b43_phy_mask(struct b43_wldev *dev, u16 offset, u16 mask)
309 {
310         if (dev->phy.ops->phy_maskset) {
311                 assert_mac_suspended(dev);
312                 dev->phy.ops->phy_maskset(dev, offset, mask, 0);
313         } else {
314                 b43_phy_write(dev, offset,
315                               b43_phy_read(dev, offset) & mask);
316         }
317 }
318
319 void b43_phy_set(struct b43_wldev *dev, u16 offset, u16 set)
320 {
321         if (dev->phy.ops->phy_maskset) {
322                 assert_mac_suspended(dev);
323                 dev->phy.ops->phy_maskset(dev, offset, 0xFFFF, set);
324         } else {
325                 b43_phy_write(dev, offset,
326                               b43_phy_read(dev, offset) | set);
327         }
328 }
329
330 void b43_phy_maskset(struct b43_wldev *dev, u16 offset, u16 mask, u16 set)
331 {
332         if (dev->phy.ops->phy_maskset) {
333                 assert_mac_suspended(dev);
334                 dev->phy.ops->phy_maskset(dev, offset, mask, set);
335         } else {
336                 b43_phy_write(dev, offset,
337                               (b43_phy_read(dev, offset) & mask) | set);
338         }
339 }
340
341 void b43_phy_put_into_reset(struct b43_wldev *dev)
342 {
343         u32 tmp;
344
345         switch (dev->dev->bus_type) {
346 #ifdef CONFIG_B43_BCMA
347         case B43_BUS_BCMA:
348                 tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
349                 tmp &= ~B43_BCMA_IOCTL_GMODE;
350                 tmp |= B43_BCMA_IOCTL_PHY_RESET;
351                 tmp |= BCMA_IOCTL_FGC;
352                 bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
353                 udelay(1);
354
355                 tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
356                 tmp &= ~BCMA_IOCTL_FGC;
357                 bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
358                 udelay(1);
359                 break;
360 #endif
361 #ifdef CONFIG_B43_SSB
362         case B43_BUS_SSB:
363                 tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
364                 tmp &= ~B43_TMSLOW_GMODE;
365                 tmp |= B43_TMSLOW_PHYRESET;
366                 tmp |= SSB_TMSLOW_FGC;
367                 ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
368                 usleep_range(1000, 2000);
369
370                 tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
371                 tmp &= ~SSB_TMSLOW_FGC;
372                 ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
373                 usleep_range(1000, 2000);
374
375                 break;
376 #endif
377         }
378 }
379
380 void b43_phy_take_out_of_reset(struct b43_wldev *dev)
381 {
382         u32 tmp;
383
384         switch (dev->dev->bus_type) {
385 #ifdef CONFIG_B43_BCMA
386         case B43_BUS_BCMA:
387                 /* Unset reset bit (with forcing clock) */
388                 tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
389                 tmp &= ~B43_BCMA_IOCTL_PHY_RESET;
390                 tmp &= ~B43_BCMA_IOCTL_PHY_CLKEN;
391                 tmp |= BCMA_IOCTL_FGC;
392                 bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
393                 udelay(1);
394
395                 /* Do not force clock anymore */
396                 tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
397                 tmp &= ~BCMA_IOCTL_FGC;
398                 tmp |= B43_BCMA_IOCTL_PHY_CLKEN;
399                 bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
400                 udelay(1);
401                 break;
402 #endif
403 #ifdef CONFIG_B43_SSB
404         case B43_BUS_SSB:
405                 /* Unset reset bit (with forcing clock) */
406                 tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
407                 tmp &= ~B43_TMSLOW_PHYRESET;
408                 tmp &= ~B43_TMSLOW_PHYCLKEN;
409                 tmp |= SSB_TMSLOW_FGC;
410                 ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
411                 ssb_read32(dev->dev->sdev, SSB_TMSLOW); /* flush */
412                 usleep_range(1000, 2000);
413
414                 tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
415                 tmp &= ~SSB_TMSLOW_FGC;
416                 tmp |= B43_TMSLOW_PHYCLKEN;
417                 ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
418                 ssb_read32(dev->dev->sdev, SSB_TMSLOW); /* flush */
419                 usleep_range(1000, 2000);
420                 break;
421 #endif
422         }
423 }
424
425 int b43_switch_channel(struct b43_wldev *dev, unsigned int new_channel)
426 {
427         struct b43_phy *phy = &(dev->phy);
428         u16 channelcookie, savedcookie;
429         int err;
430
431         /* First we set the channel radio code to prevent the
432          * firmware from sending ghost packets.
433          */
434         channelcookie = new_channel;
435         if (b43_current_band(dev->wl) == IEEE80211_BAND_5GHZ)
436                 channelcookie |= B43_SHM_SH_CHAN_5GHZ;
437         /* FIXME: set 40Mhz flag if required */
438         if (0)
439                 channelcookie |= B43_SHM_SH_CHAN_40MHZ;
440         savedcookie = b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN);
441         b43_shm_write16(dev, B43_SHM_SHARED, B43_SHM_SH_CHAN, channelcookie);
442
443         /* Now try to switch the PHY hardware channel. */
444         err = phy->ops->switch_channel(dev, new_channel);
445         if (err)
446                 goto err_restore_cookie;
447
448         /* Wait for the radio to tune to the channel and stabilize. */
449         msleep(8);
450
451         return 0;
452
453 err_restore_cookie:
454         b43_shm_write16(dev, B43_SHM_SHARED,
455                         B43_SHM_SH_CHAN, savedcookie);
456
457         return err;
458 }
459
460 void b43_software_rfkill(struct b43_wldev *dev, bool blocked)
461 {
462         struct b43_phy *phy = &dev->phy;
463
464         b43_mac_suspend(dev);
465         phy->ops->software_rfkill(dev, blocked);
466         phy->radio_on = !blocked;
467         b43_mac_enable(dev);
468 }
469
470 /**
471  * b43_phy_txpower_adjust_work - TX power workqueue.
472  *
473  * Workqueue for updating the TX power parameters in hardware.
474  */
475 void b43_phy_txpower_adjust_work(struct work_struct *work)
476 {
477         struct b43_wl *wl = container_of(work, struct b43_wl,
478                                          txpower_adjust_work);
479         struct b43_wldev *dev;
480
481         mutex_lock(&wl->mutex);
482         dev = wl->current_dev;
483
484         if (likely(dev && (b43_status(dev) >= B43_STAT_STARTED)))
485                 dev->phy.ops->adjust_txpower(dev);
486
487         mutex_unlock(&wl->mutex);
488 }
489
490 void b43_phy_txpower_check(struct b43_wldev *dev, unsigned int flags)
491 {
492         struct b43_phy *phy = &dev->phy;
493         unsigned long now = jiffies;
494         enum b43_txpwr_result result;
495
496         if (!(flags & B43_TXPWR_IGNORE_TIME)) {
497                 /* Check if it's time for a TXpower check. */
498                 if (time_before(now, phy->next_txpwr_check_time))
499                         return; /* Not yet */
500         }
501         /* The next check will be needed in two seconds, or later. */
502         phy->next_txpwr_check_time = round_jiffies(now + (HZ * 2));
503
504         if ((dev->dev->board_vendor == SSB_BOARDVENDOR_BCM) &&
505             (dev->dev->board_type == SSB_BOARD_BU4306))
506                 return; /* No software txpower adjustment needed */
507
508         result = phy->ops->recalc_txpower(dev, !!(flags & B43_TXPWR_IGNORE_TSSI));
509         if (result == B43_TXPWR_RES_DONE)
510                 return; /* We are done. */
511         B43_WARN_ON(result != B43_TXPWR_RES_NEED_ADJUST);
512         B43_WARN_ON(phy->ops->adjust_txpower == NULL);
513
514         /* We must adjust the transmission power in hardware.
515          * Schedule b43_phy_txpower_adjust_work(). */
516         ieee80211_queue_work(dev->wl->hw, &dev->wl->txpower_adjust_work);
517 }
518
519 int b43_phy_shm_tssi_read(struct b43_wldev *dev, u16 shm_offset)
520 {
521         const bool is_ofdm = (shm_offset != B43_SHM_SH_TSSI_CCK);
522         unsigned int a, b, c, d;
523         unsigned int average;
524         u32 tmp;
525
526         tmp = b43_shm_read32(dev, B43_SHM_SHARED, shm_offset);
527         a = tmp & 0xFF;
528         b = (tmp >> 8) & 0xFF;
529         c = (tmp >> 16) & 0xFF;
530         d = (tmp >> 24) & 0xFF;
531         if (a == 0 || a == B43_TSSI_MAX ||
532             b == 0 || b == B43_TSSI_MAX ||
533             c == 0 || c == B43_TSSI_MAX ||
534             d == 0 || d == B43_TSSI_MAX)
535                 return -ENOENT;
536         /* The values are OK. Clear them. */
537         tmp = B43_TSSI_MAX | (B43_TSSI_MAX << 8) |
538               (B43_TSSI_MAX << 16) | (B43_TSSI_MAX << 24);
539         b43_shm_write32(dev, B43_SHM_SHARED, shm_offset, tmp);
540
541         if (is_ofdm) {
542                 a = (a + 32) & 0x3F;
543                 b = (b + 32) & 0x3F;
544                 c = (c + 32) & 0x3F;
545                 d = (d + 32) & 0x3F;
546         }
547
548         /* Get the average of the values with 0.5 added to each value. */
549         average = (a + b + c + d + 2) / 4;
550         if (is_ofdm) {
551                 /* Adjust for CCK-boost */
552                 if (b43_shm_read16(dev, B43_SHM_SHARED, B43_SHM_SH_HOSTF1)
553                     & B43_HF_CCKBOOST)
554                         average = (average >= 13) ? (average - 13) : 0;
555         }
556
557         return average;
558 }
559
560 void b43_phyop_switch_analog_generic(struct b43_wldev *dev, bool on)
561 {
562         b43_write16(dev, B43_MMIO_PHY0, on ? 0 : 0xF4);
563 }
564
565
566 bool b43_is_40mhz(struct b43_wldev *dev)
567 {
568         return dev->phy.chandef->width == NL80211_CHAN_WIDTH_40;
569 }
570
571 /* http://bcm-v4.sipsolutions.net/802.11/PHY/N/BmacPhyClkFgc */
572 void b43_phy_force_clock(struct b43_wldev *dev, bool force)
573 {
574         u32 tmp;
575
576         WARN_ON(dev->phy.type != B43_PHYTYPE_N &&
577                 dev->phy.type != B43_PHYTYPE_HT);
578
579         switch (dev->dev->bus_type) {
580 #ifdef CONFIG_B43_BCMA
581         case B43_BUS_BCMA:
582                 tmp = bcma_aread32(dev->dev->bdev, BCMA_IOCTL);
583                 if (force)
584                         tmp |= BCMA_IOCTL_FGC;
585                 else
586                         tmp &= ~BCMA_IOCTL_FGC;
587                 bcma_awrite32(dev->dev->bdev, BCMA_IOCTL, tmp);
588                 break;
589 #endif
590 #ifdef CONFIG_B43_SSB
591         case B43_BUS_SSB:
592                 tmp = ssb_read32(dev->dev->sdev, SSB_TMSLOW);
593                 if (force)
594                         tmp |= SSB_TMSLOW_FGC;
595                 else
596                         tmp &= ~SSB_TMSLOW_FGC;
597                 ssb_write32(dev->dev->sdev, SSB_TMSLOW, tmp);
598                 break;
599 #endif
600         }
601 }
602
603 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */
604 struct b43_c32 b43_cordic(int theta)
605 {
606         static const u32 arctg[] = {
607                 2949120, 1740967, 919879, 466945, 234379, 117304,
608                   58666,   29335,  14668,   7334,   3667,   1833,
609                     917,     458,    229,    115,     57,     29,
610         };
611         u8 i;
612         s32 tmp;
613         s8 signx = 1;
614         u32 angle = 0;
615         struct b43_c32 ret = { .i = 39797, .q = 0, };
616
617         while (theta > (180 << 16))
618                 theta -= (360 << 16);
619         while (theta < -(180 << 16))
620                 theta += (360 << 16);
621
622         if (theta > (90 << 16)) {
623                 theta -= (180 << 16);
624                 signx = -1;
625         } else if (theta < -(90 << 16)) {
626                 theta += (180 << 16);
627                 signx = -1;
628         }
629
630         for (i = 0; i <= 17; i++) {
631                 if (theta > angle) {
632                         tmp = ret.i - (ret.q >> i);
633                         ret.q += ret.i >> i;
634                         ret.i = tmp;
635                         angle += arctg[i];
636                 } else {
637                         tmp = ret.i + (ret.q >> i);
638                         ret.q -= ret.i >> i;
639                         ret.i = tmp;
640                         angle -= arctg[i];
641                 }
642         }
643
644         ret.i *= signx;
645         ret.q *= signx;
646
647         return ret;
648 }