be_cmds.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /**
  2. * Copyright (C) 2005 - 2013 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. if ((evt->port_link_status == ASYNC_EVENT_LINK_DOWN) ||
  306. ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
  307. (evt->port_fault != BEISCSI_PHY_LINK_FAULT_NONE))) {
  308. phba->state = BE_ADAPTER_LINK_DOWN;
  309. beiscsi_log(phba, KERN_ERR,
  310. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  311. "BC_%d : Link Down on Port %d\n",
  312. evt->physical_port);
  313. iscsi_host_for_each_session(phba->shost,
  314. be2iscsi_fail_session);
  315. } else if ((evt->port_link_status & ASYNC_EVENT_LINK_UP) ||
  316. ((evt->port_link_status & ASYNC_EVENT_LOGICAL) &&
  317. (evt->port_fault == BEISCSI_PHY_LINK_FAULT_NONE))) {
  318. phba->state = BE_ADAPTER_UP;
  319. beiscsi_log(phba, KERN_ERR,
  320. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  321. "BC_%d : Link UP on Port %d\n",
  322. evt->physical_port);
  323. }
  324. }
  325. static void beiscsi_cq_notify(struct beiscsi_hba *phba, u16 qid, bool arm,
  326. u16 num_popped)
  327. {
  328. u32 val = 0;
  329. val |= qid & DB_CQ_RING_ID_MASK;
  330. if (arm)
  331. val |= 1 << DB_CQ_REARM_SHIFT;
  332. val |= num_popped << DB_CQ_NUM_POPPED_SHIFT;
  333. iowrite32(val, phba->db_va + DB_CQ_OFFSET);
  334. }
  335. int beiscsi_process_mcc(struct beiscsi_hba *phba)
  336. {
  337. struct be_mcc_compl *compl;
  338. int num = 0, status = 0;
  339. struct be_ctrl_info *ctrl = &phba->ctrl;
  340. spin_lock_bh(&phba->ctrl.mcc_cq_lock);
  341. while ((compl = be_mcc_compl_get(phba))) {
  342. if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
  343. /* Interpret flags as an async trailer */
  344. if (is_link_state_evt(compl->flags))
  345. /* Interpret compl as a async link evt */
  346. beiscsi_async_link_state_process(phba,
  347. (struct be_async_event_link_state *) compl);
  348. else
  349. beiscsi_log(phba, KERN_ERR,
  350. BEISCSI_LOG_CONFIG |
  351. BEISCSI_LOG_MBOX,
  352. "BC_%d : Unsupported Async Event, flags"
  353. " = 0x%08x\n", compl->flags);
  354. } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
  355. status = be_mcc_compl_process(ctrl, compl);
  356. atomic_dec(&phba->ctrl.mcc_obj.q.used);
  357. }
  358. be_mcc_compl_use(compl);
  359. num++;
  360. }
  361. if (num)
  362. beiscsi_cq_notify(phba, phba->ctrl.mcc_obj.cq.id, true, num);
  363. spin_unlock_bh(&phba->ctrl.mcc_cq_lock);
  364. return status;
  365. }
  366. /*
  367. * be_mcc_wait_compl()- Wait for MBX completion
  368. * @phba: driver private structure
  369. *
  370. * Wait till no more pending mcc requests are present
  371. *
  372. * return
  373. * Success: 0
  374. * Failure: Non-Zero
  375. *
  376. **/
  377. static int be_mcc_wait_compl(struct beiscsi_hba *phba)
  378. {
  379. int i, status;
  380. for (i = 0; i < mcc_timeout; i++) {
  381. if (beiscsi_error(phba))
  382. return -EIO;
  383. status = beiscsi_process_mcc(phba);
  384. if (status)
  385. return status;
  386. if (atomic_read(&phba->ctrl.mcc_obj.q.used) == 0)
  387. break;
  388. udelay(100);
  389. }
  390. if (i == mcc_timeout) {
  391. beiscsi_log(phba, KERN_ERR,
  392. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  393. "BC_%d : FW Timed Out\n");
  394. phba->fw_timeout = true;
  395. beiscsi_ue_detect(phba);
  396. return -EBUSY;
  397. }
  398. return 0;
  399. }
  400. /*
  401. * be_mcc_notify_wait()- Notify and wait for Compl
  402. * @phba: driver private structure
  403. *
  404. * Notify MCC requests and wait for completion
  405. *
  406. * return
  407. * Success: 0
  408. * Failure: Non-Zero
  409. **/
  410. int be_mcc_notify_wait(struct beiscsi_hba *phba)
  411. {
  412. be_mcc_notify(phba);
  413. return be_mcc_wait_compl(phba);
  414. }
  415. /*
  416. * be_mbox_db_ready_wait()- Check ready status
  417. * @ctrl: Function specific MBX data structure
  418. *
  419. * Check for the ready status of FW to send BMBX
  420. * commands to adapter.
  421. *
  422. * return
  423. * Success: 0
  424. * Failure: Non-Zero
  425. **/
  426. static int be_mbox_db_ready_wait(struct be_ctrl_info *ctrl)
  427. {
  428. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  429. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  430. uint32_t wait = 0;
  431. u32 ready;
  432. do {
  433. if (beiscsi_error(phba))
  434. return -EIO;
  435. ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
  436. if (ready)
  437. break;
  438. if (wait > BEISCSI_HOST_MBX_TIMEOUT) {
  439. beiscsi_log(phba, KERN_ERR,
  440. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  441. "BC_%d : FW Timed Out\n");
  442. phba->fw_timeout = true;
  443. beiscsi_ue_detect(phba);
  444. return -EBUSY;
  445. }
  446. mdelay(1);
  447. wait++;
  448. } while (true);
  449. return 0;
  450. }
  451. /*
  452. * be_mbox_notify: Notify adapter of new BMBX command
  453. * @ctrl: Function specific MBX data structure
  454. *
  455. * Ring doorbell to inform adapter of a BMBX command
  456. * to process
  457. *
  458. * return
  459. * Success: 0
  460. * Failure: Non-Zero
  461. **/
  462. int be_mbox_notify(struct be_ctrl_info *ctrl)
  463. {
  464. int status;
  465. u32 val = 0;
  466. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  467. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  468. struct be_mcc_mailbox *mbox = mbox_mem->va;
  469. struct be_mcc_compl *compl = &mbox->compl;
  470. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  471. status = be_mbox_db_ready_wait(ctrl);
  472. if (status)
  473. return status;
  474. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  475. val |= MPU_MAILBOX_DB_HI_MASK;
  476. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  477. iowrite32(val, db);
  478. status = be_mbox_db_ready_wait(ctrl);
  479. if (status)
  480. return status;
  481. val = 0;
  482. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  483. val &= ~MPU_MAILBOX_DB_HI_MASK;
  484. val |= (u32) (mbox_mem->dma >> 4) << 2;
  485. iowrite32(val, db);
  486. status = be_mbox_db_ready_wait(ctrl);
  487. if (status)
  488. return status;
  489. if (be_mcc_compl_is_new(compl)) {
  490. status = be_mcc_compl_process(ctrl, &mbox->compl);
  491. be_mcc_compl_use(compl);
  492. if (status) {
  493. beiscsi_log(phba, KERN_ERR,
  494. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  495. "BC_%d : After be_mcc_compl_process\n");
  496. return status;
  497. }
  498. } else {
  499. beiscsi_log(phba, KERN_ERR,
  500. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  501. "BC_%d : Invalid Mailbox Completion\n");
  502. return -EBUSY;
  503. }
  504. return 0;
  505. }
  506. /*
  507. * Insert the mailbox address into the doorbell in two steps
  508. * Polls on the mbox doorbell till a command completion (or a timeout) occurs
  509. */
  510. static int be_mbox_notify_wait(struct beiscsi_hba *phba)
  511. {
  512. int status;
  513. u32 val = 0;
  514. void __iomem *db = phba->ctrl.db + MPU_MAILBOX_DB_OFFSET;
  515. struct be_dma_mem *mbox_mem = &phba->ctrl.mbox_mem;
  516. struct be_mcc_mailbox *mbox = mbox_mem->va;
  517. struct be_mcc_compl *compl = &mbox->compl;
  518. struct be_ctrl_info *ctrl = &phba->ctrl;
  519. status = be_mbox_db_ready_wait(ctrl);
  520. if (status)
  521. return status;
  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 (is_chip_be2_be3r(phba)) {
  738. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  739. ctxt, coalesce_wm);
  740. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  741. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  742. __ilog2_u32(cq->len / 256));
  743. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  744. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  745. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  746. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  747. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  748. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  749. PCI_FUNC(ctrl->pdev->devfn));
  750. } else {
  751. req->hdr.version = MBX_CMD_VER2;
  752. req->page_size = 1;
  753. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  754. ctxt, coalesce_wm);
  755. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  756. ctxt, no_delay);
  757. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  758. __ilog2_u32(cq->len / 256));
  759. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  760. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  761. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  762. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  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. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  881. void *ctxt = &req->context;
  882. int status;
  883. spin_lock(&ctrl->mbox_lock);
  884. memset(wrb, 0, sizeof(*wrb));
  885. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  886. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  887. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  888. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  889. if (is_chip_be2_be3r(phba)) {
  890. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  891. rx_pdid, ctxt, 0);
  892. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  893. rx_pdid_valid, ctxt, 1);
  894. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  895. pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
  896. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  897. ring_size, ctxt,
  898. be_encoded_q_len(length /
  899. sizeof(struct phys_addr)));
  900. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  901. default_buffer_size, ctxt, entry_size);
  902. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  903. cq_id_recv, ctxt, cq->id);
  904. } else {
  905. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  906. rx_pdid, ctxt, 0);
  907. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  908. rx_pdid_valid, ctxt, 1);
  909. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  910. ring_size, ctxt,
  911. be_encoded_q_len(length /
  912. sizeof(struct phys_addr)));
  913. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  914. default_buffer_size, ctxt, entry_size);
  915. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  916. cq_id_recv, ctxt, cq->id);
  917. }
  918. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  919. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  920. status = be_mbox_notify(ctrl);
  921. if (!status) {
  922. struct be_defq_create_resp *resp = embedded_payload(wrb);
  923. dq->id = le16_to_cpu(resp->id);
  924. dq->created = true;
  925. }
  926. spin_unlock(&ctrl->mbox_lock);
  927. return status;
  928. }
  929. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl, struct be_dma_mem *q_mem,
  930. struct be_queue_info *wrbq)
  931. {
  932. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  933. struct be_wrbq_create_req *req = embedded_payload(wrb);
  934. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  935. int status;
  936. spin_lock(&ctrl->mbox_lock);
  937. memset(wrb, 0, sizeof(*wrb));
  938. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  939. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  940. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  941. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  942. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  943. status = be_mbox_notify(ctrl);
  944. if (!status) {
  945. wrbq->id = le16_to_cpu(resp->cid);
  946. wrbq->created = true;
  947. }
  948. spin_unlock(&ctrl->mbox_lock);
  949. return status;
  950. }
  951. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  952. struct be_dma_mem *q_mem,
  953. u32 page_offset, u32 num_pages)
  954. {
  955. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  956. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  957. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  958. int status;
  959. unsigned int curr_pages;
  960. u32 internal_page_offset = 0;
  961. u32 temp_num_pages = num_pages;
  962. if (num_pages == 0xff)
  963. num_pages = 1;
  964. spin_lock(&ctrl->mbox_lock);
  965. do {
  966. memset(wrb, 0, sizeof(*wrb));
  967. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  968. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  969. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  970. sizeof(*req));
  971. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  972. pages);
  973. req->num_pages = min(num_pages, curr_pages);
  974. req->page_offset = page_offset;
  975. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  976. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  977. internal_page_offset += req->num_pages;
  978. page_offset += req->num_pages;
  979. num_pages -= req->num_pages;
  980. if (temp_num_pages == 0xff)
  981. req->num_pages = temp_num_pages;
  982. status = be_mbox_notify(ctrl);
  983. if (status) {
  984. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  985. "BC_%d : FW CMD to map iscsi frags failed.\n");
  986. goto error;
  987. }
  988. } while (num_pages > 0);
  989. error:
  990. spin_unlock(&ctrl->mbox_lock);
  991. if (status != 0)
  992. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  993. return status;
  994. }
  995. int beiscsi_cmd_reset_function(struct beiscsi_hba *phba)
  996. {
  997. struct be_ctrl_info *ctrl = &phba->ctrl;
  998. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  999. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1000. int status;
  1001. spin_lock(&ctrl->mbox_lock);
  1002. req = embedded_payload(wrb);
  1003. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1004. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1005. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  1006. status = be_mbox_notify_wait(phba);
  1007. spin_unlock(&ctrl->mbox_lock);
  1008. return status;
  1009. }
  1010. /**
  1011. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  1012. * @phba: device priv structure instance
  1013. * @vlan_tag: TAG to be set
  1014. *
  1015. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1016. *
  1017. * returns
  1018. * TAG for the MBX Cmd
  1019. * **/
  1020. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1021. uint16_t vlan_tag)
  1022. {
  1023. unsigned int tag = 0;
  1024. struct be_mcc_wrb *wrb;
  1025. struct be_cmd_set_vlan_req *req;
  1026. struct be_ctrl_info *ctrl = &phba->ctrl;
  1027. spin_lock(&ctrl->mbox_lock);
  1028. tag = alloc_mcc_tag(phba);
  1029. if (!tag) {
  1030. spin_unlock(&ctrl->mbox_lock);
  1031. return tag;
  1032. }
  1033. wrb = wrb_from_mccq(phba);
  1034. req = embedded_payload(wrb);
  1035. wrb->tag0 |= tag;
  1036. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1037. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1038. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1039. sizeof(*req));
  1040. req->interface_hndl = phba->interface_handle;
  1041. req->vlan_priority = vlan_tag;
  1042. be_mcc_notify(phba);
  1043. spin_unlock(&ctrl->mbox_lock);
  1044. return tag;
  1045. }