Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 3 | * All rights reserved |
| 4 | * www.brocade.com |
| 5 | * |
| 6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 10 | * published by the Free Software Foundation |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | */ |
| 17 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 18 | #include "bfa_defs_svc.h" |
| 19 | #include "bfa_port.h" |
| 20 | #include "bfi.h" |
| 21 | #include "bfa_ioc.h" |
| 22 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 23 | |
| 24 | BFA_TRC_FILE(CNA, PORT); |
| 25 | |
| 26 | #define bfa_ioc_portid(__ioc) ((__ioc)->port_id) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 27 | |
| 28 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 29 | bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 30 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 31 | u32 *dip = (u32 *) stats; |
| 32 | u32 t0, t1; |
| 33 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 34 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 35 | for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32); |
| 36 | i += 2) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 37 | t0 = dip[i]; |
| 38 | t1 = dip[i + 1]; |
| 39 | #ifdef __BIGENDIAN |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 40 | dip[i] = be32_to_cpu(t0); |
| 41 | dip[i + 1] = be32_to_cpu(t1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 42 | #else |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 43 | dip[i] = be32_to_cpu(t1); |
| 44 | dip[i + 1] = be32_to_cpu(t0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 45 | #endif |
| 46 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 49 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 50 | * bfa_port_enable_isr() |
| 51 | * |
| 52 | * |
| 53 | * @param[in] port - Pointer to the port module |
| 54 | * status - Return status from the f/w |
| 55 | * |
| 56 | * @return void |
| 57 | */ |
| 58 | static void |
| 59 | bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status) |
| 60 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 61 | bfa_trc(port, status); |
| 62 | port->endis_pending = BFA_FALSE; |
| 63 | port->endis_cbfn(port->endis_cbarg, status); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 66 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 67 | * bfa_port_disable_isr() |
| 68 | * |
| 69 | * |
| 70 | * @param[in] port - Pointer to the port module |
| 71 | * status - Return status from the f/w |
| 72 | * |
| 73 | * @return void |
| 74 | */ |
| 75 | static void |
| 76 | bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status) |
| 77 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 78 | bfa_trc(port, status); |
| 79 | port->endis_pending = BFA_FALSE; |
| 80 | port->endis_cbfn(port->endis_cbarg, status); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 83 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 84 | * bfa_port_get_stats_isr() |
| 85 | * |
| 86 | * |
| 87 | * @param[in] port - Pointer to the Port module |
| 88 | * status - Return status from the f/w |
| 89 | * |
| 90 | * @return void |
| 91 | */ |
| 92 | static void |
| 93 | bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status) |
| 94 | { |
| 95 | port->stats_status = status; |
| 96 | port->stats_busy = BFA_FALSE; |
| 97 | |
| 98 | if (status == BFA_STATUS_OK) { |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 99 | struct bfa_timeval_s tv; |
| 100 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 101 | memcpy(port->stats, port->stats_dma.kva, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 102 | sizeof(union bfa_port_stats_u)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 103 | bfa_port_stats_swap(port, port->stats); |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 104 | |
| 105 | bfa_os_gettimeofday(&tv); |
| 106 | port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | if (port->stats_cbfn) { |
| 110 | port->stats_cbfn(port->stats_cbarg, status); |
| 111 | port->stats_cbfn = NULL; |
| 112 | } |
| 113 | } |
| 114 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 115 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 116 | * bfa_port_clear_stats_isr() |
| 117 | * |
| 118 | * |
| 119 | * @param[in] port - Pointer to the Port module |
| 120 | * status - Return status from the f/w |
| 121 | * |
| 122 | * @return void |
| 123 | */ |
| 124 | static void |
| 125 | bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status) |
| 126 | { |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 127 | struct bfa_timeval_s tv; |
| 128 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 129 | port->stats_status = status; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 130 | port->stats_busy = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 131 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 132 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 133 | * re-initialize time stamp for stats reset |
| 134 | */ |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 135 | bfa_os_gettimeofday(&tv); |
| 136 | port->stats_reset_time = tv.tv_sec; |
| 137 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 138 | if (port->stats_cbfn) { |
| 139 | port->stats_cbfn(port->stats_cbarg, status); |
| 140 | port->stats_cbfn = NULL; |
| 141 | } |
| 142 | } |
| 143 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 144 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 145 | * bfa_port_isr() |
| 146 | * |
| 147 | * |
| 148 | * @param[in] Pointer to the Port module data structure. |
| 149 | * |
| 150 | * @return void |
| 151 | */ |
| 152 | static void |
| 153 | bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m) |
| 154 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 155 | struct bfa_port_s *port = (struct bfa_port_s *) cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 156 | union bfi_port_i2h_msg_u *i2hmsg; |
| 157 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 158 | i2hmsg = (union bfi_port_i2h_msg_u *) m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 159 | bfa_trc(port, m->mh.msg_id); |
| 160 | |
| 161 | switch (m->mh.msg_id) { |
| 162 | case BFI_PORT_I2H_ENABLE_RSP: |
| 163 | if (port->endis_pending == BFA_FALSE) |
| 164 | break; |
| 165 | bfa_port_enable_isr(port, i2hmsg->enable_rsp.status); |
| 166 | break; |
| 167 | |
| 168 | case BFI_PORT_I2H_DISABLE_RSP: |
| 169 | if (port->endis_pending == BFA_FALSE) |
| 170 | break; |
| 171 | bfa_port_disable_isr(port, i2hmsg->disable_rsp.status); |
| 172 | break; |
| 173 | |
| 174 | case BFI_PORT_I2H_GET_STATS_RSP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 175 | /* Stats busy flag is still set? (may be cmd timed out) */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 176 | if (port->stats_busy == BFA_FALSE) |
| 177 | break; |
| 178 | bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status); |
| 179 | break; |
| 180 | |
| 181 | case BFI_PORT_I2H_CLEAR_STATS_RSP: |
| 182 | if (port->stats_busy == BFA_FALSE) |
| 183 | break; |
| 184 | bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status); |
| 185 | break; |
| 186 | |
| 187 | default: |
| 188 | bfa_assert(0); |
| 189 | } |
| 190 | } |
| 191 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 192 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 193 | * bfa_port_meminfo() |
| 194 | * |
| 195 | * |
| 196 | * @param[in] void |
| 197 | * |
| 198 | * @return Size of DMA region |
| 199 | */ |
| 200 | u32 |
| 201 | bfa_port_meminfo(void) |
| 202 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 203 | return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 206 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 207 | * bfa_port_mem_claim() |
| 208 | * |
| 209 | * |
| 210 | * @param[in] port Port module pointer |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 211 | * dma_kva Kernel Virtual Address of Port DMA Memory |
| 212 | * dma_pa Physical Address of Port DMA Memory |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 213 | * |
| 214 | * @return void |
| 215 | */ |
| 216 | void |
| 217 | bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa) |
| 218 | { |
| 219 | port->stats_dma.kva = dma_kva; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 220 | port->stats_dma.pa = dma_pa; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 223 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 224 | * bfa_port_enable() |
| 225 | * |
| 226 | * Send the Port enable request to the f/w |
| 227 | * |
| 228 | * @param[in] Pointer to the Port module data structure. |
| 229 | * |
| 230 | * @return Status |
| 231 | */ |
| 232 | bfa_status_t |
| 233 | bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 234 | void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 235 | { |
| 236 | struct bfi_port_generic_req_s *m; |
| 237 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 238 | if (bfa_ioc_is_disabled(port->ioc)) { |
| 239 | bfa_trc(port, BFA_STATUS_IOC_DISABLED); |
| 240 | return BFA_STATUS_IOC_DISABLED; |
| 241 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 242 | |
| 243 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 244 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 245 | return BFA_STATUS_IOC_FAILURE; |
| 246 | } |
| 247 | |
| 248 | if (port->endis_pending) { |
| 249 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 250 | return BFA_STATUS_DEVBUSY; |
| 251 | } |
| 252 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 253 | m = (struct bfi_port_generic_req_s *) port->endis_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 254 | |
| 255 | port->msgtag++; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 256 | port->endis_cbfn = cbfn; |
| 257 | port->endis_cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 258 | port->endis_pending = BFA_TRUE; |
| 259 | |
| 260 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ, |
| 261 | bfa_ioc_portid(port->ioc)); |
| 262 | bfa_ioc_mbox_queue(port->ioc, &port->endis_mb); |
| 263 | |
| 264 | return BFA_STATUS_OK; |
| 265 | } |
| 266 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 267 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 268 | * bfa_port_disable() |
| 269 | * |
| 270 | * Send the Port disable request to the f/w |
| 271 | * |
| 272 | * @param[in] Pointer to the Port module data structure. |
| 273 | * |
| 274 | * @return Status |
| 275 | */ |
| 276 | bfa_status_t |
| 277 | bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 278 | void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 279 | { |
| 280 | struct bfi_port_generic_req_s *m; |
| 281 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 282 | if (bfa_ioc_is_disabled(port->ioc)) { |
| 283 | bfa_trc(port, BFA_STATUS_IOC_DISABLED); |
| 284 | return BFA_STATUS_IOC_DISABLED; |
| 285 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 286 | |
| 287 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 288 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 289 | return BFA_STATUS_IOC_FAILURE; |
| 290 | } |
| 291 | |
| 292 | if (port->endis_pending) { |
| 293 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 294 | return BFA_STATUS_DEVBUSY; |
| 295 | } |
| 296 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 297 | m = (struct bfi_port_generic_req_s *) port->endis_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 298 | |
| 299 | port->msgtag++; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 300 | port->endis_cbfn = cbfn; |
| 301 | port->endis_cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 302 | port->endis_pending = BFA_TRUE; |
| 303 | |
| 304 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ, |
| 305 | bfa_ioc_portid(port->ioc)); |
| 306 | bfa_ioc_mbox_queue(port->ioc, &port->endis_mb); |
| 307 | |
| 308 | return BFA_STATUS_OK; |
| 309 | } |
| 310 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 311 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 312 | * bfa_port_get_stats() |
| 313 | * |
| 314 | * Send the request to the f/w to fetch Port statistics. |
| 315 | * |
| 316 | * @param[in] Pointer to the Port module data structure. |
| 317 | * |
| 318 | * @return Status |
| 319 | */ |
| 320 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 321 | bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats, |
| 322 | bfa_port_stats_cbfn_t cbfn, void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 323 | { |
| 324 | struct bfi_port_get_stats_req_s *m; |
| 325 | |
| 326 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 327 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 328 | return BFA_STATUS_IOC_FAILURE; |
| 329 | } |
| 330 | |
| 331 | if (port->stats_busy) { |
| 332 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 333 | return BFA_STATUS_DEVBUSY; |
| 334 | } |
| 335 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 336 | m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 337 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 338 | port->stats = stats; |
| 339 | port->stats_cbfn = cbfn; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 340 | port->stats_cbarg = cbarg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 341 | port->stats_busy = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 342 | bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa); |
| 343 | |
| 344 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ, |
| 345 | bfa_ioc_portid(port->ioc)); |
| 346 | bfa_ioc_mbox_queue(port->ioc, &port->stats_mb); |
| 347 | |
| 348 | return BFA_STATUS_OK; |
| 349 | } |
| 350 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 351 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 352 | * bfa_port_clear_stats() |
| 353 | * |
| 354 | * |
| 355 | * @param[in] Pointer to the Port module data structure. |
| 356 | * |
| 357 | * @return Status |
| 358 | */ |
| 359 | bfa_status_t |
| 360 | bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 361 | void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 362 | { |
| 363 | struct bfi_port_generic_req_s *m; |
| 364 | |
| 365 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 366 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 367 | return BFA_STATUS_IOC_FAILURE; |
| 368 | } |
| 369 | |
| 370 | if (port->stats_busy) { |
| 371 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 372 | return BFA_STATUS_DEVBUSY; |
| 373 | } |
| 374 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 375 | m = (struct bfi_port_generic_req_s *) port->stats_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 376 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 377 | port->stats_cbfn = cbfn; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 378 | port->stats_cbarg = cbarg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 379 | port->stats_busy = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 380 | |
| 381 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ, |
| 382 | bfa_ioc_portid(port->ioc)); |
| 383 | bfa_ioc_mbox_queue(port->ioc, &port->stats_mb); |
| 384 | |
| 385 | return BFA_STATUS_OK; |
| 386 | } |
| 387 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 388 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 389 | * bfa_port_hbfail() |
| 390 | * |
| 391 | * |
| 392 | * @param[in] Pointer to the Port module data structure. |
| 393 | * |
| 394 | * @return void |
| 395 | */ |
| 396 | void |
| 397 | bfa_port_hbfail(void *arg) |
| 398 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 399 | struct bfa_port_s *port = (struct bfa_port_s *) arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 400 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 401 | /* Fail any pending get_stats/clear_stats requests */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 402 | if (port->stats_busy) { |
| 403 | if (port->stats_cbfn) |
Jing Huang | 8a4adf1 | 2010-07-08 20:01:07 -0700 | [diff] [blame] | 404 | port->stats_cbfn(port->stats_cbarg, BFA_STATUS_FAILED); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 405 | port->stats_cbfn = NULL; |
| 406 | port->stats_busy = BFA_FALSE; |
| 407 | } |
| 408 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 409 | /* Clear any enable/disable is pending */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 410 | if (port->endis_pending) { |
| 411 | if (port->endis_cbfn) |
Jing Huang | 8a4adf1 | 2010-07-08 20:01:07 -0700 | [diff] [blame] | 412 | port->endis_cbfn(port->endis_cbarg, BFA_STATUS_FAILED); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 413 | port->endis_cbfn = NULL; |
| 414 | port->endis_pending = BFA_FALSE; |
| 415 | } |
| 416 | } |
| 417 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 418 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 419 | * bfa_port_attach() |
| 420 | * |
| 421 | * |
| 422 | * @param[in] port - Pointer to the Port module data structure |
| 423 | * ioc - Pointer to the ioc module data structure |
| 424 | * dev - Pointer to the device driver module data structure |
| 425 | * The device driver specific mbox ISR functions have |
| 426 | * this pointer as one of the parameters. |
| 427 | * trcmod - |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 428 | * |
| 429 | * @return void |
| 430 | */ |
| 431 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 432 | bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc, |
| 433 | void *dev, struct bfa_trc_mod_s *trcmod) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 434 | { |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 435 | struct bfa_timeval_s tv; |
| 436 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 437 | bfa_assert(port); |
| 438 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 439 | port->dev = dev; |
| 440 | port->ioc = ioc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 441 | port->trcmod = trcmod; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 442 | |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 443 | port->stats_busy = BFA_FALSE; |
| 444 | port->endis_pending = BFA_FALSE; |
| 445 | port->stats_cbfn = NULL; |
| 446 | port->endis_cbfn = NULL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 447 | |
| 448 | bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port); |
| 449 | bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port); |
| 450 | bfa_ioc_hbfail_register(port->ioc, &port->hbfail); |
| 451 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 452 | /* |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 453 | * initialize time stamp for stats reset |
| 454 | */ |
| 455 | bfa_os_gettimeofday(&tv); |
| 456 | port->stats_reset_time = tv.tv_sec; |
| 457 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 458 | bfa_trc(port, 0); |
| 459 | } |
| 460 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 461 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 462 | * bfa_port_detach() |
| 463 | * |
| 464 | * |
| 465 | * @param[in] port - Pointer to the Port module data structure |
| 466 | * |
| 467 | * @return void |
| 468 | */ |
| 469 | void |
| 470 | bfa_port_detach(struct bfa_port_s *port) |
| 471 | { |
| 472 | bfa_trc(port, 0); |
| 473 | } |