qla_attr.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2008 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/delay.h>
  11. static int qla24xx_vport_disable(struct fc_vport *, bool);
  12. static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  13. int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
  14. static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  15. /* SYSFS attributes --------------------------------------------------------- */
  16. static ssize_t
  17. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  18. struct bin_attribute *bin_attr,
  19. char *buf, loff_t off, size_t count)
  20. {
  21. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  22. struct device, kobj)));
  23. struct qla_hw_data *ha = vha->hw;
  24. if (ha->fw_dump_reading == 0)
  25. return 0;
  26. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  27. ha->fw_dump_len);
  28. }
  29. static ssize_t
  30. qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
  31. struct bin_attribute *bin_attr,
  32. char *buf, loff_t off, size_t count)
  33. {
  34. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  35. struct device, kobj)));
  36. struct qla_hw_data *ha = vha->hw;
  37. int reading;
  38. if (off != 0)
  39. return (0);
  40. reading = simple_strtol(buf, NULL, 10);
  41. switch (reading) {
  42. case 0:
  43. if (!ha->fw_dump_reading)
  44. break;
  45. qla_printk(KERN_INFO, ha,
  46. "Firmware dump cleared on (%ld).\n", vha->host_no);
  47. ha->fw_dump_reading = 0;
  48. ha->fw_dumped = 0;
  49. break;
  50. case 1:
  51. if (ha->fw_dumped && !ha->fw_dump_reading) {
  52. ha->fw_dump_reading = 1;
  53. qla_printk(KERN_INFO, ha,
  54. "Raw firmware dump ready for read on (%ld).\n",
  55. vha->host_no);
  56. }
  57. break;
  58. case 2:
  59. qla2x00_alloc_fw_dump(vha);
  60. break;
  61. case 3:
  62. qla2x00_system_error(vha);
  63. break;
  64. }
  65. return (count);
  66. }
  67. static struct bin_attribute sysfs_fw_dump_attr = {
  68. .attr = {
  69. .name = "fw_dump",
  70. .mode = S_IRUSR | S_IWUSR,
  71. },
  72. .size = 0,
  73. .read = qla2x00_sysfs_read_fw_dump,
  74. .write = qla2x00_sysfs_write_fw_dump,
  75. };
  76. static ssize_t
  77. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  78. struct bin_attribute *bin_attr,
  79. char *buf, loff_t off, size_t count)
  80. {
  81. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  82. struct device, kobj)));
  83. struct qla_hw_data *ha = vha->hw;
  84. if (!capable(CAP_SYS_ADMIN))
  85. return 0;
  86. if (IS_NOCACHE_VPD_TYPE(ha))
  87. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  88. ha->nvram_size);
  89. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  90. ha->nvram_size);
  91. }
  92. static ssize_t
  93. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  94. struct bin_attribute *bin_attr,
  95. char *buf, loff_t off, size_t count)
  96. {
  97. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  98. struct device, kobj)));
  99. struct qla_hw_data *ha = vha->hw;
  100. uint16_t cnt;
  101. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  102. !ha->isp_ops->write_nvram)
  103. return 0;
  104. /* Checksum NVRAM. */
  105. if (IS_FWI2_CAPABLE(ha)) {
  106. uint32_t *iter;
  107. uint32_t chksum;
  108. iter = (uint32_t *)buf;
  109. chksum = 0;
  110. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  111. chksum += le32_to_cpu(*iter++);
  112. chksum = ~chksum + 1;
  113. *iter = cpu_to_le32(chksum);
  114. } else {
  115. uint8_t *iter;
  116. uint8_t chksum;
  117. iter = (uint8_t *)buf;
  118. chksum = 0;
  119. for (cnt = 0; cnt < count - 1; cnt++)
  120. chksum += *iter++;
  121. chksum = ~chksum + 1;
  122. *iter = chksum;
  123. }
  124. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  125. qla_printk(KERN_WARNING, ha,
  126. "HBA not online, failing NVRAM update.\n");
  127. return -EAGAIN;
  128. }
  129. /* Write NVRAM. */
  130. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  131. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  132. count);
  133. /* NVRAM settings take effect immediately. */
  134. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  135. qla2xxx_wake_dpc(vha);
  136. qla2x00_wait_for_chip_reset(vha);
  137. return (count);
  138. }
  139. static struct bin_attribute sysfs_nvram_attr = {
  140. .attr = {
  141. .name = "nvram",
  142. .mode = S_IRUSR | S_IWUSR,
  143. },
  144. .size = 512,
  145. .read = qla2x00_sysfs_read_nvram,
  146. .write = qla2x00_sysfs_write_nvram,
  147. };
  148. static ssize_t
  149. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  150. struct bin_attribute *bin_attr,
  151. char *buf, loff_t off, size_t count)
  152. {
  153. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  154. struct device, kobj)));
  155. struct qla_hw_data *ha = vha->hw;
  156. if (ha->optrom_state != QLA_SREADING)
  157. return 0;
  158. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  159. ha->optrom_region_size);
  160. }
  161. static ssize_t
  162. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  163. struct bin_attribute *bin_attr,
  164. char *buf, loff_t off, size_t count)
  165. {
  166. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  167. struct device, kobj)));
  168. struct qla_hw_data *ha = vha->hw;
  169. if (ha->optrom_state != QLA_SWRITING)
  170. return -EINVAL;
  171. if (off > ha->optrom_region_size)
  172. return -ERANGE;
  173. if (off + count > ha->optrom_region_size)
  174. count = ha->optrom_region_size - off;
  175. memcpy(&ha->optrom_buffer[off], buf, count);
  176. return count;
  177. }
  178. static struct bin_attribute sysfs_optrom_attr = {
  179. .attr = {
  180. .name = "optrom",
  181. .mode = S_IRUSR | S_IWUSR,
  182. },
  183. .size = 0,
  184. .read = qla2x00_sysfs_read_optrom,
  185. .write = qla2x00_sysfs_write_optrom,
  186. };
  187. static ssize_t
  188. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  189. struct bin_attribute *bin_attr,
  190. char *buf, loff_t off, size_t count)
  191. {
  192. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  193. struct device, kobj)));
  194. struct qla_hw_data *ha = vha->hw;
  195. uint32_t start = 0;
  196. uint32_t size = ha->optrom_size;
  197. int val, valid;
  198. if (off)
  199. return 0;
  200. if (unlikely(pci_channel_offline(ha->pdev)))
  201. return 0;
  202. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  203. return -EINVAL;
  204. if (start > ha->optrom_size)
  205. return -EINVAL;
  206. switch (val) {
  207. case 0:
  208. if (ha->optrom_state != QLA_SREADING &&
  209. ha->optrom_state != QLA_SWRITING)
  210. break;
  211. ha->optrom_state = QLA_SWAITING;
  212. DEBUG2(qla_printk(KERN_INFO, ha,
  213. "Freeing flash region allocation -- 0x%x bytes.\n",
  214. ha->optrom_region_size));
  215. vfree(ha->optrom_buffer);
  216. ha->optrom_buffer = NULL;
  217. break;
  218. case 1:
  219. if (ha->optrom_state != QLA_SWAITING)
  220. break;
  221. ha->optrom_region_start = start;
  222. ha->optrom_region_size = start + size > ha->optrom_size ?
  223. ha->optrom_size - start : size;
  224. ha->optrom_state = QLA_SREADING;
  225. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  226. if (ha->optrom_buffer == NULL) {
  227. qla_printk(KERN_WARNING, ha,
  228. "Unable to allocate memory for optrom retrieval "
  229. "(%x).\n", ha->optrom_region_size);
  230. ha->optrom_state = QLA_SWAITING;
  231. return count;
  232. }
  233. DEBUG2(qla_printk(KERN_INFO, ha,
  234. "Reading flash region -- 0x%x/0x%x.\n",
  235. ha->optrom_region_start, ha->optrom_region_size));
  236. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  237. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  238. ha->optrom_region_start, ha->optrom_region_size);
  239. break;
  240. case 2:
  241. if (ha->optrom_state != QLA_SWAITING)
  242. break;
  243. /*
  244. * We need to be more restrictive on which FLASH regions are
  245. * allowed to be updated via user-space. Regions accessible
  246. * via this method include:
  247. *
  248. * ISP21xx/ISP22xx/ISP23xx type boards:
  249. *
  250. * 0x000000 -> 0x020000 -- Boot code.
  251. *
  252. * ISP2322/ISP24xx type boards:
  253. *
  254. * 0x000000 -> 0x07ffff -- Boot code.
  255. * 0x080000 -> 0x0fffff -- Firmware.
  256. *
  257. * ISP25xx type boards:
  258. *
  259. * 0x000000 -> 0x07ffff -- Boot code.
  260. * 0x080000 -> 0x0fffff -- Firmware.
  261. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  262. */
  263. valid = 0;
  264. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  265. valid = 1;
  266. else if (start == (ha->flt_region_boot * 4) ||
  267. start == (ha->flt_region_fw * 4))
  268. valid = 1;
  269. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  270. valid = 1;
  271. if (!valid) {
  272. qla_printk(KERN_WARNING, ha,
  273. "Invalid start region 0x%x/0x%x.\n", start, size);
  274. return -EINVAL;
  275. }
  276. ha->optrom_region_start = start;
  277. ha->optrom_region_size = start + size > ha->optrom_size ?
  278. ha->optrom_size - start : size;
  279. ha->optrom_state = QLA_SWRITING;
  280. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  281. if (ha->optrom_buffer == NULL) {
  282. qla_printk(KERN_WARNING, ha,
  283. "Unable to allocate memory for optrom update "
  284. "(%x).\n", ha->optrom_region_size);
  285. ha->optrom_state = QLA_SWAITING;
  286. return count;
  287. }
  288. DEBUG2(qla_printk(KERN_INFO, ha,
  289. "Staging flash region write -- 0x%x/0x%x.\n",
  290. ha->optrom_region_start, ha->optrom_region_size));
  291. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  292. break;
  293. case 3:
  294. if (ha->optrom_state != QLA_SWRITING)
  295. break;
  296. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  297. qla_printk(KERN_WARNING, ha,
  298. "HBA not online, failing flash update.\n");
  299. return -EAGAIN;
  300. }
  301. DEBUG2(qla_printk(KERN_INFO, ha,
  302. "Writing flash region -- 0x%x/0x%x.\n",
  303. ha->optrom_region_start, ha->optrom_region_size));
  304. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  305. ha->optrom_region_start, ha->optrom_region_size);
  306. break;
  307. default:
  308. count = -EINVAL;
  309. }
  310. return count;
  311. }
  312. static struct bin_attribute sysfs_optrom_ctl_attr = {
  313. .attr = {
  314. .name = "optrom_ctl",
  315. .mode = S_IWUSR,
  316. },
  317. .size = 0,
  318. .write = qla2x00_sysfs_write_optrom_ctl,
  319. };
  320. static ssize_t
  321. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  322. struct bin_attribute *bin_attr,
  323. char *buf, loff_t off, size_t count)
  324. {
  325. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  326. struct device, kobj)));
  327. struct qla_hw_data *ha = vha->hw;
  328. if (unlikely(pci_channel_offline(ha->pdev)))
  329. return 0;
  330. if (!capable(CAP_SYS_ADMIN))
  331. return 0;
  332. if (IS_NOCACHE_VPD_TYPE(ha))
  333. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  334. ha->vpd_size);
  335. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  336. }
  337. static ssize_t
  338. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  339. struct bin_attribute *bin_attr,
  340. char *buf, loff_t off, size_t count)
  341. {
  342. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  343. struct device, kobj)));
  344. struct qla_hw_data *ha = vha->hw;
  345. uint8_t *tmp_data;
  346. if (unlikely(pci_channel_offline(ha->pdev)))
  347. return 0;
  348. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  349. !ha->isp_ops->write_nvram)
  350. return 0;
  351. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  352. qla_printk(KERN_WARNING, ha,
  353. "HBA not online, failing VPD update.\n");
  354. return -EAGAIN;
  355. }
  356. /* Write NVRAM. */
  357. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  358. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  359. /* Update flash version information for 4Gb & above. */
  360. if (!IS_FWI2_CAPABLE(ha))
  361. goto done;
  362. tmp_data = vmalloc(256);
  363. if (!tmp_data) {
  364. qla_printk(KERN_WARNING, ha,
  365. "Unable to allocate memory for VPD information update.\n");
  366. goto done;
  367. }
  368. ha->isp_ops->get_flash_version(vha, tmp_data);
  369. vfree(tmp_data);
  370. done:
  371. return count;
  372. }
  373. static struct bin_attribute sysfs_vpd_attr = {
  374. .attr = {
  375. .name = "vpd",
  376. .mode = S_IRUSR | S_IWUSR,
  377. },
  378. .size = 0,
  379. .read = qla2x00_sysfs_read_vpd,
  380. .write = qla2x00_sysfs_write_vpd,
  381. };
  382. static ssize_t
  383. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  384. struct bin_attribute *bin_attr,
  385. char *buf, loff_t off, size_t count)
  386. {
  387. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  388. struct device, kobj)));
  389. struct qla_hw_data *ha = vha->hw;
  390. uint16_t iter, addr, offset;
  391. int rval;
  392. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  393. return 0;
  394. if (ha->sfp_data)
  395. goto do_read;
  396. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  397. &ha->sfp_data_dma);
  398. if (!ha->sfp_data) {
  399. qla_printk(KERN_WARNING, ha,
  400. "Unable to allocate memory for SFP read-data.\n");
  401. return 0;
  402. }
  403. do_read:
  404. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  405. addr = 0xa0;
  406. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  407. iter++, offset += SFP_BLOCK_SIZE) {
  408. if (iter == 4) {
  409. /* Skip to next device address. */
  410. addr = 0xa2;
  411. offset = 0;
  412. }
  413. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  414. SFP_BLOCK_SIZE);
  415. if (rval != QLA_SUCCESS) {
  416. qla_printk(KERN_WARNING, ha,
  417. "Unable to read SFP data (%x/%x/%x).\n", rval,
  418. addr, offset);
  419. count = 0;
  420. break;
  421. }
  422. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  423. buf += SFP_BLOCK_SIZE;
  424. }
  425. return count;
  426. }
  427. static struct bin_attribute sysfs_sfp_attr = {
  428. .attr = {
  429. .name = "sfp",
  430. .mode = S_IRUSR | S_IWUSR,
  431. },
  432. .size = SFP_DEV_SIZE * 2,
  433. .read = qla2x00_sysfs_read_sfp,
  434. };
  435. static ssize_t
  436. qla2x00_sysfs_write_reset(struct kobject *kobj,
  437. struct bin_attribute *bin_attr,
  438. char *buf, loff_t off, size_t count)
  439. {
  440. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  441. struct device, kobj)));
  442. struct qla_hw_data *ha = vha->hw;
  443. int type;
  444. if (off != 0)
  445. return 0;
  446. type = simple_strtol(buf, NULL, 10);
  447. switch (type) {
  448. case 0x2025c:
  449. qla_printk(KERN_INFO, ha,
  450. "Issuing ISP reset on (%ld).\n", vha->host_no);
  451. scsi_block_requests(vha->host);
  452. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  453. qla2xxx_wake_dpc(vha);
  454. qla2x00_wait_for_chip_reset(vha);
  455. scsi_unblock_requests(vha->host);
  456. break;
  457. case 0x2025d:
  458. if (!IS_QLA81XX(ha))
  459. break;
  460. qla_printk(KERN_INFO, ha,
  461. "Issuing MPI reset on (%ld).\n", vha->host_no);
  462. /* Make sure FC side is not in reset */
  463. qla2x00_wait_for_hba_online(vha);
  464. /* Issue MPI reset */
  465. scsi_block_requests(vha->host);
  466. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  467. qla_printk(KERN_WARNING, ha,
  468. "MPI reset failed on (%ld).\n", vha->host_no);
  469. scsi_unblock_requests(vha->host);
  470. break;
  471. }
  472. return count;
  473. }
  474. static struct bin_attribute sysfs_reset_attr = {
  475. .attr = {
  476. .name = "reset",
  477. .mode = S_IWUSR,
  478. },
  479. .size = 0,
  480. .write = qla2x00_sysfs_write_reset,
  481. };
  482. static ssize_t
  483. qla2x00_sysfs_write_edc(struct kobject *kobj,
  484. struct bin_attribute *bin_attr,
  485. char *buf, loff_t off, size_t count)
  486. {
  487. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  488. struct device, kobj)));
  489. struct qla_hw_data *ha = vha->hw;
  490. uint16_t dev, adr, opt, len;
  491. int rval;
  492. ha->edc_data_len = 0;
  493. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  494. return 0;
  495. if (!ha->edc_data) {
  496. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  497. &ha->edc_data_dma);
  498. if (!ha->edc_data) {
  499. DEBUG2(qla_printk(KERN_INFO, ha,
  500. "Unable to allocate memory for EDC write.\n"));
  501. return 0;
  502. }
  503. }
  504. dev = le16_to_cpup((void *)&buf[0]);
  505. adr = le16_to_cpup((void *)&buf[2]);
  506. opt = le16_to_cpup((void *)&buf[4]);
  507. len = le16_to_cpup((void *)&buf[6]);
  508. if (!(opt & BIT_0))
  509. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  510. return -EINVAL;
  511. memcpy(ha->edc_data, &buf[8], len);
  512. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  513. ha->edc_data, len, opt);
  514. if (rval != QLA_SUCCESS) {
  515. DEBUG2(qla_printk(KERN_INFO, ha,
  516. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  517. rval, dev, adr, opt, len, *buf));
  518. return 0;
  519. }
  520. return count;
  521. }
  522. static struct bin_attribute sysfs_edc_attr = {
  523. .attr = {
  524. .name = "edc",
  525. .mode = S_IWUSR,
  526. },
  527. .size = 0,
  528. .write = qla2x00_sysfs_write_edc,
  529. };
  530. static ssize_t
  531. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  532. struct bin_attribute *bin_attr,
  533. char *buf, loff_t off, size_t count)
  534. {
  535. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  536. struct device, kobj)));
  537. struct qla_hw_data *ha = vha->hw;
  538. uint16_t dev, adr, opt, len;
  539. int rval;
  540. ha->edc_data_len = 0;
  541. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  542. return 0;
  543. if (!ha->edc_data) {
  544. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  545. &ha->edc_data_dma);
  546. if (!ha->edc_data) {
  547. DEBUG2(qla_printk(KERN_INFO, ha,
  548. "Unable to allocate memory for EDC status.\n"));
  549. return 0;
  550. }
  551. }
  552. dev = le16_to_cpup((void *)&buf[0]);
  553. adr = le16_to_cpup((void *)&buf[2]);
  554. opt = le16_to_cpup((void *)&buf[4]);
  555. len = le16_to_cpup((void *)&buf[6]);
  556. if (!(opt & BIT_0))
  557. if (len == 0 || len > DMA_POOL_SIZE)
  558. return -EINVAL;
  559. memset(ha->edc_data, 0, len);
  560. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  561. ha->edc_data, len, opt);
  562. if (rval != QLA_SUCCESS) {
  563. DEBUG2(qla_printk(KERN_INFO, ha,
  564. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  565. rval, dev, adr, opt, len));
  566. return 0;
  567. }
  568. ha->edc_data_len = len;
  569. return count;
  570. }
  571. static ssize_t
  572. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  573. struct bin_attribute *bin_attr,
  574. char *buf, loff_t off, size_t count)
  575. {
  576. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  577. struct device, kobj)));
  578. struct qla_hw_data *ha = vha->hw;
  579. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  580. return 0;
  581. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  582. return -EINVAL;
  583. memcpy(buf, ha->edc_data, ha->edc_data_len);
  584. return ha->edc_data_len;
  585. }
  586. static struct bin_attribute sysfs_edc_status_attr = {
  587. .attr = {
  588. .name = "edc_status",
  589. .mode = S_IRUSR | S_IWUSR,
  590. },
  591. .size = 0,
  592. .write = qla2x00_sysfs_write_edc_status,
  593. .read = qla2x00_sysfs_read_edc_status,
  594. };
  595. static ssize_t
  596. qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
  597. struct bin_attribute *bin_attr,
  598. char *buf, loff_t off, size_t count)
  599. {
  600. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  601. struct device, kobj)));
  602. struct qla_hw_data *ha = vha->hw;
  603. int rval;
  604. uint16_t actual_size;
  605. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  606. return 0;
  607. if (ha->xgmac_data)
  608. goto do_read;
  609. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  610. &ha->xgmac_data_dma, GFP_KERNEL);
  611. if (!ha->xgmac_data) {
  612. qla_printk(KERN_WARNING, ha,
  613. "Unable to allocate memory for XGMAC read-data.\n");
  614. return 0;
  615. }
  616. do_read:
  617. actual_size = 0;
  618. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  619. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  620. XGMAC_DATA_SIZE, &actual_size);
  621. if (rval != QLA_SUCCESS) {
  622. qla_printk(KERN_WARNING, ha,
  623. "Unable to read XGMAC data (%x).\n", rval);
  624. count = 0;
  625. }
  626. count = actual_size > count ? count: actual_size;
  627. memcpy(buf, ha->xgmac_data, count);
  628. return count;
  629. }
  630. static struct bin_attribute sysfs_xgmac_stats_attr = {
  631. .attr = {
  632. .name = "xgmac_stats",
  633. .mode = S_IRUSR,
  634. },
  635. .size = 0,
  636. .read = qla2x00_sysfs_read_xgmac_stats,
  637. };
  638. static ssize_t
  639. qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
  640. struct bin_attribute *bin_attr,
  641. char *buf, loff_t off, size_t count)
  642. {
  643. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  644. struct device, kobj)));
  645. struct qla_hw_data *ha = vha->hw;
  646. int rval;
  647. uint16_t actual_size;
  648. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  649. return 0;
  650. if (ha->dcbx_tlv)
  651. goto do_read;
  652. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  653. &ha->dcbx_tlv_dma, GFP_KERNEL);
  654. if (!ha->dcbx_tlv) {
  655. qla_printk(KERN_WARNING, ha,
  656. "Unable to allocate memory for DCBX TLV read-data.\n");
  657. return 0;
  658. }
  659. do_read:
  660. actual_size = 0;
  661. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  662. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  663. DCBX_TLV_DATA_SIZE);
  664. if (rval != QLA_SUCCESS) {
  665. qla_printk(KERN_WARNING, ha,
  666. "Unable to read DCBX TLV data (%x).\n", rval);
  667. count = 0;
  668. }
  669. memcpy(buf, ha->dcbx_tlv, count);
  670. return count;
  671. }
  672. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  673. .attr = {
  674. .name = "dcbx_tlv",
  675. .mode = S_IRUSR,
  676. },
  677. .size = 0,
  678. .read = qla2x00_sysfs_read_dcbx_tlv,
  679. };
  680. static struct sysfs_entry {
  681. char *name;
  682. struct bin_attribute *attr;
  683. int is4GBp_only;
  684. } bin_file_entries[] = {
  685. { "fw_dump", &sysfs_fw_dump_attr, },
  686. { "nvram", &sysfs_nvram_attr, },
  687. { "optrom", &sysfs_optrom_attr, },
  688. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  689. { "vpd", &sysfs_vpd_attr, 1 },
  690. { "sfp", &sysfs_sfp_attr, 1 },
  691. { "reset", &sysfs_reset_attr, },
  692. { "edc", &sysfs_edc_attr, 2 },
  693. { "edc_status", &sysfs_edc_status_attr, 2 },
  694. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  695. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  696. { NULL },
  697. };
  698. void
  699. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  700. {
  701. struct Scsi_Host *host = vha->host;
  702. struct sysfs_entry *iter;
  703. int ret;
  704. for (iter = bin_file_entries; iter->name; iter++) {
  705. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  706. continue;
  707. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  708. continue;
  709. if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
  710. continue;
  711. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  712. iter->attr);
  713. if (ret)
  714. qla_printk(KERN_INFO, vha->hw,
  715. "Unable to create sysfs %s binary attribute "
  716. "(%d).\n", iter->name, ret);
  717. }
  718. }
  719. void
  720. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  721. {
  722. struct Scsi_Host *host = vha->host;
  723. struct sysfs_entry *iter;
  724. struct qla_hw_data *ha = vha->hw;
  725. for (iter = bin_file_entries; iter->name; iter++) {
  726. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  727. continue;
  728. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  729. continue;
  730. if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
  731. continue;
  732. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  733. iter->attr);
  734. }
  735. if (ha->beacon_blink_led == 1)
  736. ha->isp_ops->beacon_off(vha);
  737. }
  738. /* Scsi_Host attributes. */
  739. static ssize_t
  740. qla2x00_drvr_version_show(struct device *dev,
  741. struct device_attribute *attr, char *buf)
  742. {
  743. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  744. }
  745. static ssize_t
  746. qla2x00_fw_version_show(struct device *dev,
  747. struct device_attribute *attr, char *buf)
  748. {
  749. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  750. struct qla_hw_data *ha = vha->hw;
  751. char fw_str[128];
  752. return snprintf(buf, PAGE_SIZE, "%s\n",
  753. ha->isp_ops->fw_version_str(vha, fw_str));
  754. }
  755. static ssize_t
  756. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  757. char *buf)
  758. {
  759. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  760. struct qla_hw_data *ha = vha->hw;
  761. uint32_t sn;
  762. if (IS_FWI2_CAPABLE(ha)) {
  763. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  764. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  765. }
  766. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  767. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  768. sn % 100000);
  769. }
  770. static ssize_t
  771. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  772. char *buf)
  773. {
  774. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  775. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  776. }
  777. static ssize_t
  778. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  779. char *buf)
  780. {
  781. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  782. struct qla_hw_data *ha = vha->hw;
  783. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  784. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  785. ha->product_id[3]);
  786. }
  787. static ssize_t
  788. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  789. char *buf)
  790. {
  791. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  792. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  793. }
  794. static ssize_t
  795. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  796. char *buf)
  797. {
  798. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  799. return snprintf(buf, PAGE_SIZE, "%s\n",
  800. vha->hw->model_desc ? vha->hw->model_desc : "");
  801. }
  802. static ssize_t
  803. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  804. char *buf)
  805. {
  806. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  807. char pci_info[30];
  808. return snprintf(buf, PAGE_SIZE, "%s\n",
  809. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  810. }
  811. static ssize_t
  812. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  813. char *buf)
  814. {
  815. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  816. struct qla_hw_data *ha = vha->hw;
  817. int len = 0;
  818. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  819. atomic_read(&vha->loop_state) == LOOP_DEAD)
  820. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  821. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  822. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  823. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  824. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  825. else {
  826. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  827. switch (ha->current_topology) {
  828. case ISP_CFG_NL:
  829. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  830. break;
  831. case ISP_CFG_FL:
  832. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  833. break;
  834. case ISP_CFG_N:
  835. len += snprintf(buf + len, PAGE_SIZE-len,
  836. "N_Port to N_Port\n");
  837. break;
  838. case ISP_CFG_F:
  839. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  840. break;
  841. default:
  842. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  843. break;
  844. }
  845. }
  846. return len;
  847. }
  848. static ssize_t
  849. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  850. char *buf)
  851. {
  852. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  853. int len = 0;
  854. switch (vha->hw->zio_mode) {
  855. case QLA_ZIO_MODE_6:
  856. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  857. break;
  858. case QLA_ZIO_DISABLED:
  859. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  860. break;
  861. }
  862. return len;
  863. }
  864. static ssize_t
  865. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  866. const char *buf, size_t count)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. struct qla_hw_data *ha = vha->hw;
  870. int val = 0;
  871. uint16_t zio_mode;
  872. if (!IS_ZIO_SUPPORTED(ha))
  873. return -ENOTSUPP;
  874. if (sscanf(buf, "%d", &val) != 1)
  875. return -EINVAL;
  876. if (val)
  877. zio_mode = QLA_ZIO_MODE_6;
  878. else
  879. zio_mode = QLA_ZIO_DISABLED;
  880. /* Update per-hba values and queue a reset. */
  881. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  882. ha->zio_mode = zio_mode;
  883. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  884. }
  885. return strlen(buf);
  886. }
  887. static ssize_t
  888. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  889. char *buf)
  890. {
  891. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  892. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  893. }
  894. static ssize_t
  895. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  896. const char *buf, size_t count)
  897. {
  898. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  899. int val = 0;
  900. uint16_t zio_timer;
  901. if (sscanf(buf, "%d", &val) != 1)
  902. return -EINVAL;
  903. if (val > 25500 || val < 100)
  904. return -ERANGE;
  905. zio_timer = (uint16_t)(val / 100);
  906. vha->hw->zio_timer = zio_timer;
  907. return strlen(buf);
  908. }
  909. static ssize_t
  910. qla2x00_beacon_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. if (vha->hw->beacon_blink_led)
  916. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  917. else
  918. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  919. return len;
  920. }
  921. static ssize_t
  922. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  923. const char *buf, size_t count)
  924. {
  925. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  926. struct qla_hw_data *ha = vha->hw;
  927. int val = 0;
  928. int rval;
  929. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  930. return -EPERM;
  931. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  932. qla_printk(KERN_WARNING, ha,
  933. "Abort ISP active -- ignoring beacon request.\n");
  934. return -EBUSY;
  935. }
  936. if (sscanf(buf, "%d", &val) != 1)
  937. return -EINVAL;
  938. if (val)
  939. rval = ha->isp_ops->beacon_on(vha);
  940. else
  941. rval = ha->isp_ops->beacon_off(vha);
  942. if (rval != QLA_SUCCESS)
  943. count = 0;
  944. return count;
  945. }
  946. static ssize_t
  947. qla2x00_optrom_bios_version_show(struct device *dev,
  948. struct device_attribute *attr, char *buf)
  949. {
  950. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  951. struct qla_hw_data *ha = vha->hw;
  952. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  953. ha->bios_revision[0]);
  954. }
  955. static ssize_t
  956. qla2x00_optrom_efi_version_show(struct device *dev,
  957. struct device_attribute *attr, char *buf)
  958. {
  959. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  960. struct qla_hw_data *ha = vha->hw;
  961. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  962. ha->efi_revision[0]);
  963. }
  964. static ssize_t
  965. qla2x00_optrom_fcode_version_show(struct device *dev,
  966. struct device_attribute *attr, char *buf)
  967. {
  968. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  969. struct qla_hw_data *ha = vha->hw;
  970. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  971. ha->fcode_revision[0]);
  972. }
  973. static ssize_t
  974. qla2x00_optrom_fw_version_show(struct device *dev,
  975. struct device_attribute *attr, char *buf)
  976. {
  977. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  978. struct qla_hw_data *ha = vha->hw;
  979. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  980. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  981. ha->fw_revision[3]);
  982. }
  983. static ssize_t
  984. qla2x00_total_isp_aborts_show(struct device *dev,
  985. struct device_attribute *attr, char *buf)
  986. {
  987. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  988. struct qla_hw_data *ha = vha->hw;
  989. return snprintf(buf, PAGE_SIZE, "%d\n",
  990. ha->qla_stats.total_isp_aborts);
  991. }
  992. static ssize_t
  993. qla24xx_84xx_fw_version_show(struct device *dev,
  994. struct device_attribute *attr, char *buf)
  995. {
  996. int rval = QLA_SUCCESS;
  997. uint16_t status[2] = {0, 0};
  998. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  999. struct qla_hw_data *ha = vha->hw;
  1000. if (IS_QLA84XX(ha) && ha->cs84xx) {
  1001. if (ha->cs84xx->op_fw_version == 0) {
  1002. rval = qla84xx_verify_chip(vha, status);
  1003. }
  1004. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1005. return snprintf(buf, PAGE_SIZE, "%u\n",
  1006. (uint32_t)ha->cs84xx->op_fw_version);
  1007. }
  1008. return snprintf(buf, PAGE_SIZE, "\n");
  1009. }
  1010. static ssize_t
  1011. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1012. char *buf)
  1013. {
  1014. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1015. struct qla_hw_data *ha = vha->hw;
  1016. if (!IS_QLA81XX(ha))
  1017. return snprintf(buf, PAGE_SIZE, "\n");
  1018. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1019. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1020. ha->mpi_capabilities);
  1021. }
  1022. static ssize_t
  1023. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1024. char *buf)
  1025. {
  1026. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1027. struct qla_hw_data *ha = vha->hw;
  1028. if (!IS_QLA81XX(ha))
  1029. return snprintf(buf, PAGE_SIZE, "\n");
  1030. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1031. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1032. }
  1033. static ssize_t
  1034. qla2x00_flash_block_size_show(struct device *dev,
  1035. struct device_attribute *attr, char *buf)
  1036. {
  1037. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1038. struct qla_hw_data *ha = vha->hw;
  1039. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1040. }
  1041. static ssize_t
  1042. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1043. char *buf)
  1044. {
  1045. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1046. if (!IS_QLA81XX(vha->hw))
  1047. return snprintf(buf, PAGE_SIZE, "\n");
  1048. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1049. }
  1050. static ssize_t
  1051. qla2x00_vn_port_mac_address_show(struct device *dev,
  1052. struct device_attribute *attr, char *buf)
  1053. {
  1054. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1055. if (!IS_QLA81XX(vha->hw))
  1056. return snprintf(buf, PAGE_SIZE, "\n");
  1057. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1058. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1059. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1060. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1061. }
  1062. static ssize_t
  1063. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1064. char *buf)
  1065. {
  1066. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1067. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1068. }
  1069. static ssize_t
  1070. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1071. char *buf)
  1072. {
  1073. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1074. int rval = QLA_FUNCTION_FAILED;
  1075. uint16_t state[5];
  1076. if (!vha->hw->flags.eeh_busy)
  1077. rval = qla2x00_get_firmware_state(vha, state);
  1078. if (rval != QLA_SUCCESS)
  1079. memset(state, -1, sizeof(state));
  1080. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1081. state[1], state[2], state[3], state[4]);
  1082. }
  1083. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1084. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1085. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1086. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1087. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1088. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1089. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1090. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1091. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1092. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1093. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1094. qla2x00_zio_timer_store);
  1095. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1096. qla2x00_beacon_store);
  1097. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1098. qla2x00_optrom_bios_version_show, NULL);
  1099. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1100. qla2x00_optrom_efi_version_show, NULL);
  1101. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1102. qla2x00_optrom_fcode_version_show, NULL);
  1103. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1104. NULL);
  1105. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1106. NULL);
  1107. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1108. NULL);
  1109. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1110. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1111. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1112. NULL);
  1113. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1114. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1115. qla2x00_vn_port_mac_address_show, NULL);
  1116. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1117. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1118. struct device_attribute *qla2x00_host_attrs[] = {
  1119. &dev_attr_driver_version,
  1120. &dev_attr_fw_version,
  1121. &dev_attr_serial_num,
  1122. &dev_attr_isp_name,
  1123. &dev_attr_isp_id,
  1124. &dev_attr_model_name,
  1125. &dev_attr_model_desc,
  1126. &dev_attr_pci_info,
  1127. &dev_attr_link_state,
  1128. &dev_attr_zio,
  1129. &dev_attr_zio_timer,
  1130. &dev_attr_beacon,
  1131. &dev_attr_optrom_bios_version,
  1132. &dev_attr_optrom_efi_version,
  1133. &dev_attr_optrom_fcode_version,
  1134. &dev_attr_optrom_fw_version,
  1135. &dev_attr_84xx_fw_version,
  1136. &dev_attr_total_isp_aborts,
  1137. &dev_attr_mpi_version,
  1138. &dev_attr_phy_version,
  1139. &dev_attr_flash_block_size,
  1140. &dev_attr_vlan_id,
  1141. &dev_attr_vn_port_mac_address,
  1142. &dev_attr_fabric_param,
  1143. &dev_attr_fw_state,
  1144. NULL,
  1145. };
  1146. /* Host attributes. */
  1147. static void
  1148. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1149. {
  1150. scsi_qla_host_t *vha = shost_priv(shost);
  1151. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1152. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1153. }
  1154. static void
  1155. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1156. {
  1157. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1158. (shost_priv(shost)))->hw;
  1159. u32 speed = FC_PORTSPEED_UNKNOWN;
  1160. switch (ha->link_data_rate) {
  1161. case PORT_SPEED_1GB:
  1162. speed = FC_PORTSPEED_1GBIT;
  1163. break;
  1164. case PORT_SPEED_2GB:
  1165. speed = FC_PORTSPEED_2GBIT;
  1166. break;
  1167. case PORT_SPEED_4GB:
  1168. speed = FC_PORTSPEED_4GBIT;
  1169. break;
  1170. case PORT_SPEED_8GB:
  1171. speed = FC_PORTSPEED_8GBIT;
  1172. break;
  1173. case PORT_SPEED_10GB:
  1174. speed = FC_PORTSPEED_10GBIT;
  1175. break;
  1176. }
  1177. fc_host_speed(shost) = speed;
  1178. }
  1179. static void
  1180. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1181. {
  1182. scsi_qla_host_t *vha = shost_priv(shost);
  1183. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1184. if (vha->vp_idx) {
  1185. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1186. return;
  1187. }
  1188. switch (vha->hw->current_topology) {
  1189. case ISP_CFG_NL:
  1190. port_type = FC_PORTTYPE_LPORT;
  1191. break;
  1192. case ISP_CFG_FL:
  1193. port_type = FC_PORTTYPE_NLPORT;
  1194. break;
  1195. case ISP_CFG_N:
  1196. port_type = FC_PORTTYPE_PTP;
  1197. break;
  1198. case ISP_CFG_F:
  1199. port_type = FC_PORTTYPE_NPORT;
  1200. break;
  1201. }
  1202. fc_host_port_type(shost) = port_type;
  1203. }
  1204. static void
  1205. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1206. {
  1207. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1208. scsi_qla_host_t *vha = shost_priv(host);
  1209. fc_port_t *fcport;
  1210. u64 node_name = 0;
  1211. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1212. if (fcport->rport &&
  1213. starget->id == fcport->rport->scsi_target_id) {
  1214. node_name = wwn_to_u64(fcport->node_name);
  1215. break;
  1216. }
  1217. }
  1218. fc_starget_node_name(starget) = node_name;
  1219. }
  1220. static void
  1221. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1222. {
  1223. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1224. scsi_qla_host_t *vha = shost_priv(host);
  1225. fc_port_t *fcport;
  1226. u64 port_name = 0;
  1227. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1228. if (fcport->rport &&
  1229. starget->id == fcport->rport->scsi_target_id) {
  1230. port_name = wwn_to_u64(fcport->port_name);
  1231. break;
  1232. }
  1233. }
  1234. fc_starget_port_name(starget) = port_name;
  1235. }
  1236. static void
  1237. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1238. {
  1239. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1240. scsi_qla_host_t *vha = shost_priv(host);
  1241. fc_port_t *fcport;
  1242. uint32_t port_id = ~0U;
  1243. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1244. if (fcport->rport &&
  1245. starget->id == fcport->rport->scsi_target_id) {
  1246. port_id = fcport->d_id.b.domain << 16 |
  1247. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1248. break;
  1249. }
  1250. }
  1251. fc_starget_port_id(starget) = port_id;
  1252. }
  1253. static void
  1254. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1255. {
  1256. if (timeout)
  1257. rport->dev_loss_tmo = timeout;
  1258. else
  1259. rport->dev_loss_tmo = 1;
  1260. }
  1261. static void
  1262. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1263. {
  1264. struct Scsi_Host *host = rport_to_shost(rport);
  1265. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1266. if (!fcport)
  1267. return;
  1268. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1269. return;
  1270. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1271. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1272. return;
  1273. }
  1274. /*
  1275. * Transport has effectively 'deleted' the rport, clear
  1276. * all local references.
  1277. */
  1278. spin_lock_irq(host->host_lock);
  1279. fcport->rport = NULL;
  1280. *((fc_port_t **)rport->dd_data) = NULL;
  1281. spin_unlock_irq(host->host_lock);
  1282. }
  1283. static void
  1284. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1285. {
  1286. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1287. if (!fcport)
  1288. return;
  1289. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1290. return;
  1291. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1292. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1293. return;
  1294. }
  1295. /*
  1296. * At this point all fcport's software-states are cleared. Perform any
  1297. * final cleanup of firmware resources (PCBs and XCBs).
  1298. */
  1299. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1300. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1301. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1302. fcport->loop_id, fcport->d_id.b.domain,
  1303. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1304. }
  1305. static int
  1306. qla2x00_issue_lip(struct Scsi_Host *shost)
  1307. {
  1308. scsi_qla_host_t *vha = shost_priv(shost);
  1309. qla2x00_loop_reset(vha);
  1310. return 0;
  1311. }
  1312. static struct fc_host_statistics *
  1313. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1314. {
  1315. scsi_qla_host_t *vha = shost_priv(shost);
  1316. struct qla_hw_data *ha = vha->hw;
  1317. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1318. int rval;
  1319. struct link_statistics *stats;
  1320. dma_addr_t stats_dma;
  1321. struct fc_host_statistics *pfc_host_stat;
  1322. pfc_host_stat = &ha->fc_host_stat;
  1323. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1324. if (test_bit(UNLOADING, &vha->dpc_flags))
  1325. goto done;
  1326. if (unlikely(pci_channel_offline(ha->pdev)))
  1327. goto done;
  1328. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1329. if (stats == NULL) {
  1330. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1331. __func__, base_vha->host_no));
  1332. goto done;
  1333. }
  1334. memset(stats, 0, DMA_POOL_SIZE);
  1335. rval = QLA_FUNCTION_FAILED;
  1336. if (IS_FWI2_CAPABLE(ha)) {
  1337. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1338. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1339. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1340. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1341. !ha->dpc_active) {
  1342. /* Must be in a 'READY' state for statistics retrieval. */
  1343. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1344. stats, stats_dma);
  1345. }
  1346. if (rval != QLA_SUCCESS)
  1347. goto done_free;
  1348. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1349. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1350. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1351. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1352. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1353. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1354. if (IS_FWI2_CAPABLE(ha)) {
  1355. pfc_host_stat->lip_count = stats->lip_cnt;
  1356. pfc_host_stat->tx_frames = stats->tx_frames;
  1357. pfc_host_stat->rx_frames = stats->rx_frames;
  1358. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1359. pfc_host_stat->nos_count = stats->nos_rcvd;
  1360. }
  1361. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1362. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1363. done_free:
  1364. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1365. done:
  1366. return pfc_host_stat;
  1367. }
  1368. static void
  1369. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1370. {
  1371. scsi_qla_host_t *vha = shost_priv(shost);
  1372. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1373. }
  1374. static void
  1375. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1376. {
  1377. scsi_qla_host_t *vha = shost_priv(shost);
  1378. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1379. }
  1380. static void
  1381. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1382. {
  1383. scsi_qla_host_t *vha = shost_priv(shost);
  1384. u64 node_name;
  1385. if (vha->device_flags & SWITCH_FOUND)
  1386. node_name = wwn_to_u64(vha->fabric_node_name);
  1387. else
  1388. node_name = wwn_to_u64(vha->node_name);
  1389. fc_host_fabric_name(shost) = node_name;
  1390. }
  1391. static void
  1392. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1393. {
  1394. scsi_qla_host_t *vha = shost_priv(shost);
  1395. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1396. if (!base_vha->flags.online)
  1397. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1398. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1399. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1400. else
  1401. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1402. }
  1403. static int
  1404. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1405. {
  1406. int ret = 0;
  1407. uint8_t qos = 0;
  1408. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1409. scsi_qla_host_t *vha = NULL;
  1410. struct qla_hw_data *ha = base_vha->hw;
  1411. uint16_t options = 0;
  1412. int cnt;
  1413. struct req_que *req = ha->req_q_map[0];
  1414. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1415. if (ret) {
  1416. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1417. "status %x\n", ret));
  1418. return (ret);
  1419. }
  1420. vha = qla24xx_create_vhost(fc_vport);
  1421. if (vha == NULL) {
  1422. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1423. vha));
  1424. return FC_VPORT_FAILED;
  1425. }
  1426. if (disable) {
  1427. atomic_set(&vha->vp_state, VP_OFFLINE);
  1428. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1429. } else
  1430. atomic_set(&vha->vp_state, VP_FAILED);
  1431. /* ready to create vport */
  1432. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1433. vha->vp_idx);
  1434. /* initialized vport states */
  1435. atomic_set(&vha->loop_state, LOOP_DOWN);
  1436. vha->vp_err_state= VP_ERR_PORTDWN;
  1437. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1438. /* Check if physical ha port is Up */
  1439. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1440. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1441. /* Don't retry or attempt login of this virtual port */
  1442. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1443. base_vha->host_no));
  1444. atomic_set(&vha->loop_state, LOOP_DEAD);
  1445. if (!disable)
  1446. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1447. }
  1448. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1449. &ha->pdev->dev)) {
  1450. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1451. vha->host_no, vha->vp_idx));
  1452. goto vport_create_failed_2;
  1453. }
  1454. /* initialize attributes */
  1455. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1456. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1457. fc_host_supported_classes(vha->host) =
  1458. fc_host_supported_classes(base_vha->host);
  1459. fc_host_supported_speeds(vha->host) =
  1460. fc_host_supported_speeds(base_vha->host);
  1461. qla24xx_vport_disable(fc_vport, disable);
  1462. if (ha->flags.cpu_affinity_enabled) {
  1463. req = ha->req_q_map[1];
  1464. goto vport_queue;
  1465. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1466. goto vport_queue;
  1467. /* Create a request queue in QoS mode for the vport */
  1468. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1469. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1470. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1471. 8) == 0) {
  1472. qos = ha->npiv_info[cnt].q_qos;
  1473. break;
  1474. }
  1475. }
  1476. if (qos) {
  1477. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1478. qos);
  1479. if (!ret)
  1480. qla_printk(KERN_WARNING, ha,
  1481. "Can't create request queue for vp_idx:%d\n",
  1482. vha->vp_idx);
  1483. else {
  1484. DEBUG2(qla_printk(KERN_INFO, ha,
  1485. "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
  1486. ret, qos, vha->vp_idx));
  1487. req = ha->req_q_map[ret];
  1488. }
  1489. }
  1490. vport_queue:
  1491. vha->req = req;
  1492. return 0;
  1493. vport_create_failed_2:
  1494. qla24xx_disable_vp(vha);
  1495. qla24xx_deallocate_vp_id(vha);
  1496. scsi_host_put(vha->host);
  1497. return FC_VPORT_FAILED;
  1498. }
  1499. static int
  1500. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1501. {
  1502. scsi_qla_host_t *vha = fc_vport->dd_data;
  1503. fc_port_t *fcport, *tfcport;
  1504. struct qla_hw_data *ha = vha->hw;
  1505. uint16_t id = vha->vp_idx;
  1506. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1507. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1508. msleep(1000);
  1509. qla24xx_disable_vp(vha);
  1510. fc_remove_host(vha->host);
  1511. scsi_remove_host(vha->host);
  1512. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1513. list_del(&fcport->list);
  1514. kfree(fcport);
  1515. fcport = NULL;
  1516. }
  1517. qla24xx_deallocate_vp_id(vha);
  1518. mutex_lock(&ha->vport_lock);
  1519. ha->cur_vport_count--;
  1520. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1521. mutex_unlock(&ha->vport_lock);
  1522. if (vha->timer_active) {
  1523. qla2x00_vp_stop_timer(vha);
  1524. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1525. "has stopped\n",
  1526. vha->host_no, vha->vp_idx, vha));
  1527. }
  1528. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1529. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1530. qla_printk(KERN_WARNING, ha,
  1531. "Queue delete failed.\n");
  1532. }
  1533. scsi_host_put(vha->host);
  1534. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1535. return 0;
  1536. }
  1537. static int
  1538. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1539. {
  1540. scsi_qla_host_t *vha = fc_vport->dd_data;
  1541. if (disable)
  1542. qla24xx_disable_vp(vha);
  1543. else
  1544. qla24xx_enable_vp(vha);
  1545. return 0;
  1546. }
  1547. /* BSG support for ELS/CT pass through */
  1548. inline srb_t *
  1549. qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
  1550. {
  1551. srb_t *sp;
  1552. struct qla_hw_data *ha = vha->hw;
  1553. struct srb_bsg_ctx *ctx;
  1554. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  1555. if (!sp)
  1556. goto done;
  1557. ctx = kzalloc(size, GFP_KERNEL);
  1558. if (!ctx) {
  1559. mempool_free(sp, ha->srb_mempool);
  1560. goto done;
  1561. }
  1562. memset(sp, 0, sizeof(*sp));
  1563. sp->fcport = fcport;
  1564. sp->ctx = ctx;
  1565. done:
  1566. return sp;
  1567. }
  1568. static int
  1569. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  1570. {
  1571. struct fc_rport *rport;
  1572. fc_port_t *fcport;
  1573. struct Scsi_Host *host;
  1574. scsi_qla_host_t *vha;
  1575. struct qla_hw_data *ha;
  1576. srb_t *sp;
  1577. const char *type;
  1578. int req_sg_cnt, rsp_sg_cnt;
  1579. int rval = (DRIVER_ERROR << 16);
  1580. uint16_t nextlid = 0;
  1581. struct srb_bsg *els;
  1582. /* Multiple SG's are not supported for ELS requests */
  1583. if (bsg_job->request_payload.sg_cnt > 1 ||
  1584. bsg_job->reply_payload.sg_cnt > 1) {
  1585. DEBUG2(printk(KERN_INFO
  1586. "multiple SG's are not supported for ELS requests"
  1587. " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
  1588. bsg_job->request_payload.sg_cnt,
  1589. bsg_job->reply_payload.sg_cnt));
  1590. rval = -EPERM;
  1591. goto done;
  1592. }
  1593. /* ELS request for rport */
  1594. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1595. rport = bsg_job->rport;
  1596. fcport = *(fc_port_t **) rport->dd_data;
  1597. host = rport_to_shost(rport);
  1598. vha = shost_priv(host);
  1599. ha = vha->hw;
  1600. type = "FC_BSG_RPT_ELS";
  1601. /* make sure the rport is logged in,
  1602. * if not perform fabric login
  1603. */
  1604. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  1605. DEBUG2(qla_printk(KERN_WARNING, ha,
  1606. "failed to login port %06X for ELS passthru\n",
  1607. fcport->d_id.b24));
  1608. rval = -EIO;
  1609. goto done;
  1610. }
  1611. } else {
  1612. host = bsg_job->shost;
  1613. vha = shost_priv(host);
  1614. ha = vha->hw;
  1615. type = "FC_BSG_HST_ELS_NOLOGIN";
  1616. /* Allocate a dummy fcport structure, since functions
  1617. * preparing the IOCB and mailbox command retrieves port
  1618. * specific information from fcport structure. For Host based
  1619. * ELS commands there will be no fcport structure allocated
  1620. */
  1621. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1622. if (!fcport) {
  1623. rval = -ENOMEM;
  1624. goto done;
  1625. }
  1626. /* Initialize all required fields of fcport */
  1627. fcport->vha = vha;
  1628. fcport->vp_idx = vha->vp_idx;
  1629. fcport->d_id.b.al_pa =
  1630. bsg_job->request->rqst_data.h_els.port_id[0];
  1631. fcport->d_id.b.area =
  1632. bsg_job->request->rqst_data.h_els.port_id[1];
  1633. fcport->d_id.b.domain =
  1634. bsg_job->request->rqst_data.h_els.port_id[2];
  1635. fcport->loop_id =
  1636. (fcport->d_id.b.al_pa == 0xFD) ?
  1637. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  1638. }
  1639. if (!vha->flags.online) {
  1640. DEBUG2(qla_printk(KERN_WARNING, ha,
  1641. "host not online\n"));
  1642. rval = -EIO;
  1643. goto done;
  1644. }
  1645. req_sg_cnt =
  1646. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1647. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1648. if (!req_sg_cnt) {
  1649. rval = -ENOMEM;
  1650. goto done_free_fcport;
  1651. }
  1652. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1653. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1654. if (!rsp_sg_cnt) {
  1655. rval = -ENOMEM;
  1656. goto done_free_fcport;
  1657. }
  1658. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1659. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1660. {
  1661. DEBUG2(printk(KERN_INFO
  1662. "dma mapping resulted in different sg counts \
  1663. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1664. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1665. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1666. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1667. rval = -EAGAIN;
  1668. goto done_unmap_sg;
  1669. }
  1670. /* Alloc SRB structure */
  1671. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1672. if (!sp) {
  1673. rval = -ENOMEM;
  1674. goto done_unmap_sg;
  1675. }
  1676. els = sp->ctx;
  1677. els->ctx.type =
  1678. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  1679. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  1680. els->bsg_job = bsg_job;
  1681. DEBUG2(qla_printk(KERN_INFO, ha,
  1682. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1683. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1684. bsg_job->request->rqst_data.h_els.command_code,
  1685. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1686. fcport->d_id.b.al_pa));
  1687. rval = qla2x00_start_sp(sp);
  1688. if (rval != QLA_SUCCESS) {
  1689. kfree(sp->ctx);
  1690. mempool_free(sp, ha->srb_mempool);
  1691. rval = -EIO;
  1692. goto done_unmap_sg;
  1693. }
  1694. return rval;
  1695. done_unmap_sg:
  1696. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1697. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1698. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1699. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1700. goto done_free_fcport;
  1701. done_free_fcport:
  1702. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  1703. kfree(fcport);
  1704. done:
  1705. return rval;
  1706. }
  1707. static int
  1708. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  1709. {
  1710. srb_t *sp;
  1711. struct Scsi_Host *host = bsg_job->shost;
  1712. scsi_qla_host_t *vha = shost_priv(host);
  1713. struct qla_hw_data *ha = vha->hw;
  1714. int rval = (DRIVER_ERROR << 16);
  1715. int req_sg_cnt, rsp_sg_cnt;
  1716. uint16_t loop_id;
  1717. struct fc_port *fcport;
  1718. char *type = "FC_BSG_HST_CT";
  1719. struct srb_bsg *ct;
  1720. /* pass through is supported only for ISP 4Gb or higher */
  1721. if (!IS_FWI2_CAPABLE(ha)) {
  1722. DEBUG2(qla_printk(KERN_INFO, ha,
  1723. "scsi(%ld):Firmware is not capable to support FC "
  1724. "CT pass thru\n", vha->host_no));
  1725. rval = -EPERM;
  1726. goto done;
  1727. }
  1728. req_sg_cnt =
  1729. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1730. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1731. if (!req_sg_cnt) {
  1732. rval = -ENOMEM;
  1733. goto done;
  1734. }
  1735. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1736. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1737. if (!rsp_sg_cnt) {
  1738. rval = -ENOMEM;
  1739. goto done;
  1740. }
  1741. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1742. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1743. {
  1744. DEBUG2(qla_printk(KERN_WARNING, ha,
  1745. "dma mapping resulted in different sg counts \
  1746. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1747. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1748. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1749. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1750. rval = -EAGAIN;
  1751. goto done_unmap_sg;
  1752. }
  1753. if (!vha->flags.online) {
  1754. DEBUG2(qla_printk(KERN_WARNING, ha,
  1755. "host not online\n"));
  1756. rval = -EIO;
  1757. goto done_unmap_sg;
  1758. }
  1759. loop_id =
  1760. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  1761. >> 24;
  1762. switch (loop_id) {
  1763. case 0xFC:
  1764. loop_id = cpu_to_le16(NPH_SNS);
  1765. break;
  1766. case 0xFA:
  1767. loop_id = vha->mgmt_svr_loop_id;
  1768. break;
  1769. default:
  1770. DEBUG2(qla_printk(KERN_INFO, ha,
  1771. "Unknown loop id: %x\n", loop_id));
  1772. rval = -EINVAL;
  1773. goto done_unmap_sg;
  1774. }
  1775. /* Allocate a dummy fcport structure, since functions preparing the
  1776. * IOCB and mailbox command retrieves port specific information
  1777. * from fcport structure. For Host based ELS commands there will be
  1778. * no fcport structure allocated
  1779. */
  1780. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1781. if (!fcport)
  1782. {
  1783. rval = -ENOMEM;
  1784. goto done_unmap_sg;
  1785. }
  1786. /* Initialize all required fields of fcport */
  1787. fcport->vha = vha;
  1788. fcport->vp_idx = vha->vp_idx;
  1789. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  1790. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  1791. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  1792. fcport->loop_id = loop_id;
  1793. /* Alloc SRB structure */
  1794. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1795. if (!sp) {
  1796. rval = -ENOMEM;
  1797. goto done_free_fcport;
  1798. }
  1799. ct = sp->ctx;
  1800. ct->ctx.type = SRB_CT_CMD;
  1801. ct->bsg_job = bsg_job;
  1802. DEBUG2(qla_printk(KERN_INFO, ha,
  1803. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1804. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1805. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  1806. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1807. fcport->d_id.b.al_pa));
  1808. rval = qla2x00_start_sp(sp);
  1809. if (rval != QLA_SUCCESS) {
  1810. kfree(sp->ctx);
  1811. mempool_free(sp, ha->srb_mempool);
  1812. rval = -EIO;
  1813. goto done_free_fcport;
  1814. }
  1815. return rval;
  1816. done_free_fcport:
  1817. kfree(fcport);
  1818. done_unmap_sg:
  1819. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1820. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1821. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1822. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1823. done:
  1824. return rval;
  1825. }
  1826. static int
  1827. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1828. {
  1829. struct Scsi_Host *host = bsg_job->shost;
  1830. scsi_qla_host_t *vha = shost_priv(host);
  1831. struct qla_hw_data *ha = vha->hw;
  1832. int rval;
  1833. uint8_t command_sent;
  1834. uint32_t vendor_cmd;
  1835. char *type;
  1836. struct msg_echo_lb elreq;
  1837. uint16_t response[MAILBOX_REGISTER_COUNT];
  1838. uint8_t* fw_sts_ptr;
  1839. uint8_t *req_data;
  1840. dma_addr_t req_data_dma;
  1841. uint32_t req_data_len;
  1842. uint8_t *rsp_data;
  1843. dma_addr_t rsp_data_dma;
  1844. uint32_t rsp_data_len;
  1845. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1846. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1847. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1848. rval = -EBUSY;
  1849. goto done;
  1850. }
  1851. if (!vha->flags.online) {
  1852. DEBUG2(qla_printk(KERN_WARNING, ha,
  1853. "host not online\n"));
  1854. rval = -EIO;
  1855. goto done;
  1856. }
  1857. elreq.req_sg_cnt =
  1858. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1859. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1860. if (!elreq.req_sg_cnt) {
  1861. rval = -ENOMEM;
  1862. goto done;
  1863. }
  1864. elreq.rsp_sg_cnt =
  1865. dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1866. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1867. if (!elreq.rsp_sg_cnt) {
  1868. rval = -ENOMEM;
  1869. goto done;
  1870. }
  1871. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1872. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1873. {
  1874. DEBUG2(printk(KERN_INFO
  1875. "dma mapping resulted in different sg counts \
  1876. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1877. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1878. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  1879. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  1880. rval = -EAGAIN;
  1881. goto done_unmap_sg;
  1882. }
  1883. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  1884. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  1885. &req_data_dma, GFP_KERNEL);
  1886. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  1887. &rsp_data_dma, GFP_KERNEL);
  1888. /* Copy the request buffer in req_data now */
  1889. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1890. bsg_job->request_payload.sg_cnt, req_data,
  1891. req_data_len);
  1892. elreq.send_dma = req_data_dma;
  1893. elreq.rcv_dma = rsp_data_dma;
  1894. elreq.transfer_size = req_data_len;
  1895. /* Vendor cmd : loopback or ECHO diagnostic
  1896. * Options:
  1897. * Loopback : Either internal or external loopback
  1898. * ECHO: ECHO ELS or Vendor specific FC4 link data
  1899. */
  1900. vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
  1901. elreq.options =
  1902. *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
  1903. + 1);
  1904. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1905. case QL_VND_LOOPBACK:
  1906. if (ha->current_topology != ISP_CFG_F) {
  1907. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  1908. DEBUG2(qla_printk(KERN_INFO, ha,
  1909. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1910. vha->host_no, type, vendor_cmd, elreq.options));
  1911. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  1912. rval = qla2x00_loopback_test(vha, &elreq, response);
  1913. if (IS_QLA81XX(ha)) {
  1914. if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
  1915. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  1916. "ISP\n", __func__, vha->host_no));
  1917. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1918. qla2xxx_wake_dpc(vha);
  1919. }
  1920. }
  1921. } else {
  1922. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  1923. DEBUG2(qla_printk(KERN_INFO, ha,
  1924. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1925. vha->host_no, type, vendor_cmd, elreq.options));
  1926. command_sent = INT_DEF_LB_ECHO_CMD;
  1927. rval = qla2x00_echo_test(vha, &elreq, response);
  1928. }
  1929. break;
  1930. case QLA84_RESET:
  1931. if (!IS_QLA84XX(vha->hw)) {
  1932. rval = -EINVAL;
  1933. DEBUG16(printk(
  1934. "%s(%ld): 8xxx exiting.\n",
  1935. __func__, vha->host_no));
  1936. return rval;
  1937. }
  1938. rval = qla84xx_reset(vha, &elreq, bsg_job);
  1939. break;
  1940. case QLA84_MGMT_CMD:
  1941. if (!IS_QLA84XX(vha->hw)) {
  1942. rval = -EINVAL;
  1943. DEBUG16(printk(
  1944. "%s(%ld): 8xxx exiting.\n",
  1945. __func__, vha->host_no));
  1946. return rval;
  1947. }
  1948. rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
  1949. break;
  1950. default:
  1951. rval = -ENOSYS;
  1952. }
  1953. if (rval != QLA_SUCCESS) {
  1954. DEBUG2(qla_printk(KERN_WARNING, ha,
  1955. "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
  1956. rval = 0;
  1957. bsg_job->reply->result = (DID_ERROR << 16);
  1958. bsg_job->reply->reply_payload_rcv_len = 0;
  1959. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1960. memcpy( fw_sts_ptr, response, sizeof(response));
  1961. fw_sts_ptr += sizeof(response);
  1962. *fw_sts_ptr = command_sent;
  1963. } else {
  1964. DEBUG2(qla_printk(KERN_WARNING, ha,
  1965. "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
  1966. rval = bsg_job->reply->result = 0;
  1967. bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
  1968. bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
  1969. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1970. memcpy(fw_sts_ptr, response, sizeof(response));
  1971. fw_sts_ptr += sizeof(response);
  1972. *fw_sts_ptr = command_sent;
  1973. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1974. bsg_job->reply_payload.sg_cnt, rsp_data,
  1975. rsp_data_len);
  1976. }
  1977. bsg_job->job_done(bsg_job);
  1978. done_unmap_sg:
  1979. if(req_data)
  1980. dma_free_coherent(&ha->pdev->dev, req_data_len,
  1981. req_data, req_data_dma);
  1982. dma_unmap_sg(&ha->pdev->dev,
  1983. bsg_job->request_payload.sg_list,
  1984. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1985. dma_unmap_sg(&ha->pdev->dev,
  1986. bsg_job->reply_payload.sg_list,
  1987. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1988. done:
  1989. return rval;
  1990. }
  1991. static int
  1992. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  1993. {
  1994. int ret = -EINVAL;
  1995. switch (bsg_job->request->msgcode) {
  1996. case FC_BSG_RPT_ELS:
  1997. case FC_BSG_HST_ELS_NOLOGIN:
  1998. ret = qla2x00_process_els(bsg_job);
  1999. break;
  2000. case FC_BSG_HST_CT:
  2001. ret = qla2x00_process_ct(bsg_job);
  2002. break;
  2003. case FC_BSG_HST_VENDOR:
  2004. ret = qla2x00_process_vendor_specific(bsg_job);
  2005. break;
  2006. case FC_BSG_HST_ADD_RPORT:
  2007. case FC_BSG_HST_DEL_RPORT:
  2008. case FC_BSG_RPT_CT:
  2009. default:
  2010. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  2011. break;
  2012. }
  2013. return ret;
  2014. }
  2015. static int
  2016. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  2017. {
  2018. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  2019. struct qla_hw_data *ha = vha->hw;
  2020. srb_t *sp;
  2021. int cnt, que;
  2022. unsigned long flags;
  2023. struct req_que *req;
  2024. struct srb_bsg *sp_bsg;
  2025. /* find the bsg job from the active list of commands */
  2026. spin_lock_irqsave(&ha->hardware_lock, flags);
  2027. for (que = 0; que < ha->max_req_queues; que++) {
  2028. req = ha->req_q_map[que];
  2029. if (!req)
  2030. continue;
  2031. for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
  2032. sp = req->outstanding_cmds[cnt];
  2033. if (sp) {
  2034. sp_bsg = (struct srb_bsg*)sp->ctx;
  2035. if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
  2036. (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
  2037. || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
  2038. (sp_bsg->bsg_job == bsg_job)) {
  2039. if (ha->isp_ops->abort_command(sp)) {
  2040. DEBUG2(qla_printk(KERN_INFO, ha,
  2041. "scsi(%ld): mbx abort_command failed\n", vha->host_no));
  2042. bsg_job->req->errors = bsg_job->reply->result = -EIO;
  2043. } else {
  2044. DEBUG2(qla_printk(KERN_INFO, ha,
  2045. "scsi(%ld): mbx abort_command success\n", vha->host_no));
  2046. bsg_job->req->errors = bsg_job->reply->result = 0;
  2047. }
  2048. goto done;
  2049. }
  2050. }
  2051. }
  2052. }
  2053. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2054. DEBUG2(qla_printk(KERN_INFO, ha,
  2055. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  2056. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  2057. return 0;
  2058. done:
  2059. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  2060. kfree(sp->fcport);
  2061. kfree(sp->ctx);
  2062. mempool_free(sp, ha->srb_mempool);
  2063. return 0;
  2064. }
  2065. struct fc_function_template qla2xxx_transport_functions = {
  2066. .show_host_node_name = 1,
  2067. .show_host_port_name = 1,
  2068. .show_host_supported_classes = 1,
  2069. .show_host_supported_speeds = 1,
  2070. .get_host_port_id = qla2x00_get_host_port_id,
  2071. .show_host_port_id = 1,
  2072. .get_host_speed = qla2x00_get_host_speed,
  2073. .show_host_speed = 1,
  2074. .get_host_port_type = qla2x00_get_host_port_type,
  2075. .show_host_port_type = 1,
  2076. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2077. .show_host_symbolic_name = 1,
  2078. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2079. .show_host_system_hostname = 1,
  2080. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2081. .show_host_fabric_name = 1,
  2082. .get_host_port_state = qla2x00_get_host_port_state,
  2083. .show_host_port_state = 1,
  2084. .dd_fcrport_size = sizeof(struct fc_port *),
  2085. .show_rport_supported_classes = 1,
  2086. .get_starget_node_name = qla2x00_get_starget_node_name,
  2087. .show_starget_node_name = 1,
  2088. .get_starget_port_name = qla2x00_get_starget_port_name,
  2089. .show_starget_port_name = 1,
  2090. .get_starget_port_id = qla2x00_get_starget_port_id,
  2091. .show_starget_port_id = 1,
  2092. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2093. .show_rport_dev_loss_tmo = 1,
  2094. .issue_fc_host_lip = qla2x00_issue_lip,
  2095. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2096. .terminate_rport_io = qla2x00_terminate_rport_io,
  2097. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2098. .vport_create = qla24xx_vport_create,
  2099. .vport_disable = qla24xx_vport_disable,
  2100. .vport_delete = qla24xx_vport_delete,
  2101. .bsg_request = qla24xx_bsg_request,
  2102. .bsg_timeout = qla24xx_bsg_timeout,
  2103. };
  2104. struct fc_function_template qla2xxx_transport_vport_functions = {
  2105. .show_host_node_name = 1,
  2106. .show_host_port_name = 1,
  2107. .show_host_supported_classes = 1,
  2108. .get_host_port_id = qla2x00_get_host_port_id,
  2109. .show_host_port_id = 1,
  2110. .get_host_speed = qla2x00_get_host_speed,
  2111. .show_host_speed = 1,
  2112. .get_host_port_type = qla2x00_get_host_port_type,
  2113. .show_host_port_type = 1,
  2114. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2115. .show_host_symbolic_name = 1,
  2116. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2117. .show_host_system_hostname = 1,
  2118. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2119. .show_host_fabric_name = 1,
  2120. .get_host_port_state = qla2x00_get_host_port_state,
  2121. .show_host_port_state = 1,
  2122. .dd_fcrport_size = sizeof(struct fc_port *),
  2123. .show_rport_supported_classes = 1,
  2124. .get_starget_node_name = qla2x00_get_starget_node_name,
  2125. .show_starget_node_name = 1,
  2126. .get_starget_port_name = qla2x00_get_starget_port_name,
  2127. .show_starget_port_name = 1,
  2128. .get_starget_port_id = qla2x00_get_starget_port_id,
  2129. .show_starget_port_id = 1,
  2130. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2131. .show_rport_dev_loss_tmo = 1,
  2132. .issue_fc_host_lip = qla2x00_issue_lip,
  2133. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2134. .terminate_rport_io = qla2x00_terminate_rport_io,
  2135. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2136. .bsg_request = qla24xx_bsg_request,
  2137. .bsg_timeout = qla24xx_bsg_timeout,
  2138. };
  2139. void
  2140. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  2141. {
  2142. struct qla_hw_data *ha = vha->hw;
  2143. u32 speed = FC_PORTSPEED_UNKNOWN;
  2144. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  2145. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  2146. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  2147. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  2148. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  2149. if (IS_QLA81XX(ha))
  2150. speed = FC_PORTSPEED_10GBIT;
  2151. else if (IS_QLA25XX(ha))
  2152. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  2153. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2154. else if (IS_QLA24XX_TYPE(ha))
  2155. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  2156. FC_PORTSPEED_1GBIT;
  2157. else if (IS_QLA23XX(ha))
  2158. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2159. else
  2160. speed = FC_PORTSPEED_1GBIT;
  2161. fc_host_supported_speeds(vha->host) = speed;
  2162. }
  2163. static int
  2164. qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2165. {
  2166. int ret = 0;
  2167. int cmd;
  2168. uint16_t cmd_status;
  2169. DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2170. cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
  2171. == A84_RESET_FLAG_ENABLE_DIAG_FW ?
  2172. A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
  2173. ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
  2174. &cmd_status);
  2175. return ret;
  2176. }
  2177. static int
  2178. qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2179. {
  2180. struct access_chip_84xx *mn;
  2181. dma_addr_t mn_dma, mgmt_dma;
  2182. void *mgmt_b = NULL;
  2183. int ret = 0;
  2184. int rsp_hdr_len, len = 0;
  2185. struct qla84_msg_mgmt *ql84_mgmt;
  2186. ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
  2187. ql84_mgmt->cmd =
  2188. *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
  2189. ql84_mgmt->mgmtp.u.mem.start_addr =
  2190. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
  2191. ql84_mgmt->len =
  2192. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
  2193. ql84_mgmt->mgmtp.u.config.id =
  2194. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
  2195. ql84_mgmt->mgmtp.u.config.param0 =
  2196. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
  2197. ql84_mgmt->mgmtp.u.config.param1 =
  2198. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
  2199. ql84_mgmt->mgmtp.u.info.type =
  2200. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
  2201. ql84_mgmt->mgmtp.u.info.context =
  2202. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
  2203. rsp_hdr_len = bsg_job->request_payload.payload_len;
  2204. mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
  2205. if (mn == NULL) {
  2206. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  2207. "failed%lu\n", __func__, ha->host_no));
  2208. return -ENOMEM;
  2209. }
  2210. memset(mn, 0, sizeof (struct access_chip_84xx));
  2211. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  2212. mn->entry_count = 1;
  2213. switch (ql84_mgmt->cmd) {
  2214. case QLA84_MGMT_READ_MEM:
  2215. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  2216. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2217. break;
  2218. case QLA84_MGMT_WRITE_MEM:
  2219. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  2220. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2221. break;
  2222. case QLA84_MGMT_CHNG_CONFIG:
  2223. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  2224. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
  2225. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
  2226. mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
  2227. break;
  2228. case QLA84_MGMT_GET_INFO:
  2229. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  2230. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
  2231. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
  2232. break;
  2233. default:
  2234. ret = -EIO;
  2235. goto exit_mgmt0;
  2236. }
  2237. if ((len == ql84_mgmt->len) &&
  2238. ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
  2239. mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
  2240. &mgmt_dma, GFP_KERNEL);
  2241. if (mgmt_b == NULL) {
  2242. DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
  2243. "failed%lu\n", __func__, ha->host_no));
  2244. ret = -ENOMEM;
  2245. goto exit_mgmt0;
  2246. }
  2247. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
  2248. mn->dseg_count = cpu_to_le16(1);
  2249. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  2250. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  2251. mn->dseg_length = cpu_to_le32(len);
  2252. if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
  2253. memcpy(mgmt_b, ql84_mgmt->payload, len);
  2254. }
  2255. }
  2256. ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
  2257. if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
  2258. || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
  2259. if (ret != QLA_SUCCESS)
  2260. DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
  2261. __func__, ha->host_no));
  2262. } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
  2263. (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
  2264. }
  2265. if (mgmt_b)
  2266. dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
  2267. exit_mgmt0:
  2268. dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);
  2269. return ret;
  2270. }