Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 1 | #include "qlge.h" |
| 2 | |
Ron Mercer | a2e809b | 2009-02-26 10:08:33 +0000 | [diff] [blame] | 3 | int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data) |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 4 | { |
| 5 | int status; |
| 6 | /* wait for reg to come ready */ |
| 7 | status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR); |
| 8 | if (status) |
| 9 | goto exit; |
| 10 | /* set up for reg read */ |
| 11 | ql_write32(qdev, PROC_ADDR, reg | PROC_ADDR_R); |
| 12 | /* wait for reg to come ready */ |
| 13 | status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR); |
| 14 | if (status) |
| 15 | goto exit; |
| 16 | /* get the data */ |
| 17 | *data = ql_read32(qdev, PROC_DATA); |
| 18 | exit: |
| 19 | return status; |
| 20 | } |
| 21 | |
Ron Mercer | a2e809b | 2009-02-26 10:08:33 +0000 | [diff] [blame] | 22 | int ql_write_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 data) |
| 23 | { |
| 24 | int status = 0; |
| 25 | /* wait for reg to come ready */ |
| 26 | status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR); |
| 27 | if (status) |
| 28 | goto exit; |
| 29 | /* write the data to the data reg */ |
| 30 | ql_write32(qdev, PROC_DATA, data); |
| 31 | /* trigger the write */ |
| 32 | ql_write32(qdev, PROC_ADDR, reg); |
| 33 | /* wait for reg to come ready */ |
| 34 | status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR); |
| 35 | if (status) |
| 36 | goto exit; |
| 37 | exit: |
| 38 | return status; |
| 39 | } |
| 40 | |
| 41 | int ql_soft_reset_mpi_risc(struct ql_adapter *qdev) |
| 42 | { |
| 43 | int status; |
| 44 | status = ql_write_mpi_reg(qdev, 0x00001010, 1); |
| 45 | return status; |
| 46 | } |
| 47 | |
Hannes Eder | 2f22d22 | 2008-12-26 00:04:53 -0800 | [diff] [blame] | 48 | static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp) |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 49 | { |
| 50 | int i, status; |
| 51 | |
| 52 | status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK); |
| 53 | if (status) |
| 54 | return -EBUSY; |
| 55 | for (i = 0; i < mbcp->out_count; i++) { |
| 56 | status = |
Ron Mercer | a2e809b | 2009-02-26 10:08:33 +0000 | [diff] [blame] | 57 | ql_read_mpi_reg(qdev, qdev->mailbox_out + i, |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 58 | &mbcp->mbox_out[i]); |
| 59 | if (status) { |
| 60 | QPRINTK(qdev, DRV, ERR, "Failed mailbox read.\n"); |
| 61 | break; |
| 62 | } |
| 63 | } |
| 64 | ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */ |
| 65 | return status; |
| 66 | } |
| 67 | |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 68 | /* Wait for a single mailbox command to complete. |
| 69 | * Returns zero on success. |
| 70 | */ |
| 71 | static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev) |
| 72 | { |
Ron Mercer | 365da87 | 2009-06-07 13:58:29 +0000 | [diff] [blame] | 73 | int count = 100; |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 74 | u32 value; |
| 75 | |
| 76 | do { |
| 77 | value = ql_read32(qdev, STS); |
| 78 | if (value & STS_PI) |
| 79 | return 0; |
Ron Mercer | 365da87 | 2009-06-07 13:58:29 +0000 | [diff] [blame] | 80 | mdelay(UDELAY_DELAY); /* 100ms */ |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 81 | } while (--count); |
| 82 | return -ETIMEDOUT; |
| 83 | } |
| 84 | |
| 85 | /* Execute a single mailbox command. |
| 86 | * Caller must hold PROC_ADDR semaphore. |
| 87 | */ |
| 88 | static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 89 | { |
| 90 | int i, status; |
| 91 | |
| 92 | /* |
| 93 | * Make sure there's nothing pending. |
| 94 | * This shouldn't happen. |
| 95 | */ |
| 96 | if (ql_read32(qdev, CSR) & CSR_HRI) |
| 97 | return -EIO; |
| 98 | |
| 99 | status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK); |
| 100 | if (status) |
| 101 | return status; |
| 102 | |
| 103 | /* |
| 104 | * Fill the outbound mailboxes. |
| 105 | */ |
| 106 | for (i = 0; i < mbcp->in_count; i++) { |
| 107 | status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i, |
| 108 | mbcp->mbox_in[i]); |
| 109 | if (status) |
| 110 | goto end; |
| 111 | } |
| 112 | /* |
| 113 | * Wake up the MPI firmware. |
| 114 | */ |
| 115 | ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT); |
| 116 | end: |
| 117 | ql_sem_unlock(qdev, SEM_PROC_REG_MASK); |
| 118 | return status; |
| 119 | } |
| 120 | |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 121 | /* We are being asked by firmware to accept |
| 122 | * a change to the port. This is only |
| 123 | * a change to max frame sizes (Tx/Rx), pause |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 124 | * parameters, or loopback mode. We wake up a worker |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 125 | * to handler processing this since a mailbox command |
| 126 | * will need to be sent to ACK the request. |
| 127 | */ |
| 128 | static int ql_idc_req_aen(struct ql_adapter *qdev) |
| 129 | { |
| 130 | int status; |
| 131 | struct mbox_params *mbcp = &qdev->idc_mbc; |
| 132 | |
| 133 | QPRINTK(qdev, DRV, ERR, "Enter!\n"); |
| 134 | /* Get the status data and start up a thread to |
| 135 | * handle the request. |
| 136 | */ |
| 137 | mbcp = &qdev->idc_mbc; |
| 138 | mbcp->out_count = 4; |
| 139 | status = ql_get_mb_sts(qdev, mbcp); |
| 140 | if (status) { |
| 141 | QPRINTK(qdev, DRV, ERR, |
| 142 | "Could not read MPI, resetting ASIC!\n"); |
| 143 | ql_queue_asic_error(qdev); |
| 144 | } else { |
| 145 | /* Begin polled mode early so |
| 146 | * we don't get another interrupt |
| 147 | * when we leave mpi_worker. |
| 148 | */ |
| 149 | ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16)); |
| 150 | queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0); |
| 151 | } |
| 152 | return status; |
| 153 | } |
| 154 | |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 155 | /* Process an inter-device event completion. |
| 156 | * If good, signal the caller's completion. |
| 157 | */ |
| 158 | static int ql_idc_cmplt_aen(struct ql_adapter *qdev) |
| 159 | { |
| 160 | int status; |
| 161 | struct mbox_params *mbcp = &qdev->idc_mbc; |
| 162 | mbcp->out_count = 4; |
| 163 | status = ql_get_mb_sts(qdev, mbcp); |
| 164 | if (status) { |
| 165 | QPRINTK(qdev, DRV, ERR, |
| 166 | "Could not read MPI, resetting RISC!\n"); |
| 167 | ql_queue_fw_error(qdev); |
| 168 | } else |
| 169 | /* Wake up the sleeping mpi_idc_work thread that is |
| 170 | * waiting for this event. |
| 171 | */ |
| 172 | complete(&qdev->ide_completion); |
| 173 | |
| 174 | return status; |
| 175 | } |
Ron Mercer | 5700abe | 2009-03-03 12:10:32 +0000 | [diff] [blame] | 176 | |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 177 | static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 178 | { |
Ron Mercer | 5700abe | 2009-03-03 12:10:32 +0000 | [diff] [blame] | 179 | int status; |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 180 | mbcp->out_count = 2; |
| 181 | |
Ron Mercer | 5700abe | 2009-03-03 12:10:32 +0000 | [diff] [blame] | 182 | status = ql_get_mb_sts(qdev, mbcp); |
| 183 | if (status) { |
| 184 | QPRINTK(qdev, DRV, ERR, |
| 185 | "%s: Could not get mailbox status.\n", __func__); |
| 186 | return; |
| 187 | } |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 188 | |
| 189 | qdev->link_status = mbcp->mbox_out[1]; |
| 190 | QPRINTK(qdev, DRV, ERR, "Link Up.\n"); |
Ron Mercer | 5700abe | 2009-03-03 12:10:32 +0000 | [diff] [blame] | 191 | |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 192 | /* If we're coming back from an IDC event |
| 193 | * then set up the CAM and frame routing. |
| 194 | */ |
| 195 | if (test_bit(QL_CAM_RT_SET, &qdev->flags)) { |
| 196 | status = ql_cam_route_initialize(qdev); |
| 197 | if (status) { |
| 198 | QPRINTK(qdev, IFUP, ERR, |
| 199 | "Failed to init CAM/Routing tables.\n"); |
| 200 | return; |
| 201 | } else |
| 202 | clear_bit(QL_CAM_RT_SET, &qdev->flags); |
| 203 | } |
| 204 | |
| 205 | /* Queue up a worker to check the frame |
| 206 | * size information, and fix it if it's not |
| 207 | * to our liking. |
| 208 | */ |
| 209 | if (!test_bit(QL_PORT_CFG, &qdev->flags)) { |
| 210 | QPRINTK(qdev, DRV, ERR, "Queue Port Config Worker!\n"); |
| 211 | set_bit(QL_PORT_CFG, &qdev->flags); |
| 212 | /* Begin polled mode early so |
| 213 | * we don't get another interrupt |
| 214 | * when we leave mpi_worker dpc. |
| 215 | */ |
| 216 | ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16)); |
| 217 | queue_delayed_work(qdev->workqueue, |
| 218 | &qdev->mpi_port_cfg_work, 0); |
| 219 | } |
| 220 | |
Ron Mercer | 6a47330 | 2009-07-02 06:06:12 +0000 | [diff] [blame] | 221 | ql_link_on(qdev); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 225 | { |
Ron Mercer | 11d9fe6 | 2009-03-03 12:10:31 +0000 | [diff] [blame] | 226 | int status; |
| 227 | |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 228 | mbcp->out_count = 3; |
| 229 | |
Ron Mercer | 11d9fe6 | 2009-03-03 12:10:31 +0000 | [diff] [blame] | 230 | status = ql_get_mb_sts(qdev, mbcp); |
| 231 | if (status) |
| 232 | QPRINTK(qdev, DRV, ERR, "Link down AEN broken!\n"); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 233 | |
Ron Mercer | 6a47330 | 2009-07-02 06:06:12 +0000 | [diff] [blame] | 234 | ql_link_off(qdev); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 235 | } |
| 236 | |
Ron Mercer | eae6b58 | 2009-03-03 12:10:30 +0000 | [diff] [blame] | 237 | static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 238 | { |
| 239 | int status; |
| 240 | |
| 241 | mbcp->out_count = 5; |
| 242 | |
| 243 | status = ql_get_mb_sts(qdev, mbcp); |
| 244 | if (status) |
| 245 | QPRINTK(qdev, DRV, ERR, "SFP in AEN broken!\n"); |
| 246 | else |
| 247 | QPRINTK(qdev, DRV, ERR, "SFP insertion detected.\n"); |
| 248 | |
| 249 | return status; |
| 250 | } |
| 251 | |
| 252 | static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 253 | { |
| 254 | int status; |
| 255 | |
| 256 | mbcp->out_count = 1; |
| 257 | |
| 258 | status = ql_get_mb_sts(qdev, mbcp); |
| 259 | if (status) |
| 260 | QPRINTK(qdev, DRV, ERR, "SFP out AEN broken!\n"); |
| 261 | else |
| 262 | QPRINTK(qdev, DRV, ERR, "SFP removal detected.\n"); |
| 263 | |
| 264 | return status; |
| 265 | } |
| 266 | |
Ron Mercer | fc1f9ea | 2009-03-03 12:10:37 +0000 | [diff] [blame] | 267 | static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 268 | { |
| 269 | int status; |
| 270 | |
| 271 | mbcp->out_count = 6; |
| 272 | |
| 273 | status = ql_get_mb_sts(qdev, mbcp); |
| 274 | if (status) |
| 275 | QPRINTK(qdev, DRV, ERR, "Lost AEN broken!\n"); |
| 276 | else { |
| 277 | int i; |
| 278 | QPRINTK(qdev, DRV, ERR, "Lost AEN detected.\n"); |
| 279 | for (i = 0; i < mbcp->out_count; i++) |
| 280 | QPRINTK(qdev, DRV, ERR, "mbox_out[%d] = 0x%.08x.\n", |
| 281 | i, mbcp->mbox_out[i]); |
| 282 | |
| 283 | } |
| 284 | |
| 285 | return status; |
| 286 | } |
| 287 | |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 288 | static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 289 | { |
Ron Mercer | f56b54f | 2009-03-03 12:10:34 +0000 | [diff] [blame] | 290 | int status; |
| 291 | |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 292 | mbcp->out_count = 2; |
| 293 | |
Ron Mercer | f56b54f | 2009-03-03 12:10:34 +0000 | [diff] [blame] | 294 | status = ql_get_mb_sts(qdev, mbcp); |
| 295 | if (status) { |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 296 | QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n"); |
Ron Mercer | f56b54f | 2009-03-03 12:10:34 +0000 | [diff] [blame] | 297 | } else { |
| 298 | QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n", |
| 299 | mbcp->mbox_out[1]); |
Ron Mercer | 88051b4 | 2009-10-10 09:35:06 +0000 | [diff] [blame] | 300 | qdev->fw_rev_id = mbcp->mbox_out[1]; |
Ron Mercer | f56b54f | 2009-03-03 12:10:34 +0000 | [diff] [blame] | 301 | status = ql_cam_route_initialize(qdev); |
| 302 | if (status) |
| 303 | QPRINTK(qdev, IFUP, ERR, |
| 304 | "Failed to init CAM/Routing tables.\n"); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 305 | } |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 308 | /* Process an async event and clear it unless it's an |
| 309 | * error condition. |
| 310 | * This can get called iteratively from the mpi_work thread |
| 311 | * when events arrive via an interrupt. |
| 312 | * It also gets called when a mailbox command is polling for |
| 313 | * it's completion. */ |
| 314 | static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 315 | { |
| 316 | int status; |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 317 | int orig_count = mbcp->out_count; |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 318 | |
| 319 | /* Just get mailbox zero for now. */ |
| 320 | mbcp->out_count = 1; |
| 321 | status = ql_get_mb_sts(qdev, mbcp); |
| 322 | if (status) { |
| 323 | QPRINTK(qdev, DRV, ERR, |
| 324 | "Could not read MPI, resetting ASIC!\n"); |
| 325 | ql_queue_asic_error(qdev); |
| 326 | goto end; |
| 327 | } |
| 328 | |
| 329 | switch (mbcp->mbox_out[0]) { |
| 330 | |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 331 | /* This case is only active when we arrive here |
| 332 | * as a result of issuing a mailbox command to |
| 333 | * the firmware. |
| 334 | */ |
| 335 | case MB_CMD_STS_INTRMDT: |
| 336 | case MB_CMD_STS_GOOD: |
| 337 | case MB_CMD_STS_INVLD_CMD: |
| 338 | case MB_CMD_STS_XFC_ERR: |
| 339 | case MB_CMD_STS_CSUM_ERR: |
| 340 | case MB_CMD_STS_ERR: |
| 341 | case MB_CMD_STS_PARAM_ERR: |
| 342 | /* We can only get mailbox status if we're polling from an |
| 343 | * unfinished command. Get the rest of the status data and |
| 344 | * return back to the caller. |
| 345 | * We only end up here when we're polling for a mailbox |
| 346 | * command completion. |
| 347 | */ |
| 348 | mbcp->out_count = orig_count; |
| 349 | status = ql_get_mb_sts(qdev, mbcp); |
| 350 | return status; |
| 351 | |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 352 | /* We are being asked by firmware to accept |
| 353 | * a change to the port. This is only |
| 354 | * a change to max frame sizes (Tx/Rx), pause |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 355 | * parameters, or loopback mode. |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 356 | */ |
| 357 | case AEN_IDC_REQ: |
| 358 | status = ql_idc_req_aen(qdev); |
| 359 | break; |
| 360 | |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 361 | /* Process and inbound IDC event. |
| 362 | * This will happen when we're trying to |
| 363 | * change tx/rx max frame size, change pause |
Martin Olsson | 98a1708 | 2009-04-22 18:21:29 +0200 | [diff] [blame] | 364 | * parameters or loopback mode. |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 365 | */ |
| 366 | case AEN_IDC_CMPLT: |
| 367 | case AEN_IDC_EXT: |
| 368 | status = ql_idc_cmplt_aen(qdev); |
| 369 | break; |
| 370 | |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 371 | case AEN_LINK_UP: |
| 372 | ql_link_up(qdev, mbcp); |
| 373 | break; |
| 374 | |
| 375 | case AEN_LINK_DOWN: |
| 376 | ql_link_down(qdev, mbcp); |
| 377 | break; |
| 378 | |
| 379 | case AEN_FW_INIT_DONE: |
Ron Mercer | f56b54f | 2009-03-03 12:10:34 +0000 | [diff] [blame] | 380 | /* If we're in process on executing the firmware, |
| 381 | * then convert the status to normal mailbox status. |
| 382 | */ |
| 383 | if (mbcp->mbox_in[0] == MB_CMD_EX_FW) { |
| 384 | mbcp->out_count = orig_count; |
| 385 | status = ql_get_mb_sts(qdev, mbcp); |
| 386 | mbcp->mbox_out[0] = MB_CMD_STS_GOOD; |
| 387 | return status; |
| 388 | } |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 389 | ql_init_fw_done(qdev, mbcp); |
| 390 | break; |
| 391 | |
Ron Mercer | eae6b58 | 2009-03-03 12:10:30 +0000 | [diff] [blame] | 392 | case AEN_AEN_SFP_IN: |
| 393 | ql_sfp_in(qdev, mbcp); |
| 394 | break; |
| 395 | |
| 396 | case AEN_AEN_SFP_OUT: |
| 397 | ql_sfp_out(qdev, mbcp); |
| 398 | break; |
| 399 | |
Ron Mercer | 7c92191 | 2009-03-03 12:10:35 +0000 | [diff] [blame] | 400 | /* This event can arrive at boot time or after an |
| 401 | * MPI reset if the firmware failed to initialize. |
| 402 | */ |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 403 | case AEN_FW_INIT_FAIL: |
Ron Mercer | 7c92191 | 2009-03-03 12:10:35 +0000 | [diff] [blame] | 404 | /* If we're in process on executing the firmware, |
| 405 | * then convert the status to normal mailbox status. |
| 406 | */ |
| 407 | if (mbcp->mbox_in[0] == MB_CMD_EX_FW) { |
| 408 | mbcp->out_count = orig_count; |
| 409 | status = ql_get_mb_sts(qdev, mbcp); |
| 410 | mbcp->mbox_out[0] = MB_CMD_STS_ERR; |
| 411 | return status; |
| 412 | } |
| 413 | QPRINTK(qdev, DRV, ERR, |
| 414 | "Firmware initialization failed.\n"); |
| 415 | status = -EIO; |
| 416 | ql_queue_fw_error(qdev); |
| 417 | break; |
| 418 | |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 419 | case AEN_SYS_ERR: |
Ron Mercer | bb66767 | 2009-03-03 12:10:36 +0000 | [diff] [blame] | 420 | QPRINTK(qdev, DRV, ERR, |
| 421 | "System Error.\n"); |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 422 | ql_queue_fw_error(qdev); |
Ron Mercer | bb66767 | 2009-03-03 12:10:36 +0000 | [diff] [blame] | 423 | status = -EIO; |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 424 | break; |
| 425 | |
Ron Mercer | fc1f9ea | 2009-03-03 12:10:37 +0000 | [diff] [blame] | 426 | case AEN_AEN_LOST: |
| 427 | ql_aen_lost(qdev, mbcp); |
| 428 | break; |
| 429 | |
Ron Mercer | 91ced68 | 2009-10-10 09:35:05 +0000 | [diff] [blame] | 430 | case AEN_DCBX_CHG: |
| 431 | /* Need to support AEN 8110 */ |
| 432 | break; |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 433 | default: |
| 434 | QPRINTK(qdev, DRV, ERR, |
| 435 | "Unsupported AE %.08x.\n", mbcp->mbox_out[0]); |
| 436 | /* Clear the MPI firmware status. */ |
| 437 | } |
| 438 | end: |
| 439 | ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT); |
Ron Mercer | 709ac4f | 2009-06-07 13:58:26 +0000 | [diff] [blame] | 440 | /* Restore the original mailbox count to |
| 441 | * what the caller asked for. This can get |
| 442 | * changed when a mailbox command is waiting |
| 443 | * for a response and an AEN arrives and |
| 444 | * is handled. |
| 445 | * */ |
| 446 | mbcp->out_count = orig_count; |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 447 | return status; |
| 448 | } |
| 449 | |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 450 | /* Execute a single mailbox command. |
| 451 | * mbcp is a pointer to an array of u32. Each |
| 452 | * element in the array contains the value for it's |
| 453 | * respective mailbox register. |
| 454 | */ |
| 455 | static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp) |
| 456 | { |
| 457 | int status, count; |
| 458 | |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 459 | |
| 460 | /* Begin polled mode for MPI */ |
| 461 | ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16)); |
| 462 | |
| 463 | /* Load the mailbox registers and wake up MPI RISC. */ |
| 464 | status = ql_exec_mb_cmd(qdev, mbcp); |
| 465 | if (status) |
| 466 | goto end; |
| 467 | |
| 468 | |
| 469 | /* If we're generating a system error, then there's nothing |
| 470 | * to wait for. |
| 471 | */ |
| 472 | if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR) |
| 473 | goto end; |
| 474 | |
| 475 | /* Wait for the command to complete. We loop |
| 476 | * here because some AEN might arrive while |
| 477 | * we're waiting for the mailbox command to |
| 478 | * complete. If more than 5 arrive then we can |
| 479 | * assume something is wrong. */ |
| 480 | count = 5; |
| 481 | do { |
| 482 | /* Wait for the interrupt to come in. */ |
| 483 | status = ql_wait_mbx_cmd_cmplt(qdev); |
| 484 | if (status) |
| 485 | goto end; |
| 486 | |
| 487 | /* Process the event. If it's an AEN, it |
| 488 | * will be handled in-line or a worker |
| 489 | * will be spawned. If it's our completion |
| 490 | * we will catch it below. |
| 491 | */ |
| 492 | status = ql_mpi_handler(qdev, mbcp); |
| 493 | if (status) |
| 494 | goto end; |
| 495 | |
| 496 | /* It's either the completion for our mailbox |
| 497 | * command complete or an AEN. If it's our |
| 498 | * completion then get out. |
| 499 | */ |
| 500 | if (((mbcp->mbox_out[0] & 0x0000f000) == |
| 501 | MB_CMD_STS_GOOD) || |
| 502 | ((mbcp->mbox_out[0] & 0x0000f000) == |
| 503 | MB_CMD_STS_INTRMDT)) |
| 504 | break; |
| 505 | } while (--count); |
| 506 | |
| 507 | if (!count) { |
| 508 | QPRINTK(qdev, DRV, ERR, |
| 509 | "Timed out waiting for mailbox complete.\n"); |
| 510 | status = -ETIMEDOUT; |
| 511 | goto end; |
| 512 | } |
| 513 | |
| 514 | /* Now we can clear the interrupt condition |
| 515 | * and look at our status. |
| 516 | */ |
| 517 | ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT); |
| 518 | |
| 519 | if (((mbcp->mbox_out[0] & 0x0000f000) != |
| 520 | MB_CMD_STS_GOOD) && |
| 521 | ((mbcp->mbox_out[0] & 0x0000f000) != |
| 522 | MB_CMD_STS_INTRMDT)) { |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 523 | status = -EIO; |
| 524 | } |
| 525 | end: |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 526 | /* End polled mode for MPI */ |
| 527 | ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI); |
| 528 | return status; |
| 529 | } |
| 530 | |
Ron Mercer | cfec0cb | 2009-06-09 05:39:29 +0000 | [diff] [blame] | 531 | |
| 532 | /* Get MPI firmware version. This will be used for |
| 533 | * driver banner and for ethtool info. |
| 534 | * Returns zero on success. |
| 535 | */ |
| 536 | int ql_mb_about_fw(struct ql_adapter *qdev) |
| 537 | { |
| 538 | struct mbox_params mbc; |
| 539 | struct mbox_params *mbcp = &mbc; |
| 540 | int status = 0; |
| 541 | |
| 542 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 543 | |
| 544 | mbcp->in_count = 1; |
| 545 | mbcp->out_count = 3; |
| 546 | |
| 547 | mbcp->mbox_in[0] = MB_CMD_ABOUT_FW; |
| 548 | |
| 549 | status = ql_mailbox_command(qdev, mbcp); |
| 550 | if (status) |
| 551 | return status; |
| 552 | |
| 553 | if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 554 | QPRINTK(qdev, DRV, ERR, |
| 555 | "Failed about firmware command\n"); |
| 556 | status = -EIO; |
| 557 | } |
| 558 | |
| 559 | /* Store the firmware version */ |
| 560 | qdev->fw_rev_id = mbcp->mbox_out[1]; |
| 561 | |
| 562 | return status; |
| 563 | } |
| 564 | |
Ron Mercer | ca0413b | 2009-03-02 08:07:30 +0000 | [diff] [blame] | 565 | /* Get functional state for MPI firmware. |
| 566 | * Returns zero on success. |
| 567 | */ |
| 568 | int ql_mb_get_fw_state(struct ql_adapter *qdev) |
| 569 | { |
| 570 | struct mbox_params mbc; |
| 571 | struct mbox_params *mbcp = &mbc; |
| 572 | int status = 0; |
| 573 | |
| 574 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 575 | |
| 576 | mbcp->in_count = 1; |
| 577 | mbcp->out_count = 2; |
| 578 | |
| 579 | mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE; |
| 580 | |
| 581 | status = ql_mailbox_command(qdev, mbcp); |
| 582 | if (status) |
| 583 | return status; |
| 584 | |
| 585 | if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 586 | QPRINTK(qdev, DRV, ERR, |
| 587 | "Failed Get Firmware State.\n"); |
| 588 | status = -EIO; |
| 589 | } |
| 590 | |
| 591 | /* If bit zero is set in mbx 1 then the firmware is |
| 592 | * running, but not initialized. This should never |
| 593 | * happen. |
| 594 | */ |
| 595 | if (mbcp->mbox_out[1] & 1) { |
| 596 | QPRINTK(qdev, DRV, ERR, |
| 597 | "Firmware waiting for initialization.\n"); |
| 598 | status = -EIO; |
| 599 | } |
| 600 | |
| 601 | return status; |
| 602 | } |
| 603 | |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 604 | /* Send and ACK mailbox command to the firmware to |
| 605 | * let it continue with the change. |
| 606 | */ |
| 607 | int ql_mb_idc_ack(struct ql_adapter *qdev) |
| 608 | { |
| 609 | struct mbox_params mbc; |
| 610 | struct mbox_params *mbcp = &mbc; |
| 611 | int status = 0; |
| 612 | |
| 613 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 614 | |
| 615 | mbcp->in_count = 5; |
| 616 | mbcp->out_count = 1; |
| 617 | |
| 618 | mbcp->mbox_in[0] = MB_CMD_IDC_ACK; |
| 619 | mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1]; |
| 620 | mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2]; |
| 621 | mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3]; |
| 622 | mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4]; |
| 623 | |
| 624 | status = ql_mailbox_command(qdev, mbcp); |
| 625 | if (status) |
| 626 | return status; |
| 627 | |
| 628 | if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 629 | QPRINTK(qdev, DRV, ERR, |
| 630 | "Failed IDC ACK send.\n"); |
| 631 | status = -EIO; |
| 632 | } |
| 633 | return status; |
| 634 | } |
| 635 | |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 636 | /* Get link settings and maximum frame size settings |
| 637 | * for the current port. |
| 638 | * Most likely will block. |
| 639 | */ |
Ron Mercer | 1d30df2 | 2009-10-21 11:07:38 +0000 | [diff] [blame] | 640 | int ql_mb_set_port_cfg(struct ql_adapter *qdev) |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 641 | { |
| 642 | struct mbox_params mbc; |
| 643 | struct mbox_params *mbcp = &mbc; |
| 644 | int status = 0; |
| 645 | |
| 646 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 647 | |
| 648 | mbcp->in_count = 3; |
| 649 | mbcp->out_count = 1; |
| 650 | |
| 651 | mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG; |
| 652 | mbcp->mbox_in[1] = qdev->link_config; |
| 653 | mbcp->mbox_in[2] = qdev->max_frame_size; |
| 654 | |
| 655 | |
| 656 | status = ql_mailbox_command(qdev, mbcp); |
| 657 | if (status) |
| 658 | return status; |
| 659 | |
| 660 | if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) { |
| 661 | QPRINTK(qdev, DRV, ERR, |
| 662 | "Port Config sent, wait for IDC.\n"); |
| 663 | } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 664 | QPRINTK(qdev, DRV, ERR, |
| 665 | "Failed Set Port Configuration.\n"); |
| 666 | status = -EIO; |
| 667 | } |
| 668 | return status; |
| 669 | } |
| 670 | |
| 671 | /* Get link settings and maximum frame size settings |
| 672 | * for the current port. |
| 673 | * Most likely will block. |
| 674 | */ |
Ron Mercer | 1d30df2 | 2009-10-21 11:07:38 +0000 | [diff] [blame] | 675 | int ql_mb_get_port_cfg(struct ql_adapter *qdev) |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 676 | { |
| 677 | struct mbox_params mbc; |
| 678 | struct mbox_params *mbcp = &mbc; |
| 679 | int status = 0; |
| 680 | |
| 681 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 682 | |
| 683 | mbcp->in_count = 1; |
| 684 | mbcp->out_count = 3; |
| 685 | |
| 686 | mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG; |
| 687 | |
| 688 | status = ql_mailbox_command(qdev, mbcp); |
| 689 | if (status) |
| 690 | return status; |
| 691 | |
| 692 | if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 693 | QPRINTK(qdev, DRV, ERR, |
| 694 | "Failed Get Port Configuration.\n"); |
| 695 | status = -EIO; |
| 696 | } else { |
| 697 | QPRINTK(qdev, DRV, DEBUG, |
| 698 | "Passed Get Port Configuration.\n"); |
| 699 | qdev->link_config = mbcp->mbox_out[1]; |
| 700 | qdev->max_frame_size = mbcp->mbox_out[2]; |
| 701 | } |
| 702 | return status; |
| 703 | } |
| 704 | |
| 705 | /* IDC - Inter Device Communication... |
| 706 | * Some firmware commands require consent of adjacent FCOE |
| 707 | * function. This function waits for the OK, or a |
| 708 | * counter-request for a little more time.i |
| 709 | * The firmware will complete the request if the other |
| 710 | * function doesn't respond. |
| 711 | */ |
| 712 | static int ql_idc_wait(struct ql_adapter *qdev) |
| 713 | { |
| 714 | int status = -ETIMEDOUT; |
| 715 | long wait_time = 1 * HZ; |
| 716 | struct mbox_params *mbcp = &qdev->idc_mbc; |
| 717 | do { |
| 718 | /* Wait here for the command to complete |
| 719 | * via the IDC process. |
| 720 | */ |
| 721 | wait_time = |
| 722 | wait_for_completion_timeout(&qdev->ide_completion, |
| 723 | wait_time); |
| 724 | if (!wait_time) { |
| 725 | QPRINTK(qdev, DRV, ERR, |
| 726 | "IDC Timeout.\n"); |
| 727 | break; |
| 728 | } |
| 729 | /* Now examine the response from the IDC process. |
| 730 | * We might have a good completion or a request for |
| 731 | * more wait time. |
| 732 | */ |
| 733 | if (mbcp->mbox_out[0] == AEN_IDC_EXT) { |
| 734 | QPRINTK(qdev, DRV, ERR, |
| 735 | "IDC Time Extension from function.\n"); |
| 736 | wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f; |
| 737 | } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) { |
| 738 | QPRINTK(qdev, DRV, ERR, |
| 739 | "IDC Success.\n"); |
| 740 | status = 0; |
| 741 | break; |
| 742 | } else { |
| 743 | QPRINTK(qdev, DRV, ERR, |
| 744 | "IDC: Invalid State 0x%.04x.\n", |
| 745 | mbcp->mbox_out[0]); |
| 746 | status = -EIO; |
| 747 | break; |
| 748 | } |
| 749 | } while (wait_time); |
| 750 | |
| 751 | return status; |
| 752 | } |
| 753 | |
Ron Mercer | d8eb59d | 2009-10-21 11:07:39 +0000 | [diff] [blame^] | 754 | int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config) |
| 755 | { |
| 756 | struct mbox_params mbc; |
| 757 | struct mbox_params *mbcp = &mbc; |
| 758 | int status; |
| 759 | |
| 760 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 761 | |
| 762 | mbcp->in_count = 2; |
| 763 | mbcp->out_count = 1; |
| 764 | |
| 765 | mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG; |
| 766 | mbcp->mbox_in[1] = led_config; |
| 767 | |
| 768 | |
| 769 | status = ql_mailbox_command(qdev, mbcp); |
| 770 | if (status) |
| 771 | return status; |
| 772 | |
| 773 | if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 774 | QPRINTK(qdev, DRV, ERR, |
| 775 | "Failed to set LED Configuration.\n"); |
| 776 | status = -EIO; |
| 777 | } |
| 778 | |
| 779 | return status; |
| 780 | } |
| 781 | |
| 782 | int ql_mb_get_led_cfg(struct ql_adapter *qdev) |
| 783 | { |
| 784 | struct mbox_params mbc; |
| 785 | struct mbox_params *mbcp = &mbc; |
| 786 | int status; |
| 787 | |
| 788 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 789 | |
| 790 | mbcp->in_count = 1; |
| 791 | mbcp->out_count = 2; |
| 792 | |
| 793 | mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG; |
| 794 | |
| 795 | status = ql_mailbox_command(qdev, mbcp); |
| 796 | if (status) |
| 797 | return status; |
| 798 | |
| 799 | if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) { |
| 800 | QPRINTK(qdev, DRV, ERR, |
| 801 | "Failed to get LED Configuration.\n"); |
| 802 | status = -EIO; |
| 803 | } else |
| 804 | qdev->led_config = mbcp->mbox_out[1]; |
| 805 | |
| 806 | return status; |
| 807 | } |
| 808 | |
Ron Mercer | 84087f4 | 2009-10-08 09:54:41 +0000 | [diff] [blame] | 809 | int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control) |
| 810 | { |
| 811 | struct mbox_params mbc; |
| 812 | struct mbox_params *mbcp = &mbc; |
| 813 | int status; |
| 814 | |
| 815 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 816 | |
| 817 | mbcp->in_count = 1; |
| 818 | mbcp->out_count = 2; |
| 819 | |
| 820 | mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL; |
| 821 | mbcp->mbox_in[1] = control; |
| 822 | |
| 823 | status = ql_mailbox_command(qdev, mbcp); |
| 824 | if (status) |
| 825 | return status; |
| 826 | |
| 827 | if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) |
| 828 | return status; |
| 829 | |
| 830 | if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) { |
| 831 | QPRINTK(qdev, DRV, ERR, |
| 832 | "Command not supported by firmware.\n"); |
| 833 | status = -EINVAL; |
| 834 | } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) { |
| 835 | /* This indicates that the firmware is |
| 836 | * already in the state we are trying to |
| 837 | * change it to. |
| 838 | */ |
| 839 | QPRINTK(qdev, DRV, ERR, |
| 840 | "Command parameters make no change.\n"); |
| 841 | } |
| 842 | return status; |
| 843 | } |
| 844 | |
| 845 | /* Returns a negative error code or the mailbox command status. */ |
| 846 | static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control) |
| 847 | { |
| 848 | struct mbox_params mbc; |
| 849 | struct mbox_params *mbcp = &mbc; |
| 850 | int status; |
| 851 | |
| 852 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 853 | *control = 0; |
| 854 | |
| 855 | mbcp->in_count = 1; |
| 856 | mbcp->out_count = 1; |
| 857 | |
| 858 | mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL; |
| 859 | |
| 860 | status = ql_mailbox_command(qdev, mbcp); |
| 861 | if (status) |
| 862 | return status; |
| 863 | |
| 864 | if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) { |
| 865 | *control = mbcp->mbox_in[1]; |
| 866 | return status; |
| 867 | } |
| 868 | |
| 869 | if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) { |
| 870 | QPRINTK(qdev, DRV, ERR, |
| 871 | "Command not supported by firmware.\n"); |
| 872 | status = -EINVAL; |
| 873 | } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) { |
| 874 | QPRINTK(qdev, DRV, ERR, |
| 875 | "Failed to get MPI traffic control.\n"); |
| 876 | status = -EIO; |
| 877 | } |
| 878 | return status; |
| 879 | } |
| 880 | |
| 881 | int ql_wait_fifo_empty(struct ql_adapter *qdev) |
| 882 | { |
| 883 | int count = 5; |
| 884 | u32 mgmnt_fifo_empty; |
| 885 | u32 nic_fifo_empty; |
| 886 | |
| 887 | do { |
| 888 | nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE; |
| 889 | ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty); |
| 890 | mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY; |
| 891 | if (nic_fifo_empty && mgmnt_fifo_empty) |
| 892 | return 0; |
| 893 | msleep(100); |
| 894 | } while (count-- > 0); |
| 895 | return -ETIMEDOUT; |
| 896 | } |
| 897 | |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 898 | /* API called in work thread context to set new TX/RX |
| 899 | * maximum frame size values to match MTU. |
| 900 | */ |
| 901 | static int ql_set_port_cfg(struct ql_adapter *qdev) |
| 902 | { |
| 903 | int status; |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 904 | rtnl_lock(); |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 905 | status = ql_mb_set_port_cfg(qdev); |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 906 | rtnl_unlock(); |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 907 | if (status) |
| 908 | return status; |
| 909 | status = ql_idc_wait(qdev); |
| 910 | return status; |
| 911 | } |
| 912 | |
| 913 | /* The following routines are worker threads that process |
| 914 | * events that may sleep waiting for completion. |
| 915 | */ |
| 916 | |
| 917 | /* This thread gets the maximum TX and RX frame size values |
| 918 | * from the firmware and, if necessary, changes them to match |
| 919 | * the MTU setting. |
| 920 | */ |
| 921 | void ql_mpi_port_cfg_work(struct work_struct *work) |
| 922 | { |
| 923 | struct ql_adapter *qdev = |
| 924 | container_of(work, struct ql_adapter, mpi_port_cfg_work.work); |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 925 | int status; |
| 926 | |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 927 | rtnl_lock(); |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 928 | status = ql_mb_get_port_cfg(qdev); |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 929 | rtnl_unlock(); |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 930 | if (status) { |
| 931 | QPRINTK(qdev, DRV, ERR, |
| 932 | "Bug: Failed to get port config data.\n"); |
| 933 | goto err; |
| 934 | } |
| 935 | |
Ron Mercer | c8269b2 | 2009-06-07 13:58:27 +0000 | [diff] [blame] | 936 | if (qdev->link_config & CFG_JUMBO_FRAME_SIZE && |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 937 | qdev->max_frame_size == |
| 938 | CFG_DEFAULT_MAX_FRAME_SIZE) |
| 939 | goto end; |
| 940 | |
| 941 | qdev->link_config |= CFG_JUMBO_FRAME_SIZE; |
| 942 | qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE; |
| 943 | status = ql_set_port_cfg(qdev); |
| 944 | if (status) { |
| 945 | QPRINTK(qdev, DRV, ERR, |
| 946 | "Bug: Failed to set port config data.\n"); |
| 947 | goto err; |
| 948 | } |
| 949 | end: |
| 950 | clear_bit(QL_PORT_CFG, &qdev->flags); |
| 951 | return; |
| 952 | err: |
| 953 | ql_queue_fw_error(qdev); |
| 954 | goto end; |
| 955 | } |
| 956 | |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 957 | /* Process an inter-device request. This is issues by |
| 958 | * the firmware in response to another function requesting |
| 959 | * a change to the port. We set a flag to indicate a change |
| 960 | * has been made and then send a mailbox command ACKing |
| 961 | * the change request. |
| 962 | */ |
| 963 | void ql_mpi_idc_work(struct work_struct *work) |
| 964 | { |
| 965 | struct ql_adapter *qdev = |
| 966 | container_of(work, struct ql_adapter, mpi_idc_work.work); |
| 967 | int status; |
| 968 | struct mbox_params *mbcp = &qdev->idc_mbc; |
| 969 | u32 aen; |
| 970 | |
| 971 | aen = mbcp->mbox_out[1] >> 16; |
| 972 | |
| 973 | switch (aen) { |
| 974 | default: |
| 975 | QPRINTK(qdev, DRV, ERR, |
| 976 | "Bug: Unhandled IDC action.\n"); |
| 977 | break; |
| 978 | case MB_CMD_PORT_RESET: |
| 979 | case MB_CMD_SET_PORT_CFG: |
| 980 | case MB_CMD_STOP_FW: |
Ron Mercer | 6a47330 | 2009-07-02 06:06:12 +0000 | [diff] [blame] | 981 | ql_link_off(qdev); |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 982 | /* Signal the resulting link up AEN |
| 983 | * that the frame routing and mac addr |
| 984 | * needs to be set. |
| 985 | * */ |
| 986 | set_bit(QL_CAM_RT_SET, &qdev->flags); |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 987 | rtnl_lock(); |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 988 | status = ql_mb_idc_ack(qdev); |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 989 | rtnl_unlock(); |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 990 | if (status) { |
| 991 | QPRINTK(qdev, DRV, ERR, |
| 992 | "Bug: No pending IDC!\n"); |
| 993 | } |
| 994 | } |
| 995 | } |
| 996 | |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 997 | void ql_mpi_work(struct work_struct *work) |
| 998 | { |
| 999 | struct ql_adapter *qdev = |
| 1000 | container_of(work, struct ql_adapter, mpi_work.work); |
| 1001 | struct mbox_params mbc; |
| 1002 | struct mbox_params *mbcp = &mbc; |
Ron Mercer | d6f58c2 | 2009-06-07 13:58:25 +0000 | [diff] [blame] | 1003 | int err = 0; |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 1004 | |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 1005 | rtnl_lock(); |
Ron Mercer | efd7d26 | 2009-10-08 09:54:43 +0000 | [diff] [blame] | 1006 | /* Begin polled mode for MPI */ |
| 1007 | ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16)); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 1008 | |
| 1009 | while (ql_read32(qdev, STS) & STS_PI) { |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 1010 | memset(mbcp, 0, sizeof(struct mbox_params)); |
| 1011 | mbcp->out_count = 1; |
Ron Mercer | d6f58c2 | 2009-06-07 13:58:25 +0000 | [diff] [blame] | 1012 | /* Don't continue if an async event |
| 1013 | * did not complete properly. |
| 1014 | */ |
| 1015 | err = ql_mpi_handler(qdev, mbcp); |
| 1016 | if (err) |
| 1017 | break; |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 1018 | } |
Ron Mercer | 125844e | 2009-02-26 10:08:34 +0000 | [diff] [blame] | 1019 | |
Ron Mercer | efd7d26 | 2009-10-08 09:54:43 +0000 | [diff] [blame] | 1020 | /* End polled mode for MPI */ |
| 1021 | ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI); |
Ron Mercer | 86aaf9a | 2009-10-05 11:46:49 +0000 | [diff] [blame] | 1022 | rtnl_unlock(); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 1023 | ql_enable_completion_interrupt(qdev, 0); |
| 1024 | } |
| 1025 | |
| 1026 | void ql_mpi_reset_work(struct work_struct *work) |
| 1027 | { |
| 1028 | struct ql_adapter *qdev = |
| 1029 | container_of(work, struct ql_adapter, mpi_reset_work.work); |
Ron Mercer | bcc2cb3b | 2009-03-02 08:07:32 +0000 | [diff] [blame] | 1030 | cancel_delayed_work_sync(&qdev->mpi_work); |
| 1031 | cancel_delayed_work_sync(&qdev->mpi_port_cfg_work); |
Ron Mercer | 2ee1e27 | 2009-03-03 12:10:33 +0000 | [diff] [blame] | 1032 | cancel_delayed_work_sync(&qdev->mpi_idc_work); |
Ron Mercer | a2e809b | 2009-02-26 10:08:33 +0000 | [diff] [blame] | 1033 | ql_soft_reset_mpi_risc(qdev); |
Ron Mercer | c4e84bd | 2008-09-18 11:56:28 -0400 | [diff] [blame] | 1034 | } |