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 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 18 | #include "bfad_drv.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 19 | #include "bfa_defs_svc.h" |
| 20 | #include "bfa_port.h" |
| 21 | #include "bfi.h" |
| 22 | #include "bfa_ioc.h" |
| 23 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 24 | |
| 25 | BFA_TRC_FILE(CNA, PORT); |
| 26 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 27 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 28 | 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] | 29 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 30 | u32 *dip = (u32 *) stats; |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 31 | __be32 t0, t1; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 32 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 33 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 34 | for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32); |
| 35 | i += 2) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 36 | t0 = dip[i]; |
| 37 | t1 = dip[i + 1]; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 38 | #ifdef __BIG_ENDIAN |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 39 | dip[i] = be32_to_cpu(t0); |
| 40 | dip[i + 1] = be32_to_cpu(t1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 41 | #else |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 42 | dip[i] = be32_to_cpu(t1); |
| 43 | dip[i + 1] = be32_to_cpu(t0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 44 | #endif |
| 45 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 48 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 49 | * bfa_port_enable_isr() |
| 50 | * |
| 51 | * |
| 52 | * @param[in] port - Pointer to the port module |
| 53 | * status - Return status from the f/w |
| 54 | * |
| 55 | * @return void |
| 56 | */ |
| 57 | static void |
| 58 | bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status) |
| 59 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 60 | bfa_trc(port, status); |
| 61 | port->endis_pending = BFA_FALSE; |
| 62 | port->endis_cbfn(port->endis_cbarg, status); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 65 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 66 | * bfa_port_disable_isr() |
| 67 | * |
| 68 | * |
| 69 | * @param[in] port - Pointer to the port module |
| 70 | * status - Return status from the f/w |
| 71 | * |
| 72 | * @return void |
| 73 | */ |
| 74 | static void |
| 75 | bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status) |
| 76 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 77 | bfa_trc(port, status); |
| 78 | port->endis_pending = BFA_FALSE; |
| 79 | port->endis_cbfn(port->endis_cbarg, status); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 82 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 83 | * bfa_port_get_stats_isr() |
| 84 | * |
| 85 | * |
| 86 | * @param[in] port - Pointer to the Port module |
| 87 | * status - Return status from the f/w |
| 88 | * |
| 89 | * @return void |
| 90 | */ |
| 91 | static void |
| 92 | bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status) |
| 93 | { |
| 94 | port->stats_status = status; |
| 95 | port->stats_busy = BFA_FALSE; |
| 96 | |
| 97 | if (status == BFA_STATUS_OK) { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 98 | struct timeval tv; |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 99 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 100 | memcpy(port->stats, port->stats_dma.kva, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 101 | sizeof(union bfa_port_stats_u)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 102 | bfa_port_stats_swap(port, port->stats); |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 103 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 104 | do_gettimeofday(&tv); |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 105 | port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | if (port->stats_cbfn) { |
| 109 | port->stats_cbfn(port->stats_cbarg, status); |
| 110 | port->stats_cbfn = NULL; |
| 111 | } |
| 112 | } |
| 113 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 114 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 115 | * bfa_port_clear_stats_isr() |
| 116 | * |
| 117 | * |
| 118 | * @param[in] port - Pointer to the Port module |
| 119 | * status - Return status from the f/w |
| 120 | * |
| 121 | * @return void |
| 122 | */ |
| 123 | static void |
| 124 | bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status) |
| 125 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 126 | struct timeval tv; |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 127 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 128 | port->stats_status = status; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 129 | port->stats_busy = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 130 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 131 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 132 | * re-initialize time stamp for stats reset |
| 133 | */ |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 134 | do_gettimeofday(&tv); |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 135 | port->stats_reset_time = tv.tv_sec; |
| 136 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 137 | if (port->stats_cbfn) { |
| 138 | port->stats_cbfn(port->stats_cbarg, status); |
| 139 | port->stats_cbfn = NULL; |
| 140 | } |
| 141 | } |
| 142 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 143 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 144 | * bfa_port_isr() |
| 145 | * |
| 146 | * |
| 147 | * @param[in] Pointer to the Port module data structure. |
| 148 | * |
| 149 | * @return void |
| 150 | */ |
| 151 | static void |
| 152 | bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m) |
| 153 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 154 | struct bfa_port_s *port = (struct bfa_port_s *) cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 155 | union bfi_port_i2h_msg_u *i2hmsg; |
| 156 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 157 | i2hmsg = (union bfi_port_i2h_msg_u *) m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 158 | bfa_trc(port, m->mh.msg_id); |
| 159 | |
| 160 | switch (m->mh.msg_id) { |
| 161 | case BFI_PORT_I2H_ENABLE_RSP: |
| 162 | if (port->endis_pending == BFA_FALSE) |
| 163 | break; |
| 164 | bfa_port_enable_isr(port, i2hmsg->enable_rsp.status); |
| 165 | break; |
| 166 | |
| 167 | case BFI_PORT_I2H_DISABLE_RSP: |
| 168 | if (port->endis_pending == BFA_FALSE) |
| 169 | break; |
| 170 | bfa_port_disable_isr(port, i2hmsg->disable_rsp.status); |
| 171 | break; |
| 172 | |
| 173 | case BFI_PORT_I2H_GET_STATS_RSP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 174 | /* Stats busy flag is still set? (may be cmd timed out) */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 175 | if (port->stats_busy == BFA_FALSE) |
| 176 | break; |
| 177 | bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status); |
| 178 | break; |
| 179 | |
| 180 | case BFI_PORT_I2H_CLEAR_STATS_RSP: |
| 181 | if (port->stats_busy == BFA_FALSE) |
| 182 | break; |
| 183 | bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status); |
| 184 | break; |
| 185 | |
| 186 | default: |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 187 | WARN_ON(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 191 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 192 | * bfa_port_meminfo() |
| 193 | * |
| 194 | * |
| 195 | * @param[in] void |
| 196 | * |
| 197 | * @return Size of DMA region |
| 198 | */ |
| 199 | u32 |
| 200 | bfa_port_meminfo(void) |
| 201 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 202 | 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] | 203 | } |
| 204 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 205 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 206 | * bfa_port_mem_claim() |
| 207 | * |
| 208 | * |
| 209 | * @param[in] port Port module pointer |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 210 | * dma_kva Kernel Virtual Address of Port DMA Memory |
| 211 | * dma_pa Physical Address of Port DMA Memory |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 212 | * |
| 213 | * @return void |
| 214 | */ |
| 215 | void |
| 216 | bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa) |
| 217 | { |
| 218 | port->stats_dma.kva = dma_kva; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 219 | port->stats_dma.pa = dma_pa; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 220 | } |
| 221 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 222 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 223 | * bfa_port_enable() |
| 224 | * |
| 225 | * Send the Port enable request to the f/w |
| 226 | * |
| 227 | * @param[in] Pointer to the Port module data structure. |
| 228 | * |
| 229 | * @return Status |
| 230 | */ |
| 231 | bfa_status_t |
| 232 | 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] | 233 | void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 234 | { |
| 235 | struct bfi_port_generic_req_s *m; |
| 236 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 237 | /* If port is PBC disabled, return error */ |
| 238 | if (port->pbc_disabled) { |
| 239 | bfa_trc(port, BFA_STATUS_PBC); |
| 240 | return BFA_STATUS_PBC; |
| 241 | } |
| 242 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 243 | if (bfa_ioc_is_disabled(port->ioc)) { |
| 244 | bfa_trc(port, BFA_STATUS_IOC_DISABLED); |
| 245 | return BFA_STATUS_IOC_DISABLED; |
| 246 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 247 | |
| 248 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 249 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 250 | return BFA_STATUS_IOC_FAILURE; |
| 251 | } |
| 252 | |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 253 | /* if port is d-port enabled, return error */ |
| 254 | if (port->dport_enabled) { |
| 255 | bfa_trc(port, BFA_STATUS_DPORT_ERR); |
| 256 | return BFA_STATUS_DPORT_ERR; |
| 257 | } |
| 258 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 259 | if (port->endis_pending) { |
| 260 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 261 | return BFA_STATUS_DEVBUSY; |
| 262 | } |
| 263 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 264 | m = (struct bfi_port_generic_req_s *) port->endis_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 265 | |
| 266 | port->msgtag++; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 267 | port->endis_cbfn = cbfn; |
| 268 | port->endis_cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 269 | port->endis_pending = BFA_TRUE; |
| 270 | |
| 271 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ, |
| 272 | bfa_ioc_portid(port->ioc)); |
| 273 | bfa_ioc_mbox_queue(port->ioc, &port->endis_mb); |
| 274 | |
| 275 | return BFA_STATUS_OK; |
| 276 | } |
| 277 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 278 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 279 | * bfa_port_disable() |
| 280 | * |
| 281 | * Send the Port disable request to the f/w |
| 282 | * |
| 283 | * @param[in] Pointer to the Port module data structure. |
| 284 | * |
| 285 | * @return Status |
| 286 | */ |
| 287 | bfa_status_t |
| 288 | 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] | 289 | void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 290 | { |
| 291 | struct bfi_port_generic_req_s *m; |
| 292 | |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 293 | /* If port is PBC disabled, return error */ |
| 294 | if (port->pbc_disabled) { |
| 295 | bfa_trc(port, BFA_STATUS_PBC); |
| 296 | return BFA_STATUS_PBC; |
| 297 | } |
| 298 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 299 | if (bfa_ioc_is_disabled(port->ioc)) { |
| 300 | bfa_trc(port, BFA_STATUS_IOC_DISABLED); |
| 301 | return BFA_STATUS_IOC_DISABLED; |
| 302 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 303 | |
| 304 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 305 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 306 | return BFA_STATUS_IOC_FAILURE; |
| 307 | } |
| 308 | |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 309 | /* if port is d-port enabled, return error */ |
| 310 | if (port->dport_enabled) { |
| 311 | bfa_trc(port, BFA_STATUS_DPORT_ERR); |
| 312 | return BFA_STATUS_DPORT_ERR; |
| 313 | } |
| 314 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 315 | if (port->endis_pending) { |
| 316 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 317 | return BFA_STATUS_DEVBUSY; |
| 318 | } |
| 319 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 320 | m = (struct bfi_port_generic_req_s *) port->endis_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 321 | |
| 322 | port->msgtag++; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 323 | port->endis_cbfn = cbfn; |
| 324 | port->endis_cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 325 | port->endis_pending = BFA_TRUE; |
| 326 | |
| 327 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ, |
| 328 | bfa_ioc_portid(port->ioc)); |
| 329 | bfa_ioc_mbox_queue(port->ioc, &port->endis_mb); |
| 330 | |
| 331 | return BFA_STATUS_OK; |
| 332 | } |
| 333 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 334 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 335 | * bfa_port_get_stats() |
| 336 | * |
| 337 | * Send the request to the f/w to fetch Port statistics. |
| 338 | * |
| 339 | * @param[in] Pointer to the Port module data structure. |
| 340 | * |
| 341 | * @return Status |
| 342 | */ |
| 343 | bfa_status_t |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 344 | bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats, |
| 345 | bfa_port_stats_cbfn_t cbfn, void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 346 | { |
| 347 | struct bfi_port_get_stats_req_s *m; |
| 348 | |
| 349 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 350 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 351 | return BFA_STATUS_IOC_FAILURE; |
| 352 | } |
| 353 | |
| 354 | if (port->stats_busy) { |
| 355 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 356 | return BFA_STATUS_DEVBUSY; |
| 357 | } |
| 358 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 359 | m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 360 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 361 | port->stats = stats; |
| 362 | port->stats_cbfn = cbfn; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 363 | port->stats_cbarg = cbarg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 364 | port->stats_busy = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 365 | bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa); |
| 366 | |
| 367 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ, |
| 368 | bfa_ioc_portid(port->ioc)); |
| 369 | bfa_ioc_mbox_queue(port->ioc, &port->stats_mb); |
| 370 | |
| 371 | return BFA_STATUS_OK; |
| 372 | } |
| 373 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 374 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 375 | * bfa_port_clear_stats() |
| 376 | * |
| 377 | * |
| 378 | * @param[in] Pointer to the Port module data structure. |
| 379 | * |
| 380 | * @return Status |
| 381 | */ |
| 382 | bfa_status_t |
| 383 | 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] | 384 | void *cbarg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 385 | { |
| 386 | struct bfi_port_generic_req_s *m; |
| 387 | |
| 388 | if (!bfa_ioc_is_operational(port->ioc)) { |
| 389 | bfa_trc(port, BFA_STATUS_IOC_FAILURE); |
| 390 | return BFA_STATUS_IOC_FAILURE; |
| 391 | } |
| 392 | |
| 393 | if (port->stats_busy) { |
| 394 | bfa_trc(port, BFA_STATUS_DEVBUSY); |
| 395 | return BFA_STATUS_DEVBUSY; |
| 396 | } |
| 397 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 398 | m = (struct bfi_port_generic_req_s *) port->stats_mb.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 399 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 400 | port->stats_cbfn = cbfn; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 401 | port->stats_cbarg = cbarg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 402 | port->stats_busy = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 403 | |
| 404 | bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ, |
| 405 | bfa_ioc_portid(port->ioc)); |
| 406 | bfa_ioc_mbox_queue(port->ioc, &port->stats_mb); |
| 407 | |
| 408 | return BFA_STATUS_OK; |
| 409 | } |
| 410 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 411 | /* |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 412 | * bfa_port_notify() |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 413 | * |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 414 | * Port module IOC event handler |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 415 | * |
| 416 | * @param[in] Pointer to the Port module data structure. |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 417 | * @param[in] IOC event structure |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 418 | * |
| 419 | * @return void |
| 420 | */ |
| 421 | void |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 422 | bfa_port_notify(void *arg, enum bfa_ioc_event_e event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 423 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 424 | struct bfa_port_s *port = (struct bfa_port_s *) arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 425 | |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 426 | switch (event) { |
| 427 | case BFA_IOC_E_DISABLED: |
| 428 | case BFA_IOC_E_FAILED: |
| 429 | /* Fail any pending get_stats/clear_stats requests */ |
| 430 | if (port->stats_busy) { |
| 431 | if (port->stats_cbfn) |
| 432 | port->stats_cbfn(port->stats_cbarg, |
| 433 | BFA_STATUS_FAILED); |
| 434 | port->stats_cbfn = NULL; |
| 435 | port->stats_busy = BFA_FALSE; |
| 436 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 437 | |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 438 | /* Clear any enable/disable is pending */ |
| 439 | if (port->endis_pending) { |
| 440 | if (port->endis_cbfn) |
| 441 | port->endis_cbfn(port->endis_cbarg, |
| 442 | BFA_STATUS_FAILED); |
| 443 | port->endis_cbfn = NULL; |
| 444 | port->endis_pending = BFA_FALSE; |
| 445 | } |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 446 | |
| 447 | /* clear D-port mode */ |
| 448 | if (port->dport_enabled) |
| 449 | bfa_port_set_dportenabled(port, BFA_FALSE); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 450 | break; |
| 451 | default: |
| 452 | break; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 456 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 457 | * bfa_port_attach() |
| 458 | * |
| 459 | * |
| 460 | * @param[in] port - Pointer to the Port module data structure |
| 461 | * ioc - Pointer to the ioc module data structure |
| 462 | * dev - Pointer to the device driver module data structure |
| 463 | * The device driver specific mbox ISR functions have |
| 464 | * this pointer as one of the parameters. |
| 465 | * trcmod - |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 466 | * |
| 467 | * @return void |
| 468 | */ |
| 469 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 470 | bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc, |
| 471 | void *dev, struct bfa_trc_mod_s *trcmod) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 472 | { |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 473 | struct timeval tv; |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 474 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 475 | WARN_ON(!port); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 476 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 477 | port->dev = dev; |
| 478 | port->ioc = ioc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 479 | port->trcmod = trcmod; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 480 | |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 481 | port->stats_busy = BFA_FALSE; |
| 482 | port->endis_pending = BFA_FALSE; |
| 483 | port->stats_cbfn = NULL; |
| 484 | port->endis_cbfn = NULL; |
Krishna Gudipati | 43ffdf4 | 2011-06-13 15:46:21 -0700 | [diff] [blame] | 485 | port->pbc_disabled = BFA_FALSE; |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 486 | port->dport_enabled = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 487 | |
| 488 | bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port); |
Krishna Gudipati | 3350d98 | 2011-06-24 20:28:37 -0700 | [diff] [blame] | 489 | bfa_q_qe_init(&port->ioc_notify); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 490 | bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port); |
| 491 | list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 492 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 493 | /* |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 494 | * initialize time stamp for stats reset |
| 495 | */ |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 496 | do_gettimeofday(&tv); |
Jing Huang | b85d045 | 2010-07-08 19:48:49 -0700 | [diff] [blame] | 497 | port->stats_reset_time = tv.tv_sec; |
| 498 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 499 | bfa_trc(port, 0); |
| 500 | } |
Krishna Gudipati | 148d610 | 2011-06-24 20:25:36 -0700 | [diff] [blame] | 501 | |
| 502 | /* |
Krishna Gudipati | e353546 | 2012-09-21 17:26:07 -0700 | [diff] [blame] | 503 | * bfa_port_set_dportenabled(); |
| 504 | * |
| 505 | * Port module- set pbc disabled flag |
| 506 | * |
| 507 | * @param[in] port - Pointer to the Port module data structure |
| 508 | * |
| 509 | * @return void |
| 510 | */ |
| 511 | void |
| 512 | bfa_port_set_dportenabled(struct bfa_port_s *port, bfa_boolean_t enabled) |
| 513 | { |
| 514 | port->dport_enabled = enabled; |
| 515 | } |
| 516 | |
| 517 | /* |
Krishna Gudipati | 148d610 | 2011-06-24 20:25:36 -0700 | [diff] [blame] | 518 | * CEE module specific definitions |
| 519 | */ |
| 520 | |
| 521 | /* |
| 522 | * bfa_cee_get_attr_isr() |
| 523 | * |
| 524 | * @brief CEE ISR for get-attributes responses from f/w |
| 525 | * |
| 526 | * @param[in] cee - Pointer to the CEE module |
| 527 | * status - Return status from the f/w |
| 528 | * |
| 529 | * @return void |
| 530 | */ |
| 531 | static void |
| 532 | bfa_cee_get_attr_isr(struct bfa_cee_s *cee, bfa_status_t status) |
| 533 | { |
| 534 | struct bfa_cee_lldp_cfg_s *lldp_cfg = &cee->attr->lldp_remote; |
| 535 | |
| 536 | cee->get_attr_status = status; |
| 537 | bfa_trc(cee, 0); |
| 538 | if (status == BFA_STATUS_OK) { |
| 539 | bfa_trc(cee, 0); |
| 540 | memcpy(cee->attr, cee->attr_dma.kva, |
| 541 | sizeof(struct bfa_cee_attr_s)); |
| 542 | lldp_cfg->time_to_live = be16_to_cpu(lldp_cfg->time_to_live); |
| 543 | lldp_cfg->enabled_system_cap = |
| 544 | be16_to_cpu(lldp_cfg->enabled_system_cap); |
| 545 | } |
| 546 | cee->get_attr_pending = BFA_FALSE; |
| 547 | if (cee->cbfn.get_attr_cbfn) { |
| 548 | bfa_trc(cee, 0); |
| 549 | cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | * bfa_cee_get_stats_isr() |
| 555 | * |
| 556 | * @brief CEE ISR for get-stats responses from f/w |
| 557 | * |
| 558 | * @param[in] cee - Pointer to the CEE module |
| 559 | * status - Return status from the f/w |
| 560 | * |
| 561 | * @return void |
| 562 | */ |
| 563 | static void |
| 564 | bfa_cee_get_stats_isr(struct bfa_cee_s *cee, bfa_status_t status) |
| 565 | { |
| 566 | u32 *buffer; |
| 567 | int i; |
| 568 | |
| 569 | cee->get_stats_status = status; |
| 570 | bfa_trc(cee, 0); |
| 571 | if (status == BFA_STATUS_OK) { |
| 572 | bfa_trc(cee, 0); |
| 573 | memcpy(cee->stats, cee->stats_dma.kva, |
| 574 | sizeof(struct bfa_cee_stats_s)); |
| 575 | /* swap the cee stats */ |
| 576 | buffer = (u32 *)cee->stats; |
| 577 | for (i = 0; i < (sizeof(struct bfa_cee_stats_s) / |
| 578 | sizeof(u32)); i++) |
| 579 | buffer[i] = cpu_to_be32(buffer[i]); |
| 580 | } |
| 581 | cee->get_stats_pending = BFA_FALSE; |
| 582 | bfa_trc(cee, 0); |
| 583 | if (cee->cbfn.get_stats_cbfn) { |
| 584 | bfa_trc(cee, 0); |
| 585 | cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status); |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * bfa_cee_reset_stats_isr() |
| 591 | * |
| 592 | * @brief CEE ISR for reset-stats responses from f/w |
| 593 | * |
| 594 | * @param[in] cee - Pointer to the CEE module |
| 595 | * status - Return status from the f/w |
| 596 | * |
| 597 | * @return void |
| 598 | */ |
| 599 | static void |
| 600 | bfa_cee_reset_stats_isr(struct bfa_cee_s *cee, bfa_status_t status) |
| 601 | { |
| 602 | cee->reset_stats_status = status; |
| 603 | cee->reset_stats_pending = BFA_FALSE; |
| 604 | if (cee->cbfn.reset_stats_cbfn) |
| 605 | cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status); |
| 606 | } |
| 607 | |
| 608 | /* |
| 609 | * bfa_cee_meminfo() |
| 610 | * |
| 611 | * @brief Returns the size of the DMA memory needed by CEE module |
| 612 | * |
| 613 | * @param[in] void |
| 614 | * |
| 615 | * @return Size of DMA region |
| 616 | */ |
| 617 | u32 |
| 618 | bfa_cee_meminfo(void) |
| 619 | { |
| 620 | return BFA_ROUNDUP(sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ) + |
| 621 | BFA_ROUNDUP(sizeof(struct bfa_cee_stats_s), BFA_DMA_ALIGN_SZ); |
| 622 | } |
| 623 | |
| 624 | /* |
| 625 | * bfa_cee_mem_claim() |
| 626 | * |
| 627 | * @brief Initialized CEE DMA Memory |
| 628 | * |
| 629 | * @param[in] cee CEE module pointer |
| 630 | * dma_kva Kernel Virtual Address of CEE DMA Memory |
| 631 | * dma_pa Physical Address of CEE DMA Memory |
| 632 | * |
| 633 | * @return void |
| 634 | */ |
| 635 | void |
| 636 | bfa_cee_mem_claim(struct bfa_cee_s *cee, u8 *dma_kva, u64 dma_pa) |
| 637 | { |
| 638 | cee->attr_dma.kva = dma_kva; |
| 639 | cee->attr_dma.pa = dma_pa; |
| 640 | cee->stats_dma.kva = dma_kva + BFA_ROUNDUP( |
| 641 | sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ); |
| 642 | cee->stats_dma.pa = dma_pa + BFA_ROUNDUP( |
| 643 | sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ); |
| 644 | cee->attr = (struct bfa_cee_attr_s *) dma_kva; |
| 645 | cee->stats = (struct bfa_cee_stats_s *) (dma_kva + BFA_ROUNDUP( |
| 646 | sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ)); |
| 647 | } |
| 648 | |
| 649 | /* |
| 650 | * bfa_cee_get_attr() |
| 651 | * |
| 652 | * @brief |
| 653 | * Send the request to the f/w to fetch CEE attributes. |
| 654 | * |
| 655 | * @param[in] Pointer to the CEE module data structure. |
| 656 | * |
| 657 | * @return Status |
| 658 | */ |
| 659 | |
| 660 | bfa_status_t |
| 661 | bfa_cee_get_attr(struct bfa_cee_s *cee, struct bfa_cee_attr_s *attr, |
| 662 | bfa_cee_get_attr_cbfn_t cbfn, void *cbarg) |
| 663 | { |
| 664 | struct bfi_cee_get_req_s *cmd; |
| 665 | |
| 666 | WARN_ON((cee == NULL) || (cee->ioc == NULL)); |
| 667 | bfa_trc(cee, 0); |
| 668 | if (!bfa_ioc_is_operational(cee->ioc)) { |
| 669 | bfa_trc(cee, 0); |
| 670 | return BFA_STATUS_IOC_FAILURE; |
| 671 | } |
| 672 | if (cee->get_attr_pending == BFA_TRUE) { |
| 673 | bfa_trc(cee, 0); |
| 674 | return BFA_STATUS_DEVBUSY; |
| 675 | } |
| 676 | cee->get_attr_pending = BFA_TRUE; |
| 677 | cmd = (struct bfi_cee_get_req_s *) cee->get_cfg_mb.msg; |
| 678 | cee->attr = attr; |
| 679 | cee->cbfn.get_attr_cbfn = cbfn; |
| 680 | cee->cbfn.get_attr_cbarg = cbarg; |
| 681 | bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ, |
| 682 | bfa_ioc_portid(cee->ioc)); |
| 683 | bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa); |
| 684 | bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb); |
| 685 | |
| 686 | return BFA_STATUS_OK; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * bfa_cee_get_stats() |
| 691 | * |
| 692 | * @brief |
| 693 | * Send the request to the f/w to fetch CEE statistics. |
| 694 | * |
| 695 | * @param[in] Pointer to the CEE module data structure. |
| 696 | * |
| 697 | * @return Status |
| 698 | */ |
| 699 | |
| 700 | bfa_status_t |
| 701 | bfa_cee_get_stats(struct bfa_cee_s *cee, struct bfa_cee_stats_s *stats, |
| 702 | bfa_cee_get_stats_cbfn_t cbfn, void *cbarg) |
| 703 | { |
| 704 | struct bfi_cee_get_req_s *cmd; |
| 705 | |
| 706 | WARN_ON((cee == NULL) || (cee->ioc == NULL)); |
| 707 | |
| 708 | if (!bfa_ioc_is_operational(cee->ioc)) { |
| 709 | bfa_trc(cee, 0); |
| 710 | return BFA_STATUS_IOC_FAILURE; |
| 711 | } |
| 712 | if (cee->get_stats_pending == BFA_TRUE) { |
| 713 | bfa_trc(cee, 0); |
| 714 | return BFA_STATUS_DEVBUSY; |
| 715 | } |
| 716 | cee->get_stats_pending = BFA_TRUE; |
| 717 | cmd = (struct bfi_cee_get_req_s *) cee->get_stats_mb.msg; |
| 718 | cee->stats = stats; |
| 719 | cee->cbfn.get_stats_cbfn = cbfn; |
| 720 | cee->cbfn.get_stats_cbarg = cbarg; |
| 721 | bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ, |
| 722 | bfa_ioc_portid(cee->ioc)); |
| 723 | bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa); |
| 724 | bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb); |
| 725 | |
| 726 | return BFA_STATUS_OK; |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | * bfa_cee_reset_stats() |
| 731 | * |
| 732 | * @brief Clears CEE Stats in the f/w. |
| 733 | * |
| 734 | * @param[in] Pointer to the CEE module data structure. |
| 735 | * |
| 736 | * @return Status |
| 737 | */ |
| 738 | |
| 739 | bfa_status_t |
| 740 | bfa_cee_reset_stats(struct bfa_cee_s *cee, |
| 741 | bfa_cee_reset_stats_cbfn_t cbfn, void *cbarg) |
| 742 | { |
| 743 | struct bfi_cee_reset_stats_s *cmd; |
| 744 | |
| 745 | WARN_ON((cee == NULL) || (cee->ioc == NULL)); |
| 746 | if (!bfa_ioc_is_operational(cee->ioc)) { |
| 747 | bfa_trc(cee, 0); |
| 748 | return BFA_STATUS_IOC_FAILURE; |
| 749 | } |
| 750 | if (cee->reset_stats_pending == BFA_TRUE) { |
| 751 | bfa_trc(cee, 0); |
| 752 | return BFA_STATUS_DEVBUSY; |
| 753 | } |
| 754 | cee->reset_stats_pending = BFA_TRUE; |
| 755 | cmd = (struct bfi_cee_reset_stats_s *) cee->reset_stats_mb.msg; |
| 756 | cee->cbfn.reset_stats_cbfn = cbfn; |
| 757 | cee->cbfn.reset_stats_cbarg = cbarg; |
| 758 | bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS, |
| 759 | bfa_ioc_portid(cee->ioc)); |
| 760 | bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb); |
| 761 | |
| 762 | return BFA_STATUS_OK; |
| 763 | } |
| 764 | |
| 765 | /* |
| 766 | * bfa_cee_isrs() |
| 767 | * |
| 768 | * @brief Handles Mail-box interrupts for CEE module. |
| 769 | * |
| 770 | * @param[in] Pointer to the CEE module data structure. |
| 771 | * |
| 772 | * @return void |
| 773 | */ |
| 774 | |
| 775 | void |
| 776 | bfa_cee_isr(void *cbarg, struct bfi_mbmsg_s *m) |
| 777 | { |
| 778 | union bfi_cee_i2h_msg_u *msg; |
| 779 | struct bfi_cee_get_rsp_s *get_rsp; |
| 780 | struct bfa_cee_s *cee = (struct bfa_cee_s *) cbarg; |
| 781 | msg = (union bfi_cee_i2h_msg_u *) m; |
| 782 | get_rsp = (struct bfi_cee_get_rsp_s *) m; |
| 783 | bfa_trc(cee, msg->mh.msg_id); |
| 784 | switch (msg->mh.msg_id) { |
| 785 | case BFI_CEE_I2H_GET_CFG_RSP: |
| 786 | bfa_trc(cee, get_rsp->cmd_status); |
| 787 | bfa_cee_get_attr_isr(cee, get_rsp->cmd_status); |
| 788 | break; |
| 789 | case BFI_CEE_I2H_GET_STATS_RSP: |
| 790 | bfa_cee_get_stats_isr(cee, get_rsp->cmd_status); |
| 791 | break; |
| 792 | case BFI_CEE_I2H_RESET_STATS_RSP: |
| 793 | bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status); |
| 794 | break; |
| 795 | default: |
| 796 | WARN_ON(1); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* |
| 801 | * bfa_cee_notify() |
| 802 | * |
| 803 | * @brief CEE module IOC event handler. |
| 804 | * |
| 805 | * @param[in] Pointer to the CEE module data structure. |
| 806 | * @param[in] IOC event type |
| 807 | * |
| 808 | * @return void |
| 809 | */ |
| 810 | |
| 811 | void |
| 812 | bfa_cee_notify(void *arg, enum bfa_ioc_event_e event) |
| 813 | { |
| 814 | struct bfa_cee_s *cee = (struct bfa_cee_s *) arg; |
| 815 | |
| 816 | bfa_trc(cee, event); |
| 817 | |
| 818 | switch (event) { |
| 819 | case BFA_IOC_E_DISABLED: |
| 820 | case BFA_IOC_E_FAILED: |
| 821 | if (cee->get_attr_pending == BFA_TRUE) { |
| 822 | cee->get_attr_status = BFA_STATUS_FAILED; |
| 823 | cee->get_attr_pending = BFA_FALSE; |
| 824 | if (cee->cbfn.get_attr_cbfn) { |
| 825 | cee->cbfn.get_attr_cbfn( |
| 826 | cee->cbfn.get_attr_cbarg, |
| 827 | BFA_STATUS_FAILED); |
| 828 | } |
| 829 | } |
| 830 | if (cee->get_stats_pending == BFA_TRUE) { |
| 831 | cee->get_stats_status = BFA_STATUS_FAILED; |
| 832 | cee->get_stats_pending = BFA_FALSE; |
| 833 | if (cee->cbfn.get_stats_cbfn) { |
| 834 | cee->cbfn.get_stats_cbfn( |
| 835 | cee->cbfn.get_stats_cbarg, |
| 836 | BFA_STATUS_FAILED); |
| 837 | } |
| 838 | } |
| 839 | if (cee->reset_stats_pending == BFA_TRUE) { |
| 840 | cee->reset_stats_status = BFA_STATUS_FAILED; |
| 841 | cee->reset_stats_pending = BFA_FALSE; |
| 842 | if (cee->cbfn.reset_stats_cbfn) { |
| 843 | cee->cbfn.reset_stats_cbfn( |
| 844 | cee->cbfn.reset_stats_cbarg, |
| 845 | BFA_STATUS_FAILED); |
| 846 | } |
| 847 | } |
| 848 | break; |
| 849 | |
| 850 | default: |
| 851 | break; |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | /* |
| 856 | * bfa_cee_attach() |
| 857 | * |
| 858 | * @brief CEE module-attach API |
| 859 | * |
| 860 | * @param[in] cee - Pointer to the CEE module data structure |
| 861 | * ioc - Pointer to the ioc module data structure |
| 862 | * dev - Pointer to the device driver module data structure |
| 863 | * The device driver specific mbox ISR functions have |
| 864 | * this pointer as one of the parameters. |
| 865 | * |
| 866 | * @return void |
| 867 | */ |
| 868 | void |
| 869 | bfa_cee_attach(struct bfa_cee_s *cee, struct bfa_ioc_s *ioc, |
| 870 | void *dev) |
| 871 | { |
| 872 | WARN_ON(cee == NULL); |
| 873 | cee->dev = dev; |
| 874 | cee->ioc = ioc; |
| 875 | |
| 876 | bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee); |
| 877 | bfa_q_qe_init(&cee->ioc_notify); |
| 878 | bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee); |
| 879 | list_add_tail(&cee->ioc_notify.qe, &cee->ioc->notify_q); |
| 880 | } |