Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1 | /** |
Jayamohan Kallickal | 533c165 | 2013-04-05 20:38:34 -0700 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2013 Emulex |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License version 2 |
| 7 | * as published by the Free Software Foundation. The full GNU General |
| 8 | * Public License is included in this distribution in the file called COPYING. |
| 9 | * |
| 10 | * Contact Information: |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 12 | * |
Jayamohan Kallickal | 255fa9a | 2011-03-25 14:23:57 -0700 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 16 | */ |
| 17 | |
John Soni Jose | 2177199 | 2012-04-03 23:41:49 -0500 | [diff] [blame] | 18 | #include <scsi/iscsi_proto.h> |
| 19 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 20 | #include "be.h" |
| 21 | #include "be_mgmt.h" |
| 22 | #include "be_main.h" |
| 23 | |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 24 | int beiscsi_pci_soft_reset(struct beiscsi_hba *phba) |
| 25 | { |
| 26 | u32 sreset; |
| 27 | u8 *pci_reset_offset = 0; |
| 28 | u8 *pci_online0_offset = 0; |
| 29 | u8 *pci_online1_offset = 0; |
| 30 | u32 pconline0 = 0; |
| 31 | u32 pconline1 = 0; |
| 32 | u32 i; |
| 33 | |
| 34 | pci_reset_offset = (u8 *)phba->pci_va + BE2_SOFT_RESET; |
| 35 | pci_online0_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE0; |
| 36 | pci_online1_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE1; |
| 37 | sreset = readl((void *)pci_reset_offset); |
| 38 | sreset |= BE2_SET_RESET; |
| 39 | writel(sreset, (void *)pci_reset_offset); |
| 40 | |
| 41 | i = 0; |
| 42 | while (sreset & BE2_SET_RESET) { |
| 43 | if (i > 64) |
| 44 | break; |
| 45 | msleep(100); |
| 46 | sreset = readl((void *)pci_reset_offset); |
| 47 | i++; |
| 48 | } |
| 49 | |
| 50 | if (sreset & BE2_SET_RESET) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 51 | printk(KERN_ERR DRV_NAME |
| 52 | " Soft Reset did not deassert\n"); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 53 | return -EIO; |
| 54 | } |
| 55 | pconline1 = BE2_MPU_IRAM_ONLINE; |
| 56 | writel(pconline0, (void *)pci_online0_offset); |
| 57 | writel(pconline1, (void *)pci_online1_offset); |
| 58 | |
Minh Tran | 1d8bc70 | 2012-10-20 04:41:24 +0530 | [diff] [blame] | 59 | sreset |= BE2_SET_RESET; |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 60 | writel(sreset, (void *)pci_reset_offset); |
| 61 | |
| 62 | i = 0; |
| 63 | while (sreset & BE2_SET_RESET) { |
| 64 | if (i > 64) |
| 65 | break; |
| 66 | msleep(1); |
| 67 | sreset = readl((void *)pci_reset_offset); |
| 68 | i++; |
| 69 | } |
| 70 | if (sreset & BE2_SET_RESET) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 71 | printk(KERN_ERR DRV_NAME |
| 72 | " MPU Online Soft Reset did not deassert\n"); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 73 | return -EIO; |
| 74 | } |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | int be_chk_reset_complete(struct beiscsi_hba *phba) |
| 79 | { |
| 80 | unsigned int num_loop; |
| 81 | u8 *mpu_sem = 0; |
| 82 | u32 status; |
| 83 | |
| 84 | num_loop = 1000; |
| 85 | mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE; |
| 86 | msleep(5000); |
| 87 | |
| 88 | while (num_loop) { |
| 89 | status = readl((void *)mpu_sem); |
| 90 | |
| 91 | if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000) |
| 92 | break; |
| 93 | msleep(60); |
| 94 | num_loop--; |
| 95 | } |
| 96 | |
| 97 | if ((status & 0x80000000) || (!num_loop)) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 98 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 99 | "BC_%d : Failed in be_chk_reset_complete" |
| 100 | "status = 0x%x\n", status); |
Jayamohan Kallickal | e9b9119 | 2010-07-22 04:24:53 +0530 | [diff] [blame] | 101 | return -EIO; |
| 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 107 | void be_mcc_notify(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 108 | { |
| 109 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 110 | u32 val = 0; |
| 111 | |
| 112 | val |= mccq->id & DB_MCCQ_RING_ID_MASK; |
| 113 | val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT; |
| 114 | iowrite32(val, phba->db_va + DB_MCCQ_OFFSET); |
| 115 | } |
| 116 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 117 | unsigned int alloc_mcc_tag(struct beiscsi_hba *phba) |
| 118 | { |
| 119 | unsigned int tag = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 120 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 121 | if (phba->ctrl.mcc_tag_available) { |
| 122 | tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index]; |
| 123 | phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0; |
| 124 | phba->ctrl.mcc_numtag[tag] = 0; |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 125 | } |
| 126 | if (tag) { |
| 127 | phba->ctrl.mcc_tag_available--; |
| 128 | if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1)) |
| 129 | phba->ctrl.mcc_alloc_index = 0; |
| 130 | else |
| 131 | phba->ctrl.mcc_alloc_index++; |
| 132 | } |
| 133 | return tag; |
| 134 | } |
| 135 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 136 | /* |
| 137 | * beiscsi_mccq_compl()- Wait for completion of MBX |
| 138 | * @phba: Driver private structure |
| 139 | * @tag: Tag for the MBX Command |
| 140 | * @wrb: the WRB used for the MBX Command |
| 141 | * @cmd_hdr: IOCTL Hdr for the MBX Cmd |
| 142 | * |
| 143 | * Waits for MBX completion with the passed TAG. |
| 144 | * |
| 145 | * return |
| 146 | * Success: 0 |
| 147 | * Failure: Non-Zero |
| 148 | **/ |
| 149 | int beiscsi_mccq_compl(struct beiscsi_hba *phba, |
| 150 | uint32_t tag, struct be_mcc_wrb **wrb, |
| 151 | void *cmd_hdr) |
| 152 | { |
| 153 | int rc = 0; |
| 154 | uint32_t mcc_tag_response; |
| 155 | uint16_t status = 0, addl_status = 0, wrb_num = 0; |
| 156 | struct be_mcc_wrb *temp_wrb; |
| 157 | struct be_cmd_req_hdr *ioctl_hdr; |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 158 | struct be_cmd_resp_hdr *ioctl_resp_hdr; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 159 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 160 | |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 161 | if (beiscsi_error(phba)) |
| 162 | return -EIO; |
| 163 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 164 | /* wait for the mccq completion */ |
| 165 | rc = wait_event_interruptible_timeout( |
| 166 | phba->ctrl.mcc_wait[tag], |
| 167 | phba->ctrl.mcc_numtag[tag], |
| 168 | msecs_to_jiffies( |
| 169 | BEISCSI_HOST_MBX_TIMEOUT)); |
| 170 | |
| 171 | if (rc <= 0) { |
| 172 | beiscsi_log(phba, KERN_ERR, |
| 173 | BEISCSI_LOG_INIT | BEISCSI_LOG_EH | |
| 174 | BEISCSI_LOG_CONFIG, |
| 175 | "BC_%d : MBX Cmd Completion timed out\n"); |
| 176 | rc = -EAGAIN; |
Jayamohan Kallickal | e074d20 | 2013-09-28 15:35:39 -0700 | [diff] [blame] | 177 | |
| 178 | /* decrement the mccq used count */ |
| 179 | atomic_dec(&phba->ctrl.mcc_obj.q.used); |
| 180 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 181 | goto release_mcc_tag; |
| 182 | } else |
| 183 | rc = 0; |
| 184 | |
| 185 | mcc_tag_response = phba->ctrl.mcc_numtag[tag]; |
| 186 | status = (mcc_tag_response & CQE_STATUS_MASK); |
| 187 | addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >> |
| 188 | CQE_STATUS_ADDL_SHIFT); |
| 189 | |
| 190 | if (cmd_hdr) { |
| 191 | ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr; |
| 192 | } else { |
| 193 | wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >> |
| 194 | CQE_STATUS_WRB_SHIFT; |
| 195 | temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num); |
| 196 | ioctl_hdr = embedded_payload(temp_wrb); |
| 197 | |
| 198 | if (wrb) |
| 199 | *wrb = temp_wrb; |
| 200 | } |
| 201 | |
| 202 | if (status || addl_status) { |
| 203 | beiscsi_log(phba, KERN_ERR, |
| 204 | BEISCSI_LOG_INIT | BEISCSI_LOG_EH | |
| 205 | BEISCSI_LOG_CONFIG, |
| 206 | "BC_%d : MBX Cmd Failed for " |
| 207 | "Subsys : %d Opcode : %d with " |
| 208 | "Status : %d and Extd_Status : %d\n", |
| 209 | ioctl_hdr->subsystem, |
| 210 | ioctl_hdr->opcode, |
| 211 | status, addl_status); |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 212 | |
| 213 | if (status == MCC_STATUS_INSUFFICIENT_BUFFER) { |
| 214 | ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr; |
| 215 | if (ioctl_resp_hdr->response_length) |
| 216 | goto release_mcc_tag; |
| 217 | } |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 218 | rc = -EAGAIN; |
| 219 | } |
| 220 | |
| 221 | release_mcc_tag: |
| 222 | /* Release the MCC entry */ |
| 223 | free_mcc_tag(&phba->ctrl, tag); |
| 224 | |
| 225 | return rc; |
| 226 | } |
| 227 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 228 | void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag) |
| 229 | { |
| 230 | spin_lock(&ctrl->mbox_lock); |
| 231 | tag = tag & 0x000000FF; |
| 232 | ctrl->mcc_tag[ctrl->mcc_free_index] = tag; |
| 233 | if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1)) |
| 234 | ctrl->mcc_free_index = 0; |
| 235 | else |
| 236 | ctrl->mcc_free_index++; |
| 237 | ctrl->mcc_tag_available++; |
| 238 | spin_unlock(&ctrl->mbox_lock); |
| 239 | } |
| 240 | |
| 241 | bool is_link_state_evt(u32 trailer) |
| 242 | { |
| 243 | return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & |
| 244 | ASYNC_TRAILER_EVENT_CODE_MASK) == |
| 245 | ASYNC_EVENT_CODE_LINK_STATE); |
| 246 | } |
| 247 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 248 | static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl) |
| 249 | { |
| 250 | if (compl->flags != 0) { |
| 251 | compl->flags = le32_to_cpu(compl->flags); |
| 252 | WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0); |
| 253 | return true; |
| 254 | } else |
| 255 | return false; |
| 256 | } |
| 257 | |
| 258 | static inline void be_mcc_compl_use(struct be_mcc_compl *compl) |
| 259 | { |
| 260 | compl->flags = 0; |
| 261 | } |
| 262 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 263 | /* |
| 264 | * be_mcc_compl_process()- Check the MBX comapletion status |
| 265 | * @ctrl: Function specific MBX data structure |
| 266 | * @compl: Completion status of MBX Command |
| 267 | * |
| 268 | * Check for the MBX completion status when BMBX method used |
| 269 | * |
| 270 | * return |
| 271 | * Success: Zero |
| 272 | * Failure: Non-Zero |
| 273 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 274 | static int be_mcc_compl_process(struct be_ctrl_info *ctrl, |
| 275 | struct be_mcc_compl *compl) |
| 276 | { |
| 277 | u16 compl_status, extd_status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 278 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 279 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 280 | struct be_cmd_req_hdr *hdr = embedded_payload(wrb); |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 281 | struct be_cmd_resp_hdr *resp_hdr; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 282 | |
| 283 | be_dws_le_to_cpu(compl, 4); |
| 284 | |
| 285 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 286 | CQE_STATUS_COMPL_MASK; |
| 287 | if (compl_status != MCC_STATUS_SUCCESS) { |
| 288 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 289 | CQE_STATUS_EXTD_MASK; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 290 | |
| 291 | beiscsi_log(phba, KERN_ERR, |
| 292 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 293 | "BC_%d : error in cmd completion: " |
| 294 | "Subsystem : %d Opcode : %d " |
| 295 | "status(compl/extd)=%d/%d\n", |
| 296 | hdr->subsystem, hdr->opcode, |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 297 | compl_status, extd_status); |
| 298 | |
Jayamohan Kallickal | a8081e3 | 2013-04-05 20:38:22 -0700 | [diff] [blame] | 299 | if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) { |
| 300 | resp_hdr = (struct be_cmd_resp_hdr *) hdr; |
| 301 | if (resp_hdr->response_length) |
| 302 | return 0; |
| 303 | } |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 304 | return -EBUSY; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 305 | } |
| 306 | return 0; |
| 307 | } |
| 308 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 309 | int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl, |
| 310 | struct be_mcc_compl *compl) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 311 | { |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 312 | u16 compl_status, extd_status; |
| 313 | unsigned short tag; |
| 314 | |
| 315 | be_dws_le_to_cpu(compl, 4); |
| 316 | |
| 317 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 318 | CQE_STATUS_COMPL_MASK; |
| 319 | /* The ctrl.mcc_numtag[tag] is filled with |
| 320 | * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status, |
| 321 | * [7:0] = compl_status |
| 322 | */ |
| 323 | tag = (compl->tag0 & 0x000000FF); |
| 324 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 325 | CQE_STATUS_EXTD_MASK; |
| 326 | |
| 327 | ctrl->mcc_numtag[tag] = 0x80000000; |
| 328 | ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000); |
| 329 | ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8; |
| 330 | ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF); |
| 331 | wake_up_interruptible(&ctrl->mcc_wait[tag]); |
| 332 | return 0; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 333 | } |
| 334 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 335 | static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba) |
| 336 | { |
| 337 | struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq; |
| 338 | struct be_mcc_compl *compl = queue_tail_node(mcc_cq); |
| 339 | |
| 340 | if (be_mcc_compl_is_new(compl)) { |
| 341 | queue_tail_inc(mcc_cq); |
| 342 | return compl; |
| 343 | } |
| 344 | return NULL; |
| 345 | } |
| 346 | |
| 347 | static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session) |
| 348 | { |
| 349 | iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED); |
| 350 | } |
| 351 | |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 352 | void beiscsi_async_link_state_process(struct beiscsi_hba *phba, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 353 | struct be_async_event_link_state *evt) |
| 354 | { |
Jayamohan Kallickal | 6ea9b3b | 2013-04-05 20:38:30 -0700 | [diff] [blame] | 355 | if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) || |
| 356 | ((evt->port_link_status & ASYNC_EVENT_LOGICAL) && |
| 357 | (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) { |
| 358 | phba->state = BE_ADAPTER_LINK_DOWN; |
| 359 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 360 | beiscsi_log(phba, KERN_ERR, |
| 361 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 6ea9b3b | 2013-04-05 20:38:30 -0700 | [diff] [blame] | 362 | "BC_%d : Link Down on Port %d\n", |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 363 | evt->physical_port); |
| 364 | |
Jayamohan Kallickal | da7408c | 2010-01-05 05:11:23 +0530 | [diff] [blame] | 365 | iscsi_host_for_each_session(phba->shost, |
| 366 | be2iscsi_fail_session); |
Jayamohan Kallickal | 6ea9b3b | 2013-04-05 20:38:30 -0700 | [diff] [blame] | 367 | } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) || |
| 368 | ((evt->port_link_status & ASYNC_EVENT_LOGICAL) && |
| 369 | (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 370 | phba->state = BE_ADAPTER_UP; |
Jayamohan Kallickal | 6ea9b3b | 2013-04-05 20:38:30 -0700 | [diff] [blame] | 371 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 372 | beiscsi_log(phba, KERN_ERR, |
| 373 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT, |
Jayamohan Kallickal | 6ea9b3b | 2013-04-05 20:38:30 -0700 | [diff] [blame] | 374 | "BC_%d : Link UP on Port %d\n", |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 375 | evt->physical_port); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm, |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 380 | u16 num_popped) |
| 381 | { |
| 382 | u32 val = 0; |
| 383 | val |= qid & DB_CQ_RING_ID_MASK; |
| 384 | if (arm) |
| 385 | val |= 1 << DB_CQ_REARM_SHIFT; |
| 386 | val |= num_popped << DB_CQ_NUM_POPPED_SHIFT; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 387 | iowrite32(val, phba->db_va + DB_CQ_OFFSET); |
| 388 | } |
| 389 | |
| 390 | |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 391 | int beiscsi_process_mcc(struct beiscsi_hba *phba) |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 392 | { |
| 393 | struct be_mcc_compl *compl; |
| 394 | int num = 0, status = 0; |
| 395 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 396 | |
| 397 | spin_lock_bh(&phba->ctrl.mcc_cq_lock); |
| 398 | while ((compl = be_mcc_compl_get(phba))) { |
| 399 | if (compl->flags & CQE_FLAGS_ASYNC_MASK) { |
| 400 | /* Interpret flags as an async trailer */ |
Jayamohan Kallickal | 78b9fb6 | 2009-11-25 01:41:37 +0530 | [diff] [blame] | 401 | if (is_link_state_evt(compl->flags)) |
| 402 | /* Interpret compl as a async link evt */ |
| 403 | beiscsi_async_link_state_process(phba, |
| 404 | (struct be_async_event_link_state *) compl); |
| 405 | else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 406 | beiscsi_log(phba, KERN_ERR, |
| 407 | BEISCSI_LOG_CONFIG | |
| 408 | BEISCSI_LOG_MBOX, |
| 409 | "BC_%d : Unsupported Async Event, flags" |
| 410 | " = 0x%08x\n", compl->flags); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 411 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 412 | } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
| 413 | status = be_mcc_compl_process(ctrl, compl); |
| 414 | atomic_dec(&phba->ctrl.mcc_obj.q.used); |
| 415 | } |
| 416 | be_mcc_compl_use(compl); |
| 417 | num++; |
| 418 | } |
| 419 | |
| 420 | if (num) |
| 421 | beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num); |
| 422 | |
| 423 | spin_unlock_bh(&phba->ctrl.mcc_cq_lock); |
| 424 | return status; |
| 425 | } |
| 426 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 427 | /* |
| 428 | * be_mcc_wait_compl()- Wait for MBX completion |
| 429 | * @phba: driver private structure |
| 430 | * |
| 431 | * Wait till no more pending mcc requests are present |
| 432 | * |
| 433 | * return |
| 434 | * Success: 0 |
| 435 | * Failure: Non-Zero |
| 436 | * |
| 437 | **/ |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 438 | static int be_mcc_wait_compl(struct beiscsi_hba *phba) |
| 439 | { |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 440 | int i, status; |
| 441 | for (i = 0; i < mcc_timeout; i++) { |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 442 | if (beiscsi_error(phba)) |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 443 | return -EIO; |
| 444 | |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 445 | status = beiscsi_process_mcc(phba); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 446 | if (status) |
| 447 | return status; |
| 448 | |
| 449 | if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0) |
| 450 | break; |
| 451 | udelay(100); |
| 452 | } |
| 453 | if (i == mcc_timeout) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 454 | beiscsi_log(phba, KERN_ERR, |
| 455 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 456 | "BC_%d : FW Timed Out\n"); |
| 457 | phba->fw_timeout = true; |
John Soni Jose | 7a15800 | 2012-10-20 04:45:51 +0530 | [diff] [blame] | 458 | beiscsi_ue_detect(phba); |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 459 | return -EBUSY; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 460 | } |
| 461 | return 0; |
| 462 | } |
| 463 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 464 | /* |
| 465 | * be_mcc_notify_wait()- Notify and wait for Compl |
| 466 | * @phba: driver private structure |
| 467 | * |
| 468 | * Notify MCC requests and wait for completion |
| 469 | * |
| 470 | * return |
| 471 | * Success: 0 |
| 472 | * Failure: Non-Zero |
| 473 | **/ |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 474 | int be_mcc_notify_wait(struct beiscsi_hba *phba) |
| 475 | { |
| 476 | be_mcc_notify(phba); |
| 477 | return be_mcc_wait_compl(phba); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 478 | } |
| 479 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 480 | /* |
| 481 | * be_mbox_db_ready_wait()- Check ready status |
| 482 | * @ctrl: Function specific MBX data structure |
| 483 | * |
| 484 | * Check for the ready status of FW to send BMBX |
| 485 | * commands to adapter. |
| 486 | * |
| 487 | * return |
| 488 | * Success: 0 |
| 489 | * Failure: Non-Zero |
| 490 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 491 | static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl) |
| 492 | { |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 493 | #define BEISCSI_MBX_RDY_BIT_TIMEOUT 4000 /* 4sec */ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 494 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 495 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 496 | unsigned long timeout; |
| 497 | bool read_flag = false; |
| 498 | int ret = 0, i; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 499 | u32 ready; |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 500 | DECLARE_WAIT_QUEUE_HEAD_ONSTACK(rdybit_check_q); |
| 501 | |
| 502 | if (beiscsi_error(phba)) |
| 503 | return -EIO; |
| 504 | |
| 505 | timeout = jiffies + (HZ * 110); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 506 | |
| 507 | do { |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 508 | for (i = 0; i < BEISCSI_MBX_RDY_BIT_TIMEOUT; i++) { |
| 509 | ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK; |
| 510 | if (ready) { |
| 511 | read_flag = true; |
| 512 | break; |
| 513 | } |
| 514 | mdelay(1); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 515 | } |
| 516 | |
Jayamohan Kallickal | 92665a6 | 2013-09-28 15:35:43 -0700 | [diff] [blame] | 517 | if (!read_flag) { |
| 518 | wait_event_timeout(rdybit_check_q, |
| 519 | (read_flag != true), |
| 520 | HZ * 5); |
| 521 | } |
| 522 | } while ((time_before(jiffies, timeout)) && !read_flag); |
| 523 | |
| 524 | if (!read_flag) { |
| 525 | beiscsi_log(phba, KERN_ERR, |
| 526 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 527 | "BC_%d : FW Timed Out\n"); |
| 528 | phba->fw_timeout = true; |
| 529 | beiscsi_ue_detect(phba); |
| 530 | ret = -EBUSY; |
| 531 | } |
| 532 | |
| 533 | return ret; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 534 | } |
| 535 | |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 536 | /* |
| 537 | * be_mbox_notify: Notify adapter of new BMBX command |
| 538 | * @ctrl: Function specific MBX data structure |
| 539 | * |
| 540 | * Ring doorbell to inform adapter of a BMBX command |
| 541 | * to process |
| 542 | * |
| 543 | * return |
| 544 | * Success: 0 |
| 545 | * Failure: Non-Zero |
| 546 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 547 | int be_mbox_notify(struct be_ctrl_info *ctrl) |
| 548 | { |
| 549 | int status; |
| 550 | u32 val = 0; |
| 551 | void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET; |
| 552 | struct be_dma_mem *mbox_mem = &ctrl->mbox_mem; |
| 553 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
| 554 | struct be_mcc_compl *compl = &mbox->compl; |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 555 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 556 | |
Jayamohan Kallickal | 1e234bb | 2013-04-05 20:38:23 -0700 | [diff] [blame] | 557 | status = be_mbox_db_ready_wait(ctrl); |
| 558 | if (status) |
| 559 | return status; |
| 560 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 561 | val &= ~MPU_MAILBOX_DB_RDY_MASK; |
| 562 | val |= MPU_MAILBOX_DB_HI_MASK; |
| 563 | val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2; |
| 564 | iowrite32(val, db); |
| 565 | |
| 566 | status = be_mbox_db_ready_wait(ctrl); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 567 | if (status) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 568 | return status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 569 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 570 | val = 0; |
| 571 | val &= ~MPU_MAILBOX_DB_RDY_MASK; |
| 572 | val &= ~MPU_MAILBOX_DB_HI_MASK; |
| 573 | val |= (u32) (mbox_mem->dma >> 4) << 2; |
| 574 | iowrite32(val, db); |
| 575 | |
| 576 | status = be_mbox_db_ready_wait(ctrl); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 577 | if (status) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 578 | return status; |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 579 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 580 | if (be_mcc_compl_is_new(compl)) { |
| 581 | status = be_mcc_compl_process(ctrl, &mbox->compl); |
| 582 | be_mcc_compl_use(compl); |
| 583 | if (status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 584 | beiscsi_log(phba, KERN_ERR, |
| 585 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 586 | "BC_%d : After be_mcc_compl_process\n"); |
| 587 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 588 | return status; |
| 589 | } |
| 590 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 591 | beiscsi_log(phba, KERN_ERR, |
| 592 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 593 | "BC_%d : Invalid Mailbox Completion\n"); |
| 594 | |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 595 | return -EBUSY; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 596 | } |
| 597 | return 0; |
| 598 | } |
| 599 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 600 | /* |
| 601 | * Insert the mailbox address into the doorbell in two steps |
| 602 | * Polls on the mbox doorbell till a command completion (or a timeout) occurs |
| 603 | */ |
| 604 | static int be_mbox_notify_wait(struct beiscsi_hba *phba) |
| 605 | { |
| 606 | int status; |
| 607 | u32 val = 0; |
| 608 | void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET; |
| 609 | struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem; |
| 610 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
| 611 | struct be_mcc_compl *compl = &mbox->compl; |
| 612 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 613 | |
Jayamohan Kallickal | 1e234bb | 2013-04-05 20:38:23 -0700 | [diff] [blame] | 614 | status = be_mbox_db_ready_wait(ctrl); |
| 615 | if (status) |
| 616 | return status; |
| 617 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 618 | val |= MPU_MAILBOX_DB_HI_MASK; |
| 619 | /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */ |
| 620 | val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2; |
| 621 | iowrite32(val, db); |
| 622 | |
| 623 | /* wait for ready to be set */ |
| 624 | status = be_mbox_db_ready_wait(ctrl); |
| 625 | if (status != 0) |
| 626 | return status; |
| 627 | |
| 628 | val = 0; |
| 629 | /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */ |
| 630 | val |= (u32)(mbox_mem->dma >> 4) << 2; |
| 631 | iowrite32(val, db); |
| 632 | |
| 633 | status = be_mbox_db_ready_wait(ctrl); |
| 634 | if (status != 0) |
| 635 | return status; |
| 636 | |
| 637 | /* A cq entry has been made now */ |
| 638 | if (be_mcc_compl_is_new(compl)) { |
| 639 | status = be_mcc_compl_process(ctrl, &mbox->compl); |
| 640 | be_mcc_compl_use(compl); |
| 641 | if (status) |
| 642 | return status; |
| 643 | } else { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 644 | beiscsi_log(phba, KERN_ERR, |
| 645 | BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX, |
| 646 | "BC_%d : invalid mailbox completion\n"); |
| 647 | |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 648 | return -EBUSY; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 649 | } |
| 650 | return 0; |
| 651 | } |
| 652 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 653 | void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len, |
| 654 | bool embedded, u8 sge_cnt) |
| 655 | { |
| 656 | if (embedded) |
| 657 | wrb->embedded |= MCC_WRB_EMBEDDED_MASK; |
| 658 | else |
| 659 | wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) << |
| 660 | MCC_WRB_SGE_CNT_SHIFT; |
| 661 | wrb->payload_length = payload_len; |
| 662 | be_dws_cpu_to_le(wrb, 8); |
| 663 | } |
| 664 | |
| 665 | void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr, |
| 666 | u8 subsystem, u8 opcode, int cmd_len) |
| 667 | { |
| 668 | req_hdr->opcode = opcode; |
| 669 | req_hdr->subsystem = subsystem; |
| 670 | req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr)); |
John Soni Jose | e175def | 2012-10-20 04:45:40 +0530 | [diff] [blame] | 671 | req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages, |
| 675 | struct be_dma_mem *mem) |
| 676 | { |
| 677 | int i, buf_pages; |
| 678 | u64 dma = (u64) mem->dma; |
| 679 | |
| 680 | buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages); |
| 681 | for (i = 0; i < buf_pages; i++) { |
| 682 | pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF); |
| 683 | pages[i].hi = cpu_to_le32(upper_32_bits(dma)); |
| 684 | dma += PAGE_SIZE_4K; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | static u32 eq_delay_to_mult(u32 usec_delay) |
| 689 | { |
| 690 | #define MAX_INTR_RATE 651042 |
| 691 | const u32 round = 10; |
| 692 | u32 multiplier; |
| 693 | |
| 694 | if (usec_delay == 0) |
| 695 | multiplier = 0; |
| 696 | else { |
| 697 | u32 interrupt_rate = 1000000 / usec_delay; |
| 698 | if (interrupt_rate == 0) |
| 699 | multiplier = 1023; |
| 700 | else { |
| 701 | multiplier = (MAX_INTR_RATE - interrupt_rate) * round; |
| 702 | multiplier /= interrupt_rate; |
| 703 | multiplier = (multiplier + round / 2) / round; |
| 704 | multiplier = min(multiplier, (u32) 1023); |
| 705 | } |
| 706 | } |
| 707 | return multiplier; |
| 708 | } |
| 709 | |
| 710 | struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem) |
| 711 | { |
| 712 | return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb; |
| 713 | } |
| 714 | |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 715 | struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba) |
| 716 | { |
| 717 | struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q; |
| 718 | struct be_mcc_wrb *wrb; |
| 719 | |
Jayamohan Kallickal | e074d20 | 2013-09-28 15:35:39 -0700 | [diff] [blame] | 720 | WARN_ON(atomic_read(&mccq->used) >= mccq->len); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 721 | wrb = queue_head_node(mccq); |
Jayamohan Kallickal | 756d29c | 2010-01-05 05:10:46 +0530 | [diff] [blame] | 722 | memset(wrb, 0, sizeof(*wrb)); |
| 723 | wrb->tag0 = (mccq->head & 0x000000FF) << 16; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 724 | queue_head_inc(mccq); |
| 725 | atomic_inc(&mccq->used); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 726 | return wrb; |
| 727 | } |
| 728 | |
| 729 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 730 | int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl, |
| 731 | struct be_queue_info *eq, int eq_delay) |
| 732 | { |
| 733 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 734 | struct be_cmd_req_eq_create *req = embedded_payload(wrb); |
| 735 | struct be_cmd_resp_eq_create *resp = embedded_payload(wrb); |
| 736 | struct be_dma_mem *q_mem = &eq->dma_mem; |
| 737 | int status; |
| 738 | |
| 739 | spin_lock(&ctrl->mbox_lock); |
| 740 | memset(wrb, 0, sizeof(*wrb)); |
| 741 | |
| 742 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 743 | |
| 744 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 745 | OPCODE_COMMON_EQ_CREATE, sizeof(*req)); |
| 746 | |
| 747 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 748 | |
| 749 | AMAP_SET_BITS(struct amap_eq_context, func, req->context, |
| 750 | PCI_FUNC(ctrl->pdev->devfn)); |
| 751 | AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1); |
| 752 | AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0); |
| 753 | AMAP_SET_BITS(struct amap_eq_context, count, req->context, |
| 754 | __ilog2_u32(eq->len / 256)); |
| 755 | AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context, |
| 756 | eq_delay_to_mult(eq_delay)); |
| 757 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 758 | |
| 759 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 760 | |
| 761 | status = be_mbox_notify(ctrl); |
| 762 | if (!status) { |
| 763 | eq->id = le16_to_cpu(resp->eq_id); |
| 764 | eq->created = true; |
| 765 | } |
| 766 | spin_unlock(&ctrl->mbox_lock); |
| 767 | return status; |
| 768 | } |
| 769 | |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 770 | /** |
| 771 | * be_cmd_fw_initialize()- Initialize FW |
| 772 | * @ctrl: Pointer to function control structure |
| 773 | * |
| 774 | * Send FW initialize pattern for the function. |
| 775 | * |
| 776 | * return |
| 777 | * Success: 0 |
| 778 | * Failure: Non-Zero value |
| 779 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 780 | int be_cmd_fw_initialize(struct be_ctrl_info *ctrl) |
| 781 | { |
| 782 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 783 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 784 | int status; |
| 785 | u8 *endian_check; |
| 786 | |
| 787 | spin_lock(&ctrl->mbox_lock); |
| 788 | memset(wrb, 0, sizeof(*wrb)); |
| 789 | |
| 790 | endian_check = (u8 *) wrb; |
| 791 | *endian_check++ = 0xFF; |
| 792 | *endian_check++ = 0x12; |
| 793 | *endian_check++ = 0x34; |
| 794 | *endian_check++ = 0xFF; |
| 795 | *endian_check++ = 0xFF; |
| 796 | *endian_check++ = 0x56; |
| 797 | *endian_check++ = 0x78; |
| 798 | *endian_check++ = 0xFF; |
| 799 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 800 | |
| 801 | status = be_mbox_notify(ctrl); |
| 802 | if (status) |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 803 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 804 | "BC_%d : be_cmd_fw_initialize Failed\n"); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 805 | |
| 806 | spin_unlock(&ctrl->mbox_lock); |
| 807 | return status; |
| 808 | } |
| 809 | |
Jayamohan Kallickal | 0283fbb | 2013-04-05 20:38:21 -0700 | [diff] [blame] | 810 | /** |
| 811 | * be_cmd_fw_uninit()- Uinitialize FW |
| 812 | * @ctrl: Pointer to function control structure |
| 813 | * |
| 814 | * Send FW uninitialize pattern for the function |
| 815 | * |
| 816 | * return |
| 817 | * Success: 0 |
| 818 | * Failure: Non-Zero value |
| 819 | **/ |
| 820 | int be_cmd_fw_uninit(struct be_ctrl_info *ctrl) |
| 821 | { |
| 822 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 823 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
| 824 | int status; |
| 825 | u8 *endian_check; |
| 826 | |
| 827 | spin_lock(&ctrl->mbox_lock); |
| 828 | memset(wrb, 0, sizeof(*wrb)); |
| 829 | |
| 830 | endian_check = (u8 *) wrb; |
| 831 | *endian_check++ = 0xFF; |
| 832 | *endian_check++ = 0xAA; |
| 833 | *endian_check++ = 0xBB; |
| 834 | *endian_check++ = 0xFF; |
| 835 | *endian_check++ = 0xFF; |
| 836 | *endian_check++ = 0xCC; |
| 837 | *endian_check++ = 0xDD; |
| 838 | *endian_check = 0xFF; |
| 839 | |
| 840 | be_dws_cpu_to_le(wrb, sizeof(*wrb)); |
| 841 | |
| 842 | status = be_mbox_notify(ctrl); |
| 843 | if (status) |
| 844 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 845 | "BC_%d : be_cmd_fw_uninit Failed\n"); |
| 846 | |
| 847 | spin_unlock(&ctrl->mbox_lock); |
| 848 | return status; |
| 849 | } |
| 850 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 851 | int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl, |
| 852 | struct be_queue_info *cq, struct be_queue_info *eq, |
| 853 | bool sol_evts, bool no_delay, int coalesce_wm) |
| 854 | { |
| 855 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 856 | struct be_cmd_req_cq_create *req = embedded_payload(wrb); |
| 857 | struct be_cmd_resp_cq_create *resp = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 858 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 859 | struct be_dma_mem *q_mem = &cq->dma_mem; |
| 860 | void *ctxt = &req->context; |
| 861 | int status; |
| 862 | |
| 863 | spin_lock(&ctrl->mbox_lock); |
| 864 | memset(wrb, 0, sizeof(*wrb)); |
| 865 | |
| 866 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 867 | |
| 868 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 869 | OPCODE_COMMON_CQ_CREATE, sizeof(*req)); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 870 | |
| 871 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 872 | if (is_chip_be2_be3r(phba)) { |
John Soni Jose | eaae526 | 2012-10-20 04:43:44 +0530 | [diff] [blame] | 873 | AMAP_SET_BITS(struct amap_cq_context, coalescwm, |
| 874 | ctxt, coalesce_wm); |
| 875 | AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay); |
| 876 | AMAP_SET_BITS(struct amap_cq_context, count, ctxt, |
| 877 | __ilog2_u32(cq->len / 256)); |
| 878 | AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1); |
| 879 | AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts); |
| 880 | AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1); |
| 881 | AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id); |
| 882 | AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1); |
| 883 | AMAP_SET_BITS(struct amap_cq_context, func, ctxt, |
| 884 | PCI_FUNC(ctrl->pdev->devfn)); |
Jayamohan Kallickal | 2c9dfd3 | 2013-04-05 20:38:26 -0700 | [diff] [blame] | 885 | } else { |
| 886 | req->hdr.version = MBX_CMD_VER2; |
| 887 | req->page_size = 1; |
| 888 | AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm, |
| 889 | ctxt, coalesce_wm); |
| 890 | AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, |
| 891 | ctxt, no_delay); |
| 892 | AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt, |
| 893 | __ilog2_u32(cq->len / 256)); |
| 894 | AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1); |
| 895 | AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1); |
| 896 | AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id); |
| 897 | AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1); |
John Soni Jose | eaae526 | 2012-10-20 04:43:44 +0530 | [diff] [blame] | 898 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 899 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 900 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 901 | |
| 902 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 903 | |
| 904 | status = be_mbox_notify(ctrl); |
| 905 | if (!status) { |
| 906 | cq->id = le16_to_cpu(resp->cq_id); |
| 907 | cq->created = true; |
| 908 | } else |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 909 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 910 | "BC_%d : In be_cmd_cq_create, status=ox%08x\n", |
| 911 | status); |
| 912 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 913 | spin_unlock(&ctrl->mbox_lock); |
| 914 | |
| 915 | return status; |
| 916 | } |
| 917 | |
| 918 | static u32 be_encoded_q_len(int q_len) |
| 919 | { |
| 920 | u32 len_encoded = fls(q_len); /* log2(len) + 1 */ |
| 921 | if (len_encoded == 16) |
| 922 | len_encoded = 0; |
| 923 | return len_encoded; |
| 924 | } |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 925 | |
Jayamohan Kallickal | 35e6601 | 2009-10-23 11:53:49 +0530 | [diff] [blame] | 926 | int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba, |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 927 | struct be_queue_info *mccq, |
| 928 | struct be_queue_info *cq) |
| 929 | { |
| 930 | struct be_mcc_wrb *wrb; |
| 931 | struct be_cmd_req_mcc_create *req; |
| 932 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
| 933 | struct be_ctrl_info *ctrl; |
| 934 | void *ctxt; |
| 935 | int status; |
| 936 | |
| 937 | spin_lock(&phba->ctrl.mbox_lock); |
| 938 | ctrl = &phba->ctrl; |
| 939 | wrb = wrb_from_mbox(&ctrl->mbox_mem); |
Jayamohan Kallickal | 3760976 | 2011-10-07 19:31:11 -0500 | [diff] [blame] | 940 | memset(wrb, 0, sizeof(*wrb)); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 941 | req = embedded_payload(wrb); |
| 942 | ctxt = &req->context; |
| 943 | |
| 944 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 945 | |
| 946 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 947 | OPCODE_COMMON_MCC_CREATE, sizeof(*req)); |
| 948 | |
| 949 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 950 | |
| 951 | AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt, |
| 952 | PCI_FUNC(phba->pcidev->devfn)); |
| 953 | AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1); |
| 954 | AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt, |
| 955 | be_encoded_q_len(mccq->len)); |
| 956 | AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id); |
| 957 | |
| 958 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 959 | |
| 960 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 961 | |
| 962 | status = be_mbox_notify_wait(phba); |
| 963 | if (!status) { |
| 964 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
| 965 | mccq->id = le16_to_cpu(resp->id); |
| 966 | mccq->created = true; |
| 967 | } |
| 968 | spin_unlock(&phba->ctrl.mbox_lock); |
| 969 | |
| 970 | return status; |
| 971 | } |
| 972 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 973 | int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q, |
| 974 | int queue_type) |
| 975 | { |
| 976 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 977 | struct be_cmd_req_q_destroy *req = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 978 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 979 | u8 subsys = 0, opcode = 0; |
| 980 | int status; |
| 981 | |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 982 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT, |
| 983 | "BC_%d : In beiscsi_cmd_q_destroy " |
| 984 | "queue_type : %d\n", queue_type); |
| 985 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 986 | spin_lock(&ctrl->mbox_lock); |
| 987 | memset(wrb, 0, sizeof(*wrb)); |
| 988 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 989 | |
| 990 | switch (queue_type) { |
| 991 | case QTYPE_EQ: |
| 992 | subsys = CMD_SUBSYSTEM_COMMON; |
| 993 | opcode = OPCODE_COMMON_EQ_DESTROY; |
| 994 | break; |
| 995 | case QTYPE_CQ: |
| 996 | subsys = CMD_SUBSYSTEM_COMMON; |
| 997 | opcode = OPCODE_COMMON_CQ_DESTROY; |
| 998 | break; |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 999 | case QTYPE_MCCQ: |
| 1000 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1001 | opcode = OPCODE_COMMON_MCC_DESTROY; |
| 1002 | break; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1003 | case QTYPE_WRBQ: |
| 1004 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1005 | opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY; |
| 1006 | break; |
| 1007 | case QTYPE_DPDUQ: |
| 1008 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1009 | opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY; |
| 1010 | break; |
| 1011 | case QTYPE_SGL: |
| 1012 | subsys = CMD_SUBSYSTEM_ISCSI; |
| 1013 | opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES; |
| 1014 | break; |
| 1015 | default: |
| 1016 | spin_unlock(&ctrl->mbox_lock); |
| 1017 | BUG(); |
Jayamohan Kallickal | d3ad2bb | 2010-07-22 04:16:38 +0530 | [diff] [blame] | 1018 | return -ENXIO; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1019 | } |
| 1020 | be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req)); |
| 1021 | if (queue_type != QTYPE_SGL) |
| 1022 | req->id = cpu_to_le16(q->id); |
| 1023 | |
| 1024 | status = be_mbox_notify(ctrl); |
| 1025 | |
| 1026 | spin_unlock(&ctrl->mbox_lock); |
| 1027 | return status; |
| 1028 | } |
| 1029 | |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame^] | 1030 | /** |
| 1031 | * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter |
| 1032 | * @ctrl: ptr to ctrl_info |
| 1033 | * @cq: Completion Queue |
| 1034 | * @dq: Default Queue |
| 1035 | * @lenght: ring size |
| 1036 | * @entry_size: size of each entry in DEFQ |
| 1037 | * @is_header: Header or Data DEFQ |
| 1038 | * @ulp_num: Bind to which ULP |
| 1039 | * |
| 1040 | * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted |
| 1041 | * on this queue by the FW |
| 1042 | * |
| 1043 | * return |
| 1044 | * Success: 0 |
| 1045 | * Failure: Non-Zero Value |
| 1046 | * |
| 1047 | **/ |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1048 | int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl, |
| 1049 | struct be_queue_info *cq, |
| 1050 | struct be_queue_info *dq, int length, |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame^] | 1051 | int entry_size, uint8_t is_header, |
| 1052 | uint8_t ulp_num) |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1053 | { |
| 1054 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1055 | struct be_defq_create_req *req = embedded_payload(wrb); |
| 1056 | struct be_dma_mem *q_mem = &dq->dma_mem; |
Jayamohan Kallickal | ef9e1b9 | 2013-04-05 20:38:27 -0700 | [diff] [blame] | 1057 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1058 | void *ctxt = &req->context; |
| 1059 | int status; |
| 1060 | |
| 1061 | spin_lock(&ctrl->mbox_lock); |
| 1062 | memset(wrb, 0, sizeof(*wrb)); |
| 1063 | |
| 1064 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1065 | |
| 1066 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1067 | OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req)); |
| 1068 | |
| 1069 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame^] | 1070 | if (phba->fw_config.dual_ulp_aware) { |
| 1071 | req->ulp_num = ulp_num; |
| 1072 | req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT); |
| 1073 | req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT); |
| 1074 | } |
Jayamohan Kallickal | ef9e1b9 | 2013-04-05 20:38:27 -0700 | [diff] [blame] | 1075 | |
| 1076 | if (is_chip_be2_be3r(phba)) { |
| 1077 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1078 | rx_pdid, ctxt, 0); |
| 1079 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1080 | rx_pdid_valid, ctxt, 1); |
| 1081 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1082 | pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn)); |
| 1083 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1084 | ring_size, ctxt, |
| 1085 | be_encoded_q_len(length / |
| 1086 | sizeof(struct phys_addr))); |
| 1087 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1088 | default_buffer_size, ctxt, entry_size); |
| 1089 | AMAP_SET_BITS(struct amap_be_default_pdu_context, |
| 1090 | cq_id_recv, ctxt, cq->id); |
| 1091 | } else { |
| 1092 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1093 | rx_pdid, ctxt, 0); |
| 1094 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1095 | rx_pdid_valid, ctxt, 1); |
| 1096 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1097 | ring_size, ctxt, |
| 1098 | be_encoded_q_len(length / |
| 1099 | sizeof(struct phys_addr))); |
| 1100 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1101 | default_buffer_size, ctxt, entry_size); |
| 1102 | AMAP_SET_BITS(struct amap_default_pdu_context_ext, |
| 1103 | cq_id_recv, ctxt, cq->id); |
| 1104 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1105 | |
| 1106 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 1107 | |
| 1108 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1109 | |
| 1110 | status = be_mbox_notify(ctrl); |
| 1111 | if (!status) { |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame^] | 1112 | struct be_ring *defq_ring; |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1113 | struct be_defq_create_resp *resp = embedded_payload(wrb); |
| 1114 | |
| 1115 | dq->id = le16_to_cpu(resp->id); |
| 1116 | dq->created = true; |
Jayamohan Kallickal | 8a86e83 | 2013-09-28 15:35:45 -0700 | [diff] [blame^] | 1117 | if (is_header) |
| 1118 | defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num]; |
| 1119 | else |
| 1120 | defq_ring = &phba->phwi_ctrlr-> |
| 1121 | default_pdu_data[ulp_num]; |
| 1122 | |
| 1123 | defq_ring->id = dq->id; |
| 1124 | |
| 1125 | if (!phba->fw_config.dual_ulp_aware) { |
| 1126 | defq_ring->ulp_num = BEISCSI_ULP0; |
| 1127 | defq_ring->doorbell_offset = DB_RXULP0_OFFSET; |
| 1128 | } else { |
| 1129 | defq_ring->ulp_num = resp->ulp_num; |
| 1130 | defq_ring->doorbell_offset = resp->doorbell_offset; |
| 1131 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1132 | } |
| 1133 | spin_unlock(&ctrl->mbox_lock); |
| 1134 | |
| 1135 | return status; |
| 1136 | } |
| 1137 | |
| 1138 | int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem, |
| 1139 | struct be_queue_info *wrbq) |
| 1140 | { |
| 1141 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1142 | struct be_wrbq_create_req *req = embedded_payload(wrb); |
| 1143 | struct be_wrbq_create_resp *resp = embedded_payload(wrb); |
| 1144 | int status; |
| 1145 | |
| 1146 | spin_lock(&ctrl->mbox_lock); |
| 1147 | memset(wrb, 0, sizeof(*wrb)); |
| 1148 | |
| 1149 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1150 | |
| 1151 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1152 | OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req)); |
| 1153 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 1154 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1155 | |
| 1156 | status = be_mbox_notify(ctrl); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1157 | if (!status) { |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1158 | wrbq->id = le16_to_cpu(resp->cid); |
Jayamohan Kallickal | bfead3b | 2009-10-23 11:52:33 +0530 | [diff] [blame] | 1159 | wrbq->created = true; |
| 1160 | } |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1161 | spin_unlock(&ctrl->mbox_lock); |
| 1162 | return status; |
| 1163 | } |
| 1164 | |
Jayamohan Kallickal | 15a90fe | 2013-09-28 15:35:38 -0700 | [diff] [blame] | 1165 | int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl, |
| 1166 | struct be_dma_mem *q_mem) |
| 1167 | { |
| 1168 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1169 | struct be_post_template_pages_req *req = embedded_payload(wrb); |
| 1170 | int status; |
| 1171 | |
| 1172 | spin_lock(&ctrl->mbox_lock); |
| 1173 | |
| 1174 | memset(wrb, 0, sizeof(*wrb)); |
| 1175 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1176 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1177 | OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS, |
| 1178 | sizeof(*req)); |
| 1179 | |
| 1180 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 1181 | req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI; |
| 1182 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1183 | |
| 1184 | status = be_mbox_notify(ctrl); |
| 1185 | spin_unlock(&ctrl->mbox_lock); |
| 1186 | return status; |
| 1187 | } |
| 1188 | |
| 1189 | int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl) |
| 1190 | { |
| 1191 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1192 | struct be_remove_template_pages_req *req = embedded_payload(wrb); |
| 1193 | int status; |
| 1194 | |
| 1195 | spin_lock(&ctrl->mbox_lock); |
| 1196 | |
| 1197 | memset(wrb, 0, sizeof(*wrb)); |
| 1198 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1199 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1200 | OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS, |
| 1201 | sizeof(*req)); |
| 1202 | |
| 1203 | req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI; |
| 1204 | |
| 1205 | status = be_mbox_notify(ctrl); |
| 1206 | spin_unlock(&ctrl->mbox_lock); |
| 1207 | return status; |
| 1208 | } |
| 1209 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1210 | int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl, |
| 1211 | struct be_dma_mem *q_mem, |
| 1212 | u32 page_offset, u32 num_pages) |
| 1213 | { |
| 1214 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1215 | struct be_post_sgl_pages_req *req = embedded_payload(wrb); |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1216 | struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev); |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1217 | int status; |
| 1218 | unsigned int curr_pages; |
| 1219 | u32 internal_page_offset = 0; |
| 1220 | u32 temp_num_pages = num_pages; |
| 1221 | |
| 1222 | if (num_pages == 0xff) |
| 1223 | num_pages = 1; |
| 1224 | |
| 1225 | spin_lock(&ctrl->mbox_lock); |
| 1226 | do { |
| 1227 | memset(wrb, 0, sizeof(*wrb)); |
| 1228 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1229 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1230 | OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES, |
| 1231 | sizeof(*req)); |
| 1232 | curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req, |
| 1233 | pages); |
| 1234 | req->num_pages = min(num_pages, curr_pages); |
| 1235 | req->page_offset = page_offset; |
| 1236 | be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem); |
| 1237 | q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE); |
| 1238 | internal_page_offset += req->num_pages; |
| 1239 | page_offset += req->num_pages; |
| 1240 | num_pages -= req->num_pages; |
| 1241 | |
| 1242 | if (temp_num_pages == 0xff) |
| 1243 | req->num_pages = temp_num_pages; |
| 1244 | |
| 1245 | status = be_mbox_notify(ctrl); |
| 1246 | if (status) { |
John Soni Jose | 99bc5d5 | 2012-08-20 23:00:18 +0530 | [diff] [blame] | 1247 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, |
| 1248 | "BC_%d : FW CMD to map iscsi frags failed.\n"); |
| 1249 | |
Jayamohan Kallickal | 6733b39 | 2009-09-05 07:36:35 +0530 | [diff] [blame] | 1250 | goto error; |
| 1251 | } |
| 1252 | } while (num_pages > 0); |
| 1253 | error: |
| 1254 | spin_unlock(&ctrl->mbox_lock); |
| 1255 | if (status != 0) |
| 1256 | beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL); |
| 1257 | return status; |
| 1258 | } |
Jayamohan Kallickal | e528586 | 2011-10-07 19:31:08 -0500 | [diff] [blame] | 1259 | |
| 1260 | int beiscsi_cmd_reset_function(struct beiscsi_hba *phba) |
| 1261 | { |
| 1262 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 1263 | struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem); |
| 1264 | struct be_post_sgl_pages_req *req = embedded_payload(wrb); |
| 1265 | int status; |
| 1266 | |
| 1267 | spin_lock(&ctrl->mbox_lock); |
| 1268 | |
| 1269 | req = embedded_payload(wrb); |
| 1270 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0); |
| 1271 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1272 | OPCODE_COMMON_FUNCTION_RESET, sizeof(*req)); |
| 1273 | status = be_mbox_notify_wait(phba); |
| 1274 | |
| 1275 | spin_unlock(&ctrl->mbox_lock); |
| 1276 | return status; |
| 1277 | } |
John Soni Jose | 6f72238 | 2012-08-20 23:00:43 +0530 | [diff] [blame] | 1278 | |
| 1279 | /** |
| 1280 | * be_cmd_set_vlan()- Configure VLAN paramters on the adapter |
| 1281 | * @phba: device priv structure instance |
| 1282 | * @vlan_tag: TAG to be set |
| 1283 | * |
| 1284 | * Set the VLAN_TAG for the adapter or Disable VLAN on adapter |
| 1285 | * |
| 1286 | * returns |
| 1287 | * TAG for the MBX Cmd |
| 1288 | * **/ |
| 1289 | int be_cmd_set_vlan(struct beiscsi_hba *phba, |
| 1290 | uint16_t vlan_tag) |
| 1291 | { |
| 1292 | unsigned int tag = 0; |
| 1293 | struct be_mcc_wrb *wrb; |
| 1294 | struct be_cmd_set_vlan_req *req; |
| 1295 | struct be_ctrl_info *ctrl = &phba->ctrl; |
| 1296 | |
| 1297 | spin_lock(&ctrl->mbox_lock); |
| 1298 | tag = alloc_mcc_tag(phba); |
| 1299 | if (!tag) { |
| 1300 | spin_unlock(&ctrl->mbox_lock); |
| 1301 | return tag; |
| 1302 | } |
| 1303 | |
| 1304 | wrb = wrb_from_mccq(phba); |
| 1305 | req = embedded_payload(wrb); |
| 1306 | wrb->tag0 |= tag; |
| 1307 | be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0); |
| 1308 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI, |
| 1309 | OPCODE_COMMON_ISCSI_NTWK_SET_VLAN, |
| 1310 | sizeof(*req)); |
| 1311 | |
| 1312 | req->interface_hndl = phba->interface_handle; |
| 1313 | req->vlan_priority = vlan_tag; |
| 1314 | |
| 1315 | be_mcc_notify(phba); |
| 1316 | spin_unlock(&ctrl->mbox_lock); |
| 1317 | |
| 1318 | return tag; |
| 1319 | } |