Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | /* |
| 9 | * qla2x00_debounce_register |
| 10 | * Debounce register. |
| 11 | * |
| 12 | * Input: |
| 13 | * port = register address. |
| 14 | * |
| 15 | * Returns: |
| 16 | * register value. |
| 17 | */ |
| 18 | static __inline__ uint16_t |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 19 | qla2x00_debounce_register(volatile uint16_t __iomem *addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | { |
| 21 | volatile uint16_t first; |
| 22 | volatile uint16_t second; |
| 23 | |
| 24 | do { |
| 25 | first = RD_REG_WORD(addr); |
| 26 | barrier(); |
| 27 | cpu_relax(); |
| 28 | second = RD_REG_WORD(addr); |
| 29 | } while (first != second); |
| 30 | |
| 31 | return (first); |
| 32 | } |
| 33 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 34 | static inline void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | qla2x00_poll(scsi_qla_host_t *ha) |
| 36 | { |
Andrew Vasquez | d2ba567 | 2008-05-12 22:21:14 -0700 | [diff] [blame] | 37 | unsigned long flags; |
| 38 | |
| 39 | local_irq_save(flags); |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 40 | ha->isp_ops->intr_handler(0, ha); |
Andrew Vasquez | d2ba567 | 2008-05-12 22:21:14 -0700 | [diff] [blame] | 41 | local_irq_restore(flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Seokmann Ju | da4541b | 2008-01-31 12:33:52 -0800 | [diff] [blame] | 44 | static __inline__ scsi_qla_host_t * |
| 45 | to_qla_parent(scsi_qla_host_t *ha) |
| 46 | { |
| 47 | return ha->parent ? ha->parent : ha; |
| 48 | } |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /** |
| 51 | * qla2x00_issue_marker() - Issue a Marker IOCB if necessary. |
| 52 | * @ha: HA context |
| 53 | * @ha_locked: is function called with the hardware lock |
| 54 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 55 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | */ |
| 57 | static inline int |
| 58 | qla2x00_issue_marker(scsi_qla_host_t *ha, int ha_locked) |
| 59 | { |
| 60 | /* Send marker if required */ |
| 61 | if (ha->marker_needed != 0) { |
| 62 | if (ha_locked) { |
| 63 | if (__qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != |
| 64 | QLA_SUCCESS) |
| 65 | return (QLA_FUNCTION_FAILED); |
| 66 | } else { |
| 67 | if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != |
| 68 | QLA_SUCCESS) |
| 69 | return (QLA_FUNCTION_FAILED); |
| 70 | } |
| 71 | ha->marker_needed = 0; |
| 72 | } |
| 73 | return (QLA_SUCCESS); |
| 74 | } |
| 75 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 76 | static inline uint8_t * |
| 77 | host_to_fcp_swap(uint8_t *fcp, uint32_t bsize) |
| 78 | { |
| 79 | uint32_t *ifcp = (uint32_t *) fcp; |
| 80 | uint32_t *ofcp = (uint32_t *) fcp; |
| 81 | uint32_t iter = bsize >> 2; |
| 82 | |
| 83 | for (; iter ; iter--) |
| 84 | *ofcp++ = swab32(*ifcp++); |
| 85 | |
| 86 | return fcp; |
| 87 | } |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 88 | |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 89 | static inline int |
| 90 | qla2x00_is_reserved_id(scsi_qla_host_t *ha, uint16_t loop_id) |
| 91 | { |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 92 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 93 | return (loop_id > NPH_LAST_HANDLE); |
| 94 | |
| 95 | return ((loop_id > ha->last_loop_id && loop_id < SNS_FIRST_LOOP_ID) || |
| 96 | loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST); |
| 97 | }; |