be_cmds.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827
  1. /*
  2. * Copyright 2017 Broadcom. All Rights Reserved.
  3. * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
  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@broadcom.com
  12. *
  13. */
  14. #include <scsi/iscsi_proto.h>
  15. #include "be_main.h"
  16. #include "be.h"
  17. #include "be_mgmt.h"
  18. /* UE Status Low CSR */
  19. static const char * const desc_ue_status_low[] = {
  20. "CEV",
  21. "CTX",
  22. "DBUF",
  23. "ERX",
  24. "Host",
  25. "MPU",
  26. "NDMA",
  27. "PTC ",
  28. "RDMA ",
  29. "RXF ",
  30. "RXIPS ",
  31. "RXULP0 ",
  32. "RXULP1 ",
  33. "RXULP2 ",
  34. "TIM ",
  35. "TPOST ",
  36. "TPRE ",
  37. "TXIPS ",
  38. "TXULP0 ",
  39. "TXULP1 ",
  40. "UC ",
  41. "WDMA ",
  42. "TXULP2 ",
  43. "HOST1 ",
  44. "P0_OB_LINK ",
  45. "P1_OB_LINK ",
  46. "HOST_GPIO ",
  47. "MBOX ",
  48. "AXGMAC0",
  49. "AXGMAC1",
  50. "JTAG",
  51. "MPU_INTPEND"
  52. };
  53. /* UE Status High CSR */
  54. static const char * const desc_ue_status_hi[] = {
  55. "LPCMEMHOST",
  56. "MGMT_MAC",
  57. "PCS0ONLINE",
  58. "MPU_IRAM",
  59. "PCS1ONLINE",
  60. "PCTL0",
  61. "PCTL1",
  62. "PMEM",
  63. "RR",
  64. "TXPB",
  65. "RXPP",
  66. "XAUI",
  67. "TXP",
  68. "ARM",
  69. "IPC",
  70. "HOST2",
  71. "HOST3",
  72. "HOST4",
  73. "HOST5",
  74. "HOST6",
  75. "HOST7",
  76. "HOST8",
  77. "HOST9",
  78. "NETC",
  79. "Unknown",
  80. "Unknown",
  81. "Unknown",
  82. "Unknown",
  83. "Unknown",
  84. "Unknown",
  85. "Unknown",
  86. "Unknown"
  87. };
  88. struct be_mcc_wrb *alloc_mcc_wrb(struct beiscsi_hba *phba,
  89. unsigned int *ref_tag)
  90. {
  91. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  92. struct be_mcc_wrb *wrb = NULL;
  93. unsigned int tag;
  94. spin_lock(&phba->ctrl.mcc_lock);
  95. if (mccq->used == mccq->len) {
  96. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT |
  97. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  98. "BC_%d : MCC queue full: WRB used %u tag avail %u\n",
  99. mccq->used, phba->ctrl.mcc_tag_available);
  100. goto alloc_failed;
  101. }
  102. if (!phba->ctrl.mcc_tag_available)
  103. goto alloc_failed;
  104. tag = phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index];
  105. if (!tag) {
  106. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT |
  107. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  108. "BC_%d : MCC tag 0 allocated: tag avail %u alloc index %u\n",
  109. phba->ctrl.mcc_tag_available,
  110. phba->ctrl.mcc_alloc_index);
  111. goto alloc_failed;
  112. }
  113. /* return this tag for further reference */
  114. *ref_tag = tag;
  115. phba->ctrl.mcc_tag[phba->ctrl.mcc_alloc_index] = 0;
  116. phba->ctrl.mcc_tag_status[tag] = 0;
  117. phba->ctrl.ptag_state[tag].tag_state = 0;
  118. phba->ctrl.ptag_state[tag].cbfn = NULL;
  119. phba->ctrl.mcc_tag_available--;
  120. if (phba->ctrl.mcc_alloc_index == (MAX_MCC_CMD - 1))
  121. phba->ctrl.mcc_alloc_index = 0;
  122. else
  123. phba->ctrl.mcc_alloc_index++;
  124. wrb = queue_head_node(mccq);
  125. memset(wrb, 0, sizeof(*wrb));
  126. wrb->tag0 = tag;
  127. wrb->tag0 |= (mccq->head << MCC_Q_WRB_IDX_SHIFT) & MCC_Q_WRB_IDX_MASK;
  128. queue_head_inc(mccq);
  129. mccq->used++;
  130. alloc_failed:
  131. spin_unlock(&phba->ctrl.mcc_lock);
  132. return wrb;
  133. }
  134. void free_mcc_wrb(struct be_ctrl_info *ctrl, unsigned int tag)
  135. {
  136. struct be_queue_info *mccq = &ctrl->mcc_obj.q;
  137. spin_lock(&ctrl->mcc_lock);
  138. tag = tag & MCC_Q_CMD_TAG_MASK;
  139. ctrl->mcc_tag[ctrl->mcc_free_index] = tag;
  140. if (ctrl->mcc_free_index == (MAX_MCC_CMD - 1))
  141. ctrl->mcc_free_index = 0;
  142. else
  143. ctrl->mcc_free_index++;
  144. ctrl->mcc_tag_available++;
  145. mccq->used--;
  146. spin_unlock(&ctrl->mcc_lock);
  147. }
  148. /*
  149. * beiscsi_mcc_compl_status - Return the status of MCC completion
  150. * @phba: Driver private structure
  151. * @tag: Tag for the MBX Command
  152. * @wrb: the WRB used for the MBX Command
  153. * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
  154. *
  155. * return
  156. * Success: 0
  157. * Failure: Non-Zero
  158. */
  159. int __beiscsi_mcc_compl_status(struct beiscsi_hba *phba,
  160. unsigned int tag,
  161. struct be_mcc_wrb **wrb,
  162. struct be_dma_mem *mbx_cmd_mem)
  163. {
  164. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  165. uint16_t status = 0, addl_status = 0, wrb_num = 0;
  166. struct be_cmd_resp_hdr *mbx_resp_hdr;
  167. struct be_cmd_req_hdr *mbx_hdr;
  168. struct be_mcc_wrb *temp_wrb;
  169. uint32_t mcc_tag_status;
  170. int rc = 0;
  171. mcc_tag_status = phba->ctrl.mcc_tag_status[tag];
  172. status = (mcc_tag_status & CQE_STATUS_MASK);
  173. addl_status = ((mcc_tag_status & CQE_STATUS_ADDL_MASK) >>
  174. CQE_STATUS_ADDL_SHIFT);
  175. if (mbx_cmd_mem) {
  176. mbx_hdr = (struct be_cmd_req_hdr *)mbx_cmd_mem->va;
  177. } else {
  178. wrb_num = (mcc_tag_status & CQE_STATUS_WRB_MASK) >>
  179. CQE_STATUS_WRB_SHIFT;
  180. temp_wrb = (struct be_mcc_wrb *)queue_get_wrb(mccq, wrb_num);
  181. mbx_hdr = embedded_payload(temp_wrb);
  182. if (wrb)
  183. *wrb = temp_wrb;
  184. }
  185. if (status || addl_status) {
  186. beiscsi_log(phba, KERN_WARNING,
  187. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  188. BEISCSI_LOG_CONFIG,
  189. "BC_%d : MBX Cmd Failed for Subsys : %d Opcode : %d with Status : %d and Extd_Status : %d\n",
  190. mbx_hdr->subsystem, mbx_hdr->opcode,
  191. status, addl_status);
  192. rc = -EIO;
  193. if (status == MCC_STATUS_INSUFFICIENT_BUFFER) {
  194. mbx_resp_hdr = (struct be_cmd_resp_hdr *)mbx_hdr;
  195. beiscsi_log(phba, KERN_WARNING,
  196. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  197. BEISCSI_LOG_CONFIG,
  198. "BC_%d : Insufficient Buffer Error Resp_Len : %d Actual_Resp_Len : %d\n",
  199. mbx_resp_hdr->response_length,
  200. mbx_resp_hdr->actual_resp_len);
  201. rc = -EAGAIN;
  202. }
  203. }
  204. return rc;
  205. }
  206. /*
  207. * beiscsi_mccq_compl_wait()- Process completion in MCC CQ
  208. * @phba: Driver private structure
  209. * @tag: Tag for the MBX Command
  210. * @wrb: the WRB used for the MBX Command
  211. * @mbx_cmd_mem: ptr to memory allocated for MBX Cmd
  212. *
  213. * Waits for MBX completion with the passed TAG.
  214. *
  215. * return
  216. * Success: 0
  217. * Failure: Non-Zero
  218. **/
  219. int beiscsi_mccq_compl_wait(struct beiscsi_hba *phba,
  220. unsigned int tag,
  221. struct be_mcc_wrb **wrb,
  222. struct be_dma_mem *mbx_cmd_mem)
  223. {
  224. int rc = 0;
  225. if (!tag || tag > MAX_MCC_CMD) {
  226. __beiscsi_log(phba, KERN_ERR,
  227. "BC_%d : invalid tag %u\n", tag);
  228. return -EINVAL;
  229. }
  230. if (beiscsi_hba_in_error(phba)) {
  231. clear_bit(MCC_TAG_STATE_RUNNING,
  232. &phba->ctrl.ptag_state[tag].tag_state);
  233. return -EIO;
  234. }
  235. /* wait for the mccq completion */
  236. rc = wait_event_interruptible_timeout(phba->ctrl.mcc_wait[tag],
  237. phba->ctrl.mcc_tag_status[tag],
  238. msecs_to_jiffies(
  239. BEISCSI_HOST_MBX_TIMEOUT));
  240. /**
  241. * Return EIO if port is being disabled. Associated DMA memory, if any,
  242. * is freed by the caller. When port goes offline, MCCQ is cleaned up
  243. * so does WRB.
  244. */
  245. if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
  246. clear_bit(MCC_TAG_STATE_RUNNING,
  247. &phba->ctrl.ptag_state[tag].tag_state);
  248. return -EIO;
  249. }
  250. /**
  251. * If MBOX cmd timeout expired, tag and resource allocated
  252. * for cmd is not freed until FW returns completion.
  253. */
  254. if (rc <= 0) {
  255. struct be_dma_mem *tag_mem;
  256. /**
  257. * PCI/DMA memory allocated and posted in non-embedded mode
  258. * will have mbx_cmd_mem != NULL.
  259. * Save virtual and bus addresses for the command so that it
  260. * can be freed later.
  261. **/
  262. tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state;
  263. if (mbx_cmd_mem) {
  264. tag_mem->size = mbx_cmd_mem->size;
  265. tag_mem->va = mbx_cmd_mem->va;
  266. tag_mem->dma = mbx_cmd_mem->dma;
  267. } else
  268. tag_mem->size = 0;
  269. /* first make tag_mem_state visible to all */
  270. wmb();
  271. set_bit(MCC_TAG_STATE_TIMEOUT,
  272. &phba->ctrl.ptag_state[tag].tag_state);
  273. beiscsi_log(phba, KERN_ERR,
  274. BEISCSI_LOG_INIT | BEISCSI_LOG_EH |
  275. BEISCSI_LOG_CONFIG,
  276. "BC_%d : MBX Cmd Completion timed out\n");
  277. return -EBUSY;
  278. }
  279. rc = __beiscsi_mcc_compl_status(phba, tag, wrb, mbx_cmd_mem);
  280. free_mcc_wrb(&phba->ctrl, tag);
  281. return rc;
  282. }
  283. /*
  284. * beiscsi_process_mbox_compl()- Check the MBX completion status
  285. * @ctrl: Function specific MBX data structure
  286. * @compl: Completion status of MBX Command
  287. *
  288. * Check for the MBX completion status when BMBX method used
  289. *
  290. * return
  291. * Success: Zero
  292. * Failure: Non-Zero
  293. **/
  294. static int beiscsi_process_mbox_compl(struct be_ctrl_info *ctrl,
  295. struct be_mcc_compl *compl)
  296. {
  297. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  298. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  299. struct be_cmd_req_hdr *hdr = embedded_payload(wrb);
  300. u16 compl_status, extd_status;
  301. /**
  302. * To check if valid bit is set, check the entire word as we don't know
  303. * the endianness of the data (old entry is host endian while a new
  304. * entry is little endian)
  305. */
  306. if (!compl->flags) {
  307. beiscsi_log(phba, KERN_ERR,
  308. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  309. "BC_%d : BMBX busy, no completion\n");
  310. return -EBUSY;
  311. }
  312. compl->flags = le32_to_cpu(compl->flags);
  313. WARN_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
  314. /**
  315. * Just swap the status to host endian;
  316. * mcc tag is opaquely copied from mcc_wrb.
  317. */
  318. be_dws_le_to_cpu(compl, 4);
  319. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  320. CQE_STATUS_COMPL_MASK;
  321. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  322. CQE_STATUS_EXTD_MASK;
  323. /* Need to reset the entire word that houses the valid bit */
  324. compl->flags = 0;
  325. if (compl_status == MCC_STATUS_SUCCESS)
  326. return 0;
  327. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  328. "BC_%d : error in cmd completion: Subsystem : %d Opcode : %d status(compl/extd)=%d/%d\n",
  329. hdr->subsystem, hdr->opcode, compl_status, extd_status);
  330. return compl_status;
  331. }
  332. static void beiscsi_process_async_link(struct beiscsi_hba *phba,
  333. struct be_mcc_compl *compl)
  334. {
  335. struct be_async_event_link_state *evt;
  336. evt = (struct be_async_event_link_state *)compl;
  337. phba->port_speed = evt->port_speed;
  338. /**
  339. * Check logical link status in ASYNC event.
  340. * This has been newly introduced in SKH-R Firmware 10.0.338.45.
  341. **/
  342. if (evt->port_link_status & BE_ASYNC_LINK_UP_MASK) {
  343. set_bit(BEISCSI_HBA_LINK_UP, &phba->state);
  344. if (test_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state))
  345. beiscsi_start_boot_work(phba, BE_BOOT_INVALID_SHANDLE);
  346. __beiscsi_log(phba, KERN_ERR,
  347. "BC_%d : Link Up on Port %d tag 0x%x\n",
  348. evt->physical_port, evt->event_tag);
  349. } else {
  350. clear_bit(BEISCSI_HBA_LINK_UP, &phba->state);
  351. __beiscsi_log(phba, KERN_ERR,
  352. "BC_%d : Link Down on Port %d tag 0x%x\n",
  353. evt->physical_port, evt->event_tag);
  354. iscsi_host_for_each_session(phba->shost,
  355. beiscsi_session_fail);
  356. }
  357. }
  358. static char *beiscsi_port_misconf_event_msg[] = {
  359. "Physical Link is functional.",
  360. "Optics faulted/incorrectly installed/not installed - Reseat optics, if issue not resolved, replace.",
  361. "Optics of two types installed - Remove one optic or install matching pair of optics.",
  362. "Incompatible optics - Replace with compatible optics for card to function.",
  363. "Unqualified optics - Replace with Avago optics for Warranty and Technical Support.",
  364. "Uncertified optics - Replace with Avago Certified optics to enable link operation."
  365. };
  366. static void beiscsi_process_async_sli(struct beiscsi_hba *phba,
  367. struct be_mcc_compl *compl)
  368. {
  369. struct be_async_event_sli *async_sli;
  370. u8 evt_type, state, old_state, le;
  371. char *sev = KERN_WARNING;
  372. char *msg = NULL;
  373. evt_type = compl->flags >> ASYNC_TRAILER_EVENT_TYPE_SHIFT;
  374. evt_type &= ASYNC_TRAILER_EVENT_TYPE_MASK;
  375. /* processing only MISCONFIGURED physical port event */
  376. if (evt_type != ASYNC_SLI_EVENT_TYPE_MISCONFIGURED)
  377. return;
  378. async_sli = (struct be_async_event_sli *)compl;
  379. state = async_sli->event_data1 >>
  380. (phba->fw_config.phys_port * 8) & 0xff;
  381. le = async_sli->event_data2 >>
  382. (phba->fw_config.phys_port * 8) & 0xff;
  383. old_state = phba->optic_state;
  384. phba->optic_state = state;
  385. if (state >= ARRAY_SIZE(beiscsi_port_misconf_event_msg)) {
  386. /* fw is reporting a state we don't know, log and return */
  387. __beiscsi_log(phba, KERN_ERR,
  388. "BC_%d : Port %c: Unrecognized optic state 0x%x\n",
  389. phba->port_name, async_sli->event_data1);
  390. return;
  391. }
  392. if (ASYNC_SLI_LINK_EFFECT_VALID(le)) {
  393. /* log link effect for unqualified-4, uncertified-5 optics */
  394. if (state > 3)
  395. msg = (ASYNC_SLI_LINK_EFFECT_STATE(le)) ?
  396. " Link is non-operational." :
  397. " Link is operational.";
  398. /* 1 - info */
  399. if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 1)
  400. sev = KERN_INFO;
  401. /* 2 - error */
  402. if (ASYNC_SLI_LINK_EFFECT_SEV(le) == 2)
  403. sev = KERN_ERR;
  404. }
  405. if (old_state != phba->optic_state)
  406. __beiscsi_log(phba, sev, "BC_%d : Port %c: %s%s\n",
  407. phba->port_name,
  408. beiscsi_port_misconf_event_msg[state],
  409. !msg ? "" : msg);
  410. }
  411. void beiscsi_process_async_event(struct beiscsi_hba *phba,
  412. struct be_mcc_compl *compl)
  413. {
  414. char *sev = KERN_INFO;
  415. u8 evt_code;
  416. /* interpret flags as an async trailer */
  417. evt_code = compl->flags >> ASYNC_TRAILER_EVENT_CODE_SHIFT;
  418. evt_code &= ASYNC_TRAILER_EVENT_CODE_MASK;
  419. switch (evt_code) {
  420. case ASYNC_EVENT_CODE_LINK_STATE:
  421. beiscsi_process_async_link(phba, compl);
  422. break;
  423. case ASYNC_EVENT_CODE_ISCSI:
  424. if (test_bit(BEISCSI_HBA_BOOT_FOUND, &phba->state))
  425. beiscsi_start_boot_work(phba, BE_BOOT_INVALID_SHANDLE);
  426. sev = KERN_ERR;
  427. break;
  428. case ASYNC_EVENT_CODE_SLI:
  429. beiscsi_process_async_sli(phba, compl);
  430. break;
  431. default:
  432. /* event not registered */
  433. sev = KERN_ERR;
  434. }
  435. beiscsi_log(phba, sev, BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  436. "BC_%d : ASYNC Event %x: status 0x%08x flags 0x%08x\n",
  437. evt_code, compl->status, compl->flags);
  438. }
  439. int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl,
  440. struct be_mcc_compl *compl)
  441. {
  442. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  443. u16 compl_status, extd_status;
  444. struct be_dma_mem *tag_mem;
  445. unsigned int tag, wrb_idx;
  446. be_dws_le_to_cpu(compl, 4);
  447. tag = (compl->tag0 & MCC_Q_CMD_TAG_MASK);
  448. wrb_idx = (compl->tag0 & CQE_STATUS_WRB_MASK) >> CQE_STATUS_WRB_SHIFT;
  449. if (!test_bit(MCC_TAG_STATE_RUNNING,
  450. &ctrl->ptag_state[tag].tag_state)) {
  451. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_MBOX |
  452. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  453. "BC_%d : MBX cmd completed but not posted\n");
  454. return 0;
  455. }
  456. /* end MCC with this tag */
  457. clear_bit(MCC_TAG_STATE_RUNNING, &ctrl->ptag_state[tag].tag_state);
  458. if (test_bit(MCC_TAG_STATE_TIMEOUT, &ctrl->ptag_state[tag].tag_state)) {
  459. beiscsi_log(phba, KERN_WARNING,
  460. BEISCSI_LOG_MBOX | BEISCSI_LOG_INIT |
  461. BEISCSI_LOG_CONFIG,
  462. "BC_%d : MBX Completion for timeout Command from FW\n");
  463. /**
  464. * Check for the size before freeing resource.
  465. * Only for non-embedded cmd, PCI resource is allocated.
  466. **/
  467. tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
  468. if (tag_mem->size) {
  469. pci_free_consistent(ctrl->pdev, tag_mem->size,
  470. tag_mem->va, tag_mem->dma);
  471. tag_mem->size = 0;
  472. }
  473. free_mcc_wrb(ctrl, tag);
  474. return 0;
  475. }
  476. compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
  477. CQE_STATUS_COMPL_MASK;
  478. extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
  479. CQE_STATUS_EXTD_MASK;
  480. /* The ctrl.mcc_tag_status[tag] is filled with
  481. * [31] = valid, [30:24] = Rsvd, [23:16] = wrb, [15:8] = extd_status,
  482. * [7:0] = compl_status
  483. */
  484. ctrl->mcc_tag_status[tag] = CQE_VALID_MASK;
  485. ctrl->mcc_tag_status[tag] |= (wrb_idx << CQE_STATUS_WRB_SHIFT);
  486. ctrl->mcc_tag_status[tag] |= (extd_status << CQE_STATUS_ADDL_SHIFT) &
  487. CQE_STATUS_ADDL_MASK;
  488. ctrl->mcc_tag_status[tag] |= (compl_status & CQE_STATUS_MASK);
  489. if (test_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state)) {
  490. if (ctrl->ptag_state[tag].cbfn)
  491. ctrl->ptag_state[tag].cbfn(phba, tag);
  492. else
  493. __beiscsi_log(phba, KERN_ERR,
  494. "BC_%d : MBX ASYNC command with no callback\n");
  495. free_mcc_wrb(ctrl, tag);
  496. return 0;
  497. }
  498. if (test_bit(MCC_TAG_STATE_IGNORE, &ctrl->ptag_state[tag].tag_state)) {
  499. /* just check completion status and free wrb */
  500. __beiscsi_mcc_compl_status(phba, tag, NULL, NULL);
  501. free_mcc_wrb(ctrl, tag);
  502. return 0;
  503. }
  504. wake_up_interruptible(&ctrl->mcc_wait[tag]);
  505. return 0;
  506. }
  507. void be_mcc_notify(struct beiscsi_hba *phba, unsigned int tag)
  508. {
  509. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  510. u32 val = 0;
  511. set_bit(MCC_TAG_STATE_RUNNING, &phba->ctrl.ptag_state[tag].tag_state);
  512. val |= mccq->id & DB_MCCQ_RING_ID_MASK;
  513. val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
  514. /* make request available for DMA */
  515. wmb();
  516. iowrite32(val, phba->db_va + DB_MCCQ_OFFSET);
  517. }
  518. /*
  519. * be_mbox_db_ready_poll()- Check ready status
  520. * @ctrl: Function specific MBX data structure
  521. *
  522. * Check for the ready status of FW to send BMBX
  523. * commands to adapter.
  524. *
  525. * return
  526. * Success: 0
  527. * Failure: Non-Zero
  528. **/
  529. static int be_mbox_db_ready_poll(struct be_ctrl_info *ctrl)
  530. {
  531. /* wait 30s for generic non-flash MBOX operation */
  532. #define BEISCSI_MBX_RDY_BIT_TIMEOUT 30000
  533. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  534. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  535. unsigned long timeout;
  536. u32 ready;
  537. /*
  538. * This BMBX busy wait path is used during init only.
  539. * For the commands executed during init, 5s should suffice.
  540. */
  541. timeout = jiffies + msecs_to_jiffies(BEISCSI_MBX_RDY_BIT_TIMEOUT);
  542. do {
  543. if (beiscsi_hba_in_error(phba))
  544. return -EIO;
  545. ready = ioread32(db);
  546. if (ready == 0xffffffff)
  547. return -EIO;
  548. ready &= MPU_MAILBOX_DB_RDY_MASK;
  549. if (ready)
  550. return 0;
  551. if (time_after(jiffies, timeout))
  552. break;
  553. /* 1ms sleep is enough in most cases */
  554. schedule_timeout_uninterruptible(msecs_to_jiffies(1));
  555. } while (!ready);
  556. beiscsi_log(phba, KERN_ERR,
  557. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  558. "BC_%d : FW Timed Out\n");
  559. set_bit(BEISCSI_HBA_FW_TIMEOUT, &phba->state);
  560. return -EBUSY;
  561. }
  562. /*
  563. * be_mbox_notify: Notify adapter of new BMBX command
  564. * @ctrl: Function specific MBX data structure
  565. *
  566. * Ring doorbell to inform adapter of a BMBX command
  567. * to process
  568. *
  569. * return
  570. * Success: 0
  571. * Failure: Non-Zero
  572. **/
  573. static int be_mbox_notify(struct be_ctrl_info *ctrl)
  574. {
  575. int status;
  576. u32 val = 0;
  577. void __iomem *db = ctrl->db + MPU_MAILBOX_DB_OFFSET;
  578. struct be_dma_mem *mbox_mem = &ctrl->mbox_mem;
  579. struct be_mcc_mailbox *mbox = mbox_mem->va;
  580. status = be_mbox_db_ready_poll(ctrl);
  581. if (status)
  582. return status;
  583. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  584. val |= MPU_MAILBOX_DB_HI_MASK;
  585. val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
  586. iowrite32(val, db);
  587. status = be_mbox_db_ready_poll(ctrl);
  588. if (status)
  589. return status;
  590. val = 0;
  591. val &= ~MPU_MAILBOX_DB_RDY_MASK;
  592. val &= ~MPU_MAILBOX_DB_HI_MASK;
  593. val |= (u32) (mbox_mem->dma >> 4) << 2;
  594. iowrite32(val, db);
  595. status = be_mbox_db_ready_poll(ctrl);
  596. if (status)
  597. return status;
  598. /* RDY is set; small delay before CQE read. */
  599. udelay(1);
  600. status = beiscsi_process_mbox_compl(ctrl, &mbox->compl);
  601. return status;
  602. }
  603. void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
  604. bool embedded, u8 sge_cnt)
  605. {
  606. if (embedded)
  607. wrb->emb_sgecnt_special |= MCC_WRB_EMBEDDED_MASK;
  608. else
  609. wrb->emb_sgecnt_special |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
  610. MCC_WRB_SGE_CNT_SHIFT;
  611. wrb->payload_length = payload_len;
  612. be_dws_cpu_to_le(wrb, 8);
  613. }
  614. void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
  615. u8 subsystem, u8 opcode, int cmd_len)
  616. {
  617. req_hdr->opcode = opcode;
  618. req_hdr->subsystem = subsystem;
  619. req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
  620. req_hdr->timeout = BEISCSI_FW_MBX_TIMEOUT;
  621. }
  622. static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
  623. struct be_dma_mem *mem)
  624. {
  625. int i, buf_pages;
  626. u64 dma = (u64) mem->dma;
  627. buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
  628. for (i = 0; i < buf_pages; i++) {
  629. pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
  630. pages[i].hi = cpu_to_le32(upper_32_bits(dma));
  631. dma += PAGE_SIZE_4K;
  632. }
  633. }
  634. static u32 eq_delay_to_mult(u32 usec_delay)
  635. {
  636. #define MAX_INTR_RATE 651042
  637. const u32 round = 10;
  638. u32 multiplier;
  639. if (usec_delay == 0)
  640. multiplier = 0;
  641. else {
  642. u32 interrupt_rate = 1000000 / usec_delay;
  643. if (interrupt_rate == 0)
  644. multiplier = 1023;
  645. else {
  646. multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
  647. multiplier /= interrupt_rate;
  648. multiplier = (multiplier + round / 2) / round;
  649. multiplier = min(multiplier, (u32) 1023);
  650. }
  651. }
  652. return multiplier;
  653. }
  654. struct be_mcc_wrb *wrb_from_mbox(struct be_dma_mem *mbox_mem)
  655. {
  656. return &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
  657. }
  658. int beiscsi_cmd_eq_create(struct be_ctrl_info *ctrl,
  659. struct be_queue_info *eq, int eq_delay)
  660. {
  661. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  662. struct be_cmd_req_eq_create *req = embedded_payload(wrb);
  663. struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
  664. struct be_dma_mem *q_mem = &eq->dma_mem;
  665. int status;
  666. mutex_lock(&ctrl->mbox_lock);
  667. memset(wrb, 0, sizeof(*wrb));
  668. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  669. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  670. OPCODE_COMMON_EQ_CREATE, sizeof(*req));
  671. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  672. AMAP_SET_BITS(struct amap_eq_context, func, req->context,
  673. PCI_FUNC(ctrl->pdev->devfn));
  674. AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
  675. AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
  676. AMAP_SET_BITS(struct amap_eq_context, count, req->context,
  677. __ilog2_u32(eq->len / 256));
  678. AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
  679. eq_delay_to_mult(eq_delay));
  680. be_dws_cpu_to_le(req->context, sizeof(req->context));
  681. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  682. status = be_mbox_notify(ctrl);
  683. if (!status) {
  684. eq->id = le16_to_cpu(resp->eq_id);
  685. eq->created = true;
  686. }
  687. mutex_unlock(&ctrl->mbox_lock);
  688. return status;
  689. }
  690. int beiscsi_cmd_cq_create(struct be_ctrl_info *ctrl,
  691. struct be_queue_info *cq, struct be_queue_info *eq,
  692. bool sol_evts, bool no_delay, int coalesce_wm)
  693. {
  694. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  695. struct be_cmd_req_cq_create *req = embedded_payload(wrb);
  696. struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
  697. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  698. struct be_dma_mem *q_mem = &cq->dma_mem;
  699. void *ctxt = &req->context;
  700. int status;
  701. mutex_lock(&ctrl->mbox_lock);
  702. memset(wrb, 0, sizeof(*wrb));
  703. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  704. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  705. OPCODE_COMMON_CQ_CREATE, sizeof(*req));
  706. req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
  707. if (is_chip_be2_be3r(phba)) {
  708. AMAP_SET_BITS(struct amap_cq_context, coalescwm,
  709. ctxt, coalesce_wm);
  710. AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
  711. AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
  712. __ilog2_u32(cq->len / 256));
  713. AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
  714. AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
  715. AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
  716. AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
  717. AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
  718. AMAP_SET_BITS(struct amap_cq_context, func, ctxt,
  719. PCI_FUNC(ctrl->pdev->devfn));
  720. } else {
  721. req->hdr.version = MBX_CMD_VER2;
  722. req->page_size = 1;
  723. AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
  724. ctxt, coalesce_wm);
  725. AMAP_SET_BITS(struct amap_cq_context_v2, nodelay,
  726. ctxt, no_delay);
  727. AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
  728. __ilog2_u32(cq->len / 256));
  729. AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
  730. AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
  731. AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
  732. AMAP_SET_BITS(struct amap_cq_context_v2, armed, ctxt, 1);
  733. }
  734. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  735. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  736. status = be_mbox_notify(ctrl);
  737. if (!status) {
  738. cq->id = le16_to_cpu(resp->cq_id);
  739. cq->created = true;
  740. } else
  741. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  742. "BC_%d : In be_cmd_cq_create, status=ox%08x\n",
  743. status);
  744. mutex_unlock(&ctrl->mbox_lock);
  745. return status;
  746. }
  747. static u32 be_encoded_q_len(int q_len)
  748. {
  749. u32 len_encoded = fls(q_len); /* log2(len) + 1 */
  750. if (len_encoded == 16)
  751. len_encoded = 0;
  752. return len_encoded;
  753. }
  754. int beiscsi_cmd_mccq_create(struct beiscsi_hba *phba,
  755. struct be_queue_info *mccq,
  756. struct be_queue_info *cq)
  757. {
  758. struct be_mcc_wrb *wrb;
  759. struct be_cmd_req_mcc_create_ext *req;
  760. struct be_dma_mem *q_mem = &mccq->dma_mem;
  761. struct be_ctrl_info *ctrl;
  762. void *ctxt;
  763. int status;
  764. mutex_lock(&phba->ctrl.mbox_lock);
  765. ctrl = &phba->ctrl;
  766. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  767. memset(wrb, 0, sizeof(*wrb));
  768. req = embedded_payload(wrb);
  769. ctxt = &req->context;
  770. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  771. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  772. OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
  773. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  774. req->async_evt_bitmap = 1 << ASYNC_EVENT_CODE_LINK_STATE;
  775. req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_ISCSI;
  776. req->async_evt_bitmap |= 1 << ASYNC_EVENT_CODE_SLI;
  777. AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt,
  778. PCI_FUNC(phba->pcidev->devfn));
  779. AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
  780. AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
  781. be_encoded_q_len(mccq->len));
  782. AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
  783. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  784. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  785. status = be_mbox_notify(ctrl);
  786. if (!status) {
  787. struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
  788. mccq->id = le16_to_cpu(resp->id);
  789. mccq->created = true;
  790. }
  791. mutex_unlock(&phba->ctrl.mbox_lock);
  792. return status;
  793. }
  794. int beiscsi_cmd_q_destroy(struct be_ctrl_info *ctrl, struct be_queue_info *q,
  795. int queue_type)
  796. {
  797. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  798. struct be_cmd_req_q_destroy *req = embedded_payload(wrb);
  799. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  800. u8 subsys = 0, opcode = 0;
  801. int status;
  802. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  803. "BC_%d : In beiscsi_cmd_q_destroy "
  804. "queue_type : %d\n", queue_type);
  805. mutex_lock(&ctrl->mbox_lock);
  806. memset(wrb, 0, sizeof(*wrb));
  807. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  808. switch (queue_type) {
  809. case QTYPE_EQ:
  810. subsys = CMD_SUBSYSTEM_COMMON;
  811. opcode = OPCODE_COMMON_EQ_DESTROY;
  812. break;
  813. case QTYPE_CQ:
  814. subsys = CMD_SUBSYSTEM_COMMON;
  815. opcode = OPCODE_COMMON_CQ_DESTROY;
  816. break;
  817. case QTYPE_MCCQ:
  818. subsys = CMD_SUBSYSTEM_COMMON;
  819. opcode = OPCODE_COMMON_MCC_DESTROY;
  820. break;
  821. case QTYPE_WRBQ:
  822. subsys = CMD_SUBSYSTEM_ISCSI;
  823. opcode = OPCODE_COMMON_ISCSI_WRBQ_DESTROY;
  824. break;
  825. case QTYPE_DPDUQ:
  826. subsys = CMD_SUBSYSTEM_ISCSI;
  827. opcode = OPCODE_COMMON_ISCSI_DEFQ_DESTROY;
  828. break;
  829. case QTYPE_SGL:
  830. subsys = CMD_SUBSYSTEM_ISCSI;
  831. opcode = OPCODE_COMMON_ISCSI_CFG_REMOVE_SGL_PAGES;
  832. break;
  833. default:
  834. mutex_unlock(&ctrl->mbox_lock);
  835. BUG();
  836. return -ENXIO;
  837. }
  838. be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
  839. if (queue_type != QTYPE_SGL)
  840. req->id = cpu_to_le16(q->id);
  841. status = be_mbox_notify(ctrl);
  842. mutex_unlock(&ctrl->mbox_lock);
  843. return status;
  844. }
  845. /**
  846. * be_cmd_create_default_pdu_queue()- Create DEFQ for the adapter
  847. * @ctrl: ptr to ctrl_info
  848. * @cq: Completion Queue
  849. * @dq: Default Queue
  850. * @lenght: ring size
  851. * @entry_size: size of each entry in DEFQ
  852. * @is_header: Header or Data DEFQ
  853. * @ulp_num: Bind to which ULP
  854. *
  855. * Create HDR/Data DEFQ for the passed ULP. Unsol PDU are posted
  856. * on this queue by the FW
  857. *
  858. * return
  859. * Success: 0
  860. * Failure: Non-Zero Value
  861. *
  862. **/
  863. int be_cmd_create_default_pdu_queue(struct be_ctrl_info *ctrl,
  864. struct be_queue_info *cq,
  865. struct be_queue_info *dq, int length,
  866. int entry_size, uint8_t is_header,
  867. uint8_t ulp_num)
  868. {
  869. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  870. struct be_defq_create_req *req = embedded_payload(wrb);
  871. struct be_dma_mem *q_mem = &dq->dma_mem;
  872. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  873. void *ctxt = &req->context;
  874. int status;
  875. mutex_lock(&ctrl->mbox_lock);
  876. memset(wrb, 0, sizeof(*wrb));
  877. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  878. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  879. OPCODE_COMMON_ISCSI_DEFQ_CREATE, sizeof(*req));
  880. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  881. if (phba->fw_config.dual_ulp_aware) {
  882. req->ulp_num = ulp_num;
  883. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  884. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  885. }
  886. if (is_chip_be2_be3r(phba)) {
  887. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  888. rx_pdid, ctxt, 0);
  889. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  890. rx_pdid_valid, ctxt, 1);
  891. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  892. pci_func_id, ctxt, PCI_FUNC(ctrl->pdev->devfn));
  893. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  894. ring_size, ctxt,
  895. be_encoded_q_len(length /
  896. sizeof(struct phys_addr)));
  897. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  898. default_buffer_size, ctxt, entry_size);
  899. AMAP_SET_BITS(struct amap_be_default_pdu_context,
  900. cq_id_recv, ctxt, cq->id);
  901. } else {
  902. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  903. rx_pdid, ctxt, 0);
  904. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  905. rx_pdid_valid, ctxt, 1);
  906. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  907. ring_size, ctxt,
  908. be_encoded_q_len(length /
  909. sizeof(struct phys_addr)));
  910. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  911. default_buffer_size, ctxt, entry_size);
  912. AMAP_SET_BITS(struct amap_default_pdu_context_ext,
  913. cq_id_recv, ctxt, cq->id);
  914. }
  915. be_dws_cpu_to_le(ctxt, sizeof(req->context));
  916. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  917. status = be_mbox_notify(ctrl);
  918. if (!status) {
  919. struct be_ring *defq_ring;
  920. struct be_defq_create_resp *resp = embedded_payload(wrb);
  921. dq->id = le16_to_cpu(resp->id);
  922. dq->created = true;
  923. if (is_header)
  924. defq_ring = &phba->phwi_ctrlr->default_pdu_hdr[ulp_num];
  925. else
  926. defq_ring = &phba->phwi_ctrlr->
  927. default_pdu_data[ulp_num];
  928. defq_ring->id = dq->id;
  929. if (!phba->fw_config.dual_ulp_aware) {
  930. defq_ring->ulp_num = BEISCSI_ULP0;
  931. defq_ring->doorbell_offset = DB_RXULP0_OFFSET;
  932. } else {
  933. defq_ring->ulp_num = resp->ulp_num;
  934. defq_ring->doorbell_offset = resp->doorbell_offset;
  935. }
  936. }
  937. mutex_unlock(&ctrl->mbox_lock);
  938. return status;
  939. }
  940. /**
  941. * be_cmd_wrbq_create()- Create WRBQ
  942. * @ctrl: ptr to ctrl_info
  943. * @q_mem: memory details for the queue
  944. * @wrbq: queue info
  945. * @pwrb_context: ptr to wrb_context
  946. * @ulp_num: ULP on which the WRBQ is to be created
  947. *
  948. * Create WRBQ on the passed ULP_NUM.
  949. *
  950. **/
  951. int be_cmd_wrbq_create(struct be_ctrl_info *ctrl,
  952. struct be_dma_mem *q_mem,
  953. struct be_queue_info *wrbq,
  954. struct hwi_wrb_context *pwrb_context,
  955. uint8_t ulp_num)
  956. {
  957. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  958. struct be_wrbq_create_req *req = embedded_payload(wrb);
  959. struct be_wrbq_create_resp *resp = embedded_payload(wrb);
  960. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  961. int status;
  962. mutex_lock(&ctrl->mbox_lock);
  963. memset(wrb, 0, sizeof(*wrb));
  964. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  965. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  966. OPCODE_COMMON_ISCSI_WRBQ_CREATE, sizeof(*req));
  967. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  968. if (phba->fw_config.dual_ulp_aware) {
  969. req->ulp_num = ulp_num;
  970. req->dua_feature |= (1 << BEISCSI_DUAL_ULP_AWARE_BIT);
  971. req->dua_feature |= (1 << BEISCSI_BIND_Q_TO_ULP_BIT);
  972. }
  973. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  974. status = be_mbox_notify(ctrl);
  975. if (!status) {
  976. wrbq->id = le16_to_cpu(resp->cid);
  977. wrbq->created = true;
  978. pwrb_context->cid = wrbq->id;
  979. if (!phba->fw_config.dual_ulp_aware) {
  980. pwrb_context->doorbell_offset = DB_TXULP0_OFFSET;
  981. pwrb_context->ulp_num = BEISCSI_ULP0;
  982. } else {
  983. pwrb_context->ulp_num = resp->ulp_num;
  984. pwrb_context->doorbell_offset = resp->doorbell_offset;
  985. }
  986. }
  987. mutex_unlock(&ctrl->mbox_lock);
  988. return status;
  989. }
  990. int be_cmd_iscsi_post_template_hdr(struct be_ctrl_info *ctrl,
  991. struct be_dma_mem *q_mem)
  992. {
  993. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  994. struct be_post_template_pages_req *req = embedded_payload(wrb);
  995. int status;
  996. mutex_lock(&ctrl->mbox_lock);
  997. memset(wrb, 0, sizeof(*wrb));
  998. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  999. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1000. OPCODE_COMMON_ADD_TEMPLATE_HEADER_BUFFERS,
  1001. sizeof(*req));
  1002. req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
  1003. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1004. be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
  1005. status = be_mbox_notify(ctrl);
  1006. mutex_unlock(&ctrl->mbox_lock);
  1007. return status;
  1008. }
  1009. int be_cmd_iscsi_remove_template_hdr(struct be_ctrl_info *ctrl)
  1010. {
  1011. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1012. struct be_remove_template_pages_req *req = embedded_payload(wrb);
  1013. int status;
  1014. mutex_lock(&ctrl->mbox_lock);
  1015. memset(wrb, 0, sizeof(*wrb));
  1016. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1017. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1018. OPCODE_COMMON_REMOVE_TEMPLATE_HEADER_BUFFERS,
  1019. sizeof(*req));
  1020. req->type = BEISCSI_TEMPLATE_HDR_TYPE_ISCSI;
  1021. status = be_mbox_notify(ctrl);
  1022. mutex_unlock(&ctrl->mbox_lock);
  1023. return status;
  1024. }
  1025. int be_cmd_iscsi_post_sgl_pages(struct be_ctrl_info *ctrl,
  1026. struct be_dma_mem *q_mem,
  1027. u32 page_offset, u32 num_pages)
  1028. {
  1029. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1030. struct be_post_sgl_pages_req *req = embedded_payload(wrb);
  1031. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1032. int status;
  1033. unsigned int curr_pages;
  1034. u32 internal_page_offset = 0;
  1035. u32 temp_num_pages = num_pages;
  1036. if (num_pages == 0xff)
  1037. num_pages = 1;
  1038. mutex_lock(&ctrl->mbox_lock);
  1039. do {
  1040. memset(wrb, 0, sizeof(*wrb));
  1041. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1042. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1043. OPCODE_COMMON_ISCSI_CFG_POST_SGL_PAGES,
  1044. sizeof(*req));
  1045. curr_pages = BE_NUMBER_OF_FIELD(struct be_post_sgl_pages_req,
  1046. pages);
  1047. req->num_pages = min(num_pages, curr_pages);
  1048. req->page_offset = page_offset;
  1049. be_cmd_page_addrs_prepare(req->pages, req->num_pages, q_mem);
  1050. q_mem->dma = q_mem->dma + (req->num_pages * PAGE_SIZE);
  1051. internal_page_offset += req->num_pages;
  1052. page_offset += req->num_pages;
  1053. num_pages -= req->num_pages;
  1054. if (temp_num_pages == 0xff)
  1055. req->num_pages = temp_num_pages;
  1056. status = be_mbox_notify(ctrl);
  1057. if (status) {
  1058. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1059. "BC_%d : FW CMD to map iscsi frags failed.\n");
  1060. goto error;
  1061. }
  1062. } while (num_pages > 0);
  1063. error:
  1064. mutex_unlock(&ctrl->mbox_lock);
  1065. if (status != 0)
  1066. beiscsi_cmd_q_destroy(ctrl, NULL, QTYPE_SGL);
  1067. return status;
  1068. }
  1069. /**
  1070. * be_cmd_set_vlan()- Configure VLAN paramters on the adapter
  1071. * @phba: device priv structure instance
  1072. * @vlan_tag: TAG to be set
  1073. *
  1074. * Set the VLAN_TAG for the adapter or Disable VLAN on adapter
  1075. *
  1076. * returns
  1077. * TAG for the MBX Cmd
  1078. * **/
  1079. int be_cmd_set_vlan(struct beiscsi_hba *phba,
  1080. uint16_t vlan_tag)
  1081. {
  1082. unsigned int tag;
  1083. struct be_mcc_wrb *wrb;
  1084. struct be_cmd_set_vlan_req *req;
  1085. struct be_ctrl_info *ctrl = &phba->ctrl;
  1086. if (mutex_lock_interruptible(&ctrl->mbox_lock))
  1087. return 0;
  1088. wrb = alloc_mcc_wrb(phba, &tag);
  1089. if (!wrb) {
  1090. mutex_unlock(&ctrl->mbox_lock);
  1091. return 0;
  1092. }
  1093. req = embedded_payload(wrb);
  1094. be_wrb_hdr_prepare(wrb, sizeof(*wrb), true, 0);
  1095. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1096. OPCODE_COMMON_ISCSI_NTWK_SET_VLAN,
  1097. sizeof(*req));
  1098. req->interface_hndl = phba->interface_handle;
  1099. req->vlan_priority = vlan_tag;
  1100. be_mcc_notify(phba, tag);
  1101. mutex_unlock(&ctrl->mbox_lock);
  1102. return tag;
  1103. }
  1104. int beiscsi_check_supported_fw(struct be_ctrl_info *ctrl,
  1105. struct beiscsi_hba *phba)
  1106. {
  1107. struct be_dma_mem nonemb_cmd;
  1108. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1109. struct be_mgmt_controller_attributes *req;
  1110. struct be_sge *sge = nonembedded_sgl(wrb);
  1111. int status = 0;
  1112. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  1113. sizeof(struct be_mgmt_controller_attributes),
  1114. &nonemb_cmd.dma);
  1115. if (nonemb_cmd.va == NULL) {
  1116. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1117. "BG_%d : pci_alloc_consistent failed in %s\n",
  1118. __func__);
  1119. return -ENOMEM;
  1120. }
  1121. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  1122. req = nonemb_cmd.va;
  1123. memset(req, 0, sizeof(*req));
  1124. mutex_lock(&ctrl->mbox_lock);
  1125. memset(wrb, 0, sizeof(*wrb));
  1126. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  1127. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1128. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  1129. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  1130. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  1131. sge->len = cpu_to_le32(nonemb_cmd.size);
  1132. status = be_mbox_notify(ctrl);
  1133. if (!status) {
  1134. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  1135. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1136. "BG_%d : Firmware Version of CMD : %s\n"
  1137. "Firmware Version is : %s\n"
  1138. "Developer Build, not performing version check...\n",
  1139. resp->params.hba_attribs
  1140. .flashrom_version_string,
  1141. resp->params.hba_attribs.
  1142. firmware_version_string);
  1143. phba->fw_config.iscsi_features =
  1144. resp->params.hba_attribs.iscsi_features;
  1145. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1146. "BM_%d : phba->fw_config.iscsi_features = %d\n",
  1147. phba->fw_config.iscsi_features);
  1148. memcpy(phba->fw_ver_str, resp->params.hba_attribs.
  1149. firmware_version_string, BEISCSI_VER_STRLEN);
  1150. } else
  1151. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1152. "BG_%d : Failed in beiscsi_check_supported_fw\n");
  1153. mutex_unlock(&ctrl->mbox_lock);
  1154. if (nonemb_cmd.va)
  1155. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  1156. nonemb_cmd.va, nonemb_cmd.dma);
  1157. return status;
  1158. }
  1159. /**
  1160. * beiscsi_get_fw_config()- Get the FW config for the function
  1161. * @ctrl: ptr to Ctrl Info
  1162. * @phba: ptr to the dev priv structure
  1163. *
  1164. * Get the FW config and resources available for the function.
  1165. * The resources are created based on the count received here.
  1166. *
  1167. * return
  1168. * Success: 0
  1169. * Failure: Non-Zero Value
  1170. **/
  1171. int beiscsi_get_fw_config(struct be_ctrl_info *ctrl,
  1172. struct beiscsi_hba *phba)
  1173. {
  1174. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1175. struct be_fw_cfg *pfw_cfg = embedded_payload(wrb);
  1176. uint32_t cid_count, icd_count;
  1177. int status = -EINVAL;
  1178. uint8_t ulp_num = 0;
  1179. mutex_lock(&ctrl->mbox_lock);
  1180. memset(wrb, 0, sizeof(*wrb));
  1181. be_wrb_hdr_prepare(wrb, sizeof(*pfw_cfg), true, 0);
  1182. be_cmd_hdr_prepare(&pfw_cfg->hdr, CMD_SUBSYSTEM_COMMON,
  1183. OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
  1184. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1185. if (be_mbox_notify(ctrl)) {
  1186. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1187. "BG_%d : Failed in beiscsi_get_fw_config\n");
  1188. goto fail_init;
  1189. }
  1190. /* FW response formats depend on port id */
  1191. phba->fw_config.phys_port = pfw_cfg->phys_port;
  1192. if (phba->fw_config.phys_port >= BEISCSI_PHYS_PORT_MAX) {
  1193. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1194. "BG_%d : invalid physical port id %d\n",
  1195. phba->fw_config.phys_port);
  1196. goto fail_init;
  1197. }
  1198. /* populate and check FW config against min and max values */
  1199. if (!is_chip_be2_be3r(phba)) {
  1200. phba->fw_config.eqid_count = pfw_cfg->eqid_count;
  1201. phba->fw_config.cqid_count = pfw_cfg->cqid_count;
  1202. if (phba->fw_config.eqid_count == 0 ||
  1203. phba->fw_config.eqid_count > 2048) {
  1204. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1205. "BG_%d : invalid EQ count %d\n",
  1206. phba->fw_config.eqid_count);
  1207. goto fail_init;
  1208. }
  1209. if (phba->fw_config.cqid_count == 0 ||
  1210. phba->fw_config.cqid_count > 4096) {
  1211. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1212. "BG_%d : invalid CQ count %d\n",
  1213. phba->fw_config.cqid_count);
  1214. goto fail_init;
  1215. }
  1216. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1217. "BG_%d : EQ_Count : %d CQ_Count : %d\n",
  1218. phba->fw_config.eqid_count,
  1219. phba->fw_config.cqid_count);
  1220. }
  1221. /**
  1222. * Check on which all ULP iSCSI Protocol is loaded.
  1223. * Set the Bit for those ULP. This set flag is used
  1224. * at all places in the code to check on which ULP
  1225. * iSCSi Protocol is loaded
  1226. **/
  1227. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
  1228. if (pfw_cfg->ulp[ulp_num].ulp_mode &
  1229. BEISCSI_ULP_ISCSI_INI_MODE) {
  1230. set_bit(ulp_num, &phba->fw_config.ulp_supported);
  1231. /* Get the CID, ICD and Chain count for each ULP */
  1232. phba->fw_config.iscsi_cid_start[ulp_num] =
  1233. pfw_cfg->ulp[ulp_num].sq_base;
  1234. phba->fw_config.iscsi_cid_count[ulp_num] =
  1235. pfw_cfg->ulp[ulp_num].sq_count;
  1236. phba->fw_config.iscsi_icd_start[ulp_num] =
  1237. pfw_cfg->ulp[ulp_num].icd_base;
  1238. phba->fw_config.iscsi_icd_count[ulp_num] =
  1239. pfw_cfg->ulp[ulp_num].icd_count;
  1240. phba->fw_config.iscsi_chain_start[ulp_num] =
  1241. pfw_cfg->chain_icd[ulp_num].chain_base;
  1242. phba->fw_config.iscsi_chain_count[ulp_num] =
  1243. pfw_cfg->chain_icd[ulp_num].chain_count;
  1244. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1245. "BG_%d : Function loaded on ULP : %d\n"
  1246. "\tiscsi_cid_count : %d\n"
  1247. "\tiscsi_cid_start : %d\n"
  1248. "\t iscsi_icd_count : %d\n"
  1249. "\t iscsi_icd_start : %d\n",
  1250. ulp_num,
  1251. phba->fw_config.
  1252. iscsi_cid_count[ulp_num],
  1253. phba->fw_config.
  1254. iscsi_cid_start[ulp_num],
  1255. phba->fw_config.
  1256. iscsi_icd_count[ulp_num],
  1257. phba->fw_config.
  1258. iscsi_icd_start[ulp_num]);
  1259. }
  1260. }
  1261. if (phba->fw_config.ulp_supported == 0) {
  1262. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1263. "BG_%d : iSCSI initiator mode not set: ULP0 %x ULP1 %x\n",
  1264. pfw_cfg->ulp[BEISCSI_ULP0].ulp_mode,
  1265. pfw_cfg->ulp[BEISCSI_ULP1].ulp_mode);
  1266. goto fail_init;
  1267. }
  1268. /**
  1269. * ICD is shared among ULPs. Use icd_count of any one loaded ULP
  1270. **/
  1271. for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
  1272. if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
  1273. break;
  1274. icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
  1275. if (icd_count == 0 || icd_count > 65536) {
  1276. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1277. "BG_%d: invalid ICD count %d\n", icd_count);
  1278. goto fail_init;
  1279. }
  1280. cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
  1281. BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
  1282. if (cid_count == 0 || cid_count > 4096) {
  1283. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1284. "BG_%d: invalid CID count %d\n", cid_count);
  1285. goto fail_init;
  1286. }
  1287. /**
  1288. * Check FW is dual ULP aware i.e. can handle either
  1289. * of the protocols.
  1290. */
  1291. phba->fw_config.dual_ulp_aware = (pfw_cfg->function_mode &
  1292. BEISCSI_FUNC_DUA_MODE);
  1293. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1294. "BG_%d : DUA Mode : 0x%x\n",
  1295. phba->fw_config.dual_ulp_aware);
  1296. /* all set, continue using this FW config */
  1297. status = 0;
  1298. fail_init:
  1299. mutex_unlock(&ctrl->mbox_lock);
  1300. return status;
  1301. }
  1302. /**
  1303. * beiscsi_get_port_name()- Get port name for the function
  1304. * @ctrl: ptr to Ctrl Info
  1305. * @phba: ptr to the dev priv structure
  1306. *
  1307. * Get the alphanumeric character for port
  1308. *
  1309. **/
  1310. int beiscsi_get_port_name(struct be_ctrl_info *ctrl, struct beiscsi_hba *phba)
  1311. {
  1312. int ret = 0;
  1313. struct be_mcc_wrb *wrb;
  1314. struct be_cmd_get_port_name *ioctl;
  1315. mutex_lock(&ctrl->mbox_lock);
  1316. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1317. memset(wrb, 0, sizeof(*wrb));
  1318. ioctl = embedded_payload(wrb);
  1319. be_wrb_hdr_prepare(wrb, sizeof(*ioctl), true, 0);
  1320. be_cmd_hdr_prepare(&ioctl->h.req_hdr, CMD_SUBSYSTEM_COMMON,
  1321. OPCODE_COMMON_GET_PORT_NAME,
  1322. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1323. ret = be_mbox_notify(ctrl);
  1324. phba->port_name = 0;
  1325. if (!ret) {
  1326. phba->port_name = ioctl->p.resp.port_names >>
  1327. (phba->fw_config.phys_port * 8) & 0xff;
  1328. } else {
  1329. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1330. "BG_%d : GET_PORT_NAME ret 0x%x status 0x%x\n",
  1331. ret, ioctl->h.resp_hdr.status);
  1332. }
  1333. if (phba->port_name == 0)
  1334. phba->port_name = '?';
  1335. mutex_unlock(&ctrl->mbox_lock);
  1336. return ret;
  1337. }
  1338. int beiscsi_set_uer_feature(struct beiscsi_hba *phba)
  1339. {
  1340. struct be_ctrl_info *ctrl = &phba->ctrl;
  1341. struct be_cmd_set_features *ioctl;
  1342. struct be_mcc_wrb *wrb;
  1343. int ret = 0;
  1344. mutex_lock(&ctrl->mbox_lock);
  1345. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1346. memset(wrb, 0, sizeof(*wrb));
  1347. ioctl = embedded_payload(wrb);
  1348. be_wrb_hdr_prepare(wrb, sizeof(*ioctl), true, 0);
  1349. be_cmd_hdr_prepare(&ioctl->h.req_hdr, CMD_SUBSYSTEM_COMMON,
  1350. OPCODE_COMMON_SET_FEATURES,
  1351. EMBED_MBX_MAX_PAYLOAD_SIZE);
  1352. ioctl->feature = BE_CMD_SET_FEATURE_UER;
  1353. ioctl->param_len = sizeof(ioctl->param.req);
  1354. ioctl->param.req.uer = BE_CMD_UER_SUPP_BIT;
  1355. ret = be_mbox_notify(ctrl);
  1356. if (!ret) {
  1357. phba->ue2rp = ioctl->param.resp.ue2rp;
  1358. set_bit(BEISCSI_HBA_UER_SUPP, &phba->state);
  1359. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1360. "BG_%d : HBA error recovery supported\n");
  1361. } else {
  1362. /**
  1363. * Check "MCC_STATUS_INVALID_LENGTH" for SKH.
  1364. * Older FW versions return this error.
  1365. */
  1366. if (ret == MCC_STATUS_ILLEGAL_REQUEST ||
  1367. ret == MCC_STATUS_INVALID_LENGTH)
  1368. __beiscsi_log(phba, KERN_INFO,
  1369. "BG_%d : HBA error recovery not supported\n");
  1370. }
  1371. mutex_unlock(&ctrl->mbox_lock);
  1372. return ret;
  1373. }
  1374. static u32 beiscsi_get_post_stage(struct beiscsi_hba *phba)
  1375. {
  1376. u32 sem;
  1377. if (is_chip_be2_be3r(phba))
  1378. sem = ioread32(phba->csr_va + SLIPORT_SEMAPHORE_OFFSET_BEx);
  1379. else
  1380. pci_read_config_dword(phba->pcidev,
  1381. SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
  1382. return sem;
  1383. }
  1384. int beiscsi_check_fw_rdy(struct beiscsi_hba *phba)
  1385. {
  1386. u32 loop, post, rdy = 0;
  1387. loop = 1000;
  1388. while (loop--) {
  1389. post = beiscsi_get_post_stage(phba);
  1390. if (post & POST_ERROR_BIT)
  1391. break;
  1392. if ((post & POST_STAGE_MASK) == POST_STAGE_ARMFW_RDY) {
  1393. rdy = 1;
  1394. break;
  1395. }
  1396. msleep(60);
  1397. }
  1398. if (!rdy) {
  1399. __beiscsi_log(phba, KERN_ERR,
  1400. "BC_%d : FW not ready 0x%x\n", post);
  1401. }
  1402. return rdy;
  1403. }
  1404. int beiscsi_cmd_function_reset(struct beiscsi_hba *phba)
  1405. {
  1406. struct be_ctrl_info *ctrl = &phba->ctrl;
  1407. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1408. struct be_post_sgl_pages_req *req;
  1409. int status;
  1410. mutex_lock(&ctrl->mbox_lock);
  1411. req = embedded_payload(wrb);
  1412. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1413. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  1414. OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
  1415. status = be_mbox_notify(ctrl);
  1416. mutex_unlock(&ctrl->mbox_lock);
  1417. return status;
  1418. }
  1419. int beiscsi_cmd_special_wrb(struct be_ctrl_info *ctrl, u32 load)
  1420. {
  1421. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1422. struct beiscsi_hba *phba = pci_get_drvdata(ctrl->pdev);
  1423. u8 *endian_check;
  1424. int status;
  1425. mutex_lock(&ctrl->mbox_lock);
  1426. memset(wrb, 0, sizeof(*wrb));
  1427. endian_check = (u8 *) wrb;
  1428. if (load) {
  1429. /* to start communicating */
  1430. *endian_check++ = 0xFF;
  1431. *endian_check++ = 0x12;
  1432. *endian_check++ = 0x34;
  1433. *endian_check++ = 0xFF;
  1434. *endian_check++ = 0xFF;
  1435. *endian_check++ = 0x56;
  1436. *endian_check++ = 0x78;
  1437. *endian_check++ = 0xFF;
  1438. } else {
  1439. /* to stop communicating */
  1440. *endian_check++ = 0xFF;
  1441. *endian_check++ = 0xAA;
  1442. *endian_check++ = 0xBB;
  1443. *endian_check++ = 0xFF;
  1444. *endian_check++ = 0xFF;
  1445. *endian_check++ = 0xCC;
  1446. *endian_check++ = 0xDD;
  1447. *endian_check = 0xFF;
  1448. }
  1449. be_dws_cpu_to_le(wrb, sizeof(*wrb));
  1450. status = be_mbox_notify(ctrl);
  1451. if (status)
  1452. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  1453. "BC_%d : special WRB message failed\n");
  1454. mutex_unlock(&ctrl->mbox_lock);
  1455. return status;
  1456. }
  1457. int beiscsi_init_sliport(struct beiscsi_hba *phba)
  1458. {
  1459. int status;
  1460. /* check POST stage before talking to FW */
  1461. status = beiscsi_check_fw_rdy(phba);
  1462. if (!status)
  1463. return -EIO;
  1464. /* clear all error states after checking FW rdy */
  1465. phba->state &= ~BEISCSI_HBA_IN_ERR;
  1466. /* check again UER support */
  1467. phba->state &= ~BEISCSI_HBA_UER_SUPP;
  1468. /*
  1469. * SLI COMMON_FUNCTION_RESET completion is indicated by BMBX RDY bit.
  1470. * It should clean up any stale info in FW for this fn.
  1471. */
  1472. status = beiscsi_cmd_function_reset(phba);
  1473. if (status) {
  1474. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  1475. "BC_%d : SLI Function Reset failed\n");
  1476. return status;
  1477. }
  1478. /* indicate driver is loading */
  1479. return beiscsi_cmd_special_wrb(&phba->ctrl, 1);
  1480. }
  1481. /**
  1482. * beiscsi_cmd_iscsi_cleanup()- Inform FW to cleanup EP data structures.
  1483. * @phba: pointer to dev priv structure
  1484. * @ulp: ULP number.
  1485. *
  1486. * return
  1487. * Success: 0
  1488. * Failure: Non-Zero Value
  1489. **/
  1490. int beiscsi_cmd_iscsi_cleanup(struct beiscsi_hba *phba, unsigned short ulp)
  1491. {
  1492. struct be_ctrl_info *ctrl = &phba->ctrl;
  1493. struct iscsi_cleanup_req_v1 *req_v1;
  1494. struct iscsi_cleanup_req *req;
  1495. u16 hdr_ring_id, data_ring_id;
  1496. struct be_mcc_wrb *wrb;
  1497. int status;
  1498. mutex_lock(&ctrl->mbox_lock);
  1499. wrb = wrb_from_mbox(&ctrl->mbox_mem);
  1500. hdr_ring_id = HWI_GET_DEF_HDRQ_ID(phba, ulp);
  1501. data_ring_id = HWI_GET_DEF_BUFQ_ID(phba, ulp);
  1502. if (is_chip_be2_be3r(phba)) {
  1503. req = embedded_payload(wrb);
  1504. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  1505. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  1506. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  1507. req->chute = (1 << ulp);
  1508. /* BE2/BE3 FW creates 8-bit ring id */
  1509. req->hdr_ring_id = hdr_ring_id;
  1510. req->data_ring_id = data_ring_id;
  1511. } else {
  1512. req_v1 = embedded_payload(wrb);
  1513. be_wrb_hdr_prepare(wrb, sizeof(*req_v1), true, 0);
  1514. be_cmd_hdr_prepare(&req_v1->hdr, CMD_SUBSYSTEM_ISCSI,
  1515. OPCODE_COMMON_ISCSI_CLEANUP,
  1516. sizeof(*req_v1));
  1517. req_v1->hdr.version = 1;
  1518. req_v1->chute = (1 << ulp);
  1519. req_v1->hdr_ring_id = cpu_to_le16(hdr_ring_id);
  1520. req_v1->data_ring_id = cpu_to_le16(data_ring_id);
  1521. }
  1522. status = be_mbox_notify(ctrl);
  1523. if (status)
  1524. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  1525. "BG_%d : %s failed %d\n", __func__, ulp);
  1526. mutex_unlock(&ctrl->mbox_lock);
  1527. return status;
  1528. }
  1529. /*
  1530. * beiscsi_detect_ue()- Detect Unrecoverable Error on adapter
  1531. * @phba: Driver priv structure
  1532. *
  1533. * Read registers linked to UE and check for the UE status
  1534. **/
  1535. int beiscsi_detect_ue(struct beiscsi_hba *phba)
  1536. {
  1537. uint32_t ue_mask_hi = 0, ue_mask_lo = 0;
  1538. uint32_t ue_hi = 0, ue_lo = 0;
  1539. uint8_t i = 0;
  1540. int ret = 0;
  1541. pci_read_config_dword(phba->pcidev,
  1542. PCICFG_UE_STATUS_LOW, &ue_lo);
  1543. pci_read_config_dword(phba->pcidev,
  1544. PCICFG_UE_STATUS_MASK_LOW,
  1545. &ue_mask_lo);
  1546. pci_read_config_dword(phba->pcidev,
  1547. PCICFG_UE_STATUS_HIGH,
  1548. &ue_hi);
  1549. pci_read_config_dword(phba->pcidev,
  1550. PCICFG_UE_STATUS_MASK_HI,
  1551. &ue_mask_hi);
  1552. ue_lo = (ue_lo & ~ue_mask_lo);
  1553. ue_hi = (ue_hi & ~ue_mask_hi);
  1554. if (ue_lo || ue_hi) {
  1555. set_bit(BEISCSI_HBA_IN_UE, &phba->state);
  1556. __beiscsi_log(phba, KERN_ERR,
  1557. "BC_%d : HBA error detected\n");
  1558. ret = 1;
  1559. }
  1560. if (ue_lo) {
  1561. for (i = 0; ue_lo; ue_lo >>= 1, i++) {
  1562. if (ue_lo & 1)
  1563. __beiscsi_log(phba, KERN_ERR,
  1564. "BC_%d : UE_LOW %s bit set\n",
  1565. desc_ue_status_low[i]);
  1566. }
  1567. }
  1568. if (ue_hi) {
  1569. for (i = 0; ue_hi; ue_hi >>= 1, i++) {
  1570. if (ue_hi & 1)
  1571. __beiscsi_log(phba, KERN_ERR,
  1572. "BC_%d : UE_HIGH %s bit set\n",
  1573. desc_ue_status_hi[i]);
  1574. }
  1575. }
  1576. return ret;
  1577. }
  1578. /*
  1579. * beiscsi_detect_tpe()- Detect Transient Parity Error on adapter
  1580. * @phba: Driver priv structure
  1581. *
  1582. * Read SLIPORT SEMAPHORE register to check for UER
  1583. *
  1584. **/
  1585. int beiscsi_detect_tpe(struct beiscsi_hba *phba)
  1586. {
  1587. u32 post, status;
  1588. int ret = 0;
  1589. post = beiscsi_get_post_stage(phba);
  1590. status = post & POST_STAGE_MASK;
  1591. if ((status & POST_ERR_RECOVERY_CODE_MASK) ==
  1592. POST_STAGE_RECOVERABLE_ERR) {
  1593. set_bit(BEISCSI_HBA_IN_TPE, &phba->state);
  1594. __beiscsi_log(phba, KERN_INFO,
  1595. "BC_%d : HBA error recoverable: 0x%x\n", post);
  1596. ret = 1;
  1597. } else {
  1598. __beiscsi_log(phba, KERN_INFO,
  1599. "BC_%d : HBA in UE: 0x%x\n", post);
  1600. }
  1601. return ret;
  1602. }