be_cmds.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  1. /**
  2. * Copyright (C) 2005 - 2012 Emulex
  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:
  11. * linux-drivers@emulex.com
  12. *
  13. * Emulex
  14. * 3333 Susan Street
  15. * Costa Mesa, CA 92626
  16. */
  17. #include <scsi/iscsi_proto.h>
  18. #include "be.h"
  19. #include "be_mgmt.h"
  20. #include "be_main.h"
  21. int beiscsi_pci_soft_reset(struct beiscsi_hba *phba)
  22. {
  23. u32 sreset;
  24. u8 *pci_reset_offset = 0;
  25. u8 *pci_online0_offset = 0;
  26. u8 *pci_online1_offset = 0;
  27. u32 pconline0 = 0;
  28. u32 pconline1 = 0;
  29. u32 i;
  30. pci_reset_offset = (u8 *)phba->pci_va + BE2_SOFT_RESET;
  31. pci_online0_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE0;
  32. pci_online1_offset = (u8 *)phba->pci_va + BE2_PCI_ONLINE1;
  33. sreset = readl((void *)pci_reset_offset);
  34. sreset |= BE2_SET_RESET;
  35. writel(sreset, (void *)pci_reset_offset);
  36. i = 0;
  37. while (sreset & BE2_SET_RESET) {
  38. if (i > 64)
  39. break;
  40. msleep(100);
  41. sreset = readl((void *)pci_reset_offset);
  42. i++;
  43. }
  44. if (sreset & BE2_SET_RESET) {
  45. printk(KERN_ERR DRV_NAME
  46. " Soft Reset did not deassert\n");
  47. return -EIO;
  48. }
  49. pconline1 = BE2_MPU_IRAM_ONLINE;
  50. writel(pconline0, (void *)pci_online0_offset);
  51. writel(pconline1, (void *)pci_online1_offset);
  52. sreset |= BE2_SET_RESET;
  53. writel(sreset, (void *)pci_reset_offset);
  54. i = 0;
  55. while (sreset & BE2_SET_RESET) {
  56. if (i > 64)
  57. break;
  58. msleep(1);
  59. sreset = readl((void *)pci_reset_offset);
  60. i++;
  61. }
  62. if (sreset & BE2_SET_RESET) {
  63. printk(KERN_ERR DRV_NAME
  64. " MPU Online Soft Reset did not deassert\n");
  65. return -EIO;
  66. }
  67. return 0;
  68. }
  69. int be_chk_reset_complete(struct beiscsi_hba *phba)
  70. {
  71. unsigned int num_loop;
  72. u8 *mpu_sem = 0;
  73. u32 status;
  74. num_loop = 1000;
  75. mpu_sem = (u8 *)phba->csr_va + MPU_EP_SEMAPHORE;
  76. msleep(5000);
  77. while (num_loop) {
  78. status = readl((void *)mpu_sem);
  79. if ((status & 0x80000000) || (status & 0x0000FFFF) == 0xC000)
  80. break;
  81. msleep(60);
  82. num_loop--;
  83. }
  84. if ((status & 0x80000000) || (!num_loop)) {
  85. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  86. "BC_%d : Failed in be_chk_reset_complete"
  87. "status = 0x%x\n", status);
  88. return -EIO;
  89. }
  90. return 0;
  91. }
  92. void be_mcc_notify(struct beiscsi_hba *phba)
  93. {
  94. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  95. u32 val = 0;
  96. val |= mccq->id & DB_MCCQ_RING_ID_MASK;
  97. val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
  98. iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
  99. }
  100. unsigned int alloc_mcc_tag(struct beiscsi_hba *phba)
  101. {
  102. unsigned int tag = 0;
  103. if (phba->ctrl.mcc_tag_available) {
  104. tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
  105. phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
  106. phba->ctrl.mcc_numtag[tag] = 0;
  107. }
  108. if (tag) {
  109. phba->ctrl.mcc_tag_available--;
  110. if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
  111. phba->ctrl.mcc_alloc_index = 0;
  112. else
  113. phba->ctrl.mcc_alloc_index++;
  114. }
  115. return tag;
  116. }
  117. /*
  118. * beiscsi_mccq_compl()- Wait for completion of MBX
  119. * @phba: Driver private structure
  120. * @tag: Tag for the MBX Command
  121. * @wrb: the WRB used for the MBX Command
  122. * @cmd_hdr: IOCTL Hdr for the MBX Cmd
  123. *
  124. * Waits for MBX completion with the passed TAG.
  125. *
  126. * return
  127. * Success: 0
  128. * Failure: Non-Zero
  129. **/
  130. int beiscsi_mccq_compl(struct beiscsi_hba *phba,
  131. uint32_t tag, struct be_mcc_wrb **wrb,
  132. void *cmd_hdr)
  133. {
  134. int rc = 0;
  135. uint32_t mcc_tag_response;
  136. uint16_t status = 0, addl_status = 0, wrb_num = 0;
  137. struct be_mcc_wrb *temp_wrb;
  138. struct be_cmd_req_hdr *ioctl_hdr;
  139. struct be_cmd_resp_hdr *ioctl_resp_hdr;
  140. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  141. if (beiscsi_error(phba))
  142. return -EIO;
  143. /* wait for the mccq completion */
  144. rc = wait_event_interruptible_timeout(
  145. phba->ctrl.mcc_wait[tag],
  146. phba->ctrl.mcc_numtag[tag],
  147. msecs_to_jiffies(
  148. BEISCSI_HOST_MBX_TIMEOUT));
  149. if (rc <= 0) {
  150. beiscsi_log(phba, KERN_ERR,
  151. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  152. BEISCSI_LOG_CONFIG,
  153. "BC_%d : MBX Cmd Completion timed out\n");
  154. rc = -EAGAIN;
  155. goto release_mcc_tag;
  156. } else
  157. rc = 0;
  158. mcc_tag_response = phba->ctrl.mcc_numtag[tag];
  159. status = (mcc_tag_response & CQE_STATUS_MASK);
  160. addl_status = ((mcc_tag_response & CQE_STATUS_ADDL_MASK) >>
  161. CQE_STATUS_ADDL_SHIFT);
  162. if (cmd_hdr) {
  163. ioctl_hdr = (struct be_cmd_req_hdr *)cmd_hdr;
  164. } else {
  165. wrb_num = (mcc_tag_response & CQE_STATUS_WRB_MASK) >>
  166. CQE_STATUS_WRB_SHIFT;
  167. temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
  168. ioctl_hdr = embedded_payload(temp_wrb);
  169. if (wrb)
  170. *wrb = temp_wrb;
  171. }
  172. if (status || addl_status) {
  173. beiscsi_log(phba, KERN_ERR,
  174. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  175. BEISCSI_LOG_CONFIG,
  176. "BC_%d : MBX Cmd Failed for "
  177. "Subsys : %d Opcode : %d with "
  178. "Status : %d and Extd_Status : %d\n",
  179. ioctl_hdr->subsystem,
  180. ioctl_hdr->opcode,
  181. status, addl_status);
  182. if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  183. ioctl_resp_hdr = (struct be_cmd_resp_hdr *) ioctl_hdr;
  184. if (ioctl_resp_hdr->response_length)
  185. goto release_mcc_tag;
  186. }
  187. rc = -EAGAIN;
  188. }
  189. release_mcc_tag:
  190. /* Release the MCC entry */
  191. free_mcc_tag(&phba->ctrl, tag);
  192. return rc;
  193. }
  194. void free_mcc_tag(struct be_ctrl_info *ctrl, unsigned int tag)
  195. {
  196. spin_lock(&ctrl->mbox_lock);
  197. tag = tag & 0x000000FF;
  198. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  199. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  200. ctrl->mcc_free_index = 0;
  201. else
  202. ctrl->mcc_free_index++;
  203. ctrl->mcc_tag_available++;
  204. spin_unlock(&ctrl->mbox_lock);
  205. }
  206. bool is_link_state_evt(u32 trailer)
  207. {
  208. return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
  209. ASYNC_TRAILER_EVENT_CODE_MASK) ==
  210. ASYNC_EVENT_CODE_LINK_STATE);
  211. }
  212. static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
  213. {
  214. if (compl->flags != 0) {
  215. compl->flags = le32_to_cpu(compl->flags);
  216. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  217. return true;
  218. } else
  219. return false;
  220. }
  221. static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
  222. {
  223. compl->flags = 0;
  224. }
  225. /*
  226. * be_mcc_compl_process()- Check the MBX comapletion status
  227. * @ctrl: Function specific MBX data structure
  228. * @compl: Completion status of MBX Command
  229. *
  230. * Check for the MBX completion status when BMBX method used
  231. *
  232. * return
  233. * Success: Zero
  234. * Failure: Non-Zero
  235. **/
  236. static int be_mcc_compl_process(struct be_ctrl_info *ctrl,
  237. struct be_mcc_compl *compl)
  238. {
  239. u16 compl_status, extd_status;
  240. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  241. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  242. struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
  243. struct be_cmd_resp_hdr *resp_hdr;
  244. be_dws_le_to_cpu(compl, 4);
  245. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  246. CQE_STATUS_COMPL_MASK;
  247. if (compl_status != MCC_STATUS_SUCCESS) {
  248. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  249. CQE_STATUS_EXTD_MASK;
  250. beiscsi_log(phba, KERN_ERR,
  251. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  252. "BC_%d : error in cmd completion: "
  253. "Subsystem : %d Opcode : %d "
  254. "status(compl/extd)=%d/%d\n",
  255. hdr->subsystem, hdr->opcode,
  256. compl_status, extd_status);
  257. if (compl_status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  258. resp_hdr = (struct be_cmd_resp_hdr *) hdr;
  259. if (resp_hdr->response_length)
  260. return 0;
  261. }
  262. return -EBUSY;
  263. }
  264. return 0;
  265. }
  266. int be_mcc_compl_process_isr(struct be_ctrl_info *ctrl,
  267. struct be_mcc_compl *compl)
  268. {
  269. u16 compl_status, extd_status;
  270. unsigned short tag;
  271. be_dws_le_to_cpu(compl, 4);
  272. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  273. CQE_STATUS_COMPL_MASK;
  274. /* The ctrl.mcc_numtag[tag] is filled with
  275. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  276. * [7:0] = compl_status
  277. */
  278. tag = (compl->tag0 & 0x000000FF);
  279. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  280. CQE_STATUS_EXTD_MASK;
  281. ctrl->mcc_numtag[tag] = 0x80000000;
  282. ctrl->mcc_numtag[tag] |= (compl->tag0 & 0x00FF0000);
  283. ctrl->mcc_numtag[tag] |= (extd_status & 0x000000FF) << 8;
  284. ctrl->mcc_numtag[tag] |= (compl_status & 0x000000FF);
  285. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  286. return 0;
  287. }
  288. static struct be_mcc_compl *be_mcc_compl_get(struct beiscsi_hba *phba)
  289. {
  290. struct be_queue_info *mcc_cq = &phba->ctrl.mcc_obj.cq;
  291. struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
  292. if (be_mcc_compl_is_new(compl)) {
  293. queue_tail_inc(mcc_cq);
  294. return compl;
  295. }
  296. return NULL;
  297. }
  298. static void be2iscsi_fail_session(struct iscsi_cls_session *cls_session)
  299. {
  300. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  301. }
  302. void beiscsi_async_link_state_process(struct beiscsi_hba *phba,
  303. struct be_async_event_link_state *evt)
  304. {
  305. switch (evt->port_link_status) {
  306. case ASYNC_EVENT_LINK_DOWN:
  307. beiscsi_log(phba, KERN_ERR,
  308. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  309. "BC_%d : Link Down on Physical Port %d\n",
  310. evt->physical_port);
  311. phba->state |= BE_ADAPTER_LINK_DOWN;
  312. iscsi_host_for_each_session(phba->shost,
  313. be2iscsi_fail_session);
  314. break;
  315. case ASYNC_EVENT_LINK_UP:
  316. phba->state = BE_ADAPTER_UP;
  317. beiscsi_log(phba, KERN_ERR,
  318. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  319. "BC_%d : Link UP on Physical Port %d\n",
  320. evt->physical_port);
  321. break;
  322. default:
  323. beiscsi_log(phba, KERN_ERR,
  324. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  325. "BC_%d : Unexpected Async Notification %d on"
  326. "Physical Port %d\n",
  327. evt->port_link_status,
  328. evt->physical_port);
  329. }
  330. }
  331. static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
  332. u16 num_popped)
  333. {
  334. u32 val = 0;
  335. val |= qid & DB_CQ_RING_ID_MASK;
  336. if (arm)
  337. val |= 1 << DB_CQ_REARM_SHIFT;
  338. val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
  339. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  340. }
  341. int beiscsi_process_mcc(struct beiscsi_hba *phba)
  342. {
  343. struct be_mcc_compl *compl;
  344. int num = 0, status = 0;
  345. struct be_ctrl_info *ctrl = &phba->ctrl;
  346. spin_lock_bh(&phba->ctrl.mcc_cq_lock);
  347. while ((compl = be_mcc_compl_get(phba))) {
  348. if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
  349. /* Interpret flags as an async trailer */
  350. if (is_link_state_evt(compl->flags))
  351. /* Interpret compl as a async link evt */
  352. beiscsi_async_link_state_process(phba,
  353. (struct be_async_event_link_state *) compl);
  354. else
  355. beiscsi_log(phba, KERN_ERR,
  356. BEISCSI_LOG_CONFIG |
  357. BEISCSI_LOG_MBOX,
  358. "BC_%d : Unsupported Async Event, flags"
  359. " = 0x%08x\n", compl->flags);
  360. } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  361. status = be_mcc_compl_process(ctrl, compl);
  362. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  363. }
  364. be_mcc_compl_use(compl);
  365. num++;
  366. }
  367. if (num)
  368. beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
  369. spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
  370. return status;
  371. }
  372. /*
  373. * be_mcc_wait_compl()- Wait for MBX completion
  374. * @phba: driver private structure
  375. *
  376. * Wait till no more pending mcc requests are present
  377. *
  378. * return
  379. * Success: 0
  380. * Failure: Non-Zero
  381. *
  382. **/
  383. static int be_mcc_wait_compl(struct beiscsi_hba *phba)
  384. {
  385. int i, status;
  386. for (i = 0; i < mcc_timeout; i++) {
  387. if (beiscsi_error(phba))
  388. return -EIO;
  389. status = beiscsi_process_mcc(phba);
  390. if (status)
  391. return status;
  392. if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
  393. break;
  394. udelay(100);
  395. }
  396. if (i == mcc_timeout) {
  397. beiscsi_log(phba, KERN_ERR,
  398. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  399. "BC_%d : FW Timed Out\n");
  400. phba->fw_timeout = true;
  401. beiscsi_ue_detect(phba);
  402. return -EBUSY;
  403. }
  404. return 0;
  405. }
  406. /*
  407. * be_mcc_notify_wait()- Notify and wait for Compl
  408. * @phba: driver private structure
  409. *
  410. * Notify MCC requests and wait for completion
  411. *
  412. * return
  413. * Success: 0
  414. * Failure: Non-Zero
  415. **/
  416. int be_mcc_notify_wait(struct beiscsi_hba *phba)
  417. {
  418. be_mcc_notify(phba);
  419. return be_mcc_wait_compl(phba);
  420. }
  421. /*
  422. * be_mbox_db_ready_wait()- Check ready status
  423. * @ctrl: Function specific MBX data structure
  424. *
  425. * Check for the ready status of FW to send BMBX
  426. * commands to adapter.
  427. *
  428. * return
  429. * Success: 0
  430. * Failure: Non-Zero
  431. **/
  432. static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
  433. {
  434. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  435. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  436. int wait = 0;
  437. u32 ready;
  438. do {
  439. if (beiscsi_error(phba))
  440. return -EIO;
  441. ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
  442. if (ready)
  443. break;
  444. if (wait > BEISCSI_HOST_MBX_TIMEOUT) {
  445. beiscsi_log(phba, KERN_ERR,
  446. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  447. "BC_%d : FW Timed Out\n");
  448. phba->fw_timeout = true;
  449. beiscsi_ue_detect(phba);
  450. return -EBUSY;
  451. }
  452. mdelay(1);
  453. wait++;
  454. } while (true);
  455. return 0;
  456. }
  457. /*
  458. * be_mbox_notify: Notify adapter of new BMBX command
  459. * @ctrl: Function specific MBX data structure
  460. *
  461. * Ring doorbell to inform adapter of a BMBX command
  462. * to process
  463. *
  464. * return
  465. * Success: 0
  466. * Failure: Non-Zero
  467. **/
  468. int be_mbox_notify(struct be_ctrl_info *ctrl)
  469. {
  470. int status;
  471. u32 val = 0;
  472. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  473. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  474. struct be_mcc_mailbox *mbox = mbox_mem->va;
  475. struct be_mcc_compl *compl = &mbox->compl;
  476. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  477. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  478. val |= MPU_MAILBOX_DB_HI_MASK;
  479. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  480. iowrite32(val, db);
  481. status = be_mbox_db_ready_wait(ctrl);
  482. if (status)
  483. return status;
  484. val = 0;
  485. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  486. val &= ~MPU_MAILBOX_DB_HI_MASK;
  487. val |= (u32) (mbox_mem->dma >> 4) << 2;
  488. iowrite32(val, db);
  489. status = be_mbox_db_ready_wait(ctrl);
  490. if (status)
  491. return status;
  492. if (be_mcc_compl_is_new(compl)) {
  493. status = be_mcc_compl_process(ctrl, &mbox->compl);
  494. be_mcc_compl_use(compl);
  495. if (status) {
  496. beiscsi_log(phba, KERN_ERR,
  497. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  498. "BC_%d : After be_mcc_compl_process\n");
  499. return status;
  500. }
  501. } else {
  502. beiscsi_log(phba, KERN_ERR,
  503. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  504. "BC_%d : Invalid Mailbox Completion\n");
  505. return -EBUSY;
  506. }
  507. return 0;
  508. }
  509. /*
  510. * Insert the mailbox address into the doorbell in two steps
  511. * Polls on the mbox doorbell till a command completion (or a timeout) occurs
  512. */
  513. static int be_mbox_notify_wait(struct beiscsi_hba *phba)
  514. {
  515. int status;
  516. u32 val = 0;
  517. void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
  518. struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
  519. struct be_mcc_mailbox *mbox = mbox_mem->va;
  520. struct be_mcc_compl *compl = &mbox->compl;
  521. struct be_ctrl_info *ctrl = &phba->ctrl;
  522. val |= MPU_MAILBOX_DB_HI_MASK;
  523. /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
  524. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  525. iowrite32(val, db);
  526. /* wait for ready to be set */
  527. status = be_mbox_db_ready_wait(ctrl);
  528. if (status != 0)
  529. return status;
  530. val = 0;
  531. /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
  532. val |= (u32)(mbox_mem->dma >> 4) << 2;
  533. iowrite32(val, db);
  534. status = be_mbox_db_ready_wait(ctrl);
  535. if (status != 0)
  536. return status;
  537. /* A cq entry has been made now */
  538. if (be_mcc_compl_is_new(compl)) {
  539. status = be_mcc_compl_process(ctrl, &mbox->compl);
  540. be_mcc_compl_use(compl);
  541. if (status)
  542. return status;
  543. } else {
  544. beiscsi_log(phba, KERN_ERR,
  545. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  546. "BC_%d : invalid mailbox completion\n");
  547. return -EBUSY;
  548. }
  549. return 0;
  550. }
  551. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
  552. bool embedded, u8 sge_cnt)
  553. {
  554. if (embedded)
  555. wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
  556. else
  557. wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  558. MCC_WRB_SGE_CNT_SHIFT;
  559. wrb->payload_length = payload_len;
  560. be_dws_cpu_to_le(wrb, 8);
  561. }
  562. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  563. u8 subsystem, u8 opcode, int cmd_len)
  564. {
  565. req_hdr->opcode = opcode;
  566. req_hdr->subsystem = subsystem;
  567. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  568. req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
  569. }
  570. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  571. struct be_dma_mem *mem)
  572. {
  573. int i, buf_pages;
  574. u64 dma = (u64) mem->dma;
  575. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  576. for (i = 0; i < buf_pages; i++) {
  577. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  578. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  579. dma += PAGE_SIZE_4K;
  580. }
  581. }
  582. static u32 eq_delay_to_mult(u32 usec_delay)
  583. {
  584. #define MAX_INTR_RATE 651042
  585. const u32 round = 10;
  586. u32 multiplier;
  587. if (usec_delay == 0)
  588. multiplier = 0;
  589. else {
  590. u32 interrupt_rate = 1000000 / usec_delay;
  591. if (interrupt_rate == 0)
  592. multiplier = 1023;
  593. else {
  594. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  595. multiplier /= interrupt_rate;
  596. multiplier = (multiplier + round / 2) / round;
  597. multiplier = min(multiplier, (u32) 1023);
  598. }
  599. }
  600. return multiplier;
  601. }
  602. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  603. {
  604. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  605. }
  606. struct be_mcc_wrb *wrb_from_mccq(struct beiscsi_hba *phba)
  607. {
  608. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  609. struct be_mcc_wrb *wrb;
  610. BUG_ON(atomic_read(&mccq->used) >= mccq->len);
  611. wrb = queue_head_node(mccq);
  612. memset(wrb, 0, sizeof(*wrb));
  613. wrb->tag0 = (mccq->head & 0x000000FF) << 16;
  614. queue_head_inc(mccq);
  615. atomic_inc(&mccq->used);
  616. return wrb;
  617. }
  618. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  619. struct be_queue_info *eq, int eq_delay)
  620. {
  621. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  622. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  623. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  624. struct be_dma_mem *q_mem = &eq->dma_mem;
  625. int status;
  626. spin_lock(&ctrl->mbox_lock);
  627. memset(wrb, 0, sizeof(*wrb));
  628. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  629. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  630. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  631. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  632. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  633. PCI_FUNC(ctrl->pdev->devfn));
  634. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  635. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  636. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  637. __ilog2_u32(eq->len / 256));
  638. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  639. eq_delay_to_mult(eq_delay));
  640. be_dws_cpu_to_le(req->context, sizeof(req->context));
  641. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  642. status = be_mbox_notify(ctrl);
  643. if (!status) {
  644. eq->id = le16_to_cpu(resp->eq_id);
  645. eq->created = true;
  646. }
  647. spin_unlock(&ctrl->mbox_lock);
  648. return status;
  649. }
  650. /**
  651. * be_cmd_fw_initialize()- Initialize FW
  652. * @ctrl: Pointer to function control structure
  653. *
  654. * Send FW initialize pattern for the function.
  655. *
  656. * return
  657. * Success: 0
  658. * Failure: Non-Zero value
  659. **/
  660. int be_cmd_fw_initialize(struct be_ctrl_info *ctrl)
  661. {
  662. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  663. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  664. int status;
  665. u8 *endian_check;
  666. spin_lock(&ctrl->mbox_lock);
  667. memset(wrb, 0, sizeof(*wrb));
  668. endian_check = (u8 *) wrb;
  669. *endian_check++ = 0xFF;
  670. *endian_check++ = 0x12;
  671. *endian_check++ = 0x34;
  672. *endian_check++ = 0xFF;
  673. *endian_check++ = 0xFF;
  674. *endian_check++ = 0x56;
  675. *endian_check++ = 0x78;
  676. *endian_check++ = 0xFF;
  677. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  678. status = be_mbox_notify(ctrl);
  679. if (status)
  680. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  681. "BC_%d : be_cmd_fw_initialize Failed\n");
  682. spin_unlock(&ctrl->mbox_lock);
  683. return status;
  684. }
  685. /**
  686. * be_cmd_fw_uninit()- Uinitialize FW
  687. * @ctrl: Pointer to function control structure
  688. *
  689. * Send FW uninitialize pattern for the function
  690. *
  691. * return
  692. * Success: 0
  693. * Failure: Non-Zero value
  694. **/
  695. int be_cmd_fw_uninit(struct be_ctrl_info *ctrl)
  696. {
  697. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  698. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  699. int status;
  700. u8 *endian_check;
  701. spin_lock(&ctrl->mbox_lock);
  702. memset(wrb, 0, sizeof(*wrb));
  703. endian_check = (u8 *) wrb;
  704. *endian_check++ = 0xFF;
  705. *endian_check++ = 0xAA;
  706. *endian_check++ = 0xBB;
  707. *endian_check++ = 0xFF;
  708. *endian_check++ = 0xFF;
  709. *endian_check++ = 0xCC;
  710. *endian_check++ = 0xDD;
  711. *endian_check = 0xFF;
  712. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  713. status = be_mbox_notify(ctrl);
  714. if (status)
  715. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  716. "BC_%d : be_cmd_fw_uninit Failed\n");
  717. spin_unlock(&ctrl->mbox_lock);
  718. return status;
  719. }
  720. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  721. struct be_queue_info *cq, struct be_queue_info *eq,
  722. bool sol_evts, bool no_delay, int coalesce_wm)
  723. {
  724. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  725. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  726. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  727. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  728. struct be_dma_mem *q_mem = &cq->dma_mem;
  729. void *ctxt = &req->context;
  730. int status;
  731. spin_lock(&ctrl->mbox_lock);
  732. memset(wrb, 0, sizeof(*wrb));
  733. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  734. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  735. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  736. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  737. if (chip_skh_r(ctrl->pdev)) {
  738. req->hdr.version = MBX_CMD_VER2;
  739. req->page_size = 1;
  740. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  741. ctxt, coalesce_wm);
  742. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  743. ctxt, no_delay);
  744. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  745. __ilog2_u32(cq->len / 256));
  746. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  747. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  748. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  749. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  750. } else {
  751. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  752. ctxt, coalesce_wm);
  753. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  754. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  755. __ilog2_u32(cq->len / 256));
  756. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  757. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  758. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  759. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  760. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  761. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  762. PCI_FUNC(ctrl->pdev->devfn));
  763. }
  764. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  765. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  766. status = be_mbox_notify(ctrl);
  767. if (!status) {
  768. cq->id = le16_to_cpu(resp->cq_id);
  769. cq->created = true;
  770. } else
  771. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  772. "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
  773. status);
  774. spin_unlock(&ctrl->mbox_lock);
  775. return status;
  776. }
  777. static u32 be_encoded_q_len(int q_len)
  778. {
  779. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  780. if (len_encoded == 16)
  781. len_encoded = 0;
  782. return len_encoded;
  783. }
  784. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  785. struct be_queue_info *mccq,
  786. struct be_queue_info *cq)
  787. {
  788. struct be_mcc_wrb *wrb;
  789. struct be_cmd_req_mcc_create *req;
  790. struct be_dma_mem *q_mem = &mccq->dma_mem;
  791. struct be_ctrl_info *ctrl;
  792. void *ctxt;
  793. int status;
  794. spin_lock(&phba->ctrl.mbox_lock);
  795. ctrl = &phba->ctrl;
  796. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  797. memset(wrb, 0, sizeof(*wrb));
  798. req = embedded_payload(wrb);
  799. ctxt = &req->context;
  800. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  801. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  802. OPCODE_COMMON_MCC_CREATE, sizeof(*req));
  803. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  804. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  805. PCI_FUNC(phba->pcidev->devfn));
  806. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  807. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  808. be_encoded_q_len(mccq->len));
  809. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  810. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  811. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  812. status = be_mbox_notify_wait(phba);
  813. if (!status) {
  814. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  815. mccq->id = le16_to_cpu(resp->id);
  816. mccq->created = true;
  817. }
  818. spin_unlock(&phba->ctrl.mbox_lock);
  819. return status;
  820. }
  821. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  822. int queue_type)
  823. {
  824. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  825. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  826. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  827. u8 subsys = 0, opcode = 0;
  828. int status;
  829. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  830. "BC_%d : In beiscsi_cmd_q_destroy "
  831. "queue_type : %d\n", queue_type);
  832. spin_lock(&ctrl->mbox_lock);
  833. memset(wrb, 0, sizeof(*wrb));
  834. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  835. switch (queue_type) {
  836. case QTYPE_EQ:
  837. subsys = CMD_SUBSYSTEM_COMMON;
  838. opcode = OPCODE_COMMON_EQ_DESTROY;
  839. break;
  840. case QTYPE_CQ:
  841. subsys = CMD_SUBSYSTEM_COMMON;
  842. opcode = OPCODE_COMMON_CQ_DESTROY;
  843. break;
  844. case QTYPE_MCCQ:
  845. subsys = CMD_SUBSYSTEM_COMMON;
  846. opcode = OPCODE_COMMON_MCC_DESTROY;
  847. break;
  848. case QTYPE_WRBQ:
  849. subsys = CMD_SUBSYSTEM_ISCSI;
  850. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  851. break;
  852. case QTYPE_DPDUQ:
  853. subsys = CMD_SUBSYSTEM_ISCSI;
  854. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  855. break;
  856. case QTYPE_SGL:
  857. subsys = CMD_SUBSYSTEM_ISCSI;
  858. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  859. break;
  860. default:
  861. spin_unlock(&ctrl->mbox_lock);
  862. BUG();
  863. return -ENXIO;
  864. }
  865. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  866. if (queue_type != QTYPE_SGL)
  867. req->id = cpu_to_le16(q->id);
  868. status = be_mbox_notify(ctrl);
  869. spin_unlock(&ctrl->mbox_lock);
  870. return status;
  871. }
  872. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  873. struct be_queue_info *cq,
  874. struct be_queue_info *dq, int length,
  875. int entry_size)
  876. {
  877. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  878. struct be_defq_create_req *req = embedded_payload(wrb);
  879. struct be_dma_mem *q_mem = &dq->dma_mem;
  880. void *ctxt = &req->context;
  881. int status;
  882. spin_lock(&ctrl->mbox_lock);
  883. memset(wrb, 0, sizeof(*wrb));
  884. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  885. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  886. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  887. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  888. AMAP_SET_BITS(struct amap_be_default_pdu_context, rx_pdid, ctxt, 0);
  889. AMAP_SET_BITS(struct amap_be_default_pdu_context, rx_pdid_valid, ctxt,
  890. 1);
  891. AMAP_SET_BITS(struct amap_be_default_pdu_context, pci_func_id, ctxt,
  892. PCI_FUNC(ctrl->pdev->devfn));
  893. AMAP_SET_BITS(struct amap_be_default_pdu_context, ring_size, ctxt,
  894. be_encoded_q_len(length / sizeof(struct phys_addr)));
  895. AMAP_SET_BITS(struct amap_be_default_pdu_context, default_buffer_size,
  896. ctxt, entry_size);
  897. AMAP_SET_BITS(struct amap_be_default_pdu_context, cq_id_recv, ctxt,
  898. cq->id);
  899. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  900. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  901. status = be_mbox_notify(ctrl);
  902. if (!status) {
  903. struct be_defq_create_resp *resp = embedded_payload(wrb);
  904. dq->id = le16_to_cpu(resp->id);
  905. dq->created = true;
  906. }
  907. spin_unlock(&ctrl->mbox_lock);
  908. return status;
  909. }
  910. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
  911. struct be_queue_info *wrbq)
  912. {
  913. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  914. struct be_wrbq_create_req *req = embedded_payload(wrb);
  915. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  916. int status;
  917. spin_lock(&ctrl->mbox_lock);
  918. memset(wrb, 0, sizeof(*wrb));
  919. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  920. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  921. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  922. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  923. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  924. status = be_mbox_notify(ctrl);
  925. if (!status) {
  926. wrbq->id = le16_to_cpu(resp->cid);
  927. wrbq->created = true;
  928. }
  929. spin_unlock(&ctrl->mbox_lock);
  930. return status;
  931. }
  932. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  933. struct be_dma_mem *q_mem,
  934. u32 page_offset, u32 num_pages)
  935. {
  936. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  937. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  938. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  939. int status;
  940. unsigned int curr_pages;
  941. u32 internal_page_offset = 0;
  942. u32 temp_num_pages = num_pages;
  943. if (num_pages == 0xff)
  944. num_pages = 1;
  945. spin_lock(&ctrl->mbox_lock);
  946. do {
  947. memset(wrb, 0, sizeof(*wrb));
  948. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  949. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  950. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  951. sizeof(*req));
  952. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  953. pages);
  954. req->num_pages = min(num_pages, curr_pages);
  955. req->page_offset = page_offset;
  956. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  957. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  958. internal_page_offset += req->num_pages;
  959. page_offset += req->num_pages;
  960. num_pages -= req->num_pages;
  961. if (temp_num_pages == 0xff)
  962. req->num_pages = temp_num_pages;
  963. status = be_mbox_notify(ctrl);
  964. if (status) {
  965. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  966. "BC_%d : FW CMD to map iscsi frags failed.\n");
  967. goto error;
  968. }
  969. } while (num_pages > 0);
  970. error:
  971. spin_unlock(&ctrl->mbox_lock);
  972. if (status != 0)
  973. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  974. return status;
  975. }
  976. int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
  977. {
  978. struct be_ctrl_info *ctrl = &phba->ctrl;
  979. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  980. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  981. int status;
  982. spin_lock(&ctrl->mbox_lock);
  983. req = embedded_payload(wrb);
  984. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  985. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  986. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  987. status = be_mbox_notify_wait(phba);
  988. spin_unlock(&ctrl->mbox_lock);
  989. return status;
  990. }
  991. /**
  992. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  993. * @phba: device priv structure instance
  994. * @vlan_tag: TAG to be set
  995. *
  996. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  997. *
  998. * returns
  999. * TAG for the MBX Cmd
  1000. * **/
  1001. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1002. uint16_t vlan_tag)
  1003. {
  1004. unsigned int tag = 0;
  1005. struct be_mcc_wrb *wrb;
  1006. struct be_cmd_set_vlan_req *req;
  1007. struct be_ctrl_info *ctrl = &phba->ctrl;
  1008. spin_lock(&ctrl->mbox_lock);
  1009. tag = alloc_mcc_tag(phba);
  1010. if (!tag) {
  1011. spin_unlock(&ctrl->mbox_lock);
  1012. return tag;
  1013. }
  1014. wrb = wrb_from_mccq(phba);
  1015. req = embedded_payload(wrb);
  1016. wrb->tag0 |= tag;
  1017. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1018. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1019. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1020. sizeof(*req));
  1021. req->interface_hndl = phba->interface_handle;
  1022. req->vlan_priority = vlan_tag;
  1023. be_mcc_notify(phba);
  1024. spin_unlock(&ctrl->mbox_lock);
  1025. return tag;
  1026. }