qla_attr.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/slab.h>
  11. #include <linux/delay.h>
  12. static int qla24xx_vport_disable(struct fc_vport *, bool);
  13. /* SYSFS attributes --------------------------------------------------------- */
  14. static ssize_t
  15. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  16. struct bin_attribute *bin_attr,
  17. char *buf, loff_t off, size_t count)
  18. {
  19. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  20. struct device, kobj)));
  21. struct qla_hw_data *ha = vha->hw;
  22. int rval = 0;
  23. if (ha->fw_dump_reading == 0)
  24. return 0;
  25. if (IS_QLA82XX(ha)) {
  26. if (off < ha->md_template_size) {
  27. rval = memory_read_from_buffer(buf, count,
  28. &off, ha->md_tmplt_hdr, ha->md_template_size);
  29. return rval;
  30. }
  31. off -= ha->md_template_size;
  32. rval = memory_read_from_buffer(buf, count,
  33. &off, ha->md_dump, ha->md_dump_size);
  34. return rval;
  35. } else
  36. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  37. ha->fw_dump_len);
  38. }
  39. static ssize_t
  40. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  41. struct bin_attribute *bin_attr,
  42. char *buf, loff_t off, size_t count)
  43. {
  44. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  45. struct device, kobj)));
  46. struct qla_hw_data *ha = vha->hw;
  47. int reading;
  48. if (off != 0)
  49. return (0);
  50. reading = simple_strtol(buf, NULL, 10);
  51. switch (reading) {
  52. case 0:
  53. if (!ha->fw_dump_reading)
  54. break;
  55. ql_log(ql_log_info, vha, 0x705d,
  56. "Firmware dump cleared on (%ld).\n", vha->host_no);
  57. if (IS_QLA82XX(vha->hw)) {
  58. qla82xx_md_free(vha);
  59. qla82xx_md_prep(vha);
  60. }
  61. ha->fw_dump_reading = 0;
  62. ha->fw_dumped = 0;
  63. break;
  64. case 1:
  65. if (ha->fw_dumped && !ha->fw_dump_reading) {
  66. ha->fw_dump_reading = 1;
  67. ql_log(ql_log_info, vha, 0x705e,
  68. "Raw firmware dump ready for read on (%ld).\n",
  69. vha->host_no);
  70. }
  71. break;
  72. case 2:
  73. qla2x00_alloc_fw_dump(vha);
  74. break;
  75. case 3:
  76. if (IS_QLA82XX(ha)) {
  77. qla82xx_idc_lock(ha);
  78. qla82xx_set_reset_owner(vha);
  79. qla82xx_idc_unlock(ha);
  80. } else
  81. qla2x00_system_error(vha);
  82. break;
  83. case 4:
  84. if (IS_QLA82XX(ha)) {
  85. if (ha->md_tmplt_hdr)
  86. ql_dbg(ql_dbg_user, vha, 0x705b,
  87. "MiniDump supported with this firmware.\n");
  88. else
  89. ql_dbg(ql_dbg_user, vha, 0x709d,
  90. "MiniDump not supported with this firmware.\n");
  91. }
  92. break;
  93. case 5:
  94. if (IS_QLA82XX(ha))
  95. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  96. break;
  97. }
  98. return -EINVAL;
  99. }
  100. static struct bin_attribute sysfs_fw_dump_attr = {
  101. .attr = {
  102. .name = "fw_dump",
  103. .mode = S_IRUSR | S_IWUSR,
  104. },
  105. .size = 0,
  106. .read = qla2x00_sysfs_read_fw_dump,
  107. .write = qla2x00_sysfs_write_fw_dump,
  108. };
  109. static ssize_t
  110. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  111. struct bin_attribute *bin_attr,
  112. char *buf, loff_t off, size_t count)
  113. {
  114. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  115. struct device, kobj)));
  116. struct qla_hw_data *ha = vha->hw;
  117. if (!capable(CAP_SYS_ADMIN))
  118. return 0;
  119. if (IS_NOCACHE_VPD_TYPE(ha))
  120. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  121. ha->nvram_size);
  122. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  123. ha->nvram_size);
  124. }
  125. static ssize_t
  126. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  127. struct bin_attribute *bin_attr,
  128. char *buf, loff_t off, size_t count)
  129. {
  130. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  131. struct device, kobj)));
  132. struct qla_hw_data *ha = vha->hw;
  133. uint16_t cnt;
  134. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  135. !ha->isp_ops->write_nvram)
  136. return -EINVAL;
  137. /* Checksum NVRAM. */
  138. if (IS_FWI2_CAPABLE(ha)) {
  139. uint32_t *iter;
  140. uint32_t chksum;
  141. iter = (uint32_t *)buf;
  142. chksum = 0;
  143. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  144. chksum += le32_to_cpu(*iter++);
  145. chksum = ~chksum + 1;
  146. *iter = cpu_to_le32(chksum);
  147. } else {
  148. uint8_t *iter;
  149. uint8_t chksum;
  150. iter = (uint8_t *)buf;
  151. chksum = 0;
  152. for (cnt = 0; cnt < count - 1; cnt++)
  153. chksum += *iter++;
  154. chksum = ~chksum + 1;
  155. *iter = chksum;
  156. }
  157. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  158. ql_log(ql_log_warn, vha, 0x705f,
  159. "HBA not online, failing NVRAM update.\n");
  160. return -EAGAIN;
  161. }
  162. /* Write NVRAM. */
  163. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  164. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  165. count);
  166. ql_dbg(ql_dbg_user, vha, 0x7060,
  167. "Setting ISP_ABORT_NEEDED\n");
  168. /* NVRAM settings take effect immediately. */
  169. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  170. qla2xxx_wake_dpc(vha);
  171. qla2x00_wait_for_chip_reset(vha);
  172. return count;
  173. }
  174. static struct bin_attribute sysfs_nvram_attr = {
  175. .attr = {
  176. .name = "nvram",
  177. .mode = S_IRUSR | S_IWUSR,
  178. },
  179. .size = 512,
  180. .read = qla2x00_sysfs_read_nvram,
  181. .write = qla2x00_sysfs_write_nvram,
  182. };
  183. static ssize_t
  184. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  185. struct bin_attribute *bin_attr,
  186. char *buf, loff_t off, size_t count)
  187. {
  188. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  189. struct device, kobj)));
  190. struct qla_hw_data *ha = vha->hw;
  191. if (ha->optrom_state != QLA_SREADING)
  192. return 0;
  193. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  194. ha->optrom_region_size);
  195. }
  196. static ssize_t
  197. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  198. struct bin_attribute *bin_attr,
  199. char *buf, loff_t off, size_t count)
  200. {
  201. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  202. struct device, kobj)));
  203. struct qla_hw_data *ha = vha->hw;
  204. if (ha->optrom_state != QLA_SWRITING)
  205. return -EINVAL;
  206. if (off > ha->optrom_region_size)
  207. return -ERANGE;
  208. if (off + count > ha->optrom_region_size)
  209. count = ha->optrom_region_size - off;
  210. memcpy(&ha->optrom_buffer[off], buf, count);
  211. return count;
  212. }
  213. static struct bin_attribute sysfs_optrom_attr = {
  214. .attr = {
  215. .name = "optrom",
  216. .mode = S_IRUSR | S_IWUSR,
  217. },
  218. .size = 0,
  219. .read = qla2x00_sysfs_read_optrom,
  220. .write = qla2x00_sysfs_write_optrom,
  221. };
  222. static ssize_t
  223. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  224. struct bin_attribute *bin_attr,
  225. char *buf, loff_t off, size_t count)
  226. {
  227. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  228. struct device, kobj)));
  229. struct qla_hw_data *ha = vha->hw;
  230. uint32_t start = 0;
  231. uint32_t size = ha->optrom_size;
  232. int val, valid;
  233. if (off)
  234. return -EINVAL;
  235. if (unlikely(pci_channel_offline(ha->pdev)))
  236. return -EAGAIN;
  237. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  238. return -EINVAL;
  239. if (start > ha->optrom_size)
  240. return -EINVAL;
  241. switch (val) {
  242. case 0:
  243. if (ha->optrom_state != QLA_SREADING &&
  244. ha->optrom_state != QLA_SWRITING)
  245. return -EINVAL;
  246. ha->optrom_state = QLA_SWAITING;
  247. ql_dbg(ql_dbg_user, vha, 0x7061,
  248. "Freeing flash region allocation -- 0x%x bytes.\n",
  249. ha->optrom_region_size);
  250. vfree(ha->optrom_buffer);
  251. ha->optrom_buffer = NULL;
  252. break;
  253. case 1:
  254. if (ha->optrom_state != QLA_SWAITING)
  255. return -EINVAL;
  256. ha->optrom_region_start = start;
  257. ha->optrom_region_size = start + size > ha->optrom_size ?
  258. ha->optrom_size - start : size;
  259. ha->optrom_state = QLA_SREADING;
  260. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  261. if (ha->optrom_buffer == NULL) {
  262. ql_log(ql_log_warn, vha, 0x7062,
  263. "Unable to allocate memory for optrom retrieval "
  264. "(%x).\n", ha->optrom_region_size);
  265. ha->optrom_state = QLA_SWAITING;
  266. return -ENOMEM;
  267. }
  268. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  269. ql_log(ql_log_warn, vha, 0x7063,
  270. "HBA not online, failing NVRAM update.\n");
  271. return -EAGAIN;
  272. }
  273. ql_dbg(ql_dbg_user, vha, 0x7064,
  274. "Reading flash region -- 0x%x/0x%x.\n",
  275. ha->optrom_region_start, ha->optrom_region_size);
  276. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  277. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  278. ha->optrom_region_start, ha->optrom_region_size);
  279. break;
  280. case 2:
  281. if (ha->optrom_state != QLA_SWAITING)
  282. return -EINVAL;
  283. /*
  284. * We need to be more restrictive on which FLASH regions are
  285. * allowed to be updated via user-space. Regions accessible
  286. * via this method include:
  287. *
  288. * ISP21xx/ISP22xx/ISP23xx type boards:
  289. *
  290. * 0x000000 -> 0x020000 -- Boot code.
  291. *
  292. * ISP2322/ISP24xx type boards:
  293. *
  294. * 0x000000 -> 0x07ffff -- Boot code.
  295. * 0x080000 -> 0x0fffff -- Firmware.
  296. *
  297. * ISP25xx type boards:
  298. *
  299. * 0x000000 -> 0x07ffff -- Boot code.
  300. * 0x080000 -> 0x0fffff -- Firmware.
  301. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  302. */
  303. valid = 0;
  304. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  305. valid = 1;
  306. else if (start == (ha->flt_region_boot * 4) ||
  307. start == (ha->flt_region_fw * 4))
  308. valid = 1;
  309. else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
  310. valid = 1;
  311. if (!valid) {
  312. ql_log(ql_log_warn, vha, 0x7065,
  313. "Invalid start region 0x%x/0x%x.\n", start, size);
  314. return -EINVAL;
  315. }
  316. ha->optrom_region_start = start;
  317. ha->optrom_region_size = start + size > ha->optrom_size ?
  318. ha->optrom_size - start : size;
  319. ha->optrom_state = QLA_SWRITING;
  320. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  321. if (ha->optrom_buffer == NULL) {
  322. ql_log(ql_log_warn, vha, 0x7066,
  323. "Unable to allocate memory for optrom update "
  324. "(%x)\n", ha->optrom_region_size);
  325. ha->optrom_state = QLA_SWAITING;
  326. return -ENOMEM;
  327. }
  328. ql_dbg(ql_dbg_user, vha, 0x7067,
  329. "Staging flash region write -- 0x%x/0x%x.\n",
  330. ha->optrom_region_start, ha->optrom_region_size);
  331. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  332. break;
  333. case 3:
  334. if (ha->optrom_state != QLA_SWRITING)
  335. return -ENOMEM;
  336. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  337. ql_log(ql_log_warn, vha, 0x7068,
  338. "HBA not online, failing flash update.\n");
  339. return -EAGAIN;
  340. }
  341. ql_dbg(ql_dbg_user, vha, 0x7069,
  342. "Writing flash region -- 0x%x/0x%x.\n",
  343. ha->optrom_region_start, ha->optrom_region_size);
  344. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  345. ha->optrom_region_start, ha->optrom_region_size);
  346. break;
  347. default:
  348. return -EINVAL;
  349. }
  350. return count;
  351. }
  352. static struct bin_attribute sysfs_optrom_ctl_attr = {
  353. .attr = {
  354. .name = "optrom_ctl",
  355. .mode = S_IWUSR,
  356. },
  357. .size = 0,
  358. .write = qla2x00_sysfs_write_optrom_ctl,
  359. };
  360. static ssize_t
  361. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  362. struct bin_attribute *bin_attr,
  363. char *buf, loff_t off, size_t count)
  364. {
  365. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  366. struct device, kobj)));
  367. struct qla_hw_data *ha = vha->hw;
  368. if (unlikely(pci_channel_offline(ha->pdev)))
  369. return -EAGAIN;
  370. if (!capable(CAP_SYS_ADMIN))
  371. return -EINVAL;
  372. if (IS_NOCACHE_VPD_TYPE(ha))
  373. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  374. ha->vpd_size);
  375. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  376. }
  377. static ssize_t
  378. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  379. struct bin_attribute *bin_attr,
  380. char *buf, loff_t off, size_t count)
  381. {
  382. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  383. struct device, kobj)));
  384. struct qla_hw_data *ha = vha->hw;
  385. uint8_t *tmp_data;
  386. if (unlikely(pci_channel_offline(ha->pdev)))
  387. return 0;
  388. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  389. !ha->isp_ops->write_nvram)
  390. return 0;
  391. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  392. ql_log(ql_log_warn, vha, 0x706a,
  393. "HBA not online, failing VPD update.\n");
  394. return -EAGAIN;
  395. }
  396. /* Write NVRAM. */
  397. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  398. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  399. /* Update flash version information for 4Gb & above. */
  400. if (!IS_FWI2_CAPABLE(ha))
  401. return -EINVAL;
  402. tmp_data = vmalloc(256);
  403. if (!tmp_data) {
  404. ql_log(ql_log_warn, vha, 0x706b,
  405. "Unable to allocate memory for VPD information update.\n");
  406. return -ENOMEM;
  407. }
  408. ha->isp_ops->get_flash_version(vha, tmp_data);
  409. vfree(tmp_data);
  410. return count;
  411. }
  412. static struct bin_attribute sysfs_vpd_attr = {
  413. .attr = {
  414. .name = "vpd",
  415. .mode = S_IRUSR | S_IWUSR,
  416. },
  417. .size = 0,
  418. .read = qla2x00_sysfs_read_vpd,
  419. .write = qla2x00_sysfs_write_vpd,
  420. };
  421. static ssize_t
  422. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  423. struct bin_attribute *bin_attr,
  424. char *buf, loff_t off, size_t count)
  425. {
  426. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  427. struct device, kobj)));
  428. struct qla_hw_data *ha = vha->hw;
  429. uint16_t iter, addr, offset;
  430. int rval;
  431. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  432. return 0;
  433. if (ha->sfp_data)
  434. goto do_read;
  435. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  436. &ha->sfp_data_dma);
  437. if (!ha->sfp_data) {
  438. ql_log(ql_log_warn, vha, 0x706c,
  439. "Unable to allocate memory for SFP read-data.\n");
  440. return 0;
  441. }
  442. do_read:
  443. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  444. addr = 0xa0;
  445. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  446. iter++, offset += SFP_BLOCK_SIZE) {
  447. if (iter == 4) {
  448. /* Skip to next device address. */
  449. addr = 0xa2;
  450. offset = 0;
  451. }
  452. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  453. addr, offset, SFP_BLOCK_SIZE, 0);
  454. if (rval != QLA_SUCCESS) {
  455. ql_log(ql_log_warn, vha, 0x706d,
  456. "Unable to read SFP data (%x/%x/%x).\n", rval,
  457. addr, offset);
  458. return -EIO;
  459. }
  460. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  461. buf += SFP_BLOCK_SIZE;
  462. }
  463. return count;
  464. }
  465. static struct bin_attribute sysfs_sfp_attr = {
  466. .attr = {
  467. .name = "sfp",
  468. .mode = S_IRUSR | S_IWUSR,
  469. },
  470. .size = SFP_DEV_SIZE * 2,
  471. .read = qla2x00_sysfs_read_sfp,
  472. };
  473. static ssize_t
  474. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  475. struct bin_attribute *bin_attr,
  476. char *buf, loff_t off, size_t count)
  477. {
  478. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  479. struct device, kobj)));
  480. struct qla_hw_data *ha = vha->hw;
  481. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  482. int type;
  483. if (off != 0)
  484. return -EINVAL;
  485. type = simple_strtol(buf, NULL, 10);
  486. switch (type) {
  487. case 0x2025c:
  488. ql_log(ql_log_info, vha, 0x706e,
  489. "Issuing ISP reset.\n");
  490. scsi_block_requests(vha->host);
  491. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  492. if (IS_QLA82XX(ha)) {
  493. qla82xx_idc_lock(ha);
  494. qla82xx_set_reset_owner(vha);
  495. qla82xx_idc_unlock(ha);
  496. }
  497. qla2xxx_wake_dpc(vha);
  498. qla2x00_wait_for_chip_reset(vha);
  499. scsi_unblock_requests(vha->host);
  500. break;
  501. case 0x2025d:
  502. if (!IS_QLA81XX(ha))
  503. return -EPERM;
  504. ql_log(ql_log_info, vha, 0x706f,
  505. "Issuing MPI reset.\n");
  506. /* Make sure FC side is not in reset */
  507. qla2x00_wait_for_hba_online(vha);
  508. /* Issue MPI reset */
  509. scsi_block_requests(vha->host);
  510. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  511. ql_log(ql_log_warn, vha, 0x7070,
  512. "MPI reset failed.\n");
  513. scsi_unblock_requests(vha->host);
  514. break;
  515. case 0x2025e:
  516. if (!IS_QLA82XX(ha) || vha != base_vha) {
  517. ql_log(ql_log_info, vha, 0x7071,
  518. "FCoE ctx reset no supported.\n");
  519. return -EPERM;
  520. }
  521. ql_log(ql_log_info, vha, 0x7072,
  522. "Issuing FCoE ctx reset.\n");
  523. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  524. qla2xxx_wake_dpc(vha);
  525. qla2x00_wait_for_fcoe_ctx_reset(vha);
  526. break;
  527. }
  528. return count;
  529. }
  530. static struct bin_attribute sysfs_reset_attr = {
  531. .attr = {
  532. .name = "reset",
  533. .mode = S_IWUSR,
  534. },
  535. .size = 0,
  536. .write = qla2x00_sysfs_write_reset,
  537. };
  538. static ssize_t
  539. qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
  540. struct bin_attribute *bin_attr,
  541. char *buf, loff_t off, size_t count)
  542. {
  543. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  544. struct device, kobj)));
  545. struct qla_hw_data *ha = vha->hw;
  546. uint16_t dev, adr, opt, len;
  547. int rval;
  548. ha->edc_data_len = 0;
  549. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  550. return -EINVAL;
  551. if (!ha->edc_data) {
  552. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  553. &ha->edc_data_dma);
  554. if (!ha->edc_data) {
  555. ql_log(ql_log_warn, vha, 0x7073,
  556. "Unable to allocate memory for EDC write.\n");
  557. return -ENOMEM;
  558. }
  559. }
  560. dev = le16_to_cpup((void *)&buf[0]);
  561. adr = le16_to_cpup((void *)&buf[2]);
  562. opt = le16_to_cpup((void *)&buf[4]);
  563. len = le16_to_cpup((void *)&buf[6]);
  564. if (!(opt & BIT_0))
  565. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  566. return -EINVAL;
  567. memcpy(ha->edc_data, &buf[8], len);
  568. rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
  569. dev, adr, len, opt);
  570. if (rval != QLA_SUCCESS) {
  571. ql_log(ql_log_warn, vha, 0x7074,
  572. "Unable to write EDC (%x) %02x:%04x:%02x:%02hhx\n",
  573. rval, dev, adr, opt, len, buf[8]);
  574. return -EIO;
  575. }
  576. return count;
  577. }
  578. static struct bin_attribute sysfs_edc_attr = {
  579. .attr = {
  580. .name = "edc",
  581. .mode = S_IWUSR,
  582. },
  583. .size = 0,
  584. .write = qla2x00_sysfs_write_edc,
  585. };
  586. static ssize_t
  587. qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
  588. struct bin_attribute *bin_attr,
  589. char *buf, loff_t off, size_t count)
  590. {
  591. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  592. struct device, kobj)));
  593. struct qla_hw_data *ha = vha->hw;
  594. uint16_t dev, adr, opt, len;
  595. int rval;
  596. ha->edc_data_len = 0;
  597. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  598. return -EINVAL;
  599. if (!ha->edc_data) {
  600. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  601. &ha->edc_data_dma);
  602. if (!ha->edc_data) {
  603. ql_log(ql_log_warn, vha, 0x708c,
  604. "Unable to allocate memory for EDC status.\n");
  605. return -ENOMEM;
  606. }
  607. }
  608. dev = le16_to_cpup((void *)&buf[0]);
  609. adr = le16_to_cpup((void *)&buf[2]);
  610. opt = le16_to_cpup((void *)&buf[4]);
  611. len = le16_to_cpup((void *)&buf[6]);
  612. if (!(opt & BIT_0))
  613. if (len == 0 || len > DMA_POOL_SIZE)
  614. return -EINVAL;
  615. memset(ha->edc_data, 0, len);
  616. rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
  617. dev, adr, len, opt);
  618. if (rval != QLA_SUCCESS) {
  619. ql_log(ql_log_info, vha, 0x7075,
  620. "Unable to write EDC status (%x) %02x:%04x:%02x.\n",
  621. rval, dev, adr, opt, len);
  622. return -EIO;
  623. }
  624. ha->edc_data_len = len;
  625. return count;
  626. }
  627. static ssize_t
  628. qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
  629. struct bin_attribute *bin_attr,
  630. char *buf, loff_t off, size_t count)
  631. {
  632. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  633. struct device, kobj)));
  634. struct qla_hw_data *ha = vha->hw;
  635. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  636. return 0;
  637. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  638. return -EINVAL;
  639. memcpy(buf, ha->edc_data, ha->edc_data_len);
  640. return ha->edc_data_len;
  641. }
  642. static struct bin_attribute sysfs_edc_status_attr = {
  643. .attr = {
  644. .name = "edc_status",
  645. .mode = S_IRUSR | S_IWUSR,
  646. },
  647. .size = 0,
  648. .write = qla2x00_sysfs_write_edc_status,
  649. .read = qla2x00_sysfs_read_edc_status,
  650. };
  651. static ssize_t
  652. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  653. struct bin_attribute *bin_attr,
  654. char *buf, loff_t off, size_t count)
  655. {
  656. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  657. struct device, kobj)));
  658. struct qla_hw_data *ha = vha->hw;
  659. int rval;
  660. uint16_t actual_size;
  661. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  662. return 0;
  663. if (ha->xgmac_data)
  664. goto do_read;
  665. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  666. &ha->xgmac_data_dma, GFP_KERNEL);
  667. if (!ha->xgmac_data) {
  668. ql_log(ql_log_warn, vha, 0x7076,
  669. "Unable to allocate memory for XGMAC read-data.\n");
  670. return 0;
  671. }
  672. do_read:
  673. actual_size = 0;
  674. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  675. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  676. XGMAC_DATA_SIZE, &actual_size);
  677. if (rval != QLA_SUCCESS) {
  678. ql_log(ql_log_warn, vha, 0x7077,
  679. "Unable to read XGMAC data (%x).\n", rval);
  680. count = 0;
  681. }
  682. count = actual_size > count ? count: actual_size;
  683. memcpy(buf, ha->xgmac_data, count);
  684. return count;
  685. }
  686. static struct bin_attribute sysfs_xgmac_stats_attr = {
  687. .attr = {
  688. .name = "xgmac_stats",
  689. .mode = S_IRUSR,
  690. },
  691. .size = 0,
  692. .read = qla2x00_sysfs_read_xgmac_stats,
  693. };
  694. static ssize_t
  695. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  696. struct bin_attribute *bin_attr,
  697. char *buf, loff_t off, size_t count)
  698. {
  699. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  700. struct device, kobj)));
  701. struct qla_hw_data *ha = vha->hw;
  702. int rval;
  703. uint16_t actual_size;
  704. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  705. return 0;
  706. if (ha->dcbx_tlv)
  707. goto do_read;
  708. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  709. &ha->dcbx_tlv_dma, GFP_KERNEL);
  710. if (!ha->dcbx_tlv) {
  711. ql_log(ql_log_warn, vha, 0x7078,
  712. "Unable to allocate memory for DCBX TLV read-data.\n");
  713. return -ENOMEM;
  714. }
  715. do_read:
  716. actual_size = 0;
  717. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  718. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  719. DCBX_TLV_DATA_SIZE);
  720. if (rval != QLA_SUCCESS) {
  721. ql_log(ql_log_warn, vha, 0x7079,
  722. "Unable to read DCBX TLV (%x).\n", rval);
  723. return -EIO;
  724. }
  725. memcpy(buf, ha->dcbx_tlv, count);
  726. return count;
  727. }
  728. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  729. .attr = {
  730. .name = "dcbx_tlv",
  731. .mode = S_IRUSR,
  732. },
  733. .size = 0,
  734. .read = qla2x00_sysfs_read_dcbx_tlv,
  735. };
  736. static struct sysfs_entry {
  737. char *name;
  738. struct bin_attribute *attr;
  739. int is4GBp_only;
  740. } bin_file_entries[] = {
  741. { "fw_dump", &sysfs_fw_dump_attr, },
  742. { "nvram", &sysfs_nvram_attr, },
  743. { "optrom", &sysfs_optrom_attr, },
  744. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  745. { "vpd", &sysfs_vpd_attr, 1 },
  746. { "sfp", &sysfs_sfp_attr, 1 },
  747. { "reset", &sysfs_reset_attr, },
  748. { "edc", &sysfs_edc_attr, 2 },
  749. { "edc_status", &sysfs_edc_status_attr, 2 },
  750. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  751. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  752. { NULL },
  753. };
  754. void
  755. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  756. {
  757. struct Scsi_Host *host = vha->host;
  758. struct sysfs_entry *iter;
  759. int ret;
  760. for (iter = bin_file_entries; iter->name; iter++) {
  761. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  762. continue;
  763. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  764. continue;
  765. if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
  766. continue;
  767. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  768. iter->attr);
  769. if (ret)
  770. ql_log(ql_log_warn, vha, 0x00f3,
  771. "Unable to create sysfs %s binary attribute (%d).\n",
  772. iter->name, ret);
  773. else
  774. ql_dbg(ql_dbg_init, vha, 0x00f4,
  775. "Successfully created sysfs %s binary attribure.\n",
  776. iter->name);
  777. }
  778. }
  779. void
  780. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  781. {
  782. struct Scsi_Host *host = vha->host;
  783. struct sysfs_entry *iter;
  784. struct qla_hw_data *ha = vha->hw;
  785. for (iter = bin_file_entries; iter->name; iter++) {
  786. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  787. continue;
  788. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  789. continue;
  790. if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
  791. continue;
  792. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  793. iter->attr);
  794. }
  795. if (ha->beacon_blink_led == 1)
  796. ha->isp_ops->beacon_off(vha);
  797. }
  798. /* Scsi_Host attributes. */
  799. static ssize_t
  800. qla2x00_drvr_version_show(struct device *dev,
  801. struct device_attribute *attr, char *buf)
  802. {
  803. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  804. }
  805. static ssize_t
  806. qla2x00_fw_version_show(struct device *dev,
  807. struct device_attribute *attr, char *buf)
  808. {
  809. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  810. struct qla_hw_data *ha = vha->hw;
  811. char fw_str[128];
  812. return snprintf(buf, PAGE_SIZE, "%s\n",
  813. ha->isp_ops->fw_version_str(vha, fw_str));
  814. }
  815. static ssize_t
  816. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  817. char *buf)
  818. {
  819. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  820. struct qla_hw_data *ha = vha->hw;
  821. uint32_t sn;
  822. if (IS_FWI2_CAPABLE(ha)) {
  823. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  824. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  825. }
  826. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  827. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  828. sn % 100000);
  829. }
  830. static ssize_t
  831. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  832. char *buf)
  833. {
  834. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  835. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  836. }
  837. static ssize_t
  838. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  839. char *buf)
  840. {
  841. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  842. struct qla_hw_data *ha = vha->hw;
  843. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  844. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  845. ha->product_id[3]);
  846. }
  847. static ssize_t
  848. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  849. char *buf)
  850. {
  851. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  852. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  853. }
  854. static ssize_t
  855. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  856. char *buf)
  857. {
  858. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  859. return snprintf(buf, PAGE_SIZE, "%s\n",
  860. vha->hw->model_desc ? vha->hw->model_desc : "");
  861. }
  862. static ssize_t
  863. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  864. char *buf)
  865. {
  866. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  867. char pci_info[30];
  868. return snprintf(buf, PAGE_SIZE, "%s\n",
  869. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  870. }
  871. static ssize_t
  872. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  873. char *buf)
  874. {
  875. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  876. struct qla_hw_data *ha = vha->hw;
  877. int len = 0;
  878. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  879. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  880. vha->device_flags & DFLG_NO_CABLE)
  881. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  882. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  883. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  884. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  885. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  886. else {
  887. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  888. switch (ha->current_topology) {
  889. case ISP_CFG_NL:
  890. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  891. break;
  892. case ISP_CFG_FL:
  893. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  894. break;
  895. case ISP_CFG_N:
  896. len += snprintf(buf + len, PAGE_SIZE-len,
  897. "N_Port to N_Port\n");
  898. break;
  899. case ISP_CFG_F:
  900. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  901. break;
  902. default:
  903. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  904. break;
  905. }
  906. }
  907. return len;
  908. }
  909. static ssize_t
  910. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  911. char *buf)
  912. {
  913. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  914. int len = 0;
  915. switch (vha->hw->zio_mode) {
  916. case QLA_ZIO_MODE_6:
  917. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  918. break;
  919. case QLA_ZIO_DISABLED:
  920. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  921. break;
  922. }
  923. return len;
  924. }
  925. static ssize_t
  926. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  927. const char *buf, size_t count)
  928. {
  929. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  930. struct qla_hw_data *ha = vha->hw;
  931. int val = 0;
  932. uint16_t zio_mode;
  933. if (!IS_ZIO_SUPPORTED(ha))
  934. return -ENOTSUPP;
  935. if (sscanf(buf, "%d", &val) != 1)
  936. return -EINVAL;
  937. if (val)
  938. zio_mode = QLA_ZIO_MODE_6;
  939. else
  940. zio_mode = QLA_ZIO_DISABLED;
  941. /* Update per-hba values and queue a reset. */
  942. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  943. ha->zio_mode = zio_mode;
  944. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  945. }
  946. return strlen(buf);
  947. }
  948. static ssize_t
  949. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  950. char *buf)
  951. {
  952. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  953. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  954. }
  955. static ssize_t
  956. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  957. const char *buf, size_t count)
  958. {
  959. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  960. int val = 0;
  961. uint16_t zio_timer;
  962. if (sscanf(buf, "%d", &val) != 1)
  963. return -EINVAL;
  964. if (val > 25500 || val < 100)
  965. return -ERANGE;
  966. zio_timer = (uint16_t)(val / 100);
  967. vha->hw->zio_timer = zio_timer;
  968. return strlen(buf);
  969. }
  970. static ssize_t
  971. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  972. char *buf)
  973. {
  974. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  975. int len = 0;
  976. if (vha->hw->beacon_blink_led)
  977. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  978. else
  979. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  980. return len;
  981. }
  982. static ssize_t
  983. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  984. const char *buf, size_t count)
  985. {
  986. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  987. struct qla_hw_data *ha = vha->hw;
  988. int val = 0;
  989. int rval;
  990. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  991. return -EPERM;
  992. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  993. ql_log(ql_log_warn, vha, 0x707a,
  994. "Abort ISP active -- ignoring beacon request.\n");
  995. return -EBUSY;
  996. }
  997. if (sscanf(buf, "%d", &val) != 1)
  998. return -EINVAL;
  999. if (val)
  1000. rval = ha->isp_ops->beacon_on(vha);
  1001. else
  1002. rval = ha->isp_ops->beacon_off(vha);
  1003. if (rval != QLA_SUCCESS)
  1004. count = 0;
  1005. return count;
  1006. }
  1007. static ssize_t
  1008. qla2x00_optrom_bios_version_show(struct device *dev,
  1009. struct device_attribute *attr, char *buf)
  1010. {
  1011. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1012. struct qla_hw_data *ha = vha->hw;
  1013. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  1014. ha->bios_revision[0]);
  1015. }
  1016. static ssize_t
  1017. qla2x00_optrom_efi_version_show(struct device *dev,
  1018. struct device_attribute *attr, char *buf)
  1019. {
  1020. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1021. struct qla_hw_data *ha = vha->hw;
  1022. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  1023. ha->efi_revision[0]);
  1024. }
  1025. static ssize_t
  1026. qla2x00_optrom_fcode_version_show(struct device *dev,
  1027. struct device_attribute *attr, char *buf)
  1028. {
  1029. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1030. struct qla_hw_data *ha = vha->hw;
  1031. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  1032. ha->fcode_revision[0]);
  1033. }
  1034. static ssize_t
  1035. qla2x00_optrom_fw_version_show(struct device *dev,
  1036. struct device_attribute *attr, char *buf)
  1037. {
  1038. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1039. struct qla_hw_data *ha = vha->hw;
  1040. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1041. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1042. ha->fw_revision[3]);
  1043. }
  1044. static ssize_t
  1045. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1046. struct device_attribute *attr, char *buf)
  1047. {
  1048. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1049. struct qla_hw_data *ha = vha->hw;
  1050. if (!IS_QLA81XX(ha))
  1051. return snprintf(buf, PAGE_SIZE, "\n");
  1052. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1053. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1054. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1055. }
  1056. static ssize_t
  1057. qla2x00_total_isp_aborts_show(struct device *dev,
  1058. struct device_attribute *attr, char *buf)
  1059. {
  1060. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1061. struct qla_hw_data *ha = vha->hw;
  1062. return snprintf(buf, PAGE_SIZE, "%d\n",
  1063. ha->qla_stats.total_isp_aborts);
  1064. }
  1065. static ssize_t
  1066. qla24xx_84xx_fw_version_show(struct device *dev,
  1067. struct device_attribute *attr, char *buf)
  1068. {
  1069. int rval = QLA_SUCCESS;
  1070. uint16_t status[2] = {0, 0};
  1071. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1072. struct qla_hw_data *ha = vha->hw;
  1073. if (!IS_QLA84XX(ha))
  1074. return snprintf(buf, PAGE_SIZE, "\n");
  1075. if (ha->cs84xx->op_fw_version == 0)
  1076. rval = qla84xx_verify_chip(vha, status);
  1077. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1078. return snprintf(buf, PAGE_SIZE, "%u\n",
  1079. (uint32_t)ha->cs84xx->op_fw_version);
  1080. return snprintf(buf, PAGE_SIZE, "\n");
  1081. }
  1082. static ssize_t
  1083. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1084. char *buf)
  1085. {
  1086. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1087. struct qla_hw_data *ha = vha->hw;
  1088. if (!IS_QLA81XX(ha))
  1089. return snprintf(buf, PAGE_SIZE, "\n");
  1090. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1091. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1092. ha->mpi_capabilities);
  1093. }
  1094. static ssize_t
  1095. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1096. char *buf)
  1097. {
  1098. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1099. struct qla_hw_data *ha = vha->hw;
  1100. if (!IS_QLA81XX(ha))
  1101. return snprintf(buf, PAGE_SIZE, "\n");
  1102. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1103. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1104. }
  1105. static ssize_t
  1106. qla2x00_flash_block_size_show(struct device *dev,
  1107. struct device_attribute *attr, char *buf)
  1108. {
  1109. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1110. struct qla_hw_data *ha = vha->hw;
  1111. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1112. }
  1113. static ssize_t
  1114. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1115. char *buf)
  1116. {
  1117. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1118. if (!IS_QLA8XXX_TYPE(vha->hw))
  1119. return snprintf(buf, PAGE_SIZE, "\n");
  1120. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1121. }
  1122. static ssize_t
  1123. qla2x00_vn_port_mac_address_show(struct device *dev,
  1124. struct device_attribute *attr, char *buf)
  1125. {
  1126. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1127. if (!IS_QLA8XXX_TYPE(vha->hw))
  1128. return snprintf(buf, PAGE_SIZE, "\n");
  1129. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1130. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1131. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1132. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1133. }
  1134. static ssize_t
  1135. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1136. char *buf)
  1137. {
  1138. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1139. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1140. }
  1141. static ssize_t
  1142. qla2x00_thermal_temp_show(struct device *dev,
  1143. struct device_attribute *attr, char *buf)
  1144. {
  1145. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1146. int rval = QLA_FUNCTION_FAILED;
  1147. uint16_t temp, frac;
  1148. if (!vha->hw->flags.thermal_supported)
  1149. return snprintf(buf, PAGE_SIZE, "\n");
  1150. temp = frac = 0;
  1151. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1152. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1153. ql_log(ql_log_warn, vha, 0x707b,
  1154. "ISP reset active.\n");
  1155. else if (!vha->hw->flags.eeh_busy)
  1156. rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
  1157. if (rval != QLA_SUCCESS)
  1158. temp = frac = 0;
  1159. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
  1160. }
  1161. static ssize_t
  1162. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1163. char *buf)
  1164. {
  1165. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1166. int rval = QLA_FUNCTION_FAILED;
  1167. uint16_t state[5];
  1168. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1169. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1170. ql_log(ql_log_warn, vha, 0x707c,
  1171. "ISP reset active.\n");
  1172. else if (!vha->hw->flags.eeh_busy)
  1173. rval = qla2x00_get_firmware_state(vha, state);
  1174. if (rval != QLA_SUCCESS)
  1175. memset(state, -1, sizeof(state));
  1176. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1177. state[1], state[2], state[3], state[4]);
  1178. }
  1179. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1180. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1181. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1182. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1183. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1184. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1185. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1186. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1187. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1188. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1189. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1190. qla2x00_zio_timer_store);
  1191. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1192. qla2x00_beacon_store);
  1193. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1194. qla2x00_optrom_bios_version_show, NULL);
  1195. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1196. qla2x00_optrom_efi_version_show, NULL);
  1197. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1198. qla2x00_optrom_fcode_version_show, NULL);
  1199. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1200. NULL);
  1201. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1202. qla2x00_optrom_gold_fw_version_show, NULL);
  1203. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1204. NULL);
  1205. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1206. NULL);
  1207. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1208. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1209. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1210. NULL);
  1211. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1212. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1213. qla2x00_vn_port_mac_address_show, NULL);
  1214. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1215. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1216. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1217. struct device_attribute *qla2x00_host_attrs[] = {
  1218. &dev_attr_driver_version,
  1219. &dev_attr_fw_version,
  1220. &dev_attr_serial_num,
  1221. &dev_attr_isp_name,
  1222. &dev_attr_isp_id,
  1223. &dev_attr_model_name,
  1224. &dev_attr_model_desc,
  1225. &dev_attr_pci_info,
  1226. &dev_attr_link_state,
  1227. &dev_attr_zio,
  1228. &dev_attr_zio_timer,
  1229. &dev_attr_beacon,
  1230. &dev_attr_optrom_bios_version,
  1231. &dev_attr_optrom_efi_version,
  1232. &dev_attr_optrom_fcode_version,
  1233. &dev_attr_optrom_fw_version,
  1234. &dev_attr_84xx_fw_version,
  1235. &dev_attr_total_isp_aborts,
  1236. &dev_attr_mpi_version,
  1237. &dev_attr_phy_version,
  1238. &dev_attr_flash_block_size,
  1239. &dev_attr_vlan_id,
  1240. &dev_attr_vn_port_mac_address,
  1241. &dev_attr_fabric_param,
  1242. &dev_attr_fw_state,
  1243. &dev_attr_optrom_gold_fw_version,
  1244. &dev_attr_thermal_temp,
  1245. NULL,
  1246. };
  1247. /* Host attributes. */
  1248. static void
  1249. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1250. {
  1251. scsi_qla_host_t *vha = shost_priv(shost);
  1252. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1253. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1254. }
  1255. static void
  1256. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1257. {
  1258. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1259. (shost_priv(shost)))->hw;
  1260. u32 speed = FC_PORTSPEED_UNKNOWN;
  1261. switch (ha->link_data_rate) {
  1262. case PORT_SPEED_1GB:
  1263. speed = FC_PORTSPEED_1GBIT;
  1264. break;
  1265. case PORT_SPEED_2GB:
  1266. speed = FC_PORTSPEED_2GBIT;
  1267. break;
  1268. case PORT_SPEED_4GB:
  1269. speed = FC_PORTSPEED_4GBIT;
  1270. break;
  1271. case PORT_SPEED_8GB:
  1272. speed = FC_PORTSPEED_8GBIT;
  1273. break;
  1274. case PORT_SPEED_10GB:
  1275. speed = FC_PORTSPEED_10GBIT;
  1276. break;
  1277. }
  1278. fc_host_speed(shost) = speed;
  1279. }
  1280. static void
  1281. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1282. {
  1283. scsi_qla_host_t *vha = shost_priv(shost);
  1284. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1285. if (vha->vp_idx) {
  1286. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1287. return;
  1288. }
  1289. switch (vha->hw->current_topology) {
  1290. case ISP_CFG_NL:
  1291. port_type = FC_PORTTYPE_LPORT;
  1292. break;
  1293. case ISP_CFG_FL:
  1294. port_type = FC_PORTTYPE_NLPORT;
  1295. break;
  1296. case ISP_CFG_N:
  1297. port_type = FC_PORTTYPE_PTP;
  1298. break;
  1299. case ISP_CFG_F:
  1300. port_type = FC_PORTTYPE_NPORT;
  1301. break;
  1302. }
  1303. fc_host_port_type(shost) = port_type;
  1304. }
  1305. static void
  1306. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1307. {
  1308. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1309. scsi_qla_host_t *vha = shost_priv(host);
  1310. fc_port_t *fcport;
  1311. u64 node_name = 0;
  1312. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1313. if (fcport->rport &&
  1314. starget->id == fcport->rport->scsi_target_id) {
  1315. node_name = wwn_to_u64(fcport->node_name);
  1316. break;
  1317. }
  1318. }
  1319. fc_starget_node_name(starget) = node_name;
  1320. }
  1321. static void
  1322. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1323. {
  1324. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1325. scsi_qla_host_t *vha = shost_priv(host);
  1326. fc_port_t *fcport;
  1327. u64 port_name = 0;
  1328. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1329. if (fcport->rport &&
  1330. starget->id == fcport->rport->scsi_target_id) {
  1331. port_name = wwn_to_u64(fcport->port_name);
  1332. break;
  1333. }
  1334. }
  1335. fc_starget_port_name(starget) = port_name;
  1336. }
  1337. static void
  1338. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1339. {
  1340. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1341. scsi_qla_host_t *vha = shost_priv(host);
  1342. fc_port_t *fcport;
  1343. uint32_t port_id = ~0U;
  1344. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1345. if (fcport->rport &&
  1346. starget->id == fcport->rport->scsi_target_id) {
  1347. port_id = fcport->d_id.b.domain << 16 |
  1348. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1349. break;
  1350. }
  1351. }
  1352. fc_starget_port_id(starget) = port_id;
  1353. }
  1354. static void
  1355. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1356. {
  1357. if (timeout)
  1358. rport->dev_loss_tmo = timeout;
  1359. else
  1360. rport->dev_loss_tmo = 1;
  1361. }
  1362. static void
  1363. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1364. {
  1365. struct Scsi_Host *host = rport_to_shost(rport);
  1366. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1367. unsigned long flags;
  1368. if (!fcport)
  1369. return;
  1370. /* Now that the rport has been deleted, set the fcport state to
  1371. FCS_DEVICE_DEAD */
  1372. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1373. /*
  1374. * Transport has effectively 'deleted' the rport, clear
  1375. * all local references.
  1376. */
  1377. spin_lock_irqsave(host->host_lock, flags);
  1378. fcport->rport = fcport->drport = NULL;
  1379. *((fc_port_t **)rport->dd_data) = NULL;
  1380. spin_unlock_irqrestore(host->host_lock, flags);
  1381. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1382. return;
  1383. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1384. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1385. return;
  1386. }
  1387. }
  1388. static void
  1389. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1390. {
  1391. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1392. if (!fcport)
  1393. return;
  1394. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1395. return;
  1396. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1397. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1398. return;
  1399. }
  1400. /*
  1401. * At this point all fcport's software-states are cleared. Perform any
  1402. * final cleanup of firmware resources (PCBs and XCBs).
  1403. */
  1404. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1405. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1406. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1407. fcport->loop_id, fcport->d_id.b.domain,
  1408. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1409. }
  1410. static int
  1411. qla2x00_issue_lip(struct Scsi_Host *shost)
  1412. {
  1413. scsi_qla_host_t *vha = shost_priv(shost);
  1414. qla2x00_loop_reset(vha);
  1415. return 0;
  1416. }
  1417. static struct fc_host_statistics *
  1418. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1419. {
  1420. scsi_qla_host_t *vha = shost_priv(shost);
  1421. struct qla_hw_data *ha = vha->hw;
  1422. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1423. int rval;
  1424. struct link_statistics *stats;
  1425. dma_addr_t stats_dma;
  1426. struct fc_host_statistics *pfc_host_stat;
  1427. pfc_host_stat = &ha->fc_host_stat;
  1428. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1429. if (test_bit(UNLOADING, &vha->dpc_flags))
  1430. goto done;
  1431. if (unlikely(pci_channel_offline(ha->pdev)))
  1432. goto done;
  1433. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1434. if (stats == NULL) {
  1435. ql_log(ql_log_warn, vha, 0x707d,
  1436. "Failed to allocate memory for stats.\n");
  1437. goto done;
  1438. }
  1439. memset(stats, 0, DMA_POOL_SIZE);
  1440. rval = QLA_FUNCTION_FAILED;
  1441. if (IS_FWI2_CAPABLE(ha)) {
  1442. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1443. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1444. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1445. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1446. !ha->dpc_active) {
  1447. /* Must be in a 'READY' state for statistics retrieval. */
  1448. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1449. stats, stats_dma);
  1450. }
  1451. if (rval != QLA_SUCCESS)
  1452. goto done_free;
  1453. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1454. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1455. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1456. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1457. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1458. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1459. if (IS_FWI2_CAPABLE(ha)) {
  1460. pfc_host_stat->lip_count = stats->lip_cnt;
  1461. pfc_host_stat->tx_frames = stats->tx_frames;
  1462. pfc_host_stat->rx_frames = stats->rx_frames;
  1463. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1464. pfc_host_stat->nos_count = stats->nos_rcvd;
  1465. }
  1466. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1467. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1468. done_free:
  1469. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1470. done:
  1471. return pfc_host_stat;
  1472. }
  1473. static void
  1474. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1475. {
  1476. scsi_qla_host_t *vha = shost_priv(shost);
  1477. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1478. }
  1479. static void
  1480. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1481. {
  1482. scsi_qla_host_t *vha = shost_priv(shost);
  1483. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1484. }
  1485. static void
  1486. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1487. {
  1488. scsi_qla_host_t *vha = shost_priv(shost);
  1489. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1490. 0xFF, 0xFF, 0xFF, 0xFF};
  1491. u64 fabric_name = wwn_to_u64(node_name);
  1492. if (vha->device_flags & SWITCH_FOUND)
  1493. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1494. fc_host_fabric_name(shost) = fabric_name;
  1495. }
  1496. static void
  1497. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1498. {
  1499. scsi_qla_host_t *vha = shost_priv(shost);
  1500. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1501. if (!base_vha->flags.online)
  1502. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1503. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1504. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1505. else
  1506. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1507. }
  1508. static int
  1509. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1510. {
  1511. int ret = 0;
  1512. uint8_t qos = 0;
  1513. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1514. scsi_qla_host_t *vha = NULL;
  1515. struct qla_hw_data *ha = base_vha->hw;
  1516. uint16_t options = 0;
  1517. int cnt;
  1518. struct req_que *req = ha->req_q_map[0];
  1519. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1520. if (ret) {
  1521. ql_log(ql_log_warn, vha, 0x707e,
  1522. "Vport sanity check failed, status %x\n", ret);
  1523. return (ret);
  1524. }
  1525. vha = qla24xx_create_vhost(fc_vport);
  1526. if (vha == NULL) {
  1527. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1528. return FC_VPORT_FAILED;
  1529. }
  1530. if (disable) {
  1531. atomic_set(&vha->vp_state, VP_OFFLINE);
  1532. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1533. } else
  1534. atomic_set(&vha->vp_state, VP_FAILED);
  1535. /* ready to create vport */
  1536. ql_log(ql_log_info, vha, 0x7080,
  1537. "VP entry id %d assigned.\n", vha->vp_idx);
  1538. /* initialized vport states */
  1539. atomic_set(&vha->loop_state, LOOP_DOWN);
  1540. vha->vp_err_state= VP_ERR_PORTDWN;
  1541. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1542. /* Check if physical ha port is Up */
  1543. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1544. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1545. /* Don't retry or attempt login of this virtual port */
  1546. ql_dbg(ql_dbg_user, vha, 0x7081,
  1547. "Vport loop state is not UP.\n");
  1548. atomic_set(&vha->loop_state, LOOP_DEAD);
  1549. if (!disable)
  1550. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1551. }
  1552. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1553. if (ha->fw_attributes & BIT_4) {
  1554. int prot = 0;
  1555. vha->flags.difdix_supported = 1;
  1556. ql_dbg(ql_dbg_user, vha, 0x7082,
  1557. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1558. if (ql2xenabledif == 1)
  1559. prot = SHOST_DIX_TYPE0_PROTECTION;
  1560. scsi_host_set_prot(vha->host,
  1561. prot | SHOST_DIF_TYPE1_PROTECTION
  1562. | SHOST_DIF_TYPE2_PROTECTION
  1563. | SHOST_DIF_TYPE3_PROTECTION
  1564. | SHOST_DIX_TYPE1_PROTECTION
  1565. | SHOST_DIX_TYPE2_PROTECTION
  1566. | SHOST_DIX_TYPE3_PROTECTION);
  1567. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1568. } else
  1569. vha->flags.difdix_supported = 0;
  1570. }
  1571. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1572. &ha->pdev->dev)) {
  1573. ql_dbg(ql_dbg_user, vha, 0x7083,
  1574. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1575. goto vport_create_failed_2;
  1576. }
  1577. /* initialize attributes */
  1578. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1579. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1580. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1581. fc_host_supported_classes(vha->host) =
  1582. fc_host_supported_classes(base_vha->host);
  1583. fc_host_supported_speeds(vha->host) =
  1584. fc_host_supported_speeds(base_vha->host);
  1585. qla24xx_vport_disable(fc_vport, disable);
  1586. if (ha->flags.cpu_affinity_enabled) {
  1587. req = ha->req_q_map[1];
  1588. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1589. "Request queue %p attached with "
  1590. "VP[%d], cpu affinity =%d\n",
  1591. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1592. goto vport_queue;
  1593. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1594. goto vport_queue;
  1595. /* Create a request queue in QoS mode for the vport */
  1596. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1597. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1598. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1599. 8) == 0) {
  1600. qos = ha->npiv_info[cnt].q_qos;
  1601. break;
  1602. }
  1603. }
  1604. if (qos) {
  1605. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1606. qos);
  1607. if (!ret)
  1608. ql_log(ql_log_warn, vha, 0x7084,
  1609. "Can't create request queue for VP[%d]\n",
  1610. vha->vp_idx);
  1611. else {
  1612. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1613. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1614. ret, qos, vha->vp_idx);
  1615. ql_dbg(ql_dbg_user, vha, 0x7085,
  1616. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1617. ret, qos, vha->vp_idx);
  1618. req = ha->req_q_map[ret];
  1619. }
  1620. }
  1621. vport_queue:
  1622. vha->req = req;
  1623. return 0;
  1624. vport_create_failed_2:
  1625. qla24xx_disable_vp(vha);
  1626. qla24xx_deallocate_vp_id(vha);
  1627. scsi_host_put(vha->host);
  1628. return FC_VPORT_FAILED;
  1629. }
  1630. static int
  1631. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1632. {
  1633. scsi_qla_host_t *vha = fc_vport->dd_data;
  1634. struct qla_hw_data *ha = vha->hw;
  1635. uint16_t id = vha->vp_idx;
  1636. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1637. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1638. msleep(1000);
  1639. qla24xx_disable_vp(vha);
  1640. vha->flags.delete_progress = 1;
  1641. fc_remove_host(vha->host);
  1642. scsi_remove_host(vha->host);
  1643. /* Allow timer to run to drain queued items, when removing vp */
  1644. qla24xx_deallocate_vp_id(vha);
  1645. if (vha->timer_active) {
  1646. qla2x00_vp_stop_timer(vha);
  1647. ql_dbg(ql_dbg_user, vha, 0x7086,
  1648. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1649. }
  1650. /* No pending activities shall be there on the vha now */
  1651. if (ql2xextended_error_logging & ql_dbg_user)
  1652. msleep(random32()%10); /* Just to see if something falls on
  1653. * the net we have placed below */
  1654. BUG_ON(atomic_read(&vha->vref_count));
  1655. qla2x00_free_fcports(vha);
  1656. mutex_lock(&ha->vport_lock);
  1657. ha->cur_vport_count--;
  1658. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1659. mutex_unlock(&ha->vport_lock);
  1660. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1661. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1662. ql_log(ql_log_warn, vha, 0x7087,
  1663. "Queue delete failed.\n");
  1664. }
  1665. scsi_host_put(vha->host);
  1666. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1667. return 0;
  1668. }
  1669. static int
  1670. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1671. {
  1672. scsi_qla_host_t *vha = fc_vport->dd_data;
  1673. if (disable)
  1674. qla24xx_disable_vp(vha);
  1675. else
  1676. qla24xx_enable_vp(vha);
  1677. return 0;
  1678. }
  1679. struct fc_function_template qla2xxx_transport_functions = {
  1680. .show_host_node_name = 1,
  1681. .show_host_port_name = 1,
  1682. .show_host_supported_classes = 1,
  1683. .show_host_supported_speeds = 1,
  1684. .get_host_port_id = qla2x00_get_host_port_id,
  1685. .show_host_port_id = 1,
  1686. .get_host_speed = qla2x00_get_host_speed,
  1687. .show_host_speed = 1,
  1688. .get_host_port_type = qla2x00_get_host_port_type,
  1689. .show_host_port_type = 1,
  1690. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1691. .show_host_symbolic_name = 1,
  1692. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1693. .show_host_system_hostname = 1,
  1694. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1695. .show_host_fabric_name = 1,
  1696. .get_host_port_state = qla2x00_get_host_port_state,
  1697. .show_host_port_state = 1,
  1698. .dd_fcrport_size = sizeof(struct fc_port *),
  1699. .show_rport_supported_classes = 1,
  1700. .get_starget_node_name = qla2x00_get_starget_node_name,
  1701. .show_starget_node_name = 1,
  1702. .get_starget_port_name = qla2x00_get_starget_port_name,
  1703. .show_starget_port_name = 1,
  1704. .get_starget_port_id = qla2x00_get_starget_port_id,
  1705. .show_starget_port_id = 1,
  1706. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1707. .show_rport_dev_loss_tmo = 1,
  1708. .issue_fc_host_lip = qla2x00_issue_lip,
  1709. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1710. .terminate_rport_io = qla2x00_terminate_rport_io,
  1711. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1712. .vport_create = qla24xx_vport_create,
  1713. .vport_disable = qla24xx_vport_disable,
  1714. .vport_delete = qla24xx_vport_delete,
  1715. .bsg_request = qla24xx_bsg_request,
  1716. .bsg_timeout = qla24xx_bsg_timeout,
  1717. };
  1718. struct fc_function_template qla2xxx_transport_vport_functions = {
  1719. .show_host_node_name = 1,
  1720. .show_host_port_name = 1,
  1721. .show_host_supported_classes = 1,
  1722. .get_host_port_id = qla2x00_get_host_port_id,
  1723. .show_host_port_id = 1,
  1724. .get_host_speed = qla2x00_get_host_speed,
  1725. .show_host_speed = 1,
  1726. .get_host_port_type = qla2x00_get_host_port_type,
  1727. .show_host_port_type = 1,
  1728. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1729. .show_host_symbolic_name = 1,
  1730. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1731. .show_host_system_hostname = 1,
  1732. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1733. .show_host_fabric_name = 1,
  1734. .get_host_port_state = qla2x00_get_host_port_state,
  1735. .show_host_port_state = 1,
  1736. .dd_fcrport_size = sizeof(struct fc_port *),
  1737. .show_rport_supported_classes = 1,
  1738. .get_starget_node_name = qla2x00_get_starget_node_name,
  1739. .show_starget_node_name = 1,
  1740. .get_starget_port_name = qla2x00_get_starget_port_name,
  1741. .show_starget_port_name = 1,
  1742. .get_starget_port_id = qla2x00_get_starget_port_id,
  1743. .show_starget_port_id = 1,
  1744. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1745. .show_rport_dev_loss_tmo = 1,
  1746. .issue_fc_host_lip = qla2x00_issue_lip,
  1747. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1748. .terminate_rport_io = qla2x00_terminate_rport_io,
  1749. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1750. .bsg_request = qla24xx_bsg_request,
  1751. .bsg_timeout = qla24xx_bsg_timeout,
  1752. };
  1753. void
  1754. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1755. {
  1756. struct qla_hw_data *ha = vha->hw;
  1757. u32 speed = FC_PORTSPEED_UNKNOWN;
  1758. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1759. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1760. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1761. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1762. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1763. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1764. if (IS_QLA8XXX_TYPE(ha))
  1765. speed = FC_PORTSPEED_10GBIT;
  1766. else if (IS_QLA25XX(ha))
  1767. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1768. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1769. else if (IS_QLA24XX_TYPE(ha))
  1770. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1771. FC_PORTSPEED_1GBIT;
  1772. else if (IS_QLA23XX(ha))
  1773. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1774. else
  1775. speed = FC_PORTSPEED_1GBIT;
  1776. fc_host_supported_speeds(vha->host) = speed;
  1777. }